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