testsuite: Update pr79251 ilp32 store counts.
[official-gcc.git] / gcc / print-rtl.c
blob2a56823d3c10e6c7e58866c231f29aa2c7d4cec9
1 /* Print RTL for GCC.
2 Copyright (C) 1987-2021 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 "print-tree.h"
40 #include "flags.h"
41 #include "predict.h"
42 #include "function.h"
43 #include "cfg.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 /* Disable warnings about quoting issues in the pp_xxx calls below
58 that (intentionally) don't follow GCC diagnostic conventions. */
59 #if __GNUC__ >= 10
60 # pragma GCC diagnostic push
61 # pragma GCC diagnostic ignored "-Wformat-diag"
62 #endif
64 /* String printed at beginning of each RTL when it is dumped.
65 This string is set to ASM_COMMENT_START when the RTL is dumped in
66 the assembly output file. */
67 const char *print_rtx_head = "";
69 #ifdef GENERATOR_FILE
70 /* These are defined from the .opt file when not used in generator
71 programs. */
73 /* Nonzero means suppress output of instruction numbers
74 in debugging dumps.
75 This must be defined here so that programs like gencodes can be linked. */
76 int flag_dump_unnumbered = 0;
78 /* Nonzero means suppress output of instruction numbers for previous
79 and next insns in debugging dumps.
80 This must be defined here so that programs like gencodes can be linked. */
81 int flag_dump_unnumbered_links = 0;
82 #endif
84 /* Constructor for rtx_writer. */
86 rtx_writer::rtx_writer (FILE *outf, int ind, bool simple, bool compact,
87 rtx_reuse_manager *reuse_manager)
88 : m_outfile (outf), m_sawclose (0), m_indent (ind),
89 m_in_call_function_usage (false), m_simple (simple), m_compact (compact),
90 m_rtx_reuse_manager (reuse_manager)
94 #ifndef GENERATOR_FILE
96 /* rtx_reuse_manager's ctor. */
98 rtx_reuse_manager::rtx_reuse_manager ()
99 : m_next_id (0)
103 /* Determine if X is of a kind suitable for dumping via reuse_rtx. */
105 static bool
106 uses_rtx_reuse_p (const_rtx x)
108 if (x == NULL)
109 return false;
111 switch (GET_CODE (x))
113 case DEBUG_EXPR:
114 case VALUE:
115 case SCRATCH:
116 return true;
118 /* We don't use reuse_rtx for consts. */
119 CASE_CONST_UNIQUE:
120 default:
121 return false;
125 /* Traverse X and its descendents, determining if we see any rtx more than
126 once. Any rtx suitable for "reuse_rtx" that is seen more than once is
127 assigned an ID. */
129 void
130 rtx_reuse_manager::preprocess (const_rtx x)
132 subrtx_iterator::array_type array;
133 FOR_EACH_SUBRTX (iter, array, x, NONCONST)
134 if (uses_rtx_reuse_p (*iter))
136 if (int *count = m_rtx_occurrence_count.get (*iter))
138 if (*(count++) == 1)
139 m_rtx_reuse_ids.put (*iter, m_next_id++);
141 else
142 m_rtx_occurrence_count.put (*iter, 1);
146 /* Return true iff X has been assigned a reuse ID. If it has,
147 and OUT is non-NULL, then write the reuse ID to *OUT. */
149 bool
150 rtx_reuse_manager::has_reuse_id (const_rtx x, int *out)
152 int *id = m_rtx_reuse_ids.get (x);
153 if (id)
155 if (out)
156 *out = *id;
157 return true;
159 else
160 return false;
163 /* Determine if set_seen_def has been called for the given reuse ID. */
165 bool
166 rtx_reuse_manager::seen_def_p (int reuse_id)
168 return bitmap_bit_p (m_defs_seen, reuse_id);
171 /* Record that the definition of the given reuse ID has been seen. */
173 void
174 rtx_reuse_manager::set_seen_def (int reuse_id)
176 bitmap_set_bit (m_defs_seen, reuse_id);
179 #endif /* #ifndef GENERATOR_FILE */
181 #ifndef GENERATOR_FILE
182 void
183 print_mem_expr (FILE *outfile, const_tree expr)
185 fputc (' ', outfile);
186 print_generic_expr (outfile, CONST_CAST_TREE (expr),
187 dump_flags | TDF_SLIM);
189 #endif
191 /* Print X to FILE. */
193 static void
194 print_poly_int (FILE *file, poly_int64 x)
196 HOST_WIDE_INT const_x;
197 if (x.is_constant (&const_x))
198 fprintf (file, HOST_WIDE_INT_PRINT_DEC, const_x);
199 else
201 fprintf (file, "[" HOST_WIDE_INT_PRINT_DEC, x.coeffs[0]);
202 for (int i = 1; i < NUM_POLY_INT_COEFFS; ++i)
203 fprintf (file, ", " HOST_WIDE_INT_PRINT_DEC, x.coeffs[i]);
204 fprintf (file, "]");
208 /* Subroutine of print_rtx_operand for handling code '0'.
209 0 indicates a field for internal use that should not be printed.
210 However there are various special cases, such as the third field
211 of a NOTE, where it indicates that the field has several different
212 valid contents. */
214 void
215 rtx_writer::print_rtx_operand_code_0 (const_rtx in_rtx ATTRIBUTE_UNUSED,
216 int idx ATTRIBUTE_UNUSED)
218 #ifndef GENERATOR_FILE
219 if (idx == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
221 int flags = SYMBOL_REF_FLAGS (in_rtx);
222 if (flags)
223 fprintf (m_outfile, " [flags %#x]", flags);
224 tree decl = SYMBOL_REF_DECL (in_rtx);
225 if (decl)
226 print_node_brief (m_outfile, "", decl, dump_flags);
228 else if (idx == 3 && NOTE_P (in_rtx))
230 switch (NOTE_KIND (in_rtx))
232 case NOTE_INSN_EH_REGION_BEG:
233 case NOTE_INSN_EH_REGION_END:
234 if (flag_dump_unnumbered)
235 fprintf (m_outfile, " #");
236 else
237 fprintf (m_outfile, " %d", NOTE_EH_HANDLER (in_rtx));
238 m_sawclose = 1;
239 break;
241 case NOTE_INSN_BLOCK_BEG:
242 case NOTE_INSN_BLOCK_END:
243 dump_addr (m_outfile, " ", NOTE_BLOCK (in_rtx));
244 m_sawclose = 1;
245 break;
247 case NOTE_INSN_BASIC_BLOCK:
249 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
250 if (bb != 0)
251 fprintf (m_outfile, " [bb %d]", bb->index);
252 break;
255 case NOTE_INSN_DELETED_LABEL:
256 case NOTE_INSN_DELETED_DEBUG_LABEL:
258 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
259 if (label)
260 fprintf (m_outfile, " (\"%s\")", label);
261 else
262 fprintf (m_outfile, " \"\"");
264 break;
266 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
268 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
269 if (bb != 0)
270 fprintf (m_outfile, " [bb %d]", bb->index);
271 break;
274 case NOTE_INSN_VAR_LOCATION:
275 fputc (' ', m_outfile);
276 print_rtx (NOTE_VAR_LOCATION (in_rtx));
277 break;
279 case NOTE_INSN_CFI:
280 fputc ('\n', m_outfile);
281 output_cfi_directive (m_outfile, NOTE_CFI (in_rtx));
282 fputc ('\t', m_outfile);
283 break;
285 case NOTE_INSN_BEGIN_STMT:
286 case NOTE_INSN_INLINE_ENTRY:
287 #ifndef GENERATOR_FILE
289 expanded_location xloc
290 = expand_location (NOTE_MARKER_LOCATION (in_rtx));
291 fprintf (m_outfile, " %s:%i", xloc.file, xloc.line);
293 #endif
294 break;
296 default:
297 break;
300 else if (idx == 7 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL
301 && !m_compact)
303 /* Output the JUMP_LABEL reference. */
304 fprintf (m_outfile, "\n%s%*s -> ", print_rtx_head, m_indent * 2, "");
305 if (GET_CODE (JUMP_LABEL (in_rtx)) == RETURN)
306 fprintf (m_outfile, "return");
307 else if (GET_CODE (JUMP_LABEL (in_rtx)) == SIMPLE_RETURN)
308 fprintf (m_outfile, "simple_return");
309 else
310 fprintf (m_outfile, "%d", INSN_UID (JUMP_LABEL (in_rtx)));
312 else if (idx == 0 && GET_CODE (in_rtx) == VALUE)
314 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
316 fprintf (m_outfile, " %u:%u", val->uid, val->hash);
317 dump_addr (m_outfile, " @", in_rtx);
318 dump_addr (m_outfile, "/", (void*)val);
320 else if (idx == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
322 fprintf (m_outfile, " D#%i",
323 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
325 else if (idx == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
327 m_indent += 2;
328 if (!m_sawclose)
329 fprintf (m_outfile, " ");
330 print_rtx (ENTRY_VALUE_EXP (in_rtx));
331 m_indent -= 2;
333 #endif
336 /* Subroutine of print_rtx_operand for handling code 'e'.
337 Also called by print_rtx_operand_code_u for handling code 'u'
338 for LABEL_REFs when they don't reference a CODE_LABEL. */
340 void
341 rtx_writer::print_rtx_operand_code_e (const_rtx in_rtx, int idx)
343 m_indent += 2;
344 if (idx == 6 && INSN_P (in_rtx))
345 /* Put REG_NOTES on their own line. */
346 fprintf (m_outfile, "\n%s%*s",
347 print_rtx_head, m_indent * 2, "");
348 if (!m_sawclose)
349 fprintf (m_outfile, " ");
350 if (idx == 7 && CALL_P (in_rtx))
352 m_in_call_function_usage = true;
353 print_rtx (XEXP (in_rtx, idx));
354 m_in_call_function_usage = false;
356 else
357 print_rtx (XEXP (in_rtx, idx));
358 m_indent -= 2;
361 /* Subroutine of print_rtx_operand for handling codes 'E' and 'V'. */
363 void
364 rtx_writer::print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx)
366 m_indent += 2;
367 if (m_sawclose)
369 fprintf (m_outfile, "\n%s%*s",
370 print_rtx_head, m_indent * 2, "");
371 m_sawclose = 0;
373 fputs (" [", m_outfile);
374 if (XVEC (in_rtx, idx) != NULL)
376 m_indent += 2;
377 if (XVECLEN (in_rtx, idx))
378 m_sawclose = 1;
380 for (int j = 0; j < XVECLEN (in_rtx, idx); j++)
382 int j1;
384 print_rtx (XVECEXP (in_rtx, idx, j));
385 for (j1 = j + 1; j1 < XVECLEN (in_rtx, idx); j1++)
386 if (XVECEXP (in_rtx, idx, j) != XVECEXP (in_rtx, idx, j1))
387 break;
389 if (j1 != j + 1)
391 fprintf (m_outfile, " repeated x%i", j1 - j);
392 j = j1 - 1;
396 m_indent -= 2;
398 if (m_sawclose)
399 fprintf (m_outfile, "\n%s%*s", print_rtx_head, m_indent * 2, "");
401 fputs ("]", m_outfile);
402 m_sawclose = 1;
403 m_indent -= 2;
406 /* Subroutine of print_rtx_operand for handling code 'i'. */
408 void
409 rtx_writer::print_rtx_operand_code_i (const_rtx in_rtx, int idx)
411 if (idx == 4 && INSN_P (in_rtx))
413 #ifndef GENERATOR_FILE
414 const rtx_insn *in_insn = as_a <const rtx_insn *> (in_rtx);
416 /* Pretty-print insn locations. Ignore scoping as it is mostly
417 redundant with line number information and do not print anything
418 when there is no location information available. */
419 if (INSN_HAS_LOCATION (in_insn))
421 expanded_location xloc = insn_location (in_insn);
422 fprintf (m_outfile, " \"%s\":%i:%i", xloc.file, xloc.line,
423 xloc.column);
425 #endif
427 else if (idx == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
429 #ifndef GENERATOR_FILE
430 if (ASM_OPERANDS_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
431 fprintf (m_outfile, " %s:%i",
432 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
433 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
434 #endif
436 else if (idx == 1 && GET_CODE (in_rtx) == ASM_INPUT)
438 #ifndef GENERATOR_FILE
439 if (ASM_INPUT_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
440 fprintf (m_outfile, " %s:%i",
441 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
442 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
443 #endif
445 else if (idx == 5 && NOTE_P (in_rtx))
447 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
448 other times often contains garbage from INSN->NOTE death. */
449 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL
450 || NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_DEBUG_LABEL)
451 fprintf (m_outfile, " %d", XINT (in_rtx, idx));
453 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
454 else if (idx == 1
455 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
456 && XINT (in_rtx, 1) >= 0
457 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
458 fprintf (m_outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
459 #endif
460 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
461 else if (idx == 1
462 && (GET_CODE (in_rtx) == UNSPEC
463 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
464 && XINT (in_rtx, 1) >= 0
465 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
466 fprintf (m_outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
467 #endif
468 else
470 int value = XINT (in_rtx, idx);
471 const char *name;
472 int is_insn = INSN_P (in_rtx);
474 /* Don't print INSN_CODEs in compact mode. */
475 if (m_compact && is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, idx))
477 m_sawclose = 0;
478 return;
481 if (flag_dump_unnumbered
482 && (is_insn || NOTE_P (in_rtx)))
483 fputc ('#', m_outfile);
484 else
485 fprintf (m_outfile, " %d", value);
487 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, idx)
488 && XINT (in_rtx, idx) >= 0
489 && (name = get_insn_name (XINT (in_rtx, idx))) != NULL)
490 fprintf (m_outfile, " {%s}", name);
491 m_sawclose = 0;
495 /* Subroutine of print_rtx_operand for handling code 'r'. */
497 void
498 rtx_writer::print_rtx_operand_code_r (const_rtx in_rtx)
500 int is_insn = INSN_P (in_rtx);
501 unsigned int regno = REGNO (in_rtx);
503 #ifndef GENERATOR_FILE
504 /* For hard registers and virtuals, always print the
505 regno, except in compact mode. */
506 if (regno <= LAST_VIRTUAL_REGISTER && !m_compact)
507 fprintf (m_outfile, " %d", regno);
508 if (regno < FIRST_PSEUDO_REGISTER)
509 fprintf (m_outfile, " %s", reg_names[regno]);
510 else if (regno <= LAST_VIRTUAL_REGISTER)
512 if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
513 fprintf (m_outfile, " virtual-incoming-args");
514 else if (regno == VIRTUAL_STACK_VARS_REGNUM)
515 fprintf (m_outfile, " virtual-stack-vars");
516 else if (regno == VIRTUAL_STACK_DYNAMIC_REGNUM)
517 fprintf (m_outfile, " virtual-stack-dynamic");
518 else if (regno == VIRTUAL_OUTGOING_ARGS_REGNUM)
519 fprintf (m_outfile, " virtual-outgoing-args");
520 else if (regno == VIRTUAL_CFA_REGNUM)
521 fprintf (m_outfile, " virtual-cfa");
522 else if (regno == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
523 fprintf (m_outfile, " virtual-preferred-stack-boundary");
524 else
525 fprintf (m_outfile, " virtual-reg-%d", regno-FIRST_VIRTUAL_REGISTER);
527 else
528 #endif
529 if (flag_dump_unnumbered && is_insn)
530 fputc ('#', m_outfile);
531 else if (m_compact)
533 /* In compact mode, print pseudos with '< and '>' wrapping the regno,
534 offseting it by (LAST_VIRTUAL_REGISTER + 1), so that the
535 first non-virtual pseudo is dumped as "<0>". */
536 gcc_assert (regno > LAST_VIRTUAL_REGISTER);
537 fprintf (m_outfile, " <%d>", regno - (LAST_VIRTUAL_REGISTER + 1));
539 else
540 fprintf (m_outfile, " %d", regno);
542 #ifndef GENERATOR_FILE
543 if (REG_ATTRS (in_rtx))
545 fputs (" [", m_outfile);
546 if (regno != ORIGINAL_REGNO (in_rtx))
547 fprintf (m_outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
548 if (REG_EXPR (in_rtx))
549 print_mem_expr (m_outfile, REG_EXPR (in_rtx));
551 if (maybe_ne (REG_OFFSET (in_rtx), 0))
553 fprintf (m_outfile, "+");
554 print_poly_int (m_outfile, REG_OFFSET (in_rtx));
556 fputs (" ]", m_outfile);
558 if (regno != ORIGINAL_REGNO (in_rtx))
559 fprintf (m_outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
560 #endif
563 /* Subroutine of print_rtx_operand for handling code 'u'. */
565 void
566 rtx_writer::print_rtx_operand_code_u (const_rtx in_rtx, int idx)
568 /* Don't print insn UIDs for PREV/NEXT_INSN in compact mode. */
569 if (m_compact && INSN_CHAIN_CODE_P (GET_CODE (in_rtx)) && idx < 2)
570 return;
572 if (XEXP (in_rtx, idx) != NULL)
574 rtx sub = XEXP (in_rtx, idx);
575 enum rtx_code subc = GET_CODE (sub);
577 if (GET_CODE (in_rtx) == LABEL_REF)
579 if (subc == NOTE
580 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
582 if (flag_dump_unnumbered)
583 fprintf (m_outfile, " [# deleted]");
584 else
585 fprintf (m_outfile, " [%d deleted]", INSN_UID (sub));
586 m_sawclose = 0;
587 return;
590 if (subc != CODE_LABEL)
592 print_rtx_operand_code_e (in_rtx, idx);
593 return;
597 if (flag_dump_unnumbered
598 || (flag_dump_unnumbered_links && idx <= 1
599 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
600 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
601 fputs (" #", m_outfile);
602 else
603 fprintf (m_outfile, " %d", INSN_UID (sub));
605 else
606 fputs (" 0", m_outfile);
607 m_sawclose = 0;
610 /* Subroutine of print_rtx. Print operand IDX of IN_RTX. */
612 void
613 rtx_writer::print_rtx_operand (const_rtx in_rtx, int idx)
615 const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
617 switch (format_ptr[idx])
619 const char *str;
621 case 'T':
622 str = XTMPL (in_rtx, idx);
623 goto string;
625 case 'S':
626 case 's':
627 str = XSTR (in_rtx, idx);
628 string:
630 if (str == 0)
631 fputs (" (nil)", m_outfile);
632 else
633 fprintf (m_outfile, " (\"%s\")", str);
634 m_sawclose = 1;
635 break;
637 case '0':
638 print_rtx_operand_code_0 (in_rtx, idx);
639 break;
641 case 'e':
642 print_rtx_operand_code_e (in_rtx, idx);
643 break;
645 case 'E':
646 case 'V':
647 print_rtx_operand_codes_E_and_V (in_rtx, idx);
648 break;
650 case 'w':
651 if (! m_simple)
652 fprintf (m_outfile, " ");
653 fprintf (m_outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, idx));
654 if (! m_simple && !m_compact)
655 fprintf (m_outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
656 (unsigned HOST_WIDE_INT) XWINT (in_rtx, idx));
657 break;
659 case 'i':
660 print_rtx_operand_code_i (in_rtx, idx);
661 break;
663 case 'p':
664 fprintf (m_outfile, " ");
665 print_poly_int (m_outfile, SUBREG_BYTE (in_rtx));
666 break;
668 case 'r':
669 print_rtx_operand_code_r (in_rtx);
670 break;
672 /* Print NOTE_INSN names rather than integer codes. */
674 case 'n':
675 fprintf (m_outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, idx)));
676 m_sawclose = 0;
677 break;
679 case 'u':
680 print_rtx_operand_code_u (in_rtx, idx);
681 break;
683 case 't':
684 #ifndef GENERATOR_FILE
685 if (idx == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
686 print_mem_expr (m_outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
687 else if (idx == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
688 print_mem_expr (m_outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
689 else
690 dump_addr (m_outfile, " ", XTREE (in_rtx, idx));
691 #endif
692 break;
694 case '*':
695 fputs (" Unknown", m_outfile);
696 m_sawclose = 0;
697 break;
699 case 'B':
700 /* Don't print basic block ids in compact mode. */
701 if (m_compact)
702 break;
703 #ifndef GENERATOR_FILE
704 if (XBBDEF (in_rtx, idx))
705 fprintf (m_outfile, " %i", XBBDEF (in_rtx, idx)->index);
706 #endif
707 break;
709 default:
710 gcc_unreachable ();
714 /* Subroutine of rtx_writer::print_rtx.
715 In compact mode, determine if operand IDX of IN_RTX is interesting
716 to dump, or (if in a trailing position) it can be omitted. */
718 bool
719 rtx_writer::operand_has_default_value_p (const_rtx in_rtx, int idx)
721 const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
723 switch (format_ptr[idx])
725 case 'e':
726 case 'u':
727 return XEXP (in_rtx, idx) == NULL_RTX;
729 case 's':
730 return XSTR (in_rtx, idx) == NULL;
732 case '0':
733 switch (GET_CODE (in_rtx))
735 case JUMP_INSN:
736 /* JUMP_LABELs are always omitted in compact mode, so treat
737 any value here as omittable, so that earlier operands can
738 potentially be omitted also. */
739 return m_compact;
741 default:
742 return false;
746 default:
747 return false;
751 /* Print IN_RTX onto m_outfile. This is the recursive part of printing. */
753 void
754 rtx_writer::print_rtx (const_rtx in_rtx)
756 int idx = 0;
758 if (m_sawclose)
760 if (m_simple)
761 fputc (' ', m_outfile);
762 else
763 fprintf (m_outfile, "\n%s%*s", print_rtx_head, m_indent * 2, "");
764 m_sawclose = 0;
767 if (in_rtx == 0)
769 fputs ("(nil)", m_outfile);
770 m_sawclose = 1;
771 return;
773 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
775 fprintf (m_outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
776 print_rtx_head, m_indent * 2, "");
777 m_sawclose = 1;
778 return;
781 fputc ('(', m_outfile);
783 /* Print name of expression code. */
785 /* Handle reuse. */
786 #ifndef GENERATOR_FILE
787 if (m_rtx_reuse_manager)
789 int reuse_id;
790 if (m_rtx_reuse_manager->has_reuse_id (in_rtx, &reuse_id))
792 /* Have we already seen the defn of this rtx? */
793 if (m_rtx_reuse_manager->seen_def_p (reuse_id))
795 fprintf (m_outfile, "reuse_rtx %i)", reuse_id);
796 m_sawclose = 1;
797 return;
799 else
801 /* First time we've seen this reused-rtx. */
802 fprintf (m_outfile, "%i|", reuse_id);
803 m_rtx_reuse_manager->set_seen_def (reuse_id);
807 #endif /* #ifndef GENERATOR_FILE */
809 /* In compact mode, prefix the code of insns with "c",
810 giving "cinsn", "cnote" etc. */
811 if (m_compact && is_a <const rtx_insn *, const struct rtx_def> (in_rtx))
813 /* "ccode_label" is slightly awkward, so special-case it as
814 just "clabel". */
815 rtx_code code = GET_CODE (in_rtx);
816 if (code == CODE_LABEL)
817 fprintf (m_outfile, "clabel");
818 else
819 fprintf (m_outfile, "c%s", GET_RTX_NAME (code));
821 else if (m_simple && CONST_INT_P (in_rtx))
822 ; /* no code. */
823 else
824 fprintf (m_outfile, "%s", GET_RTX_NAME (GET_CODE (in_rtx)));
826 if (! m_simple)
828 if (RTX_FLAG (in_rtx, in_struct))
829 fputs ("/s", m_outfile);
831 if (RTX_FLAG (in_rtx, volatil))
832 fputs ("/v", m_outfile);
834 if (RTX_FLAG (in_rtx, unchanging))
835 fputs ("/u", m_outfile);
837 if (RTX_FLAG (in_rtx, frame_related))
838 fputs ("/f", m_outfile);
840 if (RTX_FLAG (in_rtx, jump))
841 fputs ("/j", m_outfile);
843 if (RTX_FLAG (in_rtx, call))
844 fputs ("/c", m_outfile);
846 if (RTX_FLAG (in_rtx, return_val))
847 fputs ("/i", m_outfile);
849 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
850 if ((GET_CODE (in_rtx) == EXPR_LIST
851 || GET_CODE (in_rtx) == INSN_LIST
852 || GET_CODE (in_rtx) == INT_LIST)
853 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX
854 && !m_in_call_function_usage)
855 fprintf (m_outfile, ":%s",
856 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
858 /* For other rtl, print the mode if it's not VOID. */
859 else if (GET_MODE (in_rtx) != VOIDmode)
860 fprintf (m_outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
862 #ifndef GENERATOR_FILE
863 if (GET_CODE (in_rtx) == VAR_LOCATION)
865 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
866 fputs (" <debug string placeholder>", m_outfile);
867 else
868 print_mem_expr (m_outfile, PAT_VAR_LOCATION_DECL (in_rtx));
869 fputc (' ', m_outfile);
870 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
871 if (PAT_VAR_LOCATION_STATUS (in_rtx)
872 == VAR_INIT_STATUS_UNINITIALIZED)
873 fprintf (m_outfile, " [uninit]");
874 m_sawclose = 1;
875 idx = GET_RTX_LENGTH (VAR_LOCATION);
877 #endif
880 #ifndef GENERATOR_FILE
881 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx))
882 idx = 5;
883 #endif
885 /* For insns, print the INSN_UID. */
886 if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx)))
888 if (flag_dump_unnumbered)
889 fprintf (m_outfile, " #");
890 else
891 fprintf (m_outfile, " %d", INSN_UID (in_rtx));
894 /* Determine which is the final operand to print.
895 In compact mode, skip trailing operands that have the default values
896 e.g. trailing "(nil)" values. */
897 int limit = GET_RTX_LENGTH (GET_CODE (in_rtx));
898 if (m_compact)
899 while (limit > idx && operand_has_default_value_p (in_rtx, limit - 1))
900 limit--;
902 /* Get the format string and skip the first elements if we have handled
903 them already. */
905 for (; idx < limit; idx++)
906 print_rtx_operand (in_rtx, idx);
908 switch (GET_CODE (in_rtx))
910 #ifndef GENERATOR_FILE
911 case MEM:
912 if (__builtin_expect (final_insns_dump_p, false))
913 fprintf (m_outfile, " [");
914 else
915 fprintf (m_outfile, " [" HOST_WIDE_INT_PRINT_DEC,
916 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
918 if (MEM_EXPR (in_rtx))
919 print_mem_expr (m_outfile, MEM_EXPR (in_rtx));
920 else
921 fputc (' ', m_outfile);
923 if (MEM_OFFSET_KNOWN_P (in_rtx))
925 fprintf (m_outfile, "+");
926 print_poly_int (m_outfile, MEM_OFFSET (in_rtx));
929 if (MEM_SIZE_KNOWN_P (in_rtx))
931 fprintf (m_outfile, " S");
932 print_poly_int (m_outfile, MEM_SIZE (in_rtx));
935 if (MEM_ALIGN (in_rtx) != 1)
936 fprintf (m_outfile, " A%u", MEM_ALIGN (in_rtx));
938 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
939 fprintf (m_outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
941 fputc (']', m_outfile);
942 break;
944 case CONST_DOUBLE:
945 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
947 char s[60];
949 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
950 sizeof (s), 0, 1);
951 fprintf (m_outfile, " %s", s);
953 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
954 sizeof (s), 0, 1);
955 fprintf (m_outfile, " [%s]", s);
957 break;
959 case CONST_WIDE_INT:
960 fprintf (m_outfile, " ");
961 cwi_output_hex (m_outfile, in_rtx);
962 break;
964 case CONST_POLY_INT:
965 fprintf (m_outfile, " [");
966 print_dec (CONST_POLY_INT_COEFFS (in_rtx)[0], m_outfile, SIGNED);
967 for (unsigned int i = 1; i < NUM_POLY_INT_COEFFS; ++i)
969 fprintf (m_outfile, ", ");
970 print_dec (CONST_POLY_INT_COEFFS (in_rtx)[i], m_outfile, SIGNED);
972 fprintf (m_outfile, "]");
973 break;
974 #endif
976 case CODE_LABEL:
977 if (!m_compact)
978 fprintf (m_outfile, " [%d uses]", LABEL_NUSES (in_rtx));
979 switch (LABEL_KIND (in_rtx))
981 case LABEL_NORMAL: break;
982 case LABEL_STATIC_ENTRY: fputs (" [entry]", m_outfile); break;
983 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", m_outfile); break;
984 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", m_outfile); break;
985 default: gcc_unreachable ();
987 break;
989 default:
990 break;
993 fputc (')', m_outfile);
994 m_sawclose = 1;
997 /* Emit a closing parenthesis and newline. */
999 void
1000 rtx_writer::finish_directive ()
1002 fprintf (m_outfile, ")\n");
1003 m_sawclose = 0;
1006 /* Print an rtx on the current line of FILE. Initially indent IND
1007 characters. */
1009 void
1010 print_inline_rtx (FILE *outf, const_rtx x, int ind)
1012 rtx_writer w (outf, ind, false, false, NULL);
1013 w.print_rtx (x);
1016 /* Call this function from the debugger to see what X looks like. */
1018 DEBUG_FUNCTION void
1019 debug_rtx (const_rtx x)
1021 rtx_writer w (stderr, 0, false, false, NULL);
1022 w.print_rtx (x);
1023 fprintf (stderr, "\n");
1026 /* Dump rtx REF. */
1028 DEBUG_FUNCTION void
1029 debug (const rtx_def &ref)
1031 debug_rtx (&ref);
1034 DEBUG_FUNCTION void
1035 debug (const rtx_def *ptr)
1037 if (ptr)
1038 debug (*ptr);
1039 else
1040 fprintf (stderr, "<nil>\n");
1043 /* Like debug_rtx but with no newline, as debug_helper will add one.
1045 Note: No debug_slim(rtx_insn *) variant implemented, as this
1046 function can serve for both rtx and rtx_insn. */
1048 static void
1049 debug_slim (const_rtx x)
1051 rtx_writer w (stderr, 0, false, false, NULL);
1052 w.print_rtx (x);
1055 DEFINE_DEBUG_VEC (rtx_def *)
1056 DEFINE_DEBUG_VEC (rtx_insn *)
1057 DEFINE_DEBUG_HASH_SET (rtx_def *)
1058 DEFINE_DEBUG_HASH_SET (rtx_insn *)
1060 /* Count of rtx's to print with debug_rtx_list.
1061 This global exists because gdb user defined commands have no arguments. */
1063 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
1065 /* Call this function to print list from X on.
1067 N is a count of the rtx's to print. Positive values print from the specified
1068 rtx_insn on. Negative values print a window around the rtx_insn.
1069 EG: -5 prints 2 rtx_insn's on either side (in addition to the specified
1070 rtx_insn). */
1072 DEBUG_FUNCTION void
1073 debug_rtx_list (const rtx_insn *x, int n)
1075 int i,count;
1076 const rtx_insn *insn;
1078 count = n == 0 ? 1 : n < 0 ? -n : n;
1080 /* If we are printing a window, back up to the start. */
1082 if (n < 0)
1083 for (i = count / 2; i > 0; i--)
1085 if (PREV_INSN (x) == 0)
1086 break;
1087 x = PREV_INSN (x);
1090 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
1092 debug_rtx (insn);
1093 fprintf (stderr, "\n");
1097 /* Call this function to print an rtx_insn list from START to END
1098 inclusive. */
1100 DEBUG_FUNCTION void
1101 debug_rtx_range (const rtx_insn *start, const rtx_insn *end)
1103 while (1)
1105 debug_rtx (start);
1106 fprintf (stderr, "\n");
1107 if (!start || start == end)
1108 break;
1109 start = NEXT_INSN (start);
1113 /* Call this function to search an rtx_insn list to find one with insn uid UID,
1114 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
1115 The found insn is returned to enable further debugging analysis. */
1117 DEBUG_FUNCTION const rtx_insn *
1118 debug_rtx_find (const rtx_insn *x, int uid)
1120 while (x != 0 && INSN_UID (x) != uid)
1121 x = NEXT_INSN (x);
1122 if (x != 0)
1124 debug_rtx_list (x, debug_rtx_count);
1125 return x;
1127 else
1129 fprintf (stderr, "insn uid %d not found\n", uid);
1130 return 0;
1134 /* External entry point for printing a chain of insns
1135 starting with RTX_FIRST.
1136 A blank line separates insns.
1138 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
1140 void
1141 rtx_writer::print_rtl (const_rtx rtx_first)
1143 const rtx_insn *tmp_rtx;
1145 if (rtx_first == 0)
1147 fputs (print_rtx_head, m_outfile);
1148 fputs ("(nil)\n", m_outfile);
1150 else
1151 switch (GET_CODE (rtx_first))
1153 case INSN:
1154 case JUMP_INSN:
1155 case CALL_INSN:
1156 case NOTE:
1157 case CODE_LABEL:
1158 case JUMP_TABLE_DATA:
1159 case BARRIER:
1160 for (tmp_rtx = as_a <const rtx_insn *> (rtx_first);
1161 tmp_rtx != 0;
1162 tmp_rtx = NEXT_INSN (tmp_rtx))
1164 fputs (print_rtx_head, m_outfile);
1165 print_rtx (tmp_rtx);
1166 fprintf (m_outfile, "\n");
1168 break;
1170 default:
1171 fputs (print_rtx_head, m_outfile);
1172 print_rtx (rtx_first);
1176 /* External entry point for printing a chain of insns
1177 starting with RTX_FIRST onto file OUTF.
1178 A blank line separates insns.
1180 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
1182 void
1183 print_rtl (FILE *outf, const_rtx rtx_first)
1185 rtx_writer w (outf, 0, false, false, NULL);
1186 w.print_rtl (rtx_first);
1189 /* Like print_rtx, except specify a file. */
1190 /* Return nonzero if we actually printed anything. */
1193 print_rtl_single (FILE *outf, const_rtx x)
1195 rtx_writer w (outf, 0, false, false, NULL);
1196 return w.print_rtl_single_with_indent (x, 0);
1199 /* Like print_rtl_single, except specify an indentation. */
1202 rtx_writer::print_rtl_single_with_indent (const_rtx x, int ind)
1204 char *s_indent = (char *) alloca ((size_t) ind + 1);
1205 memset ((void *) s_indent, ' ', (size_t) ind);
1206 s_indent[ind] = '\0';
1207 fputs (s_indent, m_outfile);
1208 fputs (print_rtx_head, m_outfile);
1210 int old_indent = m_indent;
1211 m_indent = ind;
1212 m_sawclose = 0;
1213 print_rtx (x);
1214 putc ('\n', m_outfile);
1215 m_indent = old_indent;
1216 return 1;
1220 /* Like print_rtl except without all the detail; for example,
1221 if RTX is a CONST_INT then print in decimal format. */
1223 void
1224 print_simple_rtl (FILE *outf, const_rtx x)
1226 rtx_writer w (outf, 0, true, false, NULL);
1227 w.print_rtl (x);
1230 /* Print the elements of VEC to FILE. */
1232 void
1233 print_rtx_insn_vec (FILE *file, const vec<rtx_insn *> &vec)
1235 fputc('{', file);
1237 unsigned int len = vec.length ();
1238 for (unsigned int i = 0; i < len; i++)
1240 print_rtl (file, vec[i]);
1241 if (i < len - 1)
1242 fputs (", ", file);
1245 fputc ('}', file);
1248 #ifndef GENERATOR_FILE
1249 /* The functions below try to print RTL in a form resembling assembler
1250 mnemonics. Because this form is more concise than the "traditional" form
1251 of RTL printing in Lisp-style, the form printed by this file is called
1252 "slim". RTL dumps in slim format can be obtained by appending the "-slim"
1253 option to -fdump-rtl-<pass>. Control flow graph output as a DOT file is
1254 always printed in slim form.
1256 The normal interface to the functionality provided in this pretty-printer
1257 is through the dump_*_slim functions to print to a stream, or via the
1258 print_*_slim functions to print into a user's pretty-printer.
1260 It is also possible to obtain a string for a single pattern as a string
1261 pointer, via str_pattern_slim, but this usage is discouraged. */
1263 /* This recognizes rtx'en classified as expressions. These are always
1264 represent some action on values or results of other expression, that
1265 may be stored in objects representing values. */
1267 static void
1268 print_exp (pretty_printer *pp, const_rtx x, int verbose)
1270 const char *st[4];
1271 const char *fun;
1272 rtx op[4];
1273 int i;
1275 fun = (char *) 0;
1276 for (i = 0; i < 4; i++)
1278 st[i] = (char *) 0;
1279 op[i] = NULL_RTX;
1282 switch (GET_CODE (x))
1284 case PLUS:
1285 op[0] = XEXP (x, 0);
1286 if (CONST_INT_P (XEXP (x, 1))
1287 && INTVAL (XEXP (x, 1)) < 0)
1289 st[1] = "-";
1290 op[1] = GEN_INT (-INTVAL (XEXP (x, 1)));
1292 else
1294 st[1] = "+";
1295 op[1] = XEXP (x, 1);
1297 break;
1298 case LO_SUM:
1299 op[0] = XEXP (x, 0);
1300 st[1] = "+low(";
1301 op[1] = XEXP (x, 1);
1302 st[2] = ")";
1303 break;
1304 case MINUS:
1305 op[0] = XEXP (x, 0);
1306 st[1] = "-";
1307 op[1] = XEXP (x, 1);
1308 break;
1309 case COMPARE:
1310 fun = "cmp";
1311 op[0] = XEXP (x, 0);
1312 op[1] = XEXP (x, 1);
1313 break;
1314 case NEG:
1315 st[0] = "-";
1316 op[0] = XEXP (x, 0);
1317 break;
1318 case FMA:
1319 st[0] = "{";
1320 op[0] = XEXP (x, 0);
1321 st[1] = "*";
1322 op[1] = XEXP (x, 1);
1323 st[2] = "+";
1324 op[2] = XEXP (x, 2);
1325 st[3] = "}";
1326 break;
1327 case MULT:
1328 op[0] = XEXP (x, 0);
1329 st[1] = "*";
1330 op[1] = XEXP (x, 1);
1331 break;
1332 case DIV:
1333 op[0] = XEXP (x, 0);
1334 st[1] = "/";
1335 op[1] = XEXP (x, 1);
1336 break;
1337 case UDIV:
1338 fun = "udiv";
1339 op[0] = XEXP (x, 0);
1340 op[1] = XEXP (x, 1);
1341 break;
1342 case MOD:
1343 op[0] = XEXP (x, 0);
1344 st[1] = "%";
1345 op[1] = XEXP (x, 1);
1346 break;
1347 case UMOD:
1348 fun = "umod";
1349 op[0] = XEXP (x, 0);
1350 op[1] = XEXP (x, 1);
1351 break;
1352 case SMIN:
1353 fun = "smin";
1354 op[0] = XEXP (x, 0);
1355 op[1] = XEXP (x, 1);
1356 break;
1357 case SMAX:
1358 fun = "smax";
1359 op[0] = XEXP (x, 0);
1360 op[1] = XEXP (x, 1);
1361 break;
1362 case UMIN:
1363 fun = "umin";
1364 op[0] = XEXP (x, 0);
1365 op[1] = XEXP (x, 1);
1366 break;
1367 case UMAX:
1368 fun = "umax";
1369 op[0] = XEXP (x, 0);
1370 op[1] = XEXP (x, 1);
1371 break;
1372 case NOT:
1373 st[0] = "~";
1374 op[0] = XEXP (x, 0);
1375 break;
1376 case AND:
1377 op[0] = XEXP (x, 0);
1378 st[1] = "&";
1379 op[1] = XEXP (x, 1);
1380 break;
1381 case IOR:
1382 op[0] = XEXP (x, 0);
1383 st[1] = "|";
1384 op[1] = XEXP (x, 1);
1385 break;
1386 case XOR:
1387 op[0] = XEXP (x, 0);
1388 st[1] = "^";
1389 op[1] = XEXP (x, 1);
1390 break;
1391 case ASHIFT:
1392 op[0] = XEXP (x, 0);
1393 st[1] = "<<";
1394 op[1] = XEXP (x, 1);
1395 break;
1396 case LSHIFTRT:
1397 op[0] = XEXP (x, 0);
1398 st[1] = " 0>>";
1399 op[1] = XEXP (x, 1);
1400 break;
1401 case ASHIFTRT:
1402 op[0] = XEXP (x, 0);
1403 st[1] = ">>";
1404 op[1] = XEXP (x, 1);
1405 break;
1406 case ROTATE:
1407 op[0] = XEXP (x, 0);
1408 st[1] = "<-<";
1409 op[1] = XEXP (x, 1);
1410 break;
1411 case ROTATERT:
1412 op[0] = XEXP (x, 0);
1413 st[1] = ">->";
1414 op[1] = XEXP (x, 1);
1415 break;
1416 case NE:
1417 op[0] = XEXP (x, 0);
1418 st[1] = "!=";
1419 op[1] = XEXP (x, 1);
1420 break;
1421 case EQ:
1422 op[0] = XEXP (x, 0);
1423 st[1] = "==";
1424 op[1] = XEXP (x, 1);
1425 break;
1426 case GE:
1427 op[0] = XEXP (x, 0);
1428 st[1] = ">=";
1429 op[1] = XEXP (x, 1);
1430 break;
1431 case GT:
1432 op[0] = XEXP (x, 0);
1433 st[1] = ">";
1434 op[1] = XEXP (x, 1);
1435 break;
1436 case LE:
1437 op[0] = XEXP (x, 0);
1438 st[1] = "<=";
1439 op[1] = XEXP (x, 1);
1440 break;
1441 case LT:
1442 op[0] = XEXP (x, 0);
1443 st[1] = "<";
1444 op[1] = XEXP (x, 1);
1445 break;
1446 case SIGN_EXTRACT:
1447 fun = (verbose) ? "sign_extract" : "sxt";
1448 op[0] = XEXP (x, 0);
1449 op[1] = XEXP (x, 1);
1450 op[2] = XEXP (x, 2);
1451 break;
1452 case ZERO_EXTRACT:
1453 fun = (verbose) ? "zero_extract" : "zxt";
1454 op[0] = XEXP (x, 0);
1455 op[1] = XEXP (x, 1);
1456 op[2] = XEXP (x, 2);
1457 break;
1458 case SIGN_EXTEND:
1459 fun = (verbose) ? "sign_extend" : "sxn";
1460 op[0] = XEXP (x, 0);
1461 break;
1462 case ZERO_EXTEND:
1463 fun = (verbose) ? "zero_extend" : "zxn";
1464 op[0] = XEXP (x, 0);
1465 break;
1466 case FLOAT_EXTEND:
1467 fun = (verbose) ? "float_extend" : "fxn";
1468 op[0] = XEXP (x, 0);
1469 break;
1470 case TRUNCATE:
1471 fun = (verbose) ? "trunc" : "trn";
1472 op[0] = XEXP (x, 0);
1473 break;
1474 case FLOAT_TRUNCATE:
1475 fun = (verbose) ? "float_trunc" : "ftr";
1476 op[0] = XEXP (x, 0);
1477 break;
1478 case FLOAT:
1479 fun = (verbose) ? "float" : "flt";
1480 op[0] = XEXP (x, 0);
1481 break;
1482 case UNSIGNED_FLOAT:
1483 fun = (verbose) ? "uns_float" : "ufl";
1484 op[0] = XEXP (x, 0);
1485 break;
1486 case FIX:
1487 fun = "fix";
1488 op[0] = XEXP (x, 0);
1489 break;
1490 case UNSIGNED_FIX:
1491 fun = (verbose) ? "uns_fix" : "ufx";
1492 op[0] = XEXP (x, 0);
1493 break;
1494 case PRE_DEC:
1495 st[0] = "--";
1496 op[0] = XEXP (x, 0);
1497 break;
1498 case PRE_INC:
1499 st[0] = "++";
1500 op[0] = XEXP (x, 0);
1501 break;
1502 case POST_DEC:
1503 op[0] = XEXP (x, 0);
1504 st[1] = "--";
1505 break;
1506 case POST_INC:
1507 op[0] = XEXP (x, 0);
1508 st[1] = "++";
1509 break;
1510 case PRE_MODIFY:
1511 st[0] = "pre ";
1512 op[0] = XEXP (XEXP (x, 1), 0);
1513 st[1] = "+=";
1514 op[1] = XEXP (XEXP (x, 1), 1);
1515 break;
1516 case POST_MODIFY:
1517 st[0] = "post ";
1518 op[0] = XEXP (XEXP (x, 1), 0);
1519 st[1] = "+=";
1520 op[1] = XEXP (XEXP (x, 1), 1);
1521 break;
1522 case CALL:
1523 st[0] = "call ";
1524 op[0] = XEXP (x, 0);
1525 if (verbose)
1527 st[1] = " argc:";
1528 op[1] = XEXP (x, 1);
1530 break;
1531 case IF_THEN_ELSE:
1532 st[0] = "{(";
1533 op[0] = XEXP (x, 0);
1534 st[1] = ")?";
1535 op[1] = XEXP (x, 1);
1536 st[2] = ":";
1537 op[2] = XEXP (x, 2);
1538 st[3] = "}";
1539 break;
1540 case TRAP_IF:
1541 fun = "trap_if";
1542 op[0] = TRAP_CONDITION (x);
1543 break;
1544 case PREFETCH:
1545 fun = "prefetch";
1546 op[0] = XEXP (x, 0);
1547 op[1] = XEXP (x, 1);
1548 op[2] = XEXP (x, 2);
1549 break;
1550 case UNSPEC:
1551 case UNSPEC_VOLATILE:
1553 pp_string (pp, "unspec");
1554 if (GET_CODE (x) == UNSPEC_VOLATILE)
1555 pp_string (pp, "/v");
1556 pp_left_bracket (pp);
1557 for (i = 0; i < XVECLEN (x, 0); i++)
1559 if (i != 0)
1560 pp_comma (pp);
1561 print_pattern (pp, XVECEXP (x, 0, i), verbose);
1563 pp_string (pp, "] ");
1564 pp_decimal_int (pp, XINT (x, 1));
1566 break;
1567 default:
1569 /* Most unhandled codes can be printed as pseudo-functions. */
1570 if (GET_RTX_CLASS (GET_CODE (x)) == RTX_UNARY)
1572 fun = GET_RTX_NAME (GET_CODE (x));
1573 op[0] = XEXP (x, 0);
1575 else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_COMPARE
1576 || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_COMPARE
1577 || GET_RTX_CLASS (GET_CODE (x)) == RTX_BIN_ARITH
1578 || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_ARITH)
1580 fun = GET_RTX_NAME (GET_CODE (x));
1581 op[0] = XEXP (x, 0);
1582 op[1] = XEXP (x, 1);
1584 else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_TERNARY)
1586 fun = GET_RTX_NAME (GET_CODE (x));
1587 op[0] = XEXP (x, 0);
1588 op[1] = XEXP (x, 1);
1589 op[2] = XEXP (x, 2);
1591 else
1592 /* Give up, just print the RTX name. */
1593 st[0] = GET_RTX_NAME (GET_CODE (x));
1595 break;
1598 /* Print this as a function? */
1599 if (fun)
1601 pp_string (pp, fun);
1602 pp_left_paren (pp);
1605 for (i = 0; i < 4; i++)
1607 if (st[i])
1608 pp_string (pp, st[i]);
1610 if (op[i])
1612 if (fun && i != 0)
1613 pp_comma (pp);
1614 print_value (pp, op[i], verbose);
1618 if (fun)
1619 pp_right_paren (pp);
1620 } /* print_exp */
1622 /* Prints rtxes, I customarily classified as values. They're constants,
1623 registers, labels, symbols and memory accesses. */
1625 void
1626 print_value (pretty_printer *pp, const_rtx x, int verbose)
1628 char tmp[1024];
1630 if (!x)
1632 pp_string (pp, "(nil)");
1633 return;
1635 switch (GET_CODE (x))
1637 case CONST_INT:
1638 pp_scalar (pp, HOST_WIDE_INT_PRINT_HEX,
1639 (unsigned HOST_WIDE_INT) INTVAL (x));
1640 break;
1642 case CONST_WIDE_INT:
1644 const char *sep = "<";
1645 int i;
1646 for (i = CONST_WIDE_INT_NUNITS (x) - 1; i >= 0; i--)
1648 pp_string (pp, sep);
1649 sep = ",";
1650 sprintf (tmp, HOST_WIDE_INT_PRINT_HEX,
1651 (unsigned HOST_WIDE_INT) CONST_WIDE_INT_ELT (x, i));
1652 pp_string (pp, tmp);
1654 pp_greater (pp);
1656 break;
1658 case CONST_POLY_INT:
1659 pp_left_bracket (pp);
1660 pp_wide_int (pp, CONST_POLY_INT_COEFFS (x)[0], SIGNED);
1661 for (unsigned int i = 1; i < NUM_POLY_INT_COEFFS; ++i)
1663 pp_string (pp, ", ");
1664 pp_wide_int (pp, CONST_POLY_INT_COEFFS (x)[i], SIGNED);
1666 pp_right_bracket (pp);
1667 break;
1669 case CONST_DOUBLE:
1670 if (FLOAT_MODE_P (GET_MODE (x)))
1672 real_to_decimal (tmp, CONST_DOUBLE_REAL_VALUE (x),
1673 sizeof (tmp), 0, 1);
1674 pp_string (pp, tmp);
1676 else
1677 pp_printf (pp, "<%wx,%wx>",
1678 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x),
1679 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x));
1680 break;
1681 case CONST_FIXED:
1682 fixed_to_decimal (tmp, CONST_FIXED_VALUE (x), sizeof (tmp));
1683 pp_string (pp, tmp);
1684 break;
1685 case CONST_STRING:
1686 pp_string (pp, "\"");
1687 pretty_print_string (pp, XSTR (x, 0), strlen (XSTR (x, 0)));
1688 pp_string (pp, "\"");
1689 break;
1690 case SYMBOL_REF:
1691 pp_printf (pp, "`%s'", XSTR (x, 0));
1692 break;
1693 case LABEL_REF:
1694 pp_printf (pp, "L%d", INSN_UID (label_ref_label (x)));
1695 break;
1696 case CONST:
1697 case HIGH:
1698 case STRICT_LOW_PART:
1699 pp_printf (pp, "%s(", GET_RTX_NAME (GET_CODE (x)));
1700 print_value (pp, XEXP (x, 0), verbose);
1701 pp_right_paren (pp);
1702 break;
1703 case REG:
1704 if (REGNO (x) < FIRST_PSEUDO_REGISTER)
1706 if (ISDIGIT (reg_names[REGNO (x)][0]))
1707 pp_modulo (pp);
1708 pp_string (pp, reg_names[REGNO (x)]);
1710 else
1711 pp_printf (pp, "r%d", REGNO (x));
1712 if (verbose)
1713 pp_printf (pp, ":%s", GET_MODE_NAME (GET_MODE (x)));
1714 break;
1715 case SUBREG:
1716 print_value (pp, SUBREG_REG (x), verbose);
1717 pp_printf (pp, "#");
1718 pp_wide_integer (pp, SUBREG_BYTE (x));
1719 break;
1720 case SCRATCH:
1721 case CC0:
1722 case PC:
1723 pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
1724 break;
1725 case MEM:
1726 pp_left_bracket (pp);
1727 print_value (pp, XEXP (x, 0), verbose);
1728 pp_right_bracket (pp);
1729 break;
1730 case DEBUG_EXPR:
1731 pp_printf (pp, "D#%i", DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x)));
1732 break;
1733 default:
1734 print_exp (pp, x, verbose);
1735 break;
1737 } /* print_value */
1739 /* The next step in insn detalization, its pattern recognition. */
1741 void
1742 print_pattern (pretty_printer *pp, const_rtx x, int verbose)
1744 if (! x)
1746 pp_string (pp, "(nil)");
1747 return;
1750 switch (GET_CODE (x))
1752 case SET:
1753 print_value (pp, SET_DEST (x), verbose);
1754 pp_equal (pp);
1755 print_value (pp, SET_SRC (x), verbose);
1756 break;
1757 case RETURN:
1758 case SIMPLE_RETURN:
1759 case EH_RETURN:
1760 pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
1761 break;
1762 case CALL:
1763 print_exp (pp, x, verbose);
1764 break;
1765 case CLOBBER:
1766 case USE:
1767 pp_printf (pp, "%s ", GET_RTX_NAME (GET_CODE (x)));
1768 print_value (pp, XEXP (x, 0), verbose);
1769 break;
1770 case VAR_LOCATION:
1771 pp_string (pp, "loc ");
1772 print_value (pp, PAT_VAR_LOCATION_LOC (x), verbose);
1773 break;
1774 case COND_EXEC:
1775 pp_left_paren (pp);
1776 if (GET_CODE (COND_EXEC_TEST (x)) == NE
1777 && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
1778 print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
1779 else if (GET_CODE (COND_EXEC_TEST (x)) == EQ
1780 && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
1782 pp_exclamation (pp);
1783 print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
1785 else
1786 print_value (pp, COND_EXEC_TEST (x), verbose);
1787 pp_string (pp, ") ");
1788 print_pattern (pp, COND_EXEC_CODE (x), verbose);
1789 break;
1790 case PARALLEL:
1792 int i;
1794 pp_left_brace (pp);
1795 for (i = 0; i < XVECLEN (x, 0); i++)
1797 print_pattern (pp, XVECEXP (x, 0, i), verbose);
1798 pp_semicolon (pp);
1800 pp_right_brace (pp);
1802 break;
1803 case SEQUENCE:
1805 const rtx_sequence *seq = as_a <const rtx_sequence *> (x);
1806 pp_string (pp, "sequence{");
1807 if (INSN_P (seq->element (0)))
1809 /* Print the sequence insns indented. */
1810 const char * save_print_rtx_head = print_rtx_head;
1811 char indented_print_rtx_head[32];
1813 pp_newline (pp);
1814 gcc_assert (strlen (print_rtx_head) < sizeof (indented_print_rtx_head) - 4);
1815 snprintf (indented_print_rtx_head,
1816 sizeof (indented_print_rtx_head),
1817 "%s ", print_rtx_head);
1818 print_rtx_head = indented_print_rtx_head;
1819 for (int i = 0; i < seq->len (); i++)
1820 print_insn_with_notes (pp, seq->insn (i));
1821 pp_printf (pp, "%s ", save_print_rtx_head);
1822 print_rtx_head = save_print_rtx_head;
1824 else
1826 for (int i = 0; i < seq->len (); i++)
1828 print_pattern (pp, seq->element (i), verbose);
1829 pp_semicolon (pp);
1832 pp_right_brace (pp);
1834 break;
1835 case ASM_INPUT:
1836 pp_printf (pp, "asm {%s}", XSTR (x, 0));
1837 break;
1838 case ADDR_VEC:
1839 for (int i = 0; i < XVECLEN (x, 0); i++)
1841 print_value (pp, XVECEXP (x, 0, i), verbose);
1842 pp_semicolon (pp);
1844 break;
1845 case ADDR_DIFF_VEC:
1846 for (int i = 0; i < XVECLEN (x, 1); i++)
1848 print_value (pp, XVECEXP (x, 1, i), verbose);
1849 pp_semicolon (pp);
1851 break;
1852 case TRAP_IF:
1853 pp_string (pp, "trap_if ");
1854 print_value (pp, TRAP_CONDITION (x), verbose);
1855 break;
1856 case UNSPEC:
1857 case UNSPEC_VOLATILE:
1858 /* Fallthru -- leave UNSPECs to print_exp. */
1859 default:
1860 print_value (pp, x, verbose);
1862 } /* print_pattern */
1864 /* This is the main function in slim rtl visualization mechanism.
1866 X is an insn, to be printed into PP.
1868 This function tries to print it properly in human-readable form,
1869 resembling assembler mnemonics (instead of the older Lisp-style
1870 form).
1872 If VERBOSE is TRUE, insns are printed with more complete (but
1873 longer) pattern names and with extra information, and prefixed
1874 with their INSN_UIDs. */
1876 void
1877 print_insn (pretty_printer *pp, const rtx_insn *x, int verbose)
1879 if (verbose)
1881 /* Blech, pretty-print can't print integers with a specified width. */
1882 char uid_prefix[32];
1883 snprintf (uid_prefix, sizeof uid_prefix, " %4d: ", INSN_UID (x));
1884 pp_string (pp, uid_prefix);
1887 switch (GET_CODE (x))
1889 case INSN:
1890 print_pattern (pp, PATTERN (x), verbose);
1891 break;
1893 case DEBUG_INSN:
1895 if (DEBUG_MARKER_INSN_P (x))
1897 switch (INSN_DEBUG_MARKER_KIND (x))
1899 case NOTE_INSN_BEGIN_STMT:
1900 pp_string (pp, "debug begin stmt marker");
1901 break;
1903 case NOTE_INSN_INLINE_ENTRY:
1904 pp_string (pp, "debug inline entry marker");
1905 break;
1907 default:
1908 gcc_unreachable ();
1910 break;
1913 const char *name = "?";
1914 char idbuf[32];
1916 if (DECL_P (INSN_VAR_LOCATION_DECL (x)))
1918 tree id = DECL_NAME (INSN_VAR_LOCATION_DECL (x));
1919 if (id)
1920 name = IDENTIFIER_POINTER (id);
1921 else if (TREE_CODE (INSN_VAR_LOCATION_DECL (x))
1922 == DEBUG_EXPR_DECL)
1924 sprintf (idbuf, "D#%i",
1925 DEBUG_TEMP_UID (INSN_VAR_LOCATION_DECL (x)));
1926 name = idbuf;
1928 else
1930 sprintf (idbuf, "D.%i",
1931 DECL_UID (INSN_VAR_LOCATION_DECL (x)));
1932 name = idbuf;
1935 pp_printf (pp, "debug %s => ", name);
1936 if (VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (x)))
1937 pp_string (pp, "optimized away");
1938 else
1939 print_pattern (pp, INSN_VAR_LOCATION_LOC (x), verbose);
1941 break;
1943 case JUMP_INSN:
1944 print_pattern (pp, PATTERN (x), verbose);
1945 break;
1946 case CALL_INSN:
1947 if (GET_CODE (PATTERN (x)) == PARALLEL)
1948 print_pattern (pp, XVECEXP (PATTERN (x), 0, 0), verbose);
1949 else
1950 print_pattern (pp, PATTERN (x), verbose);
1951 break;
1952 case CODE_LABEL:
1953 pp_printf (pp, "L%d:", INSN_UID (x));
1954 break;
1955 case JUMP_TABLE_DATA:
1956 pp_string (pp, "jump_table_data{\n");
1957 print_pattern (pp, PATTERN (x), verbose);
1958 pp_right_brace (pp);
1959 break;
1960 case BARRIER:
1961 pp_string (pp, "barrier");
1962 break;
1963 case NOTE:
1965 pp_string (pp, GET_NOTE_INSN_NAME (NOTE_KIND (x)));
1966 switch (NOTE_KIND (x))
1968 case NOTE_INSN_EH_REGION_BEG:
1969 case NOTE_INSN_EH_REGION_END:
1970 pp_printf (pp, " %d", NOTE_EH_HANDLER (x));
1971 break;
1973 case NOTE_INSN_BLOCK_BEG:
1974 case NOTE_INSN_BLOCK_END:
1975 pp_printf (pp, " %d", BLOCK_NUMBER (NOTE_BLOCK (x)));
1976 break;
1978 case NOTE_INSN_BASIC_BLOCK:
1979 pp_printf (pp, " %d", NOTE_BASIC_BLOCK (x)->index);
1980 break;
1982 case NOTE_INSN_DELETED_LABEL:
1983 case NOTE_INSN_DELETED_DEBUG_LABEL:
1985 const char *label = NOTE_DELETED_LABEL_NAME (x);
1986 if (label == NULL)
1987 label = "";
1988 pp_printf (pp, " (\"%s\")", label);
1990 break;
1992 case NOTE_INSN_VAR_LOCATION:
1993 pp_left_brace (pp);
1994 print_pattern (pp, NOTE_VAR_LOCATION (x), verbose);
1995 pp_right_brace (pp);
1996 break;
1998 default:
1999 break;
2001 break;
2003 default:
2004 gcc_unreachable ();
2006 } /* print_insn */
2008 /* Pretty-print a slim dump of X (an insn) to PP, including any register
2009 note attached to the instruction. */
2011 void
2012 print_insn_with_notes (pretty_printer *pp, const rtx_insn *x)
2014 pp_string (pp, print_rtx_head);
2015 print_insn (pp, x, 1);
2016 pp_newline (pp);
2017 if (INSN_P (x) && REG_NOTES (x))
2018 for (rtx note = REG_NOTES (x); note; note = XEXP (note, 1))
2020 pp_printf (pp, "%s %s ", print_rtx_head,
2021 GET_REG_NOTE_NAME (REG_NOTE_KIND (note)));
2022 if (GET_CODE (note) == INT_LIST)
2023 pp_printf (pp, "%d", XINT (note, 0));
2024 else
2025 print_pattern (pp, XEXP (note, 0), 1);
2026 pp_newline (pp);
2030 /* Print X, an RTL value node, to file F in slim format. Include
2031 additional information if VERBOSE is nonzero.
2033 Value nodes are constants, registers, labels, symbols and
2034 memory. */
2036 void
2037 dump_value_slim (FILE *f, const_rtx x, int verbose)
2039 pretty_printer rtl_slim_pp;
2040 rtl_slim_pp.buffer->stream = f;
2041 print_value (&rtl_slim_pp, x, verbose);
2042 pp_flush (&rtl_slim_pp);
2045 /* Emit a slim dump of X (an insn) to the file F, including any register
2046 note attached to the instruction. */
2047 void
2048 dump_insn_slim (FILE *f, const rtx_insn *x)
2050 pretty_printer rtl_slim_pp;
2051 rtl_slim_pp.buffer->stream = f;
2052 print_insn_with_notes (&rtl_slim_pp, x);
2053 pp_flush (&rtl_slim_pp);
2056 /* Same as above, but stop at LAST or when COUNT == 0.
2057 If COUNT < 0 it will stop only at LAST or NULL rtx. */
2059 void
2060 dump_rtl_slim (FILE *f, const rtx_insn *first, const rtx_insn *last,
2061 int count, int flags ATTRIBUTE_UNUSED)
2063 const rtx_insn *insn, *tail;
2064 pretty_printer rtl_slim_pp;
2065 rtl_slim_pp.buffer->stream = f;
2067 tail = last ? NEXT_INSN (last) : NULL;
2068 for (insn = first;
2069 (insn != NULL) && (insn != tail) && (count != 0);
2070 insn = NEXT_INSN (insn))
2072 print_insn_with_notes (&rtl_slim_pp, insn);
2073 if (count > 0)
2074 count--;
2077 pp_flush (&rtl_slim_pp);
2080 /* Dumps basic block BB to pretty-printer PP in slim form and without and
2081 no indentation, for use as a label of a DOT graph record-node. */
2083 void
2084 rtl_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
2086 rtx_insn *insn;
2087 bool first = true;
2089 /* TODO: inter-bb stuff. */
2090 FOR_BB_INSNS (bb, insn)
2092 if (! first)
2094 pp_bar (pp);
2095 pp_write_text_to_stream (pp);
2097 first = false;
2098 print_insn_with_notes (pp, insn);
2099 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2103 /* Pretty-print pattern X of some insn in non-verbose mode.
2104 Return a string pointer to the pretty-printer buffer.
2106 This function is only exported exists only to accommodate some older users
2107 of the slim RTL pretty printers. Please do not use it for new code. */
2109 const char *
2110 str_pattern_slim (const_rtx x)
2112 pretty_printer rtl_slim_pp;
2113 print_pattern (&rtl_slim_pp, x, 0);
2114 return ggc_strdup (pp_formatted_text (&rtl_slim_pp));
2117 /* Emit a slim dump of X (an insn) to stderr. */
2118 extern void debug_insn_slim (const rtx_insn *);
2119 DEBUG_FUNCTION void
2120 debug_insn_slim (const rtx_insn *x)
2122 dump_insn_slim (stderr, x);
2125 /* Same as above, but using dump_rtl_slim. */
2126 extern void debug_rtl_slim (FILE *, const rtx_insn *, const rtx_insn *,
2127 int, int);
2128 DEBUG_FUNCTION void
2129 debug_rtl_slim (const rtx_insn *first, const rtx_insn *last, int count,
2130 int flags)
2132 dump_rtl_slim (stderr, first, last, count, flags);
2135 extern void debug_bb_slim (basic_block);
2136 DEBUG_FUNCTION void
2137 debug_bb_slim (basic_block bb)
2139 debug_bb (bb, TDF_SLIM | TDF_BLOCKS);
2142 extern void debug_bb_n_slim (int);
2143 DEBUG_FUNCTION void
2144 debug_bb_n_slim (int n)
2146 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, n);
2147 debug_bb_slim (bb);
2150 #endif
2152 #if __GNUC__ >= 10
2153 # pragma GCC diagnostic pop
2154 #endif