2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003,
3 2004, 2005, 2007, 2008, 2009, 2010
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 "tree-pass.h"
50 static int sawclose
= 0;
54 static void print_rtx (const_rtx
);
56 /* String printed at beginning of each RTL when it is dumped.
57 This string is set to ASM_COMMENT_START when the RTL is dumped in
58 the assembly output file. */
59 const char *print_rtx_head
= "";
61 /* Nonzero means suppress output of instruction numbers
63 This must be defined here so that programs like gencodes can be linked. */
64 int flag_dump_unnumbered
= 0;
66 /* Nonzero means suppress output of instruction numbers for previous
67 and next insns in debugging dumps.
68 This must be defined here so that programs like gencodes can be linked. */
69 int flag_dump_unnumbered_links
= 0;
71 /* Nonzero means use simplified format without flags, modes, etc. */
74 /* Nonzero if we are dumping graphical description. */
77 #ifndef GENERATOR_FILE
79 print_mem_expr (FILE *outfile
, const_tree expr
)
82 print_generic_expr (outfile
, CONST_CAST_TREE (expr
), dump_flags
);
86 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
89 print_rtx (const_rtx in_rtx
)
93 const char *format_ptr
;
101 fprintf (outfile
, "\n%s%*s", print_rtx_head
, indent
* 2, "");
107 fputs ("(nil)", outfile
);
111 else if (GET_CODE (in_rtx
) > NUM_RTX_CODE
)
113 fprintf (outfile
, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx
),
114 print_rtx_head
, indent
* 2, "");
119 is_insn
= INSN_P (in_rtx
);
121 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
122 in separate nodes and therefore have to handle them special here. */
124 && (is_insn
|| NOTE_P (in_rtx
)
125 || LABEL_P (in_rtx
) || BARRIER_P (in_rtx
)))
132 /* Print name of expression code. */
133 if (flag_simple
&& CONST_INT_P (in_rtx
))
134 fputc ('(', outfile
);
136 fprintf (outfile
, "(%s", GET_RTX_NAME (GET_CODE (in_rtx
)));
140 if (RTX_FLAG (in_rtx
, in_struct
))
141 fputs ("/s", outfile
);
143 if (RTX_FLAG (in_rtx
, volatil
))
144 fputs ("/v", outfile
);
146 if (RTX_FLAG (in_rtx
, unchanging
))
147 fputs ("/u", outfile
);
149 if (RTX_FLAG (in_rtx
, frame_related
))
150 fputs ("/f", outfile
);
152 if (RTX_FLAG (in_rtx
, jump
))
153 fputs ("/j", outfile
);
155 if (RTX_FLAG (in_rtx
, call
))
156 fputs ("/c", outfile
);
158 if (RTX_FLAG (in_rtx
, return_val
))
159 fputs ("/i", outfile
);
161 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
162 if ((GET_CODE (in_rtx
) == EXPR_LIST
163 || GET_CODE (in_rtx
) == INSN_LIST
)
164 && (int)GET_MODE (in_rtx
) < REG_NOTE_MAX
)
165 fprintf (outfile
, ":%s",
166 GET_REG_NOTE_NAME (GET_MODE (in_rtx
)));
168 /* For other rtl, print the mode if it's not VOID. */
169 else if (GET_MODE (in_rtx
) != VOIDmode
)
170 fprintf (outfile
, ":%s", GET_MODE_NAME (GET_MODE (in_rtx
)));
172 #ifndef GENERATOR_FILE
173 if (GET_CODE (in_rtx
) == VAR_LOCATION
)
175 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx
)) == STRING_CST
)
176 fputs (" <debug string placeholder>", outfile
);
178 print_mem_expr (outfile
, PAT_VAR_LOCATION_DECL (in_rtx
));
179 fputc (' ', outfile
);
180 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx
));
181 if (PAT_VAR_LOCATION_STATUS (in_rtx
)
182 == VAR_INIT_STATUS_UNINITIALIZED
)
183 fprintf (outfile
, " [uninit]");
185 i
= GET_RTX_LENGTH (VAR_LOCATION
);
191 #ifndef GENERATOR_FILE
192 if (GET_CODE (in_rtx
) == CONST_DOUBLE
&& FLOAT_MODE_P (GET_MODE (in_rtx
)))
196 /* Get the format string and skip the first elements if we have handled
198 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
)) + i
;
199 for (; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
200 switch (*format_ptr
++)
205 str
= XTMPL (in_rtx
, i
);
210 str
= XSTR (in_rtx
, i
);
214 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
218 fprintf (outfile
, " (\\\"%s\\\")", str
);
220 fprintf (outfile
, " (\"%s\")", str
);
225 /* 0 indicates a field for internal use that should not be printed.
226 An exception is the third field of a NOTE, where it indicates
227 that the field has several different valid contents. */
229 if (i
== 1 && REG_P (in_rtx
))
231 if (REGNO (in_rtx
) != ORIGINAL_REGNO (in_rtx
))
232 fprintf (outfile
, " [%d]", ORIGINAL_REGNO (in_rtx
));
234 #ifndef GENERATOR_FILE
235 else if (i
== 1 && GET_CODE (in_rtx
) == SYMBOL_REF
)
237 int flags
= SYMBOL_REF_FLAGS (in_rtx
);
239 fprintf (outfile
, " [flags %#x]", flags
);
241 else if (i
== 2 && GET_CODE (in_rtx
) == SYMBOL_REF
)
243 tree decl
= SYMBOL_REF_DECL (in_rtx
);
245 print_node_brief (outfile
, "", decl
, dump_flags
);
248 else if (i
== 4 && NOTE_P (in_rtx
))
250 switch (NOTE_KIND (in_rtx
))
252 case NOTE_INSN_EH_REGION_BEG
:
253 case NOTE_INSN_EH_REGION_END
:
254 if (flag_dump_unnumbered
)
255 fprintf (outfile
, " #");
257 fprintf (outfile
, " %d", NOTE_EH_HANDLER (in_rtx
));
261 case NOTE_INSN_BLOCK_BEG
:
262 case NOTE_INSN_BLOCK_END
:
263 #ifndef GENERATOR_FILE
264 dump_addr (outfile
, " ", NOTE_BLOCK (in_rtx
));
269 case NOTE_INSN_BASIC_BLOCK
:
271 #ifndef GENERATOR_FILE
272 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
274 fprintf (outfile
, " [bb %d]", bb
->index
);
279 case NOTE_INSN_DELETED_LABEL
:
281 const char *label
= NOTE_DELETED_LABEL_NAME (in_rtx
);
283 fprintf (outfile
, " (\"%s\")", label
);
285 fprintf (outfile
, " \"\"");
289 case NOTE_INSN_SWITCH_TEXT_SECTIONS
:
291 #ifndef GENERATOR_FILE
292 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
294 fprintf (outfile
, " [bb %d]", bb
->index
);
299 case NOTE_INSN_VAR_LOCATION
:
300 #ifndef GENERATOR_FILE
301 fputc (' ', outfile
);
302 print_rtx (NOTE_VAR_LOCATION (in_rtx
));
310 else if (i
== 8 && JUMP_P (in_rtx
) && JUMP_LABEL (in_rtx
) != NULL
)
311 /* Output the JUMP_LABEL reference. */
312 fprintf (outfile
, "\n%s%*s -> %d", print_rtx_head
, indent
* 2, "",
313 INSN_UID (JUMP_LABEL (in_rtx
)));
314 else if (i
== 0 && GET_CODE (in_rtx
) == VALUE
)
316 #ifndef GENERATOR_FILE
317 cselib_val
*val
= CSELIB_VAL_PTR (in_rtx
);
319 fprintf (outfile
, " %u:%u", val
->uid
, val
->hash
);
320 dump_addr (outfile
, " @", in_rtx
);
321 dump_addr (outfile
, "/", (void*)val
);
324 else if (i
== 0 && GET_CODE (in_rtx
) == DEBUG_EXPR
)
326 #ifndef GENERATOR_FILE
327 fprintf (outfile
, " D#%i",
328 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx
)));
336 if (i
== 7 && INSN_P (in_rtx
))
337 /* Put REG_NOTES on their own line. */
338 fprintf (outfile
, "\n%s%*s",
339 print_rtx_head
, indent
* 2, "");
341 fprintf (outfile
, " ");
342 print_rtx (XEXP (in_rtx
, i
));
351 fprintf (outfile
, "\n%s%*s",
352 print_rtx_head
, indent
* 2, "");
355 fputs (" [", outfile
);
356 if (NULL
!= XVEC (in_rtx
, i
))
359 if (XVECLEN (in_rtx
, i
))
362 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
363 print_rtx (XVECEXP (in_rtx
, i
, j
));
368 fprintf (outfile
, "\n%s%*s", print_rtx_head
, indent
* 2, "");
370 fputs ("]", outfile
);
377 fprintf (outfile
, " ");
378 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, XWINT (in_rtx
, i
));
380 fprintf (outfile
, " [" HOST_WIDE_INT_PRINT_HEX
"]",
381 (unsigned HOST_WIDE_INT
) XWINT (in_rtx
, i
));
385 if (i
== 5 && INSN_P (in_rtx
))
387 #ifndef GENERATOR_FILE
388 /* Pretty-print insn locators. Ignore scoping as it is mostly
389 redundant with line number information and do not print anything
390 when there is no location information available. */
391 if (INSN_LOCATOR (in_rtx
) && insn_file (in_rtx
))
392 fprintf(outfile
, " %s:%i", insn_file (in_rtx
), insn_line (in_rtx
));
395 else if (i
== 6 && GET_CODE (in_rtx
) == ASM_OPERANDS
)
397 #ifndef GENERATOR_FILE
398 fprintf (outfile
, " %s:%i",
399 locator_file (ASM_OPERANDS_SOURCE_LOCATION (in_rtx
)),
400 locator_line (ASM_OPERANDS_SOURCE_LOCATION (in_rtx
)));
403 else if (i
== 1 && GET_CODE (in_rtx
) == ASM_INPUT
)
405 #ifndef GENERATOR_FILE
406 fprintf (outfile
, " %s:%i",
407 locator_file (ASM_INPUT_SOURCE_LOCATION (in_rtx
)),
408 locator_line (ASM_INPUT_SOURCE_LOCATION (in_rtx
)));
411 else if (i
== 6 && NOTE_P (in_rtx
))
413 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
414 other times often contains garbage from INSN->NOTE death. */
415 if (NOTE_KIND (in_rtx
) == NOTE_INSN_DELETED_LABEL
)
416 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
418 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
420 && GET_CODE (in_rtx
) == UNSPEC_VOLATILE
421 && XINT (in_rtx
, 1) >= 0
422 && XINT (in_rtx
, 1) < NUM_UNSPECV_VALUES
)
423 fprintf (outfile
, " %s", unspecv_strings
[XINT (in_rtx
, 1)]);
425 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
427 && (GET_CODE (in_rtx
) == UNSPEC
428 || GET_CODE (in_rtx
) == UNSPEC_VOLATILE
)
429 && XINT (in_rtx
, 1) >= 0
430 && XINT (in_rtx
, 1) < NUM_UNSPEC_VALUES
)
431 fprintf (outfile
, " %s", unspec_strings
[XINT (in_rtx
, 1)]);
435 int value
= XINT (in_rtx
, i
);
438 #ifndef GENERATOR_FILE
439 if (REG_P (in_rtx
) && value
< FIRST_PSEUDO_REGISTER
)
440 fprintf (outfile
, " %d %s", REGNO (in_rtx
),
441 reg_names
[REGNO (in_rtx
)]);
442 else if (REG_P (in_rtx
)
443 && value
<= LAST_VIRTUAL_REGISTER
)
445 if (value
== VIRTUAL_INCOMING_ARGS_REGNUM
)
446 fprintf (outfile
, " %d virtual-incoming-args", value
);
447 else if (value
== VIRTUAL_STACK_VARS_REGNUM
)
448 fprintf (outfile
, " %d virtual-stack-vars", value
);
449 else if (value
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
450 fprintf (outfile
, " %d virtual-stack-dynamic", value
);
451 else if (value
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
452 fprintf (outfile
, " %d virtual-outgoing-args", value
);
453 else if (value
== VIRTUAL_CFA_REGNUM
)
454 fprintf (outfile
, " %d virtual-cfa", value
);
456 fprintf (outfile
, " %d virtual-reg-%d", value
,
457 value
-FIRST_VIRTUAL_REGISTER
);
461 if (flag_dump_unnumbered
462 && (is_insn
|| NOTE_P (in_rtx
)))
463 fputc ('#', outfile
);
465 fprintf (outfile
, " %d", value
);
467 #ifndef GENERATOR_FILE
468 if (REG_P (in_rtx
) && REG_ATTRS (in_rtx
))
470 fputs (" [", outfile
);
471 if (ORIGINAL_REGNO (in_rtx
) != REGNO (in_rtx
))
472 fprintf (outfile
, "orig:%i", ORIGINAL_REGNO (in_rtx
));
473 if (REG_EXPR (in_rtx
))
474 print_mem_expr (outfile
, REG_EXPR (in_rtx
));
476 if (REG_OFFSET (in_rtx
))
477 fprintf (outfile
, "+" HOST_WIDE_INT_PRINT_DEC
,
478 REG_OFFSET (in_rtx
));
479 fputs (" ]", outfile
);
483 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
484 && XINT (in_rtx
, i
) >= 0
485 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
486 fprintf (outfile
, " {%s}", name
);
491 /* Print NOTE_INSN names rather than integer codes. */
494 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
499 if (XEXP (in_rtx
, i
) != NULL
)
501 rtx sub
= XEXP (in_rtx
, i
);
502 enum rtx_code subc
= GET_CODE (sub
);
504 if (GET_CODE (in_rtx
) == LABEL_REF
)
507 && NOTE_KIND (sub
) == NOTE_INSN_DELETED_LABEL
)
509 if (flag_dump_unnumbered
)
510 fprintf (outfile
, " [# deleted]");
512 fprintf (outfile
, " [%d deleted]", INSN_UID (sub
));
517 if (subc
!= CODE_LABEL
)
521 if (flag_dump_unnumbered
522 || (flag_dump_unnumbered_links
&& (i
== 1 || i
== 2)
523 && (INSN_P (in_rtx
) || NOTE_P (in_rtx
)
524 || LABEL_P (in_rtx
) || BARRIER_P (in_rtx
))))
525 fputs (" #", outfile
);
527 fprintf (outfile
, " %d", INSN_UID (sub
));
530 fputs (" 0", outfile
);
535 #ifndef GENERATOR_FILE
536 dump_addr (outfile
, " ", XTREE (in_rtx
, i
));
541 fputs (" Unknown", outfile
);
546 #ifndef GENERATOR_FILE
547 if (XBBDEF (in_rtx
, i
))
548 fprintf (outfile
, " %i", XBBDEF (in_rtx
, i
)->index
);
556 switch (GET_CODE (in_rtx
))
558 #ifndef GENERATOR_FILE
560 if (__builtin_expect (final_insns_dump_p
, false))
561 fprintf (outfile
, " [");
563 fprintf (outfile
, " [" HOST_WIDE_INT_PRINT_DEC
,
564 (HOST_WIDE_INT
) MEM_ALIAS_SET (in_rtx
));
566 if (MEM_EXPR (in_rtx
))
567 print_mem_expr (outfile
, MEM_EXPR (in_rtx
));
569 if (MEM_OFFSET (in_rtx
))
570 fprintf (outfile
, "+" HOST_WIDE_INT_PRINT_DEC
,
571 INTVAL (MEM_OFFSET (in_rtx
)));
573 if (MEM_SIZE (in_rtx
))
574 fprintf (outfile
, " S" HOST_WIDE_INT_PRINT_DEC
,
575 INTVAL (MEM_SIZE (in_rtx
)));
577 if (MEM_ALIGN (in_rtx
) != 1)
578 fprintf (outfile
, " A%u", MEM_ALIGN (in_rtx
));
580 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx
)))
581 fprintf (outfile
, " AS%u", MEM_ADDR_SPACE (in_rtx
));
583 fputc (']', outfile
);
587 if (FLOAT_MODE_P (GET_MODE (in_rtx
)))
591 real_to_decimal (s
, CONST_DOUBLE_REAL_VALUE (in_rtx
),
593 fprintf (outfile
, " %s", s
);
595 real_to_hexadecimal (s
, CONST_DOUBLE_REAL_VALUE (in_rtx
),
597 fprintf (outfile
, " [%s]", s
);
603 fprintf (outfile
, " [%d uses]", LABEL_NUSES (in_rtx
));
604 switch (LABEL_KIND (in_rtx
))
606 case LABEL_NORMAL
: break;
607 case LABEL_STATIC_ENTRY
: fputs (" [entry]", outfile
); break;
608 case LABEL_GLOBAL_ENTRY
: fputs (" [global entry]", outfile
); break;
609 case LABEL_WEAK_ENTRY
: fputs (" [weak entry]", outfile
); break;
610 default: gcc_unreachable ();
619 && (is_insn
|| NOTE_P (in_rtx
)
620 || LABEL_P (in_rtx
) || BARRIER_P (in_rtx
)))
624 fputc (')', outfile
);
629 /* Print an rtx on the current line of FILE. Initially indent IND
633 print_inline_rtx (FILE *outf
, const_rtx x
, int ind
)
635 int oldsaw
= sawclose
;
636 int oldindent
= indent
;
646 /* Call this function from the debugger to see what X looks like. */
649 debug_rtx (const_rtx x
)
654 fprintf (stderr
, "\n");
657 /* Count of rtx's to print with debug_rtx_list.
658 This global exists because gdb user defined commands have no arguments. */
660 DEBUG_VARIABLE
int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
662 /* Call this function to print list from X on.
664 N is a count of the rtx's to print. Positive values print from the specified
665 rtx on. Negative values print a window around the rtx.
666 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
669 debug_rtx_list (const_rtx x
, int n
)
674 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
676 /* If we are printing a window, back up to the start. */
679 for (i
= count
/ 2; i
> 0; i
--)
681 if (PREV_INSN (x
) == 0)
686 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
689 fprintf (stderr
, "\n");
693 /* Call this function to print an rtx list from START to END inclusive. */
696 debug_rtx_range (const_rtx start
, const_rtx end
)
701 fprintf (stderr
, "\n");
702 if (!start
|| start
== end
)
704 start
= NEXT_INSN (start
);
708 /* Call this function to search an rtx list to find one with insn uid UID,
709 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
710 The found insn is returned to enable further debugging analysis. */
712 DEBUG_FUNCTION const_rtx
713 debug_rtx_find (const_rtx x
, int uid
)
715 while (x
!= 0 && INSN_UID (x
) != uid
)
719 debug_rtx_list (x
, debug_rtx_count
);
724 fprintf (stderr
, "insn uid %d not found\n", uid
);
729 /* External entry point for printing a chain of insns
730 starting with RTX_FIRST onto file OUTF.
731 A blank line separates insns.
733 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
736 print_rtl (FILE *outf
, const_rtx rtx_first
)
745 fputs (print_rtx_head
, outf
);
746 fputs ("(nil)\n", outf
);
749 switch (GET_CODE (rtx_first
))
757 for (tmp_rtx
= rtx_first
; tmp_rtx
!= 0; tmp_rtx
= NEXT_INSN (tmp_rtx
))
759 fputs (print_rtx_head
, outfile
);
761 fprintf (outfile
, "\n");
766 fputs (print_rtx_head
, outfile
);
767 print_rtx (rtx_first
);
771 /* Like print_rtx, except specify a file. */
772 /* Return nonzero if we actually printed anything. */
775 print_rtl_single (FILE *outf
, const_rtx x
)
779 fputs (print_rtx_head
, outfile
);
786 /* Like print_rtl except without all the detail; for example,
787 if RTX is a CONST_INT then print in decimal format. */
790 print_simple_rtl (FILE *outf
, const_rtx x
)