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: [PATCH] Add debug_function_to_file


On 18/02/16 16:27, Richard Biener wrote:
Attached is what I have for now, it works if you call it like

(gdb) dot-fn cfun
(gdb) dot-fn cfun, 1<<6

w/o that arg parsing ;)

I'll play with it some more tomorrow.

Richard.

2016-02-18  Richard Biener  <rguenther@suse.de>

+ /* Overload with additional flag argument.  */
+
+ void DEBUG_FUNCTION
+ print_graph_cfg (FILE *fp, struct function *fun, int flags)
+ {
+   int saved_dump_flags = dump_flags;
+   dump_flags = flags;
+   print_graph_cfg (fp, fun);
+   dump_flags = saved_dump_flags;
+ }
+
+

FTR, this is what I wrote for adding the flags argument
to dump_bb_for_graph. I ran out of steam at rtl_dump_bb_for_graph, and resorted to the same save-restore dump_flags trick, although it felt a bit hacky to me.

Thanks,
- Tom
Use flags parameter to debug_function_graph_to_file

2016-02-17  Tom de Vries  <tom@codesourcery.com>

	* cfghooks.c (dump_bb_for_graph): Add and handle flags parameter.
	* cfghooks.h (struct cfg_hooks): Add int parameter in dump_bb_for_graph
	declaration.
	* gimple-pretty-print.c (gimple_dump_bb_for_graph): Add and handle flags
	parameter.
	* gimple-pretty-print.h (gimple_dump_bb_for_graph): Add int parameter.
	* graph.c (draw_cfg_node, draw_cfg_nodes_no_loops)
	(draw_cfg_nodes_for_loop, draw_cfg_nodes, print_graph_cfg_fp)
	(print_graph_cfg, debug_function_graph_to_file): Add and handle flags
	parameter.
	* graph.h (debug_function_graph_to_file): Add int parameter.
	* print-rtl.c (rtl_dump_bb_for_graph): Add and handle flags parameter.
	* print-rtl.h (rtl_dump_bb_for_graph): Add int parameter.

---
 gcc/cfghooks.c            |  4 ++--
 gcc/cfghooks.h            |  4 ++--
 gcc/gimple-pretty-print.c |  8 ++++----
 gcc/gimple-pretty-print.h |  2 +-
 gcc/graph.c               | 33 +++++++++++++++++----------------
 gcc/graph.h               |  2 +-
 gcc/print-rtl.c           | 11 ++++++++---
 gcc/print-rtl.h           |  2 +-
 8 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/gcc/cfghooks.c b/gcc/cfghooks.c
index bbb1017..9993de1 100644
--- a/gcc/cfghooks.c
+++ b/gcc/cfghooks.c
@@ -304,7 +304,7 @@ debug (basic_block_def *ptr)
    escaped, using pp_write_text_as_dot_label_to_stream().  */
 
 void
-dump_bb_for_graph (pretty_printer *pp, basic_block bb)
+dump_bb_for_graph (pretty_printer *pp, basic_block bb, int flags)
 {
   if (!cfg_hooks->dump_bb_for_graph)
     internal_error ("%s does not support dump_bb_for_graph",
@@ -314,7 +314,7 @@ dump_bb_for_graph (pretty_printer *pp, basic_block bb)
   pp_printf (pp, " FREQ:%i |", bb->frequency);
   pp_write_text_to_stream (pp);
   if (!(dump_flags & TDF_SLIM))
-    cfg_hooks->dump_bb_for_graph (pp, bb);
+    cfg_hooks->dump_bb_for_graph (pp, bb, flags);
 }
 
 /* Dump the complete CFG to FILE.  FLAGS are the TDF_* flags in dumpfile.h.  */
diff --git a/gcc/cfghooks.h b/gcc/cfghooks.h
index b7912a1..3eaee1b 100644
--- a/gcc/cfghooks.h
+++ b/gcc/cfghooks.h
@@ -63,7 +63,7 @@ struct cfg_hooks
   /* Debugging.  */
   int (*verify_flow_info) (void);
   void (*dump_bb) (FILE *, basic_block, int, int);
-  void (*dump_bb_for_graph) (pretty_printer *, basic_block);
+  void (*dump_bb_for_graph) (pretty_printer *, basic_block, int);
 
   /* Basic CFG manipulation.  */
 
@@ -199,7 +199,7 @@ checking_verify_flow_info (void)
 }
 
 extern void dump_bb (FILE *, basic_block, int, int);
-extern void dump_bb_for_graph (pretty_printer *, basic_block);
+extern void dump_bb_for_graph (pretty_printer *, basic_block, int);
 extern void dump_flow_info (FILE *, int);
 
 extern edge redirect_edge_and_branch (edge, basic_block);
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index e27214f..b0de032 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -2577,13 +2577,13 @@ gimple_dump_bb (FILE *file, basic_block bb, int indent, int flags)
   dump_gimple_bb_footer (file, bb, indent, flags);
 }
 
-/* Dumps basic block BB to pretty-printer PP with default dump flags and
+/* Dumps basic block BB to pretty-printer PP with dump flags FLAGS and
    no indentation, for use as a label of a DOT graph record-node.
    ??? Should just use gimple_dump_bb_buff here, except that value profiling
    histogram dumping doesn't know about pretty-printers.  */
 
 void
-gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
+gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb, int flags)
 {
   pp_printf (pp, "<bb %d>:\n", bb->index);
   pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
@@ -2598,7 +2598,7 @@ gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
 	  pp_bar (pp);
 	  pp_write_text_to_stream (pp);
 	  pp_string (pp, "# ");
-	  pp_gimple_stmt_1 (pp, phi, 0, dump_flags);
+	  pp_gimple_stmt_1 (pp, phi, 0, flags);
 	  pp_newline (pp);
 	  pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
 	}
@@ -2610,7 +2610,7 @@ gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
       gimple *stmt = gsi_stmt (gsi);
       pp_bar (pp);
       pp_write_text_to_stream (pp);
-      pp_gimple_stmt_1 (pp, stmt, 0, dump_flags);
+      pp_gimple_stmt_1 (pp, stmt, 0, flags);
       pp_newline (pp);
       pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
     }
diff --git a/gcc/gimple-pretty-print.h b/gcc/gimple-pretty-print.h
index f8eef99..d9d5d84 100644
--- a/gcc/gimple-pretty-print.h
+++ b/gcc/gimple-pretty-print.h
@@ -33,7 +33,7 @@ extern void debug (gimple *ptr);
 extern void print_gimple_expr (FILE *, gimple *, int, int);
 extern void pp_gimple_stmt_1 (pretty_printer *, gimple *, int, int);
 extern void gimple_dump_bb (FILE *, basic_block, int, int);
-extern void gimple_dump_bb_for_graph (pretty_printer *, basic_block);
+extern void gimple_dump_bb_for_graph (pretty_printer *, basic_block, int);
 extern void dump_ssaname_info_to_file (FILE *, tree, int);
 
 #endif /* ! GCC_GIMPLE_PRETTY_PRINT_H */
diff --git a/gcc/graph.c b/gcc/graph.c
index 6a06c03..5f1b465 100644
--- a/gcc/graph.c
+++ b/gcc/graph.c
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfgloop.h"
 #include "graph.h"
 #include "tree.h"
+#include "dumpfile.h"
 
 /* DOT files with the .dot extension are recognized as document templates
    by a well-known piece of word processing software out of Redmond, WA.
@@ -60,7 +61,7 @@ open_graph_file (const char *base, const char *mode)
 /* Draw a basic block BB belonging to the function with FUNCDEF_NO
    as its unique number.  */
 static void
-draw_cfg_node (pretty_printer *pp, int funcdef_no, basic_block bb)
+draw_cfg_node (pretty_printer *pp, int funcdef_no, basic_block bb, int flags)
 {
   const char *shape;
   const char *fillcolor;
@@ -92,7 +93,7 @@ draw_cfg_node (pretty_printer *pp, int funcdef_no, basic_block bb)
     {
       pp_left_brace (pp);
       pp_write_text_to_stream (pp);
-      dump_bb_for_graph (pp, bb);
+      dump_bb_for_graph (pp, bb, flags);
       pp_right_brace (pp);
     }
 
@@ -152,7 +153,7 @@ draw_cfg_node_succ_edges (pretty_printer *pp, int funcdef_no, basic_block bb)
    the end.  */
 
 static void
-draw_cfg_nodes_no_loops (pretty_printer *pp, struct function *fun)
+draw_cfg_nodes_no_loops (pretty_printer *pp, struct function *fun, int flags)
 {
   int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (fun));
   int i, n;
@@ -166,7 +167,7 @@ draw_cfg_nodes_no_loops (pretty_printer *pp, struct function *fun)
        i < n_basic_blocks_for_fn (fun); i++)
     {
       basic_block bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
-      draw_cfg_node (pp, fun->funcdef_no, bb);
+      draw_cfg_node (pp, fun->funcdef_no, bb, flags);
       bitmap_set_bit (visited, bb->index);
     }
   free (rpo);
@@ -177,7 +178,7 @@ draw_cfg_nodes_no_loops (pretty_printer *pp, struct function *fun)
       basic_block bb;
       FOR_ALL_BB_FN (bb, fun)
 	if (! bitmap_bit_p (visited, bb->index))
-	  draw_cfg_node (pp, fun->funcdef_no, bb);
+	  draw_cfg_node (pp, fun->funcdef_no, bb, flags);
     }
 
   sbitmap_free (visited);
@@ -189,7 +190,7 @@ draw_cfg_nodes_no_loops (pretty_printer *pp, struct function *fun)
 
 static void
 draw_cfg_nodes_for_loop (pretty_printer *pp, int funcdef_no,
-			 struct loop *loop)
+			 struct loop *loop, int flags)
 {
   basic_block *body;
   unsigned int i;
@@ -210,7 +211,7 @@ draw_cfg_nodes_for_loop (pretty_printer *pp, int funcdef_no,
 	       loop->num);
 
   for (struct loop *inner = loop->inner; inner; inner = inner->next)
-    draw_cfg_nodes_for_loop (pp, funcdef_no, inner);
+    draw_cfg_nodes_for_loop (pp, funcdef_no, inner, flags);
 
   if (loop->header == NULL)
     return;
@@ -224,7 +225,7 @@ draw_cfg_nodes_for_loop (pretty_printer *pp, int funcdef_no,
     {
       basic_block bb = body[i];
       if (bb->loop_father == loop)
-	draw_cfg_node (pp, funcdef_no, bb);
+	draw_cfg_node (pp, funcdef_no, bb, flags);
     }
 
   free (body);
@@ -237,12 +238,12 @@ draw_cfg_nodes_for_loop (pretty_printer *pp, int funcdef_no,
    All loop bodys are printed in clusters.  */
 
 static void
-draw_cfg_nodes (pretty_printer *pp, struct function *fun)
+draw_cfg_nodes (pretty_printer *pp, struct function *fun, int flags)
 {
   if (loops_for_fn (fun))
-    draw_cfg_nodes_for_loop (pp, fun->funcdef_no, get_loop (fun, 0));
+    draw_cfg_nodes_for_loop (pp, fun->funcdef_no, get_loop (fun, 0), flags);
   else
-    draw_cfg_nodes_no_loops (pp, fun);
+    draw_cfg_nodes_no_loops (pp, fun, flags);
 }
 
 /* Draw all edges in the CFG.  Retreating edges are drawin as not
@@ -274,7 +275,7 @@ draw_cfg_edges (pretty_printer *pp, struct function *fun)
    before edges to cluster nodes properly.  */
 
 static void
-print_graph_cfg_fp (FILE *fp, struct function *fun)
+print_graph_cfg_fp (FILE *fp, struct function *fun, int flags)
 {
   const char *funcname = function_name (fun);
   pretty_printer graph_slim_pp;
@@ -285,7 +286,7 @@ print_graph_cfg_fp (FILE *fp, struct function *fun)
 		 "\tcolor=\"black\";\n"
 		 "\tlabel=\"%s ()\";\n",
 		 funcname, funcname);
-  draw_cfg_nodes (pp, fun);
+  draw_cfg_nodes (pp, fun, flags);
   draw_cfg_edges (pp, fun);
   pp_printf (pp, "}\n");
   pp_flush (pp);
@@ -298,7 +299,7 @@ void
 print_graph_cfg (const char *base, struct function *fun)
 {
   FILE *fp = open_graph_file (base, "a");
-  print_graph_cfg_fp (fp, fun);
+  print_graph_cfg_fp (fp, fun, dump_flags);
   fclose (fp);
 }
 
@@ -347,7 +348,7 @@ finish_graph_dump_file (const char *base)
 /* Dump FUNCTION_DECL FN to FILENAME.  */
 
 DEBUG_FUNCTION void
-debug_function_graph_to_file (tree fn, const char *filename)
+debug_function_graph_to_file (tree fn, const char *filename, int flags)
 {
   FILE *fp = fopen (filename, "w");
   if (fp == NULL)
@@ -357,7 +358,7 @@ debug_function_graph_to_file (tree fn, const char *filename)
     }
 
   start_graph_dump (fp, filename);
-  print_graph_cfg_fp (fp, DECL_STRUCT_FUNCTION (fn));
+  print_graph_cfg_fp (fp, DECL_STRUCT_FUNCTION (fn), flags);
   end_graph_dump (fp);
 
   fclose (fp);
diff --git a/gcc/graph.h b/gcc/graph.h
index a770f77..2618dc3 100644
--- a/gcc/graph.h
+++ b/gcc/graph.h
@@ -23,6 +23,6 @@ along with GCC; see the file COPYING3.  If not see
 extern void print_graph_cfg (const char *, struct function *);
 extern void clean_graph_dump_file (const char *);
 extern void finish_graph_dump_file (const char *);
-extern void debug_function_graph_to_file (tree, const char *);
+extern void debug_function_graph_to_file (tree, const char *, int);
 
 #endif /* ! GCC_GRAPH_H */
diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c
index 85d9b8d..fe4c422 100644
--- a/gcc/print-rtl.c
+++ b/gcc/print-rtl.c
@@ -1678,12 +1678,15 @@ dump_rtl_slim (FILE *f, const rtx_insn *first, const rtx_insn *last,
    no indentation, for use as a label of a DOT graph record-node.  */
 
 void
-rtl_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
+rtl_dump_bb_for_graph (pretty_printer *pp, basic_block bb,
+		       int flags)
 {
-  rtx_insn *insn;
-  bool first = true;
+  int save_dump_flags = dump_flags;
+  dump_flags = flags;
 
   /* TODO: inter-bb stuff.  */
+  rtx_insn *insn;
+  bool first = true;
   FOR_BB_INSNS (bb, insn)
     {
       if (! first)
@@ -1695,6 +1698,8 @@ rtl_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
       print_insn_with_notes (pp, insn);
       pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
     }
+
+  dump_flags = save_dump_flags;
 }
 
 /* Pretty-print pattern X of some insn in non-verbose mode.
diff --git a/gcc/print-rtl.h b/gcc/print-rtl.h
index 28b4626..556e186 100644
--- a/gcc/print-rtl.h
+++ b/gcc/print-rtl.h
@@ -32,7 +32,7 @@ extern void print_value (pretty_printer *, const_rtx, int);
 extern void print_pattern (pretty_printer *, const_rtx, int);
 extern void print_insn (pretty_printer *pp, const rtx_insn *x, int verbose);
 
-extern void rtl_dump_bb_for_graph (pretty_printer *, basic_block);
+extern void rtl_dump_bb_for_graph (pretty_printer *, basic_block, int);
 extern const char *str_pattern_slim (const_rtx);
 
 #endif  // GCC_PRINT_RTL_H

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