1 /* Data flow analysis for GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 /* This file contains the data flow analysis pass of the compiler. It
24 computes data flow information which tells combine_instructions
25 which insns to consider combining and controls register allocation.
27 Additional data flow information that is too bulky to record is
28 generated during the analysis, and is used at that time to create
29 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 into basic
38 blocks and constructs the CFG. The blocks are recorded in the
39 basic_block_info array; the CFG exists in the edge structures
40 referenced by the blocks.
42 find_basic_blocks also finds any unreachable loops and deletes them.
46 life_analysis is called immediately after find_basic_blocks.
47 It uses the basic block information to determine where each
48 hard or pseudo register is live.
50 ** live-register info **
52 The information about where each register is live is in two parts:
53 the REG_NOTES of insns, and the vector basic_block->global_live_at_start.
55 basic_block->global_live_at_start has an element for each basic
56 block, and the element is a bit-vector with a bit for each hard or
57 pseudo register. The bit is 1 if the register is live at the
58 beginning of the basic block.
60 Two types of elements can be added to an insn's REG_NOTES.
61 A REG_DEAD note is added to an insn's REG_NOTES for any register
62 that meets both of two conditions: The value in the register is not
63 needed in subsequent insns and the insn does not replace the value in
64 the register (in the case of multi-word hard registers, the value in
65 each register must be replaced by the insn to avoid a REG_DEAD note).
67 In the vast majority of cases, an object in a REG_DEAD note will be
68 used somewhere in the insn. The (rare) exception to this is if an
69 insn uses a multi-word hard register and only some of the registers are
70 needed in subsequent insns. In that case, REG_DEAD notes will be
71 provided for those hard registers that are not subsequently needed.
72 Partial REG_DEAD notes of this type do not occur when an insn sets
73 only some of the hard registers used in such a multi-word operand;
74 omitting REG_DEAD notes for objects stored in an insn is optional and
75 the desire to do so does not justify the complexity of the partial
78 REG_UNUSED notes are added for each register that is set by the insn
79 but is unused subsequently (if every register set by the insn is unused
80 and the insn does not reference memory or have some other side-effect,
81 the insn is deleted instead). If only part of a multi-word hard
82 register is used in a subsequent insn, REG_UNUSED notes are made for
83 the parts that will not be used.
85 To determine which registers are live after any insn, one can
86 start from the beginning of the basic block and scan insns, noting
87 which registers are set by each insn and which die there.
89 ** Other actions of life_analysis **
91 life_analysis sets up the LOG_LINKS fields of insns because the
92 information needed to do so is readily available.
94 life_analysis deletes insns whose only effect is to store a value
97 life_analysis notices cases where a reference to a register as
98 a memory address can be combined with a preceding or following
99 incrementation or decrementation of the register. The separate
100 instruction to increment or decrement is deleted and the address
101 is changed to a POST_INC or similar rtx.
103 Each time an incrementing or decrementing address is created,
104 a REG_INC element is added to the insn's REG_NOTES list.
106 life_analysis fills in certain vectors containing information about
107 register usage: REG_N_REFS, REG_N_DEATHS, REG_N_SETS, REG_LIVE_LENGTH,
108 REG_N_CALLS_CROSSED, REG_N_THROWING_CALLS_CROSSED and REG_BASIC_BLOCK.
110 life_analysis sets current_function_sp_is_unchanging if the function
111 doesn't modify the stack pointer. */
115 Split out from life_analysis:
116 - local property discovery
117 - global property computation
119 - pre/post modify transformation
124 #include "coretypes.h"
129 #include "hard-reg-set.h"
130 #include "basic-block.h"
131 #include "insn-config.h"
135 #include "function.h"
143 #include "splay-tree.h"
144 #include "tree-pass.h"
147 #ifndef HAVE_epilogue
148 #define HAVE_epilogue 0
150 #ifndef HAVE_prologue
151 #define HAVE_prologue 0
153 #ifndef HAVE_sibcall_epilogue
154 #define HAVE_sibcall_epilogue 0
157 #ifndef EPILOGUE_USES
158 #define EPILOGUE_USES(REGNO) 0
161 #define EH_USES(REGNO) 0
164 #ifdef HAVE_conditional_execution
165 #ifndef REVERSE_CONDEXEC_PREDICATES_P
166 #define REVERSE_CONDEXEC_PREDICATES_P(x, y) \
167 (GET_CODE ((x)) == reversed_comparison_code ((y), NULL))
171 /* This is the maximum number of times we process any given block if the
172 latest loop depth count is smaller than this number. Only used for the
173 failure strategy to avoid infinite loops in calculate_global_regs_live. */
174 #define MAX_LIVENESS_ROUNDS 20
176 /* Nonzero if the second flow pass has completed. */
179 /* Maximum register number used in this function, plus one. */
183 /* Indexed by n, giving various register information */
185 VEC(reg_info_p
,heap
) *reg_n_info
;
187 /* Regset of regs live when calls to `setjmp'-like functions happen. */
188 /* ??? Does this exist only for the setjmp-clobbered warning message? */
190 static regset regs_live_at_setjmp
;
192 /* List made of EXPR_LIST rtx's which gives pairs of pseudo registers
193 that have to go in the same hard reg.
194 The first two regs in the list are a pair, and the next two
195 are another pair, etc. */
198 /* Set of registers that may be eliminable. These are handled specially
199 in updating regs_ever_live. */
201 static HARD_REG_SET elim_reg_set
;
203 /* Holds information for tracking conditional register life information. */
204 struct reg_cond_life_info
206 /* A boolean expression of conditions under which a register is dead. */
208 /* Conditions under which a register is dead at the basic block end. */
211 /* A boolean expression of conditions under which a register has been
215 /* ??? Could store mask of bytes that are dead, so that we could finally
216 track lifetimes of multi-word registers accessed via subregs. */
219 /* For use in communicating between propagate_block and its subroutines.
220 Holds all information needed to compute life and def-use information. */
222 struct propagate_block_info
224 /* The basic block we're considering. */
227 /* Bit N is set if register N is conditionally or unconditionally live. */
230 /* Bit N is set if register N is set this insn. */
233 /* Element N is the next insn that uses (hard or pseudo) register N
234 within the current basic block; or zero, if there is no such insn. */
237 /* Contains a list of all the MEMs we are tracking for dead store
241 /* If non-null, record the set of registers set unconditionally in the
245 /* If non-null, record the set of registers set conditionally in the
247 regset cond_local_set
;
249 #ifdef HAVE_conditional_execution
250 /* Indexed by register number, holds a reg_cond_life_info for each
251 register that is not unconditionally live or dead. */
252 splay_tree reg_cond_dead
;
254 /* Bit N is set if register N is in an expression in reg_cond_dead. */
258 /* The length of mem_set_list. */
259 int mem_set_list_len
;
261 /* Nonzero if the value of CC0 is live. */
264 /* Flags controlling the set of information propagate_block collects. */
266 /* Index of instruction being processed. */
270 /* Number of dead insns removed. */
273 /* When PROP_REG_INFO set, array contains pbi->insn_num of instruction
274 where given register died. When the register is marked alive, we use the
275 information to compute amount of instructions life range cross.
276 (remember, we are walking backward). This can be computed as current
277 pbi->insn_num - reg_deaths[regno].
278 At the end of processing each basic block, the remaining live registers
279 are inspected and live ranges are increased same way so liverange of global
280 registers are computed correctly.
282 The array is maintained clear for dead registers, so it can be safely reused
283 for next basic block without expensive memset of the whole array after
284 reseting pbi->insn_num to 0. */
286 static int *reg_deaths
;
288 /* Forward declarations */
289 static int verify_wide_reg_1 (rtx
*, void *);
290 static void verify_wide_reg (int, basic_block
);
291 static void verify_local_live_at_start (regset
, basic_block
);
292 static void notice_stack_pointer_modification_1 (rtx
, rtx
, void *);
293 static void notice_stack_pointer_modification (void);
294 static void mark_reg (rtx
, void *);
295 static void mark_regs_live_at_end (regset
);
296 static void calculate_global_regs_live (sbitmap
, sbitmap
, int);
297 static void propagate_block_delete_insn (rtx
);
298 static rtx
propagate_block_delete_libcall (rtx
, rtx
);
299 static int insn_dead_p (struct propagate_block_info
*, rtx
, int, rtx
);
300 static int libcall_dead_p (struct propagate_block_info
*, rtx
, rtx
);
301 static void mark_set_regs (struct propagate_block_info
*, rtx
, rtx
);
302 static void mark_set_1 (struct propagate_block_info
*, enum rtx_code
, rtx
,
304 static int find_regno_partial (rtx
*, void *);
306 #ifdef HAVE_conditional_execution
307 static int mark_regno_cond_dead (struct propagate_block_info
*, int, rtx
);
308 static void free_reg_cond_life_info (splay_tree_value
);
309 static int flush_reg_cond_reg_1 (splay_tree_node
, void *);
310 static void flush_reg_cond_reg (struct propagate_block_info
*, int);
311 static rtx
elim_reg_cond (rtx
, unsigned int);
312 static rtx
ior_reg_cond (rtx
, rtx
, int);
313 static rtx
not_reg_cond (rtx
);
314 static rtx
and_reg_cond (rtx
, rtx
, int);
317 static void attempt_auto_inc (struct propagate_block_info
*, rtx
, rtx
, rtx
,
319 static void find_auto_inc (struct propagate_block_info
*, rtx
, rtx
);
320 static int try_pre_increment_1 (struct propagate_block_info
*, rtx
);
321 static int try_pre_increment (rtx
, rtx
, HOST_WIDE_INT
);
323 static void mark_used_reg (struct propagate_block_info
*, rtx
, rtx
, rtx
);
324 static void mark_used_regs (struct propagate_block_info
*, rtx
, rtx
, rtx
);
325 void debug_flow_info (void);
326 static void add_to_mem_set_list (struct propagate_block_info
*, rtx
);
327 static int invalidate_mems_from_autoinc (rtx
*, void *);
328 static void invalidate_mems_from_set (struct propagate_block_info
*, rtx
);
329 static void clear_log_links (sbitmap
);
330 static int count_or_remove_death_notes_bb (basic_block
, int);
331 static void allocate_bb_life_data (void);
333 /* Return the INSN immediately following the NOTE_INSN_BASIC_BLOCK
334 note associated with the BLOCK. */
337 first_insn_after_basic_block_note (basic_block block
)
341 /* Get the first instruction in the block. */
342 insn
= BB_HEAD (block
);
344 if (insn
== NULL_RTX
)
347 insn
= NEXT_INSN (insn
);
348 gcc_assert (NOTE_INSN_BASIC_BLOCK_P (insn
));
350 return NEXT_INSN (insn
);
353 /* Perform data flow analysis for the whole control flow graph.
354 FLAGS is a set of PROP_* flags to be used in accumulating flow info. */
357 life_analysis (int flags
)
359 #ifdef ELIMINABLE_REGS
361 static const struct {const int from
, to
; } eliminables
[] = ELIMINABLE_REGS
;
364 /* Record which registers will be eliminated. We use this in
367 CLEAR_HARD_REG_SET (elim_reg_set
);
369 #ifdef ELIMINABLE_REGS
370 for (i
= 0; i
< (int) ARRAY_SIZE (eliminables
); i
++)
371 SET_HARD_REG_BIT (elim_reg_set
, eliminables
[i
].from
);
373 SET_HARD_REG_BIT (elim_reg_set
, FRAME_POINTER_REGNUM
);
377 #ifdef CANNOT_CHANGE_MODE_CLASS
378 if (flags
& PROP_REG_INFO
)
379 init_subregs_of_mode ();
383 flags
&= ~(PROP_LOG_LINKS
| PROP_AUTOINC
| PROP_ALLOW_CFG_CHANGES
);
385 /* The post-reload life analysis have (on a global basis) the same
386 registers live as was computed by reload itself. elimination
387 Otherwise offsets and such may be incorrect.
389 Reload will make some registers as live even though they do not
392 We don't want to create new auto-incs after reload, since they
393 are unlikely to be useful and can cause problems with shared
395 if (reload_completed
)
396 flags
&= ~(PROP_REG_INFO
| PROP_AUTOINC
);
398 /* We want alias analysis information for local dead store elimination. */
399 if (optimize
&& (flags
& PROP_SCAN_DEAD_STORES
))
400 init_alias_analysis ();
402 /* Always remove no-op moves. Do this before other processing so
403 that we don't have to keep re-scanning them. */
404 delete_noop_moves ();
406 /* Some targets can emit simpler epilogues if they know that sp was
407 not ever modified during the function. After reload, of course,
408 we've already emitted the epilogue so there's no sense searching. */
409 if (! reload_completed
)
410 notice_stack_pointer_modification ();
412 /* Allocate and zero out data structures that will record the
413 data from lifetime analysis. */
414 allocate_reg_life_data ();
415 allocate_bb_life_data ();
417 /* Find the set of registers live on function exit. */
418 mark_regs_live_at_end (EXIT_BLOCK_PTR
->il
.rtl
->global_live_at_start
);
420 /* "Update" life info from zero. It'd be nice to begin the
421 relaxation with just the exit and noreturn blocks, but that set
422 is not immediately handy. */
424 if (flags
& PROP_REG_INFO
)
426 memset (regs_ever_live
, 0, sizeof (regs_ever_live
));
427 memset (regs_asm_clobbered
, 0, sizeof (regs_asm_clobbered
));
429 update_life_info (NULL
, UPDATE_LIFE_GLOBAL
, flags
);
437 if (optimize
&& (flags
& PROP_SCAN_DEAD_STORES
))
438 end_alias_analysis ();
441 dump_flow_info (dump_file
, dump_flags
);
443 /* Removing dead insns should have made jumptables really dead. */
444 delete_dead_jumptables ();
447 /* A subroutine of verify_wide_reg, called through for_each_rtx.
448 Search for REGNO. If found, return 2 if it is not wider than
452 verify_wide_reg_1 (rtx
*px
, void *pregno
)
455 unsigned int regno
= *(int *) pregno
;
457 if (REG_P (x
) && REGNO (x
) == regno
)
459 if (GET_MODE_BITSIZE (GET_MODE (x
)) <= BITS_PER_WORD
)
466 /* A subroutine of verify_local_live_at_start. Search through insns
467 of BB looking for register REGNO. */
470 verify_wide_reg (int regno
, basic_block bb
)
472 rtx head
= BB_HEAD (bb
), end
= BB_END (bb
);
478 int r
= for_each_rtx (&PATTERN (head
), verify_wide_reg_1
, ®no
);
486 head
= NEXT_INSN (head
);
490 fprintf (dump_file
, "Register %d died unexpectedly.\n", regno
);
491 dump_bb (bb
, dump_file
, 0);
493 internal_error ("internal consistency failure");
496 /* A subroutine of update_life_info. Verify that there are no untoward
497 changes in live_at_start during a local update. */
500 verify_local_live_at_start (regset new_live_at_start
, basic_block bb
)
502 if (reload_completed
)
504 /* After reload, there are no pseudos, nor subregs of multi-word
505 registers. The regsets should exactly match. */
506 if (! REG_SET_EQUAL_P (new_live_at_start
,
507 bb
->il
.rtl
->global_live_at_start
))
512 "live_at_start mismatch in bb %d, aborting\nNew:\n",
514 debug_bitmap_file (dump_file
, new_live_at_start
);
515 fputs ("Old:\n", dump_file
);
516 dump_bb (bb
, dump_file
, 0);
518 internal_error ("internal consistency failure");
524 reg_set_iterator rsi
;
526 /* Find the set of changed registers. */
527 XOR_REG_SET (new_live_at_start
, bb
->il
.rtl
->global_live_at_start
);
529 EXECUTE_IF_SET_IN_REG_SET (new_live_at_start
, 0, i
, rsi
)
531 /* No registers should die. */
532 if (REGNO_REG_SET_P (bb
->il
.rtl
->global_live_at_start
, i
))
537 "Register %d died unexpectedly.\n", i
);
538 dump_bb (bb
, dump_file
, 0);
540 internal_error ("internal consistency failure");
542 /* Verify that the now-live register is wider than word_mode. */
543 verify_wide_reg (i
, bb
);
548 /* Updates life information starting with the basic blocks set in BLOCKS.
549 If BLOCKS is null, consider it to be the universal set.
551 If EXTENT is UPDATE_LIFE_LOCAL, such as after splitting or peepholing,
552 we are only expecting local modifications to basic blocks. If we find
553 extra registers live at the beginning of a block, then we either killed
554 useful data, or we have a broken split that wants data not provided.
555 If we find registers removed from live_at_start, that means we have
556 a broken peephole that is killing a register it shouldn't.
558 ??? This is not true in one situation -- when a pre-reload splitter
559 generates subregs of a multi-word pseudo, current life analysis will
560 lose the kill. So we _can_ have a pseudo go live. How irritating.
562 It is also not true when a peephole decides that it doesn't need one
563 or more of the inputs.
565 Including PROP_REG_INFO does not properly refresh regs_ever_live
566 unless the caller resets it to zero. */
569 update_life_info (sbitmap blocks
, enum update_life_extent extent
,
574 int stabilized_prop_flags
= prop_flags
;
577 tmp
= ALLOC_REG_SET (®_obstack
);
580 if ((prop_flags
& PROP_REG_INFO
) && !reg_deaths
)
581 reg_deaths
= XCNEWVEC (int, max_regno
);
583 timevar_push ((extent
== UPDATE_LIFE_LOCAL
|| blocks
)
584 ? TV_LIFE_UPDATE
: TV_LIFE
);
586 /* Changes to the CFG are only allowed when
587 doing a global update for the entire CFG. */
588 gcc_assert (!(prop_flags
& PROP_ALLOW_CFG_CHANGES
)
589 || (extent
!= UPDATE_LIFE_LOCAL
&& !blocks
));
591 /* For a global update, we go through the relaxation process again. */
592 if (extent
!= UPDATE_LIFE_LOCAL
)
598 calculate_global_regs_live (blocks
, blocks
,
599 prop_flags
& (PROP_SCAN_DEAD_CODE
600 | PROP_SCAN_DEAD_STORES
601 | PROP_ALLOW_CFG_CHANGES
));
603 if ((prop_flags
& (PROP_KILL_DEAD_CODE
| PROP_ALLOW_CFG_CHANGES
))
604 != (PROP_KILL_DEAD_CODE
| PROP_ALLOW_CFG_CHANGES
))
607 /* Removing dead code may allow the CFG to be simplified which
608 in turn may allow for further dead code detection / removal. */
609 FOR_EACH_BB_REVERSE (bb
)
611 COPY_REG_SET (tmp
, bb
->il
.rtl
->global_live_at_end
);
612 changed
|= propagate_block (bb
, tmp
, NULL
, NULL
,
613 prop_flags
& (PROP_SCAN_DEAD_CODE
614 | PROP_SCAN_DEAD_STORES
615 | PROP_KILL_DEAD_CODE
));
618 /* Don't pass PROP_SCAN_DEAD_CODE or PROP_KILL_DEAD_CODE to
619 subsequent propagate_block calls, since removing or acting as
620 removing dead code can affect global register liveness, which
621 is supposed to be finalized for this call after this loop. */
622 stabilized_prop_flags
623 &= ~(PROP_SCAN_DEAD_CODE
| PROP_SCAN_DEAD_STORES
624 | PROP_KILL_DEAD_CODE
);
629 /* We repeat regardless of what cleanup_cfg says. If there were
630 instructions deleted above, that might have been only a
631 partial improvement (see PARAM_MAX_FLOW_MEMORY_LOCATIONS usage).
632 Further improvement may be possible. */
633 cleanup_cfg (CLEANUP_EXPENSIVE
);
635 /* Zap the life information from the last round. If we don't
636 do this, we can wind up with registers that no longer appear
637 in the code being marked live at entry. */
640 CLEAR_REG_SET (bb
->il
.rtl
->global_live_at_start
);
641 CLEAR_REG_SET (bb
->il
.rtl
->global_live_at_end
);
645 /* If asked, remove notes from the blocks we'll update. */
646 if (extent
== UPDATE_LIFE_GLOBAL_RM_NOTES
)
647 count_or_remove_death_notes (blocks
,
648 prop_flags
& PROP_POST_REGSTACK
? -1 : 1);
652 /* FIXME: This can go when the dataflow branch has been merged in. */
653 /* For a local update, if we are creating new REG_DEAD notes, then we
654 must delete the old ones first to avoid conflicts if they are
656 if (prop_flags
& PROP_DEATH_NOTES
)
657 count_or_remove_death_notes (blocks
,
658 prop_flags
& PROP_POST_REGSTACK
? -1 : 1);
662 /* Clear log links in case we are asked to (re)compute them. */
663 if (prop_flags
& PROP_LOG_LINKS
)
664 clear_log_links (blocks
);
668 sbitmap_iterator sbi
;
670 EXECUTE_IF_SET_IN_SBITMAP (blocks
, 0, i
, sbi
)
672 bb
= BASIC_BLOCK (i
);
675 /* The bitmap may be flawed in that one of the basic
676 blocks may have been deleted before you get here. */
677 COPY_REG_SET (tmp
, bb
->il
.rtl
->global_live_at_end
);
678 propagate_block (bb
, tmp
, NULL
, NULL
, stabilized_prop_flags
);
680 if (extent
== UPDATE_LIFE_LOCAL
)
681 verify_local_live_at_start (tmp
, bb
);
687 FOR_EACH_BB_REVERSE (bb
)
689 COPY_REG_SET (tmp
, bb
->il
.rtl
->global_live_at_end
);
691 propagate_block (bb
, tmp
, NULL
, NULL
, stabilized_prop_flags
);
693 if (extent
== UPDATE_LIFE_LOCAL
)
694 verify_local_live_at_start (tmp
, bb
);
700 if (prop_flags
& PROP_REG_INFO
)
702 reg_set_iterator rsi
;
704 /* The only pseudos that are live at the beginning of the function
705 are those that were not set anywhere in the function. local-alloc
706 doesn't know how to handle these correctly, so mark them as not
707 local to any one basic block. */
708 EXECUTE_IF_SET_IN_REG_SET (ENTRY_BLOCK_PTR
->il
.rtl
->global_live_at_end
,
709 FIRST_PSEUDO_REGISTER
, i
, rsi
)
710 REG_BASIC_BLOCK (i
) = REG_BLOCK_GLOBAL
;
712 /* We have a problem with any pseudoreg that lives across the setjmp.
713 ANSI says that if a user variable does not change in value between
714 the setjmp and the longjmp, then the longjmp preserves it. This
715 includes longjmp from a place where the pseudo appears dead.
716 (In principle, the value still exists if it is in scope.)
717 If the pseudo goes in a hard reg, some other value may occupy
718 that hard reg where this pseudo is dead, thus clobbering the pseudo.
719 Conclusion: such a pseudo must not go in a hard reg. */
720 EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp
,
721 FIRST_PSEUDO_REGISTER
, i
, rsi
)
723 if (regno_reg_rtx
[i
] != 0)
725 REG_LIVE_LENGTH (i
) = -1;
726 REG_BASIC_BLOCK (i
) = REG_BLOCK_UNKNOWN
;
735 timevar_pop ((extent
== UPDATE_LIFE_LOCAL
|| blocks
)
736 ? TV_LIFE_UPDATE
: TV_LIFE
);
737 if (ndead
&& dump_file
)
738 fprintf (dump_file
, "deleted %i dead insns\n", ndead
);
742 /* Update life information in all blocks where BB_DIRTY is set. */
745 update_life_info_in_dirty_blocks (enum update_life_extent extent
, int prop_flags
)
747 sbitmap update_life_blocks
= sbitmap_alloc (last_basic_block
);
752 sbitmap_zero (update_life_blocks
);
755 if (bb
->flags
& BB_DIRTY
)
757 SET_BIT (update_life_blocks
, bb
->index
);
763 retval
= update_life_info (update_life_blocks
, extent
, prop_flags
);
765 sbitmap_free (update_life_blocks
);
769 /* Free the variables allocated by find_basic_blocks. */
772 free_basic_block_vars (void)
774 if (basic_block_info
)
777 basic_block_info
= NULL
;
780 last_basic_block
= 0;
783 label_to_block_map
= NULL
;
785 ENTRY_BLOCK_PTR
->aux
= NULL
;
786 ENTRY_BLOCK_PTR
->il
.rtl
->global_live_at_end
= NULL
;
787 EXIT_BLOCK_PTR
->aux
= NULL
;
788 EXIT_BLOCK_PTR
->il
.rtl
->global_live_at_start
= NULL
;
791 /* Delete any insns that copy a register to itself. */
794 delete_noop_moves (void)
802 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
)); insn
= next
)
804 next
= NEXT_INSN (insn
);
805 if (INSN_P (insn
) && noop_move_p (insn
))
809 /* If we're about to remove the first insn of a libcall
810 then move the libcall note to the next real insn and
811 update the retval note. */
812 if ((note
= find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
))
813 && XEXP (note
, 0) != insn
)
815 rtx new_libcall_insn
= next_real_insn (insn
);
816 rtx retval_note
= find_reg_note (XEXP (note
, 0),
817 REG_RETVAL
, NULL_RTX
);
818 REG_NOTES (new_libcall_insn
)
819 = gen_rtx_INSN_LIST (REG_LIBCALL
, XEXP (note
, 0),
820 REG_NOTES (new_libcall_insn
));
821 XEXP (retval_note
, 0) = new_libcall_insn
;
824 delete_insn_and_edges (insn
);
830 if (nnoops
&& dump_file
)
831 fprintf (dump_file
, "deleted %i noop moves\n", nnoops
);
836 /* Delete any jump tables never referenced. We can't delete them at the
837 time of removing tablejump insn as they are referenced by the preceding
838 insns computing the destination, so we delay deleting and garbagecollect
839 them once life information is computed. */
841 delete_dead_jumptables (void)
845 /* A dead jump table does not belong to any basic block. Scan insns
846 between two adjacent basic blocks. */
851 for (insn
= NEXT_INSN (BB_END (bb
));
852 insn
&& !NOTE_INSN_BASIC_BLOCK_P (insn
);
855 next
= NEXT_INSN (insn
);
857 && LABEL_NUSES (insn
) == LABEL_PRESERVE_P (insn
)
859 && (GET_CODE (PATTERN (next
)) == ADDR_VEC
860 || GET_CODE (PATTERN (next
)) == ADDR_DIFF_VEC
))
862 rtx label
= insn
, jump
= next
;
865 fprintf (dump_file
, "Dead jumptable %i removed\n",
868 next
= NEXT_INSN (next
);
876 /* Determine if the stack pointer is constant over the life of the function.
877 Only useful before prologues have been emitted. */
880 notice_stack_pointer_modification_1 (rtx x
, rtx pat ATTRIBUTE_UNUSED
,
881 void *data ATTRIBUTE_UNUSED
)
883 if (x
== stack_pointer_rtx
884 /* The stack pointer is only modified indirectly as the result
885 of a push until later in flow. See the comments in rtl.texi
886 regarding Embedded Side-Effects on Addresses. */
888 && GET_RTX_CLASS (GET_CODE (XEXP (x
, 0))) == RTX_AUTOINC
889 && XEXP (XEXP (x
, 0), 0) == stack_pointer_rtx
))
890 current_function_sp_is_unchanging
= 0;
894 notice_stack_pointer_modification (void)
899 /* Assume that the stack pointer is unchanging if alloca hasn't
901 current_function_sp_is_unchanging
= !current_function_calls_alloca
;
902 if (! current_function_sp_is_unchanging
)
906 FOR_BB_INSNS (bb
, insn
)
910 /* Check if insn modifies the stack pointer. */
911 note_stores (PATTERN (insn
),
912 notice_stack_pointer_modification_1
,
914 if (! current_function_sp_is_unchanging
)
920 /* Mark a register in SET. Hard registers in large modes get all
921 of their component registers set as well. */
924 mark_reg (rtx reg
, void *xset
)
926 regset set
= (regset
) xset
;
927 int regno
= REGNO (reg
);
929 gcc_assert (GET_MODE (reg
) != BLKmode
);
931 SET_REGNO_REG_SET (set
, regno
);
932 if (regno
< FIRST_PSEUDO_REGISTER
)
934 int n
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
936 SET_REGNO_REG_SET (set
, regno
+ n
);
940 /* Mark those regs which are needed at the end of the function as live
941 at the end of the last basic block. */
944 mark_regs_live_at_end (regset set
)
948 /* If exiting needs the right stack value, consider the stack pointer
949 live at the end of the function. */
950 if ((HAVE_epilogue
&& epilogue_completed
)
951 || ! EXIT_IGNORE_STACK
952 || (! FRAME_POINTER_REQUIRED
953 && ! current_function_calls_alloca
954 && flag_omit_frame_pointer
)
955 || current_function_sp_is_unchanging
)
957 SET_REGNO_REG_SET (set
, STACK_POINTER_REGNUM
);
960 /* Mark the frame pointer if needed at the end of the function. If
961 we end up eliminating it, it will be removed from the live list
962 of each basic block by reload. */
964 if (! reload_completed
|| frame_pointer_needed
)
966 SET_REGNO_REG_SET (set
, FRAME_POINTER_REGNUM
);
967 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
968 /* If they are different, also mark the hard frame pointer as live. */
969 if (! LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM
))
970 SET_REGNO_REG_SET (set
, HARD_FRAME_POINTER_REGNUM
);
974 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
975 /* Many architectures have a GP register even without flag_pic.
976 Assume the pic register is not in use, or will be handled by
977 other means, if it is not fixed. */
978 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
979 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
980 SET_REGNO_REG_SET (set
, PIC_OFFSET_TABLE_REGNUM
);
983 /* Mark all global registers, and all registers used by the epilogue
984 as being live at the end of the function since they may be
985 referenced by our caller. */
986 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
987 if (global_regs
[i
] || EPILOGUE_USES (i
))
988 SET_REGNO_REG_SET (set
, i
);
990 if (HAVE_epilogue
&& epilogue_completed
)
992 /* Mark all call-saved registers that we actually used. */
993 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
994 if (regs_ever_live
[i
] && ! LOCAL_REGNO (i
)
995 && ! TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
996 SET_REGNO_REG_SET (set
, i
);
999 #ifdef EH_RETURN_DATA_REGNO
1000 /* Mark the registers that will contain data for the handler. */
1001 if (reload_completed
&& current_function_calls_eh_return
)
1004 unsigned regno
= EH_RETURN_DATA_REGNO(i
);
1005 if (regno
== INVALID_REGNUM
)
1007 SET_REGNO_REG_SET (set
, regno
);
1010 #ifdef EH_RETURN_STACKADJ_RTX
1011 if ((! HAVE_epilogue
|| ! epilogue_completed
)
1012 && current_function_calls_eh_return
)
1014 rtx tmp
= EH_RETURN_STACKADJ_RTX
;
1015 if (tmp
&& REG_P (tmp
))
1016 mark_reg (tmp
, set
);
1019 #ifdef EH_RETURN_HANDLER_RTX
1020 if ((! HAVE_epilogue
|| ! epilogue_completed
)
1021 && current_function_calls_eh_return
)
1023 rtx tmp
= EH_RETURN_HANDLER_RTX
;
1024 if (tmp
&& REG_P (tmp
))
1025 mark_reg (tmp
, set
);
1029 /* Mark function return value. */
1030 diddle_return_value (mark_reg
, set
);
1033 /* Propagate global life info around the graph of basic blocks. Begin
1034 considering blocks with their corresponding bit set in BLOCKS_IN.
1035 If BLOCKS_IN is null, consider it the universal set.
1037 BLOCKS_OUT is set for every block that was changed. */
1040 calculate_global_regs_live (sbitmap blocks_in
, sbitmap blocks_out
, int flags
)
1042 basic_block
*queue
, *qhead
, *qtail
, *qend
, bb
;
1043 regset tmp
, new_live_at_end
, invalidated_by_call
;
1044 regset registers_made_dead
;
1045 bool failure_strategy_required
= false;
1046 int *block_accesses
;
1048 /* The registers that are modified within this in block. */
1051 /* The registers that are conditionally modified within this block.
1052 In other words, regs that are set only as part of a COND_EXEC. */
1053 regset
*cond_local_sets
;
1057 /* Some passes used to forget clear aux field of basic block causing
1058 sick behavior here. */
1059 #ifdef ENABLE_CHECKING
1060 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, NULL
, next_bb
)
1061 gcc_assert (!bb
->aux
);
1064 tmp
= ALLOC_REG_SET (®_obstack
);
1065 new_live_at_end
= ALLOC_REG_SET (®_obstack
);
1066 invalidated_by_call
= ALLOC_REG_SET (®_obstack
);
1067 registers_made_dead
= ALLOC_REG_SET (®_obstack
);
1069 /* Inconveniently, this is only readily available in hard reg set form. */
1070 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; ++i
)
1071 if (TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
1072 SET_REGNO_REG_SET (invalidated_by_call
, i
);
1074 /* Allocate space for the sets of local properties. */
1075 local_sets
= XCNEWVEC (bitmap
, last_basic_block
);
1076 cond_local_sets
= XCNEWVEC (bitmap
, last_basic_block
);
1078 /* Create a worklist. Allocate an extra slot for the `head == tail'
1079 style test for an empty queue doesn't work with a full queue. */
1080 queue
= XNEWVEC (basic_block
, n_basic_blocks
+ 1);
1082 qhead
= qend
= queue
+ n_basic_blocks
;
1084 /* Queue the blocks set in the initial mask. Do this in reverse block
1085 number order so that we are more likely for the first round to do
1086 useful work. We use AUX non-null to flag that the block is queued. */
1090 if (TEST_BIT (blocks_in
, bb
->index
))
1105 block_accesses
= XCNEWVEC (int, last_basic_block
);
1107 /* We clean aux when we remove the initially-enqueued bbs, but we
1108 don't enqueue ENTRY and EXIT initially, so clean them upfront and
1110 ENTRY_BLOCK_PTR
->aux
= EXIT_BLOCK_PTR
->aux
= NULL
;
1113 sbitmap_zero (blocks_out
);
1115 /* We work through the queue until there are no more blocks. What
1116 is live at the end of this block is precisely the union of what
1117 is live at the beginning of all its successors. So, we set its
1118 GLOBAL_LIVE_AT_END field based on the GLOBAL_LIVE_AT_START field
1119 for its successors. Then, we compute GLOBAL_LIVE_AT_START for
1120 this block by walking through the instructions in this block in
1121 reverse order and updating as we go. If that changed
1122 GLOBAL_LIVE_AT_START, we add the predecessors of the block to the
1123 queue; they will now need to recalculate GLOBAL_LIVE_AT_END.
1125 We are guaranteed to terminate, because GLOBAL_LIVE_AT_START
1126 never shrinks. If a register appears in GLOBAL_LIVE_AT_START, it
1127 must either be live at the end of the block, or used within the
1128 block. In the latter case, it will certainly never disappear
1129 from GLOBAL_LIVE_AT_START. In the former case, the register
1130 could go away only if it disappeared from GLOBAL_LIVE_AT_START
1131 for one of the successor blocks. By induction, that cannot
1134 ??? This reasoning doesn't work if we start from non-empty initial
1135 GLOBAL_LIVE_AT_START sets. And there are actually two problems:
1136 1) Updating may not terminate (endless oscillation).
1137 2) Even if it does (and it usually does), the resulting information
1138 may be inaccurate. Consider for example the following case:
1141 while (...) {...} -- 'a' not mentioned at all
1144 If the use of 'a' is deleted between two calculations of liveness
1145 information and the initial sets are not cleared, the information
1146 about a's liveness will get stuck inside the loop and the set will
1147 appear not to be dead.
1149 We do not attempt to solve 2) -- the information is conservatively
1150 correct (i.e. we never claim that something live is dead) and the
1151 amount of optimization opportunities missed due to this problem is
1154 1) is more serious. In order to fix it, we monitor the number of times
1155 each block is processed. Once one of the blocks has been processed more
1156 times than the maximum number of rounds, we use the following strategy:
1157 When a register disappears from one of the sets, we add it to a MAKE_DEAD
1158 set, remove all registers in this set from all GLOBAL_LIVE_AT_* sets and
1159 add the blocks with changed sets into the queue. Thus we are guaranteed
1160 to terminate (the worst case corresponds to all registers in MADE_DEAD,
1161 in which case the original reasoning above is valid), but in general we
1162 only fix up a few offending registers.
1164 The maximum number of rounds for computing liveness is the largest of
1165 MAX_LIVENESS_ROUNDS and the latest loop depth count for this function. */
1167 while (qhead
!= qtail
)
1169 int rescan
, changed
;
1179 /* Should we start using the failure strategy? */
1180 if (bb
!= ENTRY_BLOCK_PTR
)
1182 int max_liveness_rounds
=
1183 MAX (MAX_LIVENESS_ROUNDS
, cfun
->max_loop_depth
);
1185 block_accesses
[bb
->index
]++;
1186 if (block_accesses
[bb
->index
] > max_liveness_rounds
)
1187 failure_strategy_required
= true;
1190 /* Begin by propagating live_at_start from the successor blocks. */
1191 CLEAR_REG_SET (new_live_at_end
);
1193 if (EDGE_COUNT (bb
->succs
) > 0)
1194 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1196 basic_block sb
= e
->dest
;
1198 /* Call-clobbered registers die across exception and
1200 /* ??? Abnormal call edges ignored for the moment, as this gets
1201 confused by sibling call edges, which crashes reg-stack. */
1202 if (e
->flags
& EDGE_EH
)
1203 bitmap_ior_and_compl_into (new_live_at_end
,
1204 sb
->il
.rtl
->global_live_at_start
,
1205 invalidated_by_call
);
1207 IOR_REG_SET (new_live_at_end
, sb
->il
.rtl
->global_live_at_start
);
1209 /* If a target saves one register in another (instead of on
1210 the stack) the save register will need to be live for EH. */
1211 if (e
->flags
& EDGE_EH
)
1212 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1214 SET_REGNO_REG_SET (new_live_at_end
, i
);
1218 /* This might be a noreturn function that throws. And
1219 even if it isn't, getting the unwind info right helps
1221 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1223 SET_REGNO_REG_SET (new_live_at_end
, i
);
1226 /* The all-important stack pointer must always be live. */
1227 SET_REGNO_REG_SET (new_live_at_end
, STACK_POINTER_REGNUM
);
1229 /* Before reload, there are a few registers that must be forced
1230 live everywhere -- which might not already be the case for
1231 blocks within infinite loops. */
1232 if (! reload_completed
)
1234 /* Any reference to any pseudo before reload is a potential
1235 reference of the frame pointer. */
1236 SET_REGNO_REG_SET (new_live_at_end
, FRAME_POINTER_REGNUM
);
1238 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1239 /* Pseudos with argument area equivalences may require
1240 reloading via the argument pointer. */
1241 if (fixed_regs
[ARG_POINTER_REGNUM
])
1242 SET_REGNO_REG_SET (new_live_at_end
, ARG_POINTER_REGNUM
);
1245 /* Any constant, or pseudo with constant equivalences, may
1246 require reloading from memory using the pic register. */
1247 if ((unsigned) PIC_OFFSET_TABLE_REGNUM
!= INVALID_REGNUM
1248 && fixed_regs
[PIC_OFFSET_TABLE_REGNUM
])
1249 SET_REGNO_REG_SET (new_live_at_end
, PIC_OFFSET_TABLE_REGNUM
);
1252 if (bb
== ENTRY_BLOCK_PTR
)
1254 COPY_REG_SET (bb
->il
.rtl
->global_live_at_end
, new_live_at_end
);
1258 /* On our first pass through this block, we'll go ahead and continue.
1259 Recognize first pass by checking if local_set is NULL for this
1260 basic block. On subsequent passes, we get to skip out early if
1261 live_at_end wouldn't have changed. */
1263 if (local_sets
[bb
->index
] == NULL
)
1265 local_sets
[bb
->index
] = ALLOC_REG_SET (®_obstack
);
1266 cond_local_sets
[bb
->index
] = ALLOC_REG_SET (®_obstack
);
1271 /* If any bits were removed from live_at_end, we'll have to
1272 rescan the block. This wouldn't be necessary if we had
1273 precalculated local_live, however with PROP_SCAN_DEAD_CODE
1274 local_live is really dependent on live_at_end. */
1275 rescan
= bitmap_intersect_compl_p (bb
->il
.rtl
->global_live_at_end
,
1280 regset cond_local_set
;
1282 /* If any of the registers in the new live_at_end set are
1283 conditionally set in this basic block, we must rescan.
1284 This is because conditional lifetimes at the end of the
1285 block do not just take the live_at_end set into
1286 account, but also the liveness at the start of each
1287 successor block. We can miss changes in those sets if
1288 we only compare the new live_at_end against the
1290 cond_local_set
= cond_local_sets
[bb
->index
];
1291 rescan
= bitmap_intersect_p (new_live_at_end
, cond_local_set
);
1298 /* Find the set of changed bits. Take this opportunity
1299 to notice that this set is empty and early out. */
1300 bitmap_xor (tmp
, bb
->il
.rtl
->global_live_at_end
, new_live_at_end
);
1301 if (bitmap_empty_p (tmp
))
1304 /* If any of the changed bits overlap with local_sets[bb],
1305 we'll have to rescan the block. */
1306 local_set
= local_sets
[bb
->index
];
1307 rescan
= bitmap_intersect_p (tmp
, local_set
);
1311 /* Let our caller know that BB changed enough to require its
1312 death notes updated. */
1314 SET_BIT (blocks_out
, bb
->index
);
1318 /* Add to live_at_start the set of all registers in
1319 new_live_at_end that aren't in the old live_at_end. */
1321 changed
= bitmap_ior_and_compl_into (bb
->il
.rtl
->global_live_at_start
,
1323 bb
->il
.rtl
->global_live_at_end
);
1324 COPY_REG_SET (bb
->il
.rtl
->global_live_at_end
, new_live_at_end
);
1330 COPY_REG_SET (bb
->il
.rtl
->global_live_at_end
, new_live_at_end
);
1332 /* Rescan the block insn by insn to turn (a copy of) live_at_end
1333 into live_at_start. */
1334 propagate_block (bb
, new_live_at_end
,
1335 local_sets
[bb
->index
],
1336 cond_local_sets
[bb
->index
],
1339 /* If live_at start didn't change, no need to go farther. */
1340 if (REG_SET_EQUAL_P (bb
->il
.rtl
->global_live_at_start
,
1344 if (failure_strategy_required
)
1346 /* Get the list of registers that were removed from the
1347 bb->global_live_at_start set. */
1348 bitmap_and_compl (tmp
, bb
->il
.rtl
->global_live_at_start
,
1350 if (!bitmap_empty_p (tmp
))
1355 /* It should not happen that one of registers we have
1356 removed last time is disappears again before any other
1358 pbb_changed
= bitmap_ior_into (registers_made_dead
, tmp
);
1359 gcc_assert (pbb_changed
);
1361 /* Now remove the registers from all sets. */
1364 pbb_changed
= false;
1367 |= bitmap_and_compl_into
1368 (pbb
->il
.rtl
->global_live_at_start
,
1369 registers_made_dead
);
1371 |= bitmap_and_compl_into
1372 (pbb
->il
.rtl
->global_live_at_end
,
1373 registers_made_dead
);
1377 /* Note the (possible) change. */
1379 SET_BIT (blocks_out
, pbb
->index
);
1381 /* Makes sure to really rescan the block. */
1382 if (local_sets
[pbb
->index
])
1384 FREE_REG_SET (local_sets
[pbb
->index
]);
1385 FREE_REG_SET (cond_local_sets
[pbb
->index
]);
1386 local_sets
[pbb
->index
] = 0;
1389 /* Add it to the queue. */
1390 if (pbb
->aux
== NULL
)
1400 } /* end of failure_strategy_required */
1402 COPY_REG_SET (bb
->il
.rtl
->global_live_at_start
, new_live_at_end
);
1405 /* Queue all predecessors of BB so that we may re-examine
1406 their live_at_end. */
1407 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
1409 basic_block pb
= e
->src
;
1411 gcc_assert ((e
->flags
& EDGE_FAKE
) == 0);
1413 if (pb
->aux
== NULL
)
1424 FREE_REG_SET (new_live_at_end
);
1425 FREE_REG_SET (invalidated_by_call
);
1426 FREE_REG_SET (registers_made_dead
);
1430 sbitmap_iterator sbi
;
1432 EXECUTE_IF_SET_IN_SBITMAP (blocks_out
, 0, i
, sbi
)
1434 basic_block bb
= BASIC_BLOCK (i
);
1435 FREE_REG_SET (local_sets
[bb
->index
]);
1436 FREE_REG_SET (cond_local_sets
[bb
->index
]);
1443 FREE_REG_SET (local_sets
[bb
->index
]);
1444 FREE_REG_SET (cond_local_sets
[bb
->index
]);
1448 free (block_accesses
);
1450 free (cond_local_sets
);
1455 /* This structure is used to pass parameters to and from the
1456 the function find_regno_partial(). It is used to pass in the
1457 register number we are looking, as well as to return any rtx
1461 unsigned regno_to_find
;
1463 } find_regno_partial_param
;
1466 /* Find the rtx for the reg numbers specified in 'data' if it is
1467 part of an expression which only uses part of the register. Return
1468 it in the structure passed in. */
1470 find_regno_partial (rtx
*ptr
, void *data
)
1472 find_regno_partial_param
*param
= (find_regno_partial_param
*)data
;
1473 unsigned reg
= param
->regno_to_find
;
1474 param
->retval
= NULL_RTX
;
1476 if (*ptr
== NULL_RTX
)
1479 switch (GET_CODE (*ptr
))
1483 case STRICT_LOW_PART
:
1484 if (REG_P (XEXP (*ptr
, 0)) && REGNO (XEXP (*ptr
, 0)) == reg
)
1486 param
->retval
= XEXP (*ptr
, 0);
1492 if (REG_P (SUBREG_REG (*ptr
))
1493 && REGNO (SUBREG_REG (*ptr
)) == reg
)
1495 param
->retval
= SUBREG_REG (*ptr
);
1507 /* Process all immediate successors of the entry block looking for pseudo
1508 registers which are live on entry. Find all of those whose first
1509 instance is a partial register reference of some kind, and initialize
1510 them to 0 after the entry block. This will prevent bit sets within
1511 registers whose value is unknown, and may contain some kind of sticky
1512 bits we don't want. */
1515 initialize_uninitialized_subregs (void)
1519 unsigned reg
, did_something
= 0;
1520 find_regno_partial_param param
;
1523 FOR_EACH_EDGE (e
, ei
, ENTRY_BLOCK_PTR
->succs
)
1525 basic_block bb
= e
->dest
;
1526 regset map
= bb
->il
.rtl
->global_live_at_start
;
1527 reg_set_iterator rsi
;
1529 EXECUTE_IF_SET_IN_REG_SET (map
, FIRST_PSEUDO_REGISTER
, reg
, rsi
)
1531 int uid
= REGNO_FIRST_UID (reg
);
1534 /* Find an insn which mentions the register we are looking for.
1535 Its preferable to have an instance of the register's rtl since
1536 there may be various flags set which we need to duplicate.
1537 If we can't find it, its probably an automatic whose initial
1538 value doesn't matter, or hopefully something we don't care about. */
1539 for (i
= get_insns (); i
&& INSN_UID (i
) != uid
; i
= NEXT_INSN (i
))
1543 /* Found the insn, now get the REG rtx, if we can. */
1544 param
.regno_to_find
= reg
;
1545 for_each_rtx (&i
, find_regno_partial
, ¶m
);
1546 if (param
.retval
!= NULL_RTX
)
1549 emit_move_insn (param
.retval
,
1550 CONST0_RTX (GET_MODE (param
.retval
)));
1551 insn
= get_insns ();
1553 insert_insn_on_edge (insn
, e
);
1561 commit_edge_insertions ();
1562 return did_something
;
1566 /* Subroutines of life analysis. */
1568 /* Allocate the permanent data structures that represent the results
1569 of life analysis. */
1572 allocate_bb_life_data (void)
1576 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, NULL
, next_bb
)
1578 if (bb
->il
.rtl
->global_live_at_start
)
1580 CLEAR_REG_SET (bb
->il
.rtl
->global_live_at_start
);
1581 CLEAR_REG_SET (bb
->il
.rtl
->global_live_at_end
);
1585 bb
->il
.rtl
->global_live_at_start
= ALLOC_REG_SET (®_obstack
);
1586 bb
->il
.rtl
->global_live_at_end
= ALLOC_REG_SET (®_obstack
);
1590 regs_live_at_setjmp
= ALLOC_REG_SET (®_obstack
);
1594 allocate_reg_life_data (void)
1598 max_regno
= max_reg_num ();
1599 gcc_assert (!reg_deaths
);
1600 reg_deaths
= XCNEWVEC (int, max_regno
);
1602 /* Recalculate the register space, in case it has grown. Old style
1603 vector oriented regsets would set regset_{size,bytes} here also. */
1604 allocate_reg_info (max_regno
, FALSE
, FALSE
);
1606 /* Reset all the data we'll collect in propagate_block and its
1608 for (i
= 0; i
< max_regno
; i
++)
1612 REG_N_DEATHS (i
) = 0;
1613 REG_N_CALLS_CROSSED (i
) = 0;
1614 REG_N_THROWING_CALLS_CROSSED (i
) = 0;
1615 REG_LIVE_LENGTH (i
) = 0;
1617 REG_BASIC_BLOCK (i
) = REG_BLOCK_UNKNOWN
;
1621 /* Delete dead instructions for propagate_block. */
1624 propagate_block_delete_insn (rtx insn
)
1626 rtx inote
= find_reg_note (insn
, REG_LABEL
, NULL_RTX
);
1628 /* If the insn referred to a label, and that label was attached to
1629 an ADDR_VEC, it's safe to delete the ADDR_VEC. In fact, it's
1630 pretty much mandatory to delete it, because the ADDR_VEC may be
1631 referencing labels that no longer exist.
1633 INSN may reference a deleted label, particularly when a jump
1634 table has been optimized into a direct jump. There's no
1635 real good way to fix up the reference to the deleted label
1636 when the label is deleted, so we just allow it here. */
1638 if (inote
&& LABEL_P (inote
))
1640 rtx label
= XEXP (inote
, 0);
1643 /* The label may be forced if it has been put in the constant
1644 pool. If that is the only use we must discard the table
1645 jump following it, but not the label itself. */
1646 if (LABEL_NUSES (label
) == 1 + LABEL_PRESERVE_P (label
)
1647 && (next
= next_nonnote_insn (label
)) != NULL
1649 && (GET_CODE (PATTERN (next
)) == ADDR_VEC
1650 || GET_CODE (PATTERN (next
)) == ADDR_DIFF_VEC
))
1652 rtx pat
= PATTERN (next
);
1653 int diff_vec_p
= GET_CODE (pat
) == ADDR_DIFF_VEC
;
1654 int len
= XVECLEN (pat
, diff_vec_p
);
1657 for (i
= 0; i
< len
; i
++)
1658 LABEL_NUSES (XEXP (XVECEXP (pat
, diff_vec_p
, i
), 0))--;
1660 delete_insn_and_edges (next
);
1665 delete_insn_and_edges (insn
);
1669 /* Delete dead libcalls for propagate_block. Return the insn
1670 before the libcall. */
1673 propagate_block_delete_libcall (rtx insn
, rtx note
)
1675 rtx first
= XEXP (note
, 0);
1676 rtx before
= PREV_INSN (first
);
1678 delete_insn_chain_and_edges (first
, insn
);
1683 /* Update the life-status of regs for one insn. Return the previous insn. */
1686 propagate_one_insn (struct propagate_block_info
*pbi
, rtx insn
)
1688 rtx prev
= PREV_INSN (insn
);
1689 int flags
= pbi
->flags
;
1690 int insn_is_dead
= 0;
1691 int libcall_is_dead
= 0;
1695 if (! INSN_P (insn
))
1698 note
= find_reg_note (insn
, REG_RETVAL
, NULL_RTX
);
1699 if (flags
& PROP_SCAN_DEAD_CODE
)
1701 insn_is_dead
= insn_dead_p (pbi
, PATTERN (insn
), 0, REG_NOTES (insn
));
1702 libcall_is_dead
= (insn_is_dead
&& note
!= 0
1703 && libcall_dead_p (pbi
, note
, insn
));
1706 /* If an instruction consists of just dead store(s) on final pass,
1708 if ((flags
& PROP_KILL_DEAD_CODE
) && insn_is_dead
)
1710 /* If we're trying to delete a prologue or epilogue instruction
1711 that isn't flagged as possibly being dead, something is wrong.
1712 But if we are keeping the stack pointer depressed, we might well
1713 be deleting insns that are used to compute the amount to update
1714 it by, so they are fine. */
1715 if (reload_completed
1716 && !(TREE_CODE (TREE_TYPE (current_function_decl
)) == FUNCTION_TYPE
1717 && (TYPE_RETURNS_STACK_DEPRESSED
1718 (TREE_TYPE (current_function_decl
))))
1719 && (((HAVE_epilogue
|| HAVE_prologue
)
1720 && prologue_epilogue_contains (insn
))
1721 || (HAVE_sibcall_epilogue
1722 && sibcall_epilogue_contains (insn
)))
1723 && find_reg_note (insn
, REG_MAYBE_DEAD
, NULL_RTX
) == 0)
1724 fatal_insn ("Attempt to delete prologue/epilogue insn:", insn
);
1726 /* Record sets. Do this even for dead instructions, since they
1727 would have killed the values if they hadn't been deleted. To
1728 be consistent, we also have to emit a clobber when we delete
1729 an insn that clobbers a live register. */
1730 pbi
->flags
|= PROP_DEAD_INSN
;
1731 mark_set_regs (pbi
, PATTERN (insn
), insn
);
1732 pbi
->flags
&= ~PROP_DEAD_INSN
;
1734 /* CC0 is now known to be dead. Either this insn used it,
1735 in which case it doesn't anymore, or clobbered it,
1736 so the next insn can't use it. */
1739 if (libcall_is_dead
)
1740 prev
= propagate_block_delete_libcall (insn
, note
);
1744 /* If INSN contains a RETVAL note and is dead, but the libcall
1745 as a whole is not dead, then we want to remove INSN, but
1746 not the whole libcall sequence.
1748 However, we need to also remove the dangling REG_LIBCALL
1749 note so that we do not have mis-matched LIBCALL/RETVAL
1750 notes. In theory we could find a new location for the
1751 REG_RETVAL note, but it hardly seems worth the effort.
1753 NOTE at this point will be the RETVAL note if it exists. */
1759 = find_reg_note (XEXP (note
, 0), REG_LIBCALL
, NULL_RTX
);
1760 remove_note (XEXP (note
, 0), libcall_note
);
1763 /* Similarly if INSN contains a LIBCALL note, remove the
1764 dangling REG_RETVAL note. */
1765 note
= find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
);
1771 = find_reg_note (XEXP (note
, 0), REG_RETVAL
, NULL_RTX
);
1772 remove_note (XEXP (note
, 0), retval_note
);
1775 /* Now delete INSN. */
1776 propagate_block_delete_insn (insn
);
1782 /* See if this is an increment or decrement that can be merged into
1783 a following memory address. */
1786 rtx x
= single_set (insn
);
1788 /* Does this instruction increment or decrement a register? */
1789 if ((flags
& PROP_AUTOINC
)
1791 && REG_P (SET_DEST (x
))
1792 && (GET_CODE (SET_SRC (x
)) == PLUS
1793 || GET_CODE (SET_SRC (x
)) == MINUS
)
1794 && XEXP (SET_SRC (x
), 0) == SET_DEST (x
)
1795 && GET_CODE (XEXP (SET_SRC (x
), 1)) == CONST_INT
1796 /* Ok, look for a following memory ref we can combine with.
1797 If one is found, change the memory ref to a PRE_INC
1798 or PRE_DEC, cancel this insn, and return 1.
1799 Return 0 if nothing has been done. */
1800 && try_pre_increment_1 (pbi
, insn
))
1803 #endif /* AUTO_INC_DEC */
1805 CLEAR_REG_SET (pbi
->new_set
);
1807 /* If this is not the final pass, and this insn is copying the value of
1808 a library call and it's dead, don't scan the insns that perform the
1809 library call, so that the call's arguments are not marked live. */
1810 if (libcall_is_dead
)
1812 /* Record the death of the dest reg. */
1813 mark_set_regs (pbi
, PATTERN (insn
), insn
);
1815 insn
= XEXP (note
, 0);
1816 return PREV_INSN (insn
);
1818 else if (GET_CODE (PATTERN (insn
)) == SET
1819 && SET_DEST (PATTERN (insn
)) == stack_pointer_rtx
1820 && GET_CODE (SET_SRC (PATTERN (insn
))) == PLUS
1821 && XEXP (SET_SRC (PATTERN (insn
)), 0) == stack_pointer_rtx
1822 && GET_CODE (XEXP (SET_SRC (PATTERN (insn
)), 1)) == CONST_INT
)
1824 /* We have an insn to pop a constant amount off the stack.
1825 (Such insns use PLUS regardless of the direction of the stack,
1826 and any insn to adjust the stack by a constant is always a pop
1828 These insns, if not dead stores, have no effect on life, though
1829 they do have an effect on the memory stores we are tracking. */
1830 invalidate_mems_from_set (pbi
, stack_pointer_rtx
);
1831 /* Still, we need to update local_set, lest ifcvt.c:dead_or_predicable
1832 concludes that the stack pointer is not modified. */
1833 mark_set_regs (pbi
, PATTERN (insn
), insn
);
1837 /* Any regs live at the time of a call instruction must not go
1838 in a register clobbered by calls. Find all regs now live and
1839 record this for them. */
1841 if (CALL_P (insn
) && (flags
& PROP_REG_INFO
))
1843 reg_set_iterator rsi
;
1844 EXECUTE_IF_SET_IN_REG_SET (pbi
->reg_live
, 0, i
, rsi
)
1845 REG_N_CALLS_CROSSED (i
)++;
1846 if (can_throw_internal (insn
))
1847 EXECUTE_IF_SET_IN_REG_SET (pbi
->reg_live
, 0, i
, rsi
)
1848 REG_N_THROWING_CALLS_CROSSED (i
)++;
1851 /* Record sets. Do this even for dead instructions, since they
1852 would have killed the values if they hadn't been deleted. */
1853 mark_set_regs (pbi
, PATTERN (insn
), insn
);
1863 if (GET_CODE (PATTERN (insn
)) == COND_EXEC
)
1864 cond
= COND_EXEC_TEST (PATTERN (insn
));
1866 /* Non-constant calls clobber memory, constant calls do not
1867 clobber memory, though they may clobber outgoing arguments
1869 if (! CONST_OR_PURE_CALL_P (insn
))
1871 free_EXPR_LIST_list (&pbi
->mem_set_list
);
1872 pbi
->mem_set_list_len
= 0;
1875 invalidate_mems_from_set (pbi
, stack_pointer_rtx
);
1877 /* There may be extra registers to be clobbered. */
1878 for (note
= CALL_INSN_FUNCTION_USAGE (insn
);
1880 note
= XEXP (note
, 1))
1881 if (GET_CODE (XEXP (note
, 0)) == CLOBBER
)
1882 mark_set_1 (pbi
, CLOBBER
, XEXP (XEXP (note
, 0), 0),
1883 cond
, insn
, pbi
->flags
);
1885 /* Calls change all call-used and global registers; sibcalls do not
1886 clobber anything that must be preserved at end-of-function,
1887 except for return values. */
1889 sibcall_p
= SIBLING_CALL_P (insn
);
1890 live_at_end
= EXIT_BLOCK_PTR
->il
.rtl
->global_live_at_start
;
1891 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1892 if (TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
)
1894 && REGNO_REG_SET_P (live_at_end
, i
)
1895 && ! refers_to_regno_p (i
, i
+1,
1896 current_function_return_rtx
,
1899 enum rtx_code code
= global_regs
[i
] ? SET
: CLOBBER
;
1900 /* We do not want REG_UNUSED notes for these registers. */
1901 mark_set_1 (pbi
, code
, regno_reg_rtx
[i
], cond
, insn
,
1902 pbi
->flags
& ~(PROP_DEATH_NOTES
| PROP_REG_INFO
));
1906 /* If an insn doesn't use CC0, it becomes dead since we assume
1907 that every insn clobbers it. So show it dead here;
1908 mark_used_regs will set it live if it is referenced. */
1913 mark_used_regs (pbi
, PATTERN (insn
), NULL_RTX
, insn
);
1915 /* Sometimes we may have inserted something before INSN (such as a move)
1916 when we make an auto-inc. So ensure we will scan those insns. */
1918 prev
= PREV_INSN (insn
);
1921 if (! insn_is_dead
&& CALL_P (insn
))
1927 if (GET_CODE (PATTERN (insn
)) == COND_EXEC
)
1928 cond
= COND_EXEC_TEST (PATTERN (insn
));
1930 /* Calls use their arguments, and may clobber memory which
1931 address involves some register. */
1932 for (note
= CALL_INSN_FUNCTION_USAGE (insn
);
1934 note
= XEXP (note
, 1))
1935 /* We find USE or CLOBBER entities in a FUNCTION_USAGE list: both
1936 of which mark_used_regs knows how to handle. */
1937 mark_used_regs (pbi
, XEXP (XEXP (note
, 0), 0), cond
, insn
);
1939 /* The stack ptr is used (honorarily) by a CALL insn. */
1940 if ((flags
& PROP_REG_INFO
)
1941 && !REGNO_REG_SET_P (pbi
->reg_live
, STACK_POINTER_REGNUM
))
1942 reg_deaths
[STACK_POINTER_REGNUM
] = pbi
->insn_num
;
1943 SET_REGNO_REG_SET (pbi
->reg_live
, STACK_POINTER_REGNUM
);
1945 /* Calls may also reference any of the global registers,
1946 so they are made live. */
1947 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1949 mark_used_reg (pbi
, regno_reg_rtx
[i
], cond
, insn
);
1958 /* Initialize a propagate_block_info struct for public consumption.
1959 Note that the structure itself is opaque to this file, but that
1960 the user can use the regsets provided here. */
1962 struct propagate_block_info
*
1963 init_propagate_block_info (basic_block bb
, regset live
, regset local_set
,
1964 regset cond_local_set
, int flags
)
1966 struct propagate_block_info
*pbi
= XNEW (struct propagate_block_info
);
1969 pbi
->reg_live
= live
;
1970 pbi
->mem_set_list
= NULL_RTX
;
1971 pbi
->mem_set_list_len
= 0;
1972 pbi
->local_set
= local_set
;
1973 pbi
->cond_local_set
= cond_local_set
;
1978 if (flags
& (PROP_LOG_LINKS
| PROP_AUTOINC
))
1979 pbi
->reg_next_use
= XCNEWVEC (rtx
, max_reg_num ());
1981 pbi
->reg_next_use
= NULL
;
1983 pbi
->new_set
= BITMAP_ALLOC (NULL
);
1985 #ifdef HAVE_conditional_execution
1986 pbi
->reg_cond_dead
= splay_tree_new (splay_tree_compare_ints
, NULL
,
1987 free_reg_cond_life_info
);
1988 pbi
->reg_cond_reg
= BITMAP_ALLOC (NULL
);
1990 /* If this block ends in a conditional branch, for each register
1991 live from one side of the branch and not the other, record the
1992 register as conditionally dead. */
1993 if (JUMP_P (BB_END (bb
))
1994 && any_condjump_p (BB_END (bb
)))
1996 regset diff
= ALLOC_REG_SET (®_obstack
);
1997 basic_block bb_true
, bb_false
;
2000 /* Identify the successor blocks. */
2001 bb_true
= EDGE_SUCC (bb
, 0)->dest
;
2002 if (!single_succ_p (bb
))
2004 bb_false
= EDGE_SUCC (bb
, 1)->dest
;
2006 if (EDGE_SUCC (bb
, 0)->flags
& EDGE_FALLTHRU
)
2008 basic_block t
= bb_false
;
2013 gcc_assert (EDGE_SUCC (bb
, 1)->flags
& EDGE_FALLTHRU
);
2017 /* This can happen with a conditional jump to the next insn. */
2018 gcc_assert (JUMP_LABEL (BB_END (bb
)) == BB_HEAD (bb_true
));
2020 /* Simplest way to do nothing. */
2024 /* Compute which register lead different lives in the successors. */
2025 bitmap_xor (diff
, bb_true
->il
.rtl
->global_live_at_start
,
2026 bb_false
->il
.rtl
->global_live_at_start
);
2028 if (!bitmap_empty_p (diff
))
2030 /* Extract the condition from the branch. */
2031 rtx set_src
= SET_SRC (pc_set (BB_END (bb
)));
2032 rtx cond_true
= XEXP (set_src
, 0);
2033 rtx reg
= XEXP (cond_true
, 0);
2034 enum rtx_code inv_cond
;
2036 if (GET_CODE (reg
) == SUBREG
)
2037 reg
= SUBREG_REG (reg
);
2039 /* We can only track conditional lifetimes if the condition is
2040 in the form of a reversible comparison of a register against
2041 zero. If the condition is more complex than that, then it is
2042 safe not to record any information. */
2043 inv_cond
= reversed_comparison_code (cond_true
, BB_END (bb
));
2044 if (inv_cond
!= UNKNOWN
2046 && XEXP (cond_true
, 1) == const0_rtx
)
2049 = gen_rtx_fmt_ee (inv_cond
,
2050 GET_MODE (cond_true
), XEXP (cond_true
, 0),
2051 XEXP (cond_true
, 1));
2052 reg_set_iterator rsi
;
2054 if (GET_CODE (XEXP (set_src
, 1)) == PC
)
2057 cond_false
= cond_true
;
2061 SET_REGNO_REG_SET (pbi
->reg_cond_reg
, REGNO (reg
));
2063 /* For each such register, mark it conditionally dead. */
2064 EXECUTE_IF_SET_IN_REG_SET (diff
, 0, i
, rsi
)
2066 struct reg_cond_life_info
*rcli
;
2069 rcli
= XNEW (struct reg_cond_life_info
);
2071 if (REGNO_REG_SET_P (bb_true
->il
.rtl
->global_live_at_start
,
2076 rcli
->condition
= cond
;
2077 rcli
->stores
= const0_rtx
;
2078 rcli
->orig_condition
= cond
;
2080 splay_tree_insert (pbi
->reg_cond_dead
, i
,
2081 (splay_tree_value
) rcli
);
2086 FREE_REG_SET (diff
);
2090 /* If this block has no successors, any stores to the frame that aren't
2091 used later in the block are dead. So make a pass over the block
2092 recording any such that are made and show them dead at the end. We do
2093 a very conservative and simple job here. */
2095 && ! (TREE_CODE (TREE_TYPE (current_function_decl
)) == FUNCTION_TYPE
2096 && (TYPE_RETURNS_STACK_DEPRESSED
2097 (TREE_TYPE (current_function_decl
))))
2098 && (flags
& PROP_SCAN_DEAD_STORES
)
2099 && (EDGE_COUNT (bb
->succs
) == 0
2100 || (single_succ_p (bb
)
2101 && single_succ (bb
) == EXIT_BLOCK_PTR
2102 && ! current_function_calls_eh_return
)))
2105 for (insn
= BB_END (bb
); insn
!= BB_HEAD (bb
); insn
= PREV_INSN (insn
))
2106 if (NONJUMP_INSN_P (insn
)
2107 && (set
= single_set (insn
))
2108 && MEM_P (SET_DEST (set
)))
2110 rtx mem
= SET_DEST (set
);
2111 rtx canon_mem
= canon_rtx (mem
);
2113 if (XEXP (canon_mem
, 0) == frame_pointer_rtx
2114 || (GET_CODE (XEXP (canon_mem
, 0)) == PLUS
2115 && XEXP (XEXP (canon_mem
, 0), 0) == frame_pointer_rtx
2116 && GET_CODE (XEXP (XEXP (canon_mem
, 0), 1)) == CONST_INT
))
2117 add_to_mem_set_list (pbi
, canon_mem
);
2124 /* Release a propagate_block_info struct. */
2127 free_propagate_block_info (struct propagate_block_info
*pbi
)
2129 free_EXPR_LIST_list (&pbi
->mem_set_list
);
2131 BITMAP_FREE (pbi
->new_set
);
2133 #ifdef HAVE_conditional_execution
2134 splay_tree_delete (pbi
->reg_cond_dead
);
2135 BITMAP_FREE (pbi
->reg_cond_reg
);
2138 if (pbi
->flags
& PROP_REG_INFO
)
2140 int num
= pbi
->insn_num
;
2142 reg_set_iterator rsi
;
2144 EXECUTE_IF_SET_IN_REG_SET (pbi
->reg_live
, 0, i
, rsi
)
2146 REG_LIVE_LENGTH (i
) += num
- reg_deaths
[i
];
2150 if (pbi
->reg_next_use
)
2151 free (pbi
->reg_next_use
);
2156 /* Compute the registers live at the beginning of a basic block BB from
2157 those live at the end.
2159 When called, REG_LIVE contains those live at the end. On return, it
2160 contains those live at the beginning.
2162 LOCAL_SET, if non-null, will be set with all registers killed
2163 unconditionally by this basic block.
2164 Likewise, COND_LOCAL_SET, if non-null, will be set with all registers
2165 killed conditionally by this basic block. If there is any unconditional
2166 set of a register, then the corresponding bit will be set in LOCAL_SET
2167 and cleared in COND_LOCAL_SET.
2168 It is valid for LOCAL_SET and COND_LOCAL_SET to be the same set. In this
2169 case, the resulting set will be equal to the union of the two sets that
2170 would otherwise be computed.
2172 Return nonzero if an INSN is deleted (i.e. by dead code removal). */
2175 propagate_block (basic_block bb
, regset live
, regset local_set
,
2176 regset cond_local_set
, int flags
)
2178 struct propagate_block_info
*pbi
;
2182 pbi
= init_propagate_block_info (bb
, live
, local_set
, cond_local_set
, flags
);
2184 if (flags
& PROP_REG_INFO
)
2187 reg_set_iterator rsi
;
2189 /* Process the regs live at the end of the block.
2190 Mark them as not local to any one basic block. */
2191 EXECUTE_IF_SET_IN_REG_SET (live
, 0, i
, rsi
)
2192 REG_BASIC_BLOCK (i
) = REG_BLOCK_GLOBAL
;
2195 /* Scan the block an insn at a time from end to beginning. */
2198 for (insn
= BB_END (bb
); ; insn
= prev
)
2200 /* If this is a call to `setjmp' et al, warn if any
2201 non-volatile datum is live. */
2202 if ((flags
& PROP_REG_INFO
)
2204 && find_reg_note (insn
, REG_SETJMP
, NULL
))
2205 IOR_REG_SET (regs_live_at_setjmp
, pbi
->reg_live
);
2207 prev
= propagate_one_insn (pbi
, insn
);
2209 changed
|= insn
!= get_insns ();
2211 changed
|= NEXT_INSN (prev
) != insn
;
2213 if (insn
== BB_HEAD (bb
))
2217 free_propagate_block_info (pbi
);
2222 /* Return 1 if X (the body of an insn, or part of it) is just dead stores
2223 (SET expressions whose destinations are registers dead after the insn).
2224 NEEDED is the regset that says which regs are alive after the insn.
2226 Unless CALL_OK is nonzero, an insn is needed if it contains a CALL.
2228 If X is the entire body of an insn, NOTES contains the reg notes
2229 pertaining to the insn. */
2232 insn_dead_p (struct propagate_block_info
*pbi
, rtx x
, int call_ok
,
2233 rtx notes ATTRIBUTE_UNUSED
)
2235 enum rtx_code code
= GET_CODE (x
);
2237 /* Don't eliminate insns that may trap. */
2238 if (flag_non_call_exceptions
&& may_trap_p (x
))
2242 /* As flow is invoked after combine, we must take existing AUTO_INC
2243 expressions into account. */
2244 for (; notes
; notes
= XEXP (notes
, 1))
2246 if (REG_NOTE_KIND (notes
) == REG_INC
)
2248 int regno
= REGNO (XEXP (notes
, 0));
2250 /* Don't delete insns to set global regs. */
2251 if ((regno
< FIRST_PSEUDO_REGISTER
&& global_regs
[regno
])
2252 || REGNO_REG_SET_P (pbi
->reg_live
, regno
))
2258 /* If setting something that's a reg or part of one,
2259 see if that register's altered value will be live. */
2263 rtx r
= SET_DEST (x
);
2266 if (GET_CODE (r
) == CC0
)
2267 return ! pbi
->cc0_live
;
2270 /* A SET that is a subroutine call cannot be dead. */
2271 if (GET_CODE (SET_SRC (x
)) == CALL
)
2277 /* Don't eliminate loads from volatile memory or volatile asms. */
2278 else if (volatile_refs_p (SET_SRC (x
)))
2285 if (MEM_VOLATILE_P (r
) || GET_MODE (r
) == BLKmode
)
2288 canon_r
= canon_rtx (r
);
2290 /* Walk the set of memory locations we are currently tracking
2291 and see if one is an identical match to this memory location.
2292 If so, this memory write is dead (remember, we're walking
2293 backwards from the end of the block to the start). Since
2294 rtx_equal_p does not check the alias set or flags, we also
2295 must have the potential for them to conflict (anti_dependence). */
2296 for (temp
= pbi
->mem_set_list
; temp
!= 0; temp
= XEXP (temp
, 1))
2297 if (anti_dependence (r
, XEXP (temp
, 0)))
2299 rtx mem
= XEXP (temp
, 0);
2301 if (rtx_equal_p (XEXP (canon_r
, 0), XEXP (mem
, 0))
2302 && (GET_MODE_SIZE (GET_MODE (canon_r
))
2303 <= GET_MODE_SIZE (GET_MODE (mem
))))
2307 /* Check if memory reference matches an auto increment. Only
2308 post increment/decrement or modify are valid. */
2309 if (GET_MODE (mem
) == GET_MODE (r
)
2310 && (GET_CODE (XEXP (mem
, 0)) == POST_DEC
2311 || GET_CODE (XEXP (mem
, 0)) == POST_INC
2312 || GET_CODE (XEXP (mem
, 0)) == POST_MODIFY
)
2313 && GET_MODE (XEXP (mem
, 0)) == GET_MODE (r
)
2314 && rtx_equal_p (XEXP (XEXP (mem
, 0), 0), XEXP (r
, 0)))
2321 while (GET_CODE (r
) == SUBREG
2322 || GET_CODE (r
) == STRICT_LOW_PART
2323 || GET_CODE (r
) == ZERO_EXTRACT
)
2328 int regno
= REGNO (r
);
2331 if (REGNO_REG_SET_P (pbi
->reg_live
, regno
))
2334 /* If this is a hard register, verify that subsequent
2335 words are not needed. */
2336 if (regno
< FIRST_PSEUDO_REGISTER
)
2338 int n
= hard_regno_nregs
[regno
][GET_MODE (r
)];
2341 if (REGNO_REG_SET_P (pbi
->reg_live
, regno
+n
))
2345 /* Don't delete insns to set global regs. */
2346 if (regno
< FIRST_PSEUDO_REGISTER
&& global_regs
[regno
])
2349 /* Make sure insns to set the stack pointer aren't deleted. */
2350 if (regno
== STACK_POINTER_REGNUM
)
2353 /* ??? These bits might be redundant with the force live bits
2354 in calculate_global_regs_live. We would delete from
2355 sequential sets; whether this actually affects real code
2356 for anything but the stack pointer I don't know. */
2357 /* Make sure insns to set the frame pointer aren't deleted. */
2358 if (regno
== FRAME_POINTER_REGNUM
2359 && (! reload_completed
|| frame_pointer_needed
))
2361 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2362 if (regno
== HARD_FRAME_POINTER_REGNUM
2363 && (! reload_completed
|| frame_pointer_needed
))
2367 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2368 /* Make sure insns to set arg pointer are never deleted
2369 (if the arg pointer isn't fixed, there will be a USE
2370 for it, so we can treat it normally). */
2371 if (regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
2375 /* Otherwise, the set is dead. */
2381 /* If performing several activities, insn is dead if each activity
2382 is individually dead. Also, CLOBBERs and USEs can be ignored; a
2383 CLOBBER or USE that's inside a PARALLEL doesn't make the insn
2385 else if (code
== PARALLEL
)
2387 int i
= XVECLEN (x
, 0);
2389 for (i
--; i
>= 0; i
--)
2390 if (GET_CODE (XVECEXP (x
, 0, i
)) != CLOBBER
2391 && GET_CODE (XVECEXP (x
, 0, i
)) != USE
2392 && ! insn_dead_p (pbi
, XVECEXP (x
, 0, i
), call_ok
, NULL_RTX
))
2398 /* A CLOBBER of a pseudo-register that is dead serves no purpose. That
2399 is not necessarily true for hard registers until after reload. */
2400 else if (code
== CLOBBER
)
2402 if (REG_P (XEXP (x
, 0))
2403 && (REGNO (XEXP (x
, 0)) >= FIRST_PSEUDO_REGISTER
2404 || reload_completed
)
2405 && ! REGNO_REG_SET_P (pbi
->reg_live
, REGNO (XEXP (x
, 0))))
2409 /* ??? A base USE is a historical relic. It ought not be needed anymore.
2410 Instances where it is still used are either (1) temporary and the USE
2411 escaped the pass, (2) cruft and the USE need not be emitted anymore,
2412 or (3) hiding bugs elsewhere that are not properly representing data
2418 /* If INSN is the last insn in a libcall, and assuming INSN is dead,
2419 return 1 if the entire library call is dead.
2420 This is true if INSN copies a register (hard or pseudo)
2421 and if the hard return reg of the call insn is dead.
2422 (The caller should have tested the destination of the SET inside
2423 INSN already for death.)
2425 If this insn doesn't just copy a register, then we don't
2426 have an ordinary libcall. In that case, cse could not have
2427 managed to substitute the source for the dest later on,
2428 so we can assume the libcall is dead.
2430 PBI is the block info giving pseudoregs live before this insn.
2431 NOTE is the REG_RETVAL note of the insn. */
2434 libcall_dead_p (struct propagate_block_info
*pbi
, rtx note
, rtx insn
)
2436 rtx x
= single_set (insn
);
2440 rtx r
= SET_SRC (x
);
2442 if (REG_P (r
) || GET_CODE (r
) == SUBREG
)
2444 rtx call
= XEXP (note
, 0);
2448 /* Find the call insn. */
2449 while (call
!= insn
&& !CALL_P (call
))
2450 call
= NEXT_INSN (call
);
2452 /* If there is none, do nothing special,
2453 since ordinary death handling can understand these insns. */
2457 /* See if the hard reg holding the value is dead.
2458 If this is a PARALLEL, find the call within it. */
2459 call_pat
= PATTERN (call
);
2460 if (GET_CODE (call_pat
) == PARALLEL
)
2462 for (i
= XVECLEN (call_pat
, 0) - 1; i
>= 0; i
--)
2463 if (GET_CODE (XVECEXP (call_pat
, 0, i
)) == SET
2464 && GET_CODE (SET_SRC (XVECEXP (call_pat
, 0, i
))) == CALL
)
2467 /* This may be a library call that is returning a value
2468 via invisible pointer. Do nothing special, since
2469 ordinary death handling can understand these insns. */
2473 call_pat
= XVECEXP (call_pat
, 0, i
);
2476 if (! insn_dead_p (pbi
, call_pat
, 1, REG_NOTES (call
)))
2479 while ((insn
= PREV_INSN (insn
)) != call
)
2481 if (! INSN_P (insn
))
2483 if (! insn_dead_p (pbi
, PATTERN (insn
), 0, REG_NOTES (insn
)))
2492 /* 1 if register REGNO was alive at a place where `setjmp' was called
2493 and was set more than once or is an argument.
2494 Such regs may be clobbered by `longjmp'. */
2497 regno_clobbered_at_setjmp (int regno
)
2499 if (n_basic_blocks
== NUM_FIXED_BLOCKS
)
2502 return ((REG_N_SETS (regno
) > 1
2503 || REGNO_REG_SET_P (ENTRY_BLOCK_PTR
->il
.rtl
->global_live_at_end
,
2505 && REGNO_REG_SET_P (regs_live_at_setjmp
, regno
));
2508 /* Add MEM to PBI->MEM_SET_LIST. MEM should be canonical. Respect the
2509 maximal list size; look for overlaps in mode and select the largest. */
2511 add_to_mem_set_list (struct propagate_block_info
*pbi
, rtx mem
)
2515 /* We don't know how large a BLKmode store is, so we must not
2516 take them into consideration. */
2517 if (GET_MODE (mem
) == BLKmode
)
2520 for (i
= pbi
->mem_set_list
; i
; i
= XEXP (i
, 1))
2522 rtx e
= XEXP (i
, 0);
2523 if (rtx_equal_p (XEXP (mem
, 0), XEXP (e
, 0)))
2525 if (GET_MODE_SIZE (GET_MODE (mem
)) > GET_MODE_SIZE (GET_MODE (e
)))
2528 /* If we must store a copy of the mem, we can just modify
2529 the mode of the stored copy. */
2530 if (pbi
->flags
& PROP_AUTOINC
)
2531 PUT_MODE (e
, GET_MODE (mem
));
2540 if (pbi
->mem_set_list_len
< PARAM_VALUE (PARAM_MAX_FLOW_MEMORY_LOCATIONS
))
2543 /* Store a copy of mem, otherwise the address may be
2544 scrogged by find_auto_inc. */
2545 if (pbi
->flags
& PROP_AUTOINC
)
2546 mem
= shallow_copy_rtx (mem
);
2548 pbi
->mem_set_list
= alloc_EXPR_LIST (0, mem
, pbi
->mem_set_list
);
2549 pbi
->mem_set_list_len
++;
2553 /* INSN references memory, possibly using autoincrement addressing modes.
2554 Find any entries on the mem_set_list that need to be invalidated due
2555 to an address change. */
2558 invalidate_mems_from_autoinc (rtx
*px
, void *data
)
2561 struct propagate_block_info
*pbi
= data
;
2563 if (GET_RTX_CLASS (GET_CODE (x
)) == RTX_AUTOINC
)
2565 invalidate_mems_from_set (pbi
, XEXP (x
, 0));
2572 /* EXP is a REG or MEM. Remove any dependent entries from
2573 pbi->mem_set_list. */
2576 invalidate_mems_from_set (struct propagate_block_info
*pbi
, rtx exp
)
2578 rtx temp
= pbi
->mem_set_list
;
2579 rtx prev
= NULL_RTX
;
2584 next
= XEXP (temp
, 1);
2585 if ((REG_P (exp
) && reg_overlap_mentioned_p (exp
, XEXP (temp
, 0)))
2586 /* When we get an EXP that is a mem here, we want to check if EXP
2587 overlaps the *address* of any of the mems in the list (i.e. not
2588 whether the mems actually overlap; that's done elsewhere). */
2590 && reg_overlap_mentioned_p (exp
, XEXP (XEXP (temp
, 0), 0))))
2592 /* Splice this entry out of the list. */
2594 XEXP (prev
, 1) = next
;
2596 pbi
->mem_set_list
= next
;
2597 free_EXPR_LIST_node (temp
);
2598 pbi
->mem_set_list_len
--;
2606 /* Process the registers that are set within X. Their bits are set to
2607 1 in the regset DEAD, because they are dead prior to this insn.
2609 If INSN is nonzero, it is the insn being processed.
2611 FLAGS is the set of operations to perform. */
2614 mark_set_regs (struct propagate_block_info
*pbi
, rtx x
, rtx insn
)
2616 rtx cond
= NULL_RTX
;
2619 int flags
= pbi
->flags
;
2622 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2624 if (REG_NOTE_KIND (link
) == REG_INC
)
2625 mark_set_1 (pbi
, SET
, XEXP (link
, 0),
2626 (GET_CODE (x
) == COND_EXEC
2627 ? COND_EXEC_TEST (x
) : NULL_RTX
),
2631 switch (code
= GET_CODE (x
))
2634 if (GET_CODE (XEXP (x
, 1)) == ASM_OPERANDS
)
2635 flags
|= PROP_ASM_SCAN
;
2638 mark_set_1 (pbi
, code
, SET_DEST (x
), cond
, insn
, flags
);
2642 cond
= COND_EXEC_TEST (x
);
2643 x
= COND_EXEC_CODE (x
);
2650 /* We must scan forwards. If we have an asm, we need to set
2651 the PROP_ASM_SCAN flag before scanning the clobbers. */
2652 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
2654 rtx sub
= XVECEXP (x
, 0, i
);
2655 switch (code
= GET_CODE (sub
))
2660 cond
= COND_EXEC_TEST (sub
);
2661 sub
= COND_EXEC_CODE (sub
);
2662 if (GET_CODE (sub
) == SET
)
2664 if (GET_CODE (sub
) == CLOBBER
)
2670 if (GET_CODE (XEXP (sub
, 1)) == ASM_OPERANDS
)
2671 flags
|= PROP_ASM_SCAN
;
2675 mark_set_1 (pbi
, code
, SET_DEST (sub
), cond
, insn
, flags
);
2679 flags
|= PROP_ASM_SCAN
;
2694 /* Process a single set, which appears in INSN. REG (which may not
2695 actually be a REG, it may also be a SUBREG, PARALLEL, etc.) is
2696 being set using the CODE (which may be SET, CLOBBER, or COND_EXEC).
2697 If the set is conditional (because it appear in a COND_EXEC), COND
2698 will be the condition. */
2701 mark_set_1 (struct propagate_block_info
*pbi
, enum rtx_code code
, rtx reg
, rtx cond
, rtx insn
, int flags
)
2703 int regno_first
= -1, regno_last
= -1;
2704 unsigned long not_dead
= 0;
2707 /* Modifying just one hardware register of a multi-reg value or just a
2708 byte field of a register does not mean the value from before this insn
2709 is now dead. Of course, if it was dead after it's unused now. */
2711 switch (GET_CODE (reg
))
2714 /* Some targets place small structures in registers for return values of
2715 functions. We have to detect this case specially here to get correct
2716 flow information. */
2717 for (i
= XVECLEN (reg
, 0) - 1; i
>= 0; i
--)
2718 if (XEXP (XVECEXP (reg
, 0, i
), 0) != 0)
2719 mark_set_1 (pbi
, code
, XEXP (XVECEXP (reg
, 0, i
), 0), cond
, insn
,
2724 /* SIGN_EXTRACT cannot be an lvalue. */
2728 case STRICT_LOW_PART
:
2729 /* ??? Assumes STRICT_LOW_PART not used on multi-word registers. */
2731 reg
= XEXP (reg
, 0);
2732 while (GET_CODE (reg
) == SUBREG
2733 || GET_CODE (reg
) == ZERO_EXTRACT
2734 || GET_CODE (reg
) == STRICT_LOW_PART
);
2737 not_dead
= (unsigned long) REGNO_REG_SET_P (pbi
->reg_live
, REGNO (reg
));
2741 regno_last
= regno_first
= REGNO (reg
);
2742 if (regno_first
< FIRST_PSEUDO_REGISTER
)
2743 regno_last
+= hard_regno_nregs
[regno_first
][GET_MODE (reg
)] - 1;
2747 if (REG_P (SUBREG_REG (reg
)))
2749 enum machine_mode outer_mode
= GET_MODE (reg
);
2750 enum machine_mode inner_mode
= GET_MODE (SUBREG_REG (reg
));
2752 /* Identify the range of registers affected. This is moderately
2753 tricky for hard registers. See alter_subreg. */
2755 regno_last
= regno_first
= REGNO (SUBREG_REG (reg
));
2756 if (regno_first
< FIRST_PSEUDO_REGISTER
)
2758 regno_first
+= subreg_regno_offset (regno_first
, inner_mode
,
2761 regno_last
= (regno_first
2762 + hard_regno_nregs
[regno_first
][outer_mode
] - 1);
2764 /* Since we've just adjusted the register number ranges, make
2765 sure REG matches. Otherwise some_was_live will be clear
2766 when it shouldn't have been, and we'll create incorrect
2767 REG_UNUSED notes. */
2768 reg
= gen_rtx_REG (outer_mode
, regno_first
);
2772 /* If the number of words in the subreg is less than the number
2773 of words in the full register, we have a well-defined partial
2774 set. Otherwise the high bits are undefined.
2776 This is only really applicable to pseudos, since we just took
2777 care of multi-word hard registers. */
2778 if (((GET_MODE_SIZE (outer_mode
)
2779 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
)
2780 < ((GET_MODE_SIZE (inner_mode
)
2781 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
))
2782 not_dead
= (unsigned long) REGNO_REG_SET_P (pbi
->reg_live
,
2785 reg
= SUBREG_REG (reg
);
2789 reg
= SUBREG_REG (reg
);
2796 /* If this set is a MEM, then it kills any aliased writes and any
2797 other MEMs which use it.
2798 If this set is a REG, then it kills any MEMs which use the reg. */
2799 if (optimize
&& (flags
& PROP_SCAN_DEAD_STORES
))
2801 if (REG_P (reg
) || MEM_P (reg
))
2802 invalidate_mems_from_set (pbi
, reg
);
2804 /* If the memory reference had embedded side effects (autoincrement
2805 address modes) then we may need to kill some entries on the
2807 if (insn
&& MEM_P (reg
))
2808 for_each_rtx (&PATTERN (insn
), invalidate_mems_from_autoinc
, pbi
);
2810 if (MEM_P (reg
) && ! side_effects_p (reg
)
2811 /* ??? With more effort we could track conditional memory life. */
2813 add_to_mem_set_list (pbi
, canon_rtx (reg
));
2817 && ! (regno_first
== FRAME_POINTER_REGNUM
2818 && (! reload_completed
|| frame_pointer_needed
))
2819 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2820 && ! (regno_first
== HARD_FRAME_POINTER_REGNUM
2821 && (! reload_completed
|| frame_pointer_needed
))
2823 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2824 && ! (regno_first
== ARG_POINTER_REGNUM
&& fixed_regs
[regno_first
])
2828 int some_was_live
= 0, some_was_dead
= 0;
2830 for (i
= regno_first
; i
<= regno_last
; ++i
)
2832 int needed_regno
= REGNO_REG_SET_P (pbi
->reg_live
, i
);
2835 /* Order of the set operation matters here since both
2836 sets may be the same. */
2837 CLEAR_REGNO_REG_SET (pbi
->cond_local_set
, i
);
2838 if (cond
!= NULL_RTX
2839 && ! REGNO_REG_SET_P (pbi
->local_set
, i
))
2840 SET_REGNO_REG_SET (pbi
->cond_local_set
, i
);
2842 SET_REGNO_REG_SET (pbi
->local_set
, i
);
2844 if (code
!= CLOBBER
|| needed_regno
)
2845 SET_REGNO_REG_SET (pbi
->new_set
, i
);
2847 some_was_live
|= needed_regno
;
2848 some_was_dead
|= ! needed_regno
;
2851 #ifdef HAVE_conditional_execution
2852 /* Consider conditional death in deciding that the register needs
2854 if (some_was_live
&& ! not_dead
2855 /* The stack pointer is never dead. Well, not strictly true,
2856 but it's very difficult to tell from here. Hopefully
2857 combine_stack_adjustments will fix up the most egregious
2859 && regno_first
!= STACK_POINTER_REGNUM
)
2861 for (i
= regno_first
; i
<= regno_last
; ++i
)
2862 if (! mark_regno_cond_dead (pbi
, i
, cond
))
2863 not_dead
|= ((unsigned long) 1) << (i
- regno_first
);
2867 /* Additional data to record if this is the final pass. */
2868 if (flags
& (PROP_LOG_LINKS
| PROP_REG_INFO
2869 | PROP_DEATH_NOTES
| PROP_AUTOINC
))
2872 int blocknum
= pbi
->bb
->index
;
2875 if (flags
& (PROP_LOG_LINKS
| PROP_AUTOINC
))
2877 y
= pbi
->reg_next_use
[regno_first
];
2879 /* The next use is no longer next, since a store intervenes. */
2880 for (i
= regno_first
; i
<= regno_last
; ++i
)
2881 pbi
->reg_next_use
[i
] = 0;
2884 if (flags
& PROP_REG_INFO
)
2886 for (i
= regno_first
; i
<= regno_last
; ++i
)
2888 /* Count (weighted) references, stores, etc. This counts a
2889 register twice if it is modified, but that is correct. */
2890 REG_N_SETS (i
) += 1;
2891 REG_N_REFS (i
) += 1;
2892 REG_FREQ (i
) += REG_FREQ_FROM_BB (pbi
->bb
);
2894 /* The insns where a reg is live are normally counted
2895 elsewhere, but we want the count to include the insn
2896 where the reg is set, and the normal counting mechanism
2897 would not count it. */
2898 REG_LIVE_LENGTH (i
) += 1;
2901 /* If this is a hard reg, record this function uses the reg. */
2902 if (regno_first
< FIRST_PSEUDO_REGISTER
)
2904 for (i
= regno_first
; i
<= regno_last
; i
++)
2905 regs_ever_live
[i
] = 1;
2906 if (flags
& PROP_ASM_SCAN
)
2907 for (i
= regno_first
; i
<= regno_last
; i
++)
2908 regs_asm_clobbered
[i
] = 1;
2912 /* Keep track of which basic blocks each reg appears in. */
2913 if (REG_BASIC_BLOCK (regno_first
) == REG_BLOCK_UNKNOWN
)
2914 REG_BASIC_BLOCK (regno_first
) = blocknum
;
2915 else if (REG_BASIC_BLOCK (regno_first
) != blocknum
)
2916 REG_BASIC_BLOCK (regno_first
) = REG_BLOCK_GLOBAL
;
2920 if (! some_was_dead
)
2922 if (flags
& PROP_LOG_LINKS
)
2924 /* Make a logical link from the next following insn
2925 that uses this register, back to this insn.
2926 The following insns have already been processed.
2928 We don't build a LOG_LINK for hard registers containing
2929 in ASM_OPERANDs. If these registers get replaced,
2930 we might wind up changing the semantics of the insn,
2931 even if reload can make what appear to be valid
2934 We don't build a LOG_LINK for global registers to
2935 or from a function call. We don't want to let
2936 combine think that it knows what is going on with
2937 global registers. */
2938 if (y
&& (BLOCK_NUM (y
) == blocknum
)
2939 && (regno_first
>= FIRST_PSEUDO_REGISTER
2940 || (asm_noperands (PATTERN (y
)) < 0
2941 && ! ((CALL_P (insn
)
2943 && global_regs
[regno_first
]))))
2944 LOG_LINKS (y
) = alloc_INSN_LIST (insn
, LOG_LINKS (y
));
2949 else if (! some_was_live
)
2951 if (flags
& PROP_REG_INFO
)
2952 REG_N_DEATHS (regno_first
) += 1;
2954 if (flags
& PROP_DEATH_NOTES
2956 && (!(flags
& PROP_POST_REGSTACK
)
2957 || !IN_RANGE (REGNO (reg
), FIRST_STACK_REG
,
2962 /* Note that dead stores have already been deleted
2963 when possible. If we get here, we have found a
2964 dead store that cannot be eliminated (because the
2965 same insn does something useful). Indicate this
2966 by marking the reg being set as dying here. */
2968 = alloc_EXPR_LIST (REG_UNUSED
, reg
, REG_NOTES (insn
));
2973 if (flags
& PROP_DEATH_NOTES
2975 && (!(flags
& PROP_POST_REGSTACK
)
2976 || !IN_RANGE (REGNO (reg
), FIRST_STACK_REG
,
2981 /* This is a case where we have a multi-word hard register
2982 and some, but not all, of the words of the register are
2983 needed in subsequent insns. Write REG_UNUSED notes
2984 for those parts that were not needed. This case should
2987 for (i
= regno_first
; i
<= regno_last
; ++i
)
2988 if (! REGNO_REG_SET_P (pbi
->reg_live
, i
))
2990 = alloc_EXPR_LIST (REG_UNUSED
,
2997 /* Mark the register as being dead. */
2999 /* The stack pointer is never dead. Well, not strictly true,
3000 but it's very difficult to tell from here. Hopefully
3001 combine_stack_adjustments will fix up the most egregious
3003 && regno_first
!= STACK_POINTER_REGNUM
)
3005 for (i
= regno_first
; i
<= regno_last
; ++i
)
3006 if (!(not_dead
& (((unsigned long) 1) << (i
- regno_first
))))
3008 if ((pbi
->flags
& PROP_REG_INFO
)
3009 && REGNO_REG_SET_P (pbi
->reg_live
, i
))
3011 REG_LIVE_LENGTH (i
) += pbi
->insn_num
- reg_deaths
[i
];
3014 CLEAR_REGNO_REG_SET (pbi
->reg_live
, i
);
3016 if (flags
& PROP_DEAD_INSN
)
3017 emit_insn_after (gen_rtx_CLOBBER (VOIDmode
, reg
), insn
);
3020 else if (REG_P (reg
))
3022 if (flags
& (PROP_LOG_LINKS
| PROP_AUTOINC
))
3023 pbi
->reg_next_use
[regno_first
] = 0;
3025 if ((flags
& PROP_REG_INFO
) != 0
3026 && (flags
& PROP_ASM_SCAN
) != 0
3027 && regno_first
< FIRST_PSEUDO_REGISTER
)
3029 for (i
= regno_first
; i
<= regno_last
; i
++)
3030 regs_asm_clobbered
[i
] = 1;
3034 /* If this is the last pass and this is a SCRATCH, show it will be dying
3035 here and count it. */
3036 else if (GET_CODE (reg
) == SCRATCH
)
3038 if (flags
& PROP_DEATH_NOTES
3040 && (!(flags
& PROP_POST_REGSTACK
)
3041 || !IN_RANGE (REGNO (reg
), FIRST_STACK_REG
, LAST_STACK_REG
))
3045 = alloc_EXPR_LIST (REG_UNUSED
, reg
, REG_NOTES (insn
));
3049 #ifdef HAVE_conditional_execution
3050 /* Mark REGNO conditionally dead.
3051 Return true if the register is now unconditionally dead. */
3054 mark_regno_cond_dead (struct propagate_block_info
*pbi
, int regno
, rtx cond
)
3056 /* If this is a store to a predicate register, the value of the
3057 predicate is changing, we don't know that the predicate as seen
3058 before is the same as that seen after. Flush all dependent
3059 conditions from reg_cond_dead. This will make all such
3060 conditionally live registers unconditionally live. */
3061 if (REGNO_REG_SET_P (pbi
->reg_cond_reg
, regno
))
3062 flush_reg_cond_reg (pbi
, regno
);
3064 /* If this is an unconditional store, remove any conditional
3065 life that may have existed. */
3066 if (cond
== NULL_RTX
)
3067 splay_tree_remove (pbi
->reg_cond_dead
, regno
);
3070 splay_tree_node node
;
3071 struct reg_cond_life_info
*rcli
;
3074 /* Otherwise this is a conditional set. Record that fact.
3075 It may have been conditionally used, or there may be a
3076 subsequent set with a complementary condition. */
3078 node
= splay_tree_lookup (pbi
->reg_cond_dead
, regno
);
3081 /* The register was unconditionally live previously.
3082 Record the current condition as the condition under
3083 which it is dead. */
3084 rcli
= XNEW (struct reg_cond_life_info
);
3085 rcli
->condition
= cond
;
3086 rcli
->stores
= cond
;
3087 rcli
->orig_condition
= const0_rtx
;
3088 splay_tree_insert (pbi
->reg_cond_dead
, regno
,
3089 (splay_tree_value
) rcli
);
3091 SET_REGNO_REG_SET (pbi
->reg_cond_reg
, REGNO (XEXP (cond
, 0)));
3093 /* Not unconditionally dead. */
3098 /* The register was conditionally live previously.
3099 Add the new condition to the old. */
3100 rcli
= (struct reg_cond_life_info
*) node
->value
;
3101 ncond
= rcli
->condition
;
3102 ncond
= ior_reg_cond (ncond
, cond
, 1);
3103 if (rcli
->stores
== const0_rtx
)
3104 rcli
->stores
= cond
;
3105 else if (rcli
->stores
!= const1_rtx
)
3106 rcli
->stores
= ior_reg_cond (rcli
->stores
, cond
, 1);
3108 /* If the register is now unconditionally dead, remove the entry
3109 in the splay_tree. A register is unconditionally dead if the
3110 dead condition ncond is true. A register is also unconditionally
3111 dead if the sum of all conditional stores is an unconditional
3112 store (stores is true), and the dead condition is identically the
3113 same as the original dead condition initialized at the end of
3114 the block. This is a pointer compare, not an rtx_equal_p
3116 if (ncond
== const1_rtx
3117 || (ncond
== rcli
->orig_condition
&& rcli
->stores
== const1_rtx
))
3118 splay_tree_remove (pbi
->reg_cond_dead
, regno
);
3121 rcli
->condition
= ncond
;
3123 SET_REGNO_REG_SET (pbi
->reg_cond_reg
, REGNO (XEXP (cond
, 0)));
3125 /* Not unconditionally dead. */
3134 /* Called from splay_tree_delete for pbi->reg_cond_life. */
3137 free_reg_cond_life_info (splay_tree_value value
)
3139 struct reg_cond_life_info
*rcli
= (struct reg_cond_life_info
*) value
;
3143 /* Helper function for flush_reg_cond_reg. */
3146 flush_reg_cond_reg_1 (splay_tree_node node
, void *data
)
3148 struct reg_cond_life_info
*rcli
;
3149 int *xdata
= (int *) data
;
3150 unsigned int regno
= xdata
[0];
3152 /* Don't need to search if last flushed value was farther on in
3153 the in-order traversal. */
3154 if (xdata
[1] >= (int) node
->key
)
3157 /* Splice out portions of the expression that refer to regno. */
3158 rcli
= (struct reg_cond_life_info
*) node
->value
;
3159 rcli
->condition
= elim_reg_cond (rcli
->condition
, regno
);
3160 if (rcli
->stores
!= const0_rtx
&& rcli
->stores
!= const1_rtx
)
3161 rcli
->stores
= elim_reg_cond (rcli
->stores
, regno
);
3163 /* If the entire condition is now false, signal the node to be removed. */
3164 if (rcli
->condition
== const0_rtx
)
3166 xdata
[1] = node
->key
;
3170 gcc_assert (rcli
->condition
!= const1_rtx
);
3175 /* Flush all (sub) expressions referring to REGNO from REG_COND_LIVE. */
3178 flush_reg_cond_reg (struct propagate_block_info
*pbi
, int regno
)
3184 while (splay_tree_foreach (pbi
->reg_cond_dead
,
3185 flush_reg_cond_reg_1
, pair
) == -1)
3186 splay_tree_remove (pbi
->reg_cond_dead
, pair
[1]);
3188 CLEAR_REGNO_REG_SET (pbi
->reg_cond_reg
, regno
);
3191 /* Logical arithmetic on predicate conditions. IOR, NOT and AND.
3192 For ior/and, the ADD flag determines whether we want to add the new
3193 condition X to the old one unconditionally. If it is zero, we will
3194 only return a new expression if X allows us to simplify part of
3195 OLD, otherwise we return NULL to the caller.
3196 If ADD is nonzero, we will return a new condition in all cases. The
3197 toplevel caller of one of these functions should always pass 1 for
3201 ior_reg_cond (rtx old
, rtx x
, int add
)
3205 if (COMPARISON_P (old
))
3207 if (COMPARISON_P (x
)
3208 && REVERSE_CONDEXEC_PREDICATES_P (x
, old
)
3209 && REGNO (XEXP (x
, 0)) == REGNO (XEXP (old
, 0)))
3211 if (GET_CODE (x
) == GET_CODE (old
)
3212 && REGNO (XEXP (x
, 0)) == REGNO (XEXP (old
, 0)))
3216 return gen_rtx_IOR (0, old
, x
);
3219 switch (GET_CODE (old
))
3222 op0
= ior_reg_cond (XEXP (old
, 0), x
, 0);
3223 op1
= ior_reg_cond (XEXP (old
, 1), x
, 0);
3224 if (op0
!= NULL
|| op1
!= NULL
)
3226 if (op0
== const0_rtx
)
3227 return op1
? op1
: gen_rtx_IOR (0, XEXP (old
, 1), x
);
3228 if (op1
== const0_rtx
)
3229 return op0
? op0
: gen_rtx_IOR (0, XEXP (old
, 0), x
);
3230 if (op0
== const1_rtx
|| op1
== const1_rtx
)
3233 op0
= gen_rtx_IOR (0, XEXP (old
, 0), x
);
3234 else if (rtx_equal_p (x
, op0
))
3235 /* (x | A) | x ~ (x | A). */
3238 op1
= gen_rtx_IOR (0, XEXP (old
, 1), x
);
3239 else if (rtx_equal_p (x
, op1
))
3240 /* (A | x) | x ~ (A | x). */
3242 return gen_rtx_IOR (0, op0
, op1
);
3246 return gen_rtx_IOR (0, old
, x
);
3249 op0
= ior_reg_cond (XEXP (old
, 0), x
, 0);
3250 op1
= ior_reg_cond (XEXP (old
, 1), x
, 0);
3251 if (op0
!= NULL
|| op1
!= NULL
)
3253 if (op0
== const1_rtx
)
3254 return op1
? op1
: gen_rtx_IOR (0, XEXP (old
, 1), x
);
3255 if (op1
== const1_rtx
)
3256 return op0
? op0
: gen_rtx_IOR (0, XEXP (old
, 0), x
);
3257 if (op0
== const0_rtx
|| op1
== const0_rtx
)
3260 op0
= gen_rtx_IOR (0, XEXP (old
, 0), x
);
3261 else if (rtx_equal_p (x
, op0
))
3262 /* (x & A) | x ~ x. */
3265 op1
= gen_rtx_IOR (0, XEXP (old
, 1), x
);
3266 else if (rtx_equal_p (x
, op1
))
3267 /* (A & x) | x ~ x. */
3269 return gen_rtx_AND (0, op0
, op1
);
3273 return gen_rtx_IOR (0, old
, x
);
3276 op0
= and_reg_cond (XEXP (old
, 0), not_reg_cond (x
), 0);
3278 return not_reg_cond (op0
);
3281 return gen_rtx_IOR (0, old
, x
);
3289 not_reg_cond (rtx x
)
3291 if (x
== const0_rtx
)
3293 else if (x
== const1_rtx
)
3295 if (GET_CODE (x
) == NOT
)
3297 if (COMPARISON_P (x
)
3298 && REG_P (XEXP (x
, 0)))
3300 gcc_assert (XEXP (x
, 1) == const0_rtx
);
3302 return gen_rtx_fmt_ee (reversed_comparison_code (x
, NULL
),
3303 VOIDmode
, XEXP (x
, 0), const0_rtx
);
3305 return gen_rtx_NOT (0, x
);
3309 and_reg_cond (rtx old
, rtx x
, int add
)
3313 if (COMPARISON_P (old
))
3315 if (COMPARISON_P (x
)
3316 && GET_CODE (x
) == reversed_comparison_code (old
, NULL
)
3317 && REGNO (XEXP (x
, 0)) == REGNO (XEXP (old
, 0)))
3319 if (GET_CODE (x
) == GET_CODE (old
)
3320 && REGNO (XEXP (x
, 0)) == REGNO (XEXP (old
, 0)))
3324 return gen_rtx_AND (0, old
, x
);
3327 switch (GET_CODE (old
))
3330 op0
= and_reg_cond (XEXP (old
, 0), x
, 0);
3331 op1
= and_reg_cond (XEXP (old
, 1), x
, 0);
3332 if (op0
!= NULL
|| op1
!= NULL
)
3334 if (op0
== const0_rtx
)
3335 return op1
? op1
: gen_rtx_AND (0, XEXP (old
, 1), x
);
3336 if (op1
== const0_rtx
)
3337 return op0
? op0
: gen_rtx_AND (0, XEXP (old
, 0), x
);
3338 if (op0
== const1_rtx
|| op1
== const1_rtx
)
3341 op0
= gen_rtx_AND (0, XEXP (old
, 0), x
);
3342 else if (rtx_equal_p (x
, op0
))
3343 /* (x | A) & x ~ x. */
3346 op1
= gen_rtx_AND (0, XEXP (old
, 1), x
);
3347 else if (rtx_equal_p (x
, op1
))
3348 /* (A | x) & x ~ x. */
3350 return gen_rtx_IOR (0, op0
, op1
);
3354 return gen_rtx_AND (0, old
, x
);
3357 op0
= and_reg_cond (XEXP (old
, 0), x
, 0);
3358 op1
= and_reg_cond (XEXP (old
, 1), x
, 0);
3359 if (op0
!= NULL
|| op1
!= NULL
)
3361 if (op0
== const1_rtx
)
3362 return op1
? op1
: gen_rtx_AND (0, XEXP (old
, 1), x
);
3363 if (op1
== const1_rtx
)
3364 return op0
? op0
: gen_rtx_AND (0, XEXP (old
, 0), x
);
3365 if (op0
== const0_rtx
|| op1
== const0_rtx
)
3368 op0
= gen_rtx_AND (0, XEXP (old
, 0), x
);
3369 else if (rtx_equal_p (x
, op0
))
3370 /* (x & A) & x ~ (x & A). */
3373 op1
= gen_rtx_AND (0, XEXP (old
, 1), x
);
3374 else if (rtx_equal_p (x
, op1
))
3375 /* (A & x) & x ~ (A & x). */
3377 return gen_rtx_AND (0, op0
, op1
);
3381 return gen_rtx_AND (0, old
, x
);
3384 op0
= ior_reg_cond (XEXP (old
, 0), not_reg_cond (x
), 0);
3386 return not_reg_cond (op0
);
3389 return gen_rtx_AND (0, old
, x
);
3396 /* Given a condition X, remove references to reg REGNO and return the
3397 new condition. The removal will be done so that all conditions
3398 involving REGNO are considered to evaluate to false. This function
3399 is used when the value of REGNO changes. */
3402 elim_reg_cond (rtx x
, unsigned int regno
)
3406 if (COMPARISON_P (x
))
3408 if (REGNO (XEXP (x
, 0)) == regno
)
3413 switch (GET_CODE (x
))
3416 op0
= elim_reg_cond (XEXP (x
, 0), regno
);
3417 op1
= elim_reg_cond (XEXP (x
, 1), regno
);
3418 if (op0
== const0_rtx
|| op1
== const0_rtx
)
3420 if (op0
== const1_rtx
)
3422 if (op1
== const1_rtx
)
3424 if (op0
== XEXP (x
, 0) && op1
== XEXP (x
, 1))
3426 return gen_rtx_AND (0, op0
, op1
);
3429 op0
= elim_reg_cond (XEXP (x
, 0), regno
);
3430 op1
= elim_reg_cond (XEXP (x
, 1), regno
);
3431 if (op0
== const1_rtx
|| op1
== const1_rtx
)
3433 if (op0
== const0_rtx
)
3435 if (op1
== const0_rtx
)
3437 if (op0
== XEXP (x
, 0) && op1
== XEXP (x
, 1))
3439 return gen_rtx_IOR (0, op0
, op1
);
3442 op0
= elim_reg_cond (XEXP (x
, 0), regno
);
3443 if (op0
== const0_rtx
)
3445 if (op0
== const1_rtx
)
3447 if (op0
!= XEXP (x
, 0))
3448 return not_reg_cond (op0
);
3455 #endif /* HAVE_conditional_execution */
3459 /* Try to substitute the auto-inc expression INC as the address inside
3460 MEM which occurs in INSN. Currently, the address of MEM is an expression
3461 involving INCR_REG, and INCR is the next use of INCR_REG; it is an insn
3462 that has a single set whose source is a PLUS of INCR_REG and something
3466 attempt_auto_inc (struct propagate_block_info
*pbi
, rtx inc
, rtx insn
,
3467 rtx mem
, rtx incr
, rtx incr_reg
)
3469 int regno
= REGNO (incr_reg
);
3470 rtx set
= single_set (incr
);
3471 rtx q
= SET_DEST (set
);
3472 rtx y
= SET_SRC (set
);
3473 int opnum
= XEXP (y
, 0) == incr_reg
? 0 : 1;
3476 /* Make sure this reg appears only once in this insn. */
3477 if (count_occurrences (PATTERN (insn
), incr_reg
, 1) != 1)
3480 if (dead_or_set_p (incr
, incr_reg
)
3481 /* Mustn't autoinc an eliminable register. */
3482 && (regno
>= FIRST_PSEUDO_REGISTER
3483 || ! TEST_HARD_REG_BIT (elim_reg_set
, regno
)))
3485 /* This is the simple case. Try to make the auto-inc. If
3486 we can't, we are done. Otherwise, we will do any
3487 needed updates below. */
3488 if (! validate_change (insn
, &XEXP (mem
, 0), inc
, 0))
3492 /* PREV_INSN used here to check the semi-open interval
3494 && ! reg_used_between_p (q
, PREV_INSN (insn
), incr
)
3495 /* We must also check for sets of q as q may be
3496 a call clobbered hard register and there may
3497 be a call between PREV_INSN (insn) and incr. */
3498 && ! reg_set_between_p (q
, PREV_INSN (insn
), incr
))
3500 /* We have *p followed sometime later by q = p+size.
3501 Both p and q must be live afterward,
3502 and q is not used between INSN and its assignment.
3503 Change it to q = p, ...*q..., q = q+size.
3504 Then fall into the usual case. */
3508 emit_move_insn (q
, incr_reg
);
3509 insns
= get_insns ();
3512 /* If we can't make the auto-inc, or can't make the
3513 replacement into Y, exit. There's no point in making
3514 the change below if we can't do the auto-inc and doing
3515 so is not correct in the pre-inc case. */
3518 validate_change (insn
, &XEXP (mem
, 0), inc
, 1);
3519 validate_change (incr
, &XEXP (y
, opnum
), q
, 1);
3520 if (! apply_change_group ())
3523 /* We now know we'll be doing this change, so emit the
3524 new insn(s) and do the updates. */
3525 emit_insn_before (insns
, insn
);
3527 if (BB_HEAD (pbi
->bb
) == insn
)
3528 BB_HEAD (pbi
->bb
) = insns
;
3530 /* INCR will become a NOTE and INSN won't contain a
3531 use of INCR_REG. If a use of INCR_REG was just placed in
3532 the insn before INSN, make that the next use.
3533 Otherwise, invalidate it. */
3534 if (NONJUMP_INSN_P (PREV_INSN (insn
))
3535 && GET_CODE (PATTERN (PREV_INSN (insn
))) == SET
3536 && SET_SRC (PATTERN (PREV_INSN (insn
))) == incr_reg
)
3537 pbi
->reg_next_use
[regno
] = PREV_INSN (insn
);
3539 pbi
->reg_next_use
[regno
] = 0;
3544 if ((pbi
->flags
& PROP_REG_INFO
)
3545 && !REGNO_REG_SET_P (pbi
->reg_live
, regno
))
3546 reg_deaths
[regno
] = pbi
->insn_num
;
3548 /* REGNO is now used in INCR which is below INSN, but
3549 it previously wasn't live here. If we don't mark
3550 it as live, we'll put a REG_DEAD note for it
3551 on this insn, which is incorrect. */
3552 SET_REGNO_REG_SET (pbi
->reg_live
, regno
);
3554 /* If there are any calls between INSN and INCR, show
3555 that REGNO now crosses them. */
3556 for (temp
= insn
; temp
!= incr
; temp
= NEXT_INSN (temp
))
3559 REG_N_CALLS_CROSSED (regno
)++;
3560 if (can_throw_internal (temp
))
3561 REG_N_THROWING_CALLS_CROSSED (regno
)++;
3564 /* Invalidate alias info for Q since we just changed its value. */
3565 clear_reg_alias_info (q
);
3570 /* If we haven't returned, it means we were able to make the
3571 auto-inc, so update the status. First, record that this insn
3572 has an implicit side effect. */
3574 REG_NOTES (insn
) = alloc_EXPR_LIST (REG_INC
, incr_reg
, REG_NOTES (insn
));
3576 /* Modify the old increment-insn to simply copy
3577 the already-incremented value of our register. */
3578 changed
= validate_change (incr
, &SET_SRC (set
), incr_reg
, 0);
3579 gcc_assert (changed
);
3581 /* If that makes it a no-op (copying the register into itself) delete
3582 it so it won't appear to be a "use" and a "set" of this
3584 if (REGNO (SET_DEST (set
)) == REGNO (incr_reg
))
3586 /* If the original source was dead, it's dead now. */
3589 while ((note
= find_reg_note (incr
, REG_DEAD
, NULL_RTX
)) != NULL_RTX
)
3591 remove_note (incr
, note
);
3592 if (XEXP (note
, 0) != incr_reg
)
3594 unsigned int regno
= REGNO (XEXP (note
, 0));
3596 if ((pbi
->flags
& PROP_REG_INFO
)
3597 && REGNO_REG_SET_P (pbi
->reg_live
, regno
))
3599 REG_LIVE_LENGTH (regno
) += pbi
->insn_num
- reg_deaths
[regno
];
3600 reg_deaths
[regno
] = 0;
3602 CLEAR_REGNO_REG_SET (pbi
->reg_live
, REGNO (XEXP (note
, 0)));
3606 SET_INSN_DELETED (incr
);
3609 if (regno
>= FIRST_PSEUDO_REGISTER
)
3611 /* Count an extra reference to the reg. When a reg is
3612 incremented, spilling it is worse, so we want to make
3613 that less likely. */
3614 REG_FREQ (regno
) += REG_FREQ_FROM_BB (pbi
->bb
);
3616 /* Count the increment as a setting of the register,
3617 even though it isn't a SET in rtl. */
3618 REG_N_SETS (regno
)++;
3622 /* X is a MEM found in INSN. See if we can convert it into an auto-increment
3626 find_auto_inc (struct propagate_block_info
*pbi
, rtx x
, rtx insn
)
3628 rtx addr
= XEXP (x
, 0);
3629 HOST_WIDE_INT offset
= 0;
3630 rtx set
, y
, incr
, inc_val
;
3632 int size
= GET_MODE_SIZE (GET_MODE (x
));
3637 /* Here we detect use of an index register which might be good for
3638 postincrement, postdecrement, preincrement, or predecrement. */
3640 if (GET_CODE (addr
) == PLUS
&& GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
3641 offset
= INTVAL (XEXP (addr
, 1)), addr
= XEXP (addr
, 0);
3646 regno
= REGNO (addr
);
3648 /* Is the next use an increment that might make auto-increment? */
3649 incr
= pbi
->reg_next_use
[regno
];
3650 if (incr
== 0 || BLOCK_NUM (incr
) != BLOCK_NUM (insn
))
3652 set
= single_set (incr
);
3653 if (set
== 0 || GET_CODE (set
) != SET
)
3657 if (GET_CODE (y
) != PLUS
)
3660 if (REG_P (XEXP (y
, 0)) && REGNO (XEXP (y
, 0)) == REGNO (addr
))
3661 inc_val
= XEXP (y
, 1);
3662 else if (REG_P (XEXP (y
, 1)) && REGNO (XEXP (y
, 1)) == REGNO (addr
))
3663 inc_val
= XEXP (y
, 0);
3667 if (GET_CODE (inc_val
) == CONST_INT
)
3669 if (HAVE_POST_INCREMENT
3670 && (INTVAL (inc_val
) == size
&& offset
== 0))
3671 attempt_auto_inc (pbi
, gen_rtx_POST_INC (Pmode
, addr
), insn
, x
,
3673 else if (HAVE_POST_DECREMENT
3674 && (INTVAL (inc_val
) == -size
&& offset
== 0))
3675 attempt_auto_inc (pbi
, gen_rtx_POST_DEC (Pmode
, addr
), insn
, x
,
3677 else if (HAVE_PRE_INCREMENT
3678 && (INTVAL (inc_val
) == size
&& offset
== size
))
3679 attempt_auto_inc (pbi
, gen_rtx_PRE_INC (Pmode
, addr
), insn
, x
,
3681 else if (HAVE_PRE_DECREMENT
3682 && (INTVAL (inc_val
) == -size
&& offset
== -size
))
3683 attempt_auto_inc (pbi
, gen_rtx_PRE_DEC (Pmode
, addr
), insn
, x
,
3685 else if (HAVE_POST_MODIFY_DISP
&& offset
== 0)
3686 attempt_auto_inc (pbi
, gen_rtx_POST_MODIFY (Pmode
, addr
,
3687 gen_rtx_PLUS (Pmode
,
3690 insn
, x
, incr
, addr
);
3691 else if (HAVE_PRE_MODIFY_DISP
&& offset
== INTVAL (inc_val
))
3692 attempt_auto_inc (pbi
, gen_rtx_PRE_MODIFY (Pmode
, addr
,
3693 gen_rtx_PLUS (Pmode
,
3696 insn
, x
, incr
, addr
);
3698 else if (REG_P (inc_val
)
3699 && ! reg_set_between_p (inc_val
, PREV_INSN (insn
),
3703 if (HAVE_POST_MODIFY_REG
&& offset
== 0)
3704 attempt_auto_inc (pbi
, gen_rtx_POST_MODIFY (Pmode
, addr
,
3705 gen_rtx_PLUS (Pmode
,
3708 insn
, x
, incr
, addr
);
3712 #endif /* AUTO_INC_DEC */
3715 mark_used_reg (struct propagate_block_info
*pbi
, rtx reg
,
3716 rtx cond ATTRIBUTE_UNUSED
, rtx insn
)
3718 unsigned int regno_first
, regno_last
, i
;
3719 int some_was_live
, some_was_dead
, some_not_set
;
3721 regno_last
= regno_first
= REGNO (reg
);
3722 if (regno_first
< FIRST_PSEUDO_REGISTER
)
3723 regno_last
+= hard_regno_nregs
[regno_first
][GET_MODE (reg
)] - 1;
3725 /* Find out if any of this register is live after this instruction. */
3726 some_was_live
= some_was_dead
= 0;
3727 for (i
= regno_first
; i
<= regno_last
; ++i
)
3729 int needed_regno
= REGNO_REG_SET_P (pbi
->reg_live
, i
);
3730 some_was_live
|= needed_regno
;
3731 some_was_dead
|= ! needed_regno
;
3734 /* Find out if any of the register was set this insn. */
3736 for (i
= regno_first
; i
<= regno_last
; ++i
)
3737 some_not_set
|= ! REGNO_REG_SET_P (pbi
->new_set
, i
);
3739 if (pbi
->flags
& (PROP_LOG_LINKS
| PROP_AUTOINC
))
3741 /* Record where each reg is used, so when the reg is set we know
3742 the next insn that uses it. */
3743 pbi
->reg_next_use
[regno_first
] = insn
;
3746 if (pbi
->flags
& PROP_REG_INFO
)
3748 if (regno_first
< FIRST_PSEUDO_REGISTER
)
3750 /* If this is a register we are going to try to eliminate,
3751 don't mark it live here. If we are successful in
3752 eliminating it, it need not be live unless it is used for
3753 pseudos, in which case it will have been set live when it
3754 was allocated to the pseudos. If the register will not
3755 be eliminated, reload will set it live at that point.
3757 Otherwise, record that this function uses this register. */
3758 /* ??? The PPC backend tries to "eliminate" on the pic
3759 register to itself. This should be fixed. In the mean
3760 time, hack around it. */
3762 if (! (TEST_HARD_REG_BIT (elim_reg_set
, regno_first
)
3763 && (regno_first
== FRAME_POINTER_REGNUM
3764 || regno_first
== ARG_POINTER_REGNUM
)))
3765 for (i
= regno_first
; i
<= regno_last
; ++i
)
3766 regs_ever_live
[i
] = 1;
3770 /* Keep track of which basic block each reg appears in. */
3772 int blocknum
= pbi
->bb
->index
;
3773 if (REG_BASIC_BLOCK (regno_first
) == REG_BLOCK_UNKNOWN
)
3774 REG_BASIC_BLOCK (regno_first
) = blocknum
;
3775 else if (REG_BASIC_BLOCK (regno_first
) != blocknum
)
3776 REG_BASIC_BLOCK (regno_first
) = REG_BLOCK_GLOBAL
;
3778 /* Count (weighted) number of uses of each reg. */
3779 REG_FREQ (regno_first
) += REG_FREQ_FROM_BB (pbi
->bb
);
3780 REG_N_REFS (regno_first
)++;
3782 for (i
= regno_first
; i
<= regno_last
; ++i
)
3783 if (! REGNO_REG_SET_P (pbi
->reg_live
, i
))
3785 gcc_assert (!reg_deaths
[i
]);
3786 reg_deaths
[i
] = pbi
->insn_num
;
3790 /* Record and count the insns in which a reg dies. If it is used in
3791 this insn and was dead below the insn then it dies in this insn.
3792 If it was set in this insn, we do not make a REG_DEAD note;
3793 likewise if we already made such a note. */
3794 if ((pbi
->flags
& (PROP_DEATH_NOTES
| PROP_REG_INFO
))
3798 /* Check for the case where the register dying partially
3799 overlaps the register set by this insn. */
3800 if (regno_first
!= regno_last
)
3801 for (i
= regno_first
; i
<= regno_last
; ++i
)
3802 some_was_live
|= REGNO_REG_SET_P (pbi
->new_set
, i
);
3804 /* If none of the words in X is needed, make a REG_DEAD note.
3805 Otherwise, we must make partial REG_DEAD notes. */
3806 if (! some_was_live
)
3808 if ((pbi
->flags
& PROP_DEATH_NOTES
)
3810 && (!(pbi
->flags
& PROP_POST_REGSTACK
)
3811 || !IN_RANGE (REGNO (reg
), FIRST_STACK_REG
, LAST_STACK_REG
))
3813 && ! find_regno_note (insn
, REG_DEAD
, regno_first
))
3815 = alloc_EXPR_LIST (REG_DEAD
, reg
, REG_NOTES (insn
));
3817 if (pbi
->flags
& PROP_REG_INFO
)
3818 REG_N_DEATHS (regno_first
)++;
3822 /* Don't make a REG_DEAD note for a part of a register
3823 that is set in the insn. */
3824 for (i
= regno_first
; i
<= regno_last
; ++i
)
3825 if (! REGNO_REG_SET_P (pbi
->reg_live
, i
)
3826 && ! dead_or_set_regno_p (insn
, i
))
3828 = alloc_EXPR_LIST (REG_DEAD
,
3834 /* Mark the register as being live. */
3835 for (i
= regno_first
; i
<= regno_last
; ++i
)
3837 #ifdef HAVE_conditional_execution
3838 int this_was_live
= REGNO_REG_SET_P (pbi
->reg_live
, i
);
3841 SET_REGNO_REG_SET (pbi
->reg_live
, i
);
3843 #ifdef HAVE_conditional_execution
3844 /* If this is a conditional use, record that fact. If it is later
3845 conditionally set, we'll know to kill the register. */
3846 if (cond
!= NULL_RTX
)
3848 splay_tree_node node
;
3849 struct reg_cond_life_info
*rcli
;
3854 node
= splay_tree_lookup (pbi
->reg_cond_dead
, i
);
3857 /* The register was unconditionally live previously.
3858 No need to do anything. */
3862 /* The register was conditionally live previously.
3863 Subtract the new life cond from the old death cond. */
3864 rcli
= (struct reg_cond_life_info
*) node
->value
;
3865 ncond
= rcli
->condition
;
3866 ncond
= and_reg_cond (ncond
, not_reg_cond (cond
), 1);
3868 /* If the register is now unconditionally live,
3869 remove the entry in the splay_tree. */
3870 if (ncond
== const0_rtx
)
3871 splay_tree_remove (pbi
->reg_cond_dead
, i
);
3874 rcli
->condition
= ncond
;
3875 SET_REGNO_REG_SET (pbi
->reg_cond_reg
,
3876 REGNO (XEXP (cond
, 0)));
3882 /* The register was not previously live at all. Record
3883 the condition under which it is still dead. */
3884 rcli
= XNEW (struct reg_cond_life_info
);
3885 rcli
->condition
= not_reg_cond (cond
);
3886 rcli
->stores
= const0_rtx
;
3887 rcli
->orig_condition
= const0_rtx
;
3888 splay_tree_insert (pbi
->reg_cond_dead
, i
,
3889 (splay_tree_value
) rcli
);
3891 SET_REGNO_REG_SET (pbi
->reg_cond_reg
, REGNO (XEXP (cond
, 0)));
3894 else if (this_was_live
)
3896 /* The register may have been conditionally live previously, but
3897 is now unconditionally live. Remove it from the conditionally
3898 dead list, so that a conditional set won't cause us to think
3900 splay_tree_remove (pbi
->reg_cond_dead
, i
);
3906 /* Scan expression X for registers which have to be marked used in PBI.
3907 X is considered to be the SET_DEST rtx of SET. TRUE is returned if
3908 X could be handled by this function. */
3911 mark_used_dest_regs (struct propagate_block_info
*pbi
, rtx x
, rtx cond
, rtx insn
)
3914 bool mark_dest
= false;
3917 /* On some platforms calls return values spread over several
3918 locations. These locations are wrapped in a EXPR_LIST rtx
3919 together with a CONST_INT offset. */
3920 if (GET_CODE (x
) == EXPR_LIST
3921 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
3927 /* If storing into MEM, don't show it as being used. But do
3928 show the address as being used. */
3932 if (pbi
->flags
& PROP_AUTOINC
)
3933 find_auto_inc (pbi
, x
, insn
);
3935 mark_used_regs (pbi
, XEXP (x
, 0), cond
, insn
);
3939 /* Storing in STRICT_LOW_PART is like storing in a reg
3940 in that this SET might be dead, so ignore it in TESTREG.
3941 but in some other ways it is like using the reg.
3943 Storing in a SUBREG or a bit field is like storing the entire
3944 register in that if the register's value is not used
3945 then this SET is not needed. */
3946 while (GET_CODE (x
) == STRICT_LOW_PART
3947 || GET_CODE (x
) == ZERO_EXTRACT
3948 || GET_CODE (x
) == SUBREG
)
3950 #ifdef CANNOT_CHANGE_MODE_CLASS
3951 if ((pbi
->flags
& PROP_REG_INFO
) && GET_CODE (x
) == SUBREG
)
3952 record_subregs_of_mode (x
);
3955 /* Modifying a single register in an alternate mode
3956 does not use any of the old value. But these other
3957 ways of storing in a register do use the old value. */
3958 if (GET_CODE (x
) == SUBREG
3959 && !((REG_BYTES (SUBREG_REG (x
))
3960 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
3962 + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
))
3970 /* If this is a store into a register or group of registers,
3971 recursively scan the value being stored. */
3973 && (regno
= REGNO (x
),
3974 !(regno
== FRAME_POINTER_REGNUM
3975 && (!reload_completed
|| frame_pointer_needed
)))
3976 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3977 && !(regno
== HARD_FRAME_POINTER_REGNUM
3978 && (!reload_completed
|| frame_pointer_needed
))
3980 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3981 && !(regno
== ARG_POINTER_REGNUM
&& fixed_regs
[regno
])
3986 mark_used_regs (pbi
, dest
, cond
, insn
);
3992 /* Scan expression X and store a 1-bit in NEW_LIVE for each reg it uses.
3993 This is done assuming the registers needed from X are those that
3994 have 1-bits in PBI->REG_LIVE.
3996 INSN is the containing instruction. If INSN is dead, this function
4000 mark_used_regs (struct propagate_block_info
*pbi
, rtx x
, rtx cond
, rtx insn
)
4003 int flags
= pbi
->flags
;
4008 code
= GET_CODE (x
);
4029 /* If we are clobbering a MEM, mark any registers inside the address
4031 if (MEM_P (XEXP (x
, 0)))
4032 mark_used_regs (pbi
, XEXP (XEXP (x
, 0), 0), cond
, insn
);
4036 /* Don't bother watching stores to mems if this is not the
4037 final pass. We'll not be deleting dead stores this round. */
4038 if (optimize
&& (flags
& PROP_SCAN_DEAD_STORES
))
4040 /* Invalidate the data for the last MEM stored, but only if MEM is
4041 something that can be stored into. */
4042 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
4043 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)))
4044 /* Needn't clear the memory set list. */
4048 rtx temp
= pbi
->mem_set_list
;
4049 rtx prev
= NULL_RTX
;
4054 next
= XEXP (temp
, 1);
4055 if (anti_dependence (XEXP (temp
, 0), x
))
4057 /* Splice temp out of the list. */
4059 XEXP (prev
, 1) = next
;
4061 pbi
->mem_set_list
= next
;
4062 free_EXPR_LIST_node (temp
);
4063 pbi
->mem_set_list_len
--;
4071 /* If the memory reference had embedded side effects (autoincrement
4072 address modes. Then we may need to kill some entries on the
4075 for_each_rtx (&PATTERN (insn
), invalidate_mems_from_autoinc
, pbi
);
4079 if (flags
& PROP_AUTOINC
)
4080 find_auto_inc (pbi
, x
, insn
);
4085 #ifdef CANNOT_CHANGE_MODE_CLASS
4086 if (flags
& PROP_REG_INFO
)
4087 record_subregs_of_mode (x
);
4090 /* While we're here, optimize this case. */
4097 /* See a register other than being set => mark it as needed. */
4098 mark_used_reg (pbi
, x
, cond
, insn
);
4103 rtx dest
= SET_DEST (x
);
4107 if (GET_CODE (dest
) == PARALLEL
)
4108 for (i
= 0; i
< XVECLEN (dest
, 0); i
++)
4109 ret
|= mark_used_dest_regs (pbi
, XVECEXP (dest
, 0, i
), cond
, insn
);
4111 ret
= mark_used_dest_regs (pbi
, dest
, cond
, insn
);
4115 mark_used_regs (pbi
, SET_SRC (x
), cond
, insn
);
4122 case UNSPEC_VOLATILE
:
4126 /* Traditional and volatile asm instructions must be considered to use
4127 and clobber all hard registers, all pseudo-registers and all of
4128 memory. So must TRAP_IF and UNSPEC_VOLATILE operations.
4130 Consider for instance a volatile asm that changes the fpu rounding
4131 mode. An insn should not be moved across this even if it only uses
4132 pseudo-regs because it might give an incorrectly rounded result.
4134 ?!? Unfortunately, marking all hard registers as live causes massive
4135 problems for the register allocator and marking all pseudos as live
4136 creates mountains of uninitialized variable warnings.
4138 So for now, just clear the memory set list and mark any regs
4139 we can find in ASM_OPERANDS as used. */
4140 if (code
!= ASM_OPERANDS
|| MEM_VOLATILE_P (x
))
4142 free_EXPR_LIST_list (&pbi
->mem_set_list
);
4143 pbi
->mem_set_list_len
= 0;
4146 /* For all ASM_OPERANDS, we must traverse the vector of input operands.
4147 We can not just fall through here since then we would be confused
4148 by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
4149 traditional asms unlike their normal usage. */
4150 if (code
== ASM_OPERANDS
)
4154 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
4155 mark_used_regs (pbi
, ASM_OPERANDS_INPUT (x
, j
), cond
, insn
);
4163 mark_used_regs (pbi
, COND_EXEC_TEST (x
), NULL_RTX
, insn
);
4165 cond
= COND_EXEC_TEST (x
);
4166 x
= COND_EXEC_CODE (x
);
4173 /* Recursively scan the operands of this expression. */
4176 const char * const fmt
= GET_RTX_FORMAT (code
);
4179 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4183 /* Tail recursive case: save a function call level. */
4189 mark_used_regs (pbi
, XEXP (x
, i
), cond
, insn
);
4191 else if (fmt
[i
] == 'E')
4194 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4195 mark_used_regs (pbi
, XVECEXP (x
, i
, j
), cond
, insn
);
4204 try_pre_increment_1 (struct propagate_block_info
*pbi
, rtx insn
)
4206 /* Find the next use of this reg. If in same basic block,
4207 make it do pre-increment or pre-decrement if appropriate. */
4208 rtx x
= single_set (insn
);
4209 HOST_WIDE_INT amount
= ((GET_CODE (SET_SRC (x
)) == PLUS
? 1 : -1)
4210 * INTVAL (XEXP (SET_SRC (x
), 1)));
4211 int regno
= REGNO (SET_DEST (x
));
4212 rtx y
= pbi
->reg_next_use
[regno
];
4214 && SET_DEST (x
) != stack_pointer_rtx
4215 && BLOCK_NUM (y
) == BLOCK_NUM (insn
)
4216 /* Don't do this if the reg dies, or gets set in y; a standard addressing
4217 mode would be better. */
4218 && ! dead_or_set_p (y
, SET_DEST (x
))
4219 && try_pre_increment (y
, SET_DEST (x
), amount
))
4221 /* We have found a suitable auto-increment and already changed
4222 insn Y to do it. So flush this increment instruction. */
4223 propagate_block_delete_insn (insn
);
4225 /* Count a reference to this reg for the increment insn we are
4226 deleting. When a reg is incremented, spilling it is worse,
4227 so we want to make that less likely. */
4228 if (regno
>= FIRST_PSEUDO_REGISTER
)
4230 REG_FREQ (regno
) += REG_FREQ_FROM_BB (pbi
->bb
);
4231 REG_N_SETS (regno
)++;
4234 /* Flush any remembered memories depending on the value of
4235 the incremented register. */
4236 invalidate_mems_from_set (pbi
, SET_DEST (x
));
4243 /* Try to change INSN so that it does pre-increment or pre-decrement
4244 addressing on register REG in order to add AMOUNT to REG.
4245 AMOUNT is negative for pre-decrement.
4246 Returns 1 if the change could be made.
4247 This checks all about the validity of the result of modifying INSN. */
4250 try_pre_increment (rtx insn
, rtx reg
, HOST_WIDE_INT amount
)
4254 /* Nonzero if we can try to make a pre-increment or pre-decrement.
4255 For example, addl $4,r1; movl (r1),... can become movl +(r1),... */
4257 /* Nonzero if we can try to make a post-increment or post-decrement.
4258 For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,...
4259 It is possible for both PRE_OK and POST_OK to be nonzero if the machine
4260 supports both pre-inc and post-inc, or both pre-dec and post-dec. */
4263 /* Nonzero if the opportunity actually requires post-inc or post-dec. */
4266 /* From the sign of increment, see which possibilities are conceivable
4267 on this target machine. */
4268 if (HAVE_PRE_INCREMENT
&& amount
> 0)
4270 if (HAVE_POST_INCREMENT
&& amount
> 0)
4273 if (HAVE_PRE_DECREMENT
&& amount
< 0)
4275 if (HAVE_POST_DECREMENT
&& amount
< 0)
4278 if (! (pre_ok
|| post_ok
))
4281 /* It is not safe to add a side effect to a jump insn
4282 because if the incremented register is spilled and must be reloaded
4283 there would be no way to store the incremented value back in memory. */
4290 use
= find_use_as_address (PATTERN (insn
), reg
, 0);
4291 if (post_ok
&& (use
== 0 || use
== (rtx
) (size_t) 1))
4293 use
= find_use_as_address (PATTERN (insn
), reg
, -amount
);
4297 if (use
== 0 || use
== (rtx
) (size_t) 1)
4300 if (GET_MODE_SIZE (GET_MODE (use
)) != (amount
> 0 ? amount
: - amount
))
4303 /* See if this combination of instruction and addressing mode exists. */
4304 if (! validate_change (insn
, &XEXP (use
, 0),
4305 gen_rtx_fmt_e (amount
> 0
4306 ? (do_post
? POST_INC
: PRE_INC
)
4307 : (do_post
? POST_DEC
: PRE_DEC
),
4311 /* Record that this insn now has an implicit side effect on X. */
4312 REG_NOTES (insn
) = alloc_EXPR_LIST (REG_INC
, reg
, REG_NOTES (insn
));
4316 #endif /* AUTO_INC_DEC */
4318 /* Find the place in the rtx X where REG is used as a memory address.
4319 Return the MEM rtx that so uses it.
4320 If PLUSCONST is nonzero, search instead for a memory address equivalent to
4321 (plus REG (const_int PLUSCONST)).
4323 If such an address does not appear, return 0.
4324 If REG appears more than once, or is used other than in such an address,
4328 find_use_as_address (rtx x
, rtx reg
, HOST_WIDE_INT plusconst
)
4330 enum rtx_code code
= GET_CODE (x
);
4331 const char * const fmt
= GET_RTX_FORMAT (code
);
4336 if (code
== MEM
&& XEXP (x
, 0) == reg
&& plusconst
== 0)
4339 if (code
== MEM
&& GET_CODE (XEXP (x
, 0)) == PLUS
4340 && XEXP (XEXP (x
, 0), 0) == reg
4341 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
4342 && INTVAL (XEXP (XEXP (x
, 0), 1)) == plusconst
)
4345 if (code
== SIGN_EXTRACT
|| code
== ZERO_EXTRACT
)
4347 /* If REG occurs inside a MEM used in a bit-field reference,
4348 that is unacceptable. */
4349 if (find_use_as_address (XEXP (x
, 0), reg
, 0) != 0)
4350 return (rtx
) (size_t) 1;
4354 return (rtx
) (size_t) 1;
4356 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4360 tem
= find_use_as_address (XEXP (x
, i
), reg
, plusconst
);
4364 return (rtx
) (size_t) 1;
4366 else if (fmt
[i
] == 'E')
4369 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4371 tem
= find_use_as_address (XVECEXP (x
, i
, j
), reg
, plusconst
);
4375 return (rtx
) (size_t) 1;
4383 /* Write information about registers and basic blocks into FILE.
4384 This is part of making a debugging dump. */
4387 dump_regset (regset r
, FILE *outf
)
4390 reg_set_iterator rsi
;
4394 fputs (" (nil)", outf
);
4398 EXECUTE_IF_SET_IN_REG_SET (r
, 0, i
, rsi
)
4400 fprintf (outf
, " %d", i
);
4401 if (i
< FIRST_PSEUDO_REGISTER
)
4402 fprintf (outf
, " [%s]",
4407 /* Print a human-readable representation of R on the standard error
4408 stream. This function is designed to be used from within the
4412 debug_regset (regset r
)
4414 dump_regset (r
, stderr
);
4415 putc ('\n', stderr
);
4418 /* Recompute register set/reference counts immediately prior to register
4421 This avoids problems with set/reference counts changing to/from values
4422 which have special meanings to the register allocators.
4424 Additionally, the reference counts are the primary component used by the
4425 register allocators to prioritize pseudos for allocation to hard regs.
4426 More accurate reference counts generally lead to better register allocation.
4428 It might be worthwhile to update REG_LIVE_LENGTH, REG_BASIC_BLOCK and
4429 possibly other information which is used by the register allocators. */
4432 recompute_reg_usage (void)
4434 allocate_reg_life_data ();
4435 /* distribute_notes in combiner fails to convert some of the
4436 REG_UNUSED notes to REG_DEAD notes. This causes CHECK_DEAD_NOTES
4437 in sched1 to die. To solve this update the DEATH_NOTES
4439 update_life_info (NULL
, UPDATE_LIFE_LOCAL
, PROP_REG_INFO
| PROP_DEATH_NOTES
);
4442 dump_flow_info (dump_file
, dump_flags
);
4446 struct tree_opt_pass pass_recompute_reg_usage
=
4450 recompute_reg_usage
, /* execute */
4453 0, /* static_pass_number */
4455 0, /* properties_required */
4456 0, /* properties_provided */
4457 0, /* properties_destroyed */
4458 0, /* todo_flags_start */
4459 TODO_dump_func
, /* todo_flags_finish */
4463 /* Optionally removes all the REG_DEAD and REG_UNUSED notes from a set of
4464 blocks. If BLOCKS is NULL, assume the universal set. Returns a count
4465 of the number of registers that died.
4466 If KILL is 1, remove old REG_DEAD / REG_UNUSED notes. If it is 0, don't.
4467 if it is -1, remove them unless they pertain to a stack reg. */
4470 count_or_remove_death_notes (sbitmap blocks
, int kill
)
4476 /* This used to be a loop over all the blocks with a membership test
4477 inside the loop. That can be amazingly expensive on a large CFG
4478 when only a small number of bits are set in BLOCKs (for example,
4479 the calls from the scheduler typically have very few bits set).
4481 For extra credit, someone should convert BLOCKS to a bitmap rather
4485 sbitmap_iterator sbi
;
4487 EXECUTE_IF_SET_IN_SBITMAP (blocks
, 0, i
, sbi
)
4489 basic_block bb
= BASIC_BLOCK (i
);
4490 /* The bitmap may be flawed in that one of the basic blocks
4491 may have been deleted before you get here. */
4493 count
+= count_or_remove_death_notes_bb (bb
, kill
);
4500 count
+= count_or_remove_death_notes_bb (bb
, kill
);
4507 /* Optionally removes all the REG_DEAD and REG_UNUSED notes from basic
4508 block BB. Returns a count of the number of registers that died. */
4511 count_or_remove_death_notes_bb (basic_block bb
, int kill
)
4516 for (insn
= BB_HEAD (bb
); ; insn
= NEXT_INSN (insn
))
4520 rtx
*pprev
= ®_NOTES (insn
);
4525 switch (REG_NOTE_KIND (link
))
4528 if (REG_P (XEXP (link
, 0)))
4530 rtx reg
= XEXP (link
, 0);
4533 if (REGNO (reg
) >= FIRST_PSEUDO_REGISTER
)
4536 n
= hard_regno_nregs
[REGNO (reg
)][GET_MODE (reg
)];
4546 && (!REG_P (XEXP (link
, 0))
4547 || !IN_RANGE (REGNO (XEXP (link
, 0)),
4548 FIRST_STACK_REG
, LAST_STACK_REG
))
4552 rtx next
= XEXP (link
, 1);
4553 free_EXPR_LIST_node (link
);
4554 *pprev
= link
= next
;
4560 pprev
= &XEXP (link
, 1);
4567 if (insn
== BB_END (bb
))
4574 /* Clear LOG_LINKS fields of insns in a selected blocks or whole chain
4575 if blocks is NULL. */
4578 clear_log_links (sbitmap blocks
)
4584 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4586 free_INSN_LIST_list (&LOG_LINKS (insn
));
4591 sbitmap_iterator sbi
;
4593 EXECUTE_IF_SET_IN_SBITMAP (blocks
, 0, i
, sbi
)
4595 basic_block bb
= BASIC_BLOCK (i
);
4597 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
4598 insn
= NEXT_INSN (insn
))
4600 free_INSN_LIST_list (&LOG_LINKS (insn
));
4605 /* Given a register bitmap, turn on the bits in a HARD_REG_SET that
4606 correspond to the hard registers, if any, set in that map. This
4607 could be done far more efficiently by having all sorts of special-cases
4608 with moving single words, but probably isn't worth the trouble. */
4611 reg_set_to_hard_reg_set (HARD_REG_SET
*to
, bitmap from
)
4616 EXECUTE_IF_SET_IN_BITMAP (from
, 0, i
, bi
)
4618 if (i
>= FIRST_PSEUDO_REGISTER
)
4620 SET_HARD_REG_BIT (*to
, i
);
4626 gate_remove_death_notes (void)
4628 return flag_profile_values
;
4632 rest_of_handle_remove_death_notes (void)
4634 count_or_remove_death_notes (NULL
, 1);
4638 struct tree_opt_pass pass_remove_death_notes
=
4640 "ednotes", /* name */
4641 gate_remove_death_notes
, /* gate */
4642 rest_of_handle_remove_death_notes
, /* execute */
4645 0, /* static_pass_number */
4647 0, /* properties_required */
4648 0, /* properties_provided */
4649 0, /* properties_destroyed */
4650 0, /* todo_flags_start */
4651 0, /* todo_flags_finish */
4655 /* Perform life analysis. */
4657 rest_of_handle_life (void)
4661 life_analysis (PROP_FINAL
);
4663 cleanup_cfg (CLEANUP_EXPENSIVE
| CLEANUP_UPDATE_LIFE
| CLEANUP_LOG_LINKS
4664 | (flag_thread_jumps
? CLEANUP_THREADING
: 0));
4668 setjmp_vars_warning (DECL_INITIAL (current_function_decl
));
4669 setjmp_args_warning ();
4674 if (initialize_uninitialized_subregs ())
4676 /* Insns were inserted, and possibly pseudos created, so
4677 things might look a bit different. */
4678 allocate_reg_life_data ();
4679 update_life_info (NULL
, UPDATE_LIFE_GLOBAL_RM_NOTES
,
4680 PROP_LOG_LINKS
| PROP_REG_INFO
| PROP_DEATH_NOTES
);
4688 struct tree_opt_pass pass_life
=
4692 rest_of_handle_life
, /* execute */
4695 0, /* static_pass_number */
4696 TV_FLOW
, /* tv_id */
4697 0, /* properties_required */
4698 0, /* properties_provided */
4699 0, /* properties_destroyed */
4700 TODO_verify_flow
, /* todo_flags_start */
4702 TODO_ggc_collect
, /* todo_flags_finish */
4707 rest_of_handle_flow2 (void)
4709 /* If optimizing, then go ahead and split insns now. */
4713 split_all_insns (0);
4715 if (flag_branch_target_load_optimize
)
4716 branch_target_load_optimize (epilogue_completed
);
4719 cleanup_cfg (CLEANUP_EXPENSIVE
);
4721 /* On some machines, the prologue and epilogue code, or parts thereof,
4722 can be represented as RTL. Doing so lets us schedule insns between
4723 it and the rest of the code and also allows delayed branch
4724 scheduling to operate in the epilogue. */
4725 thread_prologue_and_epilogue_insns (get_insns ());
4726 epilogue_completed
= 1;
4727 flow2_completed
= 1;
4731 struct tree_opt_pass pass_flow2
=
4735 rest_of_handle_flow2
, /* execute */
4738 0, /* static_pass_number */
4739 TV_FLOW2
, /* tv_id */
4740 0, /* properties_required */
4741 0, /* properties_provided */
4742 0, /* properties_destroyed */
4743 TODO_verify_flow
, /* todo_flags_start */
4745 TODO_ggc_collect
, /* todo_flags_finish */