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 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
27 /* We don't want the tree code checking code for the access to the
28 DECL_NAME to be included in the gen* programs. */
29 #undef ENABLE_TREE_CHECKING
33 #include "hard-reg-set.h"
34 #include "basic-block.h"
36 /* How to print out a register name.
37 We don't use PRINT_REG because some definitions of PRINT_REG
39 #ifndef DEBUG_PRINT_REG
40 #define DEBUG_PRINT_REG(RTX, CODE, FILE) \
41 fprintf ((FILE), "%d %s", REGNO (RTX), reg_names[REGNO (RTX)])
44 /* Array containing all of the register names */
46 #ifdef DEBUG_REGISTER_NAMES
47 static const char * const debug_reg_names[] = DEBUG_REGISTER_NAMES;
48 #define reg_names debug_reg_names
50 const char * reg_names[] = REGISTER_NAMES;
55 static int sawclose = 0;
59 static void print_rtx PARAMS ((rtx));
61 /* String printed at beginning of each RTL when it is dumped.
62 This string is set to ASM_COMMENT_START when the RTL is dumped in
63 the assembly output file. */
64 const char *print_rtx_head = "";
66 /* Nonzero means suppress output of instruction numbers and line number
67 notes in debugging dumps.
68 This must be defined here so that programs like gencodes can be linked. */
69 int flag_dump_unnumbered = 0;
71 /* Nonzero means use simplified format without flags, modes, etc. */
74 /* Nonzero if we are dumping graphical description. */
77 /* Nonzero to dump all call_placeholder alternatives. */
78 static int debug_call_placeholder_verbose;
81 print_mem_expr (outfile, expr)
85 if (TREE_CODE (expr) == COMPONENT_REF)
87 if (TREE_OPERAND (expr, 0))
88 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
90 fputs (" <variable>", outfile);
91 fprintf (outfile, ".%s",
92 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (expr, 1))));
94 else if (DECL_NAME (expr))
95 fprintf (outfile, " %s", IDENTIFIER_POINTER (DECL_NAME (expr)));
96 else if (TREE_CODE (expr) == RESULT_DECL)
97 fputs (" <result>", outfile);
99 fputs (" <anonymous>", outfile);
102 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
110 const char *format_ptr;
117 fputc (' ', outfile);
119 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
125 fputs ("(nil)", outfile);
129 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
131 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
136 is_insn = INSN_P (in_rtx);
138 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
139 in separate nodes and therefore have to handle them special here. */
141 && (is_insn || GET_CODE (in_rtx) == NOTE
142 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
149 /* Print name of expression code. */
150 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
151 fputc ('(', outfile);
153 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
157 if (RTX_FLAG (in_rtx, in_struct))
158 fputs ("/s", outfile);
160 if (RTX_FLAG (in_rtx, volatil))
161 fputs ("/v", outfile);
163 if (RTX_FLAG (in_rtx, unchanging))
164 fputs ("/u", outfile);
166 if (RTX_FLAG (in_rtx, integrated))
167 fputs ("/i", outfile);
169 if (RTX_FLAG (in_rtx, frame_related))
170 fputs ("/f", outfile);
172 if (RTX_FLAG (in_rtx, jump))
173 fputs ("/j", outfile);
175 if (RTX_FLAG (in_rtx, call))
176 fputs ("/c", outfile);
178 if (GET_MODE (in_rtx) != VOIDmode)
180 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
181 if (GET_CODE (in_rtx) == EXPR_LIST
182 || GET_CODE (in_rtx) == INSN_LIST)
183 fprintf (outfile, ":%s",
184 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
186 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
191 /* Get the format string and skip the first elements if we have handled
193 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
194 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
195 switch (*format_ptr++)
200 str = XTMPL (in_rtx, i);
205 str = XSTR (in_rtx, i);
209 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
213 fprintf (outfile, " (\\\"%s\\\")", str);
215 fprintf (outfile, " (\"%s\")", str);
220 /* 0 indicates a field for internal use that should not be printed.
221 An exception is the third field of a NOTE, where it indicates
222 that the field has several different valid contents. */
224 if (i == 1 && GET_CODE (in_rtx) == REG)
226 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
227 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
230 if (i == 3 && GET_CODE (in_rtx) == NOTE)
232 switch (NOTE_LINE_NUMBER (in_rtx))
234 case NOTE_INSN_EH_REGION_BEG:
235 case NOTE_INSN_EH_REGION_END:
236 if (flag_dump_unnumbered)
237 fprintf (outfile, " #");
239 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
243 case NOTE_INSN_BLOCK_BEG:
244 case NOTE_INSN_BLOCK_END:
245 fprintf (outfile, " ");
246 if (flag_dump_unnumbered)
247 fprintf (outfile, "#");
249 fprintf (outfile, HOST_PTR_PRINTF,
250 (char *) NOTE_BLOCK (in_rtx));
254 case NOTE_INSN_BASIC_BLOCK:
256 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
258 fprintf (outfile, " [bb %d]", bb->index);
262 case NOTE_INSN_EXPECTED_VALUE:
265 fprintf (outfile, " ");
266 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
270 case NOTE_INSN_DELETED_LABEL:
271 if (NOTE_SOURCE_FILE (in_rtx))
272 fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
274 fprintf (outfile, " \"\"");
277 case NOTE_INSN_PREDICTION:
278 if (NOTE_PREDICTION (in_rtx))
279 fprintf (outfile, " [ %d %d ] ",
280 (int)NOTE_PREDICTION_ALG (in_rtx),
281 (int) NOTE_PREDICTION_FLAGS (in_rtx));
283 fprintf (outfile, " [ ERROR ]");
288 const char * const str = X0STR (in_rtx, i);
290 if (NOTE_LINE_NUMBER (in_rtx) < 0)
293 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
297 fprintf (outfile, " (\\\"%s\\\")", str);
299 fprintf (outfile, " (\"%s\")", str);
311 fprintf (outfile, " ");
312 print_rtx (XEXP (in_rtx, i));
321 fprintf (outfile, "\n%s%*s",
322 print_rtx_head, indent * 2, "");
325 fputs ("[ ", outfile);
326 if (NULL != XVEC (in_rtx, i))
329 if (XVECLEN (in_rtx, i))
332 for (j = 0; j < XVECLEN (in_rtx, i); j++)
333 print_rtx (XVECEXP (in_rtx, i, j));
338 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
340 fputs ("] ", outfile);
347 fprintf (outfile, " ");
348 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
351 fprintf (outfile, " [");
352 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
353 fprintf (outfile, "]");
358 if (i == 5 && GET_CODE (in_rtx) == NOTE)
360 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
361 other times often contains garbage from INSN->NOTE death. */
362 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
363 fprintf (outfile, " %d", XINT (in_rtx, i));
367 int value = XINT (in_rtx, i);
370 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
372 fputc (' ', outfile);
373 DEBUG_PRINT_REG (in_rtx, 0, outfile);
375 else if (GET_CODE (in_rtx) == REG
376 && value <= LAST_VIRTUAL_REGISTER)
378 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
379 fprintf (outfile, " %d virtual-incoming-args", value);
380 else if (value == VIRTUAL_STACK_VARS_REGNUM)
381 fprintf (outfile, " %d virtual-stack-vars", value);
382 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
383 fprintf (outfile, " %d virtual-stack-dynamic", value);
384 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
385 fprintf (outfile, " %d virtual-outgoing-args", value);
386 else if (value == VIRTUAL_CFA_REGNUM)
387 fprintf (outfile, " %d virtual-cfa", value);
389 fprintf (outfile, " %d virtual-reg-%d", value,
390 value-FIRST_VIRTUAL_REGISTER);
392 else if (flag_dump_unnumbered
393 && (is_insn || GET_CODE (in_rtx) == NOTE))
394 fputc ('#', outfile);
396 fprintf (outfile, " %d", value);
398 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
399 && XINT (in_rtx, i) >= 0
400 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
401 fprintf (outfile, " {%s}", name);
406 /* Print NOTE_INSN names rather than integer codes. */
409 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
410 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
411 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
413 fprintf (outfile, " %d", XINT (in_rtx, i));
418 if (XEXP (in_rtx, i) != NULL)
420 rtx sub = XEXP (in_rtx, i);
421 enum rtx_code subc = GET_CODE (sub);
423 if (GET_CODE (in_rtx) == LABEL_REF)
426 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
428 if (flag_dump_unnumbered)
429 fprintf (outfile, " [# deleted]");
431 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
436 if (subc != CODE_LABEL)
440 if (flag_dump_unnumbered)
441 fputs (" #", outfile);
443 fprintf (outfile, " %d", INSN_UID (sub));
446 fputs (" 0", outfile);
451 if (XBITMAP (in_rtx, i) == NULL)
452 fputs (" {null}", outfile);
454 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
460 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
464 fputs (" Unknown", outfile);
469 if (XBBDEF (in_rtx, i))
470 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
475 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
480 switch (GET_CODE (in_rtx))
483 fputs (" [", outfile);
484 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
486 if (MEM_EXPR (in_rtx))
487 print_mem_expr (outfile, MEM_EXPR (in_rtx));
489 if (MEM_OFFSET (in_rtx))
491 fputc ('+', outfile);
492 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
493 INTVAL (MEM_OFFSET (in_rtx)));
496 if (MEM_SIZE (in_rtx))
498 fputs (" S", outfile);
499 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
500 INTVAL (MEM_SIZE (in_rtx)));
503 if (MEM_ALIGN (in_rtx) != 1)
504 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
506 fputc (']', outfile);
510 /* It would be nice to do this, but it would require real.o to
511 be linked into the MD-generator programs. Maybe we should
512 do that. -zw 2002-03-03 */
514 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
519 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
520 REAL_VALUE_TO_DECIMAL (val, "%.16g", s);
521 fprintf (outfile, " [%s]", s);
527 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
528 if (LABEL_ALTERNATE_NAME (in_rtx))
529 fprintf (outfile, " [alternate name: %s]",
530 LABEL_ALTERNATE_NAME (in_rtx));
533 case CALL_PLACEHOLDER:
534 if (debug_call_placeholder_verbose)
536 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile);
537 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
539 fputs ("\n ", outfile);
540 print_inline_rtx (outfile, tem, 4);
543 tem = XEXP (in_rtx, 1);
545 fputs ("\n ])\n (const_string \"tail_call\") (sequence [",
547 for (; tem != 0; tem = NEXT_INSN (tem))
549 fputs ("\n ", outfile);
550 print_inline_rtx (outfile, tem, 4);
553 tem = XEXP (in_rtx, 2);
555 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [",
557 for (; tem != 0; tem = NEXT_INSN (tem))
559 fputs ("\n ", outfile);
560 print_inline_rtx (outfile, tem, 4);
563 fputs ("\n ])\n ])", outfile);
567 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
568 if (GET_CODE (tem) == CALL_INSN)
570 fprintf (outfile, " ");
581 && (is_insn || GET_CODE (in_rtx) == NOTE
582 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
586 fputc (')', outfile);
591 /* Print an rtx on the current line of FILE. Initially indent IND
595 print_inline_rtx (outf, x, ind)
600 int oldsaw = sawclose;
601 int oldindent = indent;
611 /* Call this function from the debugger to see what X looks like. */
619 fprintf (stderr, "\n");
622 /* Count of rtx's to print with debug_rtx_list.
623 This global exists because gdb user defined commands have no arguments. */
625 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
627 /* Call this function to print list from X on.
629 N is a count of the rtx's to print. Positive values print from the specified
630 rtx on. Negative values print a window around the rtx.
631 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
634 debug_rtx_list (x, n)
641 count = n == 0 ? 1 : n < 0 ? -n : n;
643 /* If we are printing a window, back up to the start. */
646 for (i = count / 2; i > 0; i--)
648 if (PREV_INSN (x) == 0)
653 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
657 /* Call this function to print an rtx list from START to END inclusive. */
660 debug_rtx_range (start, end)
666 if (!start || start == end)
668 start = NEXT_INSN (start);
672 /* Call this function to search an rtx list to find one with insn uid UID,
673 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
674 The found insn is returned to enable further debugging analysis. */
677 debug_rtx_find (x, uid)
681 while (x != 0 && INSN_UID (x) != uid)
685 debug_rtx_list (x, debug_rtx_count);
690 fprintf (stderr, "insn uid %d not found\n", uid);
695 /* External entry point for printing a chain of insns
696 starting with RTX_FIRST onto file OUTF.
697 A blank line separates insns.
699 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
702 print_rtl (outf, rtx_first)
713 fputs (print_rtx_head, outf);
714 fputs ("(nil)\n", outf);
717 switch (GET_CODE (rtx_first))
725 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
726 if (! flag_dump_unnumbered
727 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
729 fputs (print_rtx_head, outfile);
731 fprintf (outfile, "\n");
736 fputs (print_rtx_head, outfile);
737 print_rtx (rtx_first);
741 /* Like print_rtx, except specify a file. */
742 /* Return nonzero if we actually printed anything. */
745 print_rtl_single (outf, x)
751 if (! flag_dump_unnumbered
752 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
754 fputs (print_rtx_head, outfile);
763 /* Like print_rtl except without all the detail; for example,
764 if RTX is a CONST_INT then print in decimal format. */
767 print_simple_rtl (outf, x)