aboutsummaryrefslogtreecommitdiff
path: root/libgcc
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-01-22 13:40:12 +0100
committerMartin Liska <mliska@suse.cz>2020-01-22 13:40:12 +0100
commit7491c17fe01d8cf116f645532d46120029b26408 (patch)
tree37104109f9c68904d0fe7fcb04f4afd6fb790685 /libgcc
parent9c4fb56578e0a66ec222e58bb89c1e8bc742ef5e (diff)
downloadgcc-7491c17fe01d8cf116f645532d46120029b26408.zip
gcc-7491c17fe01d8cf116f645532d46120029b26408.tar.gz
gcc-7491c17fe01d8cf116f645532d46120029b26408.tar.bz2
Fix TOP N counter update.
PR tree-optimization/92924 * libgcov-profiler.c (__gcov_topn_values_profiler_body): First try to find an existing value, then find an empty slot if not found.
Diffstat (limited to 'libgcc')
-rw-r--r--libgcc/ChangeLog7
-rw-r--r--libgcc/libgcov-profiler.c46
2 files changed, 31 insertions, 22 deletions
diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog
index 441c8f0..76c9946 100644
--- a/libgcc/ChangeLog
+++ b/libgcc/ChangeLog
@@ -1,6 +1,13 @@
2020-01-22 Martin Liska <mliska@suse.cz>
PR tree-optimization/92924
+ * libgcov-profiler.c (__gcov_topn_values_profiler_body): First
+ try to find an existing value, then find an empty slot
+ if not found.
+
+2020-01-22 Martin Liska <mliska@suse.cz>
+
+ PR tree-optimization/92924
* libgcov-driver.c (prune_topn_counter): New.
(prune_counters): Likewise.
(dump_one_gcov): Prune a run-time counter.
diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c
index f45ef49..58784d1 100644
--- a/libgcc/libgcov-profiler.c
+++ b/libgcc/libgcov-profiler.c
@@ -119,35 +119,37 @@ __gcov_topn_values_profiler_body (gcov_type *counters, gcov_type value,
++counters;
+ /* First try to find an existing value. */
+ int empty_counter = -1;
+
for (unsigned i = 0; i < GCOV_TOPN_VALUES; i++)
+ if (value == counters[2 * i])
+ {
+ if (use_atomic)
+ __atomic_fetch_add (&counters[2 * i + 1], GCOV_TOPN_VALUES,
+ __ATOMIC_RELAXED);
+ else
+ counters[2 * i + 1] += GCOV_TOPN_VALUES;
+ return;
+ }
+ else if (counters[2 * i + 1] <= 0)
+ empty_counter = i;
+
+ /* Find an empty slot for a new value. */
+ if (empty_counter != -1)
{
- if (value == counters[2 * i])
- {
- if (use_atomic)
- __atomic_fetch_add (&counters[2 * i + 1], GCOV_TOPN_VALUES,
- __ATOMIC_RELAXED);
- else
- counters[2 * i + 1] += GCOV_TOPN_VALUES;
- return;
- }
- else if (counters[2 * i + 1] <= 0)
- {
- /* We found an empty slot. */
- counters[2 * i] = value;
- counters[2 * i + 1] = GCOV_TOPN_VALUES;
- return;
- }
+ counters[2 * empty_counter] = value;
+ counters[2 * empty_counter + 1] = GCOV_TOPN_VALUES;
+ return;
}
/* We haven't found an empty slot, then decrement all
counter values by one. */
for (unsigned i = 0; i < GCOV_TOPN_VALUES; i++)
- {
- if (use_atomic)
- __atomic_fetch_sub (&counters[2 * i + 1], 1, __ATOMIC_RELAXED);
- else
- counters[2 * i + 1]--;
- }
+ if (use_atomic)
+ __atomic_fetch_sub (&counters[2 * i + 1], 1, __ATOMIC_RELAXED);
+ else
+ counters[2 * i + 1]--;
}
#ifdef L_gcov_topn_values_profiler