]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/print-rtl.c
rtl.texi (REG_NOTES): Say that int_list can also be used.
[thirdparty/gcc.git] / gcc / print-rtl.c
1 /* Print RTL for GCC.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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.
10
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.
15
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/>. */
19
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
27
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "rtl.h"
32
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
46
47 static FILE *outfile;
48
49 static int sawclose = 0;
50
51 static int indent;
52
53 static void print_rtx (const_rtx);
54
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 = "";
59
60 #ifdef GENERATOR_FILE
61 /* These are defined from the .opt file when not used in generator
62 programs. */
63
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;
68
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
74
75 /* Nonzero means use simplified format without flags, modes, etc. */
76 int flag_simple = 0;
77
78 #ifndef GENERATOR_FILE
79 void
80 print_mem_expr (FILE *outfile, const_tree expr)
81 {
82 fputc (' ', outfile);
83 print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
84 }
85 #endif
86
87 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
88
89 static void
90 print_rtx (const_rtx in_rtx)
91 {
92 int i = 0;
93 int j;
94 const char *format_ptr;
95 int is_insn;
96
97 if (sawclose)
98 {
99 if (flag_simple)
100 fputc (' ', outfile);
101 else
102 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
103 sawclose = 0;
104 }
105
106 if (in_rtx == 0)
107 {
108 fputs ("(nil)", outfile);
109 sawclose = 1;
110 return;
111 }
112 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
113 {
114 fprintf (outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
115 print_rtx_head, indent * 2, "");
116 sawclose = 1;
117 return;
118 }
119
120 is_insn = INSN_P (in_rtx);
121
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)));
127
128 if (! flag_simple)
129 {
130 if (RTX_FLAG (in_rtx, in_struct))
131 fputs ("/s", outfile);
132
133 if (RTX_FLAG (in_rtx, volatil))
134 fputs ("/v", outfile);
135
136 if (RTX_FLAG (in_rtx, unchanging))
137 fputs ("/u", outfile);
138
139 if (RTX_FLAG (in_rtx, frame_related))
140 fputs ("/f", outfile);
141
142 if (RTX_FLAG (in_rtx, jump))
143 fputs ("/j", outfile);
144
145 if (RTX_FLAG (in_rtx, call))
146 fputs ("/c", outfile);
147
148 if (RTX_FLAG (in_rtx, return_val))
149 fputs ("/i", outfile);
150
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)));
158
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)));
162
163 #ifndef GENERATOR_FILE
164 if (GET_CODE (in_rtx) == VAR_LOCATION)
165 {
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);
177 }
178 #endif
179 }
180
181 #ifndef GENERATOR_FILE
182 if (CONST_DOUBLE_AS_FLOAT_P (in_rtx))
183 i = 5;
184 #endif
185
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++)
191 {
192 const char *str;
193
194 case 'T':
195 str = XTMPL (in_rtx, i);
196 goto string;
197
198 case 'S':
199 case 's':
200 str = XSTR (in_rtx, i);
201 string:
202
203 if (str == 0)
204 fputs (" \"\"", outfile);
205 else
206 fprintf (outfile, " (\"%s\")", str);
207 sawclose = 1;
208 break;
209
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))
215 {
216 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
217 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
218 }
219 #ifndef GENERATOR_FILE
220 else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
221 {
222 int flags = SYMBOL_REF_FLAGS (in_rtx);
223 if (flags)
224 fprintf (outfile, " [flags %#x]", flags);
225 }
226 else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
227 {
228 tree decl = SYMBOL_REF_DECL (in_rtx);
229 if (decl)
230 print_node_brief (outfile, "", decl, dump_flags);
231 }
232 #endif
233 else if (i == 4 && NOTE_P (in_rtx))
234 {
235 switch (NOTE_KIND (in_rtx))
236 {
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;
245
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;
253
254 case NOTE_INSN_BASIC_BLOCK:
255 {
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;
262 }
263
264 case NOTE_INSN_DELETED_LABEL:
265 case NOTE_INSN_DELETED_DEBUG_LABEL:
266 {
267 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
268 if (label)
269 fprintf (outfile, " (\"%s\")", label);
270 else
271 fprintf (outfile, " \"\"");
272 }
273 break;
274
275 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
276 {
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;
283 }
284
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;
292
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;
300
301 default:
302 break;
303 }
304 }
305 else if (i == 8 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL)
306 {
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)));
315 }
316 else if (i == 0 && GET_CODE (in_rtx) == VALUE)
317 {
318 #ifndef GENERATOR_FILE
319 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
320
321 fprintf (outfile, " %u:%u", val->uid, val->hash);
322 dump_addr (outfile, " @", in_rtx);
323 dump_addr (outfile, "/", (void*)val);
324 #endif
325 }
326 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
327 {
328 #ifndef GENERATOR_FILE
329 fprintf (outfile, " D#%i",
330 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
331 #endif
332 }
333 else if (i == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
334 {
335 indent += 2;
336 if (!sawclose)
337 fprintf (outfile, " ");
338 print_rtx (ENTRY_VALUE_EXP (in_rtx));
339 indent -= 2;
340 }
341 break;
342
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;
355
356 case 'E':
357 case 'V':
358 indent += 2;
359 if (sawclose)
360 {
361 fprintf (outfile, "\n%s%*s",
362 print_rtx_head, indent * 2, "");
363 sawclose = 0;
364 }
365 fputs (" [", outfile);
366 if (NULL != XVEC (in_rtx, i))
367 {
368 indent += 2;
369 if (XVECLEN (in_rtx, i))
370 sawclose = 1;
371
372 for (j = 0; j < XVECLEN (in_rtx, i); j++)
373 print_rtx (XVECEXP (in_rtx, i, j));
374
375 indent -= 2;
376 }
377 if (sawclose)
378 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
379
380 fputs ("]", outfile);
381 sawclose = 1;
382 indent -= 2;
383 break;
384
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;
393
394 case 'i':
395 if (i == 5 && INSN_P (in_rtx))
396 {
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), insn_line (in_rtx));
403 #endif
404 }
405 else if (i == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
406 {
407 #ifndef GENERATOR_FILE
408 fprintf (outfile, " %s:%i",
409 LOCATION_FILE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
410 LOCATION_LINE (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
411 #endif
412 }
413 else if (i == 1 && GET_CODE (in_rtx) == ASM_INPUT)
414 {
415 #ifndef GENERATOR_FILE
416 fprintf (outfile, " %s:%i",
417 LOCATION_FILE (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
418 LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
419 #endif
420 }
421 else if (i == 6 && NOTE_P (in_rtx))
422 {
423 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
424 other times often contains garbage from INSN->NOTE death. */
425 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL
426 || NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_DEBUG_LABEL)
427 fprintf (outfile, " %d", XINT (in_rtx, i));
428 }
429 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
430 else if (i == 1
431 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
432 && XINT (in_rtx, 1) >= 0
433 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
434 fprintf (outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
435 #endif
436 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
437 else if (i == 1
438 && (GET_CODE (in_rtx) == UNSPEC
439 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
440 && XINT (in_rtx, 1) >= 0
441 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
442 fprintf (outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
443 #endif
444 else
445 {
446 int value = XINT (in_rtx, i);
447 const char *name;
448
449 #ifndef GENERATOR_FILE
450 if (REG_P (in_rtx) && (unsigned) value < FIRST_PSEUDO_REGISTER)
451 fprintf (outfile, " %d %s", value, reg_names[value]);
452 else if (REG_P (in_rtx)
453 && (unsigned) value <= LAST_VIRTUAL_REGISTER)
454 {
455 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
456 fprintf (outfile, " %d virtual-incoming-args", value);
457 else if (value == VIRTUAL_STACK_VARS_REGNUM)
458 fprintf (outfile, " %d virtual-stack-vars", value);
459 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
460 fprintf (outfile, " %d virtual-stack-dynamic", value);
461 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
462 fprintf (outfile, " %d virtual-outgoing-args", value);
463 else if (value == VIRTUAL_CFA_REGNUM)
464 fprintf (outfile, " %d virtual-cfa", value);
465 else if (value == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
466 fprintf (outfile, " %d virtual-preferred-stack-boundary",
467 value);
468 else
469 fprintf (outfile, " %d virtual-reg-%d", value,
470 value-FIRST_VIRTUAL_REGISTER);
471 }
472 else
473 #endif
474 if (flag_dump_unnumbered
475 && (is_insn || NOTE_P (in_rtx)))
476 fputc ('#', outfile);
477 else
478 fprintf (outfile, " %d", value);
479
480 #ifndef GENERATOR_FILE
481 if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
482 {
483 fputs (" [", outfile);
484 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
485 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
486 if (REG_EXPR (in_rtx))
487 print_mem_expr (outfile, REG_EXPR (in_rtx));
488
489 if (REG_OFFSET (in_rtx))
490 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
491 REG_OFFSET (in_rtx));
492 fputs (" ]", outfile);
493 }
494 #endif
495
496 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
497 && XINT (in_rtx, i) >= 0
498 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
499 fprintf (outfile, " {%s}", name);
500 sawclose = 0;
501 }
502 break;
503
504 /* Print NOTE_INSN names rather than integer codes. */
505
506 case 'n':
507 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
508 sawclose = 0;
509 break;
510
511 case 'u':
512 if (XEXP (in_rtx, i) != NULL)
513 {
514 rtx sub = XEXP (in_rtx, i);
515 enum rtx_code subc = GET_CODE (sub);
516
517 if (GET_CODE (in_rtx) == LABEL_REF)
518 {
519 if (subc == NOTE
520 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
521 {
522 if (flag_dump_unnumbered)
523 fprintf (outfile, " [# deleted]");
524 else
525 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
526 sawclose = 0;
527 break;
528 }
529
530 if (subc != CODE_LABEL)
531 goto do_e;
532 }
533
534 if (flag_dump_unnumbered
535 || (flag_dump_unnumbered_links && (i == 1 || i == 2)
536 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
537 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
538 fputs (" #", outfile);
539 else
540 fprintf (outfile, " %d", INSN_UID (sub));
541 }
542 else
543 fputs (" 0", outfile);
544 sawclose = 0;
545 break;
546
547 case 't':
548 #ifndef GENERATOR_FILE
549 if (i == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
550 print_mem_expr (outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
551 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
552 print_mem_expr (outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
553 else
554 dump_addr (outfile, " ", XTREE (in_rtx, i));
555 #endif
556 break;
557
558 case '*':
559 fputs (" Unknown", outfile);
560 sawclose = 0;
561 break;
562
563 case 'B':
564 #ifndef GENERATOR_FILE
565 if (XBBDEF (in_rtx, i))
566 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
567 #endif
568 break;
569
570 default:
571 gcc_unreachable ();
572 }
573
574 switch (GET_CODE (in_rtx))
575 {
576 #ifndef GENERATOR_FILE
577 case MEM:
578 if (__builtin_expect (final_insns_dump_p, false))
579 fprintf (outfile, " [");
580 else
581 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC,
582 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
583
584 if (MEM_EXPR (in_rtx))
585 print_mem_expr (outfile, MEM_EXPR (in_rtx));
586
587 if (MEM_OFFSET_KNOWN_P (in_rtx))
588 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC, MEM_OFFSET (in_rtx));
589
590 if (MEM_SIZE_KNOWN_P (in_rtx))
591 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC, MEM_SIZE (in_rtx));
592
593 if (MEM_ALIGN (in_rtx) != 1)
594 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
595
596 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
597 fprintf (outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
598
599 fputc (']', outfile);
600 break;
601
602 case CONST_DOUBLE:
603 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
604 {
605 char s[60];
606
607 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
608 sizeof (s), 0, 1);
609 fprintf (outfile, " %s", s);
610
611 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
612 sizeof (s), 0, 1);
613 fprintf (outfile, " [%s]", s);
614 }
615 break;
616 #endif
617
618 case CODE_LABEL:
619 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
620 switch (LABEL_KIND (in_rtx))
621 {
622 case LABEL_NORMAL: break;
623 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
624 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
625 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
626 default: gcc_unreachable ();
627 }
628 break;
629
630 default:
631 break;
632 }
633
634 fputc (')', outfile);
635 sawclose = 1;
636 }
637
638 /* Print an rtx on the current line of FILE. Initially indent IND
639 characters. */
640
641 void
642 print_inline_rtx (FILE *outf, const_rtx x, int ind)
643 {
644 int oldsaw = sawclose;
645 int oldindent = indent;
646
647 sawclose = 0;
648 indent = ind;
649 outfile = outf;
650 print_rtx (x);
651 sawclose = oldsaw;
652 indent = oldindent;
653 }
654
655 /* Call this function from the debugger to see what X looks like. */
656
657 DEBUG_FUNCTION void
658 debug_rtx (const_rtx x)
659 {
660 outfile = stderr;
661 sawclose = 0;
662 print_rtx (x);
663 fprintf (stderr, "\n");
664 }
665
666 /* Dump rtx REF. */
667
668 DEBUG_FUNCTION void
669 debug (const rtx_def &ref)
670 {
671 debug_rtx (&ref);
672 }
673
674 DEBUG_FUNCTION void
675 debug (const rtx_def *ptr)
676 {
677 if (ptr)
678 debug (*ptr);
679 else
680 fprintf (stderr, "<nil>\n");
681 }
682
683 /* Count of rtx's to print with debug_rtx_list.
684 This global exists because gdb user defined commands have no arguments. */
685
686 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
687
688 /* Call this function to print list from X on.
689
690 N is a count of the rtx's to print. Positive values print from the specified
691 rtx on. Negative values print a window around the rtx.
692 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
693
694 DEBUG_FUNCTION void
695 debug_rtx_list (const_rtx x, int n)
696 {
697 int i,count;
698 const_rtx insn;
699
700 count = n == 0 ? 1 : n < 0 ? -n : n;
701
702 /* If we are printing a window, back up to the start. */
703
704 if (n < 0)
705 for (i = count / 2; i > 0; i--)
706 {
707 if (PREV_INSN (x) == 0)
708 break;
709 x = PREV_INSN (x);
710 }
711
712 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
713 {
714 debug_rtx (insn);
715 fprintf (stderr, "\n");
716 }
717 }
718
719 /* Call this function to print an rtx list from START to END inclusive. */
720
721 DEBUG_FUNCTION void
722 debug_rtx_range (const_rtx start, const_rtx end)
723 {
724 while (1)
725 {
726 debug_rtx (start);
727 fprintf (stderr, "\n");
728 if (!start || start == end)
729 break;
730 start = NEXT_INSN (start);
731 }
732 }
733
734 /* Call this function to search an rtx list to find one with insn uid UID,
735 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
736 The found insn is returned to enable further debugging analysis. */
737
738 DEBUG_FUNCTION const_rtx
739 debug_rtx_find (const_rtx x, int uid)
740 {
741 while (x != 0 && INSN_UID (x) != uid)
742 x = NEXT_INSN (x);
743 if (x != 0)
744 {
745 debug_rtx_list (x, debug_rtx_count);
746 return x;
747 }
748 else
749 {
750 fprintf (stderr, "insn uid %d not found\n", uid);
751 return 0;
752 }
753 }
754
755 /* External entry point for printing a chain of insns
756 starting with RTX_FIRST onto file OUTF.
757 A blank line separates insns.
758
759 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
760
761 void
762 print_rtl (FILE *outf, const_rtx rtx_first)
763 {
764 const_rtx tmp_rtx;
765
766 outfile = outf;
767 sawclose = 0;
768
769 if (rtx_first == 0)
770 {
771 fputs (print_rtx_head, outf);
772 fputs ("(nil)\n", outf);
773 }
774 else
775 switch (GET_CODE (rtx_first))
776 {
777 case INSN:
778 case JUMP_INSN:
779 case CALL_INSN:
780 case NOTE:
781 case CODE_LABEL:
782 case JUMP_TABLE_DATA:
783 case BARRIER:
784 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
785 {
786 fputs (print_rtx_head, outfile);
787 print_rtx (tmp_rtx);
788 fprintf (outfile, "\n");
789 }
790 break;
791
792 default:
793 fputs (print_rtx_head, outfile);
794 print_rtx (rtx_first);
795 }
796 }
797
798 /* Like print_rtx, except specify a file. */
799 /* Return nonzero if we actually printed anything. */
800
801 int
802 print_rtl_single (FILE *outf, const_rtx x)
803 {
804 return print_rtl_single_with_indent (outf, x, 0);
805 }
806
807 /* Like print_rtl_single, except specify a file and indentation. */
808
809 int
810 print_rtl_single_with_indent (FILE *outf, const_rtx x, int ind)
811 {
812 int old_indent = indent;
813 char *s_indent = (char *) alloca ((size_t) ind + 1);
814 memset ((void *) s_indent, ' ', (size_t) ind);
815 s_indent[ind] = '\0';
816
817 indent = ind;
818 outfile = outf;
819 sawclose = 0;
820 fputs (s_indent, outfile);
821 fputs (print_rtx_head, outfile);
822 print_rtx (x);
823 putc ('\n', outf);
824 indent = old_indent;
825 return 1;
826 }
827
828
829 /* Like print_rtl except without all the detail; for example,
830 if RTX is a CONST_INT then print in decimal format. */
831
832 void
833 print_simple_rtl (FILE *outf, const_rtx x)
834 {
835 flag_simple = 1;
836 print_rtl (outf, x);
837 flag_simple = 0;
838 }