public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] middle-end/110489 - avoid useless work on statistics
Date: Fri, 30 Jun 2023 10:38:06 +0200 (CEST)	[thread overview]
Message-ID: <20230630083806.C5284138F8@imap2.suse-dmz.suse.de> (raw)

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 <void *, statistics_fini_pass_1> (NULL);
+      if (stat_hash)
+	stat_hash->traverse_noresize <void *, statistics_fini_pass_1> (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 <void *, statistics_fini_pass_2> (NULL);
-  curr_statistics_hash ()
-    ->traverse_noresize <void *, statistics_fini_pass_3> (NULL);
+    stat_hash->traverse_noresize <void *, statistics_fini_pass_2> (NULL);
+  stat_hash->traverse_noresize <void *, statistics_fini_pass_3> (NULL);
 }
 
 /* Helper for printing summary information.  */
-- 
2.35.3

                 reply	other threads:[~2023-06-30  8:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230630083806.C5284138F8@imap2.suse-dmz.suse.de \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).