diff mbox series

[COMMITTED] Implement ggc_vrange_allocator.

Message ID 20220630124754.551201-1-aldyh@redhat.com
State New
Headers show
Series [COMMITTED] Implement ggc_vrange_allocator. | expand

Commit Message

Aldy Hernandez June 30, 2022, 12:47 p.m. UTC
This patch makes the vrange_allocator an abstract class, and uses it
to implement the obstack allocator as well as a new GC allocator.

The GC bits will be used to implement the vrange storage class for
global ranges, which will be contributed in the next week or so.

Tested and benchmarked on x86-64 Linux.

gcc/ChangeLog:

	* gimple-range-cache.cc (block_range_cache::block_range_cache):
	Rename vrange_allocator to obstack_vrange_allocator.
	(ssa_global_cache::ssa_global_cache): Same.
	* gimple-range-edge.h (class gimple_outgoing_range): Same.
	* gimple-range-infer.h (class infer_range_manager): Same.
	* value-range.h (class vrange_allocator): Make abstract.
	(class obstack_vrange_allocator): Inherit from vrange_allocator.
	(class ggc_vrange_allocator): New.
---
 gcc/gimple-range-cache.cc |  4 +--
 gcc/gimple-range-edge.h   |  2 +-
 gcc/gimple-range-infer.h  |  2 +-
 gcc/value-range.h         | 57 ++++++++++++++++++++++++---------------
 4 files changed, 40 insertions(+), 25 deletions(-)
diff mbox series

Patch

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 5df744184c4..5bb52d5f70f 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -320,7 +320,7 @@  block_range_cache::block_range_cache ()
   bitmap_obstack_initialize (&m_bitmaps);
   m_ssa_ranges.create (0);
   m_ssa_ranges.safe_grow_cleared (num_ssa_names);
-  m_range_allocator = new vrange_allocator;
+  m_range_allocator = new obstack_vrange_allocator;
 }
 
 // Remove any m_block_caches which have been created.
@@ -478,7 +478,7 @@  block_range_cache::dump (FILE *f, basic_block bb, bool print_varying)
 ssa_global_cache::ssa_global_cache ()
 {
   m_tab.create (0);
-  m_range_allocator = new vrange_allocator;
+  m_range_allocator = new obstack_vrange_allocator;
 }
 
 // Deconstruct a global cache.
diff --git a/gcc/gimple-range-edge.h b/gcc/gimple-range-edge.h
index a9c4af8715b..c81b943dae6 100644
--- a/gcc/gimple-range-edge.h
+++ b/gcc/gimple-range-edge.h
@@ -47,7 +47,7 @@  private:
 
   int m_max_edges;
   hash_map<edge, irange *> *m_edge_table;
-  vrange_allocator m_range_allocator;
+  obstack_vrange_allocator m_range_allocator;
 };
 
 // If there is a range control statement at the end of block BB, return it.
diff --git a/gcc/gimple-range-infer.h b/gcc/gimple-range-infer.h
index aafa8bb74f0..bf27d0d3423 100644
--- a/gcc/gimple-range-infer.h
+++ b/gcc/gimple-range-infer.h
@@ -78,7 +78,7 @@  private:
   bitmap m_seen;
   bitmap_obstack m_bitmaps;
   struct obstack m_list_obstack;
-  vrange_allocator m_range_allocator;
+  obstack_vrange_allocator m_range_allocator;
 };
 
 #endif // GCC_GIMPLE_RANGE_SIDE_H
diff --git a/gcc/value-range.h b/gcc/value-range.h
index dc6f6b0f935..627d221fe0f 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -903,39 +903,54 @@  vrp_val_min (const_tree type)
 class vrange_allocator
 {
 public:
-  vrange_allocator ();
-  ~vrange_allocator ();
+  vrange_allocator () { }
+  virtual ~vrange_allocator () { }
   // Allocate a range of TYPE.
   vrange *alloc_vrange (tree type);
   // Allocate a memory block of BYTES.
-  void *alloc (unsigned bytes);
+  virtual void *alloc (unsigned bytes) = 0;
+  virtual void free (void *p) = 0;
   // Return a clone of SRC.
   template <typename T> T *clone (const T &src);
 private:
   irange *alloc_irange (unsigned pairs);
-  DISABLE_COPY_AND_ASSIGN (vrange_allocator);
-  struct obstack m_obstack;
+  void operator= (const vrange_allocator &) = delete;
 };
 
-inline
-vrange_allocator::vrange_allocator ()
+class obstack_vrange_allocator : public vrange_allocator
 {
-  obstack_init (&m_obstack);
-}
-
-inline
-vrange_allocator::~vrange_allocator ()
-{
-  obstack_free (&m_obstack, NULL);
-}
-
-// Provide a hunk of memory from the obstack.
+public:
+  obstack_vrange_allocator ()
+  {
+    obstack_init (&m_obstack);
+  }
+  virtual ~obstack_vrange_allocator () final override
+  {
+    obstack_free (&m_obstack, NULL);
+  }
+  virtual void *alloc (unsigned bytes) final override
+  {
+    return obstack_alloc (&m_obstack, bytes);
+  }
+  virtual void free (void *) final override { }
+private:
+  obstack m_obstack;
+};
 
-inline void *
-vrange_allocator::alloc (unsigned bytes)
+class ggc_vrange_allocator : public vrange_allocator
 {
-  return obstack_alloc (&m_obstack, bytes);
-}
+public:
+  ggc_vrange_allocator () { }
+  virtual ~ggc_vrange_allocator () final override { }
+  virtual void *alloc (unsigned bytes) final override
+  {
+    return ggc_internal_alloc (bytes);
+  }
+  virtual void free (void *p) final override
+  {
+    return ggc_free (p);
+  }
+};
 
 // Return a new range to hold ranges of TYPE.  The newly allocated
 // range is initialized to VR_UNDEFINED.