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