1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 static int rtx_addr_can_trap_p
PARAMS ((rtx
));
29 static void reg_set_p_1
PARAMS ((rtx
, rtx
, void *));
30 static void insn_dependent_p_1
PARAMS ((rtx
, rtx
, void *));
31 static void reg_set_last_1
PARAMS ((rtx
, rtx
, void *));
34 /* Forward declarations */
35 static int jmp_uses_reg_or_mem
PARAMS ((rtx
));
37 /* Bit flags that specify the machine subtype we are compiling for.
38 Bits are tested using macros TARGET_... defined in the tm.h file
39 and set by `-m...' switches. Must be defined in rtlanal.c. */
43 /* Return 1 if the value of X is unstable
44 (would be different at a different point in the program).
45 The frame pointer, arg pointer, etc. are considered stable
46 (within one function) and so is anything marked `unchanging'. */
52 register RTX_CODE code
= GET_CODE (x
);
54 register const char *fmt
;
59 return ! RTX_UNCHANGING_P (x
) || rtx_unstable_p (XEXP (x
, 0));
72 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
73 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
74 || x
== arg_pointer_rtx
|| RTX_UNCHANGING_P (x
))
76 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
77 /* ??? When call-clobbered, the value is stable modulo the restore
78 that must happen after a call. This currently screws up local-alloc
79 into believing that the restore is not needed. */
80 if (x
== pic_offset_table_rtx
)
86 if (MEM_VOLATILE_P (x
))
95 fmt
= GET_RTX_FORMAT (code
);
96 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
99 if (rtx_unstable_p (XEXP (x
, i
)))
102 else if (fmt
[i
] == 'E')
105 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
106 if (rtx_unstable_p (XVECEXP (x
, i
, j
)))
113 /* Return 1 if X has a value that can vary even between two
114 executions of the program. 0 means X can be compared reliably
115 against certain constants or near-constants.
116 The frame pointer and the arg pointer are considered constant. */
122 register RTX_CODE code
= GET_CODE (x
);
124 register const char *fmt
;
129 return ! RTX_UNCHANGING_P (x
) || rtx_varies_p (XEXP (x
, 0));
142 /* Note that we have to test for the actual rtx used for the frame
143 and arg pointers and not just the register number in case we have
144 eliminated the frame and/or arg pointer and are using it
146 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
147 || x
== arg_pointer_rtx
)
149 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
150 /* ??? When call-clobbered, the value is stable modulo the restore
151 that must happen after a call. This currently screws up local-alloc
152 into believing that the restore is not needed. */
153 if (x
== pic_offset_table_rtx
)
159 /* The operand 0 of a LO_SUM is considered constant
160 (in fact is it related specifically to operand 1). */
161 return rtx_varies_p (XEXP (x
, 1));
164 if (MEM_VOLATILE_P (x
))
173 fmt
= GET_RTX_FORMAT (code
);
174 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
177 if (rtx_varies_p (XEXP (x
, i
)))
180 else if (fmt
[i
] == 'E')
183 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
184 if (rtx_varies_p (XVECEXP (x
, i
, j
)))
191 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
194 rtx_addr_can_trap_p (x
)
197 register enum rtx_code code
= GET_CODE (x
);
203 /* SYMBOL_REF is problematic due to the possible presence of
204 a #pragma weak, but to say that loads from symbols can trap is
205 *very* costly. It's not at all clear what's best here. For
206 now, we ignore the impact of #pragma weak. */
210 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
211 return ! (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
212 || x
== stack_pointer_rtx
|| x
== arg_pointer_rtx
);
215 return rtx_addr_can_trap_p (XEXP (x
, 0));
218 /* An address is assumed not to trap if it is an address that can't
219 trap plus a constant integer or it is the pic register plus a
221 return ! ((! rtx_addr_can_trap_p (XEXP (x
, 0))
222 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
223 || (XEXP (x
, 0) == pic_offset_table_rtx
224 && CONSTANT_P (XEXP (x
, 1))));
227 return rtx_addr_can_trap_p (XEXP (x
, 1));
233 /* If it isn't one of the case above, it can cause a trap. */
237 /* Return 1 if X refers to a memory location whose address
238 cannot be compared reliably with constant addresses,
239 or if X refers to a BLKmode memory object. */
242 rtx_addr_varies_p (x
)
245 register enum rtx_code code
;
247 register const char *fmt
;
254 return GET_MODE (x
) == BLKmode
|| rtx_varies_p (XEXP (x
, 0));
256 fmt
= GET_RTX_FORMAT (code
);
257 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
260 if (rtx_addr_varies_p (XEXP (x
, i
)))
263 else if (fmt
[i
] == 'E')
266 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
267 if (rtx_addr_varies_p (XVECEXP (x
, i
, j
)))
273 /* Return the value of the integer term in X, if one is apparent;
275 Only obvious integer terms are detected.
276 This is used in cse.c with the `related_value' field.*/
282 if (GET_CODE (x
) == CONST
)
285 if (GET_CODE (x
) == MINUS
286 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
287 return - INTVAL (XEXP (x
, 1));
288 if (GET_CODE (x
) == PLUS
289 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
290 return INTVAL (XEXP (x
, 1));
294 /* If X is a constant, return the value sans apparent integer term;
296 Only obvious integer terms are detected. */
299 get_related_value (x
)
302 if (GET_CODE (x
) != CONST
)
305 if (GET_CODE (x
) == PLUS
306 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
308 else if (GET_CODE (x
) == MINUS
309 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
314 /* Return the number of places FIND appears within X. If COUNT_DEST is
315 zero, we do not count occurrences inside the destination of a SET. */
318 count_occurrences (x
, find
, count_dest
)
324 const char *format_ptr
;
344 if (GET_CODE (find
) == MEM
&& rtx_equal_p (x
, find
))
349 if (SET_DEST (x
) == find
&& ! count_dest
)
350 return count_occurrences (SET_SRC (x
), find
, count_dest
);
357 format_ptr
= GET_RTX_FORMAT (code
);
360 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
362 switch (*format_ptr
++)
365 count
+= count_occurrences (XEXP (x
, i
), find
, count_dest
);
369 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
370 count
+= count_occurrences (XVECEXP (x
, i
, j
), find
, count_dest
);
377 /* Nonzero if register REG appears somewhere within IN.
378 Also works if REG is not a register; in this case it checks
379 for a subexpression of IN that is Lisp "equal" to REG. */
382 reg_mentioned_p (reg
, in
)
383 register rtx reg
, in
;
385 register const char *fmt
;
387 register enum rtx_code code
;
395 if (GET_CODE (in
) == LABEL_REF
)
396 return reg
== XEXP (in
, 0);
398 code
= GET_CODE (in
);
402 /* Compare registers by number. */
404 return GET_CODE (reg
) == REG
&& REGNO (in
) == REGNO (reg
);
406 /* These codes have no constituent expressions
414 return GET_CODE (reg
) == CONST_INT
&& INTVAL (in
) == INTVAL (reg
);
417 /* These are kept unique for a given value. */
424 if (GET_CODE (reg
) == code
&& rtx_equal_p (reg
, in
))
427 fmt
= GET_RTX_FORMAT (code
);
429 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
434 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
435 if (reg_mentioned_p (reg
, XVECEXP (in
, i
, j
)))
438 else if (fmt
[i
] == 'e'
439 && reg_mentioned_p (reg
, XEXP (in
, i
)))
445 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
446 no CODE_LABEL insn. */
449 no_labels_between_p (beg
, end
)
453 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
454 if (GET_CODE (p
) == CODE_LABEL
)
459 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
460 no JUMP_INSN insn. */
463 no_jumps_between_p (beg
, end
)
467 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
468 if (GET_CODE (p
) == JUMP_INSN
)
473 /* Nonzero if register REG is used in an insn between
474 FROM_INSN and TO_INSN (exclusive of those two). */
477 reg_used_between_p (reg
, from_insn
, to_insn
)
478 rtx reg
, from_insn
, to_insn
;
482 if (from_insn
== to_insn
)
485 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
487 && (reg_overlap_mentioned_p (reg
, PATTERN (insn
))
488 || (GET_CODE (insn
) == CALL_INSN
489 && (find_reg_fusage (insn
, USE
, reg
)
490 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
495 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
496 is entirely replaced by a new value and the only use is as a SET_DEST,
497 we do not consider it a reference. */
500 reg_referenced_p (x
, body
)
506 switch (GET_CODE (body
))
509 if (reg_overlap_mentioned_p (x
, SET_SRC (body
)))
512 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
513 of a REG that occupies all of the REG, the insn references X if
514 it is mentioned in the destination. */
515 if (GET_CODE (SET_DEST (body
)) != CC0
516 && GET_CODE (SET_DEST (body
)) != PC
517 && GET_CODE (SET_DEST (body
)) != REG
518 && ! (GET_CODE (SET_DEST (body
)) == SUBREG
519 && GET_CODE (SUBREG_REG (SET_DEST (body
))) == REG
520 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body
))))
521 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
522 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body
)))
523 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)))
524 && reg_overlap_mentioned_p (x
, SET_DEST (body
)))
529 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
530 if (reg_overlap_mentioned_p (x
, ASM_OPERANDS_INPUT (body
, i
)))
537 return reg_overlap_mentioned_p (x
, body
);
540 return reg_overlap_mentioned_p (x
, TRAP_CONDITION (body
));
543 case UNSPEC_VOLATILE
:
544 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
545 if (reg_overlap_mentioned_p (x
, XVECEXP (body
, 0, i
)))
550 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
551 if (reg_referenced_p (x
, XVECEXP (body
, 0, i
)))
556 if (GET_CODE (XEXP (body
, 0)) == MEM
)
557 if (reg_overlap_mentioned_p (x
, XEXP (XEXP (body
, 0), 0)))
562 if (reg_overlap_mentioned_p (x
, COND_EXEC_TEST (body
)))
564 return reg_referenced_p (x
, COND_EXEC_CODE (body
));
571 /* Nonzero if register REG is referenced in an insn between
572 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
576 reg_referenced_between_p (reg
, from_insn
, to_insn
)
577 rtx reg
, from_insn
, to_insn
;
581 if (from_insn
== to_insn
)
584 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
586 && (reg_referenced_p (reg
, PATTERN (insn
))
587 || (GET_CODE (insn
) == CALL_INSN
588 && find_reg_fusage (insn
, USE
, reg
))))
593 /* Nonzero if register REG is set or clobbered in an insn between
594 FROM_INSN and TO_INSN (exclusive of those two). */
597 reg_set_between_p (reg
, from_insn
, to_insn
)
598 rtx reg
, from_insn
, to_insn
;
602 if (from_insn
== to_insn
)
605 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
606 if (INSN_P (insn
) && reg_set_p (reg
, insn
))
611 /* Internals of reg_set_between_p. */
613 static rtx reg_set_reg
;
614 static int reg_set_flag
;
617 reg_set_p_1 (x
, pat
, data
)
619 rtx pat ATTRIBUTE_UNUSED
;
620 void *data ATTRIBUTE_UNUSED
;
622 /* We don't want to return 1 if X is a MEM that contains a register
623 within REG_SET_REG. */
625 if ((GET_CODE (x
) != MEM
)
626 && reg_overlap_mentioned_p (reg_set_reg
, x
))
631 reg_set_p (reg
, insn
)
636 /* We can be passed an insn or part of one. If we are passed an insn,
637 check if a side-effect of the insn clobbers REG. */
640 if (FIND_REG_INC_NOTE (insn
, reg
)
641 || (GET_CODE (insn
) == CALL_INSN
642 /* We'd like to test call_used_regs here, but rtlanal.c can't
643 reference that variable due to its use in genattrtab. So
644 we'll just be more conservative.
646 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
647 information holds all clobbered registers. */
648 && ((GET_CODE (reg
) == REG
649 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
650 || GET_CODE (reg
) == MEM
651 || find_reg_fusage (insn
, CLOBBER
, reg
))))
654 body
= PATTERN (insn
);
659 note_stores (body
, reg_set_p_1
, NULL
);
663 /* Similar to reg_set_between_p, but check all registers in X. Return 0
664 only if none of them are modified between START and END. Do not
665 consider non-registers one way or the other. */
668 regs_set_between_p (x
, start
, end
)
672 enum rtx_code code
= GET_CODE (x
);
688 return reg_set_between_p (x
, start
, end
);
694 fmt
= GET_RTX_FORMAT (code
);
695 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
697 if (fmt
[i
] == 'e' && regs_set_between_p (XEXP (x
, i
), start
, end
))
700 else if (fmt
[i
] == 'E')
701 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
702 if (regs_set_between_p (XVECEXP (x
, i
, j
), start
, end
))
709 /* Similar to reg_set_between_p, but check all registers in X. Return 0
710 only if none of them are modified between START and END. Return 1 if
711 X contains a MEM; this routine does not perform any memory aliasing. */
714 modified_between_p (x
, start
, end
)
718 enum rtx_code code
= GET_CODE (x
);
736 /* If the memory is not constant, assume it is modified. If it is
737 constant, we still have to check the address. */
738 if (! RTX_UNCHANGING_P (x
))
743 return reg_set_between_p (x
, start
, end
);
749 fmt
= GET_RTX_FORMAT (code
);
750 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
752 if (fmt
[i
] == 'e' && modified_between_p (XEXP (x
, i
), start
, end
))
755 else if (fmt
[i
] == 'E')
756 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
757 if (modified_between_p (XVECEXP (x
, i
, j
), start
, end
))
764 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
765 of them are modified in INSN. Return 1 if X contains a MEM; this routine
766 does not perform any memory aliasing. */
769 modified_in_p (x
, insn
)
773 enum rtx_code code
= GET_CODE (x
);
791 /* If the memory is not constant, assume it is modified. If it is
792 constant, we still have to check the address. */
793 if (! RTX_UNCHANGING_P (x
))
798 return reg_set_p (x
, insn
);
804 fmt
= GET_RTX_FORMAT (code
);
805 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
807 if (fmt
[i
] == 'e' && modified_in_p (XEXP (x
, i
), insn
))
810 else if (fmt
[i
] == 'E')
811 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
812 if (modified_in_p (XVECEXP (x
, i
, j
), insn
))
819 /* Return true if anything in insn X is (anti,output,true) dependent on
820 anything in insn Y. */
823 insn_dependent_p (x
, y
)
828 if (! INSN_P (x
) || ! INSN_P (y
))
832 note_stores (PATTERN (x
), insn_dependent_p_1
, &tmp
);
837 note_stores (PATTERN (y
), insn_dependent_p_1
, &tmp
);
844 /* A helper routine for insn_dependent_p called through note_stores. */
847 insn_dependent_p_1 (x
, pat
, data
)
849 rtx pat ATTRIBUTE_UNUSED
;
852 rtx
* pinsn
= (rtx
*) data
;
854 if (*pinsn
&& reg_mentioned_p (x
, *pinsn
))
858 /* Given an INSN, return a SET expression if this insn has only a single SET.
859 It may also have CLOBBERs, USEs, or SET whose output
860 will not be used, which we ignore. */
863 single_set_2 (insn
, pat
)
867 int set_verified
= 1;
870 if (GET_CODE (pat
) == PARALLEL
)
872 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
874 rtx sub
= XVECEXP (pat
, 0, i
);
875 switch (GET_CODE (sub
))
882 /* We can consider insns having multiple sets, where all
883 but one are dead as single set insns. In common case
884 only single set is present in the pattern so we want
885 to avoid checking for REG_UNUSED notes unless neccesary.
887 When we reach set first time, we just expect this is
888 the single set we are looking for and only when more
889 sets are found in the insn, we check them. */
892 if (find_reg_note (insn
, REG_UNUSED
, SET_DEST (set
))
893 && !side_effects_p (set
))
899 set
= sub
, set_verified
= 0;
900 else if (!find_reg_note (insn
, REG_UNUSED
, SET_DEST (sub
))
901 || side_effects_p (sub
))
913 /* Given an INSN, return nonzero if it has more than one SET, else return
923 /* INSN must be an insn. */
927 /* Only a PARALLEL can have multiple SETs. */
928 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
930 for (i
= 0, found
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
931 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
933 /* If we have already found a SET, then return now. */
941 /* Either zero or one SET. */
945 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
946 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
947 If the object was modified, if we hit a partial assignment to X, or hit a
948 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
949 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
953 find_last_value (x
, pinsn
, valid_to
, allow_hwreg
)
961 for (p
= PREV_INSN (*pinsn
); p
&& GET_CODE (p
) != CODE_LABEL
;
965 rtx set
= single_set (p
);
966 rtx note
= find_reg_note (p
, REG_EQUAL
, NULL_RTX
);
968 if (set
&& rtx_equal_p (x
, SET_DEST (set
)))
970 rtx src
= SET_SRC (set
);
972 if (note
&& GET_CODE (XEXP (note
, 0)) != EXPR_LIST
)
973 src
= XEXP (note
, 0);
975 if ((valid_to
== NULL_RTX
976 || ! modified_between_p (src
, PREV_INSN (p
), valid_to
))
977 /* Reject hard registers because we don't usually want
978 to use them; we'd rather use a pseudo. */
979 && (! (GET_CODE (src
) == REG
980 && REGNO (src
) < FIRST_PSEUDO_REGISTER
) || allow_hwreg
))
987 /* If set in non-simple way, we don't have a value. */
988 if (reg_set_p (x
, p
))
995 /* Return nonzero if register in range [REGNO, ENDREGNO)
996 appears either explicitly or implicitly in X
997 other than being stored into.
999 References contained within the substructure at LOC do not count.
1000 LOC may be zero, meaning don't ignore anything. */
1003 refers_to_regno_p (regno
, endregno
, x
, loc
)
1004 unsigned int regno
, endregno
;
1009 unsigned int x_regno
;
1014 /* The contents of a REG_NONNEG note is always zero, so we must come here
1015 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
1019 code
= GET_CODE (x
);
1024 x_regno
= REGNO (x
);
1026 /* If we modifying the stack, frame, or argument pointer, it will
1027 clobber a virtual register. In fact, we could be more precise,
1028 but it isn't worth it. */
1029 if ((x_regno
== STACK_POINTER_REGNUM
1030 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1031 || x_regno
== ARG_POINTER_REGNUM
1033 || x_regno
== FRAME_POINTER_REGNUM
)
1034 && regno
>= FIRST_VIRTUAL_REGISTER
&& regno
<= LAST_VIRTUAL_REGISTER
)
1037 return (endregno
> x_regno
1038 && regno
< x_regno
+ (x_regno
< FIRST_PSEUDO_REGISTER
1039 ? HARD_REGNO_NREGS (x_regno
, GET_MODE (x
))
1043 /* If this is a SUBREG of a hard reg, we can see exactly which
1044 registers are being modified. Otherwise, handle normally. */
1045 if (GET_CODE (SUBREG_REG (x
)) == REG
1046 && REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
)
1048 unsigned int inner_regno
= REGNO (SUBREG_REG (x
)) + SUBREG_WORD (x
);
1049 unsigned int inner_endregno
1050 = inner_regno
+ (inner_regno
< FIRST_PSEUDO_REGISTER
1051 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
1053 return endregno
> inner_regno
&& regno
< inner_endregno
;
1059 if (&SET_DEST (x
) != loc
1060 /* Note setting a SUBREG counts as referring to the REG it is in for
1061 a pseudo but not for hard registers since we can
1062 treat each word individually. */
1063 && ((GET_CODE (SET_DEST (x
)) == SUBREG
1064 && loc
!= &SUBREG_REG (SET_DEST (x
))
1065 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
1066 && REGNO (SUBREG_REG (SET_DEST (x
))) >= FIRST_PSEUDO_REGISTER
1067 && refers_to_regno_p (regno
, endregno
,
1068 SUBREG_REG (SET_DEST (x
)), loc
))
1069 || (GET_CODE (SET_DEST (x
)) != REG
1070 && refers_to_regno_p (regno
, endregno
, SET_DEST (x
), loc
))))
1073 if (code
== CLOBBER
|| loc
== &SET_SRC (x
))
1082 /* X does not match, so try its subexpressions. */
1084 fmt
= GET_RTX_FORMAT (code
);
1085 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1087 if (fmt
[i
] == 'e' && loc
!= &XEXP (x
, i
))
1095 if (refers_to_regno_p (regno
, endregno
, XEXP (x
, i
), loc
))
1098 else if (fmt
[i
] == 'E')
1101 for (j
= XVECLEN (x
, i
) - 1; j
>=0; j
--)
1102 if (loc
!= &XVECEXP (x
, i
, j
)
1103 && refers_to_regno_p (regno
, endregno
, XVECEXP (x
, i
, j
), loc
))
1110 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
1111 we check if any register number in X conflicts with the relevant register
1112 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
1113 contains a MEM (we don't bother checking for memory addresses that can't
1114 conflict because we expect this to be a rare case. */
1117 reg_overlap_mentioned_p (x
, in
)
1120 unsigned int regno
, endregno
;
1122 /* Overly conservative. */
1123 if (GET_CODE (x
) == STRICT_LOW_PART
)
1126 /* If either argument is a constant, then modifying X can not affect IN. */
1127 if (CONSTANT_P (x
) || CONSTANT_P (in
))
1130 switch (GET_CODE (x
))
1133 regno
= REGNO (SUBREG_REG (x
));
1134 if (regno
< FIRST_PSEUDO_REGISTER
)
1135 regno
+= SUBREG_WORD (x
);
1141 endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
1142 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
1143 return refers_to_regno_p (regno
, endregno
, in
, NULL_PTR
);
1150 if (GET_CODE (in
) == MEM
)
1153 fmt
= GET_RTX_FORMAT (GET_CODE (in
));
1154 for (i
= GET_RTX_LENGTH (GET_CODE (in
)) - 1; i
>= 0; i
--)
1155 if (fmt
[i
] == 'e' && reg_overlap_mentioned_p (x
, XEXP (in
, i
)))
1164 return reg_mentioned_p (x
, in
);
1170 /* Check for a NULL entry, used to indicate that the parameter goes
1171 both on the stack and in registers. */
1172 if (XEXP (XVECEXP (x
, 0, 0), 0))
1177 /* If any register in here refers to it we return true. */
1178 for (n
= XVECLEN (x
, 0); i
< n
; ++i
)
1179 if (reg_overlap_mentioned_p (XEXP (XVECEXP (x
, 0, i
), 0), in
))
1191 /* Used for communications between the next few functions. */
1193 static int reg_set_last_unknown
;
1194 static rtx reg_set_last_value
;
1195 static unsigned int reg_set_last_first_regno
, reg_set_last_last_regno
;
1197 /* Called via note_stores from reg_set_last. */
1200 reg_set_last_1 (x
, pat
, data
)
1203 void *data ATTRIBUTE_UNUSED
;
1205 unsigned int first
, last
;
1207 /* If X is not a register, or is not one in the range we care
1209 if (GET_CODE (x
) != REG
)
1213 last
= first
+ (first
< FIRST_PSEUDO_REGISTER
1214 ? HARD_REGNO_NREGS (first
, GET_MODE (x
)) : 1);
1216 if (first
>= reg_set_last_last_regno
1217 || last
<= reg_set_last_first_regno
)
1220 /* If this is a CLOBBER or is some complex LHS, or doesn't modify
1221 exactly the registers we care about, show we don't know the value. */
1222 if (GET_CODE (pat
) == CLOBBER
|| SET_DEST (pat
) != x
1223 || first
!= reg_set_last_first_regno
1224 || last
!= reg_set_last_last_regno
)
1225 reg_set_last_unknown
= 1;
1227 reg_set_last_value
= SET_SRC (pat
);
1230 /* Return the last value to which REG was set prior to INSN. If we can't
1231 find it easily, return 0.
1233 We only return a REG, SUBREG, or constant because it is too hard to
1234 check if a MEM remains unchanged. */
1237 reg_set_last (x
, insn
)
1241 rtx orig_insn
= insn
;
1243 reg_set_last_first_regno
= REGNO (x
);
1245 reg_set_last_last_regno
1246 = reg_set_last_first_regno
1247 + (reg_set_last_first_regno
< FIRST_PSEUDO_REGISTER
1248 ? HARD_REGNO_NREGS (reg_set_last_first_regno
, GET_MODE (x
)) : 1);
1250 reg_set_last_unknown
= 0;
1251 reg_set_last_value
= 0;
1253 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1254 Stop when we reach a label or X is a hard reg and we reach a
1255 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1257 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1259 /* We compare with <= here, because reg_set_last_last_regno
1260 is actually the number of the first reg *not* in X. */
1262 insn
&& GET_CODE (insn
) != CODE_LABEL
1263 && ! (GET_CODE (insn
) == CALL_INSN
1264 && reg_set_last_last_regno
<= FIRST_PSEUDO_REGISTER
);
1265 insn
= PREV_INSN (insn
))
1268 note_stores (PATTERN (insn
), reg_set_last_1
, NULL
);
1269 if (reg_set_last_unknown
)
1271 else if (reg_set_last_value
)
1273 if (CONSTANT_P (reg_set_last_value
)
1274 || ((GET_CODE (reg_set_last_value
) == REG
1275 || GET_CODE (reg_set_last_value
) == SUBREG
)
1276 && ! reg_set_between_p (reg_set_last_value
,
1278 return reg_set_last_value
;
1287 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1288 (X would be the pattern of an insn).
1289 FUN receives two arguments:
1290 the REG, MEM, CC0 or PC being stored in or clobbered,
1291 the SET or CLOBBER rtx that does the store.
1293 If the item being stored in or clobbered is a SUBREG of a hard register,
1294 the SUBREG will be passed. */
1297 note_stores (x
, fun
, data
)
1299 void (*fun
) PARAMS ((rtx
, rtx
, void *));
1302 if (GET_CODE (x
) == COND_EXEC
)
1303 x
= COND_EXEC_CODE (x
);
1304 if (GET_CODE (x
) == SET
|| GET_CODE (x
) == CLOBBER
)
1306 register rtx dest
= SET_DEST (x
);
1307 while ((GET_CODE (dest
) == SUBREG
1308 && (GET_CODE (SUBREG_REG (dest
)) != REG
1309 || REGNO (SUBREG_REG (dest
)) >= FIRST_PSEUDO_REGISTER
))
1310 || GET_CODE (dest
) == ZERO_EXTRACT
1311 || GET_CODE (dest
) == SIGN_EXTRACT
1312 || GET_CODE (dest
) == STRICT_LOW_PART
)
1313 dest
= XEXP (dest
, 0);
1315 if (GET_CODE (dest
) == PARALLEL
1316 && GET_MODE (dest
) == BLKmode
)
1319 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1320 (*fun
) (SET_DEST (XVECEXP (dest
, 0, i
)), x
, data
);
1323 (*fun
) (dest
, x
, data
);
1325 else if (GET_CODE (x
) == PARALLEL
)
1328 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1330 register rtx y
= XVECEXP (x
, 0, i
);
1331 if (GET_CODE (y
) == COND_EXEC
)
1332 y
= COND_EXEC_CODE (y
);
1333 if (GET_CODE (y
) == SET
|| GET_CODE (y
) == CLOBBER
)
1335 register rtx dest
= SET_DEST (y
);
1336 while ((GET_CODE (dest
) == SUBREG
1337 && (GET_CODE (SUBREG_REG (dest
)) != REG
1338 || (REGNO (SUBREG_REG (dest
))
1339 >= FIRST_PSEUDO_REGISTER
)))
1340 || GET_CODE (dest
) == ZERO_EXTRACT
1341 || GET_CODE (dest
) == SIGN_EXTRACT
1342 || GET_CODE (dest
) == STRICT_LOW_PART
)
1343 dest
= XEXP (dest
, 0);
1344 if (GET_CODE (dest
) == PARALLEL
1345 && GET_MODE (dest
) == BLKmode
)
1349 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1350 (*fun
) (SET_DEST (XVECEXP (dest
, 0, i
)), y
, data
);
1353 (*fun
) (dest
, y
, data
);
1359 /* Return nonzero if X's old contents don't survive after INSN.
1360 This will be true if X is (cc0) or if X is a register and
1361 X dies in INSN or because INSN entirely sets X.
1363 "Entirely set" means set directly and not through a SUBREG,
1364 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1365 Likewise, REG_INC does not count.
1367 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1368 but for this use that makes no difference, since regs don't overlap
1369 during their lifetimes. Therefore, this function may be used
1370 at any time after deaths have been computed (in flow.c).
1372 If REG is a hard reg that occupies multiple machine registers, this
1373 function will only return 1 if each of those registers will be replaced
1377 dead_or_set_p (insn
, x
)
1381 unsigned int regno
, last_regno
;
1384 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1385 if (GET_CODE (x
) == CC0
)
1388 if (GET_CODE (x
) != REG
)
1392 last_regno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
1393 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
)) - 1);
1395 for (i
= regno
; i
<= last_regno
; i
++)
1396 if (! dead_or_set_regno_p (insn
, i
))
1402 /* Utility function for dead_or_set_p to check an individual register. Also
1403 called from flow.c. */
1406 dead_or_set_regno_p (insn
, test_regno
)
1408 unsigned int test_regno
;
1410 unsigned int regno
, endregno
;
1413 /* See if there is a death note for something that includes TEST_REGNO. */
1414 if (find_regno_note (insn
, REG_DEAD
, test_regno
))
1417 if (GET_CODE (insn
) == CALL_INSN
1418 && find_regno_fusage (insn
, CLOBBER
, test_regno
))
1421 pattern
= PATTERN (insn
);
1423 if (GET_CODE (pattern
) == COND_EXEC
)
1424 pattern
= COND_EXEC_CODE (pattern
);
1426 if (GET_CODE (pattern
) == SET
)
1428 rtx dest
= SET_DEST (PATTERN (insn
));
1430 /* A value is totally replaced if it is the destination or the
1431 destination is a SUBREG of REGNO that does not change the number of
1433 if (GET_CODE (dest
) == SUBREG
1434 && (((GET_MODE_SIZE (GET_MODE (dest
))
1435 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1436 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1437 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1438 dest
= SUBREG_REG (dest
);
1440 if (GET_CODE (dest
) != REG
)
1443 regno
= REGNO (dest
);
1444 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1445 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1447 return (test_regno
>= regno
&& test_regno
< endregno
);
1449 else if (GET_CODE (pattern
) == PARALLEL
)
1453 for (i
= XVECLEN (pattern
, 0) - 1; i
>= 0; i
--)
1455 rtx body
= XVECEXP (pattern
, 0, i
);
1457 if (GET_CODE (body
) == COND_EXEC
)
1458 body
= COND_EXEC_CODE (body
);
1460 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == CLOBBER
)
1462 rtx dest
= SET_DEST (body
);
1464 if (GET_CODE (dest
) == SUBREG
1465 && (((GET_MODE_SIZE (GET_MODE (dest
))
1466 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1467 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1468 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1469 dest
= SUBREG_REG (dest
);
1471 if (GET_CODE (dest
) != REG
)
1474 regno
= REGNO (dest
);
1475 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1476 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1478 if (test_regno
>= regno
&& test_regno
< endregno
)
1487 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1488 If DATUM is nonzero, look for one whose datum is DATUM. */
1491 find_reg_note (insn
, kind
, datum
)
1498 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1499 if (! INSN_P (insn
))
1502 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1503 if (REG_NOTE_KIND (link
) == kind
1504 && (datum
== 0 || datum
== XEXP (link
, 0)))
1509 /* Return the reg-note of kind KIND in insn INSN which applies to register
1510 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1511 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1512 it might be the case that the note overlaps REGNO. */
1515 find_regno_note (insn
, kind
, regno
)
1522 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1523 if (! INSN_P (insn
))
1526 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1527 if (REG_NOTE_KIND (link
) == kind
1528 /* Verify that it is a register, so that scratch and MEM won't cause a
1530 && GET_CODE (XEXP (link
, 0)) == REG
1531 && REGNO (XEXP (link
, 0)) <= regno
1532 && ((REGNO (XEXP (link
, 0))
1533 + (REGNO (XEXP (link
, 0)) >= FIRST_PSEUDO_REGISTER
? 1
1534 : HARD_REGNO_NREGS (REGNO (XEXP (link
, 0)),
1535 GET_MODE (XEXP (link
, 0)))))
1541 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1542 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1545 find_reg_fusage (insn
, code
, datum
)
1550 /* If it's not a CALL_INSN, it can't possibly have a
1551 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1552 if (GET_CODE (insn
) != CALL_INSN
)
1558 if (GET_CODE (datum
) != REG
)
1562 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1564 link
= XEXP (link
, 1))
1565 if (GET_CODE (XEXP (link
, 0)) == code
1566 && rtx_equal_p (datum
, SET_DEST (XEXP (link
, 0))))
1571 unsigned int regno
= REGNO (datum
);
1573 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1574 to pseudo registers, so don't bother checking. */
1576 if (regno
< FIRST_PSEUDO_REGISTER
)
1578 unsigned int end_regno
1579 = regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (datum
));
1582 for (i
= regno
; i
< end_regno
; i
++)
1583 if (find_regno_fusage (insn
, code
, i
))
1591 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1592 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1595 find_regno_fusage (insn
, code
, regno
)
1602 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1603 to pseudo registers, so don't bother checking. */
1605 if (regno
>= FIRST_PSEUDO_REGISTER
1606 || GET_CODE (insn
) != CALL_INSN
)
1609 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
1611 unsigned int regnote
;
1614 if (GET_CODE (op
= XEXP (link
, 0)) == code
1615 && GET_CODE (reg
= XEXP (op
, 0)) == REG
1616 && (regnote
= REGNO (reg
)) <= regno
1617 && regnote
+ HARD_REGNO_NREGS (regnote
, GET_MODE (reg
)) > regno
)
1624 /* Remove register note NOTE from the REG_NOTES of INSN. */
1627 remove_note (insn
, note
)
1633 if (note
== NULL_RTX
)
1636 if (REG_NOTES (insn
) == note
)
1638 REG_NOTES (insn
) = XEXP (note
, 1);
1642 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1643 if (XEXP (link
, 1) == note
)
1645 XEXP (link
, 1) = XEXP (note
, 1);
1652 /* Search LISTP (an EXPR_LIST) for NODE and remove NODE from the list
1655 A simple equality test is used to determine if NODE is on the
1659 remove_node_from_expr_list (node
, listp
)
1664 rtx prev
= NULL_RTX
;
1668 if (node
== XEXP (temp
, 0))
1670 /* Splice the node out of the list. */
1672 XEXP (prev
, 1) = XEXP (temp
, 1);
1674 *listp
= XEXP (temp
, 1);
1678 temp
= XEXP (temp
, 1);
1682 /* Nonzero if X contains any volatile instructions. These are instructions
1683 which may cause unpredictable machine state instructions, and thus no
1684 instructions should be moved or combined across them. This includes
1685 only volatile asms and UNSPEC_VOLATILE instructions. */
1691 register RTX_CODE code
;
1693 code
= GET_CODE (x
);
1713 case UNSPEC_VOLATILE
:
1714 /* case TRAP_IF: This isn't clear yet. */
1718 if (MEM_VOLATILE_P (x
))
1725 /* Recursively scan the operands of this expression. */
1728 register const char *fmt
= GET_RTX_FORMAT (code
);
1731 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1735 if (volatile_insn_p (XEXP (x
, i
)))
1738 else if (fmt
[i
] == 'E')
1741 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1742 if (volatile_insn_p (XVECEXP (x
, i
, j
)))
1750 /* Nonzero if X contains any volatile memory references
1751 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1757 register RTX_CODE code
;
1759 code
= GET_CODE (x
);
1778 case UNSPEC_VOLATILE
:
1779 /* case TRAP_IF: This isn't clear yet. */
1784 if (MEM_VOLATILE_P (x
))
1791 /* Recursively scan the operands of this expression. */
1794 register const char *fmt
= GET_RTX_FORMAT (code
);
1797 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1801 if (volatile_refs_p (XEXP (x
, i
)))
1804 else if (fmt
[i
] == 'E')
1807 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1808 if (volatile_refs_p (XVECEXP (x
, i
, j
)))
1816 /* Similar to above, except that it also rejects register pre- and post-
1823 register RTX_CODE code
;
1825 code
= GET_CODE (x
);
1843 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1844 when some combination can't be done. If we see one, don't think
1845 that we can simplify the expression. */
1846 return (GET_MODE (x
) != VOIDmode
);
1855 case UNSPEC_VOLATILE
:
1856 /* case TRAP_IF: This isn't clear yet. */
1861 if (MEM_VOLATILE_P (x
))
1868 /* Recursively scan the operands of this expression. */
1871 register const char *fmt
= GET_RTX_FORMAT (code
);
1874 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1878 if (side_effects_p (XEXP (x
, i
)))
1881 else if (fmt
[i
] == 'E')
1884 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1885 if (side_effects_p (XVECEXP (x
, i
, j
)))
1893 /* Return nonzero if evaluating rtx X might cause a trap. */
1905 code
= GET_CODE (x
);
1908 /* Handle these cases quickly. */
1921 case UNSPEC_VOLATILE
:
1926 return MEM_VOLATILE_P (x
);
1928 /* Memory ref can trap unless it's a static var or a stack slot. */
1930 return rtx_addr_can_trap_p (XEXP (x
, 0));
1932 /* Division by a non-constant might trap. */
1937 if (! CONSTANT_P (XEXP (x
, 1))
1938 || GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1940 /* This was const0_rtx, but by not using that,
1941 we can link this file into other programs. */
1942 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
&& INTVAL (XEXP (x
, 1)) == 0)
1947 /* An EXPR_LIST is used to represent a function call. This
1948 certainly may trap. */
1956 /* Some floating point comparisons may trap. */
1957 /* ??? There is no machine independent way to check for tests that trap
1958 when COMPARE is used, though many targets do make this distinction.
1959 For instance, sparc uses CCFPE for compares which generate exceptions
1960 and CCFP for compares which do not generate exceptions. */
1961 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1963 /* But often the compare has some CC mode, so check operand
1965 if (GET_MODE_CLASS (GET_MODE (XEXP (x
, 0))) == MODE_FLOAT
1966 || GET_MODE_CLASS (GET_MODE (XEXP (x
, 1))) == MODE_FLOAT
)
1971 /* Any floating arithmetic may trap. */
1972 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1976 fmt
= GET_RTX_FORMAT (code
);
1977 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1981 if (may_trap_p (XEXP (x
, i
)))
1984 else if (fmt
[i
] == 'E')
1987 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1988 if (may_trap_p (XVECEXP (x
, i
, j
)))
1995 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1996 i.e., an inequality. */
1999 inequality_comparisons_p (x
)
2002 register const char *fmt
;
2003 register int len
, i
;
2004 register enum rtx_code code
= GET_CODE (x
);
2033 len
= GET_RTX_LENGTH (code
);
2034 fmt
= GET_RTX_FORMAT (code
);
2036 for (i
= 0; i
< len
; i
++)
2040 if (inequality_comparisons_p (XEXP (x
, i
)))
2043 else if (fmt
[i
] == 'E')
2046 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2047 if (inequality_comparisons_p (XVECEXP (x
, i
, j
)))
2055 /* Replace any occurrence of FROM in X with TO. The function does
2056 not enter into CONST_DOUBLE for the replace.
2058 Note that copying is not done so X must not be shared unless all copies
2059 are to be modified. */
2062 replace_rtx (x
, from
, to
)
2066 register const char *fmt
;
2068 /* The following prevents loops occurrence when we change MEM in
2069 CONST_DOUBLE onto the same CONST_DOUBLE. */
2070 if (x
!= 0 && GET_CODE (x
) == CONST_DOUBLE
)
2076 /* Allow this function to make replacements in EXPR_LISTs. */
2080 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2081 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2084 XEXP (x
, i
) = replace_rtx (XEXP (x
, i
), from
, to
);
2085 else if (fmt
[i
] == 'E')
2086 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2087 XVECEXP (x
, i
, j
) = replace_rtx (XVECEXP (x
, i
, j
), from
, to
);
2093 /* Throughout the rtx X, replace many registers according to REG_MAP.
2094 Return the replacement for X (which may be X with altered contents).
2095 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
2096 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
2098 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
2099 should not be mapped to pseudos or vice versa since validate_change
2102 If REPLACE_DEST is 1, replacements are also done in destinations;
2103 otherwise, only sources are replaced. */
2106 replace_regs (x
, reg_map
, nregs
, replace_dest
)
2112 register enum rtx_code code
;
2114 register const char *fmt
;
2119 code
= GET_CODE (x
);
2133 /* Verify that the register has an entry before trying to access it. */
2134 if (REGNO (x
) < nregs
&& reg_map
[REGNO (x
)] != 0)
2136 /* SUBREGs can't be shared. Always return a copy to ensure that if
2137 this replacement occurs more than once then each instance will
2138 get distinct rtx. */
2139 if (GET_CODE (reg_map
[REGNO (x
)]) == SUBREG
)
2140 return copy_rtx (reg_map
[REGNO (x
)]);
2141 return reg_map
[REGNO (x
)];
2146 /* Prevent making nested SUBREGs. */
2147 if (GET_CODE (SUBREG_REG (x
)) == REG
&& REGNO (SUBREG_REG (x
)) < nregs
2148 && reg_map
[REGNO (SUBREG_REG (x
))] != 0
2149 && GET_CODE (reg_map
[REGNO (SUBREG_REG (x
))]) == SUBREG
)
2151 rtx map_val
= reg_map
[REGNO (SUBREG_REG (x
))];
2152 rtx map_inner
= SUBREG_REG (map_val
);
2154 if (GET_MODE (x
) == GET_MODE (map_inner
))
2158 /* We cannot call gen_rtx here since we may be linked with
2160 /* Let's try clobbering the incoming SUBREG and see
2161 if this is really safe. */
2162 SUBREG_REG (x
) = map_inner
;
2163 SUBREG_WORD (x
) += SUBREG_WORD (map_val
);
2166 rtx
new = rtx_alloc (SUBREG
);
2167 PUT_MODE (new, GET_MODE (x
));
2168 SUBREG_REG (new) = map_inner
;
2169 SUBREG_WORD (new) = SUBREG_WORD (x
) + SUBREG_WORD (map_val
);
2177 SET_DEST (x
) = replace_regs (SET_DEST (x
), reg_map
, nregs
, 0);
2179 else if (GET_CODE (SET_DEST (x
)) == MEM
2180 || GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2181 /* Even if we are not to replace destinations, replace register if it
2182 is CONTAINED in destination (destination is memory or
2183 STRICT_LOW_PART). */
2184 XEXP (SET_DEST (x
), 0) = replace_regs (XEXP (SET_DEST (x
), 0),
2186 else if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2187 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2190 SET_SRC (x
) = replace_regs (SET_SRC (x
), reg_map
, nregs
, 0);
2197 fmt
= GET_RTX_FORMAT (code
);
2198 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2201 XEXP (x
, i
) = replace_regs (XEXP (x
, i
), reg_map
, nregs
, replace_dest
);
2202 else if (fmt
[i
] == 'E')
2205 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2206 XVECEXP (x
, i
, j
) = replace_regs (XVECEXP (x
, i
, j
), reg_map
,
2207 nregs
, replace_dest
);
2213 /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is
2214 not in the constant pool and not in the condition of an IF_THEN_ELSE. */
2217 jmp_uses_reg_or_mem (x
)
2220 enum rtx_code code
= GET_CODE (x
);
2235 return ! (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
2236 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)));
2239 return (jmp_uses_reg_or_mem (XEXP (x
, 1))
2240 || jmp_uses_reg_or_mem (XEXP (x
, 2)));
2242 case PLUS
: case MINUS
: case MULT
:
2243 return (jmp_uses_reg_or_mem (XEXP (x
, 0))
2244 || jmp_uses_reg_or_mem (XEXP (x
, 1)));
2250 fmt
= GET_RTX_FORMAT (code
);
2251 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2254 && jmp_uses_reg_or_mem (XEXP (x
, i
)))
2257 else if (fmt
[i
] == 'E')
2258 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2259 if (jmp_uses_reg_or_mem (XVECEXP (x
, i
, j
)))
2266 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2268 Tablejumps and casesi insns are not considered indirect jumps;
2269 we can recognize them by a (use (label_ref)). */
2272 computed_jump_p (insn
)
2276 if (GET_CODE (insn
) == JUMP_INSN
)
2278 rtx pat
= PATTERN (insn
);
2280 if (GET_CODE (pat
) == PARALLEL
)
2282 int len
= XVECLEN (pat
, 0);
2283 int has_use_labelref
= 0;
2285 for (i
= len
- 1; i
>= 0; i
--)
2286 if (GET_CODE (XVECEXP (pat
, 0, i
)) == USE
2287 && (GET_CODE (XEXP (XVECEXP (pat
, 0, i
), 0))
2289 has_use_labelref
= 1;
2291 if (! has_use_labelref
)
2292 for (i
= len
- 1; i
>= 0; i
--)
2293 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
2294 && SET_DEST (XVECEXP (pat
, 0, i
)) == pc_rtx
2295 && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat
, 0, i
))))
2298 else if (GET_CODE (pat
) == SET
2299 && SET_DEST (pat
) == pc_rtx
2300 && jmp_uses_reg_or_mem (SET_SRC (pat
)))
2306 /* Traverse X via depth-first search, calling F for each
2307 sub-expression (including X itself). F is also passed the DATA.
2308 If F returns -1, do not traverse sub-expressions, but continue
2309 traversing the rest of the tree. If F ever returns any other
2310 non-zero value, stop the traversal, and return the value returned
2311 by F. Otherwise, return 0. This function does not traverse inside
2312 tree structure that contains RTX_EXPRs, or into sub-expressions
2313 whose format code is `0' since it is not known whether or not those
2314 codes are actually RTL.
2316 This routine is very general, and could (should?) be used to
2317 implement many of the other routines in this file. */
2320 for_each_rtx (x
, f
, data
)
2331 result
= (*f
)(x
, data
);
2333 /* Do not traverse sub-expressions. */
2335 else if (result
!= 0)
2336 /* Stop the traversal. */
2340 /* There are no sub-expressions. */
2343 length
= GET_RTX_LENGTH (GET_CODE (*x
));
2344 format
= GET_RTX_FORMAT (GET_CODE (*x
));
2346 for (i
= 0; i
< length
; ++i
)
2351 result
= for_each_rtx (&XEXP (*x
, i
), f
, data
);
2358 if (XVEC (*x
, i
) != 0)
2361 for (j
= 0; j
< XVECLEN (*x
, i
); ++j
)
2363 result
= for_each_rtx (&XVECEXP (*x
, i
, j
), f
, data
);
2371 /* Nothing to do. */
2380 /* Searches X for any reference to REGNO, returning the rtx of the
2381 reference found if any. Otherwise, returns NULL_RTX. */
2384 regno_use_in (regno
, x
)
2388 register const char *fmt
;
2392 if (GET_CODE (x
) == REG
&& REGNO (x
) == regno
)
2395 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2396 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2400 if ((tem
= regno_use_in (regno
, XEXP (x
, i
))))
2403 else if (fmt
[i
] == 'E')
2404 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2405 if ((tem
= regno_use_in (regno
, XVECEXP (x
, i
, j
))))
2413 /* Return 1 if X is an autoincrement side effect and the register is
2414 not the stack pointer. */
2419 switch (GET_CODE (x
))
2427 /* There are no REG_INC notes for SP. */
2428 if (XEXP (x
, 0) != stack_pointer_rtx
)
2436 /* Return 1 if the sequence of instructions beginning with FROM and up
2437 to and including TO is safe to move. If NEW_TO is non-NULL, and
2438 the sequence is not already safe to move, but can be easily
2439 extended to a sequence which is safe, then NEW_TO will point to the
2440 end of the extended sequence.
2442 For now, this function only checks that the region contains whole
2443 exception regiongs, but it could be extended to check additional
2444 conditions as well. */
2447 insns_safe_to_move_p (from
, to
, new_to
)
2452 int eh_region_count
= 0;
2456 /* By default, assume the end of the region will be what was
2463 if (GET_CODE (r
) == NOTE
)
2465 switch (NOTE_LINE_NUMBER (r
))
2467 case NOTE_INSN_EH_REGION_BEG
:
2471 case NOTE_INSN_EH_REGION_END
:
2472 if (eh_region_count
== 0)
2473 /* This sequence of instructions contains the end of
2474 an exception region, but not he beginning. Moving
2475 it will cause chaos. */
2486 /* If we've passed TO, and we see a non-note instruction, we
2487 can't extend the sequence to a movable sequence. */
2493 /* It's OK to move the sequence if there were matched sets of
2494 exception region notes. */
2495 return eh_region_count
== 0;
2500 /* It's OK to move the sequence if there were matched sets of
2501 exception region notes. */
2502 if (past_to_p
&& eh_region_count
== 0)
2508 /* Go to the next instruction. */
2515 /* Return non-zero if IN contains a piece of rtl that has the address LOC */
2517 loc_mentioned_in_p (loc
, in
)
2520 enum rtx_code code
= GET_CODE (in
);
2521 const char *fmt
= GET_RTX_FORMAT (code
);
2524 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2526 if (loc
== &in
->fld
[i
].rtx
)
2530 if (loc_mentioned_in_p (loc
, XEXP (in
, i
)))
2533 else if (fmt
[i
] == 'E')
2534 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
2535 if (loc_mentioned_in_p (loc
, XVECEXP (in
, i
, j
)))