diff options
author | Richard Biener <rguenther@suse.de> | 2023-06-30 09:46:48 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-06-30 10:38:14 +0200 |
commit | 18e5aeaef294428fc8458c2c70a9ac3a537c35d6 (patch) | |
tree | e5b06c8f311686e420828f58f096f67fbe5b3430 | |
parent | f7e3123638712773e8c01e17aae9dc64d9342016 (diff) | |
download | gcc-18e5aeaef294428fc8458c2c70a9ac3a537c35d6.zip gcc-18e5aeaef294428fc8458c2c70a9ac3a537c35d6.tar.gz gcc-18e5aeaef294428fc8458c2c70a9ac3a537c35d6.tar.bz2 |
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.
-rw-r--r-- | gcc/statistics.cc | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/gcc/statistics.cc b/gcc/statistics.cc index 1708e0d..6d1eefd 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. */ |