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