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 /* Print the elements of VEC to FILE. */
876 print_rtx_insn_vec (FILE *file
, const vec
<rtx_insn
*> &vec
)
880 unsigned int len
= vec
.length ();
881 for (unsigned int i
= 0; i
< len
; i
++)
883 print_rtl (file
, vec
[i
]);
891 #ifndef GENERATOR_FILE
892 /* The functions below try to print RTL in a form resembling assembler
893 mnemonics. Because this form is more concise than the "traditional" form
894 of RTL printing in Lisp-style, the form printed by this file is called
895 "slim". RTL dumps in slim format can be obtained by appending the "-slim"
896 option to -fdump-rtl-<pass>. Control flow graph output as a DOT file is
897 always printed in slim form.
899 The normal interface to the functionality provided in this pretty-printer
900 is through the dump_*_slim functions to print to a stream, or via the
901 print_*_slim functions to print into a user's pretty-printer.
903 It is also possible to obtain a string for a single pattern as a string
904 pointer, via str_pattern_slim, but this usage is discouraged. */
906 /* For insns we print patterns, and for some patterns we print insns... */
907 static void print_insn_with_notes (pretty_printer
*, const rtx_insn
*);
909 /* This recognizes rtx'en classified as expressions. These are always
910 represent some action on values or results of other expression, that
911 may be stored in objects representing values. */
914 print_exp (pretty_printer
*pp
, const_rtx x
, int verbose
)
922 for (i
= 0; i
< 4; i
++)
928 switch (GET_CODE (x
))
932 if (CONST_INT_P (XEXP (x
, 1))
933 && INTVAL (XEXP (x
, 1)) < 0)
936 op
[1] = GEN_INT (-INTVAL (XEXP (x
, 1)));
1000 op
[0] = XEXP (x
, 0);
1001 op
[1] = XEXP (x
, 1);
1005 op
[0] = XEXP (x
, 0);
1006 op
[1] = XEXP (x
, 1);
1010 op
[0] = XEXP (x
, 0);
1011 op
[1] = XEXP (x
, 1);
1015 op
[0] = XEXP (x
, 0);
1016 op
[1] = XEXP (x
, 1);
1020 op
[0] = XEXP (x
, 0);
1023 op
[0] = XEXP (x
, 0);
1025 op
[1] = XEXP (x
, 1);
1028 op
[0] = XEXP (x
, 0);
1030 op
[1] = XEXP (x
, 1);
1033 op
[0] = XEXP (x
, 0);
1035 op
[1] = XEXP (x
, 1);
1038 op
[0] = XEXP (x
, 0);
1040 op
[1] = XEXP (x
, 1);
1043 op
[0] = XEXP (x
, 0);
1045 op
[1] = XEXP (x
, 1);
1048 op
[0] = XEXP (x
, 0);
1050 op
[1] = XEXP (x
, 1);
1053 op
[0] = XEXP (x
, 0);
1055 op
[1] = XEXP (x
, 1);
1058 op
[0] = XEXP (x
, 0);
1060 op
[1] = XEXP (x
, 1);
1063 op
[0] = XEXP (x
, 0);
1065 op
[1] = XEXP (x
, 1);
1068 op
[0] = XEXP (x
, 0);
1070 op
[1] = XEXP (x
, 1);
1073 op
[0] = XEXP (x
, 0);
1075 op
[1] = XEXP (x
, 1);
1078 op
[0] = XEXP (x
, 0);
1080 op
[1] = XEXP (x
, 1);
1083 op
[0] = XEXP (x
, 0);
1085 op
[1] = XEXP (x
, 1);
1088 op
[0] = XEXP (x
, 0);
1090 op
[1] = XEXP (x
, 1);
1093 fun
= (verbose
) ? "sign_extract" : "sxt";
1094 op
[0] = XEXP (x
, 0);
1095 op
[1] = XEXP (x
, 1);
1096 op
[2] = XEXP (x
, 2);
1099 fun
= (verbose
) ? "zero_extract" : "zxt";
1100 op
[0] = XEXP (x
, 0);
1101 op
[1] = XEXP (x
, 1);
1102 op
[2] = XEXP (x
, 2);
1105 fun
= (verbose
) ? "sign_extend" : "sxn";
1106 op
[0] = XEXP (x
, 0);
1109 fun
= (verbose
) ? "zero_extend" : "zxn";
1110 op
[0] = XEXP (x
, 0);
1113 fun
= (verbose
) ? "float_extend" : "fxn";
1114 op
[0] = XEXP (x
, 0);
1117 fun
= (verbose
) ? "trunc" : "trn";
1118 op
[0] = XEXP (x
, 0);
1120 case FLOAT_TRUNCATE
:
1121 fun
= (verbose
) ? "float_trunc" : "ftr";
1122 op
[0] = XEXP (x
, 0);
1125 fun
= (verbose
) ? "float" : "flt";
1126 op
[0] = XEXP (x
, 0);
1128 case UNSIGNED_FLOAT
:
1129 fun
= (verbose
) ? "uns_float" : "ufl";
1130 op
[0] = XEXP (x
, 0);
1134 op
[0] = XEXP (x
, 0);
1137 fun
= (verbose
) ? "uns_fix" : "ufx";
1138 op
[0] = XEXP (x
, 0);
1142 op
[0] = XEXP (x
, 0);
1146 op
[0] = XEXP (x
, 0);
1149 op
[0] = XEXP (x
, 0);
1153 op
[0] = XEXP (x
, 0);
1158 op
[0] = XEXP (XEXP (x
, 1), 0);
1160 op
[1] = XEXP (XEXP (x
, 1), 1);
1164 op
[0] = XEXP (XEXP (x
, 1), 0);
1166 op
[1] = XEXP (XEXP (x
, 1), 1);
1170 op
[0] = XEXP (x
, 0);
1174 op
[1] = XEXP (x
, 1);
1179 op
[0] = XEXP (x
, 0);
1181 op
[1] = XEXP (x
, 1);
1183 op
[2] = XEXP (x
, 2);
1188 op
[0] = TRAP_CONDITION (x
);
1192 op
[0] = XEXP (x
, 0);
1193 op
[1] = XEXP (x
, 1);
1194 op
[2] = XEXP (x
, 2);
1197 case UNSPEC_VOLATILE
:
1199 pp_string (pp
, "unspec");
1200 if (GET_CODE (x
) == UNSPEC_VOLATILE
)
1201 pp_string (pp
, "/v");
1202 pp_left_bracket (pp
);
1203 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
1207 print_pattern (pp
, XVECEXP (x
, 0, i
), verbose
);
1209 pp_string (pp
, "] ");
1210 pp_decimal_int (pp
, XINT (x
, 1));
1215 /* Most unhandled codes can be printed as pseudo-functions. */
1216 if (GET_RTX_CLASS (GET_CODE (x
)) == RTX_UNARY
)
1218 fun
= GET_RTX_NAME (GET_CODE (x
));
1219 op
[0] = XEXP (x
, 0);
1221 else if (GET_RTX_CLASS (GET_CODE (x
)) == RTX_COMPARE
1222 || GET_RTX_CLASS (GET_CODE (x
)) == RTX_COMM_COMPARE
1223 || GET_RTX_CLASS (GET_CODE (x
)) == RTX_BIN_ARITH
1224 || GET_RTX_CLASS (GET_CODE (x
)) == RTX_COMM_ARITH
)
1226 fun
= GET_RTX_NAME (GET_CODE (x
));
1227 op
[0] = XEXP (x
, 0);
1228 op
[1] = XEXP (x
, 1);
1230 else if (GET_RTX_CLASS (GET_CODE (x
)) == RTX_TERNARY
)
1232 fun
= GET_RTX_NAME (GET_CODE (x
));
1233 op
[0] = XEXP (x
, 0);
1234 op
[1] = XEXP (x
, 1);
1235 op
[2] = XEXP (x
, 2);
1238 /* Give up, just print the RTX name. */
1239 st
[0] = GET_RTX_NAME (GET_CODE (x
));
1244 /* Print this as a function? */
1247 pp_string (pp
, fun
);
1251 for (i
= 0; i
< 4; i
++)
1254 pp_string (pp
, st
[i
]);
1260 print_value (pp
, op
[i
], verbose
);
1265 pp_right_paren (pp
);
1268 /* Prints rtxes, I customarily classified as values. They're constants,
1269 registers, labels, symbols and memory accesses. */
1272 print_value (pretty_printer
*pp
, const_rtx x
, int verbose
)
1278 pp_string (pp
, "(nil)");
1281 switch (GET_CODE (x
))
1284 pp_scalar (pp
, HOST_WIDE_INT_PRINT_HEX
,
1285 (unsigned HOST_WIDE_INT
) INTVAL (x
));
1288 case CONST_WIDE_INT
:
1290 const char *sep
= "<";
1292 for (i
= CONST_WIDE_INT_NUNITS (x
) - 1; i
>= 0; i
--)
1294 pp_string (pp
, sep
);
1296 sprintf (tmp
, HOST_WIDE_INT_PRINT_HEX
,
1297 (unsigned HOST_WIDE_INT
) CONST_WIDE_INT_ELT (x
, i
));
1298 pp_string (pp
, tmp
);
1305 if (FLOAT_MODE_P (GET_MODE (x
)))
1307 real_to_decimal (tmp
, CONST_DOUBLE_REAL_VALUE (x
),
1308 sizeof (tmp
), 0, 1);
1309 pp_string (pp
, tmp
);
1312 pp_printf (pp
, "<%wx,%wx>",
1313 (unsigned HOST_WIDE_INT
) CONST_DOUBLE_LOW (x
),
1314 (unsigned HOST_WIDE_INT
) CONST_DOUBLE_HIGH (x
));
1317 fixed_to_decimal (tmp
, CONST_FIXED_VALUE (x
), sizeof (tmp
));
1318 pp_string (pp
, tmp
);
1321 pp_printf (pp
, "\"%s\"", XSTR (x
, 0));
1324 pp_printf (pp
, "`%s'", XSTR (x
, 0));
1327 pp_printf (pp
, "L%d", INSN_UID (LABEL_REF_LABEL (x
)));
1331 case STRICT_LOW_PART
:
1332 pp_printf (pp
, "%s(", GET_RTX_NAME (GET_CODE (x
)));
1333 print_value (pp
, XEXP (x
, 0), verbose
);
1334 pp_right_paren (pp
);
1337 if (REGNO (x
) < FIRST_PSEUDO_REGISTER
)
1339 if (ISDIGIT (reg_names
[REGNO (x
)][0]))
1341 pp_string (pp
, reg_names
[REGNO (x
)]);
1344 pp_printf (pp
, "r%d", REGNO (x
));
1346 pp_printf (pp
, ":%s", GET_MODE_NAME (GET_MODE (x
)));
1349 print_value (pp
, SUBREG_REG (x
), verbose
);
1350 pp_printf (pp
, "#%d", SUBREG_BYTE (x
));
1355 pp_string (pp
, GET_RTX_NAME (GET_CODE (x
)));
1358 pp_left_bracket (pp
);
1359 print_value (pp
, XEXP (x
, 0), verbose
);
1360 pp_right_bracket (pp
);
1363 pp_printf (pp
, "D#%i", DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x
)));
1366 print_exp (pp
, x
, verbose
);
1371 /* The next step in insn detalization, its pattern recognition. */
1374 print_pattern (pretty_printer
*pp
, const_rtx x
, int verbose
)
1378 pp_string (pp
, "(nil)");
1382 switch (GET_CODE (x
))
1385 print_value (pp
, SET_DEST (x
), verbose
);
1387 print_value (pp
, SET_SRC (x
), verbose
);
1392 pp_string (pp
, GET_RTX_NAME (GET_CODE (x
)));
1395 print_exp (pp
, x
, verbose
);
1399 pp_printf (pp
, "%s ", GET_RTX_NAME (GET_CODE (x
)));
1400 print_value (pp
, XEXP (x
, 0), verbose
);
1403 pp_string (pp
, "loc ");
1404 print_value (pp
, PAT_VAR_LOCATION_LOC (x
), verbose
);
1408 if (GET_CODE (COND_EXEC_TEST (x
)) == NE
1409 && XEXP (COND_EXEC_TEST (x
), 1) == const0_rtx
)
1410 print_value (pp
, XEXP (COND_EXEC_TEST (x
), 0), verbose
);
1411 else if (GET_CODE (COND_EXEC_TEST (x
)) == EQ
1412 && XEXP (COND_EXEC_TEST (x
), 1) == const0_rtx
)
1414 pp_exclamation (pp
);
1415 print_value (pp
, XEXP (COND_EXEC_TEST (x
), 0), verbose
);
1418 print_value (pp
, COND_EXEC_TEST (x
), verbose
);
1419 pp_string (pp
, ") ");
1420 print_pattern (pp
, COND_EXEC_CODE (x
), verbose
);
1427 for (i
= 0; i
< XVECLEN (x
, 0); i
++)
1429 print_pattern (pp
, XVECEXP (x
, 0, i
), verbose
);
1432 pp_right_brace (pp
);
1437 const rtx_sequence
*seq
= as_a
<const rtx_sequence
*> (x
);
1438 pp_string (pp
, "sequence{");
1439 if (INSN_P (seq
->element (0)))
1441 /* Print the sequence insns indented. */
1442 const char * save_print_rtx_head
= print_rtx_head
;
1443 char indented_print_rtx_head
[32];
1446 gcc_assert (strlen (print_rtx_head
) < sizeof (indented_print_rtx_head
) - 4);
1447 snprintf (indented_print_rtx_head
,
1448 sizeof (indented_print_rtx_head
),
1449 "%s ", print_rtx_head
);
1450 print_rtx_head
= indented_print_rtx_head
;
1451 for (int i
= 0; i
< seq
->len (); i
++)
1452 print_insn_with_notes (pp
, seq
->insn (i
));
1453 pp_printf (pp
, "%s ", save_print_rtx_head
);
1454 print_rtx_head
= save_print_rtx_head
;
1458 for (int i
= 0; i
< seq
->len (); i
++)
1460 print_pattern (pp
, seq
->element (i
), verbose
);
1464 pp_right_brace (pp
);
1468 pp_printf (pp
, "asm {%s}", XSTR (x
, 0));
1471 for (int i
= 0; i
< XVECLEN (x
, 0); i
++)
1473 print_value (pp
, XVECEXP (x
, 0, i
), verbose
);
1478 for (int i
= 0; i
< XVECLEN (x
, 1); i
++)
1480 print_value (pp
, XVECEXP (x
, 1, i
), verbose
);
1485 pp_string (pp
, "trap_if ");
1486 print_value (pp
, TRAP_CONDITION (x
), verbose
);
1489 case UNSPEC_VOLATILE
:
1490 /* Fallthru -- leave UNSPECs to print_exp. */
1492 print_value (pp
, x
, verbose
);
1494 } /* print_pattern */
1496 /* This is the main function in slim rtl visualization mechanism.
1498 X is an insn, to be printed into PP.
1500 This function tries to print it properly in human-readable form,
1501 resembling assembler mnemonics (instead of the older Lisp-style
1504 If VERBOSE is TRUE, insns are printed with more complete (but
1505 longer) pattern names and with extra information, and prefixed
1506 with their INSN_UIDs. */
1509 print_insn (pretty_printer
*pp
, const rtx_insn
*x
, int verbose
)
1513 /* Blech, pretty-print can't print integers with a specified width. */
1514 char uid_prefix
[32];
1515 snprintf (uid_prefix
, sizeof uid_prefix
, " %4d: ", INSN_UID (x
));
1516 pp_string (pp
, uid_prefix
);
1519 switch (GET_CODE (x
))
1522 print_pattern (pp
, PATTERN (x
), verbose
);
1527 const char *name
= "?";
1529 if (DECL_P (INSN_VAR_LOCATION_DECL (x
)))
1531 tree id
= DECL_NAME (INSN_VAR_LOCATION_DECL (x
));
1534 name
= IDENTIFIER_POINTER (id
);
1535 else if (TREE_CODE (INSN_VAR_LOCATION_DECL (x
))
1538 sprintf (idbuf
, "D#%i",
1539 DEBUG_TEMP_UID (INSN_VAR_LOCATION_DECL (x
)));
1544 sprintf (idbuf
, "D.%i",
1545 DECL_UID (INSN_VAR_LOCATION_DECL (x
)));
1549 pp_printf (pp
, "debug %s => ", name
);
1550 if (VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (x
)))
1551 pp_string (pp
, "optimized away");
1553 print_pattern (pp
, INSN_VAR_LOCATION_LOC (x
), verbose
);
1558 print_pattern (pp
, PATTERN (x
), verbose
);
1561 if (GET_CODE (PATTERN (x
)) == PARALLEL
)
1562 print_pattern (pp
, XVECEXP (PATTERN (x
), 0, 0), verbose
);
1564 print_pattern (pp
, PATTERN (x
), verbose
);
1567 pp_printf (pp
, "L%d:", INSN_UID (x
));
1569 case JUMP_TABLE_DATA
:
1570 pp_string (pp
, "jump_table_data{\n");
1571 print_pattern (pp
, PATTERN (x
), verbose
);
1572 pp_right_brace (pp
);
1575 pp_string (pp
, "barrier");
1579 pp_string (pp
, GET_NOTE_INSN_NAME (NOTE_KIND (x
)));
1580 switch (NOTE_KIND (x
))
1582 case NOTE_INSN_EH_REGION_BEG
:
1583 case NOTE_INSN_EH_REGION_END
:
1584 pp_printf (pp
, " %d", NOTE_EH_HANDLER (x
));
1587 case NOTE_INSN_BLOCK_BEG
:
1588 case NOTE_INSN_BLOCK_END
:
1589 pp_printf (pp
, " %d", BLOCK_NUMBER (NOTE_BLOCK (x
)));
1592 case NOTE_INSN_BASIC_BLOCK
:
1593 pp_printf (pp
, " %d", NOTE_BASIC_BLOCK (x
)->index
);
1596 case NOTE_INSN_DELETED_LABEL
:
1597 case NOTE_INSN_DELETED_DEBUG_LABEL
:
1599 const char *label
= NOTE_DELETED_LABEL_NAME (x
);
1602 pp_printf (pp
, " (\"%s\")", label
);
1606 case NOTE_INSN_VAR_LOCATION
:
1607 case NOTE_INSN_CALL_ARG_LOCATION
:
1609 print_pattern (pp
, NOTE_VAR_LOCATION (x
), verbose
);
1610 pp_right_brace (pp
);
1623 /* Pretty-print a slim dump of X (an insn) to PP, including any register
1624 note attached to the instruction. */
1627 print_insn_with_notes (pretty_printer
*pp
, const rtx_insn
*x
)
1629 pp_string (pp
, print_rtx_head
);
1630 print_insn (pp
, x
, 1);
1632 if (INSN_P (x
) && REG_NOTES (x
))
1633 for (rtx note
= REG_NOTES (x
); note
; note
= XEXP (note
, 1))
1635 pp_printf (pp
, "%s %s ", print_rtx_head
,
1636 GET_REG_NOTE_NAME (REG_NOTE_KIND (note
)));
1637 if (GET_CODE (note
) == INT_LIST
)
1638 pp_printf (pp
, "%d", XINT (note
, 0));
1640 print_pattern (pp
, XEXP (note
, 0), 1);
1645 /* Print X, an RTL value node, to file F in slim format. Include
1646 additional information if VERBOSE is nonzero.
1648 Value nodes are constants, registers, labels, symbols and
1652 dump_value_slim (FILE *f
, const_rtx x
, int verbose
)
1654 pretty_printer rtl_slim_pp
;
1655 rtl_slim_pp
.buffer
->stream
= f
;
1656 print_value (&rtl_slim_pp
, x
, verbose
);
1657 pp_flush (&rtl_slim_pp
);
1660 /* Emit a slim dump of X (an insn) to the file F, including any register
1661 note attached to the instruction. */
1663 dump_insn_slim (FILE *f
, const rtx_insn
*x
)
1665 pretty_printer rtl_slim_pp
;
1666 rtl_slim_pp
.buffer
->stream
= f
;
1667 print_insn_with_notes (&rtl_slim_pp
, x
);
1668 pp_flush (&rtl_slim_pp
);
1671 /* Same as above, but stop at LAST or when COUNT == 0.
1672 If COUNT < 0 it will stop only at LAST or NULL rtx. */
1675 dump_rtl_slim (FILE *f
, const rtx_insn
*first
, const rtx_insn
*last
,
1676 int count
, int flags ATTRIBUTE_UNUSED
)
1678 const rtx_insn
*insn
, *tail
;
1679 pretty_printer rtl_slim_pp
;
1680 rtl_slim_pp
.buffer
->stream
= f
;
1682 tail
= last
? NEXT_INSN (last
) : NULL
;
1684 (insn
!= NULL
) && (insn
!= tail
) && (count
!= 0);
1685 insn
= NEXT_INSN (insn
))
1687 print_insn_with_notes (&rtl_slim_pp
, insn
);
1692 pp_flush (&rtl_slim_pp
);
1695 /* Dumps basic block BB to pretty-printer PP in slim form and without and
1696 no indentation, for use as a label of a DOT graph record-node. */
1699 rtl_dump_bb_for_graph (pretty_printer
*pp
, basic_block bb
)
1704 /* TODO: inter-bb stuff. */
1705 FOR_BB_INSNS (bb
, insn
)
1710 pp_write_text_to_stream (pp
);
1713 print_insn_with_notes (pp
, insn
);
1714 pp_write_text_as_dot_label_to_stream (pp
, /*for_record=*/true);
1718 /* Pretty-print pattern X of some insn in non-verbose mode.
1719 Return a string pointer to the pretty-printer buffer.
1721 This function is only exported exists only to accommodate some older users
1722 of the slim RTL pretty printers. Please do not use it for new code. */
1725 str_pattern_slim (const_rtx x
)
1727 pretty_printer rtl_slim_pp
;
1728 print_pattern (&rtl_slim_pp
, x
, 0);
1729 return ggc_strdup (pp_formatted_text (&rtl_slim_pp
));
1732 /* Emit a slim dump of X (an insn) to stderr. */
1733 extern void debug_insn_slim (const rtx_insn
*);
1735 debug_insn_slim (const rtx_insn
*x
)
1737 dump_insn_slim (stderr
, x
);
1740 /* Same as above, but using dump_rtl_slim. */
1741 extern void debug_rtl_slim (FILE *, const rtx_insn
*, const rtx_insn
*,
1744 debug_rtl_slim (const rtx_insn
*first
, const rtx_insn
*last
, int count
,
1747 dump_rtl_slim (stderr
, first
, last
, count
, flags
);
1750 extern void debug_bb_slim (basic_block
);
1752 debug_bb_slim (basic_block bb
)
1754 dump_bb (stderr
, bb
, 0, TDF_SLIM
| TDF_BLOCKS
);
1757 extern void debug_bb_n_slim (int);
1759 debug_bb_n_slim (int n
)
1761 basic_block bb
= BASIC_BLOCK_FOR_FN (cfun
, n
);