annotate gcc/coverage.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Read and write coverage files, and associated functionality.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 1990-2018 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 "params.h"
kono
parents: 67
diff changeset
51 #include "auto-profile.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
52 #include "profile.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 #include "gcov-io.c"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
111
kono
parents: 67
diff changeset
56 struct GTY((chain_next ("%h.next"))) coverage_data
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 {
111
kono
parents: 67
diff changeset
58 struct coverage_data *next; /* next function */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 unsigned ident; /* function ident */
111
kono
parents: 67
diff changeset
60 unsigned lineno_checksum; /* function lineno checksum */
kono
parents: 67
diff changeset
61 unsigned cfg_checksum; /* function cfg checksum */
kono
parents: 67
diff changeset
62 tree fn_decl; /* the function decl */
kono
parents: 67
diff changeset
63 tree ctr_vars[GCOV_COUNTERS]; /* counter variables. */
0
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 /* Counts information for a function. */
111
kono
parents: 67
diff changeset
67 struct counts_entry : pointer_hash <counts_entry>
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 /* We hash by */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 unsigned ident;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 unsigned ctr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 /* Store */
111
kono
parents: 67
diff changeset
74 unsigned lineno_checksum;
kono
parents: 67
diff changeset
75 unsigned cfg_checksum;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 gcov_type *counts;
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);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 }
111
kono
parents: 67
diff changeset
264 else if (entry->lineno_checksum != lineno_checksum
kono
parents: 67
diff changeset
265 || entry->cfg_checksum != cfg_checksum)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 {
111
kono
parents: 67
diff changeset
267 error ("Profile data for function %u is corrupted", fn_ident);
kono
parents: 67
diff changeset
268 error ("checksum is (%x,%x) instead of (%x,%x)",
kono
parents: 67
diff changeset
269 entry->lineno_checksum, entry->cfg_checksum,
kono
parents: 67
diff changeset
270 lineno_checksum, cfg_checksum);
kono
parents: 67
diff changeset
271 delete counts_hash;
kono
parents: 67
diff changeset
272 counts_hash = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 for (ix = 0; ix != n_counts; ix++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 entry->counts[ix] += gcov_read_counter ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 gcov_sync (offset, length);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 if ((is_error = gcov_is_error ()))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 {
111
kono
parents: 67
diff changeset
281 error (is_error < 0
kono
parents: 67
diff changeset
282 ? G_("%qs has overflowed")
kono
parents: 67
diff changeset
283 : G_("%qs is corrupted"),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 da_file_name);
111
kono
parents: 67
diff changeset
285 delete counts_hash;
kono
parents: 67
diff changeset
286 counts_hash = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 }
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 gcov_close ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 }
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 /* Returns the counters for a particular tag. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 gcov_type *
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
297 get_coverage_counts (unsigned counter, unsigned cfg_checksum,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
298 unsigned lineno_checksum)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 {
111
kono
parents: 67
diff changeset
300 counts_entry *entry, elt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 /* No hash table, no counts. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 if (!counts_hash)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 static int warned = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
307 if (!warned++)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
308 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
309 warning (OPT_Wmissing_profile,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
310 "%qs profile count data file not found",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
311 da_file_name);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
312 if (dump_enabled_p ())
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
313 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
314 dump_user_location_t loc
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
315 = dump_user_location_t::from_location_t (input_location);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
316 dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
317 "file %s not found, %s\n", da_file_name,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
318 (flag_guess_branch_prob
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
319 ? "execution counts estimated"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
320 : "execution counts assumed to be zero"));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
321 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
322 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 }
111
kono
parents: 67
diff changeset
325 if (PARAM_VALUE (PARAM_PROFILE_FUNC_INTERNAL_ID))
kono
parents: 67
diff changeset
326 elt.ident = current_function_funcdef_no + 1;
kono
parents: 67
diff changeset
327 else
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 {
111
kono
parents: 67
diff changeset
329 gcc_assert (coverage_node_map_initialized_p ());
kono
parents: 67
diff changeset
330 elt.ident = cgraph_node::get (cfun->decl)->profile_id;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 }
111
kono
parents: 67
diff changeset
332 elt.ctr = counter;
kono
parents: 67
diff changeset
333 entry = counts_hash->find (&elt);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
334 if (!entry)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
335 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
336 if (counter == GCOV_COUNTER_ARCS)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
337 warning_at (DECL_SOURCE_LOCATION (current_function_decl),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
338 OPT_Wmissing_profile,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
339 "profile for function %qD not found in profile data",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
340 current_function_decl);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
341 /* The function was not emitted, or is weak and not chosen in the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
342 final executable. Silently fail, because there's nothing we
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
343 can do about it. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
344 return NULL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
345 }
111
kono
parents: 67
diff changeset
346
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
347 if (entry->cfg_checksum != cfg_checksum)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 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
350 bool warning_printed = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351
111
kono
parents: 67
diff changeset
352 warning_printed =
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
353 warning_at (DECL_SOURCE_LOCATION (current_function_decl),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
354 OPT_Wcoverage_mismatch,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
355 "the control flow of function %qD does not match "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
356 "its profile data (counter %qs)", current_function_decl,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
357 ctr_names[counter]);
111
kono
parents: 67
diff changeset
358 if (warning_printed && dump_enabled_p ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
360 dump_user_location_t loc
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
361 = dump_user_location_t::from_location_t (input_location);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
362 dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc,
111
kono
parents: 67
diff changeset
363 "use -Wno-error=coverage-mismatch to tolerate "
kono
parents: 67
diff changeset
364 "the mismatch but performance may drop if the "
kono
parents: 67
diff changeset
365 "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
366
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
367 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
368 && !warned++)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
369 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
370 dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc,
111
kono
parents: 67
diff changeset
371 "coverage mismatch ignored\n");
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
372 dump_printf (MSG_MISSED_OPTIMIZATION,
111
kono
parents: 67
diff changeset
373 flag_guess_branch_prob
kono
parents: 67
diff changeset
374 ? G_("execution counts estimated\n")
kono
parents: 67
diff changeset
375 : 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
376 if (!flag_guess_branch_prob)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
377 dump_printf (MSG_MISSED_OPTIMIZATION,
111
kono
parents: 67
diff changeset
378 "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
379 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 }
111
kono
parents: 67
diff changeset
384 else if (entry->lineno_checksum != lineno_checksum)
kono
parents: 67
diff changeset
385 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
386 warning_at (DECL_SOURCE_LOCATION (current_function_decl),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
387 OPT_Wcoverage_mismatch,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
388 "source locations for function %qD have changed,"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
389 " the profile data may be out of date",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
390 current_function_decl);
111
kono
parents: 67
diff changeset
391 }
0
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 entry->counts;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 /* Allocate NUM counters of type COUNTER. Returns nonzero if the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 allocation succeeded. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 coverage_counter_alloc (unsigned counter, unsigned num)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 if (no_coverage)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 if (!num)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407
111
kono
parents: 67
diff changeset
408 if (!fn_v_ctrs[counter])
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 {
111
kono
parents: 67
diff changeset
410 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
411
111
kono
parents: 67
diff changeset
412 fn_v_ctrs[counter]
kono
parents: 67
diff changeset
413 = build_var (current_function_decl, array_type, counter);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 }
111
kono
parents: 67
diff changeset
415
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 fn_b_ctrs[counter] = fn_n_ctrs[counter];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 fn_n_ctrs[counter] += num;
111
kono
parents: 67
diff changeset
418
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 fn_ctr_mask |= 1 << counter;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 /* Generate a tree to access COUNTER NO. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 tree_coverage_counter_ref (unsigned counter, unsigned no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 tree gcov_type_node = get_gcov_type ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 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
431
111
kono
parents: 67
diff changeset
432 no += fn_b_ctrs[counter];
kono
parents: 67
diff changeset
433
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 /* "no" here is an array index, scaled to bytes later. */
111
kono
parents: 67
diff changeset
435 return build4 (ARRAY_REF, gcov_type_node, fn_v_ctrs[counter],
kono
parents: 67
diff changeset
436 build_int_cst (integer_type_node, no), NULL, NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 }
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 /* Generate a tree to access the address of COUNTER NO. */
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 tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 tree_coverage_counter_addr (unsigned counter, unsigned no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 tree gcov_type_node = get_gcov_type ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 gcc_assert (no < fn_n_ctrs[counter] - fn_b_ctrs[counter]);
111
kono
parents: 67
diff changeset
447 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
448
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 /* "no" here is an array index, scaled to bytes later. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 return build_fold_addr_expr (build4 (ARRAY_REF, gcov_type_node,
111
kono
parents: 67
diff changeset
451 fn_v_ctrs[counter],
kono
parents: 67
diff changeset
452 build_int_cst (integer_type_node, no),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 NULL, NULL));
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
111
kono
parents: 67
diff changeset
456
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 /* Generate a checksum for a string. CHKSUM is the current
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 checksum. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 static unsigned
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 coverage_checksum_string (unsigned chksum, const char *string)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 int i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 char *dup = 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 /* Look for everything that looks if it were produced by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 get_file_function_name and zero out the second part
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 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
469 as the checksums are used only for sanity checking. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 for (i = 0; string[i]; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 int offset = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 if (!strncmp (string + i, "_GLOBAL__N_", 11))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 offset = 11;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 if (!strncmp (string + i, "_GLOBAL__", 9))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 offset = 9;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 /* C++ namespaces do have scheme:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 _GLOBAL__N_<filename>_<wrongmagicnumber>_<magicnumber>functionname
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 since filename might contain extra underscores there seems
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 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
482 for magicnumber. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 if (offset)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 for (i = i + offset; string[i]; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 if (string[i]=='_')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 int y;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 for (y = 1; y < 9; y++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 if (!(string[i + y] >= '0' && string[i + y] <= '9')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 && !(string[i + y] >= 'A' && string[i + y] <= 'F'))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 if (y != 9 || string[i + 9] != '_')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 for (y = 10; y < 18; y++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 if (!(string[i + y] >= '0' && string[i + y] <= '9')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 && !(string[i + y] >= 'A' && string[i + y] <= 'F'))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 if (y != 18)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 if (!dup)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 string = dup = xstrdup (string);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 for (y = 10; y < 18; y++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 dup[i + y] = '0';
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 chksum = crc32_string (chksum, string);
111
kono
parents: 67
diff changeset
512 free (dup);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 return chksum;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 /* Compute checksum for the current function. We generate a CRC32. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518
111
kono
parents: 67
diff changeset
519 unsigned
kono
parents: 67
diff changeset
520 coverage_compute_lineno_checksum (void)
0
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 expanded_location xloc
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 unsigned chksum = xloc.line;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525
111
kono
parents: 67
diff changeset
526 if (xloc.file)
kono
parents: 67
diff changeset
527 chksum = coverage_checksum_string (chksum, xloc.file);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 chksum = coverage_checksum_string
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 (chksum, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 return chksum;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 }
111
kono
parents: 67
diff changeset
533
kono
parents: 67
diff changeset
534 /* Compute profile ID. This is better to be unique in whole program. */
kono
parents: 67
diff changeset
535
kono
parents: 67
diff changeset
536 unsigned
kono
parents: 67
diff changeset
537 coverage_compute_profile_id (struct cgraph_node *n)
kono
parents: 67
diff changeset
538 {
kono
parents: 67
diff changeset
539 unsigned chksum;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540
111
kono
parents: 67
diff changeset
541 /* Externally visible symbols have unique name. */
kono
parents: 67
diff changeset
542 if (TREE_PUBLIC (n->decl) || DECL_EXTERNAL (n->decl) || n->unique_name)
kono
parents: 67
diff changeset
543 {
kono
parents: 67
diff changeset
544 chksum = coverage_checksum_string
kono
parents: 67
diff changeset
545 (0, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (n->decl)));
kono
parents: 67
diff changeset
546 }
kono
parents: 67
diff changeset
547 else
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 expanded_location xloc
111
kono
parents: 67
diff changeset
550 = expand_location (DECL_SOURCE_LOCATION (n->decl));
kono
parents: 67
diff changeset
551 bool use_name_only = (PARAM_VALUE (PARAM_PROFILE_FUNC_INTERNAL_ID) == 0);
kono
parents: 67
diff changeset
552
kono
parents: 67
diff changeset
553 chksum = (use_name_only ? 0 : xloc.line);
kono
parents: 67
diff changeset
554 if (xloc.file)
kono
parents: 67
diff changeset
555 chksum = coverage_checksum_string (chksum, xloc.file);
kono
parents: 67
diff changeset
556 chksum = coverage_checksum_string
kono
parents: 67
diff changeset
557 (chksum, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (n->decl)));
kono
parents: 67
diff changeset
558 if (!use_name_only && first_global_object_name)
kono
parents: 67
diff changeset
559 chksum = coverage_checksum_string
kono
parents: 67
diff changeset
560 (chksum, first_global_object_name);
kono
parents: 67
diff changeset
561 chksum = coverage_checksum_string
kono
parents: 67
diff changeset
562 (chksum, aux_base_name);
kono
parents: 67
diff changeset
563 }
kono
parents: 67
diff changeset
564
kono
parents: 67
diff changeset
565 /* Non-negative integers are hopefully small enough to fit in all targets.
kono
parents: 67
diff changeset
566 Gcov file formats wants non-zero function IDs. */
kono
parents: 67
diff changeset
567 chksum = chksum & 0x7fffffff;
kono
parents: 67
diff changeset
568 return chksum + (!chksum);
kono
parents: 67
diff changeset
569 }
kono
parents: 67
diff changeset
570
kono
parents: 67
diff changeset
571 /* Compute cfg checksum for the function FN given as argument.
kono
parents: 67
diff changeset
572 The checksum is calculated carefully so that
kono
parents: 67
diff changeset
573 source code changes that doesn't affect the control flow graph
kono
parents: 67
diff changeset
574 won't change the checksum.
kono
parents: 67
diff changeset
575 This is to make the profile data useable across source code change.
kono
parents: 67
diff changeset
576 The downside of this is that the compiler may use potentially
kono
parents: 67
diff changeset
577 wrong profile data - that the source code change has non-trivial impact
kono
parents: 67
diff changeset
578 on the validity of profile data (e.g. the reversed condition)
kono
parents: 67
diff changeset
579 but the compiler won't detect the change and use the wrong profile data. */
kono
parents: 67
diff changeset
580
kono
parents: 67
diff changeset
581 unsigned
kono
parents: 67
diff changeset
582 coverage_compute_cfg_checksum (struct function *fn)
kono
parents: 67
diff changeset
583 {
kono
parents: 67
diff changeset
584 basic_block bb;
kono
parents: 67
diff changeset
585 unsigned chksum = n_basic_blocks_for_fn (fn);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586
111
kono
parents: 67
diff changeset
587 FOR_EACH_BB_FN (bb, fn)
kono
parents: 67
diff changeset
588 {
kono
parents: 67
diff changeset
589 edge e;
kono
parents: 67
diff changeset
590 edge_iterator ei;
kono
parents: 67
diff changeset
591 chksum = crc32_byte (chksum, bb->index);
kono
parents: 67
diff changeset
592 FOR_EACH_EDGE (e, ei, bb->succs)
kono
parents: 67
diff changeset
593 {
kono
parents: 67
diff changeset
594 chksum = crc32_byte (chksum, e->dest->index);
kono
parents: 67
diff changeset
595 }
kono
parents: 67
diff changeset
596 }
kono
parents: 67
diff changeset
597
kono
parents: 67
diff changeset
598 return chksum;
kono
parents: 67
diff changeset
599 }
kono
parents: 67
diff changeset
600
kono
parents: 67
diff changeset
601 /* Begin output to the notes file for the current function.
kono
parents: 67
diff changeset
602 Writes the function header. Returns nonzero if data should be output. */
kono
parents: 67
diff changeset
603
kono
parents: 67
diff changeset
604 int
kono
parents: 67
diff changeset
605 coverage_begin_function (unsigned lineno_checksum, unsigned cfg_checksum)
kono
parents: 67
diff changeset
606 {
kono
parents: 67
diff changeset
607 expanded_location xloc;
kono
parents: 67
diff changeset
608 unsigned long offset;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609
111
kono
parents: 67
diff changeset
610 /* We don't need to output .gcno file unless we're under -ftest-coverage
kono
parents: 67
diff changeset
611 (e.g. -fprofile-arcs/generate/use don't need .gcno to work). */
kono
parents: 67
diff changeset
612 if (no_coverage || !bbg_file_name)
kono
parents: 67
diff changeset
613 return 0;
kono
parents: 67
diff changeset
614
kono
parents: 67
diff changeset
615 xloc = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616
111
kono
parents: 67
diff changeset
617 /* Announce function */
kono
parents: 67
diff changeset
618 offset = gcov_write_tag (GCOV_TAG_FUNCTION);
kono
parents: 67
diff changeset
619 if (PARAM_VALUE (PARAM_PROFILE_FUNC_INTERNAL_ID))
kono
parents: 67
diff changeset
620 gcov_write_unsigned (current_function_funcdef_no + 1);
kono
parents: 67
diff changeset
621 else
kono
parents: 67
diff changeset
622 {
kono
parents: 67
diff changeset
623 gcc_assert (coverage_node_map_initialized_p ());
kono
parents: 67
diff changeset
624 gcov_write_unsigned (
kono
parents: 67
diff changeset
625 cgraph_node::get (current_function_decl)->profile_id);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 }
111
kono
parents: 67
diff changeset
627
kono
parents: 67
diff changeset
628 gcov_write_unsigned (lineno_checksum);
kono
parents: 67
diff changeset
629 gcov_write_unsigned (cfg_checksum);
kono
parents: 67
diff changeset
630 gcov_write_string (IDENTIFIER_POINTER
kono
parents: 67
diff changeset
631 (DECL_ASSEMBLER_NAME (current_function_decl)));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
632 gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
633 && !DECL_FUNCTION_VERSIONED (current_function_decl)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
634 && !DECL_LAMBDA_FUNCTION (current_function_decl));
111
kono
parents: 67
diff changeset
635 gcov_write_filename (xloc.file);
kono
parents: 67
diff changeset
636 gcov_write_unsigned (xloc.line);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
637 gcov_write_unsigned (xloc.column);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
638
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
639 expanded_location endloc = expand_location (cfun->function_end_locus);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
640
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
641 /* Function can start in a single file and end in another one. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
642 gcov_write_unsigned (endloc.file == xloc.file ? endloc.line : xloc.line);
111
kono
parents: 67
diff changeset
643 gcov_write_length (offset);
kono
parents: 67
diff changeset
644
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 return !gcov_is_error ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 /* Finish coverage data for the current function. Verify no output
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 error has occurred. Save function coverage counts. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 void
111
kono
parents: 67
diff changeset
652 coverage_end_function (unsigned lineno_checksum, unsigned cfg_checksum)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 unsigned i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655
111
kono
parents: 67
diff changeset
656 if (bbg_file_name && gcov_is_error ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 warning (0, "error writing %qs", bbg_file_name);
111
kono
parents: 67
diff changeset
659 unlink (bbg_file_name);
kono
parents: 67
diff changeset
660 bbg_file_name = NULL;
0
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 if (fn_ctr_mask)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 {
111
kono
parents: 67
diff changeset
665 struct coverage_data *item = 0;
kono
parents: 67
diff changeset
666
kono
parents: 67
diff changeset
667 item = ggc_alloc<coverage_data> ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668
111
kono
parents: 67
diff changeset
669 if (PARAM_VALUE (PARAM_PROFILE_FUNC_INTERNAL_ID))
kono
parents: 67
diff changeset
670 item->ident = current_function_funcdef_no + 1;
kono
parents: 67
diff changeset
671 else
kono
parents: 67
diff changeset
672 {
kono
parents: 67
diff changeset
673 gcc_assert (coverage_node_map_initialized_p ());
kono
parents: 67
diff changeset
674 item->ident = cgraph_node::get (cfun->decl)->profile_id;
kono
parents: 67
diff changeset
675 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676
111
kono
parents: 67
diff changeset
677 item->lineno_checksum = lineno_checksum;
kono
parents: 67
diff changeset
678 item->cfg_checksum = cfg_checksum;
kono
parents: 67
diff changeset
679
kono
parents: 67
diff changeset
680 item->fn_decl = current_function_decl;
kono
parents: 67
diff changeset
681 item->next = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 *functions_tail = item;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 functions_tail = &item->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 for (i = 0; i != GCOV_COUNTERS; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 {
111
kono
parents: 67
diff changeset
687 tree var = fn_v_ctrs[i];
kono
parents: 67
diff changeset
688
kono
parents: 67
diff changeset
689 if (item)
kono
parents: 67
diff changeset
690 item->ctr_vars[i] = var;
kono
parents: 67
diff changeset
691 if (var)
kono
parents: 67
diff changeset
692 {
kono
parents: 67
diff changeset
693 tree array_type = build_index_type (size_int (fn_n_ctrs[i] - 1));
kono
parents: 67
diff changeset
694 array_type = build_array_type (get_gcov_type (), array_type);
kono
parents: 67
diff changeset
695 TREE_TYPE (var) = array_type;
kono
parents: 67
diff changeset
696 DECL_SIZE (var) = TYPE_SIZE (array_type);
kono
parents: 67
diff changeset
697 DECL_SIZE_UNIT (var) = TYPE_SIZE_UNIT (array_type);
kono
parents: 67
diff changeset
698 varpool_node::finalize_decl (var);
kono
parents: 67
diff changeset
699 }
kono
parents: 67
diff changeset
700
kono
parents: 67
diff changeset
701 fn_b_ctrs[i] = fn_n_ctrs[i] = 0;
kono
parents: 67
diff changeset
702 fn_v_ctrs[i] = NULL_TREE;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 prg_ctr_mask |= fn_ctr_mask;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 fn_ctr_mask = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 }
111
kono
parents: 67
diff changeset
707 }
kono
parents: 67
diff changeset
708
kono
parents: 67
diff changeset
709 /* Remove coverage file if opened. */
kono
parents: 67
diff changeset
710
kono
parents: 67
diff changeset
711 void
kono
parents: 67
diff changeset
712 coverage_remove_note_file (void)
kono
parents: 67
diff changeset
713 {
kono
parents: 67
diff changeset
714 if (bbg_file_name)
kono
parents: 67
diff changeset
715 {
kono
parents: 67
diff changeset
716 gcov_close ();
kono
parents: 67
diff changeset
717 unlink (bbg_file_name);
kono
parents: 67
diff changeset
718 }
kono
parents: 67
diff changeset
719 }
kono
parents: 67
diff changeset
720
kono
parents: 67
diff changeset
721 /* Build a coverage variable of TYPE for function FN_DECL. If COUNTER
kono
parents: 67
diff changeset
722 >= 0 it is a counter array, otherwise it is the function structure. */
kono
parents: 67
diff changeset
723
kono
parents: 67
diff changeset
724 static tree
kono
parents: 67
diff changeset
725 build_var (tree fn_decl, tree type, int counter)
kono
parents: 67
diff changeset
726 {
kono
parents: 67
diff changeset
727 tree var = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL_TREE, type);
kono
parents: 67
diff changeset
728 const char *fn_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn_decl));
kono
parents: 67
diff changeset
729 char *buf;
kono
parents: 67
diff changeset
730 size_t fn_name_len, len;
kono
parents: 67
diff changeset
731
kono
parents: 67
diff changeset
732 fn_name = targetm.strip_name_encoding (fn_name);
kono
parents: 67
diff changeset
733 fn_name_len = strlen (fn_name);
kono
parents: 67
diff changeset
734 buf = XALLOCAVEC (char, fn_name_len + 8 + sizeof (int) * 3);
kono
parents: 67
diff changeset
735
kono
parents: 67
diff changeset
736 if (counter < 0)
kono
parents: 67
diff changeset
737 strcpy (buf, "__gcov__");
kono
parents: 67
diff changeset
738 else
kono
parents: 67
diff changeset
739 sprintf (buf, "__gcov%u_", counter);
kono
parents: 67
diff changeset
740 len = strlen (buf);
kono
parents: 67
diff changeset
741 buf[len - 1] = symbol_table::symbol_suffix_separator ();
kono
parents: 67
diff changeset
742 memcpy (buf + len, fn_name, fn_name_len + 1);
kono
parents: 67
diff changeset
743 DECL_NAME (var) = get_identifier (buf);
kono
parents: 67
diff changeset
744 TREE_STATIC (var) = 1;
kono
parents: 67
diff changeset
745 TREE_ADDRESSABLE (var) = 1;
kono
parents: 67
diff changeset
746 DECL_NONALIASED (var) = 1;
kono
parents: 67
diff changeset
747 SET_DECL_ALIGN (var, TYPE_ALIGN (type));
kono
parents: 67
diff changeset
748
kono
parents: 67
diff changeset
749 return var;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 /* Creates the gcov_fn_info RECORD_TYPE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753
111
kono
parents: 67
diff changeset
754 static void
kono
parents: 67
diff changeset
755 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
756 {
111
kono
parents: 67
diff changeset
757 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
758 tree field, fields;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 tree array_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760
111
kono
parents: 67
diff changeset
761 gcc_assert (counters);
kono
parents: 67
diff changeset
762
kono
parents: 67
diff changeset
763 /* ctr_info::num */
kono
parents: 67
diff changeset
764 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
765 get_gcov_unsigned_t ());
kono
parents: 67
diff changeset
766 fields = field;
kono
parents: 67
diff changeset
767
kono
parents: 67
diff changeset
768 /* ctr_info::values */
kono
parents: 67
diff changeset
769 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
770 build_pointer_type (get_gcov_type ()));
kono
parents: 67
diff changeset
771 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
772 fields = field;
kono
parents: 67
diff changeset
773
kono
parents: 67
diff changeset
774 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
775
111
kono
parents: 67
diff changeset
776 /* key */
kono
parents: 67
diff changeset
777 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
778 build_pointer_type (build_qualified_type
kono
parents: 67
diff changeset
779 (gcov_info_type, TYPE_QUAL_CONST)));
kono
parents: 67
diff changeset
780 fields = field;
kono
parents: 67
diff changeset
781
kono
parents: 67
diff changeset
782 /* ident */
kono
parents: 67
diff changeset
783 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
784 get_gcov_unsigned_t ());
kono
parents: 67
diff changeset
785 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
786 fields = field;
kono
parents: 67
diff changeset
787
kono
parents: 67
diff changeset
788 /* lineno_checksum */
kono
parents: 67
diff changeset
789 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
790 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
791 DECL_CHAIN (field) = fields;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 fields = field;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793
111
kono
parents: 67
diff changeset
794 /* cfg checksum */
kono
parents: 67
diff changeset
795 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
796 get_gcov_unsigned_t ());
kono
parents: 67
diff changeset
797 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
798 fields = field;
kono
parents: 67
diff changeset
799
kono
parents: 67
diff changeset
800 array_type = build_index_type (size_int (counters - 1));
kono
parents: 67
diff changeset
801 array_type = build_array_type (ctr_info, array_type);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803 /* counters */
111
kono
parents: 67
diff changeset
804 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
805 DECL_CHAIN (field) = fields;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 fields = field;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 finish_builtin_struct (type, "__gcov_fn_info", fields, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810
111
kono
parents: 67
diff changeset
811 /* Returns a CONSTRUCTOR for a gcov_fn_info. DATA is
kono
parents: 67
diff changeset
812 the coverage data for the function and TYPE is the gcov_fn_info
kono
parents: 67
diff changeset
813 RECORD_TYPE. KEY is the object file key. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 static tree
111
kono
parents: 67
diff changeset
816 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
817 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 tree fields = TYPE_FIELDS (type);
111
kono
parents: 67
diff changeset
819 tree ctr_type;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 unsigned ix;
111
kono
parents: 67
diff changeset
821 vec<constructor_elt, va_gc> *v1 = NULL;
kono
parents: 67
diff changeset
822 vec<constructor_elt, va_gc> *v2 = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823
111
kono
parents: 67
diff changeset
824 /* key */
kono
parents: 67
diff changeset
825 CONSTRUCTOR_APPEND_ELT (v1, fields,
kono
parents: 67
diff changeset
826 build1 (ADDR_EXPR, TREE_TYPE (fields), key));
kono
parents: 67
diff changeset
827 fields = DECL_CHAIN (fields);
kono
parents: 67
diff changeset
828
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829 /* 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
830 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
831 build_int_cstu (get_gcov_unsigned_t (),
111
kono
parents: 67
diff changeset
832 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
833 fields = DECL_CHAIN (fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
834
111
kono
parents: 67
diff changeset
835 /* 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
836 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
837 build_int_cstu (get_gcov_unsigned_t (),
111
kono
parents: 67
diff changeset
838 data->lineno_checksum));
kono
parents: 67
diff changeset
839 fields = DECL_CHAIN (fields);
kono
parents: 67
diff changeset
840
kono
parents: 67
diff changeset
841 /* cfg_checksum */
kono
parents: 67
diff changeset
842 CONSTRUCTOR_APPEND_ELT (v1, fields,
kono
parents: 67
diff changeset
843 build_int_cstu (get_gcov_unsigned_t (),
kono
parents: 67
diff changeset
844 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
845 fields = DECL_CHAIN (fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
846
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 /* counters */
111
kono
parents: 67
diff changeset
848 ctr_type = TREE_TYPE (TREE_TYPE (fields));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849 for (ix = 0; ix != GCOV_COUNTERS; ix++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850 if (prg_ctr_mask & (1 << ix))
111
kono
parents: 67
diff changeset
851 {
kono
parents: 67
diff changeset
852 vec<constructor_elt, va_gc> *ctr = NULL;
kono
parents: 67
diff changeset
853 tree var = data->ctr_vars[ix];
kono
parents: 67
diff changeset
854 unsigned count = 0;
kono
parents: 67
diff changeset
855
kono
parents: 67
diff changeset
856 if (var)
kono
parents: 67
diff changeset
857 count
kono
parents: 67
diff changeset
858 = tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (var))))
kono
parents: 67
diff changeset
859 + 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860
111
kono
parents: 67
diff changeset
861 CONSTRUCTOR_APPEND_ELT (ctr, TYPE_FIELDS (ctr_type),
kono
parents: 67
diff changeset
862 build_int_cstu (get_gcov_unsigned_t (),
kono
parents: 67
diff changeset
863 count));
kono
parents: 67
diff changeset
864
kono
parents: 67
diff changeset
865 if (var)
kono
parents: 67
diff changeset
866 CONSTRUCTOR_APPEND_ELT (ctr, DECL_CHAIN (TYPE_FIELDS (ctr_type)),
kono
parents: 67
diff changeset
867 build_fold_addr_expr (var));
kono
parents: 67
diff changeset
868
kono
parents: 67
diff changeset
869 CONSTRUCTOR_APPEND_ELT (v2, NULL, build_constructor (ctr_type, ctr));
kono
parents: 67
diff changeset
870 }
kono
parents: 67
diff changeset
871
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
872 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
873 build_constructor (TREE_TYPE (fields), v2));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
875 return build_constructor (type, v1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
876 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877
111
kono
parents: 67
diff changeset
878 /* Create gcov_info struct. TYPE is the incomplete RECORD_TYPE to be
kono
parents: 67
diff changeset
879 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
880
111
kono
parents: 67
diff changeset
881 static void
kono
parents: 67
diff changeset
882 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
883 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884 tree field, fields = NULL_TREE;
111
kono
parents: 67
diff changeset
885 tree merge_fn_type;
kono
parents: 67
diff changeset
886
kono
parents: 67
diff changeset
887 /* Version ident */
kono
parents: 67
diff changeset
888 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
889 get_gcov_unsigned_t ());
kono
parents: 67
diff changeset
890 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
891 fields = field;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892
111
kono
parents: 67
diff changeset
893 /* next pointer */
kono
parents: 67
diff changeset
894 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
895 build_pointer_type (build_qualified_type
kono
parents: 67
diff changeset
896 (type, TYPE_QUAL_CONST)));
kono
parents: 67
diff changeset
897 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
898 fields = field;
kono
parents: 67
diff changeset
899
kono
parents: 67
diff changeset
900 /* stamp */
kono
parents: 67
diff changeset
901 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
902 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
903 DECL_CHAIN (field) = fields;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 fields = field;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
905
111
kono
parents: 67
diff changeset
906 /* Filename */
kono
parents: 67
diff changeset
907 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
908 build_pointer_type (build_qualified_type
kono
parents: 67
diff changeset
909 (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
910 DECL_CHAIN (field) = fields;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 fields = field;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912
111
kono
parents: 67
diff changeset
913 /* merge fn array */
kono
parents: 67
diff changeset
914 merge_fn_type
kono
parents: 67
diff changeset
915 = build_function_type_list (void_type_node,
kono
parents: 67
diff changeset
916 build_pointer_type (get_gcov_type ()),
kono
parents: 67
diff changeset
917 get_gcov_unsigned_t (), NULL_TREE);
kono
parents: 67
diff changeset
918 merge_fn_type
kono
parents: 67
diff changeset
919 = build_array_type (build_pointer_type (merge_fn_type),
kono
parents: 67
diff changeset
920 build_index_type (size_int (GCOV_COUNTERS - 1)));
kono
parents: 67
diff changeset
921 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
922 merge_fn_type);
kono
parents: 67
diff changeset
923 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
924 fields = field;
kono
parents: 67
diff changeset
925
kono
parents: 67
diff changeset
926 /* n_functions */
kono
parents: 67
diff changeset
927 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
928 get_gcov_unsigned_t ());
kono
parents: 67
diff changeset
929 DECL_CHAIN (field) = fields;
kono
parents: 67
diff changeset
930 fields = field;
kono
parents: 67
diff changeset
931
kono
parents: 67
diff changeset
932 /* function_info pointer pointer */
kono
parents: 67
diff changeset
933 fn_info_ptr_type = build_pointer_type
kono
parents: 67
diff changeset
934 (build_qualified_type (fn_info_ptr_type, TYPE_QUAL_CONST));
kono
parents: 67
diff changeset
935 field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
kono
parents: 67
diff changeset
936 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
937 DECL_CHAIN (field) = fields;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 fields = field;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939
111
kono
parents: 67
diff changeset
940 finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
942
111
kono
parents: 67
diff changeset
943 /* Returns a CONSTRUCTOR for the gcov_info object. INFO_TYPE is the
kono
parents: 67
diff changeset
944 gcov_info structure type, FN_ARY is the array of pointers to
kono
parents: 67
diff changeset
945 function info objects. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
946
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
947 static tree
111
kono
parents: 67
diff changeset
948 build_info (tree info_type, tree fn_ary)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
949 {
111
kono
parents: 67
diff changeset
950 tree info_fields = TYPE_FIELDS (info_type);
kono
parents: 67
diff changeset
951 tree merge_fn_type, n_funcs;
kono
parents: 67
diff changeset
952 unsigned ix;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
953 tree filename_string;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 int da_file_name_len;
111
kono
parents: 67
diff changeset
955 vec<constructor_elt, va_gc> *v1 = NULL;
kono
parents: 67
diff changeset
956 vec<constructor_elt, va_gc> *v2 = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958 /* Version ident */
111
kono
parents: 67
diff changeset
959 CONSTRUCTOR_APPEND_ELT (v1, info_fields,
kono
parents: 67
diff changeset
960 build_int_cstu (TREE_TYPE (info_fields),
kono
parents: 67
diff changeset
961 GCOV_VERSION));
kono
parents: 67
diff changeset
962 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
963
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
964 /* next -- NULL */
111
kono
parents: 67
diff changeset
965 CONSTRUCTOR_APPEND_ELT (v1, info_fields, null_pointer_node);
kono
parents: 67
diff changeset
966 info_fields = DECL_CHAIN (info_fields);
kono
parents: 67
diff changeset
967
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
968 /* stamp */
111
kono
parents: 67
diff changeset
969 CONSTRUCTOR_APPEND_ELT (v1, info_fields,
kono
parents: 67
diff changeset
970 build_int_cstu (TREE_TYPE (info_fields),
kono
parents: 67
diff changeset
971 bbg_file_stamp));
kono
parents: 67
diff changeset
972 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
973
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 /* Filename */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
975 da_file_name_len = strlen (da_file_name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976 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
977 TREE_TYPE (filename_string) = build_array_type
111
kono
parents: 67
diff changeset
978 (char_type_node, build_index_type (size_int (da_file_name_len)));
kono
parents: 67
diff changeset
979 CONSTRUCTOR_APPEND_ELT (v1, info_fields,
kono
parents: 67
diff changeset
980 build1 (ADDR_EXPR, TREE_TYPE (info_fields),
kono
parents: 67
diff changeset
981 filename_string));
kono
parents: 67
diff changeset
982 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983
111
kono
parents: 67
diff changeset
984 /* merge fn array -- NULL slots indicate unmeasured counters */
kono
parents: 67
diff changeset
985 merge_fn_type = TREE_TYPE (TREE_TYPE (info_fields));
kono
parents: 67
diff changeset
986 for (ix = 0; ix != GCOV_COUNTERS; ix++)
kono
parents: 67
diff changeset
987 {
kono
parents: 67
diff changeset
988 tree ptr = null_pointer_node;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989
111
kono
parents: 67
diff changeset
990 if ((1u << ix) & prg_ctr_mask)
kono
parents: 67
diff changeset
991 {
kono
parents: 67
diff changeset
992 tree merge_fn = build_decl (BUILTINS_LOCATION,
kono
parents: 67
diff changeset
993 FUNCTION_DECL,
kono
parents: 67
diff changeset
994 get_identifier (ctr_merge_functions[ix]),
kono
parents: 67
diff changeset
995 TREE_TYPE (merge_fn_type));
kono
parents: 67
diff changeset
996 DECL_EXTERNAL (merge_fn) = 1;
kono
parents: 67
diff changeset
997 TREE_PUBLIC (merge_fn) = 1;
kono
parents: 67
diff changeset
998 DECL_ARTIFICIAL (merge_fn) = 1;
kono
parents: 67
diff changeset
999 TREE_NOTHROW (merge_fn) = 1;
kono
parents: 67
diff changeset
1000 /* Initialize assembler name so we can stream out. */
kono
parents: 67
diff changeset
1001 DECL_ASSEMBLER_NAME (merge_fn);
kono
parents: 67
diff changeset
1002 ptr = build1 (ADDR_EXPR, merge_fn_type, merge_fn);
kono
parents: 67
diff changeset
1003 }
kono
parents: 67
diff changeset
1004 CONSTRUCTOR_APPEND_ELT (v2, NULL, ptr);
kono
parents: 67
diff changeset
1005 }
kono
parents: 67
diff changeset
1006 CONSTRUCTOR_APPEND_ELT (v1, info_fields,
kono
parents: 67
diff changeset
1007 build_constructor (TREE_TYPE (info_fields), v2));
kono
parents: 67
diff changeset
1008 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1009
111
kono
parents: 67
diff changeset
1010 /* n_functions */
kono
parents: 67
diff changeset
1011 n_funcs = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (fn_ary)));
kono
parents: 67
diff changeset
1012 n_funcs = fold_build2 (PLUS_EXPR, TREE_TYPE (info_fields),
kono
parents: 67
diff changeset
1013 n_funcs, size_one_node);
kono
parents: 67
diff changeset
1014 CONSTRUCTOR_APPEND_ELT (v1, info_fields, n_funcs);
kono
parents: 67
diff changeset
1015 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016
111
kono
parents: 67
diff changeset
1017 /* functions */
kono
parents: 67
diff changeset
1018 CONSTRUCTOR_APPEND_ELT (v1, info_fields,
kono
parents: 67
diff changeset
1019 build1 (ADDR_EXPR, TREE_TYPE (info_fields), fn_ary));
kono
parents: 67
diff changeset
1020 info_fields = DECL_CHAIN (info_fields);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1021
111
kono
parents: 67
diff changeset
1022 gcc_assert (!info_fields);
kono
parents: 67
diff changeset
1023 return build_constructor (info_type, v1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1025
111
kono
parents: 67
diff changeset
1026 /* Generate the constructor function to call __gcov_init. */
kono
parents: 67
diff changeset
1027
kono
parents: 67
diff changeset
1028 static void
kono
parents: 67
diff changeset
1029 build_init_ctor (tree gcov_info_type)
kono
parents: 67
diff changeset
1030 {
kono
parents: 67
diff changeset
1031 tree ctor, stmt, init_fn;
kono
parents: 67
diff changeset
1032
kono
parents: 67
diff changeset
1033 /* Build a decl for __gcov_init. */
kono
parents: 67
diff changeset
1034 init_fn = build_pointer_type (gcov_info_type);
kono
parents: 67
diff changeset
1035 init_fn = build_function_type_list (void_type_node, init_fn, NULL);
kono
parents: 67
diff changeset
1036 init_fn = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
kono
parents: 67
diff changeset
1037 get_identifier ("__gcov_init"), init_fn);
kono
parents: 67
diff changeset
1038 TREE_PUBLIC (init_fn) = 1;
kono
parents: 67
diff changeset
1039 DECL_EXTERNAL (init_fn) = 1;
kono
parents: 67
diff changeset
1040 DECL_ASSEMBLER_NAME (init_fn);
kono
parents: 67
diff changeset
1041
kono
parents: 67
diff changeset
1042 /* Generate a call to __gcov_init(&gcov_info). */
kono
parents: 67
diff changeset
1043 ctor = NULL;
kono
parents: 67
diff changeset
1044 stmt = build_fold_addr_expr (gcov_info_var);
kono
parents: 67
diff changeset
1045 stmt = build_call_expr (init_fn, 1, stmt);
kono
parents: 67
diff changeset
1046 append_to_statement_list (stmt, &ctor);
kono
parents: 67
diff changeset
1047
kono
parents: 67
diff changeset
1048 /* Generate a constructor to run it. */
kono
parents: 67
diff changeset
1049 int priority = SUPPORTS_INIT_PRIORITY
kono
parents: 67
diff changeset
1050 ? MAX_RESERVED_INIT_PRIORITY: DEFAULT_INIT_PRIORITY;
kono
parents: 67
diff changeset
1051 cgraph_build_static_cdtor ('I', ctor, priority);
kono
parents: 67
diff changeset
1052 }
kono
parents: 67
diff changeset
1053
kono
parents: 67
diff changeset
1054 /* Generate the destructor function to call __gcov_exit. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1055
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056 static void
111
kono
parents: 67
diff changeset
1057 build_gcov_exit_decl (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 {
111
kono
parents: 67
diff changeset
1059 tree init_fn = build_function_type_list (void_type_node, void_type_node,
kono
parents: 67
diff changeset
1060 NULL);
kono
parents: 67
diff changeset
1061 init_fn = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
kono
parents: 67
diff changeset
1062 get_identifier ("__gcov_exit"), init_fn);
kono
parents: 67
diff changeset
1063 TREE_PUBLIC (init_fn) = 1;
kono
parents: 67
diff changeset
1064 DECL_EXTERNAL (init_fn) = 1;
kono
parents: 67
diff changeset
1065 DECL_ASSEMBLER_NAME (init_fn);
kono
parents: 67
diff changeset
1066
kono
parents: 67
diff changeset
1067 /* Generate a call to __gcov_exit (). */
kono
parents: 67
diff changeset
1068 tree dtor = NULL;
kono
parents: 67
diff changeset
1069 tree stmt = build_call_expr (init_fn, 0);
kono
parents: 67
diff changeset
1070 append_to_statement_list (stmt, &dtor);
kono
parents: 67
diff changeset
1071
kono
parents: 67
diff changeset
1072 /* Generate a destructor to run it. */
kono
parents: 67
diff changeset
1073 int priority = SUPPORTS_INIT_PRIORITY
kono
parents: 67
diff changeset
1074 ? MAX_RESERVED_INIT_PRIORITY: DEFAULT_INIT_PRIORITY;
kono
parents: 67
diff changeset
1075
kono
parents: 67
diff changeset
1076 cgraph_build_static_cdtor ('D', dtor, priority);
kono
parents: 67
diff changeset
1077 }
kono
parents: 67
diff changeset
1078
kono
parents: 67
diff changeset
1079 /* Create the gcov_info types and object. Generate the constructor
kono
parents: 67
diff changeset
1080 function to call __gcov_init. Does not generate the initializer
kono
parents: 67
diff changeset
1081 for the object. Returns TRUE if coverage data is being emitted. */
kono
parents: 67
diff changeset
1082
kono
parents: 67
diff changeset
1083 static bool
kono
parents: 67
diff changeset
1084 coverage_obj_init (void)
kono
parents: 67
diff changeset
1085 {
kono
parents: 67
diff changeset
1086 tree gcov_info_type;
kono
parents: 67
diff changeset
1087 unsigned n_counters = 0;
kono
parents: 67
diff changeset
1088 unsigned ix;
kono
parents: 67
diff changeset
1089 struct coverage_data *fn;
kono
parents: 67
diff changeset
1090 struct coverage_data **fn_prev;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1091 char name_buf[32];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1093 no_coverage = 1; /* Disable any further coverage. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1095 if (!prg_ctr_mask)
111
kono
parents: 67
diff changeset
1096 return false;
kono
parents: 67
diff changeset
1097
kono
parents: 67
diff changeset
1098 if (symtab->dump_file)
kono
parents: 67
diff changeset
1099 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
1100
111
kono
parents: 67
diff changeset
1101 /* Prune functions. */
kono
parents: 67
diff changeset
1102 for (fn_prev = &functions_head; (fn = *fn_prev);)
kono
parents: 67
diff changeset
1103 if (DECL_STRUCT_FUNCTION (fn->fn_decl))
kono
parents: 67
diff changeset
1104 fn_prev = &fn->next;
kono
parents: 67
diff changeset
1105 else
kono
parents: 67
diff changeset
1106 /* The function is not being emitted, remove from list. */
kono
parents: 67
diff changeset
1107 *fn_prev = fn->next;
kono
parents: 67
diff changeset
1108
kono
parents: 67
diff changeset
1109 if (functions_head == NULL)
kono
parents: 67
diff changeset
1110 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111
111
kono
parents: 67
diff changeset
1112 for (ix = 0; ix != GCOV_COUNTERS; ix++)
kono
parents: 67
diff changeset
1113 if ((1u << ix) & prg_ctr_mask)
kono
parents: 67
diff changeset
1114 n_counters++;
kono
parents: 67
diff changeset
1115
kono
parents: 67
diff changeset
1116 /* Build the info and fn_info types. These are mutually recursive. */
kono
parents: 67
diff changeset
1117 gcov_info_type = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents: 67
diff changeset
1118 gcov_fn_info_type = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents: 67
diff changeset
1119 build_fn_info_type (gcov_fn_info_type, n_counters, gcov_info_type);
kono
parents: 67
diff changeset
1120 gcov_info_type = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents: 67
diff changeset
1121 gcov_fn_info_ptr_type = build_pointer_type
kono
parents: 67
diff changeset
1122 (build_qualified_type (gcov_fn_info_type, TYPE_QUAL_CONST));
kono
parents: 67
diff changeset
1123 build_info_type (gcov_info_type, gcov_fn_info_ptr_type);
kono
parents: 67
diff changeset
1124
kono
parents: 67
diff changeset
1125 /* Build the gcov info var, this is referred to in its own
kono
parents: 67
diff changeset
1126 initializer. */
kono
parents: 67
diff changeset
1127 gcov_info_var = build_decl (BUILTINS_LOCATION,
kono
parents: 67
diff changeset
1128 VAR_DECL, NULL_TREE, gcov_info_type);
kono
parents: 67
diff changeset
1129 TREE_STATIC (gcov_info_var) = 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1130 ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 0);
111
kono
parents: 67
diff changeset
1131 DECL_NAME (gcov_info_var) = get_identifier (name_buf);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1132
111
kono
parents: 67
diff changeset
1133 build_init_ctor (gcov_info_type);
kono
parents: 67
diff changeset
1134 build_gcov_exit_decl ();
kono
parents: 67
diff changeset
1135
kono
parents: 67
diff changeset
1136 return true;
kono
parents: 67
diff changeset
1137 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1138
111
kono
parents: 67
diff changeset
1139 /* Generate the coverage function info for FN and DATA. Append a
kono
parents: 67
diff changeset
1140 pointer to that object to CTOR and return the appended CTOR. */
kono
parents: 67
diff changeset
1141
kono
parents: 67
diff changeset
1142 static vec<constructor_elt, va_gc> *
kono
parents: 67
diff changeset
1143 coverage_obj_fn (vec<constructor_elt, va_gc> *ctor, tree fn,
kono
parents: 67
diff changeset
1144 struct coverage_data const *data)
kono
parents: 67
diff changeset
1145 {
kono
parents: 67
diff changeset
1146 tree init = build_fn_info (data, gcov_fn_info_type, gcov_info_var);
kono
parents: 67
diff changeset
1147 tree var = build_var (fn, gcov_fn_info_type, -1);
kono
parents: 67
diff changeset
1148
kono
parents: 67
diff changeset
1149 DECL_INITIAL (var) = init;
kono
parents: 67
diff changeset
1150 varpool_node::finalize_decl (var);
kono
parents: 67
diff changeset
1151
kono
parents: 67
diff changeset
1152 CONSTRUCTOR_APPEND_ELT (ctor, NULL,
kono
parents: 67
diff changeset
1153 build1 (ADDR_EXPR, gcov_fn_info_ptr_type, var));
kono
parents: 67
diff changeset
1154 return ctor;
kono
parents: 67
diff changeset
1155 }
kono
parents: 67
diff changeset
1156
kono
parents: 67
diff changeset
1157 /* Finalize the coverage data. Generates the array of pointers to
kono
parents: 67
diff changeset
1158 function objects from CTOR. Generate the gcov_info initializer. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159
111
kono
parents: 67
diff changeset
1160 static void
kono
parents: 67
diff changeset
1161 coverage_obj_finish (vec<constructor_elt, va_gc> *ctor)
kono
parents: 67
diff changeset
1162 {
kono
parents: 67
diff changeset
1163 unsigned n_functions = vec_safe_length (ctor);
kono
parents: 67
diff changeset
1164 tree fn_info_ary_type = build_array_type
kono
parents: 67
diff changeset
1165 (build_qualified_type (gcov_fn_info_ptr_type, TYPE_QUAL_CONST),
kono
parents: 67
diff changeset
1166 build_index_type (size_int (n_functions - 1)));
kono
parents: 67
diff changeset
1167 tree fn_info_ary = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL_TREE,
kono
parents: 67
diff changeset
1168 fn_info_ary_type);
kono
parents: 67
diff changeset
1169 char name_buf[32];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170
111
kono
parents: 67
diff changeset
1171 TREE_STATIC (fn_info_ary) = 1;
kono
parents: 67
diff changeset
1172 ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 1);
kono
parents: 67
diff changeset
1173 DECL_NAME (fn_info_ary) = get_identifier (name_buf);
kono
parents: 67
diff changeset
1174 DECL_INITIAL (fn_info_ary) = build_constructor (fn_info_ary_type, ctor);
kono
parents: 67
diff changeset
1175 varpool_node::finalize_decl (fn_info_ary);
kono
parents: 67
diff changeset
1176
kono
parents: 67
diff changeset
1177 DECL_INITIAL (gcov_info_var)
kono
parents: 67
diff changeset
1178 = build_info (TREE_TYPE (gcov_info_var), fn_info_ary);
kono
parents: 67
diff changeset
1179 varpool_node::finalize_decl (gcov_info_var);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 }
111
kono
parents: 67
diff changeset
1181
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1182 /* Perform file-level initialization. Read in data file, generate name
111
kono
parents: 67
diff changeset
1183 of notes file. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1185 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 coverage_init (const char *filename)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 int len = strlen (filename);
111
kono
parents: 67
diff changeset
1189 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
1190
111
kono
parents: 67
diff changeset
1191 /* Since coverage_init is invoked very early, before the pass
kono
parents: 67
diff changeset
1192 manager, we need to set up the dumping explicitly. This is
kono
parents: 67
diff changeset
1193 similar to the handling in finish_optimization_passes. */
kono
parents: 67
diff changeset
1194 int profile_pass_num =
kono
parents: 67
diff changeset
1195 g->get_passes ()->get_pass_profile ()->static_pass_number;
kono
parents: 67
diff changeset
1196 g->get_dumps ()->dump_start (profile_pass_num, NULL);
kono
parents: 67
diff changeset
1197
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1198 if (!IS_ABSOLUTE_PATH (filename))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1199 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1200 /* When a profile_data_prefix is provided, then mangle full path
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1201 of filename in order to prevent file path clashing. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1202 if (profile_data_prefix)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1203 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1204 #if HAVE_DOS_BASED_FILE_SYSTEM
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1205 const char *separator = "\\";
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1206 #else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1207 const char *separator = "/";
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1208 #endif
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1209 filename = concat (getpwd (), separator, filename, NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1210 filename = mangle_path (filename);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1211 len = strlen (filename);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1212 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1213 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1214 profile_data_prefix = getpwd ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1215 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216
111
kono
parents: 67
diff changeset
1217 if (profile_data_prefix)
kono
parents: 67
diff changeset
1218 prefix_len = strlen (profile_data_prefix);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220 /* 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
1221 da_file_name = XNEWVEC (char, len + strlen (GCOV_DATA_SUFFIX)
111
kono
parents: 67
diff changeset
1222 + prefix_len + 2);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1223
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1224 if (profile_data_prefix)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225 {
111
kono
parents: 67
diff changeset
1226 memcpy (da_file_name, profile_data_prefix, prefix_len);
kono
parents: 67
diff changeset
1227 da_file_name[prefix_len++] = '/';
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1228 }
111
kono
parents: 67
diff changeset
1229 memcpy (da_file_name + prefix_len, filename, len);
kono
parents: 67
diff changeset
1230 strcpy (da_file_name + prefix_len + len, GCOV_DATA_SUFFIX);
kono
parents: 67
diff changeset
1231
kono
parents: 67
diff changeset
1232 bbg_file_stamp = local_tick;
kono
parents: 67
diff changeset
1233
kono
parents: 67
diff changeset
1234 if (flag_auto_profile)
kono
parents: 67
diff changeset
1235 read_autofdo_file ();
kono
parents: 67
diff changeset
1236 else if (flag_branch_probabilities)
kono
parents: 67
diff changeset
1237 read_counts_file ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1239 /* Name of bbg file. */
111
kono
parents: 67
diff changeset
1240 if (flag_test_coverage && !flag_compare_debug)
kono
parents: 67
diff changeset
1241 {
kono
parents: 67
diff changeset
1242 bbg_file_name = XNEWVEC (char, len + strlen (GCOV_NOTE_SUFFIX) + 1);
kono
parents: 67
diff changeset
1243 memcpy (bbg_file_name, filename, len);
kono
parents: 67
diff changeset
1244 strcpy (bbg_file_name + len, GCOV_NOTE_SUFFIX);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245
111
kono
parents: 67
diff changeset
1246 if (!gcov_open (bbg_file_name, -1))
kono
parents: 67
diff changeset
1247 {
kono
parents: 67
diff changeset
1248 error ("cannot open %s", bbg_file_name);
kono
parents: 67
diff changeset
1249 bbg_file_name = NULL;
kono
parents: 67
diff changeset
1250 }
kono
parents: 67
diff changeset
1251 else
kono
parents: 67
diff changeset
1252 {
kono
parents: 67
diff changeset
1253 gcov_write_unsigned (GCOV_NOTE_MAGIC);
kono
parents: 67
diff changeset
1254 gcov_write_unsigned (GCOV_VERSION);
kono
parents: 67
diff changeset
1255 gcov_write_unsigned (bbg_file_stamp);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1256 gcov_write_string (getpwd ());
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1257
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1258 /* Do not support has_unexecuted_blocks for Ada. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1259 gcov_write_unsigned (strcmp (lang_hooks.name, "GNU Ada") != 0);
111
kono
parents: 67
diff changeset
1260 }
kono
parents: 67
diff changeset
1261 }
kono
parents: 67
diff changeset
1262
kono
parents: 67
diff changeset
1263 g->get_dumps ()->dump_finish (profile_pass_num);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265
111
kono
parents: 67
diff changeset
1266 /* Performs file-level cleanup. Close notes file, generate coverage
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1267 variables and constructor. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1268
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1269 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1270 coverage_finish (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1271 {
111
kono
parents: 67
diff changeset
1272 if (bbg_file_name && gcov_close ())
kono
parents: 67
diff changeset
1273 unlink (bbg_file_name);
kono
parents: 67
diff changeset
1274
kono
parents: 67
diff changeset
1275 if (!flag_branch_probabilities && flag_test_coverage
kono
parents: 67
diff changeset
1276 && (!local_tick || local_tick == (unsigned)-1))
kono
parents: 67
diff changeset
1277 /* Only remove the da file, if we're emitting coverage code and
kono
parents: 67
diff changeset
1278 cannot uniquely stamp it. If we can stamp it, libgcov will DTRT. */
kono
parents: 67
diff changeset
1279 unlink (da_file_name);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1280
111
kono
parents: 67
diff changeset
1281 if (coverage_obj_init ())
kono
parents: 67
diff changeset
1282 {
kono
parents: 67
diff changeset
1283 vec<constructor_elt, va_gc> *fn_ctor = NULL;
kono
parents: 67
diff changeset
1284 struct coverage_data *fn;
kono
parents: 67
diff changeset
1285
kono
parents: 67
diff changeset
1286 for (fn = functions_head; fn; fn = fn->next)
kono
parents: 67
diff changeset
1287 fn_ctor = coverage_obj_fn (fn_ctor, fn->fn_decl, fn);
kono
parents: 67
diff changeset
1288 coverage_obj_finish (fn_ctor);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289 }
111
kono
parents: 67
diff changeset
1290
kono
parents: 67
diff changeset
1291 XDELETEVEC (da_file_name);
kono
parents: 67
diff changeset
1292 da_file_name = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1293 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1294
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1295 #include "gt-coverage.h"