poly_int: MEM_OFFSET and MEM_SIZE
[official-gcc.git] / gcc / print-rtl.c
blob1cf2604a8672d2bd0d752041a63b4a8f1a1d8dc8
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);
182 /* Print X to FILE. */
184 static void
185 print_poly_int (FILE *file, poly_int64 x)
187 HOST_WIDE_INT const_x;
188 if (x.is_constant (&const_x))
189 fprintf (file, HOST_WIDE_INT_PRINT_DEC, const_x);
190 else
192 fprintf (file, "[" HOST_WIDE_INT_PRINT_DEC, x.coeffs[0]);
193 for (int i = 1; i < NUM_POLY_INT_COEFFS; ++i)
194 fprintf (file, ", " HOST_WIDE_INT_PRINT_DEC, x.coeffs[i]);
195 fprintf (file, "]");
198 #endif
200 /* Subroutine of print_rtx_operand for handling code '0'.
201 0 indicates a field for internal use that should not be printed.
202 However there are various special cases, such as the third field
203 of a NOTE, where it indicates that the field has several different
204 valid contents. */
206 void
207 rtx_writer::print_rtx_operand_code_0 (const_rtx in_rtx ATTRIBUTE_UNUSED,
208 int idx ATTRIBUTE_UNUSED)
210 #ifndef GENERATOR_FILE
211 if (idx == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
213 int flags = SYMBOL_REF_FLAGS (in_rtx);
214 if (flags)
215 fprintf (m_outfile, " [flags %#x]", flags);
216 tree decl = SYMBOL_REF_DECL (in_rtx);
217 if (decl)
218 print_node_brief (m_outfile, "", decl, dump_flags);
220 else if (idx == 3 && NOTE_P (in_rtx))
222 switch (NOTE_KIND (in_rtx))
224 case NOTE_INSN_EH_REGION_BEG:
225 case NOTE_INSN_EH_REGION_END:
226 if (flag_dump_unnumbered)
227 fprintf (m_outfile, " #");
228 else
229 fprintf (m_outfile, " %d", NOTE_EH_HANDLER (in_rtx));
230 m_sawclose = 1;
231 break;
233 case NOTE_INSN_BLOCK_BEG:
234 case NOTE_INSN_BLOCK_END:
235 dump_addr (m_outfile, " ", NOTE_BLOCK (in_rtx));
236 m_sawclose = 1;
237 break;
239 case NOTE_INSN_BASIC_BLOCK:
241 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
242 if (bb != 0)
243 fprintf (m_outfile, " [bb %d]", bb->index);
244 break;
247 case NOTE_INSN_DELETED_LABEL:
248 case NOTE_INSN_DELETED_DEBUG_LABEL:
250 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
251 if (label)
252 fprintf (m_outfile, " (\"%s\")", label);
253 else
254 fprintf (m_outfile, " \"\"");
256 break;
258 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
260 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
261 if (bb != 0)
262 fprintf (m_outfile, " [bb %d]", bb->index);
263 break;
266 case NOTE_INSN_VAR_LOCATION:
267 case NOTE_INSN_CALL_ARG_LOCATION:
268 fputc (' ', m_outfile);
269 print_rtx (NOTE_VAR_LOCATION (in_rtx));
270 break;
272 case NOTE_INSN_CFI:
273 fputc ('\n', m_outfile);
274 output_cfi_directive (m_outfile, NOTE_CFI (in_rtx));
275 fputc ('\t', m_outfile);
276 break;
278 case NOTE_INSN_BEGIN_STMT:
279 #ifndef GENERATOR_FILE
281 expanded_location xloc
282 = expand_location (NOTE_MARKER_LOCATION (in_rtx));
283 fprintf (m_outfile, " %s:%i", xloc.file, xloc.line);
285 #endif
286 break;
288 default:
289 break;
292 else if (idx == 7 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL
293 && !m_compact)
295 /* Output the JUMP_LABEL reference. */
296 fprintf (m_outfile, "\n%s%*s -> ", print_rtx_head, m_indent * 2, "");
297 if (GET_CODE (JUMP_LABEL (in_rtx)) == RETURN)
298 fprintf (m_outfile, "return");
299 else if (GET_CODE (JUMP_LABEL (in_rtx)) == SIMPLE_RETURN)
300 fprintf (m_outfile, "simple_return");
301 else
302 fprintf (m_outfile, "%d", INSN_UID (JUMP_LABEL (in_rtx)));
304 else if (idx == 0 && GET_CODE (in_rtx) == VALUE)
306 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
308 fprintf (m_outfile, " %u:%u", val->uid, val->hash);
309 dump_addr (m_outfile, " @", in_rtx);
310 dump_addr (m_outfile, "/", (void*)val);
312 else if (idx == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
314 fprintf (m_outfile, " D#%i",
315 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
317 else if (idx == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
319 m_indent += 2;
320 if (!m_sawclose)
321 fprintf (m_outfile, " ");
322 print_rtx (ENTRY_VALUE_EXP (in_rtx));
323 m_indent -= 2;
325 #endif
328 /* Subroutine of print_rtx_operand for handling code 'e'.
329 Also called by print_rtx_operand_code_u for handling code 'u'
330 for LABEL_REFs when they don't reference a CODE_LABEL. */
332 void
333 rtx_writer::print_rtx_operand_code_e (const_rtx in_rtx, int idx)
335 m_indent += 2;
336 if (idx == 6 && INSN_P (in_rtx))
337 /* Put REG_NOTES on their own line. */
338 fprintf (m_outfile, "\n%s%*s",
339 print_rtx_head, m_indent * 2, "");
340 if (!m_sawclose)
341 fprintf (m_outfile, " ");
342 if (idx == 7 && CALL_P (in_rtx))
344 m_in_call_function_usage = true;
345 print_rtx (XEXP (in_rtx, idx));
346 m_in_call_function_usage = false;
348 else
349 print_rtx (XEXP (in_rtx, idx));
350 m_indent -= 2;
353 /* Subroutine of print_rtx_operand for handling codes 'E' and 'V'. */
355 void
356 rtx_writer::print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx)
358 m_indent += 2;
359 if (m_sawclose)
361 fprintf (m_outfile, "\n%s%*s",
362 print_rtx_head, m_indent * 2, "");
363 m_sawclose = 0;
365 fputs (" [", m_outfile);
366 if (XVEC (in_rtx, idx) != NULL)
368 m_indent += 2;
369 if (XVECLEN (in_rtx, idx))
370 m_sawclose = 1;
372 for (int j = 0; j < XVECLEN (in_rtx, idx); j++)
373 print_rtx (XVECEXP (in_rtx, idx, j));
375 m_indent -= 2;
377 if (m_sawclose)
378 fprintf (m_outfile, "\n%s%*s", print_rtx_head, m_indent * 2, "");
380 fputs ("]", m_outfile);
381 m_sawclose = 1;
382 m_indent -= 2;
385 /* Subroutine of print_rtx_operand for handling code 'i'. */
387 void
388 rtx_writer::print_rtx_operand_code_i (const_rtx in_rtx, int idx)
390 if (idx == 4 && INSN_P (in_rtx))
392 #ifndef GENERATOR_FILE
393 const rtx_insn *in_insn = as_a <const rtx_insn *> (in_rtx);
395 /* Pretty-print insn locations. Ignore scoping as it is mostly
396 redundant with line number information and do not print anything
397 when there is no location information available. */
398 if (INSN_HAS_LOCATION (in_insn))
400 expanded_location xloc = insn_location (in_insn);
401 fprintf (m_outfile, " \"%s\":%i", xloc.file, xloc.line);
403 #endif
405 else if (idx == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
407 #ifndef GENERATOR_FILE
408 if (ASM_OPERANDS_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
409 fprintf (m_outfile, " %s:%i",
410 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
411 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
412 #endif
414 else if (idx == 1 && GET_CODE (in_rtx) == ASM_INPUT)
416 #ifndef GENERATOR_FILE
417 if (ASM_INPUT_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
418 fprintf (m_outfile, " %s:%i",
419 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
420 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
421 #endif
423 else if (idx == 5 && NOTE_P (in_rtx))
425 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
426 other times often contains garbage from INSN->NOTE death. */
427 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL
428 || NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_DEBUG_LABEL)
429 fprintf (m_outfile, " %d", XINT (in_rtx, idx));
431 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
432 else if (idx == 1
433 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
434 && XINT (in_rtx, 1) >= 0
435 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
436 fprintf (m_outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
437 #endif
438 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
439 else if (idx == 1
440 && (GET_CODE (in_rtx) == UNSPEC
441 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
442 && XINT (in_rtx, 1) >= 0
443 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
444 fprintf (m_outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
445 #endif
446 else
448 int value = XINT (in_rtx, idx);
449 const char *name;
450 int is_insn = INSN_P (in_rtx);
452 /* Don't print INSN_CODEs in compact mode. */
453 if (m_compact && is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, idx))
455 m_sawclose = 0;
456 return;
459 if (flag_dump_unnumbered
460 && (is_insn || NOTE_P (in_rtx)))
461 fputc ('#', m_outfile);
462 else
463 fprintf (m_outfile, " %d", value);
465 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, idx)
466 && XINT (in_rtx, idx) >= 0
467 && (name = get_insn_name (XINT (in_rtx, idx))) != NULL)
468 fprintf (m_outfile, " {%s}", name);
469 m_sawclose = 0;
473 /* Subroutine of print_rtx_operand for handling code 'r'. */
475 void
476 rtx_writer::print_rtx_operand_code_r (const_rtx in_rtx)
478 int is_insn = INSN_P (in_rtx);
479 unsigned int regno = REGNO (in_rtx);
481 #ifndef GENERATOR_FILE
482 /* For hard registers and virtuals, always print the
483 regno, except in compact mode. */
484 if (regno <= LAST_VIRTUAL_REGISTER && !m_compact)
485 fprintf (m_outfile, " %d", regno);
486 if (regno < FIRST_PSEUDO_REGISTER)
487 fprintf (m_outfile, " %s", reg_names[regno]);
488 else if (regno <= LAST_VIRTUAL_REGISTER)
490 if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
491 fprintf (m_outfile, " virtual-incoming-args");
492 else if (regno == VIRTUAL_STACK_VARS_REGNUM)
493 fprintf (m_outfile, " virtual-stack-vars");
494 else if (regno == VIRTUAL_STACK_DYNAMIC_REGNUM)
495 fprintf (m_outfile, " virtual-stack-dynamic");
496 else if (regno == VIRTUAL_OUTGOING_ARGS_REGNUM)
497 fprintf (m_outfile, " virtual-outgoing-args");
498 else if (regno == VIRTUAL_CFA_REGNUM)
499 fprintf (m_outfile, " virtual-cfa");
500 else if (regno == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
501 fprintf (m_outfile, " virtual-preferred-stack-boundary");
502 else
503 fprintf (m_outfile, " virtual-reg-%d", regno-FIRST_VIRTUAL_REGISTER);
505 else
506 #endif
507 if (flag_dump_unnumbered && is_insn)
508 fputc ('#', m_outfile);
509 else if (m_compact)
511 /* In compact mode, print pseudos with '< and '>' wrapping the regno,
512 offseting it by (LAST_VIRTUAL_REGISTER + 1), so that the
513 first non-virtual pseudo is dumped as "<0>". */
514 gcc_assert (regno > LAST_VIRTUAL_REGISTER);
515 fprintf (m_outfile, " <%d>", regno - (LAST_VIRTUAL_REGISTER + 1));
517 else
518 fprintf (m_outfile, " %d", regno);
520 #ifndef GENERATOR_FILE
521 if (REG_ATTRS (in_rtx))
523 fputs (" [", m_outfile);
524 if (regno != ORIGINAL_REGNO (in_rtx))
525 fprintf (m_outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
526 if (REG_EXPR (in_rtx))
527 print_mem_expr (m_outfile, REG_EXPR (in_rtx));
529 if (maybe_ne (REG_OFFSET (in_rtx), 0))
531 fprintf (m_outfile, "+");
532 print_poly_int (m_outfile, REG_OFFSET (in_rtx));
534 fputs (" ]", m_outfile);
536 if (regno != ORIGINAL_REGNO (in_rtx))
537 fprintf (m_outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
538 #endif
541 /* Subroutine of print_rtx_operand for handling code 'u'. */
543 void
544 rtx_writer::print_rtx_operand_code_u (const_rtx in_rtx, int idx)
546 /* Don't print insn UIDs for PREV/NEXT_INSN in compact mode. */
547 if (m_compact && INSN_CHAIN_CODE_P (GET_CODE (in_rtx)) && idx < 2)
548 return;
550 if (XEXP (in_rtx, idx) != NULL)
552 rtx sub = XEXP (in_rtx, idx);
553 enum rtx_code subc = GET_CODE (sub);
555 if (GET_CODE (in_rtx) == LABEL_REF)
557 if (subc == NOTE
558 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
560 if (flag_dump_unnumbered)
561 fprintf (m_outfile, " [# deleted]");
562 else
563 fprintf (m_outfile, " [%d deleted]", INSN_UID (sub));
564 m_sawclose = 0;
565 return;
568 if (subc != CODE_LABEL)
570 print_rtx_operand_code_e (in_rtx, idx);
571 return;
575 if (flag_dump_unnumbered
576 || (flag_dump_unnumbered_links && idx <= 1
577 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
578 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
579 fputs (" #", m_outfile);
580 else
581 fprintf (m_outfile, " %d", INSN_UID (sub));
583 else
584 fputs (" 0", m_outfile);
585 m_sawclose = 0;
588 /* Subroutine of print_rtx. Print operand IDX of IN_RTX. */
590 void
591 rtx_writer::print_rtx_operand (const_rtx in_rtx, int idx)
593 const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
595 switch (format_ptr[idx])
597 const char *str;
599 case 'T':
600 str = XTMPL (in_rtx, idx);
601 goto string;
603 case 'S':
604 case 's':
605 str = XSTR (in_rtx, idx);
606 string:
608 if (str == 0)
609 fputs (" (nil)", m_outfile);
610 else
611 fprintf (m_outfile, " (\"%s\")", str);
612 m_sawclose = 1;
613 break;
615 case '0':
616 print_rtx_operand_code_0 (in_rtx, idx);
617 break;
619 case 'e':
620 print_rtx_operand_code_e (in_rtx, idx);
621 break;
623 case 'E':
624 case 'V':
625 print_rtx_operand_codes_E_and_V (in_rtx, idx);
626 break;
628 case 'w':
629 if (! m_simple)
630 fprintf (m_outfile, " ");
631 fprintf (m_outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, idx));
632 if (! m_simple && !m_compact)
633 fprintf (m_outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
634 (unsigned HOST_WIDE_INT) XWINT (in_rtx, idx));
635 break;
637 case 'i':
638 print_rtx_operand_code_i (in_rtx, idx);
639 break;
641 case 'r':
642 print_rtx_operand_code_r (in_rtx);
643 break;
645 /* Print NOTE_INSN names rather than integer codes. */
647 case 'n':
648 fprintf (m_outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, idx)));
649 m_sawclose = 0;
650 break;
652 case 'u':
653 print_rtx_operand_code_u (in_rtx, idx);
654 break;
656 case 't':
657 #ifndef GENERATOR_FILE
658 if (idx == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
659 print_mem_expr (m_outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
660 else if (idx == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
661 print_mem_expr (m_outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
662 else
663 dump_addr (m_outfile, " ", XTREE (in_rtx, idx));
664 #endif
665 break;
667 case '*':
668 fputs (" Unknown", m_outfile);
669 m_sawclose = 0;
670 break;
672 case 'B':
673 /* Don't print basic block ids in compact mode. */
674 if (m_compact)
675 break;
676 #ifndef GENERATOR_FILE
677 if (XBBDEF (in_rtx, idx))
678 fprintf (m_outfile, " %i", XBBDEF (in_rtx, idx)->index);
679 #endif
680 break;
682 default:
683 gcc_unreachable ();
687 /* Subroutine of rtx_writer::print_rtx.
688 In compact mode, determine if operand IDX of IN_RTX is interesting
689 to dump, or (if in a trailing position) it can be omitted. */
691 bool
692 rtx_writer::operand_has_default_value_p (const_rtx in_rtx, int idx)
694 const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
696 switch (format_ptr[idx])
698 case 'e':
699 case 'u':
700 return XEXP (in_rtx, idx) == NULL_RTX;
702 case 's':
703 return XSTR (in_rtx, idx) == NULL;
705 case '0':
706 switch (GET_CODE (in_rtx))
708 case JUMP_INSN:
709 /* JUMP_LABELs are always omitted in compact mode, so treat
710 any value here as omittable, so that earlier operands can
711 potentially be omitted also. */
712 return m_compact;
714 default:
715 return false;
719 default:
720 return false;
724 /* Print IN_RTX onto m_outfile. This is the recursive part of printing. */
726 void
727 rtx_writer::print_rtx (const_rtx in_rtx)
729 int idx = 0;
731 if (m_sawclose)
733 if (m_simple)
734 fputc (' ', m_outfile);
735 else
736 fprintf (m_outfile, "\n%s%*s", print_rtx_head, m_indent * 2, "");
737 m_sawclose = 0;
740 if (in_rtx == 0)
742 fputs ("(nil)", m_outfile);
743 m_sawclose = 1;
744 return;
746 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
748 fprintf (m_outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
749 print_rtx_head, m_indent * 2, "");
750 m_sawclose = 1;
751 return;
754 fputc ('(', m_outfile);
756 /* Print name of expression code. */
758 /* Handle reuse. */
759 #ifndef GENERATOR_FILE
760 if (m_rtx_reuse_manager)
762 int reuse_id;
763 if (m_rtx_reuse_manager->has_reuse_id (in_rtx, &reuse_id))
765 /* Have we already seen the defn of this rtx? */
766 if (m_rtx_reuse_manager->seen_def_p (reuse_id))
768 fprintf (m_outfile, "reuse_rtx %i)", reuse_id);
769 m_sawclose = 1;
770 return;
772 else
774 /* First time we've seen this reused-rtx. */
775 fprintf (m_outfile, "%i|", reuse_id);
776 m_rtx_reuse_manager->set_seen_def (reuse_id);
780 #endif /* #ifndef GENERATOR_FILE */
782 /* In compact mode, prefix the code of insns with "c",
783 giving "cinsn", "cnote" etc. */
784 if (m_compact && is_a <const rtx_insn *, const struct rtx_def> (in_rtx))
786 /* "ccode_label" is slightly awkward, so special-case it as
787 just "clabel". */
788 rtx_code code = GET_CODE (in_rtx);
789 if (code == CODE_LABEL)
790 fprintf (m_outfile, "clabel");
791 else
792 fprintf (m_outfile, "c%s", GET_RTX_NAME (code));
794 else if (m_simple && CONST_INT_P (in_rtx))
795 ; /* no code. */
796 else
797 fprintf (m_outfile, "%s", GET_RTX_NAME (GET_CODE (in_rtx)));
799 if (! m_simple)
801 if (RTX_FLAG (in_rtx, in_struct))
802 fputs ("/s", m_outfile);
804 if (RTX_FLAG (in_rtx, volatil))
805 fputs ("/v", m_outfile);
807 if (RTX_FLAG (in_rtx, unchanging))
808 fputs ("/u", m_outfile);
810 if (RTX_FLAG (in_rtx, frame_related))
811 fputs ("/f", m_outfile);
813 if (RTX_FLAG (in_rtx, jump))
814 fputs ("/j", m_outfile);
816 if (RTX_FLAG (in_rtx, call))
817 fputs ("/c", m_outfile);
819 if (RTX_FLAG (in_rtx, return_val))
820 fputs ("/i", m_outfile);
822 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
823 if ((GET_CODE (in_rtx) == EXPR_LIST
824 || GET_CODE (in_rtx) == INSN_LIST
825 || GET_CODE (in_rtx) == INT_LIST)
826 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX
827 && !m_in_call_function_usage)
828 fprintf (m_outfile, ":%s",
829 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
831 /* For other rtl, print the mode if it's not VOID. */
832 else if (GET_MODE (in_rtx) != VOIDmode)
833 fprintf (m_outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
835 #ifndef GENERATOR_FILE
836 if (GET_CODE (in_rtx) == VAR_LOCATION)
838 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
839 fputs (" <debug string placeholder>", m_outfile);
840 else
841 print_mem_expr (m_outfile, PAT_VAR_LOCATION_DECL (in_rtx));
842 fputc (' ', m_outfile);
843 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
844 if (PAT_VAR_LOCATION_STATUS (in_rtx)
845 == VAR_INIT_STATUS_UNINITIALIZED)
846 fprintf (m_outfile, " [uninit]");
847 m_sawclose = 1;
848 idx = GET_RTX_LENGTH (VAR_LOCATION);
850 #endif
853 #ifndef GENERATOR_FILE
854 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx))
855 idx = 5;
856 #endif
858 /* For insns, print the INSN_UID. */
859 if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx)))
861 if (flag_dump_unnumbered)
862 fprintf (m_outfile, " #");
863 else
864 fprintf (m_outfile, " %d", INSN_UID (in_rtx));
867 /* Determine which is the final operand to print.
868 In compact mode, skip trailing operands that have the default values
869 e.g. trailing "(nil)" values. */
870 int limit = GET_RTX_LENGTH (GET_CODE (in_rtx));
871 if (m_compact)
872 while (limit > idx && operand_has_default_value_p (in_rtx, limit - 1))
873 limit--;
875 /* Get the format string and skip the first elements if we have handled
876 them already. */
878 for (; idx < limit; idx++)
879 print_rtx_operand (in_rtx, idx);
881 switch (GET_CODE (in_rtx))
883 #ifndef GENERATOR_FILE
884 case MEM:
885 if (__builtin_expect (final_insns_dump_p, false))
886 fprintf (m_outfile, " [");
887 else
888 fprintf (m_outfile, " [" HOST_WIDE_INT_PRINT_DEC,
889 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
891 if (MEM_EXPR (in_rtx))
892 print_mem_expr (m_outfile, MEM_EXPR (in_rtx));
893 else
894 fputc (' ', m_outfile);
896 if (MEM_OFFSET_KNOWN_P (in_rtx))
898 fprintf (m_outfile, "+");
899 print_poly_int (m_outfile, MEM_OFFSET (in_rtx));
902 if (MEM_SIZE_KNOWN_P (in_rtx))
904 fprintf (m_outfile, " S");
905 print_poly_int (m_outfile, MEM_SIZE (in_rtx));
908 if (MEM_ALIGN (in_rtx) != 1)
909 fprintf (m_outfile, " A%u", MEM_ALIGN (in_rtx));
911 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
912 fprintf (m_outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
914 fputc (']', m_outfile);
915 break;
917 case CONST_DOUBLE:
918 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
920 char s[60];
922 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
923 sizeof (s), 0, 1);
924 fprintf (m_outfile, " %s", s);
926 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
927 sizeof (s), 0, 1);
928 fprintf (m_outfile, " [%s]", s);
930 break;
932 case CONST_WIDE_INT:
933 fprintf (m_outfile, " ");
934 cwi_output_hex (m_outfile, in_rtx);
935 break;
937 case CONST_POLY_INT:
938 fprintf (m_outfile, " [");
939 print_dec (CONST_POLY_INT_COEFFS (in_rtx)[0], m_outfile, SIGNED);
940 for (unsigned int i = 1; i < NUM_POLY_INT_COEFFS; ++i)
942 fprintf (m_outfile, ", ");
943 print_dec (CONST_POLY_INT_COEFFS (in_rtx)[i], m_outfile, SIGNED);
945 fprintf (m_outfile, "]");
946 break;
947 #endif
949 case CODE_LABEL:
950 if (!m_compact)
951 fprintf (m_outfile, " [%d uses]", LABEL_NUSES (in_rtx));
952 switch (LABEL_KIND (in_rtx))
954 case LABEL_NORMAL: break;
955 case LABEL_STATIC_ENTRY: fputs (" [entry]", m_outfile); break;
956 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", m_outfile); break;
957 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", m_outfile); break;
958 default: gcc_unreachable ();
960 break;
962 default:
963 break;
966 fputc (')', m_outfile);
967 m_sawclose = 1;
970 /* Emit a closing parenthesis and newline. */
972 void
973 rtx_writer::finish_directive ()
975 fprintf (m_outfile, ")\n");
976 m_sawclose = 0;
979 /* Print an rtx on the current line of FILE. Initially indent IND
980 characters. */
982 void
983 print_inline_rtx (FILE *outf, const_rtx x, int ind)
985 rtx_writer w (outf, ind, false, false, NULL);
986 w.print_rtx (x);
989 /* Call this function from the debugger to see what X looks like. */
991 DEBUG_FUNCTION void
992 debug_rtx (const_rtx x)
994 rtx_writer w (stderr, 0, false, false, NULL);
995 w.print_rtx (x);
996 fprintf (stderr, "\n");
999 /* Dump rtx REF. */
1001 DEBUG_FUNCTION void
1002 debug (const rtx_def &ref)
1004 debug_rtx (&ref);
1007 DEBUG_FUNCTION void
1008 debug (const rtx_def *ptr)
1010 if (ptr)
1011 debug (*ptr);
1012 else
1013 fprintf (stderr, "<nil>\n");
1016 /* Like debug_rtx but with no newline, as debug_helper will add one.
1018 Note: No debug_slim(rtx_insn *) variant implemented, as this
1019 function can serve for both rtx and rtx_insn. */
1021 static void
1022 debug_slim (const_rtx x)
1024 rtx_writer w (stderr, 0, false, false, NULL);
1025 w.print_rtx (x);
1028 DEFINE_DEBUG_VEC (rtx_def *)
1029 DEFINE_DEBUG_VEC (rtx_insn *)
1030 DEFINE_DEBUG_HASH_SET (rtx_def *)
1031 DEFINE_DEBUG_HASH_SET (rtx_insn *)
1033 /* Count of rtx's to print with debug_rtx_list.
1034 This global exists because gdb user defined commands have no arguments. */
1036 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
1038 /* Call this function to print list from X on.
1040 N is a count of the rtx's to print. Positive values print from the specified
1041 rtx_insn on. Negative values print a window around the rtx_insn.
1042 EG: -5 prints 2 rtx_insn's on either side (in addition to the specified
1043 rtx_insn). */
1045 DEBUG_FUNCTION void
1046 debug_rtx_list (const rtx_insn *x, int n)
1048 int i,count;
1049 const rtx_insn *insn;
1051 count = n == 0 ? 1 : n < 0 ? -n : n;
1053 /* If we are printing a window, back up to the start. */
1055 if (n < 0)
1056 for (i = count / 2; i > 0; i--)
1058 if (PREV_INSN (x) == 0)
1059 break;
1060 x = PREV_INSN (x);
1063 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
1065 debug_rtx (insn);
1066 fprintf (stderr, "\n");
1070 /* Call this function to print an rtx_insn list from START to END
1071 inclusive. */
1073 DEBUG_FUNCTION void
1074 debug_rtx_range (const rtx_insn *start, const rtx_insn *end)
1076 while (1)
1078 debug_rtx (start);
1079 fprintf (stderr, "\n");
1080 if (!start || start == end)
1081 break;
1082 start = NEXT_INSN (start);
1086 /* Call this function to search an rtx_insn list to find one with insn uid UID,
1087 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
1088 The found insn is returned to enable further debugging analysis. */
1090 DEBUG_FUNCTION const rtx_insn *
1091 debug_rtx_find (const rtx_insn *x, int uid)
1093 while (x != 0 && INSN_UID (x) != uid)
1094 x = NEXT_INSN (x);
1095 if (x != 0)
1097 debug_rtx_list (x, debug_rtx_count);
1098 return x;
1100 else
1102 fprintf (stderr, "insn uid %d not found\n", uid);
1103 return 0;
1107 /* External entry point for printing a chain of insns
1108 starting with RTX_FIRST.
1109 A blank line separates insns.
1111 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
1113 void
1114 rtx_writer::print_rtl (const_rtx rtx_first)
1116 const rtx_insn *tmp_rtx;
1118 if (rtx_first == 0)
1120 fputs (print_rtx_head, m_outfile);
1121 fputs ("(nil)\n", m_outfile);
1123 else
1124 switch (GET_CODE (rtx_first))
1126 case INSN:
1127 case JUMP_INSN:
1128 case CALL_INSN:
1129 case NOTE:
1130 case CODE_LABEL:
1131 case JUMP_TABLE_DATA:
1132 case BARRIER:
1133 for (tmp_rtx = as_a <const rtx_insn *> (rtx_first);
1134 tmp_rtx != 0;
1135 tmp_rtx = NEXT_INSN (tmp_rtx))
1137 fputs (print_rtx_head, m_outfile);
1138 print_rtx (tmp_rtx);
1139 fprintf (m_outfile, "\n");
1141 break;
1143 default:
1144 fputs (print_rtx_head, m_outfile);
1145 print_rtx (rtx_first);
1149 /* External entry point for printing a chain of insns
1150 starting with RTX_FIRST onto file OUTF.
1151 A blank line separates insns.
1153 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
1155 void
1156 print_rtl (FILE *outf, const_rtx rtx_first)
1158 rtx_writer w (outf, 0, false, false, NULL);
1159 w.print_rtl (rtx_first);
1162 /* Like print_rtx, except specify a file. */
1163 /* Return nonzero if we actually printed anything. */
1166 print_rtl_single (FILE *outf, const_rtx x)
1168 rtx_writer w (outf, 0, false, false, NULL);
1169 return w.print_rtl_single_with_indent (x, 0);
1172 /* Like print_rtl_single, except specify an indentation. */
1175 rtx_writer::print_rtl_single_with_indent (const_rtx x, int ind)
1177 char *s_indent = (char *) alloca ((size_t) ind + 1);
1178 memset ((void *) s_indent, ' ', (size_t) ind);
1179 s_indent[ind] = '\0';
1180 fputs (s_indent, m_outfile);
1181 fputs (print_rtx_head, m_outfile);
1183 int old_indent = m_indent;
1184 m_indent = ind;
1185 m_sawclose = 0;
1186 print_rtx (x);
1187 putc ('\n', m_outfile);
1188 m_indent = old_indent;
1189 return 1;
1193 /* Like print_rtl except without all the detail; for example,
1194 if RTX is a CONST_INT then print in decimal format. */
1196 void
1197 print_simple_rtl (FILE *outf, const_rtx x)
1199 rtx_writer w (outf, 0, true, false, NULL);
1200 w.print_rtl (x);
1203 /* Print the elements of VEC to FILE. */
1205 void
1206 print_rtx_insn_vec (FILE *file, const vec<rtx_insn *> &vec)
1208 fputc('{', file);
1210 unsigned int len = vec.length ();
1211 for (unsigned int i = 0; i < len; i++)
1213 print_rtl (file, vec[i]);
1214 if (i < len - 1)
1215 fputs (", ", file);
1218 fputc ('}', file);
1221 #ifndef GENERATOR_FILE
1222 /* The functions below try to print RTL in a form resembling assembler
1223 mnemonics. Because this form is more concise than the "traditional" form
1224 of RTL printing in Lisp-style, the form printed by this file is called
1225 "slim". RTL dumps in slim format can be obtained by appending the "-slim"
1226 option to -fdump-rtl-<pass>. Control flow graph output as a DOT file is
1227 always printed in slim form.
1229 The normal interface to the functionality provided in this pretty-printer
1230 is through the dump_*_slim functions to print to a stream, or via the
1231 print_*_slim functions to print into a user's pretty-printer.
1233 It is also possible to obtain a string for a single pattern as a string
1234 pointer, via str_pattern_slim, but this usage is discouraged. */
1236 /* For insns we print patterns, and for some patterns we print insns... */
1237 static void print_insn_with_notes (pretty_printer *, const rtx_insn *);
1239 /* This recognizes rtx'en classified as expressions. These are always
1240 represent some action on values or results of other expression, that
1241 may be stored in objects representing values. */
1243 static void
1244 print_exp (pretty_printer *pp, const_rtx x, int verbose)
1246 const char *st[4];
1247 const char *fun;
1248 rtx op[4];
1249 int i;
1251 fun = (char *) 0;
1252 for (i = 0; i < 4; i++)
1254 st[i] = (char *) 0;
1255 op[i] = NULL_RTX;
1258 switch (GET_CODE (x))
1260 case PLUS:
1261 op[0] = XEXP (x, 0);
1262 if (CONST_INT_P (XEXP (x, 1))
1263 && INTVAL (XEXP (x, 1)) < 0)
1265 st[1] = "-";
1266 op[1] = GEN_INT (-INTVAL (XEXP (x, 1)));
1268 else
1270 st[1] = "+";
1271 op[1] = XEXP (x, 1);
1273 break;
1274 case LO_SUM:
1275 op[0] = XEXP (x, 0);
1276 st[1] = "+low(";
1277 op[1] = XEXP (x, 1);
1278 st[2] = ")";
1279 break;
1280 case MINUS:
1281 op[0] = XEXP (x, 0);
1282 st[1] = "-";
1283 op[1] = XEXP (x, 1);
1284 break;
1285 case COMPARE:
1286 fun = "cmp";
1287 op[0] = XEXP (x, 0);
1288 op[1] = XEXP (x, 1);
1289 break;
1290 case NEG:
1291 st[0] = "-";
1292 op[0] = XEXP (x, 0);
1293 break;
1294 case FMA:
1295 st[0] = "{";
1296 op[0] = XEXP (x, 0);
1297 st[1] = "*";
1298 op[1] = XEXP (x, 1);
1299 st[2] = "+";
1300 op[2] = XEXP (x, 2);
1301 st[3] = "}";
1302 break;
1303 case MULT:
1304 op[0] = XEXP (x, 0);
1305 st[1] = "*";
1306 op[1] = XEXP (x, 1);
1307 break;
1308 case DIV:
1309 op[0] = XEXP (x, 0);
1310 st[1] = "/";
1311 op[1] = XEXP (x, 1);
1312 break;
1313 case UDIV:
1314 fun = "udiv";
1315 op[0] = XEXP (x, 0);
1316 op[1] = XEXP (x, 1);
1317 break;
1318 case MOD:
1319 op[0] = XEXP (x, 0);
1320 st[1] = "%";
1321 op[1] = XEXP (x, 1);
1322 break;
1323 case UMOD:
1324 fun = "umod";
1325 op[0] = XEXP (x, 0);
1326 op[1] = XEXP (x, 1);
1327 break;
1328 case SMIN:
1329 fun = "smin";
1330 op[0] = XEXP (x, 0);
1331 op[1] = XEXP (x, 1);
1332 break;
1333 case SMAX:
1334 fun = "smax";
1335 op[0] = XEXP (x, 0);
1336 op[1] = XEXP (x, 1);
1337 break;
1338 case UMIN:
1339 fun = "umin";
1340 op[0] = XEXP (x, 0);
1341 op[1] = XEXP (x, 1);
1342 break;
1343 case UMAX:
1344 fun = "umax";
1345 op[0] = XEXP (x, 0);
1346 op[1] = XEXP (x, 1);
1347 break;
1348 case NOT:
1349 st[0] = "~";
1350 op[0] = XEXP (x, 0);
1351 break;
1352 case AND:
1353 op[0] = XEXP (x, 0);
1354 st[1] = "&";
1355 op[1] = XEXP (x, 1);
1356 break;
1357 case IOR:
1358 op[0] = XEXP (x, 0);
1359 st[1] = "|";
1360 op[1] = XEXP (x, 1);
1361 break;
1362 case XOR:
1363 op[0] = XEXP (x, 0);
1364 st[1] = "^";
1365 op[1] = XEXP (x, 1);
1366 break;
1367 case ASHIFT:
1368 op[0] = XEXP (x, 0);
1369 st[1] = "<<";
1370 op[1] = XEXP (x, 1);
1371 break;
1372 case LSHIFTRT:
1373 op[0] = XEXP (x, 0);
1374 st[1] = " 0>>";
1375 op[1] = XEXP (x, 1);
1376 break;
1377 case ASHIFTRT:
1378 op[0] = XEXP (x, 0);
1379 st[1] = ">>";
1380 op[1] = XEXP (x, 1);
1381 break;
1382 case ROTATE:
1383 op[0] = XEXP (x, 0);
1384 st[1] = "<-<";
1385 op[1] = XEXP (x, 1);
1386 break;
1387 case ROTATERT:
1388 op[0] = XEXP (x, 0);
1389 st[1] = ">->";
1390 op[1] = XEXP (x, 1);
1391 break;
1392 case NE:
1393 op[0] = XEXP (x, 0);
1394 st[1] = "!=";
1395 op[1] = XEXP (x, 1);
1396 break;
1397 case EQ:
1398 op[0] = XEXP (x, 0);
1399 st[1] = "==";
1400 op[1] = XEXP (x, 1);
1401 break;
1402 case GE:
1403 op[0] = XEXP (x, 0);
1404 st[1] = ">=";
1405 op[1] = XEXP (x, 1);
1406 break;
1407 case GT:
1408 op[0] = XEXP (x, 0);
1409 st[1] = ">";
1410 op[1] = XEXP (x, 1);
1411 break;
1412 case LE:
1413 op[0] = XEXP (x, 0);
1414 st[1] = "<=";
1415 op[1] = XEXP (x, 1);
1416 break;
1417 case LT:
1418 op[0] = XEXP (x, 0);
1419 st[1] = "<";
1420 op[1] = XEXP (x, 1);
1421 break;
1422 case SIGN_EXTRACT:
1423 fun = (verbose) ? "sign_extract" : "sxt";
1424 op[0] = XEXP (x, 0);
1425 op[1] = XEXP (x, 1);
1426 op[2] = XEXP (x, 2);
1427 break;
1428 case ZERO_EXTRACT:
1429 fun = (verbose) ? "zero_extract" : "zxt";
1430 op[0] = XEXP (x, 0);
1431 op[1] = XEXP (x, 1);
1432 op[2] = XEXP (x, 2);
1433 break;
1434 case SIGN_EXTEND:
1435 fun = (verbose) ? "sign_extend" : "sxn";
1436 op[0] = XEXP (x, 0);
1437 break;
1438 case ZERO_EXTEND:
1439 fun = (verbose) ? "zero_extend" : "zxn";
1440 op[0] = XEXP (x, 0);
1441 break;
1442 case FLOAT_EXTEND:
1443 fun = (verbose) ? "float_extend" : "fxn";
1444 op[0] = XEXP (x, 0);
1445 break;
1446 case TRUNCATE:
1447 fun = (verbose) ? "trunc" : "trn";
1448 op[0] = XEXP (x, 0);
1449 break;
1450 case FLOAT_TRUNCATE:
1451 fun = (verbose) ? "float_trunc" : "ftr";
1452 op[0] = XEXP (x, 0);
1453 break;
1454 case FLOAT:
1455 fun = (verbose) ? "float" : "flt";
1456 op[0] = XEXP (x, 0);
1457 break;
1458 case UNSIGNED_FLOAT:
1459 fun = (verbose) ? "uns_float" : "ufl";
1460 op[0] = XEXP (x, 0);
1461 break;
1462 case FIX:
1463 fun = "fix";
1464 op[0] = XEXP (x, 0);
1465 break;
1466 case UNSIGNED_FIX:
1467 fun = (verbose) ? "uns_fix" : "ufx";
1468 op[0] = XEXP (x, 0);
1469 break;
1470 case PRE_DEC:
1471 st[0] = "--";
1472 op[0] = XEXP (x, 0);
1473 break;
1474 case PRE_INC:
1475 st[0] = "++";
1476 op[0] = XEXP (x, 0);
1477 break;
1478 case POST_DEC:
1479 op[0] = XEXP (x, 0);
1480 st[1] = "--";
1481 break;
1482 case POST_INC:
1483 op[0] = XEXP (x, 0);
1484 st[1] = "++";
1485 break;
1486 case PRE_MODIFY:
1487 st[0] = "pre ";
1488 op[0] = XEXP (XEXP (x, 1), 0);
1489 st[1] = "+=";
1490 op[1] = XEXP (XEXP (x, 1), 1);
1491 break;
1492 case POST_MODIFY:
1493 st[0] = "post ";
1494 op[0] = XEXP (XEXP (x, 1), 0);
1495 st[1] = "+=";
1496 op[1] = XEXP (XEXP (x, 1), 1);
1497 break;
1498 case CALL:
1499 st[0] = "call ";
1500 op[0] = XEXP (x, 0);
1501 if (verbose)
1503 st[1] = " argc:";
1504 op[1] = XEXP (x, 1);
1506 break;
1507 case IF_THEN_ELSE:
1508 st[0] = "{(";
1509 op[0] = XEXP (x, 0);
1510 st[1] = ")?";
1511 op[1] = XEXP (x, 1);
1512 st[2] = ":";
1513 op[2] = XEXP (x, 2);
1514 st[3] = "}";
1515 break;
1516 case TRAP_IF:
1517 fun = "trap_if";
1518 op[0] = TRAP_CONDITION (x);
1519 break;
1520 case PREFETCH:
1521 fun = "prefetch";
1522 op[0] = XEXP (x, 0);
1523 op[1] = XEXP (x, 1);
1524 op[2] = XEXP (x, 2);
1525 break;
1526 case UNSPEC:
1527 case UNSPEC_VOLATILE:
1529 pp_string (pp, "unspec");
1530 if (GET_CODE (x) == UNSPEC_VOLATILE)
1531 pp_string (pp, "/v");
1532 pp_left_bracket (pp);
1533 for (i = 0; i < XVECLEN (x, 0); i++)
1535 if (i != 0)
1536 pp_comma (pp);
1537 print_pattern (pp, XVECEXP (x, 0, i), verbose);
1539 pp_string (pp, "] ");
1540 pp_decimal_int (pp, XINT (x, 1));
1542 break;
1543 default:
1545 /* Most unhandled codes can be printed as pseudo-functions. */
1546 if (GET_RTX_CLASS (GET_CODE (x)) == RTX_UNARY)
1548 fun = GET_RTX_NAME (GET_CODE (x));
1549 op[0] = XEXP (x, 0);
1551 else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_COMPARE
1552 || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_COMPARE
1553 || GET_RTX_CLASS (GET_CODE (x)) == RTX_BIN_ARITH
1554 || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_ARITH)
1556 fun = GET_RTX_NAME (GET_CODE (x));
1557 op[0] = XEXP (x, 0);
1558 op[1] = XEXP (x, 1);
1560 else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_TERNARY)
1562 fun = GET_RTX_NAME (GET_CODE (x));
1563 op[0] = XEXP (x, 0);
1564 op[1] = XEXP (x, 1);
1565 op[2] = XEXP (x, 2);
1567 else
1568 /* Give up, just print the RTX name. */
1569 st[0] = GET_RTX_NAME (GET_CODE (x));
1571 break;
1574 /* Print this as a function? */
1575 if (fun)
1577 pp_string (pp, fun);
1578 pp_left_paren (pp);
1581 for (i = 0; i < 4; i++)
1583 if (st[i])
1584 pp_string (pp, st[i]);
1586 if (op[i])
1588 if (fun && i != 0)
1589 pp_comma (pp);
1590 print_value (pp, op[i], verbose);
1594 if (fun)
1595 pp_right_paren (pp);
1596 } /* print_exp */
1598 /* Prints rtxes, I customarily classified as values. They're constants,
1599 registers, labels, symbols and memory accesses. */
1601 void
1602 print_value (pretty_printer *pp, const_rtx x, int verbose)
1604 char tmp[1024];
1606 if (!x)
1608 pp_string (pp, "(nil)");
1609 return;
1611 switch (GET_CODE (x))
1613 case CONST_INT:
1614 pp_scalar (pp, HOST_WIDE_INT_PRINT_HEX,
1615 (unsigned HOST_WIDE_INT) INTVAL (x));
1616 break;
1618 case CONST_WIDE_INT:
1620 const char *sep = "<";
1621 int i;
1622 for (i = CONST_WIDE_INT_NUNITS (x) - 1; i >= 0; i--)
1624 pp_string (pp, sep);
1625 sep = ",";
1626 sprintf (tmp, HOST_WIDE_INT_PRINT_HEX,
1627 (unsigned HOST_WIDE_INT) CONST_WIDE_INT_ELT (x, i));
1628 pp_string (pp, tmp);
1630 pp_greater (pp);
1632 break;
1634 case CONST_POLY_INT:
1635 pp_left_bracket (pp);
1636 pp_wide_int (pp, CONST_POLY_INT_COEFFS (x)[0], SIGNED);
1637 for (unsigned int i = 1; i < NUM_POLY_INT_COEFFS; ++i)
1639 pp_string (pp, ", ");
1640 pp_wide_int (pp, CONST_POLY_INT_COEFFS (x)[i], SIGNED);
1642 pp_right_bracket (pp);
1643 break;
1645 case CONST_DOUBLE:
1646 if (FLOAT_MODE_P (GET_MODE (x)))
1648 real_to_decimal (tmp, CONST_DOUBLE_REAL_VALUE (x),
1649 sizeof (tmp), 0, 1);
1650 pp_string (pp, tmp);
1652 else
1653 pp_printf (pp, "<%wx,%wx>",
1654 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x),
1655 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x));
1656 break;
1657 case CONST_FIXED:
1658 fixed_to_decimal (tmp, CONST_FIXED_VALUE (x), sizeof (tmp));
1659 pp_string (pp, tmp);
1660 break;
1661 case CONST_STRING:
1662 pp_printf (pp, "\"%s\"", XSTR (x, 0));
1663 break;
1664 case SYMBOL_REF:
1665 pp_printf (pp, "`%s'", XSTR (x, 0));
1666 break;
1667 case LABEL_REF:
1668 pp_printf (pp, "L%d", INSN_UID (label_ref_label (x)));
1669 break;
1670 case CONST:
1671 case HIGH:
1672 case STRICT_LOW_PART:
1673 pp_printf (pp, "%s(", GET_RTX_NAME (GET_CODE (x)));
1674 print_value (pp, XEXP (x, 0), verbose);
1675 pp_right_paren (pp);
1676 break;
1677 case REG:
1678 if (REGNO (x) < FIRST_PSEUDO_REGISTER)
1680 if (ISDIGIT (reg_names[REGNO (x)][0]))
1681 pp_modulo (pp);
1682 pp_string (pp, reg_names[REGNO (x)]);
1684 else
1685 pp_printf (pp, "r%d", REGNO (x));
1686 if (verbose)
1687 pp_printf (pp, ":%s", GET_MODE_NAME (GET_MODE (x)));
1688 break;
1689 case SUBREG:
1690 print_value (pp, SUBREG_REG (x), verbose);
1691 pp_printf (pp, "#%d", SUBREG_BYTE (x));
1692 break;
1693 case SCRATCH:
1694 case CC0:
1695 case PC:
1696 pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
1697 break;
1698 case MEM:
1699 pp_left_bracket (pp);
1700 print_value (pp, XEXP (x, 0), verbose);
1701 pp_right_bracket (pp);
1702 break;
1703 case DEBUG_EXPR:
1704 pp_printf (pp, "D#%i", DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x)));
1705 break;
1706 default:
1707 print_exp (pp, x, verbose);
1708 break;
1710 } /* print_value */
1712 /* The next step in insn detalization, its pattern recognition. */
1714 void
1715 print_pattern (pretty_printer *pp, const_rtx x, int verbose)
1717 if (! x)
1719 pp_string (pp, "(nil)");
1720 return;
1723 switch (GET_CODE (x))
1725 case SET:
1726 print_value (pp, SET_DEST (x), verbose);
1727 pp_equal (pp);
1728 print_value (pp, SET_SRC (x), verbose);
1729 break;
1730 case RETURN:
1731 case SIMPLE_RETURN:
1732 case EH_RETURN:
1733 pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
1734 break;
1735 case CALL:
1736 print_exp (pp, x, verbose);
1737 break;
1738 case CLOBBER:
1739 case USE:
1740 pp_printf (pp, "%s ", GET_RTX_NAME (GET_CODE (x)));
1741 print_value (pp, XEXP (x, 0), verbose);
1742 break;
1743 case VAR_LOCATION:
1744 pp_string (pp, "loc ");
1745 print_value (pp, PAT_VAR_LOCATION_LOC (x), verbose);
1746 break;
1747 case COND_EXEC:
1748 pp_left_paren (pp);
1749 if (GET_CODE (COND_EXEC_TEST (x)) == NE
1750 && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
1751 print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
1752 else if (GET_CODE (COND_EXEC_TEST (x)) == EQ
1753 && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
1755 pp_exclamation (pp);
1756 print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
1758 else
1759 print_value (pp, COND_EXEC_TEST (x), verbose);
1760 pp_string (pp, ") ");
1761 print_pattern (pp, COND_EXEC_CODE (x), verbose);
1762 break;
1763 case PARALLEL:
1765 int i;
1767 pp_left_brace (pp);
1768 for (i = 0; i < XVECLEN (x, 0); i++)
1770 print_pattern (pp, XVECEXP (x, 0, i), verbose);
1771 pp_semicolon (pp);
1773 pp_right_brace (pp);
1775 break;
1776 case SEQUENCE:
1778 const rtx_sequence *seq = as_a <const rtx_sequence *> (x);
1779 pp_string (pp, "sequence{");
1780 if (INSN_P (seq->element (0)))
1782 /* Print the sequence insns indented. */
1783 const char * save_print_rtx_head = print_rtx_head;
1784 char indented_print_rtx_head[32];
1786 pp_newline (pp);
1787 gcc_assert (strlen (print_rtx_head) < sizeof (indented_print_rtx_head) - 4);
1788 snprintf (indented_print_rtx_head,
1789 sizeof (indented_print_rtx_head),
1790 "%s ", print_rtx_head);
1791 print_rtx_head = indented_print_rtx_head;
1792 for (int i = 0; i < seq->len (); i++)
1793 print_insn_with_notes (pp, seq->insn (i));
1794 pp_printf (pp, "%s ", save_print_rtx_head);
1795 print_rtx_head = save_print_rtx_head;
1797 else
1799 for (int i = 0; i < seq->len (); i++)
1801 print_pattern (pp, seq->element (i), verbose);
1802 pp_semicolon (pp);
1805 pp_right_brace (pp);
1807 break;
1808 case ASM_INPUT:
1809 pp_printf (pp, "asm {%s}", XSTR (x, 0));
1810 break;
1811 case ADDR_VEC:
1812 for (int i = 0; i < XVECLEN (x, 0); i++)
1814 print_value (pp, XVECEXP (x, 0, i), verbose);
1815 pp_semicolon (pp);
1817 break;
1818 case ADDR_DIFF_VEC:
1819 for (int i = 0; i < XVECLEN (x, 1); i++)
1821 print_value (pp, XVECEXP (x, 1, i), verbose);
1822 pp_semicolon (pp);
1824 break;
1825 case TRAP_IF:
1826 pp_string (pp, "trap_if ");
1827 print_value (pp, TRAP_CONDITION (x), verbose);
1828 break;
1829 case UNSPEC:
1830 case UNSPEC_VOLATILE:
1831 /* Fallthru -- leave UNSPECs to print_exp. */
1832 default:
1833 print_value (pp, x, verbose);
1835 } /* print_pattern */
1837 /* This is the main function in slim rtl visualization mechanism.
1839 X is an insn, to be printed into PP.
1841 This function tries to print it properly in human-readable form,
1842 resembling assembler mnemonics (instead of the older Lisp-style
1843 form).
1845 If VERBOSE is TRUE, insns are printed with more complete (but
1846 longer) pattern names and with extra information, and prefixed
1847 with their INSN_UIDs. */
1849 void
1850 print_insn (pretty_printer *pp, const rtx_insn *x, int verbose)
1852 if (verbose)
1854 /* Blech, pretty-print can't print integers with a specified width. */
1855 char uid_prefix[32];
1856 snprintf (uid_prefix, sizeof uid_prefix, " %4d: ", INSN_UID (x));
1857 pp_string (pp, uid_prefix);
1860 switch (GET_CODE (x))
1862 case INSN:
1863 print_pattern (pp, PATTERN (x), verbose);
1864 break;
1866 case DEBUG_INSN:
1868 if (DEBUG_MARKER_INSN_P (x))
1870 switch (INSN_DEBUG_MARKER_KIND (x))
1872 case NOTE_INSN_BEGIN_STMT:
1873 pp_string (pp, "debug begin stmt marker");
1874 break;
1876 default:
1877 gcc_unreachable ();
1879 break;
1882 const char *name = "?";
1883 char idbuf[32];
1885 if (DECL_P (INSN_VAR_LOCATION_DECL (x)))
1887 tree id = DECL_NAME (INSN_VAR_LOCATION_DECL (x));
1888 if (id)
1889 name = IDENTIFIER_POINTER (id);
1890 else if (TREE_CODE (INSN_VAR_LOCATION_DECL (x))
1891 == DEBUG_EXPR_DECL)
1893 sprintf (idbuf, "D#%i",
1894 DEBUG_TEMP_UID (INSN_VAR_LOCATION_DECL (x)));
1895 name = idbuf;
1897 else
1899 sprintf (idbuf, "D.%i",
1900 DECL_UID (INSN_VAR_LOCATION_DECL (x)));
1901 name = idbuf;
1904 pp_printf (pp, "debug %s => ", name);
1905 if (VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (x)))
1906 pp_string (pp, "optimized away");
1907 else
1908 print_pattern (pp, INSN_VAR_LOCATION_LOC (x), verbose);
1910 break;
1912 case JUMP_INSN:
1913 print_pattern (pp, PATTERN (x), verbose);
1914 break;
1915 case CALL_INSN:
1916 if (GET_CODE (PATTERN (x)) == PARALLEL)
1917 print_pattern (pp, XVECEXP (PATTERN (x), 0, 0), verbose);
1918 else
1919 print_pattern (pp, PATTERN (x), verbose);
1920 break;
1921 case CODE_LABEL:
1922 pp_printf (pp, "L%d:", INSN_UID (x));
1923 break;
1924 case JUMP_TABLE_DATA:
1925 pp_string (pp, "jump_table_data{\n");
1926 print_pattern (pp, PATTERN (x), verbose);
1927 pp_right_brace (pp);
1928 break;
1929 case BARRIER:
1930 pp_string (pp, "barrier");
1931 break;
1932 case NOTE:
1934 pp_string (pp, GET_NOTE_INSN_NAME (NOTE_KIND (x)));
1935 switch (NOTE_KIND (x))
1937 case NOTE_INSN_EH_REGION_BEG:
1938 case NOTE_INSN_EH_REGION_END:
1939 pp_printf (pp, " %d", NOTE_EH_HANDLER (x));
1940 break;
1942 case NOTE_INSN_BLOCK_BEG:
1943 case NOTE_INSN_BLOCK_END:
1944 pp_printf (pp, " %d", BLOCK_NUMBER (NOTE_BLOCK (x)));
1945 break;
1947 case NOTE_INSN_BASIC_BLOCK:
1948 pp_printf (pp, " %d", NOTE_BASIC_BLOCK (x)->index);
1949 break;
1951 case NOTE_INSN_DELETED_LABEL:
1952 case NOTE_INSN_DELETED_DEBUG_LABEL:
1954 const char *label = NOTE_DELETED_LABEL_NAME (x);
1955 if (label == NULL)
1956 label = "";
1957 pp_printf (pp, " (\"%s\")", label);
1959 break;
1961 case NOTE_INSN_VAR_LOCATION:
1962 case NOTE_INSN_CALL_ARG_LOCATION:
1963 pp_left_brace (pp);
1964 print_pattern (pp, NOTE_VAR_LOCATION (x), verbose);
1965 pp_right_brace (pp);
1966 break;
1968 default:
1969 break;
1971 break;
1973 default:
1974 gcc_unreachable ();
1976 } /* print_insn */
1978 /* Pretty-print a slim dump of X (an insn) to PP, including any register
1979 note attached to the instruction. */
1981 static void
1982 print_insn_with_notes (pretty_printer *pp, const rtx_insn *x)
1984 pp_string (pp, print_rtx_head);
1985 print_insn (pp, x, 1);
1986 pp_newline (pp);
1987 if (INSN_P (x) && REG_NOTES (x))
1988 for (rtx note = REG_NOTES (x); note; note = XEXP (note, 1))
1990 pp_printf (pp, "%s %s ", print_rtx_head,
1991 GET_REG_NOTE_NAME (REG_NOTE_KIND (note)));
1992 if (GET_CODE (note) == INT_LIST)
1993 pp_printf (pp, "%d", XINT (note, 0));
1994 else
1995 print_pattern (pp, XEXP (note, 0), 1);
1996 pp_newline (pp);
2000 /* Print X, an RTL value node, to file F in slim format. Include
2001 additional information if VERBOSE is nonzero.
2003 Value nodes are constants, registers, labels, symbols and
2004 memory. */
2006 void
2007 dump_value_slim (FILE *f, const_rtx x, int verbose)
2009 pretty_printer rtl_slim_pp;
2010 rtl_slim_pp.buffer->stream = f;
2011 print_value (&rtl_slim_pp, x, verbose);
2012 pp_flush (&rtl_slim_pp);
2015 /* Emit a slim dump of X (an insn) to the file F, including any register
2016 note attached to the instruction. */
2017 void
2018 dump_insn_slim (FILE *f, const rtx_insn *x)
2020 pretty_printer rtl_slim_pp;
2021 rtl_slim_pp.buffer->stream = f;
2022 print_insn_with_notes (&rtl_slim_pp, x);
2023 pp_flush (&rtl_slim_pp);
2026 /* Same as above, but stop at LAST or when COUNT == 0.
2027 If COUNT < 0 it will stop only at LAST or NULL rtx. */
2029 void
2030 dump_rtl_slim (FILE *f, const rtx_insn *first, const rtx_insn *last,
2031 int count, int flags ATTRIBUTE_UNUSED)
2033 const rtx_insn *insn, *tail;
2034 pretty_printer rtl_slim_pp;
2035 rtl_slim_pp.buffer->stream = f;
2037 tail = last ? NEXT_INSN (last) : NULL;
2038 for (insn = first;
2039 (insn != NULL) && (insn != tail) && (count != 0);
2040 insn = NEXT_INSN (insn))
2042 print_insn_with_notes (&rtl_slim_pp, insn);
2043 if (count > 0)
2044 count--;
2047 pp_flush (&rtl_slim_pp);
2050 /* Dumps basic block BB to pretty-printer PP in slim form and without and
2051 no indentation, for use as a label of a DOT graph record-node. */
2053 void
2054 rtl_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
2056 rtx_insn *insn;
2057 bool first = true;
2059 /* TODO: inter-bb stuff. */
2060 FOR_BB_INSNS (bb, insn)
2062 if (! first)
2064 pp_bar (pp);
2065 pp_write_text_to_stream (pp);
2067 first = false;
2068 print_insn_with_notes (pp, insn);
2069 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2073 /* Pretty-print pattern X of some insn in non-verbose mode.
2074 Return a string pointer to the pretty-printer buffer.
2076 This function is only exported exists only to accommodate some older users
2077 of the slim RTL pretty printers. Please do not use it for new code. */
2079 const char *
2080 str_pattern_slim (const_rtx x)
2082 pretty_printer rtl_slim_pp;
2083 print_pattern (&rtl_slim_pp, x, 0);
2084 return ggc_strdup (pp_formatted_text (&rtl_slim_pp));
2087 /* Emit a slim dump of X (an insn) to stderr. */
2088 extern void debug_insn_slim (const rtx_insn *);
2089 DEBUG_FUNCTION void
2090 debug_insn_slim (const rtx_insn *x)
2092 dump_insn_slim (stderr, x);
2095 /* Same as above, but using dump_rtl_slim. */
2096 extern void debug_rtl_slim (FILE *, const rtx_insn *, const rtx_insn *,
2097 int, int);
2098 DEBUG_FUNCTION void
2099 debug_rtl_slim (const rtx_insn *first, const rtx_insn *last, int count,
2100 int flags)
2102 dump_rtl_slim (stderr, first, last, count, flags);
2105 extern void debug_bb_slim (basic_block);
2106 DEBUG_FUNCTION void
2107 debug_bb_slim (basic_block bb)
2109 dump_bb (stderr, bb, 0, TDF_SLIM | TDF_BLOCKS);
2112 extern void debug_bb_n_slim (int);
2113 DEBUG_FUNCTION void
2114 debug_bb_n_slim (int n)
2116 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, n);
2117 debug_bb_slim (bb);
2120 #endif