diff mbox series

[COMMITTED,04/12] - Allow components to be shared among range-queries.

Message ID 593a9ac1-ecdc-42b9-ac63-88e31dc1ff2a@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
Ranger and ranger's cache are both range_query based, but they need to 
share some common components. The path ranger also needs to share the 
GORI component.   Up until now, they have simple copied pointers to 
share, but this patch provides a protected API to allow them to share 
without knowing what all components are involved.

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

Patch

From ef99d19569a1c5fafa5784c2c2f7855b6e62ffd8 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Fri, 17 May 2024 10:44:27 -0400
Subject: [PATCH 04/12] Allow components to be shared among range-queries.

Ranger and the ranger cache need to share components, this provides a
blessed way to do so.

	* gimple-range.cc (gimple_ranger::gimple_ranger): Share the
	components from ranger_cache.
	(gimple_ranger::~gimple_ranger): Don't clear pointer.
	* value-query.cc (range_query::share_query): New.
	(range_query::range_query): Clear shared component flag.
	(range_query::~range_query): Don't free shared component copies.
	* value-query.h (share_query): New prototype.
	(m_shared_copy_p): New member.
---
 gcc/gimple-range.cc |  4 +---
 gcc/value-query.cc  | 11 +++++++++++
 gcc/value-query.h   |  5 +++++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 9664300a80b..4326976fc2a 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -44,7 +44,7 @@  gimple_ranger::gimple_ranger (bool use_imm_uses) :
 	current_bb (NULL)
 {
   // Share the oracle from the cache.
-  m_relation = &m_cache.relation ();
+  share_query (m_cache);
   if (dump_file && (param_ranger_debug & RANGER_DEBUG_TRACE))
     tracer.enable_trace ();
   m_stmt_list.create (0);
@@ -67,8 +67,6 @@  gimple_ranger::gimple_ranger (bool use_imm_uses) :
 
 gimple_ranger::~gimple_ranger ()
 {
-  // Restore the original oracle.
-  m_relation = NULL;
   m_stmt_list.release ();
 }
 
diff --git a/gcc/value-query.cc b/gcc/value-query.cc
index db64a95a284..adcc59cadbf 100644
--- a/gcc/value-query.cc
+++ b/gcc/value-query.cc
@@ -211,13 +211,24 @@  range_query::destroy_relation_oracle ()
     }
 }
 
+void
+range_query::share_query (range_query &q)
+{
+  m_relation = q.m_relation;
+  m_shared_copy_p = true;
+}
+
 range_query::range_query ()
 {
   m_relation = &default_relation_oracle;
+  m_shared_copy_p = false;
 }
 
 range_query::~range_query ()
 {
+  // Do not destroy anything if this is a shared copy.
+  if (m_shared_copy_p)
+    return;
   destroy_relation_oracle ();
 }
 
diff --git a/gcc/value-query.h b/gcc/value-query.h
index a8688a099fa..a5735902af0 100644
--- a/gcc/value-query.h
+++ b/gcc/value-query.h
@@ -88,6 +88,11 @@  protected:
 			     basic_block bbentry, basic_block bbexit);
   bool get_arith_expr_range (vrange &r, tree expr, gimple *stmt);
   relation_oracle *m_relation;
+  // When multiple related range queries wish to share oracles.
+  // This is an internal interface
+  void share_query (range_query &q);
+  bool m_shared_copy_p;
+
 };
 
 // Global ranges for SSA names using SSA_NAME_RANGE_INFO.
-- 
2.41.0