From patchwork Sat Jun 12 04:58:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1491238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=SbAAs+s9; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G259F0SMkz9shn for ; Sat, 12 Jun 2021 14:59:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A69F5386545E for ; Sat, 12 Jun 2021 04:59:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A69F5386545E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623473964; bh=nLoKBAfx189JsfC3VMjoF3m7nRoE+8Q458mo6KXcJhg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=SbAAs+s9HzeiTjypsMt3NUrOx/9y31fqsjPuHtgimx67FRZaKLlJtApdPtN/DGsrJ pxb2aSiFyhFtDpwI+LFgxGUBLzzrQ2gCcku/x0f5dP+2e26yErxzg0OXvJ7cob87Sw UF3Of7/KhPf2IiXI35qOukIR3CVf2yI/Ob/exJJA= 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.133.124]) by sourceware.org (Postfix) with ESMTP id B10D43858023 for ; Sat, 12 Jun 2021 04:59:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B10D43858023 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-260-0UmjVQMKOva69nrN3X8wIw-1; Sat, 12 Jun 2021 00:59:02 -0400 X-MC-Unique: 0UmjVQMKOva69nrN3X8wIw-1 Received: by mail-qv1-f69.google.com with SMTP id s16-20020a0cdc100000b02902177eec9426so23848036qvk.4 for ; Fri, 11 Jun 2021 21:59:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=nLoKBAfx189JsfC3VMjoF3m7nRoE+8Q458mo6KXcJhg=; b=j3tnD6Ll1BVC3HTV9m3xHSprti/KDGQwFl51pK0Lyya0KR/V2w4u678fVlEsdiRfBR iH/Bc1SSfLueoEYVSwx8IAaoirIevEoy7pGxT7htG+uG8E8Z6LGGa7hwNSHMxBlVA/Tr xprUjY8n1RxY4lZbcO0IrQH16nDq2cicg7FQWWEhLTKaHp8IY+T60hrvu9hMo+j5qzLn CBrpZaX2pv/4G3iCCkeXH36s1eECudrTWFR/q/sHZcRb/tlbqXiuPAJyC/XLMEYy40jb 6hJsO9xESAarfwcyy2I66OY5Fe0OjqR1RnmtgwndY4F4+5gZ94g0we+Ns15RO859i6wf Bnxg== X-Gm-Message-State: AOAM532ABz0ZGSZhf2dmF018mAAbFq+UbT80wamkgojbfT2/KYkx91P+ KMwMiVkxgojUqBoGTfAGwY7g8MMUjxwMAlpqRhWvzl8hn0DJFGihgHRlizwj2/+GcH9rw+GHhPr uf7KjjWH13qpfgLo+xp5bc57xKzegW3QY8AcAq1IviornBCJGWOTdPk6fMIFIdpSJUA== X-Received: by 2002:ac8:6711:: with SMTP id e17mr7030456qtp.168.1623473941189; Fri, 11 Jun 2021 21:59:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvSTcAuH3RQEFwrrt+lFHQNmOWwqgscqWUmrUv0es8hZIGpCGPXjUy6NRtN1e8XhoJ9kyMIw== X-Received: by 2002:ac8:6711:: with SMTP id e17mr7030446qtp.168.1623473940841; Fri, 11 Jun 2021 21:59:00 -0700 (PDT) Received: from barrymore.redhat.com ([130.44.159.43]) by smtp.gmail.com with ESMTPSA id o22sm5451825qtq.89.2021.06.11.21.58.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 21:58:59 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: speed up looking up the current class Date: Sat, 12 Jun 2021 00:58:58 -0400 Message-Id: <20210612045858.1544797-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" While looking at template instantiation tracing, I noticed that we were frequently looking up a particular class template instance while instantiating it. This patch shortcuts that lookup, and speeds up compiling stdc++.h with my (checking/unoptimized) compiler by about 3%. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * pt.c (lookup_template_class_1): Shortcut current_class_type. --- gcc/cp/pt.c | 7 +++++++ 1 file changed, 7 insertions(+) base-commit: f16f65f8364b5bf23c72a8fdbba4974ecadc5cb6 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 141388ad2e5..d4bb5cc5eaf 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9833,6 +9833,13 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context, /* From here on, we're only interested in the most general template. */ + /* Shortcut looking up the current class scope again. */ + if (current_class_type) + if (tree ti = CLASSTYPE_TEMPLATE_INFO (current_class_type)) + if (gen_tmpl == most_general_template (TI_TEMPLATE (ti)) + && comp_template_args (arglist, TI_ARGS (ti))) + return current_class_type; + /* Calculate the BOUND_ARGS. These will be the args that are actually tsubst'd into the definition to create the instantiation. */