From patchwork Wed Feb 2 23:35:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 50687 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 937E8385803B for ; Wed, 2 Feb 2022 23:37:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 937E8385803B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1643845023; bh=37RJA3oqpRzX35zu5p+2oHiUkJZZTkj8BC9PmUyU3ug=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=a5Oy7i+BLdx2A0B/FxqYD9flDLstr1l4ujhOYpoGManbrVOcyr2QYz6//zBWJ7atH jEYjxg8qEfiuFHV9ZcA0uVOPQxMZWK2OeT2aKmsj1z0QjuAbpRk4TWgnTeGbrKkAtm nCtGbNF59Cb+pDGlaJh219muumVVVzAToxGcKTwY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 612B73858C2C for ; Wed, 2 Feb 2022 23:35:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 612B73858C2C Received: by mail-il1-x12c.google.com with SMTP id z4so727231ilz.4 for ; Wed, 02 Feb 2022 15:35:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=37RJA3oqpRzX35zu5p+2oHiUkJZZTkj8BC9PmUyU3ug=; b=aN22XJI5+V+ejz8s4bdGxdQRLw3txnTjYBQoqkjEfQYUhU02np5QIw1BFl+CmKldwu PTq0975v74yue1WAQJmMfI9M6kcYpkuKUTCQFdGmPQ/0EfKx7Cxm1xHR7HWn5aEMct61 w9am/8VeWSIHFfRqQnwjD9uVY7xqZzomCPyGuv0cSxNHz/hUu/gHwgAy9QGnLFAyZSNg ZdlWhyldcoEmZDDj9vnpfFwH22G3tRBwv9fC5wCs+ObIVmbUPiX4hO0D+7ZpVowiQyM5 Np4HoKgqmFotqpj8zekkoyVPvHFY2ZBeX5P3+XOSvPS4yRir2HEWL0TkvtNE+J5cwS8V M49Q== X-Gm-Message-State: AOAM533FM+oh6nDPZ/HeTSsGTd00OXFQ7OVgp3ajYv0bCoP8NFQUVCwu fywzb2bPECMlHdz/SjdEsdVjrgzRCuGeUQ== X-Google-Smtp-Source: ABdhPJzTuTC9soejRydHMufysft3zf7m8As6T5SkqRudBpBzdnQWDxW+NPBz3GUDMDY2BDC0nbXWtg== X-Received: by 2002:a05:6e02:1564:: with SMTP id k4mr19424469ilu.63.1643844937179; Wed, 02 Feb 2022 15:35:37 -0800 (PST) Received: from bigbox.redhat.com (97-118-100-142.hlrn.qwest.net. [97.118.100.142]) by smtp.googlemail.com with ESMTPSA id l1sm7481267iln.29.2022.02.02.15.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 15:35:36 -0800 (PST) X-Google-Original-From: Martin Sebor To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/3] Make pointer_query cache a private member. Date: Wed, 2 Feb 2022 16:35:28 -0700 Message-Id: <20220202233530.2568647-2-msebor@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220202233530.2568647-1-msebor@redhat.com> References: <20220202233530.2568647-1-msebor@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "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 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_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;