Add D30V options
[official-gcc.git] / gcc / print-rtl.c
blob16a64db9e3b5097b8fcfec80b9acecd68de2d3d0
1 /* Print RTL for GNU C Compiler.
2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU CC.
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.
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.
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. */
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"
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
39 /* Array containing all of the register names */
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
48 static FILE *outfile;
50 static const char xspaces[] = " ";
52 static int sawclose = 0;
54 static int indent;
56 static void print_rtx PARAMS ((rtx));
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;
63 /* Nonzero if we are dumping graphical description. */
64 int dump_for_graph;
66 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
68 static void
69 print_rtx (in_rtx)
70 register rtx in_rtx;
72 register int i = 0;
73 register int j;
74 register const char *format_ptr;
75 register int is_insn;
76 rtx tem;
78 if (sawclose)
80 fprintf (outfile, "\n%s",
81 (xspaces + (sizeof xspaces - 1 - indent * 2)));
82 sawclose = 0;
85 if (in_rtx == 0)
87 fputs ("(nil)", outfile);
88 sawclose = 1;
89 return;
92 is_insn = (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i');
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))
100 i = 3;
101 indent = 0;
103 else
105 /* print name of expression code */
106 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
108 if (in_rtx->in_struct)
109 fputs ("/s", outfile);
111 if (in_rtx->volatil)
112 fputs ("/v", outfile);
114 if (in_rtx->unchanging)
115 fputs ("/u", outfile);
117 if (in_rtx->integrated)
118 fputs ("/i", outfile);
120 if (in_rtx->frame_related)
121 fputs ("/f", outfile);
123 if (in_rtx->jump)
124 fputs ("/j", outfile);
126 if (in_rtx->call)
127 fputs ("/c", outfile);
129 if (GET_MODE (in_rtx) != VOIDmode)
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)));
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;
143 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
144 switch (*format_ptr++)
146 case 'S':
147 case 's':
148 if (XSTR (in_rtx, i) == 0)
149 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
150 else
152 if (dump_for_graph)
153 fprintf (outfile, " (\\\"%s\\\")", XSTR (in_rtx, i));
154 else
155 fprintf (outfile, " (\"%s\")", XSTR (in_rtx, i));
157 sawclose = 1;
158 break;
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)
166 switch (NOTE_LINE_NUMBER (in_rtx))
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;
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;
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;
198 case NOTE_INSN_BASIC_BLOCK:
200 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
201 if (bb != 0)
202 fprintf (outfile, " [bb %d]", bb->index);
203 break;
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;
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;
221 default:
223 const char * const str = X0STR (in_rtx, i);
225 if (NOTE_LINE_NUMBER (in_rtx) < 0)
227 else if (str == 0)
228 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
229 else
231 if (dump_for_graph)
232 fprintf (outfile, " (\\\"%s\\\")", str);
233 else
234 fprintf (outfile, " (\"%s\")", str);
236 break;
240 break;
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;
251 case 'E':
252 case 'V':
253 indent += 2;
254 if (sawclose)
256 fprintf (outfile, "\n%s",
257 (xspaces + (sizeof xspaces - 1 - indent * 2)));
258 sawclose = 0;
260 fputs ("[ ", outfile);
261 if (NULL != XVEC (in_rtx, i))
263 indent += 2;
264 if (XVECLEN (in_rtx, i))
265 sawclose = 1;
267 for (j = 0; j < XVECLEN (in_rtx, i); j++)
268 print_rtx (XVECEXP (in_rtx, i, j));
270 indent -= 2;
272 if (sawclose)
273 fprintf (outfile, "\n%s",
274 (xspaces + (sizeof xspaces - 1 - indent * 2)));
276 fputs ("] ", outfile);
277 sawclose = 1;
278 indent -= 2;
279 break;
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;
289 case 'i':
291 register int value = XINT (in_rtx, i);
292 const char *name;
294 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
296 fputc (' ', outfile);
297 DEBUG_PRINT_REG (in_rtx, 0, outfile);
299 else if (GET_CODE (in_rtx) == REG && value <= LAST_VIRTUAL_REGISTER)
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);
315 else if (flag_dump_unnumbered
316 && (is_insn || GET_CODE (in_rtx) == NOTE))
317 fputc ('#', outfile);
318 else
319 fprintf (outfile, " %d", value);
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;
327 break;
329 /* Print NOTE_INSN names rather than integer codes. */
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;
340 case 'u':
341 if (XEXP (in_rtx, i) != NULL)
343 rtx sub = XEXP (in_rtx, i);
344 enum rtx_code subc = GET_CODE (sub);
346 if (GET_CODE (in_rtx) == LABEL_REF)
348 if (subc == NOTE
349 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
351 if (flag_dump_unnumbered)
352 fprintf (outfile, " [# deleted]");
353 else
354 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
355 sawclose = 0;
356 break;
359 if (subc != CODE_LABEL)
360 goto do_e;
363 if (flag_dump_unnumbered)
364 fputs (" #", outfile);
365 else
366 fprintf (outfile, " %d", INSN_UID (sub));
368 else
369 fputs (" 0", outfile);
370 sawclose = 0;
371 break;
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;
381 case 't':
382 putc (' ', outfile);
383 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
384 break;
386 case '*':
387 fputs (" Unknown", outfile);
388 sawclose = 0;
389 break;
391 default:
392 fprintf (stderr,
393 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
394 format_ptr[-1]);
395 abort ();
398 switch (GET_CODE (in_rtx))
400 case MEM:
401 fputc (' ', outfile);
402 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
403 break;
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)))
409 double val;
410 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
411 fprintf (outfile, " [%.16g]", val);
413 break;
414 #endif
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;
423 case CALL_PLACEHOLDER:
424 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
425 if (GET_CODE (tem) == CALL_INSN)
427 fprintf (outfile, " ");
428 print_rtx (tem);
429 break;
431 break;
433 default:
434 break;
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
443 fputc (')', outfile);
444 sawclose = 1;
448 /* Print an rtx on the current line of FILE. Initially indent IND
449 characters. */
451 void
452 print_inline_rtx (outf, x, ind)
453 FILE *outf;
454 rtx x;
455 int ind;
457 int oldsaw = sawclose;
458 int oldindent = indent;
460 sawclose = 0;
461 indent = ind;
462 outfile = outf;
463 print_rtx (x);
464 sawclose = oldsaw;
465 indent = oldindent;
468 /* Call this function from the debugger to see what X looks like. */
470 void
471 debug_rtx (x)
472 rtx x;
474 outfile = stderr;
475 print_rtx (x);
476 fprintf (stderr, "\n");
479 /* Count of rtx's to print with debug_rtx_list.
480 This global exists because gdb user defined commands have no arguments. */
482 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
484 /* Call this function to print list from X on.
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). */
490 void
491 debug_rtx_list (x, n)
492 rtx x;
493 int n;
495 int i,count;
496 rtx insn;
498 count = n == 0 ? 1 : n < 0 ? -n : n;
500 /* If we are printing a window, back up to the start. */
502 if (n < 0)
503 for (i = count / 2; i > 0; i--)
505 if (PREV_INSN (x) == 0)
506 break;
507 x = PREV_INSN (x);
510 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
511 debug_rtx (insn);
514 /* Call this function to print an rtx list from START to END inclusive. */
516 void
517 debug_rtx_range (start, end)
518 rtx start, end;
520 while (1)
522 debug_rtx (start);
523 if (!start || start == end)
524 break;
525 start = NEXT_INSN (start);
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. */
534 debug_rtx_find (x, uid)
535 rtx x;
536 int uid;
538 while (x != 0 && INSN_UID (x) != uid)
539 x = NEXT_INSN (x);
540 if (x != 0)
542 debug_rtx_list (x, debug_rtx_count);
543 return x;
545 else
547 fprintf (stderr, "insn uid %d not found\n", uid);
548 return 0;
552 /* External entry point for printing a chain of insns
553 starting with RTX_FIRST onto file OUTF.
554 A blank line separates insns.
556 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
558 void
559 print_rtl (outf, rtx_first)
560 FILE *outf;
561 rtx rtx_first;
563 register rtx tmp_rtx;
565 outfile = outf;
566 sawclose = 0;
568 if (rtx_first == 0)
569 fputs ("(nil)\n", outf);
570 else
571 switch (GET_CODE (rtx_first))
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)
583 print_rtx (tmp_rtx);
584 fprintf (outfile, "\n");
586 break;
588 default:
589 print_rtx (rtx_first);
593 /* Like print_rtx, except specify a file. */
594 /* Return nonzero if we actually printed anything. */
597 print_rtl_single (outf, x)
598 FILE *outf;
599 rtx x;
601 outfile = outf;
602 sawclose = 0;
603 if (! flag_dump_unnumbered
604 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
606 print_rtx (x);
607 putc ('\n', outf);
608 return 1;
610 return 0;