c: Support C2x empty initializer braces
[platform/upstream/gcc.git] / gcc / gimple-pretty-print.cc
1 /* Pretty formatting of GIMPLE statements and expressions.
2    Copyright (C) 2001-2022 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 "dumpfile.h"
26 #include "backend.h"
27 #include "tree.h"
28 #include "gimple.h"
29 #include "gimple-predict.h"
30 #include "ssa.h"
31 #include "cgraph.h"
32 #include "gimple-pretty-print.h"
33 #include "value-range-pretty-print.h"
34 #include "internal-fn.h"
35 #include "tree-eh.h"
36 #include "gimple-iterator.h"
37 #include "tree-cfg.h"
38 #include "dumpfile.h"   /* for dump_flags */
39 #include "value-prof.h"
40 #include "trans-mem.h"
41 #include "cfganal.h"
42 #include "stringpool.h"
43 #include "attribs.h"
44 #include "asan.h"
45 #include "cfgloop.h"
46 #include "gimple-range.h"
47
48 /* Disable warnings about quoting issues in the pp_xxx calls below
49    that (intentionally) don't follow GCC diagnostic conventions.  */
50 #if __GNUC__ >= 10
51 #  pragma GCC diagnostic push
52 #  pragma GCC diagnostic ignored "-Wformat-diag"
53 #endif
54
55 #define INDENT(SPACE)                                                   \
56   do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
57
58 #define GIMPLE_NIY do_niy (buffer,gs)
59
60 /* Try to print on BUFFER a default message for the unrecognized
61    gimple statement GS.  */
62
63 static void
64 do_niy (pretty_printer *buffer, const gimple *gs)
65 {
66   pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
67              gimple_code_name[(int) gimple_code (gs)]);
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 }
88
89
90 /* Return formatted string of a VALUE probability
91    (biased by REG_BR_PROB_BASE).  Returned string is allocated
92    by xstrdup_for_dump.  */
93
94 static const char *
95 dump_profile (profile_count &count)
96 {
97   char *buf = NULL;
98   if (!count.initialized_p ())
99     return "";
100   if (count.ipa_p ())
101     buf = xasprintf ("[count: %" PRId64 "]",
102                      count.to_gcov_type ());
103   else if (count.initialized_p ())
104     buf = xasprintf ("[local count: %" PRId64 "]",
105                      count.to_gcov_type ());
106
107   const char *ret = xstrdup_for_dump (buf);
108   free (buf);
109
110   return ret;
111 }
112
113 /* Return formatted string of a VALUE probability
114    (biased by REG_BR_PROB_BASE).  Returned string is allocated
115    by xstrdup_for_dump.  */
116
117 static const char *
118 dump_probability (profile_probability probability)
119 {
120   float minimum = 0.01f;
121   float fvalue = -1;
122
123   if (probability.initialized_p ())
124     {
125       fvalue = probability.to_reg_br_prob_base () * 100.0f / REG_BR_PROB_BASE;
126       if (fvalue < minimum && probability.to_reg_br_prob_base ())
127         fvalue = minimum;
128     }
129
130   char *buf;
131   if (probability.initialized_p ())
132     buf = xasprintf ("[%.2f%%]", fvalue);
133   else
134     buf = xasprintf ("[INV]");
135
136   const char *ret = xstrdup_for_dump (buf);
137   free (buf);
138
139   return ret;
140 }
141
142 /* Dump E probability to BUFFER.  */
143
144 static void
145 dump_edge_probability (pretty_printer *buffer, edge e)
146 {
147   pp_scalar (buffer, " %s", dump_probability (e->probability));
148 }
149
150 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
151    FLAGS as in pp_gimple_stmt_1.  */
152
153 void
154 print_gimple_stmt (FILE *file, gimple *g, int spc, dump_flags_t flags)
155 {
156   pretty_printer buffer;
157   pp_needs_newline (&buffer) = true;
158   buffer.buffer->stream = file;
159   pp_gimple_stmt_1 (&buffer, g, spc, flags);
160   pp_newline_and_flush (&buffer);
161 }
162
163 DEBUG_FUNCTION void
164 debug (gimple &ref)
165 {
166   print_gimple_stmt (stderr, &ref, 0, TDF_NONE);
167 }
168
169 DEBUG_FUNCTION void
170 debug (gimple *ptr)
171 {
172   if (ptr)
173     debug (*ptr);
174   else
175     fprintf (stderr, "<nil>\n");
176 }
177
178
179 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
180    FLAGS as in pp_gimple_stmt_1.  Print only the right-hand side
181    of the statement.  */
182
183 void
184 print_gimple_expr (FILE *file, gimple *g, int spc, dump_flags_t flags)
185 {
186   flags |= TDF_RHS_ONLY;
187   pretty_printer buffer;
188   pp_needs_newline (&buffer) = true;
189   buffer.buffer->stream = file;
190   pp_gimple_stmt_1 (&buffer, g, spc, flags);
191   pp_flush (&buffer);
192 }
193
194
195 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentation
196    spaces and FLAGS as in pp_gimple_stmt_1.
197    The caller is responsible for calling pp_flush on BUFFER to finalize
198    the pretty printer.  */
199
200 static void
201 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc,
202                  dump_flags_t flags)
203 {
204   gimple_stmt_iterator i;
205
206   for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
207     {
208       gimple *gs = gsi_stmt (i);
209       INDENT (spc);
210       pp_gimple_stmt_1 (buffer, gs, spc, flags);
211       if (!gsi_one_before_end_p (i))
212         pp_newline (buffer);
213     }
214 }
215
216
217 /* Print GIMPLE sequence SEQ to FILE using SPC indentation spaces and
218    FLAGS as in pp_gimple_stmt_1.  */
219
220 void
221 print_gimple_seq (FILE *file, gimple_seq seq, int spc, dump_flags_t flags)
222 {
223   pretty_printer buffer;
224   pp_needs_newline (&buffer) = true;
225   buffer.buffer->stream = file;
226   dump_gimple_seq (&buffer, seq, spc, flags);
227   pp_newline_and_flush (&buffer);
228 }
229
230
231 /* Print the GIMPLE sequence SEQ on stderr.  */
232
233 DEBUG_FUNCTION void
234 debug_gimple_seq (gimple_seq seq)
235 {
236   print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
237 }
238
239
240 /* A simple helper to pretty-print some of the gimple tuples in the printf
241    style. The format modifiers are preceded by '%' and are:
242      'G' - outputs a string corresponding to the code of the given gimple,
243      'S' - outputs a gimple_seq with indent of spc + 2,
244      'T' - outputs the tree t,
245      'd' - outputs an int as a decimal,
246      's' - outputs a string,
247      'n' - outputs a newline,
248      'x' - outputs an int as hexadecimal,
249      '+' - increases indent by 2 then outputs a newline,
250      '-' - decreases indent by 2 then outputs a newline.   */
251
252 static void
253 dump_gimple_fmt (pretty_printer *buffer, int spc, dump_flags_t flags,
254                  const char *fmt, ...)
255 {
256   va_list args;
257   const char *c;
258   const char *tmp;
259
260   va_start (args, fmt);
261   for (c = fmt; *c; c++)
262     {
263       if (*c == '%')
264         {
265           gimple_seq seq;
266           tree t;
267           gimple *g;
268           switch (*++c)
269             {
270               case 'G':
271                 g = va_arg (args, gimple *);
272                 tmp = gimple_code_name[gimple_code (g)];
273                 pp_string (buffer, tmp);
274                 break;
275
276               case 'S':
277                 seq = va_arg (args, gimple_seq);
278                 pp_newline (buffer);
279                 dump_gimple_seq (buffer, seq, spc + 2, flags);
280                 newline_and_indent (buffer, spc);
281                 break;
282
283               case 'T':
284                 t = va_arg (args, tree);
285                 if (t == NULL_TREE)
286                   pp_string (buffer, "NULL");
287                 else
288                   dump_generic_node (buffer, t, spc, flags, false);
289                 break;
290
291               case 'd':
292                 pp_decimal_int (buffer, va_arg (args, int));
293                 break;
294
295               case 's':
296                 pp_string (buffer, va_arg (args, char *));
297                 break;
298
299               case 'n':
300                 newline_and_indent (buffer, spc);
301                 break;
302
303               case 'x':
304                 pp_scalar (buffer, "%x", va_arg (args, int));
305                 break;
306
307               case '+':
308                 spc += 2;
309                 newline_and_indent (buffer, spc);
310                 break;
311
312               case '-':
313                 spc -= 2;
314                 newline_and_indent (buffer, spc);
315                 break;
316
317               default:
318                 gcc_unreachable ();
319             }
320         }
321       else
322         pp_character (buffer, *c);
323     }
324   va_end (args);
325 }
326
327
328 /* Helper for dump_gimple_assign.  Print the unary RHS of the
329    assignment GS.  BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.  */
330
331 static void
332 dump_unary_rhs (pretty_printer *buffer, const gassign *gs, int spc,
333                 dump_flags_t flags)
334 {
335   enum tree_code rhs_code = gimple_assign_rhs_code (gs);
336   tree lhs = gimple_assign_lhs (gs);
337   tree rhs = gimple_assign_rhs1 (gs);
338
339   switch (rhs_code)
340     {
341     case VIEW_CONVERT_EXPR:
342     case ASSERT_EXPR:
343       dump_generic_node (buffer, rhs, spc, flags, false);
344       break;
345
346     case FIXED_CONVERT_EXPR:
347     case ADDR_SPACE_CONVERT_EXPR:
348     case FIX_TRUNC_EXPR:
349     case FLOAT_EXPR:
350     CASE_CONVERT:
351       pp_left_paren (buffer);
352       dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
353       pp_string (buffer, ") ");
354       if (op_prio (rhs) < op_code_prio (rhs_code))
355         {
356           pp_left_paren (buffer);
357           dump_generic_node (buffer, rhs, spc, flags, false);
358           pp_right_paren (buffer);
359         }
360       else
361         dump_generic_node (buffer, rhs, spc, flags, false);
362       break;
363
364     case PAREN_EXPR:
365       pp_string (buffer, "((");
366       dump_generic_node (buffer, rhs, spc, flags, false);
367       pp_string (buffer, "))");
368       break;
369
370     case ABS_EXPR:
371     case ABSU_EXPR:
372       if (flags & TDF_GIMPLE)
373         {
374           pp_string (buffer,
375                      rhs_code == ABS_EXPR ? "__ABS " : "__ABSU ");
376           dump_generic_node (buffer, rhs, spc, flags, false);
377         }
378       else
379         {
380           pp_string (buffer,
381                      rhs_code == ABS_EXPR ? "ABS_EXPR <" : "ABSU_EXPR <");
382           dump_generic_node (buffer, rhs, spc, flags, false);
383           pp_greater (buffer);
384         }
385       break;
386
387     default:
388       if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
389           || TREE_CODE_CLASS (rhs_code) == tcc_constant
390           || TREE_CODE_CLASS (rhs_code) == tcc_reference
391           || rhs_code == SSA_NAME
392           || rhs_code == ADDR_EXPR
393           || rhs_code == CONSTRUCTOR)
394         {
395           dump_generic_node (buffer, rhs, spc, flags, false);
396           break;
397         }
398       else if (rhs_code == BIT_NOT_EXPR)
399         pp_complement (buffer);
400       else if (rhs_code == TRUTH_NOT_EXPR)
401         pp_exclamation (buffer);
402       else if (rhs_code == NEGATE_EXPR)
403         pp_minus (buffer);
404       else
405         {
406           pp_left_bracket (buffer);
407           pp_string (buffer, get_tree_code_name (rhs_code));
408           pp_string (buffer, "] ");
409         }
410
411       if (op_prio (rhs) < op_code_prio (rhs_code))
412         {
413           pp_left_paren (buffer);
414           dump_generic_node (buffer, rhs, spc, flags, false);
415           pp_right_paren (buffer);
416         }
417       else
418         dump_generic_node (buffer, rhs, spc, flags, false);
419       break;
420     }
421 }
422
423
424 /* Helper for dump_gimple_assign.  Print the binary RHS of the
425    assignment GS.  BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.  */
426
427 static void
428 dump_binary_rhs (pretty_printer *buffer, const gassign *gs, int spc,
429                  dump_flags_t flags)
430 {
431   const char *p;
432   enum tree_code code = gimple_assign_rhs_code (gs);
433   switch (code)
434     {
435     case MIN_EXPR:
436     case MAX_EXPR:
437       if (flags & TDF_GIMPLE)
438         {
439           pp_string (buffer, code == MIN_EXPR ? "__MIN (" : "__MAX (");
440           dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
441                              false);
442           pp_string (buffer, ", ");
443           dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
444                              false);
445           pp_string (buffer, ")");
446           break;
447         }
448       else
449         {
450           gcc_fallthrough ();
451         }
452     case COMPLEX_EXPR:
453     case VEC_WIDEN_MULT_HI_EXPR:
454     case VEC_WIDEN_MULT_LO_EXPR:
455     case VEC_WIDEN_MULT_EVEN_EXPR:
456     case VEC_WIDEN_MULT_ODD_EXPR:
457     case VEC_PACK_TRUNC_EXPR:
458     case VEC_PACK_SAT_EXPR:
459     case VEC_PACK_FIX_TRUNC_EXPR:
460     case VEC_PACK_FLOAT_EXPR:
461     case VEC_WIDEN_LSHIFT_HI_EXPR:
462     case VEC_WIDEN_LSHIFT_LO_EXPR:
463     case VEC_WIDEN_PLUS_HI_EXPR:
464     case VEC_WIDEN_PLUS_LO_EXPR:
465     case VEC_WIDEN_MINUS_HI_EXPR:
466     case VEC_WIDEN_MINUS_LO_EXPR:
467     case VEC_SERIES_EXPR:
468       for (p = get_tree_code_name (code); *p; p++)
469         pp_character (buffer, TOUPPER (*p));
470       pp_string (buffer, " <");
471       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
472       pp_string (buffer, ", ");
473       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
474       pp_greater (buffer);
475       break;
476
477     default:
478       if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
479         {
480           pp_left_paren (buffer);
481           dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
482                              false);
483           pp_right_paren (buffer);
484         }
485       else
486         dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
487       pp_space (buffer);
488       pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
489       pp_space (buffer);
490       if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
491         {
492           pp_left_paren (buffer);
493           dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
494                              false);
495           pp_right_paren (buffer);
496         }
497       else
498         dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
499     }
500 }
501
502 /* Helper for dump_gimple_assign.  Print the ternary RHS of the
503    assignment GS.  BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.  */
504
505 static void
506 dump_ternary_rhs (pretty_printer *buffer, const gassign *gs, int spc,
507                   dump_flags_t flags)
508 {
509   const char *p;
510   enum tree_code code = gimple_assign_rhs_code (gs);
511   switch (code)
512     {
513     case WIDEN_MULT_PLUS_EXPR:
514     case WIDEN_MULT_MINUS_EXPR:
515       for (p = get_tree_code_name (code); *p; p++)
516         pp_character (buffer, TOUPPER (*p));
517       pp_string (buffer, " <");
518       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
519       pp_string (buffer, ", ");
520       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
521       pp_string (buffer, ", ");
522       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
523       pp_greater (buffer);
524       break;
525
526     case DOT_PROD_EXPR:
527       pp_string (buffer, "DOT_PROD_EXPR <");
528       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
529       pp_string (buffer, ", ");
530       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
531       pp_string (buffer, ", ");
532       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
533       pp_greater (buffer);
534       break;
535
536     case SAD_EXPR:
537       pp_string (buffer, "SAD_EXPR <");
538       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
539       pp_string (buffer, ", ");
540       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
541       pp_string (buffer, ", ");
542       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
543       pp_greater (buffer);
544       break;
545     
546     case VEC_PERM_EXPR:
547       if (flags & TDF_GIMPLE)
548         pp_string (buffer, "__VEC_PERM (");
549       else
550         pp_string (buffer, "VEC_PERM_EXPR <");
551       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
552       pp_string (buffer, ", ");
553       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
554       pp_string (buffer, ", ");
555       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
556       if (flags & TDF_GIMPLE)
557         pp_right_paren (buffer);
558       else
559         pp_greater (buffer);
560       break;
561
562     case REALIGN_LOAD_EXPR:
563       pp_string (buffer, "REALIGN_LOAD <");
564       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
565       pp_string (buffer, ", ");
566       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
567       pp_string (buffer, ", ");
568       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
569       pp_greater (buffer);
570       break;
571
572     case COND_EXPR:
573       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
574       pp_string (buffer, " ? ");
575       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
576       pp_string (buffer, " : ");
577       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
578       break;
579
580     case VEC_COND_EXPR:
581       pp_string (buffer, "VEC_COND_EXPR <");
582       dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
583       pp_string (buffer, ", ");
584       dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
585       pp_string (buffer, ", ");
586       dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
587       pp_greater (buffer);
588       break;
589
590     case BIT_INSERT_EXPR:
591       if (flags & TDF_GIMPLE)
592         {
593           pp_string (buffer, "__BIT_INSERT (");
594           dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc,
595                              flags | TDF_SLIM, false);
596           pp_string (buffer, ", ");
597           dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc,
598                              flags | TDF_SLIM, false);
599           pp_string (buffer, ", ");
600           dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc,
601                              flags | TDF_SLIM, false);
602           pp_right_paren (buffer);
603         }
604       else
605         {
606           pp_string (buffer, "BIT_INSERT_EXPR <");
607           dump_generic_node (buffer, gimple_assign_rhs1 (gs),
608                              spc, flags, false);
609           pp_string (buffer, ", ");
610           dump_generic_node (buffer, gimple_assign_rhs2 (gs),
611                              spc, flags, false);
612           pp_string (buffer, ", ");
613           dump_generic_node (buffer, gimple_assign_rhs3 (gs),
614                              spc, flags, false);
615           if (INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs2 (gs))))
616             {
617               pp_string (buffer, " (");
618               pp_decimal_int (buffer, TYPE_PRECISION
619                               (TREE_TYPE (gimple_assign_rhs2 (gs))));
620               pp_string (buffer, " bits)");
621             }
622           pp_greater (buffer);
623         }
624       break;
625
626     default:
627       gcc_unreachable ();
628     }
629 }
630
631
632 /* Dump the gimple assignment GS.  BUFFER, SPC and FLAGS are as in
633    pp_gimple_stmt_1.  */
634
635 static void
636 dump_gimple_assign (pretty_printer *buffer, const gassign *gs, int spc,
637                     dump_flags_t flags)
638 {
639   if (flags & TDF_RAW)
640     {
641       tree arg1 = NULL;
642       tree arg2 = NULL;
643       tree arg3 = NULL;
644       switch (gimple_num_ops (gs))
645         {
646         case 4:
647           arg3 = gimple_assign_rhs3 (gs);
648           /* FALLTHRU */
649         case 3:
650           arg2 = gimple_assign_rhs2 (gs);
651           /* FALLTHRU */
652         case 2:
653           arg1 = gimple_assign_rhs1 (gs);
654           break;
655         default:
656           gcc_unreachable ();
657         }
658
659       dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
660                        get_tree_code_name (gimple_assign_rhs_code (gs)),
661                        gimple_assign_lhs (gs), arg1, arg2, arg3);
662     }
663   else
664     {
665       if (!(flags & TDF_RHS_ONLY))
666         {
667           dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
668           pp_space (buffer);
669           pp_equal (buffer);
670
671           if (gimple_assign_nontemporal_move_p (gs))
672             pp_string (buffer, "{nt}");
673
674           if (gimple_has_volatile_ops (gs))
675             pp_string (buffer, "{v}");
676
677           pp_space (buffer);
678         }
679
680       if (gimple_num_ops (gs) == 2)
681         dump_unary_rhs (buffer, gs, spc,
682                         ((flags & TDF_GIMPLE)
683                          && gimple_assign_rhs_class (gs) != GIMPLE_SINGLE_RHS)
684                         ? (flags | TDF_GIMPLE_VAL) : flags);
685       else if (gimple_num_ops (gs) == 3)
686         dump_binary_rhs (buffer, gs, spc,
687                          (flags & TDF_GIMPLE)
688                          ? (flags | TDF_GIMPLE_VAL) : flags);
689       else if (gimple_num_ops (gs) == 4)
690         dump_ternary_rhs (buffer, gs, spc,
691                           (flags & TDF_GIMPLE)
692                           ? (flags | TDF_GIMPLE_VAL) : flags);
693       else
694         gcc_unreachable ();
695       if (!(flags & TDF_RHS_ONLY))
696         pp_semicolon (buffer);
697     }
698 }
699
700
701 /* Dump the return statement GS.  BUFFER, SPC and FLAGS are as in
702    pp_gimple_stmt_1.  */
703
704 static void
705 dump_gimple_return (pretty_printer *buffer, const greturn *gs, int spc,
706                     dump_flags_t flags)
707 {
708   tree t;
709
710   t = gimple_return_retval (gs);
711   if (flags & TDF_RAW)
712     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
713   else
714     {
715       pp_string (buffer, "return");
716       if (t)
717         {
718           pp_space (buffer);
719           dump_generic_node (buffer, t, spc, flags, false);
720         }
721       pp_semicolon (buffer);
722     }
723 }
724
725
726 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
727    dump_gimple_call.  */
728
729 static void
730 dump_gimple_call_args (pretty_printer *buffer, const gcall *gs,
731                        dump_flags_t flags)
732 {
733   size_t i = 0;
734
735   /* Pretty print first arg to certain internal fns.  */
736   if (gimple_call_internal_p (gs))
737     {
738       const char *const *enums = NULL;
739       unsigned limit = 0;
740
741       switch (gimple_call_internal_fn (gs))
742         {
743         case IFN_UNIQUE:
744 #define DEF(X) #X
745           static const char *const unique_args[] = {IFN_UNIQUE_CODES};
746 #undef DEF
747           enums = unique_args;
748           
749           limit = ARRAY_SIZE (unique_args);
750           break;
751           
752         case IFN_GOACC_LOOP:
753 #define DEF(X) #X
754           static const char *const loop_args[] = {IFN_GOACC_LOOP_CODES};
755 #undef DEF
756           enums = loop_args;
757           limit = ARRAY_SIZE (loop_args);
758           break;
759
760         case IFN_GOACC_REDUCTION:
761 #define DEF(X) #X
762           static const char *const reduction_args[]
763             = {IFN_GOACC_REDUCTION_CODES};
764 #undef DEF
765           enums = reduction_args;
766           limit = ARRAY_SIZE (reduction_args);
767           break;
768
769         case IFN_HWASAN_MARK:
770         case IFN_ASAN_MARK:
771 #define DEF(X) #X
772           static const char *const asan_mark_args[] = {IFN_ASAN_MARK_FLAGS};
773 #undef DEF
774           enums = asan_mark_args;
775           limit = ARRAY_SIZE (asan_mark_args);
776           break;
777
778         default:
779           break;
780         }
781       if (limit)
782         {
783           tree arg0 = gimple_call_arg (gs, 0);
784           HOST_WIDE_INT v;
785
786           if (TREE_CODE (arg0) == INTEGER_CST
787               && tree_fits_shwi_p (arg0)
788               && (v = tree_to_shwi (arg0)) >= 0 && v < limit)
789             {
790               i++;
791               pp_string (buffer, enums[v]);
792             }
793         }
794     }
795
796   for (; i < gimple_call_num_args (gs); i++)
797     {
798       if (i)
799         pp_string (buffer, ", ");
800       dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
801     }
802
803   if (gimple_call_va_arg_pack_p (gs))
804     {
805       if (i)
806         pp_string (buffer, ", ");
807
808       pp_string (buffer, "__builtin_va_arg_pack ()");
809     }
810 }
811
812 /* Dump the points-to solution *PT to BUFFER.  */
813
814 static void
815 pp_points_to_solution (pretty_printer *buffer, const pt_solution *pt)
816 {
817   if (pt->anything)
818     {
819       pp_string (buffer, "anything ");
820       return;
821     }
822   if (pt->nonlocal)
823     pp_string (buffer, "nonlocal ");
824   if (pt->escaped)
825     pp_string (buffer, "escaped ");
826   if (pt->ipa_escaped)
827     pp_string (buffer, "unit-escaped ");
828   if (pt->null)
829     pp_string (buffer, "null ");
830   if (pt->vars
831       && !bitmap_empty_p (pt->vars))
832     {
833       bitmap_iterator bi;
834       unsigned i;
835       pp_string (buffer, "{ ");
836       EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
837         {
838           pp_string (buffer, "D.");
839           pp_decimal_int (buffer, i);
840           pp_space (buffer);
841         }
842       pp_right_brace (buffer);
843       if (pt->vars_contains_nonlocal
844           || pt->vars_contains_escaped
845           || pt->vars_contains_escaped_heap
846           || pt->vars_contains_restrict)
847         {
848           const char *comma = "";
849           pp_string (buffer, " (");
850           if (pt->vars_contains_nonlocal)
851             {
852               pp_string (buffer, "nonlocal");
853               comma = ", ";
854             }
855           if (pt->vars_contains_escaped)
856             {
857               pp_string (buffer, comma);
858               pp_string (buffer, "escaped");
859               comma = ", ";
860             }
861           if (pt->vars_contains_escaped_heap)
862             {
863               pp_string (buffer, comma);
864               pp_string (buffer, "escaped heap");
865               comma = ", ";
866             }
867           if (pt->vars_contains_restrict)
868             {
869               pp_string (buffer, comma);
870               pp_string (buffer, "restrict");
871               comma = ", ";
872             }
873           if (pt->vars_contains_interposable)
874             {
875               pp_string (buffer, comma);
876               pp_string (buffer, "interposable");
877             }
878           pp_string (buffer, ")");
879         }
880
881     }
882 }
883
884 /* Dump the call statement GS.  BUFFER, SPC and FLAGS are as in
885    pp_gimple_stmt_1.  */
886
887 static void
888 dump_gimple_call (pretty_printer *buffer, const gcall *gs, int spc,
889                   dump_flags_t flags)
890 {
891   tree lhs = gimple_call_lhs (gs);
892   tree fn = gimple_call_fn (gs);
893
894   if (flags & TDF_ALIAS)
895     {
896       const pt_solution *pt;
897       pt = gimple_call_use_set (gs);
898       if (!pt_solution_empty_p (pt))
899         {
900           pp_string (buffer, "# USE = ");
901           pp_points_to_solution (buffer, pt);
902           newline_and_indent (buffer, spc);
903         }
904       pt = gimple_call_clobber_set (gs);
905       if (!pt_solution_empty_p (pt))
906         {
907           pp_string (buffer, "# CLB = ");
908           pp_points_to_solution (buffer, pt);
909           newline_and_indent (buffer, spc);
910         }
911     }
912
913   if (flags & TDF_RAW)
914     {
915       if (gimple_call_internal_p (gs))
916         dump_gimple_fmt (buffer, spc, flags, "%G <.%s, %T", gs,
917                          internal_fn_name (gimple_call_internal_fn (gs)), lhs);
918       else
919         dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T", gs, fn, lhs);
920       if (gimple_call_num_args (gs) > 0)
921         {
922           pp_string (buffer, ", ");
923           dump_gimple_call_args (buffer, gs, flags);
924         }
925       pp_greater (buffer);
926     }
927   else
928     {
929       if (lhs && !(flags & TDF_RHS_ONLY))
930         {
931           dump_generic_node (buffer, lhs, spc, flags, false);
932           pp_string (buffer, " =");
933
934           if (gimple_has_volatile_ops (gs))
935             pp_string (buffer, "{v}");
936
937           pp_space (buffer);
938         }
939       if (gimple_call_internal_p (gs))
940         {
941           pp_dot (buffer);
942           pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
943         }
944       else
945         print_call_name (buffer, fn, flags);
946       pp_string (buffer, " (");
947       dump_gimple_call_args (buffer, gs, flags);
948       pp_right_paren (buffer);
949       if (!(flags & TDF_RHS_ONLY))
950         pp_semicolon (buffer);
951     }
952
953   if (gimple_call_chain (gs))
954     {
955       pp_string (buffer, " [static-chain: ");
956       dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
957       pp_right_bracket (buffer);
958     }
959
960   if (gimple_call_return_slot_opt_p (gs))
961     pp_string (buffer, " [return slot optimization]");
962   if (gimple_call_tail_p (gs))
963     pp_string (buffer, " [tail call]");
964   if (gimple_call_must_tail_p (gs))
965     pp_string (buffer, " [must tail call]");
966
967   if (fn == NULL)
968     return;
969
970   /* Dump the arguments of _ITM_beginTransaction sanely.  */
971   if (TREE_CODE (fn) == ADDR_EXPR)
972     fn = TREE_OPERAND (fn, 0);
973   if (TREE_CODE (fn) == FUNCTION_DECL && decl_is_tm_clone (fn))
974     pp_string (buffer, " [tm-clone]");
975   if (TREE_CODE (fn) == FUNCTION_DECL
976       && fndecl_built_in_p (fn, BUILT_IN_TM_START)
977       && gimple_call_num_args (gs) > 0)
978     {
979       tree t = gimple_call_arg (gs, 0);
980       unsigned HOST_WIDE_INT props;
981       gcc_assert (TREE_CODE (t) == INTEGER_CST);
982
983       pp_string (buffer, " [ ");
984
985       /* Get the transaction code properties.  */
986       props = TREE_INT_CST_LOW (t);
987
988       if (props & PR_INSTRUMENTEDCODE)
989         pp_string (buffer, "instrumentedCode ");
990       if (props & PR_UNINSTRUMENTEDCODE)
991         pp_string (buffer, "uninstrumentedCode ");
992       if (props & PR_HASNOXMMUPDATE)
993         pp_string (buffer, "hasNoXMMUpdate ");
994       if (props & PR_HASNOABORT)
995         pp_string (buffer, "hasNoAbort ");
996       if (props & PR_HASNOIRREVOCABLE)
997         pp_string (buffer, "hasNoIrrevocable ");
998       if (props & PR_DOESGOIRREVOCABLE)
999         pp_string (buffer, "doesGoIrrevocable ");
1000       if (props & PR_HASNOSIMPLEREADS)
1001         pp_string (buffer, "hasNoSimpleReads ");
1002       if (props & PR_AWBARRIERSOMITTED)
1003         pp_string (buffer, "awBarriersOmitted ");
1004       if (props & PR_RARBARRIERSOMITTED)
1005         pp_string (buffer, "RaRBarriersOmitted ");
1006       if (props & PR_UNDOLOGCODE)
1007         pp_string (buffer, "undoLogCode ");
1008       if (props & PR_PREFERUNINSTRUMENTED)
1009         pp_string (buffer, "preferUninstrumented ");
1010       if (props & PR_EXCEPTIONBLOCK)
1011         pp_string (buffer, "exceptionBlock ");
1012       if (props & PR_HASELSE)
1013         pp_string (buffer, "hasElse ");
1014       if (props & PR_READONLY)
1015         pp_string (buffer, "readOnly ");
1016
1017       pp_right_bracket (buffer);
1018     }
1019 }
1020
1021
1022 /* Dump the switch statement GS.  BUFFER, SPC and FLAGS are as in
1023    pp_gimple_stmt_1.  */
1024
1025 static void
1026 dump_gimple_switch (pretty_printer *buffer, const gswitch *gs, int spc,
1027                     dump_flags_t flags)
1028 {
1029   unsigned int i;
1030
1031   GIMPLE_CHECK (gs, GIMPLE_SWITCH);
1032   if (flags & TDF_RAW)
1033     dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
1034                    gimple_switch_index (gs));
1035   else
1036     {
1037       pp_string (buffer, "switch (");
1038       dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
1039       if (flags & TDF_GIMPLE)
1040         pp_string (buffer, ") {");
1041       else
1042         pp_string (buffer, ") <");
1043     }
1044
1045   for (i = 0; i < gimple_switch_num_labels (gs); i++)
1046     {
1047       tree case_label = gimple_switch_label (gs, i);
1048       gcc_checking_assert (case_label != NULL_TREE);
1049       dump_generic_node (buffer, case_label, spc, flags, false);
1050       pp_space (buffer);
1051       tree label = CASE_LABEL (case_label);
1052       dump_generic_node (buffer, label, spc, flags, false);
1053
1054       if (cfun && cfun->cfg)
1055         {
1056           basic_block dest = label_to_block (cfun, label);
1057           if (dest)
1058             {
1059               edge label_edge = find_edge (gimple_bb (gs), dest);
1060               if (label_edge && !(flags & TDF_GIMPLE))
1061                 dump_edge_probability (buffer, label_edge);
1062             }
1063         }
1064
1065       if (i < gimple_switch_num_labels (gs) - 1)
1066         {
1067           if (flags & TDF_GIMPLE)
1068             pp_string (buffer, "; ");
1069           else
1070             pp_string (buffer, ", ");
1071         }
1072     }
1073   if (flags & TDF_GIMPLE)
1074     pp_string (buffer, "; }");
1075   else
1076     pp_greater (buffer);
1077 }
1078
1079
1080 /* Dump the gimple conditional GS.  BUFFER, SPC and FLAGS are as in
1081    pp_gimple_stmt_1.  */
1082
1083 static void
1084 dump_gimple_cond (pretty_printer *buffer, const gcond *gs, int spc,
1085                   dump_flags_t flags)
1086 {
1087   if (flags & TDF_RAW)
1088     dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
1089                      get_tree_code_name (gimple_cond_code (gs)),
1090                      gimple_cond_lhs (gs), gimple_cond_rhs (gs),
1091                      gimple_cond_true_label (gs), gimple_cond_false_label (gs));
1092   else
1093     {
1094       if (!(flags & TDF_RHS_ONLY))
1095         pp_string (buffer, "if (");
1096       dump_generic_node (buffer, gimple_cond_lhs (gs), spc,
1097                          flags | ((flags & TDF_GIMPLE) ? TDF_GIMPLE_VAL : TDF_NONE),
1098                          false);
1099       pp_space (buffer);
1100       pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
1101       pp_space (buffer);
1102       dump_generic_node (buffer, gimple_cond_rhs (gs), spc,
1103                          flags | ((flags & TDF_GIMPLE) ? TDF_GIMPLE_VAL : TDF_NONE),
1104                          false);
1105       if (!(flags & TDF_RHS_ONLY))
1106         {
1107           edge_iterator ei;
1108           edge e, true_edge = NULL, false_edge = NULL;
1109           basic_block bb = gimple_bb (gs);
1110
1111           if (bb)
1112             {
1113               FOR_EACH_EDGE (e, ei, bb->succs)
1114                 {
1115                   if (e->flags & EDGE_TRUE_VALUE)
1116                     true_edge = e;
1117                   else if (e->flags & EDGE_FALSE_VALUE)
1118                     false_edge = e;
1119                 }
1120             }
1121
1122           bool has_edge_info = true_edge != NULL && false_edge != NULL;
1123
1124           pp_right_paren (buffer);
1125
1126           if (gimple_cond_true_label (gs))
1127             {
1128               pp_string (buffer, " goto ");
1129               dump_generic_node (buffer, gimple_cond_true_label (gs),
1130                                  spc, flags, false);
1131               if (has_edge_info && !(flags & TDF_GIMPLE))
1132                 dump_edge_probability (buffer, true_edge);
1133               pp_semicolon (buffer);
1134             }
1135           if (gimple_cond_false_label (gs))
1136             {
1137               pp_string (buffer, " else goto ");
1138               dump_generic_node (buffer, gimple_cond_false_label (gs),
1139                                  spc, flags, false);
1140               if (has_edge_info && !(flags & TDF_GIMPLE))
1141                 dump_edge_probability (buffer, false_edge);
1142
1143               pp_semicolon (buffer);
1144             }
1145         }
1146     }
1147 }
1148
1149
1150 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
1151    spaces of indent.  FLAGS specifies details to show in the dump (see
1152    TDF_* in dumpfils.h).  */
1153
1154 static void
1155 dump_gimple_label (pretty_printer *buffer, const glabel *gs, int spc,
1156                    dump_flags_t flags)
1157 {
1158   tree label = gimple_label_label (gs);
1159   if (flags & TDF_RAW)
1160     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
1161   else
1162     {
1163       dump_generic_node (buffer, label, spc, flags, false);
1164       pp_colon (buffer);
1165     }
1166   if (flags & TDF_GIMPLE)
1167     return;
1168   if (DECL_NONLOCAL (label))
1169     pp_string (buffer, " [non-local]");
1170   if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
1171     pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
1172 }
1173
1174 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
1175    spaces of indent.  FLAGS specifies details to show in the dump (see
1176    TDF_* in dumpfile.h).  */
1177
1178 static void
1179 dump_gimple_goto (pretty_printer *buffer, const ggoto *gs, int spc,
1180                   dump_flags_t flags)
1181 {
1182   tree label = gimple_goto_dest (gs);
1183   if (flags & TDF_RAW)
1184     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
1185   else
1186     dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
1187 }
1188
1189
1190 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
1191    spaces of indent.  FLAGS specifies details to show in the dump (see
1192    TDF_* in dumpfile.h).  */
1193
1194 static void
1195 dump_gimple_bind (pretty_printer *buffer, const gbind *gs, int spc,
1196                   dump_flags_t flags)
1197 {
1198   if (flags & TDF_RAW)
1199     dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
1200   else
1201     pp_left_brace (buffer);
1202   if (!(flags & TDF_SLIM))
1203     {
1204       tree var;
1205
1206       for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
1207         {
1208           newline_and_indent (buffer, 2);
1209           print_declaration (buffer, var, spc, flags);
1210         }
1211       if (gimple_bind_vars (gs))
1212         pp_newline (buffer);
1213     }
1214   pp_newline (buffer);
1215   dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
1216   newline_and_indent (buffer, spc);
1217   if (flags & TDF_RAW)
1218     pp_greater (buffer);
1219   else
1220     pp_right_brace (buffer);
1221 }
1222
1223
1224 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
1225    indent.  FLAGS specifies details to show in the dump (see TDF_* in
1226    dumpfile.h).  */
1227
1228 static void
1229 dump_gimple_try (pretty_printer *buffer, const gtry *gs, int spc,
1230                  dump_flags_t flags)
1231 {
1232   if (flags & TDF_RAW)
1233     {
1234       const char *type;
1235       if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
1236         type = "GIMPLE_TRY_CATCH";
1237       else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
1238         type = "GIMPLE_TRY_FINALLY";
1239       else
1240         type = "UNKNOWN GIMPLE_TRY";
1241       dump_gimple_fmt (buffer, spc, flags,
1242                        "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
1243                        gimple_try_eval (gs), gimple_try_cleanup (gs));
1244     }
1245   else
1246     {
1247       pp_string (buffer, "try");
1248       newline_and_indent (buffer, spc + 2);
1249       pp_left_brace (buffer);
1250       pp_newline (buffer);
1251
1252       dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
1253       newline_and_indent (buffer, spc + 2);
1254       pp_right_brace (buffer);
1255
1256       gimple_seq seq = gimple_try_cleanup (gs);
1257
1258       if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
1259         {
1260           newline_and_indent (buffer, spc);
1261           pp_string (buffer, "catch");
1262           newline_and_indent (buffer, spc + 2);
1263           pp_left_brace (buffer);
1264         }
1265       else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
1266         {
1267           newline_and_indent (buffer, spc);
1268           pp_string (buffer, "finally");
1269           newline_and_indent (buffer, spc + 2);
1270           pp_left_brace (buffer);
1271
1272           if (seq && is_a <geh_else *> (gimple_seq_first_stmt (seq))
1273               && gimple_seq_nondebug_singleton_p (seq))
1274             {
1275               geh_else *stmt = as_a <geh_else *> (gimple_seq_first_stmt (seq));
1276               seq = gimple_eh_else_n_body (stmt);
1277               pp_newline (buffer);
1278               dump_gimple_seq (buffer, seq, spc + 4, flags);
1279               newline_and_indent (buffer, spc + 2);
1280               pp_right_brace (buffer);
1281               seq = gimple_eh_else_e_body (stmt);
1282               newline_and_indent (buffer, spc);
1283               pp_string (buffer, "else");
1284               newline_and_indent (buffer, spc + 2);
1285               pp_left_brace (buffer);
1286             }
1287         }
1288       else
1289         pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
1290
1291       pp_newline (buffer);
1292       dump_gimple_seq (buffer, seq, spc + 4, flags);
1293       newline_and_indent (buffer, spc + 2);
1294       pp_right_brace (buffer);
1295     }
1296 }
1297
1298
1299 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
1300    indent.  FLAGS specifies details to show in the dump (see TDF_* in
1301    dumpfile.h).  */
1302
1303 static void
1304 dump_gimple_catch (pretty_printer *buffer, const gcatch *gs, int spc,
1305                    dump_flags_t flags)
1306 {
1307   if (flags & TDF_RAW)
1308       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
1309                        gimple_catch_types (gs), gimple_catch_handler (gs));
1310   else
1311       dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
1312                        gimple_catch_types (gs), gimple_catch_handler (gs));
1313 }
1314
1315
1316 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
1317    indent.  FLAGS specifies details to show in the dump (see TDF_* in
1318    dumpfile.h).  */
1319
1320 static void
1321 dump_gimple_eh_filter (pretty_printer *buffer, const geh_filter *gs, int spc,
1322                        dump_flags_t flags)
1323 {
1324   if (flags & TDF_RAW)
1325     dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
1326                      gimple_eh_filter_types (gs),
1327                      gimple_eh_filter_failure (gs));
1328   else
1329     dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
1330                      gimple_eh_filter_types (gs),
1331                      gimple_eh_filter_failure (gs));
1332 }
1333
1334
1335 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple.  */
1336
1337 static void
1338 dump_gimple_eh_must_not_throw (pretty_printer *buffer,
1339                                const geh_mnt *gs, int spc, dump_flags_t flags)
1340 {
1341   if (flags & TDF_RAW)
1342     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1343                      gimple_eh_must_not_throw_fndecl (gs));
1344   else
1345     dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
1346                      gimple_eh_must_not_throw_fndecl (gs));
1347 }
1348
1349
1350 /* Dump a GIMPLE_EH_ELSE tuple on the pretty_printer BUFFER, SPC spaces of
1351    indent.  FLAGS specifies details to show in the dump (see TDF_* in
1352    dumpfile.h).  */
1353
1354 static void
1355 dump_gimple_eh_else (pretty_printer *buffer, const geh_else *gs, int spc,
1356                      dump_flags_t flags)
1357 {
1358   if (flags & TDF_RAW)
1359     dump_gimple_fmt (buffer, spc, flags,
1360                      "%G <%+N_BODY <%S>%nE_BODY <%S>%->", gs,
1361                      gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1362   else
1363     dump_gimple_fmt (buffer, spc, flags,
1364                     "<<<if_normal_exit>>>%+{%S}%-<<<else_eh_exit>>>%+{%S}",
1365                      gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1366 }
1367
1368
1369 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
1370    indent.  FLAGS specifies details to show in the dump (see TDF_* in
1371    dumpfile.h).  */
1372
1373 static void
1374 dump_gimple_resx (pretty_printer *buffer, const gresx *gs, int spc,
1375                   dump_flags_t flags)
1376 {
1377   if (flags & TDF_RAW)
1378     dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1379                      gimple_resx_region (gs));
1380   else
1381     dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
1382 }
1383
1384 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER.  */
1385
1386 static void
1387 dump_gimple_eh_dispatch (pretty_printer *buffer, const geh_dispatch *gs,
1388                          int spc, dump_flags_t flags)
1389 {
1390   if (flags & TDF_RAW)
1391     dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1392                      gimple_eh_dispatch_region (gs));
1393   else
1394     dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
1395                      gimple_eh_dispatch_region (gs));
1396 }
1397
1398 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
1399    of indent.  FLAGS specifies details to show in the dump (see TDF_*
1400    in dumpfile.h).  */
1401
1402 static void
1403 dump_gimple_debug (pretty_printer *buffer, const gdebug *gs, int spc,
1404                    dump_flags_t flags)
1405 {
1406   switch (gs->subcode)
1407     {
1408     case GIMPLE_DEBUG_BIND:
1409       if (flags & TDF_RAW)
1410         dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
1411                          gimple_debug_bind_get_var (gs),
1412                          gimple_debug_bind_get_value (gs));
1413       else
1414         dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
1415                          gimple_debug_bind_get_var (gs),
1416                          gimple_debug_bind_get_value (gs));
1417       break;
1418
1419     case GIMPLE_DEBUG_SOURCE_BIND:
1420       if (flags & TDF_RAW)
1421         dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1422                          gimple_debug_source_bind_get_var (gs),
1423                          gimple_debug_source_bind_get_value (gs));
1424       else
1425         dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1426                          gimple_debug_source_bind_get_var (gs),
1427                          gimple_debug_source_bind_get_value (gs));
1428       break;
1429
1430     case GIMPLE_DEBUG_BEGIN_STMT:
1431       if (flags & TDF_RAW)
1432         dump_gimple_fmt (buffer, spc, flags, "%G BEGIN_STMT", gs);
1433       else
1434         dump_gimple_fmt (buffer, spc, flags, "# DEBUG BEGIN_STMT");
1435       break;
1436
1437     case GIMPLE_DEBUG_INLINE_ENTRY:
1438       if (flags & TDF_RAW)
1439         dump_gimple_fmt (buffer, spc, flags, "%G INLINE_ENTRY %T", gs,
1440                          gimple_block (gs)
1441                          ? block_ultimate_origin (gimple_block (gs))
1442                          : NULL_TREE);
1443       else
1444         dump_gimple_fmt (buffer, spc, flags, "# DEBUG INLINE_ENTRY %T",
1445                          gimple_block (gs)
1446                          ? block_ultimate_origin (gimple_block (gs))
1447                          : NULL_TREE);
1448       break;
1449
1450     default:
1451       gcc_unreachable ();
1452     }
1453 }
1454
1455 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER.  */
1456 static void
1457 dump_gimple_omp_for (pretty_printer *buffer, const gomp_for *gs, int spc,
1458                      dump_flags_t flags)
1459 {
1460   size_t i;
1461
1462   if (flags & TDF_RAW)
1463     {
1464       const char *kind;
1465       switch (gimple_omp_for_kind (gs))
1466         {
1467         case GF_OMP_FOR_KIND_FOR:
1468           kind = "";
1469           break;
1470         case GF_OMP_FOR_KIND_DISTRIBUTE:
1471           kind = " distribute";
1472           break;
1473         case GF_OMP_FOR_KIND_TASKLOOP:
1474           kind = " taskloop";
1475           break;
1476         case GF_OMP_FOR_KIND_OACC_LOOP:
1477           kind = " oacc_loop";
1478           break;
1479         case GF_OMP_FOR_KIND_SIMD:
1480           kind = " simd";
1481           break;
1482         default:
1483           gcc_unreachable ();
1484         }
1485       dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1486                        kind, gimple_omp_body (gs));
1487       dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1488       dump_gimple_fmt (buffer, spc, flags, " >,");
1489       for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1490         dump_gimple_fmt (buffer, spc, flags,
1491                          "%+%T, %T, %T, %s, %T,%n",
1492                          gimple_omp_for_index (gs, i),
1493                          gimple_omp_for_initial (gs, i),
1494                          gimple_omp_for_final (gs, i),
1495                          get_tree_code_name (gimple_omp_for_cond (gs, i)),
1496                          gimple_omp_for_incr (gs, i));
1497       dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1498                        gimple_omp_for_pre_body (gs));
1499     }
1500   else
1501     {
1502       switch (gimple_omp_for_kind (gs))
1503         {
1504         case GF_OMP_FOR_KIND_FOR:
1505           pp_string (buffer, "#pragma omp for");
1506           break;
1507         case GF_OMP_FOR_KIND_DISTRIBUTE:
1508           pp_string (buffer, "#pragma omp distribute");
1509           break;
1510         case GF_OMP_FOR_KIND_TASKLOOP:
1511           pp_string (buffer, "#pragma omp taskloop");
1512           break;
1513         case GF_OMP_FOR_KIND_OACC_LOOP:
1514           pp_string (buffer, "#pragma acc loop");
1515           break;
1516         case GF_OMP_FOR_KIND_SIMD:
1517           pp_string (buffer, "#pragma omp simd");
1518           break;
1519         default:
1520           gcc_unreachable ();
1521         }
1522       dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1523       for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1524         {
1525           if (i)
1526             spc += 2;
1527           newline_and_indent (buffer, spc);
1528           pp_string (buffer, "for (");
1529           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1530                              flags, false);
1531           pp_string (buffer, " = ");
1532           tree init = gimple_omp_for_initial (gs, i);
1533           if (TREE_CODE (init) != TREE_VEC)
1534             dump_generic_node (buffer, init, spc, flags, false);
1535           else
1536             dump_omp_loop_non_rect_expr (buffer, init, spc, flags);
1537           pp_string (buffer, "; ");
1538
1539           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1540                              flags, false);
1541           pp_space (buffer);
1542           switch (gimple_omp_for_cond (gs, i))
1543             {
1544             case LT_EXPR:
1545               pp_less (buffer);
1546               break;
1547             case GT_EXPR:
1548               pp_greater (buffer);
1549               break;
1550             case LE_EXPR:
1551               pp_less_equal (buffer);
1552               break;
1553             case GE_EXPR:
1554               pp_greater_equal (buffer);
1555               break;
1556             case NE_EXPR:
1557               pp_string (buffer, "!=");
1558               break;
1559             default:
1560               gcc_unreachable ();
1561             }
1562           pp_space (buffer);
1563           tree cond = gimple_omp_for_final (gs, i);
1564           if (TREE_CODE (cond) != TREE_VEC)
1565             dump_generic_node (buffer, cond, spc, flags, false);
1566           else
1567             dump_omp_loop_non_rect_expr (buffer, cond, spc, flags);
1568           pp_string (buffer, "; ");
1569
1570           dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1571                              flags, false);
1572           pp_string (buffer, " = ");
1573           dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1574                              flags, false);
1575           pp_right_paren (buffer);
1576         }
1577
1578       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1579         {
1580           newline_and_indent (buffer, spc + 2);
1581           pp_left_brace (buffer);
1582           pp_newline (buffer);
1583           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1584           newline_and_indent (buffer, spc + 2);
1585           pp_right_brace (buffer);
1586         }
1587     }
1588 }
1589
1590 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER.  */
1591
1592 static void
1593 dump_gimple_omp_continue (pretty_printer *buffer, const gomp_continue *gs,
1594                           int spc, dump_flags_t flags)
1595 {
1596   if (flags & TDF_RAW)
1597     {
1598       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1599                        gimple_omp_continue_control_def (gs),
1600                        gimple_omp_continue_control_use (gs));
1601     }
1602   else
1603     {
1604       pp_string (buffer, "#pragma omp continue (");
1605       dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1606                          spc, flags, false);
1607       pp_comma (buffer);
1608       pp_space (buffer);
1609       dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1610                          spc, flags, false);
1611       pp_right_paren (buffer);
1612     }
1613 }
1614
1615 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER.  */
1616
1617 static void
1618 dump_gimple_omp_single (pretty_printer *buffer, const gomp_single *gs,
1619                         int spc, dump_flags_t flags)
1620 {
1621   if (flags & TDF_RAW)
1622     {
1623       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1624                        gimple_omp_body (gs));
1625       dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1626       dump_gimple_fmt (buffer, spc, flags, " >");
1627     }
1628   else
1629     {
1630       pp_string (buffer, "#pragma omp single");
1631       dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1632       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1633         {
1634           newline_and_indent (buffer, spc + 2);
1635           pp_left_brace (buffer);
1636           pp_newline (buffer);
1637           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1638           newline_and_indent (buffer, spc + 2);
1639           pp_right_brace (buffer);
1640         }
1641     }
1642 }
1643
1644 /* Dump a GIMPLE_OMP_TASKGROUP tuple on the pretty_printer BUFFER.  */
1645
1646 static void
1647 dump_gimple_omp_taskgroup (pretty_printer *buffer, const gimple *gs,
1648                            int spc, dump_flags_t flags)
1649 {
1650   if (flags & TDF_RAW)
1651     {
1652       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1653                        gimple_omp_body (gs));
1654       dump_omp_clauses (buffer, gimple_omp_taskgroup_clauses (gs), spc, flags);
1655       dump_gimple_fmt (buffer, spc, flags, " >");
1656     }
1657   else
1658     {
1659       pp_string (buffer, "#pragma omp taskgroup");
1660       dump_omp_clauses (buffer, gimple_omp_taskgroup_clauses (gs), spc, flags);
1661       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1662         {
1663           newline_and_indent (buffer, spc + 2);
1664           pp_left_brace (buffer);
1665           pp_newline (buffer);
1666           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1667           newline_and_indent (buffer, spc + 2);
1668           pp_right_brace (buffer);
1669         }
1670     }
1671 }
1672
1673 /* Dump a GIMPLE_OMP_MASKED tuple on the pretty_printer BUFFER.  */
1674
1675 static void
1676 dump_gimple_omp_masked (pretty_printer *buffer, const gimple *gs,
1677                         int spc, dump_flags_t flags)
1678 {
1679   if (flags & TDF_RAW)
1680     {
1681       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1682                        gimple_omp_body (gs));
1683       dump_omp_clauses (buffer, gimple_omp_masked_clauses (gs), spc, flags);
1684       dump_gimple_fmt (buffer, spc, flags, " >");
1685     }
1686   else
1687     {
1688       pp_string (buffer, "#pragma omp masked");
1689       dump_omp_clauses (buffer, gimple_omp_masked_clauses (gs), spc, flags);
1690       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1691         {
1692           newline_and_indent (buffer, spc + 2);
1693           pp_left_brace (buffer);
1694           pp_newline (buffer);
1695           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1696           newline_and_indent (buffer, spc + 2);
1697           pp_right_brace (buffer);
1698         }
1699     }
1700 }
1701
1702 /* Dump a GIMPLE_OMP_SCOPE tuple on the pretty_printer BUFFER.  */
1703
1704 static void
1705 dump_gimple_omp_scope (pretty_printer *buffer, const gimple *gs,
1706                        int spc, dump_flags_t 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_scope_clauses (gs), spc, flags);
1713       dump_gimple_fmt (buffer, spc, flags, " >");
1714     }
1715   else
1716     {
1717       pp_string (buffer, "#pragma omp scope");
1718       dump_omp_clauses (buffer, gimple_omp_scope_clauses (gs), spc, flags);
1719       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1720         {
1721           newline_and_indent (buffer, spc + 2);
1722           pp_left_brace (buffer);
1723           pp_newline (buffer);
1724           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1725           newline_and_indent (buffer, spc + 2);
1726           pp_right_brace (buffer);
1727         }
1728     }
1729 }
1730
1731 /* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer BUFFER.  */
1732
1733 static void
1734 dump_gimple_omp_target (pretty_printer *buffer, const gomp_target *gs,
1735                         int spc, dump_flags_t flags)
1736 {
1737   const char *kind;
1738   switch (gimple_omp_target_kind (gs))
1739     {
1740     case GF_OMP_TARGET_KIND_REGION:
1741       kind = "";
1742       break;
1743     case GF_OMP_TARGET_KIND_DATA:
1744       kind = " data";
1745       break;
1746     case GF_OMP_TARGET_KIND_UPDATE:
1747       kind = " update";
1748       break;
1749     case GF_OMP_TARGET_KIND_ENTER_DATA:
1750       kind = " enter data";
1751       break;
1752     case GF_OMP_TARGET_KIND_EXIT_DATA:
1753       kind = " exit data";
1754       break;
1755     case GF_OMP_TARGET_KIND_OACC_KERNELS:
1756       kind = " oacc_kernels";
1757       break;
1758     case GF_OMP_TARGET_KIND_OACC_PARALLEL:
1759       kind = " oacc_parallel";
1760       break;
1761     case GF_OMP_TARGET_KIND_OACC_SERIAL:
1762       kind = " oacc_serial";
1763       break;
1764     case GF_OMP_TARGET_KIND_OACC_DATA:
1765       kind = " oacc_data";
1766       break;
1767     case GF_OMP_TARGET_KIND_OACC_UPDATE:
1768       kind = " oacc_update";
1769       break;
1770     case GF_OMP_TARGET_KIND_OACC_ENTER_DATA:
1771       kind = " oacc_enter_data";
1772       break;
1773     case GF_OMP_TARGET_KIND_OACC_EXIT_DATA:
1774       kind = " oacc_exit_data";
1775       break;
1776     case GF_OMP_TARGET_KIND_OACC_DECLARE:
1777       kind = " oacc_declare";
1778       break;
1779     case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
1780       kind = " oacc_host_data";
1781       break;
1782     case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_PARALLELIZED:
1783       kind = " oacc_parallel_kernels_parallelized";
1784       break;
1785     case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_GANG_SINGLE:
1786       kind = " oacc_parallel_kernels_gang_single";
1787       break;
1788     case GF_OMP_TARGET_KIND_OACC_DATA_KERNELS:
1789       kind = " oacc_data_kernels";
1790       break;
1791     default:
1792       gcc_unreachable ();
1793     }
1794   if (flags & TDF_RAW)
1795     {
1796       dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1797                        kind, gimple_omp_body (gs));
1798       dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1799       dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1800                        gimple_omp_target_child_fn (gs),
1801                        gimple_omp_target_data_arg (gs));
1802     }
1803   else
1804     {
1805       pp_string (buffer, "#pragma omp target");
1806       pp_string (buffer, kind);
1807       dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1808       if (gimple_omp_target_child_fn (gs))
1809         {
1810           pp_string (buffer, " [child fn: ");
1811           dump_generic_node (buffer, gimple_omp_target_child_fn (gs),
1812                              spc, flags, false);
1813           pp_string (buffer, " (");
1814           if (gimple_omp_target_data_arg (gs))
1815             dump_generic_node (buffer, gimple_omp_target_data_arg (gs),
1816                                spc, flags, false);
1817           else
1818             pp_string (buffer, "???");
1819           pp_string (buffer, ")]");
1820         }
1821       gimple_seq body = gimple_omp_body (gs);
1822       if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1823         {
1824           newline_and_indent (buffer, spc + 2);
1825           pp_left_brace (buffer);
1826           pp_newline (buffer);
1827           dump_gimple_seq (buffer, body, spc + 4, flags);
1828           newline_and_indent (buffer, spc + 2);
1829           pp_right_brace (buffer);
1830         }
1831       else if (body)
1832         {
1833           pp_newline (buffer);
1834           dump_gimple_seq (buffer, body, spc + 2, flags);
1835         }
1836     }
1837 }
1838
1839 /* Dump a GIMPLE_OMP_TEAMS tuple on the pretty_printer BUFFER.  */
1840
1841 static void
1842 dump_gimple_omp_teams (pretty_printer *buffer, const gomp_teams *gs, int spc,
1843                        dump_flags_t flags)
1844 {
1845   if (flags & TDF_RAW)
1846     {
1847       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1848                        gimple_omp_body (gs));
1849       dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1850       dump_gimple_fmt (buffer, spc, flags, " >");
1851     }
1852   else
1853     {
1854       pp_string (buffer, "#pragma omp teams");
1855       dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1856       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1857         {
1858           newline_and_indent (buffer, spc + 2);
1859           pp_character (buffer, '{');
1860           pp_newline (buffer);
1861           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1862           newline_and_indent (buffer, spc + 2);
1863           pp_character (buffer, '}');
1864         }
1865     }
1866 }
1867
1868 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER.  */
1869
1870 static void
1871 dump_gimple_omp_sections (pretty_printer *buffer, const gomp_sections *gs,
1872                           int spc, dump_flags_t flags)
1873 {
1874   if (flags & TDF_RAW)
1875     {
1876       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1877                        gimple_omp_body (gs));
1878       dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1879       dump_gimple_fmt (buffer, spc, flags, " >");
1880     }
1881   else
1882     {
1883       pp_string (buffer, "#pragma omp sections");
1884       if (gimple_omp_sections_control (gs))
1885         {
1886           pp_string (buffer, " <");
1887           dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1888                              flags, false);
1889           pp_greater (buffer);
1890         }
1891       dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1892       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1893         {
1894           newline_and_indent (buffer, spc + 2);
1895           pp_left_brace (buffer);
1896           pp_newline (buffer);
1897           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1898           newline_and_indent (buffer, spc + 2);
1899           pp_right_brace (buffer);
1900         }
1901     }
1902 }
1903
1904 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the
1905    pretty_printer BUFFER.  */
1906
1907 static void
1908 dump_gimple_omp_block (pretty_printer *buffer, const gimple *gs, int spc,
1909                        dump_flags_t flags)
1910 {
1911   if (flags & TDF_RAW)
1912     dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1913                      gimple_omp_body (gs));
1914   else
1915     {
1916       switch (gimple_code (gs))
1917         {
1918         case GIMPLE_OMP_MASTER:
1919           pp_string (buffer, "#pragma omp master");
1920           break;
1921         case GIMPLE_OMP_SECTION:
1922           pp_string (buffer, "#pragma omp section");
1923           break;
1924         default:
1925           gcc_unreachable ();
1926         }
1927       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1928         {
1929           newline_and_indent (buffer, spc + 2);
1930           pp_left_brace (buffer);
1931           pp_newline (buffer);
1932           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1933           newline_and_indent (buffer, spc + 2);
1934           pp_right_brace (buffer);
1935         }
1936     }
1937 }
1938
1939 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER.  */
1940
1941 static void
1942 dump_gimple_omp_critical (pretty_printer *buffer, const gomp_critical *gs,
1943                           int spc, dump_flags_t flags)
1944 {
1945   if (flags & TDF_RAW)
1946     dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1947                      gimple_omp_body (gs));
1948   else
1949     {
1950       pp_string (buffer, "#pragma omp critical");
1951       if (gimple_omp_critical_name (gs))
1952         {
1953           pp_string (buffer, " (");
1954           dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1955                              flags, false);
1956           pp_right_paren (buffer);
1957         }
1958       dump_omp_clauses (buffer, gimple_omp_critical_clauses (gs), spc, flags);
1959       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1960         {
1961           newline_and_indent (buffer, spc + 2);
1962           pp_left_brace (buffer);
1963           pp_newline (buffer);
1964           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1965           newline_and_indent (buffer, spc + 2);
1966           pp_right_brace (buffer);
1967         }
1968     }
1969 }
1970
1971 /* Dump a GIMPLE_OMP_ORDERED tuple on the pretty_printer BUFFER.  */
1972
1973 static void
1974 dump_gimple_omp_ordered (pretty_printer *buffer, const gomp_ordered *gs,
1975                          int spc, dump_flags_t flags)
1976 {
1977   if (flags & TDF_RAW)
1978     dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1979                      gimple_omp_body (gs));
1980   else
1981     {
1982       pp_string (buffer, "#pragma omp ordered");
1983       dump_omp_clauses (buffer, gimple_omp_ordered_clauses (gs), spc, flags);
1984       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1985         {
1986           newline_and_indent (buffer, spc + 2);
1987           pp_left_brace (buffer);
1988           pp_newline (buffer);
1989           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1990           newline_and_indent (buffer, spc + 2);
1991           pp_right_brace (buffer);
1992         }
1993     }
1994 }
1995
1996 /* Dump a GIMPLE_OMP_SCAN tuple on the pretty_printer BUFFER.  */
1997
1998 static void
1999 dump_gimple_omp_scan (pretty_printer *buffer, const gomp_scan *gs,
2000                       int spc, dump_flags_t flags)
2001 {
2002   if (flags & TDF_RAW)
2003     dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
2004                      gimple_omp_body (gs));
2005   else
2006     {
2007       if (gimple_omp_scan_clauses (gs))
2008         {
2009           pp_string (buffer, "#pragma omp scan");
2010           dump_omp_clauses (buffer, gimple_omp_scan_clauses (gs), spc, flags);
2011         }
2012       if (!gimple_seq_empty_p (gimple_omp_body (gs)))
2013         {
2014           newline_and_indent (buffer, spc + 2);
2015           pp_left_brace (buffer);
2016           pp_newline (buffer);
2017           dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
2018           newline_and_indent (buffer, spc + 2);
2019           pp_right_brace (buffer);
2020         }
2021     }
2022 }
2023
2024 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER.  */
2025
2026 static void
2027 dump_gimple_omp_return (pretty_printer *buffer, const gimple *gs, int spc,
2028                         dump_flags_t flags)
2029 {
2030   if (flags & TDF_RAW)
2031     {
2032       dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d", gs,
2033                        (int) gimple_omp_return_nowait_p (gs));
2034       if (gimple_omp_return_lhs (gs))
2035         dump_gimple_fmt (buffer, spc, flags, ", lhs=%T>",
2036                          gimple_omp_return_lhs (gs));
2037       else
2038         dump_gimple_fmt (buffer, spc, flags, ">");
2039     }
2040   else
2041     {
2042       pp_string (buffer, "#pragma omp return");
2043       if (gimple_omp_return_nowait_p (gs))
2044         pp_string (buffer, "(nowait)");
2045       if (gimple_omp_return_lhs (gs))
2046         {
2047           pp_string (buffer, " (set ");
2048           dump_generic_node (buffer, gimple_omp_return_lhs (gs),
2049                              spc, flags, false);
2050           pp_character (buffer, ')');
2051         }
2052     }
2053 }
2054
2055 /* Dump a GIMPLE_TRANSACTION tuple on the pretty_printer BUFFER.  */
2056
2057 static void
2058 dump_gimple_transaction (pretty_printer *buffer, const gtransaction *gs,
2059                          int spc, dump_flags_t flags)
2060 {
2061   unsigned subcode = gimple_transaction_subcode (gs);
2062
2063   if (flags & TDF_RAW)
2064     {
2065       dump_gimple_fmt (buffer, spc, flags,
2066                        "%G [SUBCODE=%x,NORM=%T,UNINST=%T,OVER=%T] "
2067                        "<%+BODY <%S> >",
2068                        gs, subcode, gimple_transaction_label_norm (gs),
2069                        gimple_transaction_label_uninst (gs),
2070                        gimple_transaction_label_over (gs),
2071                        gimple_transaction_body (gs));
2072     }
2073   else
2074     {
2075       if (subcode & GTMA_IS_OUTER)
2076         pp_string (buffer, "__transaction_atomic [[outer]]");
2077       else if (subcode & GTMA_IS_RELAXED)
2078         pp_string (buffer, "__transaction_relaxed");
2079       else
2080         pp_string (buffer, "__transaction_atomic");
2081       subcode &= ~GTMA_DECLARATION_MASK;
2082
2083       if (gimple_transaction_body (gs))
2084         {
2085           newline_and_indent (buffer, spc + 2);
2086           pp_left_brace (buffer);
2087           pp_newline (buffer);
2088           dump_gimple_seq (buffer, gimple_transaction_body (gs),
2089                            spc + 4, flags);
2090           newline_and_indent (buffer, spc + 2);
2091           pp_right_brace (buffer);
2092         }
2093       else
2094         {
2095           pp_string (buffer, "  //");
2096           if (gimple_transaction_label_norm (gs))
2097             {
2098               pp_string (buffer, " NORM=");
2099               dump_generic_node (buffer, gimple_transaction_label_norm (gs),
2100                                  spc, flags, false);
2101             }
2102           if (gimple_transaction_label_uninst (gs))
2103             {
2104               pp_string (buffer, " UNINST=");
2105               dump_generic_node (buffer, gimple_transaction_label_uninst (gs),
2106                                  spc, flags, false);
2107             }
2108           if (gimple_transaction_label_over (gs))
2109             {
2110               pp_string (buffer, " OVER=");
2111               dump_generic_node (buffer, gimple_transaction_label_over (gs),
2112                                  spc, flags, false);
2113             }
2114           if (subcode)
2115             {
2116               pp_string (buffer, " SUBCODE=[ ");
2117               if (subcode & GTMA_HAVE_ABORT)
2118                 {
2119                   pp_string (buffer, "GTMA_HAVE_ABORT ");
2120                   subcode &= ~GTMA_HAVE_ABORT;
2121                 }
2122               if (subcode & GTMA_HAVE_LOAD)
2123                 {
2124                   pp_string (buffer, "GTMA_HAVE_LOAD ");
2125                   subcode &= ~GTMA_HAVE_LOAD;
2126                 }
2127               if (subcode & GTMA_HAVE_STORE)
2128                 {
2129                   pp_string (buffer, "GTMA_HAVE_STORE ");
2130                   subcode &= ~GTMA_HAVE_STORE;
2131                 }
2132               if (subcode & GTMA_MAY_ENTER_IRREVOCABLE)
2133                 {
2134                   pp_string (buffer, "GTMA_MAY_ENTER_IRREVOCABLE ");
2135                   subcode &= ~GTMA_MAY_ENTER_IRREVOCABLE;
2136                 }
2137               if (subcode & GTMA_DOES_GO_IRREVOCABLE)
2138                 {
2139                   pp_string (buffer, "GTMA_DOES_GO_IRREVOCABLE ");
2140                   subcode &= ~GTMA_DOES_GO_IRREVOCABLE;
2141                 }
2142               if (subcode & GTMA_HAS_NO_INSTRUMENTATION)
2143                 {
2144                   pp_string (buffer, "GTMA_HAS_NO_INSTRUMENTATION ");
2145                   subcode &= ~GTMA_HAS_NO_INSTRUMENTATION;
2146                 }
2147               if (subcode)
2148                 pp_printf (buffer, "0x%x ", subcode);
2149               pp_right_bracket (buffer);
2150             }
2151         }
2152     }
2153 }
2154
2155 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
2156    indent.  FLAGS specifies details to show in the dump (see TDF_* in
2157    dumpfile.h).  */
2158
2159 static void
2160 dump_gimple_asm (pretty_printer *buffer, const gasm *gs, int spc,
2161                  dump_flags_t flags)
2162 {
2163   unsigned int i, n, f, fields;
2164
2165   if (flags & TDF_RAW)
2166     {
2167       dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
2168                        gimple_asm_string (gs));
2169
2170       n = gimple_asm_noutputs (gs);
2171       if (n)
2172         {
2173           newline_and_indent (buffer, spc + 2);
2174           pp_string (buffer, "OUTPUT: ");
2175           for (i = 0; i < n; i++)
2176             {
2177               dump_generic_node (buffer, gimple_asm_output_op (gs, i),
2178                                  spc, flags, false);
2179               if (i < n - 1)
2180                 pp_string (buffer, ", ");
2181             }
2182         }
2183
2184       n = gimple_asm_ninputs (gs);
2185       if (n)
2186         {
2187           newline_and_indent (buffer, spc + 2);
2188           pp_string (buffer, "INPUT: ");
2189           for (i = 0; i < n; i++)
2190             {
2191               dump_generic_node (buffer, gimple_asm_input_op (gs, i),
2192                                  spc, flags, false);
2193               if (i < n - 1)
2194                 pp_string (buffer, ", ");
2195             }
2196         }
2197
2198       n = gimple_asm_nclobbers (gs);
2199       if (n)
2200         {
2201           newline_and_indent (buffer, spc + 2);
2202           pp_string (buffer, "CLOBBER: ");
2203           for (i = 0; i < n; i++)
2204             {
2205               dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
2206                                  spc, flags, false);
2207               if (i < n - 1)
2208                 pp_string (buffer, ", ");
2209             }
2210         }
2211
2212       n = gimple_asm_nlabels (gs);
2213       if (n)
2214         {
2215           newline_and_indent (buffer, spc + 2);
2216           pp_string (buffer, "LABEL: ");
2217           for (i = 0; i < n; i++)
2218             {
2219               dump_generic_node (buffer, gimple_asm_label_op (gs, i),
2220                                  spc, flags, false);
2221               if (i < n - 1)
2222                 pp_string (buffer, ", ");
2223             }
2224         }
2225
2226       newline_and_indent (buffer, spc);
2227       pp_greater (buffer);
2228     }
2229   else
2230     {
2231       pp_string (buffer, "__asm__");
2232       if (gimple_asm_volatile_p (gs))
2233         pp_string (buffer, " __volatile__");
2234       if (gimple_asm_inline_p (gs))
2235         pp_string (buffer, " __inline__");
2236       if (gimple_asm_nlabels (gs))
2237         pp_string (buffer, " goto");
2238       pp_string (buffer, "(\"");
2239       pp_string (buffer, gimple_asm_string (gs));
2240       pp_string (buffer, "\"");
2241
2242       if (gimple_asm_nlabels (gs))
2243         fields = 4;
2244       else if (gimple_asm_nclobbers (gs))
2245         fields = 3;
2246       else if (gimple_asm_ninputs (gs))
2247         fields = 2;
2248       else if (gimple_asm_noutputs (gs))
2249         fields = 1;
2250       else
2251         fields = 0;
2252
2253       for (f = 0; f < fields; ++f)
2254         {
2255           pp_string (buffer, " : ");
2256
2257           switch (f)
2258             {
2259             case 0:
2260               n = gimple_asm_noutputs (gs);
2261               for (i = 0; i < n; i++)
2262                 {
2263                   dump_generic_node (buffer, gimple_asm_output_op (gs, i),
2264                                      spc, flags, false);
2265                   if (i < n - 1)
2266                     pp_string (buffer, ", ");
2267                 }
2268               break;
2269
2270             case 1:
2271               n = gimple_asm_ninputs (gs);
2272               for (i = 0; i < n; i++)
2273                 {
2274                   dump_generic_node (buffer, gimple_asm_input_op (gs, i),
2275                                      spc, flags, false);
2276                   if (i < n - 1)
2277                     pp_string (buffer, ", ");
2278                 }
2279               break;
2280
2281             case 2:
2282               n = gimple_asm_nclobbers (gs);
2283               for (i = 0; i < n; i++)
2284                 {
2285                   dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
2286                                      spc, flags, false);
2287                   if (i < n - 1)
2288                     pp_string (buffer, ", ");
2289                 }
2290               break;
2291
2292             case 3:
2293               n = gimple_asm_nlabels (gs);
2294               for (i = 0; i < n; i++)
2295                 {
2296                   dump_generic_node (buffer, gimple_asm_label_op (gs, i),
2297                                      spc, flags, false);
2298                   if (i < n - 1)
2299                     pp_string (buffer, ", ");
2300                 }
2301               break;
2302
2303             default:
2304               gcc_unreachable ();
2305             }
2306         }
2307
2308       pp_string (buffer, ");");
2309     }
2310 }
2311
2312 /* Dump ptr_info and range_info for NODE on pretty_printer BUFFER with
2313    SPC spaces of indent.  */
2314
2315 static void
2316 dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
2317 {
2318   if (TREE_CODE (node) != SSA_NAME)
2319     return;
2320
2321   if (POINTER_TYPE_P (TREE_TYPE (node))
2322       && SSA_NAME_PTR_INFO (node))
2323     {
2324       unsigned int align, misalign;
2325       struct ptr_info_def *pi = SSA_NAME_PTR_INFO (node);
2326       pp_string (buffer, "# PT = ");
2327       pp_points_to_solution (buffer, &pi->pt);
2328       newline_and_indent (buffer, spc);
2329       if (get_ptr_info_alignment (pi, &align, &misalign))
2330         {
2331           pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u", align, misalign);
2332           newline_and_indent (buffer, spc);
2333         }
2334     }
2335
2336   if (!POINTER_TYPE_P (TREE_TYPE (node))
2337       && SSA_NAME_RANGE_INFO (node))
2338     {
2339       Value_Range r (TREE_TYPE (node));
2340       get_global_range_query ()->range_of_expr (r, node);
2341       pp_string (buffer, "# RANGE ");
2342       pp_vrange (buffer, &r);
2343       newline_and_indent (buffer, spc);
2344     }
2345 }
2346
2347 /* As dump_ssaname_info, but dump to FILE.  */
2348
2349 void
2350 dump_ssaname_info_to_file (FILE *file, tree node, int spc)
2351 {
2352   pretty_printer buffer;
2353   pp_needs_newline (&buffer) = true;
2354   buffer.buffer->stream = file;
2355   dump_ssaname_info (&buffer, node, spc);
2356   pp_flush (&buffer);
2357 }
2358
2359 /* Dump a PHI node PHI.  BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
2360    The caller is responsible for calling pp_flush on BUFFER to finalize
2361    pretty printer.  If COMMENT is true, print this after #.  */
2362
2363 static void
2364 dump_gimple_phi (pretty_printer *buffer, const gphi *phi, int spc, bool comment,
2365                  dump_flags_t flags)
2366 {
2367   size_t i;
2368   tree lhs = gimple_phi_result (phi);
2369
2370   if (flags & TDF_ALIAS)
2371     dump_ssaname_info (buffer, lhs, spc);
2372
2373   if (comment)
2374     pp_string (buffer, "# ");
2375
2376   if (flags & TDF_RAW)
2377     dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
2378                      gimple_phi_result (phi));
2379   else
2380     {
2381       dump_generic_node (buffer, lhs, spc, flags, false);
2382       if (flags & TDF_GIMPLE)
2383         pp_string (buffer, " = __PHI (");
2384       else
2385         pp_string (buffer, " = PHI <");
2386     }
2387   for (i = 0; i < gimple_phi_num_args (phi); i++)
2388     {
2389       if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
2390         dump_location (buffer, gimple_phi_arg_location (phi, i));
2391       basic_block src = gimple_phi_arg_edge (phi, i)->src;
2392       if (flags & TDF_GIMPLE)
2393         {
2394           pp_string (buffer, "__BB");
2395           pp_decimal_int (buffer, src->index);
2396           pp_string (buffer, ": ");
2397         }
2398       dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
2399                          false);
2400       if (! (flags & TDF_GIMPLE))
2401         {
2402           pp_left_paren (buffer);
2403           pp_decimal_int (buffer, src->index);
2404           pp_right_paren (buffer);
2405         }
2406       if (i < gimple_phi_num_args (phi) - 1)
2407         pp_string (buffer, ", ");
2408     }
2409   if (flags & TDF_GIMPLE)
2410     pp_string (buffer, ");");
2411   else
2412     pp_greater (buffer);
2413 }
2414
2415
2416 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
2417    of indent.  FLAGS specifies details to show in the dump (see TDF_* in
2418    dumpfile.h).  */
2419
2420 static void
2421 dump_gimple_omp_parallel (pretty_printer *buffer, const gomp_parallel *gs,
2422                           int spc, dump_flags_t flags)
2423 {
2424   if (flags & TDF_RAW)
2425     {
2426       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2427                        gimple_omp_body (gs));
2428       dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
2429       dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
2430                        gimple_omp_parallel_child_fn (gs),
2431                        gimple_omp_parallel_data_arg (gs));
2432     }
2433   else
2434     {
2435       gimple_seq body;
2436       pp_string (buffer, "#pragma omp parallel");
2437       dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
2438       if (gimple_omp_parallel_child_fn (gs))
2439         {
2440           pp_string (buffer, " [child fn: ");
2441           dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
2442                              spc, flags, false);
2443           pp_string (buffer, " (");
2444           if (gimple_omp_parallel_data_arg (gs))
2445             dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
2446                                spc, flags, false);
2447           else
2448             pp_string (buffer, "???");
2449           pp_string (buffer, ")]");
2450         }
2451       body = gimple_omp_body (gs);
2452       if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2453         {
2454           newline_and_indent (buffer, spc + 2);
2455           pp_left_brace (buffer);
2456           pp_newline (buffer);
2457           dump_gimple_seq (buffer, body, spc + 4, flags);
2458           newline_and_indent (buffer, spc + 2);
2459           pp_right_brace (buffer);
2460         }
2461       else if (body)
2462         {
2463           pp_newline (buffer);
2464           dump_gimple_seq (buffer, body, spc + 2, flags);
2465         }
2466     }
2467 }
2468
2469
2470 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
2471    of indent.  FLAGS specifies details to show in the dump (see TDF_* in
2472    dumpfile.h).  */
2473
2474 static void
2475 dump_gimple_omp_task (pretty_printer *buffer, const gomp_task *gs, int spc,
2476                       dump_flags_t flags)
2477 {
2478   if (flags & TDF_RAW)
2479     {
2480       dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2481                        gimple_omp_body (gs));
2482       dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2483       dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
2484                        gimple_omp_task_child_fn (gs),
2485                        gimple_omp_task_data_arg (gs),
2486                        gimple_omp_task_copy_fn (gs),
2487                        gimple_omp_task_arg_size (gs),
2488                        gimple_omp_task_arg_size (gs));
2489     }
2490   else
2491     {
2492       gimple_seq body;
2493       if (gimple_omp_task_taskloop_p (gs))
2494         pp_string (buffer, "#pragma omp taskloop");
2495       else if (gimple_omp_task_taskwait_p (gs))
2496         pp_string (buffer, "#pragma omp taskwait");
2497       else
2498         pp_string (buffer, "#pragma omp task");
2499       dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2500       if (gimple_omp_task_child_fn (gs))
2501         {
2502           pp_string (buffer, " [child fn: ");
2503           dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
2504                              spc, flags, false);
2505           pp_string (buffer, " (");
2506           if (gimple_omp_task_data_arg (gs))
2507             dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
2508                                spc, flags, false);
2509           else
2510             pp_string (buffer, "???");
2511           pp_string (buffer, ")]");
2512         }
2513       body = gimple_omp_body (gs);
2514       if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2515         {
2516           newline_and_indent (buffer, spc + 2);
2517           pp_left_brace (buffer);
2518           pp_newline (buffer);
2519           dump_gimple_seq (buffer, body, spc + 4, flags);
2520           newline_and_indent (buffer, spc + 2);
2521           pp_right_brace (buffer);
2522         }
2523       else if (body)
2524         {
2525           pp_newline (buffer);
2526           dump_gimple_seq (buffer, body, spc + 2, flags);
2527         }
2528     }
2529 }
2530
2531
2532 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
2533    spaces of indent.  FLAGS specifies details to show in the dump (see TDF_*
2534    in dumpfile.h).  */
2535
2536 static void
2537 dump_gimple_omp_atomic_load (pretty_printer *buffer, const gomp_atomic_load *gs,
2538                              int spc, dump_flags_t flags)
2539 {
2540   if (flags & TDF_RAW)
2541     {
2542       dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
2543                        gimple_omp_atomic_load_lhs (gs),
2544                        gimple_omp_atomic_load_rhs (gs));
2545     }
2546   else
2547     {
2548       pp_string (buffer, "#pragma omp atomic_load");
2549       dump_omp_atomic_memory_order (buffer,
2550                                     gimple_omp_atomic_memory_order (gs));
2551       if (gimple_omp_atomic_need_value_p (gs))
2552         pp_string (buffer, " [needed]");
2553       if (gimple_omp_atomic_weak_p (gs))
2554         pp_string (buffer, " [weak]");
2555       newline_and_indent (buffer, spc + 2);
2556       dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
2557                          spc, flags, false);
2558       pp_space (buffer);
2559       pp_equal (buffer);
2560       pp_space (buffer);
2561       pp_star (buffer);
2562       dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
2563                          spc, flags, false);
2564     }
2565 }
2566
2567 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
2568    spaces of indent.  FLAGS specifies details to show in the dump (see TDF_*
2569    in dumpfile.h).  */
2570
2571 static void
2572 dump_gimple_omp_atomic_store (pretty_printer *buffer,
2573                               const gomp_atomic_store *gs, int spc,
2574                               dump_flags_t flags)
2575 {
2576   if (flags & TDF_RAW)
2577     {
2578       dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
2579                        gimple_omp_atomic_store_val (gs));
2580     }
2581   else
2582     {
2583       pp_string (buffer, "#pragma omp atomic_store");
2584       dump_omp_atomic_memory_order (buffer,
2585                                     gimple_omp_atomic_memory_order (gs));
2586       pp_space (buffer);
2587       if (gimple_omp_atomic_need_value_p (gs))
2588         pp_string (buffer, "[needed] ");
2589       if (gimple_omp_atomic_weak_p (gs))
2590         pp_string (buffer, "[weak] ");
2591       pp_left_paren (buffer);
2592       dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
2593                          spc, flags, false);
2594       pp_right_paren (buffer);
2595     }
2596 }
2597
2598
2599 /* Dump all the memory operands for statement GS.  BUFFER, SPC and
2600    FLAGS are as in pp_gimple_stmt_1.  */
2601
2602 static void
2603 dump_gimple_mem_ops (pretty_printer *buffer, const gimple *gs, int spc,
2604                      dump_flags_t flags)
2605 {
2606   tree vdef = gimple_vdef (gs);
2607   tree vuse = gimple_vuse (gs);
2608
2609   if (vdef != NULL_TREE)
2610     {
2611       pp_string (buffer, "# ");
2612       dump_generic_node (buffer, vdef, spc + 2, flags, false);
2613       pp_string (buffer, " = VDEF <");
2614       dump_generic_node (buffer, vuse, spc + 2, flags, false);
2615       pp_greater (buffer);
2616       newline_and_indent (buffer, spc);
2617     }
2618   else if (vuse != NULL_TREE)
2619     {
2620       pp_string (buffer, "# VUSE <");
2621       dump_generic_node (buffer, vuse, spc + 2, flags, false);
2622       pp_greater (buffer);
2623       newline_and_indent (buffer, spc);
2624     }
2625 }
2626
2627
2628 /* Print the gimple statement GS on the pretty printer BUFFER, SPC
2629    spaces of indent.  FLAGS specifies details to show in the dump (see
2630    TDF_* in dumpfile.h).  The caller is responsible for calling
2631    pp_flush on BUFFER to finalize the pretty printer.  */
2632
2633 void
2634 pp_gimple_stmt_1 (pretty_printer *buffer, const gimple *gs, int spc,
2635                   dump_flags_t flags)
2636 {
2637   if (!gs)
2638     return;
2639
2640   if (flags & TDF_STMTADDR)
2641     pp_printf (buffer, "<&%p> ", (const void *) gs);
2642
2643   if ((flags & TDF_LINENO) && gimple_has_location (gs))
2644     dump_location (buffer, gimple_location (gs));
2645
2646   if (flags & TDF_EH)
2647     {
2648       int lp_nr = lookup_stmt_eh_lp (gs);
2649       if (lp_nr > 0)
2650         pp_printf (buffer, "[LP %d] ", lp_nr);
2651       else if (lp_nr < 0)
2652         pp_printf (buffer, "[MNT %d] ", -lp_nr);
2653     }
2654
2655   if ((flags & (TDF_VOPS|TDF_MEMSYMS))
2656       && gimple_has_mem_ops (gs))
2657     dump_gimple_mem_ops (buffer, gs, spc, flags);
2658
2659   if (gimple_has_lhs (gs)
2660       && (flags & TDF_ALIAS))
2661     dump_ssaname_info (buffer, gimple_get_lhs (gs), spc);
2662
2663   switch (gimple_code (gs))
2664     {
2665     case GIMPLE_ASM:
2666       dump_gimple_asm (buffer, as_a <const gasm *> (gs), spc, flags);
2667       break;
2668
2669     case GIMPLE_ASSIGN:
2670       dump_gimple_assign (buffer, as_a <const gassign *> (gs), spc, flags);
2671       break;
2672
2673     case GIMPLE_BIND:
2674       dump_gimple_bind (buffer, as_a <const gbind *> (gs), spc, flags);
2675       break;
2676
2677     case GIMPLE_CALL:
2678       dump_gimple_call (buffer, as_a <const gcall *> (gs), spc, flags);
2679       break;
2680
2681     case GIMPLE_COND:
2682       dump_gimple_cond (buffer, as_a <const gcond *> (gs), spc, flags);
2683       break;
2684
2685     case GIMPLE_LABEL:
2686       dump_gimple_label (buffer, as_a <const glabel *> (gs), spc, flags);
2687       break;
2688
2689     case GIMPLE_GOTO:
2690       dump_gimple_goto (buffer, as_a <const ggoto *> (gs), spc, flags);
2691       break;
2692
2693     case GIMPLE_NOP:
2694       pp_string (buffer, "GIMPLE_NOP");
2695       break;
2696
2697     case GIMPLE_RETURN:
2698       dump_gimple_return (buffer, as_a <const greturn *> (gs), spc, flags);
2699       break;
2700
2701     case GIMPLE_SWITCH:
2702       dump_gimple_switch (buffer, as_a <const gswitch *> (gs), spc, flags);
2703       break;
2704
2705     case GIMPLE_TRY:
2706       dump_gimple_try (buffer, as_a <const gtry *> (gs), spc, flags);
2707       break;
2708
2709     case GIMPLE_PHI:
2710       dump_gimple_phi (buffer, as_a <const gphi *> (gs), spc, false, flags);
2711       break;
2712
2713     case GIMPLE_OMP_PARALLEL:
2714       dump_gimple_omp_parallel (buffer, as_a <const gomp_parallel *> (gs), spc,
2715                                 flags);
2716       break;
2717
2718     case GIMPLE_OMP_TASK:
2719       dump_gimple_omp_task (buffer, as_a <const gomp_task *> (gs), spc, flags);
2720       break;
2721
2722     case GIMPLE_OMP_ATOMIC_LOAD:
2723       dump_gimple_omp_atomic_load (buffer, as_a <const gomp_atomic_load *> (gs),
2724                                    spc, flags);
2725       break;
2726
2727     case GIMPLE_OMP_ATOMIC_STORE:
2728       dump_gimple_omp_atomic_store (buffer,
2729                                     as_a <const gomp_atomic_store *> (gs),
2730                                     spc, flags);
2731       break;
2732
2733     case GIMPLE_OMP_FOR:
2734       dump_gimple_omp_for (buffer, as_a <const gomp_for *> (gs), spc, flags);
2735       break;
2736
2737     case GIMPLE_OMP_CONTINUE:
2738       dump_gimple_omp_continue (buffer, as_a <const gomp_continue *> (gs), spc,
2739                                 flags);
2740       break;
2741
2742     case GIMPLE_OMP_SINGLE:
2743       dump_gimple_omp_single (buffer, as_a <const gomp_single *> (gs), spc,
2744                               flags);
2745       break;
2746
2747     case GIMPLE_OMP_TARGET:
2748       dump_gimple_omp_target (buffer, as_a <const gomp_target *> (gs), spc,
2749                               flags);
2750       break;
2751
2752     case GIMPLE_OMP_TEAMS:
2753       dump_gimple_omp_teams (buffer, as_a <const gomp_teams *> (gs), spc,
2754                              flags);
2755       break;
2756
2757     case GIMPLE_OMP_RETURN:
2758       dump_gimple_omp_return (buffer, gs, spc, flags);
2759       break;
2760
2761     case GIMPLE_OMP_SECTIONS:
2762       dump_gimple_omp_sections (buffer, as_a <const gomp_sections *> (gs),
2763                                 spc, flags);
2764       break;
2765
2766     case GIMPLE_OMP_SECTIONS_SWITCH:
2767       pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
2768       break;
2769
2770     case GIMPLE_OMP_TASKGROUP:
2771       dump_gimple_omp_taskgroup (buffer, gs, spc, flags);
2772       break;
2773
2774     case GIMPLE_OMP_MASKED:
2775       dump_gimple_omp_masked (buffer, gs, spc, flags);
2776       break;
2777
2778     case GIMPLE_OMP_SCOPE:
2779       dump_gimple_omp_scope (buffer, gs, spc, flags);
2780       break;
2781
2782     case GIMPLE_OMP_MASTER:
2783     case GIMPLE_OMP_SECTION:
2784       dump_gimple_omp_block (buffer, gs, spc, flags);
2785       break;
2786
2787     case GIMPLE_OMP_ORDERED:
2788       dump_gimple_omp_ordered (buffer, as_a <const gomp_ordered *> (gs), spc,
2789                                flags);
2790       break;
2791
2792     case GIMPLE_OMP_SCAN:
2793       dump_gimple_omp_scan (buffer, as_a <const gomp_scan *> (gs), spc,
2794                             flags);
2795       break;
2796
2797     case GIMPLE_OMP_CRITICAL:
2798       dump_gimple_omp_critical (buffer, as_a <const gomp_critical *> (gs), spc,
2799                                 flags);
2800       break;
2801
2802     case GIMPLE_CATCH:
2803       dump_gimple_catch (buffer, as_a <const gcatch *> (gs), spc, flags);
2804       break;
2805
2806     case GIMPLE_EH_FILTER:
2807       dump_gimple_eh_filter (buffer, as_a <const geh_filter *> (gs), spc,
2808                              flags);
2809       break;
2810
2811     case GIMPLE_EH_MUST_NOT_THROW:
2812       dump_gimple_eh_must_not_throw (buffer,
2813                                      as_a <const geh_mnt *> (gs),
2814                                      spc, flags);
2815       break;
2816
2817     case GIMPLE_EH_ELSE:
2818       dump_gimple_eh_else (buffer, as_a <const geh_else *> (gs), spc, flags);
2819       break;
2820
2821     case GIMPLE_RESX:
2822       dump_gimple_resx (buffer, as_a <const gresx *> (gs), spc, flags);
2823       break;
2824
2825     case GIMPLE_EH_DISPATCH:
2826       dump_gimple_eh_dispatch (buffer, as_a <const geh_dispatch *> (gs), spc,
2827                                flags);
2828       break;
2829
2830     case GIMPLE_DEBUG:
2831       dump_gimple_debug (buffer, as_a <const gdebug *> (gs), spc, flags);
2832       break;
2833
2834     case GIMPLE_PREDICT:
2835       pp_string (buffer, "// predicted ");
2836       if (gimple_predict_outcome (gs))
2837         pp_string (buffer, "likely by ");
2838       else
2839         pp_string (buffer, "unlikely by ");
2840       pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
2841       pp_string (buffer, " predictor.");
2842       break;
2843
2844     case GIMPLE_TRANSACTION:
2845       dump_gimple_transaction (buffer, as_a <const gtransaction *> (gs), spc,
2846                                flags);
2847       break;
2848
2849     default:
2850       GIMPLE_NIY;
2851     }
2852 }
2853
2854
2855 /* Dumps header of basic block BB to OUTF indented by INDENT
2856    spaces and details described by flags.  */
2857
2858 static void
2859 dump_gimple_bb_header (FILE *outf, basic_block bb, int indent,
2860                        dump_flags_t flags)
2861 {
2862   if (flags & TDF_BLOCKS)
2863     {
2864       if (flags & TDF_LINENO)
2865         {
2866           gimple_stmt_iterator gsi;
2867
2868           fputs (";; ", outf);
2869
2870           for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2871             if (!is_gimple_debug (gsi_stmt (gsi))
2872                 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
2873               {
2874                 fprintf (outf, "%*sstarting at line %d",
2875                          indent, "", get_lineno (gsi_stmt (gsi)));
2876                 break;
2877               }
2878           if (bb->discriminator)
2879             fprintf (outf, ", discriminator %i", bb->discriminator);
2880           fputc ('\n', outf);
2881         }
2882     }
2883   else
2884     {
2885       if (flags & TDF_GIMPLE)
2886         {
2887           fprintf (outf, "%*s__BB(%d", indent, "", bb->index);
2888           if (bb->loop_father->header == bb)
2889             fprintf (outf, ",loop_header(%d)", bb->loop_father->num);
2890           if (bb->count.initialized_p ())
2891             fprintf (outf, ",%s(%" PRIu64 ")",
2892                      profile_quality_as_string (bb->count.quality ()),
2893                      bb->count.value ());
2894           fprintf (outf, "):\n");
2895         }
2896       else
2897         fprintf (outf, "%*s<bb %d> %s:\n",
2898                  indent, "", bb->index, dump_profile (bb->count));
2899     }
2900 }
2901
2902
2903 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2904    spaces.  */
2905
2906 static void
2907 dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
2908                        basic_block bb ATTRIBUTE_UNUSED,
2909                        int indent ATTRIBUTE_UNUSED,
2910                        dump_flags_t flags ATTRIBUTE_UNUSED)
2911 {
2912   /* There is currently no GIMPLE-specific basic block info to dump.  */
2913   return;
2914 }
2915
2916
2917 /* Dump PHI nodes of basic block BB to BUFFER with details described
2918    by FLAGS and indented by INDENT spaces.  */
2919
2920 static void
2921 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent,
2922                 dump_flags_t flags)
2923 {
2924   gphi_iterator i;
2925
2926   for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2927     {
2928       gphi *phi = i.phi ();
2929       if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2930         {
2931           INDENT (indent);
2932           dump_gimple_phi (buffer, phi, indent,
2933                            (flags & TDF_GIMPLE) ? false : true, flags);
2934           pp_newline (buffer);
2935         }
2936     }
2937 }
2938
2939
2940 /* Dump jump to basic block BB that is represented implicitly in the cfg
2941    to BUFFER.  */
2942
2943 static void
2944 pp_cfg_jump (pretty_printer *buffer, edge e, dump_flags_t flags)
2945 {
2946   if (flags & TDF_GIMPLE)
2947     {
2948       pp_string (buffer, "goto __BB");
2949       pp_decimal_int (buffer, e->dest->index);
2950       if (e->probability.initialized_p ())
2951         {
2952           pp_string (buffer, "(");
2953           pp_string (buffer,
2954                      profile_quality_as_string (e->probability.quality ()));
2955           pp_string (buffer, "(");
2956           pp_decimal_int (buffer, e->probability.value ());
2957           pp_string (buffer, "))");
2958         }
2959       pp_semicolon (buffer);
2960     }
2961   else
2962     {
2963       pp_string (buffer, "goto <bb ");
2964       pp_decimal_int (buffer, e->dest->index);
2965       pp_greater (buffer);
2966       pp_semicolon (buffer);
2967
2968       dump_edge_probability (buffer, e);
2969     }
2970 }
2971
2972
2973 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2974    by INDENT spaces, with details given by FLAGS.  */
2975
2976 static void
2977 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2978                      dump_flags_t flags)
2979 {
2980   edge e;
2981   gimple *stmt;
2982
2983   stmt = last_stmt (bb);
2984
2985   if (stmt && gimple_code (stmt) == GIMPLE_COND)
2986     {
2987       edge true_edge, false_edge;
2988
2989       /* When we are emitting the code or changing CFG, it is possible that
2990          the edges are not yet created.  When we are using debug_bb in such
2991          a situation, we do not want it to crash.  */
2992       if (EDGE_COUNT (bb->succs) != 2)
2993         return;
2994       extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2995
2996       INDENT (indent + 2);
2997       pp_cfg_jump (buffer, true_edge, flags);
2998       newline_and_indent (buffer, indent);
2999       pp_string (buffer, "else");
3000       newline_and_indent (buffer, indent + 2);
3001       pp_cfg_jump (buffer, false_edge, flags);
3002       pp_newline (buffer);
3003       return;
3004     }
3005
3006   /* If there is a fallthru edge, we may need to add an artificial
3007      goto to the dump.  */
3008   e = find_fallthru_edge (bb->succs);
3009
3010   if (e && (e->dest != bb->next_bb || (flags & TDF_GIMPLE)))
3011     {
3012       INDENT (indent);
3013
3014       if ((flags & TDF_LINENO)
3015           && e->goto_locus != UNKNOWN_LOCATION)
3016         dump_location (buffer, e->goto_locus);
3017
3018       pp_cfg_jump (buffer, e, flags);
3019       pp_newline (buffer);
3020     }
3021 }
3022
3023
3024 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
3025    indented by INDENT spaces.  */
3026
3027 static void
3028 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
3029                      dump_flags_t flags)
3030 {
3031   gimple_stmt_iterator gsi;
3032   gimple *stmt;
3033   int label_indent = indent - 2;
3034
3035   if (label_indent < 0)
3036     label_indent = 0;
3037
3038   dump_phi_nodes (buffer, bb, indent, flags);
3039
3040   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
3041     {
3042       int curr_indent;
3043
3044       stmt = gsi_stmt (gsi);
3045
3046       curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
3047
3048       INDENT (curr_indent);
3049       pp_gimple_stmt_1 (buffer, stmt, curr_indent, flags);
3050       pp_newline_and_flush (buffer);
3051       gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl));
3052       dump_histograms_for_stmt (DECL_STRUCT_FUNCTION (current_function_decl),
3053                                 pp_buffer (buffer)->stream, stmt);
3054     }
3055
3056   dump_implicit_edges (buffer, bb, indent, flags);
3057   pp_flush (buffer);
3058 }
3059
3060
3061 /* Dumps basic block BB to FILE with details described by FLAGS and
3062    indented by INDENT spaces.  */
3063
3064 void
3065 gimple_dump_bb (FILE *file, basic_block bb, int indent, dump_flags_t flags)
3066 {
3067   dump_gimple_bb_header (file, bb, indent, flags);
3068   if (bb->index >= NUM_FIXED_BLOCKS)
3069     {
3070       pretty_printer buffer;
3071       pp_needs_newline (&buffer) = true;
3072       buffer.buffer->stream = file;
3073       gimple_dump_bb_buff (&buffer, bb, indent, flags);
3074     }
3075   dump_gimple_bb_footer (file, bb, indent, flags);
3076 }
3077
3078 /* Dumps basic block BB to pretty-printer PP with default dump flags and
3079    no indentation, for use as a label of a DOT graph record-node.
3080    ??? Should just use gimple_dump_bb_buff here, except that value profiling
3081    histogram dumping doesn't know about pretty-printers.  */
3082
3083 void
3084 gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
3085 {
3086   pp_printf (pp, "<bb %d>:\n", bb->index);
3087   pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
3088
3089   for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
3090        gsi_next (&gsi))
3091     {
3092       gphi *phi = gsi.phi ();
3093       if (!virtual_operand_p (gimple_phi_result (phi))
3094           || (dump_flags & TDF_VOPS))
3095         {
3096           pp_bar (pp);
3097           pp_write_text_to_stream (pp);
3098           pp_string (pp, "# ");
3099           pp_gimple_stmt_1 (pp, phi, 0, dump_flags);
3100           pp_newline (pp);
3101           pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
3102         }
3103     }
3104
3105   for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
3106        gsi_next (&gsi))
3107     {
3108       gimple *stmt = gsi_stmt (gsi);
3109       pp_bar (pp);
3110       pp_write_text_to_stream (pp);
3111       pp_gimple_stmt_1 (pp, stmt, 0, dump_flags);
3112       pp_newline (pp);
3113       pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
3114     }
3115   dump_implicit_edges (pp, bb, 0, dump_flags);
3116   pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
3117 }
3118
3119 #if __GNUC__ >= 10
3120 #  pragma GCC diagnostic pop
3121 #endif