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 "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 static void print_rtx
PARAMS ((rtx
));
57 /* Nonzero means suppress output of instruction numbers and line number
58 notes in debugging dumps.
59 This must be defined here so that programs like gencodes can be linked. */
60 int flag_dump_unnumbered
= 0;
62 /* Nonzero if we are dumping graphical description. */
65 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
73 register const char *format_ptr
;
79 fprintf (outfile
, "\n%s",
80 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
86 fputs ("(nil)", outfile
);
91 is_insn
= (GET_RTX_CLASS (GET_CODE (in_rtx
)) == 'i');
93 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
94 in separate nodes and therefore have to handle them special here. */
96 (is_insn
|| GET_CODE (in_rtx
) == NOTE
|| GET_CODE (in_rtx
) == CODE_LABEL
97 || GET_CODE (in_rtx
) == BARRIER
))
104 /* print name of expression code */
105 fprintf (outfile
, "(%s", GET_RTX_NAME (GET_CODE (in_rtx
)));
107 if (in_rtx
->in_struct
)
108 fputs ("/s", outfile
);
111 fputs ("/v", outfile
);
113 if (in_rtx
->unchanging
)
114 fputs ("/u", outfile
);
116 if (in_rtx
->integrated
)
117 fputs ("/i", outfile
);
119 if (in_rtx
->frame_related
)
120 fputs ("/f", outfile
);
123 fputs ("/j", outfile
);
126 fputs ("/c", outfile
);
128 if (GET_MODE (in_rtx
) != VOIDmode
)
130 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
131 if (GET_CODE (in_rtx
) == EXPR_LIST
|| GET_CODE (in_rtx
) == INSN_LIST
)
132 fprintf (outfile
, ":%s", GET_REG_NOTE_NAME (GET_MODE (in_rtx
)));
134 fprintf (outfile
, ":%s", GET_MODE_NAME (GET_MODE (in_rtx
)));
138 /* Get the format string and skip the first elements if we have handled
140 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
)) + i
;
142 for (; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
143 switch (*format_ptr
++)
147 if (XSTR (in_rtx
, i
) == 0)
148 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
152 fprintf (outfile
, " (\\\"%s\\\")", XSTR (in_rtx
, i
));
154 fprintf (outfile
, " (\"%s\")", XSTR (in_rtx
, i
));
159 /* 0 indicates a field for internal use that should not be printed.
160 An exception is the third field of a NOTE, where it indicates
161 that the field has several different valid contents. */
163 if (i
== 3 && GET_CODE (in_rtx
) == NOTE
)
165 switch (NOTE_LINE_NUMBER (in_rtx
))
167 case NOTE_INSN_EH_REGION_BEG
:
168 case NOTE_INSN_EH_REGION_END
:
169 if (flag_dump_unnumbered
)
170 fprintf (outfile
, " #");
172 fprintf (outfile
, " %d", NOTE_EH_HANDLER (in_rtx
));
176 case NOTE_INSN_BLOCK_BEG
:
177 case NOTE_INSN_BLOCK_END
:
178 fprintf (outfile
, " ");
179 if (flag_dump_unnumbered
)
180 fprintf (outfile
, "#");
182 fprintf (outfile
, HOST_PTR_PRINTF
,
183 (char *) NOTE_BLOCK (in_rtx
));
187 case NOTE_INSN_RANGE_BEG
:
188 case NOTE_INSN_RANGE_END
:
192 fprintf (outfile
, " ");
193 print_rtx (NOTE_RANGE_INFO (in_rtx
));
197 case NOTE_INSN_BASIC_BLOCK
:
199 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
201 fprintf (outfile
, " [bb %d]", bb
->index
);
205 case NOTE_INSN_EXPECTED_VALUE
:
208 fprintf (outfile
, " ");
209 print_rtx (NOTE_EXPECTED_VALUE (in_rtx
));
213 case NOTE_INSN_DELETED_LABEL
:
214 if (NOTE_SOURCE_FILE (in_rtx
))
215 fprintf (outfile
, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx
));
217 fprintf (outfile
, " \"\"");
222 const char * const str
= X0STR (in_rtx
, i
);
224 if (NOTE_LINE_NUMBER (in_rtx
) < 0)
227 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
231 fprintf (outfile
, " (\\\"%s\\\")", str
);
233 fprintf (outfile
, " (\"%s\")", str
);
245 fprintf (outfile
, " ");
246 print_rtx (XEXP (in_rtx
, i
));
255 fprintf (outfile
, "\n%s",
256 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
259 fputs ("[ ", outfile
);
260 if (NULL
!= XVEC (in_rtx
, i
))
263 if (XVECLEN (in_rtx
, i
))
266 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
267 print_rtx (XVECEXP (in_rtx
, i
, j
));
272 fprintf (outfile
, "\n%s",
273 (xspaces
+ (sizeof xspaces
- 1 - indent
* 2)));
275 fputs ("] ", outfile
);
281 fprintf (outfile
, " ");
282 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, XWINT (in_rtx
, i
));
283 fprintf (outfile
, " [");
284 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
, XWINT (in_rtx
, i
));
285 fprintf (outfile
, "]");
290 register int value
= XINT (in_rtx
, i
);
293 if (GET_CODE (in_rtx
) == REG
&& value
< FIRST_PSEUDO_REGISTER
)
295 fputc (' ', outfile
);
296 DEBUG_PRINT_REG (in_rtx
, 0, outfile
);
298 else if (GET_CODE (in_rtx
) == REG
&& value
<= LAST_VIRTUAL_REGISTER
)
300 if (value
== VIRTUAL_INCOMING_ARGS_REGNUM
)
301 fprintf (outfile
, " %d virtual-incoming-args", value
);
302 else if (value
== VIRTUAL_STACK_VARS_REGNUM
)
303 fprintf (outfile
, " %d virtual-stack-vars", value
);
304 else if (value
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
305 fprintf (outfile
, " %d virtual-stack-dynamic", value
);
306 else if (value
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
307 fprintf (outfile
, " %d virtual-outgoing-args", value
);
308 else if (value
== VIRTUAL_CFA_REGNUM
)
309 fprintf (outfile
, " %d virtual-cfa", value
);
311 fprintf (outfile
, " %d virtual-reg-%d", value
,
312 value
-FIRST_VIRTUAL_REGISTER
);
314 else if (flag_dump_unnumbered
315 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
))
316 fputc ('#', outfile
);
318 fprintf (outfile
, " %d", value
);
320 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
321 && XINT (in_rtx
, i
) >= 0
322 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
323 fprintf (outfile
, " {%s}", name
);
328 /* Print NOTE_INSN names rather than integer codes. */
331 if (XINT (in_rtx
, i
) <= 0)
332 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
334 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
339 if (XEXP (in_rtx
, i
) != NULL
)
341 rtx sub
= XEXP (in_rtx
, i
);
342 enum rtx_code subc
= GET_CODE (sub
);
344 if (GET_CODE (in_rtx
) == LABEL_REF
)
347 && NOTE_LINE_NUMBER (sub
) == NOTE_INSN_DELETED_LABEL
)
349 if (flag_dump_unnumbered
)
350 fprintf (outfile
, " [# deleted]");
352 fprintf (outfile
, " [%d deleted]", INSN_UID (sub
));
357 if (subc
!= CODE_LABEL
)
361 if (flag_dump_unnumbered
)
362 fputs (" #", outfile
);
364 fprintf (outfile
, " %d", INSN_UID (sub
));
367 fputs (" 0", outfile
);
372 if (XBITMAP (in_rtx
, i
) == NULL
)
373 fputs (" {null}", outfile
);
375 bitmap_print (outfile
, XBITMAP (in_rtx
, i
), " {", "}");
381 fprintf (outfile
, HOST_PTR_PRINTF
, (char *) XTREE (in_rtx
, i
));
385 fputs (" Unknown", outfile
);
391 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
396 switch (GET_CODE (in_rtx
))
399 fprintf (outfile
, " %d", MEM_ALIAS_SET (in_rtx
));
402 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
404 if (FLOAT_MODE_P (GET_MODE (in_rtx
)))
407 REAL_VALUE_FROM_CONST_DOUBLE (val
, in_rtx
);
408 fprintf (outfile
, " [%.16g]", val
);
414 fprintf (outfile
, " [%d uses]", LABEL_NUSES (in_rtx
));
415 if (LABEL_ALTERNATE_NAME (in_rtx
))
416 fprintf (outfile
, " [alternate name: %s]",
417 LABEL_ALTERNATE_NAME (in_rtx
));
420 case CALL_PLACEHOLDER
:
421 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
422 if (GET_CODE (tem
) == CALL_INSN
)
424 fprintf (outfile
, " ");
435 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
436 || GET_CODE (in_rtx
) == CODE_LABEL
|| GET_CODE (in_rtx
) == BARRIER
))
440 fputc (')', outfile
);
445 /* Print an rtx on the current line of FILE. Initially indent IND
449 print_inline_rtx (outf
, x
, ind
)
454 int oldsaw
= sawclose
;
455 int oldindent
= indent
;
465 /* Call this function from the debugger to see what X looks like. */
473 fprintf (stderr
, "\n");
476 /* Count of rtx's to print with debug_rtx_list.
477 This global exists because gdb user defined commands have no arguments. */
479 int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
481 /* Call this function to print list from X on.
483 N is a count of the rtx's to print. Positive values print from the specified
484 rtx on. Negative values print a window around the rtx.
485 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
488 debug_rtx_list (x
, n
)
495 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
497 /* If we are printing a window, back up to the start. */
500 for (i
= count
/ 2; i
> 0; i
--)
502 if (PREV_INSN (x
) == 0)
507 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
511 /* Call this function to print an rtx list from START to END inclusive. */
514 debug_rtx_range (start
, end
)
520 if (!start
|| start
== end
)
522 start
= NEXT_INSN (start
);
526 /* Call this function to search an rtx list to find one with insn uid UID,
527 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
528 The found insn is returned to enable further debugging analysis. */
531 debug_rtx_find (x
, uid
)
535 while (x
!= 0 && INSN_UID (x
) != uid
)
539 debug_rtx_list (x
, debug_rtx_count
);
544 fprintf (stderr
, "insn uid %d not found\n", uid
);
549 /* External entry point for printing a chain of insns
550 starting with RTX_FIRST onto file OUTF.
551 A blank line separates insns.
553 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
556 print_rtl (outf
, rtx_first
)
560 register rtx tmp_rtx
;
566 fputs ("(nil)\n", outf
);
568 switch (GET_CODE (rtx_first
))
576 for (tmp_rtx
= rtx_first
; tmp_rtx
!= 0; tmp_rtx
= NEXT_INSN (tmp_rtx
))
577 if (! flag_dump_unnumbered
578 || GET_CODE (tmp_rtx
) != NOTE
|| NOTE_LINE_NUMBER (tmp_rtx
) < 0)
581 fprintf (outfile
, "\n");
586 print_rtx (rtx_first
);
590 /* Like print_rtx, except specify a file. */
591 /* Return nonzero if we actually printed anything. */
594 print_rtl_single (outf
, x
)
600 if (! flag_dump_unnumbered
601 || GET_CODE (x
) != NOTE
|| NOTE_LINE_NUMBER (x
) < 0)