diff mbox series

[COMMITTED,4/5] Rename ssa_global_cache to ssa_cache and add has_range

Message ID 5e014139-e9d6-52fa-bbdb-42c74981b9d7@redhat.com
State New
Headers show
Series [COMMITTED,1/5] PR tree-optimization/109417 - Don't save ssa-name pointer in dependency cache. | expand

Commit Message

Andrew MacLeod April 26, 2023, 7:26 p.m. UTC
The original ssa_global_cache was intended to simply be the global cache 
for ranger, but uses of it have since percolated such that it is really 
just a range acche for a list of ssa-names. This patch renames it from 
"ssa_global_cache" to "ssa_cache".

It also adds a method called "has_range" which didnt exist before which 
simply indicates if a range is set or not.

Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed.

Andrew
diff mbox series

Patch

From bf07de561197559304c67bd46c7bea3da9eb63f9 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Tue, 28 Mar 2023 11:32:21 -0400
Subject: [PATCH 4/5] Rename ssa_global_cache to ssa_cache and add has_range

This renames the ssa_global_cache to be ssa_cache.  The original use was
to function as a global cache, but its uses have expanded.  Remove all mention
of "global" from the class and methods.  Also add a has_range method.

	* gimple-range-cache.cc (ssa_cache::ssa_cache): Rename.
	(ssa_cache::~ssa_cache): Rename.
	(ssa_cache::has_range): New.
	(ssa_cache::get_range): Rename.
	(ssa_cache::set_range): Rename.
	(ssa_cache::clear_range): Rename.
	(ssa_cache::clear): Rename.
	(ssa_cache::dump): Rename and use get_range.
	(ranger_cache::get_global_range): Use get_range and set_range.
	(ranger_cache::range_of_def): Use get_range.
	* gimple-range-cache.h (class ssa_cache): Rename class and methods.
	(class ranger_cache): Use ssa_cache.
	* gimple-range-path.cc (path_range_query::path_range_query): Use
	ssa_cache.
	(path_range_query::get_cache): Use get_range.
	(path_range_query::set_cache): Use set_range.
	* gimple-range-path.h (class path_range_query): Use ssa_cache.
	* gimple-range.cc (assume_query::assume_range_p): Use get_range.
	(assume_query::range_of_expr): Use get_range.
	(assume_query::assume_query): Use set_range.
	(assume_query::calculate_op): Use get_range and set_range.
	* gimple-range.h (class assume_query): Use ssa_cache.
---
 gcc/gimple-range-cache.cc | 45 ++++++++++++++++++++++++---------------
 gcc/gimple-range-cache.h  | 15 +++++++------
 gcc/gimple-range-path.cc  |  8 +++----
 gcc/gimple-range-path.h   |  2 +-
 gcc/gimple-range.cc       | 14 ++++++------
 gcc/gimple-range.h        |  2 +-
 6 files changed, 49 insertions(+), 37 deletions(-)

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 868d2dda424..6de96f6b8a9 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -530,27 +530,38 @@  block_range_cache::dump (FILE *f, basic_block bb, bool print_varying)
 
 // -------------------------------------------------------------------------
 
-// Initialize a global cache.
+// Initialize an ssa cache.
 
-ssa_global_cache::ssa_global_cache ()
+ssa_cache::ssa_cache ()
 {
   m_tab.create (0);
   m_range_allocator = new obstack_vrange_allocator;
 }
 
-// Deconstruct a global cache.
+// Deconstruct an ssa cache.
 
-ssa_global_cache::~ssa_global_cache ()
+ssa_cache::~ssa_cache ()
 {
   m_tab.release ();
   delete m_range_allocator;
 }
 
+// Return TRUE if the global range of NAME has a cache entry.
+
+bool
+ssa_cache::has_range (tree name) const
+{
+  unsigned v = SSA_NAME_VERSION (name);
+  if (v >= m_tab.length ())
+    return false;
+  return m_tab[v] != NULL;
+}
+
 // Retrieve the global range of NAME from cache memory if it exists. 
 // Return the value in R.
 
 bool
-ssa_global_cache::get_global_range (vrange &r, tree name) const
+ssa_cache::get_range (vrange &r, tree name) const
 {
   unsigned v = SSA_NAME_VERSION (name);
   if (v >= m_tab.length ())
@@ -563,11 +574,11 @@  ssa_global_cache::get_global_range (vrange &r, tree name) const
   return true;
 }
 
-// Set the range for NAME to R in the global cache.
+// Set the range for NAME to R in the ssa cache.
 // Return TRUE if there was already a range set, otherwise false.
 
 bool
-ssa_global_cache::set_global_range (tree name, const vrange &r)
+ssa_cache::set_range (tree name, const vrange &r)
 {
   unsigned v = SSA_NAME_VERSION (name);
   if (v >= m_tab.length ())
@@ -584,7 +595,7 @@  ssa_global_cache::set_global_range (tree name, const vrange &r)
 // Set the range for NAME to R in the global cache.
 
 void
-ssa_global_cache::clear_global_range (tree name)
+ssa_cache::clear_range (tree name)
 {
   unsigned v = SSA_NAME_VERSION (name);
   if (v >= m_tab.length ())
@@ -592,19 +603,19 @@  ssa_global_cache::clear_global_range (tree name)
   m_tab[v] = NULL;
 }
 
-// Clear the global cache.
+// Clear the ssa cache.
 
 void
-ssa_global_cache::clear ()
+ssa_cache::clear ()
 {
   if (m_tab.address ())
     memset (m_tab.address(), 0, m_tab.length () * sizeof (vrange *));
 }
 
-// Dump the contents of the global cache to F.
+// Dump the contents of the ssa cache to F.
 
 void
-ssa_global_cache::dump (FILE *f)
+ssa_cache::dump (FILE *f)
 {
   /* Cleared after the table header has been printed.  */
   bool print_header = true;
@@ -613,7 +624,7 @@  ssa_global_cache::dump (FILE *f)
       if (!gimple_range_ssa_p (ssa_name (x)))
 	continue;
       Value_Range r (TREE_TYPE (ssa_name (x)));
-      if (get_global_range (r, ssa_name (x)) && !r.varying_p ())
+      if (get_range (r, ssa_name (x)) && !r.varying_p ())
 	{
 	  if (print_header)
 	    {
@@ -877,7 +888,7 @@  ranger_cache::dump_bb (FILE *f, basic_block bb)
 bool
 ranger_cache::get_global_range (vrange &r, tree name) const
 {
-  if (m_globals.get_global_range (r, name))
+  if (m_globals.get_range (r, name))
     return true;
   gimple_range_global (r, name);
   return false;
@@ -902,7 +913,7 @@  ranger_cache::get_global_range (vrange &r, tree name, bool &current_p)
 		|| m_temporal->current_p (name, m_gori.depend1 (name),
 					  m_gori.depend2 (name));
   else
-    m_globals.set_global_range (name, r);
+    m_globals.set_range (name, r);
 
   // If the existing value was not current, mark it as always current.
   if (!current_p)
@@ -915,7 +926,7 @@  ranger_cache::get_global_range (vrange &r, tree name, bool &current_p)
 void
 ranger_cache::set_global_range (tree name, const vrange &r)
 {
-  if (m_globals.set_global_range (name, r))
+  if (m_globals.set_range (name, r))
     {
       // If there was already a range set, propagate the new value.
       basic_block bb = gimple_bb (SSA_NAME_DEF_STMT (name));
@@ -954,7 +965,7 @@  ranger_cache::range_of_def (vrange &r, tree name, basic_block bb)
   gcc_checking_assert (!bb || bb == gimple_bb (SSA_NAME_DEF_STMT (name)));
 
   // Pick up the best global range available.
-  if (!m_globals.get_global_range (r, name))
+  if (!m_globals.get_range (r, name))
     {
       // If that fails, try to calculate the range using just global values.
       gimple *s = SSA_NAME_DEF_STMT (name);
diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h
index 4ff435dc5c1..2d41f0c5c67 100644
--- a/gcc/gimple-range-cache.h
+++ b/gcc/gimple-range-cache.h
@@ -52,14 +52,15 @@  private:
 // has been visited during this incarnation.  Once the ranger evaluates
 // a name, it is typically not re-evaluated again.
 
-class ssa_global_cache
+class ssa_cache
 {
 public:
-  ssa_global_cache ();
-  ~ssa_global_cache ();
-  bool get_global_range (vrange &r, tree name) const;
-  bool set_global_range (tree name, const vrange &r);
-  void clear_global_range (tree name);
+  ssa_cache ();
+  ~ssa_cache ();
+  bool has_range (tree name) const;
+  bool get_range (vrange &r, tree name) const;
+  bool set_range (tree name, const vrange &r);
+  void clear_range (tree name);
   void clear ();
   void dump (FILE *f = stderr);
 private:
@@ -95,7 +96,7 @@  public:
   void dump_bb (FILE *f, basic_block bb);
   virtual void dump (FILE *f) override;
 private:
-  ssa_global_cache m_globals;
+  ssa_cache m_globals;
   block_range_cache m_on_entry;
   class temporal_cache *m_temporal;
   void fill_block_cache (tree name, basic_block bb, basic_block def_bb);
diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc
index f68b2029476..07868df5e6f 100644
--- a/gcc/gimple-range-path.cc
+++ b/gcc/gimple-range-path.cc
@@ -40,7 +40,7 @@  path_range_query::path_range_query (gimple_ranger &ranger,
 				    const vec<basic_block> &path,
 				    const bitmap_head *dependencies,
 				    bool resolve)
-  : m_cache (new ssa_global_cache),
+  : m_cache (new ssa_cache),
     m_has_cache_entry (BITMAP_ALLOC (NULL)),
     m_ranger (ranger),
     m_resolve (resolve)
@@ -51,7 +51,7 @@  path_range_query::path_range_query (gimple_ranger &ranger,
 }
 
 path_range_query::path_range_query (gimple_ranger &ranger, bool resolve)
-  : m_cache (new ssa_global_cache),
+  : m_cache (new ssa_cache),
     m_has_cache_entry (BITMAP_ALLOC (NULL)),
     m_ranger (ranger),
     m_resolve (resolve)
@@ -94,7 +94,7 @@  path_range_query::get_cache (vrange &r, tree name)
 
   unsigned v = SSA_NAME_VERSION (name);
   if (bitmap_bit_p (m_has_cache_entry, v))
-    return m_cache->get_global_range (r, name);
+    return m_cache->get_range (r, name);
 
   return false;
 }
@@ -106,7 +106,7 @@  path_range_query::set_cache (const vrange &r, tree name)
 {
   unsigned v = SSA_NAME_VERSION (name);
   bitmap_set_bit (m_has_cache_entry, v);
-  m_cache->set_global_range (name, r);
+  m_cache->set_range (name, r);
 }
 
 void
diff --git a/gcc/gimple-range-path.h b/gcc/gimple-range-path.h
index e8b06b60e66..29e33c6c37b 100644
--- a/gcc/gimple-range-path.h
+++ b/gcc/gimple-range-path.h
@@ -83,7 +83,7 @@  private:
   void move_next ()	  { --m_pos; }
 
   // Range cache for SSA names.
-  ssa_global_cache *m_cache;
+  ssa_cache *m_cache;
 
   // Set for each SSA that has an active entry in the cache.
   bitmap m_has_cache_entry;
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index b4de8dd4ef9..49e9d6b4de6 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -737,7 +737,7 @@  disable_ranger (struct function *fun)
 bool
 assume_query::assume_range_p (vrange &r, tree name)
 {
-  if (global.get_global_range (r, name))
+  if (global.get_range (r, name))
     return !r.varying_p ();
   return false;
 }
@@ -750,7 +750,7 @@  assume_query::range_of_expr (vrange &r, tree expr, gimple *stmt)
   if (!gimple_range_ssa_p (expr))
     return get_tree_range (r, expr, stmt);
 
-  if (!global.get_global_range (r, expr))
+  if (!global.get_range (r, expr))
     r.set_varying (TREE_TYPE (expr));
   return true;
 }
@@ -781,7 +781,7 @@  assume_query::assume_query ()
 
       unsigned prec = TYPE_PRECISION (lhs_type);
       int_range<2> lhs_range (lhs_type, wi::one (prec), wi::one (prec));
-      global.set_global_range (op, lhs_range);
+      global.set_range (op, lhs_range);
 
       gimple *def = SSA_NAME_DEF_STMT (op);
       if (!def || gimple_get_lhs (def) != op)
@@ -802,9 +802,9 @@  assume_query::calculate_op (tree op, gimple *s, vrange &lhs, fur_source &src)
       && !op_range.varying_p ())
     {
       Value_Range range (TREE_TYPE (op));
-      if (global.get_global_range (range, op))
+      if (global.get_range (range, op))
 	op_range.intersect (range);
-      global.set_global_range (op, op_range);
+      global.set_range (op, op_range);
       gimple *def_stmt = SSA_NAME_DEF_STMT (op);
       if (def_stmt && gimple_get_lhs (def_stmt) == op)
 	calculate_stmt (def_stmt, op_range, src);
@@ -827,9 +827,9 @@  assume_query::calculate_phi (gphi *phi, vrange &lhs_range, fur_source &src)
 	  // A symbol arg will be the LHS value.
 	  arg_range = lhs_range;
 	  range_cast (arg_range, TREE_TYPE (arg));
-	  if (!global.get_global_range (arg_range, arg))
+	  if (!global.get_range (arg_range, arg))
 	    {
-	      global.set_global_range (arg, arg_range);
+	      global.set_range (arg, arg_range);
 	      gimple *def_stmt = SSA_NAME_DEF_STMT (arg);
 	      if (def_stmt && gimple_get_lhs (def_stmt) == arg)
 		calculate_stmt (def_stmt, arg_range, src);
diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h
index b8ddca59d2d..944e7692a0e 100644
--- a/gcc/gimple-range.h
+++ b/gcc/gimple-range.h
@@ -96,7 +96,7 @@  protected:
   void calculate_phi (gphi *phi, vrange &lhs_range, fur_source &src);
   void check_taken_edge (edge e, fur_source &src);
 
-  ssa_global_cache global;
+  ssa_cache global;
   gori_compute m_gori;
 };
 
-- 
2.39.2