* params.c: Fix formatting.
[official-gcc.git] / gcc / print-rtl.c
blob823ffa0c5139d1f35066b96344859fcc356cb6b4
1 /* Print RTL for GNU C Compiler.
2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000
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. */
23 #include "config.h"
24 #include "system.h"
25 #include "rtl.h"
27 /* We don't want the tree code checking code for the access to the
28 DECL_NAME to be included in the gen* programs. */
29 #undef ENABLE_TREE_CHECKING
30 #include "tree.h"
31 #include "real.h"
32 #include "flags.h"
33 #include "hard-reg-set.h"
34 #include "basic-block.h"
36 /* How to print out a register name.
37 We don't use PRINT_REG because some definitions of PRINT_REG
38 don't work here. */
39 #ifndef DEBUG_PRINT_REG
40 #define DEBUG_PRINT_REG(RTX, CODE, FILE) \
41 fprintf ((FILE), "%d %s", REGNO (RTX), reg_names[REGNO (RTX)])
42 #endif
44 /* Array containing all of the register names */
46 #ifdef DEBUG_REGISTER_NAMES
47 static const char * const debug_reg_names[] = DEBUG_REGISTER_NAMES;
48 #define reg_names debug_reg_names
49 #else
50 const char * reg_names[] = REGISTER_NAMES;
51 #endif
53 static FILE *outfile;
55 static int sawclose = 0;
57 static int indent;
59 static void print_rtx PARAMS ((rtx));
61 /* String printed at beginning of each RTL when it is dumped.
62 This string is set to ASM_COMMENT_START when the RTL is dumped in
63 the assembly output file. */
64 const char *print_rtx_head = "";
66 /* Nonzero means suppress output of instruction numbers and line number
67 notes in debugging dumps.
68 This must be defined here so that programs like gencodes can be linked. */
69 int flag_dump_unnumbered = 0;
71 /* Nonzero means use simplified format without flags, modes, etc. */
72 int flag_simple = 0;
74 /* Nonzero if we are dumping graphical description. */
75 int dump_for_graph;
77 /* Nonzero to dump all call_placeholder alternatives. */
78 static int debug_call_placeholder_verbose;
80 void
81 print_mem_expr (outfile, expr)
82 FILE *outfile;
83 tree expr;
85 if (TREE_CODE (expr) == COMPONENT_REF)
87 if (TREE_OPERAND (expr, 0))
88 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
89 else
90 fputs (" <variable>", outfile);
91 fprintf (outfile, ".%s",
92 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (expr, 1))));
94 else if (DECL_NAME (expr))
95 fprintf (outfile, " %s", IDENTIFIER_POINTER (DECL_NAME (expr)));
96 else if (TREE_CODE (expr) == RESULT_DECL)
97 fputs (" <result>", outfile);
98 else
99 fputs (" <anonymous>", outfile);
102 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
104 static void
105 print_rtx (in_rtx)
106 rtx in_rtx;
108 int i = 0;
109 int j;
110 const char *format_ptr;
111 int is_insn;
112 rtx tem;
114 if (sawclose)
116 if (flag_simple)
117 fputc (' ', outfile);
118 else
119 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
120 sawclose = 0;
123 if (in_rtx == 0)
125 fputs ("(nil)", outfile);
126 sawclose = 1;
127 return;
129 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
131 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
132 sawclose = 1;
133 return;
136 is_insn = INSN_P (in_rtx);
138 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
139 in separate nodes and therefore have to handle them special here. */
140 if (dump_for_graph
141 && (is_insn || GET_CODE (in_rtx) == NOTE
142 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
144 i = 3;
145 indent = 0;
147 else
149 /* Print name of expression code. */
150 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
151 fputc ('(', outfile);
152 else
153 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
155 if (! flag_simple)
157 if (RTX_FLAG (in_rtx, in_struct))
158 fputs ("/s", outfile);
160 if (RTX_FLAG (in_rtx, volatil))
161 fputs ("/v", outfile);
163 if (RTX_FLAG (in_rtx, unchanging))
164 fputs ("/u", outfile);
166 if (RTX_FLAG (in_rtx, integrated))
167 fputs ("/i", outfile);
169 if (RTX_FLAG (in_rtx, frame_related))
170 fputs ("/f", outfile);
172 if (RTX_FLAG (in_rtx, jump))
173 fputs ("/j", outfile);
175 if (RTX_FLAG (in_rtx, call))
176 fputs ("/c", outfile);
178 if (GET_MODE (in_rtx) != VOIDmode)
180 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
181 if (GET_CODE (in_rtx) == EXPR_LIST
182 || GET_CODE (in_rtx) == INSN_LIST)
183 fprintf (outfile, ":%s",
184 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
185 else
186 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
191 /* Get the format string and skip the first elements if we have handled
192 them already. */
193 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
194 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
195 switch (*format_ptr++)
197 const char *str;
199 case 'T':
200 str = XTMPL (in_rtx, i);
201 goto string;
203 case 'S':
204 case 's':
205 str = XSTR (in_rtx, i);
206 string:
208 if (str == 0)
209 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
210 else
212 if (dump_for_graph)
213 fprintf (outfile, " (\\\"%s\\\")", str);
214 else
215 fprintf (outfile, " (\"%s\")", str);
217 sawclose = 1;
218 break;
220 /* 0 indicates a field for internal use that should not be printed.
221 An exception is the third field of a NOTE, where it indicates
222 that the field has several different valid contents. */
223 case '0':
224 if (i == 1 && GET_CODE (in_rtx) == REG)
226 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
227 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
228 break;
230 if (i == 3 && GET_CODE (in_rtx) == NOTE)
232 switch (NOTE_LINE_NUMBER (in_rtx))
234 case NOTE_INSN_EH_REGION_BEG:
235 case NOTE_INSN_EH_REGION_END:
236 if (flag_dump_unnumbered)
237 fprintf (outfile, " #");
238 else
239 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
240 sawclose = 1;
241 break;
243 case NOTE_INSN_BLOCK_BEG:
244 case NOTE_INSN_BLOCK_END:
245 fprintf (outfile, " ");
246 if (flag_dump_unnumbered)
247 fprintf (outfile, "#");
248 else
249 fprintf (outfile, HOST_PTR_PRINTF,
250 (char *) NOTE_BLOCK (in_rtx));
251 sawclose = 1;
252 break;
254 case NOTE_INSN_RANGE_BEG:
255 case NOTE_INSN_RANGE_END:
256 case NOTE_INSN_LIVE:
257 indent += 2;
258 if (!sawclose)
259 fprintf (outfile, " ");
260 print_rtx (NOTE_RANGE_INFO (in_rtx));
261 indent -= 2;
262 break;
264 case NOTE_INSN_BASIC_BLOCK:
266 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
267 if (bb != 0)
268 fprintf (outfile, " [bb %d]", bb->index);
269 break;
272 case NOTE_INSN_EXPECTED_VALUE:
273 indent += 2;
274 if (!sawclose)
275 fprintf (outfile, " ");
276 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
277 indent -= 2;
278 break;
280 case NOTE_INSN_DELETED_LABEL:
281 if (NOTE_SOURCE_FILE (in_rtx))
282 fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
283 else
284 fprintf (outfile, " \"\"");
285 break;
287 case NOTE_INSN_PREDICTION:
288 if (NOTE_PREDICTION (in_rtx))
289 fprintf (outfile, " [ %d %d ] ",
290 (int)NOTE_PREDICTION_ALG (in_rtx),
291 (int) NOTE_PREDICTION_FLAGS (in_rtx));
292 else
293 fprintf (outfile, " [ ERROR ]");
294 break;
296 default:
298 const char * const str = X0STR (in_rtx, i);
300 if (NOTE_LINE_NUMBER (in_rtx) < 0)
302 else if (str == 0)
303 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
304 else
306 if (dump_for_graph)
307 fprintf (outfile, " (\\\"%s\\\")", str);
308 else
309 fprintf (outfile, " (\"%s\")", str);
311 break;
315 break;
317 case 'e':
318 do_e:
319 indent += 2;
320 if (!sawclose)
321 fprintf (outfile, " ");
322 print_rtx (XEXP (in_rtx, i));
323 indent -= 2;
324 break;
326 case 'E':
327 case 'V':
328 indent += 2;
329 if (sawclose)
331 fprintf (outfile, "\n%s%*s",
332 print_rtx_head, indent * 2, "");
333 sawclose = 0;
335 fputs ("[ ", outfile);
336 if (NULL != XVEC (in_rtx, i))
338 indent += 2;
339 if (XVECLEN (in_rtx, i))
340 sawclose = 1;
342 for (j = 0; j < XVECLEN (in_rtx, i); j++)
343 print_rtx (XVECEXP (in_rtx, i, j));
345 indent -= 2;
347 if (sawclose)
348 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
350 fputs ("] ", outfile);
351 sawclose = 1;
352 indent -= 2;
353 break;
355 case 'w':
356 if (! flag_simple)
357 fprintf (outfile, " ");
358 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
359 if (! flag_simple)
361 fprintf (outfile, " [");
362 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
363 fprintf (outfile, "]");
365 break;
367 case 'i':
368 if (i == 5 && GET_CODE (in_rtx) == NOTE)
370 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
371 other times often contains garbage from INSN->NOTE death. */
372 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
373 fprintf (outfile, " %d", XINT (in_rtx, i));
375 else
377 int value = XINT (in_rtx, i);
378 const char *name;
380 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
382 fputc (' ', outfile);
383 DEBUG_PRINT_REG (in_rtx, 0, outfile);
385 else if (GET_CODE (in_rtx) == REG
386 && value <= LAST_VIRTUAL_REGISTER)
388 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
389 fprintf (outfile, " %d virtual-incoming-args", value);
390 else if (value == VIRTUAL_STACK_VARS_REGNUM)
391 fprintf (outfile, " %d virtual-stack-vars", value);
392 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
393 fprintf (outfile, " %d virtual-stack-dynamic", value);
394 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
395 fprintf (outfile, " %d virtual-outgoing-args", value);
396 else if (value == VIRTUAL_CFA_REGNUM)
397 fprintf (outfile, " %d virtual-cfa", value);
398 else
399 fprintf (outfile, " %d virtual-reg-%d", value,
400 value-FIRST_VIRTUAL_REGISTER);
402 else if (flag_dump_unnumbered
403 && (is_insn || GET_CODE (in_rtx) == NOTE))
404 fputc ('#', outfile);
405 else
406 fprintf (outfile, " %d", value);
408 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
409 && XINT (in_rtx, i) >= 0
410 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
411 fprintf (outfile, " {%s}", name);
412 sawclose = 0;
414 break;
416 /* Print NOTE_INSN names rather than integer codes. */
418 case 'n':
419 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
420 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
421 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
422 else
423 fprintf (outfile, " %d", XINT (in_rtx, i));
424 sawclose = 0;
425 break;
427 case 'u':
428 if (XEXP (in_rtx, i) != NULL)
430 rtx sub = XEXP (in_rtx, i);
431 enum rtx_code subc = GET_CODE (sub);
433 if (GET_CODE (in_rtx) == LABEL_REF)
435 if (subc == NOTE
436 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
438 if (flag_dump_unnumbered)
439 fprintf (outfile, " [# deleted]");
440 else
441 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
442 sawclose = 0;
443 break;
446 if (subc != CODE_LABEL)
447 goto do_e;
450 if (flag_dump_unnumbered)
451 fputs (" #", outfile);
452 else
453 fprintf (outfile, " %d", INSN_UID (sub));
455 else
456 fputs (" 0", outfile);
457 sawclose = 0;
458 break;
460 case 'b':
461 if (XBITMAP (in_rtx, i) == NULL)
462 fputs (" {null}", outfile);
463 else
464 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
465 sawclose = 0;
466 break;
468 case 't':
469 putc (' ', outfile);
470 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
471 break;
473 case '*':
474 fputs (" Unknown", outfile);
475 sawclose = 0;
476 break;
478 default:
479 fprintf (stderr,
480 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
481 format_ptr[-1]);
482 abort ();
485 switch (GET_CODE (in_rtx))
487 case MEM:
488 fputs (" [", outfile);
489 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
491 if (MEM_EXPR (in_rtx))
492 print_mem_expr (outfile, MEM_EXPR (in_rtx));
494 if (MEM_OFFSET (in_rtx))
496 fputc ('+', outfile);
497 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
498 INTVAL (MEM_OFFSET (in_rtx)));
501 if (MEM_SIZE (in_rtx))
503 fputs (" S", outfile);
504 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC,
505 INTVAL (MEM_SIZE (in_rtx)));
508 if (MEM_ALIGN (in_rtx) != 1)
509 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
511 fputc (']', outfile);
512 break;
514 #if 0
515 /* It would be nice to do this, but it would require real.o to
516 be linked into the MD-generator programs. Maybe we should
517 do that. -zw 2002-03-03 */
518 case CONST_DOUBLE:
519 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
521 REAL_VALUE_TYPE val;
522 char s[30];
524 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
525 REAL_VALUE_TO_DECIMAL (val, "%.16g", s);
526 fprintf (outfile, " [%s]", s);
528 break;
529 #endif
531 case CODE_LABEL:
532 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
533 if (LABEL_ALTERNATE_NAME (in_rtx))
534 fprintf (outfile, " [alternate name: %s]",
535 LABEL_ALTERNATE_NAME (in_rtx));
536 break;
538 case CALL_PLACEHOLDER:
539 if (debug_call_placeholder_verbose)
541 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile);
542 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
544 fputs ("\n ", outfile);
545 print_inline_rtx (outfile, tem, 4);
548 tem = XEXP (in_rtx, 1);
549 if (tem)
550 fputs ("\n ])\n (const_string \"tail_call\") (sequence [",
551 outfile);
552 for (; tem != 0; tem = NEXT_INSN (tem))
554 fputs ("\n ", outfile);
555 print_inline_rtx (outfile, tem, 4);
558 tem = XEXP (in_rtx, 2);
559 if (tem)
560 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [",
561 outfile);
562 for (; tem != 0; tem = NEXT_INSN (tem))
564 fputs ("\n ", outfile);
565 print_inline_rtx (outfile, tem, 4);
568 fputs ("\n ])\n ])", outfile);
569 break;
572 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
573 if (GET_CODE (tem) == CALL_INSN)
575 fprintf (outfile, " ");
576 print_rtx (tem);
577 break;
579 break;
581 default:
582 break;
585 if (dump_for_graph
586 && (is_insn || GET_CODE (in_rtx) == NOTE
587 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
588 sawclose = 0;
589 else
591 fputc (')', outfile);
592 sawclose = 1;
596 /* Print an rtx on the current line of FILE. Initially indent IND
597 characters. */
599 void
600 print_inline_rtx (outf, x, ind)
601 FILE *outf;
602 rtx x;
603 int ind;
605 int oldsaw = sawclose;
606 int oldindent = indent;
608 sawclose = 0;
609 indent = ind;
610 outfile = outf;
611 print_rtx (x);
612 sawclose = oldsaw;
613 indent = oldindent;
616 /* Call this function from the debugger to see what X looks like. */
618 void
619 debug_rtx (x)
620 rtx x;
622 outfile = stderr;
623 print_rtx (x);
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). */
638 void
639 debug_rtx_list (x, n)
640 rtx x;
641 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))
659 debug_rtx (insn);
662 /* Call this function to print an rtx list from START to END inclusive. */
664 void
665 debug_rtx_range (start, end)
666 rtx start, end;
668 while (1)
670 debug_rtx (start);
671 if (!start || start == end)
672 break;
673 start = NEXT_INSN (start);
677 /* Call this function to search an rtx list to find one with insn uid UID,
678 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
679 The found insn is returned to enable further debugging analysis. */
682 debug_rtx_find (x, uid)
683 rtx x;
684 int uid;
686 while (x != 0 && INSN_UID (x) != uid)
687 x = NEXT_INSN (x);
688 if (x != 0)
690 debug_rtx_list (x, debug_rtx_count);
691 return x;
693 else
695 fprintf (stderr, "insn uid %d not found\n", uid);
696 return 0;
700 /* External entry point for printing a chain of insns
701 starting with RTX_FIRST onto file OUTF.
702 A blank line separates insns.
704 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
706 void
707 print_rtl (outf, rtx_first)
708 FILE *outf;
709 rtx rtx_first;
711 rtx tmp_rtx;
713 outfile = outf;
714 sawclose = 0;
716 if (rtx_first == 0)
718 fputs (print_rtx_head, outf);
719 fputs ("(nil)\n", outf);
721 else
722 switch (GET_CODE (rtx_first))
724 case INSN:
725 case JUMP_INSN:
726 case CALL_INSN:
727 case NOTE:
728 case CODE_LABEL:
729 case BARRIER:
730 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
731 if (! flag_dump_unnumbered
732 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
734 fputs (print_rtx_head, outfile);
735 print_rtx (tmp_rtx);
736 fprintf (outfile, "\n");
738 break;
740 default:
741 fputs (print_rtx_head, outfile);
742 print_rtx (rtx_first);
746 /* Like print_rtx, except specify a file. */
747 /* Return nonzero if we actually printed anything. */
750 print_rtl_single (outf, x)
751 FILE *outf;
752 rtx x;
754 outfile = outf;
755 sawclose = 0;
756 if (! flag_dump_unnumbered
757 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
759 fputs (print_rtx_head, outfile);
760 print_rtx (x);
761 putc ('\n', outf);
762 return 1;
764 return 0;
768 /* Like print_rtl except without all the detail; for example,
769 if RTX is a CONST_INT then print in decimal format. */
771 void
772 print_simple_rtl (outf, x)
773 FILE *outf;
774 rtx x;
776 flag_simple = 1;
777 print_rtl (outf, x);
778 flag_simple = 0;