OSDN Git Service

2dbdebe339e8ea3e96bcfdea2c839d0e48d3ff6b
[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_SHUFFLE_EXPR:
422       pp_string (buffer, "VEC_SHUFFLE_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       if (pt->vars_contains_restrict)
614         pp_string (buffer, " (restr)");
615     }
616 }
617
618 /* Dump the call statement GS.  BUFFER, SPC and FLAGS are as in
619    dump_gimple_stmt.  */
620
621 static void
622 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
623 {
624   tree lhs = gimple_call_lhs (gs);
625
626   if (flags & TDF_ALIAS)
627     {
628       struct pt_solution *pt;
629       pt = gimple_call_use_set (gs);
630       if (!pt_solution_empty_p (pt))
631         {
632           pp_string (buffer, "# USE = ");
633           pp_points_to_solution (buffer, pt);
634           newline_and_indent (buffer, spc);
635         }
636       pt = gimple_call_clobber_set (gs);
637       if (!pt_solution_empty_p (pt))
638         {
639           pp_string (buffer, "# CLB = ");
640           pp_points_to_solution (buffer, pt);
641           newline_and_indent (buffer, spc);
642         }
643     }
644
645   if (flags & TDF_RAW)
646     {
647       if (gimple_call_internal_p (gs))
648         dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T", gs,
649                          internal_fn_name (gimple_call_internal_fn (gs)), lhs);
650       else
651         dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T",
652                          gs, gimple_call_fn (gs), lhs);
653       if (gimple_call_num_args (gs) > 0)
654         {
655           pp_string (buffer, ", ");
656           dump_gimple_call_args (buffer, gs, flags);
657         }
658       pp_character (buffer, '>');
659     }
660   else
661     {
662       if (lhs && !(flags & TDF_RHS_ONLY))
663         {
664           dump_generic_node (buffer, lhs, spc, flags, false);
665           pp_string (buffer, " =");
666
667           if (gimple_has_volatile_ops (gs))
668             pp_string (buffer, "{v}");
669
670           pp_space (buffer);
671         }
672       if (gimple_call_internal_p (gs))
673         pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
674       else
675         print_call_name (buffer, gimple_call_fn (gs), flags);
676       pp_string (buffer, " (");
677       dump_gimple_call_args (buffer, gs, flags);
678       pp_character (buffer, ')');
679       if (!(flags & TDF_RHS_ONLY))
680         pp_semicolon (buffer);
681     }
682
683   if (gimple_call_chain (gs))
684     {
685       pp_string (buffer, " [static-chain: ");
686       dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
687       pp_character (buffer, ']');
688     }
689
690   if (gimple_call_return_slot_opt_p (gs))
691     pp_string (buffer, " [return slot optimization]");
692
693   if (gimple_call_tail_p (gs))
694     pp_string (buffer, " [tail call]");
695 }
696
697
698 /* Dump the switch statement GS.  BUFFER, SPC and FLAGS are as in
699    dump_gimple_stmt.  */
700
701 static void
702 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
703 {
704   unsigned int i;
705
706   GIMPLE_CHECK (gs, GIMPLE_SWITCH);
707   if (flags & TDF_RAW)
708     dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
709                    gimple_switch_index (gs));
710   else
711     {
712       pp_string (buffer, "switch (");
713       dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
714       pp_string (buffer, ") <");
715     }
716
717   for (i = 0; i < gimple_switch_num_labels (gs); i++)
718     {
719       tree case_label = gimple_switch_label (gs, i);
720       if (case_label == NULL_TREE)
721         continue;
722
723       dump_generic_node (buffer, case_label, spc, flags, false);
724       pp_character (buffer, ' ');
725       dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
726       if (i < gimple_switch_num_labels (gs) - 1)
727         pp_string (buffer, ", ");
728     }
729   pp_character (buffer, '>');
730 }
731
732
733 /* Dump the gimple conditional GS.  BUFFER, SPC and FLAGS are as in
734    dump_gimple_stmt.  */
735
736 static void
737 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
738 {
739   if (flags & TDF_RAW)
740     dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
741                    tree_code_name [gimple_cond_code (gs)],
742                    gimple_cond_lhs (gs), gimple_cond_rhs (gs),
743                    gimple_cond_true_label (gs), gimple_cond_false_label (gs));
744   else
745     {
746       if (!(flags & TDF_RHS_ONLY))
747         pp_string (buffer, "if (");
748       dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
749       pp_space (buffer);
750       pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
751       pp_space (buffer);
752       dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
753       if (!(flags & TDF_RHS_ONLY))
754         {
755           pp_character (buffer, ')');
756
757           if (gimple_cond_true_label (gs))
758             {
759               pp_string (buffer, " goto ");
760               dump_generic_node (buffer, gimple_cond_true_label (gs),
761                                  spc, flags, false);
762               pp_semicolon (buffer);
763             }
764           if (gimple_cond_false_label (gs))
765             {
766               pp_string (buffer, " else goto ");
767               dump_generic_node (buffer, gimple_cond_false_label (gs),
768                                  spc, flags, false);
769               pp_semicolon (buffer);
770             }
771         }
772     }
773 }
774
775
776 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
777    spaces of indent.  FLAGS specifies details to show in the dump (see
778    TDF_* in tree-pass.h).  */
779
780 static void
781 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
782 {
783   tree label = gimple_label_label (gs);
784   if (flags & TDF_RAW)
785       dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
786   else
787     {
788       dump_generic_node (buffer, label, spc, flags, false);
789       pp_character (buffer, ':');
790     }
791   if (DECL_NONLOCAL (label))
792     pp_string (buffer, " [non-local]");
793   if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
794     pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
795 }
796
797 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
798    spaces of indent.  FLAGS specifies details to show in the dump (see
799    TDF_* in tree-pass.h).  */
800
801 static void
802 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
803 {
804   tree label = gimple_goto_dest (gs);
805   if (flags & TDF_RAW)
806     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
807   else
808     dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
809 }
810
811
812 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
813    spaces of indent.  FLAGS specifies details to show in the dump (see
814    TDF_* in tree-pass.h).  */
815
816 static void
817 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
818 {
819   if (flags & TDF_RAW)
820     dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
821   else
822     pp_character (buffer, '{');
823   if (!(flags & TDF_SLIM))
824     {
825       tree var;
826
827       for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
828         {
829           newline_and_indent (buffer, 2);
830           print_declaration (buffer, var, spc, flags);
831         }
832       if (gimple_bind_vars (gs))
833         pp_newline (buffer);
834     }
835   pp_newline (buffer);
836   dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
837   newline_and_indent (buffer, spc);
838   if (flags & TDF_RAW)
839     pp_character (buffer, '>');
840   else
841     pp_character (buffer, '}');
842 }
843
844
845 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
846    indent.  FLAGS specifies details to show in the dump (see TDF_* in
847    tree-pass.h).  */
848
849 static void
850 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
851 {
852   if (flags & TDF_RAW)
853     {
854       const char *type;
855       if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
856         type = "GIMPLE_TRY_CATCH";
857       else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
858         type = "GIMPLE_TRY_FINALLY";
859       else
860         type = "UNKNOWN GIMPLE_TRY";
861       dump_gimple_fmt (buffer, spc, flags,
862                        "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
863                        gimple_try_eval (gs), gimple_try_cleanup (gs));
864     }
865   else
866     {
867       pp_string (buffer, "try");
868       newline_and_indent (buffer, spc + 2);
869       pp_character (buffer, '{');
870       pp_newline (buffer);
871
872       dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
873       newline_and_indent (buffer, spc + 2);
874       pp_character (buffer, '}');
875
876       if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
877         {
878           newline_and_indent (buffer, spc);
879           pp_string (buffer, "catch");
880           newline_and_indent (buffer, spc + 2);
881           pp_character (buffer, '{');
882         }
883       else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
884         {
885           newline_and_indent (buffer, spc);
886           pp_string (buffer, "finally");
887           newline_and_indent (buffer, spc + 2);
888           pp_character (buffer, '{');
889         }
890       else
891         pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
892
893       pp_newline (buffer);
894       dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
895       newline_and_indent (buffer, spc + 2);
896       pp_character (buffer, '}');
897     }
898 }
899
900
901 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
902    indent.  FLAGS specifies details to show in the dump (see TDF_* in
903    tree-pass.h).  */
904
905 static void
906 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
907 {
908   if (flags & TDF_RAW)
909       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
910                        gimple_catch_types (gs), gimple_catch_handler (gs));
911   else
912       dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
913                        gimple_catch_types (gs), gimple_catch_handler (gs));
914 }
915
916
917 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
918    indent.  FLAGS specifies details to show in the dump (see TDF_* in
919    tree-pass.h).  */
920
921 static void
922 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
923 {
924   if (flags & TDF_RAW)
925     dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
926                      gimple_eh_filter_types (gs),
927                      gimple_eh_filter_failure (gs));
928   else
929     dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
930                      gimple_eh_filter_types (gs),
931                      gimple_eh_filter_failure (gs));
932 }
933
934
935 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple.  */
936
937 static void
938 dump_gimple_eh_must_not_throw (pretty_printer *buffer, gimple gs,
939                                int spc, int flags)
940 {
941   if (flags & TDF_RAW)
942     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
943                      gimple_eh_must_not_throw_fndecl (gs));
944   else
945     dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
946                      gimple_eh_must_not_throw_fndecl (gs));
947 }
948
949
950 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
951    indent.  FLAGS specifies details to show in the dump (see TDF_* in
952    tree-pass.h).  */
953
954 static void
955 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
956 {
957   if (flags & TDF_RAW)
958     dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
959                      gimple_resx_region (gs));
960   else
961     dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
962 }
963
964 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER.  */
965
966 static void
967 dump_gimple_eh_dispatch (pretty_printer *buffer, gimple gs, int spc, int flags)
968 {
969   if (flags & TDF_RAW)
970     dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
971                      gimple_eh_dispatch_region (gs));
972   else
973     dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
974                      gimple_eh_dispatch_region (gs));
975 }
976
977 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
978    of indent.  FLAGS specifies details to show in the dump (see TDF_*
979    in tree-pass.h).  */
980
981 static void
982 dump_gimple_debug (pretty_printer *buffer, gimple gs, int spc, int flags)
983 {
984   switch (gs->gsbase.subcode)
985     {
986     case GIMPLE_DEBUG_BIND:
987       if (flags & TDF_RAW)
988         dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
989                          gimple_debug_bind_get_var (gs),
990                          gimple_debug_bind_get_value (gs));
991       else
992         dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
993                          gimple_debug_bind_get_var (gs),
994                          gimple_debug_bind_get_value (gs));
995       break;
996
997     case GIMPLE_DEBUG_SOURCE_BIND:
998       if (flags & TDF_RAW)
999         dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1000                          gimple_debug_source_bind_get_var (gs),
1001                          gimple_debug_source_bind_get_value (gs));
1002       else
1003         dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1004                          gimple_debug_source_bind_get_var (gs),
1005                          gimple_debug_source_bind_get_value (gs));
1006       break;
1007
1008     default:
1009       gcc_unreachable ();
1010     }
1011 }
1012
1013 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER.  */
1014 static void
1015 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
1016 {
1017   size_t i;
1018
1019   if (flags & TDF_RAW)
1020     {
1021       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1022                        gimple_omp_body (gs));
1023       dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1024       dump_gimple_fmt (buffer, spc, flags, " >,");
1025       for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1026         dump_gimple_fmt (buffer, spc, flags,
1027                          "%+%T, %T, %T, %s, %T,%n",
1028                          gimple_omp_for_index (gs, i),
1029                          gimple_omp_for_initial (gs, i),
1030                          gimple_omp_for_final (gs, i),
1031                          tree_code_name[gimple_omp_for_cond (gs, i)],
1032                          gimple_omp_for_incr (gs, i));
1033       dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1034                        gimple_omp_for_pre_body (gs));
1035     }
1036   else
1037     {
1038       pp_string (buffer, "#pragma omp for");
1039       dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1040       for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1041         {
1042           if (i)
1043             spc += 2;
1044           newline_and_indent (buffer, spc);
1045           pp_string (buffer, "for (");
1046           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1047                              flags, false);
1048           pp_string (buffer, " = ");
1049           dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1050                              flags, false);
1051           pp_string (buffer, "; ");
1052
1053           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1054                              flags, false);
1055           pp_space (buffer);
1056           switch (gimple_omp_for_cond (gs, i))
1057             {
1058             case LT_EXPR:
1059               pp_character (buffer, '<');
1060               break;
1061             case GT_EXPR:
1062               pp_character (buffer, '>');
1063               break;
1064             case LE_EXPR:
1065               pp_string (buffer, "<=");
1066               break;
1067             case GE_EXPR:
1068               pp_string (buffer, ">=");
1069               break;
1070             default:
1071               gcc_unreachable ();
1072             }
1073           pp_space (buffer);
1074           dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1075                              flags, false);
1076           pp_string (buffer, "; ");
1077
1078           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1079                              flags, false);
1080           pp_string (buffer, " = ");
1081           dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1082                              flags, false);
1083           pp_character (buffer, ')');
1084         }
1085
1086       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1087         {
1088           newline_and_indent (buffer, spc + 2);
1089           pp_character (buffer, '{');
1090           pp_newline (buffer);
1091           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1092           newline_and_indent (buffer, spc + 2);
1093           pp_character (buffer, '}');
1094         }
1095     }
1096 }
1097
1098 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER.  */
1099
1100 static void
1101 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
1102 {
1103   if (flags & TDF_RAW)
1104     {
1105       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1106                        gimple_omp_continue_control_def (gs),
1107                        gimple_omp_continue_control_use (gs));
1108     }
1109   else
1110     {
1111       pp_string (buffer, "#pragma omp continue (");
1112       dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1113                          spc, flags, false);
1114       pp_character (buffer, ',');
1115       pp_space (buffer);
1116       dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1117                          spc, flags, false);
1118       pp_character (buffer, ')');
1119     }
1120 }
1121
1122 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER.  */
1123
1124 static void
1125 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
1126 {
1127   if (flags & TDF_RAW)
1128     {
1129       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1130                        gimple_omp_body (gs));
1131       dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1132       dump_gimple_fmt (buffer, spc, flags, " >");
1133     }
1134   else
1135     {
1136       pp_string (buffer, "#pragma omp single");
1137       dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1138       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1139         {
1140           newline_and_indent (buffer, spc + 2);
1141           pp_character (buffer, '{');
1142           pp_newline (buffer);
1143           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1144           newline_and_indent (buffer, spc + 2);
1145           pp_character (buffer, '}');
1146         }
1147     }
1148 }
1149
1150 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER.  */
1151
1152 static void
1153 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
1154                           int flags)
1155 {
1156   if (flags & TDF_RAW)
1157     {
1158       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1159                        gimple_omp_body (gs));
1160       dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1161       dump_gimple_fmt (buffer, spc, flags, " >");
1162     }
1163   else
1164     {
1165       pp_string (buffer, "#pragma omp sections");
1166       if (gimple_omp_sections_control (gs))
1167         {
1168           pp_string (buffer, " <");
1169           dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1170                              flags, false);
1171           pp_character (buffer, '>');
1172         }
1173       dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1174       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1175         {
1176           newline_and_indent (buffer, spc + 2);
1177           pp_character (buffer, '{');
1178           pp_newline (buffer);
1179           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1180           newline_and_indent (buffer, spc + 2);
1181           pp_character (buffer, '}');
1182         }
1183     }
1184 }
1185
1186 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer
1187    BUFFER.  */
1188
1189 static void
1190 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
1191 {
1192   if (flags & TDF_RAW)
1193     dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1194                      gimple_omp_body (gs));
1195   else
1196     {
1197       switch (gimple_code (gs))
1198         {
1199         case GIMPLE_OMP_MASTER:
1200           pp_string (buffer, "#pragma omp master");
1201           break;
1202         case GIMPLE_OMP_ORDERED:
1203           pp_string (buffer, "#pragma omp ordered");
1204           break;
1205         case GIMPLE_OMP_SECTION:
1206           pp_string (buffer, "#pragma omp section");
1207           break;
1208         default:
1209           gcc_unreachable ();
1210         }
1211       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1212         {
1213           newline_and_indent (buffer, spc + 2);
1214           pp_character (buffer, '{');
1215           pp_newline (buffer);
1216           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1217           newline_and_indent (buffer, spc + 2);
1218           pp_character (buffer, '}');
1219         }
1220     }
1221 }
1222
1223 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER.  */
1224
1225 static void
1226 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
1227                           int flags)
1228 {
1229   if (flags & TDF_RAW)
1230     dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1231                      gimple_omp_body (gs));
1232   else
1233     {
1234       pp_string (buffer, "#pragma omp critical");
1235       if (gimple_omp_critical_name (gs))
1236         {
1237           pp_string (buffer, " (");
1238           dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1239                              flags, false);
1240           pp_character (buffer, ')');
1241         }
1242       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1243         {
1244           newline_and_indent (buffer, spc + 2);
1245           pp_character (buffer, '{');
1246           pp_newline (buffer);
1247           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1248           newline_and_indent (buffer, spc + 2);
1249           pp_character (buffer, '}');
1250         }
1251     }
1252 }
1253
1254 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER.  */
1255
1256 static void
1257 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1258 {
1259   if (flags & TDF_RAW)
1260     {
1261       dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d>", gs,
1262                        (int) gimple_omp_return_nowait_p (gs));
1263     }
1264   else
1265     {
1266       pp_string (buffer, "#pragma omp return");
1267       if (gimple_omp_return_nowait_p (gs))
1268         pp_string (buffer, "(nowait)");
1269     }
1270 }
1271
1272 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1273    indent.  FLAGS specifies details to show in the dump (see TDF_* in
1274    tree-pass.h).  */
1275
1276 static void
1277 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1278 {
1279   unsigned int i, n, f, fields;
1280
1281   if (flags & TDF_RAW)
1282     {
1283       dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1284                        gimple_asm_string (gs));
1285
1286       n = gimple_asm_noutputs (gs);
1287       if (n)
1288         {
1289           newline_and_indent (buffer, spc + 2);
1290           pp_string (buffer, "OUTPUT: ");
1291           for (i = 0; i < n; i++)
1292             {
1293               dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1294                                  spc, flags, false);
1295               if (i < n - 1)
1296                 pp_string (buffer, ", ");
1297             }
1298         }
1299
1300       n = gimple_asm_ninputs (gs);
1301       if (n)
1302         {
1303           newline_and_indent (buffer, spc + 2);
1304           pp_string (buffer, "INPUT: ");
1305           for (i = 0; i < n; i++)
1306             {
1307               dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1308                                  spc, flags, false);
1309               if (i < n - 1)
1310                 pp_string (buffer, ", ");
1311             }
1312         }
1313
1314       n = gimple_asm_nclobbers (gs);
1315       if (n)
1316         {
1317           newline_and_indent (buffer, spc + 2);
1318           pp_string (buffer, "CLOBBER: ");
1319           for (i = 0; i < n; i++)
1320             {
1321               dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1322                                  spc, flags, false);
1323               if (i < n - 1)
1324                 pp_string (buffer, ", ");
1325             }
1326         }
1327
1328       n = gimple_asm_nlabels (gs);
1329       if (n)
1330         {
1331           newline_and_indent (buffer, spc + 2);
1332           pp_string (buffer, "LABEL: ");
1333           for (i = 0; i < n; i++)
1334             {
1335               dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1336                                  spc, flags, false);
1337               if (i < n - 1)
1338                 pp_string (buffer, ", ");
1339             }
1340         }
1341
1342       newline_and_indent (buffer, spc);
1343       pp_character (buffer, '>');
1344     }
1345   else
1346     {
1347       pp_string (buffer, "__asm__");
1348       if (gimple_asm_volatile_p (gs))
1349         pp_string (buffer, " __volatile__");
1350       if (gimple_asm_nlabels (gs))
1351         pp_string (buffer, " goto");
1352       pp_string (buffer, "(\"");
1353       pp_string (buffer, gimple_asm_string (gs));
1354       pp_string (buffer, "\"");
1355
1356       if (gimple_asm_nlabels (gs))
1357         fields = 4;
1358       else if (gimple_asm_nclobbers (gs))
1359         fields = 3;
1360       else if (gimple_asm_ninputs (gs))
1361         fields = 2;
1362       else if (gimple_asm_noutputs (gs))
1363         fields = 1;
1364       else
1365         fields = 0;
1366
1367       for (f = 0; f < fields; ++f)
1368         {
1369           pp_string (buffer, " : ");
1370
1371           switch (f)
1372             {
1373             case 0:
1374               n = gimple_asm_noutputs (gs);
1375               for (i = 0; i < n; i++)
1376                 {
1377                   dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1378                                      spc, flags, false);
1379                   if (i < n - 1)
1380                     pp_string (buffer, ", ");
1381                 }
1382               break;
1383
1384             case 1:
1385               n = gimple_asm_ninputs (gs);
1386               for (i = 0; i < n; i++)
1387                 {
1388                   dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1389                                      spc, flags, false);
1390                   if (i < n - 1)
1391                     pp_string (buffer, ", ");
1392                 }
1393               break;
1394
1395             case 2:
1396               n = gimple_asm_nclobbers (gs);
1397               for (i = 0; i < n; i++)
1398                 {
1399                   dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1400                                      spc, flags, false);
1401                   if (i < n - 1)
1402                     pp_string (buffer, ", ");
1403                 }
1404               break;
1405
1406             case 3:
1407               n = gimple_asm_nlabels (gs);
1408               for (i = 0; i < n; i++)
1409                 {
1410                   dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1411                                      spc, flags, false);
1412                   if (i < n - 1)
1413                     pp_string (buffer, ", ");
1414                 }
1415               break;
1416
1417             default:
1418               gcc_unreachable ();
1419             }
1420         }
1421
1422       pp_string (buffer, ");");
1423     }
1424 }
1425
1426
1427 /* Dump a PHI node PHI.  BUFFER, SPC and FLAGS are as in
1428    dump_gimple_stmt.  */
1429
1430 static void
1431 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
1432 {
1433   size_t i;
1434   tree lhs = gimple_phi_result (phi);
1435
1436   if (flags & TDF_ALIAS
1437       && POINTER_TYPE_P (TREE_TYPE (lhs))
1438       && SSA_NAME_PTR_INFO (lhs))
1439     {
1440       struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
1441       pp_string (buffer, "PT = ");
1442       pp_points_to_solution (buffer, &pi->pt);
1443       newline_and_indent (buffer, spc);
1444       if (pi->align != 1)
1445         pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u",
1446                    pi->align, pi->misalign);
1447       newline_and_indent (buffer, spc);
1448       pp_string (buffer, "# ");
1449     }
1450
1451   if (flags & TDF_RAW)
1452       dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1453                        gimple_phi_result (phi));
1454   else
1455     {
1456       dump_generic_node (buffer, lhs, spc, flags, false);
1457       pp_string (buffer, " = PHI <");
1458     }
1459   for (i = 0; i < gimple_phi_num_args (phi); i++)
1460     {
1461       if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1462         {
1463           expanded_location xloc;
1464
1465           xloc = expand_location (gimple_phi_arg_location (phi, i));
1466           pp_character (buffer, '[');
1467           if (xloc.file)
1468             {
1469               pp_string (buffer, xloc.file);
1470               pp_string (buffer, " : ");
1471             }
1472           pp_decimal_int (buffer, xloc.line);
1473           pp_string (buffer, ":");
1474           pp_decimal_int (buffer, xloc.column);
1475           pp_string (buffer, "] ");
1476         }
1477       dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1478                          false);
1479       pp_character (buffer, '(');
1480       pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1481       pp_character (buffer, ')');
1482       if (i < gimple_phi_num_args (phi) - 1)
1483         pp_string (buffer, ", ");
1484     }
1485   pp_character (buffer, '>');
1486 }
1487
1488
1489 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1490    of indent.  FLAGS specifies details to show in the dump (see TDF_* in
1491    tree-pass.h).  */
1492
1493 static void
1494 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1495                           int flags)
1496 {
1497   if (flags & TDF_RAW)
1498     {
1499       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1500                        gimple_omp_body (gs));
1501       dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1502       dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1503                        gimple_omp_parallel_child_fn (gs),
1504                        gimple_omp_parallel_data_arg (gs));
1505     }
1506   else
1507     {
1508       gimple_seq body;
1509       pp_string (buffer, "#pragma omp parallel");
1510       dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1511       if (gimple_omp_parallel_child_fn (gs))
1512         {
1513           pp_string (buffer, " [child fn: ");
1514           dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1515                              spc, flags, false);
1516           pp_string (buffer, " (");
1517           if (gimple_omp_parallel_data_arg (gs))
1518             dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1519                                spc, flags, false);
1520           else
1521             pp_string (buffer, "???");
1522           pp_string (buffer, ")]");
1523         }
1524       body = gimple_omp_body (gs);
1525       if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1526         {
1527           newline_and_indent (buffer, spc + 2);
1528           pp_character (buffer, '{');
1529           pp_newline (buffer);
1530           dump_gimple_seq (buffer, body, spc + 4, flags);
1531           newline_and_indent (buffer, spc + 2);
1532           pp_character (buffer, '}');
1533         }
1534       else if (body)
1535         {
1536           pp_newline (buffer);
1537           dump_gimple_seq (buffer, body, spc + 2, flags);
1538         }
1539     }
1540 }
1541
1542
1543 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1544    of indent.  FLAGS specifies details to show in the dump (see TDF_* in
1545    tree-pass.h).  */
1546
1547 static void
1548 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1549                       int flags)
1550 {
1551   if (flags & TDF_RAW)
1552     {
1553       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1554                        gimple_omp_body (gs));
1555       dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1556       dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1557                        gimple_omp_task_child_fn (gs),
1558                        gimple_omp_task_data_arg (gs),
1559                        gimple_omp_task_copy_fn (gs),
1560                        gimple_omp_task_arg_size (gs),
1561                        gimple_omp_task_arg_size (gs));
1562     }
1563   else
1564     {
1565       gimple_seq body;
1566       pp_string (buffer, "#pragma omp task");
1567       dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1568       if (gimple_omp_task_child_fn (gs))
1569         {
1570           pp_string (buffer, " [child fn: ");
1571           dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1572                              spc, flags, false);
1573           pp_string (buffer, " (");
1574           if (gimple_omp_task_data_arg (gs))
1575             dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1576                                spc, flags, false);
1577           else
1578             pp_string (buffer, "???");
1579           pp_string (buffer, ")]");
1580         }
1581       body = gimple_omp_body (gs);
1582       if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1583         {
1584           newline_and_indent (buffer, spc + 2);
1585           pp_character (buffer, '{');
1586           pp_newline (buffer);
1587           dump_gimple_seq (buffer, body, spc + 4, flags);
1588           newline_and_indent (buffer, spc + 2);
1589           pp_character (buffer, '}');
1590         }
1591       else if (body)
1592         {
1593           pp_newline (buffer);
1594           dump_gimple_seq (buffer, body, spc + 2, flags);
1595         }
1596     }
1597 }
1598
1599
1600 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1601    spaces of indent.  FLAGS specifies details to show in the dump (see TDF_*
1602    in tree-pass.h).  */
1603
1604 static void
1605 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1606                              int flags)
1607 {
1608   if (flags & TDF_RAW)
1609     {
1610       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1611                        gimple_omp_atomic_load_lhs (gs),
1612                        gimple_omp_atomic_load_rhs (gs));
1613     }
1614   else
1615     {
1616       pp_string (buffer, "#pragma omp atomic_load");
1617       newline_and_indent (buffer, spc + 2);
1618       dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1619                          spc, flags, false);
1620       pp_space (buffer);
1621       pp_character (buffer, '=');
1622       pp_space (buffer);
1623       pp_character (buffer, '*');
1624       dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1625                          spc, flags, false);
1626     }
1627 }
1628
1629 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1630    spaces of indent.  FLAGS specifies details to show in the dump (see TDF_*
1631    in tree-pass.h).  */
1632
1633 static void
1634 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
1635                              int flags)
1636 {
1637   if (flags & TDF_RAW)
1638     {
1639       dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1640                        gimple_omp_atomic_store_val (gs));
1641     }
1642   else
1643     {
1644       pp_string (buffer, "#pragma omp atomic_store (");
1645       dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
1646                          spc, flags, false);
1647       pp_character (buffer, ')');
1648     }
1649 }
1650
1651
1652 /* Dump all the memory operands for statement GS.  BUFFER, SPC and
1653    FLAGS are as in dump_gimple_stmt.  */
1654
1655 static void
1656 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
1657 {
1658   tree vdef = gimple_vdef (gs);
1659   tree vuse = gimple_vuse (gs);
1660
1661   if (!ssa_operands_active () || !gimple_references_memory_p (gs))
1662     return;
1663
1664   if (vdef != NULL_TREE)
1665     {
1666       pp_string (buffer, "# ");
1667       dump_generic_node (buffer, vdef, spc + 2, flags, false);
1668       pp_string (buffer, " = VDEF <");
1669       dump_generic_node (buffer, vuse, spc + 2, flags, false);
1670       pp_character (buffer, '>');
1671       newline_and_indent (buffer, spc);
1672     }
1673   else if (vuse != NULL_TREE)
1674     {
1675       pp_string (buffer, "# VUSE <");
1676       dump_generic_node (buffer, vuse, spc + 2, flags, false);
1677       pp_character (buffer, '>');
1678       newline_and_indent (buffer, spc);
1679     }
1680 }
1681
1682
1683 /* Dump the gimple statement GS on the pretty printer BUFFER, SPC
1684    spaces of indent.  FLAGS specifies details to show in the dump (see
1685    TDF_* in tree-pass.h).  */
1686
1687 void
1688 dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags)
1689 {
1690   if (!gs)
1691     return;
1692
1693   if (flags & TDF_STMTADDR)
1694     pp_printf (buffer, "<&%p> ", (void *) gs);
1695
1696   if ((flags & TDF_LINENO) && gimple_has_location (gs))
1697     {
1698       expanded_location xloc = expand_location (gimple_location (gs));
1699       pp_character (buffer, '[');
1700       if (xloc.file)
1701         {
1702           pp_string (buffer, xloc.file);
1703           pp_string (buffer, " : ");
1704         }
1705       pp_decimal_int (buffer, xloc.line);
1706       pp_string (buffer, ":");
1707       pp_decimal_int (buffer, xloc.column);
1708       pp_string (buffer, "] ");
1709     }
1710
1711   if (flags & TDF_EH)
1712     {
1713       int lp_nr = lookup_stmt_eh_lp (gs);
1714       if (lp_nr > 0)
1715         pp_printf (buffer, "[LP %d] ", lp_nr);
1716       else if (lp_nr < 0)
1717         pp_printf (buffer, "[MNT %d] ", -lp_nr);
1718     }
1719
1720   if ((flags & (TDF_VOPS|TDF_MEMSYMS))
1721       && gimple_has_mem_ops (gs))
1722     dump_gimple_mem_ops (buffer, gs, spc, flags);
1723
1724   if ((flags & TDF_ALIAS)
1725       && gimple_has_lhs (gs))
1726     {
1727       tree lhs = gimple_get_lhs (gs);
1728       if (TREE_CODE (lhs) == SSA_NAME
1729           && POINTER_TYPE_P (TREE_TYPE (lhs))
1730           && SSA_NAME_PTR_INFO (lhs))
1731         {
1732           struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
1733           pp_string (buffer, "# PT = ");
1734           pp_points_to_solution (buffer, &pi->pt);
1735           newline_and_indent (buffer, spc);
1736           if (pi->align != 1)
1737             {
1738               pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u",
1739                          pi->align, pi->misalign);
1740               newline_and_indent (buffer, spc);
1741             }
1742         }
1743     }
1744
1745   switch (gimple_code (gs))
1746     {
1747     case GIMPLE_ASM:
1748       dump_gimple_asm (buffer, gs, spc, flags);
1749       break;
1750
1751     case GIMPLE_ASSIGN:
1752       dump_gimple_assign (buffer, gs, spc, flags);
1753       break;
1754
1755     case GIMPLE_BIND:
1756       dump_gimple_bind (buffer, gs, spc, flags);
1757       break;
1758
1759     case GIMPLE_CALL:
1760       dump_gimple_call (buffer, gs, spc, flags);
1761       break;
1762
1763     case GIMPLE_COND:
1764       dump_gimple_cond (buffer, gs, spc, flags);
1765       break;
1766
1767     case GIMPLE_LABEL:
1768       dump_gimple_label (buffer, gs, spc, flags);
1769       break;
1770
1771     case GIMPLE_GOTO:
1772       dump_gimple_goto (buffer, gs, spc, flags);
1773       break;
1774
1775     case GIMPLE_NOP:
1776       pp_string (buffer, "GIMPLE_NOP");
1777       break;
1778
1779     case GIMPLE_RETURN:
1780       dump_gimple_return (buffer, gs, spc, flags);
1781       break;
1782
1783     case GIMPLE_SWITCH:
1784       dump_gimple_switch (buffer, gs, spc, flags);
1785       break;
1786
1787     case GIMPLE_TRY:
1788       dump_gimple_try (buffer, gs, spc, flags);
1789       break;
1790
1791     case GIMPLE_PHI:
1792       dump_gimple_phi (buffer, gs, spc, flags);
1793       break;
1794
1795     case GIMPLE_OMP_PARALLEL:
1796       dump_gimple_omp_parallel (buffer, gs, spc, flags);
1797       break;
1798
1799     case GIMPLE_OMP_TASK:
1800       dump_gimple_omp_task (buffer, gs, spc, flags);
1801       break;
1802
1803     case GIMPLE_OMP_ATOMIC_LOAD:
1804       dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
1805
1806       break;
1807
1808     case GIMPLE_OMP_ATOMIC_STORE:
1809       dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
1810       break;
1811
1812     case GIMPLE_OMP_FOR:
1813       dump_gimple_omp_for (buffer, gs, spc, flags);
1814       break;
1815
1816     case GIMPLE_OMP_CONTINUE:
1817       dump_gimple_omp_continue (buffer, gs, spc, flags);
1818       break;
1819
1820     case GIMPLE_OMP_SINGLE:
1821       dump_gimple_omp_single (buffer, gs, spc, flags);
1822       break;
1823
1824     case GIMPLE_OMP_RETURN:
1825       dump_gimple_omp_return (buffer, gs, spc, flags);
1826       break;
1827
1828     case GIMPLE_OMP_SECTIONS:
1829       dump_gimple_omp_sections (buffer, gs, spc, flags);
1830       break;
1831
1832     case GIMPLE_OMP_SECTIONS_SWITCH:
1833       pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
1834       break;
1835
1836     case GIMPLE_OMP_MASTER:
1837     case GIMPLE_OMP_ORDERED:
1838     case GIMPLE_OMP_SECTION:
1839       dump_gimple_omp_block (buffer, gs, spc, flags);
1840       break;
1841
1842     case GIMPLE_OMP_CRITICAL:
1843       dump_gimple_omp_critical (buffer, gs, spc, flags);
1844       break;
1845
1846     case GIMPLE_CATCH:
1847       dump_gimple_catch (buffer, gs, spc, flags);
1848       break;
1849
1850     case GIMPLE_EH_FILTER:
1851       dump_gimple_eh_filter (buffer, gs, spc, flags);
1852       break;
1853
1854     case GIMPLE_EH_MUST_NOT_THROW:
1855       dump_gimple_eh_must_not_throw (buffer, gs, spc, flags);
1856       break;
1857
1858     case GIMPLE_RESX:
1859       dump_gimple_resx (buffer, gs, spc, flags);
1860       break;
1861
1862     case GIMPLE_EH_DISPATCH:
1863       dump_gimple_eh_dispatch (buffer, gs, spc, flags);
1864       break;
1865
1866     case GIMPLE_DEBUG:
1867       dump_gimple_debug (buffer, gs, spc, flags);
1868       break;
1869
1870     case GIMPLE_PREDICT:
1871       pp_string (buffer, "// predicted ");
1872       if (gimple_predict_outcome (gs))
1873         pp_string (buffer, "likely by ");
1874       else
1875         pp_string (buffer, "unlikely by ");
1876       pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
1877       pp_string (buffer, " predictor.");
1878       break;
1879
1880     default:
1881       GIMPLE_NIY;
1882     }
1883
1884   /* If we're building a diagnostic, the formatted text will be
1885      written into BUFFER's stream by the caller; otherwise, write it
1886      now.  */
1887   if (!(flags & TDF_DIAGNOSTIC))
1888     pp_write_text_to_stream (buffer);
1889 }
1890
1891
1892 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
1893    spaces and details described by flags.  */
1894
1895 static void
1896 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
1897 {
1898   edge e;
1899   gimple stmt;
1900   edge_iterator ei;
1901
1902   if (flags & TDF_BLOCKS)
1903     {
1904       INDENT (indent);
1905       pp_string (buffer, "# BLOCK ");
1906       pp_decimal_int (buffer, bb->index);
1907       if (bb->frequency)
1908         {
1909           pp_string (buffer, " freq:");
1910           pp_decimal_int (buffer, bb->frequency);
1911         }
1912       if (bb->count)
1913         {
1914           pp_string (buffer, " count:");
1915           pp_widest_integer (buffer, bb->count);
1916         }
1917
1918       if (flags & TDF_LINENO)
1919         {
1920           gimple_stmt_iterator gsi;
1921
1922           for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1923             if (!is_gimple_debug (gsi_stmt (gsi))
1924                 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
1925               {
1926                 pp_string (buffer, ", starting at line ");
1927                 pp_decimal_int (buffer, get_lineno (gsi_stmt (gsi)));
1928                 break;
1929               }
1930
1931           if (bb->discriminator)
1932             {
1933               pp_string (buffer, ", discriminator ");
1934               pp_decimal_int (buffer, bb->discriminator);
1935             }
1936         }
1937       newline_and_indent (buffer, indent);
1938
1939       pp_string (buffer, "# PRED:");
1940       pp_write_text_to_stream (buffer);
1941       FOR_EACH_EDGE (e, ei, bb->preds)
1942         if (flags & TDF_SLIM)
1943           {
1944             pp_character (buffer, ' ');
1945             if (e->src == ENTRY_BLOCK_PTR)
1946               pp_string (buffer, "ENTRY");
1947             else
1948               pp_decimal_int (buffer, e->src->index);
1949           }
1950         else
1951           dump_edge_info (buffer->buffer->stream, e, 0);
1952       pp_newline (buffer);
1953     }
1954   else
1955     {
1956       stmt = first_stmt (bb);
1957       if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
1958         {
1959           INDENT (indent - 2);
1960           pp_string (buffer, "<bb ");
1961           pp_decimal_int (buffer, bb->index);
1962           pp_string (buffer, ">:");
1963           pp_newline (buffer);
1964         }
1965     }
1966   pp_write_text_to_stream (buffer);
1967   if (cfun)
1968     check_bb_profile (bb, buffer->buffer->stream);
1969 }
1970
1971
1972 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
1973    spaces.  */
1974
1975 static void
1976 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
1977 {
1978   edge e;
1979   edge_iterator ei;
1980
1981   INDENT (indent);
1982   pp_string (buffer, "# SUCC:");
1983   pp_write_text_to_stream (buffer);
1984   FOR_EACH_EDGE (e, ei, bb->succs)
1985     if (flags & TDF_SLIM)
1986       {
1987         pp_character (buffer, ' ');
1988         if (e->dest == EXIT_BLOCK_PTR)
1989           pp_string (buffer, "EXIT");
1990         else
1991           pp_decimal_int (buffer, e->dest->index);
1992       }
1993     else
1994       dump_edge_info (buffer->buffer->stream, e, 1);
1995   pp_newline (buffer);
1996 }
1997
1998
1999 /* Dump PHI nodes of basic block BB to BUFFER with details described
2000    by FLAGS and indented by INDENT spaces.  */
2001
2002 static void
2003 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2004 {
2005   gimple_stmt_iterator i;
2006
2007   for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2008     {
2009       gimple phi = gsi_stmt (i);
2010       if (is_gimple_reg (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2011         {
2012           INDENT (indent);
2013           pp_string (buffer, "# ");
2014           dump_gimple_phi (buffer, phi, indent, flags);
2015           pp_newline (buffer);
2016         }
2017     }
2018 }
2019
2020
2021 /* Dump jump to basic block BB that is represented implicitly in the cfg
2022    to BUFFER.  */
2023
2024 static void
2025 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2026 {
2027   gimple stmt;
2028
2029   stmt = first_stmt (bb);
2030
2031   pp_string (buffer, "goto <bb ");
2032   pp_decimal_int (buffer, bb->index);
2033   pp_character (buffer, '>');
2034   if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
2035     {
2036       pp_string (buffer, " (");
2037       dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
2038       pp_character (buffer, ')');
2039       pp_semicolon (buffer);
2040     }
2041   else
2042     pp_semicolon (buffer);
2043 }
2044
2045
2046 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2047    by INDENT spaces, with details given by FLAGS.  */
2048
2049 static void
2050 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2051                      int flags)
2052 {
2053   edge e;
2054   gimple stmt;
2055
2056   stmt = last_stmt (bb);
2057
2058   if (stmt && gimple_code (stmt) == GIMPLE_COND)
2059     {
2060       edge true_edge, false_edge;
2061
2062       /* When we are emitting the code or changing CFG, it is possible that
2063          the edges are not yet created.  When we are using debug_bb in such
2064          a situation, we do not want it to crash.  */
2065       if (EDGE_COUNT (bb->succs) != 2)
2066         return;
2067       extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2068
2069       INDENT (indent + 2);
2070       pp_cfg_jump (buffer, true_edge->dest);
2071       newline_and_indent (buffer, indent);
2072       pp_string (buffer, "else");
2073       newline_and_indent (buffer, indent + 2);
2074       pp_cfg_jump (buffer, false_edge->dest);
2075       pp_newline (buffer);
2076       return;
2077     }
2078
2079   /* If there is a fallthru edge, we may need to add an artificial
2080      goto to the dump.  */
2081   e = find_fallthru_edge (bb->succs);
2082
2083   if (e && e->dest != bb->next_bb)
2084     {
2085       INDENT (indent);
2086
2087       if ((flags & TDF_LINENO)
2088           && e->goto_locus != UNKNOWN_LOCATION
2089           )
2090         {
2091           expanded_location goto_xloc;
2092           goto_xloc = expand_location (e->goto_locus);
2093           pp_character (buffer, '[');
2094           if (goto_xloc.file)
2095             {
2096               pp_string (buffer, goto_xloc.file);
2097               pp_string (buffer, " : ");
2098             }
2099           pp_decimal_int (buffer, goto_xloc.line);
2100           pp_string (buffer, " : ");
2101           pp_decimal_int (buffer, goto_xloc.column);
2102           pp_string (buffer, "] ");
2103         }
2104
2105       pp_cfg_jump (buffer, e->dest);
2106       pp_newline (buffer);
2107     }
2108 }
2109
2110
2111 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2112    indented by INDENT spaces.  */
2113
2114 static void
2115 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2116                      int flags)
2117 {
2118   gimple_stmt_iterator gsi;
2119   gimple stmt;
2120   int label_indent = indent - 2;
2121
2122   if (label_indent < 0)
2123     label_indent = 0;
2124
2125   dump_bb_header (buffer, bb, indent, flags);
2126   dump_phi_nodes (buffer, bb, indent, flags);
2127
2128   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2129     {
2130       int curr_indent;
2131
2132       stmt = gsi_stmt (gsi);
2133
2134       curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2135
2136       INDENT (curr_indent);
2137       dump_gimple_stmt (buffer, stmt, curr_indent, flags);
2138       pp_newline (buffer);
2139       dump_histograms_for_stmt (cfun, buffer->buffer->stream, stmt);
2140     }
2141
2142   dump_implicit_edges (buffer, bb, indent, flags);
2143
2144   if (flags & TDF_BLOCKS)
2145     dump_bb_end (buffer, bb, indent, flags);
2146 }
2147
2148
2149 /* Dumps basic block BB to FILE with details described by FLAGS and
2150    indented by INDENT spaces.  */
2151
2152 void
2153 gimple_dump_bb (basic_block bb, FILE *file, int indent, int flags)
2154 {
2155   maybe_init_pretty_print (file);
2156   gimple_dump_bb_buff (&buffer, bb, indent, flags);
2157   pp_flush (&buffer);
2158 }