summaryrefslogtreecommitdiff
path: root/gcc/optinfo.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-07-31 19:22:48 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2018-07-31 19:22:48 +0000
commitb84e3bde926ea3a8824120108a0184fe32743bec (patch)
tree6480c9f6b8d02e58bb2b18fc96cb22b71bcaad64 /gcc/optinfo.cc
parentb06e1dcec5e7e29d12988dc8d2a6d4183f6c91df (diff)
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/optinfo.cc')
-rw-r--r--gcc/optinfo.cc135
1 files changed, 15 insertions, 120 deletions
diff --git a/gcc/optinfo.cc b/gcc/optinfo.cc
index 93de9d9388a..b858c3ca08a 100644
--- a/gcc/optinfo.cc
+++ b/gcc/optinfo.cc
@@ -34,11 +34,11 @@ along with GCC; see the file COPYING3. If not see
#include "cgraph.h"
#include "selftest.h"
-/* optinfo_item's ctor. */
+/* optinfo_item's ctor. Takes ownership of TEXT. */
optinfo_item::optinfo_item (enum optinfo_item_kind kind, location_t location,
- char *text, bool owned)
-: m_kind (kind), m_location (location), m_text (text), m_owned (owned)
+ char *text)
+: m_kind (kind), m_location (location), m_text (text)
{
}
@@ -46,8 +46,7 @@ optinfo_item::optinfo_item (enum optinfo_item_kind kind, location_t location,
optinfo_item::~optinfo_item ()
{
- if (m_owned)
- free (m_text);
+ free (m_text);
}
/* Get a string from KIND. */
@@ -81,7 +80,17 @@ optinfo::~optinfo ()
delete item;
}
-/* Emit the optinfo to all of the active destinations. */
+/* Add ITEM to this optinfo. */
+
+void
+optinfo::add_item (optinfo_item *item)
+{
+ gcc_assert (item);
+ m_items.safe_push (item);
+}
+
+/* Emit the optinfo to all of the "non-immediate" destinations
+ (emission to "immediate" destinations is done by emit_item). */
void
optinfo::emit ()
@@ -103,120 +112,6 @@ optinfo::handle_dump_file_kind (dump_flags_t dump_kind)
m_kind = OPTINFO_KIND_NOTE;
}
-/* Append a string literal to this optinfo. */
-
-void
-optinfo::add_string (const char *str)
-{
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
- const_cast <char *> (str), false);
- m_items.safe_push (item);
-}
-
-/* Append printf-formatted text to this optinfo. */
-
-void
-optinfo::add_printf (const char *format, ...)
-{
- va_list ap;
- va_start (ap, format);
- add_printf_va (format, ap);
- va_end (ap);
-}
-
-/* Append printf-formatted text to this optinfo. */
-
-void
-optinfo::add_printf_va (const char *format, va_list ap)
-{
- char *formatted_text = xvasprintf (format, ap);
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
- formatted_text, true);
- m_items.safe_push (item);
-}
-
-/* Append a gimple statement to this optinfo, equivalent to
- print_gimple_stmt. */
-
-void
-optinfo::add_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags)
-{
- pretty_printer pp;
- pp_needs_newline (&pp) = true;
- pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
- pp_newline (&pp);
-
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
- xstrdup (pp_formatted_text (&pp)), true);
- m_items.safe_push (item);
-}
-
-/* Append a gimple statement to this optinfo, equivalent to
- print_gimple_expr. */
-
-void
-optinfo::add_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags)
-{
- dump_flags |= TDF_RHS_ONLY;
- pretty_printer pp;
- pp_needs_newline (&pp) = true;
- pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
-
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
- xstrdup (pp_formatted_text (&pp)), true);
- m_items.safe_push (item);
-}
-
-/* Append a tree node to this optinfo, equivalent to print_generic_expr. */
-
-void
-optinfo::add_tree (tree node, dump_flags_t dump_flags)
-{
- pretty_printer pp;
- pp_needs_newline (&pp) = true;
- pp_translate_identifiers (&pp) = false;
- dump_generic_node (&pp, node, 0, dump_flags, false);
-
- location_t loc = UNKNOWN_LOCATION;
- if (EXPR_HAS_LOCATION (node))
- loc = EXPR_LOCATION (node);
-
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_TREE, loc,
- xstrdup (pp_formatted_text (&pp)), true);
- m_items.safe_push (item);
-}
-
-/* Append a symbol table node to this optinfo. */
-
-void
-optinfo::add_symtab_node (symtab_node *node)
-{
- location_t loc = DECL_SOURCE_LOCATION (node->decl);
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc,
- xstrdup (node->dump_name ()), true);
- m_items.safe_push (item);
-}
-
-/* Append the decimal represenation of a wide_int_ref to this
- optinfo. */
-
-void
-optinfo::add_dec (const wide_int_ref &wi, signop sgn)
-{
- char buf[WIDE_INT_PRINT_BUFFER_SIZE];
- print_dec (wi, buf, sgn);
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
- xstrdup (buf), true);
- m_items.safe_push (item);
-}
-
/* Should optinfo instances be created?
All creation of optinfos should be guarded by this predicate.
Return true if any optinfo destinations are active. */