]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use more switch statements.
authorMartin Liska <mliska@suse.cz>
Tue, 24 Sep 2019 11:38:29 +0000 (13:38 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 24 Sep 2019 11:38:29 +0000 (11:38 +0000)
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

gcc/ChangeLog
gcc/cfgexpand.c
gcc/gimple-expr.c
gcc/gimple.c
gcc/tree-ssa-forwprop.c

index a44f4dbe44946b032d5b90ba308cd1b9f24e3681..1c4c016f46fb23d1444475c94ced8b43f1afe394 100644 (file)
@@ -1,3 +1,11 @@
+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>
 
        PR ipa/91831
index 5a93447f520f1ea8b739249bfdfec56775c91f79..a2f96239e2fee4d877e404fc9d317857de7bd67d 100644 (file)
@@ -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));
index b0c9f9b671ac2d7028da30d151611c5a56a6456a..4082828e1987330db4682c9b4d67c4051beaad4d 100644 (file)
@@ -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.  */
index 88250cad16b5fd5462818120af8b4f9180604102..af62c8bf47740a449f7e4e304245d76d315c411e 100644 (file)
@@ -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)                              \
index c464c8995861022d6c553249751f678ebdf521df..221f140b356fc9792525882ec1e27d04fe240edf 100644 (file)
@@ -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