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