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