diff mbox series

[COMMITTED,07/12] - Default gimple_outgoing_range to not process switches.

Message ID 40aae0c8-e7b1-48e8-bf1d-d6d55df87a76@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 adjusts the way gimple_outgoing_range works.  This is the 
static edge calculator that provide ranges on edges for TRUE/FALSE 
edges, as well as calculated the ranges on switch edges.   It was a 
component of ranger before or something that could be included if a pass 
wanted it.

this adjusts the way it works in preparation for being more tightly 
integrated into GORI.  It now works by always working for TRUE/FALSE 
edges, and uses a set_sw_limit routine to enable or disable switch 
processing.   Functionally there is little difference, but it will allow 
it to be the base for a GORI object now.

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

Patch

From 1ec8e2027a99a5ddca933a37b3cf5ef322208c5a Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Mon, 6 May 2024 12:04:24 -0400
Subject: [PATCH 07/12] Default gimple_outgoing_range to not process switches.

Change the default constructor to not process switches, add method to
enable/disable switch processing.

	* gimple-range-edge.cc (gimple_outgoing_range::gimple_outgoing_range):
	Do not allocate a range allocator at construction time.
	(gimple_outgoing_range::~gimple_outgoing_range): Delete allocator
	if one was allocated.
	(gimple_outgoing_range::set_switch_limit): New.
	(gimple_outgoing_range::switch_edge_range): Create an allocator if one
	does not exist.
	(gimple_outgoing_range::edge_range_p): Check for zero edges.
	* gimple-range-edge.h (class gimple_outgoing_range): Adjust prototypes.
---
 gcc/gimple-range-edge.cc | 23 +++++++++++++++++------
 gcc/gimple-range-edge.h  | 12 +++++++++++-
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/gcc/gimple-range-edge.cc b/gcc/gimple-range-edge.cc
index 3811a0995aa..0c75ad0519c 100644
--- a/gcc/gimple-range-edge.cc
+++ b/gcc/gimple-range-edge.cc
@@ -51,7 +51,6 @@  gimple_outgoing_range_stmt_p (basic_block bb)
   return NULL;
 }
 
-
 // Return a TRUE or FALSE range representing the edge value of a GCOND.
 
 void
@@ -64,22 +63,32 @@  gcond_edge_range (irange &r, edge e)
     r = range_false ();
 }
 
+// Construct a gimple_outgoing_range object.  No memory is allocated.
 
 gimple_outgoing_range::gimple_outgoing_range (int max_sw_edges)
 {
   m_edge_table = NULL;
+  m_range_allocator = NULL;
   m_max_edges = max_sw_edges;
-  m_range_allocator = new vrange_allocator;
 }
 
+// Destruct an edge object, disposing of any memory allocated.
 
 gimple_outgoing_range::~gimple_outgoing_range ()
 {
   if (m_edge_table)
     delete m_edge_table;
-  delete m_range_allocator;
+  if (m_range_allocator)
+    delete m_range_allocator;
 }
 
+// Set a new switch limit.
+
+void
+gimple_outgoing_range::set_switch_limit (int max_sw_edges)
+{
+  m_max_edges = max_sw_edges;
+}
 
 // Get a range for a switch edge E from statement S and return it in R.
 // Use a cached value if it exists, or calculate it if not.
@@ -96,8 +105,10 @@  gimple_outgoing_range::switch_edge_range (irange &r, gswitch *sw, edge e)
       TYPE_PRECISION (TREE_TYPE (gimple_switch_index (sw))))
     return false;
 
-   if (!m_edge_table)
-     m_edge_table = new hash_map<edge, vrange_storage *> (n_edges_for_fn (cfun));
+  if (!m_edge_table)
+    m_edge_table = new hash_map<edge, vrange_storage *> (n_edges_for_fn (cfun));
+  if (!m_range_allocator)
+    m_range_allocator = new vrange_allocator;
 
    vrange_storage **val = m_edge_table->get (e);
    if (!val)
@@ -202,7 +213,7 @@  gimple_outgoing_range::edge_range_p (irange &r, edge e)
     }
 
   // Only process switches if it within the size limit.
-  if (EDGE_COUNT (e->src->succs) > (unsigned)m_max_edges)
+  if (m_max_edges == 0 || (EDGE_COUNT (e->src->succs) > (unsigned)m_max_edges))
     return NULL;
 
   gcc_checking_assert (is_a<gswitch *> (s));
diff --git a/gcc/gimple-range-edge.h b/gcc/gimple-range-edge.h
index 9ac0617f970..ce8b04f6bad 100644
--- a/gcc/gimple-range-edge.h
+++ b/gcc/gimple-range-edge.h
@@ -34,13 +34,23 @@  along with GCC; see the file COPYING3.  If not see
 // The API is simple, just ask for the range on the edge.
 // The return value is NULL for no range, or the branch statement which the
 // edge gets the range from, along with the range.
+//
+// THe switch_limit is the number of switch edges beyond which the switch
+// is ignored (ie, edge_range_p () will return NULL as if the sitch was not
+// there.  THis value can be adjusted any time via set_switch_limit ().
+// THe default is 0, no switches are precoessed until set_switch_limit () is
+// called, and then the default is INT_MAX.
+//
+// No memory is allocated until an edge for a switch is processed which also
+// falls under the edge limit criteria.
 
 class gimple_outgoing_range
 {
 public:
-  gimple_outgoing_range (int max_sw_edges = INT_MAX);
+  gimple_outgoing_range (int max_sw_edges = 0);
   ~gimple_outgoing_range ();
   gimple *edge_range_p (irange &r, edge e);
+  void set_switch_limit (int max_sw_edges = INT_MAX);
 private:
   void calc_switch_ranges (gswitch *sw);
   bool switch_edge_range (irange &r, gswitch *sw, edge e);
-- 
2.41.0