Re: Fix gimple_expr_code?
authorAndrew MacLeod <amacleod@redhat.com>
Fri, 13 Nov 2020 18:56:01 +0000 (13:56 -0500)
committerAndrew MacLeod <amacleod@redhat.com>
Fri, 13 Nov 2020 18:59:44 +0000 (13:59 -0500)
have gimple_expr_code return the correct code for GIMPLE_ASSIGN.
use gassign and gcond in gimple_range_handler.

* gimple-range.h (gimple_range_handler): Cast to gimple stmt
kinds before asking for code and type.
* gimple.h (gimple_expr_code): Call gassign and gcond routines
to get their expr_code.

gcc/gimple-range.h
gcc/gimple.h

index dde41e9e743769fc1432701b7a3f7a133883e395..92bb5305c18df12b9065184cbefc39f560059881 100644 (file)
@@ -97,12 +97,12 @@ extern bool gimple_range_calc_op2 (irange &r, const gimple *s,
 static inline range_operator *
 gimple_range_handler (const gimple *s)
 {
-  if (gimple_code (s) == GIMPLE_ASSIGN)
-    return range_op_handler (gimple_assign_rhs_code (s),
-                            TREE_TYPE (gimple_assign_lhs (s)));
-  if (gimple_code (s) == GIMPLE_COND)
-    return range_op_handler (gimple_cond_code (s),
-                            TREE_TYPE (gimple_cond_lhs (s)));
+  if (const gassign *ass = dyn_cast<const gassign *> (s))
+    return range_op_handler (gimple_assign_rhs_code (ass),
+                            TREE_TYPE (gimple_assign_lhs (ass)));
+  if (const gcond *cond = dyn_cast<const gcond *> (s))
+    return range_op_handler (gimple_cond_code (cond),
+                            TREE_TYPE (gimple_cond_lhs (cond)));
   return NULL;
 }
 
index d359f7827b19f6e5caec3f0f87ec5f33daad125a..b935ad4f7614d6e4b78c6e2f8322b338551ed635 100644 (file)
@@ -2229,26 +2229,6 @@ gimple_set_modified (gimple *s, bool modifiedp)
 }
 
 
-/* Return the tree code for the expression computed by STMT.  This is
-   only valid for GIMPLE_COND, GIMPLE_CALL and GIMPLE_ASSIGN.  For
-   GIMPLE_CALL, return CALL_EXPR as the expression code for
-   consistency.  This is useful when the caller needs to deal with the
-   three kinds of computation that GIMPLE supports.  */
-
-static inline enum tree_code
-gimple_expr_code (const gimple *stmt)
-{
-  enum gimple_code code = gimple_code (stmt);
-  if (code == GIMPLE_ASSIGN || code == GIMPLE_COND)
-    return (enum tree_code) stmt->subcode;
-  else
-    {
-      gcc_gimple_checking_assert (code == GIMPLE_CALL);
-      return CALL_EXPR;
-    }
-}
-
-
 /* Return true if statement STMT contains volatile operands.  */
 
 static inline bool
@@ -3793,6 +3773,28 @@ gimple_cond_set_condition (gcond *stmt, enum tree_code code, tree lhs,
   gimple_cond_set_rhs (stmt, rhs);
 }
 
+
+/* Return the tree code for the expression computed by STMT.  This is
+   only valid for GIMPLE_COND, GIMPLE_CALL and GIMPLE_ASSIGN.  For
+   GIMPLE_CALL, return CALL_EXPR as the expression code for
+   consistency.  This is useful when the caller needs to deal with the
+   three kinds of computation that GIMPLE supports.  */
+
+static inline enum tree_code
+gimple_expr_code (const gimple *stmt)
+{
+  if (const gassign *ass = dyn_cast<const gassign *> (stmt))
+    return gimple_assign_rhs_code (ass);
+  if (const gcond *cond = dyn_cast<const gcond *> (stmt))
+    return gimple_cond_code (cond);
+  else
+    {
+      gcc_gimple_checking_assert (gimple_code (stmt) == GIMPLE_CALL);
+      return CALL_EXPR;
+    }
+}
+
+
 /* Return the LABEL_DECL node used by GIMPLE_LABEL statement GS.  */
 
 static inline tree