From: Richard Biener Date: Fri, 30 Jun 2023 07:46:48 +0000 (+0200) Subject: middle-end/110489 - avoid useless work on statistics X-Git-Tag: basepoints/gcc-15~7930 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18e5aeaef294428fc8458c2c70a9ac3a537c35d6;p=thirdparty%2Fgcc.git middle-end/110489 - avoid useless work on statistics 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. --- diff --git a/gcc/statistics.cc b/gcc/statistics.cc index 1708e0d3aacf..6d1eefd544e4 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. */