OSDN Git Service

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