[tree-ssa] empty statement cleanup
Richard Henderson
rth@twiddle.net
Sun Nov 16 11:26:00 GMT 2003
All empty statements were removed by remove_useless_stmts, and no new
empty statements are created by the optimizers. Thus there's no need
to check for them.
The remaining uses of IS_EMPTY_STMT, outside the gimplifiers and
remove_useless itself, are for default SSA definitions.
Bootstrapped and checked on i686-linux.
r~
* tree-cfg.c (last_and_only_stmt): New.
* tree-flow.h (last_and_only_stmt): Declare.
* tree-ssa-dom.c (thread_across_edge): Use it.
* tree-cfg.c (tree_block_forwards_to): Don't check for empty stmts.
(tree_forwarder_block_p): Likewise.
* tree-dfa.c (get_stmt_operands): Likewise.
* tree-ssa-ccp.c (set_rhs): Likewise.
* tree-ssa-dom.c (optimize_stmt): Likewise.
* tree-ssa.c (rewrite_stmt): Likewise.
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.216
diff -u -p -r1.1.4.216 tree-cfg.c
--- tree-cfg.c 16 Nov 2003 08:24:01 -0000 1.1.4.216
+++ tree-cfg.c 16 Nov 2003 10:55:42 -0000
@@ -1590,7 +1590,7 @@ tree_block_forwards_to (basic_block bb)
|| phi_nodes (bb->succ->dest))
return NULL;
- /* Walk past any labels or empty statements at the start of this block. */
+ /* Walk past any labels at the start of this block. */
bsi = bsi_start (bb);
while (1)
{
@@ -1598,7 +1598,7 @@ tree_block_forwards_to (basic_block bb)
if (bsi_end_p (bsi))
break;
stmt = bsi_stmt (bsi);
- if (IS_EMPTY_STMT (stmt) || TREE_CODE (stmt) == LABEL_EXPR)
+ if (TREE_CODE (stmt) == LABEL_EXPR)
bsi_next (&bsi);
else
break;
@@ -2329,6 +2329,38 @@ last_stmt_ptr (basic_block bb)
return !bsi_end_p (last) ? bsi_stmt_ptr (last) : NULL;
}
+/* Return the last statement of an otherwise empty block. Return NULL
+ if the block is totally empty, or if it contains more than one stmt. */
+
+tree
+last_and_only_stmt (basic_block bb)
+{
+ block_stmt_iterator i = bsi_last (bb);
+ tree last, prev;
+
+ if (bsi_end_p (i))
+ return NULL_TREE;
+
+ last = bsi_stmt (i);
+ bsi_prev (&i);
+ if (bsi_end_p (i))
+ return last;
+
+ /* Empty statements should no longer appear in the instruction stream.
+ Everything that might have appeared before should be deleted by
+ remove_useless_stmts, and the optimizers should just bsi_remove
+ instead of smashing with build_empty_stmt.
+
+ Thus the only thing that should appear here in a block containing
+ one executable statement is a label. */
+
+ prev = bsi_stmt (i);
+ if (TREE_CODE (prev) == LABEL_EXPR)
+ return last;
+ else
+ return NULL_TREE;
+}
+
/* Insert statement T into basic block BB. */
void
@@ -3146,10 +3178,6 @@ tree_forwarder_block_p (basic_block bb)
{
tree stmt = bsi_stmt (bsi);
- /* Ignore empty statements. */
- if (IS_EMPTY_STMT (stmt))
- continue;
-
switch (TREE_CODE (stmt))
{
case LABEL_EXPR:
Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.176
diff -u -p -r1.1.4.176 tree-dfa.c
--- tree-dfa.c 14 Nov 2003 08:16:56 -0000 1.1.4.176
+++ tree-dfa.c 16 Nov 2003 10:55:44 -0000
@@ -295,8 +295,7 @@ get_stmt_operands (tree stmt)
add_use. This default will handle statements like empty statements,
CALL_EXPRs or VA_ARG_EXPRs that may appear on the RHS of a statement
or as statements themselves. */
- if (!IS_EMPTY_STMT (stmt))
- get_expr_operands (stmt, &stmt, opf_none, prev_vops);
+ get_expr_operands (stmt, &stmt, opf_none, prev_vops);
break;
}
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.150
diff -u -p -r1.1.4.150 tree-flow.h
--- tree-flow.h 16 Nov 2003 08:24:02 -0000 1.1.4.150
+++ tree-flow.h 16 Nov 2003 10:55:44 -0000
@@ -433,6 +433,7 @@ extern void remove_phi_nodes_and_edges_f
extern tree first_stmt (basic_block);
extern tree last_stmt (basic_block);
extern tree *last_stmt_ptr (basic_block);
+extern tree last_and_only_stmt (basic_block);
extern edge find_taken_edge (basic_block, tree);
extern void remove_useless_stmts (tree *);
extern void cfg_remove_useless_stmts (void);
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.110
diff -u -p -r1.1.2.110 tree-ssa-ccp.c
--- tree-ssa-ccp.c 13 Nov 2003 02:38:01 -0000 1.1.2.110
+++ tree-ssa-ccp.c 16 Nov 2003 10:55:45 -0000
@@ -1750,15 +1750,7 @@ set_rhs (tree *stmt_p, tree expr)
else
{
stmt_ann_t ann = stmt_ann (stmt);
- if (TREE_SIDE_EFFECTS (expr))
- *stmt_p = expr;
- else
- {
- /* If the expression is not a statement with side-effects, replace
- the statement with a new empty statement. */
- *stmt_p = build_empty_stmt ();
- }
-
+ *stmt_p = expr;
(*stmt_p)->common.ann = (tree_ann) ann;
}
}
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.77
diff -u -p -r1.1.2.77 tree-ssa-dom.c
--- tree-ssa-dom.c 11 Nov 2003 18:04:46 -0000 1.1.2.77
+++ tree-ssa-dom.c 16 Nov 2003 10:55:48 -0000
@@ -494,15 +494,7 @@ thread_across_edge (edge e, varray_type
Only thread through a successor with PHI nodes if explicitly asked to. */
if (thread_through_phis || ! phi_nodes (e->dest))
{
- block_stmt_iterator bsi = bsi_start (e->dest);
- tree stmt = NULL;
-
- /* Walk past any empty statements and labels. */
- while (! bsi_end_p (bsi)
- && (stmt = bsi_stmt (bsi))
- && (IS_EMPTY_STMT (stmt)
- || TREE_CODE (stmt) == LABEL_EXPR))
- bsi_next (&bsi);
+ tree stmt = last_and_only_stmt (e->dest);
/* If we stopped at a COND_EXPR, then see if we know which arm will
be taken. */
@@ -2077,8 +2069,6 @@ optimize_stmt (block_stmt_iterator si, v
bool may_have_exposed_new_symbols = false;
stmt = bsi_stmt (si);
- if (IS_EMPTY_STMT (stmt))
- return false;
get_stmt_operands (stmt);
ann = stmt_ann (stmt);
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.152
diff -u -p -r1.1.4.152 tree-ssa.c
--- tree-ssa.c 14 Nov 2003 16:50:02 -0000 1.1.4.152
+++ tree-ssa.c 16 Nov 2003 10:55:50 -0000
@@ -2706,9 +2706,6 @@ rewrite_stmt (block_stmt_iterator si, va
varray_type defs, uses, vuses, vdefs;
stmt = bsi_stmt (si);
- if (IS_EMPTY_STMT (stmt))
- return;
-
ann = stmt_ann (stmt);
ssa_stats.num_stmts++;
More information about the Gcc-patches
mailing list