]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Adjust range_op_handler to store the handler directly.
authorAndrew MacLeod <amacleod@redhat.com>
Wed, 31 Aug 2022 18:07:13 +0000 (14:07 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Thu, 22 Sep 2022 18:14:34 +0000 (14:14 -0400)
Range_op_handler currently stores a tree code and a type.  It defers
checking to see if there is a valid handler until asked.
This change checks at constuctor time and store a pointer to
the handler if there is one.

* range-op.cc (range_op_handler::set_op_handler): Set new fields.
(ange_op_handler::range_op_handler): Likewise.
(range_op_handler::operator bool): Remove.
(range_op_handler::fold_range): Use appropriate handler.
(range_op_handler::op1_range): Likewise.
(range_op_handler::op2_range): Likewise.
(range_op_handler::lhs_op1_relation): Likewise.
(range_op_handler::lhs_op2_relation): Likewise.
(range_op_handler::op1_op2_relation): Likewise.
* range-op.h (class range_op_handler): Store handler pointers.
(range_op_handler:: operator bool): Inline.

gcc/range-op.cc
gcc/range-op.h

index 806edf1012ea2764ba89715689d54734c10a5993..f642b3f26de89247d910efa84ab4ed9038f0aa19 100644 (file)
@@ -4159,48 +4159,63 @@ get_float_handler (enum tree_code code, tree)
   return (*floating_tree_table)[code];
 }
 
+void
+range_op_handler::set_op_handler (tree_code code, tree type)
+{
+  if (irange::supports_p (type))
+    {
+      m_float = NULL;
+      m_int = get_handler (code, type);
+      m_valid = m_int != NULL;
+    }
+  else if (frange::supports_p (type))
+    {
+      m_int = NULL;
+      m_float = get_float_handler (code, type);
+      m_valid = m_float != NULL;
+    }
+  else
+    {
+      m_int = NULL;
+      m_float = NULL;
+      m_valid = false;
+    }
+}
+
 range_op_handler::range_op_handler (tree_code code, tree type)
-  : m_code (code), m_type (type)
 {
+  set_op_handler (code, type);
 }
 
 range_op_handler::range_op_handler (const gimple *s)
 {
+  tree_code code = NOP_EXPR;
+  tree type = NULL_TREE;
+
   if (const gassign *ass = dyn_cast<const gassign *> (s))
     {
-      m_code = gimple_assign_rhs_code (ass);
+      code = gimple_assign_rhs_code (ass);
       // The LHS of a comparison is always an int, so we must look at
       // the operands.
-      if (TREE_CODE_CLASS (m_code) == tcc_comparison)
-       m_type = TREE_TYPE (gimple_assign_rhs1 (ass));
+      if (TREE_CODE_CLASS (code) == tcc_comparison)
+       type = TREE_TYPE (gimple_assign_rhs1 (ass));
       else
-       m_type = TREE_TYPE (gimple_assign_lhs (ass));
+       type = TREE_TYPE (gimple_assign_lhs (ass));
     }
   else if (const gcond *cond = dyn_cast<const gcond *> (s))
     {
-      m_code = gimple_cond_code (cond);
-      m_type = TREE_TYPE (gimple_cond_lhs (cond));
+      code = gimple_cond_code (cond);
+      type = TREE_TYPE (gimple_cond_lhs (cond));
     }
-  else
+
+  if (!type)
     {
-      // A null type means there is no handler for this combination,
-      // but the decision whether there is one or not, is delayed
-      // until operator bool below is queried.
-      m_code = NOP_EXPR;
-      m_type = nullptr;
+      m_int = NULL;
+      m_float = NULL;
+      m_valid = false;
     }
-}
-
-// Return TRUE if there is a handler available for the current
-// combination of tree_code and type.
-
-range_op_handler::operator bool () const
-{
-  if (!m_type)
-    return false;
-  if (frange::supports_p (m_type))
-    return get_float_handler (m_code, m_type);
-  return get_handler (m_code, m_type);
+  else
+    set_op_handler (code, type);
 }
 
 bool
@@ -4209,26 +4224,19 @@ range_op_handler::fold_range (vrange &r, tree type,
                              const vrange &rh,
                              relation_kind rel) const
 {
-  if (irange::supports_p (m_type))
-    {
-      range_operator *op = get_handler (m_code, m_type);
-      return op->fold_range (as_a <irange> (r), type,
-                            as_a <irange> (lh),
-                            as_a <irange> (rh), rel);
-    }
-  if (frange::supports_p (m_type))
-    {
-      range_operator_float *op = get_float_handler (m_code, m_type);
-      if (is_a <irange> (r))
-       return op->fold_range (as_a <irange> (r), type,
-                              as_a <frange> (lh),
-                              as_a <frange> (rh), rel);
-      return op->fold_range (as_a <frange> (r), type,
-                            as_a <frange> (lh),
-                            as_a <frange> (rh), rel);
-    }
-  gcc_unreachable ();
-  return false;
+  gcc_checking_assert (m_valid);
+  if (m_int)
+    return m_int->fold_range (as_a <irange> (r), type,
+                          as_a <irange> (lh),
+                          as_a <irange> (rh), rel);
+
+  if (is_a <irange> (r))
+    return m_float->fold_range (as_a <irange> (r), type,
+                               as_a <frange> (lh),
+                               as_a <frange> (rh), rel);
+  return m_float->fold_range (as_a <frange> (r), type,
+                             as_a <frange> (lh),
+                             as_a <frange> (rh), rel);
 }
 
 bool
@@ -4237,26 +4245,19 @@ range_op_handler::op1_range (vrange &r, tree type,
                             const vrange &op2,
                             relation_kind rel) const
 {
-  if (irange::supports_p (m_type))
-    {
-      range_operator *op = get_handler (m_code, m_type);
-      return op->op1_range (as_a <irange> (r), type,
-                           as_a <irange> (lhs),
-                           as_a <irange> (op2), rel);
-    }
-  if (frange::supports_p (m_type))
-    {
-      range_operator_float *op = get_float_handler (m_code, m_type);
-      if (is_a <irange> (lhs))
-       return op->op1_range (as_a <frange> (r), type,
-                             as_a <irange> (lhs),
-                             as_a <frange> (op2), rel);
-      return op->op1_range (as_a <frange> (r), type,
-                           as_a <frange> (lhs),
-                           as_a <frange> (op2), rel);
-    }
-  gcc_unreachable ();
-  return false;
+  gcc_checking_assert (m_valid);
+  if (m_int)
+    return m_int->op1_range (as_a <irange> (r), type,
+                            as_a <irange> (lhs),
+                            as_a <irange> (op2), rel);
+
+  if (is_a <irange> (lhs))
+    return m_float->op1_range (as_a <frange> (r), type,
+                              as_a <irange> (lhs),
+                              as_a <frange> (op2), rel);
+  return m_float->op1_range (as_a <frange> (r), type,
+                            as_a <frange> (lhs),
+                            as_a <frange> (op2), rel);
 }
 
 bool
@@ -4265,26 +4266,19 @@ range_op_handler::op2_range (vrange &r, tree type,
                             const vrange &op1,
                             relation_kind rel) const
 {
-  if (irange::supports_p (m_type))
-    {
-      range_operator *op = get_handler (m_code, m_type);
-      return op->op2_range (as_a <irange> (r), type,
-                           as_a <irange> (lhs),
-                           as_a <irange> (op1), rel);
-    }
-  if (frange::supports_p (m_type))
-    {
-      range_operator_float *op = get_float_handler (m_code, m_type);
-      if (is_a <irange> (lhs))
-       return op->op2_range (as_a <frange> (r), type,
-                             as_a <irange> (lhs),
-                             as_a <frange> (op1), rel);
-      return op->op2_range (as_a <frange> (r), type,
-                           as_a <frange> (lhs),
-                           as_a <frange> (op1), rel);
-    }
-  gcc_unreachable ();
-  return false;
+  gcc_checking_assert (m_valid);
+  if (m_int)
+    return m_int->op2_range (as_a <irange> (r), type,
+                            as_a <irange> (lhs),
+                            as_a <irange> (op1), rel);
+
+  if (is_a <irange> (lhs))
+    return m_float->op2_range (as_a <frange> (r), type,
+                              as_a <irange> (lhs),
+                              as_a <frange> (op1), rel);
+  return m_float->op2_range (as_a <frange> (r), type,
+                            as_a <frange> (lhs),
+                            as_a <frange> (op1), rel);
 }
 
 relation_kind
@@ -4293,26 +4287,19 @@ range_op_handler::lhs_op1_relation (const vrange &lhs,
                                    const vrange &op2,
                                    relation_kind rel) const
 {
-  if (irange::supports_p (m_type))
-    {
-      range_operator *op = get_handler (m_code, m_type);
-      return op->lhs_op1_relation (as_a <irange> (lhs),
-                                  as_a <irange> (op1),
-                                  as_a <irange> (op2), rel);
-    }
-  if (frange::supports_p (m_type))
-    {
-      range_operator_float *op = get_float_handler (m_code, m_type);
-      if (is_a <irange> (lhs))
-       return op->lhs_op1_relation (as_a <irange> (lhs),
-                                    as_a <frange> (op1),
-                                    as_a <frange> (op2), rel);
-      return op->lhs_op1_relation (as_a <frange> (lhs),
-                                  as_a <frange> (op1),
-                                  as_a <frange> (op2), rel);
-    }
-  gcc_unreachable ();
-  return VREL_VARYING;
+  gcc_checking_assert (m_valid);
+  if (m_int)
+    return m_int->lhs_op1_relation (as_a <irange> (lhs),
+                                   as_a <irange> (op1),
+                                   as_a <irange> (op2), rel);
+
+  if (is_a <irange> (lhs))
+    return m_float->lhs_op1_relation (as_a <irange> (lhs),
+                                as_a <frange> (op1),
+                                as_a <frange> (op2), rel);
+  return m_float->lhs_op1_relation (as_a <frange> (lhs),
+                              as_a <frange> (op1),
+                              as_a <frange> (op2), rel);
 }
 
 relation_kind
@@ -4321,43 +4308,28 @@ range_op_handler::lhs_op2_relation (const vrange &lhs,
                                    const vrange &op2,
                                    relation_kind rel) const
 {
-  if (irange::supports_p (m_type))
-    {
-      range_operator *op = get_handler (m_code, m_type);
-      return op->lhs_op2_relation (as_a <irange> (lhs),
-                                  as_a <irange> (op1),
-                                  as_a <irange> (op2), rel);
-    }
-  if (frange::supports_p (m_type))
-    {
-      range_operator_float *op = get_float_handler (m_code, m_type);
-      if (is_a <irange> (lhs))
-       return op->lhs_op2_relation (as_a <irange> (lhs),
-                                    as_a <frange> (op1),
-                                    as_a <frange> (op2), rel);
-      return op->lhs_op2_relation (as_a <frange> (lhs),
-                                  as_a <frange> (op1),
-                                  as_a <frange> (op2), rel);
-    }
-  gcc_unreachable ();
-  return VREL_VARYING;
+  gcc_checking_assert (m_valid);
+  if (m_int)
+    return m_int->lhs_op2_relation (as_a <irange> (lhs),
+                                   as_a <irange> (op1),
+                                   as_a <irange> (op2), rel);
+
+  if (is_a <irange> (lhs))
+    return m_float->lhs_op2_relation (as_a <irange> (lhs),
+                                     as_a <frange> (op1),
+                                     as_a <frange> (op2), rel);
+  return m_float->lhs_op2_relation (as_a <frange> (lhs),
+                                     as_a <frange> (op1),
+                                     as_a <frange> (op2), rel);
 }
 
 relation_kind
 range_op_handler::op1_op2_relation (const vrange &lhs) const
 {
-  if (irange::supports_p (m_type))
-    {
-      range_operator *op = get_handler (m_code, m_type);
-      return op->op1_op2_relation (as_a <irange> (lhs));
-    }
-  if (frange::supports_p (m_type))
-    {
-      range_operator_float *op = get_float_handler (m_code, m_type);
-      return op->op1_op2_relation (as_a <irange> (lhs));
-    }
-  gcc_unreachable ();
-  return VREL_VARYING;
+  gcc_checking_assert (m_valid);
+  if (m_int)
+    return m_int->op1_op2_relation (as_a <irange> (lhs));
+  return m_float->op1_op2_relation (as_a <irange> (lhs));
 }
 
 // Cast the range in R to TYPE.
index 37d9aa91c460fa76b94e09566574209c2725801d..56c57c46a8e6da246d523a3a2c6d70547f55bd21 100644 (file)
@@ -162,7 +162,7 @@ class range_op_handler
 public:
   range_op_handler (enum tree_code code, tree type);
   range_op_handler (const gimple *s);
-  operator bool () const;
+  inline operator bool () const { return m_valid; }
 
   bool fold_range (vrange &r, tree type,
                   const vrange &lh,
@@ -186,8 +186,10 @@ public:
                                  relation_kind = VREL_VARYING) const;
   relation_kind op1_op2_relation (const vrange &lhs) const;
 private:
-  enum tree_code m_code;
-  tree m_type;
+  void set_op_handler (enum tree_code code, tree type);
+  bool m_valid;
+  range_operator *m_int;
+  range_operator_float *m_float;
 };
 
 extern bool range_cast (vrange &, tree type);