[tuples] handle TRY_*_EXPR and LOOP_EXPRs
Aldy Hernandez
aldyh@redhat.com
Wed Jul 18 19:10:00 GMT 2007
This patch tuplefies TRY_*_EXPR nodes, and LOOP_EXPR nodes.
Furthermore, I got tired of creating empty sequences just so I can pass
them to a constructor. Now all gimple_build_* functions handle a NULL
passed as a sequence by leaving the cleared body as is, thus
initializing it to an empty sequence.
I've also removed gimple_push which Diego hated. We'll come up with
something better for the GSI iterators.
Aldy
* gimplify.c (gimplify_and_add): Remove unecessary temporary sequence.
Remove fixme. Add comment.
(gimplify_loop_expr): Tuplefy.
(gimplify_bind_expr): Streamline GIMPLE_TRY_FINALLY tuple.
(gimplify_expr): Tuplefy TRY_*_EXPR cases.
* gimple.c: Fix some spacing.
(gimple_build_try, gimple_omp_build_*): Handle empty sequences.
(gimple_push): Remove.
* gimple.h (gimple_push): Remove.
Index: gimplify.c
===================================================================
--- gimplify.c (revision 126722)
+++ gimplify.c (working copy)
@@ -333,17 +333,14 @@ append_to_statement_list_force (tree t,
append_to_statement_list_1 (t, list_p);
}
-/* FIXME tuples: This function is obsolete. Use gimplify_stmt instead. */
/* Both gimplify the statement T and append it to SEQ. */
+/* This function behaves exactly as gimplify_stmt, but you don't have to pass
+ T as a reference. */
void
gimplify_and_add (tree t, gimple_seq seq)
{
- struct gimple_sequence tseq;
-
- gimple_seq_init (&tseq);
- gimplify_stmt (&t, &tseq);
- gimple_seq_append (seq, &tseq);
+ gimplify_stmt (&t, seq);
}
/* Strip off a legitimate source ending from the input string NAME of
@@ -1039,8 +1036,6 @@ gimplify_bind_expr (tree *expr_p, gimple
gimple gimple_bind;
struct gimple_sequence empty_seq;
- gimple_seq_init (&empty_seq);
-
tree temp = voidify_wrapper_expr (bind_expr, NULL);
/* Mark variables seen in this bind expr. */
@@ -1071,7 +1066,7 @@ gimplify_bind_expr (tree *expr_p, gimple
DECL_GIMPLE_REG_P (t) = 1;
}
- gimple_bind = gimple_build_bind (BIND_EXPR_VARS (bind_expr), &empty_seq);
+ gimple_bind = gimple_build_bind (BIND_EXPR_VARS (bind_expr), NULL);
gimple_push_bind_expr (gimple_bind);
gimplify_ctxp->save_stack = false;
@@ -1082,22 +1077,17 @@ gimplify_bind_expr (tree *expr_p, gimple
if (gimplify_ctxp->save_stack)
{
gimple stack_save, stack_restore, gs;
- struct gimple_sequence restore_seq;
/* Save stack on entry and restore it on exit. Add a try_finally
block to achieve this. Note that mudflap depends on the
format of the emitted code: see mx_register_decls(). */
build_stack_save_restore (&stack_save, &stack_restore);
- /* FIXME tuples: Creating a one item sequence is really
- retarded. If this happens more often in the gimplifier we
- should create a helper function for this. */
- gimple_seq_init (&restore_seq);
- gimple_add (&restore_seq, stack_restore);
-
- gs = gimple_build_try (gimple_bind_body (gimple_bind), &restore_seq,
- GIMPLE_TRY_FINALLY);
+ gs = gimple_build_try (gimple_bind_body (gimple_bind), NULL,
+ GIMPLE_TRY_FINALLY);
+ gimple_add (gimple_try_cleanup (gs), stack_restore);
+ gimple_seq_init (&empty_seq);
gimple_bind_set_body (gimple_bind, &empty_seq);
gimple_add (gimple_bind_body (gimple_bind), stack_save);
gimple_add (gimple_bind_body (gimple_bind), gs);
@@ -1294,25 +1284,22 @@ static enum gimplify_status
gimplify_loop_expr (tree *expr_p, gimple_seq pre_p)
{
tree saved_label = gimplify_ctxp->exit_label;
- tree start_label = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
- tree jump_stmt = build_and_jump (&LABEL_EXPR_LABEL (start_label));
+ tree start_label = create_artificial_label ();
- gimplify_and_add (start_label, pre_p);
+ gimple_add (pre_p, gimple_build_label (start_label));
gimplify_ctxp->exit_label = NULL_TREE;
gimplify_and_add (LOOP_EXPR_BODY (*expr_p), pre_p);
+ gimple_add (pre_p, gimple_build_goto (start_label));
+
if (gimplify_ctxp->exit_label)
- {
- gimplify_and_add (jump_stmt, pre_p);
- *expr_p = build1 (LABEL_EXPR, void_type_node, gimplify_ctxp->exit_label);
- }
- else
- *expr_p = jump_stmt;
+ gimple_add (pre_p, gimple_build_label (gimplify_ctxp->exit_label));
gimplify_ctxp->exit_label = saved_label;
+ *expr_p = NULL;
return GS_ALL_DONE;
}
@@ -5945,10 +5932,20 @@ gimplify_expr (tree *expr_p, gimple_seq
case TRY_FINALLY_EXPR:
case TRY_CATCH_EXPR:
- gimplify_to_stmt_list (&TREE_OPERAND (*expr_p, 0));
- gimplify_to_stmt_list (&TREE_OPERAND (*expr_p, 1));
- ret = GS_ALL_DONE;
- break;
+ {
+ gimple try
+ = gimple_build_try (NULL, NULL,
+ TREE_CODE (*expr_p) == TRY_FINALLY_EXPR ?
+ GIMPLE_TRY_FINALLY : GIMPLE_TRY_CATCH);
+
+ gimplify_and_add (TREE_OPERAND (*expr_p, 0), gimple_try_eval (try));
+ gimplify_and_add (TREE_OPERAND (*expr_p, 1),
+ gimple_try_cleanup (try));
+ gimple_add (pre_p, try);
+
+ ret = GS_ALL_DONE;
+ break;
+ }
case CLEANUP_POINT_EXPR:
gcc_unreachable();
@@ -6264,6 +6261,7 @@ gimplify_expr (tree *expr_p, gimple_seq
&& code != EH_FILTER_EXPR
&& code != GOTO_EXPR
&& code != LABEL_EXPR
+ && code != LOOP_EXPR
&& code != PHI_NODE
&& code != RESX_EXPR
&& code != SWITCH_EXPR
Index: gimple.c
===================================================================
--- gimple.c (revision 126719)
+++ gimple.c (working copy)
@@ -44,6 +44,9 @@ static struct pointer_map_t *gimple_bodi
/* Gimple tuple constructors. */
+/* Note: Any constructor taking a ``gimple_seq'' as a parameter, can be passed
+ a NULL to start with an empty sequence. */
+
/* Construct a GIMPLE_RETURN statement.
RESULT_DECL_P is non-zero if using RESULT_DECL.
@@ -203,7 +206,7 @@ gss_for_assign (enum tree_code code)
gimple
gimple_build_cond (enum gimple_cond pred, tree lhs, tree rhs,
- tree t_label, tree f_label)
+ tree t_label, tree f_label)
{
gimple p;
@@ -283,7 +286,8 @@ gimple_build_bind (tree vars, gimple_seq
p = ggc_alloc_cleared (sizeof (struct gimple_statement_bind));
GIMPLE_CODE (p) = GIMPLE_BIND;
gimple_bind_set_vars (p, vars);
- gimple_bind_set_body (p, body);
+ if (body)
+ gimple_bind_set_body (p, body);
return p;
}
@@ -364,11 +368,12 @@ gimple_build_eh_filter (tree types, gimp
EVAL is the expression to evaluate.
CLEANUP is the cleanup expression.
- CATCH_FINALLY is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on whether
- this is a try/catch or a try/finally respectively. */
+ CATCH_FINALLY is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
+ whether this is a try/catch or a try/finally respectively. */
gimple
-gimple_build_try (gimple_seq eval, gimple_seq cleanup, unsigned int catch_finally)
+gimple_build_try (gimple_seq eval, gimple_seq cleanup,
+ unsigned int catch_finally)
{
gimple p;
@@ -376,8 +381,10 @@ gimple_build_try (gimple_seq eval, gimpl
|| catch_finally == GIMPLE_TRY_FINALLY);
p = ggc_alloc_cleared (sizeof (struct gimple_statement_try));
GIMPLE_CODE (p) = GIMPLE_TRY;
- gimple_try_set_eval (p, eval);
- gimple_try_set_cleanup (p, cleanup);
+ if (eval)
+ gimple_try_set_eval (p, eval);
+ if (cleanup)
+ gimple_try_set_cleanup (p, cleanup);
GIMPLE_SUBCODE_FLAGS (p) = catch_finally;
return p;
@@ -489,7 +496,7 @@ gimple_build_switch (unsigned int nlabel
ARGS is a vector of labels excluding the default. */
gimple
-gimple_build_switch_vec (tree index, tree default_label, VEC(tree, heap) * args)
+gimple_build_switch_vec (tree index, tree default_label, VEC(tree, heap) *args)
{
size_t i;
size_t nlabels = VEC_length (tree, args);
@@ -517,7 +524,8 @@ gimple_omp_build_critical (gimple_seq bo
p = ggc_alloc_cleared (sizeof (struct gimple_statement_omp_critical));
GIMPLE_CODE (p) = GIMPLE_OMP_CRITICAL;
gimple_omp_critical_set_name (p, name);
- gimple_omp_set_body (p, body);
+ if (body)
+ gimple_omp_set_body (p, body);
return p;
}
@@ -543,13 +551,15 @@ gimple_omp_build_for (gimple_seq body, t
p = ggc_alloc_cleared (sizeof (struct gimple_statement_omp_for));
GIMPLE_CODE (p) = GIMPLE_OMP_FOR;
- gimple_omp_set_body (p, body);
+ if (body)
+ gimple_omp_set_body (p, body);
gimple_omp_for_set_clauses (p, clauses);
gimple_omp_for_set_index (p, index);
gimple_omp_for_set_initial (p, initial);
gimple_omp_for_set_final (p, final);
gimple_omp_for_set_incr (p, incr);
- gimple_omp_for_set_pre_body (p, pre_body);
+ if (pre_body)
+ gimple_omp_for_set_pre_body (p, pre_body);
gimple_assign_omp_for_cond (p, omp_for_cond);
return p;
@@ -570,7 +580,8 @@ gimple_omp_build_parallel (gimple_seq bo
p = ggc_alloc_cleared (sizeof (struct gimple_statement_omp_parallel));
GIMPLE_CODE (p) = GIMPLE_OMP_PARALLEL;
- gimple_omp_set_body (p, body);
+ if (body)
+ gimple_omp_set_body (p, body);
gimple_omp_parallel_set_clauses (p, clauses);
gimple_omp_parallel_set_child_fn (p, child_fn);
gimple_omp_parallel_set_data_arg (p, data_arg);
@@ -589,7 +600,8 @@ gimple_omp_build_section (gimple_seq bod
p = ggc_alloc_cleared (sizeof (struct gimple_statement_omp));
GIMPLE_CODE (p) = GIMPLE_OMP_SECTION;
- gimple_omp_set_body (p, body);
+ if (body)
+ gimple_omp_set_body (p, body);
return p;
}
@@ -604,7 +616,8 @@ gimple_omp_build_master (gimple_seq body
p = ggc_alloc_cleared (sizeof (struct gimple_statement_omp));
GIMPLE_CODE (p) = GIMPLE_OMP_MASTER;
- gimple_omp_set_body (p, body);
+ if (body)
+ gimple_omp_set_body (p, body);
return p;
}
@@ -618,7 +631,8 @@ gimple_omp_build_continue (gimple_seq bo
p = ggc_alloc_cleared (sizeof (struct gimple_statement_omp));
GIMPLE_CODE (p) = GIMPLE_OMP_CONTINUE;
- gimple_omp_set_body (p, body);
+ if (body)
+ gimple_omp_set_body (p, body);
return p;
}
@@ -635,7 +649,8 @@ gimple_omp_build_ordered (gimple_seq bod
p = ggc_alloc_cleared (sizeof (struct gimple_statement_omp));
GIMPLE_CODE (p) = GIMPLE_OMP_ORDERED;
- gimple_omp_set_body (p, body);
+ if (body)
+ gimple_omp_set_body (p, body);
return p;
}
@@ -669,7 +684,8 @@ gimple_omp_build_sections (gimple_seq bo
p = ggc_alloc_cleared (sizeof (struct gimple_statement_omp_sections));
GIMPLE_CODE (p) = GIMPLE_OMP_SECTIONS;
- gimple_omp_set_body (p, body);
+ if (body)
+ gimple_omp_set_body (p, body);
gimple_omp_sections_set_clauses (p, clauses);
return p;
@@ -688,7 +704,8 @@ gimple_omp_build_single (gimple_seq body
p = ggc_alloc_cleared (sizeof (struct gimple_statement_omp_single));
GIMPLE_CODE (p) = GIMPLE_OMP_SINGLE;
- gimple_omp_set_body (p, body);
+ if (body)
+ gimple_omp_set_body (p, body);
gimple_omp_single_set_clauses (p, clauses);
return p;
@@ -754,20 +771,6 @@ gimple_check_failed (const gimple gs, co
#endif /* ENABLE_TREE_CHECKING */
-/* Push gimple statement GS into the front of sequence SEQ. */
-
-void
-gimple_push (gimple gs, gimple_seq seq)
-{
- gimple oldfirst = gimple_seq_first (seq);
-
- GIMPLE_NEXT (gs) = oldfirst;
- if (oldfirst)
- GIMPLE_PREV (oldfirst) = gs;
- gimple_seq_set_first (seq, gs);
-}
-
-
/* Link a gimple statement(s) to the end of the sequence SEQ. */
void
Index: gimple.h
===================================================================
--- gimple.h (revision 126722)
+++ gimple.h (working copy)
@@ -425,7 +425,6 @@ extern gimple gimple_omp_build_sections
extern gimple gimple_omp_build_single (gimple_seq, tree);
extern enum gimple_statement_structure_enum gimple_statement_structure (gimple);
extern void gimple_add (gimple_seq, gimple);
-extern void gimple_push (gimple, gimple_seq);
extern enum gimple_statement_structure_enum gss_for_assign (enum tree_code);
extern void sort_case_labels (VEC(tree,heap) *);
extern void walk_tuple_ops (gimple, walk_tree_fn, void *,
More information about the Gcc-patches
mailing list