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"
41 static int sawclose = 0;
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. */
60 /* Nonzero if we are dumping graphical description. */
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));
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));
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);
87 fputs (" <anonymous>", outfile);
90 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
93 print_rtx (rtx in_rtx)
97 const char *format_ptr;
103 fputc (' ', outfile);
105 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
111 fputs ("(nil)", outfile);
115 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
117 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
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. */
127 && (is_insn || NOTE_P (in_rtx)
128 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
135 /* Print name of expression code. */
136 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
137 fputc ('(', outfile);
139 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
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)));
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)))
182 /* Get the format string and skip the first elements if we have handled
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++)
191 str = XTMPL (in_rtx, i);
196 str = XSTR (in_rtx, i);
200 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
204 fprintf (outfile, " (\\\"%s\\\")", str);
206 fprintf (outfile, " (\"%s\")", str);
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. */
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);
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);
231 print_node_brief (outfile, "", decl, 0);
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, " #");
243 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
247 case NOTE_INSN_BLOCK_BEG:
248 case NOTE_INSN_BLOCK_END:
249 fprintf (outfile, " ");
250 if (flag_dump_unnumbered)
251 fprintf (outfile, "#");
253 fprintf (outfile, HOST_PTR_PRINTF,
254 (char *) NOTE_BLOCK (in_rtx));
258 case NOTE_INSN_BASIC_BLOCK:
260 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
262 fprintf (outfile, " [bb %d]", bb->index);
266 case NOTE_INSN_EXPECTED_VALUE:
269 fprintf (outfile, " ");
270 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
274 case NOTE_INSN_DELETED_LABEL:
276 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
278 fprintf (outfile, " (\"%s\")", label);
280 fprintf (outfile, " \"\"");
284 case NOTE_INSN_PREDICTION:
285 if (NOTE_PREDICTION (in_rtx))
286 fprintf (outfile, " [ %d %d ] ",
287 (int)NOTE_PREDICTION_ALG (in_rtx),
288 (int) NOTE_PREDICTION_FLAGS (in_rtx));
290 fprintf (outfile, " [ ERROR ]");
293 case NOTE_INSN_UNLIKELY_EXECUTED_CODE:
295 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
297 fprintf (outfile, " [bb %d]", bb->index);
301 case NOTE_INSN_VAR_LOCATION:
302 fprintf (outfile, " (");
303 print_mem_expr (outfile, NOTE_VAR_LOCATION_DECL (in_rtx));
304 fprintf (outfile, " ");
305 print_rtx (NOTE_VAR_LOCATION_LOC (in_rtx));
306 fprintf (outfile, ")");
311 const char * const str = X0STR (in_rtx, i);
313 if (NOTE_LINE_NUMBER (in_rtx) < 0)
316 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
320 fprintf (outfile, " (\\\"%s\\\")", str);
322 fprintf (outfile, " (\"%s\")", str);
334 fprintf (outfile, " ");
335 print_rtx (XEXP (in_rtx, i));
344 fprintf (outfile, "\n%s%*s",
345 print_rtx_head, indent * 2, "");
348 fputs (" [", outfile);
349 if (NULL != XVEC (in_rtx, i))
352 if (XVECLEN (in_rtx, i))
355 for (j = 0; j < XVECLEN (in_rtx, i); j++)
356 print_rtx (XVECEXP (in_rtx, i, j));
361 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
363 fputs ("]", outfile);
370 fprintf (outfile, " ");
371 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
373 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
378 if (i == 4 && INSN_P (in_rtx))
380 #ifndef GENERATOR_FILE
381 /* Pretty-print insn locators. Ignore scoping as it is mostly
382 redundant with line number information and do not print anything
383 when there is no location information available. */
384 if (INSN_LOCATOR (in_rtx) && insn_file (in_rtx))
385 fprintf(outfile, " %s:%i", insn_file (in_rtx), insn_line (in_rtx));
388 else if (i == 6 && NOTE_P (in_rtx))
390 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
391 other times often contains garbage from INSN->NOTE death. */
392 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
393 fprintf (outfile, " %d", XINT (in_rtx, i));
397 int value = XINT (in_rtx, i);
400 #ifndef GENERATOR_FILE
401 if (REG_P (in_rtx) && value < FIRST_PSEUDO_REGISTER)
402 fprintf (outfile, " %d %s", REGNO (in_rtx),
403 reg_names[REGNO (in_rtx)]);
404 else if (REG_P (in_rtx)
405 && value <= LAST_VIRTUAL_REGISTER)
407 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
408 fprintf (outfile, " %d virtual-incoming-args", value);
409 else if (value == VIRTUAL_STACK_VARS_REGNUM)
410 fprintf (outfile, " %d virtual-stack-vars", value);
411 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
412 fprintf (outfile, " %d virtual-stack-dynamic", value);
413 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
414 fprintf (outfile, " %d virtual-outgoing-args", value);
415 else if (value == VIRTUAL_CFA_REGNUM)
416 fprintf (outfile, " %d virtual-cfa", value);
418 fprintf (outfile, " %d virtual-reg-%d", value,
419 value-FIRST_VIRTUAL_REGISTER);
423 if (flag_dump_unnumbered
424 && (is_insn || NOTE_P (in_rtx)))
425 fputc ('#', outfile);
427 fprintf (outfile, " %d", value);
429 if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
431 fputs (" [", outfile);
432 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
433 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
434 if (REG_EXPR (in_rtx))
435 print_mem_expr (outfile, REG_EXPR (in_rtx));
437 if (REG_OFFSET (in_rtx))
438 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
439 REG_OFFSET (in_rtx));
440 fputs (" ]", outfile);
443 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
444 && XINT (in_rtx, i) >= 0
445 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
446 fprintf (outfile, " {%s}", name);
451 /* Print NOTE_INSN names rather than integer codes. */
454 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
455 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
456 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
458 fprintf (outfile, " %d", XINT (in_rtx, i));
463 if (XEXP (in_rtx, i) != NULL)
465 rtx sub = XEXP (in_rtx, i);
466 enum rtx_code subc = GET_CODE (sub);
468 if (GET_CODE (in_rtx) == LABEL_REF)
471 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
473 if (flag_dump_unnumbered)
474 fprintf (outfile, " [# deleted]");
476 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
481 if (subc != CODE_LABEL)
485 if (flag_dump_unnumbered)
486 fputs (" #", outfile);
488 fprintf (outfile, " %d", INSN_UID (sub));
491 fputs (" 0", outfile);
496 if (XBITMAP (in_rtx, i) == NULL)
497 fputs (" {null}", outfile);
499 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
504 fprintf (outfile, " " HOST_PTR_PRINTF, (void *) XTREE (in_rtx, i));
508 fputs (" Unknown", outfile);
513 if (XBBDEF (in_rtx, i))
514 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
519 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
524 switch (GET_CODE (in_rtx))
526 #ifndef GENERATOR_FILE
528 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
530 if (MEM_EXPR (in_rtx))
531 print_mem_expr (outfile, MEM_EXPR (in_rtx));
533 if (MEM_OFFSET (in_rtx))
534 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
535 INTVAL (MEM_OFFSET (in_rtx)));
537 if (MEM_SIZE (in_rtx))
538 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC,
539 INTVAL (MEM_SIZE (in_rtx)));
541 if (MEM_ALIGN (in_rtx) != 1)
542 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
544 fputc (']', outfile);
548 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
552 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
554 fprintf (outfile, " %s", s);
556 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
558 fprintf (outfile, " [%s]", s);
564 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
565 switch (LABEL_KIND (in_rtx))
567 case LABEL_NORMAL: break;
568 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
569 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
570 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
580 && (is_insn || NOTE_P (in_rtx)
581 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
585 fputc (')', outfile);
590 /* Print an rtx on the current line of FILE. Initially indent IND
594 print_inline_rtx (FILE *outf, rtx x, int ind)
596 int oldsaw = sawclose;
597 int oldindent = indent;
607 /* Call this function from the debugger to see what X looks like. */
615 fprintf (stderr, "\n");
618 /* Count of rtx's to print with debug_rtx_list.
619 This global exists because gdb user defined commands have no arguments. */
621 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
623 /* Call this function to print list from X on.
625 N is a count of the rtx's to print. Positive values print from the specified
626 rtx on. Negative values print a window around the rtx.
627 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
630 debug_rtx_list (rtx x, int n)
635 count = n == 0 ? 1 : n < 0 ? -n : n;
637 /* If we are printing a window, back up to the start. */
640 for (i = count / 2; i > 0; i--)
642 if (PREV_INSN (x) == 0)
647 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
650 fprintf (stderr, "\n");
654 /* Call this function to print an rtx list from START to END inclusive. */
657 debug_rtx_range (rtx start, rtx end)
662 fprintf (stderr, "\n");
663 if (!start || start == end)
665 start = NEXT_INSN (start);
669 /* Call this function to search an rtx list to find one with insn uid UID,
670 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
671 The found insn is returned to enable further debugging analysis. */
674 debug_rtx_find (rtx x, int uid)
676 while (x != 0 && INSN_UID (x) != uid)
680 debug_rtx_list (x, debug_rtx_count);
685 fprintf (stderr, "insn uid %d not found\n", uid);
690 /* External entry point for printing a chain of insns
691 starting with RTX_FIRST onto file OUTF.
692 A blank line separates insns.
694 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
697 print_rtl (FILE *outf, rtx rtx_first)
706 fputs (print_rtx_head, outf);
707 fputs ("(nil)\n", outf);
710 switch (GET_CODE (rtx_first))
718 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
719 if (! flag_dump_unnumbered
720 || !NOTE_P (tmp_rtx) || NOTE_LINE_NUMBER (tmp_rtx) < 0)
722 fputs (print_rtx_head, outfile);
724 fprintf (outfile, "\n");
729 fputs (print_rtx_head, outfile);
730 print_rtx (rtx_first);
734 /* Like print_rtx, except specify a file. */
735 /* Return nonzero if we actually printed anything. */
738 print_rtl_single (FILE *outf, rtx x)
742 if (! flag_dump_unnumbered
743 || !NOTE_P (x) || NOTE_LINE_NUMBER (x) < 0)
745 fputs (print_rtx_head, outfile);
754 /* Like print_rtl except without all the detail; for example,
755 if RTX is a CONST_INT then print in decimal format. */
758 print_simple_rtl (FILE *outf, rtx x)