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;
80 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
88 const char *format_ptr;
97 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
103 fputs ("(nil)", outfile);
107 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
109 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
114 is_insn = INSN_P (in_rtx);
116 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
117 in separate nodes and therefore have to handle them special here. */
119 && (is_insn || GET_CODE (in_rtx) == NOTE
120 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
127 /* Print name of expression code. */
128 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
129 fputc ('(', outfile);
131 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
135 if (in_rtx->in_struct)
136 fputs ("/s", outfile);
139 fputs ("/v", outfile);
141 if (in_rtx->unchanging)
142 fputs ("/u", outfile);
144 if (in_rtx->integrated)
145 fputs ("/i", outfile);
147 if (in_rtx->frame_related)
148 fputs ("/f", outfile);
151 fputs ("/j", outfile);
154 fputs ("/c", outfile);
156 if (GET_MODE (in_rtx) != VOIDmode)
158 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
159 if (GET_CODE (in_rtx) == EXPR_LIST
160 || GET_CODE (in_rtx) == INSN_LIST)
161 fprintf (outfile, ":%s",
162 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
164 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
169 /* Get the format string and skip the first elements if we have handled
171 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
172 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
173 switch (*format_ptr++)
178 str = XTMPL (in_rtx, i);
183 str = XSTR (in_rtx, i);
187 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
191 fprintf (outfile, " (\\\"%s\\\")", str);
193 fprintf (outfile, " (\"%s\")", str);
198 /* 0 indicates a field for internal use that should not be printed.
199 An exception is the third field of a NOTE, where it indicates
200 that the field has several different valid contents. */
202 if (i == 1 && GET_CODE (in_rtx) == REG)
204 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
205 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
208 if (i == 3 && GET_CODE (in_rtx) == NOTE)
210 switch (NOTE_LINE_NUMBER (in_rtx))
212 case NOTE_INSN_EH_REGION_BEG:
213 case NOTE_INSN_EH_REGION_END:
214 if (flag_dump_unnumbered)
215 fprintf (outfile, " #");
217 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
221 case NOTE_INSN_BLOCK_BEG:
222 case NOTE_INSN_BLOCK_END:
223 fprintf (outfile, " ");
224 if (flag_dump_unnumbered)
225 fprintf (outfile, "#");
227 fprintf (outfile, HOST_PTR_PRINTF,
228 (char *) NOTE_BLOCK (in_rtx));
232 case NOTE_INSN_RANGE_BEG:
233 case NOTE_INSN_RANGE_END:
237 fprintf (outfile, " ");
238 print_rtx (NOTE_RANGE_INFO (in_rtx));
242 case NOTE_INSN_BASIC_BLOCK:
244 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
246 fprintf (outfile, " [bb %d]", bb->index);
250 case NOTE_INSN_EXPECTED_VALUE:
253 fprintf (outfile, " ");
254 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
258 case NOTE_INSN_DELETED_LABEL:
259 if (NOTE_SOURCE_FILE (in_rtx))
260 fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
262 fprintf (outfile, " \"\"");
267 const char * const str = X0STR (in_rtx, i);
269 if (NOTE_LINE_NUMBER (in_rtx) < 0)
272 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
276 fprintf (outfile, " (\\\"%s\\\")", str);
278 fprintf (outfile, " (\"%s\")", str);
290 fprintf (outfile, " ");
291 print_rtx (XEXP (in_rtx, i));
300 fprintf (outfile, "\n%s%*s",
301 print_rtx_head, indent * 2, "");
304 fputs ("[ ", outfile);
305 if (NULL != XVEC (in_rtx, i))
308 if (XVECLEN (in_rtx, i))
311 for (j = 0; j < XVECLEN (in_rtx, i); j++)
312 print_rtx (XVECEXP (in_rtx, i, j));
317 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
319 fputs ("] ", outfile);
326 fprintf (outfile, " ");
327 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
330 fprintf (outfile, " [");
331 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
332 fprintf (outfile, "]");
337 if (i == 5 && GET_CODE (in_rtx) == NOTE)
339 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
340 other times often contains garbage from INSN->NOTE death. */
341 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
342 fprintf (outfile, " %d", XINT (in_rtx, i));
346 int value = XINT (in_rtx, i);
349 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
351 fputc (' ', outfile);
352 DEBUG_PRINT_REG (in_rtx, 0, outfile);
354 else if (GET_CODE (in_rtx) == REG
355 && value <= LAST_VIRTUAL_REGISTER)
357 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
358 fprintf (outfile, " %d virtual-incoming-args", value);
359 else if (value == VIRTUAL_STACK_VARS_REGNUM)
360 fprintf (outfile, " %d virtual-stack-vars", value);
361 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
362 fprintf (outfile, " %d virtual-stack-dynamic", value);
363 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
364 fprintf (outfile, " %d virtual-outgoing-args", value);
365 else if (value == VIRTUAL_CFA_REGNUM)
366 fprintf (outfile, " %d virtual-cfa", value);
368 fprintf (outfile, " %d virtual-reg-%d", value,
369 value-FIRST_VIRTUAL_REGISTER);
371 else if (flag_dump_unnumbered
372 && (is_insn || GET_CODE (in_rtx) == NOTE))
373 fputc ('#', outfile);
375 fprintf (outfile, " %d", value);
377 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
378 && XINT (in_rtx, i) >= 0
379 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
380 fprintf (outfile, " {%s}", name);
385 /* Print NOTE_INSN names rather than integer codes. */
388 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
389 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
390 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
392 fprintf (outfile, " %d", XINT (in_rtx, i));
397 if (XEXP (in_rtx, i) != NULL)
399 rtx sub = XEXP (in_rtx, i);
400 enum rtx_code subc = GET_CODE (sub);
402 if (GET_CODE (in_rtx) == LABEL_REF)
405 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
407 if (flag_dump_unnumbered)
408 fprintf (outfile, " [# deleted]");
410 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
415 if (subc != CODE_LABEL)
419 if (flag_dump_unnumbered)
420 fputs (" #", outfile);
422 fprintf (outfile, " %d", INSN_UID (sub));
425 fputs (" 0", outfile);
430 if (XBITMAP (in_rtx, i) == NULL)
431 fputs (" {null}", outfile);
433 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
439 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
443 fputs (" Unknown", outfile);
449 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
454 switch (GET_CODE (in_rtx))
457 fputs (" [", outfile);
458 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
459 if (MEM_DECL (in_rtx))
460 fprintf (outfile, " %s",
461 DECL_NAME (MEM_DECL (in_rtx))
462 ? IDENTIFIER_POINTER (DECL_NAME (MEM_DECL (in_rtx)))
463 : TREE_CODE (MEM_DECL (in_rtx)) == RESULT_DECL ? "<result>"
466 if (MEM_OFFSET (in_rtx))
468 fputc ('+', outfile);
469 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
470 INTVAL (MEM_OFFSET (in_rtx)));
473 if (MEM_SIZE (in_rtx))
475 fputs (" S", outfile);
476 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
477 INTVAL (MEM_SIZE (in_rtx)));
480 if (MEM_ALIGN (in_rtx) != 1)
481 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
483 fputc (']', outfile);
486 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
488 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
491 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
492 fprintf (outfile, " [%.16g]", val);
498 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
499 if (LABEL_ALTERNATE_NAME (in_rtx))
500 fprintf (outfile, " [alternate name: %s]",
501 LABEL_ALTERNATE_NAME (in_rtx));
504 case CALL_PLACEHOLDER:
505 if (debug_call_placeholder_verbose)
507 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile);
508 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
510 fputs ("\n ", outfile);
511 print_inline_rtx (outfile, tem, 4);
514 tem = XEXP (in_rtx, 1);
516 fputs ("\n ])\n (const_string \"tail_call\") (sequence [",
518 for (; tem != 0; tem = NEXT_INSN (tem))
520 fputs ("\n ", outfile);
521 print_inline_rtx (outfile, tem, 4);
524 tem = XEXP (in_rtx, 2);
526 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [",
528 for (; tem != 0; tem = NEXT_INSN (tem))
530 fputs ("\n ", outfile);
531 print_inline_rtx (outfile, tem, 4);
534 fputs ("\n ])\n ])", outfile);
538 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
539 if (GET_CODE (tem) == CALL_INSN)
541 fprintf (outfile, " ");
552 && (is_insn || GET_CODE (in_rtx) == NOTE
553 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
557 fputc (')', outfile);
562 /* Print an rtx on the current line of FILE. Initially indent IND
566 print_inline_rtx (outf, x, ind)
571 int oldsaw = sawclose;
572 int oldindent = indent;
582 /* Call this function from the debugger to see what X looks like. */
590 fprintf (stderr, "\n");
593 /* Count of rtx's to print with debug_rtx_list.
594 This global exists because gdb user defined commands have no arguments. */
596 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
598 /* Call this function to print list from X on.
600 N is a count of the rtx's to print. Positive values print from the specified
601 rtx on. Negative values print a window around the rtx.
602 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
605 debug_rtx_list (x, n)
612 count = n == 0 ? 1 : n < 0 ? -n : n;
614 /* If we are printing a window, back up to the start. */
617 for (i = count / 2; i > 0; i--)
619 if (PREV_INSN (x) == 0)
624 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
628 /* Call this function to print an rtx list from START to END inclusive. */
631 debug_rtx_range (start, end)
637 if (!start || start == end)
639 start = NEXT_INSN (start);
643 /* Call this function to search an rtx list to find one with insn uid UID,
644 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
645 The found insn is returned to enable further debugging analysis. */
648 debug_rtx_find (x, uid)
652 while (x != 0 && INSN_UID (x) != uid)
656 debug_rtx_list (x, debug_rtx_count);
661 fprintf (stderr, "insn uid %d not found\n", uid);
666 /* External entry point for printing a chain of insns
667 starting with RTX_FIRST onto file OUTF.
668 A blank line separates insns.
670 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
673 print_rtl (outf, rtx_first)
684 fputs (print_rtx_head, outf);
685 fputs ("(nil)\n", outf);
688 switch (GET_CODE (rtx_first))
696 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
697 if (! flag_dump_unnumbered
698 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
700 fputs (print_rtx_head, outfile);
702 fprintf (outfile, "\n");
707 fputs (print_rtx_head, outfile);
708 print_rtx (rtx_first);
712 /* Like print_rtx, except specify a file. */
713 /* Return nonzero if we actually printed anything. */
716 print_rtl_single (outf, x)
722 if (! flag_dump_unnumbered
723 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
725 fputs (print_rtx_head, outfile);
734 /* Like print_rtl except without all the detail; for example,
735 if RTX is a CONST_INT then print in decimal format. */
738 print_simple_rtl (outf, x)