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 GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
31 /* How to print out a register name.
32 We don't use PRINT_REG because some definitions of PRINT_REG
34 #ifndef DEBUG_PRINT_REG
35 #define DEBUG_PRINT_REG(RTX, CODE, FILE) \
36 fprintf ((FILE), "%d %s", REGNO (RTX), reg_names[REGNO (RTX)])
39 /* Array containing all of the register names */
41 #ifdef DEBUG_REGISTER_NAMES
42 static const char * const debug_reg_names[] = DEBUG_REGISTER_NAMES;
43 #define reg_names debug_reg_names
45 const char * reg_names[] = REGISTER_NAMES;
50 static const char xspaces[] = " ";
52 static int sawclose = 0;
56 static void print_rtx PARAMS ((rtx));
58 /* String printed at beginning of each RTL when it is dumped.
59 This string is set to ASM_COMMENT_START when the RTL is dumped in
60 the assembly output file. */
61 const char *print_rtx_head = "";
63 /* Nonzero means suppress output of instruction numbers and line number
64 notes in debugging dumps.
65 This must be defined here so that programs like gencodes can be linked. */
66 int flag_dump_unnumbered = 0;
68 /* Nonzero if we are dumping graphical description. */
71 /* Nonzero to dump all call_placeholder alternatives. */
72 static int debug_call_placeholder_verbose;
74 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
82 register const char *format_ptr;
88 fprintf (outfile, "\n%s%s",
90 (xspaces + (sizeof xspaces - 1 - indent * 2)));
96 fputs ("(nil)", outfile);
101 is_insn = (INSN_P (in_rtx));
103 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
104 in separate nodes and therefore have to handle them special here. */
105 if (dump_for_graph &&
106 (is_insn || GET_CODE (in_rtx) == NOTE || GET_CODE (in_rtx) == CODE_LABEL
107 || GET_CODE (in_rtx) == BARRIER))
114 /* print name of expression code */
115 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
117 if (in_rtx->in_struct)
118 fputs ("/s", outfile);
121 fputs ("/v", outfile);
123 if (in_rtx->unchanging)
124 fputs ("/u", outfile);
126 if (in_rtx->integrated)
127 fputs ("/i", outfile);
129 if (in_rtx->frame_related)
130 fputs ("/f", outfile);
133 fputs ("/j", outfile);
136 fputs ("/c", outfile);
138 if (GET_MODE (in_rtx) != VOIDmode)
140 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
141 if (GET_CODE (in_rtx) == EXPR_LIST || GET_CODE (in_rtx) == INSN_LIST)
142 fprintf (outfile, ":%s", GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
144 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
148 /* Get the format string and skip the first elements if we have handled
150 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
152 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
153 switch (*format_ptr++)
157 if (XSTR (in_rtx, i) == 0)
158 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
162 fprintf (outfile, " (\\\"%s\\\")", XSTR (in_rtx, i));
164 fprintf (outfile, " (\"%s\")", XSTR (in_rtx, i));
169 /* 0 indicates a field for internal use that should not be printed.
170 An exception is the third field of a NOTE, where it indicates
171 that the field has several different valid contents. */
173 if (i == 1 && GET_CODE (in_rtx) == REG)
175 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
176 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
179 if (i == 3 && GET_CODE (in_rtx) == NOTE)
181 switch (NOTE_LINE_NUMBER (in_rtx))
183 case NOTE_INSN_EH_REGION_BEG:
184 case NOTE_INSN_EH_REGION_END:
185 if (flag_dump_unnumbered)
186 fprintf (outfile, " #");
188 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
192 case NOTE_INSN_BLOCK_BEG:
193 case NOTE_INSN_BLOCK_END:
194 fprintf (outfile, " ");
195 if (flag_dump_unnumbered)
196 fprintf (outfile, "#");
198 fprintf (outfile, HOST_PTR_PRINTF,
199 (char *) NOTE_BLOCK (in_rtx));
203 case NOTE_INSN_RANGE_BEG:
204 case NOTE_INSN_RANGE_END:
208 fprintf (outfile, " ");
209 print_rtx (NOTE_RANGE_INFO (in_rtx));
213 case NOTE_INSN_BASIC_BLOCK:
215 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
217 fprintf (outfile, " [bb %d]", bb->index);
221 case NOTE_INSN_EXPECTED_VALUE:
224 fprintf (outfile, " ");
225 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
229 case NOTE_INSN_DELETED_LABEL:
230 if (NOTE_SOURCE_FILE (in_rtx))
231 fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
233 fprintf (outfile, " \"\"");
238 const char * const str = X0STR (in_rtx, i);
240 if (NOTE_LINE_NUMBER (in_rtx) < 0)
243 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
247 fprintf (outfile, " (\\\"%s\\\")", str);
249 fprintf (outfile, " (\"%s\")", str);
261 fprintf (outfile, " ");
262 print_rtx (XEXP (in_rtx, i));
271 fprintf (outfile, "\n%s%s",
273 (xspaces + (sizeof xspaces - 1 - indent * 2)));
276 fputs ("[ ", outfile);
277 if (NULL != XVEC (in_rtx, i))
280 if (XVECLEN (in_rtx, i))
283 for (j = 0; j < XVECLEN (in_rtx, i); j++)
284 print_rtx (XVECEXP (in_rtx, i, j));
289 fprintf (outfile, "\n%s%s",
291 (xspaces + (sizeof xspaces - 1 - indent * 2)));
293 fputs ("] ", outfile);
299 fprintf (outfile, " ");
300 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
301 fprintf (outfile, " [");
302 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
303 fprintf (outfile, "]");
308 register int value = XINT (in_rtx, i);
311 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
313 fputc (' ', outfile);
314 DEBUG_PRINT_REG (in_rtx, 0, outfile);
316 else if (GET_CODE (in_rtx) == REG && value <= LAST_VIRTUAL_REGISTER)
318 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
319 fprintf (outfile, " %d virtual-incoming-args", value);
320 else if (value == VIRTUAL_STACK_VARS_REGNUM)
321 fprintf (outfile, " %d virtual-stack-vars", value);
322 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
323 fprintf (outfile, " %d virtual-stack-dynamic", value);
324 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
325 fprintf (outfile, " %d virtual-outgoing-args", value);
326 else if (value == VIRTUAL_CFA_REGNUM)
327 fprintf (outfile, " %d virtual-cfa", value);
329 fprintf (outfile, " %d virtual-reg-%d", value,
330 value-FIRST_VIRTUAL_REGISTER);
332 else if (flag_dump_unnumbered
333 && (is_insn || GET_CODE (in_rtx) == NOTE))
334 fputc ('#', outfile);
336 fprintf (outfile, " %d", value);
338 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
339 && XINT (in_rtx, i) >= 0
340 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
341 fprintf (outfile, " {%s}", name);
346 /* Print NOTE_INSN names rather than integer codes. */
349 if (XINT (in_rtx, i) >= NOTE_INSN_BIAS
350 && XINT (in_rtx, i) < NOTE_INSN_MAX)
351 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
353 fprintf (outfile, " %d", XINT (in_rtx, i));
358 if (XEXP (in_rtx, i) != NULL)
360 rtx sub = XEXP (in_rtx, i);
361 enum rtx_code subc = GET_CODE (sub);
363 if (GET_CODE (in_rtx) == LABEL_REF)
366 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
368 if (flag_dump_unnumbered)
369 fprintf (outfile, " [# deleted]");
371 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
376 if (subc != CODE_LABEL)
380 if (flag_dump_unnumbered)
381 fputs (" #", outfile);
383 fprintf (outfile, " %d", INSN_UID (sub));
386 fputs (" 0", outfile);
391 if (XBITMAP (in_rtx, i) == NULL)
392 fputs (" {null}", outfile);
394 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
400 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
404 fputs (" Unknown", outfile);
410 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
415 switch (GET_CODE (in_rtx))
418 fputc (' ', outfile);
419 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
422 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
424 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
427 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
428 fprintf (outfile, " [%.16g]", val);
434 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
435 if (LABEL_ALTERNATE_NAME (in_rtx))
436 fprintf (outfile, " [alternate name: %s]",
437 LABEL_ALTERNATE_NAME (in_rtx));
440 case CALL_PLACEHOLDER:
441 if (debug_call_placeholder_verbose)
443 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile);
444 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
446 fputs ("\n ", outfile);
447 print_inline_rtx (outfile, tem, 4);
450 tem = XEXP (in_rtx, 1);
452 fputs ("\n ])\n (const_string \"tail_call\") (sequence [", outfile);
453 for (; tem != 0; tem = NEXT_INSN (tem))
455 fputs ("\n ", outfile);
456 print_inline_rtx (outfile, tem, 4);
459 tem = XEXP (in_rtx, 2);
461 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [", outfile);
462 for (; tem != 0; tem = NEXT_INSN (tem))
464 fputs ("\n ", outfile);
465 print_inline_rtx (outfile, tem, 4);
468 fputs ("\n ])\n ])", outfile);
472 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
473 if (GET_CODE (tem) == CALL_INSN)
475 fprintf (outfile, " ");
486 && (is_insn || GET_CODE (in_rtx) == NOTE
487 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
491 fputc (')', outfile);
496 /* Print an rtx on the current line of FILE. Initially indent IND
500 print_inline_rtx (outf, x, ind)
505 int oldsaw = sawclose;
506 int oldindent = indent;
516 /* Call this function from the debugger to see what X looks like. */
524 fprintf (stderr, "\n");
527 /* Count of rtx's to print with debug_rtx_list.
528 This global exists because gdb user defined commands have no arguments. */
530 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
532 /* Call this function to print list from X on.
534 N is a count of the rtx's to print. Positive values print from the specified
535 rtx on. Negative values print a window around the rtx.
536 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
539 debug_rtx_list (x, n)
546 count = n == 0 ? 1 : n < 0 ? -n : n;
548 /* If we are printing a window, back up to the start. */
551 for (i = count / 2; i > 0; i--)
553 if (PREV_INSN (x) == 0)
558 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
562 /* Call this function to print an rtx list from START to END inclusive. */
565 debug_rtx_range (start, end)
571 if (!start || start == end)
573 start = NEXT_INSN (start);
577 /* Call this function to search an rtx list to find one with insn uid UID,
578 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
579 The found insn is returned to enable further debugging analysis. */
582 debug_rtx_find (x, uid)
586 while (x != 0 && INSN_UID (x) != uid)
590 debug_rtx_list (x, debug_rtx_count);
595 fprintf (stderr, "insn uid %d not found\n", uid);
600 /* External entry point for printing a chain of insns
601 starting with RTX_FIRST onto file OUTF.
602 A blank line separates insns.
604 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
607 print_rtl (outf, rtx_first)
611 register rtx tmp_rtx;
618 fputs (print_rtx_head, outf);
619 fputs ("(nil)\n", outf);
622 switch (GET_CODE (rtx_first))
630 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
631 if (! flag_dump_unnumbered
632 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
634 fputs (print_rtx_head, outfile);
636 fprintf (outfile, "\n");
641 fputs (print_rtx_head, outfile);
642 print_rtx (rtx_first);
646 /* Like print_rtx, except specify a file. */
647 /* Return nonzero if we actually printed anything. */
650 print_rtl_single (outf, x)
656 if (! flag_dump_unnumbered
657 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
659 fputs (print_rtx_head, outfile);