From e681eff479ddcde883a95444d986449055834d1b Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 16 Aug 2019 11:51:03 -0400
Subject: [PATCH 80/96] FIXME: use pool_allocator in more places

---
 gcc/analyzer/region-model.cc | 191 +++++++++++++++++++++++++++++++++++++++++++
 gcc/analyzer/region-model.h  |  30 +++++++
 2 files changed, 221 insertions(+)

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index 532a086..2400252 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -62,6 +62,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "analyzer/region-model.h"
 #include "tree-diagnostic.h"
 #include "diagnostic-color.h"
+#include "alloc-pool.h"
 #include "analyzer/constraint-manager.h"
 #include "analyzer/pending-diagnostic.h"
 
@@ -320,6 +321,25 @@ svalue::walk_for_canonicalization (canonicalization *) const
 
 /* class region_svalue : public svalue.  */
 
+/* FIXME.  */
+static pool_allocator region_svalue_pool ("region_svalue", sizeof (region_svalue));
+
+/* FIXME.  */
+void *
+region_svalue::operator new (size_t sz)
+{
+  gcc_assert (sz == sizeof (region_svalue));
+  return region_svalue_pool.allocate ();
+}
+
+/* FIXME.  */
+void
+region_svalue::operator delete (void* ptr, size_t sz)
+{
+  gcc_assert (sz == sizeof (region_svalue));
+  region_svalue_pool.remove (ptr);
+}
+
 /* Compare the fields of this region_svalue with OTHER, returning true
    if they are equal.
    For use by svalue::operator==.  */
@@ -618,6 +638,25 @@ region_svalue::eval_condition (region_svalue *lhs,
 
 /* class constant_svalue : public svalue.  */
 
+/* FIXME.  */
+static pool_allocator constant_svalue_pool ("constant_svalue", sizeof (constant_svalue));
+
+/* FIXME.  */
+void *
+constant_svalue::operator new (size_t sz)
+{
+  gcc_assert (sz == sizeof (constant_svalue));
+  return constant_svalue_pool.allocate ();
+}
+
+/* FIXME.  */
+void
+constant_svalue::operator delete (void* ptr, size_t sz)
+{
+  gcc_assert (sz == sizeof (constant_svalue));
+  constant_svalue_pool.remove (ptr);
+}
+
 /* Compare the fields of this constant_svalue with OTHER, returning true
    if they are equal.
    For use by svalue::operator==.  */
@@ -744,6 +783,25 @@ POP_IGNORE_WFORMAT
 
 /* class unknown_svalue : public svalue.  */
 
+/* FIXME.  */
+static pool_allocator unknown_svalue_pool ("unknown_svalue", sizeof (unknown_svalue));
+
+/* FIXME.  */
+void *
+unknown_svalue::operator new (size_t sz)
+{
+  gcc_assert (sz == sizeof (unknown_svalue));
+  return unknown_svalue_pool.allocate ();
+}
+
+/* FIXME.  */
+void
+unknown_svalue::operator delete (void* ptr, size_t sz)
+{
+  gcc_assert (sz == sizeof (unknown_svalue));
+  unknown_svalue_pool.remove (ptr);
+}
+
 /* Compare the fields of this unknown_svalue with OTHER, returning true
    if they are equal.
    For use by svalue::operator==.  */
@@ -795,6 +853,25 @@ poison_kind_to_str (enum poison_kind kind)
 
 /* class poisoned_svalue : public svalue.  */
 
+/* FIXME.  */
+static pool_allocator poisoned_svalue_pool ("poisoned_svalue", sizeof (poisoned_svalue));
+
+/* FIXME.  */
+void *
+poisoned_svalue::operator new (size_t sz)
+{
+  gcc_assert (sz == sizeof (poisoned_svalue));
+  return poisoned_svalue_pool.allocate ();
+}
+
+/* FIXME.  */
+void
+poisoned_svalue::operator delete (void* ptr, size_t sz)
+{
+  gcc_assert (sz == sizeof (poisoned_svalue));
+  poisoned_svalue_pool.remove (ptr);
+}
+
 /* Compare the fields of this poisoned_svalue with OTHER, returning true
    if they are equal.
    For use by svalue::operator==.  */
@@ -1653,6 +1730,25 @@ map_region::get_value_by_name (tree identifier,
 
 /* class frame_region : public map_region.  */
 
+/* FIXME.  */
+static pool_allocator frame_region_pool ("frame_region", sizeof (frame_region));
+
+/* FIXME.  */
+void *
+frame_region::operator new (size_t sz)
+{
+  gcc_assert (sz == sizeof (frame_region));
+  return frame_region_pool.allocate ();
+}
+
+/* FIXME.  */
+void
+frame_region::operator delete (void* ptr, size_t sz)
+{
+  gcc_assert (sz == sizeof (frame_region));
+  frame_region_pool.remove (ptr);
+}
+
 /* Compare the fields of this frame_region with OTHER, returning true
    if they are equal.
    For use by region::operator==.  */
@@ -1700,6 +1796,25 @@ frame_region::add_to_hash (inchash::hash &hstate) const
 
 /* class stack_region : public region.  */
 
+/* FIXME.  */
+static pool_allocator stack_region_pool ("stack_region", sizeof (stack_region));
+
+/* FIXME.  */
+void *
+stack_region::operator new (size_t sz)
+{
+  gcc_assert (sz == sizeof (stack_region));
+  return stack_region_pool.allocate ();
+}
+
+/* FIXME.  */
+void
+stack_region::operator delete (void* ptr, size_t sz)
+{
+  gcc_assert (sz == sizeof (stack_region));
+  stack_region_pool.remove (ptr);
+}
+
 /* stack_region's copy ctor.  */
 
 stack_region::stack_region (const stack_region &other)
@@ -1931,6 +2046,25 @@ stack_region::get_value_by_name (tree identifier,
 
 /* class heap_region : public region.  */
 
+/* FIXME.  */
+static pool_allocator heap_region_pool ("heap_region", sizeof (heap_region));
+
+/* FIXME.  */
+void *
+heap_region::operator new (size_t sz)
+{
+  gcc_assert (sz == sizeof (heap_region));
+  return heap_region_pool.allocate ();
+}
+
+/* FIXME.  */
+void
+heap_region::operator delete (void* ptr, size_t sz)
+{
+  gcc_assert (sz == sizeof (heap_region));
+  heap_region_pool.remove (ptr);
+}
+
 /* heap_region's copy ctor.  */
 
 heap_region::heap_region (const heap_region &other)
@@ -1992,6 +2126,25 @@ heap_region::walk_for_canonicalization (canonicalization *) const
 
 /* class root_region : public region.  */
 
+/* FIXME.  */
+static pool_allocator root_region_pool ("root_region", sizeof (root_region));
+
+/* FIXME.  */
+void *
+root_region::operator new (size_t sz)
+{
+  gcc_assert (sz == sizeof (root_region));
+  return root_region_pool.allocate ();
+}
+
+/* FIXME.  */
+void
+root_region::operator delete (void* ptr, size_t sz)
+{
+  gcc_assert (sz == sizeof (root_region));
+  root_region_pool.remove (ptr);
+}
+
 /* root_region's default ctor.  */
 
 root_region::root_region ()
@@ -2350,6 +2503,25 @@ root_region::get_value_by_name (tree identifier,
 
 /* class symbolic_region : public map_region.  */
 
+/* FIXME.  */
+static pool_allocator symbolic_region_pool ("symbolic_region", sizeof (symbolic_region));
+
+/* FIXME.  */
+void *
+symbolic_region::operator new (size_t sz)
+{
+  gcc_assert (sz == sizeof (symbolic_region));
+  return symbolic_region_pool.allocate ();
+}
+
+/* FIXME.  */
+void
+symbolic_region::operator delete (void* ptr, size_t sz)
+{
+  gcc_assert (sz == sizeof (symbolic_region));
+  symbolic_region_pool.remove (ptr);
+}
+
 /* symbolic_region's copy ctor.  */
 
 symbolic_region::symbolic_region (const symbolic_region &other)
@@ -2380,6 +2552,25 @@ symbolic_region::clone () const
 
 /* class region_model.  */
 
+/* FIXME.  */
+static pool_allocator region_model_pool ("region_model", sizeof (region_model));
+
+/* FIXME.  */
+void *
+region_model::operator new (size_t sz)
+{
+  gcc_assert (sz == sizeof (region_model));
+  return region_model_pool.allocate ();
+}
+
+/* FIXME.  */
+void
+region_model::operator delete (void* ptr, size_t sz)
+{
+  gcc_assert (sz == sizeof (region_model));
+  region_model_pool.remove (ptr);
+}
+
 /* region_model's default ctor.  */
 
 region_model::region_model ()
diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h
index 76d0cf2..1021cb2 100644
--- a/gcc/analyzer/region-model.h
+++ b/gcc/analyzer/region-model.h
@@ -502,6 +502,9 @@ public:
 class region_svalue : public svalue
 {
 public:
+  static void *operator new (size_t sz);
+  static void operator delete (void* ptr, size_t sz);
+
   region_svalue (tree type, region_id rid) : svalue (type), m_rid (rid)
   {
     /* Should we support NULL ptrs here?  */
@@ -563,6 +566,9 @@ is_a_helper <region_svalue *>::test (svalue *sval)
 class constant_svalue : public svalue
 {
 public:
+  static void *operator new (size_t sz);
+  static void operator delete (void* ptr, size_t sz);
+
   constant_svalue (tree cst_expr)
   : svalue (TREE_TYPE (cst_expr)), m_cst_expr (cst_expr)
   {
@@ -619,6 +625,9 @@ is_a_helper <constant_svalue *>::test (svalue *sval)
 class unknown_svalue : public svalue
 {
 public:
+  static void *operator new (size_t sz);
+  static void operator delete (void* ptr, size_t sz);
+
   unknown_svalue (tree type)
   : svalue (type)
   {}
@@ -663,6 +672,9 @@ extern const char *poison_kind_to_str (enum poison_kind);
 class poisoned_svalue : public svalue
 {
 public:
+  static void *operator new (size_t sz);
+  static void operator delete (void* ptr, size_t sz);
+
   poisoned_svalue (enum poison_kind kind) : svalue (NULL), m_kind (kind) {}
 
   bool compare_fields (const poisoned_svalue &other) const;
@@ -870,6 +882,9 @@ public:
 class frame_region : public map_region
 {
 public:
+  static void *operator new (size_t sz);
+  static void operator delete (void* ptr, size_t sz);
+
   frame_region (region_id parent_rid, function *fun, int depth)
   : map_region (parent_rid, NULL_TREE), m_fun (fun), m_depth (depth)
   {}
@@ -906,6 +921,9 @@ public:
 class stack_region : public region
 {
 public:
+  static void *operator new (size_t sz);
+  static void operator delete (void* ptr, size_t sz);
+
   stack_region (region_id parent_rid, svalue_id sval_id)
   : region (parent_rid, sval_id, NULL_TREE)
   {}
@@ -958,6 +976,9 @@ public:
 class heap_region : public region
 {
 public:
+  static void *operator new (size_t sz);
+  static void operator delete (void* ptr, size_t sz);
+
   heap_region (region_id parent_rid, svalue_id sval_id)
   : region (parent_rid, sval_id, NULL_TREE)
   {}
@@ -985,6 +1006,9 @@ public:
 class root_region : public region
 {
 public:
+  static void *operator new (size_t sz);
+  static void operator delete (void* ptr, size_t sz);
+
   root_region ();
   root_region (const root_region &other);
 
@@ -1046,6 +1070,9 @@ private:
 class symbolic_region : public map_region
 {
 public:
+  static void *operator new (size_t sz);
+  static void operator delete (void* ptr, size_t sz);
+
   symbolic_region (region_id parent_rid)
   : map_region (parent_rid, NULL_TREE)
   {}
@@ -1070,6 +1097,9 @@ public:
 class region_model
 {
  public:
+  static void *operator new (size_t sz);
+  static void operator delete (void* ptr, size_t sz);
+
   region_model ();
   region_model (const region_model &other);
   ~region_model ();
-- 
1.8.5.3

