1 /* Print RTL for GNU C Compiler.
2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
31 /* How to print out a register name.
32 We don't use PRINT_REG because some definitions of PRINT_REG
34 #ifndef DEBUG_PRINT_REG
35 #define DEBUG_PRINT_REG(RTX, CODE, FILE) \
36 fprintf ((FILE), "%d %s", REGNO (RTX), reg_names[REGNO (RTX)])
39 /* Array containing all of the register names */
41 #ifdef DEBUG_REGISTER_NAMES
42 static const char * const debug_reg_names
[] = DEBUG_REGISTER_NAMES
;
43 #define reg_names debug_reg_names
45 const char * reg_names
[] = REGISTER_NAMES
;
50 static const char xspaces
[] = " ";
52 static int sawclose
= 0;
56 static void print_rtx
PARAMS ((rtx
));
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
= "";
63 /* Nonzero means suppress output of instruction numbers and line number
64 notes in debugging dumps.
65 This must be defined here so that programs like gencodes can be linked. */
66 int flag_dump_unnumbered
= 0;
68 /* Nonzero means use simplified format without flags, modes, etc. */
71 /* Nonzero if we are dumping graphical description. */
74 /* Nonzero to dump all call_placeholder alternatives. */
75 static int debug_call_placeholder_verbose
;
77 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
85 register const char *format_ptr
;
94 fprintf (outfile
, "\n%s%s",
96 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
102 fputs ("(nil)", outfile
);
107 is_insn
= (INSN_P (in_rtx
));
109 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
110 in separate nodes and therefore have to handle them special here. */
111 if (dump_for_graph
&&
112 (is_insn
|| GET_CODE (in_rtx
) == NOTE
|| GET_CODE (in_rtx
) == CODE_LABEL
113 || GET_CODE (in_rtx
) == BARRIER
))
120 /* print name of expression code */
121 if (flag_simple
&& GET_CODE (in_rtx
) == CONST_INT
)
122 fputc ('(', outfile
);
124 fprintf (outfile
, "(%s", GET_RTX_NAME (GET_CODE (in_rtx
)));
128 if (in_rtx
->in_struct
)
129 fputs ("/s", outfile
);
132 fputs ("/v", outfile
);
134 if (in_rtx
->unchanging
)
135 fputs ("/u", outfile
);
137 if (in_rtx
->integrated
)
138 fputs ("/i", outfile
);
140 if (in_rtx
->frame_related
)
141 fputs ("/f", outfile
);
144 fputs ("/j", outfile
);
147 fputs ("/c", outfile
);
149 if (GET_MODE (in_rtx
) != VOIDmode
)
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 fprintf (outfile
, ":%s",
155 GET_REG_NOTE_NAME (GET_MODE (in_rtx
)));
157 fprintf (outfile
, ":%s", GET_MODE_NAME (GET_MODE (in_rtx
)));
162 /* Get the format string and skip the first elements if we have handled
164 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
)) + i
;
166 for (; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
167 switch (*format_ptr
++)
171 if (XSTR (in_rtx
, i
) == 0)
172 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
176 fprintf (outfile
, " (\\\"%s\\\")", XSTR (in_rtx
, i
));
178 fprintf (outfile
, " (\"%s\")", XSTR (in_rtx
, i
));
183 /* 0 indicates a field for internal use that should not be printed.
184 An exception is the third field of a NOTE, where it indicates
185 that the field has several different valid contents. */
187 if (i
== 1 && GET_CODE (in_rtx
) == REG
)
189 if (REGNO (in_rtx
) != ORIGINAL_REGNO (in_rtx
))
190 fprintf (outfile
, " [%d]", ORIGINAL_REGNO (in_rtx
));
193 if (i
== 3 && GET_CODE (in_rtx
) == NOTE
)
195 switch (NOTE_LINE_NUMBER (in_rtx
))
197 case NOTE_INSN_EH_REGION_BEG
:
198 case NOTE_INSN_EH_REGION_END
:
199 if (flag_dump_unnumbered
)
200 fprintf (outfile
, " #");
202 fprintf (outfile
, " %d", NOTE_EH_HANDLER (in_rtx
));
206 case NOTE_INSN_BLOCK_BEG
:
207 case NOTE_INSN_BLOCK_END
:
208 fprintf (outfile
, " ");
209 if (flag_dump_unnumbered
)
210 fprintf (outfile
, "#");
212 fprintf (outfile
, HOST_PTR_PRINTF
,
213 (char *) NOTE_BLOCK (in_rtx
));
217 case NOTE_INSN_RANGE_BEG
:
218 case NOTE_INSN_RANGE_END
:
222 fprintf (outfile
, " ");
223 print_rtx (NOTE_RANGE_INFO (in_rtx
));
227 case NOTE_INSN_BASIC_BLOCK
:
229 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
231 fprintf (outfile
, " [bb %d]", bb
->index
);
235 case NOTE_INSN_EXPECTED_VALUE
:
238 fprintf (outfile
, " ");
239 print_rtx (NOTE_EXPECTED_VALUE (in_rtx
));
243 case NOTE_INSN_DELETED_LABEL
:
244 if (NOTE_SOURCE_FILE (in_rtx
))
245 fprintf (outfile
, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx
));
247 fprintf (outfile
, " \"\"");
252 const char * const str
= X0STR (in_rtx
, i
);
254 if (NOTE_LINE_NUMBER (in_rtx
) < 0)
257 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
261 fprintf (outfile
, " (\\\"%s\\\")", str
);
263 fprintf (outfile
, " (\"%s\")", str
);
275 fprintf (outfile
, " ");
276 print_rtx (XEXP (in_rtx
, i
));
285 fprintf (outfile
, "\n%s%s",
287 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
290 fputs ("[ ", outfile
);
291 if (NULL
!= XVEC (in_rtx
, i
))
294 if (XVECLEN (in_rtx
, i
))
297 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
298 print_rtx (XVECEXP (in_rtx
, i
, j
));
303 fprintf (outfile
, "\n%s%s",
305 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
307 fputs ("] ", outfile
);
314 fprintf (outfile
, " ");
315 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, XWINT (in_rtx
, i
));
318 fprintf (outfile
, " [");
319 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
, XWINT (in_rtx
, i
));
320 fprintf (outfile
, "]");
326 register int value
= XINT (in_rtx
, i
);
329 if (GET_CODE (in_rtx
) == REG
&& value
< FIRST_PSEUDO_REGISTER
)
331 fputc (' ', outfile
);
332 DEBUG_PRINT_REG (in_rtx
, 0, outfile
);
334 else if (GET_CODE (in_rtx
) == REG
&& value
<= LAST_VIRTUAL_REGISTER
)
336 if (value
== VIRTUAL_INCOMING_ARGS_REGNUM
)
337 fprintf (outfile
, " %d virtual-incoming-args", value
);
338 else if (value
== VIRTUAL_STACK_VARS_REGNUM
)
339 fprintf (outfile
, " %d virtual-stack-vars", value
);
340 else if (value
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
341 fprintf (outfile
, " %d virtual-stack-dynamic", value
);
342 else if (value
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
343 fprintf (outfile
, " %d virtual-outgoing-args", value
);
344 else if (value
== VIRTUAL_CFA_REGNUM
)
345 fprintf (outfile
, " %d virtual-cfa", value
);
347 fprintf (outfile
, " %d virtual-reg-%d", value
,
348 value
-FIRST_VIRTUAL_REGISTER
);
350 else if (flag_dump_unnumbered
351 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
))
352 fputc ('#', outfile
);
354 fprintf (outfile
, " %d", value
);
356 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
357 && XINT (in_rtx
, i
) >= 0
358 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
359 fprintf (outfile
, " {%s}", name
);
364 /* Print NOTE_INSN names rather than integer codes. */
367 if (XINT (in_rtx
, i
) >= (int) NOTE_INSN_BIAS
368 && XINT (in_rtx
, i
) < (int) NOTE_INSN_MAX
)
369 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
371 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
376 if (XEXP (in_rtx
, i
) != NULL
)
378 rtx sub
= XEXP (in_rtx
, i
);
379 enum rtx_code subc
= GET_CODE (sub
);
381 if (GET_CODE (in_rtx
) == LABEL_REF
)
384 && NOTE_LINE_NUMBER (sub
) == NOTE_INSN_DELETED_LABEL
)
386 if (flag_dump_unnumbered
)
387 fprintf (outfile
, " [# deleted]");
389 fprintf (outfile
, " [%d deleted]", INSN_UID (sub
));
394 if (subc
!= CODE_LABEL
)
398 if (flag_dump_unnumbered
)
399 fputs (" #", outfile
);
401 fprintf (outfile
, " %d", INSN_UID (sub
));
404 fputs (" 0", outfile
);
409 if (XBITMAP (in_rtx
, i
) == NULL
)
410 fputs (" {null}", outfile
);
412 bitmap_print (outfile
, XBITMAP (in_rtx
, i
), " {", "}");
418 fprintf (outfile
, HOST_PTR_PRINTF
, (char *) XTREE (in_rtx
, i
));
422 fputs (" Unknown", outfile
);
428 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
433 switch (GET_CODE (in_rtx
))
436 fputc (' ', outfile
);
437 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, MEM_ALIAS_SET (in_rtx
));
440 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
442 if (FLOAT_MODE_P (GET_MODE (in_rtx
)))
445 REAL_VALUE_FROM_CONST_DOUBLE (val
, in_rtx
);
446 fprintf (outfile
, " [%.16g]", val
);
452 fprintf (outfile
, " [%d uses]", LABEL_NUSES (in_rtx
));
453 if (LABEL_ALTERNATE_NAME (in_rtx
))
454 fprintf (outfile
, " [alternate name: %s]",
455 LABEL_ALTERNATE_NAME (in_rtx
));
458 case CALL_PLACEHOLDER
:
459 if (debug_call_placeholder_verbose
)
461 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile
);
462 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
464 fputs ("\n ", outfile
);
465 print_inline_rtx (outfile
, tem
, 4);
468 tem
= XEXP (in_rtx
, 1);
470 fputs ("\n ])\n (const_string \"tail_call\") (sequence [", outfile
);
471 for (; tem
!= 0; tem
= NEXT_INSN (tem
))
473 fputs ("\n ", outfile
);
474 print_inline_rtx (outfile
, tem
, 4);
477 tem
= XEXP (in_rtx
, 2);
479 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [", outfile
);
480 for (; tem
!= 0; tem
= NEXT_INSN (tem
))
482 fputs ("\n ", outfile
);
483 print_inline_rtx (outfile
, tem
, 4);
486 fputs ("\n ])\n ])", outfile
);
490 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
491 if (GET_CODE (tem
) == CALL_INSN
)
493 fprintf (outfile
, " ");
504 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
505 || GET_CODE (in_rtx
) == CODE_LABEL
|| GET_CODE (in_rtx
) == BARRIER
))
509 fputc (')', outfile
);
514 /* Print an rtx on the current line of FILE. Initially indent IND
518 print_inline_rtx (outf
, x
, ind
)
523 int oldsaw
= sawclose
;
524 int oldindent
= indent
;
534 /* Call this function from the debugger to see what X looks like. */
542 fprintf (stderr
, "\n");
545 /* Count of rtx's to print with debug_rtx_list.
546 This global exists because gdb user defined commands have no arguments. */
548 int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
550 /* Call this function to print list from X on.
552 N is a count of the rtx's to print. Positive values print from the specified
553 rtx on. Negative values print a window around the rtx.
554 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
557 debug_rtx_list (x
, n
)
564 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
566 /* If we are printing a window, back up to the start. */
569 for (i
= count
/ 2; i
> 0; i
--)
571 if (PREV_INSN (x
) == 0)
576 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
580 /* Call this function to print an rtx list from START to END inclusive. */
583 debug_rtx_range (start
, end
)
589 if (!start
|| start
== end
)
591 start
= NEXT_INSN (start
);
595 /* Call this function to search an rtx list to find one with insn uid UID,
596 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
597 The found insn is returned to enable further debugging analysis. */
600 debug_rtx_find (x
, uid
)
604 while (x
!= 0 && INSN_UID (x
) != uid
)
608 debug_rtx_list (x
, debug_rtx_count
);
613 fprintf (stderr
, "insn uid %d not found\n", uid
);
618 /* External entry point for printing a chain of insns
619 starting with RTX_FIRST onto file OUTF.
620 A blank line separates insns.
622 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
625 print_rtl (outf
, rtx_first
)
629 register rtx tmp_rtx
;
636 fputs (print_rtx_head
, outf
);
637 fputs ("(nil)\n", outf
);
640 switch (GET_CODE (rtx_first
))
648 for (tmp_rtx
= rtx_first
; tmp_rtx
!= 0; tmp_rtx
= NEXT_INSN (tmp_rtx
))
649 if (! flag_dump_unnumbered
650 || GET_CODE (tmp_rtx
) != NOTE
|| NOTE_LINE_NUMBER (tmp_rtx
) < 0)
652 fputs (print_rtx_head
, outfile
);
654 fprintf (outfile
, "\n");
659 fputs (print_rtx_head
, outfile
);
660 print_rtx (rtx_first
);
664 /* Like print_rtx, except specify a file. */
665 /* Return nonzero if we actually printed anything. */
668 print_rtl_single (outf
, x
)
674 if (! flag_dump_unnumbered
675 || GET_CODE (x
) != NOTE
|| NOTE_LINE_NUMBER (x
) < 0)
677 fputs (print_rtx_head
, outfile
);
686 /* Like print_rtl except without all the detail; for example,
687 if RTX is a CONST_INT then print in decimal format. */
690 print_simple_rtl (outf
, x
)