1 /* Definitions for the shared dumpfile.
2 Copyright (C) 2004-2021 Free Software Foundation, Inc.
4 This file is part of GCC.
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)
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.
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/>. */
21 #ifndef GCC_DUMPFILE_H
22 #define GCC_DUMPFILE_H 1
24 #include "profile-count.h"
26 /* An attribute for annotating formatting printing functions that use
27 the dumpfile/optinfo formatting codes. These are the pretty_printer
28 format codes (see pretty-print.c), with additional codes for middle-end
29 specific entities (see dumpfile.c). */
31 #if GCC_VERSION >= 9000
32 #define ATTRIBUTE_GCC_DUMP_PRINTF(m, n) \
33 __attribute__ ((__format__ (__gcc_dump_printf__, m ,n))) \
36 #define ATTRIBUTE_GCC_DUMP_PRINTF(m, n) ATTRIBUTE_NONNULL(m)
39 /* Different tree dump places. When you add new tree dump places,
40 extend the DUMP_FILES array in dumpfile.c. */
43 TDI_none
, /* No dump */
44 TDI_cgraph
, /* dump function call graph. */
45 TDI_inheritance
, /* dump type inheritance graph. */
46 TDI_clones
, /* dump IPA cloning decisions. */
47 TDI_original
, /* dump each function before optimizing it */
48 TDI_gimple
, /* dump each function after gimplifying it */
49 TDI_nested
, /* dump each function after unnesting it */
50 TDI_lto_stream_out
, /* dump information about lto streaming */
51 TDI_profile_report
, /* dump information about profile quality */
53 TDI_lang_all
, /* enable all the language dumps. */
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. */
61 /* Enum used to distinguish dump files to types. */
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
74 the DUMP_OPTIONS array in dumpfile.c. The TDF_* flags coexist with
75 MSG_* flags (for -fopt-info) and the bit values must be chosen to
77 enum dump_flag
: uint32_t
79 /* Value of TDF_NONE is used just for bits filtered by TDF_KIND_MASK. */
82 /* Dump node addresses. */
83 TDF_ADDRESS
= (1 << 0),
85 /* Don't go wild following links. */
88 /* Don't unparse the function. */
91 /* Show more detailed info about each pass. */
92 TDF_DETAILS
= (1 << 3),
94 /* Dump various statistics about each pass. */
97 /* Display basic block boundaries. */
98 TDF_BLOCKS
= (1 << 5),
100 /* Display virtual operands. */
103 /* Display statement line numbers. */
104 TDF_LINENO
= (1 << 7),
106 /* Display decl UIDs. */
109 /* Address of stmt. */
110 TDF_STMTADDR
= (1 << 9),
112 /* A graph dump is being emitted. */
113 TDF_GRAPH
= (1 << 10),
115 /* Display memory symbols in expr.
117 TDF_MEMSYMS
= (1 << 11),
119 /* A flag to only print the RHS of a gimple stmt. */
120 TDF_RHS_ONLY
= (1 << 12),
122 /* Display asm names of decls. */
123 TDF_ASMNAME
= (1 << 13),
125 /* Display EH region number holding this gimple statement. */
128 /* Omit UIDs from dumps. */
129 TDF_NOUID
= (1 << 15),
131 /* Display alias information. */
132 TDF_ALIAS
= (1 << 16),
134 /* Enumerate locals by uid. */
135 TDF_ENUMERATE_LOCALS
= (1 << 17),
137 /* Dump cselib details. */
138 TDF_CSELIB
= (1 << 18),
140 /* Dump SCEV details. */
141 TDF_SCEV
= (1 << 19),
143 /* Dump in GIMPLE FE syntax. */
144 TDF_GIMPLE
= (1 << 20),
146 /* Dump folding details. */
147 TDF_FOLDING
= (1 << 21),
149 /* Dumping for range path solver. */
150 TDF_THREADING
= (1 << 22),
152 /* MSG_* flags for expressing the kinds of message to
153 be emitted by -fopt-info. */
155 /* -fopt-info optimized sources. */
156 MSG_OPTIMIZED_LOCATIONS
= (1 << 23),
158 /* Missed opportunities. */
159 MSG_MISSED_OPTIMIZATION
= (1 << 24),
161 /* General optimization info. */
162 MSG_NOTE
= (1 << 25),
164 /* Mask for selecting MSG_-kind flags. */
165 MSG_ALL_KINDS
= (MSG_OPTIMIZED_LOCATIONS
166 | MSG_MISSED_OPTIMIZATION
169 /* MSG_PRIORITY_* flags for expressing the priority levels of message
170 to be emitted by -fopt-info, and filtering on them.
171 By default, messages at the top-level dump scope are "user-facing",
172 whereas those that are in nested scopes are implicitly "internals".
173 This behavior can be overridden for a given dump message by explicitly
174 specifying one of the MSG_PRIORITY_* flags.
176 By default, dump files show both kinds of message, whereas -fopt-info
177 only shows "user-facing" messages, and requires the "-internals"
178 sub-option of -fopt-info to show the internal messages. */
180 /* Implicitly supplied for messages at the top-level dump scope. */
181 MSG_PRIORITY_USER_FACING
= (1 << 26),
183 /* Implicitly supplied for messages within nested dump scopes. */
184 MSG_PRIORITY_INTERNALS
= (1 << 27),
186 /* Supplied when an opt_problem generated in a nested scope is re-emitted
187 at the top-level. We want to default to showing these in -fopt-info
188 output, but to *not* show them in dump files, as the message would be
189 shown twice, messing up "scan-tree-dump-times" in DejaGnu tests. */
190 MSG_PRIORITY_REEMITTED
= (1 << 28),
192 /* Mask for selecting MSG_PRIORITY_* flags. */
193 MSG_ALL_PRIORITIES
= (MSG_PRIORITY_USER_FACING
194 | MSG_PRIORITY_INTERNALS
195 | MSG_PRIORITY_REEMITTED
),
197 /* All -fdump- flags. */
198 TDF_ALL_VALUES
= (1 << 29) - 1,
200 /* Dumping for -fcompare-debug. */
201 TDF_COMPARE_DEBUG
= (1 << 29),
203 /* Dump a GIMPLE value which means wrapping certain things with _Literal. */
204 TDF_GIMPLE_VAL
= (1 << 30),
207 TDF_ERROR
= ((uint32_t)1 << 31),
210 /* Dump flags type. */
212 typedef enum dump_flag dump_flags_t
;
214 static inline dump_flags_t
215 operator| (dump_flags_t lhs
, dump_flags_t rhs
)
217 return (dump_flags_t
)((std::underlying_type
<dump_flags_t
>::type
)lhs
218 | (std::underlying_type
<dump_flags_t
>::type
)rhs
);
221 static inline dump_flags_t
222 operator& (dump_flags_t lhs
, dump_flags_t rhs
)
224 return (dump_flags_t
)((std::underlying_type
<dump_flags_t
>::type
)lhs
225 & (std::underlying_type
<dump_flags_t
>::type
)rhs
);
228 static inline dump_flags_t
229 operator~ (dump_flags_t flags
)
231 return (dump_flags_t
)~((std::underlying_type
<dump_flags_t
>::type
)flags
);
234 static inline dump_flags_t
&
235 operator|= (dump_flags_t
&lhs
, dump_flags_t rhs
)
237 lhs
= (dump_flags_t
)((std::underlying_type
<dump_flags_t
>::type
)lhs
238 | (std::underlying_type
<dump_flags_t
>::type
)rhs
);
242 static inline dump_flags_t
&
243 operator&= (dump_flags_t
&lhs
, dump_flags_t rhs
)
245 lhs
= (dump_flags_t
)((std::underlying_type
<dump_flags_t
>::type
)lhs
246 & (std::underlying_type
<dump_flags_t
>::type
)rhs
);
250 /* Flags to control high-level -fopt-info dumps. Usually these flags
251 define a group of passes. An optimization pass can be part of
258 /* IPA optimization passes */
259 OPTGROUP_IPA
= (1 << 1),
261 /* Loop optimization passes */
262 OPTGROUP_LOOP
= (1 << 2),
264 /* Inlining passes */
265 OPTGROUP_INLINE
= (1 << 3),
267 /* OMP (Offloading and Multi Processing) transformations */
268 OPTGROUP_OMP
= (1 << 4),
270 /* Vectorization passes */
271 OPTGROUP_VEC
= (1 << 5),
273 /* All other passes */
274 OPTGROUP_OTHER
= (1 << 6),
276 OPTGROUP_ALL
= (OPTGROUP_IPA
| OPTGROUP_LOOP
| OPTGROUP_INLINE
277 | OPTGROUP_OMP
| OPTGROUP_VEC
| OPTGROUP_OTHER
)
280 typedef enum optgroup_flag optgroup_flags_t
;
282 static inline optgroup_flags_t
283 operator| (optgroup_flags_t lhs
, optgroup_flags_t rhs
)
285 return (optgroup_flags_t
)((std::underlying_type
<dump_flags_t
>::type
)lhs
286 | (std::underlying_type
<dump_flags_t
>::type
)rhs
);
289 static inline optgroup_flags_t
&
290 operator|= (optgroup_flags_t
&lhs
, optgroup_flags_t rhs
)
292 lhs
= (optgroup_flags_t
)((std::underlying_type
<dump_flags_t
>::type
)lhs
293 | (std::underlying_type
<dump_flags_t
>::type
)rhs
);
297 /* Define a tree dump switch. */
298 struct dump_file_info
300 /* Suffix to give output file. */
302 /* Command line dump switch. */
304 /* Command line glob. */
306 /* Filename for the pass-specific stream. */
307 const char *pfilename
;
308 /* Filename for the -fopt-info stream. */
309 const char *alt_filename
;
310 /* Pass-specific dump stream. */
312 /* -fopt-info stream. */
318 /* A pass flags for -fopt-info. */
319 dump_flags_t alt_flags
;
320 /* Flags for -fopt-info given by a user. */
321 optgroup_flags_t optgroup_flags
;
322 /* State of pass-specific stream. */
324 /* State of the -fopt-info stream. */
326 /* Dump file number. */
328 /* Fields "suffix", "swtch", "glob" can be const strings,
329 or can be dynamically allocated, needing free. */
331 /* When a given dump file is being initialized, this flag is set to true
332 if the corresponding TDF_graph dump file has also been initialized. */
333 bool graph_dump_initialized
;
336 /* A class for describing where in the user's source that a dump message
337 relates to, with various constructors for convenience.
338 In particular, this lets us associate dump messages
339 with hotness information (e.g. from PGO), allowing them to
340 be prioritized by code hotness. */
342 class dump_user_location_t
345 /* Default constructor, analogous to UNKNOWN_LOCATION. */
346 dump_user_location_t () : m_count (), m_loc (UNKNOWN_LOCATION
) {}
348 /* Construct from a gimple statement (using its location and hotness). */
349 dump_user_location_t (const gimple
*stmt
);
351 /* Construct from an RTL instruction (using its location and hotness). */
352 dump_user_location_t (const rtx_insn
*insn
);
354 /* Construct from a location_t. This one is deprecated (since it doesn't
355 capture hotness information); it thus needs to be spelled out. */
356 static dump_user_location_t
357 from_location_t (location_t loc
)
359 return dump_user_location_t (profile_count (), loc
);
362 /* Construct from a function declaration. This one requires spelling out
363 to avoid accidentally constructing from other kinds of tree. */
364 static dump_user_location_t
365 from_function_decl (tree fndecl
);
367 profile_count
get_count () const { return m_count
; }
368 location_t
get_location_t () const { return m_loc
; }
371 /* Private ctor from count and location, for use by from_location_t. */
372 dump_user_location_t (profile_count count
, location_t loc
)
373 : m_count (count
), m_loc (loc
)
376 profile_count m_count
;
380 /* A class for identifying where in the compiler's own source
381 (or a plugin) that a dump message is being emitted from. */
383 class dump_impl_location_t
386 dump_impl_location_t (
387 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
388 const char *file
= __builtin_FILE (),
389 int line
= __builtin_LINE (),
390 const char *function
= __builtin_FUNCTION ()
392 const char *file
= __FILE__
,
394 const char *function
= NULL
397 : m_file (file
), m_line (line
), m_function (function
)
402 const char *m_function
;
405 /* A bundle of metadata for describing a dump message:
407 (b) the source location within the compiler/plugin.
409 The constructors use default parameters so that (b) gets sets up
412 Hence you can pass in e.g. MSG_NOTE, and the dump call
413 will automatically record where in GCC's source code the
414 dump was emitted from. */
416 class dump_metadata_t
419 dump_metadata_t (dump_flags_t dump_flags
,
420 const dump_impl_location_t
&impl_location
421 = dump_impl_location_t ())
422 : m_dump_flags (dump_flags
),
423 m_impl_location (impl_location
)
427 dump_flags_t
get_dump_flags () const { return m_dump_flags
; }
429 const dump_impl_location_t
&
430 get_impl_location () const { return m_impl_location
; }
433 dump_flags_t m_dump_flags
;
434 dump_impl_location_t m_impl_location
;
437 /* A bundle of information for describing the location of a dump message:
438 (a) the source location and hotness within the user's code, together with
439 (b) the source location within the compiler/plugin.
441 The constructors use default parameters so that (b) gets sets up
444 The upshot is that you can pass in e.g. a gimple * to dump_printf_loc,
445 and the dump call will automatically record where in GCC's source
446 code the dump was emitted from. */
448 class dump_location_t
451 /* Default constructor, analogous to UNKNOWN_LOCATION. */
452 dump_location_t (const dump_impl_location_t
&impl_location
453 = dump_impl_location_t ())
454 : m_user_location (dump_user_location_t ()),
455 m_impl_location (impl_location
)
459 /* Construct from a gimple statement (using its location and hotness). */
460 dump_location_t (const gimple
*stmt
,
461 const dump_impl_location_t
&impl_location
462 = dump_impl_location_t ())
463 : m_user_location (dump_user_location_t (stmt
)),
464 m_impl_location (impl_location
)
468 /* Construct from an RTL instruction (using its location and hotness). */
469 dump_location_t (const rtx_insn
*insn
,
470 const dump_impl_location_t
&impl_location
471 = dump_impl_location_t ())
472 : m_user_location (dump_user_location_t (insn
)),
473 m_impl_location (impl_location
)
477 /* Construct from a dump_user_location_t. */
478 dump_location_t (const dump_user_location_t
&user_location
,
479 const dump_impl_location_t
&impl_location
480 = dump_impl_location_t ())
481 : m_user_location (user_location
),
482 m_impl_location (impl_location
)
486 /* Construct from a location_t. This one is deprecated (since it doesn't
487 capture hotness information), and thus requires spelling out. */
488 static dump_location_t
489 from_location_t (location_t loc
,
490 const dump_impl_location_t
&impl_location
491 = dump_impl_location_t ())
493 return dump_location_t (dump_user_location_t::from_location_t (loc
),
497 const dump_user_location_t
&
498 get_user_location () const { return m_user_location
; }
500 const dump_impl_location_t
&
501 get_impl_location () const { return m_impl_location
; }
503 location_t
get_location_t () const
505 return m_user_location
.get_location_t ();
508 profile_count
get_count () const { return m_user_location
.get_count (); }
511 dump_user_location_t m_user_location
;
512 dump_impl_location_t m_impl_location
;
516 extern FILE *dump_begin (int, dump_flags_t
*, int part
=-1);
517 extern void dump_end (int, FILE *);
518 extern int opt_info_switch_p (const char *);
519 extern const char *dump_flag_name (int);
520 extern const kv_pair
<optgroup_flags_t
> optgroup_options
[];
522 parse_dump_option (const char *, const char **);
524 /* Global variables used to communicate with passes. */
525 extern FILE *dump_file
;
526 extern dump_flags_t dump_flags
;
527 extern const char *dump_file_name
;
529 extern bool dumps_are_enabled
;
531 extern void set_dump_file (FILE *new_dump_file
);
533 /* Return true if any of the dumps is enabled, false otherwise. */
535 dump_enabled_p (void)
537 return dumps_are_enabled
;
540 /* The following API calls (which *don't* take a "FILE *")
541 write the output to zero or more locations.
543 Some destinations are written to immediately as dump_* calls
544 are made; for others, the output is consolidated into an "optinfo"
545 instance (with its own metadata), and only emitted once the optinfo
548 The destinations are:
550 (a) the "immediate" destinations:
551 (a.1) the active dump_file, if any
552 (a.2) the -fopt-info destination, if any
553 (b) the "optinfo" destinations, if any:
554 (b.1) as optimization records
556 dump_* (MSG_*) --> dumpfile.c --> items --> (a.1) dump_file
557 | `-> (a.2) alt_dump_file
560 `---> optinfo destinations
561 (b.1) optimization records
563 For optinfos, the dump_*_loc mark the beginning of an optinfo
564 instance: all subsequent dump_* calls are consolidated into
565 that optinfo, until the next dump_*_loc call (or a change in
566 dump scope, or a call to dumpfile_ensure_any_optinfo_are_flushed).
568 A group of dump_* calls should be guarded by:
570 if (dump_enabled_p ())
572 to minimize the work done for the common case where dumps
575 extern void dump_printf (const dump_metadata_t
&, const char *, ...)
576 ATTRIBUTE_GCC_DUMP_PRINTF (2, 3);
578 extern void dump_printf_loc (const dump_metadata_t
&, const dump_user_location_t
&,
580 ATTRIBUTE_GCC_DUMP_PRINTF (3, 0);
581 extern void dump_function (int phase
, tree fn
);
582 extern void dump_basic_block (dump_flags_t
, basic_block
, int);
583 extern void dump_generic_expr_loc (const dump_metadata_t
&,
584 const dump_user_location_t
&,
586 extern void dump_generic_expr (const dump_metadata_t
&, dump_flags_t
, tree
);
587 extern void dump_gimple_stmt_loc (const dump_metadata_t
&,
588 const dump_user_location_t
&,
589 dump_flags_t
, gimple
*, int);
590 extern void dump_gimple_stmt (const dump_metadata_t
&, dump_flags_t
, gimple
*, int);
591 extern void dump_gimple_expr_loc (const dump_metadata_t
&,
592 const dump_user_location_t
&,
593 dump_flags_t
, gimple
*, int);
594 extern void dump_gimple_expr (const dump_metadata_t
&, dump_flags_t
, gimple
*, int);
595 extern void dump_symtab_node (const dump_metadata_t
&, symtab_node
*);
597 template<unsigned int N
, typename C
>
598 void dump_dec (const dump_metadata_t
&, const poly_int
<N
, C
> &);
599 extern void dump_dec (dump_flags_t
, const poly_wide_int
&, signop
);
600 extern void dump_hex (dump_flags_t
, const poly_wide_int
&);
602 extern void dumpfile_ensure_any_optinfo_are_flushed ();
604 /* Managing nested scopes, so that dumps can express the call chain
605 leading to a dump message. */
607 extern unsigned int get_dump_scope_depth ();
608 extern void dump_begin_scope (const char *name
,
609 const dump_user_location_t
&user_location
,
610 const dump_impl_location_t
&impl_location
);
611 extern void dump_end_scope ();
613 /* Implementation detail of the AUTO_DUMP_SCOPE macro below.
615 A RAII-style class intended to make it easy to emit dump
616 information about entering and exiting a collection of nested
619 class auto_dump_scope
622 auto_dump_scope (const char *name
,
623 const dump_user_location_t
&user_location
,
624 const dump_impl_location_t
&impl_location
625 = dump_impl_location_t ())
627 if (dump_enabled_p ())
628 dump_begin_scope (name
, user_location
, impl_location
);
632 if (dump_enabled_p ())
637 /* A macro for calling:
638 dump_begin_scope (NAME, USER_LOC);
639 via an RAII object, thus printing "=== MSG ===\n" to the dumpfile etc,
642 once the object goes out of scope, thus capturing the nesting of
645 These scopes affect dump messages within them: dump messages at the
646 top level implicitly default to MSG_PRIORITY_USER_FACING, whereas those
647 in a nested scope implicitly default to MSG_PRIORITY_INTERNALS. */
649 #define AUTO_DUMP_SCOPE(NAME, USER_LOC) \
650 auto_dump_scope scope (NAME, USER_LOC)
652 extern void dump_function (int phase
, tree fn
);
653 extern void print_combine_total_stats (void);
654 extern bool enable_rtl_dump_file (void);
657 extern void dump_node (const_tree
, dump_flags_t
, FILE *);
660 extern void dump_combine_total_stats (FILE *);
662 extern void dump_bb (FILE *, basic_block
, int, dump_flags_t
);
668 /* A class for managing all of the various dump files used by the
669 optimization passes. */
678 /* Register a dumpfile.
680 TAKE_OWNERSHIP determines whether callee takes ownership of strings
681 SUFFIX, SWTCH, and GLOB. */
683 dump_register (const char *suffix
, const char *swtch
, const char *glob
,
684 dump_kind dkind
, optgroup_flags_t optgroup_flags
,
685 bool take_ownership
);
687 /* Allow languages and middle-end to register their dumps before the
688 optimization passes. */
692 /* Return the dump_file_info for the given phase. */
693 struct dump_file_info
*
694 get_dump_file_info (int phase
) const;
696 struct dump_file_info
*
697 get_dump_file_info_by_switch (const char *swtch
) const;
699 /* Return the name of the dump file for the given phase.
700 If the dump is not enabled, returns NULL. */
702 get_dump_file_name (int phase
, int part
= -1) const;
705 get_dump_file_name (struct dump_file_info
*dfi
, int part
= -1) const;
708 dump_switch_p (const char *arg
);
710 /* Start a dump for PHASE. Store user-supplied dump flags in
711 *FLAG_PTR. Return the number of streams opened. Set globals
712 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
713 set dump_flags appropriately for both pass dump stream and
714 -fopt-info stream. */
716 dump_start (int phase
, dump_flags_t
*flag_ptr
);
718 /* Finish a tree dump for PHASE and close associated dump streams. Also
719 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
721 dump_finish (int phase
);
724 dump_begin (int phase
, dump_flags_t
*flag_ptr
, int part
);
726 /* Returns nonzero if tree dump PHASE has been initialized. */
728 dump_initialized_p (int phase
) const;
730 /* Returns the switch name of PHASE. */
732 dump_flag_name (int phase
) const;
734 void register_pass (opt_pass
*pass
);
739 dump_phase_enabled_p (int phase
) const;
742 dump_switch_p_1 (const char *arg
, struct dump_file_info
*dfi
, bool doglob
);
745 dump_enable_all (dump_kind dkind
, dump_flags_t flags
, const char *filename
);
748 opt_info_enable_passes (optgroup_flags_t optgroup_flags
, dump_flags_t flags
,
749 const char *filename
);
751 bool update_dfi_for_opt_info (dump_file_info
*dfi
) const;
755 /* Dynamically registered dump files and switches. */
757 struct dump_file_info
*m_extra_dump_files
;
758 size_t m_extra_dump_files_in_use
;
759 size_t m_extra_dump_files_alloced
;
761 /* Stored values from -fopt-info, for handling passes created after
762 option-parsing (by backends and by plugins). */
763 optgroup_flags_t m_optgroup_flags
;
764 dump_flags_t m_optinfo_flags
;
765 char *m_optinfo_filename
;
767 /* Grant access to dump_enable_all. */
768 friend bool ::enable_rtl_dump_file (void);
770 /* Grant access to opt_info_enable_passes. */
771 friend int ::opt_info_switch_p (const char *arg
);
773 }; // class dump_manager
777 #endif /* GCC_DUMPFILE_H */