2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003,
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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 (const_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
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_decl_name (FILE *outfile
, const_tree node
)
74 fputs (IDENTIFIER_POINTER (DECL_NAME (node
)), outfile
);
77 if (TREE_CODE (node
) == LABEL_DECL
&& LABEL_DECL_UID (node
) != -1)
78 fprintf (outfile
, "L.%d", (int) LABEL_DECL_UID (node
));
81 char c
= TREE_CODE (node
) == CONST_DECL
? 'C' : 'D';
82 fprintf (outfile
, "%c.%u", c
, DECL_UID (node
));
88 print_mem_expr (FILE *outfile
, const_tree expr
)
90 if (TREE_CODE (expr
) == COMPONENT_REF
)
92 if (TREE_OPERAND (expr
, 0))
93 print_mem_expr (outfile
, TREE_OPERAND (expr
, 0));
95 fputs (" <variable>", outfile
);
97 print_decl_name (outfile
, TREE_OPERAND (expr
, 1));
99 else if (TREE_CODE (expr
) == INDIRECT_REF
)
101 fputs (" (*", outfile
);
102 print_mem_expr (outfile
, TREE_OPERAND (expr
, 0));
103 fputs (")", outfile
);
105 else if (TREE_CODE (expr
) == ALIGN_INDIRECT_REF
)
107 fputs (" (A*", outfile
);
108 print_mem_expr (outfile
, TREE_OPERAND (expr
, 0));
109 fputs (")", outfile
);
111 else if (TREE_CODE (expr
) == MISALIGNED_INDIRECT_REF
)
113 fputs (" (M*", outfile
);
114 print_mem_expr (outfile
, TREE_OPERAND (expr
, 0));
115 fputs (")", outfile
);
117 else if (TREE_CODE (expr
) == RESULT_DECL
)
118 fputs (" <result>", outfile
);
121 fputc (' ', outfile
);
122 print_decl_name (outfile
, expr
);
127 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
130 print_rtx (const_rtx in_rtx
)
134 const char *format_ptr
;
140 fputc (' ', outfile
);
142 fprintf (outfile
, "\n%s%*s", print_rtx_head
, indent
* 2, "");
148 fputs ("(nil)", outfile
);
152 else if (GET_CODE (in_rtx
) > NUM_RTX_CODE
)
154 fprintf (outfile
, "(??? bad code %d\n)", GET_CODE (in_rtx
));
159 is_insn
= INSN_P (in_rtx
);
161 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
162 in separate nodes and therefore have to handle them special here. */
164 && (is_insn
|| NOTE_P (in_rtx
)
165 || LABEL_P (in_rtx
) || BARRIER_P (in_rtx
)))
172 /* Print name of expression code. */
173 if (flag_simple
&& GET_CODE (in_rtx
) == CONST_INT
)
174 fputc ('(', outfile
);
176 fprintf (outfile
, "(%s", GET_RTX_NAME (GET_CODE (in_rtx
)));
180 if (RTX_FLAG (in_rtx
, in_struct
))
181 fputs ("/s", outfile
);
183 if (RTX_FLAG (in_rtx
, volatil
))
184 fputs ("/v", outfile
);
186 if (RTX_FLAG (in_rtx
, unchanging
))
187 fputs ("/u", outfile
);
189 if (RTX_FLAG (in_rtx
, frame_related
))
190 fputs ("/f", outfile
);
192 if (RTX_FLAG (in_rtx
, jump
))
193 fputs ("/j", outfile
);
195 if (RTX_FLAG (in_rtx
, call
))
196 fputs ("/c", outfile
);
198 if (RTX_FLAG (in_rtx
, return_val
))
199 fputs ("/i", outfile
);
201 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
202 if (GET_CODE (in_rtx
) == EXPR_LIST
203 || GET_CODE (in_rtx
) == INSN_LIST
)
204 fprintf (outfile
, ":%s",
205 GET_REG_NOTE_NAME (GET_MODE (in_rtx
)));
207 /* For other rtl, print the mode if it's not VOID. */
208 else if (GET_MODE (in_rtx
) != VOIDmode
)
209 fprintf (outfile
, ":%s", GET_MODE_NAME (GET_MODE (in_rtx
)));
213 #ifndef GENERATOR_FILE
214 if (GET_CODE (in_rtx
) == CONST_DOUBLE
&& FLOAT_MODE_P (GET_MODE (in_rtx
)))
218 /* Get the format string and skip the first elements if we have handled
220 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
)) + i
;
221 for (; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
222 switch (*format_ptr
++)
227 str
= XTMPL (in_rtx
, i
);
232 str
= XSTR (in_rtx
, i
);
236 fputs (dump_for_graph
? " \\\"\\\"" : " \"\"", outfile
);
240 fprintf (outfile
, " (\\\"%s\\\")", str
);
242 fprintf (outfile
, " (\"%s\")", str
);
247 /* 0 indicates a field for internal use that should not be printed.
248 An exception is the third field of a NOTE, where it indicates
249 that the field has several different valid contents. */
251 if (i
== 1 && REG_P (in_rtx
))
253 if (REGNO (in_rtx
) != ORIGINAL_REGNO (in_rtx
))
254 fprintf (outfile
, " [%d]", ORIGINAL_REGNO (in_rtx
));
256 #ifndef GENERATOR_FILE
257 else if (i
== 1 && GET_CODE (in_rtx
) == SYMBOL_REF
)
259 int flags
= SYMBOL_REF_FLAGS (in_rtx
);
261 fprintf (outfile
, " [flags 0x%x]", flags
);
263 else if (i
== 2 && GET_CODE (in_rtx
) == SYMBOL_REF
)
265 tree decl
= SYMBOL_REF_DECL (in_rtx
);
267 print_node_brief (outfile
, "", decl
, 0);
270 else if (i
== 4 && NOTE_P (in_rtx
))
272 switch (NOTE_KIND (in_rtx
))
274 case NOTE_INSN_EH_REGION_BEG
:
275 case NOTE_INSN_EH_REGION_END
:
276 if (flag_dump_unnumbered
)
277 fprintf (outfile
, " #");
279 fprintf (outfile
, " %d", NOTE_EH_HANDLER (in_rtx
));
283 case NOTE_INSN_BLOCK_BEG
:
284 case NOTE_INSN_BLOCK_END
:
285 #ifndef GENERATOR_FILE
286 dump_addr (outfile
, " ", NOTE_BLOCK (in_rtx
));
291 case NOTE_INSN_BASIC_BLOCK
:
293 #ifndef GENERATOR_FILE
294 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
296 fprintf (outfile
, " [bb %d]", bb
->index
);
301 case NOTE_INSN_DELETED_LABEL
:
303 const char *label
= NOTE_DELETED_LABEL_NAME (in_rtx
);
305 fprintf (outfile
, " (\"%s\")", label
);
307 fprintf (outfile
, " \"\"");
311 case NOTE_INSN_SWITCH_TEXT_SECTIONS
:
313 #ifndef GENERATOR_FILE
314 basic_block bb
= NOTE_BASIC_BLOCK (in_rtx
);
316 fprintf (outfile
, " [bb %d]", bb
->index
);
321 case NOTE_INSN_VAR_LOCATION
:
322 #ifndef GENERATOR_FILE
323 fprintf (outfile
, " (");
324 print_mem_expr (outfile
, NOTE_VAR_LOCATION_DECL (in_rtx
));
325 fprintf (outfile
, " ");
326 print_rtx (NOTE_VAR_LOCATION_LOC (in_rtx
));
327 if (NOTE_VAR_LOCATION_STATUS (in_rtx
) ==
328 VAR_INIT_STATUS_UNINITIALIZED
)
329 fprintf (outfile
, " [uninit]");
330 fprintf (outfile
, ")");
338 else if (i
== 9 && JUMP_P (in_rtx
) && XEXP (in_rtx
, i
) != NULL
)
339 /* Output the JUMP_LABEL reference. */
340 fprintf (outfile
, "\n -> %d", INSN_UID (XEXP (in_rtx
, i
)));
347 fprintf (outfile
, " ");
348 print_rtx (XEXP (in_rtx
, i
));
357 fprintf (outfile
, "\n%s%*s",
358 print_rtx_head
, indent
* 2, "");
361 fputs (" [", outfile
);
362 if (NULL
!= XVEC (in_rtx
, i
))
365 if (XVECLEN (in_rtx
, i
))
368 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
369 print_rtx (XVECEXP (in_rtx
, i
, j
));
374 fprintf (outfile
, "\n%s%*s", print_rtx_head
, indent
* 2, "");
376 fputs ("]", outfile
);
383 fprintf (outfile
, " ");
384 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, XWINT (in_rtx
, i
));
386 fprintf (outfile
, " [" HOST_WIDE_INT_PRINT_HEX
"]",
391 if (i
== 4 && INSN_P (in_rtx
))
393 #ifndef GENERATOR_FILE
394 /* Pretty-print insn locators. Ignore scoping as it is mostly
395 redundant with line number information and do not print anything
396 when there is no location information available. */
397 if (INSN_LOCATOR (in_rtx
) && insn_file (in_rtx
))
398 fprintf(outfile
, " %s:%i", insn_file (in_rtx
), insn_line (in_rtx
));
401 else if (i
== 6 && NOTE_P (in_rtx
))
403 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
404 other times often contains garbage from INSN->NOTE death. */
405 if (NOTE_KIND (in_rtx
) == NOTE_INSN_DELETED_LABEL
)
406 fprintf (outfile
, " %d", XINT (in_rtx
, i
));
410 int value
= XINT (in_rtx
, i
);
413 #ifndef GENERATOR_FILE
414 if (REG_P (in_rtx
) && value
< FIRST_PSEUDO_REGISTER
)
415 fprintf (outfile
, " %d %s", REGNO (in_rtx
),
416 reg_names
[REGNO (in_rtx
)]);
417 else if (REG_P (in_rtx
)
418 && value
<= LAST_VIRTUAL_REGISTER
)
420 if (value
== VIRTUAL_INCOMING_ARGS_REGNUM
)
421 fprintf (outfile
, " %d virtual-incoming-args", value
);
422 else if (value
== VIRTUAL_STACK_VARS_REGNUM
)
423 fprintf (outfile
, " %d virtual-stack-vars", value
);
424 else if (value
== VIRTUAL_STACK_DYNAMIC_REGNUM
)
425 fprintf (outfile
, " %d virtual-stack-dynamic", value
);
426 else if (value
== VIRTUAL_OUTGOING_ARGS_REGNUM
)
427 fprintf (outfile
, " %d virtual-outgoing-args", value
);
428 else if (value
== VIRTUAL_CFA_REGNUM
)
429 fprintf (outfile
, " %d virtual-cfa", value
);
431 fprintf (outfile
, " %d virtual-reg-%d", value
,
432 value
-FIRST_VIRTUAL_REGISTER
);
436 if (flag_dump_unnumbered
437 && (is_insn
|| NOTE_P (in_rtx
)))
438 fputc ('#', outfile
);
440 fprintf (outfile
, " %d", value
);
442 #ifndef GENERATOR_FILE
443 if (REG_P (in_rtx
) && REG_ATTRS (in_rtx
))
445 fputs (" [", outfile
);
446 if (ORIGINAL_REGNO (in_rtx
) != REGNO (in_rtx
))
447 fprintf (outfile
, "orig:%i", ORIGINAL_REGNO (in_rtx
));
448 if (REG_EXPR (in_rtx
))
449 print_mem_expr (outfile
, REG_EXPR (in_rtx
));
451 if (REG_OFFSET (in_rtx
))
452 fprintf (outfile
, "+" HOST_WIDE_INT_PRINT_DEC
,
453 REG_OFFSET (in_rtx
));
454 fputs (" ]", outfile
);
458 if (is_insn
&& &INSN_CODE (in_rtx
) == &XINT (in_rtx
, i
)
459 && XINT (in_rtx
, i
) >= 0
460 && (name
= get_insn_name (XINT (in_rtx
, i
))) != NULL
)
461 fprintf (outfile
, " {%s}", name
);
466 /* Print NOTE_INSN names rather than integer codes. */
469 fprintf (outfile
, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx
, i
)));
474 if (XEXP (in_rtx
, i
) != NULL
)
476 rtx sub
= XEXP (in_rtx
, i
);
477 enum rtx_code subc
= GET_CODE (sub
);
479 if (GET_CODE (in_rtx
) == LABEL_REF
)
482 && NOTE_KIND (sub
) == NOTE_INSN_DELETED_LABEL
)
484 if (flag_dump_unnumbered
)
485 fprintf (outfile
, " [# deleted]");
487 fprintf (outfile
, " [%d deleted]", INSN_UID (sub
));
492 if (subc
!= CODE_LABEL
)
496 if (flag_dump_unnumbered
)
497 fputs (" #", outfile
);
499 fprintf (outfile
, " %d", INSN_UID (sub
));
502 fputs (" 0", outfile
);
507 #ifndef GENERATOR_FILE
508 if (XBITMAP (in_rtx
, i
) == NULL
)
509 fputs (" {null}", outfile
);
511 bitmap_print (outfile
, XBITMAP (in_rtx
, i
), " {", "}");
517 #ifndef GENERATOR_FILE
518 dump_addr (outfile
, " ", XTREE (in_rtx
, i
));
523 fputs (" Unknown", outfile
);
528 #ifndef GENERATOR_FILE
529 if (XBBDEF (in_rtx
, i
))
530 fprintf (outfile
, " %i", XBBDEF (in_rtx
, i
)->index
);
538 switch (GET_CODE (in_rtx
))
540 #ifndef GENERATOR_FILE
542 fprintf (outfile
, " [" HOST_WIDE_INT_PRINT_DEC
,
543 (HOST_WIDE_INT
) MEM_ALIAS_SET (in_rtx
));
545 if (MEM_EXPR (in_rtx
))
546 print_mem_expr (outfile
, MEM_EXPR (in_rtx
));
548 if (MEM_OFFSET (in_rtx
))
549 fprintf (outfile
, "+" HOST_WIDE_INT_PRINT_DEC
,
550 INTVAL (MEM_OFFSET (in_rtx
)));
552 if (MEM_SIZE (in_rtx
))
553 fprintf (outfile
, " S" HOST_WIDE_INT_PRINT_DEC
,
554 INTVAL (MEM_SIZE (in_rtx
)));
556 if (MEM_ALIGN (in_rtx
) != 1)
557 fprintf (outfile
, " A%u", MEM_ALIGN (in_rtx
));
559 fputc (']', outfile
);
563 if (FLOAT_MODE_P (GET_MODE (in_rtx
)))
567 real_to_decimal (s
, CONST_DOUBLE_REAL_VALUE (in_rtx
),
569 fprintf (outfile
, " %s", s
);
571 real_to_hexadecimal (s
, CONST_DOUBLE_REAL_VALUE (in_rtx
),
573 fprintf (outfile
, " [%s]", s
);
579 fprintf (outfile
, " [%d uses]", LABEL_NUSES (in_rtx
));
580 switch (LABEL_KIND (in_rtx
))
582 case LABEL_NORMAL
: break;
583 case LABEL_STATIC_ENTRY
: fputs (" [entry]", outfile
); break;
584 case LABEL_GLOBAL_ENTRY
: fputs (" [global entry]", outfile
); break;
585 case LABEL_WEAK_ENTRY
: fputs (" [weak entry]", outfile
); break;
586 default: gcc_unreachable ();
595 && (is_insn
|| NOTE_P (in_rtx
)
596 || LABEL_P (in_rtx
) || BARRIER_P (in_rtx
)))
600 fputc (')', outfile
);
605 /* Print an rtx on the current line of FILE. Initially indent IND
609 print_inline_rtx (FILE *outf
, const_rtx x
, int ind
)
611 int oldsaw
= sawclose
;
612 int oldindent
= indent
;
622 /* Call this function from the debugger to see what X looks like. */
625 debug_rtx (const_rtx x
)
630 fprintf (stderr
, "\n");
633 /* Count of rtx's to print with debug_rtx_list.
634 This global exists because gdb user defined commands have no arguments. */
636 int debug_rtx_count
= 0; /* 0 is treated as equivalent to 1 */
638 /* Call this function to print list from X on.
640 N is a count of the rtx's to print. Positive values print from the specified
641 rtx on. Negative values print a window around the rtx.
642 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
645 debug_rtx_list (const_rtx x
, int n
)
650 count
= n
== 0 ? 1 : n
< 0 ? -n
: n
;
652 /* If we are printing a window, back up to the start. */
655 for (i
= count
/ 2; i
> 0; i
--)
657 if (PREV_INSN (x
) == 0)
662 for (i
= count
, insn
= x
; i
> 0 && insn
!= 0; i
--, insn
= NEXT_INSN (insn
))
665 fprintf (stderr
, "\n");
669 /* Call this function to print an rtx list from START to END inclusive. */
672 debug_rtx_range (const_rtx start
, const_rtx end
)
677 fprintf (stderr
, "\n");
678 if (!start
|| start
== end
)
680 start
= NEXT_INSN (start
);
684 /* Call this function to search an rtx list to find one with insn uid UID,
685 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
686 The found insn is returned to enable further debugging analysis. */
689 debug_rtx_find (const_rtx x
, int uid
)
691 while (x
!= 0 && INSN_UID (x
) != uid
)
695 debug_rtx_list (x
, debug_rtx_count
);
700 fprintf (stderr
, "insn uid %d not found\n", uid
);
705 /* External entry point for printing a chain of insns
706 starting with RTX_FIRST onto file OUTF.
707 A blank line separates insns.
709 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
712 print_rtl (FILE *outf
, const_rtx rtx_first
)
721 fputs (print_rtx_head
, outf
);
722 fputs ("(nil)\n", outf
);
725 switch (GET_CODE (rtx_first
))
733 for (tmp_rtx
= rtx_first
; tmp_rtx
!= 0; tmp_rtx
= NEXT_INSN (tmp_rtx
))
735 fputs (print_rtx_head
, outfile
);
737 fprintf (outfile
, "\n");
742 fputs (print_rtx_head
, outfile
);
743 print_rtx (rtx_first
);
747 /* Like print_rtx, except specify a file. */
748 /* Return nonzero if we actually printed anything. */
751 print_rtl_single (FILE *outf
, const_rtx x
)
755 fputs (print_rtx_head
, outfile
);
762 /* Like print_rtl except without all the detail; for example,
763 if RTX is a CONST_INT then print in decimal format. */
766 print_simple_rtl (FILE *outf
, const_rtx x
)