Mark ChangeLog
[official-gcc.git] / gcc / rtlanal.c
blob83c19d81918774349126bebd15ee3b4489d5a9af
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)
10 any later version.
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. */
23 #include "config.h"
24 #include "system.h"
25 #include "toplev.h"
26 #include "rtl.h"
27 #include "hard-reg-set.h"
29 static void set_of_1 PARAMS ((rtx, rtx, void *));
30 static void insn_dependent_p_1 PARAMS ((rtx, rtx, void *));
32 /* Forward declarations */
33 static int computed_jump_p_1 PARAMS ((rtx));
35 /* Bit flags that specify the machine subtype we are compiling for.
36 Bits are tested using macros TARGET_... defined in the tm.h file
37 and set by `-m...' switches. Must be defined in rtlanal.c. */
39 int target_flags;
41 /* Return 1 if the value of X is unstable
42 (would be different at a different point in the program).
43 The frame pointer, arg pointer, etc. are considered stable
44 (within one function) and so is anything marked `unchanging'. */
46 int
47 rtx_unstable_p (x)
48 rtx x;
50 register RTX_CODE code = GET_CODE (x);
51 register int i;
52 register const char *fmt;
54 switch (code)
56 case MEM:
57 return ! RTX_UNCHANGING_P (x) || rtx_unstable_p (XEXP (x, 0));
59 case QUEUED:
60 return 1;
62 case CONST:
63 case CONST_INT:
64 case CONST_DOUBLE:
65 case SYMBOL_REF:
66 case LABEL_REF:
67 return 0;
69 case REG:
70 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
71 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
72 /* The arg pointer varies if it is not a fixed register. */
73 || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])
74 || RTX_UNCHANGING_P (x))
75 return 0;
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)
81 return 0;
82 #endif
83 return 1;
85 case ASM_OPERANDS:
86 if (MEM_VOLATILE_P (x))
87 return 1;
89 /* FALLTHROUGH */
91 default:
92 break;
95 fmt = GET_RTX_FORMAT (code);
96 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
97 if (fmt[i] == 'e')
99 if (rtx_unstable_p (XEXP (x, i)))
100 return 1;
102 else if (fmt[i] == 'E')
104 int j;
105 for (j = 0; j < XVECLEN (x, i); j++)
106 if (rtx_unstable_p (XVECEXP (x, i, j)))
107 return 1;
110 return 0;
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 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
117 zero, we are slightly more conservative.
118 The frame pointer and the arg pointer are considered constant. */
121 rtx_varies_p (x, for_alias)
122 rtx x;
123 int for_alias;
125 register RTX_CODE code = GET_CODE (x);
126 register int i;
127 register const char *fmt;
129 switch (code)
131 case MEM:
132 return ! RTX_UNCHANGING_P (x) || rtx_varies_p (XEXP (x, 0), for_alias);
134 case QUEUED:
135 return 1;
137 case CONST:
138 case CONST_INT:
139 case CONST_DOUBLE:
140 case SYMBOL_REF:
141 case LABEL_REF:
142 return 0;
144 case REG:
145 /* Note that we have to test for the actual rtx used for the frame
146 and arg pointers and not just the register number in case we have
147 eliminated the frame and/or arg pointer and are using it
148 for pseudos. */
149 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
150 /* The arg pointer varies if it is not a fixed register. */
151 || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
152 return 0;
153 if (x == pic_offset_table_rtx
154 #ifdef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
155 /* ??? When call-clobbered, the value is stable modulo the restore
156 that must happen after a call. This currently screws up
157 local-alloc into believing that the restore is not needed, so we
158 must return 0 only if we are called from alias analysis. */
159 && for_alias
160 #endif
162 return 0;
163 return 1;
165 case LO_SUM:
166 /* The operand 0 of a LO_SUM is considered constant
167 (in fact it is related specifically to operand 1)
168 during alias analysis. */
169 return (! for_alias && rtx_varies_p (XEXP (x, 0), for_alias))
170 || rtx_varies_p (XEXP (x, 1), for_alias);
172 case ASM_OPERANDS:
173 if (MEM_VOLATILE_P (x))
174 return 1;
176 /* FALLTHROUGH */
178 default:
179 break;
182 fmt = GET_RTX_FORMAT (code);
183 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
184 if (fmt[i] == 'e')
186 if (rtx_varies_p (XEXP (x, i), for_alias))
187 return 1;
189 else if (fmt[i] == 'E')
191 int j;
192 for (j = 0; j < XVECLEN (x, i); j++)
193 if (rtx_varies_p (XVECEXP (x, i, j), for_alias))
194 return 1;
197 return 0;
200 /* Return 0 if the use of X as an address in a MEM can cause a trap. */
203 rtx_addr_can_trap_p (x)
204 register rtx x;
206 register enum rtx_code code = GET_CODE (x);
208 switch (code)
210 case SYMBOL_REF:
211 return SYMBOL_REF_WEAK (x);
213 case LABEL_REF:
214 return 0;
216 case REG:
217 /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
218 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
219 || x == stack_pointer_rtx
220 /* The arg pointer varies if it is not a fixed register. */
221 || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
222 return 0;
223 /* All of the virtual frame registers are stack references. */
224 if (REGNO (x) >= FIRST_VIRTUAL_REGISTER
225 && REGNO (x) <= LAST_VIRTUAL_REGISTER)
226 return 0;
227 return 1;
229 case CONST:
230 return rtx_addr_can_trap_p (XEXP (x, 0));
232 case PLUS:
233 /* An address is assumed not to trap if it is an address that can't
234 trap plus a constant integer or it is the pic register plus a
235 constant. */
236 return ! ((! rtx_addr_can_trap_p (XEXP (x, 0))
237 && GET_CODE (XEXP (x, 1)) == CONST_INT)
238 || (XEXP (x, 0) == pic_offset_table_rtx
239 && CONSTANT_P (XEXP (x, 1))));
241 case LO_SUM:
242 case PRE_MODIFY:
243 return rtx_addr_can_trap_p (XEXP (x, 1));
245 case PRE_DEC:
246 case PRE_INC:
247 case POST_DEC:
248 case POST_INC:
249 case POST_MODIFY:
250 return rtx_addr_can_trap_p (XEXP (x, 0));
252 default:
253 break;
256 /* If it isn't one of the case above, it can cause a trap. */
257 return 1;
260 /* Return 1 if X refers to a memory location whose address
261 cannot be compared reliably with constant addresses,
262 or if X refers to a BLKmode memory object.
263 FOR_ALIAS is nonzero if we are called from alias analysis; if it is
264 zero, we are slightly more conservative. */
267 rtx_addr_varies_p (x, for_alias)
268 rtx x;
269 int for_alias;
271 register enum rtx_code code;
272 register int i;
273 register const char *fmt;
275 if (x == 0)
276 return 0;
278 code = GET_CODE (x);
279 if (code == MEM)
280 return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0), for_alias);
282 fmt = GET_RTX_FORMAT (code);
283 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
284 if (fmt[i] == 'e')
286 if (rtx_addr_varies_p (XEXP (x, i), for_alias))
287 return 1;
289 else if (fmt[i] == 'E')
291 int j;
292 for (j = 0; j < XVECLEN (x, i); j++)
293 if (rtx_addr_varies_p (XVECEXP (x, i, j), for_alias))
294 return 1;
296 return 0;
299 /* Return the value of the integer term in X, if one is apparent;
300 otherwise return 0.
301 Only obvious integer terms are detected.
302 This is used in cse.c with the `related_value' field.*/
304 HOST_WIDE_INT
305 get_integer_term (x)
306 rtx x;
308 if (GET_CODE (x) == CONST)
309 x = XEXP (x, 0);
311 if (GET_CODE (x) == MINUS
312 && GET_CODE (XEXP (x, 1)) == CONST_INT)
313 return - INTVAL (XEXP (x, 1));
314 if (GET_CODE (x) == PLUS
315 && GET_CODE (XEXP (x, 1)) == CONST_INT)
316 return INTVAL (XEXP (x, 1));
317 return 0;
320 /* If X is a constant, return the value sans apparent integer term;
321 otherwise return 0.
322 Only obvious integer terms are detected. */
325 get_related_value (x)
326 rtx x;
328 if (GET_CODE (x) != CONST)
329 return 0;
330 x = XEXP (x, 0);
331 if (GET_CODE (x) == PLUS
332 && GET_CODE (XEXP (x, 1)) == CONST_INT)
333 return XEXP (x, 0);
334 else if (GET_CODE (x) == MINUS
335 && GET_CODE (XEXP (x, 1)) == CONST_INT)
336 return XEXP (x, 0);
337 return 0;
340 /* Return the number of places FIND appears within X. If COUNT_DEST is
341 zero, we do not count occurrences inside the destination of a SET. */
344 count_occurrences (x, find, count_dest)
345 rtx x, find;
346 int count_dest;
348 int i, j;
349 enum rtx_code code;
350 const char *format_ptr;
351 int count;
353 if (x == find)
354 return 1;
356 code = GET_CODE (x);
358 switch (code)
360 case REG:
361 case CONST_INT:
362 case CONST_DOUBLE:
363 case SYMBOL_REF:
364 case CODE_LABEL:
365 case PC:
366 case CC0:
367 return 0;
369 case MEM:
370 if (GET_CODE (find) == MEM && rtx_equal_p (x, find))
371 return 1;
372 break;
374 case SET:
375 if (SET_DEST (x) == find && ! count_dest)
376 return count_occurrences (SET_SRC (x), find, count_dest);
377 break;
379 default:
380 break;
383 format_ptr = GET_RTX_FORMAT (code);
384 count = 0;
386 for (i = 0; i < GET_RTX_LENGTH (code); i++)
388 switch (*format_ptr++)
390 case 'e':
391 count += count_occurrences (XEXP (x, i), find, count_dest);
392 break;
394 case 'E':
395 for (j = 0; j < XVECLEN (x, i); j++)
396 count += count_occurrences (XVECEXP (x, i, j), find, count_dest);
397 break;
400 return count;
403 /* Nonzero if register REG appears somewhere within IN.
404 Also works if REG is not a register; in this case it checks
405 for a subexpression of IN that is Lisp "equal" to REG. */
408 reg_mentioned_p (reg, in)
409 register rtx reg, in;
411 register const char *fmt;
412 register int i;
413 register enum rtx_code code;
415 if (in == 0)
416 return 0;
418 if (reg == in)
419 return 1;
421 if (GET_CODE (in) == LABEL_REF)
422 return reg == XEXP (in, 0);
424 code = GET_CODE (in);
426 switch (code)
428 /* Compare registers by number. */
429 case REG:
430 return GET_CODE (reg) == REG && REGNO (in) == REGNO (reg);
432 /* These codes have no constituent expressions
433 and are unique. */
434 case SCRATCH:
435 case CC0:
436 case PC:
437 return 0;
439 case CONST_INT:
440 return GET_CODE (reg) == CONST_INT && INTVAL (in) == INTVAL (reg);
442 case CONST_DOUBLE:
443 /* These are kept unique for a given value. */
444 return 0;
446 default:
447 break;
450 if (GET_CODE (reg) == code && rtx_equal_p (reg, in))
451 return 1;
453 fmt = GET_RTX_FORMAT (code);
455 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
457 if (fmt[i] == 'E')
459 register int j;
460 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
461 if (reg_mentioned_p (reg, XVECEXP (in, i, j)))
462 return 1;
464 else if (fmt[i] == 'e'
465 && reg_mentioned_p (reg, XEXP (in, i)))
466 return 1;
468 return 0;
471 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
472 no CODE_LABEL insn. */
475 no_labels_between_p (beg, end)
476 rtx beg, end;
478 register rtx p;
479 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
480 if (GET_CODE (p) == CODE_LABEL)
481 return 0;
482 return 1;
485 /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
486 no JUMP_INSN insn. */
489 no_jumps_between_p (beg, end)
490 rtx beg, end;
492 register rtx p;
493 for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
494 if (GET_CODE (p) == JUMP_INSN)
495 return 0;
496 return 1;
499 /* Nonzero if register REG is used in an insn between
500 FROM_INSN and TO_INSN (exclusive of those two). */
503 reg_used_between_p (reg, from_insn, to_insn)
504 rtx reg, from_insn, to_insn;
506 register rtx insn;
508 if (from_insn == to_insn)
509 return 0;
511 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
512 if (INSN_P (insn)
513 && (reg_overlap_mentioned_p (reg, PATTERN (insn))
514 || (GET_CODE (insn) == CALL_INSN
515 && (find_reg_fusage (insn, USE, reg)
516 || find_reg_fusage (insn, CLOBBER, reg)))))
517 return 1;
518 return 0;
521 /* Nonzero if the old value of X, a register, is referenced in BODY. If X
522 is entirely replaced by a new value and the only use is as a SET_DEST,
523 we do not consider it a reference. */
526 reg_referenced_p (x, body)
527 rtx x;
528 rtx body;
530 int i;
532 switch (GET_CODE (body))
534 case SET:
535 if (reg_overlap_mentioned_p (x, SET_SRC (body)))
536 return 1;
538 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
539 of a REG that occupies all of the REG, the insn references X if
540 it is mentioned in the destination. */
541 if (GET_CODE (SET_DEST (body)) != CC0
542 && GET_CODE (SET_DEST (body)) != PC
543 && GET_CODE (SET_DEST (body)) != REG
544 && ! (GET_CODE (SET_DEST (body)) == SUBREG
545 && GET_CODE (SUBREG_REG (SET_DEST (body))) == REG
546 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body))))
547 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
548 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body)))
549 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
550 && reg_overlap_mentioned_p (x, SET_DEST (body)))
551 return 1;
552 return 0;
554 case ASM_OPERANDS:
555 for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
556 if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i)))
557 return 1;
558 return 0;
560 case CALL:
561 case USE:
562 case IF_THEN_ELSE:
563 return reg_overlap_mentioned_p (x, body);
565 case TRAP_IF:
566 return reg_overlap_mentioned_p (x, TRAP_CONDITION (body));
568 case UNSPEC:
569 case UNSPEC_VOLATILE:
570 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
571 if (reg_overlap_mentioned_p (x, XVECEXP (body, 0, i)))
572 return 1;
573 return 0;
575 case PARALLEL:
576 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
577 if (reg_referenced_p (x, XVECEXP (body, 0, i)))
578 return 1;
579 return 0;
581 case CLOBBER:
582 if (GET_CODE (XEXP (body, 0)) == MEM)
583 if (reg_overlap_mentioned_p (x, XEXP (XEXP (body, 0), 0)))
584 return 1;
585 return 0;
587 case COND_EXEC:
588 if (reg_overlap_mentioned_p (x, COND_EXEC_TEST (body)))
589 return 1;
590 return reg_referenced_p (x, COND_EXEC_CODE (body));
592 default:
593 return 0;
597 /* Nonzero if register REG is referenced in an insn between
598 FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do
599 not count. */
602 reg_referenced_between_p (reg, from_insn, to_insn)
603 rtx reg, from_insn, to_insn;
605 register rtx insn;
607 if (from_insn == to_insn)
608 return 0;
610 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
611 if (INSN_P (insn)
612 && (reg_referenced_p (reg, PATTERN (insn))
613 || (GET_CODE (insn) == CALL_INSN
614 && find_reg_fusage (insn, USE, reg))))
615 return 1;
616 return 0;
619 /* Nonzero if register REG is set or clobbered in an insn between
620 FROM_INSN and TO_INSN (exclusive of those two). */
623 reg_set_between_p (reg, from_insn, to_insn)
624 rtx reg, from_insn, to_insn;
626 register rtx insn;
628 if (from_insn == to_insn)
629 return 0;
631 for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
632 if (INSN_P (insn) && reg_set_p (reg, insn))
633 return 1;
634 return 0;
637 /* Internals of reg_set_between_p. */
639 reg_set_p (reg, insn)
640 rtx reg, insn;
642 rtx body = insn;
644 /* We can be passed an insn or part of one. If we are passed an insn,
645 check if a side-effect of the insn clobbers REG. */
646 if (INSN_P (insn))
648 if (FIND_REG_INC_NOTE (insn, reg)
649 || (GET_CODE (insn) == CALL_INSN
650 /* We'd like to test call_used_regs here, but rtlanal.c can't
651 reference that variable due to its use in genattrtab. So
652 we'll just be more conservative.
654 ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE
655 information holds all clobbered registers. */
656 && ((GET_CODE (reg) == REG
657 && REGNO (reg) < FIRST_PSEUDO_REGISTER)
658 || GET_CODE (reg) == MEM
659 || find_reg_fusage (insn, CLOBBER, reg))))
660 return 1;
662 body = PATTERN (insn);
665 return set_of (reg, insn) != NULL_RTX;
668 /* Similar to reg_set_between_p, but check all registers in X. Return 0
669 only if none of them are modified between START and END. Do not
670 consider non-registers one way or the other. */
673 regs_set_between_p (x, start, end)
674 rtx x;
675 rtx start, end;
677 enum rtx_code code = GET_CODE (x);
678 const char *fmt;
679 int i, j;
681 switch (code)
683 case CONST_INT:
684 case CONST_DOUBLE:
685 case CONST:
686 case SYMBOL_REF:
687 case LABEL_REF:
688 case PC:
689 case CC0:
690 return 0;
692 case REG:
693 return reg_set_between_p (x, start, end);
695 default:
696 break;
699 fmt = GET_RTX_FORMAT (code);
700 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
702 if (fmt[i] == 'e' && regs_set_between_p (XEXP (x, i), start, end))
703 return 1;
705 else if (fmt[i] == 'E')
706 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
707 if (regs_set_between_p (XVECEXP (x, i, j), start, end))
708 return 1;
711 return 0;
714 /* Similar to reg_set_between_p, but check all registers in X. Return 0
715 only if none of them are modified between START and END. Return 1 if
716 X contains a MEM; this routine does not perform any memory aliasing. */
719 modified_between_p (x, start, end)
720 rtx x;
721 rtx start, end;
723 enum rtx_code code = GET_CODE (x);
724 const char *fmt;
725 int i, j;
727 switch (code)
729 case CONST_INT:
730 case CONST_DOUBLE:
731 case CONST:
732 case SYMBOL_REF:
733 case LABEL_REF:
734 return 0;
736 case PC:
737 case CC0:
738 return 1;
740 case MEM:
741 /* If the memory is not constant, assume it is modified. If it is
742 constant, we still have to check the address. */
743 if (! RTX_UNCHANGING_P (x))
744 return 1;
745 break;
747 case REG:
748 return reg_set_between_p (x, start, end);
750 default:
751 break;
754 fmt = GET_RTX_FORMAT (code);
755 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
757 if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end))
758 return 1;
760 else if (fmt[i] == 'E')
761 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
762 if (modified_between_p (XVECEXP (x, i, j), start, end))
763 return 1;
766 return 0;
769 /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
770 of them are modified in INSN. Return 1 if X contains a MEM; this routine
771 does not perform any memory aliasing. */
774 modified_in_p (x, insn)
775 rtx x;
776 rtx insn;
778 enum rtx_code code = GET_CODE (x);
779 const char *fmt;
780 int i, j;
782 switch (code)
784 case CONST_INT:
785 case CONST_DOUBLE:
786 case CONST:
787 case SYMBOL_REF:
788 case LABEL_REF:
789 return 0;
791 case PC:
792 case CC0:
793 return 1;
795 case MEM:
796 /* If the memory is not constant, assume it is modified. If it is
797 constant, we still have to check the address. */
798 if (! RTX_UNCHANGING_P (x))
799 return 1;
800 break;
802 case REG:
803 return reg_set_p (x, insn);
805 default:
806 break;
809 fmt = GET_RTX_FORMAT (code);
810 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
812 if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn))
813 return 1;
815 else if (fmt[i] == 'E')
816 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
817 if (modified_in_p (XVECEXP (x, i, j), insn))
818 return 1;
821 return 0;
824 /* Return true if anything in insn X is (anti,output,true) dependent on
825 anything in insn Y. */
828 insn_dependent_p (x, y)
829 rtx x, y;
831 rtx tmp;
833 if (! INSN_P (x) || ! INSN_P (y))
834 abort ();
836 tmp = PATTERN (y);
837 note_stores (PATTERN (x), insn_dependent_p_1, &tmp);
838 if (tmp == NULL_RTX)
839 return 1;
841 tmp = PATTERN (x);
842 note_stores (PATTERN (y), insn_dependent_p_1, &tmp);
843 if (tmp == NULL_RTX)
844 return 1;
846 return 0;
849 /* A helper routine for insn_dependent_p called through note_stores. */
851 static void
852 insn_dependent_p_1 (x, pat, data)
853 rtx x;
854 rtx pat ATTRIBUTE_UNUSED;
855 void *data;
857 rtx * pinsn = (rtx *) data;
859 if (*pinsn && reg_mentioned_p (x, *pinsn))
860 *pinsn = NULL_RTX;
863 /* Helper function for set_of. */
864 struct set_of_data
866 rtx found;
867 rtx pat;
870 static void
871 set_of_1 (x, pat, data1)
872 rtx x;
873 rtx pat;
874 void *data1;
876 struct set_of_data *data = (struct set_of_data *) (data1);
877 if (rtx_equal_p (x, data->pat)
878 || (GET_CODE (x) != MEM && reg_overlap_mentioned_p (data->pat, x)))
879 data->found = pat;
882 /* Give an INSN, return a SET or CLOBBER expression that does modify PAT
883 (eighter directly or via STRICT_LOW_PART and similar modifiers). */
885 set_of (pat, insn)
886 rtx pat, insn;
888 struct set_of_data data;
889 data.found = NULL_RTX;
890 data.pat = pat;
891 note_stores (INSN_P (insn) ? PATTERN (insn) : insn, set_of_1, &data);
892 return data.found;
895 /* Given an INSN, return a SET expression if this insn has only a single SET.
896 It may also have CLOBBERs, USEs, or SET whose output
897 will not be used, which we ignore. */
900 single_set_2 (insn, pat)
901 rtx insn, pat;
903 rtx set = NULL;
904 int set_verified = 1;
905 int i;
907 if (GET_CODE (pat) == PARALLEL)
909 for (i = 0; i < XVECLEN (pat, 0); i++)
911 rtx sub = XVECEXP (pat, 0, i);
912 switch (GET_CODE (sub))
914 case USE:
915 case CLOBBER:
916 break;
918 case SET:
919 /* We can consider insns having multiple sets, where all
920 but one are dead as single set insns. In common case
921 only single set is present in the pattern so we want
922 to avoid checking for REG_UNUSED notes unless neccesary.
924 When we reach set first time, we just expect this is
925 the single set we are looking for and only when more
926 sets are found in the insn, we check them. */
927 if (!set_verified)
929 if (find_reg_note (insn, REG_UNUSED, SET_DEST (set))
930 && !side_effects_p (set))
931 set = NULL;
932 else
933 set_verified = 1;
935 if (!set)
936 set = sub, set_verified = 0;
937 else if (!find_reg_note (insn, REG_UNUSED, SET_DEST (sub))
938 || side_effects_p (sub))
939 return NULL_RTX;
940 break;
942 default:
943 return NULL_RTX;
947 return set;
950 /* Given an INSN, return nonzero if it has more than one SET, else return
951 zero. */
954 multiple_sets (insn)
955 rtx insn;
957 int found;
958 int i;
960 /* INSN must be an insn. */
961 if (! INSN_P (insn))
962 return 0;
964 /* Only a PARALLEL can have multiple SETs. */
965 if (GET_CODE (PATTERN (insn)) == PARALLEL)
967 for (i = 0, found = 0; i < XVECLEN (PATTERN (insn), 0); i++)
968 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
970 /* If we have already found a SET, then return now. */
971 if (found)
972 return 1;
973 else
974 found = 1;
978 /* Either zero or one SET. */
979 return 0;
982 /* Return the last thing that X was assigned from before *PINSN. If VALID_TO
983 is not NULL_RTX then verify that the object is not modified up to VALID_TO.
984 If the object was modified, if we hit a partial assignment to X, or hit a
985 CODE_LABEL first, return X. If we found an assignment, update *PINSN to
986 point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to
987 be the src. */
990 find_last_value (x, pinsn, valid_to, allow_hwreg)
991 rtx x;
992 rtx *pinsn;
993 rtx valid_to;
994 int allow_hwreg;
996 rtx p;
998 for (p = PREV_INSN (*pinsn); p && GET_CODE (p) != CODE_LABEL;
999 p = PREV_INSN (p))
1000 if (INSN_P (p))
1002 rtx set = single_set (p);
1003 rtx note = find_reg_note (p, REG_EQUAL, NULL_RTX);
1005 if (set && rtx_equal_p (x, SET_DEST (set)))
1007 rtx src = SET_SRC (set);
1009 if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
1010 src = XEXP (note, 0);
1012 if ((valid_to == NULL_RTX
1013 || ! modified_between_p (src, PREV_INSN (p), valid_to))
1014 /* Reject hard registers because we don't usually want
1015 to use them; we'd rather use a pseudo. */
1016 && (! (GET_CODE (src) == REG
1017 && REGNO (src) < FIRST_PSEUDO_REGISTER) || allow_hwreg))
1019 *pinsn = p;
1020 return src;
1024 /* If set in non-simple way, we don't have a value. */
1025 if (reg_set_p (x, p))
1026 break;
1029 return x;
1032 /* Return nonzero if register in range [REGNO, ENDREGNO)
1033 appears either explicitly or implicitly in X
1034 other than being stored into.
1036 References contained within the substructure at LOC do not count.
1037 LOC may be zero, meaning don't ignore anything. */
1040 refers_to_regno_p (regno, endregno, x, loc)
1041 unsigned int regno, endregno;
1042 rtx x;
1043 rtx *loc;
1045 int i;
1046 unsigned int x_regno;
1047 RTX_CODE code;
1048 const char *fmt;
1050 repeat:
1051 /* The contents of a REG_NONNEG note is always zero, so we must come here
1052 upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
1053 if (x == 0)
1054 return 0;
1056 code = GET_CODE (x);
1058 switch (code)
1060 case REG:
1061 x_regno = REGNO (x);
1063 /* If we modifying the stack, frame, or argument pointer, it will
1064 clobber a virtual register. In fact, we could be more precise,
1065 but it isn't worth it. */
1066 if ((x_regno == STACK_POINTER_REGNUM
1067 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1068 || x_regno == ARG_POINTER_REGNUM
1069 #endif
1070 || x_regno == FRAME_POINTER_REGNUM)
1071 && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER)
1072 return 1;
1074 return (endregno > x_regno
1075 && regno < x_regno + (x_regno < FIRST_PSEUDO_REGISTER
1076 ? HARD_REGNO_NREGS (x_regno, GET_MODE (x))
1077 : 1));
1079 case SUBREG:
1080 /* If this is a SUBREG of a hard reg, we can see exactly which
1081 registers are being modified. Otherwise, handle normally. */
1082 if (GET_CODE (SUBREG_REG (x)) == REG
1083 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
1085 unsigned int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
1086 unsigned int inner_endregno
1087 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
1088 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
1090 return endregno > inner_regno && regno < inner_endregno;
1092 break;
1094 case CLOBBER:
1095 case SET:
1096 if (&SET_DEST (x) != loc
1097 /* Note setting a SUBREG counts as referring to the REG it is in for
1098 a pseudo but not for hard registers since we can
1099 treat each word individually. */
1100 && ((GET_CODE (SET_DEST (x)) == SUBREG
1101 && loc != &SUBREG_REG (SET_DEST (x))
1102 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
1103 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
1104 && refers_to_regno_p (regno, endregno,
1105 SUBREG_REG (SET_DEST (x)), loc))
1106 || (GET_CODE (SET_DEST (x)) != REG
1107 && refers_to_regno_p (regno, endregno, SET_DEST (x), loc))))
1108 return 1;
1110 if (code == CLOBBER || loc == &SET_SRC (x))
1111 return 0;
1112 x = SET_SRC (x);
1113 goto repeat;
1115 default:
1116 break;
1119 /* X does not match, so try its subexpressions. */
1121 fmt = GET_RTX_FORMAT (code);
1122 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1124 if (fmt[i] == 'e' && loc != &XEXP (x, i))
1126 if (i == 0)
1128 x = XEXP (x, 0);
1129 goto repeat;
1131 else
1132 if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc))
1133 return 1;
1135 else if (fmt[i] == 'E')
1137 register int j;
1138 for (j = XVECLEN (x, i) - 1; j >=0; j--)
1139 if (loc != &XVECEXP (x, i, j)
1140 && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc))
1141 return 1;
1144 return 0;
1147 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
1148 we check if any register number in X conflicts with the relevant register
1149 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
1150 contains a MEM (we don't bother checking for memory addresses that can't
1151 conflict because we expect this to be a rare case. */
1154 reg_overlap_mentioned_p (x, in)
1155 rtx x, in;
1157 unsigned int regno, endregno;
1159 /* Overly conservative. */
1160 if (GET_CODE (x) == STRICT_LOW_PART)
1161 x = XEXP (x, 0);
1163 /* If either argument is a constant, then modifying X can not affect IN. */
1164 if (CONSTANT_P (x) || CONSTANT_P (in))
1165 return 0;
1167 switch (GET_CODE (x))
1169 case SUBREG:
1170 regno = REGNO (SUBREG_REG (x));
1171 if (regno < FIRST_PSEUDO_REGISTER)
1172 regno += SUBREG_WORD (x);
1173 goto do_reg;
1175 case REG:
1176 regno = REGNO (x);
1177 do_reg:
1178 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
1179 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
1180 return refers_to_regno_p (regno, endregno, in, NULL_PTR);
1182 case MEM:
1184 const char *fmt;
1185 int i;
1187 if (GET_CODE (in) == MEM)
1188 return 1;
1190 fmt = GET_RTX_FORMAT (GET_CODE (in));
1191 for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--)
1192 if (fmt[i] == 'e' && reg_overlap_mentioned_p (x, XEXP (in, i)))
1193 return 1;
1195 return 0;
1198 case SCRATCH:
1199 case PC:
1200 case CC0:
1201 return reg_mentioned_p (x, in);
1203 case PARALLEL:
1205 int i;
1207 /* If any register in here refers to it we return true. */
1208 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1209 if (XEXP (XVECEXP (x, 0, i), 0) != 0
1210 && reg_overlap_mentioned_p (XEXP (XVECEXP (x, 0, i), 0), in))
1211 return 1;
1212 return 0;
1215 default:
1216 break;
1219 abort ();
1222 /* Return the last value to which REG was set prior to INSN. If we can't
1223 find it easily, return 0.
1225 We only return a REG, SUBREG, or constant because it is too hard to
1226 check if a MEM remains unchanged. */
1229 reg_set_last (x, insn)
1230 rtx x;
1231 rtx insn;
1233 rtx orig_insn = insn;
1235 /* Scan backwards until reg_set_last_1 changed one of the above flags.
1236 Stop when we reach a label or X is a hard reg and we reach a
1237 CALL_INSN (if reg_set_last_last_regno is a hard reg).
1239 If we find a set of X, ensure that its SET_SRC remains unchanged. */
1241 /* We compare with <= here, because reg_set_last_last_regno
1242 is actually the number of the first reg *not* in X. */
1243 for (;
1244 insn && GET_CODE (insn) != CODE_LABEL
1245 && ! (GET_CODE (insn) == CALL_INSN
1246 && REGNO (x) <= FIRST_PSEUDO_REGISTER);
1247 insn = PREV_INSN (insn))
1248 if (INSN_P (insn))
1250 rtx set = set_of (x, insn);
1251 /* OK, this function modify our register. See if we understand it. */
1252 if (set)
1254 rtx last_value;
1255 if (GET_CODE (set) != SET || SET_DEST (set) != x)
1256 return 0;
1257 last_value = SET_SRC (x);
1258 if (CONSTANT_P (last_value)
1259 || ((GET_CODE (last_value) == REG
1260 || GET_CODE (last_value) == SUBREG)
1261 && ! reg_set_between_p (last_value,
1262 insn, orig_insn)))
1263 return last_value;
1264 else
1265 return 0;
1269 return 0;
1272 /* Call FUN on each register or MEM that is stored into or clobbered by X.
1273 (X would be the pattern of an insn).
1274 FUN receives two arguments:
1275 the REG, MEM, CC0 or PC being stored in or clobbered,
1276 the SET or CLOBBER rtx that does the store.
1278 If the item being stored in or clobbered is a SUBREG of a hard register,
1279 the SUBREG will be passed. */
1281 void
1282 note_stores (x, fun, data)
1283 register rtx x;
1284 void (*fun) PARAMS ((rtx, rtx, void *));
1285 void *data;
1287 int i;
1289 if (GET_CODE (x) == COND_EXEC)
1290 x = COND_EXEC_CODE (x);
1292 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
1294 register rtx dest = SET_DEST (x);
1296 while ((GET_CODE (dest) == SUBREG
1297 && (GET_CODE (SUBREG_REG (dest)) != REG
1298 || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER))
1299 || GET_CODE (dest) == ZERO_EXTRACT
1300 || GET_CODE (dest) == SIGN_EXTRACT
1301 || GET_CODE (dest) == STRICT_LOW_PART)
1302 dest = XEXP (dest, 0);
1304 /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions,
1305 each of whose first operand is a register. We can't know what
1306 precisely is being set in these cases, so make up a CLOBBER to pass
1307 to the function. */
1308 if (GET_CODE (dest) == PARALLEL)
1310 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
1311 if (XEXP (XVECEXP (dest, 0, i), 0) != 0)
1312 (*fun) (XEXP (XVECEXP (dest, 0, i), 0),
1313 gen_rtx_CLOBBER (VOIDmode,
1314 XEXP (XVECEXP (dest, 0, i), 0)),
1315 data);
1317 else
1318 (*fun) (dest, x, data);
1321 else if (GET_CODE (x) == PARALLEL)
1322 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1323 note_stores (XVECEXP (x, 0, i), fun, data);
1326 /* Return nonzero if X's old contents don't survive after INSN.
1327 This will be true if X is (cc0) or if X is a register and
1328 X dies in INSN or because INSN entirely sets X.
1330 "Entirely set" means set directly and not through a SUBREG,
1331 ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains.
1332 Likewise, REG_INC does not count.
1334 REG may be a hard or pseudo reg. Renumbering is not taken into account,
1335 but for this use that makes no difference, since regs don't overlap
1336 during their lifetimes. Therefore, this function may be used
1337 at any time after deaths have been computed (in flow.c).
1339 If REG is a hard reg that occupies multiple machine registers, this
1340 function will only return 1 if each of those registers will be replaced
1341 by INSN. */
1344 dead_or_set_p (insn, x)
1345 rtx insn;
1346 rtx x;
1348 unsigned int regno, last_regno;
1349 unsigned int i;
1351 /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
1352 if (GET_CODE (x) == CC0)
1353 return 1;
1355 if (GET_CODE (x) != REG)
1356 abort ();
1358 regno = REGNO (x);
1359 last_regno = (regno >= FIRST_PSEUDO_REGISTER ? regno
1360 : regno + HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1);
1362 for (i = regno; i <= last_regno; i++)
1363 if (! dead_or_set_regno_p (insn, i))
1364 return 0;
1366 return 1;
1369 /* Utility function for dead_or_set_p to check an individual register. Also
1370 called from flow.c. */
1373 dead_or_set_regno_p (insn, test_regno)
1374 rtx insn;
1375 unsigned int test_regno;
1377 unsigned int regno, endregno;
1378 rtx pattern;
1380 /* See if there is a death note for something that includes TEST_REGNO. */
1381 if (find_regno_note (insn, REG_DEAD, test_regno))
1382 return 1;
1384 if (GET_CODE (insn) == CALL_INSN
1385 && find_regno_fusage (insn, CLOBBER, test_regno))
1386 return 1;
1388 pattern = PATTERN (insn);
1390 if (GET_CODE (pattern) == COND_EXEC)
1391 pattern = COND_EXEC_CODE (pattern);
1393 if (GET_CODE (pattern) == SET)
1395 rtx dest = SET_DEST (PATTERN (insn));
1397 /* A value is totally replaced if it is the destination or the
1398 destination is a SUBREG of REGNO that does not change the number of
1399 words in it. */
1400 if (GET_CODE (dest) == SUBREG
1401 && (((GET_MODE_SIZE (GET_MODE (dest))
1402 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1403 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1404 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1405 dest = SUBREG_REG (dest);
1407 if (GET_CODE (dest) != REG)
1408 return 0;
1410 regno = REGNO (dest);
1411 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1412 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1414 return (test_regno >= regno && test_regno < endregno);
1416 else if (GET_CODE (pattern) == PARALLEL)
1418 register int i;
1420 for (i = XVECLEN (pattern, 0) - 1; i >= 0; i--)
1422 rtx body = XVECEXP (pattern, 0, i);
1424 if (GET_CODE (body) == COND_EXEC)
1425 body = COND_EXEC_CODE (body);
1427 if (GET_CODE (body) == SET || GET_CODE (body) == CLOBBER)
1429 rtx dest = SET_DEST (body);
1431 if (GET_CODE (dest) == SUBREG
1432 && (((GET_MODE_SIZE (GET_MODE (dest))
1433 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1434 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
1435 + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
1436 dest = SUBREG_REG (dest);
1438 if (GET_CODE (dest) != REG)
1439 continue;
1441 regno = REGNO (dest);
1442 endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1
1443 : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest)));
1445 if (test_regno >= regno && test_regno < endregno)
1446 return 1;
1451 return 0;
1454 /* Return the reg-note of kind KIND in insn INSN, if there is one.
1455 If DATUM is nonzero, look for one whose datum is DATUM. */
1458 find_reg_note (insn, kind, datum)
1459 rtx insn;
1460 enum reg_note kind;
1461 rtx datum;
1463 register rtx link;
1465 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1466 if (! INSN_P (insn))
1467 return 0;
1469 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1470 if (REG_NOTE_KIND (link) == kind
1471 && (datum == 0 || datum == XEXP (link, 0)))
1472 return link;
1473 return 0;
1476 /* Return the reg-note of kind KIND in insn INSN which applies to register
1477 number REGNO, if any. Return 0 if there is no such reg-note. Note that
1478 the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
1479 it might be the case that the note overlaps REGNO. */
1482 find_regno_note (insn, kind, regno)
1483 rtx insn;
1484 enum reg_note kind;
1485 unsigned int regno;
1487 register rtx link;
1489 /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
1490 if (! INSN_P (insn))
1491 return 0;
1493 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1494 if (REG_NOTE_KIND (link) == kind
1495 /* Verify that it is a register, so that scratch and MEM won't cause a
1496 problem here. */
1497 && GET_CODE (XEXP (link, 0)) == REG
1498 && REGNO (XEXP (link, 0)) <= regno
1499 && ((REGNO (XEXP (link, 0))
1500 + (REGNO (XEXP (link, 0)) >= FIRST_PSEUDO_REGISTER ? 1
1501 : HARD_REGNO_NREGS (REGNO (XEXP (link, 0)),
1502 GET_MODE (XEXP (link, 0)))))
1503 > regno))
1504 return link;
1505 return 0;
1508 /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
1509 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1512 find_reg_fusage (insn, code, datum)
1513 rtx insn;
1514 enum rtx_code code;
1515 rtx datum;
1517 /* If it's not a CALL_INSN, it can't possibly have a
1518 CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
1519 if (GET_CODE (insn) != CALL_INSN)
1520 return 0;
1522 if (! datum)
1523 abort();
1525 if (GET_CODE (datum) != REG)
1527 register rtx link;
1529 for (link = CALL_INSN_FUNCTION_USAGE (insn);
1530 link;
1531 link = XEXP (link, 1))
1532 if (GET_CODE (XEXP (link, 0)) == code
1533 && rtx_equal_p (datum, SET_DEST (XEXP (link, 0))))
1534 return 1;
1536 else
1538 unsigned int regno = REGNO (datum);
1540 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1541 to pseudo registers, so don't bother checking. */
1543 if (regno < FIRST_PSEUDO_REGISTER)
1545 unsigned int end_regno
1546 = regno + HARD_REGNO_NREGS (regno, GET_MODE (datum));
1547 unsigned int i;
1549 for (i = regno; i < end_regno; i++)
1550 if (find_regno_fusage (insn, code, i))
1551 return 1;
1555 return 0;
1558 /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
1559 in the CALL_INSN_FUNCTION_USAGE information of INSN. */
1562 find_regno_fusage (insn, code, regno)
1563 rtx insn;
1564 enum rtx_code code;
1565 unsigned int regno;
1567 register rtx link;
1569 /* CALL_INSN_FUNCTION_USAGE information cannot contain references
1570 to pseudo registers, so don't bother checking. */
1572 if (regno >= FIRST_PSEUDO_REGISTER
1573 || GET_CODE (insn) != CALL_INSN )
1574 return 0;
1576 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
1578 unsigned int regnote;
1579 rtx op, reg;
1581 if (GET_CODE (op = XEXP (link, 0)) == code
1582 && GET_CODE (reg = XEXP (op, 0)) == REG
1583 && (regnote = REGNO (reg)) <= regno
1584 && regnote + HARD_REGNO_NREGS (regnote, GET_MODE (reg)) > regno)
1585 return 1;
1588 return 0;
1591 /* Remove register note NOTE from the REG_NOTES of INSN. */
1593 void
1594 remove_note (insn, note)
1595 register rtx insn;
1596 register rtx note;
1598 register rtx link;
1600 if (note == NULL_RTX)
1601 return;
1603 if (REG_NOTES (insn) == note)
1605 REG_NOTES (insn) = XEXP (note, 1);
1606 return;
1609 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1610 if (XEXP (link, 1) == note)
1612 XEXP (link, 1) = XEXP (note, 1);
1613 return;
1616 abort ();
1619 /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
1620 remove that entry from the list if it is found.
1622 A simple equality test is used to determine if NODE matches. */
1624 void
1625 remove_node_from_expr_list (node, listp)
1626 rtx node;
1627 rtx *listp;
1629 rtx temp = *listp;
1630 rtx prev = NULL_RTX;
1632 while (temp)
1634 if (node == XEXP (temp, 0))
1636 /* Splice the node out of the list. */
1637 if (prev)
1638 XEXP (prev, 1) = XEXP (temp, 1);
1639 else
1640 *listp = XEXP (temp, 1);
1642 return;
1645 prev = temp;
1646 temp = XEXP (temp, 1);
1650 /* Nonzero if X contains any volatile instructions. These are instructions
1651 which may cause unpredictable machine state instructions, and thus no
1652 instructions should be moved or combined across them. This includes
1653 only volatile asms and UNSPEC_VOLATILE instructions. */
1656 volatile_insn_p (x)
1657 rtx x;
1659 register RTX_CODE code;
1661 code = GET_CODE (x);
1662 switch (code)
1664 case LABEL_REF:
1665 case SYMBOL_REF:
1666 case CONST_INT:
1667 case CONST:
1668 case CONST_DOUBLE:
1669 case CC0:
1670 case PC:
1671 case REG:
1672 case SCRATCH:
1673 case CLOBBER:
1674 case ASM_INPUT:
1675 case ADDR_VEC:
1676 case ADDR_DIFF_VEC:
1677 case CALL:
1678 case MEM:
1679 return 0;
1681 case UNSPEC_VOLATILE:
1682 /* case TRAP_IF: This isn't clear yet. */
1683 return 1;
1685 case ASM_OPERANDS:
1686 if (MEM_VOLATILE_P (x))
1687 return 1;
1689 default:
1690 break;
1693 /* Recursively scan the operands of this expression. */
1696 register const char *fmt = GET_RTX_FORMAT (code);
1697 register int i;
1699 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1701 if (fmt[i] == 'e')
1703 if (volatile_insn_p (XEXP (x, i)))
1704 return 1;
1706 else if (fmt[i] == 'E')
1708 register int j;
1709 for (j = 0; j < XVECLEN (x, i); j++)
1710 if (volatile_insn_p (XVECEXP (x, i, j)))
1711 return 1;
1715 return 0;
1718 /* Nonzero if X contains any volatile memory references
1719 UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
1722 volatile_refs_p (x)
1723 rtx x;
1725 register RTX_CODE code;
1727 code = GET_CODE (x);
1728 switch (code)
1730 case LABEL_REF:
1731 case SYMBOL_REF:
1732 case CONST_INT:
1733 case CONST:
1734 case CONST_DOUBLE:
1735 case CC0:
1736 case PC:
1737 case REG:
1738 case SCRATCH:
1739 case CLOBBER:
1740 case ASM_INPUT:
1741 case ADDR_VEC:
1742 case ADDR_DIFF_VEC:
1743 return 0;
1745 case CALL:
1746 case UNSPEC_VOLATILE:
1747 /* case TRAP_IF: This isn't clear yet. */
1748 return 1;
1750 case MEM:
1751 case ASM_OPERANDS:
1752 if (MEM_VOLATILE_P (x))
1753 return 1;
1755 default:
1756 break;
1759 /* Recursively scan the operands of this expression. */
1762 register const char *fmt = GET_RTX_FORMAT (code);
1763 register int i;
1765 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1767 if (fmt[i] == 'e')
1769 if (volatile_refs_p (XEXP (x, i)))
1770 return 1;
1772 else if (fmt[i] == 'E')
1774 register int j;
1775 for (j = 0; j < XVECLEN (x, i); j++)
1776 if (volatile_refs_p (XVECEXP (x, i, j)))
1777 return 1;
1781 return 0;
1784 /* Similar to above, except that it also rejects register pre- and post-
1785 incrementing. */
1788 side_effects_p (x)
1789 rtx x;
1791 register RTX_CODE code;
1793 code = GET_CODE (x);
1794 switch (code)
1796 case LABEL_REF:
1797 case SYMBOL_REF:
1798 case CONST_INT:
1799 case CONST:
1800 case CONST_DOUBLE:
1801 case CC0:
1802 case PC:
1803 case REG:
1804 case SCRATCH:
1805 case ASM_INPUT:
1806 case ADDR_VEC:
1807 case ADDR_DIFF_VEC:
1808 return 0;
1810 case CLOBBER:
1811 /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
1812 when some combination can't be done. If we see one, don't think
1813 that we can simplify the expression. */
1814 return (GET_MODE (x) != VOIDmode);
1816 case PRE_INC:
1817 case PRE_DEC:
1818 case POST_INC:
1819 case POST_DEC:
1820 case PRE_MODIFY:
1821 case POST_MODIFY:
1822 case CALL:
1823 case UNSPEC_VOLATILE:
1824 /* case TRAP_IF: This isn't clear yet. */
1825 return 1;
1827 case MEM:
1828 case ASM_OPERANDS:
1829 if (MEM_VOLATILE_P (x))
1830 return 1;
1832 default:
1833 break;
1836 /* Recursively scan the operands of this expression. */
1839 register const char *fmt = GET_RTX_FORMAT (code);
1840 register int i;
1842 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1844 if (fmt[i] == 'e')
1846 if (side_effects_p (XEXP (x, i)))
1847 return 1;
1849 else if (fmt[i] == 'E')
1851 register int j;
1852 for (j = 0; j < XVECLEN (x, i); j++)
1853 if (side_effects_p (XVECEXP (x, i, j)))
1854 return 1;
1858 return 0;
1861 /* Return nonzero if evaluating rtx X might cause a trap. */
1864 may_trap_p (x)
1865 rtx x;
1867 int i;
1868 enum rtx_code code;
1869 const char *fmt;
1871 if (x == 0)
1872 return 0;
1873 code = GET_CODE (x);
1874 switch (code)
1876 /* Handle these cases quickly. */
1877 case CONST_INT:
1878 case CONST_DOUBLE:
1879 case SYMBOL_REF:
1880 case LABEL_REF:
1881 case CONST:
1882 case PC:
1883 case CC0:
1884 case REG:
1885 case SCRATCH:
1886 return 0;
1888 case ASM_INPUT:
1889 case UNSPEC_VOLATILE:
1890 case TRAP_IF:
1891 return 1;
1893 case ASM_OPERANDS:
1894 return MEM_VOLATILE_P (x);
1896 /* Memory ref can trap unless it's a static var or a stack slot. */
1897 case MEM:
1898 return rtx_addr_can_trap_p (XEXP (x, 0));
1900 /* Division by a non-constant might trap. */
1901 case DIV:
1902 case MOD:
1903 case UDIV:
1904 case UMOD:
1905 if (! CONSTANT_P (XEXP (x, 1))
1906 || GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1907 return 1;
1908 /* This was const0_rtx, but by not using that,
1909 we can link this file into other programs. */
1910 if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0)
1911 return 1;
1912 break;
1914 case EXPR_LIST:
1915 /* An EXPR_LIST is used to represent a function call. This
1916 certainly may trap. */
1917 return 1;
1919 case GE:
1920 case GT:
1921 case LE:
1922 case LT:
1923 case COMPARE:
1924 /* Some floating point comparisons may trap. */
1925 /* ??? There is no machine independent way to check for tests that trap
1926 when COMPARE is used, though many targets do make this distinction.
1927 For instance, sparc uses CCFPE for compares which generate exceptions
1928 and CCFP for compares which do not generate exceptions. */
1929 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1930 return 1;
1931 /* But often the compare has some CC mode, so check operand
1932 modes as well. */
1933 if (GET_MODE_CLASS (GET_MODE (XEXP (x, 0))) == MODE_FLOAT
1934 || GET_MODE_CLASS (GET_MODE (XEXP (x, 1))) == MODE_FLOAT)
1935 return 1;
1936 break;
1938 default:
1939 /* Any floating arithmetic may trap. */
1940 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1941 return 1;
1944 fmt = GET_RTX_FORMAT (code);
1945 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1947 if (fmt[i] == 'e')
1949 if (may_trap_p (XEXP (x, i)))
1950 return 1;
1952 else if (fmt[i] == 'E')
1954 register int j;
1955 for (j = 0; j < XVECLEN (x, i); j++)
1956 if (may_trap_p (XVECEXP (x, i, j)))
1957 return 1;
1960 return 0;
1963 /* Return nonzero if X contains a comparison that is not either EQ or NE,
1964 i.e., an inequality. */
1967 inequality_comparisons_p (x)
1968 rtx x;
1970 register const char *fmt;
1971 register int len, i;
1972 register enum rtx_code code = GET_CODE (x);
1974 switch (code)
1976 case REG:
1977 case SCRATCH:
1978 case PC:
1979 case CC0:
1980 case CONST_INT:
1981 case CONST_DOUBLE:
1982 case CONST:
1983 case LABEL_REF:
1984 case SYMBOL_REF:
1985 return 0;
1987 case LT:
1988 case LTU:
1989 case GT:
1990 case GTU:
1991 case LE:
1992 case LEU:
1993 case GE:
1994 case GEU:
1995 return 1;
1997 default:
1998 break;
2001 len = GET_RTX_LENGTH (code);
2002 fmt = GET_RTX_FORMAT (code);
2004 for (i = 0; i < len; i++)
2006 if (fmt[i] == 'e')
2008 if (inequality_comparisons_p (XEXP (x, i)))
2009 return 1;
2011 else if (fmt[i] == 'E')
2013 register int j;
2014 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2015 if (inequality_comparisons_p (XVECEXP (x, i, j)))
2016 return 1;
2020 return 0;
2023 /* Replace any occurrence of FROM in X with TO. The function does
2024 not enter into CONST_DOUBLE for the replace.
2026 Note that copying is not done so X must not be shared unless all copies
2027 are to be modified. */
2030 replace_rtx (x, from, to)
2031 rtx x, from, to;
2033 register int i, j;
2034 register const char *fmt;
2036 /* The following prevents loops occurrence when we change MEM in
2037 CONST_DOUBLE onto the same CONST_DOUBLE. */
2038 if (x != 0 && GET_CODE (x) == CONST_DOUBLE)
2039 return x;
2041 if (x == from)
2042 return to;
2044 /* Allow this function to make replacements in EXPR_LISTs. */
2045 if (x == 0)
2046 return 0;
2048 fmt = GET_RTX_FORMAT (GET_CODE (x));
2049 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2051 if (fmt[i] == 'e')
2052 XEXP (x, i) = replace_rtx (XEXP (x, i), from, to);
2053 else if (fmt[i] == 'E')
2054 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2055 XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to);
2058 return x;
2061 /* Throughout the rtx X, replace many registers according to REG_MAP.
2062 Return the replacement for X (which may be X with altered contents).
2063 REG_MAP[R] is the replacement for register R, or 0 for don't replace.
2064 NREGS is the length of REG_MAP; regs >= NREGS are not mapped.
2066 We only support REG_MAP entries of REG or SUBREG. Also, hard registers
2067 should not be mapped to pseudos or vice versa since validate_change
2068 is not called.
2070 If REPLACE_DEST is 1, replacements are also done in destinations;
2071 otherwise, only sources are replaced. */
2074 replace_regs (x, reg_map, nregs, replace_dest)
2075 rtx x;
2076 rtx *reg_map;
2077 unsigned int nregs;
2078 int replace_dest;
2080 register enum rtx_code code;
2081 register int i;
2082 register const char *fmt;
2084 if (x == 0)
2085 return x;
2087 code = GET_CODE (x);
2088 switch (code)
2090 case SCRATCH:
2091 case PC:
2092 case CC0:
2093 case CONST_INT:
2094 case CONST_DOUBLE:
2095 case CONST:
2096 case SYMBOL_REF:
2097 case LABEL_REF:
2098 return x;
2100 case REG:
2101 /* Verify that the register has an entry before trying to access it. */
2102 if (REGNO (x) < nregs && reg_map[REGNO (x)] != 0)
2104 /* SUBREGs can't be shared. Always return a copy to ensure that if
2105 this replacement occurs more than once then each instance will
2106 get distinct rtx. */
2107 if (GET_CODE (reg_map[REGNO (x)]) == SUBREG)
2108 return copy_rtx (reg_map[REGNO (x)]);
2109 return reg_map[REGNO (x)];
2111 return x;
2113 case SUBREG:
2114 /* Prevent making nested SUBREGs. */
2115 if (GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) < nregs
2116 && reg_map[REGNO (SUBREG_REG (x))] != 0
2117 && GET_CODE (reg_map[REGNO (SUBREG_REG (x))]) == SUBREG)
2119 rtx map_val = reg_map[REGNO (SUBREG_REG (x))];
2120 rtx map_inner = SUBREG_REG (map_val);
2122 if (GET_MODE (x) == GET_MODE (map_inner))
2123 return map_inner;
2124 else
2126 /* We cannot call gen_rtx here since we may be linked with
2127 genattrtab.c. */
2128 /* Let's try clobbering the incoming SUBREG and see
2129 if this is really safe. */
2130 SUBREG_REG (x) = map_inner;
2131 SUBREG_WORD (x) += SUBREG_WORD (map_val);
2132 return x;
2133 #if 0
2134 rtx new = rtx_alloc (SUBREG);
2135 PUT_MODE (new, GET_MODE (x));
2136 SUBREG_REG (new) = map_inner;
2137 SUBREG_WORD (new) = SUBREG_WORD (x) + SUBREG_WORD (map_val);
2138 #endif
2141 break;
2143 case SET:
2144 if (replace_dest)
2145 SET_DEST (x) = replace_regs (SET_DEST (x), reg_map, nregs, 0);
2147 else if (GET_CODE (SET_DEST (x)) == MEM
2148 || GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2149 /* Even if we are not to replace destinations, replace register if it
2150 is CONTAINED in destination (destination is memory or
2151 STRICT_LOW_PART). */
2152 XEXP (SET_DEST (x), 0) = replace_regs (XEXP (SET_DEST (x), 0),
2153 reg_map, nregs, 0);
2154 else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2155 /* Similarly, for ZERO_EXTRACT we replace all operands. */
2156 break;
2158 SET_SRC (x) = replace_regs (SET_SRC (x), reg_map, nregs, 0);
2159 return x;
2161 default:
2162 break;
2165 fmt = GET_RTX_FORMAT (code);
2166 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2168 if (fmt[i] == 'e')
2169 XEXP (x, i) = replace_regs (XEXP (x, i), reg_map, nregs, replace_dest);
2170 else if (fmt[i] == 'E')
2172 register int j;
2173 for (j = 0; j < XVECLEN (x, i); j++)
2174 XVECEXP (x, i, j) = replace_regs (XVECEXP (x, i, j), reg_map,
2175 nregs, replace_dest);
2178 return x;
2181 /* A subroutine of computed_jump_p, return 1 if X contains a REG or MEM or
2182 constant that is not in the constant pool and not in the condition
2183 of an IF_THEN_ELSE. */
2185 static int
2186 computed_jump_p_1 (x)
2187 rtx x;
2189 enum rtx_code code = GET_CODE (x);
2190 int i, j;
2191 const char *fmt;
2193 switch (code)
2195 case LABEL_REF:
2196 case PC:
2197 return 0;
2199 case CONST:
2200 case CONST_INT:
2201 case CONST_DOUBLE:
2202 case SYMBOL_REF:
2203 case REG:
2204 return 1;
2206 case MEM:
2207 return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
2208 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
2210 case IF_THEN_ELSE:
2211 return (computed_jump_p_1 (XEXP (x, 1))
2212 || computed_jump_p_1 (XEXP (x, 2)));
2214 default:
2215 break;
2218 fmt = GET_RTX_FORMAT (code);
2219 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2221 if (fmt[i] == 'e'
2222 && computed_jump_p_1 (XEXP (x, i)))
2223 return 1;
2225 else if (fmt[i] == 'E')
2226 for (j = 0; j < XVECLEN (x, i); j++)
2227 if (computed_jump_p_1 (XVECEXP (x, i, j)))
2228 return 1;
2231 return 0;
2234 /* Return nonzero if INSN is an indirect jump (aka computed jump).
2236 Tablejumps and casesi insns are not considered indirect jumps;
2237 we can recognize them by a (use (label_ref)). */
2240 computed_jump_p (insn)
2241 rtx insn;
2243 int i;
2244 if (GET_CODE (insn) == JUMP_INSN)
2246 rtx pat = PATTERN (insn);
2248 if (find_reg_note (insn, REG_LABEL, NULL_RTX))
2249 return 0;
2250 else if (GET_CODE (pat) == PARALLEL)
2252 int len = XVECLEN (pat, 0);
2253 int has_use_labelref = 0;
2255 for (i = len - 1; i >= 0; i--)
2256 if (GET_CODE (XVECEXP (pat, 0, i)) == USE
2257 && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0))
2258 == LABEL_REF))
2259 has_use_labelref = 1;
2261 if (! has_use_labelref)
2262 for (i = len - 1; i >= 0; i--)
2263 if (GET_CODE (XVECEXP (pat, 0, i)) == SET
2264 && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx
2265 && computed_jump_p_1 (SET_SRC (XVECEXP (pat, 0, i))))
2266 return 1;
2268 else if (GET_CODE (pat) == SET
2269 && SET_DEST (pat) == pc_rtx
2270 && computed_jump_p_1 (SET_SRC (pat)))
2271 return 1;
2273 return 0;
2276 /* Traverse X via depth-first search, calling F for each
2277 sub-expression (including X itself). F is also passed the DATA.
2278 If F returns -1, do not traverse sub-expressions, but continue
2279 traversing the rest of the tree. If F ever returns any other
2280 non-zero value, stop the traversal, and return the value returned
2281 by F. Otherwise, return 0. This function does not traverse inside
2282 tree structure that contains RTX_EXPRs, or into sub-expressions
2283 whose format code is `0' since it is not known whether or not those
2284 codes are actually RTL.
2286 This routine is very general, and could (should?) be used to
2287 implement many of the other routines in this file. */
2290 for_each_rtx (x, f, data)
2291 rtx *x;
2292 rtx_function f;
2293 void *data;
2295 int result;
2296 int length;
2297 const char* format;
2298 int i;
2300 /* Call F on X. */
2301 result = (*f)(x, data);
2302 if (result == -1)
2303 /* Do not traverse sub-expressions. */
2304 return 0;
2305 else if (result != 0)
2306 /* Stop the traversal. */
2307 return result;
2309 if (*x == NULL_RTX)
2310 /* There are no sub-expressions. */
2311 return 0;
2313 length = GET_RTX_LENGTH (GET_CODE (*x));
2314 format = GET_RTX_FORMAT (GET_CODE (*x));
2316 for (i = 0; i < length; ++i)
2318 switch (format[i])
2320 case 'e':
2321 result = for_each_rtx (&XEXP (*x, i), f, data);
2322 if (result != 0)
2323 return result;
2324 break;
2326 case 'V':
2327 case 'E':
2328 if (XVEC (*x, i) != 0)
2330 int j;
2331 for (j = 0; j < XVECLEN (*x, i); ++j)
2333 result = for_each_rtx (&XVECEXP (*x, i, j), f, data);
2334 if (result != 0)
2335 return result;
2338 break;
2340 default:
2341 /* Nothing to do. */
2342 break;
2347 return 0;
2350 /* Searches X for any reference to REGNO, returning the rtx of the
2351 reference found if any. Otherwise, returns NULL_RTX. */
2354 regno_use_in (regno, x)
2355 unsigned int regno;
2356 rtx x;
2358 register const char *fmt;
2359 int i, j;
2360 rtx tem;
2362 if (GET_CODE (x) == REG && REGNO (x) == regno)
2363 return x;
2365 fmt = GET_RTX_FORMAT (GET_CODE (x));
2366 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2368 if (fmt[i] == 'e')
2370 if ((tem = regno_use_in (regno, XEXP (x, i))))
2371 return tem;
2373 else if (fmt[i] == 'E')
2374 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2375 if ((tem = regno_use_in (regno , XVECEXP (x, i, j))))
2376 return tem;
2379 return NULL_RTX;
2383 /* Return 1 if X is an autoincrement side effect and the register is
2384 not the stack pointer. */
2386 auto_inc_p (x)
2387 rtx x;
2389 switch (GET_CODE (x))
2391 case PRE_INC:
2392 case POST_INC:
2393 case PRE_DEC:
2394 case POST_DEC:
2395 case PRE_MODIFY:
2396 case POST_MODIFY:
2397 /* There are no REG_INC notes for SP. */
2398 if (XEXP (x, 0) != stack_pointer_rtx)
2399 return 1;
2400 default:
2401 break;
2403 return 0;
2406 /* Return 1 if the sequence of instructions beginning with FROM and up
2407 to and including TO is safe to move. If NEW_TO is non-NULL, and
2408 the sequence is not already safe to move, but can be easily
2409 extended to a sequence which is safe, then NEW_TO will point to the
2410 end of the extended sequence.
2412 For now, this function only checks that the region contains whole
2413 exception regions, but it could be extended to check additional
2414 conditions as well. */
2417 insns_safe_to_move_p (from, to, new_to)
2418 rtx from;
2419 rtx to;
2420 rtx *new_to;
2422 int eh_region_count = 0;
2423 int past_to_p = 0;
2424 rtx r = from;
2426 /* By default, assume the end of the region will be what was
2427 suggested. */
2428 if (new_to)
2429 *new_to = to;
2431 while (r)
2433 if (GET_CODE (r) == NOTE)
2435 switch (NOTE_LINE_NUMBER (r))
2437 case NOTE_INSN_EH_REGION_BEG:
2438 ++eh_region_count;
2439 break;
2441 case NOTE_INSN_EH_REGION_END:
2442 if (eh_region_count == 0)
2443 /* This sequence of instructions contains the end of
2444 an exception region, but not he beginning. Moving
2445 it will cause chaos. */
2446 return 0;
2448 --eh_region_count;
2449 break;
2451 default:
2452 break;
2455 else if (past_to_p)
2456 /* If we've passed TO, and we see a non-note instruction, we
2457 can't extend the sequence to a movable sequence. */
2458 return 0;
2460 if (r == to)
2462 if (!new_to)
2463 /* It's OK to move the sequence if there were matched sets of
2464 exception region notes. */
2465 return eh_region_count == 0;
2467 past_to_p = 1;
2470 /* It's OK to move the sequence if there were matched sets of
2471 exception region notes. */
2472 if (past_to_p && eh_region_count == 0)
2474 *new_to = r;
2475 return 1;
2478 /* Go to the next instruction. */
2479 r = NEXT_INSN (r);
2482 return 0;
2485 /* Return non-zero if IN contains a piece of rtl that has the address LOC */
2487 loc_mentioned_in_p (loc, in)
2488 rtx *loc, in;
2490 enum rtx_code code = GET_CODE (in);
2491 const char *fmt = GET_RTX_FORMAT (code);
2492 int i, j;
2494 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2496 if (loc == &in->fld[i].rtx)
2497 return 1;
2498 if (fmt[i] == 'e')
2500 if (loc_mentioned_in_p (loc, XEXP (in, i)))
2501 return 1;
2503 else if (fmt[i] == 'E')
2504 for (j = XVECLEN (in, i) - 1; j >= 0; j--)
2505 if (loc_mentioned_in_p (loc, XVECEXP (in, i, j)))
2506 return 1;
2508 return 0;