1 /* Definitions for the shared dumpfile.
2 Copyright (C) 2004-2018 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 */
52 TDI_lang_all
, /* enable all the language dumps. */
53 TDI_tree_all
, /* enable all the GENERIC/GIMPLE dumps. */
54 TDI_rtl_all
, /* enable all the RTL dumps. */
55 TDI_ipa_all
, /* enable all the IPA dumps. */
60 /* Enum used to distinguish dump files to types. */
71 /* Bit masks to control dumping. Not all values are applicable to all
72 dumps. Add new ones at the end. When you define new values, extend
73 the DUMP_OPTIONS array in dumpfile.c. The TDF_* flags coexist with
74 MSG_* flags (for -fopt-info) and the bit values must be chosen to
78 /* Value of TDF_NONE is used just for bits filtered by TDF_KIND_MASK. */
81 /* Dump node addresses. */
82 TDF_ADDRESS
= (1 << 0),
84 /* Don't go wild following links. */
87 /* Don't unparse the function. */
90 /* Show more detailed info about each pass. */
91 TDF_DETAILS
= (1 << 3),
93 /* Dump various statistics about each pass. */
96 /* Display basic block boundaries. */
97 TDF_BLOCKS
= (1 << 5),
99 /* Display virtual operands. */
102 /* Display statement line numbers. */
103 TDF_LINENO
= (1 << 7),
105 /* Display decl UIDs. */
108 /* Address of stmt. */
109 TDF_STMTADDR
= (1 << 9),
111 /* A graph dump is being emitted. */
112 TDF_GRAPH
= (1 << 10),
114 /* Display memory symbols in expr.
116 TDF_MEMSYMS
= (1 << 11),
118 /* A flag to only print the RHS of a gimple stmt. */
119 TDF_RHS_ONLY
= (1 << 12),
121 /* Display asm names of decls. */
122 TDF_ASMNAME
= (1 << 13),
124 /* Display EH region number holding this gimple statement. */
127 /* Omit UIDs from dumps. */
128 TDF_NOUID
= (1 << 15),
130 /* Display alias information. */
131 TDF_ALIAS
= (1 << 16),
133 /* Enumerate locals by uid. */
134 TDF_ENUMERATE_LOCALS
= (1 << 17),
136 /* Dump cselib details. */
137 TDF_CSELIB
= (1 << 18),
139 /* Dump SCEV details. */
140 TDF_SCEV
= (1 << 19),
142 /* Dump in GIMPLE FE syntax */
143 TDF_GIMPLE
= (1 << 20),
145 /* Dump folding details. */
146 TDF_FOLDING
= (1 << 21),
148 /* MSG_* flags for expressing the kinds of message to
149 be emitted by -fopt-info. */
151 /* -fopt-info optimized sources. */
152 MSG_OPTIMIZED_LOCATIONS
= (1 << 22),
154 /* Missed opportunities. */
155 MSG_MISSED_OPTIMIZATION
= (1 << 23),
157 /* General optimization info. */
158 MSG_NOTE
= (1 << 24),
160 /* Mask for selecting MSG_-kind flags. */
161 MSG_ALL_KINDS
= (MSG_OPTIMIZED_LOCATIONS
162 | MSG_MISSED_OPTIMIZATION
165 /* MSG_PRIORITY_* flags for expressing the priority levels of message
166 to be emitted by -fopt-info, and filtering on them.
167 By default, messages at the top-level dump scope are "user-facing",
168 whereas those that are in nested scopes are implicitly "internals".
169 This behavior can be overridden for a given dump message by explicitly
170 specifying one of the MSG_PRIORITY_* flags.
172 By default, dump files show both kinds of message, whereas -fopt-info
173 only shows "user-facing" messages, and requires the "-internals"
174 sub-option of -fopt-info to show the internal messages. */
176 /* Implicitly supplied for messages at the top-level dump scope. */
177 MSG_PRIORITY_USER_FACING
= (1 << 25),
179 /* Implicitly supplied for messages within nested dump scopes. */
180 MSG_PRIORITY_INTERNALS
= (1 << 26),
182 /* Supplied when an opt_problem generated in a nested scope is re-emitted
183 at the top-level. We want to default to showing these in -fopt-info
184 output, but to *not* show them in dump files, as the message would be
185 shown twice, messing up "scan-tree-dump-times" in DejaGnu tests. */
186 MSG_PRIORITY_REEMITTED
= (1 << 27),
188 /* Mask for selecting MSG_PRIORITY_* flags. */
189 MSG_ALL_PRIORITIES
= (MSG_PRIORITY_USER_FACING
190 | MSG_PRIORITY_INTERNALS
191 | MSG_PRIORITY_REEMITTED
),
193 /* Dumping for -fcompare-debug. */
194 TDF_COMPARE_DEBUG
= (1 << 28),
197 TDF_ALL_VALUES
= (1 << 29) - 1
200 /* Dump flags type. */
202 typedef enum dump_flag dump_flags_t
;
204 static inline dump_flags_t
205 operator| (dump_flags_t lhs
, dump_flags_t rhs
)
207 return (dump_flags_t
)((int)lhs
| (int)rhs
);
210 static inline dump_flags_t
211 operator& (dump_flags_t lhs
, dump_flags_t rhs
)
213 return (dump_flags_t
)((int)lhs
& (int)rhs
);
216 static inline dump_flags_t
217 operator~ (dump_flags_t flags
)
219 return (dump_flags_t
)~((int)flags
);
222 static inline dump_flags_t
&
223 operator|= (dump_flags_t
&lhs
, dump_flags_t rhs
)
225 lhs
= (dump_flags_t
)((int)lhs
| (int)rhs
);
229 static inline dump_flags_t
&
230 operator&= (dump_flags_t
&lhs
, dump_flags_t rhs
)
232 lhs
= (dump_flags_t
)((int)lhs
& (int)rhs
);
236 /* Flags to control high-level -fopt-info dumps. Usually these flags
237 define a group of passes. An optimization pass can be part of
244 /* IPA optimization passes */
245 OPTGROUP_IPA
= (1 << 1),
247 /* Loop optimization passes */
248 OPTGROUP_LOOP
= (1 << 2),
250 /* Inlining passes */
251 OPTGROUP_INLINE
= (1 << 3),
253 /* OMP (Offloading and Multi Processing) transformations */
254 OPTGROUP_OMP
= (1 << 4),
256 /* Vectorization passes */
257 OPTGROUP_VEC
= (1 << 5),
259 /* All other passes */
260 OPTGROUP_OTHER
= (1 << 6),
262 OPTGROUP_ALL
= (OPTGROUP_IPA
| OPTGROUP_LOOP
| OPTGROUP_INLINE
263 | OPTGROUP_OMP
| OPTGROUP_VEC
| OPTGROUP_OTHER
)
266 typedef enum optgroup_flag optgroup_flags_t
;
268 static inline optgroup_flags_t
269 operator| (optgroup_flags_t lhs
, optgroup_flags_t rhs
)
271 return (optgroup_flags_t
)((int)lhs
| (int)rhs
);
274 static inline optgroup_flags_t
&
275 operator|= (optgroup_flags_t
&lhs
, optgroup_flags_t rhs
)
277 lhs
= (optgroup_flags_t
)((int)lhs
| (int)rhs
);
281 /* Define a tree dump switch. */
282 struct dump_file_info
284 /* Suffix to give output file. */
286 /* Command line dump switch. */
288 /* Command line glob. */
290 /* Filename for the pass-specific stream. */
291 const char *pfilename
;
292 /* Filename for the -fopt-info stream. */
293 const char *alt_filename
;
294 /* Pass-specific dump stream. */
296 /* -fopt-info stream. */
302 /* A pass flags for -fopt-info. */
303 dump_flags_t alt_flags
;
304 /* Flags for -fopt-info given by a user. */
305 optgroup_flags_t optgroup_flags
;
306 /* State of pass-specific stream. */
308 /* State of the -fopt-info stream. */
310 /* Dump file number. */
312 /* Fields "suffix", "swtch", "glob" can be const strings,
313 or can be dynamically allocated, needing free. */
315 /* When a given dump file is being initialized, this flag is set to true
316 if the corresponding TDF_graph dump file has also been initialized. */
317 bool graph_dump_initialized
;
320 /* A class for describing where in the user's source that a dump message
321 relates to, with various constructors for convenience.
322 In particular, this lets us associate dump messages
323 with hotness information (e.g. from PGO), allowing them to
324 be prioritized by code hotness. */
326 class dump_user_location_t
329 /* Default constructor, analogous to UNKNOWN_LOCATION. */
330 dump_user_location_t () : m_count (), m_loc (UNKNOWN_LOCATION
) {}
332 /* Construct from a gimple statement (using its location and hotness). */
333 dump_user_location_t (const gimple
*stmt
);
335 /* Construct from an RTL instruction (using its location and hotness). */
336 dump_user_location_t (const rtx_insn
*insn
);
338 /* Construct from a location_t. This one is deprecated (since it doesn't
339 capture hotness information); it thus needs to be spelled out. */
340 static dump_user_location_t
341 from_location_t (location_t loc
)
343 return dump_user_location_t (profile_count (), loc
);
346 /* Construct from a function declaration. This one requires spelling out
347 to avoid accidentally constructing from other kinds of tree. */
348 static dump_user_location_t
349 from_function_decl (tree fndecl
);
351 profile_count
get_count () const { return m_count
; }
352 location_t
get_location_t () const { return m_loc
; }
355 /* Private ctor from count and location, for use by from_location_t. */
356 dump_user_location_t (profile_count count
, location_t loc
)
357 : m_count (count
), m_loc (loc
)
360 profile_count m_count
;
364 /* A class for identifying where in the compiler's own source
365 (or a plugin) that a dump message is being emitted from. */
367 struct dump_impl_location_t
369 dump_impl_location_t (
370 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
371 const char *file
= __builtin_FILE (),
372 int line
= __builtin_LINE (),
373 const char *function
= __builtin_FUNCTION ()
375 const char *file
= __FILE__
,
377 const char *function
= NULL
380 : m_file (file
), m_line (line
), m_function (function
)
385 const char *m_function
;
388 /* A bundle of metadata for describing a dump message:
390 (b) the source location within the compiler/plugin.
392 The constructors use default parameters so that (b) gets sets up
395 Hence you can pass in e.g. MSG_NOTE, and the dump call
396 will automatically record where in GCC's source code the
397 dump was emitted from. */
399 class dump_metadata_t
402 dump_metadata_t (dump_flags_t dump_flags
,
403 const dump_impl_location_t
&impl_location
404 = dump_impl_location_t ())
405 : m_dump_flags (dump_flags
),
406 m_impl_location (impl_location
)
410 dump_flags_t
get_dump_flags () const { return m_dump_flags
; }
412 const dump_impl_location_t
&
413 get_impl_location () const { return m_impl_location
; }
416 dump_flags_t m_dump_flags
;
417 dump_impl_location_t m_impl_location
;
420 /* A bundle of information for describing the location of a dump message:
421 (a) the source location and hotness within the user's code, together with
422 (b) the source location within the compiler/plugin.
424 The constructors use default parameters so that (b) gets sets up
427 The upshot is that you can pass in e.g. a gimple * to dump_printf_loc,
428 and the dump call will automatically record where in GCC's source
429 code the dump was emitted from. */
431 class dump_location_t
434 /* Default constructor, analogous to UNKNOWN_LOCATION. */
435 dump_location_t (const dump_impl_location_t
&impl_location
436 = dump_impl_location_t ())
437 : m_user_location (dump_user_location_t ()),
438 m_impl_location (impl_location
)
442 /* Construct from a gimple statement (using its location and hotness). */
443 dump_location_t (const gimple
*stmt
,
444 const dump_impl_location_t
&impl_location
445 = dump_impl_location_t ())
446 : m_user_location (dump_user_location_t (stmt
)),
447 m_impl_location (impl_location
)
451 /* Construct from an RTL instruction (using its location and hotness). */
452 dump_location_t (const rtx_insn
*insn
,
453 const dump_impl_location_t
&impl_location
454 = dump_impl_location_t ())
455 : m_user_location (dump_user_location_t (insn
)),
456 m_impl_location (impl_location
)
460 /* Construct from a dump_user_location_t. */
461 dump_location_t (const dump_user_location_t
&user_location
,
462 const dump_impl_location_t
&impl_location
463 = dump_impl_location_t ())
464 : m_user_location (user_location
),
465 m_impl_location (impl_location
)
469 /* Construct from a location_t. This one is deprecated (since it doesn't
470 capture hotness information), and thus requires spelling out. */
471 static dump_location_t
472 from_location_t (location_t loc
,
473 const dump_impl_location_t
&impl_location
474 = dump_impl_location_t ())
476 return dump_location_t (dump_user_location_t::from_location_t (loc
),
480 const dump_user_location_t
&
481 get_user_location () const { return m_user_location
; }
483 const dump_impl_location_t
&
484 get_impl_location () const { return m_impl_location
; }
486 location_t
get_location_t () const
488 return m_user_location
.get_location_t ();
491 profile_count
get_count () const { return m_user_location
.get_count (); }
494 dump_user_location_t m_user_location
;
495 dump_impl_location_t m_impl_location
;
499 extern FILE *dump_begin (int, dump_flags_t
*, int part
=-1);
500 extern void dump_end (int, FILE *);
501 extern int opt_info_switch_p (const char *);
502 extern const char *dump_flag_name (int);
503 extern const kv_pair
<optgroup_flags_t
> optgroup_options
[];
505 /* Global variables used to communicate with passes. */
506 extern FILE *dump_file
;
507 extern dump_flags_t dump_flags
;
508 extern const char *dump_file_name
;
510 extern bool dumps_are_enabled
;
512 extern void set_dump_file (FILE *new_dump_file
);
514 /* Return true if any of the dumps is enabled, false otherwise. */
516 dump_enabled_p (void)
518 return dumps_are_enabled
;
521 /* The following API calls (which *don't* take a "FILE *")
522 write the output to zero or more locations.
524 Some destinations are written to immediately as dump_* calls
525 are made; for others, the output is consolidated into an "optinfo"
526 instance (with its own metadata), and only emitted once the optinfo
529 The destinations are:
531 (a) the "immediate" destinations:
532 (a.1) the active dump_file, if any
533 (a.2) the -fopt-info destination, if any
534 (b) the "optinfo" destinations, if any:
535 (b.1) as optimization records
537 dump_* (MSG_*) --> dumpfile.c --> items --> (a.1) dump_file
538 | `-> (a.2) alt_dump_file
541 `---> optinfo destinations
542 (b.1) optimization records
544 For optinfos, the dump_*_loc mark the beginning of an optinfo
545 instance: all subsequent dump_* calls are consolidated into
546 that optinfo, until the next dump_*_loc call (or a change in
547 dump scope, or a call to dumpfile_ensure_any_optinfo_are_flushed).
549 A group of dump_* calls should be guarded by:
551 if (dump_enabled_p ())
553 to minimize the work done for the common case where dumps
556 extern void dump_printf (const dump_metadata_t
&, const char *, ...)
557 ATTRIBUTE_GCC_DUMP_PRINTF (2, 3);
559 extern void dump_printf_loc (const dump_metadata_t
&, const dump_user_location_t
&,
561 ATTRIBUTE_GCC_DUMP_PRINTF (3, 0);
562 extern void dump_function (int phase
, tree fn
);
563 extern void dump_basic_block (dump_flags_t
, basic_block
, int);
564 extern void dump_generic_expr_loc (const dump_metadata_t
&,
565 const dump_user_location_t
&,
567 extern void dump_generic_expr (const dump_metadata_t
&, dump_flags_t
, tree
);
568 extern void dump_gimple_stmt_loc (const dump_metadata_t
&,
569 const dump_user_location_t
&,
570 dump_flags_t
, gimple
*, int);
571 extern void dump_gimple_stmt (const dump_metadata_t
&, dump_flags_t
, gimple
*, int);
572 extern void dump_gimple_expr_loc (const dump_metadata_t
&,
573 const dump_user_location_t
&,
574 dump_flags_t
, gimple
*, int);
575 extern void dump_gimple_expr (const dump_metadata_t
&, dump_flags_t
, gimple
*, int);
576 extern void dump_symtab_node (const dump_metadata_t
&, symtab_node
*);
578 template<unsigned int N
, typename C
>
579 void dump_dec (const dump_metadata_t
&, const poly_int
<N
, C
> &);
580 extern void dump_dec (dump_flags_t
, const poly_wide_int
&, signop
);
581 extern void dump_hex (dump_flags_t
, const poly_wide_int
&);
583 extern void dumpfile_ensure_any_optinfo_are_flushed ();
585 /* Managing nested scopes, so that dumps can express the call chain
586 leading to a dump message. */
588 extern unsigned int get_dump_scope_depth ();
589 extern void dump_begin_scope (const char *name
,
590 const dump_user_location_t
&user_location
,
591 const dump_impl_location_t
&impl_location
);
592 extern void dump_end_scope ();
594 /* Implementation detail of the AUTO_DUMP_SCOPE macro below.
596 A RAII-style class intended to make it easy to emit dump
597 information about entering and exiting a collection of nested
600 class auto_dump_scope
603 auto_dump_scope (const char *name
,
604 const dump_user_location_t
&user_location
,
605 const dump_impl_location_t
&impl_location
606 = dump_impl_location_t ())
608 if (dump_enabled_p ())
609 dump_begin_scope (name
, user_location
, impl_location
);
613 if (dump_enabled_p ())
618 /* A macro for calling:
619 dump_begin_scope (NAME, USER_LOC);
620 via an RAII object, thus printing "=== MSG ===\n" to the dumpfile etc,
623 once the object goes out of scope, thus capturing the nesting of
626 These scopes affect dump messages within them: dump messages at the
627 top level implicitly default to MSG_PRIORITY_USER_FACING, whereas those
628 in a nested scope implicitly default to MSG_PRIORITY_INTERNALS. */
630 #define AUTO_DUMP_SCOPE(NAME, USER_LOC) \
631 auto_dump_scope scope (NAME, USER_LOC)
633 extern void dump_function (int phase
, tree fn
);
634 extern void print_combine_total_stats (void);
635 extern bool enable_rtl_dump_file (void);
638 extern void dump_node (const_tree
, dump_flags_t
, FILE *);
641 extern void dump_combine_total_stats (FILE *);
643 extern void dump_bb (FILE *, basic_block
, int, dump_flags_t
);
649 /* A class for managing all of the various dump files used by the
650 optimization passes. */
659 /* Register a dumpfile.
661 TAKE_OWNERSHIP determines whether callee takes ownership of strings
662 SUFFIX, SWTCH, and GLOB. */
664 dump_register (const char *suffix
, const char *swtch
, const char *glob
,
665 dump_kind dkind
, optgroup_flags_t optgroup_flags
,
666 bool take_ownership
);
668 /* Allow languages and middle-end to register their dumps before the
669 optimization passes. */
673 /* Return the dump_file_info for the given phase. */
674 struct dump_file_info
*
675 get_dump_file_info (int phase
) const;
677 struct dump_file_info
*
678 get_dump_file_info_by_switch (const char *swtch
) const;
680 /* Return the name of the dump file for the given phase.
681 If the dump is not enabled, returns NULL. */
683 get_dump_file_name (int phase
, int part
= -1) const;
686 get_dump_file_name (struct dump_file_info
*dfi
, int part
= -1) const;
689 dump_switch_p (const char *arg
);
691 /* Start a dump for PHASE. Store user-supplied dump flags in
692 *FLAG_PTR. Return the number of streams opened. Set globals
693 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
694 set dump_flags appropriately for both pass dump stream and
695 -fopt-info stream. */
697 dump_start (int phase
, dump_flags_t
*flag_ptr
);
699 /* Finish a tree dump for PHASE and close associated dump streams. Also
700 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
702 dump_finish (int phase
);
705 dump_begin (int phase
, dump_flags_t
*flag_ptr
, int part
);
707 /* Returns nonzero if tree dump PHASE has been initialized. */
709 dump_initialized_p (int phase
) const;
711 /* Returns the switch name of PHASE. */
713 dump_flag_name (int phase
) const;
715 void register_pass (opt_pass
*pass
);
720 dump_phase_enabled_p (int phase
) const;
723 dump_switch_p_1 (const char *arg
, struct dump_file_info
*dfi
, bool doglob
);
726 dump_enable_all (dump_kind dkind
, dump_flags_t flags
, const char *filename
);
729 opt_info_enable_passes (optgroup_flags_t optgroup_flags
, dump_flags_t flags
,
730 const char *filename
);
732 bool update_dfi_for_opt_info (dump_file_info
*dfi
) const;
736 /* Dynamically registered dump files and switches. */
738 struct dump_file_info
*m_extra_dump_files
;
739 size_t m_extra_dump_files_in_use
;
740 size_t m_extra_dump_files_alloced
;
742 /* Stored values from -fopt-info, for handling passes created after
743 option-parsing (by backends and by plugins). */
744 optgroup_flags_t m_optgroup_flags
;
745 dump_flags_t m_optinfo_flags
;
746 char *m_optinfo_filename
;
748 /* Grant access to dump_enable_all. */
749 friend bool ::enable_rtl_dump_file (void);
751 /* Grant access to opt_info_enable_passes. */
752 friend int ::opt_info_switch_p (const char *arg
);
754 }; // class dump_manager
758 #endif /* GCC_DUMPFILE_H */