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