* include/bits/stl_list.h (_M_resize_pos(size_type&)): Declare.
[official-gcc.git] / gcc / recog.c
blobffbd7b5c5608455c82e0b7b09c6787dd18ea868b
1 /* Subroutines used by or related to instruction recognition.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "hash-set.h"
26 #include "machmode.h"
27 #include "vec.h"
28 #include "double-int.h"
29 #include "input.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "tree.h"
35 #include "rtl-error.h"
36 #include "tm_p.h"
37 #include "insn-config.h"
38 #include "insn-attr.h"
39 #include "hard-reg-set.h"
40 #include "recog.h"
41 #include "regs.h"
42 #include "addresses.h"
43 #include "hashtab.h"
44 #include "function.h"
45 #include "rtl.h"
46 #include "flags.h"
47 #include "statistics.h"
48 #include "real.h"
49 #include "fixed-value.h"
50 #include "expmed.h"
51 #include "dojump.h"
52 #include "explow.h"
53 #include "calls.h"
54 #include "emit-rtl.h"
55 #include "varasm.h"
56 #include "stmt.h"
57 #include "expr.h"
58 #include "predict.h"
59 #include "dominance.h"
60 #include "cfg.h"
61 #include "cfgrtl.h"
62 #include "cfgbuild.h"
63 #include "cfgcleanup.h"
64 #include "basic-block.h"
65 #include "reload.h"
66 #include "target.h"
67 #include "tree-pass.h"
68 #include "df.h"
69 #include "insn-codes.h"
71 #ifndef STACK_PUSH_CODE
72 #ifdef STACK_GROWS_DOWNWARD
73 #define STACK_PUSH_CODE PRE_DEC
74 #else
75 #define STACK_PUSH_CODE PRE_INC
76 #endif
77 #endif
79 #ifndef STACK_POP_CODE
80 #ifdef STACK_GROWS_DOWNWARD
81 #define STACK_POP_CODE POST_INC
82 #else
83 #define STACK_POP_CODE POST_DEC
84 #endif
85 #endif
87 static void validate_replace_rtx_1 (rtx *, rtx, rtx, rtx_insn *, bool);
88 static void validate_replace_src_1 (rtx *, void *);
89 static rtx_insn *split_insn (rtx_insn *);
91 struct target_recog default_target_recog;
92 #if SWITCHABLE_TARGET
93 struct target_recog *this_target_recog = &default_target_recog;
94 #endif
96 /* Nonzero means allow operands to be volatile.
97 This should be 0 if you are generating rtl, such as if you are calling
98 the functions in optabs.c and expmed.c (most of the time).
99 This should be 1 if all valid insns need to be recognized,
100 such as in reginfo.c and final.c and reload.c.
102 init_recog and init_recog_no_volatile are responsible for setting this. */
104 int volatile_ok;
106 struct recog_data_d recog_data;
108 /* Contains a vector of operand_alternative structures, such that
109 operand OP of alternative A is at index A * n_operands + OP.
110 Set up by preprocess_constraints. */
111 const operand_alternative *recog_op_alt;
113 /* Used to provide recog_op_alt for asms. */
114 static operand_alternative asm_op_alt[MAX_RECOG_OPERANDS
115 * MAX_RECOG_ALTERNATIVES];
117 /* On return from `constrain_operands', indicate which alternative
118 was satisfied. */
120 int which_alternative;
122 /* Nonzero after end of reload pass.
123 Set to 1 or 0 by toplev.c.
124 Controls the significance of (SUBREG (MEM)). */
126 int reload_completed;
128 /* Nonzero after thread_prologue_and_epilogue_insns has run. */
129 int epilogue_completed;
131 /* Initialize data used by the function `recog'.
132 This must be called once in the compilation of a function
133 before any insn recognition may be done in the function. */
135 void
136 init_recog_no_volatile (void)
138 volatile_ok = 0;
141 void
142 init_recog (void)
144 volatile_ok = 1;
148 /* Return true if labels in asm operands BODY are LABEL_REFs. */
150 static bool
151 asm_labels_ok (rtx body)
153 rtx asmop;
154 int i;
156 asmop = extract_asm_operands (body);
157 if (asmop == NULL_RTX)
158 return true;
160 for (i = 0; i < ASM_OPERANDS_LABEL_LENGTH (asmop); i++)
161 if (GET_CODE (ASM_OPERANDS_LABEL (asmop, i)) != LABEL_REF)
162 return false;
164 return true;
167 /* Check that X is an insn-body for an `asm' with operands
168 and that the operands mentioned in it are legitimate. */
171 check_asm_operands (rtx x)
173 int noperands;
174 rtx *operands;
175 const char **constraints;
176 int i;
178 if (!asm_labels_ok (x))
179 return 0;
181 /* Post-reload, be more strict with things. */
182 if (reload_completed)
184 /* ??? Doh! We've not got the wrapping insn. Cook one up. */
185 rtx_insn *insn = make_insn_raw (x);
186 extract_insn (insn);
187 constrain_operands (1, get_enabled_alternatives (insn));
188 return which_alternative >= 0;
191 noperands = asm_noperands (x);
192 if (noperands < 0)
193 return 0;
194 if (noperands == 0)
195 return 1;
197 operands = XALLOCAVEC (rtx, noperands);
198 constraints = XALLOCAVEC (const char *, noperands);
200 decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
202 for (i = 0; i < noperands; i++)
204 const char *c = constraints[i];
205 if (c[0] == '%')
206 c++;
207 if (! asm_operand_ok (operands[i], c, constraints))
208 return 0;
211 return 1;
214 /* Static data for the next two routines. */
216 typedef struct change_t
218 rtx object;
219 int old_code;
220 rtx *loc;
221 rtx old;
222 bool unshare;
223 } change_t;
225 static change_t *changes;
226 static int changes_allocated;
228 static int num_changes = 0;
230 /* Validate a proposed change to OBJECT. LOC is the location in the rtl
231 at which NEW_RTX will be placed. If OBJECT is zero, no validation is done,
232 the change is simply made.
234 Two types of objects are supported: If OBJECT is a MEM, memory_address_p
235 will be called with the address and mode as parameters. If OBJECT is
236 an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
237 the change in place.
239 IN_GROUP is nonzero if this is part of a group of changes that must be
240 performed as a group. In that case, the changes will be stored. The
241 function `apply_change_group' will validate and apply the changes.
243 If IN_GROUP is zero, this is a single change. Try to recognize the insn
244 or validate the memory reference with the change applied. If the result
245 is not valid for the machine, suppress the change and return zero.
246 Otherwise, perform the change and return 1. */
248 static bool
249 validate_change_1 (rtx object, rtx *loc, rtx new_rtx, bool in_group, bool unshare)
251 rtx old = *loc;
253 if (old == new_rtx || rtx_equal_p (old, new_rtx))
254 return 1;
256 gcc_assert (in_group != 0 || num_changes == 0);
258 *loc = new_rtx;
260 /* Save the information describing this change. */
261 if (num_changes >= changes_allocated)
263 if (changes_allocated == 0)
264 /* This value allows for repeated substitutions inside complex
265 indexed addresses, or changes in up to 5 insns. */
266 changes_allocated = MAX_RECOG_OPERANDS * 5;
267 else
268 changes_allocated *= 2;
270 changes = XRESIZEVEC (change_t, changes, changes_allocated);
273 changes[num_changes].object = object;
274 changes[num_changes].loc = loc;
275 changes[num_changes].old = old;
276 changes[num_changes].unshare = unshare;
278 if (object && !MEM_P (object))
280 /* Set INSN_CODE to force rerecognition of insn. Save old code in
281 case invalid. */
282 changes[num_changes].old_code = INSN_CODE (object);
283 INSN_CODE (object) = -1;
286 num_changes++;
288 /* If we are making a group of changes, return 1. Otherwise, validate the
289 change group we made. */
291 if (in_group)
292 return 1;
293 else
294 return apply_change_group ();
297 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
298 UNSHARE to false. */
300 bool
301 validate_change (rtx object, rtx *loc, rtx new_rtx, bool in_group)
303 return validate_change_1 (object, loc, new_rtx, in_group, false);
306 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
307 UNSHARE to true. */
309 bool
310 validate_unshare_change (rtx object, rtx *loc, rtx new_rtx, bool in_group)
312 return validate_change_1 (object, loc, new_rtx, in_group, true);
316 /* Keep X canonicalized if some changes have made it non-canonical; only
317 modifies the operands of X, not (for example) its code. Simplifications
318 are not the job of this routine.
320 Return true if anything was changed. */
321 bool
322 canonicalize_change_group (rtx_insn *insn, rtx x)
324 if (COMMUTATIVE_P (x)
325 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
327 /* Oops, the caller has made X no longer canonical.
328 Let's redo the changes in the correct order. */
329 rtx tem = XEXP (x, 0);
330 validate_unshare_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
331 validate_unshare_change (insn, &XEXP (x, 1), tem, 1);
332 return true;
334 else
335 return false;
339 /* This subroutine of apply_change_group verifies whether the changes to INSN
340 were valid; i.e. whether INSN can still be recognized.
342 If IN_GROUP is true clobbers which have to be added in order to
343 match the instructions will be added to the current change group.
344 Otherwise the changes will take effect immediately. */
347 insn_invalid_p (rtx_insn *insn, bool in_group)
349 rtx pat = PATTERN (insn);
350 int num_clobbers = 0;
351 /* If we are before reload and the pattern is a SET, see if we can add
352 clobbers. */
353 int icode = recog (pat, insn,
354 (GET_CODE (pat) == SET
355 && ! reload_completed
356 && ! reload_in_progress)
357 ? &num_clobbers : 0);
358 int is_asm = icode < 0 && asm_noperands (PATTERN (insn)) >= 0;
361 /* If this is an asm and the operand aren't legal, then fail. Likewise if
362 this is not an asm and the insn wasn't recognized. */
363 if ((is_asm && ! check_asm_operands (PATTERN (insn)))
364 || (!is_asm && icode < 0))
365 return 1;
367 /* If we have to add CLOBBERs, fail if we have to add ones that reference
368 hard registers since our callers can't know if they are live or not.
369 Otherwise, add them. */
370 if (num_clobbers > 0)
372 rtx newpat;
374 if (added_clobbers_hard_reg_p (icode))
375 return 1;
377 newpat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_clobbers + 1));
378 XVECEXP (newpat, 0, 0) = pat;
379 add_clobbers (newpat, icode);
380 if (in_group)
381 validate_change (insn, &PATTERN (insn), newpat, 1);
382 else
383 PATTERN (insn) = pat = newpat;
386 /* After reload, verify that all constraints are satisfied. */
387 if (reload_completed)
389 extract_insn (insn);
391 if (! constrain_operands (1, get_preferred_alternatives (insn)))
392 return 1;
395 INSN_CODE (insn) = icode;
396 return 0;
399 /* Return number of changes made and not validated yet. */
401 num_changes_pending (void)
403 return num_changes;
406 /* Tentatively apply the changes numbered NUM and up.
407 Return 1 if all changes are valid, zero otherwise. */
410 verify_changes (int num)
412 int i;
413 rtx last_validated = NULL_RTX;
415 /* The changes have been applied and all INSN_CODEs have been reset to force
416 rerecognition.
418 The changes are valid if we aren't given an object, or if we are
419 given a MEM and it still is a valid address, or if this is in insn
420 and it is recognized. In the latter case, if reload has completed,
421 we also require that the operands meet the constraints for
422 the insn. */
424 for (i = num; i < num_changes; i++)
426 rtx object = changes[i].object;
428 /* If there is no object to test or if it is the same as the one we
429 already tested, ignore it. */
430 if (object == 0 || object == last_validated)
431 continue;
433 if (MEM_P (object))
435 if (! memory_address_addr_space_p (GET_MODE (object),
436 XEXP (object, 0),
437 MEM_ADDR_SPACE (object)))
438 break;
440 else if (/* changes[i].old might be zero, e.g. when putting a
441 REG_FRAME_RELATED_EXPR into a previously empty list. */
442 changes[i].old
443 && REG_P (changes[i].old)
444 && asm_noperands (PATTERN (object)) > 0
445 && REG_EXPR (changes[i].old) != NULL_TREE
446 && DECL_ASSEMBLER_NAME_SET_P (REG_EXPR (changes[i].old))
447 && DECL_REGISTER (REG_EXPR (changes[i].old)))
449 /* Don't allow changes of hard register operands to inline
450 assemblies if they have been defined as register asm ("x"). */
451 break;
453 else if (DEBUG_INSN_P (object))
454 continue;
455 else if (insn_invalid_p (as_a <rtx_insn *> (object), true))
457 rtx pat = PATTERN (object);
459 /* Perhaps we couldn't recognize the insn because there were
460 extra CLOBBERs at the end. If so, try to re-recognize
461 without the last CLOBBER (later iterations will cause each of
462 them to be eliminated, in turn). But don't do this if we
463 have an ASM_OPERAND. */
464 if (GET_CODE (pat) == PARALLEL
465 && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
466 && asm_noperands (PATTERN (object)) < 0)
468 rtx newpat;
470 if (XVECLEN (pat, 0) == 2)
471 newpat = XVECEXP (pat, 0, 0);
472 else
474 int j;
476 newpat
477 = gen_rtx_PARALLEL (VOIDmode,
478 rtvec_alloc (XVECLEN (pat, 0) - 1));
479 for (j = 0; j < XVECLEN (newpat, 0); j++)
480 XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
483 /* Add a new change to this group to replace the pattern
484 with this new pattern. Then consider this change
485 as having succeeded. The change we added will
486 cause the entire call to fail if things remain invalid.
488 Note that this can lose if a later change than the one
489 we are processing specified &XVECEXP (PATTERN (object), 0, X)
490 but this shouldn't occur. */
492 validate_change (object, &PATTERN (object), newpat, 1);
493 continue;
495 else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER
496 || GET_CODE (pat) == VAR_LOCATION)
497 /* If this insn is a CLOBBER or USE, it is always valid, but is
498 never recognized. */
499 continue;
500 else
501 break;
503 last_validated = object;
506 return (i == num_changes);
509 /* A group of changes has previously been issued with validate_change
510 and verified with verify_changes. Call df_insn_rescan for each of
511 the insn changed and clear num_changes. */
513 void
514 confirm_change_group (void)
516 int i;
517 rtx last_object = NULL;
519 for (i = 0; i < num_changes; i++)
521 rtx object = changes[i].object;
523 if (changes[i].unshare)
524 *changes[i].loc = copy_rtx (*changes[i].loc);
526 /* Avoid unnecessary rescanning when multiple changes to same instruction
527 are made. */
528 if (object)
530 if (object != last_object && last_object && INSN_P (last_object))
531 df_insn_rescan (as_a <rtx_insn *> (last_object));
532 last_object = object;
536 if (last_object && INSN_P (last_object))
537 df_insn_rescan (as_a <rtx_insn *> (last_object));
538 num_changes = 0;
541 /* Apply a group of changes previously issued with `validate_change'.
542 If all changes are valid, call confirm_change_group and return 1,
543 otherwise, call cancel_changes and return 0. */
546 apply_change_group (void)
548 if (verify_changes (0))
550 confirm_change_group ();
551 return 1;
553 else
555 cancel_changes (0);
556 return 0;
561 /* Return the number of changes so far in the current group. */
564 num_validated_changes (void)
566 return num_changes;
569 /* Retract the changes numbered NUM and up. */
571 void
572 cancel_changes (int num)
574 int i;
576 /* Back out all the changes. Do this in the opposite order in which
577 they were made. */
578 for (i = num_changes - 1; i >= num; i--)
580 *changes[i].loc = changes[i].old;
581 if (changes[i].object && !MEM_P (changes[i].object))
582 INSN_CODE (changes[i].object) = changes[i].old_code;
584 num_changes = num;
587 /* Reduce conditional compilation elsewhere. */
588 #ifndef HAVE_extv
589 #define HAVE_extv 0
590 #define CODE_FOR_extv CODE_FOR_nothing
591 #endif
592 #ifndef HAVE_extzv
593 #define HAVE_extzv 0
594 #define CODE_FOR_extzv CODE_FOR_nothing
595 #endif
597 /* A subroutine of validate_replace_rtx_1 that tries to simplify the resulting
598 rtx. */
600 static void
601 simplify_while_replacing (rtx *loc, rtx to, rtx_insn *object,
602 machine_mode op0_mode)
604 rtx x = *loc;
605 enum rtx_code code = GET_CODE (x);
606 rtx new_rtx = NULL_RTX;
608 if (SWAPPABLE_OPERANDS_P (x)
609 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
611 validate_unshare_change (object, loc,
612 gen_rtx_fmt_ee (COMMUTATIVE_ARITH_P (x) ? code
613 : swap_condition (code),
614 GET_MODE (x), XEXP (x, 1),
615 XEXP (x, 0)), 1);
616 x = *loc;
617 code = GET_CODE (x);
620 /* Canonicalize arithmetics with all constant operands. */
621 switch (GET_RTX_CLASS (code))
623 case RTX_UNARY:
624 if (CONSTANT_P (XEXP (x, 0)))
625 new_rtx = simplify_unary_operation (code, GET_MODE (x), XEXP (x, 0),
626 op0_mode);
627 break;
628 case RTX_COMM_ARITH:
629 case RTX_BIN_ARITH:
630 if (CONSTANT_P (XEXP (x, 0)) && CONSTANT_P (XEXP (x, 1)))
631 new_rtx = simplify_binary_operation (code, GET_MODE (x), XEXP (x, 0),
632 XEXP (x, 1));
633 break;
634 case RTX_COMPARE:
635 case RTX_COMM_COMPARE:
636 if (CONSTANT_P (XEXP (x, 0)) && CONSTANT_P (XEXP (x, 1)))
637 new_rtx = simplify_relational_operation (code, GET_MODE (x), op0_mode,
638 XEXP (x, 0), XEXP (x, 1));
639 break;
640 default:
641 break;
643 if (new_rtx)
645 validate_change (object, loc, new_rtx, 1);
646 return;
649 switch (code)
651 case PLUS:
652 /* If we have a PLUS whose second operand is now a CONST_INT, use
653 simplify_gen_binary to try to simplify it.
654 ??? We may want later to remove this, once simplification is
655 separated from this function. */
656 if (CONST_INT_P (XEXP (x, 1)) && XEXP (x, 1) == to)
657 validate_change (object, loc,
658 simplify_gen_binary
659 (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
660 break;
661 case MINUS:
662 if (CONST_SCALAR_INT_P (XEXP (x, 1)))
663 validate_change (object, loc,
664 simplify_gen_binary
665 (PLUS, GET_MODE (x), XEXP (x, 0),
666 simplify_gen_unary (NEG,
667 GET_MODE (x), XEXP (x, 1),
668 GET_MODE (x))), 1);
669 break;
670 case ZERO_EXTEND:
671 case SIGN_EXTEND:
672 if (GET_MODE (XEXP (x, 0)) == VOIDmode)
674 new_rtx = simplify_gen_unary (code, GET_MODE (x), XEXP (x, 0),
675 op0_mode);
676 /* If any of the above failed, substitute in something that
677 we know won't be recognized. */
678 if (!new_rtx)
679 new_rtx = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
680 validate_change (object, loc, new_rtx, 1);
682 break;
683 case SUBREG:
684 /* All subregs possible to simplify should be simplified. */
685 new_rtx = simplify_subreg (GET_MODE (x), SUBREG_REG (x), op0_mode,
686 SUBREG_BYTE (x));
688 /* Subregs of VOIDmode operands are incorrect. */
689 if (!new_rtx && GET_MODE (SUBREG_REG (x)) == VOIDmode)
690 new_rtx = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
691 if (new_rtx)
692 validate_change (object, loc, new_rtx, 1);
693 break;
694 case ZERO_EXTRACT:
695 case SIGN_EXTRACT:
696 /* If we are replacing a register with memory, try to change the memory
697 to be the mode required for memory in extract operations (this isn't
698 likely to be an insertion operation; if it was, nothing bad will
699 happen, we might just fail in some cases). */
701 if (MEM_P (XEXP (x, 0))
702 && CONST_INT_P (XEXP (x, 1))
703 && CONST_INT_P (XEXP (x, 2))
704 && !mode_dependent_address_p (XEXP (XEXP (x, 0), 0),
705 MEM_ADDR_SPACE (XEXP (x, 0)))
706 && !MEM_VOLATILE_P (XEXP (x, 0)))
708 machine_mode wanted_mode = VOIDmode;
709 machine_mode is_mode = GET_MODE (XEXP (x, 0));
710 int pos = INTVAL (XEXP (x, 2));
712 if (GET_CODE (x) == ZERO_EXTRACT && HAVE_extzv)
714 wanted_mode = insn_data[CODE_FOR_extzv].operand[1].mode;
715 if (wanted_mode == VOIDmode)
716 wanted_mode = word_mode;
718 else if (GET_CODE (x) == SIGN_EXTRACT && HAVE_extv)
720 wanted_mode = insn_data[CODE_FOR_extv].operand[1].mode;
721 if (wanted_mode == VOIDmode)
722 wanted_mode = word_mode;
725 /* If we have a narrower mode, we can do something. */
726 if (wanted_mode != VOIDmode
727 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
729 int offset = pos / BITS_PER_UNIT;
730 rtx newmem;
732 /* If the bytes and bits are counted differently, we
733 must adjust the offset. */
734 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
735 offset =
736 (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) -
737 offset);
739 gcc_assert (GET_MODE_PRECISION (wanted_mode)
740 == GET_MODE_BITSIZE (wanted_mode));
741 pos %= GET_MODE_BITSIZE (wanted_mode);
743 newmem = adjust_address_nv (XEXP (x, 0), wanted_mode, offset);
745 validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
746 validate_change (object, &XEXP (x, 0), newmem, 1);
750 break;
752 default:
753 break;
757 /* Replace every occurrence of FROM in X with TO. Mark each change with
758 validate_change passing OBJECT. */
760 static void
761 validate_replace_rtx_1 (rtx *loc, rtx from, rtx to, rtx_insn *object,
762 bool simplify)
764 int i, j;
765 const char *fmt;
766 rtx x = *loc;
767 enum rtx_code code;
768 machine_mode op0_mode = VOIDmode;
769 int prev_changes = num_changes;
771 if (!x)
772 return;
774 code = GET_CODE (x);
775 fmt = GET_RTX_FORMAT (code);
776 if (fmt[0] == 'e')
777 op0_mode = GET_MODE (XEXP (x, 0));
779 /* X matches FROM if it is the same rtx or they are both referring to the
780 same register in the same mode. Avoid calling rtx_equal_p unless the
781 operands look similar. */
783 if (x == from
784 || (REG_P (x) && REG_P (from)
785 && GET_MODE (x) == GET_MODE (from)
786 && REGNO (x) == REGNO (from))
787 || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
788 && rtx_equal_p (x, from)))
790 validate_unshare_change (object, loc, to, 1);
791 return;
794 /* Call ourself recursively to perform the replacements.
795 We must not replace inside already replaced expression, otherwise we
796 get infinite recursion for replacements like (reg X)->(subreg (reg X))
797 so we must special case shared ASM_OPERANDS. */
799 if (GET_CODE (x) == PARALLEL)
801 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
803 if (j && GET_CODE (XVECEXP (x, 0, j)) == SET
804 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == ASM_OPERANDS)
806 /* Verify that operands are really shared. */
807 gcc_assert (ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (x, 0, 0)))
808 == ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP
809 (x, 0, j))));
810 validate_replace_rtx_1 (&SET_DEST (XVECEXP (x, 0, j)),
811 from, to, object, simplify);
813 else
814 validate_replace_rtx_1 (&XVECEXP (x, 0, j), from, to, object,
815 simplify);
818 else
819 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
821 if (fmt[i] == 'e')
822 validate_replace_rtx_1 (&XEXP (x, i), from, to, object, simplify);
823 else if (fmt[i] == 'E')
824 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
825 validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object,
826 simplify);
829 /* If we didn't substitute, there is nothing more to do. */
830 if (num_changes == prev_changes)
831 return;
833 /* ??? The regmove is no more, so is this aberration still necessary? */
834 /* Allow substituted expression to have different mode. This is used by
835 regmove to change mode of pseudo register. */
836 if (fmt[0] == 'e' && GET_MODE (XEXP (x, 0)) != VOIDmode)
837 op0_mode = GET_MODE (XEXP (x, 0));
839 /* Do changes needed to keep rtx consistent. Don't do any other
840 simplifications, as it is not our job. */
841 if (simplify)
842 simplify_while_replacing (loc, to, object, op0_mode);
845 /* Try replacing every occurrence of FROM in subexpression LOC of INSN
846 with TO. After all changes have been made, validate by seeing
847 if INSN is still valid. */
850 validate_replace_rtx_subexp (rtx from, rtx to, rtx_insn *insn, rtx *loc)
852 validate_replace_rtx_1 (loc, from, to, insn, true);
853 return apply_change_group ();
856 /* Try replacing every occurrence of FROM in INSN with TO. After all
857 changes have been made, validate by seeing if INSN is still valid. */
860 validate_replace_rtx (rtx from, rtx to, rtx_insn *insn)
862 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
863 return apply_change_group ();
866 /* Try replacing every occurrence of FROM in WHERE with TO. Assume that WHERE
867 is a part of INSN. After all changes have been made, validate by seeing if
868 INSN is still valid.
869 validate_replace_rtx (from, to, insn) is equivalent to
870 validate_replace_rtx_part (from, to, &PATTERN (insn), insn). */
873 validate_replace_rtx_part (rtx from, rtx to, rtx *where, rtx_insn *insn)
875 validate_replace_rtx_1 (where, from, to, insn, true);
876 return apply_change_group ();
879 /* Same as above, but do not simplify rtx afterwards. */
881 validate_replace_rtx_part_nosimplify (rtx from, rtx to, rtx *where,
882 rtx_insn *insn)
884 validate_replace_rtx_1 (where, from, to, insn, false);
885 return apply_change_group ();
889 /* Try replacing every occurrence of FROM in INSN with TO. This also
890 will replace in REG_EQUAL and REG_EQUIV notes. */
892 void
893 validate_replace_rtx_group (rtx from, rtx to, rtx_insn *insn)
895 rtx note;
896 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
897 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
898 if (REG_NOTE_KIND (note) == REG_EQUAL
899 || REG_NOTE_KIND (note) == REG_EQUIV)
900 validate_replace_rtx_1 (&XEXP (note, 0), from, to, insn, true);
903 /* Function called by note_uses to replace used subexpressions. */
904 struct validate_replace_src_data
906 rtx from; /* Old RTX */
907 rtx to; /* New RTX */
908 rtx_insn *insn; /* Insn in which substitution is occurring. */
911 static void
912 validate_replace_src_1 (rtx *x, void *data)
914 struct validate_replace_src_data *d
915 = (struct validate_replace_src_data *) data;
917 validate_replace_rtx_1 (x, d->from, d->to, d->insn, true);
920 /* Try replacing every occurrence of FROM in INSN with TO, avoiding
921 SET_DESTs. */
923 void
924 validate_replace_src_group (rtx from, rtx to, rtx_insn *insn)
926 struct validate_replace_src_data d;
928 d.from = from;
929 d.to = to;
930 d.insn = insn;
931 note_uses (&PATTERN (insn), validate_replace_src_1, &d);
934 /* Try simplify INSN.
935 Invoke simplify_rtx () on every SET_SRC and SET_DEST inside the INSN's
936 pattern and return true if something was simplified. */
938 bool
939 validate_simplify_insn (rtx_insn *insn)
941 int i;
942 rtx pat = NULL;
943 rtx newpat = NULL;
945 pat = PATTERN (insn);
947 if (GET_CODE (pat) == SET)
949 newpat = simplify_rtx (SET_SRC (pat));
950 if (newpat && !rtx_equal_p (SET_SRC (pat), newpat))
951 validate_change (insn, &SET_SRC (pat), newpat, 1);
952 newpat = simplify_rtx (SET_DEST (pat));
953 if (newpat && !rtx_equal_p (SET_DEST (pat), newpat))
954 validate_change (insn, &SET_DEST (pat), newpat, 1);
956 else if (GET_CODE (pat) == PARALLEL)
957 for (i = 0; i < XVECLEN (pat, 0); i++)
959 rtx s = XVECEXP (pat, 0, i);
961 if (GET_CODE (XVECEXP (pat, 0, i)) == SET)
963 newpat = simplify_rtx (SET_SRC (s));
964 if (newpat && !rtx_equal_p (SET_SRC (s), newpat))
965 validate_change (insn, &SET_SRC (s), newpat, 1);
966 newpat = simplify_rtx (SET_DEST (s));
967 if (newpat && !rtx_equal_p (SET_DEST (s), newpat))
968 validate_change (insn, &SET_DEST (s), newpat, 1);
971 return ((num_changes_pending () > 0) && (apply_change_group () > 0));
974 /* Return 1 if the insn using CC0 set by INSN does not contain
975 any ordered tests applied to the condition codes.
976 EQ and NE tests do not count. */
979 next_insn_tests_no_inequality (rtx_insn *insn)
981 rtx_insn *next = next_cc0_user (insn);
983 /* If there is no next insn, we have to take the conservative choice. */
984 if (next == 0)
985 return 0;
987 return (INSN_P (next)
988 && ! inequality_comparisons_p (PATTERN (next)));
991 /* Return 1 if OP is a valid general operand for machine mode MODE.
992 This is either a register reference, a memory reference,
993 or a constant. In the case of a memory reference, the address
994 is checked for general validity for the target machine.
996 Register and memory references must have mode MODE in order to be valid,
997 but some constants have no machine mode and are valid for any mode.
999 If MODE is VOIDmode, OP is checked for validity for whatever mode
1000 it has.
1002 The main use of this function is as a predicate in match_operand
1003 expressions in the machine description. */
1006 general_operand (rtx op, machine_mode mode)
1008 enum rtx_code code = GET_CODE (op);
1010 if (mode == VOIDmode)
1011 mode = GET_MODE (op);
1013 /* Don't accept CONST_INT or anything similar
1014 if the caller wants something floating. */
1015 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1016 && GET_MODE_CLASS (mode) != MODE_INT
1017 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1018 return 0;
1020 if (CONST_INT_P (op)
1021 && mode != VOIDmode
1022 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1023 return 0;
1025 if (CONSTANT_P (op))
1026 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
1027 || mode == VOIDmode)
1028 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1029 && targetm.legitimate_constant_p (mode == VOIDmode
1030 ? GET_MODE (op)
1031 : mode, op));
1033 /* Except for certain constants with VOIDmode, already checked for,
1034 OP's mode must match MODE if MODE specifies a mode. */
1036 if (GET_MODE (op) != mode)
1037 return 0;
1039 if (code == SUBREG)
1041 rtx sub = SUBREG_REG (op);
1043 #ifdef INSN_SCHEDULING
1044 /* On machines that have insn scheduling, we want all memory
1045 reference to be explicit, so outlaw paradoxical SUBREGs.
1046 However, we must allow them after reload so that they can
1047 get cleaned up by cleanup_subreg_operands. */
1048 if (!reload_completed && MEM_P (sub)
1049 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (sub)))
1050 return 0;
1051 #endif
1052 /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
1053 may result in incorrect reference. We should simplify all valid
1054 subregs of MEM anyway. But allow this after reload because we
1055 might be called from cleanup_subreg_operands.
1057 ??? This is a kludge. */
1058 if (!reload_completed && SUBREG_BYTE (op) != 0
1059 && MEM_P (sub))
1060 return 0;
1062 #ifdef CANNOT_CHANGE_MODE_CLASS
1063 if (REG_P (sub)
1064 && REGNO (sub) < FIRST_PSEUDO_REGISTER
1065 && REG_CANNOT_CHANGE_MODE_P (REGNO (sub), GET_MODE (sub), mode)
1066 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_INT
1067 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_FLOAT
1068 /* LRA can generate some invalid SUBREGS just for matched
1069 operand reload presentation. LRA needs to treat them as
1070 valid. */
1071 && ! LRA_SUBREG_P (op))
1072 return 0;
1073 #endif
1075 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
1076 create such rtl, and we must reject it. */
1077 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
1078 /* LRA can use subreg to store a floating point value in an
1079 integer mode. Although the floating point and the
1080 integer modes need the same number of hard registers, the
1081 size of floating point mode can be less than the integer
1082 mode. */
1083 && ! lra_in_progress
1084 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
1085 return 0;
1087 op = sub;
1088 code = GET_CODE (op);
1091 if (code == REG)
1092 return (REGNO (op) >= FIRST_PSEUDO_REGISTER
1093 || in_hard_reg_set_p (operand_reg_set, GET_MODE (op), REGNO (op)));
1095 if (code == MEM)
1097 rtx y = XEXP (op, 0);
1099 if (! volatile_ok && MEM_VOLATILE_P (op))
1100 return 0;
1102 /* Use the mem's mode, since it will be reloaded thus. LRA can
1103 generate move insn with invalid addresses which is made valid
1104 and efficiently calculated by LRA through further numerous
1105 transformations. */
1106 if (lra_in_progress
1107 || memory_address_addr_space_p (GET_MODE (op), y, MEM_ADDR_SPACE (op)))
1108 return 1;
1111 return 0;
1114 /* Return 1 if OP is a valid memory address for a memory reference
1115 of mode MODE.
1117 The main use of this function is as a predicate in match_operand
1118 expressions in the machine description. */
1121 address_operand (rtx op, machine_mode mode)
1123 return memory_address_p (mode, op);
1126 /* Return 1 if OP is a register reference of mode MODE.
1127 If MODE is VOIDmode, accept a register in any mode.
1129 The main use of this function is as a predicate in match_operand
1130 expressions in the machine description. */
1133 register_operand (rtx op, machine_mode mode)
1135 if (GET_CODE (op) == SUBREG)
1137 rtx sub = SUBREG_REG (op);
1139 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1140 because it is guaranteed to be reloaded into one.
1141 Just make sure the MEM is valid in itself.
1142 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1143 but currently it does result from (SUBREG (REG)...) where the
1144 reg went on the stack.) */
1145 if (!REG_P (sub) && (reload_completed || !MEM_P (sub)))
1146 return 0;
1148 else if (!REG_P (op))
1149 return 0;
1150 return general_operand (op, mode);
1153 /* Return 1 for a register in Pmode; ignore the tested mode. */
1156 pmode_register_operand (rtx op, machine_mode mode ATTRIBUTE_UNUSED)
1158 return register_operand (op, Pmode);
1161 /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
1162 or a hard register. */
1165 scratch_operand (rtx op, machine_mode mode)
1167 if (GET_MODE (op) != mode && mode != VOIDmode)
1168 return 0;
1170 return (GET_CODE (op) == SCRATCH
1171 || (REG_P (op)
1172 && (lra_in_progress
1173 || (REGNO (op) < FIRST_PSEUDO_REGISTER
1174 && REGNO_REG_CLASS (REGNO (op)) != NO_REGS))));
1177 /* Return 1 if OP is a valid immediate operand for mode MODE.
1179 The main use of this function is as a predicate in match_operand
1180 expressions in the machine description. */
1183 immediate_operand (rtx op, machine_mode mode)
1185 /* Don't accept CONST_INT or anything similar
1186 if the caller wants something floating. */
1187 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1188 && GET_MODE_CLASS (mode) != MODE_INT
1189 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1190 return 0;
1192 if (CONST_INT_P (op)
1193 && mode != VOIDmode
1194 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1195 return 0;
1197 return (CONSTANT_P (op)
1198 && (GET_MODE (op) == mode || mode == VOIDmode
1199 || GET_MODE (op) == VOIDmode)
1200 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1201 && targetm.legitimate_constant_p (mode == VOIDmode
1202 ? GET_MODE (op)
1203 : mode, op));
1206 /* Returns 1 if OP is an operand that is a CONST_INT of mode MODE. */
1209 const_int_operand (rtx op, machine_mode mode)
1211 if (!CONST_INT_P (op))
1212 return 0;
1214 if (mode != VOIDmode
1215 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1216 return 0;
1218 return 1;
1221 #if TARGET_SUPPORTS_WIDE_INT
1222 /* Returns 1 if OP is an operand that is a CONST_INT or CONST_WIDE_INT
1223 of mode MODE. */
1225 const_scalar_int_operand (rtx op, machine_mode mode)
1227 if (!CONST_SCALAR_INT_P (op))
1228 return 0;
1230 if (CONST_INT_P (op))
1231 return const_int_operand (op, mode);
1233 if (mode != VOIDmode)
1235 int prec = GET_MODE_PRECISION (mode);
1236 int bitsize = GET_MODE_BITSIZE (mode);
1238 if (CONST_WIDE_INT_NUNITS (op) * HOST_BITS_PER_WIDE_INT > bitsize)
1239 return 0;
1241 if (prec == bitsize)
1242 return 1;
1243 else
1245 /* Multiword partial int. */
1246 HOST_WIDE_INT x
1247 = CONST_WIDE_INT_ELT (op, CONST_WIDE_INT_NUNITS (op) - 1);
1248 return (sext_hwi (x, prec & (HOST_BITS_PER_WIDE_INT - 1)) == x);
1251 return 1;
1254 /* Returns 1 if OP is an operand that is a constant integer or constant
1255 floating-point number of MODE. */
1258 const_double_operand (rtx op, machine_mode mode)
1260 return (GET_CODE (op) == CONST_DOUBLE)
1261 && (GET_MODE (op) == mode || mode == VOIDmode);
1263 #else
1264 /* Returns 1 if OP is an operand that is a constant integer or constant
1265 floating-point number of MODE. */
1268 const_double_operand (rtx op, machine_mode mode)
1270 /* Don't accept CONST_INT or anything similar
1271 if the caller wants something floating. */
1272 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1273 && GET_MODE_CLASS (mode) != MODE_INT
1274 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1275 return 0;
1277 return ((CONST_DOUBLE_P (op) || CONST_INT_P (op))
1278 && (mode == VOIDmode || GET_MODE (op) == mode
1279 || GET_MODE (op) == VOIDmode));
1281 #endif
1282 /* Return 1 if OP is a general operand that is not an immediate
1283 operand of mode MODE. */
1286 nonimmediate_operand (rtx op, machine_mode mode)
1288 return (general_operand (op, mode) && ! CONSTANT_P (op));
1291 /* Return 1 if OP is a register reference or immediate value of mode MODE. */
1294 nonmemory_operand (rtx op, machine_mode mode)
1296 if (CONSTANT_P (op))
1297 return immediate_operand (op, mode);
1298 return register_operand (op, mode);
1301 /* Return 1 if OP is a valid operand that stands for pushing a
1302 value of mode MODE onto the stack.
1304 The main use of this function is as a predicate in match_operand
1305 expressions in the machine description. */
1308 push_operand (rtx op, machine_mode mode)
1310 unsigned int rounded_size = GET_MODE_SIZE (mode);
1312 #ifdef PUSH_ROUNDING
1313 rounded_size = PUSH_ROUNDING (rounded_size);
1314 #endif
1316 if (!MEM_P (op))
1317 return 0;
1319 if (mode != VOIDmode && GET_MODE (op) != mode)
1320 return 0;
1322 op = XEXP (op, 0);
1324 if (rounded_size == GET_MODE_SIZE (mode))
1326 if (GET_CODE (op) != STACK_PUSH_CODE)
1327 return 0;
1329 else
1331 if (GET_CODE (op) != PRE_MODIFY
1332 || GET_CODE (XEXP (op, 1)) != PLUS
1333 || XEXP (XEXP (op, 1), 0) != XEXP (op, 0)
1334 || !CONST_INT_P (XEXP (XEXP (op, 1), 1))
1335 #ifdef STACK_GROWS_DOWNWARD
1336 || INTVAL (XEXP (XEXP (op, 1), 1)) != - (int) rounded_size
1337 #else
1338 || INTVAL (XEXP (XEXP (op, 1), 1)) != (int) rounded_size
1339 #endif
1341 return 0;
1344 return XEXP (op, 0) == stack_pointer_rtx;
1347 /* Return 1 if OP is a valid operand that stands for popping a
1348 value of mode MODE off the stack.
1350 The main use of this function is as a predicate in match_operand
1351 expressions in the machine description. */
1354 pop_operand (rtx op, machine_mode mode)
1356 if (!MEM_P (op))
1357 return 0;
1359 if (mode != VOIDmode && GET_MODE (op) != mode)
1360 return 0;
1362 op = XEXP (op, 0);
1364 if (GET_CODE (op) != STACK_POP_CODE)
1365 return 0;
1367 return XEXP (op, 0) == stack_pointer_rtx;
1370 /* Return 1 if ADDR is a valid memory address
1371 for mode MODE in address space AS. */
1374 memory_address_addr_space_p (machine_mode mode ATTRIBUTE_UNUSED,
1375 rtx addr, addr_space_t as)
1377 #ifdef GO_IF_LEGITIMATE_ADDRESS
1378 gcc_assert (ADDR_SPACE_GENERIC_P (as));
1379 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1380 return 0;
1382 win:
1383 return 1;
1384 #else
1385 return targetm.addr_space.legitimate_address_p (mode, addr, 0, as);
1386 #endif
1389 /* Return 1 if OP is a valid memory reference with mode MODE,
1390 including a valid address.
1392 The main use of this function is as a predicate in match_operand
1393 expressions in the machine description. */
1396 memory_operand (rtx op, machine_mode mode)
1398 rtx inner;
1400 if (! reload_completed)
1401 /* Note that no SUBREG is a memory operand before end of reload pass,
1402 because (SUBREG (MEM...)) forces reloading into a register. */
1403 return MEM_P (op) && general_operand (op, mode);
1405 if (mode != VOIDmode && GET_MODE (op) != mode)
1406 return 0;
1408 inner = op;
1409 if (GET_CODE (inner) == SUBREG)
1410 inner = SUBREG_REG (inner);
1412 return (MEM_P (inner) && general_operand (op, mode));
1415 /* Return 1 if OP is a valid indirect memory reference with mode MODE;
1416 that is, a memory reference whose address is a general_operand. */
1419 indirect_operand (rtx op, machine_mode mode)
1421 /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1422 if (! reload_completed
1423 && GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))
1425 int offset = SUBREG_BYTE (op);
1426 rtx inner = SUBREG_REG (op);
1428 if (mode != VOIDmode && GET_MODE (op) != mode)
1429 return 0;
1431 /* The only way that we can have a general_operand as the resulting
1432 address is if OFFSET is zero and the address already is an operand
1433 or if the address is (plus Y (const_int -OFFSET)) and Y is an
1434 operand. */
1436 return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1437 || (GET_CODE (XEXP (inner, 0)) == PLUS
1438 && CONST_INT_P (XEXP (XEXP (inner, 0), 1))
1439 && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1440 && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1443 return (MEM_P (op)
1444 && memory_operand (op, mode)
1445 && general_operand (XEXP (op, 0), Pmode));
1448 /* Return 1 if this is an ordered comparison operator (not including
1449 ORDERED and UNORDERED). */
1452 ordered_comparison_operator (rtx op, machine_mode mode)
1454 if (mode != VOIDmode && GET_MODE (op) != mode)
1455 return false;
1456 switch (GET_CODE (op))
1458 case EQ:
1459 case NE:
1460 case LT:
1461 case LTU:
1462 case LE:
1463 case LEU:
1464 case GT:
1465 case GTU:
1466 case GE:
1467 case GEU:
1468 return true;
1469 default:
1470 return false;
1474 /* Return 1 if this is a comparison operator. This allows the use of
1475 MATCH_OPERATOR to recognize all the branch insns. */
1478 comparison_operator (rtx op, machine_mode mode)
1480 return ((mode == VOIDmode || GET_MODE (op) == mode)
1481 && COMPARISON_P (op));
1484 /* If BODY is an insn body that uses ASM_OPERANDS, return it. */
1487 extract_asm_operands (rtx body)
1489 rtx tmp;
1490 switch (GET_CODE (body))
1492 case ASM_OPERANDS:
1493 return body;
1495 case SET:
1496 /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
1497 tmp = SET_SRC (body);
1498 if (GET_CODE (tmp) == ASM_OPERANDS)
1499 return tmp;
1500 break;
1502 case PARALLEL:
1503 tmp = XVECEXP (body, 0, 0);
1504 if (GET_CODE (tmp) == ASM_OPERANDS)
1505 return tmp;
1506 if (GET_CODE (tmp) == SET)
1508 tmp = SET_SRC (tmp);
1509 if (GET_CODE (tmp) == ASM_OPERANDS)
1510 return tmp;
1512 break;
1514 default:
1515 break;
1517 return NULL;
1520 /* If BODY is an insn body that uses ASM_OPERANDS,
1521 return the number of operands (both input and output) in the insn.
1522 Otherwise return -1. */
1525 asm_noperands (const_rtx body)
1527 rtx asm_op = extract_asm_operands (CONST_CAST_RTX (body));
1528 int n_sets = 0;
1530 if (asm_op == NULL)
1531 return -1;
1533 if (GET_CODE (body) == SET)
1534 n_sets = 1;
1535 else if (GET_CODE (body) == PARALLEL)
1537 int i;
1538 if (GET_CODE (XVECEXP (body, 0, 0)) == SET)
1540 /* Multiple output operands, or 1 output plus some clobbers:
1541 body is
1542 [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
1543 /* Count backwards through CLOBBERs to determine number of SETs. */
1544 for (i = XVECLEN (body, 0); i > 0; i--)
1546 if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1547 break;
1548 if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1549 return -1;
1552 /* N_SETS is now number of output operands. */
1553 n_sets = i;
1555 /* Verify that all the SETs we have
1556 came from a single original asm_operands insn
1557 (so that invalid combinations are blocked). */
1558 for (i = 0; i < n_sets; i++)
1560 rtx elt = XVECEXP (body, 0, i);
1561 if (GET_CODE (elt) != SET)
1562 return -1;
1563 if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1564 return -1;
1565 /* If these ASM_OPERANDS rtx's came from different original insns
1566 then they aren't allowed together. */
1567 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1568 != ASM_OPERANDS_INPUT_VEC (asm_op))
1569 return -1;
1572 else
1574 /* 0 outputs, but some clobbers:
1575 body is [(asm_operands ...) (clobber (reg ...))...]. */
1576 /* Make sure all the other parallel things really are clobbers. */
1577 for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1578 if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1579 return -1;
1583 return (ASM_OPERANDS_INPUT_LENGTH (asm_op)
1584 + ASM_OPERANDS_LABEL_LENGTH (asm_op) + n_sets);
1587 /* Assuming BODY is an insn body that uses ASM_OPERANDS,
1588 copy its operands (both input and output) into the vector OPERANDS,
1589 the locations of the operands within the insn into the vector OPERAND_LOCS,
1590 and the constraints for the operands into CONSTRAINTS.
1591 Write the modes of the operands into MODES.
1592 Return the assembler-template.
1594 If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1595 we don't store that info. */
1597 const char *
1598 decode_asm_operands (rtx body, rtx *operands, rtx **operand_locs,
1599 const char **constraints, machine_mode *modes,
1600 location_t *loc)
1602 int nbase = 0, n, i;
1603 rtx asmop;
1605 switch (GET_CODE (body))
1607 case ASM_OPERANDS:
1608 /* Zero output asm: BODY is (asm_operands ...). */
1609 asmop = body;
1610 break;
1612 case SET:
1613 /* Single output asm: BODY is (set OUTPUT (asm_operands ...)). */
1614 asmop = SET_SRC (body);
1616 /* The output is in the SET.
1617 Its constraint is in the ASM_OPERANDS itself. */
1618 if (operands)
1619 operands[0] = SET_DEST (body);
1620 if (operand_locs)
1621 operand_locs[0] = &SET_DEST (body);
1622 if (constraints)
1623 constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1624 if (modes)
1625 modes[0] = GET_MODE (SET_DEST (body));
1626 nbase = 1;
1627 break;
1629 case PARALLEL:
1631 int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
1633 asmop = XVECEXP (body, 0, 0);
1634 if (GET_CODE (asmop) == SET)
1636 asmop = SET_SRC (asmop);
1638 /* At least one output, plus some CLOBBERs. The outputs are in
1639 the SETs. Their constraints are in the ASM_OPERANDS itself. */
1640 for (i = 0; i < nparallel; i++)
1642 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1643 break; /* Past last SET */
1644 if (operands)
1645 operands[i] = SET_DEST (XVECEXP (body, 0, i));
1646 if (operand_locs)
1647 operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1648 if (constraints)
1649 constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1650 if (modes)
1651 modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1653 nbase = i;
1655 break;
1658 default:
1659 gcc_unreachable ();
1662 n = ASM_OPERANDS_INPUT_LENGTH (asmop);
1663 for (i = 0; i < n; i++)
1665 if (operand_locs)
1666 operand_locs[nbase + i] = &ASM_OPERANDS_INPUT (asmop, i);
1667 if (operands)
1668 operands[nbase + i] = ASM_OPERANDS_INPUT (asmop, i);
1669 if (constraints)
1670 constraints[nbase + i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1671 if (modes)
1672 modes[nbase + i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1674 nbase += n;
1676 n = ASM_OPERANDS_LABEL_LENGTH (asmop);
1677 for (i = 0; i < n; i++)
1679 if (operand_locs)
1680 operand_locs[nbase + i] = &ASM_OPERANDS_LABEL (asmop, i);
1681 if (operands)
1682 operands[nbase + i] = ASM_OPERANDS_LABEL (asmop, i);
1683 if (constraints)
1684 constraints[nbase + i] = "";
1685 if (modes)
1686 modes[nbase + i] = Pmode;
1689 if (loc)
1690 *loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
1692 return ASM_OPERANDS_TEMPLATE (asmop);
1695 /* Parse inline assembly string STRING and determine which operands are
1696 referenced by % markers. For the first NOPERANDS operands, set USED[I]
1697 to true if operand I is referenced.
1699 This is intended to distinguish barrier-like asms such as:
1701 asm ("" : "=m" (...));
1703 from real references such as:
1705 asm ("sw\t$0, %0" : "=m" (...)); */
1707 void
1708 get_referenced_operands (const char *string, bool *used,
1709 unsigned int noperands)
1711 memset (used, 0, sizeof (bool) * noperands);
1712 const char *p = string;
1713 while (*p)
1714 switch (*p)
1716 case '%':
1717 p += 1;
1718 /* A letter followed by a digit indicates an operand number. */
1719 if (ISALPHA (p[0]) && ISDIGIT (p[1]))
1720 p += 1;
1721 if (ISDIGIT (*p))
1723 char *endptr;
1724 unsigned long opnum = strtoul (p, &endptr, 10);
1725 if (endptr != p && opnum < noperands)
1726 used[opnum] = true;
1727 p = endptr;
1729 else
1730 p += 1;
1731 break;
1733 default:
1734 p++;
1735 break;
1739 /* Check if an asm_operand matches its constraints.
1740 Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
1743 asm_operand_ok (rtx op, const char *constraint, const char **constraints)
1745 int result = 0;
1746 #ifdef AUTO_INC_DEC
1747 bool incdec_ok = false;
1748 #endif
1750 /* Use constrain_operands after reload. */
1751 gcc_assert (!reload_completed);
1753 /* Empty constraint string is the same as "X,...,X", i.e. X for as
1754 many alternatives as required to match the other operands. */
1755 if (*constraint == '\0')
1756 result = 1;
1758 while (*constraint)
1760 enum constraint_num cn;
1761 char c = *constraint;
1762 int len;
1763 switch (c)
1765 case ',':
1766 constraint++;
1767 continue;
1769 case '0': case '1': case '2': case '3': case '4':
1770 case '5': case '6': case '7': case '8': case '9':
1771 /* If caller provided constraints pointer, look up
1772 the matching constraint. Otherwise, our caller should have
1773 given us the proper matching constraint, but we can't
1774 actually fail the check if they didn't. Indicate that
1775 results are inconclusive. */
1776 if (constraints)
1778 char *end;
1779 unsigned long match;
1781 match = strtoul (constraint, &end, 10);
1782 if (!result)
1783 result = asm_operand_ok (op, constraints[match], NULL);
1784 constraint = (const char *) end;
1786 else
1789 constraint++;
1790 while (ISDIGIT (*constraint));
1791 if (! result)
1792 result = -1;
1794 continue;
1796 /* The rest of the compiler assumes that reloading the address
1797 of a MEM into a register will make it fit an 'o' constraint.
1798 That is, if it sees a MEM operand for an 'o' constraint,
1799 it assumes that (mem (base-reg)) will fit.
1801 That assumption fails on targets that don't have offsettable
1802 addresses at all. We therefore need to treat 'o' asm
1803 constraints as a special case and only accept operands that
1804 are already offsettable, thus proving that at least one
1805 offsettable address exists. */
1806 case 'o': /* offsettable */
1807 if (offsettable_nonstrict_memref_p (op))
1808 result = 1;
1809 break;
1811 case 'g':
1812 if (general_operand (op, VOIDmode))
1813 result = 1;
1814 break;
1816 #ifdef AUTO_INC_DEC
1817 case '<':
1818 case '>':
1819 /* ??? Before auto-inc-dec, auto inc/dec insns are not supposed
1820 to exist, excepting those that expand_call created. Further,
1821 on some machines which do not have generalized auto inc/dec,
1822 an inc/dec is not a memory_operand.
1824 Match any memory and hope things are resolved after reload. */
1825 incdec_ok = true;
1826 #endif
1827 default:
1828 cn = lookup_constraint (constraint);
1829 switch (get_constraint_type (cn))
1831 case CT_REGISTER:
1832 if (!result
1833 && reg_class_for_constraint (cn) != NO_REGS
1834 && GET_MODE (op) != BLKmode
1835 && register_operand (op, VOIDmode))
1836 result = 1;
1837 break;
1839 case CT_CONST_INT:
1840 if (!result
1841 && CONST_INT_P (op)
1842 && insn_const_int_ok_for_constraint (INTVAL (op), cn))
1843 result = 1;
1844 break;
1846 case CT_MEMORY:
1847 /* Every memory operand can be reloaded to fit. */
1848 result = result || memory_operand (op, VOIDmode);
1849 break;
1851 case CT_ADDRESS:
1852 /* Every address operand can be reloaded to fit. */
1853 result = result || address_operand (op, VOIDmode);
1854 break;
1856 case CT_FIXED_FORM:
1857 result = result || constraint_satisfied_p (op, cn);
1858 break;
1860 break;
1862 len = CONSTRAINT_LEN (c, constraint);
1864 constraint++;
1865 while (--len && *constraint);
1866 if (len)
1867 return 0;
1870 #ifdef AUTO_INC_DEC
1871 /* For operands without < or > constraints reject side-effects. */
1872 if (!incdec_ok && result && MEM_P (op))
1873 switch (GET_CODE (XEXP (op, 0)))
1875 case PRE_INC:
1876 case POST_INC:
1877 case PRE_DEC:
1878 case POST_DEC:
1879 case PRE_MODIFY:
1880 case POST_MODIFY:
1881 return 0;
1882 default:
1883 break;
1885 #endif
1887 return result;
1890 /* Given an rtx *P, if it is a sum containing an integer constant term,
1891 return the location (type rtx *) of the pointer to that constant term.
1892 Otherwise, return a null pointer. */
1894 rtx *
1895 find_constant_term_loc (rtx *p)
1897 rtx *tem;
1898 enum rtx_code code = GET_CODE (*p);
1900 /* If *P IS such a constant term, P is its location. */
1902 if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1903 || code == CONST)
1904 return p;
1906 /* Otherwise, if not a sum, it has no constant term. */
1908 if (GET_CODE (*p) != PLUS)
1909 return 0;
1911 /* If one of the summands is constant, return its location. */
1913 if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1914 && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1915 return p;
1917 /* Otherwise, check each summand for containing a constant term. */
1919 if (XEXP (*p, 0) != 0)
1921 tem = find_constant_term_loc (&XEXP (*p, 0));
1922 if (tem != 0)
1923 return tem;
1926 if (XEXP (*p, 1) != 0)
1928 tem = find_constant_term_loc (&XEXP (*p, 1));
1929 if (tem != 0)
1930 return tem;
1933 return 0;
1936 /* Return 1 if OP is a memory reference
1937 whose address contains no side effects
1938 and remains valid after the addition
1939 of a positive integer less than the
1940 size of the object being referenced.
1942 We assume that the original address is valid and do not check it.
1944 This uses strict_memory_address_p as a subroutine, so
1945 don't use it before reload. */
1948 offsettable_memref_p (rtx op)
1950 return ((MEM_P (op))
1951 && offsettable_address_addr_space_p (1, GET_MODE (op), XEXP (op, 0),
1952 MEM_ADDR_SPACE (op)));
1955 /* Similar, but don't require a strictly valid mem ref:
1956 consider pseudo-regs valid as index or base regs. */
1959 offsettable_nonstrict_memref_p (rtx op)
1961 return ((MEM_P (op))
1962 && offsettable_address_addr_space_p (0, GET_MODE (op), XEXP (op, 0),
1963 MEM_ADDR_SPACE (op)));
1966 /* Return 1 if Y is a memory address which contains no side effects
1967 and would remain valid for address space AS after the addition of
1968 a positive integer less than the size of that mode.
1970 We assume that the original address is valid and do not check it.
1971 We do check that it is valid for narrower modes.
1973 If STRICTP is nonzero, we require a strictly valid address,
1974 for the sake of use in reload.c. */
1977 offsettable_address_addr_space_p (int strictp, machine_mode mode, rtx y,
1978 addr_space_t as)
1980 enum rtx_code ycode = GET_CODE (y);
1981 rtx z;
1982 rtx y1 = y;
1983 rtx *y2;
1984 int (*addressp) (machine_mode, rtx, addr_space_t) =
1985 (strictp ? strict_memory_address_addr_space_p
1986 : memory_address_addr_space_p);
1987 unsigned int mode_sz = GET_MODE_SIZE (mode);
1989 if (CONSTANT_ADDRESS_P (y))
1990 return 1;
1992 /* Adjusting an offsettable address involves changing to a narrower mode.
1993 Make sure that's OK. */
1995 if (mode_dependent_address_p (y, as))
1996 return 0;
1998 machine_mode address_mode = GET_MODE (y);
1999 if (address_mode == VOIDmode)
2000 address_mode = targetm.addr_space.address_mode (as);
2001 #ifdef POINTERS_EXTEND_UNSIGNED
2002 machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
2003 #endif
2005 /* ??? How much offset does an offsettable BLKmode reference need?
2006 Clearly that depends on the situation in which it's being used.
2007 However, the current situation in which we test 0xffffffff is
2008 less than ideal. Caveat user. */
2009 if (mode_sz == 0)
2010 mode_sz = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2012 /* If the expression contains a constant term,
2013 see if it remains valid when max possible offset is added. */
2015 if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
2017 int good;
2019 y1 = *y2;
2020 *y2 = plus_constant (address_mode, *y2, mode_sz - 1);
2021 /* Use QImode because an odd displacement may be automatically invalid
2022 for any wider mode. But it should be valid for a single byte. */
2023 good = (*addressp) (QImode, y, as);
2025 /* In any case, restore old contents of memory. */
2026 *y2 = y1;
2027 return good;
2030 if (GET_RTX_CLASS (ycode) == RTX_AUTOINC)
2031 return 0;
2033 /* The offset added here is chosen as the maximum offset that
2034 any instruction could need to add when operating on something
2035 of the specified mode. We assume that if Y and Y+c are
2036 valid addresses then so is Y+d for all 0<d<c. adjust_address will
2037 go inside a LO_SUM here, so we do so as well. */
2038 if (GET_CODE (y) == LO_SUM
2039 && mode != BLKmode
2040 && mode_sz <= GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT)
2041 z = gen_rtx_LO_SUM (address_mode, XEXP (y, 0),
2042 plus_constant (address_mode, XEXP (y, 1),
2043 mode_sz - 1));
2044 #ifdef POINTERS_EXTEND_UNSIGNED
2045 /* Likewise for a ZERO_EXTEND from pointer_mode. */
2046 else if (POINTERS_EXTEND_UNSIGNED > 0
2047 && GET_CODE (y) == ZERO_EXTEND
2048 && GET_MODE (XEXP (y, 0)) == pointer_mode)
2049 z = gen_rtx_ZERO_EXTEND (address_mode,
2050 plus_constant (pointer_mode, XEXP (y, 0),
2051 mode_sz - 1));
2052 #endif
2053 else
2054 z = plus_constant (address_mode, y, mode_sz - 1);
2056 /* Use QImode because an odd displacement may be automatically invalid
2057 for any wider mode. But it should be valid for a single byte. */
2058 return (*addressp) (QImode, z, as);
2061 /* Return 1 if ADDR is an address-expression whose effect depends
2062 on the mode of the memory reference it is used in.
2064 ADDRSPACE is the address space associated with the address.
2066 Autoincrement addressing is a typical example of mode-dependence
2067 because the amount of the increment depends on the mode. */
2069 bool
2070 mode_dependent_address_p (rtx addr, addr_space_t addrspace)
2072 /* Auto-increment addressing with anything other than post_modify
2073 or pre_modify always introduces a mode dependency. Catch such
2074 cases now instead of deferring to the target. */
2075 if (GET_CODE (addr) == PRE_INC
2076 || GET_CODE (addr) == POST_INC
2077 || GET_CODE (addr) == PRE_DEC
2078 || GET_CODE (addr) == POST_DEC)
2079 return true;
2081 return targetm.mode_dependent_address_p (addr, addrspace);
2084 /* Return true if boolean attribute ATTR is supported. */
2086 static bool
2087 have_bool_attr (bool_attr attr)
2089 switch (attr)
2091 case BA_ENABLED:
2092 return HAVE_ATTR_enabled;
2093 case BA_PREFERRED_FOR_SIZE:
2094 return HAVE_ATTR_enabled || HAVE_ATTR_preferred_for_size;
2095 case BA_PREFERRED_FOR_SPEED:
2096 return HAVE_ATTR_enabled || HAVE_ATTR_preferred_for_speed;
2098 gcc_unreachable ();
2101 /* Return the value of ATTR for instruction INSN. */
2103 static bool
2104 get_bool_attr (rtx_insn *insn, bool_attr attr)
2106 switch (attr)
2108 case BA_ENABLED:
2109 return get_attr_enabled (insn);
2110 case BA_PREFERRED_FOR_SIZE:
2111 return get_attr_enabled (insn) && get_attr_preferred_for_size (insn);
2112 case BA_PREFERRED_FOR_SPEED:
2113 return get_attr_enabled (insn) && get_attr_preferred_for_speed (insn);
2115 gcc_unreachable ();
2118 /* Like get_bool_attr_mask, but don't use the cache. */
2120 static alternative_mask
2121 get_bool_attr_mask_uncached (rtx_insn *insn, bool_attr attr)
2123 /* Temporarily install enough information for get_attr_<foo> to assume
2124 that the insn operands are already cached. As above, the attribute
2125 mustn't depend on the values of operands, so we don't provide their
2126 real values here. */
2127 rtx_insn *old_insn = recog_data.insn;
2128 int old_alternative = which_alternative;
2130 recog_data.insn = insn;
2131 alternative_mask mask = ALL_ALTERNATIVES;
2132 int n_alternatives = insn_data[INSN_CODE (insn)].n_alternatives;
2133 for (int i = 0; i < n_alternatives; i++)
2135 which_alternative = i;
2136 if (!get_bool_attr (insn, attr))
2137 mask &= ~ALTERNATIVE_BIT (i);
2140 recog_data.insn = old_insn;
2141 which_alternative = old_alternative;
2142 return mask;
2145 /* Return the mask of operand alternatives that are allowed for INSN
2146 by boolean attribute ATTR. This mask depends only on INSN and on
2147 the current target; it does not depend on things like the values of
2148 operands. */
2150 static alternative_mask
2151 get_bool_attr_mask (rtx_insn *insn, bool_attr attr)
2153 /* Quick exit for asms and for targets that don't use these attributes. */
2154 int code = INSN_CODE (insn);
2155 if (code < 0 || !have_bool_attr (attr))
2156 return ALL_ALTERNATIVES;
2158 /* Calling get_attr_<foo> can be expensive, so cache the mask
2159 for speed. */
2160 if (!this_target_recog->x_bool_attr_masks[code][attr])
2161 this_target_recog->x_bool_attr_masks[code][attr]
2162 = get_bool_attr_mask_uncached (insn, attr);
2163 return this_target_recog->x_bool_attr_masks[code][attr];
2166 /* Return the set of alternatives of INSN that are allowed by the current
2167 target. */
2169 alternative_mask
2170 get_enabled_alternatives (rtx_insn *insn)
2172 return get_bool_attr_mask (insn, BA_ENABLED);
2175 /* Return the set of alternatives of INSN that are allowed by the current
2176 target and are preferred for the current size/speed optimization
2177 choice. */
2179 alternative_mask
2180 get_preferred_alternatives (rtx_insn *insn)
2182 if (optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn)))
2183 return get_bool_attr_mask (insn, BA_PREFERRED_FOR_SPEED);
2184 else
2185 return get_bool_attr_mask (insn, BA_PREFERRED_FOR_SIZE);
2188 /* Return the set of alternatives of INSN that are allowed by the current
2189 target and are preferred for the size/speed optimization choice
2190 associated with BB. Passing a separate BB is useful if INSN has not
2191 been emitted yet or if we are considering moving it to a different
2192 block. */
2194 alternative_mask
2195 get_preferred_alternatives (rtx_insn *insn, basic_block bb)
2197 if (optimize_bb_for_speed_p (bb))
2198 return get_bool_attr_mask (insn, BA_PREFERRED_FOR_SPEED);
2199 else
2200 return get_bool_attr_mask (insn, BA_PREFERRED_FOR_SIZE);
2203 /* Assert that the cached boolean attributes for INSN are still accurate.
2204 The backend is required to define these attributes in a way that only
2205 depends on the current target (rather than operands, compiler phase,
2206 etc.). */
2208 bool
2209 check_bool_attrs (rtx_insn *insn)
2211 int code = INSN_CODE (insn);
2212 if (code >= 0)
2213 for (int i = 0; i <= BA_LAST; ++i)
2215 enum bool_attr attr = (enum bool_attr) i;
2216 if (this_target_recog->x_bool_attr_masks[code][attr])
2217 gcc_assert (this_target_recog->x_bool_attr_masks[code][attr]
2218 == get_bool_attr_mask_uncached (insn, attr));
2220 return true;
2223 /* Like extract_insn, but save insn extracted and don't extract again, when
2224 called again for the same insn expecting that recog_data still contain the
2225 valid information. This is used primary by gen_attr infrastructure that
2226 often does extract insn again and again. */
2227 void
2228 extract_insn_cached (rtx_insn *insn)
2230 if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
2231 return;
2232 extract_insn (insn);
2233 recog_data.insn = insn;
2236 /* Do uncached extract_insn, constrain_operands and complain about failures.
2237 This should be used when extracting a pre-existing constrained instruction
2238 if the caller wants to know which alternative was chosen. */
2239 void
2240 extract_constrain_insn (rtx_insn *insn)
2242 extract_insn (insn);
2243 if (!constrain_operands (reload_completed, get_enabled_alternatives (insn)))
2244 fatal_insn_not_found (insn);
2247 /* Do cached extract_insn, constrain_operands and complain about failures.
2248 Used by insn_attrtab. */
2249 void
2250 extract_constrain_insn_cached (rtx_insn *insn)
2252 extract_insn_cached (insn);
2253 if (which_alternative == -1
2254 && !constrain_operands (reload_completed,
2255 get_enabled_alternatives (insn)))
2256 fatal_insn_not_found (insn);
2259 /* Do cached constrain_operands on INSN and complain about failures. */
2261 constrain_operands_cached (rtx_insn *insn, int strict)
2263 if (which_alternative == -1)
2264 return constrain_operands (strict, get_enabled_alternatives (insn));
2265 else
2266 return 1;
2269 /* Analyze INSN and fill in recog_data. */
2271 void
2272 extract_insn (rtx_insn *insn)
2274 int i;
2275 int icode;
2276 int noperands;
2277 rtx body = PATTERN (insn);
2279 recog_data.n_operands = 0;
2280 recog_data.n_alternatives = 0;
2281 recog_data.n_dups = 0;
2282 recog_data.is_asm = false;
2284 switch (GET_CODE (body))
2286 case USE:
2287 case CLOBBER:
2288 case ASM_INPUT:
2289 case ADDR_VEC:
2290 case ADDR_DIFF_VEC:
2291 case VAR_LOCATION:
2292 return;
2294 case SET:
2295 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
2296 goto asm_insn;
2297 else
2298 goto normal_insn;
2299 case PARALLEL:
2300 if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
2301 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
2302 || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
2303 goto asm_insn;
2304 else
2305 goto normal_insn;
2306 case ASM_OPERANDS:
2307 asm_insn:
2308 recog_data.n_operands = noperands = asm_noperands (body);
2309 if (noperands >= 0)
2311 /* This insn is an `asm' with operands. */
2313 /* expand_asm_operands makes sure there aren't too many operands. */
2314 gcc_assert (noperands <= MAX_RECOG_OPERANDS);
2316 /* Now get the operand values and constraints out of the insn. */
2317 decode_asm_operands (body, recog_data.operand,
2318 recog_data.operand_loc,
2319 recog_data.constraints,
2320 recog_data.operand_mode, NULL);
2321 memset (recog_data.is_operator, 0, sizeof recog_data.is_operator);
2322 if (noperands > 0)
2324 const char *p = recog_data.constraints[0];
2325 recog_data.n_alternatives = 1;
2326 while (*p)
2327 recog_data.n_alternatives += (*p++ == ',');
2329 recog_data.is_asm = true;
2330 break;
2332 fatal_insn_not_found (insn);
2334 default:
2335 normal_insn:
2336 /* Ordinary insn: recognize it, get the operands via insn_extract
2337 and get the constraints. */
2339 icode = recog_memoized (insn);
2340 if (icode < 0)
2341 fatal_insn_not_found (insn);
2343 recog_data.n_operands = noperands = insn_data[icode].n_operands;
2344 recog_data.n_alternatives = insn_data[icode].n_alternatives;
2345 recog_data.n_dups = insn_data[icode].n_dups;
2347 insn_extract (insn);
2349 for (i = 0; i < noperands; i++)
2351 recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
2352 recog_data.is_operator[i] = insn_data[icode].operand[i].is_operator;
2353 recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
2354 /* VOIDmode match_operands gets mode from their real operand. */
2355 if (recog_data.operand_mode[i] == VOIDmode)
2356 recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2359 for (i = 0; i < noperands; i++)
2360 recog_data.operand_type[i]
2361 = (recog_data.constraints[i][0] == '=' ? OP_OUT
2362 : recog_data.constraints[i][0] == '+' ? OP_INOUT
2363 : OP_IN);
2365 gcc_assert (recog_data.n_alternatives <= MAX_RECOG_ALTERNATIVES);
2367 recog_data.insn = NULL;
2368 which_alternative = -1;
2371 /* Fill in OP_ALT_BASE for an instruction that has N_OPERANDS operands,
2372 N_ALTERNATIVES alternatives and constraint strings CONSTRAINTS.
2373 OP_ALT_BASE has N_ALTERNATIVES * N_OPERANDS entries and CONSTRAINTS
2374 has N_OPERANDS entries. */
2376 void
2377 preprocess_constraints (int n_operands, int n_alternatives,
2378 const char **constraints,
2379 operand_alternative *op_alt_base)
2381 for (int i = 0; i < n_operands; i++)
2383 int j;
2384 struct operand_alternative *op_alt;
2385 const char *p = constraints[i];
2387 op_alt = op_alt_base;
2389 for (j = 0; j < n_alternatives; j++, op_alt += n_operands)
2391 op_alt[i].cl = NO_REGS;
2392 op_alt[i].constraint = p;
2393 op_alt[i].matches = -1;
2394 op_alt[i].matched = -1;
2396 if (*p == '\0' || *p == ',')
2398 op_alt[i].anything_ok = 1;
2399 continue;
2402 for (;;)
2404 char c = *p;
2405 if (c == '#')
2407 c = *++p;
2408 while (c != ',' && c != '\0');
2409 if (c == ',' || c == '\0')
2411 p++;
2412 break;
2415 switch (c)
2417 case '?':
2418 op_alt[i].reject += 6;
2419 break;
2420 case '!':
2421 op_alt[i].reject += 600;
2422 break;
2423 case '&':
2424 op_alt[i].earlyclobber = 1;
2425 break;
2427 case '0': case '1': case '2': case '3': case '4':
2428 case '5': case '6': case '7': case '8': case '9':
2430 char *end;
2431 op_alt[i].matches = strtoul (p, &end, 10);
2432 op_alt[op_alt[i].matches].matched = i;
2433 p = end;
2435 continue;
2437 case 'X':
2438 op_alt[i].anything_ok = 1;
2439 break;
2441 case 'g':
2442 op_alt[i].cl =
2443 reg_class_subunion[(int) op_alt[i].cl][(int) GENERAL_REGS];
2444 break;
2446 default:
2447 enum constraint_num cn = lookup_constraint (p);
2448 enum reg_class cl;
2449 switch (get_constraint_type (cn))
2451 case CT_REGISTER:
2452 cl = reg_class_for_constraint (cn);
2453 if (cl != NO_REGS)
2454 op_alt[i].cl = reg_class_subunion[op_alt[i].cl][cl];
2455 break;
2457 case CT_CONST_INT:
2458 break;
2460 case CT_MEMORY:
2461 op_alt[i].memory_ok = 1;
2462 break;
2464 case CT_ADDRESS:
2465 op_alt[i].is_address = 1;
2466 op_alt[i].cl
2467 = (reg_class_subunion
2468 [(int) op_alt[i].cl]
2469 [(int) base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
2470 ADDRESS, SCRATCH)]);
2471 break;
2473 case CT_FIXED_FORM:
2474 break;
2476 break;
2478 p += CONSTRAINT_LEN (c, p);
2484 /* Return an array of operand_alternative instructions for
2485 instruction ICODE. */
2487 const operand_alternative *
2488 preprocess_insn_constraints (int icode)
2490 gcc_checking_assert (IN_RANGE (icode, 0, LAST_INSN_CODE));
2491 if (this_target_recog->x_op_alt[icode])
2492 return this_target_recog->x_op_alt[icode];
2494 int n_operands = insn_data[icode].n_operands;
2495 if (n_operands == 0)
2496 return 0;
2497 /* Always provide at least one alternative so that which_op_alt ()
2498 works correctly. If the instruction has 0 alternatives (i.e. all
2499 constraint strings are empty) then each operand in this alternative
2500 will have anything_ok set. */
2501 int n_alternatives = MAX (insn_data[icode].n_alternatives, 1);
2502 int n_entries = n_operands * n_alternatives;
2504 operand_alternative *op_alt = XCNEWVEC (operand_alternative, n_entries);
2505 const char **constraints = XALLOCAVEC (const char *, n_operands);
2507 for (int i = 0; i < n_operands; ++i)
2508 constraints[i] = insn_data[icode].operand[i].constraint;
2509 preprocess_constraints (n_operands, n_alternatives, constraints, op_alt);
2511 this_target_recog->x_op_alt[icode] = op_alt;
2512 return op_alt;
2515 /* After calling extract_insn, you can use this function to extract some
2516 information from the constraint strings into a more usable form.
2517 The collected data is stored in recog_op_alt. */
2519 void
2520 preprocess_constraints (rtx_insn *insn)
2522 int icode = INSN_CODE (insn);
2523 if (icode >= 0)
2524 recog_op_alt = preprocess_insn_constraints (icode);
2525 else
2527 int n_operands = recog_data.n_operands;
2528 int n_alternatives = recog_data.n_alternatives;
2529 int n_entries = n_operands * n_alternatives;
2530 memset (asm_op_alt, 0, n_entries * sizeof (operand_alternative));
2531 preprocess_constraints (n_operands, n_alternatives,
2532 recog_data.constraints, asm_op_alt);
2533 recog_op_alt = asm_op_alt;
2537 /* Check the operands of an insn against the insn's operand constraints
2538 and return 1 if they match any of the alternatives in ALTERNATIVES.
2540 The information about the insn's operands, constraints, operand modes
2541 etc. is obtained from the global variables set up by extract_insn.
2543 WHICH_ALTERNATIVE is set to a number which indicates which
2544 alternative of constraints was matched: 0 for the first alternative,
2545 1 for the next, etc.
2547 In addition, when two operands are required to match
2548 and it happens that the output operand is (reg) while the
2549 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2550 make the output operand look like the input.
2551 This is because the output operand is the one the template will print.
2553 This is used in final, just before printing the assembler code and by
2554 the routines that determine an insn's attribute.
2556 If STRICT is a positive nonzero value, it means that we have been
2557 called after reload has been completed. In that case, we must
2558 do all checks strictly. If it is zero, it means that we have been called
2559 before reload has completed. In that case, we first try to see if we can
2560 find an alternative that matches strictly. If not, we try again, this
2561 time assuming that reload will fix up the insn. This provides a "best
2562 guess" for the alternative and is used to compute attributes of insns prior
2563 to reload. A negative value of STRICT is used for this internal call. */
2565 struct funny_match
2567 int this_op, other;
2571 constrain_operands (int strict, alternative_mask alternatives)
2573 const char *constraints[MAX_RECOG_OPERANDS];
2574 int matching_operands[MAX_RECOG_OPERANDS];
2575 int earlyclobber[MAX_RECOG_OPERANDS];
2576 int c;
2578 struct funny_match funny_match[MAX_RECOG_OPERANDS];
2579 int funny_match_index;
2581 which_alternative = 0;
2582 if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
2583 return 1;
2585 for (c = 0; c < recog_data.n_operands; c++)
2587 constraints[c] = recog_data.constraints[c];
2588 matching_operands[c] = -1;
2593 int seen_earlyclobber_at = -1;
2594 int opno;
2595 int lose = 0;
2596 funny_match_index = 0;
2598 if (!TEST_BIT (alternatives, which_alternative))
2600 int i;
2602 for (i = 0; i < recog_data.n_operands; i++)
2603 constraints[i] = skip_alternative (constraints[i]);
2605 which_alternative++;
2606 continue;
2609 for (opno = 0; opno < recog_data.n_operands; opno++)
2611 rtx op = recog_data.operand[opno];
2612 machine_mode mode = GET_MODE (op);
2613 const char *p = constraints[opno];
2614 int offset = 0;
2615 int win = 0;
2616 int val;
2617 int len;
2619 earlyclobber[opno] = 0;
2621 /* A unary operator may be accepted by the predicate, but it
2622 is irrelevant for matching constraints. */
2623 if (UNARY_P (op))
2624 op = XEXP (op, 0);
2626 if (GET_CODE (op) == SUBREG)
2628 if (REG_P (SUBREG_REG (op))
2629 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
2630 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
2631 GET_MODE (SUBREG_REG (op)),
2632 SUBREG_BYTE (op),
2633 GET_MODE (op));
2634 op = SUBREG_REG (op);
2637 /* An empty constraint or empty alternative
2638 allows anything which matched the pattern. */
2639 if (*p == 0 || *p == ',')
2640 win = 1;
2643 switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
2645 case '\0':
2646 len = 0;
2647 break;
2648 case ',':
2649 c = '\0';
2650 break;
2652 case '#':
2653 /* Ignore rest of this alternative as far as
2654 constraint checking is concerned. */
2656 p++;
2657 while (*p && *p != ',');
2658 len = 0;
2659 break;
2661 case '&':
2662 earlyclobber[opno] = 1;
2663 if (seen_earlyclobber_at < 0)
2664 seen_earlyclobber_at = opno;
2665 break;
2667 case '0': case '1': case '2': case '3': case '4':
2668 case '5': case '6': case '7': case '8': case '9':
2670 /* This operand must be the same as a previous one.
2671 This kind of constraint is used for instructions such
2672 as add when they take only two operands.
2674 Note that the lower-numbered operand is passed first.
2676 If we are not testing strictly, assume that this
2677 constraint will be satisfied. */
2679 char *end;
2680 int match;
2682 match = strtoul (p, &end, 10);
2683 p = end;
2685 if (strict < 0)
2686 val = 1;
2687 else
2689 rtx op1 = recog_data.operand[match];
2690 rtx op2 = recog_data.operand[opno];
2692 /* A unary operator may be accepted by the predicate,
2693 but it is irrelevant for matching constraints. */
2694 if (UNARY_P (op1))
2695 op1 = XEXP (op1, 0);
2696 if (UNARY_P (op2))
2697 op2 = XEXP (op2, 0);
2699 val = operands_match_p (op1, op2);
2702 matching_operands[opno] = match;
2703 matching_operands[match] = opno;
2705 if (val != 0)
2706 win = 1;
2708 /* If output is *x and input is *--x, arrange later
2709 to change the output to *--x as well, since the
2710 output op is the one that will be printed. */
2711 if (val == 2 && strict > 0)
2713 funny_match[funny_match_index].this_op = opno;
2714 funny_match[funny_match_index++].other = match;
2717 len = 0;
2718 break;
2720 case 'p':
2721 /* p is used for address_operands. When we are called by
2722 gen_reload, no one will have checked that the address is
2723 strictly valid, i.e., that all pseudos requiring hard regs
2724 have gotten them. */
2725 if (strict <= 0
2726 || (strict_memory_address_p (recog_data.operand_mode[opno],
2727 op)))
2728 win = 1;
2729 break;
2731 /* No need to check general_operand again;
2732 it was done in insn-recog.c. Well, except that reload
2733 doesn't check the validity of its replacements, but
2734 that should only matter when there's a bug. */
2735 case 'g':
2736 /* Anything goes unless it is a REG and really has a hard reg
2737 but the hard reg is not in the class GENERAL_REGS. */
2738 if (REG_P (op))
2740 if (strict < 0
2741 || GENERAL_REGS == ALL_REGS
2742 || (reload_in_progress
2743 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2744 || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
2745 win = 1;
2747 else if (strict < 0 || general_operand (op, mode))
2748 win = 1;
2749 break;
2751 default:
2753 enum constraint_num cn = lookup_constraint (p);
2754 enum reg_class cl = reg_class_for_constraint (cn);
2755 if (cl != NO_REGS)
2757 if (strict < 0
2758 || (strict == 0
2759 && REG_P (op)
2760 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2761 || (strict == 0 && GET_CODE (op) == SCRATCH)
2762 || (REG_P (op)
2763 && reg_fits_class_p (op, cl, offset, mode)))
2764 win = 1;
2767 else if (constraint_satisfied_p (op, cn))
2768 win = 1;
2770 else if (insn_extra_memory_constraint (cn)
2771 /* Every memory operand can be reloaded to fit. */
2772 && ((strict < 0 && MEM_P (op))
2773 /* Before reload, accept what reload can turn
2774 into a mem. */
2775 || (strict < 0 && CONSTANT_P (op))
2776 /* Before reload, accept a pseudo,
2777 since LRA can turn it into a mem. */
2778 || (strict < 0 && targetm.lra_p () && REG_P (op)
2779 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2780 /* During reload, accept a pseudo */
2781 || (reload_in_progress && REG_P (op)
2782 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))
2783 win = 1;
2784 else if (insn_extra_address_constraint (cn)
2785 /* Every address operand can be reloaded to fit. */
2786 && strict < 0)
2787 win = 1;
2788 /* Cater to architectures like IA-64 that define extra memory
2789 constraints without using define_memory_constraint. */
2790 else if (reload_in_progress
2791 && REG_P (op)
2792 && REGNO (op) >= FIRST_PSEUDO_REGISTER
2793 && reg_renumber[REGNO (op)] < 0
2794 && reg_equiv_mem (REGNO (op)) != 0
2795 && constraint_satisfied_p
2796 (reg_equiv_mem (REGNO (op)), cn))
2797 win = 1;
2798 break;
2801 while (p += len, c);
2803 constraints[opno] = p;
2804 /* If this operand did not win somehow,
2805 this alternative loses. */
2806 if (! win)
2807 lose = 1;
2809 /* This alternative won; the operands are ok.
2810 Change whichever operands this alternative says to change. */
2811 if (! lose)
2813 int opno, eopno;
2815 /* See if any earlyclobber operand conflicts with some other
2816 operand. */
2818 if (strict > 0 && seen_earlyclobber_at >= 0)
2819 for (eopno = seen_earlyclobber_at;
2820 eopno < recog_data.n_operands;
2821 eopno++)
2822 /* Ignore earlyclobber operands now in memory,
2823 because we would often report failure when we have
2824 two memory operands, one of which was formerly a REG. */
2825 if (earlyclobber[eopno]
2826 && REG_P (recog_data.operand[eopno]))
2827 for (opno = 0; opno < recog_data.n_operands; opno++)
2828 if ((MEM_P (recog_data.operand[opno])
2829 || recog_data.operand_type[opno] != OP_OUT)
2830 && opno != eopno
2831 /* Ignore things like match_operator operands. */
2832 && *recog_data.constraints[opno] != 0
2833 && ! (matching_operands[opno] == eopno
2834 && operands_match_p (recog_data.operand[opno],
2835 recog_data.operand[eopno]))
2836 && ! safe_from_earlyclobber (recog_data.operand[opno],
2837 recog_data.operand[eopno]))
2838 lose = 1;
2840 if (! lose)
2842 while (--funny_match_index >= 0)
2844 recog_data.operand[funny_match[funny_match_index].other]
2845 = recog_data.operand[funny_match[funny_match_index].this_op];
2848 #ifdef AUTO_INC_DEC
2849 /* For operands without < or > constraints reject side-effects. */
2850 if (recog_data.is_asm)
2852 for (opno = 0; opno < recog_data.n_operands; opno++)
2853 if (MEM_P (recog_data.operand[opno]))
2854 switch (GET_CODE (XEXP (recog_data.operand[opno], 0)))
2856 case PRE_INC:
2857 case POST_INC:
2858 case PRE_DEC:
2859 case POST_DEC:
2860 case PRE_MODIFY:
2861 case POST_MODIFY:
2862 if (strchr (recog_data.constraints[opno], '<') == NULL
2863 && strchr (recog_data.constraints[opno], '>')
2864 == NULL)
2865 return 0;
2866 break;
2867 default:
2868 break;
2871 #endif
2872 return 1;
2876 which_alternative++;
2878 while (which_alternative < recog_data.n_alternatives);
2880 which_alternative = -1;
2881 /* If we are about to reject this, but we are not to test strictly,
2882 try a very loose test. Only return failure if it fails also. */
2883 if (strict == 0)
2884 return constrain_operands (-1, alternatives);
2885 else
2886 return 0;
2889 /* Return true iff OPERAND (assumed to be a REG rtx)
2890 is a hard reg in class CLASS when its regno is offset by OFFSET
2891 and changed to mode MODE.
2892 If REG occupies multiple hard regs, all of them must be in CLASS. */
2894 bool
2895 reg_fits_class_p (const_rtx operand, reg_class_t cl, int offset,
2896 machine_mode mode)
2898 unsigned int regno = REGNO (operand);
2900 if (cl == NO_REGS)
2901 return false;
2903 /* Regno must not be a pseudo register. Offset may be negative. */
2904 return (HARD_REGISTER_NUM_P (regno)
2905 && HARD_REGISTER_NUM_P (regno + offset)
2906 && in_hard_reg_set_p (reg_class_contents[(int) cl], mode,
2907 regno + offset));
2910 /* Split single instruction. Helper function for split_all_insns and
2911 split_all_insns_noflow. Return last insn in the sequence if successful,
2912 or NULL if unsuccessful. */
2914 static rtx_insn *
2915 split_insn (rtx_insn *insn)
2917 /* Split insns here to get max fine-grain parallelism. */
2918 rtx_insn *first = PREV_INSN (insn);
2919 rtx_insn *last = try_split (PATTERN (insn), insn, 1);
2920 rtx insn_set, last_set, note;
2922 if (last == insn)
2923 return NULL;
2925 /* If the original instruction was a single set that was known to be
2926 equivalent to a constant, see if we can say the same about the last
2927 instruction in the split sequence. The two instructions must set
2928 the same destination. */
2929 insn_set = single_set (insn);
2930 if (insn_set)
2932 last_set = single_set (last);
2933 if (last_set && rtx_equal_p (SET_DEST (last_set), SET_DEST (insn_set)))
2935 note = find_reg_equal_equiv_note (insn);
2936 if (note && CONSTANT_P (XEXP (note, 0)))
2937 set_unique_reg_note (last, REG_EQUAL, XEXP (note, 0));
2938 else if (CONSTANT_P (SET_SRC (insn_set)))
2939 set_unique_reg_note (last, REG_EQUAL,
2940 copy_rtx (SET_SRC (insn_set)));
2944 /* try_split returns the NOTE that INSN became. */
2945 SET_INSN_DELETED (insn);
2947 /* ??? Coddle to md files that generate subregs in post-reload
2948 splitters instead of computing the proper hard register. */
2949 if (reload_completed && first != last)
2951 first = NEXT_INSN (first);
2952 for (;;)
2954 if (INSN_P (first))
2955 cleanup_subreg_operands (first);
2956 if (first == last)
2957 break;
2958 first = NEXT_INSN (first);
2962 return last;
2965 /* Split all insns in the function. If UPD_LIFE, update life info after. */
2967 void
2968 split_all_insns (void)
2970 sbitmap blocks;
2971 bool changed;
2972 basic_block bb;
2974 blocks = sbitmap_alloc (last_basic_block_for_fn (cfun));
2975 bitmap_clear (blocks);
2976 changed = false;
2978 FOR_EACH_BB_REVERSE_FN (bb, cfun)
2980 rtx_insn *insn, *next;
2981 bool finish = false;
2983 rtl_profile_for_bb (bb);
2984 for (insn = BB_HEAD (bb); !finish ; insn = next)
2986 /* Can't use `next_real_insn' because that might go across
2987 CODE_LABELS and short-out basic blocks. */
2988 next = NEXT_INSN (insn);
2989 finish = (insn == BB_END (bb));
2990 if (INSN_P (insn))
2992 rtx set = single_set (insn);
2994 /* Don't split no-op move insns. These should silently
2995 disappear later in final. Splitting such insns would
2996 break the code that handles LIBCALL blocks. */
2997 if (set && set_noop_p (set))
2999 /* Nops get in the way while scheduling, so delete them
3000 now if register allocation has already been done. It
3001 is too risky to try to do this before register
3002 allocation, and there are unlikely to be very many
3003 nops then anyways. */
3004 if (reload_completed)
3005 delete_insn_and_edges (insn);
3007 else
3009 if (split_insn (insn))
3011 bitmap_set_bit (blocks, bb->index);
3012 changed = true;
3019 default_rtl_profile ();
3020 if (changed)
3021 find_many_sub_basic_blocks (blocks);
3023 #ifdef ENABLE_CHECKING
3024 verify_flow_info ();
3025 #endif
3027 sbitmap_free (blocks);
3030 /* Same as split_all_insns, but do not expect CFG to be available.
3031 Used by machine dependent reorg passes. */
3033 unsigned int
3034 split_all_insns_noflow (void)
3036 rtx_insn *next, *insn;
3038 for (insn = get_insns (); insn; insn = next)
3040 next = NEXT_INSN (insn);
3041 if (INSN_P (insn))
3043 /* Don't split no-op move insns. These should silently
3044 disappear later in final. Splitting such insns would
3045 break the code that handles LIBCALL blocks. */
3046 rtx set = single_set (insn);
3047 if (set && set_noop_p (set))
3049 /* Nops get in the way while scheduling, so delete them
3050 now if register allocation has already been done. It
3051 is too risky to try to do this before register
3052 allocation, and there are unlikely to be very many
3053 nops then anyways.
3055 ??? Should we use delete_insn when the CFG isn't valid? */
3056 if (reload_completed)
3057 delete_insn_and_edges (insn);
3059 else
3060 split_insn (insn);
3063 return 0;
3066 #ifdef HAVE_peephole2
3067 struct peep2_insn_data
3069 rtx insn;
3070 regset live_before;
3073 static struct peep2_insn_data peep2_insn_data[MAX_INSNS_PER_PEEP2 + 1];
3074 static int peep2_current;
3076 static bool peep2_do_rebuild_jump_labels;
3077 static bool peep2_do_cleanup_cfg;
3079 /* The number of instructions available to match a peep2. */
3080 int peep2_current_count;
3082 /* A non-insn marker indicating the last insn of the block.
3083 The live_before regset for this element is correct, indicating
3084 DF_LIVE_OUT for the block. */
3085 #define PEEP2_EOB pc_rtx
3087 /* Wrap N to fit into the peep2_insn_data buffer. */
3089 static int
3090 peep2_buf_position (int n)
3092 if (n >= MAX_INSNS_PER_PEEP2 + 1)
3093 n -= MAX_INSNS_PER_PEEP2 + 1;
3094 return n;
3097 /* Return the Nth non-note insn after `current', or return NULL_RTX if it
3098 does not exist. Used by the recognizer to find the next insn to match
3099 in a multi-insn pattern. */
3102 peep2_next_insn (int n)
3104 gcc_assert (n <= peep2_current_count);
3106 n = peep2_buf_position (peep2_current + n);
3108 return peep2_insn_data[n].insn;
3111 /* Return true if REGNO is dead before the Nth non-note insn
3112 after `current'. */
3115 peep2_regno_dead_p (int ofs, int regno)
3117 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3119 ofs = peep2_buf_position (peep2_current + ofs);
3121 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3123 return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
3126 /* Similarly for a REG. */
3129 peep2_reg_dead_p (int ofs, rtx reg)
3131 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3133 ofs = peep2_buf_position (peep2_current + ofs);
3135 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3137 unsigned int end_regno = END_REGNO (reg);
3138 for (unsigned int regno = REGNO (reg); regno < end_regno; ++regno)
3139 if (REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno))
3140 return 0;
3141 return 1;
3144 /* Regno offset to be used in the register search. */
3145 static int search_ofs;
3147 /* Try to find a hard register of mode MODE, matching the register class in
3148 CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
3149 remains available until the end of LAST_INSN. LAST_INSN may be NULL_RTX,
3150 in which case the only condition is that the register must be available
3151 before CURRENT_INSN.
3152 Registers that already have bits set in REG_SET will not be considered.
3154 If an appropriate register is available, it will be returned and the
3155 corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
3156 returned. */
3159 peep2_find_free_register (int from, int to, const char *class_str,
3160 machine_mode mode, HARD_REG_SET *reg_set)
3162 enum reg_class cl;
3163 HARD_REG_SET live;
3164 df_ref def;
3165 int i;
3167 gcc_assert (from < MAX_INSNS_PER_PEEP2 + 1);
3168 gcc_assert (to < MAX_INSNS_PER_PEEP2 + 1);
3170 from = peep2_buf_position (peep2_current + from);
3171 to = peep2_buf_position (peep2_current + to);
3173 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3174 REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
3176 while (from != to)
3178 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3180 /* Don't use registers set or clobbered by the insn. */
3181 FOR_EACH_INSN_DEF (def, peep2_insn_data[from].insn)
3182 SET_HARD_REG_BIT (live, DF_REF_REGNO (def));
3184 from = peep2_buf_position (from + 1);
3187 cl = reg_class_for_constraint (lookup_constraint (class_str));
3189 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3191 int raw_regno, regno, success, j;
3193 /* Distribute the free registers as much as possible. */
3194 raw_regno = search_ofs + i;
3195 if (raw_regno >= FIRST_PSEUDO_REGISTER)
3196 raw_regno -= FIRST_PSEUDO_REGISTER;
3197 #ifdef REG_ALLOC_ORDER
3198 regno = reg_alloc_order[raw_regno];
3199 #else
3200 regno = raw_regno;
3201 #endif
3203 /* Can it support the mode we need? */
3204 if (! HARD_REGNO_MODE_OK (regno, mode))
3205 continue;
3207 success = 1;
3208 for (j = 0; success && j < hard_regno_nregs[regno][mode]; j++)
3210 /* Don't allocate fixed registers. */
3211 if (fixed_regs[regno + j])
3213 success = 0;
3214 break;
3216 /* Don't allocate global registers. */
3217 if (global_regs[regno + j])
3219 success = 0;
3220 break;
3222 /* Make sure the register is of the right class. */
3223 if (! TEST_HARD_REG_BIT (reg_class_contents[cl], regno + j))
3225 success = 0;
3226 break;
3228 /* And that we don't create an extra save/restore. */
3229 if (! call_used_regs[regno + j] && ! df_regs_ever_live_p (regno + j))
3231 success = 0;
3232 break;
3235 if (! targetm.hard_regno_scratch_ok (regno + j))
3237 success = 0;
3238 break;
3241 /* And we don't clobber traceback for noreturn functions. */
3242 if ((regno + j == FRAME_POINTER_REGNUM
3243 || regno + j == HARD_FRAME_POINTER_REGNUM)
3244 && (! reload_completed || frame_pointer_needed))
3246 success = 0;
3247 break;
3250 if (TEST_HARD_REG_BIT (*reg_set, regno + j)
3251 || TEST_HARD_REG_BIT (live, regno + j))
3253 success = 0;
3254 break;
3258 if (success)
3260 add_to_hard_reg_set (reg_set, mode, regno);
3262 /* Start the next search with the next register. */
3263 if (++raw_regno >= FIRST_PSEUDO_REGISTER)
3264 raw_regno = 0;
3265 search_ofs = raw_regno;
3267 return gen_rtx_REG (mode, regno);
3271 search_ofs = 0;
3272 return NULL_RTX;
3275 /* Forget all currently tracked instructions, only remember current
3276 LIVE regset. */
3278 static void
3279 peep2_reinit_state (regset live)
3281 int i;
3283 /* Indicate that all slots except the last holds invalid data. */
3284 for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
3285 peep2_insn_data[i].insn = NULL_RTX;
3286 peep2_current_count = 0;
3288 /* Indicate that the last slot contains live_after data. */
3289 peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
3290 peep2_current = MAX_INSNS_PER_PEEP2;
3292 COPY_REG_SET (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
3295 /* While scanning basic block BB, we found a match of length MATCH_LEN,
3296 starting at INSN. Perform the replacement, removing the old insns and
3297 replacing them with ATTEMPT. Returns the last insn emitted, or NULL
3298 if the replacement is rejected. */
3300 static rtx_insn *
3301 peep2_attempt (basic_block bb, rtx uncast_insn, int match_len, rtx_insn *attempt)
3303 rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
3304 int i;
3305 rtx_insn *last, *before_try, *x;
3306 rtx eh_note, as_note;
3307 rtx_insn *old_insn;
3308 rtx_insn *new_insn;
3309 bool was_call = false;
3311 /* If we are splitting an RTX_FRAME_RELATED_P insn, do not allow it to
3312 match more than one insn, or to be split into more than one insn. */
3313 old_insn = as_a <rtx_insn *> (peep2_insn_data[peep2_current].insn);
3314 if (RTX_FRAME_RELATED_P (old_insn))
3316 bool any_note = false;
3317 rtx note;
3319 if (match_len != 0)
3320 return NULL;
3322 /* Look for one "active" insn. I.e. ignore any "clobber" insns that
3323 may be in the stream for the purpose of register allocation. */
3324 if (active_insn_p (attempt))
3325 new_insn = attempt;
3326 else
3327 new_insn = next_active_insn (attempt);
3328 if (next_active_insn (new_insn))
3329 return NULL;
3331 /* We have a 1-1 replacement. Copy over any frame-related info. */
3332 RTX_FRAME_RELATED_P (new_insn) = 1;
3334 /* Allow the backend to fill in a note during the split. */
3335 for (note = REG_NOTES (new_insn); note ; note = XEXP (note, 1))
3336 switch (REG_NOTE_KIND (note))
3338 case REG_FRAME_RELATED_EXPR:
3339 case REG_CFA_DEF_CFA:
3340 case REG_CFA_ADJUST_CFA:
3341 case REG_CFA_OFFSET:
3342 case REG_CFA_REGISTER:
3343 case REG_CFA_EXPRESSION:
3344 case REG_CFA_RESTORE:
3345 case REG_CFA_SET_VDRAP:
3346 any_note = true;
3347 break;
3348 default:
3349 break;
3352 /* If the backend didn't supply a note, copy one over. */
3353 if (!any_note)
3354 for (note = REG_NOTES (old_insn); note ; note = XEXP (note, 1))
3355 switch (REG_NOTE_KIND (note))
3357 case REG_FRAME_RELATED_EXPR:
3358 case REG_CFA_DEF_CFA:
3359 case REG_CFA_ADJUST_CFA:
3360 case REG_CFA_OFFSET:
3361 case REG_CFA_REGISTER:
3362 case REG_CFA_EXPRESSION:
3363 case REG_CFA_RESTORE:
3364 case REG_CFA_SET_VDRAP:
3365 add_reg_note (new_insn, REG_NOTE_KIND (note), XEXP (note, 0));
3366 any_note = true;
3367 break;
3368 default:
3369 break;
3372 /* If there still isn't a note, make sure the unwind info sees the
3373 same expression as before the split. */
3374 if (!any_note)
3376 rtx old_set, new_set;
3378 /* The old insn had better have been simple, or annotated. */
3379 old_set = single_set (old_insn);
3380 gcc_assert (old_set != NULL);
3382 new_set = single_set (new_insn);
3383 if (!new_set || !rtx_equal_p (new_set, old_set))
3384 add_reg_note (new_insn, REG_FRAME_RELATED_EXPR, old_set);
3387 /* Copy prologue/epilogue status. This is required in order to keep
3388 proper placement of EPILOGUE_BEG and the DW_CFA_remember_state. */
3389 maybe_copy_prologue_epilogue_insn (old_insn, new_insn);
3392 /* If we are splitting a CALL_INSN, look for the CALL_INSN
3393 in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
3394 cfg-related call notes. */
3395 for (i = 0; i <= match_len; ++i)
3397 int j;
3398 rtx note;
3400 j = peep2_buf_position (peep2_current + i);
3401 old_insn = as_a <rtx_insn *> (peep2_insn_data[j].insn);
3402 if (!CALL_P (old_insn))
3403 continue;
3404 was_call = true;
3406 new_insn = attempt;
3407 while (new_insn != NULL_RTX)
3409 if (CALL_P (new_insn))
3410 break;
3411 new_insn = NEXT_INSN (new_insn);
3414 gcc_assert (new_insn != NULL_RTX);
3416 CALL_INSN_FUNCTION_USAGE (new_insn)
3417 = CALL_INSN_FUNCTION_USAGE (old_insn);
3418 SIBLING_CALL_P (new_insn) = SIBLING_CALL_P (old_insn);
3420 for (note = REG_NOTES (old_insn);
3421 note;
3422 note = XEXP (note, 1))
3423 switch (REG_NOTE_KIND (note))
3425 case REG_NORETURN:
3426 case REG_SETJMP:
3427 case REG_TM:
3428 add_reg_note (new_insn, REG_NOTE_KIND (note),
3429 XEXP (note, 0));
3430 break;
3431 default:
3432 /* Discard all other reg notes. */
3433 break;
3436 /* Croak if there is another call in the sequence. */
3437 while (++i <= match_len)
3439 j = peep2_buf_position (peep2_current + i);
3440 old_insn = as_a <rtx_insn *> (peep2_insn_data[j].insn);
3441 gcc_assert (!CALL_P (old_insn));
3443 break;
3446 /* If we matched any instruction that had a REG_ARGS_SIZE, then
3447 move those notes over to the new sequence. */
3448 as_note = NULL;
3449 for (i = match_len; i >= 0; --i)
3451 int j = peep2_buf_position (peep2_current + i);
3452 old_insn = as_a <rtx_insn *> (peep2_insn_data[j].insn);
3454 as_note = find_reg_note (old_insn, REG_ARGS_SIZE, NULL);
3455 if (as_note)
3456 break;
3459 i = peep2_buf_position (peep2_current + match_len);
3460 eh_note = find_reg_note (peep2_insn_data[i].insn, REG_EH_REGION, NULL_RTX);
3462 /* Replace the old sequence with the new. */
3463 rtx_insn *peepinsn = as_a <rtx_insn *> (peep2_insn_data[i].insn);
3464 last = emit_insn_after_setloc (attempt,
3465 peep2_insn_data[i].insn,
3466 INSN_LOCATION (peepinsn));
3467 before_try = PREV_INSN (insn);
3468 delete_insn_chain (insn, peep2_insn_data[i].insn, false);
3470 /* Re-insert the EH_REGION notes. */
3471 if (eh_note || (was_call && nonlocal_goto_handler_labels))
3473 edge eh_edge;
3474 edge_iterator ei;
3476 FOR_EACH_EDGE (eh_edge, ei, bb->succs)
3477 if (eh_edge->flags & (EDGE_EH | EDGE_ABNORMAL_CALL))
3478 break;
3480 if (eh_note)
3481 copy_reg_eh_region_note_backward (eh_note, last, before_try);
3483 if (eh_edge)
3484 for (x = last; x != before_try; x = PREV_INSN (x))
3485 if (x != BB_END (bb)
3486 && (can_throw_internal (x)
3487 || can_nonlocal_goto (x)))
3489 edge nfte, nehe;
3490 int flags;
3492 nfte = split_block (bb, x);
3493 flags = (eh_edge->flags
3494 & (EDGE_EH | EDGE_ABNORMAL));
3495 if (CALL_P (x))
3496 flags |= EDGE_ABNORMAL_CALL;
3497 nehe = make_edge (nfte->src, eh_edge->dest,
3498 flags);
3500 nehe->probability = eh_edge->probability;
3501 nfte->probability
3502 = REG_BR_PROB_BASE - nehe->probability;
3504 peep2_do_cleanup_cfg |= purge_dead_edges (nfte->dest);
3505 bb = nfte->src;
3506 eh_edge = nehe;
3509 /* Converting possibly trapping insn to non-trapping is
3510 possible. Zap dummy outgoing edges. */
3511 peep2_do_cleanup_cfg |= purge_dead_edges (bb);
3514 /* Re-insert the ARGS_SIZE notes. */
3515 if (as_note)
3516 fixup_args_size_notes (before_try, last, INTVAL (XEXP (as_note, 0)));
3518 /* If we generated a jump instruction, it won't have
3519 JUMP_LABEL set. Recompute after we're done. */
3520 for (x = last; x != before_try; x = PREV_INSN (x))
3521 if (JUMP_P (x))
3523 peep2_do_rebuild_jump_labels = true;
3524 break;
3527 return last;
3530 /* After performing a replacement in basic block BB, fix up the life
3531 information in our buffer. LAST is the last of the insns that we
3532 emitted as a replacement. PREV is the insn before the start of
3533 the replacement. MATCH_LEN is the number of instructions that were
3534 matched, and which now need to be replaced in the buffer. */
3536 static void
3537 peep2_update_life (basic_block bb, int match_len, rtx_insn *last,
3538 rtx_insn *prev)
3540 int i = peep2_buf_position (peep2_current + match_len + 1);
3541 rtx_insn *x;
3542 regset_head live;
3544 INIT_REG_SET (&live);
3545 COPY_REG_SET (&live, peep2_insn_data[i].live_before);
3547 gcc_assert (peep2_current_count >= match_len + 1);
3548 peep2_current_count -= match_len + 1;
3550 x = last;
3553 if (INSN_P (x))
3555 df_insn_rescan (x);
3556 if (peep2_current_count < MAX_INSNS_PER_PEEP2)
3558 peep2_current_count++;
3559 if (--i < 0)
3560 i = MAX_INSNS_PER_PEEP2;
3561 peep2_insn_data[i].insn = x;
3562 df_simulate_one_insn_backwards (bb, x, &live);
3563 COPY_REG_SET (peep2_insn_data[i].live_before, &live);
3566 x = PREV_INSN (x);
3568 while (x != prev);
3569 CLEAR_REG_SET (&live);
3571 peep2_current = i;
3574 /* Add INSN, which is in BB, at the end of the peep2 insn buffer if possible.
3575 Return true if we added it, false otherwise. The caller will try to match
3576 peepholes against the buffer if we return false; otherwise it will try to
3577 add more instructions to the buffer. */
3579 static bool
3580 peep2_fill_buffer (basic_block bb, rtx insn, regset live)
3582 int pos;
3584 /* Once we have filled the maximum number of insns the buffer can hold,
3585 allow the caller to match the insns against peepholes. We wait until
3586 the buffer is full in case the target has similar peepholes of different
3587 length; we always want to match the longest if possible. */
3588 if (peep2_current_count == MAX_INSNS_PER_PEEP2)
3589 return false;
3591 /* If an insn has RTX_FRAME_RELATED_P set, do not allow it to be matched with
3592 any other pattern, lest it change the semantics of the frame info. */
3593 if (RTX_FRAME_RELATED_P (insn))
3595 /* Let the buffer drain first. */
3596 if (peep2_current_count > 0)
3597 return false;
3598 /* Now the insn will be the only thing in the buffer. */
3601 pos = peep2_buf_position (peep2_current + peep2_current_count);
3602 peep2_insn_data[pos].insn = insn;
3603 COPY_REG_SET (peep2_insn_data[pos].live_before, live);
3604 peep2_current_count++;
3606 df_simulate_one_insn_forwards (bb, as_a <rtx_insn *> (insn), live);
3607 return true;
3610 /* Perform the peephole2 optimization pass. */
3612 static void
3613 peephole2_optimize (void)
3615 rtx_insn *insn;
3616 bitmap live;
3617 int i;
3618 basic_block bb;
3620 peep2_do_cleanup_cfg = false;
3621 peep2_do_rebuild_jump_labels = false;
3623 df_set_flags (DF_LR_RUN_DCE);
3624 df_note_add_problem ();
3625 df_analyze ();
3627 /* Initialize the regsets we're going to use. */
3628 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3629 peep2_insn_data[i].live_before = BITMAP_ALLOC (&reg_obstack);
3630 search_ofs = 0;
3631 live = BITMAP_ALLOC (&reg_obstack);
3633 FOR_EACH_BB_REVERSE_FN (bb, cfun)
3635 bool past_end = false;
3636 int pos;
3638 rtl_profile_for_bb (bb);
3640 /* Start up propagation. */
3641 bitmap_copy (live, DF_LR_IN (bb));
3642 df_simulate_initialize_forwards (bb, live);
3643 peep2_reinit_state (live);
3645 insn = BB_HEAD (bb);
3646 for (;;)
3648 rtx_insn *attempt;
3649 rtx head;
3650 int match_len;
3652 if (!past_end && !NONDEBUG_INSN_P (insn))
3654 next_insn:
3655 insn = NEXT_INSN (insn);
3656 if (insn == NEXT_INSN (BB_END (bb)))
3657 past_end = true;
3658 continue;
3660 if (!past_end && peep2_fill_buffer (bb, insn, live))
3661 goto next_insn;
3663 /* If we did not fill an empty buffer, it signals the end of the
3664 block. */
3665 if (peep2_current_count == 0)
3666 break;
3668 /* The buffer filled to the current maximum, so try to match. */
3670 pos = peep2_buf_position (peep2_current + peep2_current_count);
3671 peep2_insn_data[pos].insn = PEEP2_EOB;
3672 COPY_REG_SET (peep2_insn_data[pos].live_before, live);
3674 /* Match the peephole. */
3675 head = peep2_insn_data[peep2_current].insn;
3676 attempt = safe_as_a <rtx_insn *> (
3677 peephole2_insns (PATTERN (head), head, &match_len));
3678 if (attempt != NULL)
3680 rtx_insn *last = peep2_attempt (bb, head, match_len, attempt);
3681 if (last)
3683 peep2_update_life (bb, match_len, last, PREV_INSN (attempt));
3684 continue;
3688 /* No match: advance the buffer by one insn. */
3689 peep2_current = peep2_buf_position (peep2_current + 1);
3690 peep2_current_count--;
3694 default_rtl_profile ();
3695 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3696 BITMAP_FREE (peep2_insn_data[i].live_before);
3697 BITMAP_FREE (live);
3698 if (peep2_do_rebuild_jump_labels)
3699 rebuild_jump_labels (get_insns ());
3700 if (peep2_do_cleanup_cfg)
3701 cleanup_cfg (CLEANUP_CFG_CHANGED);
3703 #endif /* HAVE_peephole2 */
3705 /* Common predicates for use with define_bypass. */
3707 /* True if the dependency between OUT_INSN and IN_INSN is on the store
3708 data not the address operand(s) of the store. IN_INSN and OUT_INSN
3709 must be either a single_set or a PARALLEL with SETs inside. */
3712 store_data_bypass_p (rtx_insn *out_insn, rtx_insn *in_insn)
3714 rtx out_set, in_set;
3715 rtx out_pat, in_pat;
3716 rtx out_exp, in_exp;
3717 int i, j;
3719 in_set = single_set (in_insn);
3720 if (in_set)
3722 if (!MEM_P (SET_DEST (in_set)))
3723 return false;
3725 out_set = single_set (out_insn);
3726 if (out_set)
3728 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_set)))
3729 return false;
3731 else
3733 out_pat = PATTERN (out_insn);
3735 if (GET_CODE (out_pat) != PARALLEL)
3736 return false;
3738 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3740 out_exp = XVECEXP (out_pat, 0, i);
3742 if (GET_CODE (out_exp) == CLOBBER)
3743 continue;
3745 gcc_assert (GET_CODE (out_exp) == SET);
3747 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_set)))
3748 return false;
3752 else
3754 in_pat = PATTERN (in_insn);
3755 gcc_assert (GET_CODE (in_pat) == PARALLEL);
3757 for (i = 0; i < XVECLEN (in_pat, 0); i++)
3759 in_exp = XVECEXP (in_pat, 0, i);
3761 if (GET_CODE (in_exp) == CLOBBER)
3762 continue;
3764 gcc_assert (GET_CODE (in_exp) == SET);
3766 if (!MEM_P (SET_DEST (in_exp)))
3767 return false;
3769 out_set = single_set (out_insn);
3770 if (out_set)
3772 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_exp)))
3773 return false;
3775 else
3777 out_pat = PATTERN (out_insn);
3778 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3780 for (j = 0; j < XVECLEN (out_pat, 0); j++)
3782 out_exp = XVECEXP (out_pat, 0, j);
3784 if (GET_CODE (out_exp) == CLOBBER)
3785 continue;
3787 gcc_assert (GET_CODE (out_exp) == SET);
3789 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_exp)))
3790 return false;
3796 return true;
3799 /* True if the dependency between OUT_INSN and IN_INSN is in the IF_THEN_ELSE
3800 condition, and not the THEN or ELSE branch. OUT_INSN may be either a single
3801 or multiple set; IN_INSN should be single_set for truth, but for convenience
3802 of insn categorization may be any JUMP or CALL insn. */
3805 if_test_bypass_p (rtx_insn *out_insn, rtx_insn *in_insn)
3807 rtx out_set, in_set;
3809 in_set = single_set (in_insn);
3810 if (! in_set)
3812 gcc_assert (JUMP_P (in_insn) || CALL_P (in_insn));
3813 return false;
3816 if (GET_CODE (SET_SRC (in_set)) != IF_THEN_ELSE)
3817 return false;
3818 in_set = SET_SRC (in_set);
3820 out_set = single_set (out_insn);
3821 if (out_set)
3823 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3824 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3825 return false;
3827 else
3829 rtx out_pat;
3830 int i;
3832 out_pat = PATTERN (out_insn);
3833 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3835 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3837 rtx exp = XVECEXP (out_pat, 0, i);
3839 if (GET_CODE (exp) == CLOBBER)
3840 continue;
3842 gcc_assert (GET_CODE (exp) == SET);
3844 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3845 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3846 return false;
3850 return true;
3853 static unsigned int
3854 rest_of_handle_peephole2 (void)
3856 #ifdef HAVE_peephole2
3857 peephole2_optimize ();
3858 #endif
3859 return 0;
3862 namespace {
3864 const pass_data pass_data_peephole2 =
3866 RTL_PASS, /* type */
3867 "peephole2", /* name */
3868 OPTGROUP_NONE, /* optinfo_flags */
3869 TV_PEEPHOLE2, /* tv_id */
3870 0, /* properties_required */
3871 0, /* properties_provided */
3872 0, /* properties_destroyed */
3873 0, /* todo_flags_start */
3874 TODO_df_finish, /* todo_flags_finish */
3877 class pass_peephole2 : public rtl_opt_pass
3879 public:
3880 pass_peephole2 (gcc::context *ctxt)
3881 : rtl_opt_pass (pass_data_peephole2, ctxt)
3884 /* opt_pass methods: */
3885 /* The epiphany backend creates a second instance of this pass, so we need
3886 a clone method. */
3887 opt_pass * clone () { return new pass_peephole2 (m_ctxt); }
3888 virtual bool gate (function *) { return (optimize > 0 && flag_peephole2); }
3889 virtual unsigned int execute (function *)
3891 return rest_of_handle_peephole2 ();
3894 }; // class pass_peephole2
3896 } // anon namespace
3898 rtl_opt_pass *
3899 make_pass_peephole2 (gcc::context *ctxt)
3901 return new pass_peephole2 (ctxt);
3904 namespace {
3906 const pass_data pass_data_split_all_insns =
3908 RTL_PASS, /* type */
3909 "split1", /* name */
3910 OPTGROUP_NONE, /* optinfo_flags */
3911 TV_NONE, /* tv_id */
3912 0, /* properties_required */
3913 0, /* properties_provided */
3914 0, /* properties_destroyed */
3915 0, /* todo_flags_start */
3916 0, /* todo_flags_finish */
3919 class pass_split_all_insns : public rtl_opt_pass
3921 public:
3922 pass_split_all_insns (gcc::context *ctxt)
3923 : rtl_opt_pass (pass_data_split_all_insns, ctxt)
3926 /* opt_pass methods: */
3927 /* The epiphany backend creates a second instance of this pass, so
3928 we need a clone method. */
3929 opt_pass * clone () { return new pass_split_all_insns (m_ctxt); }
3930 virtual unsigned int execute (function *)
3932 split_all_insns ();
3933 return 0;
3936 }; // class pass_split_all_insns
3938 } // anon namespace
3940 rtl_opt_pass *
3941 make_pass_split_all_insns (gcc::context *ctxt)
3943 return new pass_split_all_insns (ctxt);
3946 static unsigned int
3947 rest_of_handle_split_after_reload (void)
3949 /* If optimizing, then go ahead and split insns now. */
3950 #ifndef STACK_REGS
3951 if (optimize > 0)
3952 #endif
3953 split_all_insns ();
3954 return 0;
3957 namespace {
3959 const pass_data pass_data_split_after_reload =
3961 RTL_PASS, /* type */
3962 "split2", /* name */
3963 OPTGROUP_NONE, /* optinfo_flags */
3964 TV_NONE, /* tv_id */
3965 0, /* properties_required */
3966 0, /* properties_provided */
3967 0, /* properties_destroyed */
3968 0, /* todo_flags_start */
3969 0, /* todo_flags_finish */
3972 class pass_split_after_reload : public rtl_opt_pass
3974 public:
3975 pass_split_after_reload (gcc::context *ctxt)
3976 : rtl_opt_pass (pass_data_split_after_reload, ctxt)
3979 /* opt_pass methods: */
3980 virtual unsigned int execute (function *)
3982 return rest_of_handle_split_after_reload ();
3985 }; // class pass_split_after_reload
3987 } // anon namespace
3989 rtl_opt_pass *
3990 make_pass_split_after_reload (gcc::context *ctxt)
3992 return new pass_split_after_reload (ctxt);
3995 namespace {
3997 const pass_data pass_data_split_before_regstack =
3999 RTL_PASS, /* type */
4000 "split3", /* name */
4001 OPTGROUP_NONE, /* optinfo_flags */
4002 TV_NONE, /* tv_id */
4003 0, /* properties_required */
4004 0, /* properties_provided */
4005 0, /* properties_destroyed */
4006 0, /* todo_flags_start */
4007 0, /* todo_flags_finish */
4010 class pass_split_before_regstack : public rtl_opt_pass
4012 public:
4013 pass_split_before_regstack (gcc::context *ctxt)
4014 : rtl_opt_pass (pass_data_split_before_regstack, ctxt)
4017 /* opt_pass methods: */
4018 virtual bool gate (function *);
4019 virtual unsigned int execute (function *)
4021 split_all_insns ();
4022 return 0;
4025 }; // class pass_split_before_regstack
4027 bool
4028 pass_split_before_regstack::gate (function *)
4030 #if HAVE_ATTR_length && defined (STACK_REGS)
4031 /* If flow2 creates new instructions which need splitting
4032 and scheduling after reload is not done, they might not be
4033 split until final which doesn't allow splitting
4034 if HAVE_ATTR_length. */
4035 # ifdef INSN_SCHEDULING
4036 return (optimize && !flag_schedule_insns_after_reload);
4037 # else
4038 return (optimize);
4039 # endif
4040 #else
4041 return 0;
4042 #endif
4045 } // anon namespace
4047 rtl_opt_pass *
4048 make_pass_split_before_regstack (gcc::context *ctxt)
4050 return new pass_split_before_regstack (ctxt);
4053 static unsigned int
4054 rest_of_handle_split_before_sched2 (void)
4056 #ifdef INSN_SCHEDULING
4057 split_all_insns ();
4058 #endif
4059 return 0;
4062 namespace {
4064 const pass_data pass_data_split_before_sched2 =
4066 RTL_PASS, /* type */
4067 "split4", /* name */
4068 OPTGROUP_NONE, /* optinfo_flags */
4069 TV_NONE, /* tv_id */
4070 0, /* properties_required */
4071 0, /* properties_provided */
4072 0, /* properties_destroyed */
4073 0, /* todo_flags_start */
4074 0, /* todo_flags_finish */
4077 class pass_split_before_sched2 : public rtl_opt_pass
4079 public:
4080 pass_split_before_sched2 (gcc::context *ctxt)
4081 : rtl_opt_pass (pass_data_split_before_sched2, ctxt)
4084 /* opt_pass methods: */
4085 virtual bool gate (function *)
4087 #ifdef INSN_SCHEDULING
4088 return optimize > 0 && flag_schedule_insns_after_reload;
4089 #else
4090 return false;
4091 #endif
4094 virtual unsigned int execute (function *)
4096 return rest_of_handle_split_before_sched2 ();
4099 }; // class pass_split_before_sched2
4101 } // anon namespace
4103 rtl_opt_pass *
4104 make_pass_split_before_sched2 (gcc::context *ctxt)
4106 return new pass_split_before_sched2 (ctxt);
4109 namespace {
4111 const pass_data pass_data_split_for_shorten_branches =
4113 RTL_PASS, /* type */
4114 "split5", /* name */
4115 OPTGROUP_NONE, /* optinfo_flags */
4116 TV_NONE, /* tv_id */
4117 0, /* properties_required */
4118 0, /* properties_provided */
4119 0, /* properties_destroyed */
4120 0, /* todo_flags_start */
4121 0, /* todo_flags_finish */
4124 class pass_split_for_shorten_branches : public rtl_opt_pass
4126 public:
4127 pass_split_for_shorten_branches (gcc::context *ctxt)
4128 : rtl_opt_pass (pass_data_split_for_shorten_branches, ctxt)
4131 /* opt_pass methods: */
4132 virtual bool gate (function *)
4134 /* The placement of the splitting that we do for shorten_branches
4135 depends on whether regstack is used by the target or not. */
4136 #if HAVE_ATTR_length && !defined (STACK_REGS)
4137 return true;
4138 #else
4139 return false;
4140 #endif
4143 virtual unsigned int execute (function *)
4145 return split_all_insns_noflow ();
4148 }; // class pass_split_for_shorten_branches
4150 } // anon namespace
4152 rtl_opt_pass *
4153 make_pass_split_for_shorten_branches (gcc::context *ctxt)
4155 return new pass_split_for_shorten_branches (ctxt);
4158 /* (Re)initialize the target information after a change in target. */
4160 void
4161 recog_init ()
4163 /* The information is zero-initialized, so we don't need to do anything
4164 first time round. */
4165 if (!this_target_recog->x_initialized)
4167 this_target_recog->x_initialized = true;
4168 return;
4170 memset (this_target_recog->x_bool_attr_masks, 0,
4171 sizeof (this_target_recog->x_bool_attr_masks));
4172 for (int i = 0; i < LAST_INSN_CODE; ++i)
4173 if (this_target_recog->x_op_alt[i])
4175 free (this_target_recog->x_op_alt[i]);
4176 this_target_recog->x_op_alt[i] = 0;