Fix typo
[official-gcc.git] / gcc / print-rtl.c
blobaeae71e89b651cc7b459b94fa8f2d6ed5d7f3458
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 GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "rtl.h"
26 #include "real.h"
27 #include "flags.h"
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
31 /* How to print out a register name.
32 We don't use PRINT_REG because some definitions of PRINT_REG
33 don't work here. */
34 #ifndef DEBUG_PRINT_REG
35 #define DEBUG_PRINT_REG(RTX, CODE, FILE) \
36 fprintf ((FILE), "%d %s", REGNO (RTX), reg_names[REGNO (RTX)])
37 #endif
39 /* Array containing all of the register names */
41 #ifdef DEBUG_REGISTER_NAMES
42 static const char * const debug_reg_names[] = DEBUG_REGISTER_NAMES;
43 #define reg_names debug_reg_names
44 #else
45 const char * reg_names[] = REGISTER_NAMES;
46 #endif
48 static FILE *outfile;
50 static const char xspaces[] = " ";
52 static int sawclose = 0;
54 static int indent;
56 static void print_rtx PARAMS ((rtx));
58 /* String printed at beginning of each RTL when it is dumped.
59 This string is set to ASM_COMMENT_START when the RTL is dumped in
60 the assembly output file. */
61 const char *print_rtx_head = "";
63 /* Nonzero means suppress output of instruction numbers and line number
64 notes in debugging dumps.
65 This must be defined here so that programs like gencodes can be linked. */
66 int flag_dump_unnumbered = 0;
68 /* Nonzero means use simplified format without flags, modes, etc. */
69 int flag_simple = 0;
71 /* Nonzero if we are dumping graphical description. */
72 int dump_for_graph;
74 /* Nonzero to dump all call_placeholder alternatives. */
75 static int debug_call_placeholder_verbose;
77 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
79 static void
80 print_rtx (in_rtx)
81 register rtx in_rtx;
83 register int i = 0;
84 register int j;
85 register const char *format_ptr;
86 register int is_insn;
87 rtx tem;
89 if (sawclose)
91 if (flag_simple)
92 fputc (' ', outfile);
93 else
94 fprintf (outfile, "\n%s%s",
95 print_rtx_head,
96 (xspaces + (sizeof xspaces - 1 - indent * 2)));
97 sawclose = 0;
100 if (in_rtx == 0)
102 fputs ("(nil)", outfile);
103 sawclose = 1;
104 return;
107 is_insn = (INSN_P (in_rtx));
109 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
110 in separate nodes and therefore have to handle them special here. */
111 if (dump_for_graph &&
112 (is_insn || GET_CODE (in_rtx) == NOTE || GET_CODE (in_rtx) == CODE_LABEL
113 || GET_CODE (in_rtx) == BARRIER))
115 i = 3;
116 indent = 0;
118 else
120 /* print name of expression code */
121 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
122 fputc ('(', outfile);
123 else
124 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
126 if (! flag_simple)
128 if (in_rtx->in_struct)
129 fputs ("/s", outfile);
131 if (in_rtx->volatil)
132 fputs ("/v", outfile);
134 if (in_rtx->unchanging)
135 fputs ("/u", outfile);
137 if (in_rtx->integrated)
138 fputs ("/i", outfile);
140 if (in_rtx->frame_related)
141 fputs ("/f", outfile);
143 if (in_rtx->jump)
144 fputs ("/j", outfile);
146 if (in_rtx->call)
147 fputs ("/c", outfile);
149 if (GET_MODE (in_rtx) != VOIDmode)
151 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
152 if (GET_CODE (in_rtx) == EXPR_LIST
153 || GET_CODE (in_rtx) == INSN_LIST)
154 fprintf (outfile, ":%s",
155 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
156 else
157 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
162 /* Get the format string and skip the first elements if we have handled
163 them already. */
164 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
166 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
167 switch (*format_ptr++)
169 case 'S':
170 case 's':
171 if (XSTR (in_rtx, i) == 0)
172 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
173 else
175 if (dump_for_graph)
176 fprintf (outfile, " (\\\"%s\\\")", XSTR (in_rtx, i));
177 else
178 fprintf (outfile, " (\"%s\")", XSTR (in_rtx, i));
180 sawclose = 1;
181 break;
183 /* 0 indicates a field for internal use that should not be printed.
184 An exception is the third field of a NOTE, where it indicates
185 that the field has several different valid contents. */
186 case '0':
187 if (i == 1 && GET_CODE (in_rtx) == REG)
189 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
190 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
191 break;
193 if (i == 3 && GET_CODE (in_rtx) == NOTE)
195 switch (NOTE_LINE_NUMBER (in_rtx))
197 case NOTE_INSN_EH_REGION_BEG:
198 case NOTE_INSN_EH_REGION_END:
199 if (flag_dump_unnumbered)
200 fprintf (outfile, " #");
201 else
202 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
203 sawclose = 1;
204 break;
206 case NOTE_INSN_BLOCK_BEG:
207 case NOTE_INSN_BLOCK_END:
208 fprintf (outfile, " ");
209 if (flag_dump_unnumbered)
210 fprintf (outfile, "#");
211 else
212 fprintf (outfile, HOST_PTR_PRINTF,
213 (char *) NOTE_BLOCK (in_rtx));
214 sawclose = 1;
215 break;
217 case NOTE_INSN_RANGE_BEG:
218 case NOTE_INSN_RANGE_END:
219 case NOTE_INSN_LIVE:
220 indent += 2;
221 if (!sawclose)
222 fprintf (outfile, " ");
223 print_rtx (NOTE_RANGE_INFO (in_rtx));
224 indent -= 2;
225 break;
227 case NOTE_INSN_BASIC_BLOCK:
229 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
230 if (bb != 0)
231 fprintf (outfile, " [bb %d]", bb->index);
232 break;
235 case NOTE_INSN_EXPECTED_VALUE:
236 indent += 2;
237 if (!sawclose)
238 fprintf (outfile, " ");
239 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
240 indent -= 2;
241 break;
243 case NOTE_INSN_DELETED_LABEL:
244 if (NOTE_SOURCE_FILE (in_rtx))
245 fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
246 else
247 fprintf (outfile, " \"\"");
248 break;
250 default:
252 const char * const str = X0STR (in_rtx, i);
254 if (NOTE_LINE_NUMBER (in_rtx) < 0)
256 else if (str == 0)
257 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
258 else
260 if (dump_for_graph)
261 fprintf (outfile, " (\\\"%s\\\")", str);
262 else
263 fprintf (outfile, " (\"%s\")", str);
265 break;
269 break;
271 case 'e':
272 do_e:
273 indent += 2;
274 if (!sawclose)
275 fprintf (outfile, " ");
276 print_rtx (XEXP (in_rtx, i));
277 indent -= 2;
278 break;
280 case 'E':
281 case 'V':
282 indent += 2;
283 if (sawclose)
285 fprintf (outfile, "\n%s%s",
286 print_rtx_head,
287 (xspaces + (sizeof xspaces - 1 - indent * 2)));
288 sawclose = 0;
290 fputs ("[ ", outfile);
291 if (NULL != XVEC (in_rtx, i))
293 indent += 2;
294 if (XVECLEN (in_rtx, i))
295 sawclose = 1;
297 for (j = 0; j < XVECLEN (in_rtx, i); j++)
298 print_rtx (XVECEXP (in_rtx, i, j));
300 indent -= 2;
302 if (sawclose)
303 fprintf (outfile, "\n%s%s",
304 print_rtx_head,
305 (xspaces + (sizeof xspaces - 1 - indent * 2)));
307 fputs ("] ", outfile);
308 sawclose = 1;
309 indent -= 2;
310 break;
312 case 'w':
313 if (! flag_simple)
314 fprintf (outfile, " ");
315 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
316 if (! flag_simple)
318 fprintf (outfile, " [");
319 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
320 fprintf (outfile, "]");
322 break;
324 case 'i':
325 if (i == 5 && GET_CODE (in_rtx) == NOTE)
327 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
328 other times often contains garbage from INSN->NOTE death. */
329 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
330 fprintf (outfile, " %d", XINT (in_rtx, i));
332 else
334 register int value = XINT (in_rtx, i);
335 const char *name;
337 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
339 fputc (' ', outfile);
340 DEBUG_PRINT_REG (in_rtx, 0, outfile);
342 else if (GET_CODE (in_rtx) == REG
343 && value <= LAST_VIRTUAL_REGISTER)
345 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
346 fprintf (outfile, " %d virtual-incoming-args", value);
347 else if (value == VIRTUAL_STACK_VARS_REGNUM)
348 fprintf (outfile, " %d virtual-stack-vars", value);
349 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
350 fprintf (outfile, " %d virtual-stack-dynamic", value);
351 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
352 fprintf (outfile, " %d virtual-outgoing-args", value);
353 else if (value == VIRTUAL_CFA_REGNUM)
354 fprintf (outfile, " %d virtual-cfa", value);
355 else
356 fprintf (outfile, " %d virtual-reg-%d", value,
357 value-FIRST_VIRTUAL_REGISTER);
359 else if (flag_dump_unnumbered
360 && (is_insn || GET_CODE (in_rtx) == NOTE))
361 fputc ('#', outfile);
362 else
363 fprintf (outfile, " %d", value);
365 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
366 && XINT (in_rtx, i) >= 0
367 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
368 fprintf (outfile, " {%s}", name);
369 sawclose = 0;
371 break;
373 /* Print NOTE_INSN names rather than integer codes. */
375 case 'n':
376 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
377 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
378 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
379 else
380 fprintf (outfile, " %d", XINT (in_rtx, i));
381 sawclose = 0;
382 break;
384 case 'u':
385 if (XEXP (in_rtx, i) != NULL)
387 rtx sub = XEXP (in_rtx, i);
388 enum rtx_code subc = GET_CODE (sub);
390 if (GET_CODE (in_rtx) == LABEL_REF)
392 if (subc == NOTE
393 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
395 if (flag_dump_unnumbered)
396 fprintf (outfile, " [# deleted]");
397 else
398 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
399 sawclose = 0;
400 break;
403 if (subc != CODE_LABEL)
404 goto do_e;
407 if (flag_dump_unnumbered)
408 fputs (" #", outfile);
409 else
410 fprintf (outfile, " %d", INSN_UID (sub));
412 else
413 fputs (" 0", outfile);
414 sawclose = 0;
415 break;
417 case 'b':
418 if (XBITMAP (in_rtx, i) == NULL)
419 fputs (" {null}", outfile);
420 else
421 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
422 sawclose = 0;
423 break;
425 case 't':
426 putc (' ', outfile);
427 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
428 break;
430 case '*':
431 fputs (" Unknown", outfile);
432 sawclose = 0;
433 break;
435 default:
436 fprintf (stderr,
437 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
438 format_ptr[-1]);
439 abort ();
442 switch (GET_CODE (in_rtx))
444 case MEM:
445 fputc (' ', outfile);
446 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
447 break;
449 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
450 case CONST_DOUBLE:
451 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
453 double val;
454 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
455 fprintf (outfile, " [%.16g]", val);
457 break;
458 #endif
460 case CODE_LABEL:
461 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
462 if (LABEL_ALTERNATE_NAME (in_rtx))
463 fprintf (outfile, " [alternate name: %s]",
464 LABEL_ALTERNATE_NAME (in_rtx));
465 break;
467 case CALL_PLACEHOLDER:
468 if (debug_call_placeholder_verbose)
470 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile);
471 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
473 fputs ("\n ", outfile);
474 print_inline_rtx (outfile, tem, 4);
477 tem = XEXP (in_rtx, 1);
478 if (tem)
479 fputs ("\n ])\n (const_string \"tail_call\") (sequence [", outfile);
480 for (; tem != 0; tem = NEXT_INSN (tem))
482 fputs ("\n ", outfile);
483 print_inline_rtx (outfile, tem, 4);
486 tem = XEXP (in_rtx, 2);
487 if (tem)
488 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [", outfile);
489 for (; tem != 0; tem = NEXT_INSN (tem))
491 fputs ("\n ", outfile);
492 print_inline_rtx (outfile, tem, 4);
495 fputs ("\n ])\n ])", outfile);
496 break;
499 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
500 if (GET_CODE (tem) == CALL_INSN)
502 fprintf (outfile, " ");
503 print_rtx (tem);
504 break;
506 break;
508 default:
509 break;
512 if (dump_for_graph
513 && (is_insn || GET_CODE (in_rtx) == NOTE
514 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
515 sawclose = 0;
516 else
518 fputc (')', outfile);
519 sawclose = 1;
523 /* Print an rtx on the current line of FILE. Initially indent IND
524 characters. */
526 void
527 print_inline_rtx (outf, x, ind)
528 FILE *outf;
529 rtx x;
530 int ind;
532 int oldsaw = sawclose;
533 int oldindent = indent;
535 sawclose = 0;
536 indent = ind;
537 outfile = outf;
538 print_rtx (x);
539 sawclose = oldsaw;
540 indent = oldindent;
543 /* Call this function from the debugger to see what X looks like. */
545 void
546 debug_rtx (x)
547 rtx x;
549 outfile = stderr;
550 print_rtx (x);
551 fprintf (stderr, "\n");
554 /* Count of rtx's to print with debug_rtx_list.
555 This global exists because gdb user defined commands have no arguments. */
557 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
559 /* Call this function to print list from X on.
561 N is a count of the rtx's to print. Positive values print from the specified
562 rtx on. Negative values print a window around the rtx.
563 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
565 void
566 debug_rtx_list (x, n)
567 rtx x;
568 int n;
570 int i,count;
571 rtx insn;
573 count = n == 0 ? 1 : n < 0 ? -n : n;
575 /* If we are printing a window, back up to the start. */
577 if (n < 0)
578 for (i = count / 2; i > 0; i--)
580 if (PREV_INSN (x) == 0)
581 break;
582 x = PREV_INSN (x);
585 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
586 debug_rtx (insn);
589 /* Call this function to print an rtx list from START to END inclusive. */
591 void
592 debug_rtx_range (start, end)
593 rtx start, end;
595 while (1)
597 debug_rtx (start);
598 if (!start || start == end)
599 break;
600 start = NEXT_INSN (start);
604 /* Call this function to search an rtx list to find one with insn uid UID,
605 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
606 The found insn is returned to enable further debugging analysis. */
609 debug_rtx_find (x, uid)
610 rtx x;
611 int uid;
613 while (x != 0 && INSN_UID (x) != uid)
614 x = NEXT_INSN (x);
615 if (x != 0)
617 debug_rtx_list (x, debug_rtx_count);
618 return x;
620 else
622 fprintf (stderr, "insn uid %d not found\n", uid);
623 return 0;
627 /* External entry point for printing a chain of insns
628 starting with RTX_FIRST onto file OUTF.
629 A blank line separates insns.
631 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
633 void
634 print_rtl (outf, rtx_first)
635 FILE *outf;
636 rtx rtx_first;
638 register rtx tmp_rtx;
640 outfile = outf;
641 sawclose = 0;
643 if (rtx_first == 0)
645 fputs (print_rtx_head, outf);
646 fputs ("(nil)\n", outf);
648 else
649 switch (GET_CODE (rtx_first))
651 case INSN:
652 case JUMP_INSN:
653 case CALL_INSN:
654 case NOTE:
655 case CODE_LABEL:
656 case BARRIER:
657 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
658 if (! flag_dump_unnumbered
659 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
661 fputs (print_rtx_head, outfile);
662 print_rtx (tmp_rtx);
663 fprintf (outfile, "\n");
665 break;
667 default:
668 fputs (print_rtx_head, outfile);
669 print_rtx (rtx_first);
673 /* Like print_rtx, except specify a file. */
674 /* Return nonzero if we actually printed anything. */
677 print_rtl_single (outf, x)
678 FILE *outf;
679 rtx x;
681 outfile = outf;
682 sawclose = 0;
683 if (! flag_dump_unnumbered
684 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
686 fputs (print_rtx_head, outfile);
687 print_rtx (x);
688 putc ('\n', outf);
689 return 1;
691 return 0;
695 /* Like print_rtl except without all the detail; for example,
696 if RTX is a CONST_INT then print in decimal format. */
698 void
699 print_simple_rtl (outf, x)
700 FILE *outf;
701 rtx x;
703 flag_simple = 1;
704 print_rtl (outf, x);
705 flag_simple = 0;