annotate libgcc/libgcov-merge.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Routines required for instrumenting a program. */
kono
parents:
diff changeset
2 /* Compile this one with gcc. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3 /* Copyright (C) 1989-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
18 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
19 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
22 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
24 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 #include "libgcov.h"
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 #if defined(inhibit_libc)
kono
parents:
diff changeset
29 /* If libc and its header files are not available, provide dummy functions. */
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 #ifdef L_gcov_merge_add
kono
parents:
diff changeset
32 void __gcov_merge_add (gcov_type *counters __attribute__ ((unused)),
kono
parents:
diff changeset
33 unsigned n_counters __attribute__ ((unused))) {}
kono
parents:
diff changeset
34 #endif
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 #ifdef L_gcov_merge_single
kono
parents:
diff changeset
37 void __gcov_merge_single (gcov_type *counters __attribute__ ((unused)),
kono
parents:
diff changeset
38 unsigned n_counters __attribute__ ((unused))) {}
kono
parents:
diff changeset
39 #endif
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 #else
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 #ifdef L_gcov_merge_add
kono
parents:
diff changeset
44 /* The profile merging function that just adds the counters. It is given
kono
parents:
diff changeset
45 an array COUNTERS of N_COUNTERS old counters and it reads the same number
kono
parents:
diff changeset
46 of counters from the gcov file. */
kono
parents:
diff changeset
47 void
kono
parents:
diff changeset
48 __gcov_merge_add (gcov_type *counters, unsigned n_counters)
kono
parents:
diff changeset
49 {
kono
parents:
diff changeset
50 for (; n_counters; counters++, n_counters--)
kono
parents:
diff changeset
51 *counters += gcov_get_counter ();
kono
parents:
diff changeset
52 }
kono
parents:
diff changeset
53 #endif /* L_gcov_merge_add */
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 #ifdef L_gcov_merge_ior
kono
parents:
diff changeset
56 /* The profile merging function that just adds the counters. It is given
kono
parents:
diff changeset
57 an array COUNTERS of N_COUNTERS old counters and it reads the same number
kono
parents:
diff changeset
58 of counters from the gcov file. */
kono
parents:
diff changeset
59 void
kono
parents:
diff changeset
60 __gcov_merge_ior (gcov_type *counters, unsigned n_counters)
kono
parents:
diff changeset
61 {
kono
parents:
diff changeset
62 for (; n_counters; counters++, n_counters--)
kono
parents:
diff changeset
63 *counters |= gcov_get_counter_target ();
kono
parents:
diff changeset
64 }
kono
parents:
diff changeset
65 #endif
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 #ifdef L_gcov_merge_time_profile
kono
parents:
diff changeset
68 /* Time profiles are merged so that minimum from all valid (greater than zero)
kono
parents:
diff changeset
69 is stored. There could be a fork that creates new counters. To have
kono
parents:
diff changeset
70 the profile stable, we chosen to pick the smallest function visit time. */
kono
parents:
diff changeset
71 void
kono
parents:
diff changeset
72 __gcov_merge_time_profile (gcov_type *counters, unsigned n_counters)
kono
parents:
diff changeset
73 {
kono
parents:
diff changeset
74 unsigned int i;
kono
parents:
diff changeset
75 gcov_type value;
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 for (i = 0; i < n_counters; i++)
kono
parents:
diff changeset
78 {
kono
parents:
diff changeset
79 value = gcov_get_counter_target ();
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 if (value && (!counters[i] || value < counters[i]))
kono
parents:
diff changeset
82 counters[i] = value;
kono
parents:
diff changeset
83 }
kono
parents:
diff changeset
84 }
kono
parents:
diff changeset
85 #endif /* L_gcov_merge_time_profile */
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 #ifdef L_gcov_merge_single
kono
parents:
diff changeset
88 /* The profile merging function for choosing the most common value.
kono
parents:
diff changeset
89 It is given an array COUNTERS of N_COUNTERS old counters and it
kono
parents:
diff changeset
90 reads the same number of counters from the gcov file. The counters
kono
parents:
diff changeset
91 are split into 3-tuples where the members of the tuple have
kono
parents:
diff changeset
92 meanings:
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 -- the stored candidate on the most common value of the measured entity
kono
parents:
diff changeset
95 -- counter
kono
parents:
diff changeset
96 -- total number of evaluations of the value */
kono
parents:
diff changeset
97 void
kono
parents:
diff changeset
98 __gcov_merge_single (gcov_type *counters, unsigned n_counters)
kono
parents:
diff changeset
99 {
kono
parents:
diff changeset
100 unsigned i, n_measures;
kono
parents:
diff changeset
101 gcov_type value, counter, all;
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 gcc_assert (!(n_counters % 3));
kono
parents:
diff changeset
104 n_measures = n_counters / 3;
kono
parents:
diff changeset
105 for (i = 0; i < n_measures; i++, counters += 3)
kono
parents:
diff changeset
106 {
kono
parents:
diff changeset
107 value = gcov_get_counter_target ();
kono
parents:
diff changeset
108 counter = gcov_get_counter ();
kono
parents:
diff changeset
109 all = gcov_get_counter ();
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 if (counters[0] == value)
kono
parents:
diff changeset
112 counters[1] += counter;
kono
parents:
diff changeset
113 else if (counter > counters[1])
kono
parents:
diff changeset
114 {
kono
parents:
diff changeset
115 counters[0] = value;
kono
parents:
diff changeset
116 counters[1] = counter - counters[1];
kono
parents:
diff changeset
117 }
kono
parents:
diff changeset
118 else
kono
parents:
diff changeset
119 counters[1] -= counter;
kono
parents:
diff changeset
120 counters[2] += all;
kono
parents:
diff changeset
121 }
kono
parents:
diff changeset
122 }
kono
parents:
diff changeset
123 #endif /* L_gcov_merge_single */
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 #ifdef L_gcov_merge_icall_topn
kono
parents:
diff changeset
126 /* The profile merging function used for merging indirect call counts
kono
parents:
diff changeset
127 This function is given array COUNTERS of N_COUNTERS old counters and it
kono
parents:
diff changeset
128 reads the same number of counters from the gcov file. */
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 void
kono
parents:
diff changeset
131 __gcov_merge_icall_topn (gcov_type *counters, unsigned n_counters)
kono
parents:
diff changeset
132 {
kono
parents:
diff changeset
133 unsigned i, j, k, m;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 gcc_assert (!(n_counters % GCOV_ICALL_TOPN_NCOUNTS));
kono
parents:
diff changeset
136 for (i = 0; i < n_counters; i += GCOV_ICALL_TOPN_NCOUNTS)
kono
parents:
diff changeset
137 {
kono
parents:
diff changeset
138 gcov_type *value_array = &counters[i + 1];
kono
parents:
diff changeset
139 unsigned tmp_size = 2 * (GCOV_ICALL_TOPN_NCOUNTS - 1);
kono
parents:
diff changeset
140 gcov_type *tmp_array
kono
parents:
diff changeset
141 = (gcov_type *) alloca (tmp_size * sizeof (gcov_type));
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 for (j = 0; j < tmp_size; j++)
kono
parents:
diff changeset
144 tmp_array[j] = 0;
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 for (j = 0; j < GCOV_ICALL_TOPN_NCOUNTS - 1; j += 2)
kono
parents:
diff changeset
147 {
kono
parents:
diff changeset
148 tmp_array[j] = value_array[j];
kono
parents:
diff changeset
149 tmp_array[j + 1] = value_array [j + 1];
kono
parents:
diff changeset
150 }
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 /* Skip the number_of_eviction entry. */
kono
parents:
diff changeset
153 gcov_get_counter ();
kono
parents:
diff changeset
154 for (k = 0; k < GCOV_ICALL_TOPN_NCOUNTS - 1; k += 2)
kono
parents:
diff changeset
155 {
kono
parents:
diff changeset
156 int found = 0;
kono
parents:
diff changeset
157 gcov_type global_id = gcov_get_counter_target ();
kono
parents:
diff changeset
158 gcov_type call_count = gcov_get_counter ();
kono
parents:
diff changeset
159 for (m = 0; m < j; m += 2)
kono
parents:
diff changeset
160 {
kono
parents:
diff changeset
161 if (tmp_array[m] == global_id)
kono
parents:
diff changeset
162 {
kono
parents:
diff changeset
163 found = 1;
kono
parents:
diff changeset
164 tmp_array[m + 1] += call_count;
kono
parents:
diff changeset
165 break;
kono
parents:
diff changeset
166 }
kono
parents:
diff changeset
167 }
kono
parents:
diff changeset
168 if (!found)
kono
parents:
diff changeset
169 {
kono
parents:
diff changeset
170 tmp_array[j] = global_id;
kono
parents:
diff changeset
171 tmp_array[j + 1] = call_count;
kono
parents:
diff changeset
172 j += 2;
kono
parents:
diff changeset
173 }
kono
parents:
diff changeset
174 }
kono
parents:
diff changeset
175 /* Now sort the temp array */
kono
parents:
diff changeset
176 gcov_sort_n_vals (tmp_array, j);
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 /* Now copy back the top half of the temp array */
kono
parents:
diff changeset
179 for (k = 0; k < GCOV_ICALL_TOPN_NCOUNTS - 1; k += 2)
kono
parents:
diff changeset
180 {
kono
parents:
diff changeset
181 value_array[k] = tmp_array[k];
kono
parents:
diff changeset
182 value_array[k + 1] = tmp_array[k + 1];
kono
parents:
diff changeset
183 }
kono
parents:
diff changeset
184 }
kono
parents:
diff changeset
185 }
kono
parents:
diff changeset
186 #endif /* L_gcov_merge_icall_topn */
kono
parents:
diff changeset
187 #endif /* inhibit_libc */