1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 88, 9-5, 1996 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
29 /* Forward declarations */
30 static int jmp_uses_reg_or_mem PROTO((rtx));
32 /* Bit flags that specify the machine subtype we are compiling for.
33 Bits are tested using macros TARGET_... defined in the tm.h file
34 and set by `-m...' switches. Must be defined in rtlanal.c. */
38 /* Return 1 if the value of X is unstable
39 (would be different at a different point in the program).
40 The frame pointer, arg pointer, etc. are considered stable
41 (within one function) and so is anything marked `unchanging'. */
47 register RTX_CODE code = GET_CODE (x);
52 return ! RTX_UNCHANGING_P (x);
57 if (code == CONST || code == CONST_INT)
61 return ! (REGNO (x) == FRAME_POINTER_REGNUM
62 || REGNO (x) == HARD_FRAME_POINTER_REGNUM
63 || REGNO (x) == ARG_POINTER_REGNUM
64 || RTX_UNCHANGING_P (x));
66 fmt = GET_RTX_FORMAT (code);
67 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
69 if (rtx_unstable_p (XEXP (x, i)))
74 /* Return 1 if X has a value that can vary even between two
75 executions of the program. 0 means X can be compared reliably
76 against certain constants or near-constants.
77 The frame pointer and the arg pointer are considered constant. */
83 register RTX_CODE code = GET_CODE (x);
101 /* Note that we have to test for the actual rtx used for the frame
102 and arg pointers and not just the register number in case we have
103 eliminated the frame and/or arg pointer and are using it
105 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
106 || x == arg_pointer_rtx);
109 /* The operand 0 of a LO_SUM is considered constant
110 (in fact is it related specifically to operand 1). */
111 return rtx_varies_p (XEXP (x, 1));
114 fmt = GET_RTX_FORMAT (code);
115 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
117 if (rtx_varies_p (XEXP (x, i)))
122 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
125 rtx_addr_can_trap_p (x)
128 register enum rtx_code code = GET_CODE (x);
134 /* SYMBOL_REF is problematic due to the possible presence of
135 a #pragma weak, but to say that loads from symbols can trap is
136 *very* costly. It's not at all clear what's best here. For
137 now, we ignore the impact of #pragma weak. */
141 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
142 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
143 || x == stack_pointer_rtx || x == arg_pointer_rtx);
146 return rtx_addr_can_trap_p (XEXP (x, 0));
149 /* An address is assumed not to trap if it is an address that can't
150 trap plus a constant integer. */
151 return (rtx_addr_can_trap_p (XEXP (x, 0))
152 || GET_CODE (XEXP (x, 1)) != CONST_INT);
155 return rtx_addr_can_trap_p (XEXP (x, 1));
158 /* If it isn't one of the case above, it can cause a trap. */
162 /* Return 1 if X refers to a memory location whose address
163 cannot be compared reliably with constant addresses,
164 or if X refers to a BLKmode memory object. */
167 rtx_addr_varies_p (x)
170 register enum rtx_code code;
179 return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0));
181 fmt = GET_RTX_FORMAT (code);
182 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
185 if (rtx_addr_varies_p (XEXP (x, i)))
188 else if (fmt[i] == 'E')
191 for (j = 0; j < XVECLEN (x, i); j++)
192 if (rtx_addr_varies_p (XVECEXP (x, i, j)))
198 /* Return the value of the integer term in X, if one is apparent;
200 Only obvious integer terms are detected.
201 This is used in cse.c with the `related_value' field.*/
207 if (GET_CODE (x) == CONST)
210 if (GET_CODE (x) == MINUS
211 && GET_CODE (XEXP (x, 1)) == CONST_INT)
212 return - INTVAL (XEXP (x, 1));
213 if (GET_CODE (x) == PLUS
214 && GET_CODE (XEXP (x, 1)) == CONST_INT)
215 return INTVAL (XEXP (x, 1));
219 /* If X is a constant, return the value sans apparent integer term;
221 Only obvious integer terms are detected. */
224 get_related_value (x)
227 if (GET_CODE (x) != CONST)
230 if (GET_CODE (x) == PLUS
231 && GET_CODE (XEXP (x, 1)) == CONST_INT)
233 else if (GET_CODE (x) == MINUS
234 && GET_CODE (XEXP (x, 1)) == CONST_INT)
239 /* Nonzero if register REG appears somewhere within IN.
240 Also works if REG is not a register; in this case it checks
241 for a subexpression of IN that is Lisp "equal" to REG. */
244 reg_mentioned_p (reg, in)
245 register rtx reg, in;
249 register enum rtx_code code;
257 if (GET_CODE (in) == LABEL_REF)
258 return reg == XEXP (in, 0);
260 code = GET_CODE (in);
264 /* Compare registers by number. */
266 return GET_CODE (reg) == REG && REGNO (in) == REGNO (reg);
268 /* These codes have no constituent expressions
276 return GET_CODE (reg) == CONST_INT && INTVAL (in) == INTVAL (reg);
279 /* These are kept unique for a given value. */
283 if (GET_CODE (reg) == code && rtx_equal_p (reg, in))
286 fmt = GET_RTX_FORMAT (code);
288 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
293 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
294 if (reg_mentioned_p (reg, XVECEXP (in, i, j)))
297 else if (fmt[i] == 'e'
298 && reg_mentioned_p (reg, XEXP (in, i)))
304 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
305 no CODE_LABEL insn. */
308 no_labels_between_p (beg, end)
312 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
313 if (GET_CODE (p) == CODE_LABEL)
318 /* Nonzero if register REG is used in an insn between
319 FROM_INSN and TO_INSN (exclusive of those two). */
322 reg_used_between_p (reg, from_insn, to_insn)
323 rtx reg, from_insn, to_insn;
327 if (from_insn == to_insn)
330 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
331 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
332 && (reg_overlap_mentioned_p (reg, PATTERN (insn))
333 || (GET_CODE (insn) == CALL_INSN
334 && (find_reg_fusage (insn, USE, reg)
335 || find_reg_fusage (insn, CLOBBER, reg)))))
340 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
341 is entirely replaced by a new value and the only use is as a SET_DEST,
342 we do not consider it a reference. */
345 reg_referenced_p (x, body)
351 switch (GET_CODE (body))
354 if (reg_overlap_mentioned_p (x, SET_SRC (body)))
357 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
358 of a REG that occupies all of the REG, the insn references X if
359 it is mentioned in the destination. */
360 if (GET_CODE (SET_DEST (body)) != CC0
361 && GET_CODE (SET_DEST (body)) != PC
362 && GET_CODE (SET_DEST (body)) != REG
363 && ! (GET_CODE (SET_DEST (body)) == SUBREG
364 && GET_CODE (SUBREG_REG (SET_DEST (body))) == REG
365 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body))))
366 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
367 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body)))
368 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
369 && reg_overlap_mentioned_p (x, SET_DEST (body)))
374 for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
375 if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i)))
381 return reg_overlap_mentioned_p (x, body);
384 return reg_overlap_mentioned_p (x, TRAP_CONDITION (body));
387 case UNSPEC_VOLATILE:
389 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
390 if (reg_referenced_p (x, XVECEXP (body, 0, i)))
398 /* Nonzero if register REG is referenced in an insn between
399 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
403 reg_referenced_between_p (reg, from_insn, to_insn)
404 rtx reg, from_insn, to_insn;
408 if (from_insn == to_insn)
411 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
412 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
413 && (reg_referenced_p (reg, PATTERN (insn))
414 || (GET_CODE (insn) == CALL_INSN
415 && find_reg_fusage (insn, USE, reg))))
420 /* Nonzero if register REG is set or clobbered in an insn between
421 FROM_INSN and TO_INSN (exclusive of those two). */
424 reg_set_between_p (reg, from_insn, to_insn)
425 rtx reg, from_insn, to_insn;
429 if (from_insn == to_insn)
432 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
433 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
434 && reg_set_p (reg, insn))
439 /* Internals of reg_set_between_p. */
441 static rtx reg_set_reg;
442 static int reg_set_flag;
448 /* We don't want to return 1 if X is a MEM that contains a register
449 within REG_SET_REG. */
451 if ((GET_CODE (x) != MEM)
452 && reg_overlap_mentioned_p (reg_set_reg, x))
457 reg_set_p (reg, insn)
462 /* We can be passed an insn or part of one. If we are passed an insn,
463 check if a side-effect of the insn clobbers REG. */
464 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
466 if (FIND_REG_INC_NOTE (insn, reg)
467 || (GET_CODE (insn) == CALL_INSN
468 /* We'd like to test call_used_regs here, but rtlanal.c can't
469 reference that variable due to its use in genattrtab. So
470 we'll just be more conservative.
472 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
473 information holds all clobbered registers. */
474 && ((GET_CODE (reg) == REG
475 && REGNO (reg) < FIRST_PSEUDO_REGISTER)
476 || GET_CODE (reg) == MEM
477 || find_reg_fusage (insn, CLOBBER, reg))))
480 body = PATTERN (insn);
485 note_stores (body, reg_set_p_1);
489 /* Similar to reg_set_between_p, but check all registers in X. Return 0
490 only if none of them are modified between START and END. Return 1 if
491 X contains a MEM; this routine does not perform any memory aliasing. */
494 modified_between_p (x, start, end)
498 enum rtx_code code = GET_CODE (x);
516 /* If the memory is not constant, assume it is modified. If it is
517 constant, we still have to check the address. */
518 if (! RTX_UNCHANGING_P (x))
523 return reg_set_between_p (x, start, end);
526 fmt = GET_RTX_FORMAT (code);
527 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
529 if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end))
533 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
534 if (modified_between_p (XVECEXP (x, i, j), start, end))
541 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
542 of them are modified in INSN. Return 1 if X contains a MEM; this routine
543 does not perform any memory aliasing. */
546 modified_in_p (x, insn)
550 enum rtx_code code = GET_CODE (x);
568 /* If the memory is not constant, assume it is modified. If it is
569 constant, we still have to check the address. */
570 if (! RTX_UNCHANGING_P (x))
575 return reg_set_p (x, insn);
578 fmt = GET_RTX_FORMAT (code);
579 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
581 if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn))
585 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
586 if (modified_in_p (XVECEXP (x, i, j), insn))
593 /* Given an INSN, return a SET expression if this insn has only a single SET.
594 It may also have CLOBBERs, USEs, or SET whose output
595 will not be used, which we ignore. */
604 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
607 if (GET_CODE (PATTERN (insn)) == SET)
608 return PATTERN (insn);
610 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
612 for (i = 0, set = 0; i < XVECLEN (PATTERN (insn), 0); i++)
613 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET
614 && (! find_reg_note (insn, REG_UNUSED,
615 SET_DEST (XVECEXP (PATTERN (insn), 0, i)))
616 || side_effects_p (XVECEXP (PATTERN (insn), 0, i))))
621 set = XVECEXP (PATTERN (insn), 0, i);
629 /* Return the last thing that X was assigned from before *PINSN. Verify that
630 the object is not modified up to VALID_TO. If it was, if we hit
631 a partial assignment to X, or hit a CODE_LABEL first, return X. If we
632 found an assignment, update *PINSN to point to it. */
635 find_last_value (x, pinsn, valid_to)
642 for (p = PREV_INSN (*pinsn); p && GET_CODE (p) != CODE_LABEL;
644 if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
646 rtx set = single_set (p);
647 rtx note = find_reg_note (p, REG_EQUAL, NULL_RTX);
649 if (set && rtx_equal_p (x, SET_DEST (set)))
651 rtx src = SET_SRC (set);
653 if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
654 src = XEXP (note, 0);
656 if (! modified_between_p (src, PREV_INSN (p), valid_to)
657 /* Reject hard registers because we don't usually want
658 to use them; we'd rather use a pseudo. */
659 && ! (GET_CODE (src) == REG
660 && REGNO (src) < FIRST_PSEUDO_REGISTER))
667 /* If set in non-simple way, we don't have a value. */
668 if (reg_set_p (x, p))
675 /* Return nonzero if register in range [REGNO, ENDREGNO)
676 appears either explicitly or implicitly in X
677 other than being stored into.
679 References contained within the substructure at LOC do not count.
680 LOC may be zero, meaning don't ignore anything. */
683 refers_to_regno_p (regno, endregno, x, loc)
689 register RTX_CODE code;
693 /* The contents of a REG_NONNEG note is always zero, so we must come here
694 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
705 /* If we modifying the stack, frame, or argument pointer, it will
706 clobber a virtual register. In fact, we could be more precise,
707 but it isn't worth it. */
708 if ((i == STACK_POINTER_REGNUM
709 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
710 || i == ARG_POINTER_REGNUM
712 || i == FRAME_POINTER_REGNUM)
713 && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER)
717 && regno < i + (i < FIRST_PSEUDO_REGISTER
718 ? HARD_REGNO_NREGS (i, GET_MODE (x))
722 /* If this is a SUBREG of a hard reg, we can see exactly which
723 registers are being modified. Otherwise, handle normally. */
724 if (GET_CODE (SUBREG_REG (x)) == REG
725 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
727 int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
729 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
730 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
732 return endregno > inner_regno && regno < inner_endregno;
738 if (&SET_DEST (x) != loc
739 /* Note setting a SUBREG counts as referring to the REG it is in for
740 a pseudo but not for hard registers since we can
741 treat each word individually. */
742 && ((GET_CODE (SET_DEST (x)) == SUBREG
743 && loc != &SUBREG_REG (SET_DEST (x))
744 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
745 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
746 && refers_to_regno_p (regno, endregno,
747 SUBREG_REG (SET_DEST (x)), loc))
748 || (GET_CODE (SET_DEST (x)) != REG
749 && refers_to_regno_p (regno, endregno, SET_DEST (x), loc))))
752 if (code == CLOBBER || loc == &SET_SRC (x))
758 /* X does not match, so try its subexpressions. */
760 fmt = GET_RTX_FORMAT (code);
761 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
763 if (fmt[i] == 'e' && loc != &XEXP (x, i))
771 if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc))
774 else if (fmt[i] == 'E')
777 for (j = XVECLEN (x, i) - 1; j >=0; j--)
778 if (loc != &XVECEXP (x, i, j)
779 && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc))
786 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
787 we check if any register number in X conflicts with the relevant register
788 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
789 contains a MEM (we don't bother checking for memory addresses that can't
790 conflict because we expect this to be a rare case. */
793 reg_overlap_mentioned_p (x, in)
798 if (GET_CODE (x) == SUBREG)
800 regno = REGNO (SUBREG_REG (x));
801 if (regno < FIRST_PSEUDO_REGISTER)
802 regno += SUBREG_WORD (x);
804 else if (GET_CODE (x) == REG)
806 else if (CONSTANT_P (x))
808 else if (GET_CODE (x) == MEM)
813 if (GET_CODE (in) == MEM)
816 fmt = GET_RTX_FORMAT (GET_CODE (in));
818 for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--)
819 if (fmt[i] == 'e' && reg_overlap_mentioned_p (x, XEXP (in, i)))
824 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
825 || GET_CODE (x) == CC0)
826 return reg_mentioned_p (x, in);
830 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
831 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
833 return refers_to_regno_p (regno, endregno, in, NULL_PTR);
836 /* Used for communications between the next few functions. */
838 static int reg_set_last_unknown;
839 static rtx reg_set_last_value;
840 static int reg_set_last_first_regno, reg_set_last_last_regno;
842 /* Called via note_stores from reg_set_last. */
845 reg_set_last_1 (x, pat)
851 /* If X is not a register, or is not one in the range we care
853 if (GET_CODE (x) != REG)
857 last = first + (first < FIRST_PSEUDO_REGISTER
858 ? HARD_REGNO_NREGS (first, GET_MODE (x)) : 1);
860 if (first >= reg_set_last_last_regno
861 || last <= reg_set_last_first_regno)
864 /* If this is a CLOBBER or is some complex LHS, or doesn't modify
865 exactly the registers we care about, show we don't know the value. */
866 if (GET_CODE (pat) == CLOBBER || SET_DEST (pat) != x
867 || first != reg_set_last_first_regno
868 || last != reg_set_last_last_regno)
869 reg_set_last_unknown = 1;
871 reg_set_last_value = SET_SRC (pat);
874 /* Return the last value to which REG was set prior to INSN. If we can't
875 find it easily, return 0.
877 We only return a REG, SUBREG, or constant because it is too hard to
878 check if a MEM remains unchanged. */
881 reg_set_last (x, insn)
885 rtx orig_insn = insn;
887 reg_set_last_first_regno = REGNO (x);
889 reg_set_last_last_regno
890 = reg_set_last_first_regno
891 + (reg_set_last_first_regno < FIRST_PSEUDO_REGISTER
892 ? HARD_REGNO_NREGS (reg_set_last_first_regno, GET_MODE (x)) : 1);
894 reg_set_last_unknown = 0;
895 reg_set_last_value = 0;
897 /* Scan backwards until reg_set_last_1 changed one of the above flags.
898 Stop when we reach a label or X is a hard reg and we reach a
899 CALL_INSN (if reg_set_last_last_regno is a hard reg).
901 If we find a set of X, ensure that its SET_SRC remains unchanged. */
903 /* We compare with <= here, because reg_set_last_last_regno
904 is actually the number of the first reg *not* in X. */
906 insn && GET_CODE (insn) != CODE_LABEL
907 && ! (GET_CODE (insn) == CALL_INSN
908 && reg_set_last_last_regno <= FIRST_PSEUDO_REGISTER);
909 insn = PREV_INSN (insn))
910 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
912 note_stores (PATTERN (insn), reg_set_last_1);
913 if (reg_set_last_unknown)
915 else if (reg_set_last_value)
917 if (CONSTANT_P (reg_set_last_value)
918 || ((GET_CODE (reg_set_last_value) == REG
919 || GET_CODE (reg_set_last_value) == SUBREG)
920 && ! reg_set_between_p (reg_set_last_value,
922 return reg_set_last_value;
931 /* This is 1 until after the rtl generation pass. */
932 int rtx_equal_function_value_matters;
934 /* Return 1 if X and Y are identical-looking rtx's.
935 This is the Lisp function EQUAL for rtx arguments. */
943 register enum rtx_code code;
948 if (x == 0 || y == 0)
952 /* Rtx's of different codes cannot be equal. */
953 if (code != GET_CODE (y))
956 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
957 (REG:SI x) and (REG:HI x) are NOT equivalent. */
959 if (GET_MODE (x) != GET_MODE (y))
962 /* REG, LABEL_REF, and SYMBOL_REF can be compared nonrecursively. */
965 /* Until rtl generation is complete, don't consider a reference to the
966 return register of the current function the same as the return from a
967 called function. This eases the job of function integration. Once the
968 distinction is no longer needed, they can be considered equivalent. */
969 return (REGNO (x) == REGNO (y)
970 && (! rtx_equal_function_value_matters
971 || REG_FUNCTION_VALUE_P (x) == REG_FUNCTION_VALUE_P (y)));
972 else if (code == LABEL_REF)
973 return XEXP (x, 0) == XEXP (y, 0);
974 else if (code == SYMBOL_REF)
975 return XSTR (x, 0) == XSTR (y, 0);
976 else if (code == SCRATCH || code == CONST_DOUBLE)
979 /* Compare the elements. If any pair of corresponding elements
980 fail to match, return 0 for the whole things. */
982 fmt = GET_RTX_FORMAT (code);
983 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
988 if (XWINT (x, i) != XWINT (y, i))
994 if (XINT (x, i) != XINT (y, i))
1000 /* Two vectors must have the same length. */
1001 if (XVECLEN (x, i) != XVECLEN (y, i))
1004 /* And the corresponding elements must match. */
1005 for (j = 0; j < XVECLEN (x, i); j++)
1006 if (rtx_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)) == 0)
1011 if (rtx_equal_p (XEXP (x, i), XEXP (y, i)) == 0)
1017 if (strcmp (XSTR (x, i), XSTR (y, i)))
1022 /* These are just backpointers, so they don't matter. */
1028 /* It is believed that rtx's at this level will never
1029 contain anything but integers and other rtx's,
1030 except for within LABEL_REFs and SYMBOL_REFs. */
1038 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1039 (X would be the pattern of an insn).
1040 FUN receives two arguments:
1041 the REG, MEM, CC0 or PC being stored in or clobbered,
1042 the SET or CLOBBER rtx that does the store.
1044 If the item being stored in or clobbered is a SUBREG of a hard register,
1045 the SUBREG will be passed. */
1048 note_stores (x, fun)
1052 if ((GET_CODE (x) == SET || GET_CODE (x) == CLOBBER))
1054 register rtx dest = SET_DEST (x);
1055 while ((GET_CODE (dest) == SUBREG
1056 && (GET_CODE (SUBREG_REG (dest)) != REG
1057 || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER))
1058 || GET_CODE (dest) == ZERO_EXTRACT
1059 || GET_CODE (dest) == SIGN_EXTRACT
1060 || GET_CODE (dest) == STRICT_LOW_PART)
1061 dest = XEXP (dest, 0);
1064 else if (GET_CODE (x) == PARALLEL)
1067 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1069 register rtx y = XVECEXP (x, 0, i);
1070 if (GET_CODE (y) == SET || GET_CODE (y) == CLOBBER)
1072 register rtx dest = SET_DEST (y);
1073 while ((GET_CODE (dest) == SUBREG
1074 && (GET_CODE (SUBREG_REG (dest)) != REG
1075 || (REGNO (SUBREG_REG (dest))
1076 >= FIRST_PSEUDO_REGISTER)))
1077 || GET_CODE (dest) == ZERO_EXTRACT
1078 || GET_CODE (dest) == SIGN_EXTRACT
1079 || GET_CODE (dest) == STRICT_LOW_PART)
1080 dest = XEXP (dest, 0);
1087 /* Return nonzero if X's old contents don't survive after INSN.
1088 This will be true if X is (cc0) or if X is a register and
1089 X dies in INSN or because INSN entirely sets X.
1091 "Entirely set" means set directly and not through a SUBREG,
1092 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1093 Likewise, REG_INC does not count.
1095 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1096 but for this use that makes no difference, since regs don't overlap
1097 during their lifetimes. Therefore, this function may be used
1098 at any time after deaths have been computed (in flow.c).
1100 If REG is a hard reg that occupies multiple machine registers, this
1101 function will only return 1 if each of those registers will be replaced
1105 dead_or_set_p (insn, x)
1109 register int regno, last_regno;
1112 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1113 if (GET_CODE (x) == CC0)
1116 if (GET_CODE (x) != REG)
1120 last_regno = (regno >= FIRST_PSEUDO_REGISTER ? regno
1121 : regno + HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1);
1123 for (i = regno; i <= last_regno; i++)
1124 if (! dead_or_set_regno_p (insn, i))
1130 /* Utility function for dead_or_set_p to check an individual register. Also
1131 called from flow.c. */
1134 dead_or_set_regno_p (insn, test_regno)
1138 int regno, endregno;
1141 /* See if there is a death note for something that includes TEST_REGNO. */
1142 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1144 if (REG_NOTE_KIND (link) != REG_DEAD || GET_CODE (XEXP (link, 0)) != REG)
1147 regno = REGNO (XEXP (link, 0));
1148 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1149 : regno + HARD_REGNO_NREGS (regno,
1150 GET_MODE (XEXP (link, 0))));
1152 if (test_regno >= regno && test_regno < endregno)
1156 if (GET_CODE (insn) == CALL_INSN
1157 && find_regno_fusage (insn, CLOBBER, test_regno))
1160 if (GET_CODE (PATTERN (insn)) == SET)
1162 rtx dest = SET_DEST (PATTERN (insn));
1164 /* A value is totally replaced if it is the destination or the
1165 destination is a SUBREG of REGNO that does not change the number of
1167 if (GET_CODE (dest) == SUBREG
1168 && (((GET_MODE_SIZE (GET_MODE (dest))
1169 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1170 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1171 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1172 dest = SUBREG_REG (dest);
1174 if (GET_CODE (dest) != REG)
1177 regno = REGNO (dest);
1178 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1179 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1181 return (test_regno >= regno && test_regno < endregno);
1183 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
1187 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1189 rtx body = XVECEXP (PATTERN (insn), 0, i);
1191 if (GET_CODE (body) == SET || GET_CODE (body) == CLOBBER)
1193 rtx dest = SET_DEST (body);
1195 if (GET_CODE (dest) == SUBREG
1196 && (((GET_MODE_SIZE (GET_MODE (dest))
1197 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1198 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1199 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1200 dest = SUBREG_REG (dest);
1202 if (GET_CODE (dest) != REG)
1205 regno = REGNO (dest);
1206 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1207 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1209 if (test_regno >= regno && test_regno < endregno)
1218 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1219 If DATUM is nonzero, look for one whose datum is DATUM. */
1222 find_reg_note (insn, kind, datum)
1229 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1230 if (REG_NOTE_KIND (link) == kind
1231 && (datum == 0 || datum == XEXP (link, 0)))
1236 /* Return the reg-note of kind KIND in insn INSN which applies to register
1237 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1238 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1239 it might be the case that the note overlaps REGNO. */
1242 find_regno_note (insn, kind, regno)
1249 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1250 if (REG_NOTE_KIND (link) == kind
1251 /* Verify that it is a register, so that scratch and MEM won't cause a
1253 && GET_CODE (XEXP (link, 0)) == REG
1254 && REGNO (XEXP (link, 0)) <= regno
1255 && ((REGNO (XEXP (link, 0))
1256 + (REGNO (XEXP (link, 0)) >= FIRST_PSEUDO_REGISTER ? 1
1257 : HARD_REGNO_NREGS (REGNO (XEXP (link, 0)),
1258 GET_MODE (XEXP (link, 0)))))
1264 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1265 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1268 find_reg_fusage (insn, code, datum)
1273 /* If it's not a CALL_INSN, it can't possibly have a
1274 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1275 if (GET_CODE (insn) != CALL_INSN)
1281 if (GET_CODE (datum) != REG)
1285 for (link = CALL_INSN_FUNCTION_USAGE (insn);
1287 link = XEXP (link, 1))
1288 if (GET_CODE (XEXP (link, 0)) == code
1289 && rtx_equal_p (datum, SET_DEST (XEXP (link, 0))))
1294 register int regno = REGNO (datum);
1296 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1297 to pseudo registers, so don't bother checking. */
1299 if (regno < FIRST_PSEUDO_REGISTER)
1301 int end_regno = regno + HARD_REGNO_NREGS (regno, GET_MODE (datum));
1304 for (i = regno; i < end_regno; i++)
1305 if (find_regno_fusage (insn, code, i))
1313 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1314 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1317 find_regno_fusage (insn, code, regno)
1324 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1325 to pseudo registers, so don't bother checking. */
1327 if (regno >= FIRST_PSEUDO_REGISTER
1328 || GET_CODE (insn) != CALL_INSN )
1331 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
1333 register int regnote;
1336 if (GET_CODE (op = XEXP (link, 0)) == code
1337 && GET_CODE (SET_DEST (op)) == REG
1338 && (regnote = REGNO (SET_DEST (op))) <= regno
1340 + HARD_REGNO_NREGS (regnote, GET_MODE (SET_DEST (op)))
1348 /* Remove register note NOTE from the REG_NOTES of INSN. */
1351 remove_note (insn, note)
1357 if (REG_NOTES (insn) == note)
1359 REG_NOTES (insn) = XEXP (note, 1);
1363 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1364 if (XEXP (link, 1) == note)
1366 XEXP (link, 1) = XEXP (note, 1);
1373 /* Nonzero if X contains any volatile instructions. These are instructions
1374 which may cause unpredictable machine state instructions, and thus no
1375 instructions should be moved or combined across them. This includes
1376 only volatile asms and UNSPEC_VOLATILE instructions. */
1382 register RTX_CODE code;
1384 code = GET_CODE (x);
1404 case UNSPEC_VOLATILE:
1405 /* case TRAP_IF: This isn't clear yet. */
1409 if (MEM_VOLATILE_P (x))
1413 /* Recursively scan the operands of this expression. */
1416 register char *fmt = GET_RTX_FORMAT (code);
1419 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1423 if (volatile_insn_p (XEXP (x, i)))
1429 for (j = 0; j < XVECLEN (x, i); j++)
1430 if (volatile_insn_p (XVECEXP (x, i, j)))
1438 /* Nonzero if X contains any volatile memory references
1439 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1445 register RTX_CODE code;
1447 code = GET_CODE (x);
1466 case UNSPEC_VOLATILE:
1467 /* case TRAP_IF: This isn't clear yet. */
1472 if (MEM_VOLATILE_P (x))
1476 /* Recursively scan the operands of this expression. */
1479 register char *fmt = GET_RTX_FORMAT (code);
1482 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1486 if (volatile_refs_p (XEXP (x, i)))
1492 for (j = 0; j < XVECLEN (x, i); j++)
1493 if (volatile_refs_p (XVECEXP (x, i, j)))
1501 /* Similar to above, except that it also rejects register pre- and post-
1508 register RTX_CODE code;
1510 code = GET_CODE (x);
1528 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1529 when some combination can't be done. If we see one, don't think
1530 that we can simplify the expression. */
1531 return (GET_MODE (x) != VOIDmode);
1538 case UNSPEC_VOLATILE:
1539 /* case TRAP_IF: This isn't clear yet. */
1544 if (MEM_VOLATILE_P (x))
1548 /* Recursively scan the operands of this expression. */
1551 register char *fmt = GET_RTX_FORMAT (code);
1554 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1558 if (side_effects_p (XEXP (x, i)))
1564 for (j = 0; j < XVECLEN (x, i); j++)
1565 if (side_effects_p (XVECEXP (x, i, j)))
1573 /* Return nonzero if evaluating rtx X might cause a trap. */
1585 code = GET_CODE (x);
1588 /* Handle these cases quickly. */
1600 /* Conditional trap can trap! */
1601 case UNSPEC_VOLATILE:
1605 /* Memory ref can trap unless it's a static var or a stack slot. */
1607 return rtx_addr_can_trap_p (XEXP (x, 0));
1609 /* Division by a non-constant might trap. */
1614 if (! CONSTANT_P (XEXP (x, 1)))
1616 /* This was const0_rtx, but by not using that,
1617 we can link this file into other programs. */
1618 if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
1621 /* An EXPR_LIST is used to represent a function call. This
1622 certainly may trap. */
1625 /* Any floating arithmetic may trap. */
1626 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1630 fmt = GET_RTX_FORMAT (code);
1631 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1635 if (may_trap_p (XEXP (x, i)))
1638 else if (fmt[i] == 'E')
1641 for (j = 0; j < XVECLEN (x, i); j++)
1642 if (may_trap_p (XVECEXP (x, i, j)))
1649 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1650 i.e., an inequality. */
1653 inequality_comparisons_p (x)
1657 register int len, i;
1658 register enum rtx_code code = GET_CODE (x);
1684 len = GET_RTX_LENGTH (code);
1685 fmt = GET_RTX_FORMAT (code);
1687 for (i = 0; i < len; i++)
1691 if (inequality_comparisons_p (XEXP (x, i)))
1694 else if (fmt[i] == 'E')
1697 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1698 if (inequality_comparisons_p (XVECEXP (x, i, j)))
1706 /* Replace any occurrence of FROM in X with TO.
1708 Note that copying is not done so X must not be shared unless all copies
1709 are to be modified. */
1712 replace_rtx (x, from, to)
1721 /* Allow this function to make replacements in EXPR_LISTs. */
1725 fmt = GET_RTX_FORMAT (GET_CODE (x));
1726 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
1729 XEXP (x, i) = replace_rtx (XEXP (x, i), from, to);
1730 else if (fmt[i] == 'E')
1731 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1732 XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to);
1738 /* Throughout the rtx X, replace many registers according to REG_MAP.
1739 Return the replacement for X (which may be X with altered contents).
1740 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
1741 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
1743 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
1744 should not be mapped to pseudos or vice versa since validate_change
1747 If REPLACE_DEST is 1, replacements are also done in destinations;
1748 otherwise, only sources are replaced. */
1751 replace_regs (x, reg_map, nregs, replace_dest)
1757 register enum rtx_code code;
1764 code = GET_CODE (x);
1778 /* Verify that the register has an entry before trying to access it. */
1779 if (REGNO (x) < nregs && reg_map[REGNO (x)] != 0)
1781 /* SUBREGs can't be shared. Always return a copy to ensure that if
1782 this replacement occurs more than once then each instance will
1783 get distinct rtx. */
1784 if (GET_CODE (reg_map[REGNO (x)]) == SUBREG)
1785 return copy_rtx (reg_map[REGNO (x)]);
1786 return reg_map[REGNO (x)];
1791 /* Prevent making nested SUBREGs. */
1792 if (GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) < nregs
1793 && reg_map[REGNO (SUBREG_REG (x))] != 0
1794 && GET_CODE (reg_map[REGNO (SUBREG_REG (x))]) == SUBREG)
1796 rtx map_val = reg_map[REGNO (SUBREG_REG (x))];
1797 rtx map_inner = SUBREG_REG (map_val);
1799 if (GET_MODE (x) == GET_MODE (map_inner))
1803 /* We cannot call gen_rtx here since we may be linked with
1805 /* Let's try clobbering the incoming SUBREG and see
1806 if this is really safe. */
1807 SUBREG_REG (x) = map_inner;
1808 SUBREG_WORD (x) += SUBREG_WORD (map_val);
1811 rtx new = rtx_alloc (SUBREG);
1812 PUT_MODE (new, GET_MODE (x));
1813 SUBREG_REG (new) = map_inner;
1814 SUBREG_WORD (new) = SUBREG_WORD (x) + SUBREG_WORD (map_val);
1822 SET_DEST (x) = replace_regs (SET_DEST (x), reg_map, nregs, 0);
1824 else if (GET_CODE (SET_DEST (x)) == MEM
1825 || GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
1826 /* Even if we are not to replace destinations, replace register if it
1827 is CONTAINED in destination (destination is memory or
1828 STRICT_LOW_PART). */
1829 XEXP (SET_DEST (x), 0) = replace_regs (XEXP (SET_DEST (x), 0),
1831 else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1832 /* Similarly, for ZERO_EXTRACT we replace all operands. */
1835 SET_SRC (x) = replace_regs (SET_SRC (x), reg_map, nregs, 0);
1839 fmt = GET_RTX_FORMAT (code);
1840 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1843 XEXP (x, i) = replace_regs (XEXP (x, i), reg_map, nregs, replace_dest);
1847 for (j = 0; j < XVECLEN (x, i); j++)
1848 XVECEXP (x, i, j) = replace_regs (XVECEXP (x, i, j), reg_map,
1849 nregs, replace_dest);
1856 /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is
1857 not in the constant pool and not in the condition of an IF_THEN_ELSE. */
1860 jmp_uses_reg_or_mem (x)
1863 enum rtx_code code = GET_CODE (x);
1878 return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1879 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
1882 return (jmp_uses_reg_or_mem (XEXP (x, 1))
1883 || jmp_uses_reg_or_mem (XEXP (x, 2)));
1885 case PLUS: case MINUS: case MULT:
1886 return (jmp_uses_reg_or_mem (XEXP (x, 0))
1887 || jmp_uses_reg_or_mem (XEXP (x, 1)));
1890 fmt = GET_RTX_FORMAT (code);
1891 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1894 && jmp_uses_reg_or_mem (XEXP (x, i)))
1898 for (j = 0; j < XVECLEN (x, i); j++)
1899 if (jmp_uses_reg_or_mem (XVECEXP (x, i, j)))
1906 /* Return nonzero if INSN is an indirect jump (aka computed jump).
1908 Tablejumps and casesi insns are not considered indirect jumps;
1909 we can recognize them by a (use (lael_ref)). */
1912 computed_jump_p (insn)
1916 if (GET_CODE (insn) == JUMP_INSN)
1918 rtx pat = PATTERN (insn);
1919 int computed_jump = 0;
1921 if (GET_CODE (pat) == PARALLEL)
1923 int len = XVECLEN (pat, 0);
1924 int has_use_labelref = 0;
1926 for (i = len - 1; i >= 0; i--)
1927 if (GET_CODE (XVECEXP (pat, 0, i)) == USE
1928 && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0))
1930 has_use_labelref = 1;
1932 if (! has_use_labelref)
1933 for (i = len - 1; i >= 0; i--)
1934 if (GET_CODE (XVECEXP (pat, 0, i)) == SET
1935 && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx
1936 && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat, 0, i))))
1939 else if (GET_CODE (pat) == SET
1940 && SET_DEST (pat) == pc_rtx
1941 && jmp_uses_reg_or_mem (SET_SRC (pat)))