PR libstdc++/67078
[official-gcc.git] / gcc / print-rtl.c
blobaacadbb9b4490954a64eece2d7f97317dcd6bc4e
1 /* Print RTL for GCC.
2 Copyright (C) 1987-2015 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 "print-tree.h"
39 #include "flags.h"
40 #include "predict.h"
41 #include "function.h"
42 #include "basic-block.h"
43 #include "diagnostic.h"
44 #include "tree-pretty-print.h"
45 #include "alloc-pool.h"
46 #include "cselib.h"
47 #include "dumpfile.h" /* for dump_flags */
48 #include "dwarf2out.h"
49 #endif
51 static FILE *outfile;
53 static int sawclose = 0;
55 static int indent;
57 static bool in_call_function_usage;
59 static void print_rtx (const_rtx);
61 /* String printed at beginning of each RTL when it is dumped.
62 This string is set to ASM_COMMENT_START when the RTL is dumped in
63 the assembly output file. */
64 const char *print_rtx_head = "";
66 #ifdef GENERATOR_FILE
67 /* These are defined from the .opt file when not used in generator
68 programs. */
70 /* Nonzero means suppress output of instruction numbers
71 in debugging dumps.
72 This must be defined here so that programs like gencodes can be linked. */
73 int flag_dump_unnumbered = 0;
75 /* Nonzero means suppress output of instruction numbers for previous
76 and next insns in debugging dumps.
77 This must be defined here so that programs like gencodes can be linked. */
78 int flag_dump_unnumbered_links = 0;
79 #endif
81 /* Nonzero means use simplified format without flags, modes, etc. */
82 int flag_simple = 0;
84 #ifndef GENERATOR_FILE
85 void
86 print_mem_expr (FILE *outfile, const_tree expr)
88 fputc (' ', outfile);
89 print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
91 #endif
93 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
95 static void
96 print_rtx (const_rtx in_rtx)
98 int i = 0;
99 int j;
100 const char *format_ptr;
101 int is_insn;
103 if (sawclose)
105 if (flag_simple)
106 fputc (' ', outfile);
107 else
108 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
109 sawclose = 0;
112 if (in_rtx == 0)
114 fputs ("(nil)", outfile);
115 sawclose = 1;
116 return;
118 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
120 fprintf (outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
121 print_rtx_head, indent * 2, "");
122 sawclose = 1;
123 return;
126 is_insn = INSN_P (in_rtx);
128 /* Print name of expression code. */
129 if (flag_simple && CONST_INT_P (in_rtx))
130 fputc ('(', outfile);
131 else
132 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
134 if (! flag_simple)
136 if (RTX_FLAG (in_rtx, in_struct))
137 fputs ("/s", outfile);
139 if (RTX_FLAG (in_rtx, volatil))
140 fputs ("/v", outfile);
142 if (RTX_FLAG (in_rtx, unchanging))
143 fputs ("/u", outfile);
145 if (RTX_FLAG (in_rtx, frame_related))
146 fputs ("/f", outfile);
148 if (RTX_FLAG (in_rtx, jump))
149 fputs ("/j", outfile);
151 if (RTX_FLAG (in_rtx, call))
152 fputs ("/c", outfile);
154 if (RTX_FLAG (in_rtx, return_val))
155 fputs ("/i", outfile);
157 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
158 if ((GET_CODE (in_rtx) == EXPR_LIST
159 || GET_CODE (in_rtx) == INSN_LIST
160 || GET_CODE (in_rtx) == INT_LIST)
161 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX
162 && !in_call_function_usage)
163 fprintf (outfile, ":%s",
164 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
166 /* For other rtl, print the mode if it's not VOID. */
167 else if (GET_MODE (in_rtx) != VOIDmode)
168 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
170 #ifndef GENERATOR_FILE
171 if (GET_CODE (in_rtx) == VAR_LOCATION)
173 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
174 fputs (" <debug string placeholder>", outfile);
175 else
176 print_mem_expr (outfile, PAT_VAR_LOCATION_DECL (in_rtx));
177 fputc (' ', outfile);
178 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
179 if (PAT_VAR_LOCATION_STATUS (in_rtx)
180 == VAR_INIT_STATUS_UNINITIALIZED)
181 fprintf (outfile, " [uninit]");
182 sawclose = 1;
183 i = GET_RTX_LENGTH (VAR_LOCATION);
185 #endif
188 #ifndef GENERATOR_FILE
189 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx))
190 i = 5;
191 #endif
193 if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx)))
195 if (flag_dump_unnumbered)
196 fprintf (outfile, " #");
197 else
198 fprintf (outfile, " %d", INSN_UID (in_rtx));
201 /* Get the format string and skip the first elements if we have handled
202 them already. */
203 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
204 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
205 switch (*format_ptr++)
207 const char *str;
209 case 'T':
210 str = XTMPL (in_rtx, i);
211 goto string;
213 case 'S':
214 case 's':
215 str = XSTR (in_rtx, i);
216 string:
218 if (str == 0)
219 fputs (" \"\"", outfile);
220 else
221 fprintf (outfile, " (\"%s\")", str);
222 sawclose = 1;
223 break;
225 /* 0 indicates a field for internal use that should not be printed.
226 An exception is the third field of a NOTE, where it indicates
227 that the field has several different valid contents. */
228 case '0':
229 #ifndef GENERATOR_FILE
230 if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
232 int flags = SYMBOL_REF_FLAGS (in_rtx);
233 if (flags)
234 fprintf (outfile, " [flags %#x]", flags);
235 tree decl = SYMBOL_REF_DECL (in_rtx);
236 if (decl)
237 print_node_brief (outfile, "", decl, dump_flags);
239 else if (i == 3 && NOTE_P (in_rtx))
241 switch (NOTE_KIND (in_rtx))
243 case NOTE_INSN_EH_REGION_BEG:
244 case NOTE_INSN_EH_REGION_END:
245 if (flag_dump_unnumbered)
246 fprintf (outfile, " #");
247 else
248 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
249 sawclose = 1;
250 break;
252 case NOTE_INSN_BLOCK_BEG:
253 case NOTE_INSN_BLOCK_END:
254 dump_addr (outfile, " ", NOTE_BLOCK (in_rtx));
255 sawclose = 1;
256 break;
258 case NOTE_INSN_BASIC_BLOCK:
260 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
261 if (bb != 0)
262 fprintf (outfile, " [bb %d]", bb->index);
263 break;
266 case NOTE_INSN_DELETED_LABEL:
267 case NOTE_INSN_DELETED_DEBUG_LABEL:
269 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
270 if (label)
271 fprintf (outfile, " (\"%s\")", label);
272 else
273 fprintf (outfile, " \"\"");
275 break;
277 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
279 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
280 if (bb != 0)
281 fprintf (outfile, " [bb %d]", bb->index);
282 break;
285 case NOTE_INSN_VAR_LOCATION:
286 case NOTE_INSN_CALL_ARG_LOCATION:
287 fputc (' ', outfile);
288 print_rtx (NOTE_VAR_LOCATION (in_rtx));
289 break;
291 case NOTE_INSN_CFI:
292 fputc ('\n', outfile);
293 output_cfi_directive (outfile, NOTE_CFI (in_rtx));
294 fputc ('\t', outfile);
295 break;
297 default:
298 break;
301 else if (i == 7 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL)
303 /* Output the JUMP_LABEL reference. */
304 fprintf (outfile, "\n%s%*s -> ", print_rtx_head, indent * 2, "");
305 if (GET_CODE (JUMP_LABEL (in_rtx)) == RETURN)
306 fprintf (outfile, "return");
307 else if (GET_CODE (JUMP_LABEL (in_rtx)) == SIMPLE_RETURN)
308 fprintf (outfile, "simple_return");
309 else
310 fprintf (outfile, "%d", INSN_UID (JUMP_LABEL (in_rtx)));
312 else if (i == 0 && GET_CODE (in_rtx) == VALUE)
314 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
316 fprintf (outfile, " %u:%u", val->uid, val->hash);
317 dump_addr (outfile, " @", in_rtx);
318 dump_addr (outfile, "/", (void*)val);
320 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
322 fprintf (outfile, " D#%i",
323 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
325 else if (i == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
327 indent += 2;
328 if (!sawclose)
329 fprintf (outfile, " ");
330 print_rtx (ENTRY_VALUE_EXP (in_rtx));
331 indent -= 2;
333 #endif
334 break;
336 case 'e':
337 do_e:
338 indent += 2;
339 if (i == 6 && INSN_P (in_rtx))
340 /* Put REG_NOTES on their own line. */
341 fprintf (outfile, "\n%s%*s",
342 print_rtx_head, indent * 2, "");
343 if (!sawclose)
344 fprintf (outfile, " ");
345 if (i == 7 && CALL_P (in_rtx))
347 in_call_function_usage = true;
348 print_rtx (XEXP (in_rtx, i));
349 in_call_function_usage = false;
351 else
352 print_rtx (XEXP (in_rtx, i));
353 indent -= 2;
354 break;
356 case 'E':
357 case 'V':
358 indent += 2;
359 if (sawclose)
361 fprintf (outfile, "\n%s%*s",
362 print_rtx_head, indent * 2, "");
363 sawclose = 0;
365 fputs (" [", outfile);
366 if (NULL != XVEC (in_rtx, i))
368 indent += 2;
369 if (XVECLEN (in_rtx, i))
370 sawclose = 1;
372 for (j = 0; j < XVECLEN (in_rtx, i); j++)
373 print_rtx (XVECEXP (in_rtx, i, j));
375 indent -= 2;
377 if (sawclose)
378 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
380 fputs ("]", outfile);
381 sawclose = 1;
382 indent -= 2;
383 break;
385 case 'w':
386 if (! flag_simple)
387 fprintf (outfile, " ");
388 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
389 if (! flag_simple)
390 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
391 (unsigned HOST_WIDE_INT) XWINT (in_rtx, i));
392 break;
394 case 'i':
395 if (i == 4 && INSN_P (in_rtx))
397 #ifndef GENERATOR_FILE
398 const rtx_insn *in_insn = as_a <const rtx_insn *> (in_rtx);
400 /* Pretty-print insn locations. Ignore scoping as it is mostly
401 redundant with line number information and do not print anything
402 when there is no location information available. */
403 if (INSN_HAS_LOCATION (in_insn))
405 expanded_location xloc = insn_location (in_insn);
406 fprintf (outfile, " %s:%i", xloc.file, xloc.line);
408 #endif
410 else if (i == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
412 #ifndef GENERATOR_FILE
413 if (ASM_OPERANDS_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
414 fprintf (outfile, " %s:%i",
415 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
416 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
417 #endif
419 else if (i == 1 && GET_CODE (in_rtx) == ASM_INPUT)
421 #ifndef GENERATOR_FILE
422 if (ASM_INPUT_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
423 fprintf (outfile, " %s:%i",
424 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
425 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
426 #endif
428 else if (i == 5 && NOTE_P (in_rtx))
430 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
431 other times often contains garbage from INSN->NOTE death. */
432 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL
433 || NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_DEBUG_LABEL)
434 fprintf (outfile, " %d", XINT (in_rtx, i));
436 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
437 else if (i == 1
438 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
439 && XINT (in_rtx, 1) >= 0
440 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
441 fprintf (outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
442 #endif
443 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
444 else if (i == 1
445 && (GET_CODE (in_rtx) == UNSPEC
446 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
447 && XINT (in_rtx, 1) >= 0
448 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
449 fprintf (outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
450 #endif
451 else
453 int value = XINT (in_rtx, i);
454 const char *name;
456 if (flag_dump_unnumbered
457 && (is_insn || NOTE_P (in_rtx)))
458 fputc ('#', outfile);
459 else
460 fprintf (outfile, " %d", value);
462 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
463 && XINT (in_rtx, i) >= 0
464 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
465 fprintf (outfile, " {%s}", name);
466 sawclose = 0;
468 break;
470 case 'r':
472 unsigned int regno = REGNO (in_rtx);
473 #ifndef GENERATOR_FILE
474 if (regno < FIRST_PSEUDO_REGISTER)
475 fprintf (outfile, " %d %s", regno, reg_names[regno]);
476 else if (regno <= LAST_VIRTUAL_REGISTER)
478 if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
479 fprintf (outfile, " %d virtual-incoming-args", regno);
480 else if (regno == VIRTUAL_STACK_VARS_REGNUM)
481 fprintf (outfile, " %d virtual-stack-vars", regno);
482 else if (regno == VIRTUAL_STACK_DYNAMIC_REGNUM)
483 fprintf (outfile, " %d virtual-stack-dynamic", regno);
484 else if (regno == VIRTUAL_OUTGOING_ARGS_REGNUM)
485 fprintf (outfile, " %d virtual-outgoing-args", regno);
486 else if (regno == VIRTUAL_CFA_REGNUM)
487 fprintf (outfile, " %d virtual-cfa", regno);
488 else if (regno == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
489 fprintf (outfile, " %d virtual-preferred-stack-boundary",
490 regno);
491 else
492 fprintf (outfile, " %d virtual-reg-%d", regno,
493 regno-FIRST_VIRTUAL_REGISTER);
495 else
496 #endif
497 if (flag_dump_unnumbered && is_insn)
498 fputc ('#', outfile);
499 else
500 fprintf (outfile, " %d", regno);
502 #ifndef GENERATOR_FILE
503 if (REG_ATTRS (in_rtx))
505 fputs (" [", outfile);
506 if (regno != ORIGINAL_REGNO (in_rtx))
507 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
508 if (REG_EXPR (in_rtx))
509 print_mem_expr (outfile, REG_EXPR (in_rtx));
511 if (REG_OFFSET (in_rtx))
512 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
513 REG_OFFSET (in_rtx));
514 fputs (" ]", outfile);
516 if (regno != ORIGINAL_REGNO (in_rtx))
517 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
518 #endif
519 break;
522 /* Print NOTE_INSN names rather than integer codes. */
524 case 'n':
525 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
526 sawclose = 0;
527 break;
529 case 'u':
530 if (XEXP (in_rtx, i) != NULL)
532 rtx sub = XEXP (in_rtx, i);
533 enum rtx_code subc = GET_CODE (sub);
535 if (GET_CODE (in_rtx) == LABEL_REF)
537 if (subc == NOTE
538 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
540 if (flag_dump_unnumbered)
541 fprintf (outfile, " [# deleted]");
542 else
543 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
544 sawclose = 0;
545 break;
548 if (subc != CODE_LABEL)
549 goto do_e;
552 if (flag_dump_unnumbered
553 || (flag_dump_unnumbered_links && (i == 1 || i == 2)
554 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
555 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
556 fputs (" #", outfile);
557 else
558 fprintf (outfile, " %d", INSN_UID (sub));
560 else
561 fputs (" 0", outfile);
562 sawclose = 0;
563 break;
565 case 't':
566 #ifndef GENERATOR_FILE
567 if (i == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
568 print_mem_expr (outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
569 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
570 print_mem_expr (outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
571 else
572 dump_addr (outfile, " ", XTREE (in_rtx, i));
573 #endif
574 break;
576 case '*':
577 fputs (" Unknown", outfile);
578 sawclose = 0;
579 break;
581 case 'B':
582 #ifndef GENERATOR_FILE
583 if (XBBDEF (in_rtx, i))
584 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
585 #endif
586 break;
588 default:
589 gcc_unreachable ();
592 switch (GET_CODE (in_rtx))
594 #ifndef GENERATOR_FILE
595 case MEM:
596 if (__builtin_expect (final_insns_dump_p, false))
597 fprintf (outfile, " [");
598 else
599 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC,
600 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
602 if (MEM_EXPR (in_rtx))
603 print_mem_expr (outfile, MEM_EXPR (in_rtx));
604 else
605 fputc (' ', outfile);
607 if (MEM_OFFSET_KNOWN_P (in_rtx))
608 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC, MEM_OFFSET (in_rtx));
610 if (MEM_SIZE_KNOWN_P (in_rtx))
611 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC, MEM_SIZE (in_rtx));
613 if (MEM_ALIGN (in_rtx) != 1)
614 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
616 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
617 fprintf (outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
619 fputc (']', outfile);
620 break;
622 case CONST_DOUBLE:
623 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
625 char s[60];
627 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
628 sizeof (s), 0, 1);
629 fprintf (outfile, " %s", s);
631 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
632 sizeof (s), 0, 1);
633 fprintf (outfile, " [%s]", s);
635 break;
637 case CONST_WIDE_INT:
638 fprintf (outfile, " ");
639 cwi_output_hex (outfile, in_rtx);
640 break;
641 #endif
643 case CODE_LABEL:
644 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
645 switch (LABEL_KIND (in_rtx))
647 case LABEL_NORMAL: break;
648 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
649 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
650 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
651 default: gcc_unreachable ();
653 break;
655 default:
656 break;
659 fputc (')', outfile);
660 sawclose = 1;
663 /* Print an rtx on the current line of FILE. Initially indent IND
664 characters. */
666 void
667 print_inline_rtx (FILE *outf, const_rtx x, int ind)
669 int oldsaw = sawclose;
670 int oldindent = indent;
672 sawclose = 0;
673 indent = ind;
674 outfile = outf;
675 print_rtx (x);
676 sawclose = oldsaw;
677 indent = oldindent;
680 /* Call this function from the debugger to see what X looks like. */
682 DEBUG_FUNCTION void
683 debug_rtx (const_rtx x)
685 outfile = stderr;
686 sawclose = 0;
687 print_rtx (x);
688 fprintf (stderr, "\n");
691 /* Dump rtx REF. */
693 DEBUG_FUNCTION void
694 debug (const rtx_def &ref)
696 debug_rtx (&ref);
699 DEBUG_FUNCTION void
700 debug (const rtx_def *ptr)
702 if (ptr)
703 debug (*ptr);
704 else
705 fprintf (stderr, "<nil>\n");
708 /* Count of rtx's to print with debug_rtx_list.
709 This global exists because gdb user defined commands have no arguments. */
711 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
713 /* Call this function to print list from X on.
715 N is a count of the rtx's to print. Positive values print from the specified
716 rtx_insn on. Negative values print a window around the rtx_insn.
717 EG: -5 prints 2 rtx_insn's on either side (in addition to the specified
718 rtx_insn). */
720 DEBUG_FUNCTION void
721 debug_rtx_list (const rtx_insn *x, int n)
723 int i,count;
724 const rtx_insn *insn;
726 count = n == 0 ? 1 : n < 0 ? -n : n;
728 /* If we are printing a window, back up to the start. */
730 if (n < 0)
731 for (i = count / 2; i > 0; i--)
733 if (PREV_INSN (x) == 0)
734 break;
735 x = PREV_INSN (x);
738 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
740 debug_rtx (insn);
741 fprintf (stderr, "\n");
745 /* Call this function to print an rtx_insn list from START to END
746 inclusive. */
748 DEBUG_FUNCTION void
749 debug_rtx_range (const rtx_insn *start, const rtx_insn *end)
751 while (1)
753 debug_rtx (start);
754 fprintf (stderr, "\n");
755 if (!start || start == end)
756 break;
757 start = NEXT_INSN (start);
761 /* Call this function to search an rtx_insn list to find one with insn uid UID,
762 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
763 The found insn is returned to enable further debugging analysis. */
765 DEBUG_FUNCTION const rtx_insn *
766 debug_rtx_find (const rtx_insn *x, int uid)
768 while (x != 0 && INSN_UID (x) != uid)
769 x = NEXT_INSN (x);
770 if (x != 0)
772 debug_rtx_list (x, debug_rtx_count);
773 return x;
775 else
777 fprintf (stderr, "insn uid %d not found\n", uid);
778 return 0;
782 /* External entry point for printing a chain of insns
783 starting with RTX_FIRST onto file OUTF.
784 A blank line separates insns.
786 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
788 void
789 print_rtl (FILE *outf, const_rtx rtx_first)
791 const rtx_insn *tmp_rtx;
793 outfile = outf;
794 sawclose = 0;
796 if (rtx_first == 0)
798 fputs (print_rtx_head, outf);
799 fputs ("(nil)\n", outf);
801 else
802 switch (GET_CODE (rtx_first))
804 case INSN:
805 case JUMP_INSN:
806 case CALL_INSN:
807 case NOTE:
808 case CODE_LABEL:
809 case JUMP_TABLE_DATA:
810 case BARRIER:
811 for (tmp_rtx = as_a <const rtx_insn *> (rtx_first);
812 tmp_rtx != 0;
813 tmp_rtx = NEXT_INSN (tmp_rtx))
815 fputs (print_rtx_head, outfile);
816 print_rtx (tmp_rtx);
817 fprintf (outfile, "\n");
819 break;
821 default:
822 fputs (print_rtx_head, outfile);
823 print_rtx (rtx_first);
827 /* Like print_rtx, except specify a file. */
828 /* Return nonzero if we actually printed anything. */
831 print_rtl_single (FILE *outf, const_rtx x)
833 return print_rtl_single_with_indent (outf, x, 0);
836 /* Like print_rtl_single, except specify a file and indentation. */
839 print_rtl_single_with_indent (FILE *outf, const_rtx x, int ind)
841 int old_indent = indent;
842 char *s_indent = (char *) alloca ((size_t) ind + 1);
843 memset ((void *) s_indent, ' ', (size_t) ind);
844 s_indent[ind] = '\0';
846 indent = ind;
847 outfile = outf;
848 sawclose = 0;
849 fputs (s_indent, outfile);
850 fputs (print_rtx_head, outfile);
851 print_rtx (x);
852 putc ('\n', outf);
853 indent = old_indent;
854 return 1;
858 /* Like print_rtl except without all the detail; for example,
859 if RTX is a CONST_INT then print in decimal format. */
861 void
862 print_simple_rtl (FILE *outf, const_rtx x)
864 flag_simple = 1;
865 print_rtl (outf, x);
866 flag_simple = 0;