On October 4, 2018 6:35:57 PM GMT+02:00, David Malcolm <dmalc...@redhat.com> wrote: >On Thu, 2018-10-04 at 12:45 +0200, Richard Biener wrote: >> On Fri, 28 Sep 2018, David Malcolm wrote: >> >> > This patch introduces a verbosity level to dump messages: >> > "user-facing" vs "internals". >> > >> > By default, messages at the top-level dump scope are "user-facing", >> > whereas those that are in nested scopes are implicitly "internals", >> > and are filtered out by -fopt-info unless a new "-internals" sub- >> > option >> > of "-fopt-info" is supplied (intended purely for use by GCC >> > developers). >> > Dumpfiles are unaffected by the change. >> > >> > Given that the vectorizer is the only subsystem using >> > AUTO_DUMP_SCOPE >> > (via DUMP_VECT_SCOPE), this only affects the vectorizer. >> > >> > Filtering out these implementation-detail messages goes a long way >> > towards making -fopt-info-vec-all more accessible to advanced end- >> > users; >> > the follow-up patch restores the most pertinent missing details. >> > >> > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. >> > >> > OK for trunk? >> >> What happens for flags & MSG_ALL_PRIORITIES == 0? That is, >> do we require two bits for the priority at all? > >I didn't want to go through every dump_* call, adding explicit >priorities, hence I went with the implicit priority scheme. >In the patch, > flags & MSG_ALL_PRIORITIES == 0 >is the case for almost all dump_* calls, and indicates "use implicit >priority", making use of the nesting. This is implemented in the patch >in dump_context::apply_dump_filter_p. > >In a few places, some dump_* calls *do* have an explicit priority, in >which case dump_context::apply_dump_filter_p uses it. > >Hence in some ways it's a tri-state: > >(a) implicit > (flags & MSG_ALL_PRIORITIES == 0) > >(b) explicitly "user-facing" > (flags & MSG_ALL_PRIORITIES == MSG_PRIORITY_USER_FACING) > >(b) explicitly "internals" > (flags & MSG_ALL_PRIORITIES == MSG_PRIORITY_INTERNALS) > >...and so needs 2 bits. This scheme also supports messages that are >both "user-facing" *and* "internals", though I don't know if that's >useful. selftest::test_capture_of_dump_calls has test coverage for all >4 combinations of the bits. > >I went with the bits scheme for similarity with the existing MSG_ kinds >(MSG_OPTIMIZED_LOCATIONS, MSG_MISSED_OPTIMIZATION, MSG_NOTE), and the >way it allows filtering based on masking.
Ah, OK, that makes sense. Patch is OK. Richard. >Dave > >> It's an implementation detail of course, generally I like this >> (maybe not so much conflating with nesting, but ...). > > >> Richard. >> >> > gcc/ChangeLog: >> > * doc/invoke.texi (-fopt-info): Document new "internals" >> > sub-option. >> > * dump-context.h (dump_context::apply_dump_filter_p): New decl. >> > * dumpfile.c (dump_options): Update for renaming of MSG_ALL to >> > MSG_ALL_KINDS. >> > (optinfo_verbosity_options): Add "internals". >> > (kind_as_string): Update for renaming of MSG_ALL to >> > MSG_ALL_KINDS. >> > (dump_context::apply_dump_filter_p): New member function. >> > (dump_context::dump_loc): Use apply_dump_filter_p rather than >> > explicitly masking the dump_kind. >> > (dump_context::begin_scope): Increment the scope depth >> > first. Use >> > apply_dump_filter_p rather than explicitly masking the >> > dump_kind. >> > (dump_context::emit_item): Use apply_dump_filter_p rather than >> > explicitly masking the dump_kind. >> > (dump_dec): Likewise. >> > (dump_hex): Likewise. >> > (dump_switch_p_1): Default to MSG_ALL_PRIORITIES. >> > (opt_info_switch_p_1): Default to MSG_PRIORITY_USER_FACING. >> > (opt_info_switch_p): Update handling of default >> > MSG_OPTIMIZED_LOCATIONS to cope with default of >> > MSG_PRIORITY_USER_FACING. >> > (dump_basic_block): Use apply_dump_filter_p rather than >> > explicitly >> > masking the dump_kind. >> > (selftest::test_capture_of_dump_calls): Update >> > test_dump_context >> > instances to use MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING >> > rather >> > than MSG_ALL. Generalize scope test to be run at all four >> > combinations of with/without MSG_PRIORITY_USER_FACING and >> > MSG_PRIORITY_INTERNALS, adding examples of explicit priority >> > for each of the two values. >> > * dumpfile.h (enum dump_flag): Add comment about the MSG_* >> > flags. >> > Rename MSG_ALL to MSG_ALL_KINDS. Add MSG_PRIORITY_USER_FACING, >> > MSG_PRIORITY_INTERNALS, and MSG_ALL_PRIORITIES, updating the >> > values for TDF_COMPARE_DEBUG and TDF_ALL_VALUES. >> > (AUTO_DUMP_SCOPE): Add a note to the comment about the >> > interaction >> > with MSG_PRIORITY_*. >> > * tree-vect-loop-manip.c (vect_loop_versioning): Mark >> > versioning >> > dump messages as MSG_PRIORITY_USER_FACING. >> > * tree-vectorizer.h (DUMP_VECT_SCOPE): Add a note to the >> > comment >> > about the interaction with MSG_PRIORITY_*. >> > >> > gcc/testsuite/ChangeLog: >> > * gcc.dg/plugin/dump-1.c: Update expected output for >> > test_scopes >> > due to "-internals" not being selected. >> > * gcc.dg/plugin/dump-2.c: New test, based on dump-1.c, with >> > "-internals" added to re-enable the output from test_scopes. >> > * gcc.dg/plugin/plugin.exp (plugin_test_list): Add dump-2.c. >> > --- >> > gcc/doc/invoke.texi | 31 ++++- >> > gcc/dump-context.h | 2 + >> > gcc/dumpfile.c | 248 >> > +++++++++++++++++++++++---------- >> > gcc/dumpfile.h | 41 +++++- >> > gcc/testsuite/gcc.dg/plugin/dump-1.c | 10 +- >> > gcc/testsuite/gcc.dg/plugin/dump-2.c | 30 ++++ >> > gcc/testsuite/gcc.dg/plugin/plugin.exp | 3 +- >> > gcc/tree-vect-loop-manip.c | 6 +- >> > gcc/tree-vectorizer.h | 6 +- >> > 9 files changed, 279 insertions(+), 98 deletions(-) >> > create mode 100644 gcc/testsuite/gcc.dg/plugin/dump-2.c >> > >> > diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi >> > index 5c95f67..ab8d9b7e8 100644 >> > --- a/gcc/doc/invoke.texi >> > +++ b/gcc/doc/invoke.texi >> > @@ -14207,14 +14207,21 @@ Controls optimization dumps from various >> > optimization passes. If the >> > @samp{-} separated option keywords to select the dump details and >> > optimizations. >> > >> > -The @var{options} can be divided into two groups: options >> > describing the >> > -verbosity of the dump, and options describing which optimizations >> > -should be included. The options from both the groups can be freely >> > -mixed as they are non-overlapping. However, in case of any >> > conflicts, >> > +The @var{options} can be divided into three groups: >> > +@enumerate >> > +@item >> > +options describing what kinds of messages should be emitted, >> > +@item >> > +options describing the verbosity of the dump, and >> > +@item >> > +options describing which optimizations should be included. >> > +@end enumerate >> > +The options from each group can be freely mixed as they are >> > +non-overlapping. However, in case of any conflicts, >> > the later options override the earlier options on the command >> > line. >> > >> > -The following options control the dump verbosity: >> > +The following options control which kinds of messages should be >> > emitted: >> > >> > @table @samp >> > @item optimized >> > @@ -14233,6 +14240,15 @@ Print detailed optimization information. >> > This includes >> > @samp{optimized}, @samp{missed}, and @samp{note}. >> > @end table >> > >> > +The following option controls the dump verbosity: >> > + >> > +@table @samp >> > +@item internals >> > +By default, only ``high-level'' messages are emitted. This option >> > enables >> > +additional, more detailed, messages, which are likely to only be >> > of interest >> > +to GCC developers. >> > +@end table >> > + >> > One or more of the following option keywords can be used to >> > describe a >> > group of optimizations: >> > >> > @@ -14253,8 +14269,9 @@ the optimization groups listed above. >> > @end table >> > >> > If @var{options} is >> > -omitted, it defaults to @samp{optimized-optall}, which means to >> > dump all >> > -info about successful optimizations from all the passes. >> > +omitted, it defaults to @samp{optimized-optall}, which means to >> > dump messages >> > +about successful optimizations from all the passes, omitting >> > messages >> > +that are treated as ``internals''. >> > >> > If the @var{filename} is provided, then the dumps from all the >> > applicable optimizations are concatenated into the @var{filename}. >> > diff --git a/gcc/dump-context.h b/gcc/dump-context.h >> > index 5b20c15..20b94a7 100644 >> > --- a/gcc/dump-context.h >> > +++ b/gcc/dump-context.h >> > @@ -100,6 +100,8 @@ class dump_context >> > >> > void emit_item (optinfo_item *item, dump_flags_t dump_kind); >> > >> > + bool apply_dump_filter_p (dump_flags_t dump_kind, dump_flags_t >> > filter) const; >> > + >> > private: >> > optinfo &ensure_pending_optinfo (); >> > optinfo &begin_next_optinfo (const dump_location_t &loc); >> > diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c >> > index d359e41..e15edc7 100644 >> > --- a/gcc/dumpfile.c >> > +++ b/gcc/dumpfile.c >> > @@ -141,7 +141,7 @@ static const kv_pair<dump_flags_t> >> > dump_options[] = >> > {"optimized", MSG_OPTIMIZED_LOCATIONS}, >> > {"missed", MSG_MISSED_OPTIMIZATION}, >> > {"note", MSG_NOTE}, >> > - {"optall", MSG_ALL}, >> > + {"optall", MSG_ALL_KINDS}, >> > {"all", dump_flags_t (TDF_ALL_VALUES >> > & ~(TDF_RAW | TDF_SLIM | TDF_LINENO | >> > TDF_GRAPH >> > | TDF_STMTADDR | TDF_RHS_ONLY | >> > TDF_NOUID >> > @@ -157,7 +157,8 @@ static const kv_pair<dump_flags_t> >> > optinfo_verbosity_options[] = >> > {"optimized", MSG_OPTIMIZED_LOCATIONS}, >> > {"missed", MSG_MISSED_OPTIMIZATION}, >> > {"note", MSG_NOTE}, >> > - {"all", MSG_ALL}, >> > + {"all", MSG_ALL_KINDS}, >> > + {"internals", MSG_PRIORITY_INTERNALS}, >> > {NULL, TDF_NONE} >> > }; >> > >> > @@ -449,7 +450,7 @@ dump_user_location_t::from_function_decl (tree >> > fndecl) >> > static const char * >> > kind_as_string (dump_flags_t dump_kind) >> > { >> > - switch (dump_kind & MSG_ALL) >> > + switch (dump_kind & MSG_ALL_KINDS) >> > { >> > default: >> > gcc_unreachable (); >> > @@ -524,6 +525,35 @@ dump_context::refresh_dumps_are_enabled () >> > || m_test_pp); >> > } >> > >> > +/* Determine if a message of kind DUMP_KIND and at the current >> > scope depth >> > + should be printed. >> > + >> > + Only show messages that match FILTER both on their kind *and* >> > + their priority. */ >> > + >> > +bool >> > +dump_context::apply_dump_filter_p (dump_flags_t dump_kind, >> > + dump_flags_t filter) const >> > +{ >> > + /* Few messages, if any, have an explicit MSG_PRIORITY. >> > + If DUMP_KIND does, we'll use it. >> > + Otherwise, generate an implicit priority value for the >> > message based >> > + on the current scope depth. >> > + Messages at the top-level scope are MSG_PRIORITY_USER_FACING, >> > + whereas those in nested scopes are >> > MSG_PRIORITY_INTERNALS. */ >> > + if (!(dump_kind & MSG_ALL_PRIORITIES)) >> > + { >> > + dump_flags_t implicit_priority >> > + = (m_scope_depth > 0 >> > + ? MSG_PRIORITY_INTERNALS >> > + : MSG_PRIORITY_USER_FACING); >> > + dump_kind |= implicit_priority; >> > + } >> > + >> > + return (dump_kind & (filter & MSG_ALL_KINDS) >> > + && dump_kind & (filter & MSG_ALL_PRIORITIES)); >> > +} >> > + >> > /* Print LOC to the appropriate dump destinations, given >> > DUMP_KIND. >> > If optinfos are enabled, begin a new optinfo. */ >> > >> > @@ -534,14 +564,14 @@ dump_context::dump_loc (dump_flags_t >> > dump_kind, const dump_location_t &loc) >> > >> > location_t srcloc = loc.get_location_t (); >> > >> > - if (dump_file && (dump_kind & pflags)) >> > + if (dump_file && apply_dump_filter_p (dump_kind, pflags)) >> > ::dump_loc (dump_kind, dump_file, srcloc); >> > >> > - if (alt_dump_file && (dump_kind & alt_flags)) >> > + if (alt_dump_file && apply_dump_filter_p (dump_kind, alt_flags)) >> > ::dump_loc (dump_kind, alt_dump_file, srcloc); >> > >> > /* Support for temp_dump_context in selftests. */ >> > - if (m_test_pp && (dump_kind & m_test_pp_flags)) >> > + if (m_test_pp && apply_dump_filter_p (dump_kind, >> > m_test_pp_flags)) >> > ::dump_loc (dump_kind, m_test_pp, srcloc); >> > >> > if (optinfo_enabled_p ()) >> > @@ -1067,22 +1097,24 @@ dump_context::get_scope_depth () const >> > } >> > >> > /* Push a nested dump scope. >> > + Increment the scope depth. >> > Print "=== NAME ===\n" to the dumpfile, if any, and to the >> > -fopt-info >> > destination, if any. >> > - Emit a "scope" optinfo if optinfos are enabled. >> > - Increment the scope depth. */ >> > + Emit a "scope" optinfo if optinfos are enabled. */ >> > >> > void >> > dump_context::begin_scope (const char *name, const dump_location_t >> > &loc) >> > { >> > - if (dump_file && (MSG_NOTE & pflags)) >> > + m_scope_depth++; >> > + >> > + if (dump_file && apply_dump_filter_p (MSG_NOTE, pflags)) >> > ::dump_loc (MSG_NOTE, dump_file, loc.get_location_t ()); >> > >> > - if (alt_dump_file && (MSG_NOTE & alt_flags)) >> > + if (alt_dump_file && apply_dump_filter_p (MSG_NOTE, alt_flags)) >> > ::dump_loc (MSG_NOTE, alt_dump_file, loc.get_location_t ()); >> > >> > /* Support for temp_dump_context in selftests. */ >> > - if (m_test_pp && (MSG_NOTE & m_test_pp_flags)) >> > + if (m_test_pp && apply_dump_filter_p (MSG_NOTE, >> > m_test_pp_flags)) >> > ::dump_loc (MSG_NOTE, m_test_pp, loc.get_location_t ()); >> > >> > pretty_printer pp; >> > @@ -1100,8 +1132,6 @@ dump_context::begin_scope (const char *name, >> > const dump_location_t &loc) >> > } >> > else >> > delete item; >> > - >> > - m_scope_depth++; >> > } >> > >> > /* Pop a nested dump scope. */ >> > @@ -1155,14 +1185,14 @@ dump_context::end_any_optinfo () >> > void >> > dump_context::emit_item (optinfo_item *item, dump_flags_t >> > dump_kind) >> > { >> > - if (dump_file && (dump_kind & pflags)) >> > + if (dump_file && apply_dump_filter_p (dump_kind, pflags)) >> > fprintf (dump_file, "%s", item->get_text ()); >> > >> > - if (alt_dump_file && (dump_kind & alt_flags)) >> > + if (alt_dump_file && apply_dump_filter_p (dump_kind, alt_flags)) >> > fprintf (alt_dump_file, "%s", item->get_text ()); >> > >> > /* Support for temp_dump_context in selftests. */ >> > - if (m_test_pp && (dump_kind & m_test_pp_flags)) >> > + if (m_test_pp && apply_dump_filter_p (dump_kind, >> > m_test_pp_flags)) >> > pp_string (m_test_pp, item->get_text ()); >> > } >> > >> > @@ -1278,10 +1308,12 @@ template void dump_dec (dump_flags_t, const >> > poly_widest_int &); >> > void >> > dump_dec (dump_flags_t dump_kind, const poly_wide_int &value, >> > signop sgn) >> > { >> > - if (dump_file && (dump_kind & pflags)) >> > + if (dump_file >> > + && dump_context::get ().apply_dump_filter_p (dump_kind, >> > pflags)) >> > print_dec (value, dump_file, sgn); >> > >> > - if (alt_dump_file && (dump_kind & alt_flags)) >> > + if (alt_dump_file >> > + && dump_context::get ().apply_dump_filter_p (dump_kind, >> > alt_flags)) >> > print_dec (value, alt_dump_file, sgn); >> > } >> > >> > @@ -1290,10 +1322,12 @@ dump_dec (dump_flags_t dump_kind, const >> > poly_wide_int &value, signop sgn) >> > void >> > dump_hex (dump_flags_t dump_kind, const poly_wide_int &value) >> > { >> > - if (dump_file && (dump_kind & pflags)) >> > + if (dump_file >> > + && dump_context::get ().apply_dump_filter_p (dump_kind, >> > pflags)) >> > print_hex (value, dump_file); >> > >> > - if (alt_dump_file && (dump_kind & alt_flags)) >> > + if (alt_dump_file >> > + && dump_context::get ().apply_dump_filter_p (dump_kind, >> > alt_flags)) >> > print_hex (value, alt_dump_file); >> > } >> > >> > @@ -1698,7 +1732,7 @@ dump_switch_p_1 (const char *arg, struct >> > dump_file_info *dfi, bool doglob) >> > return 0; >> > >> > ptr = option_value; >> > - flags = TDF_NONE; >> > + flags = MSG_ALL_PRIORITIES; >> > >> > while (*ptr) >> > { >> > @@ -1794,7 +1828,11 @@ opt_info_switch_p_1 (const char *arg, >> > dump_flags_t *flags, >> > ptr = option_value; >> > >> > *filename = NULL; >> > - *flags = TDF_NONE; >> > + >> > + /* Default to filtering out "internals" messages, and retaining >> > + "user-facing" messages. */ >> > + *flags = MSG_PRIORITY_USER_FACING; >> > + >> > *optgroup_flags = OPTGROUP_NONE; >> > >> > if (!ptr) >> > @@ -1883,8 +1921,8 @@ opt_info_switch_p (const char *arg) >> > } >> > >> > file_seen = xstrdup (filename); >> > - if (!flags) >> > - flags = MSG_OPTIMIZED_LOCATIONS; >> > + if (!(flags & MSG_ALL_KINDS)) >> > + flags |= MSG_OPTIMIZED_LOCATIONS; >> > if (!optgroup_flags) >> > optgroup_flags = OPTGROUP_ALL; >> > >> > @@ -1896,9 +1934,11 @@ opt_info_switch_p (const char *arg) >> > void >> > dump_basic_block (dump_flags_t dump_kind, basic_block bb, int >> > indent) >> > { >> > - if (dump_file && (dump_kind & pflags)) >> > + if (dump_file >> > + && dump_context::get ().apply_dump_filter_p (dump_kind, >> > pflags)) >> > dump_bb (dump_file, bb, indent, TDF_DETAILS); >> > - if (alt_dump_file && (dump_kind & alt_flags)) >> > + if (alt_dump_file >> > + && dump_context::get ().apply_dump_filter_p (dump_kind, >> > alt_flags)) >> > dump_bb (alt_dump_file, bb, indent, TDF_DETAILS); >> > } >> > >> > @@ -2104,7 +2144,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* Test of dump_printf. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_printf (MSG_NOTE, "int: %i str: %s", 42, "foo"); >> > >> > ASSERT_DUMPED_TEXT_EQ (tmp, "int: 42 str: foo"); >> > @@ -2120,7 +2161,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* Test of dump_printf with %T. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_printf (MSG_NOTE, "tree: %T", integer_zero_node); >> > >> > ASSERT_DUMPED_TEXT_EQ (tmp, "tree: 0"); >> > @@ -2137,7 +2179,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* Test of dump_printf with %E. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_printf (MSG_NOTE, "gimple: %E", stmt); >> > >> > ASSERT_DUMPED_TEXT_EQ (tmp, "gimple: return;"); >> > @@ -2154,7 +2197,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* Test of dump_printf with %G. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_printf (MSG_NOTE, "gimple: %G", stmt); >> > >> > ASSERT_DUMPED_TEXT_EQ (tmp, "gimple: return;\n"); >> > @@ -2176,7 +2220,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > - multiple dump-specific format codes: some consecutive, >> > others >> > separated by text, trailing text after the final one. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_printf_loc (MSG_NOTE, loc, "before %T and %T" >> > " %i consecutive %E%E after\n", >> > integer_zero_node, test_decl, 42, stmt, >> > stmt); >> > @@ -2203,7 +2248,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* Tree, via dump_generic_expr. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_printf_loc (MSG_NOTE, loc, "test of tree: "); >> > dump_generic_expr (MSG_NOTE, TDF_SLIM, integer_zero_node); >> > >> > @@ -2222,7 +2268,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* Tree, via dump_generic_expr_loc. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_generic_expr_loc (MSG_NOTE, loc, TDF_SLIM, >> > integer_one_node); >> > >> > ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: 1"); >> > @@ -2241,7 +2288,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > { >> > /* dump_gimple_stmt_loc. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_gimple_stmt_loc (MSG_NOTE, loc, TDF_SLIM, stmt, 2); >> > >> > ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: >> > return;\n"); >> > @@ -2256,7 +2304,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* dump_gimple_stmt. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_gimple_stmt (MSG_NOTE, TDF_SLIM, stmt, 2); >> > >> > ASSERT_DUMPED_TEXT_EQ (tmp, "return;\n"); >> > @@ -2271,7 +2320,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* dump_gimple_expr_loc. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_gimple_expr_loc (MSG_NOTE, loc, TDF_SLIM, stmt, 2); >> > >> > ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: >> > return;"); >> > @@ -2286,7 +2336,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* dump_gimple_expr. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_gimple_expr (MSG_NOTE, TDF_SLIM, stmt, 2); >> > >> > ASSERT_DUMPED_TEXT_EQ (tmp, "return;"); >> > @@ -2302,7 +2353,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* poly_int. */ >> > { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > + temp_dump_context tmp (with_optinfo, >> > + MSG_ALL_KINDS | >> > MSG_PRIORITY_USER_FACING); >> > dump_dec (MSG_NOTE, poly_int64 (42)); >> > >> > ASSERT_DUMPED_TEXT_EQ (tmp, "42"); >> > @@ -2315,45 +2367,92 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > } >> > } >> > >> > - /* scopes. */ >> > - { >> > - temp_dump_context tmp (with_optinfo, MSG_ALL); >> > - dump_printf_loc (MSG_NOTE, stmt, "msg 1\n"); >> > + /* Scopes. Test with all 4 combinations of >> > + filtering by MSG_PRIORITY_USER_FACING >> > + and/or filtering by MSG_PRIORITY_INTERNALS. */ >> > + for (int j = 0; j < 3; j++) >> > { >> > - AUTO_DUMP_SCOPE ("outer scope", stmt); >> > - dump_printf_loc (MSG_NOTE, stmt, "msg 2\n"); >> > + dump_flags_t dump_filter = MSG_ALL_KINDS; >> > + if (j % 2) >> > + dump_filter |= MSG_PRIORITY_USER_FACING; >> > + if (j / 2) >> > + dump_filter |= MSG_PRIORITY_INTERNALS; >> > + >> > + temp_dump_context tmp (with_optinfo, dump_filter); >> > + /* Emit various messages, mostly with implicit >> > priority. */ >> > + dump_printf_loc (MSG_NOTE, stmt, "msg 1\n"); >> > + dump_printf_loc (MSG_NOTE | MSG_PRIORITY_INTERNALS, >> > stmt, >> > + "explicitly internal msg\n"); >> > { >> > - AUTO_DUMP_SCOPE ("middle scope", stmt); >> > - dump_printf_loc (MSG_NOTE, stmt, "msg 3\n"); >> > + AUTO_DUMP_SCOPE ("outer scope", stmt); >> > + dump_printf_loc (MSG_NOTE, stmt, "msg 2\n"); >> > { >> > - AUTO_DUMP_SCOPE ("inner scope", stmt); >> > - dump_printf_loc (MSG_NOTE, stmt, "msg 4\n"); >> > + AUTO_DUMP_SCOPE ("middle scope", stmt); >> > + dump_printf_loc (MSG_NOTE, stmt, "msg 3\n"); >> > + { >> > + AUTO_DUMP_SCOPE ("inner scope", stmt); >> > + dump_printf_loc (MSG_NOTE, stmt, "msg 4\n"); >> > + dump_printf_loc (MSG_NOTE | >> > MSG_PRIORITY_USER_FACING, stmt, >> > + "explicitly user-facing msg\n"); >> > + } >> > + dump_printf_loc (MSG_NOTE, stmt, "msg 5\n"); >> > } >> > - dump_printf_loc (MSG_NOTE, stmt, "msg 5\n"); >> > + dump_printf_loc (MSG_NOTE, stmt, "msg 6\n"); >> > } >> > - dump_printf_loc (MSG_NOTE, stmt, "msg 6\n"); >> > - } >> > - dump_printf_loc (MSG_NOTE, stmt, "msg 7\n"); >> > + dump_printf_loc (MSG_NOTE, stmt, "msg 7\n"); >> > >> > - ASSERT_DUMPED_TEXT_EQ (tmp, >> > - "test.txt:5:10: note: msg 1\n" >> > - "test.txt:5:10: note: === outer >> > scope ===\n" >> > - "test.txt:5:10: note: msg 2\n" >> > - "test.txt:5:10: note: === middle >> > scope ===\n" >> > - "test.txt:5:10: note: msg 3\n" >> > - "test.txt:5:10: note: === inner >> > scope ===\n" >> > - "test.txt:5:10: note: msg 4\n" >> > - "test.txt:5:10: note: msg 5\n" >> > - "test.txt:5:10: note: msg 6\n" >> > - "test.txt:5:10: note: msg 7\n"); >> > - if (with_optinfo) >> > - { >> > - optinfo *info = tmp.get_pending_optinfo (); >> > - ASSERT_TRUE (info != NULL); >> > - ASSERT_EQ (info->num_items (), 1); >> > - ASSERT_IS_TEXT (info->get_item (0), "msg 7\n"); >> > - } >> > - } >> > + switch (dump_filter & MSG_ALL_PRIORITIES) >> > + { >> > + default: >> > + gcc_unreachable (); >> > + case 0: >> > + ASSERT_DUMPED_TEXT_EQ (tmp, ""); >> > + break; >> > + case MSG_PRIORITY_USER_FACING: >> > + ASSERT_DUMPED_TEXT_EQ >> > + (tmp, >> > + "test.txt:5:10: note: msg 1\n" >> > + "test.txt:5:10: note: explicitly user-facing >> > msg\n" >> > + "test.txt:5:10: note: msg 7\n"); >> > + break; >> > + case MSG_PRIORITY_INTERNALS: >> > + ASSERT_DUMPED_TEXT_EQ >> > + (tmp, >> > + "test.txt:5:10: note: explicitly internal msg\n" >> > + "test.txt:5:10: note: === outer scope ===\n" >> > + "test.txt:5:10: note: msg 2\n" >> > + "test.txt:5:10: note: === middle scope ===\n" >> > + "test.txt:5:10: note: msg 3\n" >> > + "test.txt:5:10: note: === inner scope ===\n" >> > + "test.txt:5:10: note: msg 4\n" >> > + "test.txt:5:10: note: msg 5\n" >> > + "test.txt:5:10: note: msg 6\n"); >> > + break; >> > + case MSG_ALL_PRIORITIES: >> > + ASSERT_DUMPED_TEXT_EQ >> > + (tmp, >> > + "test.txt:5:10: note: msg 1\n" >> > + "test.txt:5:10: note: explicitly internal msg\n" >> > + "test.txt:5:10: note: === outer scope ===\n" >> > + "test.txt:5:10: note: msg 2\n" >> > + "test.txt:5:10: note: === middle scope ===\n" >> > + "test.txt:5:10: note: msg 3\n" >> > + "test.txt:5:10: note: === inner scope ===\n" >> > + "test.txt:5:10: note: msg 4\n" >> > + "test.txt:5:10: note: explicitly user-facing >> > msg\n" >> > + "test.txt:5:10: note: msg 5\n" >> > + "test.txt:5:10: note: msg 6\n" >> > + "test.txt:5:10: note: msg 7\n"); >> > + break; >> > + } >> > + if (with_optinfo) >> > + { >> > + optinfo *info = tmp.get_pending_optinfo (); >> > + ASSERT_TRUE (info != NULL); >> > + ASSERT_EQ (info->num_items (), 1); >> > + ASSERT_IS_TEXT (info->get_item (0), "msg 7\n"); >> > + } >> > + } >> > } >> > >> > /* Verify that MSG_* affects optinfo->get_kind (); we tested >> > MSG_NOTE >> > @@ -2361,7 +2460,7 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > { >> > /* MSG_OPTIMIZED_LOCATIONS. */ >> > { >> > - temp_dump_context tmp (true, MSG_ALL); >> > + temp_dump_context tmp (true, MSG_ALL_KINDS); >> > dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, "test"); >> > ASSERT_EQ (tmp.get_pending_optinfo ()->get_kind (), >> > OPTINFO_KIND_SUCCESS); >> > @@ -2369,7 +2468,7 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* MSG_MISSED_OPTIMIZATION. */ >> > { >> > - temp_dump_context tmp (true, MSG_ALL); >> > + temp_dump_context tmp (true, MSG_ALL_KINDS); >> > dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc, "test"); >> > ASSERT_EQ (tmp.get_pending_optinfo ()->get_kind (), >> > OPTINFO_KIND_FAILURE); >> > @@ -2378,7 +2477,8 @@ test_capture_of_dump_calls (const >> > line_table_case &case_) >> > >> > /* Verify that MSG_* affect AUTO_DUMP_SCOPE and the dump >> > calls. */ >> > { >> > - temp_dump_context tmp (false, MSG_OPTIMIZED_LOCATIONS); >> > + temp_dump_context tmp (false, >> > + MSG_OPTIMIZED_LOCATIONS | >> > MSG_ALL_PRIORITIES); >> > dump_printf_loc (MSG_NOTE, stmt, "msg 1\n"); >> > { >> > AUTO_DUMP_SCOPE ("outer scope", stmt); >> > diff --git a/gcc/dumpfile.h b/gcc/dumpfile.h >> > index 057ca46..5933905 100644 >> > --- a/gcc/dumpfile.h >> > +++ b/gcc/dumpfile.h >> > @@ -145,6 +145,9 @@ enum dump_flag >> > /* Dump folding details. */ >> > TDF_FOLDING = (1 << 21), >> > >> > + /* MSG_* flags for expressing the kinds of message to >> > + be emitted by -fopt-info. */ >> > + >> > /* -fopt-info optimized sources. */ >> > MSG_OPTIMIZED_LOCATIONS = (1 << 22), >> > >> > @@ -154,15 +157,37 @@ enum dump_flag >> > /* General optimization info. */ >> > MSG_NOTE = (1 << 24), >> > >> > - MSG_ALL = (MSG_OPTIMIZED_LOCATIONS >> > - | MSG_MISSED_OPTIMIZATION >> > - | MSG_NOTE), >> > + /* Mask for selecting MSG_-kind flags. */ >> > + MSG_ALL_KINDS = (MSG_OPTIMIZED_LOCATIONS >> > + | MSG_MISSED_OPTIMIZATION >> > + | MSG_NOTE), >> > + >> > + /* MSG_PRIORITY_* flags for expressing the priority levels of >> > message >> > + to be emitted by -fopt-info, and filtering on them. >> > + By default, messages at the top-level dump scope are "user- >> > facing", >> > + whereas those that are in nested scopes are implicitly >> > "internals". >> > + This behavior can be overridden for a given dump message by >> > explicitly >> > + specifying one of the MSG_PRIORITY_* flags. >> > + >> > + By default, dump files show both kinds of message, whereas >> > -fopt-info >> > + only shows "user-facing" messages, and requires the "- >> > internals" >> > + sub-option of -fopt-info to show the internal messages. */ >> > + >> > + /* Implicitly supplied for messages at the top-level dump >> > scope. */ >> > + MSG_PRIORITY_USER_FACING = (1 << 25), >> > + >> > + /* Implicitly supplied for messages within nested dump >> > scopes. */ >> > + MSG_PRIORITY_INTERNALS = (1 << 26), >> > + >> > + /* Mask for selecting MSG_PRIORITY_* flags. */ >> > + MSG_ALL_PRIORITIES = (MSG_PRIORITY_USER_FACING >> > + | MSG_PRIORITY_INTERNALS), >> > >> > /* Dumping for -fcompare-debug. */ >> > - TDF_COMPARE_DEBUG = (1 << 25), >> > + TDF_COMPARE_DEBUG = (1 << 27), >> > >> > /* All values. */ >> > - TDF_ALL_VALUES = (1 << 26) - 1 >> > + TDF_ALL_VALUES = (1 << 28) - 1 >> > }; >> > >> > /* Dump flags type. */ >> > @@ -549,7 +574,11 @@ class auto_dump_scope >> > and then calling >> > dump_end_scope (); >> > once the object goes out of scope, thus capturing the nesting >> > of >> > - the scopes. */ >> > + the scopes. >> > + >> > + These scopes affect dump messages within them: dump messages at >> > the >> > + top level implicitly default to MSG_PRIORITY_USER_FACING, >> > whereas those >> > + in a nested scope implicitly default to >> > MSG_PRIORITY_INTERNALS. */ >> > >> > #define AUTO_DUMP_SCOPE(NAME, LOC) \ >> > auto_dump_scope scope (NAME, LOC) >> > diff --git a/gcc/testsuite/gcc.dg/plugin/dump-1.c >> > b/gcc/testsuite/gcc.dg/plugin/dump-1.c >> > index 165a9c1..95bd7a4 100644 >> > --- a/gcc/testsuite/gcc.dg/plugin/dump-1.c >> > +++ b/gcc/testsuite/gcc.dg/plugin/dump-1.c >> > @@ -18,11 +18,7 @@ void test_remarks (void) >> > test_wide_int (); /* { dg-message "test of wide int: 0" } */ >> > test_poly_int (); /* { dg-message "test of poly int: 42" } */ >> > >> > - test_scopes (); /* { dg-line test_scopes_line } */ >> > - /* { dg-message "=== outer scope ===" "" { target *-*-* } >> > test_scopes_line } */ >> > -