OSDN Git Service

2011-10-18 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / gimple-pretty-print.c
1 /* Pretty formatting of GIMPLE statements and expressions.
2    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
3    2011  Free Software Foundation, Inc.
4    Contributed by Aldy Hernandez <aldyh@redhat.com> and
5    Diego Novillo <dnovillo@google.com>
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3.  If not see
21 <http://www.gnu.org/licenses/>.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "diagnostic.h"
29 #include "tree-pretty-print.h"
30 #include "gimple-pretty-print.h"
31 #include "hashtab.h"
32 #include "tree-flow.h"
33 #include "tree-pass.h"
34 #include "gimple.h"
35 #include "value-prof.h"
36
37 #define INDENT(SPACE)                                                   \
38   do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
39
40 static pretty_printer buffer;
41 static bool initialized = false;
42
43 #define GIMPLE_NIY do_niy (buffer,gs)
44
45 /* Try to print on BUFFER a default message for the unrecognized
46    gimple statement GS.  */
47
48 static void
49 do_niy (pretty_printer *buffer, gimple gs)
50 {
51   pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
52              gimple_code_name[(int) gimple_code (gs)]);
53 }
54
55
56 /* Initialize the pretty printer on FILE if needed.  */
57
58 static void
59 maybe_init_pretty_print (FILE *file)
60 {
61   if (!initialized)
62     {
63       pp_construct (&buffer, NULL, 0);
64       pp_needs_newline (&buffer) = true;
65       initialized = true;
66     }
67
68   buffer.buffer->stream = file;
69 }
70
71
72 /* Emit a newline and SPC indentantion spaces to BUFFER.  */
73
74 static void
75 newline_and_indent (pretty_printer *buffer, int spc)
76 {
77   pp_newline (buffer);
78   INDENT (spc);
79 }
80
81
82 /* Print the GIMPLE statement GS on stderr.  */
83
84 DEBUG_FUNCTION void
85 debug_gimple_stmt (gimple gs)
86 {
87   print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
88   fprintf (stderr, "\n");
89 }
90
91
92 /* Dump GIMPLE statement G to FILE using SPC indentantion spaces and
93    FLAGS as in dump_gimple_stmt.  */
94
95 void
96 print_gimple_stmt (FILE *file, gimple g, int spc, int flags)
97 {
98   maybe_init_pretty_print (file);
99   dump_gimple_stmt (&buffer, g, spc, flags);
100   pp_flush (&buffer);
101 }
102
103
104 /* Dump GIMPLE statement G to FILE using SPC indentantion spaces and
105    FLAGS as in dump_gimple_stmt.  Print only the right-hand side
106    of the statement.  */
107
108 void
109 print_gimple_expr (FILE *file, gimple g, int spc, int flags)
110 {
111   flags |= TDF_RHS_ONLY;
112   maybe_init_pretty_print (file);
113   dump_gimple_stmt (&buffer, g, spc, flags);
114 }
115
116
117 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentantion
118    spaces and FLAGS as in dump_gimple_stmt.  */
119
120 static void
121 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc, int flags)
122 {
123   gimple_stmt_iterator i;
124
125   for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
126     {
127       gimple gs = gsi_stmt (i);
128       INDENT (spc);
129       dump_gimple_stmt (buffer, gs, spc, flags);
130       if (!gsi_one_before_end_p (i))
131         pp_newline (buffer);
132     }
133 }
134
135
136 /* Dump GIMPLE sequence SEQ to FILE using SPC indentantion spaces and
137    FLAGS as in dump_gimple_stmt.  */
138
139 void
140 print_gimple_seq (FILE *file, gimple_seq seq, int spc, int flags)
141 {
142   maybe_init_pretty_print (file);
143   dump_gimple_seq (&buffer, seq, spc, flags);
144   pp_flush (&buffer);
145 }
146
147
148 /* Print the GIMPLE sequence SEQ on stderr.  */
149
150 DEBUG_FUNCTION void
151 debug_gimple_seq (gimple_seq seq)
152 {
153   print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
154 }
155
156
157 /* A simple helper to pretty-print some of the gimple tuples in the printf
158    style. The format modifiers are preceeded by '%' and are:
159      'G' - outputs a string corresponding to the code of the given gimple,
160      'S' - outputs a gimple_seq with indent of spc + 2,
161      'T' - outputs the tree t,
162      'd' - outputs an int as a decimal,
163      's' - outputs a string,
164      'n' - outputs a newline,
165      '+' - increases indent by 2 then outputs a newline,
166      '-' - decreases indent by 2 then outputs a newline.   */
167
168 static void
169 dump_gimple_fmt (pretty_printer *buffer, int spc, int flags,
170                  const char *fmt, ...)
171 {
172   va_list args;
173   const char *c;
174   const char *tmp;
175
176   va_start (args, fmt);
177   for (c = fmt; *c; c++)
178     {
179       if (*c == '%')
180         {
181           gimple_seq seq;
182           tree t;
183           gimple g;
184           switch (*++c)
185             {
186               case 'G':
187                 g = va_arg (args, gimple);
188                 tmp = gimple_code_name[gimple_code (g)];
189                 pp_string (buffer, tmp);
190                 break;
191
192               case 'S':
193                 seq = va_arg (args, gimple_seq);
194                 pp_newline (buffer);
195                 dump_gimple_seq (buffer, seq, spc + 2, flags);
196                 newline_and_indent (buffer, spc);
197                 break;
198
199               case 'T':
200                 t = va_arg (args, tree);
201                 if (t == NULL_TREE)
202                   pp_string (buffer, "NULL");
203                 else
204                   dump_generic_node (buffer, t, spc, flags, false);
205                 break;
206
207               case 'd':
208                 pp_decimal_int (buffer, va_arg (args, int));
209                 break;
210
211               case 's':
212                 pp_string (buffer, va_arg (args, char *));
213                 break;
214
215               case 'n':
216                 newline_and_indent (buffer, spc);
217                 break;
218
219               case '+':
220                 spc += 2;
221                 newline_and_indent (buffer, spc);
222                 break;
223
224               case '-':
225                 spc -= 2;
226                 newline_and_indent (buffer, spc);
227                 break;
228
229               default:
230                 gcc_unreachable ();
231             }
232         }
233       else
234         pp_character (buffer, *c);
235     }
236   va_end (args);
237 }
238
239
240 /* Helper for dump_gimple_assign.  Print the unary RHS of the
241    assignment GS.  BUFFER, SPC and FLAGS are as in dump_gimple_stmt.  */
242
243 static void
244 dump_unary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
245 {
246   enum tree_code rhs_code = gimple_assign_rhs_code (gs);
247   tree lhs = gimple_assign_lhs (gs);
248   tree rhs = gimple_assign_rhs1 (gs);
249
250   switch (rhs_code)
251     {
252     case VIEW_CONVERT_EXPR:
253     case ASSERT_EXPR:
254       dump_generic_node (buffer, rhs, spc, flags, false);
255       break;
256
257     case FIXED_CONVERT_EXPR:
258     case ADDR_SPACE_CONVERT_EXPR:
259     case FIX_TRUNC_EXPR:
260     case FLOAT_EXPR:
261     CASE_CONVERT:
262       pp_character (buffer, '(');
263       dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
264       pp_string (buffer, ") ");
265       if (op_prio (rhs) < op_code_prio (rhs_code))
266         {
267           pp_character (buffer, '(');
268           dump_generic_node (buffer, rhs, spc, flags, false);
269           pp_character (buffer, ')');
270         }
271       else
272         dump_generic_node (buffer, rhs, spc, flags, false);
273       break;
274
275     case PAREN_EXPR:
276       pp_string (buffer, "((");
277       dump_generic_node (buffer, rhs, spc, flags, false);
278       pp_string (buffer, "))");
279       break;
280
281     case ABS_EXPR:
282       pp_string (buffer, "ABS_EXPR <");
283       dump_generic_node (buffer, rhs, spc, flags, false);
284       pp_character (buffer, '>');
285       break;
286
287     default:
288       if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
289           || TREE_CODE_CLASS (rhs_code) == tcc_constant
290           || TREE_CODE_CLASS (rhs_code) == tcc_reference
291           || rhs_code == SSA_NAME
292           || rhs_code == ADDR_EXPR
293           || rhs_code == CONSTRUCTOR)
294         {
295           dump_generic_node (buffer, rhs, spc, flags, false);
296           break;
297         }
298       else if (rhs_code == BIT_NOT_EXPR)
299         pp_character (buffer, '~');
300       else if (rhs_code == TRUTH_NOT_EXPR)
301         pp_character (buffer, '!');
302       else if (rhs_code == NEGATE_EXPR)
303         pp_character (buffer, '-');
304       else
305         {
306           pp_character (buffer, '[');
307           pp_string (buffer, tree_code_name [rhs_code]);
308           pp_string (buffer, "] ");
309         }
310
311       if (op_prio (rhs) < op_code_prio (rhs_code))
312         {
313           pp_character (buffer, '(');
314           dump_generic_node (buffer, rhs, spc, flags, false);
315           pp_character (buffer, ')');
316         }
317       else
318         dump_generic_node (buffer, rhs, spc, flags, false);
319       break;
320     }
321 }
322
323
324 /* Helper for dump_gimple_assign.  Print the binary RHS of the
325    assignment GS.  BUFFER, SPC and FLAGS are as in dump_gimple_stmt.  */
326
327 static void
328 dump_binary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
329 {
330   const char *p;
331   enum tree_code code = gimple_assign_rhs_code (gs);
332   switch (code)
333     {
334     case COMPLEX_EXPR:
335     case MIN_EXPR:
336     case MAX_EXPR:
337     case VEC_WIDEN_MULT_HI_EXPR:
338     case VEC_WIDEN_MULT_LO_EXPR:
339     case VEC_PACK_TRUNC_EXPR:
340     case VEC_PACK_SAT_EXPR:
341     case VEC_PACK_FIX_TRUNC_EXPR:
342     case VEC_EXTRACT_EVEN_EXPR:
343     case VEC_EXTRACT_ODD_EXPR:
344     case VEC_INTERLEAVE_HIGH_EXPR:
345     case VEC_INTERLEAVE_LOW_EXPR:
346       for (p = tree_code_name [(int) code]; *p; p++)
347         pp_character (buffer, TOUPPER (*p));
348       pp_string (buffer, " <");
349       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
350       pp_string (buffer, ", ");
351       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
352       pp_character (buffer, '>');
353       break;
354
355     default:
356       if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
357         {
358           pp_character (buffer, '(');
359           dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
360                              false);
361           pp_character (buffer, ')');
362         }
363       else
364         dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
365       pp_space (buffer);
366       pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
367       pp_space (buffer);
368       if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
369         {
370           pp_character (buffer, '(');
371           dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
372                              false);
373           pp_character (buffer, ')');
374         }
375       else
376         dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
377     }
378 }
379
380 /* Helper for dump_gimple_assign.  Print the ternary RHS of the
381    assignment GS.  BUFFER, SPC and FLAGS are as in dump_gimple_stmt.  */
382
383 static void
384 dump_ternary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
385 {
386   const char *p;
387   enum tree_code code = gimple_assign_rhs_code (gs);
388   switch (code)
389     {
390     case WIDEN_MULT_PLUS_EXPR:
391     case WIDEN_MULT_MINUS_EXPR:
392       for (p = tree_code_name [(int) code]; *p; p++)
393         pp_character (buffer, TOUPPER (*p));
394       pp_string (buffer, " <");
395       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
396       pp_string (buffer, ", ");
397       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
398       pp_string (buffer, ", ");
399       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
400       pp_character (buffer, '>');
401       break;
402
403     case FMA_EXPR:
404       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
405       pp_string (buffer, " * ");
406       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
407       pp_string (buffer, " + ");
408       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
409       break;
410
411     case DOT_PROD_EXPR:
412       pp_string (buffer, "DOT_PROD_EXPR <");
413       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
414       pp_string (buffer, ", ");
415       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
416       pp_string (buffer, ", ");
417       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
418       pp_string (buffer, ">");
419       break;
420     
421     case VEC_PERM_EXPR:
422       pp_string (buffer, "VEC_PERM_EXPR <");
423       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
424       pp_string (buffer, ", ");
425       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
426       pp_string (buffer, ", ");
427       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
428       pp_string (buffer, ">");
429       break;
430
431     case REALIGN_LOAD_EXPR:
432       pp_string (buffer, "REALIGN_LOAD <");
433       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
434       pp_string (buffer, ", ");
435       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
436       pp_string (buffer, ", ");
437       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
438       pp_string (buffer, ">");
439       break;
440
441     case COND_EXPR:
442       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
443       pp_string (buffer, " ? ");
444       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
445       pp_string (buffer, " : ");
446       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
447       break;
448
449     case VEC_COND_EXPR:
450       pp_string (buffer, "VEC_COND_EXPR <");
451       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
452       pp_string (buffer, ", ");
453       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
454       pp_string (buffer, ", ");
455       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
456       pp_string (buffer, ">");
457       break;
458
459     default:
460       gcc_unreachable ();
461     }
462 }
463
464
465 /* Dump the gimple assignment GS.  BUFFER, SPC and FLAGS are as in
466    dump_gimple_stmt.  */
467
468 static void
469 dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
470 {
471   if (flags & TDF_RAW)
472     {
473       tree last;
474       if (gimple_num_ops (gs) == 2)
475         last = NULL_TREE;
476       else if (gimple_num_ops (gs) == 3)
477         last = gimple_assign_rhs2 (gs);
478       else
479         gcc_unreachable ();
480
481       dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T>", gs,
482                        tree_code_name[gimple_assign_rhs_code (gs)],
483                        gimple_assign_lhs (gs), gimple_assign_rhs1 (gs), last);
484     }
485   else
486     {
487       if (!(flags & TDF_RHS_ONLY))
488         {
489           dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
490           pp_space (buffer);
491           pp_character (buffer, '=');
492
493           if (gimple_assign_nontemporal_move_p (gs))
494             pp_string (buffer, "{nt}");
495
496           if (gimple_has_volatile_ops (gs))
497             pp_string (buffer, "{v}");
498
499           pp_space (buffer);
500         }
501
502       if (gimple_num_ops (gs) == 2)
503         dump_unary_rhs (buffer, gs, spc, flags);
504       else if (gimple_num_ops (gs) == 3)
505         dump_binary_rhs (buffer, gs, spc, flags);
506       else if (gimple_num_ops (gs) == 4)
507         dump_ternary_rhs (buffer, gs, spc, flags);
508       else
509         gcc_unreachable ();
510       if (!(flags & TDF_RHS_ONLY))
511         pp_semicolon(buffer);
512     }
513 }
514
515
516 /* Dump the return statement GS.  BUFFER, SPC and FLAGS are as in
517    dump_gimple_stmt.  */
518
519 static void
520 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
521 {
522   tree t;
523
524   t = gimple_return_retval (gs);
525   if (flags & TDF_RAW)
526     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
527   else
528     {
529       pp_string (buffer, "return");
530       if (t)
531         {
532           pp_space (buffer);
533           dump_generic_node (buffer, t, spc, flags, false);
534         }
535       pp_semicolon (buffer);
536     }
537 }
538
539
540 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
541    dump_gimple_call.  */
542
543 static void
544 dump_gimple_call_args (pretty_printer *buffer, gimple gs, int flags)
545 {
546   size_t i;
547
548   for (i = 0; i < gimple_call_num_args (gs); i++)
549     {
550       dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
551       if (i < gimple_call_num_args (gs) - 1)
552         pp_string (buffer, ", ");
553     }
554
555   if (gimple_call_va_arg_pack_p (gs))
556     {
557       if (gimple_call_num_args (gs) > 0)
558         {
559           pp_character (buffer, ',');
560           pp_space (buffer);
561         }
562
563       pp_string (buffer, "__builtin_va_arg_pack ()");
564     }
565 }
566
567 /* Dump the points-to solution *PT to BUFFER.  */
568
569 static void
570 pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
571 {
572   if (pt->anything)
573     {
574       pp_string (buffer, "anything ");
575       return;
576     }
577   if (pt->nonlocal)
578     pp_string (buffer, "nonlocal ");
579   if (pt->escaped)
580     pp_string (buffer, "escaped ");
581   if (pt->ipa_escaped)
582     pp_string (buffer, "unit-escaped ");
583   if (pt->null)
584     pp_string (buffer, "null ");
585   if (pt->vars
586       && !bitmap_empty_p (pt->vars))
587     {
588       bitmap_iterator bi;
589       unsigned i;
590       pp_string (buffer, "{ ");
591       EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
592         {
593           tree var = referenced_var_lookup (cfun, i);
594           if (var)
595             {
596               dump_generic_node (buffer, var, 0, dump_flags, false);
597               if (DECL_PT_UID (var) != DECL_UID (var))
598                 {
599                   pp_string (buffer, "ptD.");
600                   pp_decimal_int (buffer, DECL_PT_UID (var));
601                 }
602             }
603           else
604             {
605               pp_string (buffer, "D.");
606               pp_decimal_int (buffer, i);
607             }
608           pp_character (buffer, ' ');
609         }
610       pp_character (buffer, '}');
611       if (pt->vars_contains_global)
612         pp_string (buffer, " (glob)");
613     }
614 }
615
616 /* Dump the call statement GS.  BUFFER, SPC and FLAGS are as in
617    dump_gimple_stmt.  */
618
619 static void
620 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
621 {
622   tree lhs = gimple_call_lhs (gs);
623
624   if (flags & TDF_ALIAS)
625     {
626       struct pt_solution *pt;
627       pt = gimple_call_use_set (gs);
628       if (!pt_solution_empty_p (pt))
629         {
630           pp_string (buffer, "# USE = ");
631           pp_points_to_solution (buffer, pt);
632           newline_and_indent (buffer, spc);
633         }
634       pt = gimple_call_clobber_set (gs);
635       if (!pt_solution_empty_p (pt))
636         {
637           pp_string (buffer, "# CLB = ");
638           pp_points_to_solution (buffer, pt);
639           newline_and_indent (buffer, spc);
640         }
641     }
642
643   if (flags & TDF_RAW)
644     {
645       if (gimple_call_internal_p (gs))
646         dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T", gs,
647                          internal_fn_name (gimple_call_internal_fn (gs)), lhs);
648       else
649         dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T",
650                          gs, gimple_call_fn (gs), lhs);
651       if (gimple_call_num_args (gs) > 0)
652         {
653           pp_string (buffer, ", ");
654           dump_gimple_call_args (buffer, gs, flags);
655         }
656       pp_character (buffer, '>');
657     }
658   else
659     {
660       if (lhs && !(flags & TDF_RHS_ONLY))
661         {
662           dump_generic_node (buffer, lhs, spc, flags, false);
663           pp_string (buffer, " =");
664
665           if (gimple_has_volatile_ops (gs))
666             pp_string (buffer, "{v}");
667
668           pp_space (buffer);
669         }
670       if (gimple_call_internal_p (gs))
671         pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
672       else
673         print_call_name (buffer, gimple_call_fn (gs), flags);
674       pp_string (buffer, " (");
675       dump_gimple_call_args (buffer, gs, flags);
676       pp_character (buffer, ')');
677       if (!(flags & TDF_RHS_ONLY))
678         pp_semicolon (buffer);
679     }
680
681   if (gimple_call_chain (gs))
682     {
683       pp_string (buffer, " [static-chain: ");
684       dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
685       pp_character (buffer, ']');
686     }
687
688   if (gimple_call_return_slot_opt_p (gs))
689     pp_string (buffer, " [return slot optimization]");
690
691   if (gimple_call_tail_p (gs))
692     pp_string (buffer, " [tail call]");
693 }
694
695
696 /* Dump the switch statement GS.  BUFFER, SPC and FLAGS are as in
697    dump_gimple_stmt.  */
698
699 static void
700 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
701 {
702   unsigned int i;
703
704   GIMPLE_CHECK (gs, GIMPLE_SWITCH);
705   if (flags & TDF_RAW)
706     dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
707                    gimple_switch_index (gs));
708   else
709     {
710       pp_string (buffer, "switch (");
711       dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
712       pp_string (buffer, ") <");
713     }
714
715   for (i = 0; i < gimple_switch_num_labels (gs); i++)
716     {
717       tree case_label = gimple_switch_label (gs, i);
718       if (case_label == NULL_TREE)
719         continue;
720
721       dump_generic_node (buffer, case_label, spc, flags, false);
722       pp_character (buffer, ' ');
723       dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
724       if (i < gimple_switch_num_labels (gs) - 1)
725         pp_string (buffer, ", ");
726     }
727   pp_character (buffer, '>');
728 }
729
730
731 /* Dump the gimple conditional GS.  BUFFER, SPC and FLAGS are as in
732    dump_gimple_stmt.  */
733
734 static void
735 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
736 {
737   if (flags & TDF_RAW)
738     dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
739                    tree_code_name [gimple_cond_code (gs)],
740                    gimple_cond_lhs (gs), gimple_cond_rhs (gs),
741                    gimple_cond_true_label (gs), gimple_cond_false_label (gs));
742   else
743     {
744       if (!(flags & TDF_RHS_ONLY))
745         pp_string (buffer, "if (");
746       dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
747       pp_space (buffer);
748       pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
749       pp_space (buffer);
750       dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
751       if (!(flags & TDF_RHS_ONLY))
752         {
753           pp_character (buffer, ')');
754
755           if (gimple_cond_true_label (gs))
756             {
757               pp_string (buffer, " goto ");
758               dump_generic_node (buffer, gimple_cond_true_label (gs),
759                                  spc, flags, false);
760               pp_semicolon (buffer);
761             }
762           if (gimple_cond_false_label (gs))
763             {
764               pp_string (buffer, " else goto ");
765               dump_generic_node (buffer, gimple_cond_false_label (gs),
766                                  spc, flags, false);
767               pp_semicolon (buffer);
768             }
769         }
770     }
771 }
772
773
774 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
775    spaces of indent.  FLAGS specifies details to show in the dump (see
776    TDF_* in tree-pass.h).  */
777
778 static void
779 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
780 {
781   tree label = gimple_label_label (gs);
782   if (flags & TDF_RAW)
783       dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
784   else
785     {
786       dump_generic_node (buffer, label, spc, flags, false);
787       pp_character (buffer, ':');
788     }
789   if (DECL_NONLOCAL (label))
790     pp_string (buffer, " [non-local]");
791   if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
792     pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
793 }
794
795 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
796    spaces of indent.  FLAGS specifies details to show in the dump (see
797    TDF_* in tree-pass.h).  */
798
799 static void
800 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
801 {
802   tree label = gimple_goto_dest (gs);
803   if (flags & TDF_RAW)
804     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
805   else
806     dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
807 }
808
809
810 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
811    spaces of indent.  FLAGS specifies details to show in the dump (see
812    TDF_* in tree-pass.h).  */
813
814 static void
815 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
816 {
817   if (flags & TDF_RAW)
818     dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
819   else
820     pp_character (buffer, '{');
821   if (!(flags & TDF_SLIM))
822     {
823       tree var;
824
825       for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
826         {
827           newline_and_indent (buffer, 2);
828           print_declaration (buffer, var, spc, flags);
829         }
830       if (gimple_bind_vars (gs))
831         pp_newline (buffer);
832     }
833   pp_newline (buffer);
834   dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
835   newline_and_indent (buffer, spc);
836   if (flags & TDF_RAW)
837     pp_character (buffer, '>');
838   else
839     pp_character (buffer, '}');
840 }
841
842
843 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
844    indent.  FLAGS specifies details to show in the dump (see TDF_* in
845    tree-pass.h).  */
846
847 static void
848 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
849 {
850   if (flags & TDF_RAW)
851     {
852       const char *type;
853       if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
854         type = "GIMPLE_TRY_CATCH";
855       else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
856         type = "GIMPLE_TRY_FINALLY";
857       else
858         type = "UNKNOWN GIMPLE_TRY";
859       dump_gimple_fmt (buffer, spc, flags,
860                        "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
861                        gimple_try_eval (gs), gimple_try_cleanup (gs));
862     }
863   else
864     {
865       pp_string (buffer, "try");
866       newline_and_indent (buffer, spc + 2);
867       pp_character (buffer, '{');
868       pp_newline (buffer);
869
870       dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
871       newline_and_indent (buffer, spc + 2);
872       pp_character (buffer, '}');
873
874       if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
875         {
876           newline_and_indent (buffer, spc);
877           pp_string (buffer, "catch");
878           newline_and_indent (buffer, spc + 2);
879           pp_character (buffer, '{');
880         }
881       else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
882         {
883           newline_and_indent (buffer, spc);
884           pp_string (buffer, "finally");
885           newline_and_indent (buffer, spc + 2);
886           pp_character (buffer, '{');
887         }
888       else
889         pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
890
891       pp_newline (buffer);
892       dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
893       newline_and_indent (buffer, spc + 2);
894       pp_character (buffer, '}');
895     }
896 }
897
898
899 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
900    indent.  FLAGS specifies details to show in the dump (see TDF_* in
901    tree-pass.h).  */
902
903 static void
904 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
905 {
906   if (flags & TDF_RAW)
907       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
908                        gimple_catch_types (gs), gimple_catch_handler (gs));
909   else
910       dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
911                        gimple_catch_types (gs), gimple_catch_handler (gs));
912 }
913
914
915 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
916    indent.  FLAGS specifies details to show in the dump (see TDF_* in
917    tree-pass.h).  */
918
919 static void
920 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
921 {
922   if (flags & TDF_RAW)
923     dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
924                      gimple_eh_filter_types (gs),
925                      gimple_eh_filter_failure (gs));
926   else
927     dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
928                      gimple_eh_filter_types (gs),
929                      gimple_eh_filter_failure (gs));
930 }
931
932
933 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple.  */
934
935 static void
936 dump_gimple_eh_must_not_throw (pretty_printer *buffer, gimple gs,
937                                int spc, int flags)
938 {
939   if (flags & TDF_RAW)
940     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
941                      gimple_eh_must_not_throw_fndecl (gs));
942   else
943     dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
944                      gimple_eh_must_not_throw_fndecl (gs));
945 }
946
947
948 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
949    indent.  FLAGS specifies details to show in the dump (see TDF_* in
950    tree-pass.h).  */
951
952 static void
953 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
954 {
955   if (flags & TDF_RAW)
956     dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
957                      gimple_resx_region (gs));
958   else
959     dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
960 }
961
962 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER.  */
963
964 static void
965 dump_gimple_eh_dispatch (pretty_printer *buffer, gimple gs, int spc, int flags)
966 {
967   if (flags & TDF_RAW)
968     dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
969                      gimple_eh_dispatch_region (gs));
970   else
971     dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
972                      gimple_eh_dispatch_region (gs));
973 }
974
975 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
976    of indent.  FLAGS specifies details to show in the dump (see TDF_*
977    in tree-pass.h).  */
978
979 static void
980 dump_gimple_debug (pretty_printer *buffer, gimple gs, int spc, int flags)
981 {
982   switch (gs->gsbase.subcode)
983     {
984     case GIMPLE_DEBUG_BIND:
985       if (flags & TDF_RAW)
986         dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
987                          gimple_debug_bind_get_var (gs),
988                          gimple_debug_bind_get_value (gs));
989       else
990         dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
991                          gimple_debug_bind_get_var (gs),
992                          gimple_debug_bind_get_value (gs));
993       break;
994
995     case GIMPLE_DEBUG_SOURCE_BIND:
996       if (flags & TDF_RAW)
997         dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
998                          gimple_debug_source_bind_get_var (gs),
999                          gimple_debug_source_bind_get_value (gs));
1000       else
1001         dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1002                          gimple_debug_source_bind_get_var (gs),
1003                          gimple_debug_source_bind_get_value (gs));
1004       break;
1005
1006     default:
1007       gcc_unreachable ();
1008     }
1009 }
1010
1011 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER.  */
1012 static void
1013 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
1014 {
1015   size_t i;
1016
1017   if (flags & TDF_RAW)
1018     {
1019       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1020                        gimple_omp_body (gs));
1021       dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1022       dump_gimple_fmt (buffer, spc, flags, " >,");
1023       for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1024         dump_gimple_fmt (buffer, spc, flags,
1025                          "%+%T, %T, %T, %s, %T,%n",
1026                          gimple_omp_for_index (gs, i),
1027                          gimple_omp_for_initial (gs, i),
1028                          gimple_omp_for_final (gs, i),
1029                          tree_code_name[gimple_omp_for_cond (gs, i)],
1030                          gimple_omp_for_incr (gs, i));
1031       dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1032                        gimple_omp_for_pre_body (gs));
1033     }
1034   else
1035     {
1036       pp_string (buffer, "#pragma omp for");
1037       dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1038       for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1039         {
1040           if (i)
1041             spc += 2;
1042           newline_and_indent (buffer, spc);
1043           pp_string (buffer, "for (");
1044           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1045                              flags, false);
1046           pp_string (buffer, " = ");
1047           dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1048                              flags, false);
1049           pp_string (buffer, "; ");
1050
1051           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1052                              flags, false);
1053           pp_space (buffer);
1054           switch (gimple_omp_for_cond (gs, i))
1055             {
1056             case LT_EXPR:
1057               pp_character (buffer, '<');
1058               break;
1059             case GT_EXPR:
1060               pp_character (buffer, '>');
1061               break;
1062             case LE_EXPR:
1063               pp_string (buffer, "<=");
1064               break;
1065             case GE_EXPR:
1066               pp_string (buffer, ">=");
1067               break;
1068             default:
1069               gcc_unreachable ();
1070             }
1071           pp_space (buffer);
1072           dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1073                              flags, false);
1074           pp_string (buffer, "; ");
1075
1076           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1077                              flags, false);
1078           pp_string (buffer, " = ");
1079           dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1080                              flags, false);
1081           pp_character (buffer, ')');
1082         }
1083
1084       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1085         {
1086           newline_and_indent (buffer, spc + 2);
1087           pp_character (buffer, '{');
1088           pp_newline (buffer);
1089           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1090           newline_and_indent (buffer, spc + 2);
1091           pp_character (buffer, '}');
1092         }
1093     }
1094 }
1095
1096 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER.  */
1097
1098 static void
1099 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
1100 {
1101   if (flags & TDF_RAW)
1102     {
1103       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1104                        gimple_omp_continue_control_def (gs),
1105                        gimple_omp_continue_control_use (gs));
1106     }
1107   else
1108     {
1109       pp_string (buffer, "#pragma omp continue (");
1110       dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1111                          spc, flags, false);
1112       pp_character (buffer, ',');
1113       pp_space (buffer);
1114       dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1115                          spc, flags, false);
1116       pp_character (buffer, ')');
1117     }
1118 }
1119
1120 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER.  */
1121
1122 static void
1123 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
1124 {
1125   if (flags & TDF_RAW)
1126     {
1127       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1128                        gimple_omp_body (gs));
1129       dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1130       dump_gimple_fmt (buffer, spc, flags, " >");
1131     }
1132   else
1133     {
1134       pp_string (buffer, "#pragma omp single");
1135       dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1136       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1137         {
1138           newline_and_indent (buffer, spc + 2);
1139           pp_character (buffer, '{');
1140           pp_newline (buffer);
1141           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1142           newline_and_indent (buffer, spc + 2);
1143           pp_character (buffer, '}');
1144         }
1145     }
1146 }
1147
1148 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER.  */
1149
1150 static void
1151 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
1152                           int flags)
1153 {
1154   if (flags & TDF_RAW)
1155     {
1156       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1157                        gimple_omp_body (gs));
1158       dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1159       dump_gimple_fmt (buffer, spc, flags, " >");
1160     }
1161   else
1162     {
1163       pp_string (buffer, "#pragma omp sections");
1164       if (gimple_omp_sections_control (gs))
1165         {
1166           pp_string (buffer, " <");
1167           dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1168                              flags, false);
1169           pp_character (buffer, '>');
1170         }
1171       dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1172       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1173         {
1174           newline_and_indent (buffer, spc + 2);
1175           pp_character (buffer, '{');
1176           pp_newline (buffer);
1177           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1178           newline_and_indent (buffer, spc + 2);
1179           pp_character (buffer, '}');
1180         }
1181     }
1182 }
1183
1184 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer
1185    BUFFER.  */
1186
1187 static void
1188 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
1189 {
1190   if (flags & TDF_RAW)
1191     dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1192                      gimple_omp_body (gs));
1193   else
1194     {
1195       switch (gimple_code (gs))
1196         {
1197         case GIMPLE_OMP_MASTER:
1198           pp_string (buffer, "#pragma omp master");
1199           break;
1200         case GIMPLE_OMP_ORDERED:
1201           pp_string (buffer, "#pragma omp ordered");
1202           break;
1203         case GIMPLE_OMP_SECTION:
1204           pp_string (buffer, "#pragma omp section");
1205           break;
1206         default:
1207           gcc_unreachable ();
1208         }
1209       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1210         {
1211           newline_and_indent (buffer, spc + 2);
1212           pp_character (buffer, '{');
1213           pp_newline (buffer);
1214           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1215           newline_and_indent (buffer, spc + 2);
1216           pp_character (buffer, '}');
1217         }
1218     }
1219 }
1220
1221 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER.  */
1222
1223 static void
1224 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
1225                           int flags)
1226 {
1227   if (flags & TDF_RAW)
1228     dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1229                      gimple_omp_body (gs));
1230   else
1231     {
1232       pp_string (buffer, "#pragma omp critical");
1233       if (gimple_omp_critical_name (gs))
1234         {
1235           pp_string (buffer, " (");
1236           dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1237                              flags, false);
1238           pp_character (buffer, ')');
1239         }
1240       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1241         {
1242           newline_and_indent (buffer, spc + 2);
1243           pp_character (buffer, '{');
1244           pp_newline (buffer);
1245           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1246           newline_and_indent (buffer, spc + 2);
1247           pp_character (buffer, '}');
1248         }
1249     }
1250 }
1251
1252 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER.  */
1253
1254 static void
1255 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1256 {
1257   if (flags & TDF_RAW)
1258     {
1259       dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d>", gs,
1260                        (int) gimple_omp_return_nowait_p (gs));
1261     }
1262   else
1263     {
1264       pp_string (buffer, "#pragma omp return");
1265       if (gimple_omp_return_nowait_p (gs))
1266         pp_string (buffer, "(nowait)");
1267     }
1268 }
1269
1270 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1271    indent.  FLAGS specifies details to show in the dump (see TDF_* in
1272    tree-pass.h).  */
1273
1274 static void
1275 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1276 {
1277   unsigned int i, n, f, fields;
1278
1279   if (flags & TDF_RAW)
1280     {
1281       dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1282                        gimple_asm_string (gs));
1283
1284       n = gimple_asm_noutputs (gs);
1285       if (n)
1286         {
1287           newline_and_indent (buffer, spc + 2);
1288           pp_string (buffer, "OUTPUT: ");
1289           for (i = 0; i < n; i++)
1290             {
1291               dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1292                                  spc, flags, false);
1293               if (i < n - 1)
1294                 pp_string (buffer, ", ");
1295             }
1296         }
1297
1298       n = gimple_asm_ninputs (gs);
1299       if (n)
1300         {
1301           newline_and_indent (buffer, spc + 2);
1302           pp_string (buffer, "INPUT: ");
1303           for (i = 0; i < n; i++)
1304             {
1305               dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1306                                  spc, flags, false);
1307               if (i < n - 1)
1308                 pp_string (buffer, ", ");
1309             }
1310         }
1311
1312       n = gimple_asm_nclobbers (gs);
1313       if (n)
1314         {
1315           newline_and_indent (buffer, spc + 2);
1316           pp_string (buffer, "CLOBBER: ");
1317           for (i = 0; i < n; i++)
1318             {
1319               dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1320                                  spc, flags, false);
1321               if (i < n - 1)
1322                 pp_string (buffer, ", ");
1323             }
1324         }
1325
1326       n = gimple_asm_nlabels (gs);
1327       if (n)
1328         {
1329           newline_and_indent (buffer, spc + 2);
1330           pp_string (buffer, "LABEL: ");
1331           for (i = 0; i < n; i++)
1332             {
1333               dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1334                                  spc, flags, false);
1335               if (i < n - 1)
1336                 pp_string (buffer, ", ");
1337             }
1338         }
1339
1340       newline_and_indent (buffer, spc);
1341       pp_character (buffer, '>');
1342     }
1343   else
1344     {
1345       pp_string (buffer, "__asm__");
1346       if (gimple_asm_volatile_p (gs))
1347         pp_string (buffer, " __volatile__");
1348       if (gimple_asm_nlabels (gs))
1349         pp_string (buffer, " goto");
1350       pp_string (buffer, "(\"");
1351       pp_string (buffer, gimple_asm_string (gs));
1352       pp_string (buffer, "\"");
1353
1354       if (gimple_asm_nlabels (gs))
1355         fields = 4;
1356       else if (gimple_asm_nclobbers (gs))
1357         fields = 3;
1358       else if (gimple_asm_ninputs (gs))
1359         fields = 2;
1360       else if (gimple_asm_noutputs (gs))
1361         fields = 1;
1362       else
1363         fields = 0;
1364
1365       for (f = 0; f < fields; ++f)
1366         {
1367           pp_string (buffer, " : ");
1368
1369           switch (f)
1370             {
1371             case 0:
1372               n = gimple_asm_noutputs (gs);
1373               for (i = 0; i < n; i++)
1374                 {
1375                   dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1376                                      spc, flags, false);
1377                   if (i < n - 1)
1378                     pp_string (buffer, ", ");
1379                 }
1380               break;
1381
1382             case 1:
1383               n = gimple_asm_ninputs (gs);
1384               for (i = 0; i < n; i++)
1385                 {
1386                   dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1387                                      spc, flags, false);
1388                   if (i < n - 1)
1389                     pp_string (buffer, ", ");
1390                 }
1391               break;
1392
1393             case 2:
1394               n = gimple_asm_nclobbers (gs);
1395               for (i = 0; i < n; i++)
1396                 {
1397                   dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1398                                      spc, flags, false);
1399                   if (i < n - 1)
1400                     pp_string (buffer, ", ");
1401                 }
1402               break;
1403
1404             case 3:
1405               n = gimple_asm_nlabels (gs);
1406               for (i = 0; i < n; i++)
1407                 {
1408                   dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1409                                      spc, flags, false);
1410                   if (i < n - 1)
1411                     pp_string (buffer, ", ");
1412                 }
1413               break;
1414
1415             default:
1416               gcc_unreachable ();
1417             }
1418         }
1419
1420       pp_string (buffer, ");");
1421     }
1422 }
1423
1424
1425 /* Dump a PHI node PHI.  BUFFER, SPC and FLAGS are as in
1426    dump_gimple_stmt.  */
1427
1428 static void
1429 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
1430 {
1431   size_t i;
1432   tree lhs = gimple_phi_result (phi);
1433
1434   if (flags & TDF_ALIAS
1435       && POINTER_TYPE_P (TREE_TYPE (lhs))
1436       && SSA_NAME_PTR_INFO (lhs))
1437     {
1438       struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
1439       pp_string (buffer, "PT = ");
1440       pp_points_to_solution (buffer, &pi->pt);
1441       newline_and_indent (buffer, spc);
1442       if (pi->align != 1)
1443         pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u",
1444                    pi->align, pi->misalign);
1445       newline_and_indent (buffer, spc);
1446       pp_string (buffer, "# ");
1447     }
1448
1449   if (flags & TDF_RAW)
1450       dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1451                        gimple_phi_result (phi));
1452   else
1453     {
1454       dump_generic_node (buffer, lhs, spc, flags, false);
1455       pp_string (buffer, " = PHI <");
1456     }
1457   for (i = 0; i < gimple_phi_num_args (phi); i++)
1458     {
1459       if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1460         {
1461           expanded_location xloc;
1462
1463           xloc = expand_location (gimple_phi_arg_location (phi, i));
1464           pp_character (buffer, '[');
1465           if (xloc.file)
1466             {
1467               pp_string (buffer, xloc.file);
1468               pp_string (buffer, " : ");
1469             }
1470           pp_decimal_int (buffer, xloc.line);
1471           pp_string (buffer, ":");
1472           pp_decimal_int (buffer, xloc.column);
1473           pp_string (buffer, "] ");
1474         }
1475       dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1476                          false);
1477       pp_character (buffer, '(');
1478       pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1479       pp_character (buffer, ')');
1480       if (i < gimple_phi_num_args (phi) - 1)
1481         pp_string (buffer, ", ");
1482     }
1483   pp_character (buffer, '>');
1484 }
1485
1486
1487 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1488    of indent.  FLAGS specifies details to show in the dump (see TDF_* in
1489    tree-pass.h).  */
1490
1491 static void
1492 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1493                           int flags)
1494 {
1495   if (flags & TDF_RAW)
1496     {
1497       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1498                        gimple_omp_body (gs));
1499       dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1500       dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1501                        gimple_omp_parallel_child_fn (gs),
1502                        gimple_omp_parallel_data_arg (gs));
1503     }
1504   else
1505     {
1506       gimple_seq body;
1507       pp_string (buffer, "#pragma omp parallel");
1508       dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1509       if (gimple_omp_parallel_child_fn (gs))
1510         {
1511           pp_string (buffer, " [child fn: ");
1512           dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1513                              spc, flags, false);
1514           pp_string (buffer, " (");
1515           if (gimple_omp_parallel_data_arg (gs))
1516             dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1517                                spc, flags, false);
1518           else
1519             pp_string (buffer, "???");
1520           pp_string (buffer, ")]");
1521         }
1522       body = gimple_omp_body (gs);
1523       if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1524         {
1525           newline_and_indent (buffer, spc + 2);
1526           pp_character (buffer, '{');
1527           pp_newline (buffer);
1528           dump_gimple_seq (buffer, body, spc + 4, flags);
1529           newline_and_indent (buffer, spc + 2);
1530           pp_character (buffer, '}');
1531         }
1532       else if (body)
1533         {
1534           pp_newline (buffer);
1535           dump_gimple_seq (buffer, body, spc + 2, flags);
1536         }
1537     }
1538 }
1539
1540
1541 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1542    of indent.  FLAGS specifies details to show in the dump (see TDF_* in
1543    tree-pass.h).  */
1544
1545 static void
1546 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1547                       int flags)
1548 {
1549   if (flags & TDF_RAW)
1550     {
1551       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1552                        gimple_omp_body (gs));
1553       dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1554       dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1555                        gimple_omp_task_child_fn (gs),
1556                        gimple_omp_task_data_arg (gs),
1557                        gimple_omp_task_copy_fn (gs),
1558                        gimple_omp_task_arg_size (gs),
1559                        gimple_omp_task_arg_size (gs));
1560     }
1561   else
1562     {
1563       gimple_seq body;
1564       pp_string (buffer, "#pragma omp task");
1565       dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1566       if (gimple_omp_task_child_fn (gs))
1567         {
1568           pp_string (buffer, " [child fn: ");
1569           dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1570                              spc, flags, false);
1571           pp_string (buffer, " (");
1572           if (gimple_omp_task_data_arg (gs))
1573             dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1574                                spc, flags, false);
1575           else
1576             pp_string (buffer, "???");
1577           pp_string (buffer, ")]");
1578         }
1579       body = gimple_omp_body (gs);
1580       if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1581         {
1582           newline_and_indent (buffer, spc + 2);
1583           pp_character (buffer, '{');
1584           pp_newline (buffer);
1585           dump_gimple_seq (buffer, body, spc + 4, flags);
1586           newline_and_indent (buffer, spc + 2);
1587           pp_character (buffer, '}');
1588         }
1589       else if (body)
1590         {
1591           pp_newline (buffer);
1592           dump_gimple_seq (buffer, body, spc + 2, flags);
1593         }
1594     }
1595 }
1596
1597
1598 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1599    spaces of indent.  FLAGS specifies details to show in the dump (see TDF_*
1600    in tree-pass.h).  */
1601
1602 static void
1603 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1604                              int flags)
1605 {
1606   if (flags & TDF_RAW)
1607     {
1608       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1609                        gimple_omp_atomic_load_lhs (gs),
1610                        gimple_omp_atomic_load_rhs (gs));
1611     }
1612   else
1613     {
1614       pp_string (buffer, "#pragma omp atomic_load");
1615       newline_and_indent (buffer, spc + 2);
1616       dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1617                          spc, flags, false);
1618       pp_space (buffer);
1619       pp_character (buffer, '=');
1620       pp_space (buffer);
1621       pp_character (buffer, '*');
1622       dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1623                          spc, flags, false);
1624     }
1625 }
1626
1627 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1628    spaces of indent.  FLAGS specifies details to show in the dump (see TDF_*
1629    in tree-pass.h).  */
1630
1631 static void
1632 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
1633                              int flags)
1634 {
1635   if (flags & TDF_RAW)
1636     {
1637       dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1638                        gimple_omp_atomic_store_val (gs));
1639     }
1640   else
1641     {
1642       pp_string (buffer, "#pragma omp atomic_store (");
1643       dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
1644                          spc, flags, false);
1645       pp_character (buffer, ')');
1646     }
1647 }
1648
1649
1650 /* Dump all the memory operands for statement GS.  BUFFER, SPC and
1651    FLAGS are as in dump_gimple_stmt.  */
1652
1653 static void
1654 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
1655 {
1656   tree vdef = gimple_vdef (gs);
1657   tree vuse = gimple_vuse (gs);
1658
1659   if (!ssa_operands_active () || !gimple_references_memory_p (gs))
1660     return;
1661
1662   if (vdef != NULL_TREE)
1663     {
1664       pp_string (buffer, "# ");
1665       dump_generic_node (buffer, vdef, spc + 2, flags, false);
1666       pp_string (buffer, " = VDEF <");
1667       dump_generic_node (buffer, vuse, spc + 2, flags, false);
1668       pp_character (buffer, '>');
1669       newline_and_indent (buffer, spc);
1670     }
1671   else if (vuse != NULL_TREE)
1672     {
1673       pp_string (buffer, "# VUSE <");
1674       dump_generic_node (buffer, vuse, spc + 2, flags, false);
1675       pp_character (buffer, '>');
1676       newline_and_indent (buffer, spc);
1677     }
1678 }
1679
1680
1681 /* Dump the gimple statement GS on the pretty printer BUFFER, SPC
1682    spaces of indent.  FLAGS specifies details to show in the dump (see
1683    TDF_* in tree-pass.h).  */
1684
1685 void
1686 dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags)
1687 {
1688   if (!gs)
1689     return;
1690
1691   if (flags & TDF_STMTADDR)
1692     pp_printf (buffer, "<&%p> ", (void *) gs);
1693
1694   if ((flags & TDF_LINENO) && gimple_has_location (gs))
1695     {
1696       expanded_location xloc = expand_location (gimple_location (gs));
1697       pp_character (buffer, '[');
1698       if (xloc.file)
1699         {
1700           pp_string (buffer, xloc.file);
1701           pp_string (buffer, " : ");
1702         }
1703       pp_decimal_int (buffer, xloc.line);
1704       pp_string (buffer, ":");
1705       pp_decimal_int (buffer, xloc.column);
1706       pp_string (buffer, "] ");
1707     }
1708
1709   if (flags & TDF_EH)
1710     {
1711       int lp_nr = lookup_stmt_eh_lp (gs);
1712       if (lp_nr > 0)
1713         pp_printf (buffer, "[LP %d] ", lp_nr);
1714       else if (lp_nr < 0)
1715         pp_printf (buffer, "[MNT %d] ", -lp_nr);
1716     }
1717
1718   if ((flags & (TDF_VOPS|TDF_MEMSYMS))
1719       && gimple_has_mem_ops (gs))
1720     dump_gimple_mem_ops (buffer, gs, spc, flags);
1721
1722   if ((flags & TDF_ALIAS)
1723       && gimple_has_lhs (gs))
1724     {
1725       tree lhs = gimple_get_lhs (gs);
1726       if (TREE_CODE (lhs) == SSA_NAME
1727           && POINTER_TYPE_P (TREE_TYPE (lhs))
1728           && SSA_NAME_PTR_INFO (lhs))
1729         {
1730           struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
1731           pp_string (buffer, "# PT = ");
1732           pp_points_to_solution (buffer, &pi->pt);
1733           newline_and_indent (buffer, spc);
1734           if (pi->align != 1)
1735             {
1736               pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u",
1737                          pi->align, pi->misalign);
1738               newline_and_indent (buffer, spc);
1739             }
1740         }
1741     }
1742
1743   switch (gimple_code (gs))
1744     {
1745     case GIMPLE_ASM:
1746       dump_gimple_asm (buffer, gs, spc, flags);
1747       break;
1748
1749     case GIMPLE_ASSIGN:
1750       dump_gimple_assign (buffer, gs, spc, flags);
1751       break;
1752
1753     case GIMPLE_BIND:
1754       dump_gimple_bind (buffer, gs, spc, flags);
1755       break;
1756
1757     case GIMPLE_CALL:
1758       dump_gimple_call (buffer, gs, spc, flags);
1759       break;
1760
1761     case GIMPLE_COND:
1762       dump_gimple_cond (buffer, gs, spc, flags);
1763       break;
1764
1765     case GIMPLE_LABEL:
1766       dump_gimple_label (buffer, gs, spc, flags);
1767       break;
1768
1769     case GIMPLE_GOTO:
1770       dump_gimple_goto (buffer, gs, spc, flags);
1771       break;
1772
1773     case GIMPLE_NOP:
1774       pp_string (buffer, "GIMPLE_NOP");
1775       break;
1776
1777     case GIMPLE_RETURN:
1778       dump_gimple_return (buffer, gs, spc, flags);
1779       break;
1780
1781     case GIMPLE_SWITCH:
1782       dump_gimple_switch (buffer, gs, spc, flags);
1783       break;
1784
1785     case GIMPLE_TRY:
1786       dump_gimple_try (buffer, gs, spc, flags);
1787       break;
1788
1789     case GIMPLE_PHI:
1790       dump_gimple_phi (buffer, gs, spc, flags);
1791       break;
1792
1793     case GIMPLE_OMP_PARALLEL:
1794       dump_gimple_omp_parallel (buffer, gs, spc, flags);
1795       break;
1796
1797     case GIMPLE_OMP_TASK:
1798       dump_gimple_omp_task (buffer, gs, spc, flags);
1799       break;
1800
1801     case GIMPLE_OMP_ATOMIC_LOAD:
1802       dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
1803
1804       break;
1805
1806     case GIMPLE_OMP_ATOMIC_STORE:
1807       dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
1808       break;
1809
1810     case GIMPLE_OMP_FOR:
1811       dump_gimple_omp_for (buffer, gs, spc, flags);
1812       break;
1813
1814     case GIMPLE_OMP_CONTINUE:
1815       dump_gimple_omp_continue (buffer, gs, spc, flags);
1816       break;
1817
1818     case GIMPLE_OMP_SINGLE:
1819       dump_gimple_omp_single (buffer, gs, spc, flags);
1820       break;
1821
1822     case GIMPLE_OMP_RETURN:
1823       dump_gimple_omp_return (buffer, gs, spc, flags);
1824       break;
1825
1826     case GIMPLE_OMP_SECTIONS:
1827       dump_gimple_omp_sections (buffer, gs, spc, flags);
1828       break;
1829
1830     case GIMPLE_OMP_SECTIONS_SWITCH:
1831       pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
1832       break;
1833
1834     case GIMPLE_OMP_MASTER:
1835     case GIMPLE_OMP_ORDERED:
1836     case GIMPLE_OMP_SECTION:
1837       dump_gimple_omp_block (buffer, gs, spc, flags);
1838       break;
1839
1840     case GIMPLE_OMP_CRITICAL:
1841       dump_gimple_omp_critical (buffer, gs, spc, flags);
1842       break;
1843
1844     case GIMPLE_CATCH:
1845       dump_gimple_catch (buffer, gs, spc, flags);
1846       break;
1847
1848     case GIMPLE_EH_FILTER:
1849       dump_gimple_eh_filter (buffer, gs, spc, flags);
1850       break;
1851
1852     case GIMPLE_EH_MUST_NOT_THROW:
1853       dump_gimple_eh_must_not_throw (buffer, gs, spc, flags);
1854       break;
1855
1856     case GIMPLE_RESX:
1857       dump_gimple_resx (buffer, gs, spc, flags);
1858       break;
1859
1860     case GIMPLE_EH_DISPATCH:
1861       dump_gimple_eh_dispatch (buffer, gs, spc, flags);
1862       break;
1863
1864     case GIMPLE_DEBUG:
1865       dump_gimple_debug (buffer, gs, spc, flags);
1866       break;
1867
1868     case GIMPLE_PREDICT:
1869       pp_string (buffer, "// predicted ");
1870       if (gimple_predict_outcome (gs))
1871         pp_string (buffer, "likely by ");
1872       else
1873         pp_string (buffer, "unlikely by ");
1874       pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
1875       pp_string (buffer, " predictor.");
1876       break;
1877
1878     default:
1879       GIMPLE_NIY;
1880     }
1881
1882   /* If we're building a diagnostic, the formatted text will be
1883      written into BUFFER's stream by the caller; otherwise, write it
1884      now.  */
1885   if (!(flags & TDF_DIAGNOSTIC))
1886     pp_write_text_to_stream (buffer);
1887 }
1888
1889
1890 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
1891    spaces and details described by flags.  */
1892
1893 static void
1894 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
1895 {
1896   edge e;
1897   gimple stmt;
1898   edge_iterator ei;
1899
1900   if (flags & TDF_BLOCKS)
1901     {
1902       INDENT (indent);
1903       pp_string (buffer, "# BLOCK ");
1904       pp_decimal_int (buffer, bb->index);
1905       if (bb->frequency)
1906         {
1907           pp_string (buffer, " freq:");
1908           pp_decimal_int (buffer, bb->frequency);
1909         }
1910       if (bb->count)
1911         {
1912           pp_string (buffer, " count:");
1913           pp_widest_integer (buffer, bb->count);
1914         }
1915
1916       if (flags & TDF_LINENO)
1917         {
1918           gimple_stmt_iterator gsi;
1919
1920           for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1921             if (!is_gimple_debug (gsi_stmt (gsi))
1922                 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
1923               {
1924                 pp_string (buffer, ", starting at line ");
1925                 pp_decimal_int (buffer, get_lineno (gsi_stmt (gsi)));
1926                 break;
1927               }
1928
1929           if (bb->discriminator)
1930             {
1931               pp_string (buffer, ", discriminator ");
1932               pp_decimal_int (buffer, bb->discriminator);
1933             }
1934         }
1935       newline_and_indent (buffer, indent);
1936
1937       pp_string (buffer, "# PRED:");
1938       pp_write_text_to_stream (buffer);
1939       FOR_EACH_EDGE (e, ei, bb->preds)
1940         if (flags & TDF_SLIM)
1941           {
1942             pp_character (buffer, ' ');
1943             if (e->src == ENTRY_BLOCK_PTR)
1944               pp_string (buffer, "ENTRY");
1945             else
1946               pp_decimal_int (buffer, e->src->index);
1947           }
1948         else
1949           dump_edge_info (buffer->buffer->stream, e, 0);
1950       pp_newline (buffer);
1951     }
1952   else
1953     {
1954       stmt = first_stmt (bb);
1955       if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
1956         {
1957           INDENT (indent - 2);
1958           pp_string (buffer, "<bb ");
1959           pp_decimal_int (buffer, bb->index);
1960           pp_string (buffer, ">:");
1961           pp_newline (buffer);
1962         }
1963     }
1964   pp_write_text_to_stream (buffer);
1965   if (cfun)
1966     check_bb_profile (bb, buffer->buffer->stream);
1967 }
1968
1969
1970 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
1971    spaces.  */
1972
1973 static void
1974 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
1975 {
1976   edge e;
1977   edge_iterator ei;
1978
1979   INDENT (indent);
1980   pp_string (buffer, "# SUCC:");
1981   pp_write_text_to_stream (buffer);
1982   FOR_EACH_EDGE (e, ei, bb->succs)
1983     if (flags & TDF_SLIM)
1984       {
1985         pp_character (buffer, ' ');
1986         if (e->dest == EXIT_BLOCK_PTR)
1987           pp_string (buffer, "EXIT");
1988         else
1989           pp_decimal_int (buffer, e->dest->index);
1990       }
1991     else
1992       dump_edge_info (buffer->buffer->stream, e, 1);
1993   pp_newline (buffer);
1994 }
1995
1996
1997 /* Dump PHI nodes of basic block BB to BUFFER with details described
1998    by FLAGS and indented by INDENT spaces.  */
1999
2000 static void
2001 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2002 {
2003   gimple_stmt_iterator i;
2004
2005   for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2006     {
2007       gimple phi = gsi_stmt (i);
2008       if (is_gimple_reg (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2009         {
2010           INDENT (indent);
2011           pp_string (buffer, "# ");
2012           dump_gimple_phi (buffer, phi, indent, flags);
2013           pp_newline (buffer);
2014         }
2015     }
2016 }
2017
2018
2019 /* Dump jump to basic block BB that is represented implicitly in the cfg
2020    to BUFFER.  */
2021
2022 static void
2023 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2024 {
2025   gimple stmt;
2026
2027   stmt = first_stmt (bb);
2028
2029   pp_string (buffer, "goto <bb ");
2030   pp_decimal_int (buffer, bb->index);
2031   pp_character (buffer, '>');
2032   if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
2033     {
2034       pp_string (buffer, " (");
2035       dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
2036       pp_character (buffer, ')');
2037       pp_semicolon (buffer);
2038     }
2039   else
2040     pp_semicolon (buffer);
2041 }
2042
2043
2044 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2045    by INDENT spaces, with details given by FLAGS.  */
2046
2047 static void
2048 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2049                      int flags)
2050 {
2051   edge e;
2052   gimple stmt;
2053
2054   stmt = last_stmt (bb);
2055
2056   if (stmt && gimple_code (stmt) == GIMPLE_COND)
2057     {
2058       edge true_edge, false_edge;
2059
2060       /* When we are emitting the code or changing CFG, it is possible that
2061          the edges are not yet created.  When we are using debug_bb in such
2062          a situation, we do not want it to crash.  */
2063       if (EDGE_COUNT (bb->succs) != 2)
2064         return;
2065       extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2066
2067       INDENT (indent + 2);
2068       pp_cfg_jump (buffer, true_edge->dest);
2069       newline_and_indent (buffer, indent);
2070       pp_string (buffer, "else");
2071       newline_and_indent (buffer, indent + 2);
2072       pp_cfg_jump (buffer, false_edge->dest);
2073       pp_newline (buffer);
2074       return;
2075     }
2076
2077   /* If there is a fallthru edge, we may need to add an artificial
2078      goto to the dump.  */
2079   e = find_fallthru_edge (bb->succs);
2080
2081   if (e && e->dest != bb->next_bb)
2082     {
2083       INDENT (indent);
2084
2085       if ((flags & TDF_LINENO)
2086           && e->goto_locus != UNKNOWN_LOCATION
2087           )
2088         {
2089           expanded_location goto_xloc;
2090           goto_xloc = expand_location (e->goto_locus);
2091           pp_character (buffer, '[');
2092           if (goto_xloc.file)
2093             {
2094               pp_string (buffer, goto_xloc.file);
2095               pp_string (buffer, " : ");
2096             }
2097           pp_decimal_int (buffer, goto_xloc.line);
2098           pp_string (buffer, " : ");
2099           pp_decimal_int (buffer, goto_xloc.column);
2100           pp_string (buffer, "] ");
2101         }
2102
2103       pp_cfg_jump (buffer, e->dest);
2104       pp_newline (buffer);
2105     }
2106 }
2107
2108
2109 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2110    indented by INDENT spaces.  */
2111
2112 static void
2113 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2114                      int flags)
2115 {
2116   gimple_stmt_iterator gsi;
2117   gimple stmt;
2118   int label_indent = indent - 2;
2119
2120   if (label_indent < 0)
2121     label_indent = 0;
2122
2123   dump_bb_header (buffer, bb, indent, flags);
2124   dump_phi_nodes (buffer, bb, indent, flags);
2125
2126   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2127     {
2128       int curr_indent;
2129
2130       stmt = gsi_stmt (gsi);
2131
2132       curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2133
2134       INDENT (curr_indent);
2135       dump_gimple_stmt (buffer, stmt, curr_indent, flags);
2136       pp_newline (buffer);
2137       dump_histograms_for_stmt (cfun, buffer->buffer->stream, stmt);
2138     }
2139
2140   dump_implicit_edges (buffer, bb, indent, flags);
2141
2142   if (flags & TDF_BLOCKS)
2143     dump_bb_end (buffer, bb, indent, flags);
2144 }
2145
2146
2147 /* Dumps basic block BB to FILE with details described by FLAGS and
2148    indented by INDENT spaces.  */
2149
2150 void
2151 gimple_dump_bb (basic_block bb, FILE *file, int indent, int flags)
2152 {
2153   maybe_init_pretty_print (file);
2154   gimple_dump_bb_buff (&buffer, bb, indent, flags);
2155   pp_flush (&buffer);
2156 }