2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003,
3 2004, 2005, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This file is compiled twice: once for the generator programs,
23 once for the compiler. */
31 #include "coretypes.h"
35 /* These headers all define things which are not available in
36 generator programs. */
37 #ifndef GENERATOR_FILE
41 #include "hard-reg-set.h"
42 #include "basic-block.h"
43 #include "diagnostic.h"
49 static int sawclose = 0;
53 static void print_rtx (const_rtx);
55 /* String printed at beginning of each RTL when it is dumped.
56 This string is set to ASM_COMMENT_START when the RTL is dumped in
57 the assembly output file. */
58 const char *print_rtx_head = "";
60 /* Nonzero means suppress output of instruction numbers
62 This must be defined here so that programs like gencodes can be linked. */
63 int flag_dump_unnumbered = 0;
65 /* Nonzero means suppress output of instruction numbers for previous
66 and next insns in debugging dumps.
67 This must be defined here so that programs like gencodes can be linked. */
68 int flag_dump_unnumbered_links = 0;
70 /* Nonzero means use simplified format without flags, modes, etc. */
73 /* Nonzero if we are dumping graphical description. */
76 #ifndef GENERATOR_FILE
78 print_mem_expr (FILE *outfile, const_tree expr)
81 print_generic_expr (outfile, CONST_CAST_TREE (expr), 0);
85 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
88 print_rtx (const_rtx in_rtx)
92 const char *format_ptr;
100 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
106 fputs ("(nil)", outfile);
110 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
112 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
117 is_insn = INSN_P (in_rtx);
119 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
120 in separate nodes and therefore have to handle them special here. */
122 && (is_insn || NOTE_P (in_rtx)
123 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
130 /* Print name of expression code. */
131 if (flag_simple && CONST_INT_P (in_rtx))
132 fputc ('(', outfile);
134 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
138 if (RTX_FLAG (in_rtx, in_struct))
139 fputs ("/s", outfile);
141 if (RTX_FLAG (in_rtx, volatil))
142 fputs ("/v", outfile);
144 if (RTX_FLAG (in_rtx, unchanging))
145 fputs ("/u", outfile);
147 if (RTX_FLAG (in_rtx, frame_related))
148 fputs ("/f", outfile);
150 if (RTX_FLAG (in_rtx, jump))
151 fputs ("/j", outfile);
153 if (RTX_FLAG (in_rtx, call))
154 fputs ("/c", outfile);
156 if (RTX_FLAG (in_rtx, return_val))
157 fputs ("/i", outfile);
159 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
160 if ((GET_CODE (in_rtx) == EXPR_LIST
161 || GET_CODE (in_rtx) == INSN_LIST)
162 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX)
163 fprintf (outfile, ":%s",
164 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
166 /* For other rtl, print the mode if it's not VOID. */
167 else if (GET_MODE (in_rtx) != VOIDmode)
168 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
170 #ifndef GENERATOR_FILE
171 if (GET_CODE (in_rtx) == VAR_LOCATION)
173 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
174 fputs (" <debug string placeholder>", outfile);
176 print_mem_expr (outfile, PAT_VAR_LOCATION_DECL (in_rtx));
177 fputc (' ', outfile);
178 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
179 if (PAT_VAR_LOCATION_STATUS (in_rtx)
180 == VAR_INIT_STATUS_UNINITIALIZED)
181 fprintf (outfile, " [uninit]");
183 i = GET_RTX_LENGTH (VAR_LOCATION);
189 #ifndef GENERATOR_FILE
190 if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
194 /* Get the format string and skip the first elements if we have handled
196 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
197 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
198 switch (*format_ptr++)
203 str = XTMPL (in_rtx, i);
208 str = XSTR (in_rtx, i);
212 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
216 fprintf (outfile, " (\\\"%s\\\")", str);
218 fprintf (outfile, " (\"%s\")", str);
223 /* 0 indicates a field for internal use that should not be printed.
224 An exception is the third field of a NOTE, where it indicates
225 that the field has several different valid contents. */
227 if (i == 1 && REG_P (in_rtx))
229 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
230 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
232 #ifndef GENERATOR_FILE
233 else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
235 int flags = SYMBOL_REF_FLAGS (in_rtx);
237 fprintf (outfile, " [flags 0x%x]", flags);
239 else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
241 tree decl = SYMBOL_REF_DECL (in_rtx);
243 print_node_brief (outfile, "", decl, 0);
246 else if (i == 4 && NOTE_P (in_rtx))
248 switch (NOTE_KIND (in_rtx))
250 case NOTE_INSN_EH_REGION_BEG:
251 case NOTE_INSN_EH_REGION_END:
252 if (flag_dump_unnumbered)
253 fprintf (outfile, " #");
255 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
259 case NOTE_INSN_BLOCK_BEG:
260 case NOTE_INSN_BLOCK_END:
261 #ifndef GENERATOR_FILE
262 dump_addr (outfile, " ", NOTE_BLOCK (in_rtx));
267 case NOTE_INSN_BASIC_BLOCK:
269 #ifndef GENERATOR_FILE
270 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
272 fprintf (outfile, " [bb %d]", bb->index);
277 case NOTE_INSN_DELETED_LABEL:
279 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
281 fprintf (outfile, " (\"%s\")", label);
283 fprintf (outfile, " \"\"");
287 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
289 #ifndef GENERATOR_FILE
290 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
292 fprintf (outfile, " [bb %d]", bb->index);
297 case NOTE_INSN_VAR_LOCATION:
298 #ifndef GENERATOR_FILE
299 fputc (' ', outfile);
300 print_rtx (NOTE_VAR_LOCATION (in_rtx));
308 else if (i == 9 && JUMP_P (in_rtx) && XEXP (in_rtx, i) != NULL)
309 /* Output the JUMP_LABEL reference. */
310 fprintf (outfile, "\n -> %d", INSN_UID (XEXP (in_rtx, i)));
311 else if (i == 0 && GET_CODE (in_rtx) == VALUE)
313 #ifndef GENERATOR_FILE
314 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
316 fprintf (outfile, " %i", val->value);
317 dump_addr (outfile, " @", in_rtx);
318 dump_addr (outfile, "/", (void*)val);
327 fprintf (outfile, " ");
328 print_rtx (XEXP (in_rtx, i));
337 fprintf (outfile, "\n%s%*s",
338 print_rtx_head, indent * 2, "");
341 fputs (" [", outfile);
342 if (NULL != XVEC (in_rtx, i))
345 if (XVECLEN (in_rtx, i))
348 for (j = 0; j < XVECLEN (in_rtx, i); j++)
349 print_rtx (XVECEXP (in_rtx, i, j));
354 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
356 fputs ("]", outfile);
363 fprintf (outfile, " ");
364 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
366 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
367 (unsigned HOST_WIDE_INT) XWINT (in_rtx, i));
371 if (i == 4 && INSN_P (in_rtx))
373 #ifndef GENERATOR_FILE
374 /* Pretty-print insn locators. Ignore scoping as it is mostly
375 redundant with line number information and do not print anything
376 when there is no location information available. */
377 if (INSN_LOCATOR (in_rtx) && insn_file (in_rtx))
378 fprintf(outfile, " %s:%i", insn_file (in_rtx), insn_line (in_rtx));
381 else if (i == 6 && NOTE_P (in_rtx))
383 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
384 other times often contains garbage from INSN->NOTE death. */
385 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL)
386 fprintf (outfile, " %d", XINT (in_rtx, i));
390 int value = XINT (in_rtx, i);
393 #ifndef GENERATOR_FILE
394 if (REG_P (in_rtx) && value < FIRST_PSEUDO_REGISTER)
395 fprintf (outfile, " %d %s", REGNO (in_rtx),
396 reg_names[REGNO (in_rtx)]);
397 else if (REG_P (in_rtx)
398 && value <= LAST_VIRTUAL_REGISTER)
400 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
401 fprintf (outfile, " %d virtual-incoming-args", value);
402 else if (value == VIRTUAL_STACK_VARS_REGNUM)
403 fprintf (outfile, " %d virtual-stack-vars", value);
404 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
405 fprintf (outfile, " %d virtual-stack-dynamic", value);
406 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
407 fprintf (outfile, " %d virtual-outgoing-args", value);
408 else if (value == VIRTUAL_CFA_REGNUM)
409 fprintf (outfile, " %d virtual-cfa", value);
411 fprintf (outfile, " %d virtual-reg-%d", value,
412 value-FIRST_VIRTUAL_REGISTER);
416 if (flag_dump_unnumbered
417 && (is_insn || NOTE_P (in_rtx)))
418 fputc ('#', outfile);
420 fprintf (outfile, " %d", value);
422 #ifndef GENERATOR_FILE
423 if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
425 fputs (" [", outfile);
426 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
427 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
428 if (REG_EXPR (in_rtx))
429 print_mem_expr (outfile, REG_EXPR (in_rtx));
431 if (REG_OFFSET (in_rtx))
432 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
433 REG_OFFSET (in_rtx));
434 fputs (" ]", outfile);
438 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
439 && XINT (in_rtx, i) >= 0
440 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
441 fprintf (outfile, " {%s}", name);
446 /* Print NOTE_INSN names rather than integer codes. */
449 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
454 if (XEXP (in_rtx, i) != NULL)
456 rtx sub = XEXP (in_rtx, i);
457 enum rtx_code subc = GET_CODE (sub);
459 if (GET_CODE (in_rtx) == LABEL_REF)
462 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
464 if (flag_dump_unnumbered)
465 fprintf (outfile, " [# deleted]");
467 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
472 if (subc != CODE_LABEL)
476 if (flag_dump_unnumbered
477 || (flag_dump_unnumbered_links && (i == 1 || i == 2)
478 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
479 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
480 fputs (" #", outfile);
482 fprintf (outfile, " %d", INSN_UID (sub));
485 fputs (" 0", outfile);
490 #ifndef GENERATOR_FILE
491 if (XBITMAP (in_rtx, i) == NULL)
492 fputs (" {null}", outfile);
494 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
500 #ifndef GENERATOR_FILE
501 dump_addr (outfile, " ", XTREE (in_rtx, i));
506 fputs (" Unknown", outfile);
511 #ifndef GENERATOR_FILE
512 if (XBBDEF (in_rtx, i))
513 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
521 switch (GET_CODE (in_rtx))
523 #ifndef GENERATOR_FILE
525 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC,
526 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
528 if (MEM_EXPR (in_rtx))
529 print_mem_expr (outfile, MEM_EXPR (in_rtx));
531 if (MEM_OFFSET (in_rtx))
532 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
533 INTVAL (MEM_OFFSET (in_rtx)));
535 if (MEM_SIZE (in_rtx))
536 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC,
537 INTVAL (MEM_SIZE (in_rtx)));
539 if (MEM_ALIGN (in_rtx) != 1)
540 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
542 fputc (']', outfile);
546 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
550 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
552 fprintf (outfile, " %s", s);
554 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
556 fprintf (outfile, " [%s]", s);
562 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
563 switch (LABEL_KIND (in_rtx))
565 case LABEL_NORMAL: break;
566 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
567 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
568 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
569 default: gcc_unreachable ();
578 && (is_insn || NOTE_P (in_rtx)
579 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
583 fputc (')', outfile);
588 /* Print an rtx on the current line of FILE. Initially indent IND
592 print_inline_rtx (FILE *outf, const_rtx x, int ind)
594 int oldsaw = sawclose;
595 int oldindent = indent;
605 /* Call this function from the debugger to see what X looks like. */
608 debug_rtx (const_rtx x)
613 fprintf (stderr, "\n");
616 /* Count of rtx's to print with debug_rtx_list.
617 This global exists because gdb user defined commands have no arguments. */
619 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
621 /* Call this function to print list from X on.
623 N is a count of the rtx's to print. Positive values print from the specified
624 rtx on. Negative values print a window around the rtx.
625 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
628 debug_rtx_list (const_rtx x, int n)
633 count = n == 0 ? 1 : n < 0 ? -n : n;
635 /* If we are printing a window, back up to the start. */
638 for (i = count / 2; i > 0; i--)
640 if (PREV_INSN (x) == 0)
645 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
648 fprintf (stderr, "\n");
652 /* Call this function to print an rtx list from START to END inclusive. */
655 debug_rtx_range (const_rtx start, const_rtx end)
660 fprintf (stderr, "\n");
661 if (!start || start == end)
663 start = NEXT_INSN (start);
667 /* Call this function to search an rtx list to find one with insn uid UID,
668 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
669 The found insn is returned to enable further debugging analysis. */
672 debug_rtx_find (const_rtx x, int uid)
674 while (x != 0 && INSN_UID (x) != uid)
678 debug_rtx_list (x, debug_rtx_count);
683 fprintf (stderr, "insn uid %d not found\n", uid);
688 /* External entry point for printing a chain of insns
689 starting with RTX_FIRST onto file OUTF.
690 A blank line separates insns.
692 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
695 print_rtl (FILE *outf, const_rtx rtx_first)
704 fputs (print_rtx_head, outf);
705 fputs ("(nil)\n", outf);
708 switch (GET_CODE (rtx_first))
716 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
718 fputs (print_rtx_head, outfile);
720 fprintf (outfile, "\n");
725 fputs (print_rtx_head, outfile);
726 print_rtx (rtx_first);
730 /* Like print_rtx, except specify a file. */
731 /* Return nonzero if we actually printed anything. */
734 print_rtl_single (FILE *outf, const_rtx x)
738 fputs (print_rtx_head, outfile);
745 /* Like print_rtl except without all the detail; for example,
746 if RTX is a CONST_INT then print in decimal format. */
749 print_simple_rtl (FILE *outf, const_rtx x)