1 /* Output routines for graphical representation.
2 Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 #include "hard-reg-set.h"
30 #include "basic-block.h"
34 static const char *const graph_ext
[] =
40 static void start_fct
PARAMS ((FILE *));
41 static void start_bb
PARAMS ((FILE *, int));
42 static void node_data
PARAMS ((FILE *, rtx
));
43 static void draw_edge
PARAMS ((FILE *, int, int, int, int));
44 static void end_fct
PARAMS ((FILE *));
45 static void end_bb
PARAMS ((FILE *));
47 /* Output text for new basic block. */
53 switch (graph_dump_format
)
57 graph: { title: \"%s\"\nfolding: 1\nhidden: 2\nnode: { title: \"%s.0\" }\n",
58 current_function_name
, current_function_name
);
70 switch (graph_dump_format
)
74 graph: {\ntitle: \"%s.BB%d\"\nfolding: 1\ncolor: lightblue\n\
75 label: \"basic block %d",
76 current_function_name
, bb
, bb
);
83 /* FIXME Should this be printed? It makes the graph significantly larger. */
85 /* Print the live-at-start register list. */
87 EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start
[bb
], 0, i
,
89 fprintf (fp
, " %d", i
);
90 if (i
< FIRST_PSEUDO_REGISTER
)
96 switch (graph_dump_format
)
107 node_data (fp
, tmp_rtx
)
112 if (PREV_INSN (tmp_rtx
) == 0)
114 /* This is the first instruction. Add an edge from the starting
116 switch (graph_dump_format
)
120 edge: { sourcename: \"%s.0\" targetname: \"%s.%d\" }\n",
121 current_function_name
,
122 current_function_name
, XINT (tmp_rtx
, 0));
129 switch (graph_dump_format
)
132 fprintf (fp
, "node: {\n title: \"%s.%d\"\n color: %s\n \
134 current_function_name
, XINT (tmp_rtx
, 0),
135 GET_CODE (tmp_rtx
) == NOTE
? "lightgrey"
136 : GET_CODE (tmp_rtx
) == INSN
? "green"
137 : GET_CODE (tmp_rtx
) == JUMP_INSN
? "darkgreen"
138 : GET_CODE (tmp_rtx
) == CALL_INSN
? "darkgreen"
139 : GET_CODE (tmp_rtx
) == CODE_LABEL
? "\
140 darkgrey\n shape: ellipse" : "white",
141 GET_RTX_NAME (GET_CODE (tmp_rtx
)), XINT (tmp_rtx
, 0));
148 if (GET_CODE (tmp_rtx
) == NOTE
)
150 const char *name
= "";
151 if (NOTE_LINE_NUMBER (tmp_rtx
) < 0)
152 name
= GET_NOTE_INSN_NAME (NOTE_LINE_NUMBER (tmp_rtx
));
153 fprintf (fp
, " %s", name
);
155 else if (INSN_P (tmp_rtx
))
156 print_rtl_single (fp
, PATTERN (tmp_rtx
));
158 print_rtl_single (fp
, tmp_rtx
);
160 switch (graph_dump_format
)
163 fputs ("\"\n}\n", fp
);
171 draw_edge (fp
, from
, to
, bb_edge
, class)
179 switch (graph_dump_format
)
184 color
= "color: red ";
186 color
= "color: blue ";
188 color
= "color: green ";
190 "edge: { sourcename: \"%s.%d\" targetname: \"%s.%d\" %s",
191 current_function_name
, from
,
192 current_function_name
, to
, color
);
194 fprintf (fp
, "class: %d ", class);
206 switch (graph_dump_format
)
220 switch (graph_dump_format
)
223 fprintf (fp
, "node: { title: \"%s.999999\" label: \"END\" }\n}\n",
224 current_function_name
);
231 /* Like print_rtl, but also print out live information for the start of each
234 print_rtl_graph_with_bb (base
, suffix
, rtx_first
)
240 size_t namelen
= strlen (base
);
241 size_t suffixlen
= strlen (suffix
);
242 size_t extlen
= strlen (graph_ext
[graph_dump_format
]) + 1;
243 char *buf
= (char *) alloca (namelen
+ suffixlen
+ extlen
);
246 if (basic_block_info
== NULL
)
249 memcpy (buf
, base
, namelen
);
250 memcpy (buf
+ namelen
, suffix
, suffixlen
);
251 memcpy (buf
+ namelen
+ suffixlen
, graph_ext
[graph_dump_format
], extlen
);
253 fp
= fopen (buf
, "a");
258 fprintf (fp
, "(nil)\n");
261 enum bb_state
{ NOT_IN_BB
, IN_ONE_BB
, IN_MULTIPLE_BB
};
262 int max_uid
= get_max_uid ();
263 int *start
= (int *) xmalloc (max_uid
* sizeof (int));
264 int *end
= (int *) xmalloc (max_uid
* sizeof (int));
265 enum bb_state
*in_bb_p
= (enum bb_state
*)
266 xmalloc (max_uid
* sizeof (enum bb_state
));
270 for (j
= 0; j
< max_uid
; ++j
)
272 start
[j
] = end
[j
] = -1;
273 in_bb_p
[j
] = NOT_IN_BB
;
276 FOR_ALL_BB_REVERSE (bb
)
279 start
[INSN_UID (bb
->head
)] = bb
->sindex
;
280 end
[INSN_UID (bb
->end
)] = bb
->sindex
;
281 for (x
= bb
->head
; x
!= NULL_RTX
; x
= NEXT_INSN (x
))
283 in_bb_p
[INSN_UID (x
)]
284 = (in_bb_p
[INSN_UID (x
)] == NOT_IN_BB
)
285 ? IN_ONE_BB
: IN_MULTIPLE_BB
;
291 /* Tell print-rtl that we want graph output. */
294 /* Start new function. */
297 for (tmp_rtx
= NEXT_INSN (rtx_first
); NULL
!= tmp_rtx
;
298 tmp_rtx
= NEXT_INSN (tmp_rtx
))
300 int edge_printed
= 0;
303 if (start
[INSN_UID (tmp_rtx
)] < 0 && end
[INSN_UID (tmp_rtx
)] < 0)
305 if (GET_CODE (tmp_rtx
) == BARRIER
)
307 if (GET_CODE (tmp_rtx
) == NOTE
308 && (1 || in_bb_p
[INSN_UID (tmp_rtx
)] == NOT_IN_BB
))
312 if ((j
= start
[INSN_UID (tmp_rtx
)]) >= 0)
314 /* We start a subgraph for each basic block. */
318 draw_edge (fp
, 0, INSN_UID (tmp_rtx
), 1, 0);
321 /* Print the data for this node. */
322 node_data (fp
, tmp_rtx
);
323 next_insn
= next_nonnote_insn (tmp_rtx
);
325 if ((j
= end
[INSN_UID (tmp_rtx
)]) >= 0)
329 bb
= BASIC_BLOCK (j
);
331 /* End of the basic block. */
334 /* Now specify the edges to all the successors of this
336 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
338 if (e
->dest
!= EXIT_BLOCK_PTR
)
340 rtx block_head
= e
->dest
->head
;
342 draw_edge (fp
, INSN_UID (tmp_rtx
),
343 INSN_UID (block_head
),
344 next_insn
!= block_head
,
345 (e
->flags
& EDGE_ABNORMAL
? 2 : 0));
347 if (block_head
== next_insn
)
352 draw_edge (fp
, INSN_UID (tmp_rtx
), 999999,
354 (e
->flags
& EDGE_ABNORMAL
? 2 : 0));
364 /* Don't print edges to barriers. */
366 || GET_CODE (next_insn
) != BARRIER
)
367 draw_edge (fp
, XINT (tmp_rtx
, 0),
368 next_insn
? INSN_UID (next_insn
) : 999999, 0, 0);
371 /* We draw the remaining edges in class 3. We have
372 to skip over the barrier since these nodes are
373 not printed at all. */
375 next_insn
= NEXT_INSN (next_insn
);
377 && (GET_CODE (next_insn
) == NOTE
378 || GET_CODE (next_insn
) == BARRIER
));
380 draw_edge (fp
, XINT (tmp_rtx
, 0),
381 next_insn
? INSN_UID (next_insn
) : 999999, 0, 3);
400 /* Similar as clean_dump_file, but this time for graph output files. */
403 clean_graph_dump_file (base
, suffix
)
407 size_t namelen
= strlen (base
);
408 size_t suffixlen
= strlen (suffix
);
409 size_t extlen
= strlen (graph_ext
[graph_dump_format
]) + 1;
410 char *buf
= (char *) alloca (namelen
+ extlen
+ suffixlen
);
413 memcpy (buf
, base
, namelen
);
414 memcpy (buf
+ namelen
, suffix
, suffixlen
);
415 memcpy (buf
+ namelen
+ suffixlen
, graph_ext
[graph_dump_format
], extlen
);
417 fp
= fopen (buf
, "w");
420 fatal_io_error ("can't open %s", buf
);
422 switch (graph_dump_format
)
425 fputs ("graph: {\nport_sharing: no\n", fp
);
435 /* Do final work on the graph output file. */
437 finish_graph_dump_file (base
, suffix
)
441 size_t namelen
= strlen (base
);
442 size_t suffixlen
= strlen (suffix
);
443 size_t extlen
= strlen (graph_ext
[graph_dump_format
]) + 1;
444 char *buf
= (char *) alloca (namelen
+ suffixlen
+ extlen
);
447 memcpy (buf
, base
, namelen
);
448 memcpy (buf
+ namelen
, suffix
, suffixlen
);
449 memcpy (buf
+ namelen
+ suffixlen
, graph_ext
[graph_dump_format
], extlen
);
451 fp
= fopen (buf
, "a");
454 switch (graph_dump_format
)