diff mbox series

[COMMITTED,01/16] Make vrange an abstract class.

Message ID 20240428190557.1209586-2-aldyh@redhat.com
State New
Headers show
Series prange supporting patchset | expand

Commit Message

Aldy Hernandez April 28, 2024, 7:05 p.m. UTC
Explicitly make vrange an abstract class.  This involves fleshing out
the unsupported_range overrides which we were inheriting by default
from vrange.

gcc/ChangeLog:

	* value-range.cc (unsupported_range::accept): Move down.
 	(vrange::contains_p):  Rename to...
	(unsupported_range::contains_p): ...this.
	(vrange::singleton_p): Rename to...
	(unsupported_range::singleton_p): ...this.
	(vrange::set): Rename to...
	(unsupported_range::set): ...this.
	(vrange::type): Rename to...
	(unsupported_range::type): ...this.
	(vrange::supports_type_p): Rename to...
	(unsupported_range::supports_type_p): ...this.
	(vrange::set_undefined): Rename to...
	(unsupported_range::set_undefined): ...this.
	(vrange::set_varying): Rename to...
	(unsupported_range::set_varying): ...this.
	(vrange::union_): Rename to...
	(unsupported_range::union_): ...this.
	(vrange::intersect): Rename to...
	(unsupported_range::intersect): ...this.
	(vrange::zero_p): Rename to...
	(unsupported_range::zero_p): ...this.
	(vrange::nonzero_p): Rename to...
	(unsupported_range::nonzero_p): ...this.
	(vrange::set_nonzero): Rename to...
	(unsupported_range::set_nonzero): ...this.
	(vrange::set_zero): Rename to...
	(unsupported_range::set_zero): ...this.
	(vrange::set_nonnegative): Rename to...
	(unsupported_range::set_nonnegative): ...this.
	(vrange::fits_p): Rename to...
	(unsupported_range::fits_p): ...this.
	(unsupported_range::operator=): New.
	(frange::fits_p): New.
	* value-range.h (class vrange): Make an abstract class.
	(class unsupported_range): Declare override methods.
---
 gcc/value-range.cc | 62 ++++++++++++++++++++++++++++++----------------
 gcc/value-range.h  | 53 ++++++++++++++++++++++++---------------
 2 files changed, 73 insertions(+), 42 deletions(-)
diff mbox series

Patch

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 70375f7abf9..632d77305cc 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -37,12 +37,6 @@  irange::accept (const vrange_visitor &v) const
   v.visit (*this);
 }
 
-void
-unsupported_range::accept (const vrange_visitor &v) const
-{
-  v.visit (*this);
-}
-
 // Convenience function only available for integers and pointers.
 
 wide_int
@@ -86,52 +80,58 @@  debug (const irange_bitmask &bm)
   fprintf (stderr, "\n");
 }
 
-// Default vrange definitions.
+// Definitions for unsupported_range.
+
+void
+unsupported_range::accept (const vrange_visitor &v) const
+{
+  v.visit (*this);
+}
 
 bool
-vrange::contains_p (tree) const
+unsupported_range::contains_p (tree) const
 {
   return varying_p ();
 }
 
 bool
-vrange::singleton_p (tree *) const
+unsupported_range::singleton_p (tree *) const
 {
   return false;
 }
 
 void
-vrange::set (tree min, tree, value_range_kind)
+unsupported_range::set (tree min, tree, value_range_kind)
 {
   set_varying (TREE_TYPE (min));
 }
 
 tree
-vrange::type () const
+unsupported_range::type () const
 {
   return void_type_node;
 }
 
 bool
-vrange::supports_type_p (const_tree) const
+unsupported_range::supports_type_p (const_tree) const
 {
   return false;
 }
 
 void
-vrange::set_undefined ()
+unsupported_range::set_undefined ()
 {
   m_kind = VR_UNDEFINED;
 }
 
 void
-vrange::set_varying (tree)
+unsupported_range::set_varying (tree)
 {
   m_kind = VR_VARYING;
 }
 
 bool
-vrange::union_ (const vrange &r)
+unsupported_range::union_ (const vrange &r)
 {
   if (r.undefined_p () || varying_p ())
     return false;
@@ -145,7 +145,7 @@  vrange::union_ (const vrange &r)
 }
 
 bool
-vrange::intersect (const vrange &r)
+unsupported_range::intersect (const vrange &r)
 {
   if (undefined_p () || r.varying_p ())
     return false;
@@ -164,41 +164,53 @@  vrange::intersect (const vrange &r)
 }
 
 bool
-vrange::zero_p () const
+unsupported_range::zero_p () const
 {
   return false;
 }
 
 bool
-vrange::nonzero_p () const
+unsupported_range::nonzero_p () const
 {
   return false;
 }
 
 void
-vrange::set_nonzero (tree type)
+unsupported_range::set_nonzero (tree type)
 {
   set_varying (type);
 }
 
 void
-vrange::set_zero (tree type)
+unsupported_range::set_zero (tree type)
 {
   set_varying (type);
 }
 
 void
-vrange::set_nonnegative (tree type)
+unsupported_range::set_nonnegative (tree type)
 {
   set_varying (type);
 }
 
 bool
-vrange::fits_p (const vrange &) const
+unsupported_range::fits_p (const vrange &) const
 {
   return true;
 }
 
+unsupported_range &
+unsupported_range::operator= (const vrange &r)
+{
+  if (r.undefined_p ())
+    set_undefined ();
+  else if (r.varying_p ())
+    set_varying (void_type_node);
+  else
+    gcc_unreachable ();
+  return *this;
+}
+
 // Assignment operator for generic ranges.  Copying incompatible types
 // is not allowed.
 
@@ -359,6 +371,12 @@  frange::accept (const vrange_visitor &v) const
   v.visit (*this);
 }
 
+bool
+frange::fits_p (const vrange &) const
+{
+  return true;
+}
+
 // Flush denormal endpoints to the appropriate 0.0.
 
 void
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 9531df56988..e7f61950a24 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -80,21 +80,21 @@  class GTY((user)) vrange
   friend class range_op_handler;
 public:
   virtual void accept (const class vrange_visitor &v) const = 0;
-  virtual void set (tree, tree, value_range_kind = VR_RANGE);
-  virtual tree type () const;
-  virtual bool supports_type_p (const_tree type) const;
-  virtual void set_varying (tree type);
-  virtual void set_undefined ();
-  virtual bool union_ (const vrange &);
-  virtual bool intersect (const vrange &);
-  virtual bool singleton_p (tree *result = NULL) const;
-  virtual bool contains_p (tree cst) const;
-  virtual bool zero_p () const;
-  virtual bool nonzero_p () const;
-  virtual void set_nonzero (tree type);
-  virtual void set_zero (tree type);
-  virtual void set_nonnegative (tree type);
-  virtual bool fits_p (const vrange &r) const;
+  virtual void set (tree, tree, value_range_kind = VR_RANGE) = 0;
+  virtual tree type () const = 0;
+  virtual bool supports_type_p (const_tree type) const = 0;
+  virtual void set_varying (tree type) = 0;
+  virtual void set_undefined () = 0;
+  virtual bool union_ (const vrange &) = 0;
+  virtual bool intersect (const vrange &) = 0;
+  virtual bool singleton_p (tree *result = NULL) const = 0;
+  virtual bool contains_p (tree cst) const = 0;
+  virtual bool zero_p () const = 0;
+  virtual bool nonzero_p () const = 0;
+  virtual void set_nonzero (tree type) = 0;
+  virtual void set_zero (tree type) = 0;
+  virtual void set_nonnegative (tree type) = 0;
+  virtual bool fits_p (const vrange &r) const = 0;
 
   bool varying_p () const;
   bool undefined_p () const;
@@ -401,11 +401,23 @@  public:
   {
     set_undefined ();
   }
-  virtual void set_undefined () final override
-  {
-    m_kind = VR_UNDEFINED;
-  }
-  virtual void accept (const vrange_visitor &v) const override;
+  void set (tree min, tree, value_range_kind = VR_RANGE) final override;
+  tree type () const final override;
+  bool supports_type_p (const_tree) const final override;
+  void set_varying (tree) final override;
+  void set_undefined () final override;
+  void accept (const vrange_visitor &v) const final override;
+  bool union_ (const vrange &r) final override;
+  bool intersect (const vrange &r) final override;
+  bool singleton_p (tree * = NULL) const final override;
+  bool contains_p (tree) const final override;
+  bool zero_p () const final override;
+  bool nonzero_p () const final override;
+  void set_nonzero (tree type) final override;
+  void set_zero (tree type) final override;
+  void set_nonnegative (tree type) final override;
+  bool fits_p (const vrange &) const final override;
+  unsupported_range& operator= (const vrange &r);
 };
 
 // The NAN state as an opaque object.
@@ -507,6 +519,7 @@  public:
   virtual void set_nonzero (tree type) override;
   virtual void set_zero (tree type) override;
   virtual void set_nonnegative (tree type) override;
+  virtual bool fits_p (const vrange &) const override;
   frange& operator= (const frange &);
   bool operator== (const frange &) const;
   bool operator!= (const frange &r) const { return !(*this == r); }