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