diff mbox series

[COMMITTED,09/12] - Gori_compute inherits from gimple_outgoing_range.

Message ID f8ba3f6b-dcbd-4c75-8024-04a89cf8d215@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 makes gimple_outgoing_range a base class for the GORI API, 
and provides basic routines for the SSA-NAME versions returning false.   
gori_compute now inherits from gimple_outgoing_range and no longer needs 
it as a private member. This makes far more sense as GORI is adding the 
ability to calculate SSA_NAMEs on edges in addition to the basic static 
edge ranges.  It also renames outgoing_edge_range_p to edge_range_p for 
consistency with the static edge range routine.

The basic API for static edges (including switch ranges) is documented 
here. https://gcc.gnu.org/wiki/AndrewMacLeod/GimpleOutgoingRange

The more advanced GORI ssa-name processing engine has not been written 
yet.  its on the to-do list :-)

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

Patch

From 8feb69600dd696fb8a6e3b88b7d159ced5cb0eb9 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Thu, 9 May 2024 16:34:12 -0400
Subject: [PATCH 09/12] Gori_compute inherits from gimple_outgoing_range.

Make gimple_outgoing_range a base class for the GORI API, and provide
base routines returning false.   gori_compute inherits from
gimple_outgoing_range and no longer needs it as a private member.
Rename outgoing_edge_range_p to edge_range_p.

	* gimple-range-cache.cc (ranger_cache::ranger_cache): Adjust
	m_gori constructor.
	(ranger_cache::edge_range): Use renamed edge_range_p name.
	(ranger_cache::range_from_dom): Likewise.
	* gimple-range-edge.h (gimple_outgoing_range::condexpr_adjust): New.
	(gimple_outgoing_range::has_edge_range_p): New.
	(gimple_outgoing_range::dump): New.
	(gimple_outgoing_range::compute_operand_range): New.
	(gimple_outgoing_range::map): New.
	* gimple-range-fold.cc (fur_source::register_outgoing_edges ): Use
	renamed edge_range_p routine
	* gimple-range-gori.cc (gori_compute::gori_compute): Adjust
	constructor.
	(gori_compute::~gori_compute): New.
	(gori_compute::edge_range_p): Rename from outgoing_edge_range_p
	and use inherited routine instead of member method.
	* gimple-range-gori.h (class gori_compute): Inherit from
	gimple_outgoing_range, adjust protoypes.
	(gori_compute::outgpoing): Delete.
	* gimple-range-path.cc (path_range_query::compute_ranges_in_block): Use
	renamed edge_range_p routine.
	* tree-ssa-loop-unswitch.cc (evaluate_control_stmt_using_entry_checks):
	Likewise.
---
 gcc/gimple-range-cache.cc     |  6 +++---
 gcc/gimple-range-edge.h       | 15 ++++++++++++++-
 gcc/gimple-range-fold.cc      |  4 ++--
 gcc/gimple-range-gori.cc      | 13 ++++++++-----
 gcc/gimple-range-gori.h       | 10 +++++-----
 gcc/gimple-range-path.cc      |  4 ++--
 gcc/tree-ssa-loop-unswitch.cc |  4 ++--
 7 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index c52475852a9..40e4baa6289 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -950,7 +950,7 @@  update_list::pop ()
 // --------------------------------------------------------------------------
 
 ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses)
-						: m_gori (not_executable_flag)
+  : m_gori (not_executable_flag, param_vrp_switch_limit)
 {
   m_workback.create (0);
   m_workback.safe_grow_cleared (last_basic_block_for_fn (cfun));
@@ -1178,7 +1178,7 @@  ranger_cache::edge_range (vrange &r, edge e, tree name, enum rfd_mode mode)
   if ((e->flags & (EDGE_EH | EDGE_ABNORMAL)) == 0)
     infer_oracle ().maybe_adjust_range (r, name, e->src);
   Value_Range er (TREE_TYPE (name));
-  if (m_gori.outgoing_edge_range_p (er, e, name, *this))
+  if (m_gori.edge_range_p (er, e, name, *this))
     r.intersect (er);
   return true;
 }
@@ -1738,7 +1738,7 @@  ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb,
 
       edge e = single_pred_edge (prev_bb);
       bb = e->src;
-      if (m_gori.outgoing_edge_range_p (er, e, name, *this))
+      if (m_gori.edge_range_p (er, e, name, *this))
 	{
 	  r.intersect (er);
 	  // If this is a normal edge, apply any inferred ranges.
diff --git a/gcc/gimple-range-edge.h b/gcc/gimple-range-edge.h
index ce8b04f6bad..be1f0c2cc15 100644
--- a/gcc/gimple-range-edge.h
+++ b/gcc/gimple-range-edge.h
@@ -48,9 +48,22 @@  class gimple_outgoing_range
 {
 public:
   gimple_outgoing_range (int max_sw_edges = 0);
-  ~gimple_outgoing_range ();
+  virtual ~gimple_outgoing_range ();
   gimple *edge_range_p (irange &r, edge e);
   void set_switch_limit (int max_sw_edges = INT_MAX);
+
+  virtual bool edge_range_p (vrange &, edge, tree, range_query &)
+    { return false; }
+  virtual bool condexpr_adjust (vrange &, vrange &, gimple *, tree, tree, tree,
+				class fur_source &) { return false; }
+  virtual bool has_edge_range_p (tree, basic_block = NULL) { return false; }
+  virtual bool has_edge_range_p (tree, edge ) { return false; }
+  virtual void dump (FILE *) { }
+  virtual bool compute_operand_range (vrange &, gimple *, const vrange &, tree,
+				      fur_source &,
+				      class value_relation * = NULL)
+    { return false; }
+  virtual class gori_map *map () { return NULL; }
 private:
   void calc_switch_ranges (gswitch *sw);
   bool switch_edge_range (irange &r, gswitch *sw, edge e);
diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index b626855c51a..37c16761ba6 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -1368,14 +1368,14 @@  fur_source::register_outgoing_edges (gcond *s, irange &lhs_range,
 	{
 	  r1.set_varying (TREE_TYPE (ssa1));
 	  r2.set_varying (TREE_TYPE (ssa2));
-	  if (e0 && gori ()->outgoing_edge_range_p (r, e0, name, *m_query)
+	  if (e0 && gori ()->edge_range_p (r, e0, name, *m_query)
 	      && r.singleton_p ())
 	    {
 	      relation_kind relation = handler.op1_op2_relation (r, r1, r2);
 	      if (relation != VREL_VARYING)
 		register_relation (e0, relation, ssa1, ssa2);
 	    }
-	  if (e1 && gori ()->outgoing_edge_range_p (r, e1, name, *m_query)
+	  if (e1 && gori ()->edge_range_p (r, e1, name, *m_query)
 	      && r.singleton_p ())
 	    {
 	      relation_kind relation = handler.op1_op2_relation (r, r1, r2);
diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index fa4a235f08b..a7543064258 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -557,8 +557,8 @@  debug (gori_map &g)
 
 // Construct a gori_compute object.
 
-gori_compute::gori_compute (int not_executable_flag)
-		      : outgoing (param_vrp_switch_limit), tracer ("GORI ")
+gori_compute::gori_compute (int not_executable_flag, int sw_max_edges)
+  : gimple_outgoing_range (sw_max_edges), tracer ("GORI ")
 {
   m_not_executable_flag = not_executable_flag;
   // Create a boolean_type true and false range.
@@ -568,6 +568,10 @@  gori_compute::gori_compute (int not_executable_flag)
     tracer.enable_trace ();
 }
 
+gori_compute::~gori_compute ()
+{
+}
+
 // Given the switch S, return an evaluation in R for NAME when the lhs
 // evaluates to LHS.  Returning false means the name being looked for
 // was not resolvable.
@@ -1380,8 +1384,7 @@  gori_compute::has_edge_range_p (tree name, edge e)
 // control edge or NAME is not defined by this edge.
 
 bool
-gori_compute::outgoing_edge_range_p (vrange &r, edge e, tree name,
-				     range_query &q)
+gori_compute::edge_range_p (vrange &r, edge e, tree name, range_query &q)
 {
   unsigned idx;
 
@@ -1397,7 +1400,7 @@  gori_compute::outgoing_edge_range_p (vrange &r, edge e, tree name,
   gcc_checking_assert (gimple_range_ssa_p (name));
   int_range_max lhs;
   // Determine if there is an outgoing edge.
-  gimple *stmt = outgoing.edge_range_p (lhs, e);
+  gimple *stmt = gimple_outgoing_range::edge_range_p (lhs, e);
   if (!stmt)
     return false;
 
diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h
index ae857ecb2b5..c7a707ee724 100644
--- a/gcc/gimple-range-gori.h
+++ b/gcc/gimple-range-gori.h
@@ -127,7 +127,7 @@  private:
 //   on *ANY* edge that has been seen.  FALSE indicates that the global value
 //   is applicable everywhere that has been processed.
 //
-// outgoing_edge_range_p (vrange &range, edge e, tree name)
+// edge_range_p (vrange &range, edge e, tree name)
 //   Actually does the calculation of RANGE for name on E
 //   This represents application of whatever static range effect edge E
 //   may have on NAME, not any cumulative effect.
@@ -161,11 +161,12 @@  private:
 
 class value_relation;
 
-class gori_compute
+class gori_compute : public gimple_outgoing_range
 {
 public:
-  gori_compute (int not_executable_flag = 0);
-  bool outgoing_edge_range_p (vrange &r, edge e, tree name, range_query &q);
+  gori_compute (int not_executable_flag = 0, int max_sw_edges = 0);
+  virtual ~gori_compute ();
+  bool edge_range_p (vrange &r, edge e, tree name, range_query &q);
   bool condexpr_adjust (vrange &r1, vrange &r2, gimple *s, tree cond, tree op1,
 			tree op2, fur_source &src);
   bool has_edge_range_p (tree name, basic_block bb = NULL);
@@ -205,7 +206,6 @@  private:
   int_range<2> m_bool_zero;	// Boolean false cached.
   int_range<2> m_bool_one;	// Boolean true cached.
 
-  gimple_outgoing_range outgoing;	// Edge values for COND_EXPR & SWITCH_EXPR.
   range_tracer tracer;
   int m_not_executable_flag;
 };
diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc
index 5043c00d482..03f73218a57 100644
--- a/gcc/gimple-range-path.cc
+++ b/gcc/gimple-range-path.cc
@@ -415,7 +415,7 @@  path_range_query::compute_ranges_in_block (basic_block bb)
     {
       tree name = ssa_name (i);
       Value_Range r (TREE_TYPE (name));
-      if (g.outgoing_edge_range_p (r, e, name, *this))
+      if (g.edge_range_p (r, e, name, *this))
 	{
 	  Value_Range cached_range (TREE_TYPE (name));
 	  if (get_cache (cached_range, name))
@@ -424,7 +424,7 @@  path_range_query::compute_ranges_in_block (basic_block bb)
 	  m_cache.set_range (name, r);
 	  if (DEBUG_SOLVER)
 	    {
-	      fprintf (dump_file, "outgoing_edge_range_p for ");
+	      fprintf (dump_file, "edge_range_p for ");
 	      print_generic_expr (dump_file, name, TDF_SLIM);
 	      fprintf (dump_file, " on edge %d->%d ",
 		       e->src->index, e->dest->index);
diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc
index 9c284ce26ae..14b0df1aefe 100644
--- a/gcc/tree-ssa-loop-unswitch.cc
+++ b/gcc/tree-ssa-loop-unswitch.cc
@@ -763,8 +763,8 @@  evaluate_control_stmt_using_entry_checks (gimple *stmt,
 	    continue;
 
 	  int_range_max r;
-	  if (!ranger->gori ().outgoing_edge_range_p (r, e, idx,
-						      *get_global_range_query ()))
+	  if (!ranger->gori ().edge_range_p (r, e, idx,
+					     *get_global_range_query ()))
 	    continue;
 	  r.intersect (path_range);
 	  if (r.undefined_p ())
-- 
2.41.0