public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: simplify norm_cache manipulation
Date: Thu, 18 May 2023 14:54:50 -0400	[thread overview]
Message-ID: <1994ab2b-71a9-fe0f-6956-47a584cef509@redhat.com> (raw)
In-Reply-To: <20230518180114.4158415-1-ppalka@redhat.com>

On 5/18/23 14:01, Patrick Palka wrote:
> Avoid performing two norm_cache lookups during normalization of a
> concept-id by allocating inserting a norm_entry* before rather than
> after the fact, which is simpler and faster.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?

OK.

> gcc/cp/ChangeLog:
> 
> 	* constraint.cc (normalize_concept_check): Avoid having to do
> 	two norm_cache lookups.  Remove unnecessary early exit for an
> 	ill-formed concept definition.
> ---
>   gcc/cp/constraint.cc | 31 +++++++++----------------------
>   1 file changed, 9 insertions(+), 22 deletions(-)
> 
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index c81e024e0e2..8cf0f2d0974 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -774,38 +774,25 @@ normalize_concept_check (tree check, tree args, norm_info info)
>   
>     if (!norm_cache)
>       norm_cache = hash_table<norm_hasher>::create_ggc (31);
> -  norm_entry entry = {tmpl, targs, NULL_TREE};
> -  norm_entry **slot = nullptr;
> -  hashval_t hash = 0;
> -  bool insert = false;
> +  norm_entry *entry = nullptr;
>     if (!info.generate_diagnostics ())
>       {
>         /* Cache the normal form of the substituted concept-id (when not
>   	 diagnosing).  */
> -      hash = norm_hasher::hash (&entry);
> -      slot = norm_cache->find_slot_with_hash (&entry, hash, NO_INSERT);
> -      if (slot)
> +      norm_entry elt = {tmpl, targs, NULL_TREE};
> +      norm_entry **slot = norm_cache->find_slot (&elt, INSERT);
> +      if (*slot)
>   	return (*slot)->norm;
> -      insert = true;
> +      entry = ggc_alloc<norm_entry> ();
> +      *entry = elt;
> +      *slot = entry;
>       }
>   
> -  /* The concept may have been ill-formed.  */
>     tree def = get_concept_definition (DECL_TEMPLATE_RESULT (tmpl));
> -  if (def == error_mark_node)
> -    return error_mark_node;
> -
>     info.update_context (check, args);
>     tree norm = normalize_expression (def, targs, info);
> -  if (insert)
> -    {
> -      /* Recompute SLOT since norm_cache may have been expanded during
> -	 the recursive call.  */
> -      slot = norm_cache->find_slot_with_hash (&entry, hash, INSERT);
> -      gcc_checking_assert (!*slot);
> -      entry.norm = norm;
> -      *slot = ggc_alloc<norm_entry> ();
> -      **slot = entry;
> -    }
> +  if (entry)
> +    entry->norm = norm;
>     return norm;
>   }
>   


      reply	other threads:[~2023-05-18 18:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18 18:01 Patrick Palka
2023-05-18 18:54 ` Jason Merrill [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1994ab2b-71a9-fe0f-6956-47a584cef509@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).