From 41222ddf8ee150c52e13d48c5d1b6907a0ce589d Mon Sep 17 00:00:00 2001 From: Steven Bosscher Date: Mon, 3 Dec 2012 13:16:55 +0000 Subject: [PATCH] rtl.h (print_insn_with_notes): Prototype. * rtl.h (print_insn_with_notes): Prototype. * sched-vis.c (print_insn_with_notes): Export it. * gimple-pretty-print.h (gimple_dump_bb_for_graph): Prototype. * gimple-pretty-print.c (print_gimple_expr): Flush the buffer. (pp_gimple_stmt_1): Don't do it here. (gimple_dump_bb_for_graph): New function. * tree-pretty-print.c (print_generic_expr): Flush the buffer here. (dump_generic_node): Don't flush the buffer here. * graph.h (print_rtl_graph_with_bb): Rename to print_graph_cfg. * graph.c: Include gimple.h, dumpfile.h, and gimple-pretty-print.h. (draw_cfg_node): Handle GIMPLE basic blocks also. (print_rtl_graph_with_bb): Rename to print_graph_cfg. * passes.c (finish_optimization_passes): Don't finish graph dumps here. (execute_function_dump): Use print_graph_cfg. Enable dumping the CFG for GIMPLE also. (pass_init_dump_file): Wrap in TV_DUMP. Set up CFG graph dumps. (pass_fini_dump_file): Wrap in TV_DUMP. Finish graph dumps. (execute_one_pass): Don't set up graph dumps here. From-SVN: r194085 --- gcc/ChangeLog | 23 ++++++++++++++++++++++ gcc/gimple-pretty-print.c | 49 +++++++++++++++++++++++++++++++++++++++++------ gcc/gimple-pretty-print.h | 1 + gcc/graph.c | 46 ++++++++++++++++++++++---------------------- gcc/graph.h | 2 +- gcc/passes.c | 44 ++++++++++++++---------------------------- gcc/rtl.h | 1 + gcc/sched-vis.c | 2 +- gcc/tree-pretty-print.c | 6 +----- 9 files changed, 108 insertions(+), 66 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 130524e..3bccfd9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,26 @@ +2012-12-03 Steven Bosscher + + * rtl.h (print_insn_with_notes): Prototype. + * sched-vis.c (print_insn_with_notes): Export it. + + * gimple-pretty-print.h (gimple_dump_bb_for_graph): Prototype. + * gimple-pretty-print.c (print_gimple_expr): Flush the buffer. + (pp_gimple_stmt_1): Don't do it here. + (gimple_dump_bb_for_graph): New function. + * tree-pretty-print.c (print_generic_expr): Flush the buffer here. + (dump_generic_node): Don't flush the buffer here. + + * graph.h (print_rtl_graph_with_bb): Rename to print_graph_cfg. + * graph.c: Include gimple.h, dumpfile.h, and gimple-pretty-print.h. + (draw_cfg_node): Handle GIMPLE basic blocks also. + (print_rtl_graph_with_bb): Rename to print_graph_cfg. + * passes.c (finish_optimization_passes): Don't finish graph dumps here. + (execute_function_dump): Use print_graph_cfg. Enable dumping the CFG + for GIMPLE also. + (pass_init_dump_file): Wrap in TV_DUMP. Set up CFG graph dumps. + (pass_fini_dump_file): Wrap in TV_DUMP. Finish graph dumps. + (execute_one_pass): Don't set up graph dumps here. + 2012-12-03 Eric Botcazou * tree-ssa.c (warn_uninitialized_var): Use OPT_Wmaybe_uninitialized tag diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index a5a493a..a35fefe 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -111,6 +111,7 @@ print_gimple_expr (FILE *file, gimple g, int spc, int flags) flags |= TDF_RHS_ONLY; maybe_init_pretty_print (file); pp_gimple_stmt_1 (&buffer, g, spc, flags); + pp_flush (&buffer); } @@ -2048,12 +2049,6 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags) default: GIMPLE_NIY; } - - /* If we're building a diagnostic, the formatted text will be - written into BUFFER's stream by the caller; otherwise, write it - now. */ - if (!(flags & TDF_DIAGNOSTIC)) - pp_write_text_to_stream (buffer); } @@ -2271,3 +2266,45 @@ 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 + 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_stmt_iterator gsi; + + pp_printf (pp, ":\n", bb->index); + pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true); + + for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple phi = gsi_stmt (gsi); + if (!virtual_operand_p (gimple_phi_result (phi)) + || (dump_flags & TDF_VOPS)) + { + pp_character (pp, '|'); + pp_write_text_to_stream (pp); + pp_string (pp, "# "); + pp_gimple_stmt_1 (pp, phi, 0, dump_flags); + pp_newline (pp); + pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true); + } + } + + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple stmt = gsi_stmt (gsi); + pp_character (pp, '|'); + pp_write_text_to_stream (pp); + pp_gimple_stmt_1 (pp, stmt, 0, dump_flags); + pp_newline (pp); + pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true); + } + dump_implicit_edges (pp, bb, 0, dump_flags); + 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 9b6b559..02d8f13 100644 --- a/gcc/gimple-pretty-print.h +++ b/gcc/gimple-pretty-print.h @@ -32,5 +32,6 @@ extern void print_gimple_seq (FILE *, gimple_seq, int, int); extern void print_gimple_stmt (FILE *, gimple, int, int); 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_for_graph (pretty_printer *, basic_block); #endif /* ! GCC_GIMPLE_PRETTY_PRINT_H */ diff --git a/gcc/graph.c b/gcc/graph.c index a908e60..c0a9af8 100644 --- a/gcc/graph.c +++ b/gcc/graph.c @@ -28,8 +28,11 @@ along with GCC; see the file COPYING3. If not see #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. @@ -82,8 +85,6 @@ init_graph_slim_pretty_print (FILE *fp) static void draw_cfg_node (pretty_printer *pp, int fndecl_uid, basic_block bb) { - rtx insn; - bool first = true; const char *shape; const char *fillcolor; @@ -115,27 +116,26 @@ draw_cfg_node (pretty_printer *pp, int fndecl_uid, basic_block bb) pp_character (pp, '{'); pp_write_text_to_stream (pp); - /* TODO: inter-bb stuff. */ - FOR_BB_INSNS (bb, insn) + /* 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 { - if (! first) + rtx insn; + bool first = true; + + /* TODO: inter-bb stuff. */ + FOR_BB_INSNS (bb, insn) { - pp_character (pp, '|'); - pp_write_text_to_stream (pp); + 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); } - first = false; - - print_insn (pp, insn, 1); - pp_newline (pp); - if (INSN_P (insn) && REG_NOTES (insn)) - for (rtx note = REG_NOTES (insn); note; note = XEXP (note, 1)) - { - pp_printf (pp, " %s: ", - GET_REG_NOTE_NAME (REG_NOTE_KIND (note))); - print_pattern (pp, XEXP (note, 0), 1); - pp_newline (pp); - } - pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true); } pp_character (pp, '}'); } @@ -189,10 +189,10 @@ draw_cfg_node_succ_edges (pretty_printer *pp, int fndecl_uid, basic_block bb) pp_flush (pp); } -/* Print a graphical representation of the CFG of function FUN. - Currently only supports RTL in cfgrtl or cfglayout mode, GIMPLE is TODO. */ +/* Print a graphical representation of the CFG of function FUN. */ + void -print_rtl_graph_with_bb (const char *base, tree fndecl) +print_graph_cfg (const char *base, tree fndecl) { const char *funcname = fndecl_name (fndecl); int fndecl_uid = DECL_UID (fndecl); diff --git a/gcc/graph.h b/gcc/graph.h index 892ebb7..d99c702 100644 --- a/gcc/graph.h +++ b/gcc/graph.h @@ -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_rtl_graph_with_bb (const char *, tree); +extern void print_graph_cfg (const char *, tree); extern void clean_graph_dump_file (const char *); extern void finish_graph_dump_file (const char *); diff --git a/gcc/passes.c b/gcc/passes.c index 2a5ea00..ce487fc 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -223,10 +223,6 @@ rest_of_type_compilation (tree type, int toplev) void finish_optimization_passes (void) { - int i; - struct dump_file_info *dfi; - char *name; - timevar_push (TV_DUMP); if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities) { @@ -234,24 +230,12 @@ finish_optimization_passes (void) end_branch_prob (); dump_finish (pass_profile.pass.static_pass_number); } - if (optimize > 0) { dump_start (pass_profile.pass.static_pass_number, NULL); print_combine_total_stats (); dump_finish (pass_profile.pass.static_pass_number); } - - /* Do whatever is necessary to finish printing the graphs. */ - for (i = TDI_end; (dfi = get_dump_file_info (i)) != NULL; ++i) - if (dump_initialized_p (i) - && (dfi->pflags & TDF_GRAPH) != 0 - && (name = get_dump_file_name (i)) != NULL) - { - finish_graph_dump_file (name); - free (name); - } - timevar_pop (TV_DUMP); } @@ -1785,9 +1769,8 @@ execute_function_dump (void *data ATTRIBUTE_UNUSED) fflush (dump_file); if ((cfun->curr_properties & PROP_cfg) - && (cfun->curr_properties & PROP_rtl) && (dump_flags & TDF_GRAPH)) - print_rtl_graph_with_bb (dump_file_name, cfun->decl); + print_graph_cfg (dump_file_name, cfun->decl); } } @@ -2069,11 +2052,16 @@ pass_init_dump_file (struct opt_pass *pass) /* If a dump file name is present, open it if enabled. */ if (pass->static_pass_number != -1) { + timevar_push (TV_DUMP); bool initializing_dump = !dump_initialized_p (pass->static_pass_number); dump_file_name = get_dump_file_name (pass->static_pass_number); dump_start (pass->static_pass_number, &dump_flags); if (dump_file && current_function_decl) dump_function_header (dump_file, current_function_decl, dump_flags); + if (dump_file && (dump_flags & TDF_GRAPH) + && cfun && (cfun->curr_properties & PROP_cfg)) + clean_graph_dump_file (dump_file_name); + timevar_pop (TV_DUMP); return initializing_dump; } else @@ -2086,14 +2074,21 @@ pass_init_dump_file (struct opt_pass *pass) void pass_fini_dump_file (struct opt_pass *pass) { + timevar_push (TV_DUMP); + /* Flush and close dump file. */ if (dump_file_name) { + gcc_assert (dump_file); + if (dump_flags & TDF_GRAPH + && cfun && (cfun->curr_properties & PROP_cfg)) + finish_graph_dump_file (dump_file_name); free (CONST_CAST (char *, dump_file_name)); dump_file_name = NULL; } dump_finish (pass->static_pass_number); + timevar_pop (TV_DUMP); } /* After executing the pass, apply expected changes to the function @@ -2250,7 +2245,6 @@ override_gate_status (struct opt_pass *pass, tree func, bool gate_status) bool execute_one_pass (struct opt_pass *pass) { - bool initializing_dump; unsigned int todo_after = 0; bool gate_status; @@ -2308,7 +2302,7 @@ execute_one_pass (struct opt_pass *pass) This is a hack until the new folder is ready. */ in_gimple_form = (cfun && (cfun->curr_properties & PROP_trees)) != 0; - initializing_dump = pass_init_dump_file (pass); + pass_init_dump_file (pass); /* Run pre-pass verification. */ execute_todo (pass->todo_flags_start); @@ -2335,16 +2329,6 @@ execute_one_pass (struct opt_pass *pass) do_per_function (update_properties_after_pass, pass); - if (initializing_dump - && dump_file - && (dump_flags & TDF_GRAPH) - && cfun - && (cfun->curr_properties & (PROP_cfg | PROP_rtl)) - == (PROP_cfg | PROP_rtl)) - { - clean_graph_dump_file (dump_file_name); - } - if (profile_report && cfun && (cfun->curr_properties & PROP_cfg)) check_profile_consistency (pass->static_pass_number, 0, true); diff --git a/gcc/rtl.h b/gcc/rtl.h index 0eccaf2..2e5ca71 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -2606,6 +2606,7 @@ extern void dump_rtl_slim (FILE *, const_rtx, const_rtx, int, int); 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 const char *str_pattern_slim (const_rtx); /* In function.c */ diff --git a/gcc/sched-vis.c b/gcc/sched-vis.c index 3e5a74d..90b75f1 100644 --- a/gcc/sched-vis.c +++ b/gcc/sched-vis.c @@ -719,7 +719,7 @@ print_insn (pretty_printer *pp, const_rtx x, int verbose) /* Prerry-print a slim dump of X (an insn) to PP, including any register note attached to the instruction. */ -static void +void print_insn_with_notes (pretty_printer *pp, const_rtx x) { pp_string (pp, print_rtx_head); diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index 755e363..fda7809 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -161,6 +161,7 @@ print_generic_expr (FILE *file, tree t, int flags) { maybe_init_pretty_print (file); dump_generic_node (&buffer, t, 0, flags, false); + pp_flush (&buffer); } /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set @@ -2410,11 +2411,6 @@ dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags, if (is_stmt && is_expr) pp_semicolon (buffer); - /* If we're building a diagnostic, the formatted text will be written - into BUFFER's stream by the caller; otherwise, write it now. */ - if (!(flags & TDF_DIAGNOSTIC)) - pp_write_text_to_stream (buffer); - return spc; } -- 2.7.4