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