2 Copyright (C) 1987-2016 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file is compiled twice: once for the generator programs,
21 once for the compiler. */
29 #include "coretypes.h"
33 /* These headers all define things which are not available in
34 generator programs. */
35 #ifndef GENERATOR_FILE
39 #include "print-tree.h"
43 #include "basic-block.h"
44 #include "diagnostic.h"
45 #include "tree-pretty-print.h"
46 #include "alloc-pool.h"
48 #include "dumpfile.h" /* for dump_flags */
49 #include "dwarf2out.h"
50 #include "pretty-print.h"
53 #include "print-rtl.h"
57 static int sawclose
= 0;
61 static bool in_call_function_usage
;
63 static void print_rtx (const_rtx
);
65 /* String printed at beginning of each RTL when it is dumped.
66 This string is set to ASM_COMMENT_START when the RTL is dumped in
67 the assembly output file. */
68 const char *print_rtx_head
= "";
71 /* These are defined from the .opt file when not used in generator
74 /* Nonzero means suppress output of instruction numbers
76 This must be defined here so that programs like gencodes can be linked. */
77 int flag_dump_unnumbered
= 0;
79 /* Nonzero means suppress output of instruction numbers for previous
80 and next insns in debugging dumps.
81 This must be defined here so that programs like gencodes can be linked. */
82 int flag_dump_unnumbered_links
= 0;
85 /* Nonzero means use simplified format without flags, modes, etc. */
88 #ifndef GENERATOR_FILE
90 print_mem_expr (FILE *outfile
, const_tree expr
)
93 print_generic_expr (outfile
, CONST_CAST_TREE (expr
), dump_flags
);
97 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
100 print_rtx (const_rtx in_rtx
)
104 const char *format_ptr
;
110 fputc (' ', outfile
);
112 fprintf (outfile
, "\n%s%*s", print_rtx_head
, indent
* 2, "");
118 fputs ("(nil)", outfile
);
122 else if (GET_CODE (in_rtx
) > NUM_RTX_CODE
)
124 fprintf (outfile
, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx
),
125 print_rtx_head
, indent
* 2, "");
130 is_insn
= INSN_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 || GET_CODE (in_rtx
) == INT_LIST
)
165 && (int)GET_MODE (in_rtx
) < REG_NOTE_MAX
166 && !in_call_function_usage
)
167 fprintf (outfile
, ":%s",
168 GET_REG_NOTE_NAME (GET_MODE (in_rtx
)));
170 /* For other rtl, print the mode if it's not VOID. */
171 else if (GET_MODE (in_rtx
) != VOIDmode
)
172 fprintf (outfile
, ":%s", GET_MODE_NAME (GET_MODE (in_rtx
)));
174 #ifndef GENERATOR_FILE
175 if (GET_CODE (in_rtx
) == VAR_LOCATION
)
177 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx
)) == STRING_CST
)
178 fputs (" <debug string placeholder>", outfile
);
180 print_mem_expr (outfile
, PAT_VAR_LOCATION_DECL (in_rtx
));
181 fputc (' ', outfile
);
182 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx
));
183 if (PAT_VAR_LOCATION_STATUS (in_rtx
)
184 == VAR_INIT_STATUS_UNINITIALIZED
)
185 fprintf (outfile
, " [uninit]");
187 i
= GET_RTX_LENGTH (VAR_LOCATION
);
192 #ifndef GENERATOR_FILE
193 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx
))
197 if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx
)))
199 if (flag_dump_unnumbered
)
200 fprintf (outfile
, " #");
202 fprintf (outfile
, " %d", INSN_UID (in_rtx
));
205 /* Get the format string and skip the first elements if we have handled
207 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
)) + i
;
208 for (; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
209 switch (*format_ptr
++)
214 str
= XTMPL (in_rtx
, i
);
219 str
= XSTR (in_rtx
, i
);
223 fputs (" \"\"", outfile
);
225 fprintf (outfile
, " (\"%s\")", str
);
229 /* 0 indicates a field for internal use that should not be printed.
230 An exception is the third field of a NOTE, where it indicates
231 that the field has several different valid contents. */
233 #ifndef GENERATOR_FILE
234 if (i
== 1 && GET_CODE (in_rtx
) == SYMBOL_REF
)
236 int flags
= SYMBOL_REF_FLAGS (in_rtx
);
238 fprintf (outfile
, " [flags %#x]", flags
);
239 tree decl
= SYMBOL_REF_DECL (in_rtx
);
241 print_node_brief (outfile
, "", decl
, dump_flags
);
243 else if (i
== 3 && NOTE_P (in_rtx
))
245 switch (NOTE_KIND (in_rtx
))
247 case NOTE_INSN_EH_REGION_BEG
:
248 case NOTE_INSN_EH_REGION_END
:
249 if (flag_dump_unnumbered
)
250 fprintf (outfile
, " #");
252 fprintf (outfile
, " %d", NOTE_EH_HANDLER (in_rtx
));
256 case NOTE_INSN_BLOCK_BEG
:
257 case NOTE_INSN_BLOCK_END
:
258 dump_addr (outfile
, " ", NOTE_BLOCK (in_rtx
));
262 case NOTE_INSN_BASIC_BLOCK
:
264 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
266 fprintf (outfile
, " [bb %d]", bb
->index
);
270 case NOTE_INSN_DELETED_LABEL
:
271 case NOTE_INSN_DELETED_DEBUG_LABEL
:
273 const char *label
= NOTE_DELETED_LABEL_NAME (in_rtx
);
275 fprintf (outfile
, " (\"%s\")", label
);
277 fprintf (outfile
, " \"\"");
281 case NOTE_INSN_SWITCH_TEXT_SECTIONS
:
283 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
285 fprintf (outfile
, " [bb %d]", bb
->index
);
289 case NOTE_INSN_VAR_LOCATION
:
290 case NOTE_INSN_CALL_ARG_LOCATION
:
291 fputc (' ', outfile
);
292 print_rtx (NOTE_VAR_LOCATION (in_rtx
));
296 fputc ('\n', outfile
);
297 output_cfi_directive (outfile
, NOTE_CFI (in_rtx
));
298 fputc ('\t', outfile
);
305 else if (i
== 7 && JUMP_P (in_rtx
) && JUMP_LABEL (in_rtx
) != NULL
)
307 /* Output the JUMP_LABEL reference. */
308 fprintf (outfile
, "\n%s%*s -> ", print_rtx_head
, indent
* 2, "");
309 if (GET_CODE (JUMP_LABEL (in_rtx
)) == RETURN
)
310 fprintf (outfile
, "return");
311 else if (GET_CODE (JUMP_LABEL (in_rtx
)) == SIMPLE_RETURN
)
312 fprintf (outfile
, "simple_return");
314 fprintf (outfile
, "%d", INSN_UID (JUMP_LABEL (in_rtx
)));
316 else if (i
== 0 && GET_CODE (in_rtx
) == VALUE
)
318 cselib_val
*val
= CSELIB_VAL_PTR (in_rtx
);
320 fprintf (outfile
, " %u:%u", val
->uid
, val
->hash
);
321 dump_addr (outfile
, " @", in_rtx
);
322 dump_addr (outfile
, "/", (void*)val
);
324 else if (i
== 0 && GET_CODE (in_rtx
) == DEBUG_EXPR
)
326 fprintf (outfile
, " D#%i",
327 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx
)));
329 else if (i
== 0 && GET_CODE (in_rtx
) == ENTRY_VALUE
)
333 fprintf (outfile
, " ");
334 print_rtx (ENTRY_VALUE_EXP (in_rtx
));
343 if (i
== 6 && INSN_P (in_rtx
))
344 /* Put REG_NOTES on their own line. */
345 fprintf (outfile
, "\n%s%*s",
346 print_rtx_head
, indent
* 2, "");
348 fprintf (outfile
, " ");
349 if (i
== 7 && CALL_P (in_rtx
))
351 in_call_function_usage
= true;
352 print_rtx (XEXP (in_rtx
, i
));
353 in_call_function_usage
= false;
356 print_rtx (XEXP (in_rtx
, i
));
365 fprintf (outfile
, "\n%s%*s",
366 print_rtx_head
, indent
* 2, "");
369 fputs (" [", outfile
);
370 if (NULL
!= XVEC (in_rtx
, i
))
373 if (XVECLEN (in_rtx
, i
))
376 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
377 print_rtx (XVECEXP (in_rtx
, i
, j
));
382 fprintf (outfile
, "\n%s%*s", print_rtx_head
, indent
* 2, "");
384 fputs ("]", outfile
);
391 fprintf (outfile
, " ");
392 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, XWINT (in_rtx
, i
));
394 fprintf (outfile
, " [" HOST_WIDE_INT_PRINT_HEX
"]",
395 (unsigned HOST_WIDE_INT
) XWINT (in_rtx
, i
));
399 if (i
== 4 && INSN_P (in_rtx
))
401 #ifndef GENERATOR_FILE
402 const rtx_insn
*in_insn
= as_a
<const rtx_insn
*> (in_rtx
);
404 /* Pretty-print insn locations. Ignore scoping as it is mostly
405 redundant with line number information and do not print anything
406 when there is no location information available. */
407 if (INSN_HAS_LOCATION (in_insn
))
409 expanded_location xloc
= insn_location (in_insn
);
410 fprintf (outfile
, " %s:%i", xloc
.file
, xloc
.line
);
414 else if (i
== 6 && GET_CODE (in_rtx
) == ASM_OPERANDS
)
416 #ifndef GENERATOR_FILE
417 if (ASM_OPERANDS_SOURCE_LOCATION (in_rtx
) != UNKNOWN_LOCATION
)
418 fprintf (outfile
, " %s:%i",
419 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx
)),
420 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx
)));
423 else if (i
== 1 && GET_CODE (in_rtx
) == ASM_INPUT
)
425 #ifndef GENERATOR_FILE
426 if (ASM_INPUT_SOURCE_LOCATION (in_rtx
) != UNKNOWN_LOCATION
)
427 fprintf (outfile
, " %s:%i",
428 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx
)),
429 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx
)));
432 else if (i
== 5 && NOTE_P (in_rtx
))
434 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
435 other times often contains garbage from INSN->NOTE death. */
436 if (NOTE_KIND (in_rtx
) == NOTE_INSN_DELETED_LABEL
437 || NOTE_KIND (in_rtx
) == NOTE_INSN_DELETED_DEBUG_LABEL
)
438 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
440 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
442 && GET_CODE (in_rtx
) == UNSPEC_VOLATILE
443 && XINT (in_rtx
, 1) >= 0
444 && XINT (in_rtx
, 1) < NUM_UNSPECV_VALUES
)
445 fprintf (outfile
, " %s", unspecv_strings
[XINT (in_rtx
, 1)]);
447 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
449 && (GET_CODE (in_rtx
) == UNSPEC
450 || GET_CODE (in_rtx
) == UNSPEC_VOLATILE
)
451 && XINT (in_rtx
, 1) >= 0
452 && XINT (in_rtx
, 1) < NUM_UNSPEC_VALUES
)
453 fprintf (outfile
, " %s", unspec_strings
[XINT (in_rtx
, 1)]);
457 int value
= XINT (in_rtx
, i
);
460 if (flag_dump_unnumbered
461 && (is_insn
|| NOTE_P (in_rtx
)))
462 fputc ('#', outfile
);
464 fprintf (outfile
, " %d", value
);
466 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
467 && XINT (in_rtx
, i
) >= 0
468 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
469 fprintf (outfile
, " {%s}", name
);
476 unsigned int regno
= REGNO (in_rtx
);
477 #ifndef GENERATOR_FILE
478 if (regno
< FIRST_PSEUDO_REGISTER
)
479 fprintf (outfile
, " %d %s", regno
, reg_names
[regno
]);
480 else if (regno
<= LAST_VIRTUAL_REGISTER
)
482 if (regno
== VIRTUAL_INCOMING_ARGS_REGNUM
)
483 fprintf (outfile
, " %d virtual-incoming-args", regno
);
484 else if (regno
== VIRTUAL_STACK_VARS_REGNUM
)
485 fprintf (outfile
, " %d virtual-stack-vars", regno
);
486 else if (regno
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
487 fprintf (outfile
, " %d virtual-stack-dynamic", regno
);
488 else if (regno
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
489 fprintf (outfile
, " %d virtual-outgoing-args", regno
);
490 else if (regno
== VIRTUAL_CFA_REGNUM
)
491 fprintf (outfile
, " %d virtual-cfa", regno
);
492 else if (regno
== VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM
)
493 fprintf (outfile
, " %d virtual-preferred-stack-boundary",
496 fprintf (outfile
, " %d virtual-reg-%d", regno
,
497 regno
-FIRST_VIRTUAL_REGISTER
);
501 if (flag_dump_unnumbered
&& is_insn
)
502 fputc ('#', outfile
);
504 fprintf (outfile
, " %d", regno
);
506 #ifndef GENERATOR_FILE
507 if (REG_ATTRS (in_rtx
))
509 fputs (" [", outfile
);
510 if (regno
!= ORIGINAL_REGNO (in_rtx
))
511 fprintf (outfile
, "orig:%i", ORIGINAL_REGNO (in_rtx
));
512 if (REG_EXPR (in_rtx
))
513 print_mem_expr (outfile
, REG_EXPR (in_rtx
));
515 if (REG_OFFSET (in_rtx
))
516 fprintf (outfile
, "+" HOST_WIDE_INT_PRINT_DEC
,
517 REG_OFFSET (in_rtx
));
518 fputs (" ]", outfile
);
520 if (regno
!= ORIGINAL_REGNO (in_rtx
))
521 fprintf (outfile
, " [%d]", ORIGINAL_REGNO (in_rtx
));
526 /* Print NOTE_INSN names rather than integer codes. */
529 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
534 if (XEXP (in_rtx
, i
) != NULL
)
536 rtx sub
= XEXP (in_rtx
, i
);
537 enum rtx_code subc
= GET_CODE (sub
);
539 if (GET_CODE (in_rtx
) == LABEL_REF
)
542 && NOTE_KIND (sub
) == NOTE_INSN_DELETED_LABEL
)
544 if (flag_dump_unnumbered
)
545 fprintf (outfile
, " [# deleted]");
547 fprintf (outfile
, " [%d deleted]", INSN_UID (sub
));
552 if (subc
!= CODE_LABEL
)
556 if (flag_dump_unnumbered
557 || (flag_dump_unnumbered_links
&& i
<= 1
558 && (INSN_P (in_rtx
) || NOTE_P (in_rtx
)
559 || LABEL_P (in_rtx
) || BARRIER_P (in_rtx
))))
560 fputs (" #", outfile
);
562 fprintf (outfile
, " %d", INSN_UID (sub
));
565 fputs (" 0", outfile
);
570 #ifndef GENERATOR_FILE
571 if (i
== 0 && GET_CODE (in_rtx
) == DEBUG_IMPLICIT_PTR
)
572 print_mem_expr (outfile
, DEBUG_IMPLICIT_PTR_DECL (in_rtx
));
573 else if (i
== 0 && GET_CODE (in_rtx
) == DEBUG_PARAMETER_REF
)
574 print_mem_expr (outfile
, DEBUG_PARAMETER_REF_DECL (in_rtx
));
576 dump_addr (outfile
, " ", XTREE (in_rtx
, i
));
581 fputs (" Unknown", outfile
);
586 #ifndef GENERATOR_FILE
587 if (XBBDEF (in_rtx
, i
))
588 fprintf (outfile
, " %i", XBBDEF (in_rtx
, i
)->index
);
596 switch (GET_CODE (in_rtx
))
598 #ifndef GENERATOR_FILE
600 if (__builtin_expect (final_insns_dump_p
, false))
601 fprintf (outfile
, " [");
603 fprintf (outfile
, " [" HOST_WIDE_INT_PRINT_DEC
,
604 (HOST_WIDE_INT
) MEM_ALIAS_SET (in_rtx
));
606 if (MEM_EXPR (in_rtx
))
607 print_mem_expr (outfile
, MEM_EXPR (in_rtx
));
609 fputc (' ', outfile
);
611 if (MEM_OFFSET_KNOWN_P (in_rtx
))
612 fprintf (outfile
, "+" HOST_WIDE_INT_PRINT_DEC
, MEM_OFFSET (in_rtx
));
614 if (MEM_SIZE_KNOWN_P (in_rtx
))
615 fprintf (outfile
, " S" HOST_WIDE_INT_PRINT_DEC
, MEM_SIZE (in_rtx
));
617 if (MEM_ALIGN (in_rtx
) != 1)
618 fprintf (outfile
, " A%u", MEM_ALIGN (in_rtx
));
620 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx
)))
621 fprintf (outfile
, " AS%u", MEM_ADDR_SPACE (in_rtx
));
623 fputc (']', outfile
);
627 if (FLOAT_MODE_P (GET_MODE (in_rtx
)))
631 real_to_decimal (s
, CONST_DOUBLE_REAL_VALUE (in_rtx
),
633 fprintf (outfile
, " %s", s
);
635 real_to_hexadecimal (s
, CONST_DOUBLE_REAL_VALUE (in_rtx
),
637 fprintf (outfile
, " [%s]", s
);
642 fprintf (outfile
, " ");
643 cwi_output_hex (outfile
, in_rtx
);
648 fprintf (outfile
, " [%d uses]", LABEL_NUSES (in_rtx
));
649 switch (LABEL_KIND (in_rtx
))
651 case LABEL_NORMAL
: break;
652 case LABEL_STATIC_ENTRY
: fputs (" [entry]", outfile
); break;
653 case LABEL_GLOBAL_ENTRY
: fputs (" [global entry]", outfile
); break;
654 case LABEL_WEAK_ENTRY
: fputs (" [weak entry]", outfile
); break;
655 default: gcc_unreachable ();
663 fputc (')', outfile
);
667 /* Print an rtx on the current line of FILE. Initially indent IND
671 print_inline_rtx (FILE *outf
, const_rtx x
, int ind
)
673 int oldsaw
= sawclose
;
674 int oldindent
= indent
;
684 /* Call this function from the debugger to see what X looks like. */
687 debug_rtx (const_rtx x
)
692 fprintf (stderr
, "\n");
698 debug (const rtx_def
&ref
)
704 debug (const rtx_def
*ptr
)
709 fprintf (stderr
, "<nil>\n");
712 /* Count of rtx's to print with debug_rtx_list.
713 This global exists because gdb user defined commands have no arguments. */
715 DEBUG_VARIABLE
int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
717 /* Call this function to print list from X on.
719 N is a count of the rtx's to print. Positive values print from the specified
720 rtx_insn on. Negative values print a window around the rtx_insn.
721 EG: -5 prints 2 rtx_insn's on either side (in addition to the specified
725 debug_rtx_list (const rtx_insn
*x
, int n
)
728 const rtx_insn
*insn
;
730 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
732 /* If we are printing a window, back up to the start. */
735 for (i
= count
/ 2; i
> 0; i
--)
737 if (PREV_INSN (x
) == 0)
742 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
745 fprintf (stderr
, "\n");
749 /* Call this function to print an rtx_insn list from START to END
753 debug_rtx_range (const rtx_insn
*start
, const rtx_insn
*end
)
758 fprintf (stderr
, "\n");
759 if (!start
|| start
== end
)
761 start
= NEXT_INSN (start
);
765 /* Call this function to search an rtx_insn list to find one with insn uid UID,
766 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
767 The found insn is returned to enable further debugging analysis. */
769 DEBUG_FUNCTION
const rtx_insn
*
770 debug_rtx_find (const rtx_insn
*x
, int uid
)
772 while (x
!= 0 && INSN_UID (x
) != uid
)
776 debug_rtx_list (x
, debug_rtx_count
);
781 fprintf (stderr
, "insn uid %d not found\n", uid
);
786 /* External entry point for printing a chain of insns
787 starting with RTX_FIRST onto file OUTF.
788 A blank line separates insns.
790 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
793 print_rtl (FILE *outf
, const_rtx rtx_first
)
795 const rtx_insn
*tmp_rtx
;
802 fputs (print_rtx_head
, outf
);
803 fputs ("(nil)\n", outf
);
806 switch (GET_CODE (rtx_first
))
813 case JUMP_TABLE_DATA
:
815 for (tmp_rtx
= as_a
<const rtx_insn
*> (rtx_first
);
817 tmp_rtx
= NEXT_INSN (tmp_rtx
))
819 fputs (print_rtx_head
, outfile
);
821 fprintf (outfile
, "\n");
826 fputs (print_rtx_head
, outfile
);
827 print_rtx (rtx_first
);
831 /* Like print_rtx, except specify a file. */
832 /* Return nonzero if we actually printed anything. */
835 print_rtl_single (FILE *outf
, const_rtx x
)
837 return print_rtl_single_with_indent (outf
, x
, 0);
840 /* Like print_rtl_single, except specify a file and indentation. */
843 print_rtl_single_with_indent (FILE *outf
, const_rtx x
, int ind
)
845 int old_indent
= indent
;
846 char *s_indent
= (char *) alloca ((size_t) ind
+ 1);
847 memset ((void *) s_indent
, ' ', (size_t) ind
);
848 s_indent
[ind
] = '\0';
853 fputs (s_indent
, outfile
);
854 fputs (print_rtx_head
, outfile
);
862 /* Like print_rtl except without all the detail; for example,
863 if RTX is a CONST_INT then print in decimal format. */
866 print_simple_rtl (FILE *outf
, const_rtx x
)
873 #ifndef GENERATOR_FILE
874 /* The functions below try to print RTL in a form resembling assembler
875 mnemonics. Because this form is more concise than the "traditional" form
876 of RTL printing in Lisp-style, the form printed by this file is called
877 "slim". RTL dumps in slim format can be obtained by appending the "-slim"
878 option to -fdump-rtl-<pass>. Control flow graph output as a DOT file is
879 always printed in slim form.
881 The normal interface to the functionality provided in this pretty-printer
882 is through the dump_*_slim functions to print to a stream, or via the
883 print_*_slim functions to print into a user's pretty-printer.
885 It is also possible to obtain a string for a single pattern as a string
886 pointer, via str_pattern_slim, but this usage is discouraged. */
888 /* For insns we print patterns, and for some patterns we print insns... */
889 static void print_insn_with_notes (pretty_printer
*, const rtx_insn
*);
891 /* This recognizes rtx'en classified as expressions. These are always
892 represent some action on values or results of other expression, that
893 may be stored in objects representing values. */
896 print_exp (pretty_printer
*pp
, const_rtx x
, int verbose
)
904 for (i
= 0; i
< 4; i
++)
910 switch (GET_CODE (x
))
914 if (CONST_INT_P (XEXP (x
, 1))
915 && INTVAL (XEXP (x
, 1)) < 0)
918 op
[1] = GEN_INT (-INTVAL (XEXP (x
, 1)));
1002 op
[0] = XEXP (x
, 0);
1005 op
[0] = XEXP (x
, 0);
1007 op
[1] = XEXP (x
, 1);
1010 op
[0] = XEXP (x
, 0);
1012 op
[1] = XEXP (x
, 1);
1015 op
[0] = XEXP (x
, 0);
1017 op
[1] = XEXP (x
, 1);
1020 op
[0] = XEXP (x
, 0);
1022 op
[1] = XEXP (x
, 1);
1025 op
[0] = XEXP (x
, 0);
1027 op
[1] = XEXP (x
, 1);
1030 op
[0] = XEXP (x
, 0);
1032 op
[1] = XEXP (x
, 1);
1035 op
[0] = XEXP (x
, 0);
1037 op
[1] = XEXP (x
, 1);
1040 op
[0] = XEXP (x
, 0);
1042 op
[1] = XEXP (x
, 1);
1045 op
[0] = XEXP (x
, 0);
1047 op
[1] = XEXP (x
, 1);
1050 op
[0] = XEXP (x
, 0);
1052 op
[1] = XEXP (x
, 1);
1055 op
[0] = XEXP (x
, 0);
1057 op
[1] = XEXP (x
, 1);
1060 op
[0] = XEXP (x
, 0);
1062 op
[1] = XEXP (x
, 1);
1065 op
[0] = XEXP (x
, 0);
1067 op
[1] = XEXP (x
, 1);
1070 op
[0] = XEXP (x
, 0);
1072 op
[1] = XEXP (x
, 1);
1075 fun
= (verbose
) ? "sign_extract" : "sxt";
1076 op
[0] = XEXP (x
, 0);
1077 op
[1] = XEXP (x
, 1);
1078 op
[2] = XEXP (x
, 2);
1081 fun
= (verbose
) ? "zero_extract" : "zxt";
1082 op
[0] = XEXP (x
, 0);
1083 op
[1] = XEXP (x
, 1);
1084 op
[2] = XEXP (x
, 2);
1087 fun
= (verbose
) ? "sign_extend" : "sxn";
1088 op
[0] = XEXP (x
, 0);
1091 fun
= (verbose
) ? "zero_extend" : "zxn";
1092 op
[0] = XEXP (x
, 0);
1095 fun
= (verbose
) ? "float_extend" : "fxn";
1096 op
[0] = XEXP (x
, 0);
1099 fun
= (verbose
) ? "trunc" : "trn";
1100 op
[0] = XEXP (x
, 0);
1102 case FLOAT_TRUNCATE
:
1103 fun
= (verbose
) ? "float_trunc" : "ftr";
1104 op
[0] = XEXP (x
, 0);
1107 fun
= (verbose
) ? "float" : "flt";
1108 op
[0] = XEXP (x
, 0);
1110 case UNSIGNED_FLOAT
:
1111 fun
= (verbose
) ? "uns_float" : "ufl";
1112 op
[0] = XEXP (x
, 0);
1116 op
[0] = XEXP (x
, 0);
1119 fun
= (verbose
) ? "uns_fix" : "ufx";
1120 op
[0] = XEXP (x
, 0);
1124 op
[0] = XEXP (x
, 0);
1128 op
[0] = XEXP (x
, 0);
1131 op
[0] = XEXP (x
, 0);
1135 op
[0] = XEXP (x
, 0);
1140 op
[0] = XEXP (XEXP (x
, 1), 0);
1142 op
[1] = XEXP (XEXP (x
, 1), 1);
1146 op
[0] = XEXP (XEXP (x
, 1), 0);
1148 op
[1] = XEXP (XEXP (x
, 1), 1);
1152 op
[0] = XEXP (x
, 0);
1156 op
[1] = XEXP (x
, 1);
1161 op
[0] = XEXP (x
, 0);
1163 op
[1] = XEXP (x
, 1);
1165 op
[2] = XEXP (x
, 2);
1170 op
[0] = TRAP_CONDITION (x
);
1174 op
[0] = XEXP (x
, 0);
1175 op
[1] = XEXP (x
, 1);
1176 op
[2] = XEXP (x
, 2);
1179 case UNSPEC_VOLATILE
:
1181 pp_string (pp
, "unspec");
1182 if (GET_CODE (x
) == UNSPEC_VOLATILE
)
1183 pp_string (pp
, "/v");
1184 pp_left_bracket (pp
);
1185 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
1189 print_pattern (pp
, XVECEXP (x
, 0, i
), verbose
);
1191 pp_string (pp
, "] ");
1192 pp_decimal_int (pp
, XINT (x
, 1));
1197 /* Most unhandled codes can be printed as pseudo-functions. */
1198 if (GET_RTX_CLASS (GET_CODE (x
)) == RTX_UNARY
)
1200 fun
= GET_RTX_NAME (GET_CODE (x
));
1201 op
[0] = XEXP (x
, 0);
1203 else if (GET_RTX_CLASS (GET_CODE (x
)) == RTX_COMPARE
1204 || GET_RTX_CLASS (GET_CODE (x
)) == RTX_COMM_COMPARE
1205 || GET_RTX_CLASS (GET_CODE (x
)) == RTX_BIN_ARITH
1206 || GET_RTX_CLASS (GET_CODE (x
)) == RTX_COMM_ARITH
)
1208 fun
= GET_RTX_NAME (GET_CODE (x
));
1209 op
[0] = XEXP (x
, 0);
1210 op
[1] = XEXP (x
, 1);
1212 else if (GET_RTX_CLASS (GET_CODE (x
)) == RTX_TERNARY
)
1214 fun
= GET_RTX_NAME (GET_CODE (x
));
1215 op
[0] = XEXP (x
, 0);
1216 op
[1] = XEXP (x
, 1);
1217 op
[2] = XEXP (x
, 2);
1220 /* Give up, just print the RTX name. */
1221 st
[0] = GET_RTX_NAME (GET_CODE (x
));
1226 /* Print this as a function? */
1229 pp_string (pp
, fun
);
1233 for (i
= 0; i
< 4; i
++)
1236 pp_string (pp
, st
[i
]);
1242 print_value (pp
, op
[i
], verbose
);
1247 pp_right_paren (pp
);
1250 /* Prints rtxes, I customarily classified as values. They're constants,
1251 registers, labels, symbols and memory accesses. */
1254 print_value (pretty_printer
*pp
, const_rtx x
, int verbose
)
1260 pp_string (pp
, "(nil)");
1263 switch (GET_CODE (x
))
1266 pp_scalar (pp
, HOST_WIDE_INT_PRINT_HEX
,
1267 (unsigned HOST_WIDE_INT
) INTVAL (x
));
1270 case CONST_WIDE_INT
:
1272 const char *sep
= "<";
1274 for (i
= CONST_WIDE_INT_NUNITS (x
) - 1; i
>= 0; i
--)
1276 pp_string (pp
, sep
);
1278 sprintf (tmp
, HOST_WIDE_INT_PRINT_HEX
,
1279 (unsigned HOST_WIDE_INT
) CONST_WIDE_INT_ELT (x
, i
));
1280 pp_string (pp
, tmp
);
1287 if (FLOAT_MODE_P (GET_MODE (x
)))
1289 real_to_decimal (tmp
, CONST_DOUBLE_REAL_VALUE (x
),
1290 sizeof (tmp
), 0, 1);
1291 pp_string (pp
, tmp
);
1294 pp_printf (pp
, "<%wx,%wx>",
1295 (unsigned HOST_WIDE_INT
) CONST_DOUBLE_LOW (x
),
1296 (unsigned HOST_WIDE_INT
) CONST_DOUBLE_HIGH (x
));
1299 fixed_to_decimal (tmp
, CONST_FIXED_VALUE (x
), sizeof (tmp
));
1300 pp_string (pp
, tmp
);
1303 pp_printf (pp
, "\"%s\"", XSTR (x
, 0));
1306 pp_printf (pp
, "`%s'", XSTR (x
, 0));
1309 pp_printf (pp
, "L%d", INSN_UID (LABEL_REF_LABEL (x
)));
1313 case STRICT_LOW_PART
:
1314 pp_printf (pp
, "%s(", GET_RTX_NAME (GET_CODE (x
)));
1315 print_value (pp
, XEXP (x
, 0), verbose
);
1316 pp_right_paren (pp
);
1319 if (REGNO (x
) < FIRST_PSEUDO_REGISTER
)
1321 if (ISDIGIT (reg_names
[REGNO (x
)][0]))
1323 pp_string (pp
, reg_names
[REGNO (x
)]);
1326 pp_printf (pp
, "r%d", REGNO (x
));
1328 pp_printf (pp
, ":%s", GET_MODE_NAME (GET_MODE (x
)));
1331 print_value (pp
, SUBREG_REG (x
), verbose
);
1332 pp_printf (pp
, "#%d", SUBREG_BYTE (x
));
1337 pp_string (pp
, GET_RTX_NAME (GET_CODE (x
)));
1340 pp_left_bracket (pp
);
1341 print_value (pp
, XEXP (x
, 0), verbose
);
1342 pp_right_bracket (pp
);
1345 pp_printf (pp
, "D#%i", DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x
)));
1348 print_exp (pp
, x
, verbose
);
1353 /* The next step in insn detalization, its pattern recognition. */
1356 print_pattern (pretty_printer
*pp
, const_rtx x
, int verbose
)
1360 pp_string (pp
, "(nil)");
1364 switch (GET_CODE (x
))
1367 print_value (pp
, SET_DEST (x
), verbose
);
1369 print_value (pp
, SET_SRC (x
), verbose
);
1374 pp_string (pp
, GET_RTX_NAME (GET_CODE (x
)));
1377 print_exp (pp
, x
, verbose
);
1381 pp_printf (pp
, "%s ", GET_RTX_NAME (GET_CODE (x
)));
1382 print_value (pp
, XEXP (x
, 0), verbose
);
1385 pp_string (pp
, "loc ");
1386 print_value (pp
, PAT_VAR_LOCATION_LOC (x
), verbose
);
1390 if (GET_CODE (COND_EXEC_TEST (x
)) == NE
1391 && XEXP (COND_EXEC_TEST (x
), 1) == const0_rtx
)
1392 print_value (pp
, XEXP (COND_EXEC_TEST (x
), 0), verbose
);
1393 else if (GET_CODE (COND_EXEC_TEST (x
)) == EQ
1394 && XEXP (COND_EXEC_TEST (x
), 1) == const0_rtx
)
1396 pp_exclamation (pp
);
1397 print_value (pp
, XEXP (COND_EXEC_TEST (x
), 0), verbose
);
1400 print_value (pp
, COND_EXEC_TEST (x
), verbose
);
1401 pp_string (pp
, ") ");
1402 print_pattern (pp
, COND_EXEC_CODE (x
), verbose
);
1409 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
1411 print_pattern (pp
, XVECEXP (x
, 0, i
), verbose
);
1414 pp_right_brace (pp
);
1419 const rtx_sequence
*seq
= as_a
<const rtx_sequence
*> (x
);
1420 pp_string (pp
, "sequence{");
1421 if (INSN_P (seq
->element (0)))
1423 /* Print the sequence insns indented. */
1424 const char * save_print_rtx_head
= print_rtx_head
;
1425 char indented_print_rtx_head
[32];
1428 gcc_assert (strlen (print_rtx_head
) < sizeof (indented_print_rtx_head
) - 4);
1429 snprintf (indented_print_rtx_head
,
1430 sizeof (indented_print_rtx_head
),
1431 "%s ", print_rtx_head
);
1432 print_rtx_head
= indented_print_rtx_head
;
1433 for (int i
= 0; i
< seq
->len (); i
++)
1434 print_insn_with_notes (pp
, seq
->insn (i
));
1435 pp_printf (pp
, "%s ", save_print_rtx_head
);
1436 print_rtx_head
= save_print_rtx_head
;
1440 for (int i
= 0; i
< seq
->len (); i
++)
1442 print_pattern (pp
, seq
->element (i
), verbose
);
1446 pp_right_brace (pp
);
1450 pp_printf (pp
, "asm {%s}", XSTR (x
, 0));
1453 for (int i
= 0; i
< XVECLEN (x
, 0); i
++)
1455 print_value (pp
, XVECEXP (x
, 0, i
), verbose
);
1460 for (int i
= 0; i
< XVECLEN (x
, 1); i
++)
1462 print_value (pp
, XVECEXP (x
, 1, i
), verbose
);
1467 pp_string (pp
, "trap_if ");
1468 print_value (pp
, TRAP_CONDITION (x
), verbose
);
1471 case UNSPEC_VOLATILE
:
1472 /* Fallthru -- leave UNSPECs to print_exp. */
1474 print_value (pp
, x
, verbose
);
1476 } /* print_pattern */
1478 /* This is the main function in slim rtl visualization mechanism.
1480 X is an insn, to be printed into PP.
1482 This function tries to print it properly in human-readable form,
1483 resembling assembler mnemonics (instead of the older Lisp-style
1486 If VERBOSE is TRUE, insns are printed with more complete (but
1487 longer) pattern names and with extra information, and prefixed
1488 with their INSN_UIDs. */
1491 print_insn (pretty_printer
*pp
, const rtx_insn
*x
, int verbose
)
1495 /* Blech, pretty-print can't print integers with a specified width. */
1496 char uid_prefix
[32];
1497 snprintf (uid_prefix
, sizeof uid_prefix
, " %4d: ", INSN_UID (x
));
1498 pp_string (pp
, uid_prefix
);
1501 switch (GET_CODE (x
))
1504 print_pattern (pp
, PATTERN (x
), verbose
);
1509 const char *name
= "?";
1511 if (DECL_P (INSN_VAR_LOCATION_DECL (x
)))
1513 tree id
= DECL_NAME (INSN_VAR_LOCATION_DECL (x
));
1516 name
= IDENTIFIER_POINTER (id
);
1517 else if (TREE_CODE (INSN_VAR_LOCATION_DECL (x
))
1520 sprintf (idbuf
, "D#%i",
1521 DEBUG_TEMP_UID (INSN_VAR_LOCATION_DECL (x
)));
1526 sprintf (idbuf
, "D.%i",
1527 DECL_UID (INSN_VAR_LOCATION_DECL (x
)));
1531 pp_printf (pp
, "debug %s => ", name
);
1532 if (VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (x
)))
1533 pp_string (pp
, "optimized away");
1535 print_pattern (pp
, INSN_VAR_LOCATION_LOC (x
), verbose
);
1540 print_pattern (pp
, PATTERN (x
), verbose
);
1543 if (GET_CODE (PATTERN (x
)) == PARALLEL
)
1544 print_pattern (pp
, XVECEXP (PATTERN (x
), 0, 0), verbose
);
1546 print_pattern (pp
, PATTERN (x
), verbose
);
1549 pp_printf (pp
, "L%d:", INSN_UID (x
));
1551 case JUMP_TABLE_DATA
:
1552 pp_string (pp
, "jump_table_data{\n");
1553 print_pattern (pp
, PATTERN (x
), verbose
);
1554 pp_right_brace (pp
);
1557 pp_string (pp
, "barrier");
1561 pp_string (pp
, GET_NOTE_INSN_NAME (NOTE_KIND (x
)));
1562 switch (NOTE_KIND (x
))
1564 case NOTE_INSN_EH_REGION_BEG
:
1565 case NOTE_INSN_EH_REGION_END
:
1566 pp_printf (pp
, " %d", NOTE_EH_HANDLER (x
));
1569 case NOTE_INSN_BLOCK_BEG
:
1570 case NOTE_INSN_BLOCK_END
:
1571 pp_printf (pp
, " %d", BLOCK_NUMBER (NOTE_BLOCK (x
)));
1574 case NOTE_INSN_BASIC_BLOCK
:
1575 pp_printf (pp
, " %d", NOTE_BASIC_BLOCK (x
)->index
);
1578 case NOTE_INSN_DELETED_LABEL
:
1579 case NOTE_INSN_DELETED_DEBUG_LABEL
:
1581 const char *label
= NOTE_DELETED_LABEL_NAME (x
);
1584 pp_printf (pp
, " (\"%s\")", label
);
1588 case NOTE_INSN_VAR_LOCATION
:
1589 case NOTE_INSN_CALL_ARG_LOCATION
:
1591 print_pattern (pp
, NOTE_VAR_LOCATION (x
), verbose
);
1592 pp_right_brace (pp
);
1605 /* Pretty-print a slim dump of X (an insn) to PP, including any register
1606 note attached to the instruction. */
1609 print_insn_with_notes (pretty_printer
*pp
, const rtx_insn
*x
)
1611 pp_string (pp
, print_rtx_head
);
1612 print_insn (pp
, x
, 1);
1614 if (INSN_P (x
) && REG_NOTES (x
))
1615 for (rtx note
= REG_NOTES (x
); note
; note
= XEXP (note
, 1))
1617 pp_printf (pp
, "%s %s ", print_rtx_head
,
1618 GET_REG_NOTE_NAME (REG_NOTE_KIND (note
)));
1619 if (GET_CODE (note
) == INT_LIST
)
1620 pp_printf (pp
, "%d", XINT (note
, 0));
1622 print_pattern (pp
, XEXP (note
, 0), 1);
1627 /* Print X, an RTL value node, to file F in slim format. Include
1628 additional information if VERBOSE is nonzero.
1630 Value nodes are constants, registers, labels, symbols and
1634 dump_value_slim (FILE *f
, const_rtx x
, int verbose
)
1636 pretty_printer rtl_slim_pp
;
1637 rtl_slim_pp
.buffer
->stream
= f
;
1638 print_value (&rtl_slim_pp
, x
, verbose
);
1639 pp_flush (&rtl_slim_pp
);
1642 /* Emit a slim dump of X (an insn) to the file F, including any register
1643 note attached to the instruction. */
1645 dump_insn_slim (FILE *f
, const rtx_insn
*x
)
1647 pretty_printer rtl_slim_pp
;
1648 rtl_slim_pp
.buffer
->stream
= f
;
1649 print_insn_with_notes (&rtl_slim_pp
, x
);
1650 pp_flush (&rtl_slim_pp
);
1653 /* Same as above, but stop at LAST or when COUNT == 0.
1654 If COUNT < 0 it will stop only at LAST or NULL rtx. */
1657 dump_rtl_slim (FILE *f
, const rtx_insn
*first
, const rtx_insn
*last
,
1658 int count
, int flags ATTRIBUTE_UNUSED
)
1660 const rtx_insn
*insn
, *tail
;
1661 pretty_printer rtl_slim_pp
;
1662 rtl_slim_pp
.buffer
->stream
= f
;
1664 tail
= last
? NEXT_INSN (last
) : NULL
;
1666 (insn
!= NULL
) && (insn
!= tail
) && (count
!= 0);
1667 insn
= NEXT_INSN (insn
))
1669 print_insn_with_notes (&rtl_slim_pp
, insn
);
1674 pp_flush (&rtl_slim_pp
);
1677 /* Dumps basic block BB to pretty-printer PP in slim form and without and
1678 no indentation, for use as a label of a DOT graph record-node. */
1681 rtl_dump_bb_for_graph (pretty_printer
*pp
, basic_block bb
)
1686 /* TODO: inter-bb stuff. */
1687 FOR_BB_INSNS (bb
, insn
)
1692 pp_write_text_to_stream (pp
);
1695 print_insn_with_notes (pp
, insn
);
1696 pp_write_text_as_dot_label_to_stream (pp
, /*for_record=*/true);
1700 /* Pretty-print pattern X of some insn in non-verbose mode.
1701 Return a string pointer to the pretty-printer buffer.
1703 This function is only exported exists only to accommodate some older users
1704 of the slim RTL pretty printers. Please do not use it for new code. */
1707 str_pattern_slim (const_rtx x
)
1709 pretty_printer rtl_slim_pp
;
1710 print_pattern (&rtl_slim_pp
, x
, 0);
1711 return ggc_strdup (pp_formatted_text (&rtl_slim_pp
));
1714 /* Emit a slim dump of X (an insn) to stderr. */
1715 extern void debug_insn_slim (const rtx_insn
*);
1717 debug_insn_slim (const rtx_insn
*x
)
1719 dump_insn_slim (stderr
, x
);
1722 /* Same as above, but using dump_rtl_slim. */
1723 extern void debug_rtl_slim (FILE *, const rtx_insn
*, const rtx_insn
*,
1726 debug_rtl_slim (const rtx_insn
*first
, const rtx_insn
*last
, int count
,
1729 dump_rtl_slim (stderr
, first
, last
, count
, flags
);
1732 extern void debug_bb_slim (basic_block
);
1734 debug_bb_slim (basic_block bb
)
1736 dump_bb (stderr
, bb
, 0, TDF_SLIM
| TDF_BLOCKS
);
1739 extern void debug_bb_n_slim (int);
1741 debug_bb_n_slim (int n
)
1743 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, n
);