1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of 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 void set_of_1
PARAMS ((rtx
, rtx
, void *));
29 static void insn_dependent_p_1
PARAMS ((rtx
, rtx
, void *));
31 /* Forward declarations */
32 static int computed_jump_p_1
PARAMS ((rtx
));
34 /* Bit flags that specify the machine subtype we are compiling for.
35 Bits are tested using macros TARGET_... defined in the tm.h file
36 and set by `-m...' switches. Must be defined in rtlanal.c. */
40 /* Return 1 if the value of X is unstable
41 (would be different at a different point in the program).
42 The frame pointer, arg pointer, etc. are considered stable
43 (within one function) and so is anything marked `unchanging'. */
49 register RTX_CODE code
= GET_CODE (x
);
51 register const char *fmt
;
56 return ! RTX_UNCHANGING_P (x
) || rtx_unstable_p (XEXP (x
, 0));
69 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
70 if (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
71 || x
== arg_pointer_rtx
|| RTX_UNCHANGING_P (x
))
73 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
74 /* ??? When call-clobbered, the value is stable modulo the restore
75 that must happen after a call. This currently screws up local-alloc
76 into believing that the restore is not needed. */
77 if (x
== pic_offset_table_rtx
)
83 if (MEM_VOLATILE_P (x
))
92 fmt
= GET_RTX_FORMAT (code
);
93 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
96 if (rtx_unstable_p (XEXP (x
, i
)))
99 else if (fmt
[i
] == 'E')
102 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
103 if (rtx_unstable_p (XVECEXP (x
, i
, j
)))
110 /* Return 1 if X has a value that can vary even between two
111 executions of the program. 0 means X can be compared reliably
112 against certain constants or near-constants.
113 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
114 zero, we are slightly more conservative.
115 The frame pointer and the arg pointer are considered constant. */
118 rtx_varies_p (x
, for_alias
)
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), for_alias
);
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 if (x
== pic_offset_table_rtx
150 #ifdef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
151 /* ??? When call-clobbered, the value is stable modulo the restore
152 that must happen after a call. This currently screws up
153 local-alloc into believing that the restore is not needed, so we
154 must return 0 only if we are called from alias analysis. */
162 /* The operand 0 of a LO_SUM is considered constant
163 (in fact is it related specifically to operand 1). */
164 return rtx_varies_p (XEXP (x
, 1), for_alias
);
167 if (MEM_VOLATILE_P (x
))
176 fmt
= GET_RTX_FORMAT (code
);
177 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
180 if (rtx_varies_p (XEXP (x
, i
), for_alias
))
183 else if (fmt
[i
] == 'E')
186 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
187 if (rtx_varies_p (XVECEXP (x
, i
, j
), for_alias
))
194 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
197 rtx_addr_can_trap_p (x
)
200 register enum rtx_code code
= GET_CODE (x
);
206 /* SYMBOL_REF is problematic due to the possible presence of
207 a #pragma weak, but to say that loads from symbols can trap is
208 *very* costly. It's not at all clear what's best here. For
209 now, we ignore the impact of #pragma weak. */
213 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
214 return ! (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
215 || x
== stack_pointer_rtx
|| x
== arg_pointer_rtx
);
218 return rtx_addr_can_trap_p (XEXP (x
, 0));
221 /* An address is assumed not to trap if it is an address that can't
222 trap plus a constant integer or it is the pic register plus a
224 return ! ((! rtx_addr_can_trap_p (XEXP (x
, 0))
225 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
226 || (XEXP (x
, 0) == pic_offset_table_rtx
227 && CONSTANT_P (XEXP (x
, 1))));
230 return rtx_addr_can_trap_p (XEXP (x
, 1));
236 /* If it isn't one of the case above, it can cause a trap. */
240 /* Return 1 if X refers to a memory location whose address
241 cannot be compared reliably with constant addresses,
242 or if X refers to a BLKmode memory object.
243 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
244 zero, we are slightly more conservative. */
247 rtx_addr_varies_p (x
, for_alias
)
251 register enum rtx_code code
;
253 register const char *fmt
;
260 return GET_MODE (x
) == BLKmode
|| rtx_varies_p (XEXP (x
, 0), for_alias
);
262 fmt
= GET_RTX_FORMAT (code
);
263 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
266 if (rtx_addr_varies_p (XEXP (x
, i
), for_alias
))
269 else if (fmt
[i
] == 'E')
272 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
273 if (rtx_addr_varies_p (XVECEXP (x
, i
, j
), for_alias
))
279 /* Return the value of the integer term in X, if one is apparent;
281 Only obvious integer terms are detected.
282 This is used in cse.c with the `related_value' field.*/
288 if (GET_CODE (x
) == CONST
)
291 if (GET_CODE (x
) == MINUS
292 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
293 return - INTVAL (XEXP (x
, 1));
294 if (GET_CODE (x
) == PLUS
295 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
296 return INTVAL (XEXP (x
, 1));
300 /* If X is a constant, return the value sans apparent integer term;
302 Only obvious integer terms are detected. */
305 get_related_value (x
)
308 if (GET_CODE (x
) != CONST
)
311 if (GET_CODE (x
) == PLUS
312 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
314 else if (GET_CODE (x
) == MINUS
315 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
320 /* Return the number of places FIND appears within X. If COUNT_DEST is
321 zero, we do not count occurrences inside the destination of a SET. */
324 count_occurrences (x
, find
, count_dest
)
330 const char *format_ptr
;
350 if (GET_CODE (find
) == MEM
&& rtx_equal_p (x
, find
))
355 if (SET_DEST (x
) == find
&& ! count_dest
)
356 return count_occurrences (SET_SRC (x
), find
, count_dest
);
363 format_ptr
= GET_RTX_FORMAT (code
);
366 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
368 switch (*format_ptr
++)
371 count
+= count_occurrences (XEXP (x
, i
), find
, count_dest
);
375 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
376 count
+= count_occurrences (XVECEXP (x
, i
, j
), find
, count_dest
);
383 /* Nonzero if register REG appears somewhere within IN.
384 Also works if REG is not a register; in this case it checks
385 for a subexpression of IN that is Lisp "equal" to REG. */
388 reg_mentioned_p (reg
, in
)
389 register rtx reg
, in
;
391 register const char *fmt
;
393 register enum rtx_code code
;
401 if (GET_CODE (in
) == LABEL_REF
)
402 return reg
== XEXP (in
, 0);
404 code
= GET_CODE (in
);
408 /* Compare registers by number. */
410 return GET_CODE (reg
) == REG
&& REGNO (in
) == REGNO (reg
);
412 /* These codes have no constituent expressions
420 return GET_CODE (reg
) == CONST_INT
&& INTVAL (in
) == INTVAL (reg
);
423 /* These are kept unique for a given value. */
430 if (GET_CODE (reg
) == code
&& rtx_equal_p (reg
, in
))
433 fmt
= GET_RTX_FORMAT (code
);
435 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
440 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
441 if (reg_mentioned_p (reg
, XVECEXP (in
, i
, j
)))
444 else if (fmt
[i
] == 'e'
445 && reg_mentioned_p (reg
, XEXP (in
, i
)))
451 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
452 no CODE_LABEL insn. */
455 no_labels_between_p (beg
, end
)
459 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
460 if (GET_CODE (p
) == CODE_LABEL
)
465 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
466 no JUMP_INSN insn. */
469 no_jumps_between_p (beg
, end
)
473 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
474 if (GET_CODE (p
) == JUMP_INSN
)
479 /* Nonzero if register REG is used in an insn between
480 FROM_INSN and TO_INSN (exclusive of those two). */
483 reg_used_between_p (reg
, from_insn
, to_insn
)
484 rtx reg
, from_insn
, to_insn
;
488 if (from_insn
== to_insn
)
491 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
493 && (reg_overlap_mentioned_p (reg
, PATTERN (insn
))
494 || (GET_CODE (insn
) == CALL_INSN
495 && (find_reg_fusage (insn
, USE
, reg
)
496 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
501 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
502 is entirely replaced by a new value and the only use is as a SET_DEST,
503 we do not consider it a reference. */
506 reg_referenced_p (x
, body
)
512 switch (GET_CODE (body
))
515 if (reg_overlap_mentioned_p (x
, SET_SRC (body
)))
518 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
519 of a REG that occupies all of the REG, the insn references X if
520 it is mentioned in the destination. */
521 if (GET_CODE (SET_DEST (body
)) != CC0
522 && GET_CODE (SET_DEST (body
)) != PC
523 && GET_CODE (SET_DEST (body
)) != REG
524 && ! (GET_CODE (SET_DEST (body
)) == SUBREG
525 && GET_CODE (SUBREG_REG (SET_DEST (body
))) == REG
526 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body
))))
527 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
528 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body
)))
529 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)))
530 && reg_overlap_mentioned_p (x
, SET_DEST (body
)))
535 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
536 if (reg_overlap_mentioned_p (x
, ASM_OPERANDS_INPUT (body
, i
)))
543 return reg_overlap_mentioned_p (x
, body
);
546 return reg_overlap_mentioned_p (x
, TRAP_CONDITION (body
));
549 case UNSPEC_VOLATILE
:
550 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
551 if (reg_overlap_mentioned_p (x
, XVECEXP (body
, 0, i
)))
556 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
557 if (reg_referenced_p (x
, XVECEXP (body
, 0, i
)))
562 if (GET_CODE (XEXP (body
, 0)) == MEM
)
563 if (reg_overlap_mentioned_p (x
, XEXP (XEXP (body
, 0), 0)))
568 if (reg_overlap_mentioned_p (x
, COND_EXEC_TEST (body
)))
570 return reg_referenced_p (x
, COND_EXEC_CODE (body
));
577 /* Nonzero if register REG is referenced in an insn between
578 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
582 reg_referenced_between_p (reg
, from_insn
, to_insn
)
583 rtx reg
, from_insn
, to_insn
;
587 if (from_insn
== to_insn
)
590 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
592 && (reg_referenced_p (reg
, PATTERN (insn
))
593 || (GET_CODE (insn
) == CALL_INSN
594 && find_reg_fusage (insn
, USE
, reg
))))
599 /* Nonzero if register REG is set or clobbered in an insn between
600 FROM_INSN and TO_INSN (exclusive of those two). */
603 reg_set_between_p (reg
, from_insn
, to_insn
)
604 rtx reg
, from_insn
, to_insn
;
608 if (from_insn
== to_insn
)
611 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
612 if (INSN_P (insn
) && reg_set_p (reg
, insn
))
617 /* Internals of reg_set_between_p. */
619 reg_set_p (reg
, insn
)
624 /* We can be passed an insn or part of one. If we are passed an insn,
625 check if a side-effect of the insn clobbers REG. */
628 if (FIND_REG_INC_NOTE (insn
, reg
)
629 || (GET_CODE (insn
) == CALL_INSN
630 /* We'd like to test call_used_regs here, but rtlanal.c can't
631 reference that variable due to its use in genattrtab. So
632 we'll just be more conservative.
634 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
635 information holds all clobbered registers. */
636 && ((GET_CODE (reg
) == REG
637 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
638 || GET_CODE (reg
) == MEM
639 || find_reg_fusage (insn
, CLOBBER
, reg
))))
642 body
= PATTERN (insn
);
645 return set_of (reg
, insn
) != NULL_RTX
;
648 /* Similar to reg_set_between_p, but check all registers in X. Return 0
649 only if none of them are modified between START and END. Do not
650 consider non-registers one way or the other. */
653 regs_set_between_p (x
, start
, end
)
657 enum rtx_code code
= GET_CODE (x
);
673 return reg_set_between_p (x
, start
, end
);
679 fmt
= GET_RTX_FORMAT (code
);
680 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
682 if (fmt
[i
] == 'e' && regs_set_between_p (XEXP (x
, i
), start
, end
))
685 else if (fmt
[i
] == 'E')
686 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
687 if (regs_set_between_p (XVECEXP (x
, i
, j
), start
, end
))
694 /* Similar to reg_set_between_p, but check all registers in X. Return 0
695 only if none of them are modified between START and END. Return 1 if
696 X contains a MEM; this routine does not perform any memory aliasing. */
699 modified_between_p (x
, start
, end
)
703 enum rtx_code code
= GET_CODE (x
);
721 /* If the memory is not constant, assume it is modified. If it is
722 constant, we still have to check the address. */
723 if (! RTX_UNCHANGING_P (x
))
728 return reg_set_between_p (x
, start
, end
);
734 fmt
= GET_RTX_FORMAT (code
);
735 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
737 if (fmt
[i
] == 'e' && modified_between_p (XEXP (x
, i
), start
, end
))
740 else if (fmt
[i
] == 'E')
741 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
742 if (modified_between_p (XVECEXP (x
, i
, j
), start
, end
))
749 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
750 of them are modified in INSN. Return 1 if X contains a MEM; this routine
751 does not perform any memory aliasing. */
754 modified_in_p (x
, insn
)
758 enum rtx_code code
= GET_CODE (x
);
776 /* If the memory is not constant, assume it is modified. If it is
777 constant, we still have to check the address. */
778 if (! RTX_UNCHANGING_P (x
))
783 return reg_set_p (x
, insn
);
789 fmt
= GET_RTX_FORMAT (code
);
790 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
792 if (fmt
[i
] == 'e' && modified_in_p (XEXP (x
, i
), insn
))
795 else if (fmt
[i
] == 'E')
796 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
797 if (modified_in_p (XVECEXP (x
, i
, j
), insn
))
804 /* Return true if anything in insn X is (anti,output,true) dependent on
805 anything in insn Y. */
808 insn_dependent_p (x
, y
)
813 if (! INSN_P (x
) || ! INSN_P (y
))
817 note_stores (PATTERN (x
), insn_dependent_p_1
, &tmp
);
822 note_stores (PATTERN (y
), insn_dependent_p_1
, &tmp
);
829 /* A helper routine for insn_dependent_p called through note_stores. */
832 insn_dependent_p_1 (x
, pat
, data
)
834 rtx pat ATTRIBUTE_UNUSED
;
837 rtx
* pinsn
= (rtx
*) data
;
839 if (*pinsn
&& reg_mentioned_p (x
, *pinsn
))
843 /* Helper function for set_of. */
851 set_of_1 (x
, pat
, data1
)
856 struct set_of_data
*data
= (struct set_of_data
*) (data1
);
857 if (rtx_equal_p (x
, data
->pat
)
858 || (GET_CODE (x
) != MEM
&& reg_overlap_mentioned_p (data
->pat
, x
)))
862 /* Give an INSN, return a SET or CLOBBER expression that does modify PAT
863 (eighter directly or via STRICT_LOW_PART and similar modifiers). */
868 struct set_of_data data
;
869 data
.found
= NULL_RTX
;
871 note_stores (INSN_P (insn
) ? PATTERN (insn
) : insn
, set_of_1
, &data
);
875 /* Given an INSN, return a SET expression if this insn has only a single SET.
876 It may also have CLOBBERs, USEs, or SET whose output
877 will not be used, which we ignore. */
880 single_set_2 (insn
, pat
)
884 int set_verified
= 1;
887 if (GET_CODE (pat
) == PARALLEL
)
889 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
891 rtx sub
= XVECEXP (pat
, 0, i
);
892 switch (GET_CODE (sub
))
899 /* We can consider insns having multiple sets, where all
900 but one are dead as single set insns. In common case
901 only single set is present in the pattern so we want
902 to avoid checking for REG_UNUSED notes unless neccesary.
904 When we reach set first time, we just expect this is
905 the single set we are looking for and only when more
906 sets are found in the insn, we check them. */
909 if (find_reg_note (insn
, REG_UNUSED
, SET_DEST (set
))
910 && !side_effects_p (set
))
916 set
= sub
, set_verified
= 0;
917 else if (!find_reg_note (insn
, REG_UNUSED
, SET_DEST (sub
))
918 || side_effects_p (sub
))
930 /* Given an INSN, return nonzero if it has more than one SET, else return
940 /* INSN must be an insn. */
944 /* Only a PARALLEL can have multiple SETs. */
945 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
947 for (i
= 0, found
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
948 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
950 /* If we have already found a SET, then return now. */
958 /* Either zero or one SET. */
962 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
963 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
964 If the object was modified, if we hit a partial assignment to X, or hit a
965 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
966 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
970 find_last_value (x
, pinsn
, valid_to
, allow_hwreg
)
978 for (p
= PREV_INSN (*pinsn
); p
&& GET_CODE (p
) != CODE_LABEL
;
982 rtx set
= single_set (p
);
983 rtx note
= find_reg_note (p
, REG_EQUAL
, NULL_RTX
);
985 if (set
&& rtx_equal_p (x
, SET_DEST (set
)))
987 rtx src
= SET_SRC (set
);
989 if (note
&& GET_CODE (XEXP (note
, 0)) != EXPR_LIST
)
990 src
= XEXP (note
, 0);
992 if ((valid_to
== NULL_RTX
993 || ! modified_between_p (src
, PREV_INSN (p
), valid_to
))
994 /* Reject hard registers because we don't usually want
995 to use them; we'd rather use a pseudo. */
996 && (! (GET_CODE (src
) == REG
997 && REGNO (src
) < FIRST_PSEUDO_REGISTER
) || allow_hwreg
))
1004 /* If set in non-simple way, we don't have a value. */
1005 if (reg_set_p (x
, p
))
1012 /* Return nonzero if register in range [REGNO, ENDREGNO)
1013 appears either explicitly or implicitly in X
1014 other than being stored into.
1016 References contained within the substructure at LOC do not count.
1017 LOC may be zero, meaning don't ignore anything. */
1020 refers_to_regno_p (regno
, endregno
, x
, loc
)
1021 unsigned int regno
, endregno
;
1026 unsigned int x_regno
;
1031 /* The contents of a REG_NONNEG note is always zero, so we must come here
1032 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
1036 code
= GET_CODE (x
);
1041 x_regno
= REGNO (x
);
1043 /* If we modifying the stack, frame, or argument pointer, it will
1044 clobber a virtual register. In fact, we could be more precise,
1045 but it isn't worth it. */
1046 if ((x_regno
== STACK_POINTER_REGNUM
1047 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1048 || x_regno
== ARG_POINTER_REGNUM
1050 || x_regno
== FRAME_POINTER_REGNUM
)
1051 && regno
>= FIRST_VIRTUAL_REGISTER
&& regno
<= LAST_VIRTUAL_REGISTER
)
1054 return (endregno
> x_regno
1055 && regno
< x_regno
+ (x_regno
< FIRST_PSEUDO_REGISTER
1056 ? HARD_REGNO_NREGS (x_regno
, GET_MODE (x
))
1060 /* If this is a SUBREG of a hard reg, we can see exactly which
1061 registers are being modified. Otherwise, handle normally. */
1062 if (GET_CODE (SUBREG_REG (x
)) == REG
1063 && REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
)
1065 unsigned int inner_regno
= REGNO (SUBREG_REG (x
)) + SUBREG_WORD (x
);
1066 unsigned int inner_endregno
1067 = inner_regno
+ (inner_regno
< FIRST_PSEUDO_REGISTER
1068 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
1070 return endregno
> inner_regno
&& regno
< inner_endregno
;
1076 if (&SET_DEST (x
) != loc
1077 /* Note setting a SUBREG counts as referring to the REG it is in for
1078 a pseudo but not for hard registers since we can
1079 treat each word individually. */
1080 && ((GET_CODE (SET_DEST (x
)) == SUBREG
1081 && loc
!= &SUBREG_REG (SET_DEST (x
))
1082 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
1083 && REGNO (SUBREG_REG (SET_DEST (x
))) >= FIRST_PSEUDO_REGISTER
1084 && refers_to_regno_p (regno
, endregno
,
1085 SUBREG_REG (SET_DEST (x
)), loc
))
1086 || (GET_CODE (SET_DEST (x
)) != REG
1087 && refers_to_regno_p (regno
, endregno
, SET_DEST (x
), loc
))))
1090 if (code
== CLOBBER
|| loc
== &SET_SRC (x
))
1099 /* X does not match, so try its subexpressions. */
1101 fmt
= GET_RTX_FORMAT (code
);
1102 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1104 if (fmt
[i
] == 'e' && loc
!= &XEXP (x
, i
))
1112 if (refers_to_regno_p (regno
, endregno
, XEXP (x
, i
), loc
))
1115 else if (fmt
[i
] == 'E')
1118 for (j
= XVECLEN (x
, i
) - 1; j
>=0; j
--)
1119 if (loc
!= &XVECEXP (x
, i
, j
)
1120 && refers_to_regno_p (regno
, endregno
, XVECEXP (x
, i
, j
), loc
))
1127 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
1128 we check if any register number in X conflicts with the relevant register
1129 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
1130 contains a MEM (we don't bother checking for memory addresses that can't
1131 conflict because we expect this to be a rare case. */
1134 reg_overlap_mentioned_p (x
, in
)
1137 unsigned int regno
, endregno
;
1139 /* Overly conservative. */
1140 if (GET_CODE (x
) == STRICT_LOW_PART
)
1143 /* If either argument is a constant, then modifying X can not affect IN. */
1144 if (CONSTANT_P (x
) || CONSTANT_P (in
))
1147 switch (GET_CODE (x
))
1150 regno
= REGNO (SUBREG_REG (x
));
1151 if (regno
< FIRST_PSEUDO_REGISTER
)
1152 regno
+= SUBREG_WORD (x
);
1158 endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
1159 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
1160 return refers_to_regno_p (regno
, endregno
, in
, NULL_PTR
);
1167 if (GET_CODE (in
) == MEM
)
1170 fmt
= GET_RTX_FORMAT (GET_CODE (in
));
1171 for (i
= GET_RTX_LENGTH (GET_CODE (in
)) - 1; i
>= 0; i
--)
1172 if (fmt
[i
] == 'e' && reg_overlap_mentioned_p (x
, XEXP (in
, i
)))
1181 return reg_mentioned_p (x
, in
);
1187 /* If any register in here refers to it we return true. */
1188 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1189 if (XEXP (XVECEXP (x
, 0, i
), 0) != 0
1190 && reg_overlap_mentioned_p (XEXP (XVECEXP (x
, 0, i
), 0), in
))
1202 /* Return the last value to which REG was set prior to INSN. If we can't
1203 find it easily, return 0.
1205 We only return a REG, SUBREG, or constant because it is too hard to
1206 check if a MEM remains unchanged. */
1209 reg_set_last (x
, insn
)
1213 rtx orig_insn
= insn
;
1215 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1216 Stop when we reach a label or X is a hard reg and we reach a
1217 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1219 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1221 /* We compare with <= here, because reg_set_last_last_regno
1222 is actually the number of the first reg *not* in X. */
1224 insn
&& GET_CODE (insn
) != CODE_LABEL
1225 && ! (GET_CODE (insn
) == CALL_INSN
1226 && REGNO (x
) <= FIRST_PSEUDO_REGISTER
);
1227 insn
= PREV_INSN (insn
))
1230 rtx set
= set_of (x
, insn
);
1231 /* OK, this function modify our register. See if we understand it. */
1235 if (GET_CODE (set
) != SET
|| SET_DEST (set
) != x
)
1237 last_value
= SET_SRC (x
);
1238 if (CONSTANT_P (last_value
)
1239 || ((GET_CODE (last_value
) == REG
1240 || GET_CODE (last_value
) == SUBREG
)
1241 && ! reg_set_between_p (last_value
,
1252 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1253 (X would be the pattern of an insn).
1254 FUN receives two arguments:
1255 the REG, MEM, CC0 or PC being stored in or clobbered,
1256 the SET or CLOBBER rtx that does the store.
1258 If the item being stored in or clobbered is a SUBREG of a hard register,
1259 the SUBREG will be passed. */
1262 note_stores (x
, fun
, data
)
1264 void (*fun
) PARAMS ((rtx
, rtx
, void *));
1269 if (GET_CODE (x
) == COND_EXEC
)
1270 x
= COND_EXEC_CODE (x
);
1272 if (GET_CODE (x
) == SET
|| GET_CODE (x
) == CLOBBER
)
1274 register rtx dest
= SET_DEST (x
);
1276 while ((GET_CODE (dest
) == SUBREG
1277 && (GET_CODE (SUBREG_REG (dest
)) != REG
1278 || REGNO (SUBREG_REG (dest
)) >= FIRST_PSEUDO_REGISTER
))
1279 || GET_CODE (dest
) == ZERO_EXTRACT
1280 || GET_CODE (dest
) == SIGN_EXTRACT
1281 || GET_CODE (dest
) == STRICT_LOW_PART
)
1282 dest
= XEXP (dest
, 0);
1284 /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions,
1285 each of whose first operand is a register. We can't know what
1286 precisely is being set in these cases, so make up a CLOBBER to pass
1288 if (GET_CODE (dest
) == PARALLEL
)
1290 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1291 if (XEXP (XVECEXP (dest
, 0, i
), 0) != 0)
1292 (*fun
) (XEXP (XVECEXP (dest
, 0, i
), 0),
1293 gen_rtx_CLOBBER (VOIDmode
,
1294 XEXP (XVECEXP (dest
, 0, i
), 0)),
1298 (*fun
) (dest
, x
, data
);
1301 else if (GET_CODE (x
) == PARALLEL
)
1302 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1303 note_stores (XVECEXP (x
, 0, i
), fun
, data
);
1306 /* Return nonzero if X's old contents don't survive after INSN.
1307 This will be true if X is (cc0) or if X is a register and
1308 X dies in INSN or because INSN entirely sets X.
1310 "Entirely set" means set directly and not through a SUBREG,
1311 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1312 Likewise, REG_INC does not count.
1314 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1315 but for this use that makes no difference, since regs don't overlap
1316 during their lifetimes. Therefore, this function may be used
1317 at any time after deaths have been computed (in flow.c).
1319 If REG is a hard reg that occupies multiple machine registers, this
1320 function will only return 1 if each of those registers will be replaced
1324 dead_or_set_p (insn
, x
)
1328 unsigned int regno
, last_regno
;
1331 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1332 if (GET_CODE (x
) == CC0
)
1335 if (GET_CODE (x
) != REG
)
1339 last_regno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
1340 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
)) - 1);
1342 for (i
= regno
; i
<= last_regno
; i
++)
1343 if (! dead_or_set_regno_p (insn
, i
))
1349 /* Utility function for dead_or_set_p to check an individual register. Also
1350 called from flow.c. */
1353 dead_or_set_regno_p (insn
, test_regno
)
1355 unsigned int test_regno
;
1357 unsigned int regno
, endregno
;
1360 /* See if there is a death note for something that includes TEST_REGNO. */
1361 if (find_regno_note (insn
, REG_DEAD
, test_regno
))
1364 if (GET_CODE (insn
) == CALL_INSN
1365 && find_regno_fusage (insn
, CLOBBER
, test_regno
))
1368 pattern
= PATTERN (insn
);
1370 if (GET_CODE (pattern
) == COND_EXEC
)
1371 pattern
= COND_EXEC_CODE (pattern
);
1373 if (GET_CODE (pattern
) == SET
)
1375 rtx dest
= SET_DEST (PATTERN (insn
));
1377 /* A value is totally replaced if it is the destination or the
1378 destination is a SUBREG of REGNO that does not change the number of
1380 if (GET_CODE (dest
) == SUBREG
1381 && (((GET_MODE_SIZE (GET_MODE (dest
))
1382 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1383 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1384 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1385 dest
= SUBREG_REG (dest
);
1387 if (GET_CODE (dest
) != REG
)
1390 regno
= REGNO (dest
);
1391 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1392 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1394 return (test_regno
>= regno
&& test_regno
< endregno
);
1396 else if (GET_CODE (pattern
) == PARALLEL
)
1400 for (i
= XVECLEN (pattern
, 0) - 1; i
>= 0; i
--)
1402 rtx body
= XVECEXP (pattern
, 0, i
);
1404 if (GET_CODE (body
) == COND_EXEC
)
1405 body
= COND_EXEC_CODE (body
);
1407 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == CLOBBER
)
1409 rtx dest
= SET_DEST (body
);
1411 if (GET_CODE (dest
) == SUBREG
1412 && (((GET_MODE_SIZE (GET_MODE (dest
))
1413 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1414 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1415 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1416 dest
= SUBREG_REG (dest
);
1418 if (GET_CODE (dest
) != REG
)
1421 regno
= REGNO (dest
);
1422 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1423 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1425 if (test_regno
>= regno
&& test_regno
< endregno
)
1434 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1435 If DATUM is nonzero, look for one whose datum is DATUM. */
1438 find_reg_note (insn
, kind
, datum
)
1445 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1446 if (! INSN_P (insn
))
1449 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1450 if (REG_NOTE_KIND (link
) == kind
1451 && (datum
== 0 || datum
== XEXP (link
, 0)))
1456 /* Return the reg-note of kind KIND in insn INSN which applies to register
1457 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1458 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1459 it might be the case that the note overlaps REGNO. */
1462 find_regno_note (insn
, kind
, regno
)
1469 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1470 if (! INSN_P (insn
))
1473 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1474 if (REG_NOTE_KIND (link
) == kind
1475 /* Verify that it is a register, so that scratch and MEM won't cause a
1477 && GET_CODE (XEXP (link
, 0)) == REG
1478 && REGNO (XEXP (link
, 0)) <= regno
1479 && ((REGNO (XEXP (link
, 0))
1480 + (REGNO (XEXP (link
, 0)) >= FIRST_PSEUDO_REGISTER
? 1
1481 : HARD_REGNO_NREGS (REGNO (XEXP (link
, 0)),
1482 GET_MODE (XEXP (link
, 0)))))
1488 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1489 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1492 find_reg_fusage (insn
, code
, datum
)
1497 /* If it's not a CALL_INSN, it can't possibly have a
1498 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1499 if (GET_CODE (insn
) != CALL_INSN
)
1505 if (GET_CODE (datum
) != REG
)
1509 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1511 link
= XEXP (link
, 1))
1512 if (GET_CODE (XEXP (link
, 0)) == code
1513 && rtx_equal_p (datum
, SET_DEST (XEXP (link
, 0))))
1518 unsigned int regno
= REGNO (datum
);
1520 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1521 to pseudo registers, so don't bother checking. */
1523 if (regno
< FIRST_PSEUDO_REGISTER
)
1525 unsigned int end_regno
1526 = regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (datum
));
1529 for (i
= regno
; i
< end_regno
; i
++)
1530 if (find_regno_fusage (insn
, code
, i
))
1538 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1539 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1542 find_regno_fusage (insn
, code
, regno
)
1549 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1550 to pseudo registers, so don't bother checking. */
1552 if (regno
>= FIRST_PSEUDO_REGISTER
1553 || GET_CODE (insn
) != CALL_INSN
)
1556 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
1558 unsigned int regnote
;
1561 if (GET_CODE (op
= XEXP (link
, 0)) == code
1562 && GET_CODE (reg
= XEXP (op
, 0)) == REG
1563 && (regnote
= REGNO (reg
)) <= regno
1564 && regnote
+ HARD_REGNO_NREGS (regnote
, GET_MODE (reg
)) > regno
)
1571 /* Remove register note NOTE from the REG_NOTES of INSN. */
1574 remove_note (insn
, note
)
1580 if (note
== NULL_RTX
)
1583 if (REG_NOTES (insn
) == note
)
1585 REG_NOTES (insn
) = XEXP (note
, 1);
1589 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1590 if (XEXP (link
, 1) == note
)
1592 XEXP (link
, 1) = XEXP (note
, 1);
1599 /* Search LISTP (an EXPR_LIST) for NODE and remove NODE from the list
1602 A simple equality test is used to determine if NODE is on the
1606 remove_node_from_expr_list (node
, listp
)
1611 rtx prev
= NULL_RTX
;
1615 if (node
== XEXP (temp
, 0))
1617 /* Splice the node out of the list. */
1619 XEXP (prev
, 1) = XEXP (temp
, 1);
1621 *listp
= XEXP (temp
, 1);
1625 temp
= XEXP (temp
, 1);
1629 /* Nonzero if X contains any volatile instructions. These are instructions
1630 which may cause unpredictable machine state instructions, and thus no
1631 instructions should be moved or combined across them. This includes
1632 only volatile asms and UNSPEC_VOLATILE instructions. */
1638 register RTX_CODE code
;
1640 code
= GET_CODE (x
);
1660 case UNSPEC_VOLATILE
:
1661 /* case TRAP_IF: This isn't clear yet. */
1665 if (MEM_VOLATILE_P (x
))
1672 /* Recursively scan the operands of this expression. */
1675 register const char *fmt
= GET_RTX_FORMAT (code
);
1678 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1682 if (volatile_insn_p (XEXP (x
, i
)))
1685 else if (fmt
[i
] == 'E')
1688 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1689 if (volatile_insn_p (XVECEXP (x
, i
, j
)))
1697 /* Nonzero if X contains any volatile memory references
1698 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1704 register RTX_CODE code
;
1706 code
= GET_CODE (x
);
1725 case UNSPEC_VOLATILE
:
1726 /* case TRAP_IF: This isn't clear yet. */
1731 if (MEM_VOLATILE_P (x
))
1738 /* Recursively scan the operands of this expression. */
1741 register const char *fmt
= GET_RTX_FORMAT (code
);
1744 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1748 if (volatile_refs_p (XEXP (x
, i
)))
1751 else if (fmt
[i
] == 'E')
1754 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1755 if (volatile_refs_p (XVECEXP (x
, i
, j
)))
1763 /* Similar to above, except that it also rejects register pre- and post-
1770 register RTX_CODE code
;
1772 code
= GET_CODE (x
);
1790 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1791 when some combination can't be done. If we see one, don't think
1792 that we can simplify the expression. */
1793 return (GET_MODE (x
) != VOIDmode
);
1802 case UNSPEC_VOLATILE
:
1803 /* case TRAP_IF: This isn't clear yet. */
1808 if (MEM_VOLATILE_P (x
))
1815 /* Recursively scan the operands of this expression. */
1818 register const char *fmt
= GET_RTX_FORMAT (code
);
1821 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1825 if (side_effects_p (XEXP (x
, i
)))
1828 else if (fmt
[i
] == 'E')
1831 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1832 if (side_effects_p (XVECEXP (x
, i
, j
)))
1840 /* Return nonzero if evaluating rtx X might cause a trap. */
1852 code
= GET_CODE (x
);
1855 /* Handle these cases quickly. */
1868 case UNSPEC_VOLATILE
:
1873 return MEM_VOLATILE_P (x
);
1875 /* Memory ref can trap unless it's a static var or a stack slot. */
1877 return rtx_addr_can_trap_p (XEXP (x
, 0));
1879 /* Division by a non-constant might trap. */
1884 if (! CONSTANT_P (XEXP (x
, 1))
1885 || GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1887 /* This was const0_rtx, but by not using that,
1888 we can link this file into other programs. */
1889 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
&& INTVAL (XEXP (x
, 1)) == 0)
1894 /* An EXPR_LIST is used to represent a function call. This
1895 certainly may trap. */
1903 /* Some floating point comparisons may trap. */
1904 /* ??? There is no machine independent way to check for tests that trap
1905 when COMPARE is used, though many targets do make this distinction.
1906 For instance, sparc uses CCFPE for compares which generate exceptions
1907 and CCFP for compares which do not generate exceptions. */
1908 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1910 /* But often the compare has some CC mode, so check operand
1912 if (GET_MODE_CLASS (GET_MODE (XEXP (x
, 0))) == MODE_FLOAT
1913 || GET_MODE_CLASS (GET_MODE (XEXP (x
, 1))) == MODE_FLOAT
)
1918 /* Any floating arithmetic may trap. */
1919 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1923 fmt
= GET_RTX_FORMAT (code
);
1924 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1928 if (may_trap_p (XEXP (x
, i
)))
1931 else if (fmt
[i
] == 'E')
1934 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1935 if (may_trap_p (XVECEXP (x
, i
, j
)))
1942 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1943 i.e., an inequality. */
1946 inequality_comparisons_p (x
)
1949 register const char *fmt
;
1950 register int len
, i
;
1951 register enum rtx_code code
= GET_CODE (x
);
1980 len
= GET_RTX_LENGTH (code
);
1981 fmt
= GET_RTX_FORMAT (code
);
1983 for (i
= 0; i
< len
; i
++)
1987 if (inequality_comparisons_p (XEXP (x
, i
)))
1990 else if (fmt
[i
] == 'E')
1993 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1994 if (inequality_comparisons_p (XVECEXP (x
, i
, j
)))
2002 /* Replace any occurrence of FROM in X with TO. The function does
2003 not enter into CONST_DOUBLE for the replace.
2005 Note that copying is not done so X must not be shared unless all copies
2006 are to be modified. */
2009 replace_rtx (x
, from
, to
)
2013 register const char *fmt
;
2015 /* The following prevents loops occurrence when we change MEM in
2016 CONST_DOUBLE onto the same CONST_DOUBLE. */
2017 if (x
!= 0 && GET_CODE (x
) == CONST_DOUBLE
)
2023 /* Allow this function to make replacements in EXPR_LISTs. */
2027 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2028 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2031 XEXP (x
, i
) = replace_rtx (XEXP (x
, i
), from
, to
);
2032 else if (fmt
[i
] == 'E')
2033 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2034 XVECEXP (x
, i
, j
) = replace_rtx (XVECEXP (x
, i
, j
), from
, to
);
2040 /* Throughout the rtx X, replace many registers according to REG_MAP.
2041 Return the replacement for X (which may be X with altered contents).
2042 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
2043 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
2045 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
2046 should not be mapped to pseudos or vice versa since validate_change
2049 If REPLACE_DEST is 1, replacements are also done in destinations;
2050 otherwise, only sources are replaced. */
2053 replace_regs (x
, reg_map
, nregs
, replace_dest
)
2059 register enum rtx_code code
;
2061 register const char *fmt
;
2066 code
= GET_CODE (x
);
2080 /* Verify that the register has an entry before trying to access it. */
2081 if (REGNO (x
) < nregs
&& reg_map
[REGNO (x
)] != 0)
2083 /* SUBREGs can't be shared. Always return a copy to ensure that if
2084 this replacement occurs more than once then each instance will
2085 get distinct rtx. */
2086 if (GET_CODE (reg_map
[REGNO (x
)]) == SUBREG
)
2087 return copy_rtx (reg_map
[REGNO (x
)]);
2088 return reg_map
[REGNO (x
)];
2093 /* Prevent making nested SUBREGs. */
2094 if (GET_CODE (SUBREG_REG (x
)) == REG
&& REGNO (SUBREG_REG (x
)) < nregs
2095 && reg_map
[REGNO (SUBREG_REG (x
))] != 0
2096 && GET_CODE (reg_map
[REGNO (SUBREG_REG (x
))]) == SUBREG
)
2098 rtx map_val
= reg_map
[REGNO (SUBREG_REG (x
))];
2099 rtx map_inner
= SUBREG_REG (map_val
);
2101 if (GET_MODE (x
) == GET_MODE (map_inner
))
2105 /* We cannot call gen_rtx here since we may be linked with
2107 /* Let's try clobbering the incoming SUBREG and see
2108 if this is really safe. */
2109 SUBREG_REG (x
) = map_inner
;
2110 SUBREG_WORD (x
) += SUBREG_WORD (map_val
);
2113 rtx
new = rtx_alloc (SUBREG
);
2114 PUT_MODE (new, GET_MODE (x
));
2115 SUBREG_REG (new) = map_inner
;
2116 SUBREG_WORD (new) = SUBREG_WORD (x
) + SUBREG_WORD (map_val
);
2124 SET_DEST (x
) = replace_regs (SET_DEST (x
), reg_map
, nregs
, 0);
2126 else if (GET_CODE (SET_DEST (x
)) == MEM
2127 || GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2128 /* Even if we are not to replace destinations, replace register if it
2129 is CONTAINED in destination (destination is memory or
2130 STRICT_LOW_PART). */
2131 XEXP (SET_DEST (x
), 0) = replace_regs (XEXP (SET_DEST (x
), 0),
2133 else if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2134 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2137 SET_SRC (x
) = replace_regs (SET_SRC (x
), reg_map
, nregs
, 0);
2144 fmt
= GET_RTX_FORMAT (code
);
2145 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2148 XEXP (x
, i
) = replace_regs (XEXP (x
, i
), reg_map
, nregs
, replace_dest
);
2149 else if (fmt
[i
] == 'E')
2152 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2153 XVECEXP (x
, i
, j
) = replace_regs (XVECEXP (x
, i
, j
), reg_map
,
2154 nregs
, replace_dest
);
2160 /* A subroutine of computed_jump_p, return 1 if X contains a REG or MEM or
2161 constant that is not in the constant pool and not in the condition
2162 of an IF_THEN_ELSE. */
2165 computed_jump_p_1 (x
)
2168 enum rtx_code code
= GET_CODE (x
);
2186 return ! (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
2187 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)));
2190 return (computed_jump_p_1 (XEXP (x
, 1))
2191 || computed_jump_p_1 (XEXP (x
, 2)));
2197 fmt
= GET_RTX_FORMAT (code
);
2198 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2201 && computed_jump_p_1 (XEXP (x
, i
)))
2204 else if (fmt
[i
] == 'E')
2205 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2206 if (computed_jump_p_1 (XVECEXP (x
, i
, j
)))
2213 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2215 Tablejumps and casesi insns are not considered indirect jumps;
2216 we can recognize them by a (use (label_ref)). */
2219 computed_jump_p (insn
)
2223 if (GET_CODE (insn
) == JUMP_INSN
)
2225 rtx pat
= PATTERN (insn
);
2227 if (find_reg_note (insn
, REG_LABEL
, NULL_RTX
))
2229 else if (GET_CODE (pat
) == PARALLEL
)
2231 int len
= XVECLEN (pat
, 0);
2232 int has_use_labelref
= 0;
2234 for (i
= len
- 1; i
>= 0; i
--)
2235 if (GET_CODE (XVECEXP (pat
, 0, i
)) == USE
2236 && (GET_CODE (XEXP (XVECEXP (pat
, 0, i
), 0))
2238 has_use_labelref
= 1;
2240 if (! has_use_labelref
)
2241 for (i
= len
- 1; i
>= 0; i
--)
2242 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
2243 && SET_DEST (XVECEXP (pat
, 0, i
)) == pc_rtx
2244 && computed_jump_p_1 (SET_SRC (XVECEXP (pat
, 0, i
))))
2247 else if (GET_CODE (pat
) == SET
2248 && SET_DEST (pat
) == pc_rtx
2249 && computed_jump_p_1 (SET_SRC (pat
)))
2255 /* Traverse X via depth-first search, calling F for each
2256 sub-expression (including X itself). F is also passed the DATA.
2257 If F returns -1, do not traverse sub-expressions, but continue
2258 traversing the rest of the tree. If F ever returns any other
2259 non-zero value, stop the traversal, and return the value returned
2260 by F. Otherwise, return 0. This function does not traverse inside
2261 tree structure that contains RTX_EXPRs, or into sub-expressions
2262 whose format code is `0' since it is not known whether or not those
2263 codes are actually RTL.
2265 This routine is very general, and could (should?) be used to
2266 implement many of the other routines in this file. */
2269 for_each_rtx (x
, f
, data
)
2280 result
= (*f
)(x
, data
);
2282 /* Do not traverse sub-expressions. */
2284 else if (result
!= 0)
2285 /* Stop the traversal. */
2289 /* There are no sub-expressions. */
2292 length
= GET_RTX_LENGTH (GET_CODE (*x
));
2293 format
= GET_RTX_FORMAT (GET_CODE (*x
));
2295 for (i
= 0; i
< length
; ++i
)
2300 result
= for_each_rtx (&XEXP (*x
, i
), f
, data
);
2307 if (XVEC (*x
, i
) != 0)
2310 for (j
= 0; j
< XVECLEN (*x
, i
); ++j
)
2312 result
= for_each_rtx (&XVECEXP (*x
, i
, j
), f
, data
);
2320 /* Nothing to do. */
2329 /* Searches X for any reference to REGNO, returning the rtx of the
2330 reference found if any. Otherwise, returns NULL_RTX. */
2333 regno_use_in (regno
, x
)
2337 register const char *fmt
;
2341 if (GET_CODE (x
) == REG
&& REGNO (x
) == regno
)
2344 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2345 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2349 if ((tem
= regno_use_in (regno
, XEXP (x
, i
))))
2352 else if (fmt
[i
] == 'E')
2353 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2354 if ((tem
= regno_use_in (regno
, XVECEXP (x
, i
, j
))))
2362 /* Return 1 if X is an autoincrement side effect and the register is
2363 not the stack pointer. */
2368 switch (GET_CODE (x
))
2376 /* There are no REG_INC notes for SP. */
2377 if (XEXP (x
, 0) != stack_pointer_rtx
)
2385 /* Return 1 if the sequence of instructions beginning with FROM and up
2386 to and including TO is safe to move. If NEW_TO is non-NULL, and
2387 the sequence is not already safe to move, but can be easily
2388 extended to a sequence which is safe, then NEW_TO will point to the
2389 end of the extended sequence.
2391 For now, this function only checks that the region contains whole
2392 exception regions, but it could be extended to check additional
2393 conditions as well. */
2396 insns_safe_to_move_p (from
, to
, new_to
)
2401 int eh_region_count
= 0;
2405 /* By default, assume the end of the region will be what was
2412 if (GET_CODE (r
) == NOTE
)
2414 switch (NOTE_LINE_NUMBER (r
))
2416 case NOTE_INSN_EH_REGION_BEG
:
2420 case NOTE_INSN_EH_REGION_END
:
2421 if (eh_region_count
== 0)
2422 /* This sequence of instructions contains the end of
2423 an exception region, but not he beginning. Moving
2424 it will cause chaos. */
2435 /* If we've passed TO, and we see a non-note instruction, we
2436 can't extend the sequence to a movable sequence. */
2442 /* It's OK to move the sequence if there were matched sets of
2443 exception region notes. */
2444 return eh_region_count
== 0;
2449 /* It's OK to move the sequence if there were matched sets of
2450 exception region notes. */
2451 if (past_to_p
&& eh_region_count
== 0)
2457 /* Go to the next instruction. */
2464 /* Return non-zero if IN contains a piece of rtl that has the address LOC */
2466 loc_mentioned_in_p (loc
, in
)
2469 enum rtx_code code
= GET_CODE (in
);
2470 const char *fmt
= GET_RTX_FORMAT (code
);
2473 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2475 if (loc
== &in
->fld
[i
].rtx
)
2479 if (loc_mentioned_in_p (loc
, XEXP (in
, i
)))
2482 else if (fmt
[i
] == 'E')
2483 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
2484 if (loc_mentioned_in_p (loc
, XVECEXP (in
, i
, j
)))