1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 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 PROTO((rtx));
28 static void reg_set_p_1 PROTO((rtx, rtx));
29 static void reg_set_last_1 PROTO((rtx, rtx));
32 /* Forward declarations */
33 static int jmp_uses_reg_or_mem PROTO((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);
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);
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;
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;
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)))
407 return reg_overlap_mentioned_p (x, body);
410 return reg_overlap_mentioned_p (x, TRAP_CONDITION (body));
413 case UNSPEC_VOLATILE:
415 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
416 if (reg_referenced_p (x, XVECEXP (body, 0, i)))
425 /* Nonzero if register REG is referenced in an insn between
426 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
430 reg_referenced_between_p (reg, from_insn, to_insn)
431 rtx reg, from_insn, to_insn;
435 if (from_insn == to_insn)
438 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
439 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
440 && (reg_referenced_p (reg, PATTERN (insn))
441 || (GET_CODE (insn) == CALL_INSN
442 && find_reg_fusage (insn, USE, reg))))
447 /* Nonzero if register REG is set or clobbered in an insn between
448 FROM_INSN and TO_INSN (exclusive of those two). */
451 reg_set_between_p (reg, from_insn, to_insn)
452 rtx reg, from_insn, to_insn;
456 if (from_insn == to_insn)
459 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
460 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
461 && reg_set_p (reg, insn))
466 /* Internals of reg_set_between_p. */
468 static rtx reg_set_reg;
469 static int reg_set_flag;
474 rtx pat ATTRIBUTE_UNUSED;
476 /* We don't want to return 1 if X is a MEM that contains a register
477 within REG_SET_REG. */
479 if ((GET_CODE (x) != MEM)
480 && reg_overlap_mentioned_p (reg_set_reg, x))
485 reg_set_p (reg, insn)
490 /* We can be passed an insn or part of one. If we are passed an insn,
491 check if a side-effect of the insn clobbers REG. */
492 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
494 if (FIND_REG_INC_NOTE (insn, reg)
495 || (GET_CODE (insn) == CALL_INSN
496 /* We'd like to test call_used_regs here, but rtlanal.c can't
497 reference that variable due to its use in genattrtab. So
498 we'll just be more conservative.
500 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
501 information holds all clobbered registers. */
502 && ((GET_CODE (reg) == REG
503 && REGNO (reg) < FIRST_PSEUDO_REGISTER)
504 || GET_CODE (reg) == MEM
505 || find_reg_fusage (insn, CLOBBER, reg))))
508 body = PATTERN (insn);
513 note_stores (body, reg_set_p_1);
517 /* Similar to reg_set_between_p, but check all registers in X. Return 0
518 only if none of them are modified between START and END. Do not
519 consider non-registers one way or the other. */
522 regs_set_between_p (x, start, end)
526 enum rtx_code code = GET_CODE (x);
542 return reg_set_between_p (x, start, end);
548 fmt = GET_RTX_FORMAT (code);
549 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
551 if (fmt[i] == 'e' && regs_set_between_p (XEXP (x, i), start, end))
554 else if (fmt[i] == 'E')
555 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
556 if (regs_set_between_p (XVECEXP (x, i, j), start, end))
563 /* Similar to reg_set_between_p, but check all registers in X. Return 0
564 only if none of them are modified between START and END. Return 1 if
565 X contains a MEM; this routine does not perform any memory aliasing. */
568 modified_between_p (x, start, end)
572 enum rtx_code code = GET_CODE (x);
590 /* If the memory is not constant, assume it is modified. If it is
591 constant, we still have to check the address. */
592 if (! RTX_UNCHANGING_P (x))
597 return reg_set_between_p (x, start, end);
603 fmt = GET_RTX_FORMAT (code);
604 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
606 if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end))
610 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
611 if (modified_between_p (XVECEXP (x, i, j), start, end))
618 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
619 of them are modified in INSN. Return 1 if X contains a MEM; this routine
620 does not perform any memory aliasing. */
623 modified_in_p (x, insn)
627 enum rtx_code code = GET_CODE (x);
645 /* If the memory is not constant, assume it is modified. If it is
646 constant, we still have to check the address. */
647 if (! RTX_UNCHANGING_P (x))
652 return reg_set_p (x, insn);
658 fmt = GET_RTX_FORMAT (code);
659 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
661 if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn))
665 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
666 if (modified_in_p (XVECEXP (x, i, j), insn))
673 /* Given an INSN, return a SET expression if this insn has only a single SET.
674 It may also have CLOBBERs, USEs, or SET whose output
675 will not be used, which we ignore. */
684 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
687 if (GET_CODE (PATTERN (insn)) == SET)
688 return PATTERN (insn);
690 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
692 for (i = 0, set = 0; i < XVECLEN (PATTERN (insn), 0); i++)
693 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET
694 && (! find_reg_note (insn, REG_UNUSED,
695 SET_DEST (XVECEXP (PATTERN (insn), 0, i)))
696 || side_effects_p (XVECEXP (PATTERN (insn), 0, i))))
701 set = XVECEXP (PATTERN (insn), 0, i);
709 /* Given an INSN, return nonzero if it has more than one SET, else return
719 /* INSN must be an insn. */
720 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
723 /* Only a PARALLEL can have multiple SETs. */
724 if (GET_CODE (PATTERN (insn)) == PARALLEL)
726 for (i = 0, found = 0; i < XVECLEN (PATTERN (insn), 0); i++)
727 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
729 /* If we have already found a SET, then return now. */
737 /* Either zero or one SET. */
741 /* Return the last thing that X was assigned from before *PINSN. Verify that
742 the object is not modified up to VALID_TO. If it was, if we hit
743 a partial assignment to X, or hit a CODE_LABEL first, return X. If we
744 found an assignment, update *PINSN to point to it.
745 ALLOW_HWREG is set to 1 if hardware registers are allowed to be the src. */
748 find_last_value (x, pinsn, valid_to, allow_hwreg)
756 for (p = PREV_INSN (*pinsn); p && GET_CODE (p) != CODE_LABEL;
758 if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
760 rtx set = single_set (p);
761 rtx note = find_reg_note (p, REG_EQUAL, NULL_RTX);
763 if (set && rtx_equal_p (x, SET_DEST (set)))
765 rtx src = SET_SRC (set);
767 if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
768 src = XEXP (note, 0);
770 if (! modified_between_p (src, PREV_INSN (p), valid_to)
771 /* Reject hard registers because we don't usually want
772 to use them; we'd rather use a pseudo. */
773 && (! (GET_CODE (src) == REG
774 && REGNO (src) < FIRST_PSEUDO_REGISTER) || allow_hwreg))
781 /* If set in non-simple way, we don't have a value. */
782 if (reg_set_p (x, p))
789 /* Return nonzero if register in range [REGNO, ENDREGNO)
790 appears either explicitly or implicitly in X
791 other than being stored into.
793 References contained within the substructure at LOC do not count.
794 LOC may be zero, meaning don't ignore anything. */
797 refers_to_regno_p (regno, endregno, x, loc)
803 register RTX_CODE code;
807 /* The contents of a REG_NONNEG note is always zero, so we must come here
808 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
819 /* If we modifying the stack, frame, or argument pointer, it will
820 clobber a virtual register. In fact, we could be more precise,
821 but it isn't worth it. */
822 if ((i == STACK_POINTER_REGNUM
823 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
824 || i == ARG_POINTER_REGNUM
826 || i == FRAME_POINTER_REGNUM)
827 && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER)
831 && regno < i + (i < FIRST_PSEUDO_REGISTER
832 ? HARD_REGNO_NREGS (i, GET_MODE (x))
836 /* If this is a SUBREG of a hard reg, we can see exactly which
837 registers are being modified. Otherwise, handle normally. */
838 if (GET_CODE (SUBREG_REG (x)) == REG
839 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
841 int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
843 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
844 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
846 return endregno > inner_regno && regno < inner_endregno;
852 if (&SET_DEST (x) != loc
853 /* Note setting a SUBREG counts as referring to the REG it is in for
854 a pseudo but not for hard registers since we can
855 treat each word individually. */
856 && ((GET_CODE (SET_DEST (x)) == SUBREG
857 && loc != &SUBREG_REG (SET_DEST (x))
858 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
859 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
860 && refers_to_regno_p (regno, endregno,
861 SUBREG_REG (SET_DEST (x)), loc))
862 || (GET_CODE (SET_DEST (x)) != REG
863 && refers_to_regno_p (regno, endregno, SET_DEST (x), loc))))
866 if (code == CLOBBER || loc == &SET_SRC (x))
875 /* X does not match, so try its subexpressions. */
877 fmt = GET_RTX_FORMAT (code);
878 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
880 if (fmt[i] == 'e' && loc != &XEXP (x, i))
888 if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc))
891 else if (fmt[i] == 'E')
894 for (j = XVECLEN (x, i) - 1; j >=0; j--)
895 if (loc != &XVECEXP (x, i, j)
896 && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc))
903 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
904 we check if any register number in X conflicts with the relevant register
905 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
906 contains a MEM (we don't bother checking for memory addresses that can't
907 conflict because we expect this to be a rare case. */
910 reg_overlap_mentioned_p (x, in)
915 /* Overly conservative. */
916 if (GET_CODE (x) == STRICT_LOW_PART)
919 /* If either argument is a constant, then modifying X can not affect IN. */
920 if (CONSTANT_P (x) || CONSTANT_P (in))
922 else if (GET_CODE (x) == SUBREG)
924 regno = REGNO (SUBREG_REG (x));
925 if (regno < FIRST_PSEUDO_REGISTER)
926 regno += SUBREG_WORD (x);
928 else if (GET_CODE (x) == REG)
930 else if (GET_CODE (x) == MEM)
935 if (GET_CODE (in) == MEM)
938 fmt = GET_RTX_FORMAT (GET_CODE (in));
940 for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--)
941 if (fmt[i] == 'e' && reg_overlap_mentioned_p (x, XEXP (in, i)))
946 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
947 || GET_CODE (x) == CC0)
948 return reg_mentioned_p (x, in);
949 else if (GET_CODE (x) == PARALLEL
950 && GET_MODE (x) == BLKmode)
954 /* If any register in here refers to it
956 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
957 if (reg_overlap_mentioned_p (SET_DEST (XVECEXP (x, 0, i)), in))
964 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
965 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
967 return refers_to_regno_p (regno, endregno, in, NULL_PTR);
970 /* Used for communications between the next few functions. */
972 static int reg_set_last_unknown;
973 static rtx reg_set_last_value;
974 static int reg_set_last_first_regno, reg_set_last_last_regno;
976 /* Called via note_stores from reg_set_last. */
979 reg_set_last_1 (x, pat)
985 /* If X is not a register, or is not one in the range we care
987 if (GET_CODE (x) != REG)
991 last = first + (first < FIRST_PSEUDO_REGISTER
992 ? HARD_REGNO_NREGS (first, GET_MODE (x)) : 1);
994 if (first >= reg_set_last_last_regno
995 || last <= reg_set_last_first_regno)
998 /* If this is a CLOBBER or is some complex LHS, or doesn't modify
999 exactly the registers we care about, show we don't know the value. */
1000 if (GET_CODE (pat) == CLOBBER || SET_DEST (pat) != x
1001 || first != reg_set_last_first_regno
1002 || last != reg_set_last_last_regno)
1003 reg_set_last_unknown = 1;
1005 reg_set_last_value = SET_SRC (pat);
1008 /* Return the last value to which REG was set prior to INSN. If we can't
1009 find it easily, return 0.
1011 We only return a REG, SUBREG, or constant because it is too hard to
1012 check if a MEM remains unchanged. */
1015 reg_set_last (x, insn)
1019 rtx orig_insn = insn;
1021 reg_set_last_first_regno = REGNO (x);
1023 reg_set_last_last_regno
1024 = reg_set_last_first_regno
1025 + (reg_set_last_first_regno < FIRST_PSEUDO_REGISTER
1026 ? HARD_REGNO_NREGS (reg_set_last_first_regno, GET_MODE (x)) : 1);
1028 reg_set_last_unknown = 0;
1029 reg_set_last_value = 0;
1031 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1032 Stop when we reach a label or X is a hard reg and we reach a
1033 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1035 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1037 /* We compare with <= here, because reg_set_last_last_regno
1038 is actually the number of the first reg *not* in X. */
1040 insn && GET_CODE (insn) != CODE_LABEL
1041 && ! (GET_CODE (insn) == CALL_INSN
1042 && reg_set_last_last_regno <= FIRST_PSEUDO_REGISTER);
1043 insn = PREV_INSN (insn))
1044 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1046 note_stores (PATTERN (insn), reg_set_last_1);
1047 if (reg_set_last_unknown)
1049 else if (reg_set_last_value)
1051 if (CONSTANT_P (reg_set_last_value)
1052 || ((GET_CODE (reg_set_last_value) == REG
1053 || GET_CODE (reg_set_last_value) == SUBREG)
1054 && ! reg_set_between_p (reg_set_last_value,
1056 return reg_set_last_value;
1065 /* This is 1 until after the rtl generation pass. */
1066 int rtx_equal_function_value_matters;
1068 /* Return 1 if X and Y are identical-looking rtx's.
1069 This is the Lisp function EQUAL for rtx arguments. */
1077 register enum rtx_code code;
1082 if (x == 0 || y == 0)
1085 code = GET_CODE (x);
1086 /* Rtx's of different codes cannot be equal. */
1087 if (code != GET_CODE (y))
1090 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
1091 (REG:SI x) and (REG:HI x) are NOT equivalent. */
1093 if (GET_MODE (x) != GET_MODE (y))
1096 /* REG, LABEL_REF, and SYMBOL_REF can be compared nonrecursively. */
1099 /* Until rtl generation is complete, don't consider a reference to the
1100 return register of the current function the same as the return from a
1101 called function. This eases the job of function integration. Once the
1102 distinction is no longer needed, they can be considered equivalent. */
1103 return (REGNO (x) == REGNO (y)
1104 && (! rtx_equal_function_value_matters
1105 || REG_FUNCTION_VALUE_P (x) == REG_FUNCTION_VALUE_P (y)));
1106 else if (code == LABEL_REF)
1107 return XEXP (x, 0) == XEXP (y, 0);
1108 else if (code == SYMBOL_REF)
1109 return XSTR (x, 0) == XSTR (y, 0);
1110 else if (code == SCRATCH || code == CONST_DOUBLE)
1113 /* Compare the elements. If any pair of corresponding elements
1114 fail to match, return 0 for the whole things. */
1116 fmt = GET_RTX_FORMAT (code);
1117 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1122 if (XWINT (x, i) != XWINT (y, i))
1128 if (XINT (x, i) != XINT (y, i))
1134 /* Two vectors must have the same length. */
1135 if (XVECLEN (x, i) != XVECLEN (y, i))
1138 /* And the corresponding elements must match. */
1139 for (j = 0; j < XVECLEN (x, i); j++)
1140 if (rtx_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)) == 0)
1145 if (rtx_equal_p (XEXP (x, i), XEXP (y, i)) == 0)
1151 if (strcmp (XSTR (x, i), XSTR (y, i)))
1156 /* These are just backpointers, so they don't matter. */
1162 /* It is believed that rtx's at this level will never
1163 contain anything but integers and other rtx's,
1164 except for within LABEL_REFs and SYMBOL_REFs. */
1172 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1173 (X would be the pattern of an insn).
1174 FUN receives two arguments:
1175 the REG, MEM, CC0 or PC being stored in or clobbered,
1176 the SET or CLOBBER rtx that does the store.
1178 If the item being stored in or clobbered is a SUBREG of a hard register,
1179 the SUBREG will be passed. */
1182 note_stores (x, fun)
1184 void (*fun) PROTO ((rtx, rtx));
1186 if ((GET_CODE (x) == SET || GET_CODE (x) == CLOBBER))
1188 register rtx dest = SET_DEST (x);
1189 while ((GET_CODE (dest) == SUBREG
1190 && (GET_CODE (SUBREG_REG (dest)) != REG
1191 || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER))
1192 || GET_CODE (dest) == ZERO_EXTRACT
1193 || GET_CODE (dest) == SIGN_EXTRACT
1194 || GET_CODE (dest) == STRICT_LOW_PART)
1195 dest = XEXP (dest, 0);
1197 if (GET_CODE (dest) == PARALLEL
1198 && GET_MODE (dest) == BLKmode)
1201 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
1202 (*fun) (SET_DEST (XVECEXP (dest, 0, i)), x);
1207 else if (GET_CODE (x) == PARALLEL)
1210 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1212 register rtx y = XVECEXP (x, 0, i);
1213 if (GET_CODE (y) == SET || GET_CODE (y) == CLOBBER)
1215 register rtx dest = SET_DEST (y);
1216 while ((GET_CODE (dest) == SUBREG
1217 && (GET_CODE (SUBREG_REG (dest)) != REG
1218 || (REGNO (SUBREG_REG (dest))
1219 >= FIRST_PSEUDO_REGISTER)))
1220 || GET_CODE (dest) == ZERO_EXTRACT
1221 || GET_CODE (dest) == SIGN_EXTRACT
1222 || GET_CODE (dest) == STRICT_LOW_PART)
1223 dest = XEXP (dest, 0);
1224 if (GET_CODE (dest) == PARALLEL
1225 && GET_MODE (dest) == BLKmode)
1228 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
1229 (*fun) (SET_DEST (XVECEXP (dest, 0, i)), y);
1238 /* Return nonzero if X's old contents don't survive after INSN.
1239 This will be true if X is (cc0) or if X is a register and
1240 X dies in INSN or because INSN entirely sets X.
1242 "Entirely set" means set directly and not through a SUBREG,
1243 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1244 Likewise, REG_INC does not count.
1246 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1247 but for this use that makes no difference, since regs don't overlap
1248 during their lifetimes. Therefore, this function may be used
1249 at any time after deaths have been computed (in flow.c).
1251 If REG is a hard reg that occupies multiple machine registers, this
1252 function will only return 1 if each of those registers will be replaced
1256 dead_or_set_p (insn, x)
1260 register int regno, last_regno;
1263 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1264 if (GET_CODE (x) == CC0)
1267 if (GET_CODE (x) != REG)
1271 last_regno = (regno >= FIRST_PSEUDO_REGISTER ? regno
1272 : regno + HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1);
1274 for (i = regno; i <= last_regno; i++)
1275 if (! dead_or_set_regno_p (insn, i))
1281 /* Utility function for dead_or_set_p to check an individual register. Also
1282 called from flow.c. */
1285 dead_or_set_regno_p (insn, test_regno)
1289 int regno, endregno;
1292 /* See if there is a death note for something that includes
1294 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1296 if (REG_NOTE_KIND (link) != REG_DEAD
1297 || GET_CODE (XEXP (link, 0)) != REG)
1300 regno = REGNO (XEXP (link, 0));
1301 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1302 : regno + HARD_REGNO_NREGS (regno,
1303 GET_MODE (XEXP (link, 0))));
1305 if (test_regno >= regno && test_regno < endregno)
1309 if (GET_CODE (insn) == CALL_INSN
1310 && find_regno_fusage (insn, CLOBBER, test_regno))
1313 if (GET_CODE (PATTERN (insn)) == SET)
1315 rtx dest = SET_DEST (PATTERN (insn));
1317 /* A value is totally replaced if it is the destination or the
1318 destination is a SUBREG of REGNO that does not change the number of
1320 if (GET_CODE (dest) == SUBREG
1321 && (((GET_MODE_SIZE (GET_MODE (dest))
1322 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1323 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1324 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1325 dest = SUBREG_REG (dest);
1327 if (GET_CODE (dest) != REG)
1330 regno = REGNO (dest);
1331 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1332 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1334 return (test_regno >= regno && test_regno < endregno);
1336 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
1340 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1342 rtx body = XVECEXP (PATTERN (insn), 0, i);
1344 if (GET_CODE (body) == SET || GET_CODE (body) == CLOBBER)
1346 rtx dest = SET_DEST (body);
1348 if (GET_CODE (dest) == SUBREG
1349 && (((GET_MODE_SIZE (GET_MODE (dest))
1350 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1351 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1352 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1353 dest = SUBREG_REG (dest);
1355 if (GET_CODE (dest) != REG)
1358 regno = REGNO (dest);
1359 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1360 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1362 if (test_regno >= regno && test_regno < endregno)
1371 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1372 If DATUM is nonzero, look for one whose datum is DATUM. */
1375 find_reg_note (insn, kind, datum)
1382 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1383 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
1386 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1387 if (REG_NOTE_KIND (link) == kind
1388 && (datum == 0 || datum == XEXP (link, 0)))
1393 /* Return the reg-note of kind KIND in insn INSN which applies to register
1394 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1395 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1396 it might be the case that the note overlaps REGNO. */
1399 find_regno_note (insn, kind, regno)
1406 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1407 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
1410 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1411 if (REG_NOTE_KIND (link) == kind
1412 /* Verify that it is a register, so that scratch and MEM won't cause a
1414 && GET_CODE (XEXP (link, 0)) == REG
1415 && REGNO (XEXP (link, 0)) <= regno
1416 && ((REGNO (XEXP (link, 0))
1417 + (REGNO (XEXP (link, 0)) >= FIRST_PSEUDO_REGISTER ? 1
1418 : HARD_REGNO_NREGS (REGNO (XEXP (link, 0)),
1419 GET_MODE (XEXP (link, 0)))))
1425 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1426 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1429 find_reg_fusage (insn, code, datum)
1434 /* If it's not a CALL_INSN, it can't possibly have a
1435 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1436 if (GET_CODE (insn) != CALL_INSN)
1442 if (GET_CODE (datum) != REG)
1446 for (link = CALL_INSN_FUNCTION_USAGE (insn);
1448 link = XEXP (link, 1))
1449 if (GET_CODE (XEXP (link, 0)) == code
1450 && rtx_equal_p (datum, SET_DEST (XEXP (link, 0))))
1455 register int regno = REGNO (datum);
1457 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1458 to pseudo registers, so don't bother checking. */
1460 if (regno < FIRST_PSEUDO_REGISTER)
1462 int end_regno = regno + HARD_REGNO_NREGS (regno, GET_MODE (datum));
1465 for (i = regno; i < end_regno; i++)
1466 if (find_regno_fusage (insn, code, i))
1474 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1475 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1478 find_regno_fusage (insn, code, regno)
1485 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1486 to pseudo registers, so don't bother checking. */
1488 if (regno >= FIRST_PSEUDO_REGISTER
1489 || GET_CODE (insn) != CALL_INSN )
1492 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
1494 register int regnote;
1497 if (GET_CODE (op = XEXP (link, 0)) == code
1498 && GET_CODE (SET_DEST (op)) == REG
1499 && (regnote = REGNO (SET_DEST (op))) <= regno
1501 + HARD_REGNO_NREGS (regnote, GET_MODE (SET_DEST (op)))
1509 /* Remove register note NOTE from the REG_NOTES of INSN. */
1512 remove_note (insn, note)
1518 if (REG_NOTES (insn) == note)
1520 REG_NOTES (insn) = XEXP (note, 1);
1524 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1525 if (XEXP (link, 1) == note)
1527 XEXP (link, 1) = XEXP (note, 1);
1534 /* Search LISTP (an EXPR_LIST) for NODE and remove NODE from the list
1537 A simple equality test is used to determine if NODE is on the
1541 remove_node_from_expr_list (node, listp)
1546 rtx prev = NULL_RTX;
1550 if (node == XEXP (temp, 0))
1552 /* Splice the node out of the list. */
1554 XEXP (prev, 1) = XEXP (temp, 1);
1556 *listp = XEXP (temp, 1);
1560 temp = XEXP (temp, 1);
1564 /* Nonzero if X contains any volatile instructions. These are instructions
1565 which may cause unpredictable machine state instructions, and thus no
1566 instructions should be moved or combined across them. This includes
1567 only volatile asms and UNSPEC_VOLATILE instructions. */
1573 register RTX_CODE code;
1575 code = GET_CODE (x);
1595 case UNSPEC_VOLATILE:
1596 /* case TRAP_IF: This isn't clear yet. */
1600 if (MEM_VOLATILE_P (x))
1607 /* Recursively scan the operands of this expression. */
1610 register char *fmt = GET_RTX_FORMAT (code);
1613 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1617 if (volatile_insn_p (XEXP (x, i)))
1623 for (j = 0; j < XVECLEN (x, i); j++)
1624 if (volatile_insn_p (XVECEXP (x, i, j)))
1632 /* Nonzero if X contains any volatile memory references
1633 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1639 register RTX_CODE code;
1641 code = GET_CODE (x);
1660 case UNSPEC_VOLATILE:
1661 /* case TRAP_IF: This isn't clear yet. */
1666 if (MEM_VOLATILE_P (x))
1673 /* Recursively scan the operands of this expression. */
1676 register char *fmt = GET_RTX_FORMAT (code);
1679 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1683 if (volatile_refs_p (XEXP (x, i)))
1689 for (j = 0; j < XVECLEN (x, i); j++)
1690 if (volatile_refs_p (XVECEXP (x, i, j)))
1698 /* Similar to above, except that it also rejects register pre- and post-
1705 register RTX_CODE code;
1707 code = GET_CODE (x);
1725 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1726 when some combination can't be done. If we see one, don't think
1727 that we can simplify the expression. */
1728 return (GET_MODE (x) != VOIDmode);
1735 case UNSPEC_VOLATILE:
1736 /* case TRAP_IF: This isn't clear yet. */
1741 if (MEM_VOLATILE_P (x))
1748 /* Recursively scan the operands of this expression. */
1751 register char *fmt = GET_RTX_FORMAT (code);
1754 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1758 if (side_effects_p (XEXP (x, i)))
1764 for (j = 0; j < XVECLEN (x, i); j++)
1765 if (side_effects_p (XVECEXP (x, i, j)))
1773 /* Return nonzero if evaluating rtx X might cause a trap. */
1785 code = GET_CODE (x);
1788 /* Handle these cases quickly. */
1800 /* Conditional trap can trap! */
1801 case UNSPEC_VOLATILE:
1805 /* Memory ref can trap unless it's a static var or a stack slot. */
1807 return rtx_addr_can_trap_p (XEXP (x, 0));
1809 /* Division by a non-constant might trap. */
1814 if (! CONSTANT_P (XEXP (x, 1))
1815 || GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1817 /* This was const0_rtx, but by not using that,
1818 we can link this file into other programs. */
1819 if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
1824 /* An EXPR_LIST is used to represent a function call. This
1825 certainly may trap. */
1829 /* Any floating arithmetic may trap. */
1830 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1834 fmt = GET_RTX_FORMAT (code);
1835 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1839 if (may_trap_p (XEXP (x, i)))
1842 else if (fmt[i] == 'E')
1845 for (j = 0; j < XVECLEN (x, i); j++)
1846 if (may_trap_p (XVECEXP (x, i, j)))
1853 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1854 i.e., an inequality. */
1857 inequality_comparisons_p (x)
1861 register int len, i;
1862 register enum rtx_code code = GET_CODE (x);
1891 len = GET_RTX_LENGTH (code);
1892 fmt = GET_RTX_FORMAT (code);
1894 for (i = 0; i < len; i++)
1898 if (inequality_comparisons_p (XEXP (x, i)))
1901 else if (fmt[i] == 'E')
1904 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1905 if (inequality_comparisons_p (XVECEXP (x, i, j)))
1913 /* Replace any occurrence of FROM in X with TO. The function does
1914 not enter into CONST_DOUBLE for the replace.
1916 Note that copying is not done so X must not be shared unless all copies
1917 are to be modified. */
1920 replace_rtx (x, from, to)
1926 /* The following prevents loops occurrence when we change MEM in
1927 CONST_DOUBLE onto the same CONST_DOUBLE. */
1928 if (x != 0 && GET_CODE (x) == CONST_DOUBLE)
1934 /* Allow this function to make replacements in EXPR_LISTs. */
1938 fmt = GET_RTX_FORMAT (GET_CODE (x));
1939 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
1942 XEXP (x, i) = replace_rtx (XEXP (x, i), from, to);
1943 else if (fmt[i] == 'E')
1944 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1945 XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to);
1951 /* Throughout the rtx X, replace many registers according to REG_MAP.
1952 Return the replacement for X (which may be X with altered contents).
1953 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
1954 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
1956 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
1957 should not be mapped to pseudos or vice versa since validate_change
1960 If REPLACE_DEST is 1, replacements are also done in destinations;
1961 otherwise, only sources are replaced. */
1964 replace_regs (x, reg_map, nregs, replace_dest)
1970 register enum rtx_code code;
1977 code = GET_CODE (x);
1991 /* Verify that the register has an entry before trying to access it. */
1992 if (REGNO (x) < nregs && reg_map[REGNO (x)] != 0)
1994 /* SUBREGs can't be shared. Always return a copy to ensure that if
1995 this replacement occurs more than once then each instance will
1996 get distinct rtx. */
1997 if (GET_CODE (reg_map[REGNO (x)]) == SUBREG)
1998 return copy_rtx (reg_map[REGNO (x)]);
1999 return reg_map[REGNO (x)];
2004 /* Prevent making nested SUBREGs. */
2005 if (GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) < nregs
2006 && reg_map[REGNO (SUBREG_REG (x))] != 0
2007 && GET_CODE (reg_map[REGNO (SUBREG_REG (x))]) == SUBREG)
2009 rtx map_val = reg_map[REGNO (SUBREG_REG (x))];
2010 rtx map_inner = SUBREG_REG (map_val);
2012 if (GET_MODE (x) == GET_MODE (map_inner))
2016 /* We cannot call gen_rtx here since we may be linked with
2018 /* Let's try clobbering the incoming SUBREG and see
2019 if this is really safe. */
2020 SUBREG_REG (x) = map_inner;
2021 SUBREG_WORD (x) += SUBREG_WORD (map_val);
2024 rtx new = rtx_alloc (SUBREG);
2025 PUT_MODE (new, GET_MODE (x));
2026 SUBREG_REG (new) = map_inner;
2027 SUBREG_WORD (new) = SUBREG_WORD (x) + SUBREG_WORD (map_val);
2035 SET_DEST (x) = replace_regs (SET_DEST (x), reg_map, nregs, 0);
2037 else if (GET_CODE (SET_DEST (x)) == MEM
2038 || GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2039 /* Even if we are not to replace destinations, replace register if it
2040 is CONTAINED in destination (destination is memory or
2041 STRICT_LOW_PART). */
2042 XEXP (SET_DEST (x), 0) = replace_regs (XEXP (SET_DEST (x), 0),
2044 else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2045 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2048 SET_SRC (x) = replace_regs (SET_SRC (x), reg_map, nregs, 0);
2055 fmt = GET_RTX_FORMAT (code);
2056 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2059 XEXP (x, i) = replace_regs (XEXP (x, i), reg_map, nregs, replace_dest);
2063 for (j = 0; j < XVECLEN (x, i); j++)
2064 XVECEXP (x, i, j) = replace_regs (XVECEXP (x, i, j), reg_map,
2065 nregs, replace_dest);
2071 /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is
2072 not in the constant pool and not in the condition of an IF_THEN_ELSE. */
2075 jmp_uses_reg_or_mem (x)
2078 enum rtx_code code = GET_CODE (x);
2093 return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
2094 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
2097 return (jmp_uses_reg_or_mem (XEXP (x, 1))
2098 || jmp_uses_reg_or_mem (XEXP (x, 2)));
2100 case PLUS: case MINUS: case MULT:
2101 return (jmp_uses_reg_or_mem (XEXP (x, 0))
2102 || jmp_uses_reg_or_mem (XEXP (x, 1)));
2108 fmt = GET_RTX_FORMAT (code);
2109 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2112 && jmp_uses_reg_or_mem (XEXP (x, i)))
2116 for (j = 0; j < XVECLEN (x, i); j++)
2117 if (jmp_uses_reg_or_mem (XVECEXP (x, i, j)))
2124 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2126 Tablejumps and casesi insns are not considered indirect jumps;
2127 we can recognize them by a (use (lael_ref)). */
2130 computed_jump_p (insn)
2134 if (GET_CODE (insn) == JUMP_INSN)
2136 rtx pat = PATTERN (insn);
2138 if (GET_CODE (pat) == PARALLEL)
2140 int len = XVECLEN (pat, 0);
2141 int has_use_labelref = 0;
2143 for (i = len - 1; i >= 0; i--)
2144 if (GET_CODE (XVECEXP (pat, 0, i)) == USE
2145 && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0))
2147 has_use_labelref = 1;
2149 if (! has_use_labelref)
2150 for (i = len - 1; i >= 0; i--)
2151 if (GET_CODE (XVECEXP (pat, 0, i)) == SET
2152 && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx
2153 && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat, 0, i))))
2156 else if (GET_CODE (pat) == SET
2157 && SET_DEST (pat) == pc_rtx
2158 && jmp_uses_reg_or_mem (SET_SRC (pat)))
2164 /* Traverse X via depth-first search, calling F for each
2165 sub-expression (including X itself). F is also passed the DATA.
2166 If F returns -1, do not traverse sub-expressions, but continue
2167 traversing the rest of the tree. If F ever returns any other
2168 non-zero value, stop the traversal, and return the value returned
2169 by F. Otherwise, return 0. This function does not traverse inside
2170 tree structure that contains RTX_EXPRs, or into sub-expressions
2171 whose format code is `0' since it is not known whether or not those
2172 codes are actually RTL.
2174 This routine is very general, and could (should?) be used to
2175 implement many of the other routines in this file. */
2178 for_each_rtx (x, f, data)
2189 result = (*f)(x, data);
2191 /* Do not traverse sub-expressions. */
2193 else if (result != 0)
2194 /* Stop the traversal. */
2198 /* There are no sub-expressions. */
2201 length = GET_RTX_LENGTH (GET_CODE (*x));
2202 format = GET_RTX_FORMAT (GET_CODE (*x));
2204 for (i = 0; i < length; ++i)
2209 result = for_each_rtx (&XEXP (*x, i), f, data);
2216 if (XVEC (*x, i) != 0)
2219 for (j = 0; j < XVECLEN (*x, i); ++j)
2221 result = for_each_rtx (&XVECEXP (*x, i, j), f, data);
2229 /* Nothing to do. */
2238 /* Searches X for any reference to REGNO, returning the rtx of the
2239 reference found if any. Otherwise, returns NULL_RTX. */
2242 regno_use_in (regno, x)
2250 if (GET_CODE (x) == REG && REGNO (x) == regno)
2253 fmt = GET_RTX_FORMAT (GET_CODE (x));
2254 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2258 if ((tem = regno_use_in (regno, XEXP (x, i))))
2261 else if (fmt[i] == 'E')
2262 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2263 if ((tem = regno_use_in (regno , XVECEXP (x, i, j))))
2271 /* Return 1 if X is an autoincrement side effect and the register is
2272 not the stack pointer. */
2277 switch (GET_CODE (x))
2285 /* There are no REG_INC notes for SP. */
2286 if (XEXP (x, 0) != stack_pointer_rtx)
2294 /* Return 1 if the sequence of instructions beginning with FROM and up
2295 to and including TO is safe to move. If NEW_TO is non-NULL, and
2296 the sequence is not already safe to move, but can be easily
2297 extended to a sequence which is safe, then NEW_TO will point to the
2298 end of the extended sequence.
2300 For now, this function only checks that the region contains whole
2301 exception regiongs, but it could be extended to check additional
2302 conditions as well. */
2305 insns_safe_to_move_p (from, to, new_to)
2310 int eh_region_count = 0;
2314 /* By default, assume the end of the region will be what was
2321 if (GET_CODE (r) == NOTE)
2323 switch (NOTE_LINE_NUMBER (r))
2325 case NOTE_INSN_EH_REGION_BEG:
2329 case NOTE_INSN_EH_REGION_END:
2330 if (eh_region_count == 0)
2331 /* This sequence of instructions contains the end of
2332 an exception region, but not he beginning. Moving
2333 it will cause chaos. */
2344 /* If we've passed TO, and we see a non-note instruction, we
2345 can't extend the sequence to a movable sequence. */
2351 /* It's OK to move the sequence if there were matched sets of
2352 exception region notes. */
2353 return eh_region_count == 0;
2358 /* It's OK to move the sequence if there were matched sets of
2359 exception region notes. */
2360 if (past_to_p && eh_region_count == 0)
2366 /* Go to the next instruction. */