svn merge -r215707:216846 svn+ssh://gcc.gnu.org/svn/gcc/trunk
[official-gcc.git] / gcc / gimple-pretty-print.c
blob861529ec3e7a1313dcab2e99f325dbdeda3e2a67
1 /* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001-2014 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 "tm.h"
26 #include "tree.h"
27 #include "stringpool.h"
28 #include "diagnostic.h"
29 #include "gimple-pretty-print.h"
30 #include "hashtab.h"
31 #include "bitmap.h"
32 #include "predict.h"
33 #include "vec.h"
34 #include "hash-set.h"
35 #include "machmode.h"
36 #include "hard-reg-set.h"
37 #include "input.h"
38 #include "function.h"
39 #include "basic-block.h"
40 #include "tree-ssa-alias.h"
41 #include "internal-fn.h"
42 #include "tree-eh.h"
43 #include "gimple-expr.h"
44 #include "is-a.h"
45 #include "gimple.h"
46 #include "gimple-iterator.h"
47 #include "gimple-ssa.h"
48 #include "hash-map.h"
49 #include "plugin-api.h"
50 #include "ipa-ref.h"
51 #include "cgraph.h"
52 #include "tree-cfg.h"
53 #include "tree-ssanames.h"
54 #include "dumpfile.h" /* for dump_flags */
55 #include "value-prof.h"
56 #include "trans-mem.h"
58 #define INDENT(SPACE) \
59 do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
61 #define GIMPLE_NIY do_niy (buffer,gs)
63 /* Try to print on BUFFER a default message for the unrecognized
64 gimple statement GS. */
66 static void
67 do_niy (pretty_printer *buffer, gimple gs)
69 pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
70 gimple_code_name[(int) gimple_code (gs)]);
74 /* Emit a newline and SPC indentation spaces to BUFFER. */
76 static void
77 newline_and_indent (pretty_printer *buffer, int spc)
79 pp_newline (buffer);
80 INDENT (spc);
84 /* Print the GIMPLE statement GS on stderr. */
86 DEBUG_FUNCTION void
87 debug_gimple_stmt (gimple gs)
89 print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
93 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
94 FLAGS as in pp_gimple_stmt_1. */
96 void
97 print_gimple_stmt (FILE *file, gimple g, int spc, int flags)
99 pretty_printer buffer;
100 pp_needs_newline (&buffer) = true;
101 buffer.buffer->stream = file;
102 pp_gimple_stmt_1 (&buffer, g, spc, flags);
103 pp_newline_and_flush (&buffer);
106 DEBUG_FUNCTION void
107 debug (gimple_statement_base &ref)
109 print_gimple_stmt (stderr, &ref, 0, 0);
112 DEBUG_FUNCTION void
113 debug (gimple_statement_base *ptr)
115 if (ptr)
116 debug (*ptr);
117 else
118 fprintf (stderr, "<nil>\n");
122 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
123 FLAGS as in pp_gimple_stmt_1. Print only the right-hand side
124 of the statement. */
126 void
127 print_gimple_expr (FILE *file, gimple g, int spc, int flags)
129 flags |= TDF_RHS_ONLY;
130 pretty_printer buffer;
131 pp_needs_newline (&buffer) = true;
132 buffer.buffer->stream = file;
133 pp_gimple_stmt_1 (&buffer, g, spc, flags);
134 pp_flush (&buffer);
138 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentation
139 spaces and FLAGS as in pp_gimple_stmt_1.
140 The caller is responsible for calling pp_flush on BUFFER to finalize
141 the pretty printer. */
143 static void
144 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc, int flags)
146 gimple_stmt_iterator i;
148 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
150 gimple gs = gsi_stmt (i);
151 INDENT (spc);
152 pp_gimple_stmt_1 (buffer, gs, spc, flags);
153 if (!gsi_one_before_end_p (i))
154 pp_newline (buffer);
159 /* Print GIMPLE sequence SEQ to FILE using SPC indentation spaces and
160 FLAGS as in pp_gimple_stmt_1. */
162 void
163 print_gimple_seq (FILE *file, gimple_seq seq, int spc, int flags)
165 pretty_printer buffer;
166 pp_needs_newline (&buffer) = true;
167 buffer.buffer->stream = file;
168 dump_gimple_seq (&buffer, seq, spc, flags);
169 pp_newline_and_flush (&buffer);
173 /* Print the GIMPLE sequence SEQ on stderr. */
175 DEBUG_FUNCTION void
176 debug_gimple_seq (gimple_seq seq)
178 print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
182 /* A simple helper to pretty-print some of the gimple tuples in the printf
183 style. The format modifiers are preceded by '%' and are:
184 'G' - outputs a string corresponding to the code of the given gimple,
185 'S' - outputs a gimple_seq with indent of spc + 2,
186 'T' - outputs the tree t,
187 'd' - outputs an int as a decimal,
188 's' - outputs a string,
189 'n' - outputs a newline,
190 'x' - outputs an int as hexadecimal,
191 '+' - increases indent by 2 then outputs a newline,
192 '-' - decreases indent by 2 then outputs a newline. */
194 static void
195 dump_gimple_fmt (pretty_printer *buffer, int spc, int flags,
196 const char *fmt, ...)
198 va_list args;
199 const char *c;
200 const char *tmp;
202 va_start (args, fmt);
203 for (c = fmt; *c; c++)
205 if (*c == '%')
207 gimple_seq seq;
208 tree t;
209 gimple g;
210 switch (*++c)
212 case 'G':
213 g = va_arg (args, gimple);
214 tmp = gimple_code_name[gimple_code (g)];
215 pp_string (buffer, tmp);
216 break;
218 case 'S':
219 seq = va_arg (args, gimple_seq);
220 pp_newline (buffer);
221 dump_gimple_seq (buffer, seq, spc + 2, flags);
222 newline_and_indent (buffer, spc);
223 break;
225 case 'T':
226 t = va_arg (args, tree);
227 if (t == NULL_TREE)
228 pp_string (buffer, "NULL");
229 else
230 dump_generic_node (buffer, t, spc, flags, false);
231 break;
233 case 'd':
234 pp_decimal_int (buffer, va_arg (args, int));
235 break;
237 case 's':
238 pp_string (buffer, va_arg (args, char *));
239 break;
241 case 'n':
242 newline_and_indent (buffer, spc);
243 break;
245 case 'x':
246 pp_scalar (buffer, "%x", va_arg (args, int));
247 break;
249 case '+':
250 spc += 2;
251 newline_and_indent (buffer, spc);
252 break;
254 case '-':
255 spc -= 2;
256 newline_and_indent (buffer, spc);
257 break;
259 default:
260 gcc_unreachable ();
263 else
264 pp_character (buffer, *c);
266 va_end (args);
270 /* Helper for dump_gimple_assign. Print the unary RHS of the
271 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
273 static void
274 dump_unary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
276 enum tree_code rhs_code = gimple_assign_rhs_code (gs);
277 tree lhs = gimple_assign_lhs (gs);
278 tree rhs = gimple_assign_rhs1 (gs);
280 switch (rhs_code)
282 case VIEW_CONVERT_EXPR:
283 case ASSERT_EXPR:
284 dump_generic_node (buffer, rhs, spc, flags, false);
285 break;
287 case FIXED_CONVERT_EXPR:
288 case ADDR_SPACE_CONVERT_EXPR:
289 case FIX_TRUNC_EXPR:
290 case FLOAT_EXPR:
291 CASE_CONVERT:
292 pp_left_paren (buffer);
293 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
294 pp_string (buffer, ") ");
295 if (op_prio (rhs) < op_code_prio (rhs_code))
297 pp_left_paren (buffer);
298 dump_generic_node (buffer, rhs, spc, flags, false);
299 pp_right_paren (buffer);
301 else
302 dump_generic_node (buffer, rhs, spc, flags, false);
303 break;
305 case PAREN_EXPR:
306 pp_string (buffer, "((");
307 dump_generic_node (buffer, rhs, spc, flags, false);
308 pp_string (buffer, "))");
309 break;
311 case ABS_EXPR:
312 pp_string (buffer, "ABS_EXPR <");
313 dump_generic_node (buffer, rhs, spc, flags, false);
314 pp_greater (buffer);
315 break;
317 default:
318 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
319 || TREE_CODE_CLASS (rhs_code) == tcc_constant
320 || TREE_CODE_CLASS (rhs_code) == tcc_reference
321 || rhs_code == SSA_NAME
322 || rhs_code == ADDR_EXPR
323 || rhs_code == CONSTRUCTOR)
325 dump_generic_node (buffer, rhs, spc, flags, false);
326 break;
328 else if (rhs_code == BIT_NOT_EXPR)
329 pp_complement (buffer);
330 else if (rhs_code == TRUTH_NOT_EXPR)
331 pp_exclamation (buffer);
332 else if (rhs_code == NEGATE_EXPR)
333 pp_minus (buffer);
334 else
336 pp_left_bracket (buffer);
337 pp_string (buffer, get_tree_code_name (rhs_code));
338 pp_string (buffer, "] ");
341 if (op_prio (rhs) < op_code_prio (rhs_code))
343 pp_left_paren (buffer);
344 dump_generic_node (buffer, rhs, spc, flags, false);
345 pp_right_paren (buffer);
347 else
348 dump_generic_node (buffer, rhs, spc, flags, false);
349 break;
354 /* Helper for dump_gimple_assign. Print the binary RHS of the
355 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
357 static void
358 dump_binary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
360 const char *p;
361 enum tree_code code = gimple_assign_rhs_code (gs);
362 switch (code)
364 case COMPLEX_EXPR:
365 case MIN_EXPR:
366 case MAX_EXPR:
367 case VEC_WIDEN_MULT_HI_EXPR:
368 case VEC_WIDEN_MULT_LO_EXPR:
369 case VEC_WIDEN_MULT_EVEN_EXPR:
370 case VEC_WIDEN_MULT_ODD_EXPR:
371 case VEC_PACK_TRUNC_EXPR:
372 case VEC_PACK_SAT_EXPR:
373 case VEC_PACK_FIX_TRUNC_EXPR:
374 case VEC_WIDEN_LSHIFT_HI_EXPR:
375 case VEC_WIDEN_LSHIFT_LO_EXPR:
376 for (p = get_tree_code_name (code); *p; p++)
377 pp_character (buffer, TOUPPER (*p));
378 pp_string (buffer, " <");
379 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
380 pp_string (buffer, ", ");
381 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
382 pp_greater (buffer);
383 break;
385 default:
386 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
388 pp_left_paren (buffer);
389 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
390 false);
391 pp_right_paren (buffer);
393 else
394 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
395 pp_space (buffer);
396 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
397 pp_space (buffer);
398 if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
400 pp_left_paren (buffer);
401 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
402 false);
403 pp_right_paren (buffer);
405 else
406 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
410 /* Helper for dump_gimple_assign. Print the ternary RHS of the
411 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
413 static void
414 dump_ternary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
416 const char *p;
417 enum tree_code code = gimple_assign_rhs_code (gs);
418 switch (code)
420 case WIDEN_MULT_PLUS_EXPR:
421 case WIDEN_MULT_MINUS_EXPR:
422 for (p = get_tree_code_name (code); *p; p++)
423 pp_character (buffer, TOUPPER (*p));
424 pp_string (buffer, " <");
425 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
426 pp_string (buffer, ", ");
427 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
428 pp_string (buffer, ", ");
429 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
430 pp_greater (buffer);
431 break;
433 case FMA_EXPR:
434 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
435 pp_string (buffer, " * ");
436 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
437 pp_string (buffer, " + ");
438 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
439 break;
441 case DOT_PROD_EXPR:
442 pp_string (buffer, "DOT_PROD_EXPR <");
443 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
444 pp_string (buffer, ", ");
445 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
446 pp_string (buffer, ", ");
447 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
448 pp_greater (buffer);
449 break;
451 case SAD_EXPR:
452 pp_string (buffer, "SAD_EXPR <");
453 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
454 pp_string (buffer, ", ");
455 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
456 pp_string (buffer, ", ");
457 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
458 pp_greater (buffer);
459 break;
461 case VEC_PERM_EXPR:
462 pp_string (buffer, "VEC_PERM_EXPR <");
463 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
464 pp_string (buffer, ", ");
465 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
466 pp_string (buffer, ", ");
467 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
468 pp_greater (buffer);
469 break;
471 case REALIGN_LOAD_EXPR:
472 pp_string (buffer, "REALIGN_LOAD <");
473 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
474 pp_string (buffer, ", ");
475 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
476 pp_string (buffer, ", ");
477 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
478 pp_greater (buffer);
479 break;
481 case COND_EXPR:
482 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
483 pp_string (buffer, " ? ");
484 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
485 pp_string (buffer, " : ");
486 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
487 break;
489 case VEC_COND_EXPR:
490 pp_string (buffer, "VEC_COND_EXPR <");
491 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
492 pp_string (buffer, ", ");
493 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
494 pp_string (buffer, ", ");
495 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
496 pp_greater (buffer);
497 break;
499 default:
500 gcc_unreachable ();
505 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
506 pp_gimple_stmt_1. */
508 static void
509 dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
511 if (flags & TDF_RAW)
513 tree arg1 = NULL;
514 tree arg2 = NULL;
515 tree arg3 = NULL;
516 switch (gimple_num_ops (gs))
518 case 4:
519 arg3 = gimple_assign_rhs3 (gs);
520 case 3:
521 arg2 = gimple_assign_rhs2 (gs);
522 case 2:
523 arg1 = gimple_assign_rhs1 (gs);
524 break;
525 default:
526 gcc_unreachable ();
529 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
530 get_tree_code_name (gimple_assign_rhs_code (gs)),
531 gimple_assign_lhs (gs), arg1, arg2, arg3);
533 else
535 if (!(flags & TDF_RHS_ONLY))
537 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
538 pp_space (buffer);
539 pp_equal (buffer);
541 if (gimple_assign_nontemporal_move_p (gs))
542 pp_string (buffer, "{nt}");
544 if (gimple_has_volatile_ops (gs))
545 pp_string (buffer, "{v}");
547 pp_space (buffer);
550 if (gimple_num_ops (gs) == 2)
551 dump_unary_rhs (buffer, gs, spc, flags);
552 else if (gimple_num_ops (gs) == 3)
553 dump_binary_rhs (buffer, gs, spc, flags);
554 else if (gimple_num_ops (gs) == 4)
555 dump_ternary_rhs (buffer, gs, spc, flags);
556 else
557 gcc_unreachable ();
558 if (!(flags & TDF_RHS_ONLY))
559 pp_semicolon (buffer);
564 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
565 pp_gimple_stmt_1. */
567 static void
568 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
570 tree t;
572 t = gimple_return_retval (gs);
573 if (flags & TDF_RAW)
574 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
575 else
577 pp_string (buffer, "return");
578 if (t)
580 pp_space (buffer);
581 dump_generic_node (buffer, t, spc, flags, false);
583 pp_semicolon (buffer);
588 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
589 dump_gimple_call. */
591 static void
592 dump_gimple_call_args (pretty_printer *buffer, gimple gs, int flags)
594 size_t i;
596 for (i = 0; i < gimple_call_num_args (gs); i++)
598 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
599 if (i < gimple_call_num_args (gs) - 1)
600 pp_string (buffer, ", ");
603 if (gimple_call_va_arg_pack_p (gs))
605 if (gimple_call_num_args (gs) > 0)
607 pp_comma (buffer);
608 pp_space (buffer);
611 pp_string (buffer, "__builtin_va_arg_pack ()");
615 /* Dump the points-to solution *PT to BUFFER. */
617 static void
618 pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
620 if (pt->anything)
622 pp_string (buffer, "anything ");
623 return;
625 if (pt->nonlocal)
626 pp_string (buffer, "nonlocal ");
627 if (pt->escaped)
628 pp_string (buffer, "escaped ");
629 if (pt->ipa_escaped)
630 pp_string (buffer, "unit-escaped ");
631 if (pt->null)
632 pp_string (buffer, "null ");
633 if (pt->vars
634 && !bitmap_empty_p (pt->vars))
636 bitmap_iterator bi;
637 unsigned i;
638 pp_string (buffer, "{ ");
639 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
641 pp_string (buffer, "D.");
642 pp_decimal_int (buffer, i);
643 pp_space (buffer);
645 pp_right_brace (buffer);
646 if (pt->vars_contains_nonlocal
647 && pt->vars_contains_escaped_heap)
648 pp_string (buffer, " (nonlocal, escaped heap)");
649 else if (pt->vars_contains_nonlocal
650 && pt->vars_contains_escaped)
651 pp_string (buffer, " (nonlocal, escaped)");
652 else if (pt->vars_contains_nonlocal)
653 pp_string (buffer, " (nonlocal)");
654 else if (pt->vars_contains_escaped_heap)
655 pp_string (buffer, " (escaped heap)");
656 else if (pt->vars_contains_escaped)
657 pp_string (buffer, " (escaped)");
661 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
662 pp_gimple_stmt_1. */
664 static void
665 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
667 tree lhs = gimple_call_lhs (gs);
668 tree fn = gimple_call_fn (gs);
670 if (flags & TDF_ALIAS)
672 struct pt_solution *pt;
673 pt = gimple_call_use_set (gs);
674 if (!pt_solution_empty_p (pt))
676 pp_string (buffer, "# USE = ");
677 pp_points_to_solution (buffer, pt);
678 newline_and_indent (buffer, spc);
680 pt = gimple_call_clobber_set (gs);
681 if (!pt_solution_empty_p (pt))
683 pp_string (buffer, "# CLB = ");
684 pp_points_to_solution (buffer, pt);
685 newline_and_indent (buffer, spc);
689 if (flags & TDF_RAW)
691 if (gimple_call_internal_p (gs))
692 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T", gs,
693 internal_fn_name (gimple_call_internal_fn (gs)), lhs);
694 else
695 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T", gs, fn, lhs);
696 if (gimple_call_num_args (gs) > 0)
698 pp_string (buffer, ", ");
699 dump_gimple_call_args (buffer, gs, flags);
701 pp_greater (buffer);
703 else
705 if (lhs && !(flags & TDF_RHS_ONLY))
707 dump_generic_node (buffer, lhs, spc, flags, false);
708 pp_string (buffer, " =");
710 if (gimple_has_volatile_ops (gs))
711 pp_string (buffer, "{v}");
713 pp_space (buffer);
715 if (gimple_call_internal_p (gs))
716 pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
717 else
718 print_call_name (buffer, fn, flags);
719 pp_string (buffer, " (");
720 dump_gimple_call_args (buffer, gs, flags);
721 pp_right_paren (buffer);
722 if (!(flags & TDF_RHS_ONLY))
723 pp_semicolon (buffer);
726 if (gimple_call_chain (gs))
728 pp_string (buffer, " [static-chain: ");
729 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
730 pp_right_bracket (buffer);
733 if (gimple_call_return_slot_opt_p (gs))
734 pp_string (buffer, " [return slot optimization]");
735 if (gimple_call_tail_p (gs))
736 pp_string (buffer, " [tail call]");
738 if (fn == NULL)
739 return;
741 /* Dump the arguments of _ITM_beginTransaction sanely. */
742 if (TREE_CODE (fn) == ADDR_EXPR)
743 fn = TREE_OPERAND (fn, 0);
744 if (TREE_CODE (fn) == FUNCTION_DECL && decl_is_tm_clone (fn))
745 pp_string (buffer, " [tm-clone]");
746 if (TREE_CODE (fn) == FUNCTION_DECL
747 && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
748 && DECL_FUNCTION_CODE (fn) == BUILT_IN_TM_START
749 && gimple_call_num_args (gs) > 0)
751 tree t = gimple_call_arg (gs, 0);
752 unsigned HOST_WIDE_INT props;
753 gcc_assert (TREE_CODE (t) == INTEGER_CST);
755 pp_string (buffer, " [ ");
757 /* Get the transaction code properties. */
758 props = TREE_INT_CST_LOW (t);
760 if (props & PR_INSTRUMENTEDCODE)
761 pp_string (buffer, "instrumentedCode ");
762 if (props & PR_UNINSTRUMENTEDCODE)
763 pp_string (buffer, "uninstrumentedCode ");
764 if (props & PR_HASNOXMMUPDATE)
765 pp_string (buffer, "hasNoXMMUpdate ");
766 if (props & PR_HASNOABORT)
767 pp_string (buffer, "hasNoAbort ");
768 if (props & PR_HASNOIRREVOCABLE)
769 pp_string (buffer, "hasNoIrrevocable ");
770 if (props & PR_DOESGOIRREVOCABLE)
771 pp_string (buffer, "doesGoIrrevocable ");
772 if (props & PR_HASNOSIMPLEREADS)
773 pp_string (buffer, "hasNoSimpleReads ");
774 if (props & PR_AWBARRIERSOMITTED)
775 pp_string (buffer, "awBarriersOmitted ");
776 if (props & PR_RARBARRIERSOMITTED)
777 pp_string (buffer, "RaRBarriersOmitted ");
778 if (props & PR_UNDOLOGCODE)
779 pp_string (buffer, "undoLogCode ");
780 if (props & PR_PREFERUNINSTRUMENTED)
781 pp_string (buffer, "preferUninstrumented ");
782 if (props & PR_EXCEPTIONBLOCK)
783 pp_string (buffer, "exceptionBlock ");
784 if (props & PR_HASELSE)
785 pp_string (buffer, "hasElse ");
786 if (props & PR_READONLY)
787 pp_string (buffer, "readOnly ");
789 pp_right_bracket (buffer);
794 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
795 pp_gimple_stmt_1. */
797 static void
798 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
800 unsigned int i;
802 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
803 if (flags & TDF_RAW)
804 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
805 gimple_switch_index (gs));
806 else
808 pp_string (buffer, "switch (");
809 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
810 pp_string (buffer, ") <");
813 for (i = 0; i < gimple_switch_num_labels (gs); i++)
815 tree case_label = gimple_switch_label (gs, i);
816 gcc_checking_assert (case_label != NULL_TREE);
817 dump_generic_node (buffer, case_label, spc, flags, false);
818 pp_space (buffer);
819 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
820 if (i < gimple_switch_num_labels (gs) - 1)
821 pp_string (buffer, ", ");
823 pp_greater (buffer);
827 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
828 pp_gimple_stmt_1. */
830 static void
831 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
833 if (flags & TDF_RAW)
834 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
835 get_tree_code_name (gimple_cond_code (gs)),
836 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
837 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
838 else
840 if (!(flags & TDF_RHS_ONLY))
841 pp_string (buffer, "if (");
842 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
843 pp_space (buffer);
844 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
845 pp_space (buffer);
846 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
847 if (!(flags & TDF_RHS_ONLY))
849 pp_right_paren (buffer);
851 if (gimple_cond_true_label (gs))
853 pp_string (buffer, " goto ");
854 dump_generic_node (buffer, gimple_cond_true_label (gs),
855 spc, flags, false);
856 pp_semicolon (buffer);
858 if (gimple_cond_false_label (gs))
860 pp_string (buffer, " else goto ");
861 dump_generic_node (buffer, gimple_cond_false_label (gs),
862 spc, flags, false);
863 pp_semicolon (buffer);
870 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
871 spaces of indent. FLAGS specifies details to show in the dump (see
872 TDF_* in dumpfils.h). */
874 static void
875 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
877 tree label = gimple_label_label (gs);
878 if (flags & TDF_RAW)
879 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
880 else
882 dump_generic_node (buffer, label, spc, flags, false);
883 pp_colon (buffer);
885 if (DECL_NONLOCAL (label))
886 pp_string (buffer, " [non-local]");
887 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
888 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
891 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
892 spaces of indent. FLAGS specifies details to show in the dump (see
893 TDF_* in dumpfile.h). */
895 static void
896 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
898 tree label = gimple_goto_dest (gs);
899 if (flags & TDF_RAW)
900 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
901 else
902 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
906 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
907 spaces of indent. FLAGS specifies details to show in the dump (see
908 TDF_* in dumpfile.h). */
910 static void
911 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
913 if (flags & TDF_RAW)
914 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
915 else
916 pp_left_brace (buffer);
917 if (!(flags & TDF_SLIM))
919 tree var;
921 for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
923 newline_and_indent (buffer, 2);
924 print_declaration (buffer, var, spc, flags);
926 if (gimple_bind_vars (gs))
927 pp_newline (buffer);
929 pp_newline (buffer);
930 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
931 newline_and_indent (buffer, spc);
932 if (flags & TDF_RAW)
933 pp_greater (buffer);
934 else
935 pp_right_brace (buffer);
939 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
940 indent. FLAGS specifies details to show in the dump (see TDF_* in
941 dumpfile.h). */
943 static void
944 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
946 if (flags & TDF_RAW)
948 const char *type;
949 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
950 type = "GIMPLE_TRY_CATCH";
951 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
952 type = "GIMPLE_TRY_FINALLY";
953 else
954 type = "UNKNOWN GIMPLE_TRY";
955 dump_gimple_fmt (buffer, spc, flags,
956 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
957 gimple_try_eval (gs), gimple_try_cleanup (gs));
959 else
961 pp_string (buffer, "try");
962 newline_and_indent (buffer, spc + 2);
963 pp_left_brace (buffer);
964 pp_newline (buffer);
966 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
967 newline_and_indent (buffer, spc + 2);
968 pp_right_brace (buffer);
970 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
972 newline_and_indent (buffer, spc);
973 pp_string (buffer, "catch");
974 newline_and_indent (buffer, spc + 2);
975 pp_left_brace (buffer);
977 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
979 newline_and_indent (buffer, spc);
980 pp_string (buffer, "finally");
981 newline_and_indent (buffer, spc + 2);
982 pp_left_brace (buffer);
984 else
985 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
987 pp_newline (buffer);
988 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
989 newline_and_indent (buffer, spc + 2);
990 pp_right_brace (buffer);
995 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
996 indent. FLAGS specifies details to show in the dump (see TDF_* in
997 dumpfile.h). */
999 static void
1000 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
1002 if (flags & TDF_RAW)
1003 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
1004 gimple_catch_types (gs), gimple_catch_handler (gs));
1005 else
1006 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
1007 gimple_catch_types (gs), gimple_catch_handler (gs));
1011 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
1012 indent. FLAGS specifies details to show in the dump (see TDF_* in
1013 dumpfile.h). */
1015 static void
1016 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
1018 if (flags & TDF_RAW)
1019 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
1020 gimple_eh_filter_types (gs),
1021 gimple_eh_filter_failure (gs));
1022 else
1023 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
1024 gimple_eh_filter_types (gs),
1025 gimple_eh_filter_failure (gs));
1029 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
1031 static void
1032 dump_gimple_eh_must_not_throw (pretty_printer *buffer, gimple gs,
1033 int spc, int flags)
1035 if (flags & TDF_RAW)
1036 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1037 gimple_eh_must_not_throw_fndecl (gs));
1038 else
1039 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
1040 gimple_eh_must_not_throw_fndecl (gs));
1044 /* Dump a GIMPLE_EH_ELSE tuple on the pretty_printer BUFFER, SPC spaces of
1045 indent. FLAGS specifies details to show in the dump (see TDF_* in
1046 dumpfile.h). */
1048 static void
1049 dump_gimple_eh_else (pretty_printer *buffer, gimple gs, int spc, int flags)
1051 if (flags & TDF_RAW)
1052 dump_gimple_fmt (buffer, spc, flags,
1053 "%G <%+N_BODY <%S>%nE_BODY <%S>%->", gs,
1054 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1055 else
1056 dump_gimple_fmt (buffer, spc, flags,
1057 "<<<if_normal_exit>>>%+{%S}%-<<<else_eh_exit>>>%+{%S}",
1058 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1062 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
1063 indent. FLAGS specifies details to show in the dump (see TDF_* in
1064 dumpfile.h). */
1066 static void
1067 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
1069 if (flags & TDF_RAW)
1070 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1071 gimple_resx_region (gs));
1072 else
1073 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
1076 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
1078 static void
1079 dump_gimple_eh_dispatch (pretty_printer *buffer, gimple gs, int spc, int flags)
1081 if (flags & TDF_RAW)
1082 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1083 gimple_eh_dispatch_region (gs));
1084 else
1085 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
1086 gimple_eh_dispatch_region (gs));
1089 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
1090 of indent. FLAGS specifies details to show in the dump (see TDF_*
1091 in dumpfile.h). */
1093 static void
1094 dump_gimple_debug (pretty_printer *buffer, gimple gs, int spc, int flags)
1096 switch (gs->subcode)
1098 case GIMPLE_DEBUG_BIND:
1099 if (flags & TDF_RAW)
1100 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
1101 gimple_debug_bind_get_var (gs),
1102 gimple_debug_bind_get_value (gs));
1103 else
1104 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
1105 gimple_debug_bind_get_var (gs),
1106 gimple_debug_bind_get_value (gs));
1107 break;
1109 case GIMPLE_DEBUG_SOURCE_BIND:
1110 if (flags & TDF_RAW)
1111 dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1112 gimple_debug_source_bind_get_var (gs),
1113 gimple_debug_source_bind_get_value (gs));
1114 else
1115 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1116 gimple_debug_source_bind_get_var (gs),
1117 gimple_debug_source_bind_get_value (gs));
1118 break;
1120 default:
1121 gcc_unreachable ();
1125 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
1126 static void
1127 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
1129 size_t i;
1131 if (flags & TDF_RAW)
1133 const char *kind;
1134 switch (gimple_omp_for_kind (gs))
1136 case GF_OMP_FOR_KIND_FOR:
1137 kind = "";
1138 break;
1139 case GF_OMP_FOR_KIND_DISTRIBUTE:
1140 kind = " distribute";
1141 break;
1142 case GF_OMP_FOR_KIND_CILKFOR:
1143 kind = " _Cilk_for";
1144 break;
1145 case GF_OMP_FOR_KIND_OACC_LOOP:
1146 kind = " oacc_loop";
1147 break;
1148 case GF_OMP_FOR_KIND_SIMD:
1149 kind = " simd";
1150 break;
1151 case GF_OMP_FOR_KIND_CILKSIMD:
1152 kind = " cilksimd";
1153 break;
1154 default:
1155 gcc_unreachable ();
1157 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1158 kind, gimple_omp_body (gs));
1159 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1160 dump_gimple_fmt (buffer, spc, flags, " >,");
1161 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1162 dump_gimple_fmt (buffer, spc, flags,
1163 "%+%T, %T, %T, %s, %T,%n",
1164 gimple_omp_for_index (gs, i),
1165 gimple_omp_for_initial (gs, i),
1166 gimple_omp_for_final (gs, i),
1167 get_tree_code_name (gimple_omp_for_cond (gs, i)),
1168 gimple_omp_for_incr (gs, i));
1169 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1170 gimple_omp_for_pre_body (gs));
1172 else
1174 switch (gimple_omp_for_kind (gs))
1176 case GF_OMP_FOR_KIND_FOR:
1177 pp_string (buffer, "#pragma omp for");
1178 break;
1179 case GF_OMP_FOR_KIND_DISTRIBUTE:
1180 pp_string (buffer, "#pragma omp distribute");
1181 break;
1182 case GF_OMP_FOR_KIND_CILKFOR:
1183 break;
1184 case GF_OMP_FOR_KIND_OACC_LOOP:
1185 pp_string (buffer, "#pragma acc loop");
1186 break;
1187 case GF_OMP_FOR_KIND_SIMD:
1188 pp_string (buffer, "#pragma omp simd");
1189 break;
1190 case GF_OMP_FOR_KIND_CILKSIMD:
1191 pp_string (buffer, "#pragma simd");
1192 break;
1193 default:
1194 gcc_unreachable ();
1196 if (gimple_omp_for_kind (gs) != GF_OMP_FOR_KIND_CILKFOR)
1197 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1198 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1200 if (i)
1201 spc += 2;
1202 if (gimple_omp_for_kind (gs) == GF_OMP_FOR_KIND_CILKFOR)
1203 pp_string (buffer, "_Cilk_for (");
1204 else
1206 newline_and_indent (buffer, spc);
1207 pp_string (buffer, "for (");
1209 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1210 flags, false);
1211 pp_string (buffer, " = ");
1212 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1213 flags, false);
1214 pp_string (buffer, "; ");
1216 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1217 flags, false);
1218 pp_space (buffer);
1219 switch (gimple_omp_for_cond (gs, i))
1221 case LT_EXPR:
1222 pp_less (buffer);
1223 break;
1224 case GT_EXPR:
1225 pp_greater (buffer);
1226 break;
1227 case LE_EXPR:
1228 pp_less_equal (buffer);
1229 break;
1230 case GE_EXPR:
1231 pp_greater_equal (buffer);
1232 break;
1233 case NE_EXPR:
1234 pp_string (buffer, "!=");
1235 break;
1236 default:
1237 gcc_unreachable ();
1239 pp_space (buffer);
1240 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1241 flags, false);
1242 pp_string (buffer, "; ");
1244 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1245 flags, false);
1246 pp_string (buffer, " = ");
1247 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1248 flags, false);
1249 pp_right_paren (buffer);
1252 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1254 if (gimple_omp_for_kind (gs) == GF_OMP_FOR_KIND_CILKFOR)
1255 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1256 newline_and_indent (buffer, spc + 2);
1257 pp_left_brace (buffer);
1258 pp_newline (buffer);
1259 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1260 newline_and_indent (buffer, spc + 2);
1261 pp_right_brace (buffer);
1266 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
1268 static void
1269 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
1271 if (flags & TDF_RAW)
1273 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1274 gimple_omp_continue_control_def (gs),
1275 gimple_omp_continue_control_use (gs));
1277 else
1279 pp_string (buffer, "#pragma omp continue (");
1280 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1281 spc, flags, false);
1282 pp_comma (buffer);
1283 pp_space (buffer);
1284 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1285 spc, flags, false);
1286 pp_right_paren (buffer);
1290 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1292 static void
1293 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
1295 if (flags & TDF_RAW)
1297 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1298 gimple_omp_body (gs));
1299 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1300 dump_gimple_fmt (buffer, spc, flags, " >");
1302 else
1304 pp_string (buffer, "#pragma omp single");
1305 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1306 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1308 newline_and_indent (buffer, spc + 2);
1309 pp_left_brace (buffer);
1310 pp_newline (buffer);
1311 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1312 newline_and_indent (buffer, spc + 2);
1313 pp_right_brace (buffer);
1318 /* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer BUFFER. */
1320 static void
1321 dump_gimple_omp_target (pretty_printer *buffer, gimple gs, int spc, int flags)
1323 const char *kind;
1324 switch (gimple_omp_target_kind (gs))
1326 case GF_OMP_TARGET_KIND_REGION:
1327 kind = "";
1328 break;
1329 case GF_OMP_TARGET_KIND_DATA:
1330 kind = " data";
1331 break;
1332 case GF_OMP_TARGET_KIND_UPDATE:
1333 kind = " update";
1334 break;
1335 case GF_OMP_TARGET_KIND_OACC_DATA:
1336 kind = " oacc_data";
1337 break;
1338 case GF_OMP_TARGET_KIND_OACC_UPDATE:
1339 kind = " oacc_update";
1340 break;
1341 default:
1342 gcc_unreachable ();
1344 if (flags & TDF_RAW)
1346 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1347 kind, gimple_omp_body (gs));
1348 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1349 dump_gimple_fmt (buffer, spc, flags, " >");
1351 else
1353 pp_string (buffer, "#pragma omp target");
1354 pp_string (buffer, kind);
1355 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1356 if (gimple_omp_target_child_fn (gs))
1358 pp_string (buffer, " [child fn: ");
1359 dump_generic_node (buffer, gimple_omp_target_child_fn (gs),
1360 spc, flags, false);
1361 pp_right_bracket (buffer);
1363 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1365 newline_and_indent (buffer, spc + 2);
1366 pp_character (buffer, '{');
1367 pp_newline (buffer);
1368 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1369 newline_and_indent (buffer, spc + 2);
1370 pp_character (buffer, '}');
1375 /* Dump a GIMPLE_OMP_TEAMS tuple on the pretty_printer BUFFER. */
1377 static void
1378 dump_gimple_omp_teams (pretty_printer *buffer, gimple gs, int spc, int flags)
1380 if (flags & TDF_RAW)
1382 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1383 gimple_omp_body (gs));
1384 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1385 dump_gimple_fmt (buffer, spc, flags, " >");
1387 else
1389 pp_string (buffer, "#pragma omp teams");
1390 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1391 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1393 newline_and_indent (buffer, spc + 2);
1394 pp_character (buffer, '{');
1395 pp_newline (buffer);
1396 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1397 newline_and_indent (buffer, spc + 2);
1398 pp_character (buffer, '}');
1403 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1405 static void
1406 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
1407 int flags)
1409 if (flags & TDF_RAW)
1411 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1412 gimple_omp_body (gs));
1413 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1414 dump_gimple_fmt (buffer, spc, flags, " >");
1416 else
1418 pp_string (buffer, "#pragma omp sections");
1419 if (gimple_omp_sections_control (gs))
1421 pp_string (buffer, " <");
1422 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1423 flags, false);
1424 pp_greater (buffer);
1426 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1427 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1429 newline_and_indent (buffer, spc + 2);
1430 pp_left_brace (buffer);
1431 pp_newline (buffer);
1432 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1433 newline_and_indent (buffer, spc + 2);
1434 pp_right_brace (buffer);
1439 /* Dump a GIMPLE_OMP_{MASTER,TASKGROUP,ORDERED,SECTION} tuple on the
1440 pretty_printer BUFFER. */
1442 static void
1443 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
1445 if (flags & TDF_RAW)
1446 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1447 gimple_omp_body (gs));
1448 else
1450 switch (gimple_code (gs))
1452 case GIMPLE_OMP_MASTER:
1453 pp_string (buffer, "#pragma omp master");
1454 break;
1455 case GIMPLE_OMP_TASKGROUP:
1456 pp_string (buffer, "#pragma omp taskgroup");
1457 break;
1458 case GIMPLE_OMP_ORDERED:
1459 pp_string (buffer, "#pragma omp ordered");
1460 break;
1461 case GIMPLE_OMP_SECTION:
1462 pp_string (buffer, "#pragma omp section");
1463 break;
1464 default:
1465 gcc_unreachable ();
1467 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1469 newline_and_indent (buffer, spc + 2);
1470 pp_left_brace (buffer);
1471 pp_newline (buffer);
1472 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1473 newline_and_indent (buffer, spc + 2);
1474 pp_right_brace (buffer);
1479 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1481 static void
1482 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
1483 int flags)
1485 if (flags & TDF_RAW)
1486 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1487 gimple_omp_body (gs));
1488 else
1490 pp_string (buffer, "#pragma omp critical");
1491 if (gimple_omp_critical_name (gs))
1493 pp_string (buffer, " (");
1494 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1495 flags, false);
1496 pp_right_paren (buffer);
1498 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1500 newline_and_indent (buffer, spc + 2);
1501 pp_left_brace (buffer);
1502 pp_newline (buffer);
1503 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1504 newline_and_indent (buffer, spc + 2);
1505 pp_right_brace (buffer);
1510 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1512 static void
1513 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1515 if (flags & TDF_RAW)
1517 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d", gs,
1518 (int) gimple_omp_return_nowait_p (gs));
1519 if (gimple_omp_return_lhs (gs))
1520 dump_gimple_fmt (buffer, spc, flags, ", lhs=%T>",
1521 gimple_omp_return_lhs (gs));
1522 else
1523 dump_gimple_fmt (buffer, spc, flags, ">");
1525 else
1527 pp_string (buffer, "#pragma omp return");
1528 if (gimple_omp_return_nowait_p (gs))
1529 pp_string (buffer, "(nowait)");
1530 if (gimple_omp_return_lhs (gs))
1532 pp_string (buffer, " (set ");
1533 dump_generic_node (buffer, gimple_omp_return_lhs (gs),
1534 spc, flags, false);
1535 pp_character (buffer, ')');
1540 /* Dump a GIMPLE_TRANSACTION tuple on the pretty_printer BUFFER. */
1542 static void
1543 dump_gimple_transaction (pretty_printer *buffer, gimple gs, int spc, int flags)
1545 unsigned subcode = gimple_transaction_subcode (gs);
1547 if (flags & TDF_RAW)
1549 dump_gimple_fmt (buffer, spc, flags,
1550 "%G [SUBCODE=%x,LABEL=%T] <%+BODY <%S> >",
1551 gs, subcode, gimple_transaction_label (gs),
1552 gimple_transaction_body (gs));
1554 else
1556 if (subcode & GTMA_IS_OUTER)
1557 pp_string (buffer, "__transaction_atomic [[outer]]");
1558 else if (subcode & GTMA_IS_RELAXED)
1559 pp_string (buffer, "__transaction_relaxed");
1560 else
1561 pp_string (buffer, "__transaction_atomic");
1562 subcode &= ~GTMA_DECLARATION_MASK;
1564 if (subcode || gimple_transaction_label (gs))
1566 pp_string (buffer, " //");
1567 if (gimple_transaction_label (gs))
1569 pp_string (buffer, " LABEL=");
1570 dump_generic_node (buffer, gimple_transaction_label (gs),
1571 spc, flags, false);
1573 if (subcode)
1575 pp_string (buffer, " SUBCODE=[ ");
1576 if (subcode & GTMA_HAVE_ABORT)
1578 pp_string (buffer, "GTMA_HAVE_ABORT ");
1579 subcode &= ~GTMA_HAVE_ABORT;
1581 if (subcode & GTMA_HAVE_LOAD)
1583 pp_string (buffer, "GTMA_HAVE_LOAD ");
1584 subcode &= ~GTMA_HAVE_LOAD;
1586 if (subcode & GTMA_HAVE_STORE)
1588 pp_string (buffer, "GTMA_HAVE_STORE ");
1589 subcode &= ~GTMA_HAVE_STORE;
1591 if (subcode & GTMA_MAY_ENTER_IRREVOCABLE)
1593 pp_string (buffer, "GTMA_MAY_ENTER_IRREVOCABLE ");
1594 subcode &= ~GTMA_MAY_ENTER_IRREVOCABLE;
1596 if (subcode & GTMA_DOES_GO_IRREVOCABLE)
1598 pp_string (buffer, "GTMA_DOES_GO_IRREVOCABLE ");
1599 subcode &= ~GTMA_DOES_GO_IRREVOCABLE;
1601 if (subcode & GTMA_HAS_NO_INSTRUMENTATION)
1603 pp_string (buffer, "GTMA_HAS_NO_INSTRUMENTATION ");
1604 subcode &= ~GTMA_HAS_NO_INSTRUMENTATION;
1606 if (subcode)
1607 pp_printf (buffer, "0x%x ", subcode);
1608 pp_right_bracket (buffer);
1612 if (!gimple_seq_empty_p (gimple_transaction_body (gs)))
1614 newline_and_indent (buffer, spc + 2);
1615 pp_left_brace (buffer);
1616 pp_newline (buffer);
1617 dump_gimple_seq (buffer, gimple_transaction_body (gs),
1618 spc + 4, flags);
1619 newline_and_indent (buffer, spc + 2);
1620 pp_right_brace (buffer);
1625 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1626 indent. FLAGS specifies details to show in the dump (see TDF_* in
1627 dumpfile.h). */
1629 static void
1630 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1632 unsigned int i, n, f, fields;
1634 if (flags & TDF_RAW)
1636 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1637 gimple_asm_string (gs));
1639 n = gimple_asm_noutputs (gs);
1640 if (n)
1642 newline_and_indent (buffer, spc + 2);
1643 pp_string (buffer, "OUTPUT: ");
1644 for (i = 0; i < n; i++)
1646 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1647 spc, flags, false);
1648 if (i < n - 1)
1649 pp_string (buffer, ", ");
1653 n = gimple_asm_ninputs (gs);
1654 if (n)
1656 newline_and_indent (buffer, spc + 2);
1657 pp_string (buffer, "INPUT: ");
1658 for (i = 0; i < n; i++)
1660 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1661 spc, flags, false);
1662 if (i < n - 1)
1663 pp_string (buffer, ", ");
1667 n = gimple_asm_nclobbers (gs);
1668 if (n)
1670 newline_and_indent (buffer, spc + 2);
1671 pp_string (buffer, "CLOBBER: ");
1672 for (i = 0; i < n; i++)
1674 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1675 spc, flags, false);
1676 if (i < n - 1)
1677 pp_string (buffer, ", ");
1681 n = gimple_asm_nlabels (gs);
1682 if (n)
1684 newline_and_indent (buffer, spc + 2);
1685 pp_string (buffer, "LABEL: ");
1686 for (i = 0; i < n; i++)
1688 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1689 spc, flags, false);
1690 if (i < n - 1)
1691 pp_string (buffer, ", ");
1695 newline_and_indent (buffer, spc);
1696 pp_greater (buffer);
1698 else
1700 pp_string (buffer, "__asm__");
1701 if (gimple_asm_volatile_p (gs))
1702 pp_string (buffer, " __volatile__");
1703 if (gimple_asm_nlabels (gs))
1704 pp_string (buffer, " goto");
1705 pp_string (buffer, "(\"");
1706 pp_string (buffer, gimple_asm_string (gs));
1707 pp_string (buffer, "\"");
1709 if (gimple_asm_nlabels (gs))
1710 fields = 4;
1711 else if (gimple_asm_nclobbers (gs))
1712 fields = 3;
1713 else if (gimple_asm_ninputs (gs))
1714 fields = 2;
1715 else if (gimple_asm_noutputs (gs))
1716 fields = 1;
1717 else
1718 fields = 0;
1720 for (f = 0; f < fields; ++f)
1722 pp_string (buffer, " : ");
1724 switch (f)
1726 case 0:
1727 n = gimple_asm_noutputs (gs);
1728 for (i = 0; i < n; i++)
1730 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1731 spc, flags, false);
1732 if (i < n - 1)
1733 pp_string (buffer, ", ");
1735 break;
1737 case 1:
1738 n = gimple_asm_ninputs (gs);
1739 for (i = 0; i < n; i++)
1741 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1742 spc, flags, false);
1743 if (i < n - 1)
1744 pp_string (buffer, ", ");
1746 break;
1748 case 2:
1749 n = gimple_asm_nclobbers (gs);
1750 for (i = 0; i < n; i++)
1752 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1753 spc, flags, false);
1754 if (i < n - 1)
1755 pp_string (buffer, ", ");
1757 break;
1759 case 3:
1760 n = gimple_asm_nlabels (gs);
1761 for (i = 0; i < n; i++)
1763 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1764 spc, flags, false);
1765 if (i < n - 1)
1766 pp_string (buffer, ", ");
1768 break;
1770 default:
1771 gcc_unreachable ();
1775 pp_string (buffer, ");");
1779 /* Dump ptr_info and range_info for NODE on pretty_printer BUFFER with
1780 SPC spaces of indent. */
1782 static void
1783 dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
1785 if (TREE_CODE (node) != SSA_NAME)
1786 return;
1788 if (POINTER_TYPE_P (TREE_TYPE (node))
1789 && SSA_NAME_PTR_INFO (node))
1791 unsigned int align, misalign;
1792 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (node);
1793 pp_string (buffer, "# PT = ");
1794 pp_points_to_solution (buffer, &pi->pt);
1795 newline_and_indent (buffer, spc);
1796 if (get_ptr_info_alignment (pi, &align, &misalign))
1798 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u", align, misalign);
1799 newline_and_indent (buffer, spc);
1803 if (!POINTER_TYPE_P (TREE_TYPE (node))
1804 && SSA_NAME_RANGE_INFO (node))
1806 wide_int min, max, nonzero_bits;
1807 value_range_type range_type = get_range_info (node, &min, &max);
1809 if (range_type == VR_VARYING)
1810 pp_printf (buffer, "# RANGE VR_VARYING");
1811 else if (range_type == VR_RANGE || range_type == VR_ANTI_RANGE)
1813 pp_printf (buffer, "# RANGE ");
1814 pp_printf (buffer, "%s[", range_type == VR_RANGE ? "" : "~");
1815 pp_wide_int (buffer, min, TYPE_SIGN (TREE_TYPE (node)));
1816 pp_printf (buffer, ", ");
1817 pp_wide_int (buffer, max, TYPE_SIGN (TREE_TYPE (node)));
1818 pp_printf (buffer, "]");
1820 nonzero_bits = get_nonzero_bits (node);
1821 if (nonzero_bits != -1)
1823 pp_string (buffer, " NONZERO ");
1824 pp_wide_int (buffer, nonzero_bits, UNSIGNED);
1826 newline_and_indent (buffer, spc);
1831 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
1832 The caller is responsible for calling pp_flush on BUFFER to finalize
1833 pretty printer. If COMMENT is true, print this after #. */
1835 static void
1836 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, bool comment,
1837 int flags)
1839 size_t i;
1840 tree lhs = gimple_phi_result (phi);
1842 if (flags & TDF_ALIAS)
1843 dump_ssaname_info (buffer, lhs, spc);
1845 if (comment)
1846 pp_string (buffer, "# ");
1848 if (flags & TDF_RAW)
1849 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1850 gimple_phi_result (phi));
1851 else
1853 dump_generic_node (buffer, lhs, spc, flags, false);
1854 pp_string (buffer, " = PHI <");
1856 for (i = 0; i < gimple_phi_num_args (phi); i++)
1858 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1859 dump_location (buffer, gimple_phi_arg_location (phi, i));
1860 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1861 false);
1862 pp_left_paren (buffer);
1863 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1864 pp_right_paren (buffer);
1865 if (i < gimple_phi_num_args (phi) - 1)
1866 pp_string (buffer, ", ");
1868 pp_greater (buffer);
1872 /* Dump an OpenACC offload tuple on the pretty_printer BUFFER, SPC spaces
1873 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1874 dumpfile.h). */
1876 static void
1877 dump_gimple_oacc_offload (pretty_printer *buffer, gimple gs, int spc,
1878 int flags)
1880 tree (*gimple_omp_clauses) (const_gimple);
1881 tree (*gimple_omp_child_fn) (const_gimple);
1882 tree (*gimple_omp_data_arg) (const_gimple);
1883 const char *kind;
1884 switch (gimple_code (gs))
1886 case GIMPLE_OACC_KERNELS:
1887 gimple_omp_clauses = gimple_oacc_kernels_clauses;
1888 gimple_omp_child_fn = gimple_oacc_kernels_child_fn;
1889 gimple_omp_data_arg = gimple_oacc_kernels_data_arg;
1890 kind = "kernels";
1891 break;
1892 case GIMPLE_OACC_PARALLEL:
1893 gimple_omp_clauses = gimple_oacc_parallel_clauses;
1894 gimple_omp_child_fn = gimple_oacc_parallel_child_fn;
1895 gimple_omp_data_arg = gimple_oacc_parallel_data_arg;
1896 kind = "parallel";
1897 break;
1898 default:
1899 gcc_unreachable ();
1901 if (flags & TDF_RAW)
1903 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1904 gimple_omp_body (gs));
1905 dump_omp_clauses (buffer, gimple_omp_clauses (gs), spc, flags);
1906 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1907 gimple_omp_child_fn (gs), gimple_omp_data_arg (gs));
1909 else
1911 gimple_seq body;
1912 pp_string (buffer, "#pragma acc ");
1913 pp_string (buffer, kind);
1914 dump_omp_clauses (buffer, gimple_omp_clauses (gs), spc, flags);
1915 if (gimple_omp_child_fn (gs))
1917 pp_string (buffer, " [child fn: ");
1918 dump_generic_node (buffer, gimple_omp_child_fn (gs),
1919 spc, flags, false);
1920 pp_string (buffer, " (");
1921 if (gimple_omp_data_arg (gs))
1922 dump_generic_node (buffer, gimple_omp_data_arg (gs),
1923 spc, flags, false);
1924 else
1925 pp_string (buffer, "???");
1926 pp_string (buffer, ")]");
1928 body = gimple_omp_body (gs);
1929 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1931 newline_and_indent (buffer, spc + 2);
1932 pp_left_brace (buffer);
1933 pp_newline (buffer);
1934 dump_gimple_seq (buffer, body, spc + 4, flags);
1935 newline_and_indent (buffer, spc + 2);
1936 pp_right_brace (buffer);
1938 else if (body)
1940 pp_newline (buffer);
1941 dump_gimple_seq (buffer, body, spc + 2, flags);
1947 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1948 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1949 dumpfile.h). */
1951 static void
1952 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1953 int flags)
1955 if (flags & TDF_RAW)
1957 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1958 gimple_omp_body (gs));
1959 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1960 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1961 gimple_omp_parallel_child_fn (gs),
1962 gimple_omp_parallel_data_arg (gs));
1964 else
1966 gimple_seq body;
1967 pp_string (buffer, "#pragma omp parallel");
1968 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1969 if (gimple_omp_parallel_child_fn (gs))
1971 pp_string (buffer, " [child fn: ");
1972 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1973 spc, flags, false);
1974 pp_string (buffer, " (");
1975 if (gimple_omp_parallel_data_arg (gs))
1976 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1977 spc, flags, false);
1978 else
1979 pp_string (buffer, "???");
1980 pp_string (buffer, ")]");
1982 body = gimple_omp_body (gs);
1983 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1985 newline_and_indent (buffer, spc + 2);
1986 pp_left_brace (buffer);
1987 pp_newline (buffer);
1988 dump_gimple_seq (buffer, body, spc + 4, flags);
1989 newline_and_indent (buffer, spc + 2);
1990 pp_right_brace (buffer);
1992 else if (body)
1994 pp_newline (buffer);
1995 dump_gimple_seq (buffer, body, spc + 2, flags);
2001 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
2002 of indent. FLAGS specifies details to show in the dump (see TDF_* in
2003 dumpfile.h). */
2005 static void
2006 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
2007 int flags)
2009 if (flags & TDF_RAW)
2011 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2012 gimple_omp_body (gs));
2013 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2014 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
2015 gimple_omp_task_child_fn (gs),
2016 gimple_omp_task_data_arg (gs),
2017 gimple_omp_task_copy_fn (gs),
2018 gimple_omp_task_arg_size (gs),
2019 gimple_omp_task_arg_size (gs));
2021 else
2023 gimple_seq body;
2024 pp_string (buffer, "#pragma omp task");
2025 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2026 if (gimple_omp_task_child_fn (gs))
2028 pp_string (buffer, " [child fn: ");
2029 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
2030 spc, flags, false);
2031 pp_string (buffer, " (");
2032 if (gimple_omp_task_data_arg (gs))
2033 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
2034 spc, flags, false);
2035 else
2036 pp_string (buffer, "???");
2037 pp_string (buffer, ")]");
2039 body = gimple_omp_body (gs);
2040 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2042 newline_and_indent (buffer, spc + 2);
2043 pp_left_brace (buffer);
2044 pp_newline (buffer);
2045 dump_gimple_seq (buffer, body, spc + 4, flags);
2046 newline_and_indent (buffer, spc + 2);
2047 pp_right_brace (buffer);
2049 else if (body)
2051 pp_newline (buffer);
2052 dump_gimple_seq (buffer, body, spc + 2, flags);
2058 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
2059 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2060 in dumpfile.h). */
2062 static void
2063 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
2064 int flags)
2066 if (flags & TDF_RAW)
2068 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
2069 gimple_omp_atomic_load_lhs (gs),
2070 gimple_omp_atomic_load_rhs (gs));
2072 else
2074 pp_string (buffer, "#pragma omp atomic_load");
2075 if (gimple_omp_atomic_seq_cst_p (gs))
2076 pp_string (buffer, " seq_cst");
2077 if (gimple_omp_atomic_need_value_p (gs))
2078 pp_string (buffer, " [needed]");
2079 newline_and_indent (buffer, spc + 2);
2080 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
2081 spc, flags, false);
2082 pp_space (buffer);
2083 pp_equal (buffer);
2084 pp_space (buffer);
2085 pp_star (buffer);
2086 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
2087 spc, flags, false);
2091 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
2092 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2093 in dumpfile.h). */
2095 static void
2096 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
2097 int flags)
2099 if (flags & TDF_RAW)
2101 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
2102 gimple_omp_atomic_store_val (gs));
2104 else
2106 pp_string (buffer, "#pragma omp atomic_store ");
2107 if (gimple_omp_atomic_seq_cst_p (gs))
2108 pp_string (buffer, "seq_cst ");
2109 if (gimple_omp_atomic_need_value_p (gs))
2110 pp_string (buffer, "[needed] ");
2111 pp_left_paren (buffer);
2112 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
2113 spc, flags, false);
2114 pp_right_paren (buffer);
2119 /* Dump all the memory operands for statement GS. BUFFER, SPC and
2120 FLAGS are as in pp_gimple_stmt_1. */
2122 static void
2123 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
2125 tree vdef = gimple_vdef (gs);
2126 tree vuse = gimple_vuse (gs);
2128 if (vdef != NULL_TREE)
2130 pp_string (buffer, "# ");
2131 dump_generic_node (buffer, vdef, spc + 2, flags, false);
2132 pp_string (buffer, " = VDEF <");
2133 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2134 pp_greater (buffer);
2135 newline_and_indent (buffer, spc);
2137 else if (vuse != NULL_TREE)
2139 pp_string (buffer, "# VUSE <");
2140 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2141 pp_greater (buffer);
2142 newline_and_indent (buffer, spc);
2147 /* Print the gimple statement GS on the pretty printer BUFFER, SPC
2148 spaces of indent. FLAGS specifies details to show in the dump (see
2149 TDF_* in dumpfile.h). The caller is responsible for calling
2150 pp_flush on BUFFER to finalize the pretty printer. */
2152 void
2153 pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags)
2155 if (!gs)
2156 return;
2158 if (flags & TDF_STMTADDR)
2159 pp_printf (buffer, "<&%p> ", (void *) gs);
2161 if ((flags & TDF_LINENO) && gimple_has_location (gs))
2162 dump_location (buffer, gimple_location (gs));
2164 if (flags & TDF_EH)
2166 int lp_nr = lookup_stmt_eh_lp (gs);
2167 if (lp_nr > 0)
2168 pp_printf (buffer, "[LP %d] ", lp_nr);
2169 else if (lp_nr < 0)
2170 pp_printf (buffer, "[MNT %d] ", -lp_nr);
2173 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
2174 && gimple_has_mem_ops (gs))
2175 dump_gimple_mem_ops (buffer, gs, spc, flags);
2177 if (gimple_has_lhs (gs)
2178 && (flags & TDF_ALIAS))
2179 dump_ssaname_info (buffer, gimple_get_lhs (gs), spc);
2181 switch (gimple_code (gs))
2183 case GIMPLE_ASM:
2184 dump_gimple_asm (buffer, gs, spc, flags);
2185 break;
2187 case GIMPLE_ASSIGN:
2188 dump_gimple_assign (buffer, gs, spc, flags);
2189 break;
2191 case GIMPLE_BIND:
2192 dump_gimple_bind (buffer, gs, spc, flags);
2193 break;
2195 case GIMPLE_CALL:
2196 dump_gimple_call (buffer, gs, spc, flags);
2197 break;
2199 case GIMPLE_COND:
2200 dump_gimple_cond (buffer, gs, spc, flags);
2201 break;
2203 case GIMPLE_LABEL:
2204 dump_gimple_label (buffer, gs, spc, flags);
2205 break;
2207 case GIMPLE_GOTO:
2208 dump_gimple_goto (buffer, gs, spc, flags);
2209 break;
2211 case GIMPLE_NOP:
2212 pp_string (buffer, "GIMPLE_NOP");
2213 break;
2215 case GIMPLE_RETURN:
2216 dump_gimple_return (buffer, gs, spc, flags);
2217 break;
2219 case GIMPLE_SWITCH:
2220 dump_gimple_switch (buffer, gs, spc, flags);
2221 break;
2223 case GIMPLE_TRY:
2224 dump_gimple_try (buffer, gs, spc, flags);
2225 break;
2227 case GIMPLE_PHI:
2228 dump_gimple_phi (buffer, gs, spc, false, flags);
2229 break;
2231 case GIMPLE_OACC_KERNELS:
2232 case GIMPLE_OACC_PARALLEL:
2233 dump_gimple_oacc_offload (buffer, gs, spc, flags);
2234 break;
2236 case GIMPLE_OMP_PARALLEL:
2237 dump_gimple_omp_parallel (buffer, gs, spc, flags);
2238 break;
2240 case GIMPLE_OMP_TASK:
2241 dump_gimple_omp_task (buffer, gs, spc, flags);
2242 break;
2244 case GIMPLE_OMP_ATOMIC_LOAD:
2245 dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
2247 break;
2249 case GIMPLE_OMP_ATOMIC_STORE:
2250 dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
2251 break;
2253 case GIMPLE_OMP_FOR:
2254 dump_gimple_omp_for (buffer, gs, spc, flags);
2255 break;
2257 case GIMPLE_OMP_CONTINUE:
2258 dump_gimple_omp_continue (buffer, gs, spc, flags);
2259 break;
2261 case GIMPLE_OMP_SINGLE:
2262 dump_gimple_omp_single (buffer, gs, spc, flags);
2263 break;
2265 case GIMPLE_OMP_TARGET:
2266 dump_gimple_omp_target (buffer, gs, spc, flags);
2267 break;
2269 case GIMPLE_OMP_TEAMS:
2270 dump_gimple_omp_teams (buffer, gs, spc, flags);
2271 break;
2273 case GIMPLE_OMP_RETURN:
2274 dump_gimple_omp_return (buffer, gs, spc, flags);
2275 break;
2277 case GIMPLE_OMP_SECTIONS:
2278 dump_gimple_omp_sections (buffer, gs, spc, flags);
2279 break;
2281 case GIMPLE_OMP_SECTIONS_SWITCH:
2282 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
2283 break;
2285 case GIMPLE_OMP_MASTER:
2286 case GIMPLE_OMP_TASKGROUP:
2287 case GIMPLE_OMP_ORDERED:
2288 case GIMPLE_OMP_SECTION:
2289 dump_gimple_omp_block (buffer, gs, spc, flags);
2290 break;
2292 case GIMPLE_OMP_CRITICAL:
2293 dump_gimple_omp_critical (buffer, gs, spc, flags);
2294 break;
2296 case GIMPLE_CATCH:
2297 dump_gimple_catch (buffer, gs, spc, flags);
2298 break;
2300 case GIMPLE_EH_FILTER:
2301 dump_gimple_eh_filter (buffer, gs, spc, flags);
2302 break;
2304 case GIMPLE_EH_MUST_NOT_THROW:
2305 dump_gimple_eh_must_not_throw (buffer, gs, spc, flags);
2306 break;
2308 case GIMPLE_EH_ELSE:
2309 dump_gimple_eh_else (buffer, gs, spc, flags);
2310 break;
2312 case GIMPLE_RESX:
2313 dump_gimple_resx (buffer, gs, spc, flags);
2314 break;
2316 case GIMPLE_EH_DISPATCH:
2317 dump_gimple_eh_dispatch (buffer, gs, spc, flags);
2318 break;
2320 case GIMPLE_DEBUG:
2321 dump_gimple_debug (buffer, gs, spc, flags);
2322 break;
2324 case GIMPLE_PREDICT:
2325 pp_string (buffer, "// predicted ");
2326 if (gimple_predict_outcome (gs))
2327 pp_string (buffer, "likely by ");
2328 else
2329 pp_string (buffer, "unlikely by ");
2330 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
2331 pp_string (buffer, " predictor.");
2332 break;
2334 case GIMPLE_TRANSACTION:
2335 dump_gimple_transaction (buffer, gs, spc, flags);
2336 break;
2338 default:
2339 GIMPLE_NIY;
2344 /* Dumps header of basic block BB to OUTF indented by INDENT
2345 spaces and details described by flags. */
2347 static void
2348 dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
2350 if (flags & TDF_BLOCKS)
2352 if (flags & TDF_LINENO)
2354 gimple_stmt_iterator gsi;
2356 if (flags & TDF_COMMENT)
2357 fputs (";; ", outf);
2359 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2360 if (!is_gimple_debug (gsi_stmt (gsi))
2361 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
2363 fprintf (outf, "%*sstarting at line %d",
2364 indent, "", get_lineno (gsi_stmt (gsi)));
2365 break;
2367 if (bb->discriminator)
2368 fprintf (outf, ", discriminator %i", bb->discriminator);
2369 fputc ('\n', outf);
2372 else
2374 gimple stmt = first_stmt (bb);
2375 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
2376 fprintf (outf, "%*s<bb %d>:\n", indent, "", bb->index);
2381 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2382 spaces. */
2384 static void
2385 dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
2386 basic_block bb ATTRIBUTE_UNUSED,
2387 int indent ATTRIBUTE_UNUSED,
2388 int flags ATTRIBUTE_UNUSED)
2390 /* There is currently no GIMPLE-specific basic block info to dump. */
2391 return;
2395 /* Dump PHI nodes of basic block BB to BUFFER with details described
2396 by FLAGS and indented by INDENT spaces. */
2398 static void
2399 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2401 gimple_stmt_iterator i;
2403 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2405 gimple phi = gsi_stmt (i);
2406 if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2408 INDENT (indent);
2409 dump_gimple_phi (buffer, phi, indent, true, flags);
2410 pp_newline (buffer);
2416 /* Dump jump to basic block BB that is represented implicitly in the cfg
2417 to BUFFER. */
2419 static void
2420 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2422 gimple stmt;
2424 stmt = first_stmt (bb);
2426 pp_string (buffer, "goto <bb ");
2427 pp_decimal_int (buffer, bb->index);
2428 pp_greater (buffer);
2429 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
2431 pp_string (buffer, " (");
2432 dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
2433 pp_right_paren (buffer);
2434 pp_semicolon (buffer);
2436 else
2437 pp_semicolon (buffer);
2441 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2442 by INDENT spaces, with details given by FLAGS. */
2444 static void
2445 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2446 int flags)
2448 edge e;
2449 gimple stmt;
2451 stmt = last_stmt (bb);
2453 if (stmt && gimple_code (stmt) == GIMPLE_COND)
2455 edge true_edge, false_edge;
2457 /* When we are emitting the code or changing CFG, it is possible that
2458 the edges are not yet created. When we are using debug_bb in such
2459 a situation, we do not want it to crash. */
2460 if (EDGE_COUNT (bb->succs) != 2)
2461 return;
2462 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2464 INDENT (indent + 2);
2465 pp_cfg_jump (buffer, true_edge->dest);
2466 newline_and_indent (buffer, indent);
2467 pp_string (buffer, "else");
2468 newline_and_indent (buffer, indent + 2);
2469 pp_cfg_jump (buffer, false_edge->dest);
2470 pp_newline (buffer);
2471 return;
2474 /* If there is a fallthru edge, we may need to add an artificial
2475 goto to the dump. */
2476 e = find_fallthru_edge (bb->succs);
2478 if (e && e->dest != bb->next_bb)
2480 INDENT (indent);
2482 if ((flags & TDF_LINENO)
2483 && e->goto_locus != UNKNOWN_LOCATION)
2484 dump_location (buffer, e->goto_locus);
2486 pp_cfg_jump (buffer, e->dest);
2487 pp_newline (buffer);
2492 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2493 indented by INDENT spaces. */
2495 static void
2496 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2497 int flags)
2499 gimple_stmt_iterator gsi;
2500 gimple stmt;
2501 int label_indent = indent - 2;
2503 if (label_indent < 0)
2504 label_indent = 0;
2506 dump_phi_nodes (buffer, bb, indent, flags);
2508 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2510 int curr_indent;
2512 stmt = gsi_stmt (gsi);
2514 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2516 INDENT (curr_indent);
2517 pp_gimple_stmt_1 (buffer, stmt, curr_indent, flags);
2518 pp_newline_and_flush (buffer);
2519 gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl));
2520 dump_histograms_for_stmt (DECL_STRUCT_FUNCTION (current_function_decl),
2521 pp_buffer (buffer)->stream, stmt);
2524 dump_implicit_edges (buffer, bb, indent, flags);
2525 pp_flush (buffer);
2529 /* Dumps basic block BB to FILE with details described by FLAGS and
2530 indented by INDENT spaces. */
2532 void
2533 gimple_dump_bb (FILE *file, basic_block bb, int indent, int flags)
2535 dump_gimple_bb_header (file, bb, indent, flags);
2536 if (bb->index >= NUM_FIXED_BLOCKS)
2538 pretty_printer buffer;
2539 pp_needs_newline (&buffer) = true;
2540 buffer.buffer->stream = file;
2541 gimple_dump_bb_buff (&buffer, bb, indent, flags);
2543 dump_gimple_bb_footer (file, bb, indent, flags);
2546 /* Dumps basic block BB to pretty-printer PP with default dump flags and
2547 no indentation, for use as a label of a DOT graph record-node.
2548 ??? Should just use gimple_dump_bb_buff here, except that value profiling
2549 histogram dumping doesn't know about pretty-printers. */
2551 void
2552 gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
2554 gimple_stmt_iterator gsi;
2556 pp_printf (pp, "<bb %d>:\n", bb->index);
2557 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2559 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2561 gimple phi = gsi_stmt (gsi);
2562 if (!virtual_operand_p (gimple_phi_result (phi))
2563 || (dump_flags & TDF_VOPS))
2565 pp_bar (pp);
2566 pp_write_text_to_stream (pp);
2567 pp_string (pp, "# ");
2568 pp_gimple_stmt_1 (pp, phi, 0, dump_flags);
2569 pp_newline (pp);
2570 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2574 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2576 gimple stmt = gsi_stmt (gsi);
2577 pp_bar (pp);
2578 pp_write_text_to_stream (pp);
2579 pp_gimple_stmt_1 (pp, stmt, 0, dump_flags);
2580 pp_newline (pp);
2581 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2583 dump_implicit_edges (pp, bb, 0, dump_flags);
2584 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);