OSDN Git Service

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