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);
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--)
74 if (rtx_unstable_p (XEXP (x, i)))
77 else if (fmt[i] == 'E')
80 for (j = 0; j < XVECLEN (x, i); j++)
81 if (rtx_unstable_p (XVECEXP (x, i, j)))
88 /* Return 1 if X has a value that can vary even between two
89 executions of the program. 0 means X can be compared reliably
90 against certain constants or near-constants.
91 The frame pointer and the arg pointer are considered constant. */
97 register RTX_CODE code = GET_CODE (x);
99 register const char *fmt;
115 /* Note that we have to test for the actual rtx used for the frame
116 and arg pointers and not just the register number in case we have
117 eliminated the frame and/or arg pointer and are using it
119 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
120 || x == arg_pointer_rtx || x == pic_offset_table_rtx);
123 /* The operand 0 of a LO_SUM is considered constant
124 (in fact is it related specifically to operand 1). */
125 return rtx_varies_p (XEXP (x, 1));
131 fmt = GET_RTX_FORMAT (code);
132 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
135 if (rtx_varies_p (XEXP (x, i)))
138 else if (fmt[i] == 'E')
141 for (j = 0; j < XVECLEN (x, i); j++)
142 if (rtx_varies_p (XVECEXP (x, i, j)))
149 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
152 rtx_addr_can_trap_p (x)
155 register enum rtx_code code = GET_CODE (x);
161 /* SYMBOL_REF is problematic due to the possible presence of
162 a #pragma weak, but to say that loads from symbols can trap is
163 *very* costly. It's not at all clear what's best here. For
164 now, we ignore the impact of #pragma weak. */
168 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
169 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
170 || x == stack_pointer_rtx || x == arg_pointer_rtx);
173 return rtx_addr_can_trap_p (XEXP (x, 0));
176 /* An address is assumed not to trap if it is an address that can't
177 trap plus a constant integer. */
178 return (rtx_addr_can_trap_p (XEXP (x, 0))
179 || GET_CODE (XEXP (x, 1)) != CONST_INT);
182 return rtx_addr_can_trap_p (XEXP (x, 1));
188 /* If it isn't one of the case above, it can cause a trap. */
192 /* Return 1 if X refers to a memory location whose address
193 cannot be compared reliably with constant addresses,
194 or if X refers to a BLKmode memory object. */
197 rtx_addr_varies_p (x)
200 register enum rtx_code code;
202 register const char *fmt;
209 return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0));
211 fmt = GET_RTX_FORMAT (code);
212 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
215 if (rtx_addr_varies_p (XEXP (x, i)))
218 else if (fmt[i] == 'E')
221 for (j = 0; j < XVECLEN (x, i); j++)
222 if (rtx_addr_varies_p (XVECEXP (x, i, j)))
228 /* Return the value of the integer term in X, if one is apparent;
230 Only obvious integer terms are detected.
231 This is used in cse.c with the `related_value' field.*/
237 if (GET_CODE (x) == CONST)
240 if (GET_CODE (x) == MINUS
241 && GET_CODE (XEXP (x, 1)) == CONST_INT)
242 return - INTVAL (XEXP (x, 1));
243 if (GET_CODE (x) == PLUS
244 && GET_CODE (XEXP (x, 1)) == CONST_INT)
245 return INTVAL (XEXP (x, 1));
249 /* If X is a constant, return the value sans apparent integer term;
251 Only obvious integer terms are detected. */
254 get_related_value (x)
257 if (GET_CODE (x) != CONST)
260 if (GET_CODE (x) == PLUS
261 && GET_CODE (XEXP (x, 1)) == CONST_INT)
263 else if (GET_CODE (x) == MINUS
264 && GET_CODE (XEXP (x, 1)) == CONST_INT)
269 /* Return the number of places FIND appears within X. If COUNT_DEST is
270 zero, we do not count occurrences inside the destination of a SET. */
273 count_occurrences (x, find, count_dest)
279 const char *format_ptr;
299 if (GET_CODE (find) == MEM && rtx_equal_p (x, find))
304 if (SET_DEST (x) == find && ! count_dest)
305 return count_occurrences (SET_SRC (x), find, count_dest);
312 format_ptr = GET_RTX_FORMAT (code);
315 for (i = 0; i < GET_RTX_LENGTH (code); i++)
317 switch (*format_ptr++)
320 count += count_occurrences (XEXP (x, i), find, count_dest);
324 for (j = 0; j < XVECLEN (x, i); j++)
325 count += count_occurrences (XVECEXP (x, i, j), find, count_dest);
332 /* Nonzero if register REG appears somewhere within IN.
333 Also works if REG is not a register; in this case it checks
334 for a subexpression of IN that is Lisp "equal" to REG. */
337 reg_mentioned_p (reg, in)
338 register rtx reg, in;
340 register const char *fmt;
342 register enum rtx_code code;
350 if (GET_CODE (in) == LABEL_REF)
351 return reg == XEXP (in, 0);
353 code = GET_CODE (in);
357 /* Compare registers by number. */
359 return GET_CODE (reg) == REG && REGNO (in) == REGNO (reg);
361 /* These codes have no constituent expressions
369 return GET_CODE (reg) == CONST_INT && INTVAL (in) == INTVAL (reg);
372 /* These are kept unique for a given value. */
379 if (GET_CODE (reg) == code && rtx_equal_p (reg, in))
382 fmt = GET_RTX_FORMAT (code);
384 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
389 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
390 if (reg_mentioned_p (reg, XVECEXP (in, i, j)))
393 else if (fmt[i] == 'e'
394 && reg_mentioned_p (reg, XEXP (in, i)))
400 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
401 no CODE_LABEL insn. */
404 no_labels_between_p (beg, end)
408 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
409 if (GET_CODE (p) == CODE_LABEL)
414 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
415 no JUMP_INSN insn. */
418 no_jumps_between_p (beg, end)
422 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
423 if (GET_CODE (p) == JUMP_INSN)
428 /* Nonzero if register REG is used in an insn between
429 FROM_INSN and TO_INSN (exclusive of those two). */
432 reg_used_between_p (reg, from_insn, to_insn)
433 rtx reg, from_insn, to_insn;
437 if (from_insn == to_insn)
440 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
442 && (reg_overlap_mentioned_p (reg, PATTERN (insn))
443 || (GET_CODE (insn) == CALL_INSN
444 && (find_reg_fusage (insn, USE, reg)
445 || find_reg_fusage (insn, CLOBBER, reg)))))
450 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
451 is entirely replaced by a new value and the only use is as a SET_DEST,
452 we do not consider it a reference. */
455 reg_referenced_p (x, body)
461 switch (GET_CODE (body))
464 if (reg_overlap_mentioned_p (x, SET_SRC (body)))
467 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
468 of a REG that occupies all of the REG, the insn references X if
469 it is mentioned in the destination. */
470 if (GET_CODE (SET_DEST (body)) != CC0
471 && GET_CODE (SET_DEST (body)) != PC
472 && GET_CODE (SET_DEST (body)) != REG
473 && ! (GET_CODE (SET_DEST (body)) == SUBREG
474 && GET_CODE (SUBREG_REG (SET_DEST (body))) == REG
475 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body))))
476 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
477 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body)))
478 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
479 && reg_overlap_mentioned_p (x, SET_DEST (body)))
484 for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
485 if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i)))
492 return reg_overlap_mentioned_p (x, body);
495 return reg_overlap_mentioned_p (x, TRAP_CONDITION (body));
498 case UNSPEC_VOLATILE:
499 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
500 if (reg_overlap_mentioned_p (x, XVECEXP (body, 0, i)))
505 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
506 if (reg_referenced_p (x, XVECEXP (body, 0, i)))
511 if (GET_CODE (XEXP (body, 0)) == MEM)
512 if (reg_overlap_mentioned_p (x, XEXP (XEXP (body, 0), 0)))
517 if (reg_overlap_mentioned_p (x, COND_EXEC_TEST (body)))
519 return reg_referenced_p (x, COND_EXEC_CODE (body));
526 /* Nonzero if register REG is referenced in an insn between
527 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
531 reg_referenced_between_p (reg, from_insn, to_insn)
532 rtx reg, from_insn, to_insn;
536 if (from_insn == to_insn)
539 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
541 && (reg_referenced_p (reg, PATTERN (insn))
542 || (GET_CODE (insn) == CALL_INSN
543 && find_reg_fusage (insn, USE, reg))))
548 /* Nonzero if register REG is set or clobbered in an insn between
549 FROM_INSN and TO_INSN (exclusive of those two). */
552 reg_set_between_p (reg, from_insn, to_insn)
553 rtx reg, from_insn, to_insn;
557 if (from_insn == to_insn)
560 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
561 if (INSN_P (insn) && reg_set_p (reg, insn))
566 /* Internals of reg_set_between_p. */
568 static rtx reg_set_reg;
569 static int reg_set_flag;
572 reg_set_p_1 (x, pat, data)
574 rtx pat ATTRIBUTE_UNUSED;
575 void *data ATTRIBUTE_UNUSED;
577 /* We don't want to return 1 if X is a MEM that contains a register
578 within REG_SET_REG. */
580 if ((GET_CODE (x) != MEM)
581 && reg_overlap_mentioned_p (reg_set_reg, x))
586 reg_set_p (reg, insn)
591 /* We can be passed an insn or part of one. If we are passed an insn,
592 check if a side-effect of the insn clobbers REG. */
595 if (FIND_REG_INC_NOTE (insn, reg)
596 || (GET_CODE (insn) == CALL_INSN
597 /* We'd like to test call_used_regs here, but rtlanal.c can't
598 reference that variable due to its use in genattrtab. So
599 we'll just be more conservative.
601 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
602 information holds all clobbered registers. */
603 && ((GET_CODE (reg) == REG
604 && REGNO (reg) < FIRST_PSEUDO_REGISTER)
605 || GET_CODE (reg) == MEM
606 || find_reg_fusage (insn, CLOBBER, reg))))
609 body = PATTERN (insn);
614 note_stores (body, reg_set_p_1, NULL);
618 /* Similar to reg_set_between_p, but check all registers in X. Return 0
619 only if none of them are modified between START and END. Do not
620 consider non-registers one way or the other. */
623 regs_set_between_p (x, start, end)
627 enum rtx_code code = GET_CODE (x);
643 return reg_set_between_p (x, start, end);
649 fmt = GET_RTX_FORMAT (code);
650 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
652 if (fmt[i] == 'e' && regs_set_between_p (XEXP (x, i), start, end))
655 else if (fmt[i] == 'E')
656 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
657 if (regs_set_between_p (XVECEXP (x, i, j), start, end))
664 /* Similar to reg_set_between_p, but check all registers in X. Return 0
665 only if none of them are modified between START and END. Return 1 if
666 X contains a MEM; this routine does not perform any memory aliasing. */
669 modified_between_p (x, start, end)
673 enum rtx_code code = GET_CODE (x);
691 /* If the memory is not constant, assume it is modified. If it is
692 constant, we still have to check the address. */
693 if (! RTX_UNCHANGING_P (x))
698 return reg_set_between_p (x, start, end);
704 fmt = GET_RTX_FORMAT (code);
705 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
707 if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end))
710 else if (fmt[i] == 'E')
711 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
712 if (modified_between_p (XVECEXP (x, i, j), start, end))
719 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
720 of them are modified in INSN. Return 1 if X contains a MEM; this routine
721 does not perform any memory aliasing. */
724 modified_in_p (x, insn)
728 enum rtx_code code = GET_CODE (x);
746 /* If the memory is not constant, assume it is modified. If it is
747 constant, we still have to check the address. */
748 if (! RTX_UNCHANGING_P (x))
753 return reg_set_p (x, insn);
759 fmt = GET_RTX_FORMAT (code);
760 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
762 if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn))
765 else if (fmt[i] == 'E')
766 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
767 if (modified_in_p (XVECEXP (x, i, j), insn))
774 /* Return true if anything in insn X is (anti,output,true) dependent on
775 anything in insn Y. */
778 insn_dependent_p (x, y)
783 if (! INSN_P (x) || ! INSN_P (y))
787 note_stores (PATTERN (x), insn_dependent_p_1, &tmp);
792 note_stores (PATTERN (y), insn_dependent_p_1, &tmp);
799 /* A helper routine for insn_dependent_p called through note_stores. */
802 insn_dependent_p_1 (x, pat, data)
804 rtx pat ATTRIBUTE_UNUSED;
807 rtx * pinsn = (rtx *) data;
809 if (*pinsn && reg_mentioned_p (x, *pinsn))
813 /* Given an INSN, return a SET expression if this insn has only a single SET.
814 It may also have CLOBBERs, USEs, or SET whose output
815 will not be used, which we ignore. */
827 if (GET_CODE (PATTERN (insn)) == SET)
828 return PATTERN (insn);
830 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
832 for (i = 0, set = 0; i < XVECLEN (PATTERN (insn), 0); i++)
834 rtx sub = XVECEXP (PATTERN (insn), 0, i);
836 switch (GET_CODE (sub))
843 if (! find_reg_note (insn, REG_UNUSED, SET_DEST (sub))
844 || side_effects_p (sub))
863 /* Given an INSN, return nonzero if it has more than one SET, else return
873 /* INSN must be an insn. */
877 /* Only a PARALLEL can have multiple SETs. */
878 if (GET_CODE (PATTERN (insn)) == PARALLEL)
880 for (i = 0, found = 0; i < XVECLEN (PATTERN (insn), 0); i++)
881 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
883 /* If we have already found a SET, then return now. */
891 /* Either zero or one SET. */
895 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
896 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
897 If the object was modified, if we hit a partial assignment to X, or hit a
898 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
899 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
903 find_last_value (x, pinsn, valid_to, allow_hwreg)
911 for (p = PREV_INSN (*pinsn); p && GET_CODE (p) != CODE_LABEL;
915 rtx set = single_set (p);
916 rtx note = find_reg_note (p, REG_EQUAL, NULL_RTX);
918 if (set && rtx_equal_p (x, SET_DEST (set)))
920 rtx src = SET_SRC (set);
922 if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
923 src = XEXP (note, 0);
925 if ((valid_to == NULL_RTX
926 || ! modified_between_p (src, PREV_INSN (p), valid_to))
927 /* Reject hard registers because we don't usually want
928 to use them; we'd rather use a pseudo. */
929 && (! (GET_CODE (src) == REG
930 && REGNO (src) < FIRST_PSEUDO_REGISTER) || allow_hwreg))
937 /* If set in non-simple way, we don't have a value. */
938 if (reg_set_p (x, p))
945 /* Return nonzero if register in range [REGNO, ENDREGNO)
946 appears either explicitly or implicitly in X
947 other than being stored into.
949 References contained within the substructure at LOC do not count.
950 LOC may be zero, meaning don't ignore anything. */
953 refers_to_regno_p (regno, endregno, x, loc)
954 unsigned int regno, endregno;
959 unsigned int x_regno;
964 /* The contents of a REG_NONNEG note is always zero, so we must come here
965 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
976 /* If we modifying the stack, frame, or argument pointer, it will
977 clobber a virtual register. In fact, we could be more precise,
978 but it isn't worth it. */
979 if ((x_regno == STACK_POINTER_REGNUM
980 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
981 || x_regno == ARG_POINTER_REGNUM
983 || x_regno == FRAME_POINTER_REGNUM)
984 && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER)
987 return (endregno > x_regno
988 && regno < x_regno + (x_regno < FIRST_PSEUDO_REGISTER
989 ? HARD_REGNO_NREGS (x_regno, GET_MODE (x))
993 /* If this is a SUBREG of a hard reg, we can see exactly which
994 registers are being modified. Otherwise, handle normally. */
995 if (GET_CODE (SUBREG_REG (x)) == REG
996 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
998 unsigned int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
999 unsigned int inner_endregno
1000 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
1001 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
1003 return endregno > inner_regno && regno < inner_endregno;
1009 if (&SET_DEST (x) != loc
1010 /* Note setting a SUBREG counts as referring to the REG it is in for
1011 a pseudo but not for hard registers since we can
1012 treat each word individually. */
1013 && ((GET_CODE (SET_DEST (x)) == SUBREG
1014 && loc != &SUBREG_REG (SET_DEST (x))
1015 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
1016 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
1017 && refers_to_regno_p (regno, endregno,
1018 SUBREG_REG (SET_DEST (x)), loc))
1019 || (GET_CODE (SET_DEST (x)) != REG
1020 && refers_to_regno_p (regno, endregno, SET_DEST (x), loc))))
1023 if (code == CLOBBER || loc == &SET_SRC (x))
1032 /* X does not match, so try its subexpressions. */
1034 fmt = GET_RTX_FORMAT (code);
1035 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1037 if (fmt[i] == 'e' && loc != &XEXP (x, i))
1045 if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc))
1048 else if (fmt[i] == 'E')
1051 for (j = XVECLEN (x, i) - 1; j >=0; j--)
1052 if (loc != &XVECEXP (x, i, j)
1053 && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc))
1060 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
1061 we check if any register number in X conflicts with the relevant register
1062 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
1063 contains a MEM (we don't bother checking for memory addresses that can't
1064 conflict because we expect this to be a rare case. */
1067 reg_overlap_mentioned_p (x, in)
1070 unsigned int regno, endregno;
1072 /* Overly conservative. */
1073 if (GET_CODE (x) == STRICT_LOW_PART)
1076 /* If either argument is a constant, then modifying X can not affect IN. */
1077 if (CONSTANT_P (x) || CONSTANT_P (in))
1080 switch (GET_CODE (x))
1083 regno = REGNO (SUBREG_REG (x));
1084 if (regno < FIRST_PSEUDO_REGISTER)
1085 regno += SUBREG_WORD (x);
1091 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
1092 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
1093 return refers_to_regno_p (regno, endregno, in, NULL_PTR);
1100 if (GET_CODE (in) == MEM)
1103 fmt = GET_RTX_FORMAT (GET_CODE (in));
1104 for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--)
1105 if (fmt[i] == 'e' && reg_overlap_mentioned_p (x, XEXP (in, i)))
1114 return reg_mentioned_p (x, in);
1120 /* Check for a NULL entry, used to indicate that the parameter goes
1121 both on the stack and in registers. */
1122 if (XEXP (XVECEXP (x, 0, 0), 0))
1127 /* If any register in here refers to it we return true. */
1128 for (n = XVECLEN (x, 0); i < n; ++i)
1129 if (reg_overlap_mentioned_p (XEXP (XVECEXP (x, 0, i), 0), in))
1141 /* Used for communications between the next few functions. */
1143 static int reg_set_last_unknown;
1144 static rtx reg_set_last_value;
1145 static unsigned int reg_set_last_first_regno, reg_set_last_last_regno;
1147 /* Called via note_stores from reg_set_last. */
1150 reg_set_last_1 (x, pat, data)
1153 void *data ATTRIBUTE_UNUSED;
1155 unsigned int first, last;
1157 /* If X is not a register, or is not one in the range we care
1159 if (GET_CODE (x) != REG)
1163 last = first + (first < FIRST_PSEUDO_REGISTER
1164 ? HARD_REGNO_NREGS (first, GET_MODE (x)) : 1);
1166 if (first >= reg_set_last_last_regno
1167 || last <= reg_set_last_first_regno)
1170 /* If this is a CLOBBER or is some complex LHS, or doesn't modify
1171 exactly the registers we care about, show we don't know the value. */
1172 if (GET_CODE (pat) == CLOBBER || SET_DEST (pat) != x
1173 || first != reg_set_last_first_regno
1174 || last != reg_set_last_last_regno)
1175 reg_set_last_unknown = 1;
1177 reg_set_last_value = SET_SRC (pat);
1180 /* Return the last value to which REG was set prior to INSN. If we can't
1181 find it easily, return 0.
1183 We only return a REG, SUBREG, or constant because it is too hard to
1184 check if a MEM remains unchanged. */
1187 reg_set_last (x, insn)
1191 rtx orig_insn = insn;
1193 reg_set_last_first_regno = REGNO (x);
1195 reg_set_last_last_regno
1196 = reg_set_last_first_regno
1197 + (reg_set_last_first_regno < FIRST_PSEUDO_REGISTER
1198 ? HARD_REGNO_NREGS (reg_set_last_first_regno, GET_MODE (x)) : 1);
1200 reg_set_last_unknown = 0;
1201 reg_set_last_value = 0;
1203 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1204 Stop when we reach a label or X is a hard reg and we reach a
1205 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1207 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1209 /* We compare with <= here, because reg_set_last_last_regno
1210 is actually the number of the first reg *not* in X. */
1212 insn && GET_CODE (insn) != CODE_LABEL
1213 && ! (GET_CODE (insn) == CALL_INSN
1214 && reg_set_last_last_regno <= FIRST_PSEUDO_REGISTER);
1215 insn = PREV_INSN (insn))
1218 note_stores (PATTERN (insn), reg_set_last_1, NULL);
1219 if (reg_set_last_unknown)
1221 else if (reg_set_last_value)
1223 if (CONSTANT_P (reg_set_last_value)
1224 || ((GET_CODE (reg_set_last_value) == REG
1225 || GET_CODE (reg_set_last_value) == SUBREG)
1226 && ! reg_set_between_p (reg_set_last_value,
1228 return reg_set_last_value;
1237 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1238 (X would be the pattern of an insn).
1239 FUN receives two arguments:
1240 the REG, MEM, CC0 or PC being stored in or clobbered,
1241 the SET or CLOBBER rtx that does the store.
1243 If the item being stored in or clobbered is a SUBREG of a hard register,
1244 the SUBREG will be passed. */
1247 note_stores (x, fun, data)
1249 void (*fun) PARAMS ((rtx, rtx, void *));
1252 if (GET_CODE (x) == COND_EXEC)
1253 x = COND_EXEC_CODE (x);
1254 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
1256 register rtx dest = SET_DEST (x);
1257 while ((GET_CODE (dest) == SUBREG
1258 && (GET_CODE (SUBREG_REG (dest)) != REG
1259 || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER))
1260 || GET_CODE (dest) == ZERO_EXTRACT
1261 || GET_CODE (dest) == SIGN_EXTRACT
1262 || GET_CODE (dest) == STRICT_LOW_PART)
1263 dest = XEXP (dest, 0);
1265 if (GET_CODE (dest) == PARALLEL
1266 && GET_MODE (dest) == BLKmode)
1269 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
1270 (*fun) (SET_DEST (XVECEXP (dest, 0, i)), x, data);
1273 (*fun) (dest, x, data);
1275 else if (GET_CODE (x) == PARALLEL)
1278 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1280 register rtx y = XVECEXP (x, 0, i);
1281 if (GET_CODE (y) == COND_EXEC)
1282 y = COND_EXEC_CODE (y);
1283 if (GET_CODE (y) == SET || GET_CODE (y) == CLOBBER)
1285 register rtx dest = SET_DEST (y);
1286 while ((GET_CODE (dest) == SUBREG
1287 && (GET_CODE (SUBREG_REG (dest)) != REG
1288 || (REGNO (SUBREG_REG (dest))
1289 >= FIRST_PSEUDO_REGISTER)))
1290 || GET_CODE (dest) == ZERO_EXTRACT
1291 || GET_CODE (dest) == SIGN_EXTRACT
1292 || GET_CODE (dest) == STRICT_LOW_PART)
1293 dest = XEXP (dest, 0);
1294 if (GET_CODE (dest) == PARALLEL
1295 && GET_MODE (dest) == BLKmode)
1299 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
1300 (*fun) (SET_DEST (XVECEXP (dest, 0, i)), y, data);
1303 (*fun) (dest, y, data);
1309 /* Return nonzero if X's old contents don't survive after INSN.
1310 This will be true if X is (cc0) or if X is a register and
1311 X dies in INSN or because INSN entirely sets X.
1313 "Entirely set" means set directly and not through a SUBREG,
1314 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1315 Likewise, REG_INC does not count.
1317 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1318 but for this use that makes no difference, since regs don't overlap
1319 during their lifetimes. Therefore, this function may be used
1320 at any time after deaths have been computed (in flow.c).
1322 If REG is a hard reg that occupies multiple machine registers, this
1323 function will only return 1 if each of those registers will be replaced
1327 dead_or_set_p (insn, x)
1331 unsigned int regno, last_regno;
1334 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1335 if (GET_CODE (x) == CC0)
1338 if (GET_CODE (x) != REG)
1342 last_regno = (regno >= FIRST_PSEUDO_REGISTER ? regno
1343 : regno + HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1);
1345 for (i = regno; i <= last_regno; i++)
1346 if (! dead_or_set_regno_p (insn, i))
1352 /* Utility function for dead_or_set_p to check an individual register. Also
1353 called from flow.c. */
1356 dead_or_set_regno_p (insn, test_regno)
1358 unsigned int test_regno;
1360 unsigned int regno, endregno;
1363 /* See if there is a death note for something that includes TEST_REGNO. */
1364 if (find_regno_note (insn, REG_DEAD, test_regno))
1367 if (GET_CODE (insn) == CALL_INSN
1368 && find_regno_fusage (insn, CLOBBER, test_regno))
1371 pattern = PATTERN (insn);
1373 if (GET_CODE (pattern) == COND_EXEC)
1374 pattern = COND_EXEC_CODE (pattern);
1376 if (GET_CODE (pattern) == SET)
1378 rtx dest = SET_DEST (PATTERN (insn));
1380 /* A value is totally replaced if it is the destination or the
1381 destination is a SUBREG of REGNO that does not change the number of
1383 if (GET_CODE (dest) == SUBREG
1384 && (((GET_MODE_SIZE (GET_MODE (dest))
1385 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1386 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1387 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1388 dest = SUBREG_REG (dest);
1390 if (GET_CODE (dest) != REG)
1393 regno = REGNO (dest);
1394 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1395 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1397 return (test_regno >= regno && test_regno < endregno);
1399 else if (GET_CODE (pattern) == PARALLEL)
1403 for (i = XVECLEN (pattern, 0) - 1; i >= 0; i--)
1405 rtx body = XVECEXP (pattern, 0, i);
1407 if (GET_CODE (body) == COND_EXEC)
1408 body = COND_EXEC_CODE (body);
1410 if (GET_CODE (body) == SET || GET_CODE (body) == CLOBBER)
1412 rtx dest = SET_DEST (body);
1414 if (GET_CODE (dest) == SUBREG
1415 && (((GET_MODE_SIZE (GET_MODE (dest))
1416 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1417 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1418 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1419 dest = SUBREG_REG (dest);
1421 if (GET_CODE (dest) != REG)
1424 regno = REGNO (dest);
1425 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1426 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1428 if (test_regno >= regno && test_regno < endregno)
1437 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1438 If DATUM is nonzero, look for one whose datum is DATUM. */
1441 find_reg_note (insn, kind, datum)
1448 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1449 if (! INSN_P (insn))
1452 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1453 if (REG_NOTE_KIND (link) == kind
1454 && (datum == 0 || datum == XEXP (link, 0)))
1459 /* Return the reg-note of kind KIND in insn INSN which applies to register
1460 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1461 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1462 it might be the case that the note overlaps REGNO. */
1465 find_regno_note (insn, kind, regno)
1472 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1473 if (! INSN_P (insn))
1476 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1477 if (REG_NOTE_KIND (link) == kind
1478 /* Verify that it is a register, so that scratch and MEM won't cause a
1480 && GET_CODE (XEXP (link, 0)) == REG
1481 && REGNO (XEXP (link, 0)) <= regno
1482 && ((REGNO (XEXP (link, 0))
1483 + (REGNO (XEXP (link, 0)) >= FIRST_PSEUDO_REGISTER ? 1
1484 : HARD_REGNO_NREGS (REGNO (XEXP (link, 0)),
1485 GET_MODE (XEXP (link, 0)))))
1491 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1492 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1495 find_reg_fusage (insn, code, datum)
1500 /* If it's not a CALL_INSN, it can't possibly have a
1501 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1502 if (GET_CODE (insn) != CALL_INSN)
1508 if (GET_CODE (datum) != REG)
1512 for (link = CALL_INSN_FUNCTION_USAGE (insn);
1514 link = XEXP (link, 1))
1515 if (GET_CODE (XEXP (link, 0)) == code
1516 && rtx_equal_p (datum, SET_DEST (XEXP (link, 0))))
1521 unsigned int regno = REGNO (datum);
1523 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1524 to pseudo registers, so don't bother checking. */
1526 if (regno < FIRST_PSEUDO_REGISTER)
1528 unsigned int end_regno
1529 = regno + HARD_REGNO_NREGS (regno, GET_MODE (datum));
1532 for (i = regno; i < end_regno; i++)
1533 if (find_regno_fusage (insn, code, i))
1541 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1542 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1545 find_regno_fusage (insn, code, regno)
1552 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1553 to pseudo registers, so don't bother checking. */
1555 if (regno >= FIRST_PSEUDO_REGISTER
1556 || GET_CODE (insn) != CALL_INSN )
1559 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
1561 unsigned int regnote;
1564 if (GET_CODE (op = XEXP (link, 0)) == code
1565 && GET_CODE (reg = XEXP (op, 0)) == REG
1566 && (regnote = REGNO (reg)) <= regno
1567 && regnote + HARD_REGNO_NREGS (regnote, GET_MODE (reg)) > regno)
1574 /* Remove register note NOTE from the REG_NOTES of INSN. */
1577 remove_note (insn, note)
1583 if (note == NULL_RTX)
1586 if (REG_NOTES (insn) == note)
1588 REG_NOTES (insn) = XEXP (note, 1);
1592 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1593 if (XEXP (link, 1) == note)
1595 XEXP (link, 1) = XEXP (note, 1);
1602 /* Search LISTP (an EXPR_LIST) for NODE and remove NODE from the list
1605 A simple equality test is used to determine if NODE is on the
1609 remove_node_from_expr_list (node, listp)
1614 rtx prev = NULL_RTX;
1618 if (node == XEXP (temp, 0))
1620 /* Splice the node out of the list. */
1622 XEXP (prev, 1) = XEXP (temp, 1);
1624 *listp = XEXP (temp, 1);
1628 temp = XEXP (temp, 1);
1632 /* Nonzero if X contains any volatile instructions. These are instructions
1633 which may cause unpredictable machine state instructions, and thus no
1634 instructions should be moved or combined across them. This includes
1635 only volatile asms and UNSPEC_VOLATILE instructions. */
1641 register RTX_CODE code;
1643 code = GET_CODE (x);
1663 case UNSPEC_VOLATILE:
1664 /* case TRAP_IF: This isn't clear yet. */
1668 if (MEM_VOLATILE_P (x))
1675 /* Recursively scan the operands of this expression. */
1678 register const char *fmt = GET_RTX_FORMAT (code);
1681 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1685 if (volatile_insn_p (XEXP (x, i)))
1688 else if (fmt[i] == 'E')
1691 for (j = 0; j < XVECLEN (x, i); j++)
1692 if (volatile_insn_p (XVECEXP (x, i, j)))
1700 /* Nonzero if X contains any volatile memory references
1701 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1707 register RTX_CODE code;
1709 code = GET_CODE (x);
1728 case UNSPEC_VOLATILE:
1729 /* case TRAP_IF: This isn't clear yet. */
1734 if (MEM_VOLATILE_P (x))
1741 /* Recursively scan the operands of this expression. */
1744 register const char *fmt = GET_RTX_FORMAT (code);
1747 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1751 if (volatile_refs_p (XEXP (x, i)))
1754 else if (fmt[i] == 'E')
1757 for (j = 0; j < XVECLEN (x, i); j++)
1758 if (volatile_refs_p (XVECEXP (x, i, j)))
1766 /* Similar to above, except that it also rejects register pre- and post-
1773 register RTX_CODE code;
1775 code = GET_CODE (x);
1793 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1794 when some combination can't be done. If we see one, don't think
1795 that we can simplify the expression. */
1796 return (GET_MODE (x) != VOIDmode);
1803 case UNSPEC_VOLATILE:
1804 /* case TRAP_IF: This isn't clear yet. */
1809 if (MEM_VOLATILE_P (x))
1816 /* Recursively scan the operands of this expression. */
1819 register const char *fmt = GET_RTX_FORMAT (code);
1822 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1826 if (side_effects_p (XEXP (x, i)))
1829 else if (fmt[i] == 'E')
1832 for (j = 0; j < XVECLEN (x, i); j++)
1833 if (side_effects_p (XVECEXP (x, i, j)))
1841 /* Return nonzero if evaluating rtx X might cause a trap. */
1853 code = GET_CODE (x);
1856 /* Handle these cases quickly. */
1869 case UNSPEC_VOLATILE:
1874 return MEM_VOLATILE_P (x);
1876 /* Memory ref can trap unless it's a static var or a stack slot. */
1878 return rtx_addr_can_trap_p (XEXP (x, 0));
1880 /* Division by a non-constant might trap. */
1885 if (! CONSTANT_P (XEXP (x, 1))
1886 || GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1888 /* This was const0_rtx, but by not using that,
1889 we can link this file into other programs. */
1890 if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
1895 /* An EXPR_LIST is used to represent a function call. This
1896 certainly may trap. */
1900 /* Any floating arithmetic may trap. */
1901 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1905 fmt = GET_RTX_FORMAT (code);
1906 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1910 if (may_trap_p (XEXP (x, i)))
1913 else if (fmt[i] == 'E')
1916 for (j = 0; j < XVECLEN (x, i); j++)
1917 if (may_trap_p (XVECEXP (x, i, j)))
1924 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1925 i.e., an inequality. */
1928 inequality_comparisons_p (x)
1931 register const char *fmt;
1932 register int len, i;
1933 register enum rtx_code code = GET_CODE (x);
1962 len = GET_RTX_LENGTH (code);
1963 fmt = GET_RTX_FORMAT (code);
1965 for (i = 0; i < len; i++)
1969 if (inequality_comparisons_p (XEXP (x, i)))
1972 else if (fmt[i] == 'E')
1975 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1976 if (inequality_comparisons_p (XVECEXP (x, i, j)))
1984 /* Replace any occurrence of FROM in X with TO. The function does
1985 not enter into CONST_DOUBLE for the replace.
1987 Note that copying is not done so X must not be shared unless all copies
1988 are to be modified. */
1991 replace_rtx (x, from, to)
1995 register const char *fmt;
1997 /* The following prevents loops occurrence when we change MEM in
1998 CONST_DOUBLE onto the same CONST_DOUBLE. */
1999 if (x != 0 && GET_CODE (x) == CONST_DOUBLE)
2005 /* Allow this function to make replacements in EXPR_LISTs. */
2009 fmt = GET_RTX_FORMAT (GET_CODE (x));
2010 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2013 XEXP (x, i) = replace_rtx (XEXP (x, i), from, to);
2014 else if (fmt[i] == 'E')
2015 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2016 XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to);
2022 /* Throughout the rtx X, replace many registers according to REG_MAP.
2023 Return the replacement for X (which may be X with altered contents).
2024 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
2025 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
2027 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
2028 should not be mapped to pseudos or vice versa since validate_change
2031 If REPLACE_DEST is 1, replacements are also done in destinations;
2032 otherwise, only sources are replaced. */
2035 replace_regs (x, reg_map, nregs, replace_dest)
2041 register enum rtx_code code;
2043 register const char *fmt;
2048 code = GET_CODE (x);
2062 /* Verify that the register has an entry before trying to access it. */
2063 if (REGNO (x) < nregs && reg_map[REGNO (x)] != 0)
2065 /* SUBREGs can't be shared. Always return a copy to ensure that if
2066 this replacement occurs more than once then each instance will
2067 get distinct rtx. */
2068 if (GET_CODE (reg_map[REGNO (x)]) == SUBREG)
2069 return copy_rtx (reg_map[REGNO (x)]);
2070 return reg_map[REGNO (x)];
2075 /* Prevent making nested SUBREGs. */
2076 if (GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) < nregs
2077 && reg_map[REGNO (SUBREG_REG (x))] != 0
2078 && GET_CODE (reg_map[REGNO (SUBREG_REG (x))]) == SUBREG)
2080 rtx map_val = reg_map[REGNO (SUBREG_REG (x))];
2081 rtx map_inner = SUBREG_REG (map_val);
2083 if (GET_MODE (x) == GET_MODE (map_inner))
2087 /* We cannot call gen_rtx here since we may be linked with
2089 /* Let's try clobbering the incoming SUBREG and see
2090 if this is really safe. */
2091 SUBREG_REG (x) = map_inner;
2092 SUBREG_WORD (x) += SUBREG_WORD (map_val);
2095 rtx new = rtx_alloc (SUBREG);
2096 PUT_MODE (new, GET_MODE (x));
2097 SUBREG_REG (new) = map_inner;
2098 SUBREG_WORD (new) = SUBREG_WORD (x) + SUBREG_WORD (map_val);
2106 SET_DEST (x) = replace_regs (SET_DEST (x), reg_map, nregs, 0);
2108 else if (GET_CODE (SET_DEST (x)) == MEM
2109 || GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2110 /* Even if we are not to replace destinations, replace register if it
2111 is CONTAINED in destination (destination is memory or
2112 STRICT_LOW_PART). */
2113 XEXP (SET_DEST (x), 0) = replace_regs (XEXP (SET_DEST (x), 0),
2115 else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2116 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2119 SET_SRC (x) = replace_regs (SET_SRC (x), reg_map, nregs, 0);
2126 fmt = GET_RTX_FORMAT (code);
2127 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2130 XEXP (x, i) = replace_regs (XEXP (x, i), reg_map, nregs, replace_dest);
2131 else if (fmt[i] == 'E')
2134 for (j = 0; j < XVECLEN (x, i); j++)
2135 XVECEXP (x, i, j) = replace_regs (XVECEXP (x, i, j), reg_map,
2136 nregs, replace_dest);
2142 /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is
2143 not in the constant pool and not in the condition of an IF_THEN_ELSE. */
2146 jmp_uses_reg_or_mem (x)
2149 enum rtx_code code = GET_CODE (x);
2164 return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
2165 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
2168 return (jmp_uses_reg_or_mem (XEXP (x, 1))
2169 || jmp_uses_reg_or_mem (XEXP (x, 2)));
2171 case PLUS: case MINUS: case MULT:
2172 return (jmp_uses_reg_or_mem (XEXP (x, 0))
2173 || jmp_uses_reg_or_mem (XEXP (x, 1)));
2179 fmt = GET_RTX_FORMAT (code);
2180 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2183 && jmp_uses_reg_or_mem (XEXP (x, i)))
2186 else if (fmt[i] == 'E')
2187 for (j = 0; j < XVECLEN (x, i); j++)
2188 if (jmp_uses_reg_or_mem (XVECEXP (x, i, j)))
2195 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2197 Tablejumps and casesi insns are not considered indirect jumps;
2198 we can recognize them by a (use (label_ref)). */
2201 computed_jump_p (insn)
2205 if (GET_CODE (insn) == JUMP_INSN)
2207 rtx pat = PATTERN (insn);
2209 if (GET_CODE (pat) == PARALLEL)
2211 int len = XVECLEN (pat, 0);
2212 int has_use_labelref = 0;
2214 for (i = len - 1; i >= 0; i--)
2215 if (GET_CODE (XVECEXP (pat, 0, i)) == USE
2216 && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0))
2218 has_use_labelref = 1;
2220 if (! has_use_labelref)
2221 for (i = len - 1; i >= 0; i--)
2222 if (GET_CODE (XVECEXP (pat, 0, i)) == SET
2223 && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx
2224 && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat, 0, i))))
2227 else if (GET_CODE (pat) == SET
2228 && SET_DEST (pat) == pc_rtx
2229 && jmp_uses_reg_or_mem (SET_SRC (pat)))
2235 /* Traverse X via depth-first search, calling F for each
2236 sub-expression (including X itself). F is also passed the DATA.
2237 If F returns -1, do not traverse sub-expressions, but continue
2238 traversing the rest of the tree. If F ever returns any other
2239 non-zero value, stop the traversal, and return the value returned
2240 by F. Otherwise, return 0. This function does not traverse inside
2241 tree structure that contains RTX_EXPRs, or into sub-expressions
2242 whose format code is `0' since it is not known whether or not those
2243 codes are actually RTL.
2245 This routine is very general, and could (should?) be used to
2246 implement many of the other routines in this file. */
2249 for_each_rtx (x, f, data)
2260 result = (*f)(x, data);
2262 /* Do not traverse sub-expressions. */
2264 else if (result != 0)
2265 /* Stop the traversal. */
2269 /* There are no sub-expressions. */
2272 length = GET_RTX_LENGTH (GET_CODE (*x));
2273 format = GET_RTX_FORMAT (GET_CODE (*x));
2275 for (i = 0; i < length; ++i)
2280 result = for_each_rtx (&XEXP (*x, i), f, data);
2287 if (XVEC (*x, i) != 0)
2290 for (j = 0; j < XVECLEN (*x, i); ++j)
2292 result = for_each_rtx (&XVECEXP (*x, i, j), f, data);
2300 /* Nothing to do. */
2309 /* Searches X for any reference to REGNO, returning the rtx of the
2310 reference found if any. Otherwise, returns NULL_RTX. */
2313 regno_use_in (regno, x)
2317 register const char *fmt;
2321 if (GET_CODE (x) == REG && REGNO (x) == regno)
2324 fmt = GET_RTX_FORMAT (GET_CODE (x));
2325 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2329 if ((tem = regno_use_in (regno, XEXP (x, i))))
2332 else if (fmt[i] == 'E')
2333 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2334 if ((tem = regno_use_in (regno , XVECEXP (x, i, j))))
2342 /* Return 1 if X is an autoincrement side effect and the register is
2343 not the stack pointer. */
2348 switch (GET_CODE (x))
2356 /* There are no REG_INC notes for SP. */
2357 if (XEXP (x, 0) != stack_pointer_rtx)
2365 /* Return 1 if the sequence of instructions beginning with FROM and up
2366 to and including TO is safe to move. If NEW_TO is non-NULL, and
2367 the sequence is not already safe to move, but can be easily
2368 extended to a sequence which is safe, then NEW_TO will point to the
2369 end of the extended sequence.
2371 For now, this function only checks that the region contains whole
2372 exception regiongs, but it could be extended to check additional
2373 conditions as well. */
2376 insns_safe_to_move_p (from, to, new_to)
2381 int eh_region_count = 0;
2385 /* By default, assume the end of the region will be what was
2392 if (GET_CODE (r) == NOTE)
2394 switch (NOTE_LINE_NUMBER (r))
2396 case NOTE_INSN_EH_REGION_BEG:
2400 case NOTE_INSN_EH_REGION_END:
2401 if (eh_region_count == 0)
2402 /* This sequence of instructions contains the end of
2403 an exception region, but not he beginning. Moving
2404 it will cause chaos. */
2415 /* If we've passed TO, and we see a non-note instruction, we
2416 can't extend the sequence to a movable sequence. */
2422 /* It's OK to move the sequence if there were matched sets of
2423 exception region notes. */
2424 return eh_region_count == 0;
2429 /* It's OK to move the sequence if there were matched sets of
2430 exception region notes. */
2431 if (past_to_p && eh_region_count == 0)
2437 /* Go to the next instruction. */
2444 /* Return non-zero if IN contains a piece of rtl that has the address LOC */
2446 loc_mentioned_in_p (loc, in)
2449 enum rtx_code code = GET_CODE (in);
2450 const char *fmt = GET_RTX_FORMAT (code);
2453 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2455 if (loc == &in->fld[i].rtx)
2459 if (loc_mentioned_in_p (loc, XEXP (in, i)))
2462 else if (fmt[i] == 'E')
2463 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
2464 if (loc_mentioned_in_p (loc, XVECEXP (in, i, j)))