public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Enable pointer_query caching throughout.
@ 2022-02-02 23:35 Martin Sebor
  2022-02-02 23:35 ` [PATCH 1/3] Make pointer_query cache a private member Martin Sebor
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Martin Sebor @ 2022-02-02 23:35 UTC (permalink / raw)
  To: gcc-patches

Richard, as we discussed(*), this patch series enables the pointer_query
cache in the remaining two passes where it's currently disabled.  Since
not using the cache is not an option anymore, the first patch in
the series makes it a private member of the pointer_query class and its
use unconditional.  It also simplifies the two passes that use it to
avoid having to install it.

Tested on x86_64-linux.

Martin

[*] For reference:
https://gcc.gnu.org/pipermail/gcc-patches/2022-January/589243.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] Make pointer_query cache a private member.
  2022-02-02 23:35 [PATCH 0/3] Enable pointer_query caching throughout Martin Sebor
@ 2022-02-02 23:35 ` Martin Sebor
  2022-02-02 23:35 ` [PATCH 2/3] Enable pointer_query caching for -Warray-bounds Martin Sebor
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Martin Sebor @ 2022-02-02 23:35 UTC (permalink / raw)
  To: gcc-patches

The first patch in the series make the pointer_query cache a private
member of the class and removes the ability to create an object of it
without one, or one with an external cache.  It also simplifies existing
clients of the class that provide an external cache to avoid doing so.

gcc/ChangeLog:

	* gimple-ssa-warn-access.cc (pass_waccess::pass_waccess): Remove
	pointer_query cache.
	* pointer-query.cc (pointer_query::pointer_query): Remove cache
	argument.  Zero-initialize new cache member.
	(pointer_query::get_ref): Replace cache pointer with direct access.
	(pointer_query::put_ref): Same.
	(pointer_query::flush_cache): Same.
	(pointer_query::dump): Same.
	* pointer-query.h (class pointer_query): Remove cache argument from
	ctor.  Change cache pointer to cache subobject member.
	* tree-ssa-strlen.cc: Remove pointer_query cache.
---
 gcc/gimple-ssa-warn-access.cc |  8 ++--
 gcc/pointer-query.cc          | 74 +++++++++++++++--------------------
 gcc/pointer-query.h           | 12 +++---
 gcc/tree-ssa-strlen.cc        |  8 ++--
 4 files changed, 44 insertions(+), 58 deletions(-)

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index ad5e2f4458e..4b3d2c00b03 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -2137,10 +2137,9 @@ private:
   /* Return true if use follows an invalidating statement.  */
   bool use_after_inval_p (gimple *, gimple *, bool = false);
 
-  /* A pointer_query object and its cache to store information about
-     pointers and their targets in.  */
+  /* A pointer_query object to store information about pointers and
+     their targets in.  */
   pointer_query m_ptr_qry;
-  pointer_query::cache_type m_var_cache;
   /* Mapping from DECLs and their clobber statements in the function.  */
   hash_map<tree, gimple *> m_clobbers;
   /* A bit is set for each basic block whose statements have been assigned
@@ -2158,8 +2157,7 @@ private:
 
 pass_waccess::pass_waccess (gcc::context *ctxt)
   : gimple_opt_pass (pass_data_waccess, ctxt),
-    m_ptr_qry (NULL, &m_var_cache),
-    m_var_cache (),
+    m_ptr_qry (NULL),
     m_clobbers (),
     m_bb_uids_set (),
     m_func (),
diff --git a/gcc/pointer-query.cc b/gcc/pointer-query.cc
index b092ef4fbdc..afbcd0a15ea 100644
--- a/gcc/pointer-query.cc
+++ b/gcc/pointer-query.cc
@@ -1433,12 +1433,11 @@ ssa_name_limit_t::~ssa_name_limit_t ()
 }
 
 /* Default ctor.  Initialize object with pointers to the range_query
-   and cache_type instances to use or null.  */
+   instance to use or null.  */
 
-pointer_query::pointer_query (range_query *qry /* = NULL */,
-			      cache_type *cache /* = NULL */)
-: rvals (qry), var_cache (cache), hits (), misses (),
-  failures (), depth (), max_depth ()
+pointer_query::pointer_query (range_query *qry /* = NULL */)
+  : rvals (qry), hits (), misses (), failures (), depth (), max_depth (),
+    var_cache ()
 {
   /* No op.  */
 }
@@ -1449,28 +1448,22 @@ pointer_query::pointer_query (range_query *qry /* = NULL */,
 const access_ref *
 pointer_query::get_ref (tree ptr, int ostype /* = 1 */) const
 {
-  if (!var_cache)
-    {
-      ++misses;
-      return NULL;
-    }
-
   unsigned version = SSA_NAME_VERSION (ptr);
   unsigned idx = version << 1 | (ostype & 1);
-  if (var_cache->indices.length () <= idx)
+  if (var_cache.indices.length () <= idx)
     {
       ++misses;
       return NULL;
     }
 
-  unsigned cache_idx = var_cache->indices[idx];
-  if (var_cache->access_refs.length () <= cache_idx)
+  unsigned cache_idx = var_cache.indices[idx];
+  if (var_cache.access_refs.length () <= cache_idx)
     {
       ++misses;
       return NULL;
     }
 
-  access_ref &cache_ref = var_cache->access_refs[cache_idx];
+  const access_ref &cache_ref = var_cache.access_refs[cache_idx];
   if (cache_ref.ref)
     {
       ++hits;
@@ -1491,17 +1484,17 @@ pointer_query::get_ref (tree ptr, gimple *stmt, access_ref *pref,
   const unsigned version
     = TREE_CODE (ptr) == SSA_NAME ? SSA_NAME_VERSION (ptr) : 0;
 
-  if (var_cache && version)
+  if (version)
     {
       unsigned idx = version << 1 | (ostype & 1);
-      if (idx < var_cache->indices.length ())
+      if (idx < var_cache.indices.length ())
 	{
-	  unsigned cache_idx = var_cache->indices[idx] - 1;
-	  if (cache_idx < var_cache->access_refs.length ()
-	      && var_cache->access_refs[cache_idx].ref)
+	  unsigned cache_idx = var_cache.indices[idx] - 1;
+	  if (cache_idx < var_cache.access_refs.length ()
+	      && var_cache.access_refs[cache_idx].ref)
 	    {
 	      ++hits;
-	      *pref = var_cache->access_refs[cache_idx];
+	      *pref = var_cache.access_refs[cache_idx];
 	      return true;
 	    }
 	}
@@ -1525,7 +1518,7 @@ void
 pointer_query::put_ref (tree ptr, const access_ref &ref, int ostype /* = 1 */)
 {
   /* Only add populated/valid entries.  */
-  if (!var_cache || !ref.ref || ref.sizrng[0] < 0)
+  if (!ref.ref || ref.sizrng[0] < 0)
     return;
 
   /* Add REF to the two-level cache.  */
@@ -1535,20 +1528,20 @@ pointer_query::put_ref (tree ptr, const access_ref &ref, int ostype /* = 1 */)
   /* Grow INDICES if necessary.  An index is valid if it's nonzero.
      Its value minus one is the index into ACCESS_REFS.  Not all
      entries are valid.  */
-  if (var_cache->indices.length () <= idx)
-    var_cache->indices.safe_grow_cleared (idx + 1);
+  if (var_cache.indices.length () <= idx)
+    var_cache.indices.safe_grow_cleared (idx + 1);
 
-  if (!var_cache->indices[idx])
-    var_cache->indices[idx] = var_cache->access_refs.length () + 1;
+  if (!var_cache.indices[idx])
+    var_cache.indices[idx] = var_cache.access_refs.length () + 1;
 
   /* Grow ACCESS_REF cache if necessary.  An entry is valid if its
      REF member is nonnull.  All entries except for the last two
      are valid.  Once nonnull, the REF value must stay unchanged.  */
-  unsigned cache_idx = var_cache->indices[idx];
-  if (var_cache->access_refs.length () <= cache_idx)
-    var_cache->access_refs.safe_grow_cleared (cache_idx + 1);
+  unsigned cache_idx = var_cache.indices[idx];
+  if (var_cache.access_refs.length () <= cache_idx)
+    var_cache.access_refs.safe_grow_cleared (cache_idx + 1);
 
-  access_ref &cache_ref = var_cache->access_refs[cache_idx];
+  access_ref &cache_ref = var_cache.access_refs[cache_idx];
   if (cache_ref.ref)
   {
     gcc_checking_assert (cache_ref.ref == ref.ref);
@@ -1563,10 +1556,8 @@ pointer_query::put_ref (tree ptr, const access_ref &ref, int ostype /* = 1 */)
 void
 pointer_query::flush_cache ()
 {
-  if (!var_cache)
-    return;
-  var_cache->indices.release ();
-  var_cache->access_refs.release ();
+  var_cache.indices.release ();
+  var_cache.access_refs.release ();
 }
 
 /* Dump statistics and, optionally, cache contents to DUMP_FILE.  */
@@ -1574,20 +1565,17 @@ pointer_query::flush_cache ()
 void
 pointer_query::dump (FILE *dump_file, bool contents /* = false */)
 {
-  if (!var_cache)
-    return;
-
   unsigned nused = 0, nrefs = 0;
-  unsigned nidxs = var_cache->indices.length ();
+  unsigned nidxs = var_cache.indices.length ();
   for (unsigned i = 0; i != nidxs; ++i)
     {
-      unsigned ari = var_cache->indices[i];
+      unsigned ari = var_cache.indices[i];
       if (!ari)
 	continue;
 
       ++nused;
 
-      const access_ref &aref = var_cache->access_refs[ari];
+      const access_ref &aref = var_cache.access_refs[ari];
       if (!aref.ref)
 	continue;
 
@@ -1604,7 +1592,7 @@ pointer_query::dump (FILE *dump_file, bool contents /* = false */)
 	   "  failures:           %u\n"
 	   "  max_depth:          %u\n",
 	   nidxs, nused,
-	   var_cache->access_refs.length (), nrefs,
+	   var_cache.access_refs.length (), nrefs,
 	   hits, misses, failures, max_depth);
 
   if (!contents || !nidxs)
@@ -1614,11 +1602,11 @@ pointer_query::dump (FILE *dump_file, bool contents /* = false */)
 
   for (unsigned i = 0; i != nidxs; ++i)
     {
-      unsigned ari = var_cache->indices[i];
+      unsigned ari = var_cache.indices[i];
       if (!ari)
 	continue;
 
-      const access_ref &aref = var_cache->access_refs[ari];
+      const access_ref &aref = var_cache.access_refs[ari];
       if (!aref.ref)
 	continue;
 
diff --git a/gcc/pointer-query.h b/gcc/pointer-query.h
index dbdcd593b79..4c725eeaf34 100644
--- a/gcc/pointer-query.h
+++ b/gcc/pointer-query.h
@@ -159,7 +159,6 @@ class pointer_query
 {
   DISABLE_COPY_AND_ASSIGN (pointer_query);
 
-public:
   /* Type of the two-level cache object defined by clients of the class
      to have pointer SSA_NAMEs cached for speedy access.  */
   struct cache_type
@@ -170,8 +169,9 @@ public:
     vec<access_ref> access_refs;
   };
 
-  /* Construct an object with the given Ranger instance and cache.  */
-  explicit pointer_query (range_query * = nullptr, cache_type * = nullptr);
+public:
+  /* Construct an object with the given Ranger instance.  */
+  explicit pointer_query (range_query * = nullptr);
 
   /* Retrieve the access_ref for a variable from cache if it's there.  */
   const access_ref* get_ref (tree, int = 1) const;
@@ -190,8 +190,6 @@ public:
 
   /* A Ranger instance.  May be null to use global ranges.  */
   range_query *rvals;
-  /* Cache of SSA_NAMEs.  May be null to disable caching.  */
-  cache_type *var_cache;
 
   /* Cache performance counters.  */
   mutable unsigned hits;
@@ -199,6 +197,10 @@ public:
   mutable unsigned failures;
   mutable unsigned depth;
   mutable unsigned max_depth;
+
+private:
+  /* Cache of SSA_NAMEs.  May be null to disable caching.  */
+  cache_type var_cache;
 };
 
 /* Describes a pair of references used in an access by built-in
diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc
index df97b86d5f8..d5360f0bc28 100644
--- a/gcc/tree-ssa-strlen.cc
+++ b/gcc/tree-ssa-strlen.cc
@@ -236,8 +236,7 @@ class strlen_pass : public dom_walker
 public:
   strlen_pass (cdi_direction direction)
     : dom_walker (direction),
-      ptr_qry (&m_ranger, &var_cache),
-      var_cache (),
+      ptr_qry (&m_ranger),
       m_cleanup_cfg (false)
   {
   }
@@ -301,10 +300,9 @@ public:
 
   gimple_ranger m_ranger;
 
-  /* A pointer_query object and its cache to store information about
-     pointers and their targets in.  */
+  /* A pointer_query object to store information about pointers and
+     their targets in.  */
   pointer_query ptr_qry;
-  pointer_query::cache_type var_cache;
 
   gimple_stmt_iterator m_gsi;
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/3] Enable pointer_query caching for -Warray-bounds.
  2022-02-02 23:35 [PATCH 0/3] Enable pointer_query caching throughout Martin Sebor
  2022-02-02 23:35 ` [PATCH 1/3] Make pointer_query cache a private member Martin Sebor
@ 2022-02-02 23:35 ` Martin Sebor
  2022-02-02 23:35 ` [PATCH 3/3] Enable pointer_query caching for -Wrestrict Martin Sebor
  2022-02-03  9:07 ` [PATCH 0/3] Enable pointer_query caching throughout Richard Biener
  3 siblings, 0 replies; 10+ messages in thread
From: Martin Sebor @ 2022-02-02 23:35 UTC (permalink / raw)
  To: gcc-patches

The second patch in the series adds a pointer_query instance to the array
bounds checker object and uses it for each invocation to check a function.

gcc/ChangeLog:

	* gimple-array-bounds.cc (array_bounds_checker::array_bounds_checker):
	Define ctor.
	(array_bounds_checker::get_value_range): Use new member.
	(array_bounds_checker::check_mem_ref): Same.
	* gimple-array-bounds.h (array_bounds_checker::array_bounds_checker):
	Outline ctor.
	(array_bounds_checker::m_ptr_query): New member.
---
 gcc/gimple-array-bounds.cc | 13 ++++++++++---
 gcc/gimple-array-bounds.h  | 10 ++++++----
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc
index 80c70b49607..7ec8b08c8d2 100644
--- a/gcc/gimple-array-bounds.cc
+++ b/gcc/gimple-array-bounds.cc
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree.h"
 #include "gimple.h"
 #include "ssa.h"
+#include "pointer-query.h"
 #include "gimple-array-bounds.h"
 #include "gimple-iterator.h"
 #include "gimple-walk.h"
@@ -37,7 +38,13 @@ along with GCC; see the file COPYING3.  If not see
 #include "domwalk.h"
 #include "tree-cfg.h"
 #include "attribs.h"
-#include "pointer-query.h"
+
+array_bounds_checker::array_bounds_checker (struct function *func,
+					    range_query *qry)
+  : fun (func), m_ptr_qry (qry)
+{
+  /* No-op.  */
+}
 
 // This purposely returns a value_range, not a value_range_equiv, to
 // break the dependency on equivalences for this pass.
@@ -45,7 +52,7 @@ along with GCC; see the file COPYING3.  If not see
 const value_range *
 array_bounds_checker::get_value_range (const_tree op, gimple *stmt)
 {
-  return ranges->get_value_range (op, stmt);
+  return m_ptr_qry.rvals->get_value_range (op, stmt);
 }
 
 /* Try to determine the DECL that REF refers to.  Return the DECL or
@@ -401,7 +408,7 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref,
       axssize = wi::to_offset (access_size);
 
   access_ref aref;
-  if (!compute_objsize (ref, m_stmt, 0, &aref, ranges))
+  if (!m_ptr_qry.get_ref (ref, m_stmt, &aref, 0))
     return false;
 
   if (aref.offset_in_range (axssize))
diff --git a/gcc/gimple-array-bounds.h b/gcc/gimple-array-bounds.h
index d42146b87c8..eb399271da7 100644
--- a/gcc/gimple-array-bounds.h
+++ b/gcc/gimple-array-bounds.h
@@ -20,13 +20,14 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_GIMPLE_ARRAY_BOUNDS_H
 #define GCC_GIMPLE_ARRAY_BOUNDS_H
 
+#include "pointer-query.h"
+
 class array_bounds_checker
 {
   friend class check_array_bounds_dom_walker;
 
 public:
-  array_bounds_checker (struct function *fun, range_query *v)
-    : fun (fun), ranges (v) { }
+  array_bounds_checker (struct function *, range_query *);
   void check ();
 
 private:
@@ -38,8 +39,9 @@ private:
 
   /* Current function.  */
   struct function *fun;
-  /* Ranger instance.  */
-  range_query *ranges;
+  /* A pointer_query object to store information about pointers and
+     their targets in.  */
+  pointer_query m_ptr_qry;
   /* Current statement.  */
   gimple *m_stmt;
 };
-- 
2.34.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/3] Enable pointer_query caching for -Wrestrict.
  2022-02-02 23:35 [PATCH 0/3] Enable pointer_query caching throughout Martin Sebor
  2022-02-02 23:35 ` [PATCH 1/3] Make pointer_query cache a private member Martin Sebor
  2022-02-02 23:35 ` [PATCH 2/3] Enable pointer_query caching for -Warray-bounds Martin Sebor
@ 2022-02-02 23:35 ` Martin Sebor
  2022-02-03  9:07 ` [PATCH 0/3] Enable pointer_query caching throughout Richard Biener
  3 siblings, 0 replies; 10+ messages in thread
From: Martin Sebor @ 2022-02-02 23:35 UTC (permalink / raw)
  To: gcc-patches

The third patch in the series adds a pointer_query instance to the wrestrict
pass and uses it for each invocation to check a function.

gcc/ChangeLog:

	* gimple-ssa-warn-restrict.cc (class pass_wrestrict): Outline ctor.
	(pass_wrestrict::m_ptr_qry): New member.
	(wrestrict_walk): Rename...
	(pass_wrestrict::check_block): ...to this.
	(pass_wrestrict::execute): Set up and tear down pointer_query and
	ranger.
	(builtin_memref::builtin_memref): Change ctor argument.  Simplify.
	(builtin_access::builtin_access): Same.
	(builtin_access::m_ptr_qry): New member.
	(check_call): Rename...
	(pass_wrestrict::check_call): ...to this.
	(check_bounds_or_overlap): Change argument.
	* gimple-ssa-warn-restrict.h (check_bounds_or_overlap): Same.
---
 gcc/gimple-ssa-warn-restrict.cc | 126 ++++++++++++++++----------------
 gcc/gimple-ssa-warn-restrict.h  |   2 +-
 2 files changed, 62 insertions(+), 66 deletions(-)

diff --git a/gcc/gimple-ssa-warn-restrict.cc b/gcc/gimple-ssa-warn-restrict.cc
index d1beb01fe89..72418398dad 100644
--- a/gcc/gimple-ssa-warn-restrict.cc
+++ b/gcc/gimple-ssa-warn-restrict.cc
@@ -62,46 +62,63 @@ const pass_data pass_data_wrestrict = {
 class pass_wrestrict : public gimple_opt_pass
 {
  public:
-  pass_wrestrict (gcc::context *ctxt)
-    : gimple_opt_pass (pass_data_wrestrict, ctxt)
-    { }
+  pass_wrestrict (gcc::context *);
 
-  opt_pass *clone () { return new pass_wrestrict (m_ctxt); }
+  // opt_pass *clone () { return new pass_wrestrict (m_ctxt); }
 
   virtual bool gate (function *);
   virtual unsigned int execute (function *);
+
+  void check_call (gimple *);
+
+  void check_block (basic_block);
+
+  /* A pointer_query object to store information about pointers and
+     their targets in.  */
+  pointer_query m_ptr_qry;
 };
 
+pass_wrestrict::pass_wrestrict (gcc::context *ctxt)
+  : gimple_opt_pass (pass_data_wrestrict, ctxt),
+    m_ptr_qry ()
+{ }
+
 bool
 pass_wrestrict::gate (function *fun ATTRIBUTE_UNUSED)
 {
   return warn_array_bounds || warn_restrict || warn_stringop_overflow;
 }
 
-static void check_call (range_query *, gimple *);
-
-static void
-wrestrict_walk (range_query *query, basic_block bb)
+void
+pass_wrestrict::check_block (basic_block bb)
 {
   /* Iterate over statements, looking for function calls.  */
-  for (gimple_stmt_iterator si = gsi_start_bb (bb); !gsi_end_p (si);
-       gsi_next (&si))
+  for (auto si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
     {
       gimple *stmt = gsi_stmt (si);
       if (!is_gimple_call (stmt))
 	continue;
 
-      check_call (query, stmt);
+      check_call (stmt);
     }
 }
 
 unsigned
 pass_wrestrict::execute (function *fun)
 {
-  gimple_ranger ranger;
+  /* Create a new ranger instance and associate it with FUN.  */
+  m_ptr_qry.rvals = enable_ranger (fun);
+
   basic_block bb;
   FOR_EACH_BB_FN (bb, fun)
-    wrestrict_walk (&ranger, bb);
+    check_block (bb);
+
+  m_ptr_qry.flush_cache ();
+
+  /* Release the ranger instance and replace it with a global ranger.
+     Also reset the pointer since calling disable_ranger() deletes it.  */
+  disable_ranger (fun);
+  m_ptr_qry.rvals = NULL;
 
   return 0;
 }
@@ -145,7 +162,7 @@ public:
      only the destination reference is.  */
   bool strbounded_p;
 
-  builtin_memref (range_query *, gimple *, tree, tree);
+  builtin_memref (pointer_query &, gimple *, tree, tree);
 
   tree offset_out_of_bounds (int, offset_int[3]) const;
 
@@ -153,7 +170,7 @@ private:
   /* Call statement to the built-in.  */
   gimple *stmt;
 
-  range_query *query;
+  pointer_query &m_ptr_qry;
 
   /* Ctor helper to set or extend OFFRANGE based on argument.  */
   void extend_offset_range (tree);
@@ -187,7 +204,8 @@ class builtin_access
 	    && detect_overlap != &builtin_access::no_overlap);
   }
 
-  builtin_access (range_query *, gimple *, builtin_memref &, builtin_memref &);
+  builtin_access (pointer_query &, gimple *,
+		  builtin_memref &, builtin_memref &);
 
   /* Entry point to determine overlap.  */
   bool overlap ();
@@ -225,7 +243,7 @@ class builtin_access
    a size SIZE in bytes.  If SIZE is NULL_TREE then the size is assumed
    to be unknown.  STMT is the statement in which expr appears in.  */
 
-builtin_memref::builtin_memref (range_query *query, gimple *stmt, tree expr,
+builtin_memref::builtin_memref (pointer_query &ptrqry, gimple *stmt, tree expr,
 				tree size)
 : ptr (expr),
   ref (),
@@ -238,7 +256,7 @@ builtin_memref::builtin_memref (range_query *query, gimple *stmt, tree expr,
   maxobjsize (tree_to_shwi (max_object_size ())),
   strbounded_p (),
   stmt (stmt),
-  query (query)
+  m_ptr_qry (ptrqry)
 {
   /* Unfortunately, wide_int default ctor is a no-op so array members
      of the type must be set individually.  */
@@ -257,7 +275,7 @@ builtin_memref::builtin_memref (range_query *query, gimple *stmt, tree expr,
       tree range[2];
       /* Determine the size range, allowing for the result to be [0, 0]
 	 for SIZE in the anti-range ~[0, N] where N >= PTRDIFF_MAX.  */
-      get_size_range (query, size, stmt, range, SR_ALLOW_ZERO);
+      get_size_range (m_ptr_qry.rvals, size, stmt, range, SR_ALLOW_ZERO);
       sizrange[0] = wi::to_offset (range[0]);
       sizrange[1] = wi::to_offset (range[1]);
       /* get_size_range returns SIZE_MAX for the maximum size.
@@ -334,23 +352,10 @@ builtin_memref::extend_offset_range (tree offset)
       /* A pointer offset is represented as sizetype but treated
 	 as signed.  */
       wide_int min, max;
-      value_range_kind rng;
+      value_range_kind rng = VR_VARYING;
       value_range vr;
-      if (query && query->range_of_expr (vr, offset, stmt))
-	{
-	  rng = vr.kind ();
-	  if (!vr.undefined_p ())
-	    {
-	      min = wi::to_wide (vr.min ());
-	      max = wi::to_wide (vr.max ());
-	    }
-	}
-      else
+      if (m_ptr_qry.rvals->range_of_expr (vr, offset, stmt))
 	{
-	  /* There is a global version here because
-	     check_bounds_or_overlap may be called from gimple
-	     fold during gimple lowering.  */
-	  get_range_query (cfun)->range_of_expr (vr, offset, stmt);
 	  rng = vr.kind ();
 	  if (!vr.undefined_p ())
 	    {
@@ -358,6 +363,7 @@ builtin_memref::extend_offset_range (tree offset)
 	      max = wi::to_wide (vr.max ());
 	    }
 	}
+
       if (rng == VR_ANTI_RANGE && wi::lts_p (max, min))
 	{
 	  /* Convert an anti-range whose upper bound is less than
@@ -674,7 +680,7 @@ builtin_memref::offset_out_of_bounds (int strict, offset_int ooboff[3]) const
 /* Create an association between the memory references DST and SRC
    for access by a call EXPR to a memory or string built-in funtion.  */
 
-builtin_access::builtin_access (range_query *query, gimple *call,
+builtin_access::builtin_access (pointer_query &ptrqry, gimple *call,
 				builtin_memref &dst,
 				builtin_memref &src)
 : dstref (&dst), srcref (&src), sizrange (), ovloff (), ovlsiz (),
@@ -766,39 +772,28 @@ builtin_access::builtin_access (range_query *query, gimple *call,
       return;
     }
 
-  const offset_int maxobjsize = dst.maxobjsize;
-
   /* Try to determine the size of the base object.  compute_objsize
      expects a pointer so create one if BASE is a non-pointer object.  */
-  tree addr;
   if (dst.basesize < 0)
     {
-      addr = dst.base;
-      if (!POINTER_TYPE_P (TREE_TYPE (addr)))
-	addr = build1 (ADDR_EXPR, (TREE_TYPE (addr)), addr);
-
-      if (tree dstsize = compute_objsize (addr, call, ostype))
-	dst.basesize = wi::to_offset (dstsize);
-      else if (POINTER_TYPE_P (TREE_TYPE (addr)))
-	dst.basesize = HOST_WIDE_INT_MIN;
+      access_ref aref;
+      if (ptrqry.get_ref (dst.base, call, &aref, ostype) && aref.base0)
+	dst.basesize = aref.sizrng[1];
       else
-	dst.basesize = maxobjsize;
+	dst.basesize = HOST_WIDE_INT_MIN;
     }
 
   if (src.base && src.basesize < 0)
     {
-      addr = src.base;
-      if (!POINTER_TYPE_P (TREE_TYPE (addr)))
-	addr = build1 (ADDR_EXPR, (TREE_TYPE (addr)), addr);
-
-      if (tree srcsize = compute_objsize (addr, call, ostype))
-	src.basesize = wi::to_offset (srcsize);
-      else if (POINTER_TYPE_P (TREE_TYPE (addr)))
-	src.basesize = HOST_WIDE_INT_MIN;
+      access_ref aref;
+      if (ptrqry.get_ref (src.base, call, &aref, ostype) && aref.base0)
+	src.basesize = aref.sizrng[1];
       else
-	src.basesize = maxobjsize;
+	src.basesize = HOST_WIDE_INT_MIN;
     }
 
+  const offset_int maxobjsize = dst.maxobjsize;
+
   /* Make adjustments for references to the same object by string
      built-in functions to reflect the constraints imposed by
      the function.  */
@@ -814,7 +809,7 @@ builtin_access::builtin_access (range_query *query, gimple *call,
 
       tree size = gimple_call_arg (call, sizeargno);
       tree range[2];
-      if (get_size_range (query, size, call, range, true))
+      if (get_size_range (ptrqry.rvals, size, call, range, true))
 	{
 	  bounds[0] = wi::to_offset (range[0]);
 	  bounds[1] = wi::to_offset (range[1]);
@@ -1895,8 +1890,8 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict,
 /* Check a CALL statement for restrict-violations and issue warnings
    if/when appropriate.  */
 
-static void
-check_call (range_query *query, gimple *call)
+void
+pass_wrestrict::check_call (gimple *call)
 {
   /* Avoid checking the call if it has already been diagnosed for
      some reason.  */
@@ -1986,7 +1981,7 @@ check_call (range_query *query, gimple *call)
       || (dstwr && !INTEGRAL_TYPE_P (TREE_TYPE (dstwr))))
     return;
 
-  opt_code opt = check_bounds_or_overlap (query, call, dst, src, dstwr,
+  opt_code opt = check_bounds_or_overlap (m_ptr_qry, call, dst, src, dstwr,
 					  NULL_TREE);
   /* Avoid diagnosing the call again.  */
   suppress_warning (call, opt);
@@ -2006,25 +2001,26 @@ check_bounds_or_overlap (gimple *call, tree dst, tree src, tree dstsize,
 			 tree srcsize, bool bounds_only /* = false */,
 			 bool do_warn /* = true */)
 {
-  return check_bounds_or_overlap (/*range_query=*/NULL,
+  pointer_query ptrqry (get_range_query (cfun));
+  return check_bounds_or_overlap (ptrqry,
 				  call, dst, src, dstsize, srcsize,
 				  bounds_only, do_warn);
 }
 
 opt_code
-check_bounds_or_overlap (range_query *query,
+check_bounds_or_overlap (pointer_query &ptrqry,
 			 gimple *call, tree dst, tree src, tree dstsize,
 			 tree srcsize, bool bounds_only /* = false */,
 			 bool do_warn /* = true */)
 {
   tree func = gimple_call_fndecl (call);
 
-  builtin_memref dstref (query, call, dst, dstsize);
-  builtin_memref srcref (query, call, src, srcsize);
+  builtin_memref dstref (ptrqry, call, dst, dstsize);
+  builtin_memref srcref (ptrqry, call, src, srcsize);
 
   /* Create a descriptor of the access.  This may adjust both DSTREF
      and SRCREF based on one another and the kind of the access.  */
-  builtin_access acs (query, call, dstref, srcref);
+  builtin_access acs (ptrqry, call, dstref, srcref);
 
   /* Set STRICT to the value of the -Warray-bounds=N argument for
      string functions or when N > 1.  */
diff --git a/gcc/gimple-ssa-warn-restrict.h b/gcc/gimple-ssa-warn-restrict.h
index 1c60f51b500..2bdde030023 100644
--- a/gcc/gimple-ssa-warn-restrict.h
+++ b/gcc/gimple-ssa-warn-restrict.h
@@ -22,7 +22,7 @@
 
 extern opt_code check_bounds_or_overlap (gimple *, tree, tree, tree, tree,
 					 bool = false, bool = true);
-extern opt_code check_bounds_or_overlap (class range_query *, gimple *,
+extern opt_code check_bounds_or_overlap (class pointer_query &, gimple *,
 					 tree, tree, tree, tree,
 					 bool = false, bool = true);
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Enable pointer_query caching throughout.
  2022-02-02 23:35 [PATCH 0/3] Enable pointer_query caching throughout Martin Sebor
                   ` (2 preceding siblings ...)
  2022-02-02 23:35 ` [PATCH 3/3] Enable pointer_query caching for -Wrestrict Martin Sebor
@ 2022-02-03  9:07 ` Richard Biener
  3 siblings, 0 replies; 10+ messages in thread
From: Richard Biener @ 2022-02-03  9:07 UTC (permalink / raw)
  To: Martin Sebor; +Cc: GCC Patches

On Thu, Feb 3, 2022 at 12:35 AM Martin Sebor <msebor@gmail.com> wrote:
>
> Richard, as we discussed(*), this patch series enables the pointer_query
> cache in the remaining two passes where it's currently disabled.  Since
> not using the cache is not an option anymore, the first patch in
> the series makes it a private member of the pointer_query class and its
> use unconditional.  It also simplifies the two passes that use it to
> avoid having to install it.
>
> Tested on x86_64-linux.

OK for the whole series.

Thanks for fixing this issue!
Richard.

> Martin
>
> [*] For reference:
> https://gcc.gnu.org/pipermail/gcc-patches/2022-January/589243.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Enable pointer_query caching throughout.
  2022-02-04  0:33     ` Martin Sebor
@ 2022-02-04  2:49       ` Martin Sebor
  0 siblings, 0 replies; 10+ messages in thread
From: Martin Sebor @ 2022-02-04  2:49 UTC (permalink / raw)
  To: David Edelsohn; +Cc: GCC Patches, Richard Biener

On 2/3/22 17:33, Martin Sebor wrote:
> On 2/3/22 17:18, David Edelsohn wrote:
>> On Thu, Feb 3, 2022 at 6:09 PM Martin Sebor <msebor@gmail.com> wrote:
>>>
>>> On 2/3/22 15:56, David Edelsohn wrote:
>>>> This series of patches has exploded memory usage and I can no longer
>>>> bootstrap GCC on AIX.
>>>>
>>>> As with the Ranger problem exposed by Aldy's patch last September,
>>>> something is not freeing memory.
>>>>
>>>> Even on systems where GCC still bootstrap, this excessive memory usage
>>>> severely damages GCC compile performance.
>>>
>>> Does the change below by any chance make a difference?  (It's just
>>> a hunch, I haven't tested it beyond quickly building stage 1 and
>>> running a few tests.)
>>
>> Hi, Martin
>>
>> Thanks for the quick response.  Yes, I am able to restore bootstrap on
>> AIX (32 bit) with the change.
> 
> Let me finish testing it and if all goes well commit it later tonight.

Now pushed as r12-7043.

Martin

> 
> Thanks for the confirmation!
> 
> Martin
> 
>>
>> Thanks, David
>>
>>>
>>> Martin
>>>
>>>
>>> diff --git a/gcc/pointer-query.h b/gcc/pointer-query.h
>>> index 4c725eeaf34..801a240c38d 100644
>>> --- a/gcc/pointer-query.h
>>> +++ b/gcc/pointer-query.h
>>> @@ -164,9 +164,9 @@ class pointer_query
>>>      struct cache_type
>>>      {
>>>        /* 1-based indices into cache.  */
>>> -    vec<unsigned> indices;
>>> +    auto_vec<unsigned> indices;
>>>        /* The cache itself.  */
>>> -    vec<access_ref> access_refs;
>>> +    auto_vec<access_ref> access_refs;
>>>      };
>>>
>>>    public:
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Enable pointer_query caching throughout.
  2022-02-04  0:18   ` David Edelsohn
@ 2022-02-04  0:33     ` Martin Sebor
  2022-02-04  2:49       ` Martin Sebor
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Sebor @ 2022-02-04  0:33 UTC (permalink / raw)
  To: David Edelsohn; +Cc: GCC Patches, Richard Biener

On 2/3/22 17:18, David Edelsohn wrote:
> On Thu, Feb 3, 2022 at 6:09 PM Martin Sebor <msebor@gmail.com> wrote:
>>
>> On 2/3/22 15:56, David Edelsohn wrote:
>>> This series of patches has exploded memory usage and I can no longer
>>> bootstrap GCC on AIX.
>>>
>>> As with the Ranger problem exposed by Aldy's patch last September,
>>> something is not freeing memory.
>>>
>>> Even on systems where GCC still bootstrap, this excessive memory usage
>>> severely damages GCC compile performance.
>>
>> Does the change below by any chance make a difference?  (It's just
>> a hunch, I haven't tested it beyond quickly building stage 1 and
>> running a few tests.)
> 
> Hi, Martin
> 
> Thanks for the quick response.  Yes, I am able to restore bootstrap on
> AIX (32 bit) with the change.

Let me finish testing it and if all goes well commit it later tonight.

Thanks for the confirmation!

Martin

> 
> Thanks, David
> 
>>
>> Martin
>>
>>
>> diff --git a/gcc/pointer-query.h b/gcc/pointer-query.h
>> index 4c725eeaf34..801a240c38d 100644
>> --- a/gcc/pointer-query.h
>> +++ b/gcc/pointer-query.h
>> @@ -164,9 +164,9 @@ class pointer_query
>>      struct cache_type
>>      {
>>        /* 1-based indices into cache.  */
>> -    vec<unsigned> indices;
>> +    auto_vec<unsigned> indices;
>>        /* The cache itself.  */
>> -    vec<access_ref> access_refs;
>> +    auto_vec<access_ref> access_refs;
>>      };
>>
>>    public:


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Enable pointer_query caching throughout.
  2022-02-03 23:09 ` Martin Sebor
@ 2022-02-04  0:18   ` David Edelsohn
  2022-02-04  0:33     ` Martin Sebor
  0 siblings, 1 reply; 10+ messages in thread
From: David Edelsohn @ 2022-02-04  0:18 UTC (permalink / raw)
  To: Martin Sebor; +Cc: GCC Patches, Richard Biener

On Thu, Feb 3, 2022 at 6:09 PM Martin Sebor <msebor@gmail.com> wrote:
>
> On 2/3/22 15:56, David Edelsohn wrote:
> > This series of patches has exploded memory usage and I can no longer
> > bootstrap GCC on AIX.
> >
> > As with the Ranger problem exposed by Aldy's patch last September,
> > something is not freeing memory.
> >
> > Even on systems where GCC still bootstrap, this excessive memory usage
> > severely damages GCC compile performance.
>
> Does the change below by any chance make a difference?  (It's just
> a hunch, I haven't tested it beyond quickly building stage 1 and
> running a few tests.)

Hi, Martin

Thanks for the quick response.  Yes, I am able to restore bootstrap on
AIX (32 bit) with the change.

Thanks, David

>
> Martin
>
>
> diff --git a/gcc/pointer-query.h b/gcc/pointer-query.h
> index 4c725eeaf34..801a240c38d 100644
> --- a/gcc/pointer-query.h
> +++ b/gcc/pointer-query.h
> @@ -164,9 +164,9 @@ class pointer_query
>     struct cache_type
>     {
>       /* 1-based indices into cache.  */
> -    vec<unsigned> indices;
> +    auto_vec<unsigned> indices;
>       /* The cache itself.  */
> -    vec<access_ref> access_refs;
> +    auto_vec<access_ref> access_refs;
>     };
>
>   public:

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Enable pointer_query caching throughout.
  2022-02-03 22:56 David Edelsohn
@ 2022-02-03 23:09 ` Martin Sebor
  2022-02-04  0:18   ` David Edelsohn
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Sebor @ 2022-02-03 23:09 UTC (permalink / raw)
  To: David Edelsohn; +Cc: GCC Patches, Richard Biener

On 2/3/22 15:56, David Edelsohn wrote:
> This series of patches has exploded memory usage and I can no longer
> bootstrap GCC on AIX.
> 
> As with the Ranger problem exposed by Aldy's patch last September,
> something is not freeing memory.
> 
> Even on systems where GCC still bootstrap, this excessive memory usage
> severely damages GCC compile performance.

Does the change below by any chance make a difference?  (It's just
a hunch, I haven't tested it beyond quickly building stage 1 and
running a few tests.)

Martin


diff --git a/gcc/pointer-query.h b/gcc/pointer-query.h
index 4c725eeaf34..801a240c38d 100644
--- a/gcc/pointer-query.h
+++ b/gcc/pointer-query.h
@@ -164,9 +164,9 @@ class pointer_query
    struct cache_type
    {
      /* 1-based indices into cache.  */
-    vec<unsigned> indices;
+    auto_vec<unsigned> indices;
      /* The cache itself.  */
-    vec<access_ref> access_refs;
+    auto_vec<access_ref> access_refs;
    };

  public:

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Enable pointer_query caching throughout.
@ 2022-02-03 22:56 David Edelsohn
  2022-02-03 23:09 ` Martin Sebor
  0 siblings, 1 reply; 10+ messages in thread
From: David Edelsohn @ 2022-02-03 22:56 UTC (permalink / raw)
  To: Martin Sebor; +Cc: GCC Patches, Richard Biener

This series of patches has exploded memory usage and I can no longer
bootstrap GCC on AIX.

As with the Ranger problem exposed by Aldy's patch last September,
something is not freeing memory.

Even on systems where GCC still bootstrap, this excessive memory usage
severely damages GCC compile performance.

Thanks, David

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-02-04  2:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 23:35 [PATCH 0/3] Enable pointer_query caching throughout Martin Sebor
2022-02-02 23:35 ` [PATCH 1/3] Make pointer_query cache a private member Martin Sebor
2022-02-02 23:35 ` [PATCH 2/3] Enable pointer_query caching for -Warray-bounds Martin Sebor
2022-02-02 23:35 ` [PATCH 3/3] Enable pointer_query caching for -Wrestrict Martin Sebor
2022-02-03  9:07 ` [PATCH 0/3] Enable pointer_query caching throughout Richard Biener
2022-02-03 22:56 David Edelsohn
2022-02-03 23:09 ` Martin Sebor
2022-02-04  0:18   ` David Edelsohn
2022-02-04  0:33     ` Martin Sebor
2022-02-04  2:49       ` Martin Sebor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).