Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / gimple-pretty-print.c
blob491eae3b51bf01d71657bfaabb9f251be3c45eb1
1 /* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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 "tree-pretty-print.h"
30 #include "gimple-pretty-print.h"
31 #include "hashtab.h"
32 #include "tree-flow.h"
33 #include "tree-pass.h"
34 #include "gimple.h"
35 #include "value-prof.h"
37 #define INDENT(SPACE) \
38 do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
40 static pretty_printer buffer;
41 static bool initialized = false;
43 #define GIMPLE_NIY do_niy (buffer,gs)
45 /* Try to print on BUFFER a default message for the unrecognized
46 gimple statement GS. */
48 static void
49 do_niy (pretty_printer *buffer, gimple gs)
51 pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
52 gimple_code_name[(int) gimple_code (gs)]);
56 /* Initialize the pretty printer on FILE if needed. */
58 static void
59 maybe_init_pretty_print (FILE *file)
61 if (!initialized)
63 pp_construct (&buffer, NULL, 0);
64 pp_needs_newline (&buffer) = true;
65 initialized = true;
68 buffer.buffer->stream = file;
72 /* Emit a newline and SPC indentantion spaces to BUFFER. */
74 static void
75 newline_and_indent (pretty_printer *buffer, int spc)
77 pp_newline (buffer);
78 INDENT (spc);
82 /* Print the GIMPLE statement GS on stderr. */
84 DEBUG_FUNCTION void
85 debug_gimple_stmt (gimple gs)
87 print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
88 fprintf (stderr, "\n");
92 /* Dump GIMPLE statement G to FILE using SPC indentantion spaces and
93 FLAGS as in dump_gimple_stmt. */
95 void
96 print_gimple_stmt (FILE *file, gimple g, int spc, int flags)
98 maybe_init_pretty_print (file);
99 dump_gimple_stmt (&buffer, g, spc, flags);
100 pp_flush (&buffer);
104 /* Dump GIMPLE statement G to FILE using SPC indentantion spaces and
105 FLAGS as in dump_gimple_stmt. Print only the right-hand side
106 of the statement. */
108 void
109 print_gimple_expr (FILE *file, gimple g, int spc, int flags)
111 flags |= TDF_RHS_ONLY;
112 maybe_init_pretty_print (file);
113 dump_gimple_stmt (&buffer, g, spc, flags);
117 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentantion
118 spaces and FLAGS as in dump_gimple_stmt. */
120 static void
121 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc, int flags)
123 gimple_stmt_iterator i;
125 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
127 gimple gs = gsi_stmt (i);
128 INDENT (spc);
129 dump_gimple_stmt (buffer, gs, spc, flags);
130 if (!gsi_one_before_end_p (i))
131 pp_newline (buffer);
136 /* Dump GIMPLE sequence SEQ to FILE using SPC indentantion spaces and
137 FLAGS as in dump_gimple_stmt. */
139 void
140 print_gimple_seq (FILE *file, gimple_seq seq, int spc, int flags)
142 maybe_init_pretty_print (file);
143 dump_gimple_seq (&buffer, seq, spc, flags);
144 pp_flush (&buffer);
148 /* Print the GIMPLE sequence SEQ on stderr. */
150 DEBUG_FUNCTION void
151 debug_gimple_seq (gimple_seq seq)
153 print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
157 /* A simple helper to pretty-print some of the gimple tuples in the printf
158 style. The format modifiers are preceeded by '%' and are:
159 'G' - outputs a string corresponding to the code of the given gimple,
160 'S' - outputs a gimple_seq with indent of spc + 2,
161 'T' - outputs the tree t,
162 'd' - outputs an int as a decimal,
163 's' - outputs a string,
164 'n' - outputs a newline,
165 '+' - increases indent by 2 then outputs a newline,
166 '-' - decreases indent by 2 then outputs a newline. */
168 static void
169 dump_gimple_fmt (pretty_printer *buffer, int spc, int flags,
170 const char *fmt, ...)
172 va_list args;
173 const char *c;
174 const char *tmp;
176 va_start (args, fmt);
177 for (c = fmt; *c; c++)
179 if (*c == '%')
181 gimple_seq seq;
182 tree t;
183 gimple g;
184 switch (*++c)
186 case 'G':
187 g = va_arg (args, gimple);
188 tmp = gimple_code_name[gimple_code (g)];
189 pp_string (buffer, tmp);
190 break;
192 case 'S':
193 seq = va_arg (args, gimple_seq);
194 pp_newline (buffer);
195 dump_gimple_seq (buffer, seq, spc + 2, flags);
196 newline_and_indent (buffer, spc);
197 break;
199 case 'T':
200 t = va_arg (args, tree);
201 if (t == NULL_TREE)
202 pp_string (buffer, "NULL");
203 else
204 dump_generic_node (buffer, t, spc, flags, false);
205 break;
207 case 'd':
208 pp_decimal_int (buffer, va_arg (args, int));
209 break;
211 case 's':
212 pp_string (buffer, va_arg (args, char *));
213 break;
215 case 'n':
216 newline_and_indent (buffer, spc);
217 break;
219 case '+':
220 spc += 2;
221 newline_and_indent (buffer, spc);
222 break;
224 case '-':
225 spc -= 2;
226 newline_and_indent (buffer, spc);
227 break;
229 default:
230 gcc_unreachable ();
233 else
234 pp_character (buffer, *c);
236 va_end (args);
240 /* Helper for dump_gimple_assign. Print the unary RHS of the
241 assignment GS. BUFFER, SPC and FLAGS are as in dump_gimple_stmt. */
243 static void
244 dump_unary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
246 enum tree_code rhs_code = gimple_assign_rhs_code (gs);
247 tree lhs = gimple_assign_lhs (gs);
248 tree rhs = gimple_assign_rhs1 (gs);
250 switch (rhs_code)
252 case VIEW_CONVERT_EXPR:
253 case ASSERT_EXPR:
254 dump_generic_node (buffer, rhs, spc, flags, false);
255 break;
257 case FIXED_CONVERT_EXPR:
258 case ADDR_SPACE_CONVERT_EXPR:
259 case FIX_TRUNC_EXPR:
260 case FLOAT_EXPR:
261 CASE_CONVERT:
262 pp_character (buffer, '(');
263 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
264 pp_string (buffer, ") ");
265 if (op_prio (rhs) < op_code_prio (rhs_code))
267 pp_character (buffer, '(');
268 dump_generic_node (buffer, rhs, spc, flags, false);
269 pp_character (buffer, ')');
271 else
272 dump_generic_node (buffer, rhs, spc, flags, false);
273 break;
275 case PAREN_EXPR:
276 pp_string (buffer, "((");
277 dump_generic_node (buffer, rhs, spc, flags, false);
278 pp_string (buffer, "))");
279 break;
281 case ABS_EXPR:
282 pp_string (buffer, "ABS_EXPR <");
283 dump_generic_node (buffer, rhs, spc, flags, false);
284 pp_character (buffer, '>');
285 break;
287 default:
288 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
289 || TREE_CODE_CLASS (rhs_code) == tcc_constant
290 || TREE_CODE_CLASS (rhs_code) == tcc_reference
291 || rhs_code == SSA_NAME
292 || rhs_code == ADDR_EXPR
293 || rhs_code == CONSTRUCTOR)
295 dump_generic_node (buffer, rhs, spc, flags, false);
296 break;
298 else if (rhs_code == BIT_NOT_EXPR)
299 pp_character (buffer, '~');
300 else if (rhs_code == TRUTH_NOT_EXPR)
301 pp_character (buffer, '!');
302 else if (rhs_code == NEGATE_EXPR)
303 pp_character (buffer, '-');
304 else
306 pp_character (buffer, '[');
307 pp_string (buffer, tree_code_name [rhs_code]);
308 pp_string (buffer, "] ");
311 if (op_prio (rhs) < op_code_prio (rhs_code))
313 pp_character (buffer, '(');
314 dump_generic_node (buffer, rhs, spc, flags, false);
315 pp_character (buffer, ')');
317 else
318 dump_generic_node (buffer, rhs, spc, flags, false);
319 break;
324 /* Helper for dump_gimple_assign. Print the binary RHS of the
325 assignment GS. BUFFER, SPC and FLAGS are as in dump_gimple_stmt. */
327 static void
328 dump_binary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
330 const char *p;
331 enum tree_code code = gimple_assign_rhs_code (gs);
332 switch (code)
334 case COMPLEX_EXPR:
335 case MIN_EXPR:
336 case MAX_EXPR:
337 case VEC_WIDEN_MULT_HI_EXPR:
338 case VEC_WIDEN_MULT_LO_EXPR:
339 case VEC_PACK_TRUNC_EXPR:
340 case VEC_PACK_SAT_EXPR:
341 case VEC_PACK_FIX_TRUNC_EXPR:
342 case VEC_EXTRACT_EVEN_EXPR:
343 case VEC_EXTRACT_ODD_EXPR:
344 case VEC_INTERLEAVE_HIGH_EXPR:
345 case VEC_INTERLEAVE_LOW_EXPR:
346 for (p = tree_code_name [(int) code]; *p; p++)
347 pp_character (buffer, TOUPPER (*p));
348 pp_string (buffer, " <");
349 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
350 pp_string (buffer, ", ");
351 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
352 pp_character (buffer, '>');
353 break;
355 default:
356 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
358 pp_character (buffer, '(');
359 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
360 false);
361 pp_character (buffer, ')');
363 else
364 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
365 pp_space (buffer);
366 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
367 pp_space (buffer);
368 if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
370 pp_character (buffer, '(');
371 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
372 false);
373 pp_character (buffer, ')');
375 else
376 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
380 /* Helper for dump_gimple_assign. Print the ternary RHS of the
381 assignment GS. BUFFER, SPC and FLAGS are as in dump_gimple_stmt. */
383 static void
384 dump_ternary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
386 const char *p;
387 enum tree_code code = gimple_assign_rhs_code (gs);
388 switch (code)
390 case WIDEN_MULT_PLUS_EXPR:
391 case WIDEN_MULT_MINUS_EXPR:
392 for (p = tree_code_name [(int) code]; *p; p++)
393 pp_character (buffer, TOUPPER (*p));
394 pp_string (buffer, " <");
395 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
396 pp_string (buffer, ", ");
397 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
398 pp_string (buffer, ", ");
399 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
400 pp_character (buffer, '>');
401 break;
403 default:
404 gcc_unreachable ();
409 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
410 dump_gimple_stmt. */
412 static void
413 dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
415 if (flags & TDF_RAW)
417 tree last;
418 if (gimple_num_ops (gs) == 2)
419 last = NULL_TREE;
420 else if (gimple_num_ops (gs) == 3)
421 last = gimple_assign_rhs2 (gs);
422 else
423 gcc_unreachable ();
425 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T>", gs,
426 tree_code_name[gimple_assign_rhs_code (gs)],
427 gimple_assign_lhs (gs), gimple_assign_rhs1 (gs), last);
429 else
431 if (!(flags & TDF_RHS_ONLY))
433 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
434 pp_space (buffer);
435 pp_character (buffer, '=');
437 if (gimple_assign_nontemporal_move_p (gs))
438 pp_string (buffer, "{nt}");
440 if (gimple_has_volatile_ops (gs))
441 pp_string (buffer, "{v}");
443 pp_space (buffer);
446 if (gimple_num_ops (gs) == 2)
447 dump_unary_rhs (buffer, gs, spc, flags);
448 else if (gimple_num_ops (gs) == 3)
449 dump_binary_rhs (buffer, gs, spc, flags);
450 else if (gimple_num_ops (gs) == 4)
451 dump_ternary_rhs (buffer, gs, spc, flags);
452 else
453 gcc_unreachable ();
454 if (!(flags & TDF_RHS_ONLY))
455 pp_semicolon(buffer);
460 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
461 dump_gimple_stmt. */
463 static void
464 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
466 tree t;
468 t = gimple_return_retval (gs);
469 if (flags & TDF_RAW)
470 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
471 else
473 pp_string (buffer, "return");
474 if (t)
476 pp_space (buffer);
477 dump_generic_node (buffer, t, spc, flags, false);
479 pp_semicolon (buffer);
484 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
485 dump_gimple_call. */
487 static void
488 dump_gimple_call_args (pretty_printer *buffer, gimple gs, int flags)
490 size_t i;
492 for (i = 0; i < gimple_call_num_args (gs); i++)
494 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
495 if (i < gimple_call_num_args (gs) - 1)
496 pp_string (buffer, ", ");
499 if (gimple_call_va_arg_pack_p (gs))
501 if (gimple_call_num_args (gs) > 0)
503 pp_character (buffer, ',');
504 pp_space (buffer);
507 pp_string (buffer, "__builtin_va_arg_pack ()");
511 /* Dump the points-to solution *PT to BUFFER. */
513 static void
514 pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
516 if (pt->anything)
518 pp_string (buffer, "anything ");
519 return;
521 if (pt->nonlocal)
522 pp_string (buffer, "nonlocal ");
523 if (pt->escaped)
524 pp_string (buffer, "escaped ");
525 if (pt->ipa_escaped)
526 pp_string (buffer, "unit-escaped ");
527 if (pt->null)
528 pp_string (buffer, "null ");
529 if (pt->vars
530 && !bitmap_empty_p (pt->vars))
532 bitmap_iterator bi;
533 unsigned i;
534 pp_string (buffer, "{ ");
535 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
537 struct tree_decl_minimal in;
538 tree var;
539 in.uid = i;
540 var = (tree) htab_find_with_hash (gimple_referenced_vars (cfun),
541 &in, i);
542 if (var)
544 dump_generic_node (buffer, var, 0, dump_flags, false);
545 if (DECL_PT_UID (var) != DECL_UID (var))
547 pp_string (buffer, "ptD.");
548 pp_decimal_int (buffer, DECL_PT_UID (var));
551 else
553 pp_string (buffer, "D.");
554 pp_decimal_int (buffer, i);
556 pp_character (buffer, ' ');
558 pp_character (buffer, '}');
559 if (pt->vars_contains_global)
560 pp_string (buffer, " (glob)");
561 if (pt->vars_contains_restrict)
562 pp_string (buffer, " (restr)");
566 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
567 dump_gimple_stmt. */
569 static void
570 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
572 tree lhs = gimple_call_lhs (gs);
574 if (flags & TDF_ALIAS)
576 struct pt_solution *pt;
577 pt = gimple_call_use_set (gs);
578 if (!pt_solution_empty_p (pt))
580 pp_string (buffer, "# USE = ");
581 pp_points_to_solution (buffer, pt);
582 newline_and_indent (buffer, spc);
584 pt = gimple_call_clobber_set (gs);
585 if (!pt_solution_empty_p (pt))
587 pp_string (buffer, "# CLB = ");
588 pp_points_to_solution (buffer, pt);
589 newline_and_indent (buffer, spc);
593 if (flags & TDF_RAW)
595 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T",
596 gs, gimple_call_fn (gs), lhs);
597 if (gimple_call_num_args (gs) > 0)
599 pp_string (buffer, ", ");
600 dump_gimple_call_args (buffer, gs, flags);
602 pp_character (buffer, '>');
604 else
606 if (lhs && !(flags & TDF_RHS_ONLY))
608 dump_generic_node (buffer, lhs, spc, flags, false);
609 pp_string (buffer, " =");
611 if (gimple_has_volatile_ops (gs))
612 pp_string (buffer, "{v}");
614 pp_space (buffer);
616 print_call_name (buffer, gimple_call_fn (gs), flags);
617 pp_string (buffer, " (");
618 dump_gimple_call_args (buffer, gs, flags);
619 pp_character (buffer, ')');
620 if (!(flags & TDF_RHS_ONLY))
621 pp_semicolon (buffer);
624 if (gimple_call_chain (gs))
626 pp_string (buffer, " [static-chain: ");
627 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
628 pp_character (buffer, ']');
631 if (gimple_call_return_slot_opt_p (gs))
632 pp_string (buffer, " [return slot optimization]");
634 if (gimple_call_tail_p (gs))
635 pp_string (buffer, " [tail call]");
639 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
640 dump_gimple_stmt. */
642 static void
643 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
645 unsigned int i;
647 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
648 if (flags & TDF_RAW)
649 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
650 gimple_switch_index (gs));
651 else
653 pp_string (buffer, "switch (");
654 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
655 pp_string (buffer, ") <");
658 for (i = 0; i < gimple_switch_num_labels (gs); i++)
660 tree case_label = gimple_switch_label (gs, i);
661 if (case_label == NULL_TREE)
662 continue;
664 dump_generic_node (buffer, case_label, spc, flags, false);
665 pp_character (buffer, ' ');
666 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
667 if (i < gimple_switch_num_labels (gs) - 1)
668 pp_string (buffer, ", ");
670 pp_character (buffer, '>');
674 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
675 dump_gimple_stmt. */
677 static void
678 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
680 if (flags & TDF_RAW)
681 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
682 tree_code_name [gimple_cond_code (gs)],
683 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
684 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
685 else
687 if (!(flags & TDF_RHS_ONLY))
688 pp_string (buffer, "if (");
689 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
690 pp_space (buffer);
691 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
692 pp_space (buffer);
693 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
694 if (!(flags & TDF_RHS_ONLY))
696 pp_character (buffer, ')');
698 if (gimple_cond_true_label (gs))
700 pp_string (buffer, " goto ");
701 dump_generic_node (buffer, gimple_cond_true_label (gs),
702 spc, flags, false);
703 pp_semicolon (buffer);
705 if (gimple_cond_false_label (gs))
707 pp_string (buffer, " else goto ");
708 dump_generic_node (buffer, gimple_cond_false_label (gs),
709 spc, flags, false);
710 pp_semicolon (buffer);
717 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
718 spaces of indent. FLAGS specifies details to show in the dump (see
719 TDF_* in tree-pass.h). */
721 static void
722 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
724 tree label = gimple_label_label (gs);
725 if (flags & TDF_RAW)
726 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
727 else
729 dump_generic_node (buffer, label, spc, flags, false);
730 pp_character (buffer, ':');
732 if (DECL_NONLOCAL (label))
733 pp_string (buffer, " [non-local]");
734 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
735 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
738 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
739 spaces of indent. FLAGS specifies details to show in the dump (see
740 TDF_* in tree-pass.h). */
742 static void
743 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
745 tree label = gimple_goto_dest (gs);
746 if (flags & TDF_RAW)
747 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
748 else
749 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
753 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
754 spaces of indent. FLAGS specifies details to show in the dump (see
755 TDF_* in tree-pass.h). */
757 static void
758 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
760 if (flags & TDF_RAW)
761 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
762 else
763 pp_character (buffer, '{');
764 if (!(flags & TDF_SLIM))
766 tree var;
768 for (var = gimple_bind_vars (gs); var; var = TREE_CHAIN (var))
770 newline_and_indent (buffer, 2);
771 print_declaration (buffer, var, spc, flags);
773 if (gimple_bind_vars (gs))
774 pp_newline (buffer);
776 pp_newline (buffer);
777 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
778 newline_and_indent (buffer, spc);
779 if (flags & TDF_RAW)
780 pp_character (buffer, '>');
781 else
782 pp_character (buffer, '}');
786 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
787 indent. FLAGS specifies details to show in the dump (see TDF_* in
788 tree-pass.h). */
790 static void
791 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
793 if (flags & TDF_RAW)
795 const char *type;
796 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
797 type = "GIMPLE_TRY_CATCH";
798 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
799 type = "GIMPLE_TRY_FINALLY";
800 else
801 type = "UNKNOWN GIMPLE_TRY";
802 dump_gimple_fmt (buffer, spc, flags,
803 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
804 gimple_try_eval (gs), gimple_try_cleanup (gs));
806 else
808 pp_string (buffer, "try");
809 newline_and_indent (buffer, spc + 2);
810 pp_character (buffer, '{');
811 pp_newline (buffer);
813 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
814 newline_and_indent (buffer, spc + 2);
815 pp_character (buffer, '}');
817 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
819 newline_and_indent (buffer, spc);
820 pp_string (buffer, "catch");
821 newline_and_indent (buffer, spc + 2);
822 pp_character (buffer, '{');
824 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
826 newline_and_indent (buffer, spc);
827 pp_string (buffer, "finally");
828 newline_and_indent (buffer, spc + 2);
829 pp_character (buffer, '{');
831 else
832 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
834 pp_newline (buffer);
835 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
836 newline_and_indent (buffer, spc + 2);
837 pp_character (buffer, '}');
842 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
843 indent. FLAGS specifies details to show in the dump (see TDF_* in
844 tree-pass.h). */
846 static void
847 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
849 if (flags & TDF_RAW)
850 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
851 gimple_catch_types (gs), gimple_catch_handler (gs));
852 else
853 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
854 gimple_catch_types (gs), gimple_catch_handler (gs));
858 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
859 indent. FLAGS specifies details to show in the dump (see TDF_* in
860 tree-pass.h). */
862 static void
863 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
865 if (flags & TDF_RAW)
866 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
867 gimple_eh_filter_types (gs),
868 gimple_eh_filter_failure (gs));
869 else
870 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
871 gimple_eh_filter_types (gs),
872 gimple_eh_filter_failure (gs));
876 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
878 static void
879 dump_gimple_eh_must_not_throw (pretty_printer *buffer, gimple gs,
880 int spc, int flags)
882 if (flags & TDF_RAW)
883 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
884 gimple_eh_must_not_throw_fndecl (gs));
885 else
886 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
887 gimple_eh_must_not_throw_fndecl (gs));
891 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
892 indent. FLAGS specifies details to show in the dump (see TDF_* in
893 tree-pass.h). */
895 static void
896 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
898 if (flags & TDF_RAW)
899 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
900 gimple_resx_region (gs));
901 else
902 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
905 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
907 static void
908 dump_gimple_eh_dispatch (pretty_printer *buffer, gimple gs, int spc, int flags)
910 if (flags & TDF_RAW)
911 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
912 gimple_eh_dispatch_region (gs));
913 else
914 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
915 gimple_eh_dispatch_region (gs));
918 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
919 of indent. FLAGS specifies details to show in the dump (see TDF_*
920 in tree-pass.h). */
922 static void
923 dump_gimple_debug (pretty_printer *buffer, gimple gs, int spc, int flags)
925 switch (gs->gsbase.subcode)
927 case GIMPLE_DEBUG_BIND:
928 if (flags & TDF_RAW)
929 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
930 gimple_debug_bind_get_var (gs),
931 gimple_debug_bind_get_value (gs));
932 else
933 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
934 gimple_debug_bind_get_var (gs),
935 gimple_debug_bind_get_value (gs));
936 break;
938 default:
939 gcc_unreachable ();
943 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
944 static void
945 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
947 size_t i;
949 if (flags & TDF_RAW)
951 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
952 gimple_omp_body (gs));
953 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
954 dump_gimple_fmt (buffer, spc, flags, " >,");
955 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
956 dump_gimple_fmt (buffer, spc, flags,
957 "%+%T, %T, %T, %s, %T,%n",
958 gimple_omp_for_index (gs, i),
959 gimple_omp_for_initial (gs, i),
960 gimple_omp_for_final (gs, i),
961 tree_code_name[gimple_omp_for_cond (gs, i)],
962 gimple_omp_for_incr (gs, i));
963 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
964 gimple_omp_for_pre_body (gs));
966 else
968 pp_string (buffer, "#pragma omp for");
969 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
970 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
972 if (i)
973 spc += 2;
974 newline_and_indent (buffer, spc);
975 pp_string (buffer, "for (");
976 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
977 flags, false);
978 pp_string (buffer, " = ");
979 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
980 flags, false);
981 pp_string (buffer, "; ");
983 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
984 flags, false);
985 pp_space (buffer);
986 switch (gimple_omp_for_cond (gs, i))
988 case LT_EXPR:
989 pp_character (buffer, '<');
990 break;
991 case GT_EXPR:
992 pp_character (buffer, '>');
993 break;
994 case LE_EXPR:
995 pp_string (buffer, "<=");
996 break;
997 case GE_EXPR:
998 pp_string (buffer, ">=");
999 break;
1000 default:
1001 gcc_unreachable ();
1003 pp_space (buffer);
1004 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1005 flags, false);
1006 pp_string (buffer, "; ");
1008 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1009 flags, false);
1010 pp_string (buffer, " = ");
1011 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1012 flags, false);
1013 pp_character (buffer, ')');
1016 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1018 newline_and_indent (buffer, spc + 2);
1019 pp_character (buffer, '{');
1020 pp_newline (buffer);
1021 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1022 newline_and_indent (buffer, spc + 2);
1023 pp_character (buffer, '}');
1028 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
1030 static void
1031 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
1033 if (flags & TDF_RAW)
1035 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1036 gimple_omp_continue_control_def (gs),
1037 gimple_omp_continue_control_use (gs));
1039 else
1041 pp_string (buffer, "#pragma omp continue (");
1042 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1043 spc, flags, false);
1044 pp_character (buffer, ',');
1045 pp_space (buffer);
1046 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1047 spc, flags, false);
1048 pp_character (buffer, ')');
1052 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1054 static void
1055 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
1057 if (flags & TDF_RAW)
1059 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1060 gimple_omp_body (gs));
1061 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1062 dump_gimple_fmt (buffer, spc, flags, " >");
1064 else
1066 pp_string (buffer, "#pragma omp single");
1067 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1068 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1070 newline_and_indent (buffer, spc + 2);
1071 pp_character (buffer, '{');
1072 pp_newline (buffer);
1073 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1074 newline_and_indent (buffer, spc + 2);
1075 pp_character (buffer, '}');
1080 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1082 static void
1083 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
1084 int flags)
1086 if (flags & TDF_RAW)
1088 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1089 gimple_omp_body (gs));
1090 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1091 dump_gimple_fmt (buffer, spc, flags, " >");
1093 else
1095 pp_string (buffer, "#pragma omp sections");
1096 if (gimple_omp_sections_control (gs))
1098 pp_string (buffer, " <");
1099 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1100 flags, false);
1101 pp_character (buffer, '>');
1103 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1104 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1106 newline_and_indent (buffer, spc + 2);
1107 pp_character (buffer, '{');
1108 pp_newline (buffer);
1109 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1110 newline_and_indent (buffer, spc + 2);
1111 pp_character (buffer, '}');
1116 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer
1117 BUFFER. */
1119 static void
1120 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
1122 if (flags & TDF_RAW)
1123 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1124 gimple_omp_body (gs));
1125 else
1127 switch (gimple_code (gs))
1129 case GIMPLE_OMP_MASTER:
1130 pp_string (buffer, "#pragma omp master");
1131 break;
1132 case GIMPLE_OMP_ORDERED:
1133 pp_string (buffer, "#pragma omp ordered");
1134 break;
1135 case GIMPLE_OMP_SECTION:
1136 pp_string (buffer, "#pragma omp section");
1137 break;
1138 default:
1139 gcc_unreachable ();
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_CRITICAL tuple on the pretty_printer BUFFER. */
1155 static void
1156 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
1157 int flags)
1159 if (flags & TDF_RAW)
1160 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1161 gimple_omp_body (gs));
1162 else
1164 pp_string (buffer, "#pragma omp critical");
1165 if (gimple_omp_critical_name (gs))
1167 pp_string (buffer, " (");
1168 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1169 flags, false);
1170 pp_character (buffer, ')');
1172 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1174 newline_and_indent (buffer, spc + 2);
1175 pp_character (buffer, '{');
1176 pp_newline (buffer);
1177 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1178 newline_and_indent (buffer, spc + 2);
1179 pp_character (buffer, '}');
1184 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1186 static void
1187 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1189 if (flags & TDF_RAW)
1191 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d>", gs,
1192 (int) gimple_omp_return_nowait_p (gs));
1194 else
1196 pp_string (buffer, "#pragma omp return");
1197 if (gimple_omp_return_nowait_p (gs))
1198 pp_string (buffer, "(nowait)");
1202 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1203 indent. FLAGS specifies details to show in the dump (see TDF_* in
1204 tree-pass.h). */
1206 static void
1207 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1209 unsigned int i, n, f, fields;
1211 if (flags & TDF_RAW)
1213 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1214 gimple_asm_string (gs));
1216 n = gimple_asm_noutputs (gs);
1217 if (n)
1219 newline_and_indent (buffer, spc + 2);
1220 pp_string (buffer, "OUTPUT: ");
1221 for (i = 0; i < n; i++)
1223 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1224 spc, flags, false);
1225 if (i < n - 1)
1226 pp_string (buffer, ", ");
1230 n = gimple_asm_ninputs (gs);
1231 if (n)
1233 newline_and_indent (buffer, spc + 2);
1234 pp_string (buffer, "INPUT: ");
1235 for (i = 0; i < n; i++)
1237 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1238 spc, flags, false);
1239 if (i < n - 1)
1240 pp_string (buffer, ", ");
1244 n = gimple_asm_nclobbers (gs);
1245 if (n)
1247 newline_and_indent (buffer, spc + 2);
1248 pp_string (buffer, "CLOBBER: ");
1249 for (i = 0; i < n; i++)
1251 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1252 spc, flags, false);
1253 if (i < n - 1)
1254 pp_string (buffer, ", ");
1258 n = gimple_asm_nlabels (gs);
1259 if (n)
1261 newline_and_indent (buffer, spc + 2);
1262 pp_string (buffer, "LABEL: ");
1263 for (i = 0; i < n; i++)
1265 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1266 spc, flags, false);
1267 if (i < n - 1)
1268 pp_string (buffer, ", ");
1272 newline_and_indent (buffer, spc);
1273 pp_character (buffer, '>');
1275 else
1277 pp_string (buffer, "__asm__");
1278 if (gimple_asm_volatile_p (gs))
1279 pp_string (buffer, " __volatile__");
1280 if (gimple_asm_nlabels (gs))
1281 pp_string (buffer, " goto");
1282 pp_string (buffer, "(\"");
1283 pp_string (buffer, gimple_asm_string (gs));
1284 pp_string (buffer, "\"");
1286 if (gimple_asm_nlabels (gs))
1287 fields = 4;
1288 else if (gimple_asm_nclobbers (gs))
1289 fields = 3;
1290 else if (gimple_asm_ninputs (gs))
1291 fields = 2;
1292 else if (gimple_asm_noutputs (gs))
1293 fields = 1;
1294 else
1295 fields = 0;
1297 for (f = 0; f < fields; ++f)
1299 pp_string (buffer, " : ");
1301 switch (f)
1303 case 0:
1304 n = gimple_asm_noutputs (gs);
1305 for (i = 0; i < n; i++)
1307 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1308 spc, flags, false);
1309 if (i < n - 1)
1310 pp_string (buffer, ", ");
1312 break;
1314 case 1:
1315 n = gimple_asm_ninputs (gs);
1316 for (i = 0; i < n; i++)
1318 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1319 spc, flags, false);
1320 if (i < n - 1)
1321 pp_string (buffer, ", ");
1323 break;
1325 case 2:
1326 n = gimple_asm_nclobbers (gs);
1327 for (i = 0; i < n; i++)
1329 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1330 spc, flags, false);
1331 if (i < n - 1)
1332 pp_string (buffer, ", ");
1334 break;
1336 case 3:
1337 n = gimple_asm_nlabels (gs);
1338 for (i = 0; i < n; i++)
1340 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1341 spc, flags, false);
1342 if (i < n - 1)
1343 pp_string (buffer, ", ");
1345 break;
1347 default:
1348 gcc_unreachable ();
1352 pp_string (buffer, ");");
1357 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in
1358 dump_gimple_stmt. */
1360 static void
1361 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
1363 size_t i;
1364 tree lhs = gimple_phi_result (phi);
1366 if (flags & TDF_ALIAS
1367 && POINTER_TYPE_P (TREE_TYPE (lhs))
1368 && SSA_NAME_PTR_INFO (lhs))
1370 pp_string (buffer, "PT = ");
1371 pp_points_to_solution (buffer, &SSA_NAME_PTR_INFO (lhs)->pt);
1372 newline_and_indent (buffer, spc);
1373 pp_string (buffer, "# ");
1376 if (flags & TDF_RAW)
1377 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1378 gimple_phi_result (phi));
1379 else
1381 dump_generic_node (buffer, lhs, spc, flags, false);
1382 pp_string (buffer, " = PHI <");
1384 for (i = 0; i < gimple_phi_num_args (phi); i++)
1386 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1388 expanded_location xloc;
1390 xloc = expand_location (gimple_phi_arg_location (phi, i));
1391 pp_character (buffer, '[');
1392 if (xloc.file)
1394 pp_string (buffer, xloc.file);
1395 pp_string (buffer, " : ");
1397 pp_decimal_int (buffer, xloc.line);
1398 pp_string (buffer, ":");
1399 pp_decimal_int (buffer, xloc.column);
1400 pp_string (buffer, "] ");
1402 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1403 false);
1404 pp_character (buffer, '(');
1405 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1406 pp_character (buffer, ')');
1407 if (i < gimple_phi_num_args (phi) - 1)
1408 pp_string (buffer, ", ");
1410 pp_character (buffer, '>');
1414 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1415 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1416 tree-pass.h). */
1418 static void
1419 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1420 int flags)
1422 if (flags & TDF_RAW)
1424 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1425 gimple_omp_body (gs));
1426 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1427 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1428 gimple_omp_parallel_child_fn (gs),
1429 gimple_omp_parallel_data_arg (gs));
1431 else
1433 gimple_seq body;
1434 pp_string (buffer, "#pragma omp parallel");
1435 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1436 if (gimple_omp_parallel_child_fn (gs))
1438 pp_string (buffer, " [child fn: ");
1439 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1440 spc, flags, false);
1441 pp_string (buffer, " (");
1442 if (gimple_omp_parallel_data_arg (gs))
1443 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1444 spc, flags, false);
1445 else
1446 pp_string (buffer, "???");
1447 pp_string (buffer, ")]");
1449 body = gimple_omp_body (gs);
1450 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1452 newline_and_indent (buffer, spc + 2);
1453 pp_character (buffer, '{');
1454 pp_newline (buffer);
1455 dump_gimple_seq (buffer, body, spc + 4, flags);
1456 newline_and_indent (buffer, spc + 2);
1457 pp_character (buffer, '}');
1459 else if (body)
1461 pp_newline (buffer);
1462 dump_gimple_seq (buffer, body, spc + 2, flags);
1468 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1469 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1470 tree-pass.h). */
1472 static void
1473 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1474 int flags)
1476 if (flags & TDF_RAW)
1478 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1479 gimple_omp_body (gs));
1480 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1481 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1482 gimple_omp_task_child_fn (gs),
1483 gimple_omp_task_data_arg (gs),
1484 gimple_omp_task_copy_fn (gs),
1485 gimple_omp_task_arg_size (gs),
1486 gimple_omp_task_arg_size (gs));
1488 else
1490 gimple_seq body;
1491 pp_string (buffer, "#pragma omp task");
1492 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1493 if (gimple_omp_task_child_fn (gs))
1495 pp_string (buffer, " [child fn: ");
1496 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1497 spc, flags, false);
1498 pp_string (buffer, " (");
1499 if (gimple_omp_task_data_arg (gs))
1500 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1501 spc, flags, false);
1502 else
1503 pp_string (buffer, "???");
1504 pp_string (buffer, ")]");
1506 body = gimple_omp_body (gs);
1507 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1509 newline_and_indent (buffer, spc + 2);
1510 pp_character (buffer, '{');
1511 pp_newline (buffer);
1512 dump_gimple_seq (buffer, body, spc + 4, flags);
1513 newline_and_indent (buffer, spc + 2);
1514 pp_character (buffer, '}');
1516 else if (body)
1518 pp_newline (buffer);
1519 dump_gimple_seq (buffer, body, spc + 2, flags);
1525 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1526 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1527 in tree-pass.h). */
1529 static void
1530 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1531 int flags)
1533 if (flags & TDF_RAW)
1535 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1536 gimple_omp_atomic_load_lhs (gs),
1537 gimple_omp_atomic_load_rhs (gs));
1539 else
1541 pp_string (buffer, "#pragma omp atomic_load");
1542 newline_and_indent (buffer, spc + 2);
1543 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1544 spc, flags, false);
1545 pp_space (buffer);
1546 pp_character (buffer, '=');
1547 pp_space (buffer);
1548 pp_character (buffer, '*');
1549 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1550 spc, flags, false);
1554 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1555 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1556 in tree-pass.h). */
1558 static void
1559 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
1560 int flags)
1562 if (flags & TDF_RAW)
1564 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1565 gimple_omp_atomic_store_val (gs));
1567 else
1569 pp_string (buffer, "#pragma omp atomic_store (");
1570 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
1571 spc, flags, false);
1572 pp_character (buffer, ')');
1577 /* Dump all the memory operands for statement GS. BUFFER, SPC and
1578 FLAGS are as in dump_gimple_stmt. */
1580 static void
1581 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
1583 tree vdef = gimple_vdef (gs);
1584 tree vuse = gimple_vuse (gs);
1586 if (!ssa_operands_active () || !gimple_references_memory_p (gs))
1587 return;
1589 if (vdef != NULL_TREE)
1591 pp_string (buffer, "# ");
1592 dump_generic_node (buffer, vdef, spc + 2, flags, false);
1593 pp_string (buffer, " = VDEF <");
1594 dump_generic_node (buffer, vuse, spc + 2, flags, false);
1595 pp_character (buffer, '>');
1596 newline_and_indent (buffer, spc);
1598 else if (vuse != NULL_TREE)
1600 pp_string (buffer, "# VUSE <");
1601 dump_generic_node (buffer, vuse, spc + 2, flags, false);
1602 pp_character (buffer, '>');
1603 newline_and_indent (buffer, spc);
1608 /* Dump the gimple statement GS on the pretty printer BUFFER, SPC
1609 spaces of indent. FLAGS specifies details to show in the dump (see
1610 TDF_* in tree-pass.h). */
1612 void
1613 dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags)
1615 if (!gs)
1616 return;
1618 if (flags & TDF_STMTADDR)
1619 pp_printf (buffer, "<&%p> ", (void *) gs);
1621 if ((flags & TDF_LINENO) && gimple_has_location (gs))
1623 expanded_location xloc = expand_location (gimple_location (gs));
1624 pp_character (buffer, '[');
1625 if (xloc.file)
1627 pp_string (buffer, xloc.file);
1628 pp_string (buffer, " : ");
1630 pp_decimal_int (buffer, xloc.line);
1631 pp_string (buffer, ":");
1632 pp_decimal_int (buffer, xloc.column);
1633 pp_string (buffer, "] ");
1636 if (flags & TDF_EH)
1638 int lp_nr = lookup_stmt_eh_lp (gs);
1639 if (lp_nr > 0)
1640 pp_printf (buffer, "[LP %d] ", lp_nr);
1641 else if (lp_nr < 0)
1642 pp_printf (buffer, "[MNT %d] ", -lp_nr);
1645 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
1646 && gimple_has_mem_ops (gs))
1647 dump_gimple_mem_ops (buffer, gs, spc, flags);
1649 if ((flags & TDF_ALIAS)
1650 && gimple_has_lhs (gs))
1652 tree lhs = gimple_get_lhs (gs);
1653 if (TREE_CODE (lhs) == SSA_NAME
1654 && POINTER_TYPE_P (TREE_TYPE (lhs))
1655 && SSA_NAME_PTR_INFO (lhs))
1657 pp_string (buffer, "# PT = ");
1658 pp_points_to_solution (buffer, &SSA_NAME_PTR_INFO (lhs)->pt);
1659 newline_and_indent (buffer, spc);
1663 switch (gimple_code (gs))
1665 case GIMPLE_ASM:
1666 dump_gimple_asm (buffer, gs, spc, flags);
1667 break;
1669 case GIMPLE_ASSIGN:
1670 dump_gimple_assign (buffer, gs, spc, flags);
1671 break;
1673 case GIMPLE_BIND:
1674 dump_gimple_bind (buffer, gs, spc, flags);
1675 break;
1677 case GIMPLE_CALL:
1678 dump_gimple_call (buffer, gs, spc, flags);
1679 break;
1681 case GIMPLE_COND:
1682 dump_gimple_cond (buffer, gs, spc, flags);
1683 break;
1685 case GIMPLE_LABEL:
1686 dump_gimple_label (buffer, gs, spc, flags);
1687 break;
1689 case GIMPLE_GOTO:
1690 dump_gimple_goto (buffer, gs, spc, flags);
1691 break;
1693 case GIMPLE_NOP:
1694 pp_string (buffer, "GIMPLE_NOP");
1695 break;
1697 case GIMPLE_RETURN:
1698 dump_gimple_return (buffer, gs, spc, flags);
1699 break;
1701 case GIMPLE_SWITCH:
1702 dump_gimple_switch (buffer, gs, spc, flags);
1703 break;
1705 case GIMPLE_TRY:
1706 dump_gimple_try (buffer, gs, spc, flags);
1707 break;
1709 case GIMPLE_PHI:
1710 dump_gimple_phi (buffer, gs, spc, flags);
1711 break;
1713 case GIMPLE_OMP_PARALLEL:
1714 dump_gimple_omp_parallel (buffer, gs, spc, flags);
1715 break;
1717 case GIMPLE_OMP_TASK:
1718 dump_gimple_omp_task (buffer, gs, spc, flags);
1719 break;
1721 case GIMPLE_OMP_ATOMIC_LOAD:
1722 dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
1724 break;
1726 case GIMPLE_OMP_ATOMIC_STORE:
1727 dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
1728 break;
1730 case GIMPLE_OMP_FOR:
1731 dump_gimple_omp_for (buffer, gs, spc, flags);
1732 break;
1734 case GIMPLE_OMP_CONTINUE:
1735 dump_gimple_omp_continue (buffer, gs, spc, flags);
1736 break;
1738 case GIMPLE_OMP_SINGLE:
1739 dump_gimple_omp_single (buffer, gs, spc, flags);
1740 break;
1742 case GIMPLE_OMP_RETURN:
1743 dump_gimple_omp_return (buffer, gs, spc, flags);
1744 break;
1746 case GIMPLE_OMP_SECTIONS:
1747 dump_gimple_omp_sections (buffer, gs, spc, flags);
1748 break;
1750 case GIMPLE_OMP_SECTIONS_SWITCH:
1751 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
1752 break;
1754 case GIMPLE_OMP_MASTER:
1755 case GIMPLE_OMP_ORDERED:
1756 case GIMPLE_OMP_SECTION:
1757 dump_gimple_omp_block (buffer, gs, spc, flags);
1758 break;
1760 case GIMPLE_OMP_CRITICAL:
1761 dump_gimple_omp_critical (buffer, gs, spc, flags);
1762 break;
1764 case GIMPLE_CATCH:
1765 dump_gimple_catch (buffer, gs, spc, flags);
1766 break;
1768 case GIMPLE_EH_FILTER:
1769 dump_gimple_eh_filter (buffer, gs, spc, flags);
1770 break;
1772 case GIMPLE_EH_MUST_NOT_THROW:
1773 dump_gimple_eh_must_not_throw (buffer, gs, spc, flags);
1774 break;
1776 case GIMPLE_RESX:
1777 dump_gimple_resx (buffer, gs, spc, flags);
1778 break;
1780 case GIMPLE_EH_DISPATCH:
1781 dump_gimple_eh_dispatch (buffer, gs, spc, flags);
1782 break;
1784 case GIMPLE_DEBUG:
1785 dump_gimple_debug (buffer, gs, spc, flags);
1786 break;
1788 case GIMPLE_PREDICT:
1789 pp_string (buffer, "// predicted ");
1790 if (gimple_predict_outcome (gs))
1791 pp_string (buffer, "likely by ");
1792 else
1793 pp_string (buffer, "unlikely by ");
1794 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
1795 pp_string (buffer, " predictor.");
1796 break;
1798 default:
1799 GIMPLE_NIY;
1802 /* If we're building a diagnostic, the formatted text will be
1803 written into BUFFER's stream by the caller; otherwise, write it
1804 now. */
1805 if (!(flags & TDF_DIAGNOSTIC))
1806 pp_write_text_to_stream (buffer);
1810 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
1811 spaces and details described by flags. */
1813 static void
1814 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
1816 edge e;
1817 gimple stmt;
1818 edge_iterator ei;
1820 if (flags & TDF_BLOCKS)
1822 INDENT (indent);
1823 pp_string (buffer, "# BLOCK ");
1824 pp_decimal_int (buffer, bb->index);
1825 if (bb->frequency)
1827 pp_string (buffer, " freq:");
1828 pp_decimal_int (buffer, bb->frequency);
1830 if (bb->count)
1832 pp_string (buffer, " count:");
1833 pp_widest_integer (buffer, bb->count);
1836 if (flags & TDF_LINENO)
1838 gimple_stmt_iterator gsi;
1840 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1841 if (!is_gimple_debug (gsi_stmt (gsi))
1842 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
1844 pp_string (buffer, ", starting at line ");
1845 pp_decimal_int (buffer, get_lineno (gsi_stmt (gsi)));
1846 break;
1849 if (bb->discriminator)
1851 pp_string (buffer, ", discriminator ");
1852 pp_decimal_int (buffer, bb->discriminator);
1855 newline_and_indent (buffer, indent);
1857 pp_string (buffer, "# PRED:");
1858 pp_write_text_to_stream (buffer);
1859 FOR_EACH_EDGE (e, ei, bb->preds)
1860 if (flags & TDF_SLIM)
1862 pp_character (buffer, ' ');
1863 if (e->src == ENTRY_BLOCK_PTR)
1864 pp_string (buffer, "ENTRY");
1865 else
1866 pp_decimal_int (buffer, e->src->index);
1868 else
1869 dump_edge_info (buffer->buffer->stream, e, 0);
1870 pp_newline (buffer);
1872 else
1874 stmt = first_stmt (bb);
1875 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
1877 INDENT (indent - 2);
1878 pp_string (buffer, "<bb ");
1879 pp_decimal_int (buffer, bb->index);
1880 pp_string (buffer, ">:");
1881 pp_newline (buffer);
1884 pp_write_text_to_stream (buffer);
1885 check_bb_profile (bb, buffer->buffer->stream);
1889 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
1890 spaces. */
1892 static void
1893 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
1895 edge e;
1896 edge_iterator ei;
1898 INDENT (indent);
1899 pp_string (buffer, "# SUCC:");
1900 pp_write_text_to_stream (buffer);
1901 FOR_EACH_EDGE (e, ei, bb->succs)
1902 if (flags & TDF_SLIM)
1904 pp_character (buffer, ' ');
1905 if (e->dest == EXIT_BLOCK_PTR)
1906 pp_string (buffer, "EXIT");
1907 else
1908 pp_decimal_int (buffer, e->dest->index);
1910 else
1911 dump_edge_info (buffer->buffer->stream, e, 1);
1912 pp_newline (buffer);
1916 /* Dump PHI nodes of basic block BB to BUFFER with details described
1917 by FLAGS and indented by INDENT spaces. */
1919 static void
1920 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
1922 gimple_stmt_iterator i;
1924 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
1926 gimple phi = gsi_stmt (i);
1927 if (is_gimple_reg (gimple_phi_result (phi)) || (flags & TDF_VOPS))
1929 INDENT (indent);
1930 pp_string (buffer, "# ");
1931 dump_gimple_phi (buffer, phi, indent, flags);
1932 pp_newline (buffer);
1938 /* Dump jump to basic block BB that is represented implicitly in the cfg
1939 to BUFFER. */
1941 static void
1942 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
1944 gimple stmt;
1946 stmt = first_stmt (bb);
1948 pp_string (buffer, "goto <bb ");
1949 pp_decimal_int (buffer, bb->index);
1950 pp_character (buffer, '>');
1951 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
1953 pp_string (buffer, " (");
1954 dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
1955 pp_character (buffer, ')');
1956 pp_semicolon (buffer);
1958 else
1959 pp_semicolon (buffer);
1963 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
1964 by INDENT spaces, with details given by FLAGS. */
1966 static void
1967 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
1968 int flags)
1970 edge e;
1971 edge_iterator ei;
1972 gimple stmt;
1974 stmt = last_stmt (bb);
1976 if (stmt && gimple_code (stmt) == GIMPLE_COND)
1978 edge true_edge, false_edge;
1980 /* When we are emitting the code or changing CFG, it is possible that
1981 the edges are not yet created. When we are using debug_bb in such
1982 a situation, we do not want it to crash. */
1983 if (EDGE_COUNT (bb->succs) != 2)
1984 return;
1985 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
1987 INDENT (indent + 2);
1988 pp_cfg_jump (buffer, true_edge->dest);
1989 newline_and_indent (buffer, indent);
1990 pp_string (buffer, "else");
1991 newline_and_indent (buffer, indent + 2);
1992 pp_cfg_jump (buffer, false_edge->dest);
1993 pp_newline (buffer);
1994 return;
1997 /* If there is a fallthru edge, we may need to add an artificial
1998 goto to the dump. */
1999 FOR_EACH_EDGE (e, ei, bb->succs)
2000 if (e->flags & EDGE_FALLTHRU)
2001 break;
2003 if (e && e->dest != bb->next_bb)
2005 INDENT (indent);
2007 if ((flags & TDF_LINENO)
2008 && e->goto_locus != UNKNOWN_LOCATION
2011 expanded_location goto_xloc;
2012 goto_xloc = expand_location (e->goto_locus);
2013 pp_character (buffer, '[');
2014 if (goto_xloc.file)
2016 pp_string (buffer, goto_xloc.file);
2017 pp_string (buffer, " : ");
2019 pp_decimal_int (buffer, goto_xloc.line);
2020 pp_string (buffer, " : ");
2021 pp_decimal_int (buffer, goto_xloc.column);
2022 pp_string (buffer, "] ");
2025 pp_cfg_jump (buffer, e->dest);
2026 pp_newline (buffer);
2031 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2032 indented by INDENT spaces. */
2034 static void
2035 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2036 int flags)
2038 gimple_stmt_iterator gsi;
2039 gimple stmt;
2040 int label_indent = indent - 2;
2042 if (label_indent < 0)
2043 label_indent = 0;
2045 dump_bb_header (buffer, bb, indent, flags);
2046 dump_phi_nodes (buffer, bb, indent, flags);
2048 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2050 int curr_indent;
2052 stmt = gsi_stmt (gsi);
2054 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2056 INDENT (curr_indent);
2057 dump_gimple_stmt (buffer, stmt, curr_indent, flags);
2058 pp_newline (buffer);
2059 dump_histograms_for_stmt (cfun, buffer->buffer->stream, stmt);
2062 dump_implicit_edges (buffer, bb, indent, flags);
2064 if (flags & TDF_BLOCKS)
2065 dump_bb_end (buffer, bb, indent, flags);
2069 /* Dumps basic block BB to FILE with details described by FLAGS and
2070 indented by INDENT spaces. */
2072 void
2073 gimple_dump_bb (basic_block bb, FILE *file, int indent, int flags)
2075 maybe_init_pretty_print (file);
2076 gimple_dump_bb_buff (&buffer, bb, indent, flags);
2077 pp_flush (&buffer);