2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003, 2004
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This file is compiled twice: once for the generator programs,
23 once for the compiler. */
31 #include "coretypes.h"
35 /* These headers all define things which are not available in
36 generator programs. */
37 #ifndef GENERATOR_FILE
41 #include "hard-reg-set.h"
42 #include "basic-block.h"
47 static int sawclose
= 0;
51 static void print_rtx (rtx
);
53 /* String printed at beginning of each RTL when it is dumped.
54 This string is set to ASM_COMMENT_START when the RTL is dumped in
55 the assembly output file. */
56 const char *print_rtx_head
= "";
58 /* Nonzero means suppress output of instruction numbers and line number
59 notes in debugging dumps.
60 This must be defined here so that programs like gencodes can be linked. */
61 int flag_dump_unnumbered
= 0;
63 /* Nonzero means use simplified format without flags, modes, etc. */
66 /* Nonzero if we are dumping graphical description. */
69 #ifndef GENERATOR_FILE
71 print_mem_expr (FILE *outfile
, tree expr
)
73 if (TREE_CODE (expr
) == COMPONENT_REF
)
75 if (TREE_OPERAND (expr
, 0))
76 print_mem_expr (outfile
, TREE_OPERAND (expr
, 0));
78 fputs (" <variable>", outfile
);
79 if (DECL_NAME (TREE_OPERAND (expr
, 1)))
80 fprintf (outfile
, ".%s",
81 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (expr
, 1))));
83 else if (TREE_CODE (expr
) == INDIRECT_REF
)
85 fputs (" (*", outfile
);
86 print_mem_expr (outfile
, TREE_OPERAND (expr
, 0));
89 else if (DECL_NAME (expr
))
90 fprintf (outfile
, " %s", IDENTIFIER_POINTER (DECL_NAME (expr
)));
91 else if (TREE_CODE (expr
) == RESULT_DECL
)
92 fputs (" <result>", outfile
);
94 fputs (" <anonymous>", outfile
);
98 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
101 print_rtx (rtx in_rtx
)
105 const char *format_ptr
;
111 fputc (' ', outfile
);
113 fprintf (outfile
, "\n%s%*s", print_rtx_head
, indent
* 2, "");
119 fputs ("(nil)", outfile
);
123 else if (GET_CODE (in_rtx
) > NUM_RTX_CODE
)
125 fprintf (outfile
, "(??? bad code %d\n)", GET_CODE (in_rtx
));
130 is_insn
= INSN_P (in_rtx
);
132 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
133 in separate nodes and therefore have to handle them special here. */
135 && (is_insn
|| NOTE_P (in_rtx
)
136 || LABEL_P (in_rtx
) || BARRIER_P (in_rtx
)))
143 /* Print name of expression code. */
144 if (flag_simple
&& GET_CODE (in_rtx
) == CONST_INT
)
145 fputc ('(', outfile
);
147 fprintf (outfile
, "(%s", GET_RTX_NAME (GET_CODE (in_rtx
)));
151 if (RTX_FLAG (in_rtx
, in_struct
))
152 fputs ("/s", outfile
);
154 if (RTX_FLAG (in_rtx
, volatil
))
155 fputs ("/v", outfile
);
157 if (RTX_FLAG (in_rtx
, unchanging
))
158 fputs ("/u", outfile
);
160 if (RTX_FLAG (in_rtx
, frame_related
))
161 fputs ("/f", outfile
);
163 if (RTX_FLAG (in_rtx
, jump
))
164 fputs ("/j", outfile
);
166 if (RTX_FLAG (in_rtx
, call
))
167 fputs ("/c", outfile
);
169 if (RTX_FLAG (in_rtx
, return_val
))
170 fputs ("/i", outfile
);
172 if (GET_MODE (in_rtx
) != VOIDmode
)
174 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
175 if (GET_CODE (in_rtx
) == EXPR_LIST
176 || GET_CODE (in_rtx
) == INSN_LIST
)
177 fprintf (outfile
, ":%s",
178 GET_REG_NOTE_NAME (GET_MODE (in_rtx
)));
180 fprintf (outfile
, ":%s", GET_MODE_NAME (GET_MODE (in_rtx
)));
185 #ifndef GENERATOR_FILE
186 if (GET_CODE (in_rtx
) == CONST_DOUBLE
&& FLOAT_MODE_P (GET_MODE (in_rtx
)))
190 /* Get the format string and skip the first elements if we have handled
192 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
)) + i
;
193 for (; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
194 switch (*format_ptr
++)
199 str
= XTMPL (in_rtx
, i
);
204 str
= XSTR (in_rtx
, i
);
208 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
212 fprintf (outfile
, " (\\\"%s\\\")", str
);
214 fprintf (outfile
, " (\"%s\")", str
);
219 /* 0 indicates a field for internal use that should not be printed.
220 An exception is the third field of a NOTE, where it indicates
221 that the field has several different valid contents. */
223 if (i
== 1 && REG_P (in_rtx
))
225 if (REGNO (in_rtx
) != ORIGINAL_REGNO (in_rtx
))
226 fprintf (outfile
, " [%d]", ORIGINAL_REGNO (in_rtx
));
228 #ifndef GENERATOR_FILE
229 else if (i
== 1 && GET_CODE (in_rtx
) == SYMBOL_REF
)
231 int flags
= SYMBOL_REF_FLAGS (in_rtx
);
233 fprintf (outfile
, " [flags 0x%x]", flags
);
235 else if (i
== 2 && GET_CODE (in_rtx
) == SYMBOL_REF
)
237 tree decl
= SYMBOL_REF_DECL (in_rtx
);
239 print_node_brief (outfile
, "", decl
, 0);
242 else if (i
== 4 && NOTE_P (in_rtx
))
244 switch (NOTE_LINE_NUMBER (in_rtx
))
246 case NOTE_INSN_EH_REGION_BEG
:
247 case NOTE_INSN_EH_REGION_END
:
248 if (flag_dump_unnumbered
)
249 fprintf (outfile
, " #");
251 fprintf (outfile
, " %d", NOTE_EH_HANDLER (in_rtx
));
255 case NOTE_INSN_BLOCK_BEG
:
256 case NOTE_INSN_BLOCK_END
:
257 fprintf (outfile
, " ");
258 if (flag_dump_unnumbered
)
259 fprintf (outfile
, "#");
261 fprintf (outfile
, HOST_PTR_PRINTF
,
262 (char *) NOTE_BLOCK (in_rtx
));
266 case NOTE_INSN_BASIC_BLOCK
:
268 #ifndef GENERATOR_FILE
269 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
271 fprintf (outfile
, " [bb %d]", bb
->index
);
276 case NOTE_INSN_EXPECTED_VALUE
:
279 fprintf (outfile
, " ");
280 print_rtx (NOTE_EXPECTED_VALUE (in_rtx
));
284 case NOTE_INSN_DELETED_LABEL
:
286 const char *label
= NOTE_DELETED_LABEL_NAME (in_rtx
);
288 fprintf (outfile
, " (\"%s\")", label
);
290 fprintf (outfile
, " \"\"");
294 case NOTE_INSN_UNLIKELY_EXECUTED_CODE
:
296 #ifndef GENERATOR_FILE
297 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
299 fprintf (outfile
, " [bb %d]", bb
->index
);
304 case NOTE_INSN_VAR_LOCATION
:
305 #ifndef GENERATOR_FILE
306 fprintf (outfile
, " (");
307 print_mem_expr (outfile
, NOTE_VAR_LOCATION_DECL (in_rtx
));
308 fprintf (outfile
, " ");
309 print_rtx (NOTE_VAR_LOCATION_LOC (in_rtx
));
310 fprintf (outfile
, ")");
316 const char * const str
= X0STR (in_rtx
, i
);
318 if (NOTE_LINE_NUMBER (in_rtx
) < 0)
321 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
325 fprintf (outfile
, " (\\\"%s\\\")", str
);
327 fprintf (outfile
, " (\"%s\")", str
);
339 fprintf (outfile
, " ");
340 print_rtx (XEXP (in_rtx
, i
));
349 fprintf (outfile
, "\n%s%*s",
350 print_rtx_head
, indent
* 2, "");
353 fputs (" [", outfile
);
354 if (NULL
!= XVEC (in_rtx
, i
))
357 if (XVECLEN (in_rtx
, i
))
360 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
361 print_rtx (XVECEXP (in_rtx
, i
, j
));
366 fprintf (outfile
, "\n%s%*s", print_rtx_head
, indent
* 2, "");
368 fputs ("]", outfile
);
375 fprintf (outfile
, " ");
376 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, XWINT (in_rtx
, i
));
378 fprintf (outfile
, " [" HOST_WIDE_INT_PRINT_HEX
"]",
383 if (i
== 4 && INSN_P (in_rtx
))
385 #ifndef GENERATOR_FILE
386 /* Pretty-print insn locators. Ignore scoping as it is mostly
387 redundant with line number information and do not print anything
388 when there is no location information available. */
389 if (INSN_LOCATOR (in_rtx
) && insn_file (in_rtx
))
390 fprintf(outfile
, " %s:%i", insn_file (in_rtx
), insn_line (in_rtx
));
393 else if (i
== 6 && NOTE_P (in_rtx
))
395 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
396 other times often contains garbage from INSN->NOTE death. */
397 if (NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_DELETED_LABEL
)
398 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
402 int value
= XINT (in_rtx
, i
);
405 #ifndef GENERATOR_FILE
406 if (REG_P (in_rtx
) && value
< FIRST_PSEUDO_REGISTER
)
407 fprintf (outfile
, " %d %s", REGNO (in_rtx
),
408 reg_names
[REGNO (in_rtx
)]);
409 else if (REG_P (in_rtx
)
410 && value
<= LAST_VIRTUAL_REGISTER
)
412 if (value
== VIRTUAL_INCOMING_ARGS_REGNUM
)
413 fprintf (outfile
, " %d virtual-incoming-args", value
);
414 else if (value
== VIRTUAL_STACK_VARS_REGNUM
)
415 fprintf (outfile
, " %d virtual-stack-vars", value
);
416 else if (value
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
417 fprintf (outfile
, " %d virtual-stack-dynamic", value
);
418 else if (value
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
419 fprintf (outfile
, " %d virtual-outgoing-args", value
);
420 else if (value
== VIRTUAL_CFA_REGNUM
)
421 fprintf (outfile
, " %d virtual-cfa", value
);
423 fprintf (outfile
, " %d virtual-reg-%d", value
,
424 value
-FIRST_VIRTUAL_REGISTER
);
428 if (flag_dump_unnumbered
429 && (is_insn
|| NOTE_P (in_rtx
)))
430 fputc ('#', outfile
);
432 fprintf (outfile
, " %d", value
);
434 #ifndef GENERATOR_FILE
435 if (REG_P (in_rtx
) && REG_ATTRS (in_rtx
))
437 fputs (" [", outfile
);
438 if (ORIGINAL_REGNO (in_rtx
) != REGNO (in_rtx
))
439 fprintf (outfile
, "orig:%i", ORIGINAL_REGNO (in_rtx
));
440 if (REG_EXPR (in_rtx
))
441 print_mem_expr (outfile
, REG_EXPR (in_rtx
));
443 if (REG_OFFSET (in_rtx
))
444 fprintf (outfile
, "+" HOST_WIDE_INT_PRINT_DEC
,
445 REG_OFFSET (in_rtx
));
446 fputs (" ]", outfile
);
450 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
451 && XINT (in_rtx
, i
) >= 0
452 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
453 fprintf (outfile
, " {%s}", name
);
458 /* Print NOTE_INSN names rather than integer codes. */
461 if (XINT (in_rtx
, i
) >= (int) NOTE_INSN_BIAS
462 && XINT (in_rtx
, i
) < (int) NOTE_INSN_MAX
)
463 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
465 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
470 if (XEXP (in_rtx
, i
) != NULL
)
472 rtx sub
= XEXP (in_rtx
, i
);
473 enum rtx_code subc
= GET_CODE (sub
);
475 if (GET_CODE (in_rtx
) == LABEL_REF
)
478 && NOTE_LINE_NUMBER (sub
) == NOTE_INSN_DELETED_LABEL
)
480 if (flag_dump_unnumbered
)
481 fprintf (outfile
, " [# deleted]");
483 fprintf (outfile
, " [%d deleted]", INSN_UID (sub
));
488 if (subc
!= CODE_LABEL
)
492 if (flag_dump_unnumbered
)
493 fputs (" #", outfile
);
495 fprintf (outfile
, " %d", INSN_UID (sub
));
498 fputs (" 0", outfile
);
503 #ifndef GENERATOR_FILE
504 if (XBITMAP (in_rtx
, i
) == NULL
)
505 fputs (" {null}", outfile
);
507 bitmap_print (outfile
, XBITMAP (in_rtx
, i
), " {", "}");
513 fprintf (outfile
, " " HOST_PTR_PRINTF
, (void *) XTREE (in_rtx
, i
));
517 fputs (" Unknown", outfile
);
522 #ifndef GENERATOR_FILE
523 if (XBBDEF (in_rtx
, i
))
524 fprintf (outfile
, " %i", XBBDEF (in_rtx
, i
)->index
);
530 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
535 switch (GET_CODE (in_rtx
))
537 #ifndef GENERATOR_FILE
539 fprintf (outfile
, " [" HOST_WIDE_INT_PRINT_DEC
, MEM_ALIAS_SET (in_rtx
));
541 if (MEM_EXPR (in_rtx
))
542 print_mem_expr (outfile
, MEM_EXPR (in_rtx
));
544 if (MEM_OFFSET (in_rtx
))
545 fprintf (outfile
, "+" HOST_WIDE_INT_PRINT_DEC
,
546 INTVAL (MEM_OFFSET (in_rtx
)));
548 if (MEM_SIZE (in_rtx
))
549 fprintf (outfile
, " S" HOST_WIDE_INT_PRINT_DEC
,
550 INTVAL (MEM_SIZE (in_rtx
)));
552 if (MEM_ALIGN (in_rtx
) != 1)
553 fprintf (outfile
, " A%u", MEM_ALIGN (in_rtx
));
555 fputc (']', outfile
);
559 if (FLOAT_MODE_P (GET_MODE (in_rtx
)))
563 real_to_decimal (s
, CONST_DOUBLE_REAL_VALUE (in_rtx
),
565 fprintf (outfile
, " %s", s
);
567 real_to_hexadecimal (s
, CONST_DOUBLE_REAL_VALUE (in_rtx
),
569 fprintf (outfile
, " [%s]", s
);
575 fprintf (outfile
, " [%d uses]", LABEL_NUSES (in_rtx
));
576 switch (LABEL_KIND (in_rtx
))
578 case LABEL_NORMAL
: break;
579 case LABEL_STATIC_ENTRY
: fputs (" [entry]", outfile
); break;
580 case LABEL_GLOBAL_ENTRY
: fputs (" [global entry]", outfile
); break;
581 case LABEL_WEAK_ENTRY
: fputs (" [weak entry]", outfile
); break;
591 && (is_insn
|| NOTE_P (in_rtx
)
592 || LABEL_P (in_rtx
) || BARRIER_P (in_rtx
)))
596 fputc (')', outfile
);
601 /* Print an rtx on the current line of FILE. Initially indent IND
605 print_inline_rtx (FILE *outf
, rtx x
, int ind
)
607 int oldsaw
= sawclose
;
608 int oldindent
= indent
;
618 /* Call this function from the debugger to see what X looks like. */
626 fprintf (stderr
, "\n");
629 /* Count of rtx's to print with debug_rtx_list.
630 This global exists because gdb user defined commands have no arguments. */
632 int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
634 /* Call this function to print list from X on.
636 N is a count of the rtx's to print. Positive values print from the specified
637 rtx on. Negative values print a window around the rtx.
638 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
641 debug_rtx_list (rtx x
, int n
)
646 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
648 /* If we are printing a window, back up to the start. */
651 for (i
= count
/ 2; i
> 0; i
--)
653 if (PREV_INSN (x
) == 0)
658 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
661 fprintf (stderr
, "\n");
665 /* Call this function to print an rtx list from START to END inclusive. */
668 debug_rtx_range (rtx start
, rtx end
)
673 fprintf (stderr
, "\n");
674 if (!start
|| start
== end
)
676 start
= NEXT_INSN (start
);
680 /* Call this function to search an rtx list to find one with insn uid UID,
681 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
682 The found insn is returned to enable further debugging analysis. */
685 debug_rtx_find (rtx x
, int uid
)
687 while (x
!= 0 && INSN_UID (x
) != uid
)
691 debug_rtx_list (x
, debug_rtx_count
);
696 fprintf (stderr
, "insn uid %d not found\n", uid
);
701 /* External entry point for printing a chain of insns
702 starting with RTX_FIRST onto file OUTF.
703 A blank line separates insns.
705 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
708 print_rtl (FILE *outf
, rtx rtx_first
)
717 fputs (print_rtx_head
, outf
);
718 fputs ("(nil)\n", outf
);
721 switch (GET_CODE (rtx_first
))
729 for (tmp_rtx
= rtx_first
; tmp_rtx
!= 0; tmp_rtx
= NEXT_INSN (tmp_rtx
))
730 if (! flag_dump_unnumbered
731 || !NOTE_P (tmp_rtx
) || NOTE_LINE_NUMBER (tmp_rtx
) < 0)
733 fputs (print_rtx_head
, outfile
);
735 fprintf (outfile
, "\n");
740 fputs (print_rtx_head
, outfile
);
741 print_rtx (rtx_first
);
745 /* Like print_rtx, except specify a file. */
746 /* Return nonzero if we actually printed anything. */
749 print_rtl_single (FILE *outf
, rtx x
)
753 if (! flag_dump_unnumbered
754 || !NOTE_P (x
) || NOTE_LINE_NUMBER (x
) < 0)
756 fputs (print_rtx_head
, outfile
);
765 /* Like print_rtl except without all the detail; for example,
766 if RTX is a CONST_INT then print in decimal format. */
769 print_simple_rtl (FILE *outf
, rtx x
)