1 /* Data flow analysis for GNU compiler.
2 Copyright (C) 1987, 88, 92-97, 1998 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 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_1
PROTO((rtx
, rtx
, int));
252 static void mark_label_ref
PROTO((rtx
, rtx
, int));
253 static void life_analysis_1
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
,
267 static void find_auto_inc
PROTO((regset
, rtx
, rtx
));
268 static int try_pre_increment_1
PROTO((rtx
));
269 static int try_pre_increment
PROTO((rtx
, rtx
, HOST_WIDE_INT
));
271 static void mark_used_regs
PROTO((regset
, regset
, rtx
, int, rtx
));
272 void dump_flow_info
PROTO((FILE *));
273 static void add_pred_succ
PROTO ((int, int, int_list_ptr
*,
274 int_list_ptr
*, int *, int *));
275 static int_list_ptr alloc_int_list_node
PROTO ((int_list_block
**));
276 static int_list_ptr add_int_list_node
PROTO ((int_list_block
**,
279 /* Find basic blocks of the current function.
280 F is the first insn of the function and NREGS the number of register numbers
282 LIVE_REACHABLE_P is non-zero if the caller needs all live blocks to
283 be reachable. This turns on a kludge that causes the control flow
284 information to be inaccurate and not suitable for passes like GCSE. */
287 find_basic_blocks (f
, nregs
, file
, live_reachable_p
)
291 int live_reachable_p
;
295 rtx nonlocal_label_list
= nonlocal_label_rtx_list ();
296 int in_libcall_block
= 0;
298 /* Count the basic blocks. Also find maximum insn uid value used. */
301 register RTX_CODE prev_code
= JUMP_INSN
;
302 register RTX_CODE code
;
305 max_uid_for_flow
= 0;
307 for (insn
= f
, i
= 0; insn
; insn
= NEXT_INSN (insn
))
310 /* Track when we are inside in LIBCALL block. */
311 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
312 && find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
))
313 in_libcall_block
= 1;
315 code
= GET_CODE (insn
);
316 if (INSN_UID (insn
) > max_uid_for_flow
)
317 max_uid_for_flow
= INSN_UID (insn
);
318 if (code
== CODE_LABEL
319 || (GET_RTX_CLASS (code
) == 'i'
320 && (prev_code
== JUMP_INSN
321 || (prev_code
== CALL_INSN
322 && (nonlocal_label_list
!= 0 || eh_region
)
323 && ! in_libcall_block
)
324 || prev_code
== BARRIER
)))
327 if (code
== CALL_INSN
&& find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
332 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_BEG
)
334 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_END
)
337 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
338 && find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
339 in_libcall_block
= 0;
346 /* Leave space for insns life_analysis makes in some cases for auto-inc.
347 These cases are rare, so we don't need too much space. */
348 max_uid_for_flow
+= max_uid_for_flow
/ 10;
351 /* Allocate some tables that last till end of compiling this function
352 and some needed only in find_basic_blocks and life_analysis. */
354 basic_block_head
= (rtx
*) xmalloc (n_basic_blocks
* sizeof (rtx
));
355 basic_block_end
= (rtx
*) xmalloc (n_basic_blocks
* sizeof (rtx
));
356 basic_block_drops_in
= (char *) xmalloc (n_basic_blocks
);
357 basic_block_loop_depth
= (short *) xmalloc (n_basic_blocks
* sizeof (short));
359 = (int *) xmalloc ((max_uid_for_flow
+ 1) * sizeof (int));
360 uid_volatile
= (char *) xmalloc (max_uid_for_flow
+ 1);
361 bzero (uid_volatile
, max_uid_for_flow
+ 1);
363 find_basic_blocks_1 (f
, nonlocal_label_list
, live_reachable_p
);
366 /* Find all basic blocks of the function whose first insn is F.
367 Store the correct data in the tables that describe the basic blocks,
368 set up the chains of references for each CODE_LABEL, and
369 delete any entire basic blocks that cannot be reached.
371 NONLOCAL_LABEL_LIST is a list of non-local labels in the function.
372 Blocks that are otherwise unreachable may be reachable with a non-local
374 LIVE_REACHABLE_P is non-zero if the caller needs all live blocks to
375 be reachable. This turns on a kludge that causes the control flow
376 information to be inaccurate and not suitable for passes like GCSE. */
379 find_basic_blocks_1 (f
, nonlocal_label_list
, live_reachable_p
)
380 rtx f
, nonlocal_label_list
;
381 int live_reachable_p
;
385 register char *block_live
= (char *) alloca (n_basic_blocks
);
386 register char *block_marked
= (char *) alloca (n_basic_blocks
);
387 /* An array of CODE_LABELs, indexed by UID for the start of the active
388 EH handler for each insn in F. */
389 rtx
*active_eh_handler
;
390 /* List of label_refs to all labels whose addresses are taken
392 rtx label_value_list
;
393 rtx x
, note
, eh_note
;
394 enum rtx_code prev_code
, code
;
396 int in_libcall_block
= 0;
399 active_eh_handler
= (rtx
*) alloca ((max_uid_for_flow
+ 1) * sizeof (rtx
));
402 label_value_list
= 0;
403 block_live_static
= block_live
;
404 bzero (block_live
, n_basic_blocks
);
405 bzero (block_marked
, n_basic_blocks
);
406 bzero (active_eh_handler
, (max_uid_for_flow
+ 1) * sizeof (rtx
));
408 /* Initialize with just block 0 reachable and no blocks marked. */
409 if (n_basic_blocks
> 0)
412 /* Initialize the ref chain of each label to 0. Record where all the
413 blocks start and end and their depth in loops. For each insn, record
414 the block it is in. Also mark as reachable any blocks headed by labels
415 that must not be deleted. */
417 for (eh_note
= NULL_RTX
, insn
= f
, i
= -1, prev_code
= JUMP_INSN
, depth
= 1;
418 insn
; insn
= NEXT_INSN (insn
))
421 /* Track when we are inside in LIBCALL block. */
422 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
423 && find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
))
424 in_libcall_block
= 1;
426 code
= GET_CODE (insn
);
429 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
)
431 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
)
435 /* A basic block starts at label, or after something that can jump. */
436 else if (code
== CODE_LABEL
437 || (GET_RTX_CLASS (code
) == 'i'
438 && (prev_code
== JUMP_INSN
439 || (prev_code
== CALL_INSN
440 && (nonlocal_label_list
!= 0 || eh_note
)
441 && ! in_libcall_block
)
442 || prev_code
== BARRIER
)))
444 basic_block_head
[++i
] = insn
;
445 basic_block_end
[i
] = insn
;
446 basic_block_loop_depth
[i
] = depth
;
448 if (code
== CODE_LABEL
)
450 LABEL_REFS (insn
) = insn
;
451 /* Any label that cannot be deleted
452 is considered to start a reachable block. */
453 if (LABEL_PRESERVE_P (insn
))
458 else if (GET_RTX_CLASS (code
) == 'i')
460 basic_block_end
[i
] = insn
;
461 basic_block_loop_depth
[i
] = depth
;
464 if (GET_RTX_CLASS (code
) == 'i')
466 /* Make a list of all labels referred to other than by jumps. */
467 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
468 if (REG_NOTE_KIND (note
) == REG_LABEL
)
469 label_value_list
= gen_rtx_EXPR_LIST (VOIDmode
, XEXP (note
, 0),
473 /* Keep a lifo list of the currently active exception handlers. */
474 if (GET_CODE (insn
) == NOTE
)
476 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_BEG
)
478 for (x
= exception_handler_labels
; x
; x
= XEXP (x
, 1))
479 if (CODE_LABEL_NUMBER (XEXP (x
, 0)) == NOTE_BLOCK_NUMBER (insn
))
481 eh_note
= gen_rtx_EXPR_LIST (VOIDmode
,
482 XEXP (x
, 0), eh_note
);
488 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_END
)
489 eh_note
= XEXP (eh_note
, 1);
491 /* If we encounter a CALL_INSN, note which exception handler it
492 might pass control to.
494 If doing asynchronous exceptions, record the active EH handler
495 for every insn, since most insns can throw. */
497 && (asynchronous_exceptions
498 || (GET_CODE (insn
) == CALL_INSN
499 && ! in_libcall_block
)))
500 active_eh_handler
[INSN_UID (insn
)] = XEXP (eh_note
, 0);
502 BLOCK_NUM (insn
) = i
;
507 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i'
508 && find_reg_note (insn
, REG_RETVAL
, NULL_RTX
))
509 in_libcall_block
= 0;
512 /* During the second pass, `n_basic_blocks' is only an upper bound.
513 Only perform the sanity check for the first pass, and on the second
514 pass ensure `n_basic_blocks' is set to the correct value. */
515 if (pass
== 1 && i
+ 1 != n_basic_blocks
)
517 n_basic_blocks
= i
+ 1;
519 /* Record which basic blocks control can drop in to. */
521 for (i
= 0; i
< n_basic_blocks
; i
++)
523 for (insn
= PREV_INSN (basic_block_head
[i
]);
524 insn
&& GET_CODE (insn
) == NOTE
; insn
= PREV_INSN (insn
))
527 basic_block_drops_in
[i
] = insn
&& GET_CODE (insn
) != BARRIER
;
530 /* Now find which basic blocks can actually be reached
531 and put all jump insns' LABEL_REFS onto the ref-chains
532 of their target labels. */
534 if (n_basic_blocks
> 0)
536 int something_marked
= 1;
539 /* Pass over all blocks, marking each block that is reachable
540 and has not yet been marked.
541 Keep doing this until, in one pass, no blocks have been marked.
542 Then blocks_live and blocks_marked are identical and correct.
543 In addition, all jumps actually reachable have been marked. */
545 while (something_marked
)
547 something_marked
= 0;
548 for (i
= 0; i
< n_basic_blocks
; i
++)
549 if (block_live
[i
] && !block_marked
[i
])
552 something_marked
= 1;
553 if (i
+ 1 < n_basic_blocks
&& basic_block_drops_in
[i
+ 1])
554 block_live
[i
+ 1] = 1;
555 insn
= basic_block_end
[i
];
556 if (GET_CODE (insn
) == JUMP_INSN
)
557 mark_label_ref (PATTERN (insn
), insn
, 0);
559 /* If we have any forced labels, mark them as potentially
560 reachable from this block. */
561 for (x
= forced_labels
; x
; x
= XEXP (x
, 1))
562 if (! LABEL_REF_NONLOCAL_P (x
))
563 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode
, XEXP (x
, 0)),
566 /* Now scan the insns for this block, we may need to make
567 edges for some of them to various non-obvious locations
568 (exception handlers, nonlocal labels, etc). */
569 for (insn
= basic_block_head
[i
];
570 insn
!= NEXT_INSN (basic_block_end
[i
]);
571 insn
= NEXT_INSN (insn
))
573 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
576 /* References to labels in non-jumping insns have
577 REG_LABEL notes attached to them.
579 This can happen for computed gotos; we don't care
580 about them here since the values are also on the
581 label_value_list and will be marked live if we find
582 a live computed goto.
584 This can also happen when we take the address of
585 a label to pass as an argument to __throw. Note
586 throw only uses the value to determine what handler
587 should be called -- ie the label is not used as
588 a jump target, it just marks regions in the code.
590 In theory we should be able to ignore the REG_LABEL
591 notes, but we have to make sure that the label and
592 associated insns aren't marked dead, so we make
593 the block in question live and create an edge from
594 this insn to the label. This is not strictly
595 correct, but it is close enough for now. */
596 for (note
= REG_NOTES (insn
);
598 note
= XEXP (note
, 1))
600 if (REG_NOTE_KIND (note
) == REG_LABEL
)
603 block_live
[BLOCK_NUM (x
)] = 1;
604 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode
, x
),
609 /* If this is a computed jump, then mark it as
610 reaching everything on the label_value_list
611 and forced_labels list. */
612 if (computed_jump_p (insn
))
614 for (x
= label_value_list
; x
; x
= XEXP (x
, 1))
615 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode
,
619 for (x
= forced_labels
; x
; x
= XEXP (x
, 1))
620 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode
,
625 /* If this is a CALL_INSN, then mark it as reaching
626 the active EH handler for this CALL_INSN. If
627 we're handling asynchronous exceptions mark every
628 insn as reaching the active EH handler.
630 Also mark the CALL_INSN as reaching any nonlocal
632 else if (asynchronous_exceptions
633 || (GET_CODE (insn
) == CALL_INSN
634 && ! find_reg_note (insn
, REG_RETVAL
,
637 if (active_eh_handler
[INSN_UID (insn
)])
638 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode
,
639 active_eh_handler
[INSN_UID (insn
)]),
642 if (!asynchronous_exceptions
)
644 for (x
= nonlocal_label_list
;
647 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode
,
651 /* ??? This could be made smarter:
652 in some cases it's possible to tell that
653 certain calls will not do a nonlocal goto.
655 For example, if the nested functions that
656 do the nonlocal gotos do not have their
657 addresses taken, then only calls to those
658 functions or to other nested functions that
659 use them could possibly do nonlocal gotos. */
666 /* This should never happen. If it does that means we've computed an
667 incorrect flow graph, which can lead to aborts/crashes later in the
668 compiler or incorrect code generation.
670 We used to try and continue here, but that's just asking for trouble
671 later during the compile or at runtime. It's easier to debug the
672 problem here than later! */
673 for (i
= 1; i
< n_basic_blocks
; i
++)
674 if (block_live
[i
] && ! basic_block_drops_in
[i
]
675 && GET_CODE (basic_block_head
[i
]) == CODE_LABEL
676 && LABEL_REFS (basic_block_head
[i
]) == basic_block_head
[i
])
679 /* Now delete the code for any basic blocks that can't be reached.
680 They can occur because jump_optimize does not recognize
681 unreachable loops as unreachable. */
684 for (i
= 0; i
< n_basic_blocks
; i
++)
689 /* Delete the insns in a (non-live) block. We physically delete
690 every non-note insn except the start and end (so
691 basic_block_head/end needn't be updated), we turn the latter
692 into NOTE_INSN_DELETED notes.
693 We use to "delete" the insns by turning them into notes, but
694 we may be deleting lots of insns that subsequent passes would
695 otherwise have to process. Secondly, lots of deleted blocks in
696 a row can really slow down propagate_block since it will
697 otherwise process insn-turned-notes multiple times when it
698 looks for loop begin/end notes. */
699 if (basic_block_head
[i
] != basic_block_end
[i
])
701 /* It would be quicker to delete all of these with a single
702 unchaining, rather than one at a time, but we need to keep
704 insn
= NEXT_INSN (basic_block_head
[i
]);
705 while (insn
!= basic_block_end
[i
])
707 if (GET_CODE (insn
) == BARRIER
)
709 else if (GET_CODE (insn
) != NOTE
)
710 insn
= flow_delete_insn (insn
);
712 insn
= NEXT_INSN (insn
);
715 insn
= basic_block_head
[i
];
716 if (GET_CODE (insn
) != NOTE
)
718 /* Turn the head into a deleted insn note. */
719 if (GET_CODE (insn
) == BARRIER
)
722 /* If the head of this block is a CODE_LABEL, then it might
723 be the label for an exception handler which can't be
726 We need to remove the label from the exception_handler_label
727 list and remove the associated NOTE_EH_REGION_BEG and
728 NOTE_EH_REGION_END notes. */
729 if (GET_CODE (insn
) == CODE_LABEL
)
731 rtx x
, *prev
= &exception_handler_labels
;
733 for (x
= exception_handler_labels
; x
; x
= XEXP (x
, 1))
735 if (XEXP (x
, 0) == insn
)
737 /* Found a match, splice this label out of the
740 XEXP (x
, 1) = NULL_RTX
;
741 XEXP (x
, 0) = NULL_RTX
;
743 /* Now we have to find the EH_BEG and EH_END notes
744 associated with this label and remove them. */
746 for (x
= get_insns (); x
; x
= NEXT_INSN (x
))
748 if (GET_CODE (x
) == NOTE
749 && ((NOTE_LINE_NUMBER (x
)
750 == NOTE_INSN_EH_REGION_BEG
)
751 || (NOTE_LINE_NUMBER (x
)
752 == NOTE_INSN_EH_REGION_END
))
753 && (NOTE_BLOCK_NUMBER (x
)
754 == CODE_LABEL_NUMBER (insn
)))
756 NOTE_LINE_NUMBER (x
) = NOTE_INSN_DELETED
;
757 NOTE_SOURCE_FILE (x
) = 0;
766 PUT_CODE (insn
, NOTE
);
767 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
768 NOTE_SOURCE_FILE (insn
) = 0;
770 insn
= basic_block_end
[i
];
771 if (GET_CODE (insn
) != NOTE
)
773 /* Turn the tail into a deleted insn note. */
774 if (GET_CODE (insn
) == BARRIER
)
776 PUT_CODE (insn
, NOTE
);
777 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
778 NOTE_SOURCE_FILE (insn
) = 0;
780 /* BARRIERs are between basic blocks, not part of one.
781 Delete a BARRIER if the preceding jump is deleted.
782 We cannot alter a BARRIER into a NOTE
783 because it is too short; but we can really delete
784 it because it is not part of a basic block. */
785 if (NEXT_INSN (insn
) != 0
786 && GET_CODE (NEXT_INSN (insn
)) == BARRIER
)
787 delete_insn (NEXT_INSN (insn
));
789 /* Each time we delete some basic blocks,
790 see if there is a jump around them that is
791 being turned into a no-op. If so, delete it. */
793 if (block_live
[i
- 1])
796 for (j
= i
+ 1; j
< n_basic_blocks
; j
++)
800 insn
= basic_block_end
[i
- 1];
801 if (GET_CODE (insn
) == JUMP_INSN
802 /* An unconditional jump is the only possibility
803 we must check for, since a conditional one
804 would make these blocks live. */
805 && simplejump_p (insn
)
806 && (label
= XEXP (SET_SRC (PATTERN (insn
)), 0), 1)
807 && INSN_UID (label
) != 0
808 && BLOCK_NUM (label
) == j
)
812 /* The deleted blocks still show up in the cfg,
813 so we must set basic_block_drops_in for blocks
814 I to J inclusive to keep the cfg accurate. */
815 for (k
= i
; k
<= j
; k
++)
816 basic_block_drops_in
[k
] = 1;
818 PUT_CODE (insn
, NOTE
);
819 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
820 NOTE_SOURCE_FILE (insn
) = 0;
821 if (GET_CODE (NEXT_INSN (insn
)) != BARRIER
)
823 delete_insn (NEXT_INSN (insn
));
830 /* There are pathological cases where one function calling hundreds of
831 nested inline functions can generate lots and lots of unreachable
832 blocks that jump can't delete. Since we don't use sparse matrices
833 a lot of memory will be needed to compile such functions.
834 Implementing sparse matrices is a fair bit of work and it is not
835 clear that they win more than they lose (we don't want to
836 unnecessarily slow down compilation of normal code). By making
837 another pass for the pathological case, we can greatly speed up
838 their compilation without hurting normal code. This works because
839 all the insns in the unreachable blocks have either been deleted or
841 Note that we're talking about reducing memory usage by 10's of
842 megabytes and reducing compilation time by several minutes. */
843 /* ??? The choice of when to make another pass is a bit arbitrary,
844 and was derived from empirical data. */
849 n_basic_blocks
-= deleted
;
850 /* `n_basic_blocks' may not be correct at this point: two previously
851 separate blocks may now be merged. That's ok though as we
852 recalculate it during the second pass. It certainly can't be
853 any larger than the current value. */
859 /* Record INSN's block number as BB. */
862 set_block_num (insn
, bb
)
866 if (INSN_UID (insn
) >= max_uid_for_flow
)
868 /* Add one-eighth the size so we don't keep calling xrealloc. */
869 max_uid_for_flow
= INSN_UID (insn
) + (INSN_UID (insn
) + 7) / 8;
870 uid_block_number
= (int *)
871 xrealloc (uid_block_number
, (max_uid_for_flow
+ 1) * sizeof (int));
873 BLOCK_NUM (insn
) = bb
;
877 /* Subroutines of find_basic_blocks. */
879 /* Check expression X for label references;
880 if one is found, add INSN to the label's chain of references.
882 CHECKDUP means check for and avoid creating duplicate references
883 from the same insn. Such duplicates do no serious harm but
884 can slow life analysis. CHECKDUP is set only when duplicates
888 mark_label_ref (x
, insn
, checkdup
)
892 register RTX_CODE code
;
896 /* We can be called with NULL when scanning label_value_list. */
901 if (code
== LABEL_REF
)
903 register rtx label
= XEXP (x
, 0);
905 if (GET_CODE (label
) != CODE_LABEL
)
907 /* If the label was never emitted, this insn is junk,
908 but avoid a crash trying to refer to BLOCK_NUM (label).
909 This can happen as a result of a syntax error
910 and a diagnostic has already been printed. */
911 if (INSN_UID (label
) == 0)
913 CONTAINING_INSN (x
) = insn
;
914 /* if CHECKDUP is set, check for duplicate ref from same insn
917 for (y
= LABEL_REFS (label
); y
!= label
; y
= LABEL_NEXTREF (y
))
918 if (CONTAINING_INSN (y
) == insn
)
920 LABEL_NEXTREF (x
) = LABEL_REFS (label
);
921 LABEL_REFS (label
) = x
;
922 block_live_static
[BLOCK_NUM (label
)] = 1;
926 fmt
= GET_RTX_FORMAT (code
);
927 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
930 mark_label_ref (XEXP (x
, i
), insn
, 0);
934 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
935 mark_label_ref (XVECEXP (x
, i
, j
), insn
, 1);
940 /* Delete INSN by patching it out.
941 Return the next insn. */
944 flow_delete_insn (insn
)
947 /* ??? For the moment we assume we don't have to watch for NULLs here
948 since the start/end of basic blocks aren't deleted like this. */
949 NEXT_INSN (PREV_INSN (insn
)) = NEXT_INSN (insn
);
950 PREV_INSN (NEXT_INSN (insn
)) = PREV_INSN (insn
);
951 return NEXT_INSN (insn
);
954 /* Perform data flow analysis.
955 F is the first insn of the function and NREGS the number of register numbers
959 life_analysis (f
, nregs
, file
)
964 #ifdef ELIMINABLE_REGS
966 static struct {int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
969 /* Record which registers will be eliminated. We use this in
972 CLEAR_HARD_REG_SET (elim_reg_set
);
974 #ifdef ELIMINABLE_REGS
975 for (i
= 0; i
< sizeof eliminables
/ sizeof eliminables
[0]; i
++)
976 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
978 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
981 life_analysis_1 (f
, nregs
);
983 dump_flow_info (file
);
985 free_basic_block_vars (1);
988 /* Free the variables allocated by find_basic_blocks.
990 KEEP_HEAD_END_P is non-zero if basic_block_head and basic_block_end
991 are not to be freed. */
994 free_basic_block_vars (keep_head_end_p
)
997 if (basic_block_drops_in
)
999 free (basic_block_drops_in
);
1000 /* Tell dump_flow_info this isn't available anymore. */
1001 basic_block_drops_in
= 0;
1003 if (basic_block_loop_depth
)
1005 free (basic_block_loop_depth
);
1006 basic_block_loop_depth
= 0;
1008 if (uid_block_number
)
1010 free (uid_block_number
);
1011 uid_block_number
= 0;
1015 free (uid_volatile
);
1019 if (! keep_head_end_p
&& basic_block_head
)
1021 free (basic_block_head
);
1022 basic_block_head
= 0;
1023 free (basic_block_end
);
1024 basic_block_end
= 0;
1028 /* Determine which registers are live at the start of each
1029 basic block of the function whose first insn is F.
1030 NREGS is the number of registers used in F.
1031 We allocate the vector basic_block_live_at_start
1032 and the regsets that it points to, and fill them with the data.
1033 regset_size and regset_bytes are also set here. */
1036 life_analysis_1 (f
, nregs
)
1042 /* For each basic block, a bitmask of regs
1043 live on exit from the block. */
1044 regset
*basic_block_live_at_end
;
1045 /* For each basic block, a bitmask of regs
1046 live on entry to a successor-block of this block.
1047 If this does not match basic_block_live_at_end,
1048 that must be updated, and the block must be rescanned. */
1049 regset
*basic_block_new_live_at_end
;
1050 /* For each basic block, a bitmask of regs
1051 whose liveness at the end of the basic block
1052 can make a difference in which regs are live on entry to the block.
1053 These are the regs that are set within the basic block,
1054 possibly excluding those that are used after they are set. */
1055 regset
*basic_block_significant
;
1059 struct obstack flow_obstack
;
1061 gcc_obstack_init (&flow_obstack
);
1065 bzero (regs_ever_live
, sizeof regs_ever_live
);
1067 /* Allocate and zero out many data structures
1068 that will record the data from lifetime analysis. */
1070 allocate_for_life_analysis ();
1072 reg_next_use
= (rtx
*) alloca (nregs
* sizeof (rtx
));
1073 bzero ((char *) reg_next_use
, nregs
* sizeof (rtx
));
1075 /* Set up several regset-vectors used internally within this function.
1076 Their meanings are documented above, with their declarations. */
1078 basic_block_live_at_end
1079 = (regset
*) alloca (n_basic_blocks
* sizeof (regset
));
1081 /* Don't use alloca since that leads to a crash rather than an error message
1082 if there isn't enough space.
1083 Don't use oballoc since we may need to allocate other things during
1084 this function on the temporary obstack. */
1085 init_regset_vector (basic_block_live_at_end
, n_basic_blocks
, &flow_obstack
);
1087 basic_block_new_live_at_end
1088 = (regset
*) alloca (n_basic_blocks
* sizeof (regset
));
1089 init_regset_vector (basic_block_new_live_at_end
, n_basic_blocks
,
1092 basic_block_significant
1093 = (regset
*) alloca (n_basic_blocks
* sizeof (regset
));
1094 init_regset_vector (basic_block_significant
, n_basic_blocks
, &flow_obstack
);
1096 /* Record which insns refer to any volatile memory
1097 or for any reason can't be deleted just because they are dead stores.
1098 Also, delete any insns that copy a register to itself. */
1100 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
1102 enum rtx_code code1
= GET_CODE (insn
);
1103 if (code1
== CALL_INSN
)
1104 INSN_VOLATILE (insn
) = 1;
1105 else if (code1
== INSN
|| code1
== JUMP_INSN
)
1107 /* Delete (in effect) any obvious no-op moves. */
1108 if (GET_CODE (PATTERN (insn
)) == SET
1109 && GET_CODE (SET_DEST (PATTERN (insn
))) == REG
1110 && GET_CODE (SET_SRC (PATTERN (insn
))) == REG
1111 && (REGNO (SET_DEST (PATTERN (insn
)))
1112 == REGNO (SET_SRC (PATTERN (insn
))))
1113 /* Insns carrying these notes are useful later on. */
1114 && ! find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
1116 PUT_CODE (insn
, NOTE
);
1117 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1118 NOTE_SOURCE_FILE (insn
) = 0;
1120 /* Delete (in effect) any obvious no-op moves. */
1121 else if (GET_CODE (PATTERN (insn
)) == SET
1122 && GET_CODE (SET_DEST (PATTERN (insn
))) == SUBREG
1123 && GET_CODE (SUBREG_REG (SET_DEST (PATTERN (insn
)))) == REG
1124 && GET_CODE (SET_SRC (PATTERN (insn
))) == SUBREG
1125 && GET_CODE (SUBREG_REG (SET_SRC (PATTERN (insn
)))) == REG
1126 && (REGNO (SUBREG_REG (SET_DEST (PATTERN (insn
))))
1127 == REGNO (SUBREG_REG (SET_SRC (PATTERN (insn
)))))
1128 && SUBREG_WORD (SET_DEST (PATTERN (insn
))) ==
1129 SUBREG_WORD (SET_SRC (PATTERN (insn
)))
1130 /* Insns carrying these notes are useful later on. */
1131 && ! find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
1133 PUT_CODE (insn
, NOTE
);
1134 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1135 NOTE_SOURCE_FILE (insn
) = 0;
1137 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
1139 /* If nothing but SETs of registers to themselves,
1140 this insn can also be deleted. */
1141 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
1143 rtx tem
= XVECEXP (PATTERN (insn
), 0, i
);
1145 if (GET_CODE (tem
) == USE
1146 || GET_CODE (tem
) == CLOBBER
)
1149 if (GET_CODE (tem
) != SET
1150 || GET_CODE (SET_DEST (tem
)) != REG
1151 || GET_CODE (SET_SRC (tem
)) != REG
1152 || REGNO (SET_DEST (tem
)) != REGNO (SET_SRC (tem
)))
1156 if (i
== XVECLEN (PATTERN (insn
), 0)
1157 /* Insns carrying these notes are useful later on. */
1158 && ! find_reg_note (insn
, REG_EQUAL
, NULL_RTX
))
1160 PUT_CODE (insn
, NOTE
);
1161 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1162 NOTE_SOURCE_FILE (insn
) = 0;
1165 INSN_VOLATILE (insn
) = volatile_refs_p (PATTERN (insn
));
1167 else if (GET_CODE (PATTERN (insn
)) != USE
)
1168 INSN_VOLATILE (insn
) = volatile_refs_p (PATTERN (insn
));
1169 /* A SET that makes space on the stack cannot be dead.
1170 (Such SETs occur only for allocating variable-size data,
1171 so they will always have a PLUS or MINUS according to the
1172 direction of stack growth.)
1173 Even if this function never uses this stack pointer value,
1174 signal handlers do! */
1175 else if (code1
== INSN
&& GET_CODE (PATTERN (insn
)) == SET
1176 && SET_DEST (PATTERN (insn
)) == stack_pointer_rtx
1177 #ifdef STACK_GROWS_DOWNWARD
1178 && GET_CODE (SET_SRC (PATTERN (insn
))) == MINUS
1180 && GET_CODE (SET_SRC (PATTERN (insn
))) == PLUS
1182 && XEXP (SET_SRC (PATTERN (insn
)), 0) == stack_pointer_rtx
)
1183 INSN_VOLATILE (insn
) = 1;
1187 if (n_basic_blocks
> 0)
1188 #ifdef EXIT_IGNORE_STACK
1189 if (! EXIT_IGNORE_STACK
1190 || (! FRAME_POINTER_REQUIRED
1191 && ! current_function_calls_alloca
1192 && flag_omit_frame_pointer
))
1195 /* If exiting needs the right stack value,
1196 consider the stack pointer live at the end of the function. */
1197 SET_REGNO_REG_SET (basic_block_live_at_end
[n_basic_blocks
- 1],
1198 STACK_POINTER_REGNUM
);
1199 SET_REGNO_REG_SET (basic_block_new_live_at_end
[n_basic_blocks
- 1],
1200 STACK_POINTER_REGNUM
);
1203 /* Mark the frame pointer is needed at the end of the function. If
1204 we end up eliminating it, it will be removed from the live list
1205 of each basic block by reload. */
1207 if (n_basic_blocks
> 0)
1209 SET_REGNO_REG_SET (basic_block_live_at_end
[n_basic_blocks
- 1],
1210 FRAME_POINTER_REGNUM
);
1211 SET_REGNO_REG_SET (basic_block_new_live_at_end
[n_basic_blocks
- 1],
1212 FRAME_POINTER_REGNUM
);
1213 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
1214 /* If they are different, also mark the hard frame pointer as live */
1215 SET_REGNO_REG_SET (basic_block_live_at_end
[n_basic_blocks
- 1],
1216 HARD_FRAME_POINTER_REGNUM
);
1217 SET_REGNO_REG_SET (basic_block_new_live_at_end
[n_basic_blocks
- 1],
1218 HARD_FRAME_POINTER_REGNUM
);
1222 /* Mark all global registers and all registers used by the epilogue
1223 as being live at the end of the function since they may be
1224 referenced by our caller. */
1226 if (n_basic_blocks
> 0)
1227 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1229 #ifdef EPILOGUE_USES
1230 || EPILOGUE_USES (i
)
1234 SET_REGNO_REG_SET (basic_block_live_at_end
[n_basic_blocks
- 1], i
);
1235 SET_REGNO_REG_SET (basic_block_new_live_at_end
[n_basic_blocks
- 1], i
);
1238 /* Propagate life info through the basic blocks
1239 around the graph of basic blocks.
1241 This is a relaxation process: each time a new register
1242 is live at the end of the basic block, we must scan the block
1243 to determine which registers are, as a consequence, live at the beginning
1244 of that block. These registers must then be marked live at the ends
1245 of all the blocks that can transfer control to that block.
1246 The process continues until it reaches a fixed point. */
1253 for (i
= n_basic_blocks
- 1; i
>= 0; i
--)
1255 int consider
= first_pass
;
1256 int must_rescan
= first_pass
;
1261 /* Set CONSIDER if this block needs thinking about at all
1262 (that is, if the regs live now at the end of it
1263 are not the same as were live at the end of it when
1264 we last thought about it).
1265 Set must_rescan if it needs to be thought about
1266 instruction by instruction (that is, if any additional
1267 reg that is live at the end now but was not live there before
1268 is one of the significant regs of this basic block). */
1270 EXECUTE_IF_AND_COMPL_IN_REG_SET
1271 (basic_block_new_live_at_end
[i
],
1272 basic_block_live_at_end
[i
], 0, j
,
1275 if (REGNO_REG_SET_P (basic_block_significant
[i
], j
))
1286 /* The live_at_start of this block may be changing,
1287 so another pass will be required after this one. */
1292 /* No complete rescan needed;
1293 just record those variables newly known live at end
1294 as live at start as well. */
1295 IOR_AND_COMPL_REG_SET (basic_block_live_at_start
[i
],
1296 basic_block_new_live_at_end
[i
],
1297 basic_block_live_at_end
[i
]);
1299 IOR_AND_COMPL_REG_SET (basic_block_live_at_end
[i
],
1300 basic_block_new_live_at_end
[i
],
1301 basic_block_live_at_end
[i
]);
1305 /* Update the basic_block_live_at_start
1306 by propagation backwards through the block. */
1307 COPY_REG_SET (basic_block_live_at_end
[i
],
1308 basic_block_new_live_at_end
[i
]);
1309 COPY_REG_SET (basic_block_live_at_start
[i
],
1310 basic_block_live_at_end
[i
]);
1311 propagate_block (basic_block_live_at_start
[i
],
1312 basic_block_head
[i
], basic_block_end
[i
], 0,
1313 first_pass
? basic_block_significant
[i
]
1319 register rtx jump
, head
;
1321 /* Update the basic_block_new_live_at_end's of the block
1322 that falls through into this one (if any). */
1323 head
= basic_block_head
[i
];
1324 if (basic_block_drops_in
[i
])
1325 IOR_REG_SET (basic_block_new_live_at_end
[i
-1],
1326 basic_block_live_at_start
[i
]);
1328 /* Update the basic_block_new_live_at_end's of
1329 all the blocks that jump to this one. */
1330 if (GET_CODE (head
) == CODE_LABEL
)
1331 for (jump
= LABEL_REFS (head
);
1333 jump
= LABEL_NEXTREF (jump
))
1335 register int from_block
= BLOCK_NUM (CONTAINING_INSN (jump
));
1336 IOR_REG_SET (basic_block_new_live_at_end
[from_block
],
1337 basic_block_live_at_start
[i
]);
1347 /* The only pseudos that are live at the beginning of the function are
1348 those that were not set anywhere in the function. local-alloc doesn't
1349 know how to handle these correctly, so mark them as not local to any
1352 if (n_basic_blocks
> 0)
1353 EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start
[0],
1354 FIRST_PSEUDO_REGISTER
, i
,
1356 REG_BASIC_BLOCK (i
) = REG_BLOCK_GLOBAL
;
1359 /* Now the life information is accurate.
1360 Make one more pass over each basic block
1361 to delete dead stores, create autoincrement addressing
1362 and record how many times each register is used, is set, or dies.
1364 To save time, we operate directly in basic_block_live_at_end[i],
1365 thus destroying it (in fact, converting it into a copy of
1366 basic_block_live_at_start[i]). This is ok now because
1367 basic_block_live_at_end[i] is no longer used past this point. */
1371 for (i
= 0; i
< n_basic_blocks
; i
++)
1373 propagate_block (basic_block_live_at_end
[i
],
1374 basic_block_head
[i
], basic_block_end
[i
], 1,
1382 /* Something live during a setjmp should not be put in a register
1383 on certain machines which restore regs from stack frames
1384 rather than from the jmpbuf.
1385 But we don't need to do this for the user's variables, since
1386 ANSI says only volatile variables need this. */
1387 #ifdef LONGJMP_RESTORE_FROM_STACK
1388 EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp
,
1389 FIRST_PSEUDO_REGISTER
, i
,
1391 if (regno_reg_rtx
[i
] != 0
1392 && ! REG_USERVAR_P (regno_reg_rtx
[i
]))
1394 REG_LIVE_LENGTH (i
) = -1;
1395 REG_BASIC_BLOCK (i
) = -1;
1401 /* We have a problem with any pseudoreg that
1402 lives across the setjmp. ANSI says that if a
1403 user variable does not change in value
1404 between the setjmp and the longjmp, then the longjmp preserves it.
1405 This includes longjmp from a place where the pseudo appears dead.
1406 (In principle, the value still exists if it is in scope.)
1407 If the pseudo goes in a hard reg, some other value may occupy
1408 that hard reg where this pseudo is dead, thus clobbering the pseudo.
1409 Conclusion: such a pseudo must not go in a hard reg. */
1410 EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp
,
1411 FIRST_PSEUDO_REGISTER
, i
,
1413 if (regno_reg_rtx
[i
] != 0)
1415 REG_LIVE_LENGTH (i
) = -1;
1416 REG_BASIC_BLOCK (i
) = -1;
1421 free_regset_vector (basic_block_live_at_end
, n_basic_blocks
);
1422 free_regset_vector (basic_block_new_live_at_end
, n_basic_blocks
);
1423 free_regset_vector (basic_block_significant
, n_basic_blocks
);
1424 basic_block_live_at_end
= (regset
*)0;
1425 basic_block_new_live_at_end
= (regset
*)0;
1426 basic_block_significant
= (regset
*)0;
1428 obstack_free (&flow_obstack
, NULL_PTR
);
1431 /* Subroutines of life analysis. */
1433 /* Allocate the permanent data structures that represent the results
1434 of life analysis. Not static since used also for stupid life analysis. */
1437 allocate_for_life_analysis ()
1441 /* Recalculate the register space, in case it has grown. Old style
1442 vector oriented regsets would set regset_{size,bytes} here also. */
1443 allocate_reg_info (max_regno
, FALSE
, FALSE
);
1445 /* Because both reg_scan and flow_analysis want to set up the REG_N_SETS
1446 information, explicitly reset it here. The allocation should have
1447 already happened on the previous reg_scan pass. Make sure in case
1448 some more registers were allocated. */
1449 for (i
= 0; i
< max_regno
; i
++)
1452 basic_block_live_at_start
1453 = (regset
*) oballoc (n_basic_blocks
* sizeof (regset
));
1454 init_regset_vector (basic_block_live_at_start
, n_basic_blocks
,
1457 regs_live_at_setjmp
= OBSTACK_ALLOC_REG_SET (function_obstack
);
1458 CLEAR_REG_SET (regs_live_at_setjmp
);
1461 /* Make each element of VECTOR point at a regset. The vector has
1462 NELTS elements, and space is allocated from the ALLOC_OBSTACK
1466 init_regset_vector (vector
, nelts
, alloc_obstack
)
1469 struct obstack
*alloc_obstack
;
1473 for (i
= 0; i
< nelts
; i
++)
1475 vector
[i
] = OBSTACK_ALLOC_REG_SET (alloc_obstack
);
1476 CLEAR_REG_SET (vector
[i
]);
1480 /* Release any additional space allocated for each element of VECTOR point
1481 other than the regset header itself. The vector has NELTS elements. */
1484 free_regset_vector (vector
, nelts
)
1490 for (i
= 0; i
< nelts
; i
++)
1491 FREE_REG_SET (vector
[i
]);
1494 /* Compute the registers live at the beginning of a basic block
1495 from those live at the end.
1497 When called, OLD contains those live at the end.
1498 On return, it contains those live at the beginning.
1499 FIRST and LAST are the first and last insns of the basic block.
1501 FINAL is nonzero if we are doing the final pass which is not
1502 for computing the life info (since that has already been done)
1503 but for acting on it. On this pass, we delete dead stores,
1504 set up the logical links and dead-variables lists of instructions,
1505 and merge instructions for autoincrement and autodecrement addresses.
1507 SIGNIFICANT is nonzero only the first time for each basic block.
1508 If it is nonzero, it points to a regset in which we store
1509 a 1 for each register that is set within the block.
1511 BNUM is the number of the basic block. */
1514 propagate_block (old
, first
, last
, final
, significant
, bnum
)
1515 register regset old
;
1527 /* The following variables are used only if FINAL is nonzero. */
1528 /* This vector gets one element for each reg that has been live
1529 at any point in the basic block that has been scanned so far.
1530 SOMETIMES_MAX says how many elements are in use so far. */
1531 register int *regs_sometimes_live
;
1532 int sometimes_max
= 0;
1533 /* This regset has 1 for each reg that we have seen live so far.
1534 It and REGS_SOMETIMES_LIVE are updated together. */
1537 /* The loop depth may change in the middle of a basic block. Since we
1538 scan from end to beginning, we start with the depth at the end of the
1539 current basic block, and adjust as we pass ends and starts of loops. */
1540 loop_depth
= basic_block_loop_depth
[bnum
];
1542 dead
= ALLOCA_REG_SET ();
1543 live
= ALLOCA_REG_SET ();
1548 /* Include any notes at the end of the block in the scan.
1549 This is in case the block ends with a call to setjmp. */
1551 while (NEXT_INSN (last
) != 0 && GET_CODE (NEXT_INSN (last
)) == NOTE
)
1553 /* Look for loop boundaries, we are going forward here. */
1554 last
= NEXT_INSN (last
);
1555 if (NOTE_LINE_NUMBER (last
) == NOTE_INSN_LOOP_BEG
)
1557 else if (NOTE_LINE_NUMBER (last
) == NOTE_INSN_LOOP_END
)
1566 maxlive
= ALLOCA_REG_SET ();
1567 COPY_REG_SET (maxlive
, old
);
1568 regs_sometimes_live
= (int *) alloca (max_regno
* sizeof (int));
1570 /* Process the regs live at the end of the block.
1571 Enter them in MAXLIVE and REGS_SOMETIMES_LIVE.
1572 Also mark them as not local to any one basic block. */
1573 EXECUTE_IF_SET_IN_REG_SET (old
, 0, i
,
1575 REG_BASIC_BLOCK (i
) = REG_BLOCK_GLOBAL
;
1576 regs_sometimes_live
[sometimes_max
] = i
;
1581 /* Scan the block an insn at a time from end to beginning. */
1583 for (insn
= last
; ; insn
= prev
)
1585 prev
= PREV_INSN (insn
);
1587 if (GET_CODE (insn
) == NOTE
)
1589 /* Look for loop boundaries, remembering that we are going
1591 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
)
1593 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
)
1596 /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error.
1597 Abort now rather than setting register status incorrectly. */
1598 if (loop_depth
== 0)
1601 /* If this is a call to `setjmp' et al,
1602 warn if any non-volatile datum is live. */
1604 if (final
&& NOTE_LINE_NUMBER (insn
) == NOTE_INSN_SETJMP
)
1605 IOR_REG_SET (regs_live_at_setjmp
, old
);
1608 /* Update the life-status of regs for this insn.
1609 First DEAD gets which regs are set in this insn
1610 then LIVE gets which regs are used in this insn.
1611 Then the regs live before the insn
1612 are those live after, with DEAD regs turned off,
1613 and then LIVE regs turned on. */
1615 else if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
1618 rtx note
= find_reg_note (insn
, REG_RETVAL
, NULL_RTX
);
1620 = (insn_dead_p (PATTERN (insn
), old
, 0)
1621 /* Don't delete something that refers to volatile storage! */
1622 && ! INSN_VOLATILE (insn
));
1624 = (insn_is_dead
&& note
!= 0
1625 && libcall_dead_p (PATTERN (insn
), old
, note
, insn
));
1627 /* If an instruction consists of just dead store(s) on final pass,
1628 "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED.
1629 We could really delete it with delete_insn, but that
1630 can cause trouble for first or last insn in a basic block. */
1631 if (final
&& insn_is_dead
)
1633 PUT_CODE (insn
, NOTE
);
1634 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1635 NOTE_SOURCE_FILE (insn
) = 0;
1637 /* CC0 is now known to be dead. Either this insn used it,
1638 in which case it doesn't anymore, or clobbered it,
1639 so the next insn can't use it. */
1642 /* If this insn is copying the return value from a library call,
1643 delete the entire library call. */
1644 if (libcall_is_dead
)
1646 rtx first
= XEXP (note
, 0);
1648 while (INSN_DELETED_P (first
))
1649 first
= NEXT_INSN (first
);
1654 NOTE_LINE_NUMBER (p
) = NOTE_INSN_DELETED
;
1655 NOTE_SOURCE_FILE (p
) = 0;
1661 CLEAR_REG_SET (dead
);
1662 CLEAR_REG_SET (live
);
1664 /* See if this is an increment or decrement that can be
1665 merged into a following memory address. */
1668 register rtx x
= single_set (insn
);
1670 /* Does this instruction increment or decrement a register? */
1672 && GET_CODE (SET_DEST (x
)) == REG
1673 && (GET_CODE (SET_SRC (x
)) == PLUS
1674 || GET_CODE (SET_SRC (x
)) == MINUS
)
1675 && XEXP (SET_SRC (x
), 0) == SET_DEST (x
)
1676 && GET_CODE (XEXP (SET_SRC (x
), 1)) == CONST_INT
1677 /* Ok, look for a following memory ref we can combine with.
1678 If one is found, change the memory ref to a PRE_INC
1679 or PRE_DEC, cancel this insn, and return 1.
1680 Return 0 if nothing has been done. */
1681 && try_pre_increment_1 (insn
))
1684 #endif /* AUTO_INC_DEC */
1686 /* If this is not the final pass, and this insn is copying the
1687 value of a library call and it's dead, don't scan the
1688 insns that perform the library call, so that the call's
1689 arguments are not marked live. */
1690 if (libcall_is_dead
)
1692 /* Mark the dest reg as `significant'. */
1693 mark_set_regs (old
, dead
, PATTERN (insn
), NULL_RTX
, significant
);
1695 insn
= XEXP (note
, 0);
1696 prev
= PREV_INSN (insn
);
1698 else if (GET_CODE (PATTERN (insn
)) == SET
1699 && SET_DEST (PATTERN (insn
)) == stack_pointer_rtx
1700 && GET_CODE (SET_SRC (PATTERN (insn
))) == PLUS
1701 && XEXP (SET_SRC (PATTERN (insn
)), 0) == stack_pointer_rtx
1702 && GET_CODE (XEXP (SET_SRC (PATTERN (insn
)), 1)) == CONST_INT
)
1703 /* We have an insn to pop a constant amount off the stack.
1704 (Such insns use PLUS regardless of the direction of the stack,
1705 and any insn to adjust the stack by a constant is always a pop.)
1706 These insns, if not dead stores, have no effect on life. */
1710 /* LIVE gets the regs used in INSN;
1711 DEAD gets those set by it. Dead insns don't make anything
1714 mark_set_regs (old
, dead
, PATTERN (insn
),
1715 final
? insn
: NULL_RTX
, significant
);
1717 /* If an insn doesn't use CC0, it becomes dead since we
1718 assume that every insn clobbers it. So show it dead here;
1719 mark_used_regs will set it live if it is referenced. */
1723 mark_used_regs (old
, live
, PATTERN (insn
), final
, insn
);
1725 /* Sometimes we may have inserted something before INSN (such as
1726 a move) when we make an auto-inc. So ensure we will scan
1729 prev
= PREV_INSN (insn
);
1732 if (! insn_is_dead
&& GET_CODE (insn
) == CALL_INSN
)
1738 for (note
= CALL_INSN_FUNCTION_USAGE (insn
);
1740 note
= XEXP (note
, 1))
1741 if (GET_CODE (XEXP (note
, 0)) == USE
)
1742 mark_used_regs (old
, live
, SET_DEST (XEXP (note
, 0)),
1745 /* Each call clobbers all call-clobbered regs that are not
1746 global or fixed. Note that the function-value reg is a
1747 call-clobbered reg, and mark_set_regs has already had
1748 a chance to handle it. */
1750 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1751 if (call_used_regs
[i
] && ! global_regs
[i
]
1753 SET_REGNO_REG_SET (dead
, i
);
1755 /* The stack ptr is used (honorarily) by a CALL insn. */
1756 SET_REGNO_REG_SET (live
, STACK_POINTER_REGNUM
);
1758 /* Calls may also reference any of the global registers,
1759 so they are made live. */
1760 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1762 mark_used_regs (old
, live
,
1763 gen_rtx_REG (reg_raw_mode
[i
], i
),
1766 /* Calls also clobber memory. */
1770 /* Update OLD for the registers used or set. */
1771 AND_COMPL_REG_SET (old
, dead
);
1772 IOR_REG_SET (old
, live
);
1774 if (GET_CODE (insn
) == CALL_INSN
&& final
)
1776 /* Any regs live at the time of a call instruction
1777 must not go in a register clobbered by calls.
1778 Find all regs now live and record this for them. */
1780 register int *p
= regs_sometimes_live
;
1782 for (i
= 0; i
< sometimes_max
; i
++, p
++)
1783 if (REGNO_REG_SET_P (old
, *p
))
1784 REG_N_CALLS_CROSSED (*p
)++;
1788 /* On final pass, add any additional sometimes-live regs
1789 into MAXLIVE and REGS_SOMETIMES_LIVE.
1790 Also update counts of how many insns each reg is live at. */
1797 EXECUTE_IF_AND_COMPL_IN_REG_SET
1798 (live
, maxlive
, 0, regno
,
1800 regs_sometimes_live
[sometimes_max
++] = regno
;
1801 SET_REGNO_REG_SET (maxlive
, regno
);
1804 p
= regs_sometimes_live
;
1805 for (i
= 0; i
< sometimes_max
; i
++)
1808 if (REGNO_REG_SET_P (old
, regno
))
1809 REG_LIVE_LENGTH (regno
)++;
1818 FREE_REG_SET (dead
);
1819 FREE_REG_SET (live
);
1821 FREE_REG_SET (maxlive
);
1823 if (num_scratch
> max_scratch
)
1824 max_scratch
= num_scratch
;
1827 /* Return 1 if X (the body of an insn, or part of it) is just dead stores
1828 (SET expressions whose destinations are registers dead after the insn).
1829 NEEDED is the regset that says which regs are alive after the insn.
1831 Unless CALL_OK is non-zero, an insn is needed if it contains a CALL. */
1834 insn_dead_p (x
, needed
, call_ok
)
1839 register RTX_CODE code
= GET_CODE (x
);
1840 /* If setting something that's a reg or part of one,
1841 see if that register's altered value will be live. */
1845 register rtx r
= SET_DEST (x
);
1846 /* A SET that is a subroutine call cannot be dead. */
1847 if (! call_ok
&& GET_CODE (SET_SRC (x
)) == CALL
)
1851 if (GET_CODE (r
) == CC0
)
1855 if (GET_CODE (r
) == MEM
&& last_mem_set
&& ! MEM_VOLATILE_P (r
)
1856 && rtx_equal_p (r
, last_mem_set
))
1859 while (GET_CODE (r
) == SUBREG
1860 || GET_CODE (r
) == STRICT_LOW_PART
1861 || GET_CODE (r
) == ZERO_EXTRACT
1862 || GET_CODE (r
) == SIGN_EXTRACT
)
1865 if (GET_CODE (r
) == REG
)
1867 register int regno
= REGNO (r
);
1869 /* Don't delete insns to set global regs. */
1870 if ((regno
< FIRST_PSEUDO_REGISTER
&& global_regs
[regno
])
1871 /* Make sure insns to set frame pointer aren't deleted. */
1872 || regno
== FRAME_POINTER_REGNUM
1873 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
1874 || regno
== HARD_FRAME_POINTER_REGNUM
1876 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1877 /* Make sure insns to set arg pointer are never deleted
1878 (if the arg pointer isn't fixed, there will be a USE for
1879 it, so we can treat it normally). */
1880 || (regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
1882 || REGNO_REG_SET_P (needed
, regno
))
1885 /* If this is a hard register, verify that subsequent words are
1887 if (regno
< FIRST_PSEUDO_REGISTER
)
1889 int n
= HARD_REGNO_NREGS (regno
, GET_MODE (r
));
1892 if (REGNO_REG_SET_P (needed
, regno
+n
))
1899 /* If performing several activities,
1900 insn is dead if each activity is individually dead.
1901 Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE
1902 that's inside a PARALLEL doesn't make the insn worth keeping. */
1903 else if (code
== PARALLEL
)
1905 register int i
= XVECLEN (x
, 0);
1906 for (i
--; i
>= 0; i
--)
1908 rtx elt
= XVECEXP (x
, 0, i
);
1909 if (!insn_dead_p (elt
, needed
, call_ok
)
1910 && GET_CODE (elt
) != CLOBBER
1911 && GET_CODE (elt
) != USE
)
1916 /* We do not check CLOBBER or USE here.
1917 An insn consisting of just a CLOBBER or just a USE
1918 should not be deleted. */
1922 /* If X is the pattern of the last insn in a libcall, and assuming X is dead,
1923 return 1 if the entire library call is dead.
1924 This is true if X copies a register (hard or pseudo)
1925 and if the hard return reg of the call insn is dead.
1926 (The caller should have tested the destination of X already for death.)
1928 If this insn doesn't just copy a register, then we don't
1929 have an ordinary libcall. In that case, cse could not have
1930 managed to substitute the source for the dest later on,
1931 so we can assume the libcall is dead.
1933 NEEDED is the bit vector of pseudoregs live before this insn.
1934 NOTE is the REG_RETVAL note of the insn. INSN is the insn itself. */
1937 libcall_dead_p (x
, needed
, note
, insn
)
1943 register RTX_CODE code
= GET_CODE (x
);
1947 register rtx r
= SET_SRC (x
);
1948 if (GET_CODE (r
) == REG
)
1950 rtx call
= XEXP (note
, 0);
1953 /* Find the call insn. */
1954 while (call
!= insn
&& GET_CODE (call
) != CALL_INSN
)
1955 call
= NEXT_INSN (call
);
1957 /* If there is none, do nothing special,
1958 since ordinary death handling can understand these insns. */
1962 /* See if the hard reg holding the value is dead.
1963 If this is a PARALLEL, find the call within it. */
1964 call
= PATTERN (call
);
1965 if (GET_CODE (call
) == PARALLEL
)
1967 for (i
= XVECLEN (call
, 0) - 1; i
>= 0; i
--)
1968 if (GET_CODE (XVECEXP (call
, 0, i
)) == SET
1969 && GET_CODE (SET_SRC (XVECEXP (call
, 0, i
))) == CALL
)
1972 /* This may be a library call that is returning a value
1973 via invisible pointer. Do nothing special, since
1974 ordinary death handling can understand these insns. */
1978 call
= XVECEXP (call
, 0, i
);
1981 return insn_dead_p (call
, needed
, 1);
1987 /* Return 1 if register REGNO was used before it was set.
1988 In other words, if it is live at function entry.
1989 Don't count global register variables or variables in registers
1990 that can be used for function arg passing, though. */
1993 regno_uninitialized (regno
)
1996 if (n_basic_blocks
== 0
1997 || (regno
< FIRST_PSEUDO_REGISTER
1998 && (global_regs
[regno
] || FUNCTION_ARG_REGNO_P (regno
))))
2001 return REGNO_REG_SET_P (basic_block_live_at_start
[0], regno
);
2004 /* 1 if register REGNO was alive at a place where `setjmp' was called
2005 and was set more than once or is an argument.
2006 Such regs may be clobbered by `longjmp'. */
2009 regno_clobbered_at_setjmp (regno
)
2012 if (n_basic_blocks
== 0)
2015 return ((REG_N_SETS (regno
) > 1
2016 || REGNO_REG_SET_P (basic_block_live_at_start
[0], regno
))
2017 && REGNO_REG_SET_P (regs_live_at_setjmp
, regno
));
2020 /* Process the registers that are set within X.
2021 Their bits are set to 1 in the regset DEAD,
2022 because they are dead prior to this insn.
2024 If INSN is nonzero, it is the insn being processed
2025 and the fact that it is nonzero implies this is the FINAL pass
2026 in propagate_block. In this case, various info about register
2027 usage is stored, LOG_LINKS fields of insns are set up. */
2030 mark_set_regs (needed
, dead
, x
, insn
, significant
)
2037 register RTX_CODE code
= GET_CODE (x
);
2039 if (code
== SET
|| code
== CLOBBER
)
2040 mark_set_1 (needed
, dead
, x
, insn
, significant
);
2041 else if (code
== PARALLEL
)
2044 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
2046 code
= GET_CODE (XVECEXP (x
, 0, i
));
2047 if (code
== SET
|| code
== CLOBBER
)
2048 mark_set_1 (needed
, dead
, XVECEXP (x
, 0, i
), insn
, significant
);
2053 /* Process a single SET rtx, X. */
2056 mark_set_1 (needed
, dead
, x
, insn
, significant
)
2064 register rtx reg
= SET_DEST (x
);
2066 /* Modifying just one hardware register of a multi-reg value
2067 or just a byte field of a register
2068 does not mean the value from before this insn is now dead.
2069 But it does mean liveness of that register at the end of the block
2072 Within mark_set_1, however, we treat it as if the register is
2073 indeed modified. mark_used_regs will, however, also treat this
2074 register as being used. Thus, we treat these insns as setting a
2075 new value for the register as a function of its old value. This
2076 cases LOG_LINKS to be made appropriately and this will help combine. */
2078 while (GET_CODE (reg
) == SUBREG
|| GET_CODE (reg
) == ZERO_EXTRACT
2079 || GET_CODE (reg
) == SIGN_EXTRACT
2080 || GET_CODE (reg
) == STRICT_LOW_PART
)
2081 reg
= XEXP (reg
, 0);
2083 /* If we are writing into memory or into a register mentioned in the
2084 address of the last thing stored into memory, show we don't know
2085 what the last store was. If we are writing memory, save the address
2086 unless it is volatile. */
2087 if (GET_CODE (reg
) == MEM
2088 || (GET_CODE (reg
) == REG
2089 && last_mem_set
!= 0 && reg_overlap_mentioned_p (reg
, last_mem_set
)))
2092 if (GET_CODE (reg
) == MEM
&& ! side_effects_p (reg
)
2093 /* There are no REG_INC notes for SP, so we can't assume we'll see
2094 everything that invalidates it. To be safe, don't eliminate any
2095 stores though SP; none of them should be redundant anyway. */
2096 && ! reg_mentioned_p (stack_pointer_rtx
, reg
))
2099 if (GET_CODE (reg
) == REG
2100 && (regno
= REGNO (reg
), regno
!= FRAME_POINTER_REGNUM
)
2101 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2102 && regno
!= HARD_FRAME_POINTER_REGNUM
2104 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2105 && ! (regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
2107 && ! (regno
< FIRST_PSEUDO_REGISTER
&& global_regs
[regno
]))
2108 /* && regno != STACK_POINTER_REGNUM) -- let's try without this. */
2110 int some_needed
= REGNO_REG_SET_P (needed
, regno
);
2111 int some_not_needed
= ! some_needed
;
2113 /* Mark it as a significant register for this basic block. */
2115 SET_REGNO_REG_SET (significant
, regno
);
2117 /* Mark it as as dead before this insn. */
2118 SET_REGNO_REG_SET (dead
, regno
);
2120 /* A hard reg in a wide mode may really be multiple registers.
2121 If so, mark all of them just like the first. */
2122 if (regno
< FIRST_PSEUDO_REGISTER
)
2126 /* Nothing below is needed for the stack pointer; get out asap.
2127 Eg, log links aren't needed, since combine won't use them. */
2128 if (regno
== STACK_POINTER_REGNUM
)
2131 n
= HARD_REGNO_NREGS (regno
, GET_MODE (reg
));
2134 int regno_n
= regno
+ n
;
2135 int needed_regno
= REGNO_REG_SET_P (needed
, regno_n
);
2137 SET_REGNO_REG_SET (significant
, regno_n
);
2139 SET_REGNO_REG_SET (dead
, regno_n
);
2140 some_needed
|= needed_regno
;
2141 some_not_needed
|= ! needed_regno
;
2144 /* Additional data to record if this is the final pass. */
2147 register rtx y
= reg_next_use
[regno
];
2148 register int blocknum
= BLOCK_NUM (insn
);
2150 /* If this is a hard reg, record this function uses the reg. */
2152 if (regno
< FIRST_PSEUDO_REGISTER
)
2155 int endregno
= regno
+ HARD_REGNO_NREGS (regno
, GET_MODE (reg
));
2157 for (i
= regno
; i
< endregno
; i
++)
2159 /* The next use is no longer "next", since a store
2161 reg_next_use
[i
] = 0;
2163 regs_ever_live
[i
] = 1;
2169 /* The next use is no longer "next", since a store
2171 reg_next_use
[regno
] = 0;
2173 /* Keep track of which basic blocks each reg appears in. */
2175 if (REG_BASIC_BLOCK (regno
) == REG_BLOCK_UNKNOWN
)
2176 REG_BASIC_BLOCK (regno
) = blocknum
;
2177 else if (REG_BASIC_BLOCK (regno
) != blocknum
)
2178 REG_BASIC_BLOCK (regno
) = REG_BLOCK_GLOBAL
;
2180 /* Count (weighted) references, stores, etc. This counts a
2181 register twice if it is modified, but that is correct. */
2182 REG_N_SETS (regno
)++;
2184 REG_N_REFS (regno
) += loop_depth
;
2186 /* The insns where a reg is live are normally counted
2187 elsewhere, but we want the count to include the insn
2188 where the reg is set, and the normal counting mechanism
2189 would not count it. */
2190 REG_LIVE_LENGTH (regno
)++;
2193 if (! some_not_needed
)
2195 /* Make a logical link from the next following insn
2196 that uses this register, back to this insn.
2197 The following insns have already been processed.
2199 We don't build a LOG_LINK for hard registers containing
2200 in ASM_OPERANDs. If these registers get replaced,
2201 we might wind up changing the semantics of the insn,
2202 even if reload can make what appear to be valid assignments
2204 if (y
&& (BLOCK_NUM (y
) == blocknum
)
2205 && (regno
>= FIRST_PSEUDO_REGISTER
2206 || asm_noperands (PATTERN (y
)) < 0))
2208 = gen_rtx_INSN_LIST (VOIDmode
, insn
, LOG_LINKS (y
));
2210 else if (! some_needed
)
2212 /* Note that dead stores have already been deleted when possible
2213 If we get here, we have found a dead store that cannot
2214 be eliminated (because the same insn does something useful).
2215 Indicate this by marking the reg being set as dying here. */
2217 = gen_rtx_EXPR_LIST (REG_UNUSED
, reg
, REG_NOTES (insn
));
2218 REG_N_DEATHS (REGNO (reg
))++;
2222 /* This is a case where we have a multi-word hard register
2223 and some, but not all, of the words of the register are
2224 needed in subsequent insns. Write REG_UNUSED notes
2225 for those parts that were not needed. This case should
2230 for (i
= HARD_REGNO_NREGS (regno
, GET_MODE (reg
)) - 1;
2232 if (!REGNO_REG_SET_P (needed
, regno
+ i
))
2234 = gen_rtx_EXPR_LIST (REG_UNUSED
,
2235 gen_rtx_REG (reg_raw_mode
[regno
+ i
],
2241 else if (GET_CODE (reg
) == REG
)
2242 reg_next_use
[regno
] = 0;
2244 /* If this is the last pass and this is a SCRATCH, show it will be dying
2245 here and count it. */
2246 else if (GET_CODE (reg
) == SCRATCH
&& insn
!= 0)
2249 = gen_rtx_EXPR_LIST (REG_UNUSED
, reg
, REG_NOTES (insn
));
2256 /* X is a MEM found in INSN. See if we can convert it into an auto-increment
2260 find_auto_inc (needed
, x
, insn
)
2265 rtx addr
= XEXP (x
, 0);
2266 HOST_WIDE_INT offset
= 0;
2269 /* Here we detect use of an index register which might be good for
2270 postincrement, postdecrement, preincrement, or predecrement. */
2272 if (GET_CODE (addr
) == PLUS
&& GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
2273 offset
= INTVAL (XEXP (addr
, 1)), addr
= XEXP (addr
, 0);
2275 if (GET_CODE (addr
) == REG
)
2278 register int size
= GET_MODE_SIZE (GET_MODE (x
));
2281 int regno
= REGNO (addr
);
2283 /* Is the next use an increment that might make auto-increment? */
2284 if ((incr
= reg_next_use
[regno
]) != 0
2285 && (set
= single_set (incr
)) != 0
2286 && GET_CODE (set
) == SET
2287 && BLOCK_NUM (incr
) == BLOCK_NUM (insn
)
2288 /* Can't add side effects to jumps; if reg is spilled and
2289 reloaded, there's no way to store back the altered value. */
2290 && GET_CODE (insn
) != JUMP_INSN
2291 && (y
= SET_SRC (set
), GET_CODE (y
) == PLUS
)
2292 && XEXP (y
, 0) == addr
2293 && GET_CODE (XEXP (y
, 1)) == CONST_INT
2295 #ifdef HAVE_POST_INCREMENT
2296 || (INTVAL (XEXP (y
, 1)) == size
&& offset
== 0)
2298 #ifdef HAVE_POST_DECREMENT
2299 || (INTVAL (XEXP (y
, 1)) == - size
&& offset
== 0)
2301 #ifdef HAVE_PRE_INCREMENT
2302 || (INTVAL (XEXP (y
, 1)) == size
&& offset
== size
)
2304 #ifdef HAVE_PRE_DECREMENT
2305 || (INTVAL (XEXP (y
, 1)) == - size
&& offset
== - size
)
2308 /* Make sure this reg appears only once in this insn. */
2309 && (use
= find_use_as_address (PATTERN (insn
), addr
, offset
),
2310 use
!= 0 && use
!= (rtx
) 1))
2312 rtx q
= SET_DEST (set
);
2313 enum rtx_code inc_code
= (INTVAL (XEXP (y
, 1)) == size
2314 ? (offset
? PRE_INC
: POST_INC
)
2315 : (offset
? PRE_DEC
: POST_DEC
));
2317 if (dead_or_set_p (incr
, addr
))
2319 /* This is the simple case. Try to make the auto-inc. If
2320 we can't, we are done. Otherwise, we will do any
2321 needed updates below. */
2322 if (! validate_change (insn
, &XEXP (x
, 0),
2323 gen_rtx_fmt_e (inc_code
, Pmode
, addr
),
2327 else if (GET_CODE (q
) == REG
2328 /* PREV_INSN used here to check the semi-open interval
2330 && ! reg_used_between_p (q
, PREV_INSN (insn
), incr
)
2331 /* We must also check for sets of q as q may be
2332 a call clobbered hard register and there may
2333 be a call between PREV_INSN (insn) and incr. */
2334 && ! reg_set_between_p (q
, PREV_INSN (insn
), incr
))
2336 /* We have *p followed sometime later by q = p+size.
2337 Both p and q must be live afterward,
2338 and q is not used between INSN and it's assignment.
2339 Change it to q = p, ...*q..., q = q+size.
2340 Then fall into the usual case. */
2344 emit_move_insn (q
, addr
);
2345 insns
= get_insns ();
2348 /* If anything in INSNS have UID's that don't fit within the
2349 extra space we allocate earlier, we can't make this auto-inc.
2350 This should never happen. */
2351 for (temp
= insns
; temp
; temp
= NEXT_INSN (temp
))
2353 if (INSN_UID (temp
) > max_uid_for_flow
)
2355 BLOCK_NUM (temp
) = BLOCK_NUM (insn
);
2358 /* If we can't make the auto-inc, or can't make the
2359 replacement into Y, exit. There's no point in making
2360 the change below if we can't do the auto-inc and doing
2361 so is not correct in the pre-inc case. */
2363 validate_change (insn
, &XEXP (x
, 0),
2364 gen_rtx_fmt_e (inc_code
, Pmode
, q
),
2366 validate_change (incr
, &XEXP (y
, 0), q
, 1);
2367 if (! apply_change_group ())
2370 /* We now know we'll be doing this change, so emit the
2371 new insn(s) and do the updates. */
2372 emit_insns_before (insns
, insn
);
2374 if (basic_block_head
[BLOCK_NUM (insn
)] == insn
)
2375 basic_block_head
[BLOCK_NUM (insn
)] = insns
;
2377 /* INCR will become a NOTE and INSN won't contain a
2378 use of ADDR. If a use of ADDR was just placed in
2379 the insn before INSN, make that the next use.
2380 Otherwise, invalidate it. */
2381 if (GET_CODE (PREV_INSN (insn
)) == INSN
2382 && GET_CODE (PATTERN (PREV_INSN (insn
))) == SET
2383 && SET_SRC (PATTERN (PREV_INSN (insn
))) == addr
)
2384 reg_next_use
[regno
] = PREV_INSN (insn
);
2386 reg_next_use
[regno
] = 0;
2391 /* REGNO is now used in INCR which is below INSN, but
2392 it previously wasn't live here. If we don't mark
2393 it as needed, we'll put a REG_DEAD note for it
2394 on this insn, which is incorrect. */
2395 SET_REGNO_REG_SET (needed
, regno
);
2397 /* If there are any calls between INSN and INCR, show
2398 that REGNO now crosses them. */
2399 for (temp
= insn
; temp
!= incr
; temp
= NEXT_INSN (temp
))
2400 if (GET_CODE (temp
) == CALL_INSN
)
2401 REG_N_CALLS_CROSSED (regno
)++;
2406 /* If we haven't returned, it means we were able to make the
2407 auto-inc, so update the status. First, record that this insn
2408 has an implicit side effect. */
2411 = gen_rtx_EXPR_LIST (REG_INC
, addr
, REG_NOTES (insn
));
2413 /* Modify the old increment-insn to simply copy
2414 the already-incremented value of our register. */
2415 if (! validate_change (incr
, &SET_SRC (set
), addr
, 0))
2418 /* If that makes it a no-op (copying the register into itself) delete
2419 it so it won't appear to be a "use" and a "set" of this
2421 if (SET_DEST (set
) == addr
)
2423 PUT_CODE (incr
, NOTE
);
2424 NOTE_LINE_NUMBER (incr
) = NOTE_INSN_DELETED
;
2425 NOTE_SOURCE_FILE (incr
) = 0;
2428 if (regno
>= FIRST_PSEUDO_REGISTER
)
2430 /* Count an extra reference to the reg. When a reg is
2431 incremented, spilling it is worse, so we want to make
2432 that less likely. */
2433 REG_N_REFS (regno
) += loop_depth
;
2435 /* Count the increment as a setting of the register,
2436 even though it isn't a SET in rtl. */
2437 REG_N_SETS (regno
)++;
2442 #endif /* AUTO_INC_DEC */
2444 /* Scan expression X and store a 1-bit in LIVE for each reg it uses.
2445 This is done assuming the registers needed from X
2446 are those that have 1-bits in NEEDED.
2448 On the final pass, FINAL is 1. This means try for autoincrement
2449 and count the uses and deaths of each pseudo-reg.
2451 INSN is the containing instruction. If INSN is dead, this function is not
2455 mark_used_regs (needed
, live
, x
, final
, insn
)
2462 register RTX_CODE code
;
2467 code
= GET_CODE (x
);
2488 /* If we are clobbering a MEM, mark any registers inside the address
2490 if (GET_CODE (XEXP (x
, 0)) == MEM
)
2491 mark_used_regs (needed
, live
, XEXP (XEXP (x
, 0), 0), final
, insn
);
2495 /* Invalidate the data for the last MEM stored, but only if MEM is
2496 something that can be stored into. */
2497 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
2498 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)))
2499 ; /* needn't clear last_mem_set */
2505 find_auto_inc (needed
, x
, insn
);
2510 if (GET_CODE (SUBREG_REG (x
)) == REG
2511 && REGNO (SUBREG_REG (x
)) >= FIRST_PSEUDO_REGISTER
2512 && (GET_MODE_SIZE (GET_MODE (x
))
2513 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
)))))
2514 REG_CHANGES_SIZE (REGNO (SUBREG_REG (x
))) = 1;
2516 /* While we're here, optimize this case. */
2519 /* In case the SUBREG is not of a register, don't optimize */
2520 if (GET_CODE (x
) != REG
)
2522 mark_used_regs (needed
, live
, x
, final
, insn
);
2526 /* ... fall through ... */
2529 /* See a register other than being set
2530 => mark it as needed. */
2534 int some_needed
= REGNO_REG_SET_P (needed
, regno
);
2535 int some_not_needed
= ! some_needed
;
2537 SET_REGNO_REG_SET (live
, regno
);
2539 /* A hard reg in a wide mode may really be multiple registers.
2540 If so, mark all of them just like the first. */
2541 if (regno
< FIRST_PSEUDO_REGISTER
)
2545 /* For stack ptr or fixed arg pointer,
2546 nothing below can be necessary, so waste no more time. */
2547 if (regno
== STACK_POINTER_REGNUM
2548 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2549 || regno
== HARD_FRAME_POINTER_REGNUM
2551 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2552 || (regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
2554 || regno
== FRAME_POINTER_REGNUM
)
2556 /* If this is a register we are going to try to eliminate,
2557 don't mark it live here. If we are successful in
2558 eliminating it, it need not be live unless it is used for
2559 pseudos, in which case it will have been set live when
2560 it was allocated to the pseudos. If the register will not
2561 be eliminated, reload will set it live at that point. */
2563 if (! TEST_HARD_REG_BIT (elim_reg_set
, regno
))
2564 regs_ever_live
[regno
] = 1;
2567 /* No death notes for global register variables;
2568 their values are live after this function exits. */
2569 if (global_regs
[regno
])
2572 reg_next_use
[regno
] = insn
;
2576 n
= HARD_REGNO_NREGS (regno
, GET_MODE (x
));
2579 int regno_n
= regno
+ n
;
2580 int needed_regno
= REGNO_REG_SET_P (needed
, regno_n
);
2582 SET_REGNO_REG_SET (live
, regno_n
);
2583 some_needed
|= needed_regno
;
2584 some_not_needed
|= ! needed_regno
;
2589 /* Record where each reg is used, so when the reg
2590 is set we know the next insn that uses it. */
2592 reg_next_use
[regno
] = insn
;
2594 if (regno
< FIRST_PSEUDO_REGISTER
)
2596 /* If a hard reg is being used,
2597 record that this function does use it. */
2599 i
= HARD_REGNO_NREGS (regno
, GET_MODE (x
));
2603 regs_ever_live
[regno
+ --i
] = 1;
2608 /* Keep track of which basic block each reg appears in. */
2610 register int blocknum
= BLOCK_NUM (insn
);
2612 if (REG_BASIC_BLOCK (regno
) == REG_BLOCK_UNKNOWN
)
2613 REG_BASIC_BLOCK (regno
) = blocknum
;
2614 else if (REG_BASIC_BLOCK (regno
) != blocknum
)
2615 REG_BASIC_BLOCK (regno
) = REG_BLOCK_GLOBAL
;
2617 /* Count (weighted) number of uses of each reg. */
2619 REG_N_REFS (regno
) += loop_depth
;
2622 /* Record and count the insns in which a reg dies.
2623 If it is used in this insn and was dead below the insn
2624 then it dies in this insn. If it was set in this insn,
2625 we do not make a REG_DEAD note; likewise if we already
2626 made such a note. */
2629 && ! dead_or_set_p (insn
, x
)
2631 && (regno
>= FIRST_PSEUDO_REGISTER
|| ! fixed_regs
[regno
])
2635 /* Check for the case where the register dying partially
2636 overlaps the register set by this insn. */
2637 if (regno
< FIRST_PSEUDO_REGISTER
2638 && HARD_REGNO_NREGS (regno
, GET_MODE (x
)) > 1)
2640 int n
= HARD_REGNO_NREGS (regno
, GET_MODE (x
));
2642 some_needed
|= dead_or_set_regno_p (insn
, regno
+ n
);
2645 /* If none of the words in X is needed, make a REG_DEAD
2646 note. Otherwise, we must make partial REG_DEAD notes. */
2650 = gen_rtx_EXPR_LIST (REG_DEAD
, x
, REG_NOTES (insn
));
2651 REG_N_DEATHS (regno
)++;
2657 /* Don't make a REG_DEAD note for a part of a register
2658 that is set in the insn. */
2660 for (i
= HARD_REGNO_NREGS (regno
, GET_MODE (x
)) - 1;
2662 if (!REGNO_REG_SET_P (needed
, regno
+ i
)
2663 && ! dead_or_set_regno_p (insn
, regno
+ i
))
2665 = gen_rtx_EXPR_LIST (REG_DEAD
,
2666 gen_rtx_REG (reg_raw_mode
[regno
+ i
],
2677 register rtx testreg
= SET_DEST (x
);
2680 /* If storing into MEM, don't show it as being used. But do
2681 show the address as being used. */
2682 if (GET_CODE (testreg
) == MEM
)
2686 find_auto_inc (needed
, testreg
, insn
);
2688 mark_used_regs (needed
, live
, XEXP (testreg
, 0), final
, insn
);
2689 mark_used_regs (needed
, live
, SET_SRC (x
), final
, insn
);
2693 /* Storing in STRICT_LOW_PART is like storing in a reg
2694 in that this SET might be dead, so ignore it in TESTREG.
2695 but in some other ways it is like using the reg.
2697 Storing in a SUBREG or a bit field is like storing the entire
2698 register in that if the register's value is not used
2699 then this SET is not needed. */
2700 while (GET_CODE (testreg
) == STRICT_LOW_PART
2701 || GET_CODE (testreg
) == ZERO_EXTRACT
2702 || GET_CODE (testreg
) == SIGN_EXTRACT
2703 || GET_CODE (testreg
) == SUBREG
)
2705 if (GET_CODE (testreg
) == SUBREG
2706 && GET_CODE (SUBREG_REG (testreg
)) == REG
2707 && REGNO (SUBREG_REG (testreg
)) >= FIRST_PSEUDO_REGISTER
2708 && (GET_MODE_SIZE (GET_MODE (testreg
))
2709 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (testreg
)))))
2710 REG_CHANGES_SIZE (REGNO (SUBREG_REG (testreg
))) = 1;
2712 /* Modifying a single register in an alternate mode
2713 does not use any of the old value. But these other
2714 ways of storing in a register do use the old value. */
2715 if (GET_CODE (testreg
) == SUBREG
2716 && !(REG_SIZE (SUBREG_REG (testreg
)) > REG_SIZE (testreg
)))
2721 testreg
= XEXP (testreg
, 0);
2724 /* If this is a store into a register,
2725 recursively scan the value being stored. */
2727 if (GET_CODE (testreg
) == REG
2728 && (regno
= REGNO (testreg
), regno
!= FRAME_POINTER_REGNUM
)
2729 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2730 && regno
!= HARD_FRAME_POINTER_REGNUM
2732 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2733 && ! (regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
2736 /* We used to exclude global_regs here, but that seems wrong.
2737 Storing in them is like storing in mem. */
2739 mark_used_regs (needed
, live
, SET_SRC (x
), final
, insn
);
2741 mark_used_regs (needed
, live
, SET_DEST (x
), final
, insn
);
2748 /* If exiting needs the right stack value, consider this insn as
2749 using the stack pointer. In any event, consider it as using
2750 all global registers and all registers used by return. */
2752 #ifdef EXIT_IGNORE_STACK
2753 if (! EXIT_IGNORE_STACK
2754 || (! FRAME_POINTER_REQUIRED
2755 && ! current_function_calls_alloca
2756 && flag_omit_frame_pointer
))
2758 SET_REGNO_REG_SET (live
, STACK_POINTER_REGNUM
);
2760 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2762 #ifdef EPILOGUE_USES
2763 || EPILOGUE_USES (i
)
2766 SET_REGNO_REG_SET (live
, i
);
2773 /* Recursively scan the operands of this expression. */
2776 register char *fmt
= GET_RTX_FORMAT (code
);
2779 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2783 /* Tail recursive case: save a function call level. */
2789 mark_used_regs (needed
, live
, XEXP (x
, i
), final
, insn
);
2791 else if (fmt
[i
] == 'E')
2794 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2795 mark_used_regs (needed
, live
, XVECEXP (x
, i
, j
), final
, insn
);
2804 try_pre_increment_1 (insn
)
2807 /* Find the next use of this reg. If in same basic block,
2808 make it do pre-increment or pre-decrement if appropriate. */
2809 rtx x
= single_set (insn
);
2810 HOST_WIDE_INT amount
= ((GET_CODE (SET_SRC (x
)) == PLUS
? 1 : -1)
2811 * INTVAL (XEXP (SET_SRC (x
), 1)));
2812 int regno
= REGNO (SET_DEST (x
));
2813 rtx y
= reg_next_use
[regno
];
2815 && BLOCK_NUM (y
) == BLOCK_NUM (insn
)
2816 /* Don't do this if the reg dies, or gets set in y; a standard addressing
2817 mode would be better. */
2818 && ! dead_or_set_p (y
, SET_DEST (x
))
2819 && try_pre_increment (y
, SET_DEST (x
), amount
))
2821 /* We have found a suitable auto-increment
2822 and already changed insn Y to do it.
2823 So flush this increment-instruction. */
2824 PUT_CODE (insn
, NOTE
);
2825 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
2826 NOTE_SOURCE_FILE (insn
) = 0;
2827 /* Count a reference to this reg for the increment
2828 insn we are deleting. When a reg is incremented.
2829 spilling it is worse, so we want to make that
2831 if (regno
>= FIRST_PSEUDO_REGISTER
)
2833 REG_N_REFS (regno
) += loop_depth
;
2834 REG_N_SETS (regno
)++;
2841 /* Try to change INSN so that it does pre-increment or pre-decrement
2842 addressing on register REG in order to add AMOUNT to REG.
2843 AMOUNT is negative for pre-decrement.
2844 Returns 1 if the change could be made.
2845 This checks all about the validity of the result of modifying INSN. */
2848 try_pre_increment (insn
, reg
, amount
)
2850 HOST_WIDE_INT amount
;
2854 /* Nonzero if we can try to make a pre-increment or pre-decrement.
2855 For example, addl $4,r1; movl (r1),... can become movl +(r1),... */
2857 /* Nonzero if we can try to make a post-increment or post-decrement.
2858 For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,...
2859 It is possible for both PRE_OK and POST_OK to be nonzero if the machine
2860 supports both pre-inc and post-inc, or both pre-dec and post-dec. */
2863 /* Nonzero if the opportunity actually requires post-inc or post-dec. */
2866 /* From the sign of increment, see which possibilities are conceivable
2867 on this target machine. */
2868 #ifdef HAVE_PRE_INCREMENT
2872 #ifdef HAVE_POST_INCREMENT
2877 #ifdef HAVE_PRE_DECREMENT
2881 #ifdef HAVE_POST_DECREMENT
2886 if (! (pre_ok
|| post_ok
))
2889 /* It is not safe to add a side effect to a jump insn
2890 because if the incremented register is spilled and must be reloaded
2891 there would be no way to store the incremented value back in memory. */
2893 if (GET_CODE (insn
) == JUMP_INSN
)
2898 use
= find_use_as_address (PATTERN (insn
), reg
, 0);
2899 if (post_ok
&& (use
== 0 || use
== (rtx
) 1))
2901 use
= find_use_as_address (PATTERN (insn
), reg
, -amount
);
2905 if (use
== 0 || use
== (rtx
) 1)
2908 if (GET_MODE_SIZE (GET_MODE (use
)) != (amount
> 0 ? amount
: - amount
))
2911 /* See if this combination of instruction and addressing mode exists. */
2912 if (! validate_change (insn
, &XEXP (use
, 0),
2913 gen_rtx_fmt_e (amount
> 0
2914 ? (do_post
? POST_INC
: PRE_INC
)
2915 : (do_post
? POST_DEC
: PRE_DEC
),
2919 /* Record that this insn now has an implicit side effect on X. */
2920 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_INC
, reg
, REG_NOTES (insn
));
2924 #endif /* AUTO_INC_DEC */
2926 /* Find the place in the rtx X where REG is used as a memory address.
2927 Return the MEM rtx that so uses it.
2928 If PLUSCONST is nonzero, search instead for a memory address equivalent to
2929 (plus REG (const_int PLUSCONST)).
2931 If such an address does not appear, return 0.
2932 If REG appears more than once, or is used other than in such an address,
2936 find_use_as_address (x
, reg
, plusconst
)
2939 HOST_WIDE_INT plusconst
;
2941 enum rtx_code code
= GET_CODE (x
);
2942 char *fmt
= GET_RTX_FORMAT (code
);
2944 register rtx value
= 0;
2947 if (code
== MEM
&& XEXP (x
, 0) == reg
&& plusconst
== 0)
2950 if (code
== MEM
&& GET_CODE (XEXP (x
, 0)) == PLUS
2951 && XEXP (XEXP (x
, 0), 0) == reg
2952 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
2953 && INTVAL (XEXP (XEXP (x
, 0), 1)) == plusconst
)
2956 if (code
== SIGN_EXTRACT
|| code
== ZERO_EXTRACT
)
2958 /* If REG occurs inside a MEM used in a bit-field reference,
2959 that is unacceptable. */
2960 if (find_use_as_address (XEXP (x
, 0), reg
, 0) != 0)
2961 return (rtx
) (HOST_WIDE_INT
) 1;
2965 return (rtx
) (HOST_WIDE_INT
) 1;
2967 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2971 tem
= find_use_as_address (XEXP (x
, i
), reg
, plusconst
);
2975 return (rtx
) (HOST_WIDE_INT
) 1;
2980 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2982 tem
= find_use_as_address (XVECEXP (x
, i
, j
), reg
, plusconst
);
2986 return (rtx
) (HOST_WIDE_INT
) 1;
2994 /* Write information about registers and basic blocks into FILE.
2995 This is part of making a debugging dump. */
2998 dump_flow_info (file
)
3002 static char *reg_class_names
[] = REG_CLASS_NAMES
;
3004 fprintf (file
, "%d registers.\n", max_regno
);
3006 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
3009 enum reg_class
class, altclass
;
3010 fprintf (file
, "\nRegister %d used %d times across %d insns",
3011 i
, REG_N_REFS (i
), REG_LIVE_LENGTH (i
));
3012 if (REG_BASIC_BLOCK (i
) >= 0)
3013 fprintf (file
, " in block %d", REG_BASIC_BLOCK (i
));
3014 if (REG_N_DEATHS (i
) != 1)
3015 fprintf (file
, "; dies in %d places", REG_N_DEATHS (i
));
3016 if (REG_N_CALLS_CROSSED (i
) == 1)
3017 fprintf (file
, "; crosses 1 call");
3018 else if (REG_N_CALLS_CROSSED (i
))
3019 fprintf (file
, "; crosses %d calls", REG_N_CALLS_CROSSED (i
));
3020 if (PSEUDO_REGNO_BYTES (i
) != UNITS_PER_WORD
)
3021 fprintf (file
, "; %d bytes", PSEUDO_REGNO_BYTES (i
));
3022 class = reg_preferred_class (i
);
3023 altclass
= reg_alternate_class (i
);
3024 if (class != GENERAL_REGS
|| altclass
!= ALL_REGS
)
3026 if (altclass
== ALL_REGS
|| class == ALL_REGS
)
3027 fprintf (file
, "; pref %s", reg_class_names
[(int) class]);
3028 else if (altclass
== NO_REGS
)
3029 fprintf (file
, "; %s or none", reg_class_names
[(int) class]);
3031 fprintf (file
, "; pref %s, else %s",
3032 reg_class_names
[(int) class],
3033 reg_class_names
[(int) altclass
]);
3035 if (REGNO_POINTER_FLAG (i
))
3036 fprintf (file
, "; pointer");
3037 fprintf (file
, ".\n");
3039 fprintf (file
, "\n%d basic blocks.\n", n_basic_blocks
);
3040 for (i
= 0; i
< n_basic_blocks
; i
++)
3042 register rtx head
, jump
;
3044 fprintf (file
, "\nBasic block %d: first insn %d, last %d.\n",
3046 INSN_UID (basic_block_head
[i
]),
3047 INSN_UID (basic_block_end
[i
]));
3048 /* The control flow graph's storage is freed
3049 now when flow_analysis returns.
3050 Don't try to print it if it is gone. */
3051 if (basic_block_drops_in
)
3053 fprintf (file
, "Reached from blocks: ");
3054 head
= basic_block_head
[i
];
3055 if (GET_CODE (head
) == CODE_LABEL
)
3056 for (jump
= LABEL_REFS (head
);
3058 jump
= LABEL_NEXTREF (jump
))
3060 register int from_block
= BLOCK_NUM (CONTAINING_INSN (jump
));
3061 fprintf (file
, " %d", from_block
);
3063 if (basic_block_drops_in
[i
])
3064 fprintf (file
, " previous");
3066 fprintf (file
, "\nRegisters live at start:");
3067 for (regno
= 0; regno
< max_regno
; regno
++)
3068 if (REGNO_REG_SET_P (basic_block_live_at_start
[i
], regno
))
3069 fprintf (file
, " %d", regno
);
3070 fprintf (file
, "\n");
3072 fprintf (file
, "\n");
3076 /* Like print_rtl, but also print out live information for the start of each
3080 print_rtl_with_bb (outf
, rtx_first
)
3084 register rtx tmp_rtx
;
3087 fprintf (outf
, "(nil)\n");
3092 enum bb_state
{ NOT_IN_BB
, IN_ONE_BB
, IN_MULTIPLE_BB
};
3093 int max_uid
= get_max_uid ();
3094 int *start
= (int *) alloca (max_uid
* sizeof (int));
3095 int *end
= (int *) alloca (max_uid
* sizeof (int));
3096 char *in_bb_p
= (char *) alloca (max_uid
* sizeof (enum bb_state
));
3098 for (i
= 0; i
< max_uid
; i
++)
3100 start
[i
] = end
[i
] = -1;
3101 in_bb_p
[i
] = NOT_IN_BB
;
3104 for (i
= n_basic_blocks
-1; i
>= 0; i
--)
3107 start
[INSN_UID (basic_block_head
[i
])] = i
;
3108 end
[INSN_UID (basic_block_end
[i
])] = i
;
3109 for (x
= basic_block_head
[i
]; x
!= NULL_RTX
; x
= NEXT_INSN (x
))
3111 in_bb_p
[ INSN_UID(x
)]
3112 = (in_bb_p
[ INSN_UID(x
)] == NOT_IN_BB
)
3113 ? IN_ONE_BB
: IN_MULTIPLE_BB
;
3114 if (x
== basic_block_end
[i
])
3119 for (tmp_rtx
= rtx_first
; NULL
!= tmp_rtx
; tmp_rtx
= NEXT_INSN (tmp_rtx
))
3121 if ((bb
= start
[INSN_UID (tmp_rtx
)]) >= 0)
3123 fprintf (outf
, ";; Start of basic block %d, registers live:",
3126 EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start
[bb
], 0, i
,
3128 fprintf (outf
, " %d", i
);
3129 if (i
< FIRST_PSEUDO_REGISTER
)
3130 fprintf (outf
, " [%s]",
3136 if (in_bb_p
[ INSN_UID(tmp_rtx
)] == NOT_IN_BB
3137 && GET_CODE (tmp_rtx
) != NOTE
3138 && GET_CODE (tmp_rtx
) != BARRIER
)
3139 fprintf (outf
, ";; Insn is not within a basic block\n");
3140 else if (in_bb_p
[ INSN_UID(tmp_rtx
)] == IN_MULTIPLE_BB
)
3141 fprintf (outf
, ";; Insn is in multiple basic blocks\n");
3143 print_rtl_single (outf
, tmp_rtx
);
3145 if ((bb
= end
[INSN_UID (tmp_rtx
)]) >= 0)
3146 fprintf (outf
, ";; End of basic block %d\n", bb
);
3154 /* Integer list support. */
3156 /* Allocate a node from list *HEAD_PTR. */
3159 alloc_int_list_node (head_ptr
)
3160 int_list_block
**head_ptr
;
3162 struct int_list_block
*first_blk
= *head_ptr
;
3164 if (first_blk
== NULL
|| first_blk
->nodes_left
<= 0)
3166 first_blk
= (struct int_list_block
*) xmalloc (sizeof (struct int_list_block
));
3167 first_blk
->nodes_left
= INT_LIST_NODES_IN_BLK
;
3168 first_blk
->next
= *head_ptr
;
3169 *head_ptr
= first_blk
;
3172 first_blk
->nodes_left
--;
3173 return &first_blk
->nodes
[first_blk
->nodes_left
];
3176 /* Pointer to head of predecessor/successor block list. */
3177 static int_list_block
*pred_int_list_blocks
;
3179 /* Add a new node to integer list LIST with value VAL.
3180 LIST is a pointer to a list object to allow for different implementations.
3181 If *LIST is initially NULL, the list is empty.
3182 The caller must not care whether the element is added to the front or
3183 to the end of the list (to allow for different implementations). */
3186 add_int_list_node (blk_list
, list
, val
)
3187 int_list_block
**blk_list
;
3191 int_list_ptr p
= alloc_int_list_node (blk_list
);
3199 /* Free the blocks of lists at BLK_LIST. */
3202 free_int_list (blk_list
)
3203 int_list_block
**blk_list
;
3205 int_list_block
*p
, *next
;
3207 for (p
= *blk_list
; p
!= NULL
; p
= next
)
3213 /* Mark list as empty for the next function we compile. */
3217 /* Predecessor/successor computation. */
3219 /* Mark PRED_BB a precessor of SUCC_BB,
3220 and conversely SUCC_BB a successor of PRED_BB. */
3223 add_pred_succ (pred_bb
, succ_bb
, s_preds
, s_succs
, num_preds
, num_succs
)
3226 int_list_ptr
*s_preds
;
3227 int_list_ptr
*s_succs
;
3231 if (succ_bb
!= EXIT_BLOCK
)
3233 add_int_list_node (&pred_int_list_blocks
, &s_preds
[succ_bb
], pred_bb
);
3234 num_preds
[succ_bb
]++;
3236 if (pred_bb
!= ENTRY_BLOCK
)
3238 add_int_list_node (&pred_int_list_blocks
, &s_succs
[pred_bb
], succ_bb
);
3239 num_succs
[pred_bb
]++;
3243 /* Compute the predecessors and successors for each block. */
3245 compute_preds_succs (s_preds
, s_succs
, num_preds
, num_succs
)
3246 int_list_ptr
*s_preds
;
3247 int_list_ptr
*s_succs
;
3251 int bb
, clear_local_bb_vars
= 0;
3253 bzero ((char *) s_preds
, n_basic_blocks
* sizeof (int_list_ptr
));
3254 bzero ((char *) s_succs
, n_basic_blocks
* sizeof (int_list_ptr
));
3255 bzero ((char *) num_preds
, n_basic_blocks
* sizeof (int));
3256 bzero ((char *) num_succs
, n_basic_blocks
* sizeof (int));
3258 /* This routine can be called after life analysis; in that case
3259 basic_block_drops_in and uid_block_number will not be available
3260 and we must recompute their values. */
3261 if (basic_block_drops_in
== NULL
|| uid_block_number
== NULL
)
3263 clear_local_bb_vars
= 1;
3264 basic_block_drops_in
= (char *) alloca (n_basic_blocks
);
3265 uid_block_number
= (int *) alloca ((get_max_uid () + 1) * sizeof (int));
3267 bzero ((char *) basic_block_drops_in
, n_basic_blocks
* sizeof (char));
3268 bzero ((char *) uid_block_number
, n_basic_blocks
* sizeof (int));
3270 /* Scan each basic block setting basic_block_drops_in and
3271 uid_block_number as needed. */
3272 for (bb
= 0; bb
< n_basic_blocks
; bb
++)
3274 rtx insn
, stop_insn
;
3277 stop_insn
= NULL_RTX
;
3279 stop_insn
= basic_block_end
[bb
-1];
3281 /* Look backwards from the start of this block. Stop if we
3282 hit the start of the function or the end of a previous
3283 block. Don't walk backwards through blocks that are just
3285 for (insn
= PREV_INSN (basic_block_head
[bb
]);
3286 insn
&& insn
!= stop_insn
&& GET_CODE (insn
) == NOTE
;
3287 insn
= PREV_INSN (insn
))
3290 /* Never set basic_block_drops_in for the first block. It is
3293 If we stopped on anything other than a BARRIER, then this
3296 basic_block_drops_in
[bb
] = (insn
? GET_CODE (insn
) != BARRIER
: 1);
3298 insn
= basic_block_head
[bb
];
3301 BLOCK_NUM (insn
) = bb
;
3302 if (insn
== basic_block_end
[bb
])
3304 insn
= NEXT_INSN (insn
);
3309 for (bb
= 0; bb
< n_basic_blocks
; bb
++)
3314 head
= BLOCK_HEAD (bb
);
3316 if (GET_CODE (head
) == CODE_LABEL
)
3317 for (jump
= LABEL_REFS (head
);
3319 jump
= LABEL_NEXTREF (jump
))
3321 if (! INSN_DELETED_P (CONTAINING_INSN (jump
))
3322 && (GET_CODE (CONTAINING_INSN (jump
)) != NOTE
3323 || (NOTE_LINE_NUMBER (CONTAINING_INSN (jump
))
3324 != NOTE_INSN_DELETED
)))
3325 add_pred_succ (BLOCK_NUM (CONTAINING_INSN (jump
)), bb
,
3326 s_preds
, s_succs
, num_preds
, num_succs
);
3329 jump
= BLOCK_END (bb
);
3330 /* If this is a RETURN insn or a conditional jump in the last
3331 basic block, or a non-jump insn in the last basic block, then
3332 this block reaches the exit block. */
3333 if ((GET_CODE (jump
) == JUMP_INSN
&& GET_CODE (PATTERN (jump
)) == RETURN
)
3334 || (((GET_CODE (jump
) == JUMP_INSN
3335 && condjump_p (jump
) && !simplejump_p (jump
))
3336 || GET_CODE (jump
) != JUMP_INSN
)
3337 && (bb
== n_basic_blocks
- 1)))
3338 add_pred_succ (bb
, EXIT_BLOCK
, s_preds
, s_succs
, num_preds
, num_succs
);
3340 if (basic_block_drops_in
[bb
])
3341 add_pred_succ (bb
- 1, bb
, s_preds
, s_succs
, num_preds
, num_succs
);
3344 add_pred_succ (ENTRY_BLOCK
, 0, s_preds
, s_succs
, num_preds
, num_succs
);
3347 /* If we allocated any variables in temporary storage, clear out the
3348 pointer to the local storage to avoid dangling pointers. */
3349 if (clear_local_bb_vars
)
3351 basic_block_drops_in
= NULL
;
3352 uid_block_number
= NULL
;
3358 dump_bb_data (file
, preds
, succs
)
3360 int_list_ptr
*preds
;
3361 int_list_ptr
*succs
;
3366 fprintf (file
, "BB data\n\n");
3367 for (bb
= 0; bb
< n_basic_blocks
; bb
++)
3369 fprintf (file
, "BB %d, start %d, end %d\n", bb
,
3370 INSN_UID (BLOCK_HEAD (bb
)), INSN_UID (BLOCK_END (bb
)));
3371 fprintf (file
, " preds:");
3372 for (p
= preds
[bb
]; p
!= NULL
; p
= p
->next
)
3374 int pred_bb
= INT_LIST_VAL (p
);
3375 if (pred_bb
== ENTRY_BLOCK
)
3376 fprintf (file
, " entry");
3378 fprintf (file
, " %d", pred_bb
);
3380 fprintf (file
, "\n");
3381 fprintf (file
, " succs:");
3382 for (p
= succs
[bb
]; p
!= NULL
; p
= p
->next
)
3384 int succ_bb
= INT_LIST_VAL (p
);
3385 if (succ_bb
== EXIT_BLOCK
)
3386 fprintf (file
, " exit");
3388 fprintf (file
, " %d", succ_bb
);
3390 fprintf (file
, "\n");
3392 fprintf (file
, "\n");
3395 /* Free basic block data storage. */
3400 free_int_list (&pred_int_list_blocks
);
3403 /* Bitmap manipulation routines. */
3405 /* Allocate a simple bitmap of N_ELMS bits. */
3408 sbitmap_alloc (n_elms
)
3411 int bytes
, size
, amt
;
3414 size
= SBITMAP_SET_SIZE (n_elms
);
3415 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
3416 amt
= (sizeof (struct simple_bitmap_def
)
3417 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
3418 bmap
= (sbitmap
) xmalloc (amt
);
3419 bmap
->n_bits
= n_elms
;
3421 bmap
->bytes
= bytes
;
3425 /* Allocate a vector of N_VECS bitmaps of N_ELMS bits. */
3428 sbitmap_vector_alloc (n_vecs
, n_elms
)
3431 int i
, bytes
, offset
, elm_bytes
, size
, amt
;
3432 sbitmap
*bitmap_vector
;
3434 size
= SBITMAP_SET_SIZE (n_elms
);
3435 bytes
= size
* sizeof (SBITMAP_ELT_TYPE
);
3436 elm_bytes
= (sizeof (struct simple_bitmap_def
)
3437 + bytes
- sizeof (SBITMAP_ELT_TYPE
));
3438 amt
= (n_vecs
* sizeof (sbitmap
*)) + (n_vecs
* elm_bytes
);
3439 bitmap_vector
= (sbitmap
*) xmalloc (amt
);
3441 /* ??? There may be alignment problems, `offset' should be rounded up
3442 each time to account for alignment. Later [if ever]. */
3444 for (i
= 0, offset
= n_vecs
* sizeof (sbitmap
*);
3446 i
++, offset
+= elm_bytes
)
3448 sbitmap b
= (sbitmap
) ((char *) bitmap_vector
+ offset
);
3449 bitmap_vector
[i
] = b
;
3455 return bitmap_vector
;
3458 /* Copy sbitmap SRC to DST. */
3461 sbitmap_copy (dst
, src
)
3469 for (i
= 0; i
< dst
->size
; i
++)
3473 /* Zero all elements in a bitmap. */
3479 bzero ((char *) bmap
->elms
, bmap
->bytes
);
3482 /* Set to ones all elements in a bitmap. */
3488 memset (bmap
->elms
, -1, bmap
->bytes
);
3491 /* Zero a vector of N_VECS bitmaps. */
3494 sbitmap_vector_zero (bmap
, n_vecs
)
3500 for (i
= 0; i
< n_vecs
; i
++)
3501 sbitmap_zero (bmap
[i
]);
3504 /* Set to ones a vector of N_VECS bitmaps. */
3507 sbitmap_vector_ones (bmap
, n_vecs
)
3513 for (i
= 0; i
< n_vecs
; i
++)
3514 sbitmap_ones (bmap
[i
]);
3517 /* Set DST to be A union (B - C).
3519 Return non-zero if any change is made. */
3522 sbitmap_union_of_diff (dst
, a
, b
, c
)
3523 sbitmap dst
, a
, b
, c
;
3526 sbitmap_ptr dstp
, ap
, bp
, cp
;
3533 for (i
= 0; i
< dst
->size
; i
++)
3535 SBITMAP_ELT_TYPE tmp
= *ap
| (*bp
& ~*cp
);
3539 dstp
++; ap
++; bp
++; cp
++;
3544 /* Set bitmap DST to the bitwise negation of the bitmap SRC. */
3547 sbitmap_not (dst
, src
)
3551 sbitmap_ptr dstp
, ap
;
3555 for (i
= 0; i
< dst
->size
; i
++)
3557 SBITMAP_ELT_TYPE tmp
= ~(*ap
);
3563 /* Set the bits in DST to be the difference between the bits
3564 in A and the bits in B. i.e. dst = a - b.
3565 The - operator is implemented as a & (~b). */
3568 sbitmap_difference (dst
, a
, b
)
3572 sbitmap_ptr dstp
, ap
, bp
;
3577 for (i
= 0; i
< dst
->size
; i
++)
3578 *dstp
++ = *ap
++ & (~*bp
++);
3581 /* Set DST to be (A and B)).
3582 Return non-zero if any change is made. */
3585 sbitmap_a_and_b (dst
, a
, b
)
3589 sbitmap_ptr dstp
, ap
, bp
;
3595 for (i
= 0; i
< dst
->size
; i
++)
3597 SBITMAP_ELT_TYPE tmp
= *ap
& *bp
;
3605 /* Set DST to be (A or B)).
3606 Return non-zero if any change is made. */
3609 sbitmap_a_or_b (dst
, a
, b
)
3613 sbitmap_ptr dstp
, ap
, bp
;
3619 for (i
= 0; i
< dst
->size
; i
++)
3621 SBITMAP_ELT_TYPE tmp
= *ap
| *bp
;
3630 /* Set DST to be (A or (B and C)).
3631 Return non-zero if any change is made. */
3634 sbitmap_a_or_b_and_c (dst
, a
, b
, c
)
3635 sbitmap dst
, a
, b
, c
;
3638 sbitmap_ptr dstp
, ap
, bp
, cp
;
3645 for (i
= 0; i
< dst
->size
; i
++)
3647 SBITMAP_ELT_TYPE tmp
= *ap
| (*bp
& *cp
);
3651 dstp
++; ap
++; bp
++; cp
++;
3656 /* Set DST to be (A ann (B or C)).
3657 Return non-zero if any change is made. */
3660 sbitmap_a_and_b_or_c (dst
, a
, b
, c
)
3661 sbitmap dst
, a
, b
, c
;
3664 sbitmap_ptr dstp
, ap
, bp
, cp
;
3671 for (i
= 0; i
< dst
->size
; i
++)
3673 SBITMAP_ELT_TYPE tmp
= *ap
& (*bp
| *cp
);
3677 dstp
++; ap
++; bp
++; cp
++;
3682 /* Set the bitmap DST to the intersection of SRC of all predecessors or
3683 successors of block number BB (PRED_SUCC says which). */
3686 sbitmap_intersect_of_predsucc (dst
, src
, bb
, pred_succ
)
3690 int_list_ptr
*pred_succ
;
3694 int set_size
= dst
->size
;
3698 /* It is possible that there are no predecessors(/successors).
3699 This can happen for example in unreachable code. */
3703 /* In APL-speak this is the `and' reduction of the empty set and thus
3704 the result is the identity for `and'. */
3709 /* Set result to first predecessor/successor. */
3711 for ( ; ps
!= NULL
; ps
= ps
->next
)
3713 ps_bb
= INT_LIST_VAL (ps
);
3714 if (ps_bb
== ENTRY_BLOCK
|| ps_bb
== EXIT_BLOCK
)
3716 sbitmap_copy (dst
, src
[ps_bb
]);
3717 /* Break out since we're only doing first predecessor. */
3723 /* Now do the remaining predecessors/successors. */
3725 for (ps
= ps
->next
; ps
!= NULL
; ps
= ps
->next
)
3730 ps_bb
= INT_LIST_VAL (ps
);
3731 if (ps_bb
== ENTRY_BLOCK
|| ps_bb
== EXIT_BLOCK
)
3734 p
= src
[ps_bb
]->elms
;
3737 for (i
= 0; i
< set_size
; i
++)
3742 /* Set the bitmap DST to the intersection of SRC of all predecessors
3743 of block number BB. */
3746 sbitmap_intersect_of_predecessors (dst
, src
, bb
, s_preds
)
3750 int_list_ptr
*s_preds
;
3752 sbitmap_intersect_of_predsucc (dst
, src
, bb
, s_preds
);
3755 /* Set the bitmap DST to the intersection of SRC of all successors
3756 of block number BB. */
3759 sbitmap_intersect_of_successors (dst
, src
, bb
, s_succs
)
3763 int_list_ptr
*s_succs
;
3765 sbitmap_intersect_of_predsucc (dst
, src
, bb
, s_succs
);
3768 /* Set the bitmap DST to the union of SRC of all predecessors/successors of
3772 sbitmap_union_of_predsucc (dst
, src
, bb
, pred_succ
)
3776 int_list_ptr
*pred_succ
;
3780 int set_size
= dst
->size
;
3784 /* It is possible that there are no predecessors(/successors).
3785 This can happen for example in unreachable code. */
3789 /* In APL-speak this is the `or' reduction of the empty set and thus
3790 the result is the identity for `or'. */
3795 /* Set result to first predecessor/successor. */
3797 for ( ; ps
!= NULL
; ps
= ps
->next
)
3799 ps_bb
= INT_LIST_VAL (ps
);
3800 if (ps_bb
== ENTRY_BLOCK
|| ps_bb
== EXIT_BLOCK
)
3802 sbitmap_copy (dst
, src
[ps_bb
]);
3803 /* Break out since we're only doing first predecessor. */
3809 /* Now do the remaining predecessors/successors. */
3811 for (ps
= ps
->next
; ps
!= NULL
; ps
= ps
->next
)
3816 ps_bb
= INT_LIST_VAL (ps
);
3817 if (ps_bb
== ENTRY_BLOCK
|| ps_bb
== EXIT_BLOCK
)
3820 p
= src
[ps_bb
]->elms
;
3823 for (i
= 0; i
< set_size
; i
++)
3828 /* Set the bitmap DST to the union of SRC of all predecessors of
3832 sbitmap_union_of_predecessors (dst
, src
, bb
, s_preds
)
3836 int_list_ptr
*s_preds
;
3838 sbitmap_union_of_predsucc (dst
, src
, bb
, s_preds
);
3841 /* Compute dominator relationships. */
3843 compute_dominators (dominators
, post_dominators
, s_preds
, s_succs
)
3844 sbitmap
*dominators
;
3845 sbitmap
*post_dominators
;
3846 int_list_ptr
*s_preds
;
3847 int_list_ptr
*s_succs
;
3849 int bb
, changed
, passes
;
3850 sbitmap
*temp_bitmap
;
3852 temp_bitmap
= sbitmap_vector_alloc (n_basic_blocks
, n_basic_blocks
);
3853 sbitmap_vector_ones (dominators
, n_basic_blocks
);
3854 sbitmap_vector_ones (post_dominators
, n_basic_blocks
);
3855 sbitmap_vector_zero (temp_bitmap
, n_basic_blocks
);
3857 sbitmap_zero (dominators
[0]);
3858 SET_BIT (dominators
[0], 0);
3860 sbitmap_zero (post_dominators
[n_basic_blocks
-1]);
3861 SET_BIT (post_dominators
[n_basic_blocks
-1], 0);
3868 for (bb
= 1; bb
< n_basic_blocks
; bb
++)
3870 sbitmap_intersect_of_predecessors (temp_bitmap
[bb
], dominators
,
3872 SET_BIT (temp_bitmap
[bb
], bb
);
3873 changed
|= sbitmap_a_and_b (dominators
[bb
],
3876 sbitmap_intersect_of_successors (temp_bitmap
[bb
], post_dominators
,
3878 SET_BIT (temp_bitmap
[bb
], bb
);
3879 changed
|= sbitmap_a_and_b (post_dominators
[bb
],
3880 post_dominators
[bb
],