X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;ds=sidebyside;f=gcc%2Fgraph.c;h=d3513fde70b7b3278b0a31014d1074d82dd2a488;hb=f50b88830e71386da5ee62290eaeb204c551f818;hp=fefd175f57fb4c23e0cee1312048f1fa7494a616;hpb=f4ac4e511a6e9e8c96c3e90c9ff3d04ba749a8a5;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/graph.c b/gcc/graph.c index fefd175f57f..d3513fde70b 100644 --- a/gcc/graph.c +++ b/gcc/graph.c @@ -1,52 +1,65 @@ /* Output routines for graphical representation. - Copyright (C) 1998, 1999 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2007, 2008, 2010 + Free Software Foundation, Inc. Contributed by Ulrich Drepper , 1998. - This file is part of GNU CC. +This file is part of GCC. - GNU CC is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. - GNU CC is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. - You should have received a copy of the GNU General Public License - along with GNU CC; see the file COPYING. If not, write to - the Free Software Foundation, 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ -#include +#include "config.h" #include "system.h" - +#include "coretypes.h" +#include "tm.h" #include "rtl.h" #include "flags.h" #include "output.h" +#include "function.h" #include "hard-reg-set.h" +#include "obstack.h" #include "basic-block.h" -#include "toplev.h" +#include "diagnostic-core.h" +#include "graph.h" +#include "emit-rtl.h" -static const char *graph_ext[] = +static const char *const graph_ext[] = { /* no_graph */ "", /* vcg */ ".vcg", }; +/* The flag to indicate if output is inside of a building block. */ +static int inbb = 0; + +static void start_fct (FILE *); +static void start_bb (FILE *, int); +static void node_data (FILE *, rtx); +static void draw_edge (FILE *, int, int, int, int); +static void end_fct (FILE *); +static void end_bb (FILE *); + /* Output text for new basic block. */ static void -start_fct (fp) - FILE *fp; +start_fct (FILE *fp) { - switch (graph_dump_format) { case vcg: fprintf (fp, "\ graph: { title: \"%s\"\nfolding: 1\nhidden: 2\nnode: { title: \"%s.0\" }\n", - current_function_name, current_function_name); + current_function_name (), current_function_name ()); break; case no_graph: break; @@ -54,34 +67,36 @@ graph: { title: \"%s\"\nfolding: 1\nhidden: 2\nnode: { title: \"%s.0\" }\n", } static void -start_bb (fp, bb) - FILE *fp; - int bb; +start_bb (FILE *fp, int bb) { +#if 0 + reg_set_iterator rsi; +#endif + switch (graph_dump_format) { case vcg: fprintf (fp, "\ graph: {\ntitle: \"%s.BB%d\"\nfolding: 1\ncolor: lightblue\n\ label: \"basic block %d", - current_function_name, bb, bb); + current_function_name (), bb, bb); + inbb = 1; /* Now We are inside of a building block. */ break; case no_graph: break; } #if 0 - /* FIXME Should this be printed? It makes the graph significantly larger. */ + /* FIXME Should this be printed? It makes the graph significantly larger. */ /* Print the live-at-start register list. */ fputc ('\n', fp); - EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[bb], 0, i, - { - fprintf (fp, " %d", i); - if (i < FIRST_PSEUDO_REGISTER) - fprintf (fp, " [%s]", - reg_names[i]); - }); + EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[bb], 0, i, rsi) + { + fprintf (fp, " %d", i); + if (i < FIRST_PSEUDO_REGISTER) + fprintf (fp, " [%s]", reg_names[i]); + } #endif switch (graph_dump_format) @@ -94,13 +109,9 @@ label: \"basic block %d", } } -static int -node_data (fp, tmp_rtx) - FILE *fp; - rtx tmp_rtx; +static void +node_data (FILE *fp, rtx tmp_rtx) { - int result; - if (PREV_INSN (tmp_rtx) == 0) { /* This is the first instruction. Add an edge from the starting @@ -110,8 +121,8 @@ node_data (fp, tmp_rtx) case vcg: fprintf (fp, "\ edge: { sourcename: \"%s.0\" targetname: \"%s.%d\" }\n", - current_function_name, - current_function_name, XINT (tmp_rtx, 0)); + current_function_name (), + current_function_name (), XINT (tmp_rtx, 0)); break; case no_graph: break; @@ -123,12 +134,12 @@ edge: { sourcename: \"%s.0\" targetname: \"%s.%d\" }\n", case vcg: fprintf (fp, "node: {\n title: \"%s.%d\"\n color: %s\n \ label: \"%s %d\n", - current_function_name, XINT (tmp_rtx, 0), - GET_CODE (tmp_rtx) == NOTE ? "lightgrey" - : GET_CODE (tmp_rtx) == INSN ? "green" - : GET_CODE (tmp_rtx) == JUMP_INSN ? "darkgreen" - : GET_CODE (tmp_rtx) == CALL_INSN ? "darkgreen" - : GET_CODE (tmp_rtx) == CODE_LABEL ? "\ + current_function_name (), XINT (tmp_rtx, 0), + NOTE_P (tmp_rtx) ? "lightgrey" + : NONJUMP_INSN_P (tmp_rtx) ? "green" + : JUMP_P (tmp_rtx) ? "darkgreen" + : CALL_P (tmp_rtx) ? "darkgreen" + : LABEL_P (tmp_rtx) ? "\ darkgrey\n shape: ellipse" : "white", GET_RTX_NAME (GET_CODE (tmp_rtx)), XINT (tmp_rtx, 0)); break; @@ -137,39 +148,16 @@ darkgrey\n shape: ellipse" : "white", } /* Print the RTL. */ - if (GET_CODE (tmp_rtx) == NOTE) + if (NOTE_P (tmp_rtx)) { - static const char *note_names[] = - { - NULL, - "deleted", - "block_beg", - "block_end", - "loop_beg", - "loop_end", - "function_end", - "setjmp", - "loop_cont", - "loop_vtop", - "prologue_end", - "epilogue_beg", - "deleted_label", - "function_beg", - "eh_region_beg", - "eh_region_end", - "repeated_line_number", - "range_start", - "range_end", - "live" - }; - - fprintf (fp, " %s", - XINT (tmp_rtx, 4) < 0 ? note_names[-XINT (tmp_rtx, 4)] : ""); + const char *name; + name = GET_NOTE_INSN_NAME (NOTE_KIND (tmp_rtx)); + fprintf (fp, " %s", name); } - else if (GET_RTX_CLASS (GET_CODE (tmp_rtx)) == 'i') - result = print_rtl_single (fp, PATTERN (tmp_rtx)); + else if (INSN_P (tmp_rtx)) + print_rtl_single (fp, PATTERN (tmp_rtx)); else - result = print_rtl_single (fp, tmp_rtx); + print_rtl_single (fp, tmp_rtx); switch (graph_dump_format) { @@ -179,28 +167,28 @@ darkgrey\n shape: ellipse" : "white", case no_graph: break; } - - return result; } static void -draw_edge (fp, from, to, bb_edge, class) - FILE *fp; - int from; - int to; - int bb_edge; - int class; +draw_edge (FILE *fp, int from, int to, int bb_edge, int color_class) { + const char * color; switch (graph_dump_format) { case vcg: + color = ""; + if (color_class == 2) + color = "color: red "; + else if (bb_edge) + color = "color: blue "; + else if (color_class == 3) + color = "color: green "; fprintf (fp, "edge: { sourcename: \"%s.%d\" targetname: \"%s.%d\" %s", - current_function_name, from, - current_function_name, to, - bb_edge ? "color: blue " : class ? "color: red " : ""); - if (class) - fprintf (fp, "class: %d ", class); + current_function_name (), from, + current_function_name (), to, color); + if (color_class) + fprintf (fp, "class: %d ", color_class); fputs ("}\n", fp); break; case no_graph: @@ -209,14 +197,17 @@ draw_edge (fp, from, to, bb_edge, class) } static void -end_bb (fp, bb) - FILE *fp; - int bb ATTRIBUTE_UNUSED; +end_bb (FILE *fp) { switch (graph_dump_format) { case vcg: - fputs ("}\n", fp); + /* Check if we are inside of a building block. */ + if (inbb != 0) + { + fputs ("}\n", fp); + inbb = 0; /* Now we are outside of a building block. */ + } break; case no_graph: break; @@ -224,14 +215,13 @@ end_bb (fp, bb) } static void -end_fct (fp) - FILE *fp; +end_fct (FILE *fp) { switch (graph_dump_format) { case vcg: fprintf (fp, "node: { title: \"%s.999999\" label: \"END\" }\n}\n", - current_function_name); + current_function_name ()); break; case no_graph: break; @@ -241,24 +231,19 @@ end_fct (fp) /* Like print_rtl, but also print out live information for the start of each basic block. */ void -print_rtl_graph_with_bb (base, suffix, rtx_first) - const char *base; - const char *suffix; - rtx rtx_first; +print_rtl_graph_with_bb (const char *base, rtx rtx_first) { - register rtx tmp_rtx; + rtx tmp_rtx; size_t namelen = strlen (base); - size_t suffixlen = strlen (suffix); size_t extlen = strlen (graph_ext[graph_dump_format]) + 1; - char *buf = (char *) alloca (namelen + suffixlen + extlen); + char *buf = XALLOCAVEC (char, namelen + extlen); FILE *fp; - /* Regenerate the basic block information. */ - find_basic_blocks (rtx_first, max_reg_num (), NULL); + if (basic_block_info == NULL) + return; memcpy (buf, base, namelen); - memcpy (buf + namelen, suffix, suffixlen); - memcpy (buf + namelen + suffixlen, graph_ext[graph_dump_format], extlen); + memcpy (buf + namelen, graph_ext[graph_dump_format], extlen); fp = fopen (buf, "a"); if (fp == NULL) @@ -268,20 +253,13 @@ print_rtl_graph_with_bb (base, suffix, rtx_first) fprintf (fp, "(nil)\n"); else { - int i, bb; enum bb_state { NOT_IN_BB, IN_ONE_BB, IN_MULTIPLE_BB }; int max_uid = get_max_uid (); - int *start = (int *) alloca (max_uid * sizeof (int)); - int *end = (int *) alloca (max_uid * sizeof (int)); - enum bb_state *in_bb_p = (enum bb_state *) - alloca (max_uid * sizeof (enum bb_state)); - /* Element I is a list of I's predecessors/successors. */ - int_list_ptr *s_preds; - int_list_ptr *s_succs; - /* Element I is the number of predecessors/successors of basic - block I. */ - int *num_preds; - int *num_succs; + int *start = XNEWVEC (int, max_uid); + int *end = XNEWVEC (int, max_uid); + enum bb_state *in_bb_p = XNEWVEC (enum bb_state, max_uid); + basic_block bb; + int i; for (i = 0; i < max_uid; ++i) { @@ -289,31 +267,21 @@ print_rtl_graph_with_bb (base, suffix, rtx_first) in_bb_p[i] = NOT_IN_BB; } - for (i = n_basic_blocks - 1; i >= 0; --i) + FOR_EACH_BB_REVERSE (bb) { rtx x; - start[INSN_UID (BLOCK_HEAD (i))] = i; - end[INSN_UID (BLOCK_END (i))] = i; - for (x = BLOCK_HEAD (i); x != NULL_RTX; x = NEXT_INSN (x)) + start[INSN_UID (BB_HEAD (bb))] = bb->index; + end[INSN_UID (BB_END (bb))] = bb->index; + for (x = BB_HEAD (bb); x != NULL_RTX; x = NEXT_INSN (x)) { in_bb_p[INSN_UID (x)] = (in_bb_p[INSN_UID (x)] == NOT_IN_BB) ? IN_ONE_BB : IN_MULTIPLE_BB; - if (x == BLOCK_END (i)) + if (x == BB_END (bb)) break; } } - /* Get the information about the basic blocks predecessors and - successors. */ - s_preds = (int_list_ptr *) alloca (n_basic_blocks - * sizeof (int_list_ptr)); - s_succs = (int_list_ptr *) alloca (n_basic_blocks - * sizeof (int_list_ptr)); - num_preds = (int *) alloca (n_basic_blocks * sizeof (int)); - num_succs = (int *) alloca (n_basic_blocks * sizeof (int)); - compute_preds_succs (s_preds, s_succs, num_preds, num_succs); - /* Tell print-rtl that we want graph output. */ dump_for_graph = 1; @@ -323,66 +291,66 @@ print_rtl_graph_with_bb (base, suffix, rtx_first) for (tmp_rtx = NEXT_INSN (rtx_first); NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx)) { - int did_output; int edge_printed = 0; rtx next_insn; if (start[INSN_UID (tmp_rtx)] < 0 && end[INSN_UID (tmp_rtx)] < 0) { - if (GET_CODE (tmp_rtx) == BARRIER) + if (BARRIER_P (tmp_rtx)) continue; - if (GET_CODE (tmp_rtx) == NOTE + if (NOTE_P (tmp_rtx) && (1 || in_bb_p[INSN_UID (tmp_rtx)] == NOT_IN_BB)) continue; } - if ((bb = start[INSN_UID (tmp_rtx)]) >= 0) + if ((i = start[INSN_UID (tmp_rtx)]) >= 0) { /* We start a subgraph for each basic block. */ - start_bb (fp, bb); + start_bb (fp, i); - if (bb == 0) + if (i == 0) draw_edge (fp, 0, INSN_UID (tmp_rtx), 1, 0); } /* Print the data for this node. */ - did_output = node_data (fp, tmp_rtx); + node_data (fp, tmp_rtx); next_insn = next_nonnote_insn (tmp_rtx); - if ((bb = end[INSN_UID (tmp_rtx)]) >= 0) + if ((i = end[INSN_UID (tmp_rtx)]) >= 0) { - int_list_ptr p; + edge e; + edge_iterator ei; + + bb = BASIC_BLOCK (i); /* End of the basic block. */ - end_bb (fp, bb); + end_bb (fp); /* Now specify the edges to all the successors of this basic block. */ - for (p = s_succs[bb]; p != NULL; p = p->next) + FOR_EACH_EDGE (e, ei, bb->succs) { - int bb_succ = INT_LIST_VAL (p); - - if (bb_succ >= 0) + if (e->dest != EXIT_BLOCK_PTR) { - rtx block_head = BLOCK_HEAD (bb_succ); + rtx block_head = BB_HEAD (e->dest); draw_edge (fp, INSN_UID (tmp_rtx), INSN_UID (block_head), - next_insn != block_head, 0); + next_insn != block_head, + (e->flags & EDGE_ABNORMAL ? 2 : 0)); - if (BLOCK_HEAD (bb_succ) == next_insn) + if (block_head == next_insn) edge_printed = 1; } - else if (bb_succ == EXIT_BLOCK) + else { draw_edge (fp, INSN_UID (tmp_rtx), 999999, - next_insn != 0, 0); + next_insn != 0, + (e->flags & EDGE_ABNORMAL ? 2 : 0)); if (next_insn == 0) edge_printed = 1; } - else - abort (); } } @@ -390,22 +358,22 @@ print_rtl_graph_with_bb (base, suffix, rtx_first) { /* Don't print edges to barriers. */ if (next_insn == 0 - || GET_CODE (next_insn) != BARRIER) + || !BARRIER_P (next_insn)) draw_edge (fp, XINT (tmp_rtx, 0), next_insn ? INSN_UID (next_insn) : 999999, 0, 0); else { - /* We draw the remaining edges in class 2. We have - to skip oevr the barrier since these nodes are + /* We draw the remaining edges in class 3. We have + to skip over the barrier since these nodes are not printed at all. */ do next_insn = NEXT_INSN (next_insn); while (next_insn - && (GET_CODE (next_insn) == NOTE - || GET_CODE (next_insn) == BARRIER)); + && (NOTE_P (next_insn) + || BARRIER_P (next_insn))); draw_edge (fp, XINT (tmp_rtx, 0), - next_insn ? INSN_UID (next_insn) : 999999, 0, 2); + next_insn ? INSN_UID (next_insn) : 999999, 0, 3); } } } @@ -413,6 +381,11 @@ print_rtl_graph_with_bb (base, suffix, rtx_first) dump_for_graph = 0; end_fct (fp); + + /* Clean up. */ + free (start); + free (end); + free (in_bb_p); } fclose (fp); @@ -420,34 +393,25 @@ print_rtl_graph_with_bb (base, suffix, rtx_first) /* Similar as clean_dump_file, but this time for graph output files. */ + void -clean_graph_dump_file (base, suffix) - const char *base; - const char *suffix; +clean_graph_dump_file (const char *base) { size_t namelen = strlen (base); - size_t suffixlen = strlen (suffix); size_t extlen = strlen (graph_ext[graph_dump_format]) + 1; - char *buf = (char *) alloca (namelen + extlen + suffixlen); + char *buf = XALLOCAVEC (char, namelen + extlen); FILE *fp; memcpy (buf, base, namelen); - memcpy (buf + namelen, suffix, suffixlen); - memcpy (buf + namelen + suffixlen, graph_ext[graph_dump_format], extlen); + memcpy (buf + namelen, graph_ext[graph_dump_format], extlen); fp = fopen (buf, "w"); if (fp == NULL) - pfatal_with_name (buf); + fatal_error ("can%'t open %s: %m", buf); - switch (graph_dump_format) - { - case vcg: - fputs ("graph: {\nport_sharing: no\n", fp); - break; - case no_graph: - abort (); - } + gcc_assert (graph_dump_format == vcg); + fputs ("graph: {\nport_sharing: no\n", fp); fclose (fp); } @@ -455,32 +419,21 @@ clean_graph_dump_file (base, suffix) /* Do final work on the graph output file. */ void -finish_graph_dump_file (base, suffix) - const char *base; - const char *suffix; +finish_graph_dump_file (const char *base) { size_t namelen = strlen (base); - size_t suffixlen = strlen (suffix); size_t extlen = strlen (graph_ext[graph_dump_format]) + 1; - char *buf = (char *) alloca (namelen + suffixlen + extlen); + char *buf = XALLOCAVEC (char, namelen + extlen); FILE *fp; memcpy (buf, base, namelen); - memcpy (buf + namelen, suffix, suffixlen); - memcpy (buf + namelen + suffixlen, graph_ext[graph_dump_format], extlen); + memcpy (buf + namelen, graph_ext[graph_dump_format], extlen); fp = fopen (buf, "a"); if (fp != NULL) { - switch (graph_dump_format) - { - case vcg: - fputs ("}\n", fp); - break; - case no_graph: - abort (); - } - + gcc_assert (graph_dump_format == vcg); + fputs ("}\n", fp); fclose (fp); } }