Add debug (slp_tree) and dump infrastructure for this

This adds an alternate debug_dump_context similar to the one for
selftests but for interactive debugging routines.  This allows
to share code between user-visible dumping via the dump_* API
and those debugging routines.  The primary driver was SLP node
dumping which wasn't accessible from inside a gdb session up to
now.

2020-05-27  Richard Biener  <rguenther@suse.de>

	* dump-context.h (debug_dump_context): New class.
	(dump_context): Make it friend.
	* dumpfile.c (debug_dump_context::debug_dump_context):
	Implement.
	(debug_dump_context::~debug_dump_context): Likewise.
	* tree-vect-slp.c: Include dump-context.h.
	(vect_print_slp_tree): Dump a single SLP node.
	(debug): New overload for slp_tree.
	(vect_print_slp_graph): Rename from vect_print_slp_tree and
	use that.
	(vect_analyze_slp_instance): Adjust.
This commit is contained in:
Richard Biener 2020-05-25 16:10:12 +02:00
parent baff22c48b
commit f61f9b2879
3 changed files with 84 additions and 12 deletions

View File

@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see
class optrecord_json_writer;
namespace selftest { class temp_dump_context; }
class debug_dump_context;
/* A class for handling the various dump_* calls.
@ -42,6 +43,7 @@ namespace selftest { class temp_dump_context; }
class dump_context
{
friend class selftest::temp_dump_context;
friend class debug_dump_context;
public:
static dump_context &get () { return *s_current; }
@ -195,6 +197,25 @@ private:
auto_vec<stashed_item> m_stashed_items;
};
/* An RAII-style class for use in debug dumpers for temporarily using a
different dump_context. It enables full details and outputs to
stderr instead of the currently active dump_file. */
class debug_dump_context
{
public:
debug_dump_context ();
~debug_dump_context ();
private:
dump_context m_context;
dump_context *m_saved;
dump_flags_t m_saved_flags;
dump_flags_t m_saved_pflags;
FILE *m_saved_file;
};
#if CHECKING_P
namespace selftest {

View File

@ -2078,6 +2078,34 @@ enable_rtl_dump_file (void)
return num_enabled > 0;
}
/* debug_dump_context's ctor. Temporarily override the dump_context
(to forcibly enable output to stderr). */
debug_dump_context::debug_dump_context ()
: m_context (),
m_saved (&dump_context::get ()),
m_saved_flags (dump_flags),
m_saved_pflags (pflags),
m_saved_file (dump_file)
{
set_dump_file (stderr);
dump_context::s_current = &m_context;
pflags = dump_flags = MSG_ALL_KINDS | MSG_ALL_PRIORITIES;
dump_context::get ().refresh_dumps_are_enabled ();
}
/* debug_dump_context's dtor. Restore the saved dump_context. */
debug_dump_context::~debug_dump_context ()
{
set_dump_file (m_saved_file);
dump_context::s_current = m_saved;
dump_flags = m_saved_flags;
pflags = m_saved_pflags;
dump_context::get ().refresh_dumps_are_enabled ();
}
#if CHECKING_P
namespace selftest {

View File

@ -44,6 +44,7 @@ along with GCC; see the file COPYING3. If not see
#include "vec-perm-indices.h"
#include "gimple-fold.h"
#include "internal-fn.h"
#include "dump-context.h"
/* Initialize a SLP node. */
@ -1579,20 +1580,17 @@ fail:
return node;
}
/* Dump a slp tree NODE using flags specified in DUMP_KIND. */
/* Dump a single SLP tree NODE. */
static void
vect_print_slp_tree (dump_flags_t dump_kind, dump_location_t loc,
slp_tree node, hash_set<slp_tree> &visited)
slp_tree node)
{
unsigned i, j;
stmt_vec_info stmt_info;
slp_tree child;
stmt_vec_info stmt_info;
tree op;
if (visited.add (node))
return;
dump_metadata_t metadata (dump_kind, loc.get_impl_location ());
dump_user_location_t user_loc = loc.get_user_location ();
dump_printf_loc (metadata, user_loc, "node%s %p (max_nunits=%u, refcnt=%u)\n",
@ -1626,16 +1624,41 @@ vect_print_slp_tree (dump_flags_t dump_kind, dump_location_t loc,
FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
dump_printf (dump_kind, " %p", (void *)child);
dump_printf (dump_kind, "\n");
}
DEBUG_FUNCTION void
debug (slp_tree node)
{
debug_dump_context ctx;
vect_print_slp_tree (MSG_NOTE,
dump_location_t::from_location_t (UNKNOWN_LOCATION),
node);
}
/* Dump a slp tree NODE using flags specified in DUMP_KIND. */
static void
vect_print_slp_graph (dump_flags_t dump_kind, dump_location_t loc,
slp_tree node, hash_set<slp_tree> &visited)
{
unsigned i;
slp_tree child;
if (visited.add (node))
return;
vect_print_slp_tree (dump_kind, loc, node);
FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
vect_print_slp_tree (dump_kind, loc, child, visited);
vect_print_slp_graph (dump_kind, loc, child, visited);
}
static void
vect_print_slp_tree (dump_flags_t dump_kind, dump_location_t loc,
slp_tree node)
vect_print_slp_graph (dump_flags_t dump_kind, dump_location_t loc,
slp_tree entry)
{
hash_set<slp_tree> visited;
vect_print_slp_tree (dump_kind, loc, node, visited);
vect_print_slp_graph (dump_kind, loc, entry, visited);
}
/* Mark the tree rooted at NODE with PURE_SLP. */
@ -2240,8 +2263,8 @@ vect_analyze_slp_instance (vec_info *vinfo,
{
dump_printf_loc (MSG_NOTE, vect_location,
"Final SLP tree for instance:\n");
vect_print_slp_tree (MSG_NOTE, vect_location,
SLP_INSTANCE_TREE (new_instance));
vect_print_slp_graph (MSG_NOTE, vect_location,
SLP_INSTANCE_TREE (new_instance));
}
return true;