From patchwork Thu Feb 18 15:52:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 584781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 513681401E7 for ; Fri, 19 Feb 2016 02:52:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=xtaytGcC; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=Ei5BH3fHz6nTTYI9B lGMkElwEqZZZqX4faV2rTDrQTN3w8KqF2vMPiINXWKwe8jX4Kd3Hw2w6uSlXdrKs Pio1JT5avWOSlAWcs7F/rSzYCQuy61dAU3mxGMRe3+uRqCNsR4qx3kUG3p+dhMUt gSsBI+k5tUxv/78Ze4TrKQdeD4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=vORd/dlg+exY3eSoQAH23PH VE2E=; b=xtaytGcCUwHvCMC584/ycs+FLEwGBuj1YtkgalBDkJHO07DE0UxsfeW 4eDj8RWeJk+4r5p/xIB+sRk6JRZouOXcv3IsZzyzYgP92q5MjJ2nT6Mta2kEyNCx x/eoHjgp1p2I5F9C08Uppxny37VlP+sn69N/DE+zcMnYeOHqYZRw= Received: (qmail 6853 invoked by alias); 18 Feb 2016 15:52:37 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 6835 invoked by uid 89); 18 Feb 2016 15:52:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=non-verbose, nonverbose, steam, 607 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 18 Feb 2016 15:52:35 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47427) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1aWQsa-0001Xc-Pn for gcc-patches@gnu.org; Thu, 18 Feb 2016 10:52:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWQsX-0002aO-7B for gcc-patches@gnu.org; Thu, 18 Feb 2016 10:52:32 -0500 Received: from relay1.mentorg.com ([192.94.38.131]:64495) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWQsW-0002aJ-Tu for gcc-patches@gnu.org; Thu, 18 Feb 2016 10:52:29 -0500 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1aWQsU-00072g-Dr from Tom_deVries@mentor.com ; Thu, 18 Feb 2016 07:52:26 -0800 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Thu, 18 Feb 2016 15:52:25 +0000 Subject: Re: [PATCH] Add debug_function_to_file To: Richard Biener References: <56C46A70.4070605@mentor.com> <56C5D52E.9040302@mentor.com> <56C5E0A9.1040900@mentor.com> CC: "gcc-patches@gnu.org" From: Tom de Vries Message-ID: <56C5E8B0.3090508@mentor.com> Date: Thu, 18 Feb 2016 16:52:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 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 > + /* 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 * 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, ":\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