|
|
1.1 root 1: /* Data flow analysis for GNU compiler.
1.1.1.2 root 2: Copyright (C) 1987, 1988 Free Software Foundation, Inc.
1.1 root 3:
4: This file is part of GNU CC.
5:
1.1.1.12 root 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 1, or (at your option)
9: any later version.
10:
1.1 root 11: GNU CC is distributed in the hope that it will be useful,
1.1.1.12 root 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
1.1 root 19:
20:
21: /* This file contains the data flow analysis pass of the compiler.
22: It computes data flow information
23: which tells combine_instructions which insns to consider combining
24: and controls register allocation.
25:
26: Additional data flow information that is too bulky to record
27: is generated during the analysis, and is used at that time to
28: create autoincrement and autodecrement addressing.
29:
30: The first step is dividing the function into basic blocks.
31: find_basic_blocks does this. Then life_analysis determines
32: where each register is live and where it is dead.
33:
34: ** find_basic_blocks **
35:
36: find_basic_blocks divides the current function's rtl
37: into basic blocks. It records the beginnings and ends of the
38: basic blocks in the vectors basic_block_head and basic_block_end,
39: and the number of blocks in n_basic_blocks.
40:
41: find_basic_blocks also finds any unreachable loops
42: and deletes them.
43:
44: ** life_analysis **
45:
46: life_analysis is called immediately after find_basic_blocks.
47: It uses the basic block information to determine where each
48: hard or pseudo register is live.
49:
50: ** live-register info **
51:
52: The information about where each register is live is in two parts:
53: the REG_NOTES of insns, and the vector basic_block_live_at_start.
54:
55: basic_block_live_at_start has an element for each basic block,
56: and the element is a bit-vector with a bit for each hard or pseudo
57: register. The bit is 1 if the register is live at the beginning
58: of the basic block.
59:
60: To each insn's REG_NOTES is added an element for each register
61: that is live before the insn or set by the insn, but is dead
62: after the insn.
63:
64: To determine which registers are live after any insn, one can
65: start from the beginning of the basic block and scan insns, noting
66: which registers are set by each insn and which die there.
67:
68: ** Other actions of life_analysis **
69:
70: life_analysis sets up the LOG_LINKS fields of insns because the
71: information needed to do so is readily available.
72:
73: life_analysis deletes insns whose only effect is to store a value
74: that is never used.
75:
76: life_analysis notices cases where a reference to a register as
77: a memory address can be combined with a preceding or following
78: incrementation or decrementation of the register. The separate
79: instruction to increment or decrement is deleted and the address
80: is changed to a POST_INC or similar rtx.
81:
82: Each time an incrementing or decrementing address is created,
83: a REG_INC element is added to the insn's REG_NOTES list.
84:
85: life_analysis fills in certain vectors containing information about
86: register usage: reg_n_refs, reg_n_deaths, reg_n_sets,
87: reg_live_length, reg_crosses_call and reg_basic_block. */
88:
89: #include <stdio.h>
90: #include "config.h"
91: #include "rtl.h"
92: #include "basic-block.h"
93: #include "regs.h"
1.1.1.2 root 94: #include "hard-reg-set.h"
95: #include "flags.h"
1.1 root 96:
97: /* Get the basic block number of an insn.
98: This info should not be expected to remain available
99: after the end of life_analysis. */
100:
101: #define BLOCK_NUM(INSN) uid_block_number[INSN_UID (INSN)]
102:
103: /* This is where the BLOCK_NUM values are really stored.
104: This is set up by find_basic_blocks and used there and in life_analysis,
105: and then freed. */
106:
107: static short *uid_block_number;
108:
1.1.1.2 root 109: /* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile. */
110:
111: #define INSN_VOLATILE(INSN) uid_volatile[INSN_UID (INSN)]
112: static char *uid_volatile;
113:
1.1 root 114: /* Number of basic blocks in the current function. */
115:
116: int n_basic_blocks;
117:
118: /* Maximum register number used in this function, plus one. */
119:
120: int max_regno;
121:
122: /* Indexed by n, gives number of basic block that (REG n) is used in.
1.1.1.10 root 123: If the value is REG_BLOCK_GLOBAL (-2),
124: it means (REG n) is used in more than one basic block.
125: REG_BLOCK_UNKNOWN (-1) means it hasn't been seen yet so we don't know.
1.1 root 126: This information remains valid for the rest of the compilation
127: of the current function; it is used to control register allocation. */
128:
129: short *reg_basic_block;
130:
131: /* Indexed by n, gives number of times (REG n) is used or set, each
132: weighted by its loop-depth.
133: This information remains valid for the rest of the compilation
134: of the current function; it is used to control register allocation. */
135:
136: short *reg_n_refs;
137:
138: /* Indexed by n, gives number of times (REG n) is set.
139: This information remains valid for the rest of the compilation
140: of the current function; it is used to control register allocation. */
141:
142: short *reg_n_sets;
143:
144: /* Indexed by N, gives number of places register N dies.
145: This information remains valid for the rest of the compilation
146: of the current function; it is used to control register allocation. */
147:
148: short *reg_n_deaths;
149:
150: /* Indexed by N, gives 1 if that reg is live across any CALL_INSNs.
151: This information remains valid for the rest of the compilation
152: of the current function; it is used to control register allocation. */
153:
1.1.1.12 root 154: int *reg_n_calls_crossed;
1.1 root 155:
156: /* Total number of instructions at which (REG n) is live.
157: The larger this is, the less priority (REG n) gets for
158: allocation in a real register.
159: This information remains valid for the rest of the compilation
1.1.1.2 root 160: of the current function; it is used to control register allocation.
161:
162: local-alloc.c may alter this number to change the priority.
163:
164: Negative values are special.
165: -1 is used to mark a pseudo reg which has a constant or memory equivalent
166: and is used infrequently enough that it should not get a hard register.
167: -2 is used to mark a pseudo reg for a parameter, when a frame pointer
168: is not required. global-alloc.c makes an allocno for this but does
169: not try to assign a hard register to it. */
1.1 root 170:
171: int *reg_live_length;
172:
173: /* Element N is the next insn that uses (hard or pseudo) register number N
174: within the current basic block; or zero, if there is no such insn.
175: This is valid only during the final backward scan in propagate_block. */
176:
177: static rtx *reg_next_use;
178:
179: /* Size of a regset for the current function,
180: in (1) bytes and (2) elements. */
181:
182: int regset_bytes;
183: int regset_size;
184:
185: /* Element N is first insn in basic block N.
186: This info lasts until we finish compiling the function. */
187:
188: rtx *basic_block_head;
189:
190: /* Element N is last insn in basic block N.
191: This info lasts until we finish compiling the function. */
192:
193: rtx *basic_block_end;
194:
195: /* Element N is a regset describing the registers live
196: at the start of basic block N.
197: This info lasts until we finish compiling the function. */
198:
199: regset *basic_block_live_at_start;
200:
1.1.1.2 root 201: /* Regset of regs live when calls to `setjmp'-like functions happen. */
202:
203: regset regs_live_at_setjmp;
204:
1.1 root 205: /* Element N is nonzero if control can drop into basic block N
206: from the preceding basic block. Freed after life_analysis. */
207:
1.1.1.2 root 208: static char *basic_block_drops_in;
1.1 root 209:
210: /* Element N is depth within loops of basic block number N.
211: Freed after life_analysis. */
212:
1.1.1.2 root 213: static short *basic_block_loop_depth;
1.1 root 214:
215: /* Element N nonzero if basic block N can actually be reached.
216: Vector exists only during find_basic_blocks. */
217:
1.1.1.2 root 218: static char *block_live_static;
1.1 root 219:
220: /* Depth within loops of basic block being scanned for lifetime analysis,
221: plus one. This is the weight attached to references to registers. */
222:
1.1.1.2 root 223: static int loop_depth;
224:
225: /* Define AUTO_INC_DEC if machine has any kind of incrementing
226: or decrementing addressing. */
227:
228: #ifdef HAVE_PRE_DECREMENT
229: #define AUTO_INC_DEC
230: #endif
231:
232: #ifdef HAVE_PRE_INCREMENT
233: #define AUTO_INC_DEC
234: #endif
235:
236: #ifdef HAVE_POST_DECREMENT
237: #define AUTO_INC_DEC
238: #endif
239:
240: #ifdef HAVE_POST_INCREMENT
241: #define AUTO_INC_DEC
242: #endif
1.1 root 243:
244: /* Forward declarations */
245: static void find_basic_blocks ();
246: static void life_analysis ();
247: static void mark_label_ref ();
248: void allocate_for_life_analysis (); /* Used also in stupid_life_analysis */
249: static void init_regset_vector ();
250: static void propagate_block ();
251: static void mark_set_regs ();
252: static void mark_used_regs ();
253: static int insn_dead_p ();
1.1.1.10 root 254: static int libcall_dead_p ();
1.1 root 255: static int try_pre_increment ();
256: static int try_pre_increment_1 ();
257: static rtx find_use_as_address ();
1.1.1.2 root 258: void dump_flow_info ();
1.1 root 259:
260: /* Find basic blocks of the current function and perform data flow analysis.
261: F is the first insn of the function and NREGS the number of register numbers
262: in use. */
263:
264: void
265: flow_analysis (f, nregs, file)
266: rtx f;
267: int nregs;
268: FILE *file;
269: {
270: register rtx insn;
271: register int i;
272: register int max_uid = 0;
273:
274: /* Count the basic blocks. Also find maximum insn uid value used. */
275:
276: {
277: register RTX_CODE prev_code = JUMP_INSN;
278: register RTX_CODE code;
279:
280: for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
281: {
282: code = GET_CODE (insn);
283: if (INSN_UID (insn) > max_uid)
284: max_uid = INSN_UID (insn);
285: if (code == CODE_LABEL
286: || (prev_code != INSN && prev_code != CALL_INSN
287: && prev_code != CODE_LABEL
288: && (code == INSN || code == CALL_INSN || code == JUMP_INSN)))
289: i++;
290: if (code != NOTE)
291: prev_code = code;
292: }
293: }
294:
295: /* Allocate some tables that last till end of compiling this function
296: and some needed only in find_basic_blocks and life_analysis. */
297:
298: n_basic_blocks = i;
299: basic_block_head = (rtx *) oballoc (n_basic_blocks * sizeof (rtx));
300: basic_block_end = (rtx *) oballoc (n_basic_blocks * sizeof (rtx));
301: basic_block_drops_in = (char *) alloca (n_basic_blocks);
302: basic_block_loop_depth = (short *) alloca (n_basic_blocks * sizeof (short));
303: uid_block_number = (short *) alloca ((max_uid + 1) * sizeof (short));
1.1.1.2 root 304: uid_volatile = (char *) alloca (max_uid + 1);
305: bzero (uid_volatile, max_uid + 1);
1.1 root 306:
307: find_basic_blocks (f);
308: life_analysis (f, nregs);
309: if (file)
310: dump_flow_info (file);
311:
312: basic_block_drops_in = 0;
313: uid_block_number = 0;
314: basic_block_loop_depth = 0;
315: }
316:
317: /* Find all basic blocks of the function whose first insn is F.
318: Store the correct data in the tables that describe the basic blocks,
319: set up the chains of references for each CODE_LABEL, and
320: delete any entire basic blocks that cannot be reached. */
321:
322: static void
323: find_basic_blocks (f)
324: rtx f;
325: {
326: register rtx insn;
327: register int i;
328:
329: /* Initialize the ref chain of each label to 0. */
330: /* Record where all the blocks start and end and their depth in loops. */
331: /* For each insn, record the block it is in. */
332:
333: {
334: register RTX_CODE prev_code = JUMP_INSN;
335: register RTX_CODE code;
336: int depth = 1;
337:
338: for (insn = f, i = -1; insn; insn = NEXT_INSN (insn))
339: {
340: code = GET_CODE (insn);
341: if (code == NOTE)
342: {
343: if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
344: depth++;
345: else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
346: depth--;
347: }
348: else if (code == CODE_LABEL
349: || (prev_code != INSN && prev_code != CALL_INSN
350: && prev_code != CODE_LABEL
351: && (code == INSN || code == CALL_INSN || code == JUMP_INSN)))
352: {
353: basic_block_head[++i] = insn;
354: basic_block_end[i] = insn;
355: basic_block_loop_depth[i] = depth;
356: if (code == CODE_LABEL)
357: LABEL_REFS (insn) = insn;
358: }
359: else if (code == INSN || code == CALL_INSN || code == JUMP_INSN)
360: basic_block_end[i] = insn;
361: BLOCK_NUM (insn) = i;
362: if (code != NOTE)
363: prev_code = code;
364: }
1.1.1.4 root 365: if (i + 1 != n_basic_blocks)
366: abort ();
1.1 root 367: }
368:
369: /* Record which basic blocks control can drop in to. */
370:
371: {
372: register int i;
373: for (i = 0; i < n_basic_blocks; i++)
374: {
375: register rtx insn = PREV_INSN (basic_block_head[i]);
1.1.1.2 root 376: /* TEMP1 is used to avoid a bug in Sequent's compiler. */
377: register int temp1;
1.1 root 378: while (insn && GET_CODE (insn) == NOTE)
379: insn = PREV_INSN (insn);
1.1.1.2 root 380: temp1 = insn && GET_CODE (insn) != BARRIER;
381: basic_block_drops_in[i] = temp1;
1.1 root 382: }
383: }
384:
385: /* Now find which basic blocks can actually be reached
386: and put all jump insns' LABEL_REFS onto the ref-chains
387: of their target labels. */
388:
389: if (n_basic_blocks > 0)
390: {
391: register char *block_live = (char *) alloca (n_basic_blocks);
392: register char *block_marked = (char *) alloca (n_basic_blocks);
393: int something_marked = 1;
394:
395: /* Initialize with just block 0 reachable and no blocks marked. */
396:
397: bzero (block_live, n_basic_blocks);
398: bzero (block_marked, n_basic_blocks);
399: block_live[0] = 1;
400: block_live_static = block_live;
401:
402: /* Pass over all blocks, marking each block that is reachable
403: and has not yet been marked.
404: Keep doing this until, in one pass, no blocks have been marked.
405: Then blocks_live and blocks_marked are identical and correct.
406: In addition, all jumps actually reachable have been marked. */
407:
408: while (something_marked)
409: {
410: something_marked = 0;
411: for (i = 0; i < n_basic_blocks; i++)
412: if (block_live[i] && !block_marked[i])
413: {
414: block_marked[i] = 1;
415: something_marked = 1;
416: if (i + 1 < n_basic_blocks && basic_block_drops_in[i + 1])
417: block_live[i + 1] = 1;
418: insn = basic_block_end[i];
419: if (GET_CODE (insn) == JUMP_INSN)
420: mark_label_ref (PATTERN (insn), insn, 0);
421: }
422: }
423:
424: /* Now delete the code for any basic blocks that can't be reached.
425: They can occur because jump_optimize does not recognize
426: unreachable loops as unreachable. */
427:
428: for (i = 0; i < n_basic_blocks; i++)
429: if (!block_live[i])
430: {
431: insn = basic_block_head[i];
432: while (1)
433: {
1.1.1.2 root 434: if (GET_CODE (insn) == BARRIER)
435: abort ();
1.1 root 436: if (GET_CODE (insn) != NOTE)
437: {
438: PUT_CODE (insn, NOTE);
439: NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
440: NOTE_SOURCE_FILE (insn) = 0;
441: }
442: if (insn == basic_block_end[i])
1.1.1.2 root 443: {
444: /* BARRIERs are between basic blocks, not part of one.
445: Delete a BARRIER if the preceding jump is deleted.
446: We cannot alter a BARRIER into a NOTE
447: because it is too short; but we can really delete
448: it because it is not part of a basic block. */
449: if (NEXT_INSN (insn) != 0
450: && GET_CODE (NEXT_INSN (insn)) == BARRIER)
451: delete_insn (NEXT_INSN (insn));
452: break;
453: }
1.1 root 454: insn = NEXT_INSN (insn);
455: }
456: /* Each time we delete some basic blocks,
457: see if there is a jump around them that is
458: being turned into a no-op. If so, delete it. */
459:
460: if (block_live[i - 1])
461: {
462: register int j;
463: for (j = i; j < n_basic_blocks; j++)
464: if (block_live[j])
465: {
1.1.1.6 root 466: rtx label;
1.1 root 467: insn = basic_block_end[i - 1];
468: if (GET_CODE (insn) == JUMP_INSN
1.1.1.6 root 469: /* An unconditional jump is the only possibility
470: we must check for, since a conditional one
471: would make these blocks live. */
472: && simplejump_p (insn)
473: && (label = XEXP (SET_SRC (PATTERN (insn)), 0), 1)
474: && INSN_UID (label) != 0
475: && BLOCK_NUM (label) == j)
1.1 root 476: {
477: PUT_CODE (insn, NOTE);
478: NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
479: NOTE_SOURCE_FILE (insn) = 0;
1.1.1.2 root 480: if (GET_CODE (NEXT_INSN (insn)) != BARRIER)
481: abort ();
482: delete_insn (NEXT_INSN (insn));
1.1 root 483: }
484: break;
485: }
486: }
487: }
488: }
489: }
490:
491: /* Check expression X for label references;
492: if one is found, add INSN to the label's chain of references.
493:
494: CHECKDUP means check for and avoid creating duplicate references
495: from the same insn. Such duplicates do no serious harm but
496: can slow life analysis. CHECKDUP is set only when duplicates
497: are likely. */
498:
499: static void
500: mark_label_ref (x, insn, checkdup)
501: rtx x, insn;
502: int checkdup;
503: {
504: register RTX_CODE code = GET_CODE (x);
505: register int i;
506: register char *fmt;
507:
508: if (code == LABEL_REF)
509: {
510: register rtx label = XEXP (x, 0);
511: register rtx y;
512: if (GET_CODE (label) != CODE_LABEL)
1.1.1.4 root 513: abort ();
1.1.1.2 root 514: /* If the label was never emitted, this insn is junk,
515: but avoid a crash trying to refer to BLOCK_NUM (label).
516: This can happen as a result of a syntax error
517: and a diagnostic has already been printed. */
518: if (INSN_UID (label) == 0)
519: return;
1.1 root 520: CONTAINING_INSN (x) = insn;
521: /* if CHECKDUP is set, check for duplicate ref from same insn
522: and don't insert. */
523: if (checkdup)
524: for (y = LABEL_REFS (label); y != label; y = LABEL_NEXTREF (y))
525: if (CONTAINING_INSN (y) == insn)
526: return;
527: LABEL_NEXTREF (x) = LABEL_REFS (label);
528: LABEL_REFS (label) = x;
529: block_live_static[BLOCK_NUM (label)] = 1;
530: return;
531: }
532:
533: fmt = GET_RTX_FORMAT (code);
534: for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
535: {
536: if (fmt[i] == 'e')
537: mark_label_ref (XEXP (x, i), insn, 0);
538: if (fmt[i] == 'E')
539: {
540: register int j;
541: for (j = 0; j < XVECLEN (x, i); j++)
542: mark_label_ref (XVECEXP (x, i, j), insn, 1);
543: }
544: }
545: }
546:
547: /* Determine the which registers are live at the start of each
548: basic block of the function whose first insn is F.
549: NREGS is the number of registers used in F.
550: We allocate the vector basic_block_live_at_start
551: and the regsets that it points to, and fill them with the data.
552: regset_size and regset_bytes are also set here. */
553:
554: static void
555: life_analysis (f, nregs)
556: rtx f;
557: int nregs;
558: {
559: register regset tem;
560: int first_pass;
561: int changed;
562: /* For each basic block, a bitmask of regs
563: live on exit from the block. */
564: regset *basic_block_live_at_end;
565: /* For each basic block, a bitmask of regs
566: live on entry to a successor-block of this block.
567: If this does not match basic_block_live_at_end,
568: that must be updated, and the block must be rescanned. */
569: regset *basic_block_new_live_at_end;
570: /* For each basic block, a bitmask of regs
571: whose liveness at the end of the basic block
572: can make a difference in which regs are live on entry to the block.
573: These are the regs that are set within the basic block,
574: possibly excluding those that are used after they are set. */
575: regset *basic_block_significant;
576: register int i;
1.1.1.2 root 577: rtx insn;
1.1 root 578:
579: max_regno = nregs;
580:
581: bzero (regs_ever_live, sizeof regs_ever_live);
582:
583: /* Allocate and zero out many data structures
584: that will record the data from lifetime analysis. */
585:
586: allocate_for_life_analysis ();
587:
588: reg_next_use = (rtx *) alloca (nregs * sizeof (rtx));
589: bzero (reg_next_use, nregs * sizeof (rtx));
590:
591: /* Set up several regset-vectors used internally within this function.
592: Their meanings are documented above, with their declarations. */
593:
594: basic_block_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset));
595: tem = (regset) alloca (n_basic_blocks * regset_bytes);
596: bzero (tem, n_basic_blocks * regset_bytes);
597: init_regset_vector (basic_block_live_at_end, tem, n_basic_blocks, regset_bytes);
598:
599: basic_block_new_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset));
600: tem = (regset) alloca (n_basic_blocks * regset_bytes);
601: bzero (tem, n_basic_blocks * regset_bytes);
602: init_regset_vector (basic_block_new_live_at_end, tem, n_basic_blocks, regset_bytes);
603:
604: basic_block_significant = (regset *) alloca (n_basic_blocks * sizeof (regset));
605: tem = (regset) alloca (n_basic_blocks * regset_bytes);
606: bzero (tem, n_basic_blocks * regset_bytes);
607: init_regset_vector (basic_block_significant, tem, n_basic_blocks, regset_bytes);
608:
1.1.1.4 root 609: /* Record which insns refer to any volatile memory
1.1.1.9 root 610: or for any reason can't be deleted just because they are dead stores.
611: Also, delete any insns that copy a register to itself. */
1.1.1.2 root 612:
613: for (insn = f; insn; insn = NEXT_INSN (insn))
1.1.1.4 root 614: {
615: enum rtx_code code1 = GET_CODE (insn);
616: if (code1 == CALL_INSN)
617: INSN_VOLATILE (insn) = 1;
618: else if (code1 == INSN || code1 == JUMP_INSN)
619: {
1.1.1.9 root 620: if (GET_CODE (PATTERN (insn)) == SET
621: && GET_CODE (SET_DEST (PATTERN (insn))) == REG
622: && GET_CODE (SET_SRC (PATTERN (insn))) == REG
623: && REGNO (SET_DEST (PATTERN (insn))) ==
624: REGNO (SET_SRC (PATTERN (insn))))
625: {
626: PUT_CODE (insn, NOTE);
627: NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
628: NOTE_SOURCE_FILE (insn) = 0;
629: }
630: else if (GET_CODE (PATTERN (insn)) != USE)
1.1.1.4 root 631: INSN_VOLATILE (insn) = volatile_refs_p (PATTERN (insn));
632: }
1.1.1.6 root 633: /* A SET that makes space on the stack cannot be dead.
1.1.1.10 root 634: (Such SETs occur only for allocating variable-size data,
635: so they will always have a PLUS or MINUS according to the
636: direction of stack growth.)
1.1.1.6 root 637: Even if this function never uses this stack pointer value,
638: signal handlers do! */
639: else if (code1 == INSN && GET_CODE (PATTERN (insn)) == SET
640: && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
641: #ifdef STACK_GROWS_DOWNWARD
642: && GET_CODE (SET_SRC (PATTERN (insn))) == MINUS
643: #else
644: && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
645: #endif
646: && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx)
647: INSN_VOLATILE (insn) = 1;
1.1.1.4 root 648: }
1.1.1.2 root 649:
650: if (n_basic_blocks > 0)
651: #ifdef EXIT_IGNORE_STACK
652: if (! (EXIT_IGNORE_STACK) || ! frame_pointer_needed)
653: #endif
654: {
655: /* If exiting needs the right stack value,
656: consider the stack pointer live at the end of the function. */
657: basic_block_live_at_end[n_basic_blocks - 1]
658: [STACK_POINTER_REGNUM / REGSET_ELT_BITS]
659: |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
660: basic_block_new_live_at_end[n_basic_blocks - 1]
661: [STACK_POINTER_REGNUM / REGSET_ELT_BITS]
662: |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
663: }
664:
1.1 root 665: /* Propagate life info through the basic blocks
666: around the graph of basic blocks.
667:
668: This is a relaxation process: each time a new register
669: is live at the end of the basic block, we must scan the block
670: to determine which registers are, as a consequence, live at the beginning
671: of that block. These registers must then be marked live at the ends
672: of all the blocks that can transfer control to that block.
673: The process continues until it reaches a fixed point. */
674:
675: first_pass = 1;
676: changed = 1;
677: while (changed)
678: {
679: changed = 0;
680: for (i = n_basic_blocks - 1; i >= 0; i--)
681: {
682: int consider = first_pass;
683: int must_rescan = first_pass;
684: register int j;
685:
686: /* Set CONSIDER if this block needs thinking about at all
687: (that is, if the regs live now at the end of it
688: are not the same as were live at the end of it when
689: we last thought about it).
690: Set must_rescan if it needs to be thought about
691: instruction by instruction (that is, if any additional
692: reg that is live at the end now but was not live there before
693: is one of the significant regs of this basic block). */
694:
695: for (j = 0; j < regset_size; j++)
696: {
697: register int x = basic_block_new_live_at_end[i][j]
698: & ~basic_block_live_at_end[i][j];
699: if (x)
700: consider = 1;
701: if (x & basic_block_significant[i][j])
702: {
703: must_rescan = 1;
704: consider = 1;
705: break;
706: }
707: }
708:
709: if (! consider)
710: continue;
711:
712: /* The live_at_start of this block may be changing,
713: so another pass will be required after this one. */
714: changed = 1;
715:
716: if (! must_rescan)
717: {
718: /* No complete rescan needed;
719: just record those variables newly known live at end
720: as live at start as well. */
721: for (j = 0; j < regset_size; j++)
722: {
723: register int x = basic_block_new_live_at_end[i][j]
724: & ~basic_block_live_at_end[i][j];
725: basic_block_live_at_start[i][j] |= x;
726: basic_block_live_at_end[i][j] |= x;
727: }
728: }
729: else
730: {
731: /* Update the basic_block_live_at_start
732: by propagation backwards through the block. */
733: bcopy (basic_block_new_live_at_end[i],
734: basic_block_live_at_end[i], regset_bytes);
735: bcopy (basic_block_live_at_end[i],
736: basic_block_live_at_start[i], regset_bytes);
737: propagate_block (basic_block_live_at_start[i],
738: basic_block_head[i], basic_block_end[i], 0,
739: first_pass ? basic_block_significant[i] : 0,
740: i);
741: }
742:
743: {
744: register rtx jump, head;
745: /* Update the basic_block_new_live_at_end's of the block
746: that falls through into this one (if any). */
747: head = basic_block_head[i];
748: jump = PREV_INSN (head);
749: if (basic_block_drops_in[i])
750: {
751: register from_block = BLOCK_NUM (jump);
752: register int j;
753: for (j = 0; j < regset_size; j++)
754: basic_block_new_live_at_end[from_block][j]
755: |= basic_block_live_at_start[i][j];
756: }
757: /* Update the basic_block_new_live_at_end's of
758: all the blocks that jump to this one. */
759: if (GET_CODE (head) == CODE_LABEL)
760: for (jump = LABEL_REFS (head);
761: jump != head;
762: jump = LABEL_NEXTREF (jump))
763: {
764: register from_block = BLOCK_NUM (CONTAINING_INSN (jump));
765: register int j;
766: for (j = 0; j < regset_size; j++)
767: basic_block_new_live_at_end[from_block][j]
768: |= basic_block_live_at_start[i][j];
769: }
770: }
1.1.1.13! root 771: #ifdef USE_C_ALLOCA
! 772: alloca (0);
! 773: #endif
1.1 root 774: }
775: first_pass = 0;
776: }
777:
1.1.1.5 root 778: #if 0 /* This seems unnecessary; life at start of function shouldn't
779: mean that the reg is live in more than one basic block. */
780:
1.1.1.2 root 781: /* Process the regs live at the beginning of the function.
782: Mark them as not local to any one basic block. */
783:
784: if (n_basic_blocks > 0)
785: for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
786: if (basic_block_live_at_start[0][i / REGSET_ELT_BITS]
787: & (1 << (i % REGSET_ELT_BITS)))
1.1.1.4 root 788: reg_basic_block[i] = REG_BLOCK_GLOBAL;
1.1.1.5 root 789: #endif
1.1.1.2 root 790:
1.1 root 791: /* Now the life information is accurate.
792: Make one more pass over each basic block
793: to delete dead stores, create autoincrement addressing
794: and record how many times each register is used, is set, or dies.
795:
796: To save time, we operate directly in basic_block_live_at_end[i],
797: thus destroying it (in fact, converting it into a copy of
798: basic_block_live_at_start[i]). This is ok now because
799: basic_block_live_at_end[i] is no longer used past this point. */
800:
801: for (i = 0; i < n_basic_blocks; i++)
802: {
803: propagate_block (basic_block_live_at_end[i],
804: basic_block_head[i], basic_block_end[i], 1, 0, i);
1.1.1.13! root 805: #ifdef USE_C_ALLOCA
! 806: alloca (0);
! 807: #endif
1.1 root 808: }
809: }
810:
811: /* Subroutines of life analysis. */
812:
813: /* Allocate the permanent data structures that represent the results
814: of life analysis. Not static since used also for stupid life analysis. */
815:
816: void
817: allocate_for_life_analysis ()
818: {
819: register int i;
820: register regset tem;
821:
822: regset_size = ((max_regno + REGSET_ELT_BITS - 1) / REGSET_ELT_BITS);
823: regset_bytes = regset_size * sizeof (*(regset)0);
824:
825: reg_n_refs = (short *) oballoc (max_regno * sizeof (short));
826: bzero (reg_n_refs, max_regno * sizeof (short));
827:
828: reg_n_sets = (short *) oballoc (max_regno * sizeof (short));
829: bzero (reg_n_sets, max_regno * sizeof (short));
830:
831: reg_n_deaths = (short *) oballoc (max_regno * sizeof (short));
832: bzero (reg_n_deaths, max_regno * sizeof (short));
833:
834: reg_live_length = (int *) oballoc (max_regno * sizeof (int));
835: bzero (reg_live_length, max_regno * sizeof (int));
836:
1.1.1.12 root 837: reg_n_calls_crossed = (int *) oballoc (max_regno * sizeof (int));
838: bzero (reg_n_calls_crossed, max_regno * sizeof (int));
1.1 root 839:
840: reg_basic_block = (short *) oballoc (max_regno * sizeof (short));
841: for (i = 0; i < max_regno; i++)
1.1.1.4 root 842: reg_basic_block[i] = REG_BLOCK_UNKNOWN;
1.1 root 843:
844: basic_block_live_at_start = (regset *) oballoc (n_basic_blocks * sizeof (regset));
845: tem = (regset) oballoc (n_basic_blocks * regset_bytes);
846: bzero (tem, n_basic_blocks * regset_bytes);
847: init_regset_vector (basic_block_live_at_start, tem, n_basic_blocks, regset_bytes);
1.1.1.2 root 848:
849: regs_live_at_setjmp = (regset) oballoc (regset_bytes);
850: bzero (regs_live_at_setjmp, regset_bytes);
1.1 root 851: }
852:
853: /* Make each element of VECTOR point at a regset,
854: taking the space for all those regsets from SPACE.
855: SPACE is of type regset, but it is really as long as NELTS regsets.
856: BYTES_PER_ELT is the number of bytes in one regset. */
857:
858: static void
859: init_regset_vector (vector, space, nelts, bytes_per_elt)
860: regset *vector;
861: regset space;
862: int nelts;
863: int bytes_per_elt;
864: {
865: register int i;
866: register regset p = space;
867:
868: for (i = 0; i < nelts; i++)
869: {
870: vector[i] = p;
871: p += bytes_per_elt / sizeof (*p);
872: }
873: }
874:
875: /* Compute the registers live at the beginning of a basic block
876: from those live at the end.
877:
878: When called, OLD contains those live at the end.
879: On return, it contains those live at the beginning.
880: FIRST and LAST are the first and last insns of the basic block.
881:
882: FINAL is nonzero if we are doing the final pass which is not
883: for computing the life info (since that has already been done)
884: but for acting on it. On this pass, we delete dead stores,
885: set up the logical links and dead-variables lists of instructions,
886: and merge instructions for autoincrement and autodecrement addresses.
887:
888: SIGNIFICANT is nonzero only the first time for each basic block.
889: If it is nonzero, it points to a regset in which we store
890: a 1 for each register that is set within the block.
891:
892: BNUM is the number of the basic block. */
893:
894: static void
895: propagate_block (old, first, last, final, significant, bnum)
896: register regset old;
897: rtx first;
898: rtx last;
899: int final;
900: regset significant;
901: int bnum;
902: {
903: register rtx insn;
904: rtx prev;
905: regset live;
906: regset dead;
907:
908: /* The following variables are used only if FINAL is nonzero. */
909: /* This vector gets one element for each reg that has been live
910: at any point in the basic block that has been scanned so far.
911: SOMETIMES_MAX says how many elements are in use so far.
912: In each element, OFFSET is the byte-number within a regset
913: for the register described by the element, and BIT is a mask
914: for that register's bit within the byte. */
915: register struct foo { short offset; short bit; } *regs_sometimes_live;
916: int sometimes_max = 0;
917: /* This regset has 1 for each reg that we have seen live so far.
918: It and REGS_SOMETIMES_LIVE are updated together. */
919: regset maxlive;
920:
921: loop_depth = basic_block_loop_depth[bnum];
922:
923: dead = (regset) alloca (regset_bytes);
924: live = (regset) alloca (regset_bytes);
925:
926: if (final)
927: {
928: register int i, offset, bit;
929:
930: maxlive = (regset) alloca (regset_bytes);
931: bcopy (old, maxlive, regset_bytes);
932: regs_sometimes_live
933: = (struct foo *) alloca (max_regno * sizeof (struct foo));
934:
935: /* Process the regs live at the end of the block.
936: Enter them in MAXLIVE and REGS_SOMETIMES_LIVE.
937: Also mark them as not local to any one basic block. */
938:
939: for (offset = 0, i = 0; offset < regset_size; offset++)
940: for (bit = 1; bit; bit <<= 1, i++)
941: {
942: if (i == max_regno)
943: break;
944: if (old[offset] & bit)
945: {
1.1.1.4 root 946: reg_basic_block[i] = REG_BLOCK_GLOBAL;
1.1 root 947: regs_sometimes_live[sometimes_max].offset = offset;
948: regs_sometimes_live[sometimes_max].bit = i % REGSET_ELT_BITS;
949: sometimes_max++;
950: }
951: }
952: }
953:
954: /* Scan the block an insn at a time from end to beginning. */
955:
956: for (insn = last; ; insn = prev)
957: {
958: prev = PREV_INSN (insn);
959:
1.1.1.2 root 960: /* If this is a call to `setjmp' et al,
961: warn if any non-volatile datum is live. */
962:
963: if (final && GET_CODE (insn) == NOTE
964: && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)
965: {
966: int i;
967: for (i = 0; i < regset_size; i++)
968: regs_live_at_setjmp[i] |= old[i];
1.1 root 969: }
970:
971: /* Update the life-status of regs for this insn.
972: First DEAD gets which regs are set in this insn
973: then LIVE gets which regs are used in this insn.
974: Then the regs live before the insn
975: are those live after, with DEAD regs turned off,
976: and then LIVE regs turned on. */
977:
978: if (GET_CODE (insn) == INSN
979: || GET_CODE (insn) == JUMP_INSN
980: || GET_CODE (insn) == CALL_INSN)
981: {
982: register int i;
1.1.1.2 root 983: rtx note = find_reg_note (insn, REG_RETVAL, 0);
984:
1.1 root 985: /* If an instruction consists of just dead store(s) on final pass,
986: "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED.
987: We could really delete it with delete_insn, but that
988: can cause trouble for first or last insn in a basic block. */
1.1.1.2 root 989: if (final && insn_dead_p (PATTERN (insn), old, 1)
990: /* Don't delete something that refers to volatile storage! */
991: && ! INSN_VOLATILE (insn))
1.1 root 992: {
1.1.1.10 root 993: rtx oldpat = PATTERN (insn);
1.1 root 994: PUT_CODE (insn, NOTE);
995: NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
996: NOTE_SOURCE_FILE (insn) = 0;
1.1.1.2 root 997: /* If this insn is copying the return value from a library call,
998: delete the entire library call. */
1.1.1.10 root 999: if (note && libcall_dead_p (oldpat, old))
1.1.1.2 root 1000: {
1001: rtx first = XEXP (note, 0);
1002: rtx prev = insn;
1.1.1.9 root 1003: while (INSN_DELETED_P (first))
1.1.1.2 root 1004: first = NEXT_INSN (first);
1005: while (prev != first)
1006: {
1007: prev = PREV_INSN (prev);
1008: PUT_CODE (prev, NOTE);
1009: NOTE_LINE_NUMBER (prev) = NOTE_INSN_DELETED;
1010: NOTE_SOURCE_FILE (prev) = 0;
1011: }
1012: }
1.1 root 1013: goto flushed;
1014: }
1.1.1.2 root 1015:
1016: for (i = 0; i < regset_size; i++)
1.1 root 1017: {
1.1.1.2 root 1018: dead[i] = 0; /* Faster than bzero here */
1019: live[i] = 0; /* since regset_size is usually small */
1020: }
1.1 root 1021:
1.1.1.2 root 1022: /* See if this is an increment or decrement that can be
1023: merged into a following memory address. */
1024: #ifdef AUTO_INC_DEC
1025: {
1026: register rtx x = PATTERN (insn);
1027: /* Does this instruction increment or decrement a register? */
1028: if (final && GET_CODE (x) == SET
1029: && GET_CODE (SET_DEST (x)) == REG
1030: && (GET_CODE (SET_SRC (x)) == PLUS
1031: || GET_CODE (SET_SRC (x)) == MINUS)
1032: && XEXP (SET_SRC (x), 0) == SET_DEST (x)
1033: && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
1034: /* Ok, look for a following memory ref we can combine with.
1035: If one is found, change the memory ref to a PRE_INC
1036: or PRE_DEC, cancel this insn, and return 1.
1037: Return 0 if nothing has been done. */
1038: && try_pre_increment_1 (insn))
1039: goto flushed;
1040: }
1041: #endif /* AUTO_INC_DEC */
1.1 root 1042:
1.1.1.2 root 1043: /* If this is not the final pass, and this insn is copying the
1044: value of a library call and it's dead, don't scan the
1045: insns that perform the library call, so that the call's
1046: arguments are not marked live. */
1.1.1.10 root 1047: if (note && insn_dead_p (PATTERN (insn), old, 1)
1048: && libcall_dead_p (PATTERN (insn), old))
1.1.1.3 root 1049: {
1.1.1.4 root 1050: /* Mark the dest reg as `significant'. */
1051: mark_set_regs (old, dead, PATTERN (insn), 0, significant);
1052:
1.1.1.3 root 1053: insn = XEXP (note, 0);
1054: prev = PREV_INSN (insn);
1055: }
1.1.1.9 root 1056: else if (GET_CODE (PATTERN (insn)) == SET
1057: && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
1.1.1.4 root 1058: && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
1059: && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx
1060: && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT)
1.1.1.10 root 1061: /* We have an insn to pop a constant amount off the stack.
1062: (Such insns use PLUS regardless of the direction of the stack,
1063: and any insn to adjust the stack by a constant is always a pop.)
1064: These insns, if not dead stores, have no effect on life. */
1.1.1.4 root 1065: ;
1.1.1.2 root 1066: else
1067: {
1068: /* LIVE gets the regs used in INSN; DEAD gets those set by it. */
1.1 root 1069: mark_set_regs (old, dead, PATTERN (insn), final ? insn : 0,
1070: significant);
1.1.1.2 root 1071: mark_used_regs (old, live, PATTERN (insn), final, insn);
1.1 root 1072:
1073: /* Update OLD for the registers used or set. */
1074: for (i = 0; i < regset_size; i++)
1075: {
1076: old[i] &= ~dead[i];
1077: old[i] |= live[i];
1078: }
1079:
1.1.1.2 root 1080: if (GET_CODE (insn) == CALL_INSN)
1081: {
1082: register int i;
1083:
1084: /* Each call clobbers all call-clobbered regs.
1085: Note that the function-value reg is one of these, and
1086: mark_set_regs has already had a chance to handle it. */
1087: for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1088: if (call_used_regs[i])
1.1.1.9 root 1089: dead[i / REGSET_ELT_BITS] |=
1090: (1 << (i % REGSET_ELT_BITS));
1.1.1.2 root 1091:
1092: /* The stack ptr is used (honorarily) by a CALL insn. */
1.1.1.9 root 1093: live[STACK_POINTER_REGNUM / REGSET_ELT_BITS]
1.1.1.2 root 1094: |= (1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS));
1.1.1.9 root 1095: }
1.1.1.2 root 1096:
1.1.1.9 root 1097: /* Update OLD for the registers used or set. */
1098: for (i = 0; i < regset_size; i++)
1099: {
1100: old[i] &= ~dead[i];
1101: old[i] |= live[i];
1102: }
1103:
1104: if (GET_CODE (insn) == CALL_INSN && final)
1105: {
1106: /* Any regs live at the time of a call instruction
1107: must not go in a register clobbered by calls.
1108: Find all regs now live and record this for them. */
1109:
1110: register struct foo *p = regs_sometimes_live;
1111:
1112: for (i = 0; i < sometimes_max; i++, p++)
1113: if (old[p->offset] & (1 << p->bit))
1.1.1.12 root 1114: reg_n_calls_crossed[p->offset * REGSET_ELT_BITS + p->bit]+= 1;
1.1.1.2 root 1115: }
1116: }
1117:
1118: /* On final pass, add any additional sometimes-live regs
1119: into MAXLIVE and REGS_SOMETIMES_LIVE.
1120: Also update counts of how many insns each reg is live at. */
1.1 root 1121:
1.1.1.2 root 1122: if (final)
1123: {
1124: for (i = 0; i < regset_size; i++)
1.1 root 1125: {
1.1.1.2 root 1126: register int diff = live[i] & ~maxlive[i];
1.1 root 1127:
1.1.1.2 root 1128: if (diff)
1129: {
1130: register int regno;
1131: maxlive[i] |= diff;
1132: for (regno = 0; diff && regno < REGSET_ELT_BITS; regno++)
1133: if (diff & (1 << regno))
1134: {
1135: regs_sometimes_live[sometimes_max].offset = i;
1136: regs_sometimes_live[sometimes_max].bit = regno;
1137: diff &= ~ (1 << regno);
1138: sometimes_max++;
1139: }
1140: }
1141: }
1.1 root 1142:
1.1.1.2 root 1143: {
1144: register struct foo *p = regs_sometimes_live;
1145: for (i = 0; i < sometimes_max; i++, p++)
1.1 root 1146: {
1.1.1.2 root 1147: if (old[p->offset] & (1 << p->bit))
1148: reg_live_length[p->offset * REGSET_ELT_BITS + p->bit]++;
1.1 root 1149: }
1.1.1.2 root 1150: }
1.1 root 1151: }
1152: }
1.1.1.2 root 1153: flushed: ;
1.1 root 1154: if (insn == first)
1155: break;
1156: }
1157: }
1158:
1159: /* Return 1 if X (the body of an insn, or part of it) is just dead stores
1160: (SET expressions whose destinations are registers dead after the insn).
1161: NEEDED is the regset that says which regs are alive after the insn. */
1162:
1163: static int
1.1.1.2 root 1164: insn_dead_p (x, needed, strict_low_ok)
1.1 root 1165: rtx x;
1166: regset needed;
1.1.1.2 root 1167: int strict_low_ok;
1.1 root 1168: {
1169: register RTX_CODE code = GET_CODE (x);
1.1.1.2 root 1170: #if 0
1.1 root 1171: /* Make sure insns to set the stack pointer are never deleted. */
1172: needed[STACK_POINTER_REGNUM / REGSET_ELT_BITS]
1173: |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
1.1.1.2 root 1174: #endif
1175:
1176: /* If setting something that's a reg or part of one,
1177: see if that register's altered value will be live. */
1178:
1179: if (code == SET)
1.1 root 1180: {
1.1.1.2 root 1181: register rtx r = SET_DEST (x);
1182: /* A SET that is a subroutine call cannot be dead. */
1183: if (GET_CODE (SET_SRC (x)) == CALL)
1184: return 0;
1185: while (GET_CODE (r) == SUBREG
1186: || (strict_low_ok && GET_CODE (r) == STRICT_LOW_PART)
1187: || GET_CODE (r) == ZERO_EXTRACT
1188: || GET_CODE (r) == SIGN_EXTRACT)
1189: r = SUBREG_REG (r);
1190: if (GET_CODE (r) == REG)
1191: {
1192: register int regno = REGNO (r);
1193: register int offset = regno / REGSET_ELT_BITS;
1194: register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.11 root 1195: return (! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
1196: && (needed[offset] & bit) == 0);
1.1.1.2 root 1197: }
1.1 root 1198: }
1.1.1.2 root 1199: /* If performing several activities,
1200: insn is dead if each activity is individually dead.
1201: Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE
1202: that's inside a PARALLEL doesn't make the insn worth keeping. */
1203: else if (code == PARALLEL)
1.1 root 1204: {
1205: register int i = XVECLEN (x, 0);
1206: for (i--; i >= 0; i--)
1.1.1.2 root 1207: {
1208: rtx elt = XVECEXP (x, 0, i);
1209: if (!insn_dead_p (elt, needed, strict_low_ok)
1210: && GET_CODE (elt) != CLOBBER
1211: && GET_CODE (elt) != USE)
1212: return 0;
1213: }
1.1 root 1214: return 1;
1215: }
1.1.1.2 root 1216: /* We do not check CLOBBER or USE here.
1217: An insn consisting of just a CLOBBER or just a USE
1218: should not be deleted. */
1.1 root 1219: return 0;
1220: }
1221:
1.1.1.10 root 1222: /* If X is the last insn in a libcall, and assuming X is dead,
1223: return 1 if the entire library call is dead.
1224: This is true if the source of X is a dead register
1225: (as well as the destination, which we tested already).
1226: If this insn doesn't just copy a register, then we don't
1227: have an ordinary libcall. In that case, cse could not have
1228: managed to substitute the source for the dest later on,
1229: so we can assume the libcall is dead. */
1230:
1231: static int
1232: libcall_dead_p (x, needed)
1233: rtx x;
1234: regset needed;
1235: {
1236: register RTX_CODE code = GET_CODE (x);
1237:
1238: if (code == SET)
1239: {
1240: register rtx r = SET_SRC (x);
1241: if (GET_CODE (r) == REG)
1242: {
1243: register int regno = REGNO (r);
1244: register int offset = regno / REGSET_ELT_BITS;
1245: register int bit = 1 << (regno % REGSET_ELT_BITS);
1246: return (needed[offset] & bit) == 0;
1247: }
1248: }
1249: return 1;
1250: }
1251:
1.1.1.2 root 1252: /* Return 1 if register REGNO was used before it was set.
1253: In other words, if it is live at function entry. */
1.1 root 1254:
1.1.1.2 root 1255: int
1256: regno_uninitialized (regno)
1.1 root 1257: int regno;
1258: {
1.1.1.11 root 1259: if (n_basic_blocks == 0)
1260: return 0;
1261:
1.1.1.2 root 1262: return (basic_block_live_at_start[0][regno / REGSET_ELT_BITS]
1263: & (1 << (regno % REGSET_ELT_BITS)));
1264: }
1265:
1266: /* 1 if register REGNO was alive at a place where `setjmp' was called
1267: and was set more than once. Such regs may be clobbered by `longjmp'. */
1268:
1269: int
1270: regno_clobbered_at_setjmp (regno)
1271: int regno;
1272: {
1273: return (reg_n_sets[regno] > 1
1274: && (regs_live_at_setjmp[regno / REGSET_ELT_BITS]
1275: & (1 << (regno % REGSET_ELT_BITS))));
1.1 root 1276: }
1277:
1278: /* Process the registers that are set within X.
1279: Their bits are set to 1 in the regset DEAD,
1280: because they are dead prior to this insn.
1281:
1282: If INSN is nonzero, it is the insn being processed
1283: and the fact that it is nonzero implies this is the FINAL pass
1284: in propagate_block. In this case, various info about register
1285: usage is stored, LOG_LINKS fields of insns are set up. */
1286:
1287: static void mark_set_1 ();
1288:
1289: static void
1290: mark_set_regs (needed, dead, x, insn, significant)
1291: regset needed;
1292: regset dead;
1293: rtx x;
1294: rtx insn;
1295: regset significant;
1296: {
1297: register RTX_CODE code = GET_CODE (x);
1298:
1299: if (code == SET || code == CLOBBER)
1300: mark_set_1 (needed, dead, x, insn, significant);
1301: else if (code == PARALLEL)
1302: {
1303: register int i;
1304: for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
1305: {
1306: code = GET_CODE (XVECEXP (x, 0, i));
1307: if (code == SET || code == CLOBBER)
1308: mark_set_1 (needed, dead, XVECEXP (x, 0, i), insn, significant);
1309: }
1310: }
1311: }
1312:
1313: /* Process a single SET rtx, X. */
1314:
1315: static void
1316: mark_set_1 (needed, dead, x, insn, significant)
1317: regset needed;
1318: regset dead;
1319: rtx x;
1320: rtx insn;
1321: regset significant;
1322: {
1323: register int regno;
1324: register rtx reg = SET_DEST (x);
1.1.1.13! root 1325: int subreg_p = 0;
1.1 root 1326:
1.1.1.2 root 1327: if (reg == 0)
1328: return;
1329:
1.1.1.13! root 1330: if (GET_CODE (reg) == STRICT_LOW_PART)
! 1331: reg = XEXP (reg, 0);
! 1332:
! 1333: if (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT
! 1334: || GET_CODE (reg) == SIGN_EXTRACT)
1.1 root 1335: {
1.1.1.13! root 1336: /* Modifying just one hardware register of a multi-reg value
! 1337: or just a byte field of a register
! 1338: does not mean the value from before this insn is now dead.
! 1339: But it does mean liveness of that register at the end of the block
! 1340: is significant. */
1.1 root 1341: if (REG_SIZE (SUBREG_REG (reg)) > REG_SIZE (reg))
1.1.1.13! root 1342: subreg_p = 1;
1.1 root 1343:
1344: reg = SUBREG_REG (reg);
1345: }
1346:
1347: if (GET_CODE (reg) == REG
1348: && (regno = REGNO (reg), regno != FRAME_POINTER_REGNUM)
1.1.1.11 root 1349: && regno != ARG_POINTER_REGNUM
1350: && ! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno]))
1.1.1.2 root 1351: /* && regno != STACK_POINTER_REGNUM) -- let's try without this. */
1.1 root 1352: {
1353: register int offset = regno / REGSET_ELT_BITS;
1354: register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.2 root 1355: int is_needed = 0;
1356:
1.1 root 1357: /* Mark it as a significant register for this basic block. */
1358: if (significant)
1359: significant[offset] |= bit;
1.1.1.13! root 1360: /* That's all we do, if we are setting only part of the register. */
! 1361: if (subreg_p)
! 1362: return;
! 1363:
! 1364: /* If entire register being set, mark it as as dead before this insn. */
! 1365: dead[offset] |= bit;
1.1.1.2 root 1366: /* A hard reg in a wide mode may really be multiple registers.
1367: If so, mark all of them just like the first. */
1368: if (regno < FIRST_PSEUDO_REGISTER)
1369: {
1.1.1.4 root 1370: int n;
1371:
1372: /* Nothing below is needed for the stack pointer; get out asap.
1373: Eg, log links aren't needed, since combine won't use them. */
1374: if (regno == STACK_POINTER_REGNUM)
1375: return;
1376:
1377: n = HARD_REGNO_NREGS (regno, GET_MODE (reg));
1.1.1.2 root 1378: while (--n > 0)
1379: {
1380: dead[(regno + n) / REGSET_ELT_BITS]
1381: |= 1 << ((regno + n) % REGSET_ELT_BITS);
1382: if (significant)
1383: significant[(regno + n) / REGSET_ELT_BITS]
1384: |= 1 << ((regno + n) % REGSET_ELT_BITS);
1385: is_needed |= (needed[(regno + n) / REGSET_ELT_BITS]
1386: & 1 << ((regno + n) % REGSET_ELT_BITS));
1387: }
1388: }
1.1 root 1389: /* Additional data to record if this is the final pass. */
1390: if (insn)
1391: {
1392: register rtx y = reg_next_use[regno];
1393: register int blocknum = BLOCK_NUM (insn);
1394:
1.1.1.9 root 1395: /* If this is a hard reg, record this function uses the reg.
1396: `combine.c' will get confused if LOG_LINKs are made
1397: for hard regs. */
1.1 root 1398:
1399: if (regno < FIRST_PSEUDO_REGISTER)
1400: {
1401: register int i;
1402: i = HARD_REGNO_NREGS (regno, GET_MODE (reg));
1.1.1.8 root 1403: if (i == 0)
1404: i = 1;
1.1 root 1405: do
1406: regs_ever_live[regno + --i] = 1;
1407: while (i > 0);
1.1.1.4 root 1408:
1409: if (! ((needed[offset] & bit) || is_needed))
1410: {
1411: /* Note that dead stores have already been deleted if poss.
1412: If we get here, we have found a dead store that cannot
1413: be eliminated (because the insn does something useful).
1414: Indicate this by marking the reg set as dying here. */
1415: REG_NOTES (insn)
1416: = gen_rtx (EXPR_LIST, REG_DEAD,
1417: reg, REG_NOTES (insn));
1418: reg_n_deaths[REGNO (reg)]++;
1419: }
1420: return;
1.1 root 1421: }
1422:
1423: /* Keep track of which basic blocks each reg appears in. */
1424:
1.1.1.4 root 1425: if (reg_basic_block[regno] == REG_BLOCK_UNKNOWN)
1.1 root 1426: reg_basic_block[regno] = blocknum;
1427: else if (reg_basic_block[regno] != blocknum)
1.1.1.4 root 1428: reg_basic_block[regno] = REG_BLOCK_GLOBAL;
1.1 root 1429:
1430: /* Count (weighted) references, stores, etc. */
1431: reg_n_refs[regno] += loop_depth;
1432: reg_n_sets[regno]++;
1.1.1.2 root 1433: /* The next use is no longer "next", since a store intervenes. */
1434: reg_next_use[regno] = 0;
1.1 root 1435: /* The insns where a reg is live are normally counted elsewhere,
1436: but we want the count to include the insn where the reg is set,
1437: and the normal counting mechanism would not count it. */
1438: reg_live_length[regno]++;
1.1.1.2 root 1439: if ((needed[offset] & bit) || is_needed)
1.1 root 1440: {
1441: /* Make a logical link from the next following insn
1442: that uses this register, back to this insn.
1443: The following insns have already been processed. */
1444: if (y && (BLOCK_NUM (y) == blocknum))
1445: LOG_LINKS (y)
1446: = gen_rtx (INSN_LIST, VOIDmode, insn, LOG_LINKS (y));
1447: }
1448: else
1449: {
1450: /* Note that dead stores have already been deleted when possible
1451: If we get here, we have found a dead store that cannot
1452: be eliminated (because the same insn does something useful).
1453: Indicate this by marking the reg being set as dying here. */
1454: REG_NOTES (insn)
1455: = gen_rtx (EXPR_LIST, REG_DEAD,
1456: reg, REG_NOTES (insn));
1.1.1.3 root 1457: reg_n_deaths[REGNO (reg)]++;
1.1 root 1458: }
1459: }
1460: }
1461: }
1462:
1463: /* Scan expression X and store a 1-bit in LIVE for each reg it uses.
1464: This is done assuming the registers needed from X
1465: are those that have 1-bits in NEEDED.
1466:
1.1.1.2 root 1467: On the final pass, FINAL is 1. This means try for autoincrement
1468: and count the uses and deaths of each pseudo-reg.
1469:
1470: INSN is the containing instruction. */
1.1 root 1471:
1472: static void
1.1.1.2 root 1473: mark_used_regs (needed, live, x, final, insn)
1.1 root 1474: regset needed;
1475: regset live;
1476: rtx x;
1477: rtx insn;
1.1.1.2 root 1478: int final;
1.1 root 1479: {
1480: register RTX_CODE code;
1481: register int regno;
1482:
1483: retry:
1484: code = GET_CODE (x);
1485: switch (code)
1486: {
1487: case LABEL_REF:
1488: case SYMBOL_REF:
1489: case CONST_INT:
1490: case CONST:
1.1.1.4 root 1491: case CONST_DOUBLE:
1.1 root 1492: case CC0:
1493: case PC:
1494: case CLOBBER:
1.1.1.4 root 1495: case ADDR_VEC:
1496: case ADDR_DIFF_VEC:
1497: case ASM_INPUT:
1.1 root 1498: return;
1499:
1500: #if defined (HAVE_POST_INCREMENT) || defined (HAVE_POST_DECREMENT)
1501: case MEM:
1502: /* Here we detect use of an index register which might
1503: be good for postincrement or postdecrement. */
1.1.1.2 root 1504: if (final)
1.1 root 1505: {
1506: rtx addr = XEXP (x, 0);
1507: register int size = GET_MODE_SIZE (GET_MODE (x));
1508:
1509: if (GET_CODE (addr) == REG)
1510: {
1511: register rtx y;
1512: regno = REGNO (addr);
1513: /* Is the next use an increment that might make auto-increment? */
1514: y = reg_next_use[regno];
1515: if (y && GET_CODE (PATTERN (y)) == SET
1516: && BLOCK_NUM (y) == BLOCK_NUM (insn)
1517: /* Can't add side effects to jumps; if reg is spilled and
1518: reloaded, there's no way to store back the altered value. */
1519: && GET_CODE (insn) != JUMP_INSN
1520: && (y = SET_SRC (PATTERN (y)),
1521: (0
1522: #ifdef HAVE_POST_INCREMENT
1523: || GET_CODE (y) == PLUS
1524: #endif
1525: #ifdef HAVE_POST_DECREMENT
1526: || GET_CODE (y) == MINUS
1527: #endif
1528: )
1529: && XEXP (y, 0) == addr
1530: && GET_CODE (XEXP (y, 1)) == CONST_INT
1.1.1.2 root 1531: && INTVAL (XEXP (y, 1)) == size)
1532: && dead_or_set_p (reg_next_use[regno], addr))
1.1 root 1533: {
1.1.1.2 root 1534: rtx use = find_use_as_address (PATTERN (insn), addr, 0);
1.1 root 1535:
1536: /* Make sure this register appears only once in this insn. */
1537: if (use != 0 && use != (rtx) 1)
1538: {
1539: /* We have found a suitable auto-increment:
1540: do POST_INC around the register here,
1541: and patch out the increment instruction that follows. */
1542: XEXP (x, 0)
1543: = gen_rtx (GET_CODE (y) == PLUS ? POST_INC : POST_DEC,
1544: Pmode, addr);
1545: /* Record that this insn has an implicit side effect. */
1546: REG_NOTES (insn)
1547: = gen_rtx (EXPR_LIST, REG_INC, addr, REG_NOTES (insn));
1548:
1.1.1.2 root 1549: /* Modify the old increment-insn to simply copy
1550: the already-incremented value of our register. */
1.1 root 1551: y = reg_next_use[regno];
1.1.1.2 root 1552: SET_SRC (PATTERN (y)) = addr;
1553:
1554: /* If that makes it a no-op (copying the register
1555: into itself) then change it to a simpler no-op
1556: so it won't appear to be a "use" and a "set"
1557: of this register. */
1558: if (SET_DEST (PATTERN (y)) == addr)
1559: PATTERN (y) = gen_rtx (USE, VOIDmode, const0_rtx);
1560:
1561: /* Count an extra reference to the reg for the increment.
1562: When a reg is incremented.
1.1 root 1563: spilling it is worse, so we want to make that
1564: less likely. */
1565: reg_n_refs[regno] += loop_depth;
1.1.1.2 root 1566: /* Count the increment as a setting of the register,
1567: even though it isn't a SET in rtl. */
1568: reg_n_sets[regno]++;
1.1 root 1569: }
1570: }
1571: }
1572: }
1573: break;
1574: #endif /* HAVE_POST_INCREMENT or HAVE_POST_DECREMENT */
1575:
1576: case REG:
1577: /* See a register other than being set
1578: => mark it as needed. */
1579:
1580: regno = REGNO (x);
1581: if (regno != FRAME_POINTER_REGNUM
1.1.1.2 root 1582: && regno != ARG_POINTER_REGNUM)
1583: /* && regno != STACK_POINTER_REGNUM) -- let's try without this. */
1.1 root 1584: {
1585: register int offset = regno / REGSET_ELT_BITS;
1586: register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.2 root 1587: int is_needed = 0;
1588:
1.1 root 1589: live[offset] |= bit;
1.1.1.2 root 1590: /* A hard reg in a wide mode may really be multiple registers.
1591: If so, mark all of them just like the first. */
1592: if (regno < FIRST_PSEUDO_REGISTER)
1593: {
1.1.1.4 root 1594: int n;
1595:
1596: /* For stack ptr, nothing below here can be necessary,
1597: so waste no more time. */
1598: if (regno == STACK_POINTER_REGNUM)
1599: return;
1.1.1.12 root 1600: /* No death notes for global register variables;
1601: their values are live after this function exits. */
1602: if (global_regs[regno])
1603: return;
1.1.1.4 root 1604:
1605: n = HARD_REGNO_NREGS (regno, GET_MODE (x));
1.1.1.2 root 1606: while (--n > 0)
1607: {
1608: live[(regno + n) / REGSET_ELT_BITS]
1609: |= 1 << ((regno + n) % REGSET_ELT_BITS);
1610: is_needed |= (needed[(regno + n) / REGSET_ELT_BITS]
1611: & 1 << ((regno + n) % REGSET_ELT_BITS));
1612: }
1613: }
1614: if (final)
1.1 root 1615: {
1616: if (regno < FIRST_PSEUDO_REGISTER)
1617: {
1.1.1.4 root 1618: /* If a hard reg is being used,
1619: record that this function does use it. */
1620:
1.1 root 1621: register int i;
1622: i = HARD_REGNO_NREGS (regno, GET_MODE (x));
1.1.1.8 root 1623: if (i == 0)
1624: i = 1;
1.1 root 1625: do
1626: regs_ever_live[regno + --i] = 1;
1627: while (i > 0);
1628: }
1.1.1.4 root 1629: else
1630: {
1631: /* Keep track of which basic block each reg appears in. */
1.1 root 1632:
1.1.1.4 root 1633: register int blocknum = BLOCK_NUM (insn);
1.1 root 1634:
1.1.1.4 root 1635: if (reg_basic_block[regno] == REG_BLOCK_UNKNOWN)
1636: reg_basic_block[regno] = blocknum;
1637: else if (reg_basic_block[regno] != blocknum)
1638: reg_basic_block[regno] = REG_BLOCK_GLOBAL;
1.1 root 1639:
1.1.1.4 root 1640: /* Record where each reg is used, so when the reg
1641: is set we know the next insn that uses it. */
1.1 root 1642:
1.1.1.4 root 1643: reg_next_use[regno] = insn;
1.1 root 1644:
1.1.1.4 root 1645: /* Count (weighted) number of uses of each reg. */
1.1 root 1646:
1.1.1.4 root 1647: reg_n_refs[regno] += loop_depth;
1648: }
1.1.1.12 root 1649:
1.1 root 1650: /* Record and count the insns in which a reg dies.
1651: If it is used in this insn and was dead below the insn
1652: then it dies in this insn. */
1653:
1.1.1.2 root 1654: if (!(needed[offset] & bit) && !is_needed
1655: && ! find_regno_note (insn, REG_DEAD, regno))
1.1 root 1656: {
1657: REG_NOTES (insn)
1658: = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (insn));
1659: reg_n_deaths[regno]++;
1660: }
1661: }
1662: }
1663: return;
1664:
1665: case SET:
1666: {
1.1.1.2 root 1667: register rtx testreg = SET_DEST (x);
1668: int mark_dest = 0;
1.1 root 1669:
1.1.1.2 root 1670: /* Storing in STRICT_LOW_PART is like storing in a reg
1671: in that this SET might be dead, so ignore it in TESTREG.
1672: but in some other ways it is like using the reg. */
1673: /* Storing in a SUBREG or a bit field is like storing the entire
1674: register in that if the register's value is not used
1675: then this SET is not needed. */
1676: while (GET_CODE (testreg) == STRICT_LOW_PART
1677: || GET_CODE (testreg) == ZERO_EXTRACT
1678: || GET_CODE (testreg) == SIGN_EXTRACT
1679: || GET_CODE (testreg) == SUBREG)
1680: {
1681: /* Modifying a single register in an alternate mode
1682: does not use any of the old value. But these other
1683: ways of storing in a register do use the old value. */
1684: if (GET_CODE (testreg) == SUBREG
1685: && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
1686: ;
1687: else
1688: mark_dest = 1;
1689:
1690: testreg = XEXP (testreg, 0);
1691: }
1.1 root 1692:
1693: /* If this is a store into a register,
1694: recursively scan the only value being stored,
1695: and only if the register's value is live after this insn.
1696: If the value being computed here would never be used
1697: then the values it uses don't need to be computed either. */
1698:
1.1.1.2 root 1699: if (GET_CODE (testreg) == REG
1700: && (regno = REGNO (testreg), regno != FRAME_POINTER_REGNUM)
1.1.1.11 root 1701: && regno != ARG_POINTER_REGNUM
1702: && ! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno]))
1.1.1.7 root 1703: #if 0 /* This was added in 1.25, but screws up death notes for hard regs.
1704: It probably isn't really needed anyway. */
1.1.1.6 root 1705: && (regno >= FIRST_PSEUDO_REGISTER
1706: || INSN_VOLATILE (insn)))
1.1.1.7 root 1707: #endif
1.1 root 1708: {
1709: register int offset = regno / REGSET_ELT_BITS;
1710: register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.2 root 1711: if ((needed[offset] & bit)
1712: /* If insn refers to volatile, we mustn't delete it,
1713: so its inputs are all needed. */
1714: || INSN_VOLATILE (insn))
1715: {
1716: mark_used_regs (needed, live, SET_SRC (x), final, insn);
1717: if (mark_dest)
1718: mark_used_regs (needed, live, SET_DEST (x), final, insn);
1719: }
1.1 root 1720: return;
1721: }
1722: }
1723: break;
1724: }
1725:
1726: /* Recursively scan the operands of this expression. */
1727:
1728: {
1729: register char *fmt = GET_RTX_FORMAT (code);
1730: register int i;
1731:
1732: for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1733: {
1734: if (fmt[i] == 'e')
1735: {
1736: /* Tail recursive case: save a function call level. */
1737: if (i == 0)
1738: {
1739: x = XEXP (x, 0);
1740: goto retry;
1741: }
1.1.1.2 root 1742: mark_used_regs (needed, live, XEXP (x, i), final, insn);
1.1 root 1743: }
1.1.1.4 root 1744: else if (fmt[i] == 'E')
1.1 root 1745: {
1746: register int j;
1747: for (j = 0; j < XVECLEN (x, i); j++)
1.1.1.2 root 1748: mark_used_regs (needed, live, XVECEXP (x, i, j), final, insn);
1.1 root 1749: }
1750: }
1751: }
1752: }
1753:
1.1.1.2 root 1754: #ifdef AUTO_INC_DEC
1.1 root 1755:
1756: static int
1757: try_pre_increment_1 (insn)
1758: rtx insn;
1759: {
1760: /* Find the next use of this reg. If in same basic block,
1761: make it do pre-increment or pre-decrement if appropriate. */
1762: rtx x = PATTERN (insn);
1763: int amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1)
1764: * INTVAL (XEXP (SET_SRC (x), 1)));
1765: int regno = REGNO (SET_DEST (x));
1766: rtx y = reg_next_use[regno];
1767: if (y != 0
1768: && BLOCK_NUM (y) == BLOCK_NUM (insn)
1769: && try_pre_increment (y, SET_DEST (PATTERN (insn)),
1770: amount))
1771: {
1772: /* We have found a suitable auto-increment
1773: and already changed insn Y to do it.
1774: So flush this increment-instruction. */
1775: PUT_CODE (insn, NOTE);
1776: NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1777: NOTE_SOURCE_FILE (insn) = 0;
1778: /* Count a reference to this reg for the increment
1779: insn we are deleting. When a reg is incremented.
1780: spilling it is worse, so we want to make that
1781: less likely. */
1782: reg_n_refs[regno] += loop_depth;
1.1.1.2 root 1783: reg_n_sets[regno]++;
1.1 root 1784: return 1;
1785: }
1786: return 0;
1787: }
1788:
1789: /* Try to change INSN so that it does pre-increment or pre-decrement
1790: addressing on register REG in order to add AMOUNT to REG.
1791: AMOUNT is negative for pre-decrement.
1792: Returns 1 if the change could be made.
1793: This checks all about the validity of the result of modifying INSN. */
1794:
1795: static int
1796: try_pre_increment (insn, reg, amount)
1797: rtx insn, reg;
1798: int amount;
1799: {
1800: register rtx use;
1801:
1.1.1.2 root 1802: /* Nonzero if we can try to make a pre-increment or pre-decrement.
1803: For example, addl $4,r1; movl (r1),... can become movl +(r1),... */
1804: int pre_ok = 0;
1805: /* Nonzero if we can try to make a post-increment or post-decrement.
1806: For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,...
1807: It is possible for both PRE_OK and POST_OK to be nonzero if the machine
1808: supports both pre-inc and post-inc, or both pre-dec and post-dec. */
1809: int post_ok = 0;
1810:
1811: /* Nonzero if the opportunity actually requires post-inc or post-dec. */
1812: int do_post = 0;
1813:
1814: /* From the sign of increment, see which possibilities are conceivable
1815: on this target machine. */
1816: #ifdef HAVE_PRE_INCREMENT
1.1 root 1817: if (amount > 0)
1.1.1.2 root 1818: pre_ok = 1;
1.1 root 1819: #endif
1.1.1.2 root 1820: #ifdef HAVE_POST_INCREMENT
1821: if (amount > 0)
1822: post_ok = 1;
1.1 root 1823: #endif
1824:
1.1.1.2 root 1825: #ifdef HAVE_PRE_DECREMENT
1.1 root 1826: if (amount < 0)
1.1.1.2 root 1827: pre_ok = 1;
1828: #endif
1829: #ifdef HAVE_POST_DECREMENT
1830: if (amount < 0)
1831: post_ok = 1;
1.1 root 1832: #endif
1833:
1.1.1.2 root 1834: if (! (pre_ok || post_ok))
1835: return 0;
1836:
1.1 root 1837: /* It is not safe to add a side effect to a jump insn
1838: because if the incremented register is spilled and must be reloaded
1839: there would be no way to store the incremented value back in memory. */
1840:
1841: if (GET_CODE (insn) == JUMP_INSN)
1842: return 0;
1843:
1.1.1.2 root 1844: use = 0;
1845: if (pre_ok)
1846: use = find_use_as_address (PATTERN (insn), reg, 0);
1847: if (post_ok && (use == 0 || use == (rtx) 1))
1848: {
1849: use = find_use_as_address (PATTERN (insn), reg, -amount);
1850: do_post = 1;
1851: }
1.1 root 1852:
1853: if (use == 0 || use == (rtx) 1)
1854: return 0;
1855:
1856: if (GET_MODE_SIZE (GET_MODE (use)) != (amount > 0 ? amount : - amount))
1857: return 0;
1858:
1.1.1.2 root 1859: XEXP (use, 0) = gen_rtx (amount > 0
1860: ? (do_post ? POST_INC : PRE_INC)
1861: : (do_post ? POST_DEC : PRE_DEC),
1.1 root 1862: Pmode, reg);
1863:
1864: /* Record that this insn now has an implicit side effect on X. */
1865: REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, reg, REG_NOTES (insn));
1866: return 1;
1867: }
1868:
1.1.1.2 root 1869: #endif /* AUTO_INC_DEC */
1870:
1.1 root 1871: /* Find the place in the rtx X where REG is used as a memory address.
1872: Return the MEM rtx that so uses it.
1.1.1.2 root 1873: If PLUSCONST is nonzero, search instead for a memory address equivalent to
1874: (plus REG (const_int PLUSCONST)).
1875:
1876: If such an address does not appear, return 0.
1877: If REG appears more than once, or is used other than in such an address,
1.1 root 1878: return (rtx)1. */
1879:
1880: static rtx
1.1.1.2 root 1881: find_use_as_address (x, reg, plusconst)
1.1 root 1882: register rtx x;
1883: rtx reg;
1.1.1.2 root 1884: int plusconst;
1.1 root 1885: {
1886: enum rtx_code code = GET_CODE (x);
1887: char *fmt = GET_RTX_FORMAT (code);
1888: register int i;
1889: register rtx value = 0;
1890: register rtx tem;
1891:
1.1.1.2 root 1892: if (code == MEM && XEXP (x, 0) == reg && plusconst == 0)
1.1 root 1893: return x;
1894:
1.1.1.2 root 1895: if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS
1896: && XEXP (XEXP (x, 0), 0) == reg
1897: && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1898: && INTVAL (XEXP (XEXP (x, 0), 1)) == plusconst)
1899: return x;
1900:
1901: if (code == SIGN_EXTRACT || code == ZERO_EXTRACT)
1902: {
1903: /* If REG occurs inside a MEM used in a bit-field reference,
1904: that is unacceptable. */
1905: if (find_use_as_address (XEXP (x, 0), reg, 0) != 0)
1906: return (rtx) 1;
1907: }
1908:
1.1 root 1909: if (x == reg)
1910: return (rtx) 1;
1911:
1912: for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1913: {
1914: if (fmt[i] == 'e')
1915: {
1.1.1.2 root 1916: tem = find_use_as_address (XEXP (x, i), reg, plusconst);
1.1 root 1917: if (value == 0)
1918: value = tem;
1919: else if (tem != 0)
1920: return (rtx) 1;
1921: }
1922: if (fmt[i] == 'E')
1923: {
1924: register int j;
1925: for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1926: {
1.1.1.2 root 1927: tem = find_use_as_address (XVECEXP (x, i, j), reg, plusconst);
1.1 root 1928: if (value == 0)
1929: value = tem;
1930: else if (tem != 0)
1931: return (rtx) 1;
1932: }
1933: }
1934: }
1935:
1936: return value;
1937: }
1938:
1939: /* Write information about registers and basic blocks into FILE.
1940: This is part of making a debugging dump. */
1941:
1.1.1.2 root 1942: void
1.1 root 1943: dump_flow_info (file)
1944: FILE *file;
1945: {
1946: register int i;
1947: static char *reg_class_names[] = REG_CLASS_NAMES;
1948:
1949: fprintf (file, "%d registers.\n", max_regno);
1950:
1951: for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1952: if (reg_n_refs[i])
1953: {
1954: enum reg_class class;
1955: fprintf (file, "\nRegister %d used %d times across %d insns",
1956: i, reg_n_refs[i], reg_live_length[i]);
1957: if (reg_basic_block[i] >= 0)
1958: fprintf (file, " in block %d", reg_basic_block[i]);
1959: if (reg_n_deaths[i] != 1)
1960: fprintf (file, "; dies in %d places", reg_n_deaths[i]);
1.1.1.12 root 1961: if (reg_n_calls_crossed[i] == 1)
1962: fprintf (file, "; crosses 1 call", reg_n_calls_crossed[i]);
1963: else if (reg_n_calls_crossed[i])
1964: fprintf (file, "; crosses %d calls", reg_n_calls_crossed[i]);
1.1 root 1965: if (PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD)
1966: fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i));
1967: class = reg_preferred_class (i);
1968: if (class != GENERAL_REGS)
1.1.1.2 root 1969: {
1970: if (reg_preferred_or_nothing (i))
1971: fprintf (file, "; %s or none", reg_class_names[(int) class]);
1972: else
1973: fprintf (file, "; pref %s", reg_class_names[(int) class]);
1974: }
1.1 root 1975: if (REGNO_POINTER_FLAG (i))
1976: fprintf (file, "; pointer");
1977: fprintf (file, ".\n");
1978: }
1979: fprintf (file, "\n%d basic blocks.\n", n_basic_blocks);
1980: for (i = 0; i < n_basic_blocks; i++)
1981: {
1982: register rtx head, jump;
1983: register int regno;
1984: fprintf (file, "\nBasic block %d: first insn %d, last %d.\n",
1985: i,
1986: INSN_UID (basic_block_head[i]),
1987: INSN_UID (basic_block_end[i]));
1988: /* The control flow graph's storage is freed
1989: now when flow_analysis returns.
1990: Don't try to print it if it is gone. */
1991: if (basic_block_drops_in)
1992: {
1993: fprintf (file, "Reached from blocks: ");
1994: head = basic_block_head[i];
1995: if (GET_CODE (head) == CODE_LABEL)
1996: for (jump = LABEL_REFS (head);
1997: jump != head;
1998: jump = LABEL_NEXTREF (jump))
1999: {
2000: register from_block = BLOCK_NUM (CONTAINING_INSN (jump));
2001: fprintf (file, " %d", from_block);
2002: }
2003: if (basic_block_drops_in[i])
2004: fprintf (file, " previous");
2005: }
2006: fprintf (file, "\nRegisters live at start:");
2007: for (regno = 0; regno < max_regno; regno++)
2008: {
2009: register int offset = regno / REGSET_ELT_BITS;
2010: register int bit = 1 << (regno % REGSET_ELT_BITS);
2011: if (basic_block_live_at_start[i][offset] & bit)
2012: fprintf (file, " %d", regno);
2013: }
2014: fprintf (file, "\n");
2015: }
2016: fprintf (file, "\n");
2017: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.