public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED 04/23] Add storage support for prange.
Date: Sat,  4 May 2024 10:30:32 +0200	[thread overview]
Message-ID: <20240504083056.139719-5-aldyh@redhat.com> (raw)
In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com>

gcc/ChangeLog:

	* value-range-storage.cc (vrange_allocator::clone_varying): Add
	prange support.
	(vrange_allocator::clone_undefined): Same.
	(vrange_storage::alloc): Same.
	(vrange_storage::set_vrange): Same.
	(vrange_storage::get_vrange): Same.
	(vrange_storage::fits_p): Same.
	(vrange_storage::equal_p): Same.
	(prange_storage::alloc): New.
	(prange_storage::prange_storage): New.
	(prange_storage::set_prange): New.
	(prange_storage::get_prange): New.
	(prange_storage::equal_p): New.
	(prange_storage::fits_p): New.
	* value-range-storage.h (class prange_storage): Add prange support.
---
 gcc/value-range-storage.cc | 117 +++++++++++++++++++++++++++++++++++++
 gcc/value-range-storage.h  |  33 +++++++++++
 2 files changed, 150 insertions(+)

diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc
index 09a29776a0e..bbae0da4772 100644
--- a/gcc/value-range-storage.cc
+++ b/gcc/value-range-storage.cc
@@ -118,6 +118,8 @@ vrange_allocator::clone_varying (tree type)
 {
   if (irange::supports_p (type))
     return irange_storage::alloc (*m_alloc, int_range <1> (type));
+  if (prange::supports_p (type))
+    return prange_storage::alloc (*m_alloc, prange (type));
   if (frange::supports_p (type))
     return frange_storage::alloc (*m_alloc, frange (type));
   return NULL;
@@ -128,6 +130,8 @@ vrange_allocator::clone_undefined (tree type)
 {
   if (irange::supports_p (type))
     return irange_storage::alloc (*m_alloc, int_range<1> ());
+  if (prange::supports_p (type))
+    return prange_storage::alloc (*m_alloc, prange ());
   if (frange::supports_p (type))
     return frange_storage::alloc  (*m_alloc, frange ());
   return NULL;
@@ -141,6 +145,8 @@ vrange_storage::alloc (vrange_internal_alloc &allocator, const vrange &r)
 {
   if (is_a <irange> (r))
     return irange_storage::alloc (allocator, as_a <irange> (r));
+  if (is_a <prange> (r))
+    return prange_storage::alloc (allocator, as_a <prange> (r));
   if (is_a <frange> (r))
     return frange_storage::alloc (allocator, as_a <frange> (r));
   return NULL;
@@ -157,6 +163,12 @@ vrange_storage::set_vrange (const vrange &r)
       gcc_checking_assert (s->fits_p (as_a <irange> (r)));
       s->set_irange (as_a <irange> (r));
     }
+  else if (is_a <prange> (r))
+    {
+      prange_storage *s = static_cast <prange_storage *> (this);
+      gcc_checking_assert (s->fits_p (as_a <prange> (r)));
+      s->set_prange (as_a <prange> (r));
+    }
   else if (is_a <frange> (r))
     {
       frange_storage *s = static_cast <frange_storage *> (this);
@@ -190,6 +202,11 @@ vrange_storage::get_vrange (vrange &r, tree type) const
       const irange_storage *s = static_cast <const irange_storage *> (this);
       s->get_irange (as_a <irange> (r), type);
     }
+  else if (is_a <prange> (r))
+    {
+      const prange_storage *s = static_cast <const prange_storage *> (this);
+      s->get_prange (as_a <prange> (r), type);
+    }
   else if (is_a <frange> (r))
     {
       const frange_storage *s = static_cast <const frange_storage *> (this);
@@ -209,6 +226,11 @@ vrange_storage::fits_p (const vrange &r) const
       const irange_storage *s = static_cast <const irange_storage *> (this);
       return s->fits_p (as_a <irange> (r));
     }
+  if (is_a <prange> (r))
+    {
+      const prange_storage *s = static_cast <const prange_storage *> (this);
+      return s->fits_p (as_a <prange> (r));
+    }
   if (is_a <frange> (r))
     {
       const frange_storage *s = static_cast <const frange_storage *> (this);
@@ -230,6 +252,11 @@ vrange_storage::equal_p (const vrange &r) const
       const irange_storage *s = static_cast <const irange_storage *> (this);
       return s->equal_p (as_a <irange> (r));
     }
+  if (is_a <prange> (r))
+    {
+      const prange_storage *s = static_cast <const prange_storage *> (this);
+      return s->equal_p (as_a <prange> (r));
+    }
   if (is_a <frange> (r))
     {
       const frange_storage *s = static_cast <const frange_storage *> (this);
@@ -559,6 +586,96 @@ frange_storage::fits_p (const frange &) const
   return true;
 }
 
+//============================================================================
+// prange_storage implementation
+//============================================================================
+
+prange_storage *
+prange_storage::alloc (vrange_internal_alloc &allocator, const prange &r)
+{
+  // Assume all pointers are the same size.
+  unsigned prec = TYPE_PRECISION (TREE_TYPE (null_pointer_node));
+  gcc_checking_assert (r.undefined_p () || TYPE_PRECISION (r.type ()) == prec);
+
+  typedef trailing_wide_ints<NINTS> twi;
+  size_t size = sizeof (prange_storage) + twi::extra_size (prec);
+  prange_storage *p = static_cast <prange_storage *> (allocator.alloc (size));
+  new (p) prange_storage (r);
+  return p;
+}
+
+// Initialize the storage with R.
+
+prange_storage::prange_storage (const prange &r)
+{
+  // It is the caller's responsibility to allocate enough space such
+  // that the precision fits.
+  unsigned prec = TYPE_PRECISION (TREE_TYPE (null_pointer_node));
+  m_trailing_ints.set_precision (prec);
+
+  set_prange (r);
+}
+
+void
+prange_storage::set_prange (const prange &r)
+{
+  if (r.undefined_p ())
+    m_kind = VR_UNDEFINED;
+  else if (r.varying_p ())
+    m_kind = VR_VARYING;
+  else
+    {
+      m_kind = VR_RANGE;
+      set_low (r.lower_bound ());
+      set_high (r.upper_bound ());
+      irange_bitmask bm = r.m_bitmask;
+      set_value (bm.value ());
+      set_mask (bm.mask ());
+    }
+}
+
+void
+prange_storage::get_prange (prange &r, tree type) const
+{
+  gcc_checking_assert (r.supports_type_p (type));
+
+  if (m_kind == VR_UNDEFINED)
+    r.set_undefined ();
+  else if (m_kind == VR_VARYING)
+    r.set_varying (type);
+  else
+    {
+      gcc_checking_assert (m_kind == VR_RANGE);
+      gcc_checking_assert (TYPE_PRECISION (type) == m_trailing_ints.get_precision ());
+      r.m_kind = VR_RANGE;
+      r.m_type = type;
+      r.m_min = get_low ();
+      r.m_max = get_high ();
+      r.m_bitmask = irange_bitmask (get_value (), get_mask ());
+      if (flag_checking)
+	r.verify_range ();
+    }
+}
+
+bool
+prange_storage::equal_p (const prange &r) const
+{
+  if (r.undefined_p ())
+    return m_kind == VR_UNDEFINED;
+
+  prange tmp;
+  get_prange (tmp, r.type ());
+  return tmp == r;
+}
+
+bool
+prange_storage::fits_p (const prange &) const
+{
+  // All pointers are the same size.
+  return true;
+}
+
+\f
 static vrange_allocator ggc_vrange_allocator (true);
 
 vrange_storage *ggc_alloc_vrange_storage (tree type)
diff --git a/gcc/value-range-storage.h b/gcc/value-range-storage.h
index 5756de7e32d..dd6813873ea 100644
--- a/gcc/value-range-storage.h
+++ b/gcc/value-range-storage.h
@@ -98,6 +98,39 @@ private:
   irange_storage (const irange &r);
 };
 
+// Efficient memory storage for a prange.
+
+class prange_storage : public vrange_storage
+{
+public:
+  static prange_storage *alloc (vrange_internal_alloc &, const prange &);
+  void set_prange (const prange &r);
+  void get_prange (prange &r, tree type) const;
+  bool equal_p (const prange &r) const;
+  bool fits_p (const prange &r) const;
+  void dump () const;
+private:
+  DISABLE_COPY_AND_ASSIGN (prange_storage);
+  prange_storage (const prange &r);
+
+  enum value_range_kind m_kind : 3;
+
+  // We don't use TRAILING_WIDE_INT_ACCESSOR because the getters here
+  // must be const.  Perhaps TRAILING_WIDE_INT_ACCESSOR could be made
+  // const and return wide_int instead of trailing_wide_int.
+  wide_int get_low () const { return m_trailing_ints[0]; }
+  wide_int get_high () const { return m_trailing_ints[1]; }
+  wide_int get_value () const { return m_trailing_ints[2]; }
+  wide_int get_mask () const { return m_trailing_ints[3]; }
+  template <typename T> void set_low (const T &x) { m_trailing_ints[0] = x; }
+  template <typename T> void set_high (const T &x) { m_trailing_ints[1] = x; }
+  template <typename T> void set_value (const T &x) { m_trailing_ints[2] = x; }
+  template <typename T> void set_mask (const T &x) { m_trailing_ints[3] = x; }
+
+  static const unsigned int NINTS = 4;
+  trailing_wide_ints<NINTS> m_trailing_ints;
+};
+
 // Efficient memory storage for an frange.
 
 class frange_storage : public vrange_storage
-- 
2.44.0


  parent reply	other threads:[~2024-05-04  8:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-04  8:30 [PATCH 00/23] prange: pointer ranges Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 01/23] Minimal prange class showing inlining degradation to VRP Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 02/23] Implement basic prange class Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 03/23] Add streaming support for prange Aldy Hernandez
2024-05-04  8:30 ` Aldy Hernandez [this message]
2024-05-04  8:30 ` [COMMITTED 05/23] Add hashing " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 06/23] Add prange implementation for get_legacy_range Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 07/23] Implement range-op dispatch for prange Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 08/23] Implement operator_identity " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 09/23] Implement operator_cst " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 10/23] Implement operator_cast " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 11/23] Implement operator_min and operator_max " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 12/23] Implement operator_addr_expr " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 13/23] Implement pointer_plus_operator " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 14/23] Implement operator_pointer_diff " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 15/23] Implement operator_bitwise_and " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 16/23] Implement operator_bitwise_or " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 17/23] Implement operator_not_equal " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 18/23] Implement operator_equal " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 19/23] Implement operator_lt " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 20/23] Implement operator_le " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 21/23] Implement operator_gt " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 22/23] Implement operator_ge " Aldy Hernandez
2024-05-04  8:30 ` [COMMITTED 23/23] Add prange entries in gimple-range-op.cc Aldy Hernandez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240504083056.139719-5-aldyh@redhat.com \
    --to=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).