From 871e5ada6d53d5eb495cc9f323983f347487c1b2 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 31 Jan 2020 13:10:14 +0100 Subject: Make TOPN counter dynamically allocated. gcc/ChangeLog: * coverage.c (get_coverage_counts): Skip sanity check for TOP N counters as they have variable number of counters. * gcov-dump.c (main): Add new option -r. (print_usage): Likewise. (tag_counters): All new raw format. * gcov-io.h (struct gcov_kvp): New. (GCOV_TOPN_VALUES): Remove. (GCOV_TOPN_VALUES_COUNTERS): Likewise. (GCOV_TOPN_MEM_COUNTERS): New. (GCOV_TOPN_DISK_COUNTERS): Likewise. (GCOV_TOPN_MAXIMUM_TRACKED_VALUES): Likewise. * ipa-profile.c (ipa_profile_generate_summary): Use GCOV_TOPN_MAXIMUM_TRACKED_VALUES. (ipa_profile_write_edge_summary): Likewise. (ipa_profile_read_edge_summary): Likewise. (ipa_profile): Remove usage of GCOV_TOPN_VALUES. * profile.c (sort_hist_values): Sort variable number of counters. (compute_value_histograms): Special case for TOP N counters that have dynamic number of key-value pairs. * value-prof.c (dump_histogram_value): Dump variable number of key-value pairs. (stream_in_histogram_value): Stream in variable number of key-value pairs for TOP N counter. (get_nth_most_common_value): Deal with variable number of key-value pairs. (dump_ic_profile): Use GCOV_TOPN_MAXIMUM_TRACKED_VALUES for loop iteration. (gimple_find_values_to_profile): Set GCOV_TOPN_MEM_COUNTERS to n_counters. * doc/gcov-dump.texi: Document new -r option. libgcc/ChangeLog: * libgcov-driver.c (prune_topn_counter): Remove. (prune_counters): Likewise. (merge_one_data): Special case TOP N counters as they have variable length. (write_top_counters): New. (write_one_data): Special case TOP N. (dump_one_gcov): Do not prune TOP N counters. * libgcov-merge.c (merge_topn_values_set): Remove. (__gcov_merge_topn): Use gcov_topn_add_value. * libgcov-profiler.c (__gcov_topn_values_profiler_body): Likewise here. * libgcov.h (gcov_counter_add): New. (gcov_counter_set_if_null): Likewise. (gcov_topn_add_value): New. --- gcc/value-prof.c | 59 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 20 deletions(-) (limited to 'gcc/value-prof.c') diff --git a/gcc/value-prof.c b/gcc/value-prof.c index 45677be..ea1b1a8 100644 --- a/gcc/value-prof.c +++ b/gcc/value-prof.c @@ -265,16 +265,15 @@ dump_histogram_value (FILE *dump_file, histogram_value hist) ? "Top N value counter" : "Indirect call counter")); if (hist->hvalue.counters) { - fprintf (dump_file, " all: %" PRId64 "%s, values: ", - (int64_t) abs_hwi (hist->hvalue.counters[0]), - hist->hvalue.counters[0] < 0 - ? " (values missing)": ""); - for (unsigned i = 0; i < GCOV_TOPN_VALUES; i++) + unsigned count = hist->hvalue.counters[1]; + fprintf (dump_file, " all: %" PRId64 ", %" PRId64 " values: ", + (int64_t) hist->hvalue.counters[0], (int64_t) count); + for (unsigned i = 0; i < count; i++) { fprintf (dump_file, "[%" PRId64 ":%" PRId64 "]", - (int64_t) hist->hvalue.counters[2 * i + 1], - (int64_t) hist->hvalue.counters[2 * i + 2]); - if (i != GCOV_TOPN_VALUES - 1) + (int64_t) hist->hvalue.counters[2 * i + 2], + (int64_t) hist->hvalue.counters[2 * i + 3]); + if (i != count - 1) fprintf (dump_file, ", "); } fprintf (dump_file, ".\n"); @@ -377,7 +376,6 @@ stream_in_histogram_value (class lto_input_block *ib, gimple *stmt) case HIST_TYPE_TOPN_VALUES: case HIST_TYPE_INDIR_CALL: - ncounters = GCOV_TOPN_VALUES_COUNTERS; break; case HIST_TYPE_IOR: @@ -388,12 +386,31 @@ stream_in_histogram_value (class lto_input_block *ib, gimple *stmt) default: gcc_unreachable (); } - new_val->hvalue.counters = XNEWVAR (gcov_type, - sizeof (*new_val->hvalue.counters) - * ncounters); - new_val->n_counters = ncounters; - for (i = 0; i < ncounters; i++) - new_val->hvalue.counters[i] = streamer_read_gcov_count (ib); + + /* TOP N counters have variable number of counters. */ + if (type == HIST_TYPE_INDIR_CALL || type == HIST_TYPE_TOPN_VALUES) + { + gcov_type total = streamer_read_gcov_count (ib); + gcov_type ncounters = streamer_read_gcov_count (ib); + new_val->hvalue.counters = XNEWVAR (gcov_type, + sizeof (*new_val->hvalue.counters) + * (2 + 2 * ncounters)); + new_val->hvalue.counters[0] = total; + new_val->hvalue.counters[1] = ncounters; + new_val->n_counters = 2 + 2 * ncounters; + for (i = 0; i < 2 * ncounters; i++) + new_val->hvalue.counters[2 + i] = streamer_read_gcov_count (ib); + } + else + { + new_val->hvalue.counters = XNEWVAR (gcov_type, + sizeof (*new_val->hvalue.counters) + * ncounters); + new_val->n_counters = ncounters; + for (i = 0; i < ncounters; i++) + new_val->hvalue.counters[i] = streamer_read_gcov_count (ib); + } + if (!next_p) gimple_add_histogram_value (cfun, stmt, new_val); else @@ -738,15 +755,17 @@ get_nth_most_common_value (gimple *stmt, const char *counter_type, histogram_value hist, gcov_type *value, gcov_type *count, gcov_type *all, unsigned n) { - gcc_assert (n < GCOV_TOPN_VALUES); + unsigned counters = hist->hvalue.counters[1]; + if (n >= counters) + return false; *count = 0; *value = 0; gcov_type read_all = abs_hwi (hist->hvalue.counters[0]); - gcov_type v = hist->hvalue.counters[2 * n + 1]; - gcov_type c = hist->hvalue.counters[2 * n + 2]; + gcov_type v = hist->hvalue.counters[2 * n + 2]; + gcov_type c = hist->hvalue.counters[2 * n + 3]; if (hist->hvalue.counters[0] < 0 && (flag_profile_reproducible == PROFILE_REPRODUCIBILITY_PARALLEL_RUNS @@ -1433,7 +1452,7 @@ dump_ic_profile (gimple_stmt_iterator *gsi) count = 0; all = histogram->hvalue.counters[0]; - for (unsigned j = 0; j < GCOV_TOPN_VALUES; j++) + for (unsigned j = 0; j < GCOV_TOPN_MAXIMUM_TRACKED_VALUES; j++) { if (!get_nth_most_common_value (NULL, "indirect call", histogram, &val, &count, &all, j)) @@ -1902,7 +1921,7 @@ gimple_find_values_to_profile (histogram_values *values) case HIST_TYPE_TOPN_VALUES: case HIST_TYPE_INDIR_CALL: - hist->n_counters = GCOV_TOPN_VALUES_COUNTERS; + hist->n_counters = GCOV_TOPN_MEM_COUNTERS; break; case HIST_TYPE_TIME_PROFILE: -- cgit v1.1