]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Default gimple_outgoing_range to not process switches.
authorAndrew MacLeod <amacleod@redhat.com>
Mon, 6 May 2024 16:04:24 +0000 (12:04 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Thu, 23 May 2024 20:48:44 +0000 (16:48 -0400)
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
gcc/gimple-range-edge.h

index 3811a0995aa57f60dda299d7a97a55d47123a8ab..0c75ad0519c00b2f00391c607cde96325e8cc8b5 100644 (file)
@@ -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));
index 9ac0617f970bc5a03dfd8048f07794541f3a2236..ce8b04f6bada1ec605ea9bdf42fb488f703f9deb 100644 (file)
@@ -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);