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