OSDN Git Service

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