1 /* Print RTL for GNU C Compiler.
2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003
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"
38 /* How to print out a register name.
39 We don't use PRINT_REG because some definitions of PRINT_REG
41 #ifndef DEBUG_PRINT_REG
42 #define DEBUG_PRINT_REG(RTX, CODE, FILE) \
43 fprintf ((FILE), "%d %s", REGNO (RTX), reg_names[REGNO (RTX)])
46 /* Array containing all of the register names */
48 #ifdef DEBUG_REGISTER_NAMES
49 static const char * const debug_reg_names[] = DEBUG_REGISTER_NAMES;
50 #define reg_names debug_reg_names
52 const char * reg_names[] = REGISTER_NAMES;
57 static int sawclose = 0;
61 static void print_rtx PARAMS ((rtx));
63 /* String printed at beginning of each RTL when it is dumped.
64 This string is set to ASM_COMMENT_START when the RTL is dumped in
65 the assembly output file. */
66 const char *print_rtx_head = "";
68 /* Nonzero means suppress output of instruction numbers and line number
69 notes in debugging dumps.
70 This must be defined here so that programs like gencodes can be linked. */
71 int flag_dump_unnumbered = 0;
73 /* Nonzero means use simplified format without flags, modes, etc. */
76 /* Nonzero if we are dumping graphical description. */
79 /* Nonzero to dump all call_placeholder alternatives. */
80 static int debug_call_placeholder_verbose;
83 print_mem_expr (outfile, expr)
87 if (TREE_CODE (expr) == COMPONENT_REF)
89 if (TREE_OPERAND (expr, 0))
90 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
92 fputs (" <variable>", outfile);
93 if (DECL_NAME (TREE_OPERAND (expr, 1)))
94 fprintf (outfile, ".%s",
95 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (expr, 1))));
97 else if (TREE_CODE (expr) == INDIRECT_REF)
99 fputs (" (*", outfile);
100 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
101 fputs (")", outfile);
103 else if (DECL_NAME (expr))
104 fprintf (outfile, " %s", IDENTIFIER_POINTER (DECL_NAME (expr)));
105 else if (TREE_CODE (expr) == RESULT_DECL)
106 fputs (" <result>", outfile);
108 fputs (" <anonymous>", outfile);
111 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
119 const char *format_ptr;
126 fputc (' ', outfile);
128 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
134 fputs ("(nil)", outfile);
138 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
140 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
145 is_insn = INSN_P (in_rtx);
147 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
148 in separate nodes and therefore have to handle them special here. */
150 && (is_insn || GET_CODE (in_rtx) == NOTE
151 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
158 /* Print name of expression code. */
159 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
160 fputc ('(', outfile);
162 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
166 if (RTX_FLAG (in_rtx, in_struct))
167 fputs ("/s", outfile);
169 if (RTX_FLAG (in_rtx, volatil))
170 fputs ("/v", outfile);
172 if (RTX_FLAG (in_rtx, unchanging))
173 fputs ("/u", outfile);
175 if (RTX_FLAG (in_rtx, integrated))
176 fputs ("/i", outfile);
178 if (RTX_FLAG (in_rtx, frame_related))
179 fputs ("/f", outfile);
181 if (RTX_FLAG (in_rtx, jump))
182 fputs ("/j", outfile);
184 if (RTX_FLAG (in_rtx, call))
185 fputs ("/c", outfile);
187 if (GET_MODE (in_rtx) != VOIDmode)
189 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
190 if (GET_CODE (in_rtx) == EXPR_LIST
191 || GET_CODE (in_rtx) == INSN_LIST)
192 fprintf (outfile, ":%s",
193 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
195 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
200 #ifndef GENERATOR_FILE
201 if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
205 /* Get the format string and skip the first elements if we have handled
207 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
208 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
209 switch (*format_ptr++)
214 str = XTMPL (in_rtx, i);
219 str = XSTR (in_rtx, i);
223 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
227 fprintf (outfile, " (\\\"%s\\\")", str);
229 fprintf (outfile, " (\"%s\")", str);
234 /* 0 indicates a field for internal use that should not be printed.
235 An exception is the third field of a NOTE, where it indicates
236 that the field has several different valid contents. */
238 if (i == 1 && GET_CODE (in_rtx) == REG)
240 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
241 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
244 if (i == 4 && GET_CODE (in_rtx) == NOTE)
246 switch (NOTE_LINE_NUMBER (in_rtx))
248 case NOTE_INSN_EH_REGION_BEG:
249 case NOTE_INSN_EH_REGION_END:
250 if (flag_dump_unnumbered)
251 fprintf (outfile, " #");
253 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
257 case NOTE_INSN_BLOCK_BEG:
258 case NOTE_INSN_BLOCK_END:
259 fprintf (outfile, " ");
260 if (flag_dump_unnumbered)
261 fprintf (outfile, "#");
263 fprintf (outfile, HOST_PTR_PRINTF,
264 (char *) NOTE_BLOCK (in_rtx));
268 case NOTE_INSN_BASIC_BLOCK:
270 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
272 fprintf (outfile, " [bb %d]", bb->index);
276 case NOTE_INSN_EXPECTED_VALUE:
279 fprintf (outfile, " ");
280 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
284 case NOTE_INSN_DELETED_LABEL:
285 if (NOTE_SOURCE_FILE (in_rtx))
286 fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
288 fprintf (outfile, " \"\"");
291 case NOTE_INSN_PREDICTION:
292 if (NOTE_PREDICTION (in_rtx))
293 fprintf (outfile, " [ %d %d ] ",
294 (int)NOTE_PREDICTION_ALG (in_rtx),
295 (int) NOTE_PREDICTION_FLAGS (in_rtx));
297 fprintf (outfile, " [ ERROR ]");
302 const char * const str = X0STR (in_rtx, i);
304 if (NOTE_LINE_NUMBER (in_rtx) < 0)
307 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
311 fprintf (outfile, " (\\\"%s\\\")", str);
313 fprintf (outfile, " (\"%s\")", str);
325 fprintf (outfile, " ");
326 print_rtx (XEXP (in_rtx, i));
335 fprintf (outfile, "\n%s%*s",
336 print_rtx_head, indent * 2, "");
339 fputs (" [", outfile);
340 if (NULL != XVEC (in_rtx, i))
343 if (XVECLEN (in_rtx, i))
346 for (j = 0; j < XVECLEN (in_rtx, i); j++)
347 print_rtx (XVECEXP (in_rtx, i, j));
352 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
354 fputs ("]", outfile);
361 fprintf (outfile, " ");
362 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
365 fprintf (outfile, " [");
366 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
367 fprintf (outfile, "]");
372 if (i == 6 && GET_CODE (in_rtx) == NOTE)
374 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
375 other times often contains garbage from INSN->NOTE death. */
376 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
377 fprintf (outfile, " %d", XINT (in_rtx, i));
381 int value = XINT (in_rtx, i);
384 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
386 fputc (' ', outfile);
387 DEBUG_PRINT_REG (in_rtx, 0, outfile);
389 else if (GET_CODE (in_rtx) == REG
390 && value <= LAST_VIRTUAL_REGISTER)
392 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
393 fprintf (outfile, " %d virtual-incoming-args", value);
394 else if (value == VIRTUAL_STACK_VARS_REGNUM)
395 fprintf (outfile, " %d virtual-stack-vars", value);
396 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
397 fprintf (outfile, " %d virtual-stack-dynamic", value);
398 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
399 fprintf (outfile, " %d virtual-outgoing-args", value);
400 else if (value == VIRTUAL_CFA_REGNUM)
401 fprintf (outfile, " %d virtual-cfa", value);
403 fprintf (outfile, " %d virtual-reg-%d", value,
404 value-FIRST_VIRTUAL_REGISTER);
406 else if (flag_dump_unnumbered
407 && (is_insn || GET_CODE (in_rtx) == NOTE))
408 fputc ('#', outfile);
410 fprintf (outfile, " %d", value);
412 if (GET_CODE (in_rtx) == REG && REG_ATTRS (in_rtx))
414 fputs (" [", outfile);
415 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
416 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
417 if (REG_EXPR (in_rtx))
418 print_mem_expr (outfile, REG_EXPR (in_rtx));
420 if (REG_OFFSET (in_rtx))
422 fputc ('+', outfile);
423 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
424 REG_OFFSET (in_rtx));
426 fputs (" ]", outfile);
429 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
430 && XINT (in_rtx, i) >= 0
431 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
432 fprintf (outfile, " {%s}", name);
437 /* Print NOTE_INSN names rather than integer codes. */
440 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
441 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
442 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
444 fprintf (outfile, " %d", XINT (in_rtx, i));
449 if (XEXP (in_rtx, i) != NULL)
451 rtx sub = XEXP (in_rtx, i);
452 enum rtx_code subc = GET_CODE (sub);
454 if (GET_CODE (in_rtx) == LABEL_REF)
457 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
459 if (flag_dump_unnumbered)
460 fprintf (outfile, " [# deleted]");
462 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
467 if (subc != CODE_LABEL)
471 if (flag_dump_unnumbered)
472 fputs (" #", outfile);
474 fprintf (outfile, " %d", INSN_UID (sub));
477 fputs (" 0", outfile);
482 if (XBITMAP (in_rtx, i) == NULL)
483 fputs (" {null}", outfile);
485 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
491 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
495 fputs (" Unknown", outfile);
500 if (XBBDEF (in_rtx, i))
501 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
506 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
511 switch (GET_CODE (in_rtx))
513 #ifndef GENERATOR_FILE
515 fputs (" [", outfile);
516 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
518 if (MEM_EXPR (in_rtx))
519 print_mem_expr (outfile, MEM_EXPR (in_rtx));
521 if (MEM_OFFSET (in_rtx))
523 fputc ('+', outfile);
524 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
525 INTVAL (MEM_OFFSET (in_rtx)));
528 if (MEM_SIZE (in_rtx))
530 fputs (" S", outfile);
531 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
532 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;
569 case CALL_PLACEHOLDER:
570 if (debug_call_placeholder_verbose)
572 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile);
573 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
575 fputs ("\n ", outfile);
576 print_inline_rtx (outfile, tem, 4);
579 tem = XEXP (in_rtx, 1);
581 fputs ("\n ])\n (const_string \"tail_call\") (sequence [",
583 for (; tem != 0; tem = NEXT_INSN (tem))
585 fputs ("\n ", outfile);
586 print_inline_rtx (outfile, tem, 4);
589 tem = XEXP (in_rtx, 2);
591 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [",
593 for (; tem != 0; tem = NEXT_INSN (tem))
595 fputs ("\n ", outfile);
596 print_inline_rtx (outfile, tem, 4);
599 fputs ("\n ])\n ])", outfile);
603 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
604 if (GET_CODE (tem) == CALL_INSN)
606 fprintf (outfile, " ");
617 && (is_insn || GET_CODE (in_rtx) == NOTE
618 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
622 fputc (')', outfile);
627 /* Print an rtx on the current line of FILE. Initially indent IND
631 print_inline_rtx (outf, x, ind)
636 int oldsaw = sawclose;
637 int oldindent = indent;
647 /* Call this function from the debugger to see what X looks like. */
656 fprintf (stderr, "\n");
659 /* Count of rtx's to print with debug_rtx_list.
660 This global exists because gdb user defined commands have no arguments. */
662 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
664 /* Call this function to print list from X on.
666 N is a count of the rtx's to print. Positive values print from the specified
667 rtx on. Negative values print a window around the rtx.
668 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
671 debug_rtx_list (x, n)
678 count = n == 0 ? 1 : n < 0 ? -n : n;
680 /* If we are printing a window, back up to the start. */
683 for (i = count / 2; i > 0; i--)
685 if (PREV_INSN (x) == 0)
690 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
693 fprintf (stderr, "\n");
697 /* Call this function to print an rtx list from START to END inclusive. */
700 debug_rtx_range (start, end)
706 fprintf (stderr, "\n");
707 if (!start || start == end)
709 start = NEXT_INSN (start);
713 /* Call this function to search an rtx list to find one with insn uid UID,
714 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
715 The found insn is returned to enable further debugging analysis. */
718 debug_rtx_find (x, uid)
722 while (x != 0 && INSN_UID (x) != uid)
726 debug_rtx_list (x, debug_rtx_count);
731 fprintf (stderr, "insn uid %d not found\n", uid);
736 /* External entry point for printing a chain of insns
737 starting with RTX_FIRST onto file OUTF.
738 A blank line separates insns.
740 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
743 print_rtl (outf, rtx_first)
754 fputs (print_rtx_head, outf);
755 fputs ("(nil)\n", outf);
758 switch (GET_CODE (rtx_first))
766 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
767 if (! flag_dump_unnumbered
768 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
770 fputs (print_rtx_head, outfile);
772 fprintf (outfile, "\n");
777 fputs (print_rtx_head, outfile);
778 print_rtx (rtx_first);
782 /* Like print_rtx, except specify a file. */
783 /* Return nonzero if we actually printed anything. */
786 print_rtl_single (outf, x)
792 if (! flag_dump_unnumbered
793 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
795 fputs (print_rtx_head, outfile);
804 /* Like print_rtl except without all the detail; for example,
805 if RTX is a CONST_INT then print in decimal format. */
808 print_simple_rtl (outf, x)