1 /* Data flow analysis for GNU compiler.
2 Copyright (C) 1987, 88, 92-96, 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
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.
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.
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.
35 ** find_basic_blocks **
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.
42 find_basic_blocks also finds any unreachable loops
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.
51 ** live-register info **
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.
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
61 Two types of elements can be added to an insn's REG_NOTES.
62 A REG_DEAD note is added to an insn's REG_NOTES for any register
63 that meets both of two conditions: The value in the register is not
64 needed in subsequent insns and the insn does not replace the value in
65 the register (in the case of multi-word hard registers, the value in
66 each register must be replaced by the insn to avoid a REG_DEAD note).
68 In the vast majority of cases, an object in a REG_DEAD note will be
69 used somewhere in the insn. The (rare) exception to this is if an
70 insn uses a multi-word hard register and only some of the registers are
71 needed in subsequent insns. In that case, REG_DEAD notes will be
72 provided for those hard registers that are not subsequently needed.
73 Partial REG_DEAD notes of this type do not occur when an insn sets
74 only some of the hard registers used in such a multi-word operand;
75 omitting REG_DEAD notes for objects stored in an insn is optional and
76 the desire to do so does not justify the complexity of the partial
79 REG_UNUSED notes are added for each register that is set by the insn
80 but is unused subsequently (if every register set by the insn is unused
81 and the insn does not reference memory or have some other side-effect,
82 the insn is deleted instead). If only part of a multi-word hard
83 register is used in a subsequent insn, REG_UNUSED notes are made for
84 the parts that will not be used.
86 To determine which registers are live after any insn, one can
87 start from the beginning of the basic block and scan insns, noting
88 which registers are set by each insn and which die there.
90 ** Other actions of life_analysis **
92 life_analysis sets up the LOG_LINKS fields of insns because the
93 information needed to do so is readily available.
95 life_analysis deletes insns whose only effect is to store a value
98 life_analysis notices cases where a reference to a register as
99 a memory address can be combined with a preceding or following
100 incrementation or decrementation of the register. The separate
101 instruction to increment or decrement is deleted and the address
102 is changed to a POST_INC or similar rtx.
104 Each time an incrementing or decrementing address is created,
105 a REG_INC element is added to the insn's REG_NOTES list.
107 life_analysis fills in certain vectors containing information about
108 register usage: reg_n_refs, reg_n_deaths, reg_n_sets, reg_live_length,
109 reg_n_calls_crosses and reg_basic_block. */
114 #include "basic-block.h"
115 #include "insn-config.h"
117 #include "hard-reg-set.h"
123 #define obstack_chunk_alloc xmalloc
124 #define obstack_chunk_free free
126 /* The contents of the current function definition are allocated
127 in this obstack, and all are freed at the end of the function.
128 For top-level functions, this is temporary_obstack.
129 Separate obstacks are made for nested functions. */
131 extern struct obstack
*function_obstack
;
133 /* List of labels that must never be deleted. */
134 extern rtx forced_labels
;
136 /* Get the basic block number of an insn.
137 This info should not be expected to remain available
138 after the end of life_analysis. */
140 /* This is the limit of the allocated space in the following two arrays. */
142 static int max_uid_for_flow
;
144 #define BLOCK_NUM(INSN) uid_block_number[INSN_UID (INSN)]
146 /* This is where the BLOCK_NUM values are really stored.
147 This is set up by find_basic_blocks and used there and in life_analysis,
150 static int *uid_block_number
;
152 /* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile. */
154 #define INSN_VOLATILE(INSN) uid_volatile[INSN_UID (INSN)]
155 static char *uid_volatile
;
157 /* Number of basic blocks in the current function. */
161 /* Maximum register number used in this function, plus one. */
165 /* Maximum number of SCRATCH rtx's used in any basic block of this
170 /* Number of SCRATCH rtx's in the current block. */
172 static int num_scratch
;
174 /* Indexed by n, giving various register information */
176 reg_info
*reg_n_info
;
178 /* Element N is the next insn that uses (hard or pseudo) register number N
179 within the current basic block; or zero, if there is no such insn.
180 This is valid only during the final backward scan in propagate_block. */
182 static rtx
*reg_next_use
;
184 /* Size of a regset for the current function,
185 in (1) bytes and (2) elements. */
190 /* Element N is first insn in basic block N.
191 This info lasts until we finish compiling the function. */
193 rtx
*basic_block_head
;
195 /* Element N is last insn in basic block N.
196 This info lasts until we finish compiling the function. */
198 rtx
*basic_block_end
;
200 /* Element N is a regset describing the registers live
201 at the start of basic block N.
202 This info lasts until we finish compiling the function. */
204 regset
*basic_block_live_at_start
;
206 /* Regset of regs live when calls to `setjmp'-like functions happen. */
208 regset regs_live_at_setjmp
;
210 /* List made of EXPR_LIST rtx's which gives pairs of pseudo registers
211 that have to go in the same hard reg.
212 The first two regs in the list are a pair, and the next two
213 are another pair, etc. */
216 /* Element N is nonzero if control can drop into basic block N
217 from the preceding basic block. Freed after life_analysis. */
219 static char *basic_block_drops_in
;
221 /* Element N is depth within loops of the last insn in basic block number N.
222 Freed after life_analysis. */
224 static short *basic_block_loop_depth
;
226 /* Element N nonzero if basic block N can actually be reached.
227 Vector exists only during find_basic_blocks. */
229 static char *block_live_static
;
231 /* Depth within loops of basic block being scanned for lifetime analysis,
232 plus one. This is the weight attached to references to registers. */
234 static int loop_depth
;
236 /* During propagate_block, this is non-zero if the value of CC0 is live. */
240 /* During propagate_block, this contains the last MEM stored into. It
241 is used to eliminate consecutive stores to the same location. */
243 static rtx last_mem_set
;
245 /* Set of registers that may be eliminable. These are handled specially
246 in updating regs_ever_live. */
248 static HARD_REG_SET elim_reg_set
;
250 /* Forward declarations */
251 static void find_basic_blocks
PROTO((rtx
, rtx
));
252 static void mark_label_ref
PROTO((rtx
, rtx
, int));
253 static void life_analysis
PROTO((rtx
, int));
254 void allocate_for_life_analysis
PROTO((void));
255 void init_regset_vector
PROTO((regset
*, int, struct obstack
*));
256 void free_regset_vector
PROTO((regset
*, int));
257 static void propagate_block
PROTO((regset
, rtx
, rtx
, int,
259 static rtx flow_delete_insn
PROTO((rtx
));
260 static int insn_dead_p
PROTO((rtx
, regset
, int));
261 static int libcall_dead_p
PROTO((rtx
, regset
, rtx
, rtx
));
262 static void mark_set_regs
PROTO((regset
, regset
, rtx
,
264 static void mark_set_1
PROTO((regset
, regset
, rtx
,
266 static void find_auto_inc
PROTO((regset
, rtx
, rtx
));
267 static void mark_used_regs
PROTO((regset
, regset
, rtx
, int, rtx
));
268 static int try_pre_increment_1
PROTO((rtx
));
269 static int try_pre_increment
PROTO((rtx
, rtx
, HOST_WIDE_INT
));
270 void dump_flow_info
PROTO((FILE *));
272 /* Find basic blocks of the current function and perform data flow analysis.
273 F is the first insn of the function and NREGS the number of register numbers
277 flow_analysis (f
, nregs
, file
)
284 rtx nonlocal_label_list
= nonlocal_label_rtx_list ();
286 #ifdef ELIMINABLE_REGS
287 static struct {int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
290 /* Record which registers will be eliminated. We use this in
293 CLEAR_HARD_REG_SET (elim_reg_set
);
295 #ifdef ELIMINABLE_REGS
296 for (i
= 0; i
< sizeof eliminables
/ sizeof eliminables
[0]; i
++)
297 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
299 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
302 /* Count the basic blocks. Also find maximum insn uid value used. */
305 register RTX_CODE prev_code
= JUMP_INSN
;
306 register RTX_CODE code
;
308 max_uid_for_flow
= 0;
310 for (insn
= f
, i
= 0; insn
; insn
= NEXT_INSN (insn
))
312 code
= GET_CODE (insn
);
313 if (INSN_UID (insn
) > max_uid_for_flow
)
314 max_uid_for_flow
= INSN_UID (insn
);
315 if (code
== CODE_LABEL
316 || (GET_RTX_CLASS (code
) == 'i'
317 && (prev_code
== JUMP_INSN
318 || (prev_code
== CALL_INSN
319 && nonlocal_label_list
!= 0)
320 || prev_code
== BARRIER
)))
323 if (code
== CALL_INSN
&& find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
332 /* Leave space for insns we make in some cases for auto-inc. These cases
333 are rare, so we don't need too much space. */
334 max_uid_for_flow
+= max_uid_for_flow
/ 10;
337 /* Allocate some tables that last till end of compiling this function
338 and some needed only in find_basic_blocks and life_analysis. */
341 basic_block_head
= (rtx
*) oballoc (n_basic_blocks
* sizeof (rtx
));
342 basic_block_end
= (rtx
*) oballoc (n_basic_blocks
* sizeof (rtx
));
343 basic_block_drops_in
= (char *) alloca (n_basic_blocks
);
344 basic_block_loop_depth
= (short *) alloca (n_basic_blocks
* sizeof (short));
346 = (int *) alloca ((max_uid_for_flow
+ 1) * sizeof (int));
347 uid_volatile
= (char *) alloca (max_uid_for_flow
+ 1);
348 bzero (uid_volatile
, max_uid_for_flow
+ 1);
350 find_basic_blocks (f
, nonlocal_label_list
);
351 life_analysis (f
, nregs
);
353 dump_flow_info (file
);
355 basic_block_drops_in
= 0;
356 uid_block_number
= 0;
357 basic_block_loop_depth
= 0;
360 /* Find all basic blocks of the function whose first insn is F.
361 Store the correct data in the tables that describe the basic blocks,
362 set up the chains of references for each CODE_LABEL, and
363 delete any entire basic blocks that cannot be reached.
365 NONLOCAL_LABEL_LIST is the same local variable from flow_analysis. */
368 find_basic_blocks (f
, nonlocal_label_list
)
369 rtx f
, nonlocal_label_list
;
373 register char *block_live
= (char *) alloca (n_basic_blocks
);
374 register char *block_marked
= (char *) alloca (n_basic_blocks
);
375 /* An array of CODE_LABELs, indexed by UID for the start of the active
376 EH handler for each insn in F. */
377 rtx
*active_eh_handler
;
378 /* List of label_refs to all labels whose addresses are taken
380 rtx label_value_list
;
381 rtx x
, note
, eh_note
;
382 enum rtx_code prev_code
, code
;
386 active_eh_handler
= (rtx
*) alloca ((max_uid_for_flow
+ 1) * sizeof (rtx
));
389 label_value_list
= 0;
390 block_live_static
= block_live
;
391 bzero (block_live
, n_basic_blocks
);
392 bzero (block_marked
, n_basic_blocks
);
393 bzero (active_eh_handler
, (max_uid_for_flow
+ 1) * sizeof (rtx
));
395 /* Initialize with just block 0 reachable and no blocks marked. */
396 if (n_basic_blocks
> 0)
399 /* Initialize the ref chain of each label to 0. Record where all the
400 blocks start and end and their depth in loops. For each insn, record
401 the block it is in. Also mark as reachable any blocks headed by labels
402 that must not be deleted. */
404 for (eh_note
= NULL_RTX
, insn
= f
, i
= -1, prev_code
= JUMP_INSN
, depth
= 1;
405 insn
; insn
= NEXT_INSN (insn
))
407 code
= GET_CODE (insn
);
410 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
)
412 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
)
416 /* A basic block starts at label, or after something that can jump. */
417 else if (code
== CODE_LABEL
418 || (GET_RTX_CLASS (code
) == 'i'
419 && (prev_code
== JUMP_INSN
420 || (prev_code
== CALL_INSN
421 && nonlocal_label_list
!= 0
422 && ! find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
423 || prev_code
== BARRIER
)))
425 basic_block_head
[++i
] = insn
;
426 basic_block_end
[i
] = insn
;
427 basic_block_loop_depth
[i
] = depth
;
429 if (code
== CODE_LABEL
)
431 LABEL_REFS (insn
) = insn
;
432 /* Any label that cannot be deleted
433 is considered to start a reachable block. */
434 if (LABEL_PRESERVE_P (insn
))
439 else if (GET_RTX_CLASS (code
) == 'i')
441 basic_block_end
[i
] = insn
;
442 basic_block_loop_depth
[i
] = depth
;
445 if (GET_RTX_CLASS (code
) == 'i')
447 /* Make a list of all labels referred to other than by jumps. */
448 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
449 if (REG_NOTE_KIND (note
) == REG_LABEL
)
450 label_value_list
= gen_rtx (EXPR_LIST
, VOIDmode
, XEXP (note
, 0),
454 /* Keep a lifo list of the currently active exception handlers. */
455 if (GET_CODE (insn
) == NOTE
)
457 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_BEG
)
459 for (x
= exception_handler_labels
; x
; x
= XEXP (x
, 1))
460 if (CODE_LABEL_NUMBER (XEXP (x
, 0)) == NOTE_BLOCK_NUMBER (insn
))
462 eh_note
= gen_rtx (EXPR_LIST
, VOIDmode
,
463 XEXP (x
, 0), eh_note
);
469 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_END
)
470 eh_note
= XEXP (eh_note
, 1);
472 /* If we encounter a CALL_INSN, note which exception handler it
473 might pass control to.
475 If doing asynchronous exceptions, record the active EH handler
476 for every insn, since most insns can throw. */
478 && (asynchronous_exceptions
479 || (GET_CODE (insn
) == CALL_INSN
480 && ! find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))))
481 active_eh_handler
[INSN_UID (insn
)] = XEXP (eh_note
, 0);
483 BLOCK_NUM (insn
) = i
;
489 /* During the second pass, `n_basic_blocks' is only an upper bound.
490 Only perform the sanity check for the first pass, and on the second
491 pass ensure `n_basic_blocks' is set to the correct value. */
492 if (pass
== 1 && i
+ 1 != n_basic_blocks
)
494 n_basic_blocks
= i
+ 1;
496 /* Record which basic blocks control can drop in to. */
498 for (i
= 0; i
< n_basic_blocks
; i
++)
500 for (insn
= PREV_INSN (basic_block_head
[i
]);
501 insn
&& GET_CODE (insn
) == NOTE
; insn
= PREV_INSN (insn
))
504 basic_block_drops_in
[i
] = insn
&& GET_CODE (insn
) != BARRIER
;
507 /* Now find which basic blocks can actually be reached
508 and put all jump insns' LABEL_REFS onto the ref-chains
509 of their target labels. */
511 if (n_basic_blocks
> 0)
513 int something_marked
= 1;
516 /* Pass over all blocks, marking each block that is reachable
517 and has not yet been marked.
518 Keep doing this until, in one pass, no blocks have been marked.
519 Then blocks_live and blocks_marked are identical and correct.
520 In addition, all jumps actually reachable have been marked. */
522 while (something_marked
)
524 something_marked
= 0;
525 for (i
= 0; i
< n_basic_blocks
; i
++)
526 if (block_live
[i
] && !block_marked
[i
])
529 something_marked
= 1;
530 if (i
+ 1 < n_basic_blocks
&& basic_block_drops_in
[i
+ 1])
531 block_live
[i
+ 1] = 1;
532 insn
= basic_block_end
[i
];
533 if (GET_CODE (insn
) == JUMP_INSN
)
534 mark_label_ref (PATTERN (insn
), insn
, 0);
536 /* If we have any forced labels, mark them as potentially
537 reachable from this block. */
538 for (x
= forced_labels
; x
; x
= XEXP (x
, 1))
539 if (! LABEL_REF_NONLOCAL_P (x
))
540 mark_label_ref (gen_rtx (LABEL_REF
, VOIDmode
, XEXP (x
, 0)),
543 /* Now scan the insns for this block, we may need to make
544 edges for some of them to various non-obvious locations
545 (exception handlers, nonlocal labels, etc). */
546 for (insn
= basic_block_head
[i
];
547 insn
!= NEXT_INSN (basic_block_end
[i
]);
548 insn
= NEXT_INSN (insn
))
550 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
553 /* References to labels in non-jumping insns have
554 REG_LABEL notes attached to them.
556 This can happen for computed gotos; we don't care
557 about them here since the values are also on the
558 label_value_list and will be marked live if we find
559 a live computed goto.
561 This can also happen when we take the address of
562 a label to pass as an argument to __throw. Note
563 throw only uses the value to determine what handler
564 should be called -- ie the label is not used as
565 a jump target, it just marks regions in the code.
567 In theory we should be able to ignore the REG_LABEL
568 notes, but we have to make sure that the label and
569 associated insns aren't marked dead, so we make
570 the block in question live and create an edge from
571 this insn to the label. This is not strictly
572 correct, but it is close enough for now. */
573 for (note
= REG_NOTES (insn
);
575 note
= XEXP (note
, 1))
577 if (REG_NOTE_KIND (note
) == REG_LABEL
)
580 block_live
[BLOCK_NUM (x
)] = 1;
581 mark_label_ref (gen_rtx (LABEL_REF
,
587 /* If this is a computed jump, then mark it as
588 reaching everything on the label_value_list
589 and forced_labels list. */
590 if (computed_jump_p (insn
))
592 for (x
= label_value_list
; x
; x
= XEXP (x
, 1))
593 mark_label_ref (gen_rtx (LABEL_REF
, VOIDmode
,
597 for (x
= forced_labels
; x
; x
= XEXP (x
, 1))
598 mark_label_ref (gen_rtx (LABEL_REF
, VOIDmode
,
603 /* If this is a CALL_INSN, then mark it as reaching
604 the active EH handler for this CALL_INSN. If
605 we're handling asynchronous exceptions mark every
606 insn as reaching the active EH handler.
608 Also mark the CALL_INSN as reaching any nonlocal
610 else if (asynchronous_exceptions
611 || (GET_CODE (insn
) == CALL_INSN
612 && ! find_reg_note (insn
, REG_RETVAL
,
615 if (active_eh_handler
[INSN_UID (insn
)])
616 mark_label_ref (gen_rtx (LABEL_REF
, VOIDmode
,
617 active_eh_handler
[INSN_UID (insn
)]),
620 if (!asynchronous_exceptions
)
622 for (x
= nonlocal_label_list
;
625 mark_label_ref (gen_rtx (LABEL_REF
, VOIDmode
,
629 /* ??? This could be made smarter:
630 in some cases it's possible to tell that
631 certain calls will not do a nonlocal goto.
633 For example, if the nested functions that
634 do the nonlocal gotos do not have their
635 addresses taken, then only calls to those
636 functions or to other nested functions that
637 use them could possibly do nonlocal gotos. */
644 /* This should never happen. If it does that means we've computed an
645 incorrect flow graph, which can lead to aborts/crashes later in the
646 compiler or incorrect code generation.
648 We used to try and continue here, but that's just asking for trouble
649 later during the compile or at runtime. It's easier to debug the
650 problem here than later! */
651 for (i
= 1; i
< n_basic_blocks
; i
++)
652 if (block_live
[i
] && ! basic_block_drops_in
[i
]
653 && GET_CODE (basic_block_head
[i
]) == CODE_LABEL
654 && LABEL_REFS (basic_block_head
[i
]) == basic_block_head
[i
])
657 /* Now delete the code for any basic blocks that can't be reached.
658 They can occur because jump_optimize does not recognize
659 unreachable loops as unreachable. */
662 for (i
= 0; i
< n_basic_blocks
; i
++)
667 /* Delete the insns in a (non-live) block. We physically delete
668 every non-note insn except the start and end (so
669 basic_block_head/end needn't be updated), we turn the latter
670 into NOTE_INSN_DELETED notes.
671 We use to "delete" the insns by turning them into notes, but
672 we may be deleting lots of insns that subsequent passes would
673 otherwise have to process. Secondly, lots of deleted blocks in
674 a row can really slow down propagate_block since it will
675 otherwise process insn-turned-notes multiple times when it
676 looks for loop begin/end notes. */
677 if (basic_block_head
[i
] != basic_block_end
[i
])
679 /* It would be quicker to delete all of these with a single
680 unchaining, rather than one at a time, but we need to keep
682 insn
= NEXT_INSN (basic_block_head
[i
]);
683 while (insn
!= basic_block_end
[i
])
685 if (GET_CODE (insn
) == BARRIER
)
687 else if (GET_CODE (insn
) != NOTE
)
688 insn
= flow_delete_insn (insn
);
690 insn
= NEXT_INSN (insn
);
693 insn
= basic_block_head
[i
];
694 if (GET_CODE (insn
) != NOTE
)
696 /* Turn the head into a deleted insn note. */
697 if (GET_CODE (insn
) == BARRIER
)
700 /* If the head of this block is a CODE_LABEL, then it might
701 be the label for an exception handler which can't be
704 We need to remove the label from the exception_handler_label
705 list and remove the associated NOTE_EH_REGION_BEG and
706 NOTE_EH_REGION_END notes. */
707 if (GET_CODE (insn
) == CODE_LABEL
)
709 rtx x
, *prev
= &exception_handler_labels
;
711 for (x
= exception_handler_labels
; x
; x
= XEXP (x
, 1))
713 if (XEXP (x
, 0) == insn
)
715 /* Found a match, splice this label out of the
718 XEXP (x
, 1) = NULL_RTX
;
719 XEXP (x
, 0) = NULL_RTX
;
721 /* Now we have to find the EH_BEG and EH_END notes
722 associated with this label and remove them. */
724 for (x
= get_insns (); x
; x
= NEXT_INSN (x
))
726 if (GET_CODE (x
) == NOTE
727 && ((NOTE_LINE_NUMBER (x
)
728 == NOTE_INSN_EH_REGION_BEG
)
729 || (NOTE_LINE_NUMBER (x
)
730 == NOTE_INSN_EH_REGION_END
))
731 && (NOTE_BLOCK_NUMBER (x
)
732 == CODE_LABEL_NUMBER (insn
)))
734 NOTE_LINE_NUMBER (x
) = NOTE_INSN_DELETED
;
735 NOTE_SOURCE_FILE (x
) = 0;
744 PUT_CODE (insn
, NOTE
);
745 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
746 NOTE_SOURCE_FILE (insn
) = 0;
748 insn
= basic_block_end
[i
];
749 if (GET_CODE (insn
) != NOTE
)
751 /* Turn the tail into a deleted insn note. */
752 if (GET_CODE (insn
) == BARRIER
)
754 PUT_CODE (insn
, NOTE
);
755 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
756 NOTE_SOURCE_FILE (insn
) = 0;
758 /* BARRIERs are between basic blocks, not part of one.
759 Delete a BARRIER if the preceding jump is deleted.
760 We cannot alter a BARRIER into a NOTE
761 because it is too short; but we can really delete
762 it because it is not part of a basic block. */
763 if (NEXT_INSN (insn
) != 0
764 && GET_CODE (NEXT_INSN (insn
)) == BARRIER
)
765 delete_insn (NEXT_INSN (insn
));
767 /* Each time we delete some basic blocks,
768 see if there is a jump around them that is
769 being turned into a no-op. If so, delete it. */
771 if (block_live
[i
- 1])
774 for (j
= i
+ 1; j
< n_basic_blocks
; j
++)
778 insn
= basic_block_end
[i
- 1];
779 if (GET_CODE (insn
) == JUMP_INSN
780 /* An unconditional jump is the only possibility
781 we must check for, since a conditional one
782 would make these blocks live. */
783 && simplejump_p (insn
)
784 && (label
= XEXP (SET_SRC (PATTERN (insn
)), 0), 1)
785 && INSN_UID (label
) != 0
786 && BLOCK_NUM (label
) == j
)
788 PUT_CODE (insn
, NOTE
);
789 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
790 NOTE_SOURCE_FILE (insn
) = 0;
791 if (GET_CODE (NEXT_INSN (insn
)) != BARRIER
)
793 delete_insn (NEXT_INSN (insn
));
800 /* There are pathological cases where one function calling hundreds of
801 nested inline functions can generate lots and lots of unreachable
802 blocks that jump can't delete. Since we don't use sparse matrices
803 a lot of memory will be needed to compile such functions.
804 Implementing sparse matrices is a fair bit of work and it is not
805 clear that they win more than they lose (we don't want to
806 unnecessarily slow down compilation of normal code). By making
807 another pass for the pathological case, we can greatly speed up
808 their compilation without hurting normal code. This works because
809 all the insns in the unreachable blocks have either been deleted or
811 Note that we're talking about reducing memory usage by 10's of
812 megabytes and reducing compilation time by several minutes. */
813 /* ??? The choice of when to make another pass is a bit arbitrary,
814 and was derived from empirical data. */
819 n_basic_blocks
-= deleted
;
820 /* `n_basic_blocks' may not be correct at this point: two previously
821 separate blocks may now be merged. That's ok though as we
822 recalculate it during the second pass. It certainly can't be
823 any larger than the current value. */
829 /* Subroutines of find_basic_blocks. */
831 /* Check expression X for label references;
832 if one is found, add INSN to the label's chain of references.
834 CHECKDUP means check for and avoid creating duplicate references
835 from the same insn. Such duplicates do no serious harm but
836 can slow life analysis. CHECKDUP is set only when duplicates
840 mark_label_ref (x
, insn
, checkdup
)
844 register RTX_CODE code
;
848 /* We can be called with NULL when scanning label_value_list. */
853 if (code
== LABEL_REF
)
855 register rtx label
= XEXP (x
, 0);
857 if (GET_CODE (label
) != CODE_LABEL
)
859 /* If the label was never emitted, this insn is junk,
860 but avoid a crash trying to refer to BLOCK_NUM (label).
861 This can happen as a result of a syntax error
862 and a diagnostic has already been printed. */
863 if (INSN_UID (label
) == 0)
865 CONTAINING_INSN (x
) = insn
;
866 /* if CHECKDUP is set, check for duplicate ref from same insn
869 for (y
= LABEL_REFS (label
); y
!= label
; y
= LABEL_NEXTREF (y
))
870 if (CONTAINING_INSN (y
) == insn
)
872 LABEL_NEXTREF (x
) = LABEL_REFS (label
);
873 LABEL_REFS (label
) = x
;
874 block_live_static
[BLOCK_NUM (label
)] = 1;
878 fmt
= GET_RTX_FORMAT (code
);
879 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
882 mark_label_ref (XEXP (x
, i
), insn
, 0);
886 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
887 mark_label_ref (XVECEXP (x
, i
, j
), insn
, 1);
892 /* Delete INSN by patching it out.
893 Return the next insn. */
896 flow_delete_insn (insn
)
899 /* ??? For the moment we assume we don't have to watch for NULLs here
900 since the start/end of basic blocks aren't deleted like this. */
901 NEXT_INSN (PREV_INSN (insn
)) = NEXT_INSN (insn
);
902 PREV_INSN (NEXT_INSN (insn
)) = PREV_INSN (insn
);
903 return NEXT_INSN (insn
);
906 /* Determine which registers are live at the start of each
907 basic block of the function whose first insn is F.
908 NREGS is the number of registers used in F.
909 We allocate the vector basic_block_live_at_start
910 and the regsets that it points to, and fill them with the data.
911 regset_size and regset_bytes are also set here. */
914 life_analysis (f
, nregs
)
920 /* For each basic block, a bitmask of regs
921 live on exit from the block. */
922 regset
*basic_block_live_at_end
;
923 /* For each basic block, a bitmask of regs
924 live on entry to a successor-block of this block.
925 If this does not match basic_block_live_at_end,
926 that must be updated, and the block must be rescanned. */
927 regset
*basic_block_new_live_at_end
;
928 /* For each basic block, a bitmask of regs
929 whose liveness at the end of the basic block
930 can make a difference in which regs are live on entry to the block.
931 These are the regs that are set within the basic block,
932 possibly excluding those that are used after they are set. */
933 regset
*basic_block_significant
;
937 struct obstack flow_obstack
;
939 gcc_obstack_init (&flow_obstack
);
943 bzero (regs_ever_live
, sizeof regs_ever_live
);
945 /* Allocate and zero out many data structures
946 that will record the data from lifetime analysis. */
948 allocate_for_life_analysis ();
950 reg_next_use
= (rtx
*) alloca (nregs
* sizeof (rtx
));
951 bzero ((char *) reg_next_use
, nregs
* sizeof (rtx
));
953 /* Set up several regset-vectors used internally within this function.
954 Their meanings are documented above, with their declarations. */
956 basic_block_live_at_end
957 = (regset
*) alloca (n_basic_blocks
* sizeof (regset
));
959 /* Don't use alloca since that leads to a crash rather than an error message
960 if there isn't enough space.
961 Don't use oballoc since we may need to allocate other things during
962 this function on the temporary obstack. */
963 init_regset_vector (basic_block_live_at_end
, n_basic_blocks
, &flow_obstack
);
965 basic_block_new_live_at_end
966 = (regset
*) alloca (n_basic_blocks
* sizeof (regset
));
967 init_regset_vector (basic_block_new_live_at_end
, n_basic_blocks
,
970 basic_block_significant
971 = (regset
*) alloca (n_basic_blocks
* sizeof (regset
));
972 init_regset_vector (basic_block_significant
, n_basic_blocks
, &flow_obstack
);
974 /* Record which insns refer to any volatile memory
975 or for any reason can't be deleted just because they are dead stores.
976 Also, delete any insns that copy a register to itself. */
978 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
980 enum rtx_code code1
= GET_CODE (insn
);
981 if (code1
== CALL_INSN
)
982 INSN_VOLATILE (insn
) = 1;
983 else if (code1
== INSN
|| code1
== JUMP_INSN
)
985 /* Delete (in effect) any obvious no-op moves. */
986 if (GET_CODE (PATTERN (insn
)) == SET
987 && GET_CODE (SET_DEST (PATTERN (insn
))) == REG
988 && GET_CODE (SET_SRC (PATTERN (insn
))) == REG
989 && (REGNO (SET_DEST (PATTERN (insn
)))
990 == REGNO (SET_SRC (PATTERN (insn
))))
991 /* Insns carrying these notes are useful later on. */
992 && ! find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
994 PUT_CODE (insn
, NOTE
);
995 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
996 NOTE_SOURCE_FILE (insn
) = 0;
998 /* Delete (in effect) any obvious no-op moves. */
999 else if (GET_CODE (PATTERN (insn
)) == SET
1000 && GET_CODE (SET_DEST (PATTERN (insn
))) == SUBREG
1001 && GET_CODE (SUBREG_REG (SET_DEST (PATTERN (insn
)))) == REG
1002 && GET_CODE (SET_SRC (PATTERN (insn
))) == SUBREG
1003 && GET_CODE (SUBREG_REG (SET_SRC (PATTERN (insn
)))) == REG
1004 && (REGNO (SUBREG_REG (SET_DEST (PATTERN (insn
))))
1005 == REGNO (SUBREG_REG (SET_SRC (PATTERN (insn
)))))
1006 && SUBREG_WORD (SET_DEST (PATTERN (insn
))) ==
1007 SUBREG_WORD (SET_SRC (PATTERN (insn
)))
1008 /* Insns carrying these notes are useful later on. */
1009 && ! find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
1011 PUT_CODE (insn
, NOTE
);
1012 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1013 NOTE_SOURCE_FILE (insn
) = 0;
1015 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1017 /* If nothing but SETs of registers to themselves,
1018 this insn can also be deleted. */
1019 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
1021 rtx tem
= XVECEXP (PATTERN (insn
), 0, i
);
1023 if (GET_CODE (tem
) == USE
1024 || GET_CODE (tem
) == CLOBBER
)
1027 if (GET_CODE (tem
) != SET
1028 || GET_CODE (SET_DEST (tem
)) != REG
1029 || GET_CODE (SET_SRC (tem
)) != REG
1030 || REGNO (SET_DEST (tem
)) != REGNO (SET_SRC (tem
)))
1034 if (i
== XVECLEN (PATTERN (insn
), 0)
1035 /* Insns carrying these notes are useful later on. */
1036 && ! find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
1038 PUT_CODE (insn
, NOTE
);
1039 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1040 NOTE_SOURCE_FILE (insn
) = 0;
1043 INSN_VOLATILE (insn
) = volatile_refs_p (PATTERN (insn
));
1045 else if (GET_CODE (PATTERN (insn
)) != USE
)
1046 INSN_VOLATILE (insn
) = volatile_refs_p (PATTERN (insn
));
1047 /* A SET that makes space on the stack cannot be dead.
1048 (Such SETs occur only for allocating variable-size data,
1049 so they will always have a PLUS or MINUS according to the
1050 direction of stack growth.)
1051 Even if this function never uses this stack pointer value,
1052 signal handlers do! */
1053 else if (code1
== INSN
&& GET_CODE (PATTERN (insn
)) == SET
1054 && SET_DEST (PATTERN (insn
)) == stack_pointer_rtx
1055 #ifdef STACK_GROWS_DOWNWARD
1056 && GET_CODE (SET_SRC (PATTERN (insn
))) == MINUS
1058 && GET_CODE (SET_SRC (PATTERN (insn
))) == PLUS
1060 && XEXP (SET_SRC (PATTERN (insn
)), 0) == stack_pointer_rtx
)
1061 INSN_VOLATILE (insn
) = 1;
1065 if (n_basic_blocks
> 0)
1066 #ifdef EXIT_IGNORE_STACK
1067 if (! EXIT_IGNORE_STACK
1068 || (! FRAME_POINTER_REQUIRED
&& flag_omit_frame_pointer
))
1071 /* If exiting needs the right stack value,
1072 consider the stack pointer live at the end of the function. */
1073 SET_REGNO_REG_SET (basic_block_live_at_end
[n_basic_blocks
- 1],
1074 STACK_POINTER_REGNUM
);
1075 SET_REGNO_REG_SET (basic_block_new_live_at_end
[n_basic_blocks
- 1],
1076 STACK_POINTER_REGNUM
);
1079 /* Mark the frame pointer is needed at the end of the function. If
1080 we end up eliminating it, it will be removed from the live list
1081 of each basic block by reload. */
1083 if (n_basic_blocks
> 0)
1085 SET_REGNO_REG_SET (basic_block_live_at_end
[n_basic_blocks
- 1],
1086 FRAME_POINTER_REGNUM
);
1087 SET_REGNO_REG_SET (basic_block_new_live_at_end
[n_basic_blocks
- 1],
1088 FRAME_POINTER_REGNUM
);
1089 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
1090 /* If they are different, also mark the hard frame pointer as live */
1091 SET_REGNO_REG_SET (basic_block_live_at_end
[n_basic_blocks
- 1],
1092 HARD_FRAME_POINTER_REGNUM
);
1093 SET_REGNO_REG_SET (basic_block_new_live_at_end
[n_basic_blocks
- 1],
1094 HARD_FRAME_POINTER_REGNUM
);
1098 /* Mark all global registers and all registers used by the epilogue
1099 as being live at the end of the function since they may be
1100 referenced by our caller. */
1102 if (n_basic_blocks
> 0)
1103 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1105 #ifdef EPILOGUE_USES
1106 || EPILOGUE_USES (i
)
1110 SET_REGNO_REG_SET (basic_block_live_at_end
[n_basic_blocks
- 1], i
);
1111 SET_REGNO_REG_SET (basic_block_new_live_at_end
[n_basic_blocks
- 1], i
);
1114 /* Propagate life info through the basic blocks
1115 around the graph of basic blocks.
1117 This is a relaxation process: each time a new register
1118 is live at the end of the basic block, we must scan the block
1119 to determine which registers are, as a consequence, live at the beginning
1120 of that block. These registers must then be marked live at the ends
1121 of all the blocks that can transfer control to that block.
1122 The process continues until it reaches a fixed point. */
1129 for (i
= n_basic_blocks
- 1; i
>= 0; i
--)
1131 int consider
= first_pass
;
1132 int must_rescan
= first_pass
;
1137 /* Set CONSIDER if this block needs thinking about at all
1138 (that is, if the regs live now at the end of it
1139 are not the same as were live at the end of it when
1140 we last thought about it).
1141 Set must_rescan if it needs to be thought about
1142 instruction by instruction (that is, if any additional
1143 reg that is live at the end now but was not live there before
1144 is one of the significant regs of this basic block). */
1146 EXECUTE_IF_AND_COMPL_IN_REG_SET
1147 (basic_block_new_live_at_end
[i
],
1148 basic_block_live_at_end
[i
], 0, j
,
1151 if (REGNO_REG_SET_P (basic_block_significant
[i
], j
))
1162 /* The live_at_start of this block may be changing,
1163 so another pass will be required after this one. */
1168 /* No complete rescan needed;
1169 just record those variables newly known live at end
1170 as live at start as well. */
1171 IOR_AND_COMPL_REG_SET (basic_block_live_at_start
[i
],
1172 basic_block_new_live_at_end
[i
],
1173 basic_block_live_at_end
[i
]);
1175 IOR_AND_COMPL_REG_SET (basic_block_live_at_end
[i
],
1176 basic_block_new_live_at_end
[i
],
1177 basic_block_live_at_end
[i
]);
1181 /* Update the basic_block_live_at_start
1182 by propagation backwards through the block. */
1183 COPY_REG_SET (basic_block_live_at_end
[i
],
1184 basic_block_new_live_at_end
[i
]);
1185 COPY_REG_SET (basic_block_live_at_start
[i
],
1186 basic_block_live_at_end
[i
]);
1187 propagate_block (basic_block_live_at_start
[i
],
1188 basic_block_head
[i
], basic_block_end
[i
], 0,
1189 first_pass
? basic_block_significant
[i
]
1195 register rtx jump
, head
;
1197 /* Update the basic_block_new_live_at_end's of the block
1198 that falls through into this one (if any). */
1199 head
= basic_block_head
[i
];
1200 if (basic_block_drops_in
[i
])
1201 IOR_REG_SET (basic_block_new_live_at_end
[i
-1],
1202 basic_block_live_at_start
[i
]);
1204 /* Update the basic_block_new_live_at_end's of
1205 all the blocks that jump to this one. */
1206 if (GET_CODE (head
) == CODE_LABEL
)
1207 for (jump
= LABEL_REFS (head
);
1209 jump
= LABEL_NEXTREF (jump
))
1211 register int from_block
= BLOCK_NUM (CONTAINING_INSN (jump
));
1212 IOR_REG_SET (basic_block_new_live_at_end
[from_block
],
1213 basic_block_live_at_start
[i
]);
1223 /* The only pseudos that are live at the beginning of the function are
1224 those that were not set anywhere in the function. local-alloc doesn't
1225 know how to handle these correctly, so mark them as not local to any
1228 if (n_basic_blocks
> 0)
1229 EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start
[0],
1230 FIRST_PSEUDO_REGISTER
, i
,
1232 REG_BASIC_BLOCK (i
) = REG_BLOCK_GLOBAL
;
1235 /* Now the life information is accurate.
1236 Make one more pass over each basic block
1237 to delete dead stores, create autoincrement addressing
1238 and record how many times each register is used, is set, or dies.
1240 To save time, we operate directly in basic_block_live_at_end[i],
1241 thus destroying it (in fact, converting it into a copy of
1242 basic_block_live_at_start[i]). This is ok now because
1243 basic_block_live_at_end[i] is no longer used past this point. */
1247 for (i
= 0; i
< n_basic_blocks
; i
++)
1249 propagate_block (basic_block_live_at_end
[i
],
1250 basic_block_head
[i
], basic_block_end
[i
], 1,
1258 /* Something live during a setjmp should not be put in a register
1259 on certain machines which restore regs from stack frames
1260 rather than from the jmpbuf.
1261 But we don't need to do this for the user's variables, since
1262 ANSI says only volatile variables need this. */
1263 #ifdef LONGJMP_RESTORE_FROM_STACK
1264 EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp
,
1265 FIRST_PSEUDO_REGISTER
, i
,
1267 if (regno_reg_rtx
[i
] != 0
1268 && ! REG_USERVAR_P (regno_reg_rtx
[i
]))
1270 REG_LIVE_LENGTH (i
) = -1;
1271 REG_BASIC_BLOCK (i
) = -1;
1277 /* We have a problem with any pseudoreg that
1278 lives across the setjmp. ANSI says that if a
1279 user variable does not change in value
1280 between the setjmp and the longjmp, then the longjmp preserves it.
1281 This includes longjmp from a place where the pseudo appears dead.
1282 (In principle, the value still exists if it is in scope.)
1283 If the pseudo goes in a hard reg, some other value may occupy
1284 that hard reg where this pseudo is dead, thus clobbering the pseudo.
1285 Conclusion: such a pseudo must not go in a hard reg. */
1286 EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp
,
1287 FIRST_PSEUDO_REGISTER
, i
,
1289 if (regno_reg_rtx
[i
] != 0)
1291 REG_LIVE_LENGTH (i
) = -1;
1292 REG_BASIC_BLOCK (i
) = -1;
1297 free_regset_vector (basic_block_live_at_end
, n_basic_blocks
);
1298 free_regset_vector (basic_block_new_live_at_end
, n_basic_blocks
);
1299 free_regset_vector (basic_block_significant
, n_basic_blocks
);
1300 basic_block_live_at_end
= (regset
*)0;
1301 basic_block_new_live_at_end
= (regset
*)0;
1302 basic_block_significant
= (regset
*)0;
1304 obstack_free (&flow_obstack
, NULL_PTR
);
1307 /* Subroutines of life analysis. */
1309 /* Allocate the permanent data structures that represent the results
1310 of life analysis. Not static since used also for stupid life analysis. */
1313 allocate_for_life_analysis ()
1317 /* Recalculate the register space, in case it has grown. Old style
1318 vector oriented regsets would set regset_{size,bytes} here also. */
1319 allocate_reg_info (max_regno
, FALSE
, FALSE
);
1321 /* Because both reg_scan and flow_analysis want to set up the REG_N_SETS
1322 information, explicitly reset it here. The allocation should have
1323 already happened on the previous reg_scan pass. Make sure in case
1324 some more registers were allocated. */
1325 for (i
= 0; i
< max_regno
; i
++)
1328 basic_block_live_at_start
1329 = (regset
*) oballoc (n_basic_blocks
* sizeof (regset
));
1330 init_regset_vector (basic_block_live_at_start
, n_basic_blocks
,
1333 regs_live_at_setjmp
= OBSTACK_ALLOC_REG_SET (function_obstack
);
1334 CLEAR_REG_SET (regs_live_at_setjmp
);
1337 /* Make each element of VECTOR point at a regset. The vector has
1338 NELTS elements, and space is allocated from the ALLOC_OBSTACK
1342 init_regset_vector (vector
, nelts
, alloc_obstack
)
1345 struct obstack
*alloc_obstack
;
1349 for (i
= 0; i
< nelts
; i
++)
1351 vector
[i
] = OBSTACK_ALLOC_REG_SET (alloc_obstack
);
1352 CLEAR_REG_SET (vector
[i
]);
1356 /* Release any additional space allocated for each element of VECTOR point
1357 other than the regset header itself. The vector has NELTS elements. */
1360 free_regset_vector (vector
, nelts
)
1366 for (i
= 0; i
< nelts
; i
++)
1367 FREE_REG_SET (vector
[i
]);
1370 /* Compute the registers live at the beginning of a basic block
1371 from those live at the end.
1373 When called, OLD contains those live at the end.
1374 On return, it contains those live at the beginning.
1375 FIRST and LAST are the first and last insns of the basic block.
1377 FINAL is nonzero if we are doing the final pass which is not
1378 for computing the life info (since that has already been done)
1379 but for acting on it. On this pass, we delete dead stores,
1380 set up the logical links and dead-variables lists of instructions,
1381 and merge instructions for autoincrement and autodecrement addresses.
1383 SIGNIFICANT is nonzero only the first time for each basic block.
1384 If it is nonzero, it points to a regset in which we store
1385 a 1 for each register that is set within the block.
1387 BNUM is the number of the basic block. */
1390 propagate_block (old
, first
, last
, final
, significant
, bnum
)
1391 register regset old
;
1403 /* The following variables are used only if FINAL is nonzero. */
1404 /* This vector gets one element for each reg that has been live
1405 at any point in the basic block that has been scanned so far.
1406 SOMETIMES_MAX says how many elements are in use so far. */
1407 register int *regs_sometimes_live
;
1408 int sometimes_max
= 0;
1409 /* This regset has 1 for each reg that we have seen live so far.
1410 It and REGS_SOMETIMES_LIVE are updated together. */
1413 /* The loop depth may change in the middle of a basic block. Since we
1414 scan from end to beginning, we start with the depth at the end of the
1415 current basic block, and adjust as we pass ends and starts of loops. */
1416 loop_depth
= basic_block_loop_depth
[bnum
];
1418 dead
= ALLOCA_REG_SET ();
1419 live
= ALLOCA_REG_SET ();
1424 /* Include any notes at the end of the block in the scan.
1425 This is in case the block ends with a call to setjmp. */
1427 while (NEXT_INSN (last
) != 0 && GET_CODE (NEXT_INSN (last
)) == NOTE
)
1429 /* Look for loop boundaries, we are going forward here. */
1430 last
= NEXT_INSN (last
);
1431 if (NOTE_LINE_NUMBER (last
) == NOTE_INSN_LOOP_BEG
)
1433 else if (NOTE_LINE_NUMBER (last
) == NOTE_INSN_LOOP_END
)
1442 maxlive
= ALLOCA_REG_SET ();
1443 COPY_REG_SET (maxlive
, old
);
1444 regs_sometimes_live
= (int *) alloca (max_regno
* sizeof (int));
1446 /* Process the regs live at the end of the block.
1447 Enter them in MAXLIVE and REGS_SOMETIMES_LIVE.
1448 Also mark them as not local to any one basic block. */
1449 EXECUTE_IF_SET_IN_REG_SET (old
, 0, i
,
1451 REG_BASIC_BLOCK (i
) = REG_BLOCK_GLOBAL
;
1452 regs_sometimes_live
[sometimes_max
] = i
;
1457 /* Scan the block an insn at a time from end to beginning. */
1459 for (insn
= last
; ; insn
= prev
)
1461 prev
= PREV_INSN (insn
);
1463 if (GET_CODE (insn
) == NOTE
)
1465 /* Look for loop boundaries, remembering that we are going
1467 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
)
1469 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
)
1472 /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error.
1473 Abort now rather than setting register status incorrectly. */
1474 if (loop_depth
== 0)
1477 /* If this is a call to `setjmp' et al,
1478 warn if any non-volatile datum is live. */
1480 if (final
&& NOTE_LINE_NUMBER (insn
) == NOTE_INSN_SETJMP
)
1481 IOR_REG_SET (regs_live_at_setjmp
, old
);
1484 /* Update the life-status of regs for this insn.
1485 First DEAD gets which regs are set in this insn
1486 then LIVE gets which regs are used in this insn.
1487 Then the regs live before the insn
1488 are those live after, with DEAD regs turned off,
1489 and then LIVE regs turned on. */
1491 else if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
1494 rtx note
= find_reg_note (insn
, REG_RETVAL
, NULL_RTX
);
1496 = (insn_dead_p (PATTERN (insn
), old
, 0)
1497 /* Don't delete something that refers to volatile storage! */
1498 && ! INSN_VOLATILE (insn
));
1500 = (insn_is_dead
&& note
!= 0
1501 && libcall_dead_p (PATTERN (insn
), old
, note
, insn
));
1503 /* If an instruction consists of just dead store(s) on final pass,
1504 "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED.
1505 We could really delete it with delete_insn, but that
1506 can cause trouble for first or last insn in a basic block. */
1507 if (final
&& insn_is_dead
)
1509 PUT_CODE (insn
, NOTE
);
1510 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1511 NOTE_SOURCE_FILE (insn
) = 0;
1513 /* CC0 is now known to be dead. Either this insn used it,
1514 in which case it doesn't anymore, or clobbered it,
1515 so the next insn can't use it. */
1518 /* If this insn is copying the return value from a library call,
1519 delete the entire library call. */
1520 if (libcall_is_dead
)
1522 rtx first
= XEXP (note
, 0);
1524 while (INSN_DELETED_P (first
))
1525 first
= NEXT_INSN (first
);
1530 NOTE_LINE_NUMBER (p
) = NOTE_INSN_DELETED
;
1531 NOTE_SOURCE_FILE (p
) = 0;
1537 CLEAR_REG_SET (dead
);
1538 CLEAR_REG_SET (live
);
1540 /* See if this is an increment or decrement that can be
1541 merged into a following memory address. */
1544 register rtx x
= PATTERN (insn
);
1545 /* Does this instruction increment or decrement a register? */
1546 if (final
&& GET_CODE (x
) == SET
1547 && GET_CODE (SET_DEST (x
)) == REG
1548 && (GET_CODE (SET_SRC (x
)) == PLUS
1549 || GET_CODE (SET_SRC (x
)) == MINUS
)
1550 && XEXP (SET_SRC (x
), 0) == SET_DEST (x
)
1551 && GET_CODE (XEXP (SET_SRC (x
), 1)) == CONST_INT
1552 /* Ok, look for a following memory ref we can combine with.
1553 If one is found, change the memory ref to a PRE_INC
1554 or PRE_DEC, cancel this insn, and return 1.
1555 Return 0 if nothing has been done. */
1556 && try_pre_increment_1 (insn
))
1559 #endif /* AUTO_INC_DEC */
1561 /* If this is not the final pass, and this insn is copying the
1562 value of a library call and it's dead, don't scan the
1563 insns that perform the library call, so that the call's
1564 arguments are not marked live. */
1565 if (libcall_is_dead
)
1567 /* Mark the dest reg as `significant'. */
1568 mark_set_regs (old
, dead
, PATTERN (insn
), NULL_RTX
, significant
);
1570 insn
= XEXP (note
, 0);
1571 prev
= PREV_INSN (insn
);
1573 else if (GET_CODE (PATTERN (insn
)) == SET
1574 && SET_DEST (PATTERN (insn
)) == stack_pointer_rtx
1575 && GET_CODE (SET_SRC (PATTERN (insn
))) == PLUS
1576 && XEXP (SET_SRC (PATTERN (insn
)), 0) == stack_pointer_rtx
1577 && GET_CODE (XEXP (SET_SRC (PATTERN (insn
)), 1)) == CONST_INT
)
1578 /* We have an insn to pop a constant amount off the stack.
1579 (Such insns use PLUS regardless of the direction of the stack,
1580 and any insn to adjust the stack by a constant is always a pop.)
1581 These insns, if not dead stores, have no effect on life. */
1585 /* LIVE gets the regs used in INSN;
1586 DEAD gets those set by it. Dead insns don't make anything
1589 mark_set_regs (old
, dead
, PATTERN (insn
),
1590 final
? insn
: NULL_RTX
, significant
);
1592 /* If an insn doesn't use CC0, it becomes dead since we
1593 assume that every insn clobbers it. So show it dead here;
1594 mark_used_regs will set it live if it is referenced. */
1598 mark_used_regs (old
, live
, PATTERN (insn
), final
, insn
);
1600 /* Sometimes we may have inserted something before INSN (such as
1601 a move) when we make an auto-inc. So ensure we will scan
1604 prev
= PREV_INSN (insn
);
1607 if (! insn_is_dead
&& GET_CODE (insn
) == CALL_INSN
)
1613 for (note
= CALL_INSN_FUNCTION_USAGE (insn
);
1615 note
= XEXP (note
, 1))
1616 if (GET_CODE (XEXP (note
, 0)) == USE
)
1617 mark_used_regs (old
, live
, SET_DEST (XEXP (note
, 0)),
1620 /* Each call clobbers all call-clobbered regs that are not
1621 global or fixed. Note that the function-value reg is a
1622 call-clobbered reg, and mark_set_regs has already had
1623 a chance to handle it. */
1625 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1626 if (call_used_regs
[i
] && ! global_regs
[i
]
1628 SET_REGNO_REG_SET (dead
, i
);
1630 /* The stack ptr is used (honorarily) by a CALL insn. */
1631 SET_REGNO_REG_SET (live
, STACK_POINTER_REGNUM
);
1633 /* Calls may also reference any of the global registers,
1634 so they are made live. */
1635 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1637 mark_used_regs (old
, live
,
1638 gen_rtx (REG
, reg_raw_mode
[i
], i
),
1641 /* Calls also clobber memory. */
1645 /* Update OLD for the registers used or set. */
1646 AND_COMPL_REG_SET (old
, dead
);
1647 IOR_REG_SET (old
, live
);
1649 if (GET_CODE (insn
) == CALL_INSN
&& final
)
1651 /* Any regs live at the time of a call instruction
1652 must not go in a register clobbered by calls.
1653 Find all regs now live and record this for them. */
1655 register int *p
= regs_sometimes_live
;
1657 for (i
= 0; i
< sometimes_max
; i
++, p
++)
1658 if (REGNO_REG_SET_P (old
, *p
))
1659 REG_N_CALLS_CROSSED (*p
)++;
1663 /* On final pass, add any additional sometimes-live regs
1664 into MAXLIVE and REGS_SOMETIMES_LIVE.
1665 Also update counts of how many insns each reg is live at. */
1672 EXECUTE_IF_AND_COMPL_IN_REG_SET
1673 (live
, maxlive
, 0, regno
,
1675 regs_sometimes_live
[sometimes_max
++] = regno
;
1676 SET_REGNO_REG_SET (maxlive
, regno
);
1679 p
= regs_sometimes_live
;
1680 for (i
= 0; i
< sometimes_max
; i
++)
1683 if (REGNO_REG_SET_P (old
, regno
))
1684 REG_LIVE_LENGTH (regno
)++;
1693 FREE_REG_SET (dead
);
1694 FREE_REG_SET (live
);
1696 FREE_REG_SET (maxlive
);
1698 if (num_scratch
> max_scratch
)
1699 max_scratch
= num_scratch
;
1702 /* Return 1 if X (the body of an insn, or part of it) is just dead stores
1703 (SET expressions whose destinations are registers dead after the insn).
1704 NEEDED is the regset that says which regs are alive after the insn.
1706 Unless CALL_OK is non-zero, an insn is needed if it contains a CALL. */
1709 insn_dead_p (x
, needed
, call_ok
)
1714 register RTX_CODE code
= GET_CODE (x
);
1715 /* If setting something that's a reg or part of one,
1716 see if that register's altered value will be live. */
1720 register rtx r
= SET_DEST (x
);
1721 /* A SET that is a subroutine call cannot be dead. */
1722 if (! call_ok
&& GET_CODE (SET_SRC (x
)) == CALL
)
1726 if (GET_CODE (r
) == CC0
)
1730 if (GET_CODE (r
) == MEM
&& last_mem_set
&& ! MEM_VOLATILE_P (r
)
1731 && rtx_equal_p (r
, last_mem_set
))
1734 while (GET_CODE (r
) == SUBREG
1735 || GET_CODE (r
) == STRICT_LOW_PART
1736 || GET_CODE (r
) == ZERO_EXTRACT
1737 || GET_CODE (r
) == SIGN_EXTRACT
)
1740 if (GET_CODE (r
) == REG
)
1742 register int regno
= REGNO (r
);
1744 /* Don't delete insns to set global regs. */
1745 if ((regno
< FIRST_PSEUDO_REGISTER
&& global_regs
[regno
])
1746 /* Make sure insns to set frame pointer aren't deleted. */
1747 || regno
== FRAME_POINTER_REGNUM
1748 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
1749 || regno
== HARD_FRAME_POINTER_REGNUM
1751 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1752 /* Make sure insns to set arg pointer are never deleted
1753 (if the arg pointer isn't fixed, there will be a USE for
1754 it, so we can treat it normally). */
1755 || (regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
1757 || REGNO_REG_SET_P (needed
, regno
))
1760 /* If this is a hard register, verify that subsequent words are
1762 if (regno
< FIRST_PSEUDO_REGISTER
)
1764 int n
= HARD_REGNO_NREGS (regno
, GET_MODE (r
));
1767 if (REGNO_REG_SET_P (needed
, regno
+n
))
1774 /* If performing several activities,
1775 insn is dead if each activity is individually dead.
1776 Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE
1777 that's inside a PARALLEL doesn't make the insn worth keeping. */
1778 else if (code
== PARALLEL
)
1780 register int i
= XVECLEN (x
, 0);
1781 for (i
--; i
>= 0; i
--)
1783 rtx elt
= XVECEXP (x
, 0, i
);
1784 if (!insn_dead_p (elt
, needed
, call_ok
)
1785 && GET_CODE (elt
) != CLOBBER
1786 && GET_CODE (elt
) != USE
)
1791 /* We do not check CLOBBER or USE here.
1792 An insn consisting of just a CLOBBER or just a USE
1793 should not be deleted. */
1797 /* If X is the pattern of the last insn in a libcall, and assuming X is dead,
1798 return 1 if the entire library call is dead.
1799 This is true if X copies a register (hard or pseudo)
1800 and if the hard return reg of the call insn is dead.
1801 (The caller should have tested the destination of X already for death.)
1803 If this insn doesn't just copy a register, then we don't
1804 have an ordinary libcall. In that case, cse could not have
1805 managed to substitute the source for the dest later on,
1806 so we can assume the libcall is dead.
1808 NEEDED is the bit vector of pseudoregs live before this insn.
1809 NOTE is the REG_RETVAL note of the insn. INSN is the insn itself. */
1812 libcall_dead_p (x
, needed
, note
, insn
)
1818 register RTX_CODE code
= GET_CODE (x
);
1822 register rtx r
= SET_SRC (x
);
1823 if (GET_CODE (r
) == REG
)
1825 rtx call
= XEXP (note
, 0);
1828 /* Find the call insn. */
1829 while (call
!= insn
&& GET_CODE (call
) != CALL_INSN
)
1830 call
= NEXT_INSN (call
);
1832 /* If there is none, do nothing special,
1833 since ordinary death handling can understand these insns. */
1837 /* See if the hard reg holding the value is dead.
1838 If this is a PARALLEL, find the call within it. */
1839 call
= PATTERN (call
);
1840 if (GET_CODE (call
) == PARALLEL
)
1842 for (i
= XVECLEN (call
, 0) - 1; i
>= 0; i
--)
1843 if (GET_CODE (XVECEXP (call
, 0, i
)) == SET
1844 && GET_CODE (SET_SRC (XVECEXP (call
, 0, i
))) == CALL
)
1847 /* This may be a library call that is returning a value
1848 via invisible pointer. Do nothing special, since
1849 ordinary death handling can understand these insns. */
1853 call
= XVECEXP (call
, 0, i
);
1856 return insn_dead_p (call
, needed
, 1);
1862 /* Return 1 if register REGNO was used before it was set.
1863 In other words, if it is live at function entry.
1864 Don't count global register variables or variables in registers
1865 that can be used for function arg passing, though. */
1868 regno_uninitialized (regno
)
1871 if (n_basic_blocks
== 0
1872 || (regno
< FIRST_PSEUDO_REGISTER
1873 && (global_regs
[regno
] || FUNCTION_ARG_REGNO_P (regno
))))
1876 return REGNO_REG_SET_P (basic_block_live_at_start
[0], regno
);
1879 /* 1 if register REGNO was alive at a place where `setjmp' was called
1880 and was set more than once or is an argument.
1881 Such regs may be clobbered by `longjmp'. */
1884 regno_clobbered_at_setjmp (regno
)
1887 if (n_basic_blocks
== 0)
1890 return ((REG_N_SETS (regno
) > 1
1891 || REGNO_REG_SET_P (basic_block_live_at_start
[0], regno
))
1892 && REGNO_REG_SET_P (regs_live_at_setjmp
, regno
));
1895 /* Process the registers that are set within X.
1896 Their bits are set to 1 in the regset DEAD,
1897 because they are dead prior to this insn.
1899 If INSN is nonzero, it is the insn being processed
1900 and the fact that it is nonzero implies this is the FINAL pass
1901 in propagate_block. In this case, various info about register
1902 usage is stored, LOG_LINKS fields of insns are set up. */
1905 mark_set_regs (needed
, dead
, x
, insn
, significant
)
1912 register RTX_CODE code
= GET_CODE (x
);
1914 if (code
== SET
|| code
== CLOBBER
)
1915 mark_set_1 (needed
, dead
, x
, insn
, significant
);
1916 else if (code
== PARALLEL
)
1919 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
1921 code
= GET_CODE (XVECEXP (x
, 0, i
));
1922 if (code
== SET
|| code
== CLOBBER
)
1923 mark_set_1 (needed
, dead
, XVECEXP (x
, 0, i
), insn
, significant
);
1928 /* Process a single SET rtx, X. */
1931 mark_set_1 (needed
, dead
, x
, insn
, significant
)
1939 register rtx reg
= SET_DEST (x
);
1941 /* Modifying just one hardware register of a multi-reg value
1942 or just a byte field of a register
1943 does not mean the value from before this insn is now dead.
1944 But it does mean liveness of that register at the end of the block
1947 Within mark_set_1, however, we treat it as if the register is
1948 indeed modified. mark_used_regs will, however, also treat this
1949 register as being used. Thus, we treat these insns as setting a
1950 new value for the register as a function of its old value. This
1951 cases LOG_LINKS to be made appropriately and this will help combine. */
1953 while (GET_CODE (reg
) == SUBREG
|| GET_CODE (reg
) == ZERO_EXTRACT
1954 || GET_CODE (reg
) == SIGN_EXTRACT
1955 || GET_CODE (reg
) == STRICT_LOW_PART
)
1956 reg
= XEXP (reg
, 0);
1958 /* If we are writing into memory or into a register mentioned in the
1959 address of the last thing stored into memory, show we don't know
1960 what the last store was. If we are writing memory, save the address
1961 unless it is volatile. */
1962 if (GET_CODE (reg
) == MEM
1963 || (GET_CODE (reg
) == REG
1964 && last_mem_set
!= 0 && reg_overlap_mentioned_p (reg
, last_mem_set
)))
1967 if (GET_CODE (reg
) == MEM
&& ! side_effects_p (reg
)
1968 /* There are no REG_INC notes for SP, so we can't assume we'll see
1969 everything that invalidates it. To be safe, don't eliminate any
1970 stores though SP; none of them should be redundant anyway. */
1971 && ! reg_mentioned_p (stack_pointer_rtx
, reg
))
1974 if (GET_CODE (reg
) == REG
1975 && (regno
= REGNO (reg
), regno
!= FRAME_POINTER_REGNUM
)
1976 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
1977 && regno
!= HARD_FRAME_POINTER_REGNUM
1979 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1980 && ! (regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
1982 && ! (regno
< FIRST_PSEUDO_REGISTER
&& global_regs
[regno
]))
1983 /* && regno != STACK_POINTER_REGNUM) -- let's try without this. */
1985 int some_needed
= REGNO_REG_SET_P (needed
, regno
);
1986 int some_not_needed
= ! some_needed
;
1988 /* Mark it as a significant register for this basic block. */
1990 SET_REGNO_REG_SET (significant
, regno
);
1992 /* Mark it as as dead before this insn. */
1993 SET_REGNO_REG_SET (dead
, regno
);
1995 /* A hard reg in a wide mode may really be multiple registers.
1996 If so, mark all of them just like the first. */
1997 if (regno
< FIRST_PSEUDO_REGISTER
)
2001 /* Nothing below is needed for the stack pointer; get out asap.
2002 Eg, log links aren't needed, since combine won't use them. */
2003 if (regno
== STACK_POINTER_REGNUM
)
2006 n
= HARD_REGNO_NREGS (regno
, GET_MODE (reg
));
2009 int regno_n
= regno
+ n
;
2010 int needed_regno
= REGNO_REG_SET_P (needed
, regno_n
);
2012 SET_REGNO_REG_SET (significant
, regno_n
);
2014 SET_REGNO_REG_SET (dead
, regno_n
);
2015 some_needed
|= needed_regno
;
2016 some_not_needed
|= ! needed_regno
;
2019 /* Additional data to record if this is the final pass. */
2022 register rtx y
= reg_next_use
[regno
];
2023 register int blocknum
= BLOCK_NUM (insn
);
2025 /* If this is a hard reg, record this function uses the reg. */
2027 if (regno
< FIRST_PSEUDO_REGISTER
)
2030 int endregno
= regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (reg
));
2032 for (i
= regno
; i
< endregno
; i
++)
2034 /* The next use is no longer "next", since a store
2036 reg_next_use
[i
] = 0;
2038 regs_ever_live
[i
] = 1;
2044 /* The next use is no longer "next", since a store
2046 reg_next_use
[regno
] = 0;
2048 /* Keep track of which basic blocks each reg appears in. */
2050 if (REG_BASIC_BLOCK (regno
) == REG_BLOCK_UNKNOWN
)
2051 REG_BASIC_BLOCK (regno
) = blocknum
;
2052 else if (REG_BASIC_BLOCK (regno
) != blocknum
)
2053 REG_BASIC_BLOCK (regno
) = REG_BLOCK_GLOBAL
;
2055 /* Count (weighted) references, stores, etc. This counts a
2056 register twice if it is modified, but that is correct. */
2057 REG_N_SETS (regno
)++;
2059 REG_N_REFS (regno
) += loop_depth
;
2061 /* The insns where a reg is live are normally counted
2062 elsewhere, but we want the count to include the insn
2063 where the reg is set, and the normal counting mechanism
2064 would not count it. */
2065 REG_LIVE_LENGTH (regno
)++;
2068 if (! some_not_needed
)
2070 /* Make a logical link from the next following insn
2071 that uses this register, back to this insn.
2072 The following insns have already been processed.
2074 We don't build a LOG_LINK for hard registers containing
2075 in ASM_OPERANDs. If these registers get replaced,
2076 we might wind up changing the semantics of the insn,
2077 even if reload can make what appear to be valid assignments
2079 if (y
&& (BLOCK_NUM (y
) == blocknum
)
2080 && (regno
>= FIRST_PSEUDO_REGISTER
2081 || asm_noperands (PATTERN (y
)) < 0))
2083 = gen_rtx (INSN_LIST
, VOIDmode
, insn
, LOG_LINKS (y
));
2085 else if (! some_needed
)
2087 /* Note that dead stores have already been deleted when possible
2088 If we get here, we have found a dead store that cannot
2089 be eliminated (because the same insn does something useful).
2090 Indicate this by marking the reg being set as dying here. */
2092 = gen_rtx (EXPR_LIST
, REG_UNUSED
, reg
, REG_NOTES (insn
));
2093 REG_N_DEATHS (REGNO (reg
))++;
2097 /* This is a case where we have a multi-word hard register
2098 and some, but not all, of the words of the register are
2099 needed in subsequent insns. Write REG_UNUSED notes
2100 for those parts that were not needed. This case should
2105 for (i
= HARD_REGNO_NREGS (regno
, GET_MODE (reg
)) - 1;
2107 if (!REGNO_REG_SET_P (needed
, regno
+ i
))
2109 = gen_rtx (EXPR_LIST
, REG_UNUSED
,
2110 gen_rtx (REG
, reg_raw_mode
[regno
+ i
],
2116 else if (GET_CODE (reg
) == REG
)
2117 reg_next_use
[regno
] = 0;
2119 /* If this is the last pass and this is a SCRATCH, show it will be dying
2120 here and count it. */
2121 else if (GET_CODE (reg
) == SCRATCH
&& insn
!= 0)
2124 = gen_rtx (EXPR_LIST
, REG_UNUSED
, reg
, REG_NOTES (insn
));
2131 /* X is a MEM found in INSN. See if we can convert it into an auto-increment
2135 find_auto_inc (needed
, x
, insn
)
2140 rtx addr
= XEXP (x
, 0);
2141 HOST_WIDE_INT offset
= 0;
2144 /* Here we detect use of an index register which might be good for
2145 postincrement, postdecrement, preincrement, or predecrement. */
2147 if (GET_CODE (addr
) == PLUS
&& GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
2148 offset
= INTVAL (XEXP (addr
, 1)), addr
= XEXP (addr
, 0);
2150 if (GET_CODE (addr
) == REG
)
2153 register int size
= GET_MODE_SIZE (GET_MODE (x
));
2156 int regno
= REGNO (addr
);
2158 /* Is the next use an increment that might make auto-increment? */
2159 if ((incr
= reg_next_use
[regno
]) != 0
2160 && (set
= single_set (incr
)) != 0
2161 && GET_CODE (set
) == SET
2162 && BLOCK_NUM (incr
) == BLOCK_NUM (insn
)
2163 /* Can't add side effects to jumps; if reg is spilled and
2164 reloaded, there's no way to store back the altered value. */
2165 && GET_CODE (insn
) != JUMP_INSN
2166 && (y
= SET_SRC (set
), GET_CODE (y
) == PLUS
)
2167 && XEXP (y
, 0) == addr
2168 && GET_CODE (XEXP (y
, 1)) == CONST_INT
2170 #ifdef HAVE_POST_INCREMENT
2171 || (INTVAL (XEXP (y
, 1)) == size
&& offset
== 0)
2173 #ifdef HAVE_POST_DECREMENT
2174 || (INTVAL (XEXP (y
, 1)) == - size
&& offset
== 0)
2176 #ifdef HAVE_PRE_INCREMENT
2177 || (INTVAL (XEXP (y
, 1)) == size
&& offset
== size
)
2179 #ifdef HAVE_PRE_DECREMENT
2180 || (INTVAL (XEXP (y
, 1)) == - size
&& offset
== - size
)
2183 /* Make sure this reg appears only once in this insn. */
2184 && (use
= find_use_as_address (PATTERN (insn
), addr
, offset
),
2185 use
!= 0 && use
!= (rtx
) 1))
2187 rtx q
= SET_DEST (set
);
2188 enum rtx_code inc_code
= (INTVAL (XEXP (y
, 1)) == size
2189 ? (offset
? PRE_INC
: POST_INC
)
2190 : (offset
? PRE_DEC
: POST_DEC
));
2192 if (dead_or_set_p (incr
, addr
))
2194 /* This is the simple case. Try to make the auto-inc. If
2195 we can't, we are done. Otherwise, we will do any
2196 needed updates below. */
2197 if (! validate_change (insn
, &XEXP (x
, 0),
2198 gen_rtx (inc_code
, Pmode
, addr
),
2202 else if (GET_CODE (q
) == REG
2203 /* PREV_INSN used here to check the semi-open interval
2205 && ! reg_used_between_p (q
, PREV_INSN (insn
), incr
)
2206 /* We must also check for sets of q as q may be
2207 a call clobbered hard register and there may
2208 be a call between PREV_INSN (insn) and incr. */
2209 && ! reg_set_between_p (q
, PREV_INSN (insn
), incr
))
2211 /* We have *p followed sometime later by q = p+size.
2212 Both p and q must be live afterward,
2213 and q is not used between INSN and it's assignment.
2214 Change it to q = p, ...*q..., q = q+size.
2215 Then fall into the usual case. */
2219 emit_move_insn (q
, addr
);
2220 insns
= get_insns ();
2223 /* If anything in INSNS have UID's that don't fit within the
2224 extra space we allocate earlier, we can't make this auto-inc.
2225 This should never happen. */
2226 for (temp
= insns
; temp
; temp
= NEXT_INSN (temp
))
2228 if (INSN_UID (temp
) > max_uid_for_flow
)
2230 BLOCK_NUM (temp
) = BLOCK_NUM (insn
);
2233 /* If we can't make the auto-inc, or can't make the
2234 replacement into Y, exit. There's no point in making
2235 the change below if we can't do the auto-inc and doing
2236 so is not correct in the pre-inc case. */
2238 validate_change (insn
, &XEXP (x
, 0),
2239 gen_rtx (inc_code
, Pmode
, q
),
2241 validate_change (incr
, &XEXP (y
, 0), q
, 1);
2242 if (! apply_change_group ())
2245 /* We now know we'll be doing this change, so emit the
2246 new insn(s) and do the updates. */
2247 emit_insns_before (insns
, insn
);
2249 if (basic_block_head
[BLOCK_NUM (insn
)] == insn
)
2250 basic_block_head
[BLOCK_NUM (insn
)] = insns
;
2252 /* INCR will become a NOTE and INSN won't contain a
2253 use of ADDR. If a use of ADDR was just placed in
2254 the insn before INSN, make that the next use.
2255 Otherwise, invalidate it. */
2256 if (GET_CODE (PREV_INSN (insn
)) == INSN
2257 && GET_CODE (PATTERN (PREV_INSN (insn
))) == SET
2258 && SET_SRC (PATTERN (PREV_INSN (insn
))) == addr
)
2259 reg_next_use
[regno
] = PREV_INSN (insn
);
2261 reg_next_use
[regno
] = 0;
2266 /* REGNO is now used in INCR which is below INSN, but
2267 it previously wasn't live here. If we don't mark
2268 it as needed, we'll put a REG_DEAD note for it
2269 on this insn, which is incorrect. */
2270 SET_REGNO_REG_SET (needed
, regno
);
2272 /* If there are any calls between INSN and INCR, show
2273 that REGNO now crosses them. */
2274 for (temp
= insn
; temp
!= incr
; temp
= NEXT_INSN (temp
))
2275 if (GET_CODE (temp
) == CALL_INSN
)
2276 REG_N_CALLS_CROSSED (regno
)++;
2281 /* If we haven't returned, it means we were able to make the
2282 auto-inc, so update the status. First, record that this insn
2283 has an implicit side effect. */
2286 = gen_rtx (EXPR_LIST
, REG_INC
, addr
, REG_NOTES (insn
));
2288 /* Modify the old increment-insn to simply copy
2289 the already-incremented value of our register. */
2290 if (! validate_change (incr
, &SET_SRC (set
), addr
, 0))
2293 /* If that makes it a no-op (copying the register into itself) delete
2294 it so it won't appear to be a "use" and a "set" of this
2296 if (SET_DEST (set
) == addr
)
2298 PUT_CODE (incr
, NOTE
);
2299 NOTE_LINE_NUMBER (incr
) = NOTE_INSN_DELETED
;
2300 NOTE_SOURCE_FILE (incr
) = 0;
2303 if (regno
>= FIRST_PSEUDO_REGISTER
)
2305 /* Count an extra reference to the reg. When a reg is
2306 incremented, spilling it is worse, so we want to make
2307 that less likely. */
2308 REG_N_REFS (regno
) += loop_depth
;
2310 /* Count the increment as a setting of the register,
2311 even though it isn't a SET in rtl. */
2312 REG_N_SETS (regno
)++;
2317 #endif /* AUTO_INC_DEC */
2319 /* Scan expression X and store a 1-bit in LIVE for each reg it uses.
2320 This is done assuming the registers needed from X
2321 are those that have 1-bits in NEEDED.
2323 On the final pass, FINAL is 1. This means try for autoincrement
2324 and count the uses and deaths of each pseudo-reg.
2326 INSN is the containing instruction. If INSN is dead, this function is not
2330 mark_used_regs (needed
, live
, x
, final
, insn
)
2337 register RTX_CODE code
;
2342 code
= GET_CODE (x
);
2363 /* If we are clobbering a MEM, mark any registers inside the address
2365 if (GET_CODE (XEXP (x
, 0)) == MEM
)
2366 mark_used_regs (needed
, live
, XEXP (XEXP (x
, 0), 0), final
, insn
);
2370 /* Invalidate the data for the last MEM stored, but only if MEM is
2371 something that can be stored into. */
2372 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
2373 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)))
2374 ; /* needn't clear last_mem_set */
2380 find_auto_inc (needed
, x
, insn
);
2385 if (GET_CODE (SUBREG_REG (x
)) == REG
2386 && REGNO (SUBREG_REG (x
)) >= FIRST_PSEUDO_REGISTER
2387 && (GET_MODE_SIZE (GET_MODE (x
))
2388 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)))))
2389 REG_CHANGES_SIZE (REGNO (SUBREG_REG (x
))) = 1;
2391 /* While we're here, optimize this case. */
2394 /* In case the SUBREG is not of a register, don't optimize */
2395 if (GET_CODE (x
) != REG
)
2397 mark_used_regs (needed
, live
, x
, final
, insn
);
2401 /* ... fall through ... */
2404 /* See a register other than being set
2405 => mark it as needed. */
2409 int some_needed
= REGNO_REG_SET_P (needed
, regno
);
2410 int some_not_needed
= ! some_needed
;
2412 SET_REGNO_REG_SET (live
, regno
);
2414 /* A hard reg in a wide mode may really be multiple registers.
2415 If so, mark all of them just like the first. */
2416 if (regno
< FIRST_PSEUDO_REGISTER
)
2420 /* For stack ptr or fixed arg pointer,
2421 nothing below can be necessary, so waste no more time. */
2422 if (regno
== STACK_POINTER_REGNUM
2423 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2424 || regno
== HARD_FRAME_POINTER_REGNUM
2426 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2427 || (regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
2429 || regno
== FRAME_POINTER_REGNUM
)
2431 /* If this is a register we are going to try to eliminate,
2432 don't mark it live here. If we are successful in
2433 eliminating it, it need not be live unless it is used for
2434 pseudos, in which case it will have been set live when
2435 it was allocated to the pseudos. If the register will not
2436 be eliminated, reload will set it live at that point. */
2438 if (! TEST_HARD_REG_BIT (elim_reg_set
, regno
))
2439 regs_ever_live
[regno
] = 1;
2442 /* No death notes for global register variables;
2443 their values are live after this function exits. */
2444 if (global_regs
[regno
])
2447 reg_next_use
[regno
] = insn
;
2451 n
= HARD_REGNO_NREGS (regno
, GET_MODE (x
));
2454 int regno_n
= regno
+ n
;
2455 int needed_regno
= REGNO_REG_SET_P (needed
, regno_n
);
2457 SET_REGNO_REG_SET (live
, regno_n
);
2458 some_needed
|= needed_regno
;
2459 some_not_needed
|= ! needed_regno
;
2464 /* Record where each reg is used, so when the reg
2465 is set we know the next insn that uses it. */
2467 reg_next_use
[regno
] = insn
;
2469 if (regno
< FIRST_PSEUDO_REGISTER
)
2471 /* If a hard reg is being used,
2472 record that this function does use it. */
2474 i
= HARD_REGNO_NREGS (regno
, GET_MODE (x
));
2478 regs_ever_live
[regno
+ --i
] = 1;
2483 /* Keep track of which basic block each reg appears in. */
2485 register int blocknum
= BLOCK_NUM (insn
);
2487 if (REG_BASIC_BLOCK (regno
) == REG_BLOCK_UNKNOWN
)
2488 REG_BASIC_BLOCK (regno
) = blocknum
;
2489 else if (REG_BASIC_BLOCK (regno
) != blocknum
)
2490 REG_BASIC_BLOCK (regno
) = REG_BLOCK_GLOBAL
;
2492 /* Count (weighted) number of uses of each reg. */
2494 REG_N_REFS (regno
) += loop_depth
;
2497 /* Record and count the insns in which a reg dies.
2498 If it is used in this insn and was dead below the insn
2499 then it dies in this insn. If it was set in this insn,
2500 we do not make a REG_DEAD note; likewise if we already
2501 made such a note. */
2504 && ! dead_or_set_p (insn
, x
)
2506 && (regno
>= FIRST_PSEUDO_REGISTER
|| ! fixed_regs
[regno
])
2510 /* Check for the case where the register dying partially
2511 overlaps the register set by this insn. */
2512 if (regno
< FIRST_PSEUDO_REGISTER
2513 && HARD_REGNO_NREGS (regno
, GET_MODE (x
)) > 1)
2515 int n
= HARD_REGNO_NREGS (regno
, GET_MODE (x
));
2517 some_needed
|= dead_or_set_regno_p (insn
, regno
+ n
);
2520 /* If none of the words in X is needed, make a REG_DEAD
2521 note. Otherwise, we must make partial REG_DEAD notes. */
2525 = gen_rtx (EXPR_LIST
, REG_DEAD
, x
, REG_NOTES (insn
));
2526 REG_N_DEATHS (regno
)++;
2532 /* Don't make a REG_DEAD note for a part of a register
2533 that is set in the insn. */
2535 for (i
= HARD_REGNO_NREGS (regno
, GET_MODE (x
)) - 1;
2537 if (!REGNO_REG_SET_P (needed
, regno
+ i
)
2538 && ! dead_or_set_regno_p (insn
, regno
+ i
))
2540 = gen_rtx (EXPR_LIST
, REG_DEAD
,
2541 gen_rtx (REG
, reg_raw_mode
[regno
+ i
],
2552 register rtx testreg
= SET_DEST (x
);
2555 /* If storing into MEM, don't show it as being used. But do
2556 show the address as being used. */
2557 if (GET_CODE (testreg
) == MEM
)
2561 find_auto_inc (needed
, testreg
, insn
);
2563 mark_used_regs (needed
, live
, XEXP (testreg
, 0), final
, insn
);
2564 mark_used_regs (needed
, live
, SET_SRC (x
), final
, insn
);
2568 /* Storing in STRICT_LOW_PART is like storing in a reg
2569 in that this SET might be dead, so ignore it in TESTREG.
2570 but in some other ways it is like using the reg.
2572 Storing in a SUBREG or a bit field is like storing the entire
2573 register in that if the register's value is not used
2574 then this SET is not needed. */
2575 while (GET_CODE (testreg
) == STRICT_LOW_PART
2576 || GET_CODE (testreg
) == ZERO_EXTRACT
2577 || GET_CODE (testreg
) == SIGN_EXTRACT
2578 || GET_CODE (testreg
) == SUBREG
)
2580 if (GET_CODE (testreg
) == SUBREG
2581 && GET_CODE (SUBREG_REG (testreg
)) == REG
2582 && REGNO (SUBREG_REG (testreg
)) >= FIRST_PSEUDO_REGISTER
2583 && (GET_MODE_SIZE (GET_MODE (testreg
))
2584 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (testreg
)))))
2585 REG_CHANGES_SIZE (REGNO (SUBREG_REG (testreg
))) = 1;
2587 /* Modifying a single register in an alternate mode
2588 does not use any of the old value. But these other
2589 ways of storing in a register do use the old value. */
2590 if (GET_CODE (testreg
) == SUBREG
2591 && !(REG_SIZE (SUBREG_REG (testreg
)) > REG_SIZE (testreg
)))
2596 testreg
= XEXP (testreg
, 0);
2599 /* If this is a store into a register,
2600 recursively scan the value being stored. */
2602 if (GET_CODE (testreg
) == REG
2603 && (regno
= REGNO (testreg
), regno
!= FRAME_POINTER_REGNUM
)
2604 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2605 && regno
!= HARD_FRAME_POINTER_REGNUM
2607 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2608 && ! (regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
2611 /* We used to exclude global_regs here, but that seems wrong.
2612 Storing in them is like storing in mem. */
2614 mark_used_regs (needed
, live
, SET_SRC (x
), final
, insn
);
2616 mark_used_regs (needed
, live
, SET_DEST (x
), final
, insn
);
2623 /* If exiting needs the right stack value, consider this insn as
2624 using the stack pointer. In any event, consider it as using
2625 all global registers and all registers used by return. */
2627 #ifdef EXIT_IGNORE_STACK
2628 if (! EXIT_IGNORE_STACK
2629 || (! FRAME_POINTER_REQUIRED
&& flag_omit_frame_pointer
))
2631 SET_REGNO_REG_SET (live
, STACK_POINTER_REGNUM
);
2633 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2635 #ifdef EPILOGUE_USES
2636 || EPILOGUE_USES (i
)
2639 SET_REGNO_REG_SET (live
, i
);
2646 /* Recursively scan the operands of this expression. */
2649 register char *fmt
= GET_RTX_FORMAT (code
);
2652 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2656 /* Tail recursive case: save a function call level. */
2662 mark_used_regs (needed
, live
, XEXP (x
, i
), final
, insn
);
2664 else if (fmt
[i
] == 'E')
2667 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2668 mark_used_regs (needed
, live
, XVECEXP (x
, i
, j
), final
, insn
);
2677 try_pre_increment_1 (insn
)
2680 /* Find the next use of this reg. If in same basic block,
2681 make it do pre-increment or pre-decrement if appropriate. */
2682 rtx x
= PATTERN (insn
);
2683 HOST_WIDE_INT amount
= ((GET_CODE (SET_SRC (x
)) == PLUS
? 1 : -1)
2684 * INTVAL (XEXP (SET_SRC (x
), 1)));
2685 int regno
= REGNO (SET_DEST (x
));
2686 rtx y
= reg_next_use
[regno
];
2688 && BLOCK_NUM (y
) == BLOCK_NUM (insn
)
2689 /* Don't do this if the reg dies, or gets set in y; a standard addressing
2690 mode would be better. */
2691 && ! dead_or_set_p (y
, SET_DEST (x
))
2692 && try_pre_increment (y
, SET_DEST (PATTERN (insn
)),
2695 /* We have found a suitable auto-increment
2696 and already changed insn Y to do it.
2697 So flush this increment-instruction. */
2698 PUT_CODE (insn
, NOTE
);
2699 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
2700 NOTE_SOURCE_FILE (insn
) = 0;
2701 /* Count a reference to this reg for the increment
2702 insn we are deleting. When a reg is incremented.
2703 spilling it is worse, so we want to make that
2705 if (regno
>= FIRST_PSEUDO_REGISTER
)
2707 REG_N_REFS (regno
) += loop_depth
;
2708 REG_N_SETS (regno
)++;
2715 /* Try to change INSN so that it does pre-increment or pre-decrement
2716 addressing on register REG in order to add AMOUNT to REG.
2717 AMOUNT is negative for pre-decrement.
2718 Returns 1 if the change could be made.
2719 This checks all about the validity of the result of modifying INSN. */
2722 try_pre_increment (insn
, reg
, amount
)
2724 HOST_WIDE_INT amount
;
2728 /* Nonzero if we can try to make a pre-increment or pre-decrement.
2729 For example, addl $4,r1; movl (r1),... can become movl +(r1),... */
2731 /* Nonzero if we can try to make a post-increment or post-decrement.
2732 For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,...
2733 It is possible for both PRE_OK and POST_OK to be nonzero if the machine
2734 supports both pre-inc and post-inc, or both pre-dec and post-dec. */
2737 /* Nonzero if the opportunity actually requires post-inc or post-dec. */
2740 /* From the sign of increment, see which possibilities are conceivable
2741 on this target machine. */
2742 #ifdef HAVE_PRE_INCREMENT
2746 #ifdef HAVE_POST_INCREMENT
2751 #ifdef HAVE_PRE_DECREMENT
2755 #ifdef HAVE_POST_DECREMENT
2760 if (! (pre_ok
|| post_ok
))
2763 /* It is not safe to add a side effect to a jump insn
2764 because if the incremented register is spilled and must be reloaded
2765 there would be no way to store the incremented value back in memory. */
2767 if (GET_CODE (insn
) == JUMP_INSN
)
2772 use
= find_use_as_address (PATTERN (insn
), reg
, 0);
2773 if (post_ok
&& (use
== 0 || use
== (rtx
) 1))
2775 use
= find_use_as_address (PATTERN (insn
), reg
, -amount
);
2779 if (use
== 0 || use
== (rtx
) 1)
2782 if (GET_MODE_SIZE (GET_MODE (use
)) != (amount
> 0 ? amount
: - amount
))
2785 /* See if this combination of instruction and addressing mode exists. */
2786 if (! validate_change (insn
, &XEXP (use
, 0),
2788 ? (do_post
? POST_INC
: PRE_INC
)
2789 : (do_post
? POST_DEC
: PRE_DEC
),
2793 /* Record that this insn now has an implicit side effect on X. */
2794 REG_NOTES (insn
) = gen_rtx (EXPR_LIST
, REG_INC
, reg
, REG_NOTES (insn
));
2798 #endif /* AUTO_INC_DEC */
2800 /* Find the place in the rtx X where REG is used as a memory address.
2801 Return the MEM rtx that so uses it.
2802 If PLUSCONST is nonzero, search instead for a memory address equivalent to
2803 (plus REG (const_int PLUSCONST)).
2805 If such an address does not appear, return 0.
2806 If REG appears more than once, or is used other than in such an address,
2810 find_use_as_address (x
, reg
, plusconst
)
2813 HOST_WIDE_INT plusconst
;
2815 enum rtx_code code
= GET_CODE (x
);
2816 char *fmt
= GET_RTX_FORMAT (code
);
2818 register rtx value
= 0;
2821 if (code
== MEM
&& XEXP (x
, 0) == reg
&& plusconst
== 0)
2824 if (code
== MEM
&& GET_CODE (XEXP (x
, 0)) == PLUS
2825 && XEXP (XEXP (x
, 0), 0) == reg
2826 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
2827 && INTVAL (XEXP (XEXP (x
, 0), 1)) == plusconst
)
2830 if (code
== SIGN_EXTRACT
|| code
== ZERO_EXTRACT
)
2832 /* If REG occurs inside a MEM used in a bit-field reference,
2833 that is unacceptable. */
2834 if (find_use_as_address (XEXP (x
, 0), reg
, 0) != 0)
2835 return (rtx
) (HOST_WIDE_INT
) 1;
2839 return (rtx
) (HOST_WIDE_INT
) 1;
2841 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2845 tem
= find_use_as_address (XEXP (x
, i
), reg
, plusconst
);
2849 return (rtx
) (HOST_WIDE_INT
) 1;
2854 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2856 tem
= find_use_as_address (XVECEXP (x
, i
, j
), reg
, plusconst
);
2860 return (rtx
) (HOST_WIDE_INT
) 1;
2868 /* Write information about registers and basic blocks into FILE.
2869 This is part of making a debugging dump. */
2872 dump_flow_info (file
)
2876 static char *reg_class_names
[] = REG_CLASS_NAMES
;
2878 fprintf (file
, "%d registers.\n", max_regno
);
2880 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
2883 enum reg_class
class, altclass
;
2884 fprintf (file
, "\nRegister %d used %d times across %d insns",
2885 i
, REG_N_REFS (i
), REG_LIVE_LENGTH (i
));
2886 if (REG_BASIC_BLOCK (i
) >= 0)
2887 fprintf (file
, " in block %d", REG_BASIC_BLOCK (i
));
2888 if (REG_N_DEATHS (i
) != 1)
2889 fprintf (file
, "; dies in %d places", REG_N_DEATHS (i
));
2890 if (REG_N_CALLS_CROSSED (i
) == 1)
2891 fprintf (file
, "; crosses 1 call");
2892 else if (REG_N_CALLS_CROSSED (i
))
2893 fprintf (file
, "; crosses %d calls", REG_N_CALLS_CROSSED (i
));
2894 if (PSEUDO_REGNO_BYTES (i
) != UNITS_PER_WORD
)
2895 fprintf (file
, "; %d bytes", PSEUDO_REGNO_BYTES (i
));
2896 class = reg_preferred_class (i
);
2897 altclass
= reg_alternate_class (i
);
2898 if (class != GENERAL_REGS
|| altclass
!= ALL_REGS
)
2900 if (altclass
== ALL_REGS
|| class == ALL_REGS
)
2901 fprintf (file
, "; pref %s", reg_class_names
[(int) class]);
2902 else if (altclass
== NO_REGS
)
2903 fprintf (file
, "; %s or none", reg_class_names
[(int) class]);
2905 fprintf (file
, "; pref %s, else %s",
2906 reg_class_names
[(int) class],
2907 reg_class_names
[(int) altclass
]);
2909 if (REGNO_POINTER_FLAG (i
))
2910 fprintf (file
, "; pointer");
2911 fprintf (file
, ".\n");
2913 fprintf (file
, "\n%d basic blocks.\n", n_basic_blocks
);
2914 for (i
= 0; i
< n_basic_blocks
; i
++)
2916 register rtx head
, jump
;
2918 fprintf (file
, "\nBasic block %d: first insn %d, last %d.\n",
2920 INSN_UID (basic_block_head
[i
]),
2921 INSN_UID (basic_block_end
[i
]));
2922 /* The control flow graph's storage is freed
2923 now when flow_analysis returns.
2924 Don't try to print it if it is gone. */
2925 if (basic_block_drops_in
)
2927 fprintf (file
, "Reached from blocks: ");
2928 head
= basic_block_head
[i
];
2929 if (GET_CODE (head
) == CODE_LABEL
)
2930 for (jump
= LABEL_REFS (head
);
2932 jump
= LABEL_NEXTREF (jump
))
2934 register int from_block
= BLOCK_NUM (CONTAINING_INSN (jump
));
2935 fprintf (file
, " %d", from_block
);
2937 if (basic_block_drops_in
[i
])
2938 fprintf (file
, " previous");
2940 fprintf (file
, "\nRegisters live at start:");
2941 for (regno
= 0; regno
< max_regno
; regno
++)
2942 if (REGNO_REG_SET_P (basic_block_live_at_start
[i
], regno
))
2943 fprintf (file
, " %d", regno
);
2944 fprintf (file
, "\n");
2946 fprintf (file
, "\n");
2950 /* Like print_rtl, but also print out live information for the start of each
2954 print_rtl_with_bb (outf
, rtx_first
)
2958 register rtx tmp_rtx
;
2961 fprintf (outf
, "(nil)\n");
2966 enum bb_state
{ NOT_IN_BB
, IN_ONE_BB
, IN_MULTIPLE_BB
};
2967 int max_uid
= get_max_uid ();
2968 int *start
= (int *) alloca (max_uid
* sizeof (int));
2969 int *end
= (int *) alloca (max_uid
* sizeof (int));
2970 char *in_bb_p
= (char *) alloca (max_uid
* sizeof (enum bb_state
));
2972 for (i
= 0; i
< max_uid
; i
++)
2974 start
[i
] = end
[i
] = -1;
2975 in_bb_p
[i
] = NOT_IN_BB
;
2978 for (i
= n_basic_blocks
-1; i
>= 0; i
--)
2981 start
[INSN_UID (basic_block_head
[i
])] = i
;
2982 end
[INSN_UID (basic_block_end
[i
])] = i
;
2983 for (x
= basic_block_head
[i
]; x
!= NULL_RTX
; x
= NEXT_INSN (x
))
2985 in_bb_p
[ INSN_UID(x
)]
2986 = (in_bb_p
[ INSN_UID(x
)] == NOT_IN_BB
)
2987 ? IN_ONE_BB
: IN_MULTIPLE_BB
;
2988 if (x
== basic_block_end
[i
])
2993 for (tmp_rtx
= rtx_first
; NULL
!= tmp_rtx
; tmp_rtx
= NEXT_INSN (tmp_rtx
))
2995 if ((bb
= start
[INSN_UID (tmp_rtx
)]) >= 0)
2997 fprintf (outf
, ";; Start of basic block %d, registers live:",
3000 EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start
[bb
], 0, i
,
3002 fprintf (outf
, " %d", i
);
3003 if (i
< FIRST_PSEUDO_REGISTER
)
3004 fprintf (outf
, " [%s]",
3010 if (in_bb_p
[ INSN_UID(tmp_rtx
)] == NOT_IN_BB
3011 && GET_CODE (tmp_rtx
) != NOTE
3012 && GET_CODE (tmp_rtx
) != BARRIER
)
3013 fprintf (outf
, ";; Insn is not within a basic block\n");
3014 else if (in_bb_p
[ INSN_UID(tmp_rtx
)] == IN_MULTIPLE_BB
)
3015 fprintf (outf
, ";; Insn is in multiple basic blocks\n");
3017 print_rtl_single (outf
, tmp_rtx
);
3019 if ((bb
= end
[INSN_UID (tmp_rtx
)]) >= 0)
3020 fprintf (outf
, ";; End of basic block %d\n", bb
);