Message ID | 20220609130013.250243-1-ppalka@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 C279C38344DF for <patchwork@sourceware.org>; Thu, 9 Jun 2022 13:01:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C279C38344DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1654779666; bh=TFCY7ew+H82rH84vapqInR4SzQfHELRIxLgZEkgdHik=; 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=XsqOm9KyMQbTNYaOKyslonOffPt0s+D7Cyd0GJdffSJvqw0JMxzL04m4IMlDZYqwt 5ZAccEH/vc/3QAVq8yBtgZChIutd1LK2JuJZfKx3CuhkrwEMVmnyQoSfZdGHdAZqTT G9RHfcQoCchFK8bKP/zxquXRIWn8EgrZaHt08QFI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DABF23839406 for <gcc-patches@gcc.gnu.org>; Thu, 9 Jun 2022 13:00:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DABF23839406 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-633-VmPq7SsrOqu50cnsJv0DJw-1; Thu, 09 Jun 2022 09:00:34 -0400 X-MC-Unique: VmPq7SsrOqu50cnsJv0DJw-1 Received: by mail-qk1-f197.google.com with SMTP id bl27-20020a05620a1a9b00b0069994eeb30cso18943762qkb.11 for <gcc-patches@gcc.gnu.org>; Thu, 09 Jun 2022 06:00:34 -0700 (PDT) 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=TFCY7ew+H82rH84vapqInR4SzQfHELRIxLgZEkgdHik=; b=IZscoOLlJW8RymeLz6PMFtUeDG4cQ1JF8LN510svnnqcKMr7V2SI/L9JdbbwjXiAld Xo2EkCDW1pVIwBzi5aMGTegek0pmD59Bck0FKg0Yh7ITfdndrx+Yw4KZMHo41k9cE/Ip 3lgfveN7nnfNizJ5NOdXujOhjq5ipQ+44WNgRvI6dqs3VDMADS8g/YUcan/0OHnw5M+t /a1cm7gQjQ7wmO8UQ8GAXC+Sr0I/MN4ealYnlfYqcAcylLsw5z3ABUuiwr2e+VX5vTFc EWvf6ggQ6ZwfgmQzNCkt6cJPsMww3rr9XigQOXWmlvpWROXa1syVk9BiIP143k32YvRX bUEA== X-Gm-Message-State: AOAM532+3FqmaWx/MrF66GdfPwnRWBAiBhmoikWIQqOJC2OsxvkfByvR PWsKCQNKOecprd/p/aaHf3E28ZqIQ7+1SpFWNSYY1Y5vdxkYuTOn+mD5tSsTAWo2bfxGT0L3SvU GODWJWh1RVTXQ1ei8Q7v0+FLZzvaVysyMHev4Au7yNEcRq/6GNM3vF/wRfkhh1IrEZzY= X-Received: by 2002:ac8:5c44:0:b0:305:165e:9f3 with SMTP id j4-20020ac85c44000000b00305165e09f3mr190277qtj.560.1654779628694; Thu, 09 Jun 2022 06:00:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8SLU6+zcGvyrz9moFHuIiWC+Bwlk/t+lqz5FFmK4lOz6d1gvK3O28E9X4pmtIck5xQhsNuw== X-Received: by 2002:ac8:5c44:0:b0:305:165e:9f3 with SMTP id j4-20020ac85c44000000b00305165e09f3mr189929qtj.560.1654779625283; Thu, 09 Jun 2022 06:00:25 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id d5-20020a05620a240500b006a6b1630e95sm4447733qkn.45.2022.06.09.06.00.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jun 2022 06:00:24 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/1] c++: optimize specialization of templated member functions Date: Thu, 9 Jun 2022 09:00:13 -0400 Message-Id: <20220609130013.250243-1-ppalka@redhat.com> X-Mailer: git-send-email 2.36.1.363.g9c897eef06 In-Reply-To: <20220608182147.4123587-1-ppalka@redhat.com> References: <20220608182147.4123587-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Patrick Palka via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Patrick Palka <ppalka@redhat.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
c++: optimize specialization of nested class templates
|
|
Commit Message
Patrick Palka
June 9, 2022, 1 p.m. UTC
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.) 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(-)
Comments
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? > 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); > } >
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? 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. > > > 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); > > } > > > >
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); >>> } >>> >> >> >
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); }