Commit 90acd49f by Martin Liska Committed by Martin Liska

Use more switch statements.

2019-09-24  Martin Liska  <mliska@suse.cz>

	* cfgexpand.c (gimple_assign_rhs_to_tree): Use switch statement
	instead of if-elseif-elseif-...
	* gimple-expr.c (extract_ops_from_tree): Likewise.
	* gimple.c (get_gimple_rhs_num_ops): Likewise.
	* tree-ssa-forwprop.c (rhs_to_tree): Likewise.

From-SVN: r276095
parent 231f7546
2019-09-24 Martin Liska <mliska@suse.cz>
* cfgexpand.c (gimple_assign_rhs_to_tree): Use switch statement
instead of if-elseif-elseif-...
* gimple-expr.c (extract_ops_from_tree): Likewise.
* gimple.c (get_gimple_rhs_num_ops): Likewise.
* tree-ssa-forwprop.c (rhs_to_tree): Likewise.
2019-09-24 Martin Jambor <mjambor@suse.cz> 2019-09-24 Martin Jambor <mjambor@suse.cz>
PR ipa/91831 PR ipa/91831
......
...@@ -104,38 +104,38 @@ tree ...@@ -104,38 +104,38 @@ tree
gimple_assign_rhs_to_tree (gimple *stmt) gimple_assign_rhs_to_tree (gimple *stmt)
{ {
tree t; tree t;
enum gimple_rhs_class grhs_class; switch (get_gimple_rhs_class (gimple_expr_code (stmt)))
{
grhs_class = get_gimple_rhs_class (gimple_expr_code (stmt)); case GIMPLE_TERNARY_RHS:
t = build3 (gimple_assign_rhs_code (stmt),
if (grhs_class == GIMPLE_TERNARY_RHS) TREE_TYPE (gimple_assign_lhs (stmt)),
t = build3 (gimple_assign_rhs_code (stmt), gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt),
TREE_TYPE (gimple_assign_lhs (stmt)), gimple_assign_rhs3 (stmt));
gimple_assign_rhs1 (stmt), break;
gimple_assign_rhs2 (stmt), case GIMPLE_BINARY_RHS:
gimple_assign_rhs3 (stmt)); t = build2 (gimple_assign_rhs_code (stmt),
else if (grhs_class == GIMPLE_BINARY_RHS) TREE_TYPE (gimple_assign_lhs (stmt)),
t = build2 (gimple_assign_rhs_code (stmt), gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt));
TREE_TYPE (gimple_assign_lhs (stmt)), break;
gimple_assign_rhs1 (stmt), case GIMPLE_UNARY_RHS:
gimple_assign_rhs2 (stmt)); t = build1 (gimple_assign_rhs_code (stmt),
else if (grhs_class == GIMPLE_UNARY_RHS) TREE_TYPE (gimple_assign_lhs (stmt)),
t = build1 (gimple_assign_rhs_code (stmt), gimple_assign_rhs1 (stmt));
TREE_TYPE (gimple_assign_lhs (stmt)), break;
gimple_assign_rhs1 (stmt)); case GIMPLE_SINGLE_RHS:
else if (grhs_class == GIMPLE_SINGLE_RHS) {
{ t = gimple_assign_rhs1 (stmt);
t = gimple_assign_rhs1 (stmt); /* Avoid modifying this tree in place below. */
/* Avoid modifying this tree in place below. */ if ((gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t)
if ((gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t) && gimple_location (stmt) != EXPR_LOCATION (t))
&& gimple_location (stmt) != EXPR_LOCATION (t)) || (gimple_block (stmt) && currently_expanding_to_rtl
|| (gimple_block (stmt) && EXPR_P (t)))
&& currently_expanding_to_rtl t = copy_node (t);
&& EXPR_P (t))) break;
t = copy_node (t); }
default:
gcc_unreachable ();
} }
else
gcc_unreachable ();
if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t)) if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t))
SET_EXPR_LOCATION (t, gimple_location (stmt)); SET_EXPR_LOCATION (t, gimple_location (stmt));
......
...@@ -528,37 +528,40 @@ void ...@@ -528,37 +528,40 @@ void
extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p, extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p,
tree *op2_p, tree *op3_p) tree *op2_p, tree *op3_p)
{ {
enum gimple_rhs_class grhs_class;
*subcode_p = TREE_CODE (expr); *subcode_p = TREE_CODE (expr);
grhs_class = get_gimple_rhs_class (*subcode_p); switch (get_gimple_rhs_class (*subcode_p))
if (grhs_class == GIMPLE_TERNARY_RHS)
{
*op1_p = TREE_OPERAND (expr, 0);
*op2_p = TREE_OPERAND (expr, 1);
*op3_p = TREE_OPERAND (expr, 2);
}
else if (grhs_class == GIMPLE_BINARY_RHS)
{
*op1_p = TREE_OPERAND (expr, 0);
*op2_p = TREE_OPERAND (expr, 1);
*op3_p = NULL_TREE;
}
else if (grhs_class == GIMPLE_UNARY_RHS)
{
*op1_p = TREE_OPERAND (expr, 0);
*op2_p = NULL_TREE;
*op3_p = NULL_TREE;
}
else if (grhs_class == GIMPLE_SINGLE_RHS)
{ {
*op1_p = expr; case GIMPLE_TERNARY_RHS:
*op2_p = NULL_TREE; {
*op3_p = NULL_TREE; *op1_p = TREE_OPERAND (expr, 0);
*op2_p = TREE_OPERAND (expr, 1);
*op3_p = TREE_OPERAND (expr, 2);
break;
}
case GIMPLE_BINARY_RHS:
{
*op1_p = TREE_OPERAND (expr, 0);
*op2_p = TREE_OPERAND (expr, 1);
*op3_p = NULL_TREE;
break;
}
case GIMPLE_UNARY_RHS:
{
*op1_p = TREE_OPERAND (expr, 0);
*op2_p = NULL_TREE;
*op3_p = NULL_TREE;
break;
}
case GIMPLE_SINGLE_RHS:
{
*op1_p = expr;
*op2_p = NULL_TREE;
*op3_p = NULL_TREE;
break;
}
default:
gcc_unreachable ();
} }
else
gcc_unreachable ();
} }
/* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */ /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
......
...@@ -2225,16 +2225,18 @@ dump_gimple_statistics (void) ...@@ -2225,16 +2225,18 @@ dump_gimple_statistics (void)
unsigned unsigned
get_gimple_rhs_num_ops (enum tree_code code) get_gimple_rhs_num_ops (enum tree_code code)
{ {
enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code); switch (get_gimple_rhs_class (code))
{
if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS) case GIMPLE_UNARY_RHS:
return 1; case GIMPLE_SINGLE_RHS:
else if (rhs_class == GIMPLE_BINARY_RHS) return 1;
return 2; case GIMPLE_BINARY_RHS:
else if (rhs_class == GIMPLE_TERNARY_RHS) return 2;
return 3; case GIMPLE_TERNARY_RHS:
else return 3;
gcc_unreachable (); default:
gcc_unreachable ();
}
} }
#define DEFTREECODE(SYM, STRING, TYPE, NARGS) \ #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
......
...@@ -347,19 +347,22 @@ rhs_to_tree (tree type, gimple *stmt) ...@@ -347,19 +347,22 @@ rhs_to_tree (tree type, gimple *stmt)
{ {
location_t loc = gimple_location (stmt); location_t loc = gimple_location (stmt);
enum tree_code code = gimple_assign_rhs_code (stmt); enum tree_code code = gimple_assign_rhs_code (stmt);
if (get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS) switch (get_gimple_rhs_class (code))
return fold_build3_loc (loc, code, type, gimple_assign_rhs1 (stmt), {
gimple_assign_rhs2 (stmt), case GIMPLE_TERNARY_RHS:
gimple_assign_rhs3 (stmt)); return fold_build3_loc (loc, code, type, gimple_assign_rhs1 (stmt),
else if (get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS) gimple_assign_rhs2 (stmt),
return fold_build2_loc (loc, code, type, gimple_assign_rhs1 (stmt), gimple_assign_rhs3 (stmt));
gimple_assign_rhs2 (stmt)); case GIMPLE_BINARY_RHS:
else if (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS) return fold_build2_loc (loc, code, type, gimple_assign_rhs1 (stmt),
return build1 (code, type, gimple_assign_rhs1 (stmt)); gimple_assign_rhs2 (stmt));
else if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS) case GIMPLE_UNARY_RHS:
return gimple_assign_rhs1 (stmt); return build1 (code, type, gimple_assign_rhs1 (stmt));
else case GIMPLE_SINGLE_RHS:
gcc_unreachable (); return gimple_assign_rhs1 (stmt);
default:
gcc_unreachable ();
}
} }
/* Combine OP0 CODE OP1 in the context of a COND_EXPR. Returns /* Combine OP0 CODE OP1 in the context of a COND_EXPR. Returns
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment