From patchwork Wed Oct 2 11:53:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1991992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ASMu552+; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=09qHeiCp; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ASMu552+; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=09qHeiCp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XJY9t2dgxz1xtn for ; Wed, 2 Oct 2024 21:53:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2AA2E38650E3 for ; Wed, 2 Oct 2024 11:53:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 53B523858C60 for ; Wed, 2 Oct 2024 11:53:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53B523858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 53B523858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727870009; cv=none; b=BAUn7VHPnbkNGxSshbNuqUrn6n7WrIJUpjnaF2GcCq+8nnF1hOgFSgIsUj1attHDXW8Rx504yxJlplaOA1ygRNqtGSeYFH7qN/xzOI31tHBJPnuzitHbcHz/4q8HWPMZQgCVWOEin0T3mQCUIL6bNRmurSPxNsIx5v7h+85aglE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727870009; c=relaxed/simple; bh=4QGoQlkQEwbYsJHpAy+AMgM8lituBH9Kh4Ae3kdGUsY=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=rQN8/G1jVEPvW7HHpHnYOvWmlhkc8dzMUfaZp1lYiMBL+rVY9heTn6IC0Yp8JcMtxXhqG/tRsCXCyg5/kJJNy7WScvdPJWr5JkC6lfWAYD1JRPWMa2ZOkGu6q7SBad+ZTVnAlz1ccWqjzwxT68zOKJcSwuMOujiQMfP1zjfNuEw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 5220A1FD54 for ; Wed, 2 Oct 2024 11:53:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1727870004; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=CCf8W2+TNePpifnjEZAhcg/EoHv53f0pcVbbVtssUys=; b=ASMu552+S+Y4US5QE7S6Xef+jMgiSBxOM438XO0w8lKlzasM6jQnKY8hX9TtGtbD9qgV55 y+8mpmiRo6uwZdXROBRYSfg3L9vK3QlBjApVHCDt3rumKmH6wmV+7CIvRgsbsMp4AkC26n gZQb/Q5p5rHMnicSr4M7D27y1wkW0VA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1727870004; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=CCf8W2+TNePpifnjEZAhcg/EoHv53f0pcVbbVtssUys=; b=09qHeiCphOWJap6+AwGS5IksDhPPpNrJspLXDqUGtMUeKAQ5uos6CONB/5kej+b1IqoA+K bFYwXqITsUomSDCw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1727870004; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=CCf8W2+TNePpifnjEZAhcg/EoHv53f0pcVbbVtssUys=; b=ASMu552+S+Y4US5QE7S6Xef+jMgiSBxOM438XO0w8lKlzasM6jQnKY8hX9TtGtbD9qgV55 y+8mpmiRo6uwZdXROBRYSfg3L9vK3QlBjApVHCDt3rumKmH6wmV+7CIvRgsbsMp4AkC26n gZQb/Q5p5rHMnicSr4M7D27y1wkW0VA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1727870004; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=CCf8W2+TNePpifnjEZAhcg/EoHv53f0pcVbbVtssUys=; b=09qHeiCphOWJap6+AwGS5IksDhPPpNrJspLXDqUGtMUeKAQ5uos6CONB/5kej+b1IqoA+K bFYwXqITsUomSDCw== Date: Wed, 2 Oct 2024 13:53:24 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/3] Record template specialization hash MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-0.03 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MISSING_MID(2.50)[]; NEURAL_SPAM_LONG(0.77)[0.219]; NEURAL_HAM_SHORT(-0.20)[-0.988]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[] X-Spam-Score: -0.03 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20241002115350.2AA2E38650E3@sourceware.org> For a specific testcase a lot of compile-time is spent in re-hashing hashtable elements upon expansion. The following records the hash in the hash element. This speeds up compilation by 20%. There's probably module-related uses that need to be adjusted. Bootstrap failed (guess I was expecting this), but still I think this is a good idea - maybe somebody can pick it up. Possibly instead of having a single global hash table having one per ID would be better. The hashtable also keeps things GC-live ('args' for example). gcc/cp/ * cp-tree.h (spec_entry::hash): New member. * pt.cc (spec_hasher::hash): Return the elements recorded hash. (lookup_template_class): Record the hash in the element. --- gcc/cp/cp-tree.h | 1 + gcc/cp/pt.cc | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index c5d02567cb4..56345214d8f 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5843,6 +5843,7 @@ struct GTY((for_user)) spec_entry tree tmpl; /* The general template this is a specialization of. */ tree args; /* The args for this (maybe-partial) specialization. */ tree spec; /* The specialization itself. */ + hashval_t hash; }; /* in class.cc */ diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 2c8b0d8609d..11f84133fa7 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -1739,7 +1739,7 @@ spec_hasher::hash (tree tmpl, tree args) hashval_t spec_hasher::hash (spec_entry *e) { - return spec_hasher::hash (e->tmpl, e->args); + return e->hash; } /* Recursively calculate a hash value for a template argument ARG, for use @@ -10234,7 +10234,7 @@ lookup_template_class (tree d1, tree arglist, tree in_decl, tree context, elt.tmpl = gen_tmpl; elt.args = arglist; elt.spec = NULL_TREE; - hash = spec_hasher::hash (&elt); + hash = elt.hash = spec_hasher::hash (gen_tmpl, arglist); entry = type_specializations->find_with_hash (&elt, hash); if (entry) @@ -10519,7 +10519,7 @@ lookup_template_class (tree d1, tree arglist, tree in_decl, tree context, use it for hash table lookup. */ elt.tmpl = found; elt.args = arglist = INNERMOST_TEMPLATE_ARGS (arglist); - hash = spec_hasher::hash (&elt); + hash = elt.hash = spec_hasher::hash (found, arglist); } }