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"
34 #include "tree-pass.h"
39 DEF_VEC_ALLOC_I(int,heap);
42 /* -------------------------------------------------------------------------
43 Core mark/delete routines
44 ------------------------------------------------------------------------- */
46 /* True if we are invoked while the df engine is running; in this case,
47 we don't want to reenter it. */
48 static bool df_in_progress = false;
50 /* Instructions that have been marked but whose dependencies have not
51 yet been processed. */
52 static VEC(rtx,heap) *worklist;
54 /* Bitmap of instructions marked as needed indexed by INSN_UID. */
55 static sbitmap marked;
57 /* Bitmap obstacks used for block processing by the fast algorithm. */
58 static bitmap_obstack dce_blocks_bitmap_obstack;
59 static bitmap_obstack dce_tmp_bitmap_obstack;
61 static bool find_call_stack_args (rtx, bool, bool, bitmap);
63 /* A subroutine for which BODY is part of the instruction being tested;
64 either the top-level pattern, or an element of a PARALLEL. The
65 instruction is known not to be a bare USE or CLOBBER. */
68 deletable_insn_p_1 (rtx body)
70 switch (GET_CODE (body))
74 /* The UNSPEC case was added here because the ia-64 claims that
75 USEs do not work after reload and generates UNSPECS rather
76 than USEs. Since dce is run after reload we need to avoid
77 deleting these even if they are dead. If it turns out that
78 USEs really do work after reload, the ia-64 should be
79 changed, and the UNSPEC case can be removed. */
84 if (volatile_refs_p (body))
87 if (flag_non_call_exceptions && may_trap_p (body))
95 /* Return true if INSN is a normal instruction that can be deleted by
99 deletable_insn_p (rtx insn, bool fast, bitmap arg_stores)
105 /* We cannot delete calls inside of the recursive dce because
106 this may cause basic blocks to be deleted and this messes up
107 the rest of the stack of optimization passes. */
109 /* We cannot delete pure or const sibling calls because it is
110 hard to see the result. */
111 && (!SIBLING_CALL_P (insn))
112 /* We can delete dead const or pure calls as long as they do not
114 && (RTL_CONST_OR_PURE_CALL_P (insn)
115 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn)))
116 return find_call_stack_args (insn, false, fast, arg_stores);
118 if (!NONJUMP_INSN_P (insn))
121 body = PATTERN (insn);
122 switch (GET_CODE (body))
130 /* A CLOBBER of a dead pseudo register serves no purpose.
131 That is not necessarily true for hard registers until
134 return REG_P (x) && (!HARD_REGISTER_P (x) || reload_completed);
137 /* Because of the way that use-def chains are built, it is not
138 possible to tell if the clobber is dead because it can
139 never be the target of a use-def chain. */
143 for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
144 if (!deletable_insn_p_1 (XVECEXP (body, 0, i)))
149 return deletable_insn_p_1 (body);
154 /* Return true if INSN has been marked as needed. */
157 marked_insn_p (rtx insn)
159 /* Artificial defs are always needed and they do not have an insn.
160 We should never see them here. */
162 return TEST_BIT (marked, INSN_UID (insn));
166 /* If INSN has not yet been marked as needed, mark it now, and add it to
170 mark_insn (rtx insn, bool fast)
172 if (!marked_insn_p (insn))
175 VEC_safe_push (rtx, heap, worklist, insn);
176 SET_BIT (marked, INSN_UID (insn));
178 fprintf (dump_file, " Adding insn %d to worklist\n", INSN_UID (insn));
181 && !SIBLING_CALL_P (insn)
182 && (RTL_CONST_OR_PURE_CALL_P (insn)
183 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn)))
184 find_call_stack_args (insn, true, fast, NULL);
189 /* A note_stores callback used by mark_nonreg_stores. DATA is the
190 instruction containing DEST. */
193 mark_nonreg_stores_1 (rtx dest, const_rtx pattern, void *data)
195 if (GET_CODE (pattern) != CLOBBER && !REG_P (dest))
196 mark_insn ((rtx) data, true);
200 /* A note_stores callback used by mark_nonreg_stores. DATA is the
201 instruction containing DEST. */
204 mark_nonreg_stores_2 (rtx dest, const_rtx pattern, void *data)
206 if (GET_CODE (pattern) != CLOBBER && !REG_P (dest))
207 mark_insn ((rtx) data, false);
211 /* Mark INSN if BODY stores to a non-register destination. */
214 mark_nonreg_stores (rtx body, rtx insn, bool fast)
217 note_stores (body, mark_nonreg_stores_1, insn);
219 note_stores (body, mark_nonreg_stores_2, insn);
223 /* Try to find all stack stores of CALL_INSN arguments if
224 ACCUMULATE_OUTGOING_ARGS. If all stack stores have been found
225 and it is therefore safe to eliminate the call, return true,
226 otherwise return false. This function should be first called
227 with DO_MARK false, and only when the CALL_INSN is actually
228 going to be marked called again with DO_MARK true. */
231 find_call_stack_args (rtx call_insn, bool do_mark, bool fast,
234 rtx p, insn, prev_insn;
236 HOST_WIDE_INT min_sp_off, max_sp_off;
239 gcc_assert (CALL_P (call_insn));
240 if (!ACCUMULATE_OUTGOING_ARGS)
245 gcc_assert (arg_stores);
246 bitmap_clear (arg_stores);
249 min_sp_off = INTTYPE_MAXIMUM (HOST_WIDE_INT);
252 /* First determine the minimum and maximum offset from sp for
254 for (p = CALL_INSN_FUNCTION_USAGE (call_insn); p; p = XEXP (p, 1))
255 if (GET_CODE (XEXP (p, 0)) == USE
256 && MEM_P (XEXP (XEXP (p, 0), 0)))
258 rtx mem = XEXP (XEXP (p, 0), 0), addr, size;
259 HOST_WIDE_INT off = 0;
260 size = MEM_SIZE (mem);
261 if (size == NULL_RTX)
263 addr = XEXP (mem, 0);
264 if (GET_CODE (addr) == PLUS
265 && REG_P (XEXP (addr, 0))
266 && CONST_INT_P (XEXP (addr, 1)))
268 off = INTVAL (XEXP (addr, 1));
269 addr = XEXP (addr, 0);
271 if (addr != stack_pointer_rtx)
275 /* If not fast, use chains to see if addr wasn't set to
280 struct df_link *defs;
283 for (use_rec = DF_INSN_USES (call_insn); *use_rec; use_rec++)
284 if (rtx_equal_p (addr, DF_REF_REG (*use_rec)))
287 if (*use_rec == NULL)
290 for (defs = DF_REF_CHAIN (*use_rec); defs; defs = defs->next)
291 if (! DF_REF_IS_ARTIFICIAL (defs->ref))
297 set = single_set (DF_REF_INSN (defs->ref));
301 if (GET_CODE (SET_SRC (set)) != PLUS
302 || XEXP (SET_SRC (set), 0) != stack_pointer_rtx
303 || !CONST_INT_P (XEXP (SET_SRC (set), 1)))
306 off += INTVAL (XEXP (SET_SRC (set), 1));
311 min_sp_off = MIN (min_sp_off, off);
312 max_sp_off = MAX (max_sp_off, off + INTVAL (size));
315 if (min_sp_off >= max_sp_off)
317 sp_bytes = BITMAP_ALLOC (NULL);
319 /* Set bits in SP_BYTES bitmap for bytes relative to sp + min_sp_off
320 which contain arguments. Checking has been done in the previous
322 for (p = CALL_INSN_FUNCTION_USAGE (call_insn); p; p = XEXP (p, 1))
323 if (GET_CODE (XEXP (p, 0)) == USE
324 && MEM_P (XEXP (XEXP (p, 0), 0)))
326 rtx mem = XEXP (XEXP (p, 0), 0), addr;
327 HOST_WIDE_INT off = 0, byte;
328 addr = XEXP (mem, 0);
329 if (GET_CODE (addr) == PLUS
330 && REG_P (XEXP (addr, 0))
331 && CONST_INT_P (XEXP (addr, 1)))
333 off = INTVAL (XEXP (addr, 1));
334 addr = XEXP (addr, 0);
336 if (addr != stack_pointer_rtx)
339 struct df_link *defs;
342 for (use_rec = DF_INSN_USES (call_insn); *use_rec; use_rec++)
343 if (rtx_equal_p (addr, DF_REF_REG (*use_rec)))
346 for (defs = DF_REF_CHAIN (*use_rec); defs; defs = defs->next)
347 if (! DF_REF_IS_ARTIFICIAL (defs->ref))
350 set = single_set (DF_REF_INSN (defs->ref));
351 off += INTVAL (XEXP (SET_SRC (set), 1));
353 for (byte = off; byte < off + INTVAL (MEM_SIZE (mem)); byte++)
355 gcc_assert (!bitmap_bit_p (sp_bytes, byte - min_sp_off));
356 bitmap_set_bit (sp_bytes, byte - min_sp_off);
360 /* Walk backwards, looking for argument stores. The search stops
361 when seeing another call, sp adjustment or memory store other than
364 for (insn = PREV_INSN (call_insn); insn; insn = prev_insn)
367 HOST_WIDE_INT off, byte;
369 if (insn == BB_HEAD (BLOCK_FOR_INSN (call_insn)))
370 prev_insn = NULL_RTX;
372 prev_insn = PREV_INSN (insn);
380 set = single_set (insn);
381 if (!set || SET_DEST (set) == stack_pointer_rtx)
384 if (!MEM_P (SET_DEST (set)))
387 mem = SET_DEST (set);
388 addr = XEXP (mem, 0);
390 if (GET_CODE (addr) == PLUS
391 && REG_P (XEXP (addr, 0))
392 && CONST_INT_P (XEXP (addr, 1)))
394 off = INTVAL (XEXP (addr, 1));
395 addr = XEXP (addr, 0);
397 if (addr != stack_pointer_rtx)
404 struct df_link *defs;
407 for (use_rec = DF_INSN_USES (insn); *use_rec; use_rec++)
408 if (rtx_equal_p (addr, DF_REF_REG (*use_rec)))
411 if (*use_rec == NULL)
414 for (defs = DF_REF_CHAIN (*use_rec); defs; defs = defs->next)
415 if (! DF_REF_IS_ARTIFICIAL (defs->ref))
421 set = single_set (DF_REF_INSN (defs->ref));
425 if (GET_CODE (SET_SRC (set)) != PLUS
426 || XEXP (SET_SRC (set), 0) != stack_pointer_rtx
427 || !CONST_INT_P (XEXP (SET_SRC (set), 1)))
430 off += INTVAL (XEXP (SET_SRC (set), 1));
436 if (GET_MODE_SIZE (GET_MODE (mem)) == 0)
439 for (byte = off; byte < off + GET_MODE_SIZE (GET_MODE (mem)); byte++)
441 if (byte < min_sp_off
442 || byte >= max_sp_off
443 || !bitmap_bit_p (sp_bytes, byte - min_sp_off))
445 bitmap_clear_bit (sp_bytes, byte - min_sp_off);
448 if (!deletable_insn_p (insn, fast, NULL))
452 mark_insn (insn, fast);
454 bitmap_set_bit (arg_stores, INSN_UID (insn));
456 if (bitmap_empty_p (sp_bytes))
463 BITMAP_FREE (sp_bytes);
464 if (!ret && arg_stores)
465 bitmap_clear (arg_stores);
471 /* Delete all REG_EQUAL notes of the registers INSN writes, to prevent
472 bad dangling REG_EQUAL notes. */
475 delete_corresponding_reg_eq_notes (rtx insn)
478 for (def_rec = DF_INSN_DEFS (insn); *def_rec; def_rec++)
480 df_ref def = *def_rec;
481 unsigned int regno = DF_REF_REGNO (def);
482 /* This loop is a little tricky. We cannot just go down the
483 chain because it is being modified by the actions in the
484 loop. So we just get the head. We plan to drain the list
486 while (DF_REG_EQ_USE_CHAIN (regno))
488 df_ref eq_use = DF_REG_EQ_USE_CHAIN (regno);
489 rtx noted_insn = DF_REF_INSN (eq_use);
490 rtx note = find_reg_note (noted_insn, REG_EQUAL, NULL_RTX);
492 note = find_reg_note (noted_insn, REG_EQUIV, NULL_RTX);
494 /* This assert is generally triggered when someone deletes a
495 REG_EQUAL or REG_EQUIV note by hacking the list manually
496 rather than calling remove_note. */
498 remove_note (noted_insn, note);
504 /* Delete every instruction that hasn't been marked. */
507 delete_unmarked_insns (void)
511 bool must_clean = false;
514 FOR_BB_INSNS_SAFE (bb, insn, next)
517 /* Always delete no-op moves. */
518 if (noop_move_p (insn))
521 /* Otherwise rely only on the DCE algorithm. */
522 else if (marked_insn_p (insn))
525 /* Beware that reaching a dbg counter limit here can rarely
526 result in miscompiled file. This occurs when a group of
527 insns must be deleted together. Currently this only
528 can happen on non-looping pure and constant calls
529 on machines where ACCUMULATE_OUTGOING_ARGS is true. By
530 using the dbg_cnt, it is possible to remove the call, but
531 leave the argument pushes to the stack. */
536 fprintf (dump_file, "DCE: Deleting insn %d\n", INSN_UID (insn));
538 /* Before we delete the insn we have to delete REG_EQUAL notes
539 for the destination regs in order to avoid dangling notes. */
540 delete_corresponding_reg_eq_notes (insn);
542 /* If a pure or const call is deleted, this may make the cfg
543 have unreachable blocks. We rememeber this and call
544 delete_unreachable_blocks at the end. */
548 /* Now delete the insn. */
549 delete_insn_and_edges (insn);
552 /* Deleted a pure or const call. */
554 delete_unreachable_blocks ();
558 /* Go through the instructions and mark those whose necessity is not
559 dependent on inter-instruction information. Make sure all other
560 instructions are not marked. */
563 prescan_insns_for_dce (bool fast)
567 bitmap arg_stores = NULL;
570 fprintf (dump_file, "Finding needed instructions:\n");
572 if (!df_in_progress && ACCUMULATE_OUTGOING_ARGS)
573 arg_stores = BITMAP_ALLOC (NULL);
577 FOR_BB_INSNS_REVERSE_SAFE (bb, insn, prev)
580 /* Don't mark argument stores now. They will be marked
581 if needed when the associated CALL is marked. */
582 if (arg_stores && bitmap_bit_p (arg_stores, INSN_UID (insn)))
584 if (deletable_insn_p (insn, fast, arg_stores))
585 mark_nonreg_stores (PATTERN (insn), insn, fast);
587 mark_insn (insn, fast);
589 /* find_call_stack_args only looks at argument stores in the
592 bitmap_clear (arg_stores);
596 BITMAP_FREE (arg_stores);
599 fprintf (dump_file, "Finished finding needed instructions:\n");
603 /* UD-based DSE routines. */
605 /* Mark instructions that define artificially-used registers, such as
606 the frame pointer and the stack pointer. */
609 mark_artificial_uses (void)
612 struct df_link *defs;
617 for (use_rec = df_get_artificial_uses (bb->index);
619 for (defs = DF_REF_CHAIN (*use_rec); defs; defs = defs->next)
620 if (! DF_REF_IS_ARTIFICIAL (defs->ref))
621 mark_insn (DF_REF_INSN (defs->ref), false);
626 /* Mark every instruction that defines a register value that INSN uses. */
629 mark_reg_dependencies (rtx insn)
631 struct df_link *defs;
634 for (use_rec = DF_INSN_USES (insn); *use_rec; use_rec++)
636 df_ref use = *use_rec;
639 fprintf (dump_file, "Processing use of ");
640 print_simple_rtl (dump_file, DF_REF_REG (use));
641 fprintf (dump_file, " in insn %d:\n", INSN_UID (insn));
643 for (defs = DF_REF_CHAIN (use); defs; defs = defs->next)
644 if (! DF_REF_IS_ARTIFICIAL (defs->ref))
645 mark_insn (DF_REF_INSN (defs->ref), false);
650 /* Initialize global variables for a new DCE pass. */
658 df_chain_add_problem (DF_UD_CHAIN);
667 bitmap_obstack_initialize (&dce_blocks_bitmap_obstack);
668 bitmap_obstack_initialize (&dce_tmp_bitmap_obstack);
671 marked = sbitmap_alloc (get_max_uid () + 1);
672 sbitmap_zero (marked);
676 /* Free the data allocated by init_dce. */
681 sbitmap_free (marked);
685 bitmap_obstack_release (&dce_blocks_bitmap_obstack);
686 bitmap_obstack_release (&dce_tmp_bitmap_obstack);
691 /* UD-chain based DCE. */
694 rest_of_handle_ud_dce (void)
700 prescan_insns_for_dce (false);
701 mark_artificial_uses ();
702 while (VEC_length (rtx, worklist) > 0)
704 insn = VEC_pop (rtx, worklist);
705 mark_reg_dependencies (insn);
707 VEC_free (rtx, heap, worklist);
709 /* Before any insns are deleted, we must remove the chains since
710 they are not bidirectional. */
711 df_remove_problem (df_chain);
712 delete_unmarked_insns ();
722 return optimize > 1 && flag_dce
726 struct rtl_opt_pass pass_ud_rtl_dce =
731 gate_ud_dce, /* gate */
732 rest_of_handle_ud_dce, /* execute */
735 0, /* static_pass_number */
737 0, /* properties_required */
738 0, /* properties_provided */
739 0, /* properties_destroyed */
740 0, /* todo_flags_start */
742 TODO_df_finish | TODO_verify_rtl_sharing |
743 TODO_ggc_collect /* todo_flags_finish */
748 /* -------------------------------------------------------------------------
750 ------------------------------------------------------------------------- */
752 /* Process basic block BB. Return true if the live_in set has
753 changed. REDO_OUT is true if the info at the bottom of the block
754 needs to be recalculated before starting. AU is the proper set of
758 byte_dce_process_block (basic_block bb, bool redo_out, bitmap au)
760 bitmap local_live = BITMAP_ALLOC (&dce_tmp_bitmap_obstack);
767 /* Need to redo the live_out set of this block if when one of
768 the succs of this block has had a change in it live in
772 df_confluence_function_n con_fun_n = df_byte_lr->problem->con_fun_n;
773 bitmap_clear (DF_BYTE_LR_OUT (bb));
774 FOR_EACH_EDGE (e, ei, bb->succs)
780 fprintf (dump_file, "processing block %d live out = ", bb->index);
781 df_print_byte_regset (dump_file, DF_BYTE_LR_OUT (bb));
784 bitmap_copy (local_live, DF_BYTE_LR_OUT (bb));
786 df_byte_lr_simulate_artificial_refs_at_end (bb, local_live);
788 FOR_BB_INSNS_REVERSE (bb, insn)
791 /* The insn is needed if there is someone who uses the output. */
792 for (def_rec = DF_INSN_DEFS (insn); *def_rec; def_rec++)
794 df_ref def = *def_rec;
796 unsigned int dregno = DF_REF_REGNO (def);
797 unsigned int start = df_byte_lr_get_regno_start (dregno);
798 unsigned int len = df_byte_lr_get_regno_len (dregno);
802 /* This is one of the only places where DF_MM_MAY should
803 be used for defs. Need to make sure that we are
804 checking for all of the bits that may be used. */
806 if (!df_compute_accessed_bytes (def, DF_MM_MAY, &sb, &lb))
812 if (bitmap_bit_p (au, dregno))
814 mark_insn (insn, true);
820 if (bitmap_bit_p (local_live, start++))
822 mark_insn (insn, true);
829 /* No matter if the instruction is needed or not, we remove
830 any regno in the defs from the live set. */
831 df_byte_lr_simulate_defs (insn, local_live);
833 /* On the other hand, we do not allow the dead uses to set
834 anything in local_live. */
835 if (marked_insn_p (insn))
836 df_byte_lr_simulate_uses (insn, local_live);
840 fprintf (dump_file, "finished processing insn %d live out = ",
842 df_print_byte_regset (dump_file, local_live);
846 df_byte_lr_simulate_artificial_refs_at_top (bb, local_live);
848 block_changed = !bitmap_equal_p (local_live, DF_BYTE_LR_IN (bb));
850 bitmap_copy (DF_BYTE_LR_IN (bb), local_live);
851 BITMAP_FREE (local_live);
852 return block_changed;
856 /* Process basic block BB. Return true if the live_in set has
857 changed. REDO_OUT is true if the info at the bottom of the block
858 needs to be recalculated before starting. AU is the proper set of
862 dce_process_block (basic_block bb, bool redo_out, bitmap au)
864 bitmap local_live = BITMAP_ALLOC (&dce_tmp_bitmap_obstack);
871 /* Need to redo the live_out set of this block if when one of
872 the succs of this block has had a change in it live in
876 df_confluence_function_n con_fun_n = df_lr->problem->con_fun_n;
877 bitmap_clear (DF_LR_OUT (bb));
878 FOR_EACH_EDGE (e, ei, bb->succs)
884 fprintf (dump_file, "processing block %d lr out = ", bb->index);
885 df_print_regset (dump_file, DF_LR_OUT (bb));
888 bitmap_copy (local_live, DF_LR_OUT (bb));
890 df_simulate_initialize_backwards (bb, local_live);
892 FOR_BB_INSNS_REVERSE (bb, insn)
897 /* The insn is needed if there is someone who uses the output. */
898 for (def_rec = DF_INSN_DEFS (insn); *def_rec; def_rec++)
899 if (bitmap_bit_p (local_live, DF_REF_REGNO (*def_rec))
900 || bitmap_bit_p (au, DF_REF_REGNO (*def_rec)))
907 mark_insn (insn, true);
909 /* No matter if the instruction is needed or not, we remove
910 any regno in the defs from the live set. */
911 df_simulate_defs (insn, local_live);
913 /* On the other hand, we do not allow the dead uses to set
914 anything in local_live. */
915 if (marked_insn_p (insn))
916 df_simulate_uses (insn, local_live);
919 df_simulate_finalize_backwards (bb, local_live);
921 block_changed = !bitmap_equal_p (local_live, DF_LR_IN (bb));
923 bitmap_copy (DF_LR_IN (bb), local_live);
925 BITMAP_FREE (local_live);
926 return block_changed;
930 /* Perform fast DCE once initialization is done. If BYTE_LEVEL is
931 true, use the byte level dce, otherwise do it at the pseudo
935 fast_dce (bool byte_level)
937 int *postorder = df_get_postorder (DF_BACKWARD);
938 int n_blocks = df_get_n_blocks (DF_BACKWARD);
939 /* The set of blocks that have been seen on this iteration. */
940 bitmap processed = BITMAP_ALLOC (&dce_blocks_bitmap_obstack);
941 /* The set of blocks that need to have the out vectors reset because
942 the in of one of their successors has changed. */
943 bitmap redo_out = BITMAP_ALLOC (&dce_blocks_bitmap_obstack);
944 bitmap all_blocks = BITMAP_ALLOC (&dce_blocks_bitmap_obstack);
945 bool global_changed = true;
947 /* These regs are considered always live so if they end up dying
948 because of some def, we need to bring the back again. Calling
949 df_simulate_fixup_sets has the disadvantage of calling
950 bb_has_eh_pred once per insn, so we cache the information
952 bitmap au = df->regular_block_artificial_uses;
953 bitmap au_eh = df->eh_block_artificial_uses;
956 prescan_insns_for_dce (true);
958 for (i = 0; i < n_blocks; i++)
959 bitmap_set_bit (all_blocks, postorder[i]);
961 while (global_changed)
963 global_changed = false;
965 for (i = 0; i < n_blocks; i++)
967 int index = postorder[i];
968 basic_block bb = BASIC_BLOCK (index);
971 if (index < NUM_FIXED_BLOCKS)
973 bitmap_set_bit (processed, index);
979 = byte_dce_process_block (bb, bitmap_bit_p (redo_out, index),
980 bb_has_eh_pred (bb) ? au_eh : au);
983 = dce_process_block (bb, bitmap_bit_p (redo_out, index),
984 bb_has_eh_pred (bb) ? au_eh : au);
985 bitmap_set_bit (processed, index);
991 FOR_EACH_EDGE (e, ei, bb->preds)
992 if (bitmap_bit_p (processed, e->src->index))
993 /* Be tricky about when we need to iterate the
994 analysis. We only have redo the analysis if the
995 bitmaps change at the top of a block that is the
997 global_changed = true;
999 bitmap_set_bit (redo_out, e->src->index);
1005 /* Turn off the RUN_DCE flag to prevent recursive calls to
1007 int old_flag = df_clear_flags (DF_LR_RUN_DCE);
1009 /* So something was deleted that requires a redo. Do it on
1011 delete_unmarked_insns ();
1012 sbitmap_zero (marked);
1013 bitmap_clear (processed);
1014 bitmap_clear (redo_out);
1016 /* We do not need to rescan any instructions. We only need
1017 to redo the dataflow equations for the blocks that had a
1018 change at the top of the block. Then we need to redo the
1021 df_analyze_problem (df_byte_lr, all_blocks, postorder, n_blocks);
1023 df_analyze_problem (df_lr, all_blocks, postorder, n_blocks);
1025 if (old_flag & DF_LR_RUN_DCE)
1026 df_set_flags (DF_LR_RUN_DCE);
1028 prescan_insns_for_dce (true);
1032 delete_unmarked_insns ();
1034 BITMAP_FREE (processed);
1035 BITMAP_FREE (redo_out);
1036 BITMAP_FREE (all_blocks);
1040 /* Fast register level DCE. */
1043 rest_of_handle_fast_dce (void)
1052 /* Fast byte level DCE. */
1055 rest_of_handle_fast_byte_dce (void)
1057 df_byte_lr_add_problem ();
1065 /* This is an internal call that is used by the df live register
1066 problem to run fast dce as a side effect of creating the live
1067 information. The stack is organized so that the lr problem is run,
1068 this pass is run, which updates the live info and the df scanning
1069 info, and then returns to allow the rest of the problems to be run.
1071 This can be called by elsewhere but it will not update the bit
1072 vectors for any other problems than LR. */
1075 run_fast_df_dce (void)
1079 /* If dce is able to delete something, it has to happen
1080 immediately. Otherwise there will be problems handling the
1082 enum df_changeable_flags old_flags
1083 = df_clear_flags (DF_DEFER_INSN_RESCAN + DF_NO_INSN_RESCAN);
1085 df_in_progress = true;
1086 rest_of_handle_fast_dce ();
1087 df_in_progress = false;
1089 df_set_flags (old_flags);
1094 /* Run a fast DCE pass. */
1100 rest_of_handle_fast_dce ();
1105 gate_fast_dce (void)
1107 return optimize > 0 && flag_dce
1108 && dbg_cnt (dce_fast);
1111 struct rtl_opt_pass pass_fast_rtl_dce =
1116 gate_fast_dce, /* gate */
1117 rest_of_handle_fast_dce, /* execute */
1120 0, /* static_pass_number */
1122 0, /* properties_required */
1123 0, /* properties_provided */
1124 0, /* properties_destroyed */
1125 0, /* todo_flags_start */
1127 TODO_df_finish | TODO_verify_rtl_sharing |
1128 TODO_ggc_collect /* todo_flags_finish */
1132 struct rtl_opt_pass pass_fast_rtl_byte_dce =
1136 "byte-dce", /* name */
1137 gate_fast_dce, /* gate */
1138 rest_of_handle_fast_byte_dce, /* execute */
1141 0, /* static_pass_number */
1143 0, /* properties_required */
1144 0, /* properties_provided */
1145 0, /* properties_destroyed */
1146 0, /* todo_flags_start */
1148 TODO_df_finish | TODO_verify_rtl_sharing |
1149 TODO_ggc_collect /* todo_flags_finish */