Split print_rtx into subroutines
[official-gcc.git] / gcc / print-rtl.c
blob29e8ee2e180d8ca8f30acb0add0f44da7647b235
1 /* Print RTL for GCC.
2 Copyright (C) 1987-2016 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file is compiled twice: once for the generator programs,
21 once for the compiler. */
22 #ifdef GENERATOR_FILE
23 #include "bconfig.h"
24 #else
25 #include "config.h"
26 #endif
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "rtl.h"
33 /* These headers all define things which are not available in
34 generator programs. */
35 #ifndef GENERATOR_FILE
36 #include "alias.h"
37 #include "tree.h"
38 #include "cfg.h"
39 #include "print-tree.h"
40 #include "flags.h"
41 #include "predict.h"
42 #include "function.h"
43 #include "basic-block.h"
44 #include "diagnostic.h"
45 #include "tree-pretty-print.h"
46 #include "alloc-pool.h"
47 #include "cselib.h"
48 #include "dumpfile.h" /* for dump_flags */
49 #include "dwarf2out.h"
50 #include "pretty-print.h"
51 #endif
53 #include "print-rtl.h"
55 static FILE *outfile;
57 static int sawclose = 0;
59 static int indent;
61 static bool in_call_function_usage;
63 static void print_rtx (const_rtx);
65 /* String printed at beginning of each RTL when it is dumped.
66 This string is set to ASM_COMMENT_START when the RTL is dumped in
67 the assembly output file. */
68 const char *print_rtx_head = "";
70 #ifdef GENERATOR_FILE
71 /* These are defined from the .opt file when not used in generator
72 programs. */
74 /* Nonzero means suppress output of instruction numbers
75 in debugging dumps.
76 This must be defined here so that programs like gencodes can be linked. */
77 int flag_dump_unnumbered = 0;
79 /* Nonzero means suppress output of instruction numbers for previous
80 and next insns in debugging dumps.
81 This must be defined here so that programs like gencodes can be linked. */
82 int flag_dump_unnumbered_links = 0;
83 #endif
85 /* Nonzero means use simplified format without flags, modes, etc. */
86 int flag_simple = 0;
88 #ifndef GENERATOR_FILE
89 void
90 print_mem_expr (FILE *outfile, const_tree expr)
92 fputc (' ', outfile);
93 print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
95 #endif
97 /* Subroutine of print_rtx_operand for handling code '0'.
98 0 indicates a field for internal use that should not be printed.
99 However there are various special cases, such as the third field
100 of a NOTE, where it indicates that the field has several different
101 valid contents. */
103 static void
104 print_rtx_operand_code_0 (const_rtx in_rtx ATTRIBUTE_UNUSED,
105 int idx ATTRIBUTE_UNUSED)
107 #ifndef GENERATOR_FILE
108 if (idx == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
110 int flags = SYMBOL_REF_FLAGS (in_rtx);
111 if (flags)
112 fprintf (outfile, " [flags %#x]", flags);
113 tree decl = SYMBOL_REF_DECL (in_rtx);
114 if (decl)
115 print_node_brief (outfile, "", decl, dump_flags);
117 else if (idx == 3 && NOTE_P (in_rtx))
119 switch (NOTE_KIND (in_rtx))
121 case NOTE_INSN_EH_REGION_BEG:
122 case NOTE_INSN_EH_REGION_END:
123 if (flag_dump_unnumbered)
124 fprintf (outfile, " #");
125 else
126 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
127 sawclose = 1;
128 break;
130 case NOTE_INSN_BLOCK_BEG:
131 case NOTE_INSN_BLOCK_END:
132 dump_addr (outfile, " ", NOTE_BLOCK (in_rtx));
133 sawclose = 1;
134 break;
136 case NOTE_INSN_BASIC_BLOCK:
138 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
139 if (bb != 0)
140 fprintf (outfile, " [bb %d]", bb->index);
141 break;
144 case NOTE_INSN_DELETED_LABEL:
145 case NOTE_INSN_DELETED_DEBUG_LABEL:
147 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
148 if (label)
149 fprintf (outfile, " (\"%s\")", label);
150 else
151 fprintf (outfile, " \"\"");
153 break;
155 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
157 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
158 if (bb != 0)
159 fprintf (outfile, " [bb %d]", bb->index);
160 break;
163 case NOTE_INSN_VAR_LOCATION:
164 case NOTE_INSN_CALL_ARG_LOCATION:
165 fputc (' ', outfile);
166 print_rtx (NOTE_VAR_LOCATION (in_rtx));
167 break;
169 case NOTE_INSN_CFI:
170 fputc ('\n', outfile);
171 output_cfi_directive (outfile, NOTE_CFI (in_rtx));
172 fputc ('\t', outfile);
173 break;
175 default:
176 break;
179 else if (idx == 7 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL)
181 /* Output the JUMP_LABEL reference. */
182 fprintf (outfile, "\n%s%*s -> ", print_rtx_head, indent * 2, "");
183 if (GET_CODE (JUMP_LABEL (in_rtx)) == RETURN)
184 fprintf (outfile, "return");
185 else if (GET_CODE (JUMP_LABEL (in_rtx)) == SIMPLE_RETURN)
186 fprintf (outfile, "simple_return");
187 else
188 fprintf (outfile, "%d", INSN_UID (JUMP_LABEL (in_rtx)));
190 else if (idx == 0 && GET_CODE (in_rtx) == VALUE)
192 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
194 fprintf (outfile, " %u:%u", val->uid, val->hash);
195 dump_addr (outfile, " @", in_rtx);
196 dump_addr (outfile, "/", (void*)val);
198 else if (idx == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
200 fprintf (outfile, " D#%i",
201 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
203 else if (idx == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
205 indent += 2;
206 if (!sawclose)
207 fprintf (outfile, " ");
208 print_rtx (ENTRY_VALUE_EXP (in_rtx));
209 indent -= 2;
211 #endif
214 /* Subroutine of print_rtx_operand for handling code 'e'.
215 Also called by print_rtx_operand_code_u for handling code 'u'
216 for LABEL_REFs when they don't reference a CODE_LABEL. */
218 static void
219 print_rtx_operand_code_e (const_rtx in_rtx, int idx)
221 indent += 2;
222 if (idx == 6 && INSN_P (in_rtx))
223 /* Put REG_NOTES on their own line. */
224 fprintf (outfile, "\n%s%*s",
225 print_rtx_head, indent * 2, "");
226 if (!sawclose)
227 fprintf (outfile, " ");
228 if (idx == 7 && CALL_P (in_rtx))
230 in_call_function_usage = true;
231 print_rtx (XEXP (in_rtx, idx));
232 in_call_function_usage = false;
234 else
235 print_rtx (XEXP (in_rtx, idx));
236 indent -= 2;
239 /* Subroutine of print_rtx_operand for handling codes 'E' and 'V'. */
241 static void
242 print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx)
244 indent += 2;
245 if (sawclose)
247 fprintf (outfile, "\n%s%*s",
248 print_rtx_head, indent * 2, "");
249 sawclose = 0;
251 fputs (" [", outfile);
252 if (NULL != XVEC (in_rtx, idx))
254 indent += 2;
255 if (XVECLEN (in_rtx, idx))
256 sawclose = 1;
258 for (int j = 0; j < XVECLEN (in_rtx, idx); j++)
259 print_rtx (XVECEXP (in_rtx, idx, j));
261 indent -= 2;
263 if (sawclose)
264 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
266 fputs ("]", outfile);
267 sawclose = 1;
268 indent -= 2;
271 /* Subroutine of print_rtx_operand for handling code 'i'. */
273 static void
274 print_rtx_operand_code_i (const_rtx in_rtx, int idx)
276 if (idx == 4 && INSN_P (in_rtx))
278 #ifndef GENERATOR_FILE
279 const rtx_insn *in_insn = as_a <const rtx_insn *> (in_rtx);
281 /* Pretty-print insn locations. Ignore scoping as it is mostly
282 redundant with line number information and do not print anything
283 when there is no location information available. */
284 if (INSN_HAS_LOCATION (in_insn))
286 expanded_location xloc = insn_location (in_insn);
287 fprintf (outfile, " %s:%i", xloc.file, xloc.line);
289 #endif
291 else if (idx == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
293 #ifndef GENERATOR_FILE
294 if (ASM_OPERANDS_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
295 fprintf (outfile, " %s:%i",
296 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
297 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
298 #endif
300 else if (idx == 1 && GET_CODE (in_rtx) == ASM_INPUT)
302 #ifndef GENERATOR_FILE
303 if (ASM_INPUT_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
304 fprintf (outfile, " %s:%i",
305 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
306 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
307 #endif
309 else if (idx == 5 && NOTE_P (in_rtx))
311 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
312 other times often contains garbage from INSN->NOTE death. */
313 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL
314 || NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_DEBUG_LABEL)
315 fprintf (outfile, " %d", XINT (in_rtx, idx));
317 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
318 else if (idx == 1
319 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
320 && XINT (in_rtx, 1) >= 0
321 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
322 fprintf (outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
323 #endif
324 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
325 else if (idx == 1
326 && (GET_CODE (in_rtx) == UNSPEC
327 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
328 && XINT (in_rtx, 1) >= 0
329 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
330 fprintf (outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
331 #endif
332 else
334 int value = XINT (in_rtx, idx);
335 const char *name;
336 int is_insn = INSN_P (in_rtx);
338 if (flag_dump_unnumbered
339 && (is_insn || NOTE_P (in_rtx)))
340 fputc ('#', outfile);
341 else
342 fprintf (outfile, " %d", value);
344 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, idx)
345 && XINT (in_rtx, idx) >= 0
346 && (name = get_insn_name (XINT (in_rtx, idx))) != NULL)
347 fprintf (outfile, " {%s}", name);
348 sawclose = 0;
352 /* Subroutine of print_rtx_operand for handling code 'r'. */
354 static void
355 print_rtx_operand_code_r (const_rtx in_rtx)
357 int is_insn = INSN_P (in_rtx);
358 unsigned int regno = REGNO (in_rtx);
360 #ifndef GENERATOR_FILE
361 if (regno < FIRST_PSEUDO_REGISTER)
362 fprintf (outfile, " %d %s", regno, reg_names[regno]);
363 else if (regno <= LAST_VIRTUAL_REGISTER)
365 if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
366 fprintf (outfile, " %d virtual-incoming-args", regno);
367 else if (regno == VIRTUAL_STACK_VARS_REGNUM)
368 fprintf (outfile, " %d virtual-stack-vars", regno);
369 else if (regno == VIRTUAL_STACK_DYNAMIC_REGNUM)
370 fprintf (outfile, " %d virtual-stack-dynamic", regno);
371 else if (regno == VIRTUAL_OUTGOING_ARGS_REGNUM)
372 fprintf (outfile, " %d virtual-outgoing-args", regno);
373 else if (regno == VIRTUAL_CFA_REGNUM)
374 fprintf (outfile, " %d virtual-cfa", regno);
375 else if (regno == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
376 fprintf (outfile, " %d virtual-preferred-stack-boundary",
377 regno);
378 else
379 fprintf (outfile, " %d virtual-reg-%d", regno,
380 regno-FIRST_VIRTUAL_REGISTER);
382 else
383 #endif
384 if (flag_dump_unnumbered && is_insn)
385 fputc ('#', outfile);
386 else
387 fprintf (outfile, " %d", regno);
389 #ifndef GENERATOR_FILE
390 if (REG_ATTRS (in_rtx))
392 fputs (" [", outfile);
393 if (regno != ORIGINAL_REGNO (in_rtx))
394 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
395 if (REG_EXPR (in_rtx))
396 print_mem_expr (outfile, REG_EXPR (in_rtx));
398 if (REG_OFFSET (in_rtx))
399 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
400 REG_OFFSET (in_rtx));
401 fputs (" ]", outfile);
403 if (regno != ORIGINAL_REGNO (in_rtx))
404 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
405 #endif
408 /* Subroutine of print_rtx_operand for handling code 'u'. */
410 static void
411 print_rtx_operand_code_u (const_rtx in_rtx, int idx)
413 if (XEXP (in_rtx, idx) != NULL)
415 rtx sub = XEXP (in_rtx, idx);
416 enum rtx_code subc = GET_CODE (sub);
418 if (GET_CODE (in_rtx) == LABEL_REF)
420 if (subc == NOTE
421 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
423 if (flag_dump_unnumbered)
424 fprintf (outfile, " [# deleted]");
425 else
426 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
427 sawclose = 0;
428 return;
431 if (subc != CODE_LABEL)
433 print_rtx_operand_code_e (in_rtx, idx);
434 return;
438 if (flag_dump_unnumbered
439 || (flag_dump_unnumbered_links && idx <= 1
440 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
441 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
442 fputs (" #", outfile);
443 else
444 fprintf (outfile, " %d", INSN_UID (sub));
446 else
447 fputs (" 0", outfile);
448 sawclose = 0;
451 /* Subroutine of print_rtx. Print operand IDX of IN_RTX. */
453 static void
454 print_rtx_operand (const_rtx in_rtx, int idx)
456 const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
458 switch (format_ptr[idx])
460 const char *str;
462 case 'T':
463 str = XTMPL (in_rtx, idx);
464 goto string;
466 case 'S':
467 case 's':
468 str = XSTR (in_rtx, idx);
469 string:
471 if (str == 0)
472 fputs (" \"\"", outfile);
473 else
474 fprintf (outfile, " (\"%s\")", str);
475 sawclose = 1;
476 break;
478 case '0':
479 print_rtx_operand_code_0 (in_rtx, idx);
480 break;
482 case 'e':
483 print_rtx_operand_code_e (in_rtx, idx);
484 break;
486 case 'E':
487 case 'V':
488 print_rtx_operand_codes_E_and_V (in_rtx, idx);
489 break;
491 case 'w':
492 if (! flag_simple)
493 fprintf (outfile, " ");
494 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, idx));
495 if (! flag_simple)
496 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
497 (unsigned HOST_WIDE_INT) XWINT (in_rtx, idx));
498 break;
500 case 'i':
501 print_rtx_operand_code_i (in_rtx, idx);
502 break;
504 case 'r':
505 print_rtx_operand_code_r (in_rtx);
506 break;
508 /* Print NOTE_INSN names rather than integer codes. */
510 case 'n':
511 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, idx)));
512 sawclose = 0;
513 break;
515 case 'u':
516 print_rtx_operand_code_u (in_rtx, idx);
517 break;
519 case 't':
520 #ifndef GENERATOR_FILE
521 if (idx == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
522 print_mem_expr (outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
523 else if (idx == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
524 print_mem_expr (outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
525 else
526 dump_addr (outfile, " ", XTREE (in_rtx, idx));
527 #endif
528 break;
530 case '*':
531 fputs (" Unknown", outfile);
532 sawclose = 0;
533 break;
535 case 'B':
536 #ifndef GENERATOR_FILE
537 if (XBBDEF (in_rtx, idx))
538 fprintf (outfile, " %i", XBBDEF (in_rtx, idx)->index);
539 #endif
540 break;
542 default:
543 gcc_unreachable ();
547 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
549 static void
550 print_rtx (const_rtx in_rtx)
552 int idx = 0;
554 if (sawclose)
556 if (flag_simple)
557 fputc (' ', outfile);
558 else
559 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
560 sawclose = 0;
563 if (in_rtx == 0)
565 fputs ("(nil)", outfile);
566 sawclose = 1;
567 return;
569 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
571 fprintf (outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
572 print_rtx_head, indent * 2, "");
573 sawclose = 1;
574 return;
577 /* Print name of expression code. */
578 if (flag_simple && CONST_INT_P (in_rtx))
579 fputc ('(', outfile);
580 else
581 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
583 if (! flag_simple)
585 if (RTX_FLAG (in_rtx, in_struct))
586 fputs ("/s", outfile);
588 if (RTX_FLAG (in_rtx, volatil))
589 fputs ("/v", outfile);
591 if (RTX_FLAG (in_rtx, unchanging))
592 fputs ("/u", outfile);
594 if (RTX_FLAG (in_rtx, frame_related))
595 fputs ("/f", outfile);
597 if (RTX_FLAG (in_rtx, jump))
598 fputs ("/j", outfile);
600 if (RTX_FLAG (in_rtx, call))
601 fputs ("/c", outfile);
603 if (RTX_FLAG (in_rtx, return_val))
604 fputs ("/i", outfile);
606 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
607 if ((GET_CODE (in_rtx) == EXPR_LIST
608 || GET_CODE (in_rtx) == INSN_LIST
609 || GET_CODE (in_rtx) == INT_LIST)
610 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX
611 && !in_call_function_usage)
612 fprintf (outfile, ":%s",
613 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
615 /* For other rtl, print the mode if it's not VOID. */
616 else if (GET_MODE (in_rtx) != VOIDmode)
617 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
619 #ifndef GENERATOR_FILE
620 if (GET_CODE (in_rtx) == VAR_LOCATION)
622 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
623 fputs (" <debug string placeholder>", outfile);
624 else
625 print_mem_expr (outfile, PAT_VAR_LOCATION_DECL (in_rtx));
626 fputc (' ', outfile);
627 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
628 if (PAT_VAR_LOCATION_STATUS (in_rtx)
629 == VAR_INIT_STATUS_UNINITIALIZED)
630 fprintf (outfile, " [uninit]");
631 sawclose = 1;
632 idx = GET_RTX_LENGTH (VAR_LOCATION);
634 #endif
637 #ifndef GENERATOR_FILE
638 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx))
639 idx = 5;
640 #endif
642 if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx)))
644 if (flag_dump_unnumbered)
645 fprintf (outfile, " #");
646 else
647 fprintf (outfile, " %d", INSN_UID (in_rtx));
650 /* Get the format string and skip the first elements if we have handled
651 them already. */
652 for (; idx < GET_RTX_LENGTH (GET_CODE (in_rtx)); idx++)
653 print_rtx_operand (in_rtx, idx);
655 switch (GET_CODE (in_rtx))
657 #ifndef GENERATOR_FILE
658 case MEM:
659 if (__builtin_expect (final_insns_dump_p, false))
660 fprintf (outfile, " [");
661 else
662 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC,
663 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
665 if (MEM_EXPR (in_rtx))
666 print_mem_expr (outfile, MEM_EXPR (in_rtx));
667 else
668 fputc (' ', outfile);
670 if (MEM_OFFSET_KNOWN_P (in_rtx))
671 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC, MEM_OFFSET (in_rtx));
673 if (MEM_SIZE_KNOWN_P (in_rtx))
674 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC, MEM_SIZE (in_rtx));
676 if (MEM_ALIGN (in_rtx) != 1)
677 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
679 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
680 fprintf (outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
682 fputc (']', outfile);
683 break;
685 case CONST_DOUBLE:
686 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
688 char s[60];
690 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
691 sizeof (s), 0, 1);
692 fprintf (outfile, " %s", s);
694 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
695 sizeof (s), 0, 1);
696 fprintf (outfile, " [%s]", s);
698 break;
700 case CONST_WIDE_INT:
701 fprintf (outfile, " ");
702 cwi_output_hex (outfile, in_rtx);
703 break;
704 #endif
706 case CODE_LABEL:
707 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
708 switch (LABEL_KIND (in_rtx))
710 case LABEL_NORMAL: break;
711 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
712 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
713 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
714 default: gcc_unreachable ();
716 break;
718 default:
719 break;
722 fputc (')', outfile);
723 sawclose = 1;
726 /* Print an rtx on the current line of FILE. Initially indent IND
727 characters. */
729 void
730 print_inline_rtx (FILE *outf, const_rtx x, int ind)
732 int oldsaw = sawclose;
733 int oldindent = indent;
735 sawclose = 0;
736 indent = ind;
737 outfile = outf;
738 print_rtx (x);
739 sawclose = oldsaw;
740 indent = oldindent;
743 /* Call this function from the debugger to see what X looks like. */
745 DEBUG_FUNCTION void
746 debug_rtx (const_rtx x)
748 outfile = stderr;
749 sawclose = 0;
750 print_rtx (x);
751 fprintf (stderr, "\n");
754 /* Dump rtx REF. */
756 DEBUG_FUNCTION void
757 debug (const rtx_def &ref)
759 debug_rtx (&ref);
762 DEBUG_FUNCTION void
763 debug (const rtx_def *ptr)
765 if (ptr)
766 debug (*ptr);
767 else
768 fprintf (stderr, "<nil>\n");
771 /* Count of rtx's to print with debug_rtx_list.
772 This global exists because gdb user defined commands have no arguments. */
774 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
776 /* Call this function to print list from X on.
778 N is a count of the rtx's to print. Positive values print from the specified
779 rtx_insn on. Negative values print a window around the rtx_insn.
780 EG: -5 prints 2 rtx_insn's on either side (in addition to the specified
781 rtx_insn). */
783 DEBUG_FUNCTION void
784 debug_rtx_list (const rtx_insn *x, int n)
786 int i,count;
787 const rtx_insn *insn;
789 count = n == 0 ? 1 : n < 0 ? -n : n;
791 /* If we are printing a window, back up to the start. */
793 if (n < 0)
794 for (i = count / 2; i > 0; i--)
796 if (PREV_INSN (x) == 0)
797 break;
798 x = PREV_INSN (x);
801 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
803 debug_rtx (insn);
804 fprintf (stderr, "\n");
808 /* Call this function to print an rtx_insn list from START to END
809 inclusive. */
811 DEBUG_FUNCTION void
812 debug_rtx_range (const rtx_insn *start, const rtx_insn *end)
814 while (1)
816 debug_rtx (start);
817 fprintf (stderr, "\n");
818 if (!start || start == end)
819 break;
820 start = NEXT_INSN (start);
824 /* Call this function to search an rtx_insn list to find one with insn uid UID,
825 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
826 The found insn is returned to enable further debugging analysis. */
828 DEBUG_FUNCTION const rtx_insn *
829 debug_rtx_find (const rtx_insn *x, int uid)
831 while (x != 0 && INSN_UID (x) != uid)
832 x = NEXT_INSN (x);
833 if (x != 0)
835 debug_rtx_list (x, debug_rtx_count);
836 return x;
838 else
840 fprintf (stderr, "insn uid %d not found\n", uid);
841 return 0;
845 /* External entry point for printing a chain of insns
846 starting with RTX_FIRST onto file OUTF.
847 A blank line separates insns.
849 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
851 void
852 print_rtl (FILE *outf, const_rtx rtx_first)
854 const rtx_insn *tmp_rtx;
856 outfile = outf;
857 sawclose = 0;
859 if (rtx_first == 0)
861 fputs (print_rtx_head, outf);
862 fputs ("(nil)\n", outf);
864 else
865 switch (GET_CODE (rtx_first))
867 case INSN:
868 case JUMP_INSN:
869 case CALL_INSN:
870 case NOTE:
871 case CODE_LABEL:
872 case JUMP_TABLE_DATA:
873 case BARRIER:
874 for (tmp_rtx = as_a <const rtx_insn *> (rtx_first);
875 tmp_rtx != 0;
876 tmp_rtx = NEXT_INSN (tmp_rtx))
878 fputs (print_rtx_head, outfile);
879 print_rtx (tmp_rtx);
880 fprintf (outfile, "\n");
882 break;
884 default:
885 fputs (print_rtx_head, outfile);
886 print_rtx (rtx_first);
890 /* Like print_rtx, except specify a file. */
891 /* Return nonzero if we actually printed anything. */
894 print_rtl_single (FILE *outf, const_rtx x)
896 return print_rtl_single_with_indent (outf, x, 0);
899 /* Like print_rtl_single, except specify a file and indentation. */
902 print_rtl_single_with_indent (FILE *outf, const_rtx x, int ind)
904 int old_indent = indent;
905 char *s_indent = (char *) alloca ((size_t) ind + 1);
906 memset ((void *) s_indent, ' ', (size_t) ind);
907 s_indent[ind] = '\0';
909 indent = ind;
910 outfile = outf;
911 sawclose = 0;
912 fputs (s_indent, outfile);
913 fputs (print_rtx_head, outfile);
914 print_rtx (x);
915 putc ('\n', outf);
916 indent = old_indent;
917 return 1;
921 /* Like print_rtl except without all the detail; for example,
922 if RTX is a CONST_INT then print in decimal format. */
924 void
925 print_simple_rtl (FILE *outf, const_rtx x)
927 flag_simple = 1;
928 print_rtl (outf, x);
929 flag_simple = 0;
932 /* Print the elements of VEC to FILE. */
934 void
935 print_rtx_insn_vec (FILE *file, const vec<rtx_insn *> &vec)
937 fputc('{', file);
939 unsigned int len = vec.length ();
940 for (unsigned int i = 0; i < len; i++)
942 print_rtl (file, vec[i]);
943 if (i < len - 1)
944 fputs (", ", file);
947 fputc ('}', file);
950 #ifndef GENERATOR_FILE
951 /* The functions below try to print RTL in a form resembling assembler
952 mnemonics. Because this form is more concise than the "traditional" form
953 of RTL printing in Lisp-style, the form printed by this file is called
954 "slim". RTL dumps in slim format can be obtained by appending the "-slim"
955 option to -fdump-rtl-<pass>. Control flow graph output as a DOT file is
956 always printed in slim form.
958 The normal interface to the functionality provided in this pretty-printer
959 is through the dump_*_slim functions to print to a stream, or via the
960 print_*_slim functions to print into a user's pretty-printer.
962 It is also possible to obtain a string for a single pattern as a string
963 pointer, via str_pattern_slim, but this usage is discouraged. */
965 /* For insns we print patterns, and for some patterns we print insns... */
966 static void print_insn_with_notes (pretty_printer *, const rtx_insn *);
968 /* This recognizes rtx'en classified as expressions. These are always
969 represent some action on values or results of other expression, that
970 may be stored in objects representing values. */
972 static void
973 print_exp (pretty_printer *pp, const_rtx x, int verbose)
975 const char *st[4];
976 const char *fun;
977 rtx op[4];
978 int i;
980 fun = (char *) 0;
981 for (i = 0; i < 4; i++)
983 st[i] = (char *) 0;
984 op[i] = NULL_RTX;
987 switch (GET_CODE (x))
989 case PLUS:
990 op[0] = XEXP (x, 0);
991 if (CONST_INT_P (XEXP (x, 1))
992 && INTVAL (XEXP (x, 1)) < 0)
994 st[1] = "-";
995 op[1] = GEN_INT (-INTVAL (XEXP (x, 1)));
997 else
999 st[1] = "+";
1000 op[1] = XEXP (x, 1);
1002 break;
1003 case LO_SUM:
1004 op[0] = XEXP (x, 0);
1005 st[1] = "+low(";
1006 op[1] = XEXP (x, 1);
1007 st[2] = ")";
1008 break;
1009 case MINUS:
1010 op[0] = XEXP (x, 0);
1011 st[1] = "-";
1012 op[1] = XEXP (x, 1);
1013 break;
1014 case COMPARE:
1015 fun = "cmp";
1016 op[0] = XEXP (x, 0);
1017 op[1] = XEXP (x, 1);
1018 break;
1019 case NEG:
1020 st[0] = "-";
1021 op[0] = XEXP (x, 0);
1022 break;
1023 case FMA:
1024 st[0] = "{";
1025 op[0] = XEXP (x, 0);
1026 st[1] = "*";
1027 op[1] = XEXP (x, 1);
1028 st[2] = "+";
1029 op[2] = XEXP (x, 2);
1030 st[3] = "}";
1031 break;
1032 case MULT:
1033 op[0] = XEXP (x, 0);
1034 st[1] = "*";
1035 op[1] = XEXP (x, 1);
1036 break;
1037 case DIV:
1038 op[0] = XEXP (x, 0);
1039 st[1] = "/";
1040 op[1] = XEXP (x, 1);
1041 break;
1042 case UDIV:
1043 fun = "udiv";
1044 op[0] = XEXP (x, 0);
1045 op[1] = XEXP (x, 1);
1046 break;
1047 case MOD:
1048 op[0] = XEXP (x, 0);
1049 st[1] = "%";
1050 op[1] = XEXP (x, 1);
1051 break;
1052 case UMOD:
1053 fun = "umod";
1054 op[0] = XEXP (x, 0);
1055 op[1] = XEXP (x, 1);
1056 break;
1057 case SMIN:
1058 fun = "smin";
1059 op[0] = XEXP (x, 0);
1060 op[1] = XEXP (x, 1);
1061 break;
1062 case SMAX:
1063 fun = "smax";
1064 op[0] = XEXP (x, 0);
1065 op[1] = XEXP (x, 1);
1066 break;
1067 case UMIN:
1068 fun = "umin";
1069 op[0] = XEXP (x, 0);
1070 op[1] = XEXP (x, 1);
1071 break;
1072 case UMAX:
1073 fun = "umax";
1074 op[0] = XEXP (x, 0);
1075 op[1] = XEXP (x, 1);
1076 break;
1077 case NOT:
1078 st[0] = "!";
1079 op[0] = XEXP (x, 0);
1080 break;
1081 case AND:
1082 op[0] = XEXP (x, 0);
1083 st[1] = "&";
1084 op[1] = XEXP (x, 1);
1085 break;
1086 case IOR:
1087 op[0] = XEXP (x, 0);
1088 st[1] = "|";
1089 op[1] = XEXP (x, 1);
1090 break;
1091 case XOR:
1092 op[0] = XEXP (x, 0);
1093 st[1] = "^";
1094 op[1] = XEXP (x, 1);
1095 break;
1096 case ASHIFT:
1097 op[0] = XEXP (x, 0);
1098 st[1] = "<<";
1099 op[1] = XEXP (x, 1);
1100 break;
1101 case LSHIFTRT:
1102 op[0] = XEXP (x, 0);
1103 st[1] = " 0>>";
1104 op[1] = XEXP (x, 1);
1105 break;
1106 case ASHIFTRT:
1107 op[0] = XEXP (x, 0);
1108 st[1] = ">>";
1109 op[1] = XEXP (x, 1);
1110 break;
1111 case ROTATE:
1112 op[0] = XEXP (x, 0);
1113 st[1] = "<-<";
1114 op[1] = XEXP (x, 1);
1115 break;
1116 case ROTATERT:
1117 op[0] = XEXP (x, 0);
1118 st[1] = ">->";
1119 op[1] = XEXP (x, 1);
1120 break;
1121 case NE:
1122 op[0] = XEXP (x, 0);
1123 st[1] = "!=";
1124 op[1] = XEXP (x, 1);
1125 break;
1126 case EQ:
1127 op[0] = XEXP (x, 0);
1128 st[1] = "==";
1129 op[1] = XEXP (x, 1);
1130 break;
1131 case GE:
1132 op[0] = XEXP (x, 0);
1133 st[1] = ">=";
1134 op[1] = XEXP (x, 1);
1135 break;
1136 case GT:
1137 op[0] = XEXP (x, 0);
1138 st[1] = ">";
1139 op[1] = XEXP (x, 1);
1140 break;
1141 case LE:
1142 op[0] = XEXP (x, 0);
1143 st[1] = "<=";
1144 op[1] = XEXP (x, 1);
1145 break;
1146 case LT:
1147 op[0] = XEXP (x, 0);
1148 st[1] = "<";
1149 op[1] = XEXP (x, 1);
1150 break;
1151 case SIGN_EXTRACT:
1152 fun = (verbose) ? "sign_extract" : "sxt";
1153 op[0] = XEXP (x, 0);
1154 op[1] = XEXP (x, 1);
1155 op[2] = XEXP (x, 2);
1156 break;
1157 case ZERO_EXTRACT:
1158 fun = (verbose) ? "zero_extract" : "zxt";
1159 op[0] = XEXP (x, 0);
1160 op[1] = XEXP (x, 1);
1161 op[2] = XEXP (x, 2);
1162 break;
1163 case SIGN_EXTEND:
1164 fun = (verbose) ? "sign_extend" : "sxn";
1165 op[0] = XEXP (x, 0);
1166 break;
1167 case ZERO_EXTEND:
1168 fun = (verbose) ? "zero_extend" : "zxn";
1169 op[0] = XEXP (x, 0);
1170 break;
1171 case FLOAT_EXTEND:
1172 fun = (verbose) ? "float_extend" : "fxn";
1173 op[0] = XEXP (x, 0);
1174 break;
1175 case TRUNCATE:
1176 fun = (verbose) ? "trunc" : "trn";
1177 op[0] = XEXP (x, 0);
1178 break;
1179 case FLOAT_TRUNCATE:
1180 fun = (verbose) ? "float_trunc" : "ftr";
1181 op[0] = XEXP (x, 0);
1182 break;
1183 case FLOAT:
1184 fun = (verbose) ? "float" : "flt";
1185 op[0] = XEXP (x, 0);
1186 break;
1187 case UNSIGNED_FLOAT:
1188 fun = (verbose) ? "uns_float" : "ufl";
1189 op[0] = XEXP (x, 0);
1190 break;
1191 case FIX:
1192 fun = "fix";
1193 op[0] = XEXP (x, 0);
1194 break;
1195 case UNSIGNED_FIX:
1196 fun = (verbose) ? "uns_fix" : "ufx";
1197 op[0] = XEXP (x, 0);
1198 break;
1199 case PRE_DEC:
1200 st[0] = "--";
1201 op[0] = XEXP (x, 0);
1202 break;
1203 case PRE_INC:
1204 st[0] = "++";
1205 op[0] = XEXP (x, 0);
1206 break;
1207 case POST_DEC:
1208 op[0] = XEXP (x, 0);
1209 st[1] = "--";
1210 break;
1211 case POST_INC:
1212 op[0] = XEXP (x, 0);
1213 st[1] = "++";
1214 break;
1215 case PRE_MODIFY:
1216 st[0] = "pre ";
1217 op[0] = XEXP (XEXP (x, 1), 0);
1218 st[1] = "+=";
1219 op[1] = XEXP (XEXP (x, 1), 1);
1220 break;
1221 case POST_MODIFY:
1222 st[0] = "post ";
1223 op[0] = XEXP (XEXP (x, 1), 0);
1224 st[1] = "+=";
1225 op[1] = XEXP (XEXP (x, 1), 1);
1226 break;
1227 case CALL:
1228 st[0] = "call ";
1229 op[0] = XEXP (x, 0);
1230 if (verbose)
1232 st[1] = " argc:";
1233 op[1] = XEXP (x, 1);
1235 break;
1236 case IF_THEN_ELSE:
1237 st[0] = "{(";
1238 op[0] = XEXP (x, 0);
1239 st[1] = ")?";
1240 op[1] = XEXP (x, 1);
1241 st[2] = ":";
1242 op[2] = XEXP (x, 2);
1243 st[3] = "}";
1244 break;
1245 case TRAP_IF:
1246 fun = "trap_if";
1247 op[0] = TRAP_CONDITION (x);
1248 break;
1249 case PREFETCH:
1250 fun = "prefetch";
1251 op[0] = XEXP (x, 0);
1252 op[1] = XEXP (x, 1);
1253 op[2] = XEXP (x, 2);
1254 break;
1255 case UNSPEC:
1256 case UNSPEC_VOLATILE:
1258 pp_string (pp, "unspec");
1259 if (GET_CODE (x) == UNSPEC_VOLATILE)
1260 pp_string (pp, "/v");
1261 pp_left_bracket (pp);
1262 for (i = 0; i < XVECLEN (x, 0); i++)
1264 if (i != 0)
1265 pp_comma (pp);
1266 print_pattern (pp, XVECEXP (x, 0, i), verbose);
1268 pp_string (pp, "] ");
1269 pp_decimal_int (pp, XINT (x, 1));
1271 break;
1272 default:
1274 /* Most unhandled codes can be printed as pseudo-functions. */
1275 if (GET_RTX_CLASS (GET_CODE (x)) == RTX_UNARY)
1277 fun = GET_RTX_NAME (GET_CODE (x));
1278 op[0] = XEXP (x, 0);
1280 else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_COMPARE
1281 || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_COMPARE
1282 || GET_RTX_CLASS (GET_CODE (x)) == RTX_BIN_ARITH
1283 || GET_RTX_CLASS (GET_CODE (x)) == RTX_COMM_ARITH)
1285 fun = GET_RTX_NAME (GET_CODE (x));
1286 op[0] = XEXP (x, 0);
1287 op[1] = XEXP (x, 1);
1289 else if (GET_RTX_CLASS (GET_CODE (x)) == RTX_TERNARY)
1291 fun = GET_RTX_NAME (GET_CODE (x));
1292 op[0] = XEXP (x, 0);
1293 op[1] = XEXP (x, 1);
1294 op[2] = XEXP (x, 2);
1296 else
1297 /* Give up, just print the RTX name. */
1298 st[0] = GET_RTX_NAME (GET_CODE (x));
1300 break;
1303 /* Print this as a function? */
1304 if (fun)
1306 pp_string (pp, fun);
1307 pp_left_paren (pp);
1310 for (i = 0; i < 4; i++)
1312 if (st[i])
1313 pp_string (pp, st[i]);
1315 if (op[i])
1317 if (fun && i != 0)
1318 pp_comma (pp);
1319 print_value (pp, op[i], verbose);
1323 if (fun)
1324 pp_right_paren (pp);
1325 } /* print_exp */
1327 /* Prints rtxes, I customarily classified as values. They're constants,
1328 registers, labels, symbols and memory accesses. */
1330 void
1331 print_value (pretty_printer *pp, const_rtx x, int verbose)
1333 char tmp[1024];
1335 if (!x)
1337 pp_string (pp, "(nil)");
1338 return;
1340 switch (GET_CODE (x))
1342 case CONST_INT:
1343 pp_scalar (pp, HOST_WIDE_INT_PRINT_HEX,
1344 (unsigned HOST_WIDE_INT) INTVAL (x));
1345 break;
1347 case CONST_WIDE_INT:
1349 const char *sep = "<";
1350 int i;
1351 for (i = CONST_WIDE_INT_NUNITS (x) - 1; i >= 0; i--)
1353 pp_string (pp, sep);
1354 sep = ",";
1355 sprintf (tmp, HOST_WIDE_INT_PRINT_HEX,
1356 (unsigned HOST_WIDE_INT) CONST_WIDE_INT_ELT (x, i));
1357 pp_string (pp, tmp);
1359 pp_greater (pp);
1361 break;
1363 case CONST_DOUBLE:
1364 if (FLOAT_MODE_P (GET_MODE (x)))
1366 real_to_decimal (tmp, CONST_DOUBLE_REAL_VALUE (x),
1367 sizeof (tmp), 0, 1);
1368 pp_string (pp, tmp);
1370 else
1371 pp_printf (pp, "<%wx,%wx>",
1372 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x),
1373 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x));
1374 break;
1375 case CONST_FIXED:
1376 fixed_to_decimal (tmp, CONST_FIXED_VALUE (x), sizeof (tmp));
1377 pp_string (pp, tmp);
1378 break;
1379 case CONST_STRING:
1380 pp_printf (pp, "\"%s\"", XSTR (x, 0));
1381 break;
1382 case SYMBOL_REF:
1383 pp_printf (pp, "`%s'", XSTR (x, 0));
1384 break;
1385 case LABEL_REF:
1386 pp_printf (pp, "L%d", INSN_UID (LABEL_REF_LABEL (x)));
1387 break;
1388 case CONST:
1389 case HIGH:
1390 case STRICT_LOW_PART:
1391 pp_printf (pp, "%s(", GET_RTX_NAME (GET_CODE (x)));
1392 print_value (pp, XEXP (x, 0), verbose);
1393 pp_right_paren (pp);
1394 break;
1395 case REG:
1396 if (REGNO (x) < FIRST_PSEUDO_REGISTER)
1398 if (ISDIGIT (reg_names[REGNO (x)][0]))
1399 pp_modulo (pp);
1400 pp_string (pp, reg_names[REGNO (x)]);
1402 else
1403 pp_printf (pp, "r%d", REGNO (x));
1404 if (verbose)
1405 pp_printf (pp, ":%s", GET_MODE_NAME (GET_MODE (x)));
1406 break;
1407 case SUBREG:
1408 print_value (pp, SUBREG_REG (x), verbose);
1409 pp_printf (pp, "#%d", SUBREG_BYTE (x));
1410 break;
1411 case SCRATCH:
1412 case CC0:
1413 case PC:
1414 pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
1415 break;
1416 case MEM:
1417 pp_left_bracket (pp);
1418 print_value (pp, XEXP (x, 0), verbose);
1419 pp_right_bracket (pp);
1420 break;
1421 case DEBUG_EXPR:
1422 pp_printf (pp, "D#%i", DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x)));
1423 break;
1424 default:
1425 print_exp (pp, x, verbose);
1426 break;
1428 } /* print_value */
1430 /* The next step in insn detalization, its pattern recognition. */
1432 void
1433 print_pattern (pretty_printer *pp, const_rtx x, int verbose)
1435 if (! x)
1437 pp_string (pp, "(nil)");
1438 return;
1441 switch (GET_CODE (x))
1443 case SET:
1444 print_value (pp, SET_DEST (x), verbose);
1445 pp_equal (pp);
1446 print_value (pp, SET_SRC (x), verbose);
1447 break;
1448 case RETURN:
1449 case SIMPLE_RETURN:
1450 case EH_RETURN:
1451 pp_string (pp, GET_RTX_NAME (GET_CODE (x)));
1452 break;
1453 case CALL:
1454 print_exp (pp, x, verbose);
1455 break;
1456 case CLOBBER:
1457 case USE:
1458 pp_printf (pp, "%s ", GET_RTX_NAME (GET_CODE (x)));
1459 print_value (pp, XEXP (x, 0), verbose);
1460 break;
1461 case VAR_LOCATION:
1462 pp_string (pp, "loc ");
1463 print_value (pp, PAT_VAR_LOCATION_LOC (x), verbose);
1464 break;
1465 case COND_EXEC:
1466 pp_left_paren (pp);
1467 if (GET_CODE (COND_EXEC_TEST (x)) == NE
1468 && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
1469 print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
1470 else if (GET_CODE (COND_EXEC_TEST (x)) == EQ
1471 && XEXP (COND_EXEC_TEST (x), 1) == const0_rtx)
1473 pp_exclamation (pp);
1474 print_value (pp, XEXP (COND_EXEC_TEST (x), 0), verbose);
1476 else
1477 print_value (pp, COND_EXEC_TEST (x), verbose);
1478 pp_string (pp, ") ");
1479 print_pattern (pp, COND_EXEC_CODE (x), verbose);
1480 break;
1481 case PARALLEL:
1483 int i;
1485 pp_left_brace (pp);
1486 for (i = 0; i < XVECLEN (x, 0); i++)
1488 print_pattern (pp, XVECEXP (x, 0, i), verbose);
1489 pp_semicolon (pp);
1491 pp_right_brace (pp);
1493 break;
1494 case SEQUENCE:
1496 const rtx_sequence *seq = as_a <const rtx_sequence *> (x);
1497 pp_string (pp, "sequence{");
1498 if (INSN_P (seq->element (0)))
1500 /* Print the sequence insns indented. */
1501 const char * save_print_rtx_head = print_rtx_head;
1502 char indented_print_rtx_head[32];
1504 pp_newline (pp);
1505 gcc_assert (strlen (print_rtx_head) < sizeof (indented_print_rtx_head) - 4);
1506 snprintf (indented_print_rtx_head,
1507 sizeof (indented_print_rtx_head),
1508 "%s ", print_rtx_head);
1509 print_rtx_head = indented_print_rtx_head;
1510 for (int i = 0; i < seq->len (); i++)
1511 print_insn_with_notes (pp, seq->insn (i));
1512 pp_printf (pp, "%s ", save_print_rtx_head);
1513 print_rtx_head = save_print_rtx_head;
1515 else
1517 for (int i = 0; i < seq->len (); i++)
1519 print_pattern (pp, seq->element (i), verbose);
1520 pp_semicolon (pp);
1523 pp_right_brace (pp);
1525 break;
1526 case ASM_INPUT:
1527 pp_printf (pp, "asm {%s}", XSTR (x, 0));
1528 break;
1529 case ADDR_VEC:
1530 for (int i = 0; i < XVECLEN (x, 0); i++)
1532 print_value (pp, XVECEXP (x, 0, i), verbose);
1533 pp_semicolon (pp);
1535 break;
1536 case ADDR_DIFF_VEC:
1537 for (int i = 0; i < XVECLEN (x, 1); i++)
1539 print_value (pp, XVECEXP (x, 1, i), verbose);
1540 pp_semicolon (pp);
1542 break;
1543 case TRAP_IF:
1544 pp_string (pp, "trap_if ");
1545 print_value (pp, TRAP_CONDITION (x), verbose);
1546 break;
1547 case UNSPEC:
1548 case UNSPEC_VOLATILE:
1549 /* Fallthru -- leave UNSPECs to print_exp. */
1550 default:
1551 print_value (pp, x, verbose);
1553 } /* print_pattern */
1555 /* This is the main function in slim rtl visualization mechanism.
1557 X is an insn, to be printed into PP.
1559 This function tries to print it properly in human-readable form,
1560 resembling assembler mnemonics (instead of the older Lisp-style
1561 form).
1563 If VERBOSE is TRUE, insns are printed with more complete (but
1564 longer) pattern names and with extra information, and prefixed
1565 with their INSN_UIDs. */
1567 void
1568 print_insn (pretty_printer *pp, const rtx_insn *x, int verbose)
1570 if (verbose)
1572 /* Blech, pretty-print can't print integers with a specified width. */
1573 char uid_prefix[32];
1574 snprintf (uid_prefix, sizeof uid_prefix, " %4d: ", INSN_UID (x));
1575 pp_string (pp, uid_prefix);
1578 switch (GET_CODE (x))
1580 case INSN:
1581 print_pattern (pp, PATTERN (x), verbose);
1582 break;
1584 case DEBUG_INSN:
1586 const char *name = "?";
1588 if (DECL_P (INSN_VAR_LOCATION_DECL (x)))
1590 tree id = DECL_NAME (INSN_VAR_LOCATION_DECL (x));
1591 char idbuf[32];
1592 if (id)
1593 name = IDENTIFIER_POINTER (id);
1594 else if (TREE_CODE (INSN_VAR_LOCATION_DECL (x))
1595 == DEBUG_EXPR_DECL)
1597 sprintf (idbuf, "D#%i",
1598 DEBUG_TEMP_UID (INSN_VAR_LOCATION_DECL (x)));
1599 name = idbuf;
1601 else
1603 sprintf (idbuf, "D.%i",
1604 DECL_UID (INSN_VAR_LOCATION_DECL (x)));
1605 name = idbuf;
1608 pp_printf (pp, "debug %s => ", name);
1609 if (VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (x)))
1610 pp_string (pp, "optimized away");
1611 else
1612 print_pattern (pp, INSN_VAR_LOCATION_LOC (x), verbose);
1614 break;
1616 case JUMP_INSN:
1617 print_pattern (pp, PATTERN (x), verbose);
1618 break;
1619 case CALL_INSN:
1620 if (GET_CODE (PATTERN (x)) == PARALLEL)
1621 print_pattern (pp, XVECEXP (PATTERN (x), 0, 0), verbose);
1622 else
1623 print_pattern (pp, PATTERN (x), verbose);
1624 break;
1625 case CODE_LABEL:
1626 pp_printf (pp, "L%d:", INSN_UID (x));
1627 break;
1628 case JUMP_TABLE_DATA:
1629 pp_string (pp, "jump_table_data{\n");
1630 print_pattern (pp, PATTERN (x), verbose);
1631 pp_right_brace (pp);
1632 break;
1633 case BARRIER:
1634 pp_string (pp, "barrier");
1635 break;
1636 case NOTE:
1638 pp_string (pp, GET_NOTE_INSN_NAME (NOTE_KIND (x)));
1639 switch (NOTE_KIND (x))
1641 case NOTE_INSN_EH_REGION_BEG:
1642 case NOTE_INSN_EH_REGION_END:
1643 pp_printf (pp, " %d", NOTE_EH_HANDLER (x));
1644 break;
1646 case NOTE_INSN_BLOCK_BEG:
1647 case NOTE_INSN_BLOCK_END:
1648 pp_printf (pp, " %d", BLOCK_NUMBER (NOTE_BLOCK (x)));
1649 break;
1651 case NOTE_INSN_BASIC_BLOCK:
1652 pp_printf (pp, " %d", NOTE_BASIC_BLOCK (x)->index);
1653 break;
1655 case NOTE_INSN_DELETED_LABEL:
1656 case NOTE_INSN_DELETED_DEBUG_LABEL:
1658 const char *label = NOTE_DELETED_LABEL_NAME (x);
1659 if (label == NULL)
1660 label = "";
1661 pp_printf (pp, " (\"%s\")", label);
1663 break;
1665 case NOTE_INSN_VAR_LOCATION:
1666 case NOTE_INSN_CALL_ARG_LOCATION:
1667 pp_left_brace (pp);
1668 print_pattern (pp, NOTE_VAR_LOCATION (x), verbose);
1669 pp_right_brace (pp);
1670 break;
1672 default:
1673 break;
1675 break;
1677 default:
1678 gcc_unreachable ();
1680 } /* print_insn */
1682 /* Pretty-print a slim dump of X (an insn) to PP, including any register
1683 note attached to the instruction. */
1685 static void
1686 print_insn_with_notes (pretty_printer *pp, const rtx_insn *x)
1688 pp_string (pp, print_rtx_head);
1689 print_insn (pp, x, 1);
1690 pp_newline (pp);
1691 if (INSN_P (x) && REG_NOTES (x))
1692 for (rtx note = REG_NOTES (x); note; note = XEXP (note, 1))
1694 pp_printf (pp, "%s %s ", print_rtx_head,
1695 GET_REG_NOTE_NAME (REG_NOTE_KIND (note)));
1696 if (GET_CODE (note) == INT_LIST)
1697 pp_printf (pp, "%d", XINT (note, 0));
1698 else
1699 print_pattern (pp, XEXP (note, 0), 1);
1700 pp_newline (pp);
1704 /* Print X, an RTL value node, to file F in slim format. Include
1705 additional information if VERBOSE is nonzero.
1707 Value nodes are constants, registers, labels, symbols and
1708 memory. */
1710 void
1711 dump_value_slim (FILE *f, const_rtx x, int verbose)
1713 pretty_printer rtl_slim_pp;
1714 rtl_slim_pp.buffer->stream = f;
1715 print_value (&rtl_slim_pp, x, verbose);
1716 pp_flush (&rtl_slim_pp);
1719 /* Emit a slim dump of X (an insn) to the file F, including any register
1720 note attached to the instruction. */
1721 void
1722 dump_insn_slim (FILE *f, const rtx_insn *x)
1724 pretty_printer rtl_slim_pp;
1725 rtl_slim_pp.buffer->stream = f;
1726 print_insn_with_notes (&rtl_slim_pp, x);
1727 pp_flush (&rtl_slim_pp);
1730 /* Same as above, but stop at LAST or when COUNT == 0.
1731 If COUNT < 0 it will stop only at LAST or NULL rtx. */
1733 void
1734 dump_rtl_slim (FILE *f, const rtx_insn *first, const rtx_insn *last,
1735 int count, int flags ATTRIBUTE_UNUSED)
1737 const rtx_insn *insn, *tail;
1738 pretty_printer rtl_slim_pp;
1739 rtl_slim_pp.buffer->stream = f;
1741 tail = last ? NEXT_INSN (last) : NULL;
1742 for (insn = first;
1743 (insn != NULL) && (insn != tail) && (count != 0);
1744 insn = NEXT_INSN (insn))
1746 print_insn_with_notes (&rtl_slim_pp, insn);
1747 if (count > 0)
1748 count--;
1751 pp_flush (&rtl_slim_pp);
1754 /* Dumps basic block BB to pretty-printer PP in slim form and without and
1755 no indentation, for use as a label of a DOT graph record-node. */
1757 void
1758 rtl_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
1760 rtx_insn *insn;
1761 bool first = true;
1763 /* TODO: inter-bb stuff. */
1764 FOR_BB_INSNS (bb, insn)
1766 if (! first)
1768 pp_bar (pp);
1769 pp_write_text_to_stream (pp);
1771 first = false;
1772 print_insn_with_notes (pp, insn);
1773 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
1777 /* Pretty-print pattern X of some insn in non-verbose mode.
1778 Return a string pointer to the pretty-printer buffer.
1780 This function is only exported exists only to accommodate some older users
1781 of the slim RTL pretty printers. Please do not use it for new code. */
1783 const char *
1784 str_pattern_slim (const_rtx x)
1786 pretty_printer rtl_slim_pp;
1787 print_pattern (&rtl_slim_pp, x, 0);
1788 return ggc_strdup (pp_formatted_text (&rtl_slim_pp));
1791 /* Emit a slim dump of X (an insn) to stderr. */
1792 extern void debug_insn_slim (const rtx_insn *);
1793 DEBUG_FUNCTION void
1794 debug_insn_slim (const rtx_insn *x)
1796 dump_insn_slim (stderr, x);
1799 /* Same as above, but using dump_rtl_slim. */
1800 extern void debug_rtl_slim (FILE *, const rtx_insn *, const rtx_insn *,
1801 int, int);
1802 DEBUG_FUNCTION void
1803 debug_rtl_slim (const rtx_insn *first, const rtx_insn *last, int count,
1804 int flags)
1806 dump_rtl_slim (stderr, first, last, count, flags);
1809 extern void debug_bb_slim (basic_block);
1810 DEBUG_FUNCTION void
1811 debug_bb_slim (basic_block bb)
1813 dump_bb (stderr, bb, 0, TDF_SLIM | TDF_BLOCKS);
1816 extern void debug_bb_n_slim (int);
1817 DEBUG_FUNCTION void
1818 debug_bb_n_slim (int n)
1820 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, n);
1821 debug_bb_slim (bb);
1824 #endif