{"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
{"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}
};
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 ();
|| 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. */
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 ())
}
/* 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;
}
else
delete item;
-
- m_scope_depth++;
}
/* Pop a nested dump scope. */
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 ());
}
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);
}
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);
}
return 0;
ptr = option_value;
- flags = TDF_NONE;
+ flags = MSG_ALL_PRIORITIES;
while (*ptr)
{
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)
}
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;
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);
}
/* 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");
/* 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");
/* 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;");
/* 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");
- 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);
/* 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);
/* 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");
{
/* 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");
/* 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");
/* 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;");
/* 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;");
/* 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");
}
}
- /* 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
{
/* 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);
/* 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);
/* 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);