Fix typo.
[official-gcc.git] / gcc / gimple-pretty-print.c
blob16ff6e1eb85c65bc644b7c0d51cf2d5bfe8ef631
1 /* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
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_string (buffer, "(");
261 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
262 pp_string (buffer, ") ");
263 dump_generic_node (buffer, rhs, spc, flags, false);
264 break;
266 case PAREN_EXPR:
267 pp_string (buffer, "((");
268 dump_generic_node (buffer, rhs, spc, flags, false);
269 pp_string (buffer, "))");
270 break;
272 case ABS_EXPR:
273 pp_string (buffer, "ABS_EXPR <");
274 dump_generic_node (buffer, rhs, spc, flags, false);
275 pp_string (buffer, ">");
276 break;
278 default:
279 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
280 || TREE_CODE_CLASS (rhs_code) == tcc_constant
281 || TREE_CODE_CLASS (rhs_code) == tcc_reference
282 || rhs_code == SSA_NAME
283 || rhs_code == ADDR_EXPR
284 || rhs_code == CONSTRUCTOR)
285 ; /* do nothing. */
286 else if (rhs_code == BIT_NOT_EXPR)
287 pp_string (buffer, "~");
288 else if (rhs_code == TRUTH_NOT_EXPR)
289 pp_string (buffer, "!");
290 else if (rhs_code == NEGATE_EXPR)
291 pp_string (buffer, "-");
292 else
294 pp_string (buffer, "[");
295 pp_string (buffer, tree_code_name [rhs_code]);
296 pp_string (buffer, "] ");
299 dump_generic_node (buffer, rhs, spc, flags, false);
300 break;
305 /* Helper for dump_gimple_assign. Print the binary RHS of the
306 assignment GS. BUFFER, SPC and FLAGS are as in dump_gimple_stmt. */
308 static void
309 dump_binary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
311 const char *p;
312 enum tree_code code = gimple_assign_rhs_code (gs);
313 switch (code)
315 case COMPLEX_EXPR:
316 case MIN_EXPR:
317 case MAX_EXPR:
318 case VEC_WIDEN_MULT_HI_EXPR:
319 case VEC_WIDEN_MULT_LO_EXPR:
320 case VEC_PACK_TRUNC_EXPR:
321 case VEC_PACK_SAT_EXPR:
322 case VEC_PACK_FIX_TRUNC_EXPR:
323 case VEC_EXTRACT_EVEN_EXPR:
324 case VEC_EXTRACT_ODD_EXPR:
325 case VEC_INTERLEAVE_HIGH_EXPR:
326 case VEC_INTERLEAVE_LOW_EXPR:
327 for (p = tree_code_name [(int) code]; *p; p++)
328 pp_character (buffer, TOUPPER (*p));
329 pp_string (buffer, " <");
330 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
331 pp_string (buffer, ", ");
332 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
333 pp_character (buffer, '>');
334 break;
336 default:
337 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
338 pp_space (buffer);
339 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
340 pp_space (buffer);
341 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
346 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
347 dump_gimple_stmt. */
349 static void
350 dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
352 if (flags & TDF_RAW)
354 tree last;
355 if (gimple_num_ops (gs) == 2)
356 last = NULL_TREE;
357 else if (gimple_num_ops (gs) == 3)
358 last = gimple_assign_rhs2 (gs);
359 else
360 gcc_unreachable ();
362 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T>", gs,
363 tree_code_name[gimple_assign_rhs_code (gs)],
364 gimple_assign_lhs (gs), gimple_assign_rhs1 (gs), last);
366 else
368 if (!(flags & TDF_RHS_ONLY))
370 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
371 pp_space (buffer);
372 pp_character (buffer, '=');
374 if (gimple_assign_nontemporal_move_p (gs))
375 pp_string (buffer, "{nt}");
377 if (gimple_has_volatile_ops (gs))
378 pp_string (buffer, "{v}");
380 pp_space (buffer);
383 if (gimple_num_ops (gs) == 2)
384 dump_unary_rhs (buffer, gs, spc, flags);
385 else if (gimple_num_ops (gs) == 3)
386 dump_binary_rhs (buffer, gs, spc, flags);
387 else
388 gcc_unreachable ();
389 if (!(flags & TDF_RHS_ONLY))
390 pp_semicolon(buffer);
395 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
396 dump_gimple_stmt. */
398 static void
399 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
401 tree t;
403 t = gimple_return_retval (gs);
404 if (flags & TDF_RAW)
405 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
406 else
408 pp_string (buffer, "return");
409 if (t)
411 pp_space (buffer);
412 dump_generic_node (buffer, t, spc, flags, false);
414 pp_semicolon (buffer);
419 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
420 dump_gimple_call. */
422 static void
423 dump_gimple_call_args (pretty_printer *buffer, gimple gs, int flags)
425 size_t i;
427 for (i = 0; i < gimple_call_num_args (gs); i++)
429 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
430 if (i < gimple_call_num_args (gs) - 1)
431 pp_string (buffer, ", ");
434 if (gimple_call_va_arg_pack_p (gs))
436 if (gimple_call_num_args (gs) > 0)
438 pp_character (buffer, ',');
439 pp_space (buffer);
442 pp_string (buffer, "__builtin_va_arg_pack ()");
447 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
448 dump_gimple_stmt. */
450 static void
451 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
453 tree lhs = gimple_call_lhs (gs);
455 if (flags & TDF_RAW)
457 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T",
458 gs, gimple_call_fn (gs), lhs);
459 if (gimple_call_num_args (gs) > 0)
461 pp_string (buffer, ", ");
462 dump_gimple_call_args (buffer, gs, flags);
464 pp_string (buffer, ">");
466 else
468 if (lhs && !(flags & TDF_RHS_ONLY))
470 dump_generic_node (buffer, lhs, spc, flags, false);
471 pp_string (buffer, " =");
473 if (gimple_has_volatile_ops (gs))
474 pp_string (buffer, "{v}");
476 pp_space (buffer);
478 dump_generic_node (buffer, gimple_call_fn (gs), spc, flags, false);
479 pp_string (buffer, " (");
480 dump_gimple_call_args (buffer, gs, flags);
481 pp_string (buffer, ")");
482 if (!(flags & TDF_RHS_ONLY))
483 pp_semicolon (buffer);
486 if (gimple_call_chain (gs))
488 pp_string (buffer, " [static-chain: ");
489 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
490 pp_character (buffer, ']');
493 if (gimple_call_return_slot_opt_p (gs))
494 pp_string (buffer, " [return slot optimization]");
496 if (gimple_call_tail_p (gs))
497 pp_string (buffer, " [tail call]");
501 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
502 dump_gimple_stmt. */
504 static void
505 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
507 unsigned int i;
509 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
510 if (flags & TDF_RAW)
511 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
512 gimple_switch_index (gs));
513 else
515 pp_string (buffer, "switch (");
516 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
517 pp_string (buffer, ") <");
520 for (i = 0; i < gimple_switch_num_labels (gs); i++)
522 tree case_label = gimple_switch_label (gs, i);
523 if (case_label == NULL_TREE)
524 continue;
526 dump_generic_node (buffer, case_label, spc, flags, false);
527 pp_string (buffer, " ");
528 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
529 if (i < gimple_switch_num_labels (gs) - 1)
530 pp_string (buffer, ", ");
532 pp_string (buffer, ">");
536 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
537 dump_gimple_stmt. */
539 static void
540 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
542 if (flags & TDF_RAW)
543 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
544 tree_code_name [gimple_cond_code (gs)],
545 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
546 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
547 else
549 if (!(flags & TDF_RHS_ONLY))
550 pp_string (buffer, "if (");
551 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
552 pp_space (buffer);
553 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
554 pp_space (buffer);
555 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
556 if (!(flags & TDF_RHS_ONLY))
558 pp_string (buffer, ")");
560 if (gimple_cond_true_label (gs))
562 pp_string (buffer, " goto ");
563 dump_generic_node (buffer, gimple_cond_true_label (gs),
564 spc, flags, false);
565 pp_semicolon (buffer);
567 if (gimple_cond_false_label (gs))
569 pp_string (buffer, " else goto ");
570 dump_generic_node (buffer, gimple_cond_false_label (gs),
571 spc, flags, false);
572 pp_semicolon (buffer);
579 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
580 spaces of indent. FLAGS specifies details to show in the dump (see
581 TDF_* in tree-pass.h). */
583 static void
584 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
586 tree label = gimple_label_label (gs);
587 if (flags & TDF_RAW)
588 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
589 else
591 dump_generic_node (buffer, label, spc, flags, false);
592 pp_string (buffer, ":");
594 if (DECL_NONLOCAL (label))
595 pp_string (buffer, " [non-local]");
598 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
599 spaces of indent. FLAGS specifies details to show in the dump (see
600 TDF_* in tree-pass.h). */
602 static void
603 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
605 tree label = gimple_goto_dest (gs);
606 if (flags & TDF_RAW)
607 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
608 else
609 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
613 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
614 spaces of indent. FLAGS specifies details to show in the dump (see
615 TDF_* in tree-pass.h). */
617 static void
618 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
620 if (flags & TDF_RAW)
621 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
622 else
623 pp_character (buffer, '{');
624 if (!(flags & TDF_SLIM))
626 tree var;
628 for (var = gimple_bind_vars (gs); var; var = TREE_CHAIN (var))
630 newline_and_indent (buffer, 2);
631 print_declaration (buffer, var, spc, flags);
633 if (gimple_bind_vars (gs))
634 pp_newline (buffer);
636 pp_newline (buffer);
637 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
638 newline_and_indent (buffer, spc);
639 if (flags & TDF_RAW)
640 pp_character (buffer, '>');
641 else
642 pp_character (buffer, '}');
646 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
647 indent. FLAGS specifies details to show in the dump (see TDF_* in
648 tree-pass.h). */
650 static void
651 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
653 if (flags & TDF_RAW)
655 const char *type;
656 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
657 type = "GIMPLE_TRY_CATCH";
658 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
659 type = "GIMPLE_TRY_FINALLY";
660 else
661 type = "UNKNOWN GIMPLE_TRY";
662 dump_gimple_fmt (buffer, spc, flags,
663 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
664 gimple_try_eval (gs), gimple_try_cleanup (gs));
666 else
668 pp_string (buffer, "try");
669 newline_and_indent (buffer, spc + 2);
670 pp_string (buffer, "{");
671 pp_newline (buffer);
673 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
674 newline_and_indent (buffer, spc + 2);
675 pp_string (buffer, "}");
677 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
679 newline_and_indent (buffer, spc);
680 pp_string (buffer, "catch");
681 newline_and_indent (buffer, spc + 2);
682 pp_string (buffer, "{");
684 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
686 newline_and_indent (buffer, spc);
687 pp_string (buffer, "finally");
688 newline_and_indent (buffer, spc + 2);
689 pp_string (buffer, "{");
691 else
692 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
694 pp_newline (buffer);
695 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
696 newline_and_indent (buffer, spc + 2);
697 pp_character (buffer, '}');
702 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
703 indent. FLAGS specifies details to show in the dump (see TDF_* in
704 tree-pass.h). */
706 static void
707 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
709 if (flags & TDF_RAW)
710 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
711 gimple_catch_types (gs), gimple_catch_handler (gs));
712 else
713 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
714 gimple_catch_types (gs), gimple_catch_handler (gs));
718 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
719 indent. FLAGS specifies details to show in the dump (see TDF_* in
720 tree-pass.h). */
722 static void
723 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
725 if (flags & TDF_RAW)
726 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
727 gimple_eh_filter_types (gs),
728 gimple_eh_filter_failure (gs));
729 else
730 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
731 gimple_eh_filter_types (gs),
732 gimple_eh_filter_failure (gs));
736 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
737 indent. FLAGS specifies details to show in the dump (see TDF_* in
738 tree-pass.h). */
740 static void
741 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
743 if (flags & TDF_RAW)
744 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
745 gimple_resx_region (gs));
746 else
747 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
750 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
751 static void
752 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
754 size_t i;
756 if (flags & TDF_RAW)
758 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
759 gimple_omp_body (gs));
760 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
761 dump_gimple_fmt (buffer, spc, flags, " >,");
762 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
763 dump_gimple_fmt (buffer, spc, flags,
764 "%+%T, %T, %T, %s, %T,%n",
765 gimple_omp_for_index (gs, i),
766 gimple_omp_for_initial (gs, i),
767 gimple_omp_for_final (gs, i),
768 tree_code_name[gimple_omp_for_cond (gs, i)],
769 gimple_omp_for_incr (gs, i));
770 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
771 gimple_omp_for_pre_body (gs));
773 else
775 pp_string (buffer, "#pragma omp for");
776 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
777 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
779 if (i)
780 spc += 2;
781 newline_and_indent (buffer, spc);
782 pp_string (buffer, "for (");
783 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
784 flags, false);
785 pp_string (buffer, " = ");
786 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
787 flags, false);
788 pp_string (buffer, "; ");
790 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
791 flags, false);
792 pp_space (buffer);
793 switch (gimple_omp_for_cond (gs, i))
795 case LT_EXPR:
796 pp_character (buffer, '<');
797 break;
798 case GT_EXPR:
799 pp_character (buffer, '>');
800 break;
801 case LE_EXPR:
802 pp_string (buffer, "<=");
803 break;
804 case GE_EXPR:
805 pp_string (buffer, ">=");
806 break;
807 default:
808 gcc_unreachable ();
810 pp_space (buffer);
811 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
812 flags, false);
813 pp_string (buffer, "; ");
815 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
816 flags, false);
817 pp_string (buffer, " = ");
818 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
819 flags, false);
820 pp_character (buffer, ')');
823 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
825 newline_and_indent (buffer, spc + 2);
826 pp_character (buffer, '{');
827 pp_newline (buffer);
828 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
829 newline_and_indent (buffer, spc + 2);
830 pp_character (buffer, '}');
835 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
837 static void
838 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
840 if (flags & TDF_RAW)
842 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
843 gimple_omp_continue_control_def (gs),
844 gimple_omp_continue_control_use (gs));
846 else
848 pp_string (buffer, "#pragma omp continue (");
849 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
850 spc, flags, false);
851 pp_character (buffer, ',');
852 pp_space (buffer);
853 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
854 spc, flags, false);
855 pp_character (buffer, ')');
859 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
861 static void
862 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
864 if (flags & TDF_RAW)
866 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
867 gimple_omp_body (gs));
868 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
869 dump_gimple_fmt (buffer, spc, flags, " >");
871 else
873 pp_string (buffer, "#pragma omp single");
874 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
875 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
877 newline_and_indent (buffer, spc + 2);
878 pp_character (buffer, '{');
879 pp_newline (buffer);
880 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
881 newline_and_indent (buffer, spc + 2);
882 pp_character (buffer, '}');
887 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
889 static void
890 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
891 int flags)
893 if (flags & TDF_RAW)
895 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
896 gimple_omp_body (gs));
897 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
898 dump_gimple_fmt (buffer, spc, flags, " >");
900 else
902 pp_string (buffer, "#pragma omp sections");
903 if (gimple_omp_sections_control (gs))
905 pp_string (buffer, " <");
906 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
907 flags, false);
908 pp_character (buffer, '>');
910 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
911 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
913 newline_and_indent (buffer, spc + 2);
914 pp_character (buffer, '{');
915 pp_newline (buffer);
916 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
917 newline_and_indent (buffer, spc + 2);
918 pp_character (buffer, '}');
923 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer
924 BUFFER. */
926 static void
927 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
929 if (flags & TDF_RAW)
930 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
931 gimple_omp_body (gs));
932 else
934 switch (gimple_code (gs))
936 case GIMPLE_OMP_MASTER:
937 pp_string (buffer, "#pragma omp master");
938 break;
939 case GIMPLE_OMP_ORDERED:
940 pp_string (buffer, "#pragma omp ordered");
941 break;
942 case GIMPLE_OMP_SECTION:
943 pp_string (buffer, "#pragma omp section");
944 break;
945 default:
946 gcc_unreachable ();
948 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
950 newline_and_indent (buffer, spc + 2);
951 pp_character (buffer, '{');
952 pp_newline (buffer);
953 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
954 newline_and_indent (buffer, spc + 2);
955 pp_character (buffer, '}');
960 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
962 static void
963 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
964 int flags)
966 if (flags & TDF_RAW)
967 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
968 gimple_omp_body (gs));
969 else
971 pp_string (buffer, "#pragma omp critical");
972 if (gimple_omp_critical_name (gs))
974 pp_string (buffer, " (");
975 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
976 flags, false);
977 pp_character (buffer, ')');
979 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
981 newline_and_indent (buffer, spc + 2);
982 pp_character (buffer, '{');
983 pp_newline (buffer);
984 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
985 newline_and_indent (buffer, spc + 2);
986 pp_character (buffer, '}');
991 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
993 static void
994 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
996 if (flags & TDF_RAW)
998 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d>", gs,
999 (int) gimple_omp_return_nowait_p (gs));
1001 else
1003 pp_string (buffer, "#pragma omp return");
1004 if (gimple_omp_return_nowait_p (gs))
1005 pp_string (buffer, "(nowait)");
1009 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1010 indent. FLAGS specifies details to show in the dump (see TDF_* in
1011 tree-pass.h). */
1013 static void
1014 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1016 unsigned int i;
1018 if (flags & TDF_RAW)
1019 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1020 gimple_asm_string (gs));
1021 else
1023 pp_string (buffer, "__asm__");
1024 if (gimple_asm_volatile_p (gs))
1025 pp_string (buffer, " __volatile__");
1026 pp_string (buffer, "(\"");
1027 pp_string (buffer, gimple_asm_string (gs));
1028 pp_string (buffer, "\"");
1031 if (gimple_asm_ninputs (gs)
1032 || gimple_asm_noutputs (gs)
1033 || gimple_asm_nclobbers (gs))
1035 if (gimple_asm_noutputs (gs))
1037 if (flags & TDF_RAW)
1039 newline_and_indent (buffer, spc + 2);
1040 pp_string (buffer, "OUTPUT: ");
1042 else
1043 pp_string (buffer, " : ");
1046 for (i = 0; i < gimple_asm_noutputs (gs); i++)
1048 dump_generic_node (buffer, gimple_asm_output_op (gs, i), spc, flags,
1049 false);
1050 if ( i < gimple_asm_noutputs (gs) -1)
1051 pp_string (buffer, ", ");
1054 if (gimple_asm_ninputs (gs))
1056 if (flags & TDF_RAW)
1058 newline_and_indent (buffer, spc + 2);
1059 pp_string (buffer, "INPUT: ");
1061 else
1062 pp_string (buffer, " : ");
1065 for (i = 0; i < gimple_asm_ninputs (gs); i++)
1067 dump_generic_node (buffer, gimple_asm_input_op (gs, i), spc, flags,
1068 false);
1069 if (i < gimple_asm_ninputs (gs) -1)
1070 pp_string (buffer, " : ");
1073 if (gimple_asm_nclobbers (gs))
1075 if (flags & TDF_RAW)
1077 newline_and_indent (buffer, spc + 2);
1078 pp_string (buffer, "CLOBBER: ");
1080 else
1081 pp_string (buffer, " : ");
1084 for (i = 0; i < gimple_asm_nclobbers (gs); i++)
1086 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i), spc, flags,
1087 false);
1088 if ( i < gimple_asm_nclobbers (gs) -1)
1089 pp_string (buffer, ", ");
1092 if (flags & TDF_RAW)
1094 newline_and_indent (buffer, spc);
1095 pp_character (buffer, '>');
1097 else
1098 pp_string (buffer, ");");
1102 /* Dump the set of decls SYMS. BUFFER, SPC and FLAGS are as in
1103 dump_generic_node. */
1105 static void
1106 dump_symbols (pretty_printer *buffer, bitmap syms, int flags)
1108 unsigned i;
1109 bitmap_iterator bi;
1111 if (syms == NULL)
1112 pp_string (buffer, "NIL");
1113 else
1115 pp_string (buffer, " { ");
1117 EXECUTE_IF_SET_IN_BITMAP (syms, 0, i, bi)
1119 tree sym = referenced_var_lookup (i);
1120 dump_generic_node (buffer, sym, 0, flags, false);
1121 pp_string (buffer, " ");
1124 pp_string (buffer, "}");
1129 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in
1130 dump_gimple_stmt. */
1132 static void
1133 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
1135 size_t i;
1137 if (flags & TDF_RAW)
1138 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1139 gimple_phi_result (phi));
1140 else
1142 dump_generic_node (buffer, gimple_phi_result (phi), spc, flags, false);
1143 pp_string (buffer, " = PHI <");
1145 for (i = 0; i < gimple_phi_num_args (phi); i++)
1147 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1148 false);
1149 pp_string (buffer, "(");
1150 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1151 pp_string (buffer, ")");
1152 if (i < gimple_phi_num_args (phi) - 1)
1153 pp_string (buffer, ", ");
1155 pp_string (buffer, ">");
1159 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1160 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1161 tree-pass.h). */
1163 static void
1164 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1165 int flags)
1167 if (flags & TDF_RAW)
1169 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1170 gimple_omp_body (gs));
1171 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1172 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1173 gimple_omp_parallel_child_fn (gs),
1174 gimple_omp_parallel_data_arg (gs));
1176 else
1178 gimple_seq body;
1179 pp_string (buffer, "#pragma omp parallel");
1180 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1181 if (gimple_omp_parallel_child_fn (gs))
1183 pp_string (buffer, " [child fn: ");
1184 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1185 spc, flags, false);
1186 pp_string (buffer, " (");
1187 if (gimple_omp_parallel_data_arg (gs))
1188 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1189 spc, flags, false);
1190 else
1191 pp_string (buffer, "???");
1192 pp_string (buffer, ")]");
1194 body = gimple_omp_body (gs);
1195 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1197 newline_and_indent (buffer, spc + 2);
1198 pp_character (buffer, '{');
1199 pp_newline (buffer);
1200 dump_gimple_seq (buffer, body, spc + 4, flags);
1201 newline_and_indent (buffer, spc + 2);
1202 pp_character (buffer, '}');
1204 else if (body)
1206 pp_newline (buffer);
1207 dump_gimple_seq (buffer, body, spc + 2, flags);
1213 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1214 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1215 tree-pass.h). */
1217 static void
1218 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1219 int flags)
1221 if (flags & TDF_RAW)
1223 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1224 gimple_omp_body (gs));
1225 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1226 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1227 gimple_omp_task_child_fn (gs),
1228 gimple_omp_task_data_arg (gs),
1229 gimple_omp_task_copy_fn (gs),
1230 gimple_omp_task_arg_size (gs),
1231 gimple_omp_task_arg_size (gs));
1233 else
1235 gimple_seq body;
1236 pp_string (buffer, "#pragma omp task");
1237 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1238 if (gimple_omp_task_child_fn (gs))
1240 pp_string (buffer, " [child fn: ");
1241 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1242 spc, flags, false);
1243 pp_string (buffer, " (");
1244 if (gimple_omp_task_data_arg (gs))
1245 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1246 spc, flags, false);
1247 else
1248 pp_string (buffer, "???");
1249 pp_string (buffer, ")]");
1251 body = gimple_omp_body (gs);
1252 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1254 newline_and_indent (buffer, spc + 2);
1255 pp_character (buffer, '{');
1256 pp_newline (buffer);
1257 dump_gimple_seq (buffer, body, spc + 4, flags);
1258 newline_and_indent (buffer, spc + 2);
1259 pp_character (buffer, '}');
1261 else if (body)
1263 pp_newline (buffer);
1264 dump_gimple_seq (buffer, body, spc + 2, flags);
1270 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1271 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1272 in tree-pass.h). */
1274 static void
1275 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1276 int flags)
1278 if (flags & TDF_RAW)
1280 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1281 gimple_omp_atomic_load_lhs (gs),
1282 gimple_omp_atomic_load_rhs (gs));
1284 else
1286 pp_string (buffer, "#pragma omp atomic_load");
1287 newline_and_indent (buffer, spc + 2);
1288 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1289 spc, flags, false);
1290 pp_space (buffer);
1291 pp_character (buffer, '=');
1292 pp_space (buffer);
1293 pp_character (buffer, '*');
1294 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1295 spc, flags, false);
1299 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1300 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1301 in tree-pass.h). */
1303 static void
1304 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
1305 int flags)
1307 if (flags & TDF_RAW)
1309 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1310 gimple_omp_atomic_store_val (gs));
1312 else
1314 pp_string (buffer, "#pragma omp atomic_store (");
1315 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
1316 spc, flags, false);
1317 pp_character (buffer, ')');
1321 /* Dump a GIMPLE_CHANGE_DYNAMIC_TYPE statement GS. BUFFER, SPC and
1322 FLAGS are as in dump_gimple_stmt. */
1324 static void
1325 dump_gimple_cdt (pretty_printer *buffer, gimple gs, int spc, int flags)
1327 if (flags & TDF_RAW)
1328 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1329 gimple_cdt_new_type (gs), gimple_cdt_location (gs));
1330 else
1332 pp_string (buffer, "<<<change_dynamic_type (");
1333 dump_generic_node (buffer, gimple_cdt_new_type (gs), spc + 2, flags,
1334 false);
1335 pp_string (buffer, ") ");
1336 dump_generic_node (buffer, gimple_cdt_location (gs), spc + 2, flags,
1337 false);
1338 pp_string (buffer, ")>>>");
1343 /* Dump all the memory operands for statement GS. BUFFER, SPC and
1344 FLAGS are as in dump_gimple_stmt. */
1346 static void
1347 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
1349 struct voptype_d *vdefs;
1350 struct voptype_d *vuses;
1351 int i, n;
1353 if (!ssa_operands_active () || !gimple_references_memory_p (gs))
1354 return;
1356 /* Even if the statement doesn't have virtual operators yet, it may
1357 contain symbol information (this happens before aliases have been
1358 computed). */
1359 if ((flags & TDF_MEMSYMS)
1360 && gimple_vuse_ops (gs) == NULL
1361 && gimple_vdef_ops (gs) == NULL)
1363 if (gimple_loaded_syms (gs))
1365 pp_string (buffer, "# LOADS: ");
1366 dump_symbols (buffer, gimple_loaded_syms (gs), flags);
1367 newline_and_indent (buffer, spc);
1370 if (gimple_stored_syms (gs))
1372 pp_string (buffer, "# STORES: ");
1373 dump_symbols (buffer, gimple_stored_syms (gs), flags);
1374 newline_and_indent (buffer, spc);
1377 return;
1380 vuses = gimple_vuse_ops (gs);
1381 while (vuses)
1383 pp_string (buffer, "# VUSE <");
1385 n = VUSE_NUM (vuses);
1386 for (i = 0; i < n; i++)
1388 dump_generic_node (buffer, VUSE_OP (vuses, i), spc + 2, flags, false);
1389 if (i < n - 1)
1390 pp_string (buffer, ", ");
1393 pp_string (buffer, ">");
1395 if (flags & TDF_MEMSYMS)
1396 dump_symbols (buffer, gimple_loaded_syms (gs), flags);
1398 newline_and_indent (buffer, spc);
1399 vuses = vuses->next;
1402 vdefs = gimple_vdef_ops (gs);
1403 while (vdefs)
1405 pp_string (buffer, "# ");
1406 dump_generic_node (buffer, VDEF_RESULT (vdefs), spc + 2, flags, false);
1407 pp_string (buffer, " = VDEF <");
1409 n = VDEF_NUM (vdefs);
1410 for (i = 0; i < n; i++)
1412 dump_generic_node (buffer, VDEF_OP (vdefs, i), spc + 2, flags, 0);
1413 if (i < n - 1)
1414 pp_string (buffer, ", ");
1417 pp_string (buffer, ">");
1419 if ((flags & TDF_MEMSYMS) && vdefs->next == NULL)
1420 dump_symbols (buffer, gimple_stored_syms (gs), flags);
1422 newline_and_indent (buffer, spc);
1423 vdefs = vdefs->next;
1428 /* Dump the gimple statement GS on the pretty printer BUFFER, SPC
1429 spaces of indent. FLAGS specifies details to show in the dump (see
1430 TDF_* in tree-pass.h). */
1432 void
1433 dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags)
1435 if (!gs)
1436 return;
1438 if (flags & TDF_STMTADDR)
1439 pp_printf (buffer, "<&%p> ", (void *) gs);
1441 if ((flags & TDF_LINENO) && gimple_has_location (gs))
1443 expanded_location xloc = expand_location (gimple_location (gs));
1444 pp_character (buffer, '[');
1445 if (xloc.file)
1447 pp_string (buffer, xloc.file);
1448 pp_string (buffer, " : ");
1450 pp_decimal_int (buffer, xloc.line);
1451 pp_string (buffer, "] ");
1454 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
1455 && gimple_has_mem_ops (gs))
1456 dump_gimple_mem_ops (buffer, gs, spc, flags);
1458 switch (gimple_code (gs))
1460 case GIMPLE_ASM:
1461 dump_gimple_asm (buffer, gs, spc, flags);
1462 break;
1464 case GIMPLE_ASSIGN:
1465 dump_gimple_assign (buffer, gs, spc, flags);
1466 break;
1468 case GIMPLE_BIND:
1469 dump_gimple_bind (buffer, gs, spc, flags);
1470 break;
1472 case GIMPLE_CALL:
1473 dump_gimple_call (buffer, gs, spc, flags);
1474 break;
1476 case GIMPLE_COND:
1477 dump_gimple_cond (buffer, gs, spc, flags);
1478 break;
1480 case GIMPLE_LABEL:
1481 dump_gimple_label (buffer, gs, spc, flags);
1482 break;
1484 case GIMPLE_GOTO:
1485 dump_gimple_goto (buffer, gs, spc, flags);
1486 break;
1488 case GIMPLE_NOP:
1489 pp_string (buffer, "GIMPLE_NOP");
1490 break;
1492 case GIMPLE_RETURN:
1493 dump_gimple_return (buffer, gs, spc, flags);
1494 break;
1496 case GIMPLE_SWITCH:
1497 dump_gimple_switch (buffer, gs, spc, flags);
1498 break;
1500 case GIMPLE_TRY:
1501 dump_gimple_try (buffer, gs, spc, flags);
1502 break;
1504 case GIMPLE_PHI:
1505 dump_gimple_phi (buffer, gs, spc, flags);
1506 break;
1508 case GIMPLE_OMP_PARALLEL:
1509 dump_gimple_omp_parallel (buffer, gs, spc, flags);
1510 break;
1512 case GIMPLE_OMP_TASK:
1513 dump_gimple_omp_task (buffer, gs, spc, flags);
1514 break;
1516 case GIMPLE_OMP_ATOMIC_LOAD:
1517 dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
1519 break;
1521 case GIMPLE_OMP_ATOMIC_STORE:
1522 dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
1523 break;
1525 case GIMPLE_OMP_FOR:
1526 dump_gimple_omp_for (buffer, gs, spc, flags);
1527 break;
1529 case GIMPLE_OMP_CONTINUE:
1530 dump_gimple_omp_continue (buffer, gs, spc, flags);
1531 break;
1533 case GIMPLE_OMP_SINGLE:
1534 dump_gimple_omp_single (buffer, gs, spc, flags);
1535 break;
1537 case GIMPLE_OMP_RETURN:
1538 dump_gimple_omp_return (buffer, gs, spc, flags);
1539 break;
1541 case GIMPLE_OMP_SECTIONS:
1542 dump_gimple_omp_sections (buffer, gs, spc, flags);
1543 break;
1545 case GIMPLE_OMP_SECTIONS_SWITCH:
1546 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
1547 break;
1549 case GIMPLE_OMP_MASTER:
1550 case GIMPLE_OMP_ORDERED:
1551 case GIMPLE_OMP_SECTION:
1552 dump_gimple_omp_block (buffer, gs, spc, flags);
1553 break;
1555 case GIMPLE_OMP_CRITICAL:
1556 dump_gimple_omp_critical (buffer, gs, spc, flags);
1557 break;
1559 case GIMPLE_CHANGE_DYNAMIC_TYPE:
1560 dump_gimple_cdt (buffer, gs, spc, flags);
1561 break;
1563 case GIMPLE_CATCH:
1564 dump_gimple_catch (buffer, gs, spc, flags);
1565 break;
1567 case GIMPLE_EH_FILTER:
1568 dump_gimple_eh_filter (buffer, gs, spc, flags);
1569 break;
1571 case GIMPLE_RESX:
1572 dump_gimple_resx (buffer, gs, spc, flags);
1573 break;
1575 case GIMPLE_PREDICT:
1576 pp_string (buffer, "// predicted ");
1577 if (gimple_predict_outcome (gs))
1578 pp_string (buffer, "likely by ");
1579 else
1580 pp_string (buffer, "unlikely by ");
1581 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
1582 pp_string (buffer, " predictor.");
1583 break;
1585 default:
1586 GIMPLE_NIY;
1589 /* If we're building a diagnostic, the formatted text will be
1590 written into BUFFER's stream by the caller; otherwise, write it
1591 now. */
1592 if (!(flags & TDF_DIAGNOSTIC))
1593 pp_write_text_to_stream (buffer);
1597 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
1598 spaces and details described by flags. */
1600 static void
1601 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
1603 edge e;
1604 gimple stmt;
1605 edge_iterator ei;
1607 if (flags & TDF_BLOCKS)
1609 INDENT (indent);
1610 pp_string (buffer, "# BLOCK ");
1611 pp_decimal_int (buffer, bb->index);
1612 if (bb->frequency)
1614 pp_string (buffer, " freq:");
1615 pp_decimal_int (buffer, bb->frequency);
1617 if (bb->count)
1619 pp_string (buffer, " count:");
1620 pp_widest_integer (buffer, bb->count);
1623 if (flags & TDF_LINENO)
1625 gimple_stmt_iterator gsi;
1627 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1628 if (get_lineno (gsi_stmt (gsi)) != -1)
1630 pp_string (buffer, ", starting at line ");
1631 pp_decimal_int (buffer, get_lineno (gsi_stmt (gsi)));
1632 break;
1635 newline_and_indent (buffer, indent);
1637 pp_string (buffer, "# PRED:");
1638 pp_write_text_to_stream (buffer);
1639 FOR_EACH_EDGE (e, ei, bb->preds)
1640 if (flags & TDF_SLIM)
1642 pp_string (buffer, " ");
1643 if (e->src == ENTRY_BLOCK_PTR)
1644 pp_string (buffer, "ENTRY");
1645 else
1646 pp_decimal_int (buffer, e->src->index);
1648 else
1649 dump_edge_info (buffer->buffer->stream, e, 0);
1650 pp_newline (buffer);
1652 else
1654 stmt = first_stmt (bb);
1655 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
1657 INDENT (indent - 2);
1658 pp_string (buffer, "<bb ");
1659 pp_decimal_int (buffer, bb->index);
1660 pp_string (buffer, ">:");
1661 pp_newline (buffer);
1664 pp_write_text_to_stream (buffer);
1665 check_bb_profile (bb, buffer->buffer->stream);
1669 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
1670 spaces. */
1672 static void
1673 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
1675 edge e;
1676 edge_iterator ei;
1678 INDENT (indent);
1679 pp_string (buffer, "# SUCC:");
1680 pp_write_text_to_stream (buffer);
1681 FOR_EACH_EDGE (e, ei, bb->succs)
1682 if (flags & TDF_SLIM)
1684 pp_string (buffer, " ");
1685 if (e->dest == EXIT_BLOCK_PTR)
1686 pp_string (buffer, "EXIT");
1687 else
1688 pp_decimal_int (buffer, e->dest->index);
1690 else
1691 dump_edge_info (buffer->buffer->stream, e, 1);
1692 pp_newline (buffer);
1696 /* Dump PHI nodes of basic block BB to BUFFER with details described
1697 by FLAGS and indented by INDENT spaces. */
1699 static void
1700 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
1702 gimple_stmt_iterator i;
1704 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
1706 gimple phi = gsi_stmt (i);
1707 if (is_gimple_reg (gimple_phi_result (phi)) || (flags & TDF_VOPS))
1709 INDENT (indent);
1710 pp_string (buffer, "# ");
1711 dump_gimple_phi (buffer, phi, indent, flags);
1712 pp_newline (buffer);
1718 /* Dump jump to basic block BB that is represented implicitly in the cfg
1719 to BUFFER. */
1721 static void
1722 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
1724 gimple stmt;
1726 stmt = first_stmt (bb);
1728 pp_string (buffer, "goto <bb ");
1729 pp_decimal_int (buffer, bb->index);
1730 pp_string (buffer, ">");
1731 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
1733 pp_string (buffer, " (");
1734 dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
1735 pp_string (buffer, ")");
1736 pp_semicolon (buffer);
1738 else
1739 pp_semicolon (buffer);
1743 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
1744 by INDENT spaces, with details given by FLAGS. */
1746 static void
1747 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
1748 int flags)
1750 edge e;
1751 edge_iterator ei;
1752 gimple stmt;
1754 stmt = last_stmt (bb);
1756 if (stmt && gimple_code (stmt) == GIMPLE_COND)
1758 edge true_edge, false_edge;
1760 /* When we are emitting the code or changing CFG, it is possible that
1761 the edges are not yet created. When we are using debug_bb in such
1762 a situation, we do not want it to crash. */
1763 if (EDGE_COUNT (bb->succs) != 2)
1764 return;
1765 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
1767 INDENT (indent + 2);
1768 pp_cfg_jump (buffer, true_edge->dest);
1769 newline_and_indent (buffer, indent);
1770 pp_string (buffer, "else");
1771 newline_and_indent (buffer, indent + 2);
1772 pp_cfg_jump (buffer, false_edge->dest);
1773 pp_newline (buffer);
1774 return;
1777 /* If there is a fallthru edge, we may need to add an artificial
1778 goto to the dump. */
1779 FOR_EACH_EDGE (e, ei, bb->succs)
1780 if (e->flags & EDGE_FALLTHRU)
1781 break;
1783 if (e && e->dest != bb->next_bb)
1785 INDENT (indent);
1787 if ((flags & TDF_LINENO)
1788 && e->goto_locus != UNKNOWN_LOCATION
1791 expanded_location goto_xloc;
1792 goto_xloc = expand_location (e->goto_locus);
1793 pp_character (buffer, '[');
1794 if (goto_xloc.file)
1796 pp_string (buffer, goto_xloc.file);
1797 pp_string (buffer, " : ");
1799 pp_decimal_int (buffer, goto_xloc.line);
1800 pp_string (buffer, "] ");
1803 pp_cfg_jump (buffer, e->dest);
1804 pp_newline (buffer);
1809 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
1810 indented by INDENT spaces. */
1812 static void
1813 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
1814 int flags)
1816 gimple_stmt_iterator gsi;
1817 gimple stmt;
1818 int label_indent = indent - 2;
1820 if (label_indent < 0)
1821 label_indent = 0;
1823 dump_bb_header (buffer, bb, indent, flags);
1824 dump_phi_nodes (buffer, bb, indent, flags);
1826 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1828 int curr_indent;
1830 stmt = gsi_stmt (gsi);
1832 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
1834 INDENT (curr_indent);
1835 dump_gimple_stmt (buffer, stmt, curr_indent, flags);
1836 pp_newline (buffer);
1837 dump_histograms_for_stmt (cfun, buffer->buffer->stream, stmt);
1840 dump_implicit_edges (buffer, bb, indent, flags);
1842 if (flags & TDF_BLOCKS)
1843 dump_bb_end (buffer, bb, indent, flags);
1847 /* Dumps basic block BB to FILE with details described by FLAGS and
1848 indented by INDENT spaces. */
1850 void
1851 gimple_dump_bb (basic_block bb, FILE *file, int indent, int flags)
1853 maybe_init_pretty_print (file);
1854 gimple_dump_bb_buff (&buffer, bb, indent, flags);
1855 pp_flush (&buffer);