[AArch64] PR target/65491: Classify V1TF vectors as AAPCS64 short vectors rather...
[official-gcc.git] / gcc / print-rtl.c
blob882f808b1a2815e188cf82dcf33c3b6bfefd64d2
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 "hash-set.h"
37 #include "machmode.h"
38 #include "vec.h"
39 #include "double-int.h"
40 #include "input.h"
41 #include "alias.h"
42 #include "symtab.h"
43 #include "wide-int.h"
44 #include "inchash.h"
45 #include "tree.h"
46 #include "print-tree.h"
47 #include "flags.h"
48 #include "hard-reg-set.h"
49 #include "predict.h"
50 #include "input.h"
51 #include "function.h"
52 #include "basic-block.h"
53 #include "diagnostic.h"
54 #include "tree-pretty-print.h"
55 #include "cselib.h"
56 #include "dumpfile.h" /* for dump_flags */
57 #include "dwarf2out.h"
58 #endif
60 static FILE *outfile;
62 static int sawclose = 0;
64 static int indent;
66 static bool in_call_function_usage;
68 static void print_rtx (const_rtx);
70 /* String printed at beginning of each RTL when it is dumped.
71 This string is set to ASM_COMMENT_START when the RTL is dumped in
72 the assembly output file. */
73 const char *print_rtx_head = "";
75 #ifdef GENERATOR_FILE
76 /* These are defined from the .opt file when not used in generator
77 programs. */
79 /* Nonzero means suppress output of instruction numbers
80 in debugging dumps.
81 This must be defined here so that programs like gencodes can be linked. */
82 int flag_dump_unnumbered = 0;
84 /* Nonzero means suppress output of instruction numbers for previous
85 and next insns in debugging dumps.
86 This must be defined here so that programs like gencodes can be linked. */
87 int flag_dump_unnumbered_links = 0;
88 #endif
90 /* Nonzero means use simplified format without flags, modes, etc. */
91 int flag_simple = 0;
93 #ifndef GENERATOR_FILE
94 void
95 print_mem_expr (FILE *outfile, const_tree expr)
97 fputc (' ', outfile);
98 print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
100 #endif
102 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
104 static void
105 print_rtx (const_rtx in_rtx)
107 int i = 0;
108 int j;
109 const char *format_ptr;
110 int is_insn;
112 if (sawclose)
114 if (flag_simple)
115 fputc (' ', outfile);
116 else
117 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
118 sawclose = 0;
121 if (in_rtx == 0)
123 fputs ("(nil)", outfile);
124 sawclose = 1;
125 return;
127 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
129 fprintf (outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
130 print_rtx_head, indent * 2, "");
131 sawclose = 1;
132 return;
135 is_insn = INSN_P (in_rtx);
137 /* Print name of expression code. */
138 if (flag_simple && CONST_INT_P (in_rtx))
139 fputc ('(', outfile);
140 else
141 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
143 if (! flag_simple)
145 if (RTX_FLAG (in_rtx, in_struct))
146 fputs ("/s", outfile);
148 if (RTX_FLAG (in_rtx, volatil))
149 fputs ("/v", outfile);
151 if (RTX_FLAG (in_rtx, unchanging))
152 fputs ("/u", outfile);
154 if (RTX_FLAG (in_rtx, frame_related))
155 fputs ("/f", outfile);
157 if (RTX_FLAG (in_rtx, jump))
158 fputs ("/j", outfile);
160 if (RTX_FLAG (in_rtx, call))
161 fputs ("/c", outfile);
163 if (RTX_FLAG (in_rtx, return_val))
164 fputs ("/i", outfile);
166 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
167 if ((GET_CODE (in_rtx) == EXPR_LIST
168 || GET_CODE (in_rtx) == INSN_LIST
169 || GET_CODE (in_rtx) == INT_LIST)
170 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX
171 && !in_call_function_usage)
172 fprintf (outfile, ":%s",
173 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
175 /* For other rtl, print the mode if it's not VOID. */
176 else if (GET_MODE (in_rtx) != VOIDmode)
177 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
179 #ifndef GENERATOR_FILE
180 if (GET_CODE (in_rtx) == VAR_LOCATION)
182 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
183 fputs (" <debug string placeholder>", outfile);
184 else
185 print_mem_expr (outfile, PAT_VAR_LOCATION_DECL (in_rtx));
186 fputc (' ', outfile);
187 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
188 if (PAT_VAR_LOCATION_STATUS (in_rtx)
189 == VAR_INIT_STATUS_UNINITIALIZED)
190 fprintf (outfile, " [uninit]");
191 sawclose = 1;
192 i = GET_RTX_LENGTH (VAR_LOCATION);
194 #endif
197 #ifndef GENERATOR_FILE
198 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx))
199 i = 5;
200 #endif
202 if (INSN_CHAIN_CODE_P (GET_CODE (in_rtx)))
204 if (flag_dump_unnumbered)
205 fprintf (outfile, " #");
206 else
207 fprintf (outfile, " %d", INSN_UID (in_rtx));
210 /* Get the format string and skip the first elements if we have handled
211 them already. */
212 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
213 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
214 switch (*format_ptr++)
216 const char *str;
218 case 'T':
219 str = XTMPL (in_rtx, i);
220 goto string;
222 case 'S':
223 case 's':
224 str = XSTR (in_rtx, i);
225 string:
227 if (str == 0)
228 fputs (" \"\"", outfile);
229 else
230 fprintf (outfile, " (\"%s\")", str);
231 sawclose = 1;
232 break;
234 /* 0 indicates a field for internal use that should not be printed.
235 An exception is the third field of a NOTE, where it indicates
236 that the field has several different valid contents. */
237 case '0':
238 #ifndef GENERATOR_FILE
239 if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
241 int flags = SYMBOL_REF_FLAGS (in_rtx);
242 if (flags)
243 fprintf (outfile, " [flags %#x]", flags);
244 tree decl = SYMBOL_REF_DECL (in_rtx);
245 if (decl)
246 print_node_brief (outfile, "", decl, dump_flags);
248 else if (i == 3 && NOTE_P (in_rtx))
250 switch (NOTE_KIND (in_rtx))
252 case NOTE_INSN_EH_REGION_BEG:
253 case NOTE_INSN_EH_REGION_END:
254 if (flag_dump_unnumbered)
255 fprintf (outfile, " #");
256 else
257 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
258 sawclose = 1;
259 break;
261 case NOTE_INSN_BLOCK_BEG:
262 case NOTE_INSN_BLOCK_END:
263 dump_addr (outfile, " ", NOTE_BLOCK (in_rtx));
264 sawclose = 1;
265 break;
267 case NOTE_INSN_BASIC_BLOCK:
269 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
270 if (bb != 0)
271 fprintf (outfile, " [bb %d]", bb->index);
272 break;
275 case NOTE_INSN_DELETED_LABEL:
276 case NOTE_INSN_DELETED_DEBUG_LABEL:
278 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
279 if (label)
280 fprintf (outfile, " (\"%s\")", label);
281 else
282 fprintf (outfile, " \"\"");
284 break;
286 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
288 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
289 if (bb != 0)
290 fprintf (outfile, " [bb %d]", bb->index);
291 break;
294 case NOTE_INSN_VAR_LOCATION:
295 case NOTE_INSN_CALL_ARG_LOCATION:
296 fputc (' ', outfile);
297 print_rtx (NOTE_VAR_LOCATION (in_rtx));
298 break;
300 case NOTE_INSN_CFI:
301 fputc ('\n', outfile);
302 output_cfi_directive (outfile, NOTE_CFI (in_rtx));
303 fputc ('\t', outfile);
304 break;
306 default:
307 break;
310 else if (i == 7 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL)
312 /* Output the JUMP_LABEL reference. */
313 fprintf (outfile, "\n%s%*s -> ", print_rtx_head, indent * 2, "");
314 if (GET_CODE (JUMP_LABEL (in_rtx)) == RETURN)
315 fprintf (outfile, "return");
316 else if (GET_CODE (JUMP_LABEL (in_rtx)) == SIMPLE_RETURN)
317 fprintf (outfile, "simple_return");
318 else
319 fprintf (outfile, "%d", INSN_UID (JUMP_LABEL (in_rtx)));
321 else if (i == 0 && GET_CODE (in_rtx) == VALUE)
323 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
325 fprintf (outfile, " %u:%u", val->uid, val->hash);
326 dump_addr (outfile, " @", in_rtx);
327 dump_addr (outfile, "/", (void*)val);
329 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
331 fprintf (outfile, " D#%i",
332 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
334 else if (i == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
336 indent += 2;
337 if (!sawclose)
338 fprintf (outfile, " ");
339 print_rtx (ENTRY_VALUE_EXP (in_rtx));
340 indent -= 2;
342 #endif
343 break;
345 case 'e':
346 do_e:
347 indent += 2;
348 if (i == 6 && INSN_P (in_rtx))
349 /* Put REG_NOTES on their own line. */
350 fprintf (outfile, "\n%s%*s",
351 print_rtx_head, indent * 2, "");
352 if (!sawclose)
353 fprintf (outfile, " ");
354 if (i == 7 && CALL_P (in_rtx))
356 in_call_function_usage = true;
357 print_rtx (XEXP (in_rtx, i));
358 in_call_function_usage = false;
360 else
361 print_rtx (XEXP (in_rtx, i));
362 indent -= 2;
363 break;
365 case 'E':
366 case 'V':
367 indent += 2;
368 if (sawclose)
370 fprintf (outfile, "\n%s%*s",
371 print_rtx_head, indent * 2, "");
372 sawclose = 0;
374 fputs (" [", outfile);
375 if (NULL != XVEC (in_rtx, i))
377 indent += 2;
378 if (XVECLEN (in_rtx, i))
379 sawclose = 1;
381 for (j = 0; j < XVECLEN (in_rtx, i); j++)
382 print_rtx (XVECEXP (in_rtx, i, j));
384 indent -= 2;
386 if (sawclose)
387 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
389 fputs ("]", outfile);
390 sawclose = 1;
391 indent -= 2;
392 break;
394 case 'w':
395 if (! flag_simple)
396 fprintf (outfile, " ");
397 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
398 if (! flag_simple)
399 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
400 (unsigned HOST_WIDE_INT) XWINT (in_rtx, i));
401 break;
403 case 'i':
404 if (i == 4 && INSN_P (in_rtx))
406 #ifndef GENERATOR_FILE
407 const rtx_insn *in_insn = as_a <const rtx_insn *> (in_rtx);
409 /* Pretty-print insn locations. Ignore scoping as it is mostly
410 redundant with line number information and do not print anything
411 when there is no location information available. */
412 if (INSN_HAS_LOCATION (in_insn))
414 expanded_location xloc = insn_location (in_insn);
415 fprintf (outfile, " %s:%i", xloc.file, xloc.line);
417 #endif
419 else if (i == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
421 #ifndef GENERATOR_FILE
422 if (ASM_OPERANDS_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
423 fprintf (outfile, " %s:%i",
424 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
425 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
426 #endif
428 else if (i == 1 && GET_CODE (in_rtx) == ASM_INPUT)
430 #ifndef GENERATOR_FILE
431 if (ASM_INPUT_SOURCE_LOCATION (in_rtx) != UNKNOWN_LOCATION)
432 fprintf (outfile, " %s:%i",
433 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
434 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
435 #endif
437 else if (i == 5 && NOTE_P (in_rtx))
439 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
440 other times often contains garbage from INSN->NOTE death. */
441 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL
442 || NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_DEBUG_LABEL)
443 fprintf (outfile, " %d", XINT (in_rtx, i));
445 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
446 else if (i == 1
447 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
448 && XINT (in_rtx, 1) >= 0
449 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
450 fprintf (outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
451 #endif
452 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
453 else if (i == 1
454 && (GET_CODE (in_rtx) == UNSPEC
455 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
456 && XINT (in_rtx, 1) >= 0
457 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
458 fprintf (outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
459 #endif
460 else
462 int value = XINT (in_rtx, i);
463 const char *name;
465 if (flag_dump_unnumbered
466 && (is_insn || NOTE_P (in_rtx)))
467 fputc ('#', outfile);
468 else
469 fprintf (outfile, " %d", value);
471 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
472 && XINT (in_rtx, i) >= 0
473 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
474 fprintf (outfile, " {%s}", name);
475 sawclose = 0;
477 break;
479 case 'r':
481 unsigned int regno = REGNO (in_rtx);
482 #ifndef GENERATOR_FILE
483 if (regno < FIRST_PSEUDO_REGISTER)
484 fprintf (outfile, " %d %s", regno, reg_names[regno]);
485 else if (regno <= LAST_VIRTUAL_REGISTER)
487 if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
488 fprintf (outfile, " %d virtual-incoming-args", regno);
489 else if (regno == VIRTUAL_STACK_VARS_REGNUM)
490 fprintf (outfile, " %d virtual-stack-vars", regno);
491 else if (regno == VIRTUAL_STACK_DYNAMIC_REGNUM)
492 fprintf (outfile, " %d virtual-stack-dynamic", regno);
493 else if (regno == VIRTUAL_OUTGOING_ARGS_REGNUM)
494 fprintf (outfile, " %d virtual-outgoing-args", regno);
495 else if (regno == VIRTUAL_CFA_REGNUM)
496 fprintf (outfile, " %d virtual-cfa", regno);
497 else if (regno == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
498 fprintf (outfile, " %d virtual-preferred-stack-boundary",
499 regno);
500 else
501 fprintf (outfile, " %d virtual-reg-%d", regno,
502 regno-FIRST_VIRTUAL_REGISTER);
504 else
505 #endif
506 if (flag_dump_unnumbered && is_insn)
507 fputc ('#', outfile);
508 else
509 fprintf (outfile, " %d", regno);
511 #ifndef GENERATOR_FILE
512 if (REG_ATTRS (in_rtx))
514 fputs (" [", outfile);
515 if (regno != ORIGINAL_REGNO (in_rtx))
516 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
517 if (REG_EXPR (in_rtx))
518 print_mem_expr (outfile, REG_EXPR (in_rtx));
520 if (REG_OFFSET (in_rtx))
521 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
522 REG_OFFSET (in_rtx));
523 fputs (" ]", outfile);
525 if (regno != ORIGINAL_REGNO (in_rtx))
526 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
527 #endif
528 break;
531 /* Print NOTE_INSN names rather than integer codes. */
533 case 'n':
534 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
535 sawclose = 0;
536 break;
538 case 'u':
539 if (XEXP (in_rtx, i) != NULL)
541 rtx sub = XEXP (in_rtx, i);
542 enum rtx_code subc = GET_CODE (sub);
544 if (GET_CODE (in_rtx) == LABEL_REF)
546 if (subc == NOTE
547 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
549 if (flag_dump_unnumbered)
550 fprintf (outfile, " [# deleted]");
551 else
552 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
553 sawclose = 0;
554 break;
557 if (subc != CODE_LABEL)
558 goto do_e;
561 if (flag_dump_unnumbered
562 || (flag_dump_unnumbered_links && (i == 1 || i == 2)
563 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
564 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
565 fputs (" #", outfile);
566 else
567 fprintf (outfile, " %d", INSN_UID (sub));
569 else
570 fputs (" 0", outfile);
571 sawclose = 0;
572 break;
574 case 't':
575 #ifndef GENERATOR_FILE
576 if (i == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
577 print_mem_expr (outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
578 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
579 print_mem_expr (outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
580 else
581 dump_addr (outfile, " ", XTREE (in_rtx, i));
582 #endif
583 break;
585 case '*':
586 fputs (" Unknown", outfile);
587 sawclose = 0;
588 break;
590 case 'B':
591 #ifndef GENERATOR_FILE
592 if (XBBDEF (in_rtx, i))
593 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
594 #endif
595 break;
597 default:
598 gcc_unreachable ();
601 switch (GET_CODE (in_rtx))
603 #ifndef GENERATOR_FILE
604 case MEM:
605 if (__builtin_expect (final_insns_dump_p, false))
606 fprintf (outfile, " [");
607 else
608 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC,
609 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
611 if (MEM_EXPR (in_rtx))
612 print_mem_expr (outfile, MEM_EXPR (in_rtx));
613 else
614 fputc (' ', outfile);
616 if (MEM_OFFSET_KNOWN_P (in_rtx))
617 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC, MEM_OFFSET (in_rtx));
619 if (MEM_SIZE_KNOWN_P (in_rtx))
620 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC, MEM_SIZE (in_rtx));
622 if (MEM_ALIGN (in_rtx) != 1)
623 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
625 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
626 fprintf (outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
628 fputc (']', outfile);
629 break;
631 case CONST_DOUBLE:
632 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
634 char s[60];
636 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
637 sizeof (s), 0, 1);
638 fprintf (outfile, " %s", s);
640 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
641 sizeof (s), 0, 1);
642 fprintf (outfile, " [%s]", s);
644 break;
646 case CONST_WIDE_INT:
647 fprintf (outfile, " ");
648 cwi_output_hex (outfile, in_rtx);
649 break;
650 #endif
652 case CODE_LABEL:
653 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
654 switch (LABEL_KIND (in_rtx))
656 case LABEL_NORMAL: break;
657 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
658 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
659 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
660 default: gcc_unreachable ();
662 break;
664 default:
665 break;
668 fputc (')', outfile);
669 sawclose = 1;
672 /* Print an rtx on the current line of FILE. Initially indent IND
673 characters. */
675 void
676 print_inline_rtx (FILE *outf, const_rtx x, int ind)
678 int oldsaw = sawclose;
679 int oldindent = indent;
681 sawclose = 0;
682 indent = ind;
683 outfile = outf;
684 print_rtx (x);
685 sawclose = oldsaw;
686 indent = oldindent;
689 /* Call this function from the debugger to see what X looks like. */
691 DEBUG_FUNCTION void
692 debug_rtx (const_rtx x)
694 outfile = stderr;
695 sawclose = 0;
696 print_rtx (x);
697 fprintf (stderr, "\n");
700 /* Dump rtx REF. */
702 DEBUG_FUNCTION void
703 debug (const rtx_def &ref)
705 debug_rtx (&ref);
708 DEBUG_FUNCTION void
709 debug (const rtx_def *ptr)
711 if (ptr)
712 debug (*ptr);
713 else
714 fprintf (stderr, "<nil>\n");
717 /* Count of rtx's to print with debug_rtx_list.
718 This global exists because gdb user defined commands have no arguments. */
720 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
722 /* Call this function to print list from X on.
724 N is a count of the rtx's to print. Positive values print from the specified
725 rtx_insn on. Negative values print a window around the rtx_insn.
726 EG: -5 prints 2 rtx_insn's on either side (in addition to the specified
727 rtx_insn). */
729 DEBUG_FUNCTION void
730 debug_rtx_list (const rtx_insn *x, int n)
732 int i,count;
733 const rtx_insn *insn;
735 count = n == 0 ? 1 : n < 0 ? -n : n;
737 /* If we are printing a window, back up to the start. */
739 if (n < 0)
740 for (i = count / 2; i > 0; i--)
742 if (PREV_INSN (x) == 0)
743 break;
744 x = PREV_INSN (x);
747 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
749 debug_rtx (insn);
750 fprintf (stderr, "\n");
754 /* Call this function to print an rtx_insn list from START to END
755 inclusive. */
757 DEBUG_FUNCTION void
758 debug_rtx_range (const rtx_insn *start, const rtx_insn *end)
760 while (1)
762 debug_rtx (start);
763 fprintf (stderr, "\n");
764 if (!start || start == end)
765 break;
766 start = NEXT_INSN (start);
770 /* Call this function to search an rtx_insn list to find one with insn uid UID,
771 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
772 The found insn is returned to enable further debugging analysis. */
774 DEBUG_FUNCTION const_rtx
775 debug_rtx_find (const rtx_insn *x, int uid)
777 while (x != 0 && INSN_UID (x) != uid)
778 x = NEXT_INSN (x);
779 if (x != 0)
781 debug_rtx_list (x, debug_rtx_count);
782 return x;
784 else
786 fprintf (stderr, "insn uid %d not found\n", uid);
787 return 0;
791 /* External entry point for printing a chain of insns
792 starting with RTX_FIRST onto file OUTF.
793 A blank line separates insns.
795 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
797 void
798 print_rtl (FILE *outf, const_rtx rtx_first)
800 const rtx_insn *tmp_rtx;
802 outfile = outf;
803 sawclose = 0;
805 if (rtx_first == 0)
807 fputs (print_rtx_head, outf);
808 fputs ("(nil)\n", outf);
810 else
811 switch (GET_CODE (rtx_first))
813 case INSN:
814 case JUMP_INSN:
815 case CALL_INSN:
816 case NOTE:
817 case CODE_LABEL:
818 case JUMP_TABLE_DATA:
819 case BARRIER:
820 for (tmp_rtx = as_a <const rtx_insn *> (rtx_first);
821 tmp_rtx != 0;
822 tmp_rtx = NEXT_INSN (tmp_rtx))
824 fputs (print_rtx_head, outfile);
825 print_rtx (tmp_rtx);
826 fprintf (outfile, "\n");
828 break;
830 default:
831 fputs (print_rtx_head, outfile);
832 print_rtx (rtx_first);
836 /* Like print_rtx, except specify a file. */
837 /* Return nonzero if we actually printed anything. */
840 print_rtl_single (FILE *outf, const_rtx x)
842 return print_rtl_single_with_indent (outf, x, 0);
845 /* Like print_rtl_single, except specify a file and indentation. */
848 print_rtl_single_with_indent (FILE *outf, const_rtx x, int ind)
850 int old_indent = indent;
851 char *s_indent = (char *) alloca ((size_t) ind + 1);
852 memset ((void *) s_indent, ' ', (size_t) ind);
853 s_indent[ind] = '\0';
855 indent = ind;
856 outfile = outf;
857 sawclose = 0;
858 fputs (s_indent, outfile);
859 fputs (print_rtx_head, outfile);
860 print_rtx (x);
861 putc ('\n', outf);
862 indent = old_indent;
863 return 1;
867 /* Like print_rtl except without all the detail; for example,
868 if RTX is a CONST_INT then print in decimal format. */
870 void
871 print_simple_rtl (FILE *outf, const_rtx x)
873 flag_simple = 1;
874 print_rtl (outf, x);
875 flag_simple = 0;