Rebase.
[official-gcc.git] / gcc / gimple-pretty-print.c
blob308441958a8ca41ee92f53ae9621aee352e60dee
1 /* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldyh@redhat.com> and
4 Diego Novillo <dnovillo@google.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "stringpool.h"
28 #include "diagnostic.h"
29 #include "gimple-pretty-print.h"
30 #include "hashtab.h"
31 #include "bitmap.h"
32 #include "basic-block.h"
33 #include "tree-ssa-alias.h"
34 #include "internal-fn.h"
35 #include "tree-eh.h"
36 #include "gimple-expr.h"
37 #include "is-a.h"
38 #include "gimple.h"
39 #include "gimple-iterator.h"
40 #include "gimple-ssa.h"
41 #include "cgraph.h"
42 #include "tree-cfg.h"
43 #include "tree-ssanames.h"
44 #include "dumpfile.h" /* for dump_flags */
45 #include "value-prof.h"
46 #include "trans-mem.h"
48 #define INDENT(SPACE) \
49 do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
51 #define GIMPLE_NIY do_niy (buffer,gs)
53 /* Try to print on BUFFER a default message for the unrecognized
54 gimple statement GS. */
56 static void
57 do_niy (pretty_printer *buffer, gimple gs)
59 pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
60 gimple_code_name[(int) gimple_code (gs)]);
64 /* Emit a newline and SPC indentation spaces to BUFFER. */
66 static void
67 newline_and_indent (pretty_printer *buffer, int spc)
69 pp_newline (buffer);
70 INDENT (spc);
74 /* Print the GIMPLE statement GS on stderr. */
76 DEBUG_FUNCTION void
77 debug_gimple_stmt (gimple gs)
79 print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
83 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
84 FLAGS as in pp_gimple_stmt_1. */
86 void
87 print_gimple_stmt (FILE *file, gimple g, int spc, int flags)
89 pretty_printer buffer;
90 pp_needs_newline (&buffer) = true;
91 buffer.buffer->stream = file;
92 pp_gimple_stmt_1 (&buffer, g, spc, flags);
93 pp_newline_and_flush (&buffer);
96 DEBUG_FUNCTION void
97 debug (gimple_statement_base &ref)
99 print_gimple_stmt (stderr, &ref, 0, 0);
102 DEBUG_FUNCTION void
103 debug (gimple_statement_base *ptr)
105 if (ptr)
106 debug (*ptr);
107 else
108 fprintf (stderr, "<nil>\n");
112 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
113 FLAGS as in pp_gimple_stmt_1. Print only the right-hand side
114 of the statement. */
116 void
117 print_gimple_expr (FILE *file, gimple g, int spc, int flags)
119 flags |= TDF_RHS_ONLY;
120 pretty_printer buffer;
121 pp_needs_newline (&buffer) = true;
122 buffer.buffer->stream = file;
123 pp_gimple_stmt_1 (&buffer, g, spc, flags);
124 pp_flush (&buffer);
128 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentation
129 spaces and FLAGS as in pp_gimple_stmt_1.
130 The caller is responsible for calling pp_flush on BUFFER to finalize
131 the pretty printer. */
133 static void
134 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc, int flags)
136 gimple_stmt_iterator i;
138 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
140 gimple gs = gsi_stmt (i);
141 INDENT (spc);
142 pp_gimple_stmt_1 (buffer, gs, spc, flags);
143 if (!gsi_one_before_end_p (i))
144 pp_newline (buffer);
149 /* Print GIMPLE sequence SEQ to FILE using SPC indentation spaces and
150 FLAGS as in pp_gimple_stmt_1. */
152 void
153 print_gimple_seq (FILE *file, gimple_seq seq, int spc, int flags)
155 pretty_printer buffer;
156 pp_needs_newline (&buffer) = true;
157 buffer.buffer->stream = file;
158 dump_gimple_seq (&buffer, seq, spc, flags);
159 pp_newline_and_flush (&buffer);
163 /* Print the GIMPLE sequence SEQ on stderr. */
165 DEBUG_FUNCTION void
166 debug_gimple_seq (gimple_seq seq)
168 print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
172 /* A simple helper to pretty-print some of the gimple tuples in the printf
173 style. The format modifiers are preceded by '%' and are:
174 'G' - outputs a string corresponding to the code of the given gimple,
175 'S' - outputs a gimple_seq with indent of spc + 2,
176 'T' - outputs the tree t,
177 'd' - outputs an int as a decimal,
178 's' - outputs a string,
179 'n' - outputs a newline,
180 'x' - outputs an int as hexadecimal,
181 '+' - increases indent by 2 then outputs a newline,
182 '-' - decreases indent by 2 then outputs a newline. */
184 static void
185 dump_gimple_fmt (pretty_printer *buffer, int spc, int flags,
186 const char *fmt, ...)
188 va_list args;
189 const char *c;
190 const char *tmp;
192 va_start (args, fmt);
193 for (c = fmt; *c; c++)
195 if (*c == '%')
197 gimple_seq seq;
198 tree t;
199 gimple g;
200 switch (*++c)
202 case 'G':
203 g = va_arg (args, gimple);
204 tmp = gimple_code_name[gimple_code (g)];
205 pp_string (buffer, tmp);
206 break;
208 case 'S':
209 seq = va_arg (args, gimple_seq);
210 pp_newline (buffer);
211 dump_gimple_seq (buffer, seq, spc + 2, flags);
212 newline_and_indent (buffer, spc);
213 break;
215 case 'T':
216 t = va_arg (args, tree);
217 if (t == NULL_TREE)
218 pp_string (buffer, "NULL");
219 else
220 dump_generic_node (buffer, t, spc, flags, false);
221 break;
223 case 'd':
224 pp_decimal_int (buffer, va_arg (args, int));
225 break;
227 case 's':
228 pp_string (buffer, va_arg (args, char *));
229 break;
231 case 'n':
232 newline_and_indent (buffer, spc);
233 break;
235 case 'x':
236 pp_scalar (buffer, "%x", va_arg (args, int));
237 break;
239 case '+':
240 spc += 2;
241 newline_and_indent (buffer, spc);
242 break;
244 case '-':
245 spc -= 2;
246 newline_and_indent (buffer, spc);
247 break;
249 default:
250 gcc_unreachable ();
253 else
254 pp_character (buffer, *c);
256 va_end (args);
260 /* Helper for dump_gimple_assign. Print the unary RHS of the
261 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
263 static void
264 dump_unary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
266 enum tree_code rhs_code = gimple_assign_rhs_code (gs);
267 tree lhs = gimple_assign_lhs (gs);
268 tree rhs = gimple_assign_rhs1 (gs);
270 switch (rhs_code)
272 case VIEW_CONVERT_EXPR:
273 case ASSERT_EXPR:
274 dump_generic_node (buffer, rhs, spc, flags, false);
275 break;
277 case FIXED_CONVERT_EXPR:
278 case ADDR_SPACE_CONVERT_EXPR:
279 case FIX_TRUNC_EXPR:
280 case FLOAT_EXPR:
281 CASE_CONVERT:
282 pp_left_paren (buffer);
283 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
284 pp_string (buffer, ") ");
285 if (op_prio (rhs) < op_code_prio (rhs_code))
287 pp_left_paren (buffer);
288 dump_generic_node (buffer, rhs, spc, flags, false);
289 pp_right_paren (buffer);
291 else
292 dump_generic_node (buffer, rhs, spc, flags, false);
293 break;
295 case PAREN_EXPR:
296 pp_string (buffer, "((");
297 dump_generic_node (buffer, rhs, spc, flags, false);
298 pp_string (buffer, "))");
299 break;
301 case ABS_EXPR:
302 pp_string (buffer, "ABS_EXPR <");
303 dump_generic_node (buffer, rhs, spc, flags, false);
304 pp_greater (buffer);
305 break;
307 default:
308 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
309 || TREE_CODE_CLASS (rhs_code) == tcc_constant
310 || TREE_CODE_CLASS (rhs_code) == tcc_reference
311 || rhs_code == SSA_NAME
312 || rhs_code == ADDR_EXPR
313 || rhs_code == CONSTRUCTOR)
315 dump_generic_node (buffer, rhs, spc, flags, false);
316 break;
318 else if (rhs_code == BIT_NOT_EXPR)
319 pp_complement (buffer);
320 else if (rhs_code == TRUTH_NOT_EXPR)
321 pp_exclamation (buffer);
322 else if (rhs_code == NEGATE_EXPR)
323 pp_minus (buffer);
324 else
326 pp_left_bracket (buffer);
327 pp_string (buffer, get_tree_code_name (rhs_code));
328 pp_string (buffer, "] ");
331 if (op_prio (rhs) < op_code_prio (rhs_code))
333 pp_left_paren (buffer);
334 dump_generic_node (buffer, rhs, spc, flags, false);
335 pp_right_paren (buffer);
337 else
338 dump_generic_node (buffer, rhs, spc, flags, false);
339 break;
344 /* Helper for dump_gimple_assign. Print the binary RHS of the
345 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
347 static void
348 dump_binary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
350 const char *p;
351 enum tree_code code = gimple_assign_rhs_code (gs);
352 switch (code)
354 case COMPLEX_EXPR:
355 case MIN_EXPR:
356 case MAX_EXPR:
357 case VEC_WIDEN_MULT_HI_EXPR:
358 case VEC_WIDEN_MULT_LO_EXPR:
359 case VEC_WIDEN_MULT_EVEN_EXPR:
360 case VEC_WIDEN_MULT_ODD_EXPR:
361 case VEC_PACK_TRUNC_EXPR:
362 case VEC_PACK_SAT_EXPR:
363 case VEC_PACK_FIX_TRUNC_EXPR:
364 case VEC_WIDEN_LSHIFT_HI_EXPR:
365 case VEC_WIDEN_LSHIFT_LO_EXPR:
366 for (p = get_tree_code_name (code); *p; p++)
367 pp_character (buffer, TOUPPER (*p));
368 pp_string (buffer, " <");
369 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
370 pp_string (buffer, ", ");
371 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
372 pp_greater (buffer);
373 break;
375 default:
376 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
378 pp_left_paren (buffer);
379 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
380 false);
381 pp_right_paren (buffer);
383 else
384 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
385 pp_space (buffer);
386 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
387 pp_space (buffer);
388 if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
390 pp_left_paren (buffer);
391 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
392 false);
393 pp_right_paren (buffer);
395 else
396 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
400 /* Helper for dump_gimple_assign. Print the ternary RHS of the
401 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
403 static void
404 dump_ternary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
406 const char *p;
407 enum tree_code code = gimple_assign_rhs_code (gs);
408 switch (code)
410 case WIDEN_MULT_PLUS_EXPR:
411 case WIDEN_MULT_MINUS_EXPR:
412 for (p = get_tree_code_name (code); *p; p++)
413 pp_character (buffer, TOUPPER (*p));
414 pp_string (buffer, " <");
415 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
416 pp_string (buffer, ", ");
417 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
418 pp_string (buffer, ", ");
419 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
420 pp_greater (buffer);
421 break;
423 case FMA_EXPR:
424 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
425 pp_string (buffer, " * ");
426 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
427 pp_string (buffer, " + ");
428 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
429 break;
431 case DOT_PROD_EXPR:
432 pp_string (buffer, "DOT_PROD_EXPR <");
433 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
434 pp_string (buffer, ", ");
435 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
436 pp_string (buffer, ", ");
437 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
438 pp_greater (buffer);
439 break;
441 case SAD_EXPR:
442 pp_string (buffer, "SAD_EXPR <");
443 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
444 pp_string (buffer, ", ");
445 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
446 pp_string (buffer, ", ");
447 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
448 pp_greater (buffer);
449 break;
451 case VEC_PERM_EXPR:
452 pp_string (buffer, "VEC_PERM_EXPR <");
453 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
454 pp_string (buffer, ", ");
455 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
456 pp_string (buffer, ", ");
457 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
458 pp_greater (buffer);
459 break;
461 case REALIGN_LOAD_EXPR:
462 pp_string (buffer, "REALIGN_LOAD <");
463 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
464 pp_string (buffer, ", ");
465 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
466 pp_string (buffer, ", ");
467 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
468 pp_greater (buffer);
469 break;
471 case COND_EXPR:
472 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
473 pp_string (buffer, " ? ");
474 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
475 pp_string (buffer, " : ");
476 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
477 break;
479 case VEC_COND_EXPR:
480 pp_string (buffer, "VEC_COND_EXPR <");
481 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
482 pp_string (buffer, ", ");
483 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
484 pp_string (buffer, ", ");
485 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
486 pp_greater (buffer);
487 break;
489 default:
490 gcc_unreachable ();
495 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
496 pp_gimple_stmt_1. */
498 static void
499 dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
501 if (flags & TDF_RAW)
503 tree arg1 = NULL;
504 tree arg2 = NULL;
505 tree arg3 = NULL;
506 switch (gimple_num_ops (gs))
508 case 4:
509 arg3 = gimple_assign_rhs3 (gs);
510 case 3:
511 arg2 = gimple_assign_rhs2 (gs);
512 case 2:
513 arg1 = gimple_assign_rhs1 (gs);
514 break;
515 default:
516 gcc_unreachable ();
519 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
520 get_tree_code_name (gimple_assign_rhs_code (gs)),
521 gimple_assign_lhs (gs), arg1, arg2, arg3);
523 else
525 if (!(flags & TDF_RHS_ONLY))
527 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
528 pp_space (buffer);
529 pp_equal (buffer);
531 if (gimple_assign_nontemporal_move_p (gs))
532 pp_string (buffer, "{nt}");
534 if (gimple_has_volatile_ops (gs))
535 pp_string (buffer, "{v}");
537 pp_space (buffer);
540 if (gimple_num_ops (gs) == 2)
541 dump_unary_rhs (buffer, gs, spc, flags);
542 else if (gimple_num_ops (gs) == 3)
543 dump_binary_rhs (buffer, gs, spc, flags);
544 else if (gimple_num_ops (gs) == 4)
545 dump_ternary_rhs (buffer, gs, spc, flags);
546 else
547 gcc_unreachable ();
548 if (!(flags & TDF_RHS_ONLY))
549 pp_semicolon (buffer);
554 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
555 pp_gimple_stmt_1. */
557 static void
558 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
560 tree t, t2;
562 t = gimple_return_retval (gs);
563 t2 = gimple_return_retbnd (gs);
564 if (flags & TDF_RAW)
565 dump_gimple_fmt (buffer, spc, flags, "%G <%T %T>", gs, t, t2);
566 else
568 pp_string (buffer, "return");
569 if (t)
571 pp_space (buffer);
572 dump_generic_node (buffer, t, spc, flags, false);
574 if (t2)
576 pp_string (buffer, ", ");
577 dump_generic_node (buffer, t2, spc, flags, false);
579 pp_semicolon (buffer);
584 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
585 dump_gimple_call. */
587 static void
588 dump_gimple_call_args (pretty_printer *buffer, gimple gs, int flags)
590 size_t i;
592 for (i = 0; i < gimple_call_num_args (gs); i++)
594 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
595 if (i < gimple_call_num_args (gs) - 1)
596 pp_string (buffer, ", ");
599 if (gimple_call_va_arg_pack_p (gs))
601 if (gimple_call_num_args (gs) > 0)
603 pp_comma (buffer);
604 pp_space (buffer);
607 pp_string (buffer, "__builtin_va_arg_pack ()");
611 /* Dump the points-to solution *PT to BUFFER. */
613 static void
614 pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
616 if (pt->anything)
618 pp_string (buffer, "anything ");
619 return;
621 if (pt->nonlocal)
622 pp_string (buffer, "nonlocal ");
623 if (pt->escaped)
624 pp_string (buffer, "escaped ");
625 if (pt->ipa_escaped)
626 pp_string (buffer, "unit-escaped ");
627 if (pt->null)
628 pp_string (buffer, "null ");
629 if (pt->vars
630 && !bitmap_empty_p (pt->vars))
632 bitmap_iterator bi;
633 unsigned i;
634 pp_string (buffer, "{ ");
635 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
637 pp_string (buffer, "D.");
638 pp_decimal_int (buffer, i);
639 pp_space (buffer);
641 pp_right_brace (buffer);
642 if (pt->vars_contains_nonlocal
643 && pt->vars_contains_escaped_heap)
644 pp_string (buffer, " (nonlocal, escaped heap)");
645 else if (pt->vars_contains_nonlocal
646 && pt->vars_contains_escaped)
647 pp_string (buffer, " (nonlocal, escaped)");
648 else if (pt->vars_contains_nonlocal)
649 pp_string (buffer, " (nonlocal)");
650 else if (pt->vars_contains_escaped_heap)
651 pp_string (buffer, " (escaped heap)");
652 else if (pt->vars_contains_escaped)
653 pp_string (buffer, " (escaped)");
657 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
658 pp_gimple_stmt_1. */
660 static void
661 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
663 tree lhs = gimple_call_lhs (gs);
664 tree fn = gimple_call_fn (gs);
666 if (flags & TDF_ALIAS)
668 struct pt_solution *pt;
669 pt = gimple_call_use_set (gs);
670 if (!pt_solution_empty_p (pt))
672 pp_string (buffer, "# USE = ");
673 pp_points_to_solution (buffer, pt);
674 newline_and_indent (buffer, spc);
676 pt = gimple_call_clobber_set (gs);
677 if (!pt_solution_empty_p (pt))
679 pp_string (buffer, "# CLB = ");
680 pp_points_to_solution (buffer, pt);
681 newline_and_indent (buffer, spc);
685 if (flags & TDF_RAW)
687 if (gimple_call_internal_p (gs))
688 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T", gs,
689 internal_fn_name (gimple_call_internal_fn (gs)), lhs);
690 else
691 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T", gs, fn, lhs);
692 if (gimple_call_num_args (gs) > 0)
694 pp_string (buffer, ", ");
695 dump_gimple_call_args (buffer, gs, flags);
697 pp_greater (buffer);
699 else
701 if (lhs && !(flags & TDF_RHS_ONLY))
703 dump_generic_node (buffer, lhs, spc, flags, false);
704 pp_string (buffer, " =");
706 if (gimple_has_volatile_ops (gs))
707 pp_string (buffer, "{v}");
709 pp_space (buffer);
711 if (gimple_call_internal_p (gs))
712 pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
713 else
714 print_call_name (buffer, fn, flags);
715 pp_string (buffer, " (");
716 dump_gimple_call_args (buffer, gs, flags);
717 pp_right_paren (buffer);
718 if (!(flags & TDF_RHS_ONLY))
719 pp_semicolon (buffer);
722 if (gimple_call_chain (gs))
724 pp_string (buffer, " [static-chain: ");
725 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
726 pp_right_bracket (buffer);
729 if (gimple_call_return_slot_opt_p (gs))
730 pp_string (buffer, " [return slot optimization]");
731 if (gimple_call_tail_p (gs))
732 pp_string (buffer, " [tail call]");
734 if (fn == NULL)
735 return;
737 /* Dump the arguments of _ITM_beginTransaction sanely. */
738 if (TREE_CODE (fn) == ADDR_EXPR)
739 fn = TREE_OPERAND (fn, 0);
740 if (TREE_CODE (fn) == FUNCTION_DECL && decl_is_tm_clone (fn))
741 pp_string (buffer, " [tm-clone]");
742 if (TREE_CODE (fn) == FUNCTION_DECL
743 && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
744 && DECL_FUNCTION_CODE (fn) == BUILT_IN_TM_START
745 && gimple_call_num_args (gs) > 0)
747 tree t = gimple_call_arg (gs, 0);
748 unsigned HOST_WIDE_INT props;
749 gcc_assert (TREE_CODE (t) == INTEGER_CST);
751 pp_string (buffer, " [ ");
753 /* Get the transaction code properties. */
754 props = TREE_INT_CST_LOW (t);
756 if (props & PR_INSTRUMENTEDCODE)
757 pp_string (buffer, "instrumentedCode ");
758 if (props & PR_UNINSTRUMENTEDCODE)
759 pp_string (buffer, "uninstrumentedCode ");
760 if (props & PR_HASNOXMMUPDATE)
761 pp_string (buffer, "hasNoXMMUpdate ");
762 if (props & PR_HASNOABORT)
763 pp_string (buffer, "hasNoAbort ");
764 if (props & PR_HASNOIRREVOCABLE)
765 pp_string (buffer, "hasNoIrrevocable ");
766 if (props & PR_DOESGOIRREVOCABLE)
767 pp_string (buffer, "doesGoIrrevocable ");
768 if (props & PR_HASNOSIMPLEREADS)
769 pp_string (buffer, "hasNoSimpleReads ");
770 if (props & PR_AWBARRIERSOMITTED)
771 pp_string (buffer, "awBarriersOmitted ");
772 if (props & PR_RARBARRIERSOMITTED)
773 pp_string (buffer, "RaRBarriersOmitted ");
774 if (props & PR_UNDOLOGCODE)
775 pp_string (buffer, "undoLogCode ");
776 if (props & PR_PREFERUNINSTRUMENTED)
777 pp_string (buffer, "preferUninstrumented ");
778 if (props & PR_EXCEPTIONBLOCK)
779 pp_string (buffer, "exceptionBlock ");
780 if (props & PR_HASELSE)
781 pp_string (buffer, "hasElse ");
782 if (props & PR_READONLY)
783 pp_string (buffer, "readOnly ");
785 pp_right_bracket (buffer);
790 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
791 pp_gimple_stmt_1. */
793 static void
794 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
796 unsigned int i;
798 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
799 if (flags & TDF_RAW)
800 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
801 gimple_switch_index (gs));
802 else
804 pp_string (buffer, "switch (");
805 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
806 pp_string (buffer, ") <");
809 for (i = 0; i < gimple_switch_num_labels (gs); i++)
811 tree case_label = gimple_switch_label (gs, i);
812 gcc_checking_assert (case_label != NULL_TREE);
813 dump_generic_node (buffer, case_label, spc, flags, false);
814 pp_space (buffer);
815 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
816 if (i < gimple_switch_num_labels (gs) - 1)
817 pp_string (buffer, ", ");
819 pp_greater (buffer);
823 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
824 pp_gimple_stmt_1. */
826 static void
827 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
829 if (flags & TDF_RAW)
830 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
831 get_tree_code_name (gimple_cond_code (gs)),
832 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
833 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
834 else
836 if (!(flags & TDF_RHS_ONLY))
837 pp_string (buffer, "if (");
838 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
839 pp_space (buffer);
840 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
841 pp_space (buffer);
842 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
843 if (!(flags & TDF_RHS_ONLY))
845 pp_right_paren (buffer);
847 if (gimple_cond_true_label (gs))
849 pp_string (buffer, " goto ");
850 dump_generic_node (buffer, gimple_cond_true_label (gs),
851 spc, flags, false);
852 pp_semicolon (buffer);
854 if (gimple_cond_false_label (gs))
856 pp_string (buffer, " else goto ");
857 dump_generic_node (buffer, gimple_cond_false_label (gs),
858 spc, flags, false);
859 pp_semicolon (buffer);
866 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
867 spaces of indent. FLAGS specifies details to show in the dump (see
868 TDF_* in dumpfils.h). */
870 static void
871 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
873 tree label = gimple_label_label (gs);
874 if (flags & TDF_RAW)
875 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
876 else
878 dump_generic_node (buffer, label, spc, flags, false);
879 pp_colon (buffer);
881 if (DECL_NONLOCAL (label))
882 pp_string (buffer, " [non-local]");
883 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
884 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
887 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
888 spaces of indent. FLAGS specifies details to show in the dump (see
889 TDF_* in dumpfile.h). */
891 static void
892 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
894 tree label = gimple_goto_dest (gs);
895 if (flags & TDF_RAW)
896 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
897 else
898 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
902 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
903 spaces of indent. FLAGS specifies details to show in the dump (see
904 TDF_* in dumpfile.h). */
906 static void
907 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
909 if (flags & TDF_RAW)
910 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
911 else
912 pp_left_brace (buffer);
913 if (!(flags & TDF_SLIM))
915 tree var;
917 for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
919 newline_and_indent (buffer, 2);
920 print_declaration (buffer, var, spc, flags);
922 if (gimple_bind_vars (gs))
923 pp_newline (buffer);
925 pp_newline (buffer);
926 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
927 newline_and_indent (buffer, spc);
928 if (flags & TDF_RAW)
929 pp_greater (buffer);
930 else
931 pp_right_brace (buffer);
935 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
936 indent. FLAGS specifies details to show in the dump (see TDF_* in
937 dumpfile.h). */
939 static void
940 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
942 if (flags & TDF_RAW)
944 const char *type;
945 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
946 type = "GIMPLE_TRY_CATCH";
947 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
948 type = "GIMPLE_TRY_FINALLY";
949 else
950 type = "UNKNOWN GIMPLE_TRY";
951 dump_gimple_fmt (buffer, spc, flags,
952 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
953 gimple_try_eval (gs), gimple_try_cleanup (gs));
955 else
957 pp_string (buffer, "try");
958 newline_and_indent (buffer, spc + 2);
959 pp_left_brace (buffer);
960 pp_newline (buffer);
962 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
963 newline_and_indent (buffer, spc + 2);
964 pp_right_brace (buffer);
966 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
968 newline_and_indent (buffer, spc);
969 pp_string (buffer, "catch");
970 newline_and_indent (buffer, spc + 2);
971 pp_left_brace (buffer);
973 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
975 newline_and_indent (buffer, spc);
976 pp_string (buffer, "finally");
977 newline_and_indent (buffer, spc + 2);
978 pp_left_brace (buffer);
980 else
981 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
983 pp_newline (buffer);
984 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
985 newline_and_indent (buffer, spc + 2);
986 pp_right_brace (buffer);
991 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
992 indent. FLAGS specifies details to show in the dump (see TDF_* in
993 dumpfile.h). */
995 static void
996 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
998 if (flags & TDF_RAW)
999 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
1000 gimple_catch_types (gs), gimple_catch_handler (gs));
1001 else
1002 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
1003 gimple_catch_types (gs), gimple_catch_handler (gs));
1007 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
1008 indent. FLAGS specifies details to show in the dump (see TDF_* in
1009 dumpfile.h). */
1011 static void
1012 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
1014 if (flags & TDF_RAW)
1015 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
1016 gimple_eh_filter_types (gs),
1017 gimple_eh_filter_failure (gs));
1018 else
1019 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
1020 gimple_eh_filter_types (gs),
1021 gimple_eh_filter_failure (gs));
1025 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
1027 static void
1028 dump_gimple_eh_must_not_throw (pretty_printer *buffer, gimple gs,
1029 int spc, int flags)
1031 if (flags & TDF_RAW)
1032 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1033 gimple_eh_must_not_throw_fndecl (gs));
1034 else
1035 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
1036 gimple_eh_must_not_throw_fndecl (gs));
1040 /* Dump a GIMPLE_EH_ELSE 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_else (pretty_printer *buffer, gimple gs, int spc, int flags)
1047 if (flags & TDF_RAW)
1048 dump_gimple_fmt (buffer, spc, flags,
1049 "%G <%+N_BODY <%S>%nE_BODY <%S>%->", gs,
1050 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1051 else
1052 dump_gimple_fmt (buffer, spc, flags,
1053 "<<<if_normal_exit>>>%+{%S}%-<<<else_eh_exit>>>%+{%S}",
1054 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1058 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
1059 indent. FLAGS specifies details to show in the dump (see TDF_* in
1060 dumpfile.h). */
1062 static void
1063 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
1065 if (flags & TDF_RAW)
1066 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1067 gimple_resx_region (gs));
1068 else
1069 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
1072 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
1074 static void
1075 dump_gimple_eh_dispatch (pretty_printer *buffer, gimple gs, int spc, int flags)
1077 if (flags & TDF_RAW)
1078 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1079 gimple_eh_dispatch_region (gs));
1080 else
1081 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
1082 gimple_eh_dispatch_region (gs));
1085 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
1086 of indent. FLAGS specifies details to show in the dump (see TDF_*
1087 in dumpfile.h). */
1089 static void
1090 dump_gimple_debug (pretty_printer *buffer, gimple gs, int spc, int flags)
1092 switch (gs->subcode)
1094 case GIMPLE_DEBUG_BIND:
1095 if (flags & TDF_RAW)
1096 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
1097 gimple_debug_bind_get_var (gs),
1098 gimple_debug_bind_get_value (gs));
1099 else
1100 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
1101 gimple_debug_bind_get_var (gs),
1102 gimple_debug_bind_get_value (gs));
1103 break;
1105 case GIMPLE_DEBUG_SOURCE_BIND:
1106 if (flags & TDF_RAW)
1107 dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1108 gimple_debug_source_bind_get_var (gs),
1109 gimple_debug_source_bind_get_value (gs));
1110 else
1111 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1112 gimple_debug_source_bind_get_var (gs),
1113 gimple_debug_source_bind_get_value (gs));
1114 break;
1116 default:
1117 gcc_unreachable ();
1121 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
1122 static void
1123 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
1125 size_t i;
1127 if (flags & TDF_RAW)
1129 const char *kind;
1130 switch (gimple_omp_for_kind (gs))
1132 case GF_OMP_FOR_KIND_FOR:
1133 kind = "";
1134 break;
1135 case GF_OMP_FOR_KIND_SIMD:
1136 kind = " simd";
1137 break;
1138 case GF_OMP_FOR_KIND_CILKSIMD:
1139 kind = " cilksimd";
1140 break;
1141 case GF_OMP_FOR_KIND_DISTRIBUTE:
1142 kind = " distribute";
1143 break;
1144 default:
1145 gcc_unreachable ();
1147 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1148 kind, gimple_omp_body (gs));
1149 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1150 dump_gimple_fmt (buffer, spc, flags, " >,");
1151 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1152 dump_gimple_fmt (buffer, spc, flags,
1153 "%+%T, %T, %T, %s, %T,%n",
1154 gimple_omp_for_index (gs, i),
1155 gimple_omp_for_initial (gs, i),
1156 gimple_omp_for_final (gs, i),
1157 get_tree_code_name (gimple_omp_for_cond (gs, i)),
1158 gimple_omp_for_incr (gs, i));
1159 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1160 gimple_omp_for_pre_body (gs));
1162 else
1164 switch (gimple_omp_for_kind (gs))
1166 case GF_OMP_FOR_KIND_FOR:
1167 pp_string (buffer, "#pragma omp for");
1168 break;
1169 case GF_OMP_FOR_KIND_SIMD:
1170 pp_string (buffer, "#pragma omp simd");
1171 break;
1172 case GF_OMP_FOR_KIND_CILKSIMD:
1173 pp_string (buffer, "#pragma simd");
1174 break;
1175 case GF_OMP_FOR_KIND_DISTRIBUTE:
1176 pp_string (buffer, "#pragma omp distribute");
1177 break;
1178 default:
1179 gcc_unreachable ();
1181 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1182 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1184 if (i)
1185 spc += 2;
1186 newline_and_indent (buffer, spc);
1187 pp_string (buffer, "for (");
1188 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1189 flags, false);
1190 pp_string (buffer, " = ");
1191 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1192 flags, false);
1193 pp_string (buffer, "; ");
1195 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1196 flags, false);
1197 pp_space (buffer);
1198 switch (gimple_omp_for_cond (gs, i))
1200 case LT_EXPR:
1201 pp_less (buffer);
1202 break;
1203 case GT_EXPR:
1204 pp_greater (buffer);
1205 break;
1206 case LE_EXPR:
1207 pp_less_equal (buffer);
1208 break;
1209 case GE_EXPR:
1210 pp_greater_equal (buffer);
1211 break;
1212 default:
1213 gcc_unreachable ();
1215 pp_space (buffer);
1216 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1217 flags, false);
1218 pp_string (buffer, "; ");
1220 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1221 flags, false);
1222 pp_string (buffer, " = ");
1223 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1224 flags, false);
1225 pp_right_paren (buffer);
1228 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1230 newline_and_indent (buffer, spc + 2);
1231 pp_left_brace (buffer);
1232 pp_newline (buffer);
1233 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1234 newline_and_indent (buffer, spc + 2);
1235 pp_right_brace (buffer);
1240 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
1242 static void
1243 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
1245 if (flags & TDF_RAW)
1247 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1248 gimple_omp_continue_control_def (gs),
1249 gimple_omp_continue_control_use (gs));
1251 else
1253 pp_string (buffer, "#pragma omp continue (");
1254 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1255 spc, flags, false);
1256 pp_comma (buffer);
1257 pp_space (buffer);
1258 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1259 spc, flags, false);
1260 pp_right_paren (buffer);
1264 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1266 static void
1267 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
1269 if (flags & TDF_RAW)
1271 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1272 gimple_omp_body (gs));
1273 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1274 dump_gimple_fmt (buffer, spc, flags, " >");
1276 else
1278 pp_string (buffer, "#pragma omp single");
1279 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1280 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1282 newline_and_indent (buffer, spc + 2);
1283 pp_left_brace (buffer);
1284 pp_newline (buffer);
1285 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1286 newline_and_indent (buffer, spc + 2);
1287 pp_right_brace (buffer);
1292 /* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer BUFFER. */
1294 static void
1295 dump_gimple_omp_target (pretty_printer *buffer, gimple gs, int spc, int flags)
1297 const char *kind;
1298 switch (gimple_omp_target_kind (gs))
1300 case GF_OMP_TARGET_KIND_REGION:
1301 kind = "";
1302 break;
1303 case GF_OMP_TARGET_KIND_DATA:
1304 kind = " data";
1305 break;
1306 case GF_OMP_TARGET_KIND_UPDATE:
1307 kind = " update";
1308 break;
1309 default:
1310 gcc_unreachable ();
1312 if (flags & TDF_RAW)
1314 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1315 kind, gimple_omp_body (gs));
1316 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1317 dump_gimple_fmt (buffer, spc, flags, " >");
1319 else
1321 pp_string (buffer, "#pragma omp target");
1322 pp_string (buffer, kind);
1323 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1324 if (gimple_omp_target_child_fn (gs))
1326 pp_string (buffer, " [child fn: ");
1327 dump_generic_node (buffer, gimple_omp_target_child_fn (gs),
1328 spc, flags, false);
1329 pp_right_bracket (buffer);
1331 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1333 newline_and_indent (buffer, spc + 2);
1334 pp_character (buffer, '{');
1335 pp_newline (buffer);
1336 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1337 newline_and_indent (buffer, spc + 2);
1338 pp_character (buffer, '}');
1343 /* Dump a GIMPLE_OMP_TEAMS tuple on the pretty_printer BUFFER. */
1345 static void
1346 dump_gimple_omp_teams (pretty_printer *buffer, gimple gs, int spc, int flags)
1348 if (flags & TDF_RAW)
1350 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1351 gimple_omp_body (gs));
1352 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1353 dump_gimple_fmt (buffer, spc, flags, " >");
1355 else
1357 pp_string (buffer, "#pragma omp teams");
1358 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1359 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1361 newline_and_indent (buffer, spc + 2);
1362 pp_character (buffer, '{');
1363 pp_newline (buffer);
1364 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1365 newline_and_indent (buffer, spc + 2);
1366 pp_character (buffer, '}');
1371 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1373 static void
1374 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
1375 int flags)
1377 if (flags & TDF_RAW)
1379 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1380 gimple_omp_body (gs));
1381 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1382 dump_gimple_fmt (buffer, spc, flags, " >");
1384 else
1386 pp_string (buffer, "#pragma omp sections");
1387 if (gimple_omp_sections_control (gs))
1389 pp_string (buffer, " <");
1390 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1391 flags, false);
1392 pp_greater (buffer);
1394 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1395 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1397 newline_and_indent (buffer, spc + 2);
1398 pp_left_brace (buffer);
1399 pp_newline (buffer);
1400 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1401 newline_and_indent (buffer, spc + 2);
1402 pp_right_brace (buffer);
1407 /* Dump a GIMPLE_OMP_{MASTER,TASKGROUP,ORDERED,SECTION} tuple on the
1408 pretty_printer BUFFER. */
1410 static void
1411 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
1413 if (flags & TDF_RAW)
1414 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1415 gimple_omp_body (gs));
1416 else
1418 switch (gimple_code (gs))
1420 case GIMPLE_OMP_MASTER:
1421 pp_string (buffer, "#pragma omp master");
1422 break;
1423 case GIMPLE_OMP_TASKGROUP:
1424 pp_string (buffer, "#pragma omp taskgroup");
1425 break;
1426 case GIMPLE_OMP_ORDERED:
1427 pp_string (buffer, "#pragma omp ordered");
1428 break;
1429 case GIMPLE_OMP_SECTION:
1430 pp_string (buffer, "#pragma omp section");
1431 break;
1432 default:
1433 gcc_unreachable ();
1435 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1437 newline_and_indent (buffer, spc + 2);
1438 pp_left_brace (buffer);
1439 pp_newline (buffer);
1440 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1441 newline_and_indent (buffer, spc + 2);
1442 pp_right_brace (buffer);
1447 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1449 static void
1450 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
1451 int flags)
1453 if (flags & TDF_RAW)
1454 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1455 gimple_omp_body (gs));
1456 else
1458 pp_string (buffer, "#pragma omp critical");
1459 if (gimple_omp_critical_name (gs))
1461 pp_string (buffer, " (");
1462 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1463 flags, false);
1464 pp_right_paren (buffer);
1466 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1468 newline_and_indent (buffer, spc + 2);
1469 pp_left_brace (buffer);
1470 pp_newline (buffer);
1471 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1472 newline_and_indent (buffer, spc + 2);
1473 pp_right_brace (buffer);
1478 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1480 static void
1481 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1483 if (flags & TDF_RAW)
1485 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d", gs,
1486 (int) gimple_omp_return_nowait_p (gs));
1487 if (gimple_omp_return_lhs (gs))
1488 dump_gimple_fmt (buffer, spc, flags, ", lhs=%T>",
1489 gimple_omp_return_lhs (gs));
1490 else
1491 dump_gimple_fmt (buffer, spc, flags, ">");
1493 else
1495 pp_string (buffer, "#pragma omp return");
1496 if (gimple_omp_return_nowait_p (gs))
1497 pp_string (buffer, "(nowait)");
1498 if (gimple_omp_return_lhs (gs))
1500 pp_string (buffer, " (set ");
1501 dump_generic_node (buffer, gimple_omp_return_lhs (gs),
1502 spc, flags, false);
1503 pp_character (buffer, ')');
1508 /* Dump a GIMPLE_TRANSACTION tuple on the pretty_printer BUFFER. */
1510 static void
1511 dump_gimple_transaction (pretty_printer *buffer, gimple gs, int spc, int flags)
1513 unsigned subcode = gimple_transaction_subcode (gs);
1515 if (flags & TDF_RAW)
1517 dump_gimple_fmt (buffer, spc, flags,
1518 "%G [SUBCODE=%x,LABEL=%T] <%+BODY <%S> >",
1519 gs, subcode, gimple_transaction_label (gs),
1520 gimple_transaction_body (gs));
1522 else
1524 if (subcode & GTMA_IS_OUTER)
1525 pp_string (buffer, "__transaction_atomic [[outer]]");
1526 else if (subcode & GTMA_IS_RELAXED)
1527 pp_string (buffer, "__transaction_relaxed");
1528 else
1529 pp_string (buffer, "__transaction_atomic");
1530 subcode &= ~GTMA_DECLARATION_MASK;
1532 if (subcode || gimple_transaction_label (gs))
1534 pp_string (buffer, " //");
1535 if (gimple_transaction_label (gs))
1537 pp_string (buffer, " LABEL=");
1538 dump_generic_node (buffer, gimple_transaction_label (gs),
1539 spc, flags, false);
1541 if (subcode)
1543 pp_string (buffer, " SUBCODE=[ ");
1544 if (subcode & GTMA_HAVE_ABORT)
1546 pp_string (buffer, "GTMA_HAVE_ABORT ");
1547 subcode &= ~GTMA_HAVE_ABORT;
1549 if (subcode & GTMA_HAVE_LOAD)
1551 pp_string (buffer, "GTMA_HAVE_LOAD ");
1552 subcode &= ~GTMA_HAVE_LOAD;
1554 if (subcode & GTMA_HAVE_STORE)
1556 pp_string (buffer, "GTMA_HAVE_STORE ");
1557 subcode &= ~GTMA_HAVE_STORE;
1559 if (subcode & GTMA_MAY_ENTER_IRREVOCABLE)
1561 pp_string (buffer, "GTMA_MAY_ENTER_IRREVOCABLE ");
1562 subcode &= ~GTMA_MAY_ENTER_IRREVOCABLE;
1564 if (subcode & GTMA_DOES_GO_IRREVOCABLE)
1566 pp_string (buffer, "GTMA_DOES_GO_IRREVOCABLE ");
1567 subcode &= ~GTMA_DOES_GO_IRREVOCABLE;
1569 if (subcode & GTMA_HAS_NO_INSTRUMENTATION)
1571 pp_string (buffer, "GTMA_HAS_NO_INSTRUMENTATION ");
1572 subcode &= ~GTMA_HAS_NO_INSTRUMENTATION;
1574 if (subcode)
1575 pp_printf (buffer, "0x%x ", subcode);
1576 pp_right_bracket (buffer);
1580 if (!gimple_seq_empty_p (gimple_transaction_body (gs)))
1582 newline_and_indent (buffer, spc + 2);
1583 pp_left_brace (buffer);
1584 pp_newline (buffer);
1585 dump_gimple_seq (buffer, gimple_transaction_body (gs),
1586 spc + 4, flags);
1587 newline_and_indent (buffer, spc + 2);
1588 pp_right_brace (buffer);
1593 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1594 indent. FLAGS specifies details to show in the dump (see TDF_* in
1595 dumpfile.h). */
1597 static void
1598 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1600 unsigned int i, n, f, fields;
1602 if (flags & TDF_RAW)
1604 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1605 gimple_asm_string (gs));
1607 n = gimple_asm_noutputs (gs);
1608 if (n)
1610 newline_and_indent (buffer, spc + 2);
1611 pp_string (buffer, "OUTPUT: ");
1612 for (i = 0; i < n; i++)
1614 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1615 spc, flags, false);
1616 if (i < n - 1)
1617 pp_string (buffer, ", ");
1621 n = gimple_asm_ninputs (gs);
1622 if (n)
1624 newline_and_indent (buffer, spc + 2);
1625 pp_string (buffer, "INPUT: ");
1626 for (i = 0; i < n; i++)
1628 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1629 spc, flags, false);
1630 if (i < n - 1)
1631 pp_string (buffer, ", ");
1635 n = gimple_asm_nclobbers (gs);
1636 if (n)
1638 newline_and_indent (buffer, spc + 2);
1639 pp_string (buffer, "CLOBBER: ");
1640 for (i = 0; i < n; i++)
1642 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1643 spc, flags, false);
1644 if (i < n - 1)
1645 pp_string (buffer, ", ");
1649 n = gimple_asm_nlabels (gs);
1650 if (n)
1652 newline_and_indent (buffer, spc + 2);
1653 pp_string (buffer, "LABEL: ");
1654 for (i = 0; i < n; i++)
1656 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1657 spc, flags, false);
1658 if (i < n - 1)
1659 pp_string (buffer, ", ");
1663 newline_and_indent (buffer, spc);
1664 pp_greater (buffer);
1666 else
1668 pp_string (buffer, "__asm__");
1669 if (gimple_asm_volatile_p (gs))
1670 pp_string (buffer, " __volatile__");
1671 if (gimple_asm_nlabels (gs))
1672 pp_string (buffer, " goto");
1673 pp_string (buffer, "(\"");
1674 pp_string (buffer, gimple_asm_string (gs));
1675 pp_string (buffer, "\"");
1677 if (gimple_asm_nlabels (gs))
1678 fields = 4;
1679 else if (gimple_asm_nclobbers (gs))
1680 fields = 3;
1681 else if (gimple_asm_ninputs (gs))
1682 fields = 2;
1683 else if (gimple_asm_noutputs (gs))
1684 fields = 1;
1685 else
1686 fields = 0;
1688 for (f = 0; f < fields; ++f)
1690 pp_string (buffer, " : ");
1692 switch (f)
1694 case 0:
1695 n = gimple_asm_noutputs (gs);
1696 for (i = 0; i < n; i++)
1698 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1699 spc, flags, false);
1700 if (i < n - 1)
1701 pp_string (buffer, ", ");
1703 break;
1705 case 1:
1706 n = gimple_asm_ninputs (gs);
1707 for (i = 0; i < n; i++)
1709 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1710 spc, flags, false);
1711 if (i < n - 1)
1712 pp_string (buffer, ", ");
1714 break;
1716 case 2:
1717 n = gimple_asm_nclobbers (gs);
1718 for (i = 0; i < n; i++)
1720 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1721 spc, flags, false);
1722 if (i < n - 1)
1723 pp_string (buffer, ", ");
1725 break;
1727 case 3:
1728 n = gimple_asm_nlabels (gs);
1729 for (i = 0; i < n; i++)
1731 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1732 spc, flags, false);
1733 if (i < n - 1)
1734 pp_string (buffer, ", ");
1736 break;
1738 default:
1739 gcc_unreachable ();
1743 pp_string (buffer, ");");
1747 /* Dump ptr_info and range_info for NODE on pretty_printer BUFFER with
1748 SPC spaces of indent. */
1750 static void
1751 dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
1753 if (TREE_CODE (node) != SSA_NAME)
1754 return;
1756 if (POINTER_TYPE_P (TREE_TYPE (node))
1757 && SSA_NAME_PTR_INFO (node))
1759 unsigned int align, misalign;
1760 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (node);
1761 pp_string (buffer, "# PT = ");
1762 pp_points_to_solution (buffer, &pi->pt);
1763 newline_and_indent (buffer, spc);
1764 if (get_ptr_info_alignment (pi, &align, &misalign))
1766 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u", align, misalign);
1767 newline_and_indent (buffer, spc);
1771 if (!POINTER_TYPE_P (TREE_TYPE (node))
1772 && SSA_NAME_RANGE_INFO (node))
1774 wide_int min, max, nonzero_bits;
1775 value_range_type range_type = get_range_info (node, &min, &max);
1777 if (range_type == VR_VARYING)
1778 pp_printf (buffer, "# RANGE VR_VARYING");
1779 else if (range_type == VR_RANGE || range_type == VR_ANTI_RANGE)
1781 pp_printf (buffer, "# RANGE ");
1782 pp_printf (buffer, "%s[", range_type == VR_RANGE ? "" : "~");
1783 pp_wide_int (buffer, min, TYPE_SIGN (TREE_TYPE (node)));
1784 pp_printf (buffer, ", ");
1785 pp_wide_int (buffer, max, TYPE_SIGN (TREE_TYPE (node)));
1786 pp_printf (buffer, "]");
1788 nonzero_bits = get_nonzero_bits (node);
1789 if (nonzero_bits != -1)
1791 pp_string (buffer, " NONZERO ");
1792 pp_wide_int (buffer, nonzero_bits, UNSIGNED);
1794 newline_and_indent (buffer, spc);
1799 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
1800 The caller is responsible for calling pp_flush on BUFFER to finalize
1801 pretty printer. If COMMENT is true, print this after #. */
1803 static void
1804 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, bool comment,
1805 int flags)
1807 size_t i;
1808 tree lhs = gimple_phi_result (phi);
1810 if (flags & TDF_ALIAS)
1811 dump_ssaname_info (buffer, lhs, spc);
1813 if (comment)
1814 pp_string (buffer, "# ");
1816 if (flags & TDF_RAW)
1817 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1818 gimple_phi_result (phi));
1819 else
1821 dump_generic_node (buffer, lhs, spc, flags, false);
1822 pp_string (buffer, " = PHI <");
1824 for (i = 0; i < gimple_phi_num_args (phi); i++)
1826 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1828 expanded_location xloc;
1830 xloc = expand_location (gimple_phi_arg_location (phi, i));
1831 pp_left_bracket (buffer);
1832 if (xloc.file)
1834 pp_string (buffer, xloc.file);
1835 pp_string (buffer, " : ");
1837 pp_decimal_int (buffer, xloc.line);
1838 pp_colon (buffer);
1839 pp_decimal_int (buffer, xloc.column);
1840 pp_string (buffer, "] ");
1842 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1843 false);
1844 pp_left_paren (buffer);
1845 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1846 pp_right_paren (buffer);
1847 if (i < gimple_phi_num_args (phi) - 1)
1848 pp_string (buffer, ", ");
1850 pp_greater (buffer);
1854 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1855 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1856 dumpfile.h). */
1858 static void
1859 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1860 int flags)
1862 if (flags & TDF_RAW)
1864 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1865 gimple_omp_body (gs));
1866 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1867 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1868 gimple_omp_parallel_child_fn (gs),
1869 gimple_omp_parallel_data_arg (gs));
1871 else
1873 gimple_seq body;
1874 pp_string (buffer, "#pragma omp parallel");
1875 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1876 if (gimple_omp_parallel_child_fn (gs))
1878 pp_string (buffer, " [child fn: ");
1879 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1880 spc, flags, false);
1881 pp_string (buffer, " (");
1882 if (gimple_omp_parallel_data_arg (gs))
1883 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1884 spc, flags, false);
1885 else
1886 pp_string (buffer, "???");
1887 pp_string (buffer, ")]");
1889 body = gimple_omp_body (gs);
1890 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1892 newline_and_indent (buffer, spc + 2);
1893 pp_left_brace (buffer);
1894 pp_newline (buffer);
1895 dump_gimple_seq (buffer, body, spc + 4, flags);
1896 newline_and_indent (buffer, spc + 2);
1897 pp_right_brace (buffer);
1899 else if (body)
1901 pp_newline (buffer);
1902 dump_gimple_seq (buffer, body, spc + 2, flags);
1908 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1909 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1910 dumpfile.h). */
1912 static void
1913 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1914 int flags)
1916 if (flags & TDF_RAW)
1918 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1919 gimple_omp_body (gs));
1920 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1921 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1922 gimple_omp_task_child_fn (gs),
1923 gimple_omp_task_data_arg (gs),
1924 gimple_omp_task_copy_fn (gs),
1925 gimple_omp_task_arg_size (gs),
1926 gimple_omp_task_arg_size (gs));
1928 else
1930 gimple_seq body;
1931 pp_string (buffer, "#pragma omp task");
1932 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1933 if (gimple_omp_task_child_fn (gs))
1935 pp_string (buffer, " [child fn: ");
1936 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1937 spc, flags, false);
1938 pp_string (buffer, " (");
1939 if (gimple_omp_task_data_arg (gs))
1940 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1941 spc, flags, false);
1942 else
1943 pp_string (buffer, "???");
1944 pp_string (buffer, ")]");
1946 body = gimple_omp_body (gs);
1947 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1949 newline_and_indent (buffer, spc + 2);
1950 pp_left_brace (buffer);
1951 pp_newline (buffer);
1952 dump_gimple_seq (buffer, body, spc + 4, flags);
1953 newline_and_indent (buffer, spc + 2);
1954 pp_right_brace (buffer);
1956 else if (body)
1958 pp_newline (buffer);
1959 dump_gimple_seq (buffer, body, spc + 2, flags);
1965 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1966 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1967 in dumpfile.h). */
1969 static void
1970 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1971 int flags)
1973 if (flags & TDF_RAW)
1975 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1976 gimple_omp_atomic_load_lhs (gs),
1977 gimple_omp_atomic_load_rhs (gs));
1979 else
1981 pp_string (buffer, "#pragma omp atomic_load");
1982 if (gimple_omp_atomic_seq_cst_p (gs))
1983 pp_string (buffer, " seq_cst");
1984 if (gimple_omp_atomic_need_value_p (gs))
1985 pp_string (buffer, " [needed]");
1986 newline_and_indent (buffer, spc + 2);
1987 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1988 spc, flags, false);
1989 pp_space (buffer);
1990 pp_equal (buffer);
1991 pp_space (buffer);
1992 pp_star (buffer);
1993 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1994 spc, flags, false);
1998 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1999 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2000 in dumpfile.h). */
2002 static void
2003 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
2004 int flags)
2006 if (flags & TDF_RAW)
2008 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
2009 gimple_omp_atomic_store_val (gs));
2011 else
2013 pp_string (buffer, "#pragma omp atomic_store ");
2014 if (gimple_omp_atomic_seq_cst_p (gs))
2015 pp_string (buffer, "seq_cst ");
2016 if (gimple_omp_atomic_need_value_p (gs))
2017 pp_string (buffer, "[needed] ");
2018 pp_left_paren (buffer);
2019 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
2020 spc, flags, false);
2021 pp_right_paren (buffer);
2026 /* Dump all the memory operands for statement GS. BUFFER, SPC and
2027 FLAGS are as in pp_gimple_stmt_1. */
2029 static void
2030 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
2032 tree vdef = gimple_vdef (gs);
2033 tree vuse = gimple_vuse (gs);
2035 if (vdef != NULL_TREE)
2037 pp_string (buffer, "# ");
2038 dump_generic_node (buffer, vdef, spc + 2, flags, false);
2039 pp_string (buffer, " = VDEF <");
2040 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2041 pp_greater (buffer);
2042 newline_and_indent (buffer, spc);
2044 else if (vuse != NULL_TREE)
2046 pp_string (buffer, "# VUSE <");
2047 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2048 pp_greater (buffer);
2049 newline_and_indent (buffer, spc);
2054 /* Print the gimple statement GS on the pretty printer BUFFER, SPC
2055 spaces of indent. FLAGS specifies details to show in the dump (see
2056 TDF_* in dumpfile.h). The caller is responsible for calling
2057 pp_flush on BUFFER to finalize the pretty printer. */
2059 void
2060 pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags)
2062 if (!gs)
2063 return;
2065 if (flags & TDF_STMTADDR)
2066 pp_printf (buffer, "<&%p> ", (void *) gs);
2068 if ((flags & TDF_LINENO) && gimple_has_location (gs))
2070 expanded_location xloc = expand_location (gimple_location (gs));
2071 pp_left_bracket (buffer);
2072 if (xloc.file)
2074 pp_string (buffer, xloc.file);
2075 pp_string (buffer, " : ");
2077 pp_decimal_int (buffer, xloc.line);
2078 pp_colon (buffer);
2079 pp_decimal_int (buffer, xloc.column);
2080 pp_string (buffer, "] ");
2083 if (flags & TDF_EH)
2085 int lp_nr = lookup_stmt_eh_lp (gs);
2086 if (lp_nr > 0)
2087 pp_printf (buffer, "[LP %d] ", lp_nr);
2088 else if (lp_nr < 0)
2089 pp_printf (buffer, "[MNT %d] ", -lp_nr);
2092 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
2093 && gimple_has_mem_ops (gs))
2094 dump_gimple_mem_ops (buffer, gs, spc, flags);
2096 if (gimple_has_lhs (gs)
2097 && (flags & TDF_ALIAS))
2098 dump_ssaname_info (buffer, gimple_get_lhs (gs), spc);
2100 switch (gimple_code (gs))
2102 case GIMPLE_ASM:
2103 dump_gimple_asm (buffer, gs, spc, flags);
2104 break;
2106 case GIMPLE_ASSIGN:
2107 dump_gimple_assign (buffer, gs, spc, flags);
2108 break;
2110 case GIMPLE_BIND:
2111 dump_gimple_bind (buffer, gs, spc, flags);
2112 break;
2114 case GIMPLE_CALL:
2115 dump_gimple_call (buffer, gs, spc, flags);
2116 break;
2118 case GIMPLE_COND:
2119 dump_gimple_cond (buffer, gs, spc, flags);
2120 break;
2122 case GIMPLE_LABEL:
2123 dump_gimple_label (buffer, gs, spc, flags);
2124 break;
2126 case GIMPLE_GOTO:
2127 dump_gimple_goto (buffer, gs, spc, flags);
2128 break;
2130 case GIMPLE_NOP:
2131 pp_string (buffer, "GIMPLE_NOP");
2132 break;
2134 case GIMPLE_RETURN:
2135 dump_gimple_return (buffer, gs, spc, flags);
2136 break;
2138 case GIMPLE_SWITCH:
2139 dump_gimple_switch (buffer, gs, spc, flags);
2140 break;
2142 case GIMPLE_TRY:
2143 dump_gimple_try (buffer, gs, spc, flags);
2144 break;
2146 case GIMPLE_PHI:
2147 dump_gimple_phi (buffer, gs, spc, false, flags);
2148 break;
2150 case GIMPLE_OMP_PARALLEL:
2151 dump_gimple_omp_parallel (buffer, gs, spc, flags);
2152 break;
2154 case GIMPLE_OMP_TASK:
2155 dump_gimple_omp_task (buffer, gs, spc, flags);
2156 break;
2158 case GIMPLE_OMP_ATOMIC_LOAD:
2159 dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
2161 break;
2163 case GIMPLE_OMP_ATOMIC_STORE:
2164 dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
2165 break;
2167 case GIMPLE_OMP_FOR:
2168 dump_gimple_omp_for (buffer, gs, spc, flags);
2169 break;
2171 case GIMPLE_OMP_CONTINUE:
2172 dump_gimple_omp_continue (buffer, gs, spc, flags);
2173 break;
2175 case GIMPLE_OMP_SINGLE:
2176 dump_gimple_omp_single (buffer, gs, spc, flags);
2177 break;
2179 case GIMPLE_OMP_TARGET:
2180 dump_gimple_omp_target (buffer, gs, spc, flags);
2181 break;
2183 case GIMPLE_OMP_TEAMS:
2184 dump_gimple_omp_teams (buffer, gs, spc, flags);
2185 break;
2187 case GIMPLE_OMP_RETURN:
2188 dump_gimple_omp_return (buffer, gs, spc, flags);
2189 break;
2191 case GIMPLE_OMP_SECTIONS:
2192 dump_gimple_omp_sections (buffer, gs, spc, flags);
2193 break;
2195 case GIMPLE_OMP_SECTIONS_SWITCH:
2196 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
2197 break;
2199 case GIMPLE_OMP_MASTER:
2200 case GIMPLE_OMP_TASKGROUP:
2201 case GIMPLE_OMP_ORDERED:
2202 case GIMPLE_OMP_SECTION:
2203 dump_gimple_omp_block (buffer, gs, spc, flags);
2204 break;
2206 case GIMPLE_OMP_CRITICAL:
2207 dump_gimple_omp_critical (buffer, gs, spc, flags);
2208 break;
2210 case GIMPLE_CATCH:
2211 dump_gimple_catch (buffer, gs, spc, flags);
2212 break;
2214 case GIMPLE_EH_FILTER:
2215 dump_gimple_eh_filter (buffer, gs, spc, flags);
2216 break;
2218 case GIMPLE_EH_MUST_NOT_THROW:
2219 dump_gimple_eh_must_not_throw (buffer, gs, spc, flags);
2220 break;
2222 case GIMPLE_EH_ELSE:
2223 dump_gimple_eh_else (buffer, gs, spc, flags);
2224 break;
2226 case GIMPLE_RESX:
2227 dump_gimple_resx (buffer, gs, spc, flags);
2228 break;
2230 case GIMPLE_EH_DISPATCH:
2231 dump_gimple_eh_dispatch (buffer, gs, spc, flags);
2232 break;
2234 case GIMPLE_DEBUG:
2235 dump_gimple_debug (buffer, gs, spc, flags);
2236 break;
2238 case GIMPLE_PREDICT:
2239 pp_string (buffer, "// predicted ");
2240 if (gimple_predict_outcome (gs))
2241 pp_string (buffer, "likely by ");
2242 else
2243 pp_string (buffer, "unlikely by ");
2244 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
2245 pp_string (buffer, " predictor.");
2246 break;
2248 case GIMPLE_TRANSACTION:
2249 dump_gimple_transaction (buffer, gs, spc, flags);
2250 break;
2252 default:
2253 GIMPLE_NIY;
2258 /* Dumps header of basic block BB to OUTF indented by INDENT
2259 spaces and details described by flags. */
2261 static void
2262 dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
2264 if (flags & TDF_BLOCKS)
2266 if (flags & TDF_LINENO)
2268 gimple_stmt_iterator gsi;
2270 if (flags & TDF_COMMENT)
2271 fputs (";; ", outf);
2273 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2274 if (!is_gimple_debug (gsi_stmt (gsi))
2275 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
2277 fprintf (outf, "%*sstarting at line %d",
2278 indent, "", get_lineno (gsi_stmt (gsi)));
2279 break;
2281 if (bb->discriminator)
2282 fprintf (outf, ", discriminator %i", bb->discriminator);
2283 fputc ('\n', outf);
2286 else
2288 gimple stmt = first_stmt (bb);
2289 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
2290 fprintf (outf, "%*s<bb %d>:\n", indent, "", bb->index);
2295 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2296 spaces. */
2298 static void
2299 dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
2300 basic_block bb ATTRIBUTE_UNUSED,
2301 int indent ATTRIBUTE_UNUSED,
2302 int flags ATTRIBUTE_UNUSED)
2304 /* There is currently no GIMPLE-specific basic block info to dump. */
2305 return;
2309 /* Dump PHI nodes of basic block BB to BUFFER with details described
2310 by FLAGS and indented by INDENT spaces. */
2312 static void
2313 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2315 gimple_stmt_iterator i;
2317 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2319 gimple phi = gsi_stmt (i);
2320 if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2322 INDENT (indent);
2323 dump_gimple_phi (buffer, phi, indent, true, flags);
2324 pp_newline (buffer);
2330 /* Dump jump to basic block BB that is represented implicitly in the cfg
2331 to BUFFER. */
2333 static void
2334 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2336 gimple stmt;
2338 stmt = first_stmt (bb);
2340 pp_string (buffer, "goto <bb ");
2341 pp_decimal_int (buffer, bb->index);
2342 pp_greater (buffer);
2343 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
2345 pp_string (buffer, " (");
2346 dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
2347 pp_right_paren (buffer);
2348 pp_semicolon (buffer);
2350 else
2351 pp_semicolon (buffer);
2355 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2356 by INDENT spaces, with details given by FLAGS. */
2358 static void
2359 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2360 int flags)
2362 edge e;
2363 gimple stmt;
2365 stmt = last_stmt (bb);
2367 if (stmt && gimple_code (stmt) == GIMPLE_COND)
2369 edge true_edge, false_edge;
2371 /* When we are emitting the code or changing CFG, it is possible that
2372 the edges are not yet created. When we are using debug_bb in such
2373 a situation, we do not want it to crash. */
2374 if (EDGE_COUNT (bb->succs) != 2)
2375 return;
2376 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2378 INDENT (indent + 2);
2379 pp_cfg_jump (buffer, true_edge->dest);
2380 newline_and_indent (buffer, indent);
2381 pp_string (buffer, "else");
2382 newline_and_indent (buffer, indent + 2);
2383 pp_cfg_jump (buffer, false_edge->dest);
2384 pp_newline (buffer);
2385 return;
2388 /* If there is a fallthru edge, we may need to add an artificial
2389 goto to the dump. */
2390 e = find_fallthru_edge (bb->succs);
2392 if (e && e->dest != bb->next_bb)
2394 INDENT (indent);
2396 if ((flags & TDF_LINENO)
2397 && e->goto_locus != UNKNOWN_LOCATION
2400 expanded_location goto_xloc;
2401 goto_xloc = expand_location (e->goto_locus);
2402 pp_left_bracket (buffer);
2403 if (goto_xloc.file)
2405 pp_string (buffer, goto_xloc.file);
2406 pp_string (buffer, " : ");
2408 pp_decimal_int (buffer, goto_xloc.line);
2409 pp_string (buffer, " : ");
2410 pp_decimal_int (buffer, goto_xloc.column);
2411 pp_string (buffer, "] ");
2414 pp_cfg_jump (buffer, e->dest);
2415 pp_newline (buffer);
2420 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2421 indented by INDENT spaces. */
2423 static void
2424 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2425 int flags)
2427 gimple_stmt_iterator gsi;
2428 gimple stmt;
2429 int label_indent = indent - 2;
2431 if (label_indent < 0)
2432 label_indent = 0;
2434 dump_phi_nodes (buffer, bb, indent, flags);
2436 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2438 int curr_indent;
2440 stmt = gsi_stmt (gsi);
2442 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2444 INDENT (curr_indent);
2445 pp_gimple_stmt_1 (buffer, stmt, curr_indent, flags);
2446 pp_newline_and_flush (buffer);
2447 gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl));
2448 dump_histograms_for_stmt (DECL_STRUCT_FUNCTION (current_function_decl),
2449 pp_buffer (buffer)->stream, stmt);
2452 dump_implicit_edges (buffer, bb, indent, flags);
2453 pp_flush (buffer);
2457 /* Dumps basic block BB to FILE with details described by FLAGS and
2458 indented by INDENT spaces. */
2460 void
2461 gimple_dump_bb (FILE *file, basic_block bb, int indent, int flags)
2463 dump_gimple_bb_header (file, bb, indent, flags);
2464 if (bb->index >= NUM_FIXED_BLOCKS)
2466 pretty_printer buffer;
2467 pp_needs_newline (&buffer) = true;
2468 buffer.buffer->stream = file;
2469 gimple_dump_bb_buff (&buffer, bb, indent, flags);
2471 dump_gimple_bb_footer (file, bb, indent, flags);
2474 /* Dumps basic block BB to pretty-printer PP with default dump flags and
2475 no indentation, for use as a label of a DOT graph record-node.
2476 ??? Should just use gimple_dump_bb_buff here, except that value profiling
2477 histogram dumping doesn't know about pretty-printers. */
2479 void
2480 gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
2482 gimple_stmt_iterator gsi;
2484 pp_printf (pp, "<bb %d>:\n", bb->index);
2485 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2487 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2489 gimple phi = gsi_stmt (gsi);
2490 if (!virtual_operand_p (gimple_phi_result (phi))
2491 || (dump_flags & TDF_VOPS))
2493 pp_bar (pp);
2494 pp_write_text_to_stream (pp);
2495 pp_string (pp, "# ");
2496 pp_gimple_stmt_1 (pp, phi, 0, dump_flags);
2497 pp_newline (pp);
2498 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2502 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2504 gimple stmt = gsi_stmt (gsi);
2505 pp_bar (pp);
2506 pp_write_text_to_stream (pp);
2507 pp_gimple_stmt_1 (pp, stmt, 0, dump_flags);
2508 pp_newline (pp);
2509 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2511 dump_implicit_edges (pp, bb, 0, dump_flags);
2512 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);