From patchwork Mon Dec 3 16:54:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Bosscher X-Patchwork-Id: 203399 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]) by ozlabs.org (Postfix) with SMTP id 51C5A2C0082 for ; Tue, 4 Dec 2012 03:55:44 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1355158545; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: MIME-Version:Received:From:Date:Message-ID:Subject:To:Cc: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=iaCv9ob Y9nYGwrYgwAIzmyskxV4=; b=v4W/AczgSVhCiYEreWwnUfrL/Bixa0cQMpaCWa/ 9WKShqA13IvLH8r6XIgi3IFoNqGrEm+WM53DdlChIMxVUFUfILLBBAqhrcYOUlyh x7o6kIFS03k52wbGsJ59ke8PRkYjjDB04XMB0D/eie3SY7on27Tn1fG3V6M33QiG TP/E= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:MIME-Version:Received:From:Date:Message-ID:Subject:To:Cc:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=rnc393T0IQNcw0jpvhbKA3ESi+H8y8zeNtDGMGx9bF421J66TqvFFXSEmuQYlT bMg3nG6gpRXLcnMEflWYvIW5EssfPYwHDHRh8FxgoQA+8QPu5i2GgajVpOnw64Gb XDni/amlJdwYLGMPya8peKy9nMRNtIclHhW/nTWYYFsTo=; Received: (qmail 23438 invoked by alias); 3 Dec 2012 16:55:35 -0000 Received: (qmail 23424 invoked by uid 22791); 3 Dec 2012 16:55:30 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_CF, TW_FN, TW_IQ X-Spam-Check-By: sourceware.org Received: from mail-vb0-f47.google.com (HELO mail-vb0-f47.google.com) (209.85.212.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 03 Dec 2012 16:55:22 +0000 Received: by mail-vb0-f47.google.com with SMTP id e21so1926352vbm.20 for ; Mon, 03 Dec 2012 08:55:21 -0800 (PST) Received: by 10.58.239.162 with SMTP id vt2mr9461537vec.1.1354553721792; Mon, 03 Dec 2012 08:55:21 -0800 (PST) MIME-Version: 1.0 Received: by 10.58.215.38 with HTTP; Mon, 3 Dec 2012 08:54:41 -0800 (PST) From: Steven Bosscher Date: Mon, 3 Dec 2012 17:54:41 +0100 Message-ID: Subject: [patch] Hookize CFG DOT graph dumping To: GCC Patches Cc: Richard Biener X-IsSubscribed: yes 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 Hello, This is the last patch in this series for now, unless I can convince everyone that some files should be renamed after all these changes :-) The attached patch makes graph.c independent of the IR contained in the CFG it dumps. For this, I made the node label dumping routine a cfghook. I also changed the dumper to take a struct function rather than a fndecl tree, and use the funcdef_no as the unique number for the function. This helps when annotating the graph with profile information from .gcda files (I have a tool for that :-). I also noticed I introduced a bug in the dumping of REG_NOTEs in slim RTL dumps. Also fixed by this patch. Bootstrapped&tested on powerpc64-unknown-linux-gnu. OK? Ciao! Steven * rtl.h (print_insn_with_notes): Remove prototype. (rtl_dump_bb_for_graph): New prototype. * sched-vis.c (print_insn_with_notes): Make static again. Fix printing of notes. (rtl_dump_bb_for_graph): New function. * cfghooks.h (struct cfg_hooks) : New hook. (dump_bb_for_graph): New prototype. * cfghooks.c (dump_bb_for_graph): New function. * tree-cfg.c (gimple_cfg_hooks): Register gimple_dump_bb_for_graph as dump_bb_for_graph hook implementation for GIMPLE. * cfgrtl.c (rtl_cfg_hooks): Likewise for rtl_dump_bb_for_graph. (cfg_layout_rtl_cfg_hooks): Likewise. * graph.c (draw_cfg_node): Don't include sbitmap.h, rtl.h, tree.h, gimple.h, and gimple-pretty-print.h. (draw_cfg_node, draw_cfg_node_succ_edges): Use the uniqe function definition number instead of the function declaration UID. (print_graph_cfg): Take a struct function instead of a tree. Use the dump_bb_for_graph hook to dump the basic block content. * graph.h (print_graph_cfg): Update prototype. * passes.c (execute_function_dump): Update print_graph_cfg call. * Makefile.in (graph.o): Fixup dependencies. Index: rtl.h =================================================================== --- rtl.h (revision 194085) +++ rtl.h (working copy) @@ -2606,7 +2606,7 @@ extern void dump_rtl_slim (FILE *, const_rtx, cons extern void print_value (pretty_printer *, const_rtx, int); extern void print_pattern (pretty_printer *, const_rtx, int); extern void print_insn (pretty_printer *, const_rtx, int); -extern void print_insn_with_notes (pretty_printer *, const_rtx); +extern void rtl_dump_bb_for_graph (pretty_printer *, basic_block); extern const char *str_pattern_slim (const_rtx); /* In function.c */ Index: sched-vis.c =================================================================== --- sched-vis.c (revision 194085) +++ sched-vis.c (working copy) @@ -716,10 +716,10 @@ print_insn (pretty_printer *pp, const_rtx x, int v } } /* print_insn */ -/* Prerry-print a slim dump of X (an insn) to PP, including any register +/* Pretty-print a slim dump of X (an insn) to PP, including any register note attached to the instruction. */ -void +static void print_insn_with_notes (pretty_printer *pp, const_rtx x) { pp_string (pp, print_rtx_head); @@ -728,9 +728,9 @@ print_insn_with_notes (pretty_printer *pp, const_r if (INSN_P (x) && REG_NOTES (x)) for (rtx note = REG_NOTES (x); note; note = XEXP (note, 1)) { - pp_printf (pp, "%s %s", print_rtx_head, + pp_printf (pp, "%s %s ", print_rtx_head, GET_REG_NOTE_NAME (REG_NOTE_KIND (note))); - print_pattern (pp, XEXP (note, 0), 1); + print_pattern (pp, XEXP (note, 0), 1); pp_newline (pp); } } @@ -800,6 +800,29 @@ dump_rtl_slim (FILE *f, const_rtx first, const_rtx pp_flush (pp); } +/* Dumps basic block BB to pretty-printer PP in slim form and without and + 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) +{ + rtx insn; + bool first = true; + + /* TODO: inter-bb stuff. */ + FOR_BB_INSNS (bb, insn) + { + if (! first) + { + pp_character (pp, '|'); + pp_write_text_to_stream (pp); + } + first = false; + print_insn_with_notes (pp, insn); + pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true); + } +} + /* Pretty-print pattern X of some insn in non-verbose mode. Return a string pointer to the pretty-printer buffer. Index: cfghooks.h =================================================================== --- cfghooks.h (revision 194084) +++ cfghooks.h (working copy) @@ -29,6 +29,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); /* Basic CFG manipulation. */ @@ -152,6 +153,8 @@ struct cfg_hooks extern void verify_flow_info (void); extern void dump_bb (FILE *, basic_block, int, int); +extern void dump_bb_for_graph (pretty_printer *, basic_block); + extern edge redirect_edge_and_branch (edge, basic_block); extern basic_block redirect_edge_and_branch_force (edge, basic_block); extern bool can_remove_branch_p (const_edge); Index: cfghooks.c =================================================================== --- cfghooks.c (revision 194084) +++ cfghooks.c (working copy) @@ -280,6 +280,22 @@ dump_bb (FILE *outf, basic_block bb, int indent, i fputc ('\n', outf); } +/* Dumps basic block BB to pretty-printer PP, for use as a label of + a DOT graph record-node. The implementation of this hook is + expected to write the label to the stream that is attached to PP. + Field separators between instructions are pipe characters printed + verbatim. Instructions should be written with some characters + escaped, using pp_write_text_as_dot_label_to_stream(). */ + +void +dump_bb_for_graph (pretty_printer *pp, basic_block bb) +{ + if (!cfg_hooks->dump_bb_for_graph) + internal_error ("%s does not support dump_bb_for_graph", + cfg_hooks->name); + cfg_hooks->dump_bb_for_graph (pp, bb); +} + /* Dump the complete CFG to FILE. FLAGS are the TDF_* flags in dumpfile.h. */ void dump_flow_info (FILE *file, int flags) Index: tree-cfg.c =================================================================== --- tree-cfg.c (revision 194084) +++ tree-cfg.c (working copy) @@ -7620,6 +7620,7 @@ struct cfg_hooks gimple_cfg_hooks = { "gimple", gimple_verify_flow_info, gimple_dump_bb, /* dump_bb */ + gimple_dump_bb_for_graph, /* dump_bb_for_graph */ create_bb, /* create_basic_block */ gimple_redirect_edge_and_branch, /* redirect_edge_and_branch */ gimple_redirect_edge_and_branch_force, /* redirect_edge_and_branch_force */ Index: cfgrtl.c =================================================================== --- cfgrtl.c (revision 194084) +++ cfgrtl.c (working copy) @@ -4529,6 +4529,7 @@ struct cfg_hooks rtl_cfg_hooks = { "rtl", rtl_verify_flow_info, rtl_dump_bb, + rtl_dump_bb_for_graph, rtl_create_basic_block, rtl_redirect_edge_and_branch, rtl_redirect_edge_and_branch_force, @@ -4570,6 +4571,7 @@ struct cfg_hooks cfg_layout_rtl_cfg_hooks = { "cfglayout mode", rtl_verify_flow_info_1, rtl_dump_bb, + rtl_dump_bb_for_graph, cfg_layout_create_basic_block, cfg_layout_redirect_edge_and_branch, cfg_layout_redirect_edge_and_branch_force, Index: graph.c =================================================================== --- graph.c (revision 194085) +++ graph.c (working copy) @@ -24,15 +24,10 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" #include "diagnostic-core.h" /* for fatal_error */ -#include "sbitmap.h" #include "basic-block.h" -#include "rtl.h" -#include "tree.h" -#include "gimple.h" #include "graph.h" #include "dumpfile.h" #include "pretty-print.h" -#include "gimple-pretty-print.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. @@ -80,10 +75,10 @@ init_graph_slim_pretty_print (FILE *fp) return &graph_slim_pp; } -/* Draw a basic block BB belonging to the function with FNDECL_UID +/* 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 fndecl_uid, basic_block bb) +draw_cfg_node (pretty_printer *pp, int funcdef_no, basic_block bb) { const char *shape; const char *fillcolor; @@ -105,7 +100,7 @@ static void pp_printf (pp, "\tfn_%d_basic_block_%d " "[shape=%s,style=filled,fillcolor=%s,label=\"", - fndecl_uid, bb->index, shape, fillcolor); + funcdef_no, bb->index, shape, fillcolor); if (bb->index == ENTRY_BLOCK) pp_string (pp, "ENTRY"); @@ -115,28 +110,7 @@ static void { pp_character (pp, '{'); pp_write_text_to_stream (pp); - - /* This would be easier if there'd be an IR independent iterator... */ - if (current_ir_type () == IR_GIMPLE) - gimple_dump_bb_for_graph (pp, bb); - else - { - rtx insn; - bool first = true; - - /* TODO: inter-bb stuff. */ - FOR_BB_INSNS (bb, insn) - { - if (! first) - { - pp_character (pp, '|'); - pp_write_text_to_stream (pp); - } - first = false; - print_insn_with_notes (pp, insn); - pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true); - } - } + dump_bb_for_graph (pp, bb); pp_character (pp, '}'); } @@ -145,9 +119,9 @@ static void } /* Draw all successor edges of a basic block BB belonging to the function - with FNDECL_UID as its unique number. */ + with FUNCDEF_NO as its unique number. */ static void -draw_cfg_node_succ_edges (pretty_printer *pp, int fndecl_uid, basic_block bb) +draw_cfg_node_succ_edges (pretty_printer *pp, int funcdef_no, basic_block bb) { edge e; edge_iterator ei; @@ -181,8 +155,8 @@ static void pp_printf (pp, "\tfn_%d_basic_block_%d:s -> fn_%d_basic_block_%d:n " "[style=%s,color=%s,weight=%d,constraint=%s];\n", - fndecl_uid, e->src->index, - fndecl_uid, e->dest->index, + funcdef_no, e->src->index, + funcdef_no, e->dest->index, style, color, weight, (e->flags & (EDGE_FAKE | EDGE_DFS_BACK)) ? "false" : "true"); } @@ -192,10 +166,10 @@ static void /* Print a graphical representation of the CFG of function FUN. */ void -print_graph_cfg (const char *base, tree fndecl) +print_graph_cfg (const char *base, struct function *fun) { - const char *funcname = fndecl_name (fndecl); - int fndecl_uid = DECL_UID (fndecl); + const char *funcname = function_name (fun); + int funcdef_no = fun->funcdef_no; FILE *fp = open_graph_file (base, "a"); int *rpo = XNEWVEC (int, n_basic_blocks); basic_block bb; @@ -212,7 +186,7 @@ void of the nodes. */ n = pre_and_rev_post_order_compute (NULL, rpo, true); for (i = 0; i < n; i++) - draw_cfg_node (pp, fndecl_uid, BASIC_BLOCK (rpo[i])); + draw_cfg_node (pp, funcdef_no, BASIC_BLOCK (rpo[i])); /* Draw all edges at the end to get subgraphs right for GraphViz, which requires nodes to be defined before edges to cluster @@ -224,7 +198,7 @@ void for ourselves is also not desirable.) */ mark_dfs_back_edges (); FOR_ALL_BB (bb) - draw_cfg_node_succ_edges (pp, fndecl_uid, bb); + draw_cfg_node_succ_edges (pp, funcdef_no, bb); pp_printf (pp, "\t}\n"); pp_flush (pp); Index: graph.h =================================================================== --- graph.h (revision 194085) +++ graph.h (working copy) @@ -20,7 +20,7 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_GRAPH_H #define GCC_GRAPH_H -extern void print_graph_cfg (const char *, tree); +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 *); Index: passes.c =================================================================== --- passes.c (revision 194085) +++ passes.c (working copy) @@ -1770,7 +1770,7 @@ execute_function_dump (void *data ATTRIBUTE_UNUSED if ((cfun->curr_properties & PROP_cfg) && (dump_flags & TDF_GRAPH)) - print_graph_cfg (dump_file_name, cfun->decl); + print_graph_cfg (dump_file_name, cfun); } } Index: Makefile.in =================================================================== --- Makefile.in (revision 194084) +++ Makefile.in (working copy) @@ -1846,7 +1846,7 @@ gcc.srcextra: gengtype-lex.c -cp -p $^ $(srcdir) graph.o: graph.c graph.h $(CONFIG_H) $(SYSTEM_H) coretypes.h \ - $(DIAGNOSTIC_CORE_H) $(TM_H) $(RTL_H) $(BASIC_BLOCK_H) $(PRETTY_PRINT_H) + $(DIAGNOSTIC_CORE_H) $(BASIC_BLOCK_H) $(PRETTY_PRINT_H) dumpfile.h sbitmap.o: sbitmap.c sbitmap.h $(CONFIG_H) $(SYSTEM_H) coretypes.h sparseset.o: sparseset.c $(SYSTEM_H) sparseset.h $(CONFIG_H)