* [PATCH] Remove unused SWITCH_LABELS
@ 2017-11-27 23:26 Jakub Jelinek
2017-11-28 6:20 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-11-27 23:26 UTC (permalink / raw)
To: Richard Biener, Jeff Law; +Cc: gcc-patches
Hi!
Before tuples SWITCH_LABELS used to hold the vectors of case labels
during optimization, then it was used during expansion - GIMPLE_SWITCH
has been converted back to SWITCH_EXPR and SWITCH_LABELS used to hold
the vector. Later on we've switched to expand_case right from
GIMPLE_SWITCH, and since then SWITCH_LABELS is always NULL_TREE,
no FEs ever set it to anything different, and aside from block_may_fallthru
and dump_generic_node and a left-over assert in the gimplifier nothing
really uses it. The gimplifier will not really work if some FE would
decide to fill it in though, see David's comment in the jit FE about his
attempts.
So, this patch just removes that, turns SWITCH_EXPR into a 2 operand only
tree.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2017-11-27 Jakub Jelinek <jakub@redhat.com>
* tree.def (SWITCH_EXPR): Change from 3 operand to 2 operand tree.
Adjust comment.
* tree.h (SWITCH_LABELS): Remove.
* gimplify.c (gimplify_switch_expr): Don't test SWITCH_LABELS,
assert SWITCH_BODY is non-NULL.
* tree-pretty-print.c (dump_generic_node): Remove SWITCH_LABELS
handling.
* tree.c (block_may_fallthru): Always return true; for SWITCH_EXPR.
c/
* c-typeck.c (c_start_case): Build SWITCH_EXPR using build2 instead
of build3.
cp/
* cp-gimplify.c (genericize_switch_stmt): Build SWITCH_EXPR using
build2_loc instead of build3_loc.
ada/
* gcc-interface/trans.c (Case_Statement_to_gnu): Build SWITCH_EXPR
using build2 instead of build3.
jit/
* jit-playback.c (add_switch): Build SWITCH_EXPR using build2 instead
of build3. Formatting fixes. Adjust funciton comment.
fortran/
* trans-decl.c (gfc_trans_entry_master_switch): Build SWITCH_EXPR
using fold_build2_loc instead of fold_build3_loc.
* trans-io.c (io_result): Likewise.
* trans-stmt.c (gfc_trans_integer_select, gfc_trans_character_select):
Likewise.
go/
* go-gcc.cc (Gcc_backend::switch_statement): Build SWITCH_EXPR using
build2_loc instead of build3_loc.
brig/
* brigfrontend/brig-branch-inst-handler.cc
(brig_branch_inst_handler::operator): Build SWITCH_EXPR using build2
instead of build3.
--- gcc/tree.def.jj 2017-11-23 21:13:30.000000000 +0100
+++ gcc/tree.def 2017-11-27 14:26:08.778420518 +0100
@@ -943,10 +943,8 @@ DEFTREECODE (LOOP_EXPR, "loop_expr", tcc
Operand 0 is the expression used to perform the branch,
Operand 1 is the body of the switch, which probably contains
CASE_LABEL_EXPRs. It may also be NULL, in which case operand 2
- must not be NULL.
- Operand 2 is either NULL_TREE or a TREE_VEC of the CASE_LABEL_EXPRs
- of all the cases. */
-DEFTREECODE (SWITCH_EXPR, "switch_expr", tcc_statement, 3)
+ must not be NULL. */
+DEFTREECODE (SWITCH_EXPR, "switch_expr", tcc_statement, 2)
/* Used to represent a case label.
--- gcc/tree.h.jj 2017-11-22 21:37:46.000000000 +0100
+++ gcc/tree.h 2017-11-27 14:34:38.501259197 +0100
@@ -1172,12 +1172,9 @@ extern void protected_set_expr_location
#define COMPOUND_LITERAL_EXPR_DECL(NODE) \
DECL_EXPR_DECL (COMPOUND_LITERAL_EXPR_DECL_EXPR (NODE))
-/* SWITCH_EXPR accessors. These give access to the condition, body and
- original condition type (before any compiler conversions)
- of the switch statement, respectively. */
+/* SWITCH_EXPR accessors. These give access to the condition and body. */
#define SWITCH_COND(NODE) TREE_OPERAND (SWITCH_EXPR_CHECK (NODE), 0)
#define SWITCH_BODY(NODE) TREE_OPERAND (SWITCH_EXPR_CHECK (NODE), 1)
-#define SWITCH_LABELS(NODE) TREE_OPERAND (SWITCH_EXPR_CHECK (NODE), 2)
/* CASE_LABEL_EXPR accessors. These give access to the high and low values
of a case label, respectively. */
--- gcc/gimplify.c.jj 2017-11-23 21:13:30.000000000 +0100
+++ gcc/gimplify.c 2017-11-27 14:35:30.678614350 +0100
@@ -2287,10 +2287,6 @@ gimplify_switch_expr (tree *expr_p, gimp
tree default_case = NULL_TREE;
gswitch *switch_stmt;
- /* If someone can be bothered to fill in the labels, they can
- be bothered to null out the body too. */
- gcc_assert (!SWITCH_LABELS (switch_expr));
-
/* Save old labels, get new ones from body, then restore the old
labels. Save all the things from the switch body to append after. */
saved_labels = gimplify_ctxp->case_labels;
@@ -2347,7 +2343,7 @@ gimplify_switch_expr (tree *expr_p, gimp
labels.release ();
}
else
- gcc_assert (SWITCH_LABELS (switch_expr));
+ gcc_unreachable ();
return GS_ALL_DONE;
}
--- gcc/tree-pretty-print.c.jj 2017-11-23 21:13:27.000000000 +0100
+++ gcc/tree-pretty-print.c 2017-11-27 14:32:27.110883021 +0100
@@ -2686,26 +2686,6 @@ dump_generic_node (pretty_printer *pp, t
dump_generic_node (pp, SWITCH_BODY (node), spc+4, flags,
true);
}
- else
- {
- tree vec = SWITCH_LABELS (node);
- size_t i, n = TREE_VEC_LENGTH (vec);
- for (i = 0; i < n; ++i)
- {
- tree elt = TREE_VEC_ELT (vec, i);
- newline_and_indent (pp, spc+4);
- if (elt)
- {
- dump_generic_node (pp, elt, spc+4, flags, false);
- pp_string (pp, " goto ");
- dump_generic_node (pp, CASE_LABEL (elt), spc+4,
- flags, true);
- pp_semicolon (pp);
- }
- else
- pp_string (pp, "case ???: goto ???;");
- }
- }
newline_and_indent (pp, spc+2);
pp_right_brace (pp);
}
--- gcc/c/c-typeck.c.jj 2017-11-21 20:23:00.000000000 +0100
+++ gcc/c/c-typeck.c 2017-11-27 14:27:53.283215926 +0100
@@ -10330,7 +10330,7 @@ c_start_case (location_t switch_loc,
/* Add this new SWITCH_EXPR to the stack. */
cs = XNEW (struct c_switch);
- cs->switch_expr = build3 (SWITCH_EXPR, orig_type, exp, NULL_TREE, NULL_TREE);
+ cs->switch_expr = build2 (SWITCH_EXPR, orig_type, exp, NULL_TREE);
SET_EXPR_LOCATION (cs->switch_expr, switch_loc);
cs->orig_type = orig_type;
cs->cases = splay_tree_new (case_compare, NULL, NULL);
--- gcc/cp/cp-gimplify.c.jj 2017-11-27 14:12:31.000000000 +0100
+++ gcc/cp/cp-gimplify.c 2017-11-27 14:28:15.969954424 +0100
@@ -332,7 +332,7 @@ genericize_switch_stmt (tree *stmt_p, in
cp_walk_tree (&type, cp_genericize_r, data, NULL);
*walk_subtrees = 0;
- *stmt_p = build3_loc (stmt_locus, SWITCH_EXPR, type, cond, body, NULL_TREE);
+ *stmt_p = build2_loc (stmt_locus, SWITCH_EXPR, type, cond, body);
finish_bc_block (stmt_p, bc_break, break_block);
}
--- gcc/ada/gcc-interface/trans.c.jj 2017-11-23 21:13:29.000000000 +0100
+++ gcc/ada/gcc-interface/trans.c 2017-11-27 14:29:18.752210902 +0100
@@ -2625,8 +2625,7 @@ Case_Statement_to_gnu (Node_Id gnat_node
/* Now emit a definition of the label the cases branch to, if any. */
if (may_fallthru)
add_stmt (build1 (LABEL_EXPR, void_type_node, gnu_label));
- gnu_result
- = build3 (SWITCH_EXPR, gnu_type, gnu_expr, end_stmt_group (), NULL_TREE);
+ gnu_result = build2 (SWITCH_EXPR, gnu_type, gnu_expr, end_stmt_group ());
return gnu_result;
}
--- gcc/jit/jit-playback.c.jj 2017-10-04 16:45:27.000000000 +0200
+++ gcc/jit/jit-playback.c 2017-11-27 14:33:40.330978110 +0100
@@ -1689,12 +1689,7 @@ add_case (tree *ptr_t_switch_body,
/* Add a switch statement to the function's statement list.
- My initial attempt at implementing this constructed a TREE_VEC
- of the cases and set it as SWITCH_LABELS (switch_expr). However,
- gimplify.c:gimplify_switch_expr is set up to deal with SWITCH_BODY, and
- doesn't have any logic for gimplifying SWITCH_LABELS.
-
- Hence we create a switch body, and populate it with case labels, each
+ We create a switch body, and populate it with case labels, each
followed by a goto to the desired block. */
void
@@ -1722,18 +1717,12 @@ add_switch (location *loc,
{
tree t_low_value = c->m_min_value->as_tree ();
tree t_high_value = c->m_max_value->as_tree ();
- add_case (&t_switch_body,
- t_low_value,
- t_high_value,
- c->m_dest_block);
+ add_case (&t_switch_body, t_low_value, t_high_value, c->m_dest_block);
}
/* Default label. */
- add_case (&t_switch_body,
- NULL_TREE, NULL_TREE,
- default_block);
+ add_case (&t_switch_body, NULL_TREE, NULL_TREE, default_block);
- tree switch_stmt = build3 (SWITCH_EXPR, t_type, t_expr,
- t_switch_body, NULL_TREE);
+ tree switch_stmt = build2 (SWITCH_EXPR, t_type, t_expr, t_switch_body);
if (loc)
set_tree_location (switch_stmt, loc);
add_stmt (switch_stmt);
--- gcc/tree.c.jj 2017-11-22 21:37:46.000000000 +0100
+++ gcc/tree.c 2017-11-27 14:36:09.559133834 +0100
@@ -12339,11 +12339,7 @@ block_may_fallthru (const_tree block)
return false;
case SWITCH_EXPR:
- /* If SWITCH_LABELS is set, this is lowered, and represents a
- branch to a selected label and hence can not fall through.
- Otherwise SWITCH_BODY is set, and the switch can fall
- through. */
- return SWITCH_LABELS (stmt) == NULL_TREE;
+ return true;
case COND_EXPR:
if (block_may_fallthru (COND_EXPR_THEN (stmt)))
--- gcc/fortran/trans-decl.c.jj 2017-11-20 11:02:41.000000000 +0100
+++ gcc/fortran/trans-decl.c 2017-11-27 14:29:42.653915506 +0100
@@ -5758,8 +5758,7 @@ gfc_trans_entry_master_switch (gfc_entry
tmp = gfc_finish_block (&block);
/* The first argument selects the entry point. */
val = DECL_ARGUMENTS (current_function_decl);
- tmp = fold_build3_loc (input_location, SWITCH_EXPR, NULL_TREE,
- val, tmp, NULL_TREE);
+ tmp = fold_build2_loc (input_location, SWITCH_EXPR, NULL_TREE, val, tmp);
return tmp;
}
--- gcc/fortran/trans-io.c.jj 2017-11-08 16:19:36.000000000 +0100
+++ gcc/fortran/trans-io.c 2017-11-27 14:30:01.938677170 +0100
@@ -1002,8 +1002,7 @@ io_result (stmtblock_t * block, tree var
rc, build_int_cst (TREE_TYPE (rc),
IOPARM_common_libreturn_mask));
- tmp = fold_build3_loc (input_location, SWITCH_EXPR, NULL_TREE,
- rc, tmp, NULL_TREE);
+ tmp = fold_build2_loc (input_location, SWITCH_EXPR, NULL_TREE, rc, tmp);
gfc_add_expr_to_block (block, tmp);
}
--- gcc/fortran/trans-stmt.c.jj 2017-11-23 21:13:29.000000000 +0100
+++ gcc/fortran/trans-stmt.c 2017-11-27 14:30:42.530175510 +0100
@@ -2666,8 +2666,7 @@ gfc_trans_integer_select (gfc_code * cod
}
tmp = gfc_finish_block (&body);
- tmp = fold_build3_loc (input_location, SWITCH_EXPR, NULL_TREE,
- se.expr, tmp, NULL_TREE);
+ tmp = fold_build2_loc (input_location, SWITCH_EXPR, NULL_TREE, se.expr, tmp);
gfc_add_expr_to_block (&block, tmp);
tmp = build1_v (LABEL_EXPR, end_label);
@@ -2952,8 +2951,8 @@ gfc_trans_character_select (gfc_code *co
gfc_add_block_to_block (&block, &expr1se.post);
tmp = gfc_finish_block (&body);
- tmp = fold_build3_loc (input_location, SWITCH_EXPR, NULL_TREE,
- case_num, tmp, NULL_TREE);
+ tmp = fold_build2_loc (input_location, SWITCH_EXPR, NULL_TREE,
+ case_num, tmp);
gfc_add_expr_to_block (&block, tmp);
tmp = build1_v (LABEL_EXPR, end_label);
@@ -3099,8 +3098,8 @@ gfc_trans_character_select (gfc_code *co
gfc_add_block_to_block (&block, &expr1se.post);
tmp = gfc_finish_block (&body);
- tmp = fold_build3_loc (input_location, SWITCH_EXPR, NULL_TREE,
- case_num, tmp, NULL_TREE);
+ tmp = fold_build2_loc (input_location, SWITCH_EXPR, NULL_TREE,
+ case_num, tmp);
gfc_add_expr_to_block (&block, tmp);
tmp = build1_v (LABEL_EXPR, end_label);
--- gcc/go/go-gcc.cc.jj 2017-11-21 23:17:33.000000000 +0100
+++ gcc/go/go-gcc.cc 2017-11-27 21:21:35.272001550 +0100
@@ -2289,8 +2289,8 @@ Gcc_backend::switch_statement(
tree tv = value->get_tree();
if (tv == error_mark_node)
return this->error_statement();
- tree t = build3_loc(switch_location.gcc_location(), SWITCH_EXPR,
- NULL_TREE, tv, stmt_list, NULL_TREE);
+ tree t = build2_loc(switch_location.gcc_location(), SWITCH_EXPR,
+ NULL_TREE, tv, stmt_list);
return this->make_statement(t);
}
--- gcc/brig/brigfrontend/brig-branch-inst-handler.cc.jj 2017-11-21 23:18:18.000000000 +0100
+++ gcc/brig/brigfrontend/brig-branch-inst-handler.cc 2017-11-27 21:29:27.659245467 +0100
@@ -167,8 +167,8 @@ brig_branch_inst_handler::operator () (c
tree select = operands[0];
tree cases = operands[1];
- tree switch_expr = build3 (SWITCH_EXPR, TREE_TYPE (select), select,
- NULL_TREE, NULL_TREE);
+ tree switch_expr = build2 (SWITCH_EXPR, TREE_TYPE (select), select,
+ NULL_TREE);
tree default_case
= build_case_label (NULL_TREE, NULL_TREE,
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Remove unused SWITCH_LABELS
2017-11-27 23:26 [PATCH] Remove unused SWITCH_LABELS Jakub Jelinek
@ 2017-11-28 6:20 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2017-11-28 6:20 UTC (permalink / raw)
To: Jakub Jelinek, Richard Biener; +Cc: gcc-patches
On 11/27/2017 03:41 PM, Jakub Jelinek wrote:
> Hi!
>
> Before tuples SWITCH_LABELS used to hold the vectors of case labels
> during optimization, then it was used during expansion - GIMPLE_SWITCH
> has been converted back to SWITCH_EXPR and SWITCH_LABELS used to hold
> the vector. Later on we've switched to expand_case right from
> GIMPLE_SWITCH, and since then SWITCH_LABELS is always NULL_TREE,
> no FEs ever set it to anything different, and aside from block_may_fallthru
> and dump_generic_node and a left-over assert in the gimplifier nothing
> really uses it. The gimplifier will not really work if some FE would
> decide to fill it in though, see David's comment in the jit FE about his
> attempts.
>
> So, this patch just removes that, turns SWITCH_EXPR into a 2 operand only
> tree.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2017-11-27 Jakub Jelinek <jakub@redhat.com>
>
> * tree.def (SWITCH_EXPR): Change from 3 operand to 2 operand tree.
> Adjust comment.
> * tree.h (SWITCH_LABELS): Remove.
> * gimplify.c (gimplify_switch_expr): Don't test SWITCH_LABELS,
> assert SWITCH_BODY is non-NULL.
> * tree-pretty-print.c (dump_generic_node): Remove SWITCH_LABELS
> handling.
> * tree.c (block_may_fallthru): Always return true; for SWITCH_EXPR.
> c/
> * c-typeck.c (c_start_case): Build SWITCH_EXPR using build2 instead
> of build3.
> cp/
> * cp-gimplify.c (genericize_switch_stmt): Build SWITCH_EXPR using
> build2_loc instead of build3_loc.
> ada/
> * gcc-interface/trans.c (Case_Statement_to_gnu): Build SWITCH_EXPR
> using build2 instead of build3.
> jit/
> * jit-playback.c (add_switch): Build SWITCH_EXPR using build2 instead
> of build3. Formatting fixes. Adjust funciton comment.
> fortran/
> * trans-decl.c (gfc_trans_entry_master_switch): Build SWITCH_EXPR
> using fold_build2_loc instead of fold_build3_loc.
> * trans-io.c (io_result): Likewise.
> * trans-stmt.c (gfc_trans_integer_select, gfc_trans_character_select):
> Likewise.
> go/
> * go-gcc.cc (Gcc_backend::switch_statement): Build SWITCH_EXPR using
> build2_loc instead of build3_loc.
> brig/
> * brigfrontend/brig-branch-inst-handler.cc
> (brig_branch_inst_handler::operator): Build SWITCH_EXPR using build2
> instead of build3.
OK.
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-11-28 6:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27 23:26 [PATCH] Remove unused SWITCH_LABELS Jakub Jelinek
2017-11-28 6:20 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).