1 /* RTL dead code elimination.
2 Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
28 #include "hard-reg-set.h"
35 #include "tree-pass.h"
38 #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
41 /* -------------------------------------------------------------------------
42 Core mark/delete routines
43 ------------------------------------------------------------------------- */
45 /* True if we are invoked while the df engine is running; in this case,
46 we don't want to reenter it. */
47 static bool df_in_progress
= false;
49 /* Instructions that have been marked but whose dependencies have not
50 yet been processed. */
51 static VEC(rtx
,heap
) *worklist
;
53 /* Bitmap of instructions marked as needed indexed by INSN_UID. */
54 static sbitmap marked
;
56 /* Bitmap obstacks used for block processing by the fast algorithm. */
57 static bitmap_obstack dce_blocks_bitmap_obstack
;
58 static bitmap_obstack dce_tmp_bitmap_obstack
;
60 static bool find_call_stack_args (rtx
, bool, bool, bitmap
);
62 /* A subroutine for which BODY is part of the instruction being tested;
63 either the top-level pattern, or an element of a PARALLEL. The
64 instruction is known not to be a bare USE or CLOBBER. */
67 deletable_insn_p_1 (rtx body
)
69 switch (GET_CODE (body
))
73 /* The UNSPEC case was added here because the ia-64 claims that
74 USEs do not work after reload and generates UNSPECS rather
75 than USEs. Since dce is run after reload we need to avoid
76 deleting these even if they are dead. If it turns out that
77 USEs really do work after reload, the ia-64 should be
78 changed, and the UNSPEC case can be removed. */
83 return !volatile_refs_p (body
);
88 /* Return true if INSN is a normal instruction that can be deleted by
92 deletable_insn_p (rtx insn
, bool fast
, bitmap arg_stores
)
98 /* We cannot delete calls inside of the recursive dce because
99 this may cause basic blocks to be deleted and this messes up
100 the rest of the stack of optimization passes. */
102 /* We cannot delete pure or const sibling calls because it is
103 hard to see the result. */
104 && (!SIBLING_CALL_P (insn
))
105 /* We can delete dead const or pure calls as long as they do not
107 && (RTL_CONST_OR_PURE_CALL_P (insn
)
108 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn
)))
109 return find_call_stack_args (insn
, false, fast
, arg_stores
);
111 /* Don't delete jumps, notes and the like. */
112 if (!NONJUMP_INSN_P (insn
))
115 /* Don't delete insns that can throw. */
116 if (!insn_nothrow_p (insn
))
119 body
= PATTERN (insn
);
120 switch (GET_CODE (body
))
129 /* A CLOBBER of a dead pseudo register serves no purpose.
130 That is not necessarily true for hard registers until
133 return REG_P (x
) && (!HARD_REGISTER_P (x
) || reload_completed
);
136 /* Because of the way that use-def chains are built, it is not
137 possible to tell if the clobber is dead because it can
138 never be the target of a use-def chain. */
142 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; i
--)
143 if (!deletable_insn_p_1 (XVECEXP (body
, 0, i
)))
148 return deletable_insn_p_1 (body
);
153 /* Return true if INSN has been marked as needed. */
156 marked_insn_p (rtx insn
)
158 /* Artificial defs are always needed and they do not have an insn.
159 We should never see them here. */
161 return TEST_BIT (marked
, INSN_UID (insn
));
165 /* If INSN has not yet been marked as needed, mark it now, and add it to
169 mark_insn (rtx insn
, bool fast
)
171 if (!marked_insn_p (insn
))
174 VEC_safe_push (rtx
, heap
, worklist
, insn
);
175 SET_BIT (marked
, INSN_UID (insn
));
177 fprintf (dump_file
, " Adding insn %d to worklist\n", INSN_UID (insn
));
180 && !SIBLING_CALL_P (insn
)
181 && (RTL_CONST_OR_PURE_CALL_P (insn
)
182 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn
)))
183 find_call_stack_args (insn
, true, fast
, NULL
);
188 /* A note_stores callback used by mark_nonreg_stores. DATA is the
189 instruction containing DEST. */
192 mark_nonreg_stores_1 (rtx dest
, const_rtx pattern
, void *data
)
194 if (GET_CODE (pattern
) != CLOBBER
&& !REG_P (dest
))
195 mark_insn ((rtx
) data
, true);
199 /* A note_stores callback used by mark_nonreg_stores. DATA is the
200 instruction containing DEST. */
203 mark_nonreg_stores_2 (rtx dest
, const_rtx pattern
, void *data
)
205 if (GET_CODE (pattern
) != CLOBBER
&& !REG_P (dest
))
206 mark_insn ((rtx
) data
, false);
210 /* Mark INSN if BODY stores to a non-register destination. */
213 mark_nonreg_stores (rtx body
, rtx insn
, bool fast
)
216 note_stores (body
, mark_nonreg_stores_1
, insn
);
218 note_stores (body
, mark_nonreg_stores_2
, insn
);
222 /* Try to find all stack stores of CALL_INSN arguments if
223 ACCUMULATE_OUTGOING_ARGS. If all stack stores have been found
224 and it is therefore safe to eliminate the call, return true,
225 otherwise return false. This function should be first called
226 with DO_MARK false, and only when the CALL_INSN is actually
227 going to be marked called again with DO_MARK true. */
230 find_call_stack_args (rtx call_insn
, bool do_mark
, bool fast
,
233 rtx p
, insn
, prev_insn
;
235 HOST_WIDE_INT min_sp_off
, max_sp_off
;
238 gcc_assert (CALL_P (call_insn
));
239 if (!ACCUMULATE_OUTGOING_ARGS
)
244 gcc_assert (arg_stores
);
245 bitmap_clear (arg_stores
);
248 min_sp_off
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
251 /* First determine the minimum and maximum offset from sp for
253 for (p
= CALL_INSN_FUNCTION_USAGE (call_insn
); p
; p
= XEXP (p
, 1))
254 if (GET_CODE (XEXP (p
, 0)) == USE
255 && MEM_P (XEXP (XEXP (p
, 0), 0)))
257 rtx mem
= XEXP (XEXP (p
, 0), 0), addr
, size
;
258 HOST_WIDE_INT off
= 0;
259 size
= MEM_SIZE (mem
);
260 if (size
== NULL_RTX
)
262 addr
= XEXP (mem
, 0);
263 if (GET_CODE (addr
) == PLUS
264 && REG_P (XEXP (addr
, 0))
265 && CONST_INT_P (XEXP (addr
, 1)))
267 off
= INTVAL (XEXP (addr
, 1));
268 addr
= XEXP (addr
, 0);
270 if (addr
!= stack_pointer_rtx
)
274 /* If not fast, use chains to see if addr wasn't set to
279 struct df_link
*defs
;
282 for (use_rec
= DF_INSN_USES (call_insn
); *use_rec
; use_rec
++)
283 if (rtx_equal_p (addr
, DF_REF_REG (*use_rec
)))
286 if (*use_rec
== NULL
)
289 for (defs
= DF_REF_CHAIN (*use_rec
); defs
; defs
= defs
->next
)
290 if (! DF_REF_IS_ARTIFICIAL (defs
->ref
))
296 set
= single_set (DF_REF_INSN (defs
->ref
));
300 if (GET_CODE (SET_SRC (set
)) != PLUS
301 || XEXP (SET_SRC (set
), 0) != stack_pointer_rtx
302 || !CONST_INT_P (XEXP (SET_SRC (set
), 1)))
305 off
+= INTVAL (XEXP (SET_SRC (set
), 1));
310 min_sp_off
= MIN (min_sp_off
, off
);
311 max_sp_off
= MAX (max_sp_off
, off
+ INTVAL (size
));
314 if (min_sp_off
>= max_sp_off
)
316 sp_bytes
= BITMAP_ALLOC (NULL
);
318 /* Set bits in SP_BYTES bitmap for bytes relative to sp + min_sp_off
319 which contain arguments. Checking has been done in the previous
321 for (p
= CALL_INSN_FUNCTION_USAGE (call_insn
); p
; p
= XEXP (p
, 1))
322 if (GET_CODE (XEXP (p
, 0)) == USE
323 && MEM_P (XEXP (XEXP (p
, 0), 0)))
325 rtx mem
= XEXP (XEXP (p
, 0), 0), addr
;
326 HOST_WIDE_INT off
= 0, byte
;
327 addr
= XEXP (mem
, 0);
328 if (GET_CODE (addr
) == PLUS
329 && REG_P (XEXP (addr
, 0))
330 && CONST_INT_P (XEXP (addr
, 1)))
332 off
= INTVAL (XEXP (addr
, 1));
333 addr
= XEXP (addr
, 0);
335 if (addr
!= stack_pointer_rtx
)
338 struct df_link
*defs
;
341 for (use_rec
= DF_INSN_USES (call_insn
); *use_rec
; use_rec
++)
342 if (rtx_equal_p (addr
, DF_REF_REG (*use_rec
)))
345 for (defs
= DF_REF_CHAIN (*use_rec
); defs
; defs
= defs
->next
)
346 if (! DF_REF_IS_ARTIFICIAL (defs
->ref
))
349 set
= single_set (DF_REF_INSN (defs
->ref
));
350 off
+= INTVAL (XEXP (SET_SRC (set
), 1));
352 for (byte
= off
; byte
< off
+ INTVAL (MEM_SIZE (mem
)); byte
++)
354 if (!bitmap_set_bit (sp_bytes
, byte
- min_sp_off
))
359 /* Walk backwards, looking for argument stores. The search stops
360 when seeing another call, sp adjustment or memory store other than
363 for (insn
= PREV_INSN (call_insn
); insn
; insn
= prev_insn
)
366 HOST_WIDE_INT off
, byte
;
368 if (insn
== BB_HEAD (BLOCK_FOR_INSN (call_insn
)))
369 prev_insn
= NULL_RTX
;
371 prev_insn
= PREV_INSN (insn
);
379 set
= single_set (insn
);
380 if (!set
|| SET_DEST (set
) == stack_pointer_rtx
)
383 if (!MEM_P (SET_DEST (set
)))
386 mem
= SET_DEST (set
);
387 addr
= XEXP (mem
, 0);
389 if (GET_CODE (addr
) == PLUS
390 && REG_P (XEXP (addr
, 0))
391 && CONST_INT_P (XEXP (addr
, 1)))
393 off
= INTVAL (XEXP (addr
, 1));
394 addr
= XEXP (addr
, 0);
396 if (addr
!= stack_pointer_rtx
)
403 struct df_link
*defs
;
406 for (use_rec
= DF_INSN_USES (insn
); *use_rec
; use_rec
++)
407 if (rtx_equal_p (addr
, DF_REF_REG (*use_rec
)))
410 if (*use_rec
== NULL
)
413 for (defs
= DF_REF_CHAIN (*use_rec
); defs
; defs
= defs
->next
)
414 if (! DF_REF_IS_ARTIFICIAL (defs
->ref
))
420 set
= single_set (DF_REF_INSN (defs
->ref
));
424 if (GET_CODE (SET_SRC (set
)) != PLUS
425 || XEXP (SET_SRC (set
), 0) != stack_pointer_rtx
426 || !CONST_INT_P (XEXP (SET_SRC (set
), 1)))
429 off
+= INTVAL (XEXP (SET_SRC (set
), 1));
435 if (GET_MODE_SIZE (GET_MODE (mem
)) == 0)
438 for (byte
= off
; byte
< off
+ GET_MODE_SIZE (GET_MODE (mem
)); byte
++)
440 if (byte
< min_sp_off
441 || byte
>= max_sp_off
442 || !bitmap_clear_bit (sp_bytes
, byte
- min_sp_off
))
446 if (!deletable_insn_p (insn
, fast
, NULL
))
450 mark_insn (insn
, fast
);
452 bitmap_set_bit (arg_stores
, INSN_UID (insn
));
454 if (bitmap_empty_p (sp_bytes
))
461 BITMAP_FREE (sp_bytes
);
462 if (!ret
&& arg_stores
)
463 bitmap_clear (arg_stores
);
469 /* Remove all REG_EQUAL and REG_EQUIV notes referring to the registers INSN
473 remove_reg_equal_equiv_notes_for_defs (rtx insn
)
477 for (def_rec
= DF_INSN_DEFS (insn
); *def_rec
; def_rec
++)
478 remove_reg_equal_equiv_notes_for_regno (DF_REF_REGNO (*def_rec
));
482 /* Delete every instruction that hasn't been marked. */
485 delete_unmarked_insns (void)
489 bool must_clean
= false;
491 FOR_EACH_BB_REVERSE (bb
)
492 FOR_BB_INSNS_REVERSE_SAFE (bb
, insn
, next
)
495 /* Always delete no-op moves. */
496 if (noop_move_p (insn
))
499 /* Otherwise rely only on the DCE algorithm. */
500 else if (marked_insn_p (insn
))
503 /* Beware that reaching a dbg counter limit here can result
504 in miscompiled file. This occurs when a group of insns
505 must be deleted together, typically because the kept insn
506 depends on the output from the deleted insn. Deleting
507 this insns in reverse order (both at the bb level and
508 when looking at the blocks) minimizes this, but does not
509 eliminate it, since it is possible for the using insn to
510 be top of a block and the producer to be at the bottom of
511 the block. However, in most cases this will only result
512 in an uninitialized use of an insn that is dead anyway.
514 However, there is one rare case that will cause a
515 miscompile: deletion of non-looping pure and constant
516 calls on a machine where ACCUMULATE_OUTGOING_ARGS is true.
517 In this case it is possible to remove the call, but leave
518 the argument pushes to the stack. Because of the changes
519 to the stack pointer, this will almost always lead to a
525 fprintf (dump_file
, "DCE: Deleting insn %d\n", INSN_UID (insn
));
527 /* Before we delete the insn we have to remove the REG_EQUAL notes
528 for the destination regs in order to avoid dangling notes. */
529 remove_reg_equal_equiv_notes_for_defs (insn
);
531 /* If a pure or const call is deleted, this may make the cfg
532 have unreachable blocks. We rememeber this and call
533 delete_unreachable_blocks at the end. */
537 /* Now delete the insn. */
538 delete_insn_and_edges (insn
);
541 /* Deleted a pure or const call. */
543 delete_unreachable_blocks ();
547 /* Go through the instructions and mark those whose necessity is not
548 dependent on inter-instruction information. Make sure all other
549 instructions are not marked. */
552 prescan_insns_for_dce (bool fast
)
556 bitmap arg_stores
= NULL
;
559 fprintf (dump_file
, "Finding needed instructions:\n");
561 if (!df_in_progress
&& ACCUMULATE_OUTGOING_ARGS
)
562 arg_stores
= BITMAP_ALLOC (NULL
);
566 FOR_BB_INSNS_REVERSE_SAFE (bb
, insn
, prev
)
569 /* Don't mark argument stores now. They will be marked
570 if needed when the associated CALL is marked. */
571 if (arg_stores
&& bitmap_bit_p (arg_stores
, INSN_UID (insn
)))
573 if (deletable_insn_p (insn
, fast
, arg_stores
))
574 mark_nonreg_stores (PATTERN (insn
), insn
, fast
);
576 mark_insn (insn
, fast
);
578 /* find_call_stack_args only looks at argument stores in the
581 bitmap_clear (arg_stores
);
585 BITMAP_FREE (arg_stores
);
588 fprintf (dump_file
, "Finished finding needed instructions:\n");
592 /* UD-based DSE routines. */
594 /* Mark instructions that define artificially-used registers, such as
595 the frame pointer and the stack pointer. */
598 mark_artificial_uses (void)
601 struct df_link
*defs
;
606 for (use_rec
= df_get_artificial_uses (bb
->index
);
608 for (defs
= DF_REF_CHAIN (*use_rec
); defs
; defs
= defs
->next
)
609 if (! DF_REF_IS_ARTIFICIAL (defs
->ref
))
610 mark_insn (DF_REF_INSN (defs
->ref
), false);
615 /* Mark every instruction that defines a register value that INSN uses. */
618 mark_reg_dependencies (rtx insn
)
620 struct df_link
*defs
;
623 if (DEBUG_INSN_P (insn
))
626 for (use_rec
= DF_INSN_USES (insn
); *use_rec
; use_rec
++)
628 df_ref use
= *use_rec
;
631 fprintf (dump_file
, "Processing use of ");
632 print_simple_rtl (dump_file
, DF_REF_REG (use
));
633 fprintf (dump_file
, " in insn %d:\n", INSN_UID (insn
));
635 for (defs
= DF_REF_CHAIN (use
); defs
; defs
= defs
->next
)
636 if (! DF_REF_IS_ARTIFICIAL (defs
->ref
))
637 mark_insn (DF_REF_INSN (defs
->ref
), false);
642 /* Initialize global variables for a new DCE pass. */
650 df_chain_add_problem (DF_UD_CHAIN
);
659 bitmap_obstack_initialize (&dce_blocks_bitmap_obstack
);
660 bitmap_obstack_initialize (&dce_tmp_bitmap_obstack
);
663 marked
= sbitmap_alloc (get_max_uid () + 1);
664 sbitmap_zero (marked
);
668 /* Free the data allocated by init_dce. */
673 sbitmap_free (marked
);
677 bitmap_obstack_release (&dce_blocks_bitmap_obstack
);
678 bitmap_obstack_release (&dce_tmp_bitmap_obstack
);
683 /* UD-chain based DCE. */
686 rest_of_handle_ud_dce (void)
692 prescan_insns_for_dce (false);
693 mark_artificial_uses ();
694 while (VEC_length (rtx
, worklist
) > 0)
696 insn
= VEC_pop (rtx
, worklist
);
697 mark_reg_dependencies (insn
);
699 VEC_free (rtx
, heap
, worklist
);
701 /* Before any insns are deleted, we must remove the chains since
702 they are not bidirectional. */
703 df_remove_problem (df_chain
);
704 delete_unmarked_insns ();
714 return optimize
> 1 && flag_dce
718 struct rtl_opt_pass pass_ud_rtl_dce
=
723 gate_ud_dce
, /* gate */
724 rest_of_handle_ud_dce
, /* execute */
727 0, /* static_pass_number */
729 0, /* properties_required */
730 0, /* properties_provided */
731 0, /* properties_destroyed */
732 0, /* todo_flags_start */
734 TODO_df_finish
| TODO_verify_rtl_sharing
|
735 TODO_ggc_collect
/* todo_flags_finish */
740 /* -------------------------------------------------------------------------
742 ------------------------------------------------------------------------- */
744 /* Process basic block BB. Return true if the live_in set has
745 changed. REDO_OUT is true if the info at the bottom of the block
746 needs to be recalculated before starting. AU is the proper set of
750 word_dce_process_block (basic_block bb
, bool redo_out
)
752 bitmap local_live
= BITMAP_ALLOC (&dce_tmp_bitmap_obstack
);
758 /* Need to redo the live_out set of this block if when one of
759 the succs of this block has had a change in it live in
763 df_confluence_function_n con_fun_n
= df_word_lr
->problem
->con_fun_n
;
764 bitmap_clear (DF_WORD_LR_OUT (bb
));
765 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
771 fprintf (dump_file
, "processing block %d live out = ", bb
->index
);
772 df_print_word_regset (dump_file
, DF_WORD_LR_OUT (bb
));
775 bitmap_copy (local_live
, DF_WORD_LR_OUT (bb
));
777 FOR_BB_INSNS_REVERSE (bb
, insn
)
778 if (NONDEBUG_INSN_P (insn
))
781 /* No matter if the instruction is needed or not, we remove
782 any regno in the defs from the live set. */
783 any_changed
= df_word_lr_simulate_defs (insn
, local_live
);
785 mark_insn (insn
, true);
787 /* On the other hand, we do not allow the dead uses to set
788 anything in local_live. */
789 if (marked_insn_p (insn
))
790 df_word_lr_simulate_uses (insn
, local_live
);
794 fprintf (dump_file
, "finished processing insn %d live out = ",
796 df_print_word_regset (dump_file
, local_live
);
800 block_changed
= !bitmap_equal_p (local_live
, DF_WORD_LR_IN (bb
));
802 bitmap_copy (DF_WORD_LR_IN (bb
), local_live
);
804 BITMAP_FREE (local_live
);
805 return block_changed
;
809 /* Process basic block BB. Return true if the live_in set has
810 changed. REDO_OUT is true if the info at the bottom of the block
811 needs to be recalculated before starting. AU is the proper set of
815 dce_process_block (basic_block bb
, bool redo_out
, bitmap au
)
817 bitmap local_live
= BITMAP_ALLOC (&dce_tmp_bitmap_obstack
);
824 /* Need to redo the live_out set of this block if when one of
825 the succs of this block has had a change in it live in
829 df_confluence_function_n con_fun_n
= df_lr
->problem
->con_fun_n
;
830 bitmap_clear (DF_LR_OUT (bb
));
831 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
837 fprintf (dump_file
, "processing block %d lr out = ", bb
->index
);
838 df_print_regset (dump_file
, DF_LR_OUT (bb
));
841 bitmap_copy (local_live
, DF_LR_OUT (bb
));
843 df_simulate_initialize_backwards (bb
, local_live
);
845 FOR_BB_INSNS_REVERSE (bb
, insn
)
848 bool needed
= marked_insn_p (insn
);
850 /* The insn is needed if there is someone who uses the output. */
852 for (def_rec
= DF_INSN_DEFS (insn
); *def_rec
; def_rec
++)
853 if (bitmap_bit_p (local_live
, DF_REF_REGNO (*def_rec
))
854 || bitmap_bit_p (au
, DF_REF_REGNO (*def_rec
)))
857 mark_insn (insn
, true);
861 /* No matter if the instruction is needed or not, we remove
862 any regno in the defs from the live set. */
863 df_simulate_defs (insn
, local_live
);
865 /* On the other hand, we do not allow the dead uses to set
866 anything in local_live. */
868 df_simulate_uses (insn
, local_live
);
871 df_simulate_finalize_backwards (bb
, local_live
);
873 block_changed
= !bitmap_equal_p (local_live
, DF_LR_IN (bb
));
875 bitmap_copy (DF_LR_IN (bb
), local_live
);
877 BITMAP_FREE (local_live
);
878 return block_changed
;
882 /* Perform fast DCE once initialization is done. If WORD_LEVEL is
883 true, use the word level dce, otherwise do it at the pseudo
887 fast_dce (bool word_level
)
889 int *postorder
= df_get_postorder (DF_BACKWARD
);
890 int n_blocks
= df_get_n_blocks (DF_BACKWARD
);
891 /* The set of blocks that have been seen on this iteration. */
892 bitmap processed
= BITMAP_ALLOC (&dce_blocks_bitmap_obstack
);
893 /* The set of blocks that need to have the out vectors reset because
894 the in of one of their successors has changed. */
895 bitmap redo_out
= BITMAP_ALLOC (&dce_blocks_bitmap_obstack
);
896 bitmap all_blocks
= BITMAP_ALLOC (&dce_blocks_bitmap_obstack
);
897 bool global_changed
= true;
899 /* These regs are considered always live so if they end up dying
900 because of some def, we need to bring the back again. Calling
901 df_simulate_fixup_sets has the disadvantage of calling
902 bb_has_eh_pred once per insn, so we cache the information
904 bitmap au
= &df
->regular_block_artificial_uses
;
905 bitmap au_eh
= &df
->eh_block_artificial_uses
;
908 prescan_insns_for_dce (true);
910 for (i
= 0; i
< n_blocks
; i
++)
911 bitmap_set_bit (all_blocks
, postorder
[i
]);
913 while (global_changed
)
915 global_changed
= false;
917 for (i
= 0; i
< n_blocks
; i
++)
919 int index
= postorder
[i
];
920 basic_block bb
= BASIC_BLOCK (index
);
923 if (index
< NUM_FIXED_BLOCKS
)
925 bitmap_set_bit (processed
, index
);
931 = word_dce_process_block (bb
, bitmap_bit_p (redo_out
, index
));
934 = dce_process_block (bb
, bitmap_bit_p (redo_out
, index
),
935 bb_has_eh_pred (bb
) ? au_eh
: au
);
936 bitmap_set_bit (processed
, index
);
942 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
943 if (bitmap_bit_p (processed
, e
->src
->index
))
944 /* Be tricky about when we need to iterate the
945 analysis. We only have redo the analysis if the
946 bitmaps change at the top of a block that is the
948 global_changed
= true;
950 bitmap_set_bit (redo_out
, e
->src
->index
);
956 /* Turn off the RUN_DCE flag to prevent recursive calls to
958 int old_flag
= df_clear_flags (DF_LR_RUN_DCE
);
960 /* So something was deleted that requires a redo. Do it on
962 delete_unmarked_insns ();
963 sbitmap_zero (marked
);
964 bitmap_clear (processed
);
965 bitmap_clear (redo_out
);
967 /* We do not need to rescan any instructions. We only need
968 to redo the dataflow equations for the blocks that had a
969 change at the top of the block. Then we need to redo the
972 df_analyze_problem (df_word_lr
, all_blocks
, postorder
, n_blocks
);
974 df_analyze_problem (df_lr
, all_blocks
, postorder
, n_blocks
);
976 if (old_flag
& DF_LR_RUN_DCE
)
977 df_set_flags (DF_LR_RUN_DCE
);
979 prescan_insns_for_dce (true);
983 delete_unmarked_insns ();
985 BITMAP_FREE (processed
);
986 BITMAP_FREE (redo_out
);
987 BITMAP_FREE (all_blocks
);
991 /* Fast register level DCE. */
994 rest_of_handle_fast_dce (void)
1003 /* Fast byte level DCE. */
1013 timevar_push (TV_DCE
);
1014 old_flags
= df_clear_flags (DF_DEFER_INSN_RESCAN
+ DF_NO_INSN_RESCAN
);
1015 df_word_lr_add_problem ();
1019 df_set_flags (old_flags
);
1020 timevar_pop (TV_DCE
);
1024 /* This is an internal call that is used by the df live register
1025 problem to run fast dce as a side effect of creating the live
1026 information. The stack is organized so that the lr problem is run,
1027 this pass is run, which updates the live info and the df scanning
1028 info, and then returns to allow the rest of the problems to be run.
1030 This can be called by elsewhere but it will not update the bit
1031 vectors for any other problems than LR. */
1034 run_fast_df_dce (void)
1038 /* If dce is able to delete something, it has to happen
1039 immediately. Otherwise there will be problems handling the
1042 df_clear_flags (DF_DEFER_INSN_RESCAN
+ DF_NO_INSN_RESCAN
);
1044 df_in_progress
= true;
1045 rest_of_handle_fast_dce ();
1046 df_in_progress
= false;
1048 df_set_flags (old_flags
);
1053 /* Run a fast DCE pass. */
1059 rest_of_handle_fast_dce ();
1064 gate_fast_dce (void)
1066 return optimize
> 0 && flag_dce
1067 && dbg_cnt (dce_fast
);
1070 struct rtl_opt_pass pass_fast_rtl_dce
=
1074 "rtl dce", /* name */
1075 gate_fast_dce
, /* gate */
1076 rest_of_handle_fast_dce
, /* execute */
1079 0, /* static_pass_number */
1081 0, /* properties_required */
1082 0, /* properties_provided */
1083 0, /* properties_destroyed */
1084 0, /* todo_flags_start */
1086 TODO_df_finish
| TODO_verify_rtl_sharing
|
1087 TODO_ggc_collect
/* todo_flags_finish */