c++: 'this' adjustment for devirtualized call
[official-gcc.git] / gcc / gimple-pretty-print.c
blobc9c0a66ee308a034cc82b4976c15a0e20e43a4b7
1 /* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001-2021 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldyh@redhat.com> and
4 Diego Novillo <dnovillo@google.com>
6 This file is part of GCC.
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.
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.
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/>. */
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"
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
54 #define INDENT(SPACE) \
55 do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
57 #define GIMPLE_NIY do_niy (buffer,gs)
59 /* Try to print on BUFFER a default message for the unrecognized
60 gimple statement GS. */
62 static void
63 do_niy (pretty_printer *buffer, const gimple *gs)
65 pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
66 gimple_code_name[(int) gimple_code (gs)]);
70 /* Emit a newline and SPC indentation spaces to BUFFER. */
72 static void
73 newline_and_indent (pretty_printer *buffer, int spc)
75 pp_newline (buffer);
76 INDENT (spc);
80 /* Print the GIMPLE statement GS on stderr. */
82 DEBUG_FUNCTION void
83 debug_gimple_stmt (gimple *gs)
85 print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
89 /* Return formatted string of a VALUE probability
90 (biased by REG_BR_PROB_BASE). Returned string is allocated
91 by xstrdup_for_dump. */
93 static const char *
94 dump_profile (profile_count &count)
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 ());
106 const char *ret = xstrdup_for_dump (buf);
107 free (buf);
109 return ret;
112 /* Return formatted string of a VALUE probability
113 (biased by REG_BR_PROB_BASE). Returned string is allocated
114 by xstrdup_for_dump. */
116 static const char *
117 dump_probability (profile_probability probability)
119 float minimum = 0.01f;
120 float fvalue = -1;
122 if (probability.initialized_p ())
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;
129 char *buf;
130 if (probability.initialized_p ())
131 buf = xasprintf ("[%.2f%%]", fvalue);
132 else
133 buf = xasprintf ("[INV]");
135 const char *ret = xstrdup_for_dump (buf);
136 free (buf);
138 return ret;
141 /* Dump E probability to BUFFER. */
143 static void
144 dump_edge_probability (pretty_printer *buffer, edge e)
146 pp_scalar (buffer, " %s", dump_probability (e->probability));
149 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
150 FLAGS as in pp_gimple_stmt_1. */
152 void
153 print_gimple_stmt (FILE *file, gimple *g, int spc, dump_flags_t flags)
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);
162 DEBUG_FUNCTION void
163 debug (gimple &ref)
165 print_gimple_stmt (stderr, &ref, 0, TDF_NONE);
168 DEBUG_FUNCTION void
169 debug (gimple *ptr)
171 if (ptr)
172 debug (*ptr);
173 else
174 fprintf (stderr, "<nil>\n");
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. */
182 void
183 print_gimple_expr (FILE *file, gimple *g, int spc, dump_flags_t flags)
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);
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. */
199 static void
200 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc,
201 dump_flags_t flags)
203 gimple_stmt_iterator i;
205 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
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);
216 /* Print GIMPLE sequence SEQ to FILE using SPC indentation spaces and
217 FLAGS as in pp_gimple_stmt_1. */
219 void
220 print_gimple_seq (FILE *file, gimple_seq seq, int spc, dump_flags_t flags)
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);
230 /* Print the GIMPLE sequence SEQ on stderr. */
232 DEBUG_FUNCTION void
233 debug_gimple_seq (gimple_seq seq)
235 print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
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. */
251 static void
252 dump_gimple_fmt (pretty_printer *buffer, int spc, dump_flags_t flags,
253 const char *fmt, ...)
255 va_list args;
256 const char *c;
257 const char *tmp;
259 va_start (args, fmt);
260 for (c = fmt; *c; c++)
262 if (*c == '%')
264 gimple_seq seq;
265 tree t;
266 gimple *g;
267 switch (*++c)
269 case 'G':
270 g = va_arg (args, gimple *);
271 tmp = gimple_code_name[gimple_code (g)];
272 pp_string (buffer, tmp);
273 break;
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;
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;
290 case 'd':
291 pp_decimal_int (buffer, va_arg (args, int));
292 break;
294 case 's':
295 pp_string (buffer, va_arg (args, char *));
296 break;
298 case 'n':
299 newline_and_indent (buffer, spc);
300 break;
302 case 'x':
303 pp_scalar (buffer, "%x", va_arg (args, int));
304 break;
306 case '+':
307 spc += 2;
308 newline_and_indent (buffer, spc);
309 break;
311 case '-':
312 spc -= 2;
313 newline_and_indent (buffer, spc);
314 break;
316 default:
317 gcc_unreachable ();
320 else
321 pp_character (buffer, *c);
323 va_end (args);
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. */
330 static void
331 dump_unary_rhs (pretty_printer *buffer, const gassign *gs, int spc,
332 dump_flags_t flags)
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);
338 switch (rhs_code)
340 case VIEW_CONVERT_EXPR:
341 case ASSERT_EXPR:
342 dump_generic_node (buffer, rhs, spc, flags, false);
343 break;
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))
355 pp_left_paren (buffer);
356 dump_generic_node (buffer, rhs, spc, flags, false);
357 pp_right_paren (buffer);
359 else
360 dump_generic_node (buffer, rhs, spc, flags, false);
361 break;
363 case PAREN_EXPR:
364 pp_string (buffer, "((");
365 dump_generic_node (buffer, rhs, spc, flags, false);
366 pp_string (buffer, "))");
367 break;
369 case ABS_EXPR:
370 case ABSU_EXPR:
371 if (flags & TDF_GIMPLE)
373 pp_string (buffer,
374 rhs_code == ABS_EXPR ? "__ABS " : "__ABSU ");
375 dump_generic_node (buffer, rhs, spc, flags, false);
377 else
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);
384 break;
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)
394 dump_generic_node (buffer, rhs, spc, flags, false);
395 break;
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
405 pp_left_bracket (buffer);
406 pp_string (buffer, get_tree_code_name (rhs_code));
407 pp_string (buffer, "] ");
410 if (op_prio (rhs) < op_code_prio (rhs_code))
412 pp_left_paren (buffer);
413 dump_generic_node (buffer, rhs, spc, flags, false);
414 pp_right_paren (buffer);
416 else
417 dump_generic_node (buffer, rhs, spc, flags, false);
418 break;
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. */
426 static void
427 dump_binary_rhs (pretty_printer *buffer, const gassign *gs, int spc,
428 dump_flags_t flags)
430 const char *p;
431 enum tree_code code = gimple_assign_rhs_code (gs);
432 switch (code)
434 case MIN_EXPR:
435 case MAX_EXPR:
436 if (flags & TDF_GIMPLE)
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;
447 else
449 gcc_fallthrough ();
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;
476 default:
477 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
479 pp_left_paren (buffer);
480 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
481 false);
482 pp_right_paren (buffer);
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))
491 pp_left_paren (buffer);
492 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
493 false);
494 pp_right_paren (buffer);
496 else
497 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
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. */
504 static void
505 dump_ternary_rhs (pretty_printer *buffer, const gassign *gs, int spc,
506 dump_flags_t flags)
508 const char *p;
509 enum tree_code code = gimple_assign_rhs_code (gs);
510 switch (code)
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;
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;
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;
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;
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;
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;
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;
589 case BIT_INSERT_EXPR:
590 if (flags & TDF_GIMPLE)
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);
603 else
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))))
616 pp_string (buffer, " (");
617 pp_decimal_int (buffer, TYPE_PRECISION
618 (TREE_TYPE (gimple_assign_rhs2 (gs))));
619 pp_string (buffer, " bits)");
621 pp_greater (buffer);
623 break;
625 default:
626 gcc_unreachable ();
631 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
632 pp_gimple_stmt_1. */
634 static void
635 dump_gimple_assign (pretty_printer *buffer, const gassign *gs, int spc,
636 dump_flags_t flags)
638 if (flags & TDF_RAW)
640 tree arg1 = NULL;
641 tree arg2 = NULL;
642 tree arg3 = NULL;
643 switch (gimple_num_ops (gs))
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 ();
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);
662 else
664 if (!(flags & TDF_RHS_ONLY))
666 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
667 pp_space (buffer);
668 pp_equal (buffer);
670 if (gimple_assign_nontemporal_move_p (gs))
671 pp_string (buffer, "{nt}");
673 if (gimple_has_volatile_ops (gs))
674 pp_string (buffer, "{v}");
676 pp_space (buffer);
679 if (gimple_num_ops (gs) == 2)
680 dump_unary_rhs (buffer, gs, spc, flags);
681 else if (gimple_num_ops (gs) == 3)
682 dump_binary_rhs (buffer, gs, spc, flags);
683 else if (gimple_num_ops (gs) == 4)
684 dump_ternary_rhs (buffer, gs, spc, flags);
685 else
686 gcc_unreachable ();
687 if (!(flags & TDF_RHS_ONLY))
688 pp_semicolon (buffer);
693 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
694 pp_gimple_stmt_1. */
696 static void
697 dump_gimple_return (pretty_printer *buffer, const greturn *gs, int spc,
698 dump_flags_t flags)
700 tree t;
702 t = gimple_return_retval (gs);
703 if (flags & TDF_RAW)
704 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
705 else
707 pp_string (buffer, "return");
708 if (t)
710 pp_space (buffer);
711 dump_generic_node (buffer, t, spc, flags, false);
713 pp_semicolon (buffer);
718 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
719 dump_gimple_call. */
721 static void
722 dump_gimple_call_args (pretty_printer *buffer, const gcall *gs,
723 dump_flags_t flags)
725 size_t i = 0;
727 /* Pretty print first arg to certain internal fns. */
728 if (gimple_call_internal_p (gs))
730 const char *const *enums = NULL;
731 unsigned limit = 0;
733 switch (gimple_call_internal_fn (gs))
735 case IFN_UNIQUE:
736 #define DEF(X) #X
737 static const char *const unique_args[] = {IFN_UNIQUE_CODES};
738 #undef DEF
739 enums = unique_args;
741 limit = ARRAY_SIZE (unique_args);
742 break;
744 case IFN_GOACC_LOOP:
745 #define DEF(X) #X
746 static const char *const loop_args[] = {IFN_GOACC_LOOP_CODES};
747 #undef DEF
748 enums = loop_args;
749 limit = ARRAY_SIZE (loop_args);
750 break;
752 case IFN_GOACC_REDUCTION:
753 #define DEF(X) #X
754 static const char *const reduction_args[]
755 = {IFN_GOACC_REDUCTION_CODES};
756 #undef DEF
757 enums = reduction_args;
758 limit = ARRAY_SIZE (reduction_args);
759 break;
761 case IFN_HWASAN_MARK:
762 case IFN_ASAN_MARK:
763 #define DEF(X) #X
764 static const char *const asan_mark_args[] = {IFN_ASAN_MARK_FLAGS};
765 #undef DEF
766 enums = asan_mark_args;
767 limit = ARRAY_SIZE (asan_mark_args);
768 break;
770 default:
771 break;
773 if (limit)
775 tree arg0 = gimple_call_arg (gs, 0);
776 HOST_WIDE_INT v;
778 if (TREE_CODE (arg0) == INTEGER_CST
779 && tree_fits_shwi_p (arg0)
780 && (v = tree_to_shwi (arg0)) >= 0 && v < limit)
782 i++;
783 pp_string (buffer, enums[v]);
788 for (; i < gimple_call_num_args (gs); i++)
790 if (i)
791 pp_string (buffer, ", ");
792 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
795 if (gimple_call_va_arg_pack_p (gs))
797 if (i)
798 pp_string (buffer, ", ");
800 pp_string (buffer, "__builtin_va_arg_pack ()");
804 /* Dump the points-to solution *PT to BUFFER. */
806 static void
807 pp_points_to_solution (pretty_printer *buffer, const pt_solution *pt)
809 if (pt->anything)
811 pp_string (buffer, "anything ");
812 return;
814 if (pt->nonlocal)
815 pp_string (buffer, "nonlocal ");
816 if (pt->escaped)
817 pp_string (buffer, "escaped ");
818 if (pt->ipa_escaped)
819 pp_string (buffer, "unit-escaped ");
820 if (pt->null)
821 pp_string (buffer, "null ");
822 if (pt->vars
823 && !bitmap_empty_p (pt->vars))
825 bitmap_iterator bi;
826 unsigned i;
827 pp_string (buffer, "{ ");
828 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
830 pp_string (buffer, "D.");
831 pp_decimal_int (buffer, i);
832 pp_space (buffer);
834 pp_right_brace (buffer);
835 if (pt->vars_contains_nonlocal
836 || pt->vars_contains_escaped
837 || pt->vars_contains_escaped_heap
838 || pt->vars_contains_restrict)
840 const char *comma = "";
841 pp_string (buffer, " (");
842 if (pt->vars_contains_nonlocal)
844 pp_string (buffer, "nonlocal");
845 comma = ", ";
847 if (pt->vars_contains_escaped)
849 pp_string (buffer, comma);
850 pp_string (buffer, "escaped");
851 comma = ", ";
853 if (pt->vars_contains_escaped_heap)
855 pp_string (buffer, comma);
856 pp_string (buffer, "escaped heap");
857 comma = ", ";
859 if (pt->vars_contains_restrict)
861 pp_string (buffer, comma);
862 pp_string (buffer, "restrict");
863 comma = ", ";
865 if (pt->vars_contains_interposable)
867 pp_string (buffer, comma);
868 pp_string (buffer, "interposable");
870 pp_string (buffer, ")");
876 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
877 pp_gimple_stmt_1. */
879 static void
880 dump_gimple_call (pretty_printer *buffer, const gcall *gs, int spc,
881 dump_flags_t flags)
883 tree lhs = gimple_call_lhs (gs);
884 tree fn = gimple_call_fn (gs);
886 if (flags & TDF_ALIAS)
888 const pt_solution *pt;
889 pt = gimple_call_use_set (gs);
890 if (!pt_solution_empty_p (pt))
892 pp_string (buffer, "# USE = ");
893 pp_points_to_solution (buffer, pt);
894 newline_and_indent (buffer, spc);
896 pt = gimple_call_clobber_set (gs);
897 if (!pt_solution_empty_p (pt))
899 pp_string (buffer, "# CLB = ");
900 pp_points_to_solution (buffer, pt);
901 newline_and_indent (buffer, spc);
905 if (flags & TDF_RAW)
907 if (gimple_call_internal_p (gs))
908 dump_gimple_fmt (buffer, spc, flags, "%G <.%s, %T", gs,
909 internal_fn_name (gimple_call_internal_fn (gs)), lhs);
910 else
911 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T", gs, fn, lhs);
912 if (gimple_call_num_args (gs) > 0)
914 pp_string (buffer, ", ");
915 dump_gimple_call_args (buffer, gs, flags);
917 pp_greater (buffer);
919 else
921 if (lhs && !(flags & TDF_RHS_ONLY))
923 dump_generic_node (buffer, lhs, spc, flags, false);
924 pp_string (buffer, " =");
926 if (gimple_has_volatile_ops (gs))
927 pp_string (buffer, "{v}");
929 pp_space (buffer);
931 if (gimple_call_internal_p (gs))
933 pp_dot (buffer);
934 pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
936 else
937 print_call_name (buffer, fn, flags);
938 pp_string (buffer, " (");
939 dump_gimple_call_args (buffer, gs, flags);
940 pp_right_paren (buffer);
941 if (!(flags & TDF_RHS_ONLY))
942 pp_semicolon (buffer);
945 if (gimple_call_chain (gs))
947 pp_string (buffer, " [static-chain: ");
948 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
949 pp_right_bracket (buffer);
952 if (gimple_call_return_slot_opt_p (gs))
953 pp_string (buffer, " [return slot optimization]");
954 if (gimple_call_tail_p (gs))
955 pp_string (buffer, " [tail call]");
956 if (gimple_call_must_tail_p (gs))
957 pp_string (buffer, " [must tail call]");
959 if (fn == NULL)
960 return;
962 /* Dump the arguments of _ITM_beginTransaction sanely. */
963 if (TREE_CODE (fn) == ADDR_EXPR)
964 fn = TREE_OPERAND (fn, 0);
965 if (TREE_CODE (fn) == FUNCTION_DECL && decl_is_tm_clone (fn))
966 pp_string (buffer, " [tm-clone]");
967 if (TREE_CODE (fn) == FUNCTION_DECL
968 && fndecl_built_in_p (fn, BUILT_IN_TM_START)
969 && gimple_call_num_args (gs) > 0)
971 tree t = gimple_call_arg (gs, 0);
972 unsigned HOST_WIDE_INT props;
973 gcc_assert (TREE_CODE (t) == INTEGER_CST);
975 pp_string (buffer, " [ ");
977 /* Get the transaction code properties. */
978 props = TREE_INT_CST_LOW (t);
980 if (props & PR_INSTRUMENTEDCODE)
981 pp_string (buffer, "instrumentedCode ");
982 if (props & PR_UNINSTRUMENTEDCODE)
983 pp_string (buffer, "uninstrumentedCode ");
984 if (props & PR_HASNOXMMUPDATE)
985 pp_string (buffer, "hasNoXMMUpdate ");
986 if (props & PR_HASNOABORT)
987 pp_string (buffer, "hasNoAbort ");
988 if (props & PR_HASNOIRREVOCABLE)
989 pp_string (buffer, "hasNoIrrevocable ");
990 if (props & PR_DOESGOIRREVOCABLE)
991 pp_string (buffer, "doesGoIrrevocable ");
992 if (props & PR_HASNOSIMPLEREADS)
993 pp_string (buffer, "hasNoSimpleReads ");
994 if (props & PR_AWBARRIERSOMITTED)
995 pp_string (buffer, "awBarriersOmitted ");
996 if (props & PR_RARBARRIERSOMITTED)
997 pp_string (buffer, "RaRBarriersOmitted ");
998 if (props & PR_UNDOLOGCODE)
999 pp_string (buffer, "undoLogCode ");
1000 if (props & PR_PREFERUNINSTRUMENTED)
1001 pp_string (buffer, "preferUninstrumented ");
1002 if (props & PR_EXCEPTIONBLOCK)
1003 pp_string (buffer, "exceptionBlock ");
1004 if (props & PR_HASELSE)
1005 pp_string (buffer, "hasElse ");
1006 if (props & PR_READONLY)
1007 pp_string (buffer, "readOnly ");
1009 pp_right_bracket (buffer);
1014 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
1015 pp_gimple_stmt_1. */
1017 static void
1018 dump_gimple_switch (pretty_printer *buffer, const gswitch *gs, int spc,
1019 dump_flags_t flags)
1021 unsigned int i;
1023 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
1024 if (flags & TDF_RAW)
1025 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
1026 gimple_switch_index (gs));
1027 else
1029 pp_string (buffer, "switch (");
1030 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
1031 if (flags & TDF_GIMPLE)
1032 pp_string (buffer, ") {");
1033 else
1034 pp_string (buffer, ") <");
1037 for (i = 0; i < gimple_switch_num_labels (gs); i++)
1039 tree case_label = gimple_switch_label (gs, i);
1040 gcc_checking_assert (case_label != NULL_TREE);
1041 dump_generic_node (buffer, case_label, spc, flags, false);
1042 pp_space (buffer);
1043 tree label = CASE_LABEL (case_label);
1044 dump_generic_node (buffer, label, spc, flags, false);
1046 if (cfun && cfun->cfg)
1048 basic_block dest = label_to_block (cfun, label);
1049 if (dest)
1051 edge label_edge = find_edge (gimple_bb (gs), dest);
1052 if (label_edge && !(flags & TDF_GIMPLE))
1053 dump_edge_probability (buffer, label_edge);
1057 if (i < gimple_switch_num_labels (gs) - 1)
1059 if (flags & TDF_GIMPLE)
1060 pp_string (buffer, "; ");
1061 else
1062 pp_string (buffer, ", ");
1065 if (flags & TDF_GIMPLE)
1066 pp_string (buffer, "; }");
1067 else
1068 pp_greater (buffer);
1072 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
1073 pp_gimple_stmt_1. */
1075 static void
1076 dump_gimple_cond (pretty_printer *buffer, const gcond *gs, int spc,
1077 dump_flags_t flags)
1079 if (flags & TDF_RAW)
1080 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
1081 get_tree_code_name (gimple_cond_code (gs)),
1082 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
1083 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
1084 else
1086 if (!(flags & TDF_RHS_ONLY))
1087 pp_string (buffer, "if (");
1088 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
1089 pp_space (buffer);
1090 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
1091 pp_space (buffer);
1092 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
1093 if (!(flags & TDF_RHS_ONLY))
1095 edge_iterator ei;
1096 edge e, true_edge = NULL, false_edge = NULL;
1097 basic_block bb = gimple_bb (gs);
1099 if (bb)
1101 FOR_EACH_EDGE (e, ei, bb->succs)
1103 if (e->flags & EDGE_TRUE_VALUE)
1104 true_edge = e;
1105 else if (e->flags & EDGE_FALSE_VALUE)
1106 false_edge = e;
1110 bool has_edge_info = true_edge != NULL && false_edge != NULL;
1112 pp_right_paren (buffer);
1114 if (gimple_cond_true_label (gs))
1116 pp_string (buffer, " goto ");
1117 dump_generic_node (buffer, gimple_cond_true_label (gs),
1118 spc, flags, false);
1119 if (has_edge_info && !(flags & TDF_GIMPLE))
1120 dump_edge_probability (buffer, true_edge);
1121 pp_semicolon (buffer);
1123 if (gimple_cond_false_label (gs))
1125 pp_string (buffer, " else goto ");
1126 dump_generic_node (buffer, gimple_cond_false_label (gs),
1127 spc, flags, false);
1128 if (has_edge_info && !(flags & TDF_GIMPLE))
1129 dump_edge_probability (buffer, false_edge);
1131 pp_semicolon (buffer);
1138 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
1139 spaces of indent. FLAGS specifies details to show in the dump (see
1140 TDF_* in dumpfils.h). */
1142 static void
1143 dump_gimple_label (pretty_printer *buffer, const glabel *gs, int spc,
1144 dump_flags_t flags)
1146 tree label = gimple_label_label (gs);
1147 if (flags & TDF_RAW)
1148 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
1149 else
1151 dump_generic_node (buffer, label, spc, flags, false);
1152 pp_colon (buffer);
1154 if (flags & TDF_GIMPLE)
1155 return;
1156 if (DECL_NONLOCAL (label))
1157 pp_string (buffer, " [non-local]");
1158 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
1159 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
1162 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
1163 spaces of indent. FLAGS specifies details to show in the dump (see
1164 TDF_* in dumpfile.h). */
1166 static void
1167 dump_gimple_goto (pretty_printer *buffer, const ggoto *gs, int spc,
1168 dump_flags_t flags)
1170 tree label = gimple_goto_dest (gs);
1171 if (flags & TDF_RAW)
1172 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
1173 else
1174 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
1178 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
1179 spaces of indent. FLAGS specifies details to show in the dump (see
1180 TDF_* in dumpfile.h). */
1182 static void
1183 dump_gimple_bind (pretty_printer *buffer, const gbind *gs, int spc,
1184 dump_flags_t flags)
1186 if (flags & TDF_RAW)
1187 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
1188 else
1189 pp_left_brace (buffer);
1190 if (!(flags & TDF_SLIM))
1192 tree var;
1194 for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
1196 newline_and_indent (buffer, 2);
1197 print_declaration (buffer, var, spc, flags);
1199 if (gimple_bind_vars (gs))
1200 pp_newline (buffer);
1202 pp_newline (buffer);
1203 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
1204 newline_and_indent (buffer, spc);
1205 if (flags & TDF_RAW)
1206 pp_greater (buffer);
1207 else
1208 pp_right_brace (buffer);
1212 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
1213 indent. FLAGS specifies details to show in the dump (see TDF_* in
1214 dumpfile.h). */
1216 static void
1217 dump_gimple_try (pretty_printer *buffer, const gtry *gs, int spc,
1218 dump_flags_t flags)
1220 if (flags & TDF_RAW)
1222 const char *type;
1223 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
1224 type = "GIMPLE_TRY_CATCH";
1225 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
1226 type = "GIMPLE_TRY_FINALLY";
1227 else
1228 type = "UNKNOWN GIMPLE_TRY";
1229 dump_gimple_fmt (buffer, spc, flags,
1230 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
1231 gimple_try_eval (gs), gimple_try_cleanup (gs));
1233 else
1235 pp_string (buffer, "try");
1236 newline_and_indent (buffer, spc + 2);
1237 pp_left_brace (buffer);
1238 pp_newline (buffer);
1240 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
1241 newline_and_indent (buffer, spc + 2);
1242 pp_right_brace (buffer);
1244 gimple_seq seq = gimple_try_cleanup (gs);
1246 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
1248 newline_and_indent (buffer, spc);
1249 pp_string (buffer, "catch");
1250 newline_and_indent (buffer, spc + 2);
1251 pp_left_brace (buffer);
1253 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
1255 newline_and_indent (buffer, spc);
1256 pp_string (buffer, "finally");
1257 newline_and_indent (buffer, spc + 2);
1258 pp_left_brace (buffer);
1260 if (seq && is_a <geh_else *> (gimple_seq_first_stmt (seq))
1261 && gimple_seq_nondebug_singleton_p (seq))
1263 geh_else *stmt = as_a <geh_else *> (gimple_seq_first_stmt (seq));
1264 seq = gimple_eh_else_n_body (stmt);
1265 pp_newline (buffer);
1266 dump_gimple_seq (buffer, seq, spc + 4, flags);
1267 newline_and_indent (buffer, spc + 2);
1268 pp_right_brace (buffer);
1269 seq = gimple_eh_else_e_body (stmt);
1270 newline_and_indent (buffer, spc);
1271 pp_string (buffer, "else");
1272 newline_and_indent (buffer, spc + 2);
1273 pp_left_brace (buffer);
1276 else
1277 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
1279 pp_newline (buffer);
1280 dump_gimple_seq (buffer, seq, spc + 4, flags);
1281 newline_and_indent (buffer, spc + 2);
1282 pp_right_brace (buffer);
1287 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
1288 indent. FLAGS specifies details to show in the dump (see TDF_* in
1289 dumpfile.h). */
1291 static void
1292 dump_gimple_catch (pretty_printer *buffer, const gcatch *gs, int spc,
1293 dump_flags_t flags)
1295 if (flags & TDF_RAW)
1296 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
1297 gimple_catch_types (gs), gimple_catch_handler (gs));
1298 else
1299 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
1300 gimple_catch_types (gs), gimple_catch_handler (gs));
1304 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
1305 indent. FLAGS specifies details to show in the dump (see TDF_* in
1306 dumpfile.h). */
1308 static void
1309 dump_gimple_eh_filter (pretty_printer *buffer, const geh_filter *gs, int spc,
1310 dump_flags_t flags)
1312 if (flags & TDF_RAW)
1313 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
1314 gimple_eh_filter_types (gs),
1315 gimple_eh_filter_failure (gs));
1316 else
1317 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
1318 gimple_eh_filter_types (gs),
1319 gimple_eh_filter_failure (gs));
1323 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
1325 static void
1326 dump_gimple_eh_must_not_throw (pretty_printer *buffer,
1327 const geh_mnt *gs, int spc, dump_flags_t flags)
1329 if (flags & TDF_RAW)
1330 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1331 gimple_eh_must_not_throw_fndecl (gs));
1332 else
1333 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
1334 gimple_eh_must_not_throw_fndecl (gs));
1338 /* Dump a GIMPLE_EH_ELSE tuple on the pretty_printer BUFFER, SPC spaces of
1339 indent. FLAGS specifies details to show in the dump (see TDF_* in
1340 dumpfile.h). */
1342 static void
1343 dump_gimple_eh_else (pretty_printer *buffer, const geh_else *gs, int spc,
1344 dump_flags_t flags)
1346 if (flags & TDF_RAW)
1347 dump_gimple_fmt (buffer, spc, flags,
1348 "%G <%+N_BODY <%S>%nE_BODY <%S>%->", gs,
1349 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1350 else
1351 dump_gimple_fmt (buffer, spc, flags,
1352 "<<<if_normal_exit>>>%+{%S}%-<<<else_eh_exit>>>%+{%S}",
1353 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1357 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
1358 indent. FLAGS specifies details to show in the dump (see TDF_* in
1359 dumpfile.h). */
1361 static void
1362 dump_gimple_resx (pretty_printer *buffer, const gresx *gs, int spc,
1363 dump_flags_t flags)
1365 if (flags & TDF_RAW)
1366 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1367 gimple_resx_region (gs));
1368 else
1369 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
1372 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
1374 static void
1375 dump_gimple_eh_dispatch (pretty_printer *buffer, const geh_dispatch *gs,
1376 int spc, dump_flags_t flags)
1378 if (flags & TDF_RAW)
1379 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1380 gimple_eh_dispatch_region (gs));
1381 else
1382 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
1383 gimple_eh_dispatch_region (gs));
1386 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
1387 of indent. FLAGS specifies details to show in the dump (see TDF_*
1388 in dumpfile.h). */
1390 static void
1391 dump_gimple_debug (pretty_printer *buffer, const gdebug *gs, int spc,
1392 dump_flags_t flags)
1394 switch (gs->subcode)
1396 case GIMPLE_DEBUG_BIND:
1397 if (flags & TDF_RAW)
1398 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
1399 gimple_debug_bind_get_var (gs),
1400 gimple_debug_bind_get_value (gs));
1401 else
1402 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
1403 gimple_debug_bind_get_var (gs),
1404 gimple_debug_bind_get_value (gs));
1405 break;
1407 case GIMPLE_DEBUG_SOURCE_BIND:
1408 if (flags & TDF_RAW)
1409 dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1410 gimple_debug_source_bind_get_var (gs),
1411 gimple_debug_source_bind_get_value (gs));
1412 else
1413 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1414 gimple_debug_source_bind_get_var (gs),
1415 gimple_debug_source_bind_get_value (gs));
1416 break;
1418 case GIMPLE_DEBUG_BEGIN_STMT:
1419 if (flags & TDF_RAW)
1420 dump_gimple_fmt (buffer, spc, flags, "%G BEGIN_STMT", gs);
1421 else
1422 dump_gimple_fmt (buffer, spc, flags, "# DEBUG BEGIN_STMT");
1423 break;
1425 case GIMPLE_DEBUG_INLINE_ENTRY:
1426 if (flags & TDF_RAW)
1427 dump_gimple_fmt (buffer, spc, flags, "%G INLINE_ENTRY %T", gs,
1428 gimple_block (gs)
1429 ? block_ultimate_origin (gimple_block (gs))
1430 : NULL_TREE);
1431 else
1432 dump_gimple_fmt (buffer, spc, flags, "# DEBUG INLINE_ENTRY %T",
1433 gimple_block (gs)
1434 ? block_ultimate_origin (gimple_block (gs))
1435 : NULL_TREE);
1436 break;
1438 default:
1439 gcc_unreachable ();
1443 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
1444 static void
1445 dump_gimple_omp_for (pretty_printer *buffer, const gomp_for *gs, int spc,
1446 dump_flags_t flags)
1448 size_t i;
1450 if (flags & TDF_RAW)
1452 const char *kind;
1453 switch (gimple_omp_for_kind (gs))
1455 case GF_OMP_FOR_KIND_FOR:
1456 kind = "";
1457 break;
1458 case GF_OMP_FOR_KIND_DISTRIBUTE:
1459 kind = " distribute";
1460 break;
1461 case GF_OMP_FOR_KIND_TASKLOOP:
1462 kind = " taskloop";
1463 break;
1464 case GF_OMP_FOR_KIND_OACC_LOOP:
1465 kind = " oacc_loop";
1466 break;
1467 case GF_OMP_FOR_KIND_SIMD:
1468 kind = " simd";
1469 break;
1470 default:
1471 gcc_unreachable ();
1473 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1474 kind, gimple_omp_body (gs));
1475 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1476 dump_gimple_fmt (buffer, spc, flags, " >,");
1477 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1478 dump_gimple_fmt (buffer, spc, flags,
1479 "%+%T, %T, %T, %s, %T,%n",
1480 gimple_omp_for_index (gs, i),
1481 gimple_omp_for_initial (gs, i),
1482 gimple_omp_for_final (gs, i),
1483 get_tree_code_name (gimple_omp_for_cond (gs, i)),
1484 gimple_omp_for_incr (gs, i));
1485 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1486 gimple_omp_for_pre_body (gs));
1488 else
1490 switch (gimple_omp_for_kind (gs))
1492 case GF_OMP_FOR_KIND_FOR:
1493 pp_string (buffer, "#pragma omp for");
1494 break;
1495 case GF_OMP_FOR_KIND_DISTRIBUTE:
1496 pp_string (buffer, "#pragma omp distribute");
1497 break;
1498 case GF_OMP_FOR_KIND_TASKLOOP:
1499 pp_string (buffer, "#pragma omp taskloop");
1500 break;
1501 case GF_OMP_FOR_KIND_OACC_LOOP:
1502 pp_string (buffer, "#pragma acc loop");
1503 break;
1504 case GF_OMP_FOR_KIND_SIMD:
1505 pp_string (buffer, "#pragma omp simd");
1506 break;
1507 default:
1508 gcc_unreachable ();
1510 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1511 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1513 if (i)
1514 spc += 2;
1515 newline_and_indent (buffer, spc);
1516 pp_string (buffer, "for (");
1517 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1518 flags, false);
1519 pp_string (buffer, " = ");
1520 tree init = gimple_omp_for_initial (gs, i);
1521 if (TREE_CODE (init) != TREE_VEC)
1522 dump_generic_node (buffer, init, spc, flags, false);
1523 else
1524 dump_omp_loop_non_rect_expr (buffer, init, spc, flags);
1525 pp_string (buffer, "; ");
1527 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1528 flags, false);
1529 pp_space (buffer);
1530 switch (gimple_omp_for_cond (gs, i))
1532 case LT_EXPR:
1533 pp_less (buffer);
1534 break;
1535 case GT_EXPR:
1536 pp_greater (buffer);
1537 break;
1538 case LE_EXPR:
1539 pp_less_equal (buffer);
1540 break;
1541 case GE_EXPR:
1542 pp_greater_equal (buffer);
1543 break;
1544 case NE_EXPR:
1545 pp_string (buffer, "!=");
1546 break;
1547 default:
1548 gcc_unreachable ();
1550 pp_space (buffer);
1551 tree cond = gimple_omp_for_final (gs, i);
1552 if (TREE_CODE (cond) != TREE_VEC)
1553 dump_generic_node (buffer, cond, spc, flags, false);
1554 else
1555 dump_omp_loop_non_rect_expr (buffer, cond, spc, flags);
1556 pp_string (buffer, "; ");
1558 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1559 flags, false);
1560 pp_string (buffer, " = ");
1561 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1562 flags, false);
1563 pp_right_paren (buffer);
1566 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1568 newline_and_indent (buffer, spc + 2);
1569 pp_left_brace (buffer);
1570 pp_newline (buffer);
1571 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1572 newline_and_indent (buffer, spc + 2);
1573 pp_right_brace (buffer);
1578 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
1580 static void
1581 dump_gimple_omp_continue (pretty_printer *buffer, const gomp_continue *gs,
1582 int spc, dump_flags_t flags)
1584 if (flags & TDF_RAW)
1586 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1587 gimple_omp_continue_control_def (gs),
1588 gimple_omp_continue_control_use (gs));
1590 else
1592 pp_string (buffer, "#pragma omp continue (");
1593 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1594 spc, flags, false);
1595 pp_comma (buffer);
1596 pp_space (buffer);
1597 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1598 spc, flags, false);
1599 pp_right_paren (buffer);
1603 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1605 static void
1606 dump_gimple_omp_single (pretty_printer *buffer, const gomp_single *gs,
1607 int spc, dump_flags_t flags)
1609 if (flags & TDF_RAW)
1611 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1612 gimple_omp_body (gs));
1613 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1614 dump_gimple_fmt (buffer, spc, flags, " >");
1616 else
1618 pp_string (buffer, "#pragma omp single");
1619 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1620 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1622 newline_and_indent (buffer, spc + 2);
1623 pp_left_brace (buffer);
1624 pp_newline (buffer);
1625 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1626 newline_and_indent (buffer, spc + 2);
1627 pp_right_brace (buffer);
1632 /* Dump a GIMPLE_OMP_TASKGROUP tuple on the pretty_printer BUFFER. */
1634 static void
1635 dump_gimple_omp_taskgroup (pretty_printer *buffer, const gimple *gs,
1636 int spc, dump_flags_t flags)
1638 if (flags & TDF_RAW)
1640 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1641 gimple_omp_body (gs));
1642 dump_omp_clauses (buffer, gimple_omp_taskgroup_clauses (gs), spc, flags);
1643 dump_gimple_fmt (buffer, spc, flags, " >");
1645 else
1647 pp_string (buffer, "#pragma omp taskgroup");
1648 dump_omp_clauses (buffer, gimple_omp_taskgroup_clauses (gs), spc, flags);
1649 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1651 newline_and_indent (buffer, spc + 2);
1652 pp_left_brace (buffer);
1653 pp_newline (buffer);
1654 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1655 newline_and_indent (buffer, spc + 2);
1656 pp_right_brace (buffer);
1661 /* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer BUFFER. */
1663 static void
1664 dump_gimple_omp_target (pretty_printer *buffer, const gomp_target *gs,
1665 int spc, dump_flags_t flags)
1667 const char *kind;
1668 switch (gimple_omp_target_kind (gs))
1670 case GF_OMP_TARGET_KIND_REGION:
1671 kind = "";
1672 break;
1673 case GF_OMP_TARGET_KIND_DATA:
1674 kind = " data";
1675 break;
1676 case GF_OMP_TARGET_KIND_UPDATE:
1677 kind = " update";
1678 break;
1679 case GF_OMP_TARGET_KIND_ENTER_DATA:
1680 kind = " enter data";
1681 break;
1682 case GF_OMP_TARGET_KIND_EXIT_DATA:
1683 kind = " exit data";
1684 break;
1685 case GF_OMP_TARGET_KIND_OACC_KERNELS:
1686 kind = " oacc_kernels";
1687 break;
1688 case GF_OMP_TARGET_KIND_OACC_PARALLEL:
1689 kind = " oacc_parallel";
1690 break;
1691 case GF_OMP_TARGET_KIND_OACC_SERIAL:
1692 kind = " oacc_serial";
1693 break;
1694 case GF_OMP_TARGET_KIND_OACC_DATA:
1695 kind = " oacc_data";
1696 break;
1697 case GF_OMP_TARGET_KIND_OACC_UPDATE:
1698 kind = " oacc_update";
1699 break;
1700 case GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA:
1701 kind = " oacc_enter_exit_data";
1702 break;
1703 case GF_OMP_TARGET_KIND_OACC_DECLARE:
1704 kind = " oacc_declare";
1705 break;
1706 case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
1707 kind = " oacc_host_data";
1708 break;
1709 case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_PARALLELIZED:
1710 kind = " oacc_parallel_kernels_parallelized";
1711 break;
1712 case GF_OMP_TARGET_KIND_OACC_PARALLEL_KERNELS_GANG_SINGLE:
1713 kind = " oacc_parallel_kernels_gang_single";
1714 break;
1715 case GF_OMP_TARGET_KIND_OACC_DATA_KERNELS:
1716 kind = " oacc_data_kernels";
1717 break;
1718 default:
1719 gcc_unreachable ();
1721 if (flags & TDF_RAW)
1723 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1724 kind, gimple_omp_body (gs));
1725 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1726 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1727 gimple_omp_target_child_fn (gs),
1728 gimple_omp_target_data_arg (gs));
1730 else
1732 pp_string (buffer, "#pragma omp target");
1733 pp_string (buffer, kind);
1734 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1735 if (gimple_omp_target_child_fn (gs))
1737 pp_string (buffer, " [child fn: ");
1738 dump_generic_node (buffer, gimple_omp_target_child_fn (gs),
1739 spc, flags, false);
1740 pp_string (buffer, " (");
1741 if (gimple_omp_target_data_arg (gs))
1742 dump_generic_node (buffer, gimple_omp_target_data_arg (gs),
1743 spc, flags, false);
1744 else
1745 pp_string (buffer, "???");
1746 pp_string (buffer, ")]");
1748 gimple_seq body = gimple_omp_body (gs);
1749 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1751 newline_and_indent (buffer, spc + 2);
1752 pp_left_brace (buffer);
1753 pp_newline (buffer);
1754 dump_gimple_seq (buffer, body, spc + 4, flags);
1755 newline_and_indent (buffer, spc + 2);
1756 pp_right_brace (buffer);
1758 else if (body)
1760 pp_newline (buffer);
1761 dump_gimple_seq (buffer, body, spc + 2, flags);
1766 /* Dump a GIMPLE_OMP_TEAMS tuple on the pretty_printer BUFFER. */
1768 static void
1769 dump_gimple_omp_teams (pretty_printer *buffer, const gomp_teams *gs, int spc,
1770 dump_flags_t flags)
1772 if (flags & TDF_RAW)
1774 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1775 gimple_omp_body (gs));
1776 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1777 dump_gimple_fmt (buffer, spc, flags, " >");
1779 else
1781 pp_string (buffer, "#pragma omp teams");
1782 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1783 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1785 newline_and_indent (buffer, spc + 2);
1786 pp_character (buffer, '{');
1787 pp_newline (buffer);
1788 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1789 newline_and_indent (buffer, spc + 2);
1790 pp_character (buffer, '}');
1795 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1797 static void
1798 dump_gimple_omp_sections (pretty_printer *buffer, const gomp_sections *gs,
1799 int spc, dump_flags_t flags)
1801 if (flags & TDF_RAW)
1803 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1804 gimple_omp_body (gs));
1805 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1806 dump_gimple_fmt (buffer, spc, flags, " >");
1808 else
1810 pp_string (buffer, "#pragma omp sections");
1811 if (gimple_omp_sections_control (gs))
1813 pp_string (buffer, " <");
1814 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1815 flags, false);
1816 pp_greater (buffer);
1818 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1819 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1821 newline_and_indent (buffer, spc + 2);
1822 pp_left_brace (buffer);
1823 pp_newline (buffer);
1824 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1825 newline_and_indent (buffer, spc + 2);
1826 pp_right_brace (buffer);
1831 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the
1832 pretty_printer BUFFER. */
1834 static void
1835 dump_gimple_omp_block (pretty_printer *buffer, const gimple *gs, int spc,
1836 dump_flags_t flags)
1838 if (flags & TDF_RAW)
1839 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1840 gimple_omp_body (gs));
1841 else
1843 switch (gimple_code (gs))
1845 case GIMPLE_OMP_MASTER:
1846 pp_string (buffer, "#pragma omp master");
1847 break;
1848 case GIMPLE_OMP_SECTION:
1849 pp_string (buffer, "#pragma omp section");
1850 break;
1851 default:
1852 gcc_unreachable ();
1854 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1856 newline_and_indent (buffer, spc + 2);
1857 pp_left_brace (buffer);
1858 pp_newline (buffer);
1859 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1860 newline_and_indent (buffer, spc + 2);
1861 pp_right_brace (buffer);
1866 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1868 static void
1869 dump_gimple_omp_critical (pretty_printer *buffer, const gomp_critical *gs,
1870 int spc, dump_flags_t flags)
1872 if (flags & TDF_RAW)
1873 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1874 gimple_omp_body (gs));
1875 else
1877 pp_string (buffer, "#pragma omp critical");
1878 if (gimple_omp_critical_name (gs))
1880 pp_string (buffer, " (");
1881 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1882 flags, false);
1883 pp_right_paren (buffer);
1885 dump_omp_clauses (buffer, gimple_omp_critical_clauses (gs), spc, flags);
1886 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1888 newline_and_indent (buffer, spc + 2);
1889 pp_left_brace (buffer);
1890 pp_newline (buffer);
1891 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1892 newline_and_indent (buffer, spc + 2);
1893 pp_right_brace (buffer);
1898 /* Dump a GIMPLE_OMP_ORDERED tuple on the pretty_printer BUFFER. */
1900 static void
1901 dump_gimple_omp_ordered (pretty_printer *buffer, const gomp_ordered *gs,
1902 int spc, dump_flags_t flags)
1904 if (flags & TDF_RAW)
1905 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1906 gimple_omp_body (gs));
1907 else
1909 pp_string (buffer, "#pragma omp ordered");
1910 dump_omp_clauses (buffer, gimple_omp_ordered_clauses (gs), spc, flags);
1911 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1913 newline_and_indent (buffer, spc + 2);
1914 pp_left_brace (buffer);
1915 pp_newline (buffer);
1916 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1917 newline_and_indent (buffer, spc + 2);
1918 pp_right_brace (buffer);
1923 /* Dump a GIMPLE_OMP_SCAN tuple on the pretty_printer BUFFER. */
1925 static void
1926 dump_gimple_omp_scan (pretty_printer *buffer, const gomp_scan *gs,
1927 int spc, dump_flags_t flags)
1929 if (flags & TDF_RAW)
1930 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1931 gimple_omp_body (gs));
1932 else
1934 if (gimple_omp_scan_clauses (gs))
1936 pp_string (buffer, "#pragma omp scan");
1937 dump_omp_clauses (buffer, gimple_omp_scan_clauses (gs), spc, flags);
1939 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1941 newline_and_indent (buffer, spc + 2);
1942 pp_left_brace (buffer);
1943 pp_newline (buffer);
1944 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1945 newline_and_indent (buffer, spc + 2);
1946 pp_right_brace (buffer);
1951 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1953 static void
1954 dump_gimple_omp_return (pretty_printer *buffer, const gimple *gs, int spc,
1955 dump_flags_t flags)
1957 if (flags & TDF_RAW)
1959 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d", gs,
1960 (int) gimple_omp_return_nowait_p (gs));
1961 if (gimple_omp_return_lhs (gs))
1962 dump_gimple_fmt (buffer, spc, flags, ", lhs=%T>",
1963 gimple_omp_return_lhs (gs));
1964 else
1965 dump_gimple_fmt (buffer, spc, flags, ">");
1967 else
1969 pp_string (buffer, "#pragma omp return");
1970 if (gimple_omp_return_nowait_p (gs))
1971 pp_string (buffer, "(nowait)");
1972 if (gimple_omp_return_lhs (gs))
1974 pp_string (buffer, " (set ");
1975 dump_generic_node (buffer, gimple_omp_return_lhs (gs),
1976 spc, flags, false);
1977 pp_character (buffer, ')');
1982 /* Dump a GIMPLE_TRANSACTION tuple on the pretty_printer BUFFER. */
1984 static void
1985 dump_gimple_transaction (pretty_printer *buffer, const gtransaction *gs,
1986 int spc, dump_flags_t flags)
1988 unsigned subcode = gimple_transaction_subcode (gs);
1990 if (flags & TDF_RAW)
1992 dump_gimple_fmt (buffer, spc, flags,
1993 "%G [SUBCODE=%x,NORM=%T,UNINST=%T,OVER=%T] "
1994 "<%+BODY <%S> >",
1995 gs, subcode, gimple_transaction_label_norm (gs),
1996 gimple_transaction_label_uninst (gs),
1997 gimple_transaction_label_over (gs),
1998 gimple_transaction_body (gs));
2000 else
2002 if (subcode & GTMA_IS_OUTER)
2003 pp_string (buffer, "__transaction_atomic [[outer]]");
2004 else if (subcode & GTMA_IS_RELAXED)
2005 pp_string (buffer, "__transaction_relaxed");
2006 else
2007 pp_string (buffer, "__transaction_atomic");
2008 subcode &= ~GTMA_DECLARATION_MASK;
2010 if (gimple_transaction_body (gs))
2012 newline_and_indent (buffer, spc + 2);
2013 pp_left_brace (buffer);
2014 pp_newline (buffer);
2015 dump_gimple_seq (buffer, gimple_transaction_body (gs),
2016 spc + 4, flags);
2017 newline_and_indent (buffer, spc + 2);
2018 pp_right_brace (buffer);
2020 else
2022 pp_string (buffer, " //");
2023 if (gimple_transaction_label_norm (gs))
2025 pp_string (buffer, " NORM=");
2026 dump_generic_node (buffer, gimple_transaction_label_norm (gs),
2027 spc, flags, false);
2029 if (gimple_transaction_label_uninst (gs))
2031 pp_string (buffer, " UNINST=");
2032 dump_generic_node (buffer, gimple_transaction_label_uninst (gs),
2033 spc, flags, false);
2035 if (gimple_transaction_label_over (gs))
2037 pp_string (buffer, " OVER=");
2038 dump_generic_node (buffer, gimple_transaction_label_over (gs),
2039 spc, flags, false);
2041 if (subcode)
2043 pp_string (buffer, " SUBCODE=[ ");
2044 if (subcode & GTMA_HAVE_ABORT)
2046 pp_string (buffer, "GTMA_HAVE_ABORT ");
2047 subcode &= ~GTMA_HAVE_ABORT;
2049 if (subcode & GTMA_HAVE_LOAD)
2051 pp_string (buffer, "GTMA_HAVE_LOAD ");
2052 subcode &= ~GTMA_HAVE_LOAD;
2054 if (subcode & GTMA_HAVE_STORE)
2056 pp_string (buffer, "GTMA_HAVE_STORE ");
2057 subcode &= ~GTMA_HAVE_STORE;
2059 if (subcode & GTMA_MAY_ENTER_IRREVOCABLE)
2061 pp_string (buffer, "GTMA_MAY_ENTER_IRREVOCABLE ");
2062 subcode &= ~GTMA_MAY_ENTER_IRREVOCABLE;
2064 if (subcode & GTMA_DOES_GO_IRREVOCABLE)
2066 pp_string (buffer, "GTMA_DOES_GO_IRREVOCABLE ");
2067 subcode &= ~GTMA_DOES_GO_IRREVOCABLE;
2069 if (subcode & GTMA_HAS_NO_INSTRUMENTATION)
2071 pp_string (buffer, "GTMA_HAS_NO_INSTRUMENTATION ");
2072 subcode &= ~GTMA_HAS_NO_INSTRUMENTATION;
2074 if (subcode)
2075 pp_printf (buffer, "0x%x ", subcode);
2076 pp_right_bracket (buffer);
2082 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
2083 indent. FLAGS specifies details to show in the dump (see TDF_* in
2084 dumpfile.h). */
2086 static void
2087 dump_gimple_asm (pretty_printer *buffer, const gasm *gs, int spc,
2088 dump_flags_t flags)
2090 unsigned int i, n, f, fields;
2092 if (flags & TDF_RAW)
2094 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
2095 gimple_asm_string (gs));
2097 n = gimple_asm_noutputs (gs);
2098 if (n)
2100 newline_and_indent (buffer, spc + 2);
2101 pp_string (buffer, "OUTPUT: ");
2102 for (i = 0; i < n; i++)
2104 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
2105 spc, flags, false);
2106 if (i < n - 1)
2107 pp_string (buffer, ", ");
2111 n = gimple_asm_ninputs (gs);
2112 if (n)
2114 newline_and_indent (buffer, spc + 2);
2115 pp_string (buffer, "INPUT: ");
2116 for (i = 0; i < n; i++)
2118 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
2119 spc, flags, false);
2120 if (i < n - 1)
2121 pp_string (buffer, ", ");
2125 n = gimple_asm_nclobbers (gs);
2126 if (n)
2128 newline_and_indent (buffer, spc + 2);
2129 pp_string (buffer, "CLOBBER: ");
2130 for (i = 0; i < n; i++)
2132 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
2133 spc, flags, false);
2134 if (i < n - 1)
2135 pp_string (buffer, ", ");
2139 n = gimple_asm_nlabels (gs);
2140 if (n)
2142 newline_and_indent (buffer, spc + 2);
2143 pp_string (buffer, "LABEL: ");
2144 for (i = 0; i < n; i++)
2146 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
2147 spc, flags, false);
2148 if (i < n - 1)
2149 pp_string (buffer, ", ");
2153 newline_and_indent (buffer, spc);
2154 pp_greater (buffer);
2156 else
2158 pp_string (buffer, "__asm__");
2159 if (gimple_asm_volatile_p (gs))
2160 pp_string (buffer, " __volatile__");
2161 if (gimple_asm_inline_p (gs))
2162 pp_string (buffer, " __inline__");
2163 if (gimple_asm_nlabels (gs))
2164 pp_string (buffer, " goto");
2165 pp_string (buffer, "(\"");
2166 pp_string (buffer, gimple_asm_string (gs));
2167 pp_string (buffer, "\"");
2169 if (gimple_asm_nlabels (gs))
2170 fields = 4;
2171 else if (gimple_asm_nclobbers (gs))
2172 fields = 3;
2173 else if (gimple_asm_ninputs (gs))
2174 fields = 2;
2175 else if (gimple_asm_noutputs (gs))
2176 fields = 1;
2177 else
2178 fields = 0;
2180 for (f = 0; f < fields; ++f)
2182 pp_string (buffer, " : ");
2184 switch (f)
2186 case 0:
2187 n = gimple_asm_noutputs (gs);
2188 for (i = 0; i < n; i++)
2190 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
2191 spc, flags, false);
2192 if (i < n - 1)
2193 pp_string (buffer, ", ");
2195 break;
2197 case 1:
2198 n = gimple_asm_ninputs (gs);
2199 for (i = 0; i < n; i++)
2201 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
2202 spc, flags, false);
2203 if (i < n - 1)
2204 pp_string (buffer, ", ");
2206 break;
2208 case 2:
2209 n = gimple_asm_nclobbers (gs);
2210 for (i = 0; i < n; i++)
2212 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
2213 spc, flags, false);
2214 if (i < n - 1)
2215 pp_string (buffer, ", ");
2217 break;
2219 case 3:
2220 n = gimple_asm_nlabels (gs);
2221 for (i = 0; i < n; i++)
2223 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
2224 spc, flags, false);
2225 if (i < n - 1)
2226 pp_string (buffer, ", ");
2228 break;
2230 default:
2231 gcc_unreachable ();
2235 pp_string (buffer, ");");
2239 /* Dump ptr_info and range_info for NODE on pretty_printer BUFFER with
2240 SPC spaces of indent. */
2242 static void
2243 dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
2245 if (TREE_CODE (node) != SSA_NAME)
2246 return;
2248 if (POINTER_TYPE_P (TREE_TYPE (node))
2249 && SSA_NAME_PTR_INFO (node))
2251 unsigned int align, misalign;
2252 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (node);
2253 pp_string (buffer, "# PT = ");
2254 pp_points_to_solution (buffer, &pi->pt);
2255 newline_and_indent (buffer, spc);
2256 if (get_ptr_info_alignment (pi, &align, &misalign))
2258 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u", align, misalign);
2259 newline_and_indent (buffer, spc);
2263 if (!POINTER_TYPE_P (TREE_TYPE (node))
2264 && SSA_NAME_RANGE_INFO (node))
2266 wide_int min, max, nonzero_bits;
2267 value_range r;
2269 get_global_range_query ()->range_of_expr (r, node);
2270 value_range_kind range_type = r.kind ();
2271 if (!r.undefined_p ())
2273 min = wi::to_wide (r.min ());
2274 max = wi::to_wide (r.max ());
2277 // FIXME: Use irange::dump() instead.
2278 if (range_type == VR_VARYING)
2279 pp_printf (buffer, "# RANGE VR_VARYING");
2280 else if (range_type == VR_RANGE || range_type == VR_ANTI_RANGE)
2282 pp_printf (buffer, "# RANGE ");
2283 pp_printf (buffer, "%s[", range_type == VR_RANGE ? "" : "~");
2284 pp_wide_int (buffer, min, TYPE_SIGN (TREE_TYPE (node)));
2285 pp_printf (buffer, ", ");
2286 pp_wide_int (buffer, max, TYPE_SIGN (TREE_TYPE (node)));
2287 pp_printf (buffer, "]");
2289 nonzero_bits = get_nonzero_bits (node);
2290 if (nonzero_bits != -1)
2292 pp_string (buffer, " NONZERO ");
2293 pp_wide_int (buffer, nonzero_bits, UNSIGNED);
2295 newline_and_indent (buffer, spc);
2299 /* As dump_ssaname_info, but dump to FILE. */
2301 void
2302 dump_ssaname_info_to_file (FILE *file, tree node, int spc)
2304 pretty_printer buffer;
2305 pp_needs_newline (&buffer) = true;
2306 buffer.buffer->stream = file;
2307 dump_ssaname_info (&buffer, node, spc);
2308 pp_flush (&buffer);
2311 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
2312 The caller is responsible for calling pp_flush on BUFFER to finalize
2313 pretty printer. If COMMENT is true, print this after #. */
2315 static void
2316 dump_gimple_phi (pretty_printer *buffer, const gphi *phi, int spc, bool comment,
2317 dump_flags_t flags)
2319 size_t i;
2320 tree lhs = gimple_phi_result (phi);
2322 if (flags & TDF_ALIAS)
2323 dump_ssaname_info (buffer, lhs, spc);
2325 if (comment)
2326 pp_string (buffer, "# ");
2328 if (flags & TDF_RAW)
2329 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
2330 gimple_phi_result (phi));
2331 else
2333 dump_generic_node (buffer, lhs, spc, flags, false);
2334 if (flags & TDF_GIMPLE)
2335 pp_string (buffer, " = __PHI (");
2336 else
2337 pp_string (buffer, " = PHI <");
2339 for (i = 0; i < gimple_phi_num_args (phi); i++)
2341 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
2342 dump_location (buffer, gimple_phi_arg_location (phi, i));
2343 basic_block src = gimple_phi_arg_edge (phi, i)->src;
2344 if (flags & TDF_GIMPLE)
2346 pp_string (buffer, "__BB");
2347 pp_decimal_int (buffer, src->index);
2348 pp_string (buffer, ": ");
2350 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
2351 false);
2352 if (! (flags & TDF_GIMPLE))
2354 pp_left_paren (buffer);
2355 pp_decimal_int (buffer, src->index);
2356 pp_right_paren (buffer);
2358 if (i < gimple_phi_num_args (phi) - 1)
2359 pp_string (buffer, ", ");
2361 if (flags & TDF_GIMPLE)
2362 pp_string (buffer, ");");
2363 else
2364 pp_greater (buffer);
2368 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
2369 of indent. FLAGS specifies details to show in the dump (see TDF_* in
2370 dumpfile.h). */
2372 static void
2373 dump_gimple_omp_parallel (pretty_printer *buffer, const gomp_parallel *gs,
2374 int spc, dump_flags_t flags)
2376 if (flags & TDF_RAW)
2378 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2379 gimple_omp_body (gs));
2380 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
2381 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
2382 gimple_omp_parallel_child_fn (gs),
2383 gimple_omp_parallel_data_arg (gs));
2385 else
2387 gimple_seq body;
2388 pp_string (buffer, "#pragma omp parallel");
2389 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
2390 if (gimple_omp_parallel_child_fn (gs))
2392 pp_string (buffer, " [child fn: ");
2393 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
2394 spc, flags, false);
2395 pp_string (buffer, " (");
2396 if (gimple_omp_parallel_data_arg (gs))
2397 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
2398 spc, flags, false);
2399 else
2400 pp_string (buffer, "???");
2401 pp_string (buffer, ")]");
2403 body = gimple_omp_body (gs);
2404 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2406 newline_and_indent (buffer, spc + 2);
2407 pp_left_brace (buffer);
2408 pp_newline (buffer);
2409 dump_gimple_seq (buffer, body, spc + 4, flags);
2410 newline_and_indent (buffer, spc + 2);
2411 pp_right_brace (buffer);
2413 else if (body)
2415 pp_newline (buffer);
2416 dump_gimple_seq (buffer, body, spc + 2, flags);
2422 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
2423 of indent. FLAGS specifies details to show in the dump (see TDF_* in
2424 dumpfile.h). */
2426 static void
2427 dump_gimple_omp_task (pretty_printer *buffer, const gomp_task *gs, int spc,
2428 dump_flags_t flags)
2430 if (flags & TDF_RAW)
2432 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2433 gimple_omp_body (gs));
2434 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2435 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
2436 gimple_omp_task_child_fn (gs),
2437 gimple_omp_task_data_arg (gs),
2438 gimple_omp_task_copy_fn (gs),
2439 gimple_omp_task_arg_size (gs),
2440 gimple_omp_task_arg_size (gs));
2442 else
2444 gimple_seq body;
2445 if (gimple_omp_task_taskloop_p (gs))
2446 pp_string (buffer, "#pragma omp taskloop");
2447 else if (gimple_omp_task_taskwait_p (gs))
2448 pp_string (buffer, "#pragma omp taskwait");
2449 else
2450 pp_string (buffer, "#pragma omp task");
2451 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2452 if (gimple_omp_task_child_fn (gs))
2454 pp_string (buffer, " [child fn: ");
2455 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
2456 spc, flags, false);
2457 pp_string (buffer, " (");
2458 if (gimple_omp_task_data_arg (gs))
2459 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
2460 spc, flags, false);
2461 else
2462 pp_string (buffer, "???");
2463 pp_string (buffer, ")]");
2465 body = gimple_omp_body (gs);
2466 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2468 newline_and_indent (buffer, spc + 2);
2469 pp_left_brace (buffer);
2470 pp_newline (buffer);
2471 dump_gimple_seq (buffer, body, spc + 4, flags);
2472 newline_and_indent (buffer, spc + 2);
2473 pp_right_brace (buffer);
2475 else if (body)
2477 pp_newline (buffer);
2478 dump_gimple_seq (buffer, body, spc + 2, flags);
2484 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
2485 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2486 in dumpfile.h). */
2488 static void
2489 dump_gimple_omp_atomic_load (pretty_printer *buffer, const gomp_atomic_load *gs,
2490 int spc, dump_flags_t flags)
2492 if (flags & TDF_RAW)
2494 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
2495 gimple_omp_atomic_load_lhs (gs),
2496 gimple_omp_atomic_load_rhs (gs));
2498 else
2500 pp_string (buffer, "#pragma omp atomic_load");
2501 dump_omp_atomic_memory_order (buffer,
2502 gimple_omp_atomic_memory_order (gs));
2503 if (gimple_omp_atomic_need_value_p (gs))
2504 pp_string (buffer, " [needed]");
2505 newline_and_indent (buffer, spc + 2);
2506 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
2507 spc, flags, false);
2508 pp_space (buffer);
2509 pp_equal (buffer);
2510 pp_space (buffer);
2511 pp_star (buffer);
2512 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
2513 spc, flags, false);
2517 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
2518 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2519 in dumpfile.h). */
2521 static void
2522 dump_gimple_omp_atomic_store (pretty_printer *buffer,
2523 const gomp_atomic_store *gs, int spc,
2524 dump_flags_t flags)
2526 if (flags & TDF_RAW)
2528 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
2529 gimple_omp_atomic_store_val (gs));
2531 else
2533 pp_string (buffer, "#pragma omp atomic_store");
2534 dump_omp_atomic_memory_order (buffer,
2535 gimple_omp_atomic_memory_order (gs));
2536 pp_space (buffer);
2537 if (gimple_omp_atomic_need_value_p (gs))
2538 pp_string (buffer, "[needed] ");
2539 pp_left_paren (buffer);
2540 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
2541 spc, flags, false);
2542 pp_right_paren (buffer);
2547 /* Dump all the memory operands for statement GS. BUFFER, SPC and
2548 FLAGS are as in pp_gimple_stmt_1. */
2550 static void
2551 dump_gimple_mem_ops (pretty_printer *buffer, const gimple *gs, int spc,
2552 dump_flags_t flags)
2554 tree vdef = gimple_vdef (gs);
2555 tree vuse = gimple_vuse (gs);
2557 if (vdef != NULL_TREE)
2559 pp_string (buffer, "# ");
2560 dump_generic_node (buffer, vdef, spc + 2, flags, false);
2561 pp_string (buffer, " = VDEF <");
2562 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2563 pp_greater (buffer);
2564 newline_and_indent (buffer, spc);
2566 else if (vuse != NULL_TREE)
2568 pp_string (buffer, "# VUSE <");
2569 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2570 pp_greater (buffer);
2571 newline_and_indent (buffer, spc);
2576 /* Print the gimple statement GS on the pretty printer BUFFER, SPC
2577 spaces of indent. FLAGS specifies details to show in the dump (see
2578 TDF_* in dumpfile.h). The caller is responsible for calling
2579 pp_flush on BUFFER to finalize the pretty printer. */
2581 void
2582 pp_gimple_stmt_1 (pretty_printer *buffer, const gimple *gs, int spc,
2583 dump_flags_t flags)
2585 if (!gs)
2586 return;
2588 if (flags & TDF_STMTADDR)
2589 pp_printf (buffer, "<&%p> ", (const void *) gs);
2591 if ((flags & TDF_LINENO) && gimple_has_location (gs))
2592 dump_location (buffer, gimple_location (gs));
2594 if (flags & TDF_EH)
2596 int lp_nr = lookup_stmt_eh_lp (gs);
2597 if (lp_nr > 0)
2598 pp_printf (buffer, "[LP %d] ", lp_nr);
2599 else if (lp_nr < 0)
2600 pp_printf (buffer, "[MNT %d] ", -lp_nr);
2603 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
2604 && gimple_has_mem_ops (gs))
2605 dump_gimple_mem_ops (buffer, gs, spc, flags);
2607 if (gimple_has_lhs (gs)
2608 && (flags & TDF_ALIAS))
2609 dump_ssaname_info (buffer, gimple_get_lhs (gs), spc);
2611 switch (gimple_code (gs))
2613 case GIMPLE_ASM:
2614 dump_gimple_asm (buffer, as_a <const gasm *> (gs), spc, flags);
2615 break;
2617 case GIMPLE_ASSIGN:
2618 dump_gimple_assign (buffer, as_a <const gassign *> (gs), spc, flags);
2619 break;
2621 case GIMPLE_BIND:
2622 dump_gimple_bind (buffer, as_a <const gbind *> (gs), spc, flags);
2623 break;
2625 case GIMPLE_CALL:
2626 dump_gimple_call (buffer, as_a <const gcall *> (gs), spc, flags);
2627 break;
2629 case GIMPLE_COND:
2630 dump_gimple_cond (buffer, as_a <const gcond *> (gs), spc, flags);
2631 break;
2633 case GIMPLE_LABEL:
2634 dump_gimple_label (buffer, as_a <const glabel *> (gs), spc, flags);
2635 break;
2637 case GIMPLE_GOTO:
2638 dump_gimple_goto (buffer, as_a <const ggoto *> (gs), spc, flags);
2639 break;
2641 case GIMPLE_NOP:
2642 pp_string (buffer, "GIMPLE_NOP");
2643 break;
2645 case GIMPLE_RETURN:
2646 dump_gimple_return (buffer, as_a <const greturn *> (gs), spc, flags);
2647 break;
2649 case GIMPLE_SWITCH:
2650 dump_gimple_switch (buffer, as_a <const gswitch *> (gs), spc, flags);
2651 break;
2653 case GIMPLE_TRY:
2654 dump_gimple_try (buffer, as_a <const gtry *> (gs), spc, flags);
2655 break;
2657 case GIMPLE_PHI:
2658 dump_gimple_phi (buffer, as_a <const gphi *> (gs), spc, false, flags);
2659 break;
2661 case GIMPLE_OMP_PARALLEL:
2662 dump_gimple_omp_parallel (buffer, as_a <const gomp_parallel *> (gs), spc,
2663 flags);
2664 break;
2666 case GIMPLE_OMP_TASK:
2667 dump_gimple_omp_task (buffer, as_a <const gomp_task *> (gs), spc, flags);
2668 break;
2670 case GIMPLE_OMP_ATOMIC_LOAD:
2671 dump_gimple_omp_atomic_load (buffer, as_a <const gomp_atomic_load *> (gs),
2672 spc, flags);
2673 break;
2675 case GIMPLE_OMP_ATOMIC_STORE:
2676 dump_gimple_omp_atomic_store (buffer,
2677 as_a <const gomp_atomic_store *> (gs),
2678 spc, flags);
2679 break;
2681 case GIMPLE_OMP_FOR:
2682 dump_gimple_omp_for (buffer, as_a <const gomp_for *> (gs), spc, flags);
2683 break;
2685 case GIMPLE_OMP_CONTINUE:
2686 dump_gimple_omp_continue (buffer, as_a <const gomp_continue *> (gs), spc,
2687 flags);
2688 break;
2690 case GIMPLE_OMP_SINGLE:
2691 dump_gimple_omp_single (buffer, as_a <const gomp_single *> (gs), spc,
2692 flags);
2693 break;
2695 case GIMPLE_OMP_TARGET:
2696 dump_gimple_omp_target (buffer, as_a <const gomp_target *> (gs), spc,
2697 flags);
2698 break;
2700 case GIMPLE_OMP_TEAMS:
2701 dump_gimple_omp_teams (buffer, as_a <const gomp_teams *> (gs), spc,
2702 flags);
2703 break;
2705 case GIMPLE_OMP_RETURN:
2706 dump_gimple_omp_return (buffer, gs, spc, flags);
2707 break;
2709 case GIMPLE_OMP_SECTIONS:
2710 dump_gimple_omp_sections (buffer, as_a <const gomp_sections *> (gs),
2711 spc, flags);
2712 break;
2714 case GIMPLE_OMP_SECTIONS_SWITCH:
2715 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
2716 break;
2718 case GIMPLE_OMP_TASKGROUP:
2719 dump_gimple_omp_taskgroup (buffer, gs, spc, flags);
2720 break;
2722 case GIMPLE_OMP_MASTER:
2723 case GIMPLE_OMP_SECTION:
2724 dump_gimple_omp_block (buffer, gs, spc, flags);
2725 break;
2727 case GIMPLE_OMP_ORDERED:
2728 dump_gimple_omp_ordered (buffer, as_a <const gomp_ordered *> (gs), spc,
2729 flags);
2730 break;
2732 case GIMPLE_OMP_SCAN:
2733 dump_gimple_omp_scan (buffer, as_a <const gomp_scan *> (gs), spc,
2734 flags);
2735 break;
2737 case GIMPLE_OMP_CRITICAL:
2738 dump_gimple_omp_critical (buffer, as_a <const gomp_critical *> (gs), spc,
2739 flags);
2740 break;
2742 case GIMPLE_CATCH:
2743 dump_gimple_catch (buffer, as_a <const gcatch *> (gs), spc, flags);
2744 break;
2746 case GIMPLE_EH_FILTER:
2747 dump_gimple_eh_filter (buffer, as_a <const geh_filter *> (gs), spc,
2748 flags);
2749 break;
2751 case GIMPLE_EH_MUST_NOT_THROW:
2752 dump_gimple_eh_must_not_throw (buffer,
2753 as_a <const geh_mnt *> (gs),
2754 spc, flags);
2755 break;
2757 case GIMPLE_EH_ELSE:
2758 dump_gimple_eh_else (buffer, as_a <const geh_else *> (gs), spc, flags);
2759 break;
2761 case GIMPLE_RESX:
2762 dump_gimple_resx (buffer, as_a <const gresx *> (gs), spc, flags);
2763 break;
2765 case GIMPLE_EH_DISPATCH:
2766 dump_gimple_eh_dispatch (buffer, as_a <const geh_dispatch *> (gs), spc,
2767 flags);
2768 break;
2770 case GIMPLE_DEBUG:
2771 dump_gimple_debug (buffer, as_a <const gdebug *> (gs), spc, flags);
2772 break;
2774 case GIMPLE_PREDICT:
2775 pp_string (buffer, "// predicted ");
2776 if (gimple_predict_outcome (gs))
2777 pp_string (buffer, "likely by ");
2778 else
2779 pp_string (buffer, "unlikely by ");
2780 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
2781 pp_string (buffer, " predictor.");
2782 break;
2784 case GIMPLE_TRANSACTION:
2785 dump_gimple_transaction (buffer, as_a <const gtransaction *> (gs), spc,
2786 flags);
2787 break;
2789 default:
2790 GIMPLE_NIY;
2795 /* Dumps header of basic block BB to OUTF indented by INDENT
2796 spaces and details described by flags. */
2798 static void
2799 dump_gimple_bb_header (FILE *outf, basic_block bb, int indent,
2800 dump_flags_t flags)
2802 if (flags & TDF_BLOCKS)
2804 if (flags & TDF_LINENO)
2806 gimple_stmt_iterator gsi;
2808 fputs (";; ", outf);
2810 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2811 if (!is_gimple_debug (gsi_stmt (gsi))
2812 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
2814 fprintf (outf, "%*sstarting at line %d",
2815 indent, "", get_lineno (gsi_stmt (gsi)));
2816 break;
2818 if (bb->discriminator)
2819 fprintf (outf, ", discriminator %i", bb->discriminator);
2820 fputc ('\n', outf);
2823 else
2825 if (flags & TDF_GIMPLE)
2827 fprintf (outf, "%*s__BB(%d", indent, "", bb->index);
2828 if (bb->loop_father->header == bb)
2829 fprintf (outf, ",loop_header(%d)", bb->loop_father->num);
2830 if (bb->count.initialized_p ())
2831 fprintf (outf, ",%s(%d)",
2832 profile_quality_as_string (bb->count.quality ()),
2833 bb->count.value ());
2834 fprintf (outf, "):\n");
2836 else
2837 fprintf (outf, "%*s<bb %d> %s:\n",
2838 indent, "", bb->index, dump_profile (bb->count));
2843 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2844 spaces. */
2846 static void
2847 dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
2848 basic_block bb ATTRIBUTE_UNUSED,
2849 int indent ATTRIBUTE_UNUSED,
2850 dump_flags_t flags ATTRIBUTE_UNUSED)
2852 /* There is currently no GIMPLE-specific basic block info to dump. */
2853 return;
2857 /* Dump PHI nodes of basic block BB to BUFFER with details described
2858 by FLAGS and indented by INDENT spaces. */
2860 static void
2861 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent,
2862 dump_flags_t flags)
2864 gphi_iterator i;
2866 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2868 gphi *phi = i.phi ();
2869 if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2871 INDENT (indent);
2872 dump_gimple_phi (buffer, phi, indent,
2873 (flags & TDF_GIMPLE) ? false : true, flags);
2874 pp_newline (buffer);
2880 /* Dump jump to basic block BB that is represented implicitly in the cfg
2881 to BUFFER. */
2883 static void
2884 pp_cfg_jump (pretty_printer *buffer, edge e, dump_flags_t flags)
2886 if (flags & TDF_GIMPLE)
2888 pp_string (buffer, "goto __BB");
2889 pp_decimal_int (buffer, e->dest->index);
2890 if (e->probability.initialized_p ())
2892 pp_string (buffer, "(");
2893 pp_string (buffer,
2894 profile_quality_as_string (e->probability.quality ()));
2895 pp_string (buffer, "(");
2896 pp_decimal_int (buffer, e->probability.value ());
2897 pp_string (buffer, "))");
2899 pp_semicolon (buffer);
2901 else
2903 pp_string (buffer, "goto <bb ");
2904 pp_decimal_int (buffer, e->dest->index);
2905 pp_greater (buffer);
2906 pp_semicolon (buffer);
2908 dump_edge_probability (buffer, e);
2913 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2914 by INDENT spaces, with details given by FLAGS. */
2916 static void
2917 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2918 dump_flags_t flags)
2920 edge e;
2921 gimple *stmt;
2923 stmt = last_stmt (bb);
2925 if (stmt && gimple_code (stmt) == GIMPLE_COND)
2927 edge true_edge, false_edge;
2929 /* When we are emitting the code or changing CFG, it is possible that
2930 the edges are not yet created. When we are using debug_bb in such
2931 a situation, we do not want it to crash. */
2932 if (EDGE_COUNT (bb->succs) != 2)
2933 return;
2934 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2936 INDENT (indent + 2);
2937 pp_cfg_jump (buffer, true_edge, flags);
2938 newline_and_indent (buffer, indent);
2939 pp_string (buffer, "else");
2940 newline_and_indent (buffer, indent + 2);
2941 pp_cfg_jump (buffer, false_edge, flags);
2942 pp_newline (buffer);
2943 return;
2946 /* If there is a fallthru edge, we may need to add an artificial
2947 goto to the dump. */
2948 e = find_fallthru_edge (bb->succs);
2950 if (e && (e->dest != bb->next_bb || (flags & TDF_GIMPLE)))
2952 INDENT (indent);
2954 if ((flags & TDF_LINENO)
2955 && e->goto_locus != UNKNOWN_LOCATION)
2956 dump_location (buffer, e->goto_locus);
2958 pp_cfg_jump (buffer, e, flags);
2959 pp_newline (buffer);
2964 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2965 indented by INDENT spaces. */
2967 static void
2968 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2969 dump_flags_t flags)
2971 gimple_stmt_iterator gsi;
2972 gimple *stmt;
2973 int label_indent = indent - 2;
2975 if (label_indent < 0)
2976 label_indent = 0;
2978 dump_phi_nodes (buffer, bb, indent, flags);
2980 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2982 int curr_indent;
2984 stmt = gsi_stmt (gsi);
2986 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2988 INDENT (curr_indent);
2989 pp_gimple_stmt_1 (buffer, stmt, curr_indent, flags);
2990 pp_newline_and_flush (buffer);
2991 gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl));
2992 dump_histograms_for_stmt (DECL_STRUCT_FUNCTION (current_function_decl),
2993 pp_buffer (buffer)->stream, stmt);
2996 dump_implicit_edges (buffer, bb, indent, flags);
2997 pp_flush (buffer);
3001 /* Dumps basic block BB to FILE with details described by FLAGS and
3002 indented by INDENT spaces. */
3004 void
3005 gimple_dump_bb (FILE *file, basic_block bb, int indent, dump_flags_t flags)
3007 dump_gimple_bb_header (file, bb, indent, flags);
3008 if (bb->index >= NUM_FIXED_BLOCKS)
3010 pretty_printer buffer;
3011 pp_needs_newline (&buffer) = true;
3012 buffer.buffer->stream = file;
3013 gimple_dump_bb_buff (&buffer, bb, indent, flags);
3015 dump_gimple_bb_footer (file, bb, indent, flags);
3018 /* Dumps basic block BB to pretty-printer PP with default dump flags and
3019 no indentation, for use as a label of a DOT graph record-node.
3020 ??? Should just use gimple_dump_bb_buff here, except that value profiling
3021 histogram dumping doesn't know about pretty-printers. */
3023 void
3024 gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
3026 pp_printf (pp, "<bb %d>:\n", bb->index);
3027 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
3029 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
3030 gsi_next (&gsi))
3032 gphi *phi = gsi.phi ();
3033 if (!virtual_operand_p (gimple_phi_result (phi))
3034 || (dump_flags & TDF_VOPS))
3036 pp_bar (pp);
3037 pp_write_text_to_stream (pp);
3038 pp_string (pp, "# ");
3039 pp_gimple_stmt_1 (pp, phi, 0, dump_flags);
3040 pp_newline (pp);
3041 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
3045 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
3046 gsi_next (&gsi))
3048 gimple *stmt = gsi_stmt (gsi);
3049 pp_bar (pp);
3050 pp_write_text_to_stream (pp);
3051 pp_gimple_stmt_1 (pp, stmt, 0, dump_flags);
3052 pp_newline (pp);
3053 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
3055 dump_implicit_edges (pp, bb, 0, dump_flags);
3056 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
3060 /* Handle the %G format for TEXT. Same as %K in handle_K_format in
3061 tree-pretty-print.c but with a Gimple statement as an argument. */
3063 void
3064 percent_G_format (text_info *text)
3066 gimple *stmt = va_arg (*text->args_ptr, gimple*);
3068 /* Fall back on the rich location if the statement doesn't have one. */
3069 location_t loc = gimple_location (stmt);
3070 if (loc == UNKNOWN_LOCATION)
3071 loc = text->m_richloc->get_loc ();
3072 tree block = gimple_block (stmt);
3073 percent_K_format (text, loc, block);
3076 #if __GNUC__ >= 10
3077 # pragma GCC diagnostic pop
3078 #endif