Enable dumping of alias graphs.
[official-gcc/Ramakrishna.git] / gcc / gimple-pretty-print.c
blob50180203e2d2351e90d956b108de9256341f6956
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 FIX_TRUNC_EXPR:
258 case FLOAT_EXPR:
259 CASE_CONVERT:
260 pp_character (buffer, '(');
261 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
262 pp_string (buffer, ") ");
263 if (op_prio (rhs) < op_code_prio (rhs_code))
265 pp_character (buffer, '(');
266 dump_generic_node (buffer, rhs, spc, flags, false);
267 pp_character (buffer, ')');
269 else
270 dump_generic_node (buffer, rhs, spc, flags, false);
271 break;
273 case PAREN_EXPR:
274 pp_string (buffer, "((");
275 dump_generic_node (buffer, rhs, spc, flags, false);
276 pp_string (buffer, "))");
277 break;
279 case ABS_EXPR:
280 pp_string (buffer, "ABS_EXPR <");
281 dump_generic_node (buffer, rhs, spc, flags, false);
282 pp_character (buffer, '>');
283 break;
285 default:
286 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
287 || TREE_CODE_CLASS (rhs_code) == tcc_constant
288 || TREE_CODE_CLASS (rhs_code) == tcc_reference
289 || rhs_code == SSA_NAME
290 || rhs_code == ADDR_EXPR
291 || rhs_code == CONSTRUCTOR)
293 dump_generic_node (buffer, rhs, spc, flags, false);
294 break;
296 else if (rhs_code == BIT_NOT_EXPR)
297 pp_character (buffer, '~');
298 else if (rhs_code == TRUTH_NOT_EXPR)
299 pp_character (buffer, '!');
300 else if (rhs_code == NEGATE_EXPR)
301 pp_character (buffer, '-');
302 else
304 pp_character (buffer, '[');
305 pp_string (buffer, tree_code_name [rhs_code]);
306 pp_string (buffer, "] ");
309 if (op_prio (rhs) < op_code_prio (rhs_code))
311 pp_character (buffer, '(');
312 dump_generic_node (buffer, rhs, spc, flags, false);
313 pp_character (buffer, ')');
315 else
316 dump_generic_node (buffer, rhs, spc, flags, false);
317 break;
322 /* Helper for dump_gimple_assign. Print the binary RHS of the
323 assignment GS. BUFFER, SPC and FLAGS are as in dump_gimple_stmt. */
325 static void
326 dump_binary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
328 const char *p;
329 enum tree_code code = gimple_assign_rhs_code (gs);
330 switch (code)
332 case COMPLEX_EXPR:
333 case MIN_EXPR:
334 case MAX_EXPR:
335 case VEC_WIDEN_MULT_HI_EXPR:
336 case VEC_WIDEN_MULT_LO_EXPR:
337 case VEC_PACK_TRUNC_EXPR:
338 case VEC_PACK_SAT_EXPR:
339 case VEC_PACK_FIX_TRUNC_EXPR:
340 case VEC_EXTRACT_EVEN_EXPR:
341 case VEC_EXTRACT_ODD_EXPR:
342 case VEC_INTERLEAVE_HIGH_EXPR:
343 case VEC_INTERLEAVE_LOW_EXPR:
344 for (p = tree_code_name [(int) code]; *p; p++)
345 pp_character (buffer, TOUPPER (*p));
346 pp_string (buffer, " <");
347 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
348 pp_string (buffer, ", ");
349 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
350 pp_character (buffer, '>');
351 break;
353 default:
354 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
356 pp_character (buffer, '(');
357 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
358 false);
359 pp_character (buffer, ')');
361 else
362 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
363 pp_space (buffer);
364 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
365 pp_space (buffer);
366 if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
368 pp_character (buffer, '(');
369 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
370 false);
371 pp_character (buffer, ')');
373 else
374 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
379 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
380 dump_gimple_stmt. */
382 static void
383 dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
385 if (flags & TDF_RAW)
387 tree last;
388 if (gimple_num_ops (gs) == 2)
389 last = NULL_TREE;
390 else if (gimple_num_ops (gs) == 3)
391 last = gimple_assign_rhs2 (gs);
392 else
393 gcc_unreachable ();
395 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T>", gs,
396 tree_code_name[gimple_assign_rhs_code (gs)],
397 gimple_assign_lhs (gs), gimple_assign_rhs1 (gs), last);
399 else
401 if (!(flags & TDF_RHS_ONLY))
403 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
404 pp_space (buffer);
405 pp_character (buffer, '=');
407 if (gimple_assign_nontemporal_move_p (gs))
408 pp_string (buffer, "{nt}");
410 if (gimple_has_volatile_ops (gs))
411 pp_string (buffer, "{v}");
413 pp_space (buffer);
416 if (gimple_num_ops (gs) == 2)
417 dump_unary_rhs (buffer, gs, spc, flags);
418 else if (gimple_num_ops (gs) == 3)
419 dump_binary_rhs (buffer, gs, spc, flags);
420 else
421 gcc_unreachable ();
422 if (!(flags & TDF_RHS_ONLY))
423 pp_semicolon(buffer);
428 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
429 dump_gimple_stmt. */
431 static void
432 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
434 tree t;
436 t = gimple_return_retval (gs);
437 if (flags & TDF_RAW)
438 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
439 else
441 pp_string (buffer, "return");
442 if (t)
444 pp_space (buffer);
445 dump_generic_node (buffer, t, spc, flags, false);
447 pp_semicolon (buffer);
452 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
453 dump_gimple_call. */
455 static void
456 dump_gimple_call_args (pretty_printer *buffer, gimple gs, int flags)
458 size_t i;
460 for (i = 0; i < gimple_call_num_args (gs); i++)
462 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
463 if (i < gimple_call_num_args (gs) - 1)
464 pp_string (buffer, ", ");
467 if (gimple_call_va_arg_pack_p (gs))
469 if (gimple_call_num_args (gs) > 0)
471 pp_character (buffer, ',');
472 pp_space (buffer);
475 pp_string (buffer, "__builtin_va_arg_pack ()");
480 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
481 dump_gimple_stmt. */
483 static void
484 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
486 tree lhs = gimple_call_lhs (gs);
488 if (flags & TDF_RAW)
490 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T",
491 gs, gimple_call_fn (gs), lhs);
492 if (gimple_call_num_args (gs) > 0)
494 pp_string (buffer, ", ");
495 dump_gimple_call_args (buffer, gs, flags);
497 pp_character (buffer, '>');
499 else
501 if (lhs && !(flags & TDF_RHS_ONLY))
503 dump_generic_node (buffer, lhs, spc, flags, false);
504 pp_string (buffer, " =");
506 if (gimple_has_volatile_ops (gs))
507 pp_string (buffer, "{v}");
509 pp_space (buffer);
511 print_call_name (buffer, gimple_call_fn (gs), flags);
512 pp_string (buffer, " (");
513 dump_gimple_call_args (buffer, gs, flags);
514 pp_character (buffer, ')');
515 if (!(flags & TDF_RHS_ONLY))
516 pp_semicolon (buffer);
519 if (gimple_call_chain (gs))
521 pp_string (buffer, " [static-chain: ");
522 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
523 pp_character (buffer, ']');
526 if (gimple_call_return_slot_opt_p (gs))
527 pp_string (buffer, " [return slot optimization]");
529 if (gimple_call_tail_p (gs))
530 pp_string (buffer, " [tail call]");
534 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
535 dump_gimple_stmt. */
537 static void
538 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
540 unsigned int i;
542 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
543 if (flags & TDF_RAW)
544 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
545 gimple_switch_index (gs));
546 else
548 pp_string (buffer, "switch (");
549 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
550 pp_string (buffer, ") <");
553 for (i = 0; i < gimple_switch_num_labels (gs); i++)
555 tree case_label = gimple_switch_label (gs, i);
556 if (case_label == NULL_TREE)
557 continue;
559 dump_generic_node (buffer, case_label, spc, flags, false);
560 pp_character (buffer, ' ');
561 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
562 if (i < gimple_switch_num_labels (gs) - 1)
563 pp_string (buffer, ", ");
565 pp_character (buffer, '>');
569 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
570 dump_gimple_stmt. */
572 static void
573 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
575 if (flags & TDF_RAW)
576 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
577 tree_code_name [gimple_cond_code (gs)],
578 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
579 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
580 else
582 if (!(flags & TDF_RHS_ONLY))
583 pp_string (buffer, "if (");
584 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
585 pp_space (buffer);
586 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
587 pp_space (buffer);
588 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
589 if (!(flags & TDF_RHS_ONLY))
591 pp_character (buffer, ')');
593 if (gimple_cond_true_label (gs))
595 pp_string (buffer, " goto ");
596 dump_generic_node (buffer, gimple_cond_true_label (gs),
597 spc, flags, false);
598 pp_semicolon (buffer);
600 if (gimple_cond_false_label (gs))
602 pp_string (buffer, " else goto ");
603 dump_generic_node (buffer, gimple_cond_false_label (gs),
604 spc, flags, false);
605 pp_semicolon (buffer);
612 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
613 spaces of indent. FLAGS specifies details to show in the dump (see
614 TDF_* in tree-pass.h). */
616 static void
617 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
619 tree label = gimple_label_label (gs);
620 if (flags & TDF_RAW)
621 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
622 else
624 dump_generic_node (buffer, label, spc, flags, false);
625 pp_character (buffer, ':');
627 if (DECL_NONLOCAL (label))
628 pp_string (buffer, " [non-local]");
631 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
632 spaces of indent. FLAGS specifies details to show in the dump (see
633 TDF_* in tree-pass.h). */
635 static void
636 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
638 tree label = gimple_goto_dest (gs);
639 if (flags & TDF_RAW)
640 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
641 else
642 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
646 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
647 spaces of indent. FLAGS specifies details to show in the dump (see
648 TDF_* in tree-pass.h). */
650 static void
651 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
653 if (flags & TDF_RAW)
654 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
655 else
656 pp_character (buffer, '{');
657 if (!(flags & TDF_SLIM))
659 tree var;
661 for (var = gimple_bind_vars (gs); var; var = TREE_CHAIN (var))
663 newline_and_indent (buffer, 2);
664 print_declaration (buffer, var, spc, flags);
666 if (gimple_bind_vars (gs))
667 pp_newline (buffer);
669 pp_newline (buffer);
670 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
671 newline_and_indent (buffer, spc);
672 if (flags & TDF_RAW)
673 pp_character (buffer, '>');
674 else
675 pp_character (buffer, '}');
679 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
680 indent. FLAGS specifies details to show in the dump (see TDF_* in
681 tree-pass.h). */
683 static void
684 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
686 if (flags & TDF_RAW)
688 const char *type;
689 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
690 type = "GIMPLE_TRY_CATCH";
691 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
692 type = "GIMPLE_TRY_FINALLY";
693 else
694 type = "UNKNOWN GIMPLE_TRY";
695 dump_gimple_fmt (buffer, spc, flags,
696 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
697 gimple_try_eval (gs), gimple_try_cleanup (gs));
699 else
701 pp_string (buffer, "try");
702 newline_and_indent (buffer, spc + 2);
703 pp_character (buffer, '{');
704 pp_newline (buffer);
706 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
707 newline_and_indent (buffer, spc + 2);
708 pp_character (buffer, '}');
710 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
712 newline_and_indent (buffer, spc);
713 pp_string (buffer, "catch");
714 newline_and_indent (buffer, spc + 2);
715 pp_character (buffer, '{');
717 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
719 newline_and_indent (buffer, spc);
720 pp_string (buffer, "finally");
721 newline_and_indent (buffer, spc + 2);
722 pp_character (buffer, '{');
724 else
725 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
727 pp_newline (buffer);
728 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
729 newline_and_indent (buffer, spc + 2);
730 pp_character (buffer, '}');
735 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
736 indent. FLAGS specifies details to show in the dump (see TDF_* in
737 tree-pass.h). */
739 static void
740 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
742 if (flags & TDF_RAW)
743 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
744 gimple_catch_types (gs), gimple_catch_handler (gs));
745 else
746 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
747 gimple_catch_types (gs), gimple_catch_handler (gs));
751 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
752 indent. FLAGS specifies details to show in the dump (see TDF_* in
753 tree-pass.h). */
755 static void
756 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
758 if (flags & TDF_RAW)
759 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
760 gimple_eh_filter_types (gs),
761 gimple_eh_filter_failure (gs));
762 else
763 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
764 gimple_eh_filter_types (gs),
765 gimple_eh_filter_failure (gs));
769 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
770 indent. FLAGS specifies details to show in the dump (see TDF_* in
771 tree-pass.h). */
773 static void
774 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
776 if (flags & TDF_RAW)
777 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
778 gimple_resx_region (gs));
779 else
780 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
783 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
784 of indent. FLAGS specifies details to show in the dump (see TDF_*
785 in tree-pass.h). */
787 static void
788 dump_gimple_debug (pretty_printer *buffer, gimple gs, int spc, int flags)
790 switch (gs->gsbase.subcode)
792 case GIMPLE_DEBUG_BIND:
793 if (flags & TDF_RAW)
794 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
795 gimple_debug_bind_get_var (gs),
796 gimple_debug_bind_get_value (gs));
797 else
798 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
799 gimple_debug_bind_get_var (gs),
800 gimple_debug_bind_get_value (gs));
801 break;
803 default:
804 gcc_unreachable ();
808 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
809 static void
810 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
812 size_t i;
814 if (flags & TDF_RAW)
816 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
817 gimple_omp_body (gs));
818 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
819 dump_gimple_fmt (buffer, spc, flags, " >,");
820 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
821 dump_gimple_fmt (buffer, spc, flags,
822 "%+%T, %T, %T, %s, %T,%n",
823 gimple_omp_for_index (gs, i),
824 gimple_omp_for_initial (gs, i),
825 gimple_omp_for_final (gs, i),
826 tree_code_name[gimple_omp_for_cond (gs, i)],
827 gimple_omp_for_incr (gs, i));
828 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
829 gimple_omp_for_pre_body (gs));
831 else
833 pp_string (buffer, "#pragma omp for");
834 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
835 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
837 if (i)
838 spc += 2;
839 newline_and_indent (buffer, spc);
840 pp_string (buffer, "for (");
841 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
842 flags, false);
843 pp_string (buffer, " = ");
844 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
845 flags, false);
846 pp_string (buffer, "; ");
848 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
849 flags, false);
850 pp_space (buffer);
851 switch (gimple_omp_for_cond (gs, i))
853 case LT_EXPR:
854 pp_character (buffer, '<');
855 break;
856 case GT_EXPR:
857 pp_character (buffer, '>');
858 break;
859 case LE_EXPR:
860 pp_string (buffer, "<=");
861 break;
862 case GE_EXPR:
863 pp_string (buffer, ">=");
864 break;
865 default:
866 gcc_unreachable ();
868 pp_space (buffer);
869 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
870 flags, false);
871 pp_string (buffer, "; ");
873 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
874 flags, false);
875 pp_string (buffer, " = ");
876 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
877 flags, false);
878 pp_character (buffer, ')');
881 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
883 newline_and_indent (buffer, spc + 2);
884 pp_character (buffer, '{');
885 pp_newline (buffer);
886 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
887 newline_and_indent (buffer, spc + 2);
888 pp_character (buffer, '}');
893 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
895 static void
896 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
898 if (flags & TDF_RAW)
900 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
901 gimple_omp_continue_control_def (gs),
902 gimple_omp_continue_control_use (gs));
904 else
906 pp_string (buffer, "#pragma omp continue (");
907 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
908 spc, flags, false);
909 pp_character (buffer, ',');
910 pp_space (buffer);
911 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
912 spc, flags, false);
913 pp_character (buffer, ')');
917 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
919 static void
920 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
922 if (flags & TDF_RAW)
924 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
925 gimple_omp_body (gs));
926 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
927 dump_gimple_fmt (buffer, spc, flags, " >");
929 else
931 pp_string (buffer, "#pragma omp single");
932 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
933 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
935 newline_and_indent (buffer, spc + 2);
936 pp_character (buffer, '{');
937 pp_newline (buffer);
938 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
939 newline_and_indent (buffer, spc + 2);
940 pp_character (buffer, '}');
945 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
947 static void
948 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
949 int flags)
951 if (flags & TDF_RAW)
953 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
954 gimple_omp_body (gs));
955 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
956 dump_gimple_fmt (buffer, spc, flags, " >");
958 else
960 pp_string (buffer, "#pragma omp sections");
961 if (gimple_omp_sections_control (gs))
963 pp_string (buffer, " <");
964 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
965 flags, false);
966 pp_character (buffer, '>');
968 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
969 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
971 newline_and_indent (buffer, spc + 2);
972 pp_character (buffer, '{');
973 pp_newline (buffer);
974 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
975 newline_and_indent (buffer, spc + 2);
976 pp_character (buffer, '}');
981 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer
982 BUFFER. */
984 static void
985 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
987 if (flags & TDF_RAW)
988 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
989 gimple_omp_body (gs));
990 else
992 switch (gimple_code (gs))
994 case GIMPLE_OMP_MASTER:
995 pp_string (buffer, "#pragma omp master");
996 break;
997 case GIMPLE_OMP_ORDERED:
998 pp_string (buffer, "#pragma omp ordered");
999 break;
1000 case GIMPLE_OMP_SECTION:
1001 pp_string (buffer, "#pragma omp section");
1002 break;
1003 default:
1004 gcc_unreachable ();
1006 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1008 newline_and_indent (buffer, spc + 2);
1009 pp_character (buffer, '{');
1010 pp_newline (buffer);
1011 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1012 newline_and_indent (buffer, spc + 2);
1013 pp_character (buffer, '}');
1018 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1020 static void
1021 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
1022 int flags)
1024 if (flags & TDF_RAW)
1025 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1026 gimple_omp_body (gs));
1027 else
1029 pp_string (buffer, "#pragma omp critical");
1030 if (gimple_omp_critical_name (gs))
1032 pp_string (buffer, " (");
1033 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1034 flags, false);
1035 pp_character (buffer, ')');
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_RETURN tuple on the pretty_printer BUFFER. */
1051 static void
1052 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1054 if (flags & TDF_RAW)
1056 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d>", gs,
1057 (int) gimple_omp_return_nowait_p (gs));
1059 else
1061 pp_string (buffer, "#pragma omp return");
1062 if (gimple_omp_return_nowait_p (gs))
1063 pp_string (buffer, "(nowait)");
1067 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1068 indent. FLAGS specifies details to show in the dump (see TDF_* in
1069 tree-pass.h). */
1071 static void
1072 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1074 unsigned int i;
1076 if (flags & TDF_RAW)
1077 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1078 gimple_asm_string (gs));
1079 else
1081 pp_string (buffer, "__asm__");
1082 if (gimple_asm_volatile_p (gs))
1083 pp_string (buffer, " __volatile__");
1084 pp_string (buffer, "(\"");
1085 pp_string (buffer, gimple_asm_string (gs));
1086 pp_string (buffer, "\"");
1089 if (gimple_asm_ninputs (gs)
1090 || gimple_asm_noutputs (gs)
1091 || gimple_asm_nclobbers (gs))
1093 if (gimple_asm_noutputs (gs))
1095 if (flags & TDF_RAW)
1097 newline_and_indent (buffer, spc + 2);
1098 pp_string (buffer, "OUTPUT: ");
1100 else
1101 pp_string (buffer, " : ");
1104 for (i = 0; i < gimple_asm_noutputs (gs); i++)
1106 dump_generic_node (buffer, gimple_asm_output_op (gs, i), spc, flags,
1107 false);
1108 if ( i < gimple_asm_noutputs (gs) -1)
1109 pp_string (buffer, ", ");
1112 if (gimple_asm_ninputs (gs))
1114 if (flags & TDF_RAW)
1116 newline_and_indent (buffer, spc + 2);
1117 pp_string (buffer, "INPUT: ");
1119 else
1120 pp_string (buffer, " : ");
1123 for (i = 0; i < gimple_asm_ninputs (gs); i++)
1125 dump_generic_node (buffer, gimple_asm_input_op (gs, i), spc, flags,
1126 false);
1127 if (i < gimple_asm_ninputs (gs) -1)
1128 pp_string (buffer, " : ");
1131 if (gimple_asm_nclobbers (gs))
1133 if (flags & TDF_RAW)
1135 newline_and_indent (buffer, spc + 2);
1136 pp_string (buffer, "CLOBBER: ");
1138 else
1139 pp_string (buffer, " : ");
1142 for (i = 0; i < gimple_asm_nclobbers (gs); i++)
1144 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i), spc, flags,
1145 false);
1146 if ( i < gimple_asm_nclobbers (gs) -1)
1147 pp_string (buffer, ", ");
1150 if (flags & TDF_RAW)
1152 newline_and_indent (buffer, spc);
1153 pp_character (buffer, '>');
1155 else
1156 pp_string (buffer, ");");
1160 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in
1161 dump_gimple_stmt. */
1163 static void
1164 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
1166 size_t i;
1168 if (flags & TDF_RAW)
1169 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1170 gimple_phi_result (phi));
1171 else
1173 dump_generic_node (buffer, gimple_phi_result (phi), spc, flags, false);
1174 pp_string (buffer, " = PHI <");
1176 for (i = 0; i < gimple_phi_num_args (phi); i++)
1178 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1180 expanded_location xloc;
1182 xloc = expand_location (gimple_phi_arg_location (phi, i));
1183 pp_character (buffer, '[');
1184 if (xloc.file)
1186 pp_string (buffer, xloc.file);
1187 pp_string (buffer, " : ");
1189 pp_decimal_int (buffer, xloc.line);
1190 pp_string (buffer, ":");
1191 pp_decimal_int (buffer, xloc.column);
1192 pp_string (buffer, "] ");
1194 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1195 false);
1196 pp_character (buffer, '(');
1197 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1198 pp_character (buffer, ')');
1199 if (i < gimple_phi_num_args (phi) - 1)
1200 pp_string (buffer, ", ");
1202 pp_character (buffer, '>');
1206 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1207 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1208 tree-pass.h). */
1210 static void
1211 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1212 int flags)
1214 if (flags & TDF_RAW)
1216 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1217 gimple_omp_body (gs));
1218 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1219 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1220 gimple_omp_parallel_child_fn (gs),
1221 gimple_omp_parallel_data_arg (gs));
1223 else
1225 gimple_seq body;
1226 pp_string (buffer, "#pragma omp parallel");
1227 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1228 if (gimple_omp_parallel_child_fn (gs))
1230 pp_string (buffer, " [child fn: ");
1231 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1232 spc, flags, false);
1233 pp_string (buffer, " (");
1234 if (gimple_omp_parallel_data_arg (gs))
1235 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1236 spc, flags, false);
1237 else
1238 pp_string (buffer, "???");
1239 pp_string (buffer, ")]");
1241 body = gimple_omp_body (gs);
1242 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1244 newline_and_indent (buffer, spc + 2);
1245 pp_character (buffer, '{');
1246 pp_newline (buffer);
1247 dump_gimple_seq (buffer, body, spc + 4, flags);
1248 newline_and_indent (buffer, spc + 2);
1249 pp_character (buffer, '}');
1251 else if (body)
1253 pp_newline (buffer);
1254 dump_gimple_seq (buffer, body, spc + 2, flags);
1260 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1261 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1262 tree-pass.h). */
1264 static void
1265 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1266 int flags)
1268 if (flags & TDF_RAW)
1270 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1271 gimple_omp_body (gs));
1272 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1273 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1274 gimple_omp_task_child_fn (gs),
1275 gimple_omp_task_data_arg (gs),
1276 gimple_omp_task_copy_fn (gs),
1277 gimple_omp_task_arg_size (gs),
1278 gimple_omp_task_arg_size (gs));
1280 else
1282 gimple_seq body;
1283 pp_string (buffer, "#pragma omp task");
1284 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1285 if (gimple_omp_task_child_fn (gs))
1287 pp_string (buffer, " [child fn: ");
1288 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1289 spc, flags, false);
1290 pp_string (buffer, " (");
1291 if (gimple_omp_task_data_arg (gs))
1292 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1293 spc, flags, false);
1294 else
1295 pp_string (buffer, "???");
1296 pp_string (buffer, ")]");
1298 body = gimple_omp_body (gs);
1299 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1301 newline_and_indent (buffer, spc + 2);
1302 pp_character (buffer, '{');
1303 pp_newline (buffer);
1304 dump_gimple_seq (buffer, body, spc + 4, flags);
1305 newline_and_indent (buffer, spc + 2);
1306 pp_character (buffer, '}');
1308 else if (body)
1310 pp_newline (buffer);
1311 dump_gimple_seq (buffer, body, spc + 2, flags);
1317 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1318 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1319 in tree-pass.h). */
1321 static void
1322 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1323 int flags)
1325 if (flags & TDF_RAW)
1327 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1328 gimple_omp_atomic_load_lhs (gs),
1329 gimple_omp_atomic_load_rhs (gs));
1331 else
1333 pp_string (buffer, "#pragma omp atomic_load");
1334 newline_and_indent (buffer, spc + 2);
1335 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1336 spc, flags, false);
1337 pp_space (buffer);
1338 pp_character (buffer, '=');
1339 pp_space (buffer);
1340 pp_character (buffer, '*');
1341 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1342 spc, flags, false);
1346 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1347 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1348 in tree-pass.h). */
1350 static void
1351 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
1352 int flags)
1354 if (flags & TDF_RAW)
1356 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1357 gimple_omp_atomic_store_val (gs));
1359 else
1361 pp_string (buffer, "#pragma omp atomic_store (");
1362 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
1363 spc, flags, false);
1364 pp_character (buffer, ')');
1369 /* Dump all the memory operands for statement GS. BUFFER, SPC and
1370 FLAGS are as in dump_gimple_stmt. */
1372 static void
1373 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
1375 tree vdef = gimple_vdef (gs);
1376 tree vuse = gimple_vuse (gs);
1378 if (!ssa_operands_active () || !gimple_references_memory_p (gs))
1379 return;
1381 if (vdef != NULL_TREE)
1383 pp_string (buffer, "# ");
1384 dump_generic_node (buffer, vdef, spc + 2, flags, false);
1385 pp_string (buffer, " = VDEF <");
1386 dump_generic_node (buffer, vuse, spc + 2, flags, false);
1387 pp_character (buffer, '>');
1388 newline_and_indent (buffer, spc);
1390 else if (vuse != NULL_TREE)
1392 pp_string (buffer, "# VUSE <");
1393 dump_generic_node (buffer, vuse, spc + 2, flags, false);
1394 pp_character (buffer, '>');
1395 newline_and_indent (buffer, spc);
1400 /* Dump the gimple statement GS on the pretty printer BUFFER, SPC
1401 spaces of indent. FLAGS specifies details to show in the dump (see
1402 TDF_* in tree-pass.h). */
1404 void
1405 dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags)
1407 if (!gs)
1408 return;
1410 if (flags & TDF_STMTADDR)
1411 pp_printf (buffer, "<&%p> ", (void *) gs);
1413 if ((flags & TDF_LINENO) && gimple_has_location (gs))
1415 expanded_location xloc = expand_location (gimple_location (gs));
1416 pp_character (buffer, '[');
1417 if (xloc.file)
1419 pp_string (buffer, xloc.file);
1420 pp_string (buffer, " : ");
1422 pp_decimal_int (buffer, xloc.line);
1423 pp_string (buffer, ":");
1424 pp_decimal_int (buffer, xloc.column);
1425 pp_string (buffer, "] ");
1428 if (flags & TDF_EH)
1430 int eh_region = lookup_stmt_eh_region_fn (cfun, gs);
1431 if (eh_region >= 0)
1432 pp_printf (buffer, "[EH #%d] ", eh_region);
1435 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
1436 && gimple_has_mem_ops (gs))
1437 dump_gimple_mem_ops (buffer, gs, spc, flags);
1439 switch (gimple_code (gs))
1441 case GIMPLE_ASM:
1442 dump_gimple_asm (buffer, gs, spc, flags);
1443 break;
1445 case GIMPLE_ASSIGN:
1446 dump_gimple_assign (buffer, gs, spc, flags);
1447 break;
1449 case GIMPLE_BIND:
1450 dump_gimple_bind (buffer, gs, spc, flags);
1451 break;
1453 case GIMPLE_CALL:
1454 dump_gimple_call (buffer, gs, spc, flags);
1455 break;
1457 case GIMPLE_COND:
1458 dump_gimple_cond (buffer, gs, spc, flags);
1459 break;
1461 case GIMPLE_LABEL:
1462 dump_gimple_label (buffer, gs, spc, flags);
1463 break;
1465 case GIMPLE_GOTO:
1466 dump_gimple_goto (buffer, gs, spc, flags);
1467 break;
1469 case GIMPLE_NOP:
1470 pp_string (buffer, "GIMPLE_NOP");
1471 break;
1473 case GIMPLE_RETURN:
1474 dump_gimple_return (buffer, gs, spc, flags);
1475 break;
1477 case GIMPLE_SWITCH:
1478 dump_gimple_switch (buffer, gs, spc, flags);
1479 break;
1481 case GIMPLE_TRY:
1482 dump_gimple_try (buffer, gs, spc, flags);
1483 break;
1485 case GIMPLE_PHI:
1486 dump_gimple_phi (buffer, gs, spc, flags);
1487 break;
1489 case GIMPLE_OMP_PARALLEL:
1490 dump_gimple_omp_parallel (buffer, gs, spc, flags);
1491 break;
1493 case GIMPLE_OMP_TASK:
1494 dump_gimple_omp_task (buffer, gs, spc, flags);
1495 break;
1497 case GIMPLE_OMP_ATOMIC_LOAD:
1498 dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
1500 break;
1502 case GIMPLE_OMP_ATOMIC_STORE:
1503 dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
1504 break;
1506 case GIMPLE_OMP_FOR:
1507 dump_gimple_omp_for (buffer, gs, spc, flags);
1508 break;
1510 case GIMPLE_OMP_CONTINUE:
1511 dump_gimple_omp_continue (buffer, gs, spc, flags);
1512 break;
1514 case GIMPLE_OMP_SINGLE:
1515 dump_gimple_omp_single (buffer, gs, spc, flags);
1516 break;
1518 case GIMPLE_OMP_RETURN:
1519 dump_gimple_omp_return (buffer, gs, spc, flags);
1520 break;
1522 case GIMPLE_OMP_SECTIONS:
1523 dump_gimple_omp_sections (buffer, gs, spc, flags);
1524 break;
1526 case GIMPLE_OMP_SECTIONS_SWITCH:
1527 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
1528 break;
1530 case GIMPLE_OMP_MASTER:
1531 case GIMPLE_OMP_ORDERED:
1532 case GIMPLE_OMP_SECTION:
1533 dump_gimple_omp_block (buffer, gs, spc, flags);
1534 break;
1536 case GIMPLE_OMP_CRITICAL:
1537 dump_gimple_omp_critical (buffer, gs, spc, flags);
1538 break;
1540 case GIMPLE_CATCH:
1541 dump_gimple_catch (buffer, gs, spc, flags);
1542 break;
1544 case GIMPLE_EH_FILTER:
1545 dump_gimple_eh_filter (buffer, gs, spc, flags);
1546 break;
1548 case GIMPLE_RESX:
1549 dump_gimple_resx (buffer, gs, spc, flags);
1550 break;
1552 case GIMPLE_DEBUG:
1553 dump_gimple_debug (buffer, gs, spc, flags);
1554 break;
1556 case GIMPLE_PREDICT:
1557 pp_string (buffer, "// predicted ");
1558 if (gimple_predict_outcome (gs))
1559 pp_string (buffer, "likely by ");
1560 else
1561 pp_string (buffer, "unlikely by ");
1562 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
1563 pp_string (buffer, " predictor.");
1564 break;
1566 default:
1567 GIMPLE_NIY;
1570 /* If we're building a diagnostic, the formatted text will be
1571 written into BUFFER's stream by the caller; otherwise, write it
1572 now. */
1573 if (!(flags & TDF_DIAGNOSTIC))
1574 pp_write_text_to_stream (buffer);
1578 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
1579 spaces and details described by flags. */
1581 static void
1582 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
1584 edge e;
1585 gimple stmt;
1586 edge_iterator ei;
1588 if (flags & TDF_BLOCKS)
1590 INDENT (indent);
1591 pp_string (buffer, "# BLOCK ");
1592 pp_decimal_int (buffer, bb->index);
1593 if (bb->frequency)
1595 pp_string (buffer, " freq:");
1596 pp_decimal_int (buffer, bb->frequency);
1598 if (bb->count)
1600 pp_string (buffer, " count:");
1601 pp_widest_integer (buffer, bb->count);
1604 if (flags & TDF_LINENO)
1606 gimple_stmt_iterator gsi;
1608 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1609 if (!is_gimple_debug (gsi_stmt (gsi))
1610 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
1612 pp_string (buffer, ", starting at line ");
1613 pp_decimal_int (buffer, get_lineno (gsi_stmt (gsi)));
1614 break;
1617 if (bb->discriminator)
1619 pp_string (buffer, ", discriminator ");
1620 pp_decimal_int (buffer, bb->discriminator);
1623 newline_and_indent (buffer, indent);
1625 pp_string (buffer, "# PRED:");
1626 pp_write_text_to_stream (buffer);
1627 FOR_EACH_EDGE (e, ei, bb->preds)
1628 if (flags & TDF_SLIM)
1630 pp_character (buffer, ' ');
1631 if (e->src == ENTRY_BLOCK_PTR)
1632 pp_string (buffer, "ENTRY");
1633 else
1634 pp_decimal_int (buffer, e->src->index);
1636 else
1637 dump_edge_info (buffer->buffer->stream, e, 0);
1638 pp_newline (buffer);
1640 else
1642 stmt = first_stmt (bb);
1643 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
1645 INDENT (indent - 2);
1646 pp_string (buffer, "<bb ");
1647 pp_decimal_int (buffer, bb->index);
1648 pp_string (buffer, ">:");
1649 pp_newline (buffer);
1652 pp_write_text_to_stream (buffer);
1653 check_bb_profile (bb, buffer->buffer->stream);
1657 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
1658 spaces. */
1660 static void
1661 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
1663 edge e;
1664 edge_iterator ei;
1666 INDENT (indent);
1667 pp_string (buffer, "# SUCC:");
1668 pp_write_text_to_stream (buffer);
1669 FOR_EACH_EDGE (e, ei, bb->succs)
1670 if (flags & TDF_SLIM)
1672 pp_character (buffer, ' ');
1673 if (e->dest == EXIT_BLOCK_PTR)
1674 pp_string (buffer, "EXIT");
1675 else
1676 pp_decimal_int (buffer, e->dest->index);
1678 else
1679 dump_edge_info (buffer->buffer->stream, e, 1);
1680 pp_newline (buffer);
1684 /* Dump PHI nodes of basic block BB to BUFFER with details described
1685 by FLAGS and indented by INDENT spaces. */
1687 static void
1688 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
1690 gimple_stmt_iterator i;
1692 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
1694 gimple phi = gsi_stmt (i);
1695 if (is_gimple_reg (gimple_phi_result (phi)) || (flags & TDF_VOPS))
1697 INDENT (indent);
1698 pp_string (buffer, "# ");
1699 dump_gimple_phi (buffer, phi, indent, flags);
1700 pp_newline (buffer);
1706 /* Dump jump to basic block BB that is represented implicitly in the cfg
1707 to BUFFER. */
1709 static void
1710 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
1712 gimple stmt;
1714 stmt = first_stmt (bb);
1716 pp_string (buffer, "goto <bb ");
1717 pp_decimal_int (buffer, bb->index);
1718 pp_character (buffer, '>');
1719 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
1721 pp_string (buffer, " (");
1722 dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
1723 pp_character (buffer, ')');
1724 pp_semicolon (buffer);
1726 else
1727 pp_semicolon (buffer);
1731 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
1732 by INDENT spaces, with details given by FLAGS. */
1734 static void
1735 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
1736 int flags)
1738 edge e;
1739 edge_iterator ei;
1740 gimple stmt;
1742 stmt = last_stmt (bb);
1744 if (stmt && gimple_code (stmt) == GIMPLE_COND)
1746 edge true_edge, false_edge;
1748 /* When we are emitting the code or changing CFG, it is possible that
1749 the edges are not yet created. When we are using debug_bb in such
1750 a situation, we do not want it to crash. */
1751 if (EDGE_COUNT (bb->succs) != 2)
1752 return;
1753 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
1755 INDENT (indent + 2);
1756 pp_cfg_jump (buffer, true_edge->dest);
1757 newline_and_indent (buffer, indent);
1758 pp_string (buffer, "else");
1759 newline_and_indent (buffer, indent + 2);
1760 pp_cfg_jump (buffer, false_edge->dest);
1761 pp_newline (buffer);
1762 return;
1765 /* If there is a fallthru edge, we may need to add an artificial
1766 goto to the dump. */
1767 FOR_EACH_EDGE (e, ei, bb->succs)
1768 if (e->flags & EDGE_FALLTHRU)
1769 break;
1771 if (e && e->dest != bb->next_bb)
1773 INDENT (indent);
1775 if ((flags & TDF_LINENO)
1776 && e->goto_locus != UNKNOWN_LOCATION
1779 expanded_location goto_xloc;
1780 goto_xloc = expand_location (e->goto_locus);
1781 pp_character (buffer, '[');
1782 if (goto_xloc.file)
1784 pp_string (buffer, goto_xloc.file);
1785 pp_string (buffer, " : ");
1787 pp_decimal_int (buffer, goto_xloc.line);
1788 pp_string (buffer, " : ");
1789 pp_decimal_int (buffer, goto_xloc.column);
1790 pp_string (buffer, "] ");
1793 pp_cfg_jump (buffer, e->dest);
1794 pp_newline (buffer);
1799 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
1800 indented by INDENT spaces. */
1802 static void
1803 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
1804 int flags)
1806 gimple_stmt_iterator gsi;
1807 gimple stmt;
1808 int label_indent = indent - 2;
1810 if (label_indent < 0)
1811 label_indent = 0;
1813 dump_bb_header (buffer, bb, indent, flags);
1814 dump_phi_nodes (buffer, bb, indent, flags);
1816 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1818 int curr_indent;
1820 stmt = gsi_stmt (gsi);
1822 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
1824 INDENT (curr_indent);
1825 dump_gimple_stmt (buffer, stmt, curr_indent, flags);
1826 pp_newline (buffer);
1827 dump_histograms_for_stmt (cfun, buffer->buffer->stream, stmt);
1830 dump_implicit_edges (buffer, bb, indent, flags);
1832 if (flags & TDF_BLOCKS)
1833 dump_bb_end (buffer, bb, indent, flags);
1837 /* Dumps basic block BB to FILE with details described by FLAGS and
1838 indented by INDENT spaces. */
1840 void
1841 gimple_dump_bb (basic_block bb, FILE *file, int indent, int flags)
1843 maybe_init_pretty_print (file);
1844 gimple_dump_bb_buff (&buffer, bb, indent, flags);
1845 pp_flush (&buffer);