2009-03-05 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / gcc / gimple-pretty-print.c
blobde1d3ea062cd8c04c82dfc7a88ef76c8ef17b1c1
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 if (rhs_code == NEGATENV_EXPR)
303 pp_string (buffer, "-/nv");
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);
381 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
382 dump_gimple_stmt. */
384 static void
385 dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
387 if (flags & TDF_RAW)
389 tree last;
390 if (gimple_num_ops (gs) == 2)
391 last = NULL_TREE;
392 else if (gimple_num_ops (gs) == 3)
393 last = gimple_assign_rhs2 (gs);
394 else
395 gcc_unreachable ();
397 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T>", gs,
398 tree_code_name[gimple_assign_rhs_code (gs)],
399 gimple_assign_lhs (gs), gimple_assign_rhs1 (gs), last);
401 else
403 if (!(flags & TDF_RHS_ONLY))
405 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
406 pp_space (buffer);
407 pp_character (buffer, '=');
409 if (gimple_assign_nontemporal_move_p (gs))
410 pp_string (buffer, "{nt}");
412 if (gimple_has_volatile_ops (gs))
413 pp_string (buffer, "{v}");
415 pp_space (buffer);
418 if (gimple_num_ops (gs) == 2)
419 dump_unary_rhs (buffer, gs, spc, flags);
420 else if (gimple_num_ops (gs) == 3)
421 dump_binary_rhs (buffer, gs, spc, flags);
422 else
423 gcc_unreachable ();
424 if (!(flags & TDF_RHS_ONLY))
425 pp_semicolon(buffer);
430 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
431 dump_gimple_stmt. */
433 static void
434 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
436 tree t;
438 t = gimple_return_retval (gs);
439 if (flags & TDF_RAW)
440 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
441 else
443 pp_string (buffer, "return");
444 if (t)
446 pp_space (buffer);
447 dump_generic_node (buffer, t, spc, flags, false);
449 pp_semicolon (buffer);
454 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
455 dump_gimple_call. */
457 static void
458 dump_gimple_call_args (pretty_printer *buffer, gimple gs, int flags)
460 size_t i;
462 for (i = 0; i < gimple_call_num_args (gs); i++)
464 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
465 if (i < gimple_call_num_args (gs) - 1)
466 pp_string (buffer, ", ");
469 if (gimple_call_va_arg_pack_p (gs))
471 if (gimple_call_num_args (gs) > 0)
473 pp_character (buffer, ',');
474 pp_space (buffer);
477 pp_string (buffer, "__builtin_va_arg_pack ()");
482 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
483 dump_gimple_stmt. */
485 static void
486 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
488 tree lhs = gimple_call_lhs (gs);
490 if (flags & TDF_RAW)
492 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T",
493 gs, gimple_call_fn (gs), lhs);
494 if (gimple_call_num_args (gs) > 0)
496 pp_string (buffer, ", ");
497 dump_gimple_call_args (buffer, gs, flags);
499 pp_character (buffer, '>');
501 else
503 if (lhs && !(flags & TDF_RHS_ONLY))
505 dump_generic_node (buffer, lhs, spc, flags, false);
506 pp_string (buffer, " =");
508 if (gimple_has_volatile_ops (gs))
509 pp_string (buffer, "{v}");
511 pp_space (buffer);
513 dump_generic_node (buffer, gimple_call_fn (gs), spc, flags, false);
514 pp_string (buffer, " (");
515 dump_gimple_call_args (buffer, gs, flags);
516 pp_character (buffer, ')');
517 if (!(flags & TDF_RHS_ONLY))
518 pp_semicolon (buffer);
521 if (gimple_call_chain (gs))
523 pp_string (buffer, " [static-chain: ");
524 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
525 pp_character (buffer, ']');
528 if (gimple_call_return_slot_opt_p (gs))
529 pp_string (buffer, " [return slot optimization]");
531 if (gimple_call_tail_p (gs))
532 pp_string (buffer, " [tail call]");
536 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
537 dump_gimple_stmt. */
539 static void
540 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
542 unsigned int i;
544 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
545 if (flags & TDF_RAW)
546 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
547 gimple_switch_index (gs));
548 else
550 pp_string (buffer, "switch (");
551 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
552 pp_string (buffer, ") <");
555 for (i = 0; i < gimple_switch_num_labels (gs); i++)
557 tree case_label = gimple_switch_label (gs, i);
558 if (case_label == NULL_TREE)
559 continue;
561 dump_generic_node (buffer, case_label, spc, flags, false);
562 pp_character (buffer, ' ');
563 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
564 if (i < gimple_switch_num_labels (gs) - 1)
565 pp_string (buffer, ", ");
567 pp_character (buffer, '>');
571 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
572 dump_gimple_stmt. */
574 static void
575 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
577 if (flags & TDF_RAW)
578 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
579 tree_code_name [gimple_cond_code (gs)],
580 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
581 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
582 else
584 if (!(flags & TDF_RHS_ONLY))
585 pp_string (buffer, "if (");
586 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
587 pp_space (buffer);
588 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
589 pp_space (buffer);
590 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
591 if (!(flags & TDF_RHS_ONLY))
593 pp_character (buffer, ')');
595 if (gimple_cond_true_label (gs))
597 pp_string (buffer, " goto ");
598 dump_generic_node (buffer, gimple_cond_true_label (gs),
599 spc, flags, false);
600 pp_semicolon (buffer);
602 if (gimple_cond_false_label (gs))
604 pp_string (buffer, " else goto ");
605 dump_generic_node (buffer, gimple_cond_false_label (gs),
606 spc, flags, false);
607 pp_semicolon (buffer);
614 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
615 spaces of indent. FLAGS specifies details to show in the dump (see
616 TDF_* in tree-pass.h). */
618 static void
619 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
621 tree label = gimple_label_label (gs);
622 if (flags & TDF_RAW)
623 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
624 else
626 dump_generic_node (buffer, label, spc, flags, false);
627 pp_character (buffer, ':');
629 if (DECL_NONLOCAL (label))
630 pp_string (buffer, " [non-local]");
633 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
634 spaces of indent. FLAGS specifies details to show in the dump (see
635 TDF_* in tree-pass.h). */
637 static void
638 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
640 tree label = gimple_goto_dest (gs);
641 if (flags & TDF_RAW)
642 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
643 else
644 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
648 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
649 spaces of indent. FLAGS specifies details to show in the dump (see
650 TDF_* in tree-pass.h). */
652 static void
653 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
655 if (flags & TDF_RAW)
656 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
657 else
658 pp_character (buffer, '{');
659 if (!(flags & TDF_SLIM))
661 tree var;
663 for (var = gimple_bind_vars (gs); var; var = TREE_CHAIN (var))
665 newline_and_indent (buffer, 2);
666 print_declaration (buffer, var, spc, flags);
668 if (gimple_bind_vars (gs))
669 pp_newline (buffer);
671 pp_newline (buffer);
672 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
673 newline_and_indent (buffer, spc);
674 if (flags & TDF_RAW)
675 pp_character (buffer, '>');
676 else
677 pp_character (buffer, '}');
681 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
682 indent. FLAGS specifies details to show in the dump (see TDF_* in
683 tree-pass.h). */
685 static void
686 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
688 if (flags & TDF_RAW)
690 const char *type;
691 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
692 type = "GIMPLE_TRY_CATCH";
693 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
694 type = "GIMPLE_TRY_FINALLY";
695 else
696 type = "UNKNOWN GIMPLE_TRY";
697 dump_gimple_fmt (buffer, spc, flags,
698 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
699 gimple_try_eval (gs), gimple_try_cleanup (gs));
701 else
703 pp_string (buffer, "try");
704 newline_and_indent (buffer, spc + 2);
705 pp_character (buffer, '{');
706 pp_newline (buffer);
708 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
709 newline_and_indent (buffer, spc + 2);
710 pp_character (buffer, '}');
712 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
714 newline_and_indent (buffer, spc);
715 pp_string (buffer, "catch");
716 newline_and_indent (buffer, spc + 2);
717 pp_character (buffer, '{');
719 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
721 newline_and_indent (buffer, spc);
722 pp_string (buffer, "finally");
723 newline_and_indent (buffer, spc + 2);
724 pp_character (buffer, '{');
726 else
727 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
729 pp_newline (buffer);
730 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
731 newline_and_indent (buffer, spc + 2);
732 pp_character (buffer, '}');
737 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
738 indent. FLAGS specifies details to show in the dump (see TDF_* in
739 tree-pass.h). */
741 static void
742 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
744 if (flags & TDF_RAW)
745 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
746 gimple_catch_types (gs), gimple_catch_handler (gs));
747 else
748 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
749 gimple_catch_types (gs), gimple_catch_handler (gs));
753 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
754 indent. FLAGS specifies details to show in the dump (see TDF_* in
755 tree-pass.h). */
757 static void
758 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
760 if (flags & TDF_RAW)
761 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
762 gimple_eh_filter_types (gs),
763 gimple_eh_filter_failure (gs));
764 else
765 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
766 gimple_eh_filter_types (gs),
767 gimple_eh_filter_failure (gs));
771 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
772 indent. FLAGS specifies details to show in the dump (see TDF_* in
773 tree-pass.h). */
775 static void
776 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
778 if (flags & TDF_RAW)
779 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
780 gimple_resx_region (gs));
781 else
782 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
785 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
786 static void
787 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
789 size_t i;
791 if (flags & TDF_RAW)
793 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
794 gimple_omp_body (gs));
795 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
796 dump_gimple_fmt (buffer, spc, flags, " >,");
797 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
798 dump_gimple_fmt (buffer, spc, flags,
799 "%+%T, %T, %T, %s, %T,%n",
800 gimple_omp_for_index (gs, i),
801 gimple_omp_for_initial (gs, i),
802 gimple_omp_for_final (gs, i),
803 tree_code_name[gimple_omp_for_cond (gs, i)],
804 gimple_omp_for_incr (gs, i));
805 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
806 gimple_omp_for_pre_body (gs));
808 else
810 pp_string (buffer, "#pragma omp for");
811 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
812 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
814 if (i)
815 spc += 2;
816 newline_and_indent (buffer, spc);
817 pp_string (buffer, "for (");
818 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
819 flags, false);
820 pp_string (buffer, " = ");
821 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
822 flags, false);
823 pp_string (buffer, "; ");
825 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
826 flags, false);
827 pp_space (buffer);
828 switch (gimple_omp_for_cond (gs, i))
830 case LT_EXPR:
831 pp_character (buffer, '<');
832 break;
833 case GT_EXPR:
834 pp_character (buffer, '>');
835 break;
836 case LE_EXPR:
837 pp_string (buffer, "<=");
838 break;
839 case GE_EXPR:
840 pp_string (buffer, ">=");
841 break;
842 default:
843 gcc_unreachable ();
845 pp_space (buffer);
846 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
847 flags, false);
848 pp_string (buffer, "; ");
850 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
851 flags, false);
852 pp_string (buffer, " = ");
853 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
854 flags, false);
855 pp_character (buffer, ')');
858 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
860 newline_and_indent (buffer, spc + 2);
861 pp_character (buffer, '{');
862 pp_newline (buffer);
863 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
864 newline_and_indent (buffer, spc + 2);
865 pp_character (buffer, '}');
870 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
872 static void
873 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
875 if (flags & TDF_RAW)
877 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
878 gimple_omp_continue_control_def (gs),
879 gimple_omp_continue_control_use (gs));
881 else
883 pp_string (buffer, "#pragma omp continue (");
884 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
885 spc, flags, false);
886 pp_character (buffer, ',');
887 pp_space (buffer);
888 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
889 spc, flags, false);
890 pp_character (buffer, ')');
894 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
896 static void
897 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
899 if (flags & TDF_RAW)
901 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
902 gimple_omp_body (gs));
903 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
904 dump_gimple_fmt (buffer, spc, flags, " >");
906 else
908 pp_string (buffer, "#pragma omp single");
909 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
910 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
912 newline_and_indent (buffer, spc + 2);
913 pp_character (buffer, '{');
914 pp_newline (buffer);
915 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
916 newline_and_indent (buffer, spc + 2);
917 pp_character (buffer, '}');
922 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
924 static void
925 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
926 int flags)
928 if (flags & TDF_RAW)
930 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
931 gimple_omp_body (gs));
932 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
933 dump_gimple_fmt (buffer, spc, flags, " >");
935 else
937 pp_string (buffer, "#pragma omp sections");
938 if (gimple_omp_sections_control (gs))
940 pp_string (buffer, " <");
941 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
942 flags, false);
943 pp_character (buffer, '>');
945 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
946 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
948 newline_and_indent (buffer, spc + 2);
949 pp_character (buffer, '{');
950 pp_newline (buffer);
951 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
952 newline_and_indent (buffer, spc + 2);
953 pp_character (buffer, '}');
958 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer
959 BUFFER. */
961 static void
962 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
964 if (flags & TDF_RAW)
965 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
966 gimple_omp_body (gs));
967 else
969 switch (gimple_code (gs))
971 case GIMPLE_OMP_MASTER:
972 pp_string (buffer, "#pragma omp master");
973 break;
974 case GIMPLE_OMP_ORDERED:
975 pp_string (buffer, "#pragma omp ordered");
976 break;
977 case GIMPLE_OMP_SECTION:
978 pp_string (buffer, "#pragma omp section");
979 break;
980 default:
981 gcc_unreachable ();
983 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
985 newline_and_indent (buffer, spc + 2);
986 pp_character (buffer, '{');
987 pp_newline (buffer);
988 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
989 newline_and_indent (buffer, spc + 2);
990 pp_character (buffer, '}');
995 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
997 static void
998 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
999 int flags)
1001 if (flags & TDF_RAW)
1002 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1003 gimple_omp_body (gs));
1004 else
1006 pp_string (buffer, "#pragma omp critical");
1007 if (gimple_omp_critical_name (gs))
1009 pp_string (buffer, " (");
1010 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1011 flags, false);
1012 pp_character (buffer, ')');
1014 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1016 newline_and_indent (buffer, spc + 2);
1017 pp_character (buffer, '{');
1018 pp_newline (buffer);
1019 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1020 newline_and_indent (buffer, spc + 2);
1021 pp_character (buffer, '}');
1026 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1028 static void
1029 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1031 if (flags & TDF_RAW)
1033 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d>", gs,
1034 (int) gimple_omp_return_nowait_p (gs));
1036 else
1038 pp_string (buffer, "#pragma omp return");
1039 if (gimple_omp_return_nowait_p (gs))
1040 pp_string (buffer, "(nowait)");
1044 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1045 indent. FLAGS specifies details to show in the dump (see TDF_* in
1046 tree-pass.h). */
1048 static void
1049 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1051 unsigned int i;
1053 if (flags & TDF_RAW)
1054 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1055 gimple_asm_string (gs));
1056 else
1058 pp_string (buffer, "__asm__");
1059 if (gimple_asm_volatile_p (gs))
1060 pp_string (buffer, " __volatile__");
1061 pp_string (buffer, "(\"");
1062 pp_string (buffer, gimple_asm_string (gs));
1063 pp_string (buffer, "\"");
1066 if (gimple_asm_ninputs (gs)
1067 || gimple_asm_noutputs (gs)
1068 || gimple_asm_nclobbers (gs))
1070 if (gimple_asm_noutputs (gs))
1072 if (flags & TDF_RAW)
1074 newline_and_indent (buffer, spc + 2);
1075 pp_string (buffer, "OUTPUT: ");
1077 else
1078 pp_string (buffer, " : ");
1081 for (i = 0; i < gimple_asm_noutputs (gs); i++)
1083 dump_generic_node (buffer, gimple_asm_output_op (gs, i), spc, flags,
1084 false);
1085 if ( i < gimple_asm_noutputs (gs) -1)
1086 pp_string (buffer, ", ");
1089 if (gimple_asm_ninputs (gs))
1091 if (flags & TDF_RAW)
1093 newline_and_indent (buffer, spc + 2);
1094 pp_string (buffer, "INPUT: ");
1096 else
1097 pp_string (buffer, " : ");
1100 for (i = 0; i < gimple_asm_ninputs (gs); i++)
1102 dump_generic_node (buffer, gimple_asm_input_op (gs, i), spc, flags,
1103 false);
1104 if (i < gimple_asm_ninputs (gs) -1)
1105 pp_string (buffer, " : ");
1108 if (gimple_asm_nclobbers (gs))
1110 if (flags & TDF_RAW)
1112 newline_and_indent (buffer, spc + 2);
1113 pp_string (buffer, "CLOBBER: ");
1115 else
1116 pp_string (buffer, " : ");
1119 for (i = 0; i < gimple_asm_nclobbers (gs); i++)
1121 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i), spc, flags,
1122 false);
1123 if ( i < gimple_asm_nclobbers (gs) -1)
1124 pp_string (buffer, ", ");
1127 if (flags & TDF_RAW)
1129 newline_and_indent (buffer, spc);
1130 pp_character (buffer, '>');
1132 else
1133 pp_string (buffer, ");");
1137 /* Dump the set of decls SYMS. BUFFER, SPC and FLAGS are as in
1138 dump_generic_node. */
1140 static void
1141 dump_symbols (pretty_printer *buffer, bitmap syms, int flags)
1143 unsigned i;
1144 bitmap_iterator bi;
1146 if (syms == NULL)
1147 pp_string (buffer, "NIL");
1148 else
1150 pp_string (buffer, " { ");
1152 EXECUTE_IF_SET_IN_BITMAP (syms, 0, i, bi)
1154 tree sym = referenced_var_lookup (i);
1155 dump_generic_node (buffer, sym, 0, flags, false);
1156 pp_character (buffer, ' ');
1159 pp_character (buffer, '}');
1164 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in
1165 dump_gimple_stmt. */
1167 static void
1168 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
1170 size_t i;
1172 if (flags & TDF_RAW)
1173 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1174 gimple_phi_result (phi));
1175 else
1177 dump_generic_node (buffer, gimple_phi_result (phi), spc, flags, false);
1178 pp_string (buffer, " = PHI <");
1180 for (i = 0; i < gimple_phi_num_args (phi); i++)
1182 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1183 false);
1184 pp_character (buffer, '(');
1185 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1186 pp_character (buffer, ')');
1187 if (i < gimple_phi_num_args (phi) - 1)
1188 pp_string (buffer, ", ");
1190 pp_character (buffer, '>');
1194 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1195 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1196 tree-pass.h). */
1198 static void
1199 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1200 int flags)
1202 if (flags & TDF_RAW)
1204 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1205 gimple_omp_body (gs));
1206 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1207 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1208 gimple_omp_parallel_child_fn (gs),
1209 gimple_omp_parallel_data_arg (gs));
1211 else
1213 gimple_seq body;
1214 pp_string (buffer, "#pragma omp parallel");
1215 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1216 if (gimple_omp_parallel_child_fn (gs))
1218 pp_string (buffer, " [child fn: ");
1219 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1220 spc, flags, false);
1221 pp_string (buffer, " (");
1222 if (gimple_omp_parallel_data_arg (gs))
1223 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1224 spc, flags, false);
1225 else
1226 pp_string (buffer, "???");
1227 pp_string (buffer, ")]");
1229 body = gimple_omp_body (gs);
1230 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1232 newline_and_indent (buffer, spc + 2);
1233 pp_character (buffer, '{');
1234 pp_newline (buffer);
1235 dump_gimple_seq (buffer, body, spc + 4, flags);
1236 newline_and_indent (buffer, spc + 2);
1237 pp_character (buffer, '}');
1239 else if (body)
1241 pp_newline (buffer);
1242 dump_gimple_seq (buffer, body, spc + 2, flags);
1248 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1249 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1250 tree-pass.h). */
1252 static void
1253 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1254 int flags)
1256 if (flags & TDF_RAW)
1258 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1259 gimple_omp_body (gs));
1260 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1261 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1262 gimple_omp_task_child_fn (gs),
1263 gimple_omp_task_data_arg (gs),
1264 gimple_omp_task_copy_fn (gs),
1265 gimple_omp_task_arg_size (gs),
1266 gimple_omp_task_arg_size (gs));
1268 else
1270 gimple_seq body;
1271 pp_string (buffer, "#pragma omp task");
1272 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1273 if (gimple_omp_task_child_fn (gs))
1275 pp_string (buffer, " [child fn: ");
1276 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1277 spc, flags, false);
1278 pp_string (buffer, " (");
1279 if (gimple_omp_task_data_arg (gs))
1280 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1281 spc, flags, false);
1282 else
1283 pp_string (buffer, "???");
1284 pp_string (buffer, ")]");
1286 body = gimple_omp_body (gs);
1287 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1289 newline_and_indent (buffer, spc + 2);
1290 pp_character (buffer, '{');
1291 pp_newline (buffer);
1292 dump_gimple_seq (buffer, body, spc + 4, flags);
1293 newline_and_indent (buffer, spc + 2);
1294 pp_character (buffer, '}');
1296 else if (body)
1298 pp_newline (buffer);
1299 dump_gimple_seq (buffer, body, spc + 2, flags);
1305 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1306 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1307 in tree-pass.h). */
1309 static void
1310 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1311 int flags)
1313 if (flags & TDF_RAW)
1315 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1316 gimple_omp_atomic_load_lhs (gs),
1317 gimple_omp_atomic_load_rhs (gs));
1319 else
1321 pp_string (buffer, "#pragma omp atomic_load");
1322 newline_and_indent (buffer, spc + 2);
1323 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1324 spc, flags, false);
1325 pp_space (buffer);
1326 pp_character (buffer, '=');
1327 pp_space (buffer);
1328 pp_character (buffer, '*');
1329 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1330 spc, flags, false);
1334 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1335 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1336 in tree-pass.h). */
1338 static void
1339 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
1340 int flags)
1342 if (flags & TDF_RAW)
1344 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1345 gimple_omp_atomic_store_val (gs));
1347 else
1349 pp_string (buffer, "#pragma omp atomic_store (");
1350 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
1351 spc, flags, false);
1352 pp_character (buffer, ')');
1356 /* Dump a GIMPLE_CHANGE_DYNAMIC_TYPE statement GS. BUFFER, SPC and
1357 FLAGS are as in dump_gimple_stmt. */
1359 static void
1360 dump_gimple_cdt (pretty_printer *buffer, gimple gs, int spc, int flags)
1362 if (flags & TDF_RAW)
1363 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1364 gimple_cdt_new_type (gs), gimple_cdt_location (gs));
1365 else
1367 pp_string (buffer, "<<<change_dynamic_type (");
1368 dump_generic_node (buffer, gimple_cdt_new_type (gs), spc + 2, flags,
1369 false);
1370 pp_string (buffer, ") ");
1371 dump_generic_node (buffer, gimple_cdt_location (gs), spc + 2, flags,
1372 false);
1373 pp_string (buffer, ")>>>");
1378 /* Dump all the memory operands for statement GS. BUFFER, SPC and
1379 FLAGS are as in dump_gimple_stmt. */
1381 static void
1382 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
1384 struct voptype_d *vdefs;
1385 struct voptype_d *vuses;
1386 int i, n;
1388 if (!ssa_operands_active () || !gimple_references_memory_p (gs))
1389 return;
1391 /* Even if the statement doesn't have virtual operators yet, it may
1392 contain symbol information (this happens before aliases have been
1393 computed). */
1394 if ((flags & TDF_MEMSYMS)
1395 && gimple_vuse_ops (gs) == NULL
1396 && gimple_vdef_ops (gs) == NULL)
1398 if (gimple_loaded_syms (gs))
1400 pp_string (buffer, "# LOADS: ");
1401 dump_symbols (buffer, gimple_loaded_syms (gs), flags);
1402 newline_and_indent (buffer, spc);
1405 if (gimple_stored_syms (gs))
1407 pp_string (buffer, "# STORES: ");
1408 dump_symbols (buffer, gimple_stored_syms (gs), flags);
1409 newline_and_indent (buffer, spc);
1412 return;
1415 vuses = gimple_vuse_ops (gs);
1416 while (vuses)
1418 pp_string (buffer, "# VUSE <");
1420 n = VUSE_NUM (vuses);
1421 for (i = 0; i < n; i++)
1423 dump_generic_node (buffer, VUSE_OP (vuses, i), spc + 2, flags, false);
1424 if (i < n - 1)
1425 pp_string (buffer, ", ");
1428 pp_character (buffer, '>');
1430 if (flags & TDF_MEMSYMS)
1431 dump_symbols (buffer, gimple_loaded_syms (gs), flags);
1433 newline_and_indent (buffer, spc);
1434 vuses = vuses->next;
1437 vdefs = gimple_vdef_ops (gs);
1438 while (vdefs)
1440 pp_string (buffer, "# ");
1441 dump_generic_node (buffer, VDEF_RESULT (vdefs), spc + 2, flags, false);
1442 pp_string (buffer, " = VDEF <");
1444 n = VDEF_NUM (vdefs);
1445 for (i = 0; i < n; i++)
1447 dump_generic_node (buffer, VDEF_OP (vdefs, i), spc + 2, flags, 0);
1448 if (i < n - 1)
1449 pp_string (buffer, ", ");
1452 pp_character (buffer, '>');
1454 if ((flags & TDF_MEMSYMS) && vdefs->next == NULL)
1455 dump_symbols (buffer, gimple_stored_syms (gs), flags);
1457 newline_and_indent (buffer, spc);
1458 vdefs = vdefs->next;
1463 /* Dump the gimple statement GS on the pretty printer BUFFER, SPC
1464 spaces of indent. FLAGS specifies details to show in the dump (see
1465 TDF_* in tree-pass.h). */
1467 void
1468 dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags)
1470 if (!gs)
1471 return;
1473 if (flags & TDF_STMTADDR)
1474 pp_printf (buffer, "<&%p> ", (void *) gs);
1476 if ((flags & TDF_LINENO) && gimple_has_location (gs))
1478 expanded_location xloc = expand_location (gimple_location (gs));
1479 pp_character (buffer, '[');
1480 if (xloc.file)
1482 pp_string (buffer, xloc.file);
1483 pp_string (buffer, " : ");
1485 pp_decimal_int (buffer, xloc.line);
1486 pp_string (buffer, "] ");
1489 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
1490 && gimple_has_mem_ops (gs))
1491 dump_gimple_mem_ops (buffer, gs, spc, flags);
1493 switch (gimple_code (gs))
1495 case GIMPLE_ASM:
1496 dump_gimple_asm (buffer, gs, spc, flags);
1497 break;
1499 case GIMPLE_ASSIGN:
1500 dump_gimple_assign (buffer, gs, spc, flags);
1501 break;
1503 case GIMPLE_BIND:
1504 dump_gimple_bind (buffer, gs, spc, flags);
1505 break;
1507 case GIMPLE_CALL:
1508 dump_gimple_call (buffer, gs, spc, flags);
1509 break;
1511 case GIMPLE_COND:
1512 dump_gimple_cond (buffer, gs, spc, flags);
1513 break;
1515 case GIMPLE_LABEL:
1516 dump_gimple_label (buffer, gs, spc, flags);
1517 break;
1519 case GIMPLE_GOTO:
1520 dump_gimple_goto (buffer, gs, spc, flags);
1521 break;
1523 case GIMPLE_NOP:
1524 pp_string (buffer, "GIMPLE_NOP");
1525 break;
1527 case GIMPLE_RETURN:
1528 dump_gimple_return (buffer, gs, spc, flags);
1529 break;
1531 case GIMPLE_SWITCH:
1532 dump_gimple_switch (buffer, gs, spc, flags);
1533 break;
1535 case GIMPLE_TRY:
1536 dump_gimple_try (buffer, gs, spc, flags);
1537 break;
1539 case GIMPLE_PHI:
1540 dump_gimple_phi (buffer, gs, spc, flags);
1541 break;
1543 case GIMPLE_OMP_PARALLEL:
1544 dump_gimple_omp_parallel (buffer, gs, spc, flags);
1545 break;
1547 case GIMPLE_OMP_TASK:
1548 dump_gimple_omp_task (buffer, gs, spc, flags);
1549 break;
1551 case GIMPLE_OMP_ATOMIC_LOAD:
1552 dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
1554 break;
1556 case GIMPLE_OMP_ATOMIC_STORE:
1557 dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
1558 break;
1560 case GIMPLE_OMP_FOR:
1561 dump_gimple_omp_for (buffer, gs, spc, flags);
1562 break;
1564 case GIMPLE_OMP_CONTINUE:
1565 dump_gimple_omp_continue (buffer, gs, spc, flags);
1566 break;
1568 case GIMPLE_OMP_SINGLE:
1569 dump_gimple_omp_single (buffer, gs, spc, flags);
1570 break;
1572 case GIMPLE_OMP_RETURN:
1573 dump_gimple_omp_return (buffer, gs, spc, flags);
1574 break;
1576 case GIMPLE_OMP_SECTIONS:
1577 dump_gimple_omp_sections (buffer, gs, spc, flags);
1578 break;
1580 case GIMPLE_OMP_SECTIONS_SWITCH:
1581 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
1582 break;
1584 case GIMPLE_OMP_MASTER:
1585 case GIMPLE_OMP_ORDERED:
1586 case GIMPLE_OMP_SECTION:
1587 dump_gimple_omp_block (buffer, gs, spc, flags);
1588 break;
1590 case GIMPLE_OMP_CRITICAL:
1591 dump_gimple_omp_critical (buffer, gs, spc, flags);
1592 break;
1594 case GIMPLE_CHANGE_DYNAMIC_TYPE:
1595 dump_gimple_cdt (buffer, gs, spc, flags);
1596 break;
1598 case GIMPLE_CATCH:
1599 dump_gimple_catch (buffer, gs, spc, flags);
1600 break;
1602 case GIMPLE_EH_FILTER:
1603 dump_gimple_eh_filter (buffer, gs, spc, flags);
1604 break;
1606 case GIMPLE_RESX:
1607 dump_gimple_resx (buffer, gs, spc, flags);
1608 break;
1610 case GIMPLE_PREDICT:
1611 pp_string (buffer, "// predicted ");
1612 if (gimple_predict_outcome (gs))
1613 pp_string (buffer, "likely by ");
1614 else
1615 pp_string (buffer, "unlikely by ");
1616 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
1617 pp_string (buffer, " predictor.");
1618 break;
1620 default:
1621 GIMPLE_NIY;
1624 /* If we're building a diagnostic, the formatted text will be
1625 written into BUFFER's stream by the caller; otherwise, write it
1626 now. */
1627 if (!(flags & TDF_DIAGNOSTIC))
1628 pp_write_text_to_stream (buffer);
1632 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
1633 spaces and details described by flags. */
1635 static void
1636 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
1638 edge e;
1639 gimple stmt;
1640 edge_iterator ei;
1642 if (flags & TDF_BLOCKS)
1644 INDENT (indent);
1645 pp_string (buffer, "# BLOCK ");
1646 pp_decimal_int (buffer, bb->index);
1647 if (bb->frequency)
1649 pp_string (buffer, " freq:");
1650 pp_decimal_int (buffer, bb->frequency);
1652 if (bb->count)
1654 pp_string (buffer, " count:");
1655 pp_widest_integer (buffer, bb->count);
1658 if (flags & TDF_LINENO)
1660 gimple_stmt_iterator gsi;
1662 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1663 if (get_lineno (gsi_stmt (gsi)) != -1)
1665 pp_string (buffer, ", starting at line ");
1666 pp_decimal_int (buffer, get_lineno (gsi_stmt (gsi)));
1667 break;
1670 newline_and_indent (buffer, indent);
1672 pp_string (buffer, "# PRED:");
1673 pp_write_text_to_stream (buffer);
1674 FOR_EACH_EDGE (e, ei, bb->preds)
1675 if (flags & TDF_SLIM)
1677 pp_character (buffer, ' ');
1678 if (e->src == ENTRY_BLOCK_PTR)
1679 pp_string (buffer, "ENTRY");
1680 else
1681 pp_decimal_int (buffer, e->src->index);
1683 else
1684 dump_edge_info (buffer->buffer->stream, e, 0);
1685 pp_newline (buffer);
1687 else
1689 stmt = first_stmt (bb);
1690 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
1692 INDENT (indent - 2);
1693 pp_string (buffer, "<bb ");
1694 pp_decimal_int (buffer, bb->index);
1695 pp_string (buffer, ">:");
1696 pp_newline (buffer);
1699 pp_write_text_to_stream (buffer);
1700 check_bb_profile (bb, buffer->buffer->stream);
1704 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
1705 spaces. */
1707 static void
1708 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
1710 edge e;
1711 edge_iterator ei;
1713 INDENT (indent);
1714 pp_string (buffer, "# SUCC:");
1715 pp_write_text_to_stream (buffer);
1716 FOR_EACH_EDGE (e, ei, bb->succs)
1717 if (flags & TDF_SLIM)
1719 pp_character (buffer, ' ');
1720 if (e->dest == EXIT_BLOCK_PTR)
1721 pp_string (buffer, "EXIT");
1722 else
1723 pp_decimal_int (buffer, e->dest->index);
1725 else
1726 dump_edge_info (buffer->buffer->stream, e, 1);
1727 pp_newline (buffer);
1731 /* Dump PHI nodes of basic block BB to BUFFER with details described
1732 by FLAGS and indented by INDENT spaces. */
1734 static void
1735 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
1737 gimple_stmt_iterator i;
1739 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
1741 gimple phi = gsi_stmt (i);
1742 if (is_gimple_reg (gimple_phi_result (phi)) || (flags & TDF_VOPS))
1744 INDENT (indent);
1745 pp_string (buffer, "# ");
1746 dump_gimple_phi (buffer, phi, indent, flags);
1747 pp_newline (buffer);
1753 /* Dump jump to basic block BB that is represented implicitly in the cfg
1754 to BUFFER. */
1756 static void
1757 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
1759 gimple stmt;
1761 stmt = first_stmt (bb);
1763 pp_string (buffer, "goto <bb ");
1764 pp_decimal_int (buffer, bb->index);
1765 pp_character (buffer, '>');
1766 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
1768 pp_string (buffer, " (");
1769 dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
1770 pp_character (buffer, ')');
1771 pp_semicolon (buffer);
1773 else
1774 pp_semicolon (buffer);
1778 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
1779 by INDENT spaces, with details given by FLAGS. */
1781 static void
1782 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
1783 int flags)
1785 edge e;
1786 edge_iterator ei;
1787 gimple stmt;
1789 stmt = last_stmt (bb);
1791 if (stmt && gimple_code (stmt) == GIMPLE_COND)
1793 edge true_edge, false_edge;
1795 /* When we are emitting the code or changing CFG, it is possible that
1796 the edges are not yet created. When we are using debug_bb in such
1797 a situation, we do not want it to crash. */
1798 if (EDGE_COUNT (bb->succs) != 2)
1799 return;
1800 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
1802 INDENT (indent + 2);
1803 pp_cfg_jump (buffer, true_edge->dest);
1804 newline_and_indent (buffer, indent);
1805 pp_string (buffer, "else");
1806 newline_and_indent (buffer, indent + 2);
1807 pp_cfg_jump (buffer, false_edge->dest);
1808 pp_newline (buffer);
1809 return;
1812 /* If there is a fallthru edge, we may need to add an artificial
1813 goto to the dump. */
1814 FOR_EACH_EDGE (e, ei, bb->succs)
1815 if (e->flags & EDGE_FALLTHRU)
1816 break;
1818 if (e && e->dest != bb->next_bb)
1820 INDENT (indent);
1822 if ((flags & TDF_LINENO)
1823 && e->goto_locus != UNKNOWN_LOCATION
1826 expanded_location goto_xloc;
1827 goto_xloc = expand_location (e->goto_locus);
1828 pp_character (buffer, '[');
1829 if (goto_xloc.file)
1831 pp_string (buffer, goto_xloc.file);
1832 pp_string (buffer, " : ");
1834 pp_decimal_int (buffer, goto_xloc.line);
1835 pp_string (buffer, "] ");
1838 pp_cfg_jump (buffer, e->dest);
1839 pp_newline (buffer);
1844 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
1845 indented by INDENT spaces. */
1847 static void
1848 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
1849 int flags)
1851 gimple_stmt_iterator gsi;
1852 gimple stmt;
1853 int label_indent = indent - 2;
1855 if (label_indent < 0)
1856 label_indent = 0;
1858 dump_bb_header (buffer, bb, indent, flags);
1859 dump_phi_nodes (buffer, bb, indent, flags);
1861 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1863 int curr_indent;
1865 stmt = gsi_stmt (gsi);
1867 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
1869 INDENT (curr_indent);
1870 dump_gimple_stmt (buffer, stmt, curr_indent, flags);
1871 pp_newline (buffer);
1872 dump_histograms_for_stmt (cfun, buffer->buffer->stream, stmt);
1875 dump_implicit_edges (buffer, bb, indent, flags);
1877 if (flags & TDF_BLOCKS)
1878 dump_bb_end (buffer, bb, indent, flags);
1882 /* Dumps basic block BB to FILE with details described by FLAGS and
1883 indented by INDENT spaces. */
1885 void
1886 gimple_dump_bb (basic_block bb, FILE *file, int indent, int flags)
1888 maybe_init_pretty_print (file);
1889 gimple_dump_bb_buff (&buffer, bb, indent, flags);
1890 pp_flush (&buffer);