* rtl.h (insn_note): Remove NOTE_INSN_PREDICTION.
[official-gcc.git] / gcc / print-rtl.c
blob8b211f076acd9e4c9009a91bc7c41d39100efa62
1 /* Print RTL for GCC.
2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003, 2004
3 Free Software Foundation, Inc.
5 This file is part of GCC.
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.
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.
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. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "rtl.h"
29 /* We don't want the tree code checking code for the access to the
30 DECL_NAME to be included in the gen* programs. */
31 #undef ENABLE_TREE_CHECKING
32 #include "tree.h"
33 #include "real.h"
34 #include "flags.h"
35 #include "hard-reg-set.h"
36 #include "basic-block.h"
37 #include "tm_p.h"
39 static FILE *outfile;
41 static int sawclose = 0;
43 static int indent;
45 static void print_rtx (rtx);
47 /* String printed at beginning of each RTL when it is dumped.
48 This string is set to ASM_COMMENT_START when the RTL is dumped in
49 the assembly output file. */
50 const char *print_rtx_head = "";
52 /* Nonzero means suppress output of instruction numbers and line number
53 notes in debugging dumps.
54 This must be defined here so that programs like gencodes can be linked. */
55 int flag_dump_unnumbered = 0;
57 /* Nonzero means use simplified format without flags, modes, etc. */
58 int flag_simple = 0;
60 /* Nonzero if we are dumping graphical description. */
61 int dump_for_graph;
63 void
64 print_mem_expr (FILE *outfile, tree expr)
66 if (TREE_CODE (expr) == COMPONENT_REF)
68 if (TREE_OPERAND (expr, 0))
69 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
70 else
71 fputs (" <variable>", outfile);
72 if (DECL_NAME (TREE_OPERAND (expr, 1)))
73 fprintf (outfile, ".%s",
74 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (expr, 1))));
76 else if (TREE_CODE (expr) == INDIRECT_REF)
78 fputs (" (*", outfile);
79 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
80 fputs (")", outfile);
82 else if (DECL_NAME (expr))
83 fprintf (outfile, " %s", IDENTIFIER_POINTER (DECL_NAME (expr)));
84 else if (TREE_CODE (expr) == RESULT_DECL)
85 fputs (" <result>", outfile);
86 else
87 fputs (" <anonymous>", outfile);
90 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
92 static void
93 print_rtx (rtx in_rtx)
95 int i = 0;
96 int j;
97 const char *format_ptr;
98 int is_insn;
100 if (sawclose)
102 if (flag_simple)
103 fputc (' ', outfile);
104 else
105 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
106 sawclose = 0;
109 if (in_rtx == 0)
111 fputs ("(nil)", outfile);
112 sawclose = 1;
113 return;
115 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
117 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
118 sawclose = 1;
119 return;
122 is_insn = INSN_P (in_rtx);
124 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
125 in separate nodes and therefore have to handle them special here. */
126 if (dump_for_graph
127 && (is_insn || NOTE_P (in_rtx)
128 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
130 i = 3;
131 indent = 0;
133 else
135 /* Print name of expression code. */
136 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
137 fputc ('(', outfile);
138 else
139 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
141 if (! flag_simple)
143 if (RTX_FLAG (in_rtx, in_struct))
144 fputs ("/s", outfile);
146 if (RTX_FLAG (in_rtx, volatil))
147 fputs ("/v", outfile);
149 if (RTX_FLAG (in_rtx, unchanging))
150 fputs ("/u", outfile);
152 if (RTX_FLAG (in_rtx, frame_related))
153 fputs ("/f", outfile);
155 if (RTX_FLAG (in_rtx, jump))
156 fputs ("/j", outfile);
158 if (RTX_FLAG (in_rtx, call))
159 fputs ("/c", outfile);
161 if (RTX_FLAG (in_rtx, return_val))
162 fputs ("/i", outfile);
164 if (GET_MODE (in_rtx) != VOIDmode)
166 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
167 if (GET_CODE (in_rtx) == EXPR_LIST
168 || GET_CODE (in_rtx) == INSN_LIST)
169 fprintf (outfile, ":%s",
170 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
171 else
172 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
177 #ifndef GENERATOR_FILE
178 if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
179 i = 5;
180 #endif
182 /* Get the format string and skip the first elements if we have handled
183 them already. */
184 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
185 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
186 switch (*format_ptr++)
188 const char *str;
190 case 'T':
191 str = XTMPL (in_rtx, i);
192 goto string;
194 case 'S':
195 case 's':
196 str = XSTR (in_rtx, i);
197 string:
199 if (str == 0)
200 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
201 else
203 if (dump_for_graph)
204 fprintf (outfile, " (\\\"%s\\\")", str);
205 else
206 fprintf (outfile, " (\"%s\")", str);
208 sawclose = 1;
209 break;
211 /* 0 indicates a field for internal use that should not be printed.
212 An exception is the third field of a NOTE, where it indicates
213 that the field has several different valid contents. */
214 case '0':
215 if (i == 1 && REG_P (in_rtx))
217 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
218 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
220 #ifndef GENERATOR_FILE
221 else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
223 int flags = SYMBOL_REF_FLAGS (in_rtx);
224 if (flags)
225 fprintf (outfile, " [flags 0x%x]", flags);
227 else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
229 tree decl = SYMBOL_REF_DECL (in_rtx);
230 if (decl)
231 print_node_brief (outfile, "", decl, 0);
233 #endif
234 else if (i == 4 && NOTE_P (in_rtx))
236 switch (NOTE_LINE_NUMBER (in_rtx))
238 case NOTE_INSN_EH_REGION_BEG:
239 case NOTE_INSN_EH_REGION_END:
240 if (flag_dump_unnumbered)
241 fprintf (outfile, " #");
242 else
243 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
244 sawclose = 1;
245 break;
247 case NOTE_INSN_BLOCK_BEG:
248 case NOTE_INSN_BLOCK_END:
249 fprintf (outfile, " ");
250 if (flag_dump_unnumbered)
251 fprintf (outfile, "#");
252 else
253 fprintf (outfile, HOST_PTR_PRINTF,
254 (char *) NOTE_BLOCK (in_rtx));
255 sawclose = 1;
256 break;
258 case NOTE_INSN_BASIC_BLOCK:
260 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
261 if (bb != 0)
262 fprintf (outfile, " [bb %d]", bb->index);
263 break;
266 case NOTE_INSN_EXPECTED_VALUE:
267 indent += 2;
268 if (!sawclose)
269 fprintf (outfile, " ");
270 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
271 indent -= 2;
272 break;
274 case NOTE_INSN_DELETED_LABEL:
276 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
277 if (label)
278 fprintf (outfile, " (\"%s\")", label);
279 else
280 fprintf (outfile, " \"\"");
282 break;
284 case NOTE_INSN_UNLIKELY_EXECUTED_CODE:
286 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
287 if (bb != 0)
288 fprintf (outfile, " [bb %d]", bb->index);
289 break;
292 case NOTE_INSN_VAR_LOCATION:
293 fprintf (outfile, " (");
294 print_mem_expr (outfile, NOTE_VAR_LOCATION_DECL (in_rtx));
295 fprintf (outfile, " ");
296 print_rtx (NOTE_VAR_LOCATION_LOC (in_rtx));
297 fprintf (outfile, ")");
298 break;
300 default:
302 const char * const str = X0STR (in_rtx, i);
304 if (NOTE_LINE_NUMBER (in_rtx) < 0)
306 else if (str == 0)
307 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
308 else
310 if (dump_for_graph)
311 fprintf (outfile, " (\\\"%s\\\")", str);
312 else
313 fprintf (outfile, " (\"%s\")", str);
315 break;
319 break;
321 case 'e':
322 do_e:
323 indent += 2;
324 if (!sawclose)
325 fprintf (outfile, " ");
326 print_rtx (XEXP (in_rtx, i));
327 indent -= 2;
328 break;
330 case 'E':
331 case 'V':
332 indent += 2;
333 if (sawclose)
335 fprintf (outfile, "\n%s%*s",
336 print_rtx_head, indent * 2, "");
337 sawclose = 0;
339 fputs (" [", outfile);
340 if (NULL != XVEC (in_rtx, i))
342 indent += 2;
343 if (XVECLEN (in_rtx, i))
344 sawclose = 1;
346 for (j = 0; j < XVECLEN (in_rtx, i); j++)
347 print_rtx (XVECEXP (in_rtx, i, j));
349 indent -= 2;
351 if (sawclose)
352 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
354 fputs ("]", outfile);
355 sawclose = 1;
356 indent -= 2;
357 break;
359 case 'w':
360 if (! flag_simple)
361 fprintf (outfile, " ");
362 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
363 if (! flag_simple)
364 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
365 XWINT (in_rtx, i));
366 break;
368 case 'i':
369 if (i == 4 && INSN_P (in_rtx))
371 #ifndef GENERATOR_FILE
372 /* Pretty-print insn locators. Ignore scoping as it is mostly
373 redundant with line number information and do not print anything
374 when there is no location information available. */
375 if (INSN_LOCATOR (in_rtx) && insn_file (in_rtx))
376 fprintf(outfile, " %s:%i", insn_file (in_rtx), insn_line (in_rtx));
377 #endif
379 else if (i == 6 && NOTE_P (in_rtx))
381 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
382 other times often contains garbage from INSN->NOTE death. */
383 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
384 fprintf (outfile, " %d", XINT (in_rtx, i));
386 else
388 int value = XINT (in_rtx, i);
389 const char *name;
391 #ifndef GENERATOR_FILE
392 if (REG_P (in_rtx) && value < FIRST_PSEUDO_REGISTER)
393 fprintf (outfile, " %d %s", REGNO (in_rtx),
394 reg_names[REGNO (in_rtx)]);
395 else if (REG_P (in_rtx)
396 && value <= LAST_VIRTUAL_REGISTER)
398 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
399 fprintf (outfile, " %d virtual-incoming-args", value);
400 else if (value == VIRTUAL_STACK_VARS_REGNUM)
401 fprintf (outfile, " %d virtual-stack-vars", value);
402 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
403 fprintf (outfile, " %d virtual-stack-dynamic", value);
404 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
405 fprintf (outfile, " %d virtual-outgoing-args", value);
406 else if (value == VIRTUAL_CFA_REGNUM)
407 fprintf (outfile, " %d virtual-cfa", value);
408 else
409 fprintf (outfile, " %d virtual-reg-%d", value,
410 value-FIRST_VIRTUAL_REGISTER);
412 else
413 #endif
414 if (flag_dump_unnumbered
415 && (is_insn || NOTE_P (in_rtx)))
416 fputc ('#', outfile);
417 else
418 fprintf (outfile, " %d", value);
420 if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
422 fputs (" [", outfile);
423 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
424 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
425 if (REG_EXPR (in_rtx))
426 print_mem_expr (outfile, REG_EXPR (in_rtx));
428 if (REG_OFFSET (in_rtx))
429 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
430 REG_OFFSET (in_rtx));
431 fputs (" ]", outfile);
434 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
435 && XINT (in_rtx, i) >= 0
436 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
437 fprintf (outfile, " {%s}", name);
438 sawclose = 0;
440 break;
442 /* Print NOTE_INSN names rather than integer codes. */
444 case 'n':
445 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
446 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
447 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
448 else
449 fprintf (outfile, " %d", XINT (in_rtx, i));
450 sawclose = 0;
451 break;
453 case 'u':
454 if (XEXP (in_rtx, i) != NULL)
456 rtx sub = XEXP (in_rtx, i);
457 enum rtx_code subc = GET_CODE (sub);
459 if (GET_CODE (in_rtx) == LABEL_REF)
461 if (subc == NOTE
462 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
464 if (flag_dump_unnumbered)
465 fprintf (outfile, " [# deleted]");
466 else
467 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
468 sawclose = 0;
469 break;
472 if (subc != CODE_LABEL)
473 goto do_e;
476 if (flag_dump_unnumbered)
477 fputs (" #", outfile);
478 else
479 fprintf (outfile, " %d", INSN_UID (sub));
481 else
482 fputs (" 0", outfile);
483 sawclose = 0;
484 break;
486 case 'b':
487 if (XBITMAP (in_rtx, i) == NULL)
488 fputs (" {null}", outfile);
489 else
490 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
491 sawclose = 0;
492 break;
494 case 't':
495 fprintf (outfile, " " HOST_PTR_PRINTF, (void *) XTREE (in_rtx, i));
496 break;
498 case '*':
499 fputs (" Unknown", outfile);
500 sawclose = 0;
501 break;
503 case 'B':
504 if (XBBDEF (in_rtx, i))
505 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
506 break;
508 default:
509 fprintf (stderr,
510 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
511 format_ptr[-1]);
512 abort ();
515 switch (GET_CODE (in_rtx))
517 #ifndef GENERATOR_FILE
518 case MEM:
519 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
521 if (MEM_EXPR (in_rtx))
522 print_mem_expr (outfile, MEM_EXPR (in_rtx));
524 if (MEM_OFFSET (in_rtx))
525 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
526 INTVAL (MEM_OFFSET (in_rtx)));
528 if (MEM_SIZE (in_rtx))
529 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC,
530 INTVAL (MEM_SIZE (in_rtx)));
532 if (MEM_ALIGN (in_rtx) != 1)
533 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
535 fputc (']', outfile);
536 break;
538 case CONST_DOUBLE:
539 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
541 char s[60];
543 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
544 sizeof (s), 0, 1);
545 fprintf (outfile, " %s", s);
547 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
548 sizeof (s), 0, 1);
549 fprintf (outfile, " [%s]", s);
551 break;
552 #endif
554 case CODE_LABEL:
555 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
556 switch (LABEL_KIND (in_rtx))
558 case LABEL_NORMAL: break;
559 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
560 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
561 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
562 default: abort();
564 break;
566 default:
567 break;
570 if (dump_for_graph
571 && (is_insn || NOTE_P (in_rtx)
572 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
573 sawclose = 0;
574 else
576 fputc (')', outfile);
577 sawclose = 1;
581 /* Print an rtx on the current line of FILE. Initially indent IND
582 characters. */
584 void
585 print_inline_rtx (FILE *outf, rtx x, int ind)
587 int oldsaw = sawclose;
588 int oldindent = indent;
590 sawclose = 0;
591 indent = ind;
592 outfile = outf;
593 print_rtx (x);
594 sawclose = oldsaw;
595 indent = oldindent;
598 /* Call this function from the debugger to see what X looks like. */
600 void
601 debug_rtx (rtx x)
603 outfile = stderr;
604 sawclose = 0;
605 print_rtx (x);
606 fprintf (stderr, "\n");
609 /* Count of rtx's to print with debug_rtx_list.
610 This global exists because gdb user defined commands have no arguments. */
612 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
614 /* Call this function to print list from X on.
616 N is a count of the rtx's to print. Positive values print from the specified
617 rtx on. Negative values print a window around the rtx.
618 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
620 void
621 debug_rtx_list (rtx x, int n)
623 int i,count;
624 rtx insn;
626 count = n == 0 ? 1 : n < 0 ? -n : n;
628 /* If we are printing a window, back up to the start. */
630 if (n < 0)
631 for (i = count / 2; i > 0; i--)
633 if (PREV_INSN (x) == 0)
634 break;
635 x = PREV_INSN (x);
638 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
640 debug_rtx (insn);
641 fprintf (stderr, "\n");
645 /* Call this function to print an rtx list from START to END inclusive. */
647 void
648 debug_rtx_range (rtx start, rtx end)
650 while (1)
652 debug_rtx (start);
653 fprintf (stderr, "\n");
654 if (!start || start == end)
655 break;
656 start = NEXT_INSN (start);
660 /* Call this function to search an rtx list to find one with insn uid UID,
661 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
662 The found insn is returned to enable further debugging analysis. */
665 debug_rtx_find (rtx x, int uid)
667 while (x != 0 && INSN_UID (x) != uid)
668 x = NEXT_INSN (x);
669 if (x != 0)
671 debug_rtx_list (x, debug_rtx_count);
672 return x;
674 else
676 fprintf (stderr, "insn uid %d not found\n", uid);
677 return 0;
681 /* External entry point for printing a chain of insns
682 starting with RTX_FIRST onto file OUTF.
683 A blank line separates insns.
685 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
687 void
688 print_rtl (FILE *outf, rtx rtx_first)
690 rtx tmp_rtx;
692 outfile = outf;
693 sawclose = 0;
695 if (rtx_first == 0)
697 fputs (print_rtx_head, outf);
698 fputs ("(nil)\n", outf);
700 else
701 switch (GET_CODE (rtx_first))
703 case INSN:
704 case JUMP_INSN:
705 case CALL_INSN:
706 case NOTE:
707 case CODE_LABEL:
708 case BARRIER:
709 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
710 if (! flag_dump_unnumbered
711 || !NOTE_P (tmp_rtx) || NOTE_LINE_NUMBER (tmp_rtx) < 0)
713 fputs (print_rtx_head, outfile);
714 print_rtx (tmp_rtx);
715 fprintf (outfile, "\n");
717 break;
719 default:
720 fputs (print_rtx_head, outfile);
721 print_rtx (rtx_first);
725 /* Like print_rtx, except specify a file. */
726 /* Return nonzero if we actually printed anything. */
729 print_rtl_single (FILE *outf, rtx x)
731 outfile = outf;
732 sawclose = 0;
733 if (! flag_dump_unnumbered
734 || !NOTE_P (x) || NOTE_LINE_NUMBER (x) < 0)
736 fputs (print_rtx_head, outfile);
737 print_rtx (x);
738 putc ('\n', outf);
739 return 1;
741 return 0;
745 /* Like print_rtl except without all the detail; for example,
746 if RTX is a CONST_INT then print in decimal format. */
748 void
749 print_simple_rtl (FILE *outf, rtx x)
751 flag_simple = 1;
752 print_rtl (outf, x);
753 flag_simple = 0;