OSDN Git Service

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