gcc/
[official-gcc.git] / gcc / gimple-pretty-print.c
blob48edacce1483cbdf962e8134a020ec839786086d
1 /* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001-2016 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 "backend.h"
26 #include "tree.h"
27 #include "gimple.h"
28 #include "gimple-predict.h"
29 #include "ssa.h"
30 #include "cgraph.h"
31 #include "gimple-pretty-print.h"
32 #include "internal-fn.h"
33 #include "tree-eh.h"
34 #include "gimple-iterator.h"
35 #include "tree-cfg.h"
36 #include "dumpfile.h" /* for dump_flags */
37 #include "value-prof.h"
38 #include "trans-mem.h"
40 #define INDENT(SPACE) \
41 do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
43 #define GIMPLE_NIY do_niy (buffer,gs)
45 /* Try to print on BUFFER a default message for the unrecognized
46 gimple statement GS. */
48 static void
49 do_niy (pretty_printer *buffer, gimple *gs)
51 pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
52 gimple_code_name[(int) gimple_code (gs)]);
56 /* Emit a newline and SPC indentation spaces to BUFFER. */
58 static void
59 newline_and_indent (pretty_printer *buffer, int spc)
61 pp_newline (buffer);
62 INDENT (spc);
66 /* Print the GIMPLE statement GS on stderr. */
68 DEBUG_FUNCTION void
69 debug_gimple_stmt (gimple *gs)
71 print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
75 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
76 FLAGS as in pp_gimple_stmt_1. */
78 void
79 print_gimple_stmt (FILE *file, gimple *g, int spc, int flags)
81 pretty_printer buffer;
82 pp_needs_newline (&buffer) = true;
83 buffer.buffer->stream = file;
84 pp_gimple_stmt_1 (&buffer, g, spc, flags);
85 pp_newline_and_flush (&buffer);
88 DEBUG_FUNCTION void
89 debug (gimple &ref)
91 print_gimple_stmt (stderr, &ref, 0, 0);
94 DEBUG_FUNCTION void
95 debug (gimple *ptr)
97 if (ptr)
98 debug (*ptr);
99 else
100 fprintf (stderr, "<nil>\n");
104 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
105 FLAGS as in pp_gimple_stmt_1. Print only the right-hand side
106 of the statement. */
108 void
109 print_gimple_expr (FILE *file, gimple *g, int spc, int flags)
111 flags |= TDF_RHS_ONLY;
112 pretty_printer buffer;
113 pp_needs_newline (&buffer) = true;
114 buffer.buffer->stream = file;
115 pp_gimple_stmt_1 (&buffer, g, spc, flags);
116 pp_flush (&buffer);
120 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentation
121 spaces and FLAGS as in pp_gimple_stmt_1.
122 The caller is responsible for calling pp_flush on BUFFER to finalize
123 the pretty printer. */
125 static void
126 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc, int flags)
128 gimple_stmt_iterator i;
130 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
132 gimple *gs = gsi_stmt (i);
133 INDENT (spc);
134 pp_gimple_stmt_1 (buffer, gs, spc, flags);
135 if (!gsi_one_before_end_p (i))
136 pp_newline (buffer);
141 /* Print GIMPLE sequence SEQ to FILE using SPC indentation spaces and
142 FLAGS as in pp_gimple_stmt_1. */
144 void
145 print_gimple_seq (FILE *file, gimple_seq seq, int spc, int flags)
147 pretty_printer buffer;
148 pp_needs_newline (&buffer) = true;
149 buffer.buffer->stream = file;
150 dump_gimple_seq (&buffer, seq, spc, flags);
151 pp_newline_and_flush (&buffer);
155 /* Print the GIMPLE sequence SEQ on stderr. */
157 DEBUG_FUNCTION void
158 debug_gimple_seq (gimple_seq seq)
160 print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
164 /* A simple helper to pretty-print some of the gimple tuples in the printf
165 style. The format modifiers are preceded by '%' and are:
166 'G' - outputs a string corresponding to the code of the given gimple,
167 'S' - outputs a gimple_seq with indent of spc + 2,
168 'T' - outputs the tree t,
169 'd' - outputs an int as a decimal,
170 's' - outputs a string,
171 'n' - outputs a newline,
172 'x' - outputs an int as hexadecimal,
173 '+' - increases indent by 2 then outputs a newline,
174 '-' - decreases indent by 2 then outputs a newline. */
176 static void
177 dump_gimple_fmt (pretty_printer *buffer, int spc, int flags,
178 const char *fmt, ...)
180 va_list args;
181 const char *c;
182 const char *tmp;
184 va_start (args, fmt);
185 for (c = fmt; *c; c++)
187 if (*c == '%')
189 gimple_seq seq;
190 tree t;
191 gimple *g;
192 switch (*++c)
194 case 'G':
195 g = va_arg (args, gimple *);
196 tmp = gimple_code_name[gimple_code (g)];
197 pp_string (buffer, tmp);
198 break;
200 case 'S':
201 seq = va_arg (args, gimple_seq);
202 pp_newline (buffer);
203 dump_gimple_seq (buffer, seq, spc + 2, flags);
204 newline_and_indent (buffer, spc);
205 break;
207 case 'T':
208 t = va_arg (args, tree);
209 if (t == NULL_TREE)
210 pp_string (buffer, "NULL");
211 else
212 dump_generic_node (buffer, t, spc, flags, false);
213 break;
215 case 'd':
216 pp_decimal_int (buffer, va_arg (args, int));
217 break;
219 case 's':
220 pp_string (buffer, va_arg (args, char *));
221 break;
223 case 'n':
224 newline_and_indent (buffer, spc);
225 break;
227 case 'x':
228 pp_scalar (buffer, "%x", va_arg (args, int));
229 break;
231 case '+':
232 spc += 2;
233 newline_and_indent (buffer, spc);
234 break;
236 case '-':
237 spc -= 2;
238 newline_and_indent (buffer, spc);
239 break;
241 default:
242 gcc_unreachable ();
245 else
246 pp_character (buffer, *c);
248 va_end (args);
252 /* Helper for dump_gimple_assign. Print the unary RHS of the
253 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
255 static void
256 dump_unary_rhs (pretty_printer *buffer, gassign *gs, int spc, int flags)
258 enum tree_code rhs_code = gimple_assign_rhs_code (gs);
259 tree lhs = gimple_assign_lhs (gs);
260 tree rhs = gimple_assign_rhs1 (gs);
262 switch (rhs_code)
264 case VIEW_CONVERT_EXPR:
265 case ASSERT_EXPR:
266 dump_generic_node (buffer, rhs, spc, flags, false);
267 break;
269 case FIXED_CONVERT_EXPR:
270 case ADDR_SPACE_CONVERT_EXPR:
271 case FIX_TRUNC_EXPR:
272 case FLOAT_EXPR:
273 CASE_CONVERT:
274 pp_left_paren (buffer);
275 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
276 pp_string (buffer, ") ");
277 if (op_prio (rhs) < op_code_prio (rhs_code))
279 pp_left_paren (buffer);
280 dump_generic_node (buffer, rhs, spc, flags, false);
281 pp_right_paren (buffer);
283 else
284 dump_generic_node (buffer, rhs, spc, flags, false);
285 break;
287 case PAREN_EXPR:
288 pp_string (buffer, "((");
289 dump_generic_node (buffer, rhs, spc, flags, false);
290 pp_string (buffer, "))");
291 break;
293 case ABS_EXPR:
294 pp_string (buffer, "ABS_EXPR <");
295 dump_generic_node (buffer, rhs, spc, flags, false);
296 pp_greater (buffer);
297 break;
299 default:
300 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
301 || TREE_CODE_CLASS (rhs_code) == tcc_constant
302 || TREE_CODE_CLASS (rhs_code) == tcc_reference
303 || rhs_code == SSA_NAME
304 || rhs_code == ADDR_EXPR
305 || rhs_code == CONSTRUCTOR)
307 dump_generic_node (buffer, rhs, spc, flags, false);
308 break;
310 else if (rhs_code == BIT_NOT_EXPR)
311 pp_complement (buffer);
312 else if (rhs_code == TRUTH_NOT_EXPR)
313 pp_exclamation (buffer);
314 else if (rhs_code == NEGATE_EXPR)
315 pp_minus (buffer);
316 else
318 pp_left_bracket (buffer);
319 pp_string (buffer, get_tree_code_name (rhs_code));
320 pp_string (buffer, "] ");
323 if (op_prio (rhs) < op_code_prio (rhs_code))
325 pp_left_paren (buffer);
326 dump_generic_node (buffer, rhs, spc, flags, false);
327 pp_right_paren (buffer);
329 else
330 dump_generic_node (buffer, rhs, spc, flags, false);
331 break;
336 /* Helper for dump_gimple_assign. Print the binary RHS of the
337 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
339 static void
340 dump_binary_rhs (pretty_printer *buffer, gassign *gs, int spc, int flags)
342 const char *p;
343 enum tree_code code = gimple_assign_rhs_code (gs);
344 switch (code)
346 case COMPLEX_EXPR:
347 case MIN_EXPR:
348 case MAX_EXPR:
349 case VEC_WIDEN_MULT_HI_EXPR:
350 case VEC_WIDEN_MULT_LO_EXPR:
351 case VEC_WIDEN_MULT_EVEN_EXPR:
352 case VEC_WIDEN_MULT_ODD_EXPR:
353 case VEC_PACK_TRUNC_EXPR:
354 case VEC_PACK_SAT_EXPR:
355 case VEC_PACK_FIX_TRUNC_EXPR:
356 case VEC_WIDEN_LSHIFT_HI_EXPR:
357 case VEC_WIDEN_LSHIFT_LO_EXPR:
358 for (p = get_tree_code_name (code); *p; p++)
359 pp_character (buffer, TOUPPER (*p));
360 pp_string (buffer, " <");
361 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
362 pp_string (buffer, ", ");
363 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
364 pp_greater (buffer);
365 break;
367 default:
368 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
370 pp_left_paren (buffer);
371 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
372 false);
373 pp_right_paren (buffer);
375 else
376 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
377 pp_space (buffer);
378 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
379 pp_space (buffer);
380 if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
382 pp_left_paren (buffer);
383 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
384 false);
385 pp_right_paren (buffer);
387 else
388 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
392 /* Helper for dump_gimple_assign. Print the ternary RHS of the
393 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
395 static void
396 dump_ternary_rhs (pretty_printer *buffer, gassign *gs, int spc, int flags)
398 const char *p;
399 enum tree_code code = gimple_assign_rhs_code (gs);
400 switch (code)
402 case WIDEN_MULT_PLUS_EXPR:
403 case WIDEN_MULT_MINUS_EXPR:
404 for (p = get_tree_code_name (code); *p; p++)
405 pp_character (buffer, TOUPPER (*p));
406 pp_string (buffer, " <");
407 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
408 pp_string (buffer, ", ");
409 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
410 pp_string (buffer, ", ");
411 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
412 pp_greater (buffer);
413 break;
415 case FMA_EXPR:
416 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
417 pp_string (buffer, " * ");
418 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
419 pp_string (buffer, " + ");
420 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
421 break;
423 case DOT_PROD_EXPR:
424 pp_string (buffer, "DOT_PROD_EXPR <");
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 SAD_EXPR:
434 pp_string (buffer, "SAD_EXPR <");
435 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
436 pp_string (buffer, ", ");
437 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
438 pp_string (buffer, ", ");
439 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
440 pp_greater (buffer);
441 break;
443 case VEC_PERM_EXPR:
444 pp_string (buffer, "VEC_PERM_EXPR <");
445 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
446 pp_string (buffer, ", ");
447 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
448 pp_string (buffer, ", ");
449 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
450 pp_greater (buffer);
451 break;
453 case REALIGN_LOAD_EXPR:
454 pp_string (buffer, "REALIGN_LOAD <");
455 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
456 pp_string (buffer, ", ");
457 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
458 pp_string (buffer, ", ");
459 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
460 pp_greater (buffer);
461 break;
463 case COND_EXPR:
464 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
465 pp_string (buffer, " ? ");
466 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
467 pp_string (buffer, " : ");
468 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
469 break;
471 case VEC_COND_EXPR:
472 pp_string (buffer, "VEC_COND_EXPR <");
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 BIT_INSERT_EXPR:
482 pp_string (buffer, "BIT_INSERT_EXPR <");
483 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
484 pp_string (buffer, ", ");
485 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
486 pp_string (buffer, ", ");
487 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
488 pp_string (buffer, " (");
489 if (INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs2 (gs))))
490 pp_decimal_int (buffer,
491 TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs2 (gs))));
492 else
493 dump_generic_node (buffer,
494 TYPE_SIZE (TREE_TYPE (gimple_assign_rhs2 (gs))),
495 spc, flags, false);
496 pp_string (buffer, " bits)>");
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, gassign *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, greturn *gs, int spc, int flags)
570 tree t, t2;
572 t = gimple_return_retval (gs);
573 t2 = gimple_return_retbnd (gs);
574 if (flags & TDF_RAW)
575 dump_gimple_fmt (buffer, spc, flags, "%G <%T %T>", gs, t, t2);
576 else
578 pp_string (buffer, "return");
579 if (t)
581 pp_space (buffer);
582 dump_generic_node (buffer, t, spc, flags, false);
584 if (t2)
586 pp_string (buffer, ", ");
587 dump_generic_node (buffer, t2, spc, flags, false);
589 pp_semicolon (buffer);
594 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
595 dump_gimple_call. */
597 static void
598 dump_gimple_call_args (pretty_printer *buffer, gcall *gs, int flags)
600 size_t i;
602 for (i = 0; i < gimple_call_num_args (gs); i++)
604 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
605 if (i < gimple_call_num_args (gs) - 1)
606 pp_string (buffer, ", ");
609 if (gimple_call_va_arg_pack_p (gs))
611 if (gimple_call_num_args (gs) > 0)
613 pp_comma (buffer);
614 pp_space (buffer);
617 pp_string (buffer, "__builtin_va_arg_pack ()");
621 /* Dump the points-to solution *PT to BUFFER. */
623 static void
624 pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
626 if (pt->anything)
628 pp_string (buffer, "anything ");
629 return;
631 if (pt->nonlocal)
632 pp_string (buffer, "nonlocal ");
633 if (pt->escaped)
634 pp_string (buffer, "escaped ");
635 if (pt->ipa_escaped)
636 pp_string (buffer, "unit-escaped ");
637 if (pt->null)
638 pp_string (buffer, "null ");
639 if (pt->vars
640 && !bitmap_empty_p (pt->vars))
642 bitmap_iterator bi;
643 unsigned i;
644 pp_string (buffer, "{ ");
645 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
647 pp_string (buffer, "D.");
648 pp_decimal_int (buffer, i);
649 pp_space (buffer);
651 pp_right_brace (buffer);
652 if (pt->vars_contains_nonlocal
653 || pt->vars_contains_escaped
654 || pt->vars_contains_escaped_heap
655 || pt->vars_contains_restrict)
657 const char *comma = "";
658 pp_string (buffer, " (");
659 if (pt->vars_contains_nonlocal)
661 pp_string (buffer, "nonlocal");
662 comma = ", ";
664 if (pt->vars_contains_escaped)
666 pp_string (buffer, comma);
667 pp_string (buffer, "escaped");
668 comma = ", ";
670 if (pt->vars_contains_escaped_heap)
672 pp_string (buffer, comma);
673 pp_string (buffer, "escaped heap");
674 comma = ", ";
676 if (pt->vars_contains_restrict)
678 pp_string (buffer, comma);
679 pp_string (buffer, "restrict");
681 pp_string (buffer, ")");
687 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
688 pp_gimple_stmt_1. */
690 static void
691 dump_gimple_call (pretty_printer *buffer, gcall *gs, int spc, int flags)
693 tree lhs = gimple_call_lhs (gs);
694 tree fn = gimple_call_fn (gs);
696 if (flags & TDF_ALIAS)
698 struct pt_solution *pt;
699 pt = gimple_call_use_set (gs);
700 if (!pt_solution_empty_p (pt))
702 pp_string (buffer, "# USE = ");
703 pp_points_to_solution (buffer, pt);
704 newline_and_indent (buffer, spc);
706 pt = gimple_call_clobber_set (gs);
707 if (!pt_solution_empty_p (pt))
709 pp_string (buffer, "# CLB = ");
710 pp_points_to_solution (buffer, pt);
711 newline_and_indent (buffer, spc);
715 if (flags & TDF_RAW)
717 if (gimple_call_internal_p (gs))
718 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T", gs,
719 internal_fn_name (gimple_call_internal_fn (gs)), lhs);
720 else
721 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T", gs, fn, lhs);
722 if (gimple_call_num_args (gs) > 0)
724 pp_string (buffer, ", ");
725 dump_gimple_call_args (buffer, gs, flags);
727 pp_greater (buffer);
729 else
731 if (lhs && !(flags & TDF_RHS_ONLY))
733 dump_generic_node (buffer, lhs, spc, flags, false);
734 pp_string (buffer, " =");
736 if (gimple_has_volatile_ops (gs))
737 pp_string (buffer, "{v}");
739 pp_space (buffer);
741 if (gimple_call_internal_p (gs))
742 pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
743 else
744 print_call_name (buffer, fn, flags);
745 pp_string (buffer, " (");
746 dump_gimple_call_args (buffer, gs, flags);
747 pp_right_paren (buffer);
748 if (!(flags & TDF_RHS_ONLY))
749 pp_semicolon (buffer);
752 if (gimple_call_chain (gs))
754 pp_string (buffer, " [static-chain: ");
755 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
756 pp_right_bracket (buffer);
759 if (gimple_call_return_slot_opt_p (gs))
760 pp_string (buffer, " [return slot optimization]");
761 if (gimple_call_tail_p (gs))
762 pp_string (buffer, " [tail call]");
763 if (gimple_call_must_tail_p (gs))
764 pp_string (buffer, " [must tail call]");
766 if (fn == NULL)
767 return;
769 /* Dump the arguments of _ITM_beginTransaction sanely. */
770 if (TREE_CODE (fn) == ADDR_EXPR)
771 fn = TREE_OPERAND (fn, 0);
772 if (TREE_CODE (fn) == FUNCTION_DECL && decl_is_tm_clone (fn))
773 pp_string (buffer, " [tm-clone]");
774 if (TREE_CODE (fn) == FUNCTION_DECL
775 && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
776 && DECL_FUNCTION_CODE (fn) == BUILT_IN_TM_START
777 && gimple_call_num_args (gs) > 0)
779 tree t = gimple_call_arg (gs, 0);
780 unsigned HOST_WIDE_INT props;
781 gcc_assert (TREE_CODE (t) == INTEGER_CST);
783 pp_string (buffer, " [ ");
785 /* Get the transaction code properties. */
786 props = TREE_INT_CST_LOW (t);
788 if (props & PR_INSTRUMENTEDCODE)
789 pp_string (buffer, "instrumentedCode ");
790 if (props & PR_UNINSTRUMENTEDCODE)
791 pp_string (buffer, "uninstrumentedCode ");
792 if (props & PR_HASNOXMMUPDATE)
793 pp_string (buffer, "hasNoXMMUpdate ");
794 if (props & PR_HASNOABORT)
795 pp_string (buffer, "hasNoAbort ");
796 if (props & PR_HASNOIRREVOCABLE)
797 pp_string (buffer, "hasNoIrrevocable ");
798 if (props & PR_DOESGOIRREVOCABLE)
799 pp_string (buffer, "doesGoIrrevocable ");
800 if (props & PR_HASNOSIMPLEREADS)
801 pp_string (buffer, "hasNoSimpleReads ");
802 if (props & PR_AWBARRIERSOMITTED)
803 pp_string (buffer, "awBarriersOmitted ");
804 if (props & PR_RARBARRIERSOMITTED)
805 pp_string (buffer, "RaRBarriersOmitted ");
806 if (props & PR_UNDOLOGCODE)
807 pp_string (buffer, "undoLogCode ");
808 if (props & PR_PREFERUNINSTRUMENTED)
809 pp_string (buffer, "preferUninstrumented ");
810 if (props & PR_EXCEPTIONBLOCK)
811 pp_string (buffer, "exceptionBlock ");
812 if (props & PR_HASELSE)
813 pp_string (buffer, "hasElse ");
814 if (props & PR_READONLY)
815 pp_string (buffer, "readOnly ");
817 pp_right_bracket (buffer);
822 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
823 pp_gimple_stmt_1. */
825 static void
826 dump_gimple_switch (pretty_printer *buffer, gswitch *gs, int spc,
827 int flags)
829 unsigned int i;
831 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
832 if (flags & TDF_RAW)
833 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
834 gimple_switch_index (gs));
835 else
837 pp_string (buffer, "switch (");
838 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
839 pp_string (buffer, ") <");
842 for (i = 0; i < gimple_switch_num_labels (gs); i++)
844 tree case_label = gimple_switch_label (gs, i);
845 gcc_checking_assert (case_label != NULL_TREE);
846 dump_generic_node (buffer, case_label, spc, flags, false);
847 pp_space (buffer);
848 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
849 if (i < gimple_switch_num_labels (gs) - 1)
850 pp_string (buffer, ", ");
852 pp_greater (buffer);
856 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
857 pp_gimple_stmt_1. */
859 static void
860 dump_gimple_cond (pretty_printer *buffer, gcond *gs, int spc, int flags)
862 if (flags & TDF_RAW)
863 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
864 get_tree_code_name (gimple_cond_code (gs)),
865 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
866 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
867 else
869 if (!(flags & TDF_RHS_ONLY))
870 pp_string (buffer, "if (");
871 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
872 pp_space (buffer);
873 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
874 pp_space (buffer);
875 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
876 if (!(flags & TDF_RHS_ONLY))
878 pp_right_paren (buffer);
880 if (gimple_cond_true_label (gs))
882 pp_string (buffer, " goto ");
883 dump_generic_node (buffer, gimple_cond_true_label (gs),
884 spc, flags, false);
885 pp_semicolon (buffer);
887 if (gimple_cond_false_label (gs))
889 pp_string (buffer, " else goto ");
890 dump_generic_node (buffer, gimple_cond_false_label (gs),
891 spc, flags, false);
892 pp_semicolon (buffer);
899 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
900 spaces of indent. FLAGS specifies details to show in the dump (see
901 TDF_* in dumpfils.h). */
903 static void
904 dump_gimple_label (pretty_printer *buffer, glabel *gs, int spc, int flags)
906 tree label = gimple_label_label (gs);
907 if (flags & TDF_RAW)
908 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
909 else
911 dump_generic_node (buffer, label, spc, flags, false);
912 pp_colon (buffer);
914 if (DECL_NONLOCAL (label))
915 pp_string (buffer, " [non-local]");
916 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
917 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
920 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
921 spaces of indent. FLAGS specifies details to show in the dump (see
922 TDF_* in dumpfile.h). */
924 static void
925 dump_gimple_goto (pretty_printer *buffer, ggoto *gs, int spc, int flags)
927 tree label = gimple_goto_dest (gs);
928 if (flags & TDF_RAW)
929 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
930 else
931 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
935 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
936 spaces of indent. FLAGS specifies details to show in the dump (see
937 TDF_* in dumpfile.h). */
939 static void
940 dump_gimple_bind (pretty_printer *buffer, gbind *gs, int spc, int flags)
942 if (flags & TDF_RAW)
943 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
944 else
945 pp_left_brace (buffer);
946 if (!(flags & TDF_SLIM))
948 tree var;
950 for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
952 newline_and_indent (buffer, 2);
953 print_declaration (buffer, var, spc, flags);
955 if (gimple_bind_vars (gs))
956 pp_newline (buffer);
958 pp_newline (buffer);
959 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
960 newline_and_indent (buffer, spc);
961 if (flags & TDF_RAW)
962 pp_greater (buffer);
963 else
964 pp_right_brace (buffer);
968 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
969 indent. FLAGS specifies details to show in the dump (see TDF_* in
970 dumpfile.h). */
972 static void
973 dump_gimple_try (pretty_printer *buffer, gtry *gs, int spc, int flags)
975 if (flags & TDF_RAW)
977 const char *type;
978 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
979 type = "GIMPLE_TRY_CATCH";
980 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
981 type = "GIMPLE_TRY_FINALLY";
982 else
983 type = "UNKNOWN GIMPLE_TRY";
984 dump_gimple_fmt (buffer, spc, flags,
985 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
986 gimple_try_eval (gs), gimple_try_cleanup (gs));
988 else
990 pp_string (buffer, "try");
991 newline_and_indent (buffer, spc + 2);
992 pp_left_brace (buffer);
993 pp_newline (buffer);
995 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
996 newline_and_indent (buffer, spc + 2);
997 pp_right_brace (buffer);
999 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
1001 newline_and_indent (buffer, spc);
1002 pp_string (buffer, "catch");
1003 newline_and_indent (buffer, spc + 2);
1004 pp_left_brace (buffer);
1006 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
1008 newline_and_indent (buffer, spc);
1009 pp_string (buffer, "finally");
1010 newline_and_indent (buffer, spc + 2);
1011 pp_left_brace (buffer);
1013 else
1014 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
1016 pp_newline (buffer);
1017 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
1018 newline_and_indent (buffer, spc + 2);
1019 pp_right_brace (buffer);
1024 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
1025 indent. FLAGS specifies details to show in the dump (see TDF_* in
1026 dumpfile.h). */
1028 static void
1029 dump_gimple_catch (pretty_printer *buffer, gcatch *gs, int spc, int flags)
1031 if (flags & TDF_RAW)
1032 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
1033 gimple_catch_types (gs), gimple_catch_handler (gs));
1034 else
1035 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
1036 gimple_catch_types (gs), gimple_catch_handler (gs));
1040 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
1041 indent. FLAGS specifies details to show in the dump (see TDF_* in
1042 dumpfile.h). */
1044 static void
1045 dump_gimple_eh_filter (pretty_printer *buffer, geh_filter *gs, int spc,
1046 int flags)
1048 if (flags & TDF_RAW)
1049 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
1050 gimple_eh_filter_types (gs),
1051 gimple_eh_filter_failure (gs));
1052 else
1053 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
1054 gimple_eh_filter_types (gs),
1055 gimple_eh_filter_failure (gs));
1059 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
1061 static void
1062 dump_gimple_eh_must_not_throw (pretty_printer *buffer,
1063 geh_mnt *gs, int spc, int flags)
1065 if (flags & TDF_RAW)
1066 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1067 gimple_eh_must_not_throw_fndecl (gs));
1068 else
1069 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
1070 gimple_eh_must_not_throw_fndecl (gs));
1074 /* Dump a GIMPLE_EH_ELSE tuple on the pretty_printer BUFFER, SPC spaces of
1075 indent. FLAGS specifies details to show in the dump (see TDF_* in
1076 dumpfile.h). */
1078 static void
1079 dump_gimple_eh_else (pretty_printer *buffer, geh_else *gs, int spc,
1080 int flags)
1082 if (flags & TDF_RAW)
1083 dump_gimple_fmt (buffer, spc, flags,
1084 "%G <%+N_BODY <%S>%nE_BODY <%S>%->", gs,
1085 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1086 else
1087 dump_gimple_fmt (buffer, spc, flags,
1088 "<<<if_normal_exit>>>%+{%S}%-<<<else_eh_exit>>>%+{%S}",
1089 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1093 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
1094 indent. FLAGS specifies details to show in the dump (see TDF_* in
1095 dumpfile.h). */
1097 static void
1098 dump_gimple_resx (pretty_printer *buffer, gresx *gs, int spc, int flags)
1100 if (flags & TDF_RAW)
1101 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1102 gimple_resx_region (gs));
1103 else
1104 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
1107 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
1109 static void
1110 dump_gimple_eh_dispatch (pretty_printer *buffer, geh_dispatch *gs, int spc, int flags)
1112 if (flags & TDF_RAW)
1113 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1114 gimple_eh_dispatch_region (gs));
1115 else
1116 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
1117 gimple_eh_dispatch_region (gs));
1120 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
1121 of indent. FLAGS specifies details to show in the dump (see TDF_*
1122 in dumpfile.h). */
1124 static void
1125 dump_gimple_debug (pretty_printer *buffer, gdebug *gs, int spc, int flags)
1127 switch (gs->subcode)
1129 case GIMPLE_DEBUG_BIND:
1130 if (flags & TDF_RAW)
1131 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
1132 gimple_debug_bind_get_var (gs),
1133 gimple_debug_bind_get_value (gs));
1134 else
1135 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
1136 gimple_debug_bind_get_var (gs),
1137 gimple_debug_bind_get_value (gs));
1138 break;
1140 case GIMPLE_DEBUG_SOURCE_BIND:
1141 if (flags & TDF_RAW)
1142 dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1143 gimple_debug_source_bind_get_var (gs),
1144 gimple_debug_source_bind_get_value (gs));
1145 else
1146 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1147 gimple_debug_source_bind_get_var (gs),
1148 gimple_debug_source_bind_get_value (gs));
1149 break;
1151 default:
1152 gcc_unreachable ();
1156 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
1157 static void
1158 dump_gimple_omp_for (pretty_printer *buffer, gomp_for *gs, int spc, int flags)
1160 size_t i;
1162 if (flags & TDF_RAW)
1164 const char *kind;
1165 switch (gimple_omp_for_kind (gs))
1167 case GF_OMP_FOR_KIND_FOR:
1168 kind = "";
1169 break;
1170 case GF_OMP_FOR_KIND_DISTRIBUTE:
1171 kind = " distribute";
1172 break;
1173 case GF_OMP_FOR_KIND_TASKLOOP:
1174 kind = " taskloop";
1175 break;
1176 case GF_OMP_FOR_KIND_CILKFOR:
1177 kind = " _Cilk_for";
1178 break;
1179 case GF_OMP_FOR_KIND_OACC_LOOP:
1180 kind = " oacc_loop";
1181 break;
1182 case GF_OMP_FOR_KIND_SIMD:
1183 kind = " simd";
1184 break;
1185 case GF_OMP_FOR_KIND_CILKSIMD:
1186 kind = " cilksimd";
1187 break;
1188 default:
1189 gcc_unreachable ();
1191 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1192 kind, gimple_omp_body (gs));
1193 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1194 dump_gimple_fmt (buffer, spc, flags, " >,");
1195 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1196 dump_gimple_fmt (buffer, spc, flags,
1197 "%+%T, %T, %T, %s, %T,%n",
1198 gimple_omp_for_index (gs, i),
1199 gimple_omp_for_initial (gs, i),
1200 gimple_omp_for_final (gs, i),
1201 get_tree_code_name (gimple_omp_for_cond (gs, i)),
1202 gimple_omp_for_incr (gs, i));
1203 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1204 gimple_omp_for_pre_body (gs));
1206 else
1208 switch (gimple_omp_for_kind (gs))
1210 case GF_OMP_FOR_KIND_FOR:
1211 pp_string (buffer, "#pragma omp for");
1212 break;
1213 case GF_OMP_FOR_KIND_DISTRIBUTE:
1214 pp_string (buffer, "#pragma omp distribute");
1215 break;
1216 case GF_OMP_FOR_KIND_TASKLOOP:
1217 pp_string (buffer, "#pragma omp taskloop");
1218 break;
1219 case GF_OMP_FOR_KIND_CILKFOR:
1220 break;
1221 case GF_OMP_FOR_KIND_OACC_LOOP:
1222 pp_string (buffer, "#pragma acc loop");
1223 break;
1224 case GF_OMP_FOR_KIND_SIMD:
1225 pp_string (buffer, "#pragma omp simd");
1226 break;
1227 case GF_OMP_FOR_KIND_CILKSIMD:
1228 pp_string (buffer, "#pragma simd");
1229 break;
1230 case GF_OMP_FOR_KIND_GRID_LOOP:
1231 pp_string (buffer, "#pragma omp for grid_loop");
1232 break;
1233 default:
1234 gcc_unreachable ();
1236 if (gimple_omp_for_kind (gs) != GF_OMP_FOR_KIND_CILKFOR)
1237 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1238 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1240 if (i)
1241 spc += 2;
1242 if (gimple_omp_for_kind (gs) == GF_OMP_FOR_KIND_CILKFOR)
1243 pp_string (buffer, "_Cilk_for (");
1244 else
1246 newline_and_indent (buffer, spc);
1247 pp_string (buffer, "for (");
1249 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1250 flags, false);
1251 pp_string (buffer, " = ");
1252 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1253 flags, false);
1254 pp_string (buffer, "; ");
1256 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1257 flags, false);
1258 pp_space (buffer);
1259 switch (gimple_omp_for_cond (gs, i))
1261 case LT_EXPR:
1262 pp_less (buffer);
1263 break;
1264 case GT_EXPR:
1265 pp_greater (buffer);
1266 break;
1267 case LE_EXPR:
1268 pp_less_equal (buffer);
1269 break;
1270 case GE_EXPR:
1271 pp_greater_equal (buffer);
1272 break;
1273 case NE_EXPR:
1274 pp_string (buffer, "!=");
1275 break;
1276 default:
1277 gcc_unreachable ();
1279 pp_space (buffer);
1280 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1281 flags, false);
1282 pp_string (buffer, "; ");
1284 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1285 flags, false);
1286 pp_string (buffer, " = ");
1287 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1288 flags, false);
1289 pp_right_paren (buffer);
1292 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1294 if (gimple_omp_for_kind (gs) == GF_OMP_FOR_KIND_CILKFOR)
1295 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1296 newline_and_indent (buffer, spc + 2);
1297 pp_left_brace (buffer);
1298 pp_newline (buffer);
1299 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1300 newline_and_indent (buffer, spc + 2);
1301 pp_right_brace (buffer);
1306 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
1308 static void
1309 dump_gimple_omp_continue (pretty_printer *buffer, gomp_continue *gs,
1310 int spc, int flags)
1312 if (flags & TDF_RAW)
1314 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1315 gimple_omp_continue_control_def (gs),
1316 gimple_omp_continue_control_use (gs));
1318 else
1320 pp_string (buffer, "#pragma omp continue (");
1321 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1322 spc, flags, false);
1323 pp_comma (buffer);
1324 pp_space (buffer);
1325 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1326 spc, flags, false);
1327 pp_right_paren (buffer);
1331 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1333 static void
1334 dump_gimple_omp_single (pretty_printer *buffer, gomp_single *gs,
1335 int spc, int flags)
1337 if (flags & TDF_RAW)
1339 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1340 gimple_omp_body (gs));
1341 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1342 dump_gimple_fmt (buffer, spc, flags, " >");
1344 else
1346 pp_string (buffer, "#pragma omp single");
1347 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1348 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1350 newline_and_indent (buffer, spc + 2);
1351 pp_left_brace (buffer);
1352 pp_newline (buffer);
1353 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1354 newline_and_indent (buffer, spc + 2);
1355 pp_right_brace (buffer);
1360 /* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer BUFFER. */
1362 static void
1363 dump_gimple_omp_target (pretty_printer *buffer, gomp_target *gs,
1364 int spc, int flags)
1366 const char *kind;
1367 switch (gimple_omp_target_kind (gs))
1369 case GF_OMP_TARGET_KIND_REGION:
1370 kind = "";
1371 break;
1372 case GF_OMP_TARGET_KIND_DATA:
1373 kind = " data";
1374 break;
1375 case GF_OMP_TARGET_KIND_UPDATE:
1376 kind = " update";
1377 break;
1378 case GF_OMP_TARGET_KIND_ENTER_DATA:
1379 kind = " enter data";
1380 break;
1381 case GF_OMP_TARGET_KIND_EXIT_DATA:
1382 kind = " exit data";
1383 break;
1384 case GF_OMP_TARGET_KIND_OACC_KERNELS:
1385 kind = " oacc_kernels";
1386 break;
1387 case GF_OMP_TARGET_KIND_OACC_PARALLEL:
1388 kind = " oacc_parallel";
1389 break;
1390 case GF_OMP_TARGET_KIND_OACC_DATA:
1391 kind = " oacc_data";
1392 break;
1393 case GF_OMP_TARGET_KIND_OACC_UPDATE:
1394 kind = " oacc_update";
1395 break;
1396 case GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA:
1397 kind = " oacc_enter_exit_data";
1398 break;
1399 case GF_OMP_TARGET_KIND_OACC_DECLARE:
1400 kind = " oacc_declare";
1401 break;
1402 case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
1403 kind = " oacc_host_data";
1404 break;
1405 default:
1406 gcc_unreachable ();
1408 if (flags & TDF_RAW)
1410 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1411 kind, gimple_omp_body (gs));
1412 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1413 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1414 gimple_omp_target_child_fn (gs),
1415 gimple_omp_target_data_arg (gs));
1417 else
1419 pp_string (buffer, "#pragma omp target");
1420 pp_string (buffer, kind);
1421 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1422 if (gimple_omp_target_child_fn (gs))
1424 pp_string (buffer, " [child fn: ");
1425 dump_generic_node (buffer, gimple_omp_target_child_fn (gs),
1426 spc, flags, false);
1427 pp_string (buffer, " (");
1428 if (gimple_omp_target_data_arg (gs))
1429 dump_generic_node (buffer, gimple_omp_target_data_arg (gs),
1430 spc, flags, false);
1431 else
1432 pp_string (buffer, "???");
1433 pp_string (buffer, ")]");
1435 gimple_seq body = gimple_omp_body (gs);
1436 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1438 newline_and_indent (buffer, spc + 2);
1439 pp_left_brace (buffer);
1440 pp_newline (buffer);
1441 dump_gimple_seq (buffer, body, spc + 4, flags);
1442 newline_and_indent (buffer, spc + 2);
1443 pp_right_brace (buffer);
1445 else if (body)
1447 pp_newline (buffer);
1448 dump_gimple_seq (buffer, body, spc + 2, flags);
1453 /* Dump a GIMPLE_OMP_TEAMS tuple on the pretty_printer BUFFER. */
1455 static void
1456 dump_gimple_omp_teams (pretty_printer *buffer, gomp_teams *gs, int spc,
1457 int flags)
1459 if (flags & TDF_RAW)
1461 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1462 gimple_omp_body (gs));
1463 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1464 dump_gimple_fmt (buffer, spc, flags, " >");
1466 else
1468 pp_string (buffer, "#pragma omp teams");
1469 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1470 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1472 newline_and_indent (buffer, spc + 2);
1473 pp_character (buffer, '{');
1474 pp_newline (buffer);
1475 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1476 newline_and_indent (buffer, spc + 2);
1477 pp_character (buffer, '}');
1482 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1484 static void
1485 dump_gimple_omp_sections (pretty_printer *buffer, gomp_sections *gs,
1486 int spc, int flags)
1488 if (flags & TDF_RAW)
1490 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1491 gimple_omp_body (gs));
1492 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1493 dump_gimple_fmt (buffer, spc, flags, " >");
1495 else
1497 pp_string (buffer, "#pragma omp sections");
1498 if (gimple_omp_sections_control (gs))
1500 pp_string (buffer, " <");
1501 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1502 flags, false);
1503 pp_greater (buffer);
1505 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1506 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1508 newline_and_indent (buffer, spc + 2);
1509 pp_left_brace (buffer);
1510 pp_newline (buffer);
1511 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1512 newline_and_indent (buffer, spc + 2);
1513 pp_right_brace (buffer);
1518 /* Dump a GIMPLE_OMP_{MASTER,TASKGROUP,ORDERED,SECTION} tuple on the
1519 pretty_printer BUFFER. */
1521 static void
1522 dump_gimple_omp_block (pretty_printer *buffer, gimple *gs, int spc, int flags)
1524 if (flags & TDF_RAW)
1525 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1526 gimple_omp_body (gs));
1527 else
1529 switch (gimple_code (gs))
1531 case GIMPLE_OMP_MASTER:
1532 pp_string (buffer, "#pragma omp master");
1533 break;
1534 case GIMPLE_OMP_TASKGROUP:
1535 pp_string (buffer, "#pragma omp taskgroup");
1536 break;
1537 case GIMPLE_OMP_SECTION:
1538 pp_string (buffer, "#pragma omp section");
1539 break;
1540 case GIMPLE_OMP_GRID_BODY:
1541 pp_string (buffer, "#pragma omp gridified body");
1542 break;
1543 default:
1544 gcc_unreachable ();
1546 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1548 newline_and_indent (buffer, spc + 2);
1549 pp_left_brace (buffer);
1550 pp_newline (buffer);
1551 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1552 newline_and_indent (buffer, spc + 2);
1553 pp_right_brace (buffer);
1558 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1560 static void
1561 dump_gimple_omp_critical (pretty_printer *buffer, gomp_critical *gs,
1562 int spc, int flags)
1564 if (flags & TDF_RAW)
1565 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1566 gimple_omp_body (gs));
1567 else
1569 pp_string (buffer, "#pragma omp critical");
1570 if (gimple_omp_critical_name (gs))
1572 pp_string (buffer, " (");
1573 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1574 flags, false);
1575 pp_right_paren (buffer);
1577 dump_omp_clauses (buffer, gimple_omp_critical_clauses (gs), spc, flags);
1578 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1580 newline_and_indent (buffer, spc + 2);
1581 pp_left_brace (buffer);
1582 pp_newline (buffer);
1583 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1584 newline_and_indent (buffer, spc + 2);
1585 pp_right_brace (buffer);
1590 /* Dump a GIMPLE_OMP_ORDERED tuple on the pretty_printer BUFFER. */
1592 static void
1593 dump_gimple_omp_ordered (pretty_printer *buffer, gomp_ordered *gs,
1594 int spc, int flags)
1596 if (flags & TDF_RAW)
1597 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1598 gimple_omp_body (gs));
1599 else
1601 pp_string (buffer, "#pragma omp ordered");
1602 dump_omp_clauses (buffer, gimple_omp_ordered_clauses (gs), spc, flags);
1603 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1605 newline_and_indent (buffer, spc + 2);
1606 pp_left_brace (buffer);
1607 pp_newline (buffer);
1608 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1609 newline_and_indent (buffer, spc + 2);
1610 pp_right_brace (buffer);
1615 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1617 static void
1618 dump_gimple_omp_return (pretty_printer *buffer, gimple *gs, int spc, int flags)
1620 if (flags & TDF_RAW)
1622 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d", gs,
1623 (int) gimple_omp_return_nowait_p (gs));
1624 if (gimple_omp_return_lhs (gs))
1625 dump_gimple_fmt (buffer, spc, flags, ", lhs=%T>",
1626 gimple_omp_return_lhs (gs));
1627 else
1628 dump_gimple_fmt (buffer, spc, flags, ">");
1630 else
1632 pp_string (buffer, "#pragma omp return");
1633 if (gimple_omp_return_nowait_p (gs))
1634 pp_string (buffer, "(nowait)");
1635 if (gimple_omp_return_lhs (gs))
1637 pp_string (buffer, " (set ");
1638 dump_generic_node (buffer, gimple_omp_return_lhs (gs),
1639 spc, flags, false);
1640 pp_character (buffer, ')');
1645 /* Dump a GIMPLE_TRANSACTION tuple on the pretty_printer BUFFER. */
1647 static void
1648 dump_gimple_transaction (pretty_printer *buffer, gtransaction *gs,
1649 int spc, int flags)
1651 unsigned subcode = gimple_transaction_subcode (gs);
1653 if (flags & TDF_RAW)
1655 dump_gimple_fmt (buffer, spc, flags,
1656 "%G [SUBCODE=%x,NORM=%T,UNINST=%T,OVER=%T] "
1657 "<%+BODY <%S> >",
1658 gs, subcode, gimple_transaction_label_norm (gs),
1659 gimple_transaction_label_uninst (gs),
1660 gimple_transaction_label_over (gs),
1661 gimple_transaction_body (gs));
1663 else
1665 if (subcode & GTMA_IS_OUTER)
1666 pp_string (buffer, "__transaction_atomic [[outer]]");
1667 else if (subcode & GTMA_IS_RELAXED)
1668 pp_string (buffer, "__transaction_relaxed");
1669 else
1670 pp_string (buffer, "__transaction_atomic");
1671 subcode &= ~GTMA_DECLARATION_MASK;
1673 if (gimple_transaction_body (gs))
1675 newline_and_indent (buffer, spc + 2);
1676 pp_left_brace (buffer);
1677 pp_newline (buffer);
1678 dump_gimple_seq (buffer, gimple_transaction_body (gs),
1679 spc + 4, flags);
1680 newline_and_indent (buffer, spc + 2);
1681 pp_right_brace (buffer);
1683 else
1685 pp_string (buffer, " //");
1686 if (gimple_transaction_label_norm (gs))
1688 pp_string (buffer, " NORM=");
1689 dump_generic_node (buffer, gimple_transaction_label_norm (gs),
1690 spc, flags, false);
1692 if (gimple_transaction_label_uninst (gs))
1694 pp_string (buffer, " UNINST=");
1695 dump_generic_node (buffer, gimple_transaction_label_uninst (gs),
1696 spc, flags, false);
1698 if (gimple_transaction_label_over (gs))
1700 pp_string (buffer, " OVER=");
1701 dump_generic_node (buffer, gimple_transaction_label_over (gs),
1702 spc, flags, false);
1704 if (subcode)
1706 pp_string (buffer, " SUBCODE=[ ");
1707 if (subcode & GTMA_HAVE_ABORT)
1709 pp_string (buffer, "GTMA_HAVE_ABORT ");
1710 subcode &= ~GTMA_HAVE_ABORT;
1712 if (subcode & GTMA_HAVE_LOAD)
1714 pp_string (buffer, "GTMA_HAVE_LOAD ");
1715 subcode &= ~GTMA_HAVE_LOAD;
1717 if (subcode & GTMA_HAVE_STORE)
1719 pp_string (buffer, "GTMA_HAVE_STORE ");
1720 subcode &= ~GTMA_HAVE_STORE;
1722 if (subcode & GTMA_MAY_ENTER_IRREVOCABLE)
1724 pp_string (buffer, "GTMA_MAY_ENTER_IRREVOCABLE ");
1725 subcode &= ~GTMA_MAY_ENTER_IRREVOCABLE;
1727 if (subcode & GTMA_DOES_GO_IRREVOCABLE)
1729 pp_string (buffer, "GTMA_DOES_GO_IRREVOCABLE ");
1730 subcode &= ~GTMA_DOES_GO_IRREVOCABLE;
1732 if (subcode & GTMA_HAS_NO_INSTRUMENTATION)
1734 pp_string (buffer, "GTMA_HAS_NO_INSTRUMENTATION ");
1735 subcode &= ~GTMA_HAS_NO_INSTRUMENTATION;
1737 if (subcode)
1738 pp_printf (buffer, "0x%x ", subcode);
1739 pp_right_bracket (buffer);
1745 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1746 indent. FLAGS specifies details to show in the dump (see TDF_* in
1747 dumpfile.h). */
1749 static void
1750 dump_gimple_asm (pretty_printer *buffer, gasm *gs, int spc, int flags)
1752 unsigned int i, n, f, fields;
1754 if (flags & TDF_RAW)
1756 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1757 gimple_asm_string (gs));
1759 n = gimple_asm_noutputs (gs);
1760 if (n)
1762 newline_and_indent (buffer, spc + 2);
1763 pp_string (buffer, "OUTPUT: ");
1764 for (i = 0; i < n; i++)
1766 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1767 spc, flags, false);
1768 if (i < n - 1)
1769 pp_string (buffer, ", ");
1773 n = gimple_asm_ninputs (gs);
1774 if (n)
1776 newline_and_indent (buffer, spc + 2);
1777 pp_string (buffer, "INPUT: ");
1778 for (i = 0; i < n; i++)
1780 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1781 spc, flags, false);
1782 if (i < n - 1)
1783 pp_string (buffer, ", ");
1787 n = gimple_asm_nclobbers (gs);
1788 if (n)
1790 newline_and_indent (buffer, spc + 2);
1791 pp_string (buffer, "CLOBBER: ");
1792 for (i = 0; i < n; i++)
1794 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1795 spc, flags, false);
1796 if (i < n - 1)
1797 pp_string (buffer, ", ");
1801 n = gimple_asm_nlabels (gs);
1802 if (n)
1804 newline_and_indent (buffer, spc + 2);
1805 pp_string (buffer, "LABEL: ");
1806 for (i = 0; i < n; i++)
1808 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1809 spc, flags, false);
1810 if (i < n - 1)
1811 pp_string (buffer, ", ");
1815 newline_and_indent (buffer, spc);
1816 pp_greater (buffer);
1818 else
1820 pp_string (buffer, "__asm__");
1821 if (gimple_asm_volatile_p (gs))
1822 pp_string (buffer, " __volatile__");
1823 if (gimple_asm_nlabels (gs))
1824 pp_string (buffer, " goto");
1825 pp_string (buffer, "(\"");
1826 pp_string (buffer, gimple_asm_string (gs));
1827 pp_string (buffer, "\"");
1829 if (gimple_asm_nlabels (gs))
1830 fields = 4;
1831 else if (gimple_asm_nclobbers (gs))
1832 fields = 3;
1833 else if (gimple_asm_ninputs (gs))
1834 fields = 2;
1835 else if (gimple_asm_noutputs (gs))
1836 fields = 1;
1837 else
1838 fields = 0;
1840 for (f = 0; f < fields; ++f)
1842 pp_string (buffer, " : ");
1844 switch (f)
1846 case 0:
1847 n = gimple_asm_noutputs (gs);
1848 for (i = 0; i < n; i++)
1850 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1851 spc, flags, false);
1852 if (i < n - 1)
1853 pp_string (buffer, ", ");
1855 break;
1857 case 1:
1858 n = gimple_asm_ninputs (gs);
1859 for (i = 0; i < n; i++)
1861 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1862 spc, flags, false);
1863 if (i < n - 1)
1864 pp_string (buffer, ", ");
1866 break;
1868 case 2:
1869 n = gimple_asm_nclobbers (gs);
1870 for (i = 0; i < n; i++)
1872 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1873 spc, flags, false);
1874 if (i < n - 1)
1875 pp_string (buffer, ", ");
1877 break;
1879 case 3:
1880 n = gimple_asm_nlabels (gs);
1881 for (i = 0; i < n; i++)
1883 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1884 spc, flags, false);
1885 if (i < n - 1)
1886 pp_string (buffer, ", ");
1888 break;
1890 default:
1891 gcc_unreachable ();
1895 pp_string (buffer, ");");
1899 /* Dump ptr_info and range_info for NODE on pretty_printer BUFFER with
1900 SPC spaces of indent. */
1902 static void
1903 dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
1905 if (TREE_CODE (node) != SSA_NAME)
1906 return;
1908 if (POINTER_TYPE_P (TREE_TYPE (node))
1909 && SSA_NAME_PTR_INFO (node))
1911 unsigned int align, misalign;
1912 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (node);
1913 pp_string (buffer, "# PT = ");
1914 pp_points_to_solution (buffer, &pi->pt);
1915 newline_and_indent (buffer, spc);
1916 if (get_ptr_info_alignment (pi, &align, &misalign))
1918 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u", align, misalign);
1919 newline_and_indent (buffer, spc);
1923 if (!POINTER_TYPE_P (TREE_TYPE (node))
1924 && SSA_NAME_RANGE_INFO (node))
1926 wide_int min, max, nonzero_bits;
1927 value_range_type range_type = get_range_info (node, &min, &max);
1929 if (range_type == VR_VARYING)
1930 pp_printf (buffer, "# RANGE VR_VARYING");
1931 else if (range_type == VR_RANGE || range_type == VR_ANTI_RANGE)
1933 pp_printf (buffer, "# RANGE ");
1934 pp_printf (buffer, "%s[", range_type == VR_RANGE ? "" : "~");
1935 pp_wide_int (buffer, min, TYPE_SIGN (TREE_TYPE (node)));
1936 pp_printf (buffer, ", ");
1937 pp_wide_int (buffer, max, TYPE_SIGN (TREE_TYPE (node)));
1938 pp_printf (buffer, "]");
1940 nonzero_bits = get_nonzero_bits (node);
1941 if (nonzero_bits != -1)
1943 pp_string (buffer, " NONZERO ");
1944 pp_wide_int (buffer, nonzero_bits, UNSIGNED);
1946 newline_and_indent (buffer, spc);
1950 /* As dump_ssaname_info, but dump to FILE. */
1952 void
1953 dump_ssaname_info_to_file (FILE *file, tree node, int spc)
1955 pretty_printer buffer;
1956 pp_needs_newline (&buffer) = true;
1957 buffer.buffer->stream = file;
1958 dump_ssaname_info (&buffer, node, spc);
1959 pp_flush (&buffer);
1962 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
1963 The caller is responsible for calling pp_flush on BUFFER to finalize
1964 pretty printer. If COMMENT is true, print this after #. */
1966 static void
1967 dump_gimple_phi (pretty_printer *buffer, gphi *phi, int spc, bool comment,
1968 int flags)
1970 size_t i;
1971 tree lhs = gimple_phi_result (phi);
1973 if (flags & TDF_ALIAS)
1974 dump_ssaname_info (buffer, lhs, spc);
1976 if (comment)
1977 pp_string (buffer, "# ");
1979 if (flags & TDF_RAW)
1980 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1981 gimple_phi_result (phi));
1982 else
1984 dump_generic_node (buffer, lhs, spc, flags, false);
1985 pp_string (buffer, " = PHI <");
1987 for (i = 0; i < gimple_phi_num_args (phi); i++)
1989 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1990 dump_location (buffer, gimple_phi_arg_location (phi, i));
1991 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1992 false);
1993 pp_left_paren (buffer);
1994 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1995 pp_right_paren (buffer);
1996 if (i < gimple_phi_num_args (phi) - 1)
1997 pp_string (buffer, ", ");
1999 pp_greater (buffer);
2003 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
2004 of indent. FLAGS specifies details to show in the dump (see TDF_* in
2005 dumpfile.h). */
2007 static void
2008 dump_gimple_omp_parallel (pretty_printer *buffer, gomp_parallel *gs,
2009 int spc, int flags)
2011 if (flags & TDF_RAW)
2013 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2014 gimple_omp_body (gs));
2015 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
2016 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
2017 gimple_omp_parallel_child_fn (gs),
2018 gimple_omp_parallel_data_arg (gs));
2020 else
2022 gimple_seq body;
2023 pp_string (buffer, "#pragma omp parallel");
2024 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
2025 if (gimple_omp_parallel_child_fn (gs))
2027 pp_string (buffer, " [child fn: ");
2028 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
2029 spc, flags, false);
2030 pp_string (buffer, " (");
2031 if (gimple_omp_parallel_data_arg (gs))
2032 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
2033 spc, flags, false);
2034 else
2035 pp_string (buffer, "???");
2036 pp_string (buffer, ")]");
2038 body = gimple_omp_body (gs);
2039 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2041 newline_and_indent (buffer, spc + 2);
2042 pp_left_brace (buffer);
2043 pp_newline (buffer);
2044 dump_gimple_seq (buffer, body, spc + 4, flags);
2045 newline_and_indent (buffer, spc + 2);
2046 pp_right_brace (buffer);
2048 else if (body)
2050 pp_newline (buffer);
2051 dump_gimple_seq (buffer, body, spc + 2, flags);
2057 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
2058 of indent. FLAGS specifies details to show in the dump (see TDF_* in
2059 dumpfile.h). */
2061 static void
2062 dump_gimple_omp_task (pretty_printer *buffer, gomp_task *gs, int spc,
2063 int flags)
2065 if (flags & TDF_RAW)
2067 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2068 gimple_omp_body (gs));
2069 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2070 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
2071 gimple_omp_task_child_fn (gs),
2072 gimple_omp_task_data_arg (gs),
2073 gimple_omp_task_copy_fn (gs),
2074 gimple_omp_task_arg_size (gs),
2075 gimple_omp_task_arg_size (gs));
2077 else
2079 gimple_seq body;
2080 if (gimple_omp_task_taskloop_p (gs))
2081 pp_string (buffer, "#pragma omp taskloop");
2082 else
2083 pp_string (buffer, "#pragma omp task");
2084 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2085 if (gimple_omp_task_child_fn (gs))
2087 pp_string (buffer, " [child fn: ");
2088 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
2089 spc, flags, false);
2090 pp_string (buffer, " (");
2091 if (gimple_omp_task_data_arg (gs))
2092 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
2093 spc, flags, false);
2094 else
2095 pp_string (buffer, "???");
2096 pp_string (buffer, ")]");
2098 body = gimple_omp_body (gs);
2099 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2101 newline_and_indent (buffer, spc + 2);
2102 pp_left_brace (buffer);
2103 pp_newline (buffer);
2104 dump_gimple_seq (buffer, body, spc + 4, flags);
2105 newline_and_indent (buffer, spc + 2);
2106 pp_right_brace (buffer);
2108 else if (body)
2110 pp_newline (buffer);
2111 dump_gimple_seq (buffer, body, spc + 2, flags);
2117 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
2118 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2119 in dumpfile.h). */
2121 static void
2122 dump_gimple_omp_atomic_load (pretty_printer *buffer, gomp_atomic_load *gs,
2123 int spc, int flags)
2125 if (flags & TDF_RAW)
2127 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
2128 gimple_omp_atomic_load_lhs (gs),
2129 gimple_omp_atomic_load_rhs (gs));
2131 else
2133 pp_string (buffer, "#pragma omp atomic_load");
2134 if (gimple_omp_atomic_seq_cst_p (gs))
2135 pp_string (buffer, " seq_cst");
2136 if (gimple_omp_atomic_need_value_p (gs))
2137 pp_string (buffer, " [needed]");
2138 newline_and_indent (buffer, spc + 2);
2139 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
2140 spc, flags, false);
2141 pp_space (buffer);
2142 pp_equal (buffer);
2143 pp_space (buffer);
2144 pp_star (buffer);
2145 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
2146 spc, flags, false);
2150 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
2151 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2152 in dumpfile.h). */
2154 static void
2155 dump_gimple_omp_atomic_store (pretty_printer *buffer,
2156 gomp_atomic_store *gs, int spc, int flags)
2158 if (flags & TDF_RAW)
2160 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
2161 gimple_omp_atomic_store_val (gs));
2163 else
2165 pp_string (buffer, "#pragma omp atomic_store ");
2166 if (gimple_omp_atomic_seq_cst_p (gs))
2167 pp_string (buffer, "seq_cst ");
2168 if (gimple_omp_atomic_need_value_p (gs))
2169 pp_string (buffer, "[needed] ");
2170 pp_left_paren (buffer);
2171 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
2172 spc, flags, false);
2173 pp_right_paren (buffer);
2178 /* Dump all the memory operands for statement GS. BUFFER, SPC and
2179 FLAGS are as in pp_gimple_stmt_1. */
2181 static void
2182 dump_gimple_mem_ops (pretty_printer *buffer, gimple *gs, int spc, int flags)
2184 tree vdef = gimple_vdef (gs);
2185 tree vuse = gimple_vuse (gs);
2187 if (vdef != NULL_TREE)
2189 pp_string (buffer, "# ");
2190 dump_generic_node (buffer, vdef, spc + 2, flags, false);
2191 pp_string (buffer, " = VDEF <");
2192 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2193 pp_greater (buffer);
2194 newline_and_indent (buffer, spc);
2196 else if (vuse != NULL_TREE)
2198 pp_string (buffer, "# VUSE <");
2199 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2200 pp_greater (buffer);
2201 newline_and_indent (buffer, spc);
2206 /* Print the gimple statement GS on the pretty printer BUFFER, SPC
2207 spaces of indent. FLAGS specifies details to show in the dump (see
2208 TDF_* in dumpfile.h). The caller is responsible for calling
2209 pp_flush on BUFFER to finalize the pretty printer. */
2211 void
2212 pp_gimple_stmt_1 (pretty_printer *buffer, gimple *gs, int spc, int flags)
2214 if (!gs)
2215 return;
2217 if (flags & TDF_STMTADDR)
2218 pp_printf (buffer, "<&%p> ", (void *) gs);
2220 if ((flags & TDF_LINENO) && gimple_has_location (gs))
2221 dump_location (buffer, gimple_location (gs));
2223 if (flags & TDF_EH)
2225 int lp_nr = lookup_stmt_eh_lp (gs);
2226 if (lp_nr > 0)
2227 pp_printf (buffer, "[LP %d] ", lp_nr);
2228 else if (lp_nr < 0)
2229 pp_printf (buffer, "[MNT %d] ", -lp_nr);
2232 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
2233 && gimple_has_mem_ops (gs))
2234 dump_gimple_mem_ops (buffer, gs, spc, flags);
2236 if (gimple_has_lhs (gs)
2237 && (flags & TDF_ALIAS))
2238 dump_ssaname_info (buffer, gimple_get_lhs (gs), spc);
2240 switch (gimple_code (gs))
2242 case GIMPLE_ASM:
2243 dump_gimple_asm (buffer, as_a <gasm *> (gs), spc, flags);
2244 break;
2246 case GIMPLE_ASSIGN:
2247 dump_gimple_assign (buffer, as_a <gassign *> (gs), spc, flags);
2248 break;
2250 case GIMPLE_BIND:
2251 dump_gimple_bind (buffer, as_a <gbind *> (gs), spc, flags);
2252 break;
2254 case GIMPLE_CALL:
2255 dump_gimple_call (buffer, as_a <gcall *> (gs), spc, flags);
2256 break;
2258 case GIMPLE_COND:
2259 dump_gimple_cond (buffer, as_a <gcond *> (gs), spc, flags);
2260 break;
2262 case GIMPLE_LABEL:
2263 dump_gimple_label (buffer, as_a <glabel *> (gs), spc, flags);
2264 break;
2266 case GIMPLE_GOTO:
2267 dump_gimple_goto (buffer, as_a <ggoto *> (gs), spc, flags);
2268 break;
2270 case GIMPLE_NOP:
2271 pp_string (buffer, "GIMPLE_NOP");
2272 break;
2274 case GIMPLE_RETURN:
2275 dump_gimple_return (buffer, as_a <greturn *> (gs), spc, flags);
2276 break;
2278 case GIMPLE_SWITCH:
2279 dump_gimple_switch (buffer, as_a <gswitch *> (gs), spc, flags);
2280 break;
2282 case GIMPLE_TRY:
2283 dump_gimple_try (buffer, as_a <gtry *> (gs), spc, flags);
2284 break;
2286 case GIMPLE_PHI:
2287 dump_gimple_phi (buffer, as_a <gphi *> (gs), spc, false, flags);
2288 break;
2290 case GIMPLE_OMP_PARALLEL:
2291 dump_gimple_omp_parallel (buffer, as_a <gomp_parallel *> (gs), spc,
2292 flags);
2293 break;
2295 case GIMPLE_OMP_TASK:
2296 dump_gimple_omp_task (buffer, as_a <gomp_task *> (gs), spc, flags);
2297 break;
2299 case GIMPLE_OMP_ATOMIC_LOAD:
2300 dump_gimple_omp_atomic_load (buffer, as_a <gomp_atomic_load *> (gs),
2301 spc, flags);
2302 break;
2304 case GIMPLE_OMP_ATOMIC_STORE:
2305 dump_gimple_omp_atomic_store (buffer,
2306 as_a <gomp_atomic_store *> (gs),
2307 spc, flags);
2308 break;
2310 case GIMPLE_OMP_FOR:
2311 dump_gimple_omp_for (buffer, as_a <gomp_for *> (gs), spc, flags);
2312 break;
2314 case GIMPLE_OMP_CONTINUE:
2315 dump_gimple_omp_continue (buffer, as_a <gomp_continue *> (gs), spc,
2316 flags);
2317 break;
2319 case GIMPLE_OMP_SINGLE:
2320 dump_gimple_omp_single (buffer, as_a <gomp_single *> (gs), spc,
2321 flags);
2322 break;
2324 case GIMPLE_OMP_TARGET:
2325 dump_gimple_omp_target (buffer, as_a <gomp_target *> (gs), spc,
2326 flags);
2327 break;
2329 case GIMPLE_OMP_TEAMS:
2330 dump_gimple_omp_teams (buffer, as_a <gomp_teams *> (gs), spc,
2331 flags);
2332 break;
2334 case GIMPLE_OMP_RETURN:
2335 dump_gimple_omp_return (buffer, gs, spc, flags);
2336 break;
2338 case GIMPLE_OMP_SECTIONS:
2339 dump_gimple_omp_sections (buffer, as_a <gomp_sections *> (gs),
2340 spc, flags);
2341 break;
2343 case GIMPLE_OMP_SECTIONS_SWITCH:
2344 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
2345 break;
2347 case GIMPLE_OMP_MASTER:
2348 case GIMPLE_OMP_TASKGROUP:
2349 case GIMPLE_OMP_SECTION:
2350 case GIMPLE_OMP_GRID_BODY:
2351 dump_gimple_omp_block (buffer, gs, spc, flags);
2352 break;
2354 case GIMPLE_OMP_ORDERED:
2355 dump_gimple_omp_ordered (buffer, as_a <gomp_ordered *> (gs), spc,
2356 flags);
2357 break;
2359 case GIMPLE_OMP_CRITICAL:
2360 dump_gimple_omp_critical (buffer, as_a <gomp_critical *> (gs), spc,
2361 flags);
2362 break;
2364 case GIMPLE_CATCH:
2365 dump_gimple_catch (buffer, as_a <gcatch *> (gs), spc, flags);
2366 break;
2368 case GIMPLE_EH_FILTER:
2369 dump_gimple_eh_filter (buffer, as_a <geh_filter *> (gs), spc, flags);
2370 break;
2372 case GIMPLE_EH_MUST_NOT_THROW:
2373 dump_gimple_eh_must_not_throw (buffer,
2374 as_a <geh_mnt *> (gs),
2375 spc, flags);
2376 break;
2378 case GIMPLE_EH_ELSE:
2379 dump_gimple_eh_else (buffer, as_a <geh_else *> (gs), spc, flags);
2380 break;
2382 case GIMPLE_RESX:
2383 dump_gimple_resx (buffer, as_a <gresx *> (gs), spc, flags);
2384 break;
2386 case GIMPLE_EH_DISPATCH:
2387 dump_gimple_eh_dispatch (buffer, as_a <geh_dispatch *> (gs), spc,
2388 flags);
2389 break;
2391 case GIMPLE_DEBUG:
2392 dump_gimple_debug (buffer, as_a <gdebug *> (gs), spc, flags);
2393 break;
2395 case GIMPLE_PREDICT:
2396 pp_string (buffer, "// predicted ");
2397 if (gimple_predict_outcome (gs))
2398 pp_string (buffer, "likely by ");
2399 else
2400 pp_string (buffer, "unlikely by ");
2401 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
2402 pp_string (buffer, " predictor.");
2403 break;
2405 case GIMPLE_TRANSACTION:
2406 dump_gimple_transaction (buffer, as_a <gtransaction *> (gs), spc,
2407 flags);
2408 break;
2410 default:
2411 GIMPLE_NIY;
2416 /* Dumps header of basic block BB to OUTF indented by INDENT
2417 spaces and details described by flags. */
2419 static void
2420 dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
2422 if (flags & TDF_BLOCKS)
2424 if (flags & TDF_LINENO)
2426 gimple_stmt_iterator gsi;
2428 if (flags & TDF_COMMENT)
2429 fputs (";; ", outf);
2431 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2432 if (!is_gimple_debug (gsi_stmt (gsi))
2433 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
2435 fprintf (outf, "%*sstarting at line %d",
2436 indent, "", get_lineno (gsi_stmt (gsi)));
2437 break;
2439 if (bb->discriminator)
2440 fprintf (outf, ", discriminator %i", bb->discriminator);
2441 fputc ('\n', outf);
2444 else
2446 gimple *stmt = first_stmt (bb);
2447 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
2448 fprintf (outf, "%*s<bb %d>:\n", indent, "", bb->index);
2453 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2454 spaces. */
2456 static void
2457 dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
2458 basic_block bb ATTRIBUTE_UNUSED,
2459 int indent ATTRIBUTE_UNUSED,
2460 int flags ATTRIBUTE_UNUSED)
2462 /* There is currently no GIMPLE-specific basic block info to dump. */
2463 return;
2467 /* Dump PHI nodes of basic block BB to BUFFER with details described
2468 by FLAGS and indented by INDENT spaces. */
2470 static void
2471 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2473 gphi_iterator i;
2475 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2477 gphi *phi = i.phi ();
2478 if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2480 INDENT (indent);
2481 dump_gimple_phi (buffer, phi, indent, true, flags);
2482 pp_newline (buffer);
2488 /* Dump jump to basic block BB that is represented implicitly in the cfg
2489 to BUFFER. */
2491 static void
2492 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2494 gimple *stmt;
2496 stmt = first_stmt (bb);
2498 pp_string (buffer, "goto <bb ");
2499 pp_decimal_int (buffer, bb->index);
2500 pp_greater (buffer);
2501 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
2503 pp_string (buffer, " (");
2504 dump_generic_node (buffer,
2505 gimple_label_label (as_a <glabel *> (stmt)),
2506 0, 0, false);
2507 pp_right_paren (buffer);
2508 pp_semicolon (buffer);
2510 else
2511 pp_semicolon (buffer);
2515 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2516 by INDENT spaces, with details given by FLAGS. */
2518 static void
2519 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2520 int flags)
2522 edge e;
2523 gimple *stmt;
2525 stmt = last_stmt (bb);
2527 if (stmt && gimple_code (stmt) == GIMPLE_COND)
2529 edge true_edge, false_edge;
2531 /* When we are emitting the code or changing CFG, it is possible that
2532 the edges are not yet created. When we are using debug_bb in such
2533 a situation, we do not want it to crash. */
2534 if (EDGE_COUNT (bb->succs) != 2)
2535 return;
2536 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2538 INDENT (indent + 2);
2539 pp_cfg_jump (buffer, true_edge->dest);
2540 newline_and_indent (buffer, indent);
2541 pp_string (buffer, "else");
2542 newline_and_indent (buffer, indent + 2);
2543 pp_cfg_jump (buffer, false_edge->dest);
2544 pp_newline (buffer);
2545 return;
2548 /* If there is a fallthru edge, we may need to add an artificial
2549 goto to the dump. */
2550 e = find_fallthru_edge (bb->succs);
2552 if (e && e->dest != bb->next_bb)
2554 INDENT (indent);
2556 if ((flags & TDF_LINENO)
2557 && e->goto_locus != UNKNOWN_LOCATION)
2558 dump_location (buffer, e->goto_locus);
2560 pp_cfg_jump (buffer, e->dest);
2561 pp_newline (buffer);
2566 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2567 indented by INDENT spaces. */
2569 static void
2570 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2571 int flags)
2573 gimple_stmt_iterator gsi;
2574 gimple *stmt;
2575 int label_indent = indent - 2;
2577 if (label_indent < 0)
2578 label_indent = 0;
2580 dump_phi_nodes (buffer, bb, indent, flags);
2582 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2584 int curr_indent;
2586 stmt = gsi_stmt (gsi);
2588 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2590 INDENT (curr_indent);
2591 pp_gimple_stmt_1 (buffer, stmt, curr_indent, flags);
2592 pp_newline_and_flush (buffer);
2593 gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl));
2594 dump_histograms_for_stmt (DECL_STRUCT_FUNCTION (current_function_decl),
2595 pp_buffer (buffer)->stream, stmt);
2598 dump_implicit_edges (buffer, bb, indent, flags);
2599 pp_flush (buffer);
2603 /* Dumps basic block BB to FILE with details described by FLAGS and
2604 indented by INDENT spaces. */
2606 void
2607 gimple_dump_bb (FILE *file, basic_block bb, int indent, int flags)
2609 dump_gimple_bb_header (file, bb, indent, flags);
2610 if (bb->index >= NUM_FIXED_BLOCKS)
2612 pretty_printer buffer;
2613 pp_needs_newline (&buffer) = true;
2614 buffer.buffer->stream = file;
2615 gimple_dump_bb_buff (&buffer, bb, indent, flags);
2617 dump_gimple_bb_footer (file, bb, indent, flags);
2620 /* Dumps basic block BB to pretty-printer PP with default dump flags and
2621 no indentation, for use as a label of a DOT graph record-node.
2622 ??? Should just use gimple_dump_bb_buff here, except that value profiling
2623 histogram dumping doesn't know about pretty-printers. */
2625 void
2626 gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
2628 pp_printf (pp, "<bb %d>:\n", bb->index);
2629 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2631 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2632 gsi_next (&gsi))
2634 gphi *phi = gsi.phi ();
2635 if (!virtual_operand_p (gimple_phi_result (phi))
2636 || (dump_flags & TDF_VOPS))
2638 pp_bar (pp);
2639 pp_write_text_to_stream (pp);
2640 pp_string (pp, "# ");
2641 pp_gimple_stmt_1 (pp, phi, 0, dump_flags);
2642 pp_newline (pp);
2643 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2647 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
2648 gsi_next (&gsi))
2650 gimple *stmt = gsi_stmt (gsi);
2651 pp_bar (pp);
2652 pp_write_text_to_stream (pp);
2653 pp_gimple_stmt_1 (pp, stmt, 0, dump_flags);
2654 pp_newline (pp);
2655 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2657 dump_implicit_edges (pp, bb, 0, dump_flags);
2658 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);