]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/print-rtl.c
Oops, missed ChangeLog in last checkin...
[thirdparty/gcc.git] / gcc / print-rtl.c
CommitLineData
e1a79915 1/* Print RTL for GNU C Compiler.
9311a396 2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000
c5c76735 3 Free Software Foundation, Inc.
e1a79915
RS
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
e99215a3
RK
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
e1a79915
RS
21
22
23#include "config.h"
670ee920 24#include "system.h"
e1a79915 25#include "rtl.h"
800d5c9e 26#include "real.h"
b707b450 27#include "flags.h"
e881bb1b 28#include "basic-block.h"
e1a79915
RS
29
30
cf99a734
RS
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
6f7d635c 42static const char * const reg_names[] = DEBUG_REGISTER_NAMES;
cf99a734 43#else
6f7d635c 44static const char * const reg_names[] = REGISTER_NAMES;
cf99a734
RS
45#endif
46
e1a79915
RS
47static FILE *outfile;
48
2778b98d 49static const char xspaces[] = " ";
e1a79915
RS
50
51static int sawclose = 0;
52
1d79197a
RK
53static int indent;
54
957e4763 55static void print_rtx PARAMS ((rtx));
5edc9230 56
b707b450
R
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. */
9ec36da5 60int flag_dump_unnumbered = 0;
b707b450 61
735a0e33
UD
62/* Nonzero if we are dumping graphical description. */
63int dump_for_graph;
64
e1a79915
RS
65/* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
66
67static void
68print_rtx (in_rtx)
69 register rtx in_rtx;
70{
735a0e33
UD
71 register int i = 0;
72 register int j;
6f7d635c 73 register const char *format_ptr;
e1a79915 74 register int is_insn;
c3c63936 75 rtx tem;
e1a79915
RS
76
77 if (sawclose)
78 {
79 fprintf (outfile, "\n%s",
2778b98d 80 (xspaces + (sizeof xspaces - 1 - indent * 2)));
e1a79915
RS
81 sawclose = 0;
82 }
83
84 if (in_rtx == 0)
85 {
735a0e33 86 fputs ("(nil)", outfile);
e1a79915
RS
87 sawclose = 1;
88 return;
89 }
90
735a0e33
UD
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)));
e1a79915 106
735a0e33
UD
107 if (in_rtx->in_struct)
108 fputs ("/s", outfile);
e1a79915 109
735a0e33
UD
110 if (in_rtx->volatil)
111 fputs ("/v", outfile);
e1a79915 112
735a0e33
UD
113 if (in_rtx->unchanging)
114 fputs ("/u", outfile);
e1a79915 115
735a0e33
UD
116 if (in_rtx->integrated)
117 fputs ("/i", outfile);
e1a79915 118
c6df88cb
MM
119 if (in_rtx->frame_related)
120 fputs ("/f", outfile);
121
5a25c64c
JL
122 if (in_rtx->jump)
123 fputs ("/j", outfile);
124
125 if (in_rtx->call)
126 fputs ("/c", outfile);
127
735a0e33
UD
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 }
e1a79915
RS
136 }
137
735a0e33
UD
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;
e1a79915 141
735a0e33 142 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
e1a79915
RS
143 switch (*format_ptr++)
144 {
145 case 'S':
146 case 's':
147 if (XSTR (in_rtx, i) == 0)
735a0e33 148 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
e1a79915 149 else
913d0833
KG
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 }
e1a79915
RS
156 sawclose = 1;
157 break;
158
8f985ec4
ZW
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. */
e1a79915 162 case '0':
8f985ec4
ZW
163 if (i == 3 && GET_CODE (in_rtx) == NOTE)
164 {
994a57cd 165 switch (NOTE_LINE_NUMBER (in_rtx))
bf43101e 166 {
994a57cd
RH
167 case NOTE_INSN_EH_REGION_BEG:
168 case NOTE_INSN_EH_REGION_END:
f76ca83c
GK
169 if (flag_dump_unnumbered)
170 fprintf (outfile, " #");
171 else
172 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
bf43101e 173 sawclose = 1;
994a57cd
RH
174 break;
175
176 case NOTE_INSN_BLOCK_BEG:
177 case NOTE_INSN_BLOCK_END:
1a4450c7 178 fprintf (outfile, " ");
f76ca83c
GK
179 if (flag_dump_unnumbered)
180 fprintf (outfile, "#");
181 else
182 fprintf (outfile, HOST_PTR_PRINTF,
183 (char *) NOTE_BLOCK (in_rtx));
8f985ec4 184 sawclose = 1;
994a57cd
RH
185 break;
186
b3b42a4d 187 case NOTE_INSN_RANGE_BEG:
994a57cd
RH
188 case NOTE_INSN_RANGE_END:
189 case NOTE_INSN_LIVE:
8f985ec4
ZW
190 indent += 2;
191 if (!sawclose)
192 fprintf (outfile, " ");
193 print_rtx (NOTE_RANGE_INFO (in_rtx));
194 indent -= 2;
994a57cd 195 break;
4c1545e4 196
994a57cd
RH
197 case NOTE_INSN_BASIC_BLOCK:
198 {
199 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
200 if (bb != 0)
201 fprintf (outfile, " [bb %d]", bb->index);
202 break;
203 }
204
205 case NOTE_INSN_EXPECTED_VALUE:
206 indent += 2;
207 if (!sawclose)
208 fprintf (outfile, " ");
209 print_rtx (NOTE_EXPECTED_VALUE (in_rtx));
210 indent -= 2;
211 break;
212
213 default:
214 {
215 const char * const str = X0STR (in_rtx, i);
216
217 if (NOTE_LINE_NUMBER (in_rtx) < 0)
218 ;
219 else if (str == 0)
220 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
221 else
222 {
223 if (dump_for_graph)
224 fprintf (outfile, " (\\\"%s\\\")", str);
225 else
226 fprintf (outfile, " (\"%s\")", str);
227 }
228 break;
229 }
8f985ec4
ZW
230 }
231 }
e1a79915
RS
232 break;
233
234 case 'e':
bcdaba58 235 do_e:
e1a79915
RS
236 indent += 2;
237 if (!sawclose)
238 fprintf (outfile, " ");
239 print_rtx (XEXP (in_rtx, i));
240 indent -= 2;
241 break;
242
243 case 'E':
244 case 'V':
245 indent += 2;
246 if (sawclose)
247 {
248 fprintf (outfile, "\n%s",
2778b98d 249 (xspaces + (sizeof xspaces - 1 - indent * 2)));
e1a79915
RS
250 sawclose = 0;
251 }
735a0e33 252 fputs ("[ ", outfile);
e1a79915
RS
253 if (NULL != XVEC (in_rtx, i))
254 {
255 indent += 2;
256 if (XVECLEN (in_rtx, i))
257 sawclose = 1;
258
259 for (j = 0; j < XVECLEN (in_rtx, i); j++)
260 print_rtx (XVECEXP (in_rtx, i, j));
261
262 indent -= 2;
263 }
264 if (sawclose)
265 fprintf (outfile, "\n%s",
2778b98d 266 (xspaces + (sizeof xspaces - 1 - indent * 2)));
e1a79915 267
735a0e33 268 fputs ("] ", outfile);
e1a79915
RS
269 sawclose = 1;
270 indent -= 2;
271 break;
272
5bf665df 273 case 'w':
734de8c8
RK
274 fprintf (outfile, " ");
275 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
7b028dba
NC
276 fprintf (outfile, " [");
277 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, XWINT (in_rtx, i));
278 fprintf (outfile, "]");
5bf665df
RK
279 break;
280
e1a79915 281 case 'i':
cf99a734
RS
282 {
283 register int value = XINT (in_rtx, i);
a995e389 284 const char *name;
cf99a734
RS
285
286 if (GET_CODE (in_rtx) == REG && value < FIRST_PSEUDO_REGISTER)
287 {
288 fputc (' ', outfile);
289 DEBUG_PRINT_REG (in_rtx, 0, outfile);
290 }
a6c7a886
MM
291 else if (GET_CODE (in_rtx) == REG && value <= LAST_VIRTUAL_REGISTER)
292 {
293 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
294 fprintf (outfile, " %d virtual-incoming-args", value);
295 else if (value == VIRTUAL_STACK_VARS_REGNUM)
296 fprintf (outfile, " %d virtual-stack-vars", value);
297 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
298 fprintf (outfile, " %d virtual-stack-dynamic", value);
299 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
300 fprintf (outfile, " %d virtual-outgoing-args", value);
301 else if (value == VIRTUAL_CFA_REGNUM)
302 fprintf (outfile, " %d virtual-cfa", value);
303 else
304 fprintf (outfile, " %d virtual-reg-%d", value,
305 value-FIRST_VIRTUAL_REGISTER);
306 }
9ec36da5
JL
307 else if (flag_dump_unnumbered
308 && (is_insn || GET_CODE (in_rtx) == NOTE))
735a0e33 309 fputc ('#', outfile);
cf99a734
RS
310 else
311 fprintf (outfile, " %d", value);
a995e389
RH
312
313 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
314 && XINT (in_rtx, i) >= 0
315 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
316 fprintf (outfile, " {%s}", name);
317 sawclose = 0;
cf99a734 318 }
e1a79915
RS
319 break;
320
321 /* Print NOTE_INSN names rather than integer codes. */
322
323 case 'n':
324 if (XINT (in_rtx, i) <= 0)
325 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
326 else
327 fprintf (outfile, " %d", XINT (in_rtx, i));
328 sawclose = 0;
329 break;
330
331 case 'u':
332 if (XEXP (in_rtx, i) != NULL)
9ec36da5 333 {
556ffcc5
RH
334 rtx sub = XEXP (in_rtx, i);
335 enum rtx_code subc = GET_CODE (sub);
336
c3c63936 337 if (GET_CODE (in_rtx) == LABEL_REF && subc != CODE_LABEL)
bcdaba58
RH
338 goto do_e;
339
9ec36da5 340 if (flag_dump_unnumbered)
735a0e33 341 fputc ('#', outfile);
9ec36da5 342 else
556ffcc5 343 fprintf (outfile, " %d", INSN_UID (sub));
9ec36da5 344 }
e1a79915 345 else
d5e3e85b 346 fputs (" 0", outfile);
d64be5ec
CH
347 sawclose = 0;
348 break;
349
0dfa1860
MM
350 case 'b':
351 if (XBITMAP (in_rtx, i) == NULL)
735a0e33 352 fputs (" {null}", outfile);
0dfa1860
MM
353 else
354 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
355 sawclose = 0;
356 break;
357
358 case 't':
359 putc (' ', outfile);
c6b0465b 360 fprintf (outfile, HOST_PTR_PRINTF, (char *) XTREE (in_rtx, i));
0dfa1860
MM
361 break;
362
d64be5ec 363 case '*':
735a0e33 364 fputs (" Unknown", outfile);
e1a79915
RS
365 sawclose = 0;
366 break;
367
368 default:
369 fprintf (stderr,
370 "switch format wrong in rtl.print_rtx(). format was: %c.\n",
371 format_ptr[-1]);
372 abort ();
373 }
374
5a0a1a66
BS
375 if (GET_CODE (in_rtx) == MEM)
376 fprintf (outfile, " %d", MEM_ALIAS_SET (in_rtx));
377
4710d3eb 378#if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && MAX_LONG_DOUBLE_TYPE_SIZE == 64
800d5c9e
RH
379 if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
380 {
5dd2add6 381 double val;
800d5c9e
RH
382 REAL_VALUE_FROM_CONST_DOUBLE (val, in_rtx);
383 fprintf (outfile, " [%.16g]", val);
384 }
385#endif
386
75c437de 387 if (GET_CODE (in_rtx) == CODE_LABEL)
8cd0faaf 388 {
c3c63936 389 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
8cd0faaf 390 if (LABEL_ALTERNATE_NAME (in_rtx))
c3c63936
RK
391 fprintf (outfile, " [alternate name: %s]",
392 LABEL_ALTERNATE_NAME (in_rtx));
8cd0faaf 393 }
75c437de 394
c3c63936
RK
395 if (GET_CODE (in_rtx) == CALL_PLACEHOLDER)
396 for (tem = XEXP (in_rtx, 0); tem != 0; tem = NEXT_INSN (tem))
397 if (GET_CODE (tem) == CALL_INSN)
398 {
399 fprintf (outfile, " ");
400 print_rtx (tem);
401 break;
402 }
403
735a0e33
UD
404 if (dump_for_graph
405 && (is_insn || GET_CODE (in_rtx) == NOTE
406 || GET_CODE (in_rtx) == CODE_LABEL || GET_CODE (in_rtx) == BARRIER))
407 sawclose = 0;
408 else
409 {
410 fputc (')', outfile);
411 sawclose = 1;
412 }
e1a79915
RS
413}
414
1d79197a
RK
415/* Print an rtx on the current line of FILE. Initially indent IND
416 characters. */
417
418void
419print_inline_rtx (outf, x, ind)
420 FILE *outf;
421 rtx x;
9870475c 422 int ind;
1d79197a 423{
956d6950
JL
424 int oldsaw = sawclose;
425 int oldindent = indent;
426
1d79197a
RK
427 sawclose = 0;
428 indent = ind;
429 outfile = outf;
430 print_rtx (x);
956d6950
JL
431 sawclose = oldsaw;
432 indent = oldindent;
1d79197a
RK
433}
434
e1a79915
RS
435/* Call this function from the debugger to see what X looks like. */
436
437void
438debug_rtx (x)
439 rtx x;
440{
441 outfile = stderr;
442 print_rtx (x);
443 fprintf (stderr, "\n");
444}
445
716f003f
DE
446/* Count of rtx's to print with debug_rtx_list.
447 This global exists because gdb user defined commands have no arguments. */
448
449int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
450
451/* Call this function to print list from X on.
452
453 N is a count of the rtx's to print. Positive values print from the specified
454 rtx on. Negative values print a window around the rtx.
455 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
456
457void
458debug_rtx_list (x, n)
459 rtx x;
460 int n;
461{
462 int i,count;
463 rtx insn;
464
465 count = n == 0 ? 1 : n < 0 ? -n : n;
466
467 /* If we are printing a window, back up to the start. */
468
469 if (n < 0)
470 for (i = count / 2; i > 0; i--)
471 {
472 if (PREV_INSN (x) == 0)
473 break;
474 x = PREV_INSN (x);
475 }
476
477 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
478 debug_rtx (insn);
479}
480
4c85a96d
RH
481/* Call this function to print an rtx list from START to END inclusive. */
482
483void
484debug_rtx_range (start, end)
485 rtx start, end;
486{
487 while (1)
488 {
489 debug_rtx (start);
490 if (!start || start == end)
491 break;
492 start = NEXT_INSN (start);
493 }
494}
495
716f003f
DE
496/* Call this function to search an rtx list to find one with insn uid UID,
497 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
498 The found insn is returned to enable further debugging analysis. */
499
500rtx
1d79197a 501debug_rtx_find (x, uid)
716f003f
DE
502 rtx x;
503 int uid;
504{
505 while (x != 0 && INSN_UID (x) != uid)
506 x = NEXT_INSN (x);
507 if (x != 0)
508 {
509 debug_rtx_list (x, debug_rtx_count);
510 return x;
511 }
512 else
513 {
514 fprintf (stderr, "insn uid %d not found\n", uid);
515 return 0;
516 }
517}
518
e1a79915
RS
519/* External entry point for printing a chain of insns
520 starting with RTX_FIRST onto file OUTF.
521 A blank line separates insns.
522
523 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
524
525void
526print_rtl (outf, rtx_first)
527 FILE *outf;
528 rtx rtx_first;
529{
530 register rtx tmp_rtx;
531
532 outfile = outf;
533 sawclose = 0;
534
535 if (rtx_first == 0)
735a0e33 536 fputs ("(nil)\n", outf);
e1a79915
RS
537 else
538 switch (GET_CODE (rtx_first))
539 {
540 case INSN:
541 case JUMP_INSN:
542 case CALL_INSN:
543 case NOTE:
544 case CODE_LABEL:
545 case BARRIER:
c3c63936
RK
546 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
547 if (! flag_dump_unnumbered
548 || GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
549 {
550 print_rtx (tmp_rtx);
551 fprintf (outfile, "\n");
552 }
e1a79915
RS
553 break;
554
555 default:
556 print_rtx (rtx_first);
557 }
558}
3e28fe44
MM
559
560/* Like print_rtx, except specify a file. */
b707b450 561/* Return nonzero if we actually printed anything. */
3e28fe44 562
b707b450 563int
3e28fe44
MM
564print_rtl_single (outf, x)
565 FILE *outf;
566 rtx x;
567{
568 outfile = outf;
569 sawclose = 0;
9ec36da5
JL
570 if (! flag_dump_unnumbered
571 || GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
572 {
573 print_rtx (x);
574 putc ('\n', outf);
b707b450 575 return 1;
9ec36da5 576 }
b707b450 577 return 0;
3e28fe44 578}