1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 88, 92-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 static int rtx_addr_can_trap_p PROTO((rtx));
27 static void reg_set_p_1 PROTO((rtx, rtx));
28 static void reg_set_last_1 PROTO((rtx, rtx));
31 /* Forward declarations */
32 static int jmp_uses_reg_or_mem PROTO((rtx));
34 /* Bit flags that specify the machine subtype we are compiling for.
35 Bits are tested using macros TARGET_... defined in the tm.h file
36 and set by `-m...' switches. Must be defined in rtlanal.c. */
40 /* Return 1 if the value of X is unstable
41 (would be different at a different point in the program).
42 The frame pointer, arg pointer, etc. are considered stable
43 (within one function) and so is anything marked `unchanging'. */
49 register RTX_CODE code = GET_CODE (x);
54 return ! RTX_UNCHANGING_P (x);
59 if (code == CONST || code == CONST_INT)
63 return ! (REGNO (x) == FRAME_POINTER_REGNUM
64 || REGNO (x) == HARD_FRAME_POINTER_REGNUM
65 || REGNO (x) == ARG_POINTER_REGNUM
66 || RTX_UNCHANGING_P (x));
68 fmt = GET_RTX_FORMAT (code);
69 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
71 if (rtx_unstable_p (XEXP (x, i)))
76 /* Return 1 if X has a value that can vary even between two
77 executions of the program. 0 means X can be compared reliably
78 against certain constants or near-constants.
79 The frame pointer and the arg pointer are considered constant. */
85 register RTX_CODE code = GET_CODE (x);
103 /* Note that we have to test for the actual rtx used for the frame
104 and arg pointers and not just the register number in case we have
105 eliminated the frame and/or arg pointer and are using it
107 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
108 || x == arg_pointer_rtx || x == pic_offset_table_rtx);
111 /* The operand 0 of a LO_SUM is considered constant
112 (in fact is it related specifically to operand 1). */
113 return rtx_varies_p (XEXP (x, 1));
119 fmt = GET_RTX_FORMAT (code);
120 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
122 if (rtx_varies_p (XEXP (x, i)))
127 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
130 rtx_addr_can_trap_p (x)
133 register enum rtx_code code = GET_CODE (x);
139 /* SYMBOL_REF is problematic due to the possible presence of
140 a #pragma weak, but to say that loads from symbols can trap is
141 *very* costly. It's not at all clear what's best here. For
142 now, we ignore the impact of #pragma weak. */
146 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
147 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
148 || x == stack_pointer_rtx || x == arg_pointer_rtx);
151 return rtx_addr_can_trap_p (XEXP (x, 0));
154 /* An address is assumed not to trap if it is an address that can't
155 trap plus a constant integer. */
156 return (rtx_addr_can_trap_p (XEXP (x, 0))
157 || GET_CODE (XEXP (x, 1)) != CONST_INT);
160 return rtx_addr_can_trap_p (XEXP (x, 1));
166 /* If it isn't one of the case above, it can cause a trap. */
170 /* Return 1 if X refers to a memory location whose address
171 cannot be compared reliably with constant addresses,
172 or if X refers to a BLKmode memory object. */
175 rtx_addr_varies_p (x)
178 register enum rtx_code code;
187 return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0));
189 fmt = GET_RTX_FORMAT (code);
190 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
193 if (rtx_addr_varies_p (XEXP (x, i)))
196 else if (fmt[i] == 'E')
199 for (j = 0; j < XVECLEN (x, i); j++)
200 if (rtx_addr_varies_p (XVECEXP (x, i, j)))
206 /* Return the value of the integer term in X, if one is apparent;
208 Only obvious integer terms are detected.
209 This is used in cse.c with the `related_value' field.*/
215 if (GET_CODE (x) == CONST)
218 if (GET_CODE (x) == MINUS
219 && GET_CODE (XEXP (x, 1)) == CONST_INT)
220 return - INTVAL (XEXP (x, 1));
221 if (GET_CODE (x) == PLUS
222 && GET_CODE (XEXP (x, 1)) == CONST_INT)
223 return INTVAL (XEXP (x, 1));
227 /* If X is a constant, return the value sans apparent integer term;
229 Only obvious integer terms are detected. */
232 get_related_value (x)
235 if (GET_CODE (x) != CONST)
238 if (GET_CODE (x) == PLUS
239 && GET_CODE (XEXP (x, 1)) == CONST_INT)
241 else if (GET_CODE (x) == MINUS
242 && GET_CODE (XEXP (x, 1)) == CONST_INT)
247 /* Nonzero if register REG appears somewhere within IN.
248 Also works if REG is not a register; in this case it checks
249 for a subexpression of IN that is Lisp "equal" to REG. */
252 reg_mentioned_p (reg, in)
253 register rtx reg, in;
257 register enum rtx_code code;
265 if (GET_CODE (in) == LABEL_REF)
266 return reg == XEXP (in, 0);
268 code = GET_CODE (in);
272 /* Compare registers by number. */
274 return GET_CODE (reg) == REG && REGNO (in) == REGNO (reg);
276 /* These codes have no constituent expressions
284 return GET_CODE (reg) == CONST_INT && INTVAL (in) == INTVAL (reg);
287 /* These are kept unique for a given value. */
294 if (GET_CODE (reg) == code && rtx_equal_p (reg, in))
297 fmt = GET_RTX_FORMAT (code);
299 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
304 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
305 if (reg_mentioned_p (reg, XVECEXP (in, i, j)))
308 else if (fmt[i] == 'e'
309 && reg_mentioned_p (reg, XEXP (in, i)))
315 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
316 no CODE_LABEL insn. */
319 no_labels_between_p (beg, end)
323 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
324 if (GET_CODE (p) == CODE_LABEL)
329 /* Nonzero if register REG is used in an insn between
330 FROM_INSN and TO_INSN (exclusive of those two). */
333 reg_used_between_p (reg, from_insn, to_insn)
334 rtx reg, from_insn, to_insn;
338 if (from_insn == to_insn)
341 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
342 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
343 && (reg_overlap_mentioned_p (reg, PATTERN (insn))
344 || (GET_CODE (insn) == CALL_INSN
345 && (find_reg_fusage (insn, USE, reg)
346 || find_reg_fusage (insn, CLOBBER, reg)))))
351 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
352 is entirely replaced by a new value and the only use is as a SET_DEST,
353 we do not consider it a reference. */
356 reg_referenced_p (x, body)
362 switch (GET_CODE (body))
365 if (reg_overlap_mentioned_p (x, SET_SRC (body)))
368 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
369 of a REG that occupies all of the REG, the insn references X if
370 it is mentioned in the destination. */
371 if (GET_CODE (SET_DEST (body)) != CC0
372 && GET_CODE (SET_DEST (body)) != PC
373 && GET_CODE (SET_DEST (body)) != REG
374 && ! (GET_CODE (SET_DEST (body)) == SUBREG
375 && GET_CODE (SUBREG_REG (SET_DEST (body))) == REG
376 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body))))
377 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
378 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body)))
379 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
380 && reg_overlap_mentioned_p (x, SET_DEST (body)))
385 for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
386 if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i)))
392 return reg_overlap_mentioned_p (x, body);
395 return reg_overlap_mentioned_p (x, TRAP_CONDITION (body));
398 case UNSPEC_VOLATILE:
400 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
401 if (reg_referenced_p (x, XVECEXP (body, 0, i)))
410 /* Nonzero if register REG is referenced in an insn between
411 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
415 reg_referenced_between_p (reg, from_insn, to_insn)
416 rtx reg, from_insn, to_insn;
420 if (from_insn == to_insn)
423 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
424 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
425 && (reg_referenced_p (reg, PATTERN (insn))
426 || (GET_CODE (insn) == CALL_INSN
427 && find_reg_fusage (insn, USE, reg))))
432 /* Nonzero if register REG is set or clobbered in an insn between
433 FROM_INSN and TO_INSN (exclusive of those two). */
436 reg_set_between_p (reg, from_insn, to_insn)
437 rtx reg, from_insn, to_insn;
441 if (from_insn == to_insn)
444 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
445 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
446 && reg_set_p (reg, insn))
451 /* Internals of reg_set_between_p. */
453 static rtx reg_set_reg;
454 static int reg_set_flag;
460 /* We don't want to return 1 if X is a MEM that contains a register
461 within REG_SET_REG. */
463 if ((GET_CODE (x) != MEM)
464 && reg_overlap_mentioned_p (reg_set_reg, x))
469 reg_set_p (reg, insn)
474 /* We can be passed an insn or part of one. If we are passed an insn,
475 check if a side-effect of the insn clobbers REG. */
476 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
478 if (FIND_REG_INC_NOTE (insn, reg)
479 || (GET_CODE (insn) == CALL_INSN
480 /* We'd like to test call_used_regs here, but rtlanal.c can't
481 reference that variable due to its use in genattrtab. So
482 we'll just be more conservative.
484 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
485 information holds all clobbered registers. */
486 && ((GET_CODE (reg) == REG
487 && REGNO (reg) < FIRST_PSEUDO_REGISTER)
488 || GET_CODE (reg) == MEM
489 || find_reg_fusage (insn, CLOBBER, reg))))
492 body = PATTERN (insn);
497 note_stores (body, reg_set_p_1);
501 /* Similar to reg_set_between_p, but check all registers in X. Return 0
502 only if none of them are modified between START and END. Return 1 if
503 X contains a MEM; this routine does not perform any memory aliasing. */
506 modified_between_p (x, start, end)
510 enum rtx_code code = GET_CODE (x);
528 /* If the memory is not constant, assume it is modified. If it is
529 constant, we still have to check the address. */
530 if (! RTX_UNCHANGING_P (x))
535 return reg_set_between_p (x, start, end);
541 fmt = GET_RTX_FORMAT (code);
542 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
544 if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end))
548 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
549 if (modified_between_p (XVECEXP (x, i, j), start, end))
556 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
557 of them are modified in INSN. Return 1 if X contains a MEM; this routine
558 does not perform any memory aliasing. */
561 modified_in_p (x, insn)
565 enum rtx_code code = GET_CODE (x);
583 /* If the memory is not constant, assume it is modified. If it is
584 constant, we still have to check the address. */
585 if (! RTX_UNCHANGING_P (x))
590 return reg_set_p (x, insn);
596 fmt = GET_RTX_FORMAT (code);
597 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
599 if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn))
603 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
604 if (modified_in_p (XVECEXP (x, i, j), insn))
611 /* Given an INSN, return a SET expression if this insn has only a single SET.
612 It may also have CLOBBERs, USEs, or SET whose output
613 will not be used, which we ignore. */
622 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
625 if (GET_CODE (PATTERN (insn)) == SET)
626 return PATTERN (insn);
628 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
630 for (i = 0, set = 0; i < XVECLEN (PATTERN (insn), 0); i++)
631 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET
632 && (! find_reg_note (insn, REG_UNUSED,
633 SET_DEST (XVECEXP (PATTERN (insn), 0, i)))
634 || side_effects_p (XVECEXP (PATTERN (insn), 0, i))))
639 set = XVECEXP (PATTERN (insn), 0, i);
647 /* Return the last thing that X was assigned from before *PINSN. Verify that
648 the object is not modified up to VALID_TO. If it was, if we hit
649 a partial assignment to X, or hit a CODE_LABEL first, return X. If we
650 found an assignment, update *PINSN to point to it. */
653 find_last_value (x, pinsn, valid_to)
660 for (p = PREV_INSN (*pinsn); p && GET_CODE (p) != CODE_LABEL;
662 if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
664 rtx set = single_set (p);
665 rtx note = find_reg_note (p, REG_EQUAL, NULL_RTX);
667 if (set && rtx_equal_p (x, SET_DEST (set)))
669 rtx src = SET_SRC (set);
671 if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
672 src = XEXP (note, 0);
674 if (! modified_between_p (src, PREV_INSN (p), valid_to)
675 /* Reject hard registers because we don't usually want
676 to use them; we'd rather use a pseudo. */
677 && ! (GET_CODE (src) == REG
678 && REGNO (src) < FIRST_PSEUDO_REGISTER))
685 /* If set in non-simple way, we don't have a value. */
686 if (reg_set_p (x, p))
693 /* Return nonzero if register in range [REGNO, ENDREGNO)
694 appears either explicitly or implicitly in X
695 other than being stored into.
697 References contained within the substructure at LOC do not count.
698 LOC may be zero, meaning don't ignore anything. */
701 refers_to_regno_p (regno, endregno, x, loc)
707 register RTX_CODE code;
711 /* The contents of a REG_NONNEG note is always zero, so we must come here
712 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
723 /* If we modifying the stack, frame, or argument pointer, it will
724 clobber a virtual register. In fact, we could be more precise,
725 but it isn't worth it. */
726 if ((i == STACK_POINTER_REGNUM
727 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
728 || i == ARG_POINTER_REGNUM
730 || i == FRAME_POINTER_REGNUM)
731 && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER)
735 && regno < i + (i < FIRST_PSEUDO_REGISTER
736 ? HARD_REGNO_NREGS (i, GET_MODE (x))
740 /* If this is a SUBREG of a hard reg, we can see exactly which
741 registers are being modified. Otherwise, handle normally. */
742 if (GET_CODE (SUBREG_REG (x)) == REG
743 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
745 int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
747 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
748 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
750 return endregno > inner_regno && regno < inner_endregno;
756 if (&SET_DEST (x) != loc
757 /* Note setting a SUBREG counts as referring to the REG it is in for
758 a pseudo but not for hard registers since we can
759 treat each word individually. */
760 && ((GET_CODE (SET_DEST (x)) == SUBREG
761 && loc != &SUBREG_REG (SET_DEST (x))
762 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
763 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
764 && refers_to_regno_p (regno, endregno,
765 SUBREG_REG (SET_DEST (x)), loc))
766 || (GET_CODE (SET_DEST (x)) != REG
767 && refers_to_regno_p (regno, endregno, SET_DEST (x), loc))))
770 if (code == CLOBBER || loc == &SET_SRC (x))
779 /* X does not match, so try its subexpressions. */
781 fmt = GET_RTX_FORMAT (code);
782 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
784 if (fmt[i] == 'e' && loc != &XEXP (x, i))
792 if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc))
795 else if (fmt[i] == 'E')
798 for (j = XVECLEN (x, i) - 1; j >=0; j--)
799 if (loc != &XVECEXP (x, i, j)
800 && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc))
807 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
808 we check if any register number in X conflicts with the relevant register
809 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
810 contains a MEM (we don't bother checking for memory addresses that can't
811 conflict because we expect this to be a rare case. */
814 reg_overlap_mentioned_p (x, in)
819 if (GET_CODE (x) == SUBREG)
821 regno = REGNO (SUBREG_REG (x));
822 if (regno < FIRST_PSEUDO_REGISTER)
823 regno += SUBREG_WORD (x);
825 else if (GET_CODE (x) == REG)
827 else if (CONSTANT_P (x))
829 else if (GET_CODE (x) == MEM)
834 if (GET_CODE (in) == MEM)
837 fmt = GET_RTX_FORMAT (GET_CODE (in));
839 for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--)
840 if (fmt[i] == 'e' && reg_overlap_mentioned_p (x, XEXP (in, i)))
845 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
846 || GET_CODE (x) == CC0)
847 return reg_mentioned_p (x, in);
851 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
852 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
854 return refers_to_regno_p (regno, endregno, in, NULL_PTR);
857 /* Used for communications between the next few functions. */
859 static int reg_set_last_unknown;
860 static rtx reg_set_last_value;
861 static int reg_set_last_first_regno, reg_set_last_last_regno;
863 /* Called via note_stores from reg_set_last. */
866 reg_set_last_1 (x, pat)
872 /* If X is not a register, or is not one in the range we care
874 if (GET_CODE (x) != REG)
878 last = first + (first < FIRST_PSEUDO_REGISTER
879 ? HARD_REGNO_NREGS (first, GET_MODE (x)) : 1);
881 if (first >= reg_set_last_last_regno
882 || last <= reg_set_last_first_regno)
885 /* If this is a CLOBBER or is some complex LHS, or doesn't modify
886 exactly the registers we care about, show we don't know the value. */
887 if (GET_CODE (pat) == CLOBBER || SET_DEST (pat) != x
888 || first != reg_set_last_first_regno
889 || last != reg_set_last_last_regno)
890 reg_set_last_unknown = 1;
892 reg_set_last_value = SET_SRC (pat);
895 /* Return the last value to which REG was set prior to INSN. If we can't
896 find it easily, return 0.
898 We only return a REG, SUBREG, or constant because it is too hard to
899 check if a MEM remains unchanged. */
902 reg_set_last (x, insn)
906 rtx orig_insn = insn;
908 reg_set_last_first_regno = REGNO (x);
910 reg_set_last_last_regno
911 = reg_set_last_first_regno
912 + (reg_set_last_first_regno < FIRST_PSEUDO_REGISTER
913 ? HARD_REGNO_NREGS (reg_set_last_first_regno, GET_MODE (x)) : 1);
915 reg_set_last_unknown = 0;
916 reg_set_last_value = 0;
918 /* Scan backwards until reg_set_last_1 changed one of the above flags.
919 Stop when we reach a label or X is a hard reg and we reach a
920 CALL_INSN (if reg_set_last_last_regno is a hard reg).
922 If we find a set of X, ensure that its SET_SRC remains unchanged. */
924 /* We compare with <= here, because reg_set_last_last_regno
925 is actually the number of the first reg *not* in X. */
927 insn && GET_CODE (insn) != CODE_LABEL
928 && ! (GET_CODE (insn) == CALL_INSN
929 && reg_set_last_last_regno <= FIRST_PSEUDO_REGISTER);
930 insn = PREV_INSN (insn))
931 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
933 note_stores (PATTERN (insn), reg_set_last_1);
934 if (reg_set_last_unknown)
936 else if (reg_set_last_value)
938 if (CONSTANT_P (reg_set_last_value)
939 || ((GET_CODE (reg_set_last_value) == REG
940 || GET_CODE (reg_set_last_value) == SUBREG)
941 && ! reg_set_between_p (reg_set_last_value,
943 return reg_set_last_value;
952 /* This is 1 until after the rtl generation pass. */
953 int rtx_equal_function_value_matters;
955 /* Return 1 if X and Y are identical-looking rtx's.
956 This is the Lisp function EQUAL for rtx arguments. */
964 register enum rtx_code code;
969 if (x == 0 || y == 0)
973 /* Rtx's of different codes cannot be equal. */
974 if (code != GET_CODE (y))
977 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
978 (REG:SI x) and (REG:HI x) are NOT equivalent. */
980 if (GET_MODE (x) != GET_MODE (y))
983 /* REG, LABEL_REF, and SYMBOL_REF can be compared nonrecursively. */
986 /* Until rtl generation is complete, don't consider a reference to the
987 return register of the current function the same as the return from a
988 called function. This eases the job of function integration. Once the
989 distinction is no longer needed, they can be considered equivalent. */
990 return (REGNO (x) == REGNO (y)
991 && (! rtx_equal_function_value_matters
992 || REG_FUNCTION_VALUE_P (x) == REG_FUNCTION_VALUE_P (y)));
993 else if (code == LABEL_REF)
994 return XEXP (x, 0) == XEXP (y, 0);
995 else if (code == SYMBOL_REF)
996 return XSTR (x, 0) == XSTR (y, 0);
997 else if (code == SCRATCH || code == CONST_DOUBLE)
1000 /* Compare the elements. If any pair of corresponding elements
1001 fail to match, return 0 for the whole things. */
1003 fmt = GET_RTX_FORMAT (code);
1004 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1009 if (XWINT (x, i) != XWINT (y, i))
1015 if (XINT (x, i) != XINT (y, i))
1021 /* Two vectors must have the same length. */
1022 if (XVECLEN (x, i) != XVECLEN (y, i))
1025 /* And the corresponding elements must match. */
1026 for (j = 0; j < XVECLEN (x, i); j++)
1027 if (rtx_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)) == 0)
1032 if (rtx_equal_p (XEXP (x, i), XEXP (y, i)) == 0)
1038 if (strcmp (XSTR (x, i), XSTR (y, i)))
1043 /* These are just backpointers, so they don't matter. */
1049 /* It is believed that rtx's at this level will never
1050 contain anything but integers and other rtx's,
1051 except for within LABEL_REFs and SYMBOL_REFs. */
1059 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1060 (X would be the pattern of an insn).
1061 FUN receives two arguments:
1062 the REG, MEM, CC0 or PC being stored in or clobbered,
1063 the SET or CLOBBER rtx that does the store.
1065 If the item being stored in or clobbered is a SUBREG of a hard register,
1066 the SUBREG will be passed. */
1069 note_stores (x, fun)
1073 if ((GET_CODE (x) == SET || GET_CODE (x) == CLOBBER))
1075 register rtx dest = SET_DEST (x);
1076 while ((GET_CODE (dest) == SUBREG
1077 && (GET_CODE (SUBREG_REG (dest)) != REG
1078 || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER))
1079 || GET_CODE (dest) == ZERO_EXTRACT
1080 || GET_CODE (dest) == SIGN_EXTRACT
1081 || GET_CODE (dest) == STRICT_LOW_PART)
1082 dest = XEXP (dest, 0);
1085 else if (GET_CODE (x) == PARALLEL)
1088 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1090 register rtx y = XVECEXP (x, 0, i);
1091 if (GET_CODE (y) == SET || GET_CODE (y) == CLOBBER)
1093 register rtx dest = SET_DEST (y);
1094 while ((GET_CODE (dest) == SUBREG
1095 && (GET_CODE (SUBREG_REG (dest)) != REG
1096 || (REGNO (SUBREG_REG (dest))
1097 >= FIRST_PSEUDO_REGISTER)))
1098 || GET_CODE (dest) == ZERO_EXTRACT
1099 || GET_CODE (dest) == SIGN_EXTRACT
1100 || GET_CODE (dest) == STRICT_LOW_PART)
1101 dest = XEXP (dest, 0);
1108 /* Return nonzero if X's old contents don't survive after INSN.
1109 This will be true if X is (cc0) or if X is a register and
1110 X dies in INSN or because INSN entirely sets X.
1112 "Entirely set" means set directly and not through a SUBREG,
1113 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1114 Likewise, REG_INC does not count.
1116 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1117 but for this use that makes no difference, since regs don't overlap
1118 during their lifetimes. Therefore, this function may be used
1119 at any time after deaths have been computed (in flow.c).
1121 If REG is a hard reg that occupies multiple machine registers, this
1122 function will only return 1 if each of those registers will be replaced
1126 dead_or_set_p (insn, x)
1130 register int regno, last_regno;
1133 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1134 if (GET_CODE (x) == CC0)
1137 if (GET_CODE (x) != REG)
1141 last_regno = (regno >= FIRST_PSEUDO_REGISTER ? regno
1142 : regno + HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1);
1144 for (i = regno; i <= last_regno; i++)
1145 if (! dead_or_set_regno_p (insn, i))
1151 /* Utility function for dead_or_set_p to check an individual register. Also
1152 called from flow.c. */
1155 dead_or_set_regno_p (insn, test_regno)
1159 int regno, endregno;
1162 /* REG_READ notes are not normally maintained after reload, so we
1163 ignore them if the are invalid. */
1164 if (! reload_completed
1165 #ifdef PRESERVE_DEATH_INFO_REGNO_P
1166 || PRESERVE_DEATH_INFO_REGNO_P (test_regno)
1170 /* See if there is a death note for something that includes
1172 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1174 if (REG_NOTE_KIND (link) != REG_DEAD
1175 || GET_CODE (XEXP (link, 0)) != REG)
1178 regno = REGNO (XEXP (link, 0));
1179 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1180 : regno + HARD_REGNO_NREGS (regno,
1181 GET_MODE (XEXP (link, 0))));
1183 if (test_regno >= regno && test_regno < endregno)
1188 if (GET_CODE (insn) == CALL_INSN
1189 && find_regno_fusage (insn, CLOBBER, test_regno))
1192 if (GET_CODE (PATTERN (insn)) == SET)
1194 rtx dest = SET_DEST (PATTERN (insn));
1196 /* A value is totally replaced if it is the destination or the
1197 destination is a SUBREG of REGNO that does not change the number of
1199 if (GET_CODE (dest) == SUBREG
1200 && (((GET_MODE_SIZE (GET_MODE (dest))
1201 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1202 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1203 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1204 dest = SUBREG_REG (dest);
1206 if (GET_CODE (dest) != REG)
1209 regno = REGNO (dest);
1210 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1211 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1213 return (test_regno >= regno && test_regno < endregno);
1215 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
1219 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1221 rtx body = XVECEXP (PATTERN (insn), 0, i);
1223 if (GET_CODE (body) == SET || GET_CODE (body) == CLOBBER)
1225 rtx dest = SET_DEST (body);
1227 if (GET_CODE (dest) == SUBREG
1228 && (((GET_MODE_SIZE (GET_MODE (dest))
1229 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1230 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1231 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1232 dest = SUBREG_REG (dest);
1234 if (GET_CODE (dest) != REG)
1237 regno = REGNO (dest);
1238 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1239 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1241 if (test_regno >= regno && test_regno < endregno)
1250 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1251 If DATUM is nonzero, look for one whose datum is DATUM. */
1254 find_reg_note (insn, kind, datum)
1261 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1262 if (REG_NOTE_KIND (link) == kind
1263 && (datum == 0 || datum == XEXP (link, 0)))
1268 /* Return the reg-note of kind KIND in insn INSN which applies to register
1269 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1270 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1271 it might be the case that the note overlaps REGNO. */
1274 find_regno_note (insn, kind, regno)
1281 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1282 if (REG_NOTE_KIND (link) == kind
1283 /* Verify that it is a register, so that scratch and MEM won't cause a
1285 && GET_CODE (XEXP (link, 0)) == REG
1286 && REGNO (XEXP (link, 0)) <= regno
1287 && ((REGNO (XEXP (link, 0))
1288 + (REGNO (XEXP (link, 0)) >= FIRST_PSEUDO_REGISTER ? 1
1289 : HARD_REGNO_NREGS (REGNO (XEXP (link, 0)),
1290 GET_MODE (XEXP (link, 0)))))
1296 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1297 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1300 find_reg_fusage (insn, code, datum)
1305 /* If it's not a CALL_INSN, it can't possibly have a
1306 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1307 if (GET_CODE (insn) != CALL_INSN)
1313 if (GET_CODE (datum) != REG)
1317 for (link = CALL_INSN_FUNCTION_USAGE (insn);
1319 link = XEXP (link, 1))
1320 if (GET_CODE (XEXP (link, 0)) == code
1321 && rtx_equal_p (datum, SET_DEST (XEXP (link, 0))))
1326 register int regno = REGNO (datum);
1328 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1329 to pseudo registers, so don't bother checking. */
1331 if (regno < FIRST_PSEUDO_REGISTER)
1333 int end_regno = regno + HARD_REGNO_NREGS (regno, GET_MODE (datum));
1336 for (i = regno; i < end_regno; i++)
1337 if (find_regno_fusage (insn, code, i))
1345 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1346 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1349 find_regno_fusage (insn, code, regno)
1356 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1357 to pseudo registers, so don't bother checking. */
1359 if (regno >= FIRST_PSEUDO_REGISTER
1360 || GET_CODE (insn) != CALL_INSN )
1363 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
1365 register int regnote;
1368 if (GET_CODE (op = XEXP (link, 0)) == code
1369 && GET_CODE (SET_DEST (op)) == REG
1370 && (regnote = REGNO (SET_DEST (op))) <= regno
1372 + HARD_REGNO_NREGS (regnote, GET_MODE (SET_DEST (op)))
1380 /* Remove register note NOTE from the REG_NOTES of INSN. */
1383 remove_note (insn, note)
1389 if (REG_NOTES (insn) == note)
1391 REG_NOTES (insn) = XEXP (note, 1);
1395 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1396 if (XEXP (link, 1) == note)
1398 XEXP (link, 1) = XEXP (note, 1);
1405 /* Nonzero if X contains any volatile instructions. These are instructions
1406 which may cause unpredictable machine state instructions, and thus no
1407 instructions should be moved or combined across them. This includes
1408 only volatile asms and UNSPEC_VOLATILE instructions. */
1414 register RTX_CODE code;
1416 code = GET_CODE (x);
1436 case UNSPEC_VOLATILE:
1437 /* case TRAP_IF: This isn't clear yet. */
1441 if (MEM_VOLATILE_P (x))
1448 /* Recursively scan the operands of this expression. */
1451 register char *fmt = GET_RTX_FORMAT (code);
1454 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1458 if (volatile_insn_p (XEXP (x, i)))
1464 for (j = 0; j < XVECLEN (x, i); j++)
1465 if (volatile_insn_p (XVECEXP (x, i, j)))
1473 /* Nonzero if X contains any volatile memory references
1474 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1480 register RTX_CODE code;
1482 code = GET_CODE (x);
1501 case UNSPEC_VOLATILE:
1502 /* case TRAP_IF: This isn't clear yet. */
1507 if (MEM_VOLATILE_P (x))
1514 /* Recursively scan the operands of this expression. */
1517 register char *fmt = GET_RTX_FORMAT (code);
1520 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1524 if (volatile_refs_p (XEXP (x, i)))
1530 for (j = 0; j < XVECLEN (x, i); j++)
1531 if (volatile_refs_p (XVECEXP (x, i, j)))
1539 /* Similar to above, except that it also rejects register pre- and post-
1546 register RTX_CODE code;
1548 code = GET_CODE (x);
1566 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1567 when some combination can't be done. If we see one, don't think
1568 that we can simplify the expression. */
1569 return (GET_MODE (x) != VOIDmode);
1576 case UNSPEC_VOLATILE:
1577 /* case TRAP_IF: This isn't clear yet. */
1582 if (MEM_VOLATILE_P (x))
1589 /* Recursively scan the operands of this expression. */
1592 register char *fmt = GET_RTX_FORMAT (code);
1595 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1599 if (side_effects_p (XEXP (x, i)))
1605 for (j = 0; j < XVECLEN (x, i); j++)
1606 if (side_effects_p (XVECEXP (x, i, j)))
1614 /* Return nonzero if evaluating rtx X might cause a trap. */
1626 code = GET_CODE (x);
1629 /* Handle these cases quickly. */
1641 /* Conditional trap can trap! */
1642 case UNSPEC_VOLATILE:
1646 /* Memory ref can trap unless it's a static var or a stack slot. */
1648 return rtx_addr_can_trap_p (XEXP (x, 0));
1650 /* Division by a non-constant might trap. */
1655 if (! CONSTANT_P (XEXP (x, 1))
1656 || GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1658 /* This was const0_rtx, but by not using that,
1659 we can link this file into other programs. */
1660 if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
1665 /* An EXPR_LIST is used to represent a function call. This
1666 certainly may trap. */
1670 /* Any floating arithmetic may trap. */
1671 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1675 fmt = GET_RTX_FORMAT (code);
1676 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1680 if (may_trap_p (XEXP (x, i)))
1683 else if (fmt[i] == 'E')
1686 for (j = 0; j < XVECLEN (x, i); j++)
1687 if (may_trap_p (XVECEXP (x, i, j)))
1694 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1695 i.e., an inequality. */
1698 inequality_comparisons_p (x)
1702 register int len, i;
1703 register enum rtx_code code = GET_CODE (x);
1732 len = GET_RTX_LENGTH (code);
1733 fmt = GET_RTX_FORMAT (code);
1735 for (i = 0; i < len; i++)
1739 if (inequality_comparisons_p (XEXP (x, i)))
1742 else if (fmt[i] == 'E')
1745 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1746 if (inequality_comparisons_p (XVECEXP (x, i, j)))
1754 /* Replace any occurrence of FROM in X with TO.
1756 Note that copying is not done so X must not be shared unless all copies
1757 are to be modified. */
1760 replace_rtx (x, from, to)
1769 /* Allow this function to make replacements in EXPR_LISTs. */
1773 fmt = GET_RTX_FORMAT (GET_CODE (x));
1774 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
1777 XEXP (x, i) = replace_rtx (XEXP (x, i), from, to);
1778 else if (fmt[i] == 'E')
1779 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1780 XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to);
1786 /* Throughout the rtx X, replace many registers according to REG_MAP.
1787 Return the replacement for X (which may be X with altered contents).
1788 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
1789 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
1791 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
1792 should not be mapped to pseudos or vice versa since validate_change
1795 If REPLACE_DEST is 1, replacements are also done in destinations;
1796 otherwise, only sources are replaced. */
1799 replace_regs (x, reg_map, nregs, replace_dest)
1805 register enum rtx_code code;
1812 code = GET_CODE (x);
1826 /* Verify that the register has an entry before trying to access it. */
1827 if (REGNO (x) < nregs && reg_map[REGNO (x)] != 0)
1829 /* SUBREGs can't be shared. Always return a copy to ensure that if
1830 this replacement occurs more than once then each instance will
1831 get distinct rtx. */
1832 if (GET_CODE (reg_map[REGNO (x)]) == SUBREG)
1833 return copy_rtx (reg_map[REGNO (x)]);
1834 return reg_map[REGNO (x)];
1839 /* Prevent making nested SUBREGs. */
1840 if (GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) < nregs
1841 && reg_map[REGNO (SUBREG_REG (x))] != 0
1842 && GET_CODE (reg_map[REGNO (SUBREG_REG (x))]) == SUBREG)
1844 rtx map_val = reg_map[REGNO (SUBREG_REG (x))];
1845 rtx map_inner = SUBREG_REG (map_val);
1847 if (GET_MODE (x) == GET_MODE (map_inner))
1851 /* We cannot call gen_rtx here since we may be linked with
1853 /* Let's try clobbering the incoming SUBREG and see
1854 if this is really safe. */
1855 SUBREG_REG (x) = map_inner;
1856 SUBREG_WORD (x) += SUBREG_WORD (map_val);
1859 rtx new = rtx_alloc (SUBREG);
1860 PUT_MODE (new, GET_MODE (x));
1861 SUBREG_REG (new) = map_inner;
1862 SUBREG_WORD (new) = SUBREG_WORD (x) + SUBREG_WORD (map_val);
1870 SET_DEST (x) = replace_regs (SET_DEST (x), reg_map, nregs, 0);
1872 else if (GET_CODE (SET_DEST (x)) == MEM
1873 || GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
1874 /* Even if we are not to replace destinations, replace register if it
1875 is CONTAINED in destination (destination is memory or
1876 STRICT_LOW_PART). */
1877 XEXP (SET_DEST (x), 0) = replace_regs (XEXP (SET_DEST (x), 0),
1879 else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1880 /* Similarly, for ZERO_EXTRACT we replace all operands. */
1883 SET_SRC (x) = replace_regs (SET_SRC (x), reg_map, nregs, 0);
1890 fmt = GET_RTX_FORMAT (code);
1891 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1894 XEXP (x, i) = replace_regs (XEXP (x, i), reg_map, nregs, replace_dest);
1898 for (j = 0; j < XVECLEN (x, i); j++)
1899 XVECEXP (x, i, j) = replace_regs (XVECEXP (x, i, j), reg_map,
1900 nregs, replace_dest);
1906 /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is
1907 not in the constant pool and not in the condition of an IF_THEN_ELSE. */
1910 jmp_uses_reg_or_mem (x)
1913 enum rtx_code code = GET_CODE (x);
1928 return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1929 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
1932 return (jmp_uses_reg_or_mem (XEXP (x, 1))
1933 || jmp_uses_reg_or_mem (XEXP (x, 2)));
1935 case PLUS: case MINUS: case MULT:
1936 return (jmp_uses_reg_or_mem (XEXP (x, 0))
1937 || jmp_uses_reg_or_mem (XEXP (x, 1)));
1943 fmt = GET_RTX_FORMAT (code);
1944 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1947 && jmp_uses_reg_or_mem (XEXP (x, i)))
1951 for (j = 0; j < XVECLEN (x, i); j++)
1952 if (jmp_uses_reg_or_mem (XVECEXP (x, i, j)))
1959 /* Return nonzero if INSN is an indirect jump (aka computed jump).
1961 Tablejumps and casesi insns are not considered indirect jumps;
1962 we can recognize them by a (use (lael_ref)). */
1965 computed_jump_p (insn)
1969 if (GET_CODE (insn) == JUMP_INSN)
1971 rtx pat = PATTERN (insn);
1973 if (GET_CODE (pat) == PARALLEL)
1975 int len = XVECLEN (pat, 0);
1976 int has_use_labelref = 0;
1978 for (i = len - 1; i >= 0; i--)
1979 if (GET_CODE (XVECEXP (pat, 0, i)) == USE
1980 && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0))
1982 has_use_labelref = 1;
1984 if (! has_use_labelref)
1985 for (i = len - 1; i >= 0; i--)
1986 if (GET_CODE (XVECEXP (pat, 0, i)) == SET
1987 && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx
1988 && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat, 0, i))))
1991 else if (GET_CODE (pat) == SET
1992 && SET_DEST (pat) == pc_rtx
1993 && jmp_uses_reg_or_mem (SET_SRC (pat)))