There are times when a bitmap_obstack could be provided to the lazy
cache, in which case it does not need to manage an obstack on its own.
fast_vrp can have a few of these live at once, and I anticipate some
changes to GORI where we may use them a bit more too, so this just
provides a little more flexibility.
bootstrapped on x86_64-pc-linux-gnu with no regressions. Pushed.
Andrew
From 5612541834c063dd4126fb059e59c5dc8d5f2f8e Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacl...@redhat.com>
Date: Wed, 26 Jun 2024 14:53:54 -0400
Subject: [PATCH] ssa_lazy_cache takes an optional bitmap_obstack pointer.
Allow ssa_lazy cache to allocate bitmaps from a client provided obstack
if so desired.
* gimple-range-cache.cc (ssa_lazy_cache::ssa_lazy_cache): Relocate here.
Check for provided obstack.
(ssa_lazy_cache::~ssa_lazy_cache): Relocate here. Free bitmap or obstack.
* gimple-range-cache.h (ssa_lazy_cache::ssa_lazy_cache): Move.
(ssa_lazy_cache::~ssa_lazy_cache): Move.
(ssa_lazy_cache::m_ob): New.
* gimple-range.cc (dom_ranger::dom_ranger): Iniitialize obstack.
(dom_ranger::~dom_ranger): Release obstack.
(dom_ranger::pre_bb): Create ssa_lazy_cache using obstack.
* gimple-range.h (m_bitmaps): New.
---
gcc/gimple-range-cache.cc | 26 ++++++++++++++++++++++++++
gcc/gimple-range-cache.h | 9 +++------
gcc/gimple-range.cc | 4 +++-
gcc/gimple-range.h | 1 +
4 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 6979a14cbaa..0fffd7c16a1 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -683,6 +683,32 @@ ssa_cache::dump (FILE *f)
}
+// Construct an ssa_lazy_cache. If OB is specified, us it, otherwise use
+// a local bitmap obstack.
+
+ssa_lazy_cache::ssa_lazy_cache (bitmap_obstack *ob)
+{
+ if (!ob)
+ {
+ bitmap_obstack_initialize (&m_bitmaps);
+ m_ob = &m_bitmaps;
+ }
+ else
+ m_ob = ob;
+ active_p = BITMAP_ALLOC (m_ob);
+}
+
+// Destruct an sa_lazy_cache. Free the bitmap if it came from a different
+// obstack, or release the obstack if it was a local one.
+
+ssa_lazy_cache::~ssa_lazy_cache ()
+{
+ if (m_ob == &m_bitmaps)
+ bitmap_obstack_release (&m_bitmaps);
+ else
+ BITMAP_FREE (active_p);
+}
+
// Return true if NAME has an active range in the cache.
bool
diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h
index 0ea34d3f686..539c06753dd 100644
--- a/gcc/gimple-range-cache.h
+++ b/gcc/gimple-range-cache.h
@@ -78,12 +78,8 @@ protected:
class ssa_lazy_cache : public ssa_cache
{
public:
- inline ssa_lazy_cache ()
- {
- bitmap_obstack_initialize (&m_bitmaps);
- active_p = BITMAP_ALLOC (&m_bitmaps);
- }
- inline ~ssa_lazy_cache () { bitmap_obstack_release (&m_bitmaps); }
+ ssa_lazy_cache (bitmap_obstack *ob = NULL);
+ ~ssa_lazy_cache ();
inline bool empty_p () const { return bitmap_empty_p (active_p); }
virtual bool has_range (tree name) const;
virtual bool set_range (tree name, const vrange &r);
@@ -94,6 +90,7 @@ public:
void merge (const ssa_lazy_cache &);
protected:
bitmap_obstack m_bitmaps;
+ bitmap_obstack *m_ob;
bitmap active_p;
};
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 5df649e268c..7ba7d464b5e 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -908,6 +908,7 @@ assume_query::dump (FILE *f)
dom_ranger::dom_ranger () : m_global ()
{
+ bitmap_obstack_initialize (&m_bitmaps);
m_freelist.create (0);
m_freelist.truncate (0);
m_bb.create (0);
@@ -928,6 +929,7 @@ dom_ranger::~dom_ranger ()
}
m_bb.release ();
m_freelist.release ();
+ bitmap_obstack_release (&m_bitmaps);
}
// Implement range of EXPR on stmt S, and return it in R.
@@ -1071,7 +1073,7 @@ dom_ranger::pre_bb (basic_block bb)
if (!m_freelist.is_empty ())
e_cache = m_freelist.pop ();
else
- e_cache = new ssa_lazy_cache;
+ e_cache = new ssa_lazy_cache (&m_bitmaps);
gcc_checking_assert (e_cache->empty_p ());
// If there is a single pred, check if there are any ranges on
diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h
index 91177567947..62bd8a87112 100644
--- a/gcc/gimple-range.h
+++ b/gcc/gimple-range.h
@@ -116,6 +116,7 @@ public:
void pre_bb (basic_block bb);
void post_bb (basic_block bb);
protected:
+ bitmap_obstack m_bitmaps;
void range_in_bb (vrange &r, basic_block bb, tree name);
DISABLE_COPY_AND_ASSIGN (dom_ranger);
ssa_cache m_global;
--
2.45.0