2001-01-23 Alexandre Petit-Bianco <apbianco@cygnus.com>
[official-gcc.git] / gcc / print-rtl.c
blob23d889a873ba34948be1935ec170a7f3aa37b16f
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':
326 register int value = XINT (in_rtx, i);
327 const char *name;
329 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
331 fputc (' ', outfile);
332 DEBUG_PRINT_REG (in_rtx, 0, outfile);
334 else if (GET_CODE (in_rtx) == REG && value <= LAST_VIRTUAL_REGISTER)
336 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
337 fprintf (outfile, " %d virtual-incoming-args", value);
338 else if (value == VIRTUAL_STACK_VARS_REGNUM)
339 fprintf (outfile, " %d virtual-stack-vars", value);
340 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
341 fprintf (outfile, " %d virtual-stack-dynamic", value);
342 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
343 fprintf (outfile, " %d virtual-outgoing-args", value);
344 else if (value == VIRTUAL_CFA_REGNUM)
345 fprintf (outfile, " %d virtual-cfa", value);
346 else
347 fprintf (outfile, " %d virtual-reg-%d", value,
348 value-FIRST_VIRTUAL_REGISTER);
350 else if (flag_dump_unnumbered
351 && (is_insn || GET_CODE (in_rtx) == NOTE))
352 fputc ('#', outfile);
353 else
354 fprintf (outfile, " %d", value);
356 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
357 && XINT (in_rtx, i) >= 0
358 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
359 fprintf (outfile, " {%s}", name);
360 sawclose = 0;
362 break;
364 /* Print NOTE_INSN names rather than integer codes. */
366 case 'n':
367 if (XINT (in_rtx, i) >= NOTE_INSN_BIAS
368 && XINT (in_rtx, i) < NOTE_INSN_MAX)
369 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
370 else
371 fprintf (outfile, " %d", XINT (in_rtx, i));
372 sawclose = 0;
373 break;
375 case 'u':
376 if (XEXP (in_rtx, i) != NULL)
378 rtx sub = XEXP (in_rtx, i);
379 enum rtx_code subc = GET_CODE (sub);
381 if (GET_CODE (in_rtx) == LABEL_REF)
383 if (subc == NOTE
384 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
386 if (flag_dump_unnumbered)
387 fprintf (outfile, " [# deleted]");
388 else
389 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
390 sawclose = 0;
391 break;
394 if (subc != CODE_LABEL)
395 goto do_e;
398 if (flag_dump_unnumbered)
399 fputs (" #", outfile);
400 else
401 fprintf (outfile, " %d", INSN_UID (sub));
403 else
404 fputs (" 0", outfile);
405 sawclose = 0;
406 break;
408 case 'b':
409 if (XBITMAP (in_rtx, i) == NULL)
410 fputs (" {null}", outfile);
411 else
412 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
413 sawclose = 0;
414 break;
416 case 't':
417 putc (' ', outfile);
418 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
419 break;
421 case '*':
422 fputs (" Unknown", outfile);
423 sawclose = 0;
424 break;
426 default:
427 fprintf (stderr,
428 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
429 format_ptr[-1]);
430 abort ();
433 switch (GET_CODE (in_rtx))
435 case MEM:
436 fputc (' ', outfile);
437 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
438 break;
440 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
441 case CONST_DOUBLE:
442 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
444 double val;
445 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
446 fprintf (outfile, " [%.16g]", val);
448 break;
449 #endif
451 case CODE_LABEL:
452 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
453 if (LABEL_ALTERNATE_NAME (in_rtx))
454 fprintf (outfile, " [alternate name: %s]",
455 LABEL_ALTERNATE_NAME (in_rtx));
456 break;
458 case CALL_PLACEHOLDER:
459 if (debug_call_placeholder_verbose)
461 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile);
462 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
464 fputs ("\n ", outfile);
465 print_inline_rtx (outfile, tem, 4);
468 tem = XEXP (in_rtx, 1);
469 if (tem)
470 fputs ("\n ])\n (const_string \"tail_call\") (sequence [", outfile);
471 for (; tem != 0; tem = NEXT_INSN (tem))
473 fputs ("\n ", outfile);
474 print_inline_rtx (outfile, tem, 4);
477 tem = XEXP (in_rtx, 2);
478 if (tem)
479 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [", outfile);
480 for (; tem != 0; tem = NEXT_INSN (tem))
482 fputs ("\n ", outfile);
483 print_inline_rtx (outfile, tem, 4);
486 fputs ("\n ])\n ])", outfile);
487 break;
490 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
491 if (GET_CODE (tem) == CALL_INSN)
493 fprintf (outfile, " ");
494 print_rtx (tem);
495 break;
497 break;
499 default:
500 break;
503 if (dump_for_graph
504 && (is_insn || GET_CODE (in_rtx) == NOTE
505 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
506 sawclose = 0;
507 else
509 fputc (')', outfile);
510 sawclose = 1;
514 /* Print an rtx on the current line of FILE. Initially indent IND
515 characters. */
517 void
518 print_inline_rtx (outf, x, ind)
519 FILE *outf;
520 rtx x;
521 int ind;
523 int oldsaw = sawclose;
524 int oldindent = indent;
526 sawclose = 0;
527 indent = ind;
528 outfile = outf;
529 print_rtx (x);
530 sawclose = oldsaw;
531 indent = oldindent;
534 /* Call this function from the debugger to see what X looks like. */
536 void
537 debug_rtx (x)
538 rtx x;
540 outfile = stderr;
541 print_rtx (x);
542 fprintf (stderr, "\n");
545 /* Count of rtx's to print with debug_rtx_list.
546 This global exists because gdb user defined commands have no arguments. */
548 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
550 /* Call this function to print list from X on.
552 N is a count of the rtx's to print. Positive values print from the specified
553 rtx on. Negative values print a window around the rtx.
554 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
556 void
557 debug_rtx_list (x, n)
558 rtx x;
559 int n;
561 int i,count;
562 rtx insn;
564 count = n == 0 ? 1 : n < 0 ? -n : n;
566 /* If we are printing a window, back up to the start. */
568 if (n < 0)
569 for (i = count / 2; i > 0; i--)
571 if (PREV_INSN (x) == 0)
572 break;
573 x = PREV_INSN (x);
576 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
577 debug_rtx (insn);
580 /* Call this function to print an rtx list from START to END inclusive. */
582 void
583 debug_rtx_range (start, end)
584 rtx start, end;
586 while (1)
588 debug_rtx (start);
589 if (!start || start == end)
590 break;
591 start = NEXT_INSN (start);
595 /* Call this function to search an rtx list to find one with insn uid UID,
596 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
597 The found insn is returned to enable further debugging analysis. */
600 debug_rtx_find (x, uid)
601 rtx x;
602 int uid;
604 while (x != 0 && INSN_UID (x) != uid)
605 x = NEXT_INSN (x);
606 if (x != 0)
608 debug_rtx_list (x, debug_rtx_count);
609 return x;
611 else
613 fprintf (stderr, "insn uid %d not found\n", uid);
614 return 0;
618 /* External entry point for printing a chain of insns
619 starting with RTX_FIRST onto file OUTF.
620 A blank line separates insns.
622 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
624 void
625 print_rtl (outf, rtx_first)
626 FILE *outf;
627 rtx rtx_first;
629 register rtx tmp_rtx;
631 outfile = outf;
632 sawclose = 0;
634 if (rtx_first == 0)
636 fputs (print_rtx_head, outf);
637 fputs ("(nil)\n", outf);
639 else
640 switch (GET_CODE (rtx_first))
642 case INSN:
643 case JUMP_INSN:
644 case CALL_INSN:
645 case NOTE:
646 case CODE_LABEL:
647 case BARRIER:
648 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
649 if (! flag_dump_unnumbered
650 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
652 fputs (print_rtx_head, outfile);
653 print_rtx (tmp_rtx);
654 fprintf (outfile, "\n");
656 break;
658 default:
659 fputs (print_rtx_head, outfile);
660 print_rtx (rtx_first);
664 /* Like print_rtx, except specify a file. */
665 /* Return nonzero if we actually printed anything. */
668 print_rtl_single (outf, x)
669 FILE *outf;
670 rtx x;
672 outfile = outf;
673 sawclose = 0;
674 if (! flag_dump_unnumbered
675 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
677 fputs (print_rtx_head, outfile);
678 print_rtx (x);
679 putc ('\n', outf);
680 return 1;
682 return 0;
686 /* Like print_rtl except without all the detail; for example,
687 if RTX is a CONST_INT then print in decimal format. */
689 void
690 print_simple_rtl (outf, x)
691 FILE *outf;
692 rtx x;
694 flag_simple = 1;
695 print_rtl (outf, x);
696 flag_simple = 0;