rephrase text
[official-gcc.git] / gcc / gimple-pretty-print.c
blobc9a9242e3ca8934362cec2c164217d66421c4580
1 /* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
3 Free Software Foundation, Inc.
4 Contributed by Aldy Hernandez <aldyh@redhat.com> and
5 Diego Novillo <dnovillo@google.com>
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "diagnostic.h"
29 #include "real.h"
30 #include "hashtab.h"
31 #include "tree-flow.h"
32 #include "tree-pass.h"
33 #include "gimple.h"
34 #include "value-prof.h"
36 #define INDENT(SPACE) \
37 do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
39 static pretty_printer buffer;
40 static bool initialized = false;
42 #define GIMPLE_NIY do_niy (buffer,gs)
44 /* Try to print on BUFFER a default message for the unrecognized
45 gimple statement GS. */
47 static void
48 do_niy (pretty_printer *buffer, gimple gs)
50 pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
51 gimple_code_name[(int) gimple_code (gs)]);
55 /* Initialize the pretty printer on FILE if needed. */
57 static void
58 maybe_init_pretty_print (FILE *file)
60 if (!initialized)
62 pp_construct (&buffer, NULL, 0);
63 pp_needs_newline (&buffer) = true;
64 initialized = true;
67 buffer.buffer->stream = file;
71 /* Emit a newline and SPC indentantion spaces to BUFFER. */
73 static void
74 newline_and_indent (pretty_printer *buffer, int spc)
76 pp_newline (buffer);
77 INDENT (spc);
81 /* Print the GIMPLE statement GS on stderr. */
83 void
84 debug_gimple_stmt (gimple gs)
86 print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
87 fprintf (stderr, "\n");
91 /* Dump GIMPLE statement G to FILE using SPC indentantion spaces and
92 FLAGS as in dump_gimple_stmt. */
94 void
95 print_gimple_stmt (FILE *file, gimple g, int spc, int flags)
97 maybe_init_pretty_print (file);
98 dump_gimple_stmt (&buffer, g, spc, flags);
99 pp_flush (&buffer);
103 /* Dump GIMPLE statement G to FILE using SPC indentantion spaces and
104 FLAGS as in dump_gimple_stmt. Print only the right-hand side
105 of the statement. */
107 void
108 print_gimple_expr (FILE *file, gimple g, int spc, int flags)
110 flags |= TDF_RHS_ONLY;
111 maybe_init_pretty_print (file);
112 dump_gimple_stmt (&buffer, g, spc, flags);
116 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentantion
117 spaces and FLAGS as in dump_gimple_stmt. */
119 static void
120 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc, int flags)
122 gimple_stmt_iterator i;
124 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
126 gimple gs = gsi_stmt (i);
127 INDENT (spc);
128 dump_gimple_stmt (buffer, gs, spc, flags);
129 if (!gsi_one_before_end_p (i))
130 pp_newline (buffer);
135 /* Dump GIMPLE sequence SEQ to FILE using SPC indentantion spaces and
136 FLAGS as in dump_gimple_stmt. */
138 void
139 print_gimple_seq (FILE *file, gimple_seq seq, int spc, int flags)
141 maybe_init_pretty_print (file);
142 dump_gimple_seq (&buffer, seq, spc, flags);
143 pp_flush (&buffer);
147 /* Print the GIMPLE sequence SEQ on stderr. */
149 void
150 debug_gimple_seq (gimple_seq seq)
152 print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
156 /* A simple helper to pretty-print some of the gimple tuples in the printf
157 style. The format modifiers are preceeded by '%' and are:
158 'G' - outputs a string corresponding to the code of the given gimple,
159 'S' - outputs a gimple_seq with indent of spc + 2,
160 'T' - outputs the tree t,
161 'd' - outputs an int as a decimal,
162 's' - outputs a string,
163 'n' - outputs a newline,
164 '+' - increases indent by 2 then outputs a newline,
165 '-' - decreases indent by 2 then outputs a newline. */
167 static void
168 dump_gimple_fmt (pretty_printer *buffer, int spc, int flags,
169 const char *fmt, ...)
171 va_list args;
172 const char *c;
173 const char *tmp;
175 va_start (args, fmt);
176 for (c = fmt; *c; c++)
178 if (*c == '%')
180 gimple_seq seq;
181 tree t;
182 gimple g;
183 switch (*++c)
185 case 'G':
186 g = va_arg (args, gimple);
187 tmp = gimple_code_name[gimple_code (g)];
188 pp_string (buffer, tmp);
189 break;
191 case 'S':
192 seq = va_arg (args, gimple_seq);
193 pp_newline (buffer);
194 dump_gimple_seq (buffer, seq, spc + 2, flags);
195 newline_and_indent (buffer, spc);
196 break;
198 case 'T':
199 t = va_arg (args, tree);
200 if (t == NULL_TREE)
201 pp_string (buffer, "NULL");
202 else
203 dump_generic_node (buffer, t, spc, flags, false);
204 break;
206 case 'd':
207 pp_decimal_int (buffer, va_arg (args, int));
208 break;
210 case 's':
211 pp_string (buffer, va_arg (args, char *));
212 break;
214 case 'n':
215 newline_and_indent (buffer, spc);
216 break;
218 case '+':
219 spc += 2;
220 newline_and_indent (buffer, spc);
221 break;
223 case '-':
224 spc -= 2;
225 newline_and_indent (buffer, spc);
226 break;
228 default:
229 gcc_unreachable ();
232 else
233 pp_character (buffer, *c);
235 va_end (args);
239 /* Helper for dump_gimple_assign. Print the unary RHS of the
240 assignment GS. BUFFER, SPC and FLAGS are as in dump_gimple_stmt. */
242 static void
243 dump_unary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
245 enum tree_code rhs_code = gimple_assign_rhs_code (gs);
246 tree lhs = gimple_assign_lhs (gs);
247 tree rhs = gimple_assign_rhs1 (gs);
249 switch (rhs_code)
251 case VIEW_CONVERT_EXPR:
252 case ASSERT_EXPR:
253 dump_generic_node (buffer, rhs, spc, flags, false);
254 break;
256 case FIXED_CONVERT_EXPR:
257 case ADDR_SPACE_CONVERT_EXPR:
258 case FIX_TRUNC_EXPR:
259 case FLOAT_EXPR:
260 CASE_CONVERT:
261 pp_character (buffer, '(');
262 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
263 pp_string (buffer, ") ");
264 if (op_prio (rhs) < op_code_prio (rhs_code))
266 pp_character (buffer, '(');
267 dump_generic_node (buffer, rhs, spc, flags, false);
268 pp_character (buffer, ')');
270 else
271 dump_generic_node (buffer, rhs, spc, flags, false);
272 break;
274 case PAREN_EXPR:
275 pp_string (buffer, "((");
276 dump_generic_node (buffer, rhs, spc, flags, false);
277 pp_string (buffer, "))");
278 break;
280 case ABS_EXPR:
281 pp_string (buffer, "ABS_EXPR <");
282 dump_generic_node (buffer, rhs, spc, flags, false);
283 pp_character (buffer, '>');
284 break;
286 default:
287 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
288 || TREE_CODE_CLASS (rhs_code) == tcc_constant
289 || TREE_CODE_CLASS (rhs_code) == tcc_reference
290 || rhs_code == SSA_NAME
291 || rhs_code == ADDR_EXPR
292 || rhs_code == CONSTRUCTOR)
294 dump_generic_node (buffer, rhs, spc, flags, false);
295 break;
297 else if (rhs_code == BIT_NOT_EXPR)
298 pp_character (buffer, '~');
299 else if (rhs_code == TRUTH_NOT_EXPR)
300 pp_character (buffer, '!');
301 else if (rhs_code == NEGATE_EXPR)
302 pp_character (buffer, '-');
303 else
305 pp_character (buffer, '[');
306 pp_string (buffer, tree_code_name [rhs_code]);
307 pp_string (buffer, "] ");
310 if (op_prio (rhs) < op_code_prio (rhs_code))
312 pp_character (buffer, '(');
313 dump_generic_node (buffer, rhs, spc, flags, false);
314 pp_character (buffer, ')');
316 else
317 dump_generic_node (buffer, rhs, spc, flags, false);
318 break;
323 /* Helper for dump_gimple_assign. Print the binary RHS of the
324 assignment GS. BUFFER, SPC and FLAGS are as in dump_gimple_stmt. */
326 static void
327 dump_binary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
329 const char *p;
330 enum tree_code code = gimple_assign_rhs_code (gs);
331 switch (code)
333 case COMPLEX_EXPR:
334 case MIN_EXPR:
335 case MAX_EXPR:
336 case VEC_WIDEN_MULT_HI_EXPR:
337 case VEC_WIDEN_MULT_LO_EXPR:
338 case VEC_PACK_TRUNC_EXPR:
339 case VEC_PACK_SAT_EXPR:
340 case VEC_PACK_FIX_TRUNC_EXPR:
341 case VEC_EXTRACT_EVEN_EXPR:
342 case VEC_EXTRACT_ODD_EXPR:
343 case VEC_INTERLEAVE_HIGH_EXPR:
344 case VEC_INTERLEAVE_LOW_EXPR:
345 for (p = tree_code_name [(int) code]; *p; p++)
346 pp_character (buffer, TOUPPER (*p));
347 pp_string (buffer, " <");
348 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
349 pp_string (buffer, ", ");
350 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
351 pp_character (buffer, '>');
352 break;
354 default:
355 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
357 pp_character (buffer, '(');
358 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
359 false);
360 pp_character (buffer, ')');
362 else
363 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
364 pp_space (buffer);
365 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
366 pp_space (buffer);
367 if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
369 pp_character (buffer, '(');
370 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
371 false);
372 pp_character (buffer, ')');
374 else
375 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
380 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
381 dump_gimple_stmt. */
383 static void
384 dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
386 if (flags & TDF_RAW)
388 tree last;
389 if (gimple_num_ops (gs) == 2)
390 last = NULL_TREE;
391 else if (gimple_num_ops (gs) == 3)
392 last = gimple_assign_rhs2 (gs);
393 else
394 gcc_unreachable ();
396 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T>", gs,
397 tree_code_name[gimple_assign_rhs_code (gs)],
398 gimple_assign_lhs (gs), gimple_assign_rhs1 (gs), last);
400 else
402 if (!(flags & TDF_RHS_ONLY))
404 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
405 pp_space (buffer);
406 pp_character (buffer, '=');
408 if (gimple_assign_nontemporal_move_p (gs))
409 pp_string (buffer, "{nt}");
411 if (gimple_has_volatile_ops (gs))
412 pp_string (buffer, "{v}");
414 pp_space (buffer);
417 if (gimple_num_ops (gs) == 2)
418 dump_unary_rhs (buffer, gs, spc, flags);
419 else if (gimple_num_ops (gs) == 3)
420 dump_binary_rhs (buffer, gs, spc, flags);
421 else
422 gcc_unreachable ();
423 if (!(flags & TDF_RHS_ONLY))
424 pp_semicolon(buffer);
429 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
430 dump_gimple_stmt. */
432 static void
433 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
435 tree t;
437 t = gimple_return_retval (gs);
438 if (flags & TDF_RAW)
439 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
440 else
442 pp_string (buffer, "return");
443 if (t)
445 pp_space (buffer);
446 dump_generic_node (buffer, t, spc, flags, false);
448 pp_semicolon (buffer);
453 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
454 dump_gimple_call. */
456 static void
457 dump_gimple_call_args (pretty_printer *buffer, gimple gs, int flags)
459 size_t i;
461 for (i = 0; i < gimple_call_num_args (gs); i++)
463 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
464 if (i < gimple_call_num_args (gs) - 1)
465 pp_string (buffer, ", ");
468 if (gimple_call_va_arg_pack_p (gs))
470 if (gimple_call_num_args (gs) > 0)
472 pp_character (buffer, ',');
473 pp_space (buffer);
476 pp_string (buffer, "__builtin_va_arg_pack ()");
480 /* Dump the points-to solution *PT to BUFFER. */
482 static void
483 pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
485 if (pt->anything)
487 pp_string (buffer, "anything ");
488 return;
490 if (pt->nonlocal)
491 pp_string (buffer, "nonlocal ");
492 if (pt->escaped)
493 pp_string (buffer, "escaped ");
494 if (pt->ipa_escaped)
495 pp_string (buffer, "unit-escaped ");
496 if (pt->null)
497 pp_string (buffer, "null ");
498 if (pt->vars
499 && !bitmap_empty_p (pt->vars))
501 bitmap_iterator bi;
502 unsigned i;
503 pp_string (buffer, "{ ");
504 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
506 struct tree_decl_minimal in;
507 tree var;
508 in.uid = i;
509 var = (tree) htab_find_with_hash (gimple_referenced_vars (cfun),
510 &in, i);
511 if (var)
513 dump_generic_node (buffer, var, 0, dump_flags, false);
514 if (DECL_PT_UID (var) != DECL_UID (var))
516 pp_string (buffer, "ptD.");
517 pp_decimal_int (buffer, DECL_PT_UID (var));
520 else
522 pp_string (buffer, "D.");
523 pp_decimal_int (buffer, i);
525 pp_character (buffer, ' ');
527 pp_character (buffer, '}');
528 if (pt->vars_contains_global)
529 pp_string (buffer, " (glob)");
530 if (pt->vars_contains_restrict)
531 pp_string (buffer, " (restr)");
535 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
536 dump_gimple_stmt. */
538 static void
539 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
541 tree lhs = gimple_call_lhs (gs);
543 if (flags & TDF_ALIAS)
545 struct pt_solution *pt;
546 pt = gimple_call_use_set (gs);
547 if (!pt_solution_empty_p (pt))
549 pp_string (buffer, "# USE = ");
550 pp_points_to_solution (buffer, pt);
551 newline_and_indent (buffer, spc);
553 pt = gimple_call_clobber_set (gs);
554 if (!pt_solution_empty_p (pt))
556 pp_string (buffer, "# CLB = ");
557 pp_points_to_solution (buffer, pt);
558 newline_and_indent (buffer, spc);
562 if (flags & TDF_RAW)
564 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T",
565 gs, gimple_call_fn (gs), lhs);
566 if (gimple_call_num_args (gs) > 0)
568 pp_string (buffer, ", ");
569 dump_gimple_call_args (buffer, gs, flags);
571 pp_character (buffer, '>');
573 else
575 if (lhs && !(flags & TDF_RHS_ONLY))
577 dump_generic_node (buffer, lhs, spc, flags, false);
578 pp_string (buffer, " =");
580 if (gimple_has_volatile_ops (gs))
581 pp_string (buffer, "{v}");
583 pp_space (buffer);
585 print_call_name (buffer, gimple_call_fn (gs), flags);
586 pp_string (buffer, " (");
587 dump_gimple_call_args (buffer, gs, flags);
588 pp_character (buffer, ')');
589 if (!(flags & TDF_RHS_ONLY))
590 pp_semicolon (buffer);
593 if (gimple_call_chain (gs))
595 pp_string (buffer, " [static-chain: ");
596 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
597 pp_character (buffer, ']');
600 if (gimple_call_return_slot_opt_p (gs))
601 pp_string (buffer, " [return slot optimization]");
603 if (gimple_call_tail_p (gs))
604 pp_string (buffer, " [tail call]");
608 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
609 dump_gimple_stmt. */
611 static void
612 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
614 unsigned int i;
616 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
617 if (flags & TDF_RAW)
618 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
619 gimple_switch_index (gs));
620 else
622 pp_string (buffer, "switch (");
623 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
624 pp_string (buffer, ") <");
627 for (i = 0; i < gimple_switch_num_labels (gs); i++)
629 tree case_label = gimple_switch_label (gs, i);
630 if (case_label == NULL_TREE)
631 continue;
633 dump_generic_node (buffer, case_label, spc, flags, false);
634 pp_character (buffer, ' ');
635 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
636 if (i < gimple_switch_num_labels (gs) - 1)
637 pp_string (buffer, ", ");
639 pp_character (buffer, '>');
643 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
644 dump_gimple_stmt. */
646 static void
647 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
649 if (flags & TDF_RAW)
650 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
651 tree_code_name [gimple_cond_code (gs)],
652 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
653 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
654 else
656 if (!(flags & TDF_RHS_ONLY))
657 pp_string (buffer, "if (");
658 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
659 pp_space (buffer);
660 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
661 pp_space (buffer);
662 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
663 if (!(flags & TDF_RHS_ONLY))
665 pp_character (buffer, ')');
667 if (gimple_cond_true_label (gs))
669 pp_string (buffer, " goto ");
670 dump_generic_node (buffer, gimple_cond_true_label (gs),
671 spc, flags, false);
672 pp_semicolon (buffer);
674 if (gimple_cond_false_label (gs))
676 pp_string (buffer, " else goto ");
677 dump_generic_node (buffer, gimple_cond_false_label (gs),
678 spc, flags, false);
679 pp_semicolon (buffer);
686 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
687 spaces of indent. FLAGS specifies details to show in the dump (see
688 TDF_* in tree-pass.h). */
690 static void
691 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
693 tree label = gimple_label_label (gs);
694 if (flags & TDF_RAW)
695 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
696 else
698 dump_generic_node (buffer, label, spc, flags, false);
699 pp_character (buffer, ':');
701 if (DECL_NONLOCAL (label))
702 pp_string (buffer, " [non-local]");
703 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
704 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
707 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
708 spaces of indent. FLAGS specifies details to show in the dump (see
709 TDF_* in tree-pass.h). */
711 static void
712 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
714 tree label = gimple_goto_dest (gs);
715 if (flags & TDF_RAW)
716 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
717 else
718 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
722 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
723 spaces of indent. FLAGS specifies details to show in the dump (see
724 TDF_* in tree-pass.h). */
726 static void
727 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
729 if (flags & TDF_RAW)
730 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
731 else
732 pp_character (buffer, '{');
733 if (!(flags & TDF_SLIM))
735 tree var;
737 for (var = gimple_bind_vars (gs); var; var = TREE_CHAIN (var))
739 newline_and_indent (buffer, 2);
740 print_declaration (buffer, var, spc, flags);
742 if (gimple_bind_vars (gs))
743 pp_newline (buffer);
745 pp_newline (buffer);
746 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
747 newline_and_indent (buffer, spc);
748 if (flags & TDF_RAW)
749 pp_character (buffer, '>');
750 else
751 pp_character (buffer, '}');
755 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
756 indent. FLAGS specifies details to show in the dump (see TDF_* in
757 tree-pass.h). */
759 static void
760 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
762 if (flags & TDF_RAW)
764 const char *type;
765 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
766 type = "GIMPLE_TRY_CATCH";
767 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
768 type = "GIMPLE_TRY_FINALLY";
769 else
770 type = "UNKNOWN GIMPLE_TRY";
771 dump_gimple_fmt (buffer, spc, flags,
772 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
773 gimple_try_eval (gs), gimple_try_cleanup (gs));
775 else
777 pp_string (buffer, "try");
778 newline_and_indent (buffer, spc + 2);
779 pp_character (buffer, '{');
780 pp_newline (buffer);
782 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
783 newline_and_indent (buffer, spc + 2);
784 pp_character (buffer, '}');
786 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
788 newline_and_indent (buffer, spc);
789 pp_string (buffer, "catch");
790 newline_and_indent (buffer, spc + 2);
791 pp_character (buffer, '{');
793 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
795 newline_and_indent (buffer, spc);
796 pp_string (buffer, "finally");
797 newline_and_indent (buffer, spc + 2);
798 pp_character (buffer, '{');
800 else
801 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
803 pp_newline (buffer);
804 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
805 newline_and_indent (buffer, spc + 2);
806 pp_character (buffer, '}');
811 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
812 indent. FLAGS specifies details to show in the dump (see TDF_* in
813 tree-pass.h). */
815 static void
816 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
818 if (flags & TDF_RAW)
819 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
820 gimple_catch_types (gs), gimple_catch_handler (gs));
821 else
822 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
823 gimple_catch_types (gs), gimple_catch_handler (gs));
827 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
828 indent. FLAGS specifies details to show in the dump (see TDF_* in
829 tree-pass.h). */
831 static void
832 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
834 if (flags & TDF_RAW)
835 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
836 gimple_eh_filter_types (gs),
837 gimple_eh_filter_failure (gs));
838 else
839 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
840 gimple_eh_filter_types (gs),
841 gimple_eh_filter_failure (gs));
845 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
847 static void
848 dump_gimple_eh_must_not_throw (pretty_printer *buffer, gimple gs,
849 int spc, int flags)
851 if (flags & TDF_RAW)
852 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
853 gimple_eh_must_not_throw_fndecl (gs));
854 else
855 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
856 gimple_eh_must_not_throw_fndecl (gs));
860 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
861 indent. FLAGS specifies details to show in the dump (see TDF_* in
862 tree-pass.h). */
864 static void
865 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
867 if (flags & TDF_RAW)
868 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
869 gimple_resx_region (gs));
870 else
871 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
874 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
876 static void
877 dump_gimple_eh_dispatch (pretty_printer *buffer, gimple gs, int spc, int flags)
879 if (flags & TDF_RAW)
880 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
881 gimple_eh_dispatch_region (gs));
882 else
883 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
884 gimple_eh_dispatch_region (gs));
887 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
888 of indent. FLAGS specifies details to show in the dump (see TDF_*
889 in tree-pass.h). */
891 static void
892 dump_gimple_debug (pretty_printer *buffer, gimple gs, int spc, int flags)
894 switch (gs->gsbase.subcode)
896 case GIMPLE_DEBUG_BIND:
897 if (flags & TDF_RAW)
898 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
899 gimple_debug_bind_get_var (gs),
900 gimple_debug_bind_get_value (gs));
901 else
902 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
903 gimple_debug_bind_get_var (gs),
904 gimple_debug_bind_get_value (gs));
905 break;
907 default:
908 gcc_unreachable ();
912 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
913 static void
914 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
916 size_t i;
918 if (flags & TDF_RAW)
920 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
921 gimple_omp_body (gs));
922 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
923 dump_gimple_fmt (buffer, spc, flags, " >,");
924 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
925 dump_gimple_fmt (buffer, spc, flags,
926 "%+%T, %T, %T, %s, %T,%n",
927 gimple_omp_for_index (gs, i),
928 gimple_omp_for_initial (gs, i),
929 gimple_omp_for_final (gs, i),
930 tree_code_name[gimple_omp_for_cond (gs, i)],
931 gimple_omp_for_incr (gs, i));
932 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
933 gimple_omp_for_pre_body (gs));
935 else
937 pp_string (buffer, "#pragma omp for");
938 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
939 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
941 if (i)
942 spc += 2;
943 newline_and_indent (buffer, spc);
944 pp_string (buffer, "for (");
945 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
946 flags, false);
947 pp_string (buffer, " = ");
948 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
949 flags, false);
950 pp_string (buffer, "; ");
952 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
953 flags, false);
954 pp_space (buffer);
955 switch (gimple_omp_for_cond (gs, i))
957 case LT_EXPR:
958 pp_character (buffer, '<');
959 break;
960 case GT_EXPR:
961 pp_character (buffer, '>');
962 break;
963 case LE_EXPR:
964 pp_string (buffer, "<=");
965 break;
966 case GE_EXPR:
967 pp_string (buffer, ">=");
968 break;
969 default:
970 gcc_unreachable ();
972 pp_space (buffer);
973 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
974 flags, false);
975 pp_string (buffer, "; ");
977 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
978 flags, false);
979 pp_string (buffer, " = ");
980 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
981 flags, false);
982 pp_character (buffer, ')');
985 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
987 newline_and_indent (buffer, spc + 2);
988 pp_character (buffer, '{');
989 pp_newline (buffer);
990 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
991 newline_and_indent (buffer, spc + 2);
992 pp_character (buffer, '}');
997 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
999 static void
1000 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
1002 if (flags & TDF_RAW)
1004 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1005 gimple_omp_continue_control_def (gs),
1006 gimple_omp_continue_control_use (gs));
1008 else
1010 pp_string (buffer, "#pragma omp continue (");
1011 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1012 spc, flags, false);
1013 pp_character (buffer, ',');
1014 pp_space (buffer);
1015 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1016 spc, flags, false);
1017 pp_character (buffer, ')');
1021 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1023 static void
1024 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
1026 if (flags & TDF_RAW)
1028 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1029 gimple_omp_body (gs));
1030 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1031 dump_gimple_fmt (buffer, spc, flags, " >");
1033 else
1035 pp_string (buffer, "#pragma omp single");
1036 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1037 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1039 newline_and_indent (buffer, spc + 2);
1040 pp_character (buffer, '{');
1041 pp_newline (buffer);
1042 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1043 newline_and_indent (buffer, spc + 2);
1044 pp_character (buffer, '}');
1049 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1051 static void
1052 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
1053 int flags)
1055 if (flags & TDF_RAW)
1057 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1058 gimple_omp_body (gs));
1059 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1060 dump_gimple_fmt (buffer, spc, flags, " >");
1062 else
1064 pp_string (buffer, "#pragma omp sections");
1065 if (gimple_omp_sections_control (gs))
1067 pp_string (buffer, " <");
1068 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1069 flags, false);
1070 pp_character (buffer, '>');
1072 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1073 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1075 newline_and_indent (buffer, spc + 2);
1076 pp_character (buffer, '{');
1077 pp_newline (buffer);
1078 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1079 newline_and_indent (buffer, spc + 2);
1080 pp_character (buffer, '}');
1085 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer
1086 BUFFER. */
1088 static void
1089 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
1091 if (flags & TDF_RAW)
1092 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1093 gimple_omp_body (gs));
1094 else
1096 switch (gimple_code (gs))
1098 case GIMPLE_OMP_MASTER:
1099 pp_string (buffer, "#pragma omp master");
1100 break;
1101 case GIMPLE_OMP_ORDERED:
1102 pp_string (buffer, "#pragma omp ordered");
1103 break;
1104 case GIMPLE_OMP_SECTION:
1105 pp_string (buffer, "#pragma omp section");
1106 break;
1107 default:
1108 gcc_unreachable ();
1110 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1112 newline_and_indent (buffer, spc + 2);
1113 pp_character (buffer, '{');
1114 pp_newline (buffer);
1115 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1116 newline_and_indent (buffer, spc + 2);
1117 pp_character (buffer, '}');
1122 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1124 static void
1125 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
1126 int flags)
1128 if (flags & TDF_RAW)
1129 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1130 gimple_omp_body (gs));
1131 else
1133 pp_string (buffer, "#pragma omp critical");
1134 if (gimple_omp_critical_name (gs))
1136 pp_string (buffer, " (");
1137 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1138 flags, false);
1139 pp_character (buffer, ')');
1141 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1143 newline_and_indent (buffer, spc + 2);
1144 pp_character (buffer, '{');
1145 pp_newline (buffer);
1146 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1147 newline_and_indent (buffer, spc + 2);
1148 pp_character (buffer, '}');
1153 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1155 static void
1156 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1158 if (flags & TDF_RAW)
1160 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d>", gs,
1161 (int) gimple_omp_return_nowait_p (gs));
1163 else
1165 pp_string (buffer, "#pragma omp return");
1166 if (gimple_omp_return_nowait_p (gs))
1167 pp_string (buffer, "(nowait)");
1171 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1172 indent. FLAGS specifies details to show in the dump (see TDF_* in
1173 tree-pass.h). */
1175 static void
1176 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1178 unsigned int i, n, f, fields;
1180 if (flags & TDF_RAW)
1182 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1183 gimple_asm_string (gs));
1185 n = gimple_asm_noutputs (gs);
1186 if (n)
1188 newline_and_indent (buffer, spc + 2);
1189 pp_string (buffer, "OUTPUT: ");
1190 for (i = 0; i < n; i++)
1192 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1193 spc, flags, false);
1194 if (i < n - 1)
1195 pp_string (buffer, ", ");
1199 n = gimple_asm_ninputs (gs);
1200 if (n)
1202 newline_and_indent (buffer, spc + 2);
1203 pp_string (buffer, "INPUT: ");
1204 for (i = 0; i < n; i++)
1206 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1207 spc, flags, false);
1208 if (i < n - 1)
1209 pp_string (buffer, ", ");
1213 n = gimple_asm_nclobbers (gs);
1214 if (n)
1216 newline_and_indent (buffer, spc + 2);
1217 pp_string (buffer, "CLOBBER: ");
1218 for (i = 0; i < n; i++)
1220 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1221 spc, flags, false);
1222 if (i < n - 1)
1223 pp_string (buffer, ", ");
1227 n = gimple_asm_nlabels (gs);
1228 if (n)
1230 newline_and_indent (buffer, spc + 2);
1231 pp_string (buffer, "LABEL: ");
1232 for (i = 0; i < n; i++)
1234 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1235 spc, flags, false);
1236 if (i < n - 1)
1237 pp_string (buffer, ", ");
1241 newline_and_indent (buffer, spc);
1242 pp_character (buffer, '>');
1244 else
1246 pp_string (buffer, "__asm__");
1247 if (gimple_asm_volatile_p (gs))
1248 pp_string (buffer, " __volatile__");
1249 if (gimple_asm_nlabels (gs))
1250 pp_string (buffer, " goto");
1251 pp_string (buffer, "(\"");
1252 pp_string (buffer, gimple_asm_string (gs));
1253 pp_string (buffer, "\"");
1255 if (gimple_asm_nlabels (gs))
1256 fields = 4;
1257 else if (gimple_asm_nclobbers (gs))
1258 fields = 3;
1259 else if (gimple_asm_ninputs (gs))
1260 fields = 2;
1261 else if (gimple_asm_noutputs (gs))
1262 fields = 1;
1263 else
1264 fields = 0;
1266 for (f = 0; f < fields; ++f)
1268 pp_string (buffer, " : ");
1270 switch (f)
1272 case 0:
1273 n = gimple_asm_noutputs (gs);
1274 for (i = 0; i < n; i++)
1276 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1277 spc, flags, false);
1278 if (i < n - 1)
1279 pp_string (buffer, ", ");
1281 break;
1283 case 1:
1284 n = gimple_asm_ninputs (gs);
1285 for (i = 0; i < n; i++)
1287 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1288 spc, flags, false);
1289 if (i < n - 1)
1290 pp_string (buffer, ", ");
1292 break;
1294 case 2:
1295 n = gimple_asm_nclobbers (gs);
1296 for (i = 0; i < n; i++)
1298 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1299 spc, flags, false);
1300 if (i < n - 1)
1301 pp_string (buffer, ", ");
1303 break;
1305 case 3:
1306 n = gimple_asm_nlabels (gs);
1307 for (i = 0; i < n; i++)
1309 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1310 spc, flags, false);
1311 if (i < n - 1)
1312 pp_string (buffer, ", ");
1314 break;
1316 default:
1317 gcc_unreachable ();
1321 pp_string (buffer, ");");
1326 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in
1327 dump_gimple_stmt. */
1329 static void
1330 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
1332 size_t i;
1333 tree lhs = gimple_phi_result (phi);
1335 if (flags & TDF_ALIAS
1336 && POINTER_TYPE_P (TREE_TYPE (lhs))
1337 && SSA_NAME_PTR_INFO (lhs))
1339 pp_string (buffer, "PT = ");
1340 pp_points_to_solution (buffer, &SSA_NAME_PTR_INFO (lhs)->pt);
1341 newline_and_indent (buffer, spc);
1342 pp_string (buffer, "# ");
1345 if (flags & TDF_RAW)
1346 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1347 gimple_phi_result (phi));
1348 else
1350 dump_generic_node (buffer, lhs, spc, flags, false);
1351 pp_string (buffer, " = PHI <");
1353 for (i = 0; i < gimple_phi_num_args (phi); i++)
1355 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1357 expanded_location xloc;
1359 xloc = expand_location (gimple_phi_arg_location (phi, i));
1360 pp_character (buffer, '[');
1361 if (xloc.file)
1363 pp_string (buffer, xloc.file);
1364 pp_string (buffer, " : ");
1366 pp_decimal_int (buffer, xloc.line);
1367 pp_string (buffer, ":");
1368 pp_decimal_int (buffer, xloc.column);
1369 pp_string (buffer, "] ");
1371 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1372 false);
1373 pp_character (buffer, '(');
1374 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1375 pp_character (buffer, ')');
1376 if (i < gimple_phi_num_args (phi) - 1)
1377 pp_string (buffer, ", ");
1379 pp_character (buffer, '>');
1383 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1384 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1385 tree-pass.h). */
1387 static void
1388 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1389 int flags)
1391 if (flags & TDF_RAW)
1393 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1394 gimple_omp_body (gs));
1395 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1396 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1397 gimple_omp_parallel_child_fn (gs),
1398 gimple_omp_parallel_data_arg (gs));
1400 else
1402 gimple_seq body;
1403 pp_string (buffer, "#pragma omp parallel");
1404 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1405 if (gimple_omp_parallel_child_fn (gs))
1407 pp_string (buffer, " [child fn: ");
1408 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1409 spc, flags, false);
1410 pp_string (buffer, " (");
1411 if (gimple_omp_parallel_data_arg (gs))
1412 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1413 spc, flags, false);
1414 else
1415 pp_string (buffer, "???");
1416 pp_string (buffer, ")]");
1418 body = gimple_omp_body (gs);
1419 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1421 newline_and_indent (buffer, spc + 2);
1422 pp_character (buffer, '{');
1423 pp_newline (buffer);
1424 dump_gimple_seq (buffer, body, spc + 4, flags);
1425 newline_and_indent (buffer, spc + 2);
1426 pp_character (buffer, '}');
1428 else if (body)
1430 pp_newline (buffer);
1431 dump_gimple_seq (buffer, body, spc + 2, flags);
1437 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1438 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1439 tree-pass.h). */
1441 static void
1442 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1443 int flags)
1445 if (flags & TDF_RAW)
1447 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1448 gimple_omp_body (gs));
1449 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1450 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1451 gimple_omp_task_child_fn (gs),
1452 gimple_omp_task_data_arg (gs),
1453 gimple_omp_task_copy_fn (gs),
1454 gimple_omp_task_arg_size (gs),
1455 gimple_omp_task_arg_size (gs));
1457 else
1459 gimple_seq body;
1460 pp_string (buffer, "#pragma omp task");
1461 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1462 if (gimple_omp_task_child_fn (gs))
1464 pp_string (buffer, " [child fn: ");
1465 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1466 spc, flags, false);
1467 pp_string (buffer, " (");
1468 if (gimple_omp_task_data_arg (gs))
1469 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1470 spc, flags, false);
1471 else
1472 pp_string (buffer, "???");
1473 pp_string (buffer, ")]");
1475 body = gimple_omp_body (gs);
1476 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1478 newline_and_indent (buffer, spc + 2);
1479 pp_character (buffer, '{');
1480 pp_newline (buffer);
1481 dump_gimple_seq (buffer, body, spc + 4, flags);
1482 newline_and_indent (buffer, spc + 2);
1483 pp_character (buffer, '}');
1485 else if (body)
1487 pp_newline (buffer);
1488 dump_gimple_seq (buffer, body, spc + 2, flags);
1494 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1495 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1496 in tree-pass.h). */
1498 static void
1499 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1500 int flags)
1502 if (flags & TDF_RAW)
1504 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1505 gimple_omp_atomic_load_lhs (gs),
1506 gimple_omp_atomic_load_rhs (gs));
1508 else
1510 pp_string (buffer, "#pragma omp atomic_load");
1511 newline_and_indent (buffer, spc + 2);
1512 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1513 spc, flags, false);
1514 pp_space (buffer);
1515 pp_character (buffer, '=');
1516 pp_space (buffer);
1517 pp_character (buffer, '*');
1518 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1519 spc, flags, false);
1523 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1524 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1525 in tree-pass.h). */
1527 static void
1528 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
1529 int flags)
1531 if (flags & TDF_RAW)
1533 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1534 gimple_omp_atomic_store_val (gs));
1536 else
1538 pp_string (buffer, "#pragma omp atomic_store (");
1539 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
1540 spc, flags, false);
1541 pp_character (buffer, ')');
1546 /* Dump all the memory operands for statement GS. BUFFER, SPC and
1547 FLAGS are as in dump_gimple_stmt. */
1549 static void
1550 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
1552 tree vdef = gimple_vdef (gs);
1553 tree vuse = gimple_vuse (gs);
1555 if (!ssa_operands_active () || !gimple_references_memory_p (gs))
1556 return;
1558 if (vdef != NULL_TREE)
1560 pp_string (buffer, "# ");
1561 dump_generic_node (buffer, vdef, spc + 2, flags, false);
1562 pp_string (buffer, " = VDEF <");
1563 dump_generic_node (buffer, vuse, spc + 2, flags, false);
1564 pp_character (buffer, '>');
1565 newline_and_indent (buffer, spc);
1567 else if (vuse != NULL_TREE)
1569 pp_string (buffer, "# VUSE <");
1570 dump_generic_node (buffer, vuse, spc + 2, flags, false);
1571 pp_character (buffer, '>');
1572 newline_and_indent (buffer, spc);
1577 /* Dump the gimple statement GS on the pretty printer BUFFER, SPC
1578 spaces of indent. FLAGS specifies details to show in the dump (see
1579 TDF_* in tree-pass.h). */
1581 void
1582 dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags)
1584 if (!gs)
1585 return;
1587 if (flags & TDF_STMTADDR)
1588 pp_printf (buffer, "<&%p> ", (void *) gs);
1590 if ((flags & TDF_LINENO) && gimple_has_location (gs))
1592 expanded_location xloc = expand_location (gimple_location (gs));
1593 pp_character (buffer, '[');
1594 if (xloc.file)
1596 pp_string (buffer, xloc.file);
1597 pp_string (buffer, " : ");
1599 pp_decimal_int (buffer, xloc.line);
1600 pp_string (buffer, ":");
1601 pp_decimal_int (buffer, xloc.column);
1602 pp_string (buffer, "] ");
1605 if (flags & TDF_EH)
1607 int lp_nr = lookup_stmt_eh_lp (gs);
1608 if (lp_nr > 0)
1609 pp_printf (buffer, "[LP %d] ", lp_nr);
1610 else if (lp_nr < 0)
1611 pp_printf (buffer, "[MNT %d] ", -lp_nr);
1614 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
1615 && gimple_has_mem_ops (gs))
1616 dump_gimple_mem_ops (buffer, gs, spc, flags);
1618 if ((flags & TDF_ALIAS)
1619 && gimple_has_lhs (gs))
1621 tree lhs = gimple_get_lhs (gs);
1622 if (TREE_CODE (lhs) == SSA_NAME
1623 && POINTER_TYPE_P (TREE_TYPE (lhs))
1624 && SSA_NAME_PTR_INFO (lhs))
1626 pp_string (buffer, "# PT = ");
1627 pp_points_to_solution (buffer, &SSA_NAME_PTR_INFO (lhs)->pt);
1628 newline_and_indent (buffer, spc);
1632 switch (gimple_code (gs))
1634 case GIMPLE_ASM:
1635 dump_gimple_asm (buffer, gs, spc, flags);
1636 break;
1638 case GIMPLE_ASSIGN:
1639 dump_gimple_assign (buffer, gs, spc, flags);
1640 break;
1642 case GIMPLE_BIND:
1643 dump_gimple_bind (buffer, gs, spc, flags);
1644 break;
1646 case GIMPLE_CALL:
1647 dump_gimple_call (buffer, gs, spc, flags);
1648 break;
1650 case GIMPLE_COND:
1651 dump_gimple_cond (buffer, gs, spc, flags);
1652 break;
1654 case GIMPLE_LABEL:
1655 dump_gimple_label (buffer, gs, spc, flags);
1656 break;
1658 case GIMPLE_GOTO:
1659 dump_gimple_goto (buffer, gs, spc, flags);
1660 break;
1662 case GIMPLE_NOP:
1663 pp_string (buffer, "GIMPLE_NOP");
1664 break;
1666 case GIMPLE_RETURN:
1667 dump_gimple_return (buffer, gs, spc, flags);
1668 break;
1670 case GIMPLE_SWITCH:
1671 dump_gimple_switch (buffer, gs, spc, flags);
1672 break;
1674 case GIMPLE_TRY:
1675 dump_gimple_try (buffer, gs, spc, flags);
1676 break;
1678 case GIMPLE_PHI:
1679 dump_gimple_phi (buffer, gs, spc, flags);
1680 break;
1682 case GIMPLE_OMP_PARALLEL:
1683 dump_gimple_omp_parallel (buffer, gs, spc, flags);
1684 break;
1686 case GIMPLE_OMP_TASK:
1687 dump_gimple_omp_task (buffer, gs, spc, flags);
1688 break;
1690 case GIMPLE_OMP_ATOMIC_LOAD:
1691 dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
1693 break;
1695 case GIMPLE_OMP_ATOMIC_STORE:
1696 dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
1697 break;
1699 case GIMPLE_OMP_FOR:
1700 dump_gimple_omp_for (buffer, gs, spc, flags);
1701 break;
1703 case GIMPLE_OMP_CONTINUE:
1704 dump_gimple_omp_continue (buffer, gs, spc, flags);
1705 break;
1707 case GIMPLE_OMP_SINGLE:
1708 dump_gimple_omp_single (buffer, gs, spc, flags);
1709 break;
1711 case GIMPLE_OMP_RETURN:
1712 dump_gimple_omp_return (buffer, gs, spc, flags);
1713 break;
1715 case GIMPLE_OMP_SECTIONS:
1716 dump_gimple_omp_sections (buffer, gs, spc, flags);
1717 break;
1719 case GIMPLE_OMP_SECTIONS_SWITCH:
1720 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
1721 break;
1723 case GIMPLE_OMP_MASTER:
1724 case GIMPLE_OMP_ORDERED:
1725 case GIMPLE_OMP_SECTION:
1726 dump_gimple_omp_block (buffer, gs, spc, flags);
1727 break;
1729 case GIMPLE_OMP_CRITICAL:
1730 dump_gimple_omp_critical (buffer, gs, spc, flags);
1731 break;
1733 case GIMPLE_CATCH:
1734 dump_gimple_catch (buffer, gs, spc, flags);
1735 break;
1737 case GIMPLE_EH_FILTER:
1738 dump_gimple_eh_filter (buffer, gs, spc, flags);
1739 break;
1741 case GIMPLE_EH_MUST_NOT_THROW:
1742 dump_gimple_eh_must_not_throw (buffer, gs, spc, flags);
1743 break;
1745 case GIMPLE_RESX:
1746 dump_gimple_resx (buffer, gs, spc, flags);
1747 break;
1749 case GIMPLE_EH_DISPATCH:
1750 dump_gimple_eh_dispatch (buffer, gs, spc, flags);
1751 break;
1753 case GIMPLE_DEBUG:
1754 dump_gimple_debug (buffer, gs, spc, flags);
1755 break;
1757 case GIMPLE_PREDICT:
1758 pp_string (buffer, "// predicted ");
1759 if (gimple_predict_outcome (gs))
1760 pp_string (buffer, "likely by ");
1761 else
1762 pp_string (buffer, "unlikely by ");
1763 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
1764 pp_string (buffer, " predictor.");
1765 break;
1767 default:
1768 GIMPLE_NIY;
1771 /* If we're building a diagnostic, the formatted text will be
1772 written into BUFFER's stream by the caller; otherwise, write it
1773 now. */
1774 if (!(flags & TDF_DIAGNOSTIC))
1775 pp_write_text_to_stream (buffer);
1779 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
1780 spaces and details described by flags. */
1782 static void
1783 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
1785 edge e;
1786 gimple stmt;
1787 edge_iterator ei;
1789 if (flags & TDF_BLOCKS)
1791 INDENT (indent);
1792 pp_string (buffer, "# BLOCK ");
1793 pp_decimal_int (buffer, bb->index);
1794 if (bb->frequency)
1796 pp_string (buffer, " freq:");
1797 pp_decimal_int (buffer, bb->frequency);
1799 if (bb->count)
1801 pp_string (buffer, " count:");
1802 pp_widest_integer (buffer, bb->count);
1805 if (flags & TDF_LINENO)
1807 gimple_stmt_iterator gsi;
1809 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1810 if (!is_gimple_debug (gsi_stmt (gsi))
1811 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
1813 pp_string (buffer, ", starting at line ");
1814 pp_decimal_int (buffer, get_lineno (gsi_stmt (gsi)));
1815 break;
1818 if (bb->discriminator)
1820 pp_string (buffer, ", discriminator ");
1821 pp_decimal_int (buffer, bb->discriminator);
1824 newline_and_indent (buffer, indent);
1826 pp_string (buffer, "# PRED:");
1827 pp_write_text_to_stream (buffer);
1828 FOR_EACH_EDGE (e, ei, bb->preds)
1829 if (flags & TDF_SLIM)
1831 pp_character (buffer, ' ');
1832 if (e->src == ENTRY_BLOCK_PTR)
1833 pp_string (buffer, "ENTRY");
1834 else
1835 pp_decimal_int (buffer, e->src->index);
1837 else
1838 dump_edge_info (buffer->buffer->stream, e, 0);
1839 pp_newline (buffer);
1841 else
1843 stmt = first_stmt (bb);
1844 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
1846 INDENT (indent - 2);
1847 pp_string (buffer, "<bb ");
1848 pp_decimal_int (buffer, bb->index);
1849 pp_string (buffer, ">:");
1850 pp_newline (buffer);
1853 pp_write_text_to_stream (buffer);
1854 check_bb_profile (bb, buffer->buffer->stream);
1858 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
1859 spaces. */
1861 static void
1862 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
1864 edge e;
1865 edge_iterator ei;
1867 INDENT (indent);
1868 pp_string (buffer, "# SUCC:");
1869 pp_write_text_to_stream (buffer);
1870 FOR_EACH_EDGE (e, ei, bb->succs)
1871 if (flags & TDF_SLIM)
1873 pp_character (buffer, ' ');
1874 if (e->dest == EXIT_BLOCK_PTR)
1875 pp_string (buffer, "EXIT");
1876 else
1877 pp_decimal_int (buffer, e->dest->index);
1879 else
1880 dump_edge_info (buffer->buffer->stream, e, 1);
1881 pp_newline (buffer);
1885 /* Dump PHI nodes of basic block BB to BUFFER with details described
1886 by FLAGS and indented by INDENT spaces. */
1888 static void
1889 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
1891 gimple_stmt_iterator i;
1893 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
1895 gimple phi = gsi_stmt (i);
1896 if (is_gimple_reg (gimple_phi_result (phi)) || (flags & TDF_VOPS))
1898 INDENT (indent);
1899 pp_string (buffer, "# ");
1900 dump_gimple_phi (buffer, phi, indent, flags);
1901 pp_newline (buffer);
1907 /* Dump jump to basic block BB that is represented implicitly in the cfg
1908 to BUFFER. */
1910 static void
1911 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
1913 gimple stmt;
1915 stmt = first_stmt (bb);
1917 pp_string (buffer, "goto <bb ");
1918 pp_decimal_int (buffer, bb->index);
1919 pp_character (buffer, '>');
1920 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
1922 pp_string (buffer, " (");
1923 dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
1924 pp_character (buffer, ')');
1925 pp_semicolon (buffer);
1927 else
1928 pp_semicolon (buffer);
1932 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
1933 by INDENT spaces, with details given by FLAGS. */
1935 static void
1936 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
1937 int flags)
1939 edge e;
1940 edge_iterator ei;
1941 gimple stmt;
1943 stmt = last_stmt (bb);
1945 if (stmt && gimple_code (stmt) == GIMPLE_COND)
1947 edge true_edge, false_edge;
1949 /* When we are emitting the code or changing CFG, it is possible that
1950 the edges are not yet created. When we are using debug_bb in such
1951 a situation, we do not want it to crash. */
1952 if (EDGE_COUNT (bb->succs) != 2)
1953 return;
1954 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
1956 INDENT (indent + 2);
1957 pp_cfg_jump (buffer, true_edge->dest);
1958 newline_and_indent (buffer, indent);
1959 pp_string (buffer, "else");
1960 newline_and_indent (buffer, indent + 2);
1961 pp_cfg_jump (buffer, false_edge->dest);
1962 pp_newline (buffer);
1963 return;
1966 /* If there is a fallthru edge, we may need to add an artificial
1967 goto to the dump. */
1968 FOR_EACH_EDGE (e, ei, bb->succs)
1969 if (e->flags & EDGE_FALLTHRU)
1970 break;
1972 if (e && e->dest != bb->next_bb)
1974 INDENT (indent);
1976 if ((flags & TDF_LINENO)
1977 && e->goto_locus != UNKNOWN_LOCATION
1980 expanded_location goto_xloc;
1981 goto_xloc = expand_location (e->goto_locus);
1982 pp_character (buffer, '[');
1983 if (goto_xloc.file)
1985 pp_string (buffer, goto_xloc.file);
1986 pp_string (buffer, " : ");
1988 pp_decimal_int (buffer, goto_xloc.line);
1989 pp_string (buffer, " : ");
1990 pp_decimal_int (buffer, goto_xloc.column);
1991 pp_string (buffer, "] ");
1994 pp_cfg_jump (buffer, e->dest);
1995 pp_newline (buffer);
2000 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2001 indented by INDENT spaces. */
2003 static void
2004 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2005 int flags)
2007 gimple_stmt_iterator gsi;
2008 gimple stmt;
2009 int label_indent = indent - 2;
2011 if (label_indent < 0)
2012 label_indent = 0;
2014 dump_bb_header (buffer, bb, indent, flags);
2015 dump_phi_nodes (buffer, bb, indent, flags);
2017 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2019 int curr_indent;
2021 stmt = gsi_stmt (gsi);
2023 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2025 INDENT (curr_indent);
2026 dump_gimple_stmt (buffer, stmt, curr_indent, flags);
2027 pp_newline (buffer);
2028 dump_histograms_for_stmt (cfun, buffer->buffer->stream, stmt);
2031 dump_implicit_edges (buffer, bb, indent, flags);
2033 if (flags & TDF_BLOCKS)
2034 dump_bb_end (buffer, bb, indent, flags);
2038 /* Dumps basic block BB to FILE with details described by FLAGS and
2039 indented by INDENT spaces. */
2041 void
2042 gimple_dump_bb (basic_block bb, FILE *file, int indent, int flags)
2044 maybe_init_pretty_print (file);
2045 gimple_dump_bb_buff (&buffer, bb, indent, flags);
2046 pp_flush (&buffer);