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",
98 print_rtx_head, indent * 2, "");
104 fputs ("(nil)", outfile);
109 is_insn = (INSN_P (in_rtx));
111 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
112 in separate nodes and therefore have to handle them special here. */
113 if (dump_for_graph &&
114 (is_insn || GET_CODE (in_rtx) == NOTE || GET_CODE (in_rtx) == CODE_LABEL
115 || GET_CODE (in_rtx) == BARRIER))
122 /* print name of expression code */
123 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
124 fputc ('(', outfile);
126 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
130 if (in_rtx->in_struct)
131 fputs ("/s", outfile);
134 fputs ("/v", outfile);
136 if (in_rtx->unchanging)
137 fputs ("/u", outfile);
139 if (in_rtx->integrated)
140 fputs ("/i", outfile);
142 if (in_rtx->frame_related)
143 fputs ("/f", outfile);
146 fputs ("/j", outfile);
149 fputs ("/c", outfile);
151 if (GET_MODE (in_rtx) != VOIDmode)
153 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
154 if (GET_CODE (in_rtx) == EXPR_LIST
155 || GET_CODE (in_rtx) == INSN_LIST)
156 fprintf (outfile, ":%s",
157 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
159 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
164 /* Get the format string and skip the first elements if we have handled
166 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
168 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
169 switch (*format_ptr++)
174 str = XTMPL (in_rtx, i);
179 str = XSTR (in_rtx, i);
183 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
187 fprintf (outfile, " (\\\"%s\\\")", str);
189 fprintf (outfile, " (\"%s\")", str);
194 /* 0 indicates a field for internal use that should not be printed.
195 An exception is the third field of a NOTE, where it indicates
196 that the field has several different valid contents. */
198 if (i == 1 && GET_CODE (in_rtx) == REG)
200 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
201 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
204 if (i == 3 && GET_CODE (in_rtx) == NOTE)
206 switch (NOTE_LINE_NUMBER (in_rtx))
208 case NOTE_INSN_EH_REGION_BEG:
209 case NOTE_INSN_EH_REGION_END:
210 if (flag_dump_unnumbered)
211 fprintf (outfile, " #");
213 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
217 case NOTE_INSN_BLOCK_BEG:
218 case NOTE_INSN_BLOCK_END:
219 fprintf (outfile, " ");
220 if (flag_dump_unnumbered)
221 fprintf (outfile, "#");
223 fprintf (outfile, HOST_PTR_PRINTF,
224 (char *) NOTE_BLOCK (in_rtx));
228 case NOTE_INSN_RANGE_BEG:
229 case NOTE_INSN_RANGE_END:
233 fprintf (outfile, " ");
234 print_rtx (NOTE_RANGE_INFO (in_rtx));
238 case NOTE_INSN_BASIC_BLOCK:
240 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
242 fprintf (outfile, " [bb %d]", bb->index);
246 case NOTE_INSN_EXPECTED_VALUE:
249 fprintf (outfile, " ");
250 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
254 case NOTE_INSN_DELETED_LABEL:
255 if (NOTE_SOURCE_FILE (in_rtx))
256 fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
258 fprintf (outfile, " \"\"");
263 const char * const str = X0STR (in_rtx, i);
265 if (NOTE_LINE_NUMBER (in_rtx) < 0)
268 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
272 fprintf (outfile, " (\\\"%s\\\")", str);
274 fprintf (outfile, " (\"%s\")", str);
286 fprintf (outfile, " ");
287 print_rtx (XEXP (in_rtx, i));
296 fprintf (outfile, "\n%s%*s",
297 print_rtx_head, indent * 2, "");
300 fputs ("[ ", outfile);
301 if (NULL != XVEC (in_rtx, i))
304 if (XVECLEN (in_rtx, i))
307 for (j = 0; j < XVECLEN (in_rtx, i); j++)
308 print_rtx (XVECEXP (in_rtx, i, j));
313 fprintf (outfile, "\n%s%*s",
314 print_rtx_head, indent * 2, "");
316 fputs ("] ", outfile);
323 fprintf (outfile, " ");
324 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
327 fprintf (outfile, " [");
328 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
329 fprintf (outfile, "]");
334 if (i == 5 && GET_CODE (in_rtx) == NOTE)
336 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
337 other times often contains garbage from INSN->NOTE death. */
338 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
339 fprintf (outfile, " %d", XINT (in_rtx, i));
343 int value = XINT (in_rtx, i);
346 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
348 fputc (' ', outfile);
349 DEBUG_PRINT_REG (in_rtx, 0, outfile);
351 else if (GET_CODE (in_rtx) == REG
352 && value <= LAST_VIRTUAL_REGISTER)
354 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
355 fprintf (outfile, " %d virtual-incoming-args", value);
356 else if (value == VIRTUAL_STACK_VARS_REGNUM)
357 fprintf (outfile, " %d virtual-stack-vars", value);
358 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
359 fprintf (outfile, " %d virtual-stack-dynamic", value);
360 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
361 fprintf (outfile, " %d virtual-outgoing-args", value);
362 else if (value == VIRTUAL_CFA_REGNUM)
363 fprintf (outfile, " %d virtual-cfa", value);
365 fprintf (outfile, " %d virtual-reg-%d", value,
366 value-FIRST_VIRTUAL_REGISTER);
368 else if (flag_dump_unnumbered
369 && (is_insn || GET_CODE (in_rtx) == NOTE))
370 fputc ('#', outfile);
372 fprintf (outfile, " %d", value);
374 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
375 && XINT (in_rtx, i) >= 0
376 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
377 fprintf (outfile, " {%s}", name);
382 /* Print NOTE_INSN names rather than integer codes. */
385 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
386 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
387 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
389 fprintf (outfile, " %d", XINT (in_rtx, i));
394 if (XEXP (in_rtx, i) != NULL)
396 rtx sub = XEXP (in_rtx, i);
397 enum rtx_code subc = GET_CODE (sub);
399 if (GET_CODE (in_rtx) == LABEL_REF)
402 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
404 if (flag_dump_unnumbered)
405 fprintf (outfile, " [# deleted]");
407 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
412 if (subc != CODE_LABEL)
416 if (flag_dump_unnumbered)
417 fputs (" #", outfile);
419 fprintf (outfile, " %d", INSN_UID (sub));
422 fputs (" 0", outfile);
427 if (XBITMAP (in_rtx, i) == NULL)
428 fputs (" {null}", outfile);
430 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
436 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
440 fputs (" Unknown", outfile);
446 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
451 switch (GET_CODE (in_rtx))
454 fputs (" [", outfile);
455 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
456 if (MEM_DECL (in_rtx) && DECL_NAME (MEM_DECL (in_rtx)))
457 fprintf (outfile, " %s",
458 IDENTIFIER_POINTER (DECL_NAME (MEM_DECL (in_rtx))));
460 if (MEM_OFFSET (in_rtx))
462 fputc ('+', outfile);
463 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
464 INTVAL (MEM_OFFSET (in_rtx)));
467 if (MEM_SIZE (in_rtx))
469 fputs (" S", outfile);
470 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
471 INTVAL (MEM_SIZE (in_rtx)));
474 if (MEM_ALIGN (in_rtx) != 1)
475 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
477 fputc (']', outfile);
480 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
482 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
485 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
486 fprintf (outfile, " [%.16g]", val);
492 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
493 if (LABEL_ALTERNATE_NAME (in_rtx))
494 fprintf (outfile, " [alternate name: %s]",
495 LABEL_ALTERNATE_NAME (in_rtx));
498 case CALL_PLACEHOLDER:
499 if (debug_call_placeholder_verbose)
501 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile);
502 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
504 fputs ("\n ", outfile);
505 print_inline_rtx (outfile, tem, 4);
508 tem = XEXP (in_rtx, 1);
510 fputs ("\n ])\n (const_string \"tail_call\") (sequence [", outfile);
511 for (; tem != 0; tem = NEXT_INSN (tem))
513 fputs ("\n ", outfile);
514 print_inline_rtx (outfile, tem, 4);
517 tem = XEXP (in_rtx, 2);
519 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [", outfile);
520 for (; tem != 0; tem = NEXT_INSN (tem))
522 fputs ("\n ", outfile);
523 print_inline_rtx (outfile, tem, 4);
526 fputs ("\n ])\n ])", outfile);
530 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
531 if (GET_CODE (tem) == CALL_INSN)
533 fprintf (outfile, " ");
544 && (is_insn || GET_CODE (in_rtx) == NOTE
545 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
549 fputc (')', outfile);
554 /* Print an rtx on the current line of FILE. Initially indent IND
558 print_inline_rtx (outf, x, ind)
563 int oldsaw = sawclose;
564 int oldindent = indent;
574 /* Call this function from the debugger to see what X looks like. */
582 fprintf (stderr, "\n");
585 /* Count of rtx's to print with debug_rtx_list.
586 This global exists because gdb user defined commands have no arguments. */
588 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
590 /* Call this function to print list from X on.
592 N is a count of the rtx's to print. Positive values print from the specified
593 rtx on. Negative values print a window around the rtx.
594 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
597 debug_rtx_list (x, n)
604 count = n == 0 ? 1 : n < 0 ? -n : n;
606 /* If we are printing a window, back up to the start. */
609 for (i = count / 2; i > 0; i--)
611 if (PREV_INSN (x) == 0)
616 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
620 /* Call this function to print an rtx list from START to END inclusive. */
623 debug_rtx_range (start, end)
629 if (!start || start == end)
631 start = NEXT_INSN (start);
635 /* Call this function to search an rtx list to find one with insn uid UID,
636 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
637 The found insn is returned to enable further debugging analysis. */
640 debug_rtx_find (x, uid)
644 while (x != 0 && INSN_UID (x) != uid)
648 debug_rtx_list (x, debug_rtx_count);
653 fprintf (stderr, "insn uid %d not found\n", uid);
658 /* External entry point for printing a chain of insns
659 starting with RTX_FIRST onto file OUTF.
660 A blank line separates insns.
662 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
665 print_rtl (outf, rtx_first)
676 fputs (print_rtx_head, outf);
677 fputs ("(nil)\n", outf);
680 switch (GET_CODE (rtx_first))
688 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
689 if (! flag_dump_unnumbered
690 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
692 fputs (print_rtx_head, outfile);
694 fprintf (outfile, "\n");
699 fputs (print_rtx_head, outfile);
700 print_rtx (rtx_first);
704 /* Like print_rtx, except specify a file. */
705 /* Return nonzero if we actually printed anything. */
708 print_rtl_single (outf, x)
714 if (! flag_dump_unnumbered
715 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
717 fputs (print_rtx_head, outfile);
726 /* Like print_rtl except without all the detail; for example,
727 if RTX is a CONST_INT then print in decimal format. */
730 print_simple_rtl (outf, x)