aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-range-cache.cc
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2023-03-28 11:35:26 -0400
committerAndrew MacLeod <amacleod@redhat.com>2023-04-26 15:17:08 -0400
commit0a38f677463ff8a4fb61b049263aa596ef6471a7 (patch)
tree28f6ae3086f4e023f3ea48f49e4086776e4995ef /gcc/gimple-range-cache.cc
parent8a3590e5ce8fcc6b381d9572edbca6157bd67cfd (diff)
downloadgcc-0a38f677463ff8a4fb61b049263aa596ef6471a7.zip
gcc-0a38f677463ff8a4fb61b049263aa596ef6471a7.tar.gz
gcc-0a38f677463ff8a4fb61b049263aa596ef6471a7.tar.bz2
Create a lazy ssa_cache.
Sparsely used ssa caches can benefit from using a bitmap to determine if a name already has an entry. Utilize it in the path query and remove its private bitmap for tracking the same info. Also use it in the "assume" query class. PR tree-optimization/108697 * gimple-range-cache.cc (ssa_global_cache::clear_range): Do not clear the vector on an out of range query. (ssa_cache::dump): Use dump_range_query instead of get_range. (ssa_cache::dump_range_query): New. (ssa_lazy_cache::dump_range_query): New. (ssa_lazy_cache::set_range): New. * gimple-range-cache.h (ssa_cache::dump_range_query): New. (class ssa_lazy_cache): New. (ssa_lazy_cache::ssa_lazy_cache): New. (ssa_lazy_cache::~ssa_lazy_cache): New. (ssa_lazy_cache::get_range): New. (ssa_lazy_cache::clear_range): New. (ssa_lazy_cache::clear): New. (ssa_lazy_cache::dump): New. * gimple-range-path.cc (path_range_query::path_range_query): Do not allocate a ssa_cache object nor has_cache bitmap. (path_range_query::~path_range_query): Do not free objects. (path_range_query::clear_cache): Remove. (path_range_query::get_cache): Adjust. (path_range_query::set_cache): Remove. (path_range_query::dump): Don't call through a pointer. (path_range_query::internal_range_of_expr): Set cache directly. (path_range_query::reset_path): Clear cache directly. (path_range_query::ssa_range_in_phi): Fold with globals only. (path_range_query::compute_ranges_in_phis): Simply set range. (path_range_query::compute_ranges_in_block): Call cache directly. * gimple-range-path.h (class path_range_query): Replace bitmap and cache pointer with lazy cache object. * gimple-range.h (class assume_query): Use ssa_lazy_cache.
Diffstat (limited to 'gcc/gimple-range-cache.cc')
-rw-r--r--gcc/gimple-range-cache.cc45
1 files changed, 42 insertions, 3 deletions
diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 6de96f6..5510efb 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -592,14 +592,14 @@ ssa_cache::set_range (tree name, const vrange &r)
return m != NULL;
}
-// Set the range for NAME to R in the global cache.
+// Set the range for NAME to R in the ssa cache.
void
ssa_cache::clear_range (tree name)
{
unsigned v = SSA_NAME_VERSION (name);
if (v >= m_tab.length ())
- m_tab.safe_grow_cleared (num_ssa_names + 1);
+ return;
m_tab[v] = NULL;
}
@@ -624,7 +624,10 @@ ssa_cache::dump (FILE *f)
if (!gimple_range_ssa_p (ssa_name (x)))
continue;
Value_Range r (TREE_TYPE (ssa_name (x)));
- if (get_range (r, ssa_name (x)) && !r.varying_p ())
+ // Invoke dump_range_query which is a private virtual version of
+ // get_range. This avoids performance impacts on general queries,
+ // but allows sharing of the dump routine.
+ if (dump_range_query (r, ssa_name (x)) && !r.varying_p ())
{
if (print_header)
{
@@ -646,6 +649,42 @@ ssa_cache::dump (FILE *f)
fputc ('\n', f);
}
+// Virtual private get_range query for dumping.
+
+bool
+ssa_cache::dump_range_query (vrange &r, tree name) const
+{
+ return get_range (r, name);
+}
+
+// Virtual private get_range query for dumping.
+
+bool
+ssa_lazy_cache::dump_range_query (vrange &r, tree name) const
+{
+ return get_range (r, name);
+}
+
+
+// Set range of NAME to R in a lazy cache. Return FALSE if it did not already
+// have a range.
+
+bool
+ssa_lazy_cache::set_range (tree name, const vrange &r)
+{
+ unsigned v = SSA_NAME_VERSION (name);
+ if (!bitmap_set_bit (active_p, v))
+ {
+ // There is already an entry, simply set it.
+ gcc_checking_assert (v < m_tab.length ());
+ return ssa_cache::set_range (name, r);
+ }
+ if (v >= m_tab.length ())
+ m_tab.safe_grow (num_ssa_names + 1);
+ m_tab[v] = m_range_allocator->clone (r);
+ return false;
+}
+
// --------------------------------------------------------------------------