2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003
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
25 #include "coretypes.h"
29 /* We don't want the tree code checking code for the access to the
30 DECL_NAME to be included in the gen* programs. */
31 #undef ENABLE_TREE_CHECKING
35 #include "hard-reg-set.h"
36 #include "basic-block.h"
41 static int sawclose
= 0;
45 static void print_rtx (rtx
);
47 /* String printed at beginning of each RTL when it is dumped.
48 This string is set to ASM_COMMENT_START when the RTL is dumped in
49 the assembly output file. */
50 const char *print_rtx_head
= "";
52 /* Nonzero means suppress output of instruction numbers and line number
53 notes in debugging dumps.
54 This must be defined here so that programs like gencodes can be linked. */
55 int flag_dump_unnumbered
= 0;
57 /* Nonzero means use simplified format without flags, modes, etc. */
60 /* Nonzero if we are dumping graphical description. */
63 /* Nonzero to dump all call_placeholder alternatives. */
64 static int debug_call_placeholder_verbose
;
67 print_mem_expr (FILE *outfile
, tree expr
)
69 if (TREE_CODE (expr
) == COMPONENT_REF
)
71 if (TREE_OPERAND (expr
, 0))
72 print_mem_expr (outfile
, TREE_OPERAND (expr
, 0));
74 fputs (" <variable>", outfile
);
75 if (DECL_NAME (TREE_OPERAND (expr
, 1)))
76 fprintf (outfile
, ".%s",
77 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (expr
, 1))));
79 else if (TREE_CODE (expr
) == INDIRECT_REF
)
81 fputs (" (*", outfile
);
82 print_mem_expr (outfile
, TREE_OPERAND (expr
, 0));
85 else if (DECL_NAME (expr
))
86 fprintf (outfile
, " %s", IDENTIFIER_POINTER (DECL_NAME (expr
)));
87 else if (TREE_CODE (expr
) == RESULT_DECL
)
88 fputs (" <result>", outfile
);
90 fputs (" <anonymous>", outfile
);
93 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
96 print_rtx (rtx in_rtx
)
100 const char *format_ptr
;
107 fputc (' ', outfile
);
109 fprintf (outfile
, "\n%s%*s", print_rtx_head
, indent
* 2, "");
115 fputs ("(nil)", outfile
);
119 else if (GET_CODE (in_rtx
) > NUM_RTX_CODE
)
121 fprintf (outfile
, "(??? bad code %d\n)", GET_CODE (in_rtx
));
126 is_insn
= INSN_P (in_rtx
);
128 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
129 in separate nodes and therefore have to handle them special here. */
131 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
132 || GET_CODE (in_rtx
) == CODE_LABEL
|| GET_CODE (in_rtx
) == BARRIER
))
139 /* Print name of expression code. */
140 if (flag_simple
&& GET_CODE (in_rtx
) == CONST_INT
)
141 fputc ('(', outfile
);
143 fprintf (outfile
, "(%s", GET_RTX_NAME (GET_CODE (in_rtx
)));
147 if (RTX_FLAG (in_rtx
, in_struct
))
148 fputs ("/s", outfile
);
150 if (RTX_FLAG (in_rtx
, volatil
))
151 fputs ("/v", outfile
);
153 if (RTX_FLAG (in_rtx
, unchanging
))
154 fputs ("/u", outfile
);
156 if (RTX_FLAG (in_rtx
, integrated
))
157 fputs ("/i", outfile
);
159 if (RTX_FLAG (in_rtx
, frame_related
))
160 fputs ("/f", outfile
);
162 if (RTX_FLAG (in_rtx
, jump
))
163 fputs ("/j", outfile
);
165 if (RTX_FLAG (in_rtx
, call
))
166 fputs ("/c", outfile
);
168 if (GET_MODE (in_rtx
) != VOIDmode
)
170 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
171 if (GET_CODE (in_rtx
) == EXPR_LIST
172 || GET_CODE (in_rtx
) == INSN_LIST
)
173 fprintf (outfile
, ":%s",
174 GET_REG_NOTE_NAME (GET_MODE (in_rtx
)));
176 fprintf (outfile
, ":%s", GET_MODE_NAME (GET_MODE (in_rtx
)));
181 #ifndef GENERATOR_FILE
182 if (GET_CODE (in_rtx
) == CONST_DOUBLE
&& FLOAT_MODE_P (GET_MODE (in_rtx
)))
186 /* Get the format string and skip the first elements if we have handled
188 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
)) + i
;
189 for (; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
190 switch (*format_ptr
++)
195 str
= XTMPL (in_rtx
, i
);
200 str
= XSTR (in_rtx
, i
);
204 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
208 fprintf (outfile
, " (\\\"%s\\\")", str
);
210 fprintf (outfile
, " (\"%s\")", str
);
215 /* 0 indicates a field for internal use that should not be printed.
216 An exception is the third field of a NOTE, where it indicates
217 that the field has several different valid contents. */
219 if (i
== 1 && GET_CODE (in_rtx
) == REG
)
221 if (REGNO (in_rtx
) != ORIGINAL_REGNO (in_rtx
))
222 fprintf (outfile
, " [%d]", ORIGINAL_REGNO (in_rtx
));
224 #ifndef GENERATOR_FILE
225 else if (i
== 1 && GET_CODE (in_rtx
) == SYMBOL_REF
)
227 int flags
= SYMBOL_REF_FLAGS (in_rtx
);
229 fprintf (outfile
, " [flags 0x%x]", flags
);
231 else if (i
== 2 && GET_CODE (in_rtx
) == SYMBOL_REF
)
233 tree decl
= SYMBOL_REF_DECL (in_rtx
);
235 print_node_brief (outfile
, "", decl
, 0);
238 else if (i
== 4 && GET_CODE (in_rtx
) == NOTE
)
240 switch (NOTE_LINE_NUMBER (in_rtx
))
242 case NOTE_INSN_EH_REGION_BEG
:
243 case NOTE_INSN_EH_REGION_END
:
244 if (flag_dump_unnumbered
)
245 fprintf (outfile
, " #");
247 fprintf (outfile
, " %d", NOTE_EH_HANDLER (in_rtx
));
251 case NOTE_INSN_BLOCK_BEG
:
252 case NOTE_INSN_BLOCK_END
:
253 fprintf (outfile
, " ");
254 if (flag_dump_unnumbered
)
255 fprintf (outfile
, "#");
257 fprintf (outfile
, HOST_PTR_PRINTF
,
258 (char *) NOTE_BLOCK (in_rtx
));
262 case NOTE_INSN_BASIC_BLOCK
:
264 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
266 fprintf (outfile
, " [bb %d]", bb
->index
);
270 case NOTE_INSN_EXPECTED_VALUE
:
273 fprintf (outfile
, " ");
274 print_rtx (NOTE_EXPECTED_VALUE (in_rtx
));
278 case NOTE_INSN_DELETED_LABEL
:
279 if (NOTE_SOURCE_FILE (in_rtx
))
280 fprintf (outfile
, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx
));
282 fprintf (outfile
, " \"\"");
285 case NOTE_INSN_PREDICTION
:
286 if (NOTE_PREDICTION (in_rtx
))
287 fprintf (outfile
, " [ %d %d ] ",
288 (int)NOTE_PREDICTION_ALG (in_rtx
),
289 (int) NOTE_PREDICTION_FLAGS (in_rtx
));
291 fprintf (outfile
, " [ ERROR ]");
296 const char * const str
= X0STR (in_rtx
, i
);
298 if (NOTE_LINE_NUMBER (in_rtx
) < 0)
301 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
305 fprintf (outfile
, " (\\\"%s\\\")", str
);
307 fprintf (outfile
, " (\"%s\")", str
);
319 fprintf (outfile
, " ");
320 print_rtx (XEXP (in_rtx
, i
));
329 fprintf (outfile
, "\n%s%*s",
330 print_rtx_head
, indent
* 2, "");
333 fputs (" [", outfile
);
334 if (NULL
!= XVEC (in_rtx
, i
))
337 if (XVECLEN (in_rtx
, i
))
340 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
341 print_rtx (XVECEXP (in_rtx
, i
, j
));
346 fprintf (outfile
, "\n%s%*s", print_rtx_head
, indent
* 2, "");
348 fputs ("]", outfile
);
355 fprintf (outfile
, " ");
356 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, XWINT (in_rtx
, i
));
358 fprintf (outfile
, " [" HOST_WIDE_INT_PRINT_HEX
"]",
363 if (i
== 4 && INSN_P (in_rtx
))
365 #ifndef GENERATOR_FILE
366 /* Pretty-print insn locators. Ignore scoping as it is mostly
367 redundant with line number information and do not print anything
368 when there is no location information available. */
369 if (INSN_LOCATOR (in_rtx
) && insn_file (in_rtx
))
370 fprintf(outfile
, " %s:%i", insn_file (in_rtx
), insn_line (in_rtx
));
373 else if (i
== 6 && GET_CODE (in_rtx
) == NOTE
)
375 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
376 other times often contains garbage from INSN->NOTE death. */
377 if (NOTE_LINE_NUMBER (in_rtx
) == NOTE_INSN_DELETED_LABEL
)
378 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
382 int value
= XINT (in_rtx
, i
);
385 #ifndef GENERATOR_FILE
386 if (GET_CODE (in_rtx
) == REG
&& value
< FIRST_PSEUDO_REGISTER
)
388 fputc (' ', outfile
);
389 PRINT_REG (in_rtx
, 0, outfile
);
391 else if (GET_CODE (in_rtx
) == REG
392 && value
<= LAST_VIRTUAL_REGISTER
)
394 if (value
== VIRTUAL_INCOMING_ARGS_REGNUM
)
395 fprintf (outfile
, " %d virtual-incoming-args", value
);
396 else if (value
== VIRTUAL_STACK_VARS_REGNUM
)
397 fprintf (outfile
, " %d virtual-stack-vars", value
);
398 else if (value
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
399 fprintf (outfile
, " %d virtual-stack-dynamic", value
);
400 else if (value
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
401 fprintf (outfile
, " %d virtual-outgoing-args", value
);
402 else if (value
== VIRTUAL_CFA_REGNUM
)
403 fprintf (outfile
, " %d virtual-cfa", value
);
405 fprintf (outfile
, " %d virtual-reg-%d", value
,
406 value
-FIRST_VIRTUAL_REGISTER
);
410 if (flag_dump_unnumbered
411 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
))
412 fputc ('#', outfile
);
414 fprintf (outfile
, " %d", value
);
416 if (GET_CODE (in_rtx
) == REG
&& REG_ATTRS (in_rtx
))
418 fputs (" [", outfile
);
419 if (ORIGINAL_REGNO (in_rtx
) != REGNO (in_rtx
))
420 fprintf (outfile
, "orig:%i", ORIGINAL_REGNO (in_rtx
));
421 if (REG_EXPR (in_rtx
))
422 print_mem_expr (outfile
, REG_EXPR (in_rtx
));
424 if (REG_OFFSET (in_rtx
))
425 fprintf (outfile
, "+" HOST_WIDE_INT_PRINT_DEC
,
426 REG_OFFSET (in_rtx
));
427 fputs (" ]", outfile
);
430 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
431 && XINT (in_rtx
, i
) >= 0
432 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
433 fprintf (outfile
, " {%s}", name
);
438 /* Print NOTE_INSN names rather than integer codes. */
441 if (XINT (in_rtx
, i
) >= (int) NOTE_INSN_BIAS
442 && XINT (in_rtx
, i
) < (int) NOTE_INSN_MAX
)
443 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
445 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
450 if (XEXP (in_rtx
, i
) != NULL
)
452 rtx sub
= XEXP (in_rtx
, i
);
453 enum rtx_code subc
= GET_CODE (sub
);
455 if (GET_CODE (in_rtx
) == LABEL_REF
)
458 && NOTE_LINE_NUMBER (sub
) == NOTE_INSN_DELETED_LABEL
)
460 if (flag_dump_unnumbered
)
461 fprintf (outfile
, " [# deleted]");
463 fprintf (outfile
, " [%d deleted]", INSN_UID (sub
));
468 if (subc
!= CODE_LABEL
)
472 if (flag_dump_unnumbered
)
473 fputs (" #", outfile
);
475 fprintf (outfile
, " %d", INSN_UID (sub
));
478 fputs (" 0", outfile
);
483 if (XBITMAP (in_rtx
, i
) == NULL
)
484 fputs (" {null}", outfile
);
486 bitmap_print (outfile
, XBITMAP (in_rtx
, i
), " {", "}");
491 fprintf (outfile
, " " HOST_PTR_PRINTF
, (void *) XTREE (in_rtx
, i
));
495 fputs (" Unknown", outfile
);
500 if (XBBDEF (in_rtx
, i
))
501 fprintf (outfile
, " %i", XBBDEF (in_rtx
, i
)->index
);
506 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
511 switch (GET_CODE (in_rtx
))
513 #ifndef GENERATOR_FILE
515 fprintf (outfile
, " [" HOST_WIDE_INT_PRINT_DEC
, MEM_ALIAS_SET (in_rtx
));
517 if (MEM_EXPR (in_rtx
))
518 print_mem_expr (outfile
, MEM_EXPR (in_rtx
));
520 if (MEM_OFFSET (in_rtx
))
521 fprintf (outfile
, "+" HOST_WIDE_INT_PRINT_DEC
,
522 INTVAL (MEM_OFFSET (in_rtx
)));
524 if (MEM_SIZE (in_rtx
))
525 fprintf (outfile
, " S" HOST_WIDE_INT_PRINT_DEC
,
526 INTVAL (MEM_SIZE (in_rtx
)));
528 if (MEM_ALIGN (in_rtx
) != 1)
529 fprintf (outfile
, " A%u", MEM_ALIGN (in_rtx
));
531 fputc (']', outfile
);
535 if (FLOAT_MODE_P (GET_MODE (in_rtx
)))
539 real_to_decimal (s
, CONST_DOUBLE_REAL_VALUE (in_rtx
),
541 fprintf (outfile
, " %s", s
);
543 real_to_hexadecimal (s
, CONST_DOUBLE_REAL_VALUE (in_rtx
),
545 fprintf (outfile
, " [%s]", s
);
551 fprintf (outfile
, " [%d uses]", LABEL_NUSES (in_rtx
));
552 switch (LABEL_KIND (in_rtx
))
554 case LABEL_NORMAL
: break;
555 case LABEL_STATIC_ENTRY
: fputs (" [entry]", outfile
); break;
556 case LABEL_GLOBAL_ENTRY
: fputs (" [global entry]", outfile
); break;
557 case LABEL_WEAK_ENTRY
: fputs (" [weak entry]", outfile
); break;
562 case CALL_PLACEHOLDER
:
563 if (debug_call_placeholder_verbose
)
565 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile
);
566 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
568 fputs ("\n ", outfile
);
569 print_inline_rtx (outfile
, tem
, 4);
572 tem
= XEXP (in_rtx
, 1);
574 fputs ("\n ])\n (const_string \"tail_call\") (sequence [",
576 for (; tem
!= 0; tem
= NEXT_INSN (tem
))
578 fputs ("\n ", outfile
);
579 print_inline_rtx (outfile
, tem
, 4);
582 tem
= XEXP (in_rtx
, 2);
584 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [",
586 for (; tem
!= 0; tem
= NEXT_INSN (tem
))
588 fputs ("\n ", outfile
);
589 print_inline_rtx (outfile
, tem
, 4);
592 fputs ("\n ])\n ])", outfile
);
596 for (tem
= XEXP (in_rtx
, 0); tem
!= 0; tem
= NEXT_INSN (tem
))
597 if (GET_CODE (tem
) == CALL_INSN
)
599 fprintf (outfile
, " ");
610 && (is_insn
|| GET_CODE (in_rtx
) == NOTE
611 || GET_CODE (in_rtx
) == CODE_LABEL
|| GET_CODE (in_rtx
) == BARRIER
))
615 fputc (')', outfile
);
620 /* Print an rtx on the current line of FILE. Initially indent IND
624 print_inline_rtx (FILE *outf
, rtx x
, int ind
)
626 int oldsaw
= sawclose
;
627 int oldindent
= indent
;
637 /* Call this function from the debugger to see what X looks like. */
645 fprintf (stderr
, "\n");
648 /* Count of rtx's to print with debug_rtx_list.
649 This global exists because gdb user defined commands have no arguments. */
651 int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
653 /* Call this function to print list from X on.
655 N is a count of the rtx's to print. Positive values print from the specified
656 rtx on. Negative values print a window around the rtx.
657 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
660 debug_rtx_list (rtx x
, int n
)
665 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
667 /* If we are printing a window, back up to the start. */
670 for (i
= count
/ 2; i
> 0; i
--)
672 if (PREV_INSN (x
) == 0)
677 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
680 fprintf (stderr
, "\n");
684 /* Call this function to print an rtx list from START to END inclusive. */
687 debug_rtx_range (rtx start
, rtx end
)
692 fprintf (stderr
, "\n");
693 if (!start
|| start
== end
)
695 start
= NEXT_INSN (start
);
699 /* Call this function to search an rtx list to find one with insn uid UID,
700 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
701 The found insn is returned to enable further debugging analysis. */
704 debug_rtx_find (rtx x
, int uid
)
706 while (x
!= 0 && INSN_UID (x
) != uid
)
710 debug_rtx_list (x
, debug_rtx_count
);
715 fprintf (stderr
, "insn uid %d not found\n", uid
);
720 /* External entry point for printing a chain of insns
721 starting with RTX_FIRST onto file OUTF.
722 A blank line separates insns.
724 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
727 print_rtl (FILE *outf
, rtx rtx_first
)
736 fputs (print_rtx_head
, outf
);
737 fputs ("(nil)\n", outf
);
740 switch (GET_CODE (rtx_first
))
748 for (tmp_rtx
= rtx_first
; tmp_rtx
!= 0; tmp_rtx
= NEXT_INSN (tmp_rtx
))
749 if (! flag_dump_unnumbered
750 || GET_CODE (tmp_rtx
) != NOTE
|| NOTE_LINE_NUMBER (tmp_rtx
) < 0)
752 fputs (print_rtx_head
, outfile
);
754 fprintf (outfile
, "\n");
759 fputs (print_rtx_head
, outfile
);
760 print_rtx (rtx_first
);
764 /* Like print_rtx, except specify a file. */
765 /* Return nonzero if we actually printed anything. */
768 print_rtl_single (FILE *outf
, rtx x
)
772 if (! flag_dump_unnumbered
773 || GET_CODE (x
) != NOTE
|| NOTE_LINE_NUMBER (x
) < 0)
775 fputs (print_rtx_head
, outfile
);
784 /* Like print_rtl except without all the detail; for example,
785 if RTX is a CONST_INT then print in decimal format. */
788 print_simple_rtl (FILE *outf
, rtx x
)