1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 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
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "insn-config.h"
34 #include "basic-block.h"
37 /* Forward declarations */
38 static int global_reg_mentioned_p_1
PARAMS ((rtx
*, void *));
39 static void set_of_1
PARAMS ((rtx
, rtx
, void *));
40 static void insn_dependent_p_1
PARAMS ((rtx
, rtx
, void *));
41 static int rtx_referenced_p_1
PARAMS ((rtx
*, void *));
42 static int computed_jump_p_1
PARAMS ((rtx
));
43 static void parms_set
PARAMS ((rtx
, rtx
, void *));
44 static bool hoist_test_store
PARAMS ((rtx
, rtx
, regset
));
45 static void hoist_update_store
PARAMS ((rtx
, rtx
*, rtx
, rtx
));
47 /* Bit flags that specify the machine subtype we are compiling for.
48 Bits are tested using macros TARGET_... defined in the tm.h file
49 and set by `-m...' switches. Must be defined in rtlanal.c. */
53 /* Return 1 if the value of X is unstable
54 (would be different at a different point in the program).
55 The frame pointer, arg pointer, etc. are considered stable
56 (within one function) and so is anything marked `unchanging'. */
62 RTX_CODE code
= GET_CODE (x
);
69 return ! RTX_UNCHANGING_P (x
) || rtx_unstable_p (XEXP (x
, 0));
84 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
85 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
86 /* The arg pointer varies if it is not a fixed register. */
87 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
])
88 || RTX_UNCHANGING_P (x
))
90 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
91 /* ??? When call-clobbered, the value is stable modulo the restore
92 that must happen after a call. This currently screws up local-alloc
93 into believing that the restore is not needed. */
94 if (x
== pic_offset_table_rtx
)
100 if (MEM_VOLATILE_P (x
))
109 fmt
= GET_RTX_FORMAT (code
);
110 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
113 if (rtx_unstable_p (XEXP (x
, i
)))
116 else if (fmt
[i
] == 'E')
119 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
120 if (rtx_unstable_p (XVECEXP (x
, i
, j
)))
127 /* Return 1 if X has a value that can vary even between two
128 executions of the program. 0 means X can be compared reliably
129 against certain constants or near-constants.
130 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
131 zero, we are slightly more conservative.
132 The frame pointer and the arg pointer are considered constant. */
135 rtx_varies_p (x
, for_alias
)
139 RTX_CODE code
= GET_CODE (x
);
146 return ! RTX_UNCHANGING_P (x
) || rtx_varies_p (XEXP (x
, 0), for_alias
);
160 /* This will resolve to some offset from the frame pointer. */
164 /* Note that we have to test for the actual rtx used for the frame
165 and arg pointers and not just the register number in case we have
166 eliminated the frame and/or arg pointer and are using it
168 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
169 /* The arg pointer varies if it is not a fixed register. */
170 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
172 if (x
== pic_offset_table_rtx
173 #ifdef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
174 /* ??? When call-clobbered, the value is stable modulo the restore
175 that must happen after a call. This currently screws up
176 local-alloc into believing that the restore is not needed, so we
177 must return 0 only if we are called from alias analysis. */
185 /* The operand 0 of a LO_SUM is considered constant
186 (in fact it is related specifically to operand 1)
187 during alias analysis. */
188 return (! for_alias
&& rtx_varies_p (XEXP (x
, 0), for_alias
))
189 || rtx_varies_p (XEXP (x
, 1), for_alias
);
192 if (MEM_VOLATILE_P (x
))
201 fmt
= GET_RTX_FORMAT (code
);
202 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
205 if (rtx_varies_p (XEXP (x
, i
), for_alias
))
208 else if (fmt
[i
] == 'E')
211 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
212 if (rtx_varies_p (XVECEXP (x
, i
, j
), for_alias
))
219 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
222 rtx_addr_can_trap_p (x
)
225 enum rtx_code code
= GET_CODE (x
);
230 return SYMBOL_REF_WEAK (x
);
236 /* This will resolve to some offset from the frame pointer. */
240 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
241 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
242 || x
== stack_pointer_rtx
243 /* The arg pointer varies if it is not a fixed register. */
244 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
246 /* All of the virtual frame registers are stack references. */
247 if (REGNO (x
) >= FIRST_VIRTUAL_REGISTER
248 && REGNO (x
) <= LAST_VIRTUAL_REGISTER
)
253 return rtx_addr_can_trap_p (XEXP (x
, 0));
256 /* An address is assumed not to trap if it is an address that can't
257 trap plus a constant integer or it is the pic register plus a
259 return ! ((! rtx_addr_can_trap_p (XEXP (x
, 0))
260 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
261 || (XEXP (x
, 0) == pic_offset_table_rtx
262 && CONSTANT_P (XEXP (x
, 1))));
266 return rtx_addr_can_trap_p (XEXP (x
, 1));
273 return rtx_addr_can_trap_p (XEXP (x
, 0));
279 /* If it isn't one of the case above, it can cause a trap. */
283 /* Return true if X is an address that is known to not be zero. */
286 nonzero_address_p (x
)
289 enum rtx_code code
= GET_CODE (x
);
294 return !SYMBOL_REF_WEAK (x
);
300 /* This will resolve to some offset from the frame pointer. */
304 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
305 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
306 || x
== stack_pointer_rtx
307 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
309 /* All of the virtual frame registers are stack references. */
310 if (REGNO (x
) >= FIRST_VIRTUAL_REGISTER
311 && REGNO (x
) <= LAST_VIRTUAL_REGISTER
)
316 return nonzero_address_p (XEXP (x
, 0));
319 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
321 /* Pointers aren't allowed to wrap. If we've got a register
322 that is known to be a pointer, and a positive offset, then
323 the composite can't be zero. */
324 if (INTVAL (XEXP (x
, 1)) > 0
325 && REG_P (XEXP (x
, 0))
326 && REG_POINTER (XEXP (x
, 0)))
329 return nonzero_address_p (XEXP (x
, 0));
331 /* Handle PIC references. */
332 else if (XEXP (x
, 0) == pic_offset_table_rtx
333 && CONSTANT_P (XEXP (x
, 1)))
338 /* Similar to the above; allow positive offsets. Further, since
339 auto-inc is only allowed in memories, the register must be a
341 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
342 && INTVAL (XEXP (x
, 1)) > 0)
344 return nonzero_address_p (XEXP (x
, 0));
347 /* Similarly. Further, the offset is always positive. */
354 return nonzero_address_p (XEXP (x
, 0));
357 return nonzero_address_p (XEXP (x
, 1));
363 /* If it isn't one of the case above, might be zero. */
367 /* Return 1 if X refers to a memory location whose address
368 cannot be compared reliably with constant addresses,
369 or if X refers to a BLKmode memory object.
370 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
371 zero, we are slightly more conservative. */
374 rtx_addr_varies_p (x
, for_alias
)
387 return GET_MODE (x
) == BLKmode
|| rtx_varies_p (XEXP (x
, 0), for_alias
);
389 fmt
= GET_RTX_FORMAT (code
);
390 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
393 if (rtx_addr_varies_p (XEXP (x
, i
), for_alias
))
396 else if (fmt
[i
] == 'E')
399 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
400 if (rtx_addr_varies_p (XVECEXP (x
, i
, j
), for_alias
))
406 /* Return the value of the integer term in X, if one is apparent;
408 Only obvious integer terms are detected.
409 This is used in cse.c with the `related_value' field. */
415 if (GET_CODE (x
) == CONST
)
418 if (GET_CODE (x
) == MINUS
419 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
420 return - INTVAL (XEXP (x
, 1));
421 if (GET_CODE (x
) == PLUS
422 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
423 return INTVAL (XEXP (x
, 1));
427 /* If X is a constant, return the value sans apparent integer term;
429 Only obvious integer terms are detected. */
432 get_related_value (x
)
435 if (GET_CODE (x
) != CONST
)
438 if (GET_CODE (x
) == PLUS
439 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
441 else if (GET_CODE (x
) == MINUS
442 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
447 /* Given a tablejump insn INSN, return the RTL expression for the offset
448 into the jump table. If the offset cannot be determined, then return
451 If EARLIEST is nonzero, it is a pointer to a place where the earliest
452 insn used in locating the offset was found. */
455 get_jump_table_offset (insn
, earliest
)
469 if (!tablejump_p (insn
, &label
, &table
) || !(set
= single_set (insn
)))
474 /* Some targets (eg, ARM) emit a tablejump that also
475 contains the out-of-range target. */
476 if (GET_CODE (x
) == IF_THEN_ELSE
477 && GET_CODE (XEXP (x
, 2)) == LABEL_REF
)
480 /* Search backwards and locate the expression stored in X. */
481 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
482 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
485 /* If X is an expression using a relative address then strip
486 off the addition / subtraction of PC, PIC_OFFSET_TABLE_REGNUM,
487 or the jump table label. */
488 if (GET_CODE (PATTERN (table
)) == ADDR_DIFF_VEC
489 && (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
))
491 for (i
= 0; i
< 2; i
++)
496 if (y
== pc_rtx
|| y
== pic_offset_table_rtx
)
499 for (old_y
= NULL_RTX
; GET_CODE (y
) == REG
&& y
!= old_y
;
500 old_y
= y
, y
= find_last_value (y
, &old_insn
, NULL_RTX
, 0))
503 if ((GET_CODE (y
) == LABEL_REF
&& XEXP (y
, 0) == label
))
512 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
513 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
517 /* Strip off any sign or zero extension. */
518 if (GET_CODE (x
) == SIGN_EXTEND
|| GET_CODE (x
) == ZERO_EXTEND
)
522 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
523 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
527 /* If X isn't a MEM then this isn't a tablejump we understand. */
528 if (GET_CODE (x
) != MEM
)
531 /* Strip off the MEM. */
534 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
535 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
538 /* If X isn't a PLUS than this isn't a tablejump we understand. */
539 if (GET_CODE (x
) != PLUS
)
542 /* At this point we should have an expression representing the jump table
543 plus an offset. Examine each operand in order to determine which one
544 represents the jump table. Knowing that tells us that the other operand
545 must represent the offset. */
546 for (i
= 0; i
< 2; i
++)
551 for (old_y
= NULL_RTX
; GET_CODE (y
) == REG
&& y
!= old_y
;
552 old_y
= y
, y
= find_last_value (y
, &old_insn
, NULL_RTX
, 0))
555 if ((GET_CODE (y
) == CONST
|| GET_CODE (y
) == LABEL_REF
)
556 && reg_mentioned_p (label
, y
))
565 /* Strip off the addition / subtraction of PIC_OFFSET_TABLE_REGNUM. */
566 if (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
)
567 for (i
= 0; i
< 2; i
++)
568 if (XEXP (x
, i
) == pic_offset_table_rtx
)
577 /* Return the RTL expression representing the offset. */
581 /* A subroutine of global_reg_mentioned_p, returns 1 if *LOC mentions
582 a global register. */
585 global_reg_mentioned_p_1 (loc
, data
)
587 void *data ATTRIBUTE_UNUSED
;
595 switch (GET_CODE (x
))
598 if (GET_CODE (SUBREG_REG (x
)) == REG
)
600 if (REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
601 && global_regs
[subreg_regno (x
)])
609 if (regno
< FIRST_PSEUDO_REGISTER
&& global_regs
[regno
])
623 /* A non-constant call might use a global register. */
633 /* Returns nonzero if X mentions a global register. */
636 global_reg_mentioned_p (x
)
642 if (GET_CODE (x
) == CALL_INSN
)
644 if (! CONST_OR_PURE_CALL_P (x
))
646 x
= CALL_INSN_FUNCTION_USAGE (x
);
654 return for_each_rtx (&x
, global_reg_mentioned_p_1
, NULL
);
657 /* Return the number of places FIND appears within X. If COUNT_DEST is
658 zero, we do not count occurrences inside the destination of a SET. */
661 count_occurrences (x
, find
, count_dest
)
667 const char *format_ptr
;
688 if (GET_CODE (find
) == MEM
&& rtx_equal_p (x
, find
))
693 if (SET_DEST (x
) == find
&& ! count_dest
)
694 return count_occurrences (SET_SRC (x
), find
, count_dest
);
701 format_ptr
= GET_RTX_FORMAT (code
);
704 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
706 switch (*format_ptr
++)
709 count
+= count_occurrences (XEXP (x
, i
), find
, count_dest
);
713 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
714 count
+= count_occurrences (XVECEXP (x
, i
, j
), find
, count_dest
);
721 /* Nonzero if register REG appears somewhere within IN.
722 Also works if REG is not a register; in this case it checks
723 for a subexpression of IN that is Lisp "equal" to REG. */
726 reg_mentioned_p (reg
, in
)
739 if (GET_CODE (in
) == LABEL_REF
)
740 return reg
== XEXP (in
, 0);
742 code
= GET_CODE (in
);
746 /* Compare registers by number. */
748 return GET_CODE (reg
) == REG
&& REGNO (in
) == REGNO (reg
);
750 /* These codes have no constituent expressions
758 return GET_CODE (reg
) == CONST_INT
&& INTVAL (in
) == INTVAL (reg
);
762 /* These are kept unique for a given value. */
769 if (GET_CODE (reg
) == code
&& rtx_equal_p (reg
, in
))
772 fmt
= GET_RTX_FORMAT (code
);
774 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
779 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
780 if (reg_mentioned_p (reg
, XVECEXP (in
, i
, j
)))
783 else if (fmt
[i
] == 'e'
784 && reg_mentioned_p (reg
, XEXP (in
, i
)))
790 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
791 no CODE_LABEL insn. */
794 no_labels_between_p (beg
, end
)
800 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
801 if (GET_CODE (p
) == CODE_LABEL
)
806 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
807 no JUMP_INSN insn. */
810 no_jumps_between_p (beg
, end
)
814 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
815 if (GET_CODE (p
) == JUMP_INSN
)
820 /* Nonzero if register REG is used in an insn between
821 FROM_INSN and TO_INSN (exclusive of those two). */
824 reg_used_between_p (reg
, from_insn
, to_insn
)
825 rtx reg
, from_insn
, to_insn
;
829 if (from_insn
== to_insn
)
832 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
834 && (reg_overlap_mentioned_p (reg
, PATTERN (insn
))
835 || (GET_CODE (insn
) == CALL_INSN
836 && (find_reg_fusage (insn
, USE
, reg
)
837 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
842 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
843 is entirely replaced by a new value and the only use is as a SET_DEST,
844 we do not consider it a reference. */
847 reg_referenced_p (x
, body
)
853 switch (GET_CODE (body
))
856 if (reg_overlap_mentioned_p (x
, SET_SRC (body
)))
859 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
860 of a REG that occupies all of the REG, the insn references X if
861 it is mentioned in the destination. */
862 if (GET_CODE (SET_DEST (body
)) != CC0
863 && GET_CODE (SET_DEST (body
)) != PC
864 && GET_CODE (SET_DEST (body
)) != REG
865 && ! (GET_CODE (SET_DEST (body
)) == SUBREG
866 && GET_CODE (SUBREG_REG (SET_DEST (body
))) == REG
867 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body
))))
868 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
869 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body
)))
870 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)))
871 && reg_overlap_mentioned_p (x
, SET_DEST (body
)))
876 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
877 if (reg_overlap_mentioned_p (x
, ASM_OPERANDS_INPUT (body
, i
)))
884 return reg_overlap_mentioned_p (x
, body
);
887 return reg_overlap_mentioned_p (x
, TRAP_CONDITION (body
));
890 return reg_overlap_mentioned_p (x
, XEXP (body
, 0));
893 case UNSPEC_VOLATILE
:
894 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
895 if (reg_overlap_mentioned_p (x
, XVECEXP (body
, 0, i
)))
900 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
901 if (reg_referenced_p (x
, XVECEXP (body
, 0, i
)))
906 if (GET_CODE (XEXP (body
, 0)) == MEM
)
907 if (reg_overlap_mentioned_p (x
, XEXP (XEXP (body
, 0), 0)))
912 if (reg_overlap_mentioned_p (x
, COND_EXEC_TEST (body
)))
914 return reg_referenced_p (x
, COND_EXEC_CODE (body
));
921 /* Nonzero if register REG is referenced in an insn between
922 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
926 reg_referenced_between_p (reg
, from_insn
, to_insn
)
927 rtx reg
, from_insn
, to_insn
;
931 if (from_insn
== to_insn
)
934 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
936 && (reg_referenced_p (reg
, PATTERN (insn
))
937 || (GET_CODE (insn
) == CALL_INSN
938 && find_reg_fusage (insn
, USE
, reg
))))
943 /* Nonzero if register REG is set or clobbered in an insn between
944 FROM_INSN and TO_INSN (exclusive of those two). */
947 reg_set_between_p (reg
, from_insn
, to_insn
)
948 rtx reg
, from_insn
, to_insn
;
952 if (from_insn
== to_insn
)
955 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
956 if (INSN_P (insn
) && reg_set_p (reg
, insn
))
961 /* Internals of reg_set_between_p. */
963 reg_set_p (reg
, insn
)
966 /* We can be passed an insn or part of one. If we are passed an insn,
967 check if a side-effect of the insn clobbers REG. */
969 && (FIND_REG_INC_NOTE (insn
, reg
)
970 || (GET_CODE (insn
) == CALL_INSN
971 /* We'd like to test call_used_regs here, but rtlanal.c can't
972 reference that variable due to its use in genattrtab. So
973 we'll just be more conservative.
975 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
976 information holds all clobbered registers. */
977 && ((GET_CODE (reg
) == REG
978 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
979 || GET_CODE (reg
) == MEM
980 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
983 return set_of (reg
, insn
) != NULL_RTX
;
986 /* Similar to reg_set_between_p, but check all registers in X. Return 0
987 only if none of them are modified between START and END. Do not
988 consider non-registers one way or the other. */
991 regs_set_between_p (x
, start
, end
)
995 enum rtx_code code
= GET_CODE (x
);
1012 return reg_set_between_p (x
, start
, end
);
1018 fmt
= GET_RTX_FORMAT (code
);
1019 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1021 if (fmt
[i
] == 'e' && regs_set_between_p (XEXP (x
, i
), start
, end
))
1024 else if (fmt
[i
] == 'E')
1025 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1026 if (regs_set_between_p (XVECEXP (x
, i
, j
), start
, end
))
1033 /* Similar to reg_set_between_p, but check all registers in X. Return 0
1034 only if none of them are modified between START and END. Return 1 if
1035 X contains a MEM; this routine does usememory aliasing. */
1038 modified_between_p (x
, start
, end
)
1042 enum rtx_code code
= GET_CODE (x
);
1065 if (RTX_UNCHANGING_P (x
))
1067 if (modified_between_p (XEXP (x
, 0), start
, end
))
1069 for (insn
= NEXT_INSN (start
); insn
!= end
; insn
= NEXT_INSN (insn
))
1070 if (memory_modified_in_insn_p (x
, insn
))
1076 return reg_set_between_p (x
, start
, end
);
1082 fmt
= GET_RTX_FORMAT (code
);
1083 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1085 if (fmt
[i
] == 'e' && modified_between_p (XEXP (x
, i
), start
, end
))
1088 else if (fmt
[i
] == 'E')
1089 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1090 if (modified_between_p (XVECEXP (x
, i
, j
), start
, end
))
1097 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
1098 of them are modified in INSN. Return 1 if X contains a MEM; this routine
1099 does use memory aliasing. */
1102 modified_in_p (x
, insn
)
1106 enum rtx_code code
= GET_CODE (x
);
1125 if (RTX_UNCHANGING_P (x
))
1127 if (modified_in_p (XEXP (x
, 0), insn
))
1129 if (memory_modified_in_insn_p (x
, insn
))
1135 return reg_set_p (x
, insn
);
1141 fmt
= GET_RTX_FORMAT (code
);
1142 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1144 if (fmt
[i
] == 'e' && modified_in_p (XEXP (x
, i
), insn
))
1147 else if (fmt
[i
] == 'E')
1148 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1149 if (modified_in_p (XVECEXP (x
, i
, j
), insn
))
1156 /* Return true if anything in insn X is (anti,output,true) dependent on
1157 anything in insn Y. */
1160 insn_dependent_p (x
, y
)
1165 if (! INSN_P (x
) || ! INSN_P (y
))
1169 note_stores (PATTERN (x
), insn_dependent_p_1
, &tmp
);
1170 if (tmp
== NULL_RTX
)
1174 note_stores (PATTERN (y
), insn_dependent_p_1
, &tmp
);
1175 if (tmp
== NULL_RTX
)
1181 /* A helper routine for insn_dependent_p called through note_stores. */
1184 insn_dependent_p_1 (x
, pat
, data
)
1186 rtx pat ATTRIBUTE_UNUSED
;
1189 rtx
* pinsn
= (rtx
*) data
;
1191 if (*pinsn
&& reg_mentioned_p (x
, *pinsn
))
1195 /* Helper function for set_of. */
1203 set_of_1 (x
, pat
, data1
)
1208 struct set_of_data
*data
= (struct set_of_data
*) (data1
);
1209 if (rtx_equal_p (x
, data
->pat
)
1210 || (GET_CODE (x
) != MEM
&& reg_overlap_mentioned_p (data
->pat
, x
)))
1214 /* Give an INSN, return a SET or CLOBBER expression that does modify PAT
1215 (either directly or via STRICT_LOW_PART and similar modifiers). */
1220 struct set_of_data data
;
1221 data
.found
= NULL_RTX
;
1223 note_stores (INSN_P (insn
) ? PATTERN (insn
) : insn
, set_of_1
, &data
);
1227 /* Given an INSN, return a SET expression if this insn has only a single SET.
1228 It may also have CLOBBERs, USEs, or SET whose output
1229 will not be used, which we ignore. */
1232 single_set_2 (insn
, pat
)
1236 int set_verified
= 1;
1239 if (GET_CODE (pat
) == PARALLEL
)
1241 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1243 rtx sub
= XVECEXP (pat
, 0, i
);
1244 switch (GET_CODE (sub
))
1251 /* We can consider insns having multiple sets, where all
1252 but one are dead as single set insns. In common case
1253 only single set is present in the pattern so we want
1254 to avoid checking for REG_UNUSED notes unless necessary.
1256 When we reach set first time, we just expect this is
1257 the single set we are looking for and only when more
1258 sets are found in the insn, we check them. */
1261 if (find_reg_note (insn
, REG_UNUSED
, SET_DEST (set
))
1262 && !side_effects_p (set
))
1268 set
= sub
, set_verified
= 0;
1269 else if (!find_reg_note (insn
, REG_UNUSED
, SET_DEST (sub
))
1270 || side_effects_p (sub
))
1282 /* Given an INSN, return nonzero if it has more than one SET, else return
1286 multiple_sets (insn
)
1292 /* INSN must be an insn. */
1293 if (! INSN_P (insn
))
1296 /* Only a PARALLEL can have multiple SETs. */
1297 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1299 for (i
= 0, found
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
1300 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1302 /* If we have already found a SET, then return now. */
1310 /* Either zero or one SET. */
1314 /* Return nonzero if the destination of SET equals the source
1315 and there are no side effects. */
1321 rtx src
= SET_SRC (set
);
1322 rtx dst
= SET_DEST (set
);
1324 if (dst
== pc_rtx
&& src
== pc_rtx
)
1327 if (GET_CODE (dst
) == MEM
&& GET_CODE (src
) == MEM
)
1328 return rtx_equal_p (dst
, src
) && !side_effects_p (dst
);
1330 if (GET_CODE (dst
) == SIGN_EXTRACT
1331 || GET_CODE (dst
) == ZERO_EXTRACT
)
1332 return rtx_equal_p (XEXP (dst
, 0), src
)
1333 && ! BYTES_BIG_ENDIAN
&& XEXP (dst
, 2) == const0_rtx
1334 && !side_effects_p (src
);
1336 if (GET_CODE (dst
) == STRICT_LOW_PART
)
1337 dst
= XEXP (dst
, 0);
1339 if (GET_CODE (src
) == SUBREG
&& GET_CODE (dst
) == SUBREG
)
1341 if (SUBREG_BYTE (src
) != SUBREG_BYTE (dst
))
1343 src
= SUBREG_REG (src
);
1344 dst
= SUBREG_REG (dst
);
1347 return (GET_CODE (src
) == REG
&& GET_CODE (dst
) == REG
1348 && REGNO (src
) == REGNO (dst
));
1351 /* Return nonzero if an insn consists only of SETs, each of which only sets a
1358 rtx pat
= PATTERN (insn
);
1360 if (INSN_CODE (insn
) == NOOP_MOVE_INSN_CODE
)
1363 /* Insns carrying these notes are useful later on. */
1364 if (find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
1367 /* For now treat an insn with a REG_RETVAL note as a
1368 a special insn which should not be considered a no-op. */
1369 if (find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
1372 if (GET_CODE (pat
) == SET
&& set_noop_p (pat
))
1375 if (GET_CODE (pat
) == PARALLEL
)
1378 /* If nothing but SETs of registers to themselves,
1379 this insn can also be deleted. */
1380 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1382 rtx tem
= XVECEXP (pat
, 0, i
);
1384 if (GET_CODE (tem
) == USE
1385 || GET_CODE (tem
) == CLOBBER
)
1388 if (GET_CODE (tem
) != SET
|| ! set_noop_p (tem
))
1398 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
1399 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
1400 If the object was modified, if we hit a partial assignment to X, or hit a
1401 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
1402 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
1406 find_last_value (x
, pinsn
, valid_to
, allow_hwreg
)
1414 for (p
= PREV_INSN (*pinsn
); p
&& GET_CODE (p
) != CODE_LABEL
;
1418 rtx set
= single_set (p
);
1419 rtx note
= find_reg_note (p
, REG_EQUAL
, NULL_RTX
);
1421 if (set
&& rtx_equal_p (x
, SET_DEST (set
)))
1423 rtx src
= SET_SRC (set
);
1425 if (note
&& GET_CODE (XEXP (note
, 0)) != EXPR_LIST
)
1426 src
= XEXP (note
, 0);
1428 if ((valid_to
== NULL_RTX
1429 || ! modified_between_p (src
, PREV_INSN (p
), valid_to
))
1430 /* Reject hard registers because we don't usually want
1431 to use them; we'd rather use a pseudo. */
1432 && (! (GET_CODE (src
) == REG
1433 && REGNO (src
) < FIRST_PSEUDO_REGISTER
) || allow_hwreg
))
1440 /* If set in non-simple way, we don't have a value. */
1441 if (reg_set_p (x
, p
))
1448 /* Return nonzero if register in range [REGNO, ENDREGNO)
1449 appears either explicitly or implicitly in X
1450 other than being stored into.
1452 References contained within the substructure at LOC do not count.
1453 LOC may be zero, meaning don't ignore anything. */
1456 refers_to_regno_p (regno
, endregno
, x
, loc
)
1457 unsigned int regno
, endregno
;
1462 unsigned int x_regno
;
1467 /* The contents of a REG_NONNEG note is always zero, so we must come here
1468 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
1472 code
= GET_CODE (x
);
1477 x_regno
= REGNO (x
);
1479 /* If we modifying the stack, frame, or argument pointer, it will
1480 clobber a virtual register. In fact, we could be more precise,
1481 but it isn't worth it. */
1482 if ((x_regno
== STACK_POINTER_REGNUM
1483 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1484 || x_regno
== ARG_POINTER_REGNUM
1486 || x_regno
== FRAME_POINTER_REGNUM
)
1487 && regno
>= FIRST_VIRTUAL_REGISTER
&& regno
<= LAST_VIRTUAL_REGISTER
)
1490 return (endregno
> x_regno
1491 && regno
< x_regno
+ (x_regno
< FIRST_PSEUDO_REGISTER
1492 ? HARD_REGNO_NREGS (x_regno
, GET_MODE (x
))
1496 /* If this is a SUBREG of a hard reg, we can see exactly which
1497 registers are being modified. Otherwise, handle normally. */
1498 if (GET_CODE (SUBREG_REG (x
)) == REG
1499 && REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
)
1501 unsigned int inner_regno
= subreg_regno (x
);
1502 unsigned int inner_endregno
1503 = inner_regno
+ (inner_regno
< FIRST_PSEUDO_REGISTER
1504 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
1506 return endregno
> inner_regno
&& regno
< inner_endregno
;
1512 if (&SET_DEST (x
) != loc
1513 /* Note setting a SUBREG counts as referring to the REG it is in for
1514 a pseudo but not for hard registers since we can
1515 treat each word individually. */
1516 && ((GET_CODE (SET_DEST (x
)) == SUBREG
1517 && loc
!= &SUBREG_REG (SET_DEST (x
))
1518 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
1519 && REGNO (SUBREG_REG (SET_DEST (x
))) >= FIRST_PSEUDO_REGISTER
1520 && refers_to_regno_p (regno
, endregno
,
1521 SUBREG_REG (SET_DEST (x
)), loc
))
1522 || (GET_CODE (SET_DEST (x
)) != REG
1523 && refers_to_regno_p (regno
, endregno
, SET_DEST (x
), loc
))))
1526 if (code
== CLOBBER
|| loc
== &SET_SRC (x
))
1535 /* X does not match, so try its subexpressions. */
1537 fmt
= GET_RTX_FORMAT (code
);
1538 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1540 if (fmt
[i
] == 'e' && loc
!= &XEXP (x
, i
))
1548 if (refers_to_regno_p (regno
, endregno
, XEXP (x
, i
), loc
))
1551 else if (fmt
[i
] == 'E')
1554 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1555 if (loc
!= &XVECEXP (x
, i
, j
)
1556 && refers_to_regno_p (regno
, endregno
, XVECEXP (x
, i
, j
), loc
))
1563 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
1564 we check if any register number in X conflicts with the relevant register
1565 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
1566 contains a MEM (we don't bother checking for memory addresses that can't
1567 conflict because we expect this to be a rare case. */
1570 reg_overlap_mentioned_p (x
, in
)
1573 unsigned int regno
, endregno
;
1575 /* Overly conservative. */
1576 if (GET_CODE (x
) == STRICT_LOW_PART
1577 || GET_CODE (x
) == ZERO_EXTRACT
1578 || GET_CODE (x
) == SIGN_EXTRACT
)
1581 /* If either argument is a constant, then modifying X can not affect IN. */
1582 if (CONSTANT_P (x
) || CONSTANT_P (in
))
1585 switch (GET_CODE (x
))
1588 regno
= REGNO (SUBREG_REG (x
));
1589 if (regno
< FIRST_PSEUDO_REGISTER
)
1590 regno
= subreg_regno (x
);
1596 endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
1597 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
1598 return refers_to_regno_p (regno
, endregno
, in
, (rtx
*) 0);
1605 if (GET_CODE (in
) == MEM
)
1608 fmt
= GET_RTX_FORMAT (GET_CODE (in
));
1609 for (i
= GET_RTX_LENGTH (GET_CODE (in
)) - 1; i
>= 0; i
--)
1610 if (fmt
[i
] == 'e' && reg_overlap_mentioned_p (x
, XEXP (in
, i
)))
1619 return reg_mentioned_p (x
, in
);
1625 /* If any register in here refers to it we return true. */
1626 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1627 if (XEXP (XVECEXP (x
, 0, i
), 0) != 0
1628 && reg_overlap_mentioned_p (XEXP (XVECEXP (x
, 0, i
), 0), in
))
1640 /* Return the last value to which REG was set prior to INSN. If we can't
1641 find it easily, return 0.
1643 We only return a REG, SUBREG, or constant because it is too hard to
1644 check if a MEM remains unchanged. */
1647 reg_set_last (x
, insn
)
1651 rtx orig_insn
= insn
;
1653 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1654 Stop when we reach a label or X is a hard reg and we reach a
1655 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1657 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1659 /* We compare with <= here, because reg_set_last_last_regno
1660 is actually the number of the first reg *not* in X. */
1662 insn
&& GET_CODE (insn
) != CODE_LABEL
1663 && ! (GET_CODE (insn
) == CALL_INSN
1664 && REGNO (x
) <= FIRST_PSEUDO_REGISTER
);
1665 insn
= PREV_INSN (insn
))
1668 rtx set
= set_of (x
, insn
);
1669 /* OK, this function modify our register. See if we understand it. */
1673 if (GET_CODE (set
) != SET
|| SET_DEST (set
) != x
)
1675 last_value
= SET_SRC (x
);
1676 if (CONSTANT_P (last_value
)
1677 || ((GET_CODE (last_value
) == REG
1678 || GET_CODE (last_value
) == SUBREG
)
1679 && ! reg_set_between_p (last_value
,
1690 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1691 (X would be the pattern of an insn).
1692 FUN receives two arguments:
1693 the REG, MEM, CC0 or PC being stored in or clobbered,
1694 the SET or CLOBBER rtx that does the store.
1696 If the item being stored in or clobbered is a SUBREG of a hard register,
1697 the SUBREG will be passed. */
1700 note_stores (x
, fun
, data
)
1702 void (*fun
) PARAMS ((rtx
, rtx
, void *));
1707 if (GET_CODE (x
) == COND_EXEC
)
1708 x
= COND_EXEC_CODE (x
);
1710 if (GET_CODE (x
) == SET
|| GET_CODE (x
) == CLOBBER
)
1712 rtx dest
= SET_DEST (x
);
1714 while ((GET_CODE (dest
) == SUBREG
1715 && (GET_CODE (SUBREG_REG (dest
)) != REG
1716 || REGNO (SUBREG_REG (dest
)) >= FIRST_PSEUDO_REGISTER
))
1717 || GET_CODE (dest
) == ZERO_EXTRACT
1718 || GET_CODE (dest
) == SIGN_EXTRACT
1719 || GET_CODE (dest
) == STRICT_LOW_PART
)
1720 dest
= XEXP (dest
, 0);
1722 /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions,
1723 each of whose first operand is a register. */
1724 if (GET_CODE (dest
) == PARALLEL
)
1726 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1727 if (XEXP (XVECEXP (dest
, 0, i
), 0) != 0)
1728 (*fun
) (XEXP (XVECEXP (dest
, 0, i
), 0), x
, data
);
1731 (*fun
) (dest
, x
, data
);
1734 else if (GET_CODE (x
) == PARALLEL
)
1735 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1736 note_stores (XVECEXP (x
, 0, i
), fun
, data
);
1739 /* Like notes_stores, but call FUN for each expression that is being
1740 referenced in PBODY, a pointer to the PATTERN of an insn. We only call
1741 FUN for each expression, not any interior subexpressions. FUN receives a
1742 pointer to the expression and the DATA passed to this function.
1744 Note that this is not quite the same test as that done in reg_referenced_p
1745 since that considers something as being referenced if it is being
1746 partially set, while we do not. */
1749 note_uses (pbody
, fun
, data
)
1751 void (*fun
) PARAMS ((rtx
*, void *));
1757 switch (GET_CODE (body
))
1760 (*fun
) (&COND_EXEC_TEST (body
), data
);
1761 note_uses (&COND_EXEC_CODE (body
), fun
, data
);
1765 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
1766 note_uses (&XVECEXP (body
, 0, i
), fun
, data
);
1770 (*fun
) (&XEXP (body
, 0), data
);
1774 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
1775 (*fun
) (&ASM_OPERANDS_INPUT (body
, i
), data
);
1779 (*fun
) (&TRAP_CONDITION (body
), data
);
1783 (*fun
) (&XEXP (body
, 0), data
);
1787 case UNSPEC_VOLATILE
:
1788 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
1789 (*fun
) (&XVECEXP (body
, 0, i
), data
);
1793 if (GET_CODE (XEXP (body
, 0)) == MEM
)
1794 (*fun
) (&XEXP (XEXP (body
, 0), 0), data
);
1799 rtx dest
= SET_DEST (body
);
1801 /* For sets we replace everything in source plus registers in memory
1802 expression in store and operands of a ZERO_EXTRACT. */
1803 (*fun
) (&SET_SRC (body
), data
);
1805 if (GET_CODE (dest
) == ZERO_EXTRACT
)
1807 (*fun
) (&XEXP (dest
, 1), data
);
1808 (*fun
) (&XEXP (dest
, 2), data
);
1811 while (GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
)
1812 dest
= XEXP (dest
, 0);
1814 if (GET_CODE (dest
) == MEM
)
1815 (*fun
) (&XEXP (dest
, 0), data
);
1820 /* All the other possibilities never store. */
1821 (*fun
) (pbody
, data
);
1826 /* Return nonzero if X's old contents don't survive after INSN.
1827 This will be true if X is (cc0) or if X is a register and
1828 X dies in INSN or because INSN entirely sets X.
1830 "Entirely set" means set directly and not through a SUBREG,
1831 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1832 Likewise, REG_INC does not count.
1834 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1835 but for this use that makes no difference, since regs don't overlap
1836 during their lifetimes. Therefore, this function may be used
1837 at any time after deaths have been computed (in flow.c).
1839 If REG is a hard reg that occupies multiple machine registers, this
1840 function will only return 1 if each of those registers will be replaced
1844 dead_or_set_p (insn
, x
)
1848 unsigned int regno
, last_regno
;
1851 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1852 if (GET_CODE (x
) == CC0
)
1855 if (GET_CODE (x
) != REG
)
1859 last_regno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
1860 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
)) - 1);
1862 for (i
= regno
; i
<= last_regno
; i
++)
1863 if (! dead_or_set_regno_p (insn
, i
))
1869 /* Utility function for dead_or_set_p to check an individual register. Also
1870 called from flow.c. */
1873 dead_or_set_regno_p (insn
, test_regno
)
1875 unsigned int test_regno
;
1877 unsigned int regno
, endregno
;
1880 /* See if there is a death note for something that includes TEST_REGNO. */
1881 if (find_regno_note (insn
, REG_DEAD
, test_regno
))
1884 if (GET_CODE (insn
) == CALL_INSN
1885 && find_regno_fusage (insn
, CLOBBER
, test_regno
))
1888 pattern
= PATTERN (insn
);
1890 if (GET_CODE (pattern
) == COND_EXEC
)
1891 pattern
= COND_EXEC_CODE (pattern
);
1893 if (GET_CODE (pattern
) == SET
)
1895 rtx dest
= SET_DEST (pattern
);
1897 /* A value is totally replaced if it is the destination or the
1898 destination is a SUBREG of REGNO that does not change the number of
1900 if (GET_CODE (dest
) == SUBREG
1901 && (((GET_MODE_SIZE (GET_MODE (dest
))
1902 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1903 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1904 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1905 dest
= SUBREG_REG (dest
);
1907 if (GET_CODE (dest
) != REG
)
1910 regno
= REGNO (dest
);
1911 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1912 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1914 return (test_regno
>= regno
&& test_regno
< endregno
);
1916 else if (GET_CODE (pattern
) == PARALLEL
)
1920 for (i
= XVECLEN (pattern
, 0) - 1; i
>= 0; i
--)
1922 rtx body
= XVECEXP (pattern
, 0, i
);
1924 if (GET_CODE (body
) == COND_EXEC
)
1925 body
= COND_EXEC_CODE (body
);
1927 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == CLOBBER
)
1929 rtx dest
= SET_DEST (body
);
1931 if (GET_CODE (dest
) == SUBREG
1932 && (((GET_MODE_SIZE (GET_MODE (dest
))
1933 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1934 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1935 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1936 dest
= SUBREG_REG (dest
);
1938 if (GET_CODE (dest
) != REG
)
1941 regno
= REGNO (dest
);
1942 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1943 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1945 if (test_regno
>= regno
&& test_regno
< endregno
)
1954 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1955 If DATUM is nonzero, look for one whose datum is DATUM. */
1958 find_reg_note (insn
, kind
, datum
)
1965 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1966 if (! INSN_P (insn
))
1969 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1970 if (REG_NOTE_KIND (link
) == kind
1971 && (datum
== 0 || datum
== XEXP (link
, 0)))
1976 /* Return the reg-note of kind KIND in insn INSN which applies to register
1977 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1978 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1979 it might be the case that the note overlaps REGNO. */
1982 find_regno_note (insn
, kind
, regno
)
1989 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1990 if (! INSN_P (insn
))
1993 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1994 if (REG_NOTE_KIND (link
) == kind
1995 /* Verify that it is a register, so that scratch and MEM won't cause a
1997 && GET_CODE (XEXP (link
, 0)) == REG
1998 && REGNO (XEXP (link
, 0)) <= regno
1999 && ((REGNO (XEXP (link
, 0))
2000 + (REGNO (XEXP (link
, 0)) >= FIRST_PSEUDO_REGISTER
? 1
2001 : HARD_REGNO_NREGS (REGNO (XEXP (link
, 0)),
2002 GET_MODE (XEXP (link
, 0)))))
2008 /* Return a REG_EQUIV or REG_EQUAL note if insn has only a single set and
2012 find_reg_equal_equiv_note (insn
)
2019 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2020 if (REG_NOTE_KIND (link
) == REG_EQUAL
2021 || REG_NOTE_KIND (link
) == REG_EQUIV
)
2023 if (single_set (insn
) == 0)
2030 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
2031 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
2034 find_reg_fusage (insn
, code
, datum
)
2039 /* If it's not a CALL_INSN, it can't possibly have a
2040 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
2041 if (GET_CODE (insn
) != CALL_INSN
)
2047 if (GET_CODE (datum
) != REG
)
2051 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
2053 link
= XEXP (link
, 1))
2054 if (GET_CODE (XEXP (link
, 0)) == code
2055 && rtx_equal_p (datum
, XEXP (XEXP (link
, 0), 0)))
2060 unsigned int regno
= REGNO (datum
);
2062 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
2063 to pseudo registers, so don't bother checking. */
2065 if (regno
< FIRST_PSEUDO_REGISTER
)
2067 unsigned int end_regno
2068 = regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (datum
));
2071 for (i
= regno
; i
< end_regno
; i
++)
2072 if (find_regno_fusage (insn
, code
, i
))
2080 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
2081 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
2084 find_regno_fusage (insn
, code
, regno
)
2091 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
2092 to pseudo registers, so don't bother checking. */
2094 if (regno
>= FIRST_PSEUDO_REGISTER
2095 || GET_CODE (insn
) != CALL_INSN
)
2098 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2100 unsigned int regnote
;
2103 if (GET_CODE (op
= XEXP (link
, 0)) == code
2104 && GET_CODE (reg
= XEXP (op
, 0)) == REG
2105 && (regnote
= REGNO (reg
)) <= regno
2106 && regnote
+ HARD_REGNO_NREGS (regnote
, GET_MODE (reg
)) > regno
)
2113 /* Return true if INSN is a call to a pure function. */
2121 if (GET_CODE (insn
) != CALL_INSN
|| ! CONST_OR_PURE_CALL_P (insn
))
2124 /* Look for the note that differentiates const and pure functions. */
2125 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2129 if (GET_CODE (u
= XEXP (link
, 0)) == USE
2130 && GET_CODE (m
= XEXP (u
, 0)) == MEM
&& GET_MODE (m
) == BLKmode
2131 && GET_CODE (XEXP (m
, 0)) == SCRATCH
)
2138 /* Remove register note NOTE from the REG_NOTES of INSN. */
2141 remove_note (insn
, note
)
2147 if (note
== NULL_RTX
)
2150 if (REG_NOTES (insn
) == note
)
2152 REG_NOTES (insn
) = XEXP (note
, 1);
2156 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2157 if (XEXP (link
, 1) == note
)
2159 XEXP (link
, 1) = XEXP (note
, 1);
2166 /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
2167 return 1 if it is found. A simple equality test is used to determine if
2171 in_expr_list_p (listp
, node
)
2177 for (x
= listp
; x
; x
= XEXP (x
, 1))
2178 if (node
== XEXP (x
, 0))
2184 /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
2185 remove that entry from the list if it is found.
2187 A simple equality test is used to determine if NODE matches. */
2190 remove_node_from_expr_list (node
, listp
)
2195 rtx prev
= NULL_RTX
;
2199 if (node
== XEXP (temp
, 0))
2201 /* Splice the node out of the list. */
2203 XEXP (prev
, 1) = XEXP (temp
, 1);
2205 *listp
= XEXP (temp
, 1);
2211 temp
= XEXP (temp
, 1);
2215 /* Nonzero if X contains any volatile instructions. These are instructions
2216 which may cause unpredictable machine state instructions, and thus no
2217 instructions should be moved or combined across them. This includes
2218 only volatile asms and UNSPEC_VOLATILE instructions. */
2226 code
= GET_CODE (x
);
2246 case UNSPEC_VOLATILE
:
2247 /* case TRAP_IF: This isn't clear yet. */
2252 if (MEM_VOLATILE_P (x
))
2259 /* Recursively scan the operands of this expression. */
2262 const char *fmt
= GET_RTX_FORMAT (code
);
2265 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2269 if (volatile_insn_p (XEXP (x
, i
)))
2272 else if (fmt
[i
] == 'E')
2275 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2276 if (volatile_insn_p (XVECEXP (x
, i
, j
)))
2284 /* Nonzero if X contains any volatile memory references
2285 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
2293 code
= GET_CODE (x
);
2311 case UNSPEC_VOLATILE
:
2317 if (MEM_VOLATILE_P (x
))
2324 /* Recursively scan the operands of this expression. */
2327 const char *fmt
= GET_RTX_FORMAT (code
);
2330 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2334 if (volatile_refs_p (XEXP (x
, i
)))
2337 else if (fmt
[i
] == 'E')
2340 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2341 if (volatile_refs_p (XVECEXP (x
, i
, j
)))
2349 /* Similar to above, except that it also rejects register pre- and post-
2358 code
= GET_CODE (x
);
2376 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
2377 when some combination can't be done. If we see one, don't think
2378 that we can simplify the expression. */
2379 return (GET_MODE (x
) != VOIDmode
);
2388 case UNSPEC_VOLATILE
:
2389 /* case TRAP_IF: This isn't clear yet. */
2395 if (MEM_VOLATILE_P (x
))
2402 /* Recursively scan the operands of this expression. */
2405 const char *fmt
= GET_RTX_FORMAT (code
);
2408 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2412 if (side_effects_p (XEXP (x
, i
)))
2415 else if (fmt
[i
] == 'E')
2418 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2419 if (side_effects_p (XVECEXP (x
, i
, j
)))
2427 /* Return nonzero if evaluating rtx X might cause a trap. */
2439 code
= GET_CODE (x
);
2442 /* Handle these cases quickly. */
2456 case UNSPEC_VOLATILE
:
2461 return MEM_VOLATILE_P (x
);
2463 /* Memory ref can trap unless it's a static var or a stack slot. */
2465 if (MEM_NOTRAP_P (x
))
2467 return rtx_addr_can_trap_p (XEXP (x
, 0));
2469 /* Division by a non-constant might trap. */
2474 if (HONOR_SNANS (GET_MODE (x
)))
2476 if (! CONSTANT_P (XEXP (x
, 1))
2477 || (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
2478 && flag_trapping_math
))
2480 /* This was const0_rtx, but by not using that,
2481 we can link this file into other programs. */
2482 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
&& INTVAL (XEXP (x
, 1)) == 0)
2487 /* An EXPR_LIST is used to represent a function call. This
2488 certainly may trap. */
2496 /* Some floating point comparisons may trap. */
2497 if (!flag_trapping_math
)
2499 /* ??? There is no machine independent way to check for tests that trap
2500 when COMPARE is used, though many targets do make this distinction.
2501 For instance, sparc uses CCFPE for compares which generate exceptions
2502 and CCFP for compares which do not generate exceptions. */
2503 if (HONOR_NANS (GET_MODE (x
)))
2505 /* But often the compare has some CC mode, so check operand
2507 if (HONOR_NANS (GET_MODE (XEXP (x
, 0)))
2508 || HONOR_NANS (GET_MODE (XEXP (x
, 1))))
2514 if (HONOR_SNANS (GET_MODE (x
)))
2516 /* Often comparison is CC mode, so check operand modes. */
2517 if (HONOR_SNANS (GET_MODE (XEXP (x
, 0)))
2518 || HONOR_SNANS (GET_MODE (XEXP (x
, 1))))
2523 /* Conversion of floating point might trap. */
2524 if (flag_trapping_math
&& HONOR_NANS (GET_MODE (XEXP (x
, 0))))
2530 /* These operations don't trap even with floating point. */
2534 /* Any floating arithmetic may trap. */
2535 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
2536 && flag_trapping_math
)
2540 fmt
= GET_RTX_FORMAT (code
);
2541 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2545 if (may_trap_p (XEXP (x
, i
)))
2548 else if (fmt
[i
] == 'E')
2551 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2552 if (may_trap_p (XVECEXP (x
, i
, j
)))
2559 /* Return nonzero if X contains a comparison that is not either EQ or NE,
2560 i.e., an inequality. */
2563 inequality_comparisons_p (x
)
2568 enum rtx_code code
= GET_CODE (x
);
2598 len
= GET_RTX_LENGTH (code
);
2599 fmt
= GET_RTX_FORMAT (code
);
2601 for (i
= 0; i
< len
; i
++)
2605 if (inequality_comparisons_p (XEXP (x
, i
)))
2608 else if (fmt
[i
] == 'E')
2611 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2612 if (inequality_comparisons_p (XVECEXP (x
, i
, j
)))
2620 /* Replace any occurrence of FROM in X with TO. The function does
2621 not enter into CONST_DOUBLE for the replace.
2623 Note that copying is not done so X must not be shared unless all copies
2624 are to be modified. */
2627 replace_rtx (x
, from
, to
)
2633 /* The following prevents loops occurrence when we change MEM in
2634 CONST_DOUBLE onto the same CONST_DOUBLE. */
2635 if (x
!= 0 && GET_CODE (x
) == CONST_DOUBLE
)
2641 /* Allow this function to make replacements in EXPR_LISTs. */
2645 if (GET_CODE (x
) == SUBREG
)
2647 rtx
new = replace_rtx (SUBREG_REG (x
), from
, to
);
2649 if (GET_CODE (new) == CONST_INT
)
2651 x
= simplify_subreg (GET_MODE (x
), new,
2652 GET_MODE (SUBREG_REG (x
)),
2658 SUBREG_REG (x
) = new;
2662 else if (GET_CODE (x
) == ZERO_EXTEND
)
2664 rtx
new = replace_rtx (XEXP (x
, 0), from
, to
);
2666 if (GET_CODE (new) == CONST_INT
)
2668 x
= simplify_unary_operation (ZERO_EXTEND
, GET_MODE (x
),
2669 new, GET_MODE (XEXP (x
, 0)));
2679 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2680 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2683 XEXP (x
, i
) = replace_rtx (XEXP (x
, i
), from
, to
);
2684 else if (fmt
[i
] == 'E')
2685 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2686 XVECEXP (x
, i
, j
) = replace_rtx (XVECEXP (x
, i
, j
), from
, to
);
2692 /* Throughout the rtx X, replace many registers according to REG_MAP.
2693 Return the replacement for X (which may be X with altered contents).
2694 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
2695 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
2697 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
2698 should not be mapped to pseudos or vice versa since validate_change
2701 If REPLACE_DEST is 1, replacements are also done in destinations;
2702 otherwise, only sources are replaced. */
2705 replace_regs (x
, reg_map
, nregs
, replace_dest
)
2718 code
= GET_CODE (x
);
2733 /* Verify that the register has an entry before trying to access it. */
2734 if (REGNO (x
) < nregs
&& reg_map
[REGNO (x
)] != 0)
2736 /* SUBREGs can't be shared. Always return a copy to ensure that if
2737 this replacement occurs more than once then each instance will
2738 get distinct rtx. */
2739 if (GET_CODE (reg_map
[REGNO (x
)]) == SUBREG
)
2740 return copy_rtx (reg_map
[REGNO (x
)]);
2741 return reg_map
[REGNO (x
)];
2746 /* Prevent making nested SUBREGs. */
2747 if (GET_CODE (SUBREG_REG (x
)) == REG
&& REGNO (SUBREG_REG (x
)) < nregs
2748 && reg_map
[REGNO (SUBREG_REG (x
))] != 0
2749 && GET_CODE (reg_map
[REGNO (SUBREG_REG (x
))]) == SUBREG
)
2751 rtx map_val
= reg_map
[REGNO (SUBREG_REG (x
))];
2752 return simplify_gen_subreg (GET_MODE (x
), map_val
,
2753 GET_MODE (SUBREG_REG (x
)),
2760 SET_DEST (x
) = replace_regs (SET_DEST (x
), reg_map
, nregs
, 0);
2762 else if (GET_CODE (SET_DEST (x
)) == MEM
2763 || GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2764 /* Even if we are not to replace destinations, replace register if it
2765 is CONTAINED in destination (destination is memory or
2766 STRICT_LOW_PART). */
2767 XEXP (SET_DEST (x
), 0) = replace_regs (XEXP (SET_DEST (x
), 0),
2769 else if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2770 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2773 SET_SRC (x
) = replace_regs (SET_SRC (x
), reg_map
, nregs
, 0);
2780 fmt
= GET_RTX_FORMAT (code
);
2781 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2784 XEXP (x
, i
) = replace_regs (XEXP (x
, i
), reg_map
, nregs
, replace_dest
);
2785 else if (fmt
[i
] == 'E')
2788 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2789 XVECEXP (x
, i
, j
) = replace_regs (XVECEXP (x
, i
, j
), reg_map
,
2790 nregs
, replace_dest
);
2796 /* Replace occurrences of the old label in *X with the new one.
2797 DATA is a REPLACE_LABEL_DATA containing the old and new labels. */
2800 replace_label (x
, data
)
2806 rtx old_label
= ((replace_label_data
*) data
)->r1
;
2807 rtx new_label
= ((replace_label_data
*) data
)->r2
;
2808 bool update_label_nuses
= ((replace_label_data
*) data
)->update_label_nuses
;
2813 if (GET_CODE (l
) == MEM
2814 && (tmp
= XEXP (l
, 0)) != NULL_RTX
2815 && GET_CODE (tmp
) == SYMBOL_REF
2816 && CONSTANT_POOL_ADDRESS_P (tmp
))
2818 rtx c
= get_pool_constant (tmp
);
2819 if (rtx_referenced_p (old_label
, c
))
2822 replace_label_data
*d
= (replace_label_data
*) data
;
2824 /* Create a copy of constant C; replace the label inside
2825 but do not update LABEL_NUSES because uses in constant pool
2827 new_c
= copy_rtx (c
);
2828 d
->update_label_nuses
= false;
2829 for_each_rtx (&new_c
, replace_label
, data
);
2830 d
->update_label_nuses
= update_label_nuses
;
2832 /* Add the new constant NEW_C to constant pool and replace
2833 the old reference to constant by new reference. */
2834 new_l
= force_const_mem (get_pool_mode (tmp
), new_c
);
2835 *x
= replace_rtx (l
, l
, new_l
);
2840 /* If this is a JUMP_INSN, then we also need to fix the JUMP_LABEL
2841 field. This is not handled by for_each_rtx because it doesn't
2842 handle unprinted ('0') fields. */
2843 if (GET_CODE (l
) == JUMP_INSN
&& JUMP_LABEL (l
) == old_label
)
2844 JUMP_LABEL (l
) = new_label
;
2846 if ((GET_CODE (l
) == LABEL_REF
2847 || GET_CODE (l
) == INSN_LIST
)
2848 && XEXP (l
, 0) == old_label
)
2850 XEXP (l
, 0) = new_label
;
2851 if (update_label_nuses
)
2853 ++LABEL_NUSES (new_label
);
2854 --LABEL_NUSES (old_label
);
2862 /* When *BODY is equal to X or X is directly referenced by *BODY
2863 return nonzero, thus FOR_EACH_RTX stops traversing and returns nonzero
2864 too, otherwise FOR_EACH_RTX continues traversing *BODY. */
2867 rtx_referenced_p_1 (body
, x
)
2873 if (*body
== NULL_RTX
)
2874 return y
== NULL_RTX
;
2876 /* Return true if a label_ref *BODY refers to label Y. */
2877 if (GET_CODE (*body
) == LABEL_REF
&& GET_CODE (y
) == CODE_LABEL
)
2878 return XEXP (*body
, 0) == y
;
2880 /* If *BODY is a reference to pool constant traverse the constant. */
2881 if (GET_CODE (*body
) == SYMBOL_REF
2882 && CONSTANT_POOL_ADDRESS_P (*body
))
2883 return rtx_referenced_p (y
, get_pool_constant (*body
));
2885 /* By default, compare the RTL expressions. */
2886 return rtx_equal_p (*body
, y
);
2889 /* Return true if X is referenced in BODY. */
2892 rtx_referenced_p (x
, body
)
2896 return for_each_rtx (&body
, rtx_referenced_p_1
, x
);
2899 /* If INSN is a jump to jumptable insn rturn true and store the label (which
2900 INSN jumps to) to *LABEL and the tablejump insn to *TABLE.
2901 LABEL and TABLE may be NULL. */
2904 tablejump_p (insn
, label
, table
)
2911 if (onlyjump_p (insn
)
2912 && (l
= JUMP_LABEL (insn
)) != NULL_RTX
2913 && (t
= NEXT_INSN (l
)) != NULL_RTX
2914 && GET_CODE (t
) == JUMP_INSN
2915 && (GET_CODE (PATTERN (t
)) == ADDR_VEC
2916 || GET_CODE (PATTERN (t
)) == ADDR_DIFF_VEC
))
2927 /* A subroutine of computed_jump_p, return 1 if X contains a REG or MEM or
2928 constant that is not in the constant pool and not in the condition
2929 of an IF_THEN_ELSE. */
2932 computed_jump_p_1 (x
)
2935 enum rtx_code code
= GET_CODE (x
);
2954 return ! (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
2955 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)));
2958 return (computed_jump_p_1 (XEXP (x
, 1))
2959 || computed_jump_p_1 (XEXP (x
, 2)));
2965 fmt
= GET_RTX_FORMAT (code
);
2966 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2969 && computed_jump_p_1 (XEXP (x
, i
)))
2972 else if (fmt
[i
] == 'E')
2973 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2974 if (computed_jump_p_1 (XVECEXP (x
, i
, j
)))
2981 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2983 Tablejumps and casesi insns are not considered indirect jumps;
2984 we can recognize them by a (use (label_ref)). */
2987 computed_jump_p (insn
)
2991 if (GET_CODE (insn
) == JUMP_INSN
)
2993 rtx pat
= PATTERN (insn
);
2995 if (find_reg_note (insn
, REG_LABEL
, NULL_RTX
))
2997 else if (GET_CODE (pat
) == PARALLEL
)
2999 int len
= XVECLEN (pat
, 0);
3000 int has_use_labelref
= 0;
3002 for (i
= len
- 1; i
>= 0; i
--)
3003 if (GET_CODE (XVECEXP (pat
, 0, i
)) == USE
3004 && (GET_CODE (XEXP (XVECEXP (pat
, 0, i
), 0))
3006 has_use_labelref
= 1;
3008 if (! has_use_labelref
)
3009 for (i
= len
- 1; i
>= 0; i
--)
3010 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
3011 && SET_DEST (XVECEXP (pat
, 0, i
)) == pc_rtx
3012 && computed_jump_p_1 (SET_SRC (XVECEXP (pat
, 0, i
))))
3015 else if (GET_CODE (pat
) == SET
3016 && SET_DEST (pat
) == pc_rtx
3017 && computed_jump_p_1 (SET_SRC (pat
)))
3023 /* Traverse X via depth-first search, calling F for each
3024 sub-expression (including X itself). F is also passed the DATA.
3025 If F returns -1, do not traverse sub-expressions, but continue
3026 traversing the rest of the tree. If F ever returns any other
3027 nonzero value, stop the traversal, and return the value returned
3028 by F. Otherwise, return 0. This function does not traverse inside
3029 tree structure that contains RTX_EXPRs, or into sub-expressions
3030 whose format code is `0' since it is not known whether or not those
3031 codes are actually RTL.
3033 This routine is very general, and could (should?) be used to
3034 implement many of the other routines in this file. */
3037 for_each_rtx (x
, f
, data
)
3048 result
= (*f
) (x
, data
);
3050 /* Do not traverse sub-expressions. */
3052 else if (result
!= 0)
3053 /* Stop the traversal. */
3057 /* There are no sub-expressions. */
3060 length
= GET_RTX_LENGTH (GET_CODE (*x
));
3061 format
= GET_RTX_FORMAT (GET_CODE (*x
));
3063 for (i
= 0; i
< length
; ++i
)
3068 result
= for_each_rtx (&XEXP (*x
, i
), f
, data
);
3075 if (XVEC (*x
, i
) != 0)
3078 for (j
= 0; j
< XVECLEN (*x
, i
); ++j
)
3080 result
= for_each_rtx (&XVECEXP (*x
, i
, j
), f
, data
);
3088 /* Nothing to do. */
3097 /* Searches X for any reference to REGNO, returning the rtx of the
3098 reference found if any. Otherwise, returns NULL_RTX. */
3101 regno_use_in (regno
, x
)
3109 if (GET_CODE (x
) == REG
&& REGNO (x
) == regno
)
3112 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
3113 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
3117 if ((tem
= regno_use_in (regno
, XEXP (x
, i
))))
3120 else if (fmt
[i
] == 'E')
3121 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
3122 if ((tem
= regno_use_in (regno
, XVECEXP (x
, i
, j
))))
3129 /* Return a value indicating whether OP, an operand of a commutative
3130 operation, is preferred as the first or second operand. The higher
3131 the value, the stronger the preference for being the first operand.
3132 We use negative values to indicate a preference for the first operand
3133 and positive values for the second operand. */
3136 commutative_operand_precedence (op
)
3139 /* Constants always come the second operand. Prefer "nice" constants. */
3140 if (GET_CODE (op
) == CONST_INT
)
3142 if (GET_CODE (op
) == CONST_DOUBLE
)
3144 if (CONSTANT_P (op
))
3147 /* SUBREGs of objects should come second. */
3148 if (GET_CODE (op
) == SUBREG
3149 && GET_RTX_CLASS (GET_CODE (SUBREG_REG (op
))) == 'o')
3152 /* If only one operand is a `neg', `not',
3153 `mult', `plus', or `minus' expression, it will be the first
3155 if (GET_CODE (op
) == NEG
|| GET_CODE (op
) == NOT
3156 || GET_CODE (op
) == MULT
|| GET_CODE (op
) == PLUS
3157 || GET_CODE (op
) == MINUS
)
3160 /* Complex expressions should be the first, so decrease priority
3162 if (GET_RTX_CLASS (GET_CODE (op
)) == 'o')
3167 /* Return 1 iff it is necessary to swap operands of commutative operation
3168 in order to canonicalize expression. */
3171 swap_commutative_operands_p (x
, y
)
3174 return (commutative_operand_precedence (x
)
3175 < commutative_operand_precedence (y
));
3178 /* Return 1 if X is an autoincrement side effect and the register is
3179 not the stack pointer. */
3184 switch (GET_CODE (x
))
3192 /* There are no REG_INC notes for SP. */
3193 if (XEXP (x
, 0) != stack_pointer_rtx
)
3201 /* Return 1 if the sequence of instructions beginning with FROM and up
3202 to and including TO is safe to move. If NEW_TO is non-NULL, and
3203 the sequence is not already safe to move, but can be easily
3204 extended to a sequence which is safe, then NEW_TO will point to the
3205 end of the extended sequence.
3207 For now, this function only checks that the region contains whole
3208 exception regions, but it could be extended to check additional
3209 conditions as well. */
3212 insns_safe_to_move_p (from
, to
, new_to
)
3217 int eh_region_count
= 0;
3221 /* By default, assume the end of the region will be what was
3228 if (GET_CODE (r
) == NOTE
)
3230 switch (NOTE_LINE_NUMBER (r
))
3232 case NOTE_INSN_EH_REGION_BEG
:
3236 case NOTE_INSN_EH_REGION_END
:
3237 if (eh_region_count
== 0)
3238 /* This sequence of instructions contains the end of
3239 an exception region, but not he beginning. Moving
3240 it will cause chaos. */
3251 /* If we've passed TO, and we see a non-note instruction, we
3252 can't extend the sequence to a movable sequence. */
3258 /* It's OK to move the sequence if there were matched sets of
3259 exception region notes. */
3260 return eh_region_count
== 0;
3265 /* It's OK to move the sequence if there were matched sets of
3266 exception region notes. */
3267 if (past_to_p
&& eh_region_count
== 0)
3273 /* Go to the next instruction. */
3280 /* Return nonzero if IN contains a piece of rtl that has the address LOC */
3282 loc_mentioned_in_p (loc
, in
)
3285 enum rtx_code code
= GET_CODE (in
);
3286 const char *fmt
= GET_RTX_FORMAT (code
);
3289 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3291 if (loc
== &in
->fld
[i
].rtx
)
3295 if (loc_mentioned_in_p (loc
, XEXP (in
, i
)))
3298 else if (fmt
[i
] == 'E')
3299 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
3300 if (loc_mentioned_in_p (loc
, XVECEXP (in
, i
, j
)))
3306 /* Given a subreg X, return the bit offset where the subreg begins
3307 (counting from the least significant bit of the reg). */
3313 enum machine_mode inner_mode
= GET_MODE (SUBREG_REG (x
));
3314 enum machine_mode mode
= GET_MODE (x
);
3315 unsigned int bitpos
;
3319 /* A paradoxical subreg begins at bit position 0. */
3320 if (GET_MODE_BITSIZE (mode
) > GET_MODE_BITSIZE (inner_mode
))
3323 if (WORDS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
3324 /* If the subreg crosses a word boundary ensure that
3325 it also begins and ends on a word boundary. */
3326 if ((SUBREG_BYTE (x
) % UNITS_PER_WORD
3327 + GET_MODE_SIZE (mode
)) > UNITS_PER_WORD
3328 && (SUBREG_BYTE (x
) % UNITS_PER_WORD
3329 || GET_MODE_SIZE (mode
) % UNITS_PER_WORD
))
3332 if (WORDS_BIG_ENDIAN
)
3333 word
= (GET_MODE_SIZE (inner_mode
)
3334 - (SUBREG_BYTE (x
) + GET_MODE_SIZE (mode
))) / UNITS_PER_WORD
;
3336 word
= SUBREG_BYTE (x
) / UNITS_PER_WORD
;
3337 bitpos
= word
* BITS_PER_WORD
;
3339 if (BYTES_BIG_ENDIAN
)
3340 byte
= (GET_MODE_SIZE (inner_mode
)
3341 - (SUBREG_BYTE (x
) + GET_MODE_SIZE (mode
))) % UNITS_PER_WORD
;
3343 byte
= SUBREG_BYTE (x
) % UNITS_PER_WORD
;
3344 bitpos
+= byte
* BITS_PER_UNIT
;
3349 /* This function returns the regno offset of a subreg expression.
3350 xregno - A regno of an inner hard subreg_reg (or what will become one).
3351 xmode - The mode of xregno.
3352 offset - The byte offset.
3353 ymode - The mode of a top level SUBREG (or what may become one).
3354 RETURN - The regno offset which would be used. */
3356 subreg_regno_offset (xregno
, xmode
, offset
, ymode
)
3357 unsigned int xregno
;
3358 enum machine_mode xmode
;
3359 unsigned int offset
;
3360 enum machine_mode ymode
;
3362 int nregs_xmode
, nregs_ymode
;
3363 int mode_multiple
, nregs_multiple
;
3366 if (xregno
>= FIRST_PSEUDO_REGISTER
)
3369 nregs_xmode
= HARD_REGNO_NREGS (xregno
, xmode
);
3370 nregs_ymode
= HARD_REGNO_NREGS (xregno
, ymode
);
3372 /* If this is a big endian paradoxical subreg, which uses more actual
3373 hard registers than the original register, we must return a negative
3374 offset so that we find the proper highpart of the register. */
3376 && nregs_ymode
> nregs_xmode
3377 && (GET_MODE_SIZE (ymode
) > UNITS_PER_WORD
3378 ? WORDS_BIG_ENDIAN
: BYTES_BIG_ENDIAN
))
3379 return nregs_xmode
- nregs_ymode
;
3381 if (offset
== 0 || nregs_xmode
== nregs_ymode
)
3384 /* size of ymode must not be greater than the size of xmode. */
3385 mode_multiple
= GET_MODE_SIZE (xmode
) / GET_MODE_SIZE (ymode
);
3386 if (mode_multiple
== 0)
3389 y_offset
= offset
/ GET_MODE_SIZE (ymode
);
3390 nregs_multiple
= nregs_xmode
/ nregs_ymode
;
3391 return (y_offset
/ (mode_multiple
/ nregs_multiple
)) * nregs_ymode
;
3394 /* This function returns true when the offset is representable via
3395 subreg_offset in the given regno.
3396 xregno - A regno of an inner hard subreg_reg (or what will become one).
3397 xmode - The mode of xregno.
3398 offset - The byte offset.
3399 ymode - The mode of a top level SUBREG (or what may become one).
3400 RETURN - The regno offset which would be used. */
3402 subreg_offset_representable_p (xregno
, xmode
, offset
, ymode
)
3403 unsigned int xregno
;
3404 enum machine_mode xmode
;
3405 unsigned int offset
;
3406 enum machine_mode ymode
;
3408 int nregs_xmode
, nregs_ymode
;
3409 int mode_multiple
, nregs_multiple
;
3412 if (xregno
>= FIRST_PSEUDO_REGISTER
)
3415 nregs_xmode
= HARD_REGNO_NREGS (xregno
, xmode
);
3416 nregs_ymode
= HARD_REGNO_NREGS (xregno
, ymode
);
3418 /* paradoxical subregs are always valid. */
3420 && nregs_ymode
> nregs_xmode
3421 && (GET_MODE_SIZE (ymode
) > UNITS_PER_WORD
3422 ? WORDS_BIG_ENDIAN
: BYTES_BIG_ENDIAN
))
3425 /* Lowpart subregs are always valid. */
3426 if (offset
== subreg_lowpart_offset (ymode
, xmode
))
3429 #ifdef ENABLE_CHECKING
3430 /* This should always pass, otherwise we don't know how to verify the
3433 These conditions may be relaxed but subreg_offset would need to be
3435 if (GET_MODE_SIZE (xmode
) % GET_MODE_SIZE (ymode
)
3436 || GET_MODE_SIZE (ymode
) % nregs_ymode
3437 || (GET_MODE_BITSIZE (mode_for_size (GET_MODE_BITSIZE (xmode
)
3440 != GET_MODE_BITSIZE (xmode
) / nregs_xmode
)
3441 || nregs_xmode
% nregs_ymode
)
3445 /* The XMODE value can be seen as an vector of NREGS_XMODE
3446 values. The subreg must represent an lowpart of given field.
3447 Compute what field it is. */
3448 offset
-= subreg_lowpart_offset (ymode
,
3449 mode_for_size (GET_MODE_BITSIZE (xmode
)
3453 /* size of ymode must not be greater than the size of xmode. */
3454 mode_multiple
= GET_MODE_SIZE (xmode
) / GET_MODE_SIZE (ymode
);
3455 if (mode_multiple
== 0)
3458 y_offset
= offset
/ GET_MODE_SIZE (ymode
);
3459 nregs_multiple
= nregs_xmode
/ nregs_ymode
;
3460 #ifdef ENABLE_CHECKING
3461 if (offset
% GET_MODE_SIZE (ymode
)
3462 || mode_multiple
% nregs_multiple
)
3465 return (!(y_offset
% (mode_multiple
/ nregs_multiple
)));
3468 /* Return the final regno that a subreg expression refers to. */
3474 rtx subreg
= SUBREG_REG (x
);
3475 int regno
= REGNO (subreg
);
3477 ret
= regno
+ subreg_regno_offset (regno
,
3484 struct parms_set_data
3490 /* Helper function for noticing stores to parameter registers. */
3492 parms_set (x
, pat
, data
)
3493 rtx x
, pat ATTRIBUTE_UNUSED
;
3496 struct parms_set_data
*d
= data
;
3497 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
3498 && TEST_HARD_REG_BIT (d
->regs
, REGNO (x
)))
3500 CLEAR_HARD_REG_BIT (d
->regs
, REGNO (x
));
3505 /* Look backward for first parameter to be loaded.
3506 Do not skip BOUNDARY. */
3508 find_first_parameter_load (call_insn
, boundary
)
3509 rtx call_insn
, boundary
;
3511 struct parms_set_data parm
;
3514 /* Since different machines initialize their parameter registers
3515 in different orders, assume nothing. Collect the set of all
3516 parameter registers. */
3517 CLEAR_HARD_REG_SET (parm
.regs
);
3519 for (p
= CALL_INSN_FUNCTION_USAGE (call_insn
); p
; p
= XEXP (p
, 1))
3520 if (GET_CODE (XEXP (p
, 0)) == USE
3521 && GET_CODE (XEXP (XEXP (p
, 0), 0)) == REG
)
3523 if (REGNO (XEXP (XEXP (p
, 0), 0)) >= FIRST_PSEUDO_REGISTER
)
3526 /* We only care about registers which can hold function
3528 if (!FUNCTION_ARG_REGNO_P (REGNO (XEXP (XEXP (p
, 0), 0))))
3531 SET_HARD_REG_BIT (parm
.regs
, REGNO (XEXP (XEXP (p
, 0), 0)));
3536 /* Search backward for the first set of a register in this set. */
3537 while (parm
.nregs
&& before
!= boundary
)
3539 before
= PREV_INSN (before
);
3541 /* It is possible that some loads got CSEed from one call to
3542 another. Stop in that case. */
3543 if (GET_CODE (before
) == CALL_INSN
)
3546 /* Our caller needs either ensure that we will find all sets
3547 (in case code has not been optimized yet), or take care
3548 for possible labels in a way by setting boundary to preceding
3550 if (GET_CODE (before
) == CODE_LABEL
)
3552 if (before
!= boundary
)
3557 if (INSN_P (before
))
3558 note_stores (PATTERN (before
), parms_set
, &parm
);
3563 /* Return true if we should avoid inserting code between INSN and preceding
3564 call instruction. */
3567 keep_with_call_p (insn
)
3572 if (INSN_P (insn
) && (set
= single_set (insn
)) != NULL
)
3574 if (GET_CODE (SET_DEST (set
)) == REG
3575 && REGNO (SET_DEST (set
)) < FIRST_PSEUDO_REGISTER
3576 && fixed_regs
[REGNO (SET_DEST (set
))]
3577 && general_operand (SET_SRC (set
), VOIDmode
))
3579 if (GET_CODE (SET_SRC (set
)) == REG
3580 && FUNCTION_VALUE_REGNO_P (REGNO (SET_SRC (set
)))
3581 && GET_CODE (SET_DEST (set
)) == REG
3582 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
)
3584 /* There may be a stack pop just after the call and before the store
3585 of the return register. Search for the actual store when deciding
3586 if we can break or not. */
3587 if (SET_DEST (set
) == stack_pointer_rtx
)
3589 rtx i2
= next_nonnote_insn (insn
);
3590 if (i2
&& keep_with_call_p (i2
))
3597 /* Return true when store to register X can be hoisted to the place
3598 with LIVE registers (can be NULL). Value VAL contains destination
3599 whose value will be used. */
3602 hoist_test_store (x
, val
, live
)
3606 if (GET_CODE (x
) == SCRATCH
)
3609 if (rtx_equal_p (x
, val
))
3612 /* Allow subreg of X in case it is not writting just part of multireg pseudo.
3613 Then we would need to update all users to care hoisting the store too.
3614 Caller may represent that by specifying whole subreg as val. */
3616 if (GET_CODE (x
) == SUBREG
&& rtx_equal_p (SUBREG_REG (x
), val
))
3618 if (GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) > UNITS_PER_WORD
3619 && GET_MODE_BITSIZE (GET_MODE (x
)) <
3620 GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
))))
3624 if (GET_CODE (x
) == SUBREG
)
3627 /* Anything except register store is not hoistable. This includes the
3628 partial stores to registers. */
3633 /* Pseudo registers can be allways replaced by another pseudo to avoid
3634 the side effect, for hard register we must ensure that they are dead.
3635 Eventually we may want to add code to try turn pseudos to hards, but it
3636 is unlikely useful. */
3638 if (REGNO (x
) < FIRST_PSEUDO_REGISTER
)
3640 int regno
= REGNO (x
);
3641 int n
= HARD_REGNO_NREGS (regno
, GET_MODE (x
));
3645 if (REGNO_REG_SET_P (live
, regno
))
3648 if (REGNO_REG_SET_P (live
, regno
+ n
))
3655 /* Return true if INSN can be hoisted to place with LIVE hard registers
3656 (LIVE can be NULL when unknown). VAL is expected to be stored by the insn
3657 and used by the hoisting pass. */
3660 can_hoist_insn_p (insn
, val
, live
)
3664 rtx pat
= PATTERN (insn
);
3667 /* It probably does not worth the complexity to handle multiple
3669 if (!single_set (insn
))
3671 /* We can move CALL_INSN, but we need to check that all caller clobbered
3673 if (GET_CODE (insn
) == CALL_INSN
)
3675 /* In future we will handle hoisting of libcall sequences, but
3677 if (find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
3679 switch (GET_CODE (pat
))
3682 if (!hoist_test_store (SET_DEST (pat
), val
, live
))
3686 /* USES do have sick semantics, so do not move them. */
3690 if (!hoist_test_store (XEXP (pat
, 0), val
, live
))
3694 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
3696 rtx x
= XVECEXP (pat
, 0, i
);
3697 switch (GET_CODE (x
))
3700 if (!hoist_test_store (SET_DEST (x
), val
, live
))
3704 /* We need to fix callers to really ensure availability
3705 of all values inisn uses, but for now it is safe to prohibit
3706 hoisting of any insn having such a hidden uses. */
3710 if (!hoist_test_store (SET_DEST (x
), val
, live
))
3724 /* Update store after hoisting - replace all stores to pseudo registers
3725 by new ones to avoid clobbering of values except for store to VAL that will
3726 be updated to NEW. */
3729 hoist_update_store (insn
, xp
, val
, new)
3730 rtx insn
, *xp
, val
, new;
3734 if (GET_CODE (x
) == SCRATCH
)
3737 if (GET_CODE (x
) == SUBREG
&& SUBREG_REG (x
) == val
)
3738 validate_change (insn
, xp
,
3739 simplify_gen_subreg (GET_MODE (x
), new, GET_MODE (new),
3740 SUBREG_BYTE (x
)), 1);
3741 if (rtx_equal_p (x
, val
))
3743 validate_change (insn
, xp
, new, 1);
3746 if (GET_CODE (x
) == SUBREG
)
3748 xp
= &SUBREG_REG (x
);
3755 /* We've verified that hard registers are dead, so we may keep the side
3756 effect. Otherwise replace it by new pseudo. */
3757 if (REGNO (x
) >= FIRST_PSEUDO_REGISTER
)
3758 validate_change (insn
, xp
, gen_reg_rtx (GET_MODE (x
)), 1);
3760 = alloc_EXPR_LIST (REG_UNUSED
, *xp
, REG_NOTES (insn
));
3763 /* Create a copy of INSN after AFTER replacing store of VAL to NEW
3764 and each other side effect to pseudo register by new pseudo register. */
3767 hoist_insn_after (insn
, after
, val
, new)
3768 rtx insn
, after
, val
, new;
3774 insn
= emit_copy_of_insn_after (insn
, after
);
3775 pat
= PATTERN (insn
);
3777 /* Remove REG_UNUSED notes as we will re-emit them. */
3778 while ((note
= find_reg_note (insn
, REG_UNUSED
, NULL_RTX
)))
3779 remove_note (insn
, note
);
3781 /* To get this working callers must ensure to move everything referenced
3782 by REG_EQUAL/REG_EQUIV notes too. Lets remove them, it is probably
3784 while ((note
= find_reg_note (insn
, REG_EQUAL
, NULL_RTX
)))
3785 remove_note (insn
, note
);
3786 while ((note
= find_reg_note (insn
, REG_EQUIV
, NULL_RTX
)))
3787 remove_note (insn
, note
);
3789 /* Remove REG_DEAD notes as they might not be valid anymore in case
3790 we create redundancy. */
3791 while ((note
= find_reg_note (insn
, REG_DEAD
, NULL_RTX
)))
3792 remove_note (insn
, note
);
3793 switch (GET_CODE (pat
))
3796 hoist_update_store (insn
, &SET_DEST (pat
), val
, new);
3801 hoist_update_store (insn
, &XEXP (pat
, 0), val
, new);
3804 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
3806 rtx x
= XVECEXP (pat
, 0, i
);
3807 switch (GET_CODE (x
))
3810 hoist_update_store (insn
, &SET_DEST (x
), val
, new);
3815 hoist_update_store (insn
, &SET_DEST (x
), val
, new);
3825 if (!apply_change_group ())
3832 hoist_insn_to_edge (insn
, e
, val
, new)
3838 /* We cannot insert instructions on an abnormal critical edge.
3839 It will be easier to find the culprit if we die now. */
3840 if ((e
->flags
& EDGE_ABNORMAL
) && EDGE_CRITICAL_P (e
))
3843 /* Do not use emit_insn_on_edge as we want to preserve notes and similar
3844 stuff. We also emit CALL_INSNS and firends. */
3845 if (e
->insns
== NULL_RTX
)
3848 emit_note (NULL
, NOTE_INSN_DELETED
);
3851 push_to_sequence (e
->insns
);
3853 new_insn
= hoist_insn_after (insn
, get_last_insn (), val
, new);
3855 e
->insns
= get_insns ();