Call fatal_insn_not_found instead of abort
[official-gcc.git] / gcc / flow.c
blobeb6c2a0079ad084959132ecc8f2632db7bf0a920
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)
9 any later version.
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
43 and deletes them.
45 ** life_analysis **
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
59 of the basic block.
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
77 REG_DEAD notes.
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
96 that is never used.
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. */
111 #include "config.h"
112 #include "system.h"
113 #include "rtl.h"
114 #include "basic-block.h"
115 #include "insn-config.h"
116 #include "regs.h"
117 #include "hard-reg-set.h"
118 #include "flags.h"
119 #include "output.h"
120 #include "except.h"
121 #include "toplev.h"
123 #include "obstack.h"
124 #define obstack_chunk_alloc xmalloc
125 #define obstack_chunk_free free
127 /* The contents of the current function definition are allocated
128 in this obstack, and all are freed at the end of the function.
129 For top-level functions, this is temporary_obstack.
130 Separate obstacks are made for nested functions. */
132 extern struct obstack *function_obstack;
134 /* List of labels that must never be deleted. */
135 extern rtx forced_labels;
137 /* Get the basic block number of an insn.
138 This info should not be expected to remain available
139 after the end of life_analysis. */
141 /* This is the limit of the allocated space in the following two arrays. */
143 static int max_uid_for_flow;
145 #define BLOCK_NUM(INSN) uid_block_number[INSN_UID (INSN)]
147 /* This is where the BLOCK_NUM values are really stored.
148 This is set up by find_basic_blocks and used there and in life_analysis,
149 and then freed. */
151 int *uid_block_number;
153 /* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile. */
155 #define INSN_VOLATILE(INSN) uid_volatile[INSN_UID (INSN)]
156 static char *uid_volatile;
158 /* Number of basic blocks in the current function. */
160 int n_basic_blocks;
162 /* Maximum register number used in this function, plus one. */
164 int max_regno;
166 /* Maximum number of SCRATCH rtx's used in any basic block of this
167 function. */
169 int max_scratch;
171 /* Number of SCRATCH rtx's in the current block. */
173 static int num_scratch;
175 /* Indexed by n, giving various register information */
177 reg_info *reg_n_info;
179 /* Size of the reg_n_info table. */
181 unsigned int reg_n_max;
183 /* Element N is the next insn that uses (hard or pseudo) register number N
184 within the current basic block; or zero, if there is no such insn.
185 This is valid only during the final backward scan in propagate_block. */
187 static rtx *reg_next_use;
189 /* Size of a regset for the current function,
190 in (1) bytes and (2) elements. */
192 int regset_bytes;
193 int regset_size;
195 /* Element N is first insn in basic block N.
196 This info lasts until we finish compiling the function. */
198 rtx *basic_block_head;
200 /* Element N is last insn in basic block N.
201 This info lasts until we finish compiling the function. */
203 rtx *basic_block_end;
205 /* Element N indicates whether basic block N can be reached through a
206 computed jump. */
208 char *basic_block_computed_jump_target;
210 /* Element N is a regset describing the registers live
211 at the start of basic block N.
212 This info lasts until we finish compiling the function. */
214 regset *basic_block_live_at_start;
216 /* Regset of regs live when calls to `setjmp'-like functions happen. */
218 regset regs_live_at_setjmp;
220 /* List made of EXPR_LIST rtx's which gives pairs of pseudo registers
221 that have to go in the same hard reg.
222 The first two regs in the list are a pair, and the next two
223 are another pair, etc. */
224 rtx regs_may_share;
226 /* Element N is nonzero if control can drop into basic block N
227 from the preceding basic block. Freed after life_analysis. */
229 static char *basic_block_drops_in;
231 /* Element N is depth within loops of the last insn in basic block number N.
232 Freed after life_analysis. */
234 static short *basic_block_loop_depth;
236 /* Element N nonzero if basic block N can actually be reached.
237 Vector exists only during find_basic_blocks. */
239 static char *block_live_static;
241 /* Depth within loops of basic block being scanned for lifetime analysis,
242 plus one. This is the weight attached to references to registers. */
244 static int loop_depth;
246 /* During propagate_block, this is non-zero if the value of CC0 is live. */
248 static int cc0_live;
250 /* During propagate_block, this contains the last MEM stored into. It
251 is used to eliminate consecutive stores to the same location. */
253 static rtx last_mem_set;
255 /* Set of registers that may be eliminable. These are handled specially
256 in updating regs_ever_live. */
258 static HARD_REG_SET elim_reg_set;
260 /* Forward declarations */
261 static void find_basic_blocks_1 PROTO((rtx, rtx, int));
262 static void mark_label_ref PROTO((rtx, rtx, int));
263 static void life_analysis_1 PROTO((rtx, int));
264 static void propagate_block PROTO((regset, rtx, rtx, int,
265 regset, int));
266 static rtx flow_delete_insn PROTO((rtx));
267 static int insn_dead_p PROTO((rtx, regset, int));
268 static int libcall_dead_p PROTO((rtx, regset, rtx, rtx));
269 static void mark_set_regs PROTO((regset, regset, rtx,
270 rtx, regset));
271 static void mark_set_1 PROTO((regset, regset, rtx,
272 rtx, regset));
273 #ifdef AUTO_INC_DEC
274 static void find_auto_inc PROTO((regset, rtx, rtx));
275 static int try_pre_increment_1 PROTO((rtx));
276 static int try_pre_increment PROTO((rtx, rtx, HOST_WIDE_INT));
277 #endif
278 static void mark_used_regs PROTO((regset, regset, rtx, int, rtx));
279 void dump_flow_info PROTO((FILE *));
280 static void add_pred_succ PROTO ((int, int, int_list_ptr *,
281 int_list_ptr *, int *, int *));
282 static int_list_ptr alloc_int_list_node PROTO ((int_list_block **));
283 static int_list_ptr add_int_list_node PROTO ((int_list_block **,
284 int_list **, int));
285 static void init_regset_vector PROTO ((regset *, int,
286 struct obstack *));
287 static void count_reg_sets_1 PROTO ((rtx));
288 static void count_reg_sets PROTO ((rtx));
289 static void count_reg_references PROTO ((rtx));
291 /* Find basic blocks of the current function.
292 F is the first insn of the function and NREGS the number of register numbers
293 in use.
294 LIVE_REACHABLE_P is non-zero if the caller needs all live blocks to
295 be reachable. This turns on a kludge that causes the control flow
296 information to be inaccurate and not suitable for passes like GCSE. */
298 void
299 find_basic_blocks (f, nregs, file, live_reachable_p)
300 rtx f;
301 int nregs;
302 FILE *file;
303 int live_reachable_p;
305 register rtx insn;
306 register int i;
307 rtx nonlocal_label_list = nonlocal_label_rtx_list ();
308 int in_libcall_block = 0;
310 /* Count the basic blocks. Also find maximum insn uid value used. */
313 register RTX_CODE prev_code = JUMP_INSN;
314 register RTX_CODE code;
315 int eh_region = 0;
317 max_uid_for_flow = 0;
319 for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
322 /* Track when we are inside in LIBCALL block. */
323 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
324 && find_reg_note (insn, REG_LIBCALL, NULL_RTX))
325 in_libcall_block = 1;
327 code = GET_CODE (insn);
328 if (INSN_UID (insn) > max_uid_for_flow)
329 max_uid_for_flow = INSN_UID (insn);
330 if (code == CODE_LABEL
331 || (GET_RTX_CLASS (code) == 'i'
332 && (prev_code == JUMP_INSN
333 || (prev_code == CALL_INSN
334 && (nonlocal_label_list != 0 || eh_region)
335 && ! in_libcall_block)
336 || prev_code == BARRIER)))
337 i++;
339 if (code == CALL_INSN && find_reg_note (insn, REG_RETVAL, NULL_RTX))
340 code = INSN;
342 if (code != NOTE)
343 prev_code = code;
344 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
345 ++eh_region;
346 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
347 --eh_region;
349 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
350 && find_reg_note (insn, REG_RETVAL, NULL_RTX))
351 in_libcall_block = 0;
355 n_basic_blocks = i;
357 #ifdef AUTO_INC_DEC
358 /* Leave space for insns life_analysis makes in some cases for auto-inc.
359 These cases are rare, so we don't need too much space. */
360 max_uid_for_flow += max_uid_for_flow / 10;
361 #endif
363 /* Allocate some tables that last till end of compiling this function
364 and some needed only in find_basic_blocks and life_analysis. */
366 basic_block_head = (rtx *) xmalloc (n_basic_blocks * sizeof (rtx));
367 basic_block_end = (rtx *) xmalloc (n_basic_blocks * sizeof (rtx));
368 basic_block_drops_in = (char *) xmalloc (n_basic_blocks);
369 basic_block_computed_jump_target = (char *) oballoc (n_basic_blocks);
370 basic_block_loop_depth = (short *) xmalloc (n_basic_blocks * sizeof (short));
371 uid_block_number
372 = (int *) xmalloc ((max_uid_for_flow + 1) * sizeof (int));
373 uid_volatile = (char *) xmalloc (max_uid_for_flow + 1);
374 bzero (uid_volatile, max_uid_for_flow + 1);
376 find_basic_blocks_1 (f, nonlocal_label_list, live_reachable_p);
379 /* Find all basic blocks of the function whose first insn is F.
380 Store the correct data in the tables that describe the basic blocks,
381 set up the chains of references for each CODE_LABEL, and
382 delete any entire basic blocks that cannot be reached.
384 NONLOCAL_LABEL_LIST is a list of non-local labels in the function.
385 Blocks that are otherwise unreachable may be reachable with a non-local
386 goto.
387 LIVE_REACHABLE_P is non-zero if the caller needs all live blocks to
388 be reachable. This turns on a kludge that causes the control flow
389 information to be inaccurate and not suitable for passes like GCSE. */
391 static void
392 find_basic_blocks_1 (f, nonlocal_label_list, live_reachable_p)
393 rtx f, nonlocal_label_list;
394 int live_reachable_p;
396 register rtx insn;
397 register int i;
398 register char *block_live = (char *) alloca (n_basic_blocks);
399 register char *block_marked = (char *) alloca (n_basic_blocks);
400 /* An array of CODE_LABELs, indexed by UID for the start of the active
401 EH handler for each insn in F. */
402 int *active_eh_region;
403 int *nested_eh_region;
404 /* List of label_refs to all labels whose addresses are taken
405 and used as data. */
406 rtx label_value_list;
407 rtx x, note, eh_note;
408 enum rtx_code prev_code, code;
409 int depth, pass;
410 int in_libcall_block = 0;
411 int deleted_handler = 0;
413 pass = 1;
414 active_eh_region = (int *) alloca ((max_uid_for_flow + 1) * sizeof (int));
415 nested_eh_region = (int *) alloca ((max_label_num () + 1) * sizeof (int));
416 restart:
418 label_value_list = 0;
419 block_live_static = block_live;
420 bzero (block_live, n_basic_blocks);
421 bzero (block_marked, n_basic_blocks);
422 bzero (basic_block_computed_jump_target, n_basic_blocks);
423 bzero ((char *) active_eh_region, (max_uid_for_flow + 1) * sizeof (int));
424 bzero ((char *) nested_eh_region, (max_label_num () + 1) * sizeof (int));
425 current_function_has_computed_jump = 0;
427 /* Initialize with just block 0 reachable and no blocks marked. */
428 if (n_basic_blocks > 0)
429 block_live[0] = 1;
431 /* Initialize the ref chain of each label to 0. Record where all the
432 blocks start and end and their depth in loops. For each insn, record
433 the block it is in. Also mark as reachable any blocks headed by labels
434 that must not be deleted. */
436 for (eh_note = NULL_RTX, insn = f, i = -1, prev_code = JUMP_INSN, depth = 1;
437 insn; insn = NEXT_INSN (insn))
440 /* Track when we are inside in LIBCALL block. */
441 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
442 && find_reg_note (insn, REG_LIBCALL, NULL_RTX))
443 in_libcall_block = 1;
445 code = GET_CODE (insn);
446 if (code == NOTE)
448 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
449 depth++;
450 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
451 depth--;
454 /* A basic block starts at label, or after something that can jump. */
455 else if (code == CODE_LABEL
456 || (GET_RTX_CLASS (code) == 'i'
457 && (prev_code == JUMP_INSN
458 || (prev_code == CALL_INSN
459 && (nonlocal_label_list != 0 || eh_note)
460 && ! in_libcall_block)
461 || prev_code == BARRIER)))
463 basic_block_head[++i] = insn;
464 basic_block_end[i] = insn;
465 basic_block_loop_depth[i] = depth;
467 if (code == CODE_LABEL)
469 LABEL_REFS (insn) = insn;
470 /* Any label that cannot be deleted
471 is considered to start a reachable block. */
472 if (LABEL_PRESERVE_P (insn))
473 block_live[i] = 1;
477 else if (GET_RTX_CLASS (code) == 'i')
479 basic_block_end[i] = insn;
480 basic_block_loop_depth[i] = depth;
483 if (GET_RTX_CLASS (code) == 'i')
485 /* Make a list of all labels referred to other than by jumps. */
486 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
487 if (REG_NOTE_KIND (note) == REG_LABEL)
488 label_value_list = gen_rtx_EXPR_LIST (VOIDmode, XEXP (note, 0),
489 label_value_list);
492 /* Keep a lifo list of the currently active exception notes. */
493 if (GET_CODE (insn) == NOTE)
495 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
497 if (eh_note)
498 nested_eh_region [NOTE_BLOCK_NUMBER (insn)] =
499 NOTE_BLOCK_NUMBER (XEXP (eh_note, 0));
500 else
501 nested_eh_region [NOTE_BLOCK_NUMBER (insn)] = 0;
502 eh_note = gen_rtx_EXPR_LIST (VOIDmode,
503 insn, eh_note);
505 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
506 eh_note = XEXP (eh_note, 1);
508 /* If we encounter a CALL_INSN, note which exception handler it
509 might pass control to.
511 If doing asynchronous exceptions, record the active EH handler
512 for every insn, since most insns can throw. */
513 else if (eh_note
514 && (asynchronous_exceptions
515 || (GET_CODE (insn) == CALL_INSN
516 && ! in_libcall_block)))
517 active_eh_region[INSN_UID (insn)] =
518 NOTE_BLOCK_NUMBER (XEXP (eh_note, 0));
519 BLOCK_NUM (insn) = i;
521 if (code != NOTE)
522 prev_code = code;
524 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
525 && find_reg_note (insn, REG_RETVAL, NULL_RTX))
526 in_libcall_block = 0;
529 /* During the second pass, `n_basic_blocks' is only an upper bound.
530 Only perform the sanity check for the first pass, and on the second
531 pass ensure `n_basic_blocks' is set to the correct value. */
532 if (pass == 1 && i + 1 != n_basic_blocks)
533 abort ();
534 n_basic_blocks = i + 1;
536 /* Record which basic blocks control can drop in to. */
538 for (i = 0; i < n_basic_blocks; i++)
540 for (insn = PREV_INSN (basic_block_head[i]);
541 insn && GET_CODE (insn) == NOTE; insn = PREV_INSN (insn))
544 basic_block_drops_in[i] = insn && GET_CODE (insn) != BARRIER;
547 /* Now find which basic blocks can actually be reached
548 and put all jump insns' LABEL_REFS onto the ref-chains
549 of their target labels. */
551 if (n_basic_blocks > 0)
553 int something_marked = 1;
554 int deleted;
556 /* Pass over all blocks, marking each block that is reachable
557 and has not yet been marked.
558 Keep doing this until, in one pass, no blocks have been marked.
559 Then blocks_live and blocks_marked are identical and correct.
560 In addition, all jumps actually reachable have been marked. */
562 while (something_marked)
564 something_marked = 0;
565 for (i = 0; i < n_basic_blocks; i++)
566 if (block_live[i] && !block_marked[i])
568 block_marked[i] = 1;
569 something_marked = 1;
570 if (i + 1 < n_basic_blocks && basic_block_drops_in[i + 1])
571 block_live[i + 1] = 1;
572 insn = basic_block_end[i];
573 if (GET_CODE (insn) == JUMP_INSN)
574 mark_label_ref (PATTERN (insn), insn, 0);
576 /* If we have any forced labels, mark them as potentially
577 reachable from this block. */
578 for (x = forced_labels; x; x = XEXP (x, 1))
579 if (! LABEL_REF_NONLOCAL_P (x))
580 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode, XEXP (x, 0)),
581 insn, 0);
583 /* Now scan the insns for this block, we may need to make
584 edges for some of them to various non-obvious locations
585 (exception handlers, nonlocal labels, etc). */
586 for (insn = basic_block_head[i];
587 insn != NEXT_INSN (basic_block_end[i]);
588 insn = NEXT_INSN (insn))
590 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
593 /* References to labels in non-jumping insns have
594 REG_LABEL notes attached to them.
596 This can happen for computed gotos; we don't care
597 about them here since the values are also on the
598 label_value_list and will be marked live if we find
599 a live computed goto.
601 This can also happen when we take the address of
602 a label to pass as an argument to __throw. Note
603 throw only uses the value to determine what handler
604 should be called -- ie the label is not used as
605 a jump target, it just marks regions in the code.
607 In theory we should be able to ignore the REG_LABEL
608 notes, but we have to make sure that the label and
609 associated insns aren't marked dead, so we make
610 the block in question live and create an edge from
611 this insn to the label. This is not strictly
612 correct, but it is close enough for now. */
613 for (note = REG_NOTES (insn);
614 note;
615 note = XEXP (note, 1))
617 if (REG_NOTE_KIND (note) == REG_LABEL)
619 x = XEXP (note, 0);
620 block_live[BLOCK_NUM (x)] = 1;
621 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode, x),
622 insn, 0);
626 /* If this is a computed jump, then mark it as
627 reaching everything on the label_value_list
628 and forced_labels list. */
629 if (computed_jump_p (insn))
631 current_function_has_computed_jump = 1;
632 for (x = label_value_list; x; x = XEXP (x, 1))
634 int b = BLOCK_NUM (XEXP (x, 0));
635 basic_block_computed_jump_target[b] = 1;
636 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode,
637 XEXP (x, 0)),
638 insn, 0);
641 for (x = forced_labels; x; x = XEXP (x, 1))
643 int b = BLOCK_NUM (XEXP (x, 0));
644 basic_block_computed_jump_target[b] = 1;
645 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode,
646 XEXP (x, 0)),
647 insn, 0);
651 /* If this is a CALL_INSN, then mark it as reaching
652 the active EH handler for this CALL_INSN. If
653 we're handling asynchronous exceptions mark every
654 insn as reaching the active EH handler.
656 Also mark the CALL_INSN as reaching any nonlocal
657 goto sites. */
658 else if (asynchronous_exceptions
659 || (GET_CODE (insn) == CALL_INSN
660 && ! find_reg_note (insn, REG_RETVAL,
661 NULL_RTX)))
663 if (active_eh_region[INSN_UID (insn)])
665 int region;
666 handler_info *ptr;
667 region = active_eh_region[INSN_UID (insn)];
668 for ( ; region;
669 region = nested_eh_region[region])
671 ptr = get_first_handler (region);
672 for ( ; ptr ; ptr = ptr->next)
673 mark_label_ref (gen_rtx_LABEL_REF
674 (VOIDmode, ptr->handler_label), insn, 0);
677 if (!asynchronous_exceptions)
679 for (x = nonlocal_label_list;
681 x = XEXP (x, 1))
682 mark_label_ref (gen_rtx_LABEL_REF (VOIDmode,
683 XEXP (x, 0)),
684 insn, 0);
686 /* ??? This could be made smarter:
687 in some cases it's possible to tell that
688 certain calls will not do a nonlocal goto.
690 For example, if the nested functions that
691 do the nonlocal gotos do not have their
692 addresses taken, then only calls to those
693 functions or to other nested functions that
694 use them could possibly do nonlocal gotos. */
701 /* This should never happen. If it does that means we've computed an
702 incorrect flow graph, which can lead to aborts/crashes later in the
703 compiler or incorrect code generation.
705 We used to try and continue here, but that's just asking for trouble
706 later during the compile or at runtime. It's easier to debug the
707 problem here than later! */
708 for (i = 1; i < n_basic_blocks; i++)
709 if (block_live[i] && ! basic_block_drops_in[i]
710 && GET_CODE (basic_block_head[i]) == CODE_LABEL
711 && LABEL_REFS (basic_block_head[i]) == basic_block_head[i])
712 abort ();
714 /* Now delete the code for any basic blocks that can't be reached.
715 They can occur because jump_optimize does not recognize
716 unreachable loops as unreachable. */
718 deleted = 0;
719 for (i = 0; i < n_basic_blocks; i++)
720 if (!block_live[i])
722 deleted++;
724 /* Delete the insns in a (non-live) block. We physically delete
725 every non-note insn except the start and end (so
726 basic_block_head/end needn't be updated), we turn the latter
727 into NOTE_INSN_DELETED notes.
728 We use to "delete" the insns by turning them into notes, but
729 we may be deleting lots of insns that subsequent passes would
730 otherwise have to process. Secondly, lots of deleted blocks in
731 a row can really slow down propagate_block since it will
732 otherwise process insn-turned-notes multiple times when it
733 looks for loop begin/end notes. */
734 if (basic_block_head[i] != basic_block_end[i])
736 /* It would be quicker to delete all of these with a single
737 unchaining, rather than one at a time, but we need to keep
738 the NOTE's. */
739 insn = NEXT_INSN (basic_block_head[i]);
740 while (insn != basic_block_end[i])
742 if (GET_CODE (insn) == BARRIER)
743 abort ();
744 else if (GET_CODE (insn) != NOTE)
745 insn = flow_delete_insn (insn);
746 else
747 insn = NEXT_INSN (insn);
750 insn = basic_block_head[i];
751 if (GET_CODE (insn) != NOTE)
753 /* Turn the head into a deleted insn note. */
754 if (GET_CODE (insn) == BARRIER)
755 abort ();
757 /* If the head of this block is a CODE_LABEL, then it might
758 be the label for an exception handler which can't be
759 reached.
761 We need to remove the label from the exception_handler_label
762 list and remove the associated NOTE_EH_REGION_BEG and
763 NOTE_EH_REGION_END notes. */
764 if (GET_CODE (insn) == CODE_LABEL)
766 rtx x, *prev = &exception_handler_labels;
768 for (x = exception_handler_labels; x; x = XEXP (x, 1))
770 if (XEXP (x, 0) == insn)
772 /* Found a match, splice this label out of the
773 EH label list. */
774 *prev = XEXP (x, 1);
775 XEXP (x, 1) = NULL_RTX;
776 XEXP (x, 0) = NULL_RTX;
778 /* Remove the handler from all regions */
779 remove_handler (insn);
780 deleted_handler = 1;
781 break;
783 prev = &XEXP (x, 1);
787 PUT_CODE (insn, NOTE);
788 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
789 NOTE_SOURCE_FILE (insn) = 0;
791 insn = basic_block_end[i];
792 if (GET_CODE (insn) != NOTE)
794 /* Turn the tail into a deleted insn note. */
795 if (GET_CODE (insn) == BARRIER)
796 abort ();
797 PUT_CODE (insn, NOTE);
798 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
799 NOTE_SOURCE_FILE (insn) = 0;
801 /* BARRIERs are between basic blocks, not part of one.
802 Delete a BARRIER if the preceding jump is deleted.
803 We cannot alter a BARRIER into a NOTE
804 because it is too short; but we can really delete
805 it because it is not part of a basic block. */
806 if (NEXT_INSN (insn) != 0
807 && GET_CODE (NEXT_INSN (insn)) == BARRIER)
808 delete_insn (NEXT_INSN (insn));
810 /* Each time we delete some basic blocks,
811 see if there is a jump around them that is
812 being turned into a no-op. If so, delete it. */
814 if (block_live[i - 1])
816 register int j;
817 for (j = i + 1; j < n_basic_blocks; j++)
818 if (block_live[j])
820 rtx label;
821 insn = basic_block_end[i - 1];
822 if (GET_CODE (insn) == JUMP_INSN
823 /* An unconditional jump is the only possibility
824 we must check for, since a conditional one
825 would make these blocks live. */
826 && simplejump_p (insn)
827 && (label = XEXP (SET_SRC (PATTERN (insn)), 0), 1)
828 && INSN_UID (label) != 0
829 && BLOCK_NUM (label) == j)
831 int k;
833 /* The deleted blocks still show up in the cfg,
834 so we must set basic_block_drops_in for blocks
835 I to J inclusive to keep the cfg accurate. */
836 for (k = i; k <= j; k++)
837 basic_block_drops_in[k] = 1;
839 PUT_CODE (insn, NOTE);
840 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
841 NOTE_SOURCE_FILE (insn) = 0;
842 if (GET_CODE (NEXT_INSN (insn)) != BARRIER)
843 abort ();
844 delete_insn (NEXT_INSN (insn));
846 break;
850 /* If we deleted an exception handler, we may have EH region
851 begin/end blocks to remove as well. */
852 if (deleted_handler)
853 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
854 if (GET_CODE (insn) == NOTE)
856 if ((NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG) ||
857 (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END))
859 int num = CODE_LABEL_NUMBER (insn);
860 /* A NULL handler indicates a region is no longer needed */
861 if (get_first_handler (num) == NULL)
863 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
864 NOTE_SOURCE_FILE (insn) = 0;
869 /* There are pathological cases where one function calling hundreds of
870 nested inline functions can generate lots and lots of unreachable
871 blocks that jump can't delete. Since we don't use sparse matrices
872 a lot of memory will be needed to compile such functions.
873 Implementing sparse matrices is a fair bit of work and it is not
874 clear that they win more than they lose (we don't want to
875 unnecessarily slow down compilation of normal code). By making
876 another pass for the pathological case, we can greatly speed up
877 their compilation without hurting normal code. This works because
878 all the insns in the unreachable blocks have either been deleted or
879 turned into notes.
880 Note that we're talking about reducing memory usage by 10's of
881 megabytes and reducing compilation time by several minutes. */
882 /* ??? The choice of when to make another pass is a bit arbitrary,
883 and was derived from empirical data. */
884 if (pass == 1
885 && deleted > 200)
887 pass++;
888 n_basic_blocks -= deleted;
889 /* `n_basic_blocks' may not be correct at this point: two previously
890 separate blocks may now be merged. That's ok though as we
891 recalculate it during the second pass. It certainly can't be
892 any larger than the current value. */
893 goto restart;
898 /* Record INSN's block number as BB. */
900 void
901 set_block_num (insn, bb)
902 rtx insn;
903 int bb;
905 if (INSN_UID (insn) >= max_uid_for_flow)
907 /* Add one-eighth the size so we don't keep calling xrealloc. */
908 max_uid_for_flow = INSN_UID (insn) + (INSN_UID (insn) + 7) / 8;
909 uid_block_number = (int *)
910 xrealloc (uid_block_number, (max_uid_for_flow + 1) * sizeof (int));
912 BLOCK_NUM (insn) = bb;
916 /* Subroutines of find_basic_blocks. */
918 /* Check expression X for label references;
919 if one is found, add INSN to the label's chain of references.
921 CHECKDUP means check for and avoid creating duplicate references
922 from the same insn. Such duplicates do no serious harm but
923 can slow life analysis. CHECKDUP is set only when duplicates
924 are likely. */
926 static void
927 mark_label_ref (x, insn, checkdup)
928 rtx x, insn;
929 int checkdup;
931 register RTX_CODE code;
932 register int i;
933 register char *fmt;
935 /* We can be called with NULL when scanning label_value_list. */
936 if (x == 0)
937 return;
939 code = GET_CODE (x);
940 if (code == LABEL_REF)
942 register rtx label = XEXP (x, 0);
943 register rtx y;
944 if (GET_CODE (label) != CODE_LABEL)
945 abort ();
946 /* If the label was never emitted, this insn is junk,
947 but avoid a crash trying to refer to BLOCK_NUM (label).
948 This can happen as a result of a syntax error
949 and a diagnostic has already been printed. */
950 if (INSN_UID (label) == 0)
951 return;
952 CONTAINING_INSN (x) = insn;
953 /* if CHECKDUP is set, check for duplicate ref from same insn
954 and don't insert. */
955 if (checkdup)
956 for (y = LABEL_REFS (label); y != label; y = LABEL_NEXTREF (y))
957 if (CONTAINING_INSN (y) == insn)
958 return;
959 LABEL_NEXTREF (x) = LABEL_REFS (label);
960 LABEL_REFS (label) = x;
961 block_live_static[BLOCK_NUM (label)] = 1;
962 return;
965 fmt = GET_RTX_FORMAT (code);
966 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
968 if (fmt[i] == 'e')
969 mark_label_ref (XEXP (x, i), insn, 0);
970 if (fmt[i] == 'E')
972 register int j;
973 for (j = 0; j < XVECLEN (x, i); j++)
974 mark_label_ref (XVECEXP (x, i, j), insn, 1);
979 /* Delete INSN by patching it out.
980 Return the next insn. */
982 static rtx
983 flow_delete_insn (insn)
984 rtx insn;
986 /* ??? For the moment we assume we don't have to watch for NULLs here
987 since the start/end of basic blocks aren't deleted like this. */
988 NEXT_INSN (PREV_INSN (insn)) = NEXT_INSN (insn);
989 PREV_INSN (NEXT_INSN (insn)) = PREV_INSN (insn);
990 return NEXT_INSN (insn);
993 /* Perform data flow analysis.
994 F is the first insn of the function and NREGS the number of register numbers
995 in use. */
997 void
998 life_analysis (f, nregs, file)
999 rtx f;
1000 int nregs;
1001 FILE *file;
1003 #ifdef ELIMINABLE_REGS
1004 register size_t i;
1005 static struct {int from, to; } eliminables[] = ELIMINABLE_REGS;
1006 #endif
1008 /* Record which registers will be eliminated. We use this in
1009 mark_used_regs. */
1011 CLEAR_HARD_REG_SET (elim_reg_set);
1013 #ifdef ELIMINABLE_REGS
1014 for (i = 0; i < sizeof eliminables / sizeof eliminables[0]; i++)
1015 SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from);
1016 #else
1017 SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM);
1018 #endif
1020 life_analysis_1 (f, nregs);
1021 if (file)
1022 dump_flow_info (file);
1024 free_basic_block_vars (1);
1027 /* Free the variables allocated by find_basic_blocks.
1029 KEEP_HEAD_END_P is non-zero if basic_block_head and basic_block_end
1030 are not to be freed. */
1032 void
1033 free_basic_block_vars (keep_head_end_p)
1034 int keep_head_end_p;
1036 if (basic_block_drops_in)
1038 free (basic_block_drops_in);
1039 /* Tell dump_flow_info this isn't available anymore. */
1040 basic_block_drops_in = 0;
1042 if (basic_block_loop_depth)
1044 free (basic_block_loop_depth);
1045 basic_block_loop_depth = 0;
1047 if (uid_block_number)
1049 free (uid_block_number);
1050 uid_block_number = 0;
1052 if (uid_volatile)
1054 free (uid_volatile);
1055 uid_volatile = 0;
1058 if (! keep_head_end_p && basic_block_head)
1060 free (basic_block_head);
1061 basic_block_head = 0;
1062 free (basic_block_end);
1063 basic_block_end = 0;
1067 /* Determine which registers are live at the start of each
1068 basic block of the function whose first insn is F.
1069 NREGS is the number of registers used in F.
1070 We allocate the vector basic_block_live_at_start
1071 and the regsets that it points to, and fill them with the data.
1072 regset_size and regset_bytes are also set here. */
1074 static void
1075 life_analysis_1 (f, nregs)
1076 rtx f;
1077 int nregs;
1079 int first_pass;
1080 int changed;
1081 /* For each basic block, a bitmask of regs
1082 live on exit from the block. */
1083 regset *basic_block_live_at_end;
1084 /* For each basic block, a bitmask of regs
1085 live on entry to a successor-block of this block.
1086 If this does not match basic_block_live_at_end,
1087 that must be updated, and the block must be rescanned. */
1088 regset *basic_block_new_live_at_end;
1089 /* For each basic block, a bitmask of regs
1090 whose liveness at the end of the basic block
1091 can make a difference in which regs are live on entry to the block.
1092 These are the regs that are set within the basic block,
1093 possibly excluding those that are used after they are set. */
1094 regset *basic_block_significant;
1095 register int i;
1096 rtx insn;
1098 struct obstack flow_obstack;
1100 gcc_obstack_init (&flow_obstack);
1102 max_regno = nregs;
1104 bzero (regs_ever_live, sizeof regs_ever_live);
1106 /* Allocate and zero out many data structures
1107 that will record the data from lifetime analysis. */
1109 allocate_for_life_analysis ();
1111 reg_next_use = (rtx *) alloca (nregs * sizeof (rtx));
1112 bzero ((char *) reg_next_use, nregs * sizeof (rtx));
1114 /* Set up several regset-vectors used internally within this function.
1115 Their meanings are documented above, with their declarations. */
1117 basic_block_live_at_end
1118 = (regset *) alloca (n_basic_blocks * sizeof (regset));
1120 /* Don't use alloca since that leads to a crash rather than an error message
1121 if there isn't enough space.
1122 Don't use oballoc since we may need to allocate other things during
1123 this function on the temporary obstack. */
1124 init_regset_vector (basic_block_live_at_end, n_basic_blocks, &flow_obstack);
1126 basic_block_new_live_at_end
1127 = (regset *) alloca (n_basic_blocks * sizeof (regset));
1128 init_regset_vector (basic_block_new_live_at_end, n_basic_blocks,
1129 &flow_obstack);
1131 basic_block_significant
1132 = (regset *) alloca (n_basic_blocks * sizeof (regset));
1133 init_regset_vector (basic_block_significant, n_basic_blocks, &flow_obstack);
1135 /* Record which insns refer to any volatile memory
1136 or for any reason can't be deleted just because they are dead stores.
1137 Also, delete any insns that copy a register to itself. */
1139 for (insn = f; insn; insn = NEXT_INSN (insn))
1141 enum rtx_code code1 = GET_CODE (insn);
1142 if (code1 == CALL_INSN)
1143 INSN_VOLATILE (insn) = 1;
1144 else if (code1 == INSN || code1 == JUMP_INSN)
1146 /* Delete (in effect) any obvious no-op moves. */
1147 if (GET_CODE (PATTERN (insn)) == SET
1148 && GET_CODE (SET_DEST (PATTERN (insn))) == REG
1149 && GET_CODE (SET_SRC (PATTERN (insn))) == REG
1150 && (REGNO (SET_DEST (PATTERN (insn)))
1151 == REGNO (SET_SRC (PATTERN (insn))))
1152 /* Insns carrying these notes are useful later on. */
1153 && ! find_reg_note (insn, REG_EQUAL, NULL_RTX))
1155 PUT_CODE (insn, NOTE);
1156 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1157 NOTE_SOURCE_FILE (insn) = 0;
1159 /* Delete (in effect) any obvious no-op moves. */
1160 else if (GET_CODE (PATTERN (insn)) == SET
1161 && GET_CODE (SET_DEST (PATTERN (insn))) == SUBREG
1162 && GET_CODE (SUBREG_REG (SET_DEST (PATTERN (insn)))) == REG
1163 && GET_CODE (SET_SRC (PATTERN (insn))) == SUBREG
1164 && GET_CODE (SUBREG_REG (SET_SRC (PATTERN (insn)))) == REG
1165 && (REGNO (SUBREG_REG (SET_DEST (PATTERN (insn))))
1166 == REGNO (SUBREG_REG (SET_SRC (PATTERN (insn)))))
1167 && SUBREG_WORD (SET_DEST (PATTERN (insn))) ==
1168 SUBREG_WORD (SET_SRC (PATTERN (insn)))
1169 /* Insns carrying these notes are useful later on. */
1170 && ! find_reg_note (insn, REG_EQUAL, NULL_RTX))
1172 PUT_CODE (insn, NOTE);
1173 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1174 NOTE_SOURCE_FILE (insn) = 0;
1176 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
1178 /* If nothing but SETs of registers to themselves,
1179 this insn can also be deleted. */
1180 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
1182 rtx tem = XVECEXP (PATTERN (insn), 0, i);
1184 if (GET_CODE (tem) == USE
1185 || GET_CODE (tem) == CLOBBER)
1186 continue;
1188 if (GET_CODE (tem) != SET
1189 || GET_CODE (SET_DEST (tem)) != REG
1190 || GET_CODE (SET_SRC (tem)) != REG
1191 || REGNO (SET_DEST (tem)) != REGNO (SET_SRC (tem)))
1192 break;
1195 if (i == XVECLEN (PATTERN (insn), 0)
1196 /* Insns carrying these notes are useful later on. */
1197 && ! find_reg_note (insn, REG_EQUAL, NULL_RTX))
1199 PUT_CODE (insn, NOTE);
1200 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1201 NOTE_SOURCE_FILE (insn) = 0;
1203 else
1204 INSN_VOLATILE (insn) = volatile_refs_p (PATTERN (insn));
1206 else if (GET_CODE (PATTERN (insn)) != USE)
1207 INSN_VOLATILE (insn) = volatile_refs_p (PATTERN (insn));
1208 /* A SET that makes space on the stack cannot be dead.
1209 (Such SETs occur only for allocating variable-size data,
1210 so they will always have a PLUS or MINUS according to the
1211 direction of stack growth.)
1212 Even if this function never uses this stack pointer value,
1213 signal handlers do! */
1214 else if (code1 == INSN && GET_CODE (PATTERN (insn)) == SET
1215 && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
1216 #ifdef STACK_GROWS_DOWNWARD
1217 && GET_CODE (SET_SRC (PATTERN (insn))) == MINUS
1218 #else
1219 && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
1220 #endif
1221 && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx)
1222 INSN_VOLATILE (insn) = 1;
1226 if (n_basic_blocks > 0)
1227 #ifdef EXIT_IGNORE_STACK
1228 if (! EXIT_IGNORE_STACK
1229 || (! FRAME_POINTER_REQUIRED
1230 && ! current_function_calls_alloca
1231 && flag_omit_frame_pointer))
1232 #endif
1234 /* If exiting needs the right stack value,
1235 consider the stack pointer live at the end of the function. */
1236 SET_REGNO_REG_SET (basic_block_live_at_end[n_basic_blocks - 1],
1237 STACK_POINTER_REGNUM);
1238 SET_REGNO_REG_SET (basic_block_new_live_at_end[n_basic_blocks - 1],
1239 STACK_POINTER_REGNUM);
1242 /* Mark the frame pointer is needed at the end of the function. If
1243 we end up eliminating it, it will be removed from the live list
1244 of each basic block by reload. */
1246 if (n_basic_blocks > 0)
1248 SET_REGNO_REG_SET (basic_block_live_at_end[n_basic_blocks - 1],
1249 FRAME_POINTER_REGNUM);
1250 SET_REGNO_REG_SET (basic_block_new_live_at_end[n_basic_blocks - 1],
1251 FRAME_POINTER_REGNUM);
1252 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
1253 /* If they are different, also mark the hard frame pointer as live */
1254 SET_REGNO_REG_SET (basic_block_live_at_end[n_basic_blocks - 1],
1255 HARD_FRAME_POINTER_REGNUM);
1256 SET_REGNO_REG_SET (basic_block_new_live_at_end[n_basic_blocks - 1],
1257 HARD_FRAME_POINTER_REGNUM);
1258 #endif
1261 /* Mark all global registers and all registers used by the epilogue
1262 as being live at the end of the function since they may be
1263 referenced by our caller. */
1265 if (n_basic_blocks > 0)
1266 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1267 if (global_regs[i]
1268 #ifdef EPILOGUE_USES
1269 || EPILOGUE_USES (i)
1270 #endif
1273 SET_REGNO_REG_SET (basic_block_live_at_end[n_basic_blocks - 1], i);
1274 SET_REGNO_REG_SET (basic_block_new_live_at_end[n_basic_blocks - 1], i);
1277 /* Propagate life info through the basic blocks
1278 around the graph of basic blocks.
1280 This is a relaxation process: each time a new register
1281 is live at the end of the basic block, we must scan the block
1282 to determine which registers are, as a consequence, live at the beginning
1283 of that block. These registers must then be marked live at the ends
1284 of all the blocks that can transfer control to that block.
1285 The process continues until it reaches a fixed point. */
1287 first_pass = 1;
1288 changed = 1;
1289 while (changed)
1291 changed = 0;
1292 for (i = n_basic_blocks - 1; i >= 0; i--)
1294 int consider = first_pass;
1295 int must_rescan = first_pass;
1296 register int j;
1298 if (!first_pass)
1300 /* Set CONSIDER if this block needs thinking about at all
1301 (that is, if the regs live now at the end of it
1302 are not the same as were live at the end of it when
1303 we last thought about it).
1304 Set must_rescan if it needs to be thought about
1305 instruction by instruction (that is, if any additional
1306 reg that is live at the end now but was not live there before
1307 is one of the significant regs of this basic block). */
1309 EXECUTE_IF_AND_COMPL_IN_REG_SET
1310 (basic_block_new_live_at_end[i],
1311 basic_block_live_at_end[i], 0, j,
1313 consider = 1;
1314 if (REGNO_REG_SET_P (basic_block_significant[i], j))
1316 must_rescan = 1;
1317 goto done;
1320 done:
1321 if (! consider)
1322 continue;
1325 /* The live_at_start of this block may be changing,
1326 so another pass will be required after this one. */
1327 changed = 1;
1329 if (! must_rescan)
1331 /* No complete rescan needed;
1332 just record those variables newly known live at end
1333 as live at start as well. */
1334 IOR_AND_COMPL_REG_SET (basic_block_live_at_start[i],
1335 basic_block_new_live_at_end[i],
1336 basic_block_live_at_end[i]);
1338 IOR_AND_COMPL_REG_SET (basic_block_live_at_end[i],
1339 basic_block_new_live_at_end[i],
1340 basic_block_live_at_end[i]);
1342 else
1344 /* Update the basic_block_live_at_start
1345 by propagation backwards through the block. */
1346 COPY_REG_SET (basic_block_live_at_end[i],
1347 basic_block_new_live_at_end[i]);
1348 COPY_REG_SET (basic_block_live_at_start[i],
1349 basic_block_live_at_end[i]);
1350 propagate_block (basic_block_live_at_start[i],
1351 basic_block_head[i], basic_block_end[i], 0,
1352 first_pass ? basic_block_significant[i]
1353 : (regset) 0,
1358 register rtx jump, head;
1360 /* Update the basic_block_new_live_at_end's of the block
1361 that falls through into this one (if any). */
1362 head = basic_block_head[i];
1363 if (basic_block_drops_in[i])
1364 IOR_REG_SET (basic_block_new_live_at_end[i-1],
1365 basic_block_live_at_start[i]);
1367 /* Update the basic_block_new_live_at_end's of
1368 all the blocks that jump to this one. */
1369 if (GET_CODE (head) == CODE_LABEL)
1370 for (jump = LABEL_REFS (head);
1371 jump != head;
1372 jump = LABEL_NEXTREF (jump))
1374 register int from_block = BLOCK_NUM (CONTAINING_INSN (jump));
1375 IOR_REG_SET (basic_block_new_live_at_end[from_block],
1376 basic_block_live_at_start[i]);
1379 #ifdef USE_C_ALLOCA
1380 alloca (0);
1381 #endif
1383 first_pass = 0;
1386 /* The only pseudos that are live at the beginning of the function are
1387 those that were not set anywhere in the function. local-alloc doesn't
1388 know how to handle these correctly, so mark them as not local to any
1389 one basic block. */
1391 if (n_basic_blocks > 0)
1392 EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[0],
1393 FIRST_PSEUDO_REGISTER, i,
1395 REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL;
1398 /* Now the life information is accurate.
1399 Make one more pass over each basic block
1400 to delete dead stores, create autoincrement addressing
1401 and record how many times each register is used, is set, or dies.
1403 To save time, we operate directly in basic_block_live_at_end[i],
1404 thus destroying it (in fact, converting it into a copy of
1405 basic_block_live_at_start[i]). This is ok now because
1406 basic_block_live_at_end[i] is no longer used past this point. */
1408 max_scratch = 0;
1410 for (i = 0; i < n_basic_blocks; i++)
1412 propagate_block (basic_block_live_at_end[i],
1413 basic_block_head[i], basic_block_end[i], 1,
1414 (regset) 0, i);
1415 #ifdef USE_C_ALLOCA
1416 alloca (0);
1417 #endif
1420 #if 0
1421 /* Something live during a setjmp should not be put in a register
1422 on certain machines which restore regs from stack frames
1423 rather than from the jmpbuf.
1424 But we don't need to do this for the user's variables, since
1425 ANSI says only volatile variables need this. */
1426 #ifdef LONGJMP_RESTORE_FROM_STACK
1427 EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp,
1428 FIRST_PSEUDO_REGISTER, i,
1430 if (regno_reg_rtx[i] != 0
1431 && ! REG_USERVAR_P (regno_reg_rtx[i]))
1433 REG_LIVE_LENGTH (i) = -1;
1434 REG_BASIC_BLOCK (i) = -1;
1437 #endif
1438 #endif
1440 /* We have a problem with any pseudoreg that
1441 lives across the setjmp. ANSI says that if a
1442 user variable does not change in value
1443 between the setjmp and the longjmp, then the longjmp preserves it.
1444 This includes longjmp from a place where the pseudo appears dead.
1445 (In principle, the value still exists if it is in scope.)
1446 If the pseudo goes in a hard reg, some other value may occupy
1447 that hard reg where this pseudo is dead, thus clobbering the pseudo.
1448 Conclusion: such a pseudo must not go in a hard reg. */
1449 EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp,
1450 FIRST_PSEUDO_REGISTER, i,
1452 if (regno_reg_rtx[i] != 0)
1454 REG_LIVE_LENGTH (i) = -1;
1455 REG_BASIC_BLOCK (i) = -1;
1460 free_regset_vector (basic_block_live_at_end, n_basic_blocks);
1461 free_regset_vector (basic_block_new_live_at_end, n_basic_blocks);
1462 free_regset_vector (basic_block_significant, n_basic_blocks);
1463 basic_block_live_at_end = (regset *)0;
1464 basic_block_new_live_at_end = (regset *)0;
1465 basic_block_significant = (regset *)0;
1467 obstack_free (&flow_obstack, NULL_PTR);
1470 /* Subroutines of life analysis. */
1472 /* Allocate the permanent data structures that represent the results
1473 of life analysis. Not static since used also for stupid life analysis. */
1475 void
1476 allocate_for_life_analysis ()
1478 register int i;
1480 /* Recalculate the register space, in case it has grown. Old style
1481 vector oriented regsets would set regset_{size,bytes} here also. */
1482 allocate_reg_info (max_regno, FALSE, FALSE);
1484 /* Because both reg_scan and flow_analysis want to set up the REG_N_SETS
1485 information, explicitly reset it here. The allocation should have
1486 already happened on the previous reg_scan pass. Make sure in case
1487 some more registers were allocated. */
1488 for (i = 0; i < max_regno; i++)
1489 REG_N_SETS (i) = 0;
1491 basic_block_live_at_start
1492 = (regset *) oballoc (n_basic_blocks * sizeof (regset));
1493 init_regset_vector (basic_block_live_at_start, n_basic_blocks,
1494 function_obstack);
1496 regs_live_at_setjmp = OBSTACK_ALLOC_REG_SET (function_obstack);
1497 CLEAR_REG_SET (regs_live_at_setjmp);
1500 /* Make each element of VECTOR point at a regset. The vector has
1501 NELTS elements, and space is allocated from the ALLOC_OBSTACK
1502 obstack. */
1504 static void
1505 init_regset_vector (vector, nelts, alloc_obstack)
1506 regset *vector;
1507 int nelts;
1508 struct obstack *alloc_obstack;
1510 register int i;
1512 for (i = 0; i < nelts; i++)
1514 vector[i] = OBSTACK_ALLOC_REG_SET (alloc_obstack);
1515 CLEAR_REG_SET (vector[i]);
1519 /* Release any additional space allocated for each element of VECTOR point
1520 other than the regset header itself. The vector has NELTS elements. */
1522 void
1523 free_regset_vector (vector, nelts)
1524 regset *vector;
1525 int nelts;
1527 register int i;
1529 for (i = 0; i < nelts; i++)
1530 FREE_REG_SET (vector[i]);
1533 /* Compute the registers live at the beginning of a basic block
1534 from those live at the end.
1536 When called, OLD contains those live at the end.
1537 On return, it contains those live at the beginning.
1538 FIRST and LAST are the first and last insns of the basic block.
1540 FINAL is nonzero if we are doing the final pass which is not
1541 for computing the life info (since that has already been done)
1542 but for acting on it. On this pass, we delete dead stores,
1543 set up the logical links and dead-variables lists of instructions,
1544 and merge instructions for autoincrement and autodecrement addresses.
1546 SIGNIFICANT is nonzero only the first time for each basic block.
1547 If it is nonzero, it points to a regset in which we store
1548 a 1 for each register that is set within the block.
1550 BNUM is the number of the basic block. */
1552 static void
1553 propagate_block (old, first, last, final, significant, bnum)
1554 register regset old;
1555 rtx first;
1556 rtx last;
1557 int final;
1558 regset significant;
1559 int bnum;
1561 register rtx insn;
1562 rtx prev;
1563 regset live;
1564 regset dead;
1566 /* The following variables are used only if FINAL is nonzero. */
1567 /* This vector gets one element for each reg that has been live
1568 at any point in the basic block that has been scanned so far.
1569 SOMETIMES_MAX says how many elements are in use so far. */
1570 register int *regs_sometimes_live;
1571 int sometimes_max = 0;
1572 /* This regset has 1 for each reg that we have seen live so far.
1573 It and REGS_SOMETIMES_LIVE are updated together. */
1574 regset maxlive;
1576 /* The loop depth may change in the middle of a basic block. Since we
1577 scan from end to beginning, we start with the depth at the end of the
1578 current basic block, and adjust as we pass ends and starts of loops. */
1579 loop_depth = basic_block_loop_depth[bnum];
1581 dead = ALLOCA_REG_SET ();
1582 live = ALLOCA_REG_SET ();
1584 cc0_live = 0;
1585 last_mem_set = 0;
1587 /* Include any notes at the end of the block in the scan.
1588 This is in case the block ends with a call to setjmp. */
1590 while (NEXT_INSN (last) != 0 && GET_CODE (NEXT_INSN (last)) == NOTE)
1592 /* Look for loop boundaries, we are going forward here. */
1593 last = NEXT_INSN (last);
1594 if (NOTE_LINE_NUMBER (last) == NOTE_INSN_LOOP_BEG)
1595 loop_depth++;
1596 else if (NOTE_LINE_NUMBER (last) == NOTE_INSN_LOOP_END)
1597 loop_depth--;
1600 if (final)
1602 register int i;
1604 num_scratch = 0;
1605 maxlive = ALLOCA_REG_SET ();
1606 COPY_REG_SET (maxlive, old);
1607 regs_sometimes_live = (int *) alloca (max_regno * sizeof (int));
1609 /* Process the regs live at the end of the block.
1610 Enter them in MAXLIVE and REGS_SOMETIMES_LIVE.
1611 Also mark them as not local to any one basic block. */
1612 EXECUTE_IF_SET_IN_REG_SET (old, 0, i,
1614 REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL;
1615 regs_sometimes_live[sometimes_max] = i;
1616 sometimes_max++;
1620 /* Scan the block an insn at a time from end to beginning. */
1622 for (insn = last; ; insn = prev)
1624 prev = PREV_INSN (insn);
1626 if (GET_CODE (insn) == NOTE)
1628 /* Look for loop boundaries, remembering that we are going
1629 backwards. */
1630 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
1631 loop_depth++;
1632 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
1633 loop_depth--;
1635 /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error.
1636 Abort now rather than setting register status incorrectly. */
1637 if (loop_depth == 0)
1638 abort ();
1640 /* If this is a call to `setjmp' et al,
1641 warn if any non-volatile datum is live. */
1643 if (final && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)
1644 IOR_REG_SET (regs_live_at_setjmp, old);
1647 /* Update the life-status of regs for this insn.
1648 First DEAD gets which regs are set in this insn
1649 then LIVE gets which regs are used in this insn.
1650 Then the regs live before the insn
1651 are those live after, with DEAD regs turned off,
1652 and then LIVE regs turned on. */
1654 else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1656 register int i;
1657 rtx note = find_reg_note (insn, REG_RETVAL, NULL_RTX);
1658 int insn_is_dead
1659 = (insn_dead_p (PATTERN (insn), old, 0)
1660 /* Don't delete something that refers to volatile storage! */
1661 && ! INSN_VOLATILE (insn));
1662 int libcall_is_dead
1663 = (insn_is_dead && note != 0
1664 && libcall_dead_p (PATTERN (insn), old, note, insn));
1666 /* If an instruction consists of just dead store(s) on final pass,
1667 "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED.
1668 We could really delete it with delete_insn, but that
1669 can cause trouble for first or last insn in a basic block. */
1670 if (final && insn_is_dead)
1672 PUT_CODE (insn, NOTE);
1673 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1674 NOTE_SOURCE_FILE (insn) = 0;
1676 /* CC0 is now known to be dead. Either this insn used it,
1677 in which case it doesn't anymore, or clobbered it,
1678 so the next insn can't use it. */
1679 cc0_live = 0;
1681 /* If this insn is copying the return value from a library call,
1682 delete the entire library call. */
1683 if (libcall_is_dead)
1685 rtx first = XEXP (note, 0);
1686 rtx p = insn;
1687 while (INSN_DELETED_P (first))
1688 first = NEXT_INSN (first);
1689 while (p != first)
1691 p = PREV_INSN (p);
1692 PUT_CODE (p, NOTE);
1693 NOTE_LINE_NUMBER (p) = NOTE_INSN_DELETED;
1694 NOTE_SOURCE_FILE (p) = 0;
1697 goto flushed;
1700 CLEAR_REG_SET (dead);
1701 CLEAR_REG_SET (live);
1703 /* See if this is an increment or decrement that can be
1704 merged into a following memory address. */
1705 #ifdef AUTO_INC_DEC
1707 register rtx x = single_set (insn);
1709 /* Does this instruction increment or decrement a register? */
1710 if (final && x != 0
1711 && GET_CODE (SET_DEST (x)) == REG
1712 && (GET_CODE (SET_SRC (x)) == PLUS
1713 || GET_CODE (SET_SRC (x)) == MINUS)
1714 && XEXP (SET_SRC (x), 0) == SET_DEST (x)
1715 && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
1716 /* Ok, look for a following memory ref we can combine with.
1717 If one is found, change the memory ref to a PRE_INC
1718 or PRE_DEC, cancel this insn, and return 1.
1719 Return 0 if nothing has been done. */
1720 && try_pre_increment_1 (insn))
1721 goto flushed;
1723 #endif /* AUTO_INC_DEC */
1725 /* If this is not the final pass, and this insn is copying the
1726 value of a library call and it's dead, don't scan the
1727 insns that perform the library call, so that the call's
1728 arguments are not marked live. */
1729 if (libcall_is_dead)
1731 /* Mark the dest reg as `significant'. */
1732 mark_set_regs (old, dead, PATTERN (insn), NULL_RTX, significant);
1734 insn = XEXP (note, 0);
1735 prev = PREV_INSN (insn);
1737 else if (GET_CODE (PATTERN (insn)) == SET
1738 && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
1739 && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
1740 && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx
1741 && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT)
1742 /* We have an insn to pop a constant amount off the stack.
1743 (Such insns use PLUS regardless of the direction of the stack,
1744 and any insn to adjust the stack by a constant is always a pop.)
1745 These insns, if not dead stores, have no effect on life. */
1747 else
1749 /* LIVE gets the regs used in INSN;
1750 DEAD gets those set by it. Dead insns don't make anything
1751 live. */
1753 mark_set_regs (old, dead, PATTERN (insn),
1754 final ? insn : NULL_RTX, significant);
1756 /* If an insn doesn't use CC0, it becomes dead since we
1757 assume that every insn clobbers it. So show it dead here;
1758 mark_used_regs will set it live if it is referenced. */
1759 cc0_live = 0;
1761 if (! insn_is_dead)
1762 mark_used_regs (old, live, PATTERN (insn), final, insn);
1764 /* Sometimes we may have inserted something before INSN (such as
1765 a move) when we make an auto-inc. So ensure we will scan
1766 those insns. */
1767 #ifdef AUTO_INC_DEC
1768 prev = PREV_INSN (insn);
1769 #endif
1771 if (! insn_is_dead && GET_CODE (insn) == CALL_INSN)
1773 register int i;
1775 rtx note;
1777 for (note = CALL_INSN_FUNCTION_USAGE (insn);
1778 note;
1779 note = XEXP (note, 1))
1780 if (GET_CODE (XEXP (note, 0)) == USE)
1781 mark_used_regs (old, live, SET_DEST (XEXP (note, 0)),
1782 final, insn);
1784 /* Each call clobbers all call-clobbered regs that are not
1785 global or fixed. Note that the function-value reg is a
1786 call-clobbered reg, and mark_set_regs has already had
1787 a chance to handle it. */
1789 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1790 if (call_used_regs[i] && ! global_regs[i]
1791 && ! fixed_regs[i])
1792 SET_REGNO_REG_SET (dead, i);
1794 /* The stack ptr is used (honorarily) by a CALL insn. */
1795 SET_REGNO_REG_SET (live, STACK_POINTER_REGNUM);
1797 /* Calls may also reference any of the global registers,
1798 so they are made live. */
1799 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1800 if (global_regs[i])
1801 mark_used_regs (old, live,
1802 gen_rtx_REG (reg_raw_mode[i], i),
1803 final, insn);
1805 /* Calls also clobber memory. */
1806 last_mem_set = 0;
1809 /* Update OLD for the registers used or set. */
1810 AND_COMPL_REG_SET (old, dead);
1811 IOR_REG_SET (old, live);
1813 if (GET_CODE (insn) == CALL_INSN && final)
1815 /* Any regs live at the time of a call instruction
1816 must not go in a register clobbered by calls.
1817 Find all regs now live and record this for them. */
1819 register int *p = regs_sometimes_live;
1821 for (i = 0; i < sometimes_max; i++, p++)
1822 if (REGNO_REG_SET_P (old, *p))
1823 REG_N_CALLS_CROSSED (*p)++;
1827 /* On final pass, add any additional sometimes-live regs
1828 into MAXLIVE and REGS_SOMETIMES_LIVE.
1829 Also update counts of how many insns each reg is live at. */
1831 if (final)
1833 register int regno;
1834 register int *p;
1836 EXECUTE_IF_AND_COMPL_IN_REG_SET
1837 (live, maxlive, 0, regno,
1839 regs_sometimes_live[sometimes_max++] = regno;
1840 SET_REGNO_REG_SET (maxlive, regno);
1843 p = regs_sometimes_live;
1844 for (i = 0; i < sometimes_max; i++)
1846 regno = *p++;
1847 if (REGNO_REG_SET_P (old, regno))
1848 REG_LIVE_LENGTH (regno)++;
1852 flushed: ;
1853 if (insn == first)
1854 break;
1857 FREE_REG_SET (dead);
1858 FREE_REG_SET (live);
1859 if (final)
1860 FREE_REG_SET (maxlive);
1862 if (num_scratch > max_scratch)
1863 max_scratch = num_scratch;
1866 /* Return 1 if X (the body of an insn, or part of it) is just dead stores
1867 (SET expressions whose destinations are registers dead after the insn).
1868 NEEDED is the regset that says which regs are alive after the insn.
1870 Unless CALL_OK is non-zero, an insn is needed if it contains a CALL. */
1872 static int
1873 insn_dead_p (x, needed, call_ok)
1874 rtx x;
1875 regset needed;
1876 int call_ok;
1878 enum rtx_code code = GET_CODE (x);
1880 /* If setting something that's a reg or part of one,
1881 see if that register's altered value will be live. */
1883 if (code == SET)
1885 rtx r = SET_DEST (x);
1887 /* A SET that is a subroutine call cannot be dead. */
1888 if (! call_ok && GET_CODE (SET_SRC (x)) == CALL)
1889 return 0;
1891 #ifdef HAVE_cc0
1892 if (GET_CODE (r) == CC0)
1893 return ! cc0_live;
1894 #endif
1896 if (GET_CODE (r) == MEM && last_mem_set && ! MEM_VOLATILE_P (r)
1897 && rtx_equal_p (r, last_mem_set))
1898 return 1;
1900 while (GET_CODE (r) == SUBREG || GET_CODE (r) == STRICT_LOW_PART
1901 || GET_CODE (r) == ZERO_EXTRACT)
1902 r = SUBREG_REG (r);
1904 if (GET_CODE (r) == REG)
1906 int regno = REGNO (r);
1908 /* Don't delete insns to set global regs. */
1909 if ((regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
1910 /* Make sure insns to set frame pointer aren't deleted. */
1911 || regno == FRAME_POINTER_REGNUM
1912 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
1913 || regno == HARD_FRAME_POINTER_REGNUM
1914 #endif
1915 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1916 /* Make sure insns to set arg pointer are never deleted
1917 (if the arg pointer isn't fixed, there will be a USE for
1918 it, so we can treat it normally). */
1919 || (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
1920 #endif
1921 || REGNO_REG_SET_P (needed, regno))
1922 return 0;
1924 /* If this is a hard register, verify that subsequent words are
1925 not needed. */
1926 if (regno < FIRST_PSEUDO_REGISTER)
1928 int n = HARD_REGNO_NREGS (regno, GET_MODE (r));
1930 while (--n > 0)
1931 if (REGNO_REG_SET_P (needed, regno+n))
1932 return 0;
1935 return 1;
1939 /* If performing several activities,
1940 insn is dead if each activity is individually dead.
1941 Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE
1942 that's inside a PARALLEL doesn't make the insn worth keeping. */
1943 else if (code == PARALLEL)
1945 int i = XVECLEN (x, 0);
1947 for (i--; i >= 0; i--)
1948 if (GET_CODE (XVECEXP (x, 0, i)) != CLOBBER
1949 && GET_CODE (XVECEXP (x, 0, i)) != USE
1950 && ! insn_dead_p (XVECEXP (x, 0, i), needed, call_ok))
1951 return 0;
1953 return 1;
1956 /* A CLOBBER of a pseudo-register that is dead serves no purpose. That
1957 is not necessarily true for hard registers. */
1958 else if (code == CLOBBER && GET_CODE (XEXP (x, 0)) == REG
1959 && REGNO (XEXP (x, 0)) >= FIRST_PSEUDO_REGISTER
1960 && ! REGNO_REG_SET_P (needed, REGNO (XEXP (x, 0))))
1961 return 1;
1963 /* We do not check other CLOBBER or USE here. An insn consisting of just
1964 a CLOBBER or just a USE should not be deleted. */
1965 return 0;
1968 /* If X is the pattern of the last insn in a libcall, and assuming X is dead,
1969 return 1 if the entire library call is dead.
1970 This is true if X copies a register (hard or pseudo)
1971 and if the hard return reg of the call insn is dead.
1972 (The caller should have tested the destination of X already for death.)
1974 If this insn doesn't just copy a register, then we don't
1975 have an ordinary libcall. In that case, cse could not have
1976 managed to substitute the source for the dest later on,
1977 so we can assume the libcall is dead.
1979 NEEDED is the bit vector of pseudoregs live before this insn.
1980 NOTE is the REG_RETVAL note of the insn. INSN is the insn itself. */
1982 static int
1983 libcall_dead_p (x, needed, note, insn)
1984 rtx x;
1985 regset needed;
1986 rtx note;
1987 rtx insn;
1989 register RTX_CODE code = GET_CODE (x);
1991 if (code == SET)
1993 register rtx r = SET_SRC (x);
1994 if (GET_CODE (r) == REG)
1996 rtx call = XEXP (note, 0);
1997 register int i;
1999 /* Find the call insn. */
2000 while (call != insn && GET_CODE (call) != CALL_INSN)
2001 call = NEXT_INSN (call);
2003 /* If there is none, do nothing special,
2004 since ordinary death handling can understand these insns. */
2005 if (call == insn)
2006 return 0;
2008 /* See if the hard reg holding the value is dead.
2009 If this is a PARALLEL, find the call within it. */
2010 call = PATTERN (call);
2011 if (GET_CODE (call) == PARALLEL)
2013 for (i = XVECLEN (call, 0) - 1; i >= 0; i--)
2014 if (GET_CODE (XVECEXP (call, 0, i)) == SET
2015 && GET_CODE (SET_SRC (XVECEXP (call, 0, i))) == CALL)
2016 break;
2018 /* This may be a library call that is returning a value
2019 via invisible pointer. Do nothing special, since
2020 ordinary death handling can understand these insns. */
2021 if (i < 0)
2022 return 0;
2024 call = XVECEXP (call, 0, i);
2027 return insn_dead_p (call, needed, 1);
2030 return 1;
2033 /* Return 1 if register REGNO was used before it was set.
2034 In other words, if it is live at function entry.
2035 Don't count global register variables or variables in registers
2036 that can be used for function arg passing, though. */
2039 regno_uninitialized (regno)
2040 int regno;
2042 if (n_basic_blocks == 0
2043 || (regno < FIRST_PSEUDO_REGISTER
2044 && (global_regs[regno] || FUNCTION_ARG_REGNO_P (regno))))
2045 return 0;
2047 return REGNO_REG_SET_P (basic_block_live_at_start[0], regno);
2050 /* 1 if register REGNO was alive at a place where `setjmp' was called
2051 and was set more than once or is an argument.
2052 Such regs may be clobbered by `longjmp'. */
2055 regno_clobbered_at_setjmp (regno)
2056 int regno;
2058 if (n_basic_blocks == 0)
2059 return 0;
2061 return ((REG_N_SETS (regno) > 1
2062 || REGNO_REG_SET_P (basic_block_live_at_start[0], regno))
2063 && REGNO_REG_SET_P (regs_live_at_setjmp, regno));
2066 /* Process the registers that are set within X.
2067 Their bits are set to 1 in the regset DEAD,
2068 because they are dead prior to this insn.
2070 If INSN is nonzero, it is the insn being processed
2071 and the fact that it is nonzero implies this is the FINAL pass
2072 in propagate_block. In this case, various info about register
2073 usage is stored, LOG_LINKS fields of insns are set up. */
2075 static void
2076 mark_set_regs (needed, dead, x, insn, significant)
2077 regset needed;
2078 regset dead;
2079 rtx x;
2080 rtx insn;
2081 regset significant;
2083 register RTX_CODE code = GET_CODE (x);
2085 if (code == SET || code == CLOBBER)
2086 mark_set_1 (needed, dead, x, insn, significant);
2087 else if (code == PARALLEL)
2089 register int i;
2090 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
2092 code = GET_CODE (XVECEXP (x, 0, i));
2093 if (code == SET || code == CLOBBER)
2094 mark_set_1 (needed, dead, XVECEXP (x, 0, i), insn, significant);
2099 /* Process a single SET rtx, X. */
2101 static void
2102 mark_set_1 (needed, dead, x, insn, significant)
2103 regset needed;
2104 regset dead;
2105 rtx x;
2106 rtx insn;
2107 regset significant;
2109 register int regno;
2110 register rtx reg = SET_DEST (x);
2112 /* Modifying just one hardware register of a multi-reg value
2113 or just a byte field of a register
2114 does not mean the value from before this insn is now dead.
2115 But it does mean liveness of that register at the end of the block
2116 is significant.
2118 Within mark_set_1, however, we treat it as if the register is
2119 indeed modified. mark_used_regs will, however, also treat this
2120 register as being used. Thus, we treat these insns as setting a
2121 new value for the register as a function of its old value. This
2122 cases LOG_LINKS to be made appropriately and this will help combine. */
2124 while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT
2125 || GET_CODE (reg) == SIGN_EXTRACT
2126 || GET_CODE (reg) == STRICT_LOW_PART)
2127 reg = XEXP (reg, 0);
2129 /* If we are writing into memory or into a register mentioned in the
2130 address of the last thing stored into memory, show we don't know
2131 what the last store was. If we are writing memory, save the address
2132 unless it is volatile. */
2133 if (GET_CODE (reg) == MEM
2134 || (GET_CODE (reg) == REG
2135 && last_mem_set != 0 && reg_overlap_mentioned_p (reg, last_mem_set)))
2136 last_mem_set = 0;
2138 if (GET_CODE (reg) == MEM && ! side_effects_p (reg)
2139 /* There are no REG_INC notes for SP, so we can't assume we'll see
2140 everything that invalidates it. To be safe, don't eliminate any
2141 stores though SP; none of them should be redundant anyway. */
2142 && ! reg_mentioned_p (stack_pointer_rtx, reg))
2143 last_mem_set = reg;
2145 if (GET_CODE (reg) == REG
2146 && (regno = REGNO (reg), regno != FRAME_POINTER_REGNUM)
2147 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2148 && regno != HARD_FRAME_POINTER_REGNUM
2149 #endif
2150 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2151 && ! (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
2152 #endif
2153 && ! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno]))
2154 /* && regno != STACK_POINTER_REGNUM) -- let's try without this. */
2156 int some_needed = REGNO_REG_SET_P (needed, regno);
2157 int some_not_needed = ! some_needed;
2159 /* Mark it as a significant register for this basic block. */
2160 if (significant)
2161 SET_REGNO_REG_SET (significant, regno);
2163 /* Mark it as dead before this insn. */
2164 SET_REGNO_REG_SET (dead, regno);
2166 /* A hard reg in a wide mode may really be multiple registers.
2167 If so, mark all of them just like the first. */
2168 if (regno < FIRST_PSEUDO_REGISTER)
2170 int n;
2172 /* Nothing below is needed for the stack pointer; get out asap.
2173 Eg, log links aren't needed, since combine won't use them. */
2174 if (regno == STACK_POINTER_REGNUM)
2175 return;
2177 n = HARD_REGNO_NREGS (regno, GET_MODE (reg));
2178 while (--n > 0)
2180 int regno_n = regno + n;
2181 int needed_regno = REGNO_REG_SET_P (needed, regno_n);
2182 if (significant)
2183 SET_REGNO_REG_SET (significant, regno_n);
2185 SET_REGNO_REG_SET (dead, regno_n);
2186 some_needed |= needed_regno;
2187 some_not_needed |= ! needed_regno;
2190 /* Additional data to record if this is the final pass. */
2191 if (insn)
2193 register rtx y = reg_next_use[regno];
2194 register int blocknum = BLOCK_NUM (insn);
2196 /* If this is a hard reg, record this function uses the reg. */
2198 if (regno < FIRST_PSEUDO_REGISTER)
2200 register int i;
2201 int endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
2203 for (i = regno; i < endregno; i++)
2205 /* The next use is no longer "next", since a store
2206 intervenes. */
2207 reg_next_use[i] = 0;
2209 regs_ever_live[i] = 1;
2210 REG_N_SETS (i)++;
2213 else
2215 /* The next use is no longer "next", since a store
2216 intervenes. */
2217 reg_next_use[regno] = 0;
2219 /* Keep track of which basic blocks each reg appears in. */
2221 if (REG_BASIC_BLOCK (regno) == REG_BLOCK_UNKNOWN)
2222 REG_BASIC_BLOCK (regno) = blocknum;
2223 else if (REG_BASIC_BLOCK (regno) != blocknum)
2224 REG_BASIC_BLOCK (regno) = REG_BLOCK_GLOBAL;
2226 /* Count (weighted) references, stores, etc. This counts a
2227 register twice if it is modified, but that is correct. */
2228 REG_N_SETS (regno)++;
2230 REG_N_REFS (regno) += loop_depth;
2232 /* The insns where a reg is live are normally counted
2233 elsewhere, but we want the count to include the insn
2234 where the reg is set, and the normal counting mechanism
2235 would not count it. */
2236 REG_LIVE_LENGTH (regno)++;
2239 if (! some_not_needed)
2241 /* Make a logical link from the next following insn
2242 that uses this register, back to this insn.
2243 The following insns have already been processed.
2245 We don't build a LOG_LINK for hard registers containing
2246 in ASM_OPERANDs. If these registers get replaced,
2247 we might wind up changing the semantics of the insn,
2248 even if reload can make what appear to be valid assignments
2249 later. */
2250 if (y && (BLOCK_NUM (y) == blocknum)
2251 && (regno >= FIRST_PSEUDO_REGISTER
2252 || asm_noperands (PATTERN (y)) < 0))
2253 LOG_LINKS (y)
2254 = gen_rtx_INSN_LIST (VOIDmode, insn, LOG_LINKS (y));
2256 else if (! some_needed)
2258 /* Note that dead stores have already been deleted when possible
2259 If we get here, we have found a dead store that cannot
2260 be eliminated (because the same insn does something useful).
2261 Indicate this by marking the reg being set as dying here. */
2262 REG_NOTES (insn)
2263 = gen_rtx_EXPR_LIST (REG_UNUSED, reg, REG_NOTES (insn));
2264 REG_N_DEATHS (REGNO (reg))++;
2266 else
2268 /* This is a case where we have a multi-word hard register
2269 and some, but not all, of the words of the register are
2270 needed in subsequent insns. Write REG_UNUSED notes
2271 for those parts that were not needed. This case should
2272 be rare. */
2274 int i;
2276 for (i = HARD_REGNO_NREGS (regno, GET_MODE (reg)) - 1;
2277 i >= 0; i--)
2278 if (!REGNO_REG_SET_P (needed, regno + i))
2279 REG_NOTES (insn)
2280 = gen_rtx_EXPR_LIST (REG_UNUSED,
2281 gen_rtx_REG (reg_raw_mode[regno + i],
2282 regno + i),
2283 REG_NOTES (insn));
2287 else if (GET_CODE (reg) == REG)
2288 reg_next_use[regno] = 0;
2290 /* If this is the last pass and this is a SCRATCH, show it will be dying
2291 here and count it. */
2292 else if (GET_CODE (reg) == SCRATCH && insn != 0)
2294 REG_NOTES (insn)
2295 = gen_rtx_EXPR_LIST (REG_UNUSED, reg, REG_NOTES (insn));
2296 num_scratch++;
2300 #ifdef AUTO_INC_DEC
2302 /* X is a MEM found in INSN. See if we can convert it into an auto-increment
2303 reference. */
2305 static void
2306 find_auto_inc (needed, x, insn)
2307 regset needed;
2308 rtx x;
2309 rtx insn;
2311 rtx addr = XEXP (x, 0);
2312 HOST_WIDE_INT offset = 0;
2313 rtx set;
2315 /* Here we detect use of an index register which might be good for
2316 postincrement, postdecrement, preincrement, or predecrement. */
2318 if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2319 offset = INTVAL (XEXP (addr, 1)), addr = XEXP (addr, 0);
2321 if (GET_CODE (addr) == REG)
2323 register rtx y;
2324 register int size = GET_MODE_SIZE (GET_MODE (x));
2325 rtx use;
2326 rtx incr;
2327 int regno = REGNO (addr);
2329 /* Is the next use an increment that might make auto-increment? */
2330 if ((incr = reg_next_use[regno]) != 0
2331 && (set = single_set (incr)) != 0
2332 && GET_CODE (set) == SET
2333 && BLOCK_NUM (incr) == BLOCK_NUM (insn)
2334 /* Can't add side effects to jumps; if reg is spilled and
2335 reloaded, there's no way to store back the altered value. */
2336 && GET_CODE (insn) != JUMP_INSN
2337 && (y = SET_SRC (set), GET_CODE (y) == PLUS)
2338 && XEXP (y, 0) == addr
2339 && GET_CODE (XEXP (y, 1)) == CONST_INT
2340 && (0
2341 #ifdef HAVE_POST_INCREMENT
2342 || (INTVAL (XEXP (y, 1)) == size && offset == 0)
2343 #endif
2344 #ifdef HAVE_POST_DECREMENT
2345 || (INTVAL (XEXP (y, 1)) == - size && offset == 0)
2346 #endif
2347 #ifdef HAVE_PRE_INCREMENT
2348 || (INTVAL (XEXP (y, 1)) == size && offset == size)
2349 #endif
2350 #ifdef HAVE_PRE_DECREMENT
2351 || (INTVAL (XEXP (y, 1)) == - size && offset == - size)
2352 #endif
2354 /* Make sure this reg appears only once in this insn. */
2355 && (use = find_use_as_address (PATTERN (insn), addr, offset),
2356 use != 0 && use != (rtx) 1))
2358 rtx q = SET_DEST (set);
2359 enum rtx_code inc_code = (INTVAL (XEXP (y, 1)) == size
2360 ? (offset ? PRE_INC : POST_INC)
2361 : (offset ? PRE_DEC : POST_DEC));
2363 if (dead_or_set_p (incr, addr))
2365 /* This is the simple case. Try to make the auto-inc. If
2366 we can't, we are done. Otherwise, we will do any
2367 needed updates below. */
2368 if (! validate_change (insn, &XEXP (x, 0),
2369 gen_rtx_fmt_e (inc_code, Pmode, addr),
2371 return;
2373 else if (GET_CODE (q) == REG
2374 /* PREV_INSN used here to check the semi-open interval
2375 [insn,incr). */
2376 && ! reg_used_between_p (q, PREV_INSN (insn), incr)
2377 /* We must also check for sets of q as q may be
2378 a call clobbered hard register and there may
2379 be a call between PREV_INSN (insn) and incr. */
2380 && ! reg_set_between_p (q, PREV_INSN (insn), incr))
2382 /* We have *p followed sometime later by q = p+size.
2383 Both p and q must be live afterward,
2384 and q is not used between INSN and its assignment.
2385 Change it to q = p, ...*q..., q = q+size.
2386 Then fall into the usual case. */
2387 rtx insns, temp;
2389 start_sequence ();
2390 emit_move_insn (q, addr);
2391 insns = get_insns ();
2392 end_sequence ();
2394 /* If anything in INSNS have UID's that don't fit within the
2395 extra space we allocate earlier, we can't make this auto-inc.
2396 This should never happen. */
2397 for (temp = insns; temp; temp = NEXT_INSN (temp))
2399 if (INSN_UID (temp) > max_uid_for_flow)
2400 return;
2401 BLOCK_NUM (temp) = BLOCK_NUM (insn);
2404 /* If we can't make the auto-inc, or can't make the
2405 replacement into Y, exit. There's no point in making
2406 the change below if we can't do the auto-inc and doing
2407 so is not correct in the pre-inc case. */
2409 validate_change (insn, &XEXP (x, 0),
2410 gen_rtx_fmt_e (inc_code, Pmode, q),
2412 validate_change (incr, &XEXP (y, 0), q, 1);
2413 if (! apply_change_group ())
2414 return;
2416 /* We now know we'll be doing this change, so emit the
2417 new insn(s) and do the updates. */
2418 emit_insns_before (insns, insn);
2420 if (basic_block_head[BLOCK_NUM (insn)] == insn)
2421 basic_block_head[BLOCK_NUM (insn)] = insns;
2423 /* INCR will become a NOTE and INSN won't contain a
2424 use of ADDR. If a use of ADDR was just placed in
2425 the insn before INSN, make that the next use.
2426 Otherwise, invalidate it. */
2427 if (GET_CODE (PREV_INSN (insn)) == INSN
2428 && GET_CODE (PATTERN (PREV_INSN (insn))) == SET
2429 && SET_SRC (PATTERN (PREV_INSN (insn))) == addr)
2430 reg_next_use[regno] = PREV_INSN (insn);
2431 else
2432 reg_next_use[regno] = 0;
2434 addr = q;
2435 regno = REGNO (q);
2437 /* REGNO is now used in INCR which is below INSN, but
2438 it previously wasn't live here. If we don't mark
2439 it as needed, we'll put a REG_DEAD note for it
2440 on this insn, which is incorrect. */
2441 SET_REGNO_REG_SET (needed, regno);
2443 /* If there are any calls between INSN and INCR, show
2444 that REGNO now crosses them. */
2445 for (temp = insn; temp != incr; temp = NEXT_INSN (temp))
2446 if (GET_CODE (temp) == CALL_INSN)
2447 REG_N_CALLS_CROSSED (regno)++;
2449 else
2450 return;
2452 /* If we haven't returned, it means we were able to make the
2453 auto-inc, so update the status. First, record that this insn
2454 has an implicit side effect. */
2456 REG_NOTES (insn)
2457 = gen_rtx_EXPR_LIST (REG_INC, addr, REG_NOTES (insn));
2459 /* Modify the old increment-insn to simply copy
2460 the already-incremented value of our register. */
2461 if (! validate_change (incr, &SET_SRC (set), addr, 0))
2462 abort ();
2464 /* If that makes it a no-op (copying the register into itself) delete
2465 it so it won't appear to be a "use" and a "set" of this
2466 register. */
2467 if (SET_DEST (set) == addr)
2469 PUT_CODE (incr, NOTE);
2470 NOTE_LINE_NUMBER (incr) = NOTE_INSN_DELETED;
2471 NOTE_SOURCE_FILE (incr) = 0;
2474 if (regno >= FIRST_PSEUDO_REGISTER)
2476 /* Count an extra reference to the reg. When a reg is
2477 incremented, spilling it is worse, so we want to make
2478 that less likely. */
2479 REG_N_REFS (regno) += loop_depth;
2481 /* Count the increment as a setting of the register,
2482 even though it isn't a SET in rtl. */
2483 REG_N_SETS (regno)++;
2488 #endif /* AUTO_INC_DEC */
2490 /* Scan expression X and store a 1-bit in LIVE for each reg it uses.
2491 This is done assuming the registers needed from X
2492 are those that have 1-bits in NEEDED.
2494 On the final pass, FINAL is 1. This means try for autoincrement
2495 and count the uses and deaths of each pseudo-reg.
2497 INSN is the containing instruction. If INSN is dead, this function is not
2498 called. */
2500 static void
2501 mark_used_regs (needed, live, x, final, insn)
2502 regset needed;
2503 regset live;
2504 rtx x;
2505 int final;
2506 rtx insn;
2508 register RTX_CODE code;
2509 register int regno;
2510 int i;
2512 retry:
2513 code = GET_CODE (x);
2514 switch (code)
2516 case LABEL_REF:
2517 case SYMBOL_REF:
2518 case CONST_INT:
2519 case CONST:
2520 case CONST_DOUBLE:
2521 case PC:
2522 case ADDR_VEC:
2523 case ADDR_DIFF_VEC:
2524 case ASM_INPUT:
2525 return;
2527 #ifdef HAVE_cc0
2528 case CC0:
2529 cc0_live = 1;
2530 return;
2531 #endif
2533 case CLOBBER:
2534 /* If we are clobbering a MEM, mark any registers inside the address
2535 as being used. */
2536 if (GET_CODE (XEXP (x, 0)) == MEM)
2537 mark_used_regs (needed, live, XEXP (XEXP (x, 0), 0), final, insn);
2538 return;
2540 case MEM:
2541 /* Invalidate the data for the last MEM stored, but only if MEM is
2542 something that can be stored into. */
2543 if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
2544 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
2545 ; /* needn't clear last_mem_set */
2546 else
2547 last_mem_set = 0;
2549 #ifdef AUTO_INC_DEC
2550 if (final)
2551 find_auto_inc (needed, x, insn);
2552 #endif
2553 break;
2555 case SUBREG:
2556 if (GET_CODE (SUBREG_REG (x)) == REG
2557 && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER
2558 && (GET_MODE_SIZE (GET_MODE (x))
2559 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
2560 REG_CHANGES_SIZE (REGNO (SUBREG_REG (x))) = 1;
2562 /* While we're here, optimize this case. */
2563 x = SUBREG_REG (x);
2565 /* In case the SUBREG is not of a register, don't optimize */
2566 if (GET_CODE (x) != REG)
2568 mark_used_regs (needed, live, x, final, insn);
2569 return;
2572 /* ... fall through ... */
2574 case REG:
2575 /* See a register other than being set
2576 => mark it as needed. */
2578 regno = REGNO (x);
2580 int some_needed = REGNO_REG_SET_P (needed, regno);
2581 int some_not_needed = ! some_needed;
2583 SET_REGNO_REG_SET (live, regno);
2585 /* A hard reg in a wide mode may really be multiple registers.
2586 If so, mark all of them just like the first. */
2587 if (regno < FIRST_PSEUDO_REGISTER)
2589 int n;
2591 /* For stack ptr or fixed arg pointer,
2592 nothing below can be necessary, so waste no more time. */
2593 if (regno == STACK_POINTER_REGNUM
2594 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2595 || regno == HARD_FRAME_POINTER_REGNUM
2596 #endif
2597 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2598 || (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
2599 #endif
2600 || regno == FRAME_POINTER_REGNUM)
2602 /* If this is a register we are going to try to eliminate,
2603 don't mark it live here. If we are successful in
2604 eliminating it, it need not be live unless it is used for
2605 pseudos, in which case it will have been set live when
2606 it was allocated to the pseudos. If the register will not
2607 be eliminated, reload will set it live at that point. */
2609 if (! TEST_HARD_REG_BIT (elim_reg_set, regno))
2610 regs_ever_live[regno] = 1;
2611 return;
2613 /* No death notes for global register variables;
2614 their values are live after this function exits. */
2615 if (global_regs[regno])
2617 if (final)
2618 reg_next_use[regno] = insn;
2619 return;
2622 n = HARD_REGNO_NREGS (regno, GET_MODE (x));
2623 while (--n > 0)
2625 int regno_n = regno + n;
2626 int needed_regno = REGNO_REG_SET_P (needed, regno_n);
2628 SET_REGNO_REG_SET (live, regno_n);
2629 some_needed |= needed_regno;
2630 some_not_needed |= ! needed_regno;
2633 if (final)
2635 /* Record where each reg is used, so when the reg
2636 is set we know the next insn that uses it. */
2638 reg_next_use[regno] = insn;
2640 if (regno < FIRST_PSEUDO_REGISTER)
2642 /* If a hard reg is being used,
2643 record that this function does use it. */
2645 i = HARD_REGNO_NREGS (regno, GET_MODE (x));
2646 if (i == 0)
2647 i = 1;
2649 regs_ever_live[regno + --i] = 1;
2650 while (i > 0);
2652 else
2654 /* Keep track of which basic block each reg appears in. */
2656 register int blocknum = BLOCK_NUM (insn);
2658 if (REG_BASIC_BLOCK (regno) == REG_BLOCK_UNKNOWN)
2659 REG_BASIC_BLOCK (regno) = blocknum;
2660 else if (REG_BASIC_BLOCK (regno) != blocknum)
2661 REG_BASIC_BLOCK (regno) = REG_BLOCK_GLOBAL;
2663 /* Count (weighted) number of uses of each reg. */
2665 REG_N_REFS (regno) += loop_depth;
2668 /* Record and count the insns in which a reg dies.
2669 If it is used in this insn and was dead below the insn
2670 then it dies in this insn. If it was set in this insn,
2671 we do not make a REG_DEAD note; likewise if we already
2672 made such a note. */
2674 if (some_not_needed
2675 && ! dead_or_set_p (insn, x)
2676 #if 0
2677 && (regno >= FIRST_PSEUDO_REGISTER || ! fixed_regs[regno])
2678 #endif
2681 /* Check for the case where the register dying partially
2682 overlaps the register set by this insn. */
2683 if (regno < FIRST_PSEUDO_REGISTER
2684 && HARD_REGNO_NREGS (regno, GET_MODE (x)) > 1)
2686 int n = HARD_REGNO_NREGS (regno, GET_MODE (x));
2687 while (--n >= 0)
2688 some_needed |= dead_or_set_regno_p (insn, regno + n);
2691 /* If none of the words in X is needed, make a REG_DEAD
2692 note. Otherwise, we must make partial REG_DEAD notes. */
2693 if (! some_needed)
2695 REG_NOTES (insn)
2696 = gen_rtx_EXPR_LIST (REG_DEAD, x, REG_NOTES (insn));
2697 REG_N_DEATHS (regno)++;
2699 else
2701 int i;
2703 /* Don't make a REG_DEAD note for a part of a register
2704 that is set in the insn. */
2706 for (i = HARD_REGNO_NREGS (regno, GET_MODE (x)) - 1;
2707 i >= 0; i--)
2708 if (!REGNO_REG_SET_P (needed, regno + i)
2709 && ! dead_or_set_regno_p (insn, regno + i))
2710 REG_NOTES (insn)
2711 = gen_rtx_EXPR_LIST (REG_DEAD,
2712 gen_rtx_REG (reg_raw_mode[regno + i],
2713 regno + i),
2714 REG_NOTES (insn));
2719 return;
2721 case SET:
2723 register rtx testreg = SET_DEST (x);
2724 int mark_dest = 0;
2726 /* If storing into MEM, don't show it as being used. But do
2727 show the address as being used. */
2728 if (GET_CODE (testreg) == MEM)
2730 #ifdef AUTO_INC_DEC
2731 if (final)
2732 find_auto_inc (needed, testreg, insn);
2733 #endif
2734 mark_used_regs (needed, live, XEXP (testreg, 0), final, insn);
2735 mark_used_regs (needed, live, SET_SRC (x), final, insn);
2736 return;
2739 /* Storing in STRICT_LOW_PART is like storing in a reg
2740 in that this SET might be dead, so ignore it in TESTREG.
2741 but in some other ways it is like using the reg.
2743 Storing in a SUBREG or a bit field is like storing the entire
2744 register in that if the register's value is not used
2745 then this SET is not needed. */
2746 while (GET_CODE (testreg) == STRICT_LOW_PART
2747 || GET_CODE (testreg) == ZERO_EXTRACT
2748 || GET_CODE (testreg) == SIGN_EXTRACT
2749 || GET_CODE (testreg) == SUBREG)
2751 if (GET_CODE (testreg) == SUBREG
2752 && GET_CODE (SUBREG_REG (testreg)) == REG
2753 && REGNO (SUBREG_REG (testreg)) >= FIRST_PSEUDO_REGISTER
2754 && (GET_MODE_SIZE (GET_MODE (testreg))
2755 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (testreg)))))
2756 REG_CHANGES_SIZE (REGNO (SUBREG_REG (testreg))) = 1;
2758 /* Modifying a single register in an alternate mode
2759 does not use any of the old value. But these other
2760 ways of storing in a register do use the old value. */
2761 if (GET_CODE (testreg) == SUBREG
2762 && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
2764 else
2765 mark_dest = 1;
2767 testreg = XEXP (testreg, 0);
2770 /* If this is a store into a register,
2771 recursively scan the value being stored. */
2773 if (GET_CODE (testreg) == REG
2774 && (regno = REGNO (testreg), regno != FRAME_POINTER_REGNUM)
2775 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2776 && regno != HARD_FRAME_POINTER_REGNUM
2777 #endif
2778 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2779 && ! (regno == ARG_POINTER_REGNUM && fixed_regs[regno])
2780 #endif
2782 /* We used to exclude global_regs here, but that seems wrong.
2783 Storing in them is like storing in mem. */
2785 mark_used_regs (needed, live, SET_SRC (x), final, insn);
2786 if (mark_dest)
2787 mark_used_regs (needed, live, SET_DEST (x), final, insn);
2788 return;
2791 break;
2793 case RETURN:
2794 /* If exiting needs the right stack value, consider this insn as
2795 using the stack pointer. In any event, consider it as using
2796 all global registers and all registers used by return. */
2798 #ifdef EXIT_IGNORE_STACK
2799 if (! EXIT_IGNORE_STACK
2800 || (! FRAME_POINTER_REQUIRED
2801 && ! current_function_calls_alloca
2802 && flag_omit_frame_pointer))
2803 #endif
2804 SET_REGNO_REG_SET (live, STACK_POINTER_REGNUM);
2806 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2807 if (global_regs[i]
2808 #ifdef EPILOGUE_USES
2809 || EPILOGUE_USES (i)
2810 #endif
2812 SET_REGNO_REG_SET (live, i);
2813 break;
2815 default:
2816 break;
2819 /* Recursively scan the operands of this expression. */
2822 register char *fmt = GET_RTX_FORMAT (code);
2823 register int i;
2825 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2827 if (fmt[i] == 'e')
2829 /* Tail recursive case: save a function call level. */
2830 if (i == 0)
2832 x = XEXP (x, 0);
2833 goto retry;
2835 mark_used_regs (needed, live, XEXP (x, i), final, insn);
2837 else if (fmt[i] == 'E')
2839 register int j;
2840 for (j = 0; j < XVECLEN (x, i); j++)
2841 mark_used_regs (needed, live, XVECEXP (x, i, j), final, insn);
2847 #ifdef AUTO_INC_DEC
2849 static int
2850 try_pre_increment_1 (insn)
2851 rtx insn;
2853 /* Find the next use of this reg. If in same basic block,
2854 make it do pre-increment or pre-decrement if appropriate. */
2855 rtx x = single_set (insn);
2856 HOST_WIDE_INT amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1)
2857 * INTVAL (XEXP (SET_SRC (x), 1)));
2858 int regno = REGNO (SET_DEST (x));
2859 rtx y = reg_next_use[regno];
2860 if (y != 0
2861 && BLOCK_NUM (y) == BLOCK_NUM (insn)
2862 /* Don't do this if the reg dies, or gets set in y; a standard addressing
2863 mode would be better. */
2864 && ! dead_or_set_p (y, SET_DEST (x))
2865 && try_pre_increment (y, SET_DEST (x), amount))
2867 /* We have found a suitable auto-increment
2868 and already changed insn Y to do it.
2869 So flush this increment-instruction. */
2870 PUT_CODE (insn, NOTE);
2871 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2872 NOTE_SOURCE_FILE (insn) = 0;
2873 /* Count a reference to this reg for the increment
2874 insn we are deleting. When a reg is incremented.
2875 spilling it is worse, so we want to make that
2876 less likely. */
2877 if (regno >= FIRST_PSEUDO_REGISTER)
2879 REG_N_REFS (regno) += loop_depth;
2880 REG_N_SETS (regno)++;
2882 return 1;
2884 return 0;
2887 /* Try to change INSN so that it does pre-increment or pre-decrement
2888 addressing on register REG in order to add AMOUNT to REG.
2889 AMOUNT is negative for pre-decrement.
2890 Returns 1 if the change could be made.
2891 This checks all about the validity of the result of modifying INSN. */
2893 static int
2894 try_pre_increment (insn, reg, amount)
2895 rtx insn, reg;
2896 HOST_WIDE_INT amount;
2898 register rtx use;
2900 /* Nonzero if we can try to make a pre-increment or pre-decrement.
2901 For example, addl $4,r1; movl (r1),... can become movl +(r1),... */
2902 int pre_ok = 0;
2903 /* Nonzero if we can try to make a post-increment or post-decrement.
2904 For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,...
2905 It is possible for both PRE_OK and POST_OK to be nonzero if the machine
2906 supports both pre-inc and post-inc, or both pre-dec and post-dec. */
2907 int post_ok = 0;
2909 /* Nonzero if the opportunity actually requires post-inc or post-dec. */
2910 int do_post = 0;
2912 /* From the sign of increment, see which possibilities are conceivable
2913 on this target machine. */
2914 #ifdef HAVE_PRE_INCREMENT
2915 if (amount > 0)
2916 pre_ok = 1;
2917 #endif
2918 #ifdef HAVE_POST_INCREMENT
2919 if (amount > 0)
2920 post_ok = 1;
2921 #endif
2923 #ifdef HAVE_PRE_DECREMENT
2924 if (amount < 0)
2925 pre_ok = 1;
2926 #endif
2927 #ifdef HAVE_POST_DECREMENT
2928 if (amount < 0)
2929 post_ok = 1;
2930 #endif
2932 if (! (pre_ok || post_ok))
2933 return 0;
2935 /* It is not safe to add a side effect to a jump insn
2936 because if the incremented register is spilled and must be reloaded
2937 there would be no way to store the incremented value back in memory. */
2939 if (GET_CODE (insn) == JUMP_INSN)
2940 return 0;
2942 use = 0;
2943 if (pre_ok)
2944 use = find_use_as_address (PATTERN (insn), reg, 0);
2945 if (post_ok && (use == 0 || use == (rtx) 1))
2947 use = find_use_as_address (PATTERN (insn), reg, -amount);
2948 do_post = 1;
2951 if (use == 0 || use == (rtx) 1)
2952 return 0;
2954 if (GET_MODE_SIZE (GET_MODE (use)) != (amount > 0 ? amount : - amount))
2955 return 0;
2957 /* See if this combination of instruction and addressing mode exists. */
2958 if (! validate_change (insn, &XEXP (use, 0),
2959 gen_rtx_fmt_e (amount > 0
2960 ? (do_post ? POST_INC : PRE_INC)
2961 : (do_post ? POST_DEC : PRE_DEC),
2962 Pmode, reg), 0))
2963 return 0;
2965 /* Record that this insn now has an implicit side effect on X. */
2966 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_INC, reg, REG_NOTES (insn));
2967 return 1;
2970 #endif /* AUTO_INC_DEC */
2972 /* Find the place in the rtx X where REG is used as a memory address.
2973 Return the MEM rtx that so uses it.
2974 If PLUSCONST is nonzero, search instead for a memory address equivalent to
2975 (plus REG (const_int PLUSCONST)).
2977 If such an address does not appear, return 0.
2978 If REG appears more than once, or is used other than in such an address,
2979 return (rtx)1. */
2982 find_use_as_address (x, reg, plusconst)
2983 register rtx x;
2984 rtx reg;
2985 HOST_WIDE_INT plusconst;
2987 enum rtx_code code = GET_CODE (x);
2988 char *fmt = GET_RTX_FORMAT (code);
2989 register int i;
2990 register rtx value = 0;
2991 register rtx tem;
2993 if (code == MEM && XEXP (x, 0) == reg && plusconst == 0)
2994 return x;
2996 if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS
2997 && XEXP (XEXP (x, 0), 0) == reg
2998 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2999 && INTVAL (XEXP (XEXP (x, 0), 1)) == plusconst)
3000 return x;
3002 if (code == SIGN_EXTRACT || code == ZERO_EXTRACT)
3004 /* If REG occurs inside a MEM used in a bit-field reference,
3005 that is unacceptable. */
3006 if (find_use_as_address (XEXP (x, 0), reg, 0) != 0)
3007 return (rtx) (HOST_WIDE_INT) 1;
3010 if (x == reg)
3011 return (rtx) (HOST_WIDE_INT) 1;
3013 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3015 if (fmt[i] == 'e')
3017 tem = find_use_as_address (XEXP (x, i), reg, plusconst);
3018 if (value == 0)
3019 value = tem;
3020 else if (tem != 0)
3021 return (rtx) (HOST_WIDE_INT) 1;
3023 if (fmt[i] == 'E')
3025 register int j;
3026 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3028 tem = find_use_as_address (XVECEXP (x, i, j), reg, plusconst);
3029 if (value == 0)
3030 value = tem;
3031 else if (tem != 0)
3032 return (rtx) (HOST_WIDE_INT) 1;
3037 return value;
3040 /* Write information about registers and basic blocks into FILE.
3041 This is part of making a debugging dump. */
3043 void
3044 dump_flow_info (file)
3045 FILE *file;
3047 register int i;
3048 static char *reg_class_names[] = REG_CLASS_NAMES;
3050 fprintf (file, "%d registers.\n", max_regno);
3052 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
3053 if (REG_N_REFS (i))
3055 enum reg_class class, altclass;
3056 fprintf (file, "\nRegister %d used %d times across %d insns",
3057 i, REG_N_REFS (i), REG_LIVE_LENGTH (i));
3058 if (REG_BASIC_BLOCK (i) >= 0)
3059 fprintf (file, " in block %d", REG_BASIC_BLOCK (i));
3060 if (REG_N_SETS (i))
3061 fprintf (file, "; set %d time%s", REG_N_SETS (i),
3062 (REG_N_SETS (i) == 1) ? "" : "s");
3063 if (REG_USERVAR_P (regno_reg_rtx[i]))
3064 fprintf (file, "; user var");
3065 if (REG_N_DEATHS (i) != 1)
3066 fprintf (file, "; dies in %d places", REG_N_DEATHS (i));
3067 if (REG_N_CALLS_CROSSED (i) == 1)
3068 fprintf (file, "; crosses 1 call");
3069 else if (REG_N_CALLS_CROSSED (i))
3070 fprintf (file, "; crosses %d calls", REG_N_CALLS_CROSSED (i));
3071 if (PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD)
3072 fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i));
3073 class = reg_preferred_class (i);
3074 altclass = reg_alternate_class (i);
3075 if (class != GENERAL_REGS || altclass != ALL_REGS)
3077 if (altclass == ALL_REGS || class == ALL_REGS)
3078 fprintf (file, "; pref %s", reg_class_names[(int) class]);
3079 else if (altclass == NO_REGS)
3080 fprintf (file, "; %s or none", reg_class_names[(int) class]);
3081 else
3082 fprintf (file, "; pref %s, else %s",
3083 reg_class_names[(int) class],
3084 reg_class_names[(int) altclass]);
3086 if (REGNO_POINTER_FLAG (i))
3087 fprintf (file, "; pointer");
3088 fprintf (file, ".\n");
3090 fprintf (file, "\n%d basic blocks.\n", n_basic_blocks);
3091 for (i = 0; i < n_basic_blocks; i++)
3093 register rtx head, jump;
3094 register int regno;
3095 fprintf (file, "\nBasic block %d: first insn %d, last %d.\n",
3097 INSN_UID (basic_block_head[i]),
3098 INSN_UID (basic_block_end[i]));
3099 /* The control flow graph's storage is freed
3100 now when flow_analysis returns.
3101 Don't try to print it if it is gone. */
3102 if (basic_block_drops_in)
3104 fprintf (file, "Reached from blocks: ");
3105 head = basic_block_head[i];
3106 if (GET_CODE (head) == CODE_LABEL)
3107 for (jump = LABEL_REFS (head);
3108 jump != head;
3109 jump = LABEL_NEXTREF (jump))
3111 register int from_block = BLOCK_NUM (CONTAINING_INSN (jump));
3112 fprintf (file, " %d", from_block);
3114 if (basic_block_drops_in[i])
3115 fprintf (file, " previous");
3117 fprintf (file, "\nRegisters live at start:");
3118 for (regno = 0; regno < max_regno; regno++)
3119 if (REGNO_REG_SET_P (basic_block_live_at_start[i], regno))
3120 fprintf (file, " %d", regno);
3121 fprintf (file, "\n");
3123 fprintf (file, "\n");
3127 /* Like print_rtl, but also print out live information for the start of each
3128 basic block. */
3130 void
3131 print_rtl_with_bb (outf, rtx_first)
3132 FILE *outf;
3133 rtx rtx_first;
3135 extern int flag_dump_unnumbered;
3136 register rtx tmp_rtx;
3138 if (rtx_first == 0)
3139 fprintf (outf, "(nil)\n");
3141 else
3143 int i, bb;
3144 enum bb_state { NOT_IN_BB, IN_ONE_BB, IN_MULTIPLE_BB };
3145 int max_uid = get_max_uid ();
3146 int *start = (int *) alloca (max_uid * sizeof (int));
3147 int *end = (int *) alloca (max_uid * sizeof (int));
3148 char *in_bb_p = (char *) alloca (max_uid * sizeof (enum bb_state));
3150 for (i = 0; i < max_uid; i++)
3152 start[i] = end[i] = -1;
3153 in_bb_p[i] = NOT_IN_BB;
3156 for (i = n_basic_blocks-1; i >= 0; i--)
3158 rtx x;
3159 start[INSN_UID (basic_block_head[i])] = i;
3160 end[INSN_UID (basic_block_end[i])] = i;
3161 for (x = basic_block_head[i]; x != NULL_RTX; x = NEXT_INSN (x))
3163 in_bb_p[ INSN_UID(x)]
3164 = (in_bb_p[ INSN_UID(x)] == NOT_IN_BB)
3165 ? IN_ONE_BB : IN_MULTIPLE_BB;
3166 if (x == basic_block_end[i])
3167 break;
3171 for (tmp_rtx = rtx_first; NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx))
3173 if ((bb = start[INSN_UID (tmp_rtx)]) >= 0)
3175 fprintf (outf, ";; Start of basic block %d, registers live:",
3176 bb);
3178 EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[bb], 0, i,
3180 fprintf (outf, " %d", i);
3181 if (i < FIRST_PSEUDO_REGISTER)
3182 fprintf (outf, " [%s]",
3183 reg_names[i]);
3185 putc ('\n', outf);
3188 if (in_bb_p[ INSN_UID(tmp_rtx)] == NOT_IN_BB
3189 && GET_CODE (tmp_rtx) != NOTE
3190 && GET_CODE (tmp_rtx) != BARRIER)
3191 fprintf (outf, ";; Insn is not within a basic block\n");
3192 else if (in_bb_p[ INSN_UID(tmp_rtx)] == IN_MULTIPLE_BB)
3193 fprintf (outf, ";; Insn is in multiple basic blocks\n");
3195 print_rtl_single (outf, tmp_rtx);
3197 if ((bb = end[INSN_UID (tmp_rtx)]) >= 0)
3198 fprintf (outf, ";; End of basic block %d\n", bb);
3200 if (! flag_dump_unnumbered
3201 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
3202 putc ('\n', outf);
3208 /* Integer list support. */
3210 /* Allocate a node from list *HEAD_PTR. */
3212 static int_list_ptr
3213 alloc_int_list_node (head_ptr)
3214 int_list_block **head_ptr;
3216 struct int_list_block *first_blk = *head_ptr;
3218 if (first_blk == NULL || first_blk->nodes_left <= 0)
3220 first_blk = (struct int_list_block *) xmalloc (sizeof (struct int_list_block));
3221 first_blk->nodes_left = INT_LIST_NODES_IN_BLK;
3222 first_blk->next = *head_ptr;
3223 *head_ptr = first_blk;
3226 first_blk->nodes_left--;
3227 return &first_blk->nodes[first_blk->nodes_left];
3230 /* Pointer to head of predecessor/successor block list. */
3231 static int_list_block *pred_int_list_blocks;
3233 /* Add a new node to integer list LIST with value VAL.
3234 LIST is a pointer to a list object to allow for different implementations.
3235 If *LIST is initially NULL, the list is empty.
3236 The caller must not care whether the element is added to the front or
3237 to the end of the list (to allow for different implementations). */
3239 static int_list_ptr
3240 add_int_list_node (blk_list, list, val)
3241 int_list_block **blk_list;
3242 int_list **list;
3243 int val;
3245 int_list_ptr p = alloc_int_list_node (blk_list);
3247 p->val = val;
3248 p->next = *list;
3249 *list = p;
3250 return p;
3253 /* Free the blocks of lists at BLK_LIST. */
3255 void
3256 free_int_list (blk_list)
3257 int_list_block **blk_list;
3259 int_list_block *p, *next;
3261 for (p = *blk_list; p != NULL; p = next)
3263 next = p->next;
3264 free (p);
3267 /* Mark list as empty for the next function we compile. */
3268 *blk_list = NULL;
3271 /* Predecessor/successor computation. */
3273 /* Mark PRED_BB a precessor of SUCC_BB,
3274 and conversely SUCC_BB a successor of PRED_BB. */
3276 static void
3277 add_pred_succ (pred_bb, succ_bb, s_preds, s_succs, num_preds, num_succs)
3278 int pred_bb;
3279 int succ_bb;
3280 int_list_ptr *s_preds;
3281 int_list_ptr *s_succs;
3282 int *num_preds;
3283 int *num_succs;
3285 if (succ_bb != EXIT_BLOCK)
3287 add_int_list_node (&pred_int_list_blocks, &s_preds[succ_bb], pred_bb);
3288 num_preds[succ_bb]++;
3290 if (pred_bb != ENTRY_BLOCK)
3292 add_int_list_node (&pred_int_list_blocks, &s_succs[pred_bb], succ_bb);
3293 num_succs[pred_bb]++;
3297 /* Compute the predecessors and successors for each block. */
3298 void
3299 compute_preds_succs (s_preds, s_succs, num_preds, num_succs)
3300 int_list_ptr *s_preds;
3301 int_list_ptr *s_succs;
3302 int *num_preds;
3303 int *num_succs;
3305 int bb, clear_local_bb_vars = 0;
3307 bzero ((char *) s_preds, n_basic_blocks * sizeof (int_list_ptr));
3308 bzero ((char *) s_succs, n_basic_blocks * sizeof (int_list_ptr));
3309 bzero ((char *) num_preds, n_basic_blocks * sizeof (int));
3310 bzero ((char *) num_succs, n_basic_blocks * sizeof (int));
3312 /* This routine can be called after life analysis; in that case
3313 basic_block_drops_in and uid_block_number will not be available
3314 and we must recompute their values. */
3315 if (basic_block_drops_in == NULL || uid_block_number == NULL)
3317 clear_local_bb_vars = 1;
3318 basic_block_drops_in = (char *) alloca (n_basic_blocks);
3319 uid_block_number = (int *) alloca ((get_max_uid () + 1) * sizeof (int));
3321 bzero ((char *) basic_block_drops_in, n_basic_blocks * sizeof (char));
3322 bzero ((char *) uid_block_number, n_basic_blocks * sizeof (int));
3324 /* Scan each basic block setting basic_block_drops_in and
3325 uid_block_number as needed. */
3326 for (bb = 0; bb < n_basic_blocks; bb++)
3328 rtx insn, stop_insn;
3330 if (bb == 0)
3331 stop_insn = NULL_RTX;
3332 else
3333 stop_insn = basic_block_end[bb-1];
3335 /* Look backwards from the start of this block. Stop if we
3336 hit the start of the function or the end of a previous
3337 block. Don't walk backwards through blocks that are just
3338 deleted insns! */
3339 for (insn = PREV_INSN (basic_block_head[bb]);
3340 insn && insn != stop_insn && GET_CODE (insn) == NOTE;
3341 insn = PREV_INSN (insn))
3344 /* Never set basic_block_drops_in for the first block. It is
3345 implicit.
3347 If we stopped on anything other than a BARRIER, then this
3348 block drops in. */
3349 if (bb != 0)
3350 basic_block_drops_in[bb] = (insn ? GET_CODE (insn) != BARRIER : 1);
3352 insn = basic_block_head[bb];
3353 while (insn)
3355 BLOCK_NUM (insn) = bb;
3356 if (insn == basic_block_end[bb])
3357 break;
3358 insn = NEXT_INSN (insn);
3363 for (bb = 0; bb < n_basic_blocks; bb++)
3365 rtx head;
3366 rtx jump;
3368 head = BLOCK_HEAD (bb);
3370 if (GET_CODE (head) == CODE_LABEL)
3371 for (jump = LABEL_REFS (head);
3372 jump != head;
3373 jump = LABEL_NEXTREF (jump))
3375 if (! INSN_DELETED_P (CONTAINING_INSN (jump))
3376 && (GET_CODE (CONTAINING_INSN (jump)) != NOTE
3377 || (NOTE_LINE_NUMBER (CONTAINING_INSN (jump))
3378 != NOTE_INSN_DELETED)))
3379 add_pred_succ (BLOCK_NUM (CONTAINING_INSN (jump)), bb,
3380 s_preds, s_succs, num_preds, num_succs);
3383 jump = BLOCK_END (bb);
3384 /* If this is a RETURN insn or a conditional jump in the last
3385 basic block, or a non-jump insn in the last basic block, then
3386 this block reaches the exit block. */
3387 if ((GET_CODE (jump) == JUMP_INSN && GET_CODE (PATTERN (jump)) == RETURN)
3388 || (((GET_CODE (jump) == JUMP_INSN
3389 && condjump_p (jump) && !simplejump_p (jump))
3390 || GET_CODE (jump) != JUMP_INSN)
3391 && (bb == n_basic_blocks - 1)))
3392 add_pred_succ (bb, EXIT_BLOCK, s_preds, s_succs, num_preds, num_succs);
3394 if (basic_block_drops_in[bb])
3395 add_pred_succ (bb - 1, bb, s_preds, s_succs, num_preds, num_succs);
3398 add_pred_succ (ENTRY_BLOCK, 0, s_preds, s_succs, num_preds, num_succs);
3401 /* If we allocated any variables in temporary storage, clear out the
3402 pointer to the local storage to avoid dangling pointers. */
3403 if (clear_local_bb_vars)
3405 basic_block_drops_in = NULL;
3406 uid_block_number = NULL;
3411 void
3412 dump_bb_data (file, preds, succs)
3413 FILE *file;
3414 int_list_ptr *preds;
3415 int_list_ptr *succs;
3417 int bb;
3418 int_list_ptr p;
3420 fprintf (file, "BB data\n\n");
3421 for (bb = 0; bb < n_basic_blocks; bb++)
3423 fprintf (file, "BB %d, start %d, end %d\n", bb,
3424 INSN_UID (BLOCK_HEAD (bb)), INSN_UID (BLOCK_END (bb)));
3425 fprintf (file, " preds:");
3426 for (p = preds[bb]; p != NULL; p = p->next)
3428 int pred_bb = INT_LIST_VAL (p);
3429 if (pred_bb == ENTRY_BLOCK)
3430 fprintf (file, " entry");
3431 else
3432 fprintf (file, " %d", pred_bb);
3434 fprintf (file, "\n");
3435 fprintf (file, " succs:");
3436 for (p = succs[bb]; p != NULL; p = p->next)
3438 int succ_bb = INT_LIST_VAL (p);
3439 if (succ_bb == EXIT_BLOCK)
3440 fprintf (file, " exit");
3441 else
3442 fprintf (file, " %d", succ_bb);
3444 fprintf (file, "\n");
3446 fprintf (file, "\n");
3449 void
3450 dump_sbitmap (file, bmap)
3451 FILE *file;
3452 sbitmap bmap;
3454 int i,j,n;
3455 int set_size = bmap->size;
3456 int total_bits = bmap->n_bits;
3458 fprintf (file, " ");
3459 for (i = n = 0; i < set_size && n < total_bits; i++)
3461 for (j = 0; j < SBITMAP_ELT_BITS && n < total_bits; j++, n++)
3463 if (n != 0 && n % 10 == 0)
3464 fprintf (file, " ");
3465 fprintf (file, "%d", (bmap->elms[i] & (1L << j)) != 0);
3468 fprintf (file, "\n");
3471 void
3472 dump_sbitmap_vector (file, title, subtitle, bmaps, n_maps)
3473 FILE *file;
3474 char *title, *subtitle;
3475 sbitmap *bmaps;
3476 int n_maps;
3478 int bb;
3480 fprintf (file, "%s\n", title);
3481 for (bb = 0; bb < n_maps; bb++)
3483 fprintf (file, "%s %d\n", subtitle, bb);
3484 dump_sbitmap (file, bmaps[bb]);
3486 fprintf (file, "\n");
3489 /* Free basic block data storage. */
3491 void
3492 free_bb_mem ()
3494 free_int_list (&pred_int_list_blocks);
3497 /* Bitmap manipulation routines. */
3499 /* Allocate a simple bitmap of N_ELMS bits. */
3501 sbitmap
3502 sbitmap_alloc (n_elms)
3503 int n_elms;
3505 int bytes, size, amt;
3506 sbitmap bmap;
3508 size = SBITMAP_SET_SIZE (n_elms);
3509 bytes = size * sizeof (SBITMAP_ELT_TYPE);
3510 amt = (sizeof (struct simple_bitmap_def)
3511 + bytes - sizeof (SBITMAP_ELT_TYPE));
3512 bmap = (sbitmap) xmalloc (amt);
3513 bmap->n_bits = n_elms;
3514 bmap->size = size;
3515 bmap->bytes = bytes;
3516 return bmap;
3519 /* Allocate a vector of N_VECS bitmaps of N_ELMS bits. */
3521 sbitmap *
3522 sbitmap_vector_alloc (n_vecs, n_elms)
3523 int n_vecs, n_elms;
3525 int i, bytes, offset, elm_bytes, size, amt, vector_bytes;
3526 sbitmap *bitmap_vector;
3528 size = SBITMAP_SET_SIZE (n_elms);
3529 bytes = size * sizeof (SBITMAP_ELT_TYPE);
3530 elm_bytes = (sizeof (struct simple_bitmap_def)
3531 + bytes - sizeof (SBITMAP_ELT_TYPE));
3532 vector_bytes = n_vecs * sizeof (sbitmap *);
3534 /* Round up `vector_bytes' to account for the alignment requirements
3535 of an sbitmap. One could allocate the vector-table and set of sbitmaps
3536 separately, but that requires maintaining two pointers or creating
3537 a cover struct to hold both pointers (so our result is still just
3538 one pointer). Neither is a bad idea, but this is simpler for now. */
3540 /* Based on DEFAULT_ALIGNMENT computation in obstack.c. */
3541 struct { char x; SBITMAP_ELT_TYPE y; } align;
3542 int alignment = (char *) & align.y - & align.x;
3543 vector_bytes = (vector_bytes + alignment - 1) & ~ (alignment - 1);
3546 amt = vector_bytes + (n_vecs * elm_bytes);
3547 bitmap_vector = (sbitmap *) xmalloc (amt);
3549 for (i = 0, offset = vector_bytes;
3550 i < n_vecs;
3551 i++, offset += elm_bytes)
3553 sbitmap b = (sbitmap) ((char *) bitmap_vector + offset);
3554 bitmap_vector[i] = b;
3555 b->n_bits = n_elms;
3556 b->size = size;
3557 b->bytes = bytes;
3560 return bitmap_vector;
3563 /* Copy sbitmap SRC to DST. */
3565 void
3566 sbitmap_copy (dst, src)
3567 sbitmap dst, src;
3569 int i;
3570 sbitmap_ptr d,s;
3572 s = src->elms;
3573 d = dst->elms;
3574 for (i = 0; i < dst->size; i++)
3575 *d++ = *s++;
3578 /* Zero all elements in a bitmap. */
3580 void
3581 sbitmap_zero (bmap)
3582 sbitmap bmap;
3584 bzero ((char *) bmap->elms, bmap->bytes);
3587 /* Set to ones all elements in a bitmap. */
3589 void
3590 sbitmap_ones (bmap)
3591 sbitmap bmap;
3593 memset (bmap->elms, -1, bmap->bytes);
3596 /* Zero a vector of N_VECS bitmaps. */
3598 void
3599 sbitmap_vector_zero (bmap, n_vecs)
3600 sbitmap *bmap;
3601 int n_vecs;
3603 int i;
3605 for (i = 0; i < n_vecs; i++)
3606 sbitmap_zero (bmap[i]);
3609 /* Set to ones a vector of N_VECS bitmaps. */
3611 void
3612 sbitmap_vector_ones (bmap, n_vecs)
3613 sbitmap *bmap;
3614 int n_vecs;
3616 int i;
3618 for (i = 0; i < n_vecs; i++)
3619 sbitmap_ones (bmap[i]);
3622 /* Set DST to be A union (B - C).
3623 DST = A | (B & ~C).
3624 Return non-zero if any change is made. */
3627 sbitmap_union_of_diff (dst, a, b, c)
3628 sbitmap dst, a, b, c;
3630 int i,changed;
3631 sbitmap_ptr dstp, ap, bp, cp;
3633 changed = 0;
3634 dstp = dst->elms;
3635 ap = a->elms;
3636 bp = b->elms;
3637 cp = c->elms;
3638 for (i = 0; i < dst->size; i++)
3640 SBITMAP_ELT_TYPE tmp = *ap | (*bp & ~*cp);
3641 if (*dstp != tmp)
3642 changed = 1;
3643 *dstp = tmp;
3644 dstp++; ap++; bp++; cp++;
3646 return changed;
3649 /* Set bitmap DST to the bitwise negation of the bitmap SRC. */
3651 void
3652 sbitmap_not (dst, src)
3653 sbitmap dst, src;
3655 int i;
3656 sbitmap_ptr dstp, ap;
3658 dstp = dst->elms;
3659 ap = src->elms;
3660 for (i = 0; i < dst->size; i++)
3662 SBITMAP_ELT_TYPE tmp = ~(*ap);
3663 *dstp = tmp;
3664 dstp++; ap++;
3668 /* Set the bits in DST to be the difference between the bits
3669 in A and the bits in B. i.e. dst = a - b.
3670 The - operator is implemented as a & (~b). */
3672 void
3673 sbitmap_difference (dst, a, b)
3674 sbitmap dst, a, b;
3676 int i;
3677 sbitmap_ptr dstp, ap, bp;
3679 dstp = dst->elms;
3680 ap = a->elms;
3681 bp = b->elms;
3682 for (i = 0; i < dst->size; i++)
3683 *dstp++ = *ap++ & (~*bp++);
3686 /* Set DST to be (A and B)).
3687 Return non-zero if any change is made. */
3690 sbitmap_a_and_b (dst, a, b)
3691 sbitmap dst, a, b;
3693 int i,changed;
3694 sbitmap_ptr dstp, ap, bp;
3696 changed = 0;
3697 dstp = dst->elms;
3698 ap = a->elms;
3699 bp = b->elms;
3700 for (i = 0; i < dst->size; i++)
3702 SBITMAP_ELT_TYPE tmp = *ap & *bp;
3703 if (*dstp != tmp)
3704 changed = 1;
3705 *dstp = tmp;
3706 dstp++; ap++; bp++;
3708 return changed;
3710 /* Set DST to be (A or B)).
3711 Return non-zero if any change is made. */
3714 sbitmap_a_or_b (dst, a, b)
3715 sbitmap dst, a, b;
3717 int i,changed;
3718 sbitmap_ptr dstp, ap, bp;
3720 changed = 0;
3721 dstp = dst->elms;
3722 ap = a->elms;
3723 bp = b->elms;
3724 for (i = 0; i < dst->size; i++)
3726 SBITMAP_ELT_TYPE tmp = *ap | *bp;
3727 if (*dstp != tmp)
3728 changed = 1;
3729 *dstp = tmp;
3730 dstp++; ap++; bp++;
3732 return changed;
3735 /* Set DST to be (A or (B and C)).
3736 Return non-zero if any change is made. */
3739 sbitmap_a_or_b_and_c (dst, a, b, c)
3740 sbitmap dst, a, b, c;
3742 int i,changed;
3743 sbitmap_ptr dstp, ap, bp, cp;
3745 changed = 0;
3746 dstp = dst->elms;
3747 ap = a->elms;
3748 bp = b->elms;
3749 cp = c->elms;
3750 for (i = 0; i < dst->size; i++)
3752 SBITMAP_ELT_TYPE tmp = *ap | (*bp & *cp);
3753 if (*dstp != tmp)
3754 changed = 1;
3755 *dstp = tmp;
3756 dstp++; ap++; bp++; cp++;
3758 return changed;
3761 /* Set DST to be (A ann (B or C)).
3762 Return non-zero if any change is made. */
3765 sbitmap_a_and_b_or_c (dst, a, b, c)
3766 sbitmap dst, a, b, c;
3768 int i,changed;
3769 sbitmap_ptr dstp, ap, bp, cp;
3771 changed = 0;
3772 dstp = dst->elms;
3773 ap = a->elms;
3774 bp = b->elms;
3775 cp = c->elms;
3776 for (i = 0; i < dst->size; i++)
3778 SBITMAP_ELT_TYPE tmp = *ap & (*bp | *cp);
3779 if (*dstp != tmp)
3780 changed = 1;
3781 *dstp = tmp;
3782 dstp++; ap++; bp++; cp++;
3784 return changed;
3787 /* Set the bitmap DST to the intersection of SRC of all predecessors or
3788 successors of block number BB (PRED_SUCC says which). */
3790 void
3791 sbitmap_intersect_of_predsucc (dst, src, bb, pred_succ)
3792 sbitmap dst;
3793 sbitmap *src;
3794 int bb;
3795 int_list_ptr *pred_succ;
3797 int_list_ptr ps;
3798 int ps_bb;
3799 int set_size = dst->size;
3801 ps = pred_succ[bb];
3803 /* It is possible that there are no predecessors(/successors).
3804 This can happen for example in unreachable code. */
3806 if (ps == NULL)
3808 /* In APL-speak this is the `and' reduction of the empty set and thus
3809 the result is the identity for `and'. */
3810 sbitmap_ones (dst);
3811 return;
3814 /* Set result to first predecessor/successor. */
3816 for ( ; ps != NULL; ps = ps->next)
3818 ps_bb = INT_LIST_VAL (ps);
3819 if (ps_bb == ENTRY_BLOCK || ps_bb == EXIT_BLOCK)
3820 continue;
3821 sbitmap_copy (dst, src[ps_bb]);
3822 /* Break out since we're only doing first predecessor. */
3823 break;
3825 if (ps == NULL)
3826 return;
3828 /* Now do the remaining predecessors/successors. */
3830 for (ps = ps->next; ps != NULL; ps = ps->next)
3832 int i;
3833 sbitmap_ptr p,r;
3835 ps_bb = INT_LIST_VAL (ps);
3836 if (ps_bb == ENTRY_BLOCK || ps_bb == EXIT_BLOCK)
3837 continue;
3839 p = src[ps_bb]->elms;
3840 r = dst->elms;
3842 for (i = 0; i < set_size; i++)
3843 *r++ &= *p++;
3847 /* Set the bitmap DST to the intersection of SRC of all predecessors
3848 of block number BB. */
3850 void
3851 sbitmap_intersect_of_predecessors (dst, src, bb, s_preds)
3852 sbitmap dst;
3853 sbitmap *src;
3854 int bb;
3855 int_list_ptr *s_preds;
3857 sbitmap_intersect_of_predsucc (dst, src, bb, s_preds);
3860 /* Set the bitmap DST to the intersection of SRC of all successors
3861 of block number BB. */
3863 void
3864 sbitmap_intersect_of_successors (dst, src, bb, s_succs)
3865 sbitmap dst;
3866 sbitmap *src;
3867 int bb;
3868 int_list_ptr *s_succs;
3870 sbitmap_intersect_of_predsucc (dst, src, bb, s_succs);
3873 /* Set the bitmap DST to the union of SRC of all predecessors/successors of
3874 block number BB. */
3876 void
3877 sbitmap_union_of_predsucc (dst, src, bb, pred_succ)
3878 sbitmap dst;
3879 sbitmap *src;
3880 int bb;
3881 int_list_ptr *pred_succ;
3883 int_list_ptr ps;
3884 int ps_bb;
3885 int set_size = dst->size;
3887 ps = pred_succ[bb];
3889 /* It is possible that there are no predecessors(/successors).
3890 This can happen for example in unreachable code. */
3892 if (ps == NULL)
3894 /* In APL-speak this is the `or' reduction of the empty set and thus
3895 the result is the identity for `or'. */
3896 sbitmap_zero (dst);
3897 return;
3900 /* Set result to first predecessor/successor. */
3902 for ( ; ps != NULL; ps = ps->next)
3904 ps_bb = INT_LIST_VAL (ps);
3905 if (ps_bb == ENTRY_BLOCK || ps_bb == EXIT_BLOCK)
3906 continue;
3907 sbitmap_copy (dst, src[ps_bb]);
3908 /* Break out since we're only doing first predecessor. */
3909 break;
3911 if (ps == NULL)
3912 return;
3914 /* Now do the remaining predecessors/successors. */
3916 for (ps = ps->next; ps != NULL; ps = ps->next)
3918 int i;
3919 sbitmap_ptr p,r;
3921 ps_bb = INT_LIST_VAL (ps);
3922 if (ps_bb == ENTRY_BLOCK || ps_bb == EXIT_BLOCK)
3923 continue;
3925 p = src[ps_bb]->elms;
3926 r = dst->elms;
3928 for (i = 0; i < set_size; i++)
3929 *r++ |= *p++;
3933 /* Set the bitmap DST to the union of SRC of all predecessors of
3934 block number BB. */
3936 void
3937 sbitmap_union_of_predecessors (dst, src, bb, s_preds)
3938 sbitmap dst;
3939 sbitmap *src;
3940 int bb;
3941 int_list_ptr *s_preds;
3943 sbitmap_union_of_predsucc (dst, src, bb, s_preds);
3946 /* Set the bitmap DST to the union of SRC of all predecessors of
3947 block number BB. */
3949 void
3950 sbitmap_union_of_successors (dst, src, bb, s_succ)
3951 sbitmap dst;
3952 sbitmap *src;
3953 int bb;
3954 int_list_ptr *s_succ;
3956 sbitmap_union_of_predsucc (dst, src, bb, s_succ);
3959 /* Compute dominator relationships. */
3960 void
3961 compute_dominators (dominators, post_dominators, s_preds, s_succs)
3962 sbitmap *dominators;
3963 sbitmap *post_dominators;
3964 int_list_ptr *s_preds;
3965 int_list_ptr *s_succs;
3967 int bb, changed, passes;
3968 sbitmap *temp_bitmap;
3970 temp_bitmap = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
3971 sbitmap_vector_ones (dominators, n_basic_blocks);
3972 sbitmap_vector_ones (post_dominators, n_basic_blocks);
3973 sbitmap_vector_zero (temp_bitmap, n_basic_blocks);
3975 sbitmap_zero (dominators[0]);
3976 SET_BIT (dominators[0], 0);
3978 sbitmap_zero (post_dominators[n_basic_blocks-1]);
3979 SET_BIT (post_dominators[n_basic_blocks-1], 0);
3981 passes = 0;
3982 changed = 1;
3983 while (changed)
3985 changed = 0;
3986 for (bb = 1; bb < n_basic_blocks; bb++)
3988 sbitmap_intersect_of_predecessors (temp_bitmap[bb], dominators,
3989 bb, s_preds);
3990 SET_BIT (temp_bitmap[bb], bb);
3991 changed |= sbitmap_a_and_b (dominators[bb],
3992 dominators[bb],
3993 temp_bitmap[bb]);
3994 sbitmap_intersect_of_successors (temp_bitmap[bb], post_dominators,
3995 bb, s_succs);
3996 SET_BIT (temp_bitmap[bb], bb);
3997 changed |= sbitmap_a_and_b (post_dominators[bb],
3998 post_dominators[bb],
3999 temp_bitmap[bb]);
4001 passes++;
4004 free (temp_bitmap);
4007 /* Count for a single SET rtx, X. */
4009 static void
4010 count_reg_sets_1 (x)
4011 rtx x;
4013 register int regno;
4014 register rtx reg = SET_DEST (x);
4016 /* Find the register that's set/clobbered. */
4017 while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT
4018 || GET_CODE (reg) == SIGN_EXTRACT
4019 || GET_CODE (reg) == STRICT_LOW_PART)
4020 reg = XEXP (reg, 0);
4022 if (GET_CODE (reg) == REG)
4024 regno = REGNO (reg);
4025 if (regno >= FIRST_PSEUDO_REGISTER)
4027 /* Count (weighted) references, stores, etc. This counts a
4028 register twice if it is modified, but that is correct. */
4029 REG_N_SETS (regno)++;
4031 REG_N_REFS (regno) += loop_depth;
4036 /* Increment REG_N_SETS for each SET or CLOBBER found in X; also increment
4037 REG_N_REFS by the current loop depth for each SET or CLOBBER found. */
4039 static void
4040 count_reg_sets (x)
4041 rtx x;
4043 register RTX_CODE code = GET_CODE (x);
4045 if (code == SET || code == CLOBBER)
4046 count_reg_sets_1 (x);
4047 else if (code == PARALLEL)
4049 register int i;
4050 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
4052 code = GET_CODE (XVECEXP (x, 0, i));
4053 if (code == SET || code == CLOBBER)
4054 count_reg_sets_1 (XVECEXP (x, 0, i));
4059 /* Increment REG_N_REFS by the current loop depth each register reference
4060 found in X. */
4062 static void
4063 count_reg_references (x)
4064 rtx x;
4066 register RTX_CODE code;
4067 register int regno;
4068 int i;
4070 retry:
4071 code = GET_CODE (x);
4072 switch (code)
4074 case LABEL_REF:
4075 case SYMBOL_REF:
4076 case CONST_INT:
4077 case CONST:
4078 case CONST_DOUBLE:
4079 case PC:
4080 case ADDR_VEC:
4081 case ADDR_DIFF_VEC:
4082 case ASM_INPUT:
4083 return;
4085 #ifdef HAVE_cc0
4086 case CC0:
4087 return;
4088 #endif
4090 case CLOBBER:
4091 /* If we are clobbering a MEM, mark any registers inside the address
4092 as being used. */
4093 if (GET_CODE (XEXP (x, 0)) == MEM)
4094 count_reg_references (XEXP (XEXP (x, 0), 0));
4095 return;
4097 case SUBREG:
4098 /* While we're here, optimize this case. */
4099 x = SUBREG_REG (x);
4101 /* In case the SUBREG is not of a register, don't optimize */
4102 if (GET_CODE (x) != REG)
4104 count_reg_references (x);
4105 return;
4108 /* ... fall through ... */
4110 case REG:
4111 if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
4112 REG_N_REFS (REGNO (x)) += loop_depth;
4113 return;
4115 case SET:
4117 register rtx testreg = SET_DEST (x);
4118 int mark_dest = 0;
4120 /* If storing into MEM, don't show it as being used. But do
4121 show the address as being used. */
4122 if (GET_CODE (testreg) == MEM)
4124 count_reg_references (XEXP (testreg, 0));
4125 count_reg_references (SET_SRC (x));
4126 return;
4129 /* Storing in STRICT_LOW_PART is like storing in a reg
4130 in that this SET might be dead, so ignore it in TESTREG.
4131 but in some other ways it is like using the reg.
4133 Storing in a SUBREG or a bit field is like storing the entire
4134 register in that if the register's value is not used
4135 then this SET is not needed. */
4136 while (GET_CODE (testreg) == STRICT_LOW_PART
4137 || GET_CODE (testreg) == ZERO_EXTRACT
4138 || GET_CODE (testreg) == SIGN_EXTRACT
4139 || GET_CODE (testreg) == SUBREG)
4141 /* Modifying a single register in an alternate mode
4142 does not use any of the old value. But these other
4143 ways of storing in a register do use the old value. */
4144 if (GET_CODE (testreg) == SUBREG
4145 && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
4147 else
4148 mark_dest = 1;
4150 testreg = XEXP (testreg, 0);
4153 /* If this is a store into a register,
4154 recursively scan the value being stored. */
4156 if (GET_CODE (testreg) == REG)
4158 count_reg_references (SET_SRC (x));
4159 if (mark_dest)
4160 count_reg_references (SET_DEST (x));
4161 return;
4164 break;
4166 default:
4167 break;
4170 /* Recursively scan the operands of this expression. */
4173 register char *fmt = GET_RTX_FORMAT (code);
4174 register int i;
4176 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4178 if (fmt[i] == 'e')
4180 /* Tail recursive case: save a function call level. */
4181 if (i == 0)
4183 x = XEXP (x, 0);
4184 goto retry;
4186 count_reg_references (XEXP (x, i));
4188 else if (fmt[i] == 'E')
4190 register int j;
4191 for (j = 0; j < XVECLEN (x, i); j++)
4192 count_reg_references (XVECEXP (x, i, j));
4198 /* Recompute register set/reference counts immediately prior to register
4199 allocation.
4201 This avoids problems with set/reference counts changing to/from values
4202 which have special meanings to the register allocators.
4204 Additionally, the reference counts are the primary component used by the
4205 register allocators to prioritize pseudos for allocation to hard regs.
4206 More accurate reference counts generally lead to better register allocation.
4208 It might be worthwhile to update REG_LIVE_LENGTH, REG_BASIC_BLOCK and
4209 possibly other information which is used by the register allocators. */
4212 recompute_reg_usage (f)
4213 rtx f;
4215 rtx insn;
4216 int i, max_reg;
4218 /* Clear out the old data. */
4219 max_reg = max_reg_num ();
4220 for (i = FIRST_PSEUDO_REGISTER; i < max_reg; i++)
4222 REG_N_SETS (i) = 0;
4223 REG_N_REFS (i) = 0;
4226 /* Scan each insn in the chain and count how many times each register is
4227 set/used. */
4228 loop_depth = 1;
4229 for (insn = f; insn; insn = NEXT_INSN (insn))
4231 /* Keep track of loop depth. */
4232 if (GET_CODE (insn) == NOTE)
4234 /* Look for loop boundaries. */
4235 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
4236 loop_depth--;
4237 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
4238 loop_depth++;
4240 /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error.
4241 Abort now rather than setting register status incorrectly. */
4242 if (loop_depth == 0)
4243 abort ();
4245 else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
4247 rtx links;
4249 /* This call will increment REG_N_SETS for each SET or CLOBBER
4250 of a register in INSN. It will also increment REG_N_REFS
4251 by the loop depth for each set of a register in INSN. */
4252 count_reg_sets (PATTERN (insn));
4254 /* count_reg_sets does not detect autoincrement address modes, so
4255 detect them here by looking at the notes attached to INSN. */
4256 for (links = REG_NOTES (insn); links; links = XEXP (links, 1))
4258 if (REG_NOTE_KIND (links) == REG_INC)
4259 /* Count (weighted) references, stores, etc. This counts a
4260 register twice if it is modified, but that is correct. */
4261 REG_N_SETS (REGNO (XEXP (links, 0)))++;
4264 /* This call will increment REG_N_REFS by the current loop depth for
4265 each reference to a register in INSN. */
4266 count_reg_references (PATTERN (insn));
4268 /* count_reg_references will not include counts for arguments to
4269 function calls, so detect them here by examining the
4270 CALL_INSN_FUNCTION_USAGE data. */
4271 if (GET_CODE (insn) == CALL_INSN)
4273 rtx note;
4275 for (note = CALL_INSN_FUNCTION_USAGE (insn);
4276 note;
4277 note = XEXP (note, 1))
4278 if (GET_CODE (XEXP (note, 0)) == USE)
4279 count_reg_references (SET_DEST (XEXP (note, 0)));