diff options
author | David Malcolm <dmalcolm@redhat.com> | 2018-08-17 18:21:31 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-08-17 18:21:31 +0000 |
commit | 6f795a9239f6029072ac83357e8966c56cd572e0 (patch) | |
tree | bf03104d1e9fad436a85e1855394ea092e82d743 /gcc/dumpfile.h | |
parent | 478490f681da504e75723828d9f1b3b09928b5e5 (diff) | |
download | gcc-6f795a9239f6029072ac83357e8966c56cd572e0.zip gcc-6f795a9239f6029072ac83357e8966c56cd572e0.tar.gz gcc-6f795a9239f6029072ac83357e8966c56cd572e0.tar.bz2 |
Formatted printing for dump_* in the middle-end
This patch converts dump_print and dump_printf_loc from using
printf (and thus ATTRIBUTE_PRINTF) to using a new pretty-printer
based on pp_format, which supports formatting middle-end types.
In particular, the following codes are implemented (in addition
to the standard pretty_printer ones):
%E: gimple *:
Equivalent to: dump_gimple_expr (MSG_*, TDF_SLIM, stmt, 0)
%G: gimple *:
Equivalent to: dump_gimple_stmt (MSG_*, TDF_SLIM, stmt, 0)
%T: tree:
Equivalent to: dump_generic_expr (MSG_*, arg, TDF_SLIM).
Hence it becomes possible to convert e.g.:
if (dump_enabled_p ())
{
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
"not vectorized: different sized vector "
"types in statement, ");
dump_generic_expr (MSG_MISSED_OPTIMIZATION, TDF_SLIM, vectype);
dump_printf (MSG_MISSED_OPTIMIZATION, " and ");
dump_generic_expr (MSG_MISSED_OPTIMIZATION, TDF_SLIM, nunits_vectype);
dump_printf (MSG_MISSED_OPTIMIZATION, "\n");
}
into a one-liner:
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
"not vectorized: different sized vector "
"types in statement, %T and %T\n",
vectype, nunits_vectype);
Unlike regular pretty-printers, this one captures optinfo_item
instances for the formatted chunks as appropriate, so that when
written out to a JSON optimization record, the relevant parts of
the message are labelled by type, and by source location (so that
e.g. %G is entirely equivalent to using dump_gimple_stmt).
dump_printf and dump_printf_loc become marked with
ATTRIBUTE_GCC_DUMP_PRINTF, which the patch also implements.
gcc/c-family/ChangeLog:
* c-format.c (enum format_type): Add gcc_dump_printf_format_type.
(gcc_dump_printf_length_specs): New.
(gcc_dump_printf_flag_pairs): New.
(gcc_dump_printf_flag_specs): New.
(gcc_dump_printf_char_table): New.
(format_types_orig): Add entry for "gcc_dump_printf".
(init_dynamic_diag_info): Set up length_char_specs and
conversion_specs for gcc_dump_printf_format_type.
(handle_format_attribute): Handle gcc_dump_printf_format_type.
gcc/ChangeLog:
* dump-context.h: Include "dumpfile.h".
(dump_context::dump_printf_va): Convert final param from va_list
to va_list *. Convert from ATTRIBUTE_PRINTF to
ATTRIBUTE_GCC_DUMP_PRINTF.
(dump_context::dump_printf_loc_va): Likewise.
* dumpfile.c: Include "stringpool.h".
(make_item_for_dump_printf_va): Delete.
(make_item_for_dump_printf): Delete.
(class dump_pretty_printer): New class.
(dump_pretty_printer::dump_pretty_printer): New ctor.
(dump_pretty_printer::emit_items): New member function.
(dump_pretty_printer::emit_any_pending_textual_chunks): New member
function.
(dump_pretty_printer::emit_item): New member function.
(dump_pretty_printer::stash_item): New member function.
(dump_pretty_printer::format_decoder_cb): New member function.
(dump_pretty_printer::decode_format): New member function.
(dump_context::dump_printf_va): Reimplement in terms of
dump_pretty_printer.
(dump_context::dump_printf_loc_va): Convert final param from va_list
to va_list *.
(dump_context::begin_scope): Reimplement call to
make_item_for_dump_printf.
(dump_printf): Update for change to dump_printf_va.
(dump_printf_loc): Likewise.
(selftest::test_capture_of_dump_calls): Convert "stmt" from
greturn * to gimple *. Add a test_decl. Add tests of dump_printf
with %T, %E, and %G.
* dumpfile.h (ATTRIBUTE_GCC_DUMP_PRINTF): New macro.
(dump_printf): Replace ATTRIBUTE_PRINTF_2 with
ATTRIBUTE_GCC_DUMP_PRINTF (2, 3).
(dump_printf_loc): Replace ATTRIBUTE_PRINTF_3 with
ATTRIBUTE_GCC_DUMP_PRINTF (3, 0).
* tree-vect-data-refs.c (vect_lanes_optab_supported_p): Convert
use of HOST_WIDE_INT_PRINT_DEC on unsigned HOST_WIDE_INT "count"
within a dump_printf_loc call to "%wu".
(vector_alignment_reachable_p): Merge two dump_printf[_loc] calls,
converting a use of HOST_WIDE_INT_PRINT_DEC to "%wd". Add a
missing space after "=".
* tree-vect-loop.c (vect_analyze_loop_2) Within a dump_printf
call, convert use of HOST_WIDE_INT_PRINT_DEC to "%wd".
* tree-vect-slp.c (vect_slp_bb): Within a dump_printf_loc call,
convert use of HOST_WIDE_INT_PRINT_UNSIGNED to "%wu".
* tree-vectorizer.c (try_vectorize_loop_1): Likewise. Remove
duplicate "vectorized" from message.
gcc/testsuite/ChangeLog:
* gcc.dg/format/gcc_diag-1.c: Fix typo. Add test coverage for
gcc_dump_printf.
* gcc.dg/format/gcc_diag-10.c: Add gimple typedef. Add test
coverage for gcc_dump_printf.
From-SVN: r263626
Diffstat (limited to 'gcc/dumpfile.h')
-rw-r--r-- | gcc/dumpfile.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/gcc/dumpfile.h b/gcc/dumpfile.h index 8de001d..0305d36 100644 --- a/gcc/dumpfile.h +++ b/gcc/dumpfile.h @@ -23,6 +23,19 @@ along with GCC; see the file COPYING3. If not see #include "profile-count.h" +/* An attribute for annotating formatting printing functions that use + the dumpfile/optinfo formatting codes. These are the pretty_printer + format codes (see pretty-print.c), with additional codes for middle-end + specific entities (see dumpfile.c). */ + +#if GCC_VERSION >= 3005 +#define ATTRIBUTE_GCC_DUMP_PRINTF(m, n) \ + __attribute__ ((__format__ (__gcc_dump_printf__, m ,n))) \ + ATTRIBUTE_NONNULL(m) +#else +#define ATTRIBUTE_GCC_DUMP_PRINTF(m, n) ATTRIBUTE_NONNULL(m) +#endif + /* Different tree dump places. When you add new tree dump places, extend the DUMP_FILES array in dumpfile.c. */ enum tree_dump_index @@ -476,9 +489,12 @@ 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 *, ...) ATTRIBUTE_PRINTF_2; +extern void dump_printf (dump_flags_t, const char *, ...) + ATTRIBUTE_GCC_DUMP_PRINTF (2, 3); + extern void dump_printf_loc (dump_flags_t, const dump_location_t &, - const char *, ...) ATTRIBUTE_PRINTF_3; + 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 &, |