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