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
, "]");
325 if (i
== 5 && GET_CODE (in_rtx
) == NOTE
)
327 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
328 other times often contains garbage from INSN->NOTE death. */
329 if (NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_DELETED_LABEL
)
330 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
334 register int value
= XINT (in_rtx
, i
);
337 if (GET_CODE (in_rtx
) == REG
&& value
< FIRST_PSEUDO_REGISTER
)
339 fputc (' ', outfile
);
340 DEBUG_PRINT_REG (in_rtx
, 0, outfile
);
342 else if (GET_CODE (in_rtx
) == REG
343 && value
<= LAST_VIRTUAL_REGISTER
)
345 if (value
== VIRTUAL_INCOMING_ARGS_REGNUM
)
346 fprintf (outfile
, " %d virtual-incoming-args", value
);
347 else if (value
== VIRTUAL_STACK_VARS_REGNUM
)
348 fprintf (outfile
, " %d virtual-stack-vars", value
);
349 else if (value
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
350 fprintf (outfile
, " %d virtual-stack-dynamic", value
);
351 else if (value
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
352 fprintf (outfile
, " %d virtual-outgoing-args", value
);
353 else if (value
== VIRTUAL_CFA_REGNUM
)
354 fprintf (outfile
, " %d virtual-cfa", value
);
356 fprintf (outfile
, " %d virtual-reg-%d", value
,
357 value
-FIRST_VIRTUAL_REGISTER
);
359 else if (flag_dump_unnumbered
360 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
))
361 fputc ('#', outfile
);
363 fprintf (outfile
, " %d", value
);
365 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
366 && XINT (in_rtx
, i
) >= 0
367 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
368 fprintf (outfile
, " {%s}", name
);
373 /* Print NOTE_INSN names rather than integer codes. */
376 if (XINT (in_rtx
, i
) >= (int) NOTE_INSN_BIAS
377 && XINT (in_rtx
, i
) < (int) NOTE_INSN_MAX
)
378 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
380 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
385 if (XEXP (in_rtx
, i
) != NULL
)
387 rtx sub
= XEXP (in_rtx
, i
);
388 enum rtx_code subc
= GET_CODE (sub
);
390 if (GET_CODE (in_rtx
) == LABEL_REF
)
393 && NOTE_LINE_NUMBER (sub
) == NOTE_INSN_DELETED_LABEL
)
395 if (flag_dump_unnumbered
)
396 fprintf (outfile
, " [# deleted]");
398 fprintf (outfile
, " [%d deleted]", INSN_UID (sub
));
403 if (subc
!= CODE_LABEL
)
407 if (flag_dump_unnumbered
)
408 fputs (" #", outfile
);
410 fprintf (outfile
, " %d", INSN_UID (sub
));
413 fputs (" 0", outfile
);
418 if (XBITMAP (in_rtx
, i
) == NULL
)
419 fputs (" {null}", outfile
);
421 bitmap_print (outfile
, XBITMAP (in_rtx
, i
), " {", "}");
427 fprintf (outfile
, HOST_PTR_PRINTF
, (char *) XTREE (in_rtx
, i
));
431 fputs (" Unknown", outfile
);
437 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
442 switch (GET_CODE (in_rtx
))
445 fputc (' ', outfile
);
446 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, MEM_ALIAS_SET (in_rtx
));
449 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
451 if (FLOAT_MODE_P (GET_MODE (in_rtx
)))
454 REAL_VALUE_FROM_CONST_DOUBLE (val
, in_rtx
);
455 fprintf (outfile
, " [%.16g]", val
);
461 fprintf (outfile
, " [%d uses]", LABEL_NUSES (in_rtx
));
462 if (LABEL_ALTERNATE_NAME (in_rtx
))
463 fprintf (outfile
, " [alternate name: %s]",
464 LABEL_ALTERNATE_NAME (in_rtx
));
467 case CALL_PLACEHOLDER
:
468 if (debug_call_placeholder_verbose
)
470 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile
);
471 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
473 fputs ("\n ", outfile
);
474 print_inline_rtx (outfile
, tem
, 4);
477 tem
= XEXP (in_rtx
, 1);
479 fputs ("\n ])\n (const_string \"tail_call\") (sequence [", outfile
);
480 for (; tem
!= 0; tem
= NEXT_INSN (tem
))
482 fputs ("\n ", outfile
);
483 print_inline_rtx (outfile
, tem
, 4);
486 tem
= XEXP (in_rtx
, 2);
488 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [", outfile
);
489 for (; tem
!= 0; tem
= NEXT_INSN (tem
))
491 fputs ("\n ", outfile
);
492 print_inline_rtx (outfile
, tem
, 4);
495 fputs ("\n ])\n ])", outfile
);
499 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
500 if (GET_CODE (tem
) == CALL_INSN
)
502 fprintf (outfile
, " ");
513 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
514 || GET_CODE (in_rtx
) == CODE_LABEL
|| GET_CODE (in_rtx
) == BARRIER
))
518 fputc (')', outfile
);
523 /* Print an rtx on the current line of FILE. Initially indent IND
527 print_inline_rtx (outf
, x
, ind
)
532 int oldsaw
= sawclose
;
533 int oldindent
= indent
;
543 /* Call this function from the debugger to see what X looks like. */
551 fprintf (stderr
, "\n");
554 /* Count of rtx's to print with debug_rtx_list.
555 This global exists because gdb user defined commands have no arguments. */
557 int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
559 /* Call this function to print list from X on.
561 N is a count of the rtx's to print. Positive values print from the specified
562 rtx on. Negative values print a window around the rtx.
563 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
566 debug_rtx_list (x
, n
)
573 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
575 /* If we are printing a window, back up to the start. */
578 for (i
= count
/ 2; i
> 0; i
--)
580 if (PREV_INSN (x
) == 0)
585 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
589 /* Call this function to print an rtx list from START to END inclusive. */
592 debug_rtx_range (start
, end
)
598 if (!start
|| start
== end
)
600 start
= NEXT_INSN (start
);
604 /* Call this function to search an rtx list to find one with insn uid UID,
605 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
606 The found insn is returned to enable further debugging analysis. */
609 debug_rtx_find (x
, uid
)
613 while (x
!= 0 && INSN_UID (x
) != uid
)
617 debug_rtx_list (x
, debug_rtx_count
);
622 fprintf (stderr
, "insn uid %d not found\n", uid
);
627 /* External entry point for printing a chain of insns
628 starting with RTX_FIRST onto file OUTF.
629 A blank line separates insns.
631 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
634 print_rtl (outf
, rtx_first
)
638 register rtx tmp_rtx
;
645 fputs (print_rtx_head
, outf
);
646 fputs ("(nil)\n", outf
);
649 switch (GET_CODE (rtx_first
))
657 for (tmp_rtx
= rtx_first
; tmp_rtx
!= 0; tmp_rtx
= NEXT_INSN (tmp_rtx
))
658 if (! flag_dump_unnumbered
659 || GET_CODE (tmp_rtx
) != NOTE
|| NOTE_LINE_NUMBER (tmp_rtx
) < 0)
661 fputs (print_rtx_head
, outfile
);
663 fprintf (outfile
, "\n");
668 fputs (print_rtx_head
, outfile
);
669 print_rtx (rtx_first
);
673 /* Like print_rtx, except specify a file. */
674 /* Return nonzero if we actually printed anything. */
677 print_rtl_single (outf
, x
)
683 if (! flag_dump_unnumbered
684 || GET_CODE (x
) != NOTE
|| NOTE_LINE_NUMBER (x
) < 0)
686 fputs (print_rtx_head
, outfile
);
695 /* Like print_rtl except without all the detail; for example,
696 if RTX is a CONST_INT then print in decimal format. */
699 print_simple_rtl (outf
, x
)