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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 /* This file is compiled twice: once for the generator programs,
24 once for the compiler. */
32 #include "coretypes.h"
36 /* These headers all define things which are not available in
37 generator programs. */
38 #ifndef GENERATOR_FILE
42 #include "hard-reg-set.h"
43 #include "basic-block.h"
48 static int sawclose = 0;
52 static void print_rtx (rtx);
54 /* String printed at beginning of each RTL when it is dumped.
55 This string is set to ASM_COMMENT_START when the RTL is dumped in
56 the assembly output file. */
57 const char *print_rtx_head = "";
59 /* Nonzero means suppress output of instruction numbers and line number
60 notes in debugging dumps.
61 This must be defined here so that programs like gencodes can be linked. */
62 int flag_dump_unnumbered = 0;
64 /* Nonzero means use simplified format without flags, modes, etc. */
67 /* Nonzero if we are dumping graphical description. */
70 #ifndef GENERATOR_FILE
72 print_decl_name (FILE *outfile, tree node)
75 fputs (IDENTIFIER_POINTER (DECL_NAME (node)), outfile);
78 if (TREE_CODE (node) == LABEL_DECL && LABEL_DECL_UID (node) != -1)
79 fprintf (outfile, "L." HOST_WIDE_INT_PRINT_DEC, LABEL_DECL_UID (node));
82 char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
83 fprintf (outfile, "%c.%u", c, DECL_UID (node));
89 print_mem_expr (FILE *outfile, tree expr)
91 if (TREE_CODE (expr) == COMPONENT_REF)
93 if (TREE_OPERAND (expr, 0))
94 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
96 fputs (" <variable>", outfile);
98 print_decl_name (outfile, TREE_OPERAND (expr, 1));
100 else if (TREE_CODE (expr) == INDIRECT_REF)
102 fputs (" (*", outfile);
103 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
104 fputs (")", outfile);
106 else if (TREE_CODE (expr) == ALIGN_INDIRECT_REF)
108 fputs (" (A*", outfile);
109 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
110 fputs (")", outfile);
112 else if (TREE_CODE (expr) == MISALIGNED_INDIRECT_REF)
114 fputs (" (M*", outfile);
115 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
116 fputs (")", outfile);
118 else if (TREE_CODE (expr) == RESULT_DECL)
119 fputs (" <result>", outfile);
122 fputc (' ', outfile);
123 print_decl_name (outfile, expr);
128 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
131 print_rtx (rtx in_rtx)
135 const char *format_ptr;
141 fputc (' ', outfile);
143 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
149 fputs ("(nil)", outfile);
153 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
155 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
160 is_insn = INSN_P (in_rtx);
162 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
163 in separate nodes and therefore have to handle them special here. */
165 && (is_insn || NOTE_P (in_rtx)
166 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
173 /* Print name of expression code. */
174 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
175 fputc ('(', outfile);
177 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
181 if (RTX_FLAG (in_rtx, in_struct))
182 fputs ("/s", outfile);
184 if (RTX_FLAG (in_rtx, volatil))
185 fputs ("/v", outfile);
187 if (RTX_FLAG (in_rtx, unchanging))
188 fputs ("/u", outfile);
190 if (RTX_FLAG (in_rtx, frame_related))
191 fputs ("/f", outfile);
193 if (RTX_FLAG (in_rtx, jump))
194 fputs ("/j", outfile);
196 if (RTX_FLAG (in_rtx, call))
197 fputs ("/c", outfile);
199 if (RTX_FLAG (in_rtx, return_val))
200 fputs ("/i", outfile);
202 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
203 if (GET_CODE (in_rtx) == EXPR_LIST
204 || GET_CODE (in_rtx) == INSN_LIST)
205 fprintf (outfile, ":%s",
206 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
208 /* For other rtl, print the mode if it's not VOID. */
209 else if (GET_MODE (in_rtx) != VOIDmode)
210 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
214 #ifndef GENERATOR_FILE
215 if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
219 /* Get the format string and skip the first elements if we have handled
221 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
222 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
223 switch (*format_ptr++)
228 str = XTMPL (in_rtx, i);
233 str = XSTR (in_rtx, i);
237 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
241 fprintf (outfile, " (\\\"%s\\\")", str);
243 fprintf (outfile, " (\"%s\")", str);
248 /* 0 indicates a field for internal use that should not be printed.
249 An exception is the third field of a NOTE, where it indicates
250 that the field has several different valid contents. */
252 if (i == 1 && REG_P (in_rtx))
254 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
255 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
257 #ifndef GENERATOR_FILE
258 else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
260 int flags = SYMBOL_REF_FLAGS (in_rtx);
262 fprintf (outfile, " [flags 0x%x]", flags);
264 else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
266 tree decl = SYMBOL_REF_DECL (in_rtx);
268 print_node_brief (outfile, "", decl, 0);
271 else if (i == 4 && NOTE_P (in_rtx))
273 switch (NOTE_KIND (in_rtx))
275 case NOTE_INSN_EH_REGION_BEG:
276 case NOTE_INSN_EH_REGION_END:
277 if (flag_dump_unnumbered)
278 fprintf (outfile, " #");
280 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
284 case NOTE_INSN_BLOCK_BEG:
285 case NOTE_INSN_BLOCK_END:
286 #ifndef GENERATOR_FILE
287 dump_addr (outfile, " ", NOTE_BLOCK (in_rtx));
292 case NOTE_INSN_BASIC_BLOCK:
294 #ifndef GENERATOR_FILE
295 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
297 fprintf (outfile, " [bb %d]", bb->index);
302 case NOTE_INSN_DELETED_LABEL:
304 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
306 fprintf (outfile, " (\"%s\")", label);
308 fprintf (outfile, " \"\"");
312 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
314 #ifndef GENERATOR_FILE
315 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
317 fprintf (outfile, " [bb %d]", bb->index);
322 case NOTE_INSN_VAR_LOCATION:
323 #ifndef GENERATOR_FILE
324 fprintf (outfile, " (");
325 print_mem_expr (outfile, NOTE_VAR_LOCATION_DECL (in_rtx));
326 fprintf (outfile, " ");
327 print_rtx (NOTE_VAR_LOCATION_LOC (in_rtx));
328 fprintf (outfile, ")");
342 fprintf (outfile, " ");
343 print_rtx (XEXP (in_rtx, i));
352 fprintf (outfile, "\n%s%*s",
353 print_rtx_head, indent * 2, "");
356 fputs (" [", outfile);
357 if (NULL != XVEC (in_rtx, i))
360 if (XVECLEN (in_rtx, i))
363 for (j = 0; j < XVECLEN (in_rtx, i); j++)
364 print_rtx (XVECEXP (in_rtx, i, j));
369 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
371 fputs ("]", outfile);
378 fprintf (outfile, " ");
379 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
381 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
386 if (i == 4 && INSN_P (in_rtx))
388 #ifndef GENERATOR_FILE
389 /* Pretty-print insn locators. Ignore scoping as it is mostly
390 redundant with line number information and do not print anything
391 when there is no location information available. */
392 if (INSN_LOCATOR (in_rtx) && insn_file (in_rtx))
393 fprintf(outfile, " %s:%i", insn_file (in_rtx), insn_line (in_rtx));
396 else if (i == 6 && NOTE_P (in_rtx))
398 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
399 other times often contains garbage from INSN->NOTE death. */
400 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL)
401 fprintf (outfile, " %d", XINT (in_rtx, i));
405 int value = XINT (in_rtx, i);
408 #ifndef GENERATOR_FILE
409 if (REG_P (in_rtx) && value < FIRST_PSEUDO_REGISTER)
410 fprintf (outfile, " %d %s", REGNO (in_rtx),
411 reg_names[REGNO (in_rtx)]);
412 else if (REG_P (in_rtx)
413 && value <= LAST_VIRTUAL_REGISTER)
415 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
416 fprintf (outfile, " %d virtual-incoming-args", value);
417 else if (value == VIRTUAL_STACK_VARS_REGNUM)
418 fprintf (outfile, " %d virtual-stack-vars", value);
419 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
420 fprintf (outfile, " %d virtual-stack-dynamic", value);
421 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
422 fprintf (outfile, " %d virtual-outgoing-args", value);
423 else if (value == VIRTUAL_CFA_REGNUM)
424 fprintf (outfile, " %d virtual-cfa", value);
426 fprintf (outfile, " %d virtual-reg-%d", value,
427 value-FIRST_VIRTUAL_REGISTER);
431 if (flag_dump_unnumbered
432 && (is_insn || NOTE_P (in_rtx)))
433 fputc ('#', outfile);
435 fprintf (outfile, " %d", value);
437 #ifndef GENERATOR_FILE
438 if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
440 fputs (" [", outfile);
441 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
442 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
443 if (REG_EXPR (in_rtx))
444 print_mem_expr (outfile, REG_EXPR (in_rtx));
446 if (REG_OFFSET (in_rtx))
447 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
448 REG_OFFSET (in_rtx));
449 fputs (" ]", outfile);
453 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
454 && XINT (in_rtx, i) >= 0
455 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
456 fprintf (outfile, " {%s}", name);
461 /* Print NOTE_INSN names rather than integer codes. */
464 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
469 if (XEXP (in_rtx, i) != NULL)
471 rtx sub = XEXP (in_rtx, i);
472 enum rtx_code subc = GET_CODE (sub);
474 if (GET_CODE (in_rtx) == LABEL_REF)
477 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
479 if (flag_dump_unnumbered)
480 fprintf (outfile, " [# deleted]");
482 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
487 if (subc != CODE_LABEL)
491 if (flag_dump_unnumbered)
492 fputs (" #", outfile);
494 fprintf (outfile, " %d", INSN_UID (sub));
497 fputs (" 0", outfile);
502 #ifndef GENERATOR_FILE
503 if (XBITMAP (in_rtx, i) == NULL)
504 fputs (" {null}", outfile);
506 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
512 #ifndef GENERATOR_FILE
513 dump_addr (outfile, " ", XTREE (in_rtx, i));
518 fputs (" Unknown", outfile);
523 #ifndef GENERATOR_FILE
524 if (XBBDEF (in_rtx, i))
525 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
533 switch (GET_CODE (in_rtx))
535 #ifndef GENERATOR_FILE
537 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
539 if (MEM_EXPR (in_rtx))
540 print_mem_expr (outfile, MEM_EXPR (in_rtx));
542 if (MEM_OFFSET (in_rtx))
543 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
544 INTVAL (MEM_OFFSET (in_rtx)));
546 if (MEM_SIZE (in_rtx))
547 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC,
548 INTVAL (MEM_SIZE (in_rtx)));
550 if (MEM_ALIGN (in_rtx) != 1)
551 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
553 fputc (']', outfile);
557 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
561 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
563 fprintf (outfile, " %s", s);
565 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
567 fprintf (outfile, " [%s]", s);
573 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
574 switch (LABEL_KIND (in_rtx))
576 case LABEL_NORMAL: break;
577 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
578 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
579 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
580 default: gcc_unreachable ();
589 && (is_insn || NOTE_P (in_rtx)
590 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
594 fputc (')', outfile);
599 /* Print an rtx on the current line of FILE. Initially indent IND
603 print_inline_rtx (FILE *outf, rtx x, int ind)
605 int oldsaw = sawclose;
606 int oldindent = indent;
616 /* Call this function from the debugger to see what X looks like. */
624 fprintf (stderr, "\n");
627 /* Count of rtx's to print with debug_rtx_list.
628 This global exists because gdb user defined commands have no arguments. */
630 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
632 /* Call this function to print list from X on.
634 N is a count of the rtx's to print. Positive values print from the specified
635 rtx on. Negative values print a window around the rtx.
636 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
639 debug_rtx_list (rtx x, int n)
644 count = n == 0 ? 1 : n < 0 ? -n : n;
646 /* If we are printing a window, back up to the start. */
649 for (i = count / 2; i > 0; i--)
651 if (PREV_INSN (x) == 0)
656 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
659 fprintf (stderr, "\n");
663 /* Call this function to print an rtx list from START to END inclusive. */
666 debug_rtx_range (rtx start, rtx end)
671 fprintf (stderr, "\n");
672 if (!start || start == end)
674 start = NEXT_INSN (start);
678 /* Call this function to search an rtx list to find one with insn uid UID,
679 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
680 The found insn is returned to enable further debugging analysis. */
683 debug_rtx_find (rtx x, int uid)
685 while (x != 0 && INSN_UID (x) != uid)
689 debug_rtx_list (x, debug_rtx_count);
694 fprintf (stderr, "insn uid %d not found\n", uid);
699 /* External entry point for printing a chain of insns
700 starting with RTX_FIRST onto file OUTF.
701 A blank line separates insns.
703 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
706 print_rtl (FILE *outf, rtx rtx_first)
713 fputs (print_rtx_head, outf);
714 fputs ("(nil)\n", outf);
717 switch (GET_CODE (rtx_first))
728 fputs (print_rtx_head, outfile);
729 print_rtx (rtx_first);
733 /* Like print_rtx, except specify a file. */
734 /* Return nonzero if we actually printed anything. */
737 print_rtl_single (FILE *outf, rtx x)
741 if (! flag_dump_unnumbered)
743 fputs (print_rtx_head, outfile);
752 /* Like print_rtl except without all the detail; for example,
753 if RTX is a CONST_INT then print in decimal format. */
756 print_simple_rtl (FILE *outf, rtx x)