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 /* Nonzero means suppress output of instruction numbers and line number
59 notes in debugging dumps.
60 This must be defined here so that programs like gencodes can be linked. */
61 int flag_dump_unnumbered = 0;
63 /* Nonzero if we are dumping graphical description. */
66 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
74 register const char *format_ptr;
80 fprintf (outfile, "\n%s",
81 (xspaces + (sizeof xspaces - 1 - indent * 2)));
87 fputs ("(nil)", outfile);
92 is_insn = (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i');
94 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
95 in separate nodes and therefore have to handle them special here. */
97 (is_insn || GET_CODE (in_rtx) == NOTE || GET_CODE (in_rtx) == CODE_LABEL
98 || GET_CODE (in_rtx) == BARRIER))
105 /* print name of expression code */
106 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
108 if (in_rtx->in_struct)
109 fputs ("/s", outfile);
112 fputs ("/v", outfile);
114 if (in_rtx->unchanging)
115 fputs ("/u", outfile);
117 if (in_rtx->integrated)
118 fputs ("/i", outfile);
120 if (in_rtx->frame_related)
121 fputs ("/f", outfile);
124 fputs ("/j", outfile);
127 fputs ("/c", outfile);
129 if (GET_MODE (in_rtx) != VOIDmode)
131 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
132 if (GET_CODE (in_rtx) == EXPR_LIST || GET_CODE (in_rtx) == INSN_LIST)
133 fprintf (outfile, ":%s", GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
135 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
139 /* Get the format string and skip the first elements if we have handled
141 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
143 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
144 switch (*format_ptr++)
148 if (XSTR (in_rtx, i) == 0)
149 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
153 fprintf (outfile, " (\\\"%s\\\")", XSTR (in_rtx, i));
155 fprintf (outfile, " (\"%s\")", XSTR (in_rtx, i));
160 /* 0 indicates a field for internal use that should not be printed.
161 An exception is the third field of a NOTE, where it indicates
162 that the field has several different valid contents. */
164 if (i == 3 && GET_CODE (in_rtx) == NOTE)
166 switch (NOTE_LINE_NUMBER (in_rtx))
168 case NOTE_INSN_EH_REGION_BEG:
169 case NOTE_INSN_EH_REGION_END:
170 if (flag_dump_unnumbered)
171 fprintf (outfile, " #");
173 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
177 case NOTE_INSN_BLOCK_BEG:
178 case NOTE_INSN_BLOCK_END:
179 fprintf (outfile, " ");
180 if (flag_dump_unnumbered)
181 fprintf (outfile, "#");
183 fprintf (outfile, HOST_PTR_PRINTF,
184 (char *) NOTE_BLOCK (in_rtx));
188 case NOTE_INSN_RANGE_BEG:
189 case NOTE_INSN_RANGE_END:
193 fprintf (outfile, " ");
194 print_rtx (NOTE_RANGE_INFO (in_rtx));
198 case NOTE_INSN_BASIC_BLOCK:
200 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
202 fprintf (outfile, " [bb %d]", bb->index);
206 case NOTE_INSN_EXPECTED_VALUE:
209 fprintf (outfile, " ");
210 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
214 case NOTE_INSN_DELETED_LABEL:
215 if (NOTE_SOURCE_FILE (in_rtx))
216 fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
218 fprintf (outfile, " \"\"");
223 const char * const str = X0STR (in_rtx, i);
225 if (NOTE_LINE_NUMBER (in_rtx) < 0)
228 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
232 fprintf (outfile, " (\\\"%s\\\")", str);
234 fprintf (outfile, " (\"%s\")", str);
246 fprintf (outfile, " ");
247 print_rtx (XEXP (in_rtx, i));
256 fprintf (outfile, "\n%s",
257 (xspaces + (sizeof xspaces - 1 - indent * 2)));
260 fputs ("[ ", outfile);
261 if (NULL != XVEC (in_rtx, i))
264 if (XVECLEN (in_rtx, i))
267 for (j = 0; j < XVECLEN (in_rtx, i); j++)
268 print_rtx (XVECEXP (in_rtx, i, j));
273 fprintf (outfile, "\n%s",
274 (xspaces + (sizeof xspaces - 1 - indent * 2)));
276 fputs ("] ", outfile);
282 fprintf (outfile, " ");
283 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
284 fprintf (outfile, " [");
285 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
286 fprintf (outfile, "]");
291 register int value = XINT (in_rtx, i);
294 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
296 fputc (' ', outfile);
297 DEBUG_PRINT_REG (in_rtx, 0, outfile);
299 else if (GET_CODE (in_rtx) == REG && value <= LAST_VIRTUAL_REGISTER)
301 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
302 fprintf (outfile, " %d virtual-incoming-args", value);
303 else if (value == VIRTUAL_STACK_VARS_REGNUM)
304 fprintf (outfile, " %d virtual-stack-vars", value);
305 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
306 fprintf (outfile, " %d virtual-stack-dynamic", value);
307 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
308 fprintf (outfile, " %d virtual-outgoing-args", value);
309 else if (value == VIRTUAL_CFA_REGNUM)
310 fprintf (outfile, " %d virtual-cfa", value);
312 fprintf (outfile, " %d virtual-reg-%d", value,
313 value-FIRST_VIRTUAL_REGISTER);
315 else if (flag_dump_unnumbered
316 && (is_insn || GET_CODE (in_rtx) == NOTE))
317 fputc ('#', outfile);
319 fprintf (outfile, " %d", value);
321 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
322 && XINT (in_rtx, i) >= 0
323 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
324 fprintf (outfile, " {%s}", name);
329 /* Print NOTE_INSN names rather than integer codes. */
332 if (XINT (in_rtx, i) >= NOTE_INSN_BIAS
333 && XINT (in_rtx, i) < NOTE_INSN_MAX)
334 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
336 fprintf (outfile, " %d", XINT (in_rtx, i));
341 if (XEXP (in_rtx, i) != NULL)
343 rtx sub = XEXP (in_rtx, i);
344 enum rtx_code subc = GET_CODE (sub);
346 if (GET_CODE (in_rtx) == LABEL_REF)
349 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
351 if (flag_dump_unnumbered)
352 fprintf (outfile, " [# deleted]");
354 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
359 if (subc != CODE_LABEL)
363 if (flag_dump_unnumbered)
364 fputs (" #", outfile);
366 fprintf (outfile, " %d", INSN_UID (sub));
369 fputs (" 0", outfile);
374 if (XBITMAP (in_rtx, i) == NULL)
375 fputs (" {null}", outfile);
377 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
383 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
387 fputs (" Unknown", outfile);
393 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
398 switch (GET_CODE (in_rtx))
401 fputc (' ', outfile);
402 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
405 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
407 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
410 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
411 fprintf (outfile, " [%.16g]", val);
417 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
418 if (LABEL_ALTERNATE_NAME (in_rtx))
419 fprintf (outfile, " [alternate name: %s]",
420 LABEL_ALTERNATE_NAME (in_rtx));
423 case CALL_PLACEHOLDER:
424 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
425 if (GET_CODE (tem) == CALL_INSN)
427 fprintf (outfile, " ");
438 && (is_insn || GET_CODE (in_rtx) == NOTE
439 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
443 fputc (')', outfile);
448 /* Print an rtx on the current line of FILE. Initially indent IND
452 print_inline_rtx (outf, x, ind)
457 int oldsaw = sawclose;
458 int oldindent = indent;
468 /* Call this function from the debugger to see what X looks like. */
476 fprintf (stderr, "\n");
479 /* Count of rtx's to print with debug_rtx_list.
480 This global exists because gdb user defined commands have no arguments. */
482 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
484 /* Call this function to print list from X on.
486 N is a count of the rtx's to print. Positive values print from the specified
487 rtx on. Negative values print a window around the rtx.
488 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
491 debug_rtx_list (x, n)
498 count = n == 0 ? 1 : n < 0 ? -n : n;
500 /* If we are printing a window, back up to the start. */
503 for (i = count / 2; i > 0; i--)
505 if (PREV_INSN (x) == 0)
510 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
514 /* Call this function to print an rtx list from START to END inclusive. */
517 debug_rtx_range (start, end)
523 if (!start || start == end)
525 start = NEXT_INSN (start);
529 /* Call this function to search an rtx list to find one with insn uid UID,
530 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
531 The found insn is returned to enable further debugging analysis. */
534 debug_rtx_find (x, uid)
538 while (x != 0 && INSN_UID (x) != uid)
542 debug_rtx_list (x, debug_rtx_count);
547 fprintf (stderr, "insn uid %d not found\n", uid);
552 /* External entry point for printing a chain of insns
553 starting with RTX_FIRST onto file OUTF.
554 A blank line separates insns.
556 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
559 print_rtl (outf, rtx_first)
563 register rtx tmp_rtx;
569 fputs ("(nil)\n", outf);
571 switch (GET_CODE (rtx_first))
579 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
580 if (! flag_dump_unnumbered
581 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
584 fprintf (outfile, "\n");
589 print_rtx (rtx_first);
593 /* Like print_rtx, except specify a file. */
594 /* Return nonzero if we actually printed anything. */
597 print_rtl_single (outf, x)
603 if (! flag_dump_unnumbered
604 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)