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>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 2/1] c++: optimize specialization of templated member functions
Date: Fri, 10 Jun 2022 12:23:42 -0400	[thread overview]
Message-ID: <9ff1502d-d182-9158-1aaf-6eda568ded74@redhat.com> (raw)
In-Reply-To: <289337c5-6b62-47c7-10fe-79859ab76f52@idea>

On 6/9/22 15:37, Patrick Palka wrote:
> On Thu, 9 Jun 2022, Jason Merrill wrote:
> 
>> On 6/9/22 09:00, Patrick Palka wrote:
>>> This performs one of the optimizations added by the previous
>>> patch to lookup_template_class, to instantiate_template as well.
>>> (For the libstdc++ ranges tests this optimization appears to be
>>> effective around 30% of the time, i.e. 30% of the time context of 'tmpl'
>>> is non-dependent while the context of 'gen_tmpl' is dependent.)
>>
>> If this is a significant optimization, how about doing it in tsubst_aggr_type
>> rather than its callers?
> 
> I'm not sure how we'd do this optimization in tsubst_aggr_type?

Oops, I was overlooking the gen_tmpl vs. tmpl difference.

> I haven't observed any significant time/memory improvements based on my
> limited benchmarking, but I can imagine for deeply nested templates it
> could be significant.  And avoiding redundant work should hopefully help
> streamline debugging I suppose.

OK.

>>
>>> gcc/cp/ChangeLog:
>>>
>>> 	* pt.cc (instantiate_template): Don't substitute the context
>>> 	of the most general template if that of the partially
>>> 	instantiated template is non-dependent.
>>> ---
>>>    gcc/cp/pt.cc | 10 ++++++++--
>>>    1 file changed, 8 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
>>> index e021c254872..208daad298a 100644
>>> --- a/gcc/cp/pt.cc
>>> +++ b/gcc/cp/pt.cc
>>> @@ -21661,8 +21661,14 @@ instantiate_template (tree tmpl, tree orig_args,
>>> tsubst_flags_t complain)
>>>        ++processing_template_decl;
>>>      if (DECL_CLASS_SCOPE_P (gen_tmpl))
>>>        {
>>> -      tree ctx = tsubst_aggr_type (DECL_CONTEXT (gen_tmpl), targ_ptr,
>>> -				   complain, gen_tmpl, true);
>>> +      tree ctx;
>>> +      if (!uses_template_parms (DECL_CONTEXT (tmpl)))
>>> +	/* If the context of the partially instantiated template is already
>>> +	   non-dependent, then we might as well use it.  */
>>> +	ctx = DECL_CONTEXT (tmpl);
>>> +      else
>>> +	ctx = tsubst_aggr_type (DECL_CONTEXT (gen_tmpl), targ_ptr,
>>> +				complain, gen_tmpl, true);
>>>          push_nested_class (ctx);
>>>        }
>>>    
>>
>>
> 


  reply	other threads:[~2022-06-10 16:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 18:21 [PATCH] c++: optimize specialization of nested class templates Patrick Palka
2022-06-09 13:00 ` [PATCH 2/1] c++: optimize specialization of templated member functions Patrick Palka
2022-06-09 15:54   ` Jason Merrill
2022-06-09 19:37     ` Patrick Palka
2022-06-10 16:23       ` Jason Merrill [this message]
2022-06-09 15:54 ` [PATCH] c++: optimize specialization of nested class templates Jason Merrill
2022-06-09 19:16   ` Patrick Palka
2022-06-10 13:18     ` Patrick Palka
2022-06-10 16:00       ` Patrick Palka
2022-06-10 16:38         ` Jason Merrill

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=9ff1502d-d182-9158-1aaf-6eda568ded74@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).