* g++.dg/template/using30.C: Move ...
[official-gcc.git] / gcc / gimple-pretty-print.c
blob39e25721c21733e2802b4f7f527e024b7e3b0d60
1 /* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldyh@redhat.com> and
4 Diego Novillo <dnovillo@google.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "stringpool.h"
28 #include "diagnostic.h"
29 #include "gimple-pretty-print.h"
30 #include "hashtab.h"
31 #include "bitmap.h"
32 #include "predict.h"
33 #include "vec.h"
34 #include "hash-set.h"
35 #include "machmode.h"
36 #include "hard-reg-set.h"
37 #include "input.h"
38 #include "function.h"
39 #include "basic-block.h"
40 #include "tree-ssa-alias.h"
41 #include "internal-fn.h"
42 #include "tree-eh.h"
43 #include "gimple-expr.h"
44 #include "is-a.h"
45 #include "gimple.h"
46 #include "gimple-iterator.h"
47 #include "gimple-ssa.h"
48 #include "hash-map.h"
49 #include "plugin-api.h"
50 #include "ipa-ref.h"
51 #include "cgraph.h"
52 #include "tree-cfg.h"
53 #include "tree-ssanames.h"
54 #include "dumpfile.h" /* for dump_flags */
55 #include "value-prof.h"
56 #include "trans-mem.h"
58 #define INDENT(SPACE) \
59 do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
61 #define GIMPLE_NIY do_niy (buffer,gs)
63 /* Try to print on BUFFER a default message for the unrecognized
64 gimple statement GS. */
66 static void
67 do_niy (pretty_printer *buffer, gimple gs)
69 pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
70 gimple_code_name[(int) gimple_code (gs)]);
74 /* Emit a newline and SPC indentation spaces to BUFFER. */
76 static void
77 newline_and_indent (pretty_printer *buffer, int spc)
79 pp_newline (buffer);
80 INDENT (spc);
84 /* Print the GIMPLE statement GS on stderr. */
86 DEBUG_FUNCTION void
87 debug_gimple_stmt (gimple gs)
89 print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
93 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
94 FLAGS as in pp_gimple_stmt_1. */
96 void
97 print_gimple_stmt (FILE *file, gimple g, int spc, int flags)
99 pretty_printer buffer;
100 pp_needs_newline (&buffer) = true;
101 buffer.buffer->stream = file;
102 pp_gimple_stmt_1 (&buffer, g, spc, flags);
103 pp_newline_and_flush (&buffer);
106 DEBUG_FUNCTION void
107 debug (gimple_statement_base &ref)
109 print_gimple_stmt (stderr, &ref, 0, 0);
112 DEBUG_FUNCTION void
113 debug (gimple_statement_base *ptr)
115 if (ptr)
116 debug (*ptr);
117 else
118 fprintf (stderr, "<nil>\n");
122 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
123 FLAGS as in pp_gimple_stmt_1. Print only the right-hand side
124 of the statement. */
126 void
127 print_gimple_expr (FILE *file, gimple g, int spc, int flags)
129 flags |= TDF_RHS_ONLY;
130 pretty_printer buffer;
131 pp_needs_newline (&buffer) = true;
132 buffer.buffer->stream = file;
133 pp_gimple_stmt_1 (&buffer, g, spc, flags);
134 pp_flush (&buffer);
138 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentation
139 spaces and FLAGS as in pp_gimple_stmt_1.
140 The caller is responsible for calling pp_flush on BUFFER to finalize
141 the pretty printer. */
143 static void
144 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc, int flags)
146 gimple_stmt_iterator i;
148 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
150 gimple gs = gsi_stmt (i);
151 INDENT (spc);
152 pp_gimple_stmt_1 (buffer, gs, spc, flags);
153 if (!gsi_one_before_end_p (i))
154 pp_newline (buffer);
159 /* Print GIMPLE sequence SEQ to FILE using SPC indentation spaces and
160 FLAGS as in pp_gimple_stmt_1. */
162 void
163 print_gimple_seq (FILE *file, gimple_seq seq, int spc, int flags)
165 pretty_printer buffer;
166 pp_needs_newline (&buffer) = true;
167 buffer.buffer->stream = file;
168 dump_gimple_seq (&buffer, seq, spc, flags);
169 pp_newline_and_flush (&buffer);
173 /* Print the GIMPLE sequence SEQ on stderr. */
175 DEBUG_FUNCTION void
176 debug_gimple_seq (gimple_seq seq)
178 print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
182 /* A simple helper to pretty-print some of the gimple tuples in the printf
183 style. The format modifiers are preceded by '%' and are:
184 'G' - outputs a string corresponding to the code of the given gimple,
185 'S' - outputs a gimple_seq with indent of spc + 2,
186 'T' - outputs the tree t,
187 'd' - outputs an int as a decimal,
188 's' - outputs a string,
189 'n' - outputs a newline,
190 'x' - outputs an int as hexadecimal,
191 '+' - increases indent by 2 then outputs a newline,
192 '-' - decreases indent by 2 then outputs a newline. */
194 static void
195 dump_gimple_fmt (pretty_printer *buffer, int spc, int flags,
196 const char *fmt, ...)
198 va_list args;
199 const char *c;
200 const char *tmp;
202 va_start (args, fmt);
203 for (c = fmt; *c; c++)
205 if (*c == '%')
207 gimple_seq seq;
208 tree t;
209 gimple g;
210 switch (*++c)
212 case 'G':
213 g = va_arg (args, gimple);
214 tmp = gimple_code_name[gimple_code (g)];
215 pp_string (buffer, tmp);
216 break;
218 case 'S':
219 seq = va_arg (args, gimple_seq);
220 pp_newline (buffer);
221 dump_gimple_seq (buffer, seq, spc + 2, flags);
222 newline_and_indent (buffer, spc);
223 break;
225 case 'T':
226 t = va_arg (args, tree);
227 if (t == NULL_TREE)
228 pp_string (buffer, "NULL");
229 else
230 dump_generic_node (buffer, t, spc, flags, false);
231 break;
233 case 'd':
234 pp_decimal_int (buffer, va_arg (args, int));
235 break;
237 case 's':
238 pp_string (buffer, va_arg (args, char *));
239 break;
241 case 'n':
242 newline_and_indent (buffer, spc);
243 break;
245 case 'x':
246 pp_scalar (buffer, "%x", va_arg (args, int));
247 break;
249 case '+':
250 spc += 2;
251 newline_and_indent (buffer, spc);
252 break;
254 case '-':
255 spc -= 2;
256 newline_and_indent (buffer, spc);
257 break;
259 default:
260 gcc_unreachable ();
263 else
264 pp_character (buffer, *c);
266 va_end (args);
270 /* Helper for dump_gimple_assign. Print the unary RHS of the
271 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
273 static void
274 dump_unary_rhs (pretty_printer *buffer, gassign *gs, int spc, int flags)
276 enum tree_code rhs_code = gimple_assign_rhs_code (gs);
277 tree lhs = gimple_assign_lhs (gs);
278 tree rhs = gimple_assign_rhs1 (gs);
280 switch (rhs_code)
282 case VIEW_CONVERT_EXPR:
283 case ASSERT_EXPR:
284 dump_generic_node (buffer, rhs, spc, flags, false);
285 break;
287 case FIXED_CONVERT_EXPR:
288 case ADDR_SPACE_CONVERT_EXPR:
289 case FIX_TRUNC_EXPR:
290 case FLOAT_EXPR:
291 CASE_CONVERT:
292 pp_left_paren (buffer);
293 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
294 pp_string (buffer, ") ");
295 if (op_prio (rhs) < op_code_prio (rhs_code))
297 pp_left_paren (buffer);
298 dump_generic_node (buffer, rhs, spc, flags, false);
299 pp_right_paren (buffer);
301 else
302 dump_generic_node (buffer, rhs, spc, flags, false);
303 break;
305 case PAREN_EXPR:
306 pp_string (buffer, "((");
307 dump_generic_node (buffer, rhs, spc, flags, false);
308 pp_string (buffer, "))");
309 break;
311 case ABS_EXPR:
312 pp_string (buffer, "ABS_EXPR <");
313 dump_generic_node (buffer, rhs, spc, flags, false);
314 pp_greater (buffer);
315 break;
317 default:
318 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
319 || TREE_CODE_CLASS (rhs_code) == tcc_constant
320 || TREE_CODE_CLASS (rhs_code) == tcc_reference
321 || rhs_code == SSA_NAME
322 || rhs_code == ADDR_EXPR
323 || rhs_code == CONSTRUCTOR)
325 dump_generic_node (buffer, rhs, spc, flags, false);
326 break;
328 else if (rhs_code == BIT_NOT_EXPR)
329 pp_complement (buffer);
330 else if (rhs_code == TRUTH_NOT_EXPR)
331 pp_exclamation (buffer);
332 else if (rhs_code == NEGATE_EXPR)
333 pp_minus (buffer);
334 else
336 pp_left_bracket (buffer);
337 pp_string (buffer, get_tree_code_name (rhs_code));
338 pp_string (buffer, "] ");
341 if (op_prio (rhs) < op_code_prio (rhs_code))
343 pp_left_paren (buffer);
344 dump_generic_node (buffer, rhs, spc, flags, false);
345 pp_right_paren (buffer);
347 else
348 dump_generic_node (buffer, rhs, spc, flags, false);
349 break;
354 /* Helper for dump_gimple_assign. Print the binary RHS of the
355 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
357 static void
358 dump_binary_rhs (pretty_printer *buffer, gassign *gs, int spc, int flags)
360 const char *p;
361 enum tree_code code = gimple_assign_rhs_code (gs);
362 switch (code)
364 case COMPLEX_EXPR:
365 case MIN_EXPR:
366 case MAX_EXPR:
367 case VEC_WIDEN_MULT_HI_EXPR:
368 case VEC_WIDEN_MULT_LO_EXPR:
369 case VEC_WIDEN_MULT_EVEN_EXPR:
370 case VEC_WIDEN_MULT_ODD_EXPR:
371 case VEC_PACK_TRUNC_EXPR:
372 case VEC_PACK_SAT_EXPR:
373 case VEC_PACK_FIX_TRUNC_EXPR:
374 case VEC_WIDEN_LSHIFT_HI_EXPR:
375 case VEC_WIDEN_LSHIFT_LO_EXPR:
376 for (p = get_tree_code_name (code); *p; p++)
377 pp_character (buffer, TOUPPER (*p));
378 pp_string (buffer, " <");
379 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
380 pp_string (buffer, ", ");
381 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
382 pp_greater (buffer);
383 break;
385 default:
386 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
388 pp_left_paren (buffer);
389 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
390 false);
391 pp_right_paren (buffer);
393 else
394 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
395 pp_space (buffer);
396 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
397 pp_space (buffer);
398 if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
400 pp_left_paren (buffer);
401 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
402 false);
403 pp_right_paren (buffer);
405 else
406 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
410 /* Helper for dump_gimple_assign. Print the ternary RHS of the
411 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
413 static void
414 dump_ternary_rhs (pretty_printer *buffer, gassign *gs, int spc, int flags)
416 const char *p;
417 enum tree_code code = gimple_assign_rhs_code (gs);
418 switch (code)
420 case WIDEN_MULT_PLUS_EXPR:
421 case WIDEN_MULT_MINUS_EXPR:
422 for (p = get_tree_code_name (code); *p; p++)
423 pp_character (buffer, TOUPPER (*p));
424 pp_string (buffer, " <");
425 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
426 pp_string (buffer, ", ");
427 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
428 pp_string (buffer, ", ");
429 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
430 pp_greater (buffer);
431 break;
433 case FMA_EXPR:
434 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
435 pp_string (buffer, " * ");
436 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
437 pp_string (buffer, " + ");
438 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
439 break;
441 case DOT_PROD_EXPR:
442 pp_string (buffer, "DOT_PROD_EXPR <");
443 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
444 pp_string (buffer, ", ");
445 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
446 pp_string (buffer, ", ");
447 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
448 pp_greater (buffer);
449 break;
451 case SAD_EXPR:
452 pp_string (buffer, "SAD_EXPR <");
453 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
454 pp_string (buffer, ", ");
455 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
456 pp_string (buffer, ", ");
457 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
458 pp_greater (buffer);
459 break;
461 case VEC_PERM_EXPR:
462 pp_string (buffer, "VEC_PERM_EXPR <");
463 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
464 pp_string (buffer, ", ");
465 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
466 pp_string (buffer, ", ");
467 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
468 pp_greater (buffer);
469 break;
471 case REALIGN_LOAD_EXPR:
472 pp_string (buffer, "REALIGN_LOAD <");
473 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
474 pp_string (buffer, ", ");
475 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
476 pp_string (buffer, ", ");
477 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
478 pp_greater (buffer);
479 break;
481 case COND_EXPR:
482 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
483 pp_string (buffer, " ? ");
484 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
485 pp_string (buffer, " : ");
486 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
487 break;
489 case VEC_COND_EXPR:
490 pp_string (buffer, "VEC_COND_EXPR <");
491 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
492 pp_string (buffer, ", ");
493 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
494 pp_string (buffer, ", ");
495 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
496 pp_greater (buffer);
497 break;
499 default:
500 gcc_unreachable ();
505 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
506 pp_gimple_stmt_1. */
508 static void
509 dump_gimple_assign (pretty_printer *buffer, gassign *gs, int spc, int flags)
511 if (flags & TDF_RAW)
513 tree arg1 = NULL;
514 tree arg2 = NULL;
515 tree arg3 = NULL;
516 switch (gimple_num_ops (gs))
518 case 4:
519 arg3 = gimple_assign_rhs3 (gs);
520 case 3:
521 arg2 = gimple_assign_rhs2 (gs);
522 case 2:
523 arg1 = gimple_assign_rhs1 (gs);
524 break;
525 default:
526 gcc_unreachable ();
529 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
530 get_tree_code_name (gimple_assign_rhs_code (gs)),
531 gimple_assign_lhs (gs), arg1, arg2, arg3);
533 else
535 if (!(flags & TDF_RHS_ONLY))
537 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
538 pp_space (buffer);
539 pp_equal (buffer);
541 if (gimple_assign_nontemporal_move_p (gs))
542 pp_string (buffer, "{nt}");
544 if (gimple_has_volatile_ops (gs))
545 pp_string (buffer, "{v}");
547 pp_space (buffer);
550 if (gimple_num_ops (gs) == 2)
551 dump_unary_rhs (buffer, gs, spc, flags);
552 else if (gimple_num_ops (gs) == 3)
553 dump_binary_rhs (buffer, gs, spc, flags);
554 else if (gimple_num_ops (gs) == 4)
555 dump_ternary_rhs (buffer, gs, spc, flags);
556 else
557 gcc_unreachable ();
558 if (!(flags & TDF_RHS_ONLY))
559 pp_semicolon (buffer);
564 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
565 pp_gimple_stmt_1. */
567 static void
568 dump_gimple_return (pretty_printer *buffer, greturn *gs, int spc, int flags)
570 tree t, t2;
572 t = gimple_return_retval (gs);
573 t2 = gimple_return_retbnd (gs);
574 if (flags & TDF_RAW)
575 dump_gimple_fmt (buffer, spc, flags, "%G <%T %T>", gs, t, t2);
576 else
578 pp_string (buffer, "return");
579 if (t)
581 pp_space (buffer);
582 dump_generic_node (buffer, t, spc, flags, false);
584 if (t2)
586 pp_string (buffer, ", ");
587 dump_generic_node (buffer, t2, spc, flags, false);
589 pp_semicolon (buffer);
594 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
595 dump_gimple_call. */
597 static void
598 dump_gimple_call_args (pretty_printer *buffer, gcall *gs, int flags)
600 size_t i;
602 for (i = 0; i < gimple_call_num_args (gs); i++)
604 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
605 if (i < gimple_call_num_args (gs) - 1)
606 pp_string (buffer, ", ");
609 if (gimple_call_va_arg_pack_p (gs))
611 if (gimple_call_num_args (gs) > 0)
613 pp_comma (buffer);
614 pp_space (buffer);
617 pp_string (buffer, "__builtin_va_arg_pack ()");
621 /* Dump the points-to solution *PT to BUFFER. */
623 static void
624 pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
626 if (pt->anything)
628 pp_string (buffer, "anything ");
629 return;
631 if (pt->nonlocal)
632 pp_string (buffer, "nonlocal ");
633 if (pt->escaped)
634 pp_string (buffer, "escaped ");
635 if (pt->ipa_escaped)
636 pp_string (buffer, "unit-escaped ");
637 if (pt->null)
638 pp_string (buffer, "null ");
639 if (pt->vars
640 && !bitmap_empty_p (pt->vars))
642 bitmap_iterator bi;
643 unsigned i;
644 pp_string (buffer, "{ ");
645 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
647 pp_string (buffer, "D.");
648 pp_decimal_int (buffer, i);
649 pp_space (buffer);
651 pp_right_brace (buffer);
652 if (pt->vars_contains_nonlocal
653 && pt->vars_contains_escaped_heap)
654 pp_string (buffer, " (nonlocal, escaped heap)");
655 else if (pt->vars_contains_nonlocal
656 && pt->vars_contains_escaped)
657 pp_string (buffer, " (nonlocal, escaped)");
658 else if (pt->vars_contains_nonlocal)
659 pp_string (buffer, " (nonlocal)");
660 else if (pt->vars_contains_escaped_heap)
661 pp_string (buffer, " (escaped heap)");
662 else if (pt->vars_contains_escaped)
663 pp_string (buffer, " (escaped)");
667 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
668 pp_gimple_stmt_1. */
670 static void
671 dump_gimple_call (pretty_printer *buffer, gcall *gs, int spc, int flags)
673 tree lhs = gimple_call_lhs (gs);
674 tree fn = gimple_call_fn (gs);
676 if (flags & TDF_ALIAS)
678 struct pt_solution *pt;
679 pt = gimple_call_use_set (gs);
680 if (!pt_solution_empty_p (pt))
682 pp_string (buffer, "# USE = ");
683 pp_points_to_solution (buffer, pt);
684 newline_and_indent (buffer, spc);
686 pt = gimple_call_clobber_set (gs);
687 if (!pt_solution_empty_p (pt))
689 pp_string (buffer, "# CLB = ");
690 pp_points_to_solution (buffer, pt);
691 newline_and_indent (buffer, spc);
695 if (flags & TDF_RAW)
697 if (gimple_call_internal_p (gs))
698 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T", gs,
699 internal_fn_name (gimple_call_internal_fn (gs)), lhs);
700 else
701 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T", gs, fn, lhs);
702 if (gimple_call_num_args (gs) > 0)
704 pp_string (buffer, ", ");
705 dump_gimple_call_args (buffer, gs, flags);
707 pp_greater (buffer);
709 else
711 if (lhs && !(flags & TDF_RHS_ONLY))
713 dump_generic_node (buffer, lhs, spc, flags, false);
714 pp_string (buffer, " =");
716 if (gimple_has_volatile_ops (gs))
717 pp_string (buffer, "{v}");
719 pp_space (buffer);
721 if (gimple_call_internal_p (gs))
722 pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
723 else
724 print_call_name (buffer, fn, flags);
725 pp_string (buffer, " (");
726 dump_gimple_call_args (buffer, gs, flags);
727 pp_right_paren (buffer);
728 if (!(flags & TDF_RHS_ONLY))
729 pp_semicolon (buffer);
732 if (gimple_call_chain (gs))
734 pp_string (buffer, " [static-chain: ");
735 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
736 pp_right_bracket (buffer);
739 if (gimple_call_return_slot_opt_p (gs))
740 pp_string (buffer, " [return slot optimization]");
741 if (gimple_call_tail_p (gs))
742 pp_string (buffer, " [tail call]");
744 if (fn == NULL)
745 return;
747 /* Dump the arguments of _ITM_beginTransaction sanely. */
748 if (TREE_CODE (fn) == ADDR_EXPR)
749 fn = TREE_OPERAND (fn, 0);
750 if (TREE_CODE (fn) == FUNCTION_DECL && decl_is_tm_clone (fn))
751 pp_string (buffer, " [tm-clone]");
752 if (TREE_CODE (fn) == FUNCTION_DECL
753 && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
754 && DECL_FUNCTION_CODE (fn) == BUILT_IN_TM_START
755 && gimple_call_num_args (gs) > 0)
757 tree t = gimple_call_arg (gs, 0);
758 unsigned HOST_WIDE_INT props;
759 gcc_assert (TREE_CODE (t) == INTEGER_CST);
761 pp_string (buffer, " [ ");
763 /* Get the transaction code properties. */
764 props = TREE_INT_CST_LOW (t);
766 if (props & PR_INSTRUMENTEDCODE)
767 pp_string (buffer, "instrumentedCode ");
768 if (props & PR_UNINSTRUMENTEDCODE)
769 pp_string (buffer, "uninstrumentedCode ");
770 if (props & PR_HASNOXMMUPDATE)
771 pp_string (buffer, "hasNoXMMUpdate ");
772 if (props & PR_HASNOABORT)
773 pp_string (buffer, "hasNoAbort ");
774 if (props & PR_HASNOIRREVOCABLE)
775 pp_string (buffer, "hasNoIrrevocable ");
776 if (props & PR_DOESGOIRREVOCABLE)
777 pp_string (buffer, "doesGoIrrevocable ");
778 if (props & PR_HASNOSIMPLEREADS)
779 pp_string (buffer, "hasNoSimpleReads ");
780 if (props & PR_AWBARRIERSOMITTED)
781 pp_string (buffer, "awBarriersOmitted ");
782 if (props & PR_RARBARRIERSOMITTED)
783 pp_string (buffer, "RaRBarriersOmitted ");
784 if (props & PR_UNDOLOGCODE)
785 pp_string (buffer, "undoLogCode ");
786 if (props & PR_PREFERUNINSTRUMENTED)
787 pp_string (buffer, "preferUninstrumented ");
788 if (props & PR_EXCEPTIONBLOCK)
789 pp_string (buffer, "exceptionBlock ");
790 if (props & PR_HASELSE)
791 pp_string (buffer, "hasElse ");
792 if (props & PR_READONLY)
793 pp_string (buffer, "readOnly ");
795 pp_right_bracket (buffer);
800 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
801 pp_gimple_stmt_1. */
803 static void
804 dump_gimple_switch (pretty_printer *buffer, gswitch *gs, int spc,
805 int flags)
807 unsigned int i;
809 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
810 if (flags & TDF_RAW)
811 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
812 gimple_switch_index (gs));
813 else
815 pp_string (buffer, "switch (");
816 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
817 pp_string (buffer, ") <");
820 for (i = 0; i < gimple_switch_num_labels (gs); i++)
822 tree case_label = gimple_switch_label (gs, i);
823 gcc_checking_assert (case_label != NULL_TREE);
824 dump_generic_node (buffer, case_label, spc, flags, false);
825 pp_space (buffer);
826 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
827 if (i < gimple_switch_num_labels (gs) - 1)
828 pp_string (buffer, ", ");
830 pp_greater (buffer);
834 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
835 pp_gimple_stmt_1. */
837 static void
838 dump_gimple_cond (pretty_printer *buffer, gcond *gs, int spc, int flags)
840 if (flags & TDF_RAW)
841 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
842 get_tree_code_name (gimple_cond_code (gs)),
843 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
844 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
845 else
847 if (!(flags & TDF_RHS_ONLY))
848 pp_string (buffer, "if (");
849 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
850 pp_space (buffer);
851 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
852 pp_space (buffer);
853 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
854 if (!(flags & TDF_RHS_ONLY))
856 pp_right_paren (buffer);
858 if (gimple_cond_true_label (gs))
860 pp_string (buffer, " goto ");
861 dump_generic_node (buffer, gimple_cond_true_label (gs),
862 spc, flags, false);
863 pp_semicolon (buffer);
865 if (gimple_cond_false_label (gs))
867 pp_string (buffer, " else goto ");
868 dump_generic_node (buffer, gimple_cond_false_label (gs),
869 spc, flags, false);
870 pp_semicolon (buffer);
877 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
878 spaces of indent. FLAGS specifies details to show in the dump (see
879 TDF_* in dumpfils.h). */
881 static void
882 dump_gimple_label (pretty_printer *buffer, glabel *gs, int spc, int flags)
884 tree label = gimple_label_label (gs);
885 if (flags & TDF_RAW)
886 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
887 else
889 dump_generic_node (buffer, label, spc, flags, false);
890 pp_colon (buffer);
892 if (DECL_NONLOCAL (label))
893 pp_string (buffer, " [non-local]");
894 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
895 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
898 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
899 spaces of indent. FLAGS specifies details to show in the dump (see
900 TDF_* in dumpfile.h). */
902 static void
903 dump_gimple_goto (pretty_printer *buffer, ggoto *gs, int spc, int flags)
905 tree label = gimple_goto_dest (gs);
906 if (flags & TDF_RAW)
907 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
908 else
909 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
913 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
914 spaces of indent. FLAGS specifies details to show in the dump (see
915 TDF_* in dumpfile.h). */
917 static void
918 dump_gimple_bind (pretty_printer *buffer, gbind *gs, int spc, int flags)
920 if (flags & TDF_RAW)
921 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
922 else
923 pp_left_brace (buffer);
924 if (!(flags & TDF_SLIM))
926 tree var;
928 for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
930 newline_and_indent (buffer, 2);
931 print_declaration (buffer, var, spc, flags);
933 if (gimple_bind_vars (gs))
934 pp_newline (buffer);
936 pp_newline (buffer);
937 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
938 newline_and_indent (buffer, spc);
939 if (flags & TDF_RAW)
940 pp_greater (buffer);
941 else
942 pp_right_brace (buffer);
946 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
947 indent. FLAGS specifies details to show in the dump (see TDF_* in
948 dumpfile.h). */
950 static void
951 dump_gimple_try (pretty_printer *buffer, gtry *gs, int spc, int flags)
953 if (flags & TDF_RAW)
955 const char *type;
956 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
957 type = "GIMPLE_TRY_CATCH";
958 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
959 type = "GIMPLE_TRY_FINALLY";
960 else
961 type = "UNKNOWN GIMPLE_TRY";
962 dump_gimple_fmt (buffer, spc, flags,
963 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
964 gimple_try_eval (gs), gimple_try_cleanup (gs));
966 else
968 pp_string (buffer, "try");
969 newline_and_indent (buffer, spc + 2);
970 pp_left_brace (buffer);
971 pp_newline (buffer);
973 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
974 newline_and_indent (buffer, spc + 2);
975 pp_right_brace (buffer);
977 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
979 newline_and_indent (buffer, spc);
980 pp_string (buffer, "catch");
981 newline_and_indent (buffer, spc + 2);
982 pp_left_brace (buffer);
984 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
986 newline_and_indent (buffer, spc);
987 pp_string (buffer, "finally");
988 newline_and_indent (buffer, spc + 2);
989 pp_left_brace (buffer);
991 else
992 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
994 pp_newline (buffer);
995 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
996 newline_and_indent (buffer, spc + 2);
997 pp_right_brace (buffer);
1002 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
1003 indent. FLAGS specifies details to show in the dump (see TDF_* in
1004 dumpfile.h). */
1006 static void
1007 dump_gimple_catch (pretty_printer *buffer, gcatch *gs, int spc, int flags)
1009 if (flags & TDF_RAW)
1010 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
1011 gimple_catch_types (gs), gimple_catch_handler (gs));
1012 else
1013 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
1014 gimple_catch_types (gs), gimple_catch_handler (gs));
1018 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
1019 indent. FLAGS specifies details to show in the dump (see TDF_* in
1020 dumpfile.h). */
1022 static void
1023 dump_gimple_eh_filter (pretty_printer *buffer, geh_filter *gs, int spc,
1024 int flags)
1026 if (flags & TDF_RAW)
1027 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
1028 gimple_eh_filter_types (gs),
1029 gimple_eh_filter_failure (gs));
1030 else
1031 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
1032 gimple_eh_filter_types (gs),
1033 gimple_eh_filter_failure (gs));
1037 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
1039 static void
1040 dump_gimple_eh_must_not_throw (pretty_printer *buffer,
1041 geh_mnt *gs, int spc, int flags)
1043 if (flags & TDF_RAW)
1044 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1045 gimple_eh_must_not_throw_fndecl (gs));
1046 else
1047 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
1048 gimple_eh_must_not_throw_fndecl (gs));
1052 /* Dump a GIMPLE_EH_ELSE tuple on the pretty_printer BUFFER, SPC spaces of
1053 indent. FLAGS specifies details to show in the dump (see TDF_* in
1054 dumpfile.h). */
1056 static void
1057 dump_gimple_eh_else (pretty_printer *buffer, geh_else *gs, int spc,
1058 int flags)
1060 if (flags & TDF_RAW)
1061 dump_gimple_fmt (buffer, spc, flags,
1062 "%G <%+N_BODY <%S>%nE_BODY <%S>%->", gs,
1063 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1064 else
1065 dump_gimple_fmt (buffer, spc, flags,
1066 "<<<if_normal_exit>>>%+{%S}%-<<<else_eh_exit>>>%+{%S}",
1067 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1071 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
1072 indent. FLAGS specifies details to show in the dump (see TDF_* in
1073 dumpfile.h). */
1075 static void
1076 dump_gimple_resx (pretty_printer *buffer, gresx *gs, int spc, int flags)
1078 if (flags & TDF_RAW)
1079 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1080 gimple_resx_region (gs));
1081 else
1082 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
1085 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
1087 static void
1088 dump_gimple_eh_dispatch (pretty_printer *buffer, geh_dispatch *gs, int spc, int flags)
1090 if (flags & TDF_RAW)
1091 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1092 gimple_eh_dispatch_region (gs));
1093 else
1094 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
1095 gimple_eh_dispatch_region (gs));
1098 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
1099 of indent. FLAGS specifies details to show in the dump (see TDF_*
1100 in dumpfile.h). */
1102 static void
1103 dump_gimple_debug (pretty_printer *buffer, gdebug *gs, int spc, int flags)
1105 switch (gs->subcode)
1107 case GIMPLE_DEBUG_BIND:
1108 if (flags & TDF_RAW)
1109 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
1110 gimple_debug_bind_get_var (gs),
1111 gimple_debug_bind_get_value (gs));
1112 else
1113 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
1114 gimple_debug_bind_get_var (gs),
1115 gimple_debug_bind_get_value (gs));
1116 break;
1118 case GIMPLE_DEBUG_SOURCE_BIND:
1119 if (flags & TDF_RAW)
1120 dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1121 gimple_debug_source_bind_get_var (gs),
1122 gimple_debug_source_bind_get_value (gs));
1123 else
1124 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1125 gimple_debug_source_bind_get_var (gs),
1126 gimple_debug_source_bind_get_value (gs));
1127 break;
1129 default:
1130 gcc_unreachable ();
1134 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
1135 static void
1136 dump_gimple_omp_for (pretty_printer *buffer, gomp_for *gs, int spc, int flags)
1138 size_t i;
1140 if (flags & TDF_RAW)
1142 const char *kind;
1143 switch (gimple_omp_for_kind (gs))
1145 case GF_OMP_FOR_KIND_FOR:
1146 kind = "";
1147 break;
1148 case GF_OMP_FOR_KIND_SIMD:
1149 kind = " simd";
1150 break;
1151 case GF_OMP_FOR_KIND_CILKSIMD:
1152 kind = " cilksimd";
1153 break;
1154 case GF_OMP_FOR_KIND_DISTRIBUTE:
1155 kind = " distribute";
1156 break;
1157 case GF_OMP_FOR_KIND_CILKFOR:
1158 kind = " _Cilk_for";
1159 break;
1160 default:
1161 gcc_unreachable ();
1163 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1164 kind, gimple_omp_body (gs));
1165 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1166 dump_gimple_fmt (buffer, spc, flags, " >,");
1167 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1168 dump_gimple_fmt (buffer, spc, flags,
1169 "%+%T, %T, %T, %s, %T,%n",
1170 gimple_omp_for_index (gs, i),
1171 gimple_omp_for_initial (gs, i),
1172 gimple_omp_for_final (gs, i),
1173 get_tree_code_name (gimple_omp_for_cond (gs, i)),
1174 gimple_omp_for_incr (gs, i));
1175 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1176 gimple_omp_for_pre_body (gs));
1178 else
1180 switch (gimple_omp_for_kind (gs))
1182 case GF_OMP_FOR_KIND_FOR:
1183 pp_string (buffer, "#pragma omp for");
1184 break;
1185 case GF_OMP_FOR_KIND_SIMD:
1186 pp_string (buffer, "#pragma omp simd");
1187 break;
1188 case GF_OMP_FOR_KIND_CILKSIMD:
1189 pp_string (buffer, "#pragma simd");
1190 break;
1191 case GF_OMP_FOR_KIND_DISTRIBUTE:
1192 pp_string (buffer, "#pragma omp distribute");
1193 break;
1194 case GF_OMP_FOR_KIND_CILKFOR:
1195 break;
1196 default:
1197 gcc_unreachable ();
1199 if (gimple_omp_for_kind (gs) != GF_OMP_FOR_KIND_CILKFOR)
1200 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1201 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1203 if (i)
1204 spc += 2;
1205 if (gimple_omp_for_kind (gs) == GF_OMP_FOR_KIND_CILKFOR)
1206 pp_string (buffer, "_Cilk_for (");
1207 else
1209 newline_and_indent (buffer, spc);
1210 pp_string (buffer, "for (");
1212 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1213 flags, false);
1214 pp_string (buffer, " = ");
1215 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1216 flags, false);
1217 pp_string (buffer, "; ");
1219 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1220 flags, false);
1221 pp_space (buffer);
1222 switch (gimple_omp_for_cond (gs, i))
1224 case LT_EXPR:
1225 pp_less (buffer);
1226 break;
1227 case GT_EXPR:
1228 pp_greater (buffer);
1229 break;
1230 case LE_EXPR:
1231 pp_less_equal (buffer);
1232 break;
1233 case GE_EXPR:
1234 pp_greater_equal (buffer);
1235 break;
1236 case NE_EXPR:
1237 pp_string (buffer, "!=");
1238 break;
1239 default:
1240 gcc_unreachable ();
1242 pp_space (buffer);
1243 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1244 flags, false);
1245 pp_string (buffer, "; ");
1247 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1248 flags, false);
1249 pp_string (buffer, " = ");
1250 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1251 flags, false);
1252 pp_right_paren (buffer);
1255 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1257 if (gimple_omp_for_kind (gs) == GF_OMP_FOR_KIND_CILKFOR)
1258 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1259 newline_and_indent (buffer, spc + 2);
1260 pp_left_brace (buffer);
1261 pp_newline (buffer);
1262 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1263 newline_and_indent (buffer, spc + 2);
1264 pp_right_brace (buffer);
1269 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
1271 static void
1272 dump_gimple_omp_continue (pretty_printer *buffer, gomp_continue *gs,
1273 int spc, int flags)
1275 if (flags & TDF_RAW)
1277 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1278 gimple_omp_continue_control_def (gs),
1279 gimple_omp_continue_control_use (gs));
1281 else
1283 pp_string (buffer, "#pragma omp continue (");
1284 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1285 spc, flags, false);
1286 pp_comma (buffer);
1287 pp_space (buffer);
1288 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1289 spc, flags, false);
1290 pp_right_paren (buffer);
1294 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1296 static void
1297 dump_gimple_omp_single (pretty_printer *buffer, gomp_single *gs,
1298 int spc, int flags)
1300 if (flags & TDF_RAW)
1302 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1303 gimple_omp_body (gs));
1304 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1305 dump_gimple_fmt (buffer, spc, flags, " >");
1307 else
1309 pp_string (buffer, "#pragma omp single");
1310 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1311 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1313 newline_and_indent (buffer, spc + 2);
1314 pp_left_brace (buffer);
1315 pp_newline (buffer);
1316 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1317 newline_and_indent (buffer, spc + 2);
1318 pp_right_brace (buffer);
1323 /* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer BUFFER. */
1325 static void
1326 dump_gimple_omp_target (pretty_printer *buffer, gomp_target *gs,
1327 int spc, int flags)
1329 const char *kind;
1330 switch (gimple_omp_target_kind (gs))
1332 case GF_OMP_TARGET_KIND_REGION:
1333 kind = "";
1334 break;
1335 case GF_OMP_TARGET_KIND_DATA:
1336 kind = " data";
1337 break;
1338 case GF_OMP_TARGET_KIND_UPDATE:
1339 kind = " update";
1340 break;
1341 default:
1342 gcc_unreachable ();
1344 if (flags & TDF_RAW)
1346 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1347 kind, gimple_omp_body (gs));
1348 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1349 dump_gimple_fmt (buffer, spc, flags, " >");
1351 else
1353 pp_string (buffer, "#pragma omp target");
1354 pp_string (buffer, kind);
1355 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1356 if (gimple_omp_target_child_fn (gs))
1358 pp_string (buffer, " [child fn: ");
1359 dump_generic_node (buffer, gimple_omp_target_child_fn (gs),
1360 spc, flags, false);
1361 pp_right_bracket (buffer);
1363 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1365 newline_and_indent (buffer, spc + 2);
1366 pp_character (buffer, '{');
1367 pp_newline (buffer);
1368 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1369 newline_and_indent (buffer, spc + 2);
1370 pp_character (buffer, '}');
1375 /* Dump a GIMPLE_OMP_TEAMS tuple on the pretty_printer BUFFER. */
1377 static void
1378 dump_gimple_omp_teams (pretty_printer *buffer, gomp_teams *gs, int spc,
1379 int flags)
1381 if (flags & TDF_RAW)
1383 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1384 gimple_omp_body (gs));
1385 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1386 dump_gimple_fmt (buffer, spc, flags, " >");
1388 else
1390 pp_string (buffer, "#pragma omp teams");
1391 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1392 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1394 newline_and_indent (buffer, spc + 2);
1395 pp_character (buffer, '{');
1396 pp_newline (buffer);
1397 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1398 newline_and_indent (buffer, spc + 2);
1399 pp_character (buffer, '}');
1404 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1406 static void
1407 dump_gimple_omp_sections (pretty_printer *buffer, gomp_sections *gs,
1408 int spc, int flags)
1410 if (flags & TDF_RAW)
1412 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1413 gimple_omp_body (gs));
1414 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1415 dump_gimple_fmt (buffer, spc, flags, " >");
1417 else
1419 pp_string (buffer, "#pragma omp sections");
1420 if (gimple_omp_sections_control (gs))
1422 pp_string (buffer, " <");
1423 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1424 flags, false);
1425 pp_greater (buffer);
1427 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1428 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1430 newline_and_indent (buffer, spc + 2);
1431 pp_left_brace (buffer);
1432 pp_newline (buffer);
1433 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1434 newline_and_indent (buffer, spc + 2);
1435 pp_right_brace (buffer);
1440 /* Dump a GIMPLE_OMP_{MASTER,TASKGROUP,ORDERED,SECTION} tuple on the
1441 pretty_printer BUFFER. */
1443 static void
1444 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
1446 if (flags & TDF_RAW)
1447 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1448 gimple_omp_body (gs));
1449 else
1451 switch (gimple_code (gs))
1453 case GIMPLE_OMP_MASTER:
1454 pp_string (buffer, "#pragma omp master");
1455 break;
1456 case GIMPLE_OMP_TASKGROUP:
1457 pp_string (buffer, "#pragma omp taskgroup");
1458 break;
1459 case GIMPLE_OMP_ORDERED:
1460 pp_string (buffer, "#pragma omp ordered");
1461 break;
1462 case GIMPLE_OMP_SECTION:
1463 pp_string (buffer, "#pragma omp section");
1464 break;
1465 default:
1466 gcc_unreachable ();
1468 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1470 newline_and_indent (buffer, spc + 2);
1471 pp_left_brace (buffer);
1472 pp_newline (buffer);
1473 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1474 newline_and_indent (buffer, spc + 2);
1475 pp_right_brace (buffer);
1480 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1482 static void
1483 dump_gimple_omp_critical (pretty_printer *buffer, gomp_critical *gs,
1484 int spc, int flags)
1486 if (flags & TDF_RAW)
1487 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1488 gimple_omp_body (gs));
1489 else
1491 pp_string (buffer, "#pragma omp critical");
1492 if (gimple_omp_critical_name (gs))
1494 pp_string (buffer, " (");
1495 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1496 flags, false);
1497 pp_right_paren (buffer);
1499 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1501 newline_and_indent (buffer, spc + 2);
1502 pp_left_brace (buffer);
1503 pp_newline (buffer);
1504 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1505 newline_and_indent (buffer, spc + 2);
1506 pp_right_brace (buffer);
1511 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1513 static void
1514 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1516 if (flags & TDF_RAW)
1518 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d", gs,
1519 (int) gimple_omp_return_nowait_p (gs));
1520 if (gimple_omp_return_lhs (gs))
1521 dump_gimple_fmt (buffer, spc, flags, ", lhs=%T>",
1522 gimple_omp_return_lhs (gs));
1523 else
1524 dump_gimple_fmt (buffer, spc, flags, ">");
1526 else
1528 pp_string (buffer, "#pragma omp return");
1529 if (gimple_omp_return_nowait_p (gs))
1530 pp_string (buffer, "(nowait)");
1531 if (gimple_omp_return_lhs (gs))
1533 pp_string (buffer, " (set ");
1534 dump_generic_node (buffer, gimple_omp_return_lhs (gs),
1535 spc, flags, false);
1536 pp_character (buffer, ')');
1541 /* Dump a GIMPLE_TRANSACTION tuple on the pretty_printer BUFFER. */
1543 static void
1544 dump_gimple_transaction (pretty_printer *buffer, gtransaction *gs,
1545 int spc, int flags)
1547 unsigned subcode = gimple_transaction_subcode (gs);
1549 if (flags & TDF_RAW)
1551 dump_gimple_fmt (buffer, spc, flags,
1552 "%G [SUBCODE=%x,LABEL=%T] <%+BODY <%S> >",
1553 gs, subcode, gimple_transaction_label (gs),
1554 gimple_transaction_body (gs));
1556 else
1558 if (subcode & GTMA_IS_OUTER)
1559 pp_string (buffer, "__transaction_atomic [[outer]]");
1560 else if (subcode & GTMA_IS_RELAXED)
1561 pp_string (buffer, "__transaction_relaxed");
1562 else
1563 pp_string (buffer, "__transaction_atomic");
1564 subcode &= ~GTMA_DECLARATION_MASK;
1566 if (subcode || gimple_transaction_label (gs))
1568 pp_string (buffer, " //");
1569 if (gimple_transaction_label (gs))
1571 pp_string (buffer, " LABEL=");
1572 dump_generic_node (buffer, gimple_transaction_label (gs),
1573 spc, flags, false);
1575 if (subcode)
1577 pp_string (buffer, " SUBCODE=[ ");
1578 if (subcode & GTMA_HAVE_ABORT)
1580 pp_string (buffer, "GTMA_HAVE_ABORT ");
1581 subcode &= ~GTMA_HAVE_ABORT;
1583 if (subcode & GTMA_HAVE_LOAD)
1585 pp_string (buffer, "GTMA_HAVE_LOAD ");
1586 subcode &= ~GTMA_HAVE_LOAD;
1588 if (subcode & GTMA_HAVE_STORE)
1590 pp_string (buffer, "GTMA_HAVE_STORE ");
1591 subcode &= ~GTMA_HAVE_STORE;
1593 if (subcode & GTMA_MAY_ENTER_IRREVOCABLE)
1595 pp_string (buffer, "GTMA_MAY_ENTER_IRREVOCABLE ");
1596 subcode &= ~GTMA_MAY_ENTER_IRREVOCABLE;
1598 if (subcode & GTMA_DOES_GO_IRREVOCABLE)
1600 pp_string (buffer, "GTMA_DOES_GO_IRREVOCABLE ");
1601 subcode &= ~GTMA_DOES_GO_IRREVOCABLE;
1603 if (subcode & GTMA_HAS_NO_INSTRUMENTATION)
1605 pp_string (buffer, "GTMA_HAS_NO_INSTRUMENTATION ");
1606 subcode &= ~GTMA_HAS_NO_INSTRUMENTATION;
1608 if (subcode)
1609 pp_printf (buffer, "0x%x ", subcode);
1610 pp_right_bracket (buffer);
1614 if (!gimple_seq_empty_p (gimple_transaction_body (gs)))
1616 newline_and_indent (buffer, spc + 2);
1617 pp_left_brace (buffer);
1618 pp_newline (buffer);
1619 dump_gimple_seq (buffer, gimple_transaction_body (gs),
1620 spc + 4, flags);
1621 newline_and_indent (buffer, spc + 2);
1622 pp_right_brace (buffer);
1627 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1628 indent. FLAGS specifies details to show in the dump (see TDF_* in
1629 dumpfile.h). */
1631 static void
1632 dump_gimple_asm (pretty_printer *buffer, gasm *gs, int spc, int flags)
1634 unsigned int i, n, f, fields;
1636 if (flags & TDF_RAW)
1638 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1639 gimple_asm_string (gs));
1641 n = gimple_asm_noutputs (gs);
1642 if (n)
1644 newline_and_indent (buffer, spc + 2);
1645 pp_string (buffer, "OUTPUT: ");
1646 for (i = 0; i < n; i++)
1648 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1649 spc, flags, false);
1650 if (i < n - 1)
1651 pp_string (buffer, ", ");
1655 n = gimple_asm_ninputs (gs);
1656 if (n)
1658 newline_and_indent (buffer, spc + 2);
1659 pp_string (buffer, "INPUT: ");
1660 for (i = 0; i < n; i++)
1662 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1663 spc, flags, false);
1664 if (i < n - 1)
1665 pp_string (buffer, ", ");
1669 n = gimple_asm_nclobbers (gs);
1670 if (n)
1672 newline_and_indent (buffer, spc + 2);
1673 pp_string (buffer, "CLOBBER: ");
1674 for (i = 0; i < n; i++)
1676 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1677 spc, flags, false);
1678 if (i < n - 1)
1679 pp_string (buffer, ", ");
1683 n = gimple_asm_nlabels (gs);
1684 if (n)
1686 newline_and_indent (buffer, spc + 2);
1687 pp_string (buffer, "LABEL: ");
1688 for (i = 0; i < n; i++)
1690 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1691 spc, flags, false);
1692 if (i < n - 1)
1693 pp_string (buffer, ", ");
1697 newline_and_indent (buffer, spc);
1698 pp_greater (buffer);
1700 else
1702 pp_string (buffer, "__asm__");
1703 if (gimple_asm_volatile_p (gs))
1704 pp_string (buffer, " __volatile__");
1705 if (gimple_asm_nlabels (gs))
1706 pp_string (buffer, " goto");
1707 pp_string (buffer, "(\"");
1708 pp_string (buffer, gimple_asm_string (gs));
1709 pp_string (buffer, "\"");
1711 if (gimple_asm_nlabels (gs))
1712 fields = 4;
1713 else if (gimple_asm_nclobbers (gs))
1714 fields = 3;
1715 else if (gimple_asm_ninputs (gs))
1716 fields = 2;
1717 else if (gimple_asm_noutputs (gs))
1718 fields = 1;
1719 else
1720 fields = 0;
1722 for (f = 0; f < fields; ++f)
1724 pp_string (buffer, " : ");
1726 switch (f)
1728 case 0:
1729 n = gimple_asm_noutputs (gs);
1730 for (i = 0; i < n; i++)
1732 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1733 spc, flags, false);
1734 if (i < n - 1)
1735 pp_string (buffer, ", ");
1737 break;
1739 case 1:
1740 n = gimple_asm_ninputs (gs);
1741 for (i = 0; i < n; i++)
1743 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1744 spc, flags, false);
1745 if (i < n - 1)
1746 pp_string (buffer, ", ");
1748 break;
1750 case 2:
1751 n = gimple_asm_nclobbers (gs);
1752 for (i = 0; i < n; i++)
1754 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1755 spc, flags, false);
1756 if (i < n - 1)
1757 pp_string (buffer, ", ");
1759 break;
1761 case 3:
1762 n = gimple_asm_nlabels (gs);
1763 for (i = 0; i < n; i++)
1765 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1766 spc, flags, false);
1767 if (i < n - 1)
1768 pp_string (buffer, ", ");
1770 break;
1772 default:
1773 gcc_unreachable ();
1777 pp_string (buffer, ");");
1781 /* Dump ptr_info and range_info for NODE on pretty_printer BUFFER with
1782 SPC spaces of indent. */
1784 static void
1785 dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
1787 if (TREE_CODE (node) != SSA_NAME)
1788 return;
1790 if (POINTER_TYPE_P (TREE_TYPE (node))
1791 && SSA_NAME_PTR_INFO (node))
1793 unsigned int align, misalign;
1794 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (node);
1795 pp_string (buffer, "# PT = ");
1796 pp_points_to_solution (buffer, &pi->pt);
1797 newline_and_indent (buffer, spc);
1798 if (get_ptr_info_alignment (pi, &align, &misalign))
1800 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u", align, misalign);
1801 newline_and_indent (buffer, spc);
1805 if (!POINTER_TYPE_P (TREE_TYPE (node))
1806 && SSA_NAME_RANGE_INFO (node))
1808 wide_int min, max, nonzero_bits;
1809 value_range_type range_type = get_range_info (node, &min, &max);
1811 if (range_type == VR_VARYING)
1812 pp_printf (buffer, "# RANGE VR_VARYING");
1813 else if (range_type == VR_RANGE || range_type == VR_ANTI_RANGE)
1815 pp_printf (buffer, "# RANGE ");
1816 pp_printf (buffer, "%s[", range_type == VR_RANGE ? "" : "~");
1817 pp_wide_int (buffer, min, TYPE_SIGN (TREE_TYPE (node)));
1818 pp_printf (buffer, ", ");
1819 pp_wide_int (buffer, max, TYPE_SIGN (TREE_TYPE (node)));
1820 pp_printf (buffer, "]");
1822 nonzero_bits = get_nonzero_bits (node);
1823 if (nonzero_bits != -1)
1825 pp_string (buffer, " NONZERO ");
1826 pp_wide_int (buffer, nonzero_bits, UNSIGNED);
1828 newline_and_indent (buffer, spc);
1833 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
1834 The caller is responsible for calling pp_flush on BUFFER to finalize
1835 pretty printer. If COMMENT is true, print this after #. */
1837 static void
1838 dump_gimple_phi (pretty_printer *buffer, gphi *phi, int spc, bool comment,
1839 int flags)
1841 size_t i;
1842 tree lhs = gimple_phi_result (phi);
1844 if (flags & TDF_ALIAS)
1845 dump_ssaname_info (buffer, lhs, spc);
1847 if (comment)
1848 pp_string (buffer, "# ");
1850 if (flags & TDF_RAW)
1851 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1852 gimple_phi_result (phi));
1853 else
1855 dump_generic_node (buffer, lhs, spc, flags, false);
1856 pp_string (buffer, " = PHI <");
1858 for (i = 0; i < gimple_phi_num_args (phi); i++)
1860 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1861 dump_location (buffer, gimple_phi_arg_location (phi, i));
1862 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1863 false);
1864 pp_left_paren (buffer);
1865 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1866 pp_right_paren (buffer);
1867 if (i < gimple_phi_num_args (phi) - 1)
1868 pp_string (buffer, ", ");
1870 pp_greater (buffer);
1874 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1875 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1876 dumpfile.h). */
1878 static void
1879 dump_gimple_omp_parallel (pretty_printer *buffer, gomp_parallel *gs,
1880 int spc, int flags)
1882 if (flags & TDF_RAW)
1884 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1885 gimple_omp_body (gs));
1886 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1887 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1888 gimple_omp_parallel_child_fn (gs),
1889 gimple_omp_parallel_data_arg (gs));
1891 else
1893 gimple_seq body;
1894 pp_string (buffer, "#pragma omp parallel");
1895 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1896 if (gimple_omp_parallel_child_fn (gs))
1898 pp_string (buffer, " [child fn: ");
1899 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1900 spc, flags, false);
1901 pp_string (buffer, " (");
1902 if (gimple_omp_parallel_data_arg (gs))
1903 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1904 spc, flags, false);
1905 else
1906 pp_string (buffer, "???");
1907 pp_string (buffer, ")]");
1909 body = gimple_omp_body (gs);
1910 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1912 newline_and_indent (buffer, spc + 2);
1913 pp_left_brace (buffer);
1914 pp_newline (buffer);
1915 dump_gimple_seq (buffer, body, spc + 4, flags);
1916 newline_and_indent (buffer, spc + 2);
1917 pp_right_brace (buffer);
1919 else if (body)
1921 pp_newline (buffer);
1922 dump_gimple_seq (buffer, body, spc + 2, flags);
1928 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1929 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1930 dumpfile.h). */
1932 static void
1933 dump_gimple_omp_task (pretty_printer *buffer, gomp_task *gs, int spc,
1934 int flags)
1936 if (flags & TDF_RAW)
1938 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1939 gimple_omp_body (gs));
1940 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1941 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1942 gimple_omp_task_child_fn (gs),
1943 gimple_omp_task_data_arg (gs),
1944 gimple_omp_task_copy_fn (gs),
1945 gimple_omp_task_arg_size (gs),
1946 gimple_omp_task_arg_size (gs));
1948 else
1950 gimple_seq body;
1951 pp_string (buffer, "#pragma omp task");
1952 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1953 if (gimple_omp_task_child_fn (gs))
1955 pp_string (buffer, " [child fn: ");
1956 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1957 spc, flags, false);
1958 pp_string (buffer, " (");
1959 if (gimple_omp_task_data_arg (gs))
1960 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1961 spc, flags, false);
1962 else
1963 pp_string (buffer, "???");
1964 pp_string (buffer, ")]");
1966 body = gimple_omp_body (gs);
1967 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1969 newline_and_indent (buffer, spc + 2);
1970 pp_left_brace (buffer);
1971 pp_newline (buffer);
1972 dump_gimple_seq (buffer, body, spc + 4, flags);
1973 newline_and_indent (buffer, spc + 2);
1974 pp_right_brace (buffer);
1976 else if (body)
1978 pp_newline (buffer);
1979 dump_gimple_seq (buffer, body, spc + 2, flags);
1985 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1986 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1987 in dumpfile.h). */
1989 static void
1990 dump_gimple_omp_atomic_load (pretty_printer *buffer, gomp_atomic_load *gs,
1991 int spc, int flags)
1993 if (flags & TDF_RAW)
1995 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1996 gimple_omp_atomic_load_lhs (gs),
1997 gimple_omp_atomic_load_rhs (gs));
1999 else
2001 pp_string (buffer, "#pragma omp atomic_load");
2002 if (gimple_omp_atomic_seq_cst_p (gs))
2003 pp_string (buffer, " seq_cst");
2004 if (gimple_omp_atomic_need_value_p (gs))
2005 pp_string (buffer, " [needed]");
2006 newline_and_indent (buffer, spc + 2);
2007 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
2008 spc, flags, false);
2009 pp_space (buffer);
2010 pp_equal (buffer);
2011 pp_space (buffer);
2012 pp_star (buffer);
2013 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
2014 spc, flags, false);
2018 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
2019 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2020 in dumpfile.h). */
2022 static void
2023 dump_gimple_omp_atomic_store (pretty_printer *buffer,
2024 gomp_atomic_store *gs, int spc, int flags)
2026 if (flags & TDF_RAW)
2028 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
2029 gimple_omp_atomic_store_val (gs));
2031 else
2033 pp_string (buffer, "#pragma omp atomic_store ");
2034 if (gimple_omp_atomic_seq_cst_p (gs))
2035 pp_string (buffer, "seq_cst ");
2036 if (gimple_omp_atomic_need_value_p (gs))
2037 pp_string (buffer, "[needed] ");
2038 pp_left_paren (buffer);
2039 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
2040 spc, flags, false);
2041 pp_right_paren (buffer);
2046 /* Dump all the memory operands for statement GS. BUFFER, SPC and
2047 FLAGS are as in pp_gimple_stmt_1. */
2049 static void
2050 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
2052 tree vdef = gimple_vdef (gs);
2053 tree vuse = gimple_vuse (gs);
2055 if (vdef != NULL_TREE)
2057 pp_string (buffer, "# ");
2058 dump_generic_node (buffer, vdef, spc + 2, flags, false);
2059 pp_string (buffer, " = VDEF <");
2060 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2061 pp_greater (buffer);
2062 newline_and_indent (buffer, spc);
2064 else if (vuse != NULL_TREE)
2066 pp_string (buffer, "# VUSE <");
2067 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2068 pp_greater (buffer);
2069 newline_and_indent (buffer, spc);
2074 /* Print the gimple statement GS on the pretty printer BUFFER, SPC
2075 spaces of indent. FLAGS specifies details to show in the dump (see
2076 TDF_* in dumpfile.h). The caller is responsible for calling
2077 pp_flush on BUFFER to finalize the pretty printer. */
2079 void
2080 pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags)
2082 if (!gs)
2083 return;
2085 if (flags & TDF_STMTADDR)
2086 pp_printf (buffer, "<&%p> ", (void *) gs);
2088 if ((flags & TDF_LINENO) && gimple_has_location (gs))
2089 dump_location (buffer, gimple_location (gs));
2091 if (flags & TDF_EH)
2093 int lp_nr = lookup_stmt_eh_lp (gs);
2094 if (lp_nr > 0)
2095 pp_printf (buffer, "[LP %d] ", lp_nr);
2096 else if (lp_nr < 0)
2097 pp_printf (buffer, "[MNT %d] ", -lp_nr);
2100 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
2101 && gimple_has_mem_ops (gs))
2102 dump_gimple_mem_ops (buffer, gs, spc, flags);
2104 if (gimple_has_lhs (gs)
2105 && (flags & TDF_ALIAS))
2106 dump_ssaname_info (buffer, gimple_get_lhs (gs), spc);
2108 switch (gimple_code (gs))
2110 case GIMPLE_ASM:
2111 dump_gimple_asm (buffer, as_a <gasm *> (gs), spc, flags);
2112 break;
2114 case GIMPLE_ASSIGN:
2115 dump_gimple_assign (buffer, as_a <gassign *> (gs), spc, flags);
2116 break;
2118 case GIMPLE_BIND:
2119 dump_gimple_bind (buffer, as_a <gbind *> (gs), spc, flags);
2120 break;
2122 case GIMPLE_CALL:
2123 dump_gimple_call (buffer, as_a <gcall *> (gs), spc, flags);
2124 break;
2126 case GIMPLE_COND:
2127 dump_gimple_cond (buffer, as_a <gcond *> (gs), spc, flags);
2128 break;
2130 case GIMPLE_LABEL:
2131 dump_gimple_label (buffer, as_a <glabel *> (gs), spc, flags);
2132 break;
2134 case GIMPLE_GOTO:
2135 dump_gimple_goto (buffer, as_a <ggoto *> (gs), spc, flags);
2136 break;
2138 case GIMPLE_NOP:
2139 pp_string (buffer, "GIMPLE_NOP");
2140 break;
2142 case GIMPLE_RETURN:
2143 dump_gimple_return (buffer, as_a <greturn *> (gs), spc, flags);
2144 break;
2146 case GIMPLE_SWITCH:
2147 dump_gimple_switch (buffer, as_a <gswitch *> (gs), spc, flags);
2148 break;
2150 case GIMPLE_TRY:
2151 dump_gimple_try (buffer, as_a <gtry *> (gs), spc, flags);
2152 break;
2154 case GIMPLE_PHI:
2155 dump_gimple_phi (buffer, as_a <gphi *> (gs), spc, false, flags);
2156 break;
2158 case GIMPLE_OMP_PARALLEL:
2159 dump_gimple_omp_parallel (buffer, as_a <gomp_parallel *> (gs), spc,
2160 flags);
2161 break;
2163 case GIMPLE_OMP_TASK:
2164 dump_gimple_omp_task (buffer, as_a <gomp_task *> (gs), spc, flags);
2165 break;
2167 case GIMPLE_OMP_ATOMIC_LOAD:
2168 dump_gimple_omp_atomic_load (buffer, as_a <gomp_atomic_load *> (gs),
2169 spc, flags);
2170 break;
2172 case GIMPLE_OMP_ATOMIC_STORE:
2173 dump_gimple_omp_atomic_store (buffer,
2174 as_a <gomp_atomic_store *> (gs),
2175 spc, flags);
2176 break;
2178 case GIMPLE_OMP_FOR:
2179 dump_gimple_omp_for (buffer, as_a <gomp_for *> (gs), spc, flags);
2180 break;
2182 case GIMPLE_OMP_CONTINUE:
2183 dump_gimple_omp_continue (buffer, as_a <gomp_continue *> (gs), spc,
2184 flags);
2185 break;
2187 case GIMPLE_OMP_SINGLE:
2188 dump_gimple_omp_single (buffer, as_a <gomp_single *> (gs), spc,
2189 flags);
2190 break;
2192 case GIMPLE_OMP_TARGET:
2193 dump_gimple_omp_target (buffer, as_a <gomp_target *> (gs), spc,
2194 flags);
2195 break;
2197 case GIMPLE_OMP_TEAMS:
2198 dump_gimple_omp_teams (buffer, as_a <gomp_teams *> (gs), spc,
2199 flags);
2200 break;
2202 case GIMPLE_OMP_RETURN:
2203 dump_gimple_omp_return (buffer, gs, spc, flags);
2204 break;
2206 case GIMPLE_OMP_SECTIONS:
2207 dump_gimple_omp_sections (buffer, as_a <gomp_sections *> (gs),
2208 spc, flags);
2209 break;
2211 case GIMPLE_OMP_SECTIONS_SWITCH:
2212 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
2213 break;
2215 case GIMPLE_OMP_MASTER:
2216 case GIMPLE_OMP_TASKGROUP:
2217 case GIMPLE_OMP_ORDERED:
2218 case GIMPLE_OMP_SECTION:
2219 dump_gimple_omp_block (buffer, gs, spc, flags);
2220 break;
2222 case GIMPLE_OMP_CRITICAL:
2223 dump_gimple_omp_critical (buffer, as_a <gomp_critical *> (gs), spc,
2224 flags);
2225 break;
2227 case GIMPLE_CATCH:
2228 dump_gimple_catch (buffer, as_a <gcatch *> (gs), spc, flags);
2229 break;
2231 case GIMPLE_EH_FILTER:
2232 dump_gimple_eh_filter (buffer, as_a <geh_filter *> (gs), spc, flags);
2233 break;
2235 case GIMPLE_EH_MUST_NOT_THROW:
2236 dump_gimple_eh_must_not_throw (buffer,
2237 as_a <geh_mnt *> (gs),
2238 spc, flags);
2239 break;
2241 case GIMPLE_EH_ELSE:
2242 dump_gimple_eh_else (buffer, as_a <geh_else *> (gs), spc, flags);
2243 break;
2245 case GIMPLE_RESX:
2246 dump_gimple_resx (buffer, as_a <gresx *> (gs), spc, flags);
2247 break;
2249 case GIMPLE_EH_DISPATCH:
2250 dump_gimple_eh_dispatch (buffer, as_a <geh_dispatch *> (gs), spc,
2251 flags);
2252 break;
2254 case GIMPLE_DEBUG:
2255 dump_gimple_debug (buffer, as_a <gdebug *> (gs), spc, flags);
2256 break;
2258 case GIMPLE_PREDICT:
2259 pp_string (buffer, "// predicted ");
2260 if (gimple_predict_outcome (gs))
2261 pp_string (buffer, "likely by ");
2262 else
2263 pp_string (buffer, "unlikely by ");
2264 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
2265 pp_string (buffer, " predictor.");
2266 break;
2268 case GIMPLE_TRANSACTION:
2269 dump_gimple_transaction (buffer, as_a <gtransaction *> (gs), spc,
2270 flags);
2271 break;
2273 default:
2274 GIMPLE_NIY;
2279 /* Dumps header of basic block BB to OUTF indented by INDENT
2280 spaces and details described by flags. */
2282 static void
2283 dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
2285 if (flags & TDF_BLOCKS)
2287 if (flags & TDF_LINENO)
2289 gimple_stmt_iterator gsi;
2291 if (flags & TDF_COMMENT)
2292 fputs (";; ", outf);
2294 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2295 if (!is_gimple_debug (gsi_stmt (gsi))
2296 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
2298 fprintf (outf, "%*sstarting at line %d",
2299 indent, "", get_lineno (gsi_stmt (gsi)));
2300 break;
2302 if (bb->discriminator)
2303 fprintf (outf, ", discriminator %i", bb->discriminator);
2304 fputc ('\n', outf);
2307 else
2309 gimple stmt = first_stmt (bb);
2310 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
2311 fprintf (outf, "%*s<bb %d>:\n", indent, "", bb->index);
2316 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2317 spaces. */
2319 static void
2320 dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
2321 basic_block bb ATTRIBUTE_UNUSED,
2322 int indent ATTRIBUTE_UNUSED,
2323 int flags ATTRIBUTE_UNUSED)
2325 /* There is currently no GIMPLE-specific basic block info to dump. */
2326 return;
2330 /* Dump PHI nodes of basic block BB to BUFFER with details described
2331 by FLAGS and indented by INDENT spaces. */
2333 static void
2334 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2336 gphi_iterator i;
2338 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2340 gphi *phi = i.phi ();
2341 if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2343 INDENT (indent);
2344 dump_gimple_phi (buffer, phi, indent, true, flags);
2345 pp_newline (buffer);
2351 /* Dump jump to basic block BB that is represented implicitly in the cfg
2352 to BUFFER. */
2354 static void
2355 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2357 gimple stmt;
2359 stmt = first_stmt (bb);
2361 pp_string (buffer, "goto <bb ");
2362 pp_decimal_int (buffer, bb->index);
2363 pp_greater (buffer);
2364 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
2366 pp_string (buffer, " (");
2367 dump_generic_node (buffer,
2368 gimple_label_label (as_a <glabel *> (stmt)),
2369 0, 0, false);
2370 pp_right_paren (buffer);
2371 pp_semicolon (buffer);
2373 else
2374 pp_semicolon (buffer);
2378 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2379 by INDENT spaces, with details given by FLAGS. */
2381 static void
2382 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2383 int flags)
2385 edge e;
2386 gimple stmt;
2388 stmt = last_stmt (bb);
2390 if (stmt && gimple_code (stmt) == GIMPLE_COND)
2392 edge true_edge, false_edge;
2394 /* When we are emitting the code or changing CFG, it is possible that
2395 the edges are not yet created. When we are using debug_bb in such
2396 a situation, we do not want it to crash. */
2397 if (EDGE_COUNT (bb->succs) != 2)
2398 return;
2399 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2401 INDENT (indent + 2);
2402 pp_cfg_jump (buffer, true_edge->dest);
2403 newline_and_indent (buffer, indent);
2404 pp_string (buffer, "else");
2405 newline_and_indent (buffer, indent + 2);
2406 pp_cfg_jump (buffer, false_edge->dest);
2407 pp_newline (buffer);
2408 return;
2411 /* If there is a fallthru edge, we may need to add an artificial
2412 goto to the dump. */
2413 e = find_fallthru_edge (bb->succs);
2415 if (e && e->dest != bb->next_bb)
2417 INDENT (indent);
2419 if ((flags & TDF_LINENO)
2420 && e->goto_locus != UNKNOWN_LOCATION)
2421 dump_location (buffer, e->goto_locus);
2423 pp_cfg_jump (buffer, e->dest);
2424 pp_newline (buffer);
2429 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2430 indented by INDENT spaces. */
2432 static void
2433 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2434 int flags)
2436 gimple_stmt_iterator gsi;
2437 gimple stmt;
2438 int label_indent = indent - 2;
2440 if (label_indent < 0)
2441 label_indent = 0;
2443 dump_phi_nodes (buffer, bb, indent, flags);
2445 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2447 int curr_indent;
2449 stmt = gsi_stmt (gsi);
2451 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2453 INDENT (curr_indent);
2454 pp_gimple_stmt_1 (buffer, stmt, curr_indent, flags);
2455 pp_newline_and_flush (buffer);
2456 gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl));
2457 dump_histograms_for_stmt (DECL_STRUCT_FUNCTION (current_function_decl),
2458 pp_buffer (buffer)->stream, stmt);
2461 dump_implicit_edges (buffer, bb, indent, flags);
2462 pp_flush (buffer);
2466 /* Dumps basic block BB to FILE with details described by FLAGS and
2467 indented by INDENT spaces. */
2469 void
2470 gimple_dump_bb (FILE *file, basic_block bb, int indent, int flags)
2472 dump_gimple_bb_header (file, bb, indent, flags);
2473 if (bb->index >= NUM_FIXED_BLOCKS)
2475 pretty_printer buffer;
2476 pp_needs_newline (&buffer) = true;
2477 buffer.buffer->stream = file;
2478 gimple_dump_bb_buff (&buffer, bb, indent, flags);
2480 dump_gimple_bb_footer (file, bb, indent, flags);
2483 /* Dumps basic block BB to pretty-printer PP with default dump flags and
2484 no indentation, for use as a label of a DOT graph record-node.
2485 ??? Should just use gimple_dump_bb_buff here, except that value profiling
2486 histogram dumping doesn't know about pretty-printers. */
2488 void
2489 gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
2491 pp_printf (pp, "<bb %d>:\n", bb->index);
2492 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2494 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2495 gsi_next (&gsi))
2497 gphi *phi = gsi.phi ();
2498 if (!virtual_operand_p (gimple_phi_result (phi))
2499 || (dump_flags & TDF_VOPS))
2501 pp_bar (pp);
2502 pp_write_text_to_stream (pp);
2503 pp_string (pp, "# ");
2504 pp_gimple_stmt_1 (pp, phi, 0, dump_flags);
2505 pp_newline (pp);
2506 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2510 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
2511 gsi_next (&gsi))
2513 gimple stmt = gsi_stmt (gsi);
2514 pp_bar (pp);
2515 pp_write_text_to_stream (pp);
2516 pp_gimple_stmt_1 (pp, stmt, 0, dump_flags);
2517 pp_newline (pp);
2518 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2520 dump_implicit_edges (pp, bb, 0, dump_flags);
2521 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);