1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "hard-reg-set.h"
30 /* Forward declarations */
31 static void set_of_1 PARAMS ((rtx, rtx, void *));
32 static void insn_dependent_p_1 PARAMS ((rtx, rtx, void *));
33 static int computed_jump_p_1 PARAMS ((rtx));
34 static void parms_set PARAMS ((rtx, rtx, void *));
36 /* Bit flags that specify the machine subtype we are compiling for.
37 Bits are tested using macros TARGET_... defined in the tm.h file
38 and set by `-m...' switches. Must be defined in rtlanal.c. */
42 /* Return 1 if the value of X is unstable
43 (would be different at a different point in the program).
44 The frame pointer, arg pointer, etc. are considered stable
45 (within one function) and so is anything marked `unchanging'. */
51 RTX_CODE code = GET_CODE (x);
58 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 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
74 /* The arg pointer varies if it is not a fixed register. */
75 || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])
76 || RTX_UNCHANGING_P (x))
78 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
79 /* ??? When call-clobbered, the value is stable modulo the restore
80 that must happen after a call. This currently screws up local-alloc
81 into believing that the restore is not needed. */
82 if (x == pic_offset_table_rtx)
88 if (MEM_VOLATILE_P (x))
97 fmt = GET_RTX_FORMAT (code);
98 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
101 if (rtx_unstable_p (XEXP (x, i)))
104 else if (fmt[i] == 'E')
107 for (j = 0; j < XVECLEN (x, i); j++)
108 if (rtx_unstable_p (XVECEXP (x, i, j)))
115 /* Return 1 if X has a value that can vary even between two
116 executions of the program. 0 means X can be compared reliably
117 against certain constants or near-constants.
118 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
119 zero, we are slightly more conservative.
120 The frame pointer and the arg pointer are considered constant. */
123 rtx_varies_p (x, for_alias)
127 RTX_CODE code = GET_CODE (x);
134 return ! RTX_UNCHANGING_P (x) || rtx_varies_p (XEXP (x, 0), for_alias);
147 /* Note that we have to test for the actual rtx used for the frame
148 and arg pointers and not just the register number in case we have
149 eliminated the frame and/or arg pointer and are using it
151 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
152 /* The arg pointer varies if it is not a fixed register. */
153 || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
155 if (x == pic_offset_table_rtx
156 #ifdef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
157 /* ??? When call-clobbered, the value is stable modulo the restore
158 that must happen after a call. This currently screws up
159 local-alloc into believing that the restore is not needed, so we
160 must return 0 only if we are called from alias analysis. */
168 /* The operand 0 of a LO_SUM is considered constant
169 (in fact it is related specifically to operand 1)
170 during alias analysis. */
171 return (! for_alias && rtx_varies_p (XEXP (x, 0), for_alias))
172 || rtx_varies_p (XEXP (x, 1), for_alias);
175 if (MEM_VOLATILE_P (x))
184 fmt = GET_RTX_FORMAT (code);
185 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
188 if (rtx_varies_p (XEXP (x, i), for_alias))
191 else if (fmt[i] == 'E')
194 for (j = 0; j < XVECLEN (x, i); j++)
195 if (rtx_varies_p (XVECEXP (x, i, j), for_alias))
202 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
205 rtx_addr_can_trap_p (x)
208 enum rtx_code code = GET_CODE (x);
213 return SYMBOL_REF_WEAK (x);
219 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
220 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
221 || x == stack_pointer_rtx
222 /* The arg pointer varies if it is not a fixed register. */
223 || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
225 /* All of the virtual frame registers are stack references. */
226 if (REGNO (x) >= FIRST_VIRTUAL_REGISTER
227 && REGNO (x) <= LAST_VIRTUAL_REGISTER)
232 return rtx_addr_can_trap_p (XEXP (x, 0));
235 /* An address is assumed not to trap if it is an address that can't
236 trap plus a constant integer or it is the pic register plus a
238 return ! ((! rtx_addr_can_trap_p (XEXP (x, 0))
239 && GET_CODE (XEXP (x, 1)) == CONST_INT)
240 || (XEXP (x, 0) == pic_offset_table_rtx
241 && CONSTANT_P (XEXP (x, 1))));
245 return rtx_addr_can_trap_p (XEXP (x, 1));
252 return rtx_addr_can_trap_p (XEXP (x, 0));
258 /* If it isn't one of the case above, it can cause a trap. */
262 /* Return 1 if X refers to a memory location whose address
263 cannot be compared reliably with constant addresses,
264 or if X refers to a BLKmode memory object.
265 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
266 zero, we are slightly more conservative. */
269 rtx_addr_varies_p (x, for_alias)
282 return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0), for_alias);
284 fmt = GET_RTX_FORMAT (code);
285 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
288 if (rtx_addr_varies_p (XEXP (x, i), for_alias))
291 else if (fmt[i] == 'E')
294 for (j = 0; j < XVECLEN (x, i); j++)
295 if (rtx_addr_varies_p (XVECEXP (x, i, j), for_alias))
301 /* Return the value of the integer term in X, if one is apparent;
303 Only obvious integer terms are detected.
304 This is used in cse.c with the `related_value' field.*/
310 if (GET_CODE (x) == CONST)
313 if (GET_CODE (x) == MINUS
314 && GET_CODE (XEXP (x, 1)) == CONST_INT)
315 return - INTVAL (XEXP (x, 1));
316 if (GET_CODE (x) == PLUS
317 && GET_CODE (XEXP (x, 1)) == CONST_INT)
318 return INTVAL (XEXP (x, 1));
322 /* If X is a constant, return the value sans apparent integer term;
324 Only obvious integer terms are detected. */
327 get_related_value (x)
330 if (GET_CODE (x) != CONST)
333 if (GET_CODE (x) == PLUS
334 && GET_CODE (XEXP (x, 1)) == CONST_INT)
336 else if (GET_CODE (x) == MINUS
337 && GET_CODE (XEXP (x, 1)) == CONST_INT)
342 /* Given a tablejump insn INSN, return the RTL expression for the offset
343 into the jump table. If the offset cannot be determined, then return
346 If EARLIEST is non-zero, it is a pointer to a place where the earliest
347 insn used in locating the offset was found. */
350 get_jump_table_offset (insn, earliest)
365 if (GET_CODE (insn) != JUMP_INSN
366 || ! (label = JUMP_LABEL (insn))
367 || ! (table = NEXT_INSN (label))
368 || GET_CODE (table) != JUMP_INSN
369 || (GET_CODE (PATTERN (table)) != ADDR_VEC
370 && GET_CODE (PATTERN (table)) != ADDR_DIFF_VEC)
371 || ! (set = single_set (insn)))
376 /* Some targets (eg, ARM) emit a tablejump that also
377 contains the out-of-range target. */
378 if (GET_CODE (x) == IF_THEN_ELSE
379 && GET_CODE (XEXP (x, 2)) == LABEL_REF)
382 /* Search backwards and locate the expression stored in X. */
383 for (old_x = NULL_RTX; GET_CODE (x) == REG && x != old_x;
384 old_x = x, x = find_last_value (x, &insn, NULL_RTX, 0))
387 /* If X is an expression using a relative address then strip
388 off the addition / subtraction of PC, PIC_OFFSET_TABLE_REGNUM,
389 or the jump table label. */
390 if (GET_CODE (PATTERN (table)) == ADDR_DIFF_VEC
391 && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS))
393 for (i = 0; i < 2; i++)
398 if (y == pc_rtx || y == pic_offset_table_rtx)
401 for (old_y = NULL_RTX; GET_CODE (y) == REG && y != old_y;
402 old_y = y, y = find_last_value (y, &old_insn, NULL_RTX, 0))
405 if ((GET_CODE (y) == LABEL_REF && XEXP (y, 0) == label))
414 for (old_x = NULL_RTX; GET_CODE (x) == REG && x != old_x;
415 old_x = x, x = find_last_value (x, &insn, NULL_RTX, 0))
419 /* Strip off any sign or zero extension. */
420 if (GET_CODE (x) == SIGN_EXTEND || GET_CODE (x) == ZERO_EXTEND)
424 for (old_x = NULL_RTX; GET_CODE (x) == REG && x != old_x;
425 old_x = x, x = find_last_value (x, &insn, NULL_RTX, 0))
429 /* If X isn't a MEM then this isn't a tablejump we understand. */
430 if (GET_CODE (x) != MEM)
433 /* Strip off the MEM. */
436 for (old_x = NULL_RTX; GET_CODE (x) == REG && x != old_x;
437 old_x = x, x = find_last_value (x, &insn, NULL_RTX, 0))
440 /* If X isn't a PLUS than this isn't a tablejump we understand. */
441 if (GET_CODE (x) != PLUS)
444 /* At this point we should have an expression representing the jump table
445 plus an offset. Examine each operand in order to determine which one
446 represents the jump table. Knowing that tells us that the other operand
447 must represent the offset. */
448 for (i = 0; i < 2; i++)
453 for (old_y = NULL_RTX; GET_CODE (y) == REG && y != old_y;
454 old_y = y, y = find_last_value (y, &old_insn, NULL_RTX, 0))
457 if ((GET_CODE (y) == CONST || GET_CODE (y) == LABEL_REF)
458 && reg_mentioned_p (label, y))
467 /* Strip off the addition / subtraction of PIC_OFFSET_TABLE_REGNUM. */
468 if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS)
469 for (i = 0; i < 2; i++)
470 if (XEXP (x, i) == pic_offset_table_rtx)
479 /* Return the RTL expression representing the offset. */
483 /* Return the number of places FIND appears within X. If COUNT_DEST is
484 zero, we do not count occurrences inside the destination of a SET. */
487 count_occurrences (x, find, count_dest)
493 const char *format_ptr;
513 if (GET_CODE (find) == MEM && rtx_equal_p (x, find))
518 if (SET_DEST (x) == find && ! count_dest)
519 return count_occurrences (SET_SRC (x), find, count_dest);
526 format_ptr = GET_RTX_FORMAT (code);
529 for (i = 0; i < GET_RTX_LENGTH (code); i++)
531 switch (*format_ptr++)
534 count += count_occurrences (XEXP (x, i), find, count_dest);
538 for (j = 0; j < XVECLEN (x, i); j++)
539 count += count_occurrences (XVECEXP (x, i, j), find, count_dest);
546 /* Nonzero if register REG appears somewhere within IN.
547 Also works if REG is not a register; in this case it checks
548 for a subexpression of IN that is Lisp "equal" to REG. */
551 reg_mentioned_p (reg, in)
564 if (GET_CODE (in) == LABEL_REF)
565 return reg == XEXP (in, 0);
567 code = GET_CODE (in);
571 /* Compare registers by number. */
573 return GET_CODE (reg) == REG && REGNO (in) == REGNO (reg);
575 /* These codes have no constituent expressions
583 return GET_CODE (reg) == CONST_INT && INTVAL (in) == INTVAL (reg);
586 /* These are kept unique for a given value. */
593 if (GET_CODE (reg) == code && rtx_equal_p (reg, in))
596 fmt = GET_RTX_FORMAT (code);
598 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
603 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
604 if (reg_mentioned_p (reg, XVECEXP (in, i, j)))
607 else if (fmt[i] == 'e'
608 && reg_mentioned_p (reg, XEXP (in, i)))
614 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
615 no CODE_LABEL insn. */
618 no_labels_between_p (beg, end)
624 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
625 if (GET_CODE (p) == CODE_LABEL)
630 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
631 no JUMP_INSN insn. */
634 no_jumps_between_p (beg, end)
638 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
639 if (GET_CODE (p) == JUMP_INSN)
644 /* Nonzero if register REG is used in an insn between
645 FROM_INSN and TO_INSN (exclusive of those two). */
648 reg_used_between_p (reg, from_insn, to_insn)
649 rtx reg, from_insn, to_insn;
653 if (from_insn == to_insn)
656 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
658 && (reg_overlap_mentioned_p (reg, PATTERN (insn))
659 || (GET_CODE (insn) == CALL_INSN
660 && (find_reg_fusage (insn, USE, reg)
661 || find_reg_fusage (insn, CLOBBER, reg)))))
666 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
667 is entirely replaced by a new value and the only use is as a SET_DEST,
668 we do not consider it a reference. */
671 reg_referenced_p (x, body)
677 switch (GET_CODE (body))
680 if (reg_overlap_mentioned_p (x, SET_SRC (body)))
683 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
684 of a REG that occupies all of the REG, the insn references X if
685 it is mentioned in the destination. */
686 if (GET_CODE (SET_DEST (body)) != CC0
687 && GET_CODE (SET_DEST (body)) != PC
688 && GET_CODE (SET_DEST (body)) != REG
689 && ! (GET_CODE (SET_DEST (body)) == SUBREG
690 && GET_CODE (SUBREG_REG (SET_DEST (body))) == REG
691 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body))))
692 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
693 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body)))
694 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
695 && reg_overlap_mentioned_p (x, SET_DEST (body)))
700 for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
701 if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i)))
708 return reg_overlap_mentioned_p (x, body);
711 return reg_overlap_mentioned_p (x, TRAP_CONDITION (body));
714 return reg_overlap_mentioned_p (x, XEXP (body, 0));
717 case UNSPEC_VOLATILE:
718 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
719 if (reg_overlap_mentioned_p (x, XVECEXP (body, 0, i)))
724 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
725 if (reg_referenced_p (x, XVECEXP (body, 0, i)))
730 if (GET_CODE (XEXP (body, 0)) == MEM)
731 if (reg_overlap_mentioned_p (x, XEXP (XEXP (body, 0), 0)))
736 if (reg_overlap_mentioned_p (x, COND_EXEC_TEST (body)))
738 return reg_referenced_p (x, COND_EXEC_CODE (body));
745 /* Nonzero if register REG is referenced in an insn between
746 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
750 reg_referenced_between_p (reg, from_insn, to_insn)
751 rtx reg, from_insn, to_insn;
755 if (from_insn == to_insn)
758 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
760 && (reg_referenced_p (reg, PATTERN (insn))
761 || (GET_CODE (insn) == CALL_INSN
762 && find_reg_fusage (insn, USE, reg))))
767 /* Nonzero if register REG is set or clobbered in an insn between
768 FROM_INSN and TO_INSN (exclusive of those two). */
771 reg_set_between_p (reg, from_insn, to_insn)
772 rtx reg, from_insn, to_insn;
776 if (from_insn == to_insn)
779 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
780 if (INSN_P (insn) && reg_set_p (reg, insn))
785 /* Internals of reg_set_between_p. */
787 reg_set_p (reg, insn)
792 /* We can be passed an insn or part of one. If we are passed an insn,
793 check if a side-effect of the insn clobbers REG. */
796 if (FIND_REG_INC_NOTE (insn, reg)
797 || (GET_CODE (insn) == CALL_INSN
798 /* We'd like to test call_used_regs here, but rtlanal.c can't
799 reference that variable due to its use in genattrtab. So
800 we'll just be more conservative.
802 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
803 information holds all clobbered registers. */
804 && ((GET_CODE (reg) == REG
805 && REGNO (reg) < FIRST_PSEUDO_REGISTER)
806 || GET_CODE (reg) == MEM
807 || find_reg_fusage (insn, CLOBBER, reg))))
810 body = PATTERN (insn);
813 return set_of (reg, insn) != NULL_RTX;
816 /* Similar to reg_set_between_p, but check all registers in X. Return 0
817 only if none of them are modified between START and END. Do not
818 consider non-registers one way or the other. */
821 regs_set_between_p (x, start, end)
825 enum rtx_code code = GET_CODE (x);
841 return reg_set_between_p (x, start, end);
847 fmt = GET_RTX_FORMAT (code);
848 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
850 if (fmt[i] == 'e' && regs_set_between_p (XEXP (x, i), start, end))
853 else if (fmt[i] == 'E')
854 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
855 if (regs_set_between_p (XVECEXP (x, i, j), start, end))
862 /* Similar to reg_set_between_p, but check all registers in X. Return 0
863 only if none of them are modified between START and END. Return 1 if
864 X contains a MEM; this routine does not perform any memory aliasing. */
867 modified_between_p (x, start, end)
871 enum rtx_code code = GET_CODE (x);
889 /* If the memory is not constant, assume it is modified. If it is
890 constant, we still have to check the address. */
891 if (! RTX_UNCHANGING_P (x))
896 return reg_set_between_p (x, start, end);
902 fmt = GET_RTX_FORMAT (code);
903 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
905 if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end))
908 else if (fmt[i] == 'E')
909 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
910 if (modified_between_p (XVECEXP (x, i, j), start, end))
917 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
918 of them are modified in INSN. Return 1 if X contains a MEM; this routine
919 does not perform any memory aliasing. */
922 modified_in_p (x, insn)
926 enum rtx_code code = GET_CODE (x);
944 /* If the memory is not constant, assume it is modified. If it is
945 constant, we still have to check the address. */
946 if (! RTX_UNCHANGING_P (x))
951 return reg_set_p (x, insn);
957 fmt = GET_RTX_FORMAT (code);
958 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
960 if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn))
963 else if (fmt[i] == 'E')
964 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
965 if (modified_in_p (XVECEXP (x, i, j), insn))
972 /* Return true if anything in insn X is (anti,output,true) dependent on
973 anything in insn Y. */
976 insn_dependent_p (x, y)
981 if (! INSN_P (x) || ! INSN_P (y))
985 note_stores (PATTERN (x), insn_dependent_p_1, &tmp);
990 note_stores (PATTERN (y), insn_dependent_p_1, &tmp);
997 /* A helper routine for insn_dependent_p called through note_stores. */
1000 insn_dependent_p_1 (x, pat, data)
1002 rtx pat ATTRIBUTE_UNUSED;
1005 rtx * pinsn = (rtx *) data;
1007 if (*pinsn && reg_mentioned_p (x, *pinsn))
1011 /* Helper function for set_of. */
1019 set_of_1 (x, pat, data1)
1024 struct set_of_data *data = (struct set_of_data *) (data1);
1025 if (rtx_equal_p (x, data->pat)
1026 || (GET_CODE (x) != MEM && reg_overlap_mentioned_p (data->pat, x)))
1030 /* Give an INSN, return a SET or CLOBBER expression that does modify PAT
1031 (either directly or via STRICT_LOW_PART and similar modifiers). */
1036 struct set_of_data data;
1037 data.found = NULL_RTX;
1039 note_stores (INSN_P (insn) ? PATTERN (insn) : insn, set_of_1, &data);
1043 /* Given an INSN, return a SET expression if this insn has only a single SET.
1044 It may also have CLOBBERs, USEs, or SET whose output
1045 will not be used, which we ignore. */
1048 single_set_2 (insn, pat)
1052 int set_verified = 1;
1055 if (GET_CODE (pat) == PARALLEL)
1057 for (i = 0; i < XVECLEN (pat, 0); i++)
1059 rtx sub = XVECEXP (pat, 0, i);
1060 switch (GET_CODE (sub))
1067 /* We can consider insns having multiple sets, where all
1068 but one are dead as single set insns. In common case
1069 only single set is present in the pattern so we want
1070 to avoid checking for REG_UNUSED notes unless necessary.
1072 When we reach set first time, we just expect this is
1073 the single set we are looking for and only when more
1074 sets are found in the insn, we check them. */
1077 if (find_reg_note (insn, REG_UNUSED, SET_DEST (set))
1078 && !side_effects_p (set))
1084 set = sub, set_verified = 0;
1085 else if (!find_reg_note (insn, REG_UNUSED, SET_DEST (sub))
1086 || side_effects_p (sub))
1098 /* Given an INSN, return nonzero if it has more than one SET, else return
1102 multiple_sets (insn)
1108 /* INSN must be an insn. */
1109 if (! INSN_P (insn))
1112 /* Only a PARALLEL can have multiple SETs. */
1113 if (GET_CODE (PATTERN (insn)) == PARALLEL)
1115 for (i = 0, found = 0; i < XVECLEN (PATTERN (insn), 0); i++)
1116 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1118 /* If we have already found a SET, then return now. */
1126 /* Either zero or one SET. */
1130 /* Return nonzero if the destination of SET equals the source
1131 and there are no side effects. */
1137 rtx src = SET_SRC (set);
1138 rtx dst = SET_DEST (set);
1140 if (side_effects_p (src) || side_effects_p (dst))
1143 if (GET_CODE (dst) == MEM && GET_CODE (src) == MEM)
1144 return rtx_equal_p (dst, src);
1146 if (dst == pc_rtx && src == pc_rtx)
1149 if (GET_CODE (dst) == SIGN_EXTRACT
1150 || GET_CODE (dst) == ZERO_EXTRACT)
1151 return rtx_equal_p (XEXP (dst, 0), src)
1152 && ! BYTES_BIG_ENDIAN && XEXP (dst, 2) == const0_rtx;
1154 if (GET_CODE (dst) == STRICT_LOW_PART)
1155 dst = XEXP (dst, 0);
1157 if (GET_CODE (src) == SUBREG && GET_CODE (dst) == SUBREG)
1159 if (SUBREG_BYTE (src) != SUBREG_BYTE (dst))
1161 src = SUBREG_REG (src);
1162 dst = SUBREG_REG (dst);
1165 return (GET_CODE (src) == REG && GET_CODE (dst) == REG
1166 && REGNO (src) == REGNO (dst));
1169 /* Return nonzero if an insn consists only of SETs, each of which only sets a
1176 rtx pat = PATTERN (insn);
1178 if (INSN_CODE (insn) == NOOP_MOVE_INSN_CODE)
1181 /* Insns carrying these notes are useful later on. */
1182 if (find_reg_note (insn, REG_EQUAL, NULL_RTX))
1185 /* For now treat an insn with a REG_RETVAL note as a
1186 a special insn which should not be considered a no-op. */
1187 if (find_reg_note (insn, REG_RETVAL, NULL_RTX))
1190 if (GET_CODE (pat) == SET && set_noop_p (pat))
1193 if (GET_CODE (pat) == PARALLEL)
1196 /* If nothing but SETs of registers to themselves,
1197 this insn can also be deleted. */
1198 for (i = 0; i < XVECLEN (pat, 0); i++)
1200 rtx tem = XVECEXP (pat, 0, i);
1202 if (GET_CODE (tem) == USE
1203 || GET_CODE (tem) == CLOBBER)
1206 if (GET_CODE (tem) != SET || ! set_noop_p (tem))
1216 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
1217 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
1218 If the object was modified, if we hit a partial assignment to X, or hit a
1219 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
1220 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
1224 find_last_value (x, pinsn, valid_to, allow_hwreg)
1232 for (p = PREV_INSN (*pinsn); p && GET_CODE (p) != CODE_LABEL;
1236 rtx set = single_set (p);
1237 rtx note = find_reg_note (p, REG_EQUAL, NULL_RTX);
1239 if (set && rtx_equal_p (x, SET_DEST (set)))
1241 rtx src = SET_SRC (set);
1243 if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
1244 src = XEXP (note, 0);
1246 if ((valid_to == NULL_RTX
1247 || ! modified_between_p (src, PREV_INSN (p), valid_to))
1248 /* Reject hard registers because we don't usually want
1249 to use them; we'd rather use a pseudo. */
1250 && (! (GET_CODE (src) == REG
1251 && REGNO (src) < FIRST_PSEUDO_REGISTER) || allow_hwreg))
1258 /* If set in non-simple way, we don't have a value. */
1259 if (reg_set_p (x, p))
1266 /* Return nonzero if register in range [REGNO, ENDREGNO)
1267 appears either explicitly or implicitly in X
1268 other than being stored into.
1270 References contained within the substructure at LOC do not count.
1271 LOC may be zero, meaning don't ignore anything. */
1274 refers_to_regno_p (regno, endregno, x, loc)
1275 unsigned int regno, endregno;
1280 unsigned int x_regno;
1285 /* The contents of a REG_NONNEG note is always zero, so we must come here
1286 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
1290 code = GET_CODE (x);
1295 x_regno = REGNO (x);
1297 /* If we modifying the stack, frame, or argument pointer, it will
1298 clobber a virtual register. In fact, we could be more precise,
1299 but it isn't worth it. */
1300 if ((x_regno == STACK_POINTER_REGNUM
1301 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1302 || x_regno == ARG_POINTER_REGNUM
1304 || x_regno == FRAME_POINTER_REGNUM)
1305 && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER)
1308 return (endregno > x_regno
1309 && regno < x_regno + (x_regno < FIRST_PSEUDO_REGISTER
1310 ? HARD_REGNO_NREGS (x_regno, GET_MODE (x))
1314 /* If this is a SUBREG of a hard reg, we can see exactly which
1315 registers are being modified. Otherwise, handle normally. */
1316 if (GET_CODE (SUBREG_REG (x)) == REG
1317 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
1319 unsigned int inner_regno = subreg_regno (x);
1320 unsigned int inner_endregno
1321 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
1322 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
1324 return endregno > inner_regno && regno < inner_endregno;
1330 if (&SET_DEST (x) != loc
1331 /* Note setting a SUBREG counts as referring to the REG it is in for
1332 a pseudo but not for hard registers since we can
1333 treat each word individually. */
1334 && ((GET_CODE (SET_DEST (x)) == SUBREG
1335 && loc != &SUBREG_REG (SET_DEST (x))
1336 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
1337 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
1338 && refers_to_regno_p (regno, endregno,
1339 SUBREG_REG (SET_DEST (x)), loc))
1340 || (GET_CODE (SET_DEST (x)) != REG
1341 && refers_to_regno_p (regno, endregno, SET_DEST (x), loc))))
1344 if (code == CLOBBER || loc == &SET_SRC (x))
1353 /* X does not match, so try its subexpressions. */
1355 fmt = GET_RTX_FORMAT (code);
1356 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1358 if (fmt[i] == 'e' && loc != &XEXP (x, i))
1366 if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc))
1369 else if (fmt[i] == 'E')
1372 for (j = XVECLEN (x, i) - 1; j >=0; j--)
1373 if (loc != &XVECEXP (x, i, j)
1374 && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc))
1381 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
1382 we check if any register number in X conflicts with the relevant register
1383 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
1384 contains a MEM (we don't bother checking for memory addresses that can't
1385 conflict because we expect this to be a rare case. */
1388 reg_overlap_mentioned_p (x, in)
1391 unsigned int regno, endregno;
1393 /* Overly conservative. */
1394 if (GET_CODE (x) == STRICT_LOW_PART)
1397 /* If either argument is a constant, then modifying X can not affect IN. */
1398 if (CONSTANT_P (x) || CONSTANT_P (in))
1401 switch (GET_CODE (x))
1404 regno = REGNO (SUBREG_REG (x));
1405 if (regno < FIRST_PSEUDO_REGISTER)
1406 regno = subreg_regno (x);
1412 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
1413 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
1414 return refers_to_regno_p (regno, endregno, in, (rtx*)0);
1421 if (GET_CODE (in) == MEM)
1424 fmt = GET_RTX_FORMAT (GET_CODE (in));
1425 for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--)
1426 if (fmt[i] == 'e' && reg_overlap_mentioned_p (x, XEXP (in, i)))
1435 return reg_mentioned_p (x, in);
1441 /* If any register in here refers to it we return true. */
1442 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1443 if (XEXP (XVECEXP (x, 0, i), 0) != 0
1444 && reg_overlap_mentioned_p (XEXP (XVECEXP (x, 0, i), 0), in))
1456 /* Return the last value to which REG was set prior to INSN. If we can't
1457 find it easily, return 0.
1459 We only return a REG, SUBREG, or constant because it is too hard to
1460 check if a MEM remains unchanged. */
1463 reg_set_last (x, insn)
1467 rtx orig_insn = insn;
1469 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1470 Stop when we reach a label or X is a hard reg and we reach a
1471 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1473 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1475 /* We compare with <= here, because reg_set_last_last_regno
1476 is actually the number of the first reg *not* in X. */
1478 insn && GET_CODE (insn) != CODE_LABEL
1479 && ! (GET_CODE (insn) == CALL_INSN
1480 && REGNO (x) <= FIRST_PSEUDO_REGISTER);
1481 insn = PREV_INSN (insn))
1484 rtx set = set_of (x, insn);
1485 /* OK, this function modify our register. See if we understand it. */
1489 if (GET_CODE (set) != SET || SET_DEST (set) != x)
1491 last_value = SET_SRC (x);
1492 if (CONSTANT_P (last_value)
1493 || ((GET_CODE (last_value) == REG
1494 || GET_CODE (last_value) == SUBREG)
1495 && ! reg_set_between_p (last_value,
1506 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1507 (X would be the pattern of an insn).
1508 FUN receives two arguments:
1509 the REG, MEM, CC0 or PC being stored in or clobbered,
1510 the SET or CLOBBER rtx that does the store.
1512 If the item being stored in or clobbered is a SUBREG of a hard register,
1513 the SUBREG will be passed. */
1516 note_stores (x, fun, data)
1518 void (*fun) PARAMS ((rtx, rtx, void *));
1523 if (GET_CODE (x) == COND_EXEC)
1524 x = COND_EXEC_CODE (x);
1526 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
1528 rtx dest = SET_DEST (x);
1530 while ((GET_CODE (dest) == SUBREG
1531 && (GET_CODE (SUBREG_REG (dest)) != REG
1532 || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER))
1533 || GET_CODE (dest) == ZERO_EXTRACT
1534 || GET_CODE (dest) == SIGN_EXTRACT
1535 || GET_CODE (dest) == STRICT_LOW_PART)
1536 dest = XEXP (dest, 0);
1538 /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions,
1539 each of whose first operand is a register. We can't know what
1540 precisely is being set in these cases, so make up a CLOBBER to pass
1542 if (GET_CODE (dest) == PARALLEL)
1544 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
1545 if (XEXP (XVECEXP (dest, 0, i), 0) != 0)
1546 (*fun) (XEXP (XVECEXP (dest, 0, i), 0),
1547 gen_rtx_CLOBBER (VOIDmode,
1548 XEXP (XVECEXP (dest, 0, i), 0)),
1552 (*fun) (dest, x, data);
1555 else if (GET_CODE (x) == PARALLEL)
1556 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1557 note_stores (XVECEXP (x, 0, i), fun, data);
1560 /* Like notes_stores, but call FUN for each expression that is being
1561 referenced in PBODY, a pointer to the PATTERN of an insn. We only call
1562 FUN for each expression, not any interior subexpressions. FUN receives a
1563 pointer to the expression and the DATA passed to this function.
1565 Note that this is not quite the same test as that done in reg_referenced_p
1566 since that considers something as being referenced if it is being
1567 partially set, while we do not. */
1570 note_uses (pbody, fun, data)
1572 void (*fun) PARAMS ((rtx *, void *));
1578 switch (GET_CODE (body))
1581 (*fun) (&COND_EXEC_TEST (body), data);
1582 note_uses (&COND_EXEC_CODE (body), fun, data);
1586 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
1587 note_uses (&XVECEXP (body, 0, i), fun, data);
1591 (*fun) (&XEXP (body, 0), data);
1595 for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
1596 (*fun) (&ASM_OPERANDS_INPUT (body, i), data);
1600 (*fun) (&TRAP_CONDITION (body), data);
1604 (*fun) (&XEXP (body, 0), data);
1608 case UNSPEC_VOLATILE:
1609 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
1610 (*fun) (&XVECEXP (body, 0, i), data);
1614 if (GET_CODE (XEXP (body, 0)) == MEM)
1615 (*fun) (&XEXP (XEXP (body, 0), 0), data);
1620 rtx dest = SET_DEST (body);
1622 /* For sets we replace everything in source plus registers in memory
1623 expression in store and operands of a ZERO_EXTRACT. */
1624 (*fun) (&SET_SRC (body), data);
1626 if (GET_CODE (dest) == ZERO_EXTRACT)
1628 (*fun) (&XEXP (dest, 1), data);
1629 (*fun) (&XEXP (dest, 2), data);
1632 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART)
1633 dest = XEXP (dest, 0);
1635 if (GET_CODE (dest) == MEM)
1636 (*fun) (&XEXP (dest, 0), data);
1641 /* All the other possibilities never store. */
1642 (*fun) (pbody, data);
1647 /* Return nonzero if X's old contents don't survive after INSN.
1648 This will be true if X is (cc0) or if X is a register and
1649 X dies in INSN or because INSN entirely sets X.
1651 "Entirely set" means set directly and not through a SUBREG,
1652 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1653 Likewise, REG_INC does not count.
1655 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1656 but for this use that makes no difference, since regs don't overlap
1657 during their lifetimes. Therefore, this function may be used
1658 at any time after deaths have been computed (in flow.c).
1660 If REG is a hard reg that occupies multiple machine registers, this
1661 function will only return 1 if each of those registers will be replaced
1665 dead_or_set_p (insn, x)
1669 unsigned int regno, last_regno;
1672 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1673 if (GET_CODE (x) == CC0)
1676 if (GET_CODE (x) != REG)
1680 last_regno = (regno >= FIRST_PSEUDO_REGISTER ? regno
1681 : regno + HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1);
1683 for (i = regno; i <= last_regno; i++)
1684 if (! dead_or_set_regno_p (insn, i))
1690 /* Utility function for dead_or_set_p to check an individual register. Also
1691 called from flow.c. */
1694 dead_or_set_regno_p (insn, test_regno)
1696 unsigned int test_regno;
1698 unsigned int regno, endregno;
1701 /* See if there is a death note for something that includes TEST_REGNO. */
1702 if (find_regno_note (insn, REG_DEAD, test_regno))
1705 if (GET_CODE (insn) == CALL_INSN
1706 && find_regno_fusage (insn, CLOBBER, test_regno))
1709 pattern = PATTERN (insn);
1711 if (GET_CODE (pattern) == COND_EXEC)
1712 pattern = COND_EXEC_CODE (pattern);
1714 if (GET_CODE (pattern) == SET)
1716 rtx dest = SET_DEST (PATTERN (insn));
1718 /* A value is totally replaced if it is the destination or the
1719 destination is a SUBREG of REGNO that does not change the number of
1721 if (GET_CODE (dest) == SUBREG
1722 && (((GET_MODE_SIZE (GET_MODE (dest))
1723 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1724 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1725 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1726 dest = SUBREG_REG (dest);
1728 if (GET_CODE (dest) != REG)
1731 regno = REGNO (dest);
1732 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1733 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1735 return (test_regno >= regno && test_regno < endregno);
1737 else if (GET_CODE (pattern) == PARALLEL)
1741 for (i = XVECLEN (pattern, 0) - 1; i >= 0; i--)
1743 rtx body = XVECEXP (pattern, 0, i);
1745 if (GET_CODE (body) == COND_EXEC)
1746 body = COND_EXEC_CODE (body);
1748 if (GET_CODE (body) == SET || GET_CODE (body) == CLOBBER)
1750 rtx dest = SET_DEST (body);
1752 if (GET_CODE (dest) == SUBREG
1753 && (((GET_MODE_SIZE (GET_MODE (dest))
1754 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1755 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1756 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1757 dest = SUBREG_REG (dest);
1759 if (GET_CODE (dest) != REG)
1762 regno = REGNO (dest);
1763 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1764 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1766 if (test_regno >= regno && test_regno < endregno)
1775 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1776 If DATUM is nonzero, look for one whose datum is DATUM. */
1779 find_reg_note (insn, kind, datum)
1786 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1787 if (! INSN_P (insn))
1790 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1791 if (REG_NOTE_KIND (link) == kind
1792 && (datum == 0 || datum == XEXP (link, 0)))
1797 /* Return the reg-note of kind KIND in insn INSN which applies to register
1798 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1799 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1800 it might be the case that the note overlaps REGNO. */
1803 find_regno_note (insn, kind, regno)
1810 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1811 if (! INSN_P (insn))
1814 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1815 if (REG_NOTE_KIND (link) == kind
1816 /* Verify that it is a register, so that scratch and MEM won't cause a
1818 && GET_CODE (XEXP (link, 0)) == REG
1819 && REGNO (XEXP (link, 0)) <= regno
1820 && ((REGNO (XEXP (link, 0))
1821 + (REGNO (XEXP (link, 0)) >= FIRST_PSEUDO_REGISTER ? 1
1822 : HARD_REGNO_NREGS (REGNO (XEXP (link, 0)),
1823 GET_MODE (XEXP (link, 0)))))
1829 /* Return a REG_EQUIV or REG_EQUAL note if insn has only a single set and
1833 find_reg_equal_equiv_note (insn)
1838 if (single_set (insn) == 0)
1840 else if ((note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != 0)
1843 return find_reg_note (insn, REG_EQUAL, NULL_RTX);
1846 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1847 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1850 find_reg_fusage (insn, code, datum)
1855 /* If it's not a CALL_INSN, it can't possibly have a
1856 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1857 if (GET_CODE (insn) != CALL_INSN)
1863 if (GET_CODE (datum) != REG)
1867 for (link = CALL_INSN_FUNCTION_USAGE (insn);
1869 link = XEXP (link, 1))
1870 if (GET_CODE (XEXP (link, 0)) == code
1871 && rtx_equal_p (datum, SET_DEST (XEXP (link, 0))))
1876 unsigned int regno = REGNO (datum);
1878 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1879 to pseudo registers, so don't bother checking. */
1881 if (regno < FIRST_PSEUDO_REGISTER)
1883 unsigned int end_regno
1884 = regno + HARD_REGNO_NREGS (regno, GET_MODE (datum));
1887 for (i = regno; i < end_regno; i++)
1888 if (find_regno_fusage (insn, code, i))
1896 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1897 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1900 find_regno_fusage (insn, code, regno)
1907 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1908 to pseudo registers, so don't bother checking. */
1910 if (regno >= FIRST_PSEUDO_REGISTER
1911 || GET_CODE (insn) != CALL_INSN )
1914 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
1916 unsigned int regnote;
1919 if (GET_CODE (op = XEXP (link, 0)) == code
1920 && GET_CODE (reg = XEXP (op, 0)) == REG
1921 && (regnote = REGNO (reg)) <= regno
1922 && regnote + HARD_REGNO_NREGS (regnote, GET_MODE (reg)) > regno)
1929 /* Remove register note NOTE from the REG_NOTES of INSN. */
1932 remove_note (insn, note)
1938 if (note == NULL_RTX)
1941 if (REG_NOTES (insn) == note)
1943 REG_NOTES (insn) = XEXP (note, 1);
1947 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1948 if (XEXP (link, 1) == note)
1950 XEXP (link, 1) = XEXP (note, 1);
1957 /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
1958 remove that entry from the list if it is found.
1960 A simple equality test is used to determine if NODE matches. */
1963 remove_node_from_expr_list (node, listp)
1968 rtx prev = NULL_RTX;
1972 if (node == XEXP (temp, 0))
1974 /* Splice the node out of the list. */
1976 XEXP (prev, 1) = XEXP (temp, 1);
1978 *listp = XEXP (temp, 1);
1984 temp = XEXP (temp, 1);
1988 /* Nonzero if X contains any volatile instructions. These are instructions
1989 which may cause unpredictable machine state instructions, and thus no
1990 instructions should be moved or combined across them. This includes
1991 only volatile asms and UNSPEC_VOLATILE instructions. */
1999 code = GET_CODE (x);
2019 case UNSPEC_VOLATILE:
2020 /* case TRAP_IF: This isn't clear yet. */
2024 if (MEM_VOLATILE_P (x))
2031 /* Recursively scan the operands of this expression. */
2034 const char *fmt = GET_RTX_FORMAT (code);
2037 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2041 if (volatile_insn_p (XEXP (x, i)))
2044 else if (fmt[i] == 'E')
2047 for (j = 0; j < XVECLEN (x, i); j++)
2048 if (volatile_insn_p (XVECEXP (x, i, j)))
2056 /* Nonzero if X contains any volatile memory references
2057 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
2065 code = GET_CODE (x);
2084 case UNSPEC_VOLATILE:
2085 /* case TRAP_IF: This isn't clear yet. */
2090 if (MEM_VOLATILE_P (x))
2097 /* Recursively scan the operands of this expression. */
2100 const char *fmt = GET_RTX_FORMAT (code);
2103 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2107 if (volatile_refs_p (XEXP (x, i)))
2110 else if (fmt[i] == 'E')
2113 for (j = 0; j < XVECLEN (x, i); j++)
2114 if (volatile_refs_p (XVECEXP (x, i, j)))
2122 /* Similar to above, except that it also rejects register pre- and post-
2131 code = GET_CODE (x);
2149 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
2150 when some combination can't be done. If we see one, don't think
2151 that we can simplify the expression. */
2152 return (GET_MODE (x) != VOIDmode);
2161 case UNSPEC_VOLATILE:
2162 /* case TRAP_IF: This isn't clear yet. */
2167 if (MEM_VOLATILE_P (x))
2174 /* Recursively scan the operands of this expression. */
2177 const char *fmt = GET_RTX_FORMAT (code);
2180 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2184 if (side_effects_p (XEXP (x, i)))
2187 else if (fmt[i] == 'E')
2190 for (j = 0; j < XVECLEN (x, i); j++)
2191 if (side_effects_p (XVECEXP (x, i, j)))
2199 /* Return nonzero if evaluating rtx X might cause a trap. */
2211 code = GET_CODE (x);
2214 /* Handle these cases quickly. */
2227 case UNSPEC_VOLATILE:
2232 return MEM_VOLATILE_P (x);
2234 /* Memory ref can trap unless it's a static var or a stack slot. */
2236 return rtx_addr_can_trap_p (XEXP (x, 0));
2238 /* Division by a non-constant might trap. */
2243 if (! CONSTANT_P (XEXP (x, 1))
2244 || GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2246 /* This was const0_rtx, but by not using that,
2247 we can link this file into other programs. */
2248 if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
2253 /* An EXPR_LIST is used to represent a function call. This
2254 certainly may trap. */
2262 /* Some floating point comparisons may trap. */
2263 /* ??? There is no machine independent way to check for tests that trap
2264 when COMPARE is used, though many targets do make this distinction.
2265 For instance, sparc uses CCFPE for compares which generate exceptions
2266 and CCFP for compares which do not generate exceptions. */
2267 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2269 /* But often the compare has some CC mode, so check operand
2271 if (GET_MODE_CLASS (GET_MODE (XEXP (x, 0))) == MODE_FLOAT
2272 || GET_MODE_CLASS (GET_MODE (XEXP (x, 1))) == MODE_FLOAT)
2278 /* These operations don't trap even with floating point. */
2282 /* Any floating arithmetic may trap. */
2283 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2287 fmt = GET_RTX_FORMAT (code);
2288 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2292 if (may_trap_p (XEXP (x, i)))
2295 else if (fmt[i] == 'E')
2298 for (j = 0; j < XVECLEN (x, i); j++)
2299 if (may_trap_p (XVECEXP (x, i, j)))
2306 /* Return nonzero if X contains a comparison that is not either EQ or NE,
2307 i.e., an inequality. */
2310 inequality_comparisons_p (x)
2315 enum rtx_code code = GET_CODE (x);
2344 len = GET_RTX_LENGTH (code);
2345 fmt = GET_RTX_FORMAT (code);
2347 for (i = 0; i < len; i++)
2351 if (inequality_comparisons_p (XEXP (x, i)))
2354 else if (fmt[i] == 'E')
2357 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2358 if (inequality_comparisons_p (XVECEXP (x, i, j)))
2366 /* Replace any occurrence of FROM in X with TO. The function does
2367 not enter into CONST_DOUBLE for the replace.
2369 Note that copying is not done so X must not be shared unless all copies
2370 are to be modified. */
2373 replace_rtx (x, from, to)
2379 /* The following prevents loops occurrence when we change MEM in
2380 CONST_DOUBLE onto the same CONST_DOUBLE. */
2381 if (x != 0 && GET_CODE (x) == CONST_DOUBLE)
2387 /* Allow this function to make replacements in EXPR_LISTs. */
2391 fmt = GET_RTX_FORMAT (GET_CODE (x));
2392 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2395 XEXP (x, i) = replace_rtx (XEXP (x, i), from, to);
2396 else if (fmt[i] == 'E')
2397 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2398 XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to);
2404 /* Throughout the rtx X, replace many registers according to REG_MAP.
2405 Return the replacement for X (which may be X with altered contents).
2406 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
2407 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
2409 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
2410 should not be mapped to pseudos or vice versa since validate_change
2413 If REPLACE_DEST is 1, replacements are also done in destinations;
2414 otherwise, only sources are replaced. */
2417 replace_regs (x, reg_map, nregs, replace_dest)
2430 code = GET_CODE (x);
2444 /* Verify that the register has an entry before trying to access it. */
2445 if (REGNO (x) < nregs && reg_map[REGNO (x)] != 0)
2447 /* SUBREGs can't be shared. Always return a copy to ensure that if
2448 this replacement occurs more than once then each instance will
2449 get distinct rtx. */
2450 if (GET_CODE (reg_map[REGNO (x)]) == SUBREG)
2451 return copy_rtx (reg_map[REGNO (x)]);
2452 return reg_map[REGNO (x)];
2457 /* Prevent making nested SUBREGs. */
2458 if (GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) < nregs
2459 && reg_map[REGNO (SUBREG_REG (x))] != 0
2460 && GET_CODE (reg_map[REGNO (SUBREG_REG (x))]) == SUBREG)
2462 rtx map_val = reg_map[REGNO (SUBREG_REG (x))];
2463 return simplify_gen_subreg (GET_MODE (x), map_val,
2464 GET_MODE (SUBREG_REG (x)),
2471 SET_DEST (x) = replace_regs (SET_DEST (x), reg_map, nregs, 0);
2473 else if (GET_CODE (SET_DEST (x)) == MEM
2474 || GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2475 /* Even if we are not to replace destinations, replace register if it
2476 is CONTAINED in destination (destination is memory or
2477 STRICT_LOW_PART). */
2478 XEXP (SET_DEST (x), 0) = replace_regs (XEXP (SET_DEST (x), 0),
2480 else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2481 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2484 SET_SRC (x) = replace_regs (SET_SRC (x), reg_map, nregs, 0);
2491 fmt = GET_RTX_FORMAT (code);
2492 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2495 XEXP (x, i) = replace_regs (XEXP (x, i), reg_map, nregs, replace_dest);
2496 else if (fmt[i] == 'E')
2499 for (j = 0; j < XVECLEN (x, i); j++)
2500 XVECEXP (x, i, j) = replace_regs (XVECEXP (x, i, j), reg_map,
2501 nregs, replace_dest);
2507 /* A subroutine of computed_jump_p, return 1 if X contains a REG or MEM or
2508 constant that is not in the constant pool and not in the condition
2509 of an IF_THEN_ELSE. */
2512 computed_jump_p_1 (x)
2515 enum rtx_code code = GET_CODE (x);
2533 return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
2534 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
2537 return (computed_jump_p_1 (XEXP (x, 1))
2538 || computed_jump_p_1 (XEXP (x, 2)));
2544 fmt = GET_RTX_FORMAT (code);
2545 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2548 && computed_jump_p_1 (XEXP (x, i)))
2551 else if (fmt[i] == 'E')
2552 for (j = 0; j < XVECLEN (x, i); j++)
2553 if (computed_jump_p_1 (XVECEXP (x, i, j)))
2560 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2562 Tablejumps and casesi insns are not considered indirect jumps;
2563 we can recognize them by a (use (label_ref)). */
2566 computed_jump_p (insn)
2570 if (GET_CODE (insn) == JUMP_INSN)
2572 rtx pat = PATTERN (insn);
2574 if (find_reg_note (insn, REG_LABEL, NULL_RTX))
2576 else if (GET_CODE (pat) == PARALLEL)
2578 int len = XVECLEN (pat, 0);
2579 int has_use_labelref = 0;
2581 for (i = len - 1; i >= 0; i--)
2582 if (GET_CODE (XVECEXP (pat, 0, i)) == USE
2583 && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0))
2585 has_use_labelref = 1;
2587 if (! has_use_labelref)
2588 for (i = len - 1; i >= 0; i--)
2589 if (GET_CODE (XVECEXP (pat, 0, i)) == SET
2590 && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx
2591 && computed_jump_p_1 (SET_SRC (XVECEXP (pat, 0, i))))
2594 else if (GET_CODE (pat) == SET
2595 && SET_DEST (pat) == pc_rtx
2596 && computed_jump_p_1 (SET_SRC (pat)))
2602 /* Traverse X via depth-first search, calling F for each
2603 sub-expression (including X itself). F is also passed the DATA.
2604 If F returns -1, do not traverse sub-expressions, but continue
2605 traversing the rest of the tree. If F ever returns any other
2606 non-zero value, stop the traversal, and return the value returned
2607 by F. Otherwise, return 0. This function does not traverse inside
2608 tree structure that contains RTX_EXPRs, or into sub-expressions
2609 whose format code is `0' since it is not known whether or not those
2610 codes are actually RTL.
2612 This routine is very general, and could (should?) be used to
2613 implement many of the other routines in this file. */
2616 for_each_rtx (x, f, data)
2627 result = (*f) (x, data);
2629 /* Do not traverse sub-expressions. */
2631 else if (result != 0)
2632 /* Stop the traversal. */
2636 /* There are no sub-expressions. */
2639 length = GET_RTX_LENGTH (GET_CODE (*x));
2640 format = GET_RTX_FORMAT (GET_CODE (*x));
2642 for (i = 0; i < length; ++i)
2647 result = for_each_rtx (&XEXP (*x, i), f, data);
2654 if (XVEC (*x, i) != 0)
2657 for (j = 0; j < XVECLEN (*x, i); ++j)
2659 result = for_each_rtx (&XVECEXP (*x, i, j), f, data);
2667 /* Nothing to do. */
2676 /* Searches X for any reference to REGNO, returning the rtx of the
2677 reference found if any. Otherwise, returns NULL_RTX. */
2680 regno_use_in (regno, x)
2688 if (GET_CODE (x) == REG && REGNO (x) == regno)
2691 fmt = GET_RTX_FORMAT (GET_CODE (x));
2692 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2696 if ((tem = regno_use_in (regno, XEXP (x, i))))
2699 else if (fmt[i] == 'E')
2700 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2701 if ((tem = regno_use_in (regno , XVECEXP (x, i, j))))
2708 /* Return a value indicating whether OP, an operand of a commutative
2709 operation, is preferred as the first or second operand. The higher
2710 the value, the stronger the preference for being the first operand.
2711 We use negative values to indicate a preference for the first operand
2712 and positive values for the second operand. */
2715 commutative_operand_precedence (op)
2718 /* Constants always come the second operand. Prefer "nice" constants. */
2719 if (GET_CODE (op) == CONST_INT)
2721 if (GET_CODE (op) == CONST_DOUBLE)
2723 if (CONSTANT_P (op))
2726 /* SUBREGs of objects should come second. */
2727 if (GET_CODE (op) == SUBREG
2728 && GET_RTX_CLASS (GET_CODE (SUBREG_REG (op))) == 'o')
2731 /* If only one operand is a `neg', `not',
2732 `mult', `plus', or `minus' expression, it will be the first
2734 if (GET_CODE (op) == NEG || GET_CODE (op) == NOT
2735 || GET_CODE (op) == MULT || GET_CODE (op) == PLUS
2736 || GET_CODE (op) == MINUS)
2739 /* Complex expressions should be the first, so decrease priority
2741 if (GET_RTX_CLASS (GET_CODE (op)) == 'o')
2746 /* Return 1 iff it is necessary to swap operands of commutative operation
2747 in order to canonicalize expression. */
2750 swap_commutative_operands_p (x, y)
2753 return (commutative_operand_precedence (x)
2754 < commutative_operand_precedence (y));
2757 /* Return 1 if X is an autoincrement side effect and the register is
2758 not the stack pointer. */
2763 switch (GET_CODE (x))
2771 /* There are no REG_INC notes for SP. */
2772 if (XEXP (x, 0) != stack_pointer_rtx)
2780 /* Return 1 if the sequence of instructions beginning with FROM and up
2781 to and including TO is safe to move. If NEW_TO is non-NULL, and
2782 the sequence is not already safe to move, but can be easily
2783 extended to a sequence which is safe, then NEW_TO will point to the
2784 end of the extended sequence.
2786 For now, this function only checks that the region contains whole
2787 exception regions, but it could be extended to check additional
2788 conditions as well. */
2791 insns_safe_to_move_p (from, to, new_to)
2796 int eh_region_count = 0;
2800 /* By default, assume the end of the region will be what was
2807 if (GET_CODE (r) == NOTE)
2809 switch (NOTE_LINE_NUMBER (r))
2811 case NOTE_INSN_EH_REGION_BEG:
2815 case NOTE_INSN_EH_REGION_END:
2816 if (eh_region_count == 0)
2817 /* This sequence of instructions contains the end of
2818 an exception region, but not he beginning. Moving
2819 it will cause chaos. */
2830 /* If we've passed TO, and we see a non-note instruction, we
2831 can't extend the sequence to a movable sequence. */
2837 /* It's OK to move the sequence if there were matched sets of
2838 exception region notes. */
2839 return eh_region_count == 0;
2844 /* It's OK to move the sequence if there were matched sets of
2845 exception region notes. */
2846 if (past_to_p && eh_region_count == 0)
2852 /* Go to the next instruction. */
2859 /* Return non-zero if IN contains a piece of rtl that has the address LOC */
2861 loc_mentioned_in_p (loc, in)
2864 enum rtx_code code = GET_CODE (in);
2865 const char *fmt = GET_RTX_FORMAT (code);
2868 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2870 if (loc == &in->fld[i].rtx)
2874 if (loc_mentioned_in_p (loc, XEXP (in, i)))
2877 else if (fmt[i] == 'E')
2878 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
2879 if (loc_mentioned_in_p (loc, XVECEXP (in, i, j)))
2885 /* This function returns the regno offset of a subreg expression.
2886 xregno - A regno of an inner hard subreg_reg (or what will become one).
2887 xmode - The mode of xregno.
2888 offset - The byte offset.
2889 ymode - The mode of a top level SUBREG (or what may become one).
2890 RETURN - The regno offset which would be used.
2891 This function can be overridden by defining SUBREG_REGNO_OFFSET,
2892 taking the same parameters. */
2894 subreg_regno_offset (xregno, xmode, offset, ymode)
2895 unsigned int xregno;
2896 enum machine_mode xmode;
2897 unsigned int offset;
2898 enum machine_mode ymode;
2901 int nregs_xmode, nregs_ymode;
2902 int mode_multiple, nregs_multiple;
2905 /* Check for an override, and use it instead. */
2906 #ifdef SUBREG_REGNO_OFFSET
2907 ret = SUBREG_REGNO_OFFSET (xregno, xmode, offset, ymode);
2909 if (xregno >= FIRST_PSEUDO_REGISTER)
2912 nregs_xmode = HARD_REGNO_NREGS (xregno, xmode);
2913 nregs_ymode = HARD_REGNO_NREGS (xregno, ymode);
2914 if (offset == 0 || nregs_xmode == nregs_ymode)
2917 /* size of ymode must not be greater than the size of xmode. */
2918 mode_multiple = GET_MODE_SIZE (xmode) / GET_MODE_SIZE (ymode);
2919 if (mode_multiple == 0)
2922 y_offset = offset / GET_MODE_SIZE (ymode);
2923 nregs_multiple = nregs_xmode / nregs_ymode;
2924 ret = (y_offset / (mode_multiple / nregs_multiple)) * nregs_ymode;
2930 /* Return the final regno that a subreg expression refers to. */
2936 rtx subreg = SUBREG_REG (x);
2937 int regno = REGNO (subreg);
2939 ret = regno + subreg_regno_offset (regno,
2946 struct parms_set_data
2952 /* Helper function for noticing stores to parameter registers. */
2954 parms_set (x, pat, data)
2955 rtx x, pat ATTRIBUTE_UNUSED;
2958 struct parms_set_data *d = data;
2959 if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
2960 && TEST_HARD_REG_BIT (d->regs, REGNO (x)))
2962 CLEAR_HARD_REG_BIT (d->regs, REGNO (x));
2967 /* Look backward for first parameter to be loaded.
2968 Do not skip BOUNDARY. */
2970 find_first_parameter_load (call_insn, boundary)
2971 rtx call_insn, boundary;
2973 struct parms_set_data parm;
2976 /* Since different machines initialize their parameter registers
2977 in different orders, assume nothing. Collect the set of all
2978 parameter registers. */
2979 CLEAR_HARD_REG_SET (parm.regs);
2981 for (p = CALL_INSN_FUNCTION_USAGE (call_insn); p; p = XEXP (p, 1))
2982 if (GET_CODE (XEXP (p, 0)) == USE
2983 && GET_CODE (XEXP (XEXP (p, 0), 0)) == REG)
2985 if (REGNO (XEXP (XEXP (p, 0), 0)) >= FIRST_PSEUDO_REGISTER)
2988 /* We only care about registers which can hold function
2990 if (!FUNCTION_ARG_REGNO_P (REGNO (XEXP (XEXP (p, 0), 0))))
2993 SET_HARD_REG_BIT (parm.regs, REGNO (XEXP (XEXP (p, 0), 0)));
2998 /* Search backward for the first set of a register in this set. */
2999 while (parm.nregs && before != boundary)
3001 before = PREV_INSN (before);
3003 /* It is possible that some loads got CSEed from one call to
3004 another. Stop in that case. */
3005 if (GET_CODE (before) == CALL_INSN)
3008 /* Our caller needs either ensure that we will find all sets
3009 (in case code has not been optimized yet), or take care
3010 for possible labels in a way by setting boundary to preceding
3012 if (GET_CODE (before) == CODE_LABEL)
3014 if (before != boundary)
3019 if (INSN_P (before))
3020 note_stores (PATTERN (before), parms_set, &parm);