]>
Commit | Line | Data |
---|---|---|
2c88418c | 1 | /* Analyze RTL for C-Compiler |
af841dbd | 2 | Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
f759eb8b | 3 | 1999, 2000, 2001 Free Software Foundation, Inc. |
2c88418c RS |
4 | |
5 | This file is part of GNU CC. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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 | |
e99215a3 RK |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
2c88418c RS |
21 | |
22 | ||
23 | #include "config.h" | |
670ee920 | 24 | #include "system.h" |
e35b9579 | 25 | #include "toplev.h" |
2c88418c | 26 | #include "rtl.h" |
3335f1d9 | 27 | #include "hard-reg-set.h" |
2c88418c | 28 | |
e2373f95 | 29 | /* Forward declarations */ |
91b2d119 | 30 | static void set_of_1 PARAMS ((rtx, rtx, void *)); |
4eb00163 | 31 | static void insn_dependent_p_1 PARAMS ((rtx, rtx, void *)); |
fce7e199 | 32 | static int computed_jump_p_1 PARAMS ((rtx)); |
2a1777af | 33 | |
2c88418c RS |
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. */ | |
37 | ||
38 | int target_flags; | |
39 | \f | |
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'. */ | |
44 | ||
45 | int | |
46 | rtx_unstable_p (x) | |
47 | rtx x; | |
48 | { | |
49 | register RTX_CODE code = GET_CODE (x); | |
50 | register int i; | |
6f7d635c | 51 | register const char *fmt; |
2c88418c | 52 | |
ae0fb1b9 JW |
53 | switch (code) |
54 | { | |
55 | case MEM: | |
56 | return ! RTX_UNCHANGING_P (x) || rtx_unstable_p (XEXP (x, 0)); | |
2c88418c | 57 | |
ae0fb1b9 JW |
58 | case QUEUED: |
59 | return 1; | |
2c88418c | 60 | |
ae0fb1b9 JW |
61 | case CONST: |
62 | case CONST_INT: | |
63 | case CONST_DOUBLE: | |
64 | case SYMBOL_REF: | |
65 | case LABEL_REF: | |
66 | return 0; | |
2c88418c | 67 | |
ae0fb1b9 JW |
68 | case REG: |
69 | /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */ | |
c0fc376b | 70 | if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx |
3335f1d9 JL |
71 | /* The arg pointer varies if it is not a fixed register. */ |
72 | || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]) | |
73 | || RTX_UNCHANGING_P (x)) | |
c0fc376b RH |
74 | return 0; |
75 | #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED | |
76 | /* ??? When call-clobbered, the value is stable modulo the restore | |
77 | that must happen after a call. This currently screws up local-alloc | |
78 | into believing that the restore is not needed. */ | |
79 | if (x == pic_offset_table_rtx) | |
80 | return 0; | |
81 | #endif | |
82 | return 1; | |
ae0fb1b9 JW |
83 | |
84 | case ASM_OPERANDS: | |
85 | if (MEM_VOLATILE_P (x)) | |
86 | return 1; | |
87 | ||
88 | /* FALLTHROUGH */ | |
89 | ||
90 | default: | |
91 | break; | |
92 | } | |
2c88418c RS |
93 | |
94 | fmt = GET_RTX_FORMAT (code); | |
95 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
96 | if (fmt[i] == 'e') | |
9c82ac6b JW |
97 | { |
98 | if (rtx_unstable_p (XEXP (x, i))) | |
99 | return 1; | |
100 | } | |
101 | else if (fmt[i] == 'E') | |
102 | { | |
103 | int j; | |
104 | for (j = 0; j < XVECLEN (x, i); j++) | |
105 | if (rtx_unstable_p (XVECEXP (x, i, j))) | |
106 | return 1; | |
107 | } | |
108 | ||
2c88418c RS |
109 | return 0; |
110 | } | |
111 | ||
112 | /* Return 1 if X has a value that can vary even between two | |
113 | executions of the program. 0 means X can be compared reliably | |
114 | against certain constants or near-constants. | |
e38fe8e0 BS |
115 | FOR_ALIAS is nonzero if we are called from alias analysis; if it is |
116 | zero, we are slightly more conservative. | |
2c88418c RS |
117 | The frame pointer and the arg pointer are considered constant. */ |
118 | ||
119 | int | |
e38fe8e0 | 120 | rtx_varies_p (x, for_alias) |
2c88418c | 121 | rtx x; |
e38fe8e0 | 122 | int for_alias; |
2c88418c RS |
123 | { |
124 | register RTX_CODE code = GET_CODE (x); | |
125 | register int i; | |
6f7d635c | 126 | register const char *fmt; |
2c88418c RS |
127 | |
128 | switch (code) | |
129 | { | |
130 | case MEM: | |
e38fe8e0 | 131 | return ! RTX_UNCHANGING_P (x) || rtx_varies_p (XEXP (x, 0), for_alias); |
55efb413 | 132 | |
2c88418c RS |
133 | case QUEUED: |
134 | return 1; | |
135 | ||
136 | case CONST: | |
137 | case CONST_INT: | |
138 | case CONST_DOUBLE: | |
139 | case SYMBOL_REF: | |
140 | case LABEL_REF: | |
141 | return 0; | |
142 | ||
143 | case REG: | |
144 | /* Note that we have to test for the actual rtx used for the frame | |
145 | and arg pointers and not just the register number in case we have | |
146 | eliminated the frame and/or arg pointer and are using it | |
147 | for pseudos. */ | |
c0fc376b | 148 | if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx |
3335f1d9 JL |
149 | /* The arg pointer varies if it is not a fixed register. */ |
150 | || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])) | |
c0fc376b | 151 | return 0; |
e38fe8e0 BS |
152 | if (x == pic_offset_table_rtx |
153 | #ifdef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED | |
154 | /* ??? When call-clobbered, the value is stable modulo the restore | |
155 | that must happen after a call. This currently screws up | |
156 | local-alloc into believing that the restore is not needed, so we | |
157 | must return 0 only if we are called from alias analysis. */ | |
158 | && for_alias | |
c0fc376b | 159 | #endif |
e38fe8e0 BS |
160 | ) |
161 | return 0; | |
c0fc376b | 162 | return 1; |
2c88418c RS |
163 | |
164 | case LO_SUM: | |
165 | /* The operand 0 of a LO_SUM is considered constant | |
e7d96a83 JW |
166 | (in fact it is related specifically to operand 1) |
167 | during alias analysis. */ | |
168 | return (! for_alias && rtx_varies_p (XEXP (x, 0), for_alias)) | |
169 | || rtx_varies_p (XEXP (x, 1), for_alias); | |
e9a25f70 | 170 | |
ae0fb1b9 JW |
171 | case ASM_OPERANDS: |
172 | if (MEM_VOLATILE_P (x)) | |
173 | return 1; | |
174 | ||
175 | /* FALLTHROUGH */ | |
176 | ||
e9a25f70 JL |
177 | default: |
178 | break; | |
2c88418c RS |
179 | } |
180 | ||
181 | fmt = GET_RTX_FORMAT (code); | |
182 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
183 | if (fmt[i] == 'e') | |
9c82ac6b | 184 | { |
e38fe8e0 | 185 | if (rtx_varies_p (XEXP (x, i), for_alias)) |
9c82ac6b JW |
186 | return 1; |
187 | } | |
188 | else if (fmt[i] == 'E') | |
189 | { | |
190 | int j; | |
191 | for (j = 0; j < XVECLEN (x, i); j++) | |
e38fe8e0 | 192 | if (rtx_varies_p (XVECEXP (x, i, j), for_alias)) |
9c82ac6b JW |
193 | return 1; |
194 | } | |
195 | ||
2c88418c RS |
196 | return 0; |
197 | } | |
198 | ||
199 | /* Return 0 if the use of X as an address in a MEM can cause a trap. */ | |
200 | ||
e38fe8e0 | 201 | int |
2c88418c RS |
202 | rtx_addr_can_trap_p (x) |
203 | register rtx x; | |
204 | { | |
205 | register enum rtx_code code = GET_CODE (x); | |
206 | ||
207 | switch (code) | |
208 | { | |
209 | case SYMBOL_REF: | |
210 | case LABEL_REF: | |
211 | /* SYMBOL_REF is problematic due to the possible presence of | |
212 | a #pragma weak, but to say that loads from symbols can trap is | |
213 | *very* costly. It's not at all clear what's best here. For | |
214 | now, we ignore the impact of #pragma weak. */ | |
215 | return 0; | |
216 | ||
217 | case REG: | |
218 | /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */ | |
4f73495e RH |
219 | if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx |
220 | || x == stack_pointer_rtx | |
221 | /* The arg pointer varies if it is not a fixed register. */ | |
222 | || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])) | |
223 | return 0; | |
224 | /* All of the virtual frame registers are stack references. */ | |
225 | if (REGNO (x) >= FIRST_VIRTUAL_REGISTER | |
226 | && REGNO (x) <= LAST_VIRTUAL_REGISTER) | |
227 | return 0; | |
228 | return 1; | |
2c88418c RS |
229 | |
230 | case CONST: | |
231 | return rtx_addr_can_trap_p (XEXP (x, 0)); | |
232 | ||
233 | case PLUS: | |
234 | /* An address is assumed not to trap if it is an address that can't | |
55efb413 JW |
235 | trap plus a constant integer or it is the pic register plus a |
236 | constant. */ | |
237 | return ! ((! rtx_addr_can_trap_p (XEXP (x, 0)) | |
238 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
239 | || (XEXP (x, 0) == pic_offset_table_rtx | |
240 | && CONSTANT_P (XEXP (x, 1)))); | |
2c88418c RS |
241 | |
242 | case LO_SUM: | |
4f73495e | 243 | case PRE_MODIFY: |
2c88418c | 244 | return rtx_addr_can_trap_p (XEXP (x, 1)); |
4f73495e RH |
245 | |
246 | case PRE_DEC: | |
247 | case PRE_INC: | |
248 | case POST_DEC: | |
249 | case POST_INC: | |
250 | case POST_MODIFY: | |
251 | return rtx_addr_can_trap_p (XEXP (x, 0)); | |
252 | ||
e9a25f70 JL |
253 | default: |
254 | break; | |
2c88418c RS |
255 | } |
256 | ||
257 | /* If it isn't one of the case above, it can cause a trap. */ | |
258 | return 1; | |
259 | } | |
260 | ||
261 | /* Return 1 if X refers to a memory location whose address | |
262 | cannot be compared reliably with constant addresses, | |
e38fe8e0 BS |
263 | or if X refers to a BLKmode memory object. |
264 | FOR_ALIAS is nonzero if we are called from alias analysis; if it is | |
265 | zero, we are slightly more conservative. */ | |
2c88418c RS |
266 | |
267 | int | |
e38fe8e0 | 268 | rtx_addr_varies_p (x, for_alias) |
2c88418c | 269 | rtx x; |
e38fe8e0 | 270 | int for_alias; |
2c88418c RS |
271 | { |
272 | register enum rtx_code code; | |
273 | register int i; | |
6f7d635c | 274 | register const char *fmt; |
2c88418c RS |
275 | |
276 | if (x == 0) | |
277 | return 0; | |
278 | ||
279 | code = GET_CODE (x); | |
280 | if (code == MEM) | |
e38fe8e0 | 281 | return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0), for_alias); |
2c88418c RS |
282 | |
283 | fmt = GET_RTX_FORMAT (code); | |
284 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
285 | if (fmt[i] == 'e') | |
833c0b26 | 286 | { |
e38fe8e0 | 287 | if (rtx_addr_varies_p (XEXP (x, i), for_alias)) |
833c0b26 RK |
288 | return 1; |
289 | } | |
290 | else if (fmt[i] == 'E') | |
291 | { | |
292 | int j; | |
293 | for (j = 0; j < XVECLEN (x, i); j++) | |
e38fe8e0 | 294 | if (rtx_addr_varies_p (XVECEXP (x, i, j), for_alias)) |
833c0b26 RK |
295 | return 1; |
296 | } | |
2c88418c RS |
297 | return 0; |
298 | } | |
299 | \f | |
300 | /* Return the value of the integer term in X, if one is apparent; | |
301 | otherwise return 0. | |
302 | Only obvious integer terms are detected. | |
303 | This is used in cse.c with the `related_value' field.*/ | |
304 | ||
c166a311 | 305 | HOST_WIDE_INT |
2c88418c RS |
306 | get_integer_term (x) |
307 | rtx x; | |
308 | { | |
309 | if (GET_CODE (x) == CONST) | |
310 | x = XEXP (x, 0); | |
311 | ||
312 | if (GET_CODE (x) == MINUS | |
313 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
314 | return - INTVAL (XEXP (x, 1)); | |
315 | if (GET_CODE (x) == PLUS | |
316 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
317 | return INTVAL (XEXP (x, 1)); | |
318 | return 0; | |
319 | } | |
320 | ||
321 | /* If X is a constant, return the value sans apparent integer term; | |
322 | otherwise return 0. | |
323 | Only obvious integer terms are detected. */ | |
324 | ||
325 | rtx | |
326 | get_related_value (x) | |
327 | rtx x; | |
328 | { | |
329 | if (GET_CODE (x) != CONST) | |
330 | return 0; | |
331 | x = XEXP (x, 0); | |
332 | if (GET_CODE (x) == PLUS | |
333 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
334 | return XEXP (x, 0); | |
335 | else if (GET_CODE (x) == MINUS | |
336 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
337 | return XEXP (x, 0); | |
338 | return 0; | |
339 | } | |
340 | \f | |
4b983fdc RH |
341 | /* Return the number of places FIND appears within X. If COUNT_DEST is |
342 | zero, we do not count occurrences inside the destination of a SET. */ | |
343 | ||
344 | int | |
345 | count_occurrences (x, find, count_dest) | |
346 | rtx x, find; | |
347 | int count_dest; | |
348 | { | |
349 | int i, j; | |
350 | enum rtx_code code; | |
351 | const char *format_ptr; | |
352 | int count; | |
353 | ||
354 | if (x == find) | |
355 | return 1; | |
356 | ||
357 | code = GET_CODE (x); | |
358 | ||
359 | switch (code) | |
360 | { | |
361 | case REG: | |
362 | case CONST_INT: | |
363 | case CONST_DOUBLE: | |
364 | case SYMBOL_REF: | |
365 | case CODE_LABEL: | |
366 | case PC: | |
367 | case CC0: | |
368 | return 0; | |
369 | ||
370 | case MEM: | |
371 | if (GET_CODE (find) == MEM && rtx_equal_p (x, find)) | |
372 | return 1; | |
373 | break; | |
374 | ||
375 | case SET: | |
376 | if (SET_DEST (x) == find && ! count_dest) | |
377 | return count_occurrences (SET_SRC (x), find, count_dest); | |
378 | break; | |
379 | ||
380 | default: | |
381 | break; | |
382 | } | |
383 | ||
384 | format_ptr = GET_RTX_FORMAT (code); | |
385 | count = 0; | |
386 | ||
387 | for (i = 0; i < GET_RTX_LENGTH (code); i++) | |
388 | { | |
389 | switch (*format_ptr++) | |
390 | { | |
391 | case 'e': | |
392 | count += count_occurrences (XEXP (x, i), find, count_dest); | |
393 | break; | |
394 | ||
395 | case 'E': | |
396 | for (j = 0; j < XVECLEN (x, i); j++) | |
397 | count += count_occurrences (XVECEXP (x, i, j), find, count_dest); | |
398 | break; | |
399 | } | |
400 | } | |
401 | return count; | |
402 | } | |
403 | \f | |
2c88418c RS |
404 | /* Nonzero if register REG appears somewhere within IN. |
405 | Also works if REG is not a register; in this case it checks | |
406 | for a subexpression of IN that is Lisp "equal" to REG. */ | |
407 | ||
408 | int | |
409 | reg_mentioned_p (reg, in) | |
410 | register rtx reg, in; | |
411 | { | |
6f7d635c | 412 | register const char *fmt; |
2c88418c RS |
413 | register int i; |
414 | register enum rtx_code code; | |
415 | ||
416 | if (in == 0) | |
417 | return 0; | |
418 | ||
419 | if (reg == in) | |
420 | return 1; | |
421 | ||
422 | if (GET_CODE (in) == LABEL_REF) | |
423 | return reg == XEXP (in, 0); | |
424 | ||
425 | code = GET_CODE (in); | |
426 | ||
427 | switch (code) | |
428 | { | |
429 | /* Compare registers by number. */ | |
430 | case REG: | |
431 | return GET_CODE (reg) == REG && REGNO (in) == REGNO (reg); | |
432 | ||
433 | /* These codes have no constituent expressions | |
434 | and are unique. */ | |
435 | case SCRATCH: | |
436 | case CC0: | |
437 | case PC: | |
438 | return 0; | |
439 | ||
440 | case CONST_INT: | |
441 | return GET_CODE (reg) == CONST_INT && INTVAL (in) == INTVAL (reg); | |
442 | ||
443 | case CONST_DOUBLE: | |
444 | /* These are kept unique for a given value. */ | |
445 | return 0; | |
e9a25f70 JL |
446 | |
447 | default: | |
448 | break; | |
2c88418c RS |
449 | } |
450 | ||
451 | if (GET_CODE (reg) == code && rtx_equal_p (reg, in)) | |
452 | return 1; | |
453 | ||
454 | fmt = GET_RTX_FORMAT (code); | |
455 | ||
456 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
457 | { | |
458 | if (fmt[i] == 'E') | |
459 | { | |
460 | register int j; | |
461 | for (j = XVECLEN (in, i) - 1; j >= 0; j--) | |
462 | if (reg_mentioned_p (reg, XVECEXP (in, i, j))) | |
463 | return 1; | |
464 | } | |
465 | else if (fmt[i] == 'e' | |
466 | && reg_mentioned_p (reg, XEXP (in, i))) | |
467 | return 1; | |
468 | } | |
469 | return 0; | |
470 | } | |
471 | \f | |
472 | /* Return 1 if in between BEG and END, exclusive of BEG and END, there is | |
473 | no CODE_LABEL insn. */ | |
474 | ||
475 | int | |
476 | no_labels_between_p (beg, end) | |
477 | rtx beg, end; | |
478 | { | |
479 | register rtx p; | |
480 | for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p)) | |
481 | if (GET_CODE (p) == CODE_LABEL) | |
482 | return 0; | |
483 | return 1; | |
484 | } | |
485 | ||
3ec2b590 R |
486 | /* Return 1 if in between BEG and END, exclusive of BEG and END, there is |
487 | no JUMP_INSN insn. */ | |
488 | ||
489 | int | |
490 | no_jumps_between_p (beg, end) | |
491 | rtx beg, end; | |
492 | { | |
493 | register rtx p; | |
494 | for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p)) | |
495 | if (GET_CODE (p) == JUMP_INSN) | |
496 | return 0; | |
497 | return 1; | |
498 | } | |
499 | ||
2c88418c RS |
500 | /* Nonzero if register REG is used in an insn between |
501 | FROM_INSN and TO_INSN (exclusive of those two). */ | |
502 | ||
503 | int | |
504 | reg_used_between_p (reg, from_insn, to_insn) | |
505 | rtx reg, from_insn, to_insn; | |
506 | { | |
507 | register rtx insn; | |
508 | ||
509 | if (from_insn == to_insn) | |
510 | return 0; | |
511 | ||
512 | for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn)) | |
2c3c49de | 513 | if (INSN_P (insn) |
8f3e7a26 RK |
514 | && (reg_overlap_mentioned_p (reg, PATTERN (insn)) |
515 | || (GET_CODE (insn) == CALL_INSN | |
516 | && (find_reg_fusage (insn, USE, reg) | |
517 | || find_reg_fusage (insn, CLOBBER, reg))))) | |
2c88418c RS |
518 | return 1; |
519 | return 0; | |
520 | } | |
521 | \f | |
522 | /* Nonzero if the old value of X, a register, is referenced in BODY. If X | |
523 | is entirely replaced by a new value and the only use is as a SET_DEST, | |
524 | we do not consider it a reference. */ | |
525 | ||
526 | int | |
527 | reg_referenced_p (x, body) | |
528 | rtx x; | |
529 | rtx body; | |
530 | { | |
531 | int i; | |
532 | ||
533 | switch (GET_CODE (body)) | |
534 | { | |
535 | case SET: | |
536 | if (reg_overlap_mentioned_p (x, SET_SRC (body))) | |
537 | return 1; | |
538 | ||
539 | /* If the destination is anything other than CC0, PC, a REG or a SUBREG | |
540 | of a REG that occupies all of the REG, the insn references X if | |
541 | it is mentioned in the destination. */ | |
542 | if (GET_CODE (SET_DEST (body)) != CC0 | |
543 | && GET_CODE (SET_DEST (body)) != PC | |
544 | && GET_CODE (SET_DEST (body)) != REG | |
545 | && ! (GET_CODE (SET_DEST (body)) == SUBREG | |
546 | && GET_CODE (SUBREG_REG (SET_DEST (body))) == REG | |
547 | && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body)))) | |
548 | + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD) | |
549 | == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body))) | |
550 | + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))) | |
551 | && reg_overlap_mentioned_p (x, SET_DEST (body))) | |
552 | return 1; | |
e9a25f70 | 553 | return 0; |
2c88418c RS |
554 | |
555 | case ASM_OPERANDS: | |
556 | for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--) | |
557 | if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i))) | |
558 | return 1; | |
e9a25f70 | 559 | return 0; |
2c88418c RS |
560 | |
561 | case CALL: | |
562 | case USE: | |
14a774a9 | 563 | case IF_THEN_ELSE: |
2c88418c RS |
564 | return reg_overlap_mentioned_p (x, body); |
565 | ||
566 | case TRAP_IF: | |
567 | return reg_overlap_mentioned_p (x, TRAP_CONDITION (body)); | |
568 | ||
2ac4fed0 RK |
569 | case UNSPEC: |
570 | case UNSPEC_VOLATILE: | |
2f9fb4c2 R |
571 | for (i = XVECLEN (body, 0) - 1; i >= 0; i--) |
572 | if (reg_overlap_mentioned_p (x, XVECEXP (body, 0, i))) | |
573 | return 1; | |
574 | return 0; | |
575 | ||
2c88418c RS |
576 | case PARALLEL: |
577 | for (i = XVECLEN (body, 0) - 1; i >= 0; i--) | |
578 | if (reg_referenced_p (x, XVECEXP (body, 0, i))) | |
579 | return 1; | |
e9a25f70 JL |
580 | return 0; |
581 | ||
0d3ffb5a GK |
582 | case CLOBBER: |
583 | if (GET_CODE (XEXP (body, 0)) == MEM) | |
584 | if (reg_overlap_mentioned_p (x, XEXP (XEXP (body, 0), 0))) | |
585 | return 1; | |
586 | return 0; | |
587 | ||
0c99ec5c RH |
588 | case COND_EXEC: |
589 | if (reg_overlap_mentioned_p (x, COND_EXEC_TEST (body))) | |
590 | return 1; | |
591 | return reg_referenced_p (x, COND_EXEC_CODE (body)); | |
592 | ||
e9a25f70 JL |
593 | default: |
594 | return 0; | |
2c88418c | 595 | } |
2c88418c RS |
596 | } |
597 | ||
598 | /* Nonzero if register REG is referenced in an insn between | |
599 | FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do | |
0f41302f | 600 | not count. */ |
2c88418c RS |
601 | |
602 | int | |
603 | reg_referenced_between_p (reg, from_insn, to_insn) | |
604 | rtx reg, from_insn, to_insn; | |
605 | { | |
606 | register rtx insn; | |
607 | ||
608 | if (from_insn == to_insn) | |
609 | return 0; | |
610 | ||
611 | for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn)) | |
2c3c49de | 612 | if (INSN_P (insn) |
8f3e7a26 RK |
613 | && (reg_referenced_p (reg, PATTERN (insn)) |
614 | || (GET_CODE (insn) == CALL_INSN | |
615 | && find_reg_fusage (insn, USE, reg)))) | |
2c88418c RS |
616 | return 1; |
617 | return 0; | |
618 | } | |
619 | \f | |
620 | /* Nonzero if register REG is set or clobbered in an insn between | |
621 | FROM_INSN and TO_INSN (exclusive of those two). */ | |
622 | ||
623 | int | |
624 | reg_set_between_p (reg, from_insn, to_insn) | |
625 | rtx reg, from_insn, to_insn; | |
626 | { | |
627 | register rtx insn; | |
628 | ||
629 | if (from_insn == to_insn) | |
630 | return 0; | |
631 | ||
632 | for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn)) | |
2c3c49de | 633 | if (INSN_P (insn) && reg_set_p (reg, insn)) |
2c88418c RS |
634 | return 1; |
635 | return 0; | |
636 | } | |
637 | ||
638 | /* Internals of reg_set_between_p. */ | |
2c88418c RS |
639 | int |
640 | reg_set_p (reg, insn) | |
641 | rtx reg, insn; | |
642 | { | |
643 | rtx body = insn; | |
644 | ||
645 | /* We can be passed an insn or part of one. If we are passed an insn, | |
646 | check if a side-effect of the insn clobbers REG. */ | |
2c3c49de | 647 | if (INSN_P (insn)) |
2c88418c RS |
648 | { |
649 | if (FIND_REG_INC_NOTE (insn, reg) | |
650 | || (GET_CODE (insn) == CALL_INSN | |
651 | /* We'd like to test call_used_regs here, but rtlanal.c can't | |
652 | reference that variable due to its use in genattrtab. So | |
8f3e7a26 RK |
653 | we'll just be more conservative. |
654 | ||
655 | ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE | |
656 | information holds all clobbered registers. */ | |
2c88418c RS |
657 | && ((GET_CODE (reg) == REG |
658 | && REGNO (reg) < FIRST_PSEUDO_REGISTER) | |
8f3e7a26 RK |
659 | || GET_CODE (reg) == MEM |
660 | || find_reg_fusage (insn, CLOBBER, reg)))) | |
2c88418c RS |
661 | return 1; |
662 | ||
663 | body = PATTERN (insn); | |
664 | } | |
665 | ||
91b2d119 | 666 | return set_of (reg, insn) != NULL_RTX; |
2c88418c RS |
667 | } |
668 | ||
a2e1a0bf RH |
669 | /* Similar to reg_set_between_p, but check all registers in X. Return 0 |
670 | only if none of them are modified between START and END. Do not | |
671 | consider non-registers one way or the other. */ | |
672 | ||
673 | int | |
674 | regs_set_between_p (x, start, end) | |
675 | rtx x; | |
676 | rtx start, end; | |
677 | { | |
678 | enum rtx_code code = GET_CODE (x); | |
6f7d635c | 679 | const char *fmt; |
a2e1a0bf RH |
680 | int i, j; |
681 | ||
682 | switch (code) | |
683 | { | |
684 | case CONST_INT: | |
685 | case CONST_DOUBLE: | |
686 | case CONST: | |
687 | case SYMBOL_REF: | |
688 | case LABEL_REF: | |
689 | case PC: | |
690 | case CC0: | |
691 | return 0; | |
692 | ||
693 | case REG: | |
694 | return reg_set_between_p (x, start, end); | |
695 | ||
696 | default: | |
697 | break; | |
698 | } | |
699 | ||
700 | fmt = GET_RTX_FORMAT (code); | |
701 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
702 | { | |
703 | if (fmt[i] == 'e' && regs_set_between_p (XEXP (x, i), start, end)) | |
704 | return 1; | |
705 | ||
706 | else if (fmt[i] == 'E') | |
707 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
708 | if (regs_set_between_p (XVECEXP (x, i, j), start, end)) | |
709 | return 1; | |
710 | } | |
711 | ||
712 | return 0; | |
713 | } | |
714 | ||
2c88418c RS |
715 | /* Similar to reg_set_between_p, but check all registers in X. Return 0 |
716 | only if none of them are modified between START and END. Return 1 if | |
717 | X contains a MEM; this routine does not perform any memory aliasing. */ | |
718 | ||
719 | int | |
720 | modified_between_p (x, start, end) | |
721 | rtx x; | |
722 | rtx start, end; | |
723 | { | |
724 | enum rtx_code code = GET_CODE (x); | |
6f7d635c | 725 | const char *fmt; |
f8163c92 | 726 | int i, j; |
2c88418c RS |
727 | |
728 | switch (code) | |
729 | { | |
730 | case CONST_INT: | |
731 | case CONST_DOUBLE: | |
732 | case CONST: | |
733 | case SYMBOL_REF: | |
734 | case LABEL_REF: | |
735 | return 0; | |
736 | ||
737 | case PC: | |
738 | case CC0: | |
739 | return 1; | |
740 | ||
741 | case MEM: | |
742 | /* If the memory is not constant, assume it is modified. If it is | |
743 | constant, we still have to check the address. */ | |
744 | if (! RTX_UNCHANGING_P (x)) | |
745 | return 1; | |
746 | break; | |
747 | ||
748 | case REG: | |
749 | return reg_set_between_p (x, start, end); | |
e9a25f70 JL |
750 | |
751 | default: | |
752 | break; | |
2c88418c RS |
753 | } |
754 | ||
755 | fmt = GET_RTX_FORMAT (code); | |
756 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
f8163c92 RK |
757 | { |
758 | if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end)) | |
759 | return 1; | |
760 | ||
d4757e6a | 761 | else if (fmt[i] == 'E') |
f8163c92 RK |
762 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) |
763 | if (modified_between_p (XVECEXP (x, i, j), start, end)) | |
764 | return 1; | |
765 | } | |
766 | ||
767 | return 0; | |
768 | } | |
769 | ||
770 | /* Similar to reg_set_p, but check all registers in X. Return 0 only if none | |
771 | of them are modified in INSN. Return 1 if X contains a MEM; this routine | |
772 | does not perform any memory aliasing. */ | |
773 | ||
774 | int | |
775 | modified_in_p (x, insn) | |
776 | rtx x; | |
777 | rtx insn; | |
778 | { | |
779 | enum rtx_code code = GET_CODE (x); | |
6f7d635c | 780 | const char *fmt; |
f8163c92 RK |
781 | int i, j; |
782 | ||
783 | switch (code) | |
784 | { | |
785 | case CONST_INT: | |
786 | case CONST_DOUBLE: | |
787 | case CONST: | |
788 | case SYMBOL_REF: | |
789 | case LABEL_REF: | |
790 | return 0; | |
791 | ||
792 | case PC: | |
793 | case CC0: | |
2c88418c RS |
794 | return 1; |
795 | ||
f8163c92 RK |
796 | case MEM: |
797 | /* If the memory is not constant, assume it is modified. If it is | |
798 | constant, we still have to check the address. */ | |
799 | if (! RTX_UNCHANGING_P (x)) | |
800 | return 1; | |
801 | break; | |
802 | ||
803 | case REG: | |
804 | return reg_set_p (x, insn); | |
e9a25f70 JL |
805 | |
806 | default: | |
807 | break; | |
f8163c92 RK |
808 | } |
809 | ||
810 | fmt = GET_RTX_FORMAT (code); | |
811 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
812 | { | |
813 | if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn)) | |
814 | return 1; | |
815 | ||
d4757e6a | 816 | else if (fmt[i] == 'E') |
f8163c92 RK |
817 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) |
818 | if (modified_in_p (XVECEXP (x, i, j), insn)) | |
819 | return 1; | |
820 | } | |
821 | ||
2c88418c RS |
822 | return 0; |
823 | } | |
a8393d5d | 824 | |
4eb00163 | 825 | /* Return true if anything in insn X is (anti,output,true) dependent on |
a8393d5d RH |
826 | anything in insn Y. */ |
827 | ||
828 | int | |
4eb00163 | 829 | insn_dependent_p (x, y) |
a8393d5d RH |
830 | rtx x, y; |
831 | { | |
832 | rtx tmp; | |
833 | ||
834 | if (! INSN_P (x) || ! INSN_P (y)) | |
835 | abort (); | |
836 | ||
837 | tmp = PATTERN (y); | |
4eb00163 | 838 | note_stores (PATTERN (x), insn_dependent_p_1, &tmp); |
a8393d5d RH |
839 | if (tmp == NULL_RTX) |
840 | return 1; | |
841 | ||
842 | tmp = PATTERN (x); | |
4eb00163 | 843 | note_stores (PATTERN (y), insn_dependent_p_1, &tmp); |
a8393d5d RH |
844 | if (tmp == NULL_RTX) |
845 | return 1; | |
846 | ||
847 | return 0; | |
848 | } | |
849 | ||
4eb00163 | 850 | /* A helper routine for insn_dependent_p called through note_stores. */ |
a8393d5d RH |
851 | |
852 | static void | |
4eb00163 | 853 | insn_dependent_p_1 (x, pat, data) |
a8393d5d RH |
854 | rtx x; |
855 | rtx pat ATTRIBUTE_UNUSED; | |
856 | void *data; | |
857 | { | |
858 | rtx * pinsn = (rtx *) data; | |
859 | ||
860 | if (*pinsn && reg_mentioned_p (x, *pinsn)) | |
861 | *pinsn = NULL_RTX; | |
862 | } | |
2c88418c | 863 | \f |
91b2d119 JH |
864 | /* Helper function for set_of. */ |
865 | struct set_of_data | |
866 | { | |
867 | rtx found; | |
868 | rtx pat; | |
869 | }; | |
870 | ||
871 | static void | |
872 | set_of_1 (x, pat, data1) | |
873 | rtx x; | |
874 | rtx pat; | |
875 | void *data1; | |
876 | { | |
877 | struct set_of_data *data = (struct set_of_data *) (data1); | |
878 | if (rtx_equal_p (x, data->pat) | |
879 | || (GET_CODE (x) != MEM && reg_overlap_mentioned_p (data->pat, x))) | |
880 | data->found = pat; | |
881 | } | |
882 | ||
883 | /* Give an INSN, return a SET or CLOBBER expression that does modify PAT | |
884 | (eighter directly or via STRICT_LOW_PART and similar modifiers). */ | |
885 | rtx | |
886 | set_of (pat, insn) | |
887 | rtx pat, insn; | |
888 | { | |
889 | struct set_of_data data; | |
890 | data.found = NULL_RTX; | |
891 | data.pat = pat; | |
892 | note_stores (INSN_P (insn) ? PATTERN (insn) : insn, set_of_1, &data); | |
893 | return data.found; | |
894 | } | |
895 | \f | |
2c88418c RS |
896 | /* Given an INSN, return a SET expression if this insn has only a single SET. |
897 | It may also have CLOBBERs, USEs, or SET whose output | |
898 | will not be used, which we ignore. */ | |
899 | ||
900 | rtx | |
2130b7fb BS |
901 | single_set_2 (insn, pat) |
902 | rtx insn, pat; | |
2c88418c | 903 | { |
c9b89a21 JH |
904 | rtx set = NULL; |
905 | int set_verified = 1; | |
2c88418c | 906 | int i; |
c9b89a21 | 907 | |
b1cdafbb | 908 | if (GET_CODE (pat) == PARALLEL) |
2c88418c | 909 | { |
c9b89a21 | 910 | for (i = 0; i < XVECLEN (pat, 0); i++) |
b1cdafbb | 911 | { |
c9b89a21 JH |
912 | rtx sub = XVECEXP (pat, 0, i); |
913 | switch (GET_CODE (sub)) | |
914 | { | |
915 | case USE: | |
916 | case CLOBBER: | |
917 | break; | |
918 | ||
919 | case SET: | |
920 | /* We can consider insns having multiple sets, where all | |
921 | but one are dead as single set insns. In common case | |
922 | only single set is present in the pattern so we want | |
923 | to avoid checking for REG_UNUSED notes unless neccesary. | |
924 | ||
925 | When we reach set first time, we just expect this is | |
926 | the single set we are looking for and only when more | |
927 | sets are found in the insn, we check them. */ | |
928 | if (!set_verified) | |
929 | { | |
930 | if (find_reg_note (insn, REG_UNUSED, SET_DEST (set)) | |
931 | && !side_effects_p (set)) | |
932 | set = NULL; | |
933 | else | |
934 | set_verified = 1; | |
935 | } | |
936 | if (!set) | |
937 | set = sub, set_verified = 0; | |
938 | else if (!find_reg_note (insn, REG_UNUSED, SET_DEST (sub)) | |
939 | || side_effects_p (sub)) | |
940 | return NULL_RTX; | |
941 | break; | |
942 | ||
943 | default: | |
944 | return NULL_RTX; | |
945 | } | |
787ccee0 | 946 | } |
2c88418c | 947 | } |
c9b89a21 | 948 | return set; |
2c88418c | 949 | } |
941c63ac JL |
950 | |
951 | /* Given an INSN, return nonzero if it has more than one SET, else return | |
952 | zero. */ | |
953 | ||
5f7d3786 | 954 | int |
941c63ac JL |
955 | multiple_sets (insn) |
956 | rtx insn; | |
957 | { | |
cae8acdd | 958 | int found; |
941c63ac JL |
959 | int i; |
960 | ||
961 | /* INSN must be an insn. */ | |
2c3c49de | 962 | if (! INSN_P (insn)) |
941c63ac JL |
963 | return 0; |
964 | ||
965 | /* Only a PARALLEL can have multiple SETs. */ | |
966 | if (GET_CODE (PATTERN (insn)) == PARALLEL) | |
967 | { | |
968 | for (i = 0, found = 0; i < XVECLEN (PATTERN (insn), 0); i++) | |
969 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET) | |
970 | { | |
971 | /* If we have already found a SET, then return now. */ | |
972 | if (found) | |
973 | return 1; | |
974 | else | |
975 | found = 1; | |
976 | } | |
977 | } | |
978 | ||
979 | /* Either zero or one SET. */ | |
980 | return 0; | |
981 | } | |
2c88418c | 982 | \f |
63be01fb JW |
983 | /* Return the last thing that X was assigned from before *PINSN. If VALID_TO |
984 | is not NULL_RTX then verify that the object is not modified up to VALID_TO. | |
985 | If the object was modified, if we hit a partial assignment to X, or hit a | |
986 | CODE_LABEL first, return X. If we found an assignment, update *PINSN to | |
987 | point to it. ALLOW_HWREG is set to 1 if hardware registers are allowed to | |
988 | be the src. */ | |
2c88418c RS |
989 | |
990 | rtx | |
89d3d442 | 991 | find_last_value (x, pinsn, valid_to, allow_hwreg) |
2c88418c RS |
992 | rtx x; |
993 | rtx *pinsn; | |
994 | rtx valid_to; | |
89d3d442 | 995 | int allow_hwreg; |
2c88418c RS |
996 | { |
997 | rtx p; | |
998 | ||
999 | for (p = PREV_INSN (*pinsn); p && GET_CODE (p) != CODE_LABEL; | |
1000 | p = PREV_INSN (p)) | |
2c3c49de | 1001 | if (INSN_P (p)) |
2c88418c RS |
1002 | { |
1003 | rtx set = single_set (p); | |
c166a311 | 1004 | rtx note = find_reg_note (p, REG_EQUAL, NULL_RTX); |
2c88418c RS |
1005 | |
1006 | if (set && rtx_equal_p (x, SET_DEST (set))) | |
1007 | { | |
1008 | rtx src = SET_SRC (set); | |
1009 | ||
1010 | if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST) | |
1011 | src = XEXP (note, 0); | |
1012 | ||
63be01fb JW |
1013 | if ((valid_to == NULL_RTX |
1014 | || ! modified_between_p (src, PREV_INSN (p), valid_to)) | |
2c88418c RS |
1015 | /* Reject hard registers because we don't usually want |
1016 | to use them; we'd rather use a pseudo. */ | |
89d3d442 AM |
1017 | && (! (GET_CODE (src) == REG |
1018 | && REGNO (src) < FIRST_PSEUDO_REGISTER) || allow_hwreg)) | |
2c88418c RS |
1019 | { |
1020 | *pinsn = p; | |
1021 | return src; | |
1022 | } | |
1023 | } | |
1024 | ||
1025 | /* If set in non-simple way, we don't have a value. */ | |
1026 | if (reg_set_p (x, p)) | |
1027 | break; | |
1028 | } | |
1029 | ||
1030 | return x; | |
1031 | } | |
1032 | \f | |
1033 | /* Return nonzero if register in range [REGNO, ENDREGNO) | |
1034 | appears either explicitly or implicitly in X | |
1035 | other than being stored into. | |
1036 | ||
1037 | References contained within the substructure at LOC do not count. | |
1038 | LOC may be zero, meaning don't ignore anything. */ | |
1039 | ||
1040 | int | |
1041 | refers_to_regno_p (regno, endregno, x, loc) | |
770ae6cc | 1042 | unsigned int regno, endregno; |
2c88418c RS |
1043 | rtx x; |
1044 | rtx *loc; | |
1045 | { | |
770ae6cc RK |
1046 | int i; |
1047 | unsigned int x_regno; | |
1048 | RTX_CODE code; | |
1049 | const char *fmt; | |
2c88418c RS |
1050 | |
1051 | repeat: | |
1052 | /* The contents of a REG_NONNEG note is always zero, so we must come here | |
1053 | upon repeat in case the last REG_NOTE is a REG_NONNEG note. */ | |
1054 | if (x == 0) | |
1055 | return 0; | |
1056 | ||
1057 | code = GET_CODE (x); | |
1058 | ||
1059 | switch (code) | |
1060 | { | |
1061 | case REG: | |
770ae6cc | 1062 | x_regno = REGNO (x); |
f8163c92 RK |
1063 | |
1064 | /* If we modifying the stack, frame, or argument pointer, it will | |
1065 | clobber a virtual register. In fact, we could be more precise, | |
1066 | but it isn't worth it. */ | |
770ae6cc | 1067 | if ((x_regno == STACK_POINTER_REGNUM |
f8163c92 | 1068 | #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
770ae6cc | 1069 | || x_regno == ARG_POINTER_REGNUM |
f8163c92 | 1070 | #endif |
770ae6cc | 1071 | || x_regno == FRAME_POINTER_REGNUM) |
f8163c92 RK |
1072 | && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER) |
1073 | return 1; | |
1074 | ||
770ae6cc RK |
1075 | return (endregno > x_regno |
1076 | && regno < x_regno + (x_regno < FIRST_PSEUDO_REGISTER | |
1077 | ? HARD_REGNO_NREGS (x_regno, GET_MODE (x)) | |
2c88418c RS |
1078 | : 1)); |
1079 | ||
1080 | case SUBREG: | |
1081 | /* If this is a SUBREG of a hard reg, we can see exactly which | |
1082 | registers are being modified. Otherwise, handle normally. */ | |
1083 | if (GET_CODE (SUBREG_REG (x)) == REG | |
1084 | && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER) | |
1085 | { | |
ddef6bc7 | 1086 | unsigned int inner_regno = subreg_regno (x); |
770ae6cc | 1087 | unsigned int inner_endregno |
2c88418c RS |
1088 | = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER |
1089 | ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1); | |
1090 | ||
1091 | return endregno > inner_regno && regno < inner_endregno; | |
1092 | } | |
1093 | break; | |
1094 | ||
1095 | case CLOBBER: | |
1096 | case SET: | |
1097 | if (&SET_DEST (x) != loc | |
1098 | /* Note setting a SUBREG counts as referring to the REG it is in for | |
1099 | a pseudo but not for hard registers since we can | |
1100 | treat each word individually. */ | |
1101 | && ((GET_CODE (SET_DEST (x)) == SUBREG | |
1102 | && loc != &SUBREG_REG (SET_DEST (x)) | |
1103 | && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG | |
1104 | && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER | |
1105 | && refers_to_regno_p (regno, endregno, | |
1106 | SUBREG_REG (SET_DEST (x)), loc)) | |
1107 | || (GET_CODE (SET_DEST (x)) != REG | |
1108 | && refers_to_regno_p (regno, endregno, SET_DEST (x), loc)))) | |
1109 | return 1; | |
1110 | ||
1111 | if (code == CLOBBER || loc == &SET_SRC (x)) | |
1112 | return 0; | |
1113 | x = SET_SRC (x); | |
1114 | goto repeat; | |
e9a25f70 JL |
1115 | |
1116 | default: | |
1117 | break; | |
2c88418c RS |
1118 | } |
1119 | ||
1120 | /* X does not match, so try its subexpressions. */ | |
1121 | ||
1122 | fmt = GET_RTX_FORMAT (code); | |
1123 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
1124 | { | |
1125 | if (fmt[i] == 'e' && loc != &XEXP (x, i)) | |
1126 | { | |
1127 | if (i == 0) | |
1128 | { | |
1129 | x = XEXP (x, 0); | |
1130 | goto repeat; | |
1131 | } | |
1132 | else | |
1133 | if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc)) | |
1134 | return 1; | |
1135 | } | |
1136 | else if (fmt[i] == 'E') | |
1137 | { | |
1138 | register int j; | |
1139 | for (j = XVECLEN (x, i) - 1; j >=0; j--) | |
1140 | if (loc != &XVECEXP (x, i, j) | |
1141 | && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc)) | |
1142 | return 1; | |
1143 | } | |
1144 | } | |
1145 | return 0; | |
1146 | } | |
1147 | ||
1148 | /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG, | |
1149 | we check if any register number in X conflicts with the relevant register | |
1150 | numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN | |
1151 | contains a MEM (we don't bother checking for memory addresses that can't | |
1152 | conflict because we expect this to be a rare case. */ | |
1153 | ||
1154 | int | |
1155 | reg_overlap_mentioned_p (x, in) | |
1156 | rtx x, in; | |
1157 | { | |
770ae6cc | 1158 | unsigned int regno, endregno; |
2c88418c | 1159 | |
b98b49ac JL |
1160 | /* Overly conservative. */ |
1161 | if (GET_CODE (x) == STRICT_LOW_PART) | |
1162 | x = XEXP (x, 0); | |
1163 | ||
1164 | /* If either argument is a constant, then modifying X can not affect IN. */ | |
1165 | if (CONSTANT_P (x) || CONSTANT_P (in)) | |
1166 | return 0; | |
0c99ec5c RH |
1167 | |
1168 | switch (GET_CODE (x)) | |
2c88418c | 1169 | { |
0c99ec5c | 1170 | case SUBREG: |
2c88418c RS |
1171 | regno = REGNO (SUBREG_REG (x)); |
1172 | if (regno < FIRST_PSEUDO_REGISTER) | |
ddef6bc7 | 1173 | regno = subreg_regno (x); |
0c99ec5c | 1174 | goto do_reg; |
2c88418c | 1175 | |
0c99ec5c RH |
1176 | case REG: |
1177 | regno = REGNO (x); | |
1178 | do_reg: | |
1179 | endregno = regno + (regno < FIRST_PSEUDO_REGISTER | |
1180 | ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1); | |
1181 | return refers_to_regno_p (regno, endregno, in, NULL_PTR); | |
2c88418c | 1182 | |
0c99ec5c RH |
1183 | case MEM: |
1184 | { | |
1185 | const char *fmt; | |
1186 | int i; | |
2c88418c | 1187 | |
0c99ec5c | 1188 | if (GET_CODE (in) == MEM) |
2c88418c RS |
1189 | return 1; |
1190 | ||
0c99ec5c RH |
1191 | fmt = GET_RTX_FORMAT (GET_CODE (in)); |
1192 | for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--) | |
1193 | if (fmt[i] == 'e' && reg_overlap_mentioned_p (x, XEXP (in, i))) | |
1194 | return 1; | |
c0222c21 | 1195 | |
0c99ec5c RH |
1196 | return 0; |
1197 | } | |
1198 | ||
1199 | case SCRATCH: | |
1200 | case PC: | |
1201 | case CC0: | |
1202 | return reg_mentioned_p (x, in); | |
1203 | ||
1204 | case PARALLEL: | |
37ceff9d | 1205 | { |
90d036a0 | 1206 | int i; |
37ceff9d RH |
1207 | |
1208 | /* If any register in here refers to it we return true. */ | |
7193d1dc RK |
1209 | for (i = XVECLEN (x, 0) - 1; i >= 0; i--) |
1210 | if (XEXP (XVECEXP (x, 0, i), 0) != 0 | |
1211 | && reg_overlap_mentioned_p (XEXP (XVECEXP (x, 0, i), 0), in)) | |
90d036a0 | 1212 | return 1; |
7193d1dc | 1213 | return 0; |
37ceff9d | 1214 | } |
2c88418c | 1215 | |
0c99ec5c RH |
1216 | default: |
1217 | break; | |
1218 | } | |
2c88418c | 1219 | |
0c99ec5c | 1220 | abort (); |
2c88418c RS |
1221 | } |
1222 | \f | |
2c88418c RS |
1223 | /* Return the last value to which REG was set prior to INSN. If we can't |
1224 | find it easily, return 0. | |
1225 | ||
4d9d7d9d RK |
1226 | We only return a REG, SUBREG, or constant because it is too hard to |
1227 | check if a MEM remains unchanged. */ | |
2c88418c RS |
1228 | |
1229 | rtx | |
1230 | reg_set_last (x, insn) | |
1231 | rtx x; | |
1232 | rtx insn; | |
1233 | { | |
1234 | rtx orig_insn = insn; | |
1235 | ||
2c88418c RS |
1236 | /* Scan backwards until reg_set_last_1 changed one of the above flags. |
1237 | Stop when we reach a label or X is a hard reg and we reach a | |
1238 | CALL_INSN (if reg_set_last_last_regno is a hard reg). | |
1239 | ||
1240 | If we find a set of X, ensure that its SET_SRC remains unchanged. */ | |
1241 | ||
6b02c316 RS |
1242 | /* We compare with <= here, because reg_set_last_last_regno |
1243 | is actually the number of the first reg *not* in X. */ | |
2c88418c RS |
1244 | for (; |
1245 | insn && GET_CODE (insn) != CODE_LABEL | |
1246 | && ! (GET_CODE (insn) == CALL_INSN | |
91b2d119 | 1247 | && REGNO (x) <= FIRST_PSEUDO_REGISTER); |
2c88418c | 1248 | insn = PREV_INSN (insn)) |
2c3c49de | 1249 | if (INSN_P (insn)) |
2c88418c | 1250 | { |
91b2d119 JH |
1251 | rtx set = set_of (x, insn); |
1252 | /* OK, this function modify our register. See if we understand it. */ | |
1253 | if (set) | |
2c88418c | 1254 | { |
91b2d119 JH |
1255 | rtx last_value; |
1256 | if (GET_CODE (set) != SET || SET_DEST (set) != x) | |
1257 | return 0; | |
1258 | last_value = SET_SRC (x); | |
1259 | if (CONSTANT_P (last_value) | |
1260 | || ((GET_CODE (last_value) == REG | |
1261 | || GET_CODE (last_value) == SUBREG) | |
1262 | && ! reg_set_between_p (last_value, | |
ce9c8df2 | 1263 | insn, orig_insn))) |
91b2d119 | 1264 | return last_value; |
2c88418c RS |
1265 | else |
1266 | return 0; | |
1267 | } | |
1268 | } | |
1269 | ||
1270 | return 0; | |
1271 | } | |
1272 | \f | |
2c88418c RS |
1273 | /* Call FUN on each register or MEM that is stored into or clobbered by X. |
1274 | (X would be the pattern of an insn). | |
1275 | FUN receives two arguments: | |
1276 | the REG, MEM, CC0 or PC being stored in or clobbered, | |
1277 | the SET or CLOBBER rtx that does the store. | |
1278 | ||
1279 | If the item being stored in or clobbered is a SUBREG of a hard register, | |
1280 | the SUBREG will be passed. */ | |
1281 | ||
1282 | void | |
84832317 | 1283 | note_stores (x, fun, data) |
2c88418c | 1284 | register rtx x; |
cdadb1dd | 1285 | void (*fun) PARAMS ((rtx, rtx, void *)); |
84832317 | 1286 | void *data; |
2c88418c | 1287 | { |
90d036a0 RK |
1288 | int i; |
1289 | ||
0c99ec5c RH |
1290 | if (GET_CODE (x) == COND_EXEC) |
1291 | x = COND_EXEC_CODE (x); | |
90d036a0 | 1292 | |
0c99ec5c | 1293 | if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER) |
2c88418c RS |
1294 | { |
1295 | register rtx dest = SET_DEST (x); | |
90d036a0 | 1296 | |
2c88418c RS |
1297 | while ((GET_CODE (dest) == SUBREG |
1298 | && (GET_CODE (SUBREG_REG (dest)) != REG | |
1299 | || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER)) | |
1300 | || GET_CODE (dest) == ZERO_EXTRACT | |
1301 | || GET_CODE (dest) == SIGN_EXTRACT | |
1302 | || GET_CODE (dest) == STRICT_LOW_PART) | |
1303 | dest = XEXP (dest, 0); | |
86465af7 | 1304 | |
7193d1dc RK |
1305 | /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions, |
1306 | each of whose first operand is a register. We can't know what | |
1307 | precisely is being set in these cases, so make up a CLOBBER to pass | |
1308 | to the function. */ | |
1309 | if (GET_CODE (dest) == PARALLEL) | |
1310 | { | |
1311 | for (i = XVECLEN (dest, 0) - 1; i >= 0; i--) | |
1312 | if (XEXP (XVECEXP (dest, 0, i), 0) != 0) | |
1313 | (*fun) (XEXP (XVECEXP (dest, 0, i), 0), | |
1314 | gen_rtx_CLOBBER (VOIDmode, | |
1315 | XEXP (XVECEXP (dest, 0, i), 0)), | |
1316 | data); | |
1317 | } | |
86465af7 | 1318 | else |
84832317 | 1319 | (*fun) (dest, x, data); |
2c88418c | 1320 | } |
770ae6cc | 1321 | |
90d036a0 RK |
1322 | else if (GET_CODE (x) == PARALLEL) |
1323 | for (i = XVECLEN (x, 0) - 1; i >= 0; i--) | |
1324 | note_stores (XVECEXP (x, 0, i), fun, data); | |
2c88418c RS |
1325 | } |
1326 | \f | |
e2373f95 RK |
1327 | /* Like notes_stores, but call FUN for each expression that is being |
1328 | referenced in PBODY, a pointer to the PATTERN of an insn. We only call | |
1329 | FUN for each expression, not any interior subexpressions. FUN receives a | |
1330 | pointer to the expression and the DATA passed to this function. | |
1331 | ||
1332 | Note that this is not quite the same test as that done in reg_referenced_p | |
1333 | since that considers something as being referenced if it is being | |
1334 | partially set, while we do not. */ | |
1335 | ||
1336 | void | |
1337 | note_uses (pbody, fun, data) | |
1338 | rtx *pbody; | |
1339 | void (*fun) PARAMS ((rtx *, void *)); | |
1340 | void *data; | |
1341 | { | |
1342 | rtx body = *pbody; | |
1343 | int i; | |
1344 | ||
1345 | switch (GET_CODE (body)) | |
1346 | { | |
1347 | case COND_EXEC: | |
1348 | (*fun) (&COND_EXEC_TEST (body), data); | |
1349 | note_uses (&COND_EXEC_CODE (body), fun, data); | |
1350 | return; | |
1351 | ||
1352 | case PARALLEL: | |
1353 | for (i = XVECLEN (body, 0) - 1; i >= 0; i--) | |
1354 | note_uses (&XVECEXP (body, 0, i), fun, data); | |
1355 | return; | |
1356 | ||
1357 | case USE: | |
1358 | (*fun) (&XEXP (body, 0), data); | |
1359 | return; | |
1360 | ||
1361 | case ASM_OPERANDS: | |
1362 | for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--) | |
1363 | (*fun) (&ASM_OPERANDS_INPUT (body, i), data); | |
1364 | return; | |
1365 | ||
1366 | case TRAP_IF: | |
1367 | (*fun) (&TRAP_CONDITION (body), data); | |
1368 | return; | |
1369 | ||
1370 | case UNSPEC: | |
1371 | case UNSPEC_VOLATILE: | |
1372 | for (i = XVECLEN (body, 0) - 1; i >= 0; i--) | |
1373 | (*fun) (&XVECEXP (body, 0, i), data); | |
1374 | return; | |
1375 | ||
1376 | case CLOBBER: | |
1377 | if (GET_CODE (XEXP (body, 0)) == MEM) | |
1378 | (*fun) (&XEXP (XEXP (body, 0), 0), data); | |
1379 | return; | |
1380 | ||
1381 | case SET: | |
1382 | { | |
1383 | rtx dest = SET_DEST (body); | |
1384 | ||
1385 | /* For sets we replace everything in source plus registers in memory | |
1386 | expression in store and operands of a ZERO_EXTRACT. */ | |
1387 | (*fun) (&SET_SRC (body), data); | |
1388 | ||
1389 | if (GET_CODE (dest) == ZERO_EXTRACT) | |
1390 | { | |
1391 | (*fun) (&XEXP (dest, 1), data); | |
1392 | (*fun) (&XEXP (dest, 2), data); | |
1393 | } | |
1394 | ||
1395 | while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART) | |
1396 | dest = XEXP (dest, 0); | |
1397 | ||
1398 | if (GET_CODE (dest) == MEM) | |
1399 | (*fun) (&XEXP (dest, 0), data); | |
1400 | } | |
1401 | return; | |
1402 | ||
1403 | default: | |
1404 | /* All the other possibilities never store. */ | |
1405 | (*fun) (pbody, data); | |
1406 | return; | |
1407 | } | |
1408 | } | |
1409 | \f | |
2c88418c RS |
1410 | /* Return nonzero if X's old contents don't survive after INSN. |
1411 | This will be true if X is (cc0) or if X is a register and | |
1412 | X dies in INSN or because INSN entirely sets X. | |
1413 | ||
1414 | "Entirely set" means set directly and not through a SUBREG, | |
1415 | ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains. | |
1416 | Likewise, REG_INC does not count. | |
1417 | ||
1418 | REG may be a hard or pseudo reg. Renumbering is not taken into account, | |
1419 | but for this use that makes no difference, since regs don't overlap | |
1420 | during their lifetimes. Therefore, this function may be used | |
1421 | at any time after deaths have been computed (in flow.c). | |
1422 | ||
1423 | If REG is a hard reg that occupies multiple machine registers, this | |
1424 | function will only return 1 if each of those registers will be replaced | |
1425 | by INSN. */ | |
1426 | ||
1427 | int | |
1428 | dead_or_set_p (insn, x) | |
1429 | rtx insn; | |
1430 | rtx x; | |
1431 | { | |
770ae6cc RK |
1432 | unsigned int regno, last_regno; |
1433 | unsigned int i; | |
2c88418c RS |
1434 | |
1435 | /* Can't use cc0_rtx below since this file is used by genattrtab.c. */ | |
1436 | if (GET_CODE (x) == CC0) | |
1437 | return 1; | |
1438 | ||
1439 | if (GET_CODE (x) != REG) | |
1440 | abort (); | |
1441 | ||
1442 | regno = REGNO (x); | |
1443 | last_regno = (regno >= FIRST_PSEUDO_REGISTER ? regno | |
1444 | : regno + HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1); | |
1445 | ||
1446 | for (i = regno; i <= last_regno; i++) | |
1447 | if (! dead_or_set_regno_p (insn, i)) | |
1448 | return 0; | |
1449 | ||
1450 | return 1; | |
1451 | } | |
1452 | ||
1453 | /* Utility function for dead_or_set_p to check an individual register. Also | |
1454 | called from flow.c. */ | |
1455 | ||
1456 | int | |
1457 | dead_or_set_regno_p (insn, test_regno) | |
1458 | rtx insn; | |
770ae6cc | 1459 | unsigned int test_regno; |
2c88418c | 1460 | { |
770ae6cc | 1461 | unsigned int regno, endregno; |
8c8de5fc | 1462 | rtx pattern; |
2c88418c | 1463 | |
0a2287bf RH |
1464 | /* See if there is a death note for something that includes TEST_REGNO. */ |
1465 | if (find_regno_note (insn, REG_DEAD, test_regno)) | |
1466 | return 1; | |
2c88418c | 1467 | |
8f3e7a26 RK |
1468 | if (GET_CODE (insn) == CALL_INSN |
1469 | && find_regno_fusage (insn, CLOBBER, test_regno)) | |
1470 | return 1; | |
1471 | ||
0c99ec5c RH |
1472 | pattern = PATTERN (insn); |
1473 | ||
1474 | if (GET_CODE (pattern) == COND_EXEC) | |
1475 | pattern = COND_EXEC_CODE (pattern); | |
1476 | ||
1477 | if (GET_CODE (pattern) == SET) | |
2c88418c RS |
1478 | { |
1479 | rtx dest = SET_DEST (PATTERN (insn)); | |
1480 | ||
1481 | /* A value is totally replaced if it is the destination or the | |
1482 | destination is a SUBREG of REGNO that does not change the number of | |
1483 | words in it. */ | |
6764d250 | 1484 | if (GET_CODE (dest) == SUBREG |
2c88418c RS |
1485 | && (((GET_MODE_SIZE (GET_MODE (dest)) |
1486 | + UNITS_PER_WORD - 1) / UNITS_PER_WORD) | |
1487 | == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) | |
1488 | + UNITS_PER_WORD - 1) / UNITS_PER_WORD))) | |
1489 | dest = SUBREG_REG (dest); | |
1490 | ||
1491 | if (GET_CODE (dest) != REG) | |
1492 | return 0; | |
1493 | ||
1494 | regno = REGNO (dest); | |
1495 | endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1 | |
1496 | : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest))); | |
1497 | ||
1498 | return (test_regno >= regno && test_regno < endregno); | |
1499 | } | |
0c99ec5c | 1500 | else if (GET_CODE (pattern) == PARALLEL) |
2c88418c RS |
1501 | { |
1502 | register int i; | |
1503 | ||
0c99ec5c | 1504 | for (i = XVECLEN (pattern, 0) - 1; i >= 0; i--) |
2c88418c | 1505 | { |
0c99ec5c RH |
1506 | rtx body = XVECEXP (pattern, 0, i); |
1507 | ||
1508 | if (GET_CODE (body) == COND_EXEC) | |
1509 | body = COND_EXEC_CODE (body); | |
2c88418c RS |
1510 | |
1511 | if (GET_CODE (body) == SET || GET_CODE (body) == CLOBBER) | |
1512 | { | |
1513 | rtx dest = SET_DEST (body); | |
1514 | ||
1515 | if (GET_CODE (dest) == SUBREG | |
1516 | && (((GET_MODE_SIZE (GET_MODE (dest)) | |
1517 | + UNITS_PER_WORD - 1) / UNITS_PER_WORD) | |
1518 | == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) | |
1519 | + UNITS_PER_WORD - 1) / UNITS_PER_WORD))) | |
1520 | dest = SUBREG_REG (dest); | |
1521 | ||
1522 | if (GET_CODE (dest) != REG) | |
1523 | continue; | |
1524 | ||
1525 | regno = REGNO (dest); | |
1526 | endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1 | |
1527 | : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest))); | |
1528 | ||
1529 | if (test_regno >= regno && test_regno < endregno) | |
1530 | return 1; | |
1531 | } | |
1532 | } | |
1533 | } | |
1534 | ||
1535 | return 0; | |
1536 | } | |
1537 | ||
1538 | /* Return the reg-note of kind KIND in insn INSN, if there is one. | |
1539 | If DATUM is nonzero, look for one whose datum is DATUM. */ | |
1540 | ||
1541 | rtx | |
1542 | find_reg_note (insn, kind, datum) | |
1543 | rtx insn; | |
1544 | enum reg_note kind; | |
1545 | rtx datum; | |
1546 | { | |
1547 | register rtx link; | |
1548 | ||
ae78d276 | 1549 | /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */ |
2c3c49de | 1550 | if (! INSN_P (insn)) |
ae78d276 MM |
1551 | return 0; |
1552 | ||
2c88418c RS |
1553 | for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) |
1554 | if (REG_NOTE_KIND (link) == kind | |
1555 | && (datum == 0 || datum == XEXP (link, 0))) | |
1556 | return link; | |
1557 | return 0; | |
1558 | } | |
1559 | ||
1560 | /* Return the reg-note of kind KIND in insn INSN which applies to register | |
99309f3b RK |
1561 | number REGNO, if any. Return 0 if there is no such reg-note. Note that |
1562 | the REGNO of this NOTE need not be REGNO if REGNO is a hard register; | |
1563 | it might be the case that the note overlaps REGNO. */ | |
2c88418c RS |
1564 | |
1565 | rtx | |
1566 | find_regno_note (insn, kind, regno) | |
1567 | rtx insn; | |
1568 | enum reg_note kind; | |
770ae6cc | 1569 | unsigned int regno; |
2c88418c RS |
1570 | { |
1571 | register rtx link; | |
1572 | ||
ae78d276 | 1573 | /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */ |
2c3c49de | 1574 | if (! INSN_P (insn)) |
ae78d276 MM |
1575 | return 0; |
1576 | ||
2c88418c RS |
1577 | for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) |
1578 | if (REG_NOTE_KIND (link) == kind | |
1579 | /* Verify that it is a register, so that scratch and MEM won't cause a | |
1580 | problem here. */ | |
1581 | && GET_CODE (XEXP (link, 0)) == REG | |
99309f3b RK |
1582 | && REGNO (XEXP (link, 0)) <= regno |
1583 | && ((REGNO (XEXP (link, 0)) | |
1584 | + (REGNO (XEXP (link, 0)) >= FIRST_PSEUDO_REGISTER ? 1 | |
1585 | : HARD_REGNO_NREGS (REGNO (XEXP (link, 0)), | |
1586 | GET_MODE (XEXP (link, 0))))) | |
1587 | > regno)) | |
2c88418c RS |
1588 | return link; |
1589 | return 0; | |
1590 | } | |
8f3e7a26 | 1591 | |
d9c695ff RK |
1592 | /* Return a REG_EQUIV or REG_EQUAL note if insn has only a single set and |
1593 | has such a note. */ | |
1594 | ||
1595 | rtx | |
1596 | find_reg_equal_equiv_note (insn) | |
1597 | rtx insn; | |
1598 | { | |
1599 | rtx note; | |
1600 | ||
1601 | if (single_set (insn) == 0) | |
1602 | return 0; | |
1603 | else if ((note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != 0) | |
1604 | return note; | |
1605 | else | |
1606 | return find_reg_note (insn, REG_EQUAL, NULL_RTX); | |
1607 | } | |
1608 | ||
8f3e7a26 RK |
1609 | /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found |
1610 | in the CALL_INSN_FUNCTION_USAGE information of INSN. */ | |
1611 | ||
1612 | int | |
1613 | find_reg_fusage (insn, code, datum) | |
1614 | rtx insn; | |
1615 | enum rtx_code code; | |
1616 | rtx datum; | |
1617 | { | |
1618 | /* If it's not a CALL_INSN, it can't possibly have a | |
1619 | CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */ | |
1620 | if (GET_CODE (insn) != CALL_INSN) | |
1621 | return 0; | |
1622 | ||
1623 | if (! datum) | |
1624 | abort(); | |
1625 | ||
1626 | if (GET_CODE (datum) != REG) | |
1627 | { | |
1628 | register rtx link; | |
1629 | ||
1630 | for (link = CALL_INSN_FUNCTION_USAGE (insn); | |
1631 | link; | |
1632 | link = XEXP (link, 1)) | |
1633 | if (GET_CODE (XEXP (link, 0)) == code | |
1634 | && rtx_equal_p (datum, SET_DEST (XEXP (link, 0)))) | |
1635 | return 1; | |
1636 | } | |
1637 | else | |
1638 | { | |
770ae6cc | 1639 | unsigned int regno = REGNO (datum); |
8f3e7a26 RK |
1640 | |
1641 | /* CALL_INSN_FUNCTION_USAGE information cannot contain references | |
1642 | to pseudo registers, so don't bother checking. */ | |
1643 | ||
1644 | if (regno < FIRST_PSEUDO_REGISTER) | |
1645 | { | |
770ae6cc RK |
1646 | unsigned int end_regno |
1647 | = regno + HARD_REGNO_NREGS (regno, GET_MODE (datum)); | |
1648 | unsigned int i; | |
8f3e7a26 RK |
1649 | |
1650 | for (i = regno; i < end_regno; i++) | |
1651 | if (find_regno_fusage (insn, code, i)) | |
1652 | return 1; | |
1653 | } | |
1654 | } | |
1655 | ||
1656 | return 0; | |
1657 | } | |
1658 | ||
1659 | /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found | |
1660 | in the CALL_INSN_FUNCTION_USAGE information of INSN. */ | |
1661 | ||
1662 | int | |
1663 | find_regno_fusage (insn, code, regno) | |
1664 | rtx insn; | |
1665 | enum rtx_code code; | |
770ae6cc | 1666 | unsigned int regno; |
8f3e7a26 RK |
1667 | { |
1668 | register rtx link; | |
1669 | ||
1670 | /* CALL_INSN_FUNCTION_USAGE information cannot contain references | |
1671 | to pseudo registers, so don't bother checking. */ | |
1672 | ||
1673 | if (regno >= FIRST_PSEUDO_REGISTER | |
1674 | || GET_CODE (insn) != CALL_INSN ) | |
1675 | return 0; | |
1676 | ||
1677 | for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1)) | |
83ab3839 | 1678 | { |
770ae6cc RK |
1679 | unsigned int regnote; |
1680 | rtx op, reg; | |
83ab3839 RH |
1681 | |
1682 | if (GET_CODE (op = XEXP (link, 0)) == code | |
1683 | && GET_CODE (reg = XEXP (op, 0)) == REG | |
1684 | && (regnote = REGNO (reg)) <= regno | |
1685 | && regnote + HARD_REGNO_NREGS (regnote, GET_MODE (reg)) > regno) | |
1686 | return 1; | |
1687 | } | |
8f3e7a26 RK |
1688 | |
1689 | return 0; | |
1690 | } | |
2c88418c RS |
1691 | \f |
1692 | /* Remove register note NOTE from the REG_NOTES of INSN. */ | |
1693 | ||
1694 | void | |
1695 | remove_note (insn, note) | |
2c88418c | 1696 | register rtx insn; |
49c3bb12 | 1697 | register rtx note; |
2c88418c RS |
1698 | { |
1699 | register rtx link; | |
1700 | ||
49c3bb12 RH |
1701 | if (note == NULL_RTX) |
1702 | return; | |
1703 | ||
2c88418c RS |
1704 | if (REG_NOTES (insn) == note) |
1705 | { | |
1706 | REG_NOTES (insn) = XEXP (note, 1); | |
1707 | return; | |
1708 | } | |
1709 | ||
1710 | for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) | |
1711 | if (XEXP (link, 1) == note) | |
1712 | { | |
1713 | XEXP (link, 1) = XEXP (note, 1); | |
1714 | return; | |
1715 | } | |
1716 | ||
1717 | abort (); | |
1718 | } | |
55a98783 | 1719 | |
dd248abd RK |
1720 | /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and |
1721 | remove that entry from the list if it is found. | |
55a98783 | 1722 | |
dd248abd | 1723 | A simple equality test is used to determine if NODE matches. */ |
55a98783 JL |
1724 | |
1725 | void | |
1726 | remove_node_from_expr_list (node, listp) | |
1727 | rtx node; | |
1728 | rtx *listp; | |
1729 | { | |
1730 | rtx temp = *listp; | |
1731 | rtx prev = NULL_RTX; | |
1732 | ||
1733 | while (temp) | |
1734 | { | |
1735 | if (node == XEXP (temp, 0)) | |
1736 | { | |
1737 | /* Splice the node out of the list. */ | |
1738 | if (prev) | |
1739 | XEXP (prev, 1) = XEXP (temp, 1); | |
1740 | else | |
1741 | *listp = XEXP (temp, 1); | |
1742 | ||
1743 | return; | |
1744 | } | |
dd248abd RK |
1745 | |
1746 | prev = temp; | |
55a98783 JL |
1747 | temp = XEXP (temp, 1); |
1748 | } | |
1749 | } | |
2c88418c | 1750 | \f |
2b067faf RS |
1751 | /* Nonzero if X contains any volatile instructions. These are instructions |
1752 | which may cause unpredictable machine state instructions, and thus no | |
1753 | instructions should be moved or combined across them. This includes | |
1754 | only volatile asms and UNSPEC_VOLATILE instructions. */ | |
1755 | ||
1756 | int | |
1757 | volatile_insn_p (x) | |
1758 | rtx x; | |
1759 | { | |
1760 | register RTX_CODE code; | |
1761 | ||
1762 | code = GET_CODE (x); | |
1763 | switch (code) | |
1764 | { | |
1765 | case LABEL_REF: | |
1766 | case SYMBOL_REF: | |
1767 | case CONST_INT: | |
1768 | case CONST: | |
1769 | case CONST_DOUBLE: | |
1770 | case CC0: | |
1771 | case PC: | |
1772 | case REG: | |
1773 | case SCRATCH: | |
1774 | case CLOBBER: | |
1775 | case ASM_INPUT: | |
1776 | case ADDR_VEC: | |
1777 | case ADDR_DIFF_VEC: | |
1778 | case CALL: | |
1779 | case MEM: | |
1780 | return 0; | |
1781 | ||
1782 | case UNSPEC_VOLATILE: | |
1783 | /* case TRAP_IF: This isn't clear yet. */ | |
1784 | return 1; | |
1785 | ||
1786 | case ASM_OPERANDS: | |
1787 | if (MEM_VOLATILE_P (x)) | |
1788 | return 1; | |
e9a25f70 JL |
1789 | |
1790 | default: | |
1791 | break; | |
2b067faf RS |
1792 | } |
1793 | ||
1794 | /* Recursively scan the operands of this expression. */ | |
1795 | ||
1796 | { | |
6f7d635c | 1797 | register const char *fmt = GET_RTX_FORMAT (code); |
2b067faf RS |
1798 | register int i; |
1799 | ||
1800 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
1801 | { | |
1802 | if (fmt[i] == 'e') | |
1803 | { | |
31001f72 | 1804 | if (volatile_insn_p (XEXP (x, i))) |
2b067faf RS |
1805 | return 1; |
1806 | } | |
d4757e6a | 1807 | else if (fmt[i] == 'E') |
2b067faf RS |
1808 | { |
1809 | register int j; | |
1810 | for (j = 0; j < XVECLEN (x, i); j++) | |
31001f72 | 1811 | if (volatile_insn_p (XVECEXP (x, i, j))) |
2b067faf RS |
1812 | return 1; |
1813 | } | |
1814 | } | |
1815 | } | |
1816 | return 0; | |
1817 | } | |
1818 | ||
2c88418c | 1819 | /* Nonzero if X contains any volatile memory references |
2ac4fed0 | 1820 | UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */ |
2c88418c RS |
1821 | |
1822 | int | |
1823 | volatile_refs_p (x) | |
1824 | rtx x; | |
1825 | { | |
1826 | register RTX_CODE code; | |
1827 | ||
1828 | code = GET_CODE (x); | |
1829 | switch (code) | |
1830 | { | |
1831 | case LABEL_REF: | |
1832 | case SYMBOL_REF: | |
1833 | case CONST_INT: | |
1834 | case CONST: | |
1835 | case CONST_DOUBLE: | |
1836 | case CC0: | |
1837 | case PC: | |
1838 | case REG: | |
1839 | case SCRATCH: | |
1840 | case CLOBBER: | |
1841 | case ASM_INPUT: | |
1842 | case ADDR_VEC: | |
1843 | case ADDR_DIFF_VEC: | |
1844 | return 0; | |
1845 | ||
1846 | case CALL: | |
2ac4fed0 | 1847 | case UNSPEC_VOLATILE: |
2c88418c RS |
1848 | /* case TRAP_IF: This isn't clear yet. */ |
1849 | return 1; | |
1850 | ||
1851 | case MEM: | |
1852 | case ASM_OPERANDS: | |
1853 | if (MEM_VOLATILE_P (x)) | |
1854 | return 1; | |
e9a25f70 JL |
1855 | |
1856 | default: | |
1857 | break; | |
2c88418c RS |
1858 | } |
1859 | ||
1860 | /* Recursively scan the operands of this expression. */ | |
1861 | ||
1862 | { | |
6f7d635c | 1863 | register const char *fmt = GET_RTX_FORMAT (code); |
2c88418c RS |
1864 | register int i; |
1865 | ||
1866 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
1867 | { | |
1868 | if (fmt[i] == 'e') | |
1869 | { | |
1870 | if (volatile_refs_p (XEXP (x, i))) | |
1871 | return 1; | |
1872 | } | |
d4757e6a | 1873 | else if (fmt[i] == 'E') |
2c88418c RS |
1874 | { |
1875 | register int j; | |
1876 | for (j = 0; j < XVECLEN (x, i); j++) | |
1877 | if (volatile_refs_p (XVECEXP (x, i, j))) | |
1878 | return 1; | |
1879 | } | |
1880 | } | |
1881 | } | |
1882 | return 0; | |
1883 | } | |
1884 | ||
1885 | /* Similar to above, except that it also rejects register pre- and post- | |
1886 | incrementing. */ | |
1887 | ||
1888 | int | |
1889 | side_effects_p (x) | |
1890 | rtx x; | |
1891 | { | |
1892 | register RTX_CODE code; | |
1893 | ||
1894 | code = GET_CODE (x); | |
1895 | switch (code) | |
1896 | { | |
1897 | case LABEL_REF: | |
1898 | case SYMBOL_REF: | |
1899 | case CONST_INT: | |
1900 | case CONST: | |
1901 | case CONST_DOUBLE: | |
1902 | case CC0: | |
1903 | case PC: | |
1904 | case REG: | |
1905 | case SCRATCH: | |
1906 | case ASM_INPUT: | |
1907 | case ADDR_VEC: | |
1908 | case ADDR_DIFF_VEC: | |
1909 | return 0; | |
1910 | ||
1911 | case CLOBBER: | |
1912 | /* Reject CLOBBER with a non-VOID mode. These are made by combine.c | |
1913 | when some combination can't be done. If we see one, don't think | |
1914 | that we can simplify the expression. */ | |
1915 | return (GET_MODE (x) != VOIDmode); | |
1916 | ||
1917 | case PRE_INC: | |
1918 | case PRE_DEC: | |
1919 | case POST_INC: | |
1920 | case POST_DEC: | |
1fb9c5cd MH |
1921 | case PRE_MODIFY: |
1922 | case POST_MODIFY: | |
2c88418c | 1923 | case CALL: |
2ac4fed0 | 1924 | case UNSPEC_VOLATILE: |
2c88418c RS |
1925 | /* case TRAP_IF: This isn't clear yet. */ |
1926 | return 1; | |
1927 | ||
1928 | case MEM: | |
1929 | case ASM_OPERANDS: | |
1930 | if (MEM_VOLATILE_P (x)) | |
1931 | return 1; | |
e9a25f70 JL |
1932 | |
1933 | default: | |
1934 | break; | |
2c88418c RS |
1935 | } |
1936 | ||
1937 | /* Recursively scan the operands of this expression. */ | |
1938 | ||
1939 | { | |
6f7d635c | 1940 | register const char *fmt = GET_RTX_FORMAT (code); |
2c88418c RS |
1941 | register int i; |
1942 | ||
1943 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
1944 | { | |
1945 | if (fmt[i] == 'e') | |
1946 | { | |
1947 | if (side_effects_p (XEXP (x, i))) | |
1948 | return 1; | |
1949 | } | |
d4757e6a | 1950 | else if (fmt[i] == 'E') |
2c88418c RS |
1951 | { |
1952 | register int j; | |
1953 | for (j = 0; j < XVECLEN (x, i); j++) | |
1954 | if (side_effects_p (XVECEXP (x, i, j))) | |
1955 | return 1; | |
1956 | } | |
1957 | } | |
1958 | } | |
1959 | return 0; | |
1960 | } | |
1961 | \f | |
1962 | /* Return nonzero if evaluating rtx X might cause a trap. */ | |
1963 | ||
1964 | int | |
1965 | may_trap_p (x) | |
1966 | rtx x; | |
1967 | { | |
1968 | int i; | |
1969 | enum rtx_code code; | |
6f7d635c | 1970 | const char *fmt; |
2c88418c RS |
1971 | |
1972 | if (x == 0) | |
1973 | return 0; | |
1974 | code = GET_CODE (x); | |
1975 | switch (code) | |
1976 | { | |
1977 | /* Handle these cases quickly. */ | |
1978 | case CONST_INT: | |
1979 | case CONST_DOUBLE: | |
1980 | case SYMBOL_REF: | |
1981 | case LABEL_REF: | |
1982 | case CONST: | |
1983 | case PC: | |
1984 | case CC0: | |
1985 | case REG: | |
1986 | case SCRATCH: | |
1987 | return 0; | |
1988 | ||
22aa60a1 | 1989 | case ASM_INPUT: |
2ac4fed0 | 1990 | case UNSPEC_VOLATILE: |
2c88418c RS |
1991 | case TRAP_IF: |
1992 | return 1; | |
1993 | ||
22aa60a1 RH |
1994 | case ASM_OPERANDS: |
1995 | return MEM_VOLATILE_P (x); | |
1996 | ||
2c88418c RS |
1997 | /* Memory ref can trap unless it's a static var or a stack slot. */ |
1998 | case MEM: | |
1999 | return rtx_addr_can_trap_p (XEXP (x, 0)); | |
2000 | ||
2001 | /* Division by a non-constant might trap. */ | |
2002 | case DIV: | |
2003 | case MOD: | |
2004 | case UDIV: | |
2005 | case UMOD: | |
e9a25f70 JL |
2006 | if (! CONSTANT_P (XEXP (x, 1)) |
2007 | || GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) | |
2c88418c RS |
2008 | return 1; |
2009 | /* This was const0_rtx, but by not using that, | |
2010 | we can link this file into other programs. */ | |
2011 | if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0) | |
2012 | return 1; | |
e9a25f70 JL |
2013 | break; |
2014 | ||
b278301b RK |
2015 | case EXPR_LIST: |
2016 | /* An EXPR_LIST is used to represent a function call. This | |
2017 | certainly may trap. */ | |
2018 | return 1; | |
e9a25f70 | 2019 | |
734508ea JW |
2020 | case GE: |
2021 | case GT: | |
2022 | case LE: | |
2023 | case LT: | |
55143861 | 2024 | case COMPARE: |
734508ea JW |
2025 | /* Some floating point comparisons may trap. */ |
2026 | /* ??? There is no machine independent way to check for tests that trap | |
2027 | when COMPARE is used, though many targets do make this distinction. | |
2028 | For instance, sparc uses CCFPE for compares which generate exceptions | |
2029 | and CCFP for compares which do not generate exceptions. */ | |
55143861 JJ |
2030 | if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) |
2031 | return 1; | |
2032 | /* But often the compare has some CC mode, so check operand | |
2033 | modes as well. */ | |
2034 | if (GET_MODE_CLASS (GET_MODE (XEXP (x, 0))) == MODE_FLOAT | |
2035 | || GET_MODE_CLASS (GET_MODE (XEXP (x, 1))) == MODE_FLOAT) | |
2036 | return 1; | |
2037 | break; | |
2038 | ||
05cc23e8 RH |
2039 | case NEG: |
2040 | case ABS: | |
2041 | /* These operations don't trap even with floating point. */ | |
2042 | break; | |
2043 | ||
2c88418c RS |
2044 | default: |
2045 | /* Any floating arithmetic may trap. */ | |
2046 | if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) | |
2047 | return 1; | |
2048 | } | |
2049 | ||
2050 | fmt = GET_RTX_FORMAT (code); | |
2051 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
2052 | { | |
2053 | if (fmt[i] == 'e') | |
2054 | { | |
2055 | if (may_trap_p (XEXP (x, i))) | |
2056 | return 1; | |
2057 | } | |
2058 | else if (fmt[i] == 'E') | |
2059 | { | |
2060 | register int j; | |
2061 | for (j = 0; j < XVECLEN (x, i); j++) | |
2062 | if (may_trap_p (XVECEXP (x, i, j))) | |
2063 | return 1; | |
2064 | } | |
2065 | } | |
2066 | return 0; | |
2067 | } | |
2068 | \f | |
2069 | /* Return nonzero if X contains a comparison that is not either EQ or NE, | |
2070 | i.e., an inequality. */ | |
2071 | ||
2072 | int | |
2073 | inequality_comparisons_p (x) | |
2074 | rtx x; | |
2075 | { | |
6f7d635c | 2076 | register const char *fmt; |
2c88418c RS |
2077 | register int len, i; |
2078 | register enum rtx_code code = GET_CODE (x); | |
2079 | ||
2080 | switch (code) | |
2081 | { | |
2082 | case REG: | |
2083 | case SCRATCH: | |
2084 | case PC: | |
2085 | case CC0: | |
2086 | case CONST_INT: | |
2087 | case CONST_DOUBLE: | |
2088 | case CONST: | |
2089 | case LABEL_REF: | |
2090 | case SYMBOL_REF: | |
2091 | return 0; | |
2092 | ||
2093 | case LT: | |
2094 | case LTU: | |
2095 | case GT: | |
2096 | case GTU: | |
2097 | case LE: | |
2098 | case LEU: | |
2099 | case GE: | |
2100 | case GEU: | |
2101 | return 1; | |
e9a25f70 JL |
2102 | |
2103 | default: | |
2104 | break; | |
2c88418c RS |
2105 | } |
2106 | ||
2107 | len = GET_RTX_LENGTH (code); | |
2108 | fmt = GET_RTX_FORMAT (code); | |
2109 | ||
2110 | for (i = 0; i < len; i++) | |
2111 | { | |
2112 | if (fmt[i] == 'e') | |
2113 | { | |
2114 | if (inequality_comparisons_p (XEXP (x, i))) | |
2115 | return 1; | |
2116 | } | |
2117 | else if (fmt[i] == 'E') | |
2118 | { | |
2119 | register int j; | |
2120 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
2121 | if (inequality_comparisons_p (XVECEXP (x, i, j))) | |
2122 | return 1; | |
2123 | } | |
2124 | } | |
2125 | ||
2126 | return 0; | |
2127 | } | |
2128 | \f | |
1ed0205e VM |
2129 | /* Replace any occurrence of FROM in X with TO. The function does |
2130 | not enter into CONST_DOUBLE for the replace. | |
2c88418c RS |
2131 | |
2132 | Note that copying is not done so X must not be shared unless all copies | |
2133 | are to be modified. */ | |
2134 | ||
2135 | rtx | |
2136 | replace_rtx (x, from, to) | |
2137 | rtx x, from, to; | |
2138 | { | |
2139 | register int i, j; | |
6f7d635c | 2140 | register const char *fmt; |
2c88418c | 2141 | |
1ed0205e VM |
2142 | /* The following prevents loops occurrence when we change MEM in |
2143 | CONST_DOUBLE onto the same CONST_DOUBLE. */ | |
2144 | if (x != 0 && GET_CODE (x) == CONST_DOUBLE) | |
2145 | return x; | |
2146 | ||
2c88418c RS |
2147 | if (x == from) |
2148 | return to; | |
2149 | ||
2150 | /* Allow this function to make replacements in EXPR_LISTs. */ | |
2151 | if (x == 0) | |
2152 | return 0; | |
2153 | ||
2154 | fmt = GET_RTX_FORMAT (GET_CODE (x)); | |
2155 | for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) | |
2156 | { | |
2157 | if (fmt[i] == 'e') | |
2158 | XEXP (x, i) = replace_rtx (XEXP (x, i), from, to); | |
2159 | else if (fmt[i] == 'E') | |
2160 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
2161 | XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to); | |
2162 | } | |
2163 | ||
2164 | return x; | |
2165 | } | |
2166 | \f | |
2167 | /* Throughout the rtx X, replace many registers according to REG_MAP. | |
2168 | Return the replacement for X (which may be X with altered contents). | |
2169 | REG_MAP[R] is the replacement for register R, or 0 for don't replace. | |
2170 | NREGS is the length of REG_MAP; regs >= NREGS are not mapped. | |
2171 | ||
2172 | We only support REG_MAP entries of REG or SUBREG. Also, hard registers | |
2173 | should not be mapped to pseudos or vice versa since validate_change | |
2174 | is not called. | |
2175 | ||
2176 | If REPLACE_DEST is 1, replacements are also done in destinations; | |
2177 | otherwise, only sources are replaced. */ | |
2178 | ||
2179 | rtx | |
2180 | replace_regs (x, reg_map, nregs, replace_dest) | |
2181 | rtx x; | |
2182 | rtx *reg_map; | |
770ae6cc | 2183 | unsigned int nregs; |
2c88418c RS |
2184 | int replace_dest; |
2185 | { | |
2186 | register enum rtx_code code; | |
2187 | register int i; | |
6f7d635c | 2188 | register const char *fmt; |
2c88418c RS |
2189 | |
2190 | if (x == 0) | |
2191 | return x; | |
2192 | ||
2193 | code = GET_CODE (x); | |
2194 | switch (code) | |
2195 | { | |
2196 | case SCRATCH: | |
2197 | case PC: | |
2198 | case CC0: | |
2199 | case CONST_INT: | |
2200 | case CONST_DOUBLE: | |
2201 | case CONST: | |
2202 | case SYMBOL_REF: | |
2203 | case LABEL_REF: | |
2204 | return x; | |
2205 | ||
2206 | case REG: | |
2207 | /* Verify that the register has an entry before trying to access it. */ | |
2208 | if (REGNO (x) < nregs && reg_map[REGNO (x)] != 0) | |
3eb8f14c JW |
2209 | { |
2210 | /* SUBREGs can't be shared. Always return a copy to ensure that if | |
2211 | this replacement occurs more than once then each instance will | |
2212 | get distinct rtx. */ | |
2213 | if (GET_CODE (reg_map[REGNO (x)]) == SUBREG) | |
2214 | return copy_rtx (reg_map[REGNO (x)]); | |
2215 | return reg_map[REGNO (x)]; | |
2216 | } | |
2c88418c RS |
2217 | return x; |
2218 | ||
2219 | case SUBREG: | |
2220 | /* Prevent making nested SUBREGs. */ | |
2221 | if (GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) < nregs | |
2222 | && reg_map[REGNO (SUBREG_REG (x))] != 0 | |
2223 | && GET_CODE (reg_map[REGNO (SUBREG_REG (x))]) == SUBREG) | |
2224 | { | |
2225 | rtx map_val = reg_map[REGNO (SUBREG_REG (x))]; | |
2226 | rtx map_inner = SUBREG_REG (map_val); | |
2227 | ||
2228 | if (GET_MODE (x) == GET_MODE (map_inner)) | |
2229 | return map_inner; | |
2230 | else | |
2231 | { | |
ddef6bc7 JJ |
2232 | int final_offset = SUBREG_BYTE (x) + SUBREG_BYTE (map_val); |
2233 | ||
2234 | /* When working with REG SUBREGs the rule is that the byte | |
2235 | offset must be a multiple of the SUBREG's mode. */ | |
2236 | final_offset = (final_offset / GET_MODE_SIZE (GET_MODE (x))); | |
2237 | final_offset = (final_offset * GET_MODE_SIZE (GET_MODE (x))); | |
2238 | ||
2c88418c RS |
2239 | /* We cannot call gen_rtx here since we may be linked with |
2240 | genattrtab.c. */ | |
2241 | /* Let's try clobbering the incoming SUBREG and see | |
2242 | if this is really safe. */ | |
2243 | SUBREG_REG (x) = map_inner; | |
ddef6bc7 | 2244 | SUBREG_BYTE (x) = final_offset; |
2c88418c RS |
2245 | return x; |
2246 | #if 0 | |
2247 | rtx new = rtx_alloc (SUBREG); | |
ddef6bc7 JJ |
2248 | int final_offset = SUBREG_BYTE (x) + SUBREG_BYTE (map_val); |
2249 | ||
2250 | /* When working with REG SUBREGs the rule is that the byte | |
2251 | offset must be a multiple of the SUBREG's mode. */ | |
2252 | final_offset = (final_offset / GET_MODE_SIZE (GET_MODE (x))); | |
2253 | final_offset = (final_offset * GET_MODE_SIZE (GET_MODE (x))); | |
2254 | ||
2c88418c RS |
2255 | PUT_MODE (new, GET_MODE (x)); |
2256 | SUBREG_REG (new) = map_inner; | |
ddef6bc7 | 2257 | SUBREG_BYTE (new) = final_offset; |
2c88418c RS |
2258 | #endif |
2259 | } | |
2260 | } | |
2261 | break; | |
2262 | ||
2263 | case SET: | |
2264 | if (replace_dest) | |
2265 | SET_DEST (x) = replace_regs (SET_DEST (x), reg_map, nregs, 0); | |
2266 | ||
2267 | else if (GET_CODE (SET_DEST (x)) == MEM | |
2268 | || GET_CODE (SET_DEST (x)) == STRICT_LOW_PART) | |
2269 | /* Even if we are not to replace destinations, replace register if it | |
2270 | is CONTAINED in destination (destination is memory or | |
2271 | STRICT_LOW_PART). */ | |
2272 | XEXP (SET_DEST (x), 0) = replace_regs (XEXP (SET_DEST (x), 0), | |
2273 | reg_map, nregs, 0); | |
2274 | else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT) | |
2275 | /* Similarly, for ZERO_EXTRACT we replace all operands. */ | |
2276 | break; | |
2277 | ||
2278 | SET_SRC (x) = replace_regs (SET_SRC (x), reg_map, nregs, 0); | |
2279 | return x; | |
e9a25f70 JL |
2280 | |
2281 | default: | |
2282 | break; | |
2c88418c RS |
2283 | } |
2284 | ||
2285 | fmt = GET_RTX_FORMAT (code); | |
2286 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
2287 | { | |
2288 | if (fmt[i] == 'e') | |
2289 | XEXP (x, i) = replace_regs (XEXP (x, i), reg_map, nregs, replace_dest); | |
d4757e6a | 2290 | else if (fmt[i] == 'E') |
2c88418c RS |
2291 | { |
2292 | register int j; | |
2293 | for (j = 0; j < XVECLEN (x, i); j++) | |
2294 | XVECEXP (x, i, j) = replace_regs (XVECEXP (x, i, j), reg_map, | |
2295 | nregs, replace_dest); | |
2296 | } | |
2297 | } | |
2298 | return x; | |
2299 | } | |
2a1777af | 2300 | |
fce7e199 RH |
2301 | /* A subroutine of computed_jump_p, return 1 if X contains a REG or MEM or |
2302 | constant that is not in the constant pool and not in the condition | |
2303 | of an IF_THEN_ELSE. */ | |
2a1777af JL |
2304 | |
2305 | static int | |
fce7e199 | 2306 | computed_jump_p_1 (x) |
2a1777af JL |
2307 | rtx x; |
2308 | { | |
2309 | enum rtx_code code = GET_CODE (x); | |
2310 | int i, j; | |
6f7d635c | 2311 | const char *fmt; |
2a1777af JL |
2312 | |
2313 | switch (code) | |
2314 | { | |
2a1777af JL |
2315 | case LABEL_REF: |
2316 | case PC: | |
2317 | return 0; | |
2318 | ||
fce7e199 RH |
2319 | case CONST: |
2320 | case CONST_INT: | |
2321 | case CONST_DOUBLE: | |
2322 | case SYMBOL_REF: | |
2a1777af JL |
2323 | case REG: |
2324 | return 1; | |
2325 | ||
2326 | case MEM: | |
2327 | return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF | |
2328 | && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0))); | |
2329 | ||
2330 | case IF_THEN_ELSE: | |
fce7e199 RH |
2331 | return (computed_jump_p_1 (XEXP (x, 1)) |
2332 | || computed_jump_p_1 (XEXP (x, 2))); | |
1d300e19 KG |
2333 | |
2334 | default: | |
2335 | break; | |
2a1777af JL |
2336 | } |
2337 | ||
2338 | fmt = GET_RTX_FORMAT (code); | |
2339 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
2340 | { | |
2341 | if (fmt[i] == 'e' | |
fce7e199 | 2342 | && computed_jump_p_1 (XEXP (x, i))) |
2a1777af JL |
2343 | return 1; |
2344 | ||
d4757e6a | 2345 | else if (fmt[i] == 'E') |
2a1777af | 2346 | for (j = 0; j < XVECLEN (x, i); j++) |
fce7e199 | 2347 | if (computed_jump_p_1 (XVECEXP (x, i, j))) |
2a1777af JL |
2348 | return 1; |
2349 | } | |
2350 | ||
2351 | return 0; | |
2352 | } | |
2353 | ||
2354 | /* Return nonzero if INSN is an indirect jump (aka computed jump). | |
2355 | ||
2356 | Tablejumps and casesi insns are not considered indirect jumps; | |
4eb00163 | 2357 | we can recognize them by a (use (label_ref)). */ |
2a1777af JL |
2358 | |
2359 | int | |
2360 | computed_jump_p (insn) | |
2361 | rtx insn; | |
2362 | { | |
2363 | int i; | |
2364 | if (GET_CODE (insn) == JUMP_INSN) | |
2365 | { | |
2366 | rtx pat = PATTERN (insn); | |
2a1777af | 2367 | |
f759eb8b AO |
2368 | if (find_reg_note (insn, REG_LABEL, NULL_RTX)) |
2369 | return 0; | |
2370 | else if (GET_CODE (pat) == PARALLEL) | |
2a1777af JL |
2371 | { |
2372 | int len = XVECLEN (pat, 0); | |
2373 | int has_use_labelref = 0; | |
2374 | ||
2375 | for (i = len - 1; i >= 0; i--) | |
2376 | if (GET_CODE (XVECEXP (pat, 0, i)) == USE | |
2377 | && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0)) | |
2378 | == LABEL_REF)) | |
2379 | has_use_labelref = 1; | |
2380 | ||
2381 | if (! has_use_labelref) | |
2382 | for (i = len - 1; i >= 0; i--) | |
2383 | if (GET_CODE (XVECEXP (pat, 0, i)) == SET | |
2384 | && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx | |
fce7e199 | 2385 | && computed_jump_p_1 (SET_SRC (XVECEXP (pat, 0, i)))) |
2a1777af JL |
2386 | return 1; |
2387 | } | |
2388 | else if (GET_CODE (pat) == SET | |
2389 | && SET_DEST (pat) == pc_rtx | |
fce7e199 | 2390 | && computed_jump_p_1 (SET_SRC (pat))) |
2a1777af JL |
2391 | return 1; |
2392 | } | |
2393 | return 0; | |
2394 | } | |
ccc2d6d0 MM |
2395 | |
2396 | /* Traverse X via depth-first search, calling F for each | |
2397 | sub-expression (including X itself). F is also passed the DATA. | |
2398 | If F returns -1, do not traverse sub-expressions, but continue | |
2399 | traversing the rest of the tree. If F ever returns any other | |
2400 | non-zero value, stop the traversal, and return the value returned | |
2401 | by F. Otherwise, return 0. This function does not traverse inside | |
2402 | tree structure that contains RTX_EXPRs, or into sub-expressions | |
2403 | whose format code is `0' since it is not known whether or not those | |
2404 | codes are actually RTL. | |
2405 | ||
2406 | This routine is very general, and could (should?) be used to | |
2407 | implement many of the other routines in this file. */ | |
2408 | ||
ae0b51ef JL |
2409 | int |
2410 | for_each_rtx (x, f, data) | |
ef30399b | 2411 | rtx *x; |
ccc2d6d0 | 2412 | rtx_function f; |
ef30399b | 2413 | void *data; |
ccc2d6d0 MM |
2414 | { |
2415 | int result; | |
2416 | int length; | |
6f7d635c | 2417 | const char* format; |
ccc2d6d0 MM |
2418 | int i; |
2419 | ||
2420 | /* Call F on X. */ | |
2421 | result = (*f)(x, data); | |
2422 | if (result == -1) | |
2423 | /* Do not traverse sub-expressions. */ | |
2424 | return 0; | |
2425 | else if (result != 0) | |
2426 | /* Stop the traversal. */ | |
2427 | return result; | |
2428 | ||
2429 | if (*x == NULL_RTX) | |
2430 | /* There are no sub-expressions. */ | |
2431 | return 0; | |
2432 | ||
2433 | length = GET_RTX_LENGTH (GET_CODE (*x)); | |
2434 | format = GET_RTX_FORMAT (GET_CODE (*x)); | |
2435 | ||
2436 | for (i = 0; i < length; ++i) | |
2437 | { | |
2438 | switch (format[i]) | |
2439 | { | |
2440 | case 'e': | |
2441 | result = for_each_rtx (&XEXP (*x, i), f, data); | |
2442 | if (result != 0) | |
2443 | return result; | |
2444 | break; | |
2445 | ||
2446 | case 'V': | |
2447 | case 'E': | |
2448 | if (XVEC (*x, i) != 0) | |
2449 | { | |
2450 | int j; | |
2451 | for (j = 0; j < XVECLEN (*x, i); ++j) | |
2452 | { | |
2453 | result = for_each_rtx (&XVECEXP (*x, i, j), f, data); | |
2454 | if (result != 0) | |
2455 | return result; | |
2456 | } | |
2457 | } | |
2458 | break; | |
2459 | ||
2460 | default: | |
2461 | /* Nothing to do. */ | |
2462 | break; | |
2463 | } | |
2464 | ||
2465 | } | |
2466 | ||
2467 | return 0; | |
2468 | } | |
3ec2b590 | 2469 | |
777b1b71 RH |
2470 | /* Searches X for any reference to REGNO, returning the rtx of the |
2471 | reference found if any. Otherwise, returns NULL_RTX. */ | |
2472 | ||
2473 | rtx | |
2474 | regno_use_in (regno, x) | |
770ae6cc | 2475 | unsigned int regno; |
777b1b71 RH |
2476 | rtx x; |
2477 | { | |
6f7d635c | 2478 | register const char *fmt; |
777b1b71 RH |
2479 | int i, j; |
2480 | rtx tem; | |
2481 | ||
2482 | if (GET_CODE (x) == REG && REGNO (x) == regno) | |
2483 | return x; | |
2484 | ||
2485 | fmt = GET_RTX_FORMAT (GET_CODE (x)); | |
2486 | for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) | |
2487 | { | |
2488 | if (fmt[i] == 'e') | |
2489 | { | |
2490 | if ((tem = regno_use_in (regno, XEXP (x, i)))) | |
2491 | return tem; | |
2492 | } | |
2493 | else if (fmt[i] == 'E') | |
2494 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
2495 | if ((tem = regno_use_in (regno , XVECEXP (x, i, j)))) | |
2496 | return tem; | |
2497 | } | |
2498 | ||
2499 | return NULL_RTX; | |
2500 | } | |
2dfa9a87 MH |
2501 | |
2502 | ||
2503 | /* Return 1 if X is an autoincrement side effect and the register is | |
2504 | not the stack pointer. */ | |
2505 | int | |
2506 | auto_inc_p (x) | |
2507 | rtx x; | |
2508 | { | |
2509 | switch (GET_CODE (x)) | |
2510 | { | |
2511 | case PRE_INC: | |
2512 | case POST_INC: | |
2513 | case PRE_DEC: | |
2514 | case POST_DEC: | |
2515 | case PRE_MODIFY: | |
2516 | case POST_MODIFY: | |
2517 | /* There are no REG_INC notes for SP. */ | |
2518 | if (XEXP (x, 0) != stack_pointer_rtx) | |
2519 | return 1; | |
2520 | default: | |
2521 | break; | |
2522 | } | |
2523 | return 0; | |
2524 | } | |
3b10cf4b MM |
2525 | |
2526 | /* Return 1 if the sequence of instructions beginning with FROM and up | |
2527 | to and including TO is safe to move. If NEW_TO is non-NULL, and | |
2528 | the sequence is not already safe to move, but can be easily | |
2529 | extended to a sequence which is safe, then NEW_TO will point to the | |
7015a814 MM |
2530 | end of the extended sequence. |
2531 | ||
2532 | For now, this function only checks that the region contains whole | |
5bea1ccf | 2533 | exception regions, but it could be extended to check additional |
7015a814 | 2534 | conditions as well. */ |
3b10cf4b MM |
2535 | |
2536 | int | |
2537 | insns_safe_to_move_p (from, to, new_to) | |
2538 | rtx from; | |
2539 | rtx to; | |
2540 | rtx *new_to; | |
2541 | { | |
2542 | int eh_region_count = 0; | |
2543 | int past_to_p = 0; | |
2544 | rtx r = from; | |
2545 | ||
7015a814 MM |
2546 | /* By default, assume the end of the region will be what was |
2547 | suggested. */ | |
2548 | if (new_to) | |
2549 | *new_to = to; | |
2550 | ||
3b10cf4b MM |
2551 | while (r) |
2552 | { | |
2553 | if (GET_CODE (r) == NOTE) | |
2554 | { | |
2555 | switch (NOTE_LINE_NUMBER (r)) | |
2556 | { | |
2557 | case NOTE_INSN_EH_REGION_BEG: | |
2558 | ++eh_region_count; | |
2559 | break; | |
2560 | ||
2561 | case NOTE_INSN_EH_REGION_END: | |
2562 | if (eh_region_count == 0) | |
2563 | /* This sequence of instructions contains the end of | |
2564 | an exception region, but not he beginning. Moving | |
2565 | it will cause chaos. */ | |
2566 | return 0; | |
2567 | ||
2568 | --eh_region_count; | |
2569 | break; | |
2570 | ||
2571 | default: | |
2572 | break; | |
2573 | } | |
2574 | } | |
2575 | else if (past_to_p) | |
2576 | /* If we've passed TO, and we see a non-note instruction, we | |
2577 | can't extend the sequence to a movable sequence. */ | |
2578 | return 0; | |
2579 | ||
2580 | if (r == to) | |
2581 | { | |
2582 | if (!new_to) | |
2583 | /* It's OK to move the sequence if there were matched sets of | |
2584 | exception region notes. */ | |
2585 | return eh_region_count == 0; | |
2586 | ||
2587 | past_to_p = 1; | |
2588 | } | |
2589 | ||
2590 | /* It's OK to move the sequence if there were matched sets of | |
2591 | exception region notes. */ | |
2592 | if (past_to_p && eh_region_count == 0) | |
2593 | { | |
2594 | *new_to = r; | |
2595 | return 1; | |
2596 | } | |
2597 | ||
2598 | /* Go to the next instruction. */ | |
2599 | r = NEXT_INSN (r); | |
2600 | } | |
2601 | ||
2602 | return 0; | |
2603 | } | |
db7ba742 R |
2604 | |
2605 | /* Return non-zero if IN contains a piece of rtl that has the address LOC */ | |
2606 | int | |
2607 | loc_mentioned_in_p (loc, in) | |
2608 | rtx *loc, in; | |
2609 | { | |
2610 | enum rtx_code code = GET_CODE (in); | |
2611 | const char *fmt = GET_RTX_FORMAT (code); | |
2612 | int i, j; | |
2613 | ||
2614 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
2615 | { | |
2616 | if (loc == &in->fld[i].rtx) | |
2617 | return 1; | |
2618 | if (fmt[i] == 'e') | |
2619 | { | |
2620 | if (loc_mentioned_in_p (loc, XEXP (in, i))) | |
2621 | return 1; | |
2622 | } | |
2623 | else if (fmt[i] == 'E') | |
2624 | for (j = XVECLEN (in, i) - 1; j >= 0; j--) | |
2625 | if (loc_mentioned_in_p (loc, XVECEXP (in, i, j))) | |
2626 | return 1; | |
2627 | } | |
2628 | return 0; | |
2629 | } | |
ddef6bc7 JJ |
2630 | |
2631 | /* This function returns the regno offset of a subreg expression. | |
2632 | xregno - A regno of an inner hard subreg_reg (or what will become one). | |
2633 | xmode - The mode of xregno. | |
2634 | offset - The byte offset. | |
2635 | ymode - The mode of a top level SUBREG (or what may become one). | |
2636 | RETURN - The regno offset which would be used. | |
2637 | This function can be overridden by defining SUBREG_REGNO_OFFSET, | |
2638 | taking the same parameters. */ | |
2639 | unsigned int | |
2640 | subreg_regno_offset (xregno, xmode, offset, ymode) | |
2641 | unsigned int xregno; | |
2642 | enum machine_mode xmode; | |
2643 | unsigned int offset; | |
2644 | enum machine_mode ymode; | |
2645 | { | |
2646 | unsigned ret; | |
2647 | int nregs_xmode, nregs_ymode; | |
2648 | int mode_multiple, nregs_multiple; | |
2649 | int y_offset; | |
2650 | ||
2651 | /* Check for an override, and use it instead. */ | |
2652 | #ifdef SUBREG_REGNO_OFFSET | |
2653 | ret = SUBREG_REGNO_OFFSET (xregno, xmode, offset, ymode) | |
2654 | #else | |
2655 | if (xregno >= FIRST_PSEUDO_REGISTER) | |
2656 | abort (); | |
2657 | ||
2658 | nregs_xmode = HARD_REGNO_NREGS (xregno, xmode); | |
2659 | nregs_ymode = HARD_REGNO_NREGS (xregno, ymode); | |
2660 | if (offset == 0 || nregs_xmode == nregs_ymode) | |
2661 | return 0; | |
2662 | ||
2663 | /* size of ymode must not be greater than the size of xmode. */ | |
2664 | mode_multiple = GET_MODE_SIZE (xmode) / GET_MODE_SIZE (ymode); | |
2665 | if (mode_multiple == 0) | |
2666 | abort (); | |
2667 | ||
2668 | y_offset = offset / GET_MODE_SIZE (ymode); | |
2669 | nregs_multiple = nregs_xmode / nregs_ymode; | |
2670 | ret = (y_offset / (mode_multiple / nregs_multiple)) * nregs_ymode; | |
2671 | #endif | |
2672 | ||
2673 | return ret; | |
2674 | } | |
2675 | ||
2676 | /* Return the final regno that a subreg expression refers to. */ | |
2677 | unsigned int | |
2678 | subreg_regno (x) | |
2679 | rtx x; | |
2680 | { | |
2681 | unsigned int ret; | |
2682 | rtx subreg = SUBREG_REG (x); | |
2683 | int regno = REGNO (subreg); | |
2684 | ||
2685 | ret = regno + subreg_regno_offset (regno, | |
2686 | GET_MODE (subreg), | |
2687 | SUBREG_BYTE (x), | |
2688 | GET_MODE (x)); | |
2689 | return ret; | |
2690 | ||
2691 | } |