/* Output routines for graphical representation.
- Copyright (C) 1998-2012
- Free Software Foundation, Inc.
+ Copyright (C) 1998-2014 Free Software Foundation, Inc.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
Rewritten for DOT output by Steven Bosscher, 2012.
#include "coretypes.h"
#include "diagnostic-core.h" /* for fatal_error */
#include "sbitmap.h"
+#include "predict.h"
+#include "vec.h"
+#include "hashtab.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "tm.h"
+#include "hard-reg-set.h"
+#include "input.h"
+#include "function.h"
+#include "dominance.h"
+#include "cfg.h"
+#include "cfganal.h"
#include "basic-block.h"
#include "cfgloop.h"
#include "graph.h"
return fp;
}
-/* Return a pretty-print buffer for output to file FP. */
-
-static pretty_printer *
-init_graph_slim_pretty_print (FILE *fp)
-{
- static bool initialized = false;
- static pretty_printer graph_slim_pp;
-
- if (! initialized)
- {
- pp_construct (&graph_slim_pp, /*prefix=*/NULL, /*linewidth=*/0);
- initialized = true;
- }
- else
- gcc_assert (! pp_last_position_in_text (&graph_slim_pp));
-
- graph_slim_pp.buffer->stream = fp;
- return &graph_slim_pp;
-}
-
/* Draw a basic block BB belonging to the function with FUNCDEF_NO
as its unique number. */
static void
pp_string (pp, "EXIT");
else
{
- pp_character (pp, '{');
+ pp_left_brace (pp);
pp_write_text_to_stream (pp);
dump_bb_for_graph (pp, bb);
- pp_character (pp, '}');
+ pp_right_brace (pp);
}
pp_string (pp, "\"];\n\n");
pp_printf (pp,
"\tfn_%d_basic_block_%d:s -> fn_%d_basic_block_%d:n "
- "[style=%s,color=%s,weight=%d,constraint=%s];\n",
+ "[style=%s,color=%s,weight=%d,constraint=%s, label=\"[%i%%]\"];\n",
funcdef_no, e->src->index,
funcdef_no, e->dest->index,
style, color, weight,
- (e->flags & (EDGE_FAKE | EDGE_DFS_BACK)) ? "false" : "true");
+ (e->flags & (EDGE_FAKE | EDGE_DFS_BACK)) ? "false" : "true",
+ e->probability * 100 / REG_BR_PROB_BASE);
}
pp_flush (pp);
}
static void
draw_cfg_nodes_no_loops (pretty_printer *pp, struct function *fun)
{
- int *rpo = XNEWVEC (int, n_basic_blocks_for_function (fun));
+ int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (fun));
int i, n;
sbitmap visited;
- visited = sbitmap_alloc (last_basic_block);
+ visited = sbitmap_alloc (last_basic_block_for_fn (cfun));
bitmap_clear (visited);
- /* FIXME: pre_and_rev_post_order_compute only works if fun == cfun. */
- n = pre_and_rev_post_order_compute (NULL, rpo, true);
- for (i = 0; i < n; i++)
+ n = pre_and_rev_post_order_compute_fn (fun, NULL, rpo, true);
+ for (i = n_basic_blocks_for_fn (fun) - n;
+ i < n_basic_blocks_for_fn (fun); i++)
{
- basic_block bb = BASIC_BLOCK (rpo[i]);
+ basic_block bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
draw_cfg_node (pp, fun->funcdef_no, bb);
bitmap_set_bit (visited, bb->index);
}
free (rpo);
- if (n != n_basic_blocks_for_function (fun))
+ if (n != n_basic_blocks_for_fn (fun))
{
/* Some blocks are unreachable. We still want to dump them. */
basic_block bb;
unsigned int i;
const char *fillcolors[3] = { "grey88", "grey77", "grey66" };
- if (loop->latch != EXIT_BLOCK_PTR)
+ if (loop->header != NULL
+ && loop->latch != EXIT_BLOCK_PTR_FOR_FN (cfun))
pp_printf (pp,
"\tsubgraph cluster_%d_%d {\n"
"\tstyle=\"filled\";\n"
for (struct loop *inner = loop->inner; inner; inner = inner->next)
draw_cfg_nodes_for_loop (pp, funcdef_no, inner);
- if (loop->latch == EXIT_BLOCK_PTR)
+ if (loop->header == NULL)
+ return;
+
+ if (loop->latch == EXIT_BLOCK_PTR_FOR_FN (cfun))
body = get_loop_body (loop);
else
body = get_loop_body_in_bfs_order (loop);
free (body);
- if (loop->latch != EXIT_BLOCK_PTR)
+ if (loop->latch != EXIT_BLOCK_PTR_FOR_FN (cfun))
pp_printf (pp, "\t}\n");
}
static void
draw_cfg_nodes (pretty_printer *pp, struct function *fun)
{
- /* ??? This x_current_loops should be enapsulated. */
- if (fun->x_current_loops)
- draw_cfg_nodes_for_loop (pp, fun->funcdef_no,
- fun->x_current_loops->tree_root);
+ if (loops_for_fn (fun))
+ draw_cfg_nodes_for_loop (pp, fun->funcdef_no, get_loop (fun, 0));
else
draw_cfg_nodes_no_loops (pp, fun);
}
{
basic_block bb;
mark_dfs_back_edges ();
- FOR_ALL_BB (bb)
+ FOR_ALL_BB_FN (bb, cfun)
draw_cfg_node_succ_edges (pp, fun->funcdef_no, bb);
/* Add an invisible edge from ENTRY to EXIT, to improve the graph layout. */
{
const char *funcname = function_name (fun);
FILE *fp = open_graph_file (base, "a");
- pretty_printer *pp = init_graph_slim_pretty_print (fp);
+ pretty_printer graph_slim_pp;
+ graph_slim_pp.buffer->stream = fp;
+ pretty_printer *const pp = &graph_slim_pp;
pp_printf (pp, "subgraph \"%s\" {\n"
"\tcolor=\"black\";\n"
"\tlabel=\"%s\";\n",
/* Start the dump of a graph. */
static void
-start_graph_dump (FILE *fp)
+start_graph_dump (FILE *fp, const char *base)
{
- fputs ("digraph \"\" {\n"
- "overlap=false;\n",
- fp);
+ pretty_printer graph_slim_pp;
+ graph_slim_pp.buffer->stream = fp;
+ pretty_printer *const pp = &graph_slim_pp;
+ pp_string (pp, "digraph \"");
+ pp_write_text_to_stream (pp);
+ pp_string (pp, base);
+ pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/false);
+ pp_string (pp, "\" {\n");
+ pp_string (pp, "overlap=false;\n");
+ pp_flush (pp);
}
/* End the dump of a graph. */
clean_graph_dump_file (const char *base)
{
FILE *fp = open_graph_file (base, "w");
- start_graph_dump (fp);
+ start_graph_dump (fp, base);
fclose (fp);
}