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/c-family | |
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/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 12 | ||||
-rw-r--r-- | gcc/c-family/c-format.c | 36 |
2 files changed, 46 insertions, 2 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 6ad2fe0..47221b4 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,15 @@ +2018-08-17 David Malcolm <dmalcolm@redhat.com> + + * 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. + 2018-08-17 Nathan Sidwell <nathan@acm.org> * c-ada-spec.c (macro_length, dump_ada_macros): Constify. diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index 5a04f05..035878f 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -46,6 +46,7 @@ enum format_type { printf_format_type, asm_fprintf_format_type, gcc_diag_format_type, gcc_tdiag_format_type, gcc_cdiag_format_type, gcc_cxxdiag_format_type, gcc_gfc_format_type, + gcc_dump_printf_format_type, gcc_objc_string_format_type, format_type_error = -1}; @@ -463,6 +464,7 @@ static const format_length_info gcc_diag_length_specs[] = #define gcc_tdiag_length_specs gcc_diag_length_specs #define gcc_cdiag_length_specs gcc_diag_length_specs #define gcc_cxxdiag_length_specs gcc_diag_length_specs +#define gcc_dump_printf_length_specs gcc_diag_length_specs /* This differs from printf_length_specs only in that "Z" is not accepted. */ static const format_length_info scanf_length_specs[] = @@ -552,6 +554,7 @@ static const format_flag_pair gcc_diag_flag_pairs[] = #define gcc_cdiag_flag_pairs gcc_diag_flag_pairs #define gcc_cxxdiag_flag_pairs gcc_diag_flag_pairs #define gcc_gfc_flag_pairs gcc_diag_flag_pairs +#define gcc_dump_printf_flag_pairs gcc_diag_flag_pairs static const format_flag_spec gcc_diag_flag_specs[] = { @@ -567,6 +570,7 @@ static const format_flag_spec gcc_diag_flag_specs[] = #define gcc_cdiag_flag_specs gcc_diag_flag_specs #define gcc_cxxdiag_flag_specs gcc_diag_flag_specs #define gcc_gfc_flag_specs gcc_diag_flag_specs +#define gcc_dump_printf_flag_specs gcc_diag_flag_specs static const format_flag_spec scanf_flag_specs[] = { @@ -788,6 +792,22 @@ static const format_char_info gcc_gfc_char_table[] = { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL } }; +static const format_char_info gcc_dump_printf_char_table[] = +{ + /* The conversion specifiers implemented within pp_format. */ + PP_FORMAT_CHAR_TABLE, + + /* Custom conversion specifiers implemented by dump_pretty_printer. */ + + /* E and G require a "gimple *" argument at runtime. */ + { "EG", 1, STD_C89, { T89_G, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "\"", NULL }, + + /* T requires a "tree" at runtime. */ + { "T", 1, STD_C89, { T89_T, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "\"", NULL }, + + { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL } +}; + static const format_char_info scan_char_table[] = { /* C89 conversion specifiers. */ @@ -887,6 +907,13 @@ static const format_kind_info format_types_orig[] = 0, 0, 0, 0, 0, 0, NULL, NULL }, + { "gcc_dump_printf", gcc_dump_printf_length_specs, + gcc_dump_printf_char_table, "q+#", NULL, + gcc_dump_printf_flag_specs, gcc_dump_printf_flag_pairs, + FMT_FLAG_ARG_CONVERT, + 0, 0, 'p', 0, 'L', 0, + NULL, &integer_type_node + }, { "NSString", NULL, NULL, NULL, NULL, NULL, NULL, FMT_FLAG_ARG_CONVERT|FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL, 0, 0, 0, 0, 0, 0, @@ -3971,6 +3998,7 @@ init_dynamic_diag_info (void) dynamic_format_types[gcc_tdiag_format_type].length_char_specs = dynamic_format_types[gcc_cdiag_format_type].length_char_specs = dynamic_format_types[gcc_cxxdiag_format_type].length_char_specs = + dynamic_format_types[gcc_dump_printf_format_type].length_char_specs = diag_ls = (format_length_info *) xmemdup (gcc_diag_length_specs, sizeof (gcc_diag_length_specs), @@ -3997,6 +4025,8 @@ init_dynamic_diag_info (void) gcc_cdiag_char_table; dynamic_format_types[gcc_cxxdiag_format_type].conversion_specs = gcc_cxxdiag_char_table; + dynamic_format_types[gcc_dump_printf_format_type].conversion_specs = + gcc_dump_printf_char_table; } #ifdef TARGET_FORMAT_TYPES @@ -4151,7 +4181,8 @@ handle_format_attribute (tree *node, tree ARG_UNUSED (name), tree args, || info.format_type == gcc_diag_format_type || info.format_type == gcc_tdiag_format_type || info.format_type == gcc_cdiag_format_type - || info.format_type == gcc_cxxdiag_format_type) + || info.format_type == gcc_cxxdiag_format_type + || info.format_type == gcc_dump_printf_format_type) { /* Our first time through, we have to make sure that our format_type data is allocated dynamically and is modifiable. */ @@ -4173,7 +4204,8 @@ handle_format_attribute (tree *node, tree ARG_UNUSED (name), tree args, else if (info.format_type == gcc_diag_format_type || info.format_type == gcc_tdiag_format_type || info.format_type == gcc_cdiag_format_type - || info.format_type == gcc_cxxdiag_format_type) + || info.format_type == gcc_cxxdiag_format_type + || info.format_type == gcc_dump_printf_format_type) init_dynamic_diag_info (); else gcc_unreachable (); |