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
27 #include "hard-reg-set.h"
28 #include "insn-config.h"
33 /* Forward declarations */
34 static int global_reg_mentioned_p_1
PARAMS ((rtx
*, void *));
35 static void set_of_1
PARAMS ((rtx
, rtx
, void *));
36 static void insn_dependent_p_1
PARAMS ((rtx
, rtx
, void *));
37 static int computed_jump_p_1
PARAMS ((rtx
));
38 static void parms_set
PARAMS ((rtx
, rtx
, void *));
40 /* Bit flags that specify the machine subtype we are compiling for.
41 Bits are tested using macros TARGET_... defined in the tm.h file
42 and set by `-m...' switches. Must be defined in rtlanal.c. */
46 /* Return 1 if the value of X is unstable
47 (would be different at a different point in the program).
48 The frame pointer, arg pointer, etc. are considered stable
49 (within one function) and so is anything marked `unchanging'. */
55 RTX_CODE code
= GET_CODE (x
);
62 return ! RTX_UNCHANGING_P (x
) || rtx_unstable_p (XEXP (x
, 0));
77 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
78 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
79 /* The arg pointer varies if it is not a fixed register. */
80 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
])
81 || RTX_UNCHANGING_P (x
))
83 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
84 /* ??? When call-clobbered, the value is stable modulo the restore
85 that must happen after a call. This currently screws up local-alloc
86 into believing that the restore is not needed. */
87 if (x
== pic_offset_table_rtx
)
93 if (MEM_VOLATILE_P (x
))
102 fmt
= GET_RTX_FORMAT (code
);
103 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
106 if (rtx_unstable_p (XEXP (x
, i
)))
109 else if (fmt
[i
] == 'E')
112 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
113 if (rtx_unstable_p (XVECEXP (x
, i
, j
)))
120 /* Return 1 if X has a value that can vary even between two
121 executions of the program. 0 means X can be compared reliably
122 against certain constants or near-constants.
123 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
124 zero, we are slightly more conservative.
125 The frame pointer and the arg pointer are considered constant. */
128 rtx_varies_p (x
, for_alias
)
132 RTX_CODE code
= GET_CODE (x
);
139 return ! RTX_UNCHANGING_P (x
) || rtx_varies_p (XEXP (x
, 0), for_alias
);
153 /* Note that we have to test for the actual rtx used for the frame
154 and arg pointers and not just the register number in case we have
155 eliminated the frame and/or arg pointer and are using it
157 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
158 /* The arg pointer varies if it is not a fixed register. */
159 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
161 if (x
== pic_offset_table_rtx
162 #ifdef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
163 /* ??? When call-clobbered, the value is stable modulo the restore
164 that must happen after a call. This currently screws up
165 local-alloc into believing that the restore is not needed, so we
166 must return 0 only if we are called from alias analysis. */
174 /* The operand 0 of a LO_SUM is considered constant
175 (in fact it is related specifically to operand 1)
176 during alias analysis. */
177 return (! for_alias
&& rtx_varies_p (XEXP (x
, 0), for_alias
))
178 || rtx_varies_p (XEXP (x
, 1), for_alias
);
181 if (MEM_VOLATILE_P (x
))
190 fmt
= GET_RTX_FORMAT (code
);
191 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
194 if (rtx_varies_p (XEXP (x
, i
), for_alias
))
197 else if (fmt
[i
] == 'E')
200 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
201 if (rtx_varies_p (XVECEXP (x
, i
, j
), for_alias
))
208 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
211 rtx_addr_can_trap_p (x
)
214 enum rtx_code code
= GET_CODE (x
);
219 return SYMBOL_REF_WEAK (x
);
225 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
226 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
227 || x
== stack_pointer_rtx
228 /* The arg pointer varies if it is not a fixed register. */
229 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
231 /* All of the virtual frame registers are stack references. */
232 if (REGNO (x
) >= FIRST_VIRTUAL_REGISTER
233 && REGNO (x
) <= LAST_VIRTUAL_REGISTER
)
238 return rtx_addr_can_trap_p (XEXP (x
, 0));
241 /* An address is assumed not to trap if it is an address that can't
242 trap plus a constant integer or it is the pic register plus a
244 return ! ((! rtx_addr_can_trap_p (XEXP (x
, 0))
245 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
246 || (XEXP (x
, 0) == pic_offset_table_rtx
247 && CONSTANT_P (XEXP (x
, 1))));
251 return rtx_addr_can_trap_p (XEXP (x
, 1));
258 return rtx_addr_can_trap_p (XEXP (x
, 0));
264 /* If it isn't one of the case above, it can cause a trap. */
268 /* Return 1 if X refers to a memory location whose address
269 cannot be compared reliably with constant addresses,
270 or if X refers to a BLKmode memory object.
271 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
272 zero, we are slightly more conservative. */
275 rtx_addr_varies_p (x
, for_alias
)
288 return GET_MODE (x
) == BLKmode
|| rtx_varies_p (XEXP (x
, 0), for_alias
);
290 fmt
= GET_RTX_FORMAT (code
);
291 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
294 if (rtx_addr_varies_p (XEXP (x
, i
), for_alias
))
297 else if (fmt
[i
] == 'E')
300 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
301 if (rtx_addr_varies_p (XVECEXP (x
, i
, j
), for_alias
))
307 /* Return the value of the integer term in X, if one is apparent;
309 Only obvious integer terms are detected.
310 This is used in cse.c with the `related_value' field. */
316 if (GET_CODE (x
) == CONST
)
319 if (GET_CODE (x
) == MINUS
320 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
321 return - INTVAL (XEXP (x
, 1));
322 if (GET_CODE (x
) == PLUS
323 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
324 return INTVAL (XEXP (x
, 1));
328 /* If X is a constant, return the value sans apparent integer term;
330 Only obvious integer terms are detected. */
333 get_related_value (x
)
336 if (GET_CODE (x
) != CONST
)
339 if (GET_CODE (x
) == PLUS
340 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
342 else if (GET_CODE (x
) == MINUS
343 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
348 /* Given a tablejump insn INSN, return the RTL expression for the offset
349 into the jump table. If the offset cannot be determined, then return
352 If EARLIEST is non-zero, it is a pointer to a place where the earliest
353 insn used in locating the offset was found. */
356 get_jump_table_offset (insn
, earliest
)
370 if (GET_CODE (insn
) != JUMP_INSN
371 || ! (label
= JUMP_LABEL (insn
))
372 || ! (table
= NEXT_INSN (label
))
373 || GET_CODE (table
) != JUMP_INSN
374 || (GET_CODE (PATTERN (table
)) != ADDR_VEC
375 && GET_CODE (PATTERN (table
)) != ADDR_DIFF_VEC
)
376 || ! (set
= single_set (insn
)))
381 /* Some targets (eg, ARM) emit a tablejump that also
382 contains the out-of-range target. */
383 if (GET_CODE (x
) == IF_THEN_ELSE
384 && GET_CODE (XEXP (x
, 2)) == LABEL_REF
)
387 /* Search backwards and locate the expression stored in X. */
388 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
389 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
392 /* If X is an expression using a relative address then strip
393 off the addition / subtraction of PC, PIC_OFFSET_TABLE_REGNUM,
394 or the jump table label. */
395 if (GET_CODE (PATTERN (table
)) == ADDR_DIFF_VEC
396 && (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
))
398 for (i
= 0; i
< 2; i
++)
403 if (y
== pc_rtx
|| y
== pic_offset_table_rtx
)
406 for (old_y
= NULL_RTX
; GET_CODE (y
) == REG
&& y
!= old_y
;
407 old_y
= y
, y
= find_last_value (y
, &old_insn
, NULL_RTX
, 0))
410 if ((GET_CODE (y
) == LABEL_REF
&& XEXP (y
, 0) == label
))
419 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
420 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
424 /* Strip off any sign or zero extension. */
425 if (GET_CODE (x
) == SIGN_EXTEND
|| GET_CODE (x
) == ZERO_EXTEND
)
429 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
430 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
434 /* If X isn't a MEM then this isn't a tablejump we understand. */
435 if (GET_CODE (x
) != MEM
)
438 /* Strip off the MEM. */
441 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
442 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
445 /* If X isn't a PLUS than this isn't a tablejump we understand. */
446 if (GET_CODE (x
) != PLUS
)
449 /* At this point we should have an expression representing the jump table
450 plus an offset. Examine each operand in order to determine which one
451 represents the jump table. Knowing that tells us that the other operand
452 must represent the offset. */
453 for (i
= 0; i
< 2; i
++)
458 for (old_y
= NULL_RTX
; GET_CODE (y
) == REG
&& y
!= old_y
;
459 old_y
= y
, y
= find_last_value (y
, &old_insn
, NULL_RTX
, 0))
462 if ((GET_CODE (y
) == CONST
|| GET_CODE (y
) == LABEL_REF
)
463 && reg_mentioned_p (label
, y
))
472 /* Strip off the addition / subtraction of PIC_OFFSET_TABLE_REGNUM. */
473 if (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
)
474 for (i
= 0; i
< 2; i
++)
475 if (XEXP (x
, i
) == pic_offset_table_rtx
)
484 /* Return the RTL expression representing the offset. */
488 /* A subroutine of global_reg_mentioned_p, returns 1 if *LOC mentions
489 a global register. */
492 global_reg_mentioned_p_1 (loc
, data
)
494 void *data ATTRIBUTE_UNUSED
;
502 switch (GET_CODE (x
))
505 if (GET_CODE (SUBREG_REG (x
)) == REG
)
507 if (REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
508 && global_regs
[subreg_regno (x
)])
516 if (regno
< FIRST_PSEUDO_REGISTER
&& global_regs
[regno
])
530 /* A non-constant call might use a global register. */
540 /* Returns non-zero if X mentions a global register. */
543 global_reg_mentioned_p (x
)
549 if (GET_CODE (x
) == CALL_INSN
)
551 if (! CONST_OR_PURE_CALL_P (x
))
553 x
= CALL_INSN_FUNCTION_USAGE (x
);
561 return for_each_rtx (&x
, global_reg_mentioned_p_1
, NULL
);
564 /* Return the number of places FIND appears within X. If COUNT_DEST is
565 zero, we do not count occurrences inside the destination of a SET. */
568 count_occurrences (x
, find
, count_dest
)
574 const char *format_ptr
;
595 if (GET_CODE (find
) == MEM
&& rtx_equal_p (x
, find
))
600 if (SET_DEST (x
) == find
&& ! count_dest
)
601 return count_occurrences (SET_SRC (x
), find
, count_dest
);
608 format_ptr
= GET_RTX_FORMAT (code
);
611 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
613 switch (*format_ptr
++)
616 count
+= count_occurrences (XEXP (x
, i
), find
, count_dest
);
620 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
621 count
+= count_occurrences (XVECEXP (x
, i
, j
), find
, count_dest
);
628 /* Nonzero if register REG appears somewhere within IN.
629 Also works if REG is not a register; in this case it checks
630 for a subexpression of IN that is Lisp "equal" to REG. */
633 reg_mentioned_p (reg
, in
)
646 if (GET_CODE (in
) == LABEL_REF
)
647 return reg
== XEXP (in
, 0);
649 code
= GET_CODE (in
);
653 /* Compare registers by number. */
655 return GET_CODE (reg
) == REG
&& REGNO (in
) == REGNO (reg
);
657 /* These codes have no constituent expressions
665 return GET_CODE (reg
) == CONST_INT
&& INTVAL (in
) == INTVAL (reg
);
669 /* These are kept unique for a given value. */
676 if (GET_CODE (reg
) == code
&& rtx_equal_p (reg
, in
))
679 fmt
= GET_RTX_FORMAT (code
);
681 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
686 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
687 if (reg_mentioned_p (reg
, XVECEXP (in
, i
, j
)))
690 else if (fmt
[i
] == 'e'
691 && reg_mentioned_p (reg
, XEXP (in
, i
)))
697 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
698 no CODE_LABEL insn. */
701 no_labels_between_p (beg
, end
)
707 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
708 if (GET_CODE (p
) == CODE_LABEL
)
713 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
714 no JUMP_INSN insn. */
717 no_jumps_between_p (beg
, end
)
721 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
722 if (GET_CODE (p
) == JUMP_INSN
)
727 /* Nonzero if register REG is used in an insn between
728 FROM_INSN and TO_INSN (exclusive of those two). */
731 reg_used_between_p (reg
, from_insn
, to_insn
)
732 rtx reg
, from_insn
, to_insn
;
736 if (from_insn
== to_insn
)
739 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
741 && (reg_overlap_mentioned_p (reg
, PATTERN (insn
))
742 || (GET_CODE (insn
) == CALL_INSN
743 && (find_reg_fusage (insn
, USE
, reg
)
744 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
749 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
750 is entirely replaced by a new value and the only use is as a SET_DEST,
751 we do not consider it a reference. */
754 reg_referenced_p (x
, body
)
760 switch (GET_CODE (body
))
763 if (reg_overlap_mentioned_p (x
, SET_SRC (body
)))
766 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
767 of a REG that occupies all of the REG, the insn references X if
768 it is mentioned in the destination. */
769 if (GET_CODE (SET_DEST (body
)) != CC0
770 && GET_CODE (SET_DEST (body
)) != PC
771 && GET_CODE (SET_DEST (body
)) != REG
772 && ! (GET_CODE (SET_DEST (body
)) == SUBREG
773 && GET_CODE (SUBREG_REG (SET_DEST (body
))) == REG
774 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body
))))
775 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
776 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body
)))
777 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)))
778 && reg_overlap_mentioned_p (x
, SET_DEST (body
)))
783 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
784 if (reg_overlap_mentioned_p (x
, ASM_OPERANDS_INPUT (body
, i
)))
791 return reg_overlap_mentioned_p (x
, body
);
794 return reg_overlap_mentioned_p (x
, TRAP_CONDITION (body
));
797 return reg_overlap_mentioned_p (x
, XEXP (body
, 0));
800 case UNSPEC_VOLATILE
:
801 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
802 if (reg_overlap_mentioned_p (x
, XVECEXP (body
, 0, i
)))
807 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
808 if (reg_referenced_p (x
, XVECEXP (body
, 0, i
)))
813 if (GET_CODE (XEXP (body
, 0)) == MEM
)
814 if (reg_overlap_mentioned_p (x
, XEXP (XEXP (body
, 0), 0)))
819 if (reg_overlap_mentioned_p (x
, COND_EXEC_TEST (body
)))
821 return reg_referenced_p (x
, COND_EXEC_CODE (body
));
828 /* Nonzero if register REG is referenced in an insn between
829 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
833 reg_referenced_between_p (reg
, from_insn
, to_insn
)
834 rtx reg
, from_insn
, to_insn
;
838 if (from_insn
== to_insn
)
841 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
843 && (reg_referenced_p (reg
, PATTERN (insn
))
844 || (GET_CODE (insn
) == CALL_INSN
845 && find_reg_fusage (insn
, USE
, reg
))))
850 /* Nonzero if register REG is set or clobbered in an insn between
851 FROM_INSN and TO_INSN (exclusive of those two). */
854 reg_set_between_p (reg
, from_insn
, to_insn
)
855 rtx reg
, from_insn
, to_insn
;
859 if (from_insn
== to_insn
)
862 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
863 if (INSN_P (insn
) && reg_set_p (reg
, insn
))
868 /* Internals of reg_set_between_p. */
870 reg_set_p (reg
, insn
)
875 /* We can be passed an insn or part of one. If we are passed an insn,
876 check if a side-effect of the insn clobbers REG. */
879 if (FIND_REG_INC_NOTE (insn
, reg
)
880 || (GET_CODE (insn
) == CALL_INSN
881 /* We'd like to test call_used_regs here, but rtlanal.c can't
882 reference that variable due to its use in genattrtab. So
883 we'll just be more conservative.
885 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
886 information holds all clobbered registers. */
887 && ((GET_CODE (reg
) == REG
888 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
889 || GET_CODE (reg
) == MEM
890 || find_reg_fusage (insn
, CLOBBER
, reg
))))
893 body
= PATTERN (insn
);
896 return set_of (reg
, insn
) != NULL_RTX
;
899 /* Similar to reg_set_between_p, but check all registers in X. Return 0
900 only if none of them are modified between START and END. Do not
901 consider non-registers one way or the other. */
904 regs_set_between_p (x
, start
, end
)
908 enum rtx_code code
= GET_CODE (x
);
925 return reg_set_between_p (x
, start
, end
);
931 fmt
= GET_RTX_FORMAT (code
);
932 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
934 if (fmt
[i
] == 'e' && regs_set_between_p (XEXP (x
, i
), start
, end
))
937 else if (fmt
[i
] == 'E')
938 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
939 if (regs_set_between_p (XVECEXP (x
, i
, j
), start
, end
))
946 /* Similar to reg_set_between_p, but check all registers in X. Return 0
947 only if none of them are modified between START and END. Return 1 if
948 X contains a MEM; this routine does not perform any memory aliasing. */
951 modified_between_p (x
, start
, end
)
955 enum rtx_code code
= GET_CODE (x
);
974 /* If the memory is not constant, assume it is modified. If it is
975 constant, we still have to check the address. */
976 if (! RTX_UNCHANGING_P (x
))
981 return reg_set_between_p (x
, start
, end
);
987 fmt
= GET_RTX_FORMAT (code
);
988 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
990 if (fmt
[i
] == 'e' && modified_between_p (XEXP (x
, i
), start
, end
))
993 else if (fmt
[i
] == 'E')
994 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
995 if (modified_between_p (XVECEXP (x
, i
, j
), start
, end
))
1002 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
1003 of them are modified in INSN. Return 1 if X contains a MEM; this routine
1004 does not perform any memory aliasing. */
1007 modified_in_p (x
, insn
)
1011 enum rtx_code code
= GET_CODE (x
);
1030 /* If the memory is not constant, assume it is modified. If it is
1031 constant, we still have to check the address. */
1032 if (! RTX_UNCHANGING_P (x
))
1037 return reg_set_p (x
, insn
);
1043 fmt
= GET_RTX_FORMAT (code
);
1044 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1046 if (fmt
[i
] == 'e' && modified_in_p (XEXP (x
, i
), insn
))
1049 else if (fmt
[i
] == 'E')
1050 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1051 if (modified_in_p (XVECEXP (x
, i
, j
), insn
))
1058 /* Return true if anything in insn X is (anti,output,true) dependent on
1059 anything in insn Y. */
1062 insn_dependent_p (x
, y
)
1067 if (! INSN_P (x
) || ! INSN_P (y
))
1071 note_stores (PATTERN (x
), insn_dependent_p_1
, &tmp
);
1072 if (tmp
== NULL_RTX
)
1076 note_stores (PATTERN (y
), insn_dependent_p_1
, &tmp
);
1077 if (tmp
== NULL_RTX
)
1083 /* A helper routine for insn_dependent_p called through note_stores. */
1086 insn_dependent_p_1 (x
, pat
, data
)
1088 rtx pat ATTRIBUTE_UNUSED
;
1091 rtx
* pinsn
= (rtx
*) data
;
1093 if (*pinsn
&& reg_mentioned_p (x
, *pinsn
))
1097 /* Helper function for set_of. */
1105 set_of_1 (x
, pat
, data1
)
1110 struct set_of_data
*data
= (struct set_of_data
*) (data1
);
1111 if (rtx_equal_p (x
, data
->pat
)
1112 || (GET_CODE (x
) != MEM
&& reg_overlap_mentioned_p (data
->pat
, x
)))
1116 /* Give an INSN, return a SET or CLOBBER expression that does modify PAT
1117 (either directly or via STRICT_LOW_PART and similar modifiers). */
1122 struct set_of_data data
;
1123 data
.found
= NULL_RTX
;
1125 note_stores (INSN_P (insn
) ? PATTERN (insn
) : insn
, set_of_1
, &data
);
1129 /* Given an INSN, return a SET expression if this insn has only a single SET.
1130 It may also have CLOBBERs, USEs, or SET whose output
1131 will not be used, which we ignore. */
1134 single_set_2 (insn
, pat
)
1138 int set_verified
= 1;
1141 if (GET_CODE (pat
) == PARALLEL
)
1143 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1145 rtx sub
= XVECEXP (pat
, 0, i
);
1146 switch (GET_CODE (sub
))
1153 /* We can consider insns having multiple sets, where all
1154 but one are dead as single set insns. In common case
1155 only single set is present in the pattern so we want
1156 to avoid checking for REG_UNUSED notes unless necessary.
1158 When we reach set first time, we just expect this is
1159 the single set we are looking for and only when more
1160 sets are found in the insn, we check them. */
1163 if (find_reg_note (insn
, REG_UNUSED
, SET_DEST (set
))
1164 && !side_effects_p (set
))
1170 set
= sub
, set_verified
= 0;
1171 else if (!find_reg_note (insn
, REG_UNUSED
, SET_DEST (sub
))
1172 || side_effects_p (sub
))
1184 /* Given an INSN, return nonzero if it has more than one SET, else return
1188 multiple_sets (insn
)
1194 /* INSN must be an insn. */
1195 if (! INSN_P (insn
))
1198 /* Only a PARALLEL can have multiple SETs. */
1199 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1201 for (i
= 0, found
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
1202 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1204 /* If we have already found a SET, then return now. */
1212 /* Either zero or one SET. */
1216 /* Return nonzero if the destination of SET equals the source
1217 and there are no side effects. */
1223 rtx src
= SET_SRC (set
);
1224 rtx dst
= SET_DEST (set
);
1226 if (side_effects_p (src
) || side_effects_p (dst
))
1229 if (GET_CODE (dst
) == MEM
&& GET_CODE (src
) == MEM
)
1230 return rtx_equal_p (dst
, src
);
1232 if (dst
== pc_rtx
&& src
== pc_rtx
)
1235 if (GET_CODE (dst
) == SIGN_EXTRACT
1236 || GET_CODE (dst
) == ZERO_EXTRACT
)
1237 return rtx_equal_p (XEXP (dst
, 0), src
)
1238 && ! BYTES_BIG_ENDIAN
&& XEXP (dst
, 2) == const0_rtx
;
1240 if (GET_CODE (dst
) == STRICT_LOW_PART
)
1241 dst
= XEXP (dst
, 0);
1243 if (GET_CODE (src
) == SUBREG
&& GET_CODE (dst
) == SUBREG
)
1245 if (SUBREG_BYTE (src
) != SUBREG_BYTE (dst
))
1247 src
= SUBREG_REG (src
);
1248 dst
= SUBREG_REG (dst
);
1251 return (GET_CODE (src
) == REG
&& GET_CODE (dst
) == REG
1252 && REGNO (src
) == REGNO (dst
));
1255 /* Return nonzero if an insn consists only of SETs, each of which only sets a
1262 rtx pat
= PATTERN (insn
);
1264 if (INSN_CODE (insn
) == NOOP_MOVE_INSN_CODE
)
1267 /* Insns carrying these notes are useful later on. */
1268 if (find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
1271 /* For now treat an insn with a REG_RETVAL note as a
1272 a special insn which should not be considered a no-op. */
1273 if (find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
1276 if (GET_CODE (pat
) == SET
&& set_noop_p (pat
))
1279 if (GET_CODE (pat
) == PARALLEL
)
1282 /* If nothing but SETs of registers to themselves,
1283 this insn can also be deleted. */
1284 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1286 rtx tem
= XVECEXP (pat
, 0, i
);
1288 if (GET_CODE (tem
) == USE
1289 || GET_CODE (tem
) == CLOBBER
)
1292 if (GET_CODE (tem
) != SET
|| ! set_noop_p (tem
))
1302 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
1303 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
1304 If the object was modified, if we hit a partial assignment to X, or hit a
1305 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
1306 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
1310 find_last_value (x
, pinsn
, valid_to
, allow_hwreg
)
1318 for (p
= PREV_INSN (*pinsn
); p
&& GET_CODE (p
) != CODE_LABEL
;
1322 rtx set
= single_set (p
);
1323 rtx note
= find_reg_note (p
, REG_EQUAL
, NULL_RTX
);
1325 if (set
&& rtx_equal_p (x
, SET_DEST (set
)))
1327 rtx src
= SET_SRC (set
);
1329 if (note
&& GET_CODE (XEXP (note
, 0)) != EXPR_LIST
)
1330 src
= XEXP (note
, 0);
1332 if ((valid_to
== NULL_RTX
1333 || ! modified_between_p (src
, PREV_INSN (p
), valid_to
))
1334 /* Reject hard registers because we don't usually want
1335 to use them; we'd rather use a pseudo. */
1336 && (! (GET_CODE (src
) == REG
1337 && REGNO (src
) < FIRST_PSEUDO_REGISTER
) || allow_hwreg
))
1344 /* If set in non-simple way, we don't have a value. */
1345 if (reg_set_p (x
, p
))
1352 /* Return nonzero if register in range [REGNO, ENDREGNO)
1353 appears either explicitly or implicitly in X
1354 other than being stored into.
1356 References contained within the substructure at LOC do not count.
1357 LOC may be zero, meaning don't ignore anything. */
1360 refers_to_regno_p (regno
, endregno
, x
, loc
)
1361 unsigned int regno
, endregno
;
1366 unsigned int x_regno
;
1371 /* The contents of a REG_NONNEG note is always zero, so we must come here
1372 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
1376 code
= GET_CODE (x
);
1381 x_regno
= REGNO (x
);
1383 /* If we modifying the stack, frame, or argument pointer, it will
1384 clobber a virtual register. In fact, we could be more precise,
1385 but it isn't worth it. */
1386 if ((x_regno
== STACK_POINTER_REGNUM
1387 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1388 || x_regno
== ARG_POINTER_REGNUM
1390 || x_regno
== FRAME_POINTER_REGNUM
)
1391 && regno
>= FIRST_VIRTUAL_REGISTER
&& regno
<= LAST_VIRTUAL_REGISTER
)
1394 return (endregno
> x_regno
1395 && regno
< x_regno
+ (x_regno
< FIRST_PSEUDO_REGISTER
1396 ? HARD_REGNO_NREGS (x_regno
, GET_MODE (x
))
1400 /* If this is a SUBREG of a hard reg, we can see exactly which
1401 registers are being modified. Otherwise, handle normally. */
1402 if (GET_CODE (SUBREG_REG (x
)) == REG
1403 && REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
)
1405 unsigned int inner_regno
= subreg_regno (x
);
1406 unsigned int inner_endregno
1407 = inner_regno
+ (inner_regno
< FIRST_PSEUDO_REGISTER
1408 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
1410 return endregno
> inner_regno
&& regno
< inner_endregno
;
1416 if (&SET_DEST (x
) != loc
1417 /* Note setting a SUBREG counts as referring to the REG it is in for
1418 a pseudo but not for hard registers since we can
1419 treat each word individually. */
1420 && ((GET_CODE (SET_DEST (x
)) == SUBREG
1421 && loc
!= &SUBREG_REG (SET_DEST (x
))
1422 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
1423 && REGNO (SUBREG_REG (SET_DEST (x
))) >= FIRST_PSEUDO_REGISTER
1424 && refers_to_regno_p (regno
, endregno
,
1425 SUBREG_REG (SET_DEST (x
)), loc
))
1426 || (GET_CODE (SET_DEST (x
)) != REG
1427 && refers_to_regno_p (regno
, endregno
, SET_DEST (x
), loc
))))
1430 if (code
== CLOBBER
|| loc
== &SET_SRC (x
))
1439 /* X does not match, so try its subexpressions. */
1441 fmt
= GET_RTX_FORMAT (code
);
1442 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1444 if (fmt
[i
] == 'e' && loc
!= &XEXP (x
, i
))
1452 if (refers_to_regno_p (regno
, endregno
, XEXP (x
, i
), loc
))
1455 else if (fmt
[i
] == 'E')
1458 for (j
= XVECLEN (x
, i
) - 1; j
>=0; j
--)
1459 if (loc
!= &XVECEXP (x
, i
, j
)
1460 && refers_to_regno_p (regno
, endregno
, XVECEXP (x
, i
, j
), loc
))
1467 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
1468 we check if any register number in X conflicts with the relevant register
1469 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
1470 contains a MEM (we don't bother checking for memory addresses that can't
1471 conflict because we expect this to be a rare case. */
1474 reg_overlap_mentioned_p (x
, in
)
1477 unsigned int regno
, endregno
;
1479 /* Overly conservative. */
1480 if (GET_CODE (x
) == STRICT_LOW_PART
)
1483 /* If either argument is a constant, then modifying X can not affect IN. */
1484 if (CONSTANT_P (x
) || CONSTANT_P (in
))
1487 switch (GET_CODE (x
))
1490 regno
= REGNO (SUBREG_REG (x
));
1491 if (regno
< FIRST_PSEUDO_REGISTER
)
1492 regno
= subreg_regno (x
);
1498 endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
1499 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
1500 return refers_to_regno_p (regno
, endregno
, in
, (rtx
*) 0);
1507 if (GET_CODE (in
) == MEM
)
1510 fmt
= GET_RTX_FORMAT (GET_CODE (in
));
1511 for (i
= GET_RTX_LENGTH (GET_CODE (in
)) - 1; i
>= 0; i
--)
1512 if (fmt
[i
] == 'e' && reg_overlap_mentioned_p (x
, XEXP (in
, i
)))
1521 return reg_mentioned_p (x
, in
);
1527 /* If any register in here refers to it we return true. */
1528 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1529 if (XEXP (XVECEXP (x
, 0, i
), 0) != 0
1530 && reg_overlap_mentioned_p (XEXP (XVECEXP (x
, 0, i
), 0), in
))
1542 /* Return the last value to which REG was set prior to INSN. If we can't
1543 find it easily, return 0.
1545 We only return a REG, SUBREG, or constant because it is too hard to
1546 check if a MEM remains unchanged. */
1549 reg_set_last (x
, insn
)
1553 rtx orig_insn
= insn
;
1555 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1556 Stop when we reach a label or X is a hard reg and we reach a
1557 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1559 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1561 /* We compare with <= here, because reg_set_last_last_regno
1562 is actually the number of the first reg *not* in X. */
1564 insn
&& GET_CODE (insn
) != CODE_LABEL
1565 && ! (GET_CODE (insn
) == CALL_INSN
1566 && REGNO (x
) <= FIRST_PSEUDO_REGISTER
);
1567 insn
= PREV_INSN (insn
))
1570 rtx set
= set_of (x
, insn
);
1571 /* OK, this function modify our register. See if we understand it. */
1575 if (GET_CODE (set
) != SET
|| SET_DEST (set
) != x
)
1577 last_value
= SET_SRC (x
);
1578 if (CONSTANT_P (last_value
)
1579 || ((GET_CODE (last_value
) == REG
1580 || GET_CODE (last_value
) == SUBREG
)
1581 && ! reg_set_between_p (last_value
,
1592 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1593 (X would be the pattern of an insn).
1594 FUN receives two arguments:
1595 the REG, MEM, CC0 or PC being stored in or clobbered,
1596 the SET or CLOBBER rtx that does the store.
1598 If the item being stored in or clobbered is a SUBREG of a hard register,
1599 the SUBREG will be passed. */
1602 note_stores (x
, fun
, data
)
1604 void (*fun
) PARAMS ((rtx
, rtx
, void *));
1609 if (GET_CODE (x
) == COND_EXEC
)
1610 x
= COND_EXEC_CODE (x
);
1612 if (GET_CODE (x
) == SET
|| GET_CODE (x
) == CLOBBER
)
1614 rtx dest
= SET_DEST (x
);
1616 while ((GET_CODE (dest
) == SUBREG
1617 && (GET_CODE (SUBREG_REG (dest
)) != REG
1618 || REGNO (SUBREG_REG (dest
)) >= FIRST_PSEUDO_REGISTER
))
1619 || GET_CODE (dest
) == ZERO_EXTRACT
1620 || GET_CODE (dest
) == SIGN_EXTRACT
1621 || GET_CODE (dest
) == STRICT_LOW_PART
)
1622 dest
= XEXP (dest
, 0);
1624 /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions,
1625 each of whose first operand is a register. */
1626 if (GET_CODE (dest
) == PARALLEL
)
1628 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1629 if (XEXP (XVECEXP (dest
, 0, i
), 0) != 0)
1630 (*fun
) (XEXP (XVECEXP (dest
, 0, i
), 0), x
, data
);
1633 (*fun
) (dest
, x
, data
);
1636 else if (GET_CODE (x
) == PARALLEL
)
1637 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1638 note_stores (XVECEXP (x
, 0, i
), fun
, data
);
1641 /* Like notes_stores, but call FUN for each expression that is being
1642 referenced in PBODY, a pointer to the PATTERN of an insn. We only call
1643 FUN for each expression, not any interior subexpressions. FUN receives a
1644 pointer to the expression and the DATA passed to this function.
1646 Note that this is not quite the same test as that done in reg_referenced_p
1647 since that considers something as being referenced if it is being
1648 partially set, while we do not. */
1651 note_uses (pbody
, fun
, data
)
1653 void (*fun
) PARAMS ((rtx
*, void *));
1659 switch (GET_CODE (body
))
1662 (*fun
) (&COND_EXEC_TEST (body
), data
);
1663 note_uses (&COND_EXEC_CODE (body
), fun
, data
);
1667 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
1668 note_uses (&XVECEXP (body
, 0, i
), fun
, data
);
1672 (*fun
) (&XEXP (body
, 0), data
);
1676 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
1677 (*fun
) (&ASM_OPERANDS_INPUT (body
, i
), data
);
1681 (*fun
) (&TRAP_CONDITION (body
), data
);
1685 (*fun
) (&XEXP (body
, 0), data
);
1689 case UNSPEC_VOLATILE
:
1690 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
1691 (*fun
) (&XVECEXP (body
, 0, i
), data
);
1695 if (GET_CODE (XEXP (body
, 0)) == MEM
)
1696 (*fun
) (&XEXP (XEXP (body
, 0), 0), data
);
1701 rtx dest
= SET_DEST (body
);
1703 /* For sets we replace everything in source plus registers in memory
1704 expression in store and operands of a ZERO_EXTRACT. */
1705 (*fun
) (&SET_SRC (body
), data
);
1707 if (GET_CODE (dest
) == ZERO_EXTRACT
)
1709 (*fun
) (&XEXP (dest
, 1), data
);
1710 (*fun
) (&XEXP (dest
, 2), data
);
1713 while (GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
)
1714 dest
= XEXP (dest
, 0);
1716 if (GET_CODE (dest
) == MEM
)
1717 (*fun
) (&XEXP (dest
, 0), data
);
1722 /* All the other possibilities never store. */
1723 (*fun
) (pbody
, data
);
1728 /* Return nonzero if X's old contents don't survive after INSN.
1729 This will be true if X is (cc0) or if X is a register and
1730 X dies in INSN or because INSN entirely sets X.
1732 "Entirely set" means set directly and not through a SUBREG,
1733 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1734 Likewise, REG_INC does not count.
1736 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1737 but for this use that makes no difference, since regs don't overlap
1738 during their lifetimes. Therefore, this function may be used
1739 at any time after deaths have been computed (in flow.c).
1741 If REG is a hard reg that occupies multiple machine registers, this
1742 function will only return 1 if each of those registers will be replaced
1746 dead_or_set_p (insn
, x
)
1750 unsigned int regno
, last_regno
;
1753 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1754 if (GET_CODE (x
) == CC0
)
1757 if (GET_CODE (x
) != REG
)
1761 last_regno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
1762 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
)) - 1);
1764 for (i
= regno
; i
<= last_regno
; i
++)
1765 if (! dead_or_set_regno_p (insn
, i
))
1771 /* Utility function for dead_or_set_p to check an individual register. Also
1772 called from flow.c. */
1775 dead_or_set_regno_p (insn
, test_regno
)
1777 unsigned int test_regno
;
1779 unsigned int regno
, endregno
;
1782 /* See if there is a death note for something that includes TEST_REGNO. */
1783 if (find_regno_note (insn
, REG_DEAD
, test_regno
))
1786 if (GET_CODE (insn
) == CALL_INSN
1787 && find_regno_fusage (insn
, CLOBBER
, test_regno
))
1790 pattern
= PATTERN (insn
);
1792 if (GET_CODE (pattern
) == COND_EXEC
)
1793 pattern
= COND_EXEC_CODE (pattern
);
1795 if (GET_CODE (pattern
) == SET
)
1797 rtx dest
= SET_DEST (PATTERN (insn
));
1799 /* A value is totally replaced if it is the destination or the
1800 destination is a SUBREG of REGNO that does not change the number of
1802 if (GET_CODE (dest
) == SUBREG
1803 && (((GET_MODE_SIZE (GET_MODE (dest
))
1804 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1805 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1806 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1807 dest
= SUBREG_REG (dest
);
1809 if (GET_CODE (dest
) != REG
)
1812 regno
= REGNO (dest
);
1813 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1814 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1816 return (test_regno
>= regno
&& test_regno
< endregno
);
1818 else if (GET_CODE (pattern
) == PARALLEL
)
1822 for (i
= XVECLEN (pattern
, 0) - 1; i
>= 0; i
--)
1824 rtx body
= XVECEXP (pattern
, 0, i
);
1826 if (GET_CODE (body
) == COND_EXEC
)
1827 body
= COND_EXEC_CODE (body
);
1829 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == CLOBBER
)
1831 rtx dest
= SET_DEST (body
);
1833 if (GET_CODE (dest
) == SUBREG
1834 && (((GET_MODE_SIZE (GET_MODE (dest
))
1835 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1836 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1837 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1838 dest
= SUBREG_REG (dest
);
1840 if (GET_CODE (dest
) != REG
)
1843 regno
= REGNO (dest
);
1844 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1845 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1847 if (test_regno
>= regno
&& test_regno
< endregno
)
1856 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1857 If DATUM is nonzero, look for one whose datum is DATUM. */
1860 find_reg_note (insn
, kind
, datum
)
1867 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1868 if (! INSN_P (insn
))
1871 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1872 if (REG_NOTE_KIND (link
) == kind
1873 && (datum
== 0 || datum
== XEXP (link
, 0)))
1878 /* Return the reg-note of kind KIND in insn INSN which applies to register
1879 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1880 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1881 it might be the case that the note overlaps REGNO. */
1884 find_regno_note (insn
, kind
, regno
)
1891 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1892 if (! INSN_P (insn
))
1895 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1896 if (REG_NOTE_KIND (link
) == kind
1897 /* Verify that it is a register, so that scratch and MEM won't cause a
1899 && GET_CODE (XEXP (link
, 0)) == REG
1900 && REGNO (XEXP (link
, 0)) <= regno
1901 && ((REGNO (XEXP (link
, 0))
1902 + (REGNO (XEXP (link
, 0)) >= FIRST_PSEUDO_REGISTER
? 1
1903 : HARD_REGNO_NREGS (REGNO (XEXP (link
, 0)),
1904 GET_MODE (XEXP (link
, 0)))))
1910 /* Return a REG_EQUIV or REG_EQUAL note if insn has only a single set and
1914 find_reg_equal_equiv_note (insn
)
1919 if (single_set (insn
) == 0)
1921 else if ((note
= find_reg_note (insn
, REG_EQUIV
, NULL_RTX
)) != 0)
1924 return find_reg_note (insn
, REG_EQUAL
, NULL_RTX
);
1927 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1928 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1931 find_reg_fusage (insn
, code
, datum
)
1936 /* If it's not a CALL_INSN, it can't possibly have a
1937 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1938 if (GET_CODE (insn
) != CALL_INSN
)
1944 if (GET_CODE (datum
) != REG
)
1948 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1950 link
= XEXP (link
, 1))
1951 if (GET_CODE (XEXP (link
, 0)) == code
1952 && rtx_equal_p (datum
, XEXP (XEXP (link
, 0), 0)))
1957 unsigned int regno
= REGNO (datum
);
1959 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1960 to pseudo registers, so don't bother checking. */
1962 if (regno
< FIRST_PSEUDO_REGISTER
)
1964 unsigned int end_regno
1965 = regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (datum
));
1968 for (i
= regno
; i
< end_regno
; i
++)
1969 if (find_regno_fusage (insn
, code
, i
))
1977 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1978 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1981 find_regno_fusage (insn
, code
, regno
)
1988 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1989 to pseudo registers, so don't bother checking. */
1991 if (regno
>= FIRST_PSEUDO_REGISTER
1992 || GET_CODE (insn
) != CALL_INSN
)
1995 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
1997 unsigned int regnote
;
2000 if (GET_CODE (op
= XEXP (link
, 0)) == code
2001 && GET_CODE (reg
= XEXP (op
, 0)) == REG
2002 && (regnote
= REGNO (reg
)) <= regno
2003 && regnote
+ HARD_REGNO_NREGS (regnote
, GET_MODE (reg
)) > regno
)
2010 /* Return true if INSN is a call to a pure function. */
2018 if (GET_CODE (insn
) != CALL_INSN
|| ! CONST_OR_PURE_CALL_P (insn
))
2021 /* Look for the note that differentiates const and pure functions. */
2022 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2026 if (GET_CODE (u
= XEXP (link
, 0)) == USE
2027 && GET_CODE (m
= XEXP (u
, 0)) == MEM
&& GET_MODE (m
) == BLKmode
2028 && GET_CODE (XEXP (m
, 0)) == SCRATCH
)
2035 /* Remove register note NOTE from the REG_NOTES of INSN. */
2038 remove_note (insn
, note
)
2044 if (note
== NULL_RTX
)
2047 if (REG_NOTES (insn
) == note
)
2049 REG_NOTES (insn
) = XEXP (note
, 1);
2053 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2054 if (XEXP (link
, 1) == note
)
2056 XEXP (link
, 1) = XEXP (note
, 1);
2063 /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
2064 return 1 if it is found. A simple equality test is used to determine if
2068 in_expr_list_p (listp
, node
)
2074 for (x
= listp
; x
; x
= XEXP (x
, 1))
2075 if (node
== XEXP (x
, 0))
2081 /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
2082 remove that entry from the list if it is found.
2084 A simple equality test is used to determine if NODE matches. */
2087 remove_node_from_expr_list (node
, listp
)
2092 rtx prev
= NULL_RTX
;
2096 if (node
== XEXP (temp
, 0))
2098 /* Splice the node out of the list. */
2100 XEXP (prev
, 1) = XEXP (temp
, 1);
2102 *listp
= XEXP (temp
, 1);
2108 temp
= XEXP (temp
, 1);
2112 /* Nonzero if X contains any volatile instructions. These are instructions
2113 which may cause unpredictable machine state instructions, and thus no
2114 instructions should be moved or combined across them. This includes
2115 only volatile asms and UNSPEC_VOLATILE instructions. */
2123 code
= GET_CODE (x
);
2144 case UNSPEC_VOLATILE
:
2145 /* case TRAP_IF: This isn't clear yet. */
2149 if (MEM_VOLATILE_P (x
))
2156 /* Recursively scan the operands of this expression. */
2159 const char *fmt
= GET_RTX_FORMAT (code
);
2162 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2166 if (volatile_insn_p (XEXP (x
, i
)))
2169 else if (fmt
[i
] == 'E')
2172 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2173 if (volatile_insn_p (XVECEXP (x
, i
, j
)))
2181 /* Nonzero if X contains any volatile memory references
2182 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
2190 code
= GET_CODE (x
);
2210 case UNSPEC_VOLATILE
:
2211 /* case TRAP_IF: This isn't clear yet. */
2216 if (MEM_VOLATILE_P (x
))
2223 /* Recursively scan the operands of this expression. */
2226 const char *fmt
= GET_RTX_FORMAT (code
);
2229 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2233 if (volatile_refs_p (XEXP (x
, i
)))
2236 else if (fmt
[i
] == 'E')
2239 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2240 if (volatile_refs_p (XVECEXP (x
, i
, j
)))
2248 /* Similar to above, except that it also rejects register pre- and post-
2257 code
= GET_CODE (x
);
2276 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
2277 when some combination can't be done. If we see one, don't think
2278 that we can simplify the expression. */
2279 return (GET_MODE (x
) != VOIDmode
);
2288 case UNSPEC_VOLATILE
:
2289 /* case TRAP_IF: This isn't clear yet. */
2294 if (MEM_VOLATILE_P (x
))
2301 /* Recursively scan the operands of this expression. */
2304 const char *fmt
= GET_RTX_FORMAT (code
);
2307 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2311 if (side_effects_p (XEXP (x
, i
)))
2314 else if (fmt
[i
] == 'E')
2317 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2318 if (side_effects_p (XVECEXP (x
, i
, j
)))
2326 /* Return nonzero if evaluating rtx X might cause a trap. */
2338 code
= GET_CODE (x
);
2341 /* Handle these cases quickly. */
2355 case UNSPEC_VOLATILE
:
2360 return MEM_VOLATILE_P (x
);
2362 /* Memory ref can trap unless it's a static var or a stack slot. */
2364 return rtx_addr_can_trap_p (XEXP (x
, 0));
2366 /* Division by a non-constant might trap. */
2371 if (! CONSTANT_P (XEXP (x
, 1))
2372 || (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
2373 && flag_trapping_math
))
2375 /* This was const0_rtx, but by not using that,
2376 we can link this file into other programs. */
2377 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
&& INTVAL (XEXP (x
, 1)) == 0)
2382 /* An EXPR_LIST is used to represent a function call. This
2383 certainly may trap. */
2391 /* Some floating point comparisons may trap. */
2392 if (!flag_trapping_math
)
2394 /* ??? There is no machine independent way to check for tests that trap
2395 when COMPARE is used, though many targets do make this distinction.
2396 For instance, sparc uses CCFPE for compares which generate exceptions
2397 and CCFP for compares which do not generate exceptions. */
2398 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
2400 /* But often the compare has some CC mode, so check operand
2402 if (GET_MODE_CLASS (GET_MODE (XEXP (x
, 0))) == MODE_FLOAT
2403 || GET_MODE_CLASS (GET_MODE (XEXP (x
, 1))) == MODE_FLOAT
)
2409 /* These operations don't trap even with floating point. */
2413 /* Any floating arithmetic may trap. */
2414 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
2415 && flag_trapping_math
)
2419 fmt
= GET_RTX_FORMAT (code
);
2420 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2424 if (may_trap_p (XEXP (x
, i
)))
2427 else if (fmt
[i
] == 'E')
2430 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2431 if (may_trap_p (XVECEXP (x
, i
, j
)))
2438 /* Return nonzero if X contains a comparison that is not either EQ or NE,
2439 i.e., an inequality. */
2442 inequality_comparisons_p (x
)
2447 enum rtx_code code
= GET_CODE (x
);
2477 len
= GET_RTX_LENGTH (code
);
2478 fmt
= GET_RTX_FORMAT (code
);
2480 for (i
= 0; i
< len
; i
++)
2484 if (inequality_comparisons_p (XEXP (x
, i
)))
2487 else if (fmt
[i
] == 'E')
2490 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2491 if (inequality_comparisons_p (XVECEXP (x
, i
, j
)))
2499 /* Replace any occurrence of FROM in X with TO. The function does
2500 not enter into CONST_DOUBLE for the replace.
2502 Note that copying is not done so X must not be shared unless all copies
2503 are to be modified. */
2506 replace_rtx (x
, from
, to
)
2512 /* The following prevents loops occurrence when we change MEM in
2513 CONST_DOUBLE onto the same CONST_DOUBLE. */
2514 if (x
!= 0 && GET_CODE (x
) == CONST_DOUBLE
)
2520 /* Allow this function to make replacements in EXPR_LISTs. */
2524 if (GET_CODE (x
) == SUBREG
)
2526 rtx
new = replace_rtx (SUBREG_REG (x
), from
, to
);
2528 if (GET_CODE (new) == CONST_INT
)
2530 x
= simplify_subreg (GET_MODE (x
), new,
2531 GET_MODE (SUBREG_REG (x
)),
2537 SUBREG_REG (x
) = new;
2541 else if (GET_CODE (x
) == ZERO_EXTEND
)
2543 rtx
new = replace_rtx (XEXP (x
, 0), from
, to
);
2545 if (GET_CODE (new) == CONST_INT
)
2547 x
= simplify_unary_operation (ZERO_EXTEND
, GET_MODE (x
),
2548 new, GET_MODE (XEXP (x
, 0)));
2558 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2559 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2562 XEXP (x
, i
) = replace_rtx (XEXP (x
, i
), from
, to
);
2563 else if (fmt
[i
] == 'E')
2564 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2565 XVECEXP (x
, i
, j
) = replace_rtx (XVECEXP (x
, i
, j
), from
, to
);
2571 /* Throughout the rtx X, replace many registers according to REG_MAP.
2572 Return the replacement for X (which may be X with altered contents).
2573 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
2574 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
2576 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
2577 should not be mapped to pseudos or vice versa since validate_change
2580 If REPLACE_DEST is 1, replacements are also done in destinations;
2581 otherwise, only sources are replaced. */
2584 replace_regs (x
, reg_map
, nregs
, replace_dest
)
2597 code
= GET_CODE (x
);
2612 /* Verify that the register has an entry before trying to access it. */
2613 if (REGNO (x
) < nregs
&& reg_map
[REGNO (x
)] != 0)
2615 /* SUBREGs can't be shared. Always return a copy to ensure that if
2616 this replacement occurs more than once then each instance will
2617 get distinct rtx. */
2618 if (GET_CODE (reg_map
[REGNO (x
)]) == SUBREG
)
2619 return copy_rtx (reg_map
[REGNO (x
)]);
2620 return reg_map
[REGNO (x
)];
2625 /* Prevent making nested SUBREGs. */
2626 if (GET_CODE (SUBREG_REG (x
)) == REG
&& REGNO (SUBREG_REG (x
)) < nregs
2627 && reg_map
[REGNO (SUBREG_REG (x
))] != 0
2628 && GET_CODE (reg_map
[REGNO (SUBREG_REG (x
))]) == SUBREG
)
2630 rtx map_val
= reg_map
[REGNO (SUBREG_REG (x
))];
2631 return simplify_gen_subreg (GET_MODE (x
), map_val
,
2632 GET_MODE (SUBREG_REG (x
)),
2639 SET_DEST (x
) = replace_regs (SET_DEST (x
), reg_map
, nregs
, 0);
2641 else if (GET_CODE (SET_DEST (x
)) == MEM
2642 || GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2643 /* Even if we are not to replace destinations, replace register if it
2644 is CONTAINED in destination (destination is memory or
2645 STRICT_LOW_PART). */
2646 XEXP (SET_DEST (x
), 0) = replace_regs (XEXP (SET_DEST (x
), 0),
2648 else if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2649 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2652 SET_SRC (x
) = replace_regs (SET_SRC (x
), reg_map
, nregs
, 0);
2659 fmt
= GET_RTX_FORMAT (code
);
2660 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2663 XEXP (x
, i
) = replace_regs (XEXP (x
, i
), reg_map
, nregs
, replace_dest
);
2664 else if (fmt
[i
] == 'E')
2667 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2668 XVECEXP (x
, i
, j
) = replace_regs (XVECEXP (x
, i
, j
), reg_map
,
2669 nregs
, replace_dest
);
2675 /* A subroutine of computed_jump_p, return 1 if X contains a REG or MEM or
2676 constant that is not in the constant pool and not in the condition
2677 of an IF_THEN_ELSE. */
2680 computed_jump_p_1 (x
)
2683 enum rtx_code code
= GET_CODE (x
);
2702 return ! (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
2703 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)));
2706 return (computed_jump_p_1 (XEXP (x
, 1))
2707 || computed_jump_p_1 (XEXP (x
, 2)));
2713 fmt
= GET_RTX_FORMAT (code
);
2714 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2717 && computed_jump_p_1 (XEXP (x
, i
)))
2720 else if (fmt
[i
] == 'E')
2721 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2722 if (computed_jump_p_1 (XVECEXP (x
, i
, j
)))
2729 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2731 Tablejumps and casesi insns are not considered indirect jumps;
2732 we can recognize them by a (use (label_ref)). */
2735 computed_jump_p (insn
)
2739 if (GET_CODE (insn
) == JUMP_INSN
)
2741 rtx pat
= PATTERN (insn
);
2743 if (find_reg_note (insn
, REG_LABEL
, NULL_RTX
))
2745 else if (GET_CODE (pat
) == PARALLEL
)
2747 int len
= XVECLEN (pat
, 0);
2748 int has_use_labelref
= 0;
2750 for (i
= len
- 1; i
>= 0; i
--)
2751 if (GET_CODE (XVECEXP (pat
, 0, i
)) == USE
2752 && (GET_CODE (XEXP (XVECEXP (pat
, 0, i
), 0))
2754 has_use_labelref
= 1;
2756 if (! has_use_labelref
)
2757 for (i
= len
- 1; i
>= 0; i
--)
2758 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
2759 && SET_DEST (XVECEXP (pat
, 0, i
)) == pc_rtx
2760 && computed_jump_p_1 (SET_SRC (XVECEXP (pat
, 0, i
))))
2763 else if (GET_CODE (pat
) == SET
2764 && SET_DEST (pat
) == pc_rtx
2765 && computed_jump_p_1 (SET_SRC (pat
)))
2771 /* Traverse X via depth-first search, calling F for each
2772 sub-expression (including X itself). F is also passed the DATA.
2773 If F returns -1, do not traverse sub-expressions, but continue
2774 traversing the rest of the tree. If F ever returns any other
2775 non-zero value, stop the traversal, and return the value returned
2776 by F. Otherwise, return 0. This function does not traverse inside
2777 tree structure that contains RTX_EXPRs, or into sub-expressions
2778 whose format code is `0' since it is not known whether or not those
2779 codes are actually RTL.
2781 This routine is very general, and could (should?) be used to
2782 implement many of the other routines in this file. */
2785 for_each_rtx (x
, f
, data
)
2796 result
= (*f
) (x
, data
);
2798 /* Do not traverse sub-expressions. */
2800 else if (result
!= 0)
2801 /* Stop the traversal. */
2805 /* There are no sub-expressions. */
2808 length
= GET_RTX_LENGTH (GET_CODE (*x
));
2809 format
= GET_RTX_FORMAT (GET_CODE (*x
));
2811 for (i
= 0; i
< length
; ++i
)
2816 result
= for_each_rtx (&XEXP (*x
, i
), f
, data
);
2823 if (XVEC (*x
, i
) != 0)
2826 for (j
= 0; j
< XVECLEN (*x
, i
); ++j
)
2828 result
= for_each_rtx (&XVECEXP (*x
, i
, j
), f
, data
);
2836 /* Nothing to do. */
2845 /* Searches X for any reference to REGNO, returning the rtx of the
2846 reference found if any. Otherwise, returns NULL_RTX. */
2849 regno_use_in (regno
, x
)
2857 if (GET_CODE (x
) == REG
&& REGNO (x
) == regno
)
2860 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2861 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2865 if ((tem
= regno_use_in (regno
, XEXP (x
, i
))))
2868 else if (fmt
[i
] == 'E')
2869 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2870 if ((tem
= regno_use_in (regno
, XVECEXP (x
, i
, j
))))
2877 /* Return a value indicating whether OP, an operand of a commutative
2878 operation, is preferred as the first or second operand. The higher
2879 the value, the stronger the preference for being the first operand.
2880 We use negative values to indicate a preference for the first operand
2881 and positive values for the second operand. */
2884 commutative_operand_precedence (op
)
2887 /* Constants always come the second operand. Prefer "nice" constants. */
2888 if (GET_CODE (op
) == CONST_INT
)
2890 if (GET_CODE (op
) == CONST_DOUBLE
)
2892 if (CONSTANT_P (op
))
2895 /* SUBREGs of objects should come second. */
2896 if (GET_CODE (op
) == SUBREG
2897 && GET_RTX_CLASS (GET_CODE (SUBREG_REG (op
))) == 'o')
2900 /* If only one operand is a `neg', `not',
2901 `mult', `plus', or `minus' expression, it will be the first
2903 if (GET_CODE (op
) == NEG
|| GET_CODE (op
) == NOT
2904 || GET_CODE (op
) == MULT
|| GET_CODE (op
) == PLUS
2905 || GET_CODE (op
) == MINUS
)
2908 /* Complex expressions should be the first, so decrease priority
2910 if (GET_RTX_CLASS (GET_CODE (op
)) == 'o')
2915 /* Return 1 iff it is necessary to swap operands of commutative operation
2916 in order to canonicalize expression. */
2919 swap_commutative_operands_p (x
, y
)
2922 return (commutative_operand_precedence (x
)
2923 < commutative_operand_precedence (y
));
2926 /* Return 1 if X is an autoincrement side effect and the register is
2927 not the stack pointer. */
2932 switch (GET_CODE (x
))
2940 /* There are no REG_INC notes for SP. */
2941 if (XEXP (x
, 0) != stack_pointer_rtx
)
2949 /* Return 1 if the sequence of instructions beginning with FROM and up
2950 to and including TO is safe to move. If NEW_TO is non-NULL, and
2951 the sequence is not already safe to move, but can be easily
2952 extended to a sequence which is safe, then NEW_TO will point to the
2953 end of the extended sequence.
2955 For now, this function only checks that the region contains whole
2956 exception regions, but it could be extended to check additional
2957 conditions as well. */
2960 insns_safe_to_move_p (from
, to
, new_to
)
2965 int eh_region_count
= 0;
2969 /* By default, assume the end of the region will be what was
2976 if (GET_CODE (r
) == NOTE
)
2978 switch (NOTE_LINE_NUMBER (r
))
2980 case NOTE_INSN_EH_REGION_BEG
:
2984 case NOTE_INSN_EH_REGION_END
:
2985 if (eh_region_count
== 0)
2986 /* This sequence of instructions contains the end of
2987 an exception region, but not he beginning. Moving
2988 it will cause chaos. */
2999 /* If we've passed TO, and we see a non-note instruction, we
3000 can't extend the sequence to a movable sequence. */
3006 /* It's OK to move the sequence if there were matched sets of
3007 exception region notes. */
3008 return eh_region_count
== 0;
3013 /* It's OK to move the sequence if there were matched sets of
3014 exception region notes. */
3015 if (past_to_p
&& eh_region_count
== 0)
3021 /* Go to the next instruction. */
3028 /* Return non-zero if IN contains a piece of rtl that has the address LOC */
3030 loc_mentioned_in_p (loc
, in
)
3033 enum rtx_code code
= GET_CODE (in
);
3034 const char *fmt
= GET_RTX_FORMAT (code
);
3037 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3039 if (loc
== &in
->fld
[i
].rtx
)
3043 if (loc_mentioned_in_p (loc
, XEXP (in
, i
)))
3046 else if (fmt
[i
] == 'E')
3047 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
3048 if (loc_mentioned_in_p (loc
, XVECEXP (in
, i
, j
)))
3054 /* Given a subreg X, return the bit offset where the subreg begins
3055 (counting from the least significant bit of the reg). */
3061 enum machine_mode inner_mode
= GET_MODE (SUBREG_REG (x
));
3062 enum machine_mode mode
= GET_MODE (x
);
3063 unsigned int bitpos
;
3067 /* A paradoxical subreg begins at bit position 0. */
3068 if (GET_MODE_BITSIZE (mode
) > GET_MODE_BITSIZE (inner_mode
))
3071 if (WORDS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
3072 /* If the subreg crosses a word boundary ensure that
3073 it also begins and ends on a word boundary. */
3074 if ((SUBREG_BYTE (x
) % UNITS_PER_WORD
3075 + GET_MODE_SIZE (mode
)) > UNITS_PER_WORD
3076 && (SUBREG_BYTE (x
) % UNITS_PER_WORD
3077 || GET_MODE_SIZE (mode
) % UNITS_PER_WORD
))
3080 if (WORDS_BIG_ENDIAN
)
3081 word
= (GET_MODE_SIZE (inner_mode
)
3082 - (SUBREG_BYTE (x
) + GET_MODE_SIZE (mode
))) / UNITS_PER_WORD
;
3084 word
= SUBREG_BYTE (x
) / UNITS_PER_WORD
;
3085 bitpos
= word
* BITS_PER_WORD
;
3087 if (BYTES_BIG_ENDIAN
)
3088 byte
= (GET_MODE_SIZE (inner_mode
)
3089 - (SUBREG_BYTE (x
) + GET_MODE_SIZE (mode
))) % UNITS_PER_WORD
;
3091 byte
= SUBREG_BYTE (x
) % UNITS_PER_WORD
;
3092 bitpos
+= byte
* BITS_PER_UNIT
;
3097 /* This function returns the regno offset of a subreg expression.
3098 xregno - A regno of an inner hard subreg_reg (or what will become one).
3099 xmode - The mode of xregno.
3100 offset - The byte offset.
3101 ymode - The mode of a top level SUBREG (or what may become one).
3102 RETURN - The regno offset which would be used. */
3104 subreg_regno_offset (xregno
, xmode
, offset
, ymode
)
3105 unsigned int xregno
;
3106 enum machine_mode xmode
;
3107 unsigned int offset
;
3108 enum machine_mode ymode
;
3110 int nregs_xmode
, nregs_ymode
;
3111 int mode_multiple
, nregs_multiple
;
3114 if (xregno
>= FIRST_PSEUDO_REGISTER
)
3117 nregs_xmode
= HARD_REGNO_NREGS (xregno
, xmode
);
3118 nregs_ymode
= HARD_REGNO_NREGS (xregno
, ymode
);
3119 if (offset
== 0 || nregs_xmode
== nregs_ymode
)
3122 /* size of ymode must not be greater than the size of xmode. */
3123 mode_multiple
= GET_MODE_SIZE (xmode
) / GET_MODE_SIZE (ymode
);
3124 if (mode_multiple
== 0)
3127 y_offset
= offset
/ GET_MODE_SIZE (ymode
);
3128 nregs_multiple
= nregs_xmode
/ nregs_ymode
;
3129 return (y_offset
/ (mode_multiple
/ nregs_multiple
)) * nregs_ymode
;
3132 /* Return the final regno that a subreg expression refers to. */
3138 rtx subreg
= SUBREG_REG (x
);
3139 int regno
= REGNO (subreg
);
3141 ret
= regno
+ subreg_regno_offset (regno
,
3148 struct parms_set_data
3154 /* Helper function for noticing stores to parameter registers. */
3156 parms_set (x
, pat
, data
)
3157 rtx x
, pat ATTRIBUTE_UNUSED
;
3160 struct parms_set_data
*d
= data
;
3161 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
3162 && TEST_HARD_REG_BIT (d
->regs
, REGNO (x
)))
3164 CLEAR_HARD_REG_BIT (d
->regs
, REGNO (x
));
3169 /* Look backward for first parameter to be loaded.
3170 Do not skip BOUNDARY. */
3172 find_first_parameter_load (call_insn
, boundary
)
3173 rtx call_insn
, boundary
;
3175 struct parms_set_data parm
;
3178 /* Since different machines initialize their parameter registers
3179 in different orders, assume nothing. Collect the set of all
3180 parameter registers. */
3181 CLEAR_HARD_REG_SET (parm
.regs
);
3183 for (p
= CALL_INSN_FUNCTION_USAGE (call_insn
); p
; p
= XEXP (p
, 1))
3184 if (GET_CODE (XEXP (p
, 0)) == USE
3185 && GET_CODE (XEXP (XEXP (p
, 0), 0)) == REG
)
3187 if (REGNO (XEXP (XEXP (p
, 0), 0)) >= FIRST_PSEUDO_REGISTER
)
3190 /* We only care about registers which can hold function
3192 if (!FUNCTION_ARG_REGNO_P (REGNO (XEXP (XEXP (p
, 0), 0))))
3195 SET_HARD_REG_BIT (parm
.regs
, REGNO (XEXP (XEXP (p
, 0), 0)));
3200 /* Search backward for the first set of a register in this set. */
3201 while (parm
.nregs
&& before
!= boundary
)
3203 before
= PREV_INSN (before
);
3205 /* It is possible that some loads got CSEed from one call to
3206 another. Stop in that case. */
3207 if (GET_CODE (before
) == CALL_INSN
)
3210 /* Our caller needs either ensure that we will find all sets
3211 (in case code has not been optimized yet), or take care
3212 for possible labels in a way by setting boundary to preceding
3214 if (GET_CODE (before
) == CODE_LABEL
)
3216 if (before
!= boundary
)
3221 if (INSN_P (before
))
3222 note_stores (PATTERN (before
), parms_set
, &parm
);
3227 /* Return true if we should avoid inserting code between INSN and preceeding
3228 call instruction. */
3231 keep_with_call_p (insn
)
3236 if (INSN_P (insn
) && (set
= single_set (insn
)) != NULL
)
3238 if (GET_CODE (SET_DEST (set
)) == REG
3239 && fixed_regs
[REGNO (SET_DEST (set
))]
3240 && general_operand (SET_SRC (set
), VOIDmode
))
3242 if (GET_CODE (SET_SRC (set
)) == REG
3243 && FUNCTION_VALUE_REGNO_P (REGNO (SET_SRC (set
)))
3244 && GET_CODE (SET_DEST (set
)) == REG
3245 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
)
3247 /* There may be a stack pop just after the call and before the store
3248 of the return register. Search for the actual store when deciding
3249 if we can break or not. */
3250 if (SET_DEST (set
) == stack_pointer_rtx
)
3252 rtx i2
= next_nonnote_insn (insn
);
3253 if (i2
&& keep_with_call_p (i2
))