This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] gimplify LABELED_BLOCK_EXPR and EXIT_BLOCK_EXPR
- From: Jeff Sturm <jsturm at one-point dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 18 Jun 2003 18:20:25 -0400 (EDT)
- Subject: Re: [tree-ssa] gimplify LABELED_BLOCK_EXPR and EXIT_BLOCK_EXPR
On Wed, 18 Jun 2003, Jason Merrill wrote:
> In general, if you're going to replace one node with another (or several
> others) I'd just do that directly and let gimplify_expr handle reducing the
> new form further. So don't pass in pre_p, but replace *expr_p with the
> body and the new LABEL_EXPR.
With a COMPOUND_EXPR, you mean?
2003-06-18 Jeff Sturm <jsturm@one-point.com>
* gimplify.c (gimplify_expr): Handle LABELED_BLOCK_EXPR
and EXIT_BLOCK_EXPR.
(gimplify_labeled_block_expr): New function.
(gimplify_exit_block_expr): New function.
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.57
diff -c -p -r1.1.2.57 gimplify.c
*** gimplify.c 13 Jun 2003 19:00:17 -0000 1.1.2.57
--- gimplify.c 18 Jun 2003 22:14:16 -0000
*************** static void gimplify_loop_expr PARAMS (
*** 80,85 ****
--- 80,87 ----
static void gimplify_exit_expr PARAMS ((tree *));
static void gimplify_switch_expr (tree *, tree *);
static void gimple_add_case_label (tree);
+ static void gimplify_labeled_block_expr (tree *);
+ static void gimplify_exit_block_expr (tree *);
static hashval_t gimple_tree_hash (const void *);
static int gimple_tree_eq (const void *, const void *);
static tree lookup_tmp_var (tree, bool);
*************** gimplify_expr (expr_p, pre_p, post_p, gi
*** 532,539 ****
break;
case LABELED_BLOCK_EXPR:
! gimplify_stmt (&LABELED_BLOCK_BODY (*expr_p));
! recalculate_side_effects (*expr_p);
break;
case EXIT_EXPR:
--- 534,544 ----
break;
case LABELED_BLOCK_EXPR:
! gimplify_labeled_block_expr (expr_p);
! break;
!
! case EXIT_BLOCK_EXPR:
! gimplify_exit_block_expr (expr_p);
break;
case EXIT_EXPR:
*************** gimple_add_case_label (tree expr)
*** 1009,1014 ****
--- 1014,1055 ----
{
if (gimplify_ctxp->case_labels)
VARRAY_PUSH_TREE (gimplify_ctxp->case_labels, CASE_LABEL (expr));
+ }
+
+ /* Gimplify a LABELED_BLOCK_EXPR into a LABEL_EXPR following
+ a (possibly empty) body. */
+
+ static void
+ gimplify_labeled_block_expr (tree *expr_p)
+ {
+ tree body = LABELED_BLOCK_BODY (*expr_p);
+ tree label = LABELED_BLOCK_LABEL (*expr_p);
+ tree t;
+
+ DECL_CONTEXT (label) = current_function_decl;
+ t = build (LABEL_EXPR, void_type_node, label);
+ if (body != NULL_TREE)
+ t = build (COMPOUND_EXPR, void_type_node, body, t);
+ *expr_p = t;
+ }
+
+ /* Gimplify a EXIT_BLOCK_EXPR into a GOTO_EXPR. */
+
+ static void
+ gimplify_exit_block_expr (tree *expr_p)
+ {
+ tree labeled_block = TREE_OPERAND (*expr_p, 0);
+ tree label;
+
+ /* First operand must be a LABELED_BLOCK_EXPR, which should
+ already be lowered (or partially lowered) when we get here. */
+ #if defined ENABLE_CHECKING
+ if (TREE_CODE (labeled_block) != LABELED_BLOCK_EXPR)
+ abort ();
+ #endif
+
+ label = LABELED_BLOCK_LABEL (labeled_block);
+ *expr_p = build1 (GOTO_EXPR, void_type_node, label);
}
/* Build a GOTO to the LABEL_DECL pointed to by LABEL_P, building it first