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