1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
27 static int rtx_addr_can_trap_p
PARAMS ((rtx
));
28 static void reg_set_p_1
PARAMS ((rtx
, rtx
, void *));
29 static void insn_dependent_p_1
PARAMS ((rtx
, rtx
, void *));
30 static void reg_set_last_1
PARAMS ((rtx
, rtx
, void *));
33 /* Forward declarations */
34 static int jmp_uses_reg_or_mem
PARAMS ((rtx
));
36 /* Bit flags that specify the machine subtype we are compiling for.
37 Bits are tested using macros TARGET_... defined in the tm.h file
38 and set by `-m...' switches. Must be defined in rtlanal.c. */
42 /* Return 1 if the value of X is unstable
43 (would be different at a different point in the program).
44 The frame pointer, arg pointer, etc. are considered stable
45 (within one function) and so is anything marked `unchanging'. */
51 register RTX_CODE code
= GET_CODE (x
);
53 register const char *fmt
;
56 return ! RTX_UNCHANGING_P (x
);
61 if (code
== CONST
|| code
== CONST_INT
)
65 return ! (REGNO (x
) == FRAME_POINTER_REGNUM
66 || REGNO (x
) == HARD_FRAME_POINTER_REGNUM
67 || REGNO (x
) == ARG_POINTER_REGNUM
68 || RTX_UNCHANGING_P (x
));
70 fmt
= GET_RTX_FORMAT (code
);
71 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
73 if (rtx_unstable_p (XEXP (x
, i
)))
78 /* Return 1 if X has a value that can vary even between two
79 executions of the program. 0 means X can be compared reliably
80 against certain constants or near-constants.
81 The frame pointer and the arg pointer are considered constant. */
87 register RTX_CODE code
= GET_CODE (x
);
89 register const char *fmt
;
105 /* Note that we have to test for the actual rtx used for the frame
106 and arg pointers and not just the register number in case we have
107 eliminated the frame and/or arg pointer and are using it
109 return ! (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
110 || x
== arg_pointer_rtx
|| x
== pic_offset_table_rtx
);
113 /* The operand 0 of a LO_SUM is considered constant
114 (in fact is it related specifically to operand 1). */
115 return rtx_varies_p (XEXP (x
, 1));
121 fmt
= GET_RTX_FORMAT (code
);
122 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
124 if (rtx_varies_p (XEXP (x
, i
)))
129 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
132 rtx_addr_can_trap_p (x
)
135 register enum rtx_code code
= GET_CODE (x
);
141 /* SYMBOL_REF is problematic due to the possible presence of
142 a #pragma weak, but to say that loads from symbols can trap is
143 *very* costly. It's not at all clear what's best here. For
144 now, we ignore the impact of #pragma weak. */
148 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
149 return ! (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
150 || x
== stack_pointer_rtx
|| x
== arg_pointer_rtx
);
153 return rtx_addr_can_trap_p (XEXP (x
, 0));
156 /* An address is assumed not to trap if it is an address that can't
157 trap plus a constant integer. */
158 return (rtx_addr_can_trap_p (XEXP (x
, 0))
159 || GET_CODE (XEXP (x
, 1)) != CONST_INT
);
162 return rtx_addr_can_trap_p (XEXP (x
, 1));
168 /* If it isn't one of the case above, it can cause a trap. */
172 /* Return 1 if X refers to a memory location whose address
173 cannot be compared reliably with constant addresses,
174 or if X refers to a BLKmode memory object. */
177 rtx_addr_varies_p (x
)
180 register enum rtx_code code
;
182 register const char *fmt
;
189 return GET_MODE (x
) == BLKmode
|| rtx_varies_p (XEXP (x
, 0));
191 fmt
= GET_RTX_FORMAT (code
);
192 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
195 if (rtx_addr_varies_p (XEXP (x
, i
)))
198 else if (fmt
[i
] == 'E')
201 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
202 if (rtx_addr_varies_p (XVECEXP (x
, i
, j
)))
208 /* Return the value of the integer term in X, if one is apparent;
210 Only obvious integer terms are detected.
211 This is used in cse.c with the `related_value' field.*/
217 if (GET_CODE (x
) == CONST
)
220 if (GET_CODE (x
) == MINUS
221 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
222 return - INTVAL (XEXP (x
, 1));
223 if (GET_CODE (x
) == PLUS
224 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
225 return INTVAL (XEXP (x
, 1));
229 /* If X is a constant, return the value sans apparent integer term;
231 Only obvious integer terms are detected. */
234 get_related_value (x
)
237 if (GET_CODE (x
) != CONST
)
240 if (GET_CODE (x
) == PLUS
241 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
243 else if (GET_CODE (x
) == MINUS
244 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
249 /* Nonzero if register REG appears somewhere within IN.
250 Also works if REG is not a register; in this case it checks
251 for a subexpression of IN that is Lisp "equal" to REG. */
254 reg_mentioned_p (reg
, in
)
255 register rtx reg
, in
;
257 register const char *fmt
;
259 register enum rtx_code code
;
267 if (GET_CODE (in
) == LABEL_REF
)
268 return reg
== XEXP (in
, 0);
270 code
= GET_CODE (in
);
274 /* Compare registers by number. */
276 return GET_CODE (reg
) == REG
&& REGNO (in
) == REGNO (reg
);
278 /* These codes have no constituent expressions
286 return GET_CODE (reg
) == CONST_INT
&& INTVAL (in
) == INTVAL (reg
);
289 /* These are kept unique for a given value. */
296 if (GET_CODE (reg
) == code
&& rtx_equal_p (reg
, in
))
299 fmt
= GET_RTX_FORMAT (code
);
301 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
306 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
307 if (reg_mentioned_p (reg
, XVECEXP (in
, i
, j
)))
310 else if (fmt
[i
] == 'e'
311 && reg_mentioned_p (reg
, XEXP (in
, i
)))
317 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
318 no CODE_LABEL insn. */
321 no_labels_between_p (beg
, end
)
325 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
326 if (GET_CODE (p
) == CODE_LABEL
)
331 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
332 no JUMP_INSN insn. */
335 no_jumps_between_p (beg
, end
)
339 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
340 if (GET_CODE (p
) == JUMP_INSN
)
345 /* Nonzero if register REG is used in an insn between
346 FROM_INSN and TO_INSN (exclusive of those two). */
349 reg_used_between_p (reg
, from_insn
, to_insn
)
350 rtx reg
, from_insn
, to_insn
;
354 if (from_insn
== to_insn
)
357 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
358 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
359 && (reg_overlap_mentioned_p (reg
, PATTERN (insn
))
360 || (GET_CODE (insn
) == CALL_INSN
361 && (find_reg_fusage (insn
, USE
, reg
)
362 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
367 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
368 is entirely replaced by a new value and the only use is as a SET_DEST,
369 we do not consider it a reference. */
372 reg_referenced_p (x
, body
)
378 switch (GET_CODE (body
))
381 if (reg_overlap_mentioned_p (x
, SET_SRC (body
)))
384 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
385 of a REG that occupies all of the REG, the insn references X if
386 it is mentioned in the destination. */
387 if (GET_CODE (SET_DEST (body
)) != CC0
388 && GET_CODE (SET_DEST (body
)) != PC
389 && GET_CODE (SET_DEST (body
)) != REG
390 && ! (GET_CODE (SET_DEST (body
)) == SUBREG
391 && GET_CODE (SUBREG_REG (SET_DEST (body
))) == REG
392 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body
))))
393 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
394 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body
)))
395 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)))
396 && reg_overlap_mentioned_p (x
, SET_DEST (body
)))
401 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
402 if (reg_overlap_mentioned_p (x
, ASM_OPERANDS_INPUT (body
, i
)))
409 return reg_overlap_mentioned_p (x
, body
);
412 return reg_overlap_mentioned_p (x
, TRAP_CONDITION (body
));
415 case UNSPEC_VOLATILE
:
416 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
417 if (reg_overlap_mentioned_p (x
, XVECEXP (body
, 0, i
)))
422 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
423 if (reg_referenced_p (x
, XVECEXP (body
, 0, i
)))
428 if (GET_CODE (XEXP (body
, 0)) == MEM
)
429 if (reg_overlap_mentioned_p (x
, XEXP (XEXP (body
, 0), 0)))
434 if (reg_overlap_mentioned_p (x
, COND_EXEC_TEST (body
)))
436 return reg_referenced_p (x
, COND_EXEC_CODE (body
));
443 /* Nonzero if register REG is referenced in an insn between
444 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
448 reg_referenced_between_p (reg
, from_insn
, to_insn
)
449 rtx reg
, from_insn
, to_insn
;
453 if (from_insn
== to_insn
)
456 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
457 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
458 && (reg_referenced_p (reg
, PATTERN (insn
))
459 || (GET_CODE (insn
) == CALL_INSN
460 && find_reg_fusage (insn
, USE
, reg
))))
465 /* Nonzero if register REG is set or clobbered in an insn between
466 FROM_INSN and TO_INSN (exclusive of those two). */
469 reg_set_between_p (reg
, from_insn
, to_insn
)
470 rtx reg
, from_insn
, to_insn
;
474 if (from_insn
== to_insn
)
477 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
478 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
479 && reg_set_p (reg
, insn
))
484 /* Internals of reg_set_between_p. */
486 static rtx reg_set_reg
;
487 static int reg_set_flag
;
490 reg_set_p_1 (x
, pat
, data
)
492 rtx pat ATTRIBUTE_UNUSED
;
493 void *data ATTRIBUTE_UNUSED
;
495 /* We don't want to return 1 if X is a MEM that contains a register
496 within REG_SET_REG. */
498 if ((GET_CODE (x
) != MEM
)
499 && reg_overlap_mentioned_p (reg_set_reg
, x
))
504 reg_set_p (reg
, insn
)
509 /* We can be passed an insn or part of one. If we are passed an insn,
510 check if a side-effect of the insn clobbers REG. */
511 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
513 if (FIND_REG_INC_NOTE (insn
, reg
)
514 || (GET_CODE (insn
) == CALL_INSN
515 /* We'd like to test call_used_regs here, but rtlanal.c can't
516 reference that variable due to its use in genattrtab. So
517 we'll just be more conservative.
519 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
520 information holds all clobbered registers. */
521 && ((GET_CODE (reg
) == REG
522 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
523 || GET_CODE (reg
) == MEM
524 || find_reg_fusage (insn
, CLOBBER
, reg
))))
527 body
= PATTERN (insn
);
532 note_stores (body
, reg_set_p_1
, NULL
);
536 /* Similar to reg_set_between_p, but check all registers in X. Return 0
537 only if none of them are modified between START and END. Do not
538 consider non-registers one way or the other. */
541 regs_set_between_p (x
, start
, end
)
545 enum rtx_code code
= GET_CODE (x
);
561 return reg_set_between_p (x
, start
, end
);
567 fmt
= GET_RTX_FORMAT (code
);
568 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
570 if (fmt
[i
] == 'e' && regs_set_between_p (XEXP (x
, i
), start
, end
))
573 else if (fmt
[i
] == 'E')
574 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
575 if (regs_set_between_p (XVECEXP (x
, i
, j
), start
, end
))
582 /* Similar to reg_set_between_p, but check all registers in X. Return 0
583 only if none of them are modified between START and END. Return 1 if
584 X contains a MEM; this routine does not perform any memory aliasing. */
587 modified_between_p (x
, start
, end
)
591 enum rtx_code code
= GET_CODE (x
);
609 /* If the memory is not constant, assume it is modified. If it is
610 constant, we still have to check the address. */
611 if (! RTX_UNCHANGING_P (x
))
616 return reg_set_between_p (x
, start
, end
);
622 fmt
= GET_RTX_FORMAT (code
);
623 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
625 if (fmt
[i
] == 'e' && modified_between_p (XEXP (x
, i
), start
, end
))
628 else if (fmt
[i
] == 'E')
629 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
630 if (modified_between_p (XVECEXP (x
, i
, j
), start
, end
))
637 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
638 of them are modified in INSN. Return 1 if X contains a MEM; this routine
639 does not perform any memory aliasing. */
642 modified_in_p (x
, insn
)
646 enum rtx_code code
= GET_CODE (x
);
664 /* If the memory is not constant, assume it is modified. If it is
665 constant, we still have to check the address. */
666 if (! RTX_UNCHANGING_P (x
))
671 return reg_set_p (x
, insn
);
677 fmt
= GET_RTX_FORMAT (code
);
678 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
680 if (fmt
[i
] == 'e' && modified_in_p (XEXP (x
, i
), insn
))
683 else if (fmt
[i
] == 'E')
684 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
685 if (modified_in_p (XVECEXP (x
, i
, j
), insn
))
692 /* Return true if anything in insn X is (anti,output,true) dependent on
693 anything in insn Y. */
696 insn_dependent_p (x
, y
)
701 if (! INSN_P (x
) || ! INSN_P (y
))
705 note_stores (PATTERN (x
), insn_dependent_p_1
, &tmp
);
710 note_stores (PATTERN (y
), insn_dependent_p_1
, &tmp
);
717 /* A helper routine for insn_dependent_p called through note_stores. */
720 insn_dependent_p_1 (x
, pat
, data
)
722 rtx pat ATTRIBUTE_UNUSED
;
725 rtx
* pinsn
= (rtx
*) data
;
727 if (*pinsn
&& reg_mentioned_p (x
, *pinsn
))
731 /* Given an INSN, return a SET expression if this insn has only a single SET.
732 It may also have CLOBBERs, USEs, or SET whose output
733 will not be used, which we ignore. */
742 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
745 if (GET_CODE (PATTERN (insn
)) == SET
)
746 return PATTERN (insn
);
748 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
750 for (i
= 0, set
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
752 rtx sub
= XVECEXP (PATTERN (insn
), 0, i
);
754 switch (GET_CODE (sub
))
761 if (! find_reg_note (insn
, REG_UNUSED
, SET_DEST (sub
))
762 || side_effects_p (sub
))
781 /* Given an INSN, return nonzero if it has more than one SET, else return
791 /* INSN must be an insn. */
792 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
795 /* Only a PARALLEL can have multiple SETs. */
796 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
798 for (i
= 0, found
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
799 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
801 /* If we have already found a SET, then return now. */
809 /* Either zero or one SET. */
813 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
814 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
815 If the object was modified, if we hit a partial assignment to X, or hit a
816 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
817 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
821 find_last_value (x
, pinsn
, valid_to
, allow_hwreg
)
829 for (p
= PREV_INSN (*pinsn
); p
&& GET_CODE (p
) != CODE_LABEL
;
831 if (GET_RTX_CLASS (GET_CODE (p
)) == 'i')
833 rtx set
= single_set (p
);
834 rtx note
= find_reg_note (p
, REG_EQUAL
, NULL_RTX
);
836 if (set
&& rtx_equal_p (x
, SET_DEST (set
)))
838 rtx src
= SET_SRC (set
);
840 if (note
&& GET_CODE (XEXP (note
, 0)) != EXPR_LIST
)
841 src
= XEXP (note
, 0);
843 if ((valid_to
== NULL_RTX
844 || ! modified_between_p (src
, PREV_INSN (p
), valid_to
))
845 /* Reject hard registers because we don't usually want
846 to use them; we'd rather use a pseudo. */
847 && (! (GET_CODE (src
) == REG
848 && REGNO (src
) < FIRST_PSEUDO_REGISTER
) || allow_hwreg
))
855 /* If set in non-simple way, we don't have a value. */
856 if (reg_set_p (x
, p
))
863 /* Return nonzero if register in range [REGNO, ENDREGNO)
864 appears either explicitly or implicitly in X
865 other than being stored into.
867 References contained within the substructure at LOC do not count.
868 LOC may be zero, meaning don't ignore anything. */
871 refers_to_regno_p (regno
, endregno
, x
, loc
)
872 unsigned int regno
, endregno
;
877 unsigned int x_regno
;
882 /* The contents of a REG_NONNEG note is always zero, so we must come here
883 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
894 /* If we modifying the stack, frame, or argument pointer, it will
895 clobber a virtual register. In fact, we could be more precise,
896 but it isn't worth it. */
897 if ((x_regno
== STACK_POINTER_REGNUM
898 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
899 || x_regno
== ARG_POINTER_REGNUM
901 || x_regno
== FRAME_POINTER_REGNUM
)
902 && regno
>= FIRST_VIRTUAL_REGISTER
&& regno
<= LAST_VIRTUAL_REGISTER
)
905 return (endregno
> x_regno
906 && regno
< x_regno
+ (x_regno
< FIRST_PSEUDO_REGISTER
907 ? HARD_REGNO_NREGS (x_regno
, GET_MODE (x
))
911 /* If this is a SUBREG of a hard reg, we can see exactly which
912 registers are being modified. Otherwise, handle normally. */
913 if (GET_CODE (SUBREG_REG (x
)) == REG
914 && REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
)
916 unsigned int inner_regno
= REGNO (SUBREG_REG (x
)) + SUBREG_WORD (x
);
917 unsigned int inner_endregno
918 = inner_regno
+ (inner_regno
< FIRST_PSEUDO_REGISTER
919 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
921 return endregno
> inner_regno
&& regno
< inner_endregno
;
927 if (&SET_DEST (x
) != loc
928 /* Note setting a SUBREG counts as referring to the REG it is in for
929 a pseudo but not for hard registers since we can
930 treat each word individually. */
931 && ((GET_CODE (SET_DEST (x
)) == SUBREG
932 && loc
!= &SUBREG_REG (SET_DEST (x
))
933 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
934 && REGNO (SUBREG_REG (SET_DEST (x
))) >= FIRST_PSEUDO_REGISTER
935 && refers_to_regno_p (regno
, endregno
,
936 SUBREG_REG (SET_DEST (x
)), loc
))
937 || (GET_CODE (SET_DEST (x
)) != REG
938 && refers_to_regno_p (regno
, endregno
, SET_DEST (x
), loc
))))
941 if (code
== CLOBBER
|| loc
== &SET_SRC (x
))
950 /* X does not match, so try its subexpressions. */
952 fmt
= GET_RTX_FORMAT (code
);
953 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
955 if (fmt
[i
] == 'e' && loc
!= &XEXP (x
, i
))
963 if (refers_to_regno_p (regno
, endregno
, XEXP (x
, i
), loc
))
966 else if (fmt
[i
] == 'E')
969 for (j
= XVECLEN (x
, i
) - 1; j
>=0; j
--)
970 if (loc
!= &XVECEXP (x
, i
, j
)
971 && refers_to_regno_p (regno
, endregno
, XVECEXP (x
, i
, j
), loc
))
978 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
979 we check if any register number in X conflicts with the relevant register
980 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
981 contains a MEM (we don't bother checking for memory addresses that can't
982 conflict because we expect this to be a rare case. */
985 reg_overlap_mentioned_p (x
, in
)
988 unsigned int regno
, endregno
;
990 /* Overly conservative. */
991 if (GET_CODE (x
) == STRICT_LOW_PART
)
994 /* If either argument is a constant, then modifying X can not affect IN. */
995 if (CONSTANT_P (x
) || CONSTANT_P (in
))
998 switch (GET_CODE (x
))
1001 regno
= REGNO (SUBREG_REG (x
));
1002 if (regno
< FIRST_PSEUDO_REGISTER
)
1003 regno
+= SUBREG_WORD (x
);
1009 endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
1010 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
1011 return refers_to_regno_p (regno
, endregno
, in
, NULL_PTR
);
1018 if (GET_CODE (in
) == MEM
)
1021 fmt
= GET_RTX_FORMAT (GET_CODE (in
));
1022 for (i
= GET_RTX_LENGTH (GET_CODE (in
)) - 1; i
>= 0; i
--)
1023 if (fmt
[i
] == 'e' && reg_overlap_mentioned_p (x
, XEXP (in
, i
)))
1032 return reg_mentioned_p (x
, in
);
1038 /* Check for a NULL entry, used to indicate that the parameter goes
1039 both on the stack and in registers. */
1040 if (XEXP (XVECEXP (x
, 0, 0), 0))
1045 /* If any register in here refers to it we return true. */
1046 for (n
= XVECLEN (x
, 0); i
< n
; ++i
)
1047 if (reg_overlap_mentioned_p (XEXP (XVECEXP (x
, 0, i
), 0), in
))
1059 /* Used for communications between the next few functions. */
1061 static int reg_set_last_unknown
;
1062 static rtx reg_set_last_value
;
1063 static unsigned int reg_set_last_first_regno
, reg_set_last_last_regno
;
1065 /* Called via note_stores from reg_set_last. */
1068 reg_set_last_1 (x
, pat
, data
)
1071 void *data ATTRIBUTE_UNUSED
;
1073 unsigned int first
, last
;
1075 /* If X is not a register, or is not one in the range we care
1077 if (GET_CODE (x
) != REG
)
1081 last
= first
+ (first
< FIRST_PSEUDO_REGISTER
1082 ? HARD_REGNO_NREGS (first
, GET_MODE (x
)) : 1);
1084 if (first
>= reg_set_last_last_regno
1085 || last
<= reg_set_last_first_regno
)
1088 /* If this is a CLOBBER or is some complex LHS, or doesn't modify
1089 exactly the registers we care about, show we don't know the value. */
1090 if (GET_CODE (pat
) == CLOBBER
|| SET_DEST (pat
) != x
1091 || first
!= reg_set_last_first_regno
1092 || last
!= reg_set_last_last_regno
)
1093 reg_set_last_unknown
= 1;
1095 reg_set_last_value
= SET_SRC (pat
);
1098 /* Return the last value to which REG was set prior to INSN. If we can't
1099 find it easily, return 0.
1101 We only return a REG, SUBREG, or constant because it is too hard to
1102 check if a MEM remains unchanged. */
1105 reg_set_last (x
, insn
)
1109 rtx orig_insn
= insn
;
1111 reg_set_last_first_regno
= REGNO (x
);
1113 reg_set_last_last_regno
1114 = reg_set_last_first_regno
1115 + (reg_set_last_first_regno
< FIRST_PSEUDO_REGISTER
1116 ? HARD_REGNO_NREGS (reg_set_last_first_regno
, GET_MODE (x
)) : 1);
1118 reg_set_last_unknown
= 0;
1119 reg_set_last_value
= 0;
1121 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1122 Stop when we reach a label or X is a hard reg and we reach a
1123 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1125 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1127 /* We compare with <= here, because reg_set_last_last_regno
1128 is actually the number of the first reg *not* in X. */
1130 insn
&& GET_CODE (insn
) != CODE_LABEL
1131 && ! (GET_CODE (insn
) == CALL_INSN
1132 && reg_set_last_last_regno
<= FIRST_PSEUDO_REGISTER
);
1133 insn
= PREV_INSN (insn
))
1134 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
1136 note_stores (PATTERN (insn
), reg_set_last_1
, NULL
);
1137 if (reg_set_last_unknown
)
1139 else if (reg_set_last_value
)
1141 if (CONSTANT_P (reg_set_last_value
)
1142 || ((GET_CODE (reg_set_last_value
) == REG
1143 || GET_CODE (reg_set_last_value
) == SUBREG
)
1144 && ! reg_set_between_p (reg_set_last_value
,
1146 return reg_set_last_value
;
1155 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1156 (X would be the pattern of an insn).
1157 FUN receives two arguments:
1158 the REG, MEM, CC0 or PC being stored in or clobbered,
1159 the SET or CLOBBER rtx that does the store.
1161 If the item being stored in or clobbered is a SUBREG of a hard register,
1162 the SUBREG will be passed. */
1165 note_stores (x
, fun
, data
)
1167 void (*fun
) PARAMS ((rtx
, rtx
, void *));
1170 if (GET_CODE (x
) == COND_EXEC
)
1171 x
= COND_EXEC_CODE (x
);
1172 if (GET_CODE (x
) == SET
|| GET_CODE (x
) == CLOBBER
)
1174 register rtx dest
= SET_DEST (x
);
1175 while ((GET_CODE (dest
) == SUBREG
1176 && (GET_CODE (SUBREG_REG (dest
)) != REG
1177 || REGNO (SUBREG_REG (dest
)) >= FIRST_PSEUDO_REGISTER
))
1178 || GET_CODE (dest
) == ZERO_EXTRACT
1179 || GET_CODE (dest
) == SIGN_EXTRACT
1180 || GET_CODE (dest
) == STRICT_LOW_PART
)
1181 dest
= XEXP (dest
, 0);
1183 if (GET_CODE (dest
) == PARALLEL
1184 && GET_MODE (dest
) == BLKmode
)
1187 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1188 (*fun
) (SET_DEST (XVECEXP (dest
, 0, i
)), x
, data
);
1191 (*fun
) (dest
, x
, data
);
1193 else if (GET_CODE (x
) == PARALLEL
)
1196 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1198 register rtx y
= XVECEXP (x
, 0, i
);
1199 if (GET_CODE (y
) == COND_EXEC
)
1200 y
= COND_EXEC_CODE (y
);
1201 if (GET_CODE (y
) == SET
|| GET_CODE (y
) == CLOBBER
)
1203 register rtx dest
= SET_DEST (y
);
1204 while ((GET_CODE (dest
) == SUBREG
1205 && (GET_CODE (SUBREG_REG (dest
)) != REG
1206 || (REGNO (SUBREG_REG (dest
))
1207 >= FIRST_PSEUDO_REGISTER
)))
1208 || GET_CODE (dest
) == ZERO_EXTRACT
1209 || GET_CODE (dest
) == SIGN_EXTRACT
1210 || GET_CODE (dest
) == STRICT_LOW_PART
)
1211 dest
= XEXP (dest
, 0);
1212 if (GET_CODE (dest
) == PARALLEL
1213 && GET_MODE (dest
) == BLKmode
)
1217 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1218 (*fun
) (SET_DEST (XVECEXP (dest
, 0, i
)), y
, data
);
1221 (*fun
) (dest
, y
, data
);
1227 /* Return nonzero if X's old contents don't survive after INSN.
1228 This will be true if X is (cc0) or if X is a register and
1229 X dies in INSN or because INSN entirely sets X.
1231 "Entirely set" means set directly and not through a SUBREG,
1232 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1233 Likewise, REG_INC does not count.
1235 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1236 but for this use that makes no difference, since regs don't overlap
1237 during their lifetimes. Therefore, this function may be used
1238 at any time after deaths have been computed (in flow.c).
1240 If REG is a hard reg that occupies multiple machine registers, this
1241 function will only return 1 if each of those registers will be replaced
1245 dead_or_set_p (insn
, x
)
1249 unsigned int regno
, last_regno
;
1252 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1253 if (GET_CODE (x
) == CC0
)
1256 if (GET_CODE (x
) != REG
)
1260 last_regno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
1261 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
)) - 1);
1263 for (i
= regno
; i
<= last_regno
; i
++)
1264 if (! dead_or_set_regno_p (insn
, i
))
1270 /* Utility function for dead_or_set_p to check an individual register. Also
1271 called from flow.c. */
1274 dead_or_set_regno_p (insn
, test_regno
)
1276 unsigned int test_regno
;
1278 unsigned int regno
, endregno
;
1281 /* See if there is a death note for something that includes TEST_REGNO. */
1282 if (find_regno_note (insn
, REG_DEAD
, test_regno
))
1285 if (GET_CODE (insn
) == CALL_INSN
1286 && find_regno_fusage (insn
, CLOBBER
, test_regno
))
1289 pattern
= PATTERN (insn
);
1291 if (GET_CODE (pattern
) == COND_EXEC
)
1292 pattern
= COND_EXEC_CODE (pattern
);
1294 if (GET_CODE (pattern
) == SET
)
1296 rtx dest
= SET_DEST (PATTERN (insn
));
1298 /* A value is totally replaced if it is the destination or the
1299 destination is a SUBREG of REGNO that does not change the number of
1301 if (GET_CODE (dest
) == SUBREG
1302 && (((GET_MODE_SIZE (GET_MODE (dest
))
1303 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1304 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1305 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1306 dest
= SUBREG_REG (dest
);
1308 if (GET_CODE (dest
) != REG
)
1311 regno
= REGNO (dest
);
1312 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1313 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1315 return (test_regno
>= regno
&& test_regno
< endregno
);
1317 else if (GET_CODE (pattern
) == PARALLEL
)
1321 for (i
= XVECLEN (pattern
, 0) - 1; i
>= 0; i
--)
1323 rtx body
= XVECEXP (pattern
, 0, i
);
1325 if (GET_CODE (body
) == COND_EXEC
)
1326 body
= COND_EXEC_CODE (body
);
1328 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == CLOBBER
)
1330 rtx dest
= SET_DEST (body
);
1332 if (GET_CODE (dest
) == SUBREG
1333 && (((GET_MODE_SIZE (GET_MODE (dest
))
1334 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1335 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1336 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1337 dest
= SUBREG_REG (dest
);
1339 if (GET_CODE (dest
) != REG
)
1342 regno
= REGNO (dest
);
1343 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1344 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1346 if (test_regno
>= regno
&& test_regno
< endregno
)
1355 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1356 If DATUM is nonzero, look for one whose datum is DATUM. */
1359 find_reg_note (insn
, kind
, datum
)
1366 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1367 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
1370 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1371 if (REG_NOTE_KIND (link
) == kind
1372 && (datum
== 0 || datum
== XEXP (link
, 0)))
1377 /* Return the reg-note of kind KIND in insn INSN which applies to register
1378 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1379 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1380 it might be the case that the note overlaps REGNO. */
1383 find_regno_note (insn
, kind
, regno
)
1390 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1391 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
1394 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1395 if (REG_NOTE_KIND (link
) == kind
1396 /* Verify that it is a register, so that scratch and MEM won't cause a
1398 && GET_CODE (XEXP (link
, 0)) == REG
1399 && REGNO (XEXP (link
, 0)) <= regno
1400 && ((REGNO (XEXP (link
, 0))
1401 + (REGNO (XEXP (link
, 0)) >= FIRST_PSEUDO_REGISTER
? 1
1402 : HARD_REGNO_NREGS (REGNO (XEXP (link
, 0)),
1403 GET_MODE (XEXP (link
, 0)))))
1409 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1410 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1413 find_reg_fusage (insn
, code
, datum
)
1418 /* If it's not a CALL_INSN, it can't possibly have a
1419 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1420 if (GET_CODE (insn
) != CALL_INSN
)
1426 if (GET_CODE (datum
) != REG
)
1430 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1432 link
= XEXP (link
, 1))
1433 if (GET_CODE (XEXP (link
, 0)) == code
1434 && rtx_equal_p (datum
, SET_DEST (XEXP (link
, 0))))
1439 unsigned int regno
= REGNO (datum
);
1441 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1442 to pseudo registers, so don't bother checking. */
1444 if (regno
< FIRST_PSEUDO_REGISTER
)
1446 unsigned int end_regno
1447 = regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (datum
));
1450 for (i
= regno
; i
< end_regno
; i
++)
1451 if (find_regno_fusage (insn
, code
, i
))
1459 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1460 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1463 find_regno_fusage (insn
, code
, regno
)
1470 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1471 to pseudo registers, so don't bother checking. */
1473 if (regno
>= FIRST_PSEUDO_REGISTER
1474 || GET_CODE (insn
) != CALL_INSN
)
1477 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
1479 unsigned int regnote
;
1482 if (GET_CODE (op
= XEXP (link
, 0)) == code
1483 && GET_CODE (reg
= XEXP (op
, 0)) == REG
1484 && (regnote
= REGNO (reg
)) <= regno
1485 && regnote
+ HARD_REGNO_NREGS (regnote
, GET_MODE (reg
)) > regno
)
1492 /* Remove register note NOTE from the REG_NOTES of INSN. */
1495 remove_note (insn
, note
)
1501 if (note
== NULL_RTX
)
1504 if (REG_NOTES (insn
) == note
)
1506 REG_NOTES (insn
) = XEXP (note
, 1);
1510 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1511 if (XEXP (link
, 1) == note
)
1513 XEXP (link
, 1) = XEXP (note
, 1);
1520 /* Search LISTP (an EXPR_LIST) for NODE and remove NODE from the list
1523 A simple equality test is used to determine if NODE is on the
1527 remove_node_from_expr_list (node
, listp
)
1532 rtx prev
= NULL_RTX
;
1536 if (node
== XEXP (temp
, 0))
1538 /* Splice the node out of the list. */
1540 XEXP (prev
, 1) = XEXP (temp
, 1);
1542 *listp
= XEXP (temp
, 1);
1546 temp
= XEXP (temp
, 1);
1550 /* Nonzero if X contains any volatile instructions. These are instructions
1551 which may cause unpredictable machine state instructions, and thus no
1552 instructions should be moved or combined across them. This includes
1553 only volatile asms and UNSPEC_VOLATILE instructions. */
1559 register RTX_CODE code
;
1561 code
= GET_CODE (x
);
1581 case UNSPEC_VOLATILE
:
1582 /* case TRAP_IF: This isn't clear yet. */
1586 if (MEM_VOLATILE_P (x
))
1593 /* Recursively scan the operands of this expression. */
1596 register const char *fmt
= GET_RTX_FORMAT (code
);
1599 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1603 if (volatile_insn_p (XEXP (x
, i
)))
1606 else if (fmt
[i
] == 'E')
1609 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1610 if (volatile_insn_p (XVECEXP (x
, i
, j
)))
1618 /* Nonzero if X contains any volatile memory references
1619 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1625 register RTX_CODE code
;
1627 code
= GET_CODE (x
);
1646 case UNSPEC_VOLATILE
:
1647 /* case TRAP_IF: This isn't clear yet. */
1652 if (MEM_VOLATILE_P (x
))
1659 /* Recursively scan the operands of this expression. */
1662 register const char *fmt
= GET_RTX_FORMAT (code
);
1665 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1669 if (volatile_refs_p (XEXP (x
, i
)))
1672 else if (fmt
[i
] == 'E')
1675 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1676 if (volatile_refs_p (XVECEXP (x
, i
, j
)))
1684 /* Similar to above, except that it also rejects register pre- and post-
1691 register RTX_CODE code
;
1693 code
= GET_CODE (x
);
1711 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1712 when some combination can't be done. If we see one, don't think
1713 that we can simplify the expression. */
1714 return (GET_MODE (x
) != VOIDmode
);
1721 case UNSPEC_VOLATILE
:
1722 /* case TRAP_IF: This isn't clear yet. */
1727 if (MEM_VOLATILE_P (x
))
1734 /* Recursively scan the operands of this expression. */
1737 register const char *fmt
= GET_RTX_FORMAT (code
);
1740 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1744 if (side_effects_p (XEXP (x
, i
)))
1747 else if (fmt
[i
] == 'E')
1750 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1751 if (side_effects_p (XVECEXP (x
, i
, j
)))
1759 /* Return nonzero if evaluating rtx X might cause a trap. */
1771 code
= GET_CODE (x
);
1774 /* Handle these cases quickly. */
1787 case UNSPEC_VOLATILE
:
1792 return MEM_VOLATILE_P (x
);
1794 /* Memory ref can trap unless it's a static var or a stack slot. */
1796 return rtx_addr_can_trap_p (XEXP (x
, 0));
1798 /* Division by a non-constant might trap. */
1803 if (! CONSTANT_P (XEXP (x
, 1))
1804 || GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1806 /* This was const0_rtx, but by not using that,
1807 we can link this file into other programs. */
1808 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
&& INTVAL (XEXP (x
, 1)) == 0)
1813 /* An EXPR_LIST is used to represent a function call. This
1814 certainly may trap. */
1818 /* Any floating arithmetic may trap. */
1819 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1823 fmt
= GET_RTX_FORMAT (code
);
1824 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1828 if (may_trap_p (XEXP (x
, i
)))
1831 else if (fmt
[i
] == 'E')
1834 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1835 if (may_trap_p (XVECEXP (x
, i
, j
)))
1842 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1843 i.e., an inequality. */
1846 inequality_comparisons_p (x
)
1849 register const char *fmt
;
1850 register int len
, i
;
1851 register enum rtx_code code
= GET_CODE (x
);
1880 len
= GET_RTX_LENGTH (code
);
1881 fmt
= GET_RTX_FORMAT (code
);
1883 for (i
= 0; i
< len
; i
++)
1887 if (inequality_comparisons_p (XEXP (x
, i
)))
1890 else if (fmt
[i
] == 'E')
1893 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1894 if (inequality_comparisons_p (XVECEXP (x
, i
, j
)))
1902 /* Replace any occurrence of FROM in X with TO. The function does
1903 not enter into CONST_DOUBLE for the replace.
1905 Note that copying is not done so X must not be shared unless all copies
1906 are to be modified. */
1909 replace_rtx (x
, from
, to
)
1913 register const char *fmt
;
1915 /* The following prevents loops occurrence when we change MEM in
1916 CONST_DOUBLE onto the same CONST_DOUBLE. */
1917 if (x
!= 0 && GET_CODE (x
) == CONST_DOUBLE
)
1923 /* Allow this function to make replacements in EXPR_LISTs. */
1927 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
1928 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
1931 XEXP (x
, i
) = replace_rtx (XEXP (x
, i
), from
, to
);
1932 else if (fmt
[i
] == 'E')
1933 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1934 XVECEXP (x
, i
, j
) = replace_rtx (XVECEXP (x
, i
, j
), from
, to
);
1940 /* Throughout the rtx X, replace many registers according to REG_MAP.
1941 Return the replacement for X (which may be X with altered contents).
1942 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
1943 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
1945 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
1946 should not be mapped to pseudos or vice versa since validate_change
1949 If REPLACE_DEST is 1, replacements are also done in destinations;
1950 otherwise, only sources are replaced. */
1953 replace_regs (x
, reg_map
, nregs
, replace_dest
)
1959 register enum rtx_code code
;
1961 register const char *fmt
;
1966 code
= GET_CODE (x
);
1980 /* Verify that the register has an entry before trying to access it. */
1981 if (REGNO (x
) < nregs
&& reg_map
[REGNO (x
)] != 0)
1983 /* SUBREGs can't be shared. Always return a copy to ensure that if
1984 this replacement occurs more than once then each instance will
1985 get distinct rtx. */
1986 if (GET_CODE (reg_map
[REGNO (x
)]) == SUBREG
)
1987 return copy_rtx (reg_map
[REGNO (x
)]);
1988 return reg_map
[REGNO (x
)];
1993 /* Prevent making nested SUBREGs. */
1994 if (GET_CODE (SUBREG_REG (x
)) == REG
&& REGNO (SUBREG_REG (x
)) < nregs
1995 && reg_map
[REGNO (SUBREG_REG (x
))] != 0
1996 && GET_CODE (reg_map
[REGNO (SUBREG_REG (x
))]) == SUBREG
)
1998 rtx map_val
= reg_map
[REGNO (SUBREG_REG (x
))];
1999 rtx map_inner
= SUBREG_REG (map_val
);
2001 if (GET_MODE (x
) == GET_MODE (map_inner
))
2005 /* We cannot call gen_rtx here since we may be linked with
2007 /* Let's try clobbering the incoming SUBREG and see
2008 if this is really safe. */
2009 SUBREG_REG (x
) = map_inner
;
2010 SUBREG_WORD (x
) += SUBREG_WORD (map_val
);
2013 rtx
new = rtx_alloc (SUBREG
);
2014 PUT_MODE (new, GET_MODE (x
));
2015 SUBREG_REG (new) = map_inner
;
2016 SUBREG_WORD (new) = SUBREG_WORD (x
) + SUBREG_WORD (map_val
);
2024 SET_DEST (x
) = replace_regs (SET_DEST (x
), reg_map
, nregs
, 0);
2026 else if (GET_CODE (SET_DEST (x
)) == MEM
2027 || GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2028 /* Even if we are not to replace destinations, replace register if it
2029 is CONTAINED in destination (destination is memory or
2030 STRICT_LOW_PART). */
2031 XEXP (SET_DEST (x
), 0) = replace_regs (XEXP (SET_DEST (x
), 0),
2033 else if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2034 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2037 SET_SRC (x
) = replace_regs (SET_SRC (x
), reg_map
, nregs
, 0);
2044 fmt
= GET_RTX_FORMAT (code
);
2045 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2048 XEXP (x
, i
) = replace_regs (XEXP (x
, i
), reg_map
, nregs
, replace_dest
);
2049 else if (fmt
[i
] == 'E')
2052 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2053 XVECEXP (x
, i
, j
) = replace_regs (XVECEXP (x
, i
, j
), reg_map
,
2054 nregs
, replace_dest
);
2060 /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is
2061 not in the constant pool and not in the condition of an IF_THEN_ELSE. */
2064 jmp_uses_reg_or_mem (x
)
2067 enum rtx_code code
= GET_CODE (x
);
2082 return ! (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
2083 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)));
2086 return (jmp_uses_reg_or_mem (XEXP (x
, 1))
2087 || jmp_uses_reg_or_mem (XEXP (x
, 2)));
2089 case PLUS
: case MINUS
: case MULT
:
2090 return (jmp_uses_reg_or_mem (XEXP (x
, 0))
2091 || jmp_uses_reg_or_mem (XEXP (x
, 1)));
2097 fmt
= GET_RTX_FORMAT (code
);
2098 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2101 && jmp_uses_reg_or_mem (XEXP (x
, i
)))
2104 else if (fmt
[i
] == 'E')
2105 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2106 if (jmp_uses_reg_or_mem (XVECEXP (x
, i
, j
)))
2113 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2115 Tablejumps and casesi insns are not considered indirect jumps;
2116 we can recognize them by a (use (label_ref)). */
2119 computed_jump_p (insn
)
2123 if (GET_CODE (insn
) == JUMP_INSN
)
2125 rtx pat
= PATTERN (insn
);
2127 if (GET_CODE (pat
) == PARALLEL
)
2129 int len
= XVECLEN (pat
, 0);
2130 int has_use_labelref
= 0;
2132 for (i
= len
- 1; i
>= 0; i
--)
2133 if (GET_CODE (XVECEXP (pat
, 0, i
)) == USE
2134 && (GET_CODE (XEXP (XVECEXP (pat
, 0, i
), 0))
2136 has_use_labelref
= 1;
2138 if (! has_use_labelref
)
2139 for (i
= len
- 1; i
>= 0; i
--)
2140 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
2141 && SET_DEST (XVECEXP (pat
, 0, i
)) == pc_rtx
2142 && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat
, 0, i
))))
2145 else if (GET_CODE (pat
) == SET
2146 && SET_DEST (pat
) == pc_rtx
2147 && jmp_uses_reg_or_mem (SET_SRC (pat
)))
2153 /* Traverse X via depth-first search, calling F for each
2154 sub-expression (including X itself). F is also passed the DATA.
2155 If F returns -1, do not traverse sub-expressions, but continue
2156 traversing the rest of the tree. If F ever returns any other
2157 non-zero value, stop the traversal, and return the value returned
2158 by F. Otherwise, return 0. This function does not traverse inside
2159 tree structure that contains RTX_EXPRs, or into sub-expressions
2160 whose format code is `0' since it is not known whether or not those
2161 codes are actually RTL.
2163 This routine is very general, and could (should?) be used to
2164 implement many of the other routines in this file. */
2167 for_each_rtx (x
, f
, data
)
2178 result
= (*f
)(x
, data
);
2180 /* Do not traverse sub-expressions. */
2182 else if (result
!= 0)
2183 /* Stop the traversal. */
2187 /* There are no sub-expressions. */
2190 length
= GET_RTX_LENGTH (GET_CODE (*x
));
2191 format
= GET_RTX_FORMAT (GET_CODE (*x
));
2193 for (i
= 0; i
< length
; ++i
)
2198 result
= for_each_rtx (&XEXP (*x
, i
), f
, data
);
2205 if (XVEC (*x
, i
) != 0)
2208 for (j
= 0; j
< XVECLEN (*x
, i
); ++j
)
2210 result
= for_each_rtx (&XVECEXP (*x
, i
, j
), f
, data
);
2218 /* Nothing to do. */
2227 /* Searches X for any reference to REGNO, returning the rtx of the
2228 reference found if any. Otherwise, returns NULL_RTX. */
2231 regno_use_in (regno
, x
)
2235 register const char *fmt
;
2239 if (GET_CODE (x
) == REG
&& REGNO (x
) == regno
)
2242 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2243 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2247 if ((tem
= regno_use_in (regno
, XEXP (x
, i
))))
2250 else if (fmt
[i
] == 'E')
2251 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2252 if ((tem
= regno_use_in (regno
, XVECEXP (x
, i
, j
))))
2260 /* Return 1 if X is an autoincrement side effect and the register is
2261 not the stack pointer. */
2266 switch (GET_CODE (x
))
2274 /* There are no REG_INC notes for SP. */
2275 if (XEXP (x
, 0) != stack_pointer_rtx
)
2283 /* Return 1 if the sequence of instructions beginning with FROM and up
2284 to and including TO is safe to move. If NEW_TO is non-NULL, and
2285 the sequence is not already safe to move, but can be easily
2286 extended to a sequence which is safe, then NEW_TO will point to the
2287 end of the extended sequence.
2289 For now, this function only checks that the region contains whole
2290 exception regiongs, but it could be extended to check additional
2291 conditions as well. */
2294 insns_safe_to_move_p (from
, to
, new_to
)
2299 int eh_region_count
= 0;
2303 /* By default, assume the end of the region will be what was
2310 if (GET_CODE (r
) == NOTE
)
2312 switch (NOTE_LINE_NUMBER (r
))
2314 case NOTE_INSN_EH_REGION_BEG
:
2318 case NOTE_INSN_EH_REGION_END
:
2319 if (eh_region_count
== 0)
2320 /* This sequence of instructions contains the end of
2321 an exception region, but not he beginning. Moving
2322 it will cause chaos. */
2333 /* If we've passed TO, and we see a non-note instruction, we
2334 can't extend the sequence to a movable sequence. */
2340 /* It's OK to move the sequence if there were matched sets of
2341 exception region notes. */
2342 return eh_region_count
== 0;
2347 /* It's OK to move the sequence if there were matched sets of
2348 exception region notes. */
2349 if (past_to_p
&& eh_region_count
== 0)
2355 /* Go to the next instruction. */
2362 /* Return non-zero if IN contains a piece of rtl that has the address LOC */
2364 loc_mentioned_in_p (loc
, in
)
2367 enum rtx_code code
= GET_CODE (in
);
2368 const char *fmt
= GET_RTX_FORMAT (code
);
2371 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2373 if (loc
== &in
->fld
[i
].rtx
)
2377 if (loc_mentioned_in_p (loc
, XEXP (in
, i
)))
2380 else if (fmt
[i
] == 'E')
2381 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
2382 if (loc_mentioned_in_p (loc
, XVECEXP (in
, i
, j
)))