From 90acd49f6ba247e4549224c2178910aee95a2617 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 24 Sep 2019 13:38:29 +0200 Subject: [PATCH] Use more switch statements. 2019-09-24 Martin Liska * 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 --- gcc/ChangeLog | 8 +++++++ gcc/cfgexpand.c | 62 ++++++++++++++++++++++++------------------------- gcc/gimple-expr.c | 59 ++++++++++++++++++++++++---------------------- gcc/gimple.c | 22 ++++++++++-------- gcc/tree-ssa-forwprop.c | 29 ++++++++++++----------- 5 files changed, 98 insertions(+), 82 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a44f4db..1c4c016 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-09-24 Martin Liska + + * 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 PR ipa/91831 diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 5a93447..a2f9623 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -104,38 +104,38 @@ tree gimple_assign_rhs_to_tree (gimple *stmt) { tree t; - enum gimple_rhs_class grhs_class; - - grhs_class = get_gimple_rhs_class (gimple_expr_code (stmt)); - - if (grhs_class == GIMPLE_TERNARY_RHS) - t = build3 (gimple_assign_rhs_code (stmt), - TREE_TYPE (gimple_assign_lhs (stmt)), - gimple_assign_rhs1 (stmt), - gimple_assign_rhs2 (stmt), - gimple_assign_rhs3 (stmt)); - else if (grhs_class == GIMPLE_BINARY_RHS) - t = build2 (gimple_assign_rhs_code (stmt), - TREE_TYPE (gimple_assign_lhs (stmt)), - gimple_assign_rhs1 (stmt), - gimple_assign_rhs2 (stmt)); - else if (grhs_class == GIMPLE_UNARY_RHS) - t = build1 (gimple_assign_rhs_code (stmt), - TREE_TYPE (gimple_assign_lhs (stmt)), - gimple_assign_rhs1 (stmt)); - else if (grhs_class == GIMPLE_SINGLE_RHS) - { - t = gimple_assign_rhs1 (stmt); - /* Avoid modifying this tree in place below. */ - if ((gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t) - && gimple_location (stmt) != EXPR_LOCATION (t)) - || (gimple_block (stmt) - && currently_expanding_to_rtl - && EXPR_P (t))) - t = copy_node (t); + switch (get_gimple_rhs_class (gimple_expr_code (stmt))) + { + case GIMPLE_TERNARY_RHS: + t = build3 (gimple_assign_rhs_code (stmt), + TREE_TYPE (gimple_assign_lhs (stmt)), + gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt), + gimple_assign_rhs3 (stmt)); + break; + case GIMPLE_BINARY_RHS: + t = build2 (gimple_assign_rhs_code (stmt), + TREE_TYPE (gimple_assign_lhs (stmt)), + gimple_assign_rhs1 (stmt), gimple_assign_rhs2 (stmt)); + break; + case GIMPLE_UNARY_RHS: + t = build1 (gimple_assign_rhs_code (stmt), + TREE_TYPE (gimple_assign_lhs (stmt)), + gimple_assign_rhs1 (stmt)); + break; + case GIMPLE_SINGLE_RHS: + { + t = gimple_assign_rhs1 (stmt); + /* Avoid modifying this tree in place below. */ + if ((gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t) + && gimple_location (stmt) != EXPR_LOCATION (t)) + || (gimple_block (stmt) && currently_expanding_to_rtl + && EXPR_P (t))) + t = copy_node (t); + break; + } + default: + gcc_unreachable (); } - else - gcc_unreachable (); if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t)) SET_EXPR_LOCATION (t, gimple_location (stmt)); diff --git a/gcc/gimple-expr.c b/gcc/gimple-expr.c index b0c9f9b..4082828 100644 --- a/gcc/gimple-expr.c +++ b/gcc/gimple-expr.c @@ -528,37 +528,40 @@ void extract_ops_from_tree (tree expr, enum tree_code *subcode_p, tree *op1_p, tree *op2_p, tree *op3_p) { - enum gimple_rhs_class grhs_class; - *subcode_p = TREE_CODE (expr); - grhs_class = 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) + switch (get_gimple_rhs_class (*subcode_p)) { - *op1_p = expr; - *op2_p = NULL_TREE; - *op3_p = NULL_TREE; + case GIMPLE_TERNARY_RHS: + { + *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. */ diff --git a/gcc/gimple.c b/gcc/gimple.c index 88250ca..af62c8b 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -2225,16 +2225,18 @@ dump_gimple_statistics (void) unsigned get_gimple_rhs_num_ops (enum tree_code code) { - enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code); - - if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS) - return 1; - else if (rhs_class == GIMPLE_BINARY_RHS) - return 2; - else if (rhs_class == GIMPLE_TERNARY_RHS) - return 3; - else - gcc_unreachable (); + switch (get_gimple_rhs_class (code)) + { + case GIMPLE_UNARY_RHS: + case GIMPLE_SINGLE_RHS: + return 1; + case GIMPLE_BINARY_RHS: + return 2; + case GIMPLE_TERNARY_RHS: + return 3; + default: + gcc_unreachable (); + } } #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \ diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index c464c89..221f140 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -347,19 +347,22 @@ rhs_to_tree (tree type, gimple *stmt) { location_t loc = gimple_location (stmt); enum tree_code code = gimple_assign_rhs_code (stmt); - if (get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS) - return fold_build3_loc (loc, code, type, gimple_assign_rhs1 (stmt), - gimple_assign_rhs2 (stmt), - gimple_assign_rhs3 (stmt)); - else if (get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS) - return fold_build2_loc (loc, code, type, gimple_assign_rhs1 (stmt), - gimple_assign_rhs2 (stmt)); - else if (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS) - return build1 (code, type, gimple_assign_rhs1 (stmt)); - else if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS) - return gimple_assign_rhs1 (stmt); - else - gcc_unreachable (); + switch (get_gimple_rhs_class (code)) + { + case GIMPLE_TERNARY_RHS: + return fold_build3_loc (loc, code, type, gimple_assign_rhs1 (stmt), + gimple_assign_rhs2 (stmt), + gimple_assign_rhs3 (stmt)); + case GIMPLE_BINARY_RHS: + return fold_build2_loc (loc, code, type, gimple_assign_rhs1 (stmt), + gimple_assign_rhs2 (stmt)); + case GIMPLE_UNARY_RHS: + return build1 (code, type, gimple_assign_rhs1 (stmt)); + case GIMPLE_SINGLE_RHS: + return gimple_assign_rhs1 (stmt); + default: + gcc_unreachable (); + } } /* Combine OP0 CODE OP1 in the context of a COND_EXPR. Returns -- 2.7.4