This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [tree-ssa, LNO] Analysis of scalar evolutions and data dependences


> 
> Maybe the pretty printing of the loop IR is a part that should go into
> the tree-ssa instead of the sub branch (loop-nest-optimizer branch?).
> 

Let's start with this hunk.  

Until recently it was possible to read the debug_generic_stmt () and
quickly find the loop structures.  This is no longer the case, and for
detecting the loop hierarchy from the "linear" dumped code, you have
to detect the natural loops by hand...

The attached patch dumps the loop structure together with the CFG 
structure, and the statements in each basic block.  


2003-12-12  Sebastian Pop  <s.pop@laposte.net>

	* tree-cfg.c (print_loop, print_pred_bbs, print_succ_bbs, 
	debug_loop_ir, print_loop_ir): New.
	* tree-flow.g (debug_loop_ir, print_loop_ir): Declare.


Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.235
diff -d -u -p -r1.1.4.235 tree-cfg.c
--- tree-cfg.c	11 Dec 2003 01:29:50 -0000	1.1.4.235
+++ tree-cfg.c	12 Dec 2003 10:33:33 -0000
@@ -3783,6 +3783,115 @@ dump_function_to_file (tree fn, FILE *fi
   fprintf (file, "\n\n");
 }
 
+/* Pretty print of the loops intermediate representation.  */
+
+static void print_loop (FILE *, struct loop *, int);
+static void print_pred_bbs (FILE *, edge);
+static void print_succ_bbs (FILE *, edge);
+
+/* Print the predecessors indexes.  */
+
+static void
+print_pred_bbs (FILE *file, 
+		edge e)
+{
+  if (e == NULL)
+    return;
+  
+  else if (e->pred_next == NULL)
+    fprintf (file, "bb_%d", e->src->index);
+  
+  else
+    {
+      fprintf (file, "bb_%d, ", e->src->index);
+      print_pred_bbs (file, e->pred_next);
+    }
+}
+
+/* Print the successors indexes.  */
+
+static void
+print_succ_bbs (FILE *file, 
+		edge e)
+{
+  if (e == NULL)
+    return;
+  
+  else if (e->succ_next == NULL)
+    fprintf (file, "bb_%d", e->dest->index);
+  
+  else
+    {
+      fprintf (file, "bb_%d, ", e->dest->index);
+      print_succ_bbs (file, e->succ_next);
+    }
+}
+
+/* Pretty print a loop on the given file.  */
+
+static void
+print_loop (FILE *file, 
+	    struct loop *loop, 
+	    int indent)
+{
+  char *s_indent;
+  basic_block bb;
+  
+  if (loop == NULL)
+    return;
+
+  s_indent = (char *) alloca ((size_t) indent + 1);
+  memset ((void *) s_indent, ' ', (size_t) indent);
+  s_indent[indent] = '\0';
+
+  
+  /* Print the loop's header.  */
+  fprintf (file, "%sloop_%d\n", s_indent, loop->num);
+  
+  /* Print the loop's body.  */
+  fprintf (file, "%s{\n", s_indent);
+  FOR_EACH_BB (bb)
+    if (bb->loop_father == loop)
+      {
+	/* Print the basic_block's header.  */
+	fprintf (file, "%s  bb_%d (preds = {", s_indent, bb->index);
+	print_pred_bbs (file, bb->pred);
+	fprintf (file, "}, succs = {");
+	print_succ_bbs (file, bb->succ);
+	fprintf (file, "})\n");
+	
+	/* Print the basic_block's body.  */
+	fprintf (file, "%s  {\n", s_indent);
+	tree_dump_bb (bb, file, indent + 4);
+	fprintf (file, "%s  }\n", s_indent);
+      }
+  
+  print_loop (file, loop->inner, indent + 2);
+  fprintf (file, "%s}\n", s_indent);
+  print_loop (file, loop->next, indent);
+}
+
+/* Follow a CFG edge from the entry point of the program, and on entry
+   of a loop, pretty print the loop structure.  */
+
+void 
+print_loop_ir (FILE *file)
+{
+  basic_block bb;
+  
+  bb = BASIC_BLOCK (0);
+  if (bb && bb->loop_father)
+    print_loop (file, bb->loop_father, 0);
+}
+
+/* Debugging loops structure at tree level.  */
+
+void 
+debug_loop_ir (void)
+{
+  print_loop_ir (stderr);
+}
+
 /* FIXME These need to be filled in with appropriate pointers.  But this
    implies an ABI change in some functions.  */
 struct cfg_hooks tree_cfg_hooks = {
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.167
diff -d -u -p -r1.1.4.167 tree-flow.h
--- tree-flow.h	8 Dec 2003 12:58:22 -0000	1.1.4.167
+++ tree-flow.h	12 Dec 2003 10:33:33 -0000
@@ -424,6 +424,8 @@ extern void debug_tree_cfg (int);
 extern void dump_cfg_stats (FILE *);
 extern void debug_cfg_stats (void);
 extern void tree_cfg2dot (FILE *);
+extern void debug_loop_ir (void);
+extern void print_loop_ir (FILE *);
 extern void insert_bb_before (basic_block, basic_block);
 extern void cleanup_tree_cfg (void);
 extern bool remove_unreachable_blocks (void);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]