public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2255] produce simple DOT graphs from SLP trees
@ 2021-07-12 14:48 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-07-12 14:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:47113773456ade7324c5467511d97f36cced57b4

commit r12-2255-g47113773456ade7324c5467511d97f36cced57b4
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Jul 12 15:13:17 2021 +0200

    produce simple DOT graphs from SLP trees
    
    This adds a dot_slp_tree debug function producing a simple DOT
    graph from a starting node down the graph.  There's no fancy
    direct invocation of dot but the output is directed to a specified
    file.  It re-uses vect_print_slp_tree, naming nodes as their
    address.
    
    2021-07-12  Richard Biener  <rguenther@suse.de>
    
            * dump-context.h (debug_dump_context::debug_dump_context):
            Add FILE * parameter defaulted to stderr.
            * dumpfile.c (debug_dump_context::debug_dump_context): Adjust.
            * tree-vect-slp.c (dot_slp_tree): New functions.

Diff:
---
 gcc/dump-context.h  |  2 +-
 gcc/dumpfile.c      |  4 ++--
 gcc/tree-vect-slp.c | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/gcc/dump-context.h b/gcc/dump-context.h
index e8ed3743b7b..1a6bf5eb513 100644
--- a/gcc/dump-context.h
+++ b/gcc/dump-context.h
@@ -204,7 +204,7 @@ private:
 class debug_dump_context
 {
  public:
-  debug_dump_context ();
+  debug_dump_context (FILE *f = stderr);
   ~debug_dump_context ();
 
  private:
diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index 2457df2df0e..8169daf7f59 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -2098,14 +2098,14 @@ enable_rtl_dump_file (void)
 /* debug_dump_context's ctor.  Temporarily override the dump_context
    (to forcibly enable output to stderr).  */
 
-debug_dump_context::debug_dump_context ()
+debug_dump_context::debug_dump_context (FILE *f)
 : 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);
+  set_dump_file (f);
   dump_context::s_current = &m_context;
   pflags = dump_flags = MSG_ALL_KINDS | MSG_ALL_PRIORITIES;
   dump_context::get ().refresh_dumps_are_enabled ();
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index cd002b3fb7c..86fa3c1b349 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2552,6 +2552,44 @@ debug (slp_tree node)
 		       node);
 }
 
+/* Recursive helper for the dot producer below.  */
+
+static void
+dot_slp_tree (FILE *f, slp_tree node, hash_set<slp_tree> &visited)
+{
+  if (visited.add (node))
+    return;
+
+  fprintf (f, "\"%p\" [label=\"", (void *)node);
+  vect_print_slp_tree (MSG_NOTE,
+		       dump_location_t::from_location_t (UNKNOWN_LOCATION),
+		       node);
+  fprintf (f, "\"];\n");
+
+
+  for (slp_tree child : SLP_TREE_CHILDREN (node))
+    fprintf (f, "\"%p\" -> \"%p\";", (void *)node, (void *)child);
+
+  for (slp_tree child : SLP_TREE_CHILDREN (node))
+    dot_slp_tree (f, child, visited);
+}
+
+DEBUG_FUNCTION void
+dot_slp_tree (const char *fname, slp_tree node)
+{
+  FILE *f = fopen (fname, "w");
+  fprintf (f, "digraph {\n");
+  fflush (f);
+    {
+      debug_dump_context ctx (f);
+      hash_set<slp_tree> visited;
+      dot_slp_tree (f, node, visited);
+    }
+  fflush (f);
+  fprintf (f, "}\n");
+  fclose (f);
+}
+
 /* Dump a slp tree NODE using flags specified in DUMP_KIND.  */
 
 static void


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-12 14:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 14:48 [gcc r12-2255] produce simple DOT graphs from SLP trees Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).