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 if we are dumping graphical description. */
71 /* Nonzero to dump all call_placeholder alternatives. */
72 static int debug_call_placeholder_verbose
;
74 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
82 register const char *format_ptr
;
88 fprintf (outfile
, "\n%s%s",
90 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
96 fputs ("(nil)", outfile
);
101 is_insn
= (INSN_P (in_rtx
));
103 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
104 in separate nodes and therefore have to handle them special here. */
105 if (dump_for_graph
&&
106 (is_insn
|| GET_CODE (in_rtx
) == NOTE
|| GET_CODE (in_rtx
) == CODE_LABEL
107 || GET_CODE (in_rtx
) == BARRIER
))
114 /* print name of expression code */
115 fprintf (outfile
, "(%s", GET_RTX_NAME (GET_CODE (in_rtx
)));
117 if (in_rtx
->in_struct
)
118 fputs ("/s", outfile
);
121 fputs ("/v", outfile
);
123 if (in_rtx
->unchanging
)
124 fputs ("/u", outfile
);
126 if (in_rtx
->integrated
)
127 fputs ("/i", outfile
);
129 if (in_rtx
->frame_related
)
130 fputs ("/f", outfile
);
133 fputs ("/j", outfile
);
136 fputs ("/c", outfile
);
138 if (GET_MODE (in_rtx
) != VOIDmode
)
140 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
141 if (GET_CODE (in_rtx
) == EXPR_LIST
|| GET_CODE (in_rtx
) == INSN_LIST
)
142 fprintf (outfile
, ":%s", GET_REG_NOTE_NAME (GET_MODE (in_rtx
)));
144 fprintf (outfile
, ":%s", GET_MODE_NAME (GET_MODE (in_rtx
)));
148 /* Get the format string and skip the first elements if we have handled
150 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
)) + i
;
152 for (; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
153 switch (*format_ptr
++)
157 if (XSTR (in_rtx
, i
) == 0)
158 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
162 fprintf (outfile
, " (\\\"%s\\\")", XSTR (in_rtx
, i
));
164 fprintf (outfile
, " (\"%s\")", XSTR (in_rtx
, i
));
169 /* 0 indicates a field for internal use that should not be printed.
170 An exception is the third field of a NOTE, where it indicates
171 that the field has several different valid contents. */
173 if (i
== 3 && GET_CODE (in_rtx
) == NOTE
)
175 switch (NOTE_LINE_NUMBER (in_rtx
))
177 case NOTE_INSN_EH_REGION_BEG
:
178 case NOTE_INSN_EH_REGION_END
:
179 if (flag_dump_unnumbered
)
180 fprintf (outfile
, " #");
182 fprintf (outfile
, " %d", NOTE_EH_HANDLER (in_rtx
));
186 case NOTE_INSN_BLOCK_BEG
:
187 case NOTE_INSN_BLOCK_END
:
188 fprintf (outfile
, " ");
189 if (flag_dump_unnumbered
)
190 fprintf (outfile
, "#");
192 fprintf (outfile
, HOST_PTR_PRINTF
,
193 (char *) NOTE_BLOCK (in_rtx
));
197 case NOTE_INSN_RANGE_BEG
:
198 case NOTE_INSN_RANGE_END
:
202 fprintf (outfile
, " ");
203 print_rtx (NOTE_RANGE_INFO (in_rtx
));
207 case NOTE_INSN_BASIC_BLOCK
:
209 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
211 fprintf (outfile
, " [bb %d]", bb
->index
);
215 case NOTE_INSN_EXPECTED_VALUE
:
218 fprintf (outfile
, " ");
219 print_rtx (NOTE_EXPECTED_VALUE (in_rtx
));
223 case NOTE_INSN_DELETED_LABEL
:
224 if (NOTE_SOURCE_FILE (in_rtx
))
225 fprintf (outfile
, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx
));
227 fprintf (outfile
, " \"\"");
232 const char * const str
= X0STR (in_rtx
, i
);
234 if (NOTE_LINE_NUMBER (in_rtx
) < 0)
237 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
241 fprintf (outfile
, " (\\\"%s\\\")", str
);
243 fprintf (outfile
, " (\"%s\")", str
);
255 fprintf (outfile
, " ");
256 print_rtx (XEXP (in_rtx
, i
));
265 fprintf (outfile
, "\n%s%s",
267 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
270 fputs ("[ ", outfile
);
271 if (NULL
!= XVEC (in_rtx
, i
))
274 if (XVECLEN (in_rtx
, i
))
277 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
278 print_rtx (XVECEXP (in_rtx
, i
, j
));
283 fprintf (outfile
, "\n%s%s",
285 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
287 fputs ("] ", outfile
);
293 fprintf (outfile
, " ");
294 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, XWINT (in_rtx
, i
));
295 fprintf (outfile
, " [");
296 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
, XWINT (in_rtx
, i
));
297 fprintf (outfile
, "]");
302 register int value
= XINT (in_rtx
, i
);
305 if (GET_CODE (in_rtx
) == REG
&& value
< FIRST_PSEUDO_REGISTER
)
307 fputc (' ', outfile
);
308 DEBUG_PRINT_REG (in_rtx
, 0, outfile
);
310 else if (GET_CODE (in_rtx
) == REG
&& value
<= LAST_VIRTUAL_REGISTER
)
312 if (value
== VIRTUAL_INCOMING_ARGS_REGNUM
)
313 fprintf (outfile
, " %d virtual-incoming-args", value
);
314 else if (value
== VIRTUAL_STACK_VARS_REGNUM
)
315 fprintf (outfile
, " %d virtual-stack-vars", value
);
316 else if (value
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
317 fprintf (outfile
, " %d virtual-stack-dynamic", value
);
318 else if (value
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
319 fprintf (outfile
, " %d virtual-outgoing-args", value
);
320 else if (value
== VIRTUAL_CFA_REGNUM
)
321 fprintf (outfile
, " %d virtual-cfa", value
);
323 fprintf (outfile
, " %d virtual-reg-%d", value
,
324 value
-FIRST_VIRTUAL_REGISTER
);
326 else if (flag_dump_unnumbered
327 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
))
328 fputc ('#', outfile
);
330 fprintf (outfile
, " %d", value
);
332 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
333 && XINT (in_rtx
, i
) >= 0
334 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
335 fprintf (outfile
, " {%s}", name
);
340 /* Print NOTE_INSN names rather than integer codes. */
343 if (XINT (in_rtx
, i
) >= NOTE_INSN_BIAS
344 && XINT (in_rtx
, i
) < NOTE_INSN_MAX
)
345 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
347 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
352 if (XEXP (in_rtx
, i
) != NULL
)
354 rtx sub
= XEXP (in_rtx
, i
);
355 enum rtx_code subc
= GET_CODE (sub
);
357 if (GET_CODE (in_rtx
) == LABEL_REF
)
360 && NOTE_LINE_NUMBER (sub
) == NOTE_INSN_DELETED_LABEL
)
362 if (flag_dump_unnumbered
)
363 fprintf (outfile
, " [# deleted]");
365 fprintf (outfile
, " [%d deleted]", INSN_UID (sub
));
370 if (subc
!= CODE_LABEL
)
374 if (flag_dump_unnumbered
)
375 fputs (" #", outfile
);
377 fprintf (outfile
, " %d", INSN_UID (sub
));
380 fputs (" 0", outfile
);
385 if (XBITMAP (in_rtx
, i
) == NULL
)
386 fputs (" {null}", outfile
);
388 bitmap_print (outfile
, XBITMAP (in_rtx
, i
), " {", "}");
394 fprintf (outfile
, HOST_PTR_PRINTF
, (char *) XTREE (in_rtx
, i
));
398 fputs (" Unknown", outfile
);
404 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
409 switch (GET_CODE (in_rtx
))
412 fputc (' ', outfile
);
413 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, MEM_ALIAS_SET (in_rtx
));
416 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
418 if (FLOAT_MODE_P (GET_MODE (in_rtx
)))
421 REAL_VALUE_FROM_CONST_DOUBLE (val
, in_rtx
);
422 fprintf (outfile
, " [%.16g]", val
);
428 fprintf (outfile
, " [%d uses]", LABEL_NUSES (in_rtx
));
429 if (LABEL_ALTERNATE_NAME (in_rtx
))
430 fprintf (outfile
, " [alternate name: %s]",
431 LABEL_ALTERNATE_NAME (in_rtx
));
434 case CALL_PLACEHOLDER
:
435 if (debug_call_placeholder_verbose
)
437 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile
);
438 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
440 fputs ("\n ", outfile
);
441 print_inline_rtx (outfile
, tem
, 4);
444 tem
= XEXP (in_rtx
, 1);
446 fputs ("\n ])\n (const_string \"tail_call\") (sequence [", outfile
);
447 for (; tem
!= 0; tem
= NEXT_INSN (tem
))
449 fputs ("\n ", outfile
);
450 print_inline_rtx (outfile
, tem
, 4);
453 tem
= XEXP (in_rtx
, 2);
455 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [", outfile
);
456 for (; tem
!= 0; tem
= NEXT_INSN (tem
))
458 fputs ("\n ", outfile
);
459 print_inline_rtx (outfile
, tem
, 4);
462 fputs ("\n ])\n ])", outfile
);
466 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
467 if (GET_CODE (tem
) == CALL_INSN
)
469 fprintf (outfile
, " ");
480 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
481 || GET_CODE (in_rtx
) == CODE_LABEL
|| GET_CODE (in_rtx
) == BARRIER
))
485 fputc (')', outfile
);
490 /* Print an rtx on the current line of FILE. Initially indent IND
494 print_inline_rtx (outf
, x
, ind
)
499 int oldsaw
= sawclose
;
500 int oldindent
= indent
;
510 /* Call this function from the debugger to see what X looks like. */
518 fprintf (stderr
, "\n");
521 /* Count of rtx's to print with debug_rtx_list.
522 This global exists because gdb user defined commands have no arguments. */
524 int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
526 /* Call this function to print list from X on.
528 N is a count of the rtx's to print. Positive values print from the specified
529 rtx on. Negative values print a window around the rtx.
530 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
533 debug_rtx_list (x
, n
)
540 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
542 /* If we are printing a window, back up to the start. */
545 for (i
= count
/ 2; i
> 0; i
--)
547 if (PREV_INSN (x
) == 0)
552 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
556 /* Call this function to print an rtx list from START to END inclusive. */
559 debug_rtx_range (start
, end
)
565 if (!start
|| start
== end
)
567 start
= NEXT_INSN (start
);
571 /* Call this function to search an rtx list to find one with insn uid UID,
572 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
573 The found insn is returned to enable further debugging analysis. */
576 debug_rtx_find (x
, uid
)
580 while (x
!= 0 && INSN_UID (x
) != uid
)
584 debug_rtx_list (x
, debug_rtx_count
);
589 fprintf (stderr
, "insn uid %d not found\n", uid
);
594 /* External entry point for printing a chain of insns
595 starting with RTX_FIRST onto file OUTF.
596 A blank line separates insns.
598 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
601 print_rtl (outf
, rtx_first
)
605 register rtx tmp_rtx
;
612 fputs (print_rtx_head
, outf
);
613 fputs ("(nil)\n", outf
);
616 switch (GET_CODE (rtx_first
))
624 for (tmp_rtx
= rtx_first
; tmp_rtx
!= 0; tmp_rtx
= NEXT_INSN (tmp_rtx
))
625 if (! flag_dump_unnumbered
626 || GET_CODE (tmp_rtx
) != NOTE
|| NOTE_LINE_NUMBER (tmp_rtx
) < 0)
628 fputs (print_rtx_head
, outfile
);
630 fprintf (outfile
, "\n");
635 fputs (print_rtx_head
, outfile
);
636 print_rtx (rtx_first
);
640 /* Like print_rtx, except specify a file. */
641 /* Return nonzero if we actually printed anything. */
644 print_rtl_single (outf
, x
)
650 if (! flag_dump_unnumbered
651 || GET_CODE (x
) != NOTE
|| NOTE_LINE_NUMBER (x
) < 0)
653 fputs (print_rtx_head
, outfile
);