From be6e6b93cc5d42a09a1f2be26dfdf7e3f897d296 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Wed, 24 May 2023 09:06:26 -0400
Subject: [PATCH 2/4] Make ssa_cache a range_query.
By providing range_of_expr as a range_query, we can fold and do other
interesting things using values from the global table. Make ranger's
knonw globals available via const_query.
* gimple-range-cache.cc (ssa_cache::range_of_expr): New.
* gimple-range-cache.h (class ssa_cache): Inherit from range_query.
(ranger_cache::const_query): New.
* gimple-range.cc (gimple_ranger::const_query): New.
* gimple-range.h (gimple_ranger::const_query): New prototype.
---
gcc/gimple-range-cache.cc | 14 ++++++++++++++
gcc/gimple-range-cache.h | 5 ++++-
gcc/gimple-range.cc | 8 ++++++++
gcc/gimple-range.h | 1 +
4 files changed, 27 insertions(+), 1 deletion(-)
@@ -545,6 +545,20 @@ ssa_cache::~ssa_cache ()
delete m_range_allocator;
}
+// Enable a query to evaluate staements/ramnges based on picking up ranges
+// from just an ssa-cache.
+
+bool
+ssa_cache::range_of_expr (vrange &r, tree expr, gimple *stmt)
+{
+ if (!gimple_range_ssa_p (expr))
+ return get_tree_range (r, expr, stmt);
+
+ if (!get_range (r, expr))
+ gimple_range_global (r, expr, cfun);
+ return true;
+}
+
// Return TRUE if the global range of NAME has a cache entry.
bool
@@ -52,7 +52,7 @@ private:
// has been visited during this incarnation. Once the ranger evaluates
// a name, it is typically not re-evaluated again.
-class ssa_cache
+class ssa_cache : public range_query
{
public:
ssa_cache ();
@@ -63,6 +63,8 @@ public:
virtual void clear_range (tree name);
virtual void clear ();
void dump (FILE *f = stderr);
+ virtual bool range_of_expr (vrange &r, tree expr, gimple *stmt);
+
protected:
vec<vrange_storage *> m_tab;
vrange_allocator *m_range_allocator;
@@ -103,6 +105,7 @@ public:
bool get_global_range (vrange &r, tree name) const;
bool get_global_range (vrange &r, tree name, bool ¤t_p);
void set_global_range (tree name, const vrange &r, bool changed = true);
+ range_query &const_query () { return m_globals; }
void propagate_updated_value (tree name, basic_block bb);
@@ -70,6 +70,14 @@ gimple_ranger::~gimple_ranger ()
m_stmt_list.release ();
}
+// Return a range_query which accesses just the known global values.
+
+range_query &
+gimple_ranger::const_query ()
+{
+ return m_cache.const_query ();
+}
+
bool
gimple_ranger::range_of_expr (vrange &r, tree expr, gimple *stmt)
{
@@ -64,6 +64,7 @@ public:
bool fold_stmt (gimple_stmt_iterator *gsi, tree (*) (tree));
void register_inferred_ranges (gimple *s);
void register_transitive_inferred_ranges (basic_block bb);
+ range_query &const_query ();
protected:
bool fold_range_internal (vrange &r, gimple *s, tree name);
void prefill_name (vrange &r, tree name);
--
2.40.1