Index: gcc/tree-cfg.c =================================================================== --- gcc/tree-cfg.c (revision 193816) +++ gcc/tree-cfg.c (working copy) @@ -2150,6 +2154,87 @@ debug_cfg_stats (void) dump_cfg_stats (stderr); } +void +gimple_cfg2dot (const char *fname); +void +gimple_cfg2dot (const char *fname) +{ + FILE *file = fopen (fname, "w"); + basic_block bb; + pretty_printer buffer; + + pp_construct (&buffer, NULL, 0); + pp_needs_newline (&buffer) = false; + buffer.buffer->stream = file; + + fprintf (file, "digraph cfg {\n"); + + FOR_EACH_BB (bb) + { + edge_iterator ei; + edge e; + gimple_stmt_iterator gsi; + fprintf (file, "\"BB%d\"", bb->index); + fprintf (file, " [shape=box,label=\"BB%d", bb->index); + if (current_loops + && bb->loop_father) + { + fprintf (file, " loop %d", bb->loop_father->num); + if (bb->loop_father->latch == bb) + fprintf (file, " (latch)"); + if (bb->loop_father->header == bb) + fprintf (file, " (header)"); + } + fprintf (file, "\\l"); + if (!(bb->flags & BB_RTL)) + { + for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + if (!is_gimple_reg (gimple_phi_result (gsi_stmt (gsi)))) + continue; + pp_gimple_stmt_1 (&buffer, gsi_stmt (gsi), 0, TDF_SLIM); + pp_write_text_to_stream (&buffer); + fprintf (file, "\\l"); + } + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + pp_gimple_stmt_1 (&buffer, gsi_stmt (gsi), 0, TDF_SLIM); + pp_write_text_to_stream (&buffer); + fprintf (file, "\\l"); + } + } + fprintf (file, "\"]"); +#if 0 + gsi = gsi_last_bb (bb); + if (!gsi_end_p (gsi) && gimple_code (gsi_stmt (gsi)) == GIMPLE_COND) + { + fprintf (file, " [shape=box,label=\"BB%d\\l", bb->index); + dump_gimple_stmt (&buffer, gsi_stmt (gsi), 0, TDF_SLIM); + pp_write_text_to_stream (&buffer); + fprintf (file, "\"]"); + } +#endif + fprintf (file, ";\n"); + FOR_EACH_EDGE (e, ei, bb->succs) + { + fprintf (file, "\"BB%d\" -> \"BB%d\"", bb->index, e->dest->index); + if (e->flags & EDGE_EH) + fprintf (file, " [style=dashed,label=\"eh\"]"); + if (e->flags & EDGE_FAKE) + fprintf (file, " [style=dotted]"); + if (e->flags & EDGE_ABNORMAL) + fprintf (file, " [style=dashed,label=\"ab\"]"); + if (e->flags & EDGE_TRUE_VALUE) + fprintf (file, " [color=green,label=\"t\"]"); + else if (e->flags & EDGE_FALSE_VALUE) + fprintf (file, " [color=red,label=\"f\"]"); + fprintf (file, ";\n"); + } + } + + fprintf (file, "}\n"); + fclose (file); +} /* Dump the flowgraph to a .vcg FILE. */