OSDN Git Service

Fix mips64vr4100-elf build failure.
[pf3gnuchains/gcc-fork.git] / gcc / print-rtl.c
1 /* Print RTL for GNU C Compiler.
2    Copyright (C) 1987, 1988, 1992, 1997 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21
22 #include "config.h"
23 #include "system.h"
24 #include "rtl.h"
25 #include "bitmap.h"
26
27
28 /* How to print out a register name.
29    We don't use PRINT_REG because some definitions of PRINT_REG
30    don't work here.  */
31 #ifndef DEBUG_PRINT_REG
32 #define DEBUG_PRINT_REG(RTX, CODE, FILE) \
33   fprintf ((FILE), "%d %s", REGNO (RTX), reg_names[REGNO (RTX)])
34 #endif
35
36 /* Array containing all of the register names */
37
38 #ifdef DEBUG_REGISTER_NAMES
39 static char *reg_names[] = DEBUG_REGISTER_NAMES;
40 #else
41 static char *reg_names[] = REGISTER_NAMES;
42 #endif
43
44 static FILE *outfile;
45
46 char spaces[] = "                                                                                                                                                                ";
47
48 static int sawclose = 0;
49
50 static int indent;
51
52 /* Names for patterns.  Non-zero only when linked with insn-output.c.  */
53
54 extern char **insn_name_ptr;
55
56 /* Print IN_RTX onto OUTFILE.  This is the recursive part of printing.  */
57
58 static void
59 print_rtx (in_rtx)
60      register rtx in_rtx;
61 {
62   register int i, j;
63   register char *format_ptr;
64   register int is_insn;
65
66   if (sawclose)
67     {
68       fprintf (outfile, "\n%s",
69                (spaces + (sizeof spaces - 1 - indent * 2)));
70       sawclose = 0;
71     }
72
73   if (in_rtx == 0)
74     {
75       fprintf (outfile, "(nil)");
76       sawclose = 1;
77       return;
78     }
79
80   /* print name of expression code */
81   fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
82
83   if (in_rtx->in_struct)
84     fprintf (outfile, "/s");
85
86   if (in_rtx->volatil)
87     fprintf (outfile, "/v");
88
89   if (in_rtx->unchanging)
90     fprintf (outfile, "/u");
91
92   if (in_rtx->integrated)
93     fprintf (outfile, "/i");
94
95   if (GET_MODE (in_rtx) != VOIDmode)
96     {
97       /* Print REG_NOTE names for EXPR_LIST and INSN_LIST.  */
98       if (GET_CODE (in_rtx) == EXPR_LIST || GET_CODE (in_rtx) == INSN_LIST)
99         fprintf (outfile, ":%s", GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
100       else
101         fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
102     }
103
104   is_insn = (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i');
105   format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
106
107   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
108     switch (*format_ptr++)
109       {
110       case 'S':
111       case 's':
112         if (i == 3 && GET_CODE (in_rtx) == NOTE
113             && (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_EH_REGION_BEG
114                 || NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_EH_REGION_END
115                 || NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_BLOCK_BEG
116                 || NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_BLOCK_END))
117           {
118             fprintf (outfile, " %d", NOTE_BLOCK_NUMBER (in_rtx));
119             sawclose = 1;
120             break;
121           }
122
123         if (i == 3 && GET_CODE (in_rtx) == NOTE
124             && (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_RANGE_START
125                 || NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_RANGE_END))
126           {
127             indent += 2;
128             if (!sawclose)
129               fprintf (outfile, " ");
130             print_rtx (NOTE_RANGE_INFO (in_rtx));
131             indent -= 2;
132             break;
133           }
134
135         if (i == 3 && GET_CODE (in_rtx) == NOTE
136             && NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_LIVE)
137           {
138             if (XBITMAP (in_rtx, i) == NULL)
139               fprintf (outfile, " {null}");
140             else
141               bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
142             sawclose = 0;
143           }
144
145         if (XSTR (in_rtx, i) == 0)
146           fprintf (outfile, " \"\"");
147         else
148           fprintf (outfile, " (\"%s\")", XSTR (in_rtx, i));
149         sawclose = 1;
150         break;
151
152         /* 0 indicates a field for internal use that should not be printed.  */
153       case '0':
154         break;
155
156       case 'e':
157         indent += 2;
158         if (!sawclose)
159           fprintf (outfile, " ");
160         print_rtx (XEXP (in_rtx, i));
161         indent -= 2;
162         break;
163
164       case 'E':
165       case 'V':
166         indent += 2;
167         if (sawclose)
168           {
169             fprintf (outfile, "\n%s",
170                      (spaces + (sizeof spaces - 1 - indent * 2)));
171             sawclose = 0;
172           }
173         fprintf (outfile, "[ ");
174         if (NULL != XVEC (in_rtx, i))
175           {
176             indent += 2;
177             if (XVECLEN (in_rtx, i))
178               sawclose = 1;
179
180             for (j = 0; j < XVECLEN (in_rtx, i); j++)
181               print_rtx (XVECEXP (in_rtx, i, j));
182
183             indent -= 2;
184           }
185         if (sawclose)
186           fprintf (outfile, "\n%s",
187                    (spaces + (sizeof spaces - 1 - indent * 2)));
188
189         fprintf (outfile, "] ");
190         sawclose = 1;
191         indent -= 2;
192         break;
193
194       case 'w':
195         fprintf (outfile, " ");
196         fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
197         break;
198
199       case 'i':
200         {
201           register int value = XINT (in_rtx, i);
202
203           if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
204             {
205               fputc (' ', outfile);
206               DEBUG_PRINT_REG (in_rtx, 0, outfile);
207             }
208           else
209             fprintf (outfile, " %d", value);
210         }
211         if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
212             && insn_name_ptr
213             && XINT (in_rtx, i) >= 0)
214           fprintf (outfile, " {%s}", insn_name_ptr[XINT (in_rtx, i)]);
215         sawclose = 0;
216         break;
217
218       /* Print NOTE_INSN names rather than integer codes.  */
219
220       case 'n':
221         if (XINT (in_rtx, i) <= 0)
222           fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
223         else
224           fprintf (outfile, " %d", XINT (in_rtx, i));
225         sawclose = 0;
226         break;
227
228       case 'u':
229         if (XEXP (in_rtx, i) != NULL)
230           fprintf (outfile, " %d", INSN_UID (XEXP (in_rtx, i)));
231         else
232           fprintf (outfile, " 0");
233         sawclose = 0;
234         break;
235
236       case 'b':
237         if (XBITMAP (in_rtx, i) == NULL)
238           fprintf (outfile, " {null}");
239         else
240           bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
241         sawclose = 0;
242         break;
243
244       case 't':
245         putc (' ', outfile);
246         fprintf (outfile, HOST_WIDE_INT_PRINT_HEX,
247                  (HOST_WIDE_INT) XTREE (in_rtx, i));
248         break;
249
250       case '*':
251         fprintf (outfile, " Unknown");
252         sawclose = 0;
253         break;
254
255       default:
256         fprintf (stderr,
257                  "switch format wrong in rtl.print_rtx(). format was: %c.\n",
258                  format_ptr[-1]);
259         abort ();
260       }
261
262   fprintf (outfile, ")");
263   sawclose = 1;
264 }
265
266 /* Print an rtx on the current line of FILE.  Initially indent IND
267    characters.  */
268
269 void
270 print_inline_rtx (outf, x, ind)
271      FILE *outf;
272      rtx x;
273      int ind;
274 {
275   int oldsaw = sawclose;
276   int oldindent = indent;
277
278   sawclose = 0;
279   indent = ind;
280   outfile = outf;
281   print_rtx (x);
282   sawclose = oldsaw;
283   indent = oldindent;
284 }
285
286 /* Call this function from the debugger to see what X looks like.  */
287
288 void
289 debug_rtx (x)
290      rtx x;
291 {
292   outfile = stderr;
293   print_rtx (x);
294   fprintf (stderr, "\n");
295 }
296
297 /* Count of rtx's to print with debug_rtx_list.
298    This global exists because gdb user defined commands have no arguments.  */
299
300 int debug_rtx_count = 0;        /* 0 is treated as equivalent to 1 */
301
302 /* Call this function to print list from X on.
303
304    N is a count of the rtx's to print. Positive values print from the specified
305    rtx on.  Negative values print a window around the rtx.
306    EG: -5 prints 2 rtx's on either side (in addition to the specified rtx).  */
307
308 void
309 debug_rtx_list (x, n)
310      rtx x;
311      int n;
312 {
313   int i,count;
314   rtx insn;
315
316   count = n == 0 ? 1 : n < 0 ? -n : n;
317
318   /* If we are printing a window, back up to the start.  */
319
320   if (n < 0)
321     for (i = count / 2; i > 0; i--)
322       {
323         if (PREV_INSN (x) == 0)
324           break;
325         x = PREV_INSN (x);
326       }
327
328   for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
329     debug_rtx (insn);
330 }
331
332 /* Call this function to search an rtx list to find one with insn uid UID,
333    and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
334    The found insn is returned to enable further debugging analysis.  */
335
336 rtx
337 debug_rtx_find (x, uid)
338      rtx x;
339      int uid;
340 {
341   while (x != 0 && INSN_UID (x) != uid)
342     x = NEXT_INSN (x);
343   if (x != 0)
344     {
345       debug_rtx_list (x, debug_rtx_count);
346       return x;
347     }
348   else
349     {
350       fprintf (stderr, "insn uid %d not found\n", uid);
351       return 0;
352     }
353 }
354
355 /* External entry point for printing a chain of insns
356    starting with RTX_FIRST onto file OUTF.
357    A blank line separates insns.
358
359    If RTX_FIRST is not an insn, then it alone is printed, with no newline.  */
360
361 void
362 print_rtl (outf, rtx_first)
363      FILE *outf;
364      rtx rtx_first;
365 {
366   register rtx tmp_rtx;
367
368   outfile = outf;
369   sawclose = 0;
370
371   if (rtx_first == 0)
372     fprintf (outf, "(nil)\n");
373   else
374     switch (GET_CODE (rtx_first))
375       {
376       case INSN:
377       case JUMP_INSN:
378       case CALL_INSN:
379       case NOTE:
380       case CODE_LABEL:
381       case BARRIER:
382         for (tmp_rtx = rtx_first; NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx))
383           {
384             print_rtx (tmp_rtx);
385             fprintf (outfile, "\n");
386           }
387         break;
388
389       default:
390         print_rtx (rtx_first);
391       }
392 }
393
394 /* Like print_rtx, except specify a file.  */
395
396 void
397 print_rtl_single (outf, x)
398      FILE *outf;
399      rtx x;
400 {
401   outfile = outf;
402   sawclose = 0;
403   print_rtx (x);
404   putc ('\n', outf);
405 }