1 /* Print RTL for GNU C Compiler.
2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999
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 "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 reg_names
[] = DEBUG_REGISTER_NAMES
;
44 static const char * const reg_names
[] = REGISTER_NAMES
;
49 static const char xspaces
[] = " ";
51 static int sawclose
= 0;
55 /* Names for patterns. */
57 extern const char *get_insn_name
PROTO ((int));
59 static void print_rtx
PROTO ((rtx
));
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 if we are dumping graphical description. */
69 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
77 register const char *format_ptr
;
82 fprintf (outfile
, "\n%s",
83 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
89 fputs ("(nil)", outfile
);
94 is_insn
= (GET_RTX_CLASS (GET_CODE (in_rtx
)) == 'i');
96 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
97 in separate nodes and therefore have to handle them special here. */
99 (is_insn
|| GET_CODE (in_rtx
) == NOTE
|| GET_CODE (in_rtx
) == CODE_LABEL
100 || GET_CODE (in_rtx
) == BARRIER
))
107 /* print name of expression code */
108 fprintf (outfile
, "(%s", GET_RTX_NAME (GET_CODE (in_rtx
)));
110 if (in_rtx
->in_struct
)
111 fputs ("/s", outfile
);
114 fputs ("/v", outfile
);
116 if (in_rtx
->unchanging
)
117 fputs ("/u", outfile
);
119 if (in_rtx
->integrated
)
120 fputs ("/i", outfile
);
122 if (in_rtx
->frame_related
)
123 fputs ("/f", outfile
);
126 fputs ("/j", outfile
);
129 fputs ("/c", outfile
);
131 if (GET_MODE (in_rtx
) != VOIDmode
)
133 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
134 if (GET_CODE (in_rtx
) == EXPR_LIST
|| GET_CODE (in_rtx
) == INSN_LIST
)
135 fprintf (outfile
, ":%s", GET_REG_NOTE_NAME (GET_MODE (in_rtx
)));
137 fprintf (outfile
, ":%s", GET_MODE_NAME (GET_MODE (in_rtx
)));
141 /* Get the format string and skip the first elements if we have handled
143 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
)) + i
;
145 for (; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
146 switch (*format_ptr
++)
150 if (XSTR (in_rtx
, i
) == 0)
151 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
153 fprintf (outfile
, dump_for_graph
? " (\\\"%s\\\")" : " (\"%s\")",
158 /* 0 indicates a field for internal use that should not be printed.
159 An exception is the third field of a NOTE, where it indicates
160 that the field has several different valid contents. */
162 if (i
== 3 && GET_CODE (in_rtx
) == NOTE
)
164 if (NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_EH_REGION_BEG
165 || NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_EH_REGION_END
166 || NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_BLOCK_BEG
167 || NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_BLOCK_END
)
169 fprintf (outfile
, " %d", NOTE_BLOCK_NUMBER (in_rtx
));
172 else if (NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_RANGE_START
173 || NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_RANGE_END
174 || NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_LIVE
)
178 fprintf (outfile
, " ");
179 print_rtx (NOTE_RANGE_INFO (in_rtx
));
182 else if (NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_BASIC_BLOCK
)
184 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
185 fprintf (outfile
, " [bb %d]", bb
->index
);
189 char *str
= X0STR (in_rtx
, i
);
191 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
194 dump_for_graph
? " (\\\"%s\\\")" : " (\"%s\")",
203 fprintf (outfile
, " ");
204 print_rtx (XEXP (in_rtx
, i
));
213 fprintf (outfile
, "\n%s",
214 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
217 fputs ("[ ", outfile
);
218 if (NULL
!= XVEC (in_rtx
, i
))
221 if (XVECLEN (in_rtx
, i
))
224 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
225 print_rtx (XVECEXP (in_rtx
, i
, j
));
230 fprintf (outfile
, "\n%s",
231 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
233 fputs ("] ", outfile
);
239 fprintf (outfile
, " ");
240 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, XWINT (in_rtx
, i
));
241 fprintf (outfile
, " [");
242 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
, XWINT (in_rtx
, i
));
243 fprintf (outfile
, "]");
248 register int value
= XINT (in_rtx
, i
);
251 if (GET_CODE (in_rtx
) == REG
&& value
< FIRST_PSEUDO_REGISTER
)
253 fputc (' ', outfile
);
254 DEBUG_PRINT_REG (in_rtx
, 0, outfile
);
256 else if (GET_CODE (in_rtx
) == REG
&& value
<= LAST_VIRTUAL_REGISTER
)
258 if (value
== VIRTUAL_INCOMING_ARGS_REGNUM
)
259 fprintf (outfile
, " %d virtual-incoming-args", value
);
260 else if (value
== VIRTUAL_STACK_VARS_REGNUM
)
261 fprintf (outfile
, " %d virtual-stack-vars", value
);
262 else if (value
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
263 fprintf (outfile
, " %d virtual-stack-dynamic", value
);
264 else if (value
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
265 fprintf (outfile
, " %d virtual-outgoing-args", value
);
266 else if (value
== VIRTUAL_CFA_REGNUM
)
267 fprintf (outfile
, " %d virtual-cfa", value
);
269 fprintf (outfile
, " %d virtual-reg-%d", value
,
270 value
-FIRST_VIRTUAL_REGISTER
);
272 else if (flag_dump_unnumbered
273 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
))
274 fputc ('#', outfile
);
276 fprintf (outfile
, " %d", value
);
278 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
279 && XINT (in_rtx
, i
) >= 0
280 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
281 fprintf (outfile
, " {%s}", name
);
286 /* Print NOTE_INSN names rather than integer codes. */
289 if (XINT (in_rtx
, i
) <= 0)
290 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
292 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
297 if (XEXP (in_rtx
, i
) != NULL
)
299 if (flag_dump_unnumbered
)
300 fputc ('#', outfile
);
302 fprintf (outfile
, " %d", INSN_UID (XEXP (in_rtx
, i
)));
305 fputs (" 0", outfile
);
310 if (XBITMAP (in_rtx
, i
) == NULL
)
311 fputs (" {null}", outfile
);
313 bitmap_print (outfile
, XBITMAP (in_rtx
, i
), " {", "}");
319 fprintf (outfile
, HOST_PTR_PRINTF
, (char *) XTREE (in_rtx
, i
));
323 fputs (" Unknown", outfile
);
329 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
334 if (GET_CODE (in_rtx
) == MEM
)
335 fprintf (outfile
, " %d", MEM_ALIAS_SET (in_rtx
));
337 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && LONG_DOUBLE_TYPE_SIZE == 64
338 if (GET_CODE (in_rtx
) == CONST_DOUBLE
&& FLOAT_MODE_P (GET_MODE (in_rtx
)))
341 REAL_VALUE_FROM_CONST_DOUBLE (val
, in_rtx
);
342 fprintf (outfile
, " [%.16g]", val
);
346 if (GET_CODE (in_rtx
) == CODE_LABEL
)
347 fprintf (outfile
, " [num uses: %d]", LABEL_NUSES (in_rtx
));
350 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
351 || GET_CODE (in_rtx
) == CODE_LABEL
|| GET_CODE (in_rtx
) == BARRIER
))
355 fputc (')', outfile
);
360 /* Print an rtx on the current line of FILE. Initially indent IND
364 print_inline_rtx (outf
, x
, ind
)
369 int oldsaw
= sawclose
;
370 int oldindent
= indent
;
380 /* Call this function from the debugger to see what X looks like. */
388 fprintf (stderr
, "\n");
391 /* Count of rtx's to print with debug_rtx_list.
392 This global exists because gdb user defined commands have no arguments. */
394 int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
396 /* Call this function to print list from X on.
398 N is a count of the rtx's to print. Positive values print from the specified
399 rtx on. Negative values print a window around the rtx.
400 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
403 debug_rtx_list (x
, n
)
410 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
412 /* If we are printing a window, back up to the start. */
415 for (i
= count
/ 2; i
> 0; i
--)
417 if (PREV_INSN (x
) == 0)
422 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
426 /* Call this function to search an rtx list to find one with insn uid UID,
427 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
428 The found insn is returned to enable further debugging analysis. */
431 debug_rtx_find (x
, uid
)
435 while (x
!= 0 && INSN_UID (x
) != uid
)
439 debug_rtx_list (x
, debug_rtx_count
);
444 fprintf (stderr
, "insn uid %d not found\n", uid
);
449 /* External entry point for printing a chain of insns
450 starting with RTX_FIRST onto file OUTF.
451 A blank line separates insns.
453 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
456 print_rtl (outf
, rtx_first
)
460 register rtx tmp_rtx
;
466 fputs ("(nil)\n", outf
);
468 switch (GET_CODE (rtx_first
))
476 for (tmp_rtx
= rtx_first
; NULL
!= tmp_rtx
; tmp_rtx
= NEXT_INSN (tmp_rtx
))
478 if (! flag_dump_unnumbered
479 || GET_CODE (tmp_rtx
) != NOTE
480 || NOTE_LINE_NUMBER (tmp_rtx
) < 0)
483 fprintf (outfile
, "\n");
489 print_rtx (rtx_first
);
493 /* Like print_rtx, except specify a file. */
494 /* Return nonzero if we actually printed anything. */
497 print_rtl_single (outf
, x
)
503 if (! flag_dump_unnumbered
504 || GET_CODE (x
) != NOTE
|| NOTE_LINE_NUMBER (x
) < 0)