1 | /* Analyze RTL for C-Compiler |
---|
2 | Copyright (C) 1987, 88, 92-97, 1998 Free Software Foundation, Inc. |
---|
3 | |
---|
4 | This file is part of GNU CC. |
---|
5 | |
---|
6 | GNU CC is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | GNU CC is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with GNU CC; see the file COPYING. If not, write to |
---|
18 | the Free Software Foundation, 59 Temple Place - Suite 330, |
---|
19 | Boston, MA 02111-1307, USA. */ |
---|
20 | |
---|
21 | |
---|
22 | #include "config.h" |
---|
23 | #include <stdio.h> |
---|
24 | #include "rtl.h" |
---|
25 | |
---|
26 | static int rtx_addr_can_trap_p PROTO((rtx)); |
---|
27 | |
---|
28 | |
---|
29 | /* Forward declarations */ |
---|
30 | static int jmp_uses_reg_or_mem PROTO((rtx)); |
---|
31 | |
---|
32 | /* Bit flags that specify the machine subtype we are compiling for. |
---|
33 | Bits are tested using macros TARGET_... defined in the tm.h file |
---|
34 | and set by `-m...' switches. Must be defined in rtlanal.c. */ |
---|
35 | |
---|
36 | int target_flags; |
---|
37 | |
---|
38 | /* Return 1 if the value of X is unstable |
---|
39 | (would be different at a different point in the program). |
---|
40 | The frame pointer, arg pointer, etc. are considered stable |
---|
41 | (within one function) and so is anything marked `unchanging'. */ |
---|
42 | |
---|
43 | int |
---|
44 | rtx_unstable_p (x) |
---|
45 | rtx x; |
---|
46 | { |
---|
47 | register RTX_CODE code = GET_CODE (x); |
---|
48 | register int i; |
---|
49 | register char *fmt; |
---|
50 | |
---|
51 | if (code == MEM) |
---|
52 | return ! RTX_UNCHANGING_P (x); |
---|
53 | |
---|
54 | if (code == QUEUED) |
---|
55 | return 1; |
---|
56 | |
---|
57 | if (code == CONST || code == CONST_INT) |
---|
58 | return 0; |
---|
59 | |
---|
60 | if (code == REG) |
---|
61 | return ! (REGNO (x) == FRAME_POINTER_REGNUM |
---|
62 | || REGNO (x) == HARD_FRAME_POINTER_REGNUM |
---|
63 | || REGNO (x) == ARG_POINTER_REGNUM |
---|
64 | || RTX_UNCHANGING_P (x)); |
---|
65 | |
---|
66 | fmt = GET_RTX_FORMAT (code); |
---|
67 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
68 | if (fmt[i] == 'e') |
---|
69 | if (rtx_unstable_p (XEXP (x, i))) |
---|
70 | return 1; |
---|
71 | return 0; |
---|
72 | } |
---|
73 | |
---|
74 | /* Return 1 if X has a value that can vary even between two |
---|
75 | executions of the program. 0 means X can be compared reliably |
---|
76 | against certain constants or near-constants. |
---|
77 | The frame pointer and the arg pointer are considered constant. */ |
---|
78 | |
---|
79 | int |
---|
80 | rtx_varies_p (x) |
---|
81 | rtx x; |
---|
82 | { |
---|
83 | register RTX_CODE code = GET_CODE (x); |
---|
84 | register int i; |
---|
85 | register char *fmt; |
---|
86 | |
---|
87 | switch (code) |
---|
88 | { |
---|
89 | case MEM: |
---|
90 | case QUEUED: |
---|
91 | return 1; |
---|
92 | |
---|
93 | case CONST: |
---|
94 | case CONST_INT: |
---|
95 | case CONST_DOUBLE: |
---|
96 | case SYMBOL_REF: |
---|
97 | case LABEL_REF: |
---|
98 | return 0; |
---|
99 | |
---|
100 | case REG: |
---|
101 | /* Note that we have to test for the actual rtx used for the frame |
---|
102 | and arg pointers and not just the register number in case we have |
---|
103 | eliminated the frame and/or arg pointer and are using it |
---|
104 | for pseudos. */ |
---|
105 | return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx |
---|
106 | || x == arg_pointer_rtx || x == pic_offset_table_rtx); |
---|
107 | |
---|
108 | case LO_SUM: |
---|
109 | /* The operand 0 of a LO_SUM is considered constant |
---|
110 | (in fact is it related specifically to operand 1). */ |
---|
111 | return rtx_varies_p (XEXP (x, 1)); |
---|
112 | |
---|
113 | default: |
---|
114 | break; |
---|
115 | } |
---|
116 | |
---|
117 | fmt = GET_RTX_FORMAT (code); |
---|
118 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
119 | if (fmt[i] == 'e') |
---|
120 | if (rtx_varies_p (XEXP (x, i))) |
---|
121 | return 1; |
---|
122 | return 0; |
---|
123 | } |
---|
124 | |
---|
125 | /* Return 0 if the use of X as an address in a MEM can cause a trap. */ |
---|
126 | |
---|
127 | static int |
---|
128 | rtx_addr_can_trap_p (x) |
---|
129 | register rtx x; |
---|
130 | { |
---|
131 | register enum rtx_code code = GET_CODE (x); |
---|
132 | |
---|
133 | switch (code) |
---|
134 | { |
---|
135 | case SYMBOL_REF: |
---|
136 | case LABEL_REF: |
---|
137 | /* SYMBOL_REF is problematic due to the possible presence of |
---|
138 | a #pragma weak, but to say that loads from symbols can trap is |
---|
139 | *very* costly. It's not at all clear what's best here. For |
---|
140 | now, we ignore the impact of #pragma weak. */ |
---|
141 | return 0; |
---|
142 | |
---|
143 | case REG: |
---|
144 | /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */ |
---|
145 | return ! (x == frame_pointer_rtx || x == hard_frame_pointer_rtx |
---|
146 | || x == stack_pointer_rtx || x == arg_pointer_rtx); |
---|
147 | |
---|
148 | case CONST: |
---|
149 | return rtx_addr_can_trap_p (XEXP (x, 0)); |
---|
150 | |
---|
151 | case PLUS: |
---|
152 | /* An address is assumed not to trap if it is an address that can't |
---|
153 | trap plus a constant integer. */ |
---|
154 | return (rtx_addr_can_trap_p (XEXP (x, 0)) |
---|
155 | || GET_CODE (XEXP (x, 1)) != CONST_INT); |
---|
156 | |
---|
157 | case LO_SUM: |
---|
158 | return rtx_addr_can_trap_p (XEXP (x, 1)); |
---|
159 | |
---|
160 | default: |
---|
161 | break; |
---|
162 | } |
---|
163 | |
---|
164 | /* If it isn't one of the case above, it can cause a trap. */ |
---|
165 | return 1; |
---|
166 | } |
---|
167 | |
---|
168 | /* Return 1 if X refers to a memory location whose address |
---|
169 | cannot be compared reliably with constant addresses, |
---|
170 | or if X refers to a BLKmode memory object. */ |
---|
171 | |
---|
172 | int |
---|
173 | rtx_addr_varies_p (x) |
---|
174 | rtx x; |
---|
175 | { |
---|
176 | register enum rtx_code code; |
---|
177 | register int i; |
---|
178 | register char *fmt; |
---|
179 | |
---|
180 | if (x == 0) |
---|
181 | return 0; |
---|
182 | |
---|
183 | code = GET_CODE (x); |
---|
184 | if (code == MEM) |
---|
185 | return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0)); |
---|
186 | |
---|
187 | fmt = GET_RTX_FORMAT (code); |
---|
188 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
189 | if (fmt[i] == 'e') |
---|
190 | { |
---|
191 | if (rtx_addr_varies_p (XEXP (x, i))) |
---|
192 | return 1; |
---|
193 | } |
---|
194 | else if (fmt[i] == 'E') |
---|
195 | { |
---|
196 | int j; |
---|
197 | for (j = 0; j < XVECLEN (x, i); j++) |
---|
198 | if (rtx_addr_varies_p (XVECEXP (x, i, j))) |
---|
199 | return 1; |
---|
200 | } |
---|
201 | return 0; |
---|
202 | } |
---|
203 | |
---|
204 | /* Return the value of the integer term in X, if one is apparent; |
---|
205 | otherwise return 0. |
---|
206 | Only obvious integer terms are detected. |
---|
207 | This is used in cse.c with the `related_value' field.*/ |
---|
208 | |
---|
209 | HOST_WIDE_INT |
---|
210 | get_integer_term (x) |
---|
211 | rtx x; |
---|
212 | { |
---|
213 | if (GET_CODE (x) == CONST) |
---|
214 | x = XEXP (x, 0); |
---|
215 | |
---|
216 | if (GET_CODE (x) == MINUS |
---|
217 | && GET_CODE (XEXP (x, 1)) == CONST_INT) |
---|
218 | return - INTVAL (XEXP (x, 1)); |
---|
219 | if (GET_CODE (x) == PLUS |
---|
220 | && GET_CODE (XEXP (x, 1)) == CONST_INT) |
---|
221 | return INTVAL (XEXP (x, 1)); |
---|
222 | return 0; |
---|
223 | } |
---|
224 | |
---|
225 | /* If X is a constant, return the value sans apparent integer term; |
---|
226 | otherwise return 0. |
---|
227 | Only obvious integer terms are detected. */ |
---|
228 | |
---|
229 | rtx |
---|
230 | get_related_value (x) |
---|
231 | rtx x; |
---|
232 | { |
---|
233 | if (GET_CODE (x) != CONST) |
---|
234 | return 0; |
---|
235 | x = XEXP (x, 0); |
---|
236 | if (GET_CODE (x) == PLUS |
---|
237 | && GET_CODE (XEXP (x, 1)) == CONST_INT) |
---|
238 | return XEXP (x, 0); |
---|
239 | else if (GET_CODE (x) == MINUS |
---|
240 | && GET_CODE (XEXP (x, 1)) == CONST_INT) |
---|
241 | return XEXP (x, 0); |
---|
242 | return 0; |
---|
243 | } |
---|
244 | |
---|
245 | /* Nonzero if register REG appears somewhere within IN. |
---|
246 | Also works if REG is not a register; in this case it checks |
---|
247 | for a subexpression of IN that is Lisp "equal" to REG. */ |
---|
248 | |
---|
249 | int |
---|
250 | reg_mentioned_p (reg, in) |
---|
251 | register rtx reg, in; |
---|
252 | { |
---|
253 | register char *fmt; |
---|
254 | register int i; |
---|
255 | register enum rtx_code code; |
---|
256 | |
---|
257 | if (in == 0) |
---|
258 | return 0; |
---|
259 | |
---|
260 | if (reg == in) |
---|
261 | return 1; |
---|
262 | |
---|
263 | if (GET_CODE (in) == LABEL_REF) |
---|
264 | return reg == XEXP (in, 0); |
---|
265 | |
---|
266 | code = GET_CODE (in); |
---|
267 | |
---|
268 | switch (code) |
---|
269 | { |
---|
270 | /* Compare registers by number. */ |
---|
271 | case REG: |
---|
272 | return GET_CODE (reg) == REG && REGNO (in) == REGNO (reg); |
---|
273 | |
---|
274 | /* These codes have no constituent expressions |
---|
275 | and are unique. */ |
---|
276 | case SCRATCH: |
---|
277 | case CC0: |
---|
278 | case PC: |
---|
279 | return 0; |
---|
280 | |
---|
281 | case CONST_INT: |
---|
282 | return GET_CODE (reg) == CONST_INT && INTVAL (in) == INTVAL (reg); |
---|
283 | |
---|
284 | case CONST_DOUBLE: |
---|
285 | /* These are kept unique for a given value. */ |
---|
286 | return 0; |
---|
287 | |
---|
288 | default: |
---|
289 | break; |
---|
290 | } |
---|
291 | |
---|
292 | if (GET_CODE (reg) == code && rtx_equal_p (reg, in)) |
---|
293 | return 1; |
---|
294 | |
---|
295 | fmt = GET_RTX_FORMAT (code); |
---|
296 | |
---|
297 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
298 | { |
---|
299 | if (fmt[i] == 'E') |
---|
300 | { |
---|
301 | register int j; |
---|
302 | for (j = XVECLEN (in, i) - 1; j >= 0; j--) |
---|
303 | if (reg_mentioned_p (reg, XVECEXP (in, i, j))) |
---|
304 | return 1; |
---|
305 | } |
---|
306 | else if (fmt[i] == 'e' |
---|
307 | && reg_mentioned_p (reg, XEXP (in, i))) |
---|
308 | return 1; |
---|
309 | } |
---|
310 | return 0; |
---|
311 | } |
---|
312 | |
---|
313 | /* Return 1 if in between BEG and END, exclusive of BEG and END, there is |
---|
314 | no CODE_LABEL insn. */ |
---|
315 | |
---|
316 | int |
---|
317 | no_labels_between_p (beg, end) |
---|
318 | rtx beg, end; |
---|
319 | { |
---|
320 | register rtx p; |
---|
321 | for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p)) |
---|
322 | if (GET_CODE (p) == CODE_LABEL) |
---|
323 | return 0; |
---|
324 | return 1; |
---|
325 | } |
---|
326 | |
---|
327 | /* Nonzero if register REG is used in an insn between |
---|
328 | FROM_INSN and TO_INSN (exclusive of those two). */ |
---|
329 | |
---|
330 | int |
---|
331 | reg_used_between_p (reg, from_insn, to_insn) |
---|
332 | rtx reg, from_insn, to_insn; |
---|
333 | { |
---|
334 | register rtx insn; |
---|
335 | |
---|
336 | if (from_insn == to_insn) |
---|
337 | return 0; |
---|
338 | |
---|
339 | for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn)) |
---|
340 | if (GET_RTX_CLASS (GET_CODE (insn)) == 'i' |
---|
341 | && (reg_overlap_mentioned_p (reg, PATTERN (insn)) |
---|
342 | || (GET_CODE (insn) == CALL_INSN |
---|
343 | && (find_reg_fusage (insn, USE, reg) |
---|
344 | || find_reg_fusage (insn, CLOBBER, reg))))) |
---|
345 | return 1; |
---|
346 | return 0; |
---|
347 | } |
---|
348 | |
---|
349 | /* Nonzero if the old value of X, a register, is referenced in BODY. If X |
---|
350 | is entirely replaced by a new value and the only use is as a SET_DEST, |
---|
351 | we do not consider it a reference. */ |
---|
352 | |
---|
353 | int |
---|
354 | reg_referenced_p (x, body) |
---|
355 | rtx x; |
---|
356 | rtx body; |
---|
357 | { |
---|
358 | int i; |
---|
359 | |
---|
360 | switch (GET_CODE (body)) |
---|
361 | { |
---|
362 | case SET: |
---|
363 | if (reg_overlap_mentioned_p (x, SET_SRC (body))) |
---|
364 | return 1; |
---|
365 | |
---|
366 | /* If the destination is anything other than CC0, PC, a REG or a SUBREG |
---|
367 | of a REG that occupies all of the REG, the insn references X if |
---|
368 | it is mentioned in the destination. */ |
---|
369 | if (GET_CODE (SET_DEST (body)) != CC0 |
---|
370 | && GET_CODE (SET_DEST (body)) != PC |
---|
371 | && GET_CODE (SET_DEST (body)) != REG |
---|
372 | && ! (GET_CODE (SET_DEST (body)) == SUBREG |
---|
373 | && GET_CODE (SUBREG_REG (SET_DEST (body))) == REG |
---|
374 | && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body)))) |
---|
375 | + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD) |
---|
376 | == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body))) |
---|
377 | + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))) |
---|
378 | && reg_overlap_mentioned_p (x, SET_DEST (body))) |
---|
379 | return 1; |
---|
380 | return 0; |
---|
381 | |
---|
382 | case ASM_OPERANDS: |
---|
383 | for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--) |
---|
384 | if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i))) |
---|
385 | return 1; |
---|
386 | return 0; |
---|
387 | |
---|
388 | case CALL: |
---|
389 | case USE: |
---|
390 | return reg_overlap_mentioned_p (x, body); |
---|
391 | |
---|
392 | case TRAP_IF: |
---|
393 | return reg_overlap_mentioned_p (x, TRAP_CONDITION (body)); |
---|
394 | |
---|
395 | case UNSPEC: |
---|
396 | case UNSPEC_VOLATILE: |
---|
397 | case PARALLEL: |
---|
398 | for (i = XVECLEN (body, 0) - 1; i >= 0; i--) |
---|
399 | if (reg_referenced_p (x, XVECEXP (body, 0, i))) |
---|
400 | return 1; |
---|
401 | return 0; |
---|
402 | |
---|
403 | default: |
---|
404 | return 0; |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | /* Nonzero if register REG is referenced in an insn between |
---|
409 | FROM_INSN and TO_INSN (exclusive of those two). Sets of REG do |
---|
410 | not count. */ |
---|
411 | |
---|
412 | int |
---|
413 | reg_referenced_between_p (reg, from_insn, to_insn) |
---|
414 | rtx reg, from_insn, to_insn; |
---|
415 | { |
---|
416 | register rtx insn; |
---|
417 | |
---|
418 | if (from_insn == to_insn) |
---|
419 | return 0; |
---|
420 | |
---|
421 | for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn)) |
---|
422 | if (GET_RTX_CLASS (GET_CODE (insn)) == 'i' |
---|
423 | && (reg_referenced_p (reg, PATTERN (insn)) |
---|
424 | || (GET_CODE (insn) == CALL_INSN |
---|
425 | && find_reg_fusage (insn, USE, reg)))) |
---|
426 | return 1; |
---|
427 | return 0; |
---|
428 | } |
---|
429 | |
---|
430 | /* Nonzero if register REG is set or clobbered in an insn between |
---|
431 | FROM_INSN and TO_INSN (exclusive of those two). */ |
---|
432 | |
---|
433 | int |
---|
434 | reg_set_between_p (reg, from_insn, to_insn) |
---|
435 | rtx reg, from_insn, to_insn; |
---|
436 | { |
---|
437 | register rtx insn; |
---|
438 | |
---|
439 | if (from_insn == to_insn) |
---|
440 | return 0; |
---|
441 | |
---|
442 | for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn)) |
---|
443 | if (GET_RTX_CLASS (GET_CODE (insn)) == 'i' |
---|
444 | && reg_set_p (reg, insn)) |
---|
445 | return 1; |
---|
446 | return 0; |
---|
447 | } |
---|
448 | |
---|
449 | /* Internals of reg_set_between_p. */ |
---|
450 | |
---|
451 | static rtx reg_set_reg; |
---|
452 | static int reg_set_flag; |
---|
453 | |
---|
454 | static void |
---|
455 | reg_set_p_1 (x, pat) |
---|
456 | rtx x, pat; |
---|
457 | { |
---|
458 | /* We don't want to return 1 if X is a MEM that contains a register |
---|
459 | within REG_SET_REG. */ |
---|
460 | |
---|
461 | if ((GET_CODE (x) != MEM) |
---|
462 | && reg_overlap_mentioned_p (reg_set_reg, x)) |
---|
463 | reg_set_flag = 1; |
---|
464 | } |
---|
465 | |
---|
466 | int |
---|
467 | reg_set_p (reg, insn) |
---|
468 | rtx reg, insn; |
---|
469 | { |
---|
470 | rtx body = insn; |
---|
471 | |
---|
472 | /* We can be passed an insn or part of one. If we are passed an insn, |
---|
473 | check if a side-effect of the insn clobbers REG. */ |
---|
474 | if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') |
---|
475 | { |
---|
476 | if (FIND_REG_INC_NOTE (insn, reg) |
---|
477 | || (GET_CODE (insn) == CALL_INSN |
---|
478 | /* We'd like to test call_used_regs here, but rtlanal.c can't |
---|
479 | reference that variable due to its use in genattrtab. So |
---|
480 | we'll just be more conservative. |
---|
481 | |
---|
482 | ??? Unless we could ensure that the CALL_INSN_FUNCTION_USAGE |
---|
483 | information holds all clobbered registers. */ |
---|
484 | && ((GET_CODE (reg) == REG |
---|
485 | && REGNO (reg) < FIRST_PSEUDO_REGISTER) |
---|
486 | || GET_CODE (reg) == MEM |
---|
487 | || find_reg_fusage (insn, CLOBBER, reg)))) |
---|
488 | return 1; |
---|
489 | |
---|
490 | body = PATTERN (insn); |
---|
491 | } |
---|
492 | |
---|
493 | reg_set_reg = reg; |
---|
494 | reg_set_flag = 0; |
---|
495 | note_stores (body, reg_set_p_1); |
---|
496 | return reg_set_flag; |
---|
497 | } |
---|
498 | |
---|
499 | /* Similar to reg_set_between_p, but check all registers in X. Return 0 |
---|
500 | only if none of them are modified between START and END. Return 1 if |
---|
501 | X contains a MEM; this routine does not perform any memory aliasing. */ |
---|
502 | |
---|
503 | int |
---|
504 | modified_between_p (x, start, end) |
---|
505 | rtx x; |
---|
506 | rtx start, end; |
---|
507 | { |
---|
508 | enum rtx_code code = GET_CODE (x); |
---|
509 | char *fmt; |
---|
510 | int i, j; |
---|
511 | |
---|
512 | switch (code) |
---|
513 | { |
---|
514 | case CONST_INT: |
---|
515 | case CONST_DOUBLE: |
---|
516 | case CONST: |
---|
517 | case SYMBOL_REF: |
---|
518 | case LABEL_REF: |
---|
519 | return 0; |
---|
520 | |
---|
521 | case PC: |
---|
522 | case CC0: |
---|
523 | return 1; |
---|
524 | |
---|
525 | case MEM: |
---|
526 | /* If the memory is not constant, assume it is modified. If it is |
---|
527 | constant, we still have to check the address. */ |
---|
528 | if (! RTX_UNCHANGING_P (x)) |
---|
529 | return 1; |
---|
530 | break; |
---|
531 | |
---|
532 | case REG: |
---|
533 | return reg_set_between_p (x, start, end); |
---|
534 | |
---|
535 | default: |
---|
536 | break; |
---|
537 | } |
---|
538 | |
---|
539 | fmt = GET_RTX_FORMAT (code); |
---|
540 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
541 | { |
---|
542 | if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end)) |
---|
543 | return 1; |
---|
544 | |
---|
545 | if (fmt[i] == 'E') |
---|
546 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) |
---|
547 | if (modified_between_p (XVECEXP (x, i, j), start, end)) |
---|
548 | return 1; |
---|
549 | } |
---|
550 | |
---|
551 | return 0; |
---|
552 | } |
---|
553 | |
---|
554 | /* Similar to reg_set_p, but check all registers in X. Return 0 only if none |
---|
555 | of them are modified in INSN. Return 1 if X contains a MEM; this routine |
---|
556 | does not perform any memory aliasing. */ |
---|
557 | |
---|
558 | int |
---|
559 | modified_in_p (x, insn) |
---|
560 | rtx x; |
---|
561 | rtx insn; |
---|
562 | { |
---|
563 | enum rtx_code code = GET_CODE (x); |
---|
564 | char *fmt; |
---|
565 | int i, j; |
---|
566 | |
---|
567 | switch (code) |
---|
568 | { |
---|
569 | case CONST_INT: |
---|
570 | case CONST_DOUBLE: |
---|
571 | case CONST: |
---|
572 | case SYMBOL_REF: |
---|
573 | case LABEL_REF: |
---|
574 | return 0; |
---|
575 | |
---|
576 | case PC: |
---|
577 | case CC0: |
---|
578 | return 1; |
---|
579 | |
---|
580 | case MEM: |
---|
581 | /* If the memory is not constant, assume it is modified. If it is |
---|
582 | constant, we still have to check the address. */ |
---|
583 | if (! RTX_UNCHANGING_P (x)) |
---|
584 | return 1; |
---|
585 | break; |
---|
586 | |
---|
587 | case REG: |
---|
588 | return reg_set_p (x, insn); |
---|
589 | |
---|
590 | default: |
---|
591 | break; |
---|
592 | } |
---|
593 | |
---|
594 | fmt = GET_RTX_FORMAT (code); |
---|
595 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
596 | { |
---|
597 | if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn)) |
---|
598 | return 1; |
---|
599 | |
---|
600 | if (fmt[i] == 'E') |
---|
601 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) |
---|
602 | if (modified_in_p (XVECEXP (x, i, j), insn)) |
---|
603 | return 1; |
---|
604 | } |
---|
605 | |
---|
606 | return 0; |
---|
607 | } |
---|
608 | |
---|
609 | /* Given an INSN, return a SET expression if this insn has only a single SET. |
---|
610 | It may also have CLOBBERs, USEs, or SET whose output |
---|
611 | will not be used, which we ignore. */ |
---|
612 | |
---|
613 | rtx |
---|
614 | single_set (insn) |
---|
615 | rtx insn; |
---|
616 | { |
---|
617 | rtx set; |
---|
618 | int i; |
---|
619 | |
---|
620 | if (GET_RTX_CLASS (GET_CODE (insn)) != 'i') |
---|
621 | return 0; |
---|
622 | |
---|
623 | if (GET_CODE (PATTERN (insn)) == SET) |
---|
624 | return PATTERN (insn); |
---|
625 | |
---|
626 | else if (GET_CODE (PATTERN (insn)) == PARALLEL) |
---|
627 | { |
---|
628 | for (i = 0, set = 0; i < XVECLEN (PATTERN (insn), 0); i++) |
---|
629 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET |
---|
630 | && (! find_reg_note (insn, REG_UNUSED, |
---|
631 | SET_DEST (XVECEXP (PATTERN (insn), 0, i))) |
---|
632 | || side_effects_p (XVECEXP (PATTERN (insn), 0, i)))) |
---|
633 | { |
---|
634 | if (set) |
---|
635 | return 0; |
---|
636 | else |
---|
637 | set = XVECEXP (PATTERN (insn), 0, i); |
---|
638 | } |
---|
639 | return set; |
---|
640 | } |
---|
641 | |
---|
642 | return 0; |
---|
643 | } |
---|
644 | |
---|
645 | /* Return the last thing that X was assigned from before *PINSN. Verify that |
---|
646 | the object is not modified up to VALID_TO. If it was, if we hit |
---|
647 | a partial assignment to X, or hit a CODE_LABEL first, return X. If we |
---|
648 | found an assignment, update *PINSN to point to it. */ |
---|
649 | |
---|
650 | rtx |
---|
651 | find_last_value (x, pinsn, valid_to) |
---|
652 | rtx x; |
---|
653 | rtx *pinsn; |
---|
654 | rtx valid_to; |
---|
655 | { |
---|
656 | rtx p; |
---|
657 | |
---|
658 | for (p = PREV_INSN (*pinsn); p && GET_CODE (p) != CODE_LABEL; |
---|
659 | p = PREV_INSN (p)) |
---|
660 | if (GET_RTX_CLASS (GET_CODE (p)) == 'i') |
---|
661 | { |
---|
662 | rtx set = single_set (p); |
---|
663 | rtx note = find_reg_note (p, REG_EQUAL, NULL_RTX); |
---|
664 | |
---|
665 | if (set && rtx_equal_p (x, SET_DEST (set))) |
---|
666 | { |
---|
667 | rtx src = SET_SRC (set); |
---|
668 | |
---|
669 | if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST) |
---|
670 | src = XEXP (note, 0); |
---|
671 | |
---|
672 | if (! modified_between_p (src, PREV_INSN (p), valid_to) |
---|
673 | /* Reject hard registers because we don't usually want |
---|
674 | to use them; we'd rather use a pseudo. */ |
---|
675 | && ! (GET_CODE (src) == REG |
---|
676 | && REGNO (src) < FIRST_PSEUDO_REGISTER)) |
---|
677 | { |
---|
678 | *pinsn = p; |
---|
679 | return src; |
---|
680 | } |
---|
681 | } |
---|
682 | |
---|
683 | /* If set in non-simple way, we don't have a value. */ |
---|
684 | if (reg_set_p (x, p)) |
---|
685 | break; |
---|
686 | } |
---|
687 | |
---|
688 | return x; |
---|
689 | } |
---|
690 | |
---|
691 | /* Return nonzero if register in range [REGNO, ENDREGNO) |
---|
692 | appears either explicitly or implicitly in X |
---|
693 | other than being stored into. |
---|
694 | |
---|
695 | References contained within the substructure at LOC do not count. |
---|
696 | LOC may be zero, meaning don't ignore anything. */ |
---|
697 | |
---|
698 | int |
---|
699 | refers_to_regno_p (regno, endregno, x, loc) |
---|
700 | int regno, endregno; |
---|
701 | rtx x; |
---|
702 | rtx *loc; |
---|
703 | { |
---|
704 | register int i; |
---|
705 | register RTX_CODE code; |
---|
706 | register char *fmt; |
---|
707 | |
---|
708 | repeat: |
---|
709 | /* The contents of a REG_NONNEG note is always zero, so we must come here |
---|
710 | upon repeat in case the last REG_NOTE is a REG_NONNEG note. */ |
---|
711 | if (x == 0) |
---|
712 | return 0; |
---|
713 | |
---|
714 | code = GET_CODE (x); |
---|
715 | |
---|
716 | switch (code) |
---|
717 | { |
---|
718 | case REG: |
---|
719 | i = REGNO (x); |
---|
720 | |
---|
721 | /* If we modifying the stack, frame, or argument pointer, it will |
---|
722 | clobber a virtual register. In fact, we could be more precise, |
---|
723 | but it isn't worth it. */ |
---|
724 | if ((i == STACK_POINTER_REGNUM |
---|
725 | #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
---|
726 | || i == ARG_POINTER_REGNUM |
---|
727 | #endif |
---|
728 | || i == FRAME_POINTER_REGNUM) |
---|
729 | && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER) |
---|
730 | return 1; |
---|
731 | |
---|
732 | return (endregno > i |
---|
733 | && regno < i + (i < FIRST_PSEUDO_REGISTER |
---|
734 | ? HARD_REGNO_NREGS (i, GET_MODE (x)) |
---|
735 | : 1)); |
---|
736 | |
---|
737 | case SUBREG: |
---|
738 | /* If this is a SUBREG of a hard reg, we can see exactly which |
---|
739 | registers are being modified. Otherwise, handle normally. */ |
---|
740 | if (GET_CODE (SUBREG_REG (x)) == REG |
---|
741 | && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER) |
---|
742 | { |
---|
743 | int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x); |
---|
744 | int inner_endregno |
---|
745 | = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER |
---|
746 | ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1); |
---|
747 | |
---|
748 | return endregno > inner_regno && regno < inner_endregno; |
---|
749 | } |
---|
750 | break; |
---|
751 | |
---|
752 | case CLOBBER: |
---|
753 | case SET: |
---|
754 | if (&SET_DEST (x) != loc |
---|
755 | /* Note setting a SUBREG counts as referring to the REG it is in for |
---|
756 | a pseudo but not for hard registers since we can |
---|
757 | treat each word individually. */ |
---|
758 | && ((GET_CODE (SET_DEST (x)) == SUBREG |
---|
759 | && loc != &SUBREG_REG (SET_DEST (x)) |
---|
760 | && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG |
---|
761 | && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER |
---|
762 | && refers_to_regno_p (regno, endregno, |
---|
763 | SUBREG_REG (SET_DEST (x)), loc)) |
---|
764 | || (GET_CODE (SET_DEST (x)) != REG |
---|
765 | && refers_to_regno_p (regno, endregno, SET_DEST (x), loc)))) |
---|
766 | return 1; |
---|
767 | |
---|
768 | if (code == CLOBBER || loc == &SET_SRC (x)) |
---|
769 | return 0; |
---|
770 | x = SET_SRC (x); |
---|
771 | goto repeat; |
---|
772 | |
---|
773 | default: |
---|
774 | break; |
---|
775 | } |
---|
776 | |
---|
777 | /* X does not match, so try its subexpressions. */ |
---|
778 | |
---|
779 | fmt = GET_RTX_FORMAT (code); |
---|
780 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
781 | { |
---|
782 | if (fmt[i] == 'e' && loc != &XEXP (x, i)) |
---|
783 | { |
---|
784 | if (i == 0) |
---|
785 | { |
---|
786 | x = XEXP (x, 0); |
---|
787 | goto repeat; |
---|
788 | } |
---|
789 | else |
---|
790 | if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc)) |
---|
791 | return 1; |
---|
792 | } |
---|
793 | else if (fmt[i] == 'E') |
---|
794 | { |
---|
795 | register int j; |
---|
796 | for (j = XVECLEN (x, i) - 1; j >=0; j--) |
---|
797 | if (loc != &XVECEXP (x, i, j) |
---|
798 | && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc)) |
---|
799 | return 1; |
---|
800 | } |
---|
801 | } |
---|
802 | return 0; |
---|
803 | } |
---|
804 | |
---|
805 | /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG, |
---|
806 | we check if any register number in X conflicts with the relevant register |
---|
807 | numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN |
---|
808 | contains a MEM (we don't bother checking for memory addresses that can't |
---|
809 | conflict because we expect this to be a rare case. */ |
---|
810 | |
---|
811 | int |
---|
812 | reg_overlap_mentioned_p (x, in) |
---|
813 | rtx x, in; |
---|
814 | { |
---|
815 | int regno, endregno; |
---|
816 | |
---|
817 | if (GET_CODE (x) == SUBREG) |
---|
818 | { |
---|
819 | regno = REGNO (SUBREG_REG (x)); |
---|
820 | if (regno < FIRST_PSEUDO_REGISTER) |
---|
821 | regno += SUBREG_WORD (x); |
---|
822 | } |
---|
823 | else if (GET_CODE (x) == REG) |
---|
824 | regno = REGNO (x); |
---|
825 | else if (CONSTANT_P (x)) |
---|
826 | return 0; |
---|
827 | else if (GET_CODE (x) == MEM) |
---|
828 | { |
---|
829 | char *fmt; |
---|
830 | int i; |
---|
831 | |
---|
832 | if (GET_CODE (in) == MEM) |
---|
833 | return 1; |
---|
834 | |
---|
835 | fmt = GET_RTX_FORMAT (GET_CODE (in)); |
---|
836 | |
---|
837 | for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--) |
---|
838 | if (fmt[i] == 'e' && reg_overlap_mentioned_p (x, XEXP (in, i))) |
---|
839 | return 1; |
---|
840 | |
---|
841 | return 0; |
---|
842 | } |
---|
843 | else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC |
---|
844 | || GET_CODE (x) == CC0) |
---|
845 | return reg_mentioned_p (x, in); |
---|
846 | else |
---|
847 | abort (); |
---|
848 | |
---|
849 | endregno = regno + (regno < FIRST_PSEUDO_REGISTER |
---|
850 | ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1); |
---|
851 | |
---|
852 | return refers_to_regno_p (regno, endregno, in, NULL_PTR); |
---|
853 | } |
---|
854 | |
---|
855 | /* Used for communications between the next few functions. */ |
---|
856 | |
---|
857 | static int reg_set_last_unknown; |
---|
858 | static rtx reg_set_last_value; |
---|
859 | static int reg_set_last_first_regno, reg_set_last_last_regno; |
---|
860 | |
---|
861 | /* Called via note_stores from reg_set_last. */ |
---|
862 | |
---|
863 | static void |
---|
864 | reg_set_last_1 (x, pat) |
---|
865 | rtx x; |
---|
866 | rtx pat; |
---|
867 | { |
---|
868 | int first, last; |
---|
869 | |
---|
870 | /* If X is not a register, or is not one in the range we care |
---|
871 | about, ignore. */ |
---|
872 | if (GET_CODE (x) != REG) |
---|
873 | return; |
---|
874 | |
---|
875 | first = REGNO (x); |
---|
876 | last = first + (first < FIRST_PSEUDO_REGISTER |
---|
877 | ? HARD_REGNO_NREGS (first, GET_MODE (x)) : 1); |
---|
878 | |
---|
879 | if (first >= reg_set_last_last_regno |
---|
880 | || last <= reg_set_last_first_regno) |
---|
881 | return; |
---|
882 | |
---|
883 | /* If this is a CLOBBER or is some complex LHS, or doesn't modify |
---|
884 | exactly the registers we care about, show we don't know the value. */ |
---|
885 | if (GET_CODE (pat) == CLOBBER || SET_DEST (pat) != x |
---|
886 | || first != reg_set_last_first_regno |
---|
887 | || last != reg_set_last_last_regno) |
---|
888 | reg_set_last_unknown = 1; |
---|
889 | else |
---|
890 | reg_set_last_value = SET_SRC (pat); |
---|
891 | } |
---|
892 | |
---|
893 | /* Return the last value to which REG was set prior to INSN. If we can't |
---|
894 | find it easily, return 0. |
---|
895 | |
---|
896 | We only return a REG, SUBREG, or constant because it is too hard to |
---|
897 | check if a MEM remains unchanged. */ |
---|
898 | |
---|
899 | rtx |
---|
900 | reg_set_last (x, insn) |
---|
901 | rtx x; |
---|
902 | rtx insn; |
---|
903 | { |
---|
904 | rtx orig_insn = insn; |
---|
905 | |
---|
906 | reg_set_last_first_regno = REGNO (x); |
---|
907 | |
---|
908 | reg_set_last_last_regno |
---|
909 | = reg_set_last_first_regno |
---|
910 | + (reg_set_last_first_regno < FIRST_PSEUDO_REGISTER |
---|
911 | ? HARD_REGNO_NREGS (reg_set_last_first_regno, GET_MODE (x)) : 1); |
---|
912 | |
---|
913 | reg_set_last_unknown = 0; |
---|
914 | reg_set_last_value = 0; |
---|
915 | |
---|
916 | /* Scan backwards until reg_set_last_1 changed one of the above flags. |
---|
917 | Stop when we reach a label or X is a hard reg and we reach a |
---|
918 | CALL_INSN (if reg_set_last_last_regno is a hard reg). |
---|
919 | |
---|
920 | If we find a set of X, ensure that its SET_SRC remains unchanged. */ |
---|
921 | |
---|
922 | /* We compare with <= here, because reg_set_last_last_regno |
---|
923 | is actually the number of the first reg *not* in X. */ |
---|
924 | for (; |
---|
925 | insn && GET_CODE (insn) != CODE_LABEL |
---|
926 | && ! (GET_CODE (insn) == CALL_INSN |
---|
927 | && reg_set_last_last_regno <= FIRST_PSEUDO_REGISTER); |
---|
928 | insn = PREV_INSN (insn)) |
---|
929 | if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') |
---|
930 | { |
---|
931 | note_stores (PATTERN (insn), reg_set_last_1); |
---|
932 | if (reg_set_last_unknown) |
---|
933 | return 0; |
---|
934 | else if (reg_set_last_value) |
---|
935 | { |
---|
936 | if (CONSTANT_P (reg_set_last_value) |
---|
937 | || ((GET_CODE (reg_set_last_value) == REG |
---|
938 | || GET_CODE (reg_set_last_value) == SUBREG) |
---|
939 | && ! reg_set_between_p (reg_set_last_value, |
---|
940 | insn, orig_insn))) |
---|
941 | return reg_set_last_value; |
---|
942 | else |
---|
943 | return 0; |
---|
944 | } |
---|
945 | } |
---|
946 | |
---|
947 | return 0; |
---|
948 | } |
---|
949 | |
---|
950 | /* This is 1 until after the rtl generation pass. */ |
---|
951 | int rtx_equal_function_value_matters; |
---|
952 | |
---|
953 | /* Return 1 if X and Y are identical-looking rtx's. |
---|
954 | This is the Lisp function EQUAL for rtx arguments. */ |
---|
955 | |
---|
956 | int |
---|
957 | rtx_equal_p (x, y) |
---|
958 | rtx x, y; |
---|
959 | { |
---|
960 | register int i; |
---|
961 | register int j; |
---|
962 | register enum rtx_code code; |
---|
963 | register char *fmt; |
---|
964 | |
---|
965 | if (x == y) |
---|
966 | return 1; |
---|
967 | if (x == 0 || y == 0) |
---|
968 | return 0; |
---|
969 | |
---|
970 | code = GET_CODE (x); |
---|
971 | /* Rtx's of different codes cannot be equal. */ |
---|
972 | if (code != GET_CODE (y)) |
---|
973 | return 0; |
---|
974 | |
---|
975 | /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. |
---|
976 | (REG:SI x) and (REG:HI x) are NOT equivalent. */ |
---|
977 | |
---|
978 | if (GET_MODE (x) != GET_MODE (y)) |
---|
979 | return 0; |
---|
980 | |
---|
981 | /* REG, LABEL_REF, and SYMBOL_REF can be compared nonrecursively. */ |
---|
982 | |
---|
983 | if (code == REG) |
---|
984 | /* Until rtl generation is complete, don't consider a reference to the |
---|
985 | return register of the current function the same as the return from a |
---|
986 | called function. This eases the job of function integration. Once the |
---|
987 | distinction is no longer needed, they can be considered equivalent. */ |
---|
988 | return (REGNO (x) == REGNO (y) |
---|
989 | && (! rtx_equal_function_value_matters |
---|
990 | || REG_FUNCTION_VALUE_P (x) == REG_FUNCTION_VALUE_P (y))); |
---|
991 | else if (code == LABEL_REF) |
---|
992 | return XEXP (x, 0) == XEXP (y, 0); |
---|
993 | else if (code == SYMBOL_REF) |
---|
994 | return XSTR (x, 0) == XSTR (y, 0); |
---|
995 | else if (code == SCRATCH || code == CONST_DOUBLE) |
---|
996 | return 0; |
---|
997 | |
---|
998 | /* Compare the elements. If any pair of corresponding elements |
---|
999 | fail to match, return 0 for the whole things. */ |
---|
1000 | |
---|
1001 | fmt = GET_RTX_FORMAT (code); |
---|
1002 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
1003 | { |
---|
1004 | switch (fmt[i]) |
---|
1005 | { |
---|
1006 | case 'w': |
---|
1007 | if (XWINT (x, i) != XWINT (y, i)) |
---|
1008 | return 0; |
---|
1009 | break; |
---|
1010 | |
---|
1011 | case 'n': |
---|
1012 | case 'i': |
---|
1013 | if (XINT (x, i) != XINT (y, i)) |
---|
1014 | return 0; |
---|
1015 | break; |
---|
1016 | |
---|
1017 | case 'V': |
---|
1018 | case 'E': |
---|
1019 | /* Two vectors must have the same length. */ |
---|
1020 | if (XVECLEN (x, i) != XVECLEN (y, i)) |
---|
1021 | return 0; |
---|
1022 | |
---|
1023 | /* And the corresponding elements must match. */ |
---|
1024 | for (j = 0; j < XVECLEN (x, i); j++) |
---|
1025 | if (rtx_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)) == 0) |
---|
1026 | return 0; |
---|
1027 | break; |
---|
1028 | |
---|
1029 | case 'e': |
---|
1030 | if (rtx_equal_p (XEXP (x, i), XEXP (y, i)) == 0) |
---|
1031 | return 0; |
---|
1032 | break; |
---|
1033 | |
---|
1034 | case 'S': |
---|
1035 | case 's': |
---|
1036 | if (strcmp (XSTR (x, i), XSTR (y, i))) |
---|
1037 | return 0; |
---|
1038 | break; |
---|
1039 | |
---|
1040 | case 'u': |
---|
1041 | /* These are just backpointers, so they don't matter. */ |
---|
1042 | break; |
---|
1043 | |
---|
1044 | case '0': |
---|
1045 | break; |
---|
1046 | |
---|
1047 | /* It is believed that rtx's at this level will never |
---|
1048 | contain anything but integers and other rtx's, |
---|
1049 | except for within LABEL_REFs and SYMBOL_REFs. */ |
---|
1050 | default: |
---|
1051 | abort (); |
---|
1052 | } |
---|
1053 | } |
---|
1054 | return 1; |
---|
1055 | } |
---|
1056 | |
---|
1057 | /* Call FUN on each register or MEM that is stored into or clobbered by X. |
---|
1058 | (X would be the pattern of an insn). |
---|
1059 | FUN receives two arguments: |
---|
1060 | the REG, MEM, CC0 or PC being stored in or clobbered, |
---|
1061 | the SET or CLOBBER rtx that does the store. |
---|
1062 | |
---|
1063 | If the item being stored in or clobbered is a SUBREG of a hard register, |
---|
1064 | the SUBREG will be passed. */ |
---|
1065 | |
---|
1066 | void |
---|
1067 | note_stores (x, fun) |
---|
1068 | register rtx x; |
---|
1069 | void (*fun) (); |
---|
1070 | { |
---|
1071 | if ((GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)) |
---|
1072 | { |
---|
1073 | register rtx dest = SET_DEST (x); |
---|
1074 | while ((GET_CODE (dest) == SUBREG |
---|
1075 | && (GET_CODE (SUBREG_REG (dest)) != REG |
---|
1076 | || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER)) |
---|
1077 | || GET_CODE (dest) == ZERO_EXTRACT |
---|
1078 | || GET_CODE (dest) == SIGN_EXTRACT |
---|
1079 | || GET_CODE (dest) == STRICT_LOW_PART) |
---|
1080 | dest = XEXP (dest, 0); |
---|
1081 | (*fun) (dest, x); |
---|
1082 | } |
---|
1083 | else if (GET_CODE (x) == PARALLEL) |
---|
1084 | { |
---|
1085 | register int i; |
---|
1086 | for (i = XVECLEN (x, 0) - 1; i >= 0; i--) |
---|
1087 | { |
---|
1088 | register rtx y = XVECEXP (x, 0, i); |
---|
1089 | if (GET_CODE (y) == SET || GET_CODE (y) == CLOBBER) |
---|
1090 | { |
---|
1091 | register rtx dest = SET_DEST (y); |
---|
1092 | while ((GET_CODE (dest) == SUBREG |
---|
1093 | && (GET_CODE (SUBREG_REG (dest)) != REG |
---|
1094 | || (REGNO (SUBREG_REG (dest)) |
---|
1095 | >= FIRST_PSEUDO_REGISTER))) |
---|
1096 | || GET_CODE (dest) == ZERO_EXTRACT |
---|
1097 | || GET_CODE (dest) == SIGN_EXTRACT |
---|
1098 | || GET_CODE (dest) == STRICT_LOW_PART) |
---|
1099 | dest = XEXP (dest, 0); |
---|
1100 | (*fun) (dest, y); |
---|
1101 | } |
---|
1102 | } |
---|
1103 | } |
---|
1104 | } |
---|
1105 | |
---|
1106 | /* Return nonzero if X's old contents don't survive after INSN. |
---|
1107 | This will be true if X is (cc0) or if X is a register and |
---|
1108 | X dies in INSN or because INSN entirely sets X. |
---|
1109 | |
---|
1110 | "Entirely set" means set directly and not through a SUBREG, |
---|
1111 | ZERO_EXTRACT or SIGN_EXTRACT, so no trace of the old contents remains. |
---|
1112 | Likewise, REG_INC does not count. |
---|
1113 | |
---|
1114 | REG may be a hard or pseudo reg. Renumbering is not taken into account, |
---|
1115 | but for this use that makes no difference, since regs don't overlap |
---|
1116 | during their lifetimes. Therefore, this function may be used |
---|
1117 | at any time after deaths have been computed (in flow.c). |
---|
1118 | |
---|
1119 | If REG is a hard reg that occupies multiple machine registers, this |
---|
1120 | function will only return 1 if each of those registers will be replaced |
---|
1121 | by INSN. */ |
---|
1122 | |
---|
1123 | int |
---|
1124 | dead_or_set_p (insn, x) |
---|
1125 | rtx insn; |
---|
1126 | rtx x; |
---|
1127 | { |
---|
1128 | register int regno, last_regno; |
---|
1129 | register int i; |
---|
1130 | |
---|
1131 | /* Can't use cc0_rtx below since this file is used by genattrtab.c. */ |
---|
1132 | if (GET_CODE (x) == CC0) |
---|
1133 | return 1; |
---|
1134 | |
---|
1135 | if (GET_CODE (x) != REG) |
---|
1136 | abort (); |
---|
1137 | |
---|
1138 | regno = REGNO (x); |
---|
1139 | last_regno = (regno >= FIRST_PSEUDO_REGISTER ? regno |
---|
1140 | : regno + HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1); |
---|
1141 | |
---|
1142 | for (i = regno; i <= last_regno; i++) |
---|
1143 | if (! dead_or_set_regno_p (insn, i)) |
---|
1144 | return 0; |
---|
1145 | |
---|
1146 | return 1; |
---|
1147 | } |
---|
1148 | |
---|
1149 | /* Utility function for dead_or_set_p to check an individual register. Also |
---|
1150 | called from flow.c. */ |
---|
1151 | |
---|
1152 | int |
---|
1153 | dead_or_set_regno_p (insn, test_regno) |
---|
1154 | rtx insn; |
---|
1155 | int test_regno; |
---|
1156 | { |
---|
1157 | int regno, endregno; |
---|
1158 | rtx link; |
---|
1159 | |
---|
1160 | /* REG_READ notes are not normally maintained after reload, so we |
---|
1161 | ignore them if the are invalid. */ |
---|
1162 | if (! reload_completed |
---|
1163 | #ifdef PRESERVE_DEATH_INFO_REGNO_P |
---|
1164 | || PRESERVE_DEATH_INFO_REGNO_P (test_regno) |
---|
1165 | #endif |
---|
1166 | ) |
---|
1167 | { |
---|
1168 | /* See if there is a death note for something that includes |
---|
1169 | TEST_REGNO. */ |
---|
1170 | for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) |
---|
1171 | { |
---|
1172 | if (REG_NOTE_KIND (link) != REG_DEAD |
---|
1173 | || GET_CODE (XEXP (link, 0)) != REG) |
---|
1174 | continue; |
---|
1175 | |
---|
1176 | regno = REGNO (XEXP (link, 0)); |
---|
1177 | endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1 |
---|
1178 | : regno + HARD_REGNO_NREGS (regno, |
---|
1179 | GET_MODE (XEXP (link, 0)))); |
---|
1180 | |
---|
1181 | if (test_regno >= regno && test_regno < endregno) |
---|
1182 | return 1; |
---|
1183 | } |
---|
1184 | } |
---|
1185 | |
---|
1186 | if (GET_CODE (insn) == CALL_INSN |
---|
1187 | && find_regno_fusage (insn, CLOBBER, test_regno)) |
---|
1188 | return 1; |
---|
1189 | |
---|
1190 | if (GET_CODE (PATTERN (insn)) == SET) |
---|
1191 | { |
---|
1192 | rtx dest = SET_DEST (PATTERN (insn)); |
---|
1193 | |
---|
1194 | /* A value is totally replaced if it is the destination or the |
---|
1195 | destination is a SUBREG of REGNO that does not change the number of |
---|
1196 | words in it. */ |
---|
1197 | if (GET_CODE (dest) == SUBREG |
---|
1198 | && (((GET_MODE_SIZE (GET_MODE (dest)) |
---|
1199 | + UNITS_PER_WORD - 1) / UNITS_PER_WORD) |
---|
1200 | == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) |
---|
1201 | + UNITS_PER_WORD - 1) / UNITS_PER_WORD))) |
---|
1202 | dest = SUBREG_REG (dest); |
---|
1203 | |
---|
1204 | if (GET_CODE (dest) != REG) |
---|
1205 | return 0; |
---|
1206 | |
---|
1207 | regno = REGNO (dest); |
---|
1208 | endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1 |
---|
1209 | : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest))); |
---|
1210 | |
---|
1211 | return (test_regno >= regno && test_regno < endregno); |
---|
1212 | } |
---|
1213 | else if (GET_CODE (PATTERN (insn)) == PARALLEL) |
---|
1214 | { |
---|
1215 | register int i; |
---|
1216 | |
---|
1217 | for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) |
---|
1218 | { |
---|
1219 | rtx body = XVECEXP (PATTERN (insn), 0, i); |
---|
1220 | |
---|
1221 | if (GET_CODE (body) == SET || GET_CODE (body) == CLOBBER) |
---|
1222 | { |
---|
1223 | rtx dest = SET_DEST (body); |
---|
1224 | |
---|
1225 | if (GET_CODE (dest) == SUBREG |
---|
1226 | && (((GET_MODE_SIZE (GET_MODE (dest)) |
---|
1227 | + UNITS_PER_WORD - 1) / UNITS_PER_WORD) |
---|
1228 | == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) |
---|
1229 | + UNITS_PER_WORD - 1) / UNITS_PER_WORD))) |
---|
1230 | dest = SUBREG_REG (dest); |
---|
1231 | |
---|
1232 | if (GET_CODE (dest) != REG) |
---|
1233 | continue; |
---|
1234 | |
---|
1235 | regno = REGNO (dest); |
---|
1236 | endregno = (regno >= FIRST_PSEUDO_REGISTER ? regno + 1 |
---|
1237 | : regno + HARD_REGNO_NREGS (regno, GET_MODE (dest))); |
---|
1238 | |
---|
1239 | if (test_regno >= regno && test_regno < endregno) |
---|
1240 | return 1; |
---|
1241 | } |
---|
1242 | } |
---|
1243 | } |
---|
1244 | |
---|
1245 | return 0; |
---|
1246 | } |
---|
1247 | |
---|
1248 | /* Return the reg-note of kind KIND in insn INSN, if there is one. |
---|
1249 | If DATUM is nonzero, look for one whose datum is DATUM. */ |
---|
1250 | |
---|
1251 | rtx |
---|
1252 | find_reg_note (insn, kind, datum) |
---|
1253 | rtx insn; |
---|
1254 | enum reg_note kind; |
---|
1255 | rtx datum; |
---|
1256 | { |
---|
1257 | register rtx link; |
---|
1258 | |
---|
1259 | for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) |
---|
1260 | if (REG_NOTE_KIND (link) == kind |
---|
1261 | && (datum == 0 || datum == XEXP (link, 0))) |
---|
1262 | return link; |
---|
1263 | return 0; |
---|
1264 | } |
---|
1265 | |
---|
1266 | /* Return the reg-note of kind KIND in insn INSN which applies to register |
---|
1267 | number REGNO, if any. Return 0 if there is no such reg-note. Note that |
---|
1268 | the REGNO of this NOTE need not be REGNO if REGNO is a hard register; |
---|
1269 | it might be the case that the note overlaps REGNO. */ |
---|
1270 | |
---|
1271 | rtx |
---|
1272 | find_regno_note (insn, kind, regno) |
---|
1273 | rtx insn; |
---|
1274 | enum reg_note kind; |
---|
1275 | int regno; |
---|
1276 | { |
---|
1277 | register rtx link; |
---|
1278 | |
---|
1279 | for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) |
---|
1280 | if (REG_NOTE_KIND (link) == kind |
---|
1281 | /* Verify that it is a register, so that scratch and MEM won't cause a |
---|
1282 | problem here. */ |
---|
1283 | && GET_CODE (XEXP (link, 0)) == REG |
---|
1284 | && REGNO (XEXP (link, 0)) <= regno |
---|
1285 | && ((REGNO (XEXP (link, 0)) |
---|
1286 | + (REGNO (XEXP (link, 0)) >= FIRST_PSEUDO_REGISTER ? 1 |
---|
1287 | : HARD_REGNO_NREGS (REGNO (XEXP (link, 0)), |
---|
1288 | GET_MODE (XEXP (link, 0))))) |
---|
1289 | > regno)) |
---|
1290 | return link; |
---|
1291 | return 0; |
---|
1292 | } |
---|
1293 | |
---|
1294 | /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found |
---|
1295 | in the CALL_INSN_FUNCTION_USAGE information of INSN. */ |
---|
1296 | |
---|
1297 | int |
---|
1298 | find_reg_fusage (insn, code, datum) |
---|
1299 | rtx insn; |
---|
1300 | enum rtx_code code; |
---|
1301 | rtx datum; |
---|
1302 | { |
---|
1303 | /* If it's not a CALL_INSN, it can't possibly have a |
---|
1304 | CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */ |
---|
1305 | if (GET_CODE (insn) != CALL_INSN) |
---|
1306 | return 0; |
---|
1307 | |
---|
1308 | if (! datum) |
---|
1309 | abort(); |
---|
1310 | |
---|
1311 | if (GET_CODE (datum) != REG) |
---|
1312 | { |
---|
1313 | register rtx link; |
---|
1314 | |
---|
1315 | for (link = CALL_INSN_FUNCTION_USAGE (insn); |
---|
1316 | link; |
---|
1317 | link = XEXP (link, 1)) |
---|
1318 | if (GET_CODE (XEXP (link, 0)) == code |
---|
1319 | && rtx_equal_p (datum, SET_DEST (XEXP (link, 0)))) |
---|
1320 | return 1; |
---|
1321 | } |
---|
1322 | else |
---|
1323 | { |
---|
1324 | register int regno = REGNO (datum); |
---|
1325 | |
---|
1326 | /* CALL_INSN_FUNCTION_USAGE information cannot contain references |
---|
1327 | to pseudo registers, so don't bother checking. */ |
---|
1328 | |
---|
1329 | if (regno < FIRST_PSEUDO_REGISTER) |
---|
1330 | { |
---|
1331 | int end_regno = regno + HARD_REGNO_NREGS (regno, GET_MODE (datum)); |
---|
1332 | int i; |
---|
1333 | |
---|
1334 | for (i = regno; i < end_regno; i++) |
---|
1335 | if (find_regno_fusage (insn, code, i)) |
---|
1336 | return 1; |
---|
1337 | } |
---|
1338 | } |
---|
1339 | |
---|
1340 | return 0; |
---|
1341 | } |
---|
1342 | |
---|
1343 | /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found |
---|
1344 | in the CALL_INSN_FUNCTION_USAGE information of INSN. */ |
---|
1345 | |
---|
1346 | int |
---|
1347 | find_regno_fusage (insn, code, regno) |
---|
1348 | rtx insn; |
---|
1349 | enum rtx_code code; |
---|
1350 | int regno; |
---|
1351 | { |
---|
1352 | register rtx link; |
---|
1353 | |
---|
1354 | /* CALL_INSN_FUNCTION_USAGE information cannot contain references |
---|
1355 | to pseudo registers, so don't bother checking. */ |
---|
1356 | |
---|
1357 | if (regno >= FIRST_PSEUDO_REGISTER |
---|
1358 | || GET_CODE (insn) != CALL_INSN ) |
---|
1359 | return 0; |
---|
1360 | |
---|
1361 | for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1)) |
---|
1362 | { |
---|
1363 | register int regnote; |
---|
1364 | register rtx op; |
---|
1365 | |
---|
1366 | if (GET_CODE (op = XEXP (link, 0)) == code |
---|
1367 | && GET_CODE (SET_DEST (op)) == REG |
---|
1368 | && (regnote = REGNO (SET_DEST (op))) <= regno |
---|
1369 | && regnote |
---|
1370 | + HARD_REGNO_NREGS (regnote, GET_MODE (SET_DEST (op))) |
---|
1371 | > regno) |
---|
1372 | return 1; |
---|
1373 | } |
---|
1374 | |
---|
1375 | return 0; |
---|
1376 | } |
---|
1377 | |
---|
1378 | /* Remove register note NOTE from the REG_NOTES of INSN. */ |
---|
1379 | |
---|
1380 | void |
---|
1381 | remove_note (insn, note) |
---|
1382 | register rtx note; |
---|
1383 | register rtx insn; |
---|
1384 | { |
---|
1385 | register rtx link; |
---|
1386 | |
---|
1387 | if (REG_NOTES (insn) == note) |
---|
1388 | { |
---|
1389 | REG_NOTES (insn) = XEXP (note, 1); |
---|
1390 | return; |
---|
1391 | } |
---|
1392 | |
---|
1393 | for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) |
---|
1394 | if (XEXP (link, 1) == note) |
---|
1395 | { |
---|
1396 | XEXP (link, 1) = XEXP (note, 1); |
---|
1397 | return; |
---|
1398 | } |
---|
1399 | |
---|
1400 | abort (); |
---|
1401 | } |
---|
1402 | |
---|
1403 | /* Nonzero if X contains any volatile instructions. These are instructions |
---|
1404 | which may cause unpredictable machine state instructions, and thus no |
---|
1405 | instructions should be moved or combined across them. This includes |
---|
1406 | only volatile asms and UNSPEC_VOLATILE instructions. */ |
---|
1407 | |
---|
1408 | int |
---|
1409 | volatile_insn_p (x) |
---|
1410 | rtx x; |
---|
1411 | { |
---|
1412 | register RTX_CODE code; |
---|
1413 | |
---|
1414 | code = GET_CODE (x); |
---|
1415 | switch (code) |
---|
1416 | { |
---|
1417 | case LABEL_REF: |
---|
1418 | case SYMBOL_REF: |
---|
1419 | case CONST_INT: |
---|
1420 | case CONST: |
---|
1421 | case CONST_DOUBLE: |
---|
1422 | case CC0: |
---|
1423 | case PC: |
---|
1424 | case REG: |
---|
1425 | case SCRATCH: |
---|
1426 | case CLOBBER: |
---|
1427 | case ASM_INPUT: |
---|
1428 | case ADDR_VEC: |
---|
1429 | case ADDR_DIFF_VEC: |
---|
1430 | case CALL: |
---|
1431 | case MEM: |
---|
1432 | return 0; |
---|
1433 | |
---|
1434 | case UNSPEC_VOLATILE: |
---|
1435 | /* case TRAP_IF: This isn't clear yet. */ |
---|
1436 | return 1; |
---|
1437 | |
---|
1438 | case ASM_OPERANDS: |
---|
1439 | if (MEM_VOLATILE_P (x)) |
---|
1440 | return 1; |
---|
1441 | |
---|
1442 | default: |
---|
1443 | break; |
---|
1444 | } |
---|
1445 | |
---|
1446 | /* Recursively scan the operands of this expression. */ |
---|
1447 | |
---|
1448 | { |
---|
1449 | register char *fmt = GET_RTX_FORMAT (code); |
---|
1450 | register int i; |
---|
1451 | |
---|
1452 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
1453 | { |
---|
1454 | if (fmt[i] == 'e') |
---|
1455 | { |
---|
1456 | if (volatile_insn_p (XEXP (x, i))) |
---|
1457 | return 1; |
---|
1458 | } |
---|
1459 | if (fmt[i] == 'E') |
---|
1460 | { |
---|
1461 | register int j; |
---|
1462 | for (j = 0; j < XVECLEN (x, i); j++) |
---|
1463 | if (volatile_insn_p (XVECEXP (x, i, j))) |
---|
1464 | return 1; |
---|
1465 | } |
---|
1466 | } |
---|
1467 | } |
---|
1468 | return 0; |
---|
1469 | } |
---|
1470 | |
---|
1471 | /* Nonzero if X contains any volatile memory references |
---|
1472 | UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */ |
---|
1473 | |
---|
1474 | int |
---|
1475 | volatile_refs_p (x) |
---|
1476 | rtx x; |
---|
1477 | { |
---|
1478 | register RTX_CODE code; |
---|
1479 | |
---|
1480 | code = GET_CODE (x); |
---|
1481 | switch (code) |
---|
1482 | { |
---|
1483 | case LABEL_REF: |
---|
1484 | case SYMBOL_REF: |
---|
1485 | case CONST_INT: |
---|
1486 | case CONST: |
---|
1487 | case CONST_DOUBLE: |
---|
1488 | case CC0: |
---|
1489 | case PC: |
---|
1490 | case REG: |
---|
1491 | case SCRATCH: |
---|
1492 | case CLOBBER: |
---|
1493 | case ASM_INPUT: |
---|
1494 | case ADDR_VEC: |
---|
1495 | case ADDR_DIFF_VEC: |
---|
1496 | return 0; |
---|
1497 | |
---|
1498 | case CALL: |
---|
1499 | case UNSPEC_VOLATILE: |
---|
1500 | /* case TRAP_IF: This isn't clear yet. */ |
---|
1501 | return 1; |
---|
1502 | |
---|
1503 | case MEM: |
---|
1504 | case ASM_OPERANDS: |
---|
1505 | if (MEM_VOLATILE_P (x)) |
---|
1506 | return 1; |
---|
1507 | |
---|
1508 | default: |
---|
1509 | break; |
---|
1510 | } |
---|
1511 | |
---|
1512 | /* Recursively scan the operands of this expression. */ |
---|
1513 | |
---|
1514 | { |
---|
1515 | register char *fmt = GET_RTX_FORMAT (code); |
---|
1516 | register int i; |
---|
1517 | |
---|
1518 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
1519 | { |
---|
1520 | if (fmt[i] == 'e') |
---|
1521 | { |
---|
1522 | if (volatile_refs_p (XEXP (x, i))) |
---|
1523 | return 1; |
---|
1524 | } |
---|
1525 | if (fmt[i] == 'E') |
---|
1526 | { |
---|
1527 | register int j; |
---|
1528 | for (j = 0; j < XVECLEN (x, i); j++) |
---|
1529 | if (volatile_refs_p (XVECEXP (x, i, j))) |
---|
1530 | return 1; |
---|
1531 | } |
---|
1532 | } |
---|
1533 | } |
---|
1534 | return 0; |
---|
1535 | } |
---|
1536 | |
---|
1537 | /* Similar to above, except that it also rejects register pre- and post- |
---|
1538 | incrementing. */ |
---|
1539 | |
---|
1540 | int |
---|
1541 | side_effects_p (x) |
---|
1542 | rtx x; |
---|
1543 | { |
---|
1544 | register RTX_CODE code; |
---|
1545 | |
---|
1546 | code = GET_CODE (x); |
---|
1547 | switch (code) |
---|
1548 | { |
---|
1549 | case LABEL_REF: |
---|
1550 | case SYMBOL_REF: |
---|
1551 | case CONST_INT: |
---|
1552 | case CONST: |
---|
1553 | case CONST_DOUBLE: |
---|
1554 | case CC0: |
---|
1555 | case PC: |
---|
1556 | case REG: |
---|
1557 | case SCRATCH: |
---|
1558 | case ASM_INPUT: |
---|
1559 | case ADDR_VEC: |
---|
1560 | case ADDR_DIFF_VEC: |
---|
1561 | return 0; |
---|
1562 | |
---|
1563 | case CLOBBER: |
---|
1564 | /* Reject CLOBBER with a non-VOID mode. These are made by combine.c |
---|
1565 | when some combination can't be done. If we see one, don't think |
---|
1566 | that we can simplify the expression. */ |
---|
1567 | return (GET_MODE (x) != VOIDmode); |
---|
1568 | |
---|
1569 | case PRE_INC: |
---|
1570 | case PRE_DEC: |
---|
1571 | case POST_INC: |
---|
1572 | case POST_DEC: |
---|
1573 | case CALL: |
---|
1574 | case UNSPEC_VOLATILE: |
---|
1575 | /* case TRAP_IF: This isn't clear yet. */ |
---|
1576 | return 1; |
---|
1577 | |
---|
1578 | case MEM: |
---|
1579 | case ASM_OPERANDS: |
---|
1580 | if (MEM_VOLATILE_P (x)) |
---|
1581 | return 1; |
---|
1582 | |
---|
1583 | default: |
---|
1584 | break; |
---|
1585 | } |
---|
1586 | |
---|
1587 | /* Recursively scan the operands of this expression. */ |
---|
1588 | |
---|
1589 | { |
---|
1590 | register char *fmt = GET_RTX_FORMAT (code); |
---|
1591 | register int i; |
---|
1592 | |
---|
1593 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
1594 | { |
---|
1595 | if (fmt[i] == 'e') |
---|
1596 | { |
---|
1597 | if (side_effects_p (XEXP (x, i))) |
---|
1598 | return 1; |
---|
1599 | } |
---|
1600 | if (fmt[i] == 'E') |
---|
1601 | { |
---|
1602 | register int j; |
---|
1603 | for (j = 0; j < XVECLEN (x, i); j++) |
---|
1604 | if (side_effects_p (XVECEXP (x, i, j))) |
---|
1605 | return 1; |
---|
1606 | } |
---|
1607 | } |
---|
1608 | } |
---|
1609 | return 0; |
---|
1610 | } |
---|
1611 | |
---|
1612 | /* Return nonzero if evaluating rtx X might cause a trap. */ |
---|
1613 | |
---|
1614 | int |
---|
1615 | may_trap_p (x) |
---|
1616 | rtx x; |
---|
1617 | { |
---|
1618 | int i; |
---|
1619 | enum rtx_code code; |
---|
1620 | char *fmt; |
---|
1621 | |
---|
1622 | if (x == 0) |
---|
1623 | return 0; |
---|
1624 | code = GET_CODE (x); |
---|
1625 | switch (code) |
---|
1626 | { |
---|
1627 | /* Handle these cases quickly. */ |
---|
1628 | case CONST_INT: |
---|
1629 | case CONST_DOUBLE: |
---|
1630 | case SYMBOL_REF: |
---|
1631 | case LABEL_REF: |
---|
1632 | case CONST: |
---|
1633 | case PC: |
---|
1634 | case CC0: |
---|
1635 | case REG: |
---|
1636 | case SCRATCH: |
---|
1637 | return 0; |
---|
1638 | |
---|
1639 | /* Conditional trap can trap! */ |
---|
1640 | case UNSPEC_VOLATILE: |
---|
1641 | case TRAP_IF: |
---|
1642 | return 1; |
---|
1643 | |
---|
1644 | /* Memory ref can trap unless it's a static var or a stack slot. */ |
---|
1645 | case MEM: |
---|
1646 | return rtx_addr_can_trap_p (XEXP (x, 0)); |
---|
1647 | |
---|
1648 | /* Division by a non-constant might trap. */ |
---|
1649 | case DIV: |
---|
1650 | case MOD: |
---|
1651 | case UDIV: |
---|
1652 | case UMOD: |
---|
1653 | if (! CONSTANT_P (XEXP (x, 1)) |
---|
1654 | || GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) |
---|
1655 | return 1; |
---|
1656 | /* This was const0_rtx, but by not using that, |
---|
1657 | we can link this file into other programs. */ |
---|
1658 | if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 0) |
---|
1659 | return 1; |
---|
1660 | break; |
---|
1661 | |
---|
1662 | case EXPR_LIST: |
---|
1663 | /* An EXPR_LIST is used to represent a function call. This |
---|
1664 | certainly may trap. */ |
---|
1665 | return 1; |
---|
1666 | |
---|
1667 | default: |
---|
1668 | /* Any floating arithmetic may trap. */ |
---|
1669 | if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) |
---|
1670 | return 1; |
---|
1671 | } |
---|
1672 | |
---|
1673 | fmt = GET_RTX_FORMAT (code); |
---|
1674 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
1675 | { |
---|
1676 | if (fmt[i] == 'e') |
---|
1677 | { |
---|
1678 | if (may_trap_p (XEXP (x, i))) |
---|
1679 | return 1; |
---|
1680 | } |
---|
1681 | else if (fmt[i] == 'E') |
---|
1682 | { |
---|
1683 | register int j; |
---|
1684 | for (j = 0; j < XVECLEN (x, i); j++) |
---|
1685 | if (may_trap_p (XVECEXP (x, i, j))) |
---|
1686 | return 1; |
---|
1687 | } |
---|
1688 | } |
---|
1689 | return 0; |
---|
1690 | } |
---|
1691 | |
---|
1692 | /* Return nonzero if X contains a comparison that is not either EQ or NE, |
---|
1693 | i.e., an inequality. */ |
---|
1694 | |
---|
1695 | int |
---|
1696 | inequality_comparisons_p (x) |
---|
1697 | rtx x; |
---|
1698 | { |
---|
1699 | register char *fmt; |
---|
1700 | register int len, i; |
---|
1701 | register enum rtx_code code = GET_CODE (x); |
---|
1702 | |
---|
1703 | switch (code) |
---|
1704 | { |
---|
1705 | case REG: |
---|
1706 | case SCRATCH: |
---|
1707 | case PC: |
---|
1708 | case CC0: |
---|
1709 | case CONST_INT: |
---|
1710 | case CONST_DOUBLE: |
---|
1711 | case CONST: |
---|
1712 | case LABEL_REF: |
---|
1713 | case SYMBOL_REF: |
---|
1714 | return 0; |
---|
1715 | |
---|
1716 | case LT: |
---|
1717 | case LTU: |
---|
1718 | case GT: |
---|
1719 | case GTU: |
---|
1720 | case LE: |
---|
1721 | case LEU: |
---|
1722 | case GE: |
---|
1723 | case GEU: |
---|
1724 | return 1; |
---|
1725 | |
---|
1726 | default: |
---|
1727 | break; |
---|
1728 | } |
---|
1729 | |
---|
1730 | len = GET_RTX_LENGTH (code); |
---|
1731 | fmt = GET_RTX_FORMAT (code); |
---|
1732 | |
---|
1733 | for (i = 0; i < len; i++) |
---|
1734 | { |
---|
1735 | if (fmt[i] == 'e') |
---|
1736 | { |
---|
1737 | if (inequality_comparisons_p (XEXP (x, i))) |
---|
1738 | return 1; |
---|
1739 | } |
---|
1740 | else if (fmt[i] == 'E') |
---|
1741 | { |
---|
1742 | register int j; |
---|
1743 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) |
---|
1744 | if (inequality_comparisons_p (XVECEXP (x, i, j))) |
---|
1745 | return 1; |
---|
1746 | } |
---|
1747 | } |
---|
1748 | |
---|
1749 | return 0; |
---|
1750 | } |
---|
1751 | |
---|
1752 | /* Replace any occurrence of FROM in X with TO. |
---|
1753 | |
---|
1754 | Note that copying is not done so X must not be shared unless all copies |
---|
1755 | are to be modified. */ |
---|
1756 | |
---|
1757 | rtx |
---|
1758 | replace_rtx (x, from, to) |
---|
1759 | rtx x, from, to; |
---|
1760 | { |
---|
1761 | register int i, j; |
---|
1762 | register char *fmt; |
---|
1763 | |
---|
1764 | if (x == from) |
---|
1765 | return to; |
---|
1766 | |
---|
1767 | /* Allow this function to make replacements in EXPR_LISTs. */ |
---|
1768 | if (x == 0) |
---|
1769 | return 0; |
---|
1770 | |
---|
1771 | fmt = GET_RTX_FORMAT (GET_CODE (x)); |
---|
1772 | for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) |
---|
1773 | { |
---|
1774 | if (fmt[i] == 'e') |
---|
1775 | XEXP (x, i) = replace_rtx (XEXP (x, i), from, to); |
---|
1776 | else if (fmt[i] == 'E') |
---|
1777 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) |
---|
1778 | XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to); |
---|
1779 | } |
---|
1780 | |
---|
1781 | return x; |
---|
1782 | } |
---|
1783 | |
---|
1784 | /* Throughout the rtx X, replace many registers according to REG_MAP. |
---|
1785 | Return the replacement for X (which may be X with altered contents). |
---|
1786 | REG_MAP[R] is the replacement for register R, or 0 for don't replace. |
---|
1787 | NREGS is the length of REG_MAP; regs >= NREGS are not mapped. |
---|
1788 | |
---|
1789 | We only support REG_MAP entries of REG or SUBREG. Also, hard registers |
---|
1790 | should not be mapped to pseudos or vice versa since validate_change |
---|
1791 | is not called. |
---|
1792 | |
---|
1793 | If REPLACE_DEST is 1, replacements are also done in destinations; |
---|
1794 | otherwise, only sources are replaced. */ |
---|
1795 | |
---|
1796 | rtx |
---|
1797 | replace_regs (x, reg_map, nregs, replace_dest) |
---|
1798 | rtx x; |
---|
1799 | rtx *reg_map; |
---|
1800 | int nregs; |
---|
1801 | int replace_dest; |
---|
1802 | { |
---|
1803 | register enum rtx_code code; |
---|
1804 | register int i; |
---|
1805 | register char *fmt; |
---|
1806 | |
---|
1807 | if (x == 0) |
---|
1808 | return x; |
---|
1809 | |
---|
1810 | code = GET_CODE (x); |
---|
1811 | switch (code) |
---|
1812 | { |
---|
1813 | case SCRATCH: |
---|
1814 | case PC: |
---|
1815 | case CC0: |
---|
1816 | case CONST_INT: |
---|
1817 | case CONST_DOUBLE: |
---|
1818 | case CONST: |
---|
1819 | case SYMBOL_REF: |
---|
1820 | case LABEL_REF: |
---|
1821 | return x; |
---|
1822 | |
---|
1823 | case REG: |
---|
1824 | /* Verify that the register has an entry before trying to access it. */ |
---|
1825 | if (REGNO (x) < nregs && reg_map[REGNO (x)] != 0) |
---|
1826 | { |
---|
1827 | /* SUBREGs can't be shared. Always return a copy to ensure that if |
---|
1828 | this replacement occurs more than once then each instance will |
---|
1829 | get distinct rtx. */ |
---|
1830 | if (GET_CODE (reg_map[REGNO (x)]) == SUBREG) |
---|
1831 | return copy_rtx (reg_map[REGNO (x)]); |
---|
1832 | return reg_map[REGNO (x)]; |
---|
1833 | } |
---|
1834 | return x; |
---|
1835 | |
---|
1836 | case SUBREG: |
---|
1837 | /* Prevent making nested SUBREGs. */ |
---|
1838 | if (GET_CODE (SUBREG_REG (x)) == REG && REGNO (SUBREG_REG (x)) < nregs |
---|
1839 | && reg_map[REGNO (SUBREG_REG (x))] != 0 |
---|
1840 | && GET_CODE (reg_map[REGNO (SUBREG_REG (x))]) == SUBREG) |
---|
1841 | { |
---|
1842 | rtx map_val = reg_map[REGNO (SUBREG_REG (x))]; |
---|
1843 | rtx map_inner = SUBREG_REG (map_val); |
---|
1844 | |
---|
1845 | if (GET_MODE (x) == GET_MODE (map_inner)) |
---|
1846 | return map_inner; |
---|
1847 | else |
---|
1848 | { |
---|
1849 | /* We cannot call gen_rtx here since we may be linked with |
---|
1850 | genattrtab.c. */ |
---|
1851 | /* Let's try clobbering the incoming SUBREG and see |
---|
1852 | if this is really safe. */ |
---|
1853 | SUBREG_REG (x) = map_inner; |
---|
1854 | SUBREG_WORD (x) += SUBREG_WORD (map_val); |
---|
1855 | return x; |
---|
1856 | #if 0 |
---|
1857 | rtx new = rtx_alloc (SUBREG); |
---|
1858 | PUT_MODE (new, GET_MODE (x)); |
---|
1859 | SUBREG_REG (new) = map_inner; |
---|
1860 | SUBREG_WORD (new) = SUBREG_WORD (x) + SUBREG_WORD (map_val); |
---|
1861 | #endif |
---|
1862 | } |
---|
1863 | } |
---|
1864 | break; |
---|
1865 | |
---|
1866 | case SET: |
---|
1867 | if (replace_dest) |
---|
1868 | SET_DEST (x) = replace_regs (SET_DEST (x), reg_map, nregs, 0); |
---|
1869 | |
---|
1870 | else if (GET_CODE (SET_DEST (x)) == MEM |
---|
1871 | || GET_CODE (SET_DEST (x)) == STRICT_LOW_PART) |
---|
1872 | /* Even if we are not to replace destinations, replace register if it |
---|
1873 | is CONTAINED in destination (destination is memory or |
---|
1874 | STRICT_LOW_PART). */ |
---|
1875 | XEXP (SET_DEST (x), 0) = replace_regs (XEXP (SET_DEST (x), 0), |
---|
1876 | reg_map, nregs, 0); |
---|
1877 | else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT) |
---|
1878 | /* Similarly, for ZERO_EXTRACT we replace all operands. */ |
---|
1879 | break; |
---|
1880 | |
---|
1881 | SET_SRC (x) = replace_regs (SET_SRC (x), reg_map, nregs, 0); |
---|
1882 | return x; |
---|
1883 | |
---|
1884 | default: |
---|
1885 | break; |
---|
1886 | } |
---|
1887 | |
---|
1888 | fmt = GET_RTX_FORMAT (code); |
---|
1889 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
1890 | { |
---|
1891 | if (fmt[i] == 'e') |
---|
1892 | XEXP (x, i) = replace_regs (XEXP (x, i), reg_map, nregs, replace_dest); |
---|
1893 | if (fmt[i] == 'E') |
---|
1894 | { |
---|
1895 | register int j; |
---|
1896 | for (j = 0; j < XVECLEN (x, i); j++) |
---|
1897 | XVECEXP (x, i, j) = replace_regs (XVECEXP (x, i, j), reg_map, |
---|
1898 | nregs, replace_dest); |
---|
1899 | } |
---|
1900 | } |
---|
1901 | return x; |
---|
1902 | } |
---|
1903 | |
---|
1904 | /* Return 1 if X, the SRC_SRC of SET of (pc) contain a REG or MEM that is |
---|
1905 | not in the constant pool and not in the condition of an IF_THEN_ELSE. */ |
---|
1906 | |
---|
1907 | static int |
---|
1908 | jmp_uses_reg_or_mem (x) |
---|
1909 | rtx x; |
---|
1910 | { |
---|
1911 | enum rtx_code code = GET_CODE (x); |
---|
1912 | int i, j; |
---|
1913 | char *fmt; |
---|
1914 | |
---|
1915 | switch (code) |
---|
1916 | { |
---|
1917 | case CONST: |
---|
1918 | case LABEL_REF: |
---|
1919 | case PC: |
---|
1920 | return 0; |
---|
1921 | |
---|
1922 | case REG: |
---|
1923 | return 1; |
---|
1924 | |
---|
1925 | case MEM: |
---|
1926 | return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF |
---|
1927 | && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0))); |
---|
1928 | |
---|
1929 | case IF_THEN_ELSE: |
---|
1930 | return (jmp_uses_reg_or_mem (XEXP (x, 1)) |
---|
1931 | || jmp_uses_reg_or_mem (XEXP (x, 2))); |
---|
1932 | |
---|
1933 | case PLUS: case MINUS: case MULT: |
---|
1934 | return (jmp_uses_reg_or_mem (XEXP (x, 0)) |
---|
1935 | || jmp_uses_reg_or_mem (XEXP (x, 1))); |
---|
1936 | } |
---|
1937 | |
---|
1938 | fmt = GET_RTX_FORMAT (code); |
---|
1939 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
---|
1940 | { |
---|
1941 | if (fmt[i] == 'e' |
---|
1942 | && jmp_uses_reg_or_mem (XEXP (x, i))) |
---|
1943 | return 1; |
---|
1944 | |
---|
1945 | if (fmt[i] == 'E') |
---|
1946 | for (j = 0; j < XVECLEN (x, i); j++) |
---|
1947 | if (jmp_uses_reg_or_mem (XVECEXP (x, i, j))) |
---|
1948 | return 1; |
---|
1949 | } |
---|
1950 | |
---|
1951 | return 0; |
---|
1952 | } |
---|
1953 | |
---|
1954 | /* Return nonzero if INSN is an indirect jump (aka computed jump). |
---|
1955 | |
---|
1956 | Tablejumps and casesi insns are not considered indirect jumps; |
---|
1957 | we can recognize them by a (use (lael_ref)). */ |
---|
1958 | |
---|
1959 | int |
---|
1960 | computed_jump_p (insn) |
---|
1961 | rtx insn; |
---|
1962 | { |
---|
1963 | int i; |
---|
1964 | if (GET_CODE (insn) == JUMP_INSN) |
---|
1965 | { |
---|
1966 | rtx pat = PATTERN (insn); |
---|
1967 | int computed_jump = 0; |
---|
1968 | |
---|
1969 | if (GET_CODE (pat) == PARALLEL) |
---|
1970 | { |
---|
1971 | int len = XVECLEN (pat, 0); |
---|
1972 | int has_use_labelref = 0; |
---|
1973 | |
---|
1974 | for (i = len - 1; i >= 0; i--) |
---|
1975 | if (GET_CODE (XVECEXP (pat, 0, i)) == USE |
---|
1976 | && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0)) |
---|
1977 | == LABEL_REF)) |
---|
1978 | has_use_labelref = 1; |
---|
1979 | |
---|
1980 | if (! has_use_labelref) |
---|
1981 | for (i = len - 1; i >= 0; i--) |
---|
1982 | if (GET_CODE (XVECEXP (pat, 0, i)) == SET |
---|
1983 | && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx |
---|
1984 | && jmp_uses_reg_or_mem (SET_SRC (XVECEXP (pat, 0, i)))) |
---|
1985 | return 1; |
---|
1986 | } |
---|
1987 | else if (GET_CODE (pat) == SET |
---|
1988 | && SET_DEST (pat) == pc_rtx |
---|
1989 | && jmp_uses_reg_or_mem (SET_SRC (pat))) |
---|
1990 | return 1; |
---|
1991 | } |
---|
1992 | return 0; |
---|
1993 | } |
---|