* arm.h (REVERSE_CONDITION): Define.
[official-gcc.git] / gcc / print-rtl.c
bloba90a2c392cbfe490b73dd660baf9792ae9d0f8bd
1 /* Print RTL for GCC.
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
10 version.
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
15 for more details.
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
20 02111-1307, USA. */
22 /* This file is compiled twice: once for the generator programs,
23 once for the compiler. */
24 #ifdef GENERATOR_FILE
25 #include "bconfig.h"
26 #else
27 #include "config.h"
28 #endif
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include "rtl.h"
35 /* These headers all define things which are not available in
36 generator programs. */
37 #ifndef GENERATOR_FILE
38 #include "tree.h"
39 #include "real.h"
40 #include "flags.h"
41 #include "hard-reg-set.h"
42 #include "basic-block.h"
43 #endif
45 static FILE *outfile;
47 static int sawclose = 0;
49 static int indent;
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. */
64 int flag_simple = 0;
66 /* Nonzero if we are dumping graphical description. */
67 int dump_for_graph;
69 #ifndef GENERATOR_FILE
70 void
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));
77 else
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));
87 fputs (")", outfile);
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);
93 else
94 fputs (" <anonymous>", outfile);
96 #endif
98 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
100 static void
101 print_rtx (rtx in_rtx)
103 int i = 0;
104 int j;
105 const char *format_ptr;
106 int is_insn;
108 if (sawclose)
110 if (flag_simple)
111 fputc (' ', outfile);
112 else
113 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
114 sawclose = 0;
117 if (in_rtx == 0)
119 fputs ("(nil)", outfile);
120 sawclose = 1;
121 return;
123 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
125 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
126 sawclose = 1;
127 return;
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. */
134 if (dump_for_graph
135 && (is_insn || NOTE_P (in_rtx)
136 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
138 i = 3;
139 indent = 0;
141 else
143 /* Print name of expression code. */
144 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
145 fputc ('(', outfile);
146 else
147 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
149 if (! flag_simple)
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)));
179 else
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)))
187 i = 5;
188 #endif
190 /* Get the format string and skip the first elements if we have handled
191 them already. */
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++)
196 const char *str;
198 case 'T':
199 str = XTMPL (in_rtx, i);
200 goto string;
202 case 'S':
203 case 's':
204 str = XSTR (in_rtx, i);
205 string:
207 if (str == 0)
208 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
209 else
211 if (dump_for_graph)
212 fprintf (outfile, " (\\\"%s\\\")", str);
213 else
214 fprintf (outfile, " (\"%s\")", str);
216 sawclose = 1;
217 break;
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. */
222 case '0':
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);
232 if (flags)
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);
238 if (decl)
239 print_node_brief (outfile, "", decl, 0);
241 #endif
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, " #");
250 else
251 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
252 sawclose = 1;
253 break;
255 case NOTE_INSN_BLOCK_BEG:
256 case NOTE_INSN_BLOCK_END:
257 fprintf (outfile, " ");
258 if (flag_dump_unnumbered)
259 fprintf (outfile, "#");
260 else
261 fprintf (outfile, HOST_PTR_PRINTF,
262 (char *) NOTE_BLOCK (in_rtx));
263 sawclose = 1;
264 break;
266 case NOTE_INSN_BASIC_BLOCK:
268 #ifndef GENERATOR_FILE
269 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
270 if (bb != 0)
271 fprintf (outfile, " [bb %d]", bb->index);
272 #endif
273 break;
276 case NOTE_INSN_EXPECTED_VALUE:
277 indent += 2;
278 if (!sawclose)
279 fprintf (outfile, " ");
280 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
281 indent -= 2;
282 break;
284 case NOTE_INSN_DELETED_LABEL:
286 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
287 if (label)
288 fprintf (outfile, " (\"%s\")", label);
289 else
290 fprintf (outfile, " \"\"");
292 break;
294 case NOTE_INSN_UNLIKELY_EXECUTED_CODE:
296 #ifndef GENERATOR_FILE
297 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
298 if (bb != 0)
299 fprintf (outfile, " [bb %d]", bb->index);
300 #endif
301 break;
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, ")");
311 #endif
312 break;
314 default:
316 const char * const str = X0STR (in_rtx, i);
318 if (NOTE_LINE_NUMBER (in_rtx) < 0)
320 else if (str == 0)
321 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
322 else
324 if (dump_for_graph)
325 fprintf (outfile, " (\\\"%s\\\")", str);
326 else
327 fprintf (outfile, " (\"%s\")", str);
329 break;
333 break;
335 case 'e':
336 do_e:
337 indent += 2;
338 if (!sawclose)
339 fprintf (outfile, " ");
340 print_rtx (XEXP (in_rtx, i));
341 indent -= 2;
342 break;
344 case 'E':
345 case 'V':
346 indent += 2;
347 if (sawclose)
349 fprintf (outfile, "\n%s%*s",
350 print_rtx_head, indent * 2, "");
351 sawclose = 0;
353 fputs (" [", outfile);
354 if (NULL != XVEC (in_rtx, i))
356 indent += 2;
357 if (XVECLEN (in_rtx, i))
358 sawclose = 1;
360 for (j = 0; j < XVECLEN (in_rtx, i); j++)
361 print_rtx (XVECEXP (in_rtx, i, j));
363 indent -= 2;
365 if (sawclose)
366 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
368 fputs ("]", outfile);
369 sawclose = 1;
370 indent -= 2;
371 break;
373 case 'w':
374 if (! flag_simple)
375 fprintf (outfile, " ");
376 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
377 if (! flag_simple)
378 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
379 XWINT (in_rtx, i));
380 break;
382 case 'i':
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));
391 #endif
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));
400 else
402 int value = XINT (in_rtx, i);
403 const char *name;
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);
422 else
423 fprintf (outfile, " %d virtual-reg-%d", value,
424 value-FIRST_VIRTUAL_REGISTER);
426 else
427 #endif
428 if (flag_dump_unnumbered
429 && (is_insn || NOTE_P (in_rtx)))
430 fputc ('#', outfile);
431 else
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);
448 #endif
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);
454 sawclose = 0;
456 break;
458 /* Print NOTE_INSN names rather than integer codes. */
460 case 'n':
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)));
464 else
465 fprintf (outfile, " %d", XINT (in_rtx, i));
466 sawclose = 0;
467 break;
469 case 'u':
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)
477 if (subc == NOTE
478 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
480 if (flag_dump_unnumbered)
481 fprintf (outfile, " [# deleted]");
482 else
483 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
484 sawclose = 0;
485 break;
488 if (subc != CODE_LABEL)
489 goto do_e;
492 if (flag_dump_unnumbered)
493 fputs (" #", outfile);
494 else
495 fprintf (outfile, " %d", INSN_UID (sub));
497 else
498 fputs (" 0", outfile);
499 sawclose = 0;
500 break;
502 case 'b':
503 #ifndef GENERATOR_FILE
504 if (XBITMAP (in_rtx, i) == NULL)
505 fputs (" {null}", outfile);
506 else
507 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
508 #endif
509 sawclose = 0;
510 break;
512 case 't':
513 fprintf (outfile, " " HOST_PTR_PRINTF, (void *) XTREE (in_rtx, i));
514 break;
516 case '*':
517 fputs (" Unknown", outfile);
518 sawclose = 0;
519 break;
521 case 'B':
522 #ifndef GENERATOR_FILE
523 if (XBBDEF (in_rtx, i))
524 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
525 #endif
526 break;
528 default:
529 fprintf (stderr,
530 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
531 format_ptr[-1]);
532 abort ();
535 switch (GET_CODE (in_rtx))
537 #ifndef GENERATOR_FILE
538 case MEM:
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);
556 break;
558 case CONST_DOUBLE:
559 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
561 char s[60];
563 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
564 sizeof (s), 0, 1);
565 fprintf (outfile, " %s", s);
567 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
568 sizeof (s), 0, 1);
569 fprintf (outfile, " [%s]", s);
571 break;
572 #endif
574 case CODE_LABEL:
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;
582 default: abort();
584 break;
586 default:
587 break;
590 if (dump_for_graph
591 && (is_insn || NOTE_P (in_rtx)
592 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
593 sawclose = 0;
594 else
596 fputc (')', outfile);
597 sawclose = 1;
601 /* Print an rtx on the current line of FILE. Initially indent IND
602 characters. */
604 void
605 print_inline_rtx (FILE *outf, rtx x, int ind)
607 int oldsaw = sawclose;
608 int oldindent = indent;
610 sawclose = 0;
611 indent = ind;
612 outfile = outf;
613 print_rtx (x);
614 sawclose = oldsaw;
615 indent = oldindent;
618 /* Call this function from the debugger to see what X looks like. */
620 void
621 debug_rtx (rtx x)
623 outfile = stderr;
624 sawclose = 0;
625 print_rtx (x);
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). */
640 void
641 debug_rtx_list (rtx x, int n)
643 int i,count;
644 rtx insn;
646 count = n == 0 ? 1 : n < 0 ? -n : n;
648 /* If we are printing a window, back up to the start. */
650 if (n < 0)
651 for (i = count / 2; i > 0; i--)
653 if (PREV_INSN (x) == 0)
654 break;
655 x = PREV_INSN (x);
658 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
660 debug_rtx (insn);
661 fprintf (stderr, "\n");
665 /* Call this function to print an rtx list from START to END inclusive. */
667 void
668 debug_rtx_range (rtx start, rtx end)
670 while (1)
672 debug_rtx (start);
673 fprintf (stderr, "\n");
674 if (!start || start == end)
675 break;
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)
688 x = NEXT_INSN (x);
689 if (x != 0)
691 debug_rtx_list (x, debug_rtx_count);
692 return x;
694 else
696 fprintf (stderr, "insn uid %d not found\n", uid);
697 return 0;
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. */
707 void
708 print_rtl (FILE *outf, rtx rtx_first)
710 rtx tmp_rtx;
712 outfile = outf;
713 sawclose = 0;
715 if (rtx_first == 0)
717 fputs (print_rtx_head, outf);
718 fputs ("(nil)\n", outf);
720 else
721 switch (GET_CODE (rtx_first))
723 case INSN:
724 case JUMP_INSN:
725 case CALL_INSN:
726 case NOTE:
727 case CODE_LABEL:
728 case BARRIER:
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);
734 print_rtx (tmp_rtx);
735 fprintf (outfile, "\n");
737 break;
739 default:
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)
751 outfile = outf;
752 sawclose = 0;
753 if (! flag_dump_unnumbered
754 || !NOTE_P (x) || NOTE_LINE_NUMBER (x) < 0)
756 fputs (print_rtx_head, outfile);
757 print_rtx (x);
758 putc ('\n', outf);
759 return 1;
761 return 0;
765 /* Like print_rtl except without all the detail; for example,
766 if RTX is a CONST_INT then print in decimal format. */
768 void
769 print_simple_rtl (FILE *outf, rtx x)
771 flag_simple = 1;
772 print_rtl (outf, x);
773 flag_simple = 0;