2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003,
3 2004, 2005, 2007, 2008, 2009, 2010, 2011
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
40 #include "hard-reg-set.h"
41 #include "basic-block.h"
42 #include "diagnostic.h"
43 #include "tree-pretty-print.h"
45 #include "dumpfile.h" /* for dump_flags */
46 #include "dwarf2out.h"
51 static int sawclose = 0;
55 static void print_rtx (const_rtx);
57 /* String printed at beginning of each RTL when it is dumped.
58 This string is set to ASM_COMMENT_START when the RTL is dumped in
59 the assembly output file. */
60 const char *print_rtx_head = "";
63 /* These are defined from the .opt file when not used in generator
66 /* Nonzero means suppress output of instruction numbers
68 This must be defined here so that programs like gencodes can be linked. */
69 int flag_dump_unnumbered = 0;
71 /* Nonzero means suppress output of instruction numbers for previous
72 and next insns in debugging dumps.
73 This must be defined here so that programs like gencodes can be linked. */
74 int flag_dump_unnumbered_links = 0;
77 /* Nonzero means use simplified format without flags, modes, etc. */
80 /* Nonzero if we are dumping graphical description. */
83 #ifndef GENERATOR_FILE
85 print_mem_expr (FILE *outfile, const_tree expr)
88 print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
92 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
95 print_rtx (const_rtx in_rtx)
99 const char *format_ptr;
105 fputc (' ', outfile);
107 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
113 fputs ("(nil)", outfile);
117 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
119 fprintf (outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
120 print_rtx_head, indent * 2, "");
125 is_insn = INSN_P (in_rtx);
127 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
128 in separate nodes and therefore have to handle them special here. */
130 && (is_insn || NOTE_P (in_rtx)
131 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
138 /* Print name of expression code. */
139 if (flag_simple && CONST_INT_P (in_rtx))
140 fputc ('(', outfile);
142 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
146 if (RTX_FLAG (in_rtx, in_struct))
147 fputs ("/s", outfile);
149 if (RTX_FLAG (in_rtx, volatil))
150 fputs ("/v", outfile);
152 if (RTX_FLAG (in_rtx, unchanging))
153 fputs ("/u", outfile);
155 if (RTX_FLAG (in_rtx, frame_related))
156 fputs ("/f", outfile);
158 if (RTX_FLAG (in_rtx, jump))
159 fputs ("/j", outfile);
161 if (RTX_FLAG (in_rtx, call))
162 fputs ("/c", outfile);
164 if (RTX_FLAG (in_rtx, return_val))
165 fputs ("/i", outfile);
167 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
168 if ((GET_CODE (in_rtx) == EXPR_LIST
169 || GET_CODE (in_rtx) == INSN_LIST)
170 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX)
171 fprintf (outfile, ":%s",
172 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
174 /* For other rtl, print the mode if it's not VOID. */
175 else if (GET_MODE (in_rtx) != VOIDmode)
176 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
178 #ifndef GENERATOR_FILE
179 if (GET_CODE (in_rtx) == VAR_LOCATION)
181 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
182 fputs (" <debug string placeholder>", outfile);
184 print_mem_expr (outfile, PAT_VAR_LOCATION_DECL (in_rtx));
185 fputc (' ', outfile);
186 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
187 if (PAT_VAR_LOCATION_STATUS (in_rtx)
188 == VAR_INIT_STATUS_UNINITIALIZED)
189 fprintf (outfile, " [uninit]");
191 i = GET_RTX_LENGTH (VAR_LOCATION);
197 #ifndef GENERATOR_FILE
198 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx))
202 /* Get the format string and skip the first elements if we have handled
204 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
205 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
206 switch (*format_ptr++)
211 str = XTMPL (in_rtx, i);
216 str = XSTR (in_rtx, i);
220 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
224 fprintf (outfile, " (\\\"%s\\\")", str);
226 fprintf (outfile, " (\"%s\")", str);
231 /* 0 indicates a field for internal use that should not be printed.
232 An exception is the third field of a NOTE, where it indicates
233 that the field has several different valid contents. */
235 if (i == 1 && REG_P (in_rtx))
237 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
238 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
240 #ifndef GENERATOR_FILE
241 else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
243 int flags = SYMBOL_REF_FLAGS (in_rtx);
245 fprintf (outfile, " [flags %#x]", flags);
247 else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
249 tree decl = SYMBOL_REF_DECL (in_rtx);
251 print_node_brief (outfile, "", decl, dump_flags);
254 else if (i == 4 && NOTE_P (in_rtx))
256 switch (NOTE_KIND (in_rtx))
258 case NOTE_INSN_EH_REGION_BEG:
259 case NOTE_INSN_EH_REGION_END:
260 if (flag_dump_unnumbered)
261 fprintf (outfile, " #");
263 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
267 case NOTE_INSN_BLOCK_BEG:
268 case NOTE_INSN_BLOCK_END:
269 #ifndef GENERATOR_FILE
270 dump_addr (outfile, " ", NOTE_BLOCK (in_rtx));
275 case NOTE_INSN_BASIC_BLOCK:
277 #ifndef GENERATOR_FILE
278 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
280 fprintf (outfile, " [bb %d]", bb->index);
285 case NOTE_INSN_DELETED_LABEL:
286 case NOTE_INSN_DELETED_DEBUG_LABEL:
288 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
290 fprintf (outfile, " (\"%s\")", label);
292 fprintf (outfile, " \"\"");
296 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
298 #ifndef GENERATOR_FILE
299 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
301 fprintf (outfile, " [bb %d]", bb->index);
306 case NOTE_INSN_VAR_LOCATION:
307 case NOTE_INSN_CALL_ARG_LOCATION:
308 #ifndef GENERATOR_FILE
309 fputc (' ', outfile);
310 print_rtx (NOTE_VAR_LOCATION (in_rtx));
315 #ifndef GENERATOR_FILE
316 fputc ('\n', outfile);
317 output_cfi_directive (outfile, NOTE_CFI (in_rtx));
318 fputc ('\t', outfile);
326 else if (i == 8 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL)
328 /* Output the JUMP_LABEL reference. */
329 fprintf (outfile, "\n%s%*s -> ", print_rtx_head, indent * 2, "");
330 if (GET_CODE (JUMP_LABEL (in_rtx)) == RETURN)
331 fprintf (outfile, "return");
332 else if (GET_CODE (JUMP_LABEL (in_rtx)) == SIMPLE_RETURN)
333 fprintf (outfile, "simple_return");
335 fprintf (outfile, "%d", INSN_UID (JUMP_LABEL (in_rtx)));
337 else if (i == 0 && GET_CODE (in_rtx) == VALUE)
339 #ifndef GENERATOR_FILE
340 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
342 fprintf (outfile, " %u:%u", val->uid, val->hash);
343 dump_addr (outfile, " @", in_rtx);
344 dump_addr (outfile, "/", (void*)val);
347 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
349 #ifndef GENERATOR_FILE
350 fprintf (outfile, " D#%i",
351 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
354 else if (i == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
358 fprintf (outfile, " ");
359 print_rtx (ENTRY_VALUE_EXP (in_rtx));
367 if (i == 7 && INSN_P (in_rtx))
368 /* Put REG_NOTES on their own line. */
369 fprintf (outfile, "\n%s%*s",
370 print_rtx_head, indent * 2, "");
372 fprintf (outfile, " ");
373 print_rtx (XEXP (in_rtx, i));
382 fprintf (outfile, "\n%s%*s",
383 print_rtx_head, indent * 2, "");
386 fputs (" [", outfile);
387 if (NULL != XVEC (in_rtx, i))
390 if (XVECLEN (in_rtx, i))
393 for (j = 0; j < XVECLEN (in_rtx, i); j++)
394 print_rtx (XVECEXP (in_rtx, i, j));
399 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
401 fputs ("]", outfile);
408 fprintf (outfile, " ");
409 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
411 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
412 (unsigned HOST_WIDE_INT) XWINT (in_rtx, i));
416 if (i == 5 && INSN_P (in_rtx))
418 #ifndef GENERATOR_FILE
419 /* Pretty-print insn locations. Ignore scoping as it is mostly
420 redundant with line number information and do not print anything
421 when there is no location information available. */
422 if (INSN_LOCATION (in_rtx) && insn_file (in_rtx))
423 fprintf(outfile, " %s:%i", insn_file (in_rtx), insn_line (in_rtx));
426 else if (i == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
428 #ifndef GENERATOR_FILE
429 fprintf (outfile, " %s:%i",
430 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
431 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
434 else if (i == 1 && GET_CODE (in_rtx) == ASM_INPUT)
436 #ifndef GENERATOR_FILE
437 fprintf (outfile, " %s:%i",
438 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
439 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
442 else if (i == 6 && NOTE_P (in_rtx))
444 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
445 other times often contains garbage from INSN->NOTE death. */
446 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL
447 || NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_DEBUG_LABEL)
448 fprintf (outfile, " %d", XINT (in_rtx, i));
450 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
452 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
453 && XINT (in_rtx, 1) >= 0
454 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
455 fprintf (outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
457 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
459 && (GET_CODE (in_rtx) == UNSPEC
460 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
461 && XINT (in_rtx, 1) >= 0
462 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
463 fprintf (outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
467 int value = XINT (in_rtx, i);
470 #ifndef GENERATOR_FILE
471 if (REG_P (in_rtx) && (unsigned) value < FIRST_PSEUDO_REGISTER)
472 fprintf (outfile, " %d %s", value, reg_names[value]);
473 else if (REG_P (in_rtx)
474 && (unsigned) value <= LAST_VIRTUAL_REGISTER)
476 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
477 fprintf (outfile, " %d virtual-incoming-args", value);
478 else if (value == VIRTUAL_STACK_VARS_REGNUM)
479 fprintf (outfile, " %d virtual-stack-vars", value);
480 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
481 fprintf (outfile, " %d virtual-stack-dynamic", value);
482 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
483 fprintf (outfile, " %d virtual-outgoing-args", value);
484 else if (value == VIRTUAL_CFA_REGNUM)
485 fprintf (outfile, " %d virtual-cfa", value);
486 else if (value == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
487 fprintf (outfile, " %d virtual-preferred-stack-boundary",
490 fprintf (outfile, " %d virtual-reg-%d", value,
491 value-FIRST_VIRTUAL_REGISTER);
495 if (flag_dump_unnumbered
496 && (is_insn || NOTE_P (in_rtx)))
497 fputc ('#', outfile);
499 fprintf (outfile, " %d", value);
501 #ifndef GENERATOR_FILE
502 if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
504 fputs (" [", outfile);
505 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
506 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
507 if (REG_EXPR (in_rtx))
508 print_mem_expr (outfile, REG_EXPR (in_rtx));
510 if (REG_OFFSET (in_rtx))
511 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
512 REG_OFFSET (in_rtx));
513 fputs (" ]", outfile);
517 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
518 && XINT (in_rtx, i) >= 0
519 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
520 fprintf (outfile, " {%s}", name);
525 /* Print NOTE_INSN names rather than integer codes. */
528 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
533 if (XEXP (in_rtx, i) != NULL)
535 rtx sub = XEXP (in_rtx, i);
536 enum rtx_code subc = GET_CODE (sub);
538 if (GET_CODE (in_rtx) == LABEL_REF)
541 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
543 if (flag_dump_unnumbered)
544 fprintf (outfile, " [# deleted]");
546 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
551 if (subc != CODE_LABEL)
555 if (flag_dump_unnumbered
556 || (flag_dump_unnumbered_links && (i == 1 || i == 2)
557 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
558 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
559 fputs (" #", outfile);
561 fprintf (outfile, " %d", INSN_UID (sub));
564 fputs (" 0", outfile);
569 #ifndef GENERATOR_FILE
570 if (i == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
571 print_mem_expr (outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
572 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
573 print_mem_expr (outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
575 dump_addr (outfile, " ", XTREE (in_rtx, i));
580 fputs (" Unknown", outfile);
585 #ifndef GENERATOR_FILE
586 if (XBBDEF (in_rtx, i))
587 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
595 switch (GET_CODE (in_rtx))
597 #ifndef GENERATOR_FILE
599 if (__builtin_expect (final_insns_dump_p, false))
600 fprintf (outfile, " [");
602 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC,
603 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
605 if (MEM_EXPR (in_rtx))
606 print_mem_expr (outfile, MEM_EXPR (in_rtx));
608 if (MEM_OFFSET_KNOWN_P (in_rtx))
609 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC, MEM_OFFSET (in_rtx));
611 if (MEM_SIZE_KNOWN_P (in_rtx))
612 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC, MEM_SIZE (in_rtx));
614 if (MEM_ALIGN (in_rtx) != 1)
615 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
617 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
618 fprintf (outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
620 fputc (']', outfile);
624 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
628 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
630 fprintf (outfile, " %s", s);
632 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
634 fprintf (outfile, " [%s]", s);
640 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
641 switch (LABEL_KIND (in_rtx))
643 case LABEL_NORMAL: break;
644 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
645 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
646 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
647 default: gcc_unreachable ();
656 && (is_insn || NOTE_P (in_rtx)
657 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
661 fputc (')', outfile);
666 /* Print an rtx on the current line of FILE. Initially indent IND
670 print_inline_rtx (FILE *outf, const_rtx x, int ind)
672 int oldsaw = sawclose;
673 int oldindent = indent;
683 /* Call this function from the debugger to see what X looks like. */
686 debug_rtx (const_rtx x)
691 fprintf (stderr, "\n");
694 /* Count of rtx's to print with debug_rtx_list.
695 This global exists because gdb user defined commands have no arguments. */
697 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
699 /* Call this function to print list from X on.
701 N is a count of the rtx's to print. Positive values print from the specified
702 rtx on. Negative values print a window around the rtx.
703 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
706 debug_rtx_list (const_rtx x, int n)
711 count = n == 0 ? 1 : n < 0 ? -n : n;
713 /* If we are printing a window, back up to the start. */
716 for (i = count / 2; i > 0; i--)
718 if (PREV_INSN (x) == 0)
723 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
726 fprintf (stderr, "\n");
730 /* Call this function to print an rtx list from START to END inclusive. */
733 debug_rtx_range (const_rtx start, const_rtx end)
738 fprintf (stderr, "\n");
739 if (!start || start == end)
741 start = NEXT_INSN (start);
745 /* Call this function to search an rtx list to find one with insn uid UID,
746 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
747 The found insn is returned to enable further debugging analysis. */
749 DEBUG_FUNCTION const_rtx
750 debug_rtx_find (const_rtx x, int uid)
752 while (x != 0 && INSN_UID (x) != uid)
756 debug_rtx_list (x, debug_rtx_count);
761 fprintf (stderr, "insn uid %d not found\n", uid);
766 /* External entry point for printing a chain of insns
767 starting with RTX_FIRST onto file OUTF.
768 A blank line separates insns.
770 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
773 print_rtl (FILE *outf, const_rtx rtx_first)
782 fputs (print_rtx_head, outf);
783 fputs ("(nil)\n", outf);
786 switch (GET_CODE (rtx_first))
794 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
796 fputs (print_rtx_head, outfile);
798 fprintf (outfile, "\n");
803 fputs (print_rtx_head, outfile);
804 print_rtx (rtx_first);
808 /* Like print_rtx, except specify a file. */
809 /* Return nonzero if we actually printed anything. */
812 print_rtl_single (FILE *outf, const_rtx x)
814 return print_rtl_single_with_indent (outf, x, 0);
817 /* Like print_rtl_single, except specify a file and indentation. */
820 print_rtl_single_with_indent (FILE *outf, const_rtx x, int ind)
822 int old_indent = indent;
823 char *s_indent = (char *) alloca ((size_t) ind + 1);
824 memset ((void *) s_indent, ' ', (size_t) ind);
825 s_indent[ind] = '\0';
830 fputs (s_indent, outfile);
831 fputs (print_rtx_head, outfile);
839 /* Like print_rtl except without all the detail; for example,
840 if RTX is a CONST_INT then print in decimal format. */
843 print_simple_rtl (FILE *outf, const_rtx x)