1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 static int rtx_addr_can_trap_p PARAMS ((rtx));
29 static void reg_set_p_1 PARAMS ((rtx, rtx, void *));
30 static void insn_dependent_p_1 PARAMS ((rtx, rtx, void *));
31 static void reg_set_last_1 PARAMS ((rtx, rtx, void *));
34 /* Forward declarations */
35 static int jmp_uses_reg_or_mem PARAMS ((rtx));
37 /* Bit flags that specify the machine subtype we are compiling for.
38 Bits are tested using macros TARGET_... defined in the tm.h file
39 and set by `-m...' switches. Must be defined in rtlanal.c. */
43 /* Return 1 if the value of X is unstable
44 (would be different at a different point in the program).
45 The frame pointer, arg pointer, etc. are considered stable
46 (within one function) and so is anything marked `unchanging'. */
52 register RTX_CODE code = GET_CODE (x);
54 register const char *fmt;
59 return ! RTX_UNCHANGING_P (x) || rtx_unstable_p (XEXP (x, 0));
72 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
73 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
74 || x == arg_pointer_rtx || x == pic_offset_table_rtx
75 || RTX_UNCHANGING_P (x));
78 if (MEM_VOLATILE_P (x))
87 fmt = GET_RTX_FORMAT (code);
88 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
91 if (rtx_unstable_p (XEXP (x, i)))
94 else if (fmt[i] == 'E')
97 for (j = 0; j < XVECLEN (x, i); j++)
98 if (rtx_unstable_p (XVECEXP (x, i, j)))
105 /* Return 1 if X has a value that can vary even between two
106 executions of the program. 0 means X can be compared reliably
107 against certain constants or near-constants.
108 The frame pointer and the arg pointer are considered constant. */
114 register RTX_CODE code = GET_CODE (x);
116 register const char *fmt;
121 return ! RTX_UNCHANGING_P (x) || rtx_varies_p (XEXP (x, 0));
134 /* Note that we have to test for the actual rtx used for the frame
135 and arg pointers and not just the register number in case we have
136 eliminated the frame and/or arg pointer and are using it
138 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
139 || x == arg_pointer_rtx || x == pic_offset_table_rtx);
142 /* The operand 0 of a LO_SUM is considered constant
143 (in fact is it related specifically to operand 1). */
144 return rtx_varies_p (XEXP (x, 1));
147 if (MEM_VOLATILE_P (x))
156 fmt = GET_RTX_FORMAT (code);
157 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
160 if (rtx_varies_p (XEXP (x, i)))
163 else if (fmt[i] == 'E')
166 for (j = 0; j < XVECLEN (x, i); j++)
167 if (rtx_varies_p (XVECEXP (x, i, j)))
174 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
177 rtx_addr_can_trap_p (x)
180 register enum rtx_code code = GET_CODE (x);
186 /* SYMBOL_REF is problematic due to the possible presence of
187 a #pragma weak, but to say that loads from symbols can trap is
188 *very* costly. It's not at all clear what's best here. For
189 now, we ignore the impact of #pragma weak. */
193 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
194 return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
195 || x == stack_pointer_rtx || x == arg_pointer_rtx);
198 return rtx_addr_can_trap_p (XEXP (x, 0));
201 /* An address is assumed not to trap if it is an address that can't
202 trap plus a constant integer or it is the pic register plus a
204 return ! ((! rtx_addr_can_trap_p (XEXP (x, 0))
205 && GET_CODE (XEXP (x, 1)) == CONST_INT)
206 || (XEXP (x, 0) == pic_offset_table_rtx
207 && CONSTANT_P (XEXP (x, 1))));
210 return rtx_addr_can_trap_p (XEXP (x, 1));
216 /* If it isn't one of the case above, it can cause a trap. */
220 /* Return 1 if X refers to a memory location whose address
221 cannot be compared reliably with constant addresses,
222 or if X refers to a BLKmode memory object. */
225 rtx_addr_varies_p (x)
228 register enum rtx_code code;
230 register const char *fmt;
237 return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0));
239 fmt = GET_RTX_FORMAT (code);
240 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
243 if (rtx_addr_varies_p (XEXP (x, i)))
246 else if (fmt[i] == 'E')
249 for (j = 0; j < XVECLEN (x, i); j++)
250 if (rtx_addr_varies_p (XVECEXP (x, i, j)))
256 /* Return the value of the integer term in X, if one is apparent;
258 Only obvious integer terms are detected.
259 This is used in cse.c with the `related_value' field.*/
265 if (GET_CODE (x) == CONST)
268 if (GET_CODE (x) == MINUS
269 && GET_CODE (XEXP (x, 1)) == CONST_INT)
270 return - INTVAL (XEXP (x, 1));
271 if (GET_CODE (x) == PLUS
272 && GET_CODE (XEXP (x, 1)) == CONST_INT)
273 return INTVAL (XEXP (x, 1));
277 /* If X is a constant, return the value sans apparent integer term;
279 Only obvious integer terms are detected. */
282 get_related_value (x)
285 if (GET_CODE (x) != CONST)
288 if (GET_CODE (x) == PLUS
289 && GET_CODE (XEXP (x, 1)) == CONST_INT)
291 else if (GET_CODE (x) == MINUS
292 && GET_CODE (XEXP (x, 1)) == CONST_INT)
297 /* Return the number of places FIND appears within X. If COUNT_DEST is
298 zero, we do not count occurrences inside the destination of a SET. */
301 count_occurrences (x, find, count_dest)
307 const char *format_ptr;
327 if (GET_CODE (find) == MEM && rtx_equal_p (x, find))
332 if (SET_DEST (x) == find && ! count_dest)
333 return count_occurrences (SET_SRC (x), find, count_dest);
340 format_ptr = GET_RTX_FORMAT (code);
343 for (i = 0; i < GET_RTX_LENGTH (code); i++)
345 switch (*format_ptr++)
348 count += count_occurrences (XEXP (x, i), find, count_dest);
352 for (j = 0; j < XVECLEN (x, i); j++)
353 count += count_occurrences (XVECEXP (x, i, j), find, count_dest);
360 /* Nonzero if register REG appears somewhere within IN.
361 Also works if REG is not a register; in this case it checks
362 for a subexpression of IN that is Lisp "equal" to REG. */
365 reg_mentioned_p (reg, in)
366 register rtx reg, in;
368 register const char *fmt;
370 register enum rtx_code code;
378 if (GET_CODE (in) == LABEL_REF)
379 return reg == XEXP (in, 0);
381 code = GET_CODE (in);
385 /* Compare registers by number. */
387 return GET_CODE (reg) == REG && REGNO (in) == REGNO (reg);
389 /* These codes have no constituent expressions
397 return GET_CODE (reg) == CONST_INT && INTVAL (in) == INTVAL (reg);
400 /* These are kept unique for a given value. */
407 if (GET_CODE (reg) == code && rtx_equal_p (reg, in))
410 fmt = GET_RTX_FORMAT (code);
412 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
417 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
418 if (reg_mentioned_p (reg, XVECEXP (in, i, j)))
421 else if (fmt[i] == 'e'
422 && reg_mentioned_p (reg, XEXP (in, i)))
428 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
429 no CODE_LABEL insn. */
432 no_labels_between_p (beg, end)
436 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
437 if (GET_CODE (p) == CODE_LABEL)
442 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
443 no JUMP_INSN insn. */
446 no_jumps_between_p (beg, end)
450 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
451 if (GET_CODE (p) == JUMP_INSN)
456 /* Nonzero if register REG is used in an insn between
457 FROM_INSN and TO_INSN (exclusive of those two). */
460 reg_used_between_p (reg, from_insn, to_insn)
461 rtx reg, from_insn, to_insn;
465 if (from_insn == to_insn)
468 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
470 && (reg_overlap_mentioned_p (reg, PATTERN (insn))
471 || (GET_CODE (insn) == CALL_INSN
472 && (find_reg_fusage (insn, USE, reg)
473 || find_reg_fusage (insn, CLOBBER, reg)))))
478 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
479 is entirely replaced by a new value and the only use is as a SET_DEST,
480 we do not consider it a reference. */
483 reg_referenced_p (x, body)
489 switch (GET_CODE (body))
492 if (reg_overlap_mentioned_p (x, SET_SRC (body)))
495 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
496 of a REG that occupies all of the REG, the insn references X if
497 it is mentioned in the destination. */
498 if (GET_CODE (SET_DEST (body)) != CC0
499 && GET_CODE (SET_DEST (body)) != PC
500 && GET_CODE (SET_DEST (body)) != REG
501 && ! (GET_CODE (SET_DEST (body)) == SUBREG
502 && GET_CODE (SUBREG_REG (SET_DEST (body))) == REG
503 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body))))
504 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
505 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body)))
506 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
507 && reg_overlap_mentioned_p (x, SET_DEST (body)))
512 for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
513 if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i)))
520 return reg_overlap_mentioned_p (x, body);
523 return reg_overlap_mentioned_p (x, TRAP_CONDITION (body));
526 case UNSPEC_VOLATILE:
527 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
528 if (reg_overlap_mentioned_p (x, XVECEXP (body, 0, i)))
533 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
534 if (reg_referenced_p (x, XVECEXP (body, 0, i)))
539 if (GET_CODE (XEXP (body, 0)) == MEM)
540 if (reg_overlap_mentioned_p (x, XEXP (XEXP (body, 0), 0)))
545 if (reg_overlap_mentioned_p (x, COND_EXEC_TEST (body)))
547 return reg_referenced_p (x, COND_EXEC_CODE (body));
554 /* Nonzero if register REG is referenced in an insn between
555 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
559 reg_referenced_between_p (reg, from_insn, to_insn)
560 rtx reg, from_insn, to_insn;
564 if (from_insn == to_insn)
567 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
569 && (reg_referenced_p (reg, PATTERN (insn))
570 || (GET_CODE (insn) == CALL_INSN
571 && find_reg_fusage (insn, USE, reg))))
576 /* Nonzero if register REG is set or clobbered in an insn between
577 FROM_INSN and TO_INSN (exclusive of those two). */
580 reg_set_between_p (reg, from_insn, to_insn)
581 rtx reg, from_insn, to_insn;
585 if (from_insn == to_insn)
588 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
589 if (INSN_P (insn) && reg_set_p (reg, insn))
594 /* Internals of reg_set_between_p. */
596 static rtx reg_set_reg;
597 static int reg_set_flag;
600 reg_set_p_1 (x, pat, data)
602 rtx pat ATTRIBUTE_UNUSED;
603 void *data ATTRIBUTE_UNUSED;
605 /* We don't want to return 1 if X is a MEM that contains a register
606 within REG_SET_REG. */
608 if ((GET_CODE (x) != MEM)
609 && reg_overlap_mentioned_p (reg_set_reg, x))
614 reg_set_p (reg, insn)
619 /* We can be passed an insn or part of one. If we are passed an insn,
620 check if a side-effect of the insn clobbers REG. */
623 if (FIND_REG_INC_NOTE (insn, reg)
624 || (GET_CODE (insn) == CALL_INSN
625 /* We'd like to test call_used_regs here, but rtlanal.c can't
626 reference that variable due to its use in genattrtab. So
627 we'll just be more conservative.
629 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
630 information holds all clobbered registers. */
631 && ((GET_CODE (reg) == REG
632 && REGNO (reg) < FIRST_PSEUDO_REGISTER)
633 || GET_CODE (reg) == MEM
634 || find_reg_fusage (insn, CLOBBER, reg))))
637 body = PATTERN (insn);
642 note_stores (body, reg_set_p_1, NULL);
646 /* Similar to reg_set_between_p, but check all registers in X. Return 0
647 only if none of them are modified between START and END. Do not
648 consider non-registers one way or the other. */
651 regs_set_between_p (x, start, end)
655 enum rtx_code code = GET_CODE (x);
671 return reg_set_between_p (x, start, end);
677 fmt = GET_RTX_FORMAT (code);
678 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
680 if (fmt[i] == 'e' && regs_set_between_p (XEXP (x, i), start, end))
683 else if (fmt[i] == 'E')
684 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
685 if (regs_set_between_p (XVECEXP (x, i, j), start, end))
692 /* Similar to reg_set_between_p, but check all registers in X. Return 0
693 only if none of them are modified between START and END. Return 1 if
694 X contains a MEM; this routine does not perform any memory aliasing. */
697 modified_between_p (x, start, end)
701 enum rtx_code code = GET_CODE (x);
719 /* If the memory is not constant, assume it is modified. If it is
720 constant, we still have to check the address. */
721 if (! RTX_UNCHANGING_P (x))
726 return reg_set_between_p (x, start, end);
732 fmt = GET_RTX_FORMAT (code);
733 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
735 if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end))
738 else if (fmt[i] == 'E')
739 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
740 if (modified_between_p (XVECEXP (x, i, j), start, end))
747 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
748 of them are modified in INSN. Return 1 if X contains a MEM; this routine
749 does not perform any memory aliasing. */
752 modified_in_p (x, insn)
756 enum rtx_code code = GET_CODE (x);
774 /* If the memory is not constant, assume it is modified. If it is
775 constant, we still have to check the address. */
776 if (! RTX_UNCHANGING_P (x))
781 return reg_set_p (x, insn);
787 fmt = GET_RTX_FORMAT (code);
788 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
790 if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn))
793 else if (fmt[i] == 'E')
794 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
795 if (modified_in_p (XVECEXP (x, i, j), insn))
802 /* Return true if anything in insn X is (anti,output,true) dependent on
803 anything in insn Y. */
806 insn_dependent_p (x, y)
811 if (! INSN_P (x) || ! INSN_P (y))
815 note_stores (PATTERN (x), insn_dependent_p_1, &tmp);
820 note_stores (PATTERN (y), insn_dependent_p_1, &tmp);
827 /* A helper routine for insn_dependent_p called through note_stores. */
830 insn_dependent_p_1 (x, pat, data)
832 rtx pat ATTRIBUTE_UNUSED;
835 rtx * pinsn = (rtx *) data;
837 if (*pinsn && reg_mentioned_p (x, *pinsn))
841 /* Given an INSN, return a SET expression if this insn has only a single SET.
842 It may also have CLOBBERs, USEs, or SET whose output
843 will not be used, which we ignore. */
850 int set_verified = 1;
851 rtx pat = PATTERN (insn);
854 if (GET_CODE (pat) == PARALLEL)
856 for (i = 0; i < XVECLEN (pat, 0); i++)
858 rtx sub = XVECEXP (pat, 0, i);
859 switch (GET_CODE (sub))
866 /* We can consider insns having multiple sets, where all
867 but one are dead as single set insns. In common case
868 only single set is present in the pattern so we want
869 to avoid checking for REG_UNUSED notes unless neccesary.
871 When we reach set first time, we just expect this is
872 the single set we are looking for and only when more
873 sets are found in the insn, we check them. */
876 if (find_reg_note (insn, REG_UNUSED, SET_DEST (set))
877 && !side_effects_p (set))
883 set = sub, set_verified = 0;
884 else if (!find_reg_note (insn, REG_UNUSED, SET_DEST (sub))
885 || side_effects_p (sub))
897 /* Given an INSN, return nonzero if it has more than one SET, else return
907 /* INSN must be an insn. */
911 /* Only a PARALLEL can have multiple SETs. */
912 if (GET_CODE (PATTERN (insn)) == PARALLEL)
914 for (i = 0, found = 0; i < XVECLEN (PATTERN (insn), 0); i++)
915 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
917 /* If we have already found a SET, then return now. */
925 /* Either zero or one SET. */
929 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
930 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
931 If the object was modified, if we hit a partial assignment to X, or hit a
932 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
933 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
937 find_last_value (x, pinsn, valid_to, allow_hwreg)
945 for (p = PREV_INSN (*pinsn); p && GET_CODE (p) != CODE_LABEL;
949 rtx set = single_set (p);
950 rtx note = find_reg_note (p, REG_EQUAL, NULL_RTX);
952 if (set && rtx_equal_p (x, SET_DEST (set)))
954 rtx src = SET_SRC (set);
956 if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
957 src = XEXP (note, 0);
959 if ((valid_to == NULL_RTX
960 || ! modified_between_p (src, PREV_INSN (p), valid_to))
961 /* Reject hard registers because we don't usually want
962 to use them; we'd rather use a pseudo. */
963 && (! (GET_CODE (src) == REG
964 && REGNO (src) < FIRST_PSEUDO_REGISTER) || allow_hwreg))
971 /* If set in non-simple way, we don't have a value. */
972 if (reg_set_p (x, p))
979 /* Return nonzero if register in range [REGNO, ENDREGNO)
980 appears either explicitly or implicitly in X
981 other than being stored into.
983 References contained within the substructure at LOC do not count.
984 LOC may be zero, meaning don't ignore anything. */
987 refers_to_regno_p (regno, endregno, x, loc)
988 unsigned int regno, endregno;
993 unsigned int x_regno;
998 /* The contents of a REG_NONNEG note is always zero, so we must come here
999 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
1003 code = GET_CODE (x);
1008 x_regno = REGNO (x);
1010 /* If we modifying the stack, frame, or argument pointer, it will
1011 clobber a virtual register. In fact, we could be more precise,
1012 but it isn't worth it. */
1013 if ((x_regno == STACK_POINTER_REGNUM
1014 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1015 || x_regno == ARG_POINTER_REGNUM
1017 || x_regno == FRAME_POINTER_REGNUM)
1018 && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER)
1021 return (endregno > x_regno
1022 && regno < x_regno + (x_regno < FIRST_PSEUDO_REGISTER
1023 ? HARD_REGNO_NREGS (x_regno, GET_MODE (x))
1027 /* If this is a SUBREG of a hard reg, we can see exactly which
1028 registers are being modified. Otherwise, handle normally. */
1029 if (GET_CODE (SUBREG_REG (x)) == REG
1030 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
1032 unsigned int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
1033 unsigned int inner_endregno
1034 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
1035 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
1037 return endregno > inner_regno && regno < inner_endregno;
1043 if (&SET_DEST (x) != loc
1044 /* Note setting a SUBREG counts as referring to the REG it is in for
1045 a pseudo but not for hard registers since we can
1046 treat each word individually. */
1047 && ((GET_CODE (SET_DEST (x)) == SUBREG
1048 && loc != &SUBREG_REG (SET_DEST (x))
1049 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
1050 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
1051 && refers_to_regno_p (regno, endregno,
1052 SUBREG_REG (SET_DEST (x)), loc))
1053 || (GET_CODE (SET_DEST (x)) != REG
1054 && refers_to_regno_p (regno, endregno, SET_DEST (x), loc))))
1057 if (code == CLOBBER || loc == &SET_SRC (x))
1066 /* X does not match, so try its subexpressions. */
1068 fmt = GET_RTX_FORMAT (code);
1069 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1071 if (fmt[i] == 'e' && loc != &XEXP (x, i))
1079 if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc))
1082 else if (fmt[i] == 'E')
1085 for (j = XVECLEN (x, i) - 1; j >=0; j--)
1086 if (loc != &XVECEXP (x, i, j)
1087 && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc))
1094 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
1095 we check if any register number in X conflicts with the relevant register
1096 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
1097 contains a MEM (we don't bother checking for memory addresses that can't
1098 conflict because we expect this to be a rare case. */
1101 reg_overlap_mentioned_p (x, in)
1104 unsigned int regno, endregno;
1106 /* Overly conservative. */
1107 if (GET_CODE (x) == STRICT_LOW_PART)
1110 /* If either argument is a constant, then modifying X can not affect IN. */
1111 if (CONSTANT_P (x) || CONSTANT_P (in))
1114 switch (GET_CODE (x))
1117 regno = REGNO (SUBREG_REG (x));
1118 if (regno < FIRST_PSEUDO_REGISTER)
1119 regno += SUBREG_WORD (x);
1125 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
1126 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
1127 return refers_to_regno_p (regno, endregno, in, NULL_PTR);
1134 if (GET_CODE (in) == MEM)
1137 fmt = GET_RTX_FORMAT (GET_CODE (in));
1138 for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--)
1139 if (fmt[i] == 'e' && reg_overlap_mentioned_p (x, XEXP (in, i)))
1148 return reg_mentioned_p (x, in);
1154 /* Check for a NULL entry, used to indicate that the parameter goes
1155 both on the stack and in registers. */
1156 if (XEXP (XVECEXP (x, 0, 0), 0))
1161 /* If any register in here refers to it we return true. */
1162 for (n = XVECLEN (x, 0); i < n; ++i)
1163 if (reg_overlap_mentioned_p (XEXP (XVECEXP (x, 0, i), 0), in))
1175 /* Used for communications between the next few functions. */
1177 static int reg_set_last_unknown;
1178 static rtx reg_set_last_value;
1179 static unsigned int reg_set_last_first_regno, reg_set_last_last_regno;
1181 /* Called via note_stores from reg_set_last. */
1184 reg_set_last_1 (x, pat, data)
1187 void *data ATTRIBUTE_UNUSED;
1189 unsigned int first, last;
1191 /* If X is not a register, or is not one in the range we care
1193 if (GET_CODE (x) != REG)
1197 last = first + (first < FIRST_PSEUDO_REGISTER
1198 ? HARD_REGNO_NREGS (first, GET_MODE (x)) : 1);
1200 if (first >= reg_set_last_last_regno
1201 || last <= reg_set_last_first_regno)
1204 /* If this is a CLOBBER or is some complex LHS, or doesn't modify
1205 exactly the registers we care about, show we don't know the value. */
1206 if (GET_CODE (pat) == CLOBBER || SET_DEST (pat) != x
1207 || first != reg_set_last_first_regno
1208 || last != reg_set_last_last_regno)
1209 reg_set_last_unknown = 1;
1211 reg_set_last_value = SET_SRC (pat);
1214 /* Return the last value to which REG was set prior to INSN. If we can't
1215 find it easily, return 0.
1217 We only return a REG, SUBREG, or constant because it is too hard to
1218 check if a MEM remains unchanged. */
1221 reg_set_last (x, insn)
1225 rtx orig_insn = insn;
1227 reg_set_last_first_regno = REGNO (x);
1229 reg_set_last_last_regno
1230 = reg_set_last_first_regno
1231 + (reg_set_last_first_regno < FIRST_PSEUDO_REGISTER
1232 ? HARD_REGNO_NREGS (reg_set_last_first_regno, GET_MODE (x)) : 1);
1234 reg_set_last_unknown = 0;
1235 reg_set_last_value = 0;
1237 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1238 Stop when we reach a label or X is a hard reg and we reach a
1239 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1241 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1243 /* We compare with <= here, because reg_set_last_last_regno
1244 is actually the number of the first reg *not* in X. */
1246 insn && GET_CODE (insn) != CODE_LABEL
1247 && ! (GET_CODE (insn) == CALL_INSN
1248 && reg_set_last_last_regno <= FIRST_PSEUDO_REGISTER);
1249 insn = PREV_INSN (insn))
1252 note_stores (PATTERN (insn), reg_set_last_1, NULL);
1253 if (reg_set_last_unknown)
1255 else if (reg_set_last_value)
1257 if (CONSTANT_P (reg_set_last_value)
1258 || ((GET_CODE (reg_set_last_value) == REG
1259 || GET_CODE (reg_set_last_value) == SUBREG)
1260 && ! reg_set_between_p (reg_set_last_value,
1262 return reg_set_last_value;
1271 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1272 (X would be the pattern of an insn).
1273 FUN receives two arguments:
1274 the REG, MEM, CC0 or PC being stored in or clobbered,
1275 the SET or CLOBBER rtx that does the store.
1277 If the item being stored in or clobbered is a SUBREG of a hard register,
1278 the SUBREG will be passed. */
1281 note_stores (x, fun, data)
1283 void (*fun) PARAMS ((rtx, rtx, void *));
1286 if (GET_CODE (x) == COND_EXEC)
1287 x = COND_EXEC_CODE (x);
1288 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
1290 register rtx dest = SET_DEST (x);
1291 while ((GET_CODE (dest) == SUBREG
1292 && (GET_CODE (SUBREG_REG (dest)) != REG
1293 || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER))
1294 || GET_CODE (dest) == ZERO_EXTRACT
1295 || GET_CODE (dest) == SIGN_EXTRACT
1296 || GET_CODE (dest) == STRICT_LOW_PART)
1297 dest = XEXP (dest, 0);
1299 if (GET_CODE (dest) == PARALLEL
1300 && GET_MODE (dest) == BLKmode)
1303 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
1304 (*fun) (SET_DEST (XVECEXP (dest, 0, i)), x, data);
1307 (*fun) (dest, x, data);
1309 else if (GET_CODE (x) == PARALLEL)
1312 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1314 register rtx y = XVECEXP (x, 0, i);
1315 if (GET_CODE (y) == COND_EXEC)
1316 y = COND_EXEC_CODE (y);
1317 if (GET_CODE (y) == SET || GET_CODE (y) == CLOBBER)
1319 register rtx dest = SET_DEST (y);
1320 while ((GET_CODE (dest) == SUBREG
1321 && (GET_CODE (SUBREG_REG (dest)) != REG
1322 || (REGNO (SUBREG_REG (dest))
1323 >= FIRST_PSEUDO_REGISTER)))
1324 || GET_CODE (dest) == ZERO_EXTRACT
1325 || GET_CODE (dest) == SIGN_EXTRACT
1326 || GET_CODE (dest) == STRICT_LOW_PART)
1327 dest = XEXP (dest, 0);
1328 if (GET_CODE (dest) == PARALLEL
1329 && GET_MODE (dest) == BLKmode)
1333 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
1334 (*fun) (SET_DEST (XVECEXP (dest, 0, i)), y, data);
1337 (*fun) (dest, y, data);
1343 /* Return nonzero if X's old contents don't survive after INSN.
1344 This will be true if X is (cc0) or if X is a register and
1345 X dies in INSN or because INSN entirely sets X.
1347 "Entirely set" means set directly and not through a SUBREG,
1348 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1349 Likewise, REG_INC does not count.
1351 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1352 but for this use that makes no difference, since regs don't overlap
1353 during their lifetimes. Therefore, this function may be used
1354 at any time after deaths have been computed (in flow.c).
1356 If REG is a hard reg that occupies multiple machine registers, this
1357 function will only return 1 if each of those registers will be replaced
1361 dead_or_set_p (insn, x)
1365 unsigned int regno, last_regno;
1368 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1369 if (GET_CODE (x) == CC0)
1372 if (GET_CODE (x) != REG)
1376 last_regno = (regno >= FIRST_PSEUDO_REGISTER ? regno
1377 : regno + HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1);
1379 for (i = regno; i <= last_regno; i++)
1380 if (! dead_or_set_regno_p (insn, i))
1386 /* Utility function for dead_or_set_p to check an individual register. Also
1387 called from flow.c. */
1390 dead_or_set_regno_p (insn, test_regno)
1392 unsigned int test_regno;
1394 unsigned int regno, endregno;
1397 /* See if there is a death note for something that includes TEST_REGNO. */
1398 if (find_regno_note (insn, REG_DEAD, test_regno))
1401 if (GET_CODE (insn) == CALL_INSN
1402 && find_regno_fusage (insn, CLOBBER, test_regno))
1405 pattern = PATTERN (insn);
1407 if (GET_CODE (pattern) == COND_EXEC)
1408 pattern = COND_EXEC_CODE (pattern);
1410 if (GET_CODE (pattern) == SET)
1412 rtx dest = SET_DEST (PATTERN (insn));
1414 /* A value is totally replaced if it is the destination or the
1415 destination is a SUBREG of REGNO that does not change the number of
1417 if (GET_CODE (dest) == SUBREG
1418 && (((GET_MODE_SIZE (GET_MODE (dest))
1419 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1420 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1421 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1422 dest = SUBREG_REG (dest);
1424 if (GET_CODE (dest) != REG)
1427 regno = REGNO (dest);
1428 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1429 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1431 return (test_regno >= regno && test_regno < endregno);
1433 else if (GET_CODE (pattern) == PARALLEL)
1437 for (i = XVECLEN (pattern, 0) - 1; i >= 0; i--)
1439 rtx body = XVECEXP (pattern, 0, i);
1441 if (GET_CODE (body) == COND_EXEC)
1442 body = COND_EXEC_CODE (body);
1444 if (GET_CODE (body) == SET || GET_CODE (body) == CLOBBER)
1446 rtx dest = SET_DEST (body);
1448 if (GET_CODE (dest) == SUBREG
1449 && (((GET_MODE_SIZE (GET_MODE (dest))
1450 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1451 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1452 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1453 dest = SUBREG_REG (dest);
1455 if (GET_CODE (dest) != REG)
1458 regno = REGNO (dest);
1459 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1460 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1462 if (test_regno >= regno && test_regno < endregno)
1471 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1472 If DATUM is nonzero, look for one whose datum is DATUM. */
1475 find_reg_note (insn, kind, datum)
1482 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1483 if (! INSN_P (insn))
1486 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1487 if (REG_NOTE_KIND (link) == kind
1488 && (datum == 0 || datum == XEXP (link, 0)))
1493 /* Return the reg-note of kind KIND in insn INSN which applies to register
1494 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1495 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1496 it might be the case that the note overlaps REGNO. */
1499 find_regno_note (insn, kind, regno)
1506 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1507 if (! INSN_P (insn))
1510 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1511 if (REG_NOTE_KIND (link) == kind
1512 /* Verify that it is a register, so that scratch and MEM won't cause a
1514 && GET_CODE (XEXP (link, 0)) == REG
1515 && REGNO (XEXP (link, 0)) <= regno
1516 && ((REGNO (XEXP (link, 0))
1517 + (REGNO (XEXP (link, 0)) >= FIRST_PSEUDO_REGISTER ? 1
1518 : HARD_REGNO_NREGS (REGNO (XEXP (link, 0)),
1519 GET_MODE (XEXP (link, 0)))))
1525 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1526 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1529 find_reg_fusage (insn, code, datum)
1534 /* If it's not a CALL_INSN, it can't possibly have a
1535 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1536 if (GET_CODE (insn) != CALL_INSN)
1542 if (GET_CODE (datum) != REG)
1546 for (link = CALL_INSN_FUNCTION_USAGE (insn);
1548 link = XEXP (link, 1))
1549 if (GET_CODE (XEXP (link, 0)) == code
1550 && rtx_equal_p (datum, SET_DEST (XEXP (link, 0))))
1555 unsigned int regno = REGNO (datum);
1557 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1558 to pseudo registers, so don't bother checking. */
1560 if (regno < FIRST_PSEUDO_REGISTER)
1562 unsigned int end_regno
1563 = regno + HARD_REGNO_NREGS (regno, GET_MODE (datum));
1566 for (i = regno; i < end_regno; i++)
1567 if (find_regno_fusage (insn, code, i))
1575 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1576 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1579 find_regno_fusage (insn, code, regno)
1586 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1587 to pseudo registers, so don't bother checking. */
1589 if (regno >= FIRST_PSEUDO_REGISTER
1590 || GET_CODE (insn) != CALL_INSN )
1593 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
1595 unsigned int regnote;
1598 if (GET_CODE (op = XEXP (link, 0)) == code
1599 && GET_CODE (reg = XEXP (op, 0)) == REG
1600 && (regnote = REGNO (reg)) <= regno
1601 && regnote + HARD_REGNO_NREGS (regnote, GET_MODE (reg)) > regno)
1608 /* Remove register note NOTE from the REG_NOTES of INSN. */
1611 remove_note (insn, note)
1617 if (note == NULL_RTX)
1620 if (REG_NOTES (insn) == note)
1622 REG_NOTES (insn) = XEXP (note, 1);
1626 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1627 if (XEXP (link, 1) == note)
1629 XEXP (link, 1) = XEXP (note, 1);
1636 /* Search LISTP (an EXPR_LIST) for NODE and remove NODE from the list
1639 A simple equality test is used to determine if NODE is on the
1643 remove_node_from_expr_list (node, listp)
1648 rtx prev = NULL_RTX;
1652 if (node == XEXP (temp, 0))
1654 /* Splice the node out of the list. */
1656 XEXP (prev, 1) = XEXP (temp, 1);
1658 *listp = XEXP (temp, 1);
1662 temp = XEXP (temp, 1);
1666 /* Nonzero if X contains any volatile instructions. These are instructions
1667 which may cause unpredictable machine state instructions, and thus no
1668 instructions should be moved or combined across them. This includes
1669 only volatile asms and UNSPEC_VOLATILE instructions. */
1675 register RTX_CODE code;
1677 code = GET_CODE (x);
1697 case UNSPEC_VOLATILE:
1698 /* case TRAP_IF: This isn't clear yet. */
1702 if (MEM_VOLATILE_P (x))
1709 /* Recursively scan the operands of this expression. */
1712 register const char *fmt = GET_RTX_FORMAT (code);
1715 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1719 if (volatile_insn_p (XEXP (x, i)))
1722 else if (fmt[i] == 'E')
1725 for (j = 0; j < XVECLEN (x, i); j++)
1726 if (volatile_insn_p (XVECEXP (x, i, j)))
1734 /* Nonzero if X contains any volatile memory references
1735 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1741 register RTX_CODE code;
1743 code = GET_CODE (x);
1762 case UNSPEC_VOLATILE:
1763 /* case TRAP_IF: This isn't clear yet. */
1768 if (MEM_VOLATILE_P (x))
1775 /* Recursively scan the operands of this expression. */
1778 register const char *fmt = GET_RTX_FORMAT (code);
1781 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1785 if (volatile_refs_p (XEXP (x, i)))
1788 else if (fmt[i] == 'E')
1791 for (j = 0; j < XVECLEN (x, i); j++)
1792 if (volatile_refs_p (XVECEXP (x, i, j)))
1800 /* Similar to above, except that it also rejects register pre- and post-
1807 register RTX_CODE code;
1809 code = GET_CODE (x);
1827 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1828 when some combination can't be done. If we see one, don't think
1829 that we can simplify the expression. */
1830 return (GET_MODE (x) != VOIDmode);
1837 case UNSPEC_VOLATILE:
1838 /* case TRAP_IF: This isn't clear yet. */
1843 if (MEM_VOLATILE_P (x))
1850 /* Recursively scan the operands of this expression. */
1853 register const char *fmt = GET_RTX_FORMAT (code);
1856 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1860 if (side_effects_p (XEXP (x, i)))
1863 else if (fmt[i] == 'E')
1866 for (j = 0; j < XVECLEN (x, i); j++)
1867 if (side_effects_p (XVECEXP (x, i, j)))
1875 /* Return nonzero if evaluating rtx X might cause a trap. */
1887 code = GET_CODE (x);
1890 /* Handle these cases quickly. */
1903 case UNSPEC_VOLATILE:
1908 return MEM_VOLATILE_P (x);
1910 /* Memory ref can trap unless it's a static var or a stack slot. */
1912 return rtx_addr_can_trap_p (XEXP (x, 0));
1914 /* Division by a non-constant might trap. */
1919 if (! CONSTANT_P (XEXP (x, 1))
1920 || GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1922 /* This was const0_rtx, but by not using that,
1923 we can link this file into other programs. */
1924 if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
1929 /* An EXPR_LIST is used to represent a function call. This
1930 certainly may trap. */
1934 /* Any floating comparison may trap. */
1935 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1937 /* But often the compare has some CC mode, so check operand
1939 if (GET_MODE_CLASS (GET_MODE (XEXP (x, 0))) == MODE_FLOAT
1940 || GET_MODE_CLASS (GET_MODE (XEXP (x, 1))) == MODE_FLOAT)
1945 /* Any floating arithmetic may trap. */
1946 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1950 fmt = GET_RTX_FORMAT (code);
1951 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1955 if (may_trap_p (XEXP (x, i)))
1958 else if (fmt[i] == 'E')
1961 for (j = 0; j < XVECLEN (x, i); j++)
1962 if (may_trap_p (XVECEXP (x, i, j)))
1969 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1970 i.e., an inequality. */
1973 inequality_comparisons_p (x)
1976 register const char *fmt;
1977 register int len, i;
1978 register enum rtx_code code = GET_CODE (x);
2007 len = GET_RTX_LENGTH (code);
2008 fmt = GET_RTX_FORMAT (code);
2010 for (i = 0; i < len; i++)
2014 if (inequality_comparisons_p (XEXP (x, i)))
2017 else if (fmt[i] == 'E')
2020 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2021 if (inequality_comparisons_p (XVECEXP (x, i, j)))
2029 /* Replace any occurrence of FROM in X with TO. The function does
2030 not enter into CONST_DOUBLE for the replace.
2032 Note that copying is not done so X must not be shared unless all copies
2033 are to be modified. */
2036 replace_rtx (x, from, to)
2040 register const char *fmt;
2042 /* The following prevents loops occurrence when we change MEM in
2043 CONST_DOUBLE onto the same CONST_DOUBLE. */
2044 if (x != 0 && GET_CODE (x) == CONST_DOUBLE)
2050 /* Allow this function to make replacements in EXPR_LISTs. */
2054 fmt = GET_RTX_FORMAT (GET_CODE (x));
2055 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2058 XEXP (x, i) = replace_rtx (XEXP (x, i), from, to);
2059 else if (fmt[i] == 'E')
2060 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2061 XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to);
2067 /* Throughout the rtx X, replace many registers according to REG_MAP.
2068 Return the replacement for X (which may be X with altered contents).
2069 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
2070 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
2072 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
2073 should not be mapped to pseudos or vice versa since validate_change
2076 If REPLACE_DEST is 1, replacements are also done in destinations;
2077 otherwise, only sources are replaced. */
2080 replace_regs (x, reg_map, nregs, replace_dest)
2086 register enum rtx_code code;
2088 register const char *fmt;
2093 code = GET_CODE (x);
2107 /* Verify that the register has an entry before trying to access it. */
2108 if (REGNO (x) < nregs && reg_map[REGNO (x)] != 0)
2110 /* SUBREGs can't be shared. Always return a copy to ensure that if
2111 this replacement occurs more than once then each instance will
2112 get distinct rtx. */
2113 if (GET_CODE (reg_map[REGNO (x)]) == SUBREG)
2114 return copy_rtx (reg_map[REGNO (x)]);
2115 return reg_map[REGNO (x)];
2120 /* Prevent making nested SUBREGs. */
2121 if (GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) < nregs
2122 && reg_map[REGNO (SUBREG_REG (x))] != 0
2123 && GET_CODE (reg_map[REGNO (SUBREG_REG (x))]) == SUBREG)
2125 rtx map_val = reg_map[REGNO (SUBREG_REG (x))];
2126 rtx map_inner = SUBREG_REG (map_val);
2128 if (GET_MODE (x) == GET_MODE (map_inner))
2132 /* We cannot call gen_rtx here since we may be linked with
2134 /* Let's try clobbering the incoming SUBREG and see
2135 if this is really safe. */
2136 SUBREG_REG (x) = map_inner;
2137 SUBREG_WORD (x) += SUBREG_WORD (map_val);
2140 rtx new = rtx_alloc (SUBREG);
2141 PUT_MODE (new, GET_MODE (x));
2142 SUBREG_REG (new) = map_inner;
2143 SUBREG_WORD (new) = SUBREG_WORD (x) + SUBREG_WORD (map_val);
2151 SET_DEST (x) = replace_regs (SET_DEST (x), reg_map, nregs, 0);
2153 else if (GET_CODE (SET_DEST (x)) == MEM
2154 || GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2155 /* Even if we are not to replace destinations, replace register if it
2156 is CONTAINED in destination (destination is memory or
2157 STRICT_LOW_PART). */
2158 XEXP (SET_DEST (x), 0) = replace_regs (XEXP (SET_DEST (x), 0),
2160 else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2161 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2164 SET_SRC (x) = replace_regs (SET_SRC (x), reg_map, nregs, 0);
2171 fmt = GET_RTX_FORMAT (code);
2172 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2175 XEXP (x, i) = replace_regs (XEXP (x, i), reg_map, nregs, replace_dest);
2176 else if (fmt[i] == 'E')
2179 for (j = 0; j < XVECLEN (x, i); j++)
2180 XVECEXP (x, i, j) = replace_regs (XVECEXP (x, i, j), reg_map,
2181 nregs, replace_dest);
2187 /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is
2188 not in the constant pool and not in the condition of an IF_THEN_ELSE. */
2191 jmp_uses_reg_or_mem (x)
2194 enum rtx_code code = GET_CODE (x);
2209 return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
2210 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
2213 return (jmp_uses_reg_or_mem (XEXP (x, 1))
2214 || jmp_uses_reg_or_mem (XEXP (x, 2)));
2216 case PLUS: case MINUS: case MULT:
2217 return (jmp_uses_reg_or_mem (XEXP (x, 0))
2218 || jmp_uses_reg_or_mem (XEXP (x, 1)));
2224 fmt = GET_RTX_FORMAT (code);
2225 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2228 && jmp_uses_reg_or_mem (XEXP (x, i)))
2231 else if (fmt[i] == 'E')
2232 for (j = 0; j < XVECLEN (x, i); j++)
2233 if (jmp_uses_reg_or_mem (XVECEXP (x, i, j)))
2240 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2242 Tablejumps and casesi insns are not considered indirect jumps;
2243 we can recognize them by a (use (label_ref)). */
2246 computed_jump_p (insn)
2250 if (GET_CODE (insn) == JUMP_INSN)
2252 rtx pat = PATTERN (insn);
2254 if (GET_CODE (pat) == PARALLEL)
2256 int len = XVECLEN (pat, 0);
2257 int has_use_labelref = 0;
2259 for (i = len - 1; i >= 0; i--)
2260 if (GET_CODE (XVECEXP (pat, 0, i)) == USE
2261 && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0))
2263 has_use_labelref = 1;
2265 if (! has_use_labelref)
2266 for (i = len - 1; i >= 0; i--)
2267 if (GET_CODE (XVECEXP (pat, 0, i)) == SET
2268 && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx
2269 && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat, 0, i))))
2272 else if (GET_CODE (pat) == SET
2273 && SET_DEST (pat) == pc_rtx
2274 && jmp_uses_reg_or_mem (SET_SRC (pat)))
2280 /* Traverse X via depth-first search, calling F for each
2281 sub-expression (including X itself). F is also passed the DATA.
2282 If F returns -1, do not traverse sub-expressions, but continue
2283 traversing the rest of the tree. If F ever returns any other
2284 non-zero value, stop the traversal, and return the value returned
2285 by F. Otherwise, return 0. This function does not traverse inside
2286 tree structure that contains RTX_EXPRs, or into sub-expressions
2287 whose format code is `0' since it is not known whether or not those
2288 codes are actually RTL.
2290 This routine is very general, and could (should?) be used to
2291 implement many of the other routines in this file. */
2294 for_each_rtx (x, f, data)
2305 result = (*f)(x, data);
2307 /* Do not traverse sub-expressions. */
2309 else if (result != 0)
2310 /* Stop the traversal. */
2314 /* There are no sub-expressions. */
2317 length = GET_RTX_LENGTH (GET_CODE (*x));
2318 format = GET_RTX_FORMAT (GET_CODE (*x));
2320 for (i = 0; i < length; ++i)
2325 result = for_each_rtx (&XEXP (*x, i), f, data);
2332 if (XVEC (*x, i) != 0)
2335 for (j = 0; j < XVECLEN (*x, i); ++j)
2337 result = for_each_rtx (&XVECEXP (*x, i, j), f, data);
2345 /* Nothing to do. */
2354 /* Searches X for any reference to REGNO, returning the rtx of the
2355 reference found if any. Otherwise, returns NULL_RTX. */
2358 regno_use_in (regno, x)
2362 register const char *fmt;
2366 if (GET_CODE (x) == REG && REGNO (x) == regno)
2369 fmt = GET_RTX_FORMAT (GET_CODE (x));
2370 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2374 if ((tem = regno_use_in (regno, XEXP (x, i))))
2377 else if (fmt[i] == 'E')
2378 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2379 if ((tem = regno_use_in (regno , XVECEXP (x, i, j))))
2387 /* Return 1 if X is an autoincrement side effect and the register is
2388 not the stack pointer. */
2393 switch (GET_CODE (x))
2401 /* There are no REG_INC notes for SP. */
2402 if (XEXP (x, 0) != stack_pointer_rtx)
2410 /* Return 1 if the sequence of instructions beginning with FROM and up
2411 to and including TO is safe to move. If NEW_TO is non-NULL, and
2412 the sequence is not already safe to move, but can be easily
2413 extended to a sequence which is safe, then NEW_TO will point to the
2414 end of the extended sequence.
2416 For now, this function only checks that the region contains whole
2417 exception regiongs, but it could be extended to check additional
2418 conditions as well. */
2421 insns_safe_to_move_p (from, to, new_to)
2426 int eh_region_count = 0;
2430 /* By default, assume the end of the region will be what was
2437 if (GET_CODE (r) == NOTE)
2439 switch (NOTE_LINE_NUMBER (r))
2441 case NOTE_INSN_EH_REGION_BEG:
2445 case NOTE_INSN_EH_REGION_END:
2446 if (eh_region_count == 0)
2447 /* This sequence of instructions contains the end of
2448 an exception region, but not he beginning. Moving
2449 it will cause chaos. */
2460 /* If we've passed TO, and we see a non-note instruction, we
2461 can't extend the sequence to a movable sequence. */
2467 /* It's OK to move the sequence if there were matched sets of
2468 exception region notes. */
2469 return eh_region_count == 0;
2474 /* It's OK to move the sequence if there were matched sets of
2475 exception region notes. */
2476 if (past_to_p && eh_region_count == 0)
2482 /* Go to the next instruction. */
2489 /* Return non-zero if IN contains a piece of rtl that has the address LOC */
2491 loc_mentioned_in_p (loc, in)
2494 enum rtx_code code = GET_CODE (in);
2495 const char *fmt = GET_RTX_FORMAT (code);
2498 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2500 if (loc == &in->fld[i].rtx)
2504 if (loc_mentioned_in_p (loc, XEXP (in, i)))
2507 else if (fmt[i] == 'E')
2508 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
2509 if (loc_mentioned_in_p (loc, XVECEXP (in, i, j)))