Make pointer_query cache a private member.

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.
This commit is contained in:
Martin Sebor 2022-02-03 13:56:50 -07:00
parent 3c9f762ad0
commit 68e9b7b69a
4 changed files with 44 additions and 58 deletions

View File

@ -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 (),

View File

@ -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;

View File

@ -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

View File

@ -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;