[PATCH 3/5] Dot refined regions.

Sebastian Pop sebpop@gmail.com
Tue Jul 20 20:24:00 GMT 2010


2010-07-20  Vladimir Kargov  <kargov@gmail.com>

	* refined-regions.c: Include tree-pass.h, cfgloop.h, gimple.h, and
	tree-data-ref.h.
	(dot_regions_1): New.
	(dot_regions): New.
	* refined-regions.h (dot_regions): Declared.
	* Makefile.in (refined-regions.o): Update dependences.
---
 gcc/ChangeLog.graphite |    9 +++
 gcc/Makefile.in        |    3 +-
 gcc/refined-regions.c  |  161 +++++++++++++++++++++++++++++++++++++++++++++++-
 gcc/refined-regions.h  |    1 +
 4 files changed, 171 insertions(+), 3 deletions(-)

diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index f6e077a..58ab265 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,3 +1,12 @@
+2010-07-20  Vladimir Kargov  <kargov@gmail.com>
+
+	* refined-regions.c: Include tree-pass.h, cfgloop.h, gimple.h, and
+	tree-data-ref.h.
+	(dot_regions_1): New.
+	(dot_regions): New.
+	* refined-regions.h (dot_regions): Declared.
+	* Makefile.in (refined-regions.o): Update dependences.
+
 2010-07-20  Sebastian Pop  <sebastian.pop@amd.com>
 
 	* graphite-sese-to-poly.c (rewrite_close_phi_out_of_ssa): Add an
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 69c5b45..4a14d94 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2657,7 +2657,8 @@ graphite-poly.o: graphite-poly.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
 graphite-ppl.o: graphite-ppl.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
    $(GGC_H) graphite-ppl.h graphite-cloog-util.h
 refined-regions.o: refined-regions.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
-   $(TM_H) $(GGC_H) domwalk.h refined-regions.h
+   $(TM_H) $(BASIC_BLOCK_H) $(TIMEVAR_H) $(BITMAP_H) domwalk.h $(TREE_PASS_H) \
+   refined-regions.h
 graphite-scop-detection.o: graphite-scop-detection.c $(CONFIG_H) $(SYSTEM_H) \
    $(GGC_H) $(TREE_H) $(RTL_H) $(BASIC_BLOCK_H) $(DIAGNOSTIC_H) $(TOPLEV_H) \
    $(TREE_FLOW_H) $(TREE_DUMP_H) $(TIMEVAR_H) $(CFGLOOP_H) $(GIMPLE_H) \
diff --git a/gcc/refined-regions.c b/gcc/refined-regions.c
index b10daea..ef37533 100644
--- a/gcc/refined-regions.c
+++ b/gcc/refined-regions.c
@@ -26,9 +26,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "basic-block.h"
 #include "timevar.h"
 #include "bitmap.h"
-
-#include "refined-regions.h"
 #include "domwalk.h"
+#include "tree-pass.h"
+#include "refined-regions.h"
 
 /* Auxiliary function for qsort () that compares two basic blocks
    according to the values of their indices.  */
@@ -620,3 +620,160 @@ free_region_tree (refined_region_p region)
   VEC_free (refined_region_p, heap, region->children);
   free (region);
 }
+
+/* Pretty print to FILE all the REGIONS in DOT format and mark them with
+   different colors.  The behavior is the same as in dot_all_scops_1.  */
+
+static void
+dot_regions_1 (FILE *file, VEC (refined_region_p, heap) *regions)
+{
+  basic_block bb;
+  edge e;
+  edge_iterator ei;
+  refined_region_p region;
+  const char* color;
+  int i;
+
+  /* Disable debugging while printing graph.  */
+  int tmp_dump_flags = dump_flags;
+  dump_flags = 0;
+
+  fprintf (file, "digraph all {\n");
+
+  FOR_ALL_BB (bb)
+    {
+      int part_of_scop = false;
+
+      /* Use HTML for every bb label.  So we are able to print bbs
+         which are part of two different SCoPs, with two different
+         background colors.  */
+      fprintf (file, "%d [label=<\n  <TABLE BORDER=\"0\" CELLBORDER=\"1\" ",
+	       bb->index);
+      fprintf (file, "CELLSPACING=\"0\">\n");
+
+      /* Select color for SCoP.  */
+      for (i = 0; VEC_iterate (refined_region_p, regions, i, region); i++)
+	{
+	  if (refined_region_contains_bb_p (region, bb)
+	      || (region->exit == bb)
+	      || (region->entry == bb))
+	    {
+	      switch (i % 17)
+		{
+		case 0: /* red */
+		  color = "#e41a1c";
+		  break;
+		case 1: /* blue */
+		  color = "#377eb8";
+		  break;
+		case 2: /* green */
+		  color = "#4daf4a";
+		  break;
+		case 3: /* purple */
+		  color = "#984ea3";
+		  break;
+		case 4: /* orange */
+		  color = "#ff7f00";
+		  break;
+		case 5: /* yellow */
+		  color = "#ffff33";
+		  break;
+		case 6: /* brown */
+		  color = "#a65628";
+		  break;
+		case 7: /* rose */
+		  color = "#f781bf";
+		  break;
+		case 8:
+		  color = "#8dd3c7";
+		  break;
+		case 9:
+		  color = "#ffffb3";
+		  break;
+		case 10:
+		  color = "#bebada";
+		  break;
+		case 11:
+		  color = "#fb8072";
+		  break;
+		case 12:
+		  color = "#80b1d3";
+		  break;
+		case 13:
+		  color = "#fdb462";
+		  break;
+		case 14:
+		  color = "#b3de69";
+		  break;
+		case 15:
+		  color = "#fccde5";
+		  break;
+		case 16:
+		  color = "#bc80bd";
+		  break;
+		default: /* gray */
+		  color = "#999999";
+		}
+
+	      fprintf (file, "    <TR><TD WIDTH=\"50\" BGCOLOR=\"%s\">", color);
+
+	      if (!refined_region_contains_bb_p (region, bb))
+		fprintf (file, " (");
+
+	      if (bb == region->entry
+		  && bb == region->exit)
+		fprintf (file, " %d*# ", bb->index);
+	      else if (bb == region->entry)
+		fprintf (file, " %d* ", bb->index);
+	      else if (bb == region->exit)
+		fprintf (file, " %d# ", bb->index);
+	      else
+		fprintf (file, " %d ", bb->index);
+
+	      if (!refined_region_contains_bb_p (region, bb))
+		fprintf (file, ")");
+
+	      fprintf (file, "</TD></TR>\n");
+	      part_of_scop  = true;
+	    }
+	}
+
+      if (!part_of_scop)
+	{
+	  fprintf (file, "    <TR><TD WIDTH=\"50\" BGCOLOR=\"#ffffff\">");
+	  fprintf (file, " %d </TD></TR>\n", bb->index);
+	}
+      fprintf (file, "  </TABLE>>, shape=box, style=\"setlinewidth(0)\"]\n");
+    }
+
+  FOR_ALL_BB (bb)
+  {
+    FOR_EACH_EDGE (e, ei, bb->succs)
+      fprintf (file, "%d -> %d;\n", bb->index, e->dest->index);
+  }
+
+  fputs ("}\n\n", file);
+
+  /* Enable debugging again.  */
+  dump_flags = tmp_dump_flags;
+}
+
+/* Display refined REGIONS using dotty.  */
+
+void
+dot_regions (VEC (refined_region_p, heap) *regions)
+{
+  /* When debugging, enable the following code.  This cannot be used
+     in production compilers because it calls "system".  */
+#if 1
+  FILE *stream = fopen ("/tmp/regions.dot", "w");
+  gcc_assert (stream);
+
+  dot_regions_1 (stream, regions);
+  fclose (stream);
+
+  system ("dotty /tmp/regions.dot &");
+#else
+  dot_all_scops_1 (stderr, regions);
+#endif
+}
diff --git a/gcc/refined-regions.h b/gcc/refined-regions.h
index 534e3a4..9f0615a 100644
--- a/gcc/refined-regions.h
+++ b/gcc/refined-regions.h
@@ -92,5 +92,6 @@ extern bool refined_region_contains_region_p (refined_region_p,
 extern void print_refined_region (FILE*, refined_region_p, int, bool);
 extern void debug_refined_region (refined_region_p);
 extern void get_bbs_in_region (refined_region_p, VEC (basic_block, heap) **);
+extern void dot_regions (VEC (refined_region_p, heap) *);
 
 #endif  /* GCC_REFINED_REGIONS_H */
-- 
1.7.0.4



More information about the Gcc-patches mailing list