OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [graph.c] - Blame information for rev 847

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* Output routines for graphical representation.
2
   Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2007
3
   Free Software Foundation, Inc.
4
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5
 
6
This file is part of GCC.
7
 
8
GCC is free software; you can redistribute it and/or modify it under
9
the terms of the GNU General Public License as published by the Free
10
Software Foundation; either version 3, or (at your option) any later
11
version.
12
 
13
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14
WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16
for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with GCC; see the file COPYING3.  If not see
20
<http://www.gnu.org/licenses/>.  */
21
 
22
#include <config.h>
23
#include "system.h"
24
#include "coretypes.h"
25
#include "tm.h"
26
#include "rtl.h"
27
#include "flags.h"
28
#include "output.h"
29
#include "function.h"
30
#include "hard-reg-set.h"
31
#include "obstack.h"
32
#include "basic-block.h"
33
#include "toplev.h"
34
#include "graph.h"
35
 
36
static const char *const graph_ext[] =
37
{
38
  /* no_graph */ "",
39
  /* vcg */      ".vcg",
40
};
41
 
42
static void start_fct (FILE *);
43
static void start_bb (FILE *, int);
44
static void node_data (FILE *, rtx);
45
static void draw_edge (FILE *, int, int, int, int);
46
static void end_fct (FILE *);
47
static void end_bb (FILE *);
48
 
49
/* Output text for new basic block.  */
50
static void
51
start_fct (FILE *fp)
52
{
53
  switch (graph_dump_format)
54
    {
55
    case vcg:
56
      fprintf (fp, "\
57
graph: { title: \"%s\"\nfolding: 1\nhidden: 2\nnode: { title: \"%s.0\" }\n",
58
               current_function_name (), current_function_name ());
59
      break;
60
    case no_graph:
61
      break;
62
    }
63
}
64
 
65
static void
66
start_bb (FILE *fp, int bb)
67
{
68
#if 0
69
  reg_set_iterator rsi;
70
#endif
71
 
72
  switch (graph_dump_format)
73
    {
74
    case vcg:
75
      fprintf (fp, "\
76
graph: {\ntitle: \"%s.BB%d\"\nfolding: 1\ncolor: lightblue\n\
77
label: \"basic block %d",
78
               current_function_name (), bb, bb);
79
      break;
80
    case no_graph:
81
      break;
82
    }
83
 
84
#if 0
85
  /* FIXME Should this be printed?  It makes the graph significantly larger.  */
86
 
87
  /* Print the live-at-start register list.  */
88
  fputc ('\n', fp);
89
  EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[bb], 0, i, rsi)
90
    {
91
      fprintf (fp, " %d", i);
92
      if (i < FIRST_PSEUDO_REGISTER)
93
        fprintf (fp, " [%s]", reg_names[i]);
94
    }
95
#endif
96
 
97
  switch (graph_dump_format)
98
    {
99
    case vcg:
100
      fputs ("\"\n\n", fp);
101
      break;
102
    case no_graph:
103
      break;
104
    }
105
}
106
 
107
static void
108
node_data (FILE *fp, rtx tmp_rtx)
109
{
110
  if (PREV_INSN (tmp_rtx) == 0)
111
    {
112
      /* This is the first instruction.  Add an edge from the starting
113
         block.  */
114
      switch (graph_dump_format)
115
        {
116
        case vcg:
117
          fprintf (fp, "\
118
edge: { sourcename: \"%s.0\" targetname: \"%s.%d\" }\n",
119
                   current_function_name (),
120
                   current_function_name (), XINT (tmp_rtx, 0));
121
          break;
122
        case no_graph:
123
          break;
124
        }
125
    }
126
 
127
  switch (graph_dump_format)
128
    {
129
    case vcg:
130
      fprintf (fp, "node: {\n  title: \"%s.%d\"\n  color: %s\n  \
131
label: \"%s %d\n",
132
               current_function_name (), XINT (tmp_rtx, 0),
133
               NOTE_P (tmp_rtx) ? "lightgrey"
134
               : NONJUMP_INSN_P (tmp_rtx) ? "green"
135
               : JUMP_P (tmp_rtx) ? "darkgreen"
136
               : CALL_P (tmp_rtx) ? "darkgreen"
137
               : LABEL_P (tmp_rtx) ?  "\
138
darkgrey\n  shape: ellipse" : "white",
139
               GET_RTX_NAME (GET_CODE (tmp_rtx)), XINT (tmp_rtx, 0));
140
      break;
141
    case no_graph:
142
      break;
143
    }
144
 
145
  /* Print the RTL.  */
146
  if (NOTE_P (tmp_rtx))
147
    {
148
      const char *name = "";
149
      if (NOTE_LINE_NUMBER (tmp_rtx) < 0)
150
        name =  GET_NOTE_INSN_NAME (NOTE_LINE_NUMBER (tmp_rtx));
151
      fprintf (fp, " %s", name);
152
    }
153
  else if (INSN_P (tmp_rtx))
154
    print_rtl_single (fp, PATTERN (tmp_rtx));
155
  else
156
    print_rtl_single (fp, tmp_rtx);
157
 
158
  switch (graph_dump_format)
159
    {
160
    case vcg:
161
      fputs ("\"\n}\n", fp);
162
      break;
163
    case no_graph:
164
      break;
165
    }
166
}
167
 
168
static void
169
draw_edge (FILE *fp, int from, int to, int bb_edge, int class)
170
{
171
  const char * color;
172
  switch (graph_dump_format)
173
    {
174
    case vcg:
175
      color = "";
176
      if (class == 2)
177
        color = "color: red ";
178
      else if (bb_edge)
179
        color = "color: blue ";
180
      else if (class == 3)
181
        color = "color: green ";
182
      fprintf (fp,
183
               "edge: { sourcename: \"%s.%d\" targetname: \"%s.%d\" %s",
184
               current_function_name (), from,
185
               current_function_name (), to, color);
186
      if (class)
187
        fprintf (fp, "class: %d ", class);
188
      fputs ("}\n", fp);
189
      break;
190
    case no_graph:
191
      break;
192
    }
193
}
194
 
195
static void
196
end_bb (FILE *fp)
197
{
198
  switch (graph_dump_format)
199
    {
200
    case vcg:
201
      fputs ("}\n", fp);
202
      break;
203
    case no_graph:
204
      break;
205
    }
206
}
207
 
208
static void
209
end_fct (FILE *fp)
210
{
211
  switch (graph_dump_format)
212
    {
213
    case vcg:
214
      fprintf (fp, "node: { title: \"%s.999999\" label: \"END\" }\n}\n",
215
               current_function_name ());
216
      break;
217
    case no_graph:
218
      break;
219
    }
220
}
221
 
222
/* Like print_rtl, but also print out live information for the start of each
223
   basic block.  */
224
void
225
print_rtl_graph_with_bb (const char *base, rtx rtx_first)
226
{
227
  rtx tmp_rtx;
228
  size_t namelen = strlen (base);
229
  size_t extlen = strlen (graph_ext[graph_dump_format]) + 1;
230
  char *buf = alloca (namelen + extlen);
231
  FILE *fp;
232
 
233
  if (basic_block_info == NULL)
234
    return;
235
 
236
  memcpy (buf, base, namelen);
237
  memcpy (buf + namelen, graph_ext[graph_dump_format], extlen);
238
 
239
  fp = fopen (buf, "a");
240
  if (fp == NULL)
241
    return;
242
 
243
  if (rtx_first == 0)
244
    fprintf (fp, "(nil)\n");
245
  else
246
    {
247
      enum bb_state { NOT_IN_BB, IN_ONE_BB, IN_MULTIPLE_BB };
248
      int max_uid = get_max_uid ();
249
      int *start = XNEWVEC (int, max_uid);
250
      int *end = XNEWVEC (int, max_uid);
251
      enum bb_state *in_bb_p = XNEWVEC (enum bb_state, max_uid);
252
      basic_block bb;
253
      int i;
254
 
255
      for (i = 0; i < max_uid; ++i)
256
        {
257
          start[i] = end[i] = -1;
258
          in_bb_p[i] = NOT_IN_BB;
259
        }
260
 
261
      FOR_EACH_BB_REVERSE (bb)
262
        {
263
          rtx x;
264
          start[INSN_UID (BB_HEAD (bb))] = bb->index;
265
          end[INSN_UID (BB_END (bb))] = bb->index;
266
          for (x = BB_HEAD (bb); x != NULL_RTX; x = NEXT_INSN (x))
267
            {
268
              in_bb_p[INSN_UID (x)]
269
                = (in_bb_p[INSN_UID (x)] == NOT_IN_BB)
270
                 ? IN_ONE_BB : IN_MULTIPLE_BB;
271
              if (x == BB_END (bb))
272
                break;
273
            }
274
        }
275
 
276
      /* Tell print-rtl that we want graph output.  */
277
      dump_for_graph = 1;
278
 
279
      /* Start new function.  */
280
      start_fct (fp);
281
 
282
      for (tmp_rtx = NEXT_INSN (rtx_first); NULL != tmp_rtx;
283
           tmp_rtx = NEXT_INSN (tmp_rtx))
284
        {
285
          int edge_printed = 0;
286
          rtx next_insn;
287
 
288
          if (start[INSN_UID (tmp_rtx)] < 0 && end[INSN_UID (tmp_rtx)] < 0)
289
            {
290
              if (BARRIER_P (tmp_rtx))
291
                continue;
292
              if (NOTE_P (tmp_rtx)
293
                  && (1 || in_bb_p[INSN_UID (tmp_rtx)] == NOT_IN_BB))
294
                continue;
295
            }
296
 
297
          if ((i = start[INSN_UID (tmp_rtx)]) >= 0)
298
            {
299
              /* We start a subgraph for each basic block.  */
300
              start_bb (fp, i);
301
 
302
              if (i == 0)
303
                draw_edge (fp, 0, INSN_UID (tmp_rtx), 1, 0);
304
            }
305
 
306
          /* Print the data for this node.  */
307
          node_data (fp, tmp_rtx);
308
          next_insn = next_nonnote_insn (tmp_rtx);
309
 
310
          if ((i = end[INSN_UID (tmp_rtx)]) >= 0)
311
            {
312
              edge e;
313
              edge_iterator ei;
314
 
315
              bb = BASIC_BLOCK (i);
316
 
317
              /* End of the basic block.  */
318
              end_bb (fp);
319
 
320
              /* Now specify the edges to all the successors of this
321
                 basic block.  */
322
              FOR_EACH_EDGE (e, ei, bb->succs)
323
                {
324
                  if (e->dest != EXIT_BLOCK_PTR)
325
                    {
326
                      rtx block_head = BB_HEAD (e->dest);
327
 
328
                      draw_edge (fp, INSN_UID (tmp_rtx),
329
                                 INSN_UID (block_head),
330
                                 next_insn != block_head,
331
                                 (e->flags & EDGE_ABNORMAL ? 2 : 0));
332
 
333
                      if (block_head == next_insn)
334
                        edge_printed = 1;
335
                    }
336
                  else
337
                    {
338
                      draw_edge (fp, INSN_UID (tmp_rtx), 999999,
339
                                 next_insn != 0,
340
                                 (e->flags & EDGE_ABNORMAL ? 2 : 0));
341
 
342
                      if (next_insn == 0)
343
                        edge_printed = 1;
344
                    }
345
                }
346
            }
347
 
348
          if (!edge_printed)
349
            {
350
              /* Don't print edges to barriers.  */
351
              if (next_insn == 0
352
                  || !BARRIER_P (next_insn))
353
                draw_edge (fp, XINT (tmp_rtx, 0),
354
                           next_insn ? INSN_UID (next_insn) : 999999, 0, 0);
355
              else
356
                {
357
                  /* We draw the remaining edges in class 3.  We have
358
                     to skip over the barrier since these nodes are
359
                     not printed at all.  */
360
                  do
361
                    next_insn = NEXT_INSN (next_insn);
362
                  while (next_insn
363
                         && (NOTE_P (next_insn)
364
                             || BARRIER_P (next_insn)));
365
 
366
                  draw_edge (fp, XINT (tmp_rtx, 0),
367
                             next_insn ? INSN_UID (next_insn) : 999999, 0, 3);
368
                }
369
            }
370
        }
371
 
372
      dump_for_graph = 0;
373
 
374
      end_fct (fp);
375
 
376
      /* Clean up.  */
377
      free (start);
378
      free (end);
379
      free (in_bb_p);
380
    }
381
 
382
  fclose (fp);
383
}
384
 
385
 
386
/* Similar as clean_dump_file, but this time for graph output files.  */
387
 
388
void
389
clean_graph_dump_file (const char *base)
390
{
391
  size_t namelen = strlen (base);
392
  size_t extlen = strlen (graph_ext[graph_dump_format]) + 1;
393
  char *buf = alloca (namelen + extlen);
394
  FILE *fp;
395
 
396
  memcpy (buf, base, namelen);
397
  memcpy (buf + namelen, graph_ext[graph_dump_format], extlen);
398
 
399
  fp = fopen (buf, "w");
400
 
401
  if (fp == NULL)
402
    fatal_error ("can't open %s: %m", buf);
403
 
404
  gcc_assert (graph_dump_format == vcg);
405
  fputs ("graph: {\nport_sharing: no\n", fp);
406
 
407
  fclose (fp);
408
}
409
 
410
 
411
/* Do final work on the graph output file.  */
412
void
413
finish_graph_dump_file (const char *base)
414
{
415
  size_t namelen = strlen (base);
416
  size_t extlen = strlen (graph_ext[graph_dump_format]) + 1;
417
  char *buf = alloca (namelen + extlen);
418
  FILE *fp;
419
 
420
  memcpy (buf, base, namelen);
421
  memcpy (buf + namelen, graph_ext[graph_dump_format], extlen);
422
 
423
  fp = fopen (buf, "a");
424
  if (fp != NULL)
425
    {
426
      gcc_assert (graph_dump_format == vcg);
427
      fputs ("}\n", fp);
428
      fclose (fp);
429
    }
430
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.