OSDN Git Service

* cp-tree.h (struct tinst_level): Add chain_next GTY
[pf3gnuchains/gcc-fork.git] / gcc / print-rtl.c
1 /* Print RTL for GCC.
2    Copyright (C) 1987, 1988, 1992, 1997, 1998, 1999, 2000, 2002, 2003,
3    2004, 2005, 2007, 2008, 2009, 2010, 2011
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>.  */
21
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
29
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include "rtl.h"
34
35 /* These headers all define things which are not available in
36    generator programs.  */
37 #ifndef GENERATOR_FILE
38 #include "tree.h"
39 #include "flags.h"
40 #include "hard-reg-set.h"
41 #include "basic-block.h"
42 #include "diagnostic.h"
43 #include "tree-pretty-print.h"
44 #include "cselib.h"
45 #include "tree-pass.h"
46 #endif
47
48 static FILE *outfile;
49
50 static int sawclose = 0;
51
52 static int indent;
53
54 static void print_rtx (const_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 #ifdef GENERATOR_FILE
62 /* These are defined from the .opt file when not used in generator
63    programs.  */
64
65 /* Nonzero means suppress output of instruction numbers
66    in debugging dumps.
67    This must be defined here so that programs like gencodes can be linked.  */
68 int flag_dump_unnumbered = 0;
69
70 /* Nonzero means suppress output of instruction numbers for previous
71    and next insns in debugging dumps.
72    This must be defined here so that programs like gencodes can be linked.  */
73 int flag_dump_unnumbered_links = 0;
74 #endif
75
76 /* Nonzero means use simplified format without flags, modes, etc.  */
77 int flag_simple = 0;
78
79 /* Nonzero if we are dumping graphical description.  */
80 int dump_for_graph;
81
82 #ifndef GENERATOR_FILE
83 void
84 print_mem_expr (FILE *outfile, const_tree expr)
85 {
86   fputc (' ', outfile);
87   print_generic_expr (outfile, CONST_CAST_TREE (expr), dump_flags);
88 }
89 #endif
90
91 /* Print IN_RTX onto OUTFILE.  This is the recursive part of printing.  */
92
93 static void
94 print_rtx (const_rtx in_rtx)
95 {
96   int i = 0;
97   int j;
98   const char *format_ptr;
99   int is_insn;
100
101   if (sawclose)
102     {
103       if (flag_simple)
104         fputc (' ', outfile);
105       else
106         fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
107       sawclose = 0;
108     }
109
110   if (in_rtx == 0)
111     {
112       fputs ("(nil)", outfile);
113       sawclose = 1;
114       return;
115     }
116   else if (GET_CODE (in_rtx) > NUM_RTX_CODE)
117     {
118        fprintf (outfile, "(??? bad code %d\n%s%*s)", GET_CODE (in_rtx),
119                 print_rtx_head, indent * 2, "");
120        sawclose = 1;
121        return;
122     }
123
124   is_insn = INSN_P (in_rtx);
125
126   /* When printing in VCG format we write INSNs, NOTE, LABEL, and BARRIER
127      in separate nodes and therefore have to handle them special here.  */
128   if (dump_for_graph
129       && (is_insn || NOTE_P (in_rtx)
130           || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
131     {
132       i = 3;
133       indent = 0;
134     }
135   else
136     {
137       /* Print name of expression code.  */
138       if (flag_simple && CONST_INT_P (in_rtx))
139         fputc ('(', outfile);
140       else
141         fprintf (outfile, "(%s", GET_RTX_NAME (GET_CODE (in_rtx)));
142
143       if (! flag_simple)
144         {
145           if (RTX_FLAG (in_rtx, in_struct))
146             fputs ("/s", outfile);
147
148           if (RTX_FLAG (in_rtx, volatil))
149             fputs ("/v", outfile);
150
151           if (RTX_FLAG (in_rtx, unchanging))
152             fputs ("/u", outfile);
153
154           if (RTX_FLAG (in_rtx, frame_related))
155             fputs ("/f", outfile);
156
157           if (RTX_FLAG (in_rtx, jump))
158             fputs ("/j", outfile);
159
160           if (RTX_FLAG (in_rtx, call))
161             fputs ("/c", outfile);
162
163           if (RTX_FLAG (in_rtx, return_val))
164             fputs ("/i", outfile);
165
166           /* Print REG_NOTE names for EXPR_LIST and INSN_LIST.  */
167           if ((GET_CODE (in_rtx) == EXPR_LIST
168                || GET_CODE (in_rtx) == INSN_LIST)
169               && (int)GET_MODE (in_rtx) < REG_NOTE_MAX)
170             fprintf (outfile, ":%s",
171                      GET_REG_NOTE_NAME (GET_MODE (in_rtx)));
172
173           /* For other rtl, print the mode if it's not VOID.  */
174           else if (GET_MODE (in_rtx) != VOIDmode)
175             fprintf (outfile, ":%s", GET_MODE_NAME (GET_MODE (in_rtx)));
176
177 #ifndef GENERATOR_FILE
178           if (GET_CODE (in_rtx) == VAR_LOCATION)
179             {
180               if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
181                 fputs (" <debug string placeholder>", outfile);
182               else
183                 print_mem_expr (outfile, PAT_VAR_LOCATION_DECL (in_rtx));
184               fputc (' ', outfile);
185               print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
186               if (PAT_VAR_LOCATION_STATUS (in_rtx)
187                   == VAR_INIT_STATUS_UNINITIALIZED)
188                 fprintf (outfile, " [uninit]");
189               sawclose = 1;
190               i = GET_RTX_LENGTH (VAR_LOCATION);
191             }
192 #endif
193         }
194     }
195
196 #ifndef GENERATOR_FILE
197   if (GET_CODE (in_rtx) == CONST_DOUBLE && FLOAT_MODE_P (GET_MODE (in_rtx)))
198     i = 5;
199 #endif
200
201   /* Get the format string and skip the first elements if we have handled
202      them already.  */
203   format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)) + i;
204   for (; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
205     switch (*format_ptr++)
206       {
207         const char *str;
208
209       case 'T':
210         str = XTMPL (in_rtx, i);
211         goto string;
212
213       case 'S':
214       case 's':
215         str = XSTR (in_rtx, i);
216       string:
217
218         if (str == 0)
219           fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
220         else
221           {
222             if (dump_for_graph)
223               fprintf (outfile, " (\\\"%s\\\")", str);
224             else
225               fprintf (outfile, " (\"%s\")", str);
226           }
227         sawclose = 1;
228         break;
229
230         /* 0 indicates a field for internal use that should not be printed.
231            An exception is the third field of a NOTE, where it indicates
232            that the field has several different valid contents.  */
233       case '0':
234         if (i == 1 && REG_P (in_rtx))
235           {
236             if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
237               fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
238           }
239 #ifndef GENERATOR_FILE
240         else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
241           {
242             int flags = SYMBOL_REF_FLAGS (in_rtx);
243             if (flags)
244               fprintf (outfile, " [flags %#x]", flags);
245           }
246         else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
247           {
248             tree decl = SYMBOL_REF_DECL (in_rtx);
249             if (decl)
250               print_node_brief (outfile, "", decl, dump_flags);
251           }
252 #endif
253         else if (i == 4 && NOTE_P (in_rtx))
254           {
255             switch (NOTE_KIND (in_rtx))
256               {
257               case NOTE_INSN_EH_REGION_BEG:
258               case NOTE_INSN_EH_REGION_END:
259                 if (flag_dump_unnumbered)
260                   fprintf (outfile, " #");
261                 else
262                   fprintf (outfile, " %d", NOTE_EH_HANDLER (in_rtx));
263                 sawclose = 1;
264                 break;
265
266               case NOTE_INSN_BLOCK_BEG:
267               case NOTE_INSN_BLOCK_END:
268 #ifndef GENERATOR_FILE
269                 dump_addr (outfile, " ", NOTE_BLOCK (in_rtx));
270 #endif
271                 sawclose = 1;
272                 break;
273
274               case NOTE_INSN_BASIC_BLOCK:
275                 {
276 #ifndef GENERATOR_FILE
277                   basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
278                   if (bb != 0)
279                     fprintf (outfile, " [bb %d]", bb->index);
280 #endif
281                   break;
282                 }
283
284               case NOTE_INSN_DELETED_LABEL:
285                 {
286                   const char *label = NOTE_DELETED_LABEL_NAME (in_rtx);
287                   if (label)
288                     fprintf (outfile, " (\"%s\")", label);
289                   else
290                     fprintf (outfile, " \"\"");
291                 }
292                 break;
293
294               case NOTE_INSN_SWITCH_TEXT_SECTIONS:
295                 {
296 #ifndef GENERATOR_FILE
297                   basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
298                   if (bb != 0)
299                     fprintf (outfile, " [bb %d]", bb->index);
300 #endif
301                   break;
302                 }
303
304               case NOTE_INSN_VAR_LOCATION:
305               case NOTE_INSN_CALL_ARG_LOCATION:
306 #ifndef GENERATOR_FILE
307                 fputc (' ', outfile);
308                 print_rtx (NOTE_VAR_LOCATION (in_rtx));
309 #endif
310                 break;
311
312               default:
313                 break;
314               }
315           }
316         else if (i == 8 && JUMP_P (in_rtx) && JUMP_LABEL (in_rtx) != NULL)
317           /* Output the JUMP_LABEL reference.  */
318           fprintf (outfile, "\n%s%*s -> %d", print_rtx_head, indent * 2, "",
319                    INSN_UID (JUMP_LABEL (in_rtx)));
320         else if (i == 0 && GET_CODE (in_rtx) == VALUE)
321           {
322 #ifndef GENERATOR_FILE
323             cselib_val *val = CSELIB_VAL_PTR (in_rtx);
324
325             fprintf (outfile, " %u:%u", val->uid, val->hash);
326             dump_addr (outfile, " @", in_rtx);
327             dump_addr (outfile, "/", (void*)val);
328 #endif
329           }
330         else if (i == 0 && GET_CODE (in_rtx) == DEBUG_EXPR)
331           {
332 #ifndef GENERATOR_FILE
333             fprintf (outfile, " D#%i",
334                      DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (in_rtx)));
335 #endif
336           }
337         else if (i == 0 && GET_CODE (in_rtx) == ENTRY_VALUE)
338           {
339             indent += 2;
340             if (!sawclose)
341               fprintf (outfile, " ");
342             print_rtx (ENTRY_VALUE_EXP (in_rtx));
343             indent -= 2;
344           }
345         break;
346
347       case 'e':
348       do_e:
349         indent += 2;
350         if (i == 7 && INSN_P (in_rtx))
351           /* Put REG_NOTES on their own line.  */
352           fprintf (outfile, "\n%s%*s",
353                    print_rtx_head, indent * 2, "");
354         if (!sawclose)
355           fprintf (outfile, " ");
356         print_rtx (XEXP (in_rtx, i));
357         indent -= 2;
358         break;
359
360       case 'E':
361       case 'V':
362         indent += 2;
363         if (sawclose)
364           {
365             fprintf (outfile, "\n%s%*s",
366                      print_rtx_head, indent * 2, "");
367             sawclose = 0;
368           }
369         fputs (" [", outfile);
370         if (NULL != XVEC (in_rtx, i))
371           {
372             indent += 2;
373             if (XVECLEN (in_rtx, i))
374               sawclose = 1;
375
376             for (j = 0; j < XVECLEN (in_rtx, i); j++)
377               print_rtx (XVECEXP (in_rtx, i, j));
378
379             indent -= 2;
380           }
381         if (sawclose)
382           fprintf (outfile, "\n%s%*s", print_rtx_head, indent * 2, "");
383
384         fputs ("]", outfile);
385         sawclose = 1;
386         indent -= 2;
387         break;
388
389       case 'w':
390         if (! flag_simple)
391           fprintf (outfile, " ");
392         fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
393         if (! flag_simple)
394           fprintf (outfile, " [" HOST_WIDE_INT_PRINT_HEX "]",
395                    (unsigned HOST_WIDE_INT) XWINT (in_rtx, i));
396         break;
397
398       case 'i':
399         if (i == 5 && INSN_P (in_rtx))
400           {
401 #ifndef GENERATOR_FILE
402             /*  Pretty-print insn locators.  Ignore scoping as it is mostly
403                 redundant with line number information and do not print anything
404                 when there is no location information available.  */
405             if (INSN_LOCATOR (in_rtx) && insn_file (in_rtx))
406               fprintf(outfile, " %s:%i", insn_file (in_rtx), insn_line (in_rtx));
407 #endif
408           }
409         else if (i == 6 && GET_CODE (in_rtx) == ASM_OPERANDS)
410           {
411 #ifndef GENERATOR_FILE
412             fprintf (outfile, " %s:%i",
413                      locator_file (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)),
414                      locator_line (ASM_OPERANDS_SOURCE_LOCATION (in_rtx)));
415 #endif
416           }
417         else if (i == 1 && GET_CODE (in_rtx) == ASM_INPUT)
418           {
419 #ifndef GENERATOR_FILE
420             fprintf (outfile, " %s:%i",
421                      locator_file (ASM_INPUT_SOURCE_LOCATION (in_rtx)),
422                      locator_line (ASM_INPUT_SOURCE_LOCATION (in_rtx)));
423 #endif
424           }
425         else if (i == 6 && NOTE_P (in_rtx))
426           {
427             /* This field is only used for NOTE_INSN_DELETED_LABEL, and
428                other times often contains garbage from INSN->NOTE death.  */
429             if (NOTE_KIND (in_rtx) == NOTE_INSN_DELETED_LABEL)
430               fprintf (outfile, " %d",  XINT (in_rtx, i));
431           }
432 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
433         else if (i == 1
434                  && GET_CODE (in_rtx) == UNSPEC_VOLATILE
435                  && XINT (in_rtx, 1) >= 0
436                  && XINT (in_rtx, 1) < NUM_UNSPECV_VALUES)
437           fprintf (outfile, " %s", unspecv_strings[XINT (in_rtx, 1)]);
438 #endif
439 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
440         else if (i == 1
441                  && (GET_CODE (in_rtx) == UNSPEC
442                      || GET_CODE (in_rtx) == UNSPEC_VOLATILE)
443                  && XINT (in_rtx, 1) >= 0
444                  && XINT (in_rtx, 1) < NUM_UNSPEC_VALUES)
445           fprintf (outfile, " %s", unspec_strings[XINT (in_rtx, 1)]);
446 #endif
447         else
448           {
449             int value = XINT (in_rtx, i);
450             const char *name;
451
452 #ifndef GENERATOR_FILE
453             if (REG_P (in_rtx) && value < FIRST_PSEUDO_REGISTER)
454               fprintf (outfile, " %d %s", REGNO (in_rtx),
455                        reg_names[REGNO (in_rtx)]);
456             else if (REG_P (in_rtx)
457                      && value <= LAST_VIRTUAL_REGISTER)
458               {
459                 if (value == VIRTUAL_INCOMING_ARGS_REGNUM)
460                   fprintf (outfile, " %d virtual-incoming-args", value);
461                 else if (value == VIRTUAL_STACK_VARS_REGNUM)
462                   fprintf (outfile, " %d virtual-stack-vars", value);
463                 else if (value == VIRTUAL_STACK_DYNAMIC_REGNUM)
464                   fprintf (outfile, " %d virtual-stack-dynamic", value);
465                 else if (value == VIRTUAL_OUTGOING_ARGS_REGNUM)
466                   fprintf (outfile, " %d virtual-outgoing-args", value);
467                 else if (value == VIRTUAL_CFA_REGNUM)
468                   fprintf (outfile, " %d virtual-cfa", value);
469                 else if (value == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
470                   fprintf (outfile, " %d virtual-preferred-stack-boundary",
471                            value);
472                 else
473                   fprintf (outfile, " %d virtual-reg-%d", value,
474                            value-FIRST_VIRTUAL_REGISTER);
475               }
476             else
477 #endif
478               if (flag_dump_unnumbered
479                      && (is_insn || NOTE_P (in_rtx)))
480               fputc ('#', outfile);
481             else
482               fprintf (outfile, " %d", value);
483
484 #ifndef GENERATOR_FILE
485             if (REG_P (in_rtx) && REG_ATTRS (in_rtx))
486               {
487                 fputs (" [", outfile);
488                 if (ORIGINAL_REGNO (in_rtx) != REGNO (in_rtx))
489                   fprintf (outfile, "orig:%i", ORIGINAL_REGNO (in_rtx));
490                 if (REG_EXPR (in_rtx))
491                   print_mem_expr (outfile, REG_EXPR (in_rtx));
492
493                 if (REG_OFFSET (in_rtx))
494                   fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
495                            REG_OFFSET (in_rtx));
496                 fputs (" ]", outfile);
497               }
498 #endif
499
500             if (is_insn && &INSN_CODE (in_rtx) == &XINT (in_rtx, i)
501                 && XINT (in_rtx, i) >= 0
502                 && (name = get_insn_name (XINT (in_rtx, i))) != NULL)
503               fprintf (outfile, " {%s}", name);
504             sawclose = 0;
505           }
506         break;
507
508       /* Print NOTE_INSN names rather than integer codes.  */
509
510       case 'n':
511         fprintf (outfile, " %s", GET_NOTE_INSN_NAME (XINT (in_rtx, i)));
512         sawclose = 0;
513         break;
514
515       case 'u':
516         if (XEXP (in_rtx, i) != NULL)
517           {
518             rtx sub = XEXP (in_rtx, i);
519             enum rtx_code subc = GET_CODE (sub);
520
521             if (GET_CODE (in_rtx) == LABEL_REF)
522               {
523                 if (subc == NOTE
524                     && NOTE_KIND (sub) == NOTE_INSN_DELETED_LABEL)
525                   {
526                     if (flag_dump_unnumbered)
527                       fprintf (outfile, " [# deleted]");
528                     else
529                       fprintf (outfile, " [%d deleted]", INSN_UID (sub));
530                     sawclose = 0;
531                     break;
532                   }
533
534                 if (subc != CODE_LABEL)
535                   goto do_e;
536               }
537
538             if (flag_dump_unnumbered
539                 || (flag_dump_unnumbered_links && (i == 1 || i == 2)
540                     && (INSN_P (in_rtx) || NOTE_P (in_rtx)
541                         || LABEL_P (in_rtx) || BARRIER_P (in_rtx))))
542               fputs (" #", outfile);
543             else
544               fprintf (outfile, " %d", INSN_UID (sub));
545           }
546         else
547           fputs (" 0", outfile);
548         sawclose = 0;
549         break;
550
551       case 't':
552 #ifndef GENERATOR_FILE
553         if (i == 0 && GET_CODE (in_rtx) == DEBUG_IMPLICIT_PTR)
554           print_mem_expr (outfile, DEBUG_IMPLICIT_PTR_DECL (in_rtx));
555         else
556           dump_addr (outfile, " ", XTREE (in_rtx, i));
557 #endif
558         break;
559
560       case '*':
561         fputs (" Unknown", outfile);
562         sawclose = 0;
563         break;
564
565       case 'B':
566 #ifndef GENERATOR_FILE
567         if (XBBDEF (in_rtx, i))
568           fprintf (outfile, " %i", XBBDEF (in_rtx, i)->index);
569 #endif
570         break;
571
572       default:
573         gcc_unreachable ();
574       }
575
576   switch (GET_CODE (in_rtx))
577     {
578 #ifndef GENERATOR_FILE
579     case MEM:
580       if (__builtin_expect (final_insns_dump_p, false))
581         fprintf (outfile, " [");
582       else
583         fprintf (outfile, " [" HOST_WIDE_INT_PRINT_DEC,
584                  (HOST_WIDE_INT) MEM_ALIAS_SET (in_rtx));
585
586       if (MEM_EXPR (in_rtx))
587         print_mem_expr (outfile, MEM_EXPR (in_rtx));
588
589       if (MEM_OFFSET (in_rtx))
590         fprintf (outfile, "+" HOST_WIDE_INT_PRINT_DEC,
591                  INTVAL (MEM_OFFSET (in_rtx)));
592
593       if (MEM_SIZE (in_rtx))
594         fprintf (outfile, " S" HOST_WIDE_INT_PRINT_DEC,
595                  INTVAL (MEM_SIZE (in_rtx)));
596
597       if (MEM_ALIGN (in_rtx) != 1)
598         fprintf (outfile, " A%u", MEM_ALIGN (in_rtx));
599
600       if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (in_rtx)))
601         fprintf (outfile, " AS%u", MEM_ADDR_SPACE (in_rtx));
602
603       fputc (']', outfile);
604       break;
605
606     case CONST_DOUBLE:
607       if (FLOAT_MODE_P (GET_MODE (in_rtx)))
608         {
609           char s[60];
610
611           real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
612                            sizeof (s), 0, 1);
613           fprintf (outfile, " %s", s);
614
615           real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
616                                sizeof (s), 0, 1);
617           fprintf (outfile, " [%s]", s);
618         }
619       break;
620 #endif
621
622     case CODE_LABEL:
623       fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
624       switch (LABEL_KIND (in_rtx))
625         {
626           case LABEL_NORMAL: break;
627           case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
628           case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
629           case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
630           default: gcc_unreachable ();
631         }
632       break;
633
634     default:
635       break;
636     }
637
638   if (dump_for_graph
639       && (is_insn || NOTE_P (in_rtx)
640           || LABEL_P (in_rtx) || BARRIER_P (in_rtx)))
641     sawclose = 0;
642   else
643     {
644       fputc (')', outfile);
645       sawclose = 1;
646     }
647 }
648
649 /* Print an rtx on the current line of FILE.  Initially indent IND
650    characters.  */
651
652 void
653 print_inline_rtx (FILE *outf, const_rtx x, int ind)
654 {
655   int oldsaw = sawclose;
656   int oldindent = indent;
657
658   sawclose = 0;
659   indent = ind;
660   outfile = outf;
661   print_rtx (x);
662   sawclose = oldsaw;
663   indent = oldindent;
664 }
665
666 /* Call this function from the debugger to see what X looks like.  */
667
668 DEBUG_FUNCTION void
669 debug_rtx (const_rtx x)
670 {
671   outfile = stderr;
672   sawclose = 0;
673   print_rtx (x);
674   fprintf (stderr, "\n");
675 }
676
677 /* Count of rtx's to print with debug_rtx_list.
678    This global exists because gdb user defined commands have no arguments.  */
679
680 DEBUG_VARIABLE int debug_rtx_count = 0; /* 0 is treated as equivalent to 1 */
681
682 /* Call this function to print list from X on.
683
684    N is a count of the rtx's to print. Positive values print from the specified
685    rtx on.  Negative values print a window around the rtx.
686    EG: -5 prints 2 rtx's on either side (in addition to the specified rtx).  */
687
688 DEBUG_FUNCTION void
689 debug_rtx_list (const_rtx x, int n)
690 {
691   int i,count;
692   const_rtx insn;
693
694   count = n == 0 ? 1 : n < 0 ? -n : n;
695
696   /* If we are printing a window, back up to the start.  */
697
698   if (n < 0)
699     for (i = count / 2; i > 0; i--)
700       {
701         if (PREV_INSN (x) == 0)
702           break;
703         x = PREV_INSN (x);
704       }
705
706   for (i = count, insn = x; i > 0 && insn != 0; i--, insn = NEXT_INSN (insn))
707     {
708       debug_rtx (insn);
709       fprintf (stderr, "\n");
710     }
711 }
712
713 /* Call this function to print an rtx list from START to END inclusive.  */
714
715 DEBUG_FUNCTION void
716 debug_rtx_range (const_rtx start, const_rtx end)
717 {
718   while (1)
719     {
720       debug_rtx (start);
721       fprintf (stderr, "\n");
722       if (!start || start == end)
723         break;
724       start = NEXT_INSN (start);
725     }
726 }
727
728 /* Call this function to search an rtx list to find one with insn uid UID,
729    and then call debug_rtx_list to print it, using DEBUG_RTX_COUNT.
730    The found insn is returned to enable further debugging analysis.  */
731
732 DEBUG_FUNCTION const_rtx
733 debug_rtx_find (const_rtx x, int uid)
734 {
735   while (x != 0 && INSN_UID (x) != uid)
736     x = NEXT_INSN (x);
737   if (x != 0)
738     {
739       debug_rtx_list (x, debug_rtx_count);
740       return x;
741     }
742   else
743     {
744       fprintf (stderr, "insn uid %d not found\n", uid);
745       return 0;
746     }
747 }
748
749 /* External entry point for printing a chain of insns
750    starting with RTX_FIRST onto file OUTF.
751    A blank line separates insns.
752
753    If RTX_FIRST is not an insn, then it alone is printed, with no newline.  */
754
755 void
756 print_rtl (FILE *outf, const_rtx rtx_first)
757 {
758   const_rtx tmp_rtx;
759
760   outfile = outf;
761   sawclose = 0;
762
763   if (rtx_first == 0)
764     {
765       fputs (print_rtx_head, outf);
766       fputs ("(nil)\n", outf);
767     }
768   else
769     switch (GET_CODE (rtx_first))
770       {
771       case INSN:
772       case JUMP_INSN:
773       case CALL_INSN:
774       case NOTE:
775       case CODE_LABEL:
776       case BARRIER:
777         for (tmp_rtx = rtx_first; tmp_rtx != 0; tmp_rtx = NEXT_INSN (tmp_rtx))
778           {
779             fputs (print_rtx_head, outfile);
780             print_rtx (tmp_rtx);
781             fprintf (outfile, "\n");
782           }
783         break;
784
785       default:
786         fputs (print_rtx_head, outfile);
787         print_rtx (rtx_first);
788       }
789 }
790
791 /* Like print_rtx, except specify a file.  */
792 /* Return nonzero if we actually printed anything.  */
793
794 int
795 print_rtl_single (FILE *outf, const_rtx x)
796 {
797   outfile = outf;
798   sawclose = 0;
799   fputs (print_rtx_head, outfile);
800   print_rtx (x);
801   putc ('\n', outf);
802   return 1;
803 }
804
805
806 /* Like print_rtl except without all the detail; for example,
807    if RTX is a CONST_INT then print in decimal format.  */
808
809 void
810 print_simple_rtl (FILE *outf, const_rtx x)
811 {
812   flag_simple = 1;
813   print_rtl (outf, x);
814   flag_simple = 0;
815 }