From patchwork Wed Oct 2 11:49:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1991985 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=TeNc4PaJ; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=II+f245K; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=TeNc4PaJ; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=II+f245K; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4XJY5N6TLsz1xtn for ; Wed, 2 Oct 2024 21:50:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 077813861014 for ; Wed, 2 Oct 2024 11:49:59 +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 [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 9FBEB3858C60 for ; Wed, 2 Oct 2024 11:49:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9FBEB3858C60 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 9FBEB3858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727869769; cv=none; b=G+w0HPcuBPnXkzJd85LdmVnwX4lNIhervfzpxgyNx+xeeaqLUVaAd1rr+q/RvPQzuJWTd83TCv5KxZtuRiDMTs1mEP5dxwN7VmatUytP5HzjOa/JhP/TUDtjh80OWPEe9FC2gDZp/kDqK7LWeClKzri5rxAdqlJqUrz9LeEc/HI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727869769; c=relaxed/simple; bh=0b1mzTxmCczB6MEPW2zMJCHkeSv7hgDl/2vktZvTto4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=AiIYKDV303XteP3BgQVPhb/xWIobEejty0Jzha44edj/S9gDKzNoKBKfmE4L+b6Fpw6TF/cavT+NYHeY+Vz+fkgW4SaBkg99ZdVFFcd4nyLmNwXjWni4bujhJFbME7vGba0deClzs0+3C+IYa7VX72/H7y0s3cDcSCDmM/lzcYI= 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 64FF21FD56; Wed, 2 Oct 2024 11:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1727869766; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=7/nw70yZx3KU+7sRXSrZZFc9WqlkUMHtvkeQYifCeps=; b=TeNc4PaJeEM26xeJFTj2VkTstTcX86RWMyggUMQVY6cS9mpRf9nPgKJZ1ywKJ8lbC6NeXM nw/P0t0krDNLcT0h/0Iyz/H5dW9ojg+kGQn+7r7ZaA+gTpT8NMm2yqOT2JfxRW2V0yBCWz aXdp0sG5jt5vqb5eByUxWzAO0F667o0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1727869766; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=7/nw70yZx3KU+7sRXSrZZFc9WqlkUMHtvkeQYifCeps=; b=II+f245KlqoRIe8qT2KYZhRsxme/HE/PZYCmXB2M8g9EkLKQ1r0CbF4uf2SemCcdzujAda UWnrSlLNCT0mlZAA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1727869766; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=7/nw70yZx3KU+7sRXSrZZFc9WqlkUMHtvkeQYifCeps=; b=TeNc4PaJeEM26xeJFTj2VkTstTcX86RWMyggUMQVY6cS9mpRf9nPgKJZ1ywKJ8lbC6NeXM nw/P0t0krDNLcT0h/0Iyz/H5dW9ojg+kGQn+7r7ZaA+gTpT8NMm2yqOT2JfxRW2V0yBCWz aXdp0sG5jt5vqb5eByUxWzAO0F667o0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1727869766; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=7/nw70yZx3KU+7sRXSrZZFc9WqlkUMHtvkeQYifCeps=; b=II+f245KlqoRIe8qT2KYZhRsxme/HE/PZYCmXB2M8g9EkLKQ1r0CbF4uf2SemCcdzujAda UWnrSlLNCT0mlZAA== Date: Wed, 2 Oct 2024 13:49:26 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: jason@redhat.com Subject: [PATCH 1/3] Speedup iterative_hash_template_arg MIME-Version: 1.0 X-Spam-Score: -1.52 X-Spamd-Result: default: False [-1.52 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-0.72)[-0.722]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; MISSING_XM_UA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; MIME_TRACE(0.00)[0:+] X-Spam-Level: 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: <20241002114959.077813861014@sourceware.org> Using iterative_hash_object is expensive compared to using iterative_hash_hashval_t which is fit for integer sized values. The following reduces the number of perf cycles spent in iterative_hash_template_arg and iterative_hash combined by 20%. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK for trunk? Thanks, Richard. gcc/cp/ * pt.cc (iterative_hash_template_arg): Avoid using iterative_hash_object. --- gcc/cp/pt.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 43468e5f62e..04f0a1d5fff 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -1751,7 +1751,7 @@ hashval_t iterative_hash_template_arg (tree arg, hashval_t val) { if (arg == NULL_TREE) - return iterative_hash_object (arg, val); + return iterative_hash_hashval_t (0, val); if (!TYPE_P (arg)) /* Strip nop-like things, but not the same as STRIP_NOPS. */ @@ -1762,7 +1762,7 @@ iterative_hash_template_arg (tree arg, hashval_t val) enum tree_code code = TREE_CODE (arg); - val = iterative_hash_object (code, val); + val = iterative_hash_hashval_t (code, val); switch (code) { @@ -1777,7 +1777,7 @@ iterative_hash_template_arg (tree arg, hashval_t val) return val; case IDENTIFIER_NODE: - return iterative_hash_object (IDENTIFIER_HASH_VALUE (arg), val); + return iterative_hash_hashval_t (IDENTIFIER_HASH_VALUE (arg), val); case TREE_VEC: for (tree elt : tree_vec_range (arg)) From patchwork Wed Oct 2 11:50:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1991986 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=BWFC7cNG; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=YS3+iBbV; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=BWFC7cNG; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=YS3+iBbV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4XJY691NB3z1xtn for ; Wed, 2 Oct 2024 21:50:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4DE0B386544E for ; Wed, 2 Oct 2024 11:50:39 +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 5BF39384F032 for ; Wed, 2 Oct 2024 11:50:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BF39384F032 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 5BF39384F032 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=1727869817; cv=none; b=vQjYMEhbxqpxc6jF63vOKAPZb/Oc7iT9//s9wOHt1+Zxns1bpKCAYRCt+2es81FUWE8UPEryvplsY1yFG7bSXIz4//6L0w7Xn7HNmShc1k7VbnKFk6NdMId5LU2ugKfnU4VXaI7QeuB+Qf/zHNev9XPeXzo9RNKMZa42+AvRPQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727869817; c=relaxed/simple; bh=c1iyvjzuMtCVmGAc7zJu112AVPnapQCns/NkP8PvudA=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=gtGXzcsS8tX1G0ueA7K5730SLLgGVrdz6blaZ+0QN5aNmB907ZrLzzbdM4sJUX/iSGukp3Q2AO5WVqd9fdcS/DpNMoeZULbU5J7cZY8TfZ5hsQECUrSpJM/qzMqQWEbWkQu7vMhRdCy3w5ix9N1mLd0+iUxKwAbaXFntk4BHLFY= 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 63A891FD54; Wed, 2 Oct 2024 11:50:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1727869814; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=bEbw8k5PgwNFZSM00spqgZ+uBDx4A73myE5FGn7/rK8=; b=BWFC7cNG1hvMDrzIruX/sjN8PJQ04ZKXGGlGbij1lkzMS4y3B7xXsr372TQWXLtYE8chLa XIfXxzrFf1FEJGNRmszBrUdAdWRSj0laXjd1kr3SAsjEMZu2n7WWFWZ6lQYTF4Ix7ehhdQ +yHWbvSRHrsK3iy7i4a5426WNIODIj4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1727869814; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=bEbw8k5PgwNFZSM00spqgZ+uBDx4A73myE5FGn7/rK8=; b=YS3+iBbVg6Nd75ZO9jUq3Crv40tAPh5Ggd4ubxHRQh7yuG3qWU7tEzXzPoUI4HFv26+arH pqGoSbgERCmrscBw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1727869814; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=bEbw8k5PgwNFZSM00spqgZ+uBDx4A73myE5FGn7/rK8=; b=BWFC7cNG1hvMDrzIruX/sjN8PJQ04ZKXGGlGbij1lkzMS4y3B7xXsr372TQWXLtYE8chLa XIfXxzrFf1FEJGNRmszBrUdAdWRSj0laXjd1kr3SAsjEMZu2n7WWFWZ6lQYTF4Ix7ehhdQ +yHWbvSRHrsK3iy7i4a5426WNIODIj4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1727869814; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=bEbw8k5PgwNFZSM00spqgZ+uBDx4A73myE5FGn7/rK8=; b=YS3+iBbVg6Nd75ZO9jUq3Crv40tAPh5Ggd4ubxHRQh7yuG3qWU7tEzXzPoUI4HFv26+arH pqGoSbgERCmrscBw== Date: Wed, 2 Oct 2024 13:50:14 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: jason@redhat.com Subject: [PATCH 2/3] Release expanded template argument vector MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-1.52 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-0.72)[-0.721]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; MISSING_XM_UA(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; MIME_TRACE(0.00)[0:+] X-Spam-Score: -1.52 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: <20241002115039.4DE0B386544E@sourceware.org> This reduces peak memory usage by 20% for a specific testcase. Bootstrapped and tested on x86_64-unknown-linux-gnu. It's very ugly so I'd appreciate suggestions on how to handle such situations better? gcc/cp/ * pt.cc (coerce_template_parms): Release expanded argument vector when not needed. --- gcc/cp/pt.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 04f0a1d5fff..2c8b0d8609d 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -9442,6 +9442,9 @@ coerce_template_parms (tree parms, SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_inner_args, TREE_VEC_LENGTH (new_inner_args)); + if ((return_full_args ? new_args != inner_args : new_inner_args != inner_args) + && inner_args != orig_inner_args) + ggc_free (inner_args); return return_full_args ? new_args : new_inner_args; } 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); } }