1 /* Analyze RTL for C-Compiler
2 Copyright (C) 1987, 88, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 static int rtx_addr_can_trap_p
PROTO((rtx
));
27 static void reg_set_p_1
PROTO((rtx
, rtx
));
28 static void reg_set_last_1
PROTO((rtx
, rtx
));
31 /* Forward declarations */
32 static int jmp_uses_reg_or_mem
PROTO((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
);
54 return ! RTX_UNCHANGING_P (x
);
59 if (code
== CONST
|| code
== CONST_INT
)
63 return ! (REGNO (x
) == FRAME_POINTER_REGNUM
64 || REGNO (x
) == HARD_FRAME_POINTER_REGNUM
65 || REGNO (x
) == ARG_POINTER_REGNUM
66 || RTX_UNCHANGING_P (x
));
68 fmt
= GET_RTX_FORMAT (code
);
69 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
71 if (rtx_unstable_p (XEXP (x
, i
)))
76 /* Return 1 if X has a value that can vary even between two
77 executions of the program. 0 means X can be compared reliably
78 against certain constants or near-constants.
79 The frame pointer and the arg pointer are considered constant. */
85 register RTX_CODE code
= GET_CODE (x
);
103 /* Note that we have to test for the actual rtx used for the frame
104 and arg pointers and not just the register number in case we have
105 eliminated the frame and/or arg pointer and are using it
107 return ! (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
108 || x
== arg_pointer_rtx
|| x
== pic_offset_table_rtx
);
111 /* The operand 0 of a LO_SUM is considered constant
112 (in fact is it related specifically to operand 1). */
113 return rtx_varies_p (XEXP (x
, 1));
119 fmt
= GET_RTX_FORMAT (code
);
120 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
122 if (rtx_varies_p (XEXP (x
, i
)))
127 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
130 rtx_addr_can_trap_p (x
)
133 register enum rtx_code code
= GET_CODE (x
);
139 /* SYMBOL_REF is problematic due to the possible presence of
140 a #pragma weak, but to say that loads from symbols can trap is
141 *very* costly. It's not at all clear what's best here. For
142 now, we ignore the impact of #pragma weak. */
146 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
147 return ! (x
== frame_pointer_rtx
|| x
== hard_frame_pointer_rtx
148 || x
== stack_pointer_rtx
|| x
== arg_pointer_rtx
);
151 return rtx_addr_can_trap_p (XEXP (x
, 0));
154 /* An address is assumed not to trap if it is an address that can't
155 trap plus a constant integer. */
156 return (rtx_addr_can_trap_p (XEXP (x
, 0))
157 || GET_CODE (XEXP (x
, 1)) != CONST_INT
);
160 return rtx_addr_can_trap_p (XEXP (x
, 1));
166 /* If it isn't one of the case above, it can cause a trap. */
170 /* Return 1 if X refers to a memory location whose address
171 cannot be compared reliably with constant addresses,
172 or if X refers to a BLKmode memory object. */
175 rtx_addr_varies_p (x
)
178 register enum rtx_code code
;
187 return GET_MODE (x
) == BLKmode
|| rtx_varies_p (XEXP (x
, 0));
189 fmt
= GET_RTX_FORMAT (code
);
190 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
193 if (rtx_addr_varies_p (XEXP (x
, i
)))
196 else if (fmt
[i
] == 'E')
199 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
200 if (rtx_addr_varies_p (XVECEXP (x
, i
, j
)))
206 /* Return the value of the integer term in X, if one is apparent;
208 Only obvious integer terms are detected.
209 This is used in cse.c with the `related_value' field.*/
215 if (GET_CODE (x
) == CONST
)
218 if (GET_CODE (x
) == MINUS
219 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
220 return - INTVAL (XEXP (x
, 1));
221 if (GET_CODE (x
) == PLUS
222 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
223 return INTVAL (XEXP (x
, 1));
227 /* If X is a constant, return the value sans apparent integer term;
229 Only obvious integer terms are detected. */
232 get_related_value (x
)
235 if (GET_CODE (x
) != CONST
)
238 if (GET_CODE (x
) == PLUS
239 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
241 else if (GET_CODE (x
) == MINUS
242 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
247 /* Nonzero if register REG appears somewhere within IN.
248 Also works if REG is not a register; in this case it checks
249 for a subexpression of IN that is Lisp "equal" to REG. */
252 reg_mentioned_p (reg
, in
)
253 register rtx reg
, in
;
257 register enum rtx_code code
;
265 if (GET_CODE (in
) == LABEL_REF
)
266 return reg
== XEXP (in
, 0);
268 code
= GET_CODE (in
);
272 /* Compare registers by number. */
274 return GET_CODE (reg
) == REG
&& REGNO (in
) == REGNO (reg
);
276 /* These codes have no constituent expressions
284 return GET_CODE (reg
) == CONST_INT
&& INTVAL (in
) == INTVAL (reg
);
287 /* These are kept unique for a given value. */
294 if (GET_CODE (reg
) == code
&& rtx_equal_p (reg
, in
))
297 fmt
= GET_RTX_FORMAT (code
);
299 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
304 for (j
= XVECLEN (in
, i
) - 1; j
>= 0; j
--)
305 if (reg_mentioned_p (reg
, XVECEXP (in
, i
, j
)))
308 else if (fmt
[i
] == 'e'
309 && reg_mentioned_p (reg
, XEXP (in
, i
)))
315 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
316 no CODE_LABEL insn. */
319 no_labels_between_p (beg
, end
)
323 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
324 if (GET_CODE (p
) == CODE_LABEL
)
329 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
330 no JUMP_INSN insn. */
333 no_jumps_between_p (beg
, end
)
337 for (p
= NEXT_INSN (beg
); p
!= end
; p
= NEXT_INSN (p
))
338 if (GET_CODE (p
) == JUMP_INSN
)
343 /* Nonzero if register REG is used in an insn between
344 FROM_INSN and TO_INSN (exclusive of those two). */
347 reg_used_between_p (reg
, from_insn
, to_insn
)
348 rtx reg
, from_insn
, to_insn
;
352 if (from_insn
== to_insn
)
355 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
356 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
357 && (reg_overlap_mentioned_p (reg
, PATTERN (insn
))
358 || (GET_CODE (insn
) == CALL_INSN
359 && (find_reg_fusage (insn
, USE
, reg
)
360 || find_reg_fusage (insn
, CLOBBER
, reg
)))))
365 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
366 is entirely replaced by a new value and the only use is as a SET_DEST,
367 we do not consider it a reference. */
370 reg_referenced_p (x
, body
)
376 switch (GET_CODE (body
))
379 if (reg_overlap_mentioned_p (x
, SET_SRC (body
)))
382 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
383 of a REG that occupies all of the REG, the insn references X if
384 it is mentioned in the destination. */
385 if (GET_CODE (SET_DEST (body
)) != CC0
386 && GET_CODE (SET_DEST (body
)) != PC
387 && GET_CODE (SET_DEST (body
)) != REG
388 && ! (GET_CODE (SET_DEST (body
)) == SUBREG
389 && GET_CODE (SUBREG_REG (SET_DEST (body
))) == REG
390 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body
))))
391 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)
392 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body
)))
393 + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
)))
394 && reg_overlap_mentioned_p (x
, SET_DEST (body
)))
399 for (i
= ASM_OPERANDS_INPUT_LENGTH (body
) - 1; i
>= 0; i
--)
400 if (reg_overlap_mentioned_p (x
, ASM_OPERANDS_INPUT (body
, i
)))
406 return reg_overlap_mentioned_p (x
, body
);
409 return reg_overlap_mentioned_p (x
, TRAP_CONDITION (body
));
412 case UNSPEC_VOLATILE
:
413 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
414 if (reg_overlap_mentioned_p (x
, XVECEXP (body
, 0, i
)))
419 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
420 if (reg_referenced_p (x
, XVECEXP (body
, 0, i
)))
429 /* Nonzero if register REG is referenced in an insn between
430 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
434 reg_referenced_between_p (reg
, from_insn
, to_insn
)
435 rtx reg
, from_insn
, to_insn
;
439 if (from_insn
== to_insn
)
442 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
443 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
444 && (reg_referenced_p (reg
, PATTERN (insn
))
445 || (GET_CODE (insn
) == CALL_INSN
446 && find_reg_fusage (insn
, USE
, reg
))))
451 /* Nonzero if register REG is set or clobbered in an insn between
452 FROM_INSN and TO_INSN (exclusive of those two). */
455 reg_set_between_p (reg
, from_insn
, to_insn
)
456 rtx reg
, from_insn
, to_insn
;
460 if (from_insn
== to_insn
)
463 for (insn
= NEXT_INSN (from_insn
); insn
!= to_insn
; insn
= NEXT_INSN (insn
))
464 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
465 && reg_set_p (reg
, insn
))
470 /* Internals of reg_set_between_p. */
472 static rtx reg_set_reg
;
473 static int reg_set_flag
;
478 rtx pat ATTRIBUTE_UNUSED
;
480 /* We don't want to return 1 if X is a MEM that contains a register
481 within REG_SET_REG. */
483 if ((GET_CODE (x
) != MEM
)
484 && reg_overlap_mentioned_p (reg_set_reg
, x
))
489 reg_set_p (reg
, insn
)
494 /* We can be passed an insn or part of one. If we are passed an insn,
495 check if a side-effect of the insn clobbers REG. */
496 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
498 if (FIND_REG_INC_NOTE (insn
, reg
)
499 || (GET_CODE (insn
) == CALL_INSN
500 /* We'd like to test call_used_regs here, but rtlanal.c can't
501 reference that variable due to its use in genattrtab. So
502 we'll just be more conservative.
504 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
505 information holds all clobbered registers. */
506 && ((GET_CODE (reg
) == REG
507 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
508 || GET_CODE (reg
) == MEM
509 || find_reg_fusage (insn
, CLOBBER
, reg
))))
512 body
= PATTERN (insn
);
517 note_stores (body
, reg_set_p_1
);
521 /* Similar to reg_set_between_p, but check all registers in X. Return 0
522 only if none of them are modified between START and END. Do not
523 consider non-registers one way or the other. */
526 regs_set_between_p (x
, start
, end
)
530 enum rtx_code code
= GET_CODE (x
);
546 return reg_set_between_p (x
, start
, end
);
552 fmt
= GET_RTX_FORMAT (code
);
553 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
555 if (fmt
[i
] == 'e' && regs_set_between_p (XEXP (x
, i
), start
, end
))
558 else if (fmt
[i
] == 'E')
559 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
560 if (regs_set_between_p (XVECEXP (x
, i
, j
), start
, end
))
567 /* Similar to reg_set_between_p, but check all registers in X. Return 0
568 only if none of them are modified between START and END. Return 1 if
569 X contains a MEM; this routine does not perform any memory aliasing. */
572 modified_between_p (x
, start
, end
)
576 enum rtx_code code
= GET_CODE (x
);
594 /* If the memory is not constant, assume it is modified. If it is
595 constant, we still have to check the address. */
596 if (! RTX_UNCHANGING_P (x
))
601 return reg_set_between_p (x
, start
, end
);
607 fmt
= GET_RTX_FORMAT (code
);
608 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
610 if (fmt
[i
] == 'e' && modified_between_p (XEXP (x
, i
), start
, end
))
614 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
615 if (modified_between_p (XVECEXP (x
, i
, j
), start
, end
))
622 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
623 of them are modified in INSN. Return 1 if X contains a MEM; this routine
624 does not perform any memory aliasing. */
627 modified_in_p (x
, insn
)
631 enum rtx_code code
= GET_CODE (x
);
649 /* If the memory is not constant, assume it is modified. If it is
650 constant, we still have to check the address. */
651 if (! RTX_UNCHANGING_P (x
))
656 return reg_set_p (x
, insn
);
662 fmt
= GET_RTX_FORMAT (code
);
663 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
665 if (fmt
[i
] == 'e' && modified_in_p (XEXP (x
, i
), insn
))
669 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
670 if (modified_in_p (XVECEXP (x
, i
, j
), insn
))
677 /* Given an INSN, return a SET expression if this insn has only a single SET.
678 It may also have CLOBBERs, USEs, or SET whose output
679 will not be used, which we ignore. */
688 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
691 if (GET_CODE (PATTERN (insn
)) == SET
)
692 return PATTERN (insn
);
694 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
696 for (i
= 0, set
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
697 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
698 && (! find_reg_note (insn
, REG_UNUSED
,
699 SET_DEST (XVECEXP (PATTERN (insn
), 0, i
)))
700 || side_effects_p (XVECEXP (PATTERN (insn
), 0, i
))))
705 set
= XVECEXP (PATTERN (insn
), 0, i
);
713 /* Given an INSN, return nonzero if it has more than one SET, else return
723 /* INSN must be an insn. */
724 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
727 /* Only a PARALLEL can have multiple SETs. */
728 if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
730 for (i
= 0, found
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
731 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
733 /* If we have already found a SET, then return now. */
741 /* Either zero or one SET. */
745 /* Return the last thing that X was assigned from before *PINSN. Verify that
746 the object is not modified up to VALID_TO. If it was, if we hit
747 a partial assignment to X, or hit a CODE_LABEL first, return X. If we
748 found an assignment, update *PINSN to point to it.
749 ALLOW_HWREG is set to 1 if hardware registers are allowed to be the src. */
752 find_last_value (x
, pinsn
, valid_to
, allow_hwreg
)
760 for (p
= PREV_INSN (*pinsn
); p
&& GET_CODE (p
) != CODE_LABEL
;
762 if (GET_RTX_CLASS (GET_CODE (p
)) == 'i')
764 rtx set
= single_set (p
);
765 rtx note
= find_reg_note (p
, REG_EQUAL
, NULL_RTX
);
767 if (set
&& rtx_equal_p (x
, SET_DEST (set
)))
769 rtx src
= SET_SRC (set
);
771 if (note
&& GET_CODE (XEXP (note
, 0)) != EXPR_LIST
)
772 src
= XEXP (note
, 0);
774 if (! modified_between_p (src
, PREV_INSN (p
), valid_to
)
775 /* Reject hard registers because we don't usually want
776 to use them; we'd rather use a pseudo. */
777 && (! (GET_CODE (src
) == REG
778 && REGNO (src
) < FIRST_PSEUDO_REGISTER
) || allow_hwreg
))
785 /* If set in non-simple way, we don't have a value. */
786 if (reg_set_p (x
, p
))
793 /* Return nonzero if register in range [REGNO, ENDREGNO)
794 appears either explicitly or implicitly in X
795 other than being stored into.
797 References contained within the substructure at LOC do not count.
798 LOC may be zero, meaning don't ignore anything. */
801 refers_to_regno_p (regno
, endregno
, x
, loc
)
807 register RTX_CODE code
;
811 /* The contents of a REG_NONNEG note is always zero, so we must come here
812 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
823 /* If we modifying the stack, frame, or argument pointer, it will
824 clobber a virtual register. In fact, we could be more precise,
825 but it isn't worth it. */
826 if ((i
== STACK_POINTER_REGNUM
827 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
828 || i
== ARG_POINTER_REGNUM
830 || i
== FRAME_POINTER_REGNUM
)
831 && regno
>= FIRST_VIRTUAL_REGISTER
&& regno
<= LAST_VIRTUAL_REGISTER
)
835 && regno
< i
+ (i
< FIRST_PSEUDO_REGISTER
836 ? HARD_REGNO_NREGS (i
, GET_MODE (x
))
840 /* If this is a SUBREG of a hard reg, we can see exactly which
841 registers are being modified. Otherwise, handle normally. */
842 if (GET_CODE (SUBREG_REG (x
)) == REG
843 && REGNO (SUBREG_REG (x
)) < FIRST_PSEUDO_REGISTER
)
845 int inner_regno
= REGNO (SUBREG_REG (x
)) + SUBREG_WORD (x
);
847 = inner_regno
+ (inner_regno
< FIRST_PSEUDO_REGISTER
848 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
850 return endregno
> inner_regno
&& regno
< inner_endregno
;
856 if (&SET_DEST (x
) != loc
857 /* Note setting a SUBREG counts as referring to the REG it is in for
858 a pseudo but not for hard registers since we can
859 treat each word individually. */
860 && ((GET_CODE (SET_DEST (x
)) == SUBREG
861 && loc
!= &SUBREG_REG (SET_DEST (x
))
862 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
863 && REGNO (SUBREG_REG (SET_DEST (x
))) >= FIRST_PSEUDO_REGISTER
864 && refers_to_regno_p (regno
, endregno
,
865 SUBREG_REG (SET_DEST (x
)), loc
))
866 || (GET_CODE (SET_DEST (x
)) != REG
867 && refers_to_regno_p (regno
, endregno
, SET_DEST (x
), loc
))))
870 if (code
== CLOBBER
|| loc
== &SET_SRC (x
))
879 /* X does not match, so try its subexpressions. */
881 fmt
= GET_RTX_FORMAT (code
);
882 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
884 if (fmt
[i
] == 'e' && loc
!= &XEXP (x
, i
))
892 if (refers_to_regno_p (regno
, endregno
, XEXP (x
, i
), loc
))
895 else if (fmt
[i
] == 'E')
898 for (j
= XVECLEN (x
, i
) - 1; j
>=0; j
--)
899 if (loc
!= &XVECEXP (x
, i
, j
)
900 && refers_to_regno_p (regno
, endregno
, XVECEXP (x
, i
, j
), loc
))
907 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
908 we check if any register number in X conflicts with the relevant register
909 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
910 contains a MEM (we don't bother checking for memory addresses that can't
911 conflict because we expect this to be a rare case. */
914 reg_overlap_mentioned_p (x
, in
)
919 /* Overly conservative. */
920 if (GET_CODE (x
) == STRICT_LOW_PART
)
923 /* If either argument is a constant, then modifying X can not affect IN. */
924 if (CONSTANT_P (x
) || CONSTANT_P (in
))
926 else if (GET_CODE (x
) == SUBREG
)
928 regno
= REGNO (SUBREG_REG (x
));
929 if (regno
< FIRST_PSEUDO_REGISTER
)
930 regno
+= SUBREG_WORD (x
);
932 else if (GET_CODE (x
) == REG
)
934 else if (GET_CODE (x
) == MEM
)
939 if (GET_CODE (in
) == MEM
)
942 fmt
= GET_RTX_FORMAT (GET_CODE (in
));
944 for (i
= GET_RTX_LENGTH (GET_CODE (in
)) - 1; i
>= 0; i
--)
945 if (fmt
[i
] == 'e' && reg_overlap_mentioned_p (x
, XEXP (in
, i
)))
950 else if (GET_CODE (x
) == SCRATCH
|| GET_CODE (x
) == PC
951 || GET_CODE (x
) == CC0
)
952 return reg_mentioned_p (x
, in
);
953 else if (GET_CODE (x
) == PARALLEL
954 && GET_MODE (x
) == BLKmode
)
958 /* If any register in here refers to it
960 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
961 if (reg_overlap_mentioned_p (SET_DEST (XVECEXP (x
, 0, i
)), in
))
968 endregno
= regno
+ (regno
< FIRST_PSEUDO_REGISTER
969 ? HARD_REGNO_NREGS (regno
, GET_MODE (x
)) : 1);
971 return refers_to_regno_p (regno
, endregno
, in
, NULL_PTR
);
974 /* Used for communications between the next few functions. */
976 static int reg_set_last_unknown
;
977 static rtx reg_set_last_value
;
978 static int reg_set_last_first_regno
, reg_set_last_last_regno
;
980 /* Called via note_stores from reg_set_last. */
983 reg_set_last_1 (x
, pat
)
989 /* If X is not a register, or is not one in the range we care
991 if (GET_CODE (x
) != REG
)
995 last
= first
+ (first
< FIRST_PSEUDO_REGISTER
996 ? HARD_REGNO_NREGS (first
, GET_MODE (x
)) : 1);
998 if (first
>= reg_set_last_last_regno
999 || last
<= reg_set_last_first_regno
)
1002 /* If this is a CLOBBER or is some complex LHS, or doesn't modify
1003 exactly the registers we care about, show we don't know the value. */
1004 if (GET_CODE (pat
) == CLOBBER
|| SET_DEST (pat
) != x
1005 || first
!= reg_set_last_first_regno
1006 || last
!= reg_set_last_last_regno
)
1007 reg_set_last_unknown
= 1;
1009 reg_set_last_value
= SET_SRC (pat
);
1012 /* Return the last value to which REG was set prior to INSN. If we can't
1013 find it easily, return 0.
1015 We only return a REG, SUBREG, or constant because it is too hard to
1016 check if a MEM remains unchanged. */
1019 reg_set_last (x
, insn
)
1023 rtx orig_insn
= insn
;
1025 reg_set_last_first_regno
= REGNO (x
);
1027 reg_set_last_last_regno
1028 = reg_set_last_first_regno
1029 + (reg_set_last_first_regno
< FIRST_PSEUDO_REGISTER
1030 ? HARD_REGNO_NREGS (reg_set_last_first_regno
, GET_MODE (x
)) : 1);
1032 reg_set_last_unknown
= 0;
1033 reg_set_last_value
= 0;
1035 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1036 Stop when we reach a label or X is a hard reg and we reach a
1037 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1039 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1041 /* We compare with <= here, because reg_set_last_last_regno
1042 is actually the number of the first reg *not* in X. */
1044 insn
&& GET_CODE (insn
) != CODE_LABEL
1045 && ! (GET_CODE (insn
) == CALL_INSN
1046 && reg_set_last_last_regno
<= FIRST_PSEUDO_REGISTER
);
1047 insn
= PREV_INSN (insn
))
1048 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
1050 note_stores (PATTERN (insn
), reg_set_last_1
);
1051 if (reg_set_last_unknown
)
1053 else if (reg_set_last_value
)
1055 if (CONSTANT_P (reg_set_last_value
)
1056 || ((GET_CODE (reg_set_last_value
) == REG
1057 || GET_CODE (reg_set_last_value
) == SUBREG
)
1058 && ! reg_set_between_p (reg_set_last_value
,
1060 return reg_set_last_value
;
1069 /* This is 1 until after the rtl generation pass. */
1070 int rtx_equal_function_value_matters
;
1072 /* Return 1 if X and Y are identical-looking rtx's.
1073 This is the Lisp function EQUAL for rtx arguments. */
1081 register enum rtx_code code
;
1086 if (x
== 0 || y
== 0)
1089 code
= GET_CODE (x
);
1090 /* Rtx's of different codes cannot be equal. */
1091 if (code
!= GET_CODE (y
))
1094 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
1095 (REG:SI x) and (REG:HI x) are NOT equivalent. */
1097 if (GET_MODE (x
) != GET_MODE (y
))
1100 /* REG, LABEL_REF, and SYMBOL_REF can be compared nonrecursively. */
1103 /* Until rtl generation is complete, don't consider a reference to the
1104 return register of the current function the same as the return from a
1105 called function. This eases the job of function integration. Once the
1106 distinction is no longer needed, they can be considered equivalent. */
1107 return (REGNO (x
) == REGNO (y
)
1108 && (! rtx_equal_function_value_matters
1109 || REG_FUNCTION_VALUE_P (x
) == REG_FUNCTION_VALUE_P (y
)));
1110 else if (code
== LABEL_REF
)
1111 return XEXP (x
, 0) == XEXP (y
, 0);
1112 else if (code
== SYMBOL_REF
)
1113 return XSTR (x
, 0) == XSTR (y
, 0);
1114 else if (code
== SCRATCH
|| code
== CONST_DOUBLE
)
1117 /* Compare the elements. If any pair of corresponding elements
1118 fail to match, return 0 for the whole things. */
1120 fmt
= GET_RTX_FORMAT (code
);
1121 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1126 if (XWINT (x
, i
) != XWINT (y
, i
))
1132 if (XINT (x
, i
) != XINT (y
, i
))
1138 /* Two vectors must have the same length. */
1139 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
1142 /* And the corresponding elements must match. */
1143 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1144 if (rtx_equal_p (XVECEXP (x
, i
, j
), XVECEXP (y
, i
, j
)) == 0)
1149 if (rtx_equal_p (XEXP (x
, i
), XEXP (y
, i
)) == 0)
1155 if (strcmp (XSTR (x
, i
), XSTR (y
, i
)))
1160 /* These are just backpointers, so they don't matter. */
1166 /* It is believed that rtx's at this level will never
1167 contain anything but integers and other rtx's,
1168 except for within LABEL_REFs and SYMBOL_REFs. */
1176 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1177 (X would be the pattern of an insn).
1178 FUN receives two arguments:
1179 the REG, MEM, CC0 or PC being stored in or clobbered,
1180 the SET or CLOBBER rtx that does the store.
1182 If the item being stored in or clobbered is a SUBREG of a hard register,
1183 the SUBREG will be passed. */
1186 note_stores (x
, fun
)
1188 void (*fun
) PROTO ((rtx
, rtx
));
1190 if ((GET_CODE (x
) == SET
|| GET_CODE (x
) == CLOBBER
))
1192 register rtx dest
= SET_DEST (x
);
1193 while ((GET_CODE (dest
) == SUBREG
1194 && (GET_CODE (SUBREG_REG (dest
)) != REG
1195 || REGNO (SUBREG_REG (dest
)) >= FIRST_PSEUDO_REGISTER
))
1196 || GET_CODE (dest
) == ZERO_EXTRACT
1197 || GET_CODE (dest
) == SIGN_EXTRACT
1198 || GET_CODE (dest
) == STRICT_LOW_PART
)
1199 dest
= XEXP (dest
, 0);
1201 if (GET_CODE (dest
) == PARALLEL
1202 && GET_MODE (dest
) == BLKmode
)
1205 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1206 (*fun
) (SET_DEST (XVECEXP (dest
, 0, i
)), x
);
1211 else if (GET_CODE (x
) == PARALLEL
)
1214 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1216 register rtx y
= XVECEXP (x
, 0, i
);
1217 if (GET_CODE (y
) == SET
|| GET_CODE (y
) == CLOBBER
)
1219 register rtx dest
= SET_DEST (y
);
1220 while ((GET_CODE (dest
) == SUBREG
1221 && (GET_CODE (SUBREG_REG (dest
)) != REG
1222 || (REGNO (SUBREG_REG (dest
))
1223 >= FIRST_PSEUDO_REGISTER
)))
1224 || GET_CODE (dest
) == ZERO_EXTRACT
1225 || GET_CODE (dest
) == SIGN_EXTRACT
1226 || GET_CODE (dest
) == STRICT_LOW_PART
)
1227 dest
= XEXP (dest
, 0);
1228 if (GET_CODE (dest
) == PARALLEL
1229 && GET_MODE (dest
) == BLKmode
)
1232 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
1233 (*fun
) (SET_DEST (XVECEXP (dest
, 0, i
)), y
);
1242 /* Return nonzero if X's old contents don't survive after INSN.
1243 This will be true if X is (cc0) or if X is a register and
1244 X dies in INSN or because INSN entirely sets X.
1246 "Entirely set" means set directly and not through a SUBREG,
1247 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1248 Likewise, REG_INC does not count.
1250 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1251 but for this use that makes no difference, since regs don't overlap
1252 during their lifetimes. Therefore, this function may be used
1253 at any time after deaths have been computed (in flow.c).
1255 If REG is a hard reg that occupies multiple machine registers, this
1256 function will only return 1 if each of those registers will be replaced
1260 dead_or_set_p (insn
, x
)
1264 register int regno
, last_regno
;
1267 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1268 if (GET_CODE (x
) == CC0
)
1271 if (GET_CODE (x
) != REG
)
1275 last_regno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
1276 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (x
)) - 1);
1278 for (i
= regno
; i
<= last_regno
; i
++)
1279 if (! dead_or_set_regno_p (insn
, i
))
1285 /* Utility function for dead_or_set_p to check an individual register. Also
1286 called from flow.c. */
1289 dead_or_set_regno_p (insn
, test_regno
)
1293 int regno
, endregno
;
1296 /* See if there is a death note for something that includes
1298 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1300 if (REG_NOTE_KIND (link
) != REG_DEAD
1301 || GET_CODE (XEXP (link
, 0)) != REG
)
1304 regno
= REGNO (XEXP (link
, 0));
1305 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1306 : regno
+ HARD_REGNO_NREGS (regno
,
1307 GET_MODE (XEXP (link
, 0))));
1309 if (test_regno
>= regno
&& test_regno
< endregno
)
1313 if (GET_CODE (insn
) == CALL_INSN
1314 && find_regno_fusage (insn
, CLOBBER
, test_regno
))
1317 if (GET_CODE (PATTERN (insn
)) == SET
)
1319 rtx dest
= SET_DEST (PATTERN (insn
));
1321 /* A value is totally replaced if it is the destination or the
1322 destination is a SUBREG of REGNO that does not change the number of
1324 if (GET_CODE (dest
) == SUBREG
1325 && (((GET_MODE_SIZE (GET_MODE (dest
))
1326 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1327 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1328 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1329 dest
= SUBREG_REG (dest
);
1331 if (GET_CODE (dest
) != REG
)
1334 regno
= REGNO (dest
);
1335 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1336 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1338 return (test_regno
>= regno
&& test_regno
< endregno
);
1340 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1344 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1346 rtx body
= XVECEXP (PATTERN (insn
), 0, i
);
1348 if (GET_CODE (body
) == SET
|| GET_CODE (body
) == CLOBBER
)
1350 rtx dest
= SET_DEST (body
);
1352 if (GET_CODE (dest
) == SUBREG
1353 && (((GET_MODE_SIZE (GET_MODE (dest
))
1354 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
1355 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
1356 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)))
1357 dest
= SUBREG_REG (dest
);
1359 if (GET_CODE (dest
) != REG
)
1362 regno
= REGNO (dest
);
1363 endregno
= (regno
>= FIRST_PSEUDO_REGISTER
? regno
+ 1
1364 : regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (dest
)));
1366 if (test_regno
>= regno
&& test_regno
< endregno
)
1375 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1376 If DATUM is nonzero, look for one whose datum is DATUM. */
1379 find_reg_note (insn
, kind
, datum
)
1386 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1387 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
1390 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1391 if (REG_NOTE_KIND (link
) == kind
1392 && (datum
== 0 || datum
== XEXP (link
, 0)))
1397 /* Return the reg-note of kind KIND in insn INSN which applies to register
1398 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1399 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1400 it might be the case that the note overlaps REGNO. */
1403 find_regno_note (insn
, kind
, regno
)
1410 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1411 if (GET_RTX_CLASS (GET_CODE (insn
)) != 'i')
1414 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1415 if (REG_NOTE_KIND (link
) == kind
1416 /* Verify that it is a register, so that scratch and MEM won't cause a
1418 && GET_CODE (XEXP (link
, 0)) == REG
1419 && REGNO (XEXP (link
, 0)) <= regno
1420 && ((REGNO (XEXP (link
, 0))
1421 + (REGNO (XEXP (link
, 0)) >= FIRST_PSEUDO_REGISTER
? 1
1422 : HARD_REGNO_NREGS (REGNO (XEXP (link
, 0)),
1423 GET_MODE (XEXP (link
, 0)))))
1429 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1430 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1433 find_reg_fusage (insn
, code
, datum
)
1438 /* If it's not a CALL_INSN, it can't possibly have a
1439 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1440 if (GET_CODE (insn
) != CALL_INSN
)
1446 if (GET_CODE (datum
) != REG
)
1450 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1452 link
= XEXP (link
, 1))
1453 if (GET_CODE (XEXP (link
, 0)) == code
1454 && rtx_equal_p (datum
, SET_DEST (XEXP (link
, 0))))
1459 register int regno
= REGNO (datum
);
1461 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1462 to pseudo registers, so don't bother checking. */
1464 if (regno
< FIRST_PSEUDO_REGISTER
)
1466 int end_regno
= regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (datum
));
1469 for (i
= regno
; i
< end_regno
; i
++)
1470 if (find_regno_fusage (insn
, code
, i
))
1478 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1479 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1482 find_regno_fusage (insn
, code
, regno
)
1489 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1490 to pseudo registers, so don't bother checking. */
1492 if (regno
>= FIRST_PSEUDO_REGISTER
1493 || GET_CODE (insn
) != CALL_INSN
)
1496 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
1498 register int regnote
;
1501 if (GET_CODE (op
= XEXP (link
, 0)) == code
1502 && GET_CODE (SET_DEST (op
)) == REG
1503 && (regnote
= REGNO (SET_DEST (op
))) <= regno
1505 + HARD_REGNO_NREGS (regnote
, GET_MODE (SET_DEST (op
)))
1513 /* Remove register note NOTE from the REG_NOTES of INSN. */
1516 remove_note (insn
, note
)
1522 if (REG_NOTES (insn
) == note
)
1524 REG_NOTES (insn
) = XEXP (note
, 1);
1528 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
1529 if (XEXP (link
, 1) == note
)
1531 XEXP (link
, 1) = XEXP (note
, 1);
1538 /* Search LISTP (an EXPR_LIST) for NODE and remove NODE from the list
1541 A simple equality test is used to determine if NODE is on the
1545 remove_node_from_expr_list (node
, listp
)
1550 rtx prev
= NULL_RTX
;
1554 if (node
== XEXP (temp
, 0))
1556 /* Splice the node out of the list. */
1558 XEXP (prev
, 1) = XEXP (temp
, 1);
1560 *listp
= XEXP (temp
, 1);
1564 temp
= XEXP (temp
, 1);
1568 /* Nonzero if X contains any volatile instructions. These are instructions
1569 which may cause unpredictable machine state instructions, and thus no
1570 instructions should be moved or combined across them. This includes
1571 only volatile asms and UNSPEC_VOLATILE instructions. */
1577 register RTX_CODE code
;
1579 code
= GET_CODE (x
);
1599 case UNSPEC_VOLATILE
:
1600 /* case TRAP_IF: This isn't clear yet. */
1604 if (MEM_VOLATILE_P (x
))
1611 /* Recursively scan the operands of this expression. */
1614 register char *fmt
= GET_RTX_FORMAT (code
);
1617 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1621 if (volatile_insn_p (XEXP (x
, i
)))
1627 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1628 if (volatile_insn_p (XVECEXP (x
, i
, j
)))
1636 /* Nonzero if X contains any volatile memory references
1637 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1643 register RTX_CODE code
;
1645 code
= GET_CODE (x
);
1664 case UNSPEC_VOLATILE
:
1665 /* case TRAP_IF: This isn't clear yet. */
1670 if (MEM_VOLATILE_P (x
))
1677 /* Recursively scan the operands of this expression. */
1680 register char *fmt
= GET_RTX_FORMAT (code
);
1683 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1687 if (volatile_refs_p (XEXP (x
, i
)))
1693 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1694 if (volatile_refs_p (XVECEXP (x
, i
, j
)))
1702 /* Similar to above, except that it also rejects register pre- and post-
1709 register RTX_CODE code
;
1711 code
= GET_CODE (x
);
1729 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1730 when some combination can't be done. If we see one, don't think
1731 that we can simplify the expression. */
1732 return (GET_MODE (x
) != VOIDmode
);
1739 case UNSPEC_VOLATILE
:
1740 /* case TRAP_IF: This isn't clear yet. */
1745 if (MEM_VOLATILE_P (x
))
1752 /* Recursively scan the operands of this expression. */
1755 register char *fmt
= GET_RTX_FORMAT (code
);
1758 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1762 if (side_effects_p (XEXP (x
, i
)))
1768 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1769 if (side_effects_p (XVECEXP (x
, i
, j
)))
1777 /* Return nonzero if evaluating rtx X might cause a trap. */
1789 code
= GET_CODE (x
);
1792 /* Handle these cases quickly. */
1804 /* Conditional trap can trap! */
1805 case UNSPEC_VOLATILE
:
1809 /* Memory ref can trap unless it's a static var or a stack slot. */
1811 return rtx_addr_can_trap_p (XEXP (x
, 0));
1813 /* Division by a non-constant might trap. */
1818 if (! CONSTANT_P (XEXP (x
, 1))
1819 || GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1821 /* This was const0_rtx, but by not using that,
1822 we can link this file into other programs. */
1823 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
&& INTVAL (XEXP (x
, 1)) == 0)
1828 /* An EXPR_LIST is used to represent a function call. This
1829 certainly may trap. */
1833 /* Any floating arithmetic may trap. */
1834 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1838 fmt
= GET_RTX_FORMAT (code
);
1839 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1843 if (may_trap_p (XEXP (x
, i
)))
1846 else if (fmt
[i
] == 'E')
1849 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1850 if (may_trap_p (XVECEXP (x
, i
, j
)))
1857 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1858 i.e., an inequality. */
1861 inequality_comparisons_p (x
)
1865 register int len
, i
;
1866 register enum rtx_code code
= GET_CODE (x
);
1895 len
= GET_RTX_LENGTH (code
);
1896 fmt
= GET_RTX_FORMAT (code
);
1898 for (i
= 0; i
< len
; i
++)
1902 if (inequality_comparisons_p (XEXP (x
, i
)))
1905 else if (fmt
[i
] == 'E')
1908 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1909 if (inequality_comparisons_p (XVECEXP (x
, i
, j
)))
1917 /* Replace any occurrence of FROM in X with TO. The function does
1918 not enter into CONST_DOUBLE for the replace.
1920 Note that copying is not done so X must not be shared unless all copies
1921 are to be modified. */
1924 replace_rtx (x
, from
, to
)
1930 /* The following prevents loops occurrence when we change MEM in
1931 CONST_DOUBLE onto the same CONST_DOUBLE. */
1932 if (x
!= 0 && GET_CODE (x
) == CONST_DOUBLE
)
1938 /* Allow this function to make replacements in EXPR_LISTs. */
1942 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
1943 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
1946 XEXP (x
, i
) = replace_rtx (XEXP (x
, i
), from
, to
);
1947 else if (fmt
[i
] == 'E')
1948 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1949 XVECEXP (x
, i
, j
) = replace_rtx (XVECEXP (x
, i
, j
), from
, to
);
1955 /* Throughout the rtx X, replace many registers according to REG_MAP.
1956 Return the replacement for X (which may be X with altered contents).
1957 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
1958 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
1960 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
1961 should not be mapped to pseudos or vice versa since validate_change
1964 If REPLACE_DEST is 1, replacements are also done in destinations;
1965 otherwise, only sources are replaced. */
1968 replace_regs (x
, reg_map
, nregs
, replace_dest
)
1974 register enum rtx_code code
;
1981 code
= GET_CODE (x
);
1995 /* Verify that the register has an entry before trying to access it. */
1996 if (REGNO (x
) < nregs
&& reg_map
[REGNO (x
)] != 0)
1998 /* SUBREGs can't be shared. Always return a copy to ensure that if
1999 this replacement occurs more than once then each instance will
2000 get distinct rtx. */
2001 if (GET_CODE (reg_map
[REGNO (x
)]) == SUBREG
)
2002 return copy_rtx (reg_map
[REGNO (x
)]);
2003 return reg_map
[REGNO (x
)];
2008 /* Prevent making nested SUBREGs. */
2009 if (GET_CODE (SUBREG_REG (x
)) == REG
&& REGNO (SUBREG_REG (x
)) < nregs
2010 && reg_map
[REGNO (SUBREG_REG (x
))] != 0
2011 && GET_CODE (reg_map
[REGNO (SUBREG_REG (x
))]) == SUBREG
)
2013 rtx map_val
= reg_map
[REGNO (SUBREG_REG (x
))];
2014 rtx map_inner
= SUBREG_REG (map_val
);
2016 if (GET_MODE (x
) == GET_MODE (map_inner
))
2020 /* We cannot call gen_rtx here since we may be linked with
2022 /* Let's try clobbering the incoming SUBREG and see
2023 if this is really safe. */
2024 SUBREG_REG (x
) = map_inner
;
2025 SUBREG_WORD (x
) += SUBREG_WORD (map_val
);
2028 rtx
new = rtx_alloc (SUBREG
);
2029 PUT_MODE (new, GET_MODE (x
));
2030 SUBREG_REG (new) = map_inner
;
2031 SUBREG_WORD (new) = SUBREG_WORD (x
) + SUBREG_WORD (map_val
);
2039 SET_DEST (x
) = replace_regs (SET_DEST (x
), reg_map
, nregs
, 0);
2041 else if (GET_CODE (SET_DEST (x
)) == MEM
2042 || GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2043 /* Even if we are not to replace destinations, replace register if it
2044 is CONTAINED in destination (destination is memory or
2045 STRICT_LOW_PART). */
2046 XEXP (SET_DEST (x
), 0) = replace_regs (XEXP (SET_DEST (x
), 0),
2048 else if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2049 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2052 SET_SRC (x
) = replace_regs (SET_SRC (x
), reg_map
, nregs
, 0);
2059 fmt
= GET_RTX_FORMAT (code
);
2060 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2063 XEXP (x
, i
) = replace_regs (XEXP (x
, i
), reg_map
, nregs
, replace_dest
);
2067 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2068 XVECEXP (x
, i
, j
) = replace_regs (XVECEXP (x
, i
, j
), reg_map
,
2069 nregs
, replace_dest
);
2075 /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is
2076 not in the constant pool and not in the condition of an IF_THEN_ELSE. */
2079 jmp_uses_reg_or_mem (x
)
2082 enum rtx_code code
= GET_CODE (x
);
2097 return ! (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
2098 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)));
2101 return (jmp_uses_reg_or_mem (XEXP (x
, 1))
2102 || jmp_uses_reg_or_mem (XEXP (x
, 2)));
2104 case PLUS
: case MINUS
: case MULT
:
2105 return (jmp_uses_reg_or_mem (XEXP (x
, 0))
2106 || jmp_uses_reg_or_mem (XEXP (x
, 1)));
2112 fmt
= GET_RTX_FORMAT (code
);
2113 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2116 && jmp_uses_reg_or_mem (XEXP (x
, i
)))
2120 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2121 if (jmp_uses_reg_or_mem (XVECEXP (x
, i
, j
)))
2128 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2130 Tablejumps and casesi insns are not considered indirect jumps;
2131 we can recognize them by a (use (lael_ref)). */
2134 computed_jump_p (insn
)
2138 if (GET_CODE (insn
) == JUMP_INSN
)
2140 rtx pat
= PATTERN (insn
);
2142 if (GET_CODE (pat
) == PARALLEL
)
2144 int len
= XVECLEN (pat
, 0);
2145 int has_use_labelref
= 0;
2147 for (i
= len
- 1; i
>= 0; i
--)
2148 if (GET_CODE (XVECEXP (pat
, 0, i
)) == USE
2149 && (GET_CODE (XEXP (XVECEXP (pat
, 0, i
), 0))
2151 has_use_labelref
= 1;
2153 if (! has_use_labelref
)
2154 for (i
= len
- 1; i
>= 0; i
--)
2155 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
2156 && SET_DEST (XVECEXP (pat
, 0, i
)) == pc_rtx
2157 && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat
, 0, i
))))
2160 else if (GET_CODE (pat
) == SET
2161 && SET_DEST (pat
) == pc_rtx
2162 && jmp_uses_reg_or_mem (SET_SRC (pat
)))
2168 /* Traverse X via depth-first search, calling F for each
2169 sub-expression (including X itself). F is also passed the DATA.
2170 If F returns -1, do not traverse sub-expressions, but continue
2171 traversing the rest of the tree. If F ever returns any other
2172 non-zero value, stop the traversal, and return the value returned
2173 by F. Otherwise, return 0. This function does not traverse inside
2174 tree structure that contains RTX_EXPRs, or into sub-expressions
2175 whose format code is `0' since it is not known whether or not those
2176 codes are actually RTL.
2178 This routine is very general, and could (should?) be used to
2179 implement many of the other routines in this file. */
2182 for_each_rtx (x
, f
, data
)
2193 result
= (*f
)(x
, data
);
2195 /* Do not traverse sub-expressions. */
2197 else if (result
!= 0)
2198 /* Stop the traversal. */
2202 /* There are no sub-expressions. */
2205 length
= GET_RTX_LENGTH (GET_CODE (*x
));
2206 format
= GET_RTX_FORMAT (GET_CODE (*x
));
2208 for (i
= 0; i
< length
; ++i
)
2213 result
= for_each_rtx (&XEXP (*x
, i
), f
, data
);
2220 if (XVEC (*x
, i
) != 0)
2223 for (j
= 0; j
< XVECLEN (*x
, i
); ++j
)
2225 result
= for_each_rtx (&XVECEXP (*x
, i
, j
), f
, data
);
2233 /* Nothing to do. */
2242 /* Searches X for any reference to REGNO, returning the rtx of the
2243 reference found if any. Otherwise, returns NULL_RTX. */
2246 regno_use_in (regno
, x
)
2254 if (GET_CODE (x
) == REG
&& REGNO (x
) == regno
)
2257 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
2258 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
2262 if ((tem
= regno_use_in (regno
, XEXP (x
, i
))))
2265 else if (fmt
[i
] == 'E')
2266 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2267 if ((tem
= regno_use_in (regno
, XVECEXP (x
, i
, j
))))
2275 /* Return 1 if X is an autoincrement side effect and the register is
2276 not the stack pointer. */
2281 switch (GET_CODE (x
))
2289 /* There are no REG_INC notes for SP. */
2290 if (XEXP (x
, 0) != stack_pointer_rtx
)