rtl.texi (MEM_SIZE_KNOWN_P): Document.
[gcc.git] / gcc / print-rtl.c
1 /* Print RTL for GCC.
2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003,
3 2004, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22 /* This file is compiled twice: once for the generator programs,
23 once for the compiler. */
24 #ifdef GENERATOR_FILE
25 #include "bconfig.h"
26 #else
27 #include "config.h"
28 #endif
29
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include "rtl.h"
34
35 /* These headers all define things which are not available in
36 generator programs. */
37 #ifndef GENERATOR_FILE
38 #include "tree.h"
39 #include "flags.h"
40 #include "hard-reg-set.h"
41 #include "basic-block.h"
42 #include "diagnostic.h"
43 #include "tree-pretty-print.h"
44 #include "cselib.h"
45 #include "tree-pass.h"
46 #include "dwarf2out.h"
47 #endif
48
49 static FILE *outfile;
50
51 static int sawclose = 0;
52
53 static int indent;
54
55 static void print_rtx (const_rtx);
56
57 /* String printed at beginning of each RTL when it is dumped.
58 This string is set to ASM_COMMENT_START when the RTL is dumped in
59 the assembly output file. */
60 const char *print_rtx_head = "";
61
62 #ifdef GENERATOR_FILE
63 /* These are defined from the .opt file when not used in generator
64 programs. */
65
66 /* Nonzero means suppress output of instruction numbers
67 in debugging dumps.
68 This must be defined here so that programs like gencodes can be linked. */
69 int flag_dump_unnumbered = 0;
70
71 /* Nonzero means suppress output of instruction numbers for previous
72 and next insns in debugging dumps.
73 This must be defined here so that programs like gencodes can be linked. */
74 int flag_dump_unnumbered_links = 0;
75 #endif
76
77 /* Nonzero means use simplified format without flags, modes, etc. */
78 int flag_simple = 0;
79
80 /* Nonzero if we are dumping graphical description. */
81 int dump_for_graph;
82
83 #ifndef GENERATOR_FILE
84 void
85 print_mem_expr (FILE *outfile, const_tree expr)
86 {
87 fputc (' ', outfile);
88 print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
89 }
90 #endif
91
92 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
93
94 static void
95 print_rtx (const_rtx in_rtx)
96 {
97 int i = 0;
98 int j;
99 const char *format_ptr;
100 int is_insn;
101
102 if (sawclose)
103 {
104 if (flag_simple)
105 fputc (' ', outfile);
106 else
107 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
108 sawclose = 0;
109 }
110
111 if (in_rtx == 0)
112 {
113 fputs ("(nil)", outfile);
114 sawclose = 1;
115 return;
116 }
117 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
118 {
119 fprintf (outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
120 print_rtx_head, indent * 2, "");
121 sawclose = 1;
122 return;
123 }
124
125 is_insn = INSN_P (in_rtx);
126
127 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
128 in separate nodes and therefore have to handle them special here. */
129 if (dump_for_graph
130 && (is_insn || NOTE_P (in_rtx)
131 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
132 {
133 i = 3;
134 indent = 0;
135 }
136 else
137 {
138 /* Print name of expression code. */
139 if (flag_simple && CONST_INT_P (in_rtx))
140 fputc ('(', outfile);
141 else
142 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
143
144 if (! flag_simple)
145 {
146 if (RTX_FLAG (in_rtx, in_struct))
147 fputs ("/s", outfile);
148
149 if (RTX_FLAG (in_rtx, volatil))
150 fputs ("/v", outfile);
151
152 if (RTX_FLAG (in_rtx, unchanging))
153 fputs ("/u", outfile);
154
155 if (RTX_FLAG (in_rtx, frame_related))
156 fputs ("/f", outfile);
157
158 if (RTX_FLAG (in_rtx, jump))
159 fputs ("/j", outfile);
160
161 if (RTX_FLAG (in_rtx, call))
162 fputs ("/c", outfile);
163
164 if (RTX_FLAG (in_rtx, return_val))
165 fputs ("/i", outfile);
166
167 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
168 if ((GET_CODE (in_rtx) == EXPR_LIST
169 || GET_CODE (in_rtx) == INSN_LIST)
170 && (int)GET_MODE (in_rtx) < REG_NOTE_MAX)
171 fprintf (outfile, ":%s",
172 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
173
174 /* For other rtl, print the mode if it's not VOID. */
175 else if (GET_MODE (in_rtx) != VOIDmode)
176 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
177
178 #ifndef GENERATOR_FILE
179 if (GET_CODE (in_rtx) == VAR_LOCATION)
180 {
181 if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
182 fputs (" <debug string placeholder>", outfile);
183 else
184 print_mem_expr (outfile, PAT_VAR_LOCATION_DECL (in_rtx));
185 fputc (' ', outfile);
186 print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
187 if (PAT_VAR_LOCATION_STATUS (in_rtx)
188 == VAR_INIT_STATUS_UNINITIALIZED)
189 fprintf (outfile, " [uninit]");
190 sawclose = 1;
191 i = GET_RTX_LENGTH (VAR_LOCATION);
192 }
193 #endif
194 }
195 }
196
197 #ifndef GENERATOR_FILE
198 if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
199 i = 5;
200 #endif
201
202 /* Get the format string and skip the first elements if we have handled
203 them already. */
204 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
205 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
206 switch (*format_ptr++)
207 {
208 const char *str;
209
210 case 'T':
211 str = XTMPL (in_rtx, i);
212 goto string;
213
214 case 'S':
215 case 's':
216 str = XSTR (in_rtx, i);
217 string:
218
219 if (str == 0)
220 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
221 else
222 {
223 if (dump_for_graph)
224 fprintf (outfile, " (\\\"%s\\\")", str);
225 else
226 fprintf (outfile, " (\"%s\")", str);
227 }
228 sawclose = 1;
229 break;
230
231 /* 0 indicates a field for internal use that should not be printed.
232 An exception is the third field of a NOTE, where it indicates
233 that the field has several different valid contents. */
234 case '0':
235 if (i == 1 && REG_P (in_rtx))
236 {
237 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
238 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
239 }
240 #ifndef GENERATOR_FILE
241 else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
242 {
243 int flags = SYMBOL_REF_FLAGS (in_rtx);
244 if (flags)
245 fprintf (outfile, " [flags %#x]", flags);
246 }
247 else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
248 {
249 tree decl = SYMBOL_REF_DECL (in_rtx);
250 if (decl)
251 print_node_brief (outfile, "", decl, dump_flags);
252 }
253 #endif
254 else if (i == 4 && NOTE_P (in_rtx))
255 {
256 switch (NOTE_KIND (in_rtx))
257 {
258 case NOTE_INSN_EH_REGION_BEG:
259 case NOTE_INSN_EH_REGION_END:
260 if (flag_dump_unnumbered)
261 fprintf (outfile, " #");
262 else
263 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
264 sawclose = 1;
265 break;
266
267 case NOTE_INSN_BLOCK_BEG:
268 case NOTE_INSN_BLOCK_END:
269 #ifndef GENERATOR_FILE
270 dump_addr (outfile, " ", NOTE_BLOCK (in_rtx));
271 #endif
272 sawclose = 1;
273 break;
274
275 case NOTE_INSN_BASIC_BLOCK:
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_DELETED_LABEL:
286 {
287 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
288 if (label)
289 fprintf (outfile, " (\"%s\")", label);
290 else
291 fprintf (outfile, " \"\"");
292 }
293 break;
294
295 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
296 {
297 #ifndef GENERATOR_FILE
298 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
299 if (bb != 0)
300 fprintf (outfile, " [bb %d]", bb->index);
301 #endif
302 break;
303 }
304
305 case NOTE_INSN_VAR_LOCATION:
306 case NOTE_INSN_CALL_ARG_LOCATION:
307 #ifndef GENERATOR_FILE
308 fputc (' ', outfile);
309 print_rtx (NOTE_VAR_LOCATION (in_rtx));
310 #endif
311 break;
312
313 case NOTE_INSN_CFI:
314 #ifndef GENERATOR_FILE
315 fputc ('\n', outfile);
316 output_cfi_directive (outfile, NOTE_CFI (in_rtx));
317 fputc ('\t', outfile);
318 #endif
319 break;
320
321 default:
322 break;
323 }
324 }
325 else if (i == 8 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL)
326 /* Output the JUMP_LABEL reference. */
327 fprintf (outfile, "\n%s%*s -> %d", print_rtx_head, indent * 2, "",
328 INSN_UID (JUMP_LABEL (in_rtx)));
329 else if (i == 0 && GET_CODE (in_rtx) == VALUE)
330 {
331 #ifndef GENERATOR_FILE
332 cselib_val *val = CSELIB_VAL_PTR (in_rtx);
333
334 fprintf (outfile, " %u:%u", val->uid, val->hash);
335 dump_addr (outfile, " @", in_rtx);
336 dump_addr (outfile, "/", (void*)val);
337 #endif
338 }
339 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
340 {
341 #ifndef GENERATOR_FILE
342 fprintf (outfile, " D#%i",
343 DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
344 #endif
345 }
346 else if (i == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
347 {
348 indent += 2;
349 if (!sawclose)
350 fprintf (outfile, " ");
351 print_rtx (ENTRY_VALUE_EXP (in_rtx));
352 indent -= 2;
353 }
354 break;
355
356 case 'e':
357 do_e:
358 indent += 2;
359 if (i == 7 && INSN_P (in_rtx))
360 /* Put REG_NOTES on their own line. */
361 fprintf (outfile, "\n%s%*s",
362 print_rtx_head, indent * 2, "");
363 if (!sawclose)
364 fprintf (outfile, " ");
365 print_rtx (XEXP (in_rtx, i));
366 indent -= 2;
367 break;
368
369 case 'E':
370 case 'V':
371 indent += 2;
372 if (sawclose)
373 {
374 fprintf (outfile, "\n%s%*s",
375 print_rtx_head, indent * 2, "");
376 sawclose = 0;
377 }
378 fputs (" [", outfile);
379 if (NULL != XVEC (in_rtx, i))
380 {
381 indent += 2;
382 if (XVECLEN (in_rtx, i))
383 sawclose = 1;
384
385 for (j = 0; j < XVECLEN (in_rtx, i); j++)
386 print_rtx (XVECEXP (in_rtx, i, j));
387
388 indent -= 2;
389 }
390 if (sawclose)
391 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
392
393 fputs ("]", outfile);
394 sawclose = 1;
395 indent -= 2;
396 break;
397
398 case 'w':
399 if (! flag_simple)
400 fprintf (outfile, " ");
401 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
402 if (! flag_simple)
403 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
404 (unsigned HOST_WIDE_INT) XWINT (in_rtx, i));
405 break;
406
407 case 'i':
408 if (i == 5 && INSN_P (in_rtx))
409 {
410 #ifndef GENERATOR_FILE
411 /* Pretty-print insn locators. Ignore scoping as it is mostly
412 redundant with line number information and do not print anything
413 when there is no location information available. */
414 if (INSN_LOCATOR (in_rtx) && insn_file (in_rtx))
415 fprintf(outfile, " %s:%i", insn_file (in_rtx), insn_line (in_rtx));
416 #endif
417 }
418 else if (i == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
419 {
420 #ifndef GENERATOR_FILE
421 fprintf (outfile, " %s:%i",
422 locator_file (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
423 locator_line (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
424 #endif
425 }
426 else if (i == 1 && GET_CODE (in_rtx) == ASM_INPUT)
427 {
428 #ifndef GENERATOR_FILE
429 fprintf (outfile, " %s:%i",
430 locator_file (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
431 locator_line (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
432 #endif
433 }
434 else if (i == 6 && NOTE_P (in_rtx))
435 {
436 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
437 other times often contains garbage from INSN->NOTE death. */
438 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL)
439 fprintf (outfile, " %d", XINT (in_rtx, i));
440 }
441 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
442 else if (i == 1
443 && GET_CODE (in_rtx) == UNSPEC_VOLATILE
444 && XINT (in_rtx, 1) >= 0
445 && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
446 fprintf (outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
447 #endif
448 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
449 else if (i == 1
450 && (GET_CODE (in_rtx) == UNSPEC
451 || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
452 && XINT (in_rtx, 1) >= 0
453 && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
454 fprintf (outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
455 #endif
456 else
457 {
458 int value = XINT (in_rtx, i);
459 const char *name;
460
461 #ifndef GENERATOR_FILE
462 if (REG_P (in_rtx) && value < FIRST_PSEUDO_REGISTER)
463 fprintf (outfile, " %d %s", REGNO (in_rtx),
464 reg_names[REGNO (in_rtx)]);
465 else if (REG_P (in_rtx)
466 && value <= LAST_VIRTUAL_REGISTER)
467 {
468 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
469 fprintf (outfile, " %d virtual-incoming-args", value);
470 else if (value == VIRTUAL_STACK_VARS_REGNUM)
471 fprintf (outfile, " %d virtual-stack-vars", value);
472 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
473 fprintf (outfile, " %d virtual-stack-dynamic", value);
474 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
475 fprintf (outfile, " %d virtual-outgoing-args", value);
476 else if (value == VIRTUAL_CFA_REGNUM)
477 fprintf (outfile, " %d virtual-cfa", value);
478 else if (value == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
479 fprintf (outfile, " %d virtual-preferred-stack-boundary",
480 value);
481 else
482 fprintf (outfile, " %d virtual-reg-%d", value,
483 value-FIRST_VIRTUAL_REGISTER);
484 }
485 else
486 #endif
487 if (flag_dump_unnumbered
488 && (is_insn || NOTE_P (in_rtx)))
489 fputc ('#', outfile);
490 else
491 fprintf (outfile, " %d", value);
492
493 #ifndef GENERATOR_FILE
494 if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
495 {
496 fputs (" [", outfile);
497 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
498 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
499 if (REG_EXPR (in_rtx))
500 print_mem_expr (outfile, REG_EXPR (in_rtx));
501
502 if (REG_OFFSET (in_rtx))
503 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
504 REG_OFFSET (in_rtx));
505 fputs (" ]", outfile);
506 }
507 #endif
508
509 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
510 && XINT (in_rtx, i) >= 0
511 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
512 fprintf (outfile, " {%s}", name);
513 sawclose = 0;
514 }
515 break;
516
517 /* Print NOTE_INSN names rather than integer codes. */
518
519 case 'n':
520 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
521 sawclose = 0;
522 break;
523
524 case 'u':
525 if (XEXP (in_rtx, i) != NULL)
526 {
527 rtx sub = XEXP (in_rtx, i);
528 enum rtx_code subc = GET_CODE (sub);
529
530 if (GET_CODE (in_rtx) == LABEL_REF)
531 {
532 if (subc == NOTE
533 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
534 {
535 if (flag_dump_unnumbered)
536 fprintf (outfile, " [# deleted]");
537 else
538 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
539 sawclose = 0;
540 break;
541 }
542
543 if (subc != CODE_LABEL)
544 goto do_e;
545 }
546
547 if (flag_dump_unnumbered
548 || (flag_dump_unnumbered_links && (i == 1 || i == 2)
549 && (INSN_P (in_rtx) || NOTE_P (in_rtx)
550 || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
551 fputs (" #", outfile);
552 else
553 fprintf (outfile, " %d", INSN_UID (sub));
554 }
555 else
556 fputs (" 0", outfile);
557 sawclose = 0;
558 break;
559
560 case 't':
561 #ifndef GENERATOR_FILE
562 if (i == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
563 print_mem_expr (outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
564 else if (i == 0 && GET_CODE (in_rtx) == DEBUG_PARAMETER_REF)
565 print_mem_expr (outfile, DEBUG_PARAMETER_REF_DECL (in_rtx));
566 else
567 dump_addr (outfile, " ", XTREE (in_rtx, i));
568 #endif
569 break;
570
571 case '*':
572 fputs (" Unknown", outfile);
573 sawclose = 0;
574 break;
575
576 case 'B':
577 #ifndef GENERATOR_FILE
578 if (XBBDEF (in_rtx, i))
579 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
580 #endif
581 break;
582
583 default:
584 gcc_unreachable ();
585 }
586
587 switch (GET_CODE (in_rtx))
588 {
589 #ifndef GENERATOR_FILE
590 case MEM:
591 if (__builtin_expect (final_insns_dump_p, false))
592 fprintf (outfile, " [");
593 else
594 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC,
595 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
596
597 if (MEM_EXPR (in_rtx))
598 print_mem_expr (outfile, MEM_EXPR (in_rtx));
599
600 if (MEM_OFFSET (in_rtx))
601 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
602 INTVAL (MEM_OFFSET (in_rtx)));
603
604 if (MEM_SIZE_KNOWN_P (in_rtx))
605 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC, MEM_SIZE (in_rtx));
606
607 if (MEM_ALIGN (in_rtx) != 1)
608 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
609
610 if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
611 fprintf (outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
612
613 fputc (']', outfile);
614 break;
615
616 case CONST_DOUBLE:
617 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
618 {
619 char s[60];
620
621 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
622 sizeof (s), 0, 1);
623 fprintf (outfile, " %s", s);
624
625 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
626 sizeof (s), 0, 1);
627 fprintf (outfile, " [%s]", s);
628 }
629 break;
630 #endif
631
632 case CODE_LABEL:
633 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
634 switch (LABEL_KIND (in_rtx))
635 {
636 case LABEL_NORMAL: break;
637 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
638 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
639 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
640 default: gcc_unreachable ();
641 }
642 break;
643
644 default:
645 break;
646 }
647
648 if (dump_for_graph
649 && (is_insn || NOTE_P (in_rtx)
650 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
651 sawclose = 0;
652 else
653 {
654 fputc (')', outfile);
655 sawclose = 1;
656 }
657 }
658
659 /* Print an rtx on the current line of FILE. Initially indent IND
660 characters. */
661
662 void
663 print_inline_rtx (FILE *outf, const_rtx x, int ind)
664 {
665 int oldsaw = sawclose;
666 int oldindent = indent;
667
668 sawclose = 0;
669 indent = ind;
670 outfile = outf;
671 print_rtx (x);
672 sawclose = oldsaw;
673 indent = oldindent;
674 }
675
676 /* Call this function from the debugger to see what X looks like. */
677
678 DEBUG_FUNCTION void
679 debug_rtx (const_rtx x)
680 {
681 outfile = stderr;
682 sawclose = 0;
683 print_rtx (x);
684 fprintf (stderr, "\n");
685 }
686
687 /* Count of rtx's to print with debug_rtx_list.
688 This global exists because gdb user defined commands have no arguments. */
689
690 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
691
692 /* Call this function to print list from X on.
693
694 N is a count of the rtx's to print. Positive values print from the specified
695 rtx on. Negative values print a window around the rtx.
696 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
697
698 DEBUG_FUNCTION void
699 debug_rtx_list (const_rtx x, int n)
700 {
701 int i,count;
702 const_rtx insn;
703
704 count = n == 0 ? 1 : n < 0 ? -n : n;
705
706 /* If we are printing a window, back up to the start. */
707
708 if (n < 0)
709 for (i = count / 2; i > 0; i--)
710 {
711 if (PREV_INSN (x) == 0)
712 break;
713 x = PREV_INSN (x);
714 }
715
716 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
717 {
718 debug_rtx (insn);
719 fprintf (stderr, "\n");
720 }
721 }
722
723 /* Call this function to print an rtx list from START to END inclusive. */
724
725 DEBUG_FUNCTION void
726 debug_rtx_range (const_rtx start, const_rtx end)
727 {
728 while (1)
729 {
730 debug_rtx (start);
731 fprintf (stderr, "\n");
732 if (!start || start == end)
733 break;
734 start = NEXT_INSN (start);
735 }
736 }
737
738 /* Call this function to search an rtx list to find one with insn uid UID,
739 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
740 The found insn is returned to enable further debugging analysis. */
741
742 DEBUG_FUNCTION const_rtx
743 debug_rtx_find (const_rtx x, int uid)
744 {
745 while (x != 0 && INSN_UID (x) != uid)
746 x = NEXT_INSN (x);
747 if (x != 0)
748 {
749 debug_rtx_list (x, debug_rtx_count);
750 return x;
751 }
752 else
753 {
754 fprintf (stderr, "insn uid %d not found\n", uid);
755 return 0;
756 }
757 }
758
759 /* External entry point for printing a chain of insns
760 starting with RTX_FIRST onto file OUTF.
761 A blank line separates insns.
762
763 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
764
765 void
766 print_rtl (FILE *outf, const_rtx rtx_first)
767 {
768 const_rtx tmp_rtx;
769
770 outfile = outf;
771 sawclose = 0;
772
773 if (rtx_first == 0)
774 {
775 fputs (print_rtx_head, outf);
776 fputs ("(nil)\n", outf);
777 }
778 else
779 switch (GET_CODE (rtx_first))
780 {
781 case INSN:
782 case JUMP_INSN:
783 case CALL_INSN:
784 case NOTE:
785 case CODE_LABEL:
786 case BARRIER:
787 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
788 {
789 fputs (print_rtx_head, outfile);
790 print_rtx (tmp_rtx);
791 fprintf (outfile, "\n");
792 }
793 break;
794
795 default:
796 fputs (print_rtx_head, outfile);
797 print_rtx (rtx_first);
798 }
799 }
800
801 /* Like print_rtx, except specify a file. */
802 /* Return nonzero if we actually printed anything. */
803
804 int
805 print_rtl_single (FILE *outf, const_rtx x)
806 {
807 outfile = outf;
808 sawclose = 0;
809 fputs (print_rtx_head, outfile);
810 print_rtx (x);
811 putc ('\n', outf);
812 return 1;
813 }
814
815
816 /* Like print_rtl except without all the detail; for example,
817 if RTX is a CONST_INT then print in decimal format. */
818
819 void
820 print_simple_rtl (FILE *outf, const_rtx x)
821 {
822 flag_simple = 1;
823 print_rtl (outf, x);
824 flag_simple = 0;
825 }