2016-11-10 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / print-rtl.c
blobe7368c73c42f3f71853b97acfe6292ac51f5cc4d
1 /* Print RTL for GCC.
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
9 version.
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
14 for more details.
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. */
22 #ifdef GENERATOR_FILE
23 #include "bconfig.h"
24 #else
25 #include "config.h"
26 #endif
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "rtl.h"
33 /* These headers all define things which are not available in
34 generator programs. */
35 #ifndef GENERATOR_FILE
36 #include "alias.h"
37 #include "tree.h"
38 #include "cfg.h"
39 #include "print-tree.h"
40 #include "flags.h"
41 #include "predict.h"
42 #include "function.h"
43 #include "basic-block.h"
44 #include "diagnostic.h"
45 #include "tree-pretty-print.h"
46 #include "alloc-pool.h"
47 #include "cselib.h"
48 #include "dumpfile.h" /* for dump_flags */
49 #include "dwarf2out.h"
50 #include "pretty-print.h"
51 #endif
53 #include "print-rtl.h"
55 /* String printed at beginning of each RTL when it is dumped.
56 This string is set to ASM_COMMENT_START when the RTL is dumped in
57 the assembly output file. */
58 const char *print_rtx_head = "";
60 #ifdef GENERATOR_FILE
61 /* These are defined from the .opt file when not used in generator
62 programs. */
64 /* Nonzero means suppress output of instruction numbers
65 in debugging dumps.
66 This must be defined here so that programs like gencodes can be linked. */
67 int flag_dump_unnumbered = 0;
69 /* Nonzero means suppress output of instruction numbers for previous
70 and next insns in debugging dumps.
71 This must be defined here so that programs like gencodes can be linked. */
72 int flag_dump_unnumbered_links = 0;
73 #endif
75 /* Constructor for rtx_writer. */
77 rtx_writer::rtx_writer (FILE *outf, int ind, bool simple, bool compact)
78 : m_outfile (outf), m_sawclose (0), m_indent (ind),
79 m_in_call_function_usage (false), m_simple (simple), m_compact (compact)
83 #ifndef GENERATOR_FILE
84 void
85 print_mem_expr (FILE *outfile, const_tree expr)
87 fputc (' ', outfile);
88 print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
90 #endif
92 /* Subroutine of print_rtx_operand for handling code '0'.
93 0 indicates a field for internal use that should not be printed.
94 However there are various special cases, such as the third field
95 of a NOTE, where it indicates that the field has several different
96 valid contents. */
98 void
99 rtx_writer::print_rtx_operand_code_0 (const_rtx in_rtx ATTRIBUTE_UNUSED,
100 int idx ATTRIBUTE_UNUSED)
102 #ifndef GENERATOR_FILE
103 if (idx == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
105 int flags = SYMBOL_REF_FLAGS (in_rtx);
106 if (flags)
107 fprintf (m_outfile, " [flags %#x]", flags);
108 tree decl = SYMBOL_REF_DECL (in_rtx);
109 if (decl)
110 print_node_brief (m_outfile, "", decl, dump_flags);
112 else if (idx == 3 && NOTE_P (in_rtx))
114 switch (NOTE_KIND (in_rtx))
116 case NOTE_INSN_EH_REGION_BEG:
117 case NOTE_INSN_EH_REGION_END:
118 if (flag_dump_unnumbered)
119 fprintf (m_outfile, " #");
120 else
121 fprintf (m_outfile, " %d", NOTE_EH_HANDLER (in_rtx));
122 m_sawclose = 1;
123 break;
125 case NOTE_INSN_BLOCK_BEG:
126 case NOTE_INSN_BLOCK_END:
127 dump_addr (m_outfile, " ", NOTE_BLOCK (in_rtx));
128 m_sawclose = 1;
129 break;
131 case NOTE_INSN_BASIC_BLOCK:
133 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
134 if (bb != 0)
135 fprintf (m_outfile, " [bb %d]", bb->index);
136 break;
139 case NOTE_INSN_DELETED_LABEL:
140 case NOTE_INSN_DELETED_DEBUG_LABEL:
142 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
143 if (label)
144 fprintf (m_outfile, " (\"%s\")", label);
145 else
146 fprintf (m_outfile, " \"\"");
148 break;
150 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
152 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
153 if (bb != 0)
154 fprintf (m_outfile, " [bb %d]", bb->index);
155 break;
158 case NOTE_INSN_VAR_LOCATION:
159 case NOTE_INSN_CALL_ARG_LOCATION:
160 fputc (' ', m_outfile);
161 print_rtx (NOTE_VAR_LOCATION (in_rtx));
162 break;
164 case NOTE_INSN_CFI:
165 fputc ('\n', m_outfile);
166 output_cfi_directive (m_outfile, NOTE_CFI (in_rtx));
167 fputc ('\t', m_outfile);
168 break;
170 default:
171 break;
174 else if (idx == 7 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL
175 && !m_compact)
177 /* Output the JUMP_LABEL reference. */
178 fprintf (m_outfile, "\n%s%*s -> ", print_rtx_head, m_indent * 2, "");
179 if (GET_CODE (JUMP_LABEL (in_rtx)) == RETURN)
180 fprintf (m_outfile, "return");
181 else if (GET_CODE (JUMP_LABEL (in_rtx)) == SIMPLE_RETURN)
182 fprintf (m_outfile, "simple_return");
183 else
184 fprintf (m_outfile, "%d", INSN_UID (JUMP_LABEL (in_rtx)));
186 else if (idx == 0 && GET_CODE (in_rtx) == VALUE)
188 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
190 fprintf (m_outfile, " %u:%u", val->uid, val->hash);
191 dump_addr (m_outfile, " @", in_rtx);
192 dump_addr (m_outfile, "/", (void*)val);
194 else if (idx == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
196 fprintf (m_outfile, " D#%i",
197 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
199 else if (idx == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
201 m_indent += 2;
202 if (!m_sawclose)
203 fprintf (m_outfile, " ");
204 print_rtx (ENTRY_VALUE_EXP (in_rtx));
205 m_indent -= 2;
207 #endif
210 /* Subroutine of print_rtx_operand for handling code 'e'.
211 Also called by print_rtx_operand_code_u for handling code 'u'
212 for LABEL_REFs when they don't reference a CODE_LABEL. */
214 void
215 rtx_writer::print_rtx_operand_code_e (const_rtx in_rtx, int idx)
217 m_indent += 2;
218 if (idx == 6 && INSN_P (in_rtx))
219 /* Put REG_NOTES on their own line. */
220 fprintf (m_outfile, "\n%s%*s",
221 print_rtx_head, m_indent * 2, "");
222 if (!m_sawclose)
223 fprintf (m_outfile, " ");
224 if (idx == 7 && CALL_P (in_rtx))
226 m_in_call_function_usage = true;
227 print_rtx (XEXP (in_rtx, idx));
228 m_in_call_function_usage = false;
230 else
231 print_rtx (XEXP (in_rtx, idx));
232 m_indent -= 2;
235 /* Subroutine of print_rtx_operand for handling codes 'E' and 'V'. */
237 void
238 rtx_writer::print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx)
240 m_indent += 2;
241 if (m_sawclose)
243 fprintf (m_outfile, "\n%s%*s",
244 print_rtx_head, m_indent * 2, "");
245 m_sawclose = 0;
247 fputs (" [", m_outfile);
248 if (NULL != XVEC (in_rtx, idx))
250 m_indent += 2;
251 if (XVECLEN (in_rtx, idx))
252 m_sawclose = 1;
254 for (int j = 0; j < XVECLEN (in_rtx, idx); j++)
255 print_rtx (XVECEXP (in_rtx, idx, j));
257 m_indent -= 2;
259 if (m_sawclose)
260 fprintf (m_outfile, "\n%s%*s", print_rtx_head, m_indent * 2, "");
262 fputs ("]", m_outfile);
263 m_sawclose = 1;
264 m_indent -= 2;
267 /* Subroutine of print_rtx_operand for handling code 'i'. */
269 void
270 rtx_writer::print_rtx_operand_code_i (const_rtx in_rtx, int idx)
272 if (idx == 4 && INSN_P (in_rtx))
274 #ifndef GENERATOR_FILE
275 const rtx_insn *in_insn = as_a <const rtx_insn *> (in_rtx);
277 /* Pretty-print insn locations. Ignore scoping as it is mostly
278 redundant with line number information and do not print anything
279 when there is no location information available. */
280 if (INSN_HAS_LOCATION (in_insn))
282 expanded_location xloc = insn_location (in_insn);
283 fprintf (m_outfile, " \"%s\":%i", xloc.file, xloc.line);
285 #endif
287 else if (idx == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
289 #ifndef GENERATOR_FILE
290 if (ASM_OPERANDS_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
291 fprintf (m_outfile, " %s:%i",
292 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
293 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
294 #endif
296 else if (idx == 1 && GET_CODE (in_rtx) == ASM_INPUT)
298 #ifndef GENERATOR_FILE
299 if (ASM_INPUT_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
300 fprintf (m_outfile, " %s:%i",
301 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
302 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
303 #endif
305 else if (idx == 5 && NOTE_P (in_rtx))
307 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
308 other times often contains garbage from INSN->NOTE death. */
309 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL
310 || NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_DEBUG_LABEL)
311 fprintf (m_outfile, " %d", XINT (in_rtx, idx));
313 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
314 else if (idx == 1
315 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
316 && XINT (in_rtx, 1) >= 0
317 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
318 fprintf (m_outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
319 #endif
320 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
321 else if (idx == 1
322 && (GET_CODE (in_rtx) == UNSPEC
323 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
324 && XINT (in_rtx, 1) >= 0
325 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
326 fprintf (m_outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
327 #endif
328 else
330 int value = XINT (in_rtx, idx);
331 const char *name;
332 int is_insn = INSN_P (in_rtx);
334 /* Don't print INSN_CODEs in compact mode. */
335 if (m_compact && is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, idx))
337 m_sawclose = 0;
338 return;
341 if (flag_dump_unnumbered
342 && (is_insn || NOTE_P (in_rtx)))
343 fputc ('#', m_outfile);
344 else
345 fprintf (m_outfile, " %d", value);
347 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, idx)
348 && XINT (in_rtx, idx) >= 0
349 && (name = get_insn_name (XINT (in_rtx, idx))) != NULL)
350 fprintf (m_outfile, " {%s}", name);
351 m_sawclose = 0;
355 /* Subroutine of print_rtx_operand for handling code 'r'. */
357 void
358 rtx_writer::print_rtx_operand_code_r (const_rtx in_rtx)
360 int is_insn = INSN_P (in_rtx);
361 unsigned int regno = REGNO (in_rtx);
363 #ifndef GENERATOR_FILE
364 /* For hard registers and virtuals, always print the
365 regno, except in compact mode. */
366 if (regno <= LAST_VIRTUAL_REGISTER && !m_compact)
367 fprintf (m_outfile, " %d", regno);
368 if (regno < FIRST_PSEUDO_REGISTER)
369 fprintf (m_outfile, " %s", reg_names[regno]);
370 else if (regno <= LAST_VIRTUAL_REGISTER)
372 if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
373 fprintf (m_outfile, " virtual-incoming-args");
374 else if (regno == VIRTUAL_STACK_VARS_REGNUM)
375 fprintf (m_outfile, " virtual-stack-vars");
376 else if (regno == VIRTUAL_STACK_DYNAMIC_REGNUM)
377 fprintf (m_outfile, " virtual-stack-dynamic");
378 else if (regno == VIRTUAL_OUTGOING_ARGS_REGNUM)
379 fprintf (m_outfile, " virtual-outgoing-args");
380 else if (regno == VIRTUAL_CFA_REGNUM)
381 fprintf (m_outfile, " virtual-cfa");
382 else if (regno == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
383 fprintf (m_outfile, " virtual-preferred-stack-boundary");
384 else
385 fprintf (m_outfile, " virtual-reg-%d", regno-FIRST_VIRTUAL_REGISTER);
387 else
388 #endif
389 if (flag_dump_unnumbered && is_insn)
390 fputc ('#', m_outfile);
391 else if (m_compact)
393 /* In compact mode, print pseudos with a '%' sigil following
394 by the regno, offset by (LAST_VIRTUAL_REGISTER + 1), so that the
395 first non-virtual pseudo is dumped as "%0". */
396 gcc_assert (regno > LAST_VIRTUAL_REGISTER);
397 fprintf (m_outfile, " %%%d", regno - (LAST_VIRTUAL_REGISTER + 1));
399 else
400 fprintf (m_outfile, " %d", regno);
402 #ifndef GENERATOR_FILE
403 if (REG_ATTRS (in_rtx))
405 fputs (" [", m_outfile);
406 if (regno != ORIGINAL_REGNO (in_rtx))
407 fprintf (m_outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
408 if (REG_EXPR (in_rtx))
409 print_mem_expr (m_outfile, REG_EXPR (in_rtx));
411 if (REG_OFFSET (in_rtx))
412 fprintf (m_outfile, "+" HOST_WIDE_INT_PRINT_DEC,
413 REG_OFFSET (in_rtx));
414 fputs (" ]", m_outfile);
416 if (regno != ORIGINAL_REGNO (in_rtx))
417 fprintf (m_outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
418 #endif
421 /* Subroutine of print_rtx_operand for handling code 'u'. */
423 void
424 rtx_writer::print_rtx_operand_code_u (const_rtx in_rtx, int idx)
426 /* Don't print insn UIDs for PREV/NEXT_INSN in compact mode. */
427 if (m_compact && INSN_CHAIN_CODE_P (GET_CODE (in_rtx)) && idx < 2)
428 return;
430 if (XEXP (in_rtx, idx) != NULL)
432 rtx sub = XEXP (in_rtx, idx);
433 enum rtx_code subc = GET_CODE (sub);
435 if (GET_CODE (in_rtx) == LABEL_REF)
437 if (subc == NOTE
438 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
440 if (flag_dump_unnumbered)
441 fprintf (m_outfile, " [# deleted]");
442 else
443 fprintf (m_outfile, " [%d deleted]", INSN_UID (sub));
444 m_sawclose = 0;
445 return;
448 if (subc != CODE_LABEL)
450 print_rtx_operand_code_e (in_rtx, idx);
451 return;
455 if (flag_dump_unnumbered
456 || (flag_dump_unnumbered_links && idx <= 1
457 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
458 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
459 fputs (" #", m_outfile);
460 else
461 fprintf (m_outfile, " %d", INSN_UID (sub));
463 else
464 fputs (" 0", m_outfile);
465 m_sawclose = 0;
468 /* Subroutine of print_rtx. Print operand IDX of IN_RTX. */
470 void
471 rtx_writer::print_rtx_operand (const_rtx in_rtx, int idx)
473 const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
475 switch (format_ptr[idx])
477 const char *str;
479 case 'T':
480 str = XTMPL (in_rtx, idx);
481 goto string;
483 case 'S':
484 case 's':
485 str = XSTR (in_rtx, idx);
486 string:
488 if (str == 0)
489 fputs (" \"\"", m_outfile);
490 else
491 fprintf (m_outfile, " (\"%s\")", str);
492 m_sawclose = 1;
493 break;
495 case '0':
496 print_rtx_operand_code_0 (in_rtx, idx);
497 break;
499 case 'e':
500 print_rtx_operand_code_e (in_rtx, idx);
501 break;
503 case 'E':
504 case 'V':
505 print_rtx_operand_codes_E_and_V (in_rtx, idx);
506 break;
508 case 'w':
509 if (! m_simple)
510 fprintf (m_outfile, " ");
511 fprintf (m_outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, idx));
512 if (! m_simple && !m_compact)
513 fprintf (m_outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
514 (unsigned HOST_WIDE_INT) XWINT (in_rtx, idx));
515 break;
517 case 'i':
518 print_rtx_operand_code_i (in_rtx, idx);
519 break;
521 case 'r':
522 print_rtx_operand_code_r (in_rtx);
523 break;
525 /* Print NOTE_INSN names rather than integer codes. */
527 case 'n':
528 fprintf (m_outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, idx)));
529 m_sawclose = 0;
530 break;
532 case 'u':
533 print_rtx_operand_code_u (in_rtx, idx);
534 break;
536 case 't':
537 #ifndef GENERATOR_FILE
538 if (idx == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
539 print_mem_expr (m_outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
540 else if (idx == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
541 print_mem_expr (m_outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
542 else
543 dump_addr (m_outfile, " ", XTREE (in_rtx, idx));
544 #endif
545 break;
547 case '*':
548 fputs (" Unknown", m_outfile);
549 m_sawclose = 0;
550 break;
552 case 'B':
553 /* Don't print basic block ids in compact mode. */
554 if (m_compact)
555 break;
556 #ifndef GENERATOR_FILE
557 if (XBBDEF (in_rtx, idx))
558 fprintf (m_outfile, " %i", XBBDEF (in_rtx, idx)->index);
559 #endif
560 break;
562 default:
563 gcc_unreachable ();
567 /* Subroutine of rtx_writer::print_rtx.
568 In compact mode, determine if operand IDX of IN_RTX is interesting
569 to dump, or (if in a trailing position) it can be omitted. */
571 bool
572 rtx_writer::operand_has_default_value_p (const_rtx in_rtx, int idx)
574 const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
576 switch (format_ptr[idx])
578 case 'e':
579 case 'u':
580 return XEXP (in_rtx, idx) == NULL_RTX;
582 case 's':
583 return XSTR (in_rtx, idx) == NULL;
585 case '0':
586 switch (GET_CODE (in_rtx))
588 case JUMP_INSN:
589 /* JUMP_LABELs are always omitted in compact mode, so treat
590 any value here as omittable, so that earlier operands can
591 potentially be omitted also. */
592 return m_compact;
594 default:
595 return false;
599 default:
600 return false;
604 /* Print IN_RTX onto m_outfile. This is the recursive part of printing. */
606 void
607 rtx_writer::print_rtx (const_rtx in_rtx)
609 int idx = 0;
611 if (m_sawclose)
613 if (m_simple)
614 fputc (' ', m_outfile);
615 else
616 fprintf (m_outfile, "\n%s%*s", print_rtx_head, m_indent * 2, "");
617 m_sawclose = 0;
620 if (in_rtx == 0)
622 fputs ("(nil)", m_outfile);
623 m_sawclose = 1;
624 return;
626 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
628 fprintf (m_outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
629 print_rtx_head, m_indent * 2, "");
630 m_sawclose = 1;
631 return;
634 /* Print name of expression code. */
636 /* In compact mode, prefix the code of insns with "c",
637 giving "cinsn", "cnote" etc. */
638 if (m_compact && is_a <const rtx_insn *, const struct rtx_def> (in_rtx))
640 /* "ccode_label" is slightly awkward, so special-case it as
641 just "clabel". */
642 rtx_code code = GET_CODE (in_rtx);
643 if (code == CODE_LABEL)
644 fprintf (m_outfile, "(clabel");
645 else
646 fprintf (m_outfile, "(c%s", GET_RTX_NAME (code));
648 else if (m_simple && CONST_INT_P (in_rtx))
649 fputc ('(', m_outfile);
650 else
651 fprintf (m_outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
653 if (! m_simple)
655 if (RTX_FLAG (in_rtx, in_struct))
656 fputs ("/s", m_outfile);
658 if (RTX_FLAG (in_rtx, volatil))
659 fputs ("/v", m_outfile);
661 if (RTX_FLAG (in_rtx, unchanging))
662 fputs ("/u", m_outfile);
664 if (RTX_FLAG (in_rtx, frame_related))
665 fputs ("/f", m_outfile);
667 if (RTX_FLAG (in_rtx, jump))
668 fputs ("/j", m_outfile);
670 if (RTX_FLAG (in_rtx, call))
671 fputs ("/c", m_outfile);
673 if (RTX_FLAG (in_rtx, return_val))
674 fputs ("/i", m_outfile);
676 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
677 if ((GET_CODE (in_rtx) == EXPR_LIST
678 || GET_CODE (in_rtx) == INSN_LIST
679 || GET_CODE (in_rtx) == INT_LIST)
680 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX
681 && !m_in_call_function_usage)
682 fprintf (m_outfile, ":%s",
683 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
685 /* For other rtl, print the mode if it's not VOID. */
686 else if (GET_MODE (in_rtx) != VOIDmode)
687 fprintf (m_outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
689 #ifndef GENERATOR_FILE
690 if (GET_CODE (in_rtx) == VAR_LOCATION)
692 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
693 fputs (" <debug string placeholder>", m_outfile);
694 else
695 print_mem_expr (m_outfile, PAT_VAR_LOCATION_DECL (in_rtx));
696 fputc (' ', m_outfile);
697 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
698 if (PAT_VAR_LOCATION_STATUS (in_rtx)
699 == VAR_INIT_STATUS_UNINITIALIZED)
700 fprintf (m_outfile, " [uninit]");
701 m_sawclose = 1;
702 idx = GET_RTX_LENGTH (VAR_LOCATION);
704 #endif
707 #ifndef GENERATOR_FILE
708 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx))
709 idx = 5;
710 #endif
712 /* For insns, print the INSN_UID. */
713 if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx)))
715 if (flag_dump_unnumbered)
716 fprintf (m_outfile, " #");
717 else
718 fprintf (m_outfile, " %d", INSN_UID (in_rtx));
721 /* Determine which is the final operand to print.
722 In compact mode, skip trailing operands that have the default values
723 e.g. trailing "(nil)" values. */
724 int limit = GET_RTX_LENGTH (GET_CODE (in_rtx));
725 if (m_compact)
726 while (limit > idx && operand_has_default_value_p (in_rtx, limit - 1))
727 limit--;
729 /* Get the format string and skip the first elements if we have handled
730 them already. */
732 for (; idx < limit; idx++)
733 print_rtx_operand (in_rtx, idx);
735 switch (GET_CODE (in_rtx))
737 #ifndef GENERATOR_FILE
738 case MEM:
739 if (__builtin_expect (final_insns_dump_p, false))
740 fprintf (m_outfile, " [");
741 else
742 fprintf (m_outfile, " [" HOST_WIDE_INT_PRINT_DEC,
743 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
745 if (MEM_EXPR (in_rtx))
746 print_mem_expr (m_outfile, MEM_EXPR (in_rtx));
747 else
748 fputc (' ', m_outfile);
750 if (MEM_OFFSET_KNOWN_P (in_rtx))
751 fprintf (m_outfile, "+" HOST_WIDE_INT_PRINT_DEC, MEM_OFFSET (in_rtx));
753 if (MEM_SIZE_KNOWN_P (in_rtx))
754 fprintf (m_outfile, " S" HOST_WIDE_INT_PRINT_DEC, MEM_SIZE (in_rtx));
756 if (MEM_ALIGN (in_rtx) != 1)
757 fprintf (m_outfile, " A%u", MEM_ALIGN (in_rtx));
759 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
760 fprintf (m_outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
762 fputc (']', m_outfile);
763 break;
765 case CONST_DOUBLE:
766 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
768 char s[60];
770 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
771 sizeof (s), 0, 1);
772 fprintf (m_outfile, " %s", s);
774 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
775 sizeof (s), 0, 1);
776 fprintf (m_outfile, " [%s]", s);
778 break;
780 case CONST_WIDE_INT:
781 fprintf (m_outfile, " ");
782 cwi_output_hex (m_outfile, in_rtx);
783 break;
784 #endif
786 case CODE_LABEL:
787 if (!m_compact)
788 fprintf (m_outfile, " [%d uses]", LABEL_NUSES (in_rtx));
789 switch (LABEL_KIND (in_rtx))
791 case LABEL_NORMAL: break;
792 case LABEL_STATIC_ENTRY: fputs (" [entry]", m_outfile); break;
793 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", m_outfile); break;
794 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", m_outfile); break;
795 default: gcc_unreachable ();
797 break;
799 default:
800 break;
803 fputc (')', m_outfile);
804 m_sawclose = 1;
807 /* Emit a closing parenthesis and newline. */
809 void
810 rtx_writer::finish_directive ()
812 fprintf (m_outfile, ")\n");
813 m_sawclose = 0;
816 /* Print an rtx on the current line of FILE. Initially indent IND
817 characters. */
819 void
820 print_inline_rtx (FILE *outf, const_rtx x, int ind)
822 rtx_writer w (outf, ind, false, false);
823 w.print_rtx (x);
826 /* Call this function from the debugger to see what X looks like. */
828 DEBUG_FUNCTION void
829 debug_rtx (const_rtx x)
831 rtx_writer w (stderr, 0, false, false);
832 w.print_rtx (x);
833 fprintf (stderr, "\n");
836 /* Dump rtx REF. */
838 DEBUG_FUNCTION void
839 debug (const rtx_def &ref)
841 debug_rtx (&ref);
844 DEBUG_FUNCTION void
845 debug (const rtx_def *ptr)
847 if (ptr)
848 debug (*ptr);
849 else
850 fprintf (stderr, "<nil>\n");
853 /* Count of rtx's to print with debug_rtx_list.
854 This global exists because gdb user defined commands have no arguments. */
856 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
858 /* Call this function to print list from X on.
860 N is a count of the rtx's to print. Positive values print from the specified
861 rtx_insn on. Negative values print a window around the rtx_insn.
862 EG: -5 prints 2 rtx_insn's on either side (in addition to the specified
863 rtx_insn). */
865 DEBUG_FUNCTION void
866 debug_rtx_list (const rtx_insn *x, int n)
868 int i,count;
869 const rtx_insn *insn;
871 count = n == 0 ? 1 : n < 0 ? -n : n;
873 /* If we are printing a window, back up to the start. */
875 if (n < 0)
876 for (i = count / 2; i > 0; i--)
878 if (PREV_INSN (x) == 0)
879 break;
880 x = PREV_INSN (x);
883 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
885 debug_rtx (insn);
886 fprintf (stderr, "\n");
890 /* Call this function to print an rtx_insn list from START to END
891 inclusive. */
893 DEBUG_FUNCTION void
894 debug_rtx_range (const rtx_insn *start, const rtx_insn *end)
896 while (1)
898 debug_rtx (start);
899 fprintf (stderr, "\n");
900 if (!start || start == end)
901 break;
902 start = NEXT_INSN (start);
906 /* Call this function to search an rtx_insn list to find one with insn uid UID,
907 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
908 The found insn is returned to enable further debugging analysis. */
910 DEBUG_FUNCTION const rtx_insn *
911 debug_rtx_find (const rtx_insn *x, int uid)
913 while (x != 0 && INSN_UID (x) != uid)
914 x = NEXT_INSN (x);
915 if (x != 0)
917 debug_rtx_list (x, debug_rtx_count);
918 return x;
920 else
922 fprintf (stderr, "insn uid %d not found\n", uid);
923 return 0;
927 /* External entry point for printing a chain of insns
928 starting with RTX_FIRST.
929 A blank line separates insns.
931 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
933 void
934 rtx_writer::print_rtl (const_rtx rtx_first)
936 const rtx_insn *tmp_rtx;
938 if (rtx_first == 0)
940 fputs (print_rtx_head, m_outfile);
941 fputs ("(nil)\n", m_outfile);
943 else
944 switch (GET_CODE (rtx_first))
946 case INSN:
947 case JUMP_INSN:
948 case CALL_INSN:
949 case NOTE:
950 case CODE_LABEL:
951 case JUMP_TABLE_DATA:
952 case BARRIER:
953 for (tmp_rtx = as_a <const rtx_insn *> (rtx_first);
954 tmp_rtx != 0;
955 tmp_rtx = NEXT_INSN (tmp_rtx))
957 fputs (print_rtx_head, m_outfile);
958 print_rtx (tmp_rtx);
959 fprintf (m_outfile, "\n");
961 break;
963 default:
964 fputs (print_rtx_head, m_outfile);
965 print_rtx (rtx_first);
969 /* External entry point for printing a chain of insns
970 starting with RTX_FIRST onto file OUTF.
971 A blank line separates insns.
973 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
975 void
976 print_rtl (FILE *outf, const_rtx rtx_first)
978 rtx_writer w (outf, 0, false, false);
979 w.print_rtl (rtx_first);
982 /* Like print_rtx, except specify a file. */
983 /* Return nonzero if we actually printed anything. */
986 print_rtl_single (FILE *outf, const_rtx x)
988 rtx_writer w (outf, 0, false, false);
989 return w.print_rtl_single_with_indent (x, 0);
992 /* Like print_rtl_single, except specify an indentation. */
995 rtx_writer::print_rtl_single_with_indent (const_rtx x, int ind)
997 char *s_indent = (char *) alloca ((size_t) ind + 1);
998 memset ((void *) s_indent, ' ', (size_t) ind);
999 s_indent[ind] = '\0';
1000 fputs (s_indent, m_outfile);
1001 fputs (print_rtx_head, m_outfile);
1003 int old_indent = m_indent;
1004 m_indent = ind;
1005 m_sawclose = 0;
1006 print_rtx (x);
1007 putc ('\n', m_outfile);
1008 m_indent = old_indent;
1009 return 1;
1013 /* Like print_rtl except without all the detail; for example,
1014 if RTX is a CONST_INT then print in decimal format. */
1016 void
1017 print_simple_rtl (FILE *outf, const_rtx x)
1019 rtx_writer w (outf, 0, true, false);
1020 w.print_rtl (x);
1023 /* Print the elements of VEC to FILE. */
1025 void
1026 print_rtx_insn_vec (FILE *file, const vec<rtx_insn *> &vec)
1028 fputc('{', file);
1030 unsigned int len = vec.length ();
1031 for (unsigned int i = 0; i < len; i++)
1033 print_rtl (file, vec[i]);
1034 if (i < len - 1)
1035 fputs (", ", file);
1038 fputc ('}', file);
1041 #ifndef GENERATOR_FILE
1042 /* The functions below try to print RTL in a form resembling assembler
1043 mnemonics. Because this form is more concise than the "traditional" form
1044 of RTL printing in Lisp-style, the form printed by this file is called
1045 "slim". RTL dumps in slim format can be obtained by appending the "-slim"
1046 option to -fdump-rtl-<pass>. Control flow graph output as a DOT file is
1047 always printed in slim form.
1049 The normal interface to the functionality provided in this pretty-printer
1050 is through the dump_*_slim functions to print to a stream, or via the
1051 print_*_slim functions to print into a user's pretty-printer.
1053 It is also possible to obtain a string for a single pattern as a string
1054 pointer, via str_pattern_slim, but this usage is discouraged. */
1056 /* For insns we print patterns, and for some patterns we print insns... */
1057 static void print_insn_with_notes (pretty_printer *, const rtx_insn *);
1059 /* This recognizes rtx'en classified as expressions. These are always
1060 represent some action on values or results of other expression, that
1061 may be stored in objects representing values. */
1063 static void
1064 print_exp (pretty_printer *pp, const_rtx x, int verbose)
1066 const char *st[4];
1067 const char *fun;
1068 rtx op[4];
1069 int i;
1071 fun = (char *) 0;
1072 for (i = 0; i < 4; i++)
1074 st[i] = (char *) 0;
1075 op[i] = NULL_RTX;
1078 switch (GET_CODE (x))
1080 case PLUS:
1081 op[0] = XEXP (x, 0);
1082 if (CONST_INT_P (XEXP (x, 1))
1083 && INTVAL (XEXP (x, 1)) < 0)
1085 st[1] = "-";
1086 op[1] = GEN_INT (-INTVAL (XEXP (x, 1)));
1088 else
1090 st[1] = "+";
1091 op[1] = XEXP (x, 1);
1093 break;
1094 case LO_SUM:
1095 op[0] = XEXP (x, 0);
1096 st[1] = "+low(";
1097 op[1] = XEXP (x, 1);
1098 st[2] = ")";
1099 break;
1100 case MINUS:
1101 op[0] = XEXP (x, 0);
1102 st[1] = "-";
1103 op[1] = XEXP (x, 1);
1104 break;
1105 case COMPARE:
1106 fun = "cmp";
1107 op[0] = XEXP (x, 0);
1108 op[1] = XEXP (x, 1);
1109 break;
1110 case NEG:
1111 st[0] = "-";
1112 op[0] = XEXP (x, 0);
1113 break;
1114 case FMA:
1115 st[0] = "{";
1116 op[0] = XEXP (x, 0);
1117 st[1] = "*";
1118 op[1] = XEXP (x, 1);
1119 st[2] = "+";
1120 op[2] = XEXP (x, 2);
1121 st[3] = "}";
1122 break;
1123 case MULT:
1124 op[0] = XEXP (x, 0);
1125 st[1] = "*";
1126 op[1] = XEXP (x, 1);
1127 break;
1128 case DIV:
1129 op[0] = XEXP (x, 0);
1130 st[1] = "/";
1131 op[1] = XEXP (x, 1);
1132 break;
1133 case UDIV:
1134 fun = "udiv";
1135 op[0] = XEXP (x, 0);
1136 op[1] = XEXP (x, 1);
1137 break;
1138 case MOD:
1139 op[0] = XEXP (x, 0);
1140 st[1] = "%";
1141 op[1] = XEXP (x, 1);
1142 break;
1143 case UMOD:
1144 fun = "umod";
1145 op[0] = XEXP (x, 0);
1146 op[1] = XEXP (x, 1);
1147 break;
1148 case SMIN:
1149 fun = "smin";
1150 op[0] = XEXP (x, 0);
1151 op[1] = XEXP (x, 1);
1152 break;
1153 case SMAX:
1154 fun = "smax";
1155 op[0] = XEXP (x, 0);
1156 op[1] = XEXP (x, 1);
1157 break;
1158 case UMIN:
1159 fun = "umin";
1160 op[0] = XEXP (x, 0);
1161 op[1] = XEXP (x, 1);
1162 break;
1163 case UMAX:
1164 fun = "umax";
1165 op[0] = XEXP (x, 0);
1166 op[1] = XEXP (x, 1);
1167 break;
1168 case NOT:
1169 st[0] = "!";
1170 op[0] = XEXP (x, 0);
1171 break;
1172 case AND:
1173 op[0] = XEXP (x, 0);
1174 st[1] = "&";
1175 op[1] = XEXP (x, 1);
1176 break;
1177 case IOR:
1178 op[0] = XEXP (x, 0);
1179 st[1] = "|";
1180 op[1] = XEXP (x, 1);
1181 break;
1182 case XOR:
1183 op[0] = XEXP (x, 0);
1184 st[1] = "^";
1185 op[1] = XEXP (x, 1);
1186 break;
1187 case ASHIFT:
1188 op[0] = XEXP (x, 0);
1189 st[1] = "<<";
1190 op[1] = XEXP (x, 1);
1191 break;
1192 case LSHIFTRT:
1193 op[0] = XEXP (x, 0);
1194 st[1] = " 0>>";
1195 op[1] = XEXP (x, 1);
1196 break;
1197 case ASHIFTRT:
1198 op[0] = XEXP (x, 0);
1199 st[1] = ">>";
1200 op[1] = XEXP (x, 1);
1201 break;
1202 case ROTATE:
1203 op[0] = XEXP (x, 0);
1204 st[1] = "<-<";
1205 op[1] = XEXP (x, 1);
1206 break;
1207 case ROTATERT:
1208 op[0] = XEXP (x, 0);
1209 st[1] = ">->";
1210 op[1] = XEXP (x, 1);
1211 break;
1212 case NE:
1213 op[0] = XEXP (x, 0);
1214 st[1] = "!=";
1215 op[1] = XEXP (x, 1);
1216 break;
1217 case EQ:
1218 op[0] = XEXP (x, 0);
1219 st[1] = "==";
1220 op[1] = XEXP (x, 1);
1221 break;
1222 case GE:
1223 op[0] = XEXP (x, 0);
1224 st[1] = ">=";
1225 op[1] = XEXP (x, 1);
1226 break;
1227 case GT:
1228 op[0] = XEXP (x, 0);
1229 st[1] = ">";
1230 op[1] = XEXP (x, 1);
1231 break;
1232 case LE:
1233 op[0] = XEXP (x, 0);
1234 st[1] = "<=";
1235 op[1] = XEXP (x, 1);
1236 break;
1237 case LT:
1238 op[0] = XEXP (x, 0);
1239 st[1] = "<";
1240 op[1] = XEXP (x, 1);
1241 break;
1242 case SIGN_EXTRACT:
1243 fun = (verbose) ? "sign_extract" : "sxt";
1244 op[0] = XEXP (x, 0);
1245 op[1] = XEXP (x, 1);
1246 op[2] = XEXP (x, 2);
1247 break;
1248 case ZERO_EXTRACT:
1249 fun = (verbose) ? "zero_extract" : "zxt";
1250 op[0] = XEXP (x, 0);
1251 op[1] = XEXP (x, 1);
1252 op[2] = XEXP (x, 2);
1253 break;
1254 case SIGN_EXTEND:
1255 fun = (verbose) ? "sign_extend" : "sxn";
1256 op[0] = XEXP (x, 0);
1257 break;
1258 case ZERO_EXTEND:
1259 fun = (verbose) ? "zero_extend" : "zxn";
1260 op[0] = XEXP (x, 0);
1261 break;
1262 case FLOAT_EXTEND:
1263 fun = (verbose) ? "float_extend" : "fxn";
1264 op[0] = XEXP (x, 0);
1265 break;
1266 case TRUNCATE:
1267 fun = (verbose) ? "trunc" : "trn";
1268 op[0] = XEXP (x, 0);
1269 break;
1270 case FLOAT_TRUNCATE:
1271 fun = (verbose) ? "float_trunc" : "ftr";
1272 op[0] = XEXP (x, 0);
1273 break;
1274 case FLOAT:
1275 fun = (verbose) ? "float" : "flt";
1276 op[0] = XEXP (x, 0);
1277 break;
1278 case UNSIGNED_FLOAT:
1279 fun = (verbose) ? "uns_float" : "ufl";
1280 op[0] = XEXP (x, 0);
1281 break;
1282 case FIX:
1283 fun = "fix";
1284 op[0] = XEXP (x, 0);
1285 break;
1286 case UNSIGNED_FIX:
1287 fun = (verbose) ? "uns_fix" : "ufx";
1288 op[0] = XEXP (x, 0);
1289 break;
1290 case PRE_DEC:
1291 st[0] = "--";
1292 op[0] = XEXP (x, 0);
1293 break;
1294 case PRE_INC:
1295 st[0] = "++";
1296 op[0] = XEXP (x, 0);
1297 break;
1298 case POST_DEC:
1299 op[0] = XEXP (x, 0);
1300 st[1] = "--";
1301 break;
1302 case POST_INC:
1303 op[0] = XEXP (x, 0);
1304 st[1] = "++";
1305 break;
1306 case PRE_MODIFY:
1307 st[0] = "pre ";
1308 op[0] = XEXP (XEXP (x, 1), 0);
1309 st[1] = "+=";
1310 op[1] = XEXP (XEXP (x, 1), 1);
1311 break;
1312 case POST_MODIFY:
1313 st[0] = "post ";
1314 op[0] = XEXP (XEXP (x, 1), 0);
1315 st[1] = "+=";
1316 op[1] = XEXP (XEXP (x, 1), 1);
1317 break;
1318 case CALL:
1319 st[0] = "call ";
1320 op[0] = XEXP (x, 0);
1321 if (verbose)
1323 st[1] = " argc:";
1324 op[1] = XEXP (x, 1);
1326 break;
1327 case IF_THEN_ELSE:
1328 st[0] = "{(";
1329 op[0] = XEXP (x, 0);
1330 st[1] = ")?";
1331 op[1] = XEXP (x, 1);
1332 st[2] = ":";
1333 op[2] = XEXP (x, 2);
1334 st[3] = "}";
1335 break;
1336 case TRAP_IF:
1337 fun = "trap_if";
1338 op[0] = TRAP_CONDITION (x);
1339 break;
1340 case PREFETCH:
1341 fun = "prefetch";
1342 op[0] = XEXP (x, 0);
1343 op[1] = XEXP (x, 1);
1344 op[2] = XEXP (x, 2);
1345 break;
1346 case UNSPEC:
1347 case UNSPEC_VOLATILE:
1349 pp_string (pp, "unspec");
1350 if (GET_CODE (x) == UNSPEC_VOLATILE)
1351 pp_string (pp, "/v");
1352 pp_left_bracket (pp);
1353 for (i = 0; i < XVECLEN (x, 0); i++)
1355 if (i != 0)
1356 pp_comma (pp);
1357 print_pattern (pp, XVECEXP (x, 0, i), verbose);
1359 pp_string (pp, "] ");
1360 pp_decimal_int (pp, XINT (x, 1));
1362 break;
1363 default:
1365 /* Most unhandled codes can be printed as pseudo-functions. */
1366 if (GET_RTX_CLASS (GET_CODE (x)) == RTX_UNARY)
1368 fun = GET_RTX_NAME (GET_CODE (x));
1369 op[0] = XEXP (x, 0);
1371 else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_COMPARE
1372 || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_COMPARE
1373 || GET_RTX_CLASS (GET_CODE (x)) == RTX_BIN_ARITH
1374 || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_ARITH)
1376 fun = GET_RTX_NAME (GET_CODE (x));
1377 op[0] = XEXP (x, 0);
1378 op[1] = XEXP (x, 1);
1380 else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_TERNARY)
1382 fun = GET_RTX_NAME (GET_CODE (x));
1383 op[0] = XEXP (x, 0);
1384 op[1] = XEXP (x, 1);
1385 op[2] = XEXP (x, 2);
1387 else
1388 /* Give up, just print the RTX name. */
1389 st[0] = GET_RTX_NAME (GET_CODE (x));
1391 break;
1394 /* Print this as a function? */
1395 if (fun)
1397 pp_string (pp, fun);
1398 pp_left_paren (pp);
1401 for (i = 0; i < 4; i++)
1403 if (st[i])
1404 pp_string (pp, st[i]);
1406 if (op[i])
1408 if (fun && i != 0)
1409 pp_comma (pp);
1410 print_value (pp, op[i], verbose);
1414 if (fun)
1415 pp_right_paren (pp);
1416 } /* print_exp */
1418 /* Prints rtxes, I customarily classified as values. They're constants,
1419 registers, labels, symbols and memory accesses. */
1421 void
1422 print_value (pretty_printer *pp, const_rtx x, int verbose)
1424 char tmp[1024];
1426 if (!x)
1428 pp_string (pp, "(nil)");
1429 return;
1431 switch (GET_CODE (x))
1433 case CONST_INT:
1434 pp_scalar (pp, HOST_WIDE_INT_PRINT_HEX,
1435 (unsigned HOST_WIDE_INT) INTVAL (x));
1436 break;
1438 case CONST_WIDE_INT:
1440 const char *sep = "<";
1441 int i;
1442 for (i = CONST_WIDE_INT_NUNITS (x) - 1; i >= 0; i--)
1444 pp_string (pp, sep);
1445 sep = ",";
1446 sprintf (tmp, HOST_WIDE_INT_PRINT_HEX,
1447 (unsigned HOST_WIDE_INT) CONST_WIDE_INT_ELT (x, i));
1448 pp_string (pp, tmp);
1450 pp_greater (pp);
1452 break;
1454 case CONST_DOUBLE:
1455 if (FLOAT_MODE_P (GET_MODE (x)))
1457 real_to_decimal (tmp, CONST_DOUBLE_REAL_VALUE (x),
1458 sizeof (tmp), 0, 1);
1459 pp_string (pp, tmp);
1461 else
1462 pp_printf (pp, "<%wx,%wx>",
1463 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x),
1464 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x));
1465 break;
1466 case CONST_FIXED:
1467 fixed_to_decimal (tmp, CONST_FIXED_VALUE (x), sizeof (tmp));
1468 pp_string (pp, tmp);
1469 break;
1470 case CONST_STRING:
1471 pp_printf (pp, "\"%s\"", XSTR (x, 0));
1472 break;
1473 case SYMBOL_REF:
1474 pp_printf (pp, "`%s'", XSTR (x, 0));
1475 break;
1476 case LABEL_REF:
1477 pp_printf (pp, "L%d", INSN_UID (label_ref_label (x)));
1478 break;
1479 case CONST:
1480 case HIGH:
1481 case STRICT_LOW_PART:
1482 pp_printf (pp, "%s(", GET_RTX_NAME (GET_CODE (x)));
1483 print_value (pp, XEXP (x, 0), verbose);
1484 pp_right_paren (pp);
1485 break;
1486 case REG:
1487 if (REGNO (x) < FIRST_PSEUDO_REGISTER)
1489 if (ISDIGIT (reg_names[REGNO (x)][0]))
1490 pp_modulo (pp);
1491 pp_string (pp, reg_names[REGNO (x)]);
1493 else
1494 pp_printf (pp, "r%d", REGNO (x));
1495 if (verbose)
1496 pp_printf (pp, ":%s", GET_MODE_NAME (GET_MODE (x)));
1497 break;
1498 case SUBREG:
1499 print_value (pp, SUBREG_REG (x), verbose);
1500 pp_printf (pp, "#%d", SUBREG_BYTE (x));
1501 break;
1502 case SCRATCH:
1503 case CC0:
1504 case PC:
1505 pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
1506 break;
1507 case MEM:
1508 pp_left_bracket (pp);
1509 print_value (pp, XEXP (x, 0), verbose);
1510 pp_right_bracket (pp);
1511 break;
1512 case DEBUG_EXPR:
1513 pp_printf (pp, "D#%i", DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x)));
1514 break;
1515 default:
1516 print_exp (pp, x, verbose);
1517 break;
1519 } /* print_value */
1521 /* The next step in insn detalization, its pattern recognition. */
1523 void
1524 print_pattern (pretty_printer *pp, const_rtx x, int verbose)
1526 if (! x)
1528 pp_string (pp, "(nil)");
1529 return;
1532 switch (GET_CODE (x))
1534 case SET:
1535 print_value (pp, SET_DEST (x), verbose);
1536 pp_equal (pp);
1537 print_value (pp, SET_SRC (x), verbose);
1538 break;
1539 case RETURN:
1540 case SIMPLE_RETURN:
1541 case EH_RETURN:
1542 pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
1543 break;
1544 case CALL:
1545 print_exp (pp, x, verbose);
1546 break;
1547 case CLOBBER:
1548 case USE:
1549 pp_printf (pp, "%s ", GET_RTX_NAME (GET_CODE (x)));
1550 print_value (pp, XEXP (x, 0), verbose);
1551 break;
1552 case VAR_LOCATION:
1553 pp_string (pp, "loc ");
1554 print_value (pp, PAT_VAR_LOCATION_LOC (x), verbose);
1555 break;
1556 case COND_EXEC:
1557 pp_left_paren (pp);
1558 if (GET_CODE (COND_EXEC_TEST (x)) == NE
1559 && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
1560 print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
1561 else if (GET_CODE (COND_EXEC_TEST (x)) == EQ
1562 && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
1564 pp_exclamation (pp);
1565 print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
1567 else
1568 print_value (pp, COND_EXEC_TEST (x), verbose);
1569 pp_string (pp, ") ");
1570 print_pattern (pp, COND_EXEC_CODE (x), verbose);
1571 break;
1572 case PARALLEL:
1574 int i;
1576 pp_left_brace (pp);
1577 for (i = 0; i < XVECLEN (x, 0); i++)
1579 print_pattern (pp, XVECEXP (x, 0, i), verbose);
1580 pp_semicolon (pp);
1582 pp_right_brace (pp);
1584 break;
1585 case SEQUENCE:
1587 const rtx_sequence *seq = as_a <const rtx_sequence *> (x);
1588 pp_string (pp, "sequence{");
1589 if (INSN_P (seq->element (0)))
1591 /* Print the sequence insns indented. */
1592 const char * save_print_rtx_head = print_rtx_head;
1593 char indented_print_rtx_head[32];
1595 pp_newline (pp);
1596 gcc_assert (strlen (print_rtx_head) < sizeof (indented_print_rtx_head) - 4);
1597 snprintf (indented_print_rtx_head,
1598 sizeof (indented_print_rtx_head),
1599 "%s ", print_rtx_head);
1600 print_rtx_head = indented_print_rtx_head;
1601 for (int i = 0; i < seq->len (); i++)
1602 print_insn_with_notes (pp, seq->insn (i));
1603 pp_printf (pp, "%s ", save_print_rtx_head);
1604 print_rtx_head = save_print_rtx_head;
1606 else
1608 for (int i = 0; i < seq->len (); i++)
1610 print_pattern (pp, seq->element (i), verbose);
1611 pp_semicolon (pp);
1614 pp_right_brace (pp);
1616 break;
1617 case ASM_INPUT:
1618 pp_printf (pp, "asm {%s}", XSTR (x, 0));
1619 break;
1620 case ADDR_VEC:
1621 for (int i = 0; i < XVECLEN (x, 0); i++)
1623 print_value (pp, XVECEXP (x, 0, i), verbose);
1624 pp_semicolon (pp);
1626 break;
1627 case ADDR_DIFF_VEC:
1628 for (int i = 0; i < XVECLEN (x, 1); i++)
1630 print_value (pp, XVECEXP (x, 1, i), verbose);
1631 pp_semicolon (pp);
1633 break;
1634 case TRAP_IF:
1635 pp_string (pp, "trap_if ");
1636 print_value (pp, TRAP_CONDITION (x), verbose);
1637 break;
1638 case UNSPEC:
1639 case UNSPEC_VOLATILE:
1640 /* Fallthru -- leave UNSPECs to print_exp. */
1641 default:
1642 print_value (pp, x, verbose);
1644 } /* print_pattern */
1646 /* This is the main function in slim rtl visualization mechanism.
1648 X is an insn, to be printed into PP.
1650 This function tries to print it properly in human-readable form,
1651 resembling assembler mnemonics (instead of the older Lisp-style
1652 form).
1654 If VERBOSE is TRUE, insns are printed with more complete (but
1655 longer) pattern names and with extra information, and prefixed
1656 with their INSN_UIDs. */
1658 void
1659 print_insn (pretty_printer *pp, const rtx_insn *x, int verbose)
1661 if (verbose)
1663 /* Blech, pretty-print can't print integers with a specified width. */
1664 char uid_prefix[32];
1665 snprintf (uid_prefix, sizeof uid_prefix, " %4d: ", INSN_UID (x));
1666 pp_string (pp, uid_prefix);
1669 switch (GET_CODE (x))
1671 case INSN:
1672 print_pattern (pp, PATTERN (x), verbose);
1673 break;
1675 case DEBUG_INSN:
1677 const char *name = "?";
1679 if (DECL_P (INSN_VAR_LOCATION_DECL (x)))
1681 tree id = DECL_NAME (INSN_VAR_LOCATION_DECL (x));
1682 char idbuf[32];
1683 if (id)
1684 name = IDENTIFIER_POINTER (id);
1685 else if (TREE_CODE (INSN_VAR_LOCATION_DECL (x))
1686 == DEBUG_EXPR_DECL)
1688 sprintf (idbuf, "D#%i",
1689 DEBUG_TEMP_UID (INSN_VAR_LOCATION_DECL (x)));
1690 name = idbuf;
1692 else
1694 sprintf (idbuf, "D.%i",
1695 DECL_UID (INSN_VAR_LOCATION_DECL (x)));
1696 name = idbuf;
1699 pp_printf (pp, "debug %s => ", name);
1700 if (VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (x)))
1701 pp_string (pp, "optimized away");
1702 else
1703 print_pattern (pp, INSN_VAR_LOCATION_LOC (x), verbose);
1705 break;
1707 case JUMP_INSN:
1708 print_pattern (pp, PATTERN (x), verbose);
1709 break;
1710 case CALL_INSN:
1711 if (GET_CODE (PATTERN (x)) == PARALLEL)
1712 print_pattern (pp, XVECEXP (PATTERN (x), 0, 0), verbose);
1713 else
1714 print_pattern (pp, PATTERN (x), verbose);
1715 break;
1716 case CODE_LABEL:
1717 pp_printf (pp, "L%d:", INSN_UID (x));
1718 break;
1719 case JUMP_TABLE_DATA:
1720 pp_string (pp, "jump_table_data{\n");
1721 print_pattern (pp, PATTERN (x), verbose);
1722 pp_right_brace (pp);
1723 break;
1724 case BARRIER:
1725 pp_string (pp, "barrier");
1726 break;
1727 case NOTE:
1729 pp_string (pp, GET_NOTE_INSN_NAME (NOTE_KIND (x)));
1730 switch (NOTE_KIND (x))
1732 case NOTE_INSN_EH_REGION_BEG:
1733 case NOTE_INSN_EH_REGION_END:
1734 pp_printf (pp, " %d", NOTE_EH_HANDLER (x));
1735 break;
1737 case NOTE_INSN_BLOCK_BEG:
1738 case NOTE_INSN_BLOCK_END:
1739 pp_printf (pp, " %d", BLOCK_NUMBER (NOTE_BLOCK (x)));
1740 break;
1742 case NOTE_INSN_BASIC_BLOCK:
1743 pp_printf (pp, " %d", NOTE_BASIC_BLOCK (x)->index);
1744 break;
1746 case NOTE_INSN_DELETED_LABEL:
1747 case NOTE_INSN_DELETED_DEBUG_LABEL:
1749 const char *label = NOTE_DELETED_LABEL_NAME (x);
1750 if (label == NULL)
1751 label = "";
1752 pp_printf (pp, " (\"%s\")", label);
1754 break;
1756 case NOTE_INSN_VAR_LOCATION:
1757 case NOTE_INSN_CALL_ARG_LOCATION:
1758 pp_left_brace (pp);
1759 print_pattern (pp, NOTE_VAR_LOCATION (x), verbose);
1760 pp_right_brace (pp);
1761 break;
1763 default:
1764 break;
1766 break;
1768 default:
1769 gcc_unreachable ();
1771 } /* print_insn */
1773 /* Pretty-print a slim dump of X (an insn) to PP, including any register
1774 note attached to the instruction. */
1776 static void
1777 print_insn_with_notes (pretty_printer *pp, const rtx_insn *x)
1779 pp_string (pp, print_rtx_head);
1780 print_insn (pp, x, 1);
1781 pp_newline (pp);
1782 if (INSN_P (x) && REG_NOTES (x))
1783 for (rtx note = REG_NOTES (x); note; note = XEXP (note, 1))
1785 pp_printf (pp, "%s %s ", print_rtx_head,
1786 GET_REG_NOTE_NAME (REG_NOTE_KIND (note)));
1787 if (GET_CODE (note) == INT_LIST)
1788 pp_printf (pp, "%d", XINT (note, 0));
1789 else
1790 print_pattern (pp, XEXP (note, 0), 1);
1791 pp_newline (pp);
1795 /* Print X, an RTL value node, to file F in slim format. Include
1796 additional information if VERBOSE is nonzero.
1798 Value nodes are constants, registers, labels, symbols and
1799 memory. */
1801 void
1802 dump_value_slim (FILE *f, const_rtx x, int verbose)
1804 pretty_printer rtl_slim_pp;
1805 rtl_slim_pp.buffer->stream = f;
1806 print_value (&rtl_slim_pp, x, verbose);
1807 pp_flush (&rtl_slim_pp);
1810 /* Emit a slim dump of X (an insn) to the file F, including any register
1811 note attached to the instruction. */
1812 void
1813 dump_insn_slim (FILE *f, const rtx_insn *x)
1815 pretty_printer rtl_slim_pp;
1816 rtl_slim_pp.buffer->stream = f;
1817 print_insn_with_notes (&rtl_slim_pp, x);
1818 pp_flush (&rtl_slim_pp);
1821 /* Same as above, but stop at LAST or when COUNT == 0.
1822 If COUNT < 0 it will stop only at LAST or NULL rtx. */
1824 void
1825 dump_rtl_slim (FILE *f, const rtx_insn *first, const rtx_insn *last,
1826 int count, int flags ATTRIBUTE_UNUSED)
1828 const rtx_insn *insn, *tail;
1829 pretty_printer rtl_slim_pp;
1830 rtl_slim_pp.buffer->stream = f;
1832 tail = last ? NEXT_INSN (last) : NULL;
1833 for (insn = first;
1834 (insn != NULL) && (insn != tail) && (count != 0);
1835 insn = NEXT_INSN (insn))
1837 print_insn_with_notes (&rtl_slim_pp, insn);
1838 if (count > 0)
1839 count--;
1842 pp_flush (&rtl_slim_pp);
1845 /* Dumps basic block BB to pretty-printer PP in slim form and without and
1846 no indentation, for use as a label of a DOT graph record-node. */
1848 void
1849 rtl_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
1851 rtx_insn *insn;
1852 bool first = true;
1854 /* TODO: inter-bb stuff. */
1855 FOR_BB_INSNS (bb, insn)
1857 if (! first)
1859 pp_bar (pp);
1860 pp_write_text_to_stream (pp);
1862 first = false;
1863 print_insn_with_notes (pp, insn);
1864 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
1868 /* Pretty-print pattern X of some insn in non-verbose mode.
1869 Return a string pointer to the pretty-printer buffer.
1871 This function is only exported exists only to accommodate some older users
1872 of the slim RTL pretty printers. Please do not use it for new code. */
1874 const char *
1875 str_pattern_slim (const_rtx x)
1877 pretty_printer rtl_slim_pp;
1878 print_pattern (&rtl_slim_pp, x, 0);
1879 return ggc_strdup (pp_formatted_text (&rtl_slim_pp));
1882 /* Emit a slim dump of X (an insn) to stderr. */
1883 extern void debug_insn_slim (const rtx_insn *);
1884 DEBUG_FUNCTION void
1885 debug_insn_slim (const rtx_insn *x)
1887 dump_insn_slim (stderr, x);
1890 /* Same as above, but using dump_rtl_slim. */
1891 extern void debug_rtl_slim (FILE *, const rtx_insn *, const rtx_insn *,
1892 int, int);
1893 DEBUG_FUNCTION void
1894 debug_rtl_slim (const rtx_insn *first, const rtx_insn *last, int count,
1895 int flags)
1897 dump_rtl_slim (stderr, first, last, count, flags);
1900 extern void debug_bb_slim (basic_block);
1901 DEBUG_FUNCTION void
1902 debug_bb_slim (basic_block bb)
1904 dump_bb (stderr, bb, 0, TDF_SLIM | TDF_BLOCKS);
1907 extern void debug_bb_n_slim (int);
1908 DEBUG_FUNCTION void
1909 debug_bb_n_slim (int n)
1911 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, n);
1912 debug_bb_slim (bb);
1915 #endif