PR c++/81888
[official-gcc.git] / gcc / print-rtl.c
blob5fe23801ab2ddfdacdde56d4d83bc1923cbf5b88
1 /* Print RTL for GCC.
2 Copyright (C) 1987-2017 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 "basic-block.h"
39 #include "cfg.h"
40 #include "print-tree.h"
41 #include "flags.h"
42 #include "predict.h"
43 #include "function.h"
44 #include "basic-block.h"
45 #include "diagnostic.h"
46 #include "tree-pretty-print.h"
47 #include "alloc-pool.h"
48 #include "cselib.h"
49 #include "dumpfile.h" /* for dump_flags */
50 #include "dwarf2out.h"
51 #include "pretty-print.h"
52 #endif
54 #include "print-rtl.h"
55 #include "rtl-iter.h"
57 /* String printed at beginning of each RTL when it is dumped.
58 This string is set to ASM_COMMENT_START when the RTL is dumped in
59 the assembly output file. */
60 const char *print_rtx_head = "";
62 #ifdef GENERATOR_FILE
63 /* These are defined from the .opt file when not used in generator
64 programs. */
66 /* Nonzero means suppress output of instruction numbers
67 in debugging dumps.
68 This must be defined here so that programs like gencodes can be linked. */
69 int flag_dump_unnumbered = 0;
71 /* Nonzero means suppress output of instruction numbers for previous
72 and next insns in debugging dumps.
73 This must be defined here so that programs like gencodes can be linked. */
74 int flag_dump_unnumbered_links = 0;
75 #endif
77 /* Constructor for rtx_writer. */
79 rtx_writer::rtx_writer (FILE *outf, int ind, bool simple, bool compact,
80 rtx_reuse_manager *reuse_manager)
81 : m_outfile (outf), m_sawclose (0), m_indent (ind),
82 m_in_call_function_usage (false), m_simple (simple), m_compact (compact),
83 m_rtx_reuse_manager (reuse_manager)
87 #ifndef GENERATOR_FILE
89 /* rtx_reuse_manager's ctor. */
91 rtx_reuse_manager::rtx_reuse_manager ()
92 : m_next_id (0)
96 /* Determine if X is of a kind suitable for dumping via reuse_rtx. */
98 static bool
99 uses_rtx_reuse_p (const_rtx x)
101 if (x == NULL)
102 return false;
104 switch (GET_CODE (x))
106 case DEBUG_EXPR:
107 case VALUE:
108 case SCRATCH:
109 return true;
111 /* We don't use reuse_rtx for consts. */
112 CASE_CONST_UNIQUE:
113 default:
114 return false;
118 /* Traverse X and its descendents, determining if we see any rtx more than
119 once. Any rtx suitable for "reuse_rtx" that is seen more than once is
120 assigned an ID. */
122 void
123 rtx_reuse_manager::preprocess (const_rtx x)
125 subrtx_iterator::array_type array;
126 FOR_EACH_SUBRTX (iter, array, x, NONCONST)
127 if (uses_rtx_reuse_p (*iter))
129 if (int *count = m_rtx_occurrence_count.get (*iter))
131 if (*(count++) == 1)
132 m_rtx_reuse_ids.put (*iter, m_next_id++);
134 else
135 m_rtx_occurrence_count.put (*iter, 1);
139 /* Return true iff X has been assigned a reuse ID. If it has,
140 and OUT is non-NULL, then write the reuse ID to *OUT. */
142 bool
143 rtx_reuse_manager::has_reuse_id (const_rtx x, int *out)
145 int *id = m_rtx_reuse_ids.get (x);
146 if (id)
148 if (out)
149 *out = *id;
150 return true;
152 else
153 return false;
156 /* Determine if set_seen_def has been called for the given reuse ID. */
158 bool
159 rtx_reuse_manager::seen_def_p (int reuse_id)
161 return bitmap_bit_p (m_defs_seen, reuse_id);
164 /* Record that the definition of the given reuse ID has been seen. */
166 void
167 rtx_reuse_manager::set_seen_def (int reuse_id)
169 bitmap_set_bit (m_defs_seen, reuse_id);
172 #endif /* #ifndef GENERATOR_FILE */
174 #ifndef GENERATOR_FILE
175 void
176 print_mem_expr (FILE *outfile, const_tree expr)
178 fputc (' ', outfile);
179 print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
181 #endif
183 /* Subroutine of print_rtx_operand for handling code '0'.
184 0 indicates a field for internal use that should not be printed.
185 However there are various special cases, such as the third field
186 of a NOTE, where it indicates that the field has several different
187 valid contents. */
189 void
190 rtx_writer::print_rtx_operand_code_0 (const_rtx in_rtx ATTRIBUTE_UNUSED,
191 int idx ATTRIBUTE_UNUSED)
193 #ifndef GENERATOR_FILE
194 if (idx == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
196 int flags = SYMBOL_REF_FLAGS (in_rtx);
197 if (flags)
198 fprintf (m_outfile, " [flags %#x]", flags);
199 tree decl = SYMBOL_REF_DECL (in_rtx);
200 if (decl)
201 print_node_brief (m_outfile, "", decl, dump_flags);
203 else if (idx == 3 && NOTE_P (in_rtx))
205 switch (NOTE_KIND (in_rtx))
207 case NOTE_INSN_EH_REGION_BEG:
208 case NOTE_INSN_EH_REGION_END:
209 if (flag_dump_unnumbered)
210 fprintf (m_outfile, " #");
211 else
212 fprintf (m_outfile, " %d", NOTE_EH_HANDLER (in_rtx));
213 m_sawclose = 1;
214 break;
216 case NOTE_INSN_BLOCK_BEG:
217 case NOTE_INSN_BLOCK_END:
218 dump_addr (m_outfile, " ", NOTE_BLOCK (in_rtx));
219 m_sawclose = 1;
220 break;
222 case NOTE_INSN_BASIC_BLOCK:
224 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
225 if (bb != 0)
226 fprintf (m_outfile, " [bb %d]", bb->index);
227 break;
230 case NOTE_INSN_DELETED_LABEL:
231 case NOTE_INSN_DELETED_DEBUG_LABEL:
233 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
234 if (label)
235 fprintf (m_outfile, " (\"%s\")", label);
236 else
237 fprintf (m_outfile, " \"\"");
239 break;
241 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
243 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
244 if (bb != 0)
245 fprintf (m_outfile, " [bb %d]", bb->index);
246 break;
249 case NOTE_INSN_VAR_LOCATION:
250 case NOTE_INSN_CALL_ARG_LOCATION:
251 fputc (' ', m_outfile);
252 print_rtx (NOTE_VAR_LOCATION (in_rtx));
253 break;
255 case NOTE_INSN_CFI:
256 fputc ('\n', m_outfile);
257 output_cfi_directive (m_outfile, NOTE_CFI (in_rtx));
258 fputc ('\t', m_outfile);
259 break;
261 default:
262 break;
265 else if (idx == 7 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL
266 && !m_compact)
268 /* Output the JUMP_LABEL reference. */
269 fprintf (m_outfile, "\n%s%*s -> ", print_rtx_head, m_indent * 2, "");
270 if (GET_CODE (JUMP_LABEL (in_rtx)) == RETURN)
271 fprintf (m_outfile, "return");
272 else if (GET_CODE (JUMP_LABEL (in_rtx)) == SIMPLE_RETURN)
273 fprintf (m_outfile, "simple_return");
274 else
275 fprintf (m_outfile, "%d", INSN_UID (JUMP_LABEL (in_rtx)));
277 else if (idx == 0 && GET_CODE (in_rtx) == VALUE)
279 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
281 fprintf (m_outfile, " %u:%u", val->uid, val->hash);
282 dump_addr (m_outfile, " @", in_rtx);
283 dump_addr (m_outfile, "/", (void*)val);
285 else if (idx == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
287 fprintf (m_outfile, " D#%i",
288 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
290 else if (idx == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
292 m_indent += 2;
293 if (!m_sawclose)
294 fprintf (m_outfile, " ");
295 print_rtx (ENTRY_VALUE_EXP (in_rtx));
296 m_indent -= 2;
298 #endif
301 /* Subroutine of print_rtx_operand for handling code 'e'.
302 Also called by print_rtx_operand_code_u for handling code 'u'
303 for LABEL_REFs when they don't reference a CODE_LABEL. */
305 void
306 rtx_writer::print_rtx_operand_code_e (const_rtx in_rtx, int idx)
308 m_indent += 2;
309 if (idx == 6 && INSN_P (in_rtx))
310 /* Put REG_NOTES on their own line. */
311 fprintf (m_outfile, "\n%s%*s",
312 print_rtx_head, m_indent * 2, "");
313 if (!m_sawclose)
314 fprintf (m_outfile, " ");
315 if (idx == 7 && CALL_P (in_rtx))
317 m_in_call_function_usage = true;
318 print_rtx (XEXP (in_rtx, idx));
319 m_in_call_function_usage = false;
321 else
322 print_rtx (XEXP (in_rtx, idx));
323 m_indent -= 2;
326 /* Subroutine of print_rtx_operand for handling codes 'E' and 'V'. */
328 void
329 rtx_writer::print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx)
331 m_indent += 2;
332 if (m_sawclose)
334 fprintf (m_outfile, "\n%s%*s",
335 print_rtx_head, m_indent * 2, "");
336 m_sawclose = 0;
338 fputs (" [", m_outfile);
339 if (NULL != XVEC (in_rtx, idx))
341 m_indent += 2;
342 if (XVECLEN (in_rtx, idx))
343 m_sawclose = 1;
345 for (int j = 0; j < XVECLEN (in_rtx, idx); j++)
346 print_rtx (XVECEXP (in_rtx, idx, j));
348 m_indent -= 2;
350 if (m_sawclose)
351 fprintf (m_outfile, "\n%s%*s", print_rtx_head, m_indent * 2, "");
353 fputs ("]", m_outfile);
354 m_sawclose = 1;
355 m_indent -= 2;
358 /* Subroutine of print_rtx_operand for handling code 'i'. */
360 void
361 rtx_writer::print_rtx_operand_code_i (const_rtx in_rtx, int idx)
363 if (idx == 4 && INSN_P (in_rtx))
365 #ifndef GENERATOR_FILE
366 const rtx_insn *in_insn = as_a <const rtx_insn *> (in_rtx);
368 /* Pretty-print insn locations. Ignore scoping as it is mostly
369 redundant with line number information and do not print anything
370 when there is no location information available. */
371 if (INSN_HAS_LOCATION (in_insn))
373 expanded_location xloc = insn_location (in_insn);
374 fprintf (m_outfile, " \"%s\":%i", xloc.file, xloc.line);
376 #endif
378 else if (idx == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
380 #ifndef GENERATOR_FILE
381 if (ASM_OPERANDS_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
382 fprintf (m_outfile, " %s:%i",
383 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
384 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
385 #endif
387 else if (idx == 1 && GET_CODE (in_rtx) == ASM_INPUT)
389 #ifndef GENERATOR_FILE
390 if (ASM_INPUT_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
391 fprintf (m_outfile, " %s:%i",
392 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
393 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
394 #endif
396 else if (idx == 5 && NOTE_P (in_rtx))
398 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
399 other times often contains garbage from INSN->NOTE death. */
400 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL
401 || NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_DEBUG_LABEL)
402 fprintf (m_outfile, " %d", XINT (in_rtx, idx));
404 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
405 else if (idx == 1
406 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
407 && XINT (in_rtx, 1) >= 0
408 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
409 fprintf (m_outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
410 #endif
411 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
412 else if (idx == 1
413 && (GET_CODE (in_rtx) == UNSPEC
414 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
415 && XINT (in_rtx, 1) >= 0
416 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
417 fprintf (m_outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
418 #endif
419 else
421 int value = XINT (in_rtx, idx);
422 const char *name;
423 int is_insn = INSN_P (in_rtx);
425 /* Don't print INSN_CODEs in compact mode. */
426 if (m_compact && is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, idx))
428 m_sawclose = 0;
429 return;
432 if (flag_dump_unnumbered
433 && (is_insn || NOTE_P (in_rtx)))
434 fputc ('#', m_outfile);
435 else
436 fprintf (m_outfile, " %d", value);
438 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, idx)
439 && XINT (in_rtx, idx) >= 0
440 && (name = get_insn_name (XINT (in_rtx, idx))) != NULL)
441 fprintf (m_outfile, " {%s}", name);
442 m_sawclose = 0;
446 /* Subroutine of print_rtx_operand for handling code 'r'. */
448 void
449 rtx_writer::print_rtx_operand_code_r (const_rtx in_rtx)
451 int is_insn = INSN_P (in_rtx);
452 unsigned int regno = REGNO (in_rtx);
454 #ifndef GENERATOR_FILE
455 /* For hard registers and virtuals, always print the
456 regno, except in compact mode. */
457 if (regno <= LAST_VIRTUAL_REGISTER && !m_compact)
458 fprintf (m_outfile, " %d", regno);
459 if (regno < FIRST_PSEUDO_REGISTER)
460 fprintf (m_outfile, " %s", reg_names[regno]);
461 else if (regno <= LAST_VIRTUAL_REGISTER)
463 if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
464 fprintf (m_outfile, " virtual-incoming-args");
465 else if (regno == VIRTUAL_STACK_VARS_REGNUM)
466 fprintf (m_outfile, " virtual-stack-vars");
467 else if (regno == VIRTUAL_STACK_DYNAMIC_REGNUM)
468 fprintf (m_outfile, " virtual-stack-dynamic");
469 else if (regno == VIRTUAL_OUTGOING_ARGS_REGNUM)
470 fprintf (m_outfile, " virtual-outgoing-args");
471 else if (regno == VIRTUAL_CFA_REGNUM)
472 fprintf (m_outfile, " virtual-cfa");
473 else if (regno == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
474 fprintf (m_outfile, " virtual-preferred-stack-boundary");
475 else
476 fprintf (m_outfile, " virtual-reg-%d", regno-FIRST_VIRTUAL_REGISTER);
478 else
479 #endif
480 if (flag_dump_unnumbered && is_insn)
481 fputc ('#', m_outfile);
482 else if (m_compact)
484 /* In compact mode, print pseudos with '< and '>' wrapping the regno,
485 offseting it by (LAST_VIRTUAL_REGISTER + 1), so that the
486 first non-virtual pseudo is dumped as "<0>". */
487 gcc_assert (regno > LAST_VIRTUAL_REGISTER);
488 fprintf (m_outfile, " <%d>", regno - (LAST_VIRTUAL_REGISTER + 1));
490 else
491 fprintf (m_outfile, " %d", regno);
493 #ifndef GENERATOR_FILE
494 if (REG_ATTRS (in_rtx))
496 fputs (" [", m_outfile);
497 if (regno != ORIGINAL_REGNO (in_rtx))
498 fprintf (m_outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
499 if (REG_EXPR (in_rtx))
500 print_mem_expr (m_outfile, REG_EXPR (in_rtx));
502 if (REG_OFFSET (in_rtx))
503 fprintf (m_outfile, "+" HOST_WIDE_INT_PRINT_DEC,
504 REG_OFFSET (in_rtx));
505 fputs (" ]", m_outfile);
507 if (regno != ORIGINAL_REGNO (in_rtx))
508 fprintf (m_outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
509 #endif
512 /* Subroutine of print_rtx_operand for handling code 'u'. */
514 void
515 rtx_writer::print_rtx_operand_code_u (const_rtx in_rtx, int idx)
517 /* Don't print insn UIDs for PREV/NEXT_INSN in compact mode. */
518 if (m_compact && INSN_CHAIN_CODE_P (GET_CODE (in_rtx)) && idx < 2)
519 return;
521 if (XEXP (in_rtx, idx) != NULL)
523 rtx sub = XEXP (in_rtx, idx);
524 enum rtx_code subc = GET_CODE (sub);
526 if (GET_CODE (in_rtx) == LABEL_REF)
528 if (subc == NOTE
529 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
531 if (flag_dump_unnumbered)
532 fprintf (m_outfile, " [# deleted]");
533 else
534 fprintf (m_outfile, " [%d deleted]", INSN_UID (sub));
535 m_sawclose = 0;
536 return;
539 if (subc != CODE_LABEL)
541 print_rtx_operand_code_e (in_rtx, idx);
542 return;
546 if (flag_dump_unnumbered
547 || (flag_dump_unnumbered_links && idx <= 1
548 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
549 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
550 fputs (" #", m_outfile);
551 else
552 fprintf (m_outfile, " %d", INSN_UID (sub));
554 else
555 fputs (" 0", m_outfile);
556 m_sawclose = 0;
559 /* Subroutine of print_rtx. Print operand IDX of IN_RTX. */
561 void
562 rtx_writer::print_rtx_operand (const_rtx in_rtx, int idx)
564 const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
566 switch (format_ptr[idx])
568 const char *str;
570 case 'T':
571 str = XTMPL (in_rtx, idx);
572 goto string;
574 case 'S':
575 case 's':
576 str = XSTR (in_rtx, idx);
577 string:
579 if (str == 0)
580 fputs (" (nil)", m_outfile);
581 else
582 fprintf (m_outfile, " (\"%s\")", str);
583 m_sawclose = 1;
584 break;
586 case '0':
587 print_rtx_operand_code_0 (in_rtx, idx);
588 break;
590 case 'e':
591 print_rtx_operand_code_e (in_rtx, idx);
592 break;
594 case 'E':
595 case 'V':
596 print_rtx_operand_codes_E_and_V (in_rtx, idx);
597 break;
599 case 'w':
600 if (! m_simple)
601 fprintf (m_outfile, " ");
602 fprintf (m_outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, idx));
603 if (! m_simple && !m_compact)
604 fprintf (m_outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
605 (unsigned HOST_WIDE_INT) XWINT (in_rtx, idx));
606 break;
608 case 'i':
609 print_rtx_operand_code_i (in_rtx, idx);
610 break;
612 case 'r':
613 print_rtx_operand_code_r (in_rtx);
614 break;
616 /* Print NOTE_INSN names rather than integer codes. */
618 case 'n':
619 fprintf (m_outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, idx)));
620 m_sawclose = 0;
621 break;
623 case 'u':
624 print_rtx_operand_code_u (in_rtx, idx);
625 break;
627 case 't':
628 #ifndef GENERATOR_FILE
629 if (idx == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
630 print_mem_expr (m_outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
631 else if (idx == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
632 print_mem_expr (m_outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
633 else
634 dump_addr (m_outfile, " ", XTREE (in_rtx, idx));
635 #endif
636 break;
638 case '*':
639 fputs (" Unknown", m_outfile);
640 m_sawclose = 0;
641 break;
643 case 'B':
644 /* Don't print basic block ids in compact mode. */
645 if (m_compact)
646 break;
647 #ifndef GENERATOR_FILE
648 if (XBBDEF (in_rtx, idx))
649 fprintf (m_outfile, " %i", XBBDEF (in_rtx, idx)->index);
650 #endif
651 break;
653 default:
654 gcc_unreachable ();
658 /* Subroutine of rtx_writer::print_rtx.
659 In compact mode, determine if operand IDX of IN_RTX is interesting
660 to dump, or (if in a trailing position) it can be omitted. */
662 bool
663 rtx_writer::operand_has_default_value_p (const_rtx in_rtx, int idx)
665 const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
667 switch (format_ptr[idx])
669 case 'e':
670 case 'u':
671 return XEXP (in_rtx, idx) == NULL_RTX;
673 case 's':
674 return XSTR (in_rtx, idx) == NULL;
676 case '0':
677 switch (GET_CODE (in_rtx))
679 case JUMP_INSN:
680 /* JUMP_LABELs are always omitted in compact mode, so treat
681 any value here as omittable, so that earlier operands can
682 potentially be omitted also. */
683 return m_compact;
685 default:
686 return false;
690 default:
691 return false;
695 /* Print IN_RTX onto m_outfile. This is the recursive part of printing. */
697 void
698 rtx_writer::print_rtx (const_rtx in_rtx)
700 int idx = 0;
702 if (m_sawclose)
704 if (m_simple)
705 fputc (' ', m_outfile);
706 else
707 fprintf (m_outfile, "\n%s%*s", print_rtx_head, m_indent * 2, "");
708 m_sawclose = 0;
711 if (in_rtx == 0)
713 fputs ("(nil)", m_outfile);
714 m_sawclose = 1;
715 return;
717 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
719 fprintf (m_outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
720 print_rtx_head, m_indent * 2, "");
721 m_sawclose = 1;
722 return;
725 fputc ('(', m_outfile);
727 /* Print name of expression code. */
729 /* Handle reuse. */
730 #ifndef GENERATOR_FILE
731 if (m_rtx_reuse_manager)
733 int reuse_id;
734 if (m_rtx_reuse_manager->has_reuse_id (in_rtx, &reuse_id))
736 /* Have we already seen the defn of this rtx? */
737 if (m_rtx_reuse_manager->seen_def_p (reuse_id))
739 fprintf (m_outfile, "reuse_rtx %i)", reuse_id);
740 m_sawclose = 1;
741 return;
743 else
745 /* First time we've seen this reused-rtx. */
746 fprintf (m_outfile, "%i|", reuse_id);
747 m_rtx_reuse_manager->set_seen_def (reuse_id);
751 #endif /* #ifndef GENERATOR_FILE */
753 /* In compact mode, prefix the code of insns with "c",
754 giving "cinsn", "cnote" etc. */
755 if (m_compact && is_a <const rtx_insn *, const struct rtx_def> (in_rtx))
757 /* "ccode_label" is slightly awkward, so special-case it as
758 just "clabel". */
759 rtx_code code = GET_CODE (in_rtx);
760 if (code == CODE_LABEL)
761 fprintf (m_outfile, "clabel");
762 else
763 fprintf (m_outfile, "c%s", GET_RTX_NAME (code));
765 else if (m_simple && CONST_INT_P (in_rtx))
766 ; /* no code. */
767 else
768 fprintf (m_outfile, "%s", GET_RTX_NAME (GET_CODE (in_rtx)));
770 if (! m_simple)
772 if (RTX_FLAG (in_rtx, in_struct))
773 fputs ("/s", m_outfile);
775 if (RTX_FLAG (in_rtx, volatil))
776 fputs ("/v", m_outfile);
778 if (RTX_FLAG (in_rtx, unchanging))
779 fputs ("/u", m_outfile);
781 if (RTX_FLAG (in_rtx, frame_related))
782 fputs ("/f", m_outfile);
784 if (RTX_FLAG (in_rtx, jump))
785 fputs ("/j", m_outfile);
787 if (RTX_FLAG (in_rtx, call))
788 fputs ("/c", m_outfile);
790 if (RTX_FLAG (in_rtx, return_val))
791 fputs ("/i", m_outfile);
793 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
794 if ((GET_CODE (in_rtx) == EXPR_LIST
795 || GET_CODE (in_rtx) == INSN_LIST
796 || GET_CODE (in_rtx) == INT_LIST)
797 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX
798 && !m_in_call_function_usage)
799 fprintf (m_outfile, ":%s",
800 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
802 /* For other rtl, print the mode if it's not VOID. */
803 else if (GET_MODE (in_rtx) != VOIDmode)
804 fprintf (m_outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
806 #ifndef GENERATOR_FILE
807 if (GET_CODE (in_rtx) == VAR_LOCATION)
809 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
810 fputs (" <debug string placeholder>", m_outfile);
811 else
812 print_mem_expr (m_outfile, PAT_VAR_LOCATION_DECL (in_rtx));
813 fputc (' ', m_outfile);
814 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
815 if (PAT_VAR_LOCATION_STATUS (in_rtx)
816 == VAR_INIT_STATUS_UNINITIALIZED)
817 fprintf (m_outfile, " [uninit]");
818 m_sawclose = 1;
819 idx = GET_RTX_LENGTH (VAR_LOCATION);
821 #endif
824 #ifndef GENERATOR_FILE
825 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx))
826 idx = 5;
827 #endif
829 /* For insns, print the INSN_UID. */
830 if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx)))
832 if (flag_dump_unnumbered)
833 fprintf (m_outfile, " #");
834 else
835 fprintf (m_outfile, " %d", INSN_UID (in_rtx));
838 /* Determine which is the final operand to print.
839 In compact mode, skip trailing operands that have the default values
840 e.g. trailing "(nil)" values. */
841 int limit = GET_RTX_LENGTH (GET_CODE (in_rtx));
842 if (m_compact)
843 while (limit > idx && operand_has_default_value_p (in_rtx, limit - 1))
844 limit--;
846 /* Get the format string and skip the first elements if we have handled
847 them already. */
849 for (; idx < limit; idx++)
850 print_rtx_operand (in_rtx, idx);
852 switch (GET_CODE (in_rtx))
854 #ifndef GENERATOR_FILE
855 case MEM:
856 if (__builtin_expect (final_insns_dump_p, false))
857 fprintf (m_outfile, " [");
858 else
859 fprintf (m_outfile, " [" HOST_WIDE_INT_PRINT_DEC,
860 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
862 if (MEM_EXPR (in_rtx))
863 print_mem_expr (m_outfile, MEM_EXPR (in_rtx));
864 else
865 fputc (' ', m_outfile);
867 if (MEM_OFFSET_KNOWN_P (in_rtx))
868 fprintf (m_outfile, "+" HOST_WIDE_INT_PRINT_DEC, MEM_OFFSET (in_rtx));
870 if (MEM_SIZE_KNOWN_P (in_rtx))
871 fprintf (m_outfile, " S" HOST_WIDE_INT_PRINT_DEC, MEM_SIZE (in_rtx));
873 if (MEM_ALIGN (in_rtx) != 1)
874 fprintf (m_outfile, " A%u", MEM_ALIGN (in_rtx));
876 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
877 fprintf (m_outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
879 fputc (']', m_outfile);
880 break;
882 case CONST_DOUBLE:
883 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
885 char s[60];
887 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
888 sizeof (s), 0, 1);
889 fprintf (m_outfile, " %s", s);
891 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
892 sizeof (s), 0, 1);
893 fprintf (m_outfile, " [%s]", s);
895 break;
897 case CONST_WIDE_INT:
898 fprintf (m_outfile, " ");
899 cwi_output_hex (m_outfile, in_rtx);
900 break;
901 #endif
903 case CODE_LABEL:
904 if (!m_compact)
905 fprintf (m_outfile, " [%d uses]", LABEL_NUSES (in_rtx));
906 switch (LABEL_KIND (in_rtx))
908 case LABEL_NORMAL: break;
909 case LABEL_STATIC_ENTRY: fputs (" [entry]", m_outfile); break;
910 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", m_outfile); break;
911 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", m_outfile); break;
912 default: gcc_unreachable ();
914 break;
916 default:
917 break;
920 fputc (')', m_outfile);
921 m_sawclose = 1;
924 /* Emit a closing parenthesis and newline. */
926 void
927 rtx_writer::finish_directive ()
929 fprintf (m_outfile, ")\n");
930 m_sawclose = 0;
933 /* Print an rtx on the current line of FILE. Initially indent IND
934 characters. */
936 void
937 print_inline_rtx (FILE *outf, const_rtx x, int ind)
939 rtx_writer w (outf, ind, false, false, NULL);
940 w.print_rtx (x);
943 /* Call this function from the debugger to see what X looks like. */
945 DEBUG_FUNCTION void
946 debug_rtx (const_rtx x)
948 rtx_writer w (stderr, 0, false, false, NULL);
949 w.print_rtx (x);
950 fprintf (stderr, "\n");
953 /* Dump rtx REF. */
955 DEBUG_FUNCTION void
956 debug (const rtx_def &ref)
958 debug_rtx (&ref);
961 DEBUG_FUNCTION void
962 debug (const rtx_def *ptr)
964 if (ptr)
965 debug (*ptr);
966 else
967 fprintf (stderr, "<nil>\n");
970 /* Like debug_rtx but with no newline, as debug_helper will add one.
972 Note: No debug_slim(rtx_insn *) variant implemented, as this
973 function can serve for both rtx and rtx_insn. */
975 static void
976 debug_slim (const_rtx x)
978 rtx_writer w (stderr, 0, false, false, NULL);
979 w.print_rtx (x);
982 DEFINE_DEBUG_VEC (rtx_def *)
983 DEFINE_DEBUG_VEC (rtx_insn *)
984 DEFINE_DEBUG_HASH_SET (rtx_def *)
985 DEFINE_DEBUG_HASH_SET (rtx_insn *)
987 /* Count of rtx's to print with debug_rtx_list.
988 This global exists because gdb user defined commands have no arguments. */
990 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
992 /* Call this function to print list from X on.
994 N is a count of the rtx's to print. Positive values print from the specified
995 rtx_insn on. Negative values print a window around the rtx_insn.
996 EG: -5 prints 2 rtx_insn's on either side (in addition to the specified
997 rtx_insn). */
999 DEBUG_FUNCTION void
1000 debug_rtx_list (const rtx_insn *x, int n)
1002 int i,count;
1003 const rtx_insn *insn;
1005 count = n == 0 ? 1 : n < 0 ? -n : n;
1007 /* If we are printing a window, back up to the start. */
1009 if (n < 0)
1010 for (i = count / 2; i > 0; i--)
1012 if (PREV_INSN (x) == 0)
1013 break;
1014 x = PREV_INSN (x);
1017 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
1019 debug_rtx (insn);
1020 fprintf (stderr, "\n");
1024 /* Call this function to print an rtx_insn list from START to END
1025 inclusive. */
1027 DEBUG_FUNCTION void
1028 debug_rtx_range (const rtx_insn *start, const rtx_insn *end)
1030 while (1)
1032 debug_rtx (start);
1033 fprintf (stderr, "\n");
1034 if (!start || start == end)
1035 break;
1036 start = NEXT_INSN (start);
1040 /* Call this function to search an rtx_insn list to find one with insn uid UID,
1041 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
1042 The found insn is returned to enable further debugging analysis. */
1044 DEBUG_FUNCTION const rtx_insn *
1045 debug_rtx_find (const rtx_insn *x, int uid)
1047 while (x != 0 && INSN_UID (x) != uid)
1048 x = NEXT_INSN (x);
1049 if (x != 0)
1051 debug_rtx_list (x, debug_rtx_count);
1052 return x;
1054 else
1056 fprintf (stderr, "insn uid %d not found\n", uid);
1057 return 0;
1061 /* External entry point for printing a chain of insns
1062 starting with RTX_FIRST.
1063 A blank line separates insns.
1065 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
1067 void
1068 rtx_writer::print_rtl (const_rtx rtx_first)
1070 const rtx_insn *tmp_rtx;
1072 if (rtx_first == 0)
1074 fputs (print_rtx_head, m_outfile);
1075 fputs ("(nil)\n", m_outfile);
1077 else
1078 switch (GET_CODE (rtx_first))
1080 case INSN:
1081 case JUMP_INSN:
1082 case CALL_INSN:
1083 case NOTE:
1084 case CODE_LABEL:
1085 case JUMP_TABLE_DATA:
1086 case BARRIER:
1087 for (tmp_rtx = as_a <const rtx_insn *> (rtx_first);
1088 tmp_rtx != 0;
1089 tmp_rtx = NEXT_INSN (tmp_rtx))
1091 fputs (print_rtx_head, m_outfile);
1092 print_rtx (tmp_rtx);
1093 fprintf (m_outfile, "\n");
1095 break;
1097 default:
1098 fputs (print_rtx_head, m_outfile);
1099 print_rtx (rtx_first);
1103 /* External entry point for printing a chain of insns
1104 starting with RTX_FIRST onto file OUTF.
1105 A blank line separates insns.
1107 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
1109 void
1110 print_rtl (FILE *outf, const_rtx rtx_first)
1112 rtx_writer w (outf, 0, false, false, NULL);
1113 w.print_rtl (rtx_first);
1116 /* Like print_rtx, except specify a file. */
1117 /* Return nonzero if we actually printed anything. */
1120 print_rtl_single (FILE *outf, const_rtx x)
1122 rtx_writer w (outf, 0, false, false, NULL);
1123 return w.print_rtl_single_with_indent (x, 0);
1126 /* Like print_rtl_single, except specify an indentation. */
1129 rtx_writer::print_rtl_single_with_indent (const_rtx x, int ind)
1131 char *s_indent = (char *) alloca ((size_t) ind + 1);
1132 memset ((void *) s_indent, ' ', (size_t) ind);
1133 s_indent[ind] = '\0';
1134 fputs (s_indent, m_outfile);
1135 fputs (print_rtx_head, m_outfile);
1137 int old_indent = m_indent;
1138 m_indent = ind;
1139 m_sawclose = 0;
1140 print_rtx (x);
1141 putc ('\n', m_outfile);
1142 m_indent = old_indent;
1143 return 1;
1147 /* Like print_rtl except without all the detail; for example,
1148 if RTX is a CONST_INT then print in decimal format. */
1150 void
1151 print_simple_rtl (FILE *outf, const_rtx x)
1153 rtx_writer w (outf, 0, true, false, NULL);
1154 w.print_rtl (x);
1157 /* Print the elements of VEC to FILE. */
1159 void
1160 print_rtx_insn_vec (FILE *file, const vec<rtx_insn *> &vec)
1162 fputc('{', file);
1164 unsigned int len = vec.length ();
1165 for (unsigned int i = 0; i < len; i++)
1167 print_rtl (file, vec[i]);
1168 if (i < len - 1)
1169 fputs (", ", file);
1172 fputc ('}', file);
1175 #ifndef GENERATOR_FILE
1176 /* The functions below try to print RTL in a form resembling assembler
1177 mnemonics. Because this form is more concise than the "traditional" form
1178 of RTL printing in Lisp-style, the form printed by this file is called
1179 "slim". RTL dumps in slim format can be obtained by appending the "-slim"
1180 option to -fdump-rtl-<pass>. Control flow graph output as a DOT file is
1181 always printed in slim form.
1183 The normal interface to the functionality provided in this pretty-printer
1184 is through the dump_*_slim functions to print to a stream, or via the
1185 print_*_slim functions to print into a user's pretty-printer.
1187 It is also possible to obtain a string for a single pattern as a string
1188 pointer, via str_pattern_slim, but this usage is discouraged. */
1190 /* For insns we print patterns, and for some patterns we print insns... */
1191 static void print_insn_with_notes (pretty_printer *, const rtx_insn *);
1193 /* This recognizes rtx'en classified as expressions. These are always
1194 represent some action on values or results of other expression, that
1195 may be stored in objects representing values. */
1197 static void
1198 print_exp (pretty_printer *pp, const_rtx x, int verbose)
1200 const char *st[4];
1201 const char *fun;
1202 rtx op[4];
1203 int i;
1205 fun = (char *) 0;
1206 for (i = 0; i < 4; i++)
1208 st[i] = (char *) 0;
1209 op[i] = NULL_RTX;
1212 switch (GET_CODE (x))
1214 case PLUS:
1215 op[0] = XEXP (x, 0);
1216 if (CONST_INT_P (XEXP (x, 1))
1217 && INTVAL (XEXP (x, 1)) < 0)
1219 st[1] = "-";
1220 op[1] = GEN_INT (-INTVAL (XEXP (x, 1)));
1222 else
1224 st[1] = "+";
1225 op[1] = XEXP (x, 1);
1227 break;
1228 case LO_SUM:
1229 op[0] = XEXP (x, 0);
1230 st[1] = "+low(";
1231 op[1] = XEXP (x, 1);
1232 st[2] = ")";
1233 break;
1234 case MINUS:
1235 op[0] = XEXP (x, 0);
1236 st[1] = "-";
1237 op[1] = XEXP (x, 1);
1238 break;
1239 case COMPARE:
1240 fun = "cmp";
1241 op[0] = XEXP (x, 0);
1242 op[1] = XEXP (x, 1);
1243 break;
1244 case NEG:
1245 st[0] = "-";
1246 op[0] = XEXP (x, 0);
1247 break;
1248 case FMA:
1249 st[0] = "{";
1250 op[0] = XEXP (x, 0);
1251 st[1] = "*";
1252 op[1] = XEXP (x, 1);
1253 st[2] = "+";
1254 op[2] = XEXP (x, 2);
1255 st[3] = "}";
1256 break;
1257 case MULT:
1258 op[0] = XEXP (x, 0);
1259 st[1] = "*";
1260 op[1] = XEXP (x, 1);
1261 break;
1262 case DIV:
1263 op[0] = XEXP (x, 0);
1264 st[1] = "/";
1265 op[1] = XEXP (x, 1);
1266 break;
1267 case UDIV:
1268 fun = "udiv";
1269 op[0] = XEXP (x, 0);
1270 op[1] = XEXP (x, 1);
1271 break;
1272 case MOD:
1273 op[0] = XEXP (x, 0);
1274 st[1] = "%";
1275 op[1] = XEXP (x, 1);
1276 break;
1277 case UMOD:
1278 fun = "umod";
1279 op[0] = XEXP (x, 0);
1280 op[1] = XEXP (x, 1);
1281 break;
1282 case SMIN:
1283 fun = "smin";
1284 op[0] = XEXP (x, 0);
1285 op[1] = XEXP (x, 1);
1286 break;
1287 case SMAX:
1288 fun = "smax";
1289 op[0] = XEXP (x, 0);
1290 op[1] = XEXP (x, 1);
1291 break;
1292 case UMIN:
1293 fun = "umin";
1294 op[0] = XEXP (x, 0);
1295 op[1] = XEXP (x, 1);
1296 break;
1297 case UMAX:
1298 fun = "umax";
1299 op[0] = XEXP (x, 0);
1300 op[1] = XEXP (x, 1);
1301 break;
1302 case NOT:
1303 st[0] = "~";
1304 op[0] = XEXP (x, 0);
1305 break;
1306 case AND:
1307 op[0] = XEXP (x, 0);
1308 st[1] = "&";
1309 op[1] = XEXP (x, 1);
1310 break;
1311 case IOR:
1312 op[0] = XEXP (x, 0);
1313 st[1] = "|";
1314 op[1] = XEXP (x, 1);
1315 break;
1316 case XOR:
1317 op[0] = XEXP (x, 0);
1318 st[1] = "^";
1319 op[1] = XEXP (x, 1);
1320 break;
1321 case ASHIFT:
1322 op[0] = XEXP (x, 0);
1323 st[1] = "<<";
1324 op[1] = XEXP (x, 1);
1325 break;
1326 case LSHIFTRT:
1327 op[0] = XEXP (x, 0);
1328 st[1] = " 0>>";
1329 op[1] = XEXP (x, 1);
1330 break;
1331 case ASHIFTRT:
1332 op[0] = XEXP (x, 0);
1333 st[1] = ">>";
1334 op[1] = XEXP (x, 1);
1335 break;
1336 case ROTATE:
1337 op[0] = XEXP (x, 0);
1338 st[1] = "<-<";
1339 op[1] = XEXP (x, 1);
1340 break;
1341 case ROTATERT:
1342 op[0] = XEXP (x, 0);
1343 st[1] = ">->";
1344 op[1] = XEXP (x, 1);
1345 break;
1346 case NE:
1347 op[0] = XEXP (x, 0);
1348 st[1] = "!=";
1349 op[1] = XEXP (x, 1);
1350 break;
1351 case EQ:
1352 op[0] = XEXP (x, 0);
1353 st[1] = "==";
1354 op[1] = XEXP (x, 1);
1355 break;
1356 case GE:
1357 op[0] = XEXP (x, 0);
1358 st[1] = ">=";
1359 op[1] = XEXP (x, 1);
1360 break;
1361 case GT:
1362 op[0] = XEXP (x, 0);
1363 st[1] = ">";
1364 op[1] = XEXP (x, 1);
1365 break;
1366 case LE:
1367 op[0] = XEXP (x, 0);
1368 st[1] = "<=";
1369 op[1] = XEXP (x, 1);
1370 break;
1371 case LT:
1372 op[0] = XEXP (x, 0);
1373 st[1] = "<";
1374 op[1] = XEXP (x, 1);
1375 break;
1376 case SIGN_EXTRACT:
1377 fun = (verbose) ? "sign_extract" : "sxt";
1378 op[0] = XEXP (x, 0);
1379 op[1] = XEXP (x, 1);
1380 op[2] = XEXP (x, 2);
1381 break;
1382 case ZERO_EXTRACT:
1383 fun = (verbose) ? "zero_extract" : "zxt";
1384 op[0] = XEXP (x, 0);
1385 op[1] = XEXP (x, 1);
1386 op[2] = XEXP (x, 2);
1387 break;
1388 case SIGN_EXTEND:
1389 fun = (verbose) ? "sign_extend" : "sxn";
1390 op[0] = XEXP (x, 0);
1391 break;
1392 case ZERO_EXTEND:
1393 fun = (verbose) ? "zero_extend" : "zxn";
1394 op[0] = XEXP (x, 0);
1395 break;
1396 case FLOAT_EXTEND:
1397 fun = (verbose) ? "float_extend" : "fxn";
1398 op[0] = XEXP (x, 0);
1399 break;
1400 case TRUNCATE:
1401 fun = (verbose) ? "trunc" : "trn";
1402 op[0] = XEXP (x, 0);
1403 break;
1404 case FLOAT_TRUNCATE:
1405 fun = (verbose) ? "float_trunc" : "ftr";
1406 op[0] = XEXP (x, 0);
1407 break;
1408 case FLOAT:
1409 fun = (verbose) ? "float" : "flt";
1410 op[0] = XEXP (x, 0);
1411 break;
1412 case UNSIGNED_FLOAT:
1413 fun = (verbose) ? "uns_float" : "ufl";
1414 op[0] = XEXP (x, 0);
1415 break;
1416 case FIX:
1417 fun = "fix";
1418 op[0] = XEXP (x, 0);
1419 break;
1420 case UNSIGNED_FIX:
1421 fun = (verbose) ? "uns_fix" : "ufx";
1422 op[0] = XEXP (x, 0);
1423 break;
1424 case PRE_DEC:
1425 st[0] = "--";
1426 op[0] = XEXP (x, 0);
1427 break;
1428 case PRE_INC:
1429 st[0] = "++";
1430 op[0] = XEXP (x, 0);
1431 break;
1432 case POST_DEC:
1433 op[0] = XEXP (x, 0);
1434 st[1] = "--";
1435 break;
1436 case POST_INC:
1437 op[0] = XEXP (x, 0);
1438 st[1] = "++";
1439 break;
1440 case PRE_MODIFY:
1441 st[0] = "pre ";
1442 op[0] = XEXP (XEXP (x, 1), 0);
1443 st[1] = "+=";
1444 op[1] = XEXP (XEXP (x, 1), 1);
1445 break;
1446 case POST_MODIFY:
1447 st[0] = "post ";
1448 op[0] = XEXP (XEXP (x, 1), 0);
1449 st[1] = "+=";
1450 op[1] = XEXP (XEXP (x, 1), 1);
1451 break;
1452 case CALL:
1453 st[0] = "call ";
1454 op[0] = XEXP (x, 0);
1455 if (verbose)
1457 st[1] = " argc:";
1458 op[1] = XEXP (x, 1);
1460 break;
1461 case IF_THEN_ELSE:
1462 st[0] = "{(";
1463 op[0] = XEXP (x, 0);
1464 st[1] = ")?";
1465 op[1] = XEXP (x, 1);
1466 st[2] = ":";
1467 op[2] = XEXP (x, 2);
1468 st[3] = "}";
1469 break;
1470 case TRAP_IF:
1471 fun = "trap_if";
1472 op[0] = TRAP_CONDITION (x);
1473 break;
1474 case PREFETCH:
1475 fun = "prefetch";
1476 op[0] = XEXP (x, 0);
1477 op[1] = XEXP (x, 1);
1478 op[2] = XEXP (x, 2);
1479 break;
1480 case UNSPEC:
1481 case UNSPEC_VOLATILE:
1483 pp_string (pp, "unspec");
1484 if (GET_CODE (x) == UNSPEC_VOLATILE)
1485 pp_string (pp, "/v");
1486 pp_left_bracket (pp);
1487 for (i = 0; i < XVECLEN (x, 0); i++)
1489 if (i != 0)
1490 pp_comma (pp);
1491 print_pattern (pp, XVECEXP (x, 0, i), verbose);
1493 pp_string (pp, "] ");
1494 pp_decimal_int (pp, XINT (x, 1));
1496 break;
1497 default:
1499 /* Most unhandled codes can be printed as pseudo-functions. */
1500 if (GET_RTX_CLASS (GET_CODE (x)) == RTX_UNARY)
1502 fun = GET_RTX_NAME (GET_CODE (x));
1503 op[0] = XEXP (x, 0);
1505 else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_COMPARE
1506 || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_COMPARE
1507 || GET_RTX_CLASS (GET_CODE (x)) == RTX_BIN_ARITH
1508 || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_ARITH)
1510 fun = GET_RTX_NAME (GET_CODE (x));
1511 op[0] = XEXP (x, 0);
1512 op[1] = XEXP (x, 1);
1514 else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_TERNARY)
1516 fun = GET_RTX_NAME (GET_CODE (x));
1517 op[0] = XEXP (x, 0);
1518 op[1] = XEXP (x, 1);
1519 op[2] = XEXP (x, 2);
1521 else
1522 /* Give up, just print the RTX name. */
1523 st[0] = GET_RTX_NAME (GET_CODE (x));
1525 break;
1528 /* Print this as a function? */
1529 if (fun)
1531 pp_string (pp, fun);
1532 pp_left_paren (pp);
1535 for (i = 0; i < 4; i++)
1537 if (st[i])
1538 pp_string (pp, st[i]);
1540 if (op[i])
1542 if (fun && i != 0)
1543 pp_comma (pp);
1544 print_value (pp, op[i], verbose);
1548 if (fun)
1549 pp_right_paren (pp);
1550 } /* print_exp */
1552 /* Prints rtxes, I customarily classified as values. They're constants,
1553 registers, labels, symbols and memory accesses. */
1555 void
1556 print_value (pretty_printer *pp, const_rtx x, int verbose)
1558 char tmp[1024];
1560 if (!x)
1562 pp_string (pp, "(nil)");
1563 return;
1565 switch (GET_CODE (x))
1567 case CONST_INT:
1568 pp_scalar (pp, HOST_WIDE_INT_PRINT_HEX,
1569 (unsigned HOST_WIDE_INT) INTVAL (x));
1570 break;
1572 case CONST_WIDE_INT:
1574 const char *sep = "<";
1575 int i;
1576 for (i = CONST_WIDE_INT_NUNITS (x) - 1; i >= 0; i--)
1578 pp_string (pp, sep);
1579 sep = ",";
1580 sprintf (tmp, HOST_WIDE_INT_PRINT_HEX,
1581 (unsigned HOST_WIDE_INT) CONST_WIDE_INT_ELT (x, i));
1582 pp_string (pp, tmp);
1584 pp_greater (pp);
1586 break;
1588 case CONST_DOUBLE:
1589 if (FLOAT_MODE_P (GET_MODE (x)))
1591 real_to_decimal (tmp, CONST_DOUBLE_REAL_VALUE (x),
1592 sizeof (tmp), 0, 1);
1593 pp_string (pp, tmp);
1595 else
1596 pp_printf (pp, "<%wx,%wx>",
1597 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x),
1598 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x));
1599 break;
1600 case CONST_FIXED:
1601 fixed_to_decimal (tmp, CONST_FIXED_VALUE (x), sizeof (tmp));
1602 pp_string (pp, tmp);
1603 break;
1604 case CONST_STRING:
1605 pp_printf (pp, "\"%s\"", XSTR (x, 0));
1606 break;
1607 case SYMBOL_REF:
1608 pp_printf (pp, "`%s'", XSTR (x, 0));
1609 break;
1610 case LABEL_REF:
1611 pp_printf (pp, "L%d", INSN_UID (label_ref_label (x)));
1612 break;
1613 case CONST:
1614 case HIGH:
1615 case STRICT_LOW_PART:
1616 pp_printf (pp, "%s(", GET_RTX_NAME (GET_CODE (x)));
1617 print_value (pp, XEXP (x, 0), verbose);
1618 pp_right_paren (pp);
1619 break;
1620 case REG:
1621 if (REGNO (x) < FIRST_PSEUDO_REGISTER)
1623 if (ISDIGIT (reg_names[REGNO (x)][0]))
1624 pp_modulo (pp);
1625 pp_string (pp, reg_names[REGNO (x)]);
1627 else
1628 pp_printf (pp, "r%d", REGNO (x));
1629 if (verbose)
1630 pp_printf (pp, ":%s", GET_MODE_NAME (GET_MODE (x)));
1631 break;
1632 case SUBREG:
1633 print_value (pp, SUBREG_REG (x), verbose);
1634 pp_printf (pp, "#%d", SUBREG_BYTE (x));
1635 break;
1636 case SCRATCH:
1637 case CC0:
1638 case PC:
1639 pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
1640 break;
1641 case MEM:
1642 pp_left_bracket (pp);
1643 print_value (pp, XEXP (x, 0), verbose);
1644 pp_right_bracket (pp);
1645 break;
1646 case DEBUG_EXPR:
1647 pp_printf (pp, "D#%i", DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x)));
1648 break;
1649 default:
1650 print_exp (pp, x, verbose);
1651 break;
1653 } /* print_value */
1655 /* The next step in insn detalization, its pattern recognition. */
1657 void
1658 print_pattern (pretty_printer *pp, const_rtx x, int verbose)
1660 if (! x)
1662 pp_string (pp, "(nil)");
1663 return;
1666 switch (GET_CODE (x))
1668 case SET:
1669 print_value (pp, SET_DEST (x), verbose);
1670 pp_equal (pp);
1671 print_value (pp, SET_SRC (x), verbose);
1672 break;
1673 case RETURN:
1674 case SIMPLE_RETURN:
1675 case EH_RETURN:
1676 pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
1677 break;
1678 case CALL:
1679 print_exp (pp, x, verbose);
1680 break;
1681 case CLOBBER:
1682 case USE:
1683 pp_printf (pp, "%s ", GET_RTX_NAME (GET_CODE (x)));
1684 print_value (pp, XEXP (x, 0), verbose);
1685 break;
1686 case VAR_LOCATION:
1687 pp_string (pp, "loc ");
1688 print_value (pp, PAT_VAR_LOCATION_LOC (x), verbose);
1689 break;
1690 case COND_EXEC:
1691 pp_left_paren (pp);
1692 if (GET_CODE (COND_EXEC_TEST (x)) == NE
1693 && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
1694 print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
1695 else if (GET_CODE (COND_EXEC_TEST (x)) == EQ
1696 && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
1698 pp_exclamation (pp);
1699 print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
1701 else
1702 print_value (pp, COND_EXEC_TEST (x), verbose);
1703 pp_string (pp, ") ");
1704 print_pattern (pp, COND_EXEC_CODE (x), verbose);
1705 break;
1706 case PARALLEL:
1708 int i;
1710 pp_left_brace (pp);
1711 for (i = 0; i < XVECLEN (x, 0); i++)
1713 print_pattern (pp, XVECEXP (x, 0, i), verbose);
1714 pp_semicolon (pp);
1716 pp_right_brace (pp);
1718 break;
1719 case SEQUENCE:
1721 const rtx_sequence *seq = as_a <const rtx_sequence *> (x);
1722 pp_string (pp, "sequence{");
1723 if (INSN_P (seq->element (0)))
1725 /* Print the sequence insns indented. */
1726 const char * save_print_rtx_head = print_rtx_head;
1727 char indented_print_rtx_head[32];
1729 pp_newline (pp);
1730 gcc_assert (strlen (print_rtx_head) < sizeof (indented_print_rtx_head) - 4);
1731 snprintf (indented_print_rtx_head,
1732 sizeof (indented_print_rtx_head),
1733 "%s ", print_rtx_head);
1734 print_rtx_head = indented_print_rtx_head;
1735 for (int i = 0; i < seq->len (); i++)
1736 print_insn_with_notes (pp, seq->insn (i));
1737 pp_printf (pp, "%s ", save_print_rtx_head);
1738 print_rtx_head = save_print_rtx_head;
1740 else
1742 for (int i = 0; i < seq->len (); i++)
1744 print_pattern (pp, seq->element (i), verbose);
1745 pp_semicolon (pp);
1748 pp_right_brace (pp);
1750 break;
1751 case ASM_INPUT:
1752 pp_printf (pp, "asm {%s}", XSTR (x, 0));
1753 break;
1754 case ADDR_VEC:
1755 for (int i = 0; i < XVECLEN (x, 0); i++)
1757 print_value (pp, XVECEXP (x, 0, i), verbose);
1758 pp_semicolon (pp);
1760 break;
1761 case ADDR_DIFF_VEC:
1762 for (int i = 0; i < XVECLEN (x, 1); i++)
1764 print_value (pp, XVECEXP (x, 1, i), verbose);
1765 pp_semicolon (pp);
1767 break;
1768 case TRAP_IF:
1769 pp_string (pp, "trap_if ");
1770 print_value (pp, TRAP_CONDITION (x), verbose);
1771 break;
1772 case UNSPEC:
1773 case UNSPEC_VOLATILE:
1774 /* Fallthru -- leave UNSPECs to print_exp. */
1775 default:
1776 print_value (pp, x, verbose);
1778 } /* print_pattern */
1780 /* This is the main function in slim rtl visualization mechanism.
1782 X is an insn, to be printed into PP.
1784 This function tries to print it properly in human-readable form,
1785 resembling assembler mnemonics (instead of the older Lisp-style
1786 form).
1788 If VERBOSE is TRUE, insns are printed with more complete (but
1789 longer) pattern names and with extra information, and prefixed
1790 with their INSN_UIDs. */
1792 void
1793 print_insn (pretty_printer *pp, const rtx_insn *x, int verbose)
1795 if (verbose)
1797 /* Blech, pretty-print can't print integers with a specified width. */
1798 char uid_prefix[32];
1799 snprintf (uid_prefix, sizeof uid_prefix, " %4d: ", INSN_UID (x));
1800 pp_string (pp, uid_prefix);
1803 switch (GET_CODE (x))
1805 case INSN:
1806 print_pattern (pp, PATTERN (x), verbose);
1807 break;
1809 case DEBUG_INSN:
1811 const char *name = "?";
1812 char idbuf[32];
1814 if (DECL_P (INSN_VAR_LOCATION_DECL (x)))
1816 tree id = DECL_NAME (INSN_VAR_LOCATION_DECL (x));
1817 if (id)
1818 name = IDENTIFIER_POINTER (id);
1819 else if (TREE_CODE (INSN_VAR_LOCATION_DECL (x))
1820 == DEBUG_EXPR_DECL)
1822 sprintf (idbuf, "D#%i",
1823 DEBUG_TEMP_UID (INSN_VAR_LOCATION_DECL (x)));
1824 name = idbuf;
1826 else
1828 sprintf (idbuf, "D.%i",
1829 DECL_UID (INSN_VAR_LOCATION_DECL (x)));
1830 name = idbuf;
1833 pp_printf (pp, "debug %s => ", name);
1834 if (VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (x)))
1835 pp_string (pp, "optimized away");
1836 else
1837 print_pattern (pp, INSN_VAR_LOCATION_LOC (x), verbose);
1839 break;
1841 case JUMP_INSN:
1842 print_pattern (pp, PATTERN (x), verbose);
1843 break;
1844 case CALL_INSN:
1845 if (GET_CODE (PATTERN (x)) == PARALLEL)
1846 print_pattern (pp, XVECEXP (PATTERN (x), 0, 0), verbose);
1847 else
1848 print_pattern (pp, PATTERN (x), verbose);
1849 break;
1850 case CODE_LABEL:
1851 pp_printf (pp, "L%d:", INSN_UID (x));
1852 break;
1853 case JUMP_TABLE_DATA:
1854 pp_string (pp, "jump_table_data{\n");
1855 print_pattern (pp, PATTERN (x), verbose);
1856 pp_right_brace (pp);
1857 break;
1858 case BARRIER:
1859 pp_string (pp, "barrier");
1860 break;
1861 case NOTE:
1863 pp_string (pp, GET_NOTE_INSN_NAME (NOTE_KIND (x)));
1864 switch (NOTE_KIND (x))
1866 case NOTE_INSN_EH_REGION_BEG:
1867 case NOTE_INSN_EH_REGION_END:
1868 pp_printf (pp, " %d", NOTE_EH_HANDLER (x));
1869 break;
1871 case NOTE_INSN_BLOCK_BEG:
1872 case NOTE_INSN_BLOCK_END:
1873 pp_printf (pp, " %d", BLOCK_NUMBER (NOTE_BLOCK (x)));
1874 break;
1876 case NOTE_INSN_BASIC_BLOCK:
1877 pp_printf (pp, " %d", NOTE_BASIC_BLOCK (x)->index);
1878 break;
1880 case NOTE_INSN_DELETED_LABEL:
1881 case NOTE_INSN_DELETED_DEBUG_LABEL:
1883 const char *label = NOTE_DELETED_LABEL_NAME (x);
1884 if (label == NULL)
1885 label = "";
1886 pp_printf (pp, " (\"%s\")", label);
1888 break;
1890 case NOTE_INSN_VAR_LOCATION:
1891 case NOTE_INSN_CALL_ARG_LOCATION:
1892 pp_left_brace (pp);
1893 print_pattern (pp, NOTE_VAR_LOCATION (x), verbose);
1894 pp_right_brace (pp);
1895 break;
1897 default:
1898 break;
1900 break;
1902 default:
1903 gcc_unreachable ();
1905 } /* print_insn */
1907 /* Pretty-print a slim dump of X (an insn) to PP, including any register
1908 note attached to the instruction. */
1910 static void
1911 print_insn_with_notes (pretty_printer *pp, const rtx_insn *x)
1913 pp_string (pp, print_rtx_head);
1914 print_insn (pp, x, 1);
1915 pp_newline (pp);
1916 if (INSN_P (x) && REG_NOTES (x))
1917 for (rtx note = REG_NOTES (x); note; note = XEXP (note, 1))
1919 pp_printf (pp, "%s %s ", print_rtx_head,
1920 GET_REG_NOTE_NAME (REG_NOTE_KIND (note)));
1921 if (GET_CODE (note) == INT_LIST)
1922 pp_printf (pp, "%d", XINT (note, 0));
1923 else
1924 print_pattern (pp, XEXP (note, 0), 1);
1925 pp_newline (pp);
1929 /* Print X, an RTL value node, to file F in slim format. Include
1930 additional information if VERBOSE is nonzero.
1932 Value nodes are constants, registers, labels, symbols and
1933 memory. */
1935 void
1936 dump_value_slim (FILE *f, const_rtx x, int verbose)
1938 pretty_printer rtl_slim_pp;
1939 rtl_slim_pp.buffer->stream = f;
1940 print_value (&rtl_slim_pp, x, verbose);
1941 pp_flush (&rtl_slim_pp);
1944 /* Emit a slim dump of X (an insn) to the file F, including any register
1945 note attached to the instruction. */
1946 void
1947 dump_insn_slim (FILE *f, const rtx_insn *x)
1949 pretty_printer rtl_slim_pp;
1950 rtl_slim_pp.buffer->stream = f;
1951 print_insn_with_notes (&rtl_slim_pp, x);
1952 pp_flush (&rtl_slim_pp);
1955 /* Same as above, but stop at LAST or when COUNT == 0.
1956 If COUNT < 0 it will stop only at LAST or NULL rtx. */
1958 void
1959 dump_rtl_slim (FILE *f, const rtx_insn *first, const rtx_insn *last,
1960 int count, int flags ATTRIBUTE_UNUSED)
1962 const rtx_insn *insn, *tail;
1963 pretty_printer rtl_slim_pp;
1964 rtl_slim_pp.buffer->stream = f;
1966 tail = last ? NEXT_INSN (last) : NULL;
1967 for (insn = first;
1968 (insn != NULL) && (insn != tail) && (count != 0);
1969 insn = NEXT_INSN (insn))
1971 print_insn_with_notes (&rtl_slim_pp, insn);
1972 if (count > 0)
1973 count--;
1976 pp_flush (&rtl_slim_pp);
1979 /* Dumps basic block BB to pretty-printer PP in slim form and without and
1980 no indentation, for use as a label of a DOT graph record-node. */
1982 void
1983 rtl_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
1985 rtx_insn *insn;
1986 bool first = true;
1988 /* TODO: inter-bb stuff. */
1989 FOR_BB_INSNS (bb, insn)
1991 if (! first)
1993 pp_bar (pp);
1994 pp_write_text_to_stream (pp);
1996 first = false;
1997 print_insn_with_notes (pp, insn);
1998 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2002 /* Pretty-print pattern X of some insn in non-verbose mode.
2003 Return a string pointer to the pretty-printer buffer.
2005 This function is only exported exists only to accommodate some older users
2006 of the slim RTL pretty printers. Please do not use it for new code. */
2008 const char *
2009 str_pattern_slim (const_rtx x)
2011 pretty_printer rtl_slim_pp;
2012 print_pattern (&rtl_slim_pp, x, 0);
2013 return ggc_strdup (pp_formatted_text (&rtl_slim_pp));
2016 /* Emit a slim dump of X (an insn) to stderr. */
2017 extern void debug_insn_slim (const rtx_insn *);
2018 DEBUG_FUNCTION void
2019 debug_insn_slim (const rtx_insn *x)
2021 dump_insn_slim (stderr, x);
2024 /* Same as above, but using dump_rtl_slim. */
2025 extern void debug_rtl_slim (FILE *, const rtx_insn *, const rtx_insn *,
2026 int, int);
2027 DEBUG_FUNCTION void
2028 debug_rtl_slim (const rtx_insn *first, const rtx_insn *last, int count,
2029 int flags)
2031 dump_rtl_slim (stderr, first, last, count, flags);
2034 extern void debug_bb_slim (basic_block);
2035 DEBUG_FUNCTION void
2036 debug_bb_slim (basic_block bb)
2038 dump_bb (stderr, bb, 0, TDF_SLIM | TDF_BLOCKS);
2041 extern void debug_bb_n_slim (int);
2042 DEBUG_FUNCTION void
2043 debug_bb_n_slim (int n)
2045 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, n);
2046 debug_bb_slim (bb);
2049 #endif