OSDN Git Service

* gjavah.c (cxx_keyword_subst): Use ARRAY_SIZE.
[pf3gnuchains/gcc-fork.git] / gcc / print-rtl.c
1 /* Print RTL for GNU C Compiler.
2    Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000
3    Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 #include "config.h"
24 #include "system.h"
25 #include "rtl.h"
26 #include "real.h"
27 #include "flags.h"
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
30
31 /* How to print out a register name.
32    We don't use PRINT_REG because some definitions of PRINT_REG
33    don't work here.  */
34 #ifndef DEBUG_PRINT_REG
35 #define DEBUG_PRINT_REG(RTX, CODE, FILE) \
36   fprintf ((FILE), "%d %s", REGNO (RTX), reg_names[REGNO (RTX)])
37 #endif
38
39 /* Array containing all of the register names */
40
41 #ifdef DEBUG_REGISTER_NAMES
42 static const char * const debug_reg_names[] = DEBUG_REGISTER_NAMES;
43 #define reg_names debug_reg_names
44 #else
45 const char * reg_names[] = REGISTER_NAMES;
46 #endif
47
48 static FILE *outfile;
49
50 static const char xspaces[] = "                                                                                                                                                                ";
51
52 static int sawclose = 0;
53
54 static int indent;
55
56 static void print_rtx           PARAMS ((rtx));
57
58 /* Nonzero means suppress output of instruction numbers and line number
59    notes in debugging dumps.
60    This must be defined here so that programs like gencodes can be linked.  */
61 int flag_dump_unnumbered = 0;
62
63 /* Nonzero if we are dumping graphical description.  */
64 int dump_for_graph;
65
66 /* Print IN_RTX onto OUTFILE.  This is the recursive part of printing.  */
67
68 static void
69 print_rtx (in_rtx)
70      register rtx in_rtx;
71 {
72   register int i = 0;
73   register int j;
74   register const char *format_ptr;
75   register int is_insn;
76   rtx tem;
77
78   if (sawclose)
79     {
80       fprintf (outfile, "\n%s",
81                (xspaces + (sizeof xspaces - 1 - indent * 2)));
82       sawclose = 0;
83     }
84
85   if (in_rtx == 0)
86     {
87       fputs ("(nil)", outfile);
88       sawclose = 1;
89       return;
90     }
91
92   is_insn = (INSN_P (in_rtx));
93
94   /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
95      in separate nodes and therefore have to handle them special here.  */
96   if (dump_for_graph &&
97       (is_insn || GET_CODE (in_rtx) == NOTE || GET_CODE (in_rtx) == CODE_LABEL
98        || GET_CODE (in_rtx) == BARRIER))
99     {
100       i = 3;
101       indent = 0;
102     }
103   else
104     {
105       /* print name of expression code */
106       fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
107
108       if (in_rtx->in_struct)
109         fputs ("/s", outfile);
110
111       if (in_rtx->volatil)
112         fputs ("/v", outfile);
113
114       if (in_rtx->unchanging)
115         fputs ("/u", outfile);
116
117       if (in_rtx->integrated)
118         fputs ("/i", outfile);
119
120       if (in_rtx->frame_related)
121         fputs ("/f", outfile);
122
123       if (in_rtx->jump)
124         fputs ("/j", outfile);
125
126       if (in_rtx->call)
127         fputs ("/c", outfile);
128
129       if (GET_MODE (in_rtx) != VOIDmode)
130         {
131           /* Print REG_NOTE names for EXPR_LIST and INSN_LIST.  */
132           if (GET_CODE (in_rtx) == EXPR_LIST || GET_CODE (in_rtx) == INSN_LIST)
133             fprintf (outfile, ":%s", GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
134           else
135             fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
136         }
137     }
138
139   /* Get the format string and skip the first elements if we have handled
140      them already.  */
141   format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
142
143   for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
144     switch (*format_ptr++)
145       {
146       case 'S':
147       case 's':
148         if (XSTR (in_rtx, i) == 0)
149           fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
150         else
151           {
152             if (dump_for_graph)
153               fprintf (outfile, " (\\\"%s\\\")", XSTR (in_rtx, i));
154             else
155               fprintf (outfile, " (\"%s\")", XSTR (in_rtx, i));
156           }
157         sawclose = 1;
158         break;
159
160         /* 0 indicates a field for internal use that should not be printed.
161            An exception is the third field of a NOTE, where it indicates
162            that the field has several different valid contents.  */
163       case '0':
164         if (i == 3 && GET_CODE (in_rtx) == NOTE)
165           {
166             switch (NOTE_LINE_NUMBER (in_rtx))
167               {
168               case NOTE_INSN_EH_REGION_BEG:
169               case NOTE_INSN_EH_REGION_END:
170                 if (flag_dump_unnumbered)
171                   fprintf (outfile, " #");
172                 else
173                   fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
174                 sawclose = 1;
175                 break;
176
177               case NOTE_INSN_BLOCK_BEG:
178               case NOTE_INSN_BLOCK_END:
179                 fprintf (outfile, " ");
180                 if (flag_dump_unnumbered)
181                   fprintf (outfile, "#");
182                 else
183                   fprintf (outfile, HOST_PTR_PRINTF, 
184                            (char *) NOTE_BLOCK (in_rtx));
185                 sawclose = 1;
186                 break;
187
188               case NOTE_INSN_RANGE_BEG:
189               case NOTE_INSN_RANGE_END:
190               case NOTE_INSN_LIVE:
191                 indent += 2;
192                 if (!sawclose)
193                   fprintf (outfile, " ");
194                 print_rtx (NOTE_RANGE_INFO (in_rtx));
195                 indent -= 2;
196                 break;
197
198               case NOTE_INSN_BASIC_BLOCK:
199                 {
200                   basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
201                   if (bb != 0)
202                     fprintf (outfile, " [bb %d]", bb->index);
203                   break;
204                 }
205
206               case NOTE_INSN_EXPECTED_VALUE:
207                 indent += 2;
208                 if (!sawclose)
209                   fprintf (outfile, " ");
210                 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
211                 indent -= 2;
212                 break;
213
214               case NOTE_INSN_DELETED_LABEL:
215                 if (NOTE_SOURCE_FILE (in_rtx))
216                   fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
217                 else
218                   fprintf (outfile, " \"\"");
219                 break;
220
221               default:
222                 {
223                   const char * const str = X0STR (in_rtx, i);
224
225                   if (NOTE_LINE_NUMBER (in_rtx) < 0)
226                     ;
227                   else if (str == 0)
228                     fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
229                   else
230                     {
231                       if (dump_for_graph)
232                         fprintf (outfile, " (\\\"%s\\\")", str);
233                       else
234                         fprintf (outfile, " (\"%s\")", str);
235                     }
236                   break;
237                 }
238               }
239           }
240         break;
241
242       case 'e':
243       do_e:
244         indent += 2;
245         if (!sawclose)
246           fprintf (outfile, " ");
247         print_rtx (XEXP (in_rtx, i));
248         indent -= 2;
249         break;
250
251       case 'E':
252       case 'V':
253         indent += 2;
254         if (sawclose)
255           {
256             fprintf (outfile, "\n%s",
257                      (xspaces + (sizeof xspaces - 1 - indent * 2)));
258             sawclose = 0;
259           }
260         fputs ("[ ", outfile);
261         if (NULL != XVEC (in_rtx, i))
262           {
263             indent += 2;
264             if (XVECLEN (in_rtx, i))
265               sawclose = 1;
266
267             for (j = 0; j < XVECLEN (in_rtx, i); j++)
268               print_rtx (XVECEXP (in_rtx, i, j));
269
270             indent -= 2;
271           }
272         if (sawclose)
273           fprintf (outfile, "\n%s",
274                    (xspaces + (sizeof xspaces - 1 - indent * 2)));
275
276         fputs ("] ", outfile);
277         sawclose = 1;
278         indent -= 2;
279         break;
280
281       case 'w':
282         fprintf (outfile, " ");
283         fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
284         fprintf (outfile, " [");
285         fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
286         fprintf (outfile, "]");
287         break;
288
289       case 'i':
290         {
291           register int value = XINT (in_rtx, i);
292           const char *name;
293
294           if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
295             {
296               fputc (' ', outfile);
297               DEBUG_PRINT_REG (in_rtx, 0, outfile);
298             }
299           else if (GET_CODE (in_rtx) == REG && value <= LAST_VIRTUAL_REGISTER)
300             {
301               if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
302                 fprintf (outfile, " %d virtual-incoming-args", value);
303               else if (value == VIRTUAL_STACK_VARS_REGNUM)
304                 fprintf (outfile, " %d virtual-stack-vars", value);
305               else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
306                 fprintf (outfile, " %d virtual-stack-dynamic", value);
307               else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
308                 fprintf (outfile, " %d virtual-outgoing-args", value);
309               else if (value == VIRTUAL_CFA_REGNUM)
310                 fprintf (outfile, " %d virtual-cfa", value);
311               else
312                 fprintf (outfile, " %d virtual-reg-%d", value,
313                          value-FIRST_VIRTUAL_REGISTER);
314             }
315           else if (flag_dump_unnumbered
316                    && (is_insn || GET_CODE (in_rtx) == NOTE))
317             fputc ('#', outfile);
318           else
319             fprintf (outfile, " %d", value);
320
321           if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
322               && XINT (in_rtx, i) >= 0
323               && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
324             fprintf (outfile, " {%s}", name);
325           sawclose = 0;
326         }
327         break;
328
329       /* Print NOTE_INSN names rather than integer codes.  */
330
331       case 'n':
332         if (XINT (in_rtx, i) >= NOTE_INSN_BIAS
333             && XINT (in_rtx, i) < NOTE_INSN_MAX)
334           fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
335         else
336           fprintf (outfile, " %d", XINT (in_rtx, i));
337         sawclose = 0;
338         break;
339
340       case 'u':
341         if (XEXP (in_rtx, i) != NULL)
342           {
343             rtx sub = XEXP (in_rtx, i);
344             enum rtx_code subc = GET_CODE (sub);
345
346             if (GET_CODE (in_rtx) == LABEL_REF)
347               {
348                 if (subc == NOTE
349                     && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
350                   {
351                     if (flag_dump_unnumbered)
352                       fprintf (outfile, " [# deleted]");
353                     else
354                       fprintf (outfile, " [%d deleted]", INSN_UID (sub));
355                     sawclose = 0;
356                     break;
357                   }
358
359                 if (subc != CODE_LABEL)
360                   goto do_e;
361               }
362
363             if (flag_dump_unnumbered)
364               fputs (" #", outfile);
365             else
366               fprintf (outfile, " %d", INSN_UID (sub));
367           }
368         else
369           fputs (" 0", outfile);
370         sawclose = 0;
371         break;
372
373       case 'b':
374         if (XBITMAP (in_rtx, i) == NULL)
375           fputs (" {null}", outfile);
376         else
377           bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
378         sawclose = 0;
379         break;
380
381       case 't':
382         putc (' ', outfile);
383         fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
384         break;
385
386       case '*':
387         fputs (" Unknown", outfile);
388         sawclose = 0;
389         break;
390
391       default:
392         fprintf (stderr,
393                  "switch format wrong in rtl.print_rtx(). format was: %c.\n",
394                  format_ptr[-1]);
395         abort ();
396       }
397
398   switch (GET_CODE (in_rtx))
399     {
400     case MEM:
401       fputc (' ', outfile);
402       fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
403       break;
404
405 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
406     case CONST_DOUBLE:
407       if (FLOAT_MODE_P (GET_MODE (in_rtx)))
408         {
409           double val;
410           REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
411           fprintf (outfile, " [%.16g]", val);
412         }
413       break;
414 #endif
415
416     case CODE_LABEL:
417       fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
418       if (LABEL_ALTERNATE_NAME (in_rtx))
419         fprintf (outfile, " [alternate name: %s]",
420                  LABEL_ALTERNATE_NAME (in_rtx));
421       break;
422
423     case CALL_PLACEHOLDER:
424       for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
425         if (GET_CODE (tem) == CALL_INSN)
426           {
427             fprintf (outfile, " ");
428             print_rtx (tem);
429             break;
430           }
431       break;
432
433     default:
434       break;
435     }
436
437   if (dump_for_graph
438       && (is_insn || GET_CODE (in_rtx) == NOTE
439           || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
440     sawclose = 0;
441   else
442     {
443       fputc (')', outfile);
444       sawclose = 1;
445     }
446 }
447
448 /* Print an rtx on the current line of FILE.  Initially indent IND
449    characters.  */
450
451 void
452 print_inline_rtx (outf, x, ind)
453      FILE *outf;
454      rtx x;
455      int ind;
456 {
457   int oldsaw = sawclose;
458   int oldindent = indent;
459
460   sawclose = 0;
461   indent = ind;
462   outfile = outf;
463   print_rtx (x);
464   sawclose = oldsaw;
465   indent = oldindent;
466 }
467
468 /* Call this function from the debugger to see what X looks like.  */
469
470 void
471 debug_rtx (x)
472      rtx x;
473 {
474   outfile = stderr;
475   print_rtx (x);
476   fprintf (stderr, "\n");
477 }
478
479 /* Count of rtx's to print with debug_rtx_list.
480    This global exists because gdb user defined commands have no arguments.  */
481
482 int debug_rtx_count = 0;        /* 0 is treated as equivalent to 1 */
483
484 /* Call this function to print list from X on.
485
486    N is a count of the rtx's to print. Positive values print from the specified
487    rtx on.  Negative values print a window around the rtx.
488    EG: -5 prints 2 rtx's on either side (in addition to the specified rtx).  */
489
490 void
491 debug_rtx_list (x, n)
492      rtx x;
493      int n;
494 {
495   int i,count;
496   rtx insn;
497
498   count = n == 0 ? 1 : n < 0 ? -n : n;
499
500   /* If we are printing a window, back up to the start.  */
501
502   if (n < 0)
503     for (i = count / 2; i > 0; i--)
504       {
505         if (PREV_INSN (x) == 0)
506           break;
507         x = PREV_INSN (x);
508       }
509
510   for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
511     debug_rtx (insn);
512 }
513
514 /* Call this function to print an rtx list from START to END inclusive.  */
515
516 void
517 debug_rtx_range (start, end)
518      rtx start, end;
519 {
520   while (1)
521     {
522       debug_rtx (start);
523       if (!start || start == end)
524         break;
525       start = NEXT_INSN (start);
526     }
527 }
528
529 /* Call this function to search an rtx list to find one with insn uid UID,
530    and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
531    The found insn is returned to enable further debugging analysis.  */
532
533 rtx
534 debug_rtx_find (x, uid)
535      rtx x;
536      int uid;
537 {
538   while (x != 0 && INSN_UID (x) != uid)
539     x = NEXT_INSN (x);
540   if (x != 0)
541     {
542       debug_rtx_list (x, debug_rtx_count);
543       return x;
544     }
545   else
546     {
547       fprintf (stderr, "insn uid %d not found\n", uid);
548       return 0;
549     }
550 }
551
552 /* External entry point for printing a chain of insns
553    starting with RTX_FIRST onto file OUTF.
554    A blank line separates insns.
555
556    If RTX_FIRST is not an insn, then it alone is printed, with no newline.  */
557
558 void
559 print_rtl (outf, rtx_first)
560      FILE *outf;
561      rtx rtx_first;
562 {
563   register rtx tmp_rtx;
564
565   outfile = outf;
566   sawclose = 0;
567
568   if (rtx_first == 0)
569     fputs ("(nil)\n", outf);
570   else
571     switch (GET_CODE (rtx_first))
572       {
573       case INSN:
574       case JUMP_INSN:
575       case CALL_INSN:
576       case NOTE:
577       case CODE_LABEL:
578       case BARRIER:
579         for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
580           if (! flag_dump_unnumbered
581               || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
582             {
583               print_rtx (tmp_rtx);
584               fprintf (outfile, "\n");
585             }
586         break;
587
588       default:
589         print_rtx (rtx_first);
590       }
591 }
592
593 /* Like print_rtx, except specify a file.  */
594 /* Return nonzero if we actually printed anything.  */
595
596 int
597 print_rtl_single (outf, x)
598      FILE *outf;
599      rtx x;
600 {
601   outfile = outf;
602   sawclose = 0;
603   if (! flag_dump_unnumbered
604       || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
605     {
606       print_rtx (x);
607       putc ('\n', outf);
608       return 1;
609     }
610   return 0;
611 }