public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Improve loop debugging functions
@ 2007-12-15  8:28 Sebastian Pop
  2007-12-15 13:39 ` Diego Novillo
  2007-12-15 17:35 ` Zdenek Dvorak
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Pop @ 2007-12-15  8:28 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 108 bytes --]

Hi,

This patch improves the information printed for loops.  Okay for trunk?

Sebastian
-- 
AMD - GNU Tools

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 856_debug_loops.diff --]
[-- Type: text/x-diff; name=856_debug_loops.diff, Size: 7096 bytes --]

2007-12-14  Sebastian Pop  <sebastian.pop@amd.com>

	* tree-scalar-evolution.c (number_of_iterations_for_all_loops): Replace
	print_loop_ir with print_loops.
	* tree-flow.h (dot_cfg, debug_loops, debug_loop, debug_loop_num,
	print_loops, print_loops_bb): Declare.
	* tree-cfg.c (print_loops_bb): New.
	(print_loop): Print header, latch, bounds, estimation of iterations.
	(print_loop_and_siblings): New.
	(print_loop_ir): Renamed print_loops.
	(debug_loop_ir): Renamed debug_loops.
	(debug_loop, debug_loop_num): New.

Index: tree-scalar-evolution.c
===================================================================
--- tree-scalar-evolution.c	(revision 130927)
+++ tree-scalar-evolution.c	(working copy)
@@ -2376,7 +2376,7 @@ number_of_iterations_for_all_loops (VEC(
       fprintf (dump_file, "-----------------------------------------\n");
       fprintf (dump_file, ")\n\n");
       
-      print_loop_ir (dump_file);
+      print_loops (dump_file, 3);
     }
 }
 
Index: tree-flow.h
===================================================================
--- tree-flow.h	(revision 130927)
+++ tree-flow.h	(working copy)
@@ -741,9 +741,13 @@ extern basic_block debug_tree_bb_n (int)
 extern void dump_tree_cfg (FILE *, int);
 extern void debug_tree_cfg (int);
 extern void dump_cfg_stats (FILE *);
+extern void dot_cfg (void);
 extern void debug_cfg_stats (void);
-extern void debug_loop_ir (void);
-extern void print_loop_ir (FILE *);
+extern void debug_loops (int);
+extern void debug_loop (struct loop *, int);
+extern void debug_loop_num (unsigned, int);
+extern void print_loops (FILE *, int);
+extern void print_loops_bb (FILE *, basic_block, int, int);
 extern void cleanup_dead_labels (void);
 extern void group_case_labels (void);
 extern tree first_stmt (basic_block);
Index: tree-cfg.c
===================================================================
--- tree-cfg.c	(revision 130927)
+++ tree-cfg.c	(working copy)
@@ -6188,12 +6188,6 @@ debug_function (tree fn, int flags)
 }
 
 
-/* Pretty print of the loops intermediate representation.  */
-static void print_loop (FILE *, struct loop *, int);
-static void print_pred_bbs (FILE *, basic_block bb);
-static void print_succ_bbs (FILE *, basic_block bb);
-
-
 /* Print on FILE the indexes for the predecessors of basic_block BB.  */
 
 static void
@@ -6219,11 +6213,42 @@ print_succ_bbs (FILE *file, basic_block 
     fprintf (file, "bb_%d ", e->dest->index);
 }
 
+/* Print to FILE the basic block BB following the VERBOSITY level.  */
+
+void 
+print_loops_bb (FILE *file, basic_block bb, int indent, int verbosity)
+{
+  char *s_indent = (char *) alloca ((size_t) indent + 1);
+  memset ((void *) s_indent, ' ', (size_t) indent);
+  s_indent[indent] = '\0';
+
+  /* Print basic_block's header.  */
+  if (verbosity >= 2)
+    {
+      fprintf (file, "%s  bb_%d (preds = {", s_indent, bb->index);
+      print_pred_bbs (file, bb);
+      fprintf (file, "}, succs = {");
+      print_succ_bbs (file, bb);
+      fprintf (file, "})\n");
+    }
+
+  /* Print basic_block's body.  */
+  if (verbosity >= 3)
+    {
+      fprintf (file, "%s  {\n", s_indent);
+      tree_dump_bb (bb, file, indent + 4);
+      fprintf (file, "%s  }\n", s_indent);
+    }
+}
+
+static void print_loop_and_siblings (FILE *, struct loop *, int, int);
 
-/* Pretty print LOOP on FILE, indented INDENT spaces.  */
+/* Pretty print LOOP on FILE, indented INDENT spaces.  Following
+   VERBOSITY level this outputs the contents of the loop, or just its
+   structure.  */
 
 static void
-print_loop (FILE *file, struct loop *loop, int indent)
+print_loop (FILE *file, struct loop *loop, int indent, int verbosity)
 {
   char *s_indent;
   basic_block bb;
@@ -6235,55 +6260,90 @@ print_loop (FILE *file, struct loop *loo
   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 loop's header.  */
+  fprintf (file, "%sloop_%d (header = %d, latch = %d", s_indent, 
+	   loop->num, loop->header->index, loop->latch->index);
+  fprintf (file, ", niter = ");
+  print_generic_expr (file, loop->nb_iterations, 0);
+
+  if (loop->any_upper_bound)
+    {
+      fprintf (file, ", upper_bound = ");
+      dump_double_int (file, loop->nb_iterations_upper_bound, true);
+    }
+
+  if (loop->any_estimate)
+    {
+      fprintf (file, ", estimate = ");
+      dump_double_int (file, loop->nb_iterations_estimate, true);
+    }
+  fprintf (file, ")\n");
 
-  /* 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);
-	fprintf (file, "}, succs = {");
-	print_succ_bbs (file, bb);
-	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);
+  /* Print loop's body.  */
+  if (verbosity >= 1)
+    {
+      fprintf (file, "%s{\n", s_indent);
+      FOR_EACH_BB (bb)
+	if (bb->loop_father == loop)
+	  print_loops_bb (file, bb, indent, verbosity);
+
+      print_loop_and_siblings (file, loop->inner, indent + 2, verbosity);
+      fprintf (file, "%s}\n", s_indent);
+    }
 }
 
+/* Print the LOOP and its sibling loops on FILE, indented INDENT
+   spaces.  Following VERBOSITY level this outputs the contents of the
+   loop, or just its structure.  */
+
+static void
+print_loop_and_siblings (FILE *file, struct loop *loop, int indent, int verbosity)
+{
+  if (loop == NULL)
+    return;
+
+  print_loop (file, loop, indent, verbosity);
+  print_loop_and_siblings (file, loop->next, indent, verbosity);
+}
 
 /* Follow a CFG edge from the entry point of the program, and on entry
    of a loop, pretty print the loop structure on FILE.  */
 
 void
-print_loop_ir (FILE *file)
+print_loops (FILE *file, int verbosity)
 {
   basic_block bb;
 
   bb = BASIC_BLOCK (NUM_FIXED_BLOCKS);
   if (bb && bb->loop_father)
-    print_loop (file, bb->loop_father, 0);
+    print_loop_and_siblings (file, bb->loop_father, 0, verbosity);
 }
 
 
-/* Debugging loops structure at tree level.  */
+/* Debugging loops structure at tree level, at some VERBOSITY level.  */
 
 void
-debug_loop_ir (void)
+debug_loops (int verbosity)
 {
-  print_loop_ir (stderr);
+  print_loops (stderr, verbosity);
 }
 
+/* Print on stderr the code of LOOP, at some VERBOSITY level.  */
+
+void
+debug_loop (struct loop *loop, int verbosity)
+{
+  print_loop (stderr, loop, 0, verbosity);
+}
+
+/* Print on stderr the code of loop number NUM, at some VERBOSITY
+   level.  */
+
+void
+debug_loop_num (unsigned num, int verbosity)
+{
+  debug_loop (get_loop (num), verbosity);
+}
 
 /* Return true if BB ends with a call, possibly followed by some
    instructions that must stay with the call.  Return false,

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Improve loop debugging functions
  2007-12-15  8:28 [PATCH] Improve loop debugging functions Sebastian Pop
@ 2007-12-15 13:39 ` Diego Novillo
  2007-12-15 18:44   ` Sebastian Pop
  2007-12-15 17:35 ` Zdenek Dvorak
  1 sibling, 1 reply; 5+ messages in thread
From: Diego Novillo @ 2007-12-15 13:39 UTC (permalink / raw)
  To: Sebastian Pop; +Cc: GCC Patches

On 12/15/07 01:31, Sebastian Pop wrote:

> This patch improves the information printed for loops.  Okay for trunk?

OK for 4.4.


Diego.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Improve loop debugging functions
  2007-12-15  8:28 [PATCH] Improve loop debugging functions Sebastian Pop
  2007-12-15 13:39 ` Diego Novillo
@ 2007-12-15 17:35 ` Zdenek Dvorak
  1 sibling, 0 replies; 5+ messages in thread
From: Zdenek Dvorak @ 2007-12-15 17:35 UTC (permalink / raw)
  To: Sebastian Pop; +Cc: GCC Patches

Hi,

> This patch improves the information printed for loops.  Okay for trunk?

OK.

Zdenek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Improve loop debugging functions
  2007-12-15 13:39 ` Diego Novillo
@ 2007-12-15 18:44   ` Sebastian Pop
  2007-12-16 21:06     ` Diego Novillo
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Pop @ 2007-12-15 18:44 UTC (permalink / raw)
  To: Diego Novillo; +Cc: GCC Patches

On Dec 15, 2007 7:38 AM, Diego Novillo <dnovillo@google.com> wrote:
> On 12/15/07 01:31, Sebastian Pop wrote:
>
> > This patch improves the information printed for loops.  Okay for trunk?
>
> OK for 4.4.
>

Diego,
I need this patch for fixing bugs in 4.3, otherwise it's just overhead to apply
it every time I'm debugging something.  The code in this patch is safe as it
is called only for debugging purposes.  As Zdenek also approved it,
I'm going to commit it.

Sebastian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Improve loop debugging functions
  2007-12-15 18:44   ` Sebastian Pop
@ 2007-12-16 21:06     ` Diego Novillo
  0 siblings, 0 replies; 5+ messages in thread
From: Diego Novillo @ 2007-12-16 21:06 UTC (permalink / raw)
  To: Sebastian Pop; +Cc: GCC Patches

On 12/15/07 13:29, Sebastian Pop wrote:

> I need this patch for fixing bugs in 4.3, otherwise it's just overhead to apply
> it every time I'm debugging something.  The code in this patch is safe as it
> is called only for debugging purposes.  As Zdenek also approved it,
> I'm going to commit it.

This late in the development process is not a good time to apply 
anything other than bug fixing patches.  I would ask you to not commit 
this patch now, but if you need it for bug fixing, I guess it can't hurt.

For future submissions, you need to mention this exceptional 
circumstance in your original patch description.


Diego.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-12-16 20:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-15  8:28 [PATCH] Improve loop debugging functions Sebastian Pop
2007-12-15 13:39 ` Diego Novillo
2007-12-15 18:44   ` Sebastian Pop
2007-12-16 21:06     ` Diego Novillo
2007-12-15 17:35 ` Zdenek Dvorak

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).