gcov: make profile merging smarter
[official-gcc.git] / gcc / dumpfile.c
blobe6ead5debe5603a4ee22a68555e0eac8f6fe22d2
1 /* Dump infrastructure for optimizations and intermediate representation.
2 Copyright (C) 2012-2021 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 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/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "options.h"
24 #include "tree.h"
25 #include "gimple-pretty-print.h"
26 #include "diagnostic-core.h"
27 #include "dumpfile.h"
28 #include "context.h"
29 #include "profile-count.h"
30 #include "tree-cfg.h"
31 #include "langhooks.h"
32 #include "backend.h" /* for gimple.h. */
33 #include "gimple.h" /* for dump_user_location_t ctor. */
34 #include "rtl.h" /* for dump_user_location_t ctor. */
35 #include "selftest.h"
36 #include "optinfo.h"
37 #include "dump-context.h"
38 #include "cgraph.h"
39 #include "tree-pass.h" /* for "current_pass". */
40 #include "optinfo-emit-json.h"
41 #include "stringpool.h" /* for get_identifier. */
42 #include "spellcheck.h"
44 /* If non-NULL, return one past-the-end of the matching SUBPART of
45 the WHOLE string. */
46 #define skip_leading_substring(whole, part) \
47 (strncmp (whole, part, strlen (part)) ? NULL : whole + strlen (part))
49 static dump_flags_t pflags; /* current dump_flags */
51 static void dump_loc (dump_flags_t, FILE *, location_t);
53 /* Current -fopt-info output stream, if any, and flags. */
54 static FILE *alt_dump_file = NULL;
55 static dump_flags_t alt_flags;
57 static FILE *dump_open_alternate_stream (struct dump_file_info *);
59 /* These are currently used for communicating between passes.
60 However, instead of accessing them directly, the passes can use
61 dump_printf () for dumps. */
62 FILE *dump_file = NULL;
63 const char *dump_file_name;
64 dump_flags_t dump_flags;
65 bool dumps_are_enabled = false;
68 /* Set global "dump_file" to NEW_DUMP_FILE, refreshing the "dumps_are_enabled"
69 global. */
71 void
72 set_dump_file (FILE *new_dump_file)
74 dumpfile_ensure_any_optinfo_are_flushed ();
75 dump_file = new_dump_file;
76 dump_context::get ().refresh_dumps_are_enabled ();
79 /* Set "alt_dump_file" to NEW_ALT_DUMP_FILE, refreshing the "dumps_are_enabled"
80 global. */
82 static void
83 set_alt_dump_file (FILE *new_alt_dump_file)
85 dumpfile_ensure_any_optinfo_are_flushed ();
86 alt_dump_file = new_alt_dump_file;
87 dump_context::get ().refresh_dumps_are_enabled ();
90 #define DUMP_FILE_INFO(suffix, swtch, dkind, num) \
91 {suffix, swtch, NULL, NULL, NULL, NULL, NULL, dkind, TDF_NONE, TDF_NONE, \
92 OPTGROUP_NONE, 0, 0, num, false, false}
94 /* Table of tree dump switches. This must be consistent with the
95 TREE_DUMP_INDEX enumeration in dumpfile.h. */
96 static struct dump_file_info dump_files[TDI_end] =
98 DUMP_FILE_INFO (NULL, NULL, DK_none, 0),
99 DUMP_FILE_INFO (".cgraph", "ipa-cgraph", DK_ipa, 0),
100 DUMP_FILE_INFO (".type-inheritance", "ipa-type-inheritance", DK_ipa, 0),
101 DUMP_FILE_INFO (".ipa-clones", "ipa-clones", DK_ipa, 0),
102 DUMP_FILE_INFO (".original", "tree-original", DK_tree, 0),
103 DUMP_FILE_INFO (".gimple", "tree-gimple", DK_tree, 0),
104 DUMP_FILE_INFO (".nested", "tree-nested", DK_tree, 0),
105 DUMP_FILE_INFO (".lto-stream-out", "ipa-lto-stream-out", DK_ipa, 0),
106 DUMP_FILE_INFO (".profile-report", "profile-report", DK_ipa, 0),
107 #define FIRST_AUTO_NUMBERED_DUMP 1
108 #define FIRST_ME_AUTO_NUMBERED_DUMP 5
110 DUMP_FILE_INFO (NULL, "lang-all", DK_lang, 0),
111 DUMP_FILE_INFO (NULL, "tree-all", DK_tree, 0),
112 DUMP_FILE_INFO (NULL, "rtl-all", DK_rtl, 0),
113 DUMP_FILE_INFO (NULL, "ipa-all", DK_ipa, 0),
116 /* Table of dump options. This must be consistent with the TDF_* flags
117 in dumpfile.h and opt_info_options below. */
118 static const kv_pair<dump_flags_t> dump_options[] =
120 {"none", TDF_NONE},
121 {"address", TDF_ADDRESS},
122 {"asmname", TDF_ASMNAME},
123 {"slim", TDF_SLIM},
124 {"raw", TDF_RAW},
125 {"graph", TDF_GRAPH},
126 {"details", (TDF_DETAILS | MSG_OPTIMIZED_LOCATIONS
127 | MSG_MISSED_OPTIMIZATION
128 | MSG_NOTE)},
129 {"cselib", TDF_CSELIB},
130 {"stats", TDF_STATS},
131 {"blocks", TDF_BLOCKS},
132 {"vops", TDF_VOPS},
133 {"lineno", TDF_LINENO},
134 {"uid", TDF_UID},
135 {"stmtaddr", TDF_STMTADDR},
136 {"memsyms", TDF_MEMSYMS},
137 {"eh", TDF_EH},
138 {"alias", TDF_ALIAS},
139 {"nouid", TDF_NOUID},
140 {"enumerate_locals", TDF_ENUMERATE_LOCALS},
141 {"scev", TDF_SCEV},
142 {"gimple", TDF_GIMPLE},
143 {"folding", TDF_FOLDING},
144 {"optimized", MSG_OPTIMIZED_LOCATIONS},
145 {"missed", MSG_MISSED_OPTIMIZATION},
146 {"note", MSG_NOTE},
147 {"optall", MSG_ALL_KINDS},
148 {"threading", TDF_THREADING},
149 {"all", dump_flags_t (TDF_ALL_VALUES
150 & ~(TDF_RAW | TDF_SLIM | TDF_LINENO | TDF_GRAPH
151 | TDF_STMTADDR | TDF_RHS_ONLY | TDF_NOUID
152 | TDF_ENUMERATE_LOCALS | TDF_SCEV | TDF_GIMPLE))},
153 {NULL, TDF_NONE}
156 /* A subset of the dump_options table which is used for -fopt-info
157 types. This must be consistent with the MSG_* flags in dumpfile.h.
159 static const kv_pair<dump_flags_t> optinfo_verbosity_options[] =
161 {"optimized", MSG_OPTIMIZED_LOCATIONS},
162 {"missed", MSG_MISSED_OPTIMIZATION},
163 {"note", MSG_NOTE},
164 {"all", MSG_ALL_KINDS},
165 {"internals", MSG_PRIORITY_INTERNALS},
166 {NULL, TDF_NONE}
169 /* Flags used for -fopt-info groups. */
170 const kv_pair<optgroup_flags_t> optgroup_options[] =
172 {"ipa", OPTGROUP_IPA},
173 {"loop", OPTGROUP_LOOP},
174 {"inline", OPTGROUP_INLINE},
175 {"omp", OPTGROUP_OMP},
176 {"vec", OPTGROUP_VEC},
177 {"optall", OPTGROUP_ALL},
178 {NULL, OPTGROUP_NONE}
181 gcc::dump_manager::dump_manager ():
182 m_next_dump (FIRST_AUTO_NUMBERED_DUMP),
183 m_extra_dump_files (NULL),
184 m_extra_dump_files_in_use (0),
185 m_extra_dump_files_alloced (0),
186 m_optgroup_flags (OPTGROUP_NONE),
187 m_optinfo_flags (TDF_NONE),
188 m_optinfo_filename (NULL)
192 gcc::dump_manager::~dump_manager ()
194 free (m_optinfo_filename);
195 for (size_t i = 0; i < m_extra_dump_files_in_use; i++)
197 dump_file_info *dfi = &m_extra_dump_files[i];
198 /* suffix, swtch, glob are statically allocated for the entries
199 in dump_files, and for statistics, but are dynamically allocated
200 for those for passes. */
201 if (dfi->owns_strings)
203 XDELETEVEC (const_cast <char *> (dfi->suffix));
204 XDELETEVEC (const_cast <char *> (dfi->swtch));
205 XDELETEVEC (const_cast <char *> (dfi->glob));
207 /* These, if non-NULL, are always dynamically allocated. */
208 XDELETEVEC (const_cast <char *> (dfi->pfilename));
209 XDELETEVEC (const_cast <char *> (dfi->alt_filename));
211 XDELETEVEC (m_extra_dump_files);
214 unsigned int
215 gcc::dump_manager::
216 dump_register (const char *suffix, const char *swtch, const char *glob,
217 dump_kind dkind, optgroup_flags_t optgroup_flags,
218 bool take_ownership)
220 int num = m_next_dump++;
222 size_t count = m_extra_dump_files_in_use++;
224 if (count >= m_extra_dump_files_alloced)
226 if (m_extra_dump_files_alloced == 0)
227 m_extra_dump_files_alloced = 512;
228 else
229 m_extra_dump_files_alloced *= 2;
230 m_extra_dump_files = XRESIZEVEC (struct dump_file_info,
231 m_extra_dump_files,
232 m_extra_dump_files_alloced);
234 /* Construct a new object in the space allocated above. */
235 new (m_extra_dump_files + count) dump_file_info ();
237 else
239 /* Zero out the already constructed object. */
240 m_extra_dump_files[count] = dump_file_info ();
243 m_extra_dump_files[count].suffix = suffix;
244 m_extra_dump_files[count].swtch = swtch;
245 m_extra_dump_files[count].glob = glob;
246 m_extra_dump_files[count].dkind = dkind;
247 m_extra_dump_files[count].optgroup_flags = optgroup_flags;
248 m_extra_dump_files[count].num = num;
249 m_extra_dump_files[count].owns_strings = take_ownership;
251 return count + TDI_end;
255 /* Allow languages and middle-end to register their dumps before the
256 optimization passes. */
258 void
259 gcc::dump_manager::
260 register_dumps ()
262 lang_hooks.register_dumps (this);
263 /* If this assert fails, some FE registered more than
264 FIRST_ME_AUTO_NUMBERED_DUMP - FIRST_AUTO_NUMBERED_DUMP
265 dump files. Bump FIRST_ME_AUTO_NUMBERED_DUMP accordingly. */
266 gcc_assert (m_next_dump <= FIRST_ME_AUTO_NUMBERED_DUMP);
267 m_next_dump = FIRST_ME_AUTO_NUMBERED_DUMP;
268 dump_files[TDI_original].num = m_next_dump++;
269 dump_files[TDI_gimple].num = m_next_dump++;
270 dump_files[TDI_nested].num = m_next_dump++;
274 /* Return the dump_file_info for the given phase. */
276 struct dump_file_info *
277 gcc::dump_manager::
278 get_dump_file_info (int phase) const
280 if (phase < TDI_end)
281 return &dump_files[phase];
282 else if ((size_t) (phase - TDI_end) >= m_extra_dump_files_in_use)
283 return NULL;
284 else
285 return m_extra_dump_files + (phase - TDI_end);
288 /* Locate the dump_file_info with swtch equal to SWTCH,
289 or return NULL if no such dump_file_info exists. */
291 struct dump_file_info *
292 gcc::dump_manager::
293 get_dump_file_info_by_switch (const char *swtch) const
295 for (unsigned i = 0; i < m_extra_dump_files_in_use; i++)
296 if (strcmp (m_extra_dump_files[i].swtch, swtch) == 0)
297 return &m_extra_dump_files[i];
299 /* Not found. */
300 return NULL;
304 /* Return the name of the dump file for the given phase.
305 The caller is responsible for calling free on the returned
306 buffer.
307 If the dump is not enabled, returns NULL. */
309 char *
310 gcc::dump_manager::
311 get_dump_file_name (int phase, int part) const
313 struct dump_file_info *dfi;
315 if (phase == TDI_none)
316 return NULL;
318 dfi = get_dump_file_info (phase);
320 return get_dump_file_name (dfi, part);
323 /* Return the name of the dump file for the given dump_file_info.
324 The caller is responsible for calling free on the returned
325 buffer.
326 If the dump is not enabled, returns NULL. */
328 char *
329 gcc::dump_manager::
330 get_dump_file_name (struct dump_file_info *dfi, int part) const
332 char dump_id[10];
334 gcc_assert (dfi);
336 if (dfi->pstate == 0)
337 return NULL;
339 /* If available, use the command line dump filename. */
340 if (dfi->pfilename)
341 return xstrdup (dfi->pfilename);
343 if (dfi->num < 0)
344 dump_id[0] = '\0';
345 else
347 /* (null), LANG, TREE, RTL, IPA. */
348 char suffix = " ltri"[dfi->dkind];
350 if (snprintf (dump_id, sizeof (dump_id), ".%03d%c", dfi->num, suffix) < 0)
351 dump_id[0] = '\0';
354 if (part != -1)
356 char part_id[8];
357 snprintf (part_id, sizeof (part_id), ".%i", part);
358 return concat (dump_base_name, dump_id, part_id, dfi->suffix, NULL);
360 else
361 return concat (dump_base_name, dump_id, dfi->suffix, NULL);
364 /* Open a dump file called FILENAME. Some filenames are special and
365 refer to the standard streams. TRUNC indicates whether this is the
366 first open (so the file should be truncated, rather than appended).
367 An error message is emitted in the event of failure. */
369 static FILE *
370 dump_open (const char *filename, bool trunc)
372 if (strcmp ("stderr", filename) == 0)
373 return stderr;
375 if (strcmp ("stdout", filename) == 0
376 || strcmp ("-", filename) == 0)
377 return stdout;
379 FILE *stream = fopen (filename, trunc ? "w" : "a");
381 if (!stream)
382 error ("could not open dump file %qs: %m", filename);
383 return stream;
386 /* For a given DFI, open an alternate dump filename (which could also
387 be a standard stream such as stdout/stderr). If the alternate dump
388 file cannot be opened, return NULL. */
390 static FILE *
391 dump_open_alternate_stream (struct dump_file_info *dfi)
393 if (!dfi->alt_filename)
394 return NULL;
396 if (dfi->alt_stream)
397 return dfi->alt_stream;
399 FILE *stream = dump_open (dfi->alt_filename, dfi->alt_state < 0);
401 if (stream)
402 dfi->alt_state = 1;
404 return stream;
407 /* Construct a dump_user_location_t from STMT (using its location and
408 hotness). */
410 dump_user_location_t::dump_user_location_t (const gimple *stmt)
411 : m_count (), m_loc (UNKNOWN_LOCATION)
413 if (stmt)
415 if (stmt->bb)
416 m_count = stmt->bb->count;
417 m_loc = gimple_location (stmt);
421 /* Construct a dump_user_location_t from an RTL instruction (using its
422 location and hotness). */
424 dump_user_location_t::dump_user_location_t (const rtx_insn *insn)
425 : m_count (), m_loc (UNKNOWN_LOCATION)
427 if (insn)
429 basic_block bb = BLOCK_FOR_INSN (insn);
430 if (bb)
431 m_count = bb->count;
432 m_loc = INSN_LOCATION (insn);
436 /* Construct from a function declaration. This one requires spelling out
437 to avoid accidentally constructing from other kinds of tree. */
439 dump_user_location_t
440 dump_user_location_t::from_function_decl (tree fndecl)
442 gcc_assert (fndecl);
444 // FIXME: profile count for function?
445 return dump_user_location_t (profile_count (),
446 DECL_SOURCE_LOCATION (fndecl));
449 /* Extract the MSG_* component from DUMP_KIND and return a string for use
450 as a prefix to dump messages.
451 These match the strings in optinfo_verbosity_options and thus the
452 "OPTIONS" within "-fopt-info-OPTIONS". */
454 static const char *
455 kind_as_string (dump_flags_t dump_kind)
457 switch (dump_kind & MSG_ALL_KINDS)
459 default:
460 gcc_unreachable ();
461 case MSG_OPTIMIZED_LOCATIONS:
462 return "optimized";
463 case MSG_MISSED_OPTIMIZATION:
464 return "missed";
465 case MSG_NOTE:
466 return "note";
470 /* Print source location on DFILE if enabled. */
472 static void
473 dump_loc (dump_flags_t dump_kind, FILE *dfile, location_t loc)
475 if (dump_kind)
477 if (LOCATION_LOCUS (loc) > BUILTINS_LOCATION)
478 fprintf (dfile, "%s:%d:%d: ", LOCATION_FILE (loc),
479 LOCATION_LINE (loc), LOCATION_COLUMN (loc));
480 else if (current_function_decl)
481 fprintf (dfile, "%s:%d:%d: ",
482 DECL_SOURCE_FILE (current_function_decl),
483 DECL_SOURCE_LINE (current_function_decl),
484 DECL_SOURCE_COLUMN (current_function_decl));
485 fprintf (dfile, "%s: ", kind_as_string (dump_kind));
486 /* Indentation based on scope depth. */
487 fprintf (dfile, "%*s", get_dump_scope_depth (), "");
491 /* Print source location to PP if enabled. */
493 static void
494 dump_loc (dump_flags_t dump_kind, pretty_printer *pp, location_t loc)
496 /* Disable warnings about missing quoting in GCC diagnostics for
497 the pp_printf calls. Their format strings aren't used to format
498 diagnostics so don't need to follow GCC diagnostic conventions. */
499 #if __GNUC__ >= 10
500 # pragma GCC diagnostic push
501 # pragma GCC diagnostic ignored "-Wformat-diag"
502 #endif
504 if (dump_kind)
506 if (LOCATION_LOCUS (loc) > BUILTINS_LOCATION)
507 pp_printf (pp, "%s:%d:%d: ", LOCATION_FILE (loc),
508 LOCATION_LINE (loc), LOCATION_COLUMN (loc));
509 else if (current_function_decl)
510 pp_printf (pp, "%s:%d:%d: ",
511 DECL_SOURCE_FILE (current_function_decl),
512 DECL_SOURCE_LINE (current_function_decl),
513 DECL_SOURCE_COLUMN (current_function_decl));
514 pp_printf (pp, "%s: ", kind_as_string (dump_kind));
515 /* Indentation based on scope depth. */
516 for (unsigned i = 0; i < get_dump_scope_depth (); i++)
517 pp_character (pp, ' ');
520 #if __GNUC__ >= 10
521 # pragma GCC diagnostic pop
522 #endif
525 /* Implementation of dump_context member functions. */
527 /* dump_context's dtor. */
529 dump_context::~dump_context ()
531 delete m_pending;
534 void
535 dump_context::set_json_writer (optrecord_json_writer *writer)
537 delete m_json_writer;
538 m_json_writer = writer;
541 /* Perform cleanup activity for -fsave-optimization-record.
542 Currently, the file is written out here in one go, before cleaning
543 up. */
545 void
546 dump_context::finish_any_json_writer ()
548 if (!m_json_writer)
549 return;
551 m_json_writer->write ();
552 delete m_json_writer;
553 m_json_writer = NULL;
556 /* Update the "dumps_are_enabled" global; to be called whenever dump_file
557 or alt_dump_file change, or when changing dump_context in selftests. */
559 void
560 dump_context::refresh_dumps_are_enabled ()
562 dumps_are_enabled = (dump_file || alt_dump_file || optinfo_enabled_p ()
563 || m_test_pp);
566 /* Determine if a message of kind DUMP_KIND and at the current scope depth
567 should be printed.
569 Only show messages that match FILTER both on their kind *and*
570 their priority. */
572 bool
573 dump_context::apply_dump_filter_p (dump_flags_t dump_kind,
574 dump_flags_t filter) const
576 /* Few messages, if any, have an explicit MSG_PRIORITY.
577 If DUMP_KIND does, we'll use it.
578 Otherwise, generate an implicit priority value for the message based
579 on the current scope depth.
580 Messages at the top-level scope are MSG_PRIORITY_USER_FACING,
581 whereas those in nested scopes are MSG_PRIORITY_INTERNALS. */
582 if (!(dump_kind & MSG_ALL_PRIORITIES))
584 dump_flags_t implicit_priority
585 = (m_scope_depth > 0
586 ? MSG_PRIORITY_INTERNALS
587 : MSG_PRIORITY_USER_FACING);
588 dump_kind |= implicit_priority;
591 return (dump_kind & (filter & MSG_ALL_KINDS)
592 && dump_kind & (filter & MSG_ALL_PRIORITIES));
595 /* Print LOC to the appropriate dump destinations, given DUMP_KIND.
596 If optinfos are enabled, begin a new optinfo. */
598 void
599 dump_context::dump_loc (const dump_metadata_t &metadata,
600 const dump_user_location_t &loc)
602 end_any_optinfo ();
604 dump_loc_immediate (metadata.get_dump_flags (), loc);
606 if (optinfo_enabled_p ())
607 begin_next_optinfo (metadata, loc);
610 /* As dump_loc above, but without starting a new optinfo. */
612 void
613 dump_context::dump_loc_immediate (dump_flags_t dump_kind,
614 const dump_user_location_t &loc)
616 location_t srcloc = loc.get_location_t ();
618 if (dump_file && apply_dump_filter_p (dump_kind, pflags))
619 ::dump_loc (dump_kind, dump_file, srcloc);
621 if (alt_dump_file && apply_dump_filter_p (dump_kind, alt_flags))
622 ::dump_loc (dump_kind, alt_dump_file, srcloc);
624 /* Support for temp_dump_context in selftests. */
625 if (m_test_pp && apply_dump_filter_p (dump_kind, m_test_pp_flags))
626 ::dump_loc (dump_kind, m_test_pp, srcloc);
629 /* Make an item for the given dump call, equivalent to print_gimple_stmt. */
631 static optinfo_item *
632 make_item_for_dump_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags)
634 pretty_printer pp;
635 pp_needs_newline (&pp) = true;
636 pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
637 pp_newline (&pp);
639 optinfo_item *item
640 = new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
641 xstrdup (pp_formatted_text (&pp)));
642 return item;
645 /* Dump gimple statement GS with SPC indentation spaces and
646 EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled. */
648 void
649 dump_context::dump_gimple_stmt (const dump_metadata_t &metadata,
650 dump_flags_t extra_dump_flags,
651 gimple *gs, int spc)
653 optinfo_item *item
654 = make_item_for_dump_gimple_stmt (gs, spc, dump_flags | extra_dump_flags);
655 emit_item (item, metadata.get_dump_flags ());
657 if (optinfo_enabled_p ())
659 optinfo &info = ensure_pending_optinfo (metadata);
660 info.add_item (item);
662 else
663 delete item;
666 /* Similar to dump_gimple_stmt, except additionally print source location. */
668 void
669 dump_context::dump_gimple_stmt_loc (const dump_metadata_t &metadata,
670 const dump_user_location_t &loc,
671 dump_flags_t extra_dump_flags,
672 gimple *gs, int spc)
674 dump_loc (metadata, loc);
675 dump_gimple_stmt (metadata, extra_dump_flags, gs, spc);
678 /* Make an item for the given dump call, equivalent to print_gimple_expr. */
680 static optinfo_item *
681 make_item_for_dump_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags)
683 dump_flags |= TDF_RHS_ONLY;
684 pretty_printer pp;
685 pp_needs_newline (&pp) = true;
686 pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
688 optinfo_item *item
689 = new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
690 xstrdup (pp_formatted_text (&pp)));
691 return item;
694 /* Dump gimple statement GS with SPC indentation spaces and
695 EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled.
696 Do not terminate with a newline or semicolon. */
698 void
699 dump_context::dump_gimple_expr (const dump_metadata_t &metadata,
700 dump_flags_t extra_dump_flags,
701 gimple *gs, int spc)
703 optinfo_item *item
704 = make_item_for_dump_gimple_expr (gs, spc, dump_flags | extra_dump_flags);
705 emit_item (item, metadata.get_dump_flags ());
707 if (optinfo_enabled_p ())
709 optinfo &info = ensure_pending_optinfo (metadata);
710 info.add_item (item);
712 else
713 delete item;
716 /* Similar to dump_gimple_expr, except additionally print source location. */
718 void
719 dump_context::dump_gimple_expr_loc (const dump_metadata_t &metadata,
720 const dump_user_location_t &loc,
721 dump_flags_t extra_dump_flags,
722 gimple *gs,
723 int spc)
725 dump_loc (metadata, loc);
726 dump_gimple_expr (metadata, extra_dump_flags, gs, spc);
729 /* Make an item for the given dump call, equivalent to print_generic_expr. */
731 static optinfo_item *
732 make_item_for_dump_generic_expr (tree node, dump_flags_t dump_flags)
734 pretty_printer pp;
735 pp_needs_newline (&pp) = true;
736 pp_translate_identifiers (&pp) = false;
737 dump_generic_node (&pp, node, 0, dump_flags, false);
739 location_t loc = UNKNOWN_LOCATION;
740 if (EXPR_HAS_LOCATION (node))
741 loc = EXPR_LOCATION (node);
743 optinfo_item *item
744 = new optinfo_item (OPTINFO_ITEM_KIND_TREE, loc,
745 xstrdup (pp_formatted_text (&pp)));
746 return item;
749 /* Dump expression tree T using EXTRA_DUMP_FLAGS on dump streams if
750 DUMP_KIND is enabled. */
752 void
753 dump_context::dump_generic_expr (const dump_metadata_t &metadata,
754 dump_flags_t extra_dump_flags,
755 tree t)
757 optinfo_item *item
758 = make_item_for_dump_generic_expr (t, dump_flags | extra_dump_flags);
759 emit_item (item, metadata.get_dump_flags ());
761 if (optinfo_enabled_p ())
763 optinfo &info = ensure_pending_optinfo (metadata);
764 info.add_item (item);
766 else
767 delete item;
771 /* Similar to dump_generic_expr, except additionally print the source
772 location. */
774 void
775 dump_context::dump_generic_expr_loc (const dump_metadata_t &metadata,
776 const dump_user_location_t &loc,
777 dump_flags_t extra_dump_flags,
778 tree t)
780 dump_loc (metadata, loc);
781 dump_generic_expr (metadata, extra_dump_flags, t);
784 /* Make an item for the given dump call. */
786 static optinfo_item *
787 make_item_for_dump_symtab_node (symtab_node *node)
789 location_t loc = DECL_SOURCE_LOCATION (node->decl);
790 optinfo_item *item
791 = new optinfo_item (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc,
792 xstrdup (node->dump_name ()));
793 return item;
796 /* dump_pretty_printer's ctor. */
798 dump_pretty_printer::dump_pretty_printer (dump_context *context,
799 dump_flags_t dump_kind)
800 : pretty_printer (), m_context (context), m_dump_kind (dump_kind),
801 m_stashed_items ()
803 pp_format_decoder (this) = format_decoder_cb;
806 /* Phase 3 of formatting; compare with pp_output_formatted_text.
808 Emit optinfo_item instances for the various formatted chunks from phases
809 1 and 2 (i.e. pp_format).
811 Some chunks may already have had their items built (during decode_format).
812 These chunks have been stashed into m_stashed_items; we emit them here.
814 For all other purely textual chunks, they are printed into
815 buffer->formatted_obstack, and then emitted as a textual optinfo_item.
816 This consolidates multiple adjacent text chunks into a single text
817 optinfo_item. */
819 void
820 dump_pretty_printer::emit_items (optinfo *dest)
822 output_buffer *buffer = pp_buffer (this);
823 struct chunk_info *chunk_array = buffer->cur_chunk_array;
824 const char **args = chunk_array->args;
826 gcc_assert (buffer->obstack == &buffer->formatted_obstack);
827 gcc_assert (buffer->line_length == 0);
829 unsigned stashed_item_idx = 0;
830 for (unsigned chunk = 0; args[chunk]; chunk++)
832 if (stashed_item_idx < m_stashed_items.length ()
833 && args[chunk] == *m_stashed_items[stashed_item_idx].buffer_ptr)
835 emit_any_pending_textual_chunks (dest);
836 /* This chunk has a stashed item: use it. */
837 emit_item (m_stashed_items[stashed_item_idx++].item, dest);
839 else
840 /* This chunk is purely textual. Print it (to
841 buffer->formatted_obstack), so that we can consolidate adjacent
842 chunks into one textual optinfo_item. */
843 pp_string (this, args[chunk]);
846 emit_any_pending_textual_chunks (dest);
848 /* Ensure that we consumed all of stashed_items. */
849 gcc_assert (stashed_item_idx == m_stashed_items.length ());
851 /* Deallocate the chunk structure and everything after it (i.e. the
852 associated series of formatted strings). */
853 buffer->cur_chunk_array = chunk_array->prev;
854 obstack_free (&buffer->chunk_obstack, chunk_array);
857 /* Subroutine of dump_pretty_printer::emit_items
858 for consolidating multiple adjacent pure-text chunks into single
859 optinfo_items (in phase 3). */
861 void
862 dump_pretty_printer::emit_any_pending_textual_chunks (optinfo *dest)
864 gcc_assert (buffer->obstack == &buffer->formatted_obstack);
866 /* Don't emit an item if the pending text is empty. */
867 if (output_buffer_last_position_in_text (buffer) == NULL)
868 return;
870 char *formatted_text = xstrdup (pp_formatted_text (this));
871 optinfo_item *item
872 = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
873 formatted_text);
874 emit_item (item, dest);
876 /* Clear the pending text by unwinding formatted_text back to the start
877 of the buffer (without deallocating). */
878 obstack_free (&buffer->formatted_obstack,
879 buffer->formatted_obstack.object_base);
882 /* Emit ITEM and take ownership of it. If DEST is non-NULL, add ITEM
883 to DEST; otherwise delete ITEM. */
885 void
886 dump_pretty_printer::emit_item (optinfo_item *item, optinfo *dest)
888 m_context->emit_item (item, m_dump_kind);
889 if (dest)
890 dest->add_item (item);
891 else
892 delete item;
895 /* Record that ITEM (generated in phase 2 of formatting) is to be used for
896 the chunk at BUFFER_PTR in phase 3 (by emit_items). */
898 void
899 dump_pretty_printer::stash_item (const char **buffer_ptr, optinfo_item *item)
901 gcc_assert (buffer_ptr);
902 gcc_assert (item);
904 m_stashed_items.safe_push (stashed_item (buffer_ptr, item));
907 /* pp_format_decoder callback for dump_pretty_printer, and thus for
908 dump_printf and dump_printf_loc.
910 A wrapper around decode_format, for type-safety. */
912 bool
913 dump_pretty_printer::format_decoder_cb (pretty_printer *pp, text_info *text,
914 const char *spec, int /*precision*/,
915 bool /*wide*/, bool /*set_locus*/,
916 bool /*verbose*/, bool */*quoted*/,
917 const char **buffer_ptr)
919 dump_pretty_printer *opp = static_cast <dump_pretty_printer *> (pp);
920 return opp->decode_format (text, spec, buffer_ptr);
923 /* Format decoder for dump_pretty_printer, and thus for dump_printf and
924 dump_printf_loc.
926 Supported format codes (in addition to the standard pretty_printer ones)
927 are:
929 %C: cgraph_node *:
930 Equivalent to: dump_symtab_node (MSG_*, node)
931 %E: gimple *:
932 Equivalent to: dump_gimple_expr (MSG_*, TDF_SLIM, stmt, 0)
933 %G: gimple *:
934 Equivalent to: dump_gimple_stmt (MSG_*, TDF_SLIM, stmt, 0)
935 %T: tree:
936 Equivalent to: dump_generic_expr (MSG_*, arg, TDF_SLIM).
938 TODO: add a format code that can handle (symtab_node*) *and* both
939 subclasses (presumably means teaching -Wformat about non-virtual
940 subclasses).
942 These format codes build optinfo_item instances, thus capturing metadata
943 about the arguments being dumped, as well as the textual output. */
945 bool
946 dump_pretty_printer::decode_format (text_info *text, const char *spec,
947 const char **buffer_ptr)
949 /* Various format codes that imply making an optinfo_item and stashed it
950 for later use (to capture metadata, rather than plain text). */
951 switch (*spec)
953 case 'C':
955 cgraph_node *node = va_arg (*text->args_ptr, cgraph_node *);
957 /* Make an item for the node, and stash it. */
958 optinfo_item *item = make_item_for_dump_symtab_node (node);
959 stash_item (buffer_ptr, item);
960 return true;
963 case 'E':
965 gimple *stmt = va_arg (*text->args_ptr, gimple *);
967 /* Make an item for the stmt, and stash it. */
968 optinfo_item *item = make_item_for_dump_gimple_expr (stmt, 0, TDF_SLIM);
969 stash_item (buffer_ptr, item);
970 return true;
973 case 'G':
975 gimple *stmt = va_arg (*text->args_ptr, gimple *);
977 /* Make an item for the stmt, and stash it. */
978 optinfo_item *item = make_item_for_dump_gimple_stmt (stmt, 0, TDF_SLIM);
979 stash_item (buffer_ptr, item);
980 return true;
983 case 'T':
985 tree t = va_arg (*text->args_ptr, tree);
987 /* Make an item for the tree, and stash it. */
988 optinfo_item *item = make_item_for_dump_generic_expr (t, TDF_SLIM);
989 stash_item (buffer_ptr, item);
990 return true;
993 default:
994 return false;
998 /* Output a formatted message using FORMAT on appropriate dump streams. */
1000 void
1001 dump_context::dump_printf_va (const dump_metadata_t &metadata, const char *format,
1002 va_list *ap)
1004 dump_pretty_printer pp (this, metadata.get_dump_flags ());
1006 text_info text;
1007 text.err_no = errno;
1008 text.args_ptr = ap;
1009 text.format_spec = format;
1011 /* Phases 1 and 2, using pp_format. */
1012 pp_format (&pp, &text);
1014 /* Phase 3. */
1015 if (optinfo_enabled_p ())
1017 optinfo &info = ensure_pending_optinfo (metadata);
1018 pp.emit_items (&info);
1020 else
1021 pp.emit_items (NULL);
1024 /* Similar to dump_printf, except source location is also printed, and
1025 dump location captured. */
1027 void
1028 dump_context::dump_printf_loc_va (const dump_metadata_t &metadata,
1029 const dump_user_location_t &loc,
1030 const char *format, va_list *ap)
1032 dump_loc (metadata, loc);
1033 dump_printf_va (metadata, format, ap);
1036 /* Make an item for the given dump call, equivalent to print_dec. */
1038 template<unsigned int N, typename C>
1039 static optinfo_item *
1040 make_item_for_dump_dec (const poly_int<N, C> &value)
1042 STATIC_ASSERT (poly_coeff_traits<C>::signedness >= 0);
1043 signop sgn = poly_coeff_traits<C>::signedness ? SIGNED : UNSIGNED;
1045 pretty_printer pp;
1047 if (value.is_constant ())
1048 pp_wide_int (&pp, value.coeffs[0], sgn);
1049 else
1051 pp_character (&pp, '[');
1052 for (unsigned int i = 0; i < N; ++i)
1054 pp_wide_int (&pp, value.coeffs[i], sgn);
1055 pp_character (&pp, i == N - 1 ? ']' : ',');
1059 optinfo_item *item
1060 = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
1061 xstrdup (pp_formatted_text (&pp)));
1062 return item;
1065 /* Output VALUE in decimal to appropriate dump streams. */
1067 template<unsigned int N, typename C>
1068 void
1069 dump_context::dump_dec (const dump_metadata_t &metadata, const poly_int<N, C> &value)
1071 optinfo_item *item = make_item_for_dump_dec (value);
1072 emit_item (item, metadata.get_dump_flags ());
1074 if (optinfo_enabled_p ())
1076 optinfo &info = ensure_pending_optinfo (metadata);
1077 info.add_item (item);
1079 else
1080 delete item;
1083 /* Output the name of NODE on appropriate dump streams. */
1085 void
1086 dump_context::dump_symtab_node (const dump_metadata_t &metadata, symtab_node *node)
1088 optinfo_item *item = make_item_for_dump_symtab_node (node);
1089 emit_item (item, metadata.get_dump_flags ());
1091 if (optinfo_enabled_p ())
1093 optinfo &info = ensure_pending_optinfo (metadata);
1094 info.add_item (item);
1096 else
1097 delete item;
1100 /* Get the current dump scope-nesting depth.
1101 For use by -fopt-info (for showing nesting via indentation). */
1103 unsigned int
1104 dump_context::get_scope_depth () const
1106 return m_scope_depth;
1109 /* Push a nested dump scope.
1110 Increment the scope depth.
1111 Print "=== NAME ===\n" to the dumpfile, if any, and to the -fopt-info
1112 destination, if any.
1113 Emit a "scope" optinfo if optinfos are enabled. */
1115 void
1116 dump_context::begin_scope (const char *name,
1117 const dump_user_location_t &user_location,
1118 const dump_impl_location_t &impl_location)
1120 m_scope_depth++;
1122 location_t src_loc = user_location.get_location_t ();
1124 if (dump_file && apply_dump_filter_p (MSG_NOTE, pflags))
1125 ::dump_loc (MSG_NOTE, dump_file, src_loc);
1127 if (alt_dump_file && apply_dump_filter_p (MSG_NOTE, alt_flags))
1128 ::dump_loc (MSG_NOTE, alt_dump_file, src_loc);
1130 /* Support for temp_dump_context in selftests. */
1131 if (m_test_pp && apply_dump_filter_p (MSG_NOTE, m_test_pp_flags))
1132 ::dump_loc (MSG_NOTE, m_test_pp, src_loc);
1134 /* Format multiple consecutive punctuation characters via %s to
1135 avoid -Wformat-diag in the pp_printf call below whose output
1136 isn't used for diagnostic output. */
1137 pretty_printer pp;
1138 pp_printf (&pp, "%s %s %s", "===", name, "===");
1139 pp_newline (&pp);
1140 optinfo_item *item
1141 = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
1142 xstrdup (pp_formatted_text (&pp)));
1143 emit_item (item, MSG_NOTE);
1145 if (optinfo_enabled_p ())
1147 optinfo &info
1148 = begin_next_optinfo (dump_metadata_t (MSG_NOTE, impl_location),
1149 user_location);
1150 info.m_kind = OPTINFO_KIND_SCOPE;
1151 info.add_item (item);
1152 end_any_optinfo ();
1154 else
1155 delete item;
1158 /* Pop a nested dump scope. */
1160 void
1161 dump_context::end_scope ()
1163 end_any_optinfo ();
1164 m_scope_depth--;
1166 if (m_json_writer)
1167 m_json_writer->pop_scope ();
1170 /* Should optinfo instances be created?
1171 All creation of optinfos should be guarded by this predicate.
1172 Return true if any optinfo destinations are active. */
1174 bool
1175 dump_context::optinfo_enabled_p () const
1177 return (optimization_records_enabled_p ());
1180 /* Return the optinfo currently being accumulated, creating one if
1181 necessary. */
1183 optinfo &
1184 dump_context::ensure_pending_optinfo (const dump_metadata_t &metadata)
1186 if (!m_pending)
1187 return begin_next_optinfo (metadata, dump_user_location_t ());
1188 return *m_pending;
1191 /* Start a new optinfo and return it, ending any optinfo that was already
1192 accumulated. */
1194 optinfo &
1195 dump_context::begin_next_optinfo (const dump_metadata_t &metadata,
1196 const dump_user_location_t &user_loc)
1198 end_any_optinfo ();
1199 gcc_assert (m_pending == NULL);
1200 dump_location_t loc (user_loc, metadata.get_impl_location ());
1201 m_pending = new optinfo (loc, OPTINFO_KIND_NOTE, current_pass);
1202 m_pending->handle_dump_file_kind (metadata.get_dump_flags ());
1203 return *m_pending;
1206 /* End any optinfo that has been accumulated within this context; emitting
1207 it to any destinations as appropriate, such as optimization records. */
1209 void
1210 dump_context::end_any_optinfo ()
1212 if (m_pending)
1213 emit_optinfo (m_pending);
1214 delete m_pending;
1215 m_pending = NULL;
1218 /* Emit the optinfo to all of the "non-immediate" destinations
1219 (emission to "immediate" destinations is done by
1220 dump_context::emit_item). */
1222 void
1223 dump_context::emit_optinfo (const optinfo *info)
1225 /* -fsave-optimization-record. */
1226 if (m_json_writer)
1227 m_json_writer->add_record (info);
1230 /* Emit ITEM to all item destinations (those that don't require
1231 consolidation into optinfo instances). */
1233 void
1234 dump_context::emit_item (optinfo_item *item, dump_flags_t dump_kind)
1236 if (dump_file && apply_dump_filter_p (dump_kind, pflags))
1237 fprintf (dump_file, "%s", item->get_text ());
1239 if (alt_dump_file && apply_dump_filter_p (dump_kind, alt_flags))
1240 fprintf (alt_dump_file, "%s", item->get_text ());
1242 /* Support for temp_dump_context in selftests. */
1243 if (m_test_pp && apply_dump_filter_p (dump_kind, m_test_pp_flags))
1244 pp_string (m_test_pp, item->get_text ());
1247 /* The current singleton dump_context, and its default. */
1249 dump_context *dump_context::s_current = &dump_context::s_default;
1250 dump_context dump_context::s_default;
1252 /* Implementation of dump_* API calls, calling into dump_context
1253 member functions. */
1255 /* Calls to the dump_* functions do non-trivial work, so they ought
1256 to be guarded by:
1257 if (dump_enabled_p ())
1258 Assert that they are guarded, and, if assertions are disabled,
1259 bail out if the calls weren't properly guarded. */
1261 #define VERIFY_DUMP_ENABLED_P \
1262 do { \
1263 gcc_assert (dump_enabled_p ()); \
1264 if (!dump_enabled_p ()) \
1265 return; \
1266 } while (0)
1268 /* Dump gimple statement GS with SPC indentation spaces and
1269 EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled. */
1271 void
1272 dump_gimple_stmt (const dump_metadata_t &metadata, dump_flags_t extra_dump_flags,
1273 gimple *gs, int spc)
1275 VERIFY_DUMP_ENABLED_P;
1276 dump_context::get ().dump_gimple_stmt (metadata, extra_dump_flags, gs, spc);
1279 /* Similar to dump_gimple_stmt, except additionally print source location. */
1281 void
1282 dump_gimple_stmt_loc (const dump_metadata_t &metadata,
1283 const dump_user_location_t &loc,
1284 dump_flags_t extra_dump_flags, gimple *gs, int spc)
1286 VERIFY_DUMP_ENABLED_P;
1287 dump_context::get ().dump_gimple_stmt_loc (metadata, loc, extra_dump_flags,
1288 gs, spc);
1291 /* Dump gimple statement GS with SPC indentation spaces and
1292 EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled.
1293 Do not terminate with a newline or semicolon. */
1295 void
1296 dump_gimple_expr (const dump_metadata_t &metadata,
1297 dump_flags_t extra_dump_flags,
1298 gimple *gs, int spc)
1300 VERIFY_DUMP_ENABLED_P;
1301 dump_context::get ().dump_gimple_expr (metadata, extra_dump_flags, gs, spc);
1304 /* Similar to dump_gimple_expr, except additionally print source location. */
1306 void
1307 dump_gimple_expr_loc (const dump_metadata_t &metadata,
1308 const dump_user_location_t &loc,
1309 dump_flags_t extra_dump_flags, gimple *gs, int spc)
1311 VERIFY_DUMP_ENABLED_P;
1312 dump_context::get ().dump_gimple_expr_loc (metadata, loc, extra_dump_flags,
1313 gs, spc);
1316 /* Dump expression tree T using EXTRA_DUMP_FLAGS on dump streams if
1317 DUMP_KIND is enabled. */
1319 void
1320 dump_generic_expr (const dump_metadata_t &metadata, dump_flags_t extra_dump_flags,
1321 tree t)
1323 VERIFY_DUMP_ENABLED_P;
1324 dump_context::get ().dump_generic_expr (metadata, extra_dump_flags, t);
1327 /* Similar to dump_generic_expr, except additionally print the source
1328 location. */
1330 void
1331 dump_generic_expr_loc (const dump_metadata_t &metadata,
1332 const dump_user_location_t &loc,
1333 dump_flags_t extra_dump_flags, tree t)
1335 VERIFY_DUMP_ENABLED_P;
1336 dump_context::get ().dump_generic_expr_loc (metadata, loc, extra_dump_flags,
1340 /* Output a formatted message using FORMAT on appropriate dump streams. */
1342 void
1343 dump_printf (const dump_metadata_t &metadata, const char *format, ...)
1345 VERIFY_DUMP_ENABLED_P;
1346 va_list ap;
1347 va_start (ap, format);
1348 dump_context::get ().dump_printf_va (metadata, format, &ap);
1349 va_end (ap);
1352 /* Similar to dump_printf, except source location is also printed, and
1353 dump location captured. */
1355 void
1356 dump_printf_loc (const dump_metadata_t &metadata,
1357 const dump_user_location_t &loc,
1358 const char *format, ...)
1360 VERIFY_DUMP_ENABLED_P;
1361 va_list ap;
1362 va_start (ap, format);
1363 dump_context::get ().dump_printf_loc_va (metadata, loc, format, &ap);
1364 va_end (ap);
1367 /* Output VALUE in decimal to appropriate dump streams. */
1369 template<unsigned int N, typename C>
1370 void
1371 dump_dec (const dump_metadata_t &metadata, const poly_int<N, C> &value)
1373 VERIFY_DUMP_ENABLED_P;
1374 dump_context::get ().dump_dec (metadata, value);
1377 template void dump_dec (const dump_metadata_t &metadata, const poly_uint16 &);
1378 template void dump_dec (const dump_metadata_t &metadata, const poly_int64 &);
1379 template void dump_dec (const dump_metadata_t &metadata, const poly_uint64 &);
1380 template void dump_dec (const dump_metadata_t &metadata, const poly_offset_int &);
1381 template void dump_dec (const dump_metadata_t &metadata, const poly_widest_int &);
1383 void
1384 dump_dec (dump_flags_t dump_kind, const poly_wide_int &value, signop sgn)
1386 VERIFY_DUMP_ENABLED_P;
1387 if (dump_file
1388 && dump_context::get ().apply_dump_filter_p (dump_kind, pflags))
1389 print_dec (value, dump_file, sgn);
1391 if (alt_dump_file
1392 && dump_context::get ().apply_dump_filter_p (dump_kind, alt_flags))
1393 print_dec (value, alt_dump_file, sgn);
1396 /* Output VALUE in hexadecimal to appropriate dump streams. */
1398 void
1399 dump_hex (dump_flags_t dump_kind, const poly_wide_int &value)
1401 VERIFY_DUMP_ENABLED_P;
1402 if (dump_file
1403 && dump_context::get ().apply_dump_filter_p (dump_kind, pflags))
1404 print_hex (value, dump_file);
1406 if (alt_dump_file
1407 && dump_context::get ().apply_dump_filter_p (dump_kind, alt_flags))
1408 print_hex (value, alt_dump_file);
1411 /* Emit and delete the currently pending optinfo, if there is one,
1412 without the caller needing to know about class dump_context. */
1414 void
1415 dumpfile_ensure_any_optinfo_are_flushed ()
1417 dump_context::get().end_any_optinfo ();
1420 /* Output the name of NODE on appropriate dump streams. */
1422 void
1423 dump_symtab_node (const dump_metadata_t &metadata, symtab_node *node)
1425 VERIFY_DUMP_ENABLED_P;
1426 dump_context::get ().dump_symtab_node (metadata, node);
1429 /* Get the current dump scope-nesting depth.
1430 For use by -fopt-info (for showing nesting via indentation). */
1432 unsigned int
1433 get_dump_scope_depth ()
1435 return dump_context::get ().get_scope_depth ();
1438 /* Push a nested dump scope.
1439 Print "=== NAME ===\n" to the dumpfile, if any, and to the -fopt-info
1440 destination, if any.
1441 Emit a "scope" opinfo if optinfos are enabled.
1442 Increment the scope depth. */
1444 void
1445 dump_begin_scope (const char *name,
1446 const dump_user_location_t &user_location,
1447 const dump_impl_location_t &impl_location)
1449 dump_context::get ().begin_scope (name, user_location, impl_location);
1452 /* Pop a nested dump scope. */
1454 void
1455 dump_end_scope ()
1457 dump_context::get ().end_scope ();
1460 /* Start a dump for PHASE. Store user-supplied dump flags in
1461 *FLAG_PTR. Return the number of streams opened. Set globals
1462 DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
1463 set dump_flags appropriately for both pass dump stream and
1464 -fopt-info stream. */
1467 gcc::dump_manager::
1468 dump_start (int phase, dump_flags_t *flag_ptr)
1470 int count = 0;
1471 char *name;
1472 struct dump_file_info *dfi;
1473 FILE *stream;
1474 if (phase == TDI_none || !dump_phase_enabled_p (phase))
1475 return 0;
1477 dfi = get_dump_file_info (phase);
1478 name = get_dump_file_name (phase);
1479 if (name)
1481 stream = dump_open (name, dfi->pstate < 0);
1482 if (stream)
1484 dfi->pstate = 1;
1485 count++;
1487 free (name);
1488 dfi->pstream = stream;
1489 set_dump_file (dfi->pstream);
1490 /* Initialize current dump flags. */
1491 pflags = dfi->pflags;
1494 stream = dump_open_alternate_stream (dfi);
1495 if (stream)
1497 dfi->alt_stream = stream;
1498 count++;
1499 set_alt_dump_file (dfi->alt_stream);
1500 /* Initialize current -fopt-info flags. */
1501 alt_flags = dfi->alt_flags;
1504 if (flag_ptr)
1505 *flag_ptr = dfi->pflags;
1507 return count;
1510 /* Finish a tree dump for PHASE and close associated dump streams. Also
1511 reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
1513 void
1514 gcc::dump_manager::
1515 dump_finish (int phase)
1517 struct dump_file_info *dfi;
1519 if (phase < 0)
1520 return;
1521 dfi = get_dump_file_info (phase);
1522 if (dfi->pstream && dfi->pstream != stdout && dfi->pstream != stderr)
1523 fclose (dfi->pstream);
1525 if (dfi->alt_stream && dfi->alt_stream != stdout && dfi->alt_stream != stderr)
1526 fclose (dfi->alt_stream);
1528 dfi->alt_stream = NULL;
1529 dfi->pstream = NULL;
1530 set_dump_file (NULL);
1531 set_alt_dump_file (NULL);
1532 dump_flags = TDF_NONE;
1533 alt_flags = TDF_NONE;
1534 pflags = TDF_NONE;
1537 /* Begin a tree dump for PHASE. Stores any user supplied flag in
1538 *FLAG_PTR and returns a stream to write to. If the dump is not
1539 enabled, returns NULL.
1540 PART can be used for dump files which should be split to multiple
1541 parts. PART == -1 indicates dump file with no parts.
1542 If PART is -1, multiple calls will reopen and append to the dump file. */
1544 FILE *
1545 dump_begin (int phase, dump_flags_t *flag_ptr, int part)
1547 return g->get_dumps ()->dump_begin (phase, flag_ptr, part);
1550 FILE *
1551 gcc::dump_manager::
1552 dump_begin (int phase, dump_flags_t *flag_ptr, int part)
1554 if (phase == TDI_none || !dump_phase_enabled_p (phase))
1555 return NULL;
1557 char *name = get_dump_file_name (phase, part);
1558 if (!name)
1559 return NULL;
1560 struct dump_file_info *dfi = get_dump_file_info (phase);
1562 /* We do not support re-opening of dump files with parts. This would require
1563 tracking pstate per part of the dump file. */
1564 FILE *stream = dump_open (name, part != -1 || dfi->pstate < 0);
1565 if (stream)
1566 dfi->pstate = 1;
1567 free (name);
1569 if (flag_ptr)
1570 *flag_ptr = dfi->pflags;
1572 /* Initialize current flags */
1573 pflags = dfi->pflags;
1574 return stream;
1577 /* Returns nonzero if dump PHASE is enabled for at least one stream.
1578 If PHASE is TDI_tree_all, return nonzero if any dump is enabled for
1579 any phase. */
1582 gcc::dump_manager::
1583 dump_phase_enabled_p (int phase) const
1585 if (phase == TDI_tree_all)
1587 size_t i;
1588 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
1589 if (dump_files[i].pstate || dump_files[i].alt_state)
1590 return 1;
1591 for (i = 0; i < m_extra_dump_files_in_use; i++)
1592 if (m_extra_dump_files[i].pstate || m_extra_dump_files[i].alt_state)
1593 return 1;
1594 return 0;
1596 else
1598 struct dump_file_info *dfi = get_dump_file_info (phase);
1599 return dfi->pstate || dfi->alt_state;
1603 /* Returns nonzero if tree dump PHASE has been initialized. */
1606 gcc::dump_manager::
1607 dump_initialized_p (int phase) const
1609 struct dump_file_info *dfi = get_dump_file_info (phase);
1610 return dfi->pstate > 0 || dfi->alt_state > 0;
1613 /* Returns the switch name of PHASE. */
1615 const char *
1616 dump_flag_name (int phase)
1618 return g->get_dumps ()->dump_flag_name (phase);
1621 const char *
1622 gcc::dump_manager::
1623 dump_flag_name (int phase) const
1625 struct dump_file_info *dfi = get_dump_file_info (phase);
1626 return dfi->swtch;
1629 /* Handle -fdump-* and -fopt-info for a pass added after
1630 command-line options are parsed (those from plugins and
1631 those from backends).
1633 Because the registration of plugin/backend passes happens after the
1634 command-line options are parsed, the options that specify single
1635 pass dumping (e.g. -fdump-tree-PASSNAME) cannot be used for new
1636 passes. Therefore we currently can only enable dumping of
1637 new passes when the 'dump-all' flags (e.g. -fdump-tree-all)
1638 are specified. This is done here.
1640 Similarly, the saved -fopt-info options are wired up to the new pass. */
1642 void
1643 gcc::dump_manager::register_pass (opt_pass *pass)
1645 gcc_assert (pass);
1647 register_one_dump_file (pass);
1649 dump_file_info *pass_dfi = get_dump_file_info (pass->static_pass_number);
1650 gcc_assert (pass_dfi);
1652 enum tree_dump_index tdi;
1653 if (pass->type == SIMPLE_IPA_PASS
1654 || pass->type == IPA_PASS)
1655 tdi = TDI_ipa_all;
1656 else if (pass->type == GIMPLE_PASS)
1657 tdi = TDI_tree_all;
1658 else
1659 tdi = TDI_rtl_all;
1660 const dump_file_info *tdi_dfi = get_dump_file_info (tdi);
1661 gcc_assert (tdi_dfi);
1663 /* Check if dump-all flag is specified. */
1664 if (tdi_dfi->pstate)
1666 pass_dfi->pstate = tdi_dfi->pstate;
1667 pass_dfi->pflags = tdi_dfi->pflags;
1670 update_dfi_for_opt_info (pass_dfi);
1673 /* Finish a tree dump for PHASE. STREAM is the stream created by
1674 dump_begin. */
1676 void
1677 dump_end (int phase ATTRIBUTE_UNUSED, FILE *stream)
1679 if (stream != stderr && stream != stdout)
1680 fclose (stream);
1683 /* Enable all tree dumps with FLAGS on FILENAME. Return number of
1684 enabled tree dumps. */
1687 gcc::dump_manager::
1688 dump_enable_all (dump_kind dkind, dump_flags_t flags, const char *filename)
1690 int n = 0;
1691 size_t i;
1693 for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
1695 if (dump_files[i].dkind == dkind)
1697 const char *old_filename = dump_files[i].pfilename;
1698 dump_files[i].pstate = -1;
1699 dump_files[i].pflags |= flags;
1700 n++;
1701 /* Override the existing filename. */
1702 if (filename)
1704 dump_files[i].pfilename = xstrdup (filename);
1705 /* Since it is a command-line provided file, which is
1706 common to all the phases, use it in append mode. */
1707 dump_files[i].pstate = 1;
1709 if (old_filename && filename != old_filename)
1710 free (CONST_CAST (char *, old_filename));
1714 for (i = 0; i < m_extra_dump_files_in_use; i++)
1716 if (m_extra_dump_files[i].dkind == dkind)
1718 const char *old_filename = m_extra_dump_files[i].pfilename;
1719 m_extra_dump_files[i].pstate = -1;
1720 m_extra_dump_files[i].pflags |= flags;
1721 n++;
1722 /* Override the existing filename. */
1723 if (filename)
1725 m_extra_dump_files[i].pfilename = xstrdup (filename);
1726 /* Since it is a command-line provided file, which is
1727 common to all the phases, use it in append mode. */
1728 m_extra_dump_files[i].pstate = 1;
1730 if (old_filename && filename != old_filename)
1731 free (CONST_CAST (char *, old_filename));
1735 return n;
1738 /* Enable -fopt-info dumps on all dump files matching OPTGROUP_FLAGS.
1739 Enable dumps with FLAGS on FILENAME. Return the number of enabled
1740 dumps. */
1743 gcc::dump_manager::
1744 opt_info_enable_passes (optgroup_flags_t optgroup_flags, dump_flags_t flags,
1745 const char *filename)
1747 int n = 0;
1749 m_optgroup_flags = optgroup_flags;
1750 m_optinfo_flags = flags;
1751 m_optinfo_filename = xstrdup (filename);
1753 for (size_t i = TDI_none + 1; i < (size_t) TDI_end; i++)
1754 if (update_dfi_for_opt_info (&dump_files[i]))
1755 n++;
1757 for (size_t i = 0; i < m_extra_dump_files_in_use; i++)
1758 if (update_dfi_for_opt_info (&m_extra_dump_files[i]))
1759 n++;
1761 return n;
1764 /* Use the saved -fopt-info options to update DFI.
1765 Return true if the dump is enabled. */
1767 bool
1768 gcc::dump_manager::update_dfi_for_opt_info (dump_file_info *dfi) const
1770 gcc_assert (dfi);
1772 if (!(dfi->optgroup_flags & m_optgroup_flags))
1773 return false;
1775 const char *old_filename = dfi->alt_filename;
1776 /* Since this file is shared among different passes, it
1777 should be opened in append mode. */
1778 dfi->alt_state = 1;
1779 dfi->alt_flags |= m_optinfo_flags;
1780 /* Override the existing filename. */
1781 if (m_optinfo_filename)
1782 dfi->alt_filename = xstrdup (m_optinfo_filename);
1783 if (old_filename && m_optinfo_filename != old_filename)
1784 free (CONST_CAST (char *, old_filename));
1786 return true;
1789 /* Helper routine to parse -<dump format>[=filename]
1790 and return the corresponding dump flag. If POS_P is non-NULL,
1791 assign start of filename into *POS_P. */
1793 dump_flags_t
1794 parse_dump_option (const char *option_value, const char **pos_p)
1796 const char *ptr;
1797 dump_flags_t flags;
1799 ptr = option_value;
1800 if (pos_p)
1801 *pos_p = NULL;
1803 /* Retain "user-facing" and "internals" messages, but filter out
1804 those from an opt_problem being re-emitted at the top level
1805 (MSG_PRIORITY_REEMITTED), so as to avoid duplicate messages
1806 messing up scan-tree-dump-times" in DejaGnu tests. */
1807 flags = MSG_PRIORITY_USER_FACING | MSG_PRIORITY_INTERNALS;
1809 while (*ptr)
1811 const struct kv_pair<dump_flags_t> *option_ptr;
1812 const char *end_ptr;
1813 const char *eq_ptr;
1814 unsigned length;
1815 while (*ptr == '-')
1816 ptr++;
1817 end_ptr = strchr (ptr, '-');
1818 eq_ptr = strchr (ptr, '=');
1820 if (eq_ptr && (!end_ptr || end_ptr > eq_ptr))
1821 end_ptr = eq_ptr;
1823 if (!end_ptr)
1824 end_ptr = ptr + strlen (ptr);
1825 length = end_ptr - ptr;
1827 for (option_ptr = dump_options; option_ptr->name; option_ptr++)
1828 if (strlen (option_ptr->name) == length
1829 && !memcmp (option_ptr->name, ptr, length))
1831 flags |= option_ptr->value;
1832 goto found;
1835 if (*ptr == '=')
1837 /* Interpret rest of the argument as a dump filename. This
1838 filename overrides other command line filenames. */
1839 if (pos_p)
1840 *pos_p = ptr + 1;
1841 break;
1843 else
1845 warning (0, "ignoring unknown option %q.*s",
1846 length, ptr);
1847 flags = TDF_ERROR;
1849 found:
1850 ptr = end_ptr;
1853 return flags;
1856 /* Parse ARG as a dump switch. Return nonzero if it is, and store the
1857 relevant details in the dump_files array. */
1860 gcc::dump_manager::
1861 dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
1863 const char *option_value;
1864 dump_flags_t flags = TDF_NONE;
1866 if (doglob && !dfi->glob)
1867 return 0;
1869 option_value = skip_leading_substring (arg, doglob ? dfi->glob : dfi->swtch);
1870 if (!option_value)
1871 return 0;
1873 if (*option_value && *option_value != '-' && *option_value != '=')
1874 return 0;
1876 const char *filename;
1877 flags = parse_dump_option (option_value, &filename);
1878 if (filename)
1880 if (dfi->pfilename)
1881 free (CONST_CAST (char *, dfi->pfilename));
1882 dfi->pfilename = xstrdup (filename);
1885 dfi->pstate = -1;
1886 dfi->pflags |= flags;
1888 /* Process -fdump-tree-all and -fdump-rtl-all, by enabling all the
1889 known dumps. */
1890 if (dfi->suffix == NULL)
1891 dump_enable_all (dfi->dkind, dfi->pflags, dfi->pfilename);
1893 return 1;
1896 void
1897 gcc::dump_manager::
1898 dump_switch_p (const char *arg)
1900 size_t i;
1901 int any = 0;
1903 for (i = TDI_none + 1; i != TDI_end; i++)
1904 any |= dump_switch_p_1 (arg, &dump_files[i], false);
1906 /* Don't glob if we got a hit already */
1907 if (!any)
1908 for (i = TDI_none + 1; i != TDI_end; i++)
1909 any |= dump_switch_p_1 (arg, &dump_files[i], true);
1911 for (i = 0; i < m_extra_dump_files_in_use; i++)
1912 any |= dump_switch_p_1 (arg, &m_extra_dump_files[i], false);
1914 if (!any)
1915 for (i = 0; i < m_extra_dump_files_in_use; i++)
1916 any |= dump_switch_p_1 (arg, &m_extra_dump_files[i], true);
1918 if (!any)
1920 auto_vec<const char *> candidates;
1921 for (size_t i = TDI_none + 1; i != TDI_end; i++)
1922 candidates.safe_push (dump_files[i].swtch);
1923 for (size_t i = 0; i < m_extra_dump_files_in_use; i++)
1924 candidates.safe_push (m_extra_dump_files[i].swtch);
1925 const char *hint = find_closest_string (arg, &candidates);
1926 if (hint)
1927 error ("unrecognized command-line option %<-fdump-%s%>; "
1928 "did you mean %<-fdump-%s%>?", arg, hint);
1929 else
1930 error ("unrecognized command-line option %<-fdump-%s%>", arg);
1934 /* Parse ARG as a -fopt-info switch and store flags, optgroup_flags
1935 and filename. Return non-zero if it is a recognized switch. */
1937 static int
1938 opt_info_switch_p_1 (const char *arg, dump_flags_t *flags,
1939 optgroup_flags_t *optgroup_flags, char **filename)
1941 const char *option_value;
1942 const char *ptr;
1944 option_value = arg;
1945 ptr = option_value;
1947 *filename = NULL;
1949 /* Default to filtering out "internals" messages, and retaining
1950 "user-facing" messages, and those from an opt_problem being
1951 re-emitted at the top level. */
1952 *flags = MSG_PRIORITY_USER_FACING | MSG_PRIORITY_REEMITTED;
1954 *optgroup_flags = OPTGROUP_NONE;
1956 if (!ptr)
1957 return 1; /* Handle '-fopt-info' without any additional options. */
1959 while (*ptr)
1961 const char *end_ptr;
1962 const char *eq_ptr;
1963 unsigned length;
1965 while (*ptr == '-')
1966 ptr++;
1967 end_ptr = strchr (ptr, '-');
1968 eq_ptr = strchr (ptr, '=');
1970 if (eq_ptr && (!end_ptr || eq_ptr < end_ptr))
1971 end_ptr = eq_ptr;
1972 else if (!end_ptr)
1973 end_ptr = ptr + strlen (ptr);
1974 length = end_ptr - ptr;
1976 for (const kv_pair<dump_flags_t> *option_ptr = optinfo_verbosity_options;
1977 option_ptr->name; option_ptr++)
1978 if (strlen (option_ptr->name) == length
1979 && !memcmp (option_ptr->name, ptr, length))
1981 *flags |= option_ptr->value;
1982 goto found;
1985 for (const kv_pair<optgroup_flags_t> *option_ptr = optgroup_options;
1986 option_ptr->name; option_ptr++)
1987 if (strlen (option_ptr->name) == length
1988 && !memcmp (option_ptr->name, ptr, length))
1990 *optgroup_flags |= option_ptr->value;
1991 goto found;
1994 if (*ptr == '=')
1996 /* Interpret rest of the argument as a dump filename. This
1997 filename overrides other command line filenames. */
1998 *filename = xstrdup (ptr + 1);
1999 break;
2001 else
2003 warning (0, "unknown option %q.*s in %<-fopt-info-%s%>",
2004 length, ptr, arg);
2005 return 0;
2007 found:;
2008 ptr = end_ptr;
2011 return 1;
2014 /* Return non-zero if ARG is a recognized switch for
2015 -fopt-info. Return zero otherwise. */
2018 opt_info_switch_p (const char *arg)
2020 dump_flags_t flags;
2021 optgroup_flags_t optgroup_flags;
2022 char *filename;
2023 static char *file_seen = NULL;
2024 gcc::dump_manager *dumps = g->get_dumps ();
2026 if (!opt_info_switch_p_1 (arg, &flags, &optgroup_flags, &filename))
2027 return 0;
2029 if (!filename)
2030 filename = xstrdup ("stderr");
2032 /* Bail out if a different filename has been specified. */
2033 if (file_seen && strcmp (file_seen, filename))
2035 warning (0, "ignoring possibly conflicting option %<-fopt-info-%s%>",
2036 arg);
2037 return 1;
2040 file_seen = xstrdup (filename);
2041 if (!(flags & MSG_ALL_KINDS))
2042 flags |= MSG_OPTIMIZED_LOCATIONS;
2043 if (!optgroup_flags)
2044 optgroup_flags = OPTGROUP_ALL;
2046 return dumps->opt_info_enable_passes (optgroup_flags, flags, filename);
2049 /* Print basic block on the dump streams. */
2051 void
2052 dump_basic_block (dump_flags_t dump_kind, basic_block bb, int indent)
2054 if (dump_file
2055 && dump_context::get ().apply_dump_filter_p (dump_kind, pflags))
2056 dump_bb (dump_file, bb, indent, TDF_DETAILS);
2057 if (alt_dump_file
2058 && dump_context::get ().apply_dump_filter_p (dump_kind, alt_flags))
2059 dump_bb (alt_dump_file, bb, indent, TDF_DETAILS);
2062 /* Dump FUNCTION_DECL FN as tree dump PHASE. */
2064 void
2065 dump_function (int phase, tree fn)
2067 FILE *stream;
2068 dump_flags_t flags;
2070 stream = dump_begin (phase, &flags);
2071 if (stream)
2073 dump_function_to_file (fn, stream, flags);
2074 dump_end (phase, stream);
2078 /* Print information from the combine pass on dump_file. */
2080 void
2081 print_combine_total_stats (void)
2083 if (dump_file)
2084 dump_combine_total_stats (dump_file);
2087 /* Enable RTL dump for all the RTL passes. */
2089 bool
2090 enable_rtl_dump_file (void)
2092 gcc::dump_manager *dumps = g->get_dumps ();
2093 int num_enabled =
2094 dumps->dump_enable_all (DK_rtl, dump_flags_t (TDF_DETAILS) | TDF_BLOCKS,
2095 NULL);
2096 return num_enabled > 0;
2099 /* debug_dump_context's ctor. Temporarily override the dump_context
2100 (to forcibly enable output to stderr). */
2102 debug_dump_context::debug_dump_context (FILE *f)
2103 : m_context (),
2104 m_saved (&dump_context::get ()),
2105 m_saved_flags (dump_flags),
2106 m_saved_pflags (pflags),
2107 m_saved_file (dump_file)
2109 set_dump_file (f);
2110 dump_context::s_current = &m_context;
2111 pflags = dump_flags = MSG_ALL_KINDS | MSG_ALL_PRIORITIES;
2112 dump_context::get ().refresh_dumps_are_enabled ();
2115 /* debug_dump_context's dtor. Restore the saved dump_context. */
2117 debug_dump_context::~debug_dump_context ()
2119 set_dump_file (m_saved_file);
2120 dump_context::s_current = m_saved;
2121 dump_flags = m_saved_flags;
2122 pflags = m_saved_pflags;
2123 dump_context::get ().refresh_dumps_are_enabled ();
2127 #if CHECKING_P
2129 namespace selftest {
2131 /* temp_dump_context's ctor. Temporarily override the dump_context
2132 (to forcibly enable optinfo-generation). */
2134 temp_dump_context::temp_dump_context (bool forcibly_enable_optinfo,
2135 bool forcibly_enable_dumping,
2136 dump_flags_t test_pp_flags)
2137 : m_context (),
2138 m_saved (&dump_context::get ())
2140 dump_context::s_current = &m_context;
2141 if (forcibly_enable_optinfo)
2142 m_context.set_json_writer (new optrecord_json_writer ());
2143 /* Conditionally enable the test dump, so that we can verify both the
2144 dump_enabled_p and the !dump_enabled_p cases in selftests. */
2145 if (forcibly_enable_dumping)
2147 m_context.m_test_pp = &m_pp;
2148 m_context.m_test_pp_flags = test_pp_flags;
2151 dump_context::get ().refresh_dumps_are_enabled ();
2154 /* temp_dump_context's dtor. Restore the saved dump_context. */
2156 temp_dump_context::~temp_dump_context ()
2158 m_context.set_json_writer (NULL);
2160 dump_context::s_current = m_saved;
2162 dump_context::get ().refresh_dumps_are_enabled ();
2165 /* 0-terminate the text dumped so far, and return it. */
2167 const char *
2168 temp_dump_context::get_dumped_text ()
2170 return pp_formatted_text (&m_pp);
2173 /* Verify that IMPL_LOC is within EXPECTED_FILE at EXPECTED_LINE,
2174 from EXPECTED_FUNCTION, using LOC for the location of any failure,
2175 provided that the build compiler is sufficiently recent. */
2177 static void
2178 assert_impl_location_eq (const location &loc ATTRIBUTE_UNUSED,
2179 const dump_impl_location_t &impl_loc ATTRIBUTE_UNUSED,
2180 const char *expected_file ATTRIBUTE_UNUSED,
2181 int expected_line ATTRIBUTE_UNUSED,
2182 const char *expected_function ATTRIBUTE_UNUSED)
2184 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
2185 ASSERT_STR_CONTAINS_AT (loc, impl_loc.m_file, expected_file);
2186 ASSERT_EQ_AT (loc, impl_loc.m_line, expected_line);
2187 ASSERT_STR_CONTAINS_AT (loc, impl_loc.m_function, expected_function);
2188 #endif
2191 /* Verify that IMPL_LOC is within EXPECTED_FILE at EXPECTED_LINE,
2192 from EXPECTED_FUNCTION, provided that the build compiler is
2193 sufficiently recent. */
2195 #define ASSERT_IMPL_LOCATION_EQ(IMPL_LOC, EXPECTED_FILE, EXPECTED_LINE, \
2196 EXPECTED_FUNCTION) \
2197 SELFTEST_BEGIN_STMT \
2198 assert_impl_location_eq (SELFTEST_LOCATION, IMPL_LOC, \
2199 EXPECTED_FILE, EXPECTED_LINE, \
2200 EXPECTED_FUNCTION); \
2201 SELFTEST_END_STMT
2203 /* Verify that the dump_location_t constructors capture the source location
2204 at which they were called (provided that the build compiler is sufficiently
2205 recent). */
2207 static void
2208 test_impl_location ()
2210 /* Default ctor. */
2212 dump_location_t loc;
2213 const int expected_line = __LINE__ - 1;
2214 ASSERT_IMPL_LOCATION_EQ (loc.get_impl_location (),
2215 "dumpfile.c", expected_line, "test_impl_location");
2218 /* Constructing from a gimple. */
2220 dump_location_t loc ((gimple *)NULL);
2221 const int expected_line = __LINE__ - 1;
2222 ASSERT_IMPL_LOCATION_EQ (loc.get_impl_location (),
2223 "dumpfile.c", expected_line, "test_impl_location");
2226 /* Constructing from an rtx_insn. */
2228 dump_location_t loc ((rtx_insn *)NULL);
2229 const int expected_line = __LINE__ - 1;
2230 ASSERT_IMPL_LOCATION_EQ (loc.get_impl_location (),
2231 "dumpfile.c", expected_line, "test_impl_location");
2235 /* Verify that the text dumped so far in CONTEXT equals
2236 EXPECTED_TEXT, using LOC for the location of any failure.
2237 As a side-effect, the internal buffer is 0-terminated. */
2239 void
2240 verify_dumped_text (const location &loc,
2241 temp_dump_context *context,
2242 const char *expected_text)
2244 gcc_assert (context);
2245 ASSERT_STREQ_AT (loc, context->get_dumped_text (),
2246 expected_text);
2249 /* Verify that ITEM has the expected values. */
2251 void
2252 verify_item (const location &loc,
2253 const optinfo_item *item,
2254 enum optinfo_item_kind expected_kind,
2255 location_t expected_location,
2256 const char *expected_text)
2258 ASSERT_EQ_AT (loc, item->get_kind (), expected_kind);
2259 ASSERT_EQ_AT (loc, item->get_location (), expected_location);
2260 ASSERT_STREQ_AT (loc, item->get_text (), expected_text);
2263 /* Verify that calls to the dump_* API are captured and consolidated into
2264 optimization records. */
2266 static void
2267 test_capture_of_dump_calls (const line_table_case &case_)
2269 /* Generate a location_t for testing. */
2270 line_table_test ltt (case_);
2271 linemap_add (line_table, LC_ENTER, false, "test.txt", 0);
2272 linemap_line_start (line_table, 5, 100);
2273 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
2274 location_t decl_loc = linemap_position_for_column (line_table, 8);
2275 location_t stmt_loc = linemap_position_for_column (line_table, 10);
2276 if (stmt_loc > LINE_MAP_MAX_LOCATION_WITH_COLS)
2277 return;
2279 dump_user_location_t loc = dump_user_location_t::from_location_t (stmt_loc);
2281 gimple *stmt = gimple_build_return (NULL);
2282 gimple_set_location (stmt, stmt_loc);
2284 tree test_decl = build_decl (decl_loc, FUNCTION_DECL,
2285 get_identifier ("test_decl"),
2286 build_function_type_list (void_type_node,
2287 NULL_TREE));
2289 symbol_table_test tmp_symtab;
2291 cgraph_node *node = cgraph_node::get_create (test_decl);
2292 gcc_assert (node);
2294 /* Run all tests twice, with and then without optinfo enabled, to ensure
2295 that immediate destinations vs optinfo-based destinations both
2296 work, independently of each other, with no leaks. */
2297 for (int i = 0 ; i < 2; i++)
2299 bool with_optinfo = (i == 0);
2301 /* Test of dump_printf. */
2303 temp_dump_context tmp (with_optinfo, true,
2304 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2305 dump_printf (MSG_NOTE, "int: %i str: %s", 42, "foo");
2306 const int expected_impl_line = __LINE__ - 1;
2308 ASSERT_DUMPED_TEXT_EQ (tmp, "int: 42 str: foo");
2309 if (with_optinfo)
2311 optinfo *info = tmp.get_pending_optinfo ();
2312 ASSERT_TRUE (info != NULL);
2313 ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2314 ASSERT_EQ (info->num_items (), 1);
2315 ASSERT_IS_TEXT (info->get_item (0), "int: 42 str: foo");
2316 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2317 "dumpfile.c", expected_impl_line,
2318 "test_capture_of_dump_calls");
2322 /* Test of dump_printf with %T. */
2324 temp_dump_context tmp (with_optinfo, true,
2325 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2326 dump_printf (MSG_NOTE, "tree: %T", integer_zero_node);
2327 const int expected_impl_line = __LINE__ - 1;
2329 ASSERT_DUMPED_TEXT_EQ (tmp, "tree: 0");
2330 if (with_optinfo)
2332 optinfo *info = tmp.get_pending_optinfo ();
2333 ASSERT_TRUE (info != NULL);
2334 ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2335 ASSERT_EQ (info->num_items (), 2);
2336 ASSERT_IS_TEXT (info->get_item (0), "tree: ");
2337 ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0");
2338 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2339 "dumpfile.c", expected_impl_line,
2340 "test_capture_of_dump_calls");
2344 /* Test of dump_printf with %E. */
2346 temp_dump_context tmp (with_optinfo, true,
2347 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2348 dump_printf (MSG_NOTE, "gimple: %E", stmt);
2349 const int expected_impl_line = __LINE__ - 1;
2351 ASSERT_DUMPED_TEXT_EQ (tmp, "gimple: return;");
2352 if (with_optinfo)
2354 optinfo *info = tmp.get_pending_optinfo ();
2355 ASSERT_TRUE (info != NULL);
2356 ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2357 ASSERT_EQ (info->num_items (), 2);
2358 ASSERT_IS_TEXT (info->get_item (0), "gimple: ");
2359 ASSERT_IS_GIMPLE (info->get_item (1), stmt_loc, "return;");
2360 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2361 "dumpfile.c", expected_impl_line,
2362 "test_capture_of_dump_calls");
2366 /* Test of dump_printf with %G. */
2368 temp_dump_context tmp (with_optinfo, true,
2369 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2370 dump_printf (MSG_NOTE, "gimple: %G", stmt);
2371 const int expected_impl_line = __LINE__ - 1;
2373 ASSERT_DUMPED_TEXT_EQ (tmp, "gimple: return;\n");
2374 if (with_optinfo)
2376 optinfo *info = tmp.get_pending_optinfo ();
2377 ASSERT_TRUE (info != NULL);
2378 ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2379 ASSERT_EQ (info->num_items (), 2);
2380 ASSERT_IS_TEXT (info->get_item (0), "gimple: ");
2381 ASSERT_IS_GIMPLE (info->get_item (1), stmt_loc, "return;\n");
2382 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2383 "dumpfile.c", expected_impl_line,
2384 "test_capture_of_dump_calls");
2388 /* Test of dump_printf with %C. */
2390 temp_dump_context tmp (with_optinfo, true,
2391 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2392 dump_printf (MSG_NOTE, "node: %C", node);
2393 const int expected_impl_line = __LINE__ - 1;
2395 ASSERT_DUMPED_TEXT_EQ (tmp, "node: test_decl/0");
2396 if (with_optinfo)
2398 optinfo *info = tmp.get_pending_optinfo ();
2399 ASSERT_TRUE (info != NULL);
2400 ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2401 ASSERT_EQ (info->num_items (), 2);
2402 ASSERT_IS_TEXT (info->get_item (0), "node: ");
2403 ASSERT_IS_SYMTAB_NODE (info->get_item (1), decl_loc, "test_decl/0");
2404 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2405 "dumpfile.c", expected_impl_line,
2406 "test_capture_of_dump_calls");
2410 /* dump_print_loc with multiple format codes. This tests various
2411 things:
2412 - intermingling of text, format codes handled by the base
2413 pretty_printer, and dump-specific format codes
2414 - multiple dump-specific format codes: some consecutive, others
2415 separated by text, trailing text after the final one. */
2417 temp_dump_context tmp (with_optinfo, true,
2418 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2419 dump_printf_loc (MSG_NOTE, loc, "before %T and %T"
2420 " %i consecutive %E%E after\n",
2421 integer_zero_node, test_decl, 42, stmt, stmt);
2423 ASSERT_DUMPED_TEXT_EQ (tmp,
2424 "test.txt:5:10: note: before 0 and test_decl"
2425 " 42 consecutive return;return; after\n");
2426 if (with_optinfo)
2428 optinfo *info = tmp.get_pending_optinfo ();
2429 ASSERT_TRUE (info != NULL);
2430 ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2431 ASSERT_EQ (info->num_items (), 8);
2432 ASSERT_IS_TEXT (info->get_item (0), "before ");
2433 ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0");
2434 ASSERT_IS_TEXT (info->get_item (2), " and ");
2435 ASSERT_IS_TREE (info->get_item (3), UNKNOWN_LOCATION, "test_decl");
2436 ASSERT_IS_TEXT (info->get_item (4), " 42 consecutive ");
2437 ASSERT_IS_GIMPLE (info->get_item (5), stmt_loc, "return;");
2438 ASSERT_IS_GIMPLE (info->get_item (6), stmt_loc, "return;");
2439 ASSERT_IS_TEXT (info->get_item (7), " after\n");
2440 /* We don't ASSERT_IMPL_LOCATION_EQ here, to avoid having to
2441 enforce at which exact line the multiline dump_printf_loc
2442 occurred. */
2446 /* Tree, via dump_generic_expr. */
2448 temp_dump_context tmp (with_optinfo, true,
2449 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2450 dump_printf_loc (MSG_NOTE, loc, "test of tree: ");
2451 const int expected_impl_line = __LINE__ - 1;
2452 dump_generic_expr (MSG_NOTE, TDF_SLIM, integer_zero_node);
2454 ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: test of tree: 0");
2455 if (with_optinfo)
2457 optinfo *info = tmp.get_pending_optinfo ();
2458 ASSERT_TRUE (info != NULL);
2459 ASSERT_EQ (info->get_location_t (), stmt_loc);
2460 ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2461 ASSERT_EQ (info->num_items (), 2);
2462 ASSERT_IS_TEXT (info->get_item (0), "test of tree: ");
2463 ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0");
2464 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2465 "dumpfile.c", expected_impl_line,
2466 "test_capture_of_dump_calls");
2470 /* Tree, via dump_generic_expr_loc. */
2472 temp_dump_context tmp (with_optinfo, true,
2473 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2474 dump_generic_expr_loc (MSG_NOTE, loc, TDF_SLIM, integer_one_node);
2475 const int expected_impl_line = __LINE__ - 1;
2477 ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: 1");
2478 if (with_optinfo)
2480 optinfo *info = tmp.get_pending_optinfo ();
2481 ASSERT_TRUE (info != NULL);
2482 ASSERT_EQ (info->get_location_t (), stmt_loc);
2483 ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2484 ASSERT_EQ (info->num_items (), 1);
2485 ASSERT_IS_TREE (info->get_item (0), UNKNOWN_LOCATION, "1");
2486 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2487 "dumpfile.c", expected_impl_line,
2488 "test_capture_of_dump_calls");
2492 /* Gimple. */
2494 /* dump_gimple_stmt_loc. */
2496 temp_dump_context tmp (with_optinfo, true,
2497 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2498 dump_gimple_stmt_loc (MSG_NOTE, loc, TDF_SLIM, stmt, 2);
2499 const int expected_impl_line = __LINE__ - 1;
2501 ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: return;\n");
2502 if (with_optinfo)
2504 optinfo *info = tmp.get_pending_optinfo ();
2505 ASSERT_TRUE (info != NULL);
2506 ASSERT_EQ (info->num_items (), 1);
2507 ASSERT_IS_GIMPLE (info->get_item (0), stmt_loc, "return;\n");
2508 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2509 "dumpfile.c", expected_impl_line,
2510 "test_capture_of_dump_calls");
2514 /* dump_gimple_stmt. */
2516 temp_dump_context tmp (with_optinfo, true,
2517 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2518 dump_gimple_stmt (MSG_NOTE, TDF_SLIM, stmt, 2);
2519 const int expected_impl_line = __LINE__ - 1;
2521 ASSERT_DUMPED_TEXT_EQ (tmp, "return;\n");
2522 if (with_optinfo)
2524 optinfo *info = tmp.get_pending_optinfo ();
2525 ASSERT_TRUE (info != NULL);
2526 ASSERT_EQ (info->num_items (), 1);
2527 ASSERT_IS_GIMPLE (info->get_item (0), stmt_loc, "return;\n");
2528 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2529 "dumpfile.c", expected_impl_line,
2530 "test_capture_of_dump_calls");
2534 /* dump_gimple_expr_loc. */
2536 temp_dump_context tmp (with_optinfo, true,
2537 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2538 dump_gimple_expr_loc (MSG_NOTE, loc, TDF_SLIM, stmt, 2);
2539 const int expected_impl_line = __LINE__ - 1;
2541 ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: return;");
2542 if (with_optinfo)
2544 optinfo *info = tmp.get_pending_optinfo ();
2545 ASSERT_TRUE (info != NULL);
2546 ASSERT_EQ (info->num_items (), 1);
2547 ASSERT_IS_GIMPLE (info->get_item (0), stmt_loc, "return;");
2548 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2549 "dumpfile.c", expected_impl_line,
2550 "test_capture_of_dump_calls");
2554 /* dump_gimple_expr. */
2556 temp_dump_context tmp (with_optinfo, true,
2557 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2558 dump_gimple_expr (MSG_NOTE, TDF_SLIM, stmt, 2);
2559 const int expected_impl_line = __LINE__ - 1;
2561 ASSERT_DUMPED_TEXT_EQ (tmp, "return;");
2562 if (with_optinfo)
2564 optinfo *info = tmp.get_pending_optinfo ();
2565 ASSERT_TRUE (info != NULL);
2566 ASSERT_EQ (info->num_items (), 1);
2567 ASSERT_IS_GIMPLE (info->get_item (0), stmt_loc, "return;");
2568 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2569 "dumpfile.c", expected_impl_line,
2570 "test_capture_of_dump_calls");
2575 /* symtab_node. */
2577 temp_dump_context tmp (with_optinfo, true,
2578 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2579 dump_symtab_node (MSG_NOTE, node);
2580 const int expected_impl_line = __LINE__ - 1;
2582 ASSERT_DUMPED_TEXT_EQ (tmp, "test_decl/0");
2583 if (with_optinfo)
2585 optinfo *info = tmp.get_pending_optinfo ();
2586 ASSERT_TRUE (info != NULL);
2587 ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
2588 ASSERT_EQ (info->num_items (), 1);
2589 ASSERT_IS_SYMTAB_NODE (info->get_item (0), decl_loc, "test_decl/0");
2590 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2591 "dumpfile.c", expected_impl_line,
2592 "test_capture_of_dump_calls");
2596 /* poly_int. */
2598 temp_dump_context tmp (with_optinfo, true,
2599 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2600 dump_dec (MSG_NOTE, poly_int64 (42));
2601 const int expected_impl_line = __LINE__ - 1;
2603 ASSERT_DUMPED_TEXT_EQ (tmp, "42");
2604 if (with_optinfo)
2606 optinfo *info = tmp.get_pending_optinfo ();
2607 ASSERT_TRUE (info != NULL);
2608 ASSERT_EQ (info->num_items (), 1);
2609 ASSERT_IS_TEXT (info->get_item (0), "42");
2610 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2611 "dumpfile.c", expected_impl_line,
2612 "test_capture_of_dump_calls");
2616 /* Scopes. Test with all 4 combinations of
2617 filtering by MSG_PRIORITY_USER_FACING
2618 and/or filtering by MSG_PRIORITY_INTERNALS. */
2619 for (int j = 0; j < 3; j++)
2621 dump_flags_t dump_filter = MSG_ALL_KINDS;
2622 if (j % 2)
2623 dump_filter |= MSG_PRIORITY_USER_FACING;
2624 if (j / 2)
2625 dump_filter |= MSG_PRIORITY_INTERNALS;
2627 temp_dump_context tmp (with_optinfo, true, dump_filter);
2628 /* Emit various messages, mostly with implicit priority. */
2629 dump_printf_loc (MSG_NOTE, stmt, "msg 1\n");
2630 dump_printf_loc (MSG_NOTE | MSG_PRIORITY_INTERNALS, stmt,
2631 "explicitly internal msg\n");
2633 AUTO_DUMP_SCOPE ("outer scope", stmt);
2634 dump_printf_loc (MSG_NOTE, stmt, "msg 2\n");
2636 AUTO_DUMP_SCOPE ("middle scope", stmt);
2637 dump_printf_loc (MSG_NOTE, stmt, "msg 3\n");
2639 AUTO_DUMP_SCOPE ("inner scope", stmt);
2640 dump_printf_loc (MSG_NOTE, stmt, "msg 4\n");
2641 dump_printf_loc (MSG_NOTE | MSG_PRIORITY_USER_FACING, stmt,
2642 "explicitly user-facing msg\n");
2644 dump_printf_loc (MSG_NOTE, stmt, "msg 5\n");
2646 dump_printf_loc (MSG_NOTE, stmt, "msg 6\n");
2648 dump_printf_loc (MSG_NOTE, stmt, "msg 7\n");
2649 const int expected_impl_line = __LINE__ - 1;
2651 switch (dump_filter & MSG_ALL_PRIORITIES)
2653 default:
2654 gcc_unreachable ();
2655 case 0:
2656 ASSERT_DUMPED_TEXT_EQ (tmp, "");
2657 break;
2658 case MSG_PRIORITY_USER_FACING:
2659 ASSERT_DUMPED_TEXT_EQ
2660 (tmp,
2661 "test.txt:5:10: note: msg 1\n"
2662 "test.txt:5:10: note: explicitly user-facing msg\n"
2663 "test.txt:5:10: note: msg 7\n");
2664 break;
2665 case MSG_PRIORITY_INTERNALS:
2666 ASSERT_DUMPED_TEXT_EQ
2667 (tmp,
2668 "test.txt:5:10: note: explicitly internal msg\n"
2669 "test.txt:5:10: note: === outer scope ===\n"
2670 "test.txt:5:10: note: msg 2\n"
2671 "test.txt:5:10: note: === middle scope ===\n"
2672 "test.txt:5:10: note: msg 3\n"
2673 "test.txt:5:10: note: === inner scope ===\n"
2674 "test.txt:5:10: note: msg 4\n"
2675 "test.txt:5:10: note: msg 5\n"
2676 "test.txt:5:10: note: msg 6\n");
2677 break;
2678 case MSG_ALL_PRIORITIES:
2679 ASSERT_DUMPED_TEXT_EQ
2680 (tmp,
2681 "test.txt:5:10: note: msg 1\n"
2682 "test.txt:5:10: note: explicitly internal msg\n"
2683 "test.txt:5:10: note: === outer scope ===\n"
2684 "test.txt:5:10: note: msg 2\n"
2685 "test.txt:5:10: note: === middle scope ===\n"
2686 "test.txt:5:10: note: msg 3\n"
2687 "test.txt:5:10: note: === inner scope ===\n"
2688 "test.txt:5:10: note: msg 4\n"
2689 "test.txt:5:10: note: explicitly user-facing msg\n"
2690 "test.txt:5:10: note: msg 5\n"
2691 "test.txt:5:10: note: msg 6\n"
2692 "test.txt:5:10: note: msg 7\n");
2693 break;
2695 if (with_optinfo)
2697 optinfo *info = tmp.get_pending_optinfo ();
2698 ASSERT_TRUE (info != NULL);
2699 ASSERT_EQ (info->num_items (), 1);
2700 ASSERT_IS_TEXT (info->get_item (0), "msg 7\n");
2701 ASSERT_IMPL_LOCATION_EQ (info->get_impl_location (),
2702 "dumpfile.c", expected_impl_line,
2703 "test_capture_of_dump_calls");
2708 /* Verify that MSG_* affects optinfo->get_kind (); we tested MSG_NOTE
2709 above. */
2711 /* MSG_OPTIMIZED_LOCATIONS. */
2713 temp_dump_context tmp (true, true, MSG_ALL_KINDS);
2714 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, "test");
2715 ASSERT_EQ (tmp.get_pending_optinfo ()->get_kind (),
2716 OPTINFO_KIND_SUCCESS);
2719 /* MSG_MISSED_OPTIMIZATION. */
2721 temp_dump_context tmp (true, true, MSG_ALL_KINDS);
2722 dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc, "test");
2723 ASSERT_EQ (tmp.get_pending_optinfo ()->get_kind (),
2724 OPTINFO_KIND_FAILURE);
2728 /* Verify that MSG_* affect AUTO_DUMP_SCOPE and the dump calls. */
2730 temp_dump_context tmp (false, true,
2731 MSG_OPTIMIZED_LOCATIONS | MSG_ALL_PRIORITIES);
2732 dump_printf_loc (MSG_NOTE, stmt, "msg 1\n");
2734 AUTO_DUMP_SCOPE ("outer scope", stmt);
2735 dump_printf_loc (MSG_NOTE, stmt, "msg 2\n");
2737 AUTO_DUMP_SCOPE ("middle scope", stmt);
2738 dump_printf_loc (MSG_NOTE, stmt, "msg 3\n");
2740 AUTO_DUMP_SCOPE ("inner scope", stmt);
2741 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, stmt, "msg 4\n");
2743 dump_printf_loc (MSG_NOTE, stmt, "msg 5\n");
2745 dump_printf_loc (MSG_NOTE, stmt, "msg 6\n");
2747 dump_printf_loc (MSG_NOTE, stmt, "msg 7\n");
2749 ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: optimized: msg 4\n");
2753 static void
2754 test_pr87025 ()
2756 dump_user_location_t loc
2757 = dump_user_location_t::from_location_t (UNKNOWN_LOCATION);
2759 temp_dump_context tmp (true, true,
2760 MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
2762 AUTO_DUMP_SCOPE ("outer scope", loc);
2763 dump_printf (MSG_NOTE, "msg1\n");
2767 /* Run all of the selftests within this file. */
2769 void
2770 dumpfile_c_tests ()
2772 test_impl_location ();
2773 for_each_line_table_case (test_capture_of_dump_calls);
2774 test_pr87025 ();
2777 } // namespace selftest
2779 #endif /* CHECKING_P */