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 if (DECL_NAME (TREE_OPERAND (expr, 1)))
92 fprintf (outfile, ".%s",
93 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (expr, 1))));
95 else if (TREE_CODE (expr) == INDIRECT_REF)
97 fputs (" (*", outfile);
98 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
101 else if (DECL_NAME (expr))
102 fprintf (outfile, " %s", IDENTIFIER_POINTER (DECL_NAME (expr)));
103 else if (TREE_CODE (expr) == RESULT_DECL)
104 fputs (" <result>", outfile);
106 fputs (" <anonymous>", outfile);
109 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
117 const char *format_ptr;
124 fputc (' ', outfile);
126 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
132 fputs ("(nil)", outfile);
136 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
138 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
143 is_insn = INSN_P (in_rtx);
145 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
146 in separate nodes and therefore have to handle them special here. */
148 && (is_insn || GET_CODE (in_rtx) == NOTE
149 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
156 /* Print name of expression code. */
157 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
158 fputc ('(', outfile);
160 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
164 if (RTX_FLAG (in_rtx, in_struct))
165 fputs ("/s", outfile);
167 if (RTX_FLAG (in_rtx, volatil))
168 fputs ("/v", outfile);
170 if (RTX_FLAG (in_rtx, unchanging))
171 fputs ("/u", outfile);
173 if (RTX_FLAG (in_rtx, integrated))
174 fputs ("/i", outfile);
176 if (RTX_FLAG (in_rtx, frame_related))
177 fputs ("/f", outfile);
179 if (RTX_FLAG (in_rtx, jump))
180 fputs ("/j", outfile);
182 if (RTX_FLAG (in_rtx, call))
183 fputs ("/c", outfile);
185 if (GET_MODE (in_rtx) != VOIDmode)
187 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
188 if (GET_CODE (in_rtx) == EXPR_LIST
189 || GET_CODE (in_rtx) == INSN_LIST)
190 fprintf (outfile, ":%s",
191 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
193 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
198 #ifndef GENERATOR_FILE
199 if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
203 /* Get the format string and skip the first elements if we have handled
205 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
206 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
207 switch (*format_ptr++)
212 str = XTMPL (in_rtx, i);
217 str = XSTR (in_rtx, i);
221 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
225 fprintf (outfile, " (\\\"%s\\\")", str);
227 fprintf (outfile, " (\"%s\")", str);
232 /* 0 indicates a field for internal use that should not be printed.
233 An exception is the third field of a NOTE, where it indicates
234 that the field has several different valid contents. */
236 if (i == 1 && GET_CODE (in_rtx) == REG)
238 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
239 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
242 if (i == 4 && GET_CODE (in_rtx) == NOTE)
244 switch (NOTE_LINE_NUMBER (in_rtx))
246 case NOTE_INSN_EH_REGION_BEG:
247 case NOTE_INSN_EH_REGION_END:
248 if (flag_dump_unnumbered)
249 fprintf (outfile, " #");
251 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
255 case NOTE_INSN_BLOCK_BEG:
256 case NOTE_INSN_BLOCK_END:
257 fprintf (outfile, " ");
258 if (flag_dump_unnumbered)
259 fprintf (outfile, "#");
261 fprintf (outfile, HOST_PTR_PRINTF,
262 (char *) NOTE_BLOCK (in_rtx));
266 case NOTE_INSN_BASIC_BLOCK:
268 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
270 fprintf (outfile, " [bb %d]", bb->index);
274 case NOTE_INSN_EXPECTED_VALUE:
277 fprintf (outfile, " ");
278 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
282 case NOTE_INSN_DELETED_LABEL:
283 if (NOTE_SOURCE_FILE (in_rtx))
284 fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
286 fprintf (outfile, " \"\"");
289 case NOTE_INSN_PREDICTION:
290 if (NOTE_PREDICTION (in_rtx))
291 fprintf (outfile, " [ %d %d ] ",
292 (int)NOTE_PREDICTION_ALG (in_rtx),
293 (int) NOTE_PREDICTION_FLAGS (in_rtx));
295 fprintf (outfile, " [ ERROR ]");
300 const char * const str = X0STR (in_rtx, i);
302 if (NOTE_LINE_NUMBER (in_rtx) < 0)
305 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
309 fprintf (outfile, " (\\\"%s\\\")", str);
311 fprintf (outfile, " (\"%s\")", str);
323 fprintf (outfile, " ");
324 print_rtx (XEXP (in_rtx, i));
333 fprintf (outfile, "\n%s%*s",
334 print_rtx_head, indent * 2, "");
337 fputs (" [", outfile);
338 if (NULL != XVEC (in_rtx, i))
341 if (XVECLEN (in_rtx, i))
344 for (j = 0; j < XVECLEN (in_rtx, i); j++)
345 print_rtx (XVECEXP (in_rtx, i, j));
350 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
352 fputs ("]", outfile);
359 fprintf (outfile, " ");
360 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
363 fprintf (outfile, " [");
364 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
365 fprintf (outfile, "]");
370 if (i == 6 && GET_CODE (in_rtx) == NOTE)
372 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
373 other times often contains garbage from INSN->NOTE death. */
374 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
375 fprintf (outfile, " %d", XINT (in_rtx, i));
379 int value = XINT (in_rtx, i);
382 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
384 fputc (' ', outfile);
385 DEBUG_PRINT_REG (in_rtx, 0, outfile);
387 else if (GET_CODE (in_rtx) == REG
388 && value <= LAST_VIRTUAL_REGISTER)
390 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
391 fprintf (outfile, " %d virtual-incoming-args", value);
392 else if (value == VIRTUAL_STACK_VARS_REGNUM)
393 fprintf (outfile, " %d virtual-stack-vars", value);
394 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
395 fprintf (outfile, " %d virtual-stack-dynamic", value);
396 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
397 fprintf (outfile, " %d virtual-outgoing-args", value);
398 else if (value == VIRTUAL_CFA_REGNUM)
399 fprintf (outfile, " %d virtual-cfa", value);
401 fprintf (outfile, " %d virtual-reg-%d", value,
402 value-FIRST_VIRTUAL_REGISTER);
404 else if (flag_dump_unnumbered
405 && (is_insn || GET_CODE (in_rtx) == NOTE))
406 fputc ('#', outfile);
408 fprintf (outfile, " %d", value);
410 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
411 && XINT (in_rtx, i) >= 0
412 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
413 fprintf (outfile, " {%s}", name);
418 /* Print NOTE_INSN names rather than integer codes. */
421 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
422 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
423 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
425 fprintf (outfile, " %d", XINT (in_rtx, i));
430 if (XEXP (in_rtx, i) != NULL)
432 rtx sub = XEXP (in_rtx, i);
433 enum rtx_code subc = GET_CODE (sub);
435 if (GET_CODE (in_rtx) == LABEL_REF)
438 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
440 if (flag_dump_unnumbered)
441 fprintf (outfile, " [# deleted]");
443 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
448 if (subc != CODE_LABEL)
452 if (flag_dump_unnumbered)
453 fputs (" #", outfile);
455 fprintf (outfile, " %d", INSN_UID (sub));
458 fputs (" 0", outfile);
463 if (XBITMAP (in_rtx, i) == NULL)
464 fputs (" {null}", outfile);
466 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
472 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
476 fputs (" Unknown", outfile);
481 if (XBBDEF (in_rtx, i))
482 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
487 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
492 switch (GET_CODE (in_rtx))
495 fputs (" [", outfile);
496 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
498 if (MEM_EXPR (in_rtx))
499 print_mem_expr (outfile, MEM_EXPR (in_rtx));
501 if (MEM_OFFSET (in_rtx))
503 fputc ('+', outfile);
504 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
505 INTVAL (MEM_OFFSET (in_rtx)));
508 if (MEM_SIZE (in_rtx))
510 fputs (" S", outfile);
511 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
512 INTVAL (MEM_SIZE (in_rtx)));
515 if (MEM_ALIGN (in_rtx) != 1)
516 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
518 fputc (']', outfile);
521 #ifndef GENERATOR_FILE
523 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
527 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx), -1);
528 fprintf (outfile, " %s", s);
530 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx), -1);
531 fprintf (outfile, " [%s]", s);
537 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
538 switch (LABEL_KIND (in_rtx))
540 case LABEL_NORMAL: break;
541 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
542 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
543 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
548 case CALL_PLACEHOLDER:
549 if (debug_call_placeholder_verbose)
551 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile);
552 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
554 fputs ("\n ", outfile);
555 print_inline_rtx (outfile, tem, 4);
558 tem = XEXP (in_rtx, 1);
560 fputs ("\n ])\n (const_string \"tail_call\") (sequence [",
562 for (; tem != 0; tem = NEXT_INSN (tem))
564 fputs ("\n ", outfile);
565 print_inline_rtx (outfile, tem, 4);
568 tem = XEXP (in_rtx, 2);
570 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [",
572 for (; tem != 0; tem = NEXT_INSN (tem))
574 fputs ("\n ", outfile);
575 print_inline_rtx (outfile, tem, 4);
578 fputs ("\n ])\n ])", outfile);
582 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
583 if (GET_CODE (tem) == CALL_INSN)
585 fprintf (outfile, " ");
596 && (is_insn || GET_CODE (in_rtx) == NOTE
597 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
601 fputc (')', outfile);
606 /* Print an rtx on the current line of FILE. Initially indent IND
610 print_inline_rtx (outf, x, ind)
615 int oldsaw = sawclose;
616 int oldindent = indent;
626 /* Call this function from the debugger to see what X looks like. */
635 fprintf (stderr, "\n");
638 /* Count of rtx's to print with debug_rtx_list.
639 This global exists because gdb user defined commands have no arguments. */
641 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
643 /* Call this function to print list from X on.
645 N is a count of the rtx's to print. Positive values print from the specified
646 rtx on. Negative values print a window around the rtx.
647 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
650 debug_rtx_list (x, n)
657 count = n == 0 ? 1 : n < 0 ? -n : n;
659 /* If we are printing a window, back up to the start. */
662 for (i = count / 2; i > 0; i--)
664 if (PREV_INSN (x) == 0)
669 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
672 fprintf (stderr, "\n");
676 /* Call this function to print an rtx list from START to END inclusive. */
679 debug_rtx_range (start, end)
685 fprintf (stderr, "\n");
686 if (!start || start == end)
688 start = NEXT_INSN (start);
692 /* Call this function to search an rtx list to find one with insn uid UID,
693 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
694 The found insn is returned to enable further debugging analysis. */
697 debug_rtx_find (x, uid)
701 while (x != 0 && INSN_UID (x) != uid)
705 debug_rtx_list (x, debug_rtx_count);
710 fprintf (stderr, "insn uid %d not found\n", uid);
715 /* External entry point for printing a chain of insns
716 starting with RTX_FIRST onto file OUTF.
717 A blank line separates insns.
719 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
722 print_rtl (outf, rtx_first)
733 fputs (print_rtx_head, outf);
734 fputs ("(nil)\n", outf);
737 switch (GET_CODE (rtx_first))
745 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
746 if (! flag_dump_unnumbered
747 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
749 fputs (print_rtx_head, outfile);
751 fprintf (outfile, "\n");
756 fputs (print_rtx_head, outfile);
757 print_rtx (rtx_first);
761 /* Like print_rtx, except specify a file. */
762 /* Return nonzero if we actually printed anything. */
765 print_rtl_single (outf, x)
771 if (! flag_dump_unnumbered
772 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
774 fputs (print_rtx_head, outfile);
783 /* Like print_rtl except without all the detail; for example,
784 if RTX is a CONST_INT then print in decimal format. */
787 print_simple_rtl (outf, x)