print-rtl.c (print_rtx): For CALL_PLACEHOLDER, output the CALL_INSN from the normal...
[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 "basic-block.h"
29
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 reg_names[] = DEBUG_REGISTER_NAMES;
43 #else
44 static const char * const reg_names[] = REGISTER_NAMES;
45 #endif
46
47 static FILE *outfile;
48
49 static const char xspaces[] = " ";
50
51 static int sawclose = 0;
52
53 static int indent;
54
55 static void print_rtx PARAMS ((rtx));
56
57 /* Nonzero means suppress output of instruction numbers and line number
58 notes in debugging dumps.
59 This must be defined here so that programs like gencodes can be linked. */
60 int flag_dump_unnumbered = 0;
61
62 /* Nonzero if we are dumping graphical description. */
63 int dump_for_graph;
64
65 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
66
67 static void
68 print_rtx (in_rtx)
69 register rtx in_rtx;
70 {
71 register int i = 0;
72 register int j;
73 register const char *format_ptr;
74 register int is_insn;
75 rtx tem;
76
77 if (sawclose)
78 {
79 fprintf (outfile, "\n%s",
80 (xspaces + (sizeof xspaces - 1 - indent * 2)));
81 sawclose = 0;
82 }
83
84 if (in_rtx == 0)
85 {
86 fputs ("(nil)", outfile);
87 sawclose = 1;
88 return;
89 }
90
91 is_insn = (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i');
92
93 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
94 in separate nodes and therefore have to handle them special here. */
95 if (dump_for_graph &&
96 (is_insn || GET_CODE (in_rtx) == NOTE || GET_CODE (in_rtx) == CODE_LABEL
97 || GET_CODE (in_rtx) == BARRIER))
98 {
99 i = 3;
100 indent = 0;
101 }
102 else
103 {
104 /* print name of expression code */
105 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
106
107 if (in_rtx->in_struct)
108 fputs ("/s", outfile);
109
110 if (in_rtx->volatil)
111 fputs ("/v", outfile);
112
113 if (in_rtx->unchanging)
114 fputs ("/u", outfile);
115
116 if (in_rtx->integrated)
117 fputs ("/i", outfile);
118
119 if (in_rtx->frame_related)
120 fputs ("/f", outfile);
121
122 if (in_rtx->jump)
123 fputs ("/j", outfile);
124
125 if (in_rtx->call)
126 fputs ("/c", outfile);
127
128 if (GET_MODE (in_rtx) != VOIDmode)
129 {
130 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
131 if (GET_CODE (in_rtx) == EXPR_LIST || GET_CODE (in_rtx) == INSN_LIST)
132 fprintf (outfile, ":%s", GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
133 else
134 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
135 }
136 }
137
138 /* Get the format string and skip the first elements if we have handled
139 them already. */
140 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
141
142 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
143 switch (*format_ptr++)
144 {
145 case 'S':
146 case 's':
147 if (XSTR (in_rtx, i) == 0)
148 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
149 else
150 {
151 if (dump_for_graph)
152 fprintf (outfile, " (\\\"%s\\\")", XSTR (in_rtx, i));
153 else
154 fprintf (outfile, " (\"%s\")", XSTR (in_rtx, i));
155 }
156 sawclose = 1;
157 break;
158
159 /* 0 indicates a field for internal use that should not be printed.
160 An exception is the third field of a NOTE, where it indicates
161 that the field has several different valid contents. */
162 case '0':
163 if (i == 3 && GET_CODE (in_rtx) == NOTE)
164 {
165 if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_EH_REGION_BEG
166 || NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_EH_REGION_END)
167 {
168 if (flag_dump_unnumbered)
169 fprintf (outfile, " #");
170 else
171 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
172 sawclose = 1;
173 }
174 else if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_BLOCK_BEG
175 || NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_BLOCK_END)
176 {
177 fprintf (outfile, " ");
178 if (flag_dump_unnumbered)
179 fprintf (outfile, "#");
180 else
181 fprintf (outfile, HOST_PTR_PRINTF,
182 (char *) NOTE_BLOCK (in_rtx));
183 sawclose = 1;
184 }
185 else if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_RANGE_START
186 || NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_RANGE_END
187 || NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_LIVE)
188 {
189 indent += 2;
190 if (!sawclose)
191 fprintf (outfile, " ");
192 print_rtx (NOTE_RANGE_INFO (in_rtx));
193 indent -= 2;
194 }
195 else if (NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_BASIC_BLOCK)
196 {
197 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
198 fprintf (outfile, " [bb %d]", bb->index);
199 }
200 else
201 {
202 const char * const str = X0STR (in_rtx, i);
203 if (str == 0)
204 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
205 else
206 {
207 if (dump_for_graph)
208 fprintf (outfile, " (\\\"%s\\\")", str);
209 else
210 fprintf (outfile, " (\"%s\")", str);
211 }
212 }
213 }
214 break;
215
216 case 'e':
217 do_e:
218 indent += 2;
219 if (!sawclose)
220 fprintf (outfile, " ");
221 print_rtx (XEXP (in_rtx, i));
222 indent -= 2;
223 break;
224
225 case 'E':
226 case 'V':
227 indent += 2;
228 if (sawclose)
229 {
230 fprintf (outfile, "\n%s",
231 (xspaces + (sizeof xspaces - 1 - indent * 2)));
232 sawclose = 0;
233 }
234 fputs ("[ ", outfile);
235 if (NULL != XVEC (in_rtx, i))
236 {
237 indent += 2;
238 if (XVECLEN (in_rtx, i))
239 sawclose = 1;
240
241 for (j = 0; j < XVECLEN (in_rtx, i); j++)
242 print_rtx (XVECEXP (in_rtx, i, j));
243
244 indent -= 2;
245 }
246 if (sawclose)
247 fprintf (outfile, "\n%s",
248 (xspaces + (sizeof xspaces - 1 - indent * 2)));
249
250 fputs ("] ", outfile);
251 sawclose = 1;
252 indent -= 2;
253 break;
254
255 case 'w':
256 fprintf (outfile, " ");
257 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
258 fprintf (outfile, " [");
259 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
260 fprintf (outfile, "]");
261 break;
262
263 case 'i':
264 {
265 register int value = XINT (in_rtx, i);
266 const char *name;
267
268 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
269 {
270 fputc (' ', outfile);
271 DEBUG_PRINT_REG (in_rtx, 0, outfile);
272 }
273 else if (GET_CODE (in_rtx) == REG && value <= LAST_VIRTUAL_REGISTER)
274 {
275 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
276 fprintf (outfile, " %d virtual-incoming-args", value);
277 else if (value == VIRTUAL_STACK_VARS_REGNUM)
278 fprintf (outfile, " %d virtual-stack-vars", value);
279 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
280 fprintf (outfile, " %d virtual-stack-dynamic", value);
281 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
282 fprintf (outfile, " %d virtual-outgoing-args", value);
283 else if (value == VIRTUAL_CFA_REGNUM)
284 fprintf (outfile, " %d virtual-cfa", value);
285 else
286 fprintf (outfile, " %d virtual-reg-%d", value,
287 value-FIRST_VIRTUAL_REGISTER);
288 }
289 else if (flag_dump_unnumbered
290 && (is_insn || GET_CODE (in_rtx) == NOTE))
291 fputc ('#', outfile);
292 else
293 fprintf (outfile, " %d", value);
294
295 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
296 && XINT (in_rtx, i) >= 0
297 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
298 fprintf (outfile, " {%s}", name);
299 sawclose = 0;
300 }
301 break;
302
303 /* Print NOTE_INSN names rather than integer codes. */
304
305 case 'n':
306 if (XINT (in_rtx, i) <= 0)
307 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
308 else
309 fprintf (outfile, " %d", XINT (in_rtx, i));
310 sawclose = 0;
311 break;
312
313 case 'u':
314 if (XEXP (in_rtx, i) != NULL)
315 {
316 rtx sub = XEXP (in_rtx, i);
317 enum rtx_code subc = GET_CODE (sub);
318
319 if (GET_CODE (in_rtx) == LABEL_REF && subc != CODE_LABEL)
320 goto do_e;
321
322 if (flag_dump_unnumbered)
323 fputc ('#', outfile);
324 else
325 fprintf (outfile, " %d", INSN_UID (sub));
326 }
327 else
328 fputs (" 0", outfile);
329 sawclose = 0;
330 break;
331
332 case 'b':
333 if (XBITMAP (in_rtx, i) == NULL)
334 fputs (" {null}", outfile);
335 else
336 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
337 sawclose = 0;
338 break;
339
340 case 't':
341 putc (' ', outfile);
342 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
343 break;
344
345 case '*':
346 fputs (" Unknown", outfile);
347 sawclose = 0;
348 break;
349
350 default:
351 fprintf (stderr,
352 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
353 format_ptr[-1]);
354 abort ();
355 }
356
357 if (GET_CODE (in_rtx) == MEM)
358 fprintf (outfile, " %d", MEM_ALIAS_SET (in_rtx));
359
360 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
361 if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
362 {
363 double val;
364 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
365 fprintf (outfile, " [%.16g]", val);
366 }
367 #endif
368
369 if (GET_CODE (in_rtx) == CODE_LABEL)
370 {
371 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
372 if (LABEL_ALTERNATE_NAME (in_rtx))
373 fprintf (outfile, " [alternate name: %s]",
374 LABEL_ALTERNATE_NAME (in_rtx));
375 }
376
377 if (GET_CODE (in_rtx) == CALL_PLACEHOLDER)
378 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
379 if (GET_CODE (tem) == CALL_INSN)
380 {
381 fprintf (outfile, " ");
382 print_rtx (tem);
383 break;
384 }
385
386 if (dump_for_graph
387 && (is_insn || GET_CODE (in_rtx) == NOTE
388 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
389 sawclose = 0;
390 else
391 {
392 fputc (')', outfile);
393 sawclose = 1;
394 }
395 }
396
397 /* Print an rtx on the current line of FILE. Initially indent IND
398 characters. */
399
400 void
401 print_inline_rtx (outf, x, ind)
402 FILE *outf;
403 rtx x;
404 int ind;
405 {
406 int oldsaw = sawclose;
407 int oldindent = indent;
408
409 sawclose = 0;
410 indent = ind;
411 outfile = outf;
412 print_rtx (x);
413 sawclose = oldsaw;
414 indent = oldindent;
415 }
416
417 /* Call this function from the debugger to see what X looks like. */
418
419 void
420 debug_rtx (x)
421 rtx x;
422 {
423 outfile = stderr;
424 print_rtx (x);
425 fprintf (stderr, "\n");
426 }
427
428 /* Count of rtx's to print with debug_rtx_list.
429 This global exists because gdb user defined commands have no arguments. */
430
431 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
432
433 /* Call this function to print list from X on.
434
435 N is a count of the rtx's to print. Positive values print from the specified
436 rtx on. Negative values print a window around the rtx.
437 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
438
439 void
440 debug_rtx_list (x, n)
441 rtx x;
442 int n;
443 {
444 int i,count;
445 rtx insn;
446
447 count = n == 0 ? 1 : n < 0 ? -n : n;
448
449 /* If we are printing a window, back up to the start. */
450
451 if (n < 0)
452 for (i = count / 2; i > 0; i--)
453 {
454 if (PREV_INSN (x) == 0)
455 break;
456 x = PREV_INSN (x);
457 }
458
459 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
460 debug_rtx (insn);
461 }
462
463 /* Call this function to print an rtx list from START to END inclusive. */
464
465 void
466 debug_rtx_range (start, end)
467 rtx start, end;
468 {
469 while (1)
470 {
471 debug_rtx (start);
472 if (!start || start == end)
473 break;
474 start = NEXT_INSN (start);
475 }
476 }
477
478 /* Call this function to search an rtx list to find one with insn uid UID,
479 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
480 The found insn is returned to enable further debugging analysis. */
481
482 rtx
483 debug_rtx_find (x, uid)
484 rtx x;
485 int uid;
486 {
487 while (x != 0 && INSN_UID (x) != uid)
488 x = NEXT_INSN (x);
489 if (x != 0)
490 {
491 debug_rtx_list (x, debug_rtx_count);
492 return x;
493 }
494 else
495 {
496 fprintf (stderr, "insn uid %d not found\n", uid);
497 return 0;
498 }
499 }
500
501 /* External entry point for printing a chain of insns
502 starting with RTX_FIRST onto file OUTF.
503 A blank line separates insns.
504
505 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
506
507 void
508 print_rtl (outf, rtx_first)
509 FILE *outf;
510 rtx rtx_first;
511 {
512 register rtx tmp_rtx;
513
514 outfile = outf;
515 sawclose = 0;
516
517 if (rtx_first == 0)
518 fputs ("(nil)\n", outf);
519 else
520 switch (GET_CODE (rtx_first))
521 {
522 case INSN:
523 case JUMP_INSN:
524 case CALL_INSN:
525 case NOTE:
526 case CODE_LABEL:
527 case BARRIER:
528 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
529 if (! flag_dump_unnumbered
530 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
531 {
532 print_rtx (tmp_rtx);
533 fprintf (outfile, "\n");
534 }
535 break;
536
537 default:
538 print_rtx (rtx_first);
539 }
540 }
541
542 /* Like print_rtx, except specify a file. */
543 /* Return nonzero if we actually printed anything. */
544
545 int
546 print_rtl_single (outf, x)
547 FILE *outf;
548 rtx x;
549 {
550 outfile = outf;
551 sawclose = 0;
552 if (! flag_dump_unnumbered
553 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
554 {
555 print_rtx (x);
556 putc ('\n', outf);
557 return 1;
558 }
559 return 0;
560 }