1 /* Subroutines used by or related to instruction recognition.
2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
27 #include "rtl-error.h"
29 #include "insn-config.h"
30 #include "insn-attr.h"
31 #include "hard-reg-set.h"
34 #include "addresses.h"
38 #include "basic-block.h"
41 #include "tree-pass.h"
44 #ifndef STACK_PUSH_CODE
45 #ifdef STACK_GROWS_DOWNWARD
46 #define STACK_PUSH_CODE PRE_DEC
48 #define STACK_PUSH_CODE PRE_INC
52 #ifndef STACK_POP_CODE
53 #ifdef STACK_GROWS_DOWNWARD
54 #define STACK_POP_CODE POST_INC
56 #define STACK_POP_CODE POST_DEC
60 #ifndef HAVE_ATTR_enabled
62 get_attr_enabled (rtx insn ATTRIBUTE_UNUSED
)
68 static void validate_replace_rtx_1 (rtx
*, rtx
, rtx
, rtx
, bool);
69 static void validate_replace_src_1 (rtx
*, void *);
70 static rtx
split_insn (rtx
);
72 /* Nonzero means allow operands to be volatile.
73 This should be 0 if you are generating rtl, such as if you are calling
74 the functions in optabs.c and expmed.c (most of the time).
75 This should be 1 if all valid insns need to be recognized,
76 such as in reginfo.c and final.c and reload.c.
78 init_recog and init_recog_no_volatile are responsible for setting this. */
82 struct recog_data recog_data
;
84 /* Contains a vector of operand_alternative structures for every operand.
85 Set up by preprocess_constraints. */
86 struct operand_alternative recog_op_alt
[MAX_RECOG_OPERANDS
][MAX_RECOG_ALTERNATIVES
];
88 /* On return from `constrain_operands', indicate which alternative
91 int which_alternative
;
93 /* Nonzero after end of reload pass.
94 Set to 1 or 0 by toplev.c.
95 Controls the significance of (SUBREG (MEM)). */
99 /* Nonzero after thread_prologue_and_epilogue_insns has run. */
100 int epilogue_completed
;
102 /* Initialize data used by the function `recog'.
103 This must be called once in the compilation of a function
104 before any insn recognition may be done in the function. */
107 init_recog_no_volatile (void)
119 /* Return true if labels in asm operands BODY are LABEL_REFs. */
122 asm_labels_ok (rtx body
)
127 asmop
= extract_asm_operands (body
);
128 if (asmop
== NULL_RTX
)
131 for (i
= 0; i
< ASM_OPERANDS_LABEL_LENGTH (asmop
); i
++)
132 if (GET_CODE (ASM_OPERANDS_LABEL (asmop
, i
)) != LABEL_REF
)
138 /* Check that X is an insn-body for an `asm' with operands
139 and that the operands mentioned in it are legitimate. */
142 check_asm_operands (rtx x
)
146 const char **constraints
;
149 if (!asm_labels_ok (x
))
152 /* Post-reload, be more strict with things. */
153 if (reload_completed
)
155 /* ??? Doh! We've not got the wrapping insn. Cook one up. */
156 extract_insn (make_insn_raw (x
));
157 constrain_operands (1);
158 return which_alternative
>= 0;
161 noperands
= asm_noperands (x
);
167 operands
= XALLOCAVEC (rtx
, noperands
);
168 constraints
= XALLOCAVEC (const char *, noperands
);
170 decode_asm_operands (x
, operands
, NULL
, constraints
, NULL
, NULL
);
172 for (i
= 0; i
< noperands
; i
++)
174 const char *c
= constraints
[i
];
177 if (! asm_operand_ok (operands
[i
], c
, constraints
))
184 /* Static data for the next two routines. */
186 typedef struct change_t
195 static change_t
*changes
;
196 static int changes_allocated
;
198 static int num_changes
= 0;
200 /* Validate a proposed change to OBJECT. LOC is the location in the rtl
201 at which NEW_RTX will be placed. If OBJECT is zero, no validation is done,
202 the change is simply made.
204 Two types of objects are supported: If OBJECT is a MEM, memory_address_p
205 will be called with the address and mode as parameters. If OBJECT is
206 an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
209 IN_GROUP is nonzero if this is part of a group of changes that must be
210 performed as a group. In that case, the changes will be stored. The
211 function `apply_change_group' will validate and apply the changes.
213 If IN_GROUP is zero, this is a single change. Try to recognize the insn
214 or validate the memory reference with the change applied. If the result
215 is not valid for the machine, suppress the change and return zero.
216 Otherwise, perform the change and return 1. */
219 validate_change_1 (rtx object
, rtx
*loc
, rtx new_rtx
, bool in_group
, bool unshare
)
223 if (old
== new_rtx
|| rtx_equal_p (old
, new_rtx
))
226 gcc_assert (in_group
!= 0 || num_changes
== 0);
230 /* Save the information describing this change. */
231 if (num_changes
>= changes_allocated
)
233 if (changes_allocated
== 0)
234 /* This value allows for repeated substitutions inside complex
235 indexed addresses, or changes in up to 5 insns. */
236 changes_allocated
= MAX_RECOG_OPERANDS
* 5;
238 changes_allocated
*= 2;
240 changes
= XRESIZEVEC (change_t
, changes
, changes_allocated
);
243 changes
[num_changes
].object
= object
;
244 changes
[num_changes
].loc
= loc
;
245 changes
[num_changes
].old
= old
;
246 changes
[num_changes
].unshare
= unshare
;
248 if (object
&& !MEM_P (object
))
250 /* Set INSN_CODE to force rerecognition of insn. Save old code in
252 changes
[num_changes
].old_code
= INSN_CODE (object
);
253 INSN_CODE (object
) = -1;
258 /* If we are making a group of changes, return 1. Otherwise, validate the
259 change group we made. */
264 return apply_change_group ();
267 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
271 validate_change (rtx object
, rtx
*loc
, rtx new_rtx
, bool in_group
)
273 return validate_change_1 (object
, loc
, new_rtx
, in_group
, false);
276 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
280 validate_unshare_change (rtx object
, rtx
*loc
, rtx new_rtx
, bool in_group
)
282 return validate_change_1 (object
, loc
, new_rtx
, in_group
, true);
286 /* Keep X canonicalized if some changes have made it non-canonical; only
287 modifies the operands of X, not (for example) its code. Simplifications
288 are not the job of this routine.
290 Return true if anything was changed. */
292 canonicalize_change_group (rtx insn
, rtx x
)
294 if (COMMUTATIVE_P (x
)
295 && swap_commutative_operands_p (XEXP (x
, 0), XEXP (x
, 1)))
297 /* Oops, the caller has made X no longer canonical.
298 Let's redo the changes in the correct order. */
299 rtx tem
= XEXP (x
, 0);
300 validate_unshare_change (insn
, &XEXP (x
, 0), XEXP (x
, 1), 1);
301 validate_unshare_change (insn
, &XEXP (x
, 1), tem
, 1);
309 /* This subroutine of apply_change_group verifies whether the changes to INSN
310 were valid; i.e. whether INSN can still be recognized.
312 If IN_GROUP is true clobbers which have to be added in order to
313 match the instructions will be added to the current change group.
314 Otherwise the changes will take effect immediately. */
317 insn_invalid_p (rtx insn
, bool in_group
)
319 rtx pat
= PATTERN (insn
);
320 int num_clobbers
= 0;
321 /* If we are before reload and the pattern is a SET, see if we can add
323 int icode
= recog (pat
, insn
,
324 (GET_CODE (pat
) == SET
325 && ! reload_completed
&& ! reload_in_progress
)
326 ? &num_clobbers
: 0);
327 int is_asm
= icode
< 0 && asm_noperands (PATTERN (insn
)) >= 0;
330 /* If this is an asm and the operand aren't legal, then fail. Likewise if
331 this is not an asm and the insn wasn't recognized. */
332 if ((is_asm
&& ! check_asm_operands (PATTERN (insn
)))
333 || (!is_asm
&& icode
< 0))
336 /* If we have to add CLOBBERs, fail if we have to add ones that reference
337 hard registers since our callers can't know if they are live or not.
338 Otherwise, add them. */
339 if (num_clobbers
> 0)
343 if (added_clobbers_hard_reg_p (icode
))
346 newpat
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (num_clobbers
+ 1));
347 XVECEXP (newpat
, 0, 0) = pat
;
348 add_clobbers (newpat
, icode
);
350 validate_change (insn
, &PATTERN (insn
), newpat
, 1);
352 PATTERN (insn
) = pat
= newpat
;
355 /* After reload, verify that all constraints are satisfied. */
356 if (reload_completed
)
360 if (! constrain_operands (1))
364 INSN_CODE (insn
) = icode
;
368 /* Return number of changes made and not validated yet. */
370 num_changes_pending (void)
375 /* Tentatively apply the changes numbered NUM and up.
376 Return 1 if all changes are valid, zero otherwise. */
379 verify_changes (int num
)
382 rtx last_validated
= NULL_RTX
;
384 /* The changes have been applied and all INSN_CODEs have been reset to force
387 The changes are valid if we aren't given an object, or if we are
388 given a MEM and it still is a valid address, or if this is in insn
389 and it is recognized. In the latter case, if reload has completed,
390 we also require that the operands meet the constraints for
393 for (i
= num
; i
< num_changes
; i
++)
395 rtx object
= changes
[i
].object
;
397 /* If there is no object to test or if it is the same as the one we
398 already tested, ignore it. */
399 if (object
== 0 || object
== last_validated
)
404 if (! memory_address_addr_space_p (GET_MODE (object
),
406 MEM_ADDR_SPACE (object
)))
409 else if (REG_P (changes
[i
].old
)
410 && asm_noperands (PATTERN (object
)) > 0
411 && REG_EXPR (changes
[i
].old
) != NULL_TREE
412 && DECL_ASSEMBLER_NAME_SET_P (REG_EXPR (changes
[i
].old
))
413 && DECL_REGISTER (REG_EXPR (changes
[i
].old
)))
415 /* Don't allow changes of hard register operands to inline
416 assemblies if they have been defined as register asm ("x"). */
419 else if (DEBUG_INSN_P (object
))
421 else if (insn_invalid_p (object
, true))
423 rtx pat
= PATTERN (object
);
425 /* Perhaps we couldn't recognize the insn because there were
426 extra CLOBBERs at the end. If so, try to re-recognize
427 without the last CLOBBER (later iterations will cause each of
428 them to be eliminated, in turn). But don't do this if we
429 have an ASM_OPERAND. */
430 if (GET_CODE (pat
) == PARALLEL
431 && GET_CODE (XVECEXP (pat
, 0, XVECLEN (pat
, 0) - 1)) == CLOBBER
432 && asm_noperands (PATTERN (object
)) < 0)
436 if (XVECLEN (pat
, 0) == 2)
437 newpat
= XVECEXP (pat
, 0, 0);
443 = gen_rtx_PARALLEL (VOIDmode
,
444 rtvec_alloc (XVECLEN (pat
, 0) - 1));
445 for (j
= 0; j
< XVECLEN (newpat
, 0); j
++)
446 XVECEXP (newpat
, 0, j
) = XVECEXP (pat
, 0, j
);
449 /* Add a new change to this group to replace the pattern
450 with this new pattern. Then consider this change
451 as having succeeded. The change we added will
452 cause the entire call to fail if things remain invalid.
454 Note that this can lose if a later change than the one
455 we are processing specified &XVECEXP (PATTERN (object), 0, X)
456 but this shouldn't occur. */
458 validate_change (object
, &PATTERN (object
), newpat
, 1);
461 else if (GET_CODE (pat
) == USE
|| GET_CODE (pat
) == CLOBBER
462 || GET_CODE (pat
) == VAR_LOCATION
)
463 /* If this insn is a CLOBBER or USE, it is always valid, but is
469 last_validated
= object
;
472 return (i
== num_changes
);
475 /* A group of changes has previously been issued with validate_change
476 and verified with verify_changes. Call df_insn_rescan for each of
477 the insn changed and clear num_changes. */
480 confirm_change_group (void)
483 rtx last_object
= NULL
;
485 for (i
= 0; i
< num_changes
; i
++)
487 rtx object
= changes
[i
].object
;
489 if (changes
[i
].unshare
)
490 *changes
[i
].loc
= copy_rtx (*changes
[i
].loc
);
492 /* Avoid unnecessary rescanning when multiple changes to same instruction
496 if (object
!= last_object
&& last_object
&& INSN_P (last_object
))
497 df_insn_rescan (last_object
);
498 last_object
= object
;
502 if (last_object
&& INSN_P (last_object
))
503 df_insn_rescan (last_object
);
507 /* Apply a group of changes previously issued with `validate_change'.
508 If all changes are valid, call confirm_change_group and return 1,
509 otherwise, call cancel_changes and return 0. */
512 apply_change_group (void)
514 if (verify_changes (0))
516 confirm_change_group ();
527 /* Return the number of changes so far in the current group. */
530 num_validated_changes (void)
535 /* Retract the changes numbered NUM and up. */
538 cancel_changes (int num
)
542 /* Back out all the changes. Do this in the opposite order in which
544 for (i
= num_changes
- 1; i
>= num
; i
--)
546 *changes
[i
].loc
= changes
[i
].old
;
547 if (changes
[i
].object
&& !MEM_P (changes
[i
].object
))
548 INSN_CODE (changes
[i
].object
) = changes
[i
].old_code
;
553 /* A subroutine of validate_replace_rtx_1 that tries to simplify the resulting
557 simplify_while_replacing (rtx
*loc
, rtx to
, rtx object
,
558 enum machine_mode op0_mode
)
561 enum rtx_code code
= GET_CODE (x
);
564 if (SWAPPABLE_OPERANDS_P (x
)
565 && swap_commutative_operands_p (XEXP (x
, 0), XEXP (x
, 1)))
567 validate_unshare_change (object
, loc
,
568 gen_rtx_fmt_ee (COMMUTATIVE_ARITH_P (x
) ? code
569 : swap_condition (code
),
570 GET_MODE (x
), XEXP (x
, 1),
579 /* If we have a PLUS whose second operand is now a CONST_INT, use
580 simplify_gen_binary to try to simplify it.
581 ??? We may want later to remove this, once simplification is
582 separated from this function. */
583 if (CONST_INT_P (XEXP (x
, 1)) && XEXP (x
, 1) == to
)
584 validate_change (object
, loc
,
586 (PLUS
, GET_MODE (x
), XEXP (x
, 0), XEXP (x
, 1)), 1);
589 if (CONST_INT_P (XEXP (x
, 1))
590 || CONST_DOUBLE_AS_INT_P (XEXP (x
, 1)))
591 validate_change (object
, loc
,
593 (PLUS
, GET_MODE (x
), XEXP (x
, 0),
594 simplify_gen_unary (NEG
,
595 GET_MODE (x
), XEXP (x
, 1),
600 if (GET_MODE (XEXP (x
, 0)) == VOIDmode
)
602 new_rtx
= simplify_gen_unary (code
, GET_MODE (x
), XEXP (x
, 0),
604 /* If any of the above failed, substitute in something that
605 we know won't be recognized. */
607 new_rtx
= gen_rtx_CLOBBER (GET_MODE (x
), const0_rtx
);
608 validate_change (object
, loc
, new_rtx
, 1);
612 /* All subregs possible to simplify should be simplified. */
613 new_rtx
= simplify_subreg (GET_MODE (x
), SUBREG_REG (x
), op0_mode
,
616 /* Subregs of VOIDmode operands are incorrect. */
617 if (!new_rtx
&& GET_MODE (SUBREG_REG (x
)) == VOIDmode
)
618 new_rtx
= gen_rtx_CLOBBER (GET_MODE (x
), const0_rtx
);
620 validate_change (object
, loc
, new_rtx
, 1);
624 /* If we are replacing a register with memory, try to change the memory
625 to be the mode required for memory in extract operations (this isn't
626 likely to be an insertion operation; if it was, nothing bad will
627 happen, we might just fail in some cases). */
629 if (MEM_P (XEXP (x
, 0))
630 && CONST_INT_P (XEXP (x
, 1))
631 && CONST_INT_P (XEXP (x
, 2))
632 && !mode_dependent_address_p (XEXP (XEXP (x
, 0), 0),
633 MEM_ADDR_SPACE (XEXP (x
, 0)))
634 && !MEM_VOLATILE_P (XEXP (x
, 0)))
636 enum machine_mode wanted_mode
= VOIDmode
;
637 enum machine_mode is_mode
= GET_MODE (XEXP (x
, 0));
638 int pos
= INTVAL (XEXP (x
, 2));
640 if (GET_CODE (x
) == ZERO_EXTRACT
)
642 enum machine_mode new_mode
643 = mode_for_extraction (EP_extzv
, 1);
644 if (new_mode
!= MAX_MACHINE_MODE
)
645 wanted_mode
= new_mode
;
647 else if (GET_CODE (x
) == SIGN_EXTRACT
)
649 enum machine_mode new_mode
650 = mode_for_extraction (EP_extv
, 1);
651 if (new_mode
!= MAX_MACHINE_MODE
)
652 wanted_mode
= new_mode
;
655 /* If we have a narrower mode, we can do something. */
656 if (wanted_mode
!= VOIDmode
657 && GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
659 int offset
= pos
/ BITS_PER_UNIT
;
662 /* If the bytes and bits are counted differently, we
663 must adjust the offset. */
664 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
666 (GET_MODE_SIZE (is_mode
) - GET_MODE_SIZE (wanted_mode
) -
669 gcc_assert (GET_MODE_PRECISION (wanted_mode
)
670 == GET_MODE_BITSIZE (wanted_mode
));
671 pos
%= GET_MODE_BITSIZE (wanted_mode
);
673 newmem
= adjust_address_nv (XEXP (x
, 0), wanted_mode
, offset
);
675 validate_change (object
, &XEXP (x
, 2), GEN_INT (pos
), 1);
676 validate_change (object
, &XEXP (x
, 0), newmem
, 1);
687 /* Replace every occurrence of FROM in X with TO. Mark each change with
688 validate_change passing OBJECT. */
691 validate_replace_rtx_1 (rtx
*loc
, rtx from
, rtx to
, rtx object
,
698 enum machine_mode op0_mode
= VOIDmode
;
699 int prev_changes
= num_changes
;
705 fmt
= GET_RTX_FORMAT (code
);
707 op0_mode
= GET_MODE (XEXP (x
, 0));
709 /* X matches FROM if it is the same rtx or they are both referring to the
710 same register in the same mode. Avoid calling rtx_equal_p unless the
711 operands look similar. */
714 || (REG_P (x
) && REG_P (from
)
715 && GET_MODE (x
) == GET_MODE (from
)
716 && REGNO (x
) == REGNO (from
))
717 || (GET_CODE (x
) == GET_CODE (from
) && GET_MODE (x
) == GET_MODE (from
)
718 && rtx_equal_p (x
, from
)))
720 validate_unshare_change (object
, loc
, to
, 1);
724 /* Call ourself recursively to perform the replacements.
725 We must not replace inside already replaced expression, otherwise we
726 get infinite recursion for replacements like (reg X)->(subreg (reg X))
727 done by regmove, so we must special case shared ASM_OPERANDS. */
729 if (GET_CODE (x
) == PARALLEL
)
731 for (j
= XVECLEN (x
, 0) - 1; j
>= 0; j
--)
733 if (j
&& GET_CODE (XVECEXP (x
, 0, j
)) == SET
734 && GET_CODE (SET_SRC (XVECEXP (x
, 0, j
))) == ASM_OPERANDS
)
736 /* Verify that operands are really shared. */
737 gcc_assert (ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (x
, 0, 0)))
738 == ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP
740 validate_replace_rtx_1 (&SET_DEST (XVECEXP (x
, 0, j
)),
741 from
, to
, object
, simplify
);
744 validate_replace_rtx_1 (&XVECEXP (x
, 0, j
), from
, to
, object
,
749 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
752 validate_replace_rtx_1 (&XEXP (x
, i
), from
, to
, object
, simplify
);
753 else if (fmt
[i
] == 'E')
754 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
755 validate_replace_rtx_1 (&XVECEXP (x
, i
, j
), from
, to
, object
,
759 /* If we didn't substitute, there is nothing more to do. */
760 if (num_changes
== prev_changes
)
763 /* Allow substituted expression to have different mode. This is used by
764 regmove to change mode of pseudo register. */
765 if (fmt
[0] == 'e' && GET_MODE (XEXP (x
, 0)) != VOIDmode
)
766 op0_mode
= GET_MODE (XEXP (x
, 0));
768 /* Do changes needed to keep rtx consistent. Don't do any other
769 simplifications, as it is not our job. */
771 simplify_while_replacing (loc
, to
, object
, op0_mode
);
774 /* Try replacing every occurrence of FROM in subexpression LOC of INSN
775 with TO. After all changes have been made, validate by seeing
776 if INSN is still valid. */
779 validate_replace_rtx_subexp (rtx from
, rtx to
, rtx insn
, rtx
*loc
)
781 validate_replace_rtx_1 (loc
, from
, to
, insn
, true);
782 return apply_change_group ();
785 /* Try replacing every occurrence of FROM in INSN with TO. After all
786 changes have been made, validate by seeing if INSN is still valid. */
789 validate_replace_rtx (rtx from
, rtx to
, rtx insn
)
791 validate_replace_rtx_1 (&PATTERN (insn
), from
, to
, insn
, true);
792 return apply_change_group ();
795 /* Try replacing every occurrence of FROM in WHERE with TO. Assume that WHERE
796 is a part of INSN. After all changes have been made, validate by seeing if
798 validate_replace_rtx (from, to, insn) is equivalent to
799 validate_replace_rtx_part (from, to, &PATTERN (insn), insn). */
802 validate_replace_rtx_part (rtx from
, rtx to
, rtx
*where
, rtx insn
)
804 validate_replace_rtx_1 (where
, from
, to
, insn
, true);
805 return apply_change_group ();
808 /* Same as above, but do not simplify rtx afterwards. */
810 validate_replace_rtx_part_nosimplify (rtx from
, rtx to
, rtx
*where
,
813 validate_replace_rtx_1 (where
, from
, to
, insn
, false);
814 return apply_change_group ();
818 /* Try replacing every occurrence of FROM in INSN with TO. This also
819 will replace in REG_EQUAL and REG_EQUIV notes. */
822 validate_replace_rtx_group (rtx from
, rtx to
, rtx insn
)
825 validate_replace_rtx_1 (&PATTERN (insn
), from
, to
, insn
, true);
826 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
827 if (REG_NOTE_KIND (note
) == REG_EQUAL
828 || REG_NOTE_KIND (note
) == REG_EQUIV
)
829 validate_replace_rtx_1 (&XEXP (note
, 0), from
, to
, insn
, true);
832 /* Function called by note_uses to replace used subexpressions. */
833 struct validate_replace_src_data
835 rtx from
; /* Old RTX */
836 rtx to
; /* New RTX */
837 rtx insn
; /* Insn in which substitution is occurring. */
841 validate_replace_src_1 (rtx
*x
, void *data
)
843 struct validate_replace_src_data
*d
844 = (struct validate_replace_src_data
*) data
;
846 validate_replace_rtx_1 (x
, d
->from
, d
->to
, d
->insn
, true);
849 /* Try replacing every occurrence of FROM in INSN with TO, avoiding
853 validate_replace_src_group (rtx from
, rtx to
, rtx insn
)
855 struct validate_replace_src_data d
;
860 note_uses (&PATTERN (insn
), validate_replace_src_1
, &d
);
863 /* Try simplify INSN.
864 Invoke simplify_rtx () on every SET_SRC and SET_DEST inside the INSN's
865 pattern and return true if something was simplified. */
868 validate_simplify_insn (rtx insn
)
874 pat
= PATTERN (insn
);
876 if (GET_CODE (pat
) == SET
)
878 newpat
= simplify_rtx (SET_SRC (pat
));
879 if (newpat
&& !rtx_equal_p (SET_SRC (pat
), newpat
))
880 validate_change (insn
, &SET_SRC (pat
), newpat
, 1);
881 newpat
= simplify_rtx (SET_DEST (pat
));
882 if (newpat
&& !rtx_equal_p (SET_DEST (pat
), newpat
))
883 validate_change (insn
, &SET_DEST (pat
), newpat
, 1);
885 else if (GET_CODE (pat
) == PARALLEL
)
886 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
888 rtx s
= XVECEXP (pat
, 0, i
);
890 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
)
892 newpat
= simplify_rtx (SET_SRC (s
));
893 if (newpat
&& !rtx_equal_p (SET_SRC (s
), newpat
))
894 validate_change (insn
, &SET_SRC (s
), newpat
, 1);
895 newpat
= simplify_rtx (SET_DEST (s
));
896 if (newpat
&& !rtx_equal_p (SET_DEST (s
), newpat
))
897 validate_change (insn
, &SET_DEST (s
), newpat
, 1);
900 return ((num_changes_pending () > 0) && (apply_change_group () > 0));
904 /* Return 1 if the insn using CC0 set by INSN does not contain
905 any ordered tests applied to the condition codes.
906 EQ and NE tests do not count. */
909 next_insn_tests_no_inequality (rtx insn
)
911 rtx next
= next_cc0_user (insn
);
913 /* If there is no next insn, we have to take the conservative choice. */
917 return (INSN_P (next
)
918 && ! inequality_comparisons_p (PATTERN (next
)));
922 /* Return 1 if OP is a valid general operand for machine mode MODE.
923 This is either a register reference, a memory reference,
924 or a constant. In the case of a memory reference, the address
925 is checked for general validity for the target machine.
927 Register and memory references must have mode MODE in order to be valid,
928 but some constants have no machine mode and are valid for any mode.
930 If MODE is VOIDmode, OP is checked for validity for whatever mode
933 The main use of this function is as a predicate in match_operand
934 expressions in the machine description. */
937 general_operand (rtx op
, enum machine_mode mode
)
939 enum rtx_code code
= GET_CODE (op
);
941 if (mode
== VOIDmode
)
942 mode
= GET_MODE (op
);
944 /* Don't accept CONST_INT or anything similar
945 if the caller wants something floating. */
946 if (GET_MODE (op
) == VOIDmode
&& mode
!= VOIDmode
947 && GET_MODE_CLASS (mode
) != MODE_INT
948 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
953 && trunc_int_for_mode (INTVAL (op
), mode
) != INTVAL (op
))
957 return ((GET_MODE (op
) == VOIDmode
|| GET_MODE (op
) == mode
959 && (! flag_pic
|| LEGITIMATE_PIC_OPERAND_P (op
))
960 && targetm
.legitimate_constant_p (mode
== VOIDmode
964 /* Except for certain constants with VOIDmode, already checked for,
965 OP's mode must match MODE if MODE specifies a mode. */
967 if (GET_MODE (op
) != mode
)
972 rtx sub
= SUBREG_REG (op
);
974 #ifdef INSN_SCHEDULING
975 /* On machines that have insn scheduling, we want all memory
976 reference to be explicit, so outlaw paradoxical SUBREGs.
977 However, we must allow them after reload so that they can
978 get cleaned up by cleanup_subreg_operands. */
979 if (!reload_completed
&& MEM_P (sub
)
980 && GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (sub
)))
983 /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
984 may result in incorrect reference. We should simplify all valid
985 subregs of MEM anyway. But allow this after reload because we
986 might be called from cleanup_subreg_operands.
988 ??? This is a kludge. */
989 if (!reload_completed
&& SUBREG_BYTE (op
) != 0
993 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
994 create such rtl, and we must reject it. */
995 if (SCALAR_FLOAT_MODE_P (GET_MODE (op
))
996 && GET_MODE_SIZE (GET_MODE (op
)) > GET_MODE_SIZE (GET_MODE (sub
)))
1000 code
= GET_CODE (op
);
1004 return (REGNO (op
) >= FIRST_PSEUDO_REGISTER
1005 || in_hard_reg_set_p (operand_reg_set
, GET_MODE (op
), REGNO (op
)));
1009 rtx y
= XEXP (op
, 0);
1011 if (! volatile_ok
&& MEM_VOLATILE_P (op
))
1014 /* Use the mem's mode, since it will be reloaded thus. */
1015 if (memory_address_addr_space_p (GET_MODE (op
), y
, MEM_ADDR_SPACE (op
)))
1022 /* Return 1 if OP is a valid memory address for a memory reference
1025 The main use of this function is as a predicate in match_operand
1026 expressions in the machine description. */
1029 address_operand (rtx op
, enum machine_mode mode
)
1031 return memory_address_p (mode
, op
);
1034 /* Return 1 if OP is a register reference of mode MODE.
1035 If MODE is VOIDmode, accept a register in any mode.
1037 The main use of this function is as a predicate in match_operand
1038 expressions in the machine description. */
1041 register_operand (rtx op
, enum machine_mode mode
)
1043 if (GET_MODE (op
) != mode
&& mode
!= VOIDmode
)
1046 if (GET_CODE (op
) == SUBREG
)
1048 rtx sub
= SUBREG_REG (op
);
1050 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1051 because it is guaranteed to be reloaded into one.
1052 Just make sure the MEM is valid in itself.
1053 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1054 but currently it does result from (SUBREG (REG)...) where the
1055 reg went on the stack.) */
1056 if (! reload_completed
&& MEM_P (sub
))
1057 return general_operand (op
, mode
);
1059 #ifdef CANNOT_CHANGE_MODE_CLASS
1061 && REGNO (sub
) < FIRST_PSEUDO_REGISTER
1062 && REG_CANNOT_CHANGE_MODE_P (REGNO (sub
), GET_MODE (sub
), mode
)
1063 && GET_MODE_CLASS (GET_MODE (sub
)) != MODE_COMPLEX_INT
1064 && GET_MODE_CLASS (GET_MODE (sub
)) != MODE_COMPLEX_FLOAT
)
1068 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
1069 create such rtl, and we must reject it. */
1070 if (SCALAR_FLOAT_MODE_P (GET_MODE (op
))
1071 && GET_MODE_SIZE (GET_MODE (op
)) > GET_MODE_SIZE (GET_MODE (sub
)))
1078 && (REGNO (op
) >= FIRST_PSEUDO_REGISTER
1079 || in_hard_reg_set_p (operand_reg_set
,
1080 GET_MODE (op
), REGNO (op
))));
1083 /* Return 1 for a register in Pmode; ignore the tested mode. */
1086 pmode_register_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1088 return register_operand (op
, Pmode
);
1091 /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
1092 or a hard register. */
1095 scratch_operand (rtx op
, enum machine_mode mode
)
1097 if (GET_MODE (op
) != mode
&& mode
!= VOIDmode
)
1100 return (GET_CODE (op
) == SCRATCH
1102 && REGNO (op
) < FIRST_PSEUDO_REGISTER
));
1105 /* Return 1 if OP is a valid immediate operand for mode MODE.
1107 The main use of this function is as a predicate in match_operand
1108 expressions in the machine description. */
1111 immediate_operand (rtx op
, enum machine_mode mode
)
1113 /* Don't accept CONST_INT or anything similar
1114 if the caller wants something floating. */
1115 if (GET_MODE (op
) == VOIDmode
&& mode
!= VOIDmode
1116 && GET_MODE_CLASS (mode
) != MODE_INT
1117 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
1120 if (CONST_INT_P (op
)
1122 && trunc_int_for_mode (INTVAL (op
), mode
) != INTVAL (op
))
1125 return (CONSTANT_P (op
)
1126 && (GET_MODE (op
) == mode
|| mode
== VOIDmode
1127 || GET_MODE (op
) == VOIDmode
)
1128 && (! flag_pic
|| LEGITIMATE_PIC_OPERAND_P (op
))
1129 && targetm
.legitimate_constant_p (mode
== VOIDmode
1134 /* Returns 1 if OP is an operand that is a CONST_INT. */
1137 const_int_operand (rtx op
, enum machine_mode mode
)
1139 if (!CONST_INT_P (op
))
1142 if (mode
!= VOIDmode
1143 && trunc_int_for_mode (INTVAL (op
), mode
) != INTVAL (op
))
1149 /* Returns 1 if OP is an operand that is a constant integer or constant
1150 floating-point number. */
1153 const_double_operand (rtx op
, enum machine_mode mode
)
1155 /* Don't accept CONST_INT or anything similar
1156 if the caller wants something floating. */
1157 if (GET_MODE (op
) == VOIDmode
&& mode
!= VOIDmode
1158 && GET_MODE_CLASS (mode
) != MODE_INT
1159 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
1162 return ((CONST_DOUBLE_P (op
) || CONST_INT_P (op
))
1163 && (mode
== VOIDmode
|| GET_MODE (op
) == mode
1164 || GET_MODE (op
) == VOIDmode
));
1167 /* Return 1 if OP is a general operand that is not an immediate operand. */
1170 nonimmediate_operand (rtx op
, enum machine_mode mode
)
1172 return (general_operand (op
, mode
) && ! CONSTANT_P (op
));
1175 /* Return 1 if OP is a register reference or immediate value of mode MODE. */
1178 nonmemory_operand (rtx op
, enum machine_mode mode
)
1180 if (CONSTANT_P (op
))
1181 return immediate_operand (op
, mode
);
1183 if (GET_MODE (op
) != mode
&& mode
!= VOIDmode
)
1186 if (GET_CODE (op
) == SUBREG
)
1188 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1189 because it is guaranteed to be reloaded into one.
1190 Just make sure the MEM is valid in itself.
1191 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1192 but currently it does result from (SUBREG (REG)...) where the
1193 reg went on the stack.) */
1194 if (! reload_completed
&& MEM_P (SUBREG_REG (op
)))
1195 return general_operand (op
, mode
);
1196 op
= SUBREG_REG (op
);
1200 && (REGNO (op
) >= FIRST_PSEUDO_REGISTER
1201 || in_hard_reg_set_p (operand_reg_set
,
1202 GET_MODE (op
), REGNO (op
))));
1205 /* Return 1 if OP is a valid operand that stands for pushing a
1206 value of mode MODE onto the stack.
1208 The main use of this function is as a predicate in match_operand
1209 expressions in the machine description. */
1212 push_operand (rtx op
, enum machine_mode mode
)
1214 unsigned int rounded_size
= GET_MODE_SIZE (mode
);
1216 #ifdef PUSH_ROUNDING
1217 rounded_size
= PUSH_ROUNDING (rounded_size
);
1223 if (mode
!= VOIDmode
&& GET_MODE (op
) != mode
)
1228 if (rounded_size
== GET_MODE_SIZE (mode
))
1230 if (GET_CODE (op
) != STACK_PUSH_CODE
)
1235 if (GET_CODE (op
) != PRE_MODIFY
1236 || GET_CODE (XEXP (op
, 1)) != PLUS
1237 || XEXP (XEXP (op
, 1), 0) != XEXP (op
, 0)
1238 || !CONST_INT_P (XEXP (XEXP (op
, 1), 1))
1239 #ifdef STACK_GROWS_DOWNWARD
1240 || INTVAL (XEXP (XEXP (op
, 1), 1)) != - (int) rounded_size
1242 || INTVAL (XEXP (XEXP (op
, 1), 1)) != (int) rounded_size
1248 return XEXP (op
, 0) == stack_pointer_rtx
;
1251 /* Return 1 if OP is a valid operand that stands for popping a
1252 value of mode MODE off the stack.
1254 The main use of this function is as a predicate in match_operand
1255 expressions in the machine description. */
1258 pop_operand (rtx op
, enum machine_mode mode
)
1263 if (mode
!= VOIDmode
&& GET_MODE (op
) != mode
)
1268 if (GET_CODE (op
) != STACK_POP_CODE
)
1271 return XEXP (op
, 0) == stack_pointer_rtx
;
1274 /* Return 1 if ADDR is a valid memory address
1275 for mode MODE in address space AS. */
1278 memory_address_addr_space_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
1279 rtx addr
, addr_space_t as
)
1281 #ifdef GO_IF_LEGITIMATE_ADDRESS
1282 gcc_assert (ADDR_SPACE_GENERIC_P (as
));
1283 GO_IF_LEGITIMATE_ADDRESS (mode
, addr
, win
);
1289 return targetm
.addr_space
.legitimate_address_p (mode
, addr
, 0, as
);
1293 /* Return 1 if OP is a valid memory reference with mode MODE,
1294 including a valid address.
1296 The main use of this function is as a predicate in match_operand
1297 expressions in the machine description. */
1300 memory_operand (rtx op
, enum machine_mode mode
)
1304 if (! reload_completed
)
1305 /* Note that no SUBREG is a memory operand before end of reload pass,
1306 because (SUBREG (MEM...)) forces reloading into a register. */
1307 return MEM_P (op
) && general_operand (op
, mode
);
1309 if (mode
!= VOIDmode
&& GET_MODE (op
) != mode
)
1313 if (GET_CODE (inner
) == SUBREG
)
1314 inner
= SUBREG_REG (inner
);
1316 return (MEM_P (inner
) && general_operand (op
, mode
));
1319 /* Return 1 if OP is a valid indirect memory reference with mode MODE;
1320 that is, a memory reference whose address is a general_operand. */
1323 indirect_operand (rtx op
, enum machine_mode mode
)
1325 /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1326 if (! reload_completed
1327 && GET_CODE (op
) == SUBREG
&& MEM_P (SUBREG_REG (op
)))
1329 int offset
= SUBREG_BYTE (op
);
1330 rtx inner
= SUBREG_REG (op
);
1332 if (mode
!= VOIDmode
&& GET_MODE (op
) != mode
)
1335 /* The only way that we can have a general_operand as the resulting
1336 address is if OFFSET is zero and the address already is an operand
1337 or if the address is (plus Y (const_int -OFFSET)) and Y is an
1340 return ((offset
== 0 && general_operand (XEXP (inner
, 0), Pmode
))
1341 || (GET_CODE (XEXP (inner
, 0)) == PLUS
1342 && CONST_INT_P (XEXP (XEXP (inner
, 0), 1))
1343 && INTVAL (XEXP (XEXP (inner
, 0), 1)) == -offset
1344 && general_operand (XEXP (XEXP (inner
, 0), 0), Pmode
)));
1348 && memory_operand (op
, mode
)
1349 && general_operand (XEXP (op
, 0), Pmode
));
1352 /* Return 1 if this is an ordered comparison operator (not including
1353 ORDERED and UNORDERED). */
1356 ordered_comparison_operator (rtx op
, enum machine_mode mode
)
1358 if (mode
!= VOIDmode
&& GET_MODE (op
) != mode
)
1360 switch (GET_CODE (op
))
1378 /* Return 1 if this is a comparison operator. This allows the use of
1379 MATCH_OPERATOR to recognize all the branch insns. */
1382 comparison_operator (rtx op
, enum machine_mode mode
)
1384 return ((mode
== VOIDmode
|| GET_MODE (op
) == mode
)
1385 && COMPARISON_P (op
));
1388 /* If BODY is an insn body that uses ASM_OPERANDS, return it. */
1391 extract_asm_operands (rtx body
)
1394 switch (GET_CODE (body
))
1400 /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
1401 tmp
= SET_SRC (body
);
1402 if (GET_CODE (tmp
) == ASM_OPERANDS
)
1407 tmp
= XVECEXP (body
, 0, 0);
1408 if (GET_CODE (tmp
) == ASM_OPERANDS
)
1410 if (GET_CODE (tmp
) == SET
)
1412 tmp
= SET_SRC (tmp
);
1413 if (GET_CODE (tmp
) == ASM_OPERANDS
)
1424 /* If BODY is an insn body that uses ASM_OPERANDS,
1425 return the number of operands (both input and output) in the insn.
1426 Otherwise return -1. */
1429 asm_noperands (const_rtx body
)
1431 rtx asm_op
= extract_asm_operands (CONST_CAST_RTX (body
));
1437 if (GET_CODE (body
) == SET
)
1439 else if (GET_CODE (body
) == PARALLEL
)
1442 if (GET_CODE (XVECEXP (body
, 0, 0)) == SET
)
1444 /* Multiple output operands, or 1 output plus some clobbers:
1446 [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
1447 /* Count backwards through CLOBBERs to determine number of SETs. */
1448 for (i
= XVECLEN (body
, 0); i
> 0; i
--)
1450 if (GET_CODE (XVECEXP (body
, 0, i
- 1)) == SET
)
1452 if (GET_CODE (XVECEXP (body
, 0, i
- 1)) != CLOBBER
)
1456 /* N_SETS is now number of output operands. */
1459 /* Verify that all the SETs we have
1460 came from a single original asm_operands insn
1461 (so that invalid combinations are blocked). */
1462 for (i
= 0; i
< n_sets
; i
++)
1464 rtx elt
= XVECEXP (body
, 0, i
);
1465 if (GET_CODE (elt
) != SET
)
1467 if (GET_CODE (SET_SRC (elt
)) != ASM_OPERANDS
)
1469 /* If these ASM_OPERANDS rtx's came from different original insns
1470 then they aren't allowed together. */
1471 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt
))
1472 != ASM_OPERANDS_INPUT_VEC (asm_op
))
1478 /* 0 outputs, but some clobbers:
1479 body is [(asm_operands ...) (clobber (reg ...))...]. */
1480 /* Make sure all the other parallel things really are clobbers. */
1481 for (i
= XVECLEN (body
, 0) - 1; i
> 0; i
--)
1482 if (GET_CODE (XVECEXP (body
, 0, i
)) != CLOBBER
)
1487 return (ASM_OPERANDS_INPUT_LENGTH (asm_op
)
1488 + ASM_OPERANDS_LABEL_LENGTH (asm_op
) + n_sets
);
1491 /* Assuming BODY is an insn body that uses ASM_OPERANDS,
1492 copy its operands (both input and output) into the vector OPERANDS,
1493 the locations of the operands within the insn into the vector OPERAND_LOCS,
1494 and the constraints for the operands into CONSTRAINTS.
1495 Write the modes of the operands into MODES.
1496 Return the assembler-template.
1498 If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1499 we don't store that info. */
1502 decode_asm_operands (rtx body
, rtx
*operands
, rtx
**operand_locs
,
1503 const char **constraints
, enum machine_mode
*modes
,
1506 int nbase
= 0, n
, i
;
1509 switch (GET_CODE (body
))
1512 /* Zero output asm: BODY is (asm_operands ...). */
1517 /* Single output asm: BODY is (set OUTPUT (asm_operands ...)). */
1518 asmop
= SET_SRC (body
);
1520 /* The output is in the SET.
1521 Its constraint is in the ASM_OPERANDS itself. */
1523 operands
[0] = SET_DEST (body
);
1525 operand_locs
[0] = &SET_DEST (body
);
1527 constraints
[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop
);
1529 modes
[0] = GET_MODE (SET_DEST (body
));
1535 int nparallel
= XVECLEN (body
, 0); /* Includes CLOBBERs. */
1537 asmop
= XVECEXP (body
, 0, 0);
1538 if (GET_CODE (asmop
) == SET
)
1540 asmop
= SET_SRC (asmop
);
1542 /* At least one output, plus some CLOBBERs. The outputs are in
1543 the SETs. Their constraints are in the ASM_OPERANDS itself. */
1544 for (i
= 0; i
< nparallel
; i
++)
1546 if (GET_CODE (XVECEXP (body
, 0, i
)) == CLOBBER
)
1547 break; /* Past last SET */
1549 operands
[i
] = SET_DEST (XVECEXP (body
, 0, i
));
1551 operand_locs
[i
] = &SET_DEST (XVECEXP (body
, 0, i
));
1553 constraints
[i
] = XSTR (SET_SRC (XVECEXP (body
, 0, i
)), 1);
1555 modes
[i
] = GET_MODE (SET_DEST (XVECEXP (body
, 0, i
)));
1566 n
= ASM_OPERANDS_INPUT_LENGTH (asmop
);
1567 for (i
= 0; i
< n
; i
++)
1570 operand_locs
[nbase
+ i
] = &ASM_OPERANDS_INPUT (asmop
, i
);
1572 operands
[nbase
+ i
] = ASM_OPERANDS_INPUT (asmop
, i
);
1574 constraints
[nbase
+ i
] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop
, i
);
1576 modes
[nbase
+ i
] = ASM_OPERANDS_INPUT_MODE (asmop
, i
);
1580 n
= ASM_OPERANDS_LABEL_LENGTH (asmop
);
1581 for (i
= 0; i
< n
; i
++)
1584 operand_locs
[nbase
+ i
] = &ASM_OPERANDS_LABEL (asmop
, i
);
1586 operands
[nbase
+ i
] = ASM_OPERANDS_LABEL (asmop
, i
);
1588 constraints
[nbase
+ i
] = "";
1590 modes
[nbase
+ i
] = Pmode
;
1594 *loc
= ASM_OPERANDS_SOURCE_LOCATION (asmop
);
1596 return ASM_OPERANDS_TEMPLATE (asmop
);
1599 /* Check if an asm_operand matches its constraints.
1600 Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
1603 asm_operand_ok (rtx op
, const char *constraint
, const char **constraints
)
1607 bool incdec_ok
= false;
1610 /* Use constrain_operands after reload. */
1611 gcc_assert (!reload_completed
);
1613 /* Empty constraint string is the same as "X,...,X", i.e. X for as
1614 many alternatives as required to match the other operands. */
1615 if (*constraint
== '\0')
1620 char c
= *constraint
;
1637 case '0': case '1': case '2': case '3': case '4':
1638 case '5': case '6': case '7': case '8': case '9':
1639 /* If caller provided constraints pointer, look up
1640 the maching constraint. Otherwise, our caller should have
1641 given us the proper matching constraint, but we can't
1642 actually fail the check if they didn't. Indicate that
1643 results are inconclusive. */
1647 unsigned long match
;
1649 match
= strtoul (constraint
, &end
, 10);
1651 result
= asm_operand_ok (op
, constraints
[match
], NULL
);
1652 constraint
= (const char *) end
;
1658 while (ISDIGIT (*constraint
));
1665 if (address_operand (op
, VOIDmode
))
1669 case TARGET_MEM_CONSTRAINT
:
1670 case 'V': /* non-offsettable */
1671 if (memory_operand (op
, VOIDmode
))
1675 case 'o': /* offsettable */
1676 if (offsettable_nonstrict_memref_p (op
))
1681 /* ??? Before auto-inc-dec, auto inc/dec insns are not supposed to exist,
1682 excepting those that expand_call created. Further, on some
1683 machines which do not have generalized auto inc/dec, an inc/dec
1684 is not a memory_operand.
1686 Match any memory and hope things are resolved after reload. */
1690 || GET_CODE (XEXP (op
, 0)) == PRE_DEC
1691 || GET_CODE (XEXP (op
, 0)) == POST_DEC
))
1701 || GET_CODE (XEXP (op
, 0)) == PRE_INC
1702 || GET_CODE (XEXP (op
, 0)) == POST_INC
))
1711 if (CONST_DOUBLE_AS_FLOAT_P (op
)
1712 || (GET_CODE (op
) == CONST_VECTOR
1713 && GET_MODE_CLASS (GET_MODE (op
)) == MODE_VECTOR_FLOAT
))
1718 if (CONST_DOUBLE_AS_FLOAT_P (op
)
1719 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, 'G', constraint
))
1723 if (CONST_DOUBLE_AS_FLOAT_P (op
)
1724 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, 'H', constraint
))
1729 if (CONST_INT_P (op
) || CONST_DOUBLE_AS_INT_P (op
))
1734 if (CONSTANT_P (op
) && (! flag_pic
|| LEGITIMATE_PIC_OPERAND_P (op
)))
1739 if (CONST_INT_P (op
) || CONST_DOUBLE_AS_INT_P (op
))
1744 if (CONST_INT_P (op
)
1745 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), 'I', constraint
))
1749 if (CONST_INT_P (op
)
1750 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), 'J', constraint
))
1754 if (CONST_INT_P (op
)
1755 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), 'K', constraint
))
1759 if (CONST_INT_P (op
)
1760 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), 'L', constraint
))
1764 if (CONST_INT_P (op
)
1765 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), 'M', constraint
))
1769 if (CONST_INT_P (op
)
1770 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), 'N', constraint
))
1774 if (CONST_INT_P (op
)
1775 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), 'O', constraint
))
1779 if (CONST_INT_P (op
)
1780 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), 'P', constraint
))
1789 if (general_operand (op
, VOIDmode
))
1794 /* For all other letters, we first check for a register class,
1795 otherwise it is an EXTRA_CONSTRAINT. */
1796 if (REG_CLASS_FROM_CONSTRAINT (c
, constraint
) != NO_REGS
)
1799 if (GET_MODE (op
) == BLKmode
)
1801 if (register_operand (op
, VOIDmode
))
1804 #ifdef EXTRA_CONSTRAINT_STR
1805 else if (EXTRA_MEMORY_CONSTRAINT (c
, constraint
))
1806 /* Every memory operand can be reloaded to fit. */
1807 result
= result
|| memory_operand (op
, VOIDmode
);
1808 else if (EXTRA_ADDRESS_CONSTRAINT (c
, constraint
))
1809 /* Every address operand can be reloaded to fit. */
1810 result
= result
|| address_operand (op
, VOIDmode
);
1811 else if (EXTRA_CONSTRAINT_STR (op
, c
, constraint
))
1816 len
= CONSTRAINT_LEN (c
, constraint
);
1819 while (--len
&& *constraint
);
1825 /* For operands without < or > constraints reject side-effects. */
1826 if (!incdec_ok
&& result
&& MEM_P (op
))
1827 switch (GET_CODE (XEXP (op
, 0)))
1844 /* Given an rtx *P, if it is a sum containing an integer constant term,
1845 return the location (type rtx *) of the pointer to that constant term.
1846 Otherwise, return a null pointer. */
1849 find_constant_term_loc (rtx
*p
)
1852 enum rtx_code code
= GET_CODE (*p
);
1854 /* If *P IS such a constant term, P is its location. */
1856 if (code
== CONST_INT
|| code
== SYMBOL_REF
|| code
== LABEL_REF
1860 /* Otherwise, if not a sum, it has no constant term. */
1862 if (GET_CODE (*p
) != PLUS
)
1865 /* If one of the summands is constant, return its location. */
1867 if (XEXP (*p
, 0) && CONSTANT_P (XEXP (*p
, 0))
1868 && XEXP (*p
, 1) && CONSTANT_P (XEXP (*p
, 1)))
1871 /* Otherwise, check each summand for containing a constant term. */
1873 if (XEXP (*p
, 0) != 0)
1875 tem
= find_constant_term_loc (&XEXP (*p
, 0));
1880 if (XEXP (*p
, 1) != 0)
1882 tem
= find_constant_term_loc (&XEXP (*p
, 1));
1890 /* Return 1 if OP is a memory reference
1891 whose address contains no side effects
1892 and remains valid after the addition
1893 of a positive integer less than the
1894 size of the object being referenced.
1896 We assume that the original address is valid and do not check it.
1898 This uses strict_memory_address_p as a subroutine, so
1899 don't use it before reload. */
1902 offsettable_memref_p (rtx op
)
1904 return ((MEM_P (op
))
1905 && offsettable_address_addr_space_p (1, GET_MODE (op
), XEXP (op
, 0),
1906 MEM_ADDR_SPACE (op
)));
1909 /* Similar, but don't require a strictly valid mem ref:
1910 consider pseudo-regs valid as index or base regs. */
1913 offsettable_nonstrict_memref_p (rtx op
)
1915 return ((MEM_P (op
))
1916 && offsettable_address_addr_space_p (0, GET_MODE (op
), XEXP (op
, 0),
1917 MEM_ADDR_SPACE (op
)));
1920 /* Return 1 if Y is a memory address which contains no side effects
1921 and would remain valid for address space AS after the addition of
1922 a positive integer less than the size of that mode.
1924 We assume that the original address is valid and do not check it.
1925 We do check that it is valid for narrower modes.
1927 If STRICTP is nonzero, we require a strictly valid address,
1928 for the sake of use in reload.c. */
1931 offsettable_address_addr_space_p (int strictp
, enum machine_mode mode
, rtx y
,
1934 enum rtx_code ycode
= GET_CODE (y
);
1938 int (*addressp
) (enum machine_mode
, rtx
, addr_space_t
) =
1939 (strictp
? strict_memory_address_addr_space_p
1940 : memory_address_addr_space_p
);
1941 unsigned int mode_sz
= GET_MODE_SIZE (mode
);
1943 if (CONSTANT_ADDRESS_P (y
))
1946 /* Adjusting an offsettable address involves changing to a narrower mode.
1947 Make sure that's OK. */
1949 if (mode_dependent_address_p (y
, as
))
1952 /* ??? How much offset does an offsettable BLKmode reference need?
1953 Clearly that depends on the situation in which it's being used.
1954 However, the current situation in which we test 0xffffffff is
1955 less than ideal. Caveat user. */
1957 mode_sz
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
1959 /* If the expression contains a constant term,
1960 see if it remains valid when max possible offset is added. */
1962 if ((ycode
== PLUS
) && (y2
= find_constant_term_loc (&y1
)))
1967 *y2
= plus_constant (GET_MODE (y
), *y2
, mode_sz
- 1);
1968 /* Use QImode because an odd displacement may be automatically invalid
1969 for any wider mode. But it should be valid for a single byte. */
1970 good
= (*addressp
) (QImode
, y
, as
);
1972 /* In any case, restore old contents of memory. */
1977 if (GET_RTX_CLASS (ycode
) == RTX_AUTOINC
)
1980 /* The offset added here is chosen as the maximum offset that
1981 any instruction could need to add when operating on something
1982 of the specified mode. We assume that if Y and Y+c are
1983 valid addresses then so is Y+d for all 0<d<c. adjust_address will
1984 go inside a LO_SUM here, so we do so as well. */
1985 if (GET_CODE (y
) == LO_SUM
1987 && mode_sz
<= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
)
1988 z
= gen_rtx_LO_SUM (GET_MODE (y
), XEXP (y
, 0),
1989 plus_constant (GET_MODE (y
), XEXP (y
, 1),
1992 z
= plus_constant (GET_MODE (y
), y
, mode_sz
- 1);
1994 /* Use QImode because an odd displacement may be automatically invalid
1995 for any wider mode. But it should be valid for a single byte. */
1996 return (*addressp
) (QImode
, z
, as
);
1999 /* Return 1 if ADDR is an address-expression whose effect depends
2000 on the mode of the memory reference it is used in.
2002 ADDRSPACE is the address space associated with the address.
2004 Autoincrement addressing is a typical example of mode-dependence
2005 because the amount of the increment depends on the mode. */
2008 mode_dependent_address_p (rtx addr
, addr_space_t addrspace
)
2010 /* Auto-increment addressing with anything other than post_modify
2011 or pre_modify always introduces a mode dependency. Catch such
2012 cases now instead of deferring to the target. */
2013 if (GET_CODE (addr
) == PRE_INC
2014 || GET_CODE (addr
) == POST_INC
2015 || GET_CODE (addr
) == PRE_DEC
2016 || GET_CODE (addr
) == POST_DEC
)
2019 return targetm
.mode_dependent_address_p (addr
, addrspace
);
2022 /* Like extract_insn, but save insn extracted and don't extract again, when
2023 called again for the same insn expecting that recog_data still contain the
2024 valid information. This is used primary by gen_attr infrastructure that
2025 often does extract insn again and again. */
2027 extract_insn_cached (rtx insn
)
2029 if (recog_data
.insn
== insn
&& INSN_CODE (insn
) >= 0)
2031 extract_insn (insn
);
2032 recog_data
.insn
= insn
;
2035 /* Do cached extract_insn, constrain_operands and complain about failures.
2036 Used by insn_attrtab. */
2038 extract_constrain_insn_cached (rtx insn
)
2040 extract_insn_cached (insn
);
2041 if (which_alternative
== -1
2042 && !constrain_operands (reload_completed
))
2043 fatal_insn_not_found (insn
);
2046 /* Do cached constrain_operands and complain about failures. */
2048 constrain_operands_cached (int strict
)
2050 if (which_alternative
== -1)
2051 return constrain_operands (strict
);
2056 /* Analyze INSN and fill in recog_data. */
2059 extract_insn (rtx insn
)
2064 rtx body
= PATTERN (insn
);
2066 recog_data
.n_operands
= 0;
2067 recog_data
.n_alternatives
= 0;
2068 recog_data
.n_dups
= 0;
2069 recog_data
.is_asm
= false;
2071 switch (GET_CODE (body
))
2082 if (GET_CODE (SET_SRC (body
)) == ASM_OPERANDS
)
2087 if ((GET_CODE (XVECEXP (body
, 0, 0)) == SET
2088 && GET_CODE (SET_SRC (XVECEXP (body
, 0, 0))) == ASM_OPERANDS
)
2089 || GET_CODE (XVECEXP (body
, 0, 0)) == ASM_OPERANDS
)
2095 recog_data
.n_operands
= noperands
= asm_noperands (body
);
2098 /* This insn is an `asm' with operands. */
2100 /* expand_asm_operands makes sure there aren't too many operands. */
2101 gcc_assert (noperands
<= MAX_RECOG_OPERANDS
);
2103 /* Now get the operand values and constraints out of the insn. */
2104 decode_asm_operands (body
, recog_data
.operand
,
2105 recog_data
.operand_loc
,
2106 recog_data
.constraints
,
2107 recog_data
.operand_mode
, NULL
);
2108 memset (recog_data
.is_operator
, 0, sizeof recog_data
.is_operator
);
2111 const char *p
= recog_data
.constraints
[0];
2112 recog_data
.n_alternatives
= 1;
2114 recog_data
.n_alternatives
+= (*p
++ == ',');
2116 recog_data
.is_asm
= true;
2119 fatal_insn_not_found (insn
);
2123 /* Ordinary insn: recognize it, get the operands via insn_extract
2124 and get the constraints. */
2126 icode
= recog_memoized (insn
);
2128 fatal_insn_not_found (insn
);
2130 recog_data
.n_operands
= noperands
= insn_data
[icode
].n_operands
;
2131 recog_data
.n_alternatives
= insn_data
[icode
].n_alternatives
;
2132 recog_data
.n_dups
= insn_data
[icode
].n_dups
;
2134 insn_extract (insn
);
2136 for (i
= 0; i
< noperands
; i
++)
2138 recog_data
.constraints
[i
] = insn_data
[icode
].operand
[i
].constraint
;
2139 recog_data
.is_operator
[i
] = insn_data
[icode
].operand
[i
].is_operator
;
2140 recog_data
.operand_mode
[i
] = insn_data
[icode
].operand
[i
].mode
;
2141 /* VOIDmode match_operands gets mode from their real operand. */
2142 if (recog_data
.operand_mode
[i
] == VOIDmode
)
2143 recog_data
.operand_mode
[i
] = GET_MODE (recog_data
.operand
[i
]);
2146 for (i
= 0; i
< noperands
; i
++)
2147 recog_data
.operand_type
[i
]
2148 = (recog_data
.constraints
[i
][0] == '=' ? OP_OUT
2149 : recog_data
.constraints
[i
][0] == '+' ? OP_INOUT
2152 gcc_assert (recog_data
.n_alternatives
<= MAX_RECOG_ALTERNATIVES
);
2154 if (INSN_CODE (insn
) < 0)
2155 for (i
= 0; i
< recog_data
.n_alternatives
; i
++)
2156 recog_data
.alternative_enabled_p
[i
] = true;
2159 recog_data
.insn
= insn
;
2160 for (i
= 0; i
< recog_data
.n_alternatives
; i
++)
2162 which_alternative
= i
;
2163 recog_data
.alternative_enabled_p
[i
] = get_attr_enabled (insn
);
2167 recog_data
.insn
= NULL
;
2168 which_alternative
= -1;
2171 /* After calling extract_insn, you can use this function to extract some
2172 information from the constraint strings into a more usable form.
2173 The collected data is stored in recog_op_alt. */
2175 preprocess_constraints (void)
2179 for (i
= 0; i
< recog_data
.n_operands
; i
++)
2180 memset (recog_op_alt
[i
], 0, (recog_data
.n_alternatives
2181 * sizeof (struct operand_alternative
)));
2183 for (i
= 0; i
< recog_data
.n_operands
; i
++)
2186 struct operand_alternative
*op_alt
;
2187 const char *p
= recog_data
.constraints
[i
];
2189 op_alt
= recog_op_alt
[i
];
2191 for (j
= 0; j
< recog_data
.n_alternatives
; j
++)
2193 op_alt
[j
].cl
= NO_REGS
;
2194 op_alt
[j
].constraint
= p
;
2195 op_alt
[j
].matches
= -1;
2196 op_alt
[j
].matched
= -1;
2198 if (!recog_data
.alternative_enabled_p
[j
])
2200 p
= skip_alternative (p
);
2204 if (*p
== '\0' || *p
== ',')
2206 op_alt
[j
].anything_ok
= 1;
2216 while (c
!= ',' && c
!= '\0');
2217 if (c
== ',' || c
== '\0')
2225 case '=': case '+': case '*': case '%':
2226 case 'E': case 'F': case 'G': case 'H':
2227 case 's': case 'i': case 'n':
2228 case 'I': case 'J': case 'K': case 'L':
2229 case 'M': case 'N': case 'O': case 'P':
2230 /* These don't say anything we care about. */
2234 op_alt
[j
].reject
+= 6;
2237 op_alt
[j
].reject
+= 600;
2240 op_alt
[j
].earlyclobber
= 1;
2243 case '0': case '1': case '2': case '3': case '4':
2244 case '5': case '6': case '7': case '8': case '9':
2247 op_alt
[j
].matches
= strtoul (p
, &end
, 10);
2248 recog_op_alt
[op_alt
[j
].matches
][j
].matched
= i
;
2253 case TARGET_MEM_CONSTRAINT
:
2254 op_alt
[j
].memory_ok
= 1;
2257 op_alt
[j
].decmem_ok
= 1;
2260 op_alt
[j
].incmem_ok
= 1;
2263 op_alt
[j
].nonoffmem_ok
= 1;
2266 op_alt
[j
].offmem_ok
= 1;
2269 op_alt
[j
].anything_ok
= 1;
2273 op_alt
[j
].is_address
= 1;
2274 op_alt
[j
].cl
= reg_class_subunion
[(int) op_alt
[j
].cl
]
2275 [(int) base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
2282 reg_class_subunion
[(int) op_alt
[j
].cl
][(int) GENERAL_REGS
];
2286 if (EXTRA_MEMORY_CONSTRAINT (c
, p
))
2288 op_alt
[j
].memory_ok
= 1;
2291 if (EXTRA_ADDRESS_CONSTRAINT (c
, p
))
2293 op_alt
[j
].is_address
= 1;
2295 = (reg_class_subunion
2296 [(int) op_alt
[j
].cl
]
2297 [(int) base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
2298 ADDRESS
, SCRATCH
)]);
2303 = (reg_class_subunion
2304 [(int) op_alt
[j
].cl
]
2305 [(int) REG_CLASS_FROM_CONSTRAINT ((unsigned char) c
, p
)]);
2308 p
+= CONSTRAINT_LEN (c
, p
);
2314 /* Check the operands of an insn against the insn's operand constraints
2315 and return 1 if they are valid.
2316 The information about the insn's operands, constraints, operand modes
2317 etc. is obtained from the global variables set up by extract_insn.
2319 WHICH_ALTERNATIVE is set to a number which indicates which
2320 alternative of constraints was matched: 0 for the first alternative,
2321 1 for the next, etc.
2323 In addition, when two operands are required to match
2324 and it happens that the output operand is (reg) while the
2325 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2326 make the output operand look like the input.
2327 This is because the output operand is the one the template will print.
2329 This is used in final, just before printing the assembler code and by
2330 the routines that determine an insn's attribute.
2332 If STRICT is a positive nonzero value, it means that we have been
2333 called after reload has been completed. In that case, we must
2334 do all checks strictly. If it is zero, it means that we have been called
2335 before reload has completed. In that case, we first try to see if we can
2336 find an alternative that matches strictly. If not, we try again, this
2337 time assuming that reload will fix up the insn. This provides a "best
2338 guess" for the alternative and is used to compute attributes of insns prior
2339 to reload. A negative value of STRICT is used for this internal call. */
2347 constrain_operands (int strict
)
2349 const char *constraints
[MAX_RECOG_OPERANDS
];
2350 int matching_operands
[MAX_RECOG_OPERANDS
];
2351 int earlyclobber
[MAX_RECOG_OPERANDS
];
2354 struct funny_match funny_match
[MAX_RECOG_OPERANDS
];
2355 int funny_match_index
;
2357 which_alternative
= 0;
2358 if (recog_data
.n_operands
== 0 || recog_data
.n_alternatives
== 0)
2361 for (c
= 0; c
< recog_data
.n_operands
; c
++)
2363 constraints
[c
] = recog_data
.constraints
[c
];
2364 matching_operands
[c
] = -1;
2369 int seen_earlyclobber_at
= -1;
2372 funny_match_index
= 0;
2374 if (!recog_data
.alternative_enabled_p
[which_alternative
])
2378 for (i
= 0; i
< recog_data
.n_operands
; i
++)
2379 constraints
[i
] = skip_alternative (constraints
[i
]);
2381 which_alternative
++;
2385 for (opno
= 0; opno
< recog_data
.n_operands
; opno
++)
2387 rtx op
= recog_data
.operand
[opno
];
2388 enum machine_mode mode
= GET_MODE (op
);
2389 const char *p
= constraints
[opno
];
2395 earlyclobber
[opno
] = 0;
2397 /* A unary operator may be accepted by the predicate, but it
2398 is irrelevant for matching constraints. */
2402 if (GET_CODE (op
) == SUBREG
)
2404 if (REG_P (SUBREG_REG (op
))
2405 && REGNO (SUBREG_REG (op
)) < FIRST_PSEUDO_REGISTER
)
2406 offset
= subreg_regno_offset (REGNO (SUBREG_REG (op
)),
2407 GET_MODE (SUBREG_REG (op
)),
2410 op
= SUBREG_REG (op
);
2413 /* An empty constraint or empty alternative
2414 allows anything which matched the pattern. */
2415 if (*p
== 0 || *p
== ',')
2419 switch (c
= *p
, len
= CONSTRAINT_LEN (c
, p
), c
)
2428 case '?': case '!': case '*': case '%':
2433 /* Ignore rest of this alternative as far as
2434 constraint checking is concerned. */
2437 while (*p
&& *p
!= ',');
2442 earlyclobber
[opno
] = 1;
2443 if (seen_earlyclobber_at
< 0)
2444 seen_earlyclobber_at
= opno
;
2447 case '0': case '1': case '2': case '3': case '4':
2448 case '5': case '6': case '7': case '8': case '9':
2450 /* This operand must be the same as a previous one.
2451 This kind of constraint is used for instructions such
2452 as add when they take only two operands.
2454 Note that the lower-numbered operand is passed first.
2456 If we are not testing strictly, assume that this
2457 constraint will be satisfied. */
2462 match
= strtoul (p
, &end
, 10);
2469 rtx op1
= recog_data
.operand
[match
];
2470 rtx op2
= recog_data
.operand
[opno
];
2472 /* A unary operator may be accepted by the predicate,
2473 but it is irrelevant for matching constraints. */
2475 op1
= XEXP (op1
, 0);
2477 op2
= XEXP (op2
, 0);
2479 val
= operands_match_p (op1
, op2
);
2482 matching_operands
[opno
] = match
;
2483 matching_operands
[match
] = opno
;
2488 /* If output is *x and input is *--x, arrange later
2489 to change the output to *--x as well, since the
2490 output op is the one that will be printed. */
2491 if (val
== 2 && strict
> 0)
2493 funny_match
[funny_match_index
].this_op
= opno
;
2494 funny_match
[funny_match_index
++].other
= match
;
2501 /* p is used for address_operands. When we are called by
2502 gen_reload, no one will have checked that the address is
2503 strictly valid, i.e., that all pseudos requiring hard regs
2504 have gotten them. */
2506 || (strict_memory_address_p (recog_data
.operand_mode
[opno
],
2511 /* No need to check general_operand again;
2512 it was done in insn-recog.c. Well, except that reload
2513 doesn't check the validity of its replacements, but
2514 that should only matter when there's a bug. */
2516 /* Anything goes unless it is a REG and really has a hard reg
2517 but the hard reg is not in the class GENERAL_REGS. */
2521 || GENERAL_REGS
== ALL_REGS
2522 || (reload_in_progress
2523 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
)
2524 || reg_fits_class_p (op
, GENERAL_REGS
, offset
, mode
))
2527 else if (strict
< 0 || general_operand (op
, mode
))
2532 /* This is used for a MATCH_SCRATCH in the cases when
2533 we don't actually need anything. So anything goes
2538 case TARGET_MEM_CONSTRAINT
:
2539 /* Memory operands must be valid, to the extent
2540 required by STRICT. */
2544 && !strict_memory_address_addr_space_p
2545 (GET_MODE (op
), XEXP (op
, 0),
2546 MEM_ADDR_SPACE (op
)))
2549 && !memory_address_addr_space_p
2550 (GET_MODE (op
), XEXP (op
, 0),
2551 MEM_ADDR_SPACE (op
)))
2555 /* Before reload, accept what reload can turn into mem. */
2556 else if (strict
< 0 && CONSTANT_P (op
))
2558 /* During reload, accept a pseudo */
2559 else if (reload_in_progress
&& REG_P (op
)
2560 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
)
2566 && (GET_CODE (XEXP (op
, 0)) == PRE_DEC
2567 || GET_CODE (XEXP (op
, 0)) == POST_DEC
))
2573 && (GET_CODE (XEXP (op
, 0)) == PRE_INC
2574 || GET_CODE (XEXP (op
, 0)) == POST_INC
))
2580 if (CONST_DOUBLE_AS_FLOAT_P (op
)
2581 || (GET_CODE (op
) == CONST_VECTOR
2582 && GET_MODE_CLASS (GET_MODE (op
)) == MODE_VECTOR_FLOAT
))
2588 if (CONST_DOUBLE_AS_FLOAT_P (op
)
2589 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, c
, p
))
2594 if (CONST_INT_P (op
) || CONST_DOUBLE_AS_INT_P (op
))
2597 if (CONSTANT_P (op
))
2602 if (CONST_INT_P (op
) || CONST_DOUBLE_AS_INT_P (op
))
2614 if (CONST_INT_P (op
)
2615 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), c
, p
))
2621 && ((strict
> 0 && ! offsettable_memref_p (op
))
2623 && !(CONSTANT_P (op
) || MEM_P (op
)))
2624 || (reload_in_progress
2626 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
))))
2631 if ((strict
> 0 && offsettable_memref_p (op
))
2632 || (strict
== 0 && offsettable_nonstrict_memref_p (op
))
2633 /* Before reload, accept what reload can handle. */
2635 && (CONSTANT_P (op
) || MEM_P (op
)))
2636 /* During reload, accept a pseudo */
2637 || (reload_in_progress
&& REG_P (op
)
2638 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
))
2647 ? GENERAL_REGS
: REG_CLASS_FROM_CONSTRAINT (c
, p
));
2653 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
)
2654 || (strict
== 0 && GET_CODE (op
) == SCRATCH
)
2656 && reg_fits_class_p (op
, cl
, offset
, mode
)))
2659 #ifdef EXTRA_CONSTRAINT_STR
2660 else if (EXTRA_CONSTRAINT_STR (op
, c
, p
))
2663 else if (EXTRA_MEMORY_CONSTRAINT (c
, p
)
2664 /* Every memory operand can be reloaded to fit. */
2665 && ((strict
< 0 && MEM_P (op
))
2666 /* Before reload, accept what reload can turn
2668 || (strict
< 0 && CONSTANT_P (op
))
2669 /* During reload, accept a pseudo */
2670 || (reload_in_progress
&& REG_P (op
)
2671 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
)))
2673 else if (EXTRA_ADDRESS_CONSTRAINT (c
, p
)
2674 /* Every address operand can be reloaded to fit. */
2677 /* Cater to architectures like IA-64 that define extra memory
2678 constraints without using define_memory_constraint. */
2679 else if (reload_in_progress
2681 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
2682 && reg_renumber
[REGNO (op
)] < 0
2683 && reg_equiv_mem (REGNO (op
)) != 0
2684 && EXTRA_CONSTRAINT_STR
2685 (reg_equiv_mem (REGNO (op
)), c
, p
))
2691 while (p
+= len
, c
);
2693 constraints
[opno
] = p
;
2694 /* If this operand did not win somehow,
2695 this alternative loses. */
2699 /* This alternative won; the operands are ok.
2700 Change whichever operands this alternative says to change. */
2705 /* See if any earlyclobber operand conflicts with some other
2708 if (strict
> 0 && seen_earlyclobber_at
>= 0)
2709 for (eopno
= seen_earlyclobber_at
;
2710 eopno
< recog_data
.n_operands
;
2712 /* Ignore earlyclobber operands now in memory,
2713 because we would often report failure when we have
2714 two memory operands, one of which was formerly a REG. */
2715 if (earlyclobber
[eopno
]
2716 && REG_P (recog_data
.operand
[eopno
]))
2717 for (opno
= 0; opno
< recog_data
.n_operands
; opno
++)
2718 if ((MEM_P (recog_data
.operand
[opno
])
2719 || recog_data
.operand_type
[opno
] != OP_OUT
)
2721 /* Ignore things like match_operator operands. */
2722 && *recog_data
.constraints
[opno
] != 0
2723 && ! (matching_operands
[opno
] == eopno
2724 && operands_match_p (recog_data
.operand
[opno
],
2725 recog_data
.operand
[eopno
]))
2726 && ! safe_from_earlyclobber (recog_data
.operand
[opno
],
2727 recog_data
.operand
[eopno
]))
2732 while (--funny_match_index
>= 0)
2734 recog_data
.operand
[funny_match
[funny_match_index
].other
]
2735 = recog_data
.operand
[funny_match
[funny_match_index
].this_op
];
2739 /* For operands without < or > constraints reject side-effects. */
2740 if (recog_data
.is_asm
)
2742 for (opno
= 0; opno
< recog_data
.n_operands
; opno
++)
2743 if (MEM_P (recog_data
.operand
[opno
]))
2744 switch (GET_CODE (XEXP (recog_data
.operand
[opno
], 0)))
2752 if (strchr (recog_data
.constraints
[opno
], '<') == NULL
2753 && strchr (recog_data
.constraints
[opno
], '>')
2766 which_alternative
++;
2768 while (which_alternative
< recog_data
.n_alternatives
);
2770 which_alternative
= -1;
2771 /* If we are about to reject this, but we are not to test strictly,
2772 try a very loose test. Only return failure if it fails also. */
2774 return constrain_operands (-1);
2779 /* Return true iff OPERAND (assumed to be a REG rtx)
2780 is a hard reg in class CLASS when its regno is offset by OFFSET
2781 and changed to mode MODE.
2782 If REG occupies multiple hard regs, all of them must be in CLASS. */
2785 reg_fits_class_p (const_rtx operand
, reg_class_t cl
, int offset
,
2786 enum machine_mode mode
)
2788 unsigned int regno
= REGNO (operand
);
2793 /* Regno must not be a pseudo register. Offset may be negative. */
2794 return (HARD_REGISTER_NUM_P (regno
)
2795 && HARD_REGISTER_NUM_P (regno
+ offset
)
2796 && in_hard_reg_set_p (reg_class_contents
[(int) cl
], mode
,
2800 /* Split single instruction. Helper function for split_all_insns and
2801 split_all_insns_noflow. Return last insn in the sequence if successful,
2802 or NULL if unsuccessful. */
2805 split_insn (rtx insn
)
2807 /* Split insns here to get max fine-grain parallelism. */
2808 rtx first
= PREV_INSN (insn
);
2809 rtx last
= try_split (PATTERN (insn
), insn
, 1);
2810 rtx insn_set
, last_set
, note
;
2815 /* If the original instruction was a single set that was known to be
2816 equivalent to a constant, see if we can say the same about the last
2817 instruction in the split sequence. The two instructions must set
2818 the same destination. */
2819 insn_set
= single_set (insn
);
2822 last_set
= single_set (last
);
2823 if (last_set
&& rtx_equal_p (SET_DEST (last_set
), SET_DEST (insn_set
)))
2825 note
= find_reg_equal_equiv_note (insn
);
2826 if (note
&& CONSTANT_P (XEXP (note
, 0)))
2827 set_unique_reg_note (last
, REG_EQUAL
, XEXP (note
, 0));
2828 else if (CONSTANT_P (SET_SRC (insn_set
)))
2829 set_unique_reg_note (last
, REG_EQUAL
,
2830 copy_rtx (SET_SRC (insn_set
)));
2834 /* try_split returns the NOTE that INSN became. */
2835 SET_INSN_DELETED (insn
);
2837 /* ??? Coddle to md files that generate subregs in post-reload
2838 splitters instead of computing the proper hard register. */
2839 if (reload_completed
&& first
!= last
)
2841 first
= NEXT_INSN (first
);
2845 cleanup_subreg_operands (first
);
2848 first
= NEXT_INSN (first
);
2855 /* Split all insns in the function. If UPD_LIFE, update life info after. */
2858 split_all_insns (void)
2864 blocks
= sbitmap_alloc (last_basic_block
);
2865 sbitmap_zero (blocks
);
2868 FOR_EACH_BB_REVERSE (bb
)
2871 bool finish
= false;
2873 rtl_profile_for_bb (bb
);
2874 for (insn
= BB_HEAD (bb
); !finish
; insn
= next
)
2876 /* Can't use `next_real_insn' because that might go across
2877 CODE_LABELS and short-out basic blocks. */
2878 next
= NEXT_INSN (insn
);
2879 finish
= (insn
== BB_END (bb
));
2882 rtx set
= single_set (insn
);
2884 /* Don't split no-op move insns. These should silently
2885 disappear later in final. Splitting such insns would
2886 break the code that handles LIBCALL blocks. */
2887 if (set
&& set_noop_p (set
))
2889 /* Nops get in the way while scheduling, so delete them
2890 now if register allocation has already been done. It
2891 is too risky to try to do this before register
2892 allocation, and there are unlikely to be very many
2893 nops then anyways. */
2894 if (reload_completed
)
2895 delete_insn_and_edges (insn
);
2899 if (split_insn (insn
))
2901 SET_BIT (blocks
, bb
->index
);
2909 default_rtl_profile ();
2911 find_many_sub_basic_blocks (blocks
);
2913 #ifdef ENABLE_CHECKING
2914 verify_flow_info ();
2917 sbitmap_free (blocks
);
2920 /* Same as split_all_insns, but do not expect CFG to be available.
2921 Used by machine dependent reorg passes. */
2924 split_all_insns_noflow (void)
2928 for (insn
= get_insns (); insn
; insn
= next
)
2930 next
= NEXT_INSN (insn
);
2933 /* Don't split no-op move insns. These should silently
2934 disappear later in final. Splitting such insns would
2935 break the code that handles LIBCALL blocks. */
2936 rtx set
= single_set (insn
);
2937 if (set
&& set_noop_p (set
))
2939 /* Nops get in the way while scheduling, so delete them
2940 now if register allocation has already been done. It
2941 is too risky to try to do this before register
2942 allocation, and there are unlikely to be very many
2945 ??? Should we use delete_insn when the CFG isn't valid? */
2946 if (reload_completed
)
2947 delete_insn_and_edges (insn
);
2956 #ifdef HAVE_peephole2
2957 struct peep2_insn_data
2963 static struct peep2_insn_data peep2_insn_data
[MAX_INSNS_PER_PEEP2
+ 1];
2964 static int peep2_current
;
2966 static bool peep2_do_rebuild_jump_labels
;
2967 static bool peep2_do_cleanup_cfg
;
2969 /* The number of instructions available to match a peep2. */
2970 int peep2_current_count
;
2972 /* A non-insn marker indicating the last insn of the block.
2973 The live_before regset for this element is correct, indicating
2974 DF_LIVE_OUT for the block. */
2975 #define PEEP2_EOB pc_rtx
2977 /* Wrap N to fit into the peep2_insn_data buffer. */
2980 peep2_buf_position (int n
)
2982 if (n
>= MAX_INSNS_PER_PEEP2
+ 1)
2983 n
-= MAX_INSNS_PER_PEEP2
+ 1;
2987 /* Return the Nth non-note insn after `current', or return NULL_RTX if it
2988 does not exist. Used by the recognizer to find the next insn to match
2989 in a multi-insn pattern. */
2992 peep2_next_insn (int n
)
2994 gcc_assert (n
<= peep2_current_count
);
2996 n
= peep2_buf_position (peep2_current
+ n
);
2998 return peep2_insn_data
[n
].insn
;
3001 /* Return true if REGNO is dead before the Nth non-note insn
3005 peep2_regno_dead_p (int ofs
, int regno
)
3007 gcc_assert (ofs
< MAX_INSNS_PER_PEEP2
+ 1);
3009 ofs
= peep2_buf_position (peep2_current
+ ofs
);
3011 gcc_assert (peep2_insn_data
[ofs
].insn
!= NULL_RTX
);
3013 return ! REGNO_REG_SET_P (peep2_insn_data
[ofs
].live_before
, regno
);
3016 /* Similarly for a REG. */
3019 peep2_reg_dead_p (int ofs
, rtx reg
)
3023 gcc_assert (ofs
< MAX_INSNS_PER_PEEP2
+ 1);
3025 ofs
= peep2_buf_position (peep2_current
+ ofs
);
3027 gcc_assert (peep2_insn_data
[ofs
].insn
!= NULL_RTX
);
3029 regno
= REGNO (reg
);
3030 n
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
3032 if (REGNO_REG_SET_P (peep2_insn_data
[ofs
].live_before
, regno
+ n
))
3037 /* Try to find a hard register of mode MODE, matching the register class in
3038 CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
3039 remains available until the end of LAST_INSN. LAST_INSN may be NULL_RTX,
3040 in which case the only condition is that the register must be available
3041 before CURRENT_INSN.
3042 Registers that already have bits set in REG_SET will not be considered.
3044 If an appropriate register is available, it will be returned and the
3045 corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
3049 peep2_find_free_register (int from
, int to
, const char *class_str
,
3050 enum machine_mode mode
, HARD_REG_SET
*reg_set
)
3052 static int search_ofs
;
3058 gcc_assert (from
< MAX_INSNS_PER_PEEP2
+ 1);
3059 gcc_assert (to
< MAX_INSNS_PER_PEEP2
+ 1);
3061 from
= peep2_buf_position (peep2_current
+ from
);
3062 to
= peep2_buf_position (peep2_current
+ to
);
3064 gcc_assert (peep2_insn_data
[from
].insn
!= NULL_RTX
);
3065 REG_SET_TO_HARD_REG_SET (live
, peep2_insn_data
[from
].live_before
);
3069 gcc_assert (peep2_insn_data
[from
].insn
!= NULL_RTX
);
3071 /* Don't use registers set or clobbered by the insn. */
3072 for (def_rec
= DF_INSN_DEFS (peep2_insn_data
[from
].insn
);
3073 *def_rec
; def_rec
++)
3074 SET_HARD_REG_BIT (live
, DF_REF_REGNO (*def_rec
));
3076 from
= peep2_buf_position (from
+ 1);
3079 cl
= (class_str
[0] == 'r' ? GENERAL_REGS
3080 : REG_CLASS_FROM_CONSTRAINT (class_str
[0], class_str
));
3082 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3084 int raw_regno
, regno
, success
, j
;
3086 /* Distribute the free registers as much as possible. */
3087 raw_regno
= search_ofs
+ i
;
3088 if (raw_regno
>= FIRST_PSEUDO_REGISTER
)
3089 raw_regno
-= FIRST_PSEUDO_REGISTER
;
3090 #ifdef REG_ALLOC_ORDER
3091 regno
= reg_alloc_order
[raw_regno
];
3096 /* Don't allocate fixed registers. */
3097 if (fixed_regs
[regno
])
3099 /* Don't allocate global registers. */
3100 if (global_regs
[regno
])
3102 /* Make sure the register is of the right class. */
3103 if (! TEST_HARD_REG_BIT (reg_class_contents
[cl
], regno
))
3105 /* And can support the mode we need. */
3106 if (! HARD_REGNO_MODE_OK (regno
, mode
))
3108 /* And that we don't create an extra save/restore. */
3109 if (! call_used_regs
[regno
] && ! df_regs_ever_live_p (regno
))
3111 if (! targetm
.hard_regno_scratch_ok (regno
))
3114 /* And we don't clobber traceback for noreturn functions. */
3115 if ((regno
== FRAME_POINTER_REGNUM
|| regno
== HARD_FRAME_POINTER_REGNUM
)
3116 && (! reload_completed
|| frame_pointer_needed
))
3120 for (j
= hard_regno_nregs
[regno
][mode
] - 1; j
>= 0; j
--)
3122 if (TEST_HARD_REG_BIT (*reg_set
, regno
+ j
)
3123 || TEST_HARD_REG_BIT (live
, regno
+ j
))
3131 add_to_hard_reg_set (reg_set
, mode
, regno
);
3133 /* Start the next search with the next register. */
3134 if (++raw_regno
>= FIRST_PSEUDO_REGISTER
)
3136 search_ofs
= raw_regno
;
3138 return gen_rtx_REG (mode
, regno
);
3146 /* Forget all currently tracked instructions, only remember current
3150 peep2_reinit_state (regset live
)
3154 /* Indicate that all slots except the last holds invalid data. */
3155 for (i
= 0; i
< MAX_INSNS_PER_PEEP2
; ++i
)
3156 peep2_insn_data
[i
].insn
= NULL_RTX
;
3157 peep2_current_count
= 0;
3159 /* Indicate that the last slot contains live_after data. */
3160 peep2_insn_data
[MAX_INSNS_PER_PEEP2
].insn
= PEEP2_EOB
;
3161 peep2_current
= MAX_INSNS_PER_PEEP2
;
3163 COPY_REG_SET (peep2_insn_data
[MAX_INSNS_PER_PEEP2
].live_before
, live
);
3166 /* While scanning basic block BB, we found a match of length MATCH_LEN,
3167 starting at INSN. Perform the replacement, removing the old insns and
3168 replacing them with ATTEMPT. Returns the last insn emitted, or NULL
3169 if the replacement is rejected. */
3172 peep2_attempt (basic_block bb
, rtx insn
, int match_len
, rtx attempt
)
3175 rtx last
, eh_note
, as_note
, before_try
, x
;
3176 rtx old_insn
, new_insn
;
3177 bool was_call
= false;
3179 /* If we are splitting an RTX_FRAME_RELATED_P insn, do not allow it to
3180 match more than one insn, or to be split into more than one insn. */
3181 old_insn
= peep2_insn_data
[peep2_current
].insn
;
3182 if (RTX_FRAME_RELATED_P (old_insn
))
3184 bool any_note
= false;
3190 /* Look for one "active" insn. I.e. ignore any "clobber" insns that
3191 may be in the stream for the purpose of register allocation. */
3192 if (active_insn_p (attempt
))
3195 new_insn
= next_active_insn (attempt
);
3196 if (next_active_insn (new_insn
))
3199 /* We have a 1-1 replacement. Copy over any frame-related info. */
3200 RTX_FRAME_RELATED_P (new_insn
) = 1;
3202 /* Allow the backend to fill in a note during the split. */
3203 for (note
= REG_NOTES (new_insn
); note
; note
= XEXP (note
, 1))
3204 switch (REG_NOTE_KIND (note
))
3206 case REG_FRAME_RELATED_EXPR
:
3207 case REG_CFA_DEF_CFA
:
3208 case REG_CFA_ADJUST_CFA
:
3209 case REG_CFA_OFFSET
:
3210 case REG_CFA_REGISTER
:
3211 case REG_CFA_EXPRESSION
:
3212 case REG_CFA_RESTORE
:
3213 case REG_CFA_SET_VDRAP
:
3220 /* If the backend didn't supply a note, copy one over. */
3222 for (note
= REG_NOTES (old_insn
); note
; note
= XEXP (note
, 1))
3223 switch (REG_NOTE_KIND (note
))
3225 case REG_FRAME_RELATED_EXPR
:
3226 case REG_CFA_DEF_CFA
:
3227 case REG_CFA_ADJUST_CFA
:
3228 case REG_CFA_OFFSET
:
3229 case REG_CFA_REGISTER
:
3230 case REG_CFA_EXPRESSION
:
3231 case REG_CFA_RESTORE
:
3232 case REG_CFA_SET_VDRAP
:
3233 add_reg_note (new_insn
, REG_NOTE_KIND (note
), XEXP (note
, 0));
3240 /* If there still isn't a note, make sure the unwind info sees the
3241 same expression as before the split. */
3244 rtx old_set
, new_set
;
3246 /* The old insn had better have been simple, or annotated. */
3247 old_set
= single_set (old_insn
);
3248 gcc_assert (old_set
!= NULL
);
3250 new_set
= single_set (new_insn
);
3251 if (!new_set
|| !rtx_equal_p (new_set
, old_set
))
3252 add_reg_note (new_insn
, REG_FRAME_RELATED_EXPR
, old_set
);
3255 /* Copy prologue/epilogue status. This is required in order to keep
3256 proper placement of EPILOGUE_BEG and the DW_CFA_remember_state. */
3257 maybe_copy_prologue_epilogue_insn (old_insn
, new_insn
);
3260 /* If we are splitting a CALL_INSN, look for the CALL_INSN
3261 in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
3262 cfg-related call notes. */
3263 for (i
= 0; i
<= match_len
; ++i
)
3268 j
= peep2_buf_position (peep2_current
+ i
);
3269 old_insn
= peep2_insn_data
[j
].insn
;
3270 if (!CALL_P (old_insn
))
3275 while (new_insn
!= NULL_RTX
)
3277 if (CALL_P (new_insn
))
3279 new_insn
= NEXT_INSN (new_insn
);
3282 gcc_assert (new_insn
!= NULL_RTX
);
3284 CALL_INSN_FUNCTION_USAGE (new_insn
)
3285 = CALL_INSN_FUNCTION_USAGE (old_insn
);
3287 for (note
= REG_NOTES (old_insn
);
3289 note
= XEXP (note
, 1))
3290 switch (REG_NOTE_KIND (note
))
3295 add_reg_note (new_insn
, REG_NOTE_KIND (note
),
3299 /* Discard all other reg notes. */
3303 /* Croak if there is another call in the sequence. */
3304 while (++i
<= match_len
)
3306 j
= peep2_buf_position (peep2_current
+ i
);
3307 old_insn
= peep2_insn_data
[j
].insn
;
3308 gcc_assert (!CALL_P (old_insn
));
3313 /* If we matched any instruction that had a REG_ARGS_SIZE, then
3314 move those notes over to the new sequence. */
3316 for (i
= match_len
; i
>= 0; --i
)
3318 int j
= peep2_buf_position (peep2_current
+ i
);
3319 old_insn
= peep2_insn_data
[j
].insn
;
3321 as_note
= find_reg_note (old_insn
, REG_ARGS_SIZE
, NULL
);
3326 i
= peep2_buf_position (peep2_current
+ match_len
);
3327 eh_note
= find_reg_note (peep2_insn_data
[i
].insn
, REG_EH_REGION
, NULL_RTX
);
3329 /* Replace the old sequence with the new. */
3330 last
= emit_insn_after_setloc (attempt
,
3331 peep2_insn_data
[i
].insn
,
3332 INSN_LOCATION (peep2_insn_data
[i
].insn
));
3333 before_try
= PREV_INSN (insn
);
3334 delete_insn_chain (insn
, peep2_insn_data
[i
].insn
, false);
3336 /* Re-insert the EH_REGION notes. */
3337 if (eh_note
|| (was_call
&& nonlocal_goto_handler_labels
))
3342 FOR_EACH_EDGE (eh_edge
, ei
, bb
->succs
)
3343 if (eh_edge
->flags
& (EDGE_EH
| EDGE_ABNORMAL_CALL
))
3347 copy_reg_eh_region_note_backward (eh_note
, last
, before_try
);
3350 for (x
= last
; x
!= before_try
; x
= PREV_INSN (x
))
3351 if (x
!= BB_END (bb
)
3352 && (can_throw_internal (x
)
3353 || can_nonlocal_goto (x
)))
3358 nfte
= split_block (bb
, x
);
3359 flags
= (eh_edge
->flags
3360 & (EDGE_EH
| EDGE_ABNORMAL
));
3362 flags
|= EDGE_ABNORMAL_CALL
;
3363 nehe
= make_edge (nfte
->src
, eh_edge
->dest
,
3366 nehe
->probability
= eh_edge
->probability
;
3368 = REG_BR_PROB_BASE
- nehe
->probability
;
3370 peep2_do_cleanup_cfg
|= purge_dead_edges (nfte
->dest
);
3375 /* Converting possibly trapping insn to non-trapping is
3376 possible. Zap dummy outgoing edges. */
3377 peep2_do_cleanup_cfg
|= purge_dead_edges (bb
);
3380 /* Re-insert the ARGS_SIZE notes. */
3382 fixup_args_size_notes (before_try
, last
, INTVAL (XEXP (as_note
, 0)));
3384 /* If we generated a jump instruction, it won't have
3385 JUMP_LABEL set. Recompute after we're done. */
3386 for (x
= last
; x
!= before_try
; x
= PREV_INSN (x
))
3389 peep2_do_rebuild_jump_labels
= true;
3396 /* After performing a replacement in basic block BB, fix up the life
3397 information in our buffer. LAST is the last of the insns that we
3398 emitted as a replacement. PREV is the insn before the start of
3399 the replacement. MATCH_LEN is the number of instructions that were
3400 matched, and which now need to be replaced in the buffer. */
3403 peep2_update_life (basic_block bb
, int match_len
, rtx last
, rtx prev
)
3405 int i
= peep2_buf_position (peep2_current
+ match_len
+ 1);
3409 INIT_REG_SET (&live
);
3410 COPY_REG_SET (&live
, peep2_insn_data
[i
].live_before
);
3412 gcc_assert (peep2_current_count
>= match_len
+ 1);
3413 peep2_current_count
-= match_len
+ 1;
3421 if (peep2_current_count
< MAX_INSNS_PER_PEEP2
)
3423 peep2_current_count
++;
3425 i
= MAX_INSNS_PER_PEEP2
;
3426 peep2_insn_data
[i
].insn
= x
;
3427 df_simulate_one_insn_backwards (bb
, x
, &live
);
3428 COPY_REG_SET (peep2_insn_data
[i
].live_before
, &live
);
3434 CLEAR_REG_SET (&live
);
3439 /* Add INSN, which is in BB, at the end of the peep2 insn buffer if possible.
3440 Return true if we added it, false otherwise. The caller will try to match
3441 peepholes against the buffer if we return false; otherwise it will try to
3442 add more instructions to the buffer. */
3445 peep2_fill_buffer (basic_block bb
, rtx insn
, regset live
)
3449 /* Once we have filled the maximum number of insns the buffer can hold,
3450 allow the caller to match the insns against peepholes. We wait until
3451 the buffer is full in case the target has similar peepholes of different
3452 length; we always want to match the longest if possible. */
3453 if (peep2_current_count
== MAX_INSNS_PER_PEEP2
)
3456 /* If an insn has RTX_FRAME_RELATED_P set, do not allow it to be matched with
3457 any other pattern, lest it change the semantics of the frame info. */
3458 if (RTX_FRAME_RELATED_P (insn
))
3460 /* Let the buffer drain first. */
3461 if (peep2_current_count
> 0)
3463 /* Now the insn will be the only thing in the buffer. */
3466 pos
= peep2_buf_position (peep2_current
+ peep2_current_count
);
3467 peep2_insn_data
[pos
].insn
= insn
;
3468 COPY_REG_SET (peep2_insn_data
[pos
].live_before
, live
);
3469 peep2_current_count
++;
3471 df_simulate_one_insn_forwards (bb
, insn
, live
);
3475 /* Perform the peephole2 optimization pass. */
3478 peephole2_optimize (void)
3485 peep2_do_cleanup_cfg
= false;
3486 peep2_do_rebuild_jump_labels
= false;
3488 df_set_flags (DF_LR_RUN_DCE
);
3489 df_note_add_problem ();
3492 /* Initialize the regsets we're going to use. */
3493 for (i
= 0; i
< MAX_INSNS_PER_PEEP2
+ 1; ++i
)
3494 peep2_insn_data
[i
].live_before
= BITMAP_ALLOC (®_obstack
);
3495 live
= BITMAP_ALLOC (®_obstack
);
3497 FOR_EACH_BB_REVERSE (bb
)
3499 bool past_end
= false;
3502 rtl_profile_for_bb (bb
);
3504 /* Start up propagation. */
3505 bitmap_copy (live
, DF_LR_IN (bb
));
3506 df_simulate_initialize_forwards (bb
, live
);
3507 peep2_reinit_state (live
);
3509 insn
= BB_HEAD (bb
);
3515 if (!past_end
&& !NONDEBUG_INSN_P (insn
))
3518 insn
= NEXT_INSN (insn
);
3519 if (insn
== NEXT_INSN (BB_END (bb
)))
3523 if (!past_end
&& peep2_fill_buffer (bb
, insn
, live
))
3526 /* If we did not fill an empty buffer, it signals the end of the
3528 if (peep2_current_count
== 0)
3531 /* The buffer filled to the current maximum, so try to match. */
3533 pos
= peep2_buf_position (peep2_current
+ peep2_current_count
);
3534 peep2_insn_data
[pos
].insn
= PEEP2_EOB
;
3535 COPY_REG_SET (peep2_insn_data
[pos
].live_before
, live
);
3537 /* Match the peephole. */
3538 head
= peep2_insn_data
[peep2_current
].insn
;
3539 attempt
= peephole2_insns (PATTERN (head
), head
, &match_len
);
3540 if (attempt
!= NULL
)
3542 rtx last
= peep2_attempt (bb
, head
, match_len
, attempt
);
3545 peep2_update_life (bb
, match_len
, last
, PREV_INSN (attempt
));
3550 /* No match: advance the buffer by one insn. */
3551 peep2_current
= peep2_buf_position (peep2_current
+ 1);
3552 peep2_current_count
--;
3556 default_rtl_profile ();
3557 for (i
= 0; i
< MAX_INSNS_PER_PEEP2
+ 1; ++i
)
3558 BITMAP_FREE (peep2_insn_data
[i
].live_before
);
3560 if (peep2_do_rebuild_jump_labels
)
3561 rebuild_jump_labels (get_insns ());
3563 #endif /* HAVE_peephole2 */
3565 /* Common predicates for use with define_bypass. */
3567 /* True if the dependency between OUT_INSN and IN_INSN is on the store
3568 data not the address operand(s) of the store. IN_INSN and OUT_INSN
3569 must be either a single_set or a PARALLEL with SETs inside. */
3572 store_data_bypass_p (rtx out_insn
, rtx in_insn
)
3574 rtx out_set
, in_set
;
3575 rtx out_pat
, in_pat
;
3576 rtx out_exp
, in_exp
;
3579 in_set
= single_set (in_insn
);
3582 if (!MEM_P (SET_DEST (in_set
)))
3585 out_set
= single_set (out_insn
);
3588 if (reg_mentioned_p (SET_DEST (out_set
), SET_DEST (in_set
)))
3593 out_pat
= PATTERN (out_insn
);
3595 if (GET_CODE (out_pat
) != PARALLEL
)
3598 for (i
= 0; i
< XVECLEN (out_pat
, 0); i
++)
3600 out_exp
= XVECEXP (out_pat
, 0, i
);
3602 if (GET_CODE (out_exp
) == CLOBBER
)
3605 gcc_assert (GET_CODE (out_exp
) == SET
);
3607 if (reg_mentioned_p (SET_DEST (out_exp
), SET_DEST (in_set
)))
3614 in_pat
= PATTERN (in_insn
);
3615 gcc_assert (GET_CODE (in_pat
) == PARALLEL
);
3617 for (i
= 0; i
< XVECLEN (in_pat
, 0); i
++)
3619 in_exp
= XVECEXP (in_pat
, 0, i
);
3621 if (GET_CODE (in_exp
) == CLOBBER
)
3624 gcc_assert (GET_CODE (in_exp
) == SET
);
3626 if (!MEM_P (SET_DEST (in_exp
)))
3629 out_set
= single_set (out_insn
);
3632 if (reg_mentioned_p (SET_DEST (out_set
), SET_DEST (in_exp
)))
3637 out_pat
= PATTERN (out_insn
);
3638 gcc_assert (GET_CODE (out_pat
) == PARALLEL
);
3640 for (j
= 0; j
< XVECLEN (out_pat
, 0); j
++)
3642 out_exp
= XVECEXP (out_pat
, 0, j
);
3644 if (GET_CODE (out_exp
) == CLOBBER
)
3647 gcc_assert (GET_CODE (out_exp
) == SET
);
3649 if (reg_mentioned_p (SET_DEST (out_exp
), SET_DEST (in_exp
)))
3659 /* True if the dependency between OUT_INSN and IN_INSN is in the IF_THEN_ELSE
3660 condition, and not the THEN or ELSE branch. OUT_INSN may be either a single
3661 or multiple set; IN_INSN should be single_set for truth, but for convenience
3662 of insn categorization may be any JUMP or CALL insn. */
3665 if_test_bypass_p (rtx out_insn
, rtx in_insn
)
3667 rtx out_set
, in_set
;
3669 in_set
= single_set (in_insn
);
3672 gcc_assert (JUMP_P (in_insn
) || CALL_P (in_insn
));
3676 if (GET_CODE (SET_SRC (in_set
)) != IF_THEN_ELSE
)
3678 in_set
= SET_SRC (in_set
);
3680 out_set
= single_set (out_insn
);
3683 if (reg_mentioned_p (SET_DEST (out_set
), XEXP (in_set
, 1))
3684 || reg_mentioned_p (SET_DEST (out_set
), XEXP (in_set
, 2)))
3692 out_pat
= PATTERN (out_insn
);
3693 gcc_assert (GET_CODE (out_pat
) == PARALLEL
);
3695 for (i
= 0; i
< XVECLEN (out_pat
, 0); i
++)
3697 rtx exp
= XVECEXP (out_pat
, 0, i
);
3699 if (GET_CODE (exp
) == CLOBBER
)
3702 gcc_assert (GET_CODE (exp
) == SET
);
3704 if (reg_mentioned_p (SET_DEST (out_set
), XEXP (in_set
, 1))
3705 || reg_mentioned_p (SET_DEST (out_set
), XEXP (in_set
, 2)))
3714 gate_handle_peephole2 (void)
3716 return (optimize
> 0 && flag_peephole2
);
3720 rest_of_handle_peephole2 (void)
3722 #ifdef HAVE_peephole2
3723 peephole2_optimize ();
3728 struct rtl_opt_pass pass_peephole2
=
3732 "peephole2", /* name */
3733 gate_handle_peephole2
, /* gate */
3734 rest_of_handle_peephole2
, /* execute */
3737 0, /* static_pass_number */
3738 TV_PEEPHOLE2
, /* tv_id */
3739 0, /* properties_required */
3740 0, /* properties_provided */
3741 0, /* properties_destroyed */
3742 0, /* todo_flags_start */
3743 TODO_df_finish
| TODO_verify_rtl_sharing
|
3744 0 /* todo_flags_finish */
3749 rest_of_handle_split_all_insns (void)
3755 struct rtl_opt_pass pass_split_all_insns
=
3759 "split1", /* name */
3761 rest_of_handle_split_all_insns
, /* execute */
3764 0, /* static_pass_number */
3765 TV_NONE
, /* tv_id */
3766 0, /* properties_required */
3767 0, /* properties_provided */
3768 0, /* properties_destroyed */
3769 0, /* todo_flags_start */
3770 0 /* todo_flags_finish */
3775 rest_of_handle_split_after_reload (void)
3777 /* If optimizing, then go ahead and split insns now. */
3785 struct rtl_opt_pass pass_split_after_reload
=
3789 "split2", /* name */
3791 rest_of_handle_split_after_reload
, /* execute */
3794 0, /* static_pass_number */
3795 TV_NONE
, /* tv_id */
3796 0, /* properties_required */
3797 0, /* properties_provided */
3798 0, /* properties_destroyed */
3799 0, /* todo_flags_start */
3800 0 /* todo_flags_finish */
3805 gate_handle_split_before_regstack (void)
3807 #if defined (HAVE_ATTR_length) && defined (STACK_REGS)
3808 /* If flow2 creates new instructions which need splitting
3809 and scheduling after reload is not done, they might not be
3810 split until final which doesn't allow splitting
3811 if HAVE_ATTR_length. */
3812 # ifdef INSN_SCHEDULING
3813 return (optimize
&& !flag_schedule_insns_after_reload
);
3823 rest_of_handle_split_before_regstack (void)
3829 struct rtl_opt_pass pass_split_before_regstack
=
3833 "split3", /* name */
3834 gate_handle_split_before_regstack
, /* gate */
3835 rest_of_handle_split_before_regstack
, /* execute */
3838 0, /* static_pass_number */
3839 TV_NONE
, /* tv_id */
3840 0, /* properties_required */
3841 0, /* properties_provided */
3842 0, /* properties_destroyed */
3843 0, /* todo_flags_start */
3844 0 /* todo_flags_finish */
3849 gate_handle_split_before_sched2 (void)
3851 #ifdef INSN_SCHEDULING
3852 return optimize
> 0 && flag_schedule_insns_after_reload
;
3859 rest_of_handle_split_before_sched2 (void)
3861 #ifdef INSN_SCHEDULING
3867 struct rtl_opt_pass pass_split_before_sched2
=
3871 "split4", /* name */
3872 gate_handle_split_before_sched2
, /* gate */
3873 rest_of_handle_split_before_sched2
, /* execute */
3876 0, /* static_pass_number */
3877 TV_NONE
, /* tv_id */
3878 0, /* properties_required */
3879 0, /* properties_provided */
3880 0, /* properties_destroyed */
3881 0, /* todo_flags_start */
3882 TODO_verify_flow
/* todo_flags_finish */
3886 /* The placement of the splitting that we do for shorten_branches
3887 depends on whether regstack is used by the target or not. */
3889 gate_do_final_split (void)
3891 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3898 struct rtl_opt_pass pass_split_for_shorten_branches
=
3902 "split5", /* name */
3903 gate_do_final_split
, /* gate */
3904 split_all_insns_noflow
, /* execute */
3907 0, /* static_pass_number */
3908 TV_NONE
, /* tv_id */
3909 0, /* properties_required */
3910 0, /* properties_provided */
3911 0, /* properties_destroyed */
3912 0, /* todo_flags_start */
3913 TODO_verify_rtl_sharing
/* todo_flags_finish */