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
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
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
25 #include "coretypes.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
35 #include "hard-reg-set.h"
36 #include "basic-block.h"
40 static int sawclose = 0;
44 static void print_rtx (rtx);
46 /* String printed at beginning of each RTL when it is dumped.
47 This string is set to ASM_COMMENT_START when the RTL is dumped in
48 the assembly output file. */
49 const char *print_rtx_head = "";
51 /* Nonzero means suppress output of instruction numbers and line number
52 notes in debugging dumps.
53 This must be defined here so that programs like gencodes can be linked. */
54 int flag_dump_unnumbered = 0;
56 /* Nonzero means use simplified format without flags, modes, etc. */
59 /* Nonzero if we are dumping graphical description. */
63 print_mem_expr (FILE *outfile, tree expr)
65 if (TREE_CODE (expr) == COMPONENT_REF)
67 if (TREE_OPERAND (expr, 0))
68 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
70 fputs (" <variable>", outfile);
71 if (DECL_NAME (TREE_OPERAND (expr, 1)))
72 fprintf (outfile, ".%s",
73 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (expr, 1))));
75 else if (TREE_CODE (expr) == INDIRECT_REF)
77 fputs (" (*", outfile);
78 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
81 else if (DECL_NAME (expr))
82 fprintf (outfile, " %s", IDENTIFIER_POINTER (DECL_NAME (expr)));
83 else if (TREE_CODE (expr) == RESULT_DECL)
84 fputs (" <result>", outfile);
86 fputs (" <anonymous>", outfile);
89 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
92 print_rtx (rtx in_rtx)
96 const char *format_ptr;
102 fputc (' ', outfile);
104 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
110 fputs ("(nil)", outfile);
114 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
116 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
121 is_insn = INSN_P (in_rtx);
123 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
124 in separate nodes and therefore have to handle them special here. */
126 && (is_insn || NOTE_P (in_rtx)
127 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
134 /* Print name of expression code. */
135 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
136 fputc ('(', outfile);
138 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
142 if (RTX_FLAG (in_rtx, in_struct))
143 fputs ("/s", outfile);
145 if (RTX_FLAG (in_rtx, volatil))
146 fputs ("/v", outfile);
148 if (RTX_FLAG (in_rtx, unchanging))
149 fputs ("/u", outfile);
151 if (RTX_FLAG (in_rtx, frame_related))
152 fputs ("/f", outfile);
154 if (RTX_FLAG (in_rtx, jump))
155 fputs ("/j", outfile);
157 if (RTX_FLAG (in_rtx, call))
158 fputs ("/c", outfile);
160 if (RTX_FLAG (in_rtx, return_val))
161 fputs ("/i", outfile);
163 if (GET_MODE (in_rtx) != VOIDmode)
165 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
166 if (GET_CODE (in_rtx) == EXPR_LIST
167 || GET_CODE (in_rtx) == INSN_LIST)
168 fprintf (outfile, ":%s",
169 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
171 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
176 #ifndef GENERATOR_FILE
177 if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
181 /* Get the format string and skip the first elements if we have handled
183 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
184 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
185 switch (*format_ptr++)
190 str = XTMPL (in_rtx, i);
195 str = XSTR (in_rtx, i);
199 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
203 fprintf (outfile, " (\\\"%s\\\")", str);
205 fprintf (outfile, " (\"%s\")", str);
210 /* 0 indicates a field for internal use that should not be printed.
211 An exception is the third field of a NOTE, where it indicates
212 that the field has several different valid contents. */
214 if (i == 1 && REG_P (in_rtx))
216 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
217 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
219 #ifndef GENERATOR_FILE
220 else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
222 int flags = SYMBOL_REF_FLAGS (in_rtx);
224 fprintf (outfile, " [flags 0x%x]", flags);
226 else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
228 tree decl = SYMBOL_REF_DECL (in_rtx);
230 print_node_brief (outfile, "", decl, 0);
233 else if (i == 4 && NOTE_P (in_rtx))
235 switch (NOTE_LINE_NUMBER (in_rtx))
237 case NOTE_INSN_EH_REGION_BEG:
238 case NOTE_INSN_EH_REGION_END:
239 if (flag_dump_unnumbered)
240 fprintf (outfile, " #");
242 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
246 case NOTE_INSN_BLOCK_BEG:
247 case NOTE_INSN_BLOCK_END:
248 fprintf (outfile, " ");
249 if (flag_dump_unnumbered)
250 fprintf (outfile, "#");
252 fprintf (outfile, HOST_PTR_PRINTF,
253 (char *) NOTE_BLOCK (in_rtx));
257 case NOTE_INSN_BASIC_BLOCK:
259 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
261 fprintf (outfile, " [bb %d]", bb->index);
265 case NOTE_INSN_EXPECTED_VALUE:
268 fprintf (outfile, " ");
269 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
273 case NOTE_INSN_DELETED_LABEL:
275 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
277 fprintf (outfile, " (\"%s\")", label);
279 fprintf (outfile, " \"\"");
283 case NOTE_INSN_UNLIKELY_EXECUTED_CODE:
285 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
287 fprintf (outfile, " [bb %d]", bb->index);
291 case NOTE_INSN_VAR_LOCATION:
292 fprintf (outfile, " (");
293 print_mem_expr (outfile, NOTE_VAR_LOCATION_DECL (in_rtx));
294 fprintf (outfile, " ");
295 print_rtx (NOTE_VAR_LOCATION_LOC (in_rtx));
296 fprintf (outfile, ")");
301 const char * const str = X0STR (in_rtx, i);
303 if (NOTE_LINE_NUMBER (in_rtx) < 0)
306 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
310 fprintf (outfile, " (\\\"%s\\\")", str);
312 fprintf (outfile, " (\"%s\")", str);
324 fprintf (outfile, " ");
325 print_rtx (XEXP (in_rtx, i));
334 fprintf (outfile, "\n%s%*s",
335 print_rtx_head, indent * 2, "");
338 fputs (" [", outfile);
339 if (NULL != XVEC (in_rtx, i))
342 if (XVECLEN (in_rtx, i))
345 for (j = 0; j < XVECLEN (in_rtx, i); j++)
346 print_rtx (XVECEXP (in_rtx, i, j));
351 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
353 fputs ("]", outfile);
360 fprintf (outfile, " ");
361 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
363 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
368 if (i == 4 && INSN_P (in_rtx))
370 #ifndef GENERATOR_FILE
371 /* Pretty-print insn locators. Ignore scoping as it is mostly
372 redundant with line number information and do not print anything
373 when there is no location information available. */
374 if (INSN_LOCATOR (in_rtx) && insn_file (in_rtx))
375 fprintf(outfile, " %s:%i", insn_file (in_rtx), insn_line (in_rtx));
378 else if (i == 6 && NOTE_P (in_rtx))
380 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
381 other times often contains garbage from INSN->NOTE death. */
382 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
383 fprintf (outfile, " %d", XINT (in_rtx, i));
387 int value = XINT (in_rtx, i);
390 #ifndef GENERATOR_FILE
391 if (REG_P (in_rtx) && value < FIRST_PSEUDO_REGISTER)
392 fprintf (outfile, " %d %s", REGNO (in_rtx),
393 reg_names[REGNO (in_rtx)]);
394 else if (REG_P (in_rtx)
395 && value <= LAST_VIRTUAL_REGISTER)
397 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
398 fprintf (outfile, " %d virtual-incoming-args", value);
399 else if (value == VIRTUAL_STACK_VARS_REGNUM)
400 fprintf (outfile, " %d virtual-stack-vars", value);
401 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
402 fprintf (outfile, " %d virtual-stack-dynamic", value);
403 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
404 fprintf (outfile, " %d virtual-outgoing-args", value);
405 else if (value == VIRTUAL_CFA_REGNUM)
406 fprintf (outfile, " %d virtual-cfa", value);
408 fprintf (outfile, " %d virtual-reg-%d", value,
409 value-FIRST_VIRTUAL_REGISTER);
413 if (flag_dump_unnumbered
414 && (is_insn || NOTE_P (in_rtx)))
415 fputc ('#', outfile);
417 fprintf (outfile, " %d", value);
419 if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
421 fputs (" [", outfile);
422 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
423 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
424 if (REG_EXPR (in_rtx))
425 print_mem_expr (outfile, REG_EXPR (in_rtx));
427 if (REG_OFFSET (in_rtx))
428 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
429 REG_OFFSET (in_rtx));
430 fputs (" ]", outfile);
433 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
434 && XINT (in_rtx, i) >= 0
435 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
436 fprintf (outfile, " {%s}", name);
441 /* Print NOTE_INSN names rather than integer codes. */
444 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
445 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
446 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
448 fprintf (outfile, " %d", XINT (in_rtx, i));
453 if (XEXP (in_rtx, i) != NULL)
455 rtx sub = XEXP (in_rtx, i);
456 enum rtx_code subc = GET_CODE (sub);
458 if (GET_CODE (in_rtx) == LABEL_REF)
461 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
463 if (flag_dump_unnumbered)
464 fprintf (outfile, " [# deleted]");
466 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
471 if (subc != CODE_LABEL)
475 if (flag_dump_unnumbered)
476 fputs (" #", outfile);
478 fprintf (outfile, " %d", INSN_UID (sub));
481 fputs (" 0", outfile);
486 #ifdef GENERATOR_FILE
487 fputs (" {bitmap}", outfile);
489 if (XBITMAP (in_rtx, i) == NULL)
490 fputs (" {null}", outfile);
492 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
498 fprintf (outfile, " " HOST_PTR_PRINTF, (void *) XTREE (in_rtx, i));
502 fputs (" Unknown", outfile);
507 if (XBBDEF (in_rtx, i))
508 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
513 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
518 switch (GET_CODE (in_rtx))
520 #ifndef GENERATOR_FILE
522 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
524 if (MEM_EXPR (in_rtx))
525 print_mem_expr (outfile, MEM_EXPR (in_rtx));
527 if (MEM_OFFSET (in_rtx))
528 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
529 INTVAL (MEM_OFFSET (in_rtx)));
531 if (MEM_SIZE (in_rtx))
532 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC,
533 INTVAL (MEM_SIZE (in_rtx)));
535 if (MEM_ALIGN (in_rtx) != 1)
536 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
538 fputc (']', outfile);
542 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
546 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
548 fprintf (outfile, " %s", s);
550 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
552 fprintf (outfile, " [%s]", s);
558 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
559 switch (LABEL_KIND (in_rtx))
561 case LABEL_NORMAL: break;
562 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
563 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
564 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
574 && (is_insn || NOTE_P (in_rtx)
575 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
579 fputc (')', outfile);
584 /* Print an rtx on the current line of FILE. Initially indent IND
588 print_inline_rtx (FILE *outf, rtx x, int ind)
590 int oldsaw = sawclose;
591 int oldindent = indent;
601 /* Call this function from the debugger to see what X looks like. */
609 fprintf (stderr, "\n");
612 /* Count of rtx's to print with debug_rtx_list.
613 This global exists because gdb user defined commands have no arguments. */
615 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
617 /* Call this function to print list from X on.
619 N is a count of the rtx's to print. Positive values print from the specified
620 rtx on. Negative values print a window around the rtx.
621 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
624 debug_rtx_list (rtx x, int n)
629 count = n == 0 ? 1 : n < 0 ? -n : n;
631 /* If we are printing a window, back up to the start. */
634 for (i = count / 2; i > 0; i--)
636 if (PREV_INSN (x) == 0)
641 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
644 fprintf (stderr, "\n");
648 /* Call this function to print an rtx list from START to END inclusive. */
651 debug_rtx_range (rtx start, rtx end)
656 fprintf (stderr, "\n");
657 if (!start || start == end)
659 start = NEXT_INSN (start);
663 /* Call this function to search an rtx list to find one with insn uid UID,
664 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
665 The found insn is returned to enable further debugging analysis. */
668 debug_rtx_find (rtx x, int uid)
670 while (x != 0 && INSN_UID (x) != uid)
674 debug_rtx_list (x, debug_rtx_count);
679 fprintf (stderr, "insn uid %d not found\n", uid);
684 /* External entry point for printing a chain of insns
685 starting with RTX_FIRST onto file OUTF.
686 A blank line separates insns.
688 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
691 print_rtl (FILE *outf, rtx rtx_first)
700 fputs (print_rtx_head, outf);
701 fputs ("(nil)\n", outf);
704 switch (GET_CODE (rtx_first))
712 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
713 if (! flag_dump_unnumbered
714 || !NOTE_P (tmp_rtx) || NOTE_LINE_NUMBER (tmp_rtx) < 0)
716 fputs (print_rtx_head, outfile);
718 fprintf (outfile, "\n");
723 fputs (print_rtx_head, outfile);
724 print_rtx (rtx_first);
728 /* Like print_rtx, except specify a file. */
729 /* Return nonzero if we actually printed anything. */
732 print_rtl_single (FILE *outf, rtx x)
736 if (! flag_dump_unnumbered
737 || !NOTE_P (x) || NOTE_LINE_NUMBER (x) < 0)
739 fputs (print_rtx_head, outfile);
748 /* Like print_rtl except without all the detail; for example,
749 if RTX is a CONST_INT then print in decimal format. */
752 print_simple_rtl (FILE *outf, rtx x)