This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to while/loop conditions
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 17 Aug 2002 02:16:23 +0100
- Subject: C++ PATCH to while/loop conditions
This patch completes moving SCOPE_STMTs out of conditions in C++ statements
by moving evaluation of complex loop conditions into the loop body. This
is basically the same transformation as is done by maybe_fixup_loop_cond in
the tree-ssa branch, but done at build time instead.
I believe this does away with the only reason for C/C++ scopes to be
represented by begin/end pairs rather than containers, though I haven't
actually checked yet.
Tested i686-pc-linux-gnu, applied to trunk.
2002-08-15 Jason Merrill <jason@redhat.com>
* semantics.c (finish_then_clause): Remove redundant assignment.
(finish_if_stmt, begin_switch_stmt, finish_switch_stmt): Move the
extra binding level outside the if/switch statement.
(finish_while_cond, finish_for_cond): Rewrite complex condition
into the loop body.
*** semantics.c.~1~ Mon Aug 12 19:48:30 2002
--- semantics.c Fri Aug 16 10:40:09 2002
*************** finish_then_clause (if_stmt)
*** 266,272 ****
tree if_stmt;
{
RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
- last_tree = if_stmt;
return if_stmt;
}
--- 266,271 ----
*************** finish_else_clause (if_stmt)
*** 292,312 ****
void
finish_if_stmt ()
{
- do_poplevel ();
finish_stmt ();
! }
!
! void
! clear_out_block ()
! {
! /* If COND wasn't a declaration, clear out the
! block we made for it and start a new one here so the
! optimization in expand_end_loop will work. */
! if (getdecls () == NULL_TREE)
! {
! do_poplevel ();
! do_pushlevel ();
! }
}
/* Begin a while-statement. Returns a newly created WHILE_STMT if
--- 291,298 ----
void
finish_if_stmt ()
{
finish_stmt ();
! do_poplevel ();
}
/* Begin a while-statement. Returns a newly created WHILE_STMT if
*************** finish_while_stmt_cond (cond, while_stmt
*** 331,338 ****
tree while_stmt;
{
cond = maybe_convert_cond (cond);
! FINISH_COND (cond, while_stmt, WHILE_COND (while_stmt));
! clear_out_block ();
}
/* Finish a while-statement, which may be given by WHILE_STMT. */
--- 317,342 ----
tree while_stmt;
{
cond = maybe_convert_cond (cond);
! if (getdecls () == NULL_TREE)
! /* It was a simple condition; install it. */
! WHILE_COND (while_stmt) = cond;
! else
! {
! /* If there was a declaration in the condition, we can't leave it
! there; transform
! while (A x = 42) { }
! to
! while (true) { A x = 42; if (!x) break; } */
! tree if_stmt;
! WHILE_COND (while_stmt) = boolean_true_node;
!
! if_stmt = begin_if_stmt ();
! cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0);
! finish_if_stmt_cond (cond, if_stmt);
! finish_break_stmt ();
! finish_then_clause (if_stmt);
! finish_if_stmt ();
! }
}
/* Finish a while-statement, which may be given by WHILE_STMT. */
*************** finish_for_cond (cond, for_stmt)
*** 448,455 ****
tree for_stmt;
{
cond = maybe_convert_cond (cond);
! FINISH_COND (cond, for_stmt, FOR_COND (for_stmt));
! clear_out_block ();
}
/* Finish the increment-EXPRESSION in a for-statement, which may be
--- 452,477 ----
tree for_stmt;
{
cond = maybe_convert_cond (cond);
! if (getdecls () == NULL_TREE)
! /* It was a simple condition; install it. */
! FOR_COND (for_stmt) = cond;
! else
! {
! /* If there was a declaration in the condition, we can't leave it
! there; transform
! for (; A x = 42;) { }
! to
! for (;;) { A x = 42; if (!x) break; } */
! tree if_stmt;
! FOR_COND (for_stmt) = NULL_TREE;
!
! if_stmt = begin_if_stmt ();
! cond = build_unary_op (TRUTH_NOT_EXPR, cond, 0);
! finish_if_stmt_cond (cond, if_stmt);
! finish_break_stmt ();
! finish_then_clause (if_stmt);
! finish_if_stmt ();
! }
}
/* Finish the increment-EXPRESSION in a for-statement, which may be
*************** tree
*** 502,510 ****
begin_switch_stmt ()
{
tree r;
r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
add_stmt (r);
- do_pushlevel ();
return r;
}
--- 524,532 ----
begin_switch_stmt ()
{
tree r;
+ do_pushlevel ();
r = build_stmt (SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
add_stmt (r);
return r;
}
*************** finish_switch_stmt (switch_stmt)
*** 560,567 ****
{
RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
pop_switch ();
- do_poplevel ();
finish_stmt ();
}
/* Generate the RTL for T, which is a TRY_BLOCK. */
--- 582,589 ----
{
RECHAIN_STMTS (switch_stmt, SWITCH_BODY (switch_stmt));
pop_switch ();
finish_stmt ();
+ do_poplevel ();
}
/* Generate the RTL for T, which is a TRY_BLOCK. */