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