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 int sawclose
= 0;
54 static void print_rtx
PARAMS ((rtx
));
56 /* String printed at beginning of each RTL when it is dumped.
57 This string is set to ASM_COMMENT_START when the RTL is dumped in
58 the assembly output file. */
59 const char *print_rtx_head
= "";
61 /* Nonzero means suppress output of instruction numbers and line number
62 notes in debugging dumps.
63 This must be defined here so that programs like gencodes can be linked. */
64 int flag_dump_unnumbered
= 0;
66 /* Nonzero means use simplified format without flags, modes, etc. */
69 /* Nonzero if we are dumping graphical description. */
72 /* Nonzero to dump all call_placeholder alternatives. */
73 static int debug_call_placeholder_verbose
;
75 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
83 register const char *format_ptr
;
92 fprintf (outfile
, "\n%s%*s",
93 print_rtx_head
, indent
* 2, "");
99 fputs ("(nil)", outfile
);
104 is_insn
= (INSN_P (in_rtx
));
106 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
107 in separate nodes and therefore have to handle them special here. */
108 if (dump_for_graph
&&
109 (is_insn
|| GET_CODE (in_rtx
) == NOTE
|| GET_CODE (in_rtx
) == CODE_LABEL
110 || GET_CODE (in_rtx
) == BARRIER
))
117 /* print name of expression code */
118 if (flag_simple
&& GET_CODE (in_rtx
) == CONST_INT
)
119 fputc ('(', outfile
);
121 fprintf (outfile
, "(%s", GET_RTX_NAME (GET_CODE (in_rtx
)));
125 if (in_rtx
->in_struct
)
126 fputs ("/s", outfile
);
129 fputs ("/v", outfile
);
131 if (in_rtx
->unchanging
)
132 fputs ("/u", outfile
);
134 if (in_rtx
->integrated
)
135 fputs ("/i", outfile
);
137 if (in_rtx
->frame_related
)
138 fputs ("/f", outfile
);
141 fputs ("/j", outfile
);
144 fputs ("/c", outfile
);
146 if (GET_MODE (in_rtx
) != VOIDmode
)
148 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
149 if (GET_CODE (in_rtx
) == EXPR_LIST
150 || GET_CODE (in_rtx
) == INSN_LIST
)
151 fprintf (outfile
, ":%s",
152 GET_REG_NOTE_NAME (GET_MODE (in_rtx
)));
154 fprintf (outfile
, ":%s", GET_MODE_NAME (GET_MODE (in_rtx
)));
159 /* Get the format string and skip the first elements if we have handled
161 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
)) + i
;
163 for (; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
164 switch (*format_ptr
++)
168 if (XSTR (in_rtx
, i
) == 0)
169 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
173 fprintf (outfile
, " (\\\"%s\\\")", XSTR (in_rtx
, i
));
175 fprintf (outfile
, " (\"%s\")", XSTR (in_rtx
, i
));
180 /* 0 indicates a field for internal use that should not be printed.
181 An exception is the third field of a NOTE, where it indicates
182 that the field has several different valid contents. */
184 if (i
== 1 && GET_CODE (in_rtx
) == REG
)
186 if (REGNO (in_rtx
) != ORIGINAL_REGNO (in_rtx
))
187 fprintf (outfile
, " [%d]", ORIGINAL_REGNO (in_rtx
));
190 if (i
== 3 && GET_CODE (in_rtx
) == NOTE
)
192 switch (NOTE_LINE_NUMBER (in_rtx
))
194 case NOTE_INSN_EH_REGION_BEG
:
195 case NOTE_INSN_EH_REGION_END
:
196 if (flag_dump_unnumbered
)
197 fprintf (outfile
, " #");
199 fprintf (outfile
, " %d", NOTE_EH_HANDLER (in_rtx
));
203 case NOTE_INSN_BLOCK_BEG
:
204 case NOTE_INSN_BLOCK_END
:
205 fprintf (outfile
, " ");
206 if (flag_dump_unnumbered
)
207 fprintf (outfile
, "#");
209 fprintf (outfile
, HOST_PTR_PRINTF
,
210 (char *) NOTE_BLOCK (in_rtx
));
214 case NOTE_INSN_RANGE_BEG
:
215 case NOTE_INSN_RANGE_END
:
219 fprintf (outfile
, " ");
220 print_rtx (NOTE_RANGE_INFO (in_rtx
));
224 case NOTE_INSN_BASIC_BLOCK
:
226 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
228 fprintf (outfile
, " [bb %d]", bb
->index
);
232 case NOTE_INSN_EXPECTED_VALUE
:
235 fprintf (outfile
, " ");
236 print_rtx (NOTE_EXPECTED_VALUE (in_rtx
));
240 case NOTE_INSN_DELETED_LABEL
:
241 if (NOTE_SOURCE_FILE (in_rtx
))
242 fprintf (outfile
, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx
));
244 fprintf (outfile
, " \"\"");
249 const char * const str
= X0STR (in_rtx
, i
);
251 if (NOTE_LINE_NUMBER (in_rtx
) < 0)
254 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
258 fprintf (outfile
, " (\\\"%s\\\")", str
);
260 fprintf (outfile
, " (\"%s\")", str
);
272 fprintf (outfile
, " ");
273 print_rtx (XEXP (in_rtx
, i
));
282 fprintf (outfile
, "\n%s%*s",
283 print_rtx_head
, indent
* 2, "");
286 fputs ("[ ", outfile
);
287 if (NULL
!= XVEC (in_rtx
, i
))
290 if (XVECLEN (in_rtx
, i
))
293 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
294 print_rtx (XVECEXP (in_rtx
, i
, j
));
299 fprintf (outfile
, "\n%s%*s",
300 print_rtx_head
, indent
* 2, "");
302 fputs ("] ", outfile
);
309 fprintf (outfile
, " ");
310 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, XWINT (in_rtx
, i
));
313 fprintf (outfile
, " [");
314 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
, XWINT (in_rtx
, i
));
315 fprintf (outfile
, "]");
321 register int value
= XINT (in_rtx
, i
);
324 if (GET_CODE (in_rtx
) == REG
&& value
< FIRST_PSEUDO_REGISTER
)
326 fputc (' ', outfile
);
327 DEBUG_PRINT_REG (in_rtx
, 0, outfile
);
329 else if (GET_CODE (in_rtx
) == REG
&& value
<= LAST_VIRTUAL_REGISTER
)
331 if (value
== VIRTUAL_INCOMING_ARGS_REGNUM
)
332 fprintf (outfile
, " %d virtual-incoming-args", value
);
333 else if (value
== VIRTUAL_STACK_VARS_REGNUM
)
334 fprintf (outfile
, " %d virtual-stack-vars", value
);
335 else if (value
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
336 fprintf (outfile
, " %d virtual-stack-dynamic", value
);
337 else if (value
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
338 fprintf (outfile
, " %d virtual-outgoing-args", value
);
339 else if (value
== VIRTUAL_CFA_REGNUM
)
340 fprintf (outfile
, " %d virtual-cfa", value
);
342 fprintf (outfile
, " %d virtual-reg-%d", value
,
343 value
-FIRST_VIRTUAL_REGISTER
);
345 else if (flag_dump_unnumbered
346 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
))
347 fputc ('#', outfile
);
349 fprintf (outfile
, " %d", value
);
351 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
352 && XINT (in_rtx
, i
) >= 0
353 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
354 fprintf (outfile
, " {%s}", name
);
359 /* Print NOTE_INSN names rather than integer codes. */
362 if (XINT (in_rtx
, i
) >= (int) NOTE_INSN_BIAS
363 && XINT (in_rtx
, i
) < (int) NOTE_INSN_MAX
)
364 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
366 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
371 if (XEXP (in_rtx
, i
) != NULL
)
373 rtx sub
= XEXP (in_rtx
, i
);
374 enum rtx_code subc
= GET_CODE (sub
);
376 if (GET_CODE (in_rtx
) == LABEL_REF
)
379 && NOTE_LINE_NUMBER (sub
) == NOTE_INSN_DELETED_LABEL
)
381 if (flag_dump_unnumbered
)
382 fprintf (outfile
, " [# deleted]");
384 fprintf (outfile
, " [%d deleted]", INSN_UID (sub
));
389 if (subc
!= CODE_LABEL
)
393 if (flag_dump_unnumbered
)
394 fputs (" #", outfile
);
396 fprintf (outfile
, " %d", INSN_UID (sub
));
399 fputs (" 0", outfile
);
404 if (XBITMAP (in_rtx
, i
) == NULL
)
405 fputs (" {null}", outfile
);
407 bitmap_print (outfile
, XBITMAP (in_rtx
, i
), " {", "}");
413 fprintf (outfile
, HOST_PTR_PRINTF
, (char *) XTREE (in_rtx
, i
));
417 fputs (" Unknown", outfile
);
423 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
428 switch (GET_CODE (in_rtx
))
431 fputc (' ', outfile
);
432 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, MEM_ALIAS_SET (in_rtx
));
435 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
437 if (FLOAT_MODE_P (GET_MODE (in_rtx
)))
440 REAL_VALUE_FROM_CONST_DOUBLE (val
, in_rtx
);
441 fprintf (outfile
, " [%.16g]", val
);
447 fprintf (outfile
, " [%d uses]", LABEL_NUSES (in_rtx
));
448 if (LABEL_ALTERNATE_NAME (in_rtx
))
449 fprintf (outfile
, " [alternate name: %s]",
450 LABEL_ALTERNATE_NAME (in_rtx
));
453 case CALL_PLACEHOLDER
:
454 if (debug_call_placeholder_verbose
)
456 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile
);
457 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
459 fputs ("\n ", outfile
);
460 print_inline_rtx (outfile
, tem
, 4);
463 tem
= XEXP (in_rtx
, 1);
465 fputs ("\n ])\n (const_string \"tail_call\") (sequence [", outfile
);
466 for (; tem
!= 0; tem
= NEXT_INSN (tem
))
468 fputs ("\n ", outfile
);
469 print_inline_rtx (outfile
, tem
, 4);
472 tem
= XEXP (in_rtx
, 2);
474 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [", outfile
);
475 for (; tem
!= 0; tem
= NEXT_INSN (tem
))
477 fputs ("\n ", outfile
);
478 print_inline_rtx (outfile
, tem
, 4);
481 fputs ("\n ])\n ])", outfile
);
485 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
486 if (GET_CODE (tem
) == CALL_INSN
)
488 fprintf (outfile
, " ");
499 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
500 || GET_CODE (in_rtx
) == CODE_LABEL
|| GET_CODE (in_rtx
) == BARRIER
))
504 fputc (')', outfile
);
509 /* Print an rtx on the current line of FILE. Initially indent IND
513 print_inline_rtx (outf
, x
, ind
)
518 int oldsaw
= sawclose
;
519 int oldindent
= indent
;
529 /* Call this function from the debugger to see what X looks like. */
537 fprintf (stderr
, "\n");
540 /* Count of rtx's to print with debug_rtx_list.
541 This global exists because gdb user defined commands have no arguments. */
543 int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
545 /* Call this function to print list from X on.
547 N is a count of the rtx's to print. Positive values print from the specified
548 rtx on. Negative values print a window around the rtx.
549 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
552 debug_rtx_list (x
, n
)
559 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
561 /* If we are printing a window, back up to the start. */
564 for (i
= count
/ 2; i
> 0; i
--)
566 if (PREV_INSN (x
) == 0)
571 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
575 /* Call this function to print an rtx list from START to END inclusive. */
578 debug_rtx_range (start
, end
)
584 if (!start
|| start
== end
)
586 start
= NEXT_INSN (start
);
590 /* Call this function to search an rtx list to find one with insn uid UID,
591 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
592 The found insn is returned to enable further debugging analysis. */
595 debug_rtx_find (x
, uid
)
599 while (x
!= 0 && INSN_UID (x
) != uid
)
603 debug_rtx_list (x
, debug_rtx_count
);
608 fprintf (stderr
, "insn uid %d not found\n", uid
);
613 /* External entry point for printing a chain of insns
614 starting with RTX_FIRST onto file OUTF.
615 A blank line separates insns.
617 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
620 print_rtl (outf
, rtx_first
)
624 register rtx tmp_rtx
;
631 fputs (print_rtx_head
, outf
);
632 fputs ("(nil)\n", outf
);
635 switch (GET_CODE (rtx_first
))
643 for (tmp_rtx
= rtx_first
; tmp_rtx
!= 0; tmp_rtx
= NEXT_INSN (tmp_rtx
))
644 if (! flag_dump_unnumbered
645 || GET_CODE (tmp_rtx
) != NOTE
|| NOTE_LINE_NUMBER (tmp_rtx
) < 0)
647 fputs (print_rtx_head
, outfile
);
649 fprintf (outfile
, "\n");
654 fputs (print_rtx_head
, outfile
);
655 print_rtx (rtx_first
);
659 /* Like print_rtx, except specify a file. */
660 /* Return nonzero if we actually printed anything. */
663 print_rtl_single (outf
, x
)
669 if (! flag_dump_unnumbered
670 || GET_CODE (x
) != NOTE
|| NOTE_LINE_NUMBER (x
) < 0)
672 fputs (print_rtx_head
, outfile
);
681 /* Like print_rtl except without all the detail; for example,
682 if RTX is a CONST_INT then print in decimal format. */
685 print_simple_rtl (outf
, x
)