diff mbox series

[COMMITTED,08/12] - Gori_compute no longer inherits from gori_map.

Message ID 336edc4c-d589-49e4-a879-3de7f533c65d@redhat.com
State New
Headers show
Series [COMMITTED,01/12] - Move all relation queries into relation_oracle. | expand

Commit Message

Andrew MacLeod May 23, 2024, 8:53 p.m. UTC
This patch moves the gori_compute object away from inheriting a gori_map 
object and instead it as a local member.  Export it via map ().

The gori_map object contains all the SSA name dependencies and 
import/export name lists for blocks.  GORI was inheriting from this 
originally as a convenient way to share the data, but it doesn't really 
belong there.  it is really a component that is used by GORI rather than 
part of what it is.  This more accurately reflects the relationship.

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

Patch

From 9b42fafa0ec385bbc86be1d9f1a86c140e1045c3 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Thu, 9 May 2024 14:14:31 -0400
Subject: [PATCH 08/12] Gori_compute no longer inherits from gori_map.

This patch moves the gori_compute object away from inheriting a
gori_map object and instead it as a local member.  Export it via map ().

	* gimple-range-cache.cc (ranger_cache::ranger_cache): Access
	gori_map via member call.
	(ranger_cache::dump_bb): Likewise.
	(ranger_cache::get_global_range): Likewise.
	(ranger_cache::set_global_range): Likewise.
	(ranger_cache::register_inferred_value): Likewise.
	* gimple-range-fold.cc (fold_using_range::range_of_range_op): Likewise.
	(fold_using_range::range_of_address): Likewise.
	(fold_using_range::range_of_phi): Likewise.
	* gimple-range-gori.cc (gori_compute::compute_operand_range_switch):
	likewise.
	(gori_compute::compute_operand_range): Likewise.
	(gori_compute::compute_logical_operands): Likewise.
	(gori_compute::refine_using_relation): Likewise.
	(gori_compute::compute_operand1_and_operand2_range): Likewise.
	(gori_compute::may_recompute_p): Likewise.
	(gori_compute::has_edge_range_p): Likewise.
	(gori_compute::outgoing_edge_range_p): Likewise.
	(gori_compute::condexpr_adjust): Likewise.
	* gimple-range-gori.h (class gori_compute): Do not inherit from
	gori_map.
	(gori_compute::m_map): New.
	* gimple-range-path.cc (gimple-range-path.cc): Use gori_map member.
	(path_range_query::compute_exit_dependencies): Likewise.
	* gimple-range.cc (gimple_ranger::range_of_stmt): Likewise.
	(gimple_ranger::register_transitive_inferred_ranges): Likewise.
	* tree-ssa-dom.cc (set_global_ranges_from_unreachable_edges): Likewise.
	* tree-ssa-threadedge.cc
	  (hybrid_jt_simplifier::compute_exit_dependencies): Likewise.
	* tree-vrp.cc (remove_unreachable::handle_early): Likewise.
	(remove_unreachable::remove_and_update_globals): Likewise.
---
 gcc/gimple-range-cache.cc  | 16 ++++++-------
 gcc/gimple-range-fold.cc   | 12 +++++-----
 gcc/gimple-range-gori.cc   | 47 +++++++++++++++++++-------------------
 gcc/gimple-range-gori.h    |  4 +++-
 gcc/gimple-range-path.cc   |  6 ++---
 gcc/gimple-range.cc        |  6 ++---
 gcc/tree-ssa-dom.cc        |  2 +-
 gcc/tree-ssa-threadedge.cc |  2 +-
 gcc/tree-vrp.cc            |  9 ++++----
 9 files changed, 54 insertions(+), 50 deletions(-)

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 34dc9c4a3ec..c52475852a9 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -969,7 +969,7 @@  ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses)
     {
       basic_block bb = BASIC_BLOCK_FOR_FN (cfun, x);
       if (bb)
-	m_gori.exports (bb);
+	m_gori.map ()->exports (bb);
     }
   m_update = new update_list ();
 }
@@ -1000,7 +1000,7 @@  ranger_cache::dump (FILE *f)
 void
 ranger_cache::dump_bb (FILE *f, basic_block bb)
 {
-  m_gori.gori_map::dump (f, bb, false);
+  m_gori.map ()->dump (f, bb, false);
   m_on_entry.dump (f, bb);
   m_relation->dump (f, bb);
 }
@@ -1033,8 +1033,8 @@  ranger_cache::get_global_range (vrange &r, tree name, bool &current_p)
   current_p = false;
   if (had_global)
     current_p = r.singleton_p ()
-		|| m_temporal->current_p (name, m_gori.depend1 (name),
-					  m_gori.depend2 (name));
+		|| m_temporal->current_p (name, m_gori.map ()->depend1 (name),
+					  m_gori.map ()->depend2 (name));
   else
     {
       // If no global value has been set and value is VARYING, fold the stmt
@@ -1071,8 +1071,8 @@  ranger_cache::set_global_range (tree name, const vrange &r, bool changed)
   if (!changed)
     {
       // If there are dependencies, make sure this is not out of date.
-      if (!m_temporal->current_p (name, m_gori.depend1 (name),
-				 m_gori.depend2 (name)))
+      if (!m_temporal->current_p (name, m_gori.map ()->depend1 (name),
+				 m_gori.map ()->depend2 (name)))
 	m_temporal->set_timestamp (name);
       return;
     }
@@ -1097,7 +1097,7 @@  ranger_cache::set_global_range (tree name, const vrange &r, bool changed)
 
   if (r.singleton_p ()
       || (POINTER_TYPE_P (TREE_TYPE (name)) && r.nonzero_p ()))
-    m_gori.set_range_invariant (name);
+    m_gori.map ()->set_range_invariant (name);
   m_temporal->set_timestamp (name);
 }
 
@@ -1783,7 +1783,7 @@  ranger_cache::register_inferred_value (const vrange &ir, tree name,
       m_on_entry.set_bb_range (name, bb, r);
       // If this range was invariant before, remove invariant.
       if (!m_gori.has_edge_range_p (name))
-	m_gori.set_range_invariant (name, false);
+	m_gori.map ()->set_range_invariant (name, false);
     }
 }
 
diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index 9e9c5960972..b626855c51a 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -747,7 +747,7 @@  fold_using_range::range_of_range_op (vrange &r,
 	  if (lhs && gimple_range_ssa_p (op1))
 	    {
 	      if (src.gori ())
-		src.gori ()->register_dependency (lhs, op1);
+		src.gori ()->map ()->register_dependency (lhs, op1);
 	      relation_kind rel;
 	      rel = handler.lhs_op1_relation (r, range1, range1);
 	      if (rel != VREL_VARYING)
@@ -775,8 +775,8 @@  fold_using_range::range_of_range_op (vrange &r,
 	    {
 	      if (src.gori ())
 		{
-		  src.gori ()->register_dependency (lhs, op1);
-		  src.gori ()->register_dependency (lhs, op2);
+		  src.gori ()->map ()->register_dependency (lhs, op1);
+		  src.gori ()->map ()->register_dependency (lhs, op2);
 		}
 	      if (gimple_range_ssa_p (op1))
 		{
@@ -845,7 +845,7 @@  fold_using_range::range_of_address (prange &r, gimple *stmt, fur_source &src)
       tree ssa = TREE_OPERAND (base, 0);
       tree lhs = gimple_get_lhs (stmt);
       if (lhs && gimple_range_ssa_p (ssa) && src.gori ())
-	src.gori ()->register_dependency (lhs, ssa);
+	src.gori ()->map ()->register_dependency (lhs, ssa);
       src.get_operand (r, ssa);
       range_cast (r, TREE_TYPE (gimple_assign_rhs1 (stmt)));
 
@@ -952,7 +952,7 @@  fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src)
 	    r.union_ (arg_range);
 
 	  if (gimple_range_ssa_p (arg) && src.gori ())
-	    src.gori ()->register_dependency (phi_def, arg);
+	    src.gori ()->map ()->register_dependency (phi_def, arg);
 	}
 
       // Track if all arguments are the same.
@@ -1353,7 +1353,7 @@  fur_source::register_outgoing_edges (gcond *s, irange &lhs_range,
   // leading to the condition such as:
   // c_2 = a_4 < b_7
   // if (c_2)
-  FOR_EACH_GORI_EXPORT_NAME (*(gori ()), bb, name)
+  FOR_EACH_GORI_EXPORT_NAME (*(gori ()->map ()), bb, name)
     {
       if (TREE_CODE (TREE_TYPE (name)) != BOOLEAN_TYPE)
 	continue;
diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index 9afc7c1c19c..fa4a235f08b 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -589,7 +589,7 @@  gori_compute::compute_operand_range_switch (vrange &r, gswitch *s,
     }
 
   // If op1 is in the definition chain, pass lhs back.
-  if (gimple_range_ssa_p (op1) && in_chain_p (name, op1))
+  if (gimple_range_ssa_p (op1) && m_map.in_chain_p (name, op1))
     return compute_operand_range (r, SSA_NAME_DEF_STMT (op1), lhs, name, src);
 
   return false;
@@ -646,8 +646,8 @@  gori_compute::compute_operand_range (vrange &r, gimple *stmt,
 
   // NAME is not in this stmt, but one of the names in it ought to be
   // derived from it.
-  bool op1_in_chain = op1 && in_chain_p (name, op1);
-  bool op2_in_chain = op2 && in_chain_p (name, op2);
+  bool op1_in_chain = op1 && m_map.in_chain_p (name, op1);
+  bool op2_in_chain = op2 && m_map.in_chain_p (name, op2);
 
   // If neither operand is derived, then this stmt tells us nothing.
   if (!op1_in_chain && !op2_in_chain)
@@ -658,9 +658,9 @@  gori_compute::compute_operand_range (vrange &r, gimple *stmt,
   // Instead just evaluate the one operand.
   if (op1_in_chain && op2_in_chain)
     {
-      if (in_chain_p (op1, op2) || op1 == op2)
+      if (m_map.in_chain_p (op1, op2) || op1 == op2)
 	op1_in_chain = false;
-      else if (in_chain_p (op2, op1))
+      else if (m_map.in_chain_p (op2, op1))
 	op2_in_chain = false;
     }
 
@@ -675,11 +675,11 @@  gori_compute::compute_operand_range (vrange &r, gimple *stmt,
       // a) both elements are in the defchain
       //    c = x > y   // (x and y are in c's defchain)
       if (op1_in_chain)
-	res = in_chain_p (vrel_ptr->op1 (), op1)
-	      && in_chain_p (vrel_ptr->op2 (), op1);
+	res = m_map.in_chain_p (vrel_ptr->op1 (), op1)
+	      && m_map.in_chain_p (vrel_ptr->op2 (), op1);
       if (!res && op2_in_chain)
-	res = in_chain_p (vrel_ptr->op1 (), op2)
-	      || in_chain_p (vrel_ptr->op2 (), op2);
+	res = m_map.in_chain_p (vrel_ptr->op1 (), op2)
+	      || m_map.in_chain_p (vrel_ptr->op2 (), op2);
       if (!res)
 	{
 	  // or b) one relation element is in the defchain of the other and the
@@ -955,7 +955,7 @@  gori_compute::compute_logical_operands (vrange &true_range, vrange &false_range,
 {
   gimple *stmt = handler.stmt ();
   gimple *src_stmt = gimple_range_ssa_p (op) ? SSA_NAME_DEF_STMT (op) : NULL;
-  if (!op_in_chain || !src_stmt || chain_import_p (handler.lhs (), op))
+  if (!op_in_chain || !src_stmt || m_map.chain_import_p (handler.lhs (), op))
     {
       // If op is not in the def chain, or defined in this block,
       // use its known value on entry to the block.
@@ -1018,9 +1018,9 @@  gori_compute::refine_using_relation (tree op1, vrange &op1_range,
     return false;
 
   bool change = false;
-  bool op1_def_p = in_chain_p (op2, op1);
+  bool op1_def_p = m_map.in_chain_p (op2, op1);
   if (!op1_def_p)
-    if (!in_chain_p (op1, op2))
+    if (!m_map.in_chain_p (op1, op2))
       return false;
 
   tree def_op = op1_def_p ? op1 : op2;
@@ -1304,8 +1304,8 @@  gori_compute::compute_operand1_and_operand2_range (vrange &r,
 bool
 gori_compute::may_recompute_p (tree name, basic_block bb, int depth)
 {
-  tree dep1 = depend1 (name);
-  tree dep2 = depend2 (name);
+  tree dep1 = m_map.depend1 (name);
+  tree dep2 = m_map.depend2 (name);
 
   // If the first dependency is not set, there is no recomputation.
   // Dependencies reflect original IL, not current state.   Check if the
@@ -1327,7 +1327,8 @@  gori_compute::may_recompute_p (tree name, basic_block bb, int depth)
 	  gcc_checking_assert (depth >= 1);
 	}
 
-      bool res = (bb ? is_export_p (dep1, bb) : is_export_p (dep1));
+      bool res = (bb ? m_map.is_export_p (dep1, bb)
+		     : m_map.is_export_p (dep1));
       if (res || depth <= 1)
 	return res;
       // Check another level of recomputation.
@@ -1335,9 +1336,9 @@  gori_compute::may_recompute_p (tree name, basic_block bb, int depth)
     }
   // Two dependencies terminate the depth of the search.
   if (bb)
-    return is_export_p (dep1, bb) || is_export_p (dep2, bb);
+    return m_map.is_export_p (dep1, bb) || m_map.is_export_p (dep2, bb);
   else
-    return is_export_p (dep1) || is_export_p (dep2);
+    return m_map.is_export_p (dep1) || m_map.is_export_p (dep2);
 }
 
 // Return TRUE if NAME can be recomputed on edge E.  If any direct dependent
@@ -1359,10 +1360,10 @@  gori_compute::has_edge_range_p (tree name, basic_block bb)
 {
   // Check if NAME is an export or can be recomputed.
   if (bb)
-    return is_export_p (name, bb) || may_recompute_p (name, bb);
+    return m_map.is_export_p (name, bb) || may_recompute_p (name, bb);
 
   // If no block is specified, check for anywhere in the IL.
-  return is_export_p (name) || may_recompute_p (name);
+  return m_map.is_export_p (name) || may_recompute_p (name);
 }
 
 // Return TRUE if a range can be calculated or recomputed for NAME on edge E.
@@ -1402,7 +1403,7 @@  gori_compute::outgoing_edge_range_p (vrange &r, edge e, tree name,
 
   fur_stmt src (stmt, &q);
   // If NAME can be calculated on the edge, use that.
-  if (is_export_p (name, e->src))
+  if (m_map.is_export_p (name, e->src))
     {
       bool res;
       if ((idx = tracer.header ("outgoing_edge")))
@@ -1526,13 +1527,13 @@  gori_compute::condexpr_adjust (vrange &r1, vrange &r2, gimple *, tree cond,
     }
 
    // Now solve for SSA1 or SSA2 if they are in the dependency chain.
-   if (ssa1 && in_chain_p (ssa1, cond_name))
+   if (ssa1 && m_map.in_chain_p (ssa1, cond_name))
     {
       Value_Range tmp1 (TREE_TYPE (ssa1));
       if (compute_operand_range (tmp1, def_stmt, cond_true, ssa1, src))
 	r1.intersect (tmp1);
     }
-  if (ssa2 && in_chain_p (ssa2, cond_name))
+  if (ssa2 && m_map.in_chain_p (ssa2, cond_name))
     {
       Value_Range tmp2 (TREE_TYPE (ssa2));
       if (compute_operand_range (tmp2, def_stmt, cond_false, ssa2, src))
@@ -1555,7 +1556,7 @@  gori_compute::condexpr_adjust (vrange &r1, vrange &r2, gimple *, tree cond,
 void
 gori_compute::dump (FILE *f)
 {
-  gori_map::dump (f);
+  m_map.gori_map::dump (f);
 }
 
 // ------------------------------------------------------------------------
diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h
index 8f08e9a088a..ae857ecb2b5 100644
--- a/gcc/gimple-range-gori.h
+++ b/gcc/gimple-range-gori.h
@@ -161,7 +161,7 @@  private:
 
 class value_relation;
 
-class gori_compute : public gori_map
+class gori_compute
 {
 public:
   gori_compute (int not_executable_flag = 0);
@@ -174,7 +174,9 @@  public:
   bool compute_operand_range (vrange &r, gimple *stmt, const vrange &lhs,
 			      tree name, class fur_source &src,
 			      value_relation *rel = NULL);
+  gori_map *map () { return &m_map; }
 private:
+  gori_map m_map;
   bool refine_using_relation (tree op1, vrange &op1_range,
 			      tree op2, vrange &op2_range,
 			      fur_source &src, relation_kind k);
diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc
index b35ab43524b..5043c00d482 100644
--- a/gcc/gimple-range-path.cc
+++ b/gcc/gimple-range-path.cc
@@ -410,7 +410,7 @@  path_range_query::compute_ranges_in_block (basic_block bb)
     }
 
   gori_compute &g = m_ranger.gori ();
-  bitmap exports = g.exports (bb);
+  bitmap exports = g.map()->exports (bb);
   EXECUTE_IF_AND_IN_BITMAP (m_exit_dependencies, exports, 0, i, bi)
     {
       tree name = ssa_name (i);
@@ -488,7 +488,7 @@  path_range_query::compute_exit_dependencies (bitmap dependencies)
   // Start with the imports from the exit block...
   basic_block exit = m_path[0];
   gori_compute &gori = m_ranger.gori ();
-  bitmap_copy (dependencies, gori.imports (exit));
+  bitmap_copy (dependencies, gori.map()->imports (exit));
 
   auto_vec<tree> worklist (bitmap_count_bits (dependencies));
   bitmap_iterator bi;
@@ -536,7 +536,7 @@  path_range_query::compute_exit_dependencies (bitmap dependencies)
       {
 	basic_block bb = m_path[i];
 	tree name;
-	FOR_EACH_GORI_EXPORT_NAME (gori, bb, name)
+	FOR_EACH_GORI_EXPORT_NAME (*(gori.map ()), bb, name)
 	  if (TREE_CODE (TREE_TYPE (name)) == BOOLEAN_TYPE)
 	    bitmap_set_bit (dependencies, SSA_NAME_VERSION (name));
       }
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index efc84dc3b44..e7e6fd86581 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -310,7 +310,7 @@  gimple_ranger::range_of_stmt (vrange &r, gimple *s, tree name)
 	  // Update any exports in the cache if this is a gimple cond statement.
 	  tree exp;
 	  basic_block bb = gimple_bb (s);
-	  FOR_EACH_GORI_EXPORT_NAME (m_cache.m_gori, bb, exp)
+	  FOR_EACH_GORI_EXPORT_NAME (*(m_cache.m_gori.map ()), bb, exp)
 	    m_cache.propagate_updated_value (exp, bb);
 	}
     }
@@ -540,8 +540,8 @@  gimple_ranger::register_transitive_inferred_ranges (basic_block bb)
       // an inferred range as well.
       Value_Range r (TREE_TYPE (lhs));
       r.set_undefined ();
-      tree name1 = gori ().depend1 (lhs);
-      tree name2 = gori ().depend2 (lhs);
+      tree name1 = gori ().map () ->depend1 (lhs);
+      tree name2 = gori ().map ()->depend2 (lhs);
       if ((name1 && infer_oracle ().has_range_p (bb, name1))
 	  || (name2 && infer_oracle ().has_range_p (bb, name2)))
 	{
diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index 73264852ebd..81c8b16fd12 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -1431,7 +1431,7 @@  dom_opt_dom_walker::set_global_ranges_from_unreachable_edges (basic_block bb)
 
   tree name;
   gori_compute &gori = m_ranger->gori ();
-  FOR_EACH_GORI_EXPORT_NAME (gori, pred_e->src, name)
+  FOR_EACH_GORI_EXPORT_NAME (*(gori.map()), pred_e->src, name)
     if (all_uses_feed_or_dominated_by_stmt (name, stmt)
 	// The condition must post-dominate the definition point.
 	&& (SSA_NAME_IS_DEFAULT_DEF (name)
diff --git a/gcc/tree-ssa-threadedge.cc b/gcc/tree-ssa-threadedge.cc
index 2bae82a074b..f5268d45516 100644
--- a/gcc/tree-ssa-threadedge.cc
+++ b/gcc/tree-ssa-threadedge.cc
@@ -1449,7 +1449,7 @@  hybrid_jt_simplifier::compute_exit_dependencies (bitmap dependencies,
   gori_compute &gori = m_ranger->gori ();
 
   // Start with the imports to the final conditional.
-  bitmap_copy (dependencies, gori.imports (path[0]));
+  bitmap_copy (dependencies, gori.map ()->imports (path[0]));
 
   // Add any other interesting operands we may have missed.
   if (gimple_bb (stmt) != path[0])
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index a36c08f469a..be9df39f680 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -210,14 +210,14 @@  remove_unreachable::handle_early (gimple *s, edge e)
 
   // Check if every export use is dominated by this branch.
   tree name;
-  FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name)
+  FOR_EACH_GORI_EXPORT_NAME (*(m_ranger.gori ().map ()), e->src, name)
     {
       if (!fully_replaceable (name, e->src))
 	return;
     }
 
   // Set the global value for each.
-  FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name)
+  FOR_EACH_GORI_EXPORT_NAME (*(m_ranger.gori ().map ()), e->src, name)
     {
       Value_Range r (TREE_TYPE (name));
       m_ranger.range_on_entry (r, e->dest, name);
@@ -287,7 +287,7 @@  remove_unreachable::remove_and_update_globals ()
       gcc_checking_assert (gimple_code (s) == GIMPLE_COND);
 
       bool dominate_exit_p = true;
-      FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name)
+      FOR_EACH_GORI_EXPORT_NAME (*(m_ranger.gori ().map ()), e->src, name)
 	{
 	  // Ensure the cache is set for NAME in the succ block.
 	  Value_Range r(TREE_TYPE (name));
@@ -304,7 +304,8 @@  remove_unreachable::remove_and_update_globals ()
       // If the exit is dominated, add to the export list.  Otherwise if this
       // isn't the final VRP pass, leave the call in the IL.
       if (dominate_exit_p)
-	bitmap_ior_into (all_exports, m_ranger.gori ().exports (e->src));
+	bitmap_ior_into (all_exports,
+			 m_ranger.gori ().map ()->exports (e->src));
       else if (!final_p)
 	continue;
 
-- 
2.41.0