From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id A18143858404 for ; Fri, 30 Jun 2023 08:38:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A18143858404 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D9AB62189D for ; Fri, 30 Jun 2023 08:38:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1688114286; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=juUJ/oSASBgGBdclA72ST5BUFaPAuZs0TQGQq3JnpAM=; b=TwgKGN46iiFI8Tot7HckJuFI9kYSfaUP4ooBS71ZTKrkIHKQkxQe3pi8w9O+jlB65YelAM GLzr1vBi8faUKqxZWSfEMwgfSlQVNG2dwIXpflXr1K/1qymjDtglKtC58dU0Zyte8YuzSK ysIJ7BlwC8EPUFubSnVmVmWP7sirq9U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1688114286; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=juUJ/oSASBgGBdclA72ST5BUFaPAuZs0TQGQq3JnpAM=; b=xHuQh8M2C2/GkHyx4e56ysp9vnY0qIRzq5UeWqzaipSW+S0etL+eQOV84xD3X1QOEyP0SJ WkYl2uPvyQxmvuAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C5284138F8 for ; Fri, 30 Jun 2023 08:38:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HcTxLm6UnmT7UwAAMHmgww (envelope-from ) for ; Fri, 30 Jun 2023 08:38:06 +0000 Date: Fri, 30 Jun 2023 10:38:06 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/110489 - avoid useless work on statistics MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20230630083806.C5284138F8@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,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 List-Id: When we call statistics_fini_pass we unconditionally allocate the statistics hash and traverse it. When a TU has many small functions this can take considerable time. The following avoids this by never allocating the hash from this function. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/110489 * statistics.cc (curr_statistics_hash): Add argument indicating whether we should allocate the hash. (statistics_fini_pass): If the hash isn't allocated only print the summary header. --- gcc/statistics.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gcc/statistics.cc b/gcc/statistics.cc index 1708e0d3aac..6d1eefd544e 100644 --- a/gcc/statistics.cc +++ b/gcc/statistics.cc @@ -88,7 +88,7 @@ static unsigned nr_statistics_hashes; statistics. */ static stats_counter_table_type * -curr_statistics_hash (void) +curr_statistics_hash (bool alloc = true) { unsigned idx; @@ -99,6 +99,9 @@ curr_statistics_hash (void) && statistics_hashes[idx]) return statistics_hashes[idx]; + if (!alloc) + return nullptr; + if (idx >= nr_statistics_hashes) { statistics_hashes = XRESIZEVEC (stats_counter_table_type *, @@ -202,23 +205,27 @@ statistics_fini_pass (void) if (current_pass->static_pass_number == -1) return; + stats_counter_table_type *stat_hash = curr_statistics_hash (false); + if (dump_file && dump_flags & TDF_STATS) { fprintf (dump_file, "\n"); fprintf (dump_file, "Pass statistics of \"%s\": ", current_pass->name); fprintf (dump_file, "----------------\n"); - curr_statistics_hash () - ->traverse_noresize (NULL); + if (stat_hash) + stat_hash->traverse_noresize (NULL); fprintf (dump_file, "\n"); } + + if (!stat_hash) + return; + if (statistics_dump_file && !(statistics_dump_flags & TDF_STATS || statistics_dump_flags & TDF_DETAILS)) - curr_statistics_hash () - ->traverse_noresize (NULL); - curr_statistics_hash () - ->traverse_noresize (NULL); + stat_hash->traverse_noresize (NULL); + stat_hash->traverse_noresize (NULL); } /* Helper for printing summary information. */ -- 2.35.3