print-rtl.c (xspaces): Remove.
[gcc.git] / gcc / print-rtl.c
1 /* Print RTL for GNU C Compiler.
2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
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.
11
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.
16
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. */
21
22
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"
30
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
38
39 /* Array containing all of the register names */
40
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
47
48 static FILE *outfile;
49
50 static int sawclose = 0;
51
52 static int indent;
53
54 static void print_rtx PARAMS ((rtx));
55
56 /* String printed at beginning of each RTL when it is dumped.
57 This string is set to ASM_COMMENT_START when the RTL is dumped in
58 the assembly output file. */
59 const char *print_rtx_head = "";
60
61 /* Nonzero means suppress output of instruction numbers and line number
62 notes in debugging dumps.
63 This must be defined here so that programs like gencodes can be linked. */
64 int flag_dump_unnumbered = 0;
65
66 /* Nonzero means use simplified format without flags, modes, etc. */
67 int flag_simple = 0;
68
69 /* Nonzero if we are dumping graphical description. */
70 int dump_for_graph;
71
72 /* Nonzero to dump all call_placeholder alternatives. */
73 static int debug_call_placeholder_verbose;
74
75 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
76
77 static void
78 print_rtx (in_rtx)
79 register rtx in_rtx;
80 {
81 register int i = 0;
82 register int j;
83 register const char *format_ptr;
84 register int is_insn;
85 rtx tem;
86
87 if (sawclose)
88 {
89 if (flag_simple)
90 fputc (' ', outfile);
91 else
92 fprintf (outfile, "\n%s%*s",
93 print_rtx_head, indent * 2, "");
94 sawclose = 0;
95 }
96
97 if (in_rtx == 0)
98 {
99 fputs ("(nil)", outfile);
100 sawclose = 1;
101 return;
102 }
103
104 is_insn = (INSN_P (in_rtx));
105
106 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
107 in separate nodes and therefore have to handle them special here. */
108 if (dump_for_graph &&
109 (is_insn || GET_CODE (in_rtx) == NOTE || GET_CODE (in_rtx) == CODE_LABEL
110 || GET_CODE (in_rtx) == BARRIER))
111 {
112 i = 3;
113 indent = 0;
114 }
115 else
116 {
117 /* print name of expression code */
118 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
119 fputc ('(', outfile);
120 else
121 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
122
123 if (! flag_simple)
124 {
125 if (in_rtx->in_struct)
126 fputs ("/s", outfile);
127
128 if (in_rtx->volatil)
129 fputs ("/v", outfile);
130
131 if (in_rtx->unchanging)
132 fputs ("/u", outfile);
133
134 if (in_rtx->integrated)
135 fputs ("/i", outfile);
136
137 if (in_rtx->frame_related)
138 fputs ("/f", outfile);
139
140 if (in_rtx->jump)
141 fputs ("/j", outfile);
142
143 if (in_rtx->call)
144 fputs ("/c", outfile);
145
146 if (GET_MODE (in_rtx) != VOIDmode)
147 {
148 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
149 if (GET_CODE (in_rtx) == EXPR_LIST
150 || GET_CODE (in_rtx) == INSN_LIST)
151 fprintf (outfile, ":%s",
152 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
153 else
154 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
155 }
156 }
157 }
158
159 /* Get the format string and skip the first elements if we have handled
160 them already. */
161 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
162
163 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
164 switch (*format_ptr++)
165 {
166 case 'S':
167 case 's':
168 if (XSTR (in_rtx, i) == 0)
169 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
170 else
171 {
172 if (dump_for_graph)
173 fprintf (outfile, " (\\\"%s\\\")", XSTR (in_rtx, i));
174 else
175 fprintf (outfile, " (\"%s\")", XSTR (in_rtx, i));
176 }
177 sawclose = 1;
178 break;
179
180 /* 0 indicates a field for internal use that should not be printed.
181 An exception is the third field of a NOTE, where it indicates
182 that the field has several different valid contents. */
183 case '0':
184 if (i == 1 && GET_CODE (in_rtx) == REG)
185 {
186 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
187 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
188 break;
189 }
190 if (i == 3 && GET_CODE (in_rtx) == NOTE)
191 {
192 switch (NOTE_LINE_NUMBER (in_rtx))
193 {
194 case NOTE_INSN_EH_REGION_BEG:
195 case NOTE_INSN_EH_REGION_END:
196 if (flag_dump_unnumbered)
197 fprintf (outfile, " #");
198 else
199 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
200 sawclose = 1;
201 break;
202
203 case NOTE_INSN_BLOCK_BEG:
204 case NOTE_INSN_BLOCK_END:
205 fprintf (outfile, " ");
206 if (flag_dump_unnumbered)
207 fprintf (outfile, "#");
208 else
209 fprintf (outfile, HOST_PTR_PRINTF,
210 (char *) NOTE_BLOCK (in_rtx));
211 sawclose = 1;
212 break;
213
214 case NOTE_INSN_RANGE_BEG:
215 case NOTE_INSN_RANGE_END:
216 case NOTE_INSN_LIVE:
217 indent += 2;
218 if (!sawclose)
219 fprintf (outfile, " ");
220 print_rtx (NOTE_RANGE_INFO (in_rtx));
221 indent -= 2;
222 break;
223
224 case NOTE_INSN_BASIC_BLOCK:
225 {
226 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
227 if (bb != 0)
228 fprintf (outfile, " [bb %d]", bb->index);
229 break;
230 }
231
232 case NOTE_INSN_EXPECTED_VALUE:
233 indent += 2;
234 if (!sawclose)
235 fprintf (outfile, " ");
236 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
237 indent -= 2;
238 break;
239
240 case NOTE_INSN_DELETED_LABEL:
241 if (NOTE_SOURCE_FILE (in_rtx))
242 fprintf (outfile, " (\"%s\")", NOTE_SOURCE_FILE (in_rtx));
243 else
244 fprintf (outfile, " \"\"");
245 break;
246
247 default:
248 {
249 const char * const str = X0STR (in_rtx, i);
250
251 if (NOTE_LINE_NUMBER (in_rtx) < 0)
252 ;
253 else if (str == 0)
254 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
255 else
256 {
257 if (dump_for_graph)
258 fprintf (outfile, " (\\\"%s\\\")", str);
259 else
260 fprintf (outfile, " (\"%s\")", str);
261 }
262 break;
263 }
264 }
265 }
266 break;
267
268 case 'e':
269 do_e:
270 indent += 2;
271 if (!sawclose)
272 fprintf (outfile, " ");
273 print_rtx (XEXP (in_rtx, i));
274 indent -= 2;
275 break;
276
277 case 'E':
278 case 'V':
279 indent += 2;
280 if (sawclose)
281 {
282 fprintf (outfile, "\n%s%*s",
283 print_rtx_head, indent * 2, "");
284 sawclose = 0;
285 }
286 fputs ("[ ", outfile);
287 if (NULL != XVEC (in_rtx, i))
288 {
289 indent += 2;
290 if (XVECLEN (in_rtx, i))
291 sawclose = 1;
292
293 for (j = 0; j < XVECLEN (in_rtx, i); j++)
294 print_rtx (XVECEXP (in_rtx, i, j));
295
296 indent -= 2;
297 }
298 if (sawclose)
299 fprintf (outfile, "\n%s%*s",
300 print_rtx_head, indent * 2, "");
301
302 fputs ("] ", outfile);
303 sawclose = 1;
304 indent -= 2;
305 break;
306
307 case 'w':
308 if (! flag_simple)
309 fprintf (outfile, " ");
310 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
311 if (! flag_simple)
312 {
313 fprintf (outfile, " [");
314 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
315 fprintf (outfile, "]");
316 }
317 break;
318
319 case 'i':
320 if (i == 5 && GET_CODE (in_rtx) == NOTE)
321 {
322 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
323 other times often contains garbage from INSN->NOTE death. */
324 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_DELETED_LABEL)
325 fprintf (outfile, " %d", XINT (in_rtx, i));
326 }
327 else
328 {
329 register int value = XINT (in_rtx, i);
330 const char *name;
331
332 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
333 {
334 fputc (' ', outfile);
335 DEBUG_PRINT_REG (in_rtx, 0, outfile);
336 }
337 else if (GET_CODE (in_rtx) == REG
338 && value <= LAST_VIRTUAL_REGISTER)
339 {
340 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
341 fprintf (outfile, " %d virtual-incoming-args", value);
342 else if (value == VIRTUAL_STACK_VARS_REGNUM)
343 fprintf (outfile, " %d virtual-stack-vars", value);
344 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
345 fprintf (outfile, " %d virtual-stack-dynamic", value);
346 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
347 fprintf (outfile, " %d virtual-outgoing-args", value);
348 else if (value == VIRTUAL_CFA_REGNUM)
349 fprintf (outfile, " %d virtual-cfa", value);
350 else
351 fprintf (outfile, " %d virtual-reg-%d", value,
352 value-FIRST_VIRTUAL_REGISTER);
353 }
354 else if (flag_dump_unnumbered
355 && (is_insn || GET_CODE (in_rtx) == NOTE))
356 fputc ('#', outfile);
357 else
358 fprintf (outfile, " %d", value);
359
360 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
361 && XINT (in_rtx, i) >= 0
362 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
363 fprintf (outfile, " {%s}", name);
364 sawclose = 0;
365 }
366 break;
367
368 /* Print NOTE_INSN names rather than integer codes. */
369
370 case 'n':
371 if (XINT (in_rtx, i) >= (int) NOTE_INSN_BIAS
372 && XINT (in_rtx, i) < (int) NOTE_INSN_MAX)
373 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
374 else
375 fprintf (outfile, " %d", XINT (in_rtx, i));
376 sawclose = 0;
377 break;
378
379 case 'u':
380 if (XEXP (in_rtx, i) != NULL)
381 {
382 rtx sub = XEXP (in_rtx, i);
383 enum rtx_code subc = GET_CODE (sub);
384
385 if (GET_CODE (in_rtx) == LABEL_REF)
386 {
387 if (subc == NOTE
388 && NOTE_LINE_NUMBER (sub) == NOTE_INSN_DELETED_LABEL)
389 {
390 if (flag_dump_unnumbered)
391 fprintf (outfile, " [# deleted]");
392 else
393 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
394 sawclose = 0;
395 break;
396 }
397
398 if (subc != CODE_LABEL)
399 goto do_e;
400 }
401
402 if (flag_dump_unnumbered)
403 fputs (" #", outfile);
404 else
405 fprintf (outfile, " %d", INSN_UID (sub));
406 }
407 else
408 fputs (" 0", outfile);
409 sawclose = 0;
410 break;
411
412 case 'b':
413 if (XBITMAP (in_rtx, i) == NULL)
414 fputs (" {null}", outfile);
415 else
416 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
417 sawclose = 0;
418 break;
419
420 case 't':
421 putc (' ', outfile);
422 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
423 break;
424
425 case '*':
426 fputs (" Unknown", outfile);
427 sawclose = 0;
428 break;
429
430 default:
431 fprintf (stderr,
432 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
433 format_ptr[-1]);
434 abort ();
435 }
436
437 switch (GET_CODE (in_rtx))
438 {
439 case MEM:
440 fputc (' ', outfile);
441 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, MEM_ALIAS_SET (in_rtx));
442 break;
443
444 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
445 case CONST_DOUBLE:
446 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
447 {
448 double val;
449 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
450 fprintf (outfile, " [%.16g]", val);
451 }
452 break;
453 #endif
454
455 case CODE_LABEL:
456 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
457 if (LABEL_ALTERNATE_NAME (in_rtx))
458 fprintf (outfile, " [alternate name: %s]",
459 LABEL_ALTERNATE_NAME (in_rtx));
460 break;
461
462 case CALL_PLACEHOLDER:
463 if (debug_call_placeholder_verbose)
464 {
465 fputs (" (cond [\n (const_string \"normal\") (sequence [", outfile);
466 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
467 {
468 fputs ("\n ", outfile);
469 print_inline_rtx (outfile, tem, 4);
470 }
471
472 tem = XEXP (in_rtx, 1);
473 if (tem)
474 fputs ("\n ])\n (const_string \"tail_call\") (sequence [", outfile);
475 for (; tem != 0; tem = NEXT_INSN (tem))
476 {
477 fputs ("\n ", outfile);
478 print_inline_rtx (outfile, tem, 4);
479 }
480
481 tem = XEXP (in_rtx, 2);
482 if (tem)
483 fputs ("\n ])\n (const_string \"tail_recursion\") (sequence [", outfile);
484 for (; tem != 0; tem = NEXT_INSN (tem))
485 {
486 fputs ("\n ", outfile);
487 print_inline_rtx (outfile, tem, 4);
488 }
489
490 fputs ("\n ])\n ])", outfile);
491 break;
492 }
493
494 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
495 if (GET_CODE (tem) == CALL_INSN)
496 {
497 fprintf (outfile, " ");
498 print_rtx (tem);
499 break;
500 }
501 break;
502
503 default:
504 break;
505 }
506
507 if (dump_for_graph
508 && (is_insn || GET_CODE (in_rtx) == NOTE
509 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
510 sawclose = 0;
511 else
512 {
513 fputc (')', outfile);
514 sawclose = 1;
515 }
516 }
517
518 /* Print an rtx on the current line of FILE. Initially indent IND
519 characters. */
520
521 void
522 print_inline_rtx (outf, x, ind)
523 FILE *outf;
524 rtx x;
525 int ind;
526 {
527 int oldsaw = sawclose;
528 int oldindent = indent;
529
530 sawclose = 0;
531 indent = ind;
532 outfile = outf;
533 print_rtx (x);
534 sawclose = oldsaw;
535 indent = oldindent;
536 }
537
538 /* Call this function from the debugger to see what X looks like. */
539
540 void
541 debug_rtx (x)
542 rtx x;
543 {
544 outfile = stderr;
545 print_rtx (x);
546 fprintf (stderr, "\n");
547 }
548
549 /* Count of rtx's to print with debug_rtx_list.
550 This global exists because gdb user defined commands have no arguments. */
551
552 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
553
554 /* Call this function to print list from X on.
555
556 N is a count of the rtx's to print. Positive values print from the specified
557 rtx on. Negative values print a window around the rtx.
558 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
559
560 void
561 debug_rtx_list (x, n)
562 rtx x;
563 int n;
564 {
565 int i,count;
566 rtx insn;
567
568 count = n == 0 ? 1 : n < 0 ? -n : n;
569
570 /* If we are printing a window, back up to the start. */
571
572 if (n < 0)
573 for (i = count / 2; i > 0; i--)
574 {
575 if (PREV_INSN (x) == 0)
576 break;
577 x = PREV_INSN (x);
578 }
579
580 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
581 debug_rtx (insn);
582 }
583
584 /* Call this function to print an rtx list from START to END inclusive. */
585
586 void
587 debug_rtx_range (start, end)
588 rtx start, end;
589 {
590 while (1)
591 {
592 debug_rtx (start);
593 if (!start || start == end)
594 break;
595 start = NEXT_INSN (start);
596 }
597 }
598
599 /* Call this function to search an rtx list to find one with insn uid UID,
600 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
601 The found insn is returned to enable further debugging analysis. */
602
603 rtx
604 debug_rtx_find (x, uid)
605 rtx x;
606 int uid;
607 {
608 while (x != 0 && INSN_UID (x) != uid)
609 x = NEXT_INSN (x);
610 if (x != 0)
611 {
612 debug_rtx_list (x, debug_rtx_count);
613 return x;
614 }
615 else
616 {
617 fprintf (stderr, "insn uid %d not found\n", uid);
618 return 0;
619 }
620 }
621
622 /* External entry point for printing a chain of insns
623 starting with RTX_FIRST onto file OUTF.
624 A blank line separates insns.
625
626 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
627
628 void
629 print_rtl (outf, rtx_first)
630 FILE *outf;
631 rtx rtx_first;
632 {
633 register rtx tmp_rtx;
634
635 outfile = outf;
636 sawclose = 0;
637
638 if (rtx_first == 0)
639 {
640 fputs (print_rtx_head, outf);
641 fputs ("(nil)\n", outf);
642 }
643 else
644 switch (GET_CODE (rtx_first))
645 {
646 case INSN:
647 case JUMP_INSN:
648 case CALL_INSN:
649 case NOTE:
650 case CODE_LABEL:
651 case BARRIER:
652 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
653 if (! flag_dump_unnumbered
654 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
655 {
656 fputs (print_rtx_head, outfile);
657 print_rtx (tmp_rtx);
658 fprintf (outfile, "\n");
659 }
660 break;
661
662 default:
663 fputs (print_rtx_head, outfile);
664 print_rtx (rtx_first);
665 }
666 }
667
668 /* Like print_rtx, except specify a file. */
669 /* Return nonzero if we actually printed anything. */
670
671 int
672 print_rtl_single (outf, x)
673 FILE *outf;
674 rtx x;
675 {
676 outfile = outf;
677 sawclose = 0;
678 if (! flag_dump_unnumbered
679 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
680 {
681 fputs (print_rtx_head, outfile);
682 print_rtx (x);
683 putc ('\n', outf);
684 return 1;
685 }
686 return 0;
687 }
688
689
690 /* Like print_rtl except without all the detail; for example,
691 if RTX is a CONST_INT then print in decimal format. */
692
693 void
694 print_simple_rtl (outf, x)
695 FILE *outf;
696 rtx x;
697 {
698 flag_simple = 1;
699 print_rtl (outf, x);
700 flag_simple = 0;
701 }