2016-09-26 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / gcc / gimple-pretty-print.c
blob12d9a9c577bec60a3a461c45c1257ec71c6e1326
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 /* FALLTHRU */
521 case 3:
522 arg2 = gimple_assign_rhs2 (gs);
523 /* FALLTHRU */
524 case 2:
525 arg1 = gimple_assign_rhs1 (gs);
526 break;
527 default:
528 gcc_unreachable ();
531 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
532 get_tree_code_name (gimple_assign_rhs_code (gs)),
533 gimple_assign_lhs (gs), arg1, arg2, arg3);
535 else
537 if (!(flags & TDF_RHS_ONLY))
539 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
540 pp_space (buffer);
541 pp_equal (buffer);
543 if (gimple_assign_nontemporal_move_p (gs))
544 pp_string (buffer, "{nt}");
546 if (gimple_has_volatile_ops (gs))
547 pp_string (buffer, "{v}");
549 pp_space (buffer);
552 if (gimple_num_ops (gs) == 2)
553 dump_unary_rhs (buffer, gs, spc, flags);
554 else if (gimple_num_ops (gs) == 3)
555 dump_binary_rhs (buffer, gs, spc, flags);
556 else if (gimple_num_ops (gs) == 4)
557 dump_ternary_rhs (buffer, gs, spc, flags);
558 else
559 gcc_unreachable ();
560 if (!(flags & TDF_RHS_ONLY))
561 pp_semicolon (buffer);
566 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
567 pp_gimple_stmt_1. */
569 static void
570 dump_gimple_return (pretty_printer *buffer, greturn *gs, int spc, int flags)
572 tree t, t2;
574 t = gimple_return_retval (gs);
575 t2 = gimple_return_retbnd (gs);
576 if (flags & TDF_RAW)
577 dump_gimple_fmt (buffer, spc, flags, "%G <%T %T>", gs, t, t2);
578 else
580 pp_string (buffer, "return");
581 if (t)
583 pp_space (buffer);
584 dump_generic_node (buffer, t, spc, flags, false);
586 if (t2)
588 pp_string (buffer, ", ");
589 dump_generic_node (buffer, t2, spc, flags, false);
591 pp_semicolon (buffer);
596 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
597 dump_gimple_call. */
599 static void
600 dump_gimple_call_args (pretty_printer *buffer, gcall *gs, int flags)
602 size_t i;
604 for (i = 0; i < gimple_call_num_args (gs); i++)
606 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
607 if (i < gimple_call_num_args (gs) - 1)
608 pp_string (buffer, ", ");
611 if (gimple_call_va_arg_pack_p (gs))
613 if (gimple_call_num_args (gs) > 0)
615 pp_comma (buffer);
616 pp_space (buffer);
619 pp_string (buffer, "__builtin_va_arg_pack ()");
623 /* Dump the points-to solution *PT to BUFFER. */
625 static void
626 pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
628 if (pt->anything)
630 pp_string (buffer, "anything ");
631 return;
633 if (pt->nonlocal)
634 pp_string (buffer, "nonlocal ");
635 if (pt->escaped)
636 pp_string (buffer, "escaped ");
637 if (pt->ipa_escaped)
638 pp_string (buffer, "unit-escaped ");
639 if (pt->null)
640 pp_string (buffer, "null ");
641 if (pt->vars
642 && !bitmap_empty_p (pt->vars))
644 bitmap_iterator bi;
645 unsigned i;
646 pp_string (buffer, "{ ");
647 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
649 pp_string (buffer, "D.");
650 pp_decimal_int (buffer, i);
651 pp_space (buffer);
653 pp_right_brace (buffer);
654 if (pt->vars_contains_nonlocal
655 || pt->vars_contains_escaped
656 || pt->vars_contains_escaped_heap
657 || pt->vars_contains_restrict)
659 const char *comma = "";
660 pp_string (buffer, " (");
661 if (pt->vars_contains_nonlocal)
663 pp_string (buffer, "nonlocal");
664 comma = ", ";
666 if (pt->vars_contains_escaped)
668 pp_string (buffer, comma);
669 pp_string (buffer, "escaped");
670 comma = ", ";
672 if (pt->vars_contains_escaped_heap)
674 pp_string (buffer, comma);
675 pp_string (buffer, "escaped heap");
676 comma = ", ";
678 if (pt->vars_contains_restrict)
680 pp_string (buffer, comma);
681 pp_string (buffer, "restrict");
683 pp_string (buffer, ")");
689 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
690 pp_gimple_stmt_1. */
692 static void
693 dump_gimple_call (pretty_printer *buffer, gcall *gs, int spc, int flags)
695 tree lhs = gimple_call_lhs (gs);
696 tree fn = gimple_call_fn (gs);
698 if (flags & TDF_ALIAS)
700 struct pt_solution *pt;
701 pt = gimple_call_use_set (gs);
702 if (!pt_solution_empty_p (pt))
704 pp_string (buffer, "# USE = ");
705 pp_points_to_solution (buffer, pt);
706 newline_and_indent (buffer, spc);
708 pt = gimple_call_clobber_set (gs);
709 if (!pt_solution_empty_p (pt))
711 pp_string (buffer, "# CLB = ");
712 pp_points_to_solution (buffer, pt);
713 newline_and_indent (buffer, spc);
717 if (flags & TDF_RAW)
719 if (gimple_call_internal_p (gs))
720 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T", gs,
721 internal_fn_name (gimple_call_internal_fn (gs)), lhs);
722 else
723 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T", gs, fn, lhs);
724 if (gimple_call_num_args (gs) > 0)
726 pp_string (buffer, ", ");
727 dump_gimple_call_args (buffer, gs, flags);
729 pp_greater (buffer);
731 else
733 if (lhs && !(flags & TDF_RHS_ONLY))
735 dump_generic_node (buffer, lhs, spc, flags, false);
736 pp_string (buffer, " =");
738 if (gimple_has_volatile_ops (gs))
739 pp_string (buffer, "{v}");
741 pp_space (buffer);
743 if (gimple_call_internal_p (gs))
744 pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
745 else
746 print_call_name (buffer, fn, flags);
747 pp_string (buffer, " (");
748 dump_gimple_call_args (buffer, gs, flags);
749 pp_right_paren (buffer);
750 if (!(flags & TDF_RHS_ONLY))
751 pp_semicolon (buffer);
754 if (gimple_call_chain (gs))
756 pp_string (buffer, " [static-chain: ");
757 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
758 pp_right_bracket (buffer);
761 if (gimple_call_return_slot_opt_p (gs))
762 pp_string (buffer, " [return slot optimization]");
763 if (gimple_call_tail_p (gs))
764 pp_string (buffer, " [tail call]");
765 if (gimple_call_must_tail_p (gs))
766 pp_string (buffer, " [must tail call]");
768 if (fn == NULL)
769 return;
771 /* Dump the arguments of _ITM_beginTransaction sanely. */
772 if (TREE_CODE (fn) == ADDR_EXPR)
773 fn = TREE_OPERAND (fn, 0);
774 if (TREE_CODE (fn) == FUNCTION_DECL && decl_is_tm_clone (fn))
775 pp_string (buffer, " [tm-clone]");
776 if (TREE_CODE (fn) == FUNCTION_DECL
777 && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
778 && DECL_FUNCTION_CODE (fn) == BUILT_IN_TM_START
779 && gimple_call_num_args (gs) > 0)
781 tree t = gimple_call_arg (gs, 0);
782 unsigned HOST_WIDE_INT props;
783 gcc_assert (TREE_CODE (t) == INTEGER_CST);
785 pp_string (buffer, " [ ");
787 /* Get the transaction code properties. */
788 props = TREE_INT_CST_LOW (t);
790 if (props & PR_INSTRUMENTEDCODE)
791 pp_string (buffer, "instrumentedCode ");
792 if (props & PR_UNINSTRUMENTEDCODE)
793 pp_string (buffer, "uninstrumentedCode ");
794 if (props & PR_HASNOXMMUPDATE)
795 pp_string (buffer, "hasNoXMMUpdate ");
796 if (props & PR_HASNOABORT)
797 pp_string (buffer, "hasNoAbort ");
798 if (props & PR_HASNOIRREVOCABLE)
799 pp_string (buffer, "hasNoIrrevocable ");
800 if (props & PR_DOESGOIRREVOCABLE)
801 pp_string (buffer, "doesGoIrrevocable ");
802 if (props & PR_HASNOSIMPLEREADS)
803 pp_string (buffer, "hasNoSimpleReads ");
804 if (props & PR_AWBARRIERSOMITTED)
805 pp_string (buffer, "awBarriersOmitted ");
806 if (props & PR_RARBARRIERSOMITTED)
807 pp_string (buffer, "RaRBarriersOmitted ");
808 if (props & PR_UNDOLOGCODE)
809 pp_string (buffer, "undoLogCode ");
810 if (props & PR_PREFERUNINSTRUMENTED)
811 pp_string (buffer, "preferUninstrumented ");
812 if (props & PR_EXCEPTIONBLOCK)
813 pp_string (buffer, "exceptionBlock ");
814 if (props & PR_HASELSE)
815 pp_string (buffer, "hasElse ");
816 if (props & PR_READONLY)
817 pp_string (buffer, "readOnly ");
819 pp_right_bracket (buffer);
824 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
825 pp_gimple_stmt_1. */
827 static void
828 dump_gimple_switch (pretty_printer *buffer, gswitch *gs, int spc,
829 int flags)
831 unsigned int i;
833 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
834 if (flags & TDF_RAW)
835 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
836 gimple_switch_index (gs));
837 else
839 pp_string (buffer, "switch (");
840 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
841 pp_string (buffer, ") <");
844 for (i = 0; i < gimple_switch_num_labels (gs); i++)
846 tree case_label = gimple_switch_label (gs, i);
847 gcc_checking_assert (case_label != NULL_TREE);
848 dump_generic_node (buffer, case_label, spc, flags, false);
849 pp_space (buffer);
850 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
851 if (i < gimple_switch_num_labels (gs) - 1)
852 pp_string (buffer, ", ");
854 pp_greater (buffer);
858 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
859 pp_gimple_stmt_1. */
861 static void
862 dump_gimple_cond (pretty_printer *buffer, gcond *gs, int spc, int flags)
864 if (flags & TDF_RAW)
865 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
866 get_tree_code_name (gimple_cond_code (gs)),
867 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
868 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
869 else
871 if (!(flags & TDF_RHS_ONLY))
872 pp_string (buffer, "if (");
873 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
874 pp_space (buffer);
875 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
876 pp_space (buffer);
877 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
878 if (!(flags & TDF_RHS_ONLY))
880 pp_right_paren (buffer);
882 if (gimple_cond_true_label (gs))
884 pp_string (buffer, " goto ");
885 dump_generic_node (buffer, gimple_cond_true_label (gs),
886 spc, flags, false);
887 pp_semicolon (buffer);
889 if (gimple_cond_false_label (gs))
891 pp_string (buffer, " else goto ");
892 dump_generic_node (buffer, gimple_cond_false_label (gs),
893 spc, flags, false);
894 pp_semicolon (buffer);
901 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
902 spaces of indent. FLAGS specifies details to show in the dump (see
903 TDF_* in dumpfils.h). */
905 static void
906 dump_gimple_label (pretty_printer *buffer, glabel *gs, int spc, int flags)
908 tree label = gimple_label_label (gs);
909 if (flags & TDF_RAW)
910 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
911 else
913 dump_generic_node (buffer, label, spc, flags, false);
914 pp_colon (buffer);
916 if (DECL_NONLOCAL (label))
917 pp_string (buffer, " [non-local]");
918 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
919 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
922 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
923 spaces of indent. FLAGS specifies details to show in the dump (see
924 TDF_* in dumpfile.h). */
926 static void
927 dump_gimple_goto (pretty_printer *buffer, ggoto *gs, int spc, int flags)
929 tree label = gimple_goto_dest (gs);
930 if (flags & TDF_RAW)
931 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
932 else
933 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
937 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
938 spaces of indent. FLAGS specifies details to show in the dump (see
939 TDF_* in dumpfile.h). */
941 static void
942 dump_gimple_bind (pretty_printer *buffer, gbind *gs, int spc, int flags)
944 if (flags & TDF_RAW)
945 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
946 else
947 pp_left_brace (buffer);
948 if (!(flags & TDF_SLIM))
950 tree var;
952 for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
954 newline_and_indent (buffer, 2);
955 print_declaration (buffer, var, spc, flags);
957 if (gimple_bind_vars (gs))
958 pp_newline (buffer);
960 pp_newline (buffer);
961 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
962 newline_and_indent (buffer, spc);
963 if (flags & TDF_RAW)
964 pp_greater (buffer);
965 else
966 pp_right_brace (buffer);
970 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
971 indent. FLAGS specifies details to show in the dump (see TDF_* in
972 dumpfile.h). */
974 static void
975 dump_gimple_try (pretty_printer *buffer, gtry *gs, int spc, int flags)
977 if (flags & TDF_RAW)
979 const char *type;
980 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
981 type = "GIMPLE_TRY_CATCH";
982 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
983 type = "GIMPLE_TRY_FINALLY";
984 else
985 type = "UNKNOWN GIMPLE_TRY";
986 dump_gimple_fmt (buffer, spc, flags,
987 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
988 gimple_try_eval (gs), gimple_try_cleanup (gs));
990 else
992 pp_string (buffer, "try");
993 newline_and_indent (buffer, spc + 2);
994 pp_left_brace (buffer);
995 pp_newline (buffer);
997 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
998 newline_and_indent (buffer, spc + 2);
999 pp_right_brace (buffer);
1001 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
1003 newline_and_indent (buffer, spc);
1004 pp_string (buffer, "catch");
1005 newline_and_indent (buffer, spc + 2);
1006 pp_left_brace (buffer);
1008 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
1010 newline_and_indent (buffer, spc);
1011 pp_string (buffer, "finally");
1012 newline_and_indent (buffer, spc + 2);
1013 pp_left_brace (buffer);
1015 else
1016 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
1018 pp_newline (buffer);
1019 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
1020 newline_and_indent (buffer, spc + 2);
1021 pp_right_brace (buffer);
1026 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
1027 indent. FLAGS specifies details to show in the dump (see TDF_* in
1028 dumpfile.h). */
1030 static void
1031 dump_gimple_catch (pretty_printer *buffer, gcatch *gs, int spc, int flags)
1033 if (flags & TDF_RAW)
1034 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
1035 gimple_catch_types (gs), gimple_catch_handler (gs));
1036 else
1037 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
1038 gimple_catch_types (gs), gimple_catch_handler (gs));
1042 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
1043 indent. FLAGS specifies details to show in the dump (see TDF_* in
1044 dumpfile.h). */
1046 static void
1047 dump_gimple_eh_filter (pretty_printer *buffer, geh_filter *gs, int spc,
1048 int flags)
1050 if (flags & TDF_RAW)
1051 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
1052 gimple_eh_filter_types (gs),
1053 gimple_eh_filter_failure (gs));
1054 else
1055 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
1056 gimple_eh_filter_types (gs),
1057 gimple_eh_filter_failure (gs));
1061 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
1063 static void
1064 dump_gimple_eh_must_not_throw (pretty_printer *buffer,
1065 geh_mnt *gs, int spc, int flags)
1067 if (flags & TDF_RAW)
1068 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1069 gimple_eh_must_not_throw_fndecl (gs));
1070 else
1071 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
1072 gimple_eh_must_not_throw_fndecl (gs));
1076 /* Dump a GIMPLE_EH_ELSE tuple on the pretty_printer BUFFER, SPC spaces of
1077 indent. FLAGS specifies details to show in the dump (see TDF_* in
1078 dumpfile.h). */
1080 static void
1081 dump_gimple_eh_else (pretty_printer *buffer, geh_else *gs, int spc,
1082 int flags)
1084 if (flags & TDF_RAW)
1085 dump_gimple_fmt (buffer, spc, flags,
1086 "%G <%+N_BODY <%S>%nE_BODY <%S>%->", gs,
1087 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1088 else
1089 dump_gimple_fmt (buffer, spc, flags,
1090 "<<<if_normal_exit>>>%+{%S}%-<<<else_eh_exit>>>%+{%S}",
1091 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1095 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
1096 indent. FLAGS specifies details to show in the dump (see TDF_* in
1097 dumpfile.h). */
1099 static void
1100 dump_gimple_resx (pretty_printer *buffer, gresx *gs, int spc, int flags)
1102 if (flags & TDF_RAW)
1103 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1104 gimple_resx_region (gs));
1105 else
1106 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
1109 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
1111 static void
1112 dump_gimple_eh_dispatch (pretty_printer *buffer, geh_dispatch *gs, int spc, int flags)
1114 if (flags & TDF_RAW)
1115 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1116 gimple_eh_dispatch_region (gs));
1117 else
1118 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
1119 gimple_eh_dispatch_region (gs));
1122 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
1123 of indent. FLAGS specifies details to show in the dump (see TDF_*
1124 in dumpfile.h). */
1126 static void
1127 dump_gimple_debug (pretty_printer *buffer, gdebug *gs, int spc, int flags)
1129 switch (gs->subcode)
1131 case GIMPLE_DEBUG_BIND:
1132 if (flags & TDF_RAW)
1133 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
1134 gimple_debug_bind_get_var (gs),
1135 gimple_debug_bind_get_value (gs));
1136 else
1137 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
1138 gimple_debug_bind_get_var (gs),
1139 gimple_debug_bind_get_value (gs));
1140 break;
1142 case GIMPLE_DEBUG_SOURCE_BIND:
1143 if (flags & TDF_RAW)
1144 dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1145 gimple_debug_source_bind_get_var (gs),
1146 gimple_debug_source_bind_get_value (gs));
1147 else
1148 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1149 gimple_debug_source_bind_get_var (gs),
1150 gimple_debug_source_bind_get_value (gs));
1151 break;
1153 default:
1154 gcc_unreachable ();
1158 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
1159 static void
1160 dump_gimple_omp_for (pretty_printer *buffer, gomp_for *gs, int spc, int flags)
1162 size_t i;
1164 if (flags & TDF_RAW)
1166 const char *kind;
1167 switch (gimple_omp_for_kind (gs))
1169 case GF_OMP_FOR_KIND_FOR:
1170 kind = "";
1171 break;
1172 case GF_OMP_FOR_KIND_DISTRIBUTE:
1173 kind = " distribute";
1174 break;
1175 case GF_OMP_FOR_KIND_TASKLOOP:
1176 kind = " taskloop";
1177 break;
1178 case GF_OMP_FOR_KIND_CILKFOR:
1179 kind = " _Cilk_for";
1180 break;
1181 case GF_OMP_FOR_KIND_OACC_LOOP:
1182 kind = " oacc_loop";
1183 break;
1184 case GF_OMP_FOR_KIND_SIMD:
1185 kind = " simd";
1186 break;
1187 case GF_OMP_FOR_KIND_CILKSIMD:
1188 kind = " cilksimd";
1189 break;
1190 default:
1191 gcc_unreachable ();
1193 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1194 kind, gimple_omp_body (gs));
1195 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1196 dump_gimple_fmt (buffer, spc, flags, " >,");
1197 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1198 dump_gimple_fmt (buffer, spc, flags,
1199 "%+%T, %T, %T, %s, %T,%n",
1200 gimple_omp_for_index (gs, i),
1201 gimple_omp_for_initial (gs, i),
1202 gimple_omp_for_final (gs, i),
1203 get_tree_code_name (gimple_omp_for_cond (gs, i)),
1204 gimple_omp_for_incr (gs, i));
1205 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1206 gimple_omp_for_pre_body (gs));
1208 else
1210 switch (gimple_omp_for_kind (gs))
1212 case GF_OMP_FOR_KIND_FOR:
1213 pp_string (buffer, "#pragma omp for");
1214 break;
1215 case GF_OMP_FOR_KIND_DISTRIBUTE:
1216 pp_string (buffer, "#pragma omp distribute");
1217 break;
1218 case GF_OMP_FOR_KIND_TASKLOOP:
1219 pp_string (buffer, "#pragma omp taskloop");
1220 break;
1221 case GF_OMP_FOR_KIND_CILKFOR:
1222 break;
1223 case GF_OMP_FOR_KIND_OACC_LOOP:
1224 pp_string (buffer, "#pragma acc loop");
1225 break;
1226 case GF_OMP_FOR_KIND_SIMD:
1227 pp_string (buffer, "#pragma omp simd");
1228 break;
1229 case GF_OMP_FOR_KIND_CILKSIMD:
1230 pp_string (buffer, "#pragma simd");
1231 break;
1232 case GF_OMP_FOR_KIND_GRID_LOOP:
1233 pp_string (buffer, "#pragma omp for grid_loop");
1234 break;
1235 default:
1236 gcc_unreachable ();
1238 if (gimple_omp_for_kind (gs) != GF_OMP_FOR_KIND_CILKFOR)
1239 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1240 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1242 if (i)
1243 spc += 2;
1244 if (gimple_omp_for_kind (gs) == GF_OMP_FOR_KIND_CILKFOR)
1245 pp_string (buffer, "_Cilk_for (");
1246 else
1248 newline_and_indent (buffer, spc);
1249 pp_string (buffer, "for (");
1251 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1252 flags, false);
1253 pp_string (buffer, " = ");
1254 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1255 flags, false);
1256 pp_string (buffer, "; ");
1258 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1259 flags, false);
1260 pp_space (buffer);
1261 switch (gimple_omp_for_cond (gs, i))
1263 case LT_EXPR:
1264 pp_less (buffer);
1265 break;
1266 case GT_EXPR:
1267 pp_greater (buffer);
1268 break;
1269 case LE_EXPR:
1270 pp_less_equal (buffer);
1271 break;
1272 case GE_EXPR:
1273 pp_greater_equal (buffer);
1274 break;
1275 case NE_EXPR:
1276 pp_string (buffer, "!=");
1277 break;
1278 default:
1279 gcc_unreachable ();
1281 pp_space (buffer);
1282 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1283 flags, false);
1284 pp_string (buffer, "; ");
1286 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1287 flags, false);
1288 pp_string (buffer, " = ");
1289 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1290 flags, false);
1291 pp_right_paren (buffer);
1294 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1296 if (gimple_omp_for_kind (gs) == GF_OMP_FOR_KIND_CILKFOR)
1297 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1298 newline_and_indent (buffer, spc + 2);
1299 pp_left_brace (buffer);
1300 pp_newline (buffer);
1301 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1302 newline_and_indent (buffer, spc + 2);
1303 pp_right_brace (buffer);
1308 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
1310 static void
1311 dump_gimple_omp_continue (pretty_printer *buffer, gomp_continue *gs,
1312 int spc, int flags)
1314 if (flags & TDF_RAW)
1316 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1317 gimple_omp_continue_control_def (gs),
1318 gimple_omp_continue_control_use (gs));
1320 else
1322 pp_string (buffer, "#pragma omp continue (");
1323 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1324 spc, flags, false);
1325 pp_comma (buffer);
1326 pp_space (buffer);
1327 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1328 spc, flags, false);
1329 pp_right_paren (buffer);
1333 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1335 static void
1336 dump_gimple_omp_single (pretty_printer *buffer, gomp_single *gs,
1337 int spc, int flags)
1339 if (flags & TDF_RAW)
1341 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1342 gimple_omp_body (gs));
1343 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1344 dump_gimple_fmt (buffer, spc, flags, " >");
1346 else
1348 pp_string (buffer, "#pragma omp single");
1349 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1350 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1352 newline_and_indent (buffer, spc + 2);
1353 pp_left_brace (buffer);
1354 pp_newline (buffer);
1355 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1356 newline_and_indent (buffer, spc + 2);
1357 pp_right_brace (buffer);
1362 /* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer BUFFER. */
1364 static void
1365 dump_gimple_omp_target (pretty_printer *buffer, gomp_target *gs,
1366 int spc, int flags)
1368 const char *kind;
1369 switch (gimple_omp_target_kind (gs))
1371 case GF_OMP_TARGET_KIND_REGION:
1372 kind = "";
1373 break;
1374 case GF_OMP_TARGET_KIND_DATA:
1375 kind = " data";
1376 break;
1377 case GF_OMP_TARGET_KIND_UPDATE:
1378 kind = " update";
1379 break;
1380 case GF_OMP_TARGET_KIND_ENTER_DATA:
1381 kind = " enter data";
1382 break;
1383 case GF_OMP_TARGET_KIND_EXIT_DATA:
1384 kind = " exit data";
1385 break;
1386 case GF_OMP_TARGET_KIND_OACC_KERNELS:
1387 kind = " oacc_kernels";
1388 break;
1389 case GF_OMP_TARGET_KIND_OACC_PARALLEL:
1390 kind = " oacc_parallel";
1391 break;
1392 case GF_OMP_TARGET_KIND_OACC_DATA:
1393 kind = " oacc_data";
1394 break;
1395 case GF_OMP_TARGET_KIND_OACC_UPDATE:
1396 kind = " oacc_update";
1397 break;
1398 case GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA:
1399 kind = " oacc_enter_exit_data";
1400 break;
1401 case GF_OMP_TARGET_KIND_OACC_DECLARE:
1402 kind = " oacc_declare";
1403 break;
1404 case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
1405 kind = " oacc_host_data";
1406 break;
1407 default:
1408 gcc_unreachable ();
1410 if (flags & TDF_RAW)
1412 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1413 kind, gimple_omp_body (gs));
1414 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1415 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1416 gimple_omp_target_child_fn (gs),
1417 gimple_omp_target_data_arg (gs));
1419 else
1421 pp_string (buffer, "#pragma omp target");
1422 pp_string (buffer, kind);
1423 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1424 if (gimple_omp_target_child_fn (gs))
1426 pp_string (buffer, " [child fn: ");
1427 dump_generic_node (buffer, gimple_omp_target_child_fn (gs),
1428 spc, flags, false);
1429 pp_string (buffer, " (");
1430 if (gimple_omp_target_data_arg (gs))
1431 dump_generic_node (buffer, gimple_omp_target_data_arg (gs),
1432 spc, flags, false);
1433 else
1434 pp_string (buffer, "???");
1435 pp_string (buffer, ")]");
1437 gimple_seq body = gimple_omp_body (gs);
1438 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1440 newline_and_indent (buffer, spc + 2);
1441 pp_left_brace (buffer);
1442 pp_newline (buffer);
1443 dump_gimple_seq (buffer, body, spc + 4, flags);
1444 newline_and_indent (buffer, spc + 2);
1445 pp_right_brace (buffer);
1447 else if (body)
1449 pp_newline (buffer);
1450 dump_gimple_seq (buffer, body, spc + 2, flags);
1455 /* Dump a GIMPLE_OMP_TEAMS tuple on the pretty_printer BUFFER. */
1457 static void
1458 dump_gimple_omp_teams (pretty_printer *buffer, gomp_teams *gs, int spc,
1459 int flags)
1461 if (flags & TDF_RAW)
1463 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1464 gimple_omp_body (gs));
1465 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1466 dump_gimple_fmt (buffer, spc, flags, " >");
1468 else
1470 pp_string (buffer, "#pragma omp teams");
1471 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1472 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1474 newline_and_indent (buffer, spc + 2);
1475 pp_character (buffer, '{');
1476 pp_newline (buffer);
1477 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1478 newline_and_indent (buffer, spc + 2);
1479 pp_character (buffer, '}');
1484 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1486 static void
1487 dump_gimple_omp_sections (pretty_printer *buffer, gomp_sections *gs,
1488 int spc, int flags)
1490 if (flags & TDF_RAW)
1492 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1493 gimple_omp_body (gs));
1494 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1495 dump_gimple_fmt (buffer, spc, flags, " >");
1497 else
1499 pp_string (buffer, "#pragma omp sections");
1500 if (gimple_omp_sections_control (gs))
1502 pp_string (buffer, " <");
1503 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1504 flags, false);
1505 pp_greater (buffer);
1507 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1508 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1510 newline_and_indent (buffer, spc + 2);
1511 pp_left_brace (buffer);
1512 pp_newline (buffer);
1513 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1514 newline_and_indent (buffer, spc + 2);
1515 pp_right_brace (buffer);
1520 /* Dump a GIMPLE_OMP_{MASTER,TASKGROUP,ORDERED,SECTION} tuple on the
1521 pretty_printer BUFFER. */
1523 static void
1524 dump_gimple_omp_block (pretty_printer *buffer, gimple *gs, int spc, int flags)
1526 if (flags & TDF_RAW)
1527 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1528 gimple_omp_body (gs));
1529 else
1531 switch (gimple_code (gs))
1533 case GIMPLE_OMP_MASTER:
1534 pp_string (buffer, "#pragma omp master");
1535 break;
1536 case GIMPLE_OMP_TASKGROUP:
1537 pp_string (buffer, "#pragma omp taskgroup");
1538 break;
1539 case GIMPLE_OMP_SECTION:
1540 pp_string (buffer, "#pragma omp section");
1541 break;
1542 case GIMPLE_OMP_GRID_BODY:
1543 pp_string (buffer, "#pragma omp gridified body");
1544 break;
1545 default:
1546 gcc_unreachable ();
1548 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1550 newline_and_indent (buffer, spc + 2);
1551 pp_left_brace (buffer);
1552 pp_newline (buffer);
1553 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1554 newline_and_indent (buffer, spc + 2);
1555 pp_right_brace (buffer);
1560 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1562 static void
1563 dump_gimple_omp_critical (pretty_printer *buffer, gomp_critical *gs,
1564 int spc, int flags)
1566 if (flags & TDF_RAW)
1567 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1568 gimple_omp_body (gs));
1569 else
1571 pp_string (buffer, "#pragma omp critical");
1572 if (gimple_omp_critical_name (gs))
1574 pp_string (buffer, " (");
1575 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1576 flags, false);
1577 pp_right_paren (buffer);
1579 dump_omp_clauses (buffer, gimple_omp_critical_clauses (gs), spc, flags);
1580 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1582 newline_and_indent (buffer, spc + 2);
1583 pp_left_brace (buffer);
1584 pp_newline (buffer);
1585 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1586 newline_and_indent (buffer, spc + 2);
1587 pp_right_brace (buffer);
1592 /* Dump a GIMPLE_OMP_ORDERED tuple on the pretty_printer BUFFER. */
1594 static void
1595 dump_gimple_omp_ordered (pretty_printer *buffer, gomp_ordered *gs,
1596 int spc, int flags)
1598 if (flags & TDF_RAW)
1599 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1600 gimple_omp_body (gs));
1601 else
1603 pp_string (buffer, "#pragma omp ordered");
1604 dump_omp_clauses (buffer, gimple_omp_ordered_clauses (gs), spc, flags);
1605 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1607 newline_and_indent (buffer, spc + 2);
1608 pp_left_brace (buffer);
1609 pp_newline (buffer);
1610 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1611 newline_and_indent (buffer, spc + 2);
1612 pp_right_brace (buffer);
1617 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1619 static void
1620 dump_gimple_omp_return (pretty_printer *buffer, gimple *gs, int spc, int flags)
1622 if (flags & TDF_RAW)
1624 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d", gs,
1625 (int) gimple_omp_return_nowait_p (gs));
1626 if (gimple_omp_return_lhs (gs))
1627 dump_gimple_fmt (buffer, spc, flags, ", lhs=%T>",
1628 gimple_omp_return_lhs (gs));
1629 else
1630 dump_gimple_fmt (buffer, spc, flags, ">");
1632 else
1634 pp_string (buffer, "#pragma omp return");
1635 if (gimple_omp_return_nowait_p (gs))
1636 pp_string (buffer, "(nowait)");
1637 if (gimple_omp_return_lhs (gs))
1639 pp_string (buffer, " (set ");
1640 dump_generic_node (buffer, gimple_omp_return_lhs (gs),
1641 spc, flags, false);
1642 pp_character (buffer, ')');
1647 /* Dump a GIMPLE_TRANSACTION tuple on the pretty_printer BUFFER. */
1649 static void
1650 dump_gimple_transaction (pretty_printer *buffer, gtransaction *gs,
1651 int spc, int flags)
1653 unsigned subcode = gimple_transaction_subcode (gs);
1655 if (flags & TDF_RAW)
1657 dump_gimple_fmt (buffer, spc, flags,
1658 "%G [SUBCODE=%x,NORM=%T,UNINST=%T,OVER=%T] "
1659 "<%+BODY <%S> >",
1660 gs, subcode, gimple_transaction_label_norm (gs),
1661 gimple_transaction_label_uninst (gs),
1662 gimple_transaction_label_over (gs),
1663 gimple_transaction_body (gs));
1665 else
1667 if (subcode & GTMA_IS_OUTER)
1668 pp_string (buffer, "__transaction_atomic [[outer]]");
1669 else if (subcode & GTMA_IS_RELAXED)
1670 pp_string (buffer, "__transaction_relaxed");
1671 else
1672 pp_string (buffer, "__transaction_atomic");
1673 subcode &= ~GTMA_DECLARATION_MASK;
1675 if (gimple_transaction_body (gs))
1677 newline_and_indent (buffer, spc + 2);
1678 pp_left_brace (buffer);
1679 pp_newline (buffer);
1680 dump_gimple_seq (buffer, gimple_transaction_body (gs),
1681 spc + 4, flags);
1682 newline_and_indent (buffer, spc + 2);
1683 pp_right_brace (buffer);
1685 else
1687 pp_string (buffer, " //");
1688 if (gimple_transaction_label_norm (gs))
1690 pp_string (buffer, " NORM=");
1691 dump_generic_node (buffer, gimple_transaction_label_norm (gs),
1692 spc, flags, false);
1694 if (gimple_transaction_label_uninst (gs))
1696 pp_string (buffer, " UNINST=");
1697 dump_generic_node (buffer, gimple_transaction_label_uninst (gs),
1698 spc, flags, false);
1700 if (gimple_transaction_label_over (gs))
1702 pp_string (buffer, " OVER=");
1703 dump_generic_node (buffer, gimple_transaction_label_over (gs),
1704 spc, flags, false);
1706 if (subcode)
1708 pp_string (buffer, " SUBCODE=[ ");
1709 if (subcode & GTMA_HAVE_ABORT)
1711 pp_string (buffer, "GTMA_HAVE_ABORT ");
1712 subcode &= ~GTMA_HAVE_ABORT;
1714 if (subcode & GTMA_HAVE_LOAD)
1716 pp_string (buffer, "GTMA_HAVE_LOAD ");
1717 subcode &= ~GTMA_HAVE_LOAD;
1719 if (subcode & GTMA_HAVE_STORE)
1721 pp_string (buffer, "GTMA_HAVE_STORE ");
1722 subcode &= ~GTMA_HAVE_STORE;
1724 if (subcode & GTMA_MAY_ENTER_IRREVOCABLE)
1726 pp_string (buffer, "GTMA_MAY_ENTER_IRREVOCABLE ");
1727 subcode &= ~GTMA_MAY_ENTER_IRREVOCABLE;
1729 if (subcode & GTMA_DOES_GO_IRREVOCABLE)
1731 pp_string (buffer, "GTMA_DOES_GO_IRREVOCABLE ");
1732 subcode &= ~GTMA_DOES_GO_IRREVOCABLE;
1734 if (subcode & GTMA_HAS_NO_INSTRUMENTATION)
1736 pp_string (buffer, "GTMA_HAS_NO_INSTRUMENTATION ");
1737 subcode &= ~GTMA_HAS_NO_INSTRUMENTATION;
1739 if (subcode)
1740 pp_printf (buffer, "0x%x ", subcode);
1741 pp_right_bracket (buffer);
1747 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1748 indent. FLAGS specifies details to show in the dump (see TDF_* in
1749 dumpfile.h). */
1751 static void
1752 dump_gimple_asm (pretty_printer *buffer, gasm *gs, int spc, int flags)
1754 unsigned int i, n, f, fields;
1756 if (flags & TDF_RAW)
1758 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1759 gimple_asm_string (gs));
1761 n = gimple_asm_noutputs (gs);
1762 if (n)
1764 newline_and_indent (buffer, spc + 2);
1765 pp_string (buffer, "OUTPUT: ");
1766 for (i = 0; i < n; i++)
1768 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1769 spc, flags, false);
1770 if (i < n - 1)
1771 pp_string (buffer, ", ");
1775 n = gimple_asm_ninputs (gs);
1776 if (n)
1778 newline_and_indent (buffer, spc + 2);
1779 pp_string (buffer, "INPUT: ");
1780 for (i = 0; i < n; i++)
1782 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1783 spc, flags, false);
1784 if (i < n - 1)
1785 pp_string (buffer, ", ");
1789 n = gimple_asm_nclobbers (gs);
1790 if (n)
1792 newline_and_indent (buffer, spc + 2);
1793 pp_string (buffer, "CLOBBER: ");
1794 for (i = 0; i < n; i++)
1796 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1797 spc, flags, false);
1798 if (i < n - 1)
1799 pp_string (buffer, ", ");
1803 n = gimple_asm_nlabels (gs);
1804 if (n)
1806 newline_and_indent (buffer, spc + 2);
1807 pp_string (buffer, "LABEL: ");
1808 for (i = 0; i < n; i++)
1810 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1811 spc, flags, false);
1812 if (i < n - 1)
1813 pp_string (buffer, ", ");
1817 newline_and_indent (buffer, spc);
1818 pp_greater (buffer);
1820 else
1822 pp_string (buffer, "__asm__");
1823 if (gimple_asm_volatile_p (gs))
1824 pp_string (buffer, " __volatile__");
1825 if (gimple_asm_nlabels (gs))
1826 pp_string (buffer, " goto");
1827 pp_string (buffer, "(\"");
1828 pp_string (buffer, gimple_asm_string (gs));
1829 pp_string (buffer, "\"");
1831 if (gimple_asm_nlabels (gs))
1832 fields = 4;
1833 else if (gimple_asm_nclobbers (gs))
1834 fields = 3;
1835 else if (gimple_asm_ninputs (gs))
1836 fields = 2;
1837 else if (gimple_asm_noutputs (gs))
1838 fields = 1;
1839 else
1840 fields = 0;
1842 for (f = 0; f < fields; ++f)
1844 pp_string (buffer, " : ");
1846 switch (f)
1848 case 0:
1849 n = gimple_asm_noutputs (gs);
1850 for (i = 0; i < n; i++)
1852 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1853 spc, flags, false);
1854 if (i < n - 1)
1855 pp_string (buffer, ", ");
1857 break;
1859 case 1:
1860 n = gimple_asm_ninputs (gs);
1861 for (i = 0; i < n; i++)
1863 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1864 spc, flags, false);
1865 if (i < n - 1)
1866 pp_string (buffer, ", ");
1868 break;
1870 case 2:
1871 n = gimple_asm_nclobbers (gs);
1872 for (i = 0; i < n; i++)
1874 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1875 spc, flags, false);
1876 if (i < n - 1)
1877 pp_string (buffer, ", ");
1879 break;
1881 case 3:
1882 n = gimple_asm_nlabels (gs);
1883 for (i = 0; i < n; i++)
1885 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1886 spc, flags, false);
1887 if (i < n - 1)
1888 pp_string (buffer, ", ");
1890 break;
1892 default:
1893 gcc_unreachable ();
1897 pp_string (buffer, ");");
1901 /* Dump ptr_info and range_info for NODE on pretty_printer BUFFER with
1902 SPC spaces of indent. */
1904 static void
1905 dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
1907 if (TREE_CODE (node) != SSA_NAME)
1908 return;
1910 if (POINTER_TYPE_P (TREE_TYPE (node))
1911 && SSA_NAME_PTR_INFO (node))
1913 unsigned int align, misalign;
1914 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (node);
1915 pp_string (buffer, "# PT = ");
1916 pp_points_to_solution (buffer, &pi->pt);
1917 newline_and_indent (buffer, spc);
1918 if (get_ptr_info_alignment (pi, &align, &misalign))
1920 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u", align, misalign);
1921 newline_and_indent (buffer, spc);
1925 if (!POINTER_TYPE_P (TREE_TYPE (node))
1926 && SSA_NAME_RANGE_INFO (node))
1928 wide_int min, max, nonzero_bits;
1929 value_range_type range_type = get_range_info (node, &min, &max);
1931 if (range_type == VR_VARYING)
1932 pp_printf (buffer, "# RANGE VR_VARYING");
1933 else if (range_type == VR_RANGE || range_type == VR_ANTI_RANGE)
1935 pp_printf (buffer, "# RANGE ");
1936 pp_printf (buffer, "%s[", range_type == VR_RANGE ? "" : "~");
1937 pp_wide_int (buffer, min, TYPE_SIGN (TREE_TYPE (node)));
1938 pp_printf (buffer, ", ");
1939 pp_wide_int (buffer, max, TYPE_SIGN (TREE_TYPE (node)));
1940 pp_printf (buffer, "]");
1942 nonzero_bits = get_nonzero_bits (node);
1943 if (nonzero_bits != -1)
1945 pp_string (buffer, " NONZERO ");
1946 pp_wide_int (buffer, nonzero_bits, UNSIGNED);
1948 newline_and_indent (buffer, spc);
1952 /* As dump_ssaname_info, but dump to FILE. */
1954 void
1955 dump_ssaname_info_to_file (FILE *file, tree node, int spc)
1957 pretty_printer buffer;
1958 pp_needs_newline (&buffer) = true;
1959 buffer.buffer->stream = file;
1960 dump_ssaname_info (&buffer, node, spc);
1961 pp_flush (&buffer);
1964 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
1965 The caller is responsible for calling pp_flush on BUFFER to finalize
1966 pretty printer. If COMMENT is true, print this after #. */
1968 static void
1969 dump_gimple_phi (pretty_printer *buffer, gphi *phi, int spc, bool comment,
1970 int flags)
1972 size_t i;
1973 tree lhs = gimple_phi_result (phi);
1975 if (flags & TDF_ALIAS)
1976 dump_ssaname_info (buffer, lhs, spc);
1978 if (comment)
1979 pp_string (buffer, "# ");
1981 if (flags & TDF_RAW)
1982 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1983 gimple_phi_result (phi));
1984 else
1986 dump_generic_node (buffer, lhs, spc, flags, false);
1987 pp_string (buffer, " = PHI <");
1989 for (i = 0; i < gimple_phi_num_args (phi); i++)
1991 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1992 dump_location (buffer, gimple_phi_arg_location (phi, i));
1993 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1994 false);
1995 pp_left_paren (buffer);
1996 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1997 pp_right_paren (buffer);
1998 if (i < gimple_phi_num_args (phi) - 1)
1999 pp_string (buffer, ", ");
2001 pp_greater (buffer);
2005 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
2006 of indent. FLAGS specifies details to show in the dump (see TDF_* in
2007 dumpfile.h). */
2009 static void
2010 dump_gimple_omp_parallel (pretty_printer *buffer, gomp_parallel *gs,
2011 int spc, int flags)
2013 if (flags & TDF_RAW)
2015 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2016 gimple_omp_body (gs));
2017 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
2018 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
2019 gimple_omp_parallel_child_fn (gs),
2020 gimple_omp_parallel_data_arg (gs));
2022 else
2024 gimple_seq body;
2025 pp_string (buffer, "#pragma omp parallel");
2026 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
2027 if (gimple_omp_parallel_child_fn (gs))
2029 pp_string (buffer, " [child fn: ");
2030 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
2031 spc, flags, false);
2032 pp_string (buffer, " (");
2033 if (gimple_omp_parallel_data_arg (gs))
2034 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
2035 spc, flags, false);
2036 else
2037 pp_string (buffer, "???");
2038 pp_string (buffer, ")]");
2040 body = gimple_omp_body (gs);
2041 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2043 newline_and_indent (buffer, spc + 2);
2044 pp_left_brace (buffer);
2045 pp_newline (buffer);
2046 dump_gimple_seq (buffer, body, spc + 4, flags);
2047 newline_and_indent (buffer, spc + 2);
2048 pp_right_brace (buffer);
2050 else if (body)
2052 pp_newline (buffer);
2053 dump_gimple_seq (buffer, body, spc + 2, flags);
2059 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
2060 of indent. FLAGS specifies details to show in the dump (see TDF_* in
2061 dumpfile.h). */
2063 static void
2064 dump_gimple_omp_task (pretty_printer *buffer, gomp_task *gs, int spc,
2065 int flags)
2067 if (flags & TDF_RAW)
2069 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2070 gimple_omp_body (gs));
2071 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2072 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
2073 gimple_omp_task_child_fn (gs),
2074 gimple_omp_task_data_arg (gs),
2075 gimple_omp_task_copy_fn (gs),
2076 gimple_omp_task_arg_size (gs),
2077 gimple_omp_task_arg_size (gs));
2079 else
2081 gimple_seq body;
2082 if (gimple_omp_task_taskloop_p (gs))
2083 pp_string (buffer, "#pragma omp taskloop");
2084 else
2085 pp_string (buffer, "#pragma omp task");
2086 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2087 if (gimple_omp_task_child_fn (gs))
2089 pp_string (buffer, " [child fn: ");
2090 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
2091 spc, flags, false);
2092 pp_string (buffer, " (");
2093 if (gimple_omp_task_data_arg (gs))
2094 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
2095 spc, flags, false);
2096 else
2097 pp_string (buffer, "???");
2098 pp_string (buffer, ")]");
2100 body = gimple_omp_body (gs);
2101 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2103 newline_and_indent (buffer, spc + 2);
2104 pp_left_brace (buffer);
2105 pp_newline (buffer);
2106 dump_gimple_seq (buffer, body, spc + 4, flags);
2107 newline_and_indent (buffer, spc + 2);
2108 pp_right_brace (buffer);
2110 else if (body)
2112 pp_newline (buffer);
2113 dump_gimple_seq (buffer, body, spc + 2, flags);
2119 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
2120 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2121 in dumpfile.h). */
2123 static void
2124 dump_gimple_omp_atomic_load (pretty_printer *buffer, gomp_atomic_load *gs,
2125 int spc, int flags)
2127 if (flags & TDF_RAW)
2129 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
2130 gimple_omp_atomic_load_lhs (gs),
2131 gimple_omp_atomic_load_rhs (gs));
2133 else
2135 pp_string (buffer, "#pragma omp atomic_load");
2136 if (gimple_omp_atomic_seq_cst_p (gs))
2137 pp_string (buffer, " seq_cst");
2138 if (gimple_omp_atomic_need_value_p (gs))
2139 pp_string (buffer, " [needed]");
2140 newline_and_indent (buffer, spc + 2);
2141 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
2142 spc, flags, false);
2143 pp_space (buffer);
2144 pp_equal (buffer);
2145 pp_space (buffer);
2146 pp_star (buffer);
2147 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
2148 spc, flags, false);
2152 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
2153 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2154 in dumpfile.h). */
2156 static void
2157 dump_gimple_omp_atomic_store (pretty_printer *buffer,
2158 gomp_atomic_store *gs, int spc, int flags)
2160 if (flags & TDF_RAW)
2162 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
2163 gimple_omp_atomic_store_val (gs));
2165 else
2167 pp_string (buffer, "#pragma omp atomic_store ");
2168 if (gimple_omp_atomic_seq_cst_p (gs))
2169 pp_string (buffer, "seq_cst ");
2170 if (gimple_omp_atomic_need_value_p (gs))
2171 pp_string (buffer, "[needed] ");
2172 pp_left_paren (buffer);
2173 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
2174 spc, flags, false);
2175 pp_right_paren (buffer);
2180 /* Dump all the memory operands for statement GS. BUFFER, SPC and
2181 FLAGS are as in pp_gimple_stmt_1. */
2183 static void
2184 dump_gimple_mem_ops (pretty_printer *buffer, gimple *gs, int spc, int flags)
2186 tree vdef = gimple_vdef (gs);
2187 tree vuse = gimple_vuse (gs);
2189 if (vdef != NULL_TREE)
2191 pp_string (buffer, "# ");
2192 dump_generic_node (buffer, vdef, spc + 2, flags, false);
2193 pp_string (buffer, " = VDEF <");
2194 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2195 pp_greater (buffer);
2196 newline_and_indent (buffer, spc);
2198 else if (vuse != NULL_TREE)
2200 pp_string (buffer, "# VUSE <");
2201 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2202 pp_greater (buffer);
2203 newline_and_indent (buffer, spc);
2208 /* Print the gimple statement GS on the pretty printer BUFFER, SPC
2209 spaces of indent. FLAGS specifies details to show in the dump (see
2210 TDF_* in dumpfile.h). The caller is responsible for calling
2211 pp_flush on BUFFER to finalize the pretty printer. */
2213 void
2214 pp_gimple_stmt_1 (pretty_printer *buffer, gimple *gs, int spc, int flags)
2216 if (!gs)
2217 return;
2219 if (flags & TDF_STMTADDR)
2220 pp_printf (buffer, "<&%p> ", (void *) gs);
2222 if ((flags & TDF_LINENO) && gimple_has_location (gs))
2223 dump_location (buffer, gimple_location (gs));
2225 if (flags & TDF_EH)
2227 int lp_nr = lookup_stmt_eh_lp (gs);
2228 if (lp_nr > 0)
2229 pp_printf (buffer, "[LP %d] ", lp_nr);
2230 else if (lp_nr < 0)
2231 pp_printf (buffer, "[MNT %d] ", -lp_nr);
2234 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
2235 && gimple_has_mem_ops (gs))
2236 dump_gimple_mem_ops (buffer, gs, spc, flags);
2238 if (gimple_has_lhs (gs)
2239 && (flags & TDF_ALIAS))
2240 dump_ssaname_info (buffer, gimple_get_lhs (gs), spc);
2242 switch (gimple_code (gs))
2244 case GIMPLE_ASM:
2245 dump_gimple_asm (buffer, as_a <gasm *> (gs), spc, flags);
2246 break;
2248 case GIMPLE_ASSIGN:
2249 dump_gimple_assign (buffer, as_a <gassign *> (gs), spc, flags);
2250 break;
2252 case GIMPLE_BIND:
2253 dump_gimple_bind (buffer, as_a <gbind *> (gs), spc, flags);
2254 break;
2256 case GIMPLE_CALL:
2257 dump_gimple_call (buffer, as_a <gcall *> (gs), spc, flags);
2258 break;
2260 case GIMPLE_COND:
2261 dump_gimple_cond (buffer, as_a <gcond *> (gs), spc, flags);
2262 break;
2264 case GIMPLE_LABEL:
2265 dump_gimple_label (buffer, as_a <glabel *> (gs), spc, flags);
2266 break;
2268 case GIMPLE_GOTO:
2269 dump_gimple_goto (buffer, as_a <ggoto *> (gs), spc, flags);
2270 break;
2272 case GIMPLE_NOP:
2273 pp_string (buffer, "GIMPLE_NOP");
2274 break;
2276 case GIMPLE_RETURN:
2277 dump_gimple_return (buffer, as_a <greturn *> (gs), spc, flags);
2278 break;
2280 case GIMPLE_SWITCH:
2281 dump_gimple_switch (buffer, as_a <gswitch *> (gs), spc, flags);
2282 break;
2284 case GIMPLE_TRY:
2285 dump_gimple_try (buffer, as_a <gtry *> (gs), spc, flags);
2286 break;
2288 case GIMPLE_PHI:
2289 dump_gimple_phi (buffer, as_a <gphi *> (gs), spc, false, flags);
2290 break;
2292 case GIMPLE_OMP_PARALLEL:
2293 dump_gimple_omp_parallel (buffer, as_a <gomp_parallel *> (gs), spc,
2294 flags);
2295 break;
2297 case GIMPLE_OMP_TASK:
2298 dump_gimple_omp_task (buffer, as_a <gomp_task *> (gs), spc, flags);
2299 break;
2301 case GIMPLE_OMP_ATOMIC_LOAD:
2302 dump_gimple_omp_atomic_load (buffer, as_a <gomp_atomic_load *> (gs),
2303 spc, flags);
2304 break;
2306 case GIMPLE_OMP_ATOMIC_STORE:
2307 dump_gimple_omp_atomic_store (buffer,
2308 as_a <gomp_atomic_store *> (gs),
2309 spc, flags);
2310 break;
2312 case GIMPLE_OMP_FOR:
2313 dump_gimple_omp_for (buffer, as_a <gomp_for *> (gs), spc, flags);
2314 break;
2316 case GIMPLE_OMP_CONTINUE:
2317 dump_gimple_omp_continue (buffer, as_a <gomp_continue *> (gs), spc,
2318 flags);
2319 break;
2321 case GIMPLE_OMP_SINGLE:
2322 dump_gimple_omp_single (buffer, as_a <gomp_single *> (gs), spc,
2323 flags);
2324 break;
2326 case GIMPLE_OMP_TARGET:
2327 dump_gimple_omp_target (buffer, as_a <gomp_target *> (gs), spc,
2328 flags);
2329 break;
2331 case GIMPLE_OMP_TEAMS:
2332 dump_gimple_omp_teams (buffer, as_a <gomp_teams *> (gs), spc,
2333 flags);
2334 break;
2336 case GIMPLE_OMP_RETURN:
2337 dump_gimple_omp_return (buffer, gs, spc, flags);
2338 break;
2340 case GIMPLE_OMP_SECTIONS:
2341 dump_gimple_omp_sections (buffer, as_a <gomp_sections *> (gs),
2342 spc, flags);
2343 break;
2345 case GIMPLE_OMP_SECTIONS_SWITCH:
2346 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
2347 break;
2349 case GIMPLE_OMP_MASTER:
2350 case GIMPLE_OMP_TASKGROUP:
2351 case GIMPLE_OMP_SECTION:
2352 case GIMPLE_OMP_GRID_BODY:
2353 dump_gimple_omp_block (buffer, gs, spc, flags);
2354 break;
2356 case GIMPLE_OMP_ORDERED:
2357 dump_gimple_omp_ordered (buffer, as_a <gomp_ordered *> (gs), spc,
2358 flags);
2359 break;
2361 case GIMPLE_OMP_CRITICAL:
2362 dump_gimple_omp_critical (buffer, as_a <gomp_critical *> (gs), spc,
2363 flags);
2364 break;
2366 case GIMPLE_CATCH:
2367 dump_gimple_catch (buffer, as_a <gcatch *> (gs), spc, flags);
2368 break;
2370 case GIMPLE_EH_FILTER:
2371 dump_gimple_eh_filter (buffer, as_a <geh_filter *> (gs), spc, flags);
2372 break;
2374 case GIMPLE_EH_MUST_NOT_THROW:
2375 dump_gimple_eh_must_not_throw (buffer,
2376 as_a <geh_mnt *> (gs),
2377 spc, flags);
2378 break;
2380 case GIMPLE_EH_ELSE:
2381 dump_gimple_eh_else (buffer, as_a <geh_else *> (gs), spc, flags);
2382 break;
2384 case GIMPLE_RESX:
2385 dump_gimple_resx (buffer, as_a <gresx *> (gs), spc, flags);
2386 break;
2388 case GIMPLE_EH_DISPATCH:
2389 dump_gimple_eh_dispatch (buffer, as_a <geh_dispatch *> (gs), spc,
2390 flags);
2391 break;
2393 case GIMPLE_DEBUG:
2394 dump_gimple_debug (buffer, as_a <gdebug *> (gs), spc, flags);
2395 break;
2397 case GIMPLE_PREDICT:
2398 pp_string (buffer, "// predicted ");
2399 if (gimple_predict_outcome (gs))
2400 pp_string (buffer, "likely by ");
2401 else
2402 pp_string (buffer, "unlikely by ");
2403 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
2404 pp_string (buffer, " predictor.");
2405 break;
2407 case GIMPLE_TRANSACTION:
2408 dump_gimple_transaction (buffer, as_a <gtransaction *> (gs), spc,
2409 flags);
2410 break;
2412 default:
2413 GIMPLE_NIY;
2418 /* Dumps header of basic block BB to OUTF indented by INDENT
2419 spaces and details described by flags. */
2421 static void
2422 dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
2424 if (flags & TDF_BLOCKS)
2426 if (flags & TDF_LINENO)
2428 gimple_stmt_iterator gsi;
2430 if (flags & TDF_COMMENT)
2431 fputs (";; ", outf);
2433 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2434 if (!is_gimple_debug (gsi_stmt (gsi))
2435 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
2437 fprintf (outf, "%*sstarting at line %d",
2438 indent, "", get_lineno (gsi_stmt (gsi)));
2439 break;
2441 if (bb->discriminator)
2442 fprintf (outf, ", discriminator %i", bb->discriminator);
2443 fputc ('\n', outf);
2446 else
2448 gimple *stmt = first_stmt (bb);
2449 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
2450 fprintf (outf, "%*s<bb %d>:\n", indent, "", bb->index);
2455 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2456 spaces. */
2458 static void
2459 dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
2460 basic_block bb ATTRIBUTE_UNUSED,
2461 int indent ATTRIBUTE_UNUSED,
2462 int flags ATTRIBUTE_UNUSED)
2464 /* There is currently no GIMPLE-specific basic block info to dump. */
2465 return;
2469 /* Dump PHI nodes of basic block BB to BUFFER with details described
2470 by FLAGS and indented by INDENT spaces. */
2472 static void
2473 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2475 gphi_iterator i;
2477 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2479 gphi *phi = i.phi ();
2480 if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2482 INDENT (indent);
2483 dump_gimple_phi (buffer, phi, indent, true, flags);
2484 pp_newline (buffer);
2490 /* Dump jump to basic block BB that is represented implicitly in the cfg
2491 to BUFFER. */
2493 static void
2494 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2496 gimple *stmt;
2498 stmt = first_stmt (bb);
2500 pp_string (buffer, "goto <bb ");
2501 pp_decimal_int (buffer, bb->index);
2502 pp_greater (buffer);
2503 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
2505 pp_string (buffer, " (");
2506 dump_generic_node (buffer,
2507 gimple_label_label (as_a <glabel *> (stmt)),
2508 0, 0, false);
2509 pp_right_paren (buffer);
2510 pp_semicolon (buffer);
2512 else
2513 pp_semicolon (buffer);
2517 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2518 by INDENT spaces, with details given by FLAGS. */
2520 static void
2521 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2522 int flags)
2524 edge e;
2525 gimple *stmt;
2527 stmt = last_stmt (bb);
2529 if (stmt && gimple_code (stmt) == GIMPLE_COND)
2531 edge true_edge, false_edge;
2533 /* When we are emitting the code or changing CFG, it is possible that
2534 the edges are not yet created. When we are using debug_bb in such
2535 a situation, we do not want it to crash. */
2536 if (EDGE_COUNT (bb->succs) != 2)
2537 return;
2538 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2540 INDENT (indent + 2);
2541 pp_cfg_jump (buffer, true_edge->dest);
2542 newline_and_indent (buffer, indent);
2543 pp_string (buffer, "else");
2544 newline_and_indent (buffer, indent + 2);
2545 pp_cfg_jump (buffer, false_edge->dest);
2546 pp_newline (buffer);
2547 return;
2550 /* If there is a fallthru edge, we may need to add an artificial
2551 goto to the dump. */
2552 e = find_fallthru_edge (bb->succs);
2554 if (e && e->dest != bb->next_bb)
2556 INDENT (indent);
2558 if ((flags & TDF_LINENO)
2559 && e->goto_locus != UNKNOWN_LOCATION)
2560 dump_location (buffer, e->goto_locus);
2562 pp_cfg_jump (buffer, e->dest);
2563 pp_newline (buffer);
2568 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2569 indented by INDENT spaces. */
2571 static void
2572 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2573 int flags)
2575 gimple_stmt_iterator gsi;
2576 gimple *stmt;
2577 int label_indent = indent - 2;
2579 if (label_indent < 0)
2580 label_indent = 0;
2582 dump_phi_nodes (buffer, bb, indent, flags);
2584 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2586 int curr_indent;
2588 stmt = gsi_stmt (gsi);
2590 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2592 INDENT (curr_indent);
2593 pp_gimple_stmt_1 (buffer, stmt, curr_indent, flags);
2594 pp_newline_and_flush (buffer);
2595 gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl));
2596 dump_histograms_for_stmt (DECL_STRUCT_FUNCTION (current_function_decl),
2597 pp_buffer (buffer)->stream, stmt);
2600 dump_implicit_edges (buffer, bb, indent, flags);
2601 pp_flush (buffer);
2605 /* Dumps basic block BB to FILE with details described by FLAGS and
2606 indented by INDENT spaces. */
2608 void
2609 gimple_dump_bb (FILE *file, basic_block bb, int indent, int flags)
2611 dump_gimple_bb_header (file, bb, indent, flags);
2612 if (bb->index >= NUM_FIXED_BLOCKS)
2614 pretty_printer buffer;
2615 pp_needs_newline (&buffer) = true;
2616 buffer.buffer->stream = file;
2617 gimple_dump_bb_buff (&buffer, bb, indent, flags);
2619 dump_gimple_bb_footer (file, bb, indent, flags);
2622 /* Dumps basic block BB to pretty-printer PP with default dump flags and
2623 no indentation, for use as a label of a DOT graph record-node.
2624 ??? Should just use gimple_dump_bb_buff here, except that value profiling
2625 histogram dumping doesn't know about pretty-printers. */
2627 void
2628 gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
2630 pp_printf (pp, "<bb %d>:\n", bb->index);
2631 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2633 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2634 gsi_next (&gsi))
2636 gphi *phi = gsi.phi ();
2637 if (!virtual_operand_p (gimple_phi_result (phi))
2638 || (dump_flags & TDF_VOPS))
2640 pp_bar (pp);
2641 pp_write_text_to_stream (pp);
2642 pp_string (pp, "# ");
2643 pp_gimple_stmt_1 (pp, phi, 0, dump_flags);
2644 pp_newline (pp);
2645 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2649 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
2650 gsi_next (&gsi))
2652 gimple *stmt = gsi_stmt (gsi);
2653 pp_bar (pp);
2654 pp_write_text_to_stream (pp);
2655 pp_gimple_stmt_1 (pp, stmt, 0, dump_flags);
2656 pp_newline (pp);
2657 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2659 dump_implicit_edges (pp, bb, 0, dump_flags);
2660 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);