diff options
author | David Malcolm <dmalcolm@redhat.com> | 2018-11-27 00:55:28 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-11-27 00:55:28 +0000 |
commit | 3da39f52ff740ad4263a000c48fd5a6d9afd18fd (patch) | |
tree | 1bf30cfb819f615b76e6a2fdbaa3a2d58e4d8edb /gcc/dumpfile.h | |
parent | 27c16e61cb99796a912d491ad5d77ed7873a4eed (diff) | |
download | gcc-3da39f52ff740ad4263a000c48fd5a6d9afd18fd.zip gcc-3da39f52ff740ad4263a000c48fd5a6d9afd18fd.tar.gz gcc-3da39f52ff740ad4263a000c48fd5a6d9afd18fd.tar.bz2 |
Fix missing dump_impl_location_t values, using a new dump_metadata_t
The dump_* API attempts to capture emission location metadata for the
various dump messages, but looking in -fsave-optimization-record shows
that many dump messages are lacking useful impl_location values, instead
having this location within dumpfile.c:
"impl_location": {
"file": "../../src/gcc/dumpfile.c",
"function": "ensure_pending_optinfo",
"line": 1169
},
The problem is that the auto-capturing of dump_impl_location_t is tied to
dump_location_t, and this is tied to the dump_*_loc calls. If a message
comes from a dump_* call without a "_loc" suffix (e.g. dump_printf), the
current code synthesizes the dump_location_t within
dump_context::ensure_pending_optinfo, and thus saves the useless
impl_location seen above.
This patch fixes things by changing the dump_* API so that, rather than
taking a dump_flags_t, they take a new class dump_metadata_t, which is
constructed from a dump_flags_t, but captures the emission location.
Hence e.g.:
dump_printf (MSG_NOTE, "some message\n");
implicitly builds a dump_metadata_t wrapping the MSG_NOTE and the
emission location. If there are several dump_printf calls without
a dump_*_loc call, the emission location within the optinfo is that
of the first dump call within it.
The patch updates selftest::test_capture_of_dump_calls to verify
that the impl location of various dump_* calls is captured. I also
verified things manually.
gcc/ChangeLog:
* dump-context.h (dump_context::dump_loc): Convert 1st param from
dump_flags_t to const dump_metadata_t &. Convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_context::dump_loc_immediate): Convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_context::dump_gimple_stmt): Convert 1st param from
dump_flags_t to const dump_metadata_t &.
(dump_context::void dump_gimple_stmt_loc): Likewise; convert
2nd param from const dump_location_t & to
const dump_user_location_t &.
(dump_context::dump_gimple_expr): Convert 1st param from
dump_flags_t to const dump_metadata_t &.
(dump_context::dump_gimple_expr_loc): Likewise; convert
2nd param from const dump_location_t & to
const dump_user_location_t &.
(dump_context::dump_generic_expr): Convert 1st param from
dump_flags_t to const dump_metadata_t &.
(dump_context::dump_generic_expr_loc): Likewise; convert
2nd param from const dump_location_t & to
const dump_user_location_t &.
(dump_context::dump_printf_va): Convert 1st param from
dump_flags_t to const dump_metadata_t &.
(dump_context::dump_printf_loc_va): Likewise; convert
2nd param from const dump_location_t & to
const dump_user_location_t &.
(dump_context::dump_dec): Convert 1st param from
dump_flags_t to const dump_metadata_t &.
(dump_context::dump_symtab_node): Likewise.
(dump_context::begin_scope): Split out 2nd param into
user and impl locations.
(dump_context::ensure_pending_optinfo): Add metadata param.
(dump_context::begin_next_optinfo): Replace dump_location_t param
with metadata and user location.
* dumpfile.c (dump_context::dump_loc): Convert 1st param from
dump_flags_t to const dump_metadata_t &. Convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_context::dump_loc_immediate): Convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_context::dump_gimple_stmt): Convert 1st param from
dump_flags_t to const dump_metadata_t &.
(dump_context::void dump_gimple_stmt_loc): Likewise; convert
2nd param from const dump_location_t & to
const dump_user_location_t &.
(dump_context::dump_gimple_expr): Convert 1st param from
dump_flags_t to const dump_metadata_t &.
(dump_context::dump_gimple_expr_loc): Likewise; convert
2nd param from const dump_location_t & to
const dump_user_location_t &.
(dump_context::dump_generic_expr): Convert 1st param from
dump_flags_t to const dump_metadata_t &.
(dump_context::dump_generic_expr_loc): Likewise; convert
2nd param from const dump_location_t & to
const dump_user_location_t &.
(dump_context::dump_printf_va): Convert 1st param from
dump_flags_t to const dump_metadata_t &.
(dump_context::dump_printf_loc_va): Likewise; convert
2nd param from const dump_location_t & to
const dump_user_location_t &.
(dump_context::dump_dec): Convert 1st param from
dump_flags_t to const dump_metadata_t &.
(dump_context::dump_symtab_node): Likewise.
(dump_context::begin_scope): Split out 2nd param into
user and impl locations.
(dump_context::ensure_pending_optinfo): Add metadata param.
(dump_context::begin_next_optinfo): Replace dump_location_t param
with metadata and user location.
(dump_gimple_stmt): Convert 1st param from dump_flags_t to
const dump_metadata_t &.
(dump_gimple_stmt_loc): Likewise; convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_gimple_expr): Convert 1st param from dump_flags_t to
const dump_metadata_t &.
(dump_gimple_expr_loc): Likewise; convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_generic_expr): Convert 1st param from dump_flags_t to
const dump_metadata_t &.
(dump_generic_expr_loc): Likewise; convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_printf): Convert 1st param from dump_flags_t to
const dump_metadata_t &.
(dump_printf_loc): Likewise; convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_dec): Convert 1st param from dump_flags_t to
const dump_metadata_t &.
(dump_symtab_node): Likewise.
(dump_begin_scope): Split out 2nd param into user and impl
locations.
(selftest::assert_impl_location_eq): New function.
(ASSERT_IMPL_LOCATION_EQ): New macro.
(selftest::test_impl_location): Update to use
ASSERT_IMPL_LOCATION_EQ.
(selftest::test_capture_of_dump_calls): Convert "loc" to
dump_user_location_t. Add ASSERT_IMPL_LOCATION_EQ throughout,
verifying line numbers of dump emissions.
* dumpfile.h (class dump_metadata_t): New class.
(dump_printf): Convert 1st param from dump_flags_t to
const dump_metadata_t &.
(dump_printf_loc): Likewise; convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_generic_expr_loc): Likewise.
(dump_generic_expr): Convert 1st param from dump_flags_t to
const dump_metadata_t &.
(dump_gimple_stmt_loc): Likewise; convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_gimple_stmt): Convert 1st param from dump_flags_t to
const dump_metadata_t &.
(dump_gimple_expr_loc): Likewise; convert 2nd param from
const dump_location_t & to const dump_user_location_t &.
(dump_gimple_expr): Convert 1st param from dump_flags_t to
const dump_metadata_t &.
(dump_symtab_node): Likewise.
(dump_dec): Likewise.
(dump_begin_scope): Split out 2nd param into user and impl
locations.
(auto_dump_scope::auto_dump_scope): Split "loc" param into a user
location and impl_location, and capture the impl_location.
(AUTO_DUMP_SCOPE): Rename param from LOC to USER_LOC.
* loop-unroll.c (report_unroll): Update for changes to
dump_printf_loc and dump_printf.
* opt-problem.cc (opt_problem::opt_problem): Update for change to
dump_loc.
* optinfo-emit-json.cc
(selftest::test_building_json_from_dump_calls): Convert "loc" from
dump_location_t to dump_user_location_t.
* optinfo.cc (optinfo::emit_for_opt_problem): Update for change in
dump_loc_immediate.
* profile.c (compute_branch_probabilities): Update for change to
dump_printf_loc.
* selftest.h (ASSERT_STR_CONTAINS_AT): New macro.
* tree-vect-slp.c (vect_print_slp_tree): Update for change to
dump_printf_loc.
From-SVN: r266501
Diffstat (limited to 'gcc/dumpfile.h')
-rw-r--r-- | gcc/dumpfile.h | 72 |
1 files changed, 56 insertions, 16 deletions
diff --git a/gcc/dumpfile.h b/gcc/dumpfile.h index c82157d..d51e4ce 100644 --- a/gcc/dumpfile.h +++ b/gcc/dumpfile.h @@ -385,6 +385,38 @@ struct dump_impl_location_t const char *m_function; }; +/* A bundle of metadata for describing a dump message: + (a) the dump_flags + (b) the source location within the compiler/plugin. + + The constructors use default parameters so that (b) gets sets up + automatically. + + Hence you can pass in e.g. MSG_NOTE, and the dump call + will automatically record where in GCC's source code the + dump was emitted from. */ + +class dump_metadata_t +{ + public: + dump_metadata_t (dump_flags_t dump_flags, + const dump_impl_location_t &impl_location + = dump_impl_location_t ()) + : m_dump_flags (dump_flags), + m_impl_location (impl_location) + { + } + + dump_flags_t get_dump_flags () const { return m_dump_flags; } + + const dump_impl_location_t & + get_impl_location () const { return m_impl_location; } + + private: + dump_flags_t m_dump_flags; + dump_impl_location_t m_impl_location; +}; + /* A bundle of information for describing the location of a dump message: (a) the source location and hotness within the user's code, together with (b) the source location within the compiler/plugin. @@ -521,27 +553,30 @@ dump_enabled_p (void) to minimize the work done for the common case where dumps are disabled. */ -extern void dump_printf (dump_flags_t, const char *, ...) +extern void dump_printf (const dump_metadata_t &, const char *, ...) ATTRIBUTE_GCC_DUMP_PRINTF (2, 3); -extern void dump_printf_loc (dump_flags_t, const dump_location_t &, +extern void dump_printf_loc (const dump_metadata_t &, const dump_user_location_t &, const char *, ...) ATTRIBUTE_GCC_DUMP_PRINTF (3, 0); extern void dump_function (int phase, tree fn); extern void dump_basic_block (dump_flags_t, basic_block, int); -extern void dump_generic_expr_loc (dump_flags_t, const dump_location_t &, +extern void dump_generic_expr_loc (const dump_metadata_t &, + const dump_user_location_t &, dump_flags_t, tree); -extern void dump_generic_expr (dump_flags_t, dump_flags_t, tree); -extern void dump_gimple_stmt_loc (dump_flags_t, const dump_location_t &, +extern void dump_generic_expr (const dump_metadata_t &, dump_flags_t, tree); +extern void dump_gimple_stmt_loc (const dump_metadata_t &, + const dump_user_location_t &, dump_flags_t, gimple *, int); -extern void dump_gimple_stmt (dump_flags_t, dump_flags_t, gimple *, int); -extern void dump_gimple_expr_loc (dump_flags_t, const dump_location_t &, +extern void dump_gimple_stmt (const dump_metadata_t &, dump_flags_t, gimple *, int); +extern void dump_gimple_expr_loc (const dump_metadata_t &, + const dump_user_location_t &, dump_flags_t, gimple *, int); -extern void dump_gimple_expr (dump_flags_t, dump_flags_t, gimple *, int); -extern void dump_symtab_node (dump_flags_t, symtab_node *); +extern void dump_gimple_expr (const dump_metadata_t &, dump_flags_t, gimple *, int); +extern void dump_symtab_node (const dump_metadata_t &, symtab_node *); template<unsigned int N, typename C> -void dump_dec (dump_flags_t, const poly_int<N, C> &); +void dump_dec (const dump_metadata_t &, const poly_int<N, C> &); extern void dump_dec (dump_flags_t, const poly_wide_int &, signop); extern void dump_hex (dump_flags_t, const poly_wide_int &); @@ -551,7 +586,9 @@ extern void dumpfile_ensure_any_optinfo_are_flushed (); leading to a dump message. */ extern unsigned int get_dump_scope_depth (); -extern void dump_begin_scope (const char *name, const dump_location_t &loc); +extern void dump_begin_scope (const char *name, + const dump_user_location_t &user_location, + const dump_impl_location_t &impl_location); extern void dump_end_scope (); /* Implementation detail of the AUTO_DUMP_SCOPE macro below. @@ -563,10 +600,13 @@ extern void dump_end_scope (); class auto_dump_scope { public: - auto_dump_scope (const char *name, dump_location_t loc) + auto_dump_scope (const char *name, + const dump_user_location_t &user_location, + const dump_impl_location_t &impl_location + = dump_impl_location_t ()) { if (dump_enabled_p ()) - dump_begin_scope (name, loc); + dump_begin_scope (name, user_location, impl_location); } ~auto_dump_scope () { @@ -576,7 +616,7 @@ class auto_dump_scope }; /* A macro for calling: - dump_begin_scope (NAME, LOC); + dump_begin_scope (NAME, USER_LOC); via an RAII object, thus printing "=== MSG ===\n" to the dumpfile etc, and then calling dump_end_scope (); @@ -587,8 +627,8 @@ class auto_dump_scope 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) +#define AUTO_DUMP_SCOPE(NAME, USER_LOC) \ + auto_dump_scope scope (NAME, USER_LOC) extern void dump_function (int phase, tree fn); extern void print_combine_total_stats (void); |