From 15566ae4a56094305037f2650d27eabe868034f7 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 6 Mar 2019 10:52:54 -0500
Subject: [PATCH 060/169] FIXME: add enum supergraph_dot_flags and hide BBs by
 default

---
 gcc/analyzer/engine.cc     |  6 ++---
 gcc/analyzer/supergraph.cc | 56 ++++++++++++++++++++++++++++------------------
 gcc/analyzer/supergraph.h  | 22 +++++++++++++-----
 3 files changed, 54 insertions(+), 30 deletions(-)

diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 442f9a0..7bdf196 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1863,7 +1863,7 @@ run_one_checker (const supergraph &sg, const state_machine &sm, logger *logger)
       engine_annotator a (e);
       char *filename
 	= concat (dump_base_name, ".", sm.get_name (), ".1.dot", NULL);
-      sg.dump_dot (filename, &a);
+      sg.dump_dot (filename, (enum supergraph_dot_flags)0, &a);
       free (filename);
     }
 
@@ -1872,7 +1872,7 @@ run_one_checker (const supergraph &sg, const state_machine &sm, logger *logger)
       engine_annotator_2 a (e);
       char *filename
 	= concat (dump_base_name, ".", sm.get_name (), ".2.dot", NULL);
-      sg.dump_dot (filename, &a);
+      sg.dump_dot (filename, (enum supergraph_dot_flags)0, &a);
       free (filename);
     }
 
@@ -1901,7 +1901,7 @@ run_checkers ()
     if (1)
       {
 	char *filename = concat (dump_base_name, ".supergraph.dot", NULL);
-	sg.dump_dot (filename);
+	sg.dump_dot (filename, (enum supergraph_dot_flags)0);
 	free (filename);
       }
 
diff --git a/gcc/analyzer/supergraph.cc b/gcc/analyzer/supergraph.cc
index 6a9322a..0e0dd7f 100644
--- a/gcc/analyzer/supergraph.cc
+++ b/gcc/analyzer/supergraph.cc
@@ -198,7 +198,9 @@ supergraph::supergraph ()
 /* FIXME.  */
 
 void
-supergraph::dump_dot_to_pp (pretty_printer *pp, const dot_annotator *a) const
+supergraph::dump_dot_to_pp (pretty_printer *pp,
+			    enum supergraph_dot_flags flags,
+			    const dot_annotator *a) const
 {
   graphviz_out gv (pp);
 
@@ -239,26 +241,31 @@ supergraph::dump_dot_to_pp (pretty_printer *pp, const dot_annotator *a) const
 	basic_block bb;
 	FOR_ALL_BB_FN (bb, fun)
 	  {
-
-	    gv.println ("subgraph \"cluster_%s_bb_%i\" {",
-			funcname, bb->index);
-	    gv.indent ();
-	    pp_printf (pp,
-		       ("style=\"dashed\";"
-			" color=\"black\";"
-			" label=\"bb: %i\";\n"),
-		       bb->index);
+	    if (flags & SUPERGRAPH_DOT_SHOW_BBS)
+	      {
+		gv.println ("subgraph \"cluster_%s_bb_%i\" {",
+			    funcname, bb->index);
+		gv.indent ();
+		pp_printf (pp,
+			   ("style=\"dashed\";"
+			    " color=\"black\";"
+			    " label=\"bb: %i\";\n"),
+			   bb->index);
+	      }
 
 	    // TODO: maybe keep an index per-function/per-bb to speed this up???
 	    int i;
 	    supernode *n;
 	    FOR_EACH_VEC_ELT (m_nodes, i, n)
 	      if (n->m_fun == fun && n->m_bb == bb)
-		n->dump_dot (&gv, a);
-
-	    /* Terminate per-bb "subgraph" */
-	    gv.outdent ();
-	    gv.println ("}");
+		n->dump_dot (&gv, flags, a);
+
+	    if (flags & SUPERGRAPH_DOT_SHOW_BBS)
+	      {
+		/* Terminate per-bb "subgraph" */
+		gv.outdent ();
+		gv.println ("}");
+	      }
 	  }
       }
 
@@ -281,7 +288,7 @@ supergraph::dump_dot_to_pp (pretty_printer *pp, const dot_annotator *a) const
   int i;
   superedge *e;
   FOR_EACH_VEC_ELT (m_edges, i, e)
-    e->dump_dot (&gv);
+    e->dump_dot (&gv, flags);
 
   /* Terminate "digraph" */
   gv.outdent ();
@@ -289,19 +296,21 @@ supergraph::dump_dot_to_pp (pretty_printer *pp, const dot_annotator *a) const
 }
 
 void
-supergraph::dump_dot_to_file (FILE *fp, const dot_annotator *a) const
+supergraph::dump_dot_to_file (FILE *fp, enum supergraph_dot_flags flags,
+			      const dot_annotator *a) const
 {
   pretty_printer pp;
   pp.buffer->stream = fp;
-  dump_dot_to_pp (&pp, a);
+  dump_dot_to_pp (&pp, flags, a);
   pp_flush (&pp);
 }
 
 void
-supergraph::dump_dot (const char *path, const dot_annotator *a) const
+supergraph::dump_dot (const char *path, enum supergraph_dot_flags flags,
+		      const dot_annotator *a) const
 {
   FILE *fp = fopen (path, "w");
-  dump_dot_to_file (fp, a);
+  dump_dot_to_file (fp, flags, a);
   fclose (fp);
 }
 
@@ -349,7 +358,9 @@ supernode::to_str () const
 }
 
 void
-supernode::dump_dot (graphviz_out *gv, const dot_annotator *a) const
+supernode::dump_dot (graphviz_out *gv,
+		     enum supergraph_dot_flags flags ATTRIBUTE_UNUSED,
+		     const dot_annotator *a) const
 {
   gv->println ("subgraph cluster_node_%i {",
 	       m_index);
@@ -519,7 +530,8 @@ supernode::get_end_location () const
 }
 
 void
-superedge::dump_dot (graphviz_out *gv) const
+superedge::dump_dot (graphviz_out *gv,
+		     enum supergraph_dot_flags flags ATTRIBUTE_UNUSED) const
 {
   const char *style = "\"solid,bold\"";
   const char *color = "black";
diff --git a/gcc/analyzer/supergraph.h b/gcc/analyzer/supergraph.h
index a88326d..0d8901d 100644
--- a/gcc/analyzer/supergraph.h
+++ b/gcc/analyzer/supergraph.h
@@ -60,6 +60,14 @@ enum edge_kind
   }
 #endif
 
+/* Flags for controlling the appearance of .dot dumps.  */
+
+enum supergraph_dot_flags
+{
+  SUPERGRAPH_DOT_SHOW_BBS = (1 << 0)
+};
+
+
 /* FIXME.  */
 
 class supergraph
@@ -90,9 +98,12 @@ public:
 	      (m_cgraph_edge_to_caller_next_node).get (edge));
   }
 
-  void dump_dot_to_pp (pretty_printer *pp, const dot_annotator *a = NULL) const;
-  void dump_dot_to_file (FILE *fp, const dot_annotator *a = NULL) const;
-  void dump_dot (const char *path, const dot_annotator *a = NULL) const;
+  void dump_dot_to_pp (pretty_printer *pp, enum supergraph_dot_flags flags,
+		       const dot_annotator *a = NULL) const;
+  void dump_dot_to_file (FILE *fp, enum supergraph_dot_flags flags,
+			 const dot_annotator *a = NULL) const;
+  void dump_dot (const char *path, enum supergraph_dot_flags flags,
+		 const dot_annotator *a = NULL) const;
 
   int num_nodes () const { return m_nodes.length (); }
   int num_edges () const { return m_edges.length (); }
@@ -142,7 +153,8 @@ class supernode
 
   std::string to_str () const;
 
-  void dump_dot (graphviz_out *gv, const dot_annotator *a) const;
+  void dump_dot (graphviz_out *gv, enum supergraph_dot_flags flags,
+		 const dot_annotator *a) const;
   void dump_dot_id (pretty_printer *pp) const;
 
   location_t get_start_location () const;
@@ -193,7 +205,7 @@ class supernode
 class superedge
 {
  public:
-  void dump_dot (graphviz_out *gv) const;
+  void dump_dot (graphviz_out *gv, enum supergraph_dot_flags flags) const;
 
   virtual void dump_label_to_pp (pretty_printer *pp) const = 0;
   virtual cfg_superedge *dyn_cast_cfg_superedge () { return NULL; }
-- 
1.8.5.3

