]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/libgcov-merge.c
tree-optimization/95495 - use SLP_TREE_REPRESENTATIVE in assertion
[thirdparty/gcc.git] / libgcc / libgcov-merge.c
CommitLineData
d6d3f033
RX
1/* Routines required for instrumenting a program. */
2/* Compile this one with gcc. */
8d9254fc 3/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
d6d3f033
RX
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
25
40d6b753 26#include "libgcov.h"
d6d3f033
RX
27
28#if defined(inhibit_libc)
29/* If libc and its header files are not available, provide dummy functions. */
30
31#ifdef L_gcov_merge_add
32void __gcov_merge_add (gcov_type *counters __attribute__ ((unused)),
33 unsigned n_counters __attribute__ ((unused))) {}
34#endif
35
596341c7
ML
36#ifdef L_gcov_merge_topn
37void __gcov_merge_topn (gcov_type *counters __attribute__ ((unused)),
38 unsigned n_counters __attribute__ ((unused))) {}
d6d3f033
RX
39#endif
40
d6d3f033
RX
41#else
42
43#ifdef L_gcov_merge_add
44/* The profile merging function that just adds the counters. It is given
45 an array COUNTERS of N_COUNTERS old counters and it reads the same number
46 of counters from the gcov file. */
47void
48__gcov_merge_add (gcov_type *counters, unsigned n_counters)
49{
50 for (; n_counters; counters++, n_counters--)
c77556a5 51 *counters += gcov_get_counter ();
d6d3f033
RX
52}
53#endif /* L_gcov_merge_add */
54
55#ifdef L_gcov_merge_ior
56/* The profile merging function that just adds the counters. It is given
57 an array COUNTERS of N_COUNTERS old counters and it reads the same number
58 of counters from the gcov file. */
59void
60__gcov_merge_ior (gcov_type *counters, unsigned n_counters)
61{
62 for (; n_counters; counters++, n_counters--)
c77556a5 63 *counters |= gcov_get_counter_target ();
d6d3f033
RX
64}
65#endif
66
67#ifdef L_gcov_merge_time_profile
68/* Time profiles are merged so that minimum from all valid (greater than zero)
69 is stored. There could be a fork that creates new counters. To have
70 the profile stable, we chosen to pick the smallest function visit time. */
71void
72__gcov_merge_time_profile (gcov_type *counters, unsigned n_counters)
73{
74 unsigned int i;
75 gcov_type value;
76
77 for (i = 0; i < n_counters; i++)
78 {
c77556a5 79 value = gcov_get_counter_target ();
d6d3f033
RX
80
81 if (value && (!counters[i] || value < counters[i]))
82 counters[i] = value;
83 }
84}
85#endif /* L_gcov_merge_time_profile */
86
596341c7 87#ifdef L_gcov_merge_topn
92d41717 88
d6d3f033
RX
89/* The profile merging function for choosing the most common value.
90 It is given an array COUNTERS of N_COUNTERS old counters and it
91 reads the same number of counters from the gcov file. The counters
92d41717 92 are split into pairs where the members of the tuple have
d6d3f033
RX
93 meanings:
94
95 -- the stored candidate on the most common value of the measured entity
96 -- counter
92d41717 97 */
871e5ada 98
d6d3f033 99void
596341c7 100__gcov_merge_topn (gcov_type *counters, unsigned n_counters)
d6d3f033 101{
871e5ada 102 gcc_assert (!(n_counters % GCOV_TOPN_MEM_COUNTERS));
d6d3f033 103
871e5ada
ML
104 for (unsigned i = 0; i < (n_counters / GCOV_TOPN_MEM_COUNTERS); i++)
105 {
106 /* First value is number of total executions of the profiler. */
107 gcov_type all = gcov_get_counter_ignore_scaling (-1);
108 gcov_type n = gcov_get_counter_ignore_scaling (-1);
109
110 counters[GCOV_TOPN_MEM_COUNTERS * i] += all;
111
112 for (unsigned j = 0; j < n; j++)
113 {
114 gcov_type value = gcov_get_counter_target ();
115 gcov_type count = gcov_get_counter_ignore_scaling (-1);
116
117 // TODO: we should use atomic here
118 gcov_topn_add_value (counters + GCOV_TOPN_MEM_COUNTERS * i, value,
119 count, 0, 0);
120 }
121 }
d6d3f033 122}
596341c7 123#endif /* L_gcov_merge_topn */
d6d3f033 124
d6d3f033 125#endif /* inhibit_libc */