dumpfile.h revision 1.1.1.7 1 1.1 mrg /* Definitions for the shared dumpfile.
2 1.1.1.7 mrg Copyright (C) 2004-2020 Free Software Foundation, Inc.
3 1.1 mrg
4 1.1 mrg This file is part of GCC.
5 1.1 mrg
6 1.1 mrg GCC is free software; you can redistribute it and/or modify
7 1.1 mrg it under the terms of the GNU General Public License as published by
8 1.1 mrg the Free Software Foundation; either version 3, or (at your option)
9 1.1 mrg any later version.
10 1.1 mrg
11 1.1 mrg GCC is distributed in the hope that it will be useful,
12 1.1 mrg but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 1.1 mrg GNU General Public License for more details.
15 1.1 mrg
16 1.1 mrg You should have received a copy of the GNU General Public License
17 1.1 mrg along with GCC; see the file COPYING3. If not see
18 1.1 mrg <http://www.gnu.org/licenses/>. */
19 1.1 mrg
20 1.1 mrg
21 1.1 mrg #ifndef GCC_DUMPFILE_H
22 1.1 mrg #define GCC_DUMPFILE_H 1
23 1.1 mrg
24 1.1.1.6 mrg #include "profile-count.h"
25 1.1.1.6 mrg
26 1.1.1.6 mrg /* An attribute for annotating formatting printing functions that use
27 1.1.1.6 mrg the dumpfile/optinfo formatting codes. These are the pretty_printer
28 1.1.1.6 mrg format codes (see pretty-print.c), with additional codes for middle-end
29 1.1.1.6 mrg specific entities (see dumpfile.c). */
30 1.1.1.6 mrg
31 1.1.1.6 mrg #if GCC_VERSION >= 9000
32 1.1.1.6 mrg #define ATTRIBUTE_GCC_DUMP_PRINTF(m, n) \
33 1.1.1.6 mrg __attribute__ ((__format__ (__gcc_dump_printf__, m ,n))) \
34 1.1.1.6 mrg ATTRIBUTE_NONNULL(m)
35 1.1.1.6 mrg #else
36 1.1.1.6 mrg #define ATTRIBUTE_GCC_DUMP_PRINTF(m, n) ATTRIBUTE_NONNULL(m)
37 1.1.1.6 mrg #endif
38 1.1 mrg
39 1.1 mrg /* Different tree dump places. When you add new tree dump places,
40 1.1 mrg extend the DUMP_FILES array in dumpfile.c. */
41 1.1 mrg enum tree_dump_index
42 1.1 mrg {
43 1.1 mrg TDI_none, /* No dump */
44 1.1.1.5 mrg TDI_cgraph, /* dump function call graph. */
45 1.1.1.5 mrg TDI_inheritance, /* dump type inheritance graph. */
46 1.1.1.4 mrg TDI_clones, /* dump IPA cloning decisions. */
47 1.1 mrg TDI_original, /* dump each function before optimizing it */
48 1.1.1.5 mrg TDI_gimple, /* dump each function after gimplifying it */
49 1.1 mrg TDI_nested, /* dump each function after unnesting it */
50 1.1.1.6 mrg TDI_lto_stream_out, /* dump information about lto streaming */
51 1.1.1.5 mrg
52 1.1.1.5 mrg TDI_lang_all, /* enable all the language dumps. */
53 1.1.1.5 mrg TDI_tree_all, /* enable all the GENERIC/GIMPLE dumps. */
54 1.1.1.5 mrg TDI_rtl_all, /* enable all the RTL dumps. */
55 1.1.1.5 mrg TDI_ipa_all, /* enable all the IPA dumps. */
56 1.1 mrg
57 1.1 mrg TDI_end
58 1.1 mrg };
59 1.1 mrg
60 1.1.1.5 mrg /* Enum used to distinguish dump files to types. */
61 1.1.1.5 mrg
62 1.1.1.5 mrg enum dump_kind
63 1.1.1.5 mrg {
64 1.1.1.5 mrg DK_none,
65 1.1.1.5 mrg DK_lang,
66 1.1.1.5 mrg DK_tree,
67 1.1.1.5 mrg DK_rtl,
68 1.1.1.5 mrg DK_ipa
69 1.1.1.5 mrg };
70 1.1.1.5 mrg
71 1.1 mrg /* Bit masks to control dumping. Not all values are applicable to all
72 1.1 mrg dumps. Add new ones at the end. When you define new values, extend
73 1.1 mrg the DUMP_OPTIONS array in dumpfile.c. The TDF_* flags coexist with
74 1.1 mrg MSG_* flags (for -fopt-info) and the bit values must be chosen to
75 1.1 mrg allow that. */
76 1.1.1.6 mrg enum dump_flag
77 1.1.1.6 mrg {
78 1.1.1.6 mrg /* Value of TDF_NONE is used just for bits filtered by TDF_KIND_MASK. */
79 1.1.1.6 mrg TDF_NONE = 0,
80 1.1.1.6 mrg
81 1.1.1.6 mrg /* Dump node addresses. */
82 1.1.1.6 mrg TDF_ADDRESS = (1 << 0),
83 1.1.1.6 mrg
84 1.1.1.6 mrg /* Don't go wild following links. */
85 1.1.1.6 mrg TDF_SLIM = (1 << 1),
86 1.1.1.6 mrg
87 1.1.1.6 mrg /* Don't unparse the function. */
88 1.1.1.6 mrg TDF_RAW = (1 << 2),
89 1.1.1.6 mrg
90 1.1.1.6 mrg /* Show more detailed info about each pass. */
91 1.1.1.6 mrg TDF_DETAILS = (1 << 3),
92 1.1.1.6 mrg
93 1.1.1.6 mrg /* Dump various statistics about each pass. */
94 1.1.1.6 mrg TDF_STATS = (1 << 4),
95 1.1.1.6 mrg
96 1.1.1.6 mrg /* Display basic block boundaries. */
97 1.1.1.6 mrg TDF_BLOCKS = (1 << 5),
98 1.1.1.6 mrg
99 1.1.1.6 mrg /* Display virtual operands. */
100 1.1.1.6 mrg TDF_VOPS = (1 << 6),
101 1.1.1.6 mrg
102 1.1.1.6 mrg /* Display statement line numbers. */
103 1.1.1.6 mrg TDF_LINENO = (1 << 7),
104 1.1.1.6 mrg
105 1.1.1.6 mrg /* Display decl UIDs. */
106 1.1.1.6 mrg TDF_UID = (1 << 8),
107 1.1.1.6 mrg
108 1.1.1.6 mrg /* Address of stmt. */
109 1.1.1.6 mrg TDF_STMTADDR = (1 << 9),
110 1.1.1.6 mrg
111 1.1.1.6 mrg /* A graph dump is being emitted. */
112 1.1.1.6 mrg TDF_GRAPH = (1 << 10),
113 1.1.1.6 mrg
114 1.1.1.6 mrg /* Display memory symbols in expr.
115 1.1.1.6 mrg Implies TDF_VOPS. */
116 1.1.1.6 mrg TDF_MEMSYMS = (1 << 11),
117 1.1.1.6 mrg
118 1.1.1.6 mrg /* A flag to only print the RHS of a gimple stmt. */
119 1.1.1.6 mrg TDF_RHS_ONLY = (1 << 12),
120 1.1.1.6 mrg
121 1.1.1.6 mrg /* Display asm names of decls. */
122 1.1.1.6 mrg TDF_ASMNAME = (1 << 13),
123 1.1.1.6 mrg
124 1.1.1.6 mrg /* Display EH region number holding this gimple statement. */
125 1.1.1.6 mrg TDF_EH = (1 << 14),
126 1.1.1.6 mrg
127 1.1.1.6 mrg /* Omit UIDs from dumps. */
128 1.1.1.6 mrg TDF_NOUID = (1 << 15),
129 1.1.1.6 mrg
130 1.1.1.6 mrg /* Display alias information. */
131 1.1.1.6 mrg TDF_ALIAS = (1 << 16),
132 1.1.1.6 mrg
133 1.1.1.6 mrg /* Enumerate locals by uid. */
134 1.1.1.6 mrg TDF_ENUMERATE_LOCALS = (1 << 17),
135 1.1.1.6 mrg
136 1.1.1.6 mrg /* Dump cselib details. */
137 1.1.1.6 mrg TDF_CSELIB = (1 << 18),
138 1.1.1.6 mrg
139 1.1.1.6 mrg /* Dump SCEV details. */
140 1.1.1.6 mrg TDF_SCEV = (1 << 19),
141 1.1.1.6 mrg
142 1.1.1.6 mrg /* Dump in GIMPLE FE syntax */
143 1.1.1.6 mrg TDF_GIMPLE = (1 << 20),
144 1.1.1.6 mrg
145 1.1.1.6 mrg /* Dump folding details. */
146 1.1.1.6 mrg TDF_FOLDING = (1 << 21),
147 1.1.1.6 mrg
148 1.1.1.6 mrg /* MSG_* flags for expressing the kinds of message to
149 1.1.1.6 mrg be emitted by -fopt-info. */
150 1.1.1.6 mrg
151 1.1.1.6 mrg /* -fopt-info optimized sources. */
152 1.1.1.6 mrg MSG_OPTIMIZED_LOCATIONS = (1 << 22),
153 1.1.1.6 mrg
154 1.1.1.6 mrg /* Missed opportunities. */
155 1.1.1.6 mrg MSG_MISSED_OPTIMIZATION = (1 << 23),
156 1.1.1.6 mrg
157 1.1.1.6 mrg /* General optimization info. */
158 1.1.1.6 mrg MSG_NOTE = (1 << 24),
159 1.1.1.6 mrg
160 1.1.1.6 mrg /* Mask for selecting MSG_-kind flags. */
161 1.1.1.6 mrg MSG_ALL_KINDS = (MSG_OPTIMIZED_LOCATIONS
162 1.1.1.6 mrg | MSG_MISSED_OPTIMIZATION
163 1.1.1.6 mrg | MSG_NOTE),
164 1.1.1.6 mrg
165 1.1.1.6 mrg /* MSG_PRIORITY_* flags for expressing the priority levels of message
166 1.1.1.6 mrg to be emitted by -fopt-info, and filtering on them.
167 1.1.1.6 mrg By default, messages at the top-level dump scope are "user-facing",
168 1.1.1.6 mrg whereas those that are in nested scopes are implicitly "internals".
169 1.1.1.6 mrg This behavior can be overridden for a given dump message by explicitly
170 1.1.1.6 mrg specifying one of the MSG_PRIORITY_* flags.
171 1.1.1.6 mrg
172 1.1.1.6 mrg By default, dump files show both kinds of message, whereas -fopt-info
173 1.1.1.6 mrg only shows "user-facing" messages, and requires the "-internals"
174 1.1.1.6 mrg sub-option of -fopt-info to show the internal messages. */
175 1.1.1.6 mrg
176 1.1.1.6 mrg /* Implicitly supplied for messages at the top-level dump scope. */
177 1.1.1.6 mrg MSG_PRIORITY_USER_FACING = (1 << 25),
178 1.1.1.6 mrg
179 1.1.1.6 mrg /* Implicitly supplied for messages within nested dump scopes. */
180 1.1.1.6 mrg MSG_PRIORITY_INTERNALS = (1 << 26),
181 1.1 mrg
182 1.1.1.6 mrg /* Supplied when an opt_problem generated in a nested scope is re-emitted
183 1.1.1.6 mrg at the top-level. We want to default to showing these in -fopt-info
184 1.1.1.6 mrg output, but to *not* show them in dump files, as the message would be
185 1.1.1.6 mrg shown twice, messing up "scan-tree-dump-times" in DejaGnu tests. */
186 1.1.1.6 mrg MSG_PRIORITY_REEMITTED = (1 << 27),
187 1.1 mrg
188 1.1.1.6 mrg /* Mask for selecting MSG_PRIORITY_* flags. */
189 1.1.1.6 mrg MSG_ALL_PRIORITIES = (MSG_PRIORITY_USER_FACING
190 1.1.1.6 mrg | MSG_PRIORITY_INTERNALS
191 1.1.1.6 mrg | MSG_PRIORITY_REEMITTED),
192 1.1.1.5 mrg
193 1.1.1.6 mrg /* Dumping for -fcompare-debug. */
194 1.1.1.6 mrg TDF_COMPARE_DEBUG = (1 << 28),
195 1.1.1.6 mrg
196 1.1.1.7 mrg /* For error. */
197 1.1.1.7 mrg TDF_ERROR = (1 << 26),
198 1.1.1.7 mrg
199 1.1.1.6 mrg /* All values. */
200 1.1.1.6 mrg TDF_ALL_VALUES = (1 << 29) - 1
201 1.1.1.6 mrg };
202 1.1.1.6 mrg
203 1.1.1.6 mrg /* Dump flags type. */
204 1.1.1.6 mrg
205 1.1.1.6 mrg typedef enum dump_flag dump_flags_t;
206 1.1.1.6 mrg
207 1.1.1.6 mrg static inline dump_flags_t
208 1.1.1.6 mrg operator| (dump_flags_t lhs, dump_flags_t rhs)
209 1.1.1.6 mrg {
210 1.1.1.6 mrg return (dump_flags_t)((int)lhs | (int)rhs);
211 1.1.1.6 mrg }
212 1.1.1.6 mrg
213 1.1.1.6 mrg static inline dump_flags_t
214 1.1.1.6 mrg operator& (dump_flags_t lhs, dump_flags_t rhs)
215 1.1.1.6 mrg {
216 1.1.1.6 mrg return (dump_flags_t)((int)lhs & (int)rhs);
217 1.1.1.6 mrg }
218 1.1.1.6 mrg
219 1.1.1.6 mrg static inline dump_flags_t
220 1.1.1.6 mrg operator~ (dump_flags_t flags)
221 1.1.1.6 mrg {
222 1.1.1.6 mrg return (dump_flags_t)~((int)flags);
223 1.1.1.6 mrg }
224 1.1.1.6 mrg
225 1.1.1.6 mrg static inline dump_flags_t &
226 1.1.1.6 mrg operator|= (dump_flags_t &lhs, dump_flags_t rhs)
227 1.1.1.6 mrg {
228 1.1.1.6 mrg lhs = (dump_flags_t)((int)lhs | (int)rhs);
229 1.1.1.6 mrg return lhs;
230 1.1.1.6 mrg }
231 1.1.1.6 mrg
232 1.1.1.6 mrg static inline dump_flags_t &
233 1.1.1.6 mrg operator&= (dump_flags_t &lhs, dump_flags_t rhs)
234 1.1.1.6 mrg {
235 1.1.1.6 mrg lhs = (dump_flags_t)((int)lhs & (int)rhs);
236 1.1.1.6 mrg return lhs;
237 1.1.1.6 mrg }
238 1.1.1.5 mrg
239 1.1 mrg /* Flags to control high-level -fopt-info dumps. Usually these flags
240 1.1 mrg define a group of passes. An optimization pass can be part of
241 1.1 mrg multiple groups. */
242 1.1.1.5 mrg
243 1.1.1.6 mrg enum optgroup_flag
244 1.1.1.6 mrg {
245 1.1.1.6 mrg OPTGROUP_NONE = 0,
246 1.1.1.6 mrg
247 1.1.1.6 mrg /* IPA optimization passes */
248 1.1.1.6 mrg OPTGROUP_IPA = (1 << 1),
249 1.1.1.6 mrg
250 1.1.1.6 mrg /* Loop optimization passes */
251 1.1.1.6 mrg OPTGROUP_LOOP = (1 << 2),
252 1.1.1.6 mrg
253 1.1.1.6 mrg /* Inlining passes */
254 1.1.1.6 mrg OPTGROUP_INLINE = (1 << 3),
255 1.1.1.5 mrg
256 1.1.1.6 mrg /* OMP (Offloading and Multi Processing) transformations */
257 1.1.1.6 mrg OPTGROUP_OMP = (1 << 4),
258 1.1.1.6 mrg
259 1.1.1.6 mrg /* Vectorization passes */
260 1.1.1.6 mrg OPTGROUP_VEC = (1 << 5),
261 1.1.1.6 mrg
262 1.1.1.6 mrg /* All other passes */
263 1.1.1.6 mrg OPTGROUP_OTHER = (1 << 6),
264 1.1.1.6 mrg
265 1.1.1.6 mrg OPTGROUP_ALL = (OPTGROUP_IPA | OPTGROUP_LOOP | OPTGROUP_INLINE
266 1.1.1.6 mrg | OPTGROUP_OMP | OPTGROUP_VEC | OPTGROUP_OTHER)
267 1.1.1.6 mrg };
268 1.1.1.6 mrg
269 1.1.1.6 mrg typedef enum optgroup_flag optgroup_flags_t;
270 1.1.1.6 mrg
271 1.1.1.6 mrg static inline optgroup_flags_t
272 1.1.1.6 mrg operator| (optgroup_flags_t lhs, optgroup_flags_t rhs)
273 1.1.1.6 mrg {
274 1.1.1.6 mrg return (optgroup_flags_t)((int)lhs | (int)rhs);
275 1.1.1.6 mrg }
276 1.1.1.6 mrg
277 1.1.1.6 mrg static inline optgroup_flags_t &
278 1.1.1.6 mrg operator|= (optgroup_flags_t &lhs, optgroup_flags_t rhs)
279 1.1.1.6 mrg {
280 1.1.1.6 mrg lhs = (optgroup_flags_t)((int)lhs | (int)rhs);
281 1.1.1.6 mrg return lhs;
282 1.1.1.6 mrg }
283 1.1 mrg
284 1.1 mrg /* Define a tree dump switch. */
285 1.1 mrg struct dump_file_info
286 1.1 mrg {
287 1.1.1.5 mrg /* Suffix to give output file. */
288 1.1.1.5 mrg const char *suffix;
289 1.1.1.5 mrg /* Command line dump switch. */
290 1.1.1.5 mrg const char *swtch;
291 1.1.1.5 mrg /* Command line glob. */
292 1.1.1.5 mrg const char *glob;
293 1.1.1.5 mrg /* Filename for the pass-specific stream. */
294 1.1.1.5 mrg const char *pfilename;
295 1.1.1.5 mrg /* Filename for the -fopt-info stream. */
296 1.1.1.5 mrg const char *alt_filename;
297 1.1.1.5 mrg /* Pass-specific dump stream. */
298 1.1.1.5 mrg FILE *pstream;
299 1.1.1.5 mrg /* -fopt-info stream. */
300 1.1.1.5 mrg FILE *alt_stream;
301 1.1.1.5 mrg /* Dump kind. */
302 1.1.1.5 mrg dump_kind dkind;
303 1.1.1.5 mrg /* Dump flags. */
304 1.1.1.5 mrg dump_flags_t pflags;
305 1.1.1.5 mrg /* A pass flags for -fopt-info. */
306 1.1.1.6 mrg dump_flags_t alt_flags;
307 1.1.1.5 mrg /* Flags for -fopt-info given by a user. */
308 1.1.1.6 mrg optgroup_flags_t optgroup_flags;
309 1.1.1.5 mrg /* State of pass-specific stream. */
310 1.1.1.5 mrg int pstate;
311 1.1.1.5 mrg /* State of the -fopt-info stream. */
312 1.1.1.5 mrg int alt_state;
313 1.1.1.5 mrg /* Dump file number. */
314 1.1.1.5 mrg int num;
315 1.1.1.5 mrg /* Fields "suffix", "swtch", "glob" can be const strings,
316 1.1.1.5 mrg or can be dynamically allocated, needing free. */
317 1.1.1.5 mrg bool owns_strings;
318 1.1.1.5 mrg /* When a given dump file is being initialized, this flag is set to true
319 1.1.1.5 mrg if the corresponding TDF_graph dump file has also been initialized. */
320 1.1.1.5 mrg bool graph_dump_initialized;
321 1.1 mrg };
322 1.1 mrg
323 1.1.1.6 mrg /* A class for describing where in the user's source that a dump message
324 1.1.1.6 mrg relates to, with various constructors for convenience.
325 1.1.1.6 mrg In particular, this lets us associate dump messages
326 1.1.1.6 mrg with hotness information (e.g. from PGO), allowing them to
327 1.1.1.6 mrg be prioritized by code hotness. */
328 1.1.1.6 mrg
329 1.1.1.6 mrg class dump_user_location_t
330 1.1.1.6 mrg {
331 1.1.1.6 mrg public:
332 1.1.1.6 mrg /* Default constructor, analogous to UNKNOWN_LOCATION. */
333 1.1.1.6 mrg dump_user_location_t () : m_count (), m_loc (UNKNOWN_LOCATION) {}
334 1.1.1.6 mrg
335 1.1.1.6 mrg /* Construct from a gimple statement (using its location and hotness). */
336 1.1.1.6 mrg dump_user_location_t (const gimple *stmt);
337 1.1.1.6 mrg
338 1.1.1.6 mrg /* Construct from an RTL instruction (using its location and hotness). */
339 1.1.1.6 mrg dump_user_location_t (const rtx_insn *insn);
340 1.1.1.6 mrg
341 1.1.1.6 mrg /* Construct from a location_t. This one is deprecated (since it doesn't
342 1.1.1.6 mrg capture hotness information); it thus needs to be spelled out. */
343 1.1.1.6 mrg static dump_user_location_t
344 1.1.1.6 mrg from_location_t (location_t loc)
345 1.1.1.6 mrg {
346 1.1.1.6 mrg return dump_user_location_t (profile_count (), loc);
347 1.1.1.6 mrg }
348 1.1.1.6 mrg
349 1.1.1.6 mrg /* Construct from a function declaration. This one requires spelling out
350 1.1.1.6 mrg to avoid accidentally constructing from other kinds of tree. */
351 1.1.1.6 mrg static dump_user_location_t
352 1.1.1.6 mrg from_function_decl (tree fndecl);
353 1.1.1.6 mrg
354 1.1.1.6 mrg profile_count get_count () const { return m_count; }
355 1.1.1.6 mrg location_t get_location_t () const { return m_loc; }
356 1.1.1.6 mrg
357 1.1.1.6 mrg private:
358 1.1.1.6 mrg /* Private ctor from count and location, for use by from_location_t. */
359 1.1.1.6 mrg dump_user_location_t (profile_count count, location_t loc)
360 1.1.1.6 mrg : m_count (count), m_loc (loc)
361 1.1.1.6 mrg {}
362 1.1.1.6 mrg
363 1.1.1.6 mrg profile_count m_count;
364 1.1.1.6 mrg location_t m_loc;
365 1.1.1.6 mrg };
366 1.1.1.6 mrg
367 1.1.1.6 mrg /* A class for identifying where in the compiler's own source
368 1.1.1.6 mrg (or a plugin) that a dump message is being emitted from. */
369 1.1.1.6 mrg
370 1.1.1.7 mrg class dump_impl_location_t
371 1.1.1.6 mrg {
372 1.1.1.7 mrg public:
373 1.1.1.6 mrg dump_impl_location_t (
374 1.1.1.6 mrg #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
375 1.1.1.6 mrg const char *file = __builtin_FILE (),
376 1.1.1.6 mrg int line = __builtin_LINE (),
377 1.1.1.6 mrg const char *function = __builtin_FUNCTION ()
378 1.1.1.6 mrg #else
379 1.1.1.6 mrg const char *file = __FILE__,
380 1.1.1.6 mrg int line = __LINE__,
381 1.1.1.6 mrg const char *function = NULL
382 1.1.1.6 mrg #endif
383 1.1.1.6 mrg )
384 1.1.1.6 mrg : m_file (file), m_line (line), m_function (function)
385 1.1.1.6 mrg {}
386 1.1.1.6 mrg
387 1.1.1.6 mrg const char *m_file;
388 1.1.1.6 mrg int m_line;
389 1.1.1.6 mrg const char *m_function;
390 1.1.1.6 mrg };
391 1.1.1.6 mrg
392 1.1.1.6 mrg /* A bundle of metadata for describing a dump message:
393 1.1.1.6 mrg (a) the dump_flags
394 1.1.1.6 mrg (b) the source location within the compiler/plugin.
395 1.1.1.6 mrg
396 1.1.1.6 mrg The constructors use default parameters so that (b) gets sets up
397 1.1.1.6 mrg automatically.
398 1.1.1.6 mrg
399 1.1.1.6 mrg Hence you can pass in e.g. MSG_NOTE, and the dump call
400 1.1.1.6 mrg will automatically record where in GCC's source code the
401 1.1.1.6 mrg dump was emitted from. */
402 1.1.1.6 mrg
403 1.1.1.6 mrg class dump_metadata_t
404 1.1.1.6 mrg {
405 1.1.1.6 mrg public:
406 1.1.1.6 mrg dump_metadata_t (dump_flags_t dump_flags,
407 1.1.1.6 mrg const dump_impl_location_t &impl_location
408 1.1.1.6 mrg = dump_impl_location_t ())
409 1.1.1.6 mrg : m_dump_flags (dump_flags),
410 1.1.1.6 mrg m_impl_location (impl_location)
411 1.1.1.6 mrg {
412 1.1.1.6 mrg }
413 1.1.1.6 mrg
414 1.1.1.6 mrg dump_flags_t get_dump_flags () const { return m_dump_flags; }
415 1.1.1.6 mrg
416 1.1.1.6 mrg const dump_impl_location_t &
417 1.1.1.6 mrg get_impl_location () const { return m_impl_location; }
418 1.1.1.6 mrg
419 1.1.1.6 mrg private:
420 1.1.1.6 mrg dump_flags_t m_dump_flags;
421 1.1.1.6 mrg dump_impl_location_t m_impl_location;
422 1.1.1.6 mrg };
423 1.1.1.6 mrg
424 1.1.1.6 mrg /* A bundle of information for describing the location of a dump message:
425 1.1.1.6 mrg (a) the source location and hotness within the user's code, together with
426 1.1.1.6 mrg (b) the source location within the compiler/plugin.
427 1.1.1.6 mrg
428 1.1.1.6 mrg The constructors use default parameters so that (b) gets sets up
429 1.1.1.6 mrg automatically.
430 1.1.1.6 mrg
431 1.1.1.6 mrg The upshot is that you can pass in e.g. a gimple * to dump_printf_loc,
432 1.1.1.6 mrg and the dump call will automatically record where in GCC's source
433 1.1.1.6 mrg code the dump was emitted from. */
434 1.1.1.6 mrg
435 1.1.1.6 mrg class dump_location_t
436 1.1.1.6 mrg {
437 1.1.1.6 mrg public:
438 1.1.1.6 mrg /* Default constructor, analogous to UNKNOWN_LOCATION. */
439 1.1.1.6 mrg dump_location_t (const dump_impl_location_t &impl_location
440 1.1.1.6 mrg = dump_impl_location_t ())
441 1.1.1.6 mrg : m_user_location (dump_user_location_t ()),
442 1.1.1.6 mrg m_impl_location (impl_location)
443 1.1.1.6 mrg {
444 1.1.1.6 mrg }
445 1.1.1.6 mrg
446 1.1.1.6 mrg /* Construct from a gimple statement (using its location and hotness). */
447 1.1.1.6 mrg dump_location_t (const gimple *stmt,
448 1.1.1.6 mrg const dump_impl_location_t &impl_location
449 1.1.1.6 mrg = dump_impl_location_t ())
450 1.1.1.6 mrg : m_user_location (dump_user_location_t (stmt)),
451 1.1.1.6 mrg m_impl_location (impl_location)
452 1.1.1.6 mrg {
453 1.1.1.6 mrg }
454 1.1.1.6 mrg
455 1.1.1.6 mrg /* Construct from an RTL instruction (using its location and hotness). */
456 1.1.1.6 mrg dump_location_t (const rtx_insn *insn,
457 1.1.1.6 mrg const dump_impl_location_t &impl_location
458 1.1.1.6 mrg = dump_impl_location_t ())
459 1.1.1.6 mrg : m_user_location (dump_user_location_t (insn)),
460 1.1.1.6 mrg m_impl_location (impl_location)
461 1.1.1.6 mrg {
462 1.1.1.6 mrg }
463 1.1.1.6 mrg
464 1.1.1.6 mrg /* Construct from a dump_user_location_t. */
465 1.1.1.6 mrg dump_location_t (const dump_user_location_t &user_location,
466 1.1.1.6 mrg const dump_impl_location_t &impl_location
467 1.1.1.6 mrg = dump_impl_location_t ())
468 1.1.1.6 mrg : m_user_location (user_location),
469 1.1.1.6 mrg m_impl_location (impl_location)
470 1.1.1.6 mrg {
471 1.1.1.6 mrg }
472 1.1.1.6 mrg
473 1.1.1.6 mrg /* Construct from a location_t. This one is deprecated (since it doesn't
474 1.1.1.6 mrg capture hotness information), and thus requires spelling out. */
475 1.1.1.6 mrg static dump_location_t
476 1.1.1.6 mrg from_location_t (location_t loc,
477 1.1.1.6 mrg const dump_impl_location_t &impl_location
478 1.1.1.6 mrg = dump_impl_location_t ())
479 1.1.1.6 mrg {
480 1.1.1.6 mrg return dump_location_t (dump_user_location_t::from_location_t (loc),
481 1.1.1.6 mrg impl_location);
482 1.1.1.6 mrg }
483 1.1.1.6 mrg
484 1.1.1.6 mrg const dump_user_location_t &
485 1.1.1.6 mrg get_user_location () const { return m_user_location; }
486 1.1.1.6 mrg
487 1.1.1.6 mrg const dump_impl_location_t &
488 1.1.1.6 mrg get_impl_location () const { return m_impl_location; }
489 1.1.1.6 mrg
490 1.1.1.6 mrg location_t get_location_t () const
491 1.1.1.6 mrg {
492 1.1.1.6 mrg return m_user_location.get_location_t ();
493 1.1.1.6 mrg }
494 1.1.1.6 mrg
495 1.1.1.6 mrg profile_count get_count () const { return m_user_location.get_count (); }
496 1.1.1.6 mrg
497 1.1.1.6 mrg private:
498 1.1.1.6 mrg dump_user_location_t m_user_location;
499 1.1.1.6 mrg dump_impl_location_t m_impl_location;
500 1.1.1.6 mrg };
501 1.1.1.6 mrg
502 1.1 mrg /* In dumpfile.c */
503 1.1.1.6 mrg extern FILE *dump_begin (int, dump_flags_t *, int part=-1);
504 1.1 mrg extern void dump_end (int, FILE *);
505 1.1 mrg extern int opt_info_switch_p (const char *);
506 1.1 mrg extern const char *dump_flag_name (int);
507 1.1.1.6 mrg extern const kv_pair<optgroup_flags_t> optgroup_options[];
508 1.1.1.7 mrg extern dump_flags_t
509 1.1.1.7 mrg parse_dump_option (const char *, const char **);
510 1.1.1.6 mrg
511 1.1.1.6 mrg /* Global variables used to communicate with passes. */
512 1.1.1.6 mrg extern FILE *dump_file;
513 1.1.1.6 mrg extern dump_flags_t dump_flags;
514 1.1.1.6 mrg extern const char *dump_file_name;
515 1.1.1.6 mrg
516 1.1.1.6 mrg extern bool dumps_are_enabled;
517 1.1.1.6 mrg
518 1.1.1.6 mrg extern void set_dump_file (FILE *new_dump_file);
519 1.1.1.6 mrg
520 1.1.1.6 mrg /* Return true if any of the dumps is enabled, false otherwise. */
521 1.1.1.6 mrg static inline bool
522 1.1.1.6 mrg dump_enabled_p (void)
523 1.1.1.6 mrg {
524 1.1.1.6 mrg return dumps_are_enabled;
525 1.1.1.6 mrg }
526 1.1.1.6 mrg
527 1.1.1.6 mrg /* The following API calls (which *don't* take a "FILE *")
528 1.1.1.6 mrg write the output to zero or more locations.
529 1.1.1.6 mrg
530 1.1.1.6 mrg Some destinations are written to immediately as dump_* calls
531 1.1.1.6 mrg are made; for others, the output is consolidated into an "optinfo"
532 1.1.1.6 mrg instance (with its own metadata), and only emitted once the optinfo
533 1.1.1.6 mrg is complete.
534 1.1.1.6 mrg
535 1.1.1.6 mrg The destinations are:
536 1.1.1.6 mrg
537 1.1.1.6 mrg (a) the "immediate" destinations:
538 1.1.1.6 mrg (a.1) the active dump_file, if any
539 1.1.1.6 mrg (a.2) the -fopt-info destination, if any
540 1.1.1.6 mrg (b) the "optinfo" destinations, if any:
541 1.1.1.6 mrg (b.1) as optimization records
542 1.1.1.6 mrg
543 1.1.1.6 mrg dump_* (MSG_*) --> dumpfile.c --> items --> (a.1) dump_file
544 1.1.1.6 mrg | `-> (a.2) alt_dump_file
545 1.1.1.6 mrg |
546 1.1.1.6 mrg `--> (b) optinfo
547 1.1.1.6 mrg `---> optinfo destinations
548 1.1.1.6 mrg (b.1) optimization records
549 1.1.1.6 mrg
550 1.1.1.6 mrg For optinfos, the dump_*_loc mark the beginning of an optinfo
551 1.1.1.6 mrg instance: all subsequent dump_* calls are consolidated into
552 1.1.1.6 mrg that optinfo, until the next dump_*_loc call (or a change in
553 1.1.1.6 mrg dump scope, or a call to dumpfile_ensure_any_optinfo_are_flushed).
554 1.1.1.6 mrg
555 1.1.1.6 mrg A group of dump_* calls should be guarded by:
556 1.1.1.6 mrg
557 1.1.1.6 mrg if (dump_enabled_p ())
558 1.1.1.6 mrg
559 1.1.1.6 mrg to minimize the work done for the common case where dumps
560 1.1.1.6 mrg are disabled. */
561 1.1.1.6 mrg
562 1.1.1.6 mrg extern void dump_printf (const dump_metadata_t &, const char *, ...)
563 1.1.1.6 mrg ATTRIBUTE_GCC_DUMP_PRINTF (2, 3);
564 1.1.1.6 mrg
565 1.1.1.6 mrg extern void dump_printf_loc (const dump_metadata_t &, const dump_user_location_t &,
566 1.1.1.6 mrg const char *, ...)
567 1.1.1.6 mrg ATTRIBUTE_GCC_DUMP_PRINTF (3, 0);
568 1.1.1.5 mrg extern void dump_function (int phase, tree fn);
569 1.1.1.6 mrg extern void dump_basic_block (dump_flags_t, basic_block, int);
570 1.1.1.6 mrg extern void dump_generic_expr_loc (const dump_metadata_t &,
571 1.1.1.6 mrg const dump_user_location_t &,
572 1.1.1.6 mrg dump_flags_t, tree);
573 1.1.1.6 mrg extern void dump_generic_expr (const dump_metadata_t &, dump_flags_t, tree);
574 1.1.1.6 mrg extern void dump_gimple_stmt_loc (const dump_metadata_t &,
575 1.1.1.6 mrg const dump_user_location_t &,
576 1.1.1.6 mrg dump_flags_t, gimple *, int);
577 1.1.1.6 mrg extern void dump_gimple_stmt (const dump_metadata_t &, dump_flags_t, gimple *, int);
578 1.1.1.6 mrg extern void dump_gimple_expr_loc (const dump_metadata_t &,
579 1.1.1.6 mrg const dump_user_location_t &,
580 1.1.1.6 mrg dump_flags_t, gimple *, int);
581 1.1.1.6 mrg extern void dump_gimple_expr (const dump_metadata_t &, dump_flags_t, gimple *, int);
582 1.1.1.6 mrg extern void dump_symtab_node (const dump_metadata_t &, symtab_node *);
583 1.1 mrg
584 1.1.1.5 mrg template<unsigned int N, typename C>
585 1.1.1.6 mrg void dump_dec (const dump_metadata_t &, const poly_int<N, C> &);
586 1.1.1.6 mrg extern void dump_dec (dump_flags_t, const poly_wide_int &, signop);
587 1.1.1.6 mrg extern void dump_hex (dump_flags_t, const poly_wide_int &);
588 1.1.1.6 mrg
589 1.1.1.6 mrg extern void dumpfile_ensure_any_optinfo_are_flushed ();
590 1.1.1.6 mrg
591 1.1.1.6 mrg /* Managing nested scopes, so that dumps can express the call chain
592 1.1.1.6 mrg leading to a dump message. */
593 1.1.1.6 mrg
594 1.1.1.6 mrg extern unsigned int get_dump_scope_depth ();
595 1.1.1.6 mrg extern void dump_begin_scope (const char *name,
596 1.1.1.6 mrg const dump_user_location_t &user_location,
597 1.1.1.6 mrg const dump_impl_location_t &impl_location);
598 1.1.1.6 mrg extern void dump_end_scope ();
599 1.1.1.6 mrg
600 1.1.1.6 mrg /* Implementation detail of the AUTO_DUMP_SCOPE macro below.
601 1.1.1.6 mrg
602 1.1.1.6 mrg A RAII-style class intended to make it easy to emit dump
603 1.1.1.6 mrg information about entering and exiting a collection of nested
604 1.1.1.6 mrg function calls. */
605 1.1.1.6 mrg
606 1.1.1.6 mrg class auto_dump_scope
607 1.1.1.6 mrg {
608 1.1.1.6 mrg public:
609 1.1.1.6 mrg auto_dump_scope (const char *name,
610 1.1.1.6 mrg const dump_user_location_t &user_location,
611 1.1.1.6 mrg const dump_impl_location_t &impl_location
612 1.1.1.6 mrg = dump_impl_location_t ())
613 1.1.1.6 mrg {
614 1.1.1.6 mrg if (dump_enabled_p ())
615 1.1.1.6 mrg dump_begin_scope (name, user_location, impl_location);
616 1.1.1.6 mrg }
617 1.1.1.6 mrg ~auto_dump_scope ()
618 1.1.1.6 mrg {
619 1.1.1.6 mrg if (dump_enabled_p ())
620 1.1.1.6 mrg dump_end_scope ();
621 1.1.1.6 mrg }
622 1.1.1.6 mrg };
623 1.1.1.6 mrg
624 1.1.1.6 mrg /* A macro for calling:
625 1.1.1.6 mrg dump_begin_scope (NAME, USER_LOC);
626 1.1.1.6 mrg via an RAII object, thus printing "=== MSG ===\n" to the dumpfile etc,
627 1.1.1.6 mrg and then calling
628 1.1.1.6 mrg dump_end_scope ();
629 1.1.1.6 mrg once the object goes out of scope, thus capturing the nesting of
630 1.1.1.6 mrg the scopes.
631 1.1.1.6 mrg
632 1.1.1.6 mrg These scopes affect dump messages within them: dump messages at the
633 1.1.1.6 mrg top level implicitly default to MSG_PRIORITY_USER_FACING, whereas those
634 1.1.1.6 mrg in a nested scope implicitly default to MSG_PRIORITY_INTERNALS. */
635 1.1.1.6 mrg
636 1.1.1.6 mrg #define AUTO_DUMP_SCOPE(NAME, USER_LOC) \
637 1.1.1.6 mrg auto_dump_scope scope (NAME, USER_LOC)
638 1.1.1.6 mrg
639 1.1.1.6 mrg extern void dump_function (int phase, tree fn);
640 1.1.1.6 mrg extern void print_combine_total_stats (void);
641 1.1.1.6 mrg extern bool enable_rtl_dump_file (void);
642 1.1.1.5 mrg
643 1.1.1.2 mrg /* In tree-dump.c */
644 1.1.1.5 mrg extern void dump_node (const_tree, dump_flags_t, FILE *);
645 1.1.1.2 mrg
646 1.1 mrg /* In combine.c */
647 1.1 mrg extern void dump_combine_total_stats (FILE *);
648 1.1 mrg /* In cfghooks.c */
649 1.1.1.5 mrg extern void dump_bb (FILE *, basic_block, int, dump_flags_t);
650 1.1 mrg
651 1.1.1.7 mrg class opt_pass;
652 1.1 mrg
653 1.1.1.2 mrg namespace gcc {
654 1.1.1.2 mrg
655 1.1.1.6 mrg /* A class for managing all of the various dump files used by the
656 1.1.1.6 mrg optimization passes. */
657 1.1.1.6 mrg
658 1.1.1.2 mrg class dump_manager
659 1.1.1.2 mrg {
660 1.1.1.2 mrg public:
661 1.1.1.2 mrg
662 1.1.1.2 mrg dump_manager ();
663 1.1.1.2 mrg ~dump_manager ();
664 1.1.1.2 mrg
665 1.1.1.2 mrg /* Register a dumpfile.
666 1.1.1.2 mrg
667 1.1.1.2 mrg TAKE_OWNERSHIP determines whether callee takes ownership of strings
668 1.1.1.2 mrg SUFFIX, SWTCH, and GLOB. */
669 1.1.1.2 mrg unsigned int
670 1.1.1.2 mrg dump_register (const char *suffix, const char *swtch, const char *glob,
671 1.1.1.6 mrg dump_kind dkind, optgroup_flags_t optgroup_flags,
672 1.1.1.6 mrg bool take_ownership);
673 1.1.1.5 mrg
674 1.1.1.5 mrg /* Allow languages and middle-end to register their dumps before the
675 1.1.1.5 mrg optimization passes. */
676 1.1.1.5 mrg void
677 1.1.1.5 mrg register_dumps ();
678 1.1.1.2 mrg
679 1.1.1.2 mrg /* Return the dump_file_info for the given phase. */
680 1.1.1.2 mrg struct dump_file_info *
681 1.1.1.2 mrg get_dump_file_info (int phase) const;
682 1.1.1.2 mrg
683 1.1.1.2 mrg struct dump_file_info *
684 1.1.1.2 mrg get_dump_file_info_by_switch (const char *swtch) const;
685 1.1.1.2 mrg
686 1.1.1.2 mrg /* Return the name of the dump file for the given phase.
687 1.1.1.2 mrg If the dump is not enabled, returns NULL. */
688 1.1.1.2 mrg char *
689 1.1.1.6 mrg get_dump_file_name (int phase, int part = -1) const;
690 1.1.1.2 mrg
691 1.1.1.2 mrg char *
692 1.1.1.6 mrg get_dump_file_name (struct dump_file_info *dfi, int part = -1) const;
693 1.1.1.2 mrg
694 1.1.1.2 mrg int
695 1.1.1.2 mrg dump_switch_p (const char *arg);
696 1.1.1.2 mrg
697 1.1.1.2 mrg /* Start a dump for PHASE. Store user-supplied dump flags in
698 1.1.1.2 mrg *FLAG_PTR. Return the number of streams opened. Set globals
699 1.1.1.2 mrg DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
700 1.1.1.2 mrg set dump_flags appropriately for both pass dump stream and
701 1.1.1.2 mrg -fopt-info stream. */
702 1.1.1.2 mrg int
703 1.1.1.5 mrg dump_start (int phase, dump_flags_t *flag_ptr);
704 1.1.1.2 mrg
705 1.1.1.2 mrg /* Finish a tree dump for PHASE and close associated dump streams. Also
706 1.1.1.2 mrg reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
707 1.1.1.2 mrg void
708 1.1.1.2 mrg dump_finish (int phase);
709 1.1.1.2 mrg
710 1.1.1.2 mrg FILE *
711 1.1.1.6 mrg dump_begin (int phase, dump_flags_t *flag_ptr, int part);
712 1.1.1.2 mrg
713 1.1.1.2 mrg /* Returns nonzero if tree dump PHASE has been initialized. */
714 1.1.1.2 mrg int
715 1.1.1.2 mrg dump_initialized_p (int phase) const;
716 1.1.1.2 mrg
717 1.1.1.2 mrg /* Returns the switch name of PHASE. */
718 1.1.1.2 mrg const char *
719 1.1.1.2 mrg dump_flag_name (int phase) const;
720 1.1.1.2 mrg
721 1.1.1.6 mrg void register_pass (opt_pass *pass);
722 1.1.1.6 mrg
723 1.1.1.2 mrg private:
724 1.1.1.2 mrg
725 1.1.1.2 mrg int
726 1.1.1.2 mrg dump_phase_enabled_p (int phase) const;
727 1.1.1.2 mrg
728 1.1.1.2 mrg int
729 1.1.1.2 mrg dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob);
730 1.1.1.2 mrg
731 1.1.1.2 mrg int
732 1.1.1.5 mrg dump_enable_all (dump_kind dkind, dump_flags_t flags, const char *filename);
733 1.1.1.2 mrg
734 1.1.1.2 mrg int
735 1.1.1.6 mrg opt_info_enable_passes (optgroup_flags_t optgroup_flags, dump_flags_t flags,
736 1.1.1.5 mrg const char *filename);
737 1.1.1.2 mrg
738 1.1.1.6 mrg bool update_dfi_for_opt_info (dump_file_info *dfi) const;
739 1.1.1.6 mrg
740 1.1.1.2 mrg private:
741 1.1.1.2 mrg
742 1.1.1.2 mrg /* Dynamically registered dump files and switches. */
743 1.1.1.2 mrg int m_next_dump;
744 1.1.1.2 mrg struct dump_file_info *m_extra_dump_files;
745 1.1.1.2 mrg size_t m_extra_dump_files_in_use;
746 1.1.1.2 mrg size_t m_extra_dump_files_alloced;
747 1.1.1.2 mrg
748 1.1.1.6 mrg /* Stored values from -fopt-info, for handling passes created after
749 1.1.1.6 mrg option-parsing (by backends and by plugins). */
750 1.1.1.6 mrg optgroup_flags_t m_optgroup_flags;
751 1.1.1.6 mrg dump_flags_t m_optinfo_flags;
752 1.1.1.6 mrg char *m_optinfo_filename;
753 1.1.1.6 mrg
754 1.1.1.2 mrg /* Grant access to dump_enable_all. */
755 1.1.1.2 mrg friend bool ::enable_rtl_dump_file (void);
756 1.1.1.2 mrg
757 1.1.1.2 mrg /* Grant access to opt_info_enable_passes. */
758 1.1.1.2 mrg friend int ::opt_info_switch_p (const char *arg);
759 1.1.1.2 mrg
760 1.1.1.2 mrg }; // class dump_manager
761 1.1.1.2 mrg
762 1.1.1.2 mrg } // namespace gcc
763 1.1.1.2 mrg
764 1.1 mrg #endif /* GCC_DUMPFILE_H */
765