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