This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
dead code removal in flow.c cleanup
- From: Jan Hubicka <jh at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org, rth at cygnus dot com
- Date: Sun, 3 Mar 2002 19:21:57 +0100
- Subject: dead code removal in flow.c cleanup
Hi,
this patch cleans up the code removal in flow.c, adds statistics and makes
functions to return number of insns removed I use in followup patch.
Bootstrapped/regtested i386
Sun Mar 3 18:50:48 CET 2002 Jan Hubicka <jh@suse.cz>
* basic-block.h (update_life_info, update_life_info_in_dirty_blocks,
delete_noop_moves): Return indeger.
* flow.c (ndead): New variable.
(propagate_block_delete_insn): Use delete_insn_and_edges; remove
BB argument; update callers.
(propagate_block_delete_libcall): Use delete_insn_chain_and_edges.
(life_analysis): Do not call purge_all_dead_edges.
(update_life_info): Return number of deleted insns; print statistics.
(update_life_info_in_dirty_blocks): likewise.
(delete_noop_moves): Use delete_insn_and_edges; print statistics;
return number of insns deleted.
*** basic-block.h.old Sun Mar 3 16:32:30 2002
--- basic-block.h Sun Mar 3 16:37:13 2002
*************** enum update_life_extent
*** 588,596 ****
#define LOOP_ALL 31 /* All of the above */
extern void life_analysis PARAMS ((rtx, FILE *, int));
! extern void update_life_info PARAMS ((sbitmap, enum update_life_extent,
int));
! extern void update_life_info_in_dirty_blocks PARAMS ((enum update_life_extent,
int));
extern int count_or_remove_death_notes PARAMS ((sbitmap, int));
extern int propagate_block PARAMS ((basic_block, regset, regset, regset,
--- 588,596 ----
#define LOOP_ALL 31 /* All of the above */
extern void life_analysis PARAMS ((rtx, FILE *, int));
! extern int update_life_info PARAMS ((sbitmap, enum update_life_extent,
int));
! extern int update_life_info_in_dirty_blocks PARAMS ((enum update_life_extent,
int));
extern int count_or_remove_death_notes PARAMS ((sbitmap, int));
extern int propagate_block PARAMS ((basic_block, regset, regset, regset,
*************** extern void allocate_bb_life_data PARAMS
*** 636,642 ****
extern void expunge_block PARAMS ((basic_block));
extern basic_block alloc_block PARAMS ((void));
extern void find_unreachable_blocks PARAMS ((void));
! extern void delete_noop_moves PARAMS ((rtx));
extern basic_block redirect_edge_and_branch_force PARAMS ((edge, basic_block));
extern basic_block force_nonfallthru PARAMS ((edge));
extern bool redirect_edge_and_branch PARAMS ((edge, basic_block));
--- 636,642 ----
extern void expunge_block PARAMS ((basic_block));
extern basic_block alloc_block PARAMS ((void));
extern void find_unreachable_blocks PARAMS ((void));
! extern int delete_noop_moves PARAMS ((rtx));
extern basic_block redirect_edge_and_branch_force PARAMS ((edge, basic_block));
extern basic_block force_nonfallthru PARAMS ((edge));
extern bool redirect_edge_and_branch PARAMS ((edge, basic_block));
*** flow.c.old Sun Mar 3 16:30:39 2002
--- flow.c Sun Mar 3 19:04:44 2002
*************** struct propagate_block_info
*** 276,281 ****
--- 276,284 ----
int flags;
};
+ /* Number of dead insns removed. */
+ static int ndead;
+
/* Maximum length of pbi->mem_set_list before we start dropping
new elements on the floor. */
#define MAX_MEM_SET_LIST_LEN 100
*************** static void mark_reg PARAMS ((rtx, voi
*** 290,296 ****
static void mark_regs_live_at_end PARAMS ((regset));
static int set_phi_alternative_reg PARAMS ((rtx, int, int, void *));
static void calculate_global_regs_live PARAMS ((sbitmap, sbitmap, int));
! static void propagate_block_delete_insn PARAMS ((basic_block, rtx));
static rtx propagate_block_delete_libcall PARAMS ((rtx, rtx));
static int insn_dead_p PARAMS ((struct propagate_block_info *,
rtx, int, rtx));
--- 293,299 ----
static void mark_regs_live_at_end PARAMS ((regset));
static int set_phi_alternative_reg PARAMS ((rtx, int, int, void *));
static void calculate_global_regs_live PARAMS ((sbitmap, sbitmap, int));
! static void propagate_block_delete_insn PARAMS ((rtx));
static rtx propagate_block_delete_libcall PARAMS ((rtx, rtx));
static int insn_dead_p PARAMS ((struct propagate_block_info *,
rtx, int, rtx));
*************** life_analysis (f, file, flags)
*** 448,454 ****
/* Always remove no-op moves. Do this before other processing so
that we don't have to keep re-scanning them. */
delete_noop_moves (f);
- purge_all_dead_edges (false);
/* Some targets can emit simpler epilogues if they know that sp was
not ever modified during the function. After reload, of course,
--- 451,456 ----
*************** verify_local_live_at_start (new_live_at_
*** 623,629 ****
Including PROP_REG_INFO does not properly refresh regs_ever_live
unless the caller resets it to zero. */
! void
update_life_info (blocks, extent, prop_flags)
sbitmap blocks;
enum update_life_extent extent;
--- 625,631 ----
Including PROP_REG_INFO does not properly refresh regs_ever_live
unless the caller resets it to zero. */
! int
update_life_info (blocks, extent, prop_flags)
sbitmap blocks;
enum update_life_extent extent;
*************** update_life_info (blocks, extent, prop_f
*** 634,639 ****
--- 636,642 ----
int i;
tmp = INITIALIZE_REG_SET (tmp_head);
+ ndead = 0;
timevar_push ((extent == UPDATE_LIFE_LOCAL || blocks)
? TV_LIFE_UPDATE : TV_LIFE);
*************** update_life_info (blocks, extent, prop_f
*** 743,753 ****
}
timevar_pop ((extent == UPDATE_LIFE_LOCAL || blocks)
? TV_LIFE_UPDATE : TV_LIFE);
}
/* Update life information in all blocks where BB_DIRTY is set. */
! void
update_life_info_in_dirty_blocks (extent, prop_flags)
enum update_life_extent extent;
int prop_flags;
--- 746,759 ----
}
timevar_pop ((extent == UPDATE_LIFE_LOCAL || blocks)
? TV_LIFE_UPDATE : TV_LIFE);
+ if (ndead && rtl_dump_file)
+ fprintf (rtl_dump_file, "deleted %i dead insns\n", ndead);
+ return ndead;
}
/* Update life information in all blocks where BB_DIRTY is set. */
! int
update_life_info_in_dirty_blocks (extent, prop_flags)
enum update_life_extent extent;
int prop_flags;
*************** update_life_info_in_dirty_blocks (extent
*** 755,760 ****
--- 761,767 ----
sbitmap update_life_blocks = sbitmap_alloc (n_basic_blocks);
int block_num;
int n = 0;
+ int ndead;
sbitmap_zero (update_life_blocks);
for (block_num = 0; block_num < n_basic_blocks; block_num++)
*************** update_life_info_in_dirty_blocks (extent
*** 765,773 ****
}
if (n)
! update_life_info (update_life_blocks, extent, prop_flags);
sbitmap_free (update_life_blocks);
}
/* Free the variables allocated by find_basic_blocks.
--- 772,781 ----
}
if (n)
! ndead = update_life_info (update_life_blocks, extent, prop_flags);
sbitmap_free (update_life_blocks);
+ return ndead;
}
/* Free the variables allocated by find_basic_blocks.
*************** free_basic_block_vars (keep_head_end_p)
*** 796,808 ****
/* Delete any insns that copy a register to itself. */
! void
delete_noop_moves (f)
rtx f ATTRIBUTE_UNUSED;
{
int i;
rtx insn, next;
basic_block bb;
for (i = 0; i < n_basic_blocks; i++)
{
--- 804,817 ----
/* Delete any insns that copy a register to itself. */
! int
delete_noop_moves (f)
rtx f ATTRIBUTE_UNUSED;
{
int i;
rtx insn, next;
basic_block bb;
+ int nnoops = 0;
for (i = 0; i < n_basic_blocks; i++)
{
*************** delete_noop_moves (f)
*** 829,842 ****
XEXP (retval_note, 0) = new_libcall_insn;
}
! /* Do not call delete_insn here since that may change
! the basic block boundaries which upsets some callers. */
! PUT_CODE (insn, NOTE);
! NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
! NOTE_SOURCE_FILE (insn) = 0;
}
}
}
}
/* Delete any jump tables never referenced. We can't delete them at the
--- 838,851 ----
XEXP (retval_note, 0) = new_libcall_insn;
}
! delete_insn_and_edges (insn);
! nnoops++;
}
}
}
+ if (nnoops && rtl_dump_file)
+ fprintf (rtl_dump_file, "deleted %i noop moves", nnoops);
+ return nnoops;
}
/* Delete any jump tables never referenced. We can't delete them at the
*************** allocate_reg_life_data ()
*** 1483,1494 ****
/* Delete dead instructions for propagate_block. */
static void
! propagate_block_delete_insn (bb, insn)
! basic_block bb;
rtx insn;
{
rtx inote = find_reg_note (insn, REG_LABEL, NULL_RTX);
! bool purge = false;
/* If the insn referred to a label, and that label was attached to
an ADDR_VEC, it's safe to delete the ADDR_VEC. In fact, it's
--- 1492,1502 ----
/* Delete dead instructions for propagate_block. */
static void
! propagate_block_delete_insn (insn)
rtx insn;
{
rtx inote = find_reg_note (insn, REG_LABEL, NULL_RTX);
! basic_block bb = BLOCK_FOR_INSN (insn);
/* If the insn referred to a label, and that label was attached to
an ADDR_VEC, it's safe to delete the ADDR_VEC. In fact, it's
*************** propagate_block_delete_insn (bb, insn)
*** 1526,1540 ****
for (i = 0; i < len; i++)
LABEL_NUSES (XEXP (XVECEXP (pat, diff_vec_p, i), 0))--;
! delete_insn (next);
}
}
! if (bb->end == insn)
! purge = true;
! delete_insn (insn);
! if (purge)
! purge_dead_edges (bb);
}
/* Delete dead libcalls for propagate_block. Return the insn
--- 1534,1546 ----
for (i = 0; i < len; i++)
LABEL_NUSES (XEXP (XVECEXP (pat, diff_vec_p, i), 0))--;
! delete_insn_and_edges (next);
! ndead++;
}
}
! delete_insn_and_edges (insn);
! ndead++;
}
/* Delete dead libcalls for propagate_block. Return the insn
*************** propagate_block_delete_libcall ( insn, n
*** 1547,1553 ****
rtx first = XEXP (note, 0);
rtx before = PREV_INSN (first);
! delete_insn_chain (first, insn);
return before;
}
--- 1553,1560 ----
rtx first = XEXP (note, 0);
rtx before = PREV_INSN (first);
! delete_insn_chain_and_edges (first, insn);
! ndead++;
return before;
}
*************** propagate_one_insn (pbi, insn)
*** 1608,1614 ****
if (libcall_is_dead)
prev = propagate_block_delete_libcall ( insn, note);
else
! propagate_block_delete_insn (pbi->bb, insn);
return prev;
}
--- 1615,1621 ----
if (libcall_is_dead)
prev = propagate_block_delete_libcall ( insn, note);
else
! propagate_block_delete_insn (insn);
return prev;
}
*************** try_pre_increment_1 (pbi, insn)
*** 3940,3946 ****
{
/* We have found a suitable auto-increment and already changed
insn Y to do it. So flush this increment instruction. */
! propagate_block_delete_insn (pbi->bb, insn);
/* Count a reference to this reg for the increment insn we are
deleting. When a reg is incremented, spilling it is worse,
--- 3947,3953 ----
{
/* We have found a suitable auto-increment and already changed
insn Y to do it. So flush this increment instruction. */
! propagate_block_delete_insn (insn);
/* Count a reference to this reg for the increment insn we are
deleting. When a reg is incremented, spilling it is worse,