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