]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/110489 - avoid useless work on statistics
authorRichard Biener <rguenther@suse.de>
Fri, 30 Jun 2023 07:46:48 +0000 (09:46 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 30 Jun 2023 08:38:14 +0000 (10:38 +0200)
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.

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

index 1708e0d3aacf3b73e8a0c3adccc4d099d9c7b2f0..6d1eefd544e43cceb59d250368cd2cc2abebc428 100644 (file)
@@ -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.  */