aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-01-31 13:10:14 +0100
committerMartin Liska <mliska@suse.cz>2020-06-02 12:11:02 +0200
commit871e5ada6d53d5eb495cc9f323983f347487c1b2 (patch)
tree15075fc87b2c7817e72f0b26b065a91e7963d0e6 /gcc
parent23438370f768802fefd732529177fcea074c493b (diff)
downloadgcc-871e5ada6d53d5eb495cc9f323983f347487c1b2.zip
gcc-871e5ada6d53d5eb495cc9f323983f347487c1b2.tar.gz
gcc-871e5ada6d53d5eb495cc9f323983f347487c1b2.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/coverage.c7
-rw-r--r--gcc/doc/gcov-dump.texi5
-rw-r--r--gcc/gcov-dump.c14
-rw-r--r--gcc/gcov-io.h22
-rw-r--r--gcc/ipa-profile.c11
-rw-r--r--gcc/profile.c70
-rw-r--r--gcc/value-prof.c59
7 files changed, 123 insertions, 65 deletions
diff --git a/gcc/coverage.c b/gcc/coverage.c
index 7d82e44..1dcda43 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -345,8 +345,11 @@ get_coverage_counts (unsigned counter, unsigned cfg_checksum,
can do about it. */
return NULL;
}
-
- if (entry->cfg_checksum != cfg_checksum || entry->n_counts != n_counts)
+
+ if (entry->cfg_checksum != cfg_checksum
+ || (counter != GCOV_COUNTER_V_INDIR
+ && counter != GCOV_COUNTER_V_TOPN
+ && entry->n_counts != n_counts))
{
static int warned = 0;
bool warning_printed = false;
diff --git a/gcc/doc/gcov-dump.texi b/gcc/doc/gcov-dump.texi
index 776c0d5..419df98 100644
--- a/gcc/doc/gcov-dump.texi
+++ b/gcc/doc/gcov-dump.texi
@@ -61,6 +61,7 @@ gcov-dump [@option{-v}|@option{--version}]
[@option{-h}|@option{--help}]
[@option{-l}|@option{--long}]
[@option{-p}|@option{--positions}]
+ [@option{-r}|@option{--raw}]
@var{gcovfiles}
@c man end
@end ignore
@@ -80,6 +81,10 @@ Dump content of records.
@itemx --positions
Dump positions of records.
+@item -r
+@itemx --raw
+Print content records in raw format.
+
@item -v
@itemx --version
Display the @command{gcov-dump} version number (on the standard output),
diff --git a/gcc/gcov-dump.c b/gcc/gcov-dump.c
index bd2ae22..90cbd1a 100644
--- a/gcc/gcov-dump.c
+++ b/gcc/gcov-dump.c
@@ -49,6 +49,7 @@ typedef struct tag_format
static int flag_dump_contents = 0;
static int flag_dump_positions = 0;
+static int flag_dump_raw = 0;
static const struct option options[] =
{
@@ -95,7 +96,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv)
diagnostic_initialize (global_dc, 0);
- while ((opt = getopt_long (argc, argv, "hlpvw", options, NULL)) != -1)
+ while ((opt = getopt_long (argc, argv, "hlprvw", options, NULL)) != -1)
{
switch (opt)
{
@@ -111,6 +112,9 @@ main (int argc ATTRIBUTE_UNUSED, char **argv)
case 'p':
flag_dump_positions = 1;
break;
+ case 'r':
+ flag_dump_raw = 1;
+ break;
default:
fprintf (stderr, "unknown flag `%c'\n", opt);
}
@@ -129,6 +133,7 @@ print_usage (void)
printf (" -h, --help Print this help\n");
printf (" -l, --long Dump record contents too\n");
printf (" -p, --positions Dump record positions\n");
+ printf (" -r, --raw Print content records in raw format\n");
printf (" -v, --version Print version number\n");
printf ("\nFor bug reporting instructions, please see:\n%s.\n",
bug_report_url);
@@ -441,7 +446,12 @@ tag_counters (const char *filename ATTRIBUTE_UNUSED,
{
gcov_type count;
- if (!(ix & 7))
+ if (flag_dump_raw)
+ {
+ if (ix == 0)
+ printf (": ");
+ }
+ else if (!(ix & 7))
{
printf ("\n");
print_prefix (filename, depth, gcov_position ());
diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h
index 8cb68aa..940eb7d 100644
--- a/gcc/gcov-io.h
+++ b/gcc/gcov-io.h
@@ -170,6 +170,17 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#ifndef GCC_GCOV_IO_H
#define GCC_GCOV_IO_H
+/* GCOV key-value pair linked list type. */
+
+struct gcov_kvp;
+
+struct gcov_kvp
+{
+ gcov_type value;
+ gcov_type count;
+ struct gcov_kvp *next;
+};
+
#ifndef IN_LIBGCOV
/* About the host */
@@ -272,11 +283,14 @@ GCOV_COUNTERS
#define GCOV_N_VALUE_COUNTERS \
(GCOV_LAST_VALUE_COUNTER - GCOV_FIRST_VALUE_COUNTER + 1)
-/* Number of top N value histogram. */
-#define GCOV_TOPN_VALUES 4
+/* Number of top N counters when being in memory. */
+#define GCOV_TOPN_MEM_COUNTERS 3
+
+/* Number of top N counters in disk representation. */
+#define GCOV_TOPN_DISK_COUNTERS 2
-/* Total number of single value counters. */
-#define GCOV_TOPN_VALUES_COUNTERS (2 * GCOV_TOPN_VALUES + 1)
+/* Maximum number of tracked TOP N value profiles. */
+#define GCOV_TOPN_MAXIMUM_TRACKED_VALUES 32
/* Convert a counter index to a tag. */
#define GCOV_TAG_FOR_COUNTER(COUNT) \
diff --git a/gcc/ipa-profile.c b/gcc/ipa-profile.c
index 9fbfa90..43e9b6b 100644
--- a/gcc/ipa-profile.c
+++ b/gcc/ipa-profile.c
@@ -295,7 +295,8 @@ ipa_profile_generate_summary (void)
speculative_call_summary *csum
= call_sums->get_create (e);
- 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",
h, &val, &count, &all,
@@ -342,7 +343,7 @@ ipa_profile_write_edge_summary (lto_simple_output_block *ob,
len = csum->speculative_call_targets.length ();
- gcc_assert (len <= GCOV_TOPN_VALUES);
+ gcc_assert (len <= GCOV_TOPN_MAXIMUM_TRACKED_VALUES);
streamer_write_hwi_stream (ob->main_stream, len);
@@ -448,8 +449,7 @@ ipa_profile_read_edge_summary (class lto_input_block *ib, cgraph_edge *edge)
unsigned i, len;
len = streamer_read_hwi (ib);
- gcc_assert (len <= GCOV_TOPN_VALUES);
-
+ gcc_assert (len <= GCOV_TOPN_MAXIMUM_TRACKED_VALUES);
speculative_call_summary *csum = call_sums->get_create (edge);
for (i = 0; i < len; i++)
@@ -885,8 +885,7 @@ ipa_profile (void)
item.target_probability
/ (float) REG_BR_PROB_BASE);
}
- if (item.target_probability
- < REG_BR_PROB_BASE / GCOV_TOPN_VALUES / 2)
+ if (item.target_probability < REG_BR_PROB_BASE / 2)
{
nuseless++;
if (dump_file)
diff --git a/gcc/profile.c b/gcc/profile.c
index cd754c4..bd1eac1 100644
--- a/gcc/profile.c
+++ b/gcc/profile.c
@@ -765,26 +765,22 @@ compute_branch_probabilities (unsigned cfg_checksum, unsigned lineno_checksum)
static void
sort_hist_values (histogram_value hist)
{
- /* counters[2] equal to -1 means that all counters are invalidated. */
- if (hist->hvalue.counters[2] == -1)
- return;
-
gcc_assert (hist->type == HIST_TYPE_TOPN_VALUES
|| hist->type == HIST_TYPE_INDIR_CALL);
- gcc_assert (hist->n_counters == GCOV_TOPN_VALUES_COUNTERS);
-
+ int counters = hist->hvalue.counters[1];
+ for (int i = 0; i < counters - 1; i++)
/* Hist value is organized as:
- [total_executions, value1, counter1, ..., value4, counter4]
+ [total_executions, N, counter1, ..., valueN, counterN]
Use decrease bubble sort to rearrange it. The sort starts from <value1,
counter1> and compares counter first. If counter is same, compares the
value, exchange it if small to keep stable. */
- for (unsigned i = 0; i < GCOV_TOPN_VALUES - 1; i++)
+
{
bool swapped = false;
- for (unsigned j = 0; j < GCOV_TOPN_VALUES - 1 - i; j++)
+ for (int j = 0; j < counters - 1 - i; j++)
{
- gcov_type *p = &hist->hvalue.counters[2 * j + 1];
+ gcov_type *p = &hist->hvalue.counters[2 * j + 2];
if (p[1] < p[3] || (p[1] == p[3] && p[0] < p[2]))
{
std::swap (p[0], p[2]);
@@ -847,31 +843,43 @@ compute_value_histograms (histogram_values values, unsigned cfg_checksum,
gimple *stmt = hist->hvalue.stmt;
t = (int) hist->type;
+ bool topn_p = (hist->type == HIST_TYPE_TOPN_VALUES
+ || hist->type == HIST_TYPE_INDIR_CALL);
- aact_count = act_count[t];
-
- if (act_count[t])
- act_count[t] += hist->n_counters;
-
- gimple_add_histogram_value (cfun, stmt, hist);
- hist->hvalue.counters = XNEWVEC (gcov_type, hist->n_counters);
- for (j = 0; j < hist->n_counters; j++)
- if (aact_count)
- hist->hvalue.counters[j] = aact_count[j];
- else
- hist->hvalue.counters[j] = 0;
-
- if (hist->type == HIST_TYPE_TOPN_VALUES
- || hist->type == HIST_TYPE_INDIR_CALL)
+ /* TOP N counter uses variable number of counters. */
+ if (topn_p)
{
- /* Each count value is multiplied by GCOV_TOPN_VALUES. */
- if (hist->hvalue.counters[2] != -1)
- for (unsigned i = 0; i < GCOV_TOPN_VALUES; i++)
- hist->hvalue.counters[2 * i + 2]
- = RDIV (hist->hvalue.counters[2 * i + 2], GCOV_TOPN_VALUES);
-
+ unsigned total_size;
+ if (act_count[t])
+ total_size = 2 + 2 * act_count[t][1];
+ else
+ total_size = 2;
+ gimple_add_histogram_value (cfun, stmt, hist);
+ hist->n_counters = total_size;
+ hist->hvalue.counters = XNEWVEC (gcov_type, hist->n_counters);
+ for (j = 0; j < hist->n_counters; j++)
+ if (act_count[t])
+ hist->hvalue.counters[j] = act_count[t][j];
+ else
+ hist->hvalue.counters[j] = 0;
+ act_count[t] += hist->n_counters;
sort_hist_values (hist);
}
+ else
+ {
+ aact_count = act_count[t];
+
+ if (act_count[t])
+ act_count[t] += hist->n_counters;
+
+ gimple_add_histogram_value (cfun, stmt, hist);
+ hist->hvalue.counters = XNEWVEC (gcov_type, hist->n_counters);
+ for (j = 0; j < hist->n_counters; j++)
+ if (aact_count)
+ hist->hvalue.counters[j] = aact_count[j];
+ else
+ hist->hvalue.counters[j] = 0;
+ }
/* Time profiler counter is not related to any statement,
so that we have to read the counter and set the value to
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: