annotate gcc/coverage.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Read and write coverage files, and associated functionality.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 1990-2020 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by James E. Wilson, UC Berkeley/Cygnus Support;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 based on some ideas from Dain Samples of UC Berkeley.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 Further mangling by Bob Manson, Cygnus Support.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 Further mangled by Nathan Sidwell, CodeSourcery
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #define GCOV_LINKAGE
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #include "coretypes.h"
111
kono
parents: 67
diff changeset
30 #include "backend.h"
kono
parents: 67
diff changeset
31 #include "target.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 #include "rtl.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 #include "tree.h"
111
kono
parents: 67
diff changeset
34 #include "tree-pass.h"
kono
parents: 67
diff changeset
35 #include "memmodel.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 #include "tm_p.h"
111
kono
parents: 67
diff changeset
37 #include "stringpool.h"
kono
parents: 67
diff changeset
38 #include "cgraph.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 #include "coverage.h"
111
kono
parents: 67
diff changeset
40 #include "diagnostic-core.h"
kono
parents: 67
diff changeset
41 #include "fold-const.h"
kono
parents: 67
diff changeset
42 #include "stor-layout.h"
kono
parents: 67
diff changeset
43 #include "output.h"
kono
parents: 67
diff changeset
44 #include "toplev.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 #include "langhooks.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 #include "tree-iterator.h"
111
kono
parents: 67
diff changeset
47 #include "context.h"
kono
parents: 67
diff changeset
48 #include "pass_manager.h"
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
49 #include "intl.h"
111
kono
parents: 67
diff changeset
50 #include "auto-profile.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
51 #include "profile.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 #include "gcov-io.c"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
111
kono
parents: 67
diff changeset
55 struct GTY((chain_next ("%h.next"))) coverage_data
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 {
111
kono
parents: 67
diff changeset
57 struct coverage_data *next; /* next function */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 unsigned ident; /* function ident */
111
kono
parents: 67
diff changeset
59 unsigned lineno_checksum; /* function lineno checksum */
kono
parents: 67
diff changeset
60 unsigned cfg_checksum; /* function cfg checksum */
kono
parents: 67
diff changeset
61 tree fn_decl; /* the function decl */
kono
parents: 67
diff changeset
62 tree ctr_vars[GCOV_COUNTERS]; /* counter variables. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 /* Counts information for a function. */
111
kono
parents: 67
diff changeset
66 struct counts_entry : pointer_hash <counts_entry>
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 /* We hash by */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 unsigned ident;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 unsigned ctr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 /* Store */
111
kono
parents: 67
diff changeset
73 unsigned lineno_checksum;
kono
parents: 67
diff changeset
74 unsigned cfg_checksum;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 gcov_type *counts;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
76 unsigned n_counts;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
111
kono
parents: 67
diff changeset
78 /* hash_table support. */
kono
parents: 67
diff changeset
79 static inline hashval_t hash (const counts_entry *);
kono
parents: 67
diff changeset
80 static int equal (const counts_entry *, const counts_entry *);
kono
parents: 67
diff changeset
81 static void remove (counts_entry *);
kono
parents: 67
diff changeset
82 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
111
kono
parents: 67
diff changeset
84 static GTY(()) struct coverage_data *functions_head = 0;
kono
parents: 67
diff changeset
85 static struct coverage_data **functions_tail = &functions_head;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 static unsigned no_coverage = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 /* Cumulative counter information for whole program. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 static unsigned prg_ctr_mask; /* Mask of counter types generated. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 /* Counter information for current function. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 static unsigned fn_ctr_mask; /* Mask of counters used. */
111
kono
parents: 67
diff changeset
93 static GTY(()) tree fn_v_ctrs[GCOV_COUNTERS]; /* counter variables. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 static unsigned fn_n_ctrs[GCOV_COUNTERS]; /* Counters allocated. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 static unsigned fn_b_ctrs[GCOV_COUNTERS]; /* Allocation base. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
111
kono
parents: 67
diff changeset
97 /* Coverage info VAR_DECL and function info type nodes. */
kono
parents: 67
diff changeset
98 static GTY(()) tree gcov_info_var;
kono
parents: 67
diff changeset
99 static GTY(()) tree gcov_fn_info_type;
kono
parents: 67
diff changeset
100 static GTY(()) tree gcov_fn_info_ptr_type;
kono
parents: 67
diff changeset
101
kono
parents: 67
diff changeset
102 /* Name of the notes (gcno) output file. The "bbg" prefix is for
kono
parents: 67
diff changeset
103 historical reasons, when the notes file contained only the
kono
parents: 67
diff changeset
104 basic block graph notes.
kono
parents: 67
diff changeset
105 If this is NULL we're not writing to the notes file. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 static char *bbg_file_name;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
111
kono
parents: 67
diff changeset
108 /* File stamp for notes file. */
kono
parents: 67
diff changeset
109 static unsigned bbg_file_stamp;
kono
parents: 67
diff changeset
110
kono
parents: 67
diff changeset
111 /* Name of the count data (gcda) file. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 static char *da_file_name;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 /* The names of merge functions for counters. */
111
kono
parents: 67
diff changeset
115 #define STR(str) #str
kono
parents: 67
diff changeset
116 #define DEF_GCOV_COUNTER(COUNTER, NAME, FN_TYPE) STR(__gcov_merge ## FN_TYPE),
kono
parents: 67
diff changeset
117 static const char *const ctr_merge_functions[GCOV_COUNTERS] = {
kono
parents: 67
diff changeset
118 #include "gcov-counter.def"
kono
parents: 67
diff changeset
119 };
kono
parents: 67
diff changeset
120 #undef DEF_GCOV_COUNTER
kono
parents: 67
diff changeset
121 #undef STR
kono
parents: 67
diff changeset
122
kono
parents: 67
diff changeset
123 #define DEF_GCOV_COUNTER(COUNTER, NAME, FN_TYPE) NAME,
kono
parents: 67
diff changeset
124 static const char *const ctr_names[GCOV_COUNTERS] = {
kono
parents: 67
diff changeset
125 #include "gcov-counter.def"
kono
parents: 67
diff changeset
126 };
kono
parents: 67
diff changeset
127 #undef DEF_GCOV_COUNTER
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 /* Forward declarations. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 static void read_counts_file (void);
111
kono
parents: 67
diff changeset
131 static tree build_var (tree, tree, int);
kono
parents: 67
diff changeset
132 static void build_fn_info_type (tree, unsigned, tree);
kono
parents: 67
diff changeset
133 static void build_info_type (tree, tree);
kono
parents: 67
diff changeset
134 static tree build_fn_info (const struct coverage_data *, tree, tree);
kono
parents: 67
diff changeset
135 static tree build_info (tree, tree);
kono
parents: 67
diff changeset
136 static bool coverage_obj_init (void);
kono
parents: 67
diff changeset
137 static vec<constructor_elt, va_gc> *coverage_obj_fn
kono
parents: 67
diff changeset
138 (vec<constructor_elt, va_gc> *, tree, struct coverage_data const *);
kono
parents: 67
diff changeset
139 static void coverage_obj_finish (vec<constructor_elt, va_gc> *);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 /* Return the type node for gcov_type. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 get_gcov_type (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 {
111
kono
parents: 67
diff changeset
146 scalar_int_mode mode
kono
parents: 67
diff changeset
147 = smallest_int_mode_for_size (LONG_LONG_TYPE_SIZE > 32 ? 64 : 32);
kono
parents: 67
diff changeset
148 return lang_hooks.types.type_for_mode (mode, false);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 /* Return the type node for gcov_unsigned_t. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 static tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 get_gcov_unsigned_t (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 {
111
kono
parents: 67
diff changeset
156 scalar_int_mode mode = smallest_int_mode_for_size (32);
kono
parents: 67
diff changeset
157 return lang_hooks.types.type_for_mode (mode, true);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159
111
kono
parents: 67
diff changeset
160 inline hashval_t
kono
parents: 67
diff changeset
161 counts_entry::hash (const counts_entry *entry)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 return entry->ident * GCOV_COUNTERS + entry->ctr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
111
kono
parents: 67
diff changeset
166 inline int
kono
parents: 67
diff changeset
167 counts_entry::equal (const counts_entry *entry1, const counts_entry *entry2)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 return entry1->ident == entry2->ident && entry1->ctr == entry2->ctr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
111
kono
parents: 67
diff changeset
172 inline void
kono
parents: 67
diff changeset
173 counts_entry::remove (counts_entry *entry)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 free (entry->counts);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 free (entry);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178
111
kono
parents: 67
diff changeset
179 /* Hash table of count data. */
kono
parents: 67
diff changeset
180 static hash_table<counts_entry> *counts_hash;
kono
parents: 67
diff changeset
181
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 /* Read in the counts file, if available. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 read_counts_file (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 gcov_unsigned_t fn_ident = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 gcov_unsigned_t tag;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 int is_error = 0;
111
kono
parents: 67
diff changeset
190 unsigned lineno_checksum = 0;
kono
parents: 67
diff changeset
191 unsigned cfg_checksum = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 if (!gcov_open (da_file_name, 1))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 if (!gcov_magic (gcov_read_unsigned (), GCOV_DATA_MAGIC))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 warning (0, "%qs is not a gcov data file", da_file_name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 gcov_close ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 else if ((tag = gcov_read_unsigned ()) != GCOV_VERSION)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 char v[4], e[4];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 GCOV_UNSIGNED2STRING (v, tag);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 warning (0, "%qs is version %q.*s, expected version %q.*s",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 da_file_name, 4, v, 4, e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 gcov_close ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
111
kono
parents: 67
diff changeset
215 /* Read the stamp, used for creating a generation count. */
kono
parents: 67
diff changeset
216 tag = gcov_read_unsigned ();
kono
parents: 67
diff changeset
217 bbg_file_stamp = crc32_unsigned (bbg_file_stamp, tag);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
218
111
kono
parents: 67
diff changeset
219 counts_hash = new hash_table<counts_entry> (10);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 while ((tag = gcov_read_unsigned ()))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 gcov_unsigned_t length;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 gcov_position_t offset;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 length = gcov_read_unsigned ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 offset = gcov_position ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 if (tag == GCOV_TAG_FUNCTION)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 {
111
kono
parents: 67
diff changeset
229 if (length)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 {
111
kono
parents: 67
diff changeset
231 fn_ident = gcov_read_unsigned ();
kono
parents: 67
diff changeset
232 lineno_checksum = gcov_read_unsigned ();
kono
parents: 67
diff changeset
233 cfg_checksum = gcov_read_unsigned ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 }
111
kono
parents: 67
diff changeset
235 else
kono
parents: 67
diff changeset
236 fn_ident = lineno_checksum = cfg_checksum = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
238 else if (tag == GCOV_TAG_OBJECT_SUMMARY)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
240 profile_info = XCNEW (gcov_summary);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
241 profile_info->runs = gcov_read_unsigned ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
242 profile_info->sum_max = gcov_read_unsigned ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 else if (GCOV_TAG_IS_COUNTER (tag) && fn_ident)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 {
111
kono
parents: 67
diff changeset
246 counts_entry **slot, *entry, elt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 unsigned n_counts = GCOV_TAG_COUNTER_NUM (length);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 unsigned ix;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 elt.ident = fn_ident;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 elt.ctr = GCOV_COUNTER_FOR_TAG (tag);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252
111
kono
parents: 67
diff changeset
253 slot = counts_hash->find_slot (&elt, INSERT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 entry = *slot;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 if (!entry)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 {
111
kono
parents: 67
diff changeset
257 *slot = entry = XCNEW (counts_entry);
kono
parents: 67
diff changeset
258 entry->ident = fn_ident;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 entry->ctr = elt.ctr;
111
kono
parents: 67
diff changeset
260 entry->lineno_checksum = lineno_checksum;
kono
parents: 67
diff changeset
261 entry->cfg_checksum = cfg_checksum;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 entry->counts = XCNEWVEC (gcov_type, n_counts);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
263 entry->n_counts = n_counts;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 }
111
kono
parents: 67
diff changeset
265 else if (entry->lineno_checksum != lineno_checksum
kono
parents: 67
diff changeset
266 || entry->cfg_checksum != cfg_checksum)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
268 error ("profile data for function %u is corrupted", fn_ident);
111
kono
parents: 67
diff changeset
269 error ("checksum is (%x,%x) instead of (%x,%x)",
kono
parents: 67
diff changeset
270 entry->lineno_checksum, entry->cfg_checksum,
kono
parents: 67
diff changeset
271 lineno_checksum, cfg_checksum);
kono
parents: 67
diff changeset
272 delete counts_hash;
kono
parents: 67
diff changeset
273 counts_hash = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 for (ix = 0; ix != n_counts; ix++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 entry->counts[ix] += gcov_read_counter ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 gcov_sync (offset, length);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 if ((is_error = gcov_is_error ()))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 {
111
kono
parents: 67
diff changeset
282 error (is_error < 0
kono
parents: 67
diff changeset
283 ? G_("%qs has overflowed")
kono
parents: 67
diff changeset
284 : G_("%qs is corrupted"),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 da_file_name);
111
kono
parents: 67
diff changeset
286 delete counts_hash;
kono
parents: 67
diff changeset
287 counts_hash = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 gcov_close ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 /* Returns the counters for a particular tag. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 gcov_type *
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
298 get_coverage_counts (unsigned counter, unsigned cfg_checksum,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
299 unsigned lineno_checksum, unsigned int n_counts)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 {
111
kono
parents: 67
diff changeset
301 counts_entry *entry, elt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 /* No hash table, no counts. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 if (!counts_hash)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 static int warned = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
308 if (!warned++)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
309 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
310 warning (OPT_Wmissing_profile,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
311 "%qs profile count data file not found",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
312 da_file_name);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
313 if (dump_enabled_p ())
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
314 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
315 dump_user_location_t loc
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
316 = dump_user_location_t::from_location_t (input_location);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
317 dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
318 "file %s not found, %s\n", da_file_name,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
319 (flag_guess_branch_prob
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
320 ? "execution counts estimated"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
321 : "execution counts assumed to be zero"));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
322 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
323 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
326 if (param_profile_func_internal_id)
111
kono
parents: 67
diff changeset
327 elt.ident = current_function_funcdef_no + 1;
kono
parents: 67
diff changeset
328 else
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 {
111
kono
parents: 67
diff changeset
330 gcc_assert (coverage_node_map_initialized_p ());
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
331 elt.ident = cgraph_node::get (current_function_decl)->profile_id;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 }
111
kono
parents: 67
diff changeset
333 elt.ctr = counter;
kono
parents: 67
diff changeset
334 entry = counts_hash->find (&elt);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
335 if (!entry)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
336 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
337 if (counter == GCOV_COUNTER_ARCS)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
338 warning_at (DECL_SOURCE_LOCATION (current_function_decl),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
339 OPT_Wmissing_profile,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
340 "profile for function %qD not found in profile data",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
341 current_function_decl);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
342 /* The function was not emitted, or is weak and not chosen in the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
343 final executable. Silently fail, because there's nothing we
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
344 can do about it. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
345 return NULL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
346 }
111
kono
parents: 67
diff changeset
347
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
348 if (entry->cfg_checksum != cfg_checksum || entry->n_counts != n_counts)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 static int warned = 0;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
351 bool warning_printed = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
353 if (entry->n_counts != n_counts)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
354 warning_printed =
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
355 warning_at (DECL_SOURCE_LOCATION (current_function_decl),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
356 OPT_Wcoverage_mismatch,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
357 "number of counters in profile data for function %qD "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
358 "does not match "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
359 "its profile data (counter %qs, expected %i and have %i)",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
360 current_function_decl,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
361 ctr_names[counter], entry->n_counts, n_counts);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
362 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
363 warning_printed =
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
364 warning_at (DECL_SOURCE_LOCATION (current_function_decl),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
365 OPT_Wcoverage_mismatch,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
366 "the control flow of function %qD does not match "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
367 "its profile data (counter %qs)", current_function_decl,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
368 ctr_names[counter]);
111
kono
parents: 67
diff changeset
369 if (warning_printed && dump_enabled_p ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
371 dump_user_location_t loc
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
372 = dump_user_location_t::from_function_decl (current_function_decl);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
373 dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc,
111
kono
parents: 67
diff changeset
374 "use -Wno-error=coverage-mismatch to tolerate "
kono
parents: 67
diff changeset
375 "the mismatch but performance may drop if the "
kono
parents: 67
diff changeset
376 "function is hot\n");
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
377
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
378 if (!seen_error ()
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
379 && !warned++)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
380 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
381 dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc,
111
kono
parents: 67
diff changeset
382 "coverage mismatch ignored\n");
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
383 dump_printf (MSG_MISSED_OPTIMIZATION,
111
kono
parents: 67
diff changeset
384 flag_guess_branch_prob
kono
parents: 67
diff changeset
385 ? G_("execution counts estimated\n")
kono
parents: 67
diff changeset
386 : G_("execution counts assumed to be zero\n"));
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
387 if (!flag_guess_branch_prob)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
388 dump_printf (MSG_MISSED_OPTIMIZATION,
111
kono
parents: 67
diff changeset
389 "this can result in poorly optimized code\n");
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
390 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 }
111
kono
parents: 67
diff changeset
395 else if (entry->lineno_checksum != lineno_checksum)
kono
parents: 67
diff changeset
396 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
397 warning_at (DECL_SOURCE_LOCATION (current_function_decl),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
398 OPT_Wcoverage_mismatch,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
399 "source locations for function %qD have changed,"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
400 " the profile data may be out of date",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
401 current_function_decl);
111
kono
parents: 67
diff changeset
402 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 return entry->counts;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 /* Allocate NUM counters of type COUNTER. Returns nonzero if the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 allocation succeeded. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 coverage_counter_alloc (unsigned counter, unsigned num)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 if (no_coverage)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 if (!num)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418
111
kono
parents: 67
diff changeset
419 if (!fn_v_ctrs[counter])
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 {
111
kono
parents: 67
diff changeset
421 tree array_type = build_array_type (get_gcov_type (), NULL_TREE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422
111
kono
parents: 67
diff changeset
423 fn_v_ctrs[counter]
kono
parents: 67
diff changeset
424 = build_var (current_function_decl, array_type, counter);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 }
111
kono
parents: 67
diff changeset
426
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 fn_b_ctrs[counter] = fn_n_ctrs[counter];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 fn_n_ctrs[counter] += num;
111
kono
parents: 67
diff changeset
429
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 fn_ctr_mask |= 1 << counter;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 /* Generate a tree to access COUNTER NO. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 tree_coverage_counter_ref (unsigned counter, unsigned no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 tree gcov_type_node = get_gcov_type ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 gcc_assert (no < fn_n_ctrs[counter] - fn_b_ctrs[counter]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442
111
kono
parents: 67
diff changeset
443 no += fn_b_ctrs[counter];
kono
parents: 67
diff changeset
444
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 /* "no" here is an array index, scaled to bytes later. */
111
kono
parents: 67
diff changeset
446 return build4 (ARRAY_REF, gcov_type_node, fn_v_ctrs[counter],
kono
parents: 67
diff changeset
447 build_int_cst (integer_type_node, no), NULL, NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 /* Generate a tree to access the address of COUNTER NO. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 tree_coverage_counter_addr (unsigned counter, unsigned no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 tree gcov_type_node = get_gcov_type ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 gcc_assert (no < fn_n_ctrs[counter] - fn_b_ctrs[counter]);
111
kono
parents: 67
diff changeset
458 no += fn_b_ctrs[counter];
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
459
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 /* "no" here is an array index, scaled to bytes later. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 return build_fold_addr_expr (build4 (ARRAY_REF, gcov_type_node,
111
kono
parents: 67
diff changeset
462 fn_v_ctrs[counter],
kono
parents: 67
diff changeset
463 build_int_cst (integer_type_node, no),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 NULL, NULL));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466
111
kono
parents: 67
diff changeset
467
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 /* Generate a checksum for a string. CHKSUM is the current
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 checksum. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 static unsigned
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 coverage_checksum_string (unsigned chksum, const char *string)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 int i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 char *dup = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 /* Look for everything that looks if it were produced by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 get_file_function_name and zero out the second part
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 that may result from flag_random_seed. This is not critical
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 as the checksums are used only for sanity checking. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 for (i = 0; string[i]; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 int offset = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 if (!strncmp (string + i, "_GLOBAL__N_", 11))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 offset = 11;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 if (!strncmp (string + i, "_GLOBAL__", 9))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 offset = 9;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 /* C++ namespaces do have scheme:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 _GLOBAL__N_<filename>_<wrongmagicnumber>_<magicnumber>functionname
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 since filename might contain extra underscores there seems
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 to be no better chance then walk all possible offsets looking
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 for magicnumber. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 if (offset)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 for (i = i + offset; string[i]; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 if (string[i]=='_')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 int y;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 for (y = 1; y < 9; y++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 if (!(string[i + y] >= '0' && string[i + y] <= '9')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 && !(string[i + y] >= 'A' && string[i + y] <= 'F'))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 if (y != 9 || string[i + 9] != '_')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 for (y = 10; y < 18; y++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 if (!(string[i + y] >= '0' && string[i + y] <= '9')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 && !(string[i + y] >= 'A' && string[i + y] <= 'F'))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 if (y != 18)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 if (!dup)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 string = dup = xstrdup (string);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 for (y = 10; y < 18; y++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 dup[i + y] = '0';
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 chksum = crc32_string (chksum, string);
111
kono
parents: 67
diff changeset
523 free (dup);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 return chksum;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 /* Compute checksum for the current function. We generate a CRC32. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529
111
kono
parents: 67
diff changeset
530 unsigned
kono
parents: 67
diff changeset
531 coverage_compute_lineno_checksum (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 expanded_location xloc
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 unsigned chksum = xloc.line;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536
111
kono
parents: 67
diff changeset
537 if (xloc.file)
kono
parents: 67
diff changeset
538 chksum = coverage_checksum_string (chksum, xloc.file);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 chksum = coverage_checksum_string
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 (chksum, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 return chksum;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 }
111
kono
parents: 67
diff changeset
544
kono
parents: 67
diff changeset
545 /* Compute profile ID. This is better to be unique in whole program. */
kono
parents: 67
diff changeset
546
kono
parents: 67
diff changeset
547 unsigned
kono
parents: 67
diff changeset
548 coverage_compute_profile_id (struct cgraph_node *n)
kono
parents: 67
diff changeset
549 {
kono
parents: 67
diff changeset
550 unsigned chksum;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551
111
kono
parents: 67
diff changeset
552 /* Externally visible symbols have unique name. */
kono
parents: 67
diff changeset
553 if (TREE_PUBLIC (n->decl) || DECL_EXTERNAL (n->decl) || n->unique_name)
kono
parents: 67
diff changeset
554 {
kono
parents: 67
diff changeset
555 chksum = coverage_checksum_string
kono
parents: 67
diff changeset
556 (0, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (n->decl)));
kono
parents: 67
diff changeset
557 }
kono
parents: 67
diff changeset
558 else
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 expanded_location xloc
111
kono
parents: 67
diff changeset
561 = expand_location (DECL_SOURCE_LOCATION (n->decl));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
562 bool use_name_only = (param_profile_func_internal_id == 0);
111
kono
parents: 67
diff changeset
563
kono
parents: 67
diff changeset
564 chksum = (use_name_only ? 0 : xloc.line);
kono
parents: 67
diff changeset
565 if (xloc.file)
kono
parents: 67
diff changeset
566 chksum = coverage_checksum_string (chksum, xloc.file);
kono
parents: 67
diff changeset
567 chksum = coverage_checksum_string
kono
parents: 67
diff changeset
568 (chksum, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (n->decl)));
kono
parents: 67
diff changeset
569 if (!use_name_only && first_global_object_name)
kono
parents: 67
diff changeset
570 chksum = coverage_checksum_string
kono
parents: 67
diff changeset
571 (chksum, first_global_object_name);
kono
parents: 67
diff changeset
572 chksum = coverage_checksum_string
kono
parents: 67
diff changeset
573 (chksum, aux_base_name);
kono
parents: 67
diff changeset
574 }
kono
parents: 67
diff changeset
575
kono
parents: 67
diff changeset
576 /* Non-negative integers are hopefully small enough to fit in all targets.
kono
parents: 67
diff changeset
577 Gcov file formats wants non-zero function IDs. */
kono
parents: 67
diff changeset
578 chksum = chksum & 0x7fffffff;
kono
parents: 67
diff changeset
579 return chksum + (!chksum);
kono
parents: 67
diff changeset
580 }
kono
parents: 67
diff changeset
581
kono
parents: 67
diff changeset
582 /* Compute cfg checksum for the function FN given as argument.
kono
parents: 67
diff changeset
583 The checksum is calculated carefully so that
kono
parents: 67
diff changeset
584 source code changes that doesn't affect the control flow graph
kono
parents: 67
diff changeset
585 won't change the checksum.
kono
parents: 67
diff changeset
586 This is to make the profile data useable across source code change.
kono
parents: 67
diff changeset
587 The downside of this is that the compiler may use potentially
kono
parents: 67
diff changeset
588 wrong profile data - that the source code change has non-trivial impact
kono
parents: 67
diff changeset
589 on the validity of profile data (e.g. the reversed condition)
kono
parents: 67
diff changeset
590 but the compiler won't detect the change and use the wrong profile data. */
kono
parents: 67
diff changeset
591
kono
parents: 67
diff changeset
592 unsigned
kono
parents: 67
diff changeset
593 coverage_compute_cfg_checksum (struct function *fn)
kono
parents: 67
diff changeset
594 {
kono
parents: 67
diff changeset
595 basic_block bb;
kono
parents: 67
diff changeset
596 unsigned chksum = n_basic_blocks_for_fn (fn);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597
111
kono
parents: 67
diff changeset
598 FOR_EACH_BB_FN (bb, fn)
kono
parents: 67
diff changeset
599 {
kono
parents: 67
diff changeset
600 edge e;
kono
parents: 67
diff changeset
601 edge_iterator ei;
kono
parents: 67
diff changeset
602 chksum = crc32_byte (chksum, bb->index);
kono
parents: 67
diff changeset
603 FOR_EACH_EDGE (e, ei, bb->succs)
kono
parents: 67
diff changeset
604 {
kono
parents: 67
diff changeset
605 chksum = crc32_byte (chksum, e->dest->index);
kono
parents: 67
diff changeset
606 }
kono
parents: 67
diff changeset
607 }
kono
parents: 67
diff changeset
608
kono
parents: 67
diff changeset
609 return chksum;
kono
parents: 67
diff changeset
610 }
kono
parents: 67
diff changeset
611
kono
parents: 67
diff changeset
612 /* Begin output to the notes file for the current function.
kono
parents: 67
diff changeset
613 Writes the function header. Returns nonzero if data should be output. */
kono
parents: 67
diff changeset
614
kono
parents: 67
diff changeset
615 int
kono
parents: 67
diff changeset
616 coverage_begin_function (unsigned lineno_checksum, unsigned cfg_checksum)
kono
parents: 67
diff changeset
617 {
kono
parents: 67
diff changeset
618 expanded_location xloc;
kono
parents: 67
diff changeset
619 unsigned long offset;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620
111
kono
parents: 67
diff changeset
621 /* We don't need to output .gcno file unless we're under -ftest-coverage
kono
parents: 67
diff changeset
622 (e.g. -fprofile-arcs/generate/use don't need .gcno to work). */
kono
parents: 67
diff changeset
623 if (no_coverage || !bbg_file_name)
kono
parents: 67
diff changeset
624 return 0;
kono
parents: 67
diff changeset
625
kono
parents: 67
diff changeset
626 xloc = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627
111
kono
parents: 67
diff changeset
628 /* Announce function */
kono
parents: 67
diff changeset
629 offset = gcov_write_tag (GCOV_TAG_FUNCTION);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
630 if (param_profile_func_internal_id)
111
kono
parents: 67
diff changeset
631 gcov_write_unsigned (current_function_funcdef_no + 1);
kono
parents: 67
diff changeset
632 else
kono
parents: 67
diff changeset
633 {
kono
parents: 67
diff changeset
634 gcc_assert (coverage_node_map_initialized_p ());
kono
parents: 67
diff changeset
635 gcov_write_unsigned (
kono
parents: 67
diff changeset
636 cgraph_node::get (current_function_decl)->profile_id);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 }
111
kono
parents: 67
diff changeset
638
kono
parents: 67
diff changeset
639 gcov_write_unsigned (lineno_checksum);
kono
parents: 67
diff changeset
640 gcov_write_unsigned (cfg_checksum);
kono
parents: 67
diff changeset
641 gcov_write_string (IDENTIFIER_POINTER
kono
parents: 67
diff changeset
642 (DECL_ASSEMBLER_NAME (current_function_decl)));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
643 gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
644 && !DECL_FUNCTION_VERSIONED (current_function_decl)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
645 && !DECL_LAMBDA_FUNCTION_P (current_function_decl));
111
kono
parents: 67
diff changeset
646 gcov_write_filename (xloc.file);
kono
parents: 67
diff changeset
647 gcov_write_unsigned (xloc.line);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
648 gcov_write_unsigned (xloc.column);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
649
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
650 expanded_location endloc = expand_location (cfun->function_end_locus);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
651
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
652 /* Function can start in a single file and end in another one. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
653 int end_line = endloc.file == xloc.file ? endloc.line : xloc.line;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
654 int end_column = endloc.file == xloc.file ? endloc.column: xloc.column;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
655 gcc_assert (xloc.line <= end_line);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
656 gcov_write_unsigned (end_line);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
657 gcov_write_unsigned (end_column);
111
kono
parents: 67
diff changeset
658 gcov_write_length (offset);
kono
parents: 67
diff changeset
659
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 return !gcov_is_error ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
662
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 /* Finish coverage data for the current function. Verify no output
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 error has occurred. Save function coverage counts. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 void
111
kono
parents: 67
diff changeset
667 coverage_end_function (unsigned lineno_checksum, unsigned cfg_checksum)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 unsigned i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
670
111
kono
parents: 67
diff changeset
671 if (bbg_file_name && gcov_is_error ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 warning (0, "error writing %qs", bbg_file_name);
111
kono
parents: 67
diff changeset
674 unlink (bbg_file_name);
kono
parents: 67
diff changeset
675 bbg_file_name = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 if (fn_ctr_mask)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 {
111
kono
parents: 67
diff changeset
680 struct coverage_data *item = 0;
kono
parents: 67
diff changeset
681
kono
parents: 67
diff changeset
682 item = ggc_alloc<coverage_data> ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
684 if (param_profile_func_internal_id)
111
kono
parents: 67
diff changeset
685 item->ident = current_function_funcdef_no + 1;
kono
parents: 67
diff changeset
686 else
kono
parents: 67
diff changeset
687 {
kono
parents: 67
diff changeset
688 gcc_assert (coverage_node_map_initialized_p ());
kono
parents: 67
diff changeset
689 item->ident = cgraph_node::get (cfun->decl)->profile_id;
kono
parents: 67
diff changeset
690 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691
111
kono
parents: 67
diff changeset
692 item->lineno_checksum = lineno_checksum;
kono
parents: 67
diff changeset
693 item->cfg_checksum = cfg_checksum;
kono
parents: 67
diff changeset
694
kono
parents: 67
diff changeset
695 item->fn_decl = current_function_decl;
kono
parents: 67
diff changeset
696 item->next = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 *functions_tail = item;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 functions_tail = &item->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 for (i = 0; i != GCOV_COUNTERS; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 {
111
kono
parents: 67
diff changeset
702 tree var = fn_v_ctrs[i];
kono
parents: 67
diff changeset
703
kono
parents: 67
diff changeset
704 if (item)
kono
parents: 67
diff changeset
705 item->ctr_vars[i] = var;
kono
parents: 67
diff changeset
706 if (var)
kono
parents: 67
diff changeset
707 {
kono
parents: 67
diff changeset
708 tree array_type = build_index_type (size_int (fn_n_ctrs[i] - 1));
kono
parents: 67
diff changeset
709 array_type = build_array_type (get_gcov_type (), array_type);
kono
parents: 67
diff changeset
710 TREE_TYPE (var) = array_type;
kono
parents: 67
diff changeset
711 DECL_SIZE (var) = TYPE_SIZE (array_type);
kono
parents: 67
diff changeset
712 DECL_SIZE_UNIT (var) = TYPE_SIZE_UNIT (array_type);
kono
parents: 67
diff changeset
713 varpool_node::finalize_decl (var);
kono
parents: 67
diff changeset
714 }
kono
parents: 67
diff changeset
715
kono
parents: 67
diff changeset
716 fn_b_ctrs[i] = fn_n_ctrs[i] = 0;
kono
parents: 67
diff changeset
717 fn_v_ctrs[i] = NULL_TREE;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 prg_ctr_mask |= fn_ctr_mask;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 fn_ctr_mask = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 }
111
kono
parents: 67
diff changeset
722 }
kono
parents: 67
diff changeset
723
kono
parents: 67
diff changeset
724 /* Remove coverage file if opened. */
kono
parents: 67
diff changeset
725
kono
parents: 67
diff changeset
726 void
kono
parents: 67
diff changeset
727 coverage_remove_note_file (void)
kono
parents: 67
diff changeset
728 {
kono
parents: 67
diff changeset
729 if (bbg_file_name)
kono
parents: 67
diff changeset
730 {
kono
parents: 67
diff changeset
731 gcov_close ();
kono
parents: 67
diff changeset
732 unlink (bbg_file_name);
kono
parents: 67
diff changeset
733 }
kono
parents: 67
diff changeset
734 }
kono
parents: 67
diff changeset
735
kono
parents: 67
diff changeset
736 /* Build a coverage variable of TYPE for function FN_DECL. If COUNTER
kono
parents: 67
diff changeset
737 >= 0 it is a counter array, otherwise it is the function structure. */
kono
parents: 67
diff changeset
738
kono
parents: 67
diff changeset
739 static tree
kono
parents: 67
diff changeset
740 build_var (tree fn_decl, tree type, int counter)
kono
parents: 67
diff changeset
741 {
kono
parents: 67
diff changeset
742 tree var = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL_TREE, type);
kono
parents: 67
diff changeset
743 const char *fn_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn_decl));
kono
parents: 67
diff changeset
744 char *buf;
kono
parents: 67
diff changeset
745 size_t fn_name_len, len;
kono
parents: 67
diff changeset
746
kono
parents: 67
diff changeset
747 fn_name = targetm.strip_name_encoding (fn_name);
kono
parents: 67
diff changeset
748 fn_name_len = strlen (fn_name);
kono
parents: 67
diff changeset
749 buf = XALLOCAVEC (char, fn_name_len + 8 + sizeof (int) * 3);
kono
parents: 67
diff changeset
750
kono
parents: 67
diff changeset
751 if (counter < 0)
kono
parents: 67
diff changeset
752 strcpy (buf, "__gcov__");
kono
parents: 67
diff changeset
753 else
kono
parents: 67
diff changeset
754 sprintf (buf, "__gcov%u_", counter);
kono
parents: 67
diff changeset
755 len = strlen (buf);
kono
parents: 67
diff changeset
756 buf[len - 1] = symbol_table::symbol_suffix_separator ();
kono
parents: 67
diff changeset
757 memcpy (buf + len, fn_name, fn_name_len + 1);
kono
parents: 67
diff changeset
758 DECL_NAME (var) = get_identifier (buf);
kono
parents: 67
diff changeset
759 TREE_STATIC (var) = 1;
kono
parents: 67
diff changeset
760 TREE_ADDRESSABLE (var) = 1;
kono
parents: 67
diff changeset
761 DECL_NONALIASED (var) = 1;
kono
parents: 67
diff changeset
762 SET_DECL_ALIGN (var, TYPE_ALIGN (type));
kono
parents: 67
diff changeset
763
kono
parents: 67
diff changeset
764 return var;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 /* Creates the gcov_fn_info RECORD_TYPE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768
111
kono
parents: 67
diff changeset
769 static void
kono
parents: 67
diff changeset
770 build_fn_info_type (tree type, unsigned counters, tree gcov_info_type)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 {
111
kono
parents: 67
diff changeset
772 tree ctr_info = lang_hooks.types.make_type (RECORD_TYPE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 tree field, fields;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 tree array_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775
111
kono
parents: 67
diff changeset
776 gcc_assert (counters);
kono
parents: 67
diff changeset
777
kono
parents: 67
diff changeset
778 /* ctr_info::num */
kono
parents: 67
diff changeset
779 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
780 get_gcov_unsigned_t ());
kono
parents: 67
diff changeset
781 fields = field;
kono
parents: 67
diff changeset
782
kono
parents: 67
diff changeset
783 /* ctr_info::values */
kono
parents: 67
diff changeset
784 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
785 build_pointer_type (get_gcov_type ()));
kono
parents: 67
diff changeset
786 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
787 fields = field;
kono
parents: 67
diff changeset
788
kono
parents: 67
diff changeset
789 finish_builtin_struct (ctr_info, "__gcov_ctr_info", fields, NULL_TREE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790
111
kono
parents: 67
diff changeset
791 /* key */
kono
parents: 67
diff changeset
792 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
793 build_pointer_type (build_qualified_type
kono
parents: 67
diff changeset
794 (gcov_info_type, TYPE_QUAL_CONST)));
kono
parents: 67
diff changeset
795 fields = field;
kono
parents: 67
diff changeset
796
kono
parents: 67
diff changeset
797 /* ident */
kono
parents: 67
diff changeset
798 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
799 get_gcov_unsigned_t ());
kono
parents: 67
diff changeset
800 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
801 fields = field;
kono
parents: 67
diff changeset
802
kono
parents: 67
diff changeset
803 /* lineno_checksum */
kono
parents: 67
diff changeset
804 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
805 get_gcov_unsigned_t ());
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
806 DECL_CHAIN (field) = fields;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 fields = field;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808
111
kono
parents: 67
diff changeset
809 /* cfg checksum */
kono
parents: 67
diff changeset
810 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
811 get_gcov_unsigned_t ());
kono
parents: 67
diff changeset
812 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
813 fields = field;
kono
parents: 67
diff changeset
814
kono
parents: 67
diff changeset
815 array_type = build_index_type (size_int (counters - 1));
kono
parents: 67
diff changeset
816 array_type = build_array_type (ctr_info, array_type);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 /* counters */
111
kono
parents: 67
diff changeset
819 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE, array_type);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
820 DECL_CHAIN (field) = fields;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 fields = field;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 finish_builtin_struct (type, "__gcov_fn_info", fields, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825
111
kono
parents: 67
diff changeset
826 /* Returns a CONSTRUCTOR for a gcov_fn_info. DATA is
kono
parents: 67
diff changeset
827 the coverage data for the function and TYPE is the gcov_fn_info
kono
parents: 67
diff changeset
828 RECORD_TYPE. KEY is the object file key. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830 static tree
111
kono
parents: 67
diff changeset
831 build_fn_info (const struct coverage_data *data, tree type, tree key)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 tree fields = TYPE_FIELDS (type);
111
kono
parents: 67
diff changeset
834 tree ctr_type;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 unsigned ix;
111
kono
parents: 67
diff changeset
836 vec<constructor_elt, va_gc> *v1 = NULL;
kono
parents: 67
diff changeset
837 vec<constructor_elt, va_gc> *v2 = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838
111
kono
parents: 67
diff changeset
839 /* key */
kono
parents: 67
diff changeset
840 CONSTRUCTOR_APPEND_ELT (v1, fields,
kono
parents: 67
diff changeset
841 build1 (ADDR_EXPR, TREE_TYPE (fields), key));
kono
parents: 67
diff changeset
842 fields = DECL_CHAIN (fields);
kono
parents: 67
diff changeset
843
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 /* ident */
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
845 CONSTRUCTOR_APPEND_ELT (v1, fields,
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
846 build_int_cstu (get_gcov_unsigned_t (),
111
kono
parents: 67
diff changeset
847 data->ident));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
848 fields = DECL_CHAIN (fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849
111
kono
parents: 67
diff changeset
850 /* lineno_checksum */
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
851 CONSTRUCTOR_APPEND_ELT (v1, fields,
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
852 build_int_cstu (get_gcov_unsigned_t (),
111
kono
parents: 67
diff changeset
853 data->lineno_checksum));
kono
parents: 67
diff changeset
854 fields = DECL_CHAIN (fields);
kono
parents: 67
diff changeset
855
kono
parents: 67
diff changeset
856 /* cfg_checksum */
kono
parents: 67
diff changeset
857 CONSTRUCTOR_APPEND_ELT (v1, fields,
kono
parents: 67
diff changeset
858 build_int_cstu (get_gcov_unsigned_t (),
kono
parents: 67
diff changeset
859 data->cfg_checksum));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
860 fields = DECL_CHAIN (fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862 /* counters */
111
kono
parents: 67
diff changeset
863 ctr_type = TREE_TYPE (TREE_TYPE (fields));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
864 for (ix = 0; ix != GCOV_COUNTERS; ix++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865 if (prg_ctr_mask & (1 << ix))
111
kono
parents: 67
diff changeset
866 {
kono
parents: 67
diff changeset
867 vec<constructor_elt, va_gc> *ctr = NULL;
kono
parents: 67
diff changeset
868 tree var = data->ctr_vars[ix];
kono
parents: 67
diff changeset
869 unsigned count = 0;
kono
parents: 67
diff changeset
870
kono
parents: 67
diff changeset
871 if (var)
kono
parents: 67
diff changeset
872 count
kono
parents: 67
diff changeset
873 = tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (var))))
kono
parents: 67
diff changeset
874 + 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
875
111
kono
parents: 67
diff changeset
876 CONSTRUCTOR_APPEND_ELT (ctr, TYPE_FIELDS (ctr_type),
kono
parents: 67
diff changeset
877 build_int_cstu (get_gcov_unsigned_t (),
kono
parents: 67
diff changeset
878 count));
kono
parents: 67
diff changeset
879
kono
parents: 67
diff changeset
880 if (var)
kono
parents: 67
diff changeset
881 CONSTRUCTOR_APPEND_ELT (ctr, DECL_CHAIN (TYPE_FIELDS (ctr_type)),
kono
parents: 67
diff changeset
882 build_fold_addr_expr (var));
kono
parents: 67
diff changeset
883
kono
parents: 67
diff changeset
884 CONSTRUCTOR_APPEND_ELT (v2, NULL, build_constructor (ctr_type, ctr));
kono
parents: 67
diff changeset
885 }
kono
parents: 67
diff changeset
886
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
887 CONSTRUCTOR_APPEND_ELT (v1, fields,
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
888 build_constructor (TREE_TYPE (fields), v2));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
889
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
890 return build_constructor (type, v1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
891 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892
111
kono
parents: 67
diff changeset
893 /* Create gcov_info struct. TYPE is the incomplete RECORD_TYPE to be
kono
parents: 67
diff changeset
894 completed, and FN_INFO_PTR_TYPE is a pointer to the function info type. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
895
111
kono
parents: 67
diff changeset
896 static void
kono
parents: 67
diff changeset
897 build_info_type (tree type, tree fn_info_ptr_type)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
898 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
899 tree field, fields = NULL_TREE;
111
kono
parents: 67
diff changeset
900 tree merge_fn_type;
kono
parents: 67
diff changeset
901
kono
parents: 67
diff changeset
902 /* Version ident */
kono
parents: 67
diff changeset
903 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
904 get_gcov_unsigned_t ());
kono
parents: 67
diff changeset
905 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
906 fields = field;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907
111
kono
parents: 67
diff changeset
908 /* next pointer */
kono
parents: 67
diff changeset
909 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
910 build_pointer_type (build_qualified_type
kono
parents: 67
diff changeset
911 (type, TYPE_QUAL_CONST)));
kono
parents: 67
diff changeset
912 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
913 fields = field;
kono
parents: 67
diff changeset
914
kono
parents: 67
diff changeset
915 /* stamp */
kono
parents: 67
diff changeset
916 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
917 get_gcov_unsigned_t ());
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
918 DECL_CHAIN (field) = fields;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 fields = field;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
920
111
kono
parents: 67
diff changeset
921 /* Filename */
kono
parents: 67
diff changeset
922 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
923 build_pointer_type (build_qualified_type
kono
parents: 67
diff changeset
924 (char_type_node, TYPE_QUAL_CONST)));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
925 DECL_CHAIN (field) = fields;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
926 fields = field;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
927
111
kono
parents: 67
diff changeset
928 /* merge fn array */
kono
parents: 67
diff changeset
929 merge_fn_type
kono
parents: 67
diff changeset
930 = build_function_type_list (void_type_node,
kono
parents: 67
diff changeset
931 build_pointer_type (get_gcov_type ()),
kono
parents: 67
diff changeset
932 get_gcov_unsigned_t (), NULL_TREE);
kono
parents: 67
diff changeset
933 merge_fn_type
kono
parents: 67
diff changeset
934 = build_array_type (build_pointer_type (merge_fn_type),
kono
parents: 67
diff changeset
935 build_index_type (size_int (GCOV_COUNTERS - 1)));
kono
parents: 67
diff changeset
936 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
937 merge_fn_type);
kono
parents: 67
diff changeset
938 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
939 fields = field;
kono
parents: 67
diff changeset
940
kono
parents: 67
diff changeset
941 /* n_functions */
kono
parents: 67
diff changeset
942 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
943 get_gcov_unsigned_t ());
kono
parents: 67
diff changeset
944 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
945 fields = field;
kono
parents: 67
diff changeset
946
kono
parents: 67
diff changeset
947 /* function_info pointer pointer */
kono
parents: 67
diff changeset
948 fn_info_ptr_type = build_pointer_type
kono
parents: 67
diff changeset
949 (build_qualified_type (fn_info_ptr_type, TYPE_QUAL_CONST));
kono
parents: 67
diff changeset
950 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
951 fn_info_ptr_type);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
952 DECL_CHAIN (field) = fields;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
953 fields = field;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954
111
kono
parents: 67
diff changeset
955 finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957
111
kono
parents: 67
diff changeset
958 /* Returns a CONSTRUCTOR for the gcov_info object. INFO_TYPE is the
kono
parents: 67
diff changeset
959 gcov_info structure type, FN_ARY is the array of pointers to
kono
parents: 67
diff changeset
960 function info objects. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
962 static tree
111
kono
parents: 67
diff changeset
963 build_info (tree info_type, tree fn_ary)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
964 {
111
kono
parents: 67
diff changeset
965 tree info_fields = TYPE_FIELDS (info_type);
kono
parents: 67
diff changeset
966 tree merge_fn_type, n_funcs;
kono
parents: 67
diff changeset
967 unsigned ix;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
968 tree filename_string;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
969 int da_file_name_len;
111
kono
parents: 67
diff changeset
970 vec<constructor_elt, va_gc> *v1 = NULL;
kono
parents: 67
diff changeset
971 vec<constructor_elt, va_gc> *v2 = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
972
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
973 /* Version ident */
111
kono
parents: 67
diff changeset
974 CONSTRUCTOR_APPEND_ELT (v1, info_fields,
kono
parents: 67
diff changeset
975 build_int_cstu (TREE_TYPE (info_fields),
kono
parents: 67
diff changeset
976 GCOV_VERSION));
kono
parents: 67
diff changeset
977 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
978
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
979 /* next -- NULL */
111
kono
parents: 67
diff changeset
980 CONSTRUCTOR_APPEND_ELT (v1, info_fields, null_pointer_node);
kono
parents: 67
diff changeset
981 info_fields = DECL_CHAIN (info_fields);
kono
parents: 67
diff changeset
982
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983 /* stamp */
111
kono
parents: 67
diff changeset
984 CONSTRUCTOR_APPEND_ELT (v1, info_fields,
kono
parents: 67
diff changeset
985 build_int_cstu (TREE_TYPE (info_fields),
kono
parents: 67
diff changeset
986 bbg_file_stamp));
kono
parents: 67
diff changeset
987 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
988
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 /* Filename */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990 da_file_name_len = strlen (da_file_name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
991 filename_string = build_string (da_file_name_len + 1, da_file_name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
992 TREE_TYPE (filename_string) = build_array_type
111
kono
parents: 67
diff changeset
993 (char_type_node, build_index_type (size_int (da_file_name_len)));
kono
parents: 67
diff changeset
994 CONSTRUCTOR_APPEND_ELT (v1, info_fields,
kono
parents: 67
diff changeset
995 build1 (ADDR_EXPR, TREE_TYPE (info_fields),
kono
parents: 67
diff changeset
996 filename_string));
kono
parents: 67
diff changeset
997 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998
111
kono
parents: 67
diff changeset
999 /* merge fn array -- NULL slots indicate unmeasured counters */
kono
parents: 67
diff changeset
1000 merge_fn_type = TREE_TYPE (TREE_TYPE (info_fields));
kono
parents: 67
diff changeset
1001 for (ix = 0; ix != GCOV_COUNTERS; ix++)
kono
parents: 67
diff changeset
1002 {
kono
parents: 67
diff changeset
1003 tree ptr = null_pointer_node;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004
111
kono
parents: 67
diff changeset
1005 if ((1u << ix) & prg_ctr_mask)
kono
parents: 67
diff changeset
1006 {
kono
parents: 67
diff changeset
1007 tree merge_fn = build_decl (BUILTINS_LOCATION,
kono
parents: 67
diff changeset
1008 FUNCTION_DECL,
kono
parents: 67
diff changeset
1009 get_identifier (ctr_merge_functions[ix]),
kono
parents: 67
diff changeset
1010 TREE_TYPE (merge_fn_type));
kono
parents: 67
diff changeset
1011 DECL_EXTERNAL (merge_fn) = 1;
kono
parents: 67
diff changeset
1012 TREE_PUBLIC (merge_fn) = 1;
kono
parents: 67
diff changeset
1013 DECL_ARTIFICIAL (merge_fn) = 1;
kono
parents: 67
diff changeset
1014 TREE_NOTHROW (merge_fn) = 1;
kono
parents: 67
diff changeset
1015 /* Initialize assembler name so we can stream out. */
kono
parents: 67
diff changeset
1016 DECL_ASSEMBLER_NAME (merge_fn);
kono
parents: 67
diff changeset
1017 ptr = build1 (ADDR_EXPR, merge_fn_type, merge_fn);
kono
parents: 67
diff changeset
1018 }
kono
parents: 67
diff changeset
1019 CONSTRUCTOR_APPEND_ELT (v2, NULL, ptr);
kono
parents: 67
diff changeset
1020 }
kono
parents: 67
diff changeset
1021 CONSTRUCTOR_APPEND_ELT (v1, info_fields,
kono
parents: 67
diff changeset
1022 build_constructor (TREE_TYPE (info_fields), v2));
kono
parents: 67
diff changeset
1023 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024
111
kono
parents: 67
diff changeset
1025 /* n_functions */
kono
parents: 67
diff changeset
1026 n_funcs = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (fn_ary)));
kono
parents: 67
diff changeset
1027 n_funcs = fold_build2 (PLUS_EXPR, TREE_TYPE (info_fields),
kono
parents: 67
diff changeset
1028 n_funcs, size_one_node);
kono
parents: 67
diff changeset
1029 CONSTRUCTOR_APPEND_ELT (v1, info_fields, n_funcs);
kono
parents: 67
diff changeset
1030 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1031
111
kono
parents: 67
diff changeset
1032 /* functions */
kono
parents: 67
diff changeset
1033 CONSTRUCTOR_APPEND_ELT (v1, info_fields,
kono
parents: 67
diff changeset
1034 build1 (ADDR_EXPR, TREE_TYPE (info_fields), fn_ary));
kono
parents: 67
diff changeset
1035 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036
111
kono
parents: 67
diff changeset
1037 gcc_assert (!info_fields);
kono
parents: 67
diff changeset
1038 return build_constructor (info_type, v1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040
111
kono
parents: 67
diff changeset
1041 /* Generate the constructor function to call __gcov_init. */
kono
parents: 67
diff changeset
1042
kono
parents: 67
diff changeset
1043 static void
kono
parents: 67
diff changeset
1044 build_init_ctor (tree gcov_info_type)
kono
parents: 67
diff changeset
1045 {
kono
parents: 67
diff changeset
1046 tree ctor, stmt, init_fn;
kono
parents: 67
diff changeset
1047
kono
parents: 67
diff changeset
1048 /* Build a decl for __gcov_init. */
kono
parents: 67
diff changeset
1049 init_fn = build_pointer_type (gcov_info_type);
kono
parents: 67
diff changeset
1050 init_fn = build_function_type_list (void_type_node, init_fn, NULL);
kono
parents: 67
diff changeset
1051 init_fn = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
kono
parents: 67
diff changeset
1052 get_identifier ("__gcov_init"), init_fn);
kono
parents: 67
diff changeset
1053 TREE_PUBLIC (init_fn) = 1;
kono
parents: 67
diff changeset
1054 DECL_EXTERNAL (init_fn) = 1;
kono
parents: 67
diff changeset
1055 DECL_ASSEMBLER_NAME (init_fn);
kono
parents: 67
diff changeset
1056
kono
parents: 67
diff changeset
1057 /* Generate a call to __gcov_init(&gcov_info). */
kono
parents: 67
diff changeset
1058 ctor = NULL;
kono
parents: 67
diff changeset
1059 stmt = build_fold_addr_expr (gcov_info_var);
kono
parents: 67
diff changeset
1060 stmt = build_call_expr (init_fn, 1, stmt);
kono
parents: 67
diff changeset
1061 append_to_statement_list (stmt, &ctor);
kono
parents: 67
diff changeset
1062
kono
parents: 67
diff changeset
1063 /* Generate a constructor to run it. */
kono
parents: 67
diff changeset
1064 int priority = SUPPORTS_INIT_PRIORITY
kono
parents: 67
diff changeset
1065 ? MAX_RESERVED_INIT_PRIORITY: DEFAULT_INIT_PRIORITY;
kono
parents: 67
diff changeset
1066 cgraph_build_static_cdtor ('I', ctor, priority);
kono
parents: 67
diff changeset
1067 }
kono
parents: 67
diff changeset
1068
kono
parents: 67
diff changeset
1069 /* Generate the destructor function to call __gcov_exit. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1070
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1071 static void
111
kono
parents: 67
diff changeset
1072 build_gcov_exit_decl (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1074 tree init_fn = build_function_type_list (void_type_node, NULL);
111
kono
parents: 67
diff changeset
1075 init_fn = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
kono
parents: 67
diff changeset
1076 get_identifier ("__gcov_exit"), init_fn);
kono
parents: 67
diff changeset
1077 TREE_PUBLIC (init_fn) = 1;
kono
parents: 67
diff changeset
1078 DECL_EXTERNAL (init_fn) = 1;
kono
parents: 67
diff changeset
1079 DECL_ASSEMBLER_NAME (init_fn);
kono
parents: 67
diff changeset
1080
kono
parents: 67
diff changeset
1081 /* Generate a call to __gcov_exit (). */
kono
parents: 67
diff changeset
1082 tree dtor = NULL;
kono
parents: 67
diff changeset
1083 tree stmt = build_call_expr (init_fn, 0);
kono
parents: 67
diff changeset
1084 append_to_statement_list (stmt, &dtor);
kono
parents: 67
diff changeset
1085
kono
parents: 67
diff changeset
1086 /* Generate a destructor to run it. */
kono
parents: 67
diff changeset
1087 int priority = SUPPORTS_INIT_PRIORITY
kono
parents: 67
diff changeset
1088 ? MAX_RESERVED_INIT_PRIORITY: DEFAULT_INIT_PRIORITY;
kono
parents: 67
diff changeset
1089
kono
parents: 67
diff changeset
1090 cgraph_build_static_cdtor ('D', dtor, priority);
kono
parents: 67
diff changeset
1091 }
kono
parents: 67
diff changeset
1092
kono
parents: 67
diff changeset
1093 /* Create the gcov_info types and object. Generate the constructor
kono
parents: 67
diff changeset
1094 function to call __gcov_init. Does not generate the initializer
kono
parents: 67
diff changeset
1095 for the object. Returns TRUE if coverage data is being emitted. */
kono
parents: 67
diff changeset
1096
kono
parents: 67
diff changeset
1097 static bool
kono
parents: 67
diff changeset
1098 coverage_obj_init (void)
kono
parents: 67
diff changeset
1099 {
kono
parents: 67
diff changeset
1100 tree gcov_info_type;
kono
parents: 67
diff changeset
1101 unsigned n_counters = 0;
kono
parents: 67
diff changeset
1102 unsigned ix;
kono
parents: 67
diff changeset
1103 struct coverage_data *fn;
kono
parents: 67
diff changeset
1104 struct coverage_data **fn_prev;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105 char name_buf[32];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1107 no_coverage = 1; /* Disable any further coverage. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1108
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109 if (!prg_ctr_mask)
111
kono
parents: 67
diff changeset
1110 return false;
kono
parents: 67
diff changeset
1111
kono
parents: 67
diff changeset
1112 if (symtab->dump_file)
kono
parents: 67
diff changeset
1113 fprintf (symtab->dump_file, "Using data file %s\n", da_file_name);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1114
111
kono
parents: 67
diff changeset
1115 /* Prune functions. */
kono
parents: 67
diff changeset
1116 for (fn_prev = &functions_head; (fn = *fn_prev);)
kono
parents: 67
diff changeset
1117 if (DECL_STRUCT_FUNCTION (fn->fn_decl))
kono
parents: 67
diff changeset
1118 fn_prev = &fn->next;
kono
parents: 67
diff changeset
1119 else
kono
parents: 67
diff changeset
1120 /* The function is not being emitted, remove from list. */
kono
parents: 67
diff changeset
1121 *fn_prev = fn->next;
kono
parents: 67
diff changeset
1122
kono
parents: 67
diff changeset
1123 if (functions_head == NULL)
kono
parents: 67
diff changeset
1124 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1125
111
kono
parents: 67
diff changeset
1126 for (ix = 0; ix != GCOV_COUNTERS; ix++)
kono
parents: 67
diff changeset
1127 if ((1u << ix) & prg_ctr_mask)
kono
parents: 67
diff changeset
1128 n_counters++;
kono
parents: 67
diff changeset
1129
kono
parents: 67
diff changeset
1130 /* Build the info and fn_info types. These are mutually recursive. */
kono
parents: 67
diff changeset
1131 gcov_info_type = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents: 67
diff changeset
1132 gcov_fn_info_type = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents: 67
diff changeset
1133 build_fn_info_type (gcov_fn_info_type, n_counters, gcov_info_type);
kono
parents: 67
diff changeset
1134 gcov_info_type = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents: 67
diff changeset
1135 gcov_fn_info_ptr_type = build_pointer_type
kono
parents: 67
diff changeset
1136 (build_qualified_type (gcov_fn_info_type, TYPE_QUAL_CONST));
kono
parents: 67
diff changeset
1137 build_info_type (gcov_info_type, gcov_fn_info_ptr_type);
kono
parents: 67
diff changeset
1138
kono
parents: 67
diff changeset
1139 /* Build the gcov info var, this is referred to in its own
kono
parents: 67
diff changeset
1140 initializer. */
kono
parents: 67
diff changeset
1141 gcov_info_var = build_decl (BUILTINS_LOCATION,
kono
parents: 67
diff changeset
1142 VAR_DECL, NULL_TREE, gcov_info_type);
kono
parents: 67
diff changeset
1143 TREE_STATIC (gcov_info_var) = 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144 ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 0);
111
kono
parents: 67
diff changeset
1145 DECL_NAME (gcov_info_var) = get_identifier (name_buf);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1146
111
kono
parents: 67
diff changeset
1147 build_init_ctor (gcov_info_type);
kono
parents: 67
diff changeset
1148 build_gcov_exit_decl ();
kono
parents: 67
diff changeset
1149
kono
parents: 67
diff changeset
1150 return true;
kono
parents: 67
diff changeset
1151 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1152
111
kono
parents: 67
diff changeset
1153 /* Generate the coverage function info for FN and DATA. Append a
kono
parents: 67
diff changeset
1154 pointer to that object to CTOR and return the appended CTOR. */
kono
parents: 67
diff changeset
1155
kono
parents: 67
diff changeset
1156 static vec<constructor_elt, va_gc> *
kono
parents: 67
diff changeset
1157 coverage_obj_fn (vec<constructor_elt, va_gc> *ctor, tree fn,
kono
parents: 67
diff changeset
1158 struct coverage_data const *data)
kono
parents: 67
diff changeset
1159 {
kono
parents: 67
diff changeset
1160 tree init = build_fn_info (data, gcov_fn_info_type, gcov_info_var);
kono
parents: 67
diff changeset
1161 tree var = build_var (fn, gcov_fn_info_type, -1);
kono
parents: 67
diff changeset
1162
kono
parents: 67
diff changeset
1163 DECL_INITIAL (var) = init;
kono
parents: 67
diff changeset
1164 varpool_node::finalize_decl (var);
kono
parents: 67
diff changeset
1165
kono
parents: 67
diff changeset
1166 CONSTRUCTOR_APPEND_ELT (ctor, NULL,
kono
parents: 67
diff changeset
1167 build1 (ADDR_EXPR, gcov_fn_info_ptr_type, var));
kono
parents: 67
diff changeset
1168 return ctor;
kono
parents: 67
diff changeset
1169 }
kono
parents: 67
diff changeset
1170
kono
parents: 67
diff changeset
1171 /* Finalize the coverage data. Generates the array of pointers to
kono
parents: 67
diff changeset
1172 function objects from CTOR. Generate the gcov_info initializer. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173
111
kono
parents: 67
diff changeset
1174 static void
kono
parents: 67
diff changeset
1175 coverage_obj_finish (vec<constructor_elt, va_gc> *ctor)
kono
parents: 67
diff changeset
1176 {
kono
parents: 67
diff changeset
1177 unsigned n_functions = vec_safe_length (ctor);
kono
parents: 67
diff changeset
1178 tree fn_info_ary_type = build_array_type
kono
parents: 67
diff changeset
1179 (build_qualified_type (gcov_fn_info_ptr_type, TYPE_QUAL_CONST),
kono
parents: 67
diff changeset
1180 build_index_type (size_int (n_functions - 1)));
kono
parents: 67
diff changeset
1181 tree fn_info_ary = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL_TREE,
kono
parents: 67
diff changeset
1182 fn_info_ary_type);
kono
parents: 67
diff changeset
1183 char name_buf[32];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184
111
kono
parents: 67
diff changeset
1185 TREE_STATIC (fn_info_ary) = 1;
kono
parents: 67
diff changeset
1186 ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 1);
kono
parents: 67
diff changeset
1187 DECL_NAME (fn_info_ary) = get_identifier (name_buf);
kono
parents: 67
diff changeset
1188 DECL_INITIAL (fn_info_ary) = build_constructor (fn_info_ary_type, ctor);
kono
parents: 67
diff changeset
1189 varpool_node::finalize_decl (fn_info_ary);
kono
parents: 67
diff changeset
1190
kono
parents: 67
diff changeset
1191 DECL_INITIAL (gcov_info_var)
kono
parents: 67
diff changeset
1192 = build_info (TREE_TYPE (gcov_info_var), fn_info_ary);
kono
parents: 67
diff changeset
1193 varpool_node::finalize_decl (gcov_info_var);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194 }
111
kono
parents: 67
diff changeset
1195
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 /* Perform file-level initialization. Read in data file, generate name
111
kono
parents: 67
diff changeset
1197 of notes file. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1199 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1200 coverage_init (const char *filename)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1201 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202 int len = strlen (filename);
111
kono
parents: 67
diff changeset
1203 int prefix_len = 0;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1204
111
kono
parents: 67
diff changeset
1205 /* Since coverage_init is invoked very early, before the pass
kono
parents: 67
diff changeset
1206 manager, we need to set up the dumping explicitly. This is
kono
parents: 67
diff changeset
1207 similar to the handling in finish_optimization_passes. */
kono
parents: 67
diff changeset
1208 int profile_pass_num =
kono
parents: 67
diff changeset
1209 g->get_passes ()->get_pass_profile ()->static_pass_number;
kono
parents: 67
diff changeset
1210 g->get_dumps ()->dump_start (profile_pass_num, NULL);
kono
parents: 67
diff changeset
1211
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1212 if (!IS_ABSOLUTE_PATH (filename))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1213 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1214 /* When a profile_data_prefix is provided, then mangle full path
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1215 of filename in order to prevent file path clashing. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1216 if (profile_data_prefix)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1217 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1218 #if HAVE_DOS_BASED_FILE_SYSTEM
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1219 const char *separator = "\\";
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1220 #else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1221 const char *separator = "/";
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1222 #endif
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1223 filename = concat (getpwd (), separator, filename, NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1224 filename = mangle_path (filename);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1225 len = strlen (filename);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1226 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1227 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1228 profile_data_prefix = getpwd ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1229 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1230
111
kono
parents: 67
diff changeset
1231 if (profile_data_prefix)
kono
parents: 67
diff changeset
1232 prefix_len = strlen (profile_data_prefix);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1233
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1234 /* Name of da file. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1235 da_file_name = XNEWVEC (char, len + strlen (GCOV_DATA_SUFFIX)
111
kono
parents: 67
diff changeset
1236 + prefix_len + 2);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1237
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238 if (profile_data_prefix)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1239 {
111
kono
parents: 67
diff changeset
1240 memcpy (da_file_name, profile_data_prefix, prefix_len);
kono
parents: 67
diff changeset
1241 da_file_name[prefix_len++] = '/';
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1242 }
111
kono
parents: 67
diff changeset
1243 memcpy (da_file_name + prefix_len, filename, len);
kono
parents: 67
diff changeset
1244 strcpy (da_file_name + prefix_len + len, GCOV_DATA_SUFFIX);
kono
parents: 67
diff changeset
1245
kono
parents: 67
diff changeset
1246 bbg_file_stamp = local_tick;
kono
parents: 67
diff changeset
1247
kono
parents: 67
diff changeset
1248 if (flag_auto_profile)
kono
parents: 67
diff changeset
1249 read_autofdo_file ();
kono
parents: 67
diff changeset
1250 else if (flag_branch_probabilities)
kono
parents: 67
diff changeset
1251 read_counts_file ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1252
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1253 /* Name of bbg file. */
111
kono
parents: 67
diff changeset
1254 if (flag_test_coverage && !flag_compare_debug)
kono
parents: 67
diff changeset
1255 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1256 if (profile_note_location)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1257 bbg_file_name = xstrdup (profile_note_location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1258 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1259 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1260 bbg_file_name = XNEWVEC (char, len + strlen (GCOV_NOTE_SUFFIX) + 1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1261 memcpy (bbg_file_name, filename, len);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1262 strcpy (bbg_file_name + len, GCOV_NOTE_SUFFIX);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1263 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264
111
kono
parents: 67
diff changeset
1265 if (!gcov_open (bbg_file_name, -1))
kono
parents: 67
diff changeset
1266 {
kono
parents: 67
diff changeset
1267 error ("cannot open %s", bbg_file_name);
kono
parents: 67
diff changeset
1268 bbg_file_name = NULL;
kono
parents: 67
diff changeset
1269 }
kono
parents: 67
diff changeset
1270 else
kono
parents: 67
diff changeset
1271 {
kono
parents: 67
diff changeset
1272 gcov_write_unsigned (GCOV_NOTE_MAGIC);
kono
parents: 67
diff changeset
1273 gcov_write_unsigned (GCOV_VERSION);
kono
parents: 67
diff changeset
1274 gcov_write_unsigned (bbg_file_stamp);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1275 gcov_write_string (getpwd ());
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1276
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1277 /* Do not support has_unexecuted_blocks for Ada. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1278 gcov_write_unsigned (strcmp (lang_hooks.name, "GNU Ada") != 0);
111
kono
parents: 67
diff changeset
1279 }
kono
parents: 67
diff changeset
1280 }
kono
parents: 67
diff changeset
1281
kono
parents: 67
diff changeset
1282 g->get_dumps ()->dump_finish (profile_pass_num);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284
111
kono
parents: 67
diff changeset
1285 /* Performs file-level cleanup. Close notes file, generate coverage
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 variables and constructor. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289 coverage_finish (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290 {
111
kono
parents: 67
diff changeset
1291 if (bbg_file_name && gcov_close ())
kono
parents: 67
diff changeset
1292 unlink (bbg_file_name);
kono
parents: 67
diff changeset
1293
kono
parents: 67
diff changeset
1294 if (!flag_branch_probabilities && flag_test_coverage
kono
parents: 67
diff changeset
1295 && (!local_tick || local_tick == (unsigned)-1))
kono
parents: 67
diff changeset
1296 /* Only remove the da file, if we're emitting coverage code and
kono
parents: 67
diff changeset
1297 cannot uniquely stamp it. If we can stamp it, libgcov will DTRT. */
kono
parents: 67
diff changeset
1298 unlink (da_file_name);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1299
111
kono
parents: 67
diff changeset
1300 if (coverage_obj_init ())
kono
parents: 67
diff changeset
1301 {
kono
parents: 67
diff changeset
1302 vec<constructor_elt, va_gc> *fn_ctor = NULL;
kono
parents: 67
diff changeset
1303 struct coverage_data *fn;
kono
parents: 67
diff changeset
1304
kono
parents: 67
diff changeset
1305 for (fn = functions_head; fn; fn = fn->next)
kono
parents: 67
diff changeset
1306 fn_ctor = coverage_obj_fn (fn_ctor, fn->fn_decl, fn);
kono
parents: 67
diff changeset
1307 coverage_obj_finish (fn_ctor);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1308 }
111
kono
parents: 67
diff changeset
1309
kono
parents: 67
diff changeset
1310 XDELETEVEC (da_file_name);
kono
parents: 67
diff changeset
1311 da_file_name = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1312 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1313
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314 #include "gt-coverage.h"