This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Re: COND_EXPR lowering patch
- From: Andrew MacLeod <amacleod at redhat dot com>
- To: Andrew MacLeod <amacleod at redhat dot com>
- Cc: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>, gcc mailing list <gcc at gcc dot gnu dot org>, Jeff Law <law at redhat dot com>
- Date: 25 Aug 2003 10:07:20 -0400
- Subject: Re: [tree-ssa] Re: COND_EXPR lowering patch
- References: <20030823175250.GA21952@atrey.karlin.mff.cuni.cz> <1061819890.2413.39.camel@p4>
On Mon, 2003-08-25 at 09:58, Andrew MacLeod wrote:
> On Sat, 2003-08-23 at 13:52, Zdenek Dvorak wrote:
> I'm running this through the latest source code this morning, and I will
> check it in if there are no complaints and it still bootstraps et al. I
> think it'll give you something you can then move forward with.
Whoops :-)
* tree-flow.h (tree_ssa_dce): Change prototype.
* tree-optimize.c (optimize_function_tree): Add parameter to call.
* tree-ssa-dce.c (remove_conditionals): New file static.
(mark_tree_necessary): Only mark parents if removing conditionals.
(stmt_useful_p): When not removing conditional, all control flow
stmt's are necessary.
(process_worklist): When not removing conditionals, don't follow
control flow chains.
(remove_dead_stmt): Abort if removing flow when it's disabled.
(tree_ssa_dce): Add flag to disable removing flow stmt's.
(remove_conditional): Abort if flow shouldn't be removed..
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.101
diff -c -p -r1.1.4.101 tree-flow.h
*** tree-flow.h 8 Aug 2003 00:27:10 -0000 1.1.4.101
--- tree-flow.h 25 Aug 2003 13:36:23 -0000
*************** extern void dump_dominator_optimization_
*** 484,490 ****
extern void debug_dominator_optimization_stats (void);
/* In tree-ssa-dce.c */
! void tree_ssa_dce (tree);
/* In tree-ssa-copyprop.c */
--- 484,490 ----
extern void debug_dominator_optimization_stats (void);
/* In tree-ssa-dce.c */
! void tree_ssa_dce (tree, bool);
/* In tree-ssa-copyprop.c */
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-optimize.c,v
retrieving revision 1.1.4.43
diff -c -p -r1.1.4.43 tree-optimize.c
*** tree-optimize.c 8 Aug 2003 00:27:10 -0000 1.1.4.43
--- tree-optimize.c 25 Aug 2003 13:36:23 -0000
*************** optimize_function_tree (tree fndecl)
*** 86,92 ****
into must-alias relations. If DCE eliminated all the pointer
assignments that were taking the address of a local variable X,
we can now rename X as a non-aliased local. */
! tree_ssa_dce (fndecl);
if (flag_tree_dom && flag_tree_must_alias)
tree_compute_must_alias (fndecl);
}
--- 86,92 ----
into must-alias relations. If DCE eliminated all the pointer
assignments that were taking the address of a local variable X,
we can now rename X as a non-aliased local. */
! tree_ssa_dce (fndecl, false);
if (flag_tree_dom && flag_tree_must_alias)
tree_compute_must_alias (fndecl);
}
*************** optimize_function_tree (tree fndecl)
*** 101,107 ****
tree_ssa_copyprop (fndecl);
if (flag_tree_dce)
! tree_ssa_dce (fndecl);
/* Rewrite the function out of SSA form. */
rewrite_out_of_ssa (fndecl);
--- 101,107 ----
tree_ssa_copyprop (fndecl);
if (flag_tree_dce)
! tree_ssa_dce (fndecl, true);
/* Rewrite the function out of SSA form. */
rewrite_out_of_ssa (fndecl);
Index: tree-ssa-dce.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dce.c,v
retrieving revision 1.1.2.52
diff -c -p -r1.1.2.52 tree-ssa-dce.c
*** tree-ssa-dce.c 8 Aug 2003 00:27:10 -0000 1.1.2.52
--- tree-ssa-dce.c 25 Aug 2003 13:36:23 -0000
*************** static void remove_dead_stmt (block_stmt
*** 96,101 ****
--- 96,102 ----
static void remove_dead_phis (basic_block);
static void remove_conditional (basic_block);
+ static bool remove_conditionals = false;
/* Is a tree necessary? */
*************** mark_tree_necessary (tree t)
*** 138,144 ****
static void
mark_necessary (tree t)
{
! if (mark_tree_necessary (t))
{
/* Mark control parent statements as necessary. */
tree parent = parent_stmt (t);
--- 139,148 ----
static void
mark_necessary (tree t)
{
! /* If we aren't removing conditionals, all the control flow stms are
! will automatically be marked as necessary. */
!
! if (mark_tree_necessary (t) && remove_conditionals)
{
/* Mark control parent statements as necessary. */
tree parent = parent_stmt (t);
*************** stmt_useful_p (tree stmt)
*** 262,267 ****
--- 266,275 ----
|| (TREE_CODE (stmt) == CATCH_EXPR))
return true;
+ if (!remove_conditionals
+ && (is_ctrl_stmt (stmt) || is_ctrl_altering_stmt (stmt)))
+ return true;
+
/* GOTO_EXPR nodes to nonlocal labels need to be kept (This fixes
gcc.c-torture/execute/920501-7.c and others that have nested functions
with nonlocal gotos). FIXME: If we were doing IPA we could determine
*************** process_worklist (void)
*** 308,317 ****
basic_block bb;
tree i, j;
edge e;
! bitmap cond_checked, goto_checked;
! cond_checked = BITMAP_XMALLOC ();
! goto_checked = BITMAP_XMALLOC ();
while (VARRAY_ACTIVE_SIZE (worklist) > 0)
{
--- 316,329 ----
basic_block bb;
tree i, j;
edge e;
! bitmap cond_checked = (bitmap)NULL;
! bitmap goto_checked = (bitmap)NULL;
! if (remove_conditionals)
! {
! cond_checked = BITMAP_XMALLOC ();
! goto_checked = BITMAP_XMALLOC ();
! }
while (VARRAY_ACTIVE_SIZE (worklist) > 0)
{
*************** process_worklist (void)
*** 328,336 ****
/* Find any predecessor which 'goto's this block, and mark the goto
as necessary since it is control flow. A block's predecessors only
! need to be checked once. */
bb = bb_for_stmt (i);
! if (bb && !bitmap_bit_p (goto_checked, bb->index))
{
bitmap_set_bit (goto_checked, bb->index);
for (e = bb->pred; e != NULL; e = e->pred_next)
--- 340,350 ----
/* Find any predecessor which 'goto's this block, and mark the goto
as necessary since it is control flow. A block's predecessors only
! need to be checked once. If remove_conditionals is false, all
! control flow stmts are already marked as necessary. */
!
bb = bb_for_stmt (i);
! if (remove_conditionals && bb && !bitmap_bit_p (goto_checked, bb->index))
{
bitmap_set_bit (goto_checked, bb->index);
for (e = bb->pred; e != NULL; e = e->pred_next)
*************** process_worklist (void)
*** 363,387 ****
as necessary. Copies may be needed on an edge later.
This only needs to be done once per block. */
! k = bb_for_stmt (i)->index;
! if (!bitmap_bit_p (cond_checked, k))
{
! bitmap_set_bit (cond_checked, k);
! for (e = bb->pred; e; e = e->pred_next)
{
! basic_block pred, par;
! pred = e->src;
! if (pred != ENTRY_BLOCK_PTR)
{
! par = parent_block (pred);
! if (par)
{
! tree last;
! last = last_stmt (par);
! if (last && (TREE_CODE (last) == COND_EXPR
! || TREE_CODE (last) == SWITCH_EXPR))
{
! mark_necessary (last);
}
}
}
--- 377,404 ----
as necessary. Copies may be needed on an edge later.
This only needs to be done once per block. */
! if (remove_conditionals)
{
! k = bb_for_stmt (i)->index;
! if (!bitmap_bit_p (cond_checked, k))
{
! bitmap_set_bit (cond_checked, k);
! for (e = bb->pred; e; e = e->pred_next)
{
! basic_block pred, par;
! pred = e->src;
! if (pred != ENTRY_BLOCK_PTR)
{
! par = parent_block (pred);
! if (par)
{
! tree last;
! last = last_stmt (par);
! if (last && (TREE_CODE (last) == COND_EXPR
! || TREE_CODE (last) == SWITCH_EXPR))
! {
! mark_necessary (last);
! }
}
}
}
*************** process_worklist (void)
*** 423,430 ****
}
}
}
! BITMAP_XFREE (cond_checked);
! BITMAP_XFREE (goto_checked);
}
--- 440,451 ----
}
}
}
!
! if (remove_conditionals)
! {
! BITMAP_XFREE (cond_checked);
! BITMAP_XFREE (goto_checked);
! }
}
*************** remove_dead_stmt (block_stmt_iterator *i
*** 538,543 ****
--- 559,570 ----
if (TREE_CODE (t) == COND_EXPR || TREE_CODE (t) == SWITCH_EXPR)
{
tree parent = parent_stmt (t);
+
+ #ifdef ENABLE_CHECKING
+ if (!remove_conditional)
+ abort ();
+ #endif
+
if (parent == NULL_TREE || necessary_p (parent))
remove_conditional (bb);
}
*************** remove_dead_stmt (block_stmt_iterator *i
*** 548,554 ****
/* Main routine to eliminate dead code. */
void
! tree_ssa_dce (tree fndecl)
{
tree fnbody;
--- 575,581 ----
/* Main routine to eliminate dead code. */
void
! tree_ssa_dce (tree fndecl, bool remove_cond)
{
tree fnbody;
*************** tree_ssa_dce (tree fndecl)
*** 567,572 ****
--- 594,601 ----
/* Initialize dump_file for debugging dumps. */
dump_file = dump_begin (TDI_dce, &dump_flags);
+ remove_conditionals = remove_cond;
+
find_useful_stmts ();
if (dump_file && (dump_flags & TDF_DETAILS))
*************** remove_conditional (basic_block bb)
*** 601,606 ****
--- 630,640 ----
{
basic_block pdom_bb;
edge e;
+
+ #ifdef ENABLE_CHECKING
+ if (!remove_conditional)
+ abort ();
+ #endif
/* Calculate dominance info, if it hasn't been computed yet. */
if (pdom_info == NULL)