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 reg_set_last_1 PARAMS ((rtx, rtx, void *));
32 /* Forward declarations */
33 static int jmp_uses_reg_or_mem PARAMS ((rtx));
35 /* Bit flags that specify the machine subtype we are compiling for.
36 Bits are tested using macros TARGET_... defined in the tm.h file
37 and set by `-m...' switches. Must be defined in rtlanal.c. */
41 /* Return 1 if the value of X is unstable
42 (would be different at a different point in the program).
43 The frame pointer, arg pointer, etc. are considered stable
44 (within one function) and so is anything marked `unchanging'. */
50 register RTX_CODE code = GET_CODE (x);
52 register const char *fmt;
55 return ! RTX_UNCHANGING_P (x);
60 if (code == CONST || code == CONST_INT)
64 return ! (REGNO (x) == FRAME_POINTER_REGNUM
65 || REGNO (x) == HARD_FRAME_POINTER_REGNUM
66 || REGNO (x) == ARG_POINTER_REGNUM
67 || RTX_UNCHANGING_P (x));
69 fmt = GET_RTX_FORMAT (code);
70 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
72 if (rtx_unstable_p (XEXP (x, i)))
77 /* Return 1 if X has a value that can vary even between two
78 executions of the program. 0 means X can be compared reliably
79 against certain constants or near-constants.
80 The frame pointer and the arg pointer are considered constant. */
86 register RTX_CODE code = GET_CODE (x);
88 register const char *fmt;
104 /* Note that we have to test for the actual rtx used for the frame
105 and arg pointers and not just the register number in case we have
106 eliminated the frame and/or arg pointer and are using it
108 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
109 || x == arg_pointer_rtx || x == pic_offset_table_rtx);
112 /* The operand 0 of a LO_SUM is considered constant
113 (in fact is it related specifically to operand 1). */
114 return rtx_varies_p (XEXP (x, 1));
120 fmt = GET_RTX_FORMAT (code);
121 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
123 if (rtx_varies_p (XEXP (x, i)))
128 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
131 rtx_addr_can_trap_p (x)
134 register enum rtx_code code = GET_CODE (x);
140 /* SYMBOL_REF is problematic due to the possible presence of
141 a #pragma weak, but to say that loads from symbols can trap is
142 *very* costly. It's not at all clear what's best here. For
143 now, we ignore the impact of #pragma weak. */
147 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
148 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
149 || x == stack_pointer_rtx || x == arg_pointer_rtx);
152 return rtx_addr_can_trap_p (XEXP (x, 0));
155 /* An address is assumed not to trap if it is an address that can't
156 trap plus a constant integer. */
157 return (rtx_addr_can_trap_p (XEXP (x, 0))
158 || GET_CODE (XEXP (x, 1)) != CONST_INT);
161 return rtx_addr_can_trap_p (XEXP (x, 1));
167 /* If it isn't one of the case above, it can cause a trap. */
171 /* Return 1 if X refers to a memory location whose address
172 cannot be compared reliably with constant addresses,
173 or if X refers to a BLKmode memory object. */
176 rtx_addr_varies_p (x)
179 register enum rtx_code code;
181 register const char *fmt;
188 return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0));
190 fmt = GET_RTX_FORMAT (code);
191 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
194 if (rtx_addr_varies_p (XEXP (x, i)))
197 else if (fmt[i] == 'E')
200 for (j = 0; j < XVECLEN (x, i); j++)
201 if (rtx_addr_varies_p (XVECEXP (x, i, j)))
207 /* Return the value of the integer term in X, if one is apparent;
209 Only obvious integer terms are detected.
210 This is used in cse.c with the `related_value' field.*/
216 if (GET_CODE (x) == CONST)
219 if (GET_CODE (x) == MINUS
220 && GET_CODE (XEXP (x, 1)) == CONST_INT)
221 return - INTVAL (XEXP (x, 1));
222 if (GET_CODE (x) == PLUS
223 && GET_CODE (XEXP (x, 1)) == CONST_INT)
224 return INTVAL (XEXP (x, 1));
228 /* If X is a constant, return the value sans apparent integer term;
230 Only obvious integer terms are detected. */
233 get_related_value (x)
236 if (GET_CODE (x) != CONST)
239 if (GET_CODE (x) == PLUS
240 && GET_CODE (XEXP (x, 1)) == CONST_INT)
242 else if (GET_CODE (x) == MINUS
243 && GET_CODE (XEXP (x, 1)) == CONST_INT)
248 /* Nonzero if register REG appears somewhere within IN.
249 Also works if REG is not a register; in this case it checks
250 for a subexpression of IN that is Lisp "equal" to REG. */
253 reg_mentioned_p (reg, in)
254 register rtx reg, in;
256 register const char *fmt;
258 register enum rtx_code code;
266 if (GET_CODE (in) == LABEL_REF)
267 return reg == XEXP (in, 0);
269 code = GET_CODE (in);
273 /* Compare registers by number. */
275 return GET_CODE (reg) == REG && REGNO (in) == REGNO (reg);
277 /* These codes have no constituent expressions
285 return GET_CODE (reg) == CONST_INT && INTVAL (in) == INTVAL (reg);
288 /* These are kept unique for a given value. */
295 if (GET_CODE (reg) == code && rtx_equal_p (reg, in))
298 fmt = GET_RTX_FORMAT (code);
300 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
305 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
306 if (reg_mentioned_p (reg, XVECEXP (in, i, j)))
309 else if (fmt[i] == 'e'
310 && reg_mentioned_p (reg, XEXP (in, i)))
316 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
317 no CODE_LABEL insn. */
320 no_labels_between_p (beg, end)
324 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
325 if (GET_CODE (p) == CODE_LABEL)
330 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
331 no JUMP_INSN insn. */
334 no_jumps_between_p (beg, end)
338 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
339 if (GET_CODE (p) == JUMP_INSN)
344 /* Nonzero if register REG is used in an insn between
345 FROM_INSN and TO_INSN (exclusive of those two). */
348 reg_used_between_p (reg, from_insn, to_insn)
349 rtx reg, from_insn, to_insn;
353 if (from_insn == to_insn)
356 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
357 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
358 && (reg_overlap_mentioned_p (reg, PATTERN (insn))
359 || (GET_CODE (insn) == CALL_INSN
360 && (find_reg_fusage (insn, USE, reg)
361 || find_reg_fusage (insn, CLOBBER, reg)))))
366 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
367 is entirely replaced by a new value and the only use is as a SET_DEST,
368 we do not consider it a reference. */
371 reg_referenced_p (x, body)
377 switch (GET_CODE (body))
380 if (reg_overlap_mentioned_p (x, SET_SRC (body)))
383 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
384 of a REG that occupies all of the REG, the insn references X if
385 it is mentioned in the destination. */
386 if (GET_CODE (SET_DEST (body)) != CC0
387 && GET_CODE (SET_DEST (body)) != PC
388 && GET_CODE (SET_DEST (body)) != REG
389 && ! (GET_CODE (SET_DEST (body)) == SUBREG
390 && GET_CODE (SUBREG_REG (SET_DEST (body))) == REG
391 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body))))
392 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
393 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body)))
394 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
395 && reg_overlap_mentioned_p (x, SET_DEST (body)))
400 for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
401 if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i)))
408 return reg_overlap_mentioned_p (x, body);
411 return reg_overlap_mentioned_p (x, TRAP_CONDITION (body));
414 case UNSPEC_VOLATILE:
415 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
416 if (reg_overlap_mentioned_p (x, XVECEXP (body, 0, i)))
421 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
422 if (reg_referenced_p (x, XVECEXP (body, 0, i)))
427 if (GET_CODE (XEXP (body, 0)) == MEM)
428 if (reg_overlap_mentioned_p (x, XEXP (XEXP (body, 0), 0)))
437 /* Nonzero if register REG is referenced in an insn between
438 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
442 reg_referenced_between_p (reg, from_insn, to_insn)
443 rtx reg, from_insn, to_insn;
447 if (from_insn == to_insn)
450 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
451 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
452 && (reg_referenced_p (reg, PATTERN (insn))
453 || (GET_CODE (insn) == CALL_INSN
454 && find_reg_fusage (insn, USE, reg))))
459 /* Nonzero if register REG is set or clobbered in an insn between
460 FROM_INSN and TO_INSN (exclusive of those two). */
463 reg_set_between_p (reg, from_insn, to_insn)
464 rtx reg, from_insn, to_insn;
468 if (from_insn == to_insn)
471 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
472 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
473 && reg_set_p (reg, insn))
478 /* Internals of reg_set_between_p. */
480 static rtx reg_set_reg;
481 static int reg_set_flag;
484 reg_set_p_1 (x, pat, data)
486 rtx pat ATTRIBUTE_UNUSED;
487 void *data ATTRIBUTE_UNUSED;
489 /* We don't want to return 1 if X is a MEM that contains a register
490 within REG_SET_REG. */
492 if ((GET_CODE (x) != MEM)
493 && reg_overlap_mentioned_p (reg_set_reg, x))
498 reg_set_p (reg, insn)
503 /* We can be passed an insn or part of one. If we are passed an insn,
504 check if a side-effect of the insn clobbers REG. */
505 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
507 if (FIND_REG_INC_NOTE (insn, reg)
508 || (GET_CODE (insn) == CALL_INSN
509 /* We'd like to test call_used_regs here, but rtlanal.c can't
510 reference that variable due to its use in genattrtab. So
511 we'll just be more conservative.
513 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
514 information holds all clobbered registers. */
515 && ((GET_CODE (reg) == REG
516 && REGNO (reg) < FIRST_PSEUDO_REGISTER)
517 || GET_CODE (reg) == MEM
518 || find_reg_fusage (insn, CLOBBER, reg))))
521 body = PATTERN (insn);
526 note_stores (body, reg_set_p_1, NULL);
530 /* Similar to reg_set_between_p, but check all registers in X. Return 0
531 only if none of them are modified between START and END. Do not
532 consider non-registers one way or the other. */
535 regs_set_between_p (x, start, end)
539 enum rtx_code code = GET_CODE (x);
555 return reg_set_between_p (x, start, end);
561 fmt = GET_RTX_FORMAT (code);
562 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
564 if (fmt[i] == 'e' && regs_set_between_p (XEXP (x, i), start, end))
567 else if (fmt[i] == 'E')
568 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
569 if (regs_set_between_p (XVECEXP (x, i, j), start, end))
576 /* Similar to reg_set_between_p, but check all registers in X. Return 0
577 only if none of them are modified between START and END. Return 1 if
578 X contains a MEM; this routine does not perform any memory aliasing. */
581 modified_between_p (x, start, end)
585 enum rtx_code code = GET_CODE (x);
603 /* If the memory is not constant, assume it is modified. If it is
604 constant, we still have to check the address. */
605 if (! RTX_UNCHANGING_P (x))
610 return reg_set_between_p (x, start, end);
616 fmt = GET_RTX_FORMAT (code);
617 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
619 if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end))
622 else if (fmt[i] == 'E')
623 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
624 if (modified_between_p (XVECEXP (x, i, j), start, end))
631 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
632 of them are modified in INSN. Return 1 if X contains a MEM; this routine
633 does not perform any memory aliasing. */
636 modified_in_p (x, insn)
640 enum rtx_code code = GET_CODE (x);
658 /* If the memory is not constant, assume it is modified. If it is
659 constant, we still have to check the address. */
660 if (! RTX_UNCHANGING_P (x))
665 return reg_set_p (x, insn);
671 fmt = GET_RTX_FORMAT (code);
672 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
674 if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn))
677 else if (fmt[i] == 'E')
678 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
679 if (modified_in_p (XVECEXP (x, i, j), insn))
686 /* Given an INSN, return a SET expression if this insn has only a single SET.
687 It may also have CLOBBERs, USEs, or SET whose output
688 will not be used, which we ignore. */
697 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
700 if (GET_CODE (PATTERN (insn)) == SET)
701 return PATTERN (insn);
703 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
705 for (i = 0, set = 0; i < XVECLEN (PATTERN (insn), 0); i++)
707 rtx sub = XVECEXP (PATTERN (insn), 0, i);
709 switch (GET_CODE (sub))
716 if (! find_reg_note (insn, REG_UNUSED, SET_DEST (sub))
717 || side_effects_p (sub))
736 /* Given an INSN, return nonzero if it has more than one SET, else return
746 /* INSN must be an insn. */
747 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
750 /* Only a PARALLEL can have multiple SETs. */
751 if (GET_CODE (PATTERN (insn)) == PARALLEL)
753 for (i = 0, found = 0; i < XVECLEN (PATTERN (insn), 0); i++)
754 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
756 /* If we have already found a SET, then return now. */
764 /* Either zero or one SET. */
768 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
769 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
770 If the object was modified, if we hit a partial assignment to X, or hit a
771 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
772 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
776 find_last_value (x, pinsn, valid_to, allow_hwreg)
784 for (p = PREV_INSN (*pinsn); p && GET_CODE (p) != CODE_LABEL;
786 if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
788 rtx set = single_set (p);
789 rtx note = find_reg_note (p, REG_EQUAL, NULL_RTX);
791 if (set && rtx_equal_p (x, SET_DEST (set)))
793 rtx src = SET_SRC (set);
795 if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
796 src = XEXP (note, 0);
798 if ((valid_to == NULL_RTX
799 || ! modified_between_p (src, PREV_INSN (p), valid_to))
800 /* Reject hard registers because we don't usually want
801 to use them; we'd rather use a pseudo. */
802 && (! (GET_CODE (src) == REG
803 && REGNO (src) < FIRST_PSEUDO_REGISTER) || allow_hwreg))
810 /* If set in non-simple way, we don't have a value. */
811 if (reg_set_p (x, p))
818 /* Return nonzero if register in range [REGNO, ENDREGNO)
819 appears either explicitly or implicitly in X
820 other than being stored into.
822 References contained within the substructure at LOC do not count.
823 LOC may be zero, meaning don't ignore anything. */
826 refers_to_regno_p (regno, endregno, x, loc)
827 unsigned int regno, endregno;
832 unsigned int x_regno;
837 /* The contents of a REG_NONNEG note is always zero, so we must come here
838 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
849 /* If we modifying the stack, frame, or argument pointer, it will
850 clobber a virtual register. In fact, we could be more precise,
851 but it isn't worth it. */
852 if ((x_regno == STACK_POINTER_REGNUM
853 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
854 || x_regno == ARG_POINTER_REGNUM
856 || x_regno == FRAME_POINTER_REGNUM)
857 && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER)
860 return (endregno > x_regno
861 && regno < x_regno + (x_regno < FIRST_PSEUDO_REGISTER
862 ? HARD_REGNO_NREGS (x_regno, GET_MODE (x))
866 /* If this is a SUBREG of a hard reg, we can see exactly which
867 registers are being modified. Otherwise, handle normally. */
868 if (GET_CODE (SUBREG_REG (x)) == REG
869 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
871 unsigned int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
872 unsigned int inner_endregno
873 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
874 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
876 return endregno > inner_regno && regno < inner_endregno;
882 if (&SET_DEST (x) != loc
883 /* Note setting a SUBREG counts as referring to the REG it is in for
884 a pseudo but not for hard registers since we can
885 treat each word individually. */
886 && ((GET_CODE (SET_DEST (x)) == SUBREG
887 && loc != &SUBREG_REG (SET_DEST (x))
888 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
889 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
890 && refers_to_regno_p (regno, endregno,
891 SUBREG_REG (SET_DEST (x)), loc))
892 || (GET_CODE (SET_DEST (x)) != REG
893 && refers_to_regno_p (regno, endregno, SET_DEST (x), loc))))
896 if (code == CLOBBER || loc == &SET_SRC (x))
905 /* X does not match, so try its subexpressions. */
907 fmt = GET_RTX_FORMAT (code);
908 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
910 if (fmt[i] == 'e' && loc != &XEXP (x, i))
918 if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc))
921 else if (fmt[i] == 'E')
924 for (j = XVECLEN (x, i) - 1; j >=0; j--)
925 if (loc != &XVECEXP (x, i, j)
926 && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc))
933 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
934 we check if any register number in X conflicts with the relevant register
935 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
936 contains a MEM (we don't bother checking for memory addresses that can't
937 conflict because we expect this to be a rare case. */
940 reg_overlap_mentioned_p (x, in)
943 unsigned int regno, endregno;
945 /* Overly conservative. */
946 if (GET_CODE (x) == STRICT_LOW_PART)
949 /* If either argument is a constant, then modifying X can not affect IN. */
950 if (CONSTANT_P (x) || CONSTANT_P (in))
952 else if (GET_CODE (x) == SUBREG)
954 regno = REGNO (SUBREG_REG (x));
955 if (regno < FIRST_PSEUDO_REGISTER)
956 regno += SUBREG_WORD (x);
958 else if (GET_CODE (x) == REG)
960 else if (GET_CODE (x) == MEM)
965 if (GET_CODE (in) == MEM)
968 fmt = GET_RTX_FORMAT (GET_CODE (in));
970 for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--)
971 if (fmt[i] == 'e' && reg_overlap_mentioned_p (x, XEXP (in, i)))
976 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
977 || GET_CODE (x) == CC0)
978 return reg_mentioned_p (x, in);
979 else if (GET_CODE (x) == PARALLEL
980 && GET_MODE (x) == BLKmode)
984 /* If any register in here refers to it
986 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
987 if (reg_overlap_mentioned_p (SET_DEST (XVECEXP (x, 0, i)), in))
994 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
995 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
997 return refers_to_regno_p (regno, endregno, in, NULL_PTR);
1000 /* Used for communications between the next few functions. */
1002 static int reg_set_last_unknown;
1003 static rtx reg_set_last_value;
1004 static unsigned int reg_set_last_first_regno, reg_set_last_last_regno;
1006 /* Called via note_stores from reg_set_last. */
1009 reg_set_last_1 (x, pat, data)
1012 void *data ATTRIBUTE_UNUSED;
1014 unsigned int first, last;
1016 /* If X is not a register, or is not one in the range we care
1018 if (GET_CODE (x) != REG)
1022 last = first + (first < FIRST_PSEUDO_REGISTER
1023 ? HARD_REGNO_NREGS (first, GET_MODE (x)) : 1);
1025 if (first >= reg_set_last_last_regno
1026 || last <= reg_set_last_first_regno)
1029 /* If this is a CLOBBER or is some complex LHS, or doesn't modify
1030 exactly the registers we care about, show we don't know the value. */
1031 if (GET_CODE (pat) == CLOBBER || SET_DEST (pat) != x
1032 || first != reg_set_last_first_regno
1033 || last != reg_set_last_last_regno)
1034 reg_set_last_unknown = 1;
1036 reg_set_last_value = SET_SRC (pat);
1039 /* Return the last value to which REG was set prior to INSN. If we can't
1040 find it easily, return 0.
1042 We only return a REG, SUBREG, or constant because it is too hard to
1043 check if a MEM remains unchanged. */
1046 reg_set_last (x, insn)
1050 rtx orig_insn = insn;
1052 reg_set_last_first_regno = REGNO (x);
1054 reg_set_last_last_regno
1055 = reg_set_last_first_regno
1056 + (reg_set_last_first_regno < FIRST_PSEUDO_REGISTER
1057 ? HARD_REGNO_NREGS (reg_set_last_first_regno, GET_MODE (x)) : 1);
1059 reg_set_last_unknown = 0;
1060 reg_set_last_value = 0;
1062 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1063 Stop when we reach a label or X is a hard reg and we reach a
1064 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1066 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1068 /* We compare with <= here, because reg_set_last_last_regno
1069 is actually the number of the first reg *not* in X. */
1071 insn && GET_CODE (insn) != CODE_LABEL
1072 && ! (GET_CODE (insn) == CALL_INSN
1073 && reg_set_last_last_regno <= FIRST_PSEUDO_REGISTER);
1074 insn = PREV_INSN (insn))
1075 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1077 note_stores (PATTERN (insn), reg_set_last_1, NULL);
1078 if (reg_set_last_unknown)
1080 else if (reg_set_last_value)
1082 if (CONSTANT_P (reg_set_last_value)
1083 || ((GET_CODE (reg_set_last_value) == REG
1084 || GET_CODE (reg_set_last_value) == SUBREG)
1085 && ! reg_set_between_p (reg_set_last_value,
1087 return reg_set_last_value;
1096 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1097 (X would be the pattern of an insn).
1098 FUN receives two arguments:
1099 the REG, MEM, CC0 or PC being stored in or clobbered,
1100 the SET or CLOBBER rtx that does the store.
1102 If the item being stored in or clobbered is a SUBREG of a hard register,
1103 the SUBREG will be passed. */
1106 note_stores (x, fun, data)
1108 void (*fun) PARAMS ((rtx, rtx, void *));
1111 if ((GET_CODE (x) == SET || GET_CODE (x) == CLOBBER))
1113 register rtx dest = SET_DEST (x);
1114 while ((GET_CODE (dest) == SUBREG
1115 && (GET_CODE (SUBREG_REG (dest)) != REG
1116 || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER))
1117 || GET_CODE (dest) == ZERO_EXTRACT
1118 || GET_CODE (dest) == SIGN_EXTRACT
1119 || GET_CODE (dest) == STRICT_LOW_PART)
1120 dest = XEXP (dest, 0);
1122 if (GET_CODE (dest) == PARALLEL
1123 && GET_MODE (dest) == BLKmode)
1126 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
1127 (*fun) (SET_DEST (XVECEXP (dest, 0, i)), x, data);
1130 (*fun) (dest, x, data);
1132 else if (GET_CODE (x) == PARALLEL)
1135 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1137 register rtx y = XVECEXP (x, 0, i);
1138 if (GET_CODE (y) == SET || GET_CODE (y) == CLOBBER)
1140 register rtx dest = SET_DEST (y);
1141 while ((GET_CODE (dest) == SUBREG
1142 && (GET_CODE (SUBREG_REG (dest)) != REG
1143 || (REGNO (SUBREG_REG (dest))
1144 >= FIRST_PSEUDO_REGISTER)))
1145 || GET_CODE (dest) == ZERO_EXTRACT
1146 || GET_CODE (dest) == SIGN_EXTRACT
1147 || GET_CODE (dest) == STRICT_LOW_PART)
1148 dest = XEXP (dest, 0);
1149 if (GET_CODE (dest) == PARALLEL
1150 && GET_MODE (dest) == BLKmode)
1154 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
1155 (*fun) (SET_DEST (XVECEXP (dest, 0, i)), y, data);
1158 (*fun) (dest, y, data);
1164 /* Return nonzero if X's old contents don't survive after INSN.
1165 This will be true if X is (cc0) or if X is a register and
1166 X dies in INSN or because INSN entirely sets X.
1168 "Entirely set" means set directly and not through a SUBREG,
1169 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1170 Likewise, REG_INC does not count.
1172 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1173 but for this use that makes no difference, since regs don't overlap
1174 during their lifetimes. Therefore, this function may be used
1175 at any time after deaths have been computed (in flow.c).
1177 If REG is a hard reg that occupies multiple machine registers, this
1178 function will only return 1 if each of those registers will be replaced
1182 dead_or_set_p (insn, x)
1186 unsigned int regno, last_regno;
1189 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1190 if (GET_CODE (x) == CC0)
1193 if (GET_CODE (x) != REG)
1197 last_regno = (regno >= FIRST_PSEUDO_REGISTER ? regno
1198 : regno + HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1);
1200 for (i = regno; i <= last_regno; i++)
1201 if (! dead_or_set_regno_p (insn, i))
1207 /* Utility function for dead_or_set_p to check an individual register. Also
1208 called from flow.c. */
1211 dead_or_set_regno_p (insn, test_regno)
1213 unsigned int test_regno;
1215 unsigned int regno, endregno;
1218 /* See if there is a death note for something that includes
1220 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1222 if (REG_NOTE_KIND (link) != REG_DEAD
1223 || GET_CODE (XEXP (link, 0)) != REG)
1226 regno = REGNO (XEXP (link, 0));
1227 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1228 : regno + HARD_REGNO_NREGS (regno,
1229 GET_MODE (XEXP (link, 0))));
1231 if (test_regno >= regno && test_regno < endregno)
1235 if (GET_CODE (insn) == CALL_INSN
1236 && find_regno_fusage (insn, CLOBBER, test_regno))
1239 if (GET_CODE (PATTERN (insn)) == SET)
1241 rtx dest = SET_DEST (PATTERN (insn));
1243 /* A value is totally replaced if it is the destination or the
1244 destination is a SUBREG of REGNO that does not change the number of
1246 if (GET_CODE (dest) == SUBREG
1247 && (((GET_MODE_SIZE (GET_MODE (dest))
1248 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1249 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1250 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1251 dest = SUBREG_REG (dest);
1253 if (GET_CODE (dest) != REG)
1256 regno = REGNO (dest);
1257 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1258 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1260 return (test_regno >= regno && test_regno < endregno);
1262 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
1266 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1268 rtx body = XVECEXP (PATTERN (insn), 0, i);
1270 if (GET_CODE (body) == SET || GET_CODE (body) == CLOBBER)
1272 rtx dest = SET_DEST (body);
1274 if (GET_CODE (dest) == SUBREG
1275 && (((GET_MODE_SIZE (GET_MODE (dest))
1276 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1277 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1278 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1279 dest = SUBREG_REG (dest);
1281 if (GET_CODE (dest) != REG)
1284 regno = REGNO (dest);
1285 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1286 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1288 if (test_regno >= regno && test_regno < endregno)
1297 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1298 If DATUM is nonzero, look for one whose datum is DATUM. */
1301 find_reg_note (insn, kind, datum)
1308 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1309 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
1312 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1313 if (REG_NOTE_KIND (link) == kind
1314 && (datum == 0 || datum == XEXP (link, 0)))
1319 /* Return the reg-note of kind KIND in insn INSN which applies to register
1320 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1321 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1322 it might be the case that the note overlaps REGNO. */
1325 find_regno_note (insn, kind, regno)
1332 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1333 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
1336 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1337 if (REG_NOTE_KIND (link) == kind
1338 /* Verify that it is a register, so that scratch and MEM won't cause a
1340 && GET_CODE (XEXP (link, 0)) == REG
1341 && REGNO (XEXP (link, 0)) <= regno
1342 && ((REGNO (XEXP (link, 0))
1343 + (REGNO (XEXP (link, 0)) >= FIRST_PSEUDO_REGISTER ? 1
1344 : HARD_REGNO_NREGS (REGNO (XEXP (link, 0)),
1345 GET_MODE (XEXP (link, 0)))))
1351 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1352 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1355 find_reg_fusage (insn, code, datum)
1360 /* If it's not a CALL_INSN, it can't possibly have a
1361 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1362 if (GET_CODE (insn) != CALL_INSN)
1368 if (GET_CODE (datum) != REG)
1372 for (link = CALL_INSN_FUNCTION_USAGE (insn);
1374 link = XEXP (link, 1))
1375 if (GET_CODE (XEXP (link, 0)) == code
1376 && rtx_equal_p (datum, SET_DEST (XEXP (link, 0))))
1381 unsigned int regno = REGNO (datum);
1383 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1384 to pseudo registers, so don't bother checking. */
1386 if (regno < FIRST_PSEUDO_REGISTER)
1388 unsigned int end_regno
1389 = regno + HARD_REGNO_NREGS (regno, GET_MODE (datum));
1392 for (i = regno; i < end_regno; i++)
1393 if (find_regno_fusage (insn, code, i))
1401 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1402 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1405 find_regno_fusage (insn, code, regno)
1412 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1413 to pseudo registers, so don't bother checking. */
1415 if (regno >= FIRST_PSEUDO_REGISTER
1416 || GET_CODE (insn) != CALL_INSN )
1419 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
1421 unsigned int regnote;
1424 if (GET_CODE (op = XEXP (link, 0)) == code
1425 && GET_CODE (reg = XEXP (op, 0)) == REG
1426 && (regnote = REGNO (reg)) <= regno
1427 && regnote + HARD_REGNO_NREGS (regnote, GET_MODE (reg)) > regno)
1434 /* Remove register note NOTE from the REG_NOTES of INSN. */
1437 remove_note (insn, note)
1443 if (note == NULL_RTX)
1446 if (REG_NOTES (insn) == note)
1448 REG_NOTES (insn) = XEXP (note, 1);
1452 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1453 if (XEXP (link, 1) == note)
1455 XEXP (link, 1) = XEXP (note, 1);
1462 /* Search LISTP (an EXPR_LIST) for NODE and remove NODE from the list
1465 A simple equality test is used to determine if NODE is on the
1469 remove_node_from_expr_list (node, listp)
1474 rtx prev = NULL_RTX;
1478 if (node == XEXP (temp, 0))
1480 /* Splice the node out of the list. */
1482 XEXP (prev, 1) = XEXP (temp, 1);
1484 *listp = XEXP (temp, 1);
1488 temp = XEXP (temp, 1);
1492 /* Nonzero if X contains any volatile instructions. These are instructions
1493 which may cause unpredictable machine state instructions, and thus no
1494 instructions should be moved or combined across them. This includes
1495 only volatile asms and UNSPEC_VOLATILE instructions. */
1501 register RTX_CODE code;
1503 code = GET_CODE (x);
1523 case UNSPEC_VOLATILE:
1524 /* case TRAP_IF: This isn't clear yet. */
1528 if (MEM_VOLATILE_P (x))
1535 /* Recursively scan the operands of this expression. */
1538 register const char *fmt = GET_RTX_FORMAT (code);
1541 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1545 if (volatile_insn_p (XEXP (x, i)))
1548 else if (fmt[i] == 'E')
1551 for (j = 0; j < XVECLEN (x, i); j++)
1552 if (volatile_insn_p (XVECEXP (x, i, j)))
1560 /* Nonzero if X contains any volatile memory references
1561 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1567 register RTX_CODE code;
1569 code = GET_CODE (x);
1588 case UNSPEC_VOLATILE:
1589 /* case TRAP_IF: This isn't clear yet. */
1594 if (MEM_VOLATILE_P (x))
1601 /* Recursively scan the operands of this expression. */
1604 register const char *fmt = GET_RTX_FORMAT (code);
1607 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1611 if (volatile_refs_p (XEXP (x, i)))
1614 else if (fmt[i] == 'E')
1617 for (j = 0; j < XVECLEN (x, i); j++)
1618 if (volatile_refs_p (XVECEXP (x, i, j)))
1626 /* Similar to above, except that it also rejects register pre- and post-
1633 register RTX_CODE code;
1635 code = GET_CODE (x);
1653 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1654 when some combination can't be done. If we see one, don't think
1655 that we can simplify the expression. */
1656 return (GET_MODE (x) != VOIDmode);
1663 case UNSPEC_VOLATILE:
1664 /* case TRAP_IF: This isn't clear yet. */
1669 if (MEM_VOLATILE_P (x))
1676 /* Recursively scan the operands of this expression. */
1679 register const char *fmt = GET_RTX_FORMAT (code);
1682 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1686 if (side_effects_p (XEXP (x, i)))
1689 else if (fmt[i] == 'E')
1692 for (j = 0; j < XVECLEN (x, i); j++)
1693 if (side_effects_p (XVECEXP (x, i, j)))
1701 /* Return nonzero if evaluating rtx X might cause a trap. */
1713 code = GET_CODE (x);
1716 /* Handle these cases quickly. */
1728 /* Conditional trap can trap! */
1729 case UNSPEC_VOLATILE:
1733 /* Memory ref can trap unless it's a static var or a stack slot. */
1735 return rtx_addr_can_trap_p (XEXP (x, 0));
1737 /* Division by a non-constant might trap. */
1742 if (! CONSTANT_P (XEXP (x, 1))
1743 || GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1745 /* This was const0_rtx, but by not using that,
1746 we can link this file into other programs. */
1747 if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
1752 /* An EXPR_LIST is used to represent a function call. This
1753 certainly may trap. */
1757 /* Any floating arithmetic may trap. */
1758 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1762 fmt = GET_RTX_FORMAT (code);
1763 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1767 if (may_trap_p (XEXP (x, i)))
1770 else if (fmt[i] == 'E')
1773 for (j = 0; j < XVECLEN (x, i); j++)
1774 if (may_trap_p (XVECEXP (x, i, j)))
1781 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1782 i.e., an inequality. */
1785 inequality_comparisons_p (x)
1788 register const char *fmt;
1789 register int len, i;
1790 register enum rtx_code code = GET_CODE (x);
1819 len = GET_RTX_LENGTH (code);
1820 fmt = GET_RTX_FORMAT (code);
1822 for (i = 0; i < len; i++)
1826 if (inequality_comparisons_p (XEXP (x, i)))
1829 else if (fmt[i] == 'E')
1832 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1833 if (inequality_comparisons_p (XVECEXP (x, i, j)))
1841 /* Replace any occurrence of FROM in X with TO. The function does
1842 not enter into CONST_DOUBLE for the replace.
1844 Note that copying is not done so X must not be shared unless all copies
1845 are to be modified. */
1848 replace_rtx (x, from, to)
1852 register const char *fmt;
1854 /* The following prevents loops occurrence when we change MEM in
1855 CONST_DOUBLE onto the same CONST_DOUBLE. */
1856 if (x != 0 && GET_CODE (x) == CONST_DOUBLE)
1862 /* Allow this function to make replacements in EXPR_LISTs. */
1866 fmt = GET_RTX_FORMAT (GET_CODE (x));
1867 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
1870 XEXP (x, i) = replace_rtx (XEXP (x, i), from, to);
1871 else if (fmt[i] == 'E')
1872 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1873 XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to);
1879 /* Throughout the rtx X, replace many registers according to REG_MAP.
1880 Return the replacement for X (which may be X with altered contents).
1881 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
1882 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
1884 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
1885 should not be mapped to pseudos or vice versa since validate_change
1888 If REPLACE_DEST is 1, replacements are also done in destinations;
1889 otherwise, only sources are replaced. */
1892 replace_regs (x, reg_map, nregs, replace_dest)
1898 register enum rtx_code code;
1900 register const char *fmt;
1905 code = GET_CODE (x);
1919 /* Verify that the register has an entry before trying to access it. */
1920 if (REGNO (x) < nregs && reg_map[REGNO (x)] != 0)
1922 /* SUBREGs can't be shared. Always return a copy to ensure that if
1923 this replacement occurs more than once then each instance will
1924 get distinct rtx. */
1925 if (GET_CODE (reg_map[REGNO (x)]) == SUBREG)
1926 return copy_rtx (reg_map[REGNO (x)]);
1927 return reg_map[REGNO (x)];
1932 /* Prevent making nested SUBREGs. */
1933 if (GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) < nregs
1934 && reg_map[REGNO (SUBREG_REG (x))] != 0
1935 && GET_CODE (reg_map[REGNO (SUBREG_REG (x))]) == SUBREG)
1937 rtx map_val = reg_map[REGNO (SUBREG_REG (x))];
1938 rtx map_inner = SUBREG_REG (map_val);
1940 if (GET_MODE (x) == GET_MODE (map_inner))
1944 /* We cannot call gen_rtx here since we may be linked with
1946 /* Let's try clobbering the incoming SUBREG and see
1947 if this is really safe. */
1948 SUBREG_REG (x) = map_inner;
1949 SUBREG_WORD (x) += SUBREG_WORD (map_val);
1952 rtx new = rtx_alloc (SUBREG);
1953 PUT_MODE (new, GET_MODE (x));
1954 SUBREG_REG (new) = map_inner;
1955 SUBREG_WORD (new) = SUBREG_WORD (x) + SUBREG_WORD (map_val);
1963 SET_DEST (x) = replace_regs (SET_DEST (x), reg_map, nregs, 0);
1965 else if (GET_CODE (SET_DEST (x)) == MEM
1966 || GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
1967 /* Even if we are not to replace destinations, replace register if it
1968 is CONTAINED in destination (destination is memory or
1969 STRICT_LOW_PART). */
1970 XEXP (SET_DEST (x), 0) = replace_regs (XEXP (SET_DEST (x), 0),
1972 else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1973 /* Similarly, for ZERO_EXTRACT we replace all operands. */
1976 SET_SRC (x) = replace_regs (SET_SRC (x), reg_map, nregs, 0);
1983 fmt = GET_RTX_FORMAT (code);
1984 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1987 XEXP (x, i) = replace_regs (XEXP (x, i), reg_map, nregs, replace_dest);
1988 else if (fmt[i] == 'E')
1991 for (j = 0; j < XVECLEN (x, i); j++)
1992 XVECEXP (x, i, j) = replace_regs (XVECEXP (x, i, j), reg_map,
1993 nregs, replace_dest);
1999 /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is
2000 not in the constant pool and not in the condition of an IF_THEN_ELSE. */
2003 jmp_uses_reg_or_mem (x)
2006 enum rtx_code code = GET_CODE (x);
2021 return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
2022 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
2025 return (jmp_uses_reg_or_mem (XEXP (x, 1))
2026 || jmp_uses_reg_or_mem (XEXP (x, 2)));
2028 case PLUS: case MINUS: case MULT:
2029 return (jmp_uses_reg_or_mem (XEXP (x, 0))
2030 || jmp_uses_reg_or_mem (XEXP (x, 1)));
2036 fmt = GET_RTX_FORMAT (code);
2037 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2040 && jmp_uses_reg_or_mem (XEXP (x, i)))
2043 else if (fmt[i] == 'E')
2044 for (j = 0; j < XVECLEN (x, i); j++)
2045 if (jmp_uses_reg_or_mem (XVECEXP (x, i, j)))
2052 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2054 Tablejumps and casesi insns are not considered indirect jumps;
2055 we can recognize them by a (use (lael_ref)). */
2058 computed_jump_p (insn)
2062 if (GET_CODE (insn) == JUMP_INSN)
2064 rtx pat = PATTERN (insn);
2066 if (GET_CODE (pat) == PARALLEL)
2068 int len = XVECLEN (pat, 0);
2069 int has_use_labelref = 0;
2071 for (i = len - 1; i >= 0; i--)
2072 if (GET_CODE (XVECEXP (pat, 0, i)) == USE
2073 && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0))
2075 has_use_labelref = 1;
2077 if (! has_use_labelref)
2078 for (i = len - 1; i >= 0; i--)
2079 if (GET_CODE (XVECEXP (pat, 0, i)) == SET
2080 && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx
2081 && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat, 0, i))))
2084 else if (GET_CODE (pat) == SET
2085 && SET_DEST (pat) == pc_rtx
2086 && jmp_uses_reg_or_mem (SET_SRC (pat)))
2092 /* Traverse X via depth-first search, calling F for each
2093 sub-expression (including X itself). F is also passed the DATA.
2094 If F returns -1, do not traverse sub-expressions, but continue
2095 traversing the rest of the tree. If F ever returns any other
2096 non-zero value, stop the traversal, and return the value returned
2097 by F. Otherwise, return 0. This function does not traverse inside
2098 tree structure that contains RTX_EXPRs, or into sub-expressions
2099 whose format code is `0' since it is not known whether or not those
2100 codes are actually RTL.
2102 This routine is very general, and could (should?) be used to
2103 implement many of the other routines in this file. */
2106 for_each_rtx (x, f, data)
2117 result = (*f)(x, data);
2119 /* Do not traverse sub-expressions. */
2121 else if (result != 0)
2122 /* Stop the traversal. */
2126 /* There are no sub-expressions. */
2129 length = GET_RTX_LENGTH (GET_CODE (*x));
2130 format = GET_RTX_FORMAT (GET_CODE (*x));
2132 for (i = 0; i < length; ++i)
2137 result = for_each_rtx (&XEXP (*x, i), f, data);
2144 if (XVEC (*x, i) != 0)
2147 for (j = 0; j < XVECLEN (*x, i); ++j)
2149 result = for_each_rtx (&XVECEXP (*x, i, j), f, data);
2157 /* Nothing to do. */
2166 /* Searches X for any reference to REGNO, returning the rtx of the
2167 reference found if any. Otherwise, returns NULL_RTX. */
2170 regno_use_in (regno, x)
2174 register const char *fmt;
2178 if (GET_CODE (x) == REG && REGNO (x) == regno)
2181 fmt = GET_RTX_FORMAT (GET_CODE (x));
2182 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2186 if ((tem = regno_use_in (regno, XEXP (x, i))))
2189 else if (fmt[i] == 'E')
2190 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2191 if ((tem = regno_use_in (regno , XVECEXP (x, i, j))))
2199 /* Return 1 if X is an autoincrement side effect and the register is
2200 not the stack pointer. */
2205 switch (GET_CODE (x))
2213 /* There are no REG_INC notes for SP. */
2214 if (XEXP (x, 0) != stack_pointer_rtx)
2222 /* Return 1 if the sequence of instructions beginning with FROM and up
2223 to and including TO is safe to move. If NEW_TO is non-NULL, and
2224 the sequence is not already safe to move, but can be easily
2225 extended to a sequence which is safe, then NEW_TO will point to the
2226 end of the extended sequence.
2228 For now, this function only checks that the region contains whole
2229 exception regiongs, but it could be extended to check additional
2230 conditions as well. */
2233 insns_safe_to_move_p (from, to, new_to)
2238 int eh_region_count = 0;
2242 /* By default, assume the end of the region will be what was
2249 if (GET_CODE (r) == NOTE)
2251 switch (NOTE_LINE_NUMBER (r))
2253 case NOTE_INSN_EH_REGION_BEG:
2257 case NOTE_INSN_EH_REGION_END:
2258 if (eh_region_count == 0)
2259 /* This sequence of instructions contains the end of
2260 an exception region, but not he beginning. Moving
2261 it will cause chaos. */
2272 /* If we've passed TO, and we see a non-note instruction, we
2273 can't extend the sequence to a movable sequence. */
2279 /* It's OK to move the sequence if there were matched sets of
2280 exception region notes. */
2281 return eh_region_count == 0;
2286 /* It's OK to move the sequence if there were matched sets of
2287 exception region notes. */
2288 if (past_to_p && eh_region_count == 0)
2294 /* Go to the next instruction. */