OSDN Git Service

2012-12-15 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / gimple-pretty-print.c
1 /* Pretty formatting of GIMPLE statements and expressions.
2    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
3    2011  Free Software Foundation, Inc.
4    Contributed by Aldy Hernandez <aldyh@redhat.com> and
5    Diego Novillo <dnovillo@google.com>
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3.  If not see
21 <http://www.gnu.org/licenses/>.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "diagnostic.h"
29 #include "tree-pretty-print.h"
30 #include "gimple-pretty-print.h"
31 #include "hashtab.h"
32 #include "tree-flow.h"
33 #include "tree-pass.h"
34 #include "gimple.h"
35 #include "value-prof.h"
36 #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   if (fn == NULL)
702     return;
703
704   /* Dump the arguments of _ITM_beginTransaction sanely.  */
705   if (TREE_CODE (fn) == ADDR_EXPR)
706     fn = TREE_OPERAND (fn, 0);
707   if (TREE_CODE (fn) == FUNCTION_DECL && decl_is_tm_clone (fn))
708     pp_string (buffer, " [tm-clone]");
709   if (TREE_CODE (fn) == FUNCTION_DECL
710       && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
711       && DECL_FUNCTION_CODE (fn) == BUILT_IN_TM_START
712       && gimple_call_num_args (gs) > 0)
713     {
714       tree t = gimple_call_arg (gs, 0);
715       unsigned HOST_WIDE_INT props;
716       gcc_assert (TREE_CODE (t) == INTEGER_CST);
717
718       pp_string (buffer, " [ ");
719
720       /* Get the transaction code properties.  */
721       props = TREE_INT_CST_LOW (t);
722
723       if (props & PR_INSTRUMENTEDCODE)
724         pp_string (buffer, "instrumentedCode ");
725       if (props & PR_UNINSTRUMENTEDCODE)
726         pp_string (buffer, "uninstrumentedCode ");
727       if (props & PR_HASNOXMMUPDATE)
728         pp_string (buffer, "hasNoXMMUpdate ");
729       if (props & PR_HASNOABORT)
730         pp_string (buffer, "hasNoAbort ");
731       if (props & PR_HASNOIRREVOCABLE)
732         pp_string (buffer, "hasNoIrrevocable ");
733       if (props & PR_DOESGOIRREVOCABLE)
734         pp_string (buffer, "doesGoIrrevocable ");
735       if (props & PR_HASNOSIMPLEREADS)
736         pp_string (buffer, "hasNoSimpleReads ");
737       if (props & PR_AWBARRIERSOMITTED)
738         pp_string (buffer, "awBarriersOmitted ");
739       if (props & PR_RARBARRIERSOMITTED)
740         pp_string (buffer, "RaRBarriersOmitted ");
741       if (props & PR_UNDOLOGCODE)
742         pp_string (buffer, "undoLogCode ");
743       if (props & PR_PREFERUNINSTRUMENTED)
744         pp_string (buffer, "preferUninstrumented ");
745       if (props & PR_EXCEPTIONBLOCK)
746         pp_string (buffer, "exceptionBlock ");
747       if (props & PR_HASELSE)
748         pp_string (buffer, "hasElse ");
749       if (props & PR_READONLY)
750         pp_string (buffer, "readOnly ");
751
752       pp_string (buffer, "]");
753     }
754 }
755
756
757 /* Dump the switch statement GS.  BUFFER, SPC and FLAGS are as in
758    dump_gimple_stmt.  */
759
760 static void
761 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
762 {
763   unsigned int i;
764
765   GIMPLE_CHECK (gs, GIMPLE_SWITCH);
766   if (flags & TDF_RAW)
767     dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
768                    gimple_switch_index (gs));
769   else
770     {
771       pp_string (buffer, "switch (");
772       dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
773       pp_string (buffer, ") <");
774     }
775
776   for (i = 0; i < gimple_switch_num_labels (gs); i++)
777     {
778       tree case_label = gimple_switch_label (gs, i);
779       if (case_label == NULL_TREE)
780         continue;
781
782       dump_generic_node (buffer, case_label, spc, flags, false);
783       pp_character (buffer, ' ');
784       dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
785       if (i < gimple_switch_num_labels (gs) - 1)
786         pp_string (buffer, ", ");
787     }
788   pp_character (buffer, '>');
789 }
790
791
792 /* Dump the gimple conditional GS.  BUFFER, SPC and FLAGS are as in
793    dump_gimple_stmt.  */
794
795 static void
796 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
797 {
798   if (flags & TDF_RAW)
799     dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
800                    tree_code_name [gimple_cond_code (gs)],
801                    gimple_cond_lhs (gs), gimple_cond_rhs (gs),
802                    gimple_cond_true_label (gs), gimple_cond_false_label (gs));
803   else
804     {
805       if (!(flags & TDF_RHS_ONLY))
806         pp_string (buffer, "if (");
807       dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
808       pp_space (buffer);
809       pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
810       pp_space (buffer);
811       dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
812       if (!(flags & TDF_RHS_ONLY))
813         {
814           pp_character (buffer, ')');
815
816           if (gimple_cond_true_label (gs))
817             {
818               pp_string (buffer, " goto ");
819               dump_generic_node (buffer, gimple_cond_true_label (gs),
820                                  spc, flags, false);
821               pp_semicolon (buffer);
822             }
823           if (gimple_cond_false_label (gs))
824             {
825               pp_string (buffer, " else goto ");
826               dump_generic_node (buffer, gimple_cond_false_label (gs),
827                                  spc, flags, false);
828               pp_semicolon (buffer);
829             }
830         }
831     }
832 }
833
834
835 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
836    spaces of indent.  FLAGS specifies details to show in the dump (see
837    TDF_* in tree-pass.h).  */
838
839 static void
840 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
841 {
842   tree label = gimple_label_label (gs);
843   if (flags & TDF_RAW)
844       dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
845   else
846     {
847       dump_generic_node (buffer, label, spc, flags, false);
848       pp_character (buffer, ':');
849     }
850   if (DECL_NONLOCAL (label))
851     pp_string (buffer, " [non-local]");
852   if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
853     pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
854 }
855
856 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
857    spaces of indent.  FLAGS specifies details to show in the dump (see
858    TDF_* in tree-pass.h).  */
859
860 static void
861 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
862 {
863   tree label = gimple_goto_dest (gs);
864   if (flags & TDF_RAW)
865     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
866   else
867     dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
868 }
869
870
871 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
872    spaces of indent.  FLAGS specifies details to show in the dump (see
873    TDF_* in tree-pass.h).  */
874
875 static void
876 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
877 {
878   if (flags & TDF_RAW)
879     dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
880   else
881     pp_character (buffer, '{');
882   if (!(flags & TDF_SLIM))
883     {
884       tree var;
885
886       for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
887         {
888           newline_and_indent (buffer, 2);
889           print_declaration (buffer, var, spc, flags);
890         }
891       if (gimple_bind_vars (gs))
892         pp_newline (buffer);
893     }
894   pp_newline (buffer);
895   dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
896   newline_and_indent (buffer, spc);
897   if (flags & TDF_RAW)
898     pp_character (buffer, '>');
899   else
900     pp_character (buffer, '}');
901 }
902
903
904 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
905    indent.  FLAGS specifies details to show in the dump (see TDF_* in
906    tree-pass.h).  */
907
908 static void
909 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
910 {
911   if (flags & TDF_RAW)
912     {
913       const char *type;
914       if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
915         type = "GIMPLE_TRY_CATCH";
916       else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
917         type = "GIMPLE_TRY_FINALLY";
918       else
919         type = "UNKNOWN GIMPLE_TRY";
920       dump_gimple_fmt (buffer, spc, flags,
921                        "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
922                        gimple_try_eval (gs), gimple_try_cleanup (gs));
923     }
924   else
925     {
926       pp_string (buffer, "try");
927       newline_and_indent (buffer, spc + 2);
928       pp_character (buffer, '{');
929       pp_newline (buffer);
930
931       dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
932       newline_and_indent (buffer, spc + 2);
933       pp_character (buffer, '}');
934
935       if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
936         {
937           newline_and_indent (buffer, spc);
938           pp_string (buffer, "catch");
939           newline_and_indent (buffer, spc + 2);
940           pp_character (buffer, '{');
941         }
942       else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
943         {
944           newline_and_indent (buffer, spc);
945           pp_string (buffer, "finally");
946           newline_and_indent (buffer, spc + 2);
947           pp_character (buffer, '{');
948         }
949       else
950         pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
951
952       pp_newline (buffer);
953       dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
954       newline_and_indent (buffer, spc + 2);
955       pp_character (buffer, '}');
956     }
957 }
958
959
960 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
961    indent.  FLAGS specifies details to show in the dump (see TDF_* in
962    tree-pass.h).  */
963
964 static void
965 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
966 {
967   if (flags & TDF_RAW)
968       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
969                        gimple_catch_types (gs), gimple_catch_handler (gs));
970   else
971       dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
972                        gimple_catch_types (gs), gimple_catch_handler (gs));
973 }
974
975
976 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
977    indent.  FLAGS specifies details to show in the dump (see TDF_* in
978    tree-pass.h).  */
979
980 static void
981 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
982 {
983   if (flags & TDF_RAW)
984     dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
985                      gimple_eh_filter_types (gs),
986                      gimple_eh_filter_failure (gs));
987   else
988     dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
989                      gimple_eh_filter_types (gs),
990                      gimple_eh_filter_failure (gs));
991 }
992
993
994 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple.  */
995
996 static void
997 dump_gimple_eh_must_not_throw (pretty_printer *buffer, gimple gs,
998                                int spc, int flags)
999 {
1000   if (flags & TDF_RAW)
1001     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1002                      gimple_eh_must_not_throw_fndecl (gs));
1003   else
1004     dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
1005                      gimple_eh_must_not_throw_fndecl (gs));
1006 }
1007
1008
1009 /* Dump a GIMPLE_EH_ELSE tuple on the pretty_printer BUFFER, SPC spaces of
1010    indent.  FLAGS specifies details to show in the dump (see TDF_* in
1011    tree-pass.h).  */
1012
1013 static void
1014 dump_gimple_eh_else (pretty_printer *buffer, gimple gs, int spc, int flags)
1015 {
1016   if (flags & TDF_RAW)
1017     dump_gimple_fmt (buffer, spc, flags,
1018                      "%G <%+N_BODY <%S>%nE_BODY <%S>%->", gs,
1019                      gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1020   else
1021     dump_gimple_fmt (buffer, spc, flags,
1022                     "<<<if_normal_exit>>>%+{%S}%-<<<else_eh_exit>>>%+{%S}",
1023                      gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1024 }
1025
1026
1027 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
1028    indent.  FLAGS specifies details to show in the dump (see TDF_* in
1029    tree-pass.h).  */
1030
1031 static void
1032 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
1033 {
1034   if (flags & TDF_RAW)
1035     dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1036                      gimple_resx_region (gs));
1037   else
1038     dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
1039 }
1040
1041 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER.  */
1042
1043 static void
1044 dump_gimple_eh_dispatch (pretty_printer *buffer, gimple gs, int spc, int flags)
1045 {
1046   if (flags & TDF_RAW)
1047     dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1048                      gimple_eh_dispatch_region (gs));
1049   else
1050     dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
1051                      gimple_eh_dispatch_region (gs));
1052 }
1053
1054 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
1055    of indent.  FLAGS specifies details to show in the dump (see TDF_*
1056    in tree-pass.h).  */
1057
1058 static void
1059 dump_gimple_debug (pretty_printer *buffer, gimple gs, int spc, int flags)
1060 {
1061   switch (gs->gsbase.subcode)
1062     {
1063     case GIMPLE_DEBUG_BIND:
1064       if (flags & TDF_RAW)
1065         dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
1066                          gimple_debug_bind_get_var (gs),
1067                          gimple_debug_bind_get_value (gs));
1068       else
1069         dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
1070                          gimple_debug_bind_get_var (gs),
1071                          gimple_debug_bind_get_value (gs));
1072       break;
1073
1074     case GIMPLE_DEBUG_SOURCE_BIND:
1075       if (flags & TDF_RAW)
1076         dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1077                          gimple_debug_source_bind_get_var (gs),
1078                          gimple_debug_source_bind_get_value (gs));
1079       else
1080         dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1081                          gimple_debug_source_bind_get_var (gs),
1082                          gimple_debug_source_bind_get_value (gs));
1083       break;
1084
1085     default:
1086       gcc_unreachable ();
1087     }
1088 }
1089
1090 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER.  */
1091 static void
1092 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
1093 {
1094   size_t i;
1095
1096   if (flags & TDF_RAW)
1097     {
1098       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1099                        gimple_omp_body (gs));
1100       dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1101       dump_gimple_fmt (buffer, spc, flags, " >,");
1102       for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1103         dump_gimple_fmt (buffer, spc, flags,
1104                          "%+%T, %T, %T, %s, %T,%n",
1105                          gimple_omp_for_index (gs, i),
1106                          gimple_omp_for_initial (gs, i),
1107                          gimple_omp_for_final (gs, i),
1108                          tree_code_name[gimple_omp_for_cond (gs, i)],
1109                          gimple_omp_for_incr (gs, i));
1110       dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1111                        gimple_omp_for_pre_body (gs));
1112     }
1113   else
1114     {
1115       pp_string (buffer, "#pragma omp for");
1116       dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1117       for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1118         {
1119           if (i)
1120             spc += 2;
1121           newline_and_indent (buffer, spc);
1122           pp_string (buffer, "for (");
1123           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1124                              flags, false);
1125           pp_string (buffer, " = ");
1126           dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1127                              flags, false);
1128           pp_string (buffer, "; ");
1129
1130           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1131                              flags, false);
1132           pp_space (buffer);
1133           switch (gimple_omp_for_cond (gs, i))
1134             {
1135             case LT_EXPR:
1136               pp_character (buffer, '<');
1137               break;
1138             case GT_EXPR:
1139               pp_character (buffer, '>');
1140               break;
1141             case LE_EXPR:
1142               pp_string (buffer, "<=");
1143               break;
1144             case GE_EXPR:
1145               pp_string (buffer, ">=");
1146               break;
1147             default:
1148               gcc_unreachable ();
1149             }
1150           pp_space (buffer);
1151           dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1152                              flags, false);
1153           pp_string (buffer, "; ");
1154
1155           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1156                              flags, false);
1157           pp_string (buffer, " = ");
1158           dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1159                              flags, false);
1160           pp_character (buffer, ')');
1161         }
1162
1163       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1164         {
1165           newline_and_indent (buffer, spc + 2);
1166           pp_character (buffer, '{');
1167           pp_newline (buffer);
1168           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1169           newline_and_indent (buffer, spc + 2);
1170           pp_character (buffer, '}');
1171         }
1172     }
1173 }
1174
1175 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER.  */
1176
1177 static void
1178 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
1179 {
1180   if (flags & TDF_RAW)
1181     {
1182       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1183                        gimple_omp_continue_control_def (gs),
1184                        gimple_omp_continue_control_use (gs));
1185     }
1186   else
1187     {
1188       pp_string (buffer, "#pragma omp continue (");
1189       dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1190                          spc, flags, false);
1191       pp_character (buffer, ',');
1192       pp_space (buffer);
1193       dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1194                          spc, flags, false);
1195       pp_character (buffer, ')');
1196     }
1197 }
1198
1199 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER.  */
1200
1201 static void
1202 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
1203 {
1204   if (flags & TDF_RAW)
1205     {
1206       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1207                        gimple_omp_body (gs));
1208       dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1209       dump_gimple_fmt (buffer, spc, flags, " >");
1210     }
1211   else
1212     {
1213       pp_string (buffer, "#pragma omp single");
1214       dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1215       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1216         {
1217           newline_and_indent (buffer, spc + 2);
1218           pp_character (buffer, '{');
1219           pp_newline (buffer);
1220           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1221           newline_and_indent (buffer, spc + 2);
1222           pp_character (buffer, '}');
1223         }
1224     }
1225 }
1226
1227 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER.  */
1228
1229 static void
1230 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
1231                           int flags)
1232 {
1233   if (flags & TDF_RAW)
1234     {
1235       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1236                        gimple_omp_body (gs));
1237       dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1238       dump_gimple_fmt (buffer, spc, flags, " >");
1239     }
1240   else
1241     {
1242       pp_string (buffer, "#pragma omp sections");
1243       if (gimple_omp_sections_control (gs))
1244         {
1245           pp_string (buffer, " <");
1246           dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1247                              flags, false);
1248           pp_character (buffer, '>');
1249         }
1250       dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1251       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1252         {
1253           newline_and_indent (buffer, spc + 2);
1254           pp_character (buffer, '{');
1255           pp_newline (buffer);
1256           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1257           newline_and_indent (buffer, spc + 2);
1258           pp_character (buffer, '}');
1259         }
1260     }
1261 }
1262
1263 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer
1264    BUFFER.  */
1265
1266 static void
1267 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
1268 {
1269   if (flags & TDF_RAW)
1270     dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1271                      gimple_omp_body (gs));
1272   else
1273     {
1274       switch (gimple_code (gs))
1275         {
1276         case GIMPLE_OMP_MASTER:
1277           pp_string (buffer, "#pragma omp master");
1278           break;
1279         case GIMPLE_OMP_ORDERED:
1280           pp_string (buffer, "#pragma omp ordered");
1281           break;
1282         case GIMPLE_OMP_SECTION:
1283           pp_string (buffer, "#pragma omp section");
1284           break;
1285         default:
1286           gcc_unreachable ();
1287         }
1288       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1289         {
1290           newline_and_indent (buffer, spc + 2);
1291           pp_character (buffer, '{');
1292           pp_newline (buffer);
1293           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1294           newline_and_indent (buffer, spc + 2);
1295           pp_character (buffer, '}');
1296         }
1297     }
1298 }
1299
1300 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER.  */
1301
1302 static void
1303 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
1304                           int flags)
1305 {
1306   if (flags & TDF_RAW)
1307     dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1308                      gimple_omp_body (gs));
1309   else
1310     {
1311       pp_string (buffer, "#pragma omp critical");
1312       if (gimple_omp_critical_name (gs))
1313         {
1314           pp_string (buffer, " (");
1315           dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1316                              flags, false);
1317           pp_character (buffer, ')');
1318         }
1319       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1320         {
1321           newline_and_indent (buffer, spc + 2);
1322           pp_character (buffer, '{');
1323           pp_newline (buffer);
1324           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1325           newline_and_indent (buffer, spc + 2);
1326           pp_character (buffer, '}');
1327         }
1328     }
1329 }
1330
1331 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER.  */
1332
1333 static void
1334 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1335 {
1336   if (flags & TDF_RAW)
1337     {
1338       dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d>", gs,
1339                        (int) gimple_omp_return_nowait_p (gs));
1340     }
1341   else
1342     {
1343       pp_string (buffer, "#pragma omp return");
1344       if (gimple_omp_return_nowait_p (gs))
1345         pp_string (buffer, "(nowait)");
1346     }
1347 }
1348
1349 /* Dump a GIMPLE_TRANSACTION tuple on the pretty_printer BUFFER.  */
1350
1351 static void
1352 dump_gimple_transaction (pretty_printer *buffer, gimple gs, int spc, int flags)
1353 {
1354   unsigned subcode = gimple_transaction_subcode (gs);
1355
1356   if (flags & TDF_RAW)
1357     {
1358       dump_gimple_fmt (buffer, spc, flags,
1359                        "%G [SUBCODE=%x,LABEL=%T] <%+BODY <%S> >",
1360                        gs, subcode, gimple_transaction_label (gs),
1361                        gimple_transaction_body (gs));
1362     }
1363   else
1364     {
1365       if (subcode & GTMA_IS_OUTER)
1366         pp_string (buffer, "__transaction_atomic [[outer]]");
1367       else if (subcode & GTMA_IS_RELAXED)
1368         pp_string (buffer, "__transaction_relaxed");
1369       else
1370         pp_string (buffer, "__transaction_atomic");
1371       subcode &= ~GTMA_DECLARATION_MASK;
1372
1373       if (subcode || gimple_transaction_label (gs))
1374         {
1375           pp_string (buffer, "  //");
1376           if (gimple_transaction_label (gs))
1377             {
1378               pp_string (buffer, " LABEL=");
1379               dump_generic_node (buffer, gimple_transaction_label (gs),
1380                                  spc, flags, false);
1381             }
1382           if (subcode)
1383             {
1384               pp_string (buffer, " SUBCODE=[ ");
1385               if (subcode & GTMA_HAVE_ABORT)
1386                 {
1387                   pp_string (buffer, "GTMA_HAVE_ABORT ");
1388                   subcode &= ~GTMA_HAVE_ABORT;
1389                 }
1390               if (subcode & GTMA_HAVE_LOAD)
1391                 {
1392                   pp_string (buffer, "GTMA_HAVE_LOAD ");
1393                   subcode &= ~GTMA_HAVE_LOAD;
1394                 }
1395               if (subcode & GTMA_HAVE_STORE)
1396                 {
1397                   pp_string (buffer, "GTMA_HAVE_STORE ");
1398                   subcode &= ~GTMA_HAVE_STORE;
1399                 }
1400               if (subcode & GTMA_MAY_ENTER_IRREVOCABLE)
1401                 {
1402                   pp_string (buffer, "GTMA_MAY_ENTER_IRREVOCABLE ");
1403                   subcode &= ~GTMA_MAY_ENTER_IRREVOCABLE;
1404                 }
1405               if (subcode & GTMA_DOES_GO_IRREVOCABLE)
1406                 {
1407                   pp_string (buffer, "GTMA_DOES_GO_IRREVOCABLE ");
1408                   subcode &= ~GTMA_DOES_GO_IRREVOCABLE;
1409                 }
1410               if (subcode)
1411                 pp_printf (buffer, "0x%x ", subcode);
1412               pp_string (buffer, "]");
1413             }
1414         }
1415
1416       if (!gimple_seq_empty_p (gimple_transaction_body (gs)))
1417         {
1418           newline_and_indent (buffer, spc + 2);
1419           pp_character (buffer, '{');
1420           pp_newline (buffer);
1421           dump_gimple_seq (buffer, gimple_transaction_body (gs),
1422                            spc + 4, flags);
1423           newline_and_indent (buffer, spc + 2);
1424           pp_character (buffer, '}');
1425         }
1426     }
1427 }
1428
1429 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1430    indent.  FLAGS specifies details to show in the dump (see TDF_* in
1431    tree-pass.h).  */
1432
1433 static void
1434 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1435 {
1436   unsigned int i, n, f, fields;
1437
1438   if (flags & TDF_RAW)
1439     {
1440       dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1441                        gimple_asm_string (gs));
1442
1443       n = gimple_asm_noutputs (gs);
1444       if (n)
1445         {
1446           newline_and_indent (buffer, spc + 2);
1447           pp_string (buffer, "OUTPUT: ");
1448           for (i = 0; i < n; i++)
1449             {
1450               dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1451                                  spc, flags, false);
1452               if (i < n - 1)
1453                 pp_string (buffer, ", ");
1454             }
1455         }
1456
1457       n = gimple_asm_ninputs (gs);
1458       if (n)
1459         {
1460           newline_and_indent (buffer, spc + 2);
1461           pp_string (buffer, "INPUT: ");
1462           for (i = 0; i < n; i++)
1463             {
1464               dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1465                                  spc, flags, false);
1466               if (i < n - 1)
1467                 pp_string (buffer, ", ");
1468             }
1469         }
1470
1471       n = gimple_asm_nclobbers (gs);
1472       if (n)
1473         {
1474           newline_and_indent (buffer, spc + 2);
1475           pp_string (buffer, "CLOBBER: ");
1476           for (i = 0; i < n; i++)
1477             {
1478               dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1479                                  spc, flags, false);
1480               if (i < n - 1)
1481                 pp_string (buffer, ", ");
1482             }
1483         }
1484
1485       n = gimple_asm_nlabels (gs);
1486       if (n)
1487         {
1488           newline_and_indent (buffer, spc + 2);
1489           pp_string (buffer, "LABEL: ");
1490           for (i = 0; i < n; i++)
1491             {
1492               dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1493                                  spc, flags, false);
1494               if (i < n - 1)
1495                 pp_string (buffer, ", ");
1496             }
1497         }
1498
1499       newline_and_indent (buffer, spc);
1500       pp_character (buffer, '>');
1501     }
1502   else
1503     {
1504       pp_string (buffer, "__asm__");
1505       if (gimple_asm_volatile_p (gs))
1506         pp_string (buffer, " __volatile__");
1507       if (gimple_asm_nlabels (gs))
1508         pp_string (buffer, " goto");
1509       pp_string (buffer, "(\"");
1510       pp_string (buffer, gimple_asm_string (gs));
1511       pp_string (buffer, "\"");
1512
1513       if (gimple_asm_nlabels (gs))
1514         fields = 4;
1515       else if (gimple_asm_nclobbers (gs))
1516         fields = 3;
1517       else if (gimple_asm_ninputs (gs))
1518         fields = 2;
1519       else if (gimple_asm_noutputs (gs))
1520         fields = 1;
1521       else
1522         fields = 0;
1523
1524       for (f = 0; f < fields; ++f)
1525         {
1526           pp_string (buffer, " : ");
1527
1528           switch (f)
1529             {
1530             case 0:
1531               n = gimple_asm_noutputs (gs);
1532               for (i = 0; i < n; i++)
1533                 {
1534                   dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1535                                      spc, flags, false);
1536                   if (i < n - 1)
1537                     pp_string (buffer, ", ");
1538                 }
1539               break;
1540
1541             case 1:
1542               n = gimple_asm_ninputs (gs);
1543               for (i = 0; i < n; i++)
1544                 {
1545                   dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1546                                      spc, flags, false);
1547                   if (i < n - 1)
1548                     pp_string (buffer, ", ");
1549                 }
1550               break;
1551
1552             case 2:
1553               n = gimple_asm_nclobbers (gs);
1554               for (i = 0; i < n; i++)
1555                 {
1556                   dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1557                                      spc, flags, false);
1558                   if (i < n - 1)
1559                     pp_string (buffer, ", ");
1560                 }
1561               break;
1562
1563             case 3:
1564               n = gimple_asm_nlabels (gs);
1565               for (i = 0; i < n; i++)
1566                 {
1567                   dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1568                                      spc, flags, false);
1569                   if (i < n - 1)
1570                     pp_string (buffer, ", ");
1571                 }
1572               break;
1573
1574             default:
1575               gcc_unreachable ();
1576             }
1577         }
1578
1579       pp_string (buffer, ");");
1580     }
1581 }
1582
1583
1584 /* Dump a PHI node PHI.  BUFFER, SPC and FLAGS are as in
1585    dump_gimple_stmt.  */
1586
1587 static void
1588 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
1589 {
1590   size_t i;
1591   tree lhs = gimple_phi_result (phi);
1592
1593   if (flags & TDF_ALIAS
1594       && POINTER_TYPE_P (TREE_TYPE (lhs))
1595       && SSA_NAME_PTR_INFO (lhs))
1596     {
1597       struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
1598       pp_string (buffer, "PT = ");
1599       pp_points_to_solution (buffer, &pi->pt);
1600       newline_and_indent (buffer, spc);
1601       if (pi->align != 1)
1602         pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u",
1603                    pi->align, pi->misalign);
1604       newline_and_indent (buffer, spc);
1605       pp_string (buffer, "# ");
1606     }
1607
1608   if (flags & TDF_RAW)
1609       dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1610                        gimple_phi_result (phi));
1611   else
1612     {
1613       dump_generic_node (buffer, lhs, spc, flags, false);
1614       pp_string (buffer, " = PHI <");
1615     }
1616   for (i = 0; i < gimple_phi_num_args (phi); i++)
1617     {
1618       if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1619         {
1620           expanded_location xloc;
1621
1622           xloc = expand_location (gimple_phi_arg_location (phi, i));
1623           pp_character (buffer, '[');
1624           if (xloc.file)
1625             {
1626               pp_string (buffer, xloc.file);
1627               pp_string (buffer, " : ");
1628             }
1629           pp_decimal_int (buffer, xloc.line);
1630           pp_string (buffer, ":");
1631           pp_decimal_int (buffer, xloc.column);
1632           pp_string (buffer, "] ");
1633         }
1634       dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1635                          false);
1636       pp_character (buffer, '(');
1637       pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1638       pp_character (buffer, ')');
1639       if (i < gimple_phi_num_args (phi) - 1)
1640         pp_string (buffer, ", ");
1641     }
1642   pp_character (buffer, '>');
1643 }
1644
1645
1646 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1647    of indent.  FLAGS specifies details to show in the dump (see TDF_* in
1648    tree-pass.h).  */
1649
1650 static void
1651 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1652                           int flags)
1653 {
1654   if (flags & TDF_RAW)
1655     {
1656       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1657                        gimple_omp_body (gs));
1658       dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1659       dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1660                        gimple_omp_parallel_child_fn (gs),
1661                        gimple_omp_parallel_data_arg (gs));
1662     }
1663   else
1664     {
1665       gimple_seq body;
1666       pp_string (buffer, "#pragma omp parallel");
1667       dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1668       if (gimple_omp_parallel_child_fn (gs))
1669         {
1670           pp_string (buffer, " [child fn: ");
1671           dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1672                              spc, flags, false);
1673           pp_string (buffer, " (");
1674           if (gimple_omp_parallel_data_arg (gs))
1675             dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1676                                spc, flags, false);
1677           else
1678             pp_string (buffer, "???");
1679           pp_string (buffer, ")]");
1680         }
1681       body = gimple_omp_body (gs);
1682       if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1683         {
1684           newline_and_indent (buffer, spc + 2);
1685           pp_character (buffer, '{');
1686           pp_newline (buffer);
1687           dump_gimple_seq (buffer, body, spc + 4, flags);
1688           newline_and_indent (buffer, spc + 2);
1689           pp_character (buffer, '}');
1690         }
1691       else if (body)
1692         {
1693           pp_newline (buffer);
1694           dump_gimple_seq (buffer, body, spc + 2, flags);
1695         }
1696     }
1697 }
1698
1699
1700 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1701    of indent.  FLAGS specifies details to show in the dump (see TDF_* in
1702    tree-pass.h).  */
1703
1704 static void
1705 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1706                       int flags)
1707 {
1708   if (flags & TDF_RAW)
1709     {
1710       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1711                        gimple_omp_body (gs));
1712       dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1713       dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1714                        gimple_omp_task_child_fn (gs),
1715                        gimple_omp_task_data_arg (gs),
1716                        gimple_omp_task_copy_fn (gs),
1717                        gimple_omp_task_arg_size (gs),
1718                        gimple_omp_task_arg_size (gs));
1719     }
1720   else
1721     {
1722       gimple_seq body;
1723       pp_string (buffer, "#pragma omp task");
1724       dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1725       if (gimple_omp_task_child_fn (gs))
1726         {
1727           pp_string (buffer, " [child fn: ");
1728           dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1729                              spc, flags, false);
1730           pp_string (buffer, " (");
1731           if (gimple_omp_task_data_arg (gs))
1732             dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1733                                spc, flags, false);
1734           else
1735             pp_string (buffer, "???");
1736           pp_string (buffer, ")]");
1737         }
1738       body = gimple_omp_body (gs);
1739       if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1740         {
1741           newline_and_indent (buffer, spc + 2);
1742           pp_character (buffer, '{');
1743           pp_newline (buffer);
1744           dump_gimple_seq (buffer, body, spc + 4, flags);
1745           newline_and_indent (buffer, spc + 2);
1746           pp_character (buffer, '}');
1747         }
1748       else if (body)
1749         {
1750           pp_newline (buffer);
1751           dump_gimple_seq (buffer, body, spc + 2, flags);
1752         }
1753     }
1754 }
1755
1756
1757 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1758    spaces of indent.  FLAGS specifies details to show in the dump (see TDF_*
1759    in tree-pass.h).  */
1760
1761 static void
1762 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1763                              int flags)
1764 {
1765   if (flags & TDF_RAW)
1766     {
1767       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1768                        gimple_omp_atomic_load_lhs (gs),
1769                        gimple_omp_atomic_load_rhs (gs));
1770     }
1771   else
1772     {
1773       pp_string (buffer, "#pragma omp atomic_load");
1774       if (gimple_omp_atomic_need_value_p (gs))
1775         pp_string (buffer, " [needed]");
1776       newline_and_indent (buffer, spc + 2);
1777       dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1778                          spc, flags, false);
1779       pp_space (buffer);
1780       pp_character (buffer, '=');
1781       pp_space (buffer);
1782       pp_character (buffer, '*');
1783       dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1784                          spc, flags, false);
1785     }
1786 }
1787
1788 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1789    spaces of indent.  FLAGS specifies details to show in the dump (see TDF_*
1790    in tree-pass.h).  */
1791
1792 static void
1793 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
1794                              int flags)
1795 {
1796   if (flags & TDF_RAW)
1797     {
1798       dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1799                        gimple_omp_atomic_store_val (gs));
1800     }
1801   else
1802     {
1803       pp_string (buffer, "#pragma omp atomic_store ");
1804       if (gimple_omp_atomic_need_value_p (gs))
1805         pp_string (buffer, "[needed] ");
1806       pp_character (buffer, '(');
1807       dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
1808                          spc, flags, false);
1809       pp_character (buffer, ')');
1810     }
1811 }
1812
1813
1814 /* Dump all the memory operands for statement GS.  BUFFER, SPC and
1815    FLAGS are as in dump_gimple_stmt.  */
1816
1817 static void
1818 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
1819 {
1820   tree vdef = gimple_vdef (gs);
1821   tree vuse = gimple_vuse (gs);
1822
1823   if (!ssa_operands_active () || !gimple_references_memory_p (gs))
1824     return;
1825
1826   if (vdef != NULL_TREE)
1827     {
1828       pp_string (buffer, "# ");
1829       dump_generic_node (buffer, vdef, spc + 2, flags, false);
1830       pp_string (buffer, " = VDEF <");
1831       dump_generic_node (buffer, vuse, spc + 2, flags, false);
1832       pp_character (buffer, '>');
1833       newline_and_indent (buffer, spc);
1834     }
1835   else if (vuse != NULL_TREE)
1836     {
1837       pp_string (buffer, "# VUSE <");
1838       dump_generic_node (buffer, vuse, spc + 2, flags, false);
1839       pp_character (buffer, '>');
1840       newline_and_indent (buffer, spc);
1841     }
1842 }
1843
1844
1845 /* Dump the gimple statement GS on the pretty printer BUFFER, SPC
1846    spaces of indent.  FLAGS specifies details to show in the dump (see
1847    TDF_* in tree-pass.h).  */
1848
1849 void
1850 dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags)
1851 {
1852   if (!gs)
1853     return;
1854
1855   if (flags & TDF_STMTADDR)
1856     pp_printf (buffer, "<&%p> ", (void *) gs);
1857
1858   if ((flags & TDF_LINENO) && gimple_has_location (gs))
1859     {
1860       expanded_location xloc = expand_location (gimple_location (gs));
1861       pp_character (buffer, '[');
1862       if (xloc.file)
1863         {
1864           pp_string (buffer, xloc.file);
1865           pp_string (buffer, " : ");
1866         }
1867       pp_decimal_int (buffer, xloc.line);
1868       pp_string (buffer, ":");
1869       pp_decimal_int (buffer, xloc.column);
1870       pp_string (buffer, "] ");
1871     }
1872
1873   if (flags & TDF_EH)
1874     {
1875       int lp_nr = lookup_stmt_eh_lp (gs);
1876       if (lp_nr > 0)
1877         pp_printf (buffer, "[LP %d] ", lp_nr);
1878       else if (lp_nr < 0)
1879         pp_printf (buffer, "[MNT %d] ", -lp_nr);
1880     }
1881
1882   if ((flags & (TDF_VOPS|TDF_MEMSYMS))
1883       && gimple_has_mem_ops (gs))
1884     dump_gimple_mem_ops (buffer, gs, spc, flags);
1885
1886   if ((flags & TDF_ALIAS)
1887       && gimple_has_lhs (gs))
1888     {
1889       tree lhs = gimple_get_lhs (gs);
1890       if (TREE_CODE (lhs) == SSA_NAME
1891           && POINTER_TYPE_P (TREE_TYPE (lhs))
1892           && SSA_NAME_PTR_INFO (lhs))
1893         {
1894           struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
1895           pp_string (buffer, "# PT = ");
1896           pp_points_to_solution (buffer, &pi->pt);
1897           newline_and_indent (buffer, spc);
1898           if (pi->align != 1)
1899             {
1900               pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u",
1901                          pi->align, pi->misalign);
1902               newline_and_indent (buffer, spc);
1903             }
1904         }
1905     }
1906
1907   switch (gimple_code (gs))
1908     {
1909     case GIMPLE_ASM:
1910       dump_gimple_asm (buffer, gs, spc, flags);
1911       break;
1912
1913     case GIMPLE_ASSIGN:
1914       dump_gimple_assign (buffer, gs, spc, flags);
1915       break;
1916
1917     case GIMPLE_BIND:
1918       dump_gimple_bind (buffer, gs, spc, flags);
1919       break;
1920
1921     case GIMPLE_CALL:
1922       dump_gimple_call (buffer, gs, spc, flags);
1923       break;
1924
1925     case GIMPLE_COND:
1926       dump_gimple_cond (buffer, gs, spc, flags);
1927       break;
1928
1929     case GIMPLE_LABEL:
1930       dump_gimple_label (buffer, gs, spc, flags);
1931       break;
1932
1933     case GIMPLE_GOTO:
1934       dump_gimple_goto (buffer, gs, spc, flags);
1935       break;
1936
1937     case GIMPLE_NOP:
1938       pp_string (buffer, "GIMPLE_NOP");
1939       break;
1940
1941     case GIMPLE_RETURN:
1942       dump_gimple_return (buffer, gs, spc, flags);
1943       break;
1944
1945     case GIMPLE_SWITCH:
1946       dump_gimple_switch (buffer, gs, spc, flags);
1947       break;
1948
1949     case GIMPLE_TRY:
1950       dump_gimple_try (buffer, gs, spc, flags);
1951       break;
1952
1953     case GIMPLE_PHI:
1954       dump_gimple_phi (buffer, gs, spc, flags);
1955       break;
1956
1957     case GIMPLE_OMP_PARALLEL:
1958       dump_gimple_omp_parallel (buffer, gs, spc, flags);
1959       break;
1960
1961     case GIMPLE_OMP_TASK:
1962       dump_gimple_omp_task (buffer, gs, spc, flags);
1963       break;
1964
1965     case GIMPLE_OMP_ATOMIC_LOAD:
1966       dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
1967
1968       break;
1969
1970     case GIMPLE_OMP_ATOMIC_STORE:
1971       dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
1972       break;
1973
1974     case GIMPLE_OMP_FOR:
1975       dump_gimple_omp_for (buffer, gs, spc, flags);
1976       break;
1977
1978     case GIMPLE_OMP_CONTINUE:
1979       dump_gimple_omp_continue (buffer, gs, spc, flags);
1980       break;
1981
1982     case GIMPLE_OMP_SINGLE:
1983       dump_gimple_omp_single (buffer, gs, spc, flags);
1984       break;
1985
1986     case GIMPLE_OMP_RETURN:
1987       dump_gimple_omp_return (buffer, gs, spc, flags);
1988       break;
1989
1990     case GIMPLE_OMP_SECTIONS:
1991       dump_gimple_omp_sections (buffer, gs, spc, flags);
1992       break;
1993
1994     case GIMPLE_OMP_SECTIONS_SWITCH:
1995       pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
1996       break;
1997
1998     case GIMPLE_OMP_MASTER:
1999     case GIMPLE_OMP_ORDERED:
2000     case GIMPLE_OMP_SECTION:
2001       dump_gimple_omp_block (buffer, gs, spc, flags);
2002       break;
2003
2004     case GIMPLE_OMP_CRITICAL:
2005       dump_gimple_omp_critical (buffer, gs, spc, flags);
2006       break;
2007
2008     case GIMPLE_CATCH:
2009       dump_gimple_catch (buffer, gs, spc, flags);
2010       break;
2011
2012     case GIMPLE_EH_FILTER:
2013       dump_gimple_eh_filter (buffer, gs, spc, flags);
2014       break;
2015
2016     case GIMPLE_EH_MUST_NOT_THROW:
2017       dump_gimple_eh_must_not_throw (buffer, gs, spc, flags);
2018       break;
2019
2020     case GIMPLE_EH_ELSE:
2021       dump_gimple_eh_else (buffer, gs, spc, flags);
2022       break;
2023
2024     case GIMPLE_RESX:
2025       dump_gimple_resx (buffer, gs, spc, flags);
2026       break;
2027
2028     case GIMPLE_EH_DISPATCH:
2029       dump_gimple_eh_dispatch (buffer, gs, spc, flags);
2030       break;
2031
2032     case GIMPLE_DEBUG:
2033       dump_gimple_debug (buffer, gs, spc, flags);
2034       break;
2035
2036     case GIMPLE_PREDICT:
2037       pp_string (buffer, "// predicted ");
2038       if (gimple_predict_outcome (gs))
2039         pp_string (buffer, "likely by ");
2040       else
2041         pp_string (buffer, "unlikely by ");
2042       pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
2043       pp_string (buffer, " predictor.");
2044       break;
2045
2046     case GIMPLE_TRANSACTION:
2047       dump_gimple_transaction (buffer, gs, spc, flags);
2048       break;
2049
2050     default:
2051       GIMPLE_NIY;
2052     }
2053
2054   /* If we're building a diagnostic, the formatted text will be
2055      written into BUFFER's stream by the caller; otherwise, write it
2056      now.  */
2057   if (!(flags & TDF_DIAGNOSTIC))
2058     pp_write_text_to_stream (buffer);
2059 }
2060
2061
2062 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
2063    spaces and details described by flags.  */
2064
2065 static void
2066 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
2067 {
2068   edge e;
2069   gimple stmt;
2070   edge_iterator ei;
2071
2072   if (flags & TDF_BLOCKS)
2073     {
2074       INDENT (indent);
2075       pp_string (buffer, "# BLOCK ");
2076       pp_decimal_int (buffer, bb->index);
2077       if (bb->frequency)
2078         {
2079           pp_string (buffer, " freq:");
2080           pp_decimal_int (buffer, bb->frequency);
2081         }
2082       if (bb->count)
2083         {
2084           pp_string (buffer, " count:");
2085           pp_widest_integer (buffer, bb->count);
2086         }
2087
2088       if (flags & TDF_LINENO)
2089         {
2090           gimple_stmt_iterator gsi;
2091
2092           for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2093             if (!is_gimple_debug (gsi_stmt (gsi))
2094                 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
2095               {
2096                 pp_string (buffer, ", starting at line ");
2097                 pp_decimal_int (buffer, get_lineno (gsi_stmt (gsi)));
2098                 break;
2099               }
2100
2101           if (bb->discriminator)
2102             {
2103               pp_string (buffer, ", discriminator ");
2104               pp_decimal_int (buffer, bb->discriminator);
2105             }
2106         }
2107       newline_and_indent (buffer, indent);
2108
2109       pp_string (buffer, "# PRED:");
2110       pp_write_text_to_stream (buffer);
2111       FOR_EACH_EDGE (e, ei, bb->preds)
2112         if (flags & TDF_SLIM)
2113           {
2114             pp_character (buffer, ' ');
2115             if (e->src == ENTRY_BLOCK_PTR)
2116               pp_string (buffer, "ENTRY");
2117             else
2118               pp_decimal_int (buffer, e->src->index);
2119           }
2120         else
2121           dump_edge_info (buffer->buffer->stream, e, 0);
2122       pp_newline (buffer);
2123     }
2124   else
2125     {
2126       stmt = first_stmt (bb);
2127       if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
2128         {
2129           INDENT (indent - 2);
2130           pp_string (buffer, "<bb ");
2131           pp_decimal_int (buffer, bb->index);
2132           pp_string (buffer, ">:");
2133           pp_newline (buffer);
2134         }
2135     }
2136   pp_write_text_to_stream (buffer);
2137   if (cfun)
2138     check_bb_profile (bb, buffer->buffer->stream);
2139 }
2140
2141
2142 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2143    spaces.  */
2144
2145 static void
2146 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
2147 {
2148   edge e;
2149   edge_iterator ei;
2150
2151   INDENT (indent);
2152   pp_string (buffer, "# SUCC:");
2153   pp_write_text_to_stream (buffer);
2154   FOR_EACH_EDGE (e, ei, bb->succs)
2155     if (flags & TDF_SLIM)
2156       {
2157         pp_character (buffer, ' ');
2158         if (e->dest == EXIT_BLOCK_PTR)
2159           pp_string (buffer, "EXIT");
2160         else
2161           pp_decimal_int (buffer, e->dest->index);
2162       }
2163     else
2164       dump_edge_info (buffer->buffer->stream, e, 1);
2165   pp_newline (buffer);
2166 }
2167
2168
2169 /* Dump PHI nodes of basic block BB to BUFFER with details described
2170    by FLAGS and indented by INDENT spaces.  */
2171
2172 static void
2173 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2174 {
2175   gimple_stmt_iterator i;
2176
2177   for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2178     {
2179       gimple phi = gsi_stmt (i);
2180       if (is_gimple_reg (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2181         {
2182           INDENT (indent);
2183           pp_string (buffer, "# ");
2184           dump_gimple_phi (buffer, phi, indent, flags);
2185           pp_newline (buffer);
2186         }
2187     }
2188 }
2189
2190
2191 /* Dump jump to basic block BB that is represented implicitly in the cfg
2192    to BUFFER.  */
2193
2194 static void
2195 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2196 {
2197   gimple stmt;
2198
2199   stmt = first_stmt (bb);
2200
2201   pp_string (buffer, "goto <bb ");
2202   pp_decimal_int (buffer, bb->index);
2203   pp_character (buffer, '>');
2204   if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
2205     {
2206       pp_string (buffer, " (");
2207       dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
2208       pp_character (buffer, ')');
2209       pp_semicolon (buffer);
2210     }
2211   else
2212     pp_semicolon (buffer);
2213 }
2214
2215
2216 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2217    by INDENT spaces, with details given by FLAGS.  */
2218
2219 static void
2220 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2221                      int flags)
2222 {
2223   edge e;
2224   gimple stmt;
2225
2226   stmt = last_stmt (bb);
2227
2228   if (stmt && gimple_code (stmt) == GIMPLE_COND)
2229     {
2230       edge true_edge, false_edge;
2231
2232       /* When we are emitting the code or changing CFG, it is possible that
2233          the edges are not yet created.  When we are using debug_bb in such
2234          a situation, we do not want it to crash.  */
2235       if (EDGE_COUNT (bb->succs) != 2)
2236         return;
2237       extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2238
2239       INDENT (indent + 2);
2240       pp_cfg_jump (buffer, true_edge->dest);
2241       newline_and_indent (buffer, indent);
2242       pp_string (buffer, "else");
2243       newline_and_indent (buffer, indent + 2);
2244       pp_cfg_jump (buffer, false_edge->dest);
2245       pp_newline (buffer);
2246       return;
2247     }
2248
2249   /* If there is a fallthru edge, we may need to add an artificial
2250      goto to the dump.  */
2251   e = find_fallthru_edge (bb->succs);
2252
2253   if (e && e->dest != bb->next_bb)
2254     {
2255       INDENT (indent);
2256
2257       if ((flags & TDF_LINENO)
2258           && e->goto_locus != UNKNOWN_LOCATION
2259           )
2260         {
2261           expanded_location goto_xloc;
2262           goto_xloc = expand_location (e->goto_locus);
2263           pp_character (buffer, '[');
2264           if (goto_xloc.file)
2265             {
2266               pp_string (buffer, goto_xloc.file);
2267               pp_string (buffer, " : ");
2268             }
2269           pp_decimal_int (buffer, goto_xloc.line);
2270           pp_string (buffer, " : ");
2271           pp_decimal_int (buffer, goto_xloc.column);
2272           pp_string (buffer, "] ");
2273         }
2274
2275       pp_cfg_jump (buffer, e->dest);
2276       pp_newline (buffer);
2277     }
2278 }
2279
2280
2281 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2282    indented by INDENT spaces.  */
2283
2284 static void
2285 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2286                      int flags)
2287 {
2288   gimple_stmt_iterator gsi;
2289   gimple stmt;
2290   int label_indent = indent - 2;
2291
2292   if (label_indent < 0)
2293     label_indent = 0;
2294
2295   dump_bb_header (buffer, bb, indent, flags);
2296   dump_phi_nodes (buffer, bb, indent, flags);
2297
2298   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2299     {
2300       int curr_indent;
2301
2302       stmt = gsi_stmt (gsi);
2303
2304       curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2305
2306       INDENT (curr_indent);
2307       dump_gimple_stmt (buffer, stmt, curr_indent, flags);
2308       pp_newline (buffer);
2309       dump_histograms_for_stmt (cfun, buffer->buffer->stream, stmt);
2310     }
2311
2312   dump_implicit_edges (buffer, bb, indent, flags);
2313
2314   if (flags & TDF_BLOCKS)
2315     dump_bb_end (buffer, bb, indent, flags);
2316 }
2317
2318
2319 /* Dumps basic block BB to FILE with details described by FLAGS and
2320    indented by INDENT spaces.  */
2321
2322 void
2323 gimple_dump_bb (basic_block bb, FILE *file, int indent, int flags)
2324 {
2325   maybe_init_pretty_print (file);
2326   gimple_dump_bb_buff (&buffer, bb, indent, flags);
2327   pp_flush (&buffer);
2328 }