1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 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"
36 #include "basic-block.h"
40 /* Forward declarations */
41 static int global_reg_mentioned_p_1 (rtx
*, void *);
42 static void set_of_1 (rtx
, rtx
, void *);
43 static void insn_dependent_p_1 (rtx
, rtx
, void *);
44 static int rtx_referenced_p_1 (rtx
*, void *);
45 static int computed_jump_p_1 (rtx
);
46 static void parms_set (rtx
, rtx
, void *);
47 static bool hoist_test_store (rtx
, rtx
, regset
);
48 static void hoist_update_store (rtx
, rtx
*, rtx
, rtx
);
50 /* Bit flags that specify the machine subtype we are compiling for.
51 Bits are tested using macros TARGET_... defined in the tm.h file
52 and set by `-m...' switches. Must be defined in rtlanal.c. */
56 /* Return 1 if the value of X is unstable
57 (would be different at a different point in the program).
58 The frame pointer, arg pointer, etc. are considered stable
59 (within one function) and so is anything marked `unchanging'. */
62 rtx_unstable_p (rtx x
)
64 RTX_CODE code
= GET_CODE (x
);
71 return ! RTX_UNCHANGING_P (x
) || rtx_unstable_p (XEXP (x
, 0));
86 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
87 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
88 /* The arg pointer varies if it is not a fixed register. */
89 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
])
90 || RTX_UNCHANGING_P (x
))
92 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
93 /* ??? When call-clobbered, the value is stable modulo the restore
94 that must happen after a call. This currently screws up local-alloc
95 into believing that the restore is not needed. */
96 if (x
== pic_offset_table_rtx
)
102 if (MEM_VOLATILE_P (x
))
111 fmt
= GET_RTX_FORMAT (code
);
112 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
115 if (rtx_unstable_p (XEXP (x
, i
)))
118 else if (fmt
[i
] == 'E')
121 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
122 if (rtx_unstable_p (XVECEXP (x
, i
, j
)))
129 /* Return 1 if X has a value that can vary even between two
130 executions of the program. 0 means X can be compared reliably
131 against certain constants or near-constants.
132 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
133 zero, we are slightly more conservative.
134 The frame pointer and the arg pointer are considered constant. */
137 rtx_varies_p (rtx x
, int for_alias
)
150 return ! RTX_UNCHANGING_P (x
) || rtx_varies_p (XEXP (x
, 0), for_alias
);
164 /* This will resolve to some offset from the frame pointer. */
168 /* Note that we have to test for the actual rtx used for the frame
169 and arg pointers and not just the register number in case we have
170 eliminated the frame and/or arg pointer and are using it
172 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
173 /* The arg pointer varies if it is not a fixed register. */
174 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
176 if (x
== pic_offset_table_rtx
177 #ifdef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
178 /* ??? When call-clobbered, the value is stable modulo the restore
179 that must happen after a call. This currently screws up
180 local-alloc into believing that the restore is not needed, so we
181 must return 0 only if we are called from alias analysis. */
189 /* The operand 0 of a LO_SUM is considered constant
190 (in fact it is related specifically to operand 1)
191 during alias analysis. */
192 return (! for_alias
&& rtx_varies_p (XEXP (x
, 0), for_alias
))
193 || rtx_varies_p (XEXP (x
, 1), for_alias
);
196 if (MEM_VOLATILE_P (x
))
205 fmt
= GET_RTX_FORMAT (code
);
206 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
209 if (rtx_varies_p (XEXP (x
, i
), for_alias
))
212 else if (fmt
[i
] == 'E')
215 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
216 if (rtx_varies_p (XVECEXP (x
, i
, j
), for_alias
))
223 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
226 rtx_addr_can_trap_p (rtx x
)
228 enum rtx_code code
= GET_CODE (x
);
233 return SYMBOL_REF_WEAK (x
);
239 /* This will resolve to some offset from the frame pointer. */
243 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
244 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
245 || x
== stack_pointer_rtx
246 /* The arg pointer varies if it is not a fixed register. */
247 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
249 /* All of the virtual frame registers are stack references. */
250 if (REGNO (x
) >= FIRST_VIRTUAL_REGISTER
251 && REGNO (x
) <= LAST_VIRTUAL_REGISTER
)
256 return rtx_addr_can_trap_p (XEXP (x
, 0));
259 /* An address is assumed not to trap if it is an address that can't
260 trap plus a constant integer or it is the pic register plus a
262 return ! ((! rtx_addr_can_trap_p (XEXP (x
, 0))
263 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
264 || (XEXP (x
, 0) == pic_offset_table_rtx
265 && CONSTANT_P (XEXP (x
, 1))));
269 return rtx_addr_can_trap_p (XEXP (x
, 1));
276 return rtx_addr_can_trap_p (XEXP (x
, 0));
282 /* If it isn't one of the case above, it can cause a trap. */
286 /* Return true if X is an address that is known to not be zero. */
289 nonzero_address_p (rtx x
)
291 enum rtx_code code
= GET_CODE (x
);
296 return !SYMBOL_REF_WEAK (x
);
302 /* This will resolve to some offset from the frame pointer. */
306 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
307 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
308 || x
== stack_pointer_rtx
309 || (x
== arg_pointer_rtx
&& fixed_regs
[ARG_POINTER_REGNUM
]))
311 /* All of the virtual frame registers are stack references. */
312 if (REGNO (x
) >= FIRST_VIRTUAL_REGISTER
313 && REGNO (x
) <= LAST_VIRTUAL_REGISTER
)
318 return nonzero_address_p (XEXP (x
, 0));
321 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
323 /* Pointers aren't allowed to wrap. If we've got a register
324 that is known to be a pointer, and a positive offset, then
325 the composite can't be zero. */
326 if (INTVAL (XEXP (x
, 1)) > 0
327 && REG_P (XEXP (x
, 0))
328 && REG_POINTER (XEXP (x
, 0)))
331 return nonzero_address_p (XEXP (x
, 0));
333 /* Handle PIC references. */
334 else if (XEXP (x
, 0) == pic_offset_table_rtx
335 && CONSTANT_P (XEXP (x
, 1)))
340 /* Similar to the above; allow positive offsets. Further, since
341 auto-inc is only allowed in memories, the register must be a
343 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
344 && INTVAL (XEXP (x
, 1)) > 0)
346 return nonzero_address_p (XEXP (x
, 0));
349 /* Similarly. Further, the offset is always positive. */
356 return nonzero_address_p (XEXP (x
, 0));
359 return nonzero_address_p (XEXP (x
, 1));
365 /* If it isn't one of the case above, might be zero. */
369 /* Return 1 if X refers to a memory location whose address
370 cannot be compared reliably with constant addresses,
371 or if X refers to a BLKmode memory object.
372 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
373 zero, we are slightly more conservative. */
376 rtx_addr_varies_p (rtx x
, int 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. */
412 get_integer_term (rtx x
)
414 if (GET_CODE (x
) == CONST
)
417 if (GET_CODE (x
) == MINUS
418 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
419 return - INTVAL (XEXP (x
, 1));
420 if (GET_CODE (x
) == PLUS
421 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
422 return INTVAL (XEXP (x
, 1));
426 /* If X is a constant, return the value sans apparent integer term;
428 Only obvious integer terms are detected. */
431 get_related_value (rtx x
)
433 if (GET_CODE (x
) != CONST
)
436 if (GET_CODE (x
) == PLUS
437 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
439 else if (GET_CODE (x
) == MINUS
440 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
445 /* Given a tablejump insn INSN, return the RTL expression for the offset
446 into the jump table. If the offset cannot be determined, then return
449 If EARLIEST is nonzero, it is a pointer to a place where the earliest
450 insn used in locating the offset was found. */
453 get_jump_table_offset (rtx insn
, rtx
*earliest
)
465 if (!tablejump_p (insn
, &label
, &table
) || !(set
= single_set (insn
)))
470 /* Some targets (eg, ARM) emit a tablejump that also
471 contains the out-of-range target. */
472 if (GET_CODE (x
) == IF_THEN_ELSE
473 && GET_CODE (XEXP (x
, 2)) == LABEL_REF
)
476 /* Search backwards and locate the expression stored in X. */
477 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
478 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
481 /* If X is an expression using a relative address then strip
482 off the addition / subtraction of PC, PIC_OFFSET_TABLE_REGNUM,
483 or the jump table label. */
484 if (GET_CODE (PATTERN (table
)) == ADDR_DIFF_VEC
485 && (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
))
487 for (i
= 0; i
< 2; i
++)
492 if (y
== pc_rtx
|| y
== pic_offset_table_rtx
)
495 for (old_y
= NULL_RTX
; GET_CODE (y
) == REG
&& y
!= old_y
;
496 old_y
= y
, y
= find_last_value (y
, &old_insn
, NULL_RTX
, 0))
499 if ((GET_CODE (y
) == LABEL_REF
&& XEXP (y
, 0) == label
))
508 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
509 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
513 /* Strip off any sign or zero extension. */
514 if (GET_CODE (x
) == SIGN_EXTEND
|| GET_CODE (x
) == ZERO_EXTEND
)
518 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
519 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
523 /* If X isn't a MEM then this isn't a tablejump we understand. */
524 if (GET_CODE (x
) != MEM
)
527 /* Strip off the MEM. */
530 for (old_x
= NULL_RTX
; GET_CODE (x
) == REG
&& x
!= old_x
;
531 old_x
= x
, x
= find_last_value (x
, &insn
, NULL_RTX
, 0))
534 /* If X isn't a PLUS than this isn't a tablejump we understand. */
535 if (GET_CODE (x
) != PLUS
)
538 /* At this point we should have an expression representing the jump table
539 plus an offset. Examine each operand in order to determine which one
540 represents the jump table. Knowing that tells us that the other operand
541 must represent the offset. */
542 for (i
= 0; i
< 2; i
++)
547 for (old_y
= NULL_RTX
; GET_CODE (y
) == REG
&& y
!= old_y
;
548 old_y
= y
, y
= find_last_value (y
, &old_insn
, NULL_RTX
, 0))
551 if ((GET_CODE (y
) == CONST
|| GET_CODE (y
) == LABEL_REF
)
552 && reg_mentioned_p (label
, y
))
561 /* Strip off the addition / subtraction of PIC_OFFSET_TABLE_REGNUM. */
562 if (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
)
563 for (i
= 0; i
< 2; i
++)
564 if (XEXP (x
, i
) == pic_offset_table_rtx
)
573 /* Return the RTL expression representing the offset. */
577 /* A subroutine of global_reg_mentioned_p, returns 1 if *LOC mentions
578 a global register. */
581 global_reg_mentioned_p_1 (rtx
*loc
, void *data ATTRIBUTE_UNUSED
)
589 switch (GET_CODE (x
))
592 if (GET_CODE (SUBREG_REG (x
)) == REG
)
594 if (REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
595 && global_regs
[subreg_regno (x
)])
603 if (regno
< FIRST_PSEUDO_REGISTER
&& global_regs
[regno
])
617 /* A non-constant call might use a global register. */
627 /* Returns nonzero if X mentions a global register. */
630 global_reg_mentioned_p (rtx x
)
634 if (GET_CODE (x
) == CALL_INSN
)
636 if (! CONST_OR_PURE_CALL_P (x
))
638 x
= CALL_INSN_FUNCTION_USAGE (x
);
646 return for_each_rtx (&x
, global_reg_mentioned_p_1
, NULL
);
649 /* Return the number of places FIND appears within X. If COUNT_DEST is
650 zero, we do not count occurrences inside the destination of a SET. */
653 count_occurrences (rtx x
, rtx find
, int count_dest
)
657 const char *format_ptr
;
678 if (GET_CODE (find
) == MEM
&& rtx_equal_p (x
, find
))
683 if (SET_DEST (x
) == find
&& ! count_dest
)
684 return count_occurrences (SET_SRC (x
), find
, count_dest
);
691 format_ptr
= GET_RTX_FORMAT (code
);
694 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
696 switch (*format_ptr
++)
699 count
+= count_occurrences (XEXP (x
, i
), find
, count_dest
);
703 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
704 count
+= count_occurrences (XVECEXP (x
, i
, j
), find
, count_dest
);
711 /* Nonzero if register REG appears somewhere within IN.
712 Also works if REG is not a register; in this case it checks
713 for a subexpression of IN that is Lisp "equal" to REG. */
716 reg_mentioned_p (rtx reg
, rtx in
)
728 if (GET_CODE (in
) == LABEL_REF
)
729 return reg
== XEXP (in
, 0);
731 code
= GET_CODE (in
);
735 /* Compare registers by number. */
737 return GET_CODE (reg
) == REG
&& REGNO (in
) == REGNO (reg
);
739 /* These codes have no constituent expressions
749 /* These are kept unique for a given value. */
756 if (GET_CODE (reg
) == code
&& rtx_equal_p (reg
, in
))
759 fmt
= GET_RTX_FORMAT (code
);
761 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
766 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
767 if (reg_mentioned_p (reg
, XVECEXP (in
, i
, j
)))
770 else if (fmt
[i
] == 'e'
771 && reg_mentioned_p (reg
, XEXP (in
, i
)))
777 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
778 no CODE_LABEL insn. */
781 no_labels_between_p (rtx beg
, rtx end
)
786 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
787 if (GET_CODE (p
) == CODE_LABEL
)
792 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
793 no JUMP_INSN insn. */
796 no_jumps_between_p (rtx beg
, rtx end
)
799 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
800 if (GET_CODE (p
) == JUMP_INSN
)
805 /* Nonzero if register REG is used in an insn between
806 FROM_INSN and TO_INSN (exclusive of those two). */
809 reg_used_between_p (rtx reg
, rtx from_insn
, rtx to_insn
)
813 if (from_insn
== to_insn
)
816 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
818 && (reg_overlap_mentioned_p (reg
, PATTERN (insn
))
819 || (GET_CODE (insn
) == CALL_INSN
820 && (find_reg_fusage (insn
, USE
, reg
)
821 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
826 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
827 is entirely replaced by a new value and the only use is as a SET_DEST,
828 we do not consider it a reference. */
831 reg_referenced_p (rtx x
, rtx body
)
835 switch (GET_CODE (body
))
838 if (reg_overlap_mentioned_p (x
, SET_SRC (body
)))
841 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
842 of a REG that occupies all of the REG, the insn references X if
843 it is mentioned in the destination. */
844 if (GET_CODE (SET_DEST (body
)) != CC0
845 && GET_CODE (SET_DEST (body
)) != PC
846 && GET_CODE (SET_DEST (body
)) != REG
847 && ! (GET_CODE (SET_DEST (body
)) == SUBREG
848 && GET_CODE (SUBREG_REG (SET_DEST (body
))) == REG
849 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body
))))
850 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
851 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body
)))
852 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)))
853 && reg_overlap_mentioned_p (x
, SET_DEST (body
)))
858 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
859 if (reg_overlap_mentioned_p (x
, ASM_OPERANDS_INPUT (body
, i
)))
866 return reg_overlap_mentioned_p (x
, body
);
869 return reg_overlap_mentioned_p (x
, TRAP_CONDITION (body
));
872 return reg_overlap_mentioned_p (x
, XEXP (body
, 0));
875 case UNSPEC_VOLATILE
:
876 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
877 if (reg_overlap_mentioned_p (x
, XVECEXP (body
, 0, i
)))
882 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
883 if (reg_referenced_p (x
, XVECEXP (body
, 0, i
)))
888 if (GET_CODE (XEXP (body
, 0)) == MEM
)
889 if (reg_overlap_mentioned_p (x
, XEXP (XEXP (body
, 0), 0)))
894 if (reg_overlap_mentioned_p (x
, COND_EXEC_TEST (body
)))
896 return reg_referenced_p (x
, COND_EXEC_CODE (body
));
903 /* Nonzero if register REG is referenced in an insn between
904 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
908 reg_referenced_between_p (rtx reg
, rtx from_insn
, rtx to_insn
)
912 if (from_insn
== to_insn
)
915 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
917 && (reg_referenced_p (reg
, PATTERN (insn
))
918 || (GET_CODE (insn
) == CALL_INSN
919 && find_reg_fusage (insn
, USE
, reg
))))
924 /* Nonzero if register REG is set or clobbered in an insn between
925 FROM_INSN and TO_INSN (exclusive of those two). */
928 reg_set_between_p (rtx reg
, rtx from_insn
, rtx to_insn
)
932 if (from_insn
== to_insn
)
935 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
936 if (INSN_P (insn
) && reg_set_p (reg
, insn
))
941 /* Internals of reg_set_between_p. */
943 reg_set_p (rtx reg
, rtx insn
)
945 /* We can be passed an insn or part of one. If we are passed an insn,
946 check if a side-effect of the insn clobbers REG. */
948 && (FIND_REG_INC_NOTE (insn
, reg
)
949 || (GET_CODE (insn
) == CALL_INSN
950 /* We'd like to test call_used_regs here, but rtlanal.c can't
951 reference that variable due to its use in genattrtab. So
952 we'll just be more conservative.
954 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
955 information holds all clobbered registers. */
956 && ((GET_CODE (reg
) == REG
957 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
958 || GET_CODE (reg
) == MEM
959 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
962 return set_of (reg
, insn
) != NULL_RTX
;
965 /* Similar to reg_set_between_p, but check all registers in X. Return 0
966 only if none of them are modified between START and END. Do not
967 consider non-registers one way or the other. */
970 regs_set_between_p (rtx x
, rtx start
, rtx end
)
972 enum rtx_code code
= GET_CODE (x
);
989 return reg_set_between_p (x
, start
, end
);
995 fmt
= GET_RTX_FORMAT (code
);
996 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
998 if (fmt
[i
] == 'e' && regs_set_between_p (XEXP (x
, i
), start
, end
))
1001 else if (fmt
[i
] == 'E')
1002 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1003 if (regs_set_between_p (XVECEXP (x
, i
, j
), start
, end
))
1010 /* Similar to reg_set_between_p, but check all registers in X. Return 0
1011 only if none of them are modified between START and END. Return 1 if
1012 X contains a MEM; this routine does usememory aliasing. */
1015 modified_between_p (rtx x
, rtx start
, rtx end
)
1017 enum rtx_code code
= GET_CODE (x
);
1040 if (RTX_UNCHANGING_P (x
))
1042 if (modified_between_p (XEXP (x
, 0), start
, end
))
1044 for (insn
= NEXT_INSN (start
); insn
!= end
; insn
= NEXT_INSN (insn
))
1045 if (memory_modified_in_insn_p (x
, insn
))
1051 return reg_set_between_p (x
, start
, end
);
1057 fmt
= GET_RTX_FORMAT (code
);
1058 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1060 if (fmt
[i
] == 'e' && modified_between_p (XEXP (x
, i
), start
, end
))
1063 else if (fmt
[i
] == 'E')
1064 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1065 if (modified_between_p (XVECEXP (x
, i
, j
), start
, end
))
1072 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
1073 of them are modified in INSN. Return 1 if X contains a MEM; this routine
1074 does use memory aliasing. */
1077 modified_in_p (rtx x
, rtx insn
)
1079 enum rtx_code code
= GET_CODE (x
);
1098 if (RTX_UNCHANGING_P (x
))
1100 if (modified_in_p (XEXP (x
, 0), insn
))
1102 if (memory_modified_in_insn_p (x
, insn
))
1108 return reg_set_p (x
, insn
);
1114 fmt
= GET_RTX_FORMAT (code
);
1115 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1117 if (fmt
[i
] == 'e' && modified_in_p (XEXP (x
, i
), insn
))
1120 else if (fmt
[i
] == 'E')
1121 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1122 if (modified_in_p (XVECEXP (x
, i
, j
), insn
))
1129 /* Return true if anything in insn X is (anti,output,true) dependent on
1130 anything in insn Y. */
1133 insn_dependent_p (rtx x
, rtx y
)
1137 if (! INSN_P (x
) || ! INSN_P (y
))
1141 note_stores (PATTERN (x
), insn_dependent_p_1
, &tmp
);
1142 if (tmp
== NULL_RTX
)
1146 note_stores (PATTERN (y
), insn_dependent_p_1
, &tmp
);
1147 if (tmp
== NULL_RTX
)
1153 /* A helper routine for insn_dependent_p called through note_stores. */
1156 insn_dependent_p_1 (rtx x
, rtx pat ATTRIBUTE_UNUSED
, void *data
)
1158 rtx
* pinsn
= (rtx
*) data
;
1160 if (*pinsn
&& reg_mentioned_p (x
, *pinsn
))
1164 /* Helper function for set_of. */
1172 set_of_1 (rtx x
, rtx pat
, void *data1
)
1174 struct set_of_data
*data
= (struct set_of_data
*) (data1
);
1175 if (rtx_equal_p (x
, data
->pat
)
1176 || (GET_CODE (x
) != MEM
&& reg_overlap_mentioned_p (data
->pat
, x
)))
1180 /* Give an INSN, return a SET or CLOBBER expression that does modify PAT
1181 (either directly or via STRICT_LOW_PART and similar modifiers). */
1183 set_of (rtx pat
, rtx insn
)
1185 struct set_of_data data
;
1186 data
.found
= NULL_RTX
;
1188 note_stores (INSN_P (insn
) ? PATTERN (insn
) : insn
, set_of_1
, &data
);
1192 /* Given an INSN, return a SET expression if this insn has only a single SET.
1193 It may also have CLOBBERs, USEs, or SET whose output
1194 will not be used, which we ignore. */
1197 single_set_2 (rtx insn
, rtx pat
)
1200 int set_verified
= 1;
1203 if (GET_CODE (pat
) == PARALLEL
)
1205 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1207 rtx sub
= XVECEXP (pat
, 0, i
);
1208 switch (GET_CODE (sub
))
1215 /* We can consider insns having multiple sets, where all
1216 but one are dead as single set insns. In common case
1217 only single set is present in the pattern so we want
1218 to avoid checking for REG_UNUSED notes unless necessary.
1220 When we reach set first time, we just expect this is
1221 the single set we are looking for and only when more
1222 sets are found in the insn, we check them. */
1225 if (find_reg_note (insn
, REG_UNUSED
, SET_DEST (set
))
1226 && !side_effects_p (set
))
1232 set
= sub
, set_verified
= 0;
1233 else if (!find_reg_note (insn
, REG_UNUSED
, SET_DEST (sub
))
1234 || side_effects_p (sub
))
1246 /* Given an INSN, return nonzero if it has more than one SET, else return
1250 multiple_sets (rtx insn
)
1255 /* INSN must be an insn. */
1256 if (! INSN_P (insn
))
1259 /* Only a PARALLEL can have multiple SETs. */
1260 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1262 for (i
= 0, found
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
1263 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1265 /* If we have already found a SET, then return now. */
1273 /* Either zero or one SET. */
1277 /* Return nonzero if the destination of SET equals the source
1278 and there are no side effects. */
1281 set_noop_p (rtx set
)
1283 rtx src
= SET_SRC (set
);
1284 rtx dst
= SET_DEST (set
);
1286 if (dst
== pc_rtx
&& src
== pc_rtx
)
1289 if (GET_CODE (dst
) == MEM
&& GET_CODE (src
) == MEM
)
1290 return rtx_equal_p (dst
, src
) && !side_effects_p (dst
);
1292 if (GET_CODE (dst
) == SIGN_EXTRACT
1293 || GET_CODE (dst
) == ZERO_EXTRACT
)
1294 return rtx_equal_p (XEXP (dst
, 0), src
)
1295 && ! BYTES_BIG_ENDIAN
&& XEXP (dst
, 2) == const0_rtx
1296 && !side_effects_p (src
);
1298 if (GET_CODE (dst
) == STRICT_LOW_PART
)
1299 dst
= XEXP (dst
, 0);
1301 if (GET_CODE (src
) == SUBREG
&& GET_CODE (dst
) == SUBREG
)
1303 if (SUBREG_BYTE (src
) != SUBREG_BYTE (dst
))
1305 src
= SUBREG_REG (src
);
1306 dst
= SUBREG_REG (dst
);
1309 return (GET_CODE (src
) == REG
&& GET_CODE (dst
) == REG
1310 && REGNO (src
) == REGNO (dst
));
1313 /* Return nonzero if an insn consists only of SETs, each of which only sets a
1317 noop_move_p (rtx insn
)
1319 rtx pat
= PATTERN (insn
);
1321 if (INSN_CODE (insn
) == NOOP_MOVE_INSN_CODE
)
1324 /* Insns carrying these notes are useful later on. */
1325 if (find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
1328 /* For now treat an insn with a REG_RETVAL note as a
1329 a special insn which should not be considered a no-op. */
1330 if (find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
1333 if (GET_CODE (pat
) == SET
&& set_noop_p (pat
))
1336 if (GET_CODE (pat
) == PARALLEL
)
1339 /* If nothing but SETs of registers to themselves,
1340 this insn can also be deleted. */
1341 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1343 rtx tem
= XVECEXP (pat
, 0, i
);
1345 if (GET_CODE (tem
) == USE
1346 || GET_CODE (tem
) == CLOBBER
)
1349 if (GET_CODE (tem
) != SET
|| ! set_noop_p (tem
))
1359 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
1360 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
1361 If the object was modified, if we hit a partial assignment to X, or hit a
1362 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
1363 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
1367 find_last_value (rtx x
, rtx
*pinsn
, rtx valid_to
, int allow_hwreg
)
1371 for (p
= PREV_INSN (*pinsn
); p
&& GET_CODE (p
) != CODE_LABEL
;
1375 rtx set
= single_set (p
);
1376 rtx note
= find_reg_note (p
, REG_EQUAL
, NULL_RTX
);
1378 if (set
&& rtx_equal_p (x
, SET_DEST (set
)))
1380 rtx src
= SET_SRC (set
);
1382 if (note
&& GET_CODE (XEXP (note
, 0)) != EXPR_LIST
)
1383 src
= XEXP (note
, 0);
1385 if ((valid_to
== NULL_RTX
1386 || ! modified_between_p (src
, PREV_INSN (p
), valid_to
))
1387 /* Reject hard registers because we don't usually want
1388 to use them; we'd rather use a pseudo. */
1389 && (! (GET_CODE (src
) == REG
1390 && REGNO (src
) < FIRST_PSEUDO_REGISTER
) || allow_hwreg
))
1397 /* If set in non-simple way, we don't have a value. */
1398 if (reg_set_p (x
, p
))
1405 /* Return nonzero if register in range [REGNO, ENDREGNO)
1406 appears either explicitly or implicitly in X
1407 other than being stored into.
1409 References contained within the substructure at LOC do not count.
1410 LOC may be zero, meaning don't ignore anything. */
1413 refers_to_regno_p (unsigned int regno
, unsigned int endregno
, rtx x
,
1417 unsigned int x_regno
;
1422 /* The contents of a REG_NONNEG note is always zero, so we must come here
1423 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
1427 code
= GET_CODE (x
);
1432 x_regno
= REGNO (x
);
1434 /* If we modifying the stack, frame, or argument pointer, it will
1435 clobber a virtual register. In fact, we could be more precise,
1436 but it isn't worth it. */
1437 if ((x_regno
== STACK_POINTER_REGNUM
1438 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1439 || x_regno
== ARG_POINTER_REGNUM
1441 || x_regno
== FRAME_POINTER_REGNUM
)
1442 && regno
>= FIRST_VIRTUAL_REGISTER
&& regno
<= LAST_VIRTUAL_REGISTER
)
1445 return (endregno
> x_regno
1446 && regno
< x_regno
+ (x_regno
< FIRST_PSEUDO_REGISTER
1447 ? hard_regno_nregs
[x_regno
][GET_MODE (x
)]
1451 /* If this is a SUBREG of a hard reg, we can see exactly which
1452 registers are being modified. Otherwise, handle normally. */
1453 if (GET_CODE (SUBREG_REG (x
)) == REG
1454 && REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
)
1456 unsigned int inner_regno
= subreg_regno (x
);
1457 unsigned int inner_endregno
1458 = inner_regno
+ (inner_regno
< FIRST_PSEUDO_REGISTER
1459 ? hard_regno_nregs
[inner_regno
][GET_MODE (x
)] : 1);
1461 return endregno
> inner_regno
&& regno
< inner_endregno
;
1467 if (&SET_DEST (x
) != loc
1468 /* Note setting a SUBREG counts as referring to the REG it is in for
1469 a pseudo but not for hard registers since we can
1470 treat each word individually. */
1471 && ((GET_CODE (SET_DEST (x
)) == SUBREG
1472 && loc
!= &SUBREG_REG (SET_DEST (x
))
1473 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
1474 && REGNO (SUBREG_REG (SET_DEST (x
))) >= FIRST_PSEUDO_REGISTER
1475 && refers_to_regno_p (regno
, endregno
,
1476 SUBREG_REG (SET_DEST (x
)), loc
))
1477 || (GET_CODE (SET_DEST (x
)) != REG
1478 && refers_to_regno_p (regno
, endregno
, SET_DEST (x
), loc
))))
1481 if (code
== CLOBBER
|| loc
== &SET_SRC (x
))
1490 /* X does not match, so try its subexpressions. */
1492 fmt
= GET_RTX_FORMAT (code
);
1493 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1495 if (fmt
[i
] == 'e' && loc
!= &XEXP (x
, i
))
1503 if (refers_to_regno_p (regno
, endregno
, XEXP (x
, i
), loc
))
1506 else if (fmt
[i
] == 'E')
1509 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1510 if (loc
!= &XVECEXP (x
, i
, j
)
1511 && refers_to_regno_p (regno
, endregno
, XVECEXP (x
, i
, j
), loc
))
1518 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
1519 we check if any register number in X conflicts with the relevant register
1520 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
1521 contains a MEM (we don't bother checking for memory addresses that can't
1522 conflict because we expect this to be a rare case. */
1525 reg_overlap_mentioned_p (rtx x
, rtx in
)
1527 unsigned int regno
, endregno
;
1529 /* If either argument is a constant, then modifying X can not
1530 affect IN. Here we look at IN, we can profitably combine
1531 CONSTANT_P (x) with the switch statement below. */
1532 if (CONSTANT_P (in
))
1536 switch (GET_CODE (x
))
1538 case STRICT_LOW_PART
:
1541 /* Overly conservative. */
1546 regno
= REGNO (SUBREG_REG (x
));
1547 if (regno
< FIRST_PSEUDO_REGISTER
)
1548 regno
= subreg_regno (x
);
1554 endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
1555 ? hard_regno_nregs
[regno
][GET_MODE (x
)] : 1);
1556 return refers_to_regno_p (regno
, endregno
, in
, (rtx
*) 0);
1563 if (GET_CODE (in
) == MEM
)
1566 fmt
= GET_RTX_FORMAT (GET_CODE (in
));
1567 for (i
= GET_RTX_LENGTH (GET_CODE (in
)) - 1; i
>= 0; i
--)
1568 if (fmt
[i
] == 'e' && reg_overlap_mentioned_p (x
, XEXP (in
, i
)))
1577 return reg_mentioned_p (x
, in
);
1583 /* If any register in here refers to it we return true. */
1584 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1585 if (XEXP (XVECEXP (x
, 0, i
), 0) != 0
1586 && reg_overlap_mentioned_p (XEXP (XVECEXP (x
, 0, i
), 0), in
))
1592 #ifdef ENABLE_CHECKING
1593 if (!CONSTANT_P (x
))
1601 /* Return the last value to which REG was set prior to INSN. If we can't
1602 find it easily, return 0.
1604 We only return a REG, SUBREG, or constant because it is too hard to
1605 check if a MEM remains unchanged. */
1608 reg_set_last (rtx x
, rtx insn
)
1610 rtx orig_insn
= insn
;
1612 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1613 Stop when we reach a label or X is a hard reg and we reach a
1614 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1616 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1618 /* We compare with <= here, because reg_set_last_last_regno
1619 is actually the number of the first reg *not* in X. */
1621 insn
&& GET_CODE (insn
) != CODE_LABEL
1622 && ! (GET_CODE (insn
) == CALL_INSN
1623 && REGNO (x
) <= FIRST_PSEUDO_REGISTER
);
1624 insn
= PREV_INSN (insn
))
1627 rtx set
= set_of (x
, insn
);
1628 /* OK, this function modify our register. See if we understand it. */
1632 if (GET_CODE (set
) != SET
|| SET_DEST (set
) != x
)
1634 last_value
= SET_SRC (x
);
1635 if (CONSTANT_P (last_value
)
1636 || ((GET_CODE (last_value
) == REG
1637 || GET_CODE (last_value
) == SUBREG
)
1638 && ! reg_set_between_p (last_value
,
1649 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1650 (X would be the pattern of an insn).
1651 FUN receives two arguments:
1652 the REG, MEM, CC0 or PC being stored in or clobbered,
1653 the SET or CLOBBER rtx that does the store.
1655 If the item being stored in or clobbered is a SUBREG of a hard register,
1656 the SUBREG will be passed. */
1659 note_stores (rtx x
, void (*fun
) (rtx
, rtx
, void *), void *data
)
1663 if (GET_CODE (x
) == COND_EXEC
)
1664 x
= COND_EXEC_CODE (x
);
1666 if (GET_CODE (x
) == SET
|| GET_CODE (x
) == CLOBBER
)
1668 rtx dest
= SET_DEST (x
);
1670 while ((GET_CODE (dest
) == SUBREG
1671 && (GET_CODE (SUBREG_REG (dest
)) != REG
1672 || REGNO (SUBREG_REG (dest
)) >= FIRST_PSEUDO_REGISTER
))
1673 || GET_CODE (dest
) == ZERO_EXTRACT
1674 || GET_CODE (dest
) == SIGN_EXTRACT
1675 || GET_CODE (dest
) == STRICT_LOW_PART
)
1676 dest
= XEXP (dest
, 0);
1678 /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions,
1679 each of whose first operand is a register. */
1680 if (GET_CODE (dest
) == PARALLEL
)
1682 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1683 if (XEXP (XVECEXP (dest
, 0, i
), 0) != 0)
1684 (*fun
) (XEXP (XVECEXP (dest
, 0, i
), 0), x
, data
);
1687 (*fun
) (dest
, x
, data
);
1690 else if (GET_CODE (x
) == PARALLEL
)
1691 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1692 note_stores (XVECEXP (x
, 0, i
), fun
, data
);
1695 /* Like notes_stores, but call FUN for each expression that is being
1696 referenced in PBODY, a pointer to the PATTERN of an insn. We only call
1697 FUN for each expression, not any interior subexpressions. FUN receives a
1698 pointer to the expression and the DATA passed to this function.
1700 Note that this is not quite the same test as that done in reg_referenced_p
1701 since that considers something as being referenced if it is being
1702 partially set, while we do not. */
1705 note_uses (rtx
*pbody
, void (*fun
) (rtx
*, void *), void *data
)
1710 switch (GET_CODE (body
))
1713 (*fun
) (&COND_EXEC_TEST (body
), data
);
1714 note_uses (&COND_EXEC_CODE (body
), fun
, data
);
1718 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
1719 note_uses (&XVECEXP (body
, 0, i
), fun
, data
);
1723 (*fun
) (&XEXP (body
, 0), data
);
1727 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
1728 (*fun
) (&ASM_OPERANDS_INPUT (body
, i
), data
);
1732 (*fun
) (&TRAP_CONDITION (body
), data
);
1736 (*fun
) (&XEXP (body
, 0), data
);
1740 case UNSPEC_VOLATILE
:
1741 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
1742 (*fun
) (&XVECEXP (body
, 0, i
), data
);
1746 if (GET_CODE (XEXP (body
, 0)) == MEM
)
1747 (*fun
) (&XEXP (XEXP (body
, 0), 0), data
);
1752 rtx dest
= SET_DEST (body
);
1754 /* For sets we replace everything in source plus registers in memory
1755 expression in store and operands of a ZERO_EXTRACT. */
1756 (*fun
) (&SET_SRC (body
), data
);
1758 if (GET_CODE (dest
) == ZERO_EXTRACT
)
1760 (*fun
) (&XEXP (dest
, 1), data
);
1761 (*fun
) (&XEXP (dest
, 2), data
);
1764 while (GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
)
1765 dest
= XEXP (dest
, 0);
1767 if (GET_CODE (dest
) == MEM
)
1768 (*fun
) (&XEXP (dest
, 0), data
);
1773 /* All the other possibilities never store. */
1774 (*fun
) (pbody
, data
);
1779 /* Return nonzero if X's old contents don't survive after INSN.
1780 This will be true if X is (cc0) or if X is a register and
1781 X dies in INSN or because INSN entirely sets X.
1783 "Entirely set" means set directly and not through a SUBREG,
1784 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1785 Likewise, REG_INC does not count.
1787 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1788 but for this use that makes no difference, since regs don't overlap
1789 during their lifetimes. Therefore, this function may be used
1790 at any time after deaths have been computed (in flow.c).
1792 If REG is a hard reg that occupies multiple machine registers, this
1793 function will only return 1 if each of those registers will be replaced
1797 dead_or_set_p (rtx insn
, rtx x
)
1799 unsigned int regno
, last_regno
;
1802 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1803 if (GET_CODE (x
) == CC0
)
1806 if (GET_CODE (x
) != REG
)
1810 last_regno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
1811 : regno
+ hard_regno_nregs
[regno
][GET_MODE (x
)] - 1);
1813 for (i
= regno
; i
<= last_regno
; i
++)
1814 if (! dead_or_set_regno_p (insn
, i
))
1820 /* Utility function for dead_or_set_p to check an individual register. Also
1821 called from flow.c. */
1824 dead_or_set_regno_p (rtx insn
, unsigned int test_regno
)
1826 unsigned int regno
, endregno
;
1829 /* See if there is a death note for something that includes TEST_REGNO. */
1830 if (find_regno_note (insn
, REG_DEAD
, test_regno
))
1833 if (GET_CODE (insn
) == CALL_INSN
1834 && find_regno_fusage (insn
, CLOBBER
, test_regno
))
1837 pattern
= PATTERN (insn
);
1839 if (GET_CODE (pattern
) == COND_EXEC
)
1840 pattern
= COND_EXEC_CODE (pattern
);
1842 if (GET_CODE (pattern
) == SET
)
1844 rtx dest
= SET_DEST (pattern
);
1846 /* A value is totally replaced if it is the destination or the
1847 destination is a SUBREG of REGNO that does not change the number of
1849 if (GET_CODE (dest
) == SUBREG
1850 && (((GET_MODE_SIZE (GET_MODE (dest
))
1851 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1852 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1853 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1854 dest
= SUBREG_REG (dest
);
1856 if (GET_CODE (dest
) != REG
)
1859 regno
= REGNO (dest
);
1860 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1861 : regno
+ hard_regno_nregs
[regno
][GET_MODE (dest
)]);
1863 return (test_regno
>= regno
&& test_regno
< endregno
);
1865 else if (GET_CODE (pattern
) == PARALLEL
)
1869 for (i
= XVECLEN (pattern
, 0) - 1; i
>= 0; i
--)
1871 rtx body
= XVECEXP (pattern
, 0, i
);
1873 if (GET_CODE (body
) == COND_EXEC
)
1874 body
= COND_EXEC_CODE (body
);
1876 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == CLOBBER
)
1878 rtx dest
= SET_DEST (body
);
1880 if (GET_CODE (dest
) == SUBREG
1881 && (((GET_MODE_SIZE (GET_MODE (dest
))
1882 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1883 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1884 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1885 dest
= SUBREG_REG (dest
);
1887 if (GET_CODE (dest
) != REG
)
1890 regno
= REGNO (dest
);
1891 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1892 : regno
+ hard_regno_nregs
[regno
][GET_MODE (dest
)]);
1894 if (test_regno
>= regno
&& test_regno
< endregno
)
1903 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1904 If DATUM is nonzero, look for one whose datum is DATUM. */
1907 find_reg_note (rtx insn
, enum reg_note kind
, rtx datum
)
1911 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1912 if (! INSN_P (insn
))
1915 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1916 if (REG_NOTE_KIND (link
) == kind
1917 && (datum
== 0 || datum
== XEXP (link
, 0)))
1922 /* Return the reg-note of kind KIND in insn INSN which applies to register
1923 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1924 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1925 it might be the case that the note overlaps REGNO. */
1928 find_regno_note (rtx insn
, enum reg_note kind
, unsigned int regno
)
1932 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1933 if (! INSN_P (insn
))
1936 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1937 if (REG_NOTE_KIND (link
) == kind
1938 /* Verify that it is a register, so that scratch and MEM won't cause a
1940 && GET_CODE (XEXP (link
, 0)) == REG
1941 && REGNO (XEXP (link
, 0)) <= regno
1942 && ((REGNO (XEXP (link
, 0))
1943 + (REGNO (XEXP (link
, 0)) >= FIRST_PSEUDO_REGISTER
? 1
1944 : hard_regno_nregs
[REGNO (XEXP (link
, 0))]
1945 [GET_MODE (XEXP (link
, 0))]))
1951 /* Return a REG_EQUIV or REG_EQUAL note if insn has only a single set and
1955 find_reg_equal_equiv_note (rtx insn
)
1961 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1962 if (REG_NOTE_KIND (link
) == REG_EQUAL
1963 || REG_NOTE_KIND (link
) == REG_EQUIV
)
1965 if (single_set (insn
) == 0)
1972 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1973 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1976 find_reg_fusage (rtx insn
, enum rtx_code code
, rtx datum
)
1978 /* If it's not a CALL_INSN, it can't possibly have a
1979 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1980 if (GET_CODE (insn
) != CALL_INSN
)
1986 if (GET_CODE (datum
) != REG
)
1990 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1992 link
= XEXP (link
, 1))
1993 if (GET_CODE (XEXP (link
, 0)) == code
1994 && rtx_equal_p (datum
, XEXP (XEXP (link
, 0), 0)))
1999 unsigned int regno
= REGNO (datum
);
2001 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
2002 to pseudo registers, so don't bother checking. */
2004 if (regno
< FIRST_PSEUDO_REGISTER
)
2006 unsigned int end_regno
2007 = regno
+ hard_regno_nregs
[regno
][GET_MODE (datum
)];
2010 for (i
= regno
; i
< end_regno
; i
++)
2011 if (find_regno_fusage (insn
, code
, i
))
2019 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
2020 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
2023 find_regno_fusage (rtx insn
, enum rtx_code code
, unsigned int regno
)
2027 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
2028 to pseudo registers, so don't bother checking. */
2030 if (regno
>= FIRST_PSEUDO_REGISTER
2031 || GET_CODE (insn
) != CALL_INSN
)
2034 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2036 unsigned int regnote
;
2039 if (GET_CODE (op
= XEXP (link
, 0)) == code
2040 && GET_CODE (reg
= XEXP (op
, 0)) == REG
2041 && (regnote
= REGNO (reg
)) <= regno
2042 && regnote
+ hard_regno_nregs
[regnote
][GET_MODE (reg
)] > regno
)
2049 /* Return true if INSN is a call to a pure function. */
2052 pure_call_p (rtx insn
)
2056 if (GET_CODE (insn
) != CALL_INSN
|| ! CONST_OR_PURE_CALL_P (insn
))
2059 /* Look for the note that differentiates const and pure functions. */
2060 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2064 if (GET_CODE (u
= XEXP (link
, 0)) == USE
2065 && GET_CODE (m
= XEXP (u
, 0)) == MEM
&& GET_MODE (m
) == BLKmode
2066 && GET_CODE (XEXP (m
, 0)) == SCRATCH
)
2073 /* Remove register note NOTE from the REG_NOTES of INSN. */
2076 remove_note (rtx insn
, rtx note
)
2080 if (note
== NULL_RTX
)
2083 if (REG_NOTES (insn
) == note
)
2085 REG_NOTES (insn
) = XEXP (note
, 1);
2089 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2090 if (XEXP (link
, 1) == note
)
2092 XEXP (link
, 1) = XEXP (note
, 1);
2099 /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
2100 return 1 if it is found. A simple equality test is used to determine if
2104 in_expr_list_p (rtx listp
, rtx node
)
2108 for (x
= listp
; x
; x
= XEXP (x
, 1))
2109 if (node
== XEXP (x
, 0))
2115 /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
2116 remove that entry from the list if it is found.
2118 A simple equality test is used to determine if NODE matches. */
2121 remove_node_from_expr_list (rtx node
, rtx
*listp
)
2124 rtx prev
= NULL_RTX
;
2128 if (node
== XEXP (temp
, 0))
2130 /* Splice the node out of the list. */
2132 XEXP (prev
, 1) = XEXP (temp
, 1);
2134 *listp
= XEXP (temp
, 1);
2140 temp
= XEXP (temp
, 1);
2144 /* Nonzero if X contains any volatile instructions. These are instructions
2145 which may cause unpredictable machine state instructions, and thus no
2146 instructions should be moved or combined across them. This includes
2147 only volatile asms and UNSPEC_VOLATILE instructions. */
2150 volatile_insn_p (rtx x
)
2154 code
= GET_CODE (x
);
2174 case UNSPEC_VOLATILE
:
2175 /* case TRAP_IF: This isn't clear yet. */
2180 if (MEM_VOLATILE_P (x
))
2187 /* Recursively scan the operands of this expression. */
2190 const char *fmt
= GET_RTX_FORMAT (code
);
2193 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2197 if (volatile_insn_p (XEXP (x
, i
)))
2200 else if (fmt
[i
] == 'E')
2203 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2204 if (volatile_insn_p (XVECEXP (x
, i
, j
)))
2212 /* Nonzero if X contains any volatile memory references
2213 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
2216 volatile_refs_p (rtx x
)
2220 code
= GET_CODE (x
);
2238 case UNSPEC_VOLATILE
:
2244 if (MEM_VOLATILE_P (x
))
2251 /* Recursively scan the operands of this expression. */
2254 const char *fmt
= GET_RTX_FORMAT (code
);
2257 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2261 if (volatile_refs_p (XEXP (x
, i
)))
2264 else if (fmt
[i
] == 'E')
2267 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2268 if (volatile_refs_p (XVECEXP (x
, i
, j
)))
2276 /* Similar to above, except that it also rejects register pre- and post-
2280 side_effects_p (rtx x
)
2284 code
= GET_CODE (x
);
2302 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
2303 when some combination can't be done. If we see one, don't think
2304 that we can simplify the expression. */
2305 return (GET_MODE (x
) != VOIDmode
);
2314 case UNSPEC_VOLATILE
:
2315 /* case TRAP_IF: This isn't clear yet. */
2321 if (MEM_VOLATILE_P (x
))
2328 /* Recursively scan the operands of this expression. */
2331 const char *fmt
= GET_RTX_FORMAT (code
);
2334 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2338 if (side_effects_p (XEXP (x
, i
)))
2341 else if (fmt
[i
] == 'E')
2344 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2345 if (side_effects_p (XVECEXP (x
, i
, j
)))
2353 /* Return nonzero if evaluating rtx X might cause a trap. */
2364 code
= GET_CODE (x
);
2367 /* Handle these cases quickly. */
2381 case UNSPEC_VOLATILE
:
2386 return MEM_VOLATILE_P (x
);
2388 /* Memory ref can trap unless it's a static var or a stack slot. */
2390 if (MEM_NOTRAP_P (x
))
2392 return rtx_addr_can_trap_p (XEXP (x
, 0));
2394 /* Division by a non-constant might trap. */
2399 if (HONOR_SNANS (GET_MODE (x
)))
2401 if (! CONSTANT_P (XEXP (x
, 1))
2402 || (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
2403 && flag_trapping_math
))
2405 if (XEXP (x
, 1) == const0_rtx
)
2410 /* An EXPR_LIST is used to represent a function call. This
2411 certainly may trap. */
2419 /* Some floating point comparisons may trap. */
2420 if (!flag_trapping_math
)
2422 /* ??? There is no machine independent way to check for tests that trap
2423 when COMPARE is used, though many targets do make this distinction.
2424 For instance, sparc uses CCFPE for compares which generate exceptions
2425 and CCFP for compares which do not generate exceptions. */
2426 if (HONOR_NANS (GET_MODE (x
)))
2428 /* But often the compare has some CC mode, so check operand
2430 if (HONOR_NANS (GET_MODE (XEXP (x
, 0)))
2431 || HONOR_NANS (GET_MODE (XEXP (x
, 1))))
2437 if (HONOR_SNANS (GET_MODE (x
)))
2439 /* Often comparison is CC mode, so check operand modes. */
2440 if (HONOR_SNANS (GET_MODE (XEXP (x
, 0)))
2441 || HONOR_SNANS (GET_MODE (XEXP (x
, 1))))
2446 /* Conversion of floating point might trap. */
2447 if (flag_trapping_math
&& HONOR_NANS (GET_MODE (XEXP (x
, 0))))
2453 /* These operations don't trap even with floating point. */
2457 /* Any floating arithmetic may trap. */
2458 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
2459 && flag_trapping_math
)
2463 fmt
= GET_RTX_FORMAT (code
);
2464 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2468 if (may_trap_p (XEXP (x
, i
)))
2471 else if (fmt
[i
] == 'E')
2474 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2475 if (may_trap_p (XVECEXP (x
, i
, j
)))
2482 /* Return nonzero if X contains a comparison that is not either EQ or NE,
2483 i.e., an inequality. */
2486 inequality_comparisons_p (rtx x
)
2490 enum rtx_code code
= GET_CODE (x
);
2520 len
= GET_RTX_LENGTH (code
);
2521 fmt
= GET_RTX_FORMAT (code
);
2523 for (i
= 0; i
< len
; i
++)
2527 if (inequality_comparisons_p (XEXP (x
, i
)))
2530 else if (fmt
[i
] == 'E')
2533 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2534 if (inequality_comparisons_p (XVECEXP (x
, i
, j
)))
2542 /* Replace any occurrence of FROM in X with TO. The function does
2543 not enter into CONST_DOUBLE for the replace.
2545 Note that copying is not done so X must not be shared unless all copies
2546 are to be modified. */
2549 replace_rtx (rtx x
, rtx from
, rtx to
)
2554 /* The following prevents loops occurrence when we change MEM in
2555 CONST_DOUBLE onto the same CONST_DOUBLE. */
2556 if (x
!= 0 && GET_CODE (x
) == CONST_DOUBLE
)
2562 /* Allow this function to make replacements in EXPR_LISTs. */
2566 if (GET_CODE (x
) == SUBREG
)
2568 rtx
new = replace_rtx (SUBREG_REG (x
), from
, to
);
2570 if (GET_CODE (new) == CONST_INT
)
2572 x
= simplify_subreg (GET_MODE (x
), new,
2573 GET_MODE (SUBREG_REG (x
)),
2579 SUBREG_REG (x
) = new;
2583 else if (GET_CODE (x
) == ZERO_EXTEND
)
2585 rtx
new = replace_rtx (XEXP (x
, 0), from
, to
);
2587 if (GET_CODE (new) == CONST_INT
)
2589 x
= simplify_unary_operation (ZERO_EXTEND
, GET_MODE (x
),
2590 new, GET_MODE (XEXP (x
, 0)));
2600 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2601 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2604 XEXP (x
, i
) = replace_rtx (XEXP (x
, i
), from
, to
);
2605 else if (fmt
[i
] == 'E')
2606 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2607 XVECEXP (x
, i
, j
) = replace_rtx (XVECEXP (x
, i
, j
), from
, to
);
2613 /* Throughout the rtx X, replace many registers according to REG_MAP.
2614 Return the replacement for X (which may be X with altered contents).
2615 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
2616 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
2618 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
2619 should not be mapped to pseudos or vice versa since validate_change
2622 If REPLACE_DEST is 1, replacements are also done in destinations;
2623 otherwise, only sources are replaced. */
2626 replace_regs (rtx x
, rtx
*reg_map
, unsigned int nregs
, int replace_dest
)
2635 code
= GET_CODE (x
);
2650 /* Verify that the register has an entry before trying to access it. */
2651 if (REGNO (x
) < nregs
&& reg_map
[REGNO (x
)] != 0)
2653 /* SUBREGs can't be shared. Always return a copy to ensure that if
2654 this replacement occurs more than once then each instance will
2655 get distinct rtx. */
2656 if (GET_CODE (reg_map
[REGNO (x
)]) == SUBREG
)
2657 return copy_rtx (reg_map
[REGNO (x
)]);
2658 return reg_map
[REGNO (x
)];
2663 /* Prevent making nested SUBREGs. */
2664 if (GET_CODE (SUBREG_REG (x
)) == REG
&& REGNO (SUBREG_REG (x
)) < nregs
2665 && reg_map
[REGNO (SUBREG_REG (x
))] != 0
2666 && GET_CODE (reg_map
[REGNO (SUBREG_REG (x
))]) == SUBREG
)
2668 rtx map_val
= reg_map
[REGNO (SUBREG_REG (x
))];
2669 return simplify_gen_subreg (GET_MODE (x
), map_val
,
2670 GET_MODE (SUBREG_REG (x
)),
2677 SET_DEST (x
) = replace_regs (SET_DEST (x
), reg_map
, nregs
, 0);
2679 else if (GET_CODE (SET_DEST (x
)) == MEM
2680 || GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2681 /* Even if we are not to replace destinations, replace register if it
2682 is CONTAINED in destination (destination is memory or
2683 STRICT_LOW_PART). */
2684 XEXP (SET_DEST (x
), 0) = replace_regs (XEXP (SET_DEST (x
), 0),
2686 else if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2687 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2690 SET_SRC (x
) = replace_regs (SET_SRC (x
), reg_map
, nregs
, 0);
2697 fmt
= GET_RTX_FORMAT (code
);
2698 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2701 XEXP (x
, i
) = replace_regs (XEXP (x
, i
), reg_map
, nregs
, replace_dest
);
2702 else if (fmt
[i
] == 'E')
2705 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2706 XVECEXP (x
, i
, j
) = replace_regs (XVECEXP (x
, i
, j
), reg_map
,
2707 nregs
, replace_dest
);
2713 /* Replace occurrences of the old label in *X with the new one.
2714 DATA is a REPLACE_LABEL_DATA containing the old and new labels. */
2717 replace_label (rtx
*x
, void *data
)
2720 rtx old_label
= ((replace_label_data
*) data
)->r1
;
2721 rtx new_label
= ((replace_label_data
*) data
)->r2
;
2722 bool update_label_nuses
= ((replace_label_data
*) data
)->update_label_nuses
;
2727 if (GET_CODE (l
) == SYMBOL_REF
2728 && CONSTANT_POOL_ADDRESS_P (l
))
2730 rtx c
= get_pool_constant (l
);
2731 if (rtx_referenced_p (old_label
, c
))
2734 replace_label_data
*d
= (replace_label_data
*) data
;
2736 /* Create a copy of constant C; replace the label inside
2737 but do not update LABEL_NUSES because uses in constant pool
2739 new_c
= copy_rtx (c
);
2740 d
->update_label_nuses
= false;
2741 for_each_rtx (&new_c
, replace_label
, data
);
2742 d
->update_label_nuses
= update_label_nuses
;
2744 /* Add the new constant NEW_C to constant pool and replace
2745 the old reference to constant by new reference. */
2746 new_l
= XEXP (force_const_mem (get_pool_mode (l
), new_c
), 0);
2747 *x
= replace_rtx (l
, l
, new_l
);
2752 /* If this is a JUMP_INSN, then we also need to fix the JUMP_LABEL
2753 field. This is not handled by for_each_rtx because it doesn't
2754 handle unprinted ('0') fields. */
2755 if (GET_CODE (l
) == JUMP_INSN
&& JUMP_LABEL (l
) == old_label
)
2756 JUMP_LABEL (l
) = new_label
;
2758 if ((GET_CODE (l
) == LABEL_REF
2759 || GET_CODE (l
) == INSN_LIST
)
2760 && XEXP (l
, 0) == old_label
)
2762 XEXP (l
, 0) = new_label
;
2763 if (update_label_nuses
)
2765 ++LABEL_NUSES (new_label
);
2766 --LABEL_NUSES (old_label
);
2774 /* When *BODY is equal to X or X is directly referenced by *BODY
2775 return nonzero, thus FOR_EACH_RTX stops traversing and returns nonzero
2776 too, otherwise FOR_EACH_RTX continues traversing *BODY. */
2779 rtx_referenced_p_1 (rtx
*body
, void *x
)
2783 if (*body
== NULL_RTX
)
2784 return y
== NULL_RTX
;
2786 /* Return true if a label_ref *BODY refers to label Y. */
2787 if (GET_CODE (*body
) == LABEL_REF
&& GET_CODE (y
) == CODE_LABEL
)
2788 return XEXP (*body
, 0) == y
;
2790 /* If *BODY is a reference to pool constant traverse the constant. */
2791 if (GET_CODE (*body
) == SYMBOL_REF
2792 && CONSTANT_POOL_ADDRESS_P (*body
))
2793 return rtx_referenced_p (y
, get_pool_constant (*body
));
2795 /* By default, compare the RTL expressions. */
2796 return rtx_equal_p (*body
, y
);
2799 /* Return true if X is referenced in BODY. */
2802 rtx_referenced_p (rtx x
, rtx body
)
2804 return for_each_rtx (&body
, rtx_referenced_p_1
, x
);
2807 /* If INSN is a tablejump return true and store the label (before jump table) to
2808 *LABELP and the jump table to *TABLEP. LABELP and TABLEP may be NULL. */
2811 tablejump_p (rtx insn
, rtx
*labelp
, rtx
*tablep
)
2815 if (GET_CODE (insn
) == JUMP_INSN
2816 && (label
= JUMP_LABEL (insn
)) != NULL_RTX
2817 && (table
= next_active_insn (label
)) != NULL_RTX
2818 && GET_CODE (table
) == JUMP_INSN
2819 && (GET_CODE (PATTERN (table
)) == ADDR_VEC
2820 || GET_CODE (PATTERN (table
)) == ADDR_DIFF_VEC
))
2831 /* A subroutine of computed_jump_p, return 1 if X contains a REG or MEM or
2832 constant that is not in the constant pool and not in the condition
2833 of an IF_THEN_ELSE. */
2836 computed_jump_p_1 (rtx x
)
2838 enum rtx_code code
= GET_CODE (x
);
2857 return ! (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
2858 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)));
2861 return (computed_jump_p_1 (XEXP (x
, 1))
2862 || computed_jump_p_1 (XEXP (x
, 2)));
2868 fmt
= GET_RTX_FORMAT (code
);
2869 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2872 && computed_jump_p_1 (XEXP (x
, i
)))
2875 else if (fmt
[i
] == 'E')
2876 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2877 if (computed_jump_p_1 (XVECEXP (x
, i
, j
)))
2884 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2886 Tablejumps and casesi insns are not considered indirect jumps;
2887 we can recognize them by a (use (label_ref)). */
2890 computed_jump_p (rtx insn
)
2893 if (GET_CODE (insn
) == JUMP_INSN
)
2895 rtx pat
= PATTERN (insn
);
2897 if (find_reg_note (insn
, REG_LABEL
, NULL_RTX
))
2899 else if (GET_CODE (pat
) == PARALLEL
)
2901 int len
= XVECLEN (pat
, 0);
2902 int has_use_labelref
= 0;
2904 for (i
= len
- 1; i
>= 0; i
--)
2905 if (GET_CODE (XVECEXP (pat
, 0, i
)) == USE
2906 && (GET_CODE (XEXP (XVECEXP (pat
, 0, i
), 0))
2908 has_use_labelref
= 1;
2910 if (! has_use_labelref
)
2911 for (i
= len
- 1; i
>= 0; i
--)
2912 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
2913 && SET_DEST (XVECEXP (pat
, 0, i
)) == pc_rtx
2914 && computed_jump_p_1 (SET_SRC (XVECEXP (pat
, 0, i
))))
2917 else if (GET_CODE (pat
) == SET
2918 && SET_DEST (pat
) == pc_rtx
2919 && computed_jump_p_1 (SET_SRC (pat
)))
2925 /* Traverse X via depth-first search, calling F for each
2926 sub-expression (including X itself). F is also passed the DATA.
2927 If F returns -1, do not traverse sub-expressions, but continue
2928 traversing the rest of the tree. If F ever returns any other
2929 nonzero value, stop the traversal, and return the value returned
2930 by F. Otherwise, return 0. This function does not traverse inside
2931 tree structure that contains RTX_EXPRs, or into sub-expressions
2932 whose format code is `0' since it is not known whether or not those
2933 codes are actually RTL.
2935 This routine is very general, and could (should?) be used to
2936 implement many of the other routines in this file. */
2939 for_each_rtx (rtx
*x
, rtx_function f
, void *data
)
2947 result
= (*f
) (x
, data
);
2949 /* Do not traverse sub-expressions. */
2951 else if (result
!= 0)
2952 /* Stop the traversal. */
2956 /* There are no sub-expressions. */
2959 length
= GET_RTX_LENGTH (GET_CODE (*x
));
2960 format
= GET_RTX_FORMAT (GET_CODE (*x
));
2962 for (i
= 0; i
< length
; ++i
)
2967 result
= for_each_rtx (&XEXP (*x
, i
), f
, data
);
2974 if (XVEC (*x
, i
) != 0)
2977 for (j
= 0; j
< XVECLEN (*x
, i
); ++j
)
2979 result
= for_each_rtx (&XVECEXP (*x
, i
, j
), f
, data
);
2987 /* Nothing to do. */
2996 /* Searches X for any reference to REGNO, returning the rtx of the
2997 reference found if any. Otherwise, returns NULL_RTX. */
3000 regno_use_in (unsigned int regno
, rtx x
)
3006 if (GET_CODE (x
) == REG
&& REGNO (x
) == regno
)
3009 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
3010 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
3014 if ((tem
= regno_use_in (regno
, XEXP (x
, i
))))
3017 else if (fmt
[i
] == 'E')
3018 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
3019 if ((tem
= regno_use_in (regno
, XVECEXP (x
, i
, j
))))
3026 /* Return a value indicating whether OP, an operand of a commutative
3027 operation, is preferred as the first or second operand. The higher
3028 the value, the stronger the preference for being the first operand.
3029 We use negative values to indicate a preference for the first operand
3030 and positive values for the second operand. */
3033 commutative_operand_precedence (rtx op
)
3035 enum rtx_code code
= GET_CODE (op
);
3037 /* Constants always come the second operand. Prefer "nice" constants. */
3038 if (code
== CONST_INT
)
3040 if (code
== CONST_DOUBLE
)
3042 op
= avoid_constant_pool_reference (op
);
3044 switch (GET_RTX_CLASS (code
))
3047 if (code
== CONST_INT
)
3049 if (code
== CONST_DOUBLE
)
3054 /* SUBREGs of objects should come second. */
3055 if (code
== SUBREG
&& OBJECT_P (SUBREG_REG (op
)))
3058 if (!CONSTANT_P (op
))
3061 /* As for RTX_CONST_OBJ. */
3065 /* Complex expressions should be the first, so decrease priority
3069 case RTX_COMM_ARITH
:
3070 /* Prefer operands that are themselves commutative to be first.
3071 This helps to make things linear. In particular,
3072 (and (and (reg) (reg)) (not (reg))) is canonical. */
3076 /* If only one operand is a binary expression, it will be the first
3077 operand. In particular, (plus (minus (reg) (reg)) (neg (reg)))
3078 is canonical, although it will usually be further simplified. */
3082 /* Then prefer NEG and NOT. */
3083 if (code
== NEG
|| code
== NOT
)
3091 /* Return 1 iff it is necessary to swap operands of commutative operation
3092 in order to canonicalize expression. */
3095 swap_commutative_operands_p (rtx x
, rtx y
)
3097 return (commutative_operand_precedence (x
)
3098 < commutative_operand_precedence (y
));
3101 /* Return 1 if X is an autoincrement side effect and the register is
3102 not the stack pointer. */
3106 switch (GET_CODE (x
))
3114 /* There are no REG_INC notes for SP. */
3115 if (XEXP (x
, 0) != stack_pointer_rtx
)
3123 /* Return 1 if the sequence of instructions beginning with FROM and up
3124 to and including TO is safe to move. If NEW_TO is non-NULL, and
3125 the sequence is not already safe to move, but can be easily
3126 extended to a sequence which is safe, then NEW_TO will point to the
3127 end of the extended sequence.
3129 For now, this function only checks that the region contains whole
3130 exception regions, but it could be extended to check additional
3131 conditions as well. */
3134 insns_safe_to_move_p (rtx from
, rtx to
, rtx
*new_to
)
3136 int eh_region_count
= 0;
3140 /* By default, assume the end of the region will be what was
3147 if (GET_CODE (r
) == NOTE
)
3149 switch (NOTE_LINE_NUMBER (r
))
3151 case NOTE_INSN_EH_REGION_BEG
:
3155 case NOTE_INSN_EH_REGION_END
:
3156 if (eh_region_count
== 0)
3157 /* This sequence of instructions contains the end of
3158 an exception region, but not he beginning. Moving
3159 it will cause chaos. */
3170 /* If we've passed TO, and we see a non-note instruction, we
3171 can't extend the sequence to a movable sequence. */
3177 /* It's OK to move the sequence if there were matched sets of
3178 exception region notes. */
3179 return eh_region_count
== 0;
3184 /* It's OK to move the sequence if there were matched sets of
3185 exception region notes. */
3186 if (past_to_p
&& eh_region_count
== 0)
3192 /* Go to the next instruction. */
3199 /* Return nonzero if IN contains a piece of rtl that has the address LOC. */
3201 loc_mentioned_in_p (rtx
*loc
, rtx in
)
3203 enum rtx_code code
= GET_CODE (in
);
3204 const char *fmt
= GET_RTX_FORMAT (code
);
3207 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3209 if (loc
== &in
->u
.fld
[i
].rtx
)
3213 if (loc_mentioned_in_p (loc
, XEXP (in
, i
)))
3216 else if (fmt
[i
] == 'E')
3217 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
3218 if (loc_mentioned_in_p (loc
, XVECEXP (in
, i
, j
)))
3224 /* Helper function for subreg_lsb. Given a subreg's OUTER_MODE, INNER_MODE,
3225 and SUBREG_BYTE, return the bit offset where the subreg begins
3226 (counting from the least significant bit of the operand). */
3229 subreg_lsb_1 (enum machine_mode outer_mode
,
3230 enum machine_mode inner_mode
,
3231 unsigned int subreg_byte
)
3233 unsigned int bitpos
;
3237 /* A paradoxical subreg begins at bit position 0. */
3238 if (GET_MODE_BITSIZE (outer_mode
) > GET_MODE_BITSIZE (inner_mode
))
3241 if (WORDS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
3242 /* If the subreg crosses a word boundary ensure that
3243 it also begins and ends on a word boundary. */
3244 if ((subreg_byte
% UNITS_PER_WORD
3245 + GET_MODE_SIZE (outer_mode
)) > UNITS_PER_WORD
3246 && (subreg_byte
% UNITS_PER_WORD
3247 || GET_MODE_SIZE (outer_mode
) % UNITS_PER_WORD
))
3250 if (WORDS_BIG_ENDIAN
)
3251 word
= (GET_MODE_SIZE (inner_mode
)
3252 - (subreg_byte
+ GET_MODE_SIZE (outer_mode
))) / UNITS_PER_WORD
;
3254 word
= subreg_byte
/ UNITS_PER_WORD
;
3255 bitpos
= word
* BITS_PER_WORD
;
3257 if (BYTES_BIG_ENDIAN
)
3258 byte
= (GET_MODE_SIZE (inner_mode
)
3259 - (subreg_byte
+ GET_MODE_SIZE (outer_mode
))) % UNITS_PER_WORD
;
3261 byte
= subreg_byte
% UNITS_PER_WORD
;
3262 bitpos
+= byte
* BITS_PER_UNIT
;
3267 /* Given a subreg X, return the bit offset where the subreg begins
3268 (counting from the least significant bit of the reg). */
3273 return subreg_lsb_1 (GET_MODE (x
), GET_MODE (SUBREG_REG (x
)),
3277 /* This function returns the regno offset of a subreg expression.
3278 xregno - A regno of an inner hard subreg_reg (or what will become one).
3279 xmode - The mode of xregno.
3280 offset - The byte offset.
3281 ymode - The mode of a top level SUBREG (or what may become one).
3282 RETURN - The regno offset which would be used. */
3284 subreg_regno_offset (unsigned int xregno
, enum machine_mode xmode
,
3285 unsigned int offset
, enum machine_mode ymode
)
3287 int nregs_xmode
, nregs_ymode
;
3288 int mode_multiple
, nregs_multiple
;
3291 if (xregno
>= FIRST_PSEUDO_REGISTER
)
3294 nregs_xmode
= hard_regno_nregs
[xregno
][xmode
];
3295 nregs_ymode
= hard_regno_nregs
[xregno
][ymode
];
3297 /* If this is a big endian paradoxical subreg, which uses more actual
3298 hard registers than the original register, we must return a negative
3299 offset so that we find the proper highpart of the register. */
3301 && nregs_ymode
> nregs_xmode
3302 && (GET_MODE_SIZE (ymode
) > UNITS_PER_WORD
3303 ? WORDS_BIG_ENDIAN
: BYTES_BIG_ENDIAN
))
3304 return nregs_xmode
- nregs_ymode
;
3306 if (offset
== 0 || nregs_xmode
== nregs_ymode
)
3309 /* size of ymode must not be greater than the size of xmode. */
3310 mode_multiple
= GET_MODE_SIZE (xmode
) / GET_MODE_SIZE (ymode
);
3311 if (mode_multiple
== 0)
3314 y_offset
= offset
/ GET_MODE_SIZE (ymode
);
3315 nregs_multiple
= nregs_xmode
/ nregs_ymode
;
3316 return (y_offset
/ (mode_multiple
/ nregs_multiple
)) * nregs_ymode
;
3319 /* This function returns true when the offset is representable via
3320 subreg_offset in the given regno.
3321 xregno - A regno of an inner hard subreg_reg (or what will become one).
3322 xmode - The mode of xregno.
3323 offset - The byte offset.
3324 ymode - The mode of a top level SUBREG (or what may become one).
3325 RETURN - The regno offset which would be used. */
3327 subreg_offset_representable_p (unsigned int xregno
, enum machine_mode xmode
,
3328 unsigned int offset
, enum machine_mode ymode
)
3330 int nregs_xmode
, nregs_ymode
;
3331 int mode_multiple
, nregs_multiple
;
3334 if (xregno
>= FIRST_PSEUDO_REGISTER
)
3337 nregs_xmode
= hard_regno_nregs
[xregno
][xmode
];
3338 nregs_ymode
= hard_regno_nregs
[xregno
][ymode
];
3340 /* Paradoxical subregs are always valid. */
3342 && nregs_ymode
> nregs_xmode
3343 && (GET_MODE_SIZE (ymode
) > UNITS_PER_WORD
3344 ? WORDS_BIG_ENDIAN
: BYTES_BIG_ENDIAN
))
3347 /* Lowpart subregs are always valid. */
3348 if (offset
== subreg_lowpart_offset (ymode
, xmode
))
3351 #ifdef ENABLE_CHECKING
3352 /* This should always pass, otherwise we don't know how to verify the
3353 constraint. These conditions may be relaxed but subreg_offset would
3354 need to be redesigned. */
3355 if (GET_MODE_SIZE (xmode
) % GET_MODE_SIZE (ymode
)
3356 || GET_MODE_SIZE (ymode
) % nregs_ymode
3357 || nregs_xmode
% nregs_ymode
)
3361 /* The XMODE value can be seen as a vector of NREGS_XMODE
3362 values. The subreg must represent a lowpart of given field.
3363 Compute what field it is. */
3364 offset
-= subreg_lowpart_offset (ymode
,
3365 mode_for_size (GET_MODE_BITSIZE (xmode
)
3369 /* size of ymode must not be greater than the size of xmode. */
3370 mode_multiple
= GET_MODE_SIZE (xmode
) / GET_MODE_SIZE (ymode
);
3371 if (mode_multiple
== 0)
3374 y_offset
= offset
/ GET_MODE_SIZE (ymode
);
3375 nregs_multiple
= nregs_xmode
/ nregs_ymode
;
3376 #ifdef ENABLE_CHECKING
3377 if (offset
% GET_MODE_SIZE (ymode
)
3378 || mode_multiple
% nregs_multiple
)
3381 return (!(y_offset
% (mode_multiple
/ nregs_multiple
)));
3384 /* Return the final regno that a subreg expression refers to. */
3386 subreg_regno (rtx x
)
3389 rtx subreg
= SUBREG_REG (x
);
3390 int regno
= REGNO (subreg
);
3392 ret
= regno
+ subreg_regno_offset (regno
,
3399 struct parms_set_data
3405 /* Helper function for noticing stores to parameter registers. */
3407 parms_set (rtx x
, rtx pat ATTRIBUTE_UNUSED
, void *data
)
3409 struct parms_set_data
*d
= data
;
3410 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
3411 && TEST_HARD_REG_BIT (d
->regs
, REGNO (x
)))
3413 CLEAR_HARD_REG_BIT (d
->regs
, REGNO (x
));
3418 /* Look backward for first parameter to be loaded.
3419 Do not skip BOUNDARY. */
3421 find_first_parameter_load (rtx call_insn
, rtx boundary
)
3423 struct parms_set_data parm
;
3426 /* Since different machines initialize their parameter registers
3427 in different orders, assume nothing. Collect the set of all
3428 parameter registers. */
3429 CLEAR_HARD_REG_SET (parm
.regs
);
3431 for (p
= CALL_INSN_FUNCTION_USAGE (call_insn
); p
; p
= XEXP (p
, 1))
3432 if (GET_CODE (XEXP (p
, 0)) == USE
3433 && GET_CODE (XEXP (XEXP (p
, 0), 0)) == REG
)
3435 if (REGNO (XEXP (XEXP (p
, 0), 0)) >= FIRST_PSEUDO_REGISTER
)
3438 /* We only care about registers which can hold function
3440 if (!FUNCTION_ARG_REGNO_P (REGNO (XEXP (XEXP (p
, 0), 0))))
3443 SET_HARD_REG_BIT (parm
.regs
, REGNO (XEXP (XEXP (p
, 0), 0)));
3448 /* Search backward for the first set of a register in this set. */
3449 while (parm
.nregs
&& before
!= boundary
)
3451 before
= PREV_INSN (before
);
3453 /* It is possible that some loads got CSEed from one call to
3454 another. Stop in that case. */
3455 if (GET_CODE (before
) == CALL_INSN
)
3458 /* Our caller needs either ensure that we will find all sets
3459 (in case code has not been optimized yet), or take care
3460 for possible labels in a way by setting boundary to preceding
3462 if (GET_CODE (before
) == CODE_LABEL
)
3464 if (before
!= boundary
)
3469 if (INSN_P (before
))
3470 note_stores (PATTERN (before
), parms_set
, &parm
);
3475 /* Return true if we should avoid inserting code between INSN and preceding
3476 call instruction. */
3479 keep_with_call_p (rtx insn
)
3483 if (INSN_P (insn
) && (set
= single_set (insn
)) != NULL
)
3485 if (GET_CODE (SET_DEST (set
)) == REG
3486 && REGNO (SET_DEST (set
)) < FIRST_PSEUDO_REGISTER
3487 && fixed_regs
[REGNO (SET_DEST (set
))]
3488 && general_operand (SET_SRC (set
), VOIDmode
))
3490 if (GET_CODE (SET_SRC (set
)) == REG
3491 && FUNCTION_VALUE_REGNO_P (REGNO (SET_SRC (set
)))
3492 && GET_CODE (SET_DEST (set
)) == REG
3493 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
)
3495 /* There may be a stack pop just after the call and before the store
3496 of the return register. Search for the actual store when deciding
3497 if we can break or not. */
3498 if (SET_DEST (set
) == stack_pointer_rtx
)
3500 rtx i2
= next_nonnote_insn (insn
);
3501 if (i2
&& keep_with_call_p (i2
))
3508 /* Return true when store to register X can be hoisted to the place
3509 with LIVE registers (can be NULL). Value VAL contains destination
3510 whose value will be used. */
3513 hoist_test_store (rtx x
, rtx val
, regset live
)
3515 if (GET_CODE (x
) == SCRATCH
)
3518 if (rtx_equal_p (x
, val
))
3521 /* Allow subreg of X in case it is not writing just part of multireg pseudo.
3522 Then we would need to update all users to care hoisting the store too.
3523 Caller may represent that by specifying whole subreg as val. */
3525 if (GET_CODE (x
) == SUBREG
&& rtx_equal_p (SUBREG_REG (x
), val
))
3527 if (GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) > UNITS_PER_WORD
3528 && GET_MODE_BITSIZE (GET_MODE (x
)) <
3529 GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x
))))
3533 if (GET_CODE (x
) == SUBREG
)
3536 /* Anything except register store is not hoistable. This includes the
3537 partial stores to registers. */
3542 /* Pseudo registers can be always replaced by another pseudo to avoid
3543 the side effect, for hard register we must ensure that they are dead.
3544 Eventually we may want to add code to try turn pseudos to hards, but it
3545 is unlikely useful. */
3547 if (REGNO (x
) < FIRST_PSEUDO_REGISTER
)
3549 int regno
= REGNO (x
);
3550 int n
= hard_regno_nregs
[regno
][GET_MODE (x
)];
3554 if (REGNO_REG_SET_P (live
, regno
))
3557 if (REGNO_REG_SET_P (live
, regno
+ n
))
3564 /* Return true if INSN can be hoisted to place with LIVE hard registers
3565 (LIVE can be NULL when unknown). VAL is expected to be stored by the insn
3566 and used by the hoisting pass. */
3569 can_hoist_insn_p (rtx insn
, rtx val
, regset live
)
3571 rtx pat
= PATTERN (insn
);
3574 /* It probably does not worth the complexity to handle multiple
3576 if (!single_set (insn
))
3578 /* We can move CALL_INSN, but we need to check that all caller clobbered
3580 if (GET_CODE (insn
) == CALL_INSN
)
3582 /* In future we will handle hoisting of libcall sequences, but
3584 if (find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
3586 switch (GET_CODE (pat
))
3589 if (!hoist_test_store (SET_DEST (pat
), val
, live
))
3593 /* USES do have sick semantics, so do not move them. */
3597 if (!hoist_test_store (XEXP (pat
, 0), val
, live
))
3601 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
3603 rtx x
= XVECEXP (pat
, 0, i
);
3604 switch (GET_CODE (x
))
3607 if (!hoist_test_store (SET_DEST (x
), val
, live
))
3611 /* We need to fix callers to really ensure availability
3612 of all values insn uses, but for now it is safe to prohibit
3613 hoisting of any insn having such a hidden uses. */
3617 if (!hoist_test_store (SET_DEST (x
), val
, live
))
3631 /* Update store after hoisting - replace all stores to pseudo registers
3632 by new ones to avoid clobbering of values except for store to VAL that will
3633 be updated to NEW. */
3636 hoist_update_store (rtx insn
, rtx
*xp
, rtx val
, rtx
new)
3640 if (GET_CODE (x
) == SCRATCH
)
3643 if (GET_CODE (x
) == SUBREG
&& SUBREG_REG (x
) == val
)
3644 validate_change (insn
, xp
,
3645 simplify_gen_subreg (GET_MODE (x
), new, GET_MODE (new),
3646 SUBREG_BYTE (x
)), 1);
3647 if (rtx_equal_p (x
, val
))
3649 validate_change (insn
, xp
, new, 1);
3652 if (GET_CODE (x
) == SUBREG
)
3654 xp
= &SUBREG_REG (x
);
3661 /* We've verified that hard registers are dead, so we may keep the side
3662 effect. Otherwise replace it by new pseudo. */
3663 if (REGNO (x
) >= FIRST_PSEUDO_REGISTER
)
3664 validate_change (insn
, xp
, gen_reg_rtx (GET_MODE (x
)), 1);
3666 = alloc_EXPR_LIST (REG_UNUSED
, *xp
, REG_NOTES (insn
));
3669 /* Create a copy of INSN after AFTER replacing store of VAL to NEW
3670 and each other side effect to pseudo register by new pseudo register. */
3673 hoist_insn_after (rtx insn
, rtx after
, rtx val
, rtx
new)
3679 insn
= emit_copy_of_insn_after (insn
, after
);
3680 pat
= PATTERN (insn
);
3682 /* Remove REG_UNUSED notes as we will re-emit them. */
3683 while ((note
= find_reg_note (insn
, REG_UNUSED
, NULL_RTX
)))
3684 remove_note (insn
, note
);
3686 /* To get this working callers must ensure to move everything referenced
3687 by REG_EQUAL/REG_EQUIV notes too. Lets remove them, it is probably
3689 while ((note
= find_reg_note (insn
, REG_EQUAL
, NULL_RTX
)))
3690 remove_note (insn
, note
);
3691 while ((note
= find_reg_note (insn
, REG_EQUIV
, NULL_RTX
)))
3692 remove_note (insn
, note
);
3694 /* Remove REG_DEAD notes as they might not be valid anymore in case
3695 we create redundancy. */
3696 while ((note
= find_reg_note (insn
, REG_DEAD
, NULL_RTX
)))
3697 remove_note (insn
, note
);
3698 switch (GET_CODE (pat
))
3701 hoist_update_store (insn
, &SET_DEST (pat
), val
, new);
3706 hoist_update_store (insn
, &XEXP (pat
, 0), val
, new);
3709 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
3711 rtx x
= XVECEXP (pat
, 0, i
);
3712 switch (GET_CODE (x
))
3715 hoist_update_store (insn
, &SET_DEST (x
), val
, new);
3720 hoist_update_store (insn
, &SET_DEST (x
), val
, new);
3730 if (!apply_change_group ())
3737 hoist_insn_to_edge (rtx insn
, edge e
, rtx val
, rtx
new)
3741 /* We cannot insert instructions on an abnormal critical edge.
3742 It will be easier to find the culprit if we die now. */
3743 if ((e
->flags
& EDGE_ABNORMAL
) && EDGE_CRITICAL_P (e
))
3746 /* Do not use emit_insn_on_edge as we want to preserve notes and similar
3747 stuff. We also emit CALL_INSNS and friends. */
3748 if (e
->insns
== NULL_RTX
)
3751 emit_note (NOTE_INSN_DELETED
);
3754 push_to_sequence (e
->insns
);
3756 new_insn
= hoist_insn_after (insn
, get_last_insn (), val
, new);
3758 e
->insns
= get_insns ();
3763 /* Return true if LABEL is a target of JUMP_INSN. This applies only
3764 to non-complex jumps. That is, direct unconditional, conditional,
3765 and tablejumps, but not computed jumps or returns. It also does
3766 not apply to the fallthru case of a conditional jump. */
3769 label_is_jump_target_p (rtx label
, rtx jump_insn
)
3771 rtx tmp
= JUMP_LABEL (jump_insn
);
3776 if (tablejump_p (jump_insn
, NULL
, &tmp
))
3778 rtvec vec
= XVEC (PATTERN (tmp
),
3779 GET_CODE (PATTERN (tmp
)) == ADDR_DIFF_VEC
);
3780 int i
, veclen
= GET_NUM_ELEM (vec
);
3782 for (i
= 0; i
< veclen
; ++i
)
3783 if (XEXP (RTVEC_ELT (vec
, i
), 0) == label
)
3791 /* Return an estimate of the cost of computing rtx X.
3792 One use is in cse, to decide which expression to keep in the hash table.
3793 Another is in rtl generation, to pick the cheapest way to multiply.
3794 Other uses like the latter are expected in the future. */
3797 rtx_cost (rtx x
, enum rtx_code outer_code ATTRIBUTE_UNUSED
)
3807 /* Compute the default costs of certain things.
3808 Note that targetm.rtx_costs can override the defaults. */
3810 code
= GET_CODE (x
);
3814 total
= COSTS_N_INSNS (5);
3820 total
= COSTS_N_INSNS (7);
3823 /* Used in loop.c and combine.c as a marker. */
3827 total
= COSTS_N_INSNS (1);
3836 /* If we can't tie these modes, make this expensive. The larger
3837 the mode, the more expensive it is. */
3838 if (! MODES_TIEABLE_P (GET_MODE (x
), GET_MODE (SUBREG_REG (x
))))
3839 return COSTS_N_INSNS (2
3840 + GET_MODE_SIZE (GET_MODE (x
)) / UNITS_PER_WORD
);
3844 if (targetm
.rtx_costs (x
, code
, outer_code
, &total
))
3849 /* Sum the costs of the sub-rtx's, plus cost of this operation,
3850 which is already in total. */
3852 fmt
= GET_RTX_FORMAT (code
);
3853 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3855 total
+= rtx_cost (XEXP (x
, i
), code
);
3856 else if (fmt
[i
] == 'E')
3857 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3858 total
+= rtx_cost (XVECEXP (x
, i
, j
), code
);
3863 /* Return cost of address expression X.
3864 Expect that X is properly formed address reference. */
3867 address_cost (rtx x
, enum machine_mode mode
)
3869 /* The address_cost target hook does not deal with ADDRESSOF nodes. But,
3870 during CSE, such nodes are present. Using an ADDRESSOF node which
3871 refers to the address of a REG is a good thing because we can then
3872 turn (MEM (ADDRESSOF (REG))) into just plain REG. */
3874 if (GET_CODE (x
) == ADDRESSOF
&& REG_P (XEXP ((x
), 0)))
3877 /* We may be asked for cost of various unusual addresses, such as operands
3878 of push instruction. It is not worthwhile to complicate writing
3879 of the target hook by such cases. */
3881 if (!memory_address_p (mode
, x
))
3884 return targetm
.address_cost (x
);
3887 /* If the target doesn't override, compute the cost as with arithmetic. */
3890 default_address_cost (rtx x
)
3892 return rtx_cost (x
, MEM
);