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