1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 88, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 static int rtx_addr_can_trap_p
PROTO((rtx
));
27 static void reg_set_p_1
PROTO((rtx
, rtx
, void *));
28 static void reg_set_last_1
PROTO((rtx
, rtx
, void *));
31 /* Forward declarations */
32 static int jmp_uses_reg_or_mem
PROTO((rtx
));
34 /* Bit flags that specify the machine subtype we are compiling for.
35 Bits are tested using macros TARGET_... defined in the tm.h file
36 and set by `-m...' switches. Must be defined in rtlanal.c. */
40 /* Return 1 if the value of X is unstable
41 (would be different at a different point in the program).
42 The frame pointer, arg pointer, etc. are considered stable
43 (within one function) and so is anything marked `unchanging'. */
49 register RTX_CODE code
= GET_CODE (x
);
51 register const char *fmt
;
54 return ! RTX_UNCHANGING_P (x
);
59 if (code
== CONST
|| code
== CONST_INT
)
63 return ! (REGNO (x
) == FRAME_POINTER_REGNUM
64 || REGNO (x
) == HARD_FRAME_POINTER_REGNUM
65 || REGNO (x
) == ARG_POINTER_REGNUM
66 || RTX_UNCHANGING_P (x
));
68 fmt
= GET_RTX_FORMAT (code
);
69 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
71 if (rtx_unstable_p (XEXP (x
, i
)))
76 /* Return 1 if X has a value that can vary even between two
77 executions of the program. 0 means X can be compared reliably
78 against certain constants or near-constants.
79 The frame pointer and the arg pointer are considered constant. */
85 register RTX_CODE code
= GET_CODE (x
);
87 register const char *fmt
;
103 /* Note that we have to test for the actual rtx used for the frame
104 and arg pointers and not just the register number in case we have
105 eliminated the frame and/or arg pointer and are using it
107 return ! (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
108 || x
== arg_pointer_rtx
|| x
== pic_offset_table_rtx
);
111 /* The operand 0 of a LO_SUM is considered constant
112 (in fact is it related specifically to operand 1). */
113 return rtx_varies_p (XEXP (x
, 1));
119 fmt
= GET_RTX_FORMAT (code
);
120 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
122 if (rtx_varies_p (XEXP (x
, i
)))
127 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
130 rtx_addr_can_trap_p (x
)
133 register enum rtx_code code
= GET_CODE (x
);
139 /* SYMBOL_REF is problematic due to the possible presence of
140 a #pragma weak, but to say that loads from symbols can trap is
141 *very* costly. It's not at all clear what's best here. For
142 now, we ignore the impact of #pragma weak. */
146 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
147 return ! (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
148 || x
== stack_pointer_rtx
|| x
== arg_pointer_rtx
);
151 return rtx_addr_can_trap_p (XEXP (x
, 0));
154 /* An address is assumed not to trap if it is an address that can't
155 trap plus a constant integer. */
156 return (rtx_addr_can_trap_p (XEXP (x
, 0))
157 || GET_CODE (XEXP (x
, 1)) != CONST_INT
);
160 return rtx_addr_can_trap_p (XEXP (x
, 1));
166 /* If it isn't one of the case above, it can cause a trap. */
170 /* Return 1 if X refers to a memory location whose address
171 cannot be compared reliably with constant addresses,
172 or if X refers to a BLKmode memory object. */
175 rtx_addr_varies_p (x
)
178 register enum rtx_code code
;
180 register const char *fmt
;
187 return GET_MODE (x
) == BLKmode
|| rtx_varies_p (XEXP (x
, 0));
189 fmt
= GET_RTX_FORMAT (code
);
190 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
193 if (rtx_addr_varies_p (XEXP (x
, i
)))
196 else if (fmt
[i
] == 'E')
199 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
200 if (rtx_addr_varies_p (XVECEXP (x
, i
, j
)))
206 /* Return the value of the integer term in X, if one is apparent;
208 Only obvious integer terms are detected.
209 This is used in cse.c with the `related_value' field.*/
215 if (GET_CODE (x
) == CONST
)
218 if (GET_CODE (x
) == MINUS
219 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
220 return - INTVAL (XEXP (x
, 1));
221 if (GET_CODE (x
) == PLUS
222 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
223 return INTVAL (XEXP (x
, 1));
227 /* If X is a constant, return the value sans apparent integer term;
229 Only obvious integer terms are detected. */
232 get_related_value (x
)
235 if (GET_CODE (x
) != CONST
)
238 if (GET_CODE (x
) == PLUS
239 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
241 else if (GET_CODE (x
) == MINUS
242 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
247 /* Nonzero if register REG appears somewhere within IN.
248 Also works if REG is not a register; in this case it checks
249 for a subexpression of IN that is Lisp "equal" to REG. */
252 reg_mentioned_p (reg
, in
)
253 register rtx reg
, in
;
255 register const char *fmt
;
257 register enum rtx_code code
;
265 if (GET_CODE (in
) == LABEL_REF
)
266 return reg
== XEXP (in
, 0);
268 code
= GET_CODE (in
);
272 /* Compare registers by number. */
274 return GET_CODE (reg
) == REG
&& REGNO (in
) == REGNO (reg
);
276 /* These codes have no constituent expressions
284 return GET_CODE (reg
) == CONST_INT
&& INTVAL (in
) == INTVAL (reg
);
287 /* These are kept unique for a given value. */
294 if (GET_CODE (reg
) == code
&& rtx_equal_p (reg
, in
))
297 fmt
= GET_RTX_FORMAT (code
);
299 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
304 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
305 if (reg_mentioned_p (reg
, XVECEXP (in
, i
, j
)))
308 else if (fmt
[i
] == 'e'
309 && reg_mentioned_p (reg
, XEXP (in
, i
)))
315 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
316 no CODE_LABEL insn. */
319 no_labels_between_p (beg
, end
)
323 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
324 if (GET_CODE (p
) == CODE_LABEL
)
329 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
330 no JUMP_INSN insn. */
333 no_jumps_between_p (beg
, end
)
337 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
338 if (GET_CODE (p
) == JUMP_INSN
)
343 /* Nonzero if register REG is used in an insn between
344 FROM_INSN and TO_INSN (exclusive of those two). */
347 reg_used_between_p (reg
, from_insn
, to_insn
)
348 rtx reg
, from_insn
, to_insn
;
352 if (from_insn
== to_insn
)
355 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
356 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
357 && (reg_overlap_mentioned_p (reg
, PATTERN (insn
))
358 || (GET_CODE (insn
) == CALL_INSN
359 && (find_reg_fusage (insn
, USE
, reg
)
360 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
365 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
366 is entirely replaced by a new value and the only use is as a SET_DEST,
367 we do not consider it a reference. */
370 reg_referenced_p (x
, body
)
376 switch (GET_CODE (body
))
379 if (reg_overlap_mentioned_p (x
, SET_SRC (body
)))
382 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
383 of a REG that occupies all of the REG, the insn references X if
384 it is mentioned in the destination. */
385 if (GET_CODE (SET_DEST (body
)) != CC0
386 && GET_CODE (SET_DEST (body
)) != PC
387 && GET_CODE (SET_DEST (body
)) != REG
388 && ! (GET_CODE (SET_DEST (body
)) == SUBREG
389 && GET_CODE (SUBREG_REG (SET_DEST (body
))) == REG
390 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body
))))
391 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
392 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body
)))
393 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)))
394 && reg_overlap_mentioned_p (x
, SET_DEST (body
)))
399 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
400 if (reg_overlap_mentioned_p (x
, ASM_OPERANDS_INPUT (body
, i
)))
407 return reg_overlap_mentioned_p (x
, body
);
410 return reg_overlap_mentioned_p (x
, TRAP_CONDITION (body
));
413 case UNSPEC_VOLATILE
:
414 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
415 if (reg_overlap_mentioned_p (x
, XVECEXP (body
, 0, i
)))
420 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
421 if (reg_referenced_p (x
, XVECEXP (body
, 0, i
)))
430 /* Nonzero if register REG is referenced in an insn between
431 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
435 reg_referenced_between_p (reg
, from_insn
, to_insn
)
436 rtx reg
, from_insn
, to_insn
;
440 if (from_insn
== to_insn
)
443 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
444 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
445 && (reg_referenced_p (reg
, PATTERN (insn
))
446 || (GET_CODE (insn
) == CALL_INSN
447 && find_reg_fusage (insn
, USE
, reg
))))
452 /* Nonzero if register REG is set or clobbered in an insn between
453 FROM_INSN and TO_INSN (exclusive of those two). */
456 reg_set_between_p (reg
, from_insn
, to_insn
)
457 rtx reg
, from_insn
, to_insn
;
461 if (from_insn
== to_insn
)
464 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
465 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
466 && reg_set_p (reg
, insn
))
471 /* Internals of reg_set_between_p. */
473 static rtx reg_set_reg
;
474 static int reg_set_flag
;
477 reg_set_p_1 (x
, pat
, data
)
479 rtx pat ATTRIBUTE_UNUSED
;
480 void *data ATTRIBUTE_UNUSED
;
482 /* We don't want to return 1 if X is a MEM that contains a register
483 within REG_SET_REG. */
485 if ((GET_CODE (x
) != MEM
)
486 && reg_overlap_mentioned_p (reg_set_reg
, x
))
491 reg_set_p (reg
, insn
)
496 /* We can be passed an insn or part of one. If we are passed an insn,
497 check if a side-effect of the insn clobbers REG. */
498 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
500 if (FIND_REG_INC_NOTE (insn
, reg
)
501 || (GET_CODE (insn
) == CALL_INSN
502 /* We'd like to test call_used_regs here, but rtlanal.c can't
503 reference that variable due to its use in genattrtab. So
504 we'll just be more conservative.
506 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
507 information holds all clobbered registers. */
508 && ((GET_CODE (reg
) == REG
509 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
510 || GET_CODE (reg
) == MEM
511 || find_reg_fusage (insn
, CLOBBER
, reg
))))
514 body
= PATTERN (insn
);
519 note_stores (body
, reg_set_p_1
, NULL
);
523 /* Similar to reg_set_between_p, but check all registers in X. Return 0
524 only if none of them are modified between START and END. Do not
525 consider non-registers one way or the other. */
528 regs_set_between_p (x
, start
, end
)
532 enum rtx_code code
= GET_CODE (x
);
548 return reg_set_between_p (x
, start
, end
);
554 fmt
= GET_RTX_FORMAT (code
);
555 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
557 if (fmt
[i
] == 'e' && regs_set_between_p (XEXP (x
, i
), start
, end
))
560 else if (fmt
[i
] == 'E')
561 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
562 if (regs_set_between_p (XVECEXP (x
, i
, j
), start
, end
))
569 /* Similar to reg_set_between_p, but check all registers in X. Return 0
570 only if none of them are modified between START and END. Return 1 if
571 X contains a MEM; this routine does not perform any memory aliasing. */
574 modified_between_p (x
, start
, end
)
578 enum rtx_code code
= GET_CODE (x
);
596 /* If the memory is not constant, assume it is modified. If it is
597 constant, we still have to check the address. */
598 if (! RTX_UNCHANGING_P (x
))
603 return reg_set_between_p (x
, start
, end
);
609 fmt
= GET_RTX_FORMAT (code
);
610 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
612 if (fmt
[i
] == 'e' && modified_between_p (XEXP (x
, i
), start
, end
))
616 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
617 if (modified_between_p (XVECEXP (x
, i
, j
), start
, end
))
624 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
625 of them are modified in INSN. Return 1 if X contains a MEM; this routine
626 does not perform any memory aliasing. */
629 modified_in_p (x
, insn
)
633 enum rtx_code code
= GET_CODE (x
);
651 /* If the memory is not constant, assume it is modified. If it is
652 constant, we still have to check the address. */
653 if (! RTX_UNCHANGING_P (x
))
658 return reg_set_p (x
, insn
);
664 fmt
= GET_RTX_FORMAT (code
);
665 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
667 if (fmt
[i
] == 'e' && modified_in_p (XEXP (x
, i
), insn
))
671 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
672 if (modified_in_p (XVECEXP (x
, i
, j
), insn
))
679 /* Given an INSN, return a SET expression if this insn has only a single SET.
680 It may also have CLOBBERs, USEs, or SET whose output
681 will not be used, which we ignore. */
690 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
693 if (GET_CODE (PATTERN (insn
)) == SET
)
694 return PATTERN (insn
);
696 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
698 for (i
= 0, set
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
699 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
700 && (! find_reg_note (insn
, REG_UNUSED
,
701 SET_DEST (XVECEXP (PATTERN (insn
), 0, i
)))
702 || side_effects_p (XVECEXP (PATTERN (insn
), 0, i
))))
707 set
= XVECEXP (PATTERN (insn
), 0, i
);
715 /* Given an INSN, return nonzero if it has more than one SET, else return
725 /* INSN must be an insn. */
726 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
729 /* Only a PARALLEL can have multiple SETs. */
730 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
732 for (i
= 0, found
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
733 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
735 /* If we have already found a SET, then return now. */
743 /* Either zero or one SET. */
747 /* Return the last thing that X was assigned from before *PINSN. Verify that
748 the object is not modified up to VALID_TO. If it was, if we hit
749 a partial assignment to X, or hit a CODE_LABEL first, return X. If we
750 found an assignment, update *PINSN to point to it.
751 ALLOW_HWREG is set to 1 if hardware registers are allowed to be the src. */
754 find_last_value (x
, pinsn
, valid_to
, allow_hwreg
)
762 for (p
= PREV_INSN (*pinsn
); p
&& GET_CODE (p
) != CODE_LABEL
;
764 if (GET_RTX_CLASS (GET_CODE (p
)) == 'i')
766 rtx set
= single_set (p
);
767 rtx note
= find_reg_note (p
, REG_EQUAL
, NULL_RTX
);
769 if (set
&& rtx_equal_p (x
, SET_DEST (set
)))
771 rtx src
= SET_SRC (set
);
773 if (note
&& GET_CODE (XEXP (note
, 0)) != EXPR_LIST
)
774 src
= XEXP (note
, 0);
776 if (! modified_between_p (src
, PREV_INSN (p
), valid_to
)
777 /* Reject hard registers because we don't usually want
778 to use them; we'd rather use a pseudo. */
779 && (! (GET_CODE (src
) == REG
780 && REGNO (src
) < FIRST_PSEUDO_REGISTER
) || allow_hwreg
))
787 /* If set in non-simple way, we don't have a value. */
788 if (reg_set_p (x
, p
))
795 /* Return nonzero if register in range [REGNO, ENDREGNO)
796 appears either explicitly or implicitly in X
797 other than being stored into.
799 References contained within the substructure at LOC do not count.
800 LOC may be zero, meaning don't ignore anything. */
803 refers_to_regno_p (regno
, endregno
, x
, loc
)
809 register RTX_CODE code
;
810 register const char *fmt
;
813 /* The contents of a REG_NONNEG note is always zero, so we must come here
814 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
825 /* If we modifying the stack, frame, or argument pointer, it will
826 clobber a virtual register. In fact, we could be more precise,
827 but it isn't worth it. */
828 if ((i
== STACK_POINTER_REGNUM
829 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
830 || i
== ARG_POINTER_REGNUM
832 || i
== FRAME_POINTER_REGNUM
)
833 && regno
>= FIRST_VIRTUAL_REGISTER
&& regno
<= LAST_VIRTUAL_REGISTER
)
837 && regno
< i
+ (i
< FIRST_PSEUDO_REGISTER
838 ? HARD_REGNO_NREGS (i
, GET_MODE (x
))
842 /* If this is a SUBREG of a hard reg, we can see exactly which
843 registers are being modified. Otherwise, handle normally. */
844 if (GET_CODE (SUBREG_REG (x
)) == REG
845 && REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
)
847 int inner_regno
= REGNO (SUBREG_REG (x
)) + SUBREG_WORD (x
);
849 = inner_regno
+ (inner_regno
< FIRST_PSEUDO_REGISTER
850 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
852 return endregno
> inner_regno
&& regno
< inner_endregno
;
858 if (&SET_DEST (x
) != loc
859 /* Note setting a SUBREG counts as referring to the REG it is in for
860 a pseudo but not for hard registers since we can
861 treat each word individually. */
862 && ((GET_CODE (SET_DEST (x
)) == SUBREG
863 && loc
!= &SUBREG_REG (SET_DEST (x
))
864 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
865 && REGNO (SUBREG_REG (SET_DEST (x
))) >= FIRST_PSEUDO_REGISTER
866 && refers_to_regno_p (regno
, endregno
,
867 SUBREG_REG (SET_DEST (x
)), loc
))
868 || (GET_CODE (SET_DEST (x
)) != REG
869 && refers_to_regno_p (regno
, endregno
, SET_DEST (x
), loc
))))
872 if (code
== CLOBBER
|| loc
== &SET_SRC (x
))
881 /* X does not match, so try its subexpressions. */
883 fmt
= GET_RTX_FORMAT (code
);
884 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
886 if (fmt
[i
] == 'e' && loc
!= &XEXP (x
, i
))
894 if (refers_to_regno_p (regno
, endregno
, XEXP (x
, i
), loc
))
897 else if (fmt
[i
] == 'E')
900 for (j
= XVECLEN (x
, i
) - 1; j
>=0; j
--)
901 if (loc
!= &XVECEXP (x
, i
, j
)
902 && refers_to_regno_p (regno
, endregno
, XVECEXP (x
, i
, j
), loc
))
909 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
910 we check if any register number in X conflicts with the relevant register
911 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
912 contains a MEM (we don't bother checking for memory addresses that can't
913 conflict because we expect this to be a rare case. */
916 reg_overlap_mentioned_p (x
, in
)
921 /* Overly conservative. */
922 if (GET_CODE (x
) == STRICT_LOW_PART
)
925 /* If either argument is a constant, then modifying X can not affect IN. */
926 if (CONSTANT_P (x
) || CONSTANT_P (in
))
928 else if (GET_CODE (x
) == SUBREG
)
930 regno
= REGNO (SUBREG_REG (x
));
931 if (regno
< FIRST_PSEUDO_REGISTER
)
932 regno
+= SUBREG_WORD (x
);
934 else if (GET_CODE (x
) == REG
)
936 else if (GET_CODE (x
) == MEM
)
941 if (GET_CODE (in
) == MEM
)
944 fmt
= GET_RTX_FORMAT (GET_CODE (in
));
946 for (i
= GET_RTX_LENGTH (GET_CODE (in
)) - 1; i
>= 0; i
--)
947 if (fmt
[i
] == 'e' && reg_overlap_mentioned_p (x
, XEXP (in
, i
)))
952 else if (GET_CODE (x
) == SCRATCH
|| GET_CODE (x
) == PC
953 || GET_CODE (x
) == CC0
)
954 return reg_mentioned_p (x
, in
);
955 else if (GET_CODE (x
) == PARALLEL
956 && GET_MODE (x
) == BLKmode
)
960 /* If any register in here refers to it
962 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
963 if (reg_overlap_mentioned_p (SET_DEST (XVECEXP (x
, 0, i
)), in
))
970 endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
971 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
973 return refers_to_regno_p (regno
, endregno
, in
, NULL_PTR
);
976 /* Used for communications between the next few functions. */
978 static int reg_set_last_unknown
;
979 static rtx reg_set_last_value
;
980 static int reg_set_last_first_regno
, reg_set_last_last_regno
;
982 /* Called via note_stores from reg_set_last. */
985 reg_set_last_1 (x
, pat
, data
)
988 void *data ATTRIBUTE_UNUSED
;
992 /* If X is not a register, or is not one in the range we care
994 if (GET_CODE (x
) != REG
)
998 last
= first
+ (first
< FIRST_PSEUDO_REGISTER
999 ? HARD_REGNO_NREGS (first
, GET_MODE (x
)) : 1);
1001 if (first
>= reg_set_last_last_regno
1002 || last
<= reg_set_last_first_regno
)
1005 /* If this is a CLOBBER or is some complex LHS, or doesn't modify
1006 exactly the registers we care about, show we don't know the value. */
1007 if (GET_CODE (pat
) == CLOBBER
|| SET_DEST (pat
) != x
1008 || first
!= reg_set_last_first_regno
1009 || last
!= reg_set_last_last_regno
)
1010 reg_set_last_unknown
= 1;
1012 reg_set_last_value
= SET_SRC (pat
);
1015 /* Return the last value to which REG was set prior to INSN. If we can't
1016 find it easily, return 0.
1018 We only return a REG, SUBREG, or constant because it is too hard to
1019 check if a MEM remains unchanged. */
1022 reg_set_last (x
, insn
)
1026 rtx orig_insn
= insn
;
1028 reg_set_last_first_regno
= REGNO (x
);
1030 reg_set_last_last_regno
1031 = reg_set_last_first_regno
1032 + (reg_set_last_first_regno
< FIRST_PSEUDO_REGISTER
1033 ? HARD_REGNO_NREGS (reg_set_last_first_regno
, GET_MODE (x
)) : 1);
1035 reg_set_last_unknown
= 0;
1036 reg_set_last_value
= 0;
1038 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1039 Stop when we reach a label or X is a hard reg and we reach a
1040 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1042 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1044 /* We compare with <= here, because reg_set_last_last_regno
1045 is actually the number of the first reg *not* in X. */
1047 insn
&& GET_CODE (insn
) != CODE_LABEL
1048 && ! (GET_CODE (insn
) == CALL_INSN
1049 && reg_set_last_last_regno
<= FIRST_PSEUDO_REGISTER
);
1050 insn
= PREV_INSN (insn
))
1051 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
1053 note_stores (PATTERN (insn
), reg_set_last_1
, NULL
);
1054 if (reg_set_last_unknown
)
1056 else if (reg_set_last_value
)
1058 if (CONSTANT_P (reg_set_last_value
)
1059 || ((GET_CODE (reg_set_last_value
) == REG
1060 || GET_CODE (reg_set_last_value
) == SUBREG
)
1061 && ! reg_set_between_p (reg_set_last_value
,
1063 return reg_set_last_value
;
1072 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1073 (X would be the pattern of an insn).
1074 FUN receives two arguments:
1075 the REG, MEM, CC0 or PC being stored in or clobbered,
1076 the SET or CLOBBER rtx that does the store.
1078 If the item being stored in or clobbered is a SUBREG of a hard register,
1079 the SUBREG will be passed. */
1082 note_stores (x
, fun
, data
)
1084 void (*fun
) PROTO ((rtx
, rtx
, void *));
1087 if ((GET_CODE (x
) == SET
|| GET_CODE (x
) == CLOBBER
))
1089 register rtx dest
= SET_DEST (x
);
1090 while ((GET_CODE (dest
) == SUBREG
1091 && (GET_CODE (SUBREG_REG (dest
)) != REG
1092 || REGNO (SUBREG_REG (dest
)) >= FIRST_PSEUDO_REGISTER
))
1093 || GET_CODE (dest
) == ZERO_EXTRACT
1094 || GET_CODE (dest
) == SIGN_EXTRACT
1095 || GET_CODE (dest
) == STRICT_LOW_PART
)
1096 dest
= XEXP (dest
, 0);
1098 if (GET_CODE (dest
) == PARALLEL
1099 && GET_MODE (dest
) == BLKmode
)
1102 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1103 (*fun
) (SET_DEST (XVECEXP (dest
, 0, i
)), x
, data
);
1106 (*fun
) (dest
, x
, data
);
1108 else if (GET_CODE (x
) == PARALLEL
)
1111 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1113 register rtx y
= XVECEXP (x
, 0, i
);
1114 if (GET_CODE (y
) == SET
|| GET_CODE (y
) == CLOBBER
)
1116 register rtx dest
= SET_DEST (y
);
1117 while ((GET_CODE (dest
) == SUBREG
1118 && (GET_CODE (SUBREG_REG (dest
)) != REG
1119 || (REGNO (SUBREG_REG (dest
))
1120 >= FIRST_PSEUDO_REGISTER
)))
1121 || GET_CODE (dest
) == ZERO_EXTRACT
1122 || GET_CODE (dest
) == SIGN_EXTRACT
1123 || GET_CODE (dest
) == STRICT_LOW_PART
)
1124 dest
= XEXP (dest
, 0);
1125 if (GET_CODE (dest
) == PARALLEL
1126 && GET_MODE (dest
) == BLKmode
)
1129 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1130 (*fun
) (SET_DEST (XVECEXP (dest
, 0, i
)), y
, data
);
1133 (*fun
) (dest
, y
, data
);
1139 /* Return nonzero if X's old contents don't survive after INSN.
1140 This will be true if X is (cc0) or if X is a register and
1141 X dies in INSN or because INSN entirely sets X.
1143 "Entirely set" means set directly and not through a SUBREG,
1144 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1145 Likewise, REG_INC does not count.
1147 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1148 but for this use that makes no difference, since regs don't overlap
1149 during their lifetimes. Therefore, this function may be used
1150 at any time after deaths have been computed (in flow.c).
1152 If REG is a hard reg that occupies multiple machine registers, this
1153 function will only return 1 if each of those registers will be replaced
1157 dead_or_set_p (insn
, x
)
1161 register int regno
, last_regno
;
1164 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1165 if (GET_CODE (x
) == CC0
)
1168 if (GET_CODE (x
) != REG
)
1172 last_regno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
1173 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
)) - 1);
1175 for (i
= regno
; i
<= last_regno
; i
++)
1176 if (! dead_or_set_regno_p (insn
, i
))
1182 /* Utility function for dead_or_set_p to check an individual register. Also
1183 called from flow.c. */
1186 dead_or_set_regno_p (insn
, test_regno
)
1190 int regno
, endregno
;
1193 /* See if there is a death note for something that includes
1195 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1197 if (REG_NOTE_KIND (link
) != REG_DEAD
1198 || GET_CODE (XEXP (link
, 0)) != REG
)
1201 regno
= REGNO (XEXP (link
, 0));
1202 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1203 : regno
+ HARD_REGNO_NREGS (regno
,
1204 GET_MODE (XEXP (link
, 0))));
1206 if (test_regno
>= regno
&& test_regno
< endregno
)
1210 if (GET_CODE (insn
) == CALL_INSN
1211 && find_regno_fusage (insn
, CLOBBER
, test_regno
))
1214 if (GET_CODE (PATTERN (insn
)) == SET
)
1216 rtx dest
= SET_DEST (PATTERN (insn
));
1218 /* A value is totally replaced if it is the destination or the
1219 destination is a SUBREG of REGNO that does not change the number of
1221 if (GET_CODE (dest
) == SUBREG
1222 && (((GET_MODE_SIZE (GET_MODE (dest
))
1223 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1224 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1225 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1226 dest
= SUBREG_REG (dest
);
1228 if (GET_CODE (dest
) != REG
)
1231 regno
= REGNO (dest
);
1232 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1233 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1235 return (test_regno
>= regno
&& test_regno
< endregno
);
1237 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1241 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1243 rtx body
= XVECEXP (PATTERN (insn
), 0, i
);
1245 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == CLOBBER
)
1247 rtx dest
= SET_DEST (body
);
1249 if (GET_CODE (dest
) == SUBREG
1250 && (((GET_MODE_SIZE (GET_MODE (dest
))
1251 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1252 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1253 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1254 dest
= SUBREG_REG (dest
);
1256 if (GET_CODE (dest
) != REG
)
1259 regno
= REGNO (dest
);
1260 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1261 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1263 if (test_regno
>= regno
&& test_regno
< endregno
)
1272 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1273 If DATUM is nonzero, look for one whose datum is DATUM. */
1276 find_reg_note (insn
, kind
, datum
)
1283 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1284 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
1287 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1288 if (REG_NOTE_KIND (link
) == kind
1289 && (datum
== 0 || datum
== XEXP (link
, 0)))
1294 /* Return the reg-note of kind KIND in insn INSN which applies to register
1295 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1296 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1297 it might be the case that the note overlaps REGNO. */
1300 find_regno_note (insn
, kind
, regno
)
1307 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1308 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
1311 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1312 if (REG_NOTE_KIND (link
) == kind
1313 /* Verify that it is a register, so that scratch and MEM won't cause a
1315 && GET_CODE (XEXP (link
, 0)) == REG
1316 && REGNO (XEXP (link
, 0)) <= regno
1317 && ((REGNO (XEXP (link
, 0))
1318 + (REGNO (XEXP (link
, 0)) >= FIRST_PSEUDO_REGISTER
? 1
1319 : HARD_REGNO_NREGS (REGNO (XEXP (link
, 0)),
1320 GET_MODE (XEXP (link
, 0)))))
1326 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1327 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1330 find_reg_fusage (insn
, code
, datum
)
1335 /* If it's not a CALL_INSN, it can't possibly have a
1336 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1337 if (GET_CODE (insn
) != CALL_INSN
)
1343 if (GET_CODE (datum
) != REG
)
1347 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1349 link
= XEXP (link
, 1))
1350 if (GET_CODE (XEXP (link
, 0)) == code
1351 && rtx_equal_p (datum
, SET_DEST (XEXP (link
, 0))))
1356 register int regno
= REGNO (datum
);
1358 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1359 to pseudo registers, so don't bother checking. */
1361 if (regno
< FIRST_PSEUDO_REGISTER
)
1363 int end_regno
= regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (datum
));
1366 for (i
= regno
; i
< end_regno
; i
++)
1367 if (find_regno_fusage (insn
, code
, i
))
1375 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1376 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1379 find_regno_fusage (insn
, code
, regno
)
1386 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1387 to pseudo registers, so don't bother checking. */
1389 if (regno
>= FIRST_PSEUDO_REGISTER
1390 || GET_CODE (insn
) != CALL_INSN
)
1393 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
1395 register int regnote
;
1396 register rtx op
, reg
;
1398 if (GET_CODE (op
= XEXP (link
, 0)) == code
1399 && GET_CODE (reg
= XEXP (op
, 0)) == REG
1400 && (regnote
= REGNO (reg
)) <= regno
1401 && regnote
+ HARD_REGNO_NREGS (regnote
, GET_MODE (reg
)) > regno
)
1408 /* Remove register note NOTE from the REG_NOTES of INSN. */
1411 remove_note (insn
, note
)
1417 if (note
== NULL_RTX
)
1420 if (REG_NOTES (insn
) == note
)
1422 REG_NOTES (insn
) = XEXP (note
, 1);
1426 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1427 if (XEXP (link
, 1) == note
)
1429 XEXP (link
, 1) = XEXP (note
, 1);
1436 /* Search LISTP (an EXPR_LIST) for NODE and remove NODE from the list
1439 A simple equality test is used to determine if NODE is on the
1443 remove_node_from_expr_list (node
, listp
)
1448 rtx prev
= NULL_RTX
;
1452 if (node
== XEXP (temp
, 0))
1454 /* Splice the node out of the list. */
1456 XEXP (prev
, 1) = XEXP (temp
, 1);
1458 *listp
= XEXP (temp
, 1);
1462 temp
= XEXP (temp
, 1);
1466 /* Nonzero if X contains any volatile instructions. These are instructions
1467 which may cause unpredictable machine state instructions, and thus no
1468 instructions should be moved or combined across them. This includes
1469 only volatile asms and UNSPEC_VOLATILE instructions. */
1475 register RTX_CODE code
;
1477 code
= GET_CODE (x
);
1497 case UNSPEC_VOLATILE
:
1498 /* case TRAP_IF: This isn't clear yet. */
1502 if (MEM_VOLATILE_P (x
))
1509 /* Recursively scan the operands of this expression. */
1512 register const char *fmt
= GET_RTX_FORMAT (code
);
1515 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1519 if (volatile_insn_p (XEXP (x
, i
)))
1525 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1526 if (volatile_insn_p (XVECEXP (x
, i
, j
)))
1534 /* Nonzero if X contains any volatile memory references
1535 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1541 register RTX_CODE code
;
1543 code
= GET_CODE (x
);
1562 case UNSPEC_VOLATILE
:
1563 /* case TRAP_IF: This isn't clear yet. */
1568 if (MEM_VOLATILE_P (x
))
1575 /* Recursively scan the operands of this expression. */
1578 register const char *fmt
= GET_RTX_FORMAT (code
);
1581 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1585 if (volatile_refs_p (XEXP (x
, i
)))
1591 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1592 if (volatile_refs_p (XVECEXP (x
, i
, j
)))
1600 /* Similar to above, except that it also rejects register pre- and post-
1607 register RTX_CODE code
;
1609 code
= GET_CODE (x
);
1627 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1628 when some combination can't be done. If we see one, don't think
1629 that we can simplify the expression. */
1630 return (GET_MODE (x
) != VOIDmode
);
1637 case UNSPEC_VOLATILE
:
1638 /* case TRAP_IF: This isn't clear yet. */
1643 if (MEM_VOLATILE_P (x
))
1650 /* Recursively scan the operands of this expression. */
1653 register const char *fmt
= GET_RTX_FORMAT (code
);
1656 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1660 if (side_effects_p (XEXP (x
, i
)))
1666 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1667 if (side_effects_p (XVECEXP (x
, i
, j
)))
1675 /* Return nonzero if evaluating rtx X might cause a trap. */
1687 code
= GET_CODE (x
);
1690 /* Handle these cases quickly. */
1702 /* Conditional trap can trap! */
1703 case UNSPEC_VOLATILE
:
1707 /* Memory ref can trap unless it's a static var or a stack slot. */
1709 return rtx_addr_can_trap_p (XEXP (x
, 0));
1711 /* Division by a non-constant might trap. */
1716 if (! CONSTANT_P (XEXP (x
, 1))
1717 || GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1719 /* This was const0_rtx, but by not using that,
1720 we can link this file into other programs. */
1721 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
&& INTVAL (XEXP (x
, 1)) == 0)
1726 /* An EXPR_LIST is used to represent a function call. This
1727 certainly may trap. */
1731 /* Any floating arithmetic may trap. */
1732 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1736 fmt
= GET_RTX_FORMAT (code
);
1737 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1741 if (may_trap_p (XEXP (x
, i
)))
1744 else if (fmt
[i
] == 'E')
1747 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1748 if (may_trap_p (XVECEXP (x
, i
, j
)))
1755 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1756 i.e., an inequality. */
1759 inequality_comparisons_p (x
)
1762 register const char *fmt
;
1763 register int len
, i
;
1764 register enum rtx_code code
= GET_CODE (x
);
1793 len
= GET_RTX_LENGTH (code
);
1794 fmt
= GET_RTX_FORMAT (code
);
1796 for (i
= 0; i
< len
; i
++)
1800 if (inequality_comparisons_p (XEXP (x
, i
)))
1803 else if (fmt
[i
] == 'E')
1806 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1807 if (inequality_comparisons_p (XVECEXP (x
, i
, j
)))
1815 /* Replace any occurrence of FROM in X with TO. The function does
1816 not enter into CONST_DOUBLE for the replace.
1818 Note that copying is not done so X must not be shared unless all copies
1819 are to be modified. */
1822 replace_rtx (x
, from
, to
)
1826 register const char *fmt
;
1828 /* The following prevents loops occurrence when we change MEM in
1829 CONST_DOUBLE onto the same CONST_DOUBLE. */
1830 if (x
!= 0 && GET_CODE (x
) == CONST_DOUBLE
)
1836 /* Allow this function to make replacements in EXPR_LISTs. */
1840 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
1841 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
1844 XEXP (x
, i
) = replace_rtx (XEXP (x
, i
), from
, to
);
1845 else if (fmt
[i
] == 'E')
1846 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1847 XVECEXP (x
, i
, j
) = replace_rtx (XVECEXP (x
, i
, j
), from
, to
);
1853 /* Throughout the rtx X, replace many registers according to REG_MAP.
1854 Return the replacement for X (which may be X with altered contents).
1855 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
1856 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
1858 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
1859 should not be mapped to pseudos or vice versa since validate_change
1862 If REPLACE_DEST is 1, replacements are also done in destinations;
1863 otherwise, only sources are replaced. */
1866 replace_regs (x
, reg_map
, nregs
, replace_dest
)
1872 register enum rtx_code code
;
1874 register const char *fmt
;
1879 code
= GET_CODE (x
);
1893 /* Verify that the register has an entry before trying to access it. */
1894 if (REGNO (x
) < nregs
&& reg_map
[REGNO (x
)] != 0)
1896 /* SUBREGs can't be shared. Always return a copy to ensure that if
1897 this replacement occurs more than once then each instance will
1898 get distinct rtx. */
1899 if (GET_CODE (reg_map
[REGNO (x
)]) == SUBREG
)
1900 return copy_rtx (reg_map
[REGNO (x
)]);
1901 return reg_map
[REGNO (x
)];
1906 /* Prevent making nested SUBREGs. */
1907 if (GET_CODE (SUBREG_REG (x
)) == REG
&& REGNO (SUBREG_REG (x
)) < nregs
1908 && reg_map
[REGNO (SUBREG_REG (x
))] != 0
1909 && GET_CODE (reg_map
[REGNO (SUBREG_REG (x
))]) == SUBREG
)
1911 rtx map_val
= reg_map
[REGNO (SUBREG_REG (x
))];
1912 rtx map_inner
= SUBREG_REG (map_val
);
1914 if (GET_MODE (x
) == GET_MODE (map_inner
))
1918 /* We cannot call gen_rtx here since we may be linked with
1920 /* Let's try clobbering the incoming SUBREG and see
1921 if this is really safe. */
1922 SUBREG_REG (x
) = map_inner
;
1923 SUBREG_WORD (x
) += SUBREG_WORD (map_val
);
1926 rtx
new = rtx_alloc (SUBREG
);
1927 PUT_MODE (new, GET_MODE (x
));
1928 SUBREG_REG (new) = map_inner
;
1929 SUBREG_WORD (new) = SUBREG_WORD (x
) + SUBREG_WORD (map_val
);
1937 SET_DEST (x
) = replace_regs (SET_DEST (x
), reg_map
, nregs
, 0);
1939 else if (GET_CODE (SET_DEST (x
)) == MEM
1940 || GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
1941 /* Even if we are not to replace destinations, replace register if it
1942 is CONTAINED in destination (destination is memory or
1943 STRICT_LOW_PART). */
1944 XEXP (SET_DEST (x
), 0) = replace_regs (XEXP (SET_DEST (x
), 0),
1946 else if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
1947 /* Similarly, for ZERO_EXTRACT we replace all operands. */
1950 SET_SRC (x
) = replace_regs (SET_SRC (x
), reg_map
, nregs
, 0);
1957 fmt
= GET_RTX_FORMAT (code
);
1958 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1961 XEXP (x
, i
) = replace_regs (XEXP (x
, i
), reg_map
, nregs
, replace_dest
);
1965 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1966 XVECEXP (x
, i
, j
) = replace_regs (XVECEXP (x
, i
, j
), reg_map
,
1967 nregs
, replace_dest
);
1973 /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is
1974 not in the constant pool and not in the condition of an IF_THEN_ELSE. */
1977 jmp_uses_reg_or_mem (x
)
1980 enum rtx_code code
= GET_CODE (x
);
1995 return ! (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1996 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)));
1999 return (jmp_uses_reg_or_mem (XEXP (x
, 1))
2000 || jmp_uses_reg_or_mem (XEXP (x
, 2)));
2002 case PLUS
: case MINUS
: case MULT
:
2003 return (jmp_uses_reg_or_mem (XEXP (x
, 0))
2004 || jmp_uses_reg_or_mem (XEXP (x
, 1)));
2010 fmt
= GET_RTX_FORMAT (code
);
2011 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2014 && jmp_uses_reg_or_mem (XEXP (x
, i
)))
2018 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2019 if (jmp_uses_reg_or_mem (XVECEXP (x
, i
, j
)))
2026 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2028 Tablejumps and casesi insns are not considered indirect jumps;
2029 we can recognize them by a (use (lael_ref)). */
2032 computed_jump_p (insn
)
2036 if (GET_CODE (insn
) == JUMP_INSN
)
2038 rtx pat
= PATTERN (insn
);
2040 if (GET_CODE (pat
) == PARALLEL
)
2042 int len
= XVECLEN (pat
, 0);
2043 int has_use_labelref
= 0;
2045 for (i
= len
- 1; i
>= 0; i
--)
2046 if (GET_CODE (XVECEXP (pat
, 0, i
)) == USE
2047 && (GET_CODE (XEXP (XVECEXP (pat
, 0, i
), 0))
2049 has_use_labelref
= 1;
2051 if (! has_use_labelref
)
2052 for (i
= len
- 1; i
>= 0; i
--)
2053 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
2054 && SET_DEST (XVECEXP (pat
, 0, i
)) == pc_rtx
2055 && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat
, 0, i
))))
2058 else if (GET_CODE (pat
) == SET
2059 && SET_DEST (pat
) == pc_rtx
2060 && jmp_uses_reg_or_mem (SET_SRC (pat
)))
2066 /* Traverse X via depth-first search, calling F for each
2067 sub-expression (including X itself). F is also passed the DATA.
2068 If F returns -1, do not traverse sub-expressions, but continue
2069 traversing the rest of the tree. If F ever returns any other
2070 non-zero value, stop the traversal, and return the value returned
2071 by F. Otherwise, return 0. This function does not traverse inside
2072 tree structure that contains RTX_EXPRs, or into sub-expressions
2073 whose format code is `0' since it is not known whether or not those
2074 codes are actually RTL.
2076 This routine is very general, and could (should?) be used to
2077 implement many of the other routines in this file. */
2080 for_each_rtx (x
, f
, data
)
2091 result
= (*f
)(x
, data
);
2093 /* Do not traverse sub-expressions. */
2095 else if (result
!= 0)
2096 /* Stop the traversal. */
2100 /* There are no sub-expressions. */
2103 length
= GET_RTX_LENGTH (GET_CODE (*x
));
2104 format
= GET_RTX_FORMAT (GET_CODE (*x
));
2106 for (i
= 0; i
< length
; ++i
)
2111 result
= for_each_rtx (&XEXP (*x
, i
), f
, data
);
2118 if (XVEC (*x
, i
) != 0)
2121 for (j
= 0; j
< XVECLEN (*x
, i
); ++j
)
2123 result
= for_each_rtx (&XVECEXP (*x
, i
, j
), f
, data
);
2131 /* Nothing to do. */
2140 /* Searches X for any reference to REGNO, returning the rtx of the
2141 reference found if any. Otherwise, returns NULL_RTX. */
2144 regno_use_in (regno
, x
)
2148 register const char *fmt
;
2152 if (GET_CODE (x
) == REG
&& REGNO (x
) == regno
)
2155 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2156 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2160 if ((tem
= regno_use_in (regno
, XEXP (x
, i
))))
2163 else if (fmt
[i
] == 'E')
2164 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2165 if ((tem
= regno_use_in (regno
, XVECEXP (x
, i
, j
))))
2173 /* Return 1 if X is an autoincrement side effect and the register is
2174 not the stack pointer. */
2179 switch (GET_CODE (x
))
2187 /* There are no REG_INC notes for SP. */
2188 if (XEXP (x
, 0) != stack_pointer_rtx
)
2196 /* Return 1 if the sequence of instructions beginning with FROM and up
2197 to and including TO is safe to move. If NEW_TO is non-NULL, and
2198 the sequence is not already safe to move, but can be easily
2199 extended to a sequence which is safe, then NEW_TO will point to the
2200 end of the extended sequence.
2202 For now, this function only checks that the region contains whole
2203 exception regiongs, but it could be extended to check additional
2204 conditions as well. */
2207 insns_safe_to_move_p (from
, to
, new_to
)
2212 int eh_region_count
= 0;
2216 /* By default, assume the end of the region will be what was
2223 if (GET_CODE (r
) == NOTE
)
2225 switch (NOTE_LINE_NUMBER (r
))
2227 case NOTE_INSN_EH_REGION_BEG
:
2231 case NOTE_INSN_EH_REGION_END
:
2232 if (eh_region_count
== 0)
2233 /* This sequence of instructions contains the end of
2234 an exception region, but not he beginning. Moving
2235 it will cause chaos. */
2246 /* If we've passed TO, and we see a non-note instruction, we
2247 can't extend the sequence to a movable sequence. */
2253 /* It's OK to move the sequence if there were matched sets of
2254 exception region notes. */
2255 return eh_region_count
== 0;
2260 /* It's OK to move the sequence if there were matched sets of
2261 exception region notes. */
2262 if (past_to_p
&& eh_region_count
== 0)
2268 /* Go to the next instruction. */