diff options
author | David Malcolm <dmalcolm@redhat.com> | 2018-07-31 19:22:48 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-07-31 19:22:48 +0000 |
commit | b84e3bde926ea3a8824120108a0184fe32743bec (patch) | |
tree | 6480c9f6b8d02e58bb2b18fc96cb22b71bcaad64 /gcc/dump-context.h | |
parent | b06e1dcec5e7e29d12988dc8d2a6d4183f6c91df (diff) | |
download | gcc-b84e3bde926ea3a8824120108a0184fe32743bec.zip gcc-b84e3bde926ea3a8824120108a0184fe32743bec.tar.gz gcc-b84e3bde926ea3a8824120108a0184fe32743bec.tar.bz2 |
dumpfile.c: eliminate special-casing of dump_file/alt_dump_file
With the addition of optinfo, the various dump_* calls had three parts:
- optionally print to dump_file
- optionally print to alt_dump_file
- optionally make an optinfo_item and add it to the pending optinfo,
creating it for dump_*_loc calls.
However, this split makes it difficult to implement the formatted dumps
later in patch kit, so as enabling work towards that, this patch removes
the above split, so that all dumping within the dump_* API goes through
optinfo_item.
In order to ensure that the dumps to dump_file and alt_dump_file are
processed immediately (rather than being buffered within the pending
optinfo for consolidation), this patch introduces the idea of "immediate"
optinfo_item destinations vs "non-immediate" destinations.
The patch also adds selftest coverage of what's printed, and of scopes.
This adds two allocations per dump_* call when dumping is enabled.
I'm assuming that this isn't a problem, as dump_enabled_p is normally
false. There are ways of optimizing it if it is an issue (by making
optinfo_item instances become temporaries that borrow the underlying
buffer), but they require nontrivial changes, so I'd prefer to leave
that for another patch kit, if it becomes necessary.
gcc/ChangeLog:
* dump-context.h: Include "pretty-print.h".
(dump_context::refresh_dumps_are_enabled): New decl.
(dump_context::emit_item): New decl.
(class dump_context): Add fields "m_test_pp" and
"m_test_pp_flags".
(temp_dump_context::temp_dump_context): Add param "test_pp_flags".
(temp_dump_context::get_dumped_text): New decl.
(class temp_dump_context): Add field "m_pp".
* dumpfile.c (refresh_dumps_are_enabled): Convert to...
(dump_context::refresh_dumps_are_enabled): ...and add a test for
m_test_pp.
(set_dump_file): Update for above change.
(set_alt_dump_file): Likewise.
(dump_loc): New overload, taking a pretty_printer *.
(dump_context::dump_loc): Call end_any_optinfo. Dump the location
to any test pretty-printer.
(make_item_for_dump_gimple_stmt): New function, adapted from
optinfo::add_gimple_stmt.
(dump_context::dump_gimple_stmt): Call it, and use the result,
eliminating the direct usage of dump_file and alt_dump_file in
favor of indirectly using them via emit_item.
(make_item_for_dump_gimple_expr): New function, adapted from
optinfo::add_gimple_expr.
(dump_context::dump_gimple_expr): Call it, and use the result,
eliminating the direct usage of dump_file and alt_dump_file in
favor of indirectly using them via emit_item.
(make_item_for_dump_generic_expr): New function, adapted from
optinfo::add_tree.
(dump_context::dump_generic_expr): Call it, and use the result,
eliminating the direct usage of dump_file and alt_dump_file in
favor of indirectly using them via emit_item.
(make_item_for_dump_printf_va): New function, adapted from
optinfo::add_printf_va.
(make_item_for_dump_printf): New function.
(dump_context::dump_printf_va): Call make_item_for_dump_printf_va,
and use the result, eliminating the direct usage of dump_file and
alt_dump_file in favor of indirectly using them via emit_item.
(make_item_for_dump_dec): New function.
(dump_context::dump_dec): Call it, and use the result,
eliminating the direct usage of dump_file and alt_dump_file in
favor of indirectly using them via emit_item.
(make_item_for_dump_symtab_node): New function, adapted from
optinfo::add_symtab_node.
(dump_context::dump_symtab_node): Call it, and use the result,
eliminating the direct usage of dump_file and alt_dump_file in
favor of indirectly using them via emit_item.
(dump_context::begin_scope): Reimplement, avoiding direct usage
of dump_file and alt_dump_file in favor of indirectly using them
via emit_item.
(dump_context::emit_item): New member function.
(temp_dump_context::temp_dump_context): Add param "test_pp_flags".
Set up test pretty-printer on the underlying context. Call
refresh_dumps_are_enabled.
(temp_dump_context::~temp_dump_context): Call
refresh_dumps_are_enabled.
(temp_dump_context::get_dumped_text): New member function.
(selftest::verify_dumped_text): New function.
(ASSERT_DUMPED_TEXT_EQ): New macro.
(selftest::test_capture_of_dump_calls): Run all tests twice, with
and then without optinfo enabled. Add uses of
ASSERT_DUMPED_TEXT_EQ to all tests. Add test of nested scopes.
* dumpfile.h: Update comment for the dump_* API.
* optinfo-emit-json.cc
(selftest::test_building_json_from_dump_calls): Update for new
param for temp_dump_context ctor.
* optinfo.cc (optinfo_item::optinfo_item): Remove "owned" param
and "m_owned" field.
(optinfo_item::~optinfo_item): Likewise.
(optinfo::add_item): New member function.
(optinfo::emit): Update comment.
(optinfo::add_string): Delete.
(optinfo::add_printf): Delete.
(optinfo::add_printf_va): Delete.
(optinfo::add_gimple_stmt): Delete.
(optinfo::add_gimple_expr): Delete.
(optinfo::add_tree): Delete.
(optinfo::add_symtab_node): Delete.
(optinfo::add_dec): Delete.
* optinfo.h (class dump_context): New forward decl.
(optinfo::add_item): New decl.
(optinfo::add_string): Delete.
(optinfo::add_printf): Delete.
(optinfo::add_printf_va): Delete.
(optinfo::add_gimple_stmt): Delete.
(optinfo::add_gimple_expr): Delete.
(optinfo::add_tree): Delete.
(optinfo::add_symtab_node): Delete.
(optinfo::add_dec): Delete.
(optinfo::add_poly_int): Delete.
(optinfo_item::optinfo_item): Remove "owned" param.
(class optinfo_item): Remove field "m_owned".
From-SVN: r263178
Diffstat (limited to 'gcc/dump-context.h')
-rw-r--r-- | gcc/dump-context.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/gcc/dump-context.h b/gcc/dump-context.h index f6df0b4..f40ea14 100644 --- a/gcc/dump-context.h +++ b/gcc/dump-context.h @@ -22,6 +22,8 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_DUMP_CONTEXT_H #define GCC_DUMP_CONTEXT_H 1 +#include "pretty-print.h" + /* A class for handling the various dump_* calls. In particular, this class has responsibility for consolidating @@ -39,6 +41,8 @@ class dump_context ~dump_context (); + void refresh_dumps_are_enabled (); + void dump_loc (dump_flags_t dump_kind, const dump_location_t &loc); void dump_gimple_stmt (dump_flags_t dump_kind, dump_flags_t extra_dump_flags, @@ -93,6 +97,8 @@ class dump_context void end_any_optinfo (); + void emit_item (optinfo_item *item, dump_flags_t dump_kind); + private: optinfo &ensure_pending_optinfo (); optinfo &begin_next_optinfo (const dump_location_t &loc); @@ -108,6 +114,11 @@ class dump_context if any. */ optinfo *m_pending; + /* For use in selftests: if non-NULL, then items are to be printed + to this, using the given flags. */ + pretty_printer *m_test_pp; + dump_flags_t m_test_pp_flags; + /* The currently active dump_context, for use by the dump_* API calls. */ static dump_context *s_current; @@ -123,13 +134,16 @@ class dump_context class temp_dump_context { public: - temp_dump_context (bool forcibly_enable_optinfo); + temp_dump_context (bool forcibly_enable_optinfo, + dump_flags_t test_pp_flags); ~temp_dump_context (); /* Support for selftests. */ optinfo *get_pending_optinfo () const { return m_context.m_pending; } + const char *get_dumped_text (); private: + pretty_printer m_pp; dump_context m_context; dump_context *m_saved; bool m_saved_flag_remarks; |