* c-parser.c (c_parser_lex_all): Don't enforce location constraint
[official-gcc.git] / gcc / print-rtl.c
blob9bf7b18f05af8e0e852c6039a240e45b5d7fe2a6
1 /* Print RTL for GCC.
2 Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003,
3 2004, 2005, 2007
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This file is compiled twice: once for the generator programs,
23 once for the compiler. */
24 #ifdef GENERATOR_FILE
25 #include "bconfig.h"
26 #else
27 #include "config.h"
28 #endif
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include "rtl.h"
35 /* These headers all define things which are not available in
36 generator programs. */
37 #ifndef GENERATOR_FILE
38 #include "tree.h"
39 #include "real.h"
40 #include "flags.h"
41 #include "hard-reg-set.h"
42 #include "basic-block.h"
43 #include "langhooks.h"
44 #endif
46 static FILE *outfile;
48 static int sawclose = 0;
50 static int indent;
52 static void print_rtx (const_rtx);
54 /* String printed at beginning of each RTL when it is dumped.
55 This string is set to ASM_COMMENT_START when the RTL is dumped in
56 the assembly output file. */
57 const char *print_rtx_head = "";
59 /* Nonzero means suppress output of instruction numbers
60 in debugging dumps.
61 This must be defined here so that programs like gencodes can be linked. */
62 int flag_dump_unnumbered = 0;
64 /* Nonzero means use simplified format without flags, modes, etc. */
65 int flag_simple = 0;
67 /* Nonzero if we are dumping graphical description. */
68 int dump_for_graph;
70 #ifndef GENERATOR_FILE
71 static void
72 print_decl_name (FILE *outfile, const_tree node)
74 if (DECL_NAME (node))
75 fputs (IDENTIFIER_POINTER (DECL_NAME (node)), outfile);
76 else
78 if (TREE_CODE (node) == LABEL_DECL && LABEL_DECL_UID (node) != -1)
79 fprintf (outfile, "L.%d", (int) LABEL_DECL_UID (node));
80 else
82 char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
83 fprintf (outfile, "%c.%u", c, DECL_UID (node));
88 void
89 print_mem_expr (FILE *outfile, const_tree expr)
91 if (TREE_CODE (expr) == COMPONENT_REF)
93 if (TREE_OPERAND (expr, 0))
94 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
95 else
96 fputs (" <variable>", outfile);
97 fputc ('.', outfile);
98 print_decl_name (outfile, TREE_OPERAND (expr, 1));
100 else if (TREE_CODE (expr) == INDIRECT_REF)
102 fputs (" (*", outfile);
103 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
104 fputs (")", outfile);
106 else if (TREE_CODE (expr) == ALIGN_INDIRECT_REF)
108 fputs (" (A*", outfile);
109 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
110 fputs (")", outfile);
112 else if (TREE_CODE (expr) == MISALIGNED_INDIRECT_REF)
114 fputs (" (M*", outfile);
115 print_mem_expr (outfile, TREE_OPERAND (expr, 0));
116 fputs (")", outfile);
118 else if (TREE_CODE (expr) == RESULT_DECL)
119 fputs (" <result>", outfile);
120 else
122 fputc (' ', outfile);
123 print_decl_name (outfile, expr);
126 #endif
128 /* Print IN_RTX onto OUTFILE. This is the recursive part of printing. */
130 static void
131 print_rtx (const_rtx in_rtx)
133 int i = 0;
134 int j;
135 const char *format_ptr;
136 int is_insn;
138 if (sawclose)
140 if (flag_simple)
141 fputc (' ', outfile);
142 else
143 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
144 sawclose = 0;
147 if (in_rtx == 0)
149 fputs ("(nil)", outfile);
150 sawclose = 1;
151 return;
153 else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
155 fprintf (outfile, "(??? bad code %d\n)", GET_CODE (in_rtx));
156 sawclose = 1;
157 return;
160 is_insn = INSN_P (in_rtx);
162 /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
163 in separate nodes and therefore have to handle them special here. */
164 if (dump_for_graph
165 && (is_insn || NOTE_P (in_rtx)
166 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
168 i = 3;
169 indent = 0;
171 else
173 /* Print name of expression code. */
174 if (flag_simple && GET_CODE (in_rtx) == CONST_INT)
175 fputc ('(', outfile);
176 else
177 fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
179 if (! flag_simple)
181 if (RTX_FLAG (in_rtx, in_struct))
182 fputs ("/s", outfile);
184 if (RTX_FLAG (in_rtx, volatil))
185 fputs ("/v", outfile);
187 if (RTX_FLAG (in_rtx, unchanging))
188 fputs ("/u", outfile);
190 if (RTX_FLAG (in_rtx, frame_related))
191 fputs ("/f", outfile);
193 if (RTX_FLAG (in_rtx, jump))
194 fputs ("/j", outfile);
196 if (RTX_FLAG (in_rtx, call))
197 fputs ("/c", outfile);
199 if (RTX_FLAG (in_rtx, return_val))
200 fputs ("/i", outfile);
202 /* Print REG_NOTE names for EXPR_LIST and INSN_LIST. */
203 if (GET_CODE (in_rtx) == EXPR_LIST
204 || GET_CODE (in_rtx) == INSN_LIST)
205 fprintf (outfile, ":%s",
206 GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
208 /* For other rtl, print the mode if it's not VOID. */
209 else if (GET_MODE (in_rtx) != VOIDmode)
210 fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
214 #ifndef GENERATOR_FILE
215 if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
216 i = 5;
217 #endif
219 /* Get the format string and skip the first elements if we have handled
220 them already. */
221 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
222 for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
223 switch (*format_ptr++)
225 const char *str;
227 case 'T':
228 str = XTMPL (in_rtx, i);
229 goto string;
231 case 'S':
232 case 's':
233 str = XSTR (in_rtx, i);
234 string:
236 if (str == 0)
237 fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
238 else
240 if (dump_for_graph)
241 fprintf (outfile, " (\\\"%s\\\")", str);
242 else
243 fprintf (outfile, " (\"%s\")", str);
245 sawclose = 1;
246 break;
248 /* 0 indicates a field for internal use that should not be printed.
249 An exception is the third field of a NOTE, where it indicates
250 that the field has several different valid contents. */
251 case '0':
252 if (i == 1 && REG_P (in_rtx))
254 if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
255 fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
257 #ifndef GENERATOR_FILE
258 else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
260 int flags = SYMBOL_REF_FLAGS (in_rtx);
261 if (flags)
262 fprintf (outfile, " [flags 0x%x]", flags);
264 else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
266 tree decl = SYMBOL_REF_DECL (in_rtx);
267 if (decl)
268 print_node_brief (outfile, "", decl, 0);
270 #endif
271 else if (i == 4 && NOTE_P (in_rtx))
273 switch (NOTE_KIND (in_rtx))
275 case NOTE_INSN_EH_REGION_BEG:
276 case NOTE_INSN_EH_REGION_END:
277 if (flag_dump_unnumbered)
278 fprintf (outfile, " #");
279 else
280 fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
281 sawclose = 1;
282 break;
284 case NOTE_INSN_BLOCK_BEG:
285 case NOTE_INSN_BLOCK_END:
286 #ifndef GENERATOR_FILE
287 dump_addr (outfile, " ", NOTE_BLOCK (in_rtx));
288 #endif
289 sawclose = 1;
290 break;
292 case NOTE_INSN_BASIC_BLOCK:
294 #ifndef GENERATOR_FILE
295 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
296 if (bb != 0)
297 fprintf (outfile, " [bb %d]", bb->index);
298 #endif
299 break;
302 case NOTE_INSN_DELETED_LABEL:
304 const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
305 if (label)
306 fprintf (outfile, " (\"%s\")", label);
307 else
308 fprintf (outfile, " \"\"");
310 break;
312 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
314 #ifndef GENERATOR_FILE
315 basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
316 if (bb != 0)
317 fprintf (outfile, " [bb %d]", bb->index);
318 #endif
319 break;
322 case NOTE_INSN_VAR_LOCATION:
323 #ifndef GENERATOR_FILE
324 fprintf (outfile, " (");
325 print_mem_expr (outfile, NOTE_VAR_LOCATION_DECL (in_rtx));
326 fprintf (outfile, " ");
327 print_rtx (NOTE_VAR_LOCATION_LOC (in_rtx));
328 if (NOTE_VAR_LOCATION_STATUS (in_rtx) ==
329 VAR_INIT_STATUS_UNINITIALIZED)
330 fprintf (outfile, " [uninit]");
331 fprintf (outfile, ")");
332 #endif
333 break;
335 default:
336 break;
339 else if (i == 9 && JUMP_P (in_rtx) && XEXP (in_rtx, i) != NULL)
340 /* Output the JUMP_LABEL reference. */
341 fprintf (outfile, "\n -> %d", INSN_UID (XEXP (in_rtx, i)));
342 break;
344 case 'e':
345 do_e:
346 indent += 2;
347 if (!sawclose)
348 fprintf (outfile, " ");
349 print_rtx (XEXP (in_rtx, i));
350 indent -= 2;
351 break;
353 case 'E':
354 case 'V':
355 indent += 2;
356 if (sawclose)
358 fprintf (outfile, "\n%s%*s",
359 print_rtx_head, indent * 2, "");
360 sawclose = 0;
362 fputs (" [", outfile);
363 if (NULL != XVEC (in_rtx, i))
365 indent += 2;
366 if (XVECLEN (in_rtx, i))
367 sawclose = 1;
369 for (j = 0; j < XVECLEN (in_rtx, i); j++)
370 print_rtx (XVECEXP (in_rtx, i, j));
372 indent -= 2;
374 if (sawclose)
375 fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
377 fputs ("]", outfile);
378 sawclose = 1;
379 indent -= 2;
380 break;
382 case 'w':
383 if (! flag_simple)
384 fprintf (outfile, " ");
385 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
386 if (! flag_simple)
387 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
388 XWINT (in_rtx, i));
389 break;
391 case 'i':
392 if (i == 4 && INSN_P (in_rtx))
394 #ifndef GENERATOR_FILE
395 /* Pretty-print insn locators. Ignore scoping as it is mostly
396 redundant with line number information and do not print anything
397 when there is no location information available. */
398 if (INSN_LOCATOR (in_rtx) && insn_file (in_rtx))
399 fprintf(outfile, " %s:%i", insn_file (in_rtx), insn_line (in_rtx));
400 #endif
402 else if (i == 6 && NOTE_P (in_rtx))
404 /* This field is only used for NOTE_INSN_DELETED_LABEL, and
405 other times often contains garbage from INSN->NOTE death. */
406 if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL)
407 fprintf (outfile, " %d", XINT (in_rtx, i));
409 else
411 int value = XINT (in_rtx, i);
412 const char *name;
414 #ifndef GENERATOR_FILE
415 if (REG_P (in_rtx) && value < FIRST_PSEUDO_REGISTER)
416 fprintf (outfile, " %d %s", REGNO (in_rtx),
417 reg_names[REGNO (in_rtx)]);
418 else if (REG_P (in_rtx)
419 && value <= LAST_VIRTUAL_REGISTER)
421 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
422 fprintf (outfile, " %d virtual-incoming-args", value);
423 else if (value == VIRTUAL_STACK_VARS_REGNUM)
424 fprintf (outfile, " %d virtual-stack-vars", value);
425 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
426 fprintf (outfile, " %d virtual-stack-dynamic", value);
427 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
428 fprintf (outfile, " %d virtual-outgoing-args", value);
429 else if (value == VIRTUAL_CFA_REGNUM)
430 fprintf (outfile, " %d virtual-cfa", value);
431 else
432 fprintf (outfile, " %d virtual-reg-%d", value,
433 value-FIRST_VIRTUAL_REGISTER);
435 else
436 #endif
437 if (flag_dump_unnumbered
438 && (is_insn || NOTE_P (in_rtx)))
439 fputc ('#', outfile);
440 else
441 fprintf (outfile, " %d", value);
443 #ifndef GENERATOR_FILE
444 if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
446 fputs (" [", outfile);
447 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
448 fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
449 if (REG_EXPR (in_rtx))
450 print_mem_expr (outfile, REG_EXPR (in_rtx));
452 if (REG_OFFSET (in_rtx))
453 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
454 REG_OFFSET (in_rtx));
455 fputs (" ]", outfile);
457 #endif
459 if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
460 && XINT (in_rtx, i) >= 0
461 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
462 fprintf (outfile, " {%s}", name);
463 sawclose = 0;
465 break;
467 /* Print NOTE_INSN names rather than integer codes. */
469 case 'n':
470 fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
471 sawclose = 0;
472 break;
474 case 'u':
475 if (XEXP (in_rtx, i) != NULL)
477 rtx sub = XEXP (in_rtx, i);
478 enum rtx_code subc = GET_CODE (sub);
480 if (GET_CODE (in_rtx) == LABEL_REF)
482 if (subc == NOTE
483 && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
485 if (flag_dump_unnumbered)
486 fprintf (outfile, " [# deleted]");
487 else
488 fprintf (outfile, " [%d deleted]", INSN_UID (sub));
489 sawclose = 0;
490 break;
493 if (subc != CODE_LABEL)
494 goto do_e;
497 if (flag_dump_unnumbered)
498 fputs (" #", outfile);
499 else
500 fprintf (outfile, " %d", INSN_UID (sub));
502 else
503 fputs (" 0", outfile);
504 sawclose = 0;
505 break;
507 case 'b':
508 #ifndef GENERATOR_FILE
509 if (XBITMAP (in_rtx, i) == NULL)
510 fputs (" {null}", outfile);
511 else
512 bitmap_print (outfile, XBITMAP (in_rtx, i), " {", "}");
513 #endif
514 sawclose = 0;
515 break;
517 case 't':
518 #ifndef GENERATOR_FILE
519 dump_addr (outfile, " ", XTREE (in_rtx, i));
520 #endif
521 break;
523 case '*':
524 fputs (" Unknown", outfile);
525 sawclose = 0;
526 break;
528 case 'B':
529 #ifndef GENERATOR_FILE
530 if (XBBDEF (in_rtx, i))
531 fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
532 #endif
533 break;
535 default:
536 gcc_unreachable ();
539 switch (GET_CODE (in_rtx))
541 #ifndef GENERATOR_FILE
542 case MEM:
543 fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC,
544 (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
546 if (MEM_EXPR (in_rtx))
547 print_mem_expr (outfile, MEM_EXPR (in_rtx));
549 if (MEM_OFFSET (in_rtx))
550 fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
551 INTVAL (MEM_OFFSET (in_rtx)));
553 if (MEM_SIZE (in_rtx))
554 fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC,
555 INTVAL (MEM_SIZE (in_rtx)));
557 if (MEM_ALIGN (in_rtx) != 1)
558 fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
560 fputc (']', outfile);
561 break;
563 case CONST_DOUBLE:
564 if (FLOAT_MODE_P (GET_MODE (in_rtx)))
566 char s[60];
568 real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
569 sizeof (s), 0, 1);
570 fprintf (outfile, " %s", s);
572 real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
573 sizeof (s), 0, 1);
574 fprintf (outfile, " [%s]", s);
576 break;
577 #endif
579 case CODE_LABEL:
580 fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
581 switch (LABEL_KIND (in_rtx))
583 case LABEL_NORMAL: break;
584 case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
585 case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
586 case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
587 default: gcc_unreachable ();
589 break;
591 default:
592 break;
595 if (dump_for_graph
596 && (is_insn || NOTE_P (in_rtx)
597 || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
598 sawclose = 0;
599 else
601 fputc (')', outfile);
602 sawclose = 1;
606 /* Print an rtx on the current line of FILE. Initially indent IND
607 characters. */
609 void
610 print_inline_rtx (FILE *outf, const_rtx x, int ind)
612 int oldsaw = sawclose;
613 int oldindent = indent;
615 sawclose = 0;
616 indent = ind;
617 outfile = outf;
618 print_rtx (x);
619 sawclose = oldsaw;
620 indent = oldindent;
623 /* Call this function from the debugger to see what X looks like. */
625 void
626 debug_rtx (const_rtx x)
628 outfile = stderr;
629 sawclose = 0;
630 print_rtx (x);
631 fprintf (stderr, "\n");
634 /* Count of rtx's to print with debug_rtx_list.
635 This global exists because gdb user defined commands have no arguments. */
637 int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
639 /* Call this function to print list from X on.
641 N is a count of the rtx's to print. Positive values print from the specified
642 rtx on. Negative values print a window around the rtx.
643 EG: -5 prints 2 rtx's on either side (in addition to the specified rtx). */
645 void
646 debug_rtx_list (const_rtx x, int n)
648 int i,count;
649 const_rtx insn;
651 count = n == 0 ? 1 : n < 0 ? -n : n;
653 /* If we are printing a window, back up to the start. */
655 if (n < 0)
656 for (i = count / 2; i > 0; i--)
658 if (PREV_INSN (x) == 0)
659 break;
660 x = PREV_INSN (x);
663 for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
665 debug_rtx (insn);
666 fprintf (stderr, "\n");
670 /* Call this function to print an rtx list from START to END inclusive. */
672 void
673 debug_rtx_range (const_rtx start, const_rtx end)
675 while (1)
677 debug_rtx (start);
678 fprintf (stderr, "\n");
679 if (!start || start == end)
680 break;
681 start = NEXT_INSN (start);
685 /* Call this function to search an rtx list to find one with insn uid UID,
686 and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
687 The found insn is returned to enable further debugging analysis. */
689 const_rtx
690 debug_rtx_find (const_rtx x, int uid)
692 while (x != 0 && INSN_UID (x) != uid)
693 x = NEXT_INSN (x);
694 if (x != 0)
696 debug_rtx_list (x, debug_rtx_count);
697 return x;
699 else
701 fprintf (stderr, "insn uid %d not found\n", uid);
702 return 0;
706 /* External entry point for printing a chain of insns
707 starting with RTX_FIRST onto file OUTF.
708 A blank line separates insns.
710 If RTX_FIRST is not an insn, then it alone is printed, with no newline. */
712 void
713 print_rtl (FILE *outf, const_rtx rtx_first)
715 const_rtx tmp_rtx;
717 outfile = outf;
718 sawclose = 0;
720 if (rtx_first == 0)
722 fputs (print_rtx_head, outf);
723 fputs ("(nil)\n", outf);
725 else
726 switch (GET_CODE (rtx_first))
728 case INSN:
729 case JUMP_INSN:
730 case CALL_INSN:
731 case NOTE:
732 case CODE_LABEL:
733 case BARRIER:
734 for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
736 fputs (print_rtx_head, outfile);
737 print_rtx (tmp_rtx);
738 fprintf (outfile, "\n");
740 break;
742 default:
743 fputs (print_rtx_head, outfile);
744 print_rtx (rtx_first);
748 /* Like print_rtx, except specify a file. */
749 /* Return nonzero if we actually printed anything. */
752 print_rtl_single (FILE *outf, const_rtx x)
754 outfile = outf;
755 sawclose = 0;
756 fputs (print_rtx_head, outfile);
757 print_rtx (x);
758 putc ('\n', outf);
759 return 1;
763 /* Like print_rtl except without all the detail; for example,
764 if RTX is a CONST_INT then print in decimal format. */
766 void
767 print_simple_rtl (FILE *outf, const_rtx x)
769 flag_simple = 1;
770 print_rtl (outf, x);
771 flag_simple = 0;