Simplify convert_modes, ignoring invalid old modes for CONST_INTs.
[official-gcc.git] / gcc / print-rtl.c
blob043f0f797f584ac0f2e84b0989f6224e8a0b8e37
1 /* Print RTL for GCC.
2 Copyright (C) 1987-2013 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 "tree.h"
37 #include "flags.h"
38 #include "hard-reg-set.h"
39 #include "basic-block.h"
40 #include "diagnostic.h"
41 #include "tree-pretty-print.h"
42 #include "cselib.h"
43 #include "dumpfile.h" /* for dump_flags */
44 #include "dwarf2out.h"
45 #endif
47 static FILE *outfile;
49 static int sawclose = 0;
51 static int indent;
53 static void print_rtx (const_rtx);
55 /* String printed at beginning of each RTL when it is dumped.
56 This string is set to ASM_COMMENT_START when the RTL is dumped in
57 the assembly output file. */
58 const char *print_rtx_head = "";
60 #ifdef GENERATOR_FILE
61 /* These are defined from the .opt file when not used in generator
62 programs. */
64 /* Nonzero means suppress output of instruction numbers
65 in debugging dumps.
66 This must be defined here so that programs like gencodes can be linked. */
67 int flag_dump_unnumbered = 0;
69 /* Nonzero means suppress output of instruction numbers for previous
70 and next insns in debugging dumps.
71 This must be defined here so that programs like gencodes can be linked. */
72 int flag_dump_unnumbered_links = 0;
73 #endif
75 /* Nonzero means use simplified format without flags, modes, etc. */
76 int flag_simple = 0;
78 #ifndef GENERATOR_FILE
79 void
80 print_mem_expr (FILE *outfile, const_tree expr)
82 fputc (' ', outfile);
83 print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
85 #endif
87 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
89 static void
90 print_rtx (const_rtx in_rtx)
92 int i = 0;
93 int j;
94 const char *format_ptr;
95 int is_insn;
97 if (sawclose)
99 if (flag_simple)
100 fputc (' ', outfile);
101 else
102 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
103 sawclose = 0;
106 if (in_rtx == 0)
108 fputs ("(nil)", outfile);
109 sawclose = 1;
110 return;
112 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
114 fprintf (outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
115 print_rtx_head, indent * 2, "");
116 sawclose = 1;
117 return;
120 is_insn = INSN_P (in_rtx);
122 /* Print name of expression code. */
123 if (flag_simple && CONST_INT_P (in_rtx))
124 fputc ('(', outfile);
125 else
126 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
128 if (! flag_simple)
130 if (RTX_FLAG (in_rtx, in_struct))
131 fputs ("/s", outfile);
133 if (RTX_FLAG (in_rtx, volatil))
134 fputs ("/v", outfile);
136 if (RTX_FLAG (in_rtx, unchanging))
137 fputs ("/u", outfile);
139 if (RTX_FLAG (in_rtx, frame_related))
140 fputs ("/f", outfile);
142 if (RTX_FLAG (in_rtx, jump))
143 fputs ("/j", outfile);
145 if (RTX_FLAG (in_rtx, call))
146 fputs ("/c", outfile);
148 if (RTX_FLAG (in_rtx, return_val))
149 fputs ("/i", outfile);
151 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
152 if ((GET_CODE (in_rtx) == EXPR_LIST
153 || GET_CODE (in_rtx) == INSN_LIST
154 || GET_CODE (in_rtx) == INT_LIST)
155 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX)
156 fprintf (outfile, ":%s",
157 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
159 /* For other rtl, print the mode if it's not VOID. */
160 else if (GET_MODE (in_rtx) != VOIDmode)
161 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
163 #ifndef GENERATOR_FILE
164 if (GET_CODE (in_rtx) == VAR_LOCATION)
166 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
167 fputs (" <debug string placeholder>", outfile);
168 else
169 print_mem_expr (outfile, PAT_VAR_LOCATION_DECL (in_rtx));
170 fputc (' ', outfile);
171 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
172 if (PAT_VAR_LOCATION_STATUS (in_rtx)
173 == VAR_INIT_STATUS_UNINITIALIZED)
174 fprintf (outfile, " [uninit]");
175 sawclose = 1;
176 i = GET_RTX_LENGTH (VAR_LOCATION);
178 #endif
181 #ifndef GENERATOR_FILE
182 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx))
183 i = 5;
184 #endif
186 /* Get the format string and skip the first elements if we have handled
187 them already. */
188 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
189 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
190 switch (*format_ptr++)
192 const char *str;
194 case 'T':
195 str = XTMPL (in_rtx, i);
196 goto string;
198 case 'S':
199 case 's':
200 str = XSTR (in_rtx, i);
201 string:
203 if (str == 0)
204 fputs (" \"\"", outfile);
205 else
206 fprintf (outfile, " (\"%s\")", str);
207 sawclose = 1;
208 break;
210 /* 0 indicates a field for internal use that should not be printed.
211 An exception is the third field of a NOTE, where it indicates
212 that the field has several different valid contents. */
213 case '0':
214 if (i == 1 && REG_P (in_rtx))
216 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
217 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
219 #ifndef GENERATOR_FILE
220 else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
222 int flags = SYMBOL_REF_FLAGS (in_rtx);
223 if (flags)
224 fprintf (outfile, " [flags %#x]", flags);
226 else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
228 tree decl = SYMBOL_REF_DECL (in_rtx);
229 if (decl)
230 print_node_brief (outfile, "", decl, dump_flags);
232 #endif
233 else if (i == 4 && NOTE_P (in_rtx))
235 switch (NOTE_KIND (in_rtx))
237 case NOTE_INSN_EH_REGION_BEG:
238 case NOTE_INSN_EH_REGION_END:
239 if (flag_dump_unnumbered)
240 fprintf (outfile, " #");
241 else
242 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
243 sawclose = 1;
244 break;
246 case NOTE_INSN_BLOCK_BEG:
247 case NOTE_INSN_BLOCK_END:
248 #ifndef GENERATOR_FILE
249 dump_addr (outfile, " ", NOTE_BLOCK (in_rtx));
250 #endif
251 sawclose = 1;
252 break;
254 case NOTE_INSN_BASIC_BLOCK:
256 #ifndef GENERATOR_FILE
257 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
258 if (bb != 0)
259 fprintf (outfile, " [bb %d]", bb->index);
260 #endif
261 break;
264 case NOTE_INSN_DELETED_LABEL:
265 case NOTE_INSN_DELETED_DEBUG_LABEL:
267 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
268 if (label)
269 fprintf (outfile, " (\"%s\")", label);
270 else
271 fprintf (outfile, " \"\"");
273 break;
275 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
277 #ifndef GENERATOR_FILE
278 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
279 if (bb != 0)
280 fprintf (outfile, " [bb %d]", bb->index);
281 #endif
282 break;
285 case NOTE_INSN_VAR_LOCATION:
286 case NOTE_INSN_CALL_ARG_LOCATION:
287 #ifndef GENERATOR_FILE
288 fputc (' ', outfile);
289 print_rtx (NOTE_VAR_LOCATION (in_rtx));
290 #endif
291 break;
293 case NOTE_INSN_CFI:
294 #ifndef GENERATOR_FILE
295 fputc ('\n', outfile);
296 output_cfi_directive (outfile, NOTE_CFI (in_rtx));
297 fputc ('\t', outfile);
298 #endif
299 break;
301 default:
302 break;
305 else if (i == 8 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL)
307 /* Output the JUMP_LABEL reference. */
308 fprintf (outfile, "\n%s%*s -> ", print_rtx_head, indent * 2, "");
309 if (GET_CODE (JUMP_LABEL (in_rtx)) == RETURN)
310 fprintf (outfile, "return");
311 else if (GET_CODE (JUMP_LABEL (in_rtx)) == SIMPLE_RETURN)
312 fprintf (outfile, "simple_return");
313 else
314 fprintf (outfile, "%d", INSN_UID (JUMP_LABEL (in_rtx)));
316 else if (i == 0 && GET_CODE (in_rtx) == VALUE)
318 #ifndef GENERATOR_FILE
319 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
321 fprintf (outfile, " %u:%u", val->uid, val->hash);
322 dump_addr (outfile, " @", in_rtx);
323 dump_addr (outfile, "/", (void*)val);
324 #endif
326 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
328 #ifndef GENERATOR_FILE
329 fprintf (outfile, " D#%i",
330 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
331 #endif
333 else if (i == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
335 indent += 2;
336 if (!sawclose)
337 fprintf (outfile, " ");
338 print_rtx (ENTRY_VALUE_EXP (in_rtx));
339 indent -= 2;
341 break;
343 case 'e':
344 do_e:
345 indent += 2;
346 if (i == 7 && INSN_P (in_rtx))
347 /* Put REG_NOTES on their own line. */
348 fprintf (outfile, "\n%s%*s",
349 print_rtx_head, indent * 2, "");
350 if (!sawclose)
351 fprintf (outfile, " ");
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 == 5 && INSN_P (in_rtx))
397 #ifndef GENERATOR_FILE
398 /* Pretty-print insn locations. Ignore scoping as it is mostly
399 redundant with line number information and do not print anything
400 when there is no location information available. */
401 if (INSN_LOCATION (in_rtx) && insn_file (in_rtx))
402 fprintf (outfile, " %s:%i", insn_file (in_rtx),
403 insn_line (in_rtx));
404 #endif
406 else if (i == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
408 #ifndef GENERATOR_FILE
409 fprintf (outfile, " %s:%i",
410 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
411 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
412 #endif
414 else if (i == 1 && GET_CODE (in_rtx) == ASM_INPUT)
416 #ifndef GENERATOR_FILE
417 fprintf (outfile, " %s:%i",
418 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
419 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
420 #endif
422 else if (i == 6 && NOTE_P (in_rtx))
424 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
425 other times often contains garbage from INSN->NOTE death. */
426 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL
427 || NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_DEBUG_LABEL)
428 fprintf (outfile, " %d", XINT (in_rtx, i));
430 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
431 else if (i == 1
432 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
433 && XINT (in_rtx, 1) >= 0
434 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
435 fprintf (outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
436 #endif
437 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
438 else if (i == 1
439 && (GET_CODE (in_rtx) == UNSPEC
440 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
441 && XINT (in_rtx, 1) >= 0
442 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
443 fprintf (outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
444 #endif
445 else
447 int value = XINT (in_rtx, i);
448 const char *name;
450 #ifndef GENERATOR_FILE
451 if (REG_P (in_rtx) && (unsigned) value < FIRST_PSEUDO_REGISTER)
452 fprintf (outfile, " %d %s", value, reg_names[value]);
453 else if (REG_P (in_rtx)
454 && (unsigned) value <= LAST_VIRTUAL_REGISTER)
456 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
457 fprintf (outfile, " %d virtual-incoming-args", value);
458 else if (value == VIRTUAL_STACK_VARS_REGNUM)
459 fprintf (outfile, " %d virtual-stack-vars", value);
460 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
461 fprintf (outfile, " %d virtual-stack-dynamic", value);
462 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
463 fprintf (outfile, " %d virtual-outgoing-args", value);
464 else if (value == VIRTUAL_CFA_REGNUM)
465 fprintf (outfile, " %d virtual-cfa", value);
466 else if (value == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
467 fprintf (outfile, " %d virtual-preferred-stack-boundary",
468 value);
469 else
470 fprintf (outfile, " %d virtual-reg-%d", value,
471 value-FIRST_VIRTUAL_REGISTER);
473 else
474 #endif
475 if (flag_dump_unnumbered
476 && (is_insn || NOTE_P (in_rtx)))
477 fputc ('#', outfile);
478 else
479 fprintf (outfile, " %d", value);
481 #ifndef GENERATOR_FILE
482 if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
484 fputs (" [", outfile);
485 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
486 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
487 if (REG_EXPR (in_rtx))
488 print_mem_expr (outfile, REG_EXPR (in_rtx));
490 if (REG_OFFSET (in_rtx))
491 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
492 REG_OFFSET (in_rtx));
493 fputs (" ]", outfile);
495 #endif
497 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
498 && XINT (in_rtx, i) >= 0
499 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
500 fprintf (outfile, " {%s}", name);
501 sawclose = 0;
503 break;
505 /* Print NOTE_INSN names rather than integer codes. */
507 case 'n':
508 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
509 sawclose = 0;
510 break;
512 case 'u':
513 if (XEXP (in_rtx, i) != NULL)
515 rtx sub = XEXP (in_rtx, i);
516 enum rtx_code subc = GET_CODE (sub);
518 if (GET_CODE (in_rtx) == LABEL_REF)
520 if (subc == NOTE
521 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
523 if (flag_dump_unnumbered)
524 fprintf (outfile, " [# deleted]");
525 else
526 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
527 sawclose = 0;
528 break;
531 if (subc != CODE_LABEL)
532 goto do_e;
535 if (flag_dump_unnumbered
536 || (flag_dump_unnumbered_links && (i == 1 || i == 2)
537 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
538 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
539 fputs (" #", outfile);
540 else
541 fprintf (outfile, " %d", INSN_UID (sub));
543 else
544 fputs (" 0", outfile);
545 sawclose = 0;
546 break;
548 case 't':
549 #ifndef GENERATOR_FILE
550 if (i == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
551 print_mem_expr (outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
552 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
553 print_mem_expr (outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
554 else
555 dump_addr (outfile, " ", XTREE (in_rtx, i));
556 #endif
557 break;
559 case '*':
560 fputs (" Unknown", outfile);
561 sawclose = 0;
562 break;
564 case 'B':
565 #ifndef GENERATOR_FILE
566 if (XBBDEF (in_rtx, i))
567 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
568 #endif
569 break;
571 default:
572 gcc_unreachable ();
575 switch (GET_CODE (in_rtx))
577 #ifndef GENERATOR_FILE
578 case MEM:
579 if (__builtin_expect (final_insns_dump_p, false))
580 fprintf (outfile, " [");
581 else
582 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC,
583 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
585 if (MEM_EXPR (in_rtx))
586 print_mem_expr (outfile, MEM_EXPR (in_rtx));
588 if (MEM_OFFSET_KNOWN_P (in_rtx))
589 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC, MEM_OFFSET (in_rtx));
591 if (MEM_SIZE_KNOWN_P (in_rtx))
592 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC, MEM_SIZE (in_rtx));
594 if (MEM_ALIGN (in_rtx) != 1)
595 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
597 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
598 fprintf (outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
600 fputc (']', outfile);
601 break;
603 case CONST_DOUBLE:
604 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
606 char s[60];
608 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
609 sizeof (s), 0, 1);
610 fprintf (outfile, " %s", s);
612 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
613 sizeof (s), 0, 1);
614 fprintf (outfile, " [%s]", s);
616 break;
618 case CONST_WIDE_INT:
619 if (! flag_simple)
620 fprintf (outfile, " ");
621 cwi_output_hex (outfile, in_rtx);
622 break;
623 #endif
625 case CODE_LABEL:
626 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
627 switch (LABEL_KIND (in_rtx))
629 case LABEL_NORMAL: break;
630 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
631 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
632 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
633 default: gcc_unreachable ();
635 break;
637 default:
638 break;
641 fputc (')', outfile);
642 sawclose = 1;
645 /* Print an rtx on the current line of FILE. Initially indent IND
646 characters. */
648 void
649 print_inline_rtx (FILE *outf, const_rtx x, int ind)
651 int oldsaw = sawclose;
652 int oldindent = indent;
654 sawclose = 0;
655 indent = ind;
656 outfile = outf;
657 print_rtx (x);
658 sawclose = oldsaw;
659 indent = oldindent;
662 /* Call this function from the debugger to see what X looks like. */
664 DEBUG_FUNCTION void
665 debug_rtx (const_rtx x)
667 outfile = stderr;
668 sawclose = 0;
669 print_rtx (x);
670 fprintf (stderr, "\n");
673 /* Dump rtx REF. */
675 DEBUG_FUNCTION void
676 debug (const rtx_def &ref)
678 debug_rtx (&ref);
681 DEBUG_FUNCTION void
682 debug (const rtx_def *ptr)
684 if (ptr)
685 debug (*ptr);
686 else
687 fprintf (stderr, "<nil>\n");
690 /* Count of rtx's to print with debug_rtx_list.
691 This global exists because gdb user defined commands have no arguments. */
693 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
695 /* Call this function to print list from X on.
697 N is a count of the rtx's to print. Positive values print from the specified
698 rtx on. Negative values print a window around the rtx.
699 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
701 DEBUG_FUNCTION void
702 debug_rtx_list (const_rtx x, int n)
704 int i,count;
705 const_rtx insn;
707 count = n == 0 ? 1 : n < 0 ? -n : n;
709 /* If we are printing a window, back up to the start. */
711 if (n < 0)
712 for (i = count / 2; i > 0; i--)
714 if (PREV_INSN (x) == 0)
715 break;
716 x = PREV_INSN (x);
719 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
721 debug_rtx (insn);
722 fprintf (stderr, "\n");
726 /* Call this function to print an rtx list from START to END inclusive. */
728 DEBUG_FUNCTION void
729 debug_rtx_range (const_rtx start, const_rtx end)
731 while (1)
733 debug_rtx (start);
734 fprintf (stderr, "\n");
735 if (!start || start == end)
736 break;
737 start = NEXT_INSN (start);
741 /* Call this function to search an rtx list to find one with insn uid UID,
742 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
743 The found insn is returned to enable further debugging analysis. */
745 DEBUG_FUNCTION const_rtx
746 debug_rtx_find (const_rtx x, int uid)
748 while (x != 0 && INSN_UID (x) != uid)
749 x = NEXT_INSN (x);
750 if (x != 0)
752 debug_rtx_list (x, debug_rtx_count);
753 return x;
755 else
757 fprintf (stderr, "insn uid %d not found\n", uid);
758 return 0;
762 /* External entry point for printing a chain of insns
763 starting with RTX_FIRST onto file OUTF.
764 A blank line separates insns.
766 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
768 void
769 print_rtl (FILE *outf, const_rtx rtx_first)
771 const_rtx tmp_rtx;
773 outfile = outf;
774 sawclose = 0;
776 if (rtx_first == 0)
778 fputs (print_rtx_head, outf);
779 fputs ("(nil)\n", outf);
781 else
782 switch (GET_CODE (rtx_first))
784 case INSN:
785 case JUMP_INSN:
786 case CALL_INSN:
787 case NOTE:
788 case CODE_LABEL:
789 case JUMP_TABLE_DATA:
790 case BARRIER:
791 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
793 fputs (print_rtx_head, outfile);
794 print_rtx (tmp_rtx);
795 fprintf (outfile, "\n");
797 break;
799 default:
800 fputs (print_rtx_head, outfile);
801 print_rtx (rtx_first);
805 /* Like print_rtx, except specify a file. */
806 /* Return nonzero if we actually printed anything. */
809 print_rtl_single (FILE *outf, const_rtx x)
811 return print_rtl_single_with_indent (outf, x, 0);
814 /* Like print_rtl_single, except specify a file and indentation. */
817 print_rtl_single_with_indent (FILE *outf, const_rtx x, int ind)
819 int old_indent = indent;
820 char *s_indent = (char *) alloca ((size_t) ind + 1);
821 memset ((void *) s_indent, ' ', (size_t) ind);
822 s_indent[ind] = '\0';
824 indent = ind;
825 outfile = outf;
826 sawclose = 0;
827 fputs (s_indent, outfile);
828 fputs (print_rtx_head, outfile);
829 print_rtx (x);
830 putc ('\n', outf);
831 indent = old_indent;
832 return 1;
836 /* Like print_rtl except without all the detail; for example,
837 if RTX is a CONST_INT then print in decimal format. */
839 void
840 print_simple_rtl (FILE *outf, const_rtx x)
842 flag_simple = 1;
843 print_rtl (outf, x);
844 flag_simple = 0;