[gcc r12-1301] analyzer: split out struct bit_range from class concrete_binding

David Malcolm dmalcolm@gcc.gnu.org
Tue Jun 8 18:44:34 GMT 2021


https://gcc.gnu.org/g:6b400aef1bdc84bbdf5011caff3fe5f82c68d253

commit r12-1301-g6b400aef1bdc84bbdf5011caff3fe5f82c68d253
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Tue Jun 8 14:43:48 2021 -0400

    analyzer: split out struct bit_range from class concrete_binding
    
    gcc/analyzer/ChangeLog:
            * store.cc (concrete_binding::dump_to_pp): Move bulk of
            implementation to...
            (bit_range::dump_to_pp): ...this new function.
            (bit_range::cmp): New.
            (concrete_binding::overlaps_p): Update for use of bit_range.
            (concrete_binding::cmp_ptr_ptr): Likewise.
            * store.h (struct bit_range): New.
            (class concrete_binding): Replace fields m_start_bit_offset and
            m_size_in_bits with new field m_bit_range.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/store.cc | 38 ++++++++++++++++++++++----------
 gcc/analyzer/store.h  | 61 +++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 77 insertions(+), 22 deletions(-)

diff --git a/gcc/analyzer/store.cc b/gcc/analyzer/store.cc
index b1874a5a2d3..f4bb7def781 100644
--- a/gcc/analyzer/store.cc
+++ b/gcc/analyzer/store.cc
@@ -236,15 +236,12 @@ binding_key::cmp (const binding_key *k1, const binding_key *k2)
     }
 }
 
-/* class concrete_binding : public binding_key.  */
-
-/* Implementation of binding_key::dump_to_pp vfunc for concrete_binding.  */
+/* struct struct bit_range.  */
 
 void
-concrete_binding::dump_to_pp (pretty_printer *pp, bool simple) const
+bit_range::dump_to_pp (pretty_printer *pp) const
 {
-  binding_key::dump_to_pp (pp, simple);
-  pp_string (pp, ", start: ");
+  pp_string (pp, "start: ");
   pp_wide_int (pp, m_start_bit_offset, SIGNED);
   pp_string (pp, ", size: ");
   pp_wide_int (pp, m_size_in_bits, SIGNED);
@@ -252,12 +249,34 @@ concrete_binding::dump_to_pp (pretty_printer *pp, bool simple) const
   pp_wide_int (pp, get_next_bit_offset (), SIGNED);
 }
 
+int
+bit_range::cmp (const bit_range &br1, const bit_range &br2)
+{
+  if (int start_cmp = wi::cmps (br1.m_start_bit_offset,
+				br2.m_start_bit_offset))
+    return start_cmp;
+
+  return wi::cmpu (br1.m_size_in_bits, br2.m_size_in_bits);
+}
+
+/* class concrete_binding : public binding_key.  */
+
+/* Implementation of binding_key::dump_to_pp vfunc for concrete_binding.  */
+
+void
+concrete_binding::dump_to_pp (pretty_printer *pp, bool simple) const
+{
+  binding_key::dump_to_pp (pp, simple);
+  pp_string (pp, ", ");
+  m_bit_range.dump_to_pp (pp);
+}
+
 /* Return true if this binding overlaps with OTHER.  */
 
 bool
 concrete_binding::overlaps_p (const concrete_binding &other) const
 {
-  if (m_start_bit_offset < other.get_next_bit_offset ()
+  if (get_start_bit_offset () < other.get_next_bit_offset ()
       && get_next_bit_offset () > other.get_start_bit_offset ())
     return true;
   return false;
@@ -274,10 +293,7 @@ concrete_binding::cmp_ptr_ptr (const void *p1, const void *p2)
   if (int kind_cmp = b1->get_kind () - b2->get_kind ())
     return kind_cmp;
 
-  if (int start_cmp = wi::cmps (b1->m_start_bit_offset, b2->m_start_bit_offset))
-    return start_cmp;
-
-  return wi::cmpu (b1->m_size_in_bits, b2->m_size_in_bits);
+  return bit_range::cmp (b1->m_bit_range, b2->m_bit_range);
 }
 
 /* class symbolic_binding : public binding_key.  */
diff --git a/gcc/analyzer/store.h b/gcc/analyzer/store.h
index d68513ca94c..be09b427366 100644
--- a/gcc/analyzer/store.h
+++ b/gcc/analyzer/store.h
@@ -267,6 +267,42 @@ private:
   enum binding_kind m_kind;
 };
 
+struct bit_range
+{
+  bit_range (bit_offset_t start_bit_offset, bit_size_t size_in_bits)
+  : m_start_bit_offset (start_bit_offset),
+    m_size_in_bits (size_in_bits)
+  {}
+
+  void dump_to_pp (pretty_printer *pp) const;
+
+  bit_offset_t get_start_bit_offset () const
+  {
+    return m_start_bit_offset;
+  }
+  bit_offset_t get_next_bit_offset () const
+  {
+    return m_start_bit_offset + m_size_in_bits;
+  }
+
+  bool contains_p (bit_offset_t offset) const
+  {
+    return (offset >= get_start_bit_offset ()
+	    && offset < get_next_bit_offset ());
+  }
+
+  bool operator== (const bit_range &other) const
+  {
+    return (m_start_bit_offset == other.m_start_bit_offset
+	    && m_size_in_bits == other.m_size_in_bits);
+  }
+
+  static int cmp (const bit_range &br1, const bit_range &br2);
+
+  bit_offset_t m_start_bit_offset;
+  bit_size_t m_size_in_bits;
+};
+
 /* Concrete subclass of binding_key, for describing a concrete range of
    bits within the binding_map (e.g. "bits 8-15").  */
 
@@ -279,24 +315,22 @@ public:
   concrete_binding (bit_offset_t start_bit_offset, bit_size_t size_in_bits,
 		    enum binding_kind kind)
   : binding_key (kind),
-    m_start_bit_offset (start_bit_offset),
-    m_size_in_bits (size_in_bits)
+    m_bit_range (start_bit_offset, size_in_bits)
   {}
   bool concrete_p () const FINAL OVERRIDE { return true; }
 
   hashval_t hash () const
   {
     inchash::hash hstate;
-    hstate.add_wide_int (m_start_bit_offset);
-    hstate.add_wide_int (m_size_in_bits);
+    hstate.add_wide_int (m_bit_range.m_start_bit_offset);
+    hstate.add_wide_int (m_bit_range.m_size_in_bits);
     return hstate.end () ^ binding_key::impl_hash ();
   }
   bool operator== (const concrete_binding &other) const
   {
     if (!binding_key::impl_eq (other))
       return false;
-    return (m_start_bit_offset == other.m_start_bit_offset
-	    && m_size_in_bits == other.m_size_in_bits);
+    return m_bit_range == other.m_bit_range;
   }
 
   void dump_to_pp (pretty_printer *pp, bool simple) const FINAL OVERRIDE;
@@ -304,12 +338,18 @@ public:
   const concrete_binding *dyn_cast_concrete_binding () const FINAL OVERRIDE
   { return this; }
 
-  bit_offset_t get_start_bit_offset () const { return m_start_bit_offset; }
-  bit_size_t get_size_in_bits () const { return m_size_in_bits; }
+  bit_offset_t get_start_bit_offset () const
+  {
+    return m_bit_range.m_start_bit_offset;
+  }
+  bit_size_t get_size_in_bits () const
+  {
+    return m_bit_range.m_size_in_bits;
+  }
   /* Return the next bit offset after the end of this binding.  */
   bit_offset_t get_next_bit_offset () const
   {
-    return m_start_bit_offset + m_size_in_bits;
+    return m_bit_range.get_next_bit_offset ();
   }
 
   bool overlaps_p (const concrete_binding &other) const;
@@ -317,8 +357,7 @@ public:
   static int cmp_ptr_ptr (const void *, const void *);
 
 private:
-  bit_offset_t m_start_bit_offset;
-  bit_size_t m_size_in_bits;
+  bit_range m_bit_range;
 };
 
 } // namespace ana


More information about the Gcc-cvs mailing list