2017-05-11 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / gcc / dumpfile.h
blob19c6d3ec90e35fe2c5cc50909aa9b88b7b736613
1 /* Definitions for the shared dumpfile.
2 Copyright (C) 2004-2017 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)
9 any later version.
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
25 /* Different tree dump places. When you add new tree dump places,
26 extend the DUMP_FILES array in dumpfile.c. */
27 enum tree_dump_index
29 TDI_none, /* No dump */
30 TDI_cgraph, /* dump function call graph. */
31 TDI_inheritance, /* dump type inheritance graph. */
32 TDI_clones, /* dump IPA cloning decisions. */
33 TDI_tu, /* dump the whole translation unit. */
34 TDI_class, /* dump class hierarchy. */
35 TDI_original, /* dump each function before optimizing it */
36 TDI_generic, /* dump each function after genericizing it */
37 TDI_nested, /* dump each function after unnesting it */
39 TDI_lang_all, /* enable all the language dumps. */
40 TDI_tree_all, /* enable all the GENERIC/GIMPLE dumps. */
41 TDI_rtl_all, /* enable all the RTL dumps. */
42 TDI_ipa_all, /* enable all the IPA dumps. */
44 TDI_end
47 /* Bit masks to control dumping. Not all values are applicable to all
48 dumps. Add new ones at the end. When you define new values, extend
49 the DUMP_OPTIONS array in dumpfile.c. The TDF_* flags coexist with
50 MSG_* flags (for -fopt-info) and the bit values must be chosen to
51 allow that. */
52 #define TDF_LANG 0 /* is a lang-specific dump. */
53 #define TDF_TREE 1 /* is a tree dump */
54 #define TDF_RTL 2 /* is a RTL dump */
55 #define TDF_IPA 3 /* is an IPA dump */
56 #define TDF_KIND_MASK 3
57 #define TDF_KIND(X) ((X) & TDF_KIND_MASK)
58 #define TDF_FLAGS(X) ((X) & ~TDF_KIND_MASK)
60 /* Bit 2 unused, available for hire. */
61 #define TDF_ADDRESS (1 << 3) /* dump node addresses */
62 #define TDF_SLIM (1 << 4) /* don't go wild following links */
63 #define TDF_RAW (1 << 5) /* don't unparse the function */
64 #define TDF_DETAILS (1 << 6) /* show more detailed info about
65 each pass */
66 #define TDF_STATS (1 << 7) /* dump various statistics about
67 each pass */
68 #define TDF_BLOCKS (1 << 8) /* display basic block boundaries */
69 #define TDF_VOPS (1 << 9) /* display virtual operands */
70 #define TDF_LINENO (1 << 10) /* display statement line numbers */
71 #define TDF_UID (1 << 11) /* display decl UIDs */
73 #define TDF_STMTADDR (1 << 12) /* Address of stmt. */
75 #define TDF_GRAPH (1 << 13) /* a graph dump is being emitted */
76 #define TDF_MEMSYMS (1 << 14) /* display memory symbols in expr.
77 Implies TDF_VOPS. */
79 #define TDF_DIAGNOSTIC (1 << 15) /* A dump to be put in a diagnostic
80 message. */
81 #define TDF_VERBOSE (1 << 16) /* A dump that uses the full tree
82 dumper to print stmts. */
83 #define TDF_RHS_ONLY (1 << 17) /* a flag to only print the RHS of
84 a gimple stmt. */
85 #define TDF_ASMNAME (1 << 18) /* display asm names of decls */
86 #define TDF_EH (1 << 19) /* display EH region number
87 holding this gimple statement. */
88 #define TDF_NOUID (1 << 20) /* omit UIDs from dumps. */
89 #define TDF_ALIAS (1 << 21) /* display alias information */
90 #define TDF_ENUMERATE_LOCALS (1 << 22) /* Enumerate locals by uid. */
91 #define TDF_CSELIB (1 << 23) /* Dump cselib details. */
92 #define TDF_SCEV (1 << 24) /* Dump SCEV details. */
93 #define TDF_COMMENT (1 << 25) /* Dump lines with prefix ";;" */
94 #define TDF_GIMPLE (1 << 26) /* Dump in GIMPLE FE syntax */
95 #define MSG_OPTIMIZED_LOCATIONS (1 << 27) /* -fopt-info optimized sources */
96 #define MSG_MISSED_OPTIMIZATION (1 << 28) /* missed opportunities */
97 #define MSG_NOTE (1 << 29) /* general optimization info */
98 #define MSG_ALL (MSG_OPTIMIZED_LOCATIONS | MSG_MISSED_OPTIMIZATION \
99 | MSG_NOTE)
102 /* Flags to control high-level -fopt-info dumps. Usually these flags
103 define a group of passes. An optimization pass can be part of
104 multiple groups. */
105 #define OPTGROUP_NONE (0)
106 #define OPTGROUP_IPA (1 << 1) /* IPA optimization passes */
107 #define OPTGROUP_LOOP (1 << 2) /* Loop optimization passes */
108 #define OPTGROUP_INLINE (1 << 3) /* Inlining passes */
109 #define OPTGROUP_OMP (1 << 4) /* OMP (Offloading and Multi
110 Processing) transformations */
111 #define OPTGROUP_VEC (1 << 5) /* Vectorization passes */
112 #define OPTGROUP_OTHER (1 << 6) /* All other passes */
113 #define OPTGROUP_ALL (OPTGROUP_IPA | OPTGROUP_LOOP | OPTGROUP_INLINE \
114 | OPTGROUP_OMP | OPTGROUP_VEC | OPTGROUP_OTHER)
116 /* Define a tree dump switch. */
117 struct dump_file_info
119 const char *suffix; /* suffix to give output file. */
120 const char *swtch; /* command line dump switch */
121 const char *glob; /* command line glob */
122 const char *pfilename; /* filename for the pass-specific stream */
123 const char *alt_filename; /* filename for the -fopt-info stream */
124 FILE *pstream; /* pass-specific dump stream */
125 FILE *alt_stream; /* -fopt-info stream */
126 int pflags; /* dump flags */
127 int optgroup_flags; /* optgroup flags for -fopt-info */
128 int alt_flags; /* flags for opt-info */
129 int pstate; /* state of pass-specific stream */
130 int alt_state; /* state of the -fopt-info stream */
131 int num; /* dump file number */
132 bool owns_strings; /* fields "suffix", "swtch", "glob" can be
133 const strings, or can be dynamically
134 allocated, needing free. */
135 bool graph_dump_initialized; /* When a given dump file is being
136 initialized, this flag is set to
137 true if the corresponding TDF_graph
138 dump file has also been
139 initialized. */
142 /* In dumpfile.c */
143 extern FILE *dump_begin (int, int *);
144 extern void dump_end (int, FILE *);
145 extern int opt_info_switch_p (const char *);
146 extern const char *dump_flag_name (int);
147 extern void dump_printf (int, const char *, ...) ATTRIBUTE_PRINTF_2;
148 extern void dump_printf_loc (int, source_location,
149 const char *, ...) ATTRIBUTE_PRINTF_3;
150 extern void dump_function (int phase, tree fn);
151 extern void dump_basic_block (int, basic_block, int);
152 extern void dump_generic_expr_loc (int, source_location, int, tree);
153 extern void dump_generic_expr (int, int, tree);
154 extern void dump_gimple_stmt_loc (int, source_location, int, gimple *, int);
155 extern void dump_gimple_stmt (int, int, gimple *, int);
156 extern void print_combine_total_stats (void);
157 extern bool enable_rtl_dump_file (void);
159 /* In tree-dump.c */
160 extern void dump_node (const_tree, int, FILE *);
162 /* In combine.c */
163 extern void dump_combine_total_stats (FILE *);
164 /* In cfghooks.c */
165 extern void dump_bb (FILE *, basic_block, int, int);
167 /* Global variables used to communicate with passes. */
168 extern FILE *dump_file;
169 extern FILE *alt_dump_file;
170 extern int dump_flags;
171 extern const char *dump_file_name;
173 /* Return true if any of the dumps is enabled, false otherwise. */
174 static inline bool
175 dump_enabled_p (void)
177 return (dump_file || alt_dump_file);
180 namespace gcc {
182 class dump_manager
184 public:
186 dump_manager ();
187 ~dump_manager ();
189 /* Register a dumpfile.
191 TAKE_OWNERSHIP determines whether callee takes ownership of strings
192 SUFFIX, SWTCH, and GLOB. */
193 unsigned int
194 dump_register (const char *suffix, const char *swtch, const char *glob,
195 int flags, int optgroup_flags,
196 bool take_ownership);
198 /* Return the dump_file_info for the given phase. */
199 struct dump_file_info *
200 get_dump_file_info (int phase) const;
202 struct dump_file_info *
203 get_dump_file_info_by_switch (const char *swtch) const;
205 /* Return the name of the dump file for the given phase.
206 If the dump is not enabled, returns NULL. */
207 char *
208 get_dump_file_name (int phase) const;
210 char *
211 get_dump_file_name (struct dump_file_info *dfi) const;
214 dump_switch_p (const char *arg);
216 /* Start a dump for PHASE. Store user-supplied dump flags in
217 *FLAG_PTR. Return the number of streams opened. Set globals
218 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
219 set dump_flags appropriately for both pass dump stream and
220 -fopt-info stream. */
222 dump_start (int phase, int *flag_ptr);
224 /* Finish a tree dump for PHASE and close associated dump streams. Also
225 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
226 void
227 dump_finish (int phase);
229 FILE *
230 dump_begin (int phase, int *flag_ptr);
232 /* Returns nonzero if tree dump PHASE has been initialized. */
234 dump_initialized_p (int phase) const;
236 /* Returns the switch name of PHASE. */
237 const char *
238 dump_flag_name (int phase) const;
240 private:
243 dump_phase_enabled_p (int phase) const;
246 dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob);
249 dump_enable_all (int flags, const char *filename);
252 opt_info_enable_passes (int optgroup_flags, int flags, const char *filename);
254 private:
256 /* Dynamically registered dump files and switches. */
257 int m_next_dump;
258 struct dump_file_info *m_extra_dump_files;
259 size_t m_extra_dump_files_in_use;
260 size_t m_extra_dump_files_alloced;
262 /* Grant access to dump_enable_all. */
263 friend bool ::enable_rtl_dump_file (void);
265 /* Grant access to opt_info_enable_passes. */
266 friend int ::opt_info_switch_p (const char *arg);
268 }; // class dump_manager
270 } // namespace gcc
272 #endif /* GCC_DUMPFILE_H */