]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/dumpfile.h
Introduce dump_location_t
[thirdparty/gcc.git] / gcc / dumpfile.h
1 /* Definitions for the shared dumpfile.
2 Copyright (C) 2004-2018 Free Software Foundation, Inc.
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
24 #include "profile-count.h"
25
26 /* Different tree dump places. When you add new tree dump places,
27 extend the DUMP_FILES array in dumpfile.c. */
28 enum tree_dump_index
29 {
30 TDI_none, /* No dump */
31 TDI_cgraph, /* dump function call graph. */
32 TDI_inheritance, /* dump type inheritance graph. */
33 TDI_clones, /* dump IPA cloning decisions. */
34 TDI_original, /* dump each function before optimizing it */
35 TDI_gimple, /* dump each function after gimplifying it */
36 TDI_nested, /* dump each function after unnesting it */
37 TDI_lto_stream_out, /* dump information about lto streaming */
38
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. */
43
44 TDI_end
45 };
46
47 /* Enum used to distinguish dump files to types. */
48
49 enum dump_kind
50 {
51 DK_none,
52 DK_lang,
53 DK_tree,
54 DK_rtl,
55 DK_ipa
56 };
57
58 /* Bit masks to control dumping. Not all values are applicable to all
59 dumps. Add new ones at the end. When you define new values, extend
60 the DUMP_OPTIONS array in dumpfile.c. The TDF_* flags coexist with
61 MSG_* flags (for -fopt-info) and the bit values must be chosen to
62 allow that. */
63 enum dump_flag
64 {
65 /* Value of TDF_NONE is used just for bits filtered by TDF_KIND_MASK. */
66 TDF_NONE = 0,
67
68 /* Dump node addresses. */
69 TDF_ADDRESS = (1 << 0),
70
71 /* Don't go wild following links. */
72 TDF_SLIM = (1 << 1),
73
74 /* Don't unparse the function. */
75 TDF_RAW = (1 << 2),
76
77 /* Show more detailed info about each pass. */
78 TDF_DETAILS = (1 << 3),
79
80 /* Dump various statistics about each pass. */
81 TDF_STATS = (1 << 4),
82
83 /* Display basic block boundaries. */
84 TDF_BLOCKS = (1 << 5),
85
86 /* Display virtual operands. */
87 TDF_VOPS = (1 << 6),
88
89 /* Display statement line numbers. */
90 TDF_LINENO = (1 << 7),
91
92 /* Display decl UIDs. */
93 TDF_UID = (1 << 8),
94
95 /* Address of stmt. */
96 TDF_STMTADDR = (1 << 9),
97
98 /* A graph dump is being emitted. */
99 TDF_GRAPH = (1 << 10),
100
101 /* Display memory symbols in expr.
102 Implies TDF_VOPS. */
103 TDF_MEMSYMS = (1 << 11),
104
105 /* A flag to only print the RHS of a gimple stmt. */
106 TDF_RHS_ONLY = (1 << 12),
107
108 /* Display asm names of decls. */
109 TDF_ASMNAME = (1 << 13),
110
111 /* Display EH region number holding this gimple statement. */
112 TDF_EH = (1 << 14),
113
114 /* Omit UIDs from dumps. */
115 TDF_NOUID = (1 << 15),
116
117 /* Display alias information. */
118 TDF_ALIAS = (1 << 16),
119
120 /* Enumerate locals by uid. */
121 TDF_ENUMERATE_LOCALS = (1 << 17),
122
123 /* Dump cselib details. */
124 TDF_CSELIB = (1 << 18),
125
126 /* Dump SCEV details. */
127 TDF_SCEV = (1 << 19),
128
129 /* Dump in GIMPLE FE syntax */
130 TDF_GIMPLE = (1 << 20),
131
132 /* Dump folding details. */
133 TDF_FOLDING = (1 << 21),
134
135 /* -fopt-info optimized sources. */
136 MSG_OPTIMIZED_LOCATIONS = (1 << 22),
137
138 /* Missed opportunities. */
139 MSG_MISSED_OPTIMIZATION = (1 << 23),
140
141 /* General optimization info. */
142 MSG_NOTE = (1 << 24),
143
144 MSG_ALL = (MSG_OPTIMIZED_LOCATIONS
145 | MSG_MISSED_OPTIMIZATION
146 | MSG_NOTE),
147
148 /* Dumping for -fcompare-debug. */
149 TDF_COMPARE_DEBUG = (1 << 25)
150 };
151
152 /* Dump flags type. */
153
154 typedef enum dump_flag dump_flags_t;
155
156 static inline dump_flags_t
157 operator| (dump_flags_t lhs, dump_flags_t rhs)
158 {
159 return (dump_flags_t)((int)lhs | (int)rhs);
160 }
161
162 static inline dump_flags_t
163 operator& (dump_flags_t lhs, dump_flags_t rhs)
164 {
165 return (dump_flags_t)((int)lhs & (int)rhs);
166 }
167
168 static inline dump_flags_t
169 operator~ (dump_flags_t flags)
170 {
171 return (dump_flags_t)~((int)flags);
172 }
173
174 static inline dump_flags_t &
175 operator|= (dump_flags_t &lhs, dump_flags_t rhs)
176 {
177 lhs = (dump_flags_t)((int)lhs | (int)rhs);
178 return lhs;
179 }
180
181 static inline dump_flags_t &
182 operator&= (dump_flags_t &lhs, dump_flags_t rhs)
183 {
184 lhs = (dump_flags_t)((int)lhs & (int)rhs);
185 return lhs;
186 }
187
188 /* Flags to control high-level -fopt-info dumps. Usually these flags
189 define a group of passes. An optimization pass can be part of
190 multiple groups. */
191
192 enum optgroup_flag
193 {
194 OPTGROUP_NONE = 0,
195
196 /* IPA optimization passes */
197 OPTGROUP_IPA = (1 << 1),
198
199 /* Loop optimization passes */
200 OPTGROUP_LOOP = (1 << 2),
201
202 /* Inlining passes */
203 OPTGROUP_INLINE = (1 << 3),
204
205 /* OMP (Offloading and Multi Processing) transformations */
206 OPTGROUP_OMP = (1 << 4),
207
208 /* Vectorization passes */
209 OPTGROUP_VEC = (1 << 5),
210
211 /* All other passes */
212 OPTGROUP_OTHER = (1 << 6),
213
214 OPTGROUP_ALL = (OPTGROUP_IPA | OPTGROUP_LOOP | OPTGROUP_INLINE
215 | OPTGROUP_OMP | OPTGROUP_VEC | OPTGROUP_OTHER)
216 };
217
218 typedef enum optgroup_flag optgroup_flags_t;
219
220 static inline optgroup_flags_t
221 operator| (optgroup_flags_t lhs, optgroup_flags_t rhs)
222 {
223 return (optgroup_flags_t)((int)lhs | (int)rhs);
224 }
225
226 static inline optgroup_flags_t &
227 operator|= (optgroup_flags_t &lhs, optgroup_flags_t rhs)
228 {
229 lhs = (optgroup_flags_t)((int)lhs | (int)rhs);
230 return lhs;
231 }
232
233 /* Define a tree dump switch. */
234 struct dump_file_info
235 {
236 /* Suffix to give output file. */
237 const char *suffix;
238 /* Command line dump switch. */
239 const char *swtch;
240 /* Command line glob. */
241 const char *glob;
242 /* Filename for the pass-specific stream. */
243 const char *pfilename;
244 /* Filename for the -fopt-info stream. */
245 const char *alt_filename;
246 /* Pass-specific dump stream. */
247 FILE *pstream;
248 /* -fopt-info stream. */
249 FILE *alt_stream;
250 /* Dump kind. */
251 dump_kind dkind;
252 /* Dump flags. */
253 dump_flags_t pflags;
254 /* A pass flags for -fopt-info. */
255 dump_flags_t alt_flags;
256 /* Flags for -fopt-info given by a user. */
257 optgroup_flags_t optgroup_flags;
258 /* State of pass-specific stream. */
259 int pstate;
260 /* State of the -fopt-info stream. */
261 int alt_state;
262 /* Dump file number. */
263 int num;
264 /* Fields "suffix", "swtch", "glob" can be const strings,
265 or can be dynamically allocated, needing free. */
266 bool owns_strings;
267 /* When a given dump file is being initialized, this flag is set to true
268 if the corresponding TDF_graph dump file has also been initialized. */
269 bool graph_dump_initialized;
270 };
271
272 /* A class for describing where in the user's source that a dump message
273 relates to, with various constructors for convenience.
274 In particular, this lets us associate dump messages
275 with hotness information (e.g. from PGO), allowing them to
276 be prioritized by code hotness. */
277
278 class dump_user_location_t
279 {
280 public:
281 /* Default constructor, analogous to UNKNOWN_LOCATION. */
282 dump_user_location_t () : m_count (), m_loc (UNKNOWN_LOCATION) {}
283
284 /* Construct from a gimple statement (using its location and hotness). */
285 dump_user_location_t (gimple *stmt);
286
287 /* Construct from an RTL instruction (using its location and hotness). */
288 dump_user_location_t (rtx_insn *insn);
289
290 /* Construct from a location_t. This one is deprecated (since it doesn't
291 capture hotness information); it thus needs to be spelled out. */
292 static dump_user_location_t
293 from_location_t (location_t loc)
294 {
295 return dump_user_location_t (profile_count (), loc);
296 }
297
298 /* Construct from a function declaration. This one requires spelling out
299 to avoid accidentally constructing from other kinds of tree. */
300 static dump_user_location_t
301 from_function_decl (tree fndecl);
302
303 profile_count get_count () const { return m_count; }
304 location_t get_location_t () const { return m_loc; }
305
306 private:
307 /* Private ctor from count and location, for use by from_location_t. */
308 dump_user_location_t (profile_count count, location_t loc)
309 : m_count (count), m_loc (loc)
310 {}
311
312 profile_count m_count;
313 location_t m_loc;
314 };
315
316 /* A class for identifying where in the compiler's own source
317 (or a plugin) that a dump message is being emitted from. */
318
319 struct dump_impl_location_t
320 {
321 dump_impl_location_t (
322 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
323 const char *file = __builtin_FILE (),
324 int line = __builtin_LINE (),
325 const char *function = __builtin_FUNCTION ()
326 #else
327 const char *file = __FILE__,
328 int line = __LINE__,
329 const char *function = NULL
330 #endif
331 )
332 : m_file (file), m_line (line), m_function (function)
333 {}
334
335 const char *m_file;
336 int m_line;
337 const char *m_function;
338 };
339
340 /* A bundle of information for describing the location of a dump message:
341 (a) the source location and hotness within the user's code, together with
342 (b) the source location within the compiler/plugin.
343
344 The constructors use default parameters so that (b) gets sets up
345 automatically.
346
347 The upshot is that you can pass in e.g. a gimple * to dump_printf_loc,
348 and the dump call will automatically record where in GCC's source
349 code the dump was emitted from. */
350
351 class dump_location_t
352 {
353 public:
354 /* Default constructor, analogous to UNKNOWN_LOCATION. */
355 dump_location_t (const dump_impl_location_t &impl_location
356 = dump_impl_location_t ())
357 : m_user_location (dump_user_location_t ()),
358 m_impl_location (impl_location)
359 {
360 }
361
362 /* Construct from a gimple statement (using its location and hotness). */
363 dump_location_t (gimple *stmt,
364 const dump_impl_location_t &impl_location
365 = dump_impl_location_t ())
366 : m_user_location (dump_user_location_t (stmt)),
367 m_impl_location (impl_location)
368 {
369 }
370
371 /* Construct from an RTL instruction (using its location and hotness). */
372 dump_location_t (rtx_insn *insn,
373 const dump_impl_location_t &impl_location
374 = dump_impl_location_t ())
375 : m_user_location (dump_user_location_t (insn)),
376 m_impl_location (impl_location)
377 {
378 }
379
380 /* Construct from a dump_user_location_t. */
381 dump_location_t (const dump_user_location_t &user_location,
382 const dump_impl_location_t &impl_location
383 = dump_impl_location_t ())
384 : m_user_location (user_location),
385 m_impl_location (impl_location)
386 {
387 }
388
389 /* Construct from a location_t. This one is deprecated (since it doesn't
390 capture hotness information), and thus requires spelling out. */
391 static dump_location_t
392 from_location_t (location_t loc,
393 const dump_impl_location_t &impl_location
394 = dump_impl_location_t ())
395 {
396 return dump_location_t (dump_user_location_t::from_location_t (loc),
397 impl_location);
398 }
399
400 const dump_user_location_t &
401 get_user_location () const { return m_user_location; }
402
403 const dump_impl_location_t &
404 get_impl_location () const { return m_impl_location; }
405
406 location_t get_location_t () const
407 {
408 return m_user_location.get_location_t ();
409 }
410
411 profile_count get_count () const { return m_user_location.get_count (); }
412
413 private:
414 dump_user_location_t m_user_location;
415 dump_impl_location_t m_impl_location;
416 };
417
418 /* In dumpfile.c */
419 extern FILE *dump_begin (int, dump_flags_t *);
420 extern void dump_end (int, FILE *);
421 extern int opt_info_switch_p (const char *);
422 extern const char *dump_flag_name (int);
423 extern void dump_printf (dump_flags_t, const char *, ...) ATTRIBUTE_PRINTF_2;
424 extern void dump_printf_loc (dump_flags_t, const dump_location_t &,
425 const char *, ...) ATTRIBUTE_PRINTF_3;
426 extern void dump_function (int phase, tree fn);
427 extern void dump_basic_block (dump_flags_t, basic_block, int);
428 extern void dump_generic_expr (dump_flags_t, dump_flags_t, tree);
429 extern void dump_gimple_stmt_loc (dump_flags_t, const dump_location_t &,
430 dump_flags_t, gimple *, int);
431 extern void dump_gimple_stmt (dump_flags_t, dump_flags_t, gimple *, int);
432 extern void print_combine_total_stats (void);
433 extern bool enable_rtl_dump_file (void);
434
435 template<unsigned int N, typename C>
436 void dump_dec (dump_flags_t, const poly_int<N, C> &);
437
438 /* In tree-dump.c */
439 extern void dump_node (const_tree, dump_flags_t, FILE *);
440
441 /* In combine.c */
442 extern void dump_combine_total_stats (FILE *);
443 /* In cfghooks.c */
444 extern void dump_bb (FILE *, basic_block, int, dump_flags_t);
445
446 /* Global variables used to communicate with passes. */
447 extern FILE *dump_file;
448 extern FILE *alt_dump_file;
449 extern dump_flags_t dump_flags;
450 extern const char *dump_file_name;
451
452 /* Return true if any of the dumps is enabled, false otherwise. */
453 static inline bool
454 dump_enabled_p (void)
455 {
456 return (dump_file || alt_dump_file);
457 }
458
459 namespace gcc {
460
461 class dump_manager
462 {
463 public:
464
465 dump_manager ();
466 ~dump_manager ();
467
468 /* Register a dumpfile.
469
470 TAKE_OWNERSHIP determines whether callee takes ownership of strings
471 SUFFIX, SWTCH, and GLOB. */
472 unsigned int
473 dump_register (const char *suffix, const char *swtch, const char *glob,
474 dump_kind dkind, optgroup_flags_t optgroup_flags,
475 bool take_ownership);
476
477 /* Allow languages and middle-end to register their dumps before the
478 optimization passes. */
479 void
480 register_dumps ();
481
482 /* Return the dump_file_info for the given phase. */
483 struct dump_file_info *
484 get_dump_file_info (int phase) const;
485
486 struct dump_file_info *
487 get_dump_file_info_by_switch (const char *swtch) const;
488
489 /* Return the name of the dump file for the given phase.
490 If the dump is not enabled, returns NULL. */
491 char *
492 get_dump_file_name (int phase) const;
493
494 char *
495 get_dump_file_name (struct dump_file_info *dfi) const;
496
497 int
498 dump_switch_p (const char *arg);
499
500 /* Start a dump for PHASE. Store user-supplied dump flags in
501 *FLAG_PTR. Return the number of streams opened. Set globals
502 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
503 set dump_flags appropriately for both pass dump stream and
504 -fopt-info stream. */
505 int
506 dump_start (int phase, dump_flags_t *flag_ptr);
507
508 /* Finish a tree dump for PHASE and close associated dump streams. Also
509 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
510 void
511 dump_finish (int phase);
512
513 FILE *
514 dump_begin (int phase, dump_flags_t *flag_ptr);
515
516 /* Returns nonzero if tree dump PHASE has been initialized. */
517 int
518 dump_initialized_p (int phase) const;
519
520 /* Returns the switch name of PHASE. */
521 const char *
522 dump_flag_name (int phase) const;
523
524 private:
525
526 int
527 dump_phase_enabled_p (int phase) const;
528
529 int
530 dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob);
531
532 int
533 dump_enable_all (dump_kind dkind, dump_flags_t flags, const char *filename);
534
535 int
536 opt_info_enable_passes (optgroup_flags_t optgroup_flags, dump_flags_t flags,
537 const char *filename);
538
539 private:
540
541 /* Dynamically registered dump files and switches. */
542 int m_next_dump;
543 struct dump_file_info *m_extra_dump_files;
544 size_t m_extra_dump_files_in_use;
545 size_t m_extra_dump_files_alloced;
546
547 /* Grant access to dump_enable_all. */
548 friend bool ::enable_rtl_dump_file (void);
549
550 /* Grant access to opt_info_enable_passes. */
551 friend int ::opt_info_switch_p (const char *arg);
552
553 }; // class dump_manager
554
555 } // namespace gcc
556
557 #endif /* GCC_DUMPFILE_H */