public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-2784] Adjust range_op_handler to store the handler directly.
@ 2022-09-22 18:49 Andrew Macleod
  0 siblings, 0 replies; only message in thread
From: Andrew Macleod @ 2022-09-22 18:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:24c473a14d3cbe6fc44997122b532cb9406497cb

commit r13-2784-g24c473a14d3cbe6fc44997122b532cb9406497cb
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Wed Aug 31 14:07:13 2022 -0400

    Adjust range_op_handler to store the handler directly.
    
    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.

Diff:
---
 gcc/range-op.cc | 246 +++++++++++++++++++++++++-------------------------------
 gcc/range-op.h  |   8 +-
 2 files changed, 114 insertions(+), 140 deletions(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 806edf1012e..f642b3f26de 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -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.
diff --git a/gcc/range-op.h b/gcc/range-op.h
index 37d9aa91c46..56c57c46a8e 100644
--- a/gcc/range-op.h
+++ b/gcc/range-op.h
@@ -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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-22 18:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22 18:49 [gcc r13-2784] Adjust range_op_handler to store the handler directly Andrew Macleod

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).