In gcc/: 2011-04-14 Nicola Pero <nicola.pero@meta-innovation.com>
[official-gcc.git] / gcc / gimple-pretty-print.c
blobd841929fd84321dcd502beaa45913cdb3f219112
1 /* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Aldy Hernandez <aldyh@redhat.com> and
5 Diego Novillo <dnovillo@google.com>
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "diagnostic.h"
29 #include "tree-pretty-print.h"
30 #include "gimple-pretty-print.h"
31 #include "hashtab.h"
32 #include "tree-flow.h"
33 #include "tree-pass.h"
34 #include "gimple.h"
35 #include "value-prof.h"
37 #define INDENT(SPACE) \
38 do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
40 static pretty_printer buffer;
41 static bool initialized = false;
43 #define GIMPLE_NIY do_niy (buffer,gs)
45 /* Try to print on BUFFER a default message for the unrecognized
46 gimple statement GS. */
48 static void
49 do_niy (pretty_printer *buffer, gimple gs)
51 pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
52 gimple_code_name[(int) gimple_code (gs)]);
56 /* Initialize the pretty printer on FILE if needed. */
58 static void
59 maybe_init_pretty_print (FILE *file)
61 if (!initialized)
63 pp_construct (&buffer, NULL, 0);
64 pp_needs_newline (&buffer) = true;
65 initialized = true;
68 buffer.buffer->stream = file;
72 /* Emit a newline and SPC indentantion spaces to BUFFER. */
74 static void
75 newline_and_indent (pretty_printer *buffer, int spc)
77 pp_newline (buffer);
78 INDENT (spc);
82 /* Print the GIMPLE statement GS on stderr. */
84 DEBUG_FUNCTION void
85 debug_gimple_stmt (gimple gs)
87 print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
88 fprintf (stderr, "\n");
92 /* Dump GIMPLE statement G to FILE using SPC indentantion spaces and
93 FLAGS as in dump_gimple_stmt. */
95 void
96 print_gimple_stmt (FILE *file, gimple g, int spc, int flags)
98 maybe_init_pretty_print (file);
99 dump_gimple_stmt (&buffer, g, spc, flags);
100 pp_flush (&buffer);
104 /* Dump GIMPLE statement G to FILE using SPC indentantion spaces and
105 FLAGS as in dump_gimple_stmt. Print only the right-hand side
106 of the statement. */
108 void
109 print_gimple_expr (FILE *file, gimple g, int spc, int flags)
111 flags |= TDF_RHS_ONLY;
112 maybe_init_pretty_print (file);
113 dump_gimple_stmt (&buffer, g, spc, flags);
117 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentantion
118 spaces and FLAGS as in dump_gimple_stmt. */
120 static void
121 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc, int flags)
123 gimple_stmt_iterator i;
125 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
127 gimple gs = gsi_stmt (i);
128 INDENT (spc);
129 dump_gimple_stmt (buffer, gs, spc, flags);
130 if (!gsi_one_before_end_p (i))
131 pp_newline (buffer);
136 /* Dump GIMPLE sequence SEQ to FILE using SPC indentantion spaces and
137 FLAGS as in dump_gimple_stmt. */
139 void
140 print_gimple_seq (FILE *file, gimple_seq seq, int spc, int flags)
142 maybe_init_pretty_print (file);
143 dump_gimple_seq (&buffer, seq, spc, flags);
144 pp_flush (&buffer);
148 /* Print the GIMPLE sequence SEQ on stderr. */
150 DEBUG_FUNCTION void
151 debug_gimple_seq (gimple_seq seq)
153 print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
157 /* A simple helper to pretty-print some of the gimple tuples in the printf
158 style. The format modifiers are preceeded by '%' and are:
159 'G' - outputs a string corresponding to the code of the given gimple,
160 'S' - outputs a gimple_seq with indent of spc + 2,
161 'T' - outputs the tree t,
162 'd' - outputs an int as a decimal,
163 's' - outputs a string,
164 'n' - outputs a newline,
165 '+' - increases indent by 2 then outputs a newline,
166 '-' - decreases indent by 2 then outputs a newline. */
168 static void
169 dump_gimple_fmt (pretty_printer *buffer, int spc, int flags,
170 const char *fmt, ...)
172 va_list args;
173 const char *c;
174 const char *tmp;
176 va_start (args, fmt);
177 for (c = fmt; *c; c++)
179 if (*c == '%')
181 gimple_seq seq;
182 tree t;
183 gimple g;
184 switch (*++c)
186 case 'G':
187 g = va_arg (args, gimple);
188 tmp = gimple_code_name[gimple_code (g)];
189 pp_string (buffer, tmp);
190 break;
192 case 'S':
193 seq = va_arg (args, gimple_seq);
194 pp_newline (buffer);
195 dump_gimple_seq (buffer, seq, spc + 2, flags);
196 newline_and_indent (buffer, spc);
197 break;
199 case 'T':
200 t = va_arg (args, tree);
201 if (t == NULL_TREE)
202 pp_string (buffer, "NULL");
203 else
204 dump_generic_node (buffer, t, spc, flags, false);
205 break;
207 case 'd':
208 pp_decimal_int (buffer, va_arg (args, int));
209 break;
211 case 's':
212 pp_string (buffer, va_arg (args, char *));
213 break;
215 case 'n':
216 newline_and_indent (buffer, spc);
217 break;
219 case '+':
220 spc += 2;
221 newline_and_indent (buffer, spc);
222 break;
224 case '-':
225 spc -= 2;
226 newline_and_indent (buffer, spc);
227 break;
229 default:
230 gcc_unreachable ();
233 else
234 pp_character (buffer, *c);
236 va_end (args);
240 /* Helper for dump_gimple_assign. Print the unary RHS of the
241 assignment GS. BUFFER, SPC and FLAGS are as in dump_gimple_stmt. */
243 static void
244 dump_unary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
246 enum tree_code rhs_code = gimple_assign_rhs_code (gs);
247 tree lhs = gimple_assign_lhs (gs);
248 tree rhs = gimple_assign_rhs1 (gs);
250 switch (rhs_code)
252 case VIEW_CONVERT_EXPR:
253 case ASSERT_EXPR:
254 dump_generic_node (buffer, rhs, spc, flags, false);
255 break;
257 case FIXED_CONVERT_EXPR:
258 case ADDR_SPACE_CONVERT_EXPR:
259 case FIX_TRUNC_EXPR:
260 case FLOAT_EXPR:
261 CASE_CONVERT:
262 pp_character (buffer, '(');
263 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
264 pp_string (buffer, ") ");
265 if (op_prio (rhs) < op_code_prio (rhs_code))
267 pp_character (buffer, '(');
268 dump_generic_node (buffer, rhs, spc, flags, false);
269 pp_character (buffer, ')');
271 else
272 dump_generic_node (buffer, rhs, spc, flags, false);
273 break;
275 case PAREN_EXPR:
276 pp_string (buffer, "((");
277 dump_generic_node (buffer, rhs, spc, flags, false);
278 pp_string (buffer, "))");
279 break;
281 case ABS_EXPR:
282 pp_string (buffer, "ABS_EXPR <");
283 dump_generic_node (buffer, rhs, spc, flags, false);
284 pp_character (buffer, '>');
285 break;
287 default:
288 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
289 || TREE_CODE_CLASS (rhs_code) == tcc_constant
290 || TREE_CODE_CLASS (rhs_code) == tcc_reference
291 || rhs_code == SSA_NAME
292 || rhs_code == ADDR_EXPR
293 || rhs_code == CONSTRUCTOR)
295 dump_generic_node (buffer, rhs, spc, flags, false);
296 break;
298 else if (rhs_code == BIT_NOT_EXPR)
299 pp_character (buffer, '~');
300 else if (rhs_code == TRUTH_NOT_EXPR)
301 pp_character (buffer, '!');
302 else if (rhs_code == NEGATE_EXPR)
303 pp_character (buffer, '-');
304 else
306 pp_character (buffer, '[');
307 pp_string (buffer, tree_code_name [rhs_code]);
308 pp_string (buffer, "] ");
311 if (op_prio (rhs) < op_code_prio (rhs_code))
313 pp_character (buffer, '(');
314 dump_generic_node (buffer, rhs, spc, flags, false);
315 pp_character (buffer, ')');
317 else
318 dump_generic_node (buffer, rhs, spc, flags, false);
319 break;
324 /* Helper for dump_gimple_assign. Print the binary RHS of the
325 assignment GS. BUFFER, SPC and FLAGS are as in dump_gimple_stmt. */
327 static void
328 dump_binary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
330 const char *p;
331 enum tree_code code = gimple_assign_rhs_code (gs);
332 switch (code)
334 case COMPLEX_EXPR:
335 case MIN_EXPR:
336 case MAX_EXPR:
337 case VEC_WIDEN_MULT_HI_EXPR:
338 case VEC_WIDEN_MULT_LO_EXPR:
339 case VEC_PACK_TRUNC_EXPR:
340 case VEC_PACK_SAT_EXPR:
341 case VEC_PACK_FIX_TRUNC_EXPR:
342 case VEC_EXTRACT_EVEN_EXPR:
343 case VEC_EXTRACT_ODD_EXPR:
344 case VEC_INTERLEAVE_HIGH_EXPR:
345 case VEC_INTERLEAVE_LOW_EXPR:
346 for (p = tree_code_name [(int) code]; *p; p++)
347 pp_character (buffer, TOUPPER (*p));
348 pp_string (buffer, " <");
349 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
350 pp_string (buffer, ", ");
351 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
352 pp_character (buffer, '>');
353 break;
355 default:
356 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
358 pp_character (buffer, '(');
359 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
360 false);
361 pp_character (buffer, ')');
363 else
364 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
365 pp_space (buffer);
366 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
367 pp_space (buffer);
368 if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
370 pp_character (buffer, '(');
371 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
372 false);
373 pp_character (buffer, ')');
375 else
376 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
380 /* Helper for dump_gimple_assign. Print the ternary RHS of the
381 assignment GS. BUFFER, SPC and FLAGS are as in dump_gimple_stmt. */
383 static void
384 dump_ternary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
386 const char *p;
387 enum tree_code code = gimple_assign_rhs_code (gs);
388 switch (code)
390 case WIDEN_MULT_PLUS_EXPR:
391 case WIDEN_MULT_MINUS_EXPR:
392 for (p = tree_code_name [(int) code]; *p; p++)
393 pp_character (buffer, TOUPPER (*p));
394 pp_string (buffer, " <");
395 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
396 pp_string (buffer, ", ");
397 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
398 pp_string (buffer, ", ");
399 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
400 pp_character (buffer, '>');
401 break;
403 case FMA_EXPR:
404 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
405 pp_string (buffer, " * ");
406 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
407 pp_string (buffer, " + ");
408 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
409 break;
411 case DOT_PROD_EXPR:
412 pp_string (buffer, "DOT_PROD_EXPR <");
413 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
414 pp_string (buffer, ", ");
415 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
416 pp_string (buffer, ", ");
417 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
418 pp_string (buffer, ">");
419 break;
421 case REALIGN_LOAD_EXPR:
422 pp_string (buffer, "REALIGN_LOAD <");
423 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
424 pp_string (buffer, ", ");
425 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
426 pp_string (buffer, ", ");
427 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
428 pp_string (buffer, ">");
429 break;
431 default:
432 gcc_unreachable ();
437 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
438 dump_gimple_stmt. */
440 static void
441 dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
443 if (flags & TDF_RAW)
445 tree last;
446 if (gimple_num_ops (gs) == 2)
447 last = NULL_TREE;
448 else if (gimple_num_ops (gs) == 3)
449 last = gimple_assign_rhs2 (gs);
450 else
451 gcc_unreachable ();
453 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T>", gs,
454 tree_code_name[gimple_assign_rhs_code (gs)],
455 gimple_assign_lhs (gs), gimple_assign_rhs1 (gs), last);
457 else
459 if (!(flags & TDF_RHS_ONLY))
461 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
462 pp_space (buffer);
463 pp_character (buffer, '=');
465 if (gimple_assign_nontemporal_move_p (gs))
466 pp_string (buffer, "{nt}");
468 if (gimple_has_volatile_ops (gs))
469 pp_string (buffer, "{v}");
471 pp_space (buffer);
474 if (gimple_num_ops (gs) == 2)
475 dump_unary_rhs (buffer, gs, spc, flags);
476 else if (gimple_num_ops (gs) == 3)
477 dump_binary_rhs (buffer, gs, spc, flags);
478 else if (gimple_num_ops (gs) == 4)
479 dump_ternary_rhs (buffer, gs, spc, flags);
480 else
481 gcc_unreachable ();
482 if (!(flags & TDF_RHS_ONLY))
483 pp_semicolon(buffer);
488 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
489 dump_gimple_stmt. */
491 static void
492 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
494 tree t;
496 t = gimple_return_retval (gs);
497 if (flags & TDF_RAW)
498 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
499 else
501 pp_string (buffer, "return");
502 if (t)
504 pp_space (buffer);
505 dump_generic_node (buffer, t, spc, flags, false);
507 pp_semicolon (buffer);
512 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
513 dump_gimple_call. */
515 static void
516 dump_gimple_call_args (pretty_printer *buffer, gimple gs, int flags)
518 size_t i;
520 for (i = 0; i < gimple_call_num_args (gs); i++)
522 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
523 if (i < gimple_call_num_args (gs) - 1)
524 pp_string (buffer, ", ");
527 if (gimple_call_va_arg_pack_p (gs))
529 if (gimple_call_num_args (gs) > 0)
531 pp_character (buffer, ',');
532 pp_space (buffer);
535 pp_string (buffer, "__builtin_va_arg_pack ()");
539 /* Dump the points-to solution *PT to BUFFER. */
541 static void
542 pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
544 if (pt->anything)
546 pp_string (buffer, "anything ");
547 return;
549 if (pt->nonlocal)
550 pp_string (buffer, "nonlocal ");
551 if (pt->escaped)
552 pp_string (buffer, "escaped ");
553 if (pt->ipa_escaped)
554 pp_string (buffer, "unit-escaped ");
555 if (pt->null)
556 pp_string (buffer, "null ");
557 if (pt->vars
558 && !bitmap_empty_p (pt->vars))
560 bitmap_iterator bi;
561 unsigned i;
562 pp_string (buffer, "{ ");
563 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
565 tree var = referenced_var_lookup (cfun, i);
566 if (var)
568 dump_generic_node (buffer, var, 0, dump_flags, false);
569 if (DECL_PT_UID (var) != DECL_UID (var))
571 pp_string (buffer, "ptD.");
572 pp_decimal_int (buffer, DECL_PT_UID (var));
575 else
577 pp_string (buffer, "D.");
578 pp_decimal_int (buffer, i);
580 pp_character (buffer, ' ');
582 pp_character (buffer, '}');
583 if (pt->vars_contains_global)
584 pp_string (buffer, " (glob)");
585 if (pt->vars_contains_restrict)
586 pp_string (buffer, " (restr)");
590 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
591 dump_gimple_stmt. */
593 static void
594 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
596 tree lhs = gimple_call_lhs (gs);
598 if (flags & TDF_ALIAS)
600 struct pt_solution *pt;
601 pt = gimple_call_use_set (gs);
602 if (!pt_solution_empty_p (pt))
604 pp_string (buffer, "# USE = ");
605 pp_points_to_solution (buffer, pt);
606 newline_and_indent (buffer, spc);
608 pt = gimple_call_clobber_set (gs);
609 if (!pt_solution_empty_p (pt))
611 pp_string (buffer, "# CLB = ");
612 pp_points_to_solution (buffer, pt);
613 newline_and_indent (buffer, spc);
617 if (flags & TDF_RAW)
619 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T",
620 gs, gimple_call_fn (gs), lhs);
621 if (gimple_call_num_args (gs) > 0)
623 pp_string (buffer, ", ");
624 dump_gimple_call_args (buffer, gs, flags);
626 pp_character (buffer, '>');
628 else
630 if (lhs && !(flags & TDF_RHS_ONLY))
632 dump_generic_node (buffer, lhs, spc, flags, false);
633 pp_string (buffer, " =");
635 if (gimple_has_volatile_ops (gs))
636 pp_string (buffer, "{v}");
638 pp_space (buffer);
640 print_call_name (buffer, gimple_call_fn (gs), flags);
641 pp_string (buffer, " (");
642 dump_gimple_call_args (buffer, gs, flags);
643 pp_character (buffer, ')');
644 if (!(flags & TDF_RHS_ONLY))
645 pp_semicolon (buffer);
648 if (gimple_call_chain (gs))
650 pp_string (buffer, " [static-chain: ");
651 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
652 pp_character (buffer, ']');
655 if (gimple_call_return_slot_opt_p (gs))
656 pp_string (buffer, " [return slot optimization]");
658 if (gimple_call_tail_p (gs))
659 pp_string (buffer, " [tail call]");
663 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
664 dump_gimple_stmt. */
666 static void
667 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
669 unsigned int i;
671 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
672 if (flags & TDF_RAW)
673 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
674 gimple_switch_index (gs));
675 else
677 pp_string (buffer, "switch (");
678 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
679 pp_string (buffer, ") <");
682 for (i = 0; i < gimple_switch_num_labels (gs); i++)
684 tree case_label = gimple_switch_label (gs, i);
685 if (case_label == NULL_TREE)
686 continue;
688 dump_generic_node (buffer, case_label, spc, flags, false);
689 pp_character (buffer, ' ');
690 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
691 if (i < gimple_switch_num_labels (gs) - 1)
692 pp_string (buffer, ", ");
694 pp_character (buffer, '>');
698 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
699 dump_gimple_stmt. */
701 static void
702 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
704 if (flags & TDF_RAW)
705 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
706 tree_code_name [gimple_cond_code (gs)],
707 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
708 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
709 else
711 if (!(flags & TDF_RHS_ONLY))
712 pp_string (buffer, "if (");
713 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
714 pp_space (buffer);
715 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
716 pp_space (buffer);
717 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
718 if (!(flags & TDF_RHS_ONLY))
720 pp_character (buffer, ')');
722 if (gimple_cond_true_label (gs))
724 pp_string (buffer, " goto ");
725 dump_generic_node (buffer, gimple_cond_true_label (gs),
726 spc, flags, false);
727 pp_semicolon (buffer);
729 if (gimple_cond_false_label (gs))
731 pp_string (buffer, " else goto ");
732 dump_generic_node (buffer, gimple_cond_false_label (gs),
733 spc, flags, false);
734 pp_semicolon (buffer);
741 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
742 spaces of indent. FLAGS specifies details to show in the dump (see
743 TDF_* in tree-pass.h). */
745 static void
746 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
748 tree label = gimple_label_label (gs);
749 if (flags & TDF_RAW)
750 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
751 else
753 dump_generic_node (buffer, label, spc, flags, false);
754 pp_character (buffer, ':');
756 if (DECL_NONLOCAL (label))
757 pp_string (buffer, " [non-local]");
758 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
759 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
762 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
763 spaces of indent. FLAGS specifies details to show in the dump (see
764 TDF_* in tree-pass.h). */
766 static void
767 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
769 tree label = gimple_goto_dest (gs);
770 if (flags & TDF_RAW)
771 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
772 else
773 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
777 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
778 spaces of indent. FLAGS specifies details to show in the dump (see
779 TDF_* in tree-pass.h). */
781 static void
782 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
784 if (flags & TDF_RAW)
785 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
786 else
787 pp_character (buffer, '{');
788 if (!(flags & TDF_SLIM))
790 tree var;
792 for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
794 newline_and_indent (buffer, 2);
795 print_declaration (buffer, var, spc, flags);
797 if (gimple_bind_vars (gs))
798 pp_newline (buffer);
800 pp_newline (buffer);
801 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
802 newline_and_indent (buffer, spc);
803 if (flags & TDF_RAW)
804 pp_character (buffer, '>');
805 else
806 pp_character (buffer, '}');
810 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
811 indent. FLAGS specifies details to show in the dump (see TDF_* in
812 tree-pass.h). */
814 static void
815 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
817 if (flags & TDF_RAW)
819 const char *type;
820 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
821 type = "GIMPLE_TRY_CATCH";
822 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
823 type = "GIMPLE_TRY_FINALLY";
824 else
825 type = "UNKNOWN GIMPLE_TRY";
826 dump_gimple_fmt (buffer, spc, flags,
827 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
828 gimple_try_eval (gs), gimple_try_cleanup (gs));
830 else
832 pp_string (buffer, "try");
833 newline_and_indent (buffer, spc + 2);
834 pp_character (buffer, '{');
835 pp_newline (buffer);
837 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
838 newline_and_indent (buffer, spc + 2);
839 pp_character (buffer, '}');
841 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
843 newline_and_indent (buffer, spc);
844 pp_string (buffer, "catch");
845 newline_and_indent (buffer, spc + 2);
846 pp_character (buffer, '{');
848 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
850 newline_and_indent (buffer, spc);
851 pp_string (buffer, "finally");
852 newline_and_indent (buffer, spc + 2);
853 pp_character (buffer, '{');
855 else
856 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
858 pp_newline (buffer);
859 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
860 newline_and_indent (buffer, spc + 2);
861 pp_character (buffer, '}');
866 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
867 indent. FLAGS specifies details to show in the dump (see TDF_* in
868 tree-pass.h). */
870 static void
871 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
873 if (flags & TDF_RAW)
874 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
875 gimple_catch_types (gs), gimple_catch_handler (gs));
876 else
877 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
878 gimple_catch_types (gs), gimple_catch_handler (gs));
882 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
883 indent. FLAGS specifies details to show in the dump (see TDF_* in
884 tree-pass.h). */
886 static void
887 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
889 if (flags & TDF_RAW)
890 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
891 gimple_eh_filter_types (gs),
892 gimple_eh_filter_failure (gs));
893 else
894 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
895 gimple_eh_filter_types (gs),
896 gimple_eh_filter_failure (gs));
900 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
902 static void
903 dump_gimple_eh_must_not_throw (pretty_printer *buffer, gimple gs,
904 int spc, int flags)
906 if (flags & TDF_RAW)
907 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
908 gimple_eh_must_not_throw_fndecl (gs));
909 else
910 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
911 gimple_eh_must_not_throw_fndecl (gs));
915 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
916 indent. FLAGS specifies details to show in the dump (see TDF_* in
917 tree-pass.h). */
919 static void
920 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
922 if (flags & TDF_RAW)
923 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
924 gimple_resx_region (gs));
925 else
926 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
929 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
931 static void
932 dump_gimple_eh_dispatch (pretty_printer *buffer, gimple gs, int spc, int flags)
934 if (flags & TDF_RAW)
935 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
936 gimple_eh_dispatch_region (gs));
937 else
938 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
939 gimple_eh_dispatch_region (gs));
942 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
943 of indent. FLAGS specifies details to show in the dump (see TDF_*
944 in tree-pass.h). */
946 static void
947 dump_gimple_debug (pretty_printer *buffer, gimple gs, int spc, int flags)
949 switch (gs->gsbase.subcode)
951 case GIMPLE_DEBUG_BIND:
952 if (flags & TDF_RAW)
953 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
954 gimple_debug_bind_get_var (gs),
955 gimple_debug_bind_get_value (gs));
956 else
957 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
958 gimple_debug_bind_get_var (gs),
959 gimple_debug_bind_get_value (gs));
960 break;
962 default:
963 gcc_unreachable ();
967 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
968 static void
969 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
971 size_t i;
973 if (flags & TDF_RAW)
975 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
976 gimple_omp_body (gs));
977 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
978 dump_gimple_fmt (buffer, spc, flags, " >,");
979 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
980 dump_gimple_fmt (buffer, spc, flags,
981 "%+%T, %T, %T, %s, %T,%n",
982 gimple_omp_for_index (gs, i),
983 gimple_omp_for_initial (gs, i),
984 gimple_omp_for_final (gs, i),
985 tree_code_name[gimple_omp_for_cond (gs, i)],
986 gimple_omp_for_incr (gs, i));
987 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
988 gimple_omp_for_pre_body (gs));
990 else
992 pp_string (buffer, "#pragma omp for");
993 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
994 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
996 if (i)
997 spc += 2;
998 newline_and_indent (buffer, spc);
999 pp_string (buffer, "for (");
1000 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1001 flags, false);
1002 pp_string (buffer, " = ");
1003 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1004 flags, false);
1005 pp_string (buffer, "; ");
1007 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1008 flags, false);
1009 pp_space (buffer);
1010 switch (gimple_omp_for_cond (gs, i))
1012 case LT_EXPR:
1013 pp_character (buffer, '<');
1014 break;
1015 case GT_EXPR:
1016 pp_character (buffer, '>');
1017 break;
1018 case LE_EXPR:
1019 pp_string (buffer, "<=");
1020 break;
1021 case GE_EXPR:
1022 pp_string (buffer, ">=");
1023 break;
1024 default:
1025 gcc_unreachable ();
1027 pp_space (buffer);
1028 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1029 flags, false);
1030 pp_string (buffer, "; ");
1032 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1033 flags, false);
1034 pp_string (buffer, " = ");
1035 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1036 flags, false);
1037 pp_character (buffer, ')');
1040 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1042 newline_and_indent (buffer, spc + 2);
1043 pp_character (buffer, '{');
1044 pp_newline (buffer);
1045 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1046 newline_and_indent (buffer, spc + 2);
1047 pp_character (buffer, '}');
1052 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
1054 static void
1055 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
1057 if (flags & TDF_RAW)
1059 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1060 gimple_omp_continue_control_def (gs),
1061 gimple_omp_continue_control_use (gs));
1063 else
1065 pp_string (buffer, "#pragma omp continue (");
1066 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1067 spc, flags, false);
1068 pp_character (buffer, ',');
1069 pp_space (buffer);
1070 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1071 spc, flags, false);
1072 pp_character (buffer, ')');
1076 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1078 static void
1079 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
1081 if (flags & TDF_RAW)
1083 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1084 gimple_omp_body (gs));
1085 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1086 dump_gimple_fmt (buffer, spc, flags, " >");
1088 else
1090 pp_string (buffer, "#pragma omp single");
1091 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1092 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1094 newline_and_indent (buffer, spc + 2);
1095 pp_character (buffer, '{');
1096 pp_newline (buffer);
1097 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1098 newline_and_indent (buffer, spc + 2);
1099 pp_character (buffer, '}');
1104 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1106 static void
1107 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
1108 int flags)
1110 if (flags & TDF_RAW)
1112 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1113 gimple_omp_body (gs));
1114 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1115 dump_gimple_fmt (buffer, spc, flags, " >");
1117 else
1119 pp_string (buffer, "#pragma omp sections");
1120 if (gimple_omp_sections_control (gs))
1122 pp_string (buffer, " <");
1123 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1124 flags, false);
1125 pp_character (buffer, '>');
1127 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1128 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1130 newline_and_indent (buffer, spc + 2);
1131 pp_character (buffer, '{');
1132 pp_newline (buffer);
1133 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1134 newline_and_indent (buffer, spc + 2);
1135 pp_character (buffer, '}');
1140 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer
1141 BUFFER. */
1143 static void
1144 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
1146 if (flags & TDF_RAW)
1147 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1148 gimple_omp_body (gs));
1149 else
1151 switch (gimple_code (gs))
1153 case GIMPLE_OMP_MASTER:
1154 pp_string (buffer, "#pragma omp master");
1155 break;
1156 case GIMPLE_OMP_ORDERED:
1157 pp_string (buffer, "#pragma omp ordered");
1158 break;
1159 case GIMPLE_OMP_SECTION:
1160 pp_string (buffer, "#pragma omp section");
1161 break;
1162 default:
1163 gcc_unreachable ();
1165 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1167 newline_and_indent (buffer, spc + 2);
1168 pp_character (buffer, '{');
1169 pp_newline (buffer);
1170 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1171 newline_and_indent (buffer, spc + 2);
1172 pp_character (buffer, '}');
1177 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1179 static void
1180 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
1181 int flags)
1183 if (flags & TDF_RAW)
1184 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1185 gimple_omp_body (gs));
1186 else
1188 pp_string (buffer, "#pragma omp critical");
1189 if (gimple_omp_critical_name (gs))
1191 pp_string (buffer, " (");
1192 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1193 flags, false);
1194 pp_character (buffer, ')');
1196 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1198 newline_and_indent (buffer, spc + 2);
1199 pp_character (buffer, '{');
1200 pp_newline (buffer);
1201 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1202 newline_and_indent (buffer, spc + 2);
1203 pp_character (buffer, '}');
1208 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1210 static void
1211 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1213 if (flags & TDF_RAW)
1215 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d>", gs,
1216 (int) gimple_omp_return_nowait_p (gs));
1218 else
1220 pp_string (buffer, "#pragma omp return");
1221 if (gimple_omp_return_nowait_p (gs))
1222 pp_string (buffer, "(nowait)");
1226 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1227 indent. FLAGS specifies details to show in the dump (see TDF_* in
1228 tree-pass.h). */
1230 static void
1231 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1233 unsigned int i, n, f, fields;
1235 if (flags & TDF_RAW)
1237 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1238 gimple_asm_string (gs));
1240 n = gimple_asm_noutputs (gs);
1241 if (n)
1243 newline_and_indent (buffer, spc + 2);
1244 pp_string (buffer, "OUTPUT: ");
1245 for (i = 0; i < n; i++)
1247 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1248 spc, flags, false);
1249 if (i < n - 1)
1250 pp_string (buffer, ", ");
1254 n = gimple_asm_ninputs (gs);
1255 if (n)
1257 newline_and_indent (buffer, spc + 2);
1258 pp_string (buffer, "INPUT: ");
1259 for (i = 0; i < n; i++)
1261 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1262 spc, flags, false);
1263 if (i < n - 1)
1264 pp_string (buffer, ", ");
1268 n = gimple_asm_nclobbers (gs);
1269 if (n)
1271 newline_and_indent (buffer, spc + 2);
1272 pp_string (buffer, "CLOBBER: ");
1273 for (i = 0; i < n; i++)
1275 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1276 spc, flags, false);
1277 if (i < n - 1)
1278 pp_string (buffer, ", ");
1282 n = gimple_asm_nlabels (gs);
1283 if (n)
1285 newline_and_indent (buffer, spc + 2);
1286 pp_string (buffer, "LABEL: ");
1287 for (i = 0; i < n; i++)
1289 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1290 spc, flags, false);
1291 if (i < n - 1)
1292 pp_string (buffer, ", ");
1296 newline_and_indent (buffer, spc);
1297 pp_character (buffer, '>');
1299 else
1301 pp_string (buffer, "__asm__");
1302 if (gimple_asm_volatile_p (gs))
1303 pp_string (buffer, " __volatile__");
1304 if (gimple_asm_nlabels (gs))
1305 pp_string (buffer, " goto");
1306 pp_string (buffer, "(\"");
1307 pp_string (buffer, gimple_asm_string (gs));
1308 pp_string (buffer, "\"");
1310 if (gimple_asm_nlabels (gs))
1311 fields = 4;
1312 else if (gimple_asm_nclobbers (gs))
1313 fields = 3;
1314 else if (gimple_asm_ninputs (gs))
1315 fields = 2;
1316 else if (gimple_asm_noutputs (gs))
1317 fields = 1;
1318 else
1319 fields = 0;
1321 for (f = 0; f < fields; ++f)
1323 pp_string (buffer, " : ");
1325 switch (f)
1327 case 0:
1328 n = gimple_asm_noutputs (gs);
1329 for (i = 0; i < n; i++)
1331 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1332 spc, flags, false);
1333 if (i < n - 1)
1334 pp_string (buffer, ", ");
1336 break;
1338 case 1:
1339 n = gimple_asm_ninputs (gs);
1340 for (i = 0; i < n; i++)
1342 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1343 spc, flags, false);
1344 if (i < n - 1)
1345 pp_string (buffer, ", ");
1347 break;
1349 case 2:
1350 n = gimple_asm_nclobbers (gs);
1351 for (i = 0; i < n; i++)
1353 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1354 spc, flags, false);
1355 if (i < n - 1)
1356 pp_string (buffer, ", ");
1358 break;
1360 case 3:
1361 n = gimple_asm_nlabels (gs);
1362 for (i = 0; i < n; i++)
1364 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1365 spc, flags, false);
1366 if (i < n - 1)
1367 pp_string (buffer, ", ");
1369 break;
1371 default:
1372 gcc_unreachable ();
1376 pp_string (buffer, ");");
1381 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in
1382 dump_gimple_stmt. */
1384 static void
1385 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
1387 size_t i;
1388 tree lhs = gimple_phi_result (phi);
1390 if (flags & TDF_ALIAS
1391 && POINTER_TYPE_P (TREE_TYPE (lhs))
1392 && SSA_NAME_PTR_INFO (lhs))
1394 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
1395 pp_string (buffer, "PT = ");
1396 pp_points_to_solution (buffer, &pi->pt);
1397 newline_and_indent (buffer, spc);
1398 if (pi->align != 1)
1399 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u",
1400 pi->align, pi->misalign);
1401 newline_and_indent (buffer, spc);
1402 pp_string (buffer, "# ");
1405 if (flags & TDF_RAW)
1406 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1407 gimple_phi_result (phi));
1408 else
1410 dump_generic_node (buffer, lhs, spc, flags, false);
1411 pp_string (buffer, " = PHI <");
1413 for (i = 0; i < gimple_phi_num_args (phi); i++)
1415 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1417 expanded_location xloc;
1419 xloc = expand_location (gimple_phi_arg_location (phi, i));
1420 pp_character (buffer, '[');
1421 if (xloc.file)
1423 pp_string (buffer, xloc.file);
1424 pp_string (buffer, " : ");
1426 pp_decimal_int (buffer, xloc.line);
1427 pp_string (buffer, ":");
1428 pp_decimal_int (buffer, xloc.column);
1429 pp_string (buffer, "] ");
1431 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1432 false);
1433 pp_character (buffer, '(');
1434 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1435 pp_character (buffer, ')');
1436 if (i < gimple_phi_num_args (phi) - 1)
1437 pp_string (buffer, ", ");
1439 pp_character (buffer, '>');
1443 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1444 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1445 tree-pass.h). */
1447 static void
1448 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1449 int flags)
1451 if (flags & TDF_RAW)
1453 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1454 gimple_omp_body (gs));
1455 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1456 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1457 gimple_omp_parallel_child_fn (gs),
1458 gimple_omp_parallel_data_arg (gs));
1460 else
1462 gimple_seq body;
1463 pp_string (buffer, "#pragma omp parallel");
1464 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1465 if (gimple_omp_parallel_child_fn (gs))
1467 pp_string (buffer, " [child fn: ");
1468 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1469 spc, flags, false);
1470 pp_string (buffer, " (");
1471 if (gimple_omp_parallel_data_arg (gs))
1472 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1473 spc, flags, false);
1474 else
1475 pp_string (buffer, "???");
1476 pp_string (buffer, ")]");
1478 body = gimple_omp_body (gs);
1479 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1481 newline_and_indent (buffer, spc + 2);
1482 pp_character (buffer, '{');
1483 pp_newline (buffer);
1484 dump_gimple_seq (buffer, body, spc + 4, flags);
1485 newline_and_indent (buffer, spc + 2);
1486 pp_character (buffer, '}');
1488 else if (body)
1490 pp_newline (buffer);
1491 dump_gimple_seq (buffer, body, spc + 2, flags);
1497 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1498 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1499 tree-pass.h). */
1501 static void
1502 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1503 int flags)
1505 if (flags & TDF_RAW)
1507 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1508 gimple_omp_body (gs));
1509 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1510 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1511 gimple_omp_task_child_fn (gs),
1512 gimple_omp_task_data_arg (gs),
1513 gimple_omp_task_copy_fn (gs),
1514 gimple_omp_task_arg_size (gs),
1515 gimple_omp_task_arg_size (gs));
1517 else
1519 gimple_seq body;
1520 pp_string (buffer, "#pragma omp task");
1521 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1522 if (gimple_omp_task_child_fn (gs))
1524 pp_string (buffer, " [child fn: ");
1525 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1526 spc, flags, false);
1527 pp_string (buffer, " (");
1528 if (gimple_omp_task_data_arg (gs))
1529 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1530 spc, flags, false);
1531 else
1532 pp_string (buffer, "???");
1533 pp_string (buffer, ")]");
1535 body = gimple_omp_body (gs);
1536 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1538 newline_and_indent (buffer, spc + 2);
1539 pp_character (buffer, '{');
1540 pp_newline (buffer);
1541 dump_gimple_seq (buffer, body, spc + 4, flags);
1542 newline_and_indent (buffer, spc + 2);
1543 pp_character (buffer, '}');
1545 else if (body)
1547 pp_newline (buffer);
1548 dump_gimple_seq (buffer, body, spc + 2, flags);
1554 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1555 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1556 in tree-pass.h). */
1558 static void
1559 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1560 int flags)
1562 if (flags & TDF_RAW)
1564 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1565 gimple_omp_atomic_load_lhs (gs),
1566 gimple_omp_atomic_load_rhs (gs));
1568 else
1570 pp_string (buffer, "#pragma omp atomic_load");
1571 newline_and_indent (buffer, spc + 2);
1572 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1573 spc, flags, false);
1574 pp_space (buffer);
1575 pp_character (buffer, '=');
1576 pp_space (buffer);
1577 pp_character (buffer, '*');
1578 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1579 spc, flags, false);
1583 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1584 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1585 in tree-pass.h). */
1587 static void
1588 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
1589 int flags)
1591 if (flags & TDF_RAW)
1593 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1594 gimple_omp_atomic_store_val (gs));
1596 else
1598 pp_string (buffer, "#pragma omp atomic_store (");
1599 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
1600 spc, flags, false);
1601 pp_character (buffer, ')');
1606 /* Dump all the memory operands for statement GS. BUFFER, SPC and
1607 FLAGS are as in dump_gimple_stmt. */
1609 static void
1610 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
1612 tree vdef = gimple_vdef (gs);
1613 tree vuse = gimple_vuse (gs);
1615 if (!ssa_operands_active () || !gimple_references_memory_p (gs))
1616 return;
1618 if (vdef != NULL_TREE)
1620 pp_string (buffer, "# ");
1621 dump_generic_node (buffer, vdef, spc + 2, flags, false);
1622 pp_string (buffer, " = VDEF <");
1623 dump_generic_node (buffer, vuse, spc + 2, flags, false);
1624 pp_character (buffer, '>');
1625 newline_and_indent (buffer, spc);
1627 else if (vuse != NULL_TREE)
1629 pp_string (buffer, "# VUSE <");
1630 dump_generic_node (buffer, vuse, spc + 2, flags, false);
1631 pp_character (buffer, '>');
1632 newline_and_indent (buffer, spc);
1637 /* Dump the gimple statement GS on the pretty printer BUFFER, SPC
1638 spaces of indent. FLAGS specifies details to show in the dump (see
1639 TDF_* in tree-pass.h). */
1641 void
1642 dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags)
1644 if (!gs)
1645 return;
1647 if (flags & TDF_STMTADDR)
1648 pp_printf (buffer, "<&%p> ", (void *) gs);
1650 if ((flags & TDF_LINENO) && gimple_has_location (gs))
1652 expanded_location xloc = expand_location (gimple_location (gs));
1653 pp_character (buffer, '[');
1654 if (xloc.file)
1656 pp_string (buffer, xloc.file);
1657 pp_string (buffer, " : ");
1659 pp_decimal_int (buffer, xloc.line);
1660 pp_string (buffer, ":");
1661 pp_decimal_int (buffer, xloc.column);
1662 pp_string (buffer, "] ");
1665 if (flags & TDF_EH)
1667 int lp_nr = lookup_stmt_eh_lp (gs);
1668 if (lp_nr > 0)
1669 pp_printf (buffer, "[LP %d] ", lp_nr);
1670 else if (lp_nr < 0)
1671 pp_printf (buffer, "[MNT %d] ", -lp_nr);
1674 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
1675 && gimple_has_mem_ops (gs))
1676 dump_gimple_mem_ops (buffer, gs, spc, flags);
1678 if ((flags & TDF_ALIAS)
1679 && gimple_has_lhs (gs))
1681 tree lhs = gimple_get_lhs (gs);
1682 if (TREE_CODE (lhs) == SSA_NAME
1683 && POINTER_TYPE_P (TREE_TYPE (lhs))
1684 && SSA_NAME_PTR_INFO (lhs))
1686 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
1687 pp_string (buffer, "# PT = ");
1688 pp_points_to_solution (buffer, &pi->pt);
1689 newline_and_indent (buffer, spc);
1690 if (pi->align != 1)
1692 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u",
1693 pi->align, pi->misalign);
1694 newline_and_indent (buffer, spc);
1699 switch (gimple_code (gs))
1701 case GIMPLE_ASM:
1702 dump_gimple_asm (buffer, gs, spc, flags);
1703 break;
1705 case GIMPLE_ASSIGN:
1706 dump_gimple_assign (buffer, gs, spc, flags);
1707 break;
1709 case GIMPLE_BIND:
1710 dump_gimple_bind (buffer, gs, spc, flags);
1711 break;
1713 case GIMPLE_CALL:
1714 dump_gimple_call (buffer, gs, spc, flags);
1715 break;
1717 case GIMPLE_COND:
1718 dump_gimple_cond (buffer, gs, spc, flags);
1719 break;
1721 case GIMPLE_LABEL:
1722 dump_gimple_label (buffer, gs, spc, flags);
1723 break;
1725 case GIMPLE_GOTO:
1726 dump_gimple_goto (buffer, gs, spc, flags);
1727 break;
1729 case GIMPLE_NOP:
1730 pp_string (buffer, "GIMPLE_NOP");
1731 break;
1733 case GIMPLE_RETURN:
1734 dump_gimple_return (buffer, gs, spc, flags);
1735 break;
1737 case GIMPLE_SWITCH:
1738 dump_gimple_switch (buffer, gs, spc, flags);
1739 break;
1741 case GIMPLE_TRY:
1742 dump_gimple_try (buffer, gs, spc, flags);
1743 break;
1745 case GIMPLE_PHI:
1746 dump_gimple_phi (buffer, gs, spc, flags);
1747 break;
1749 case GIMPLE_OMP_PARALLEL:
1750 dump_gimple_omp_parallel (buffer, gs, spc, flags);
1751 break;
1753 case GIMPLE_OMP_TASK:
1754 dump_gimple_omp_task (buffer, gs, spc, flags);
1755 break;
1757 case GIMPLE_OMP_ATOMIC_LOAD:
1758 dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
1760 break;
1762 case GIMPLE_OMP_ATOMIC_STORE:
1763 dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
1764 break;
1766 case GIMPLE_OMP_FOR:
1767 dump_gimple_omp_for (buffer, gs, spc, flags);
1768 break;
1770 case GIMPLE_OMP_CONTINUE:
1771 dump_gimple_omp_continue (buffer, gs, spc, flags);
1772 break;
1774 case GIMPLE_OMP_SINGLE:
1775 dump_gimple_omp_single (buffer, gs, spc, flags);
1776 break;
1778 case GIMPLE_OMP_RETURN:
1779 dump_gimple_omp_return (buffer, gs, spc, flags);
1780 break;
1782 case GIMPLE_OMP_SECTIONS:
1783 dump_gimple_omp_sections (buffer, gs, spc, flags);
1784 break;
1786 case GIMPLE_OMP_SECTIONS_SWITCH:
1787 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
1788 break;
1790 case GIMPLE_OMP_MASTER:
1791 case GIMPLE_OMP_ORDERED:
1792 case GIMPLE_OMP_SECTION:
1793 dump_gimple_omp_block (buffer, gs, spc, flags);
1794 break;
1796 case GIMPLE_OMP_CRITICAL:
1797 dump_gimple_omp_critical (buffer, gs, spc, flags);
1798 break;
1800 case GIMPLE_CATCH:
1801 dump_gimple_catch (buffer, gs, spc, flags);
1802 break;
1804 case GIMPLE_EH_FILTER:
1805 dump_gimple_eh_filter (buffer, gs, spc, flags);
1806 break;
1808 case GIMPLE_EH_MUST_NOT_THROW:
1809 dump_gimple_eh_must_not_throw (buffer, gs, spc, flags);
1810 break;
1812 case GIMPLE_RESX:
1813 dump_gimple_resx (buffer, gs, spc, flags);
1814 break;
1816 case GIMPLE_EH_DISPATCH:
1817 dump_gimple_eh_dispatch (buffer, gs, spc, flags);
1818 break;
1820 case GIMPLE_DEBUG:
1821 dump_gimple_debug (buffer, gs, spc, flags);
1822 break;
1824 case GIMPLE_PREDICT:
1825 pp_string (buffer, "// predicted ");
1826 if (gimple_predict_outcome (gs))
1827 pp_string (buffer, "likely by ");
1828 else
1829 pp_string (buffer, "unlikely by ");
1830 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
1831 pp_string (buffer, " predictor.");
1832 break;
1834 default:
1835 GIMPLE_NIY;
1838 /* If we're building a diagnostic, the formatted text will be
1839 written into BUFFER's stream by the caller; otherwise, write it
1840 now. */
1841 if (!(flags & TDF_DIAGNOSTIC))
1842 pp_write_text_to_stream (buffer);
1846 /* Dumps header of basic block BB to buffer BUFFER indented by INDENT
1847 spaces and details described by flags. */
1849 static void
1850 dump_bb_header (pretty_printer *buffer, basic_block bb, int indent, int flags)
1852 edge e;
1853 gimple stmt;
1854 edge_iterator ei;
1856 if (flags & TDF_BLOCKS)
1858 INDENT (indent);
1859 pp_string (buffer, "# BLOCK ");
1860 pp_decimal_int (buffer, bb->index);
1861 if (bb->frequency)
1863 pp_string (buffer, " freq:");
1864 pp_decimal_int (buffer, bb->frequency);
1866 if (bb->count)
1868 pp_string (buffer, " count:");
1869 pp_widest_integer (buffer, bb->count);
1872 if (flags & TDF_LINENO)
1874 gimple_stmt_iterator gsi;
1876 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1877 if (!is_gimple_debug (gsi_stmt (gsi))
1878 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
1880 pp_string (buffer, ", starting at line ");
1881 pp_decimal_int (buffer, get_lineno (gsi_stmt (gsi)));
1882 break;
1885 if (bb->discriminator)
1887 pp_string (buffer, ", discriminator ");
1888 pp_decimal_int (buffer, bb->discriminator);
1891 newline_and_indent (buffer, indent);
1893 pp_string (buffer, "# PRED:");
1894 pp_write_text_to_stream (buffer);
1895 FOR_EACH_EDGE (e, ei, bb->preds)
1896 if (flags & TDF_SLIM)
1898 pp_character (buffer, ' ');
1899 if (e->src == ENTRY_BLOCK_PTR)
1900 pp_string (buffer, "ENTRY");
1901 else
1902 pp_decimal_int (buffer, e->src->index);
1904 else
1905 dump_edge_info (buffer->buffer->stream, e, 0);
1906 pp_newline (buffer);
1908 else
1910 stmt = first_stmt (bb);
1911 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
1913 INDENT (indent - 2);
1914 pp_string (buffer, "<bb ");
1915 pp_decimal_int (buffer, bb->index);
1916 pp_string (buffer, ">:");
1917 pp_newline (buffer);
1920 pp_write_text_to_stream (buffer);
1921 if (cfun)
1922 check_bb_profile (bb, buffer->buffer->stream);
1926 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
1927 spaces. */
1929 static void
1930 dump_bb_end (pretty_printer *buffer, basic_block bb, int indent, int flags)
1932 edge e;
1933 edge_iterator ei;
1935 INDENT (indent);
1936 pp_string (buffer, "# SUCC:");
1937 pp_write_text_to_stream (buffer);
1938 FOR_EACH_EDGE (e, ei, bb->succs)
1939 if (flags & TDF_SLIM)
1941 pp_character (buffer, ' ');
1942 if (e->dest == EXIT_BLOCK_PTR)
1943 pp_string (buffer, "EXIT");
1944 else
1945 pp_decimal_int (buffer, e->dest->index);
1947 else
1948 dump_edge_info (buffer->buffer->stream, e, 1);
1949 pp_newline (buffer);
1953 /* Dump PHI nodes of basic block BB to BUFFER with details described
1954 by FLAGS and indented by INDENT spaces. */
1956 static void
1957 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
1959 gimple_stmt_iterator i;
1961 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
1963 gimple phi = gsi_stmt (i);
1964 if (is_gimple_reg (gimple_phi_result (phi)) || (flags & TDF_VOPS))
1966 INDENT (indent);
1967 pp_string (buffer, "# ");
1968 dump_gimple_phi (buffer, phi, indent, flags);
1969 pp_newline (buffer);
1975 /* Dump jump to basic block BB that is represented implicitly in the cfg
1976 to BUFFER. */
1978 static void
1979 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
1981 gimple stmt;
1983 stmt = first_stmt (bb);
1985 pp_string (buffer, "goto <bb ");
1986 pp_decimal_int (buffer, bb->index);
1987 pp_character (buffer, '>');
1988 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
1990 pp_string (buffer, " (");
1991 dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
1992 pp_character (buffer, ')');
1993 pp_semicolon (buffer);
1995 else
1996 pp_semicolon (buffer);
2000 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2001 by INDENT spaces, with details given by FLAGS. */
2003 static void
2004 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2005 int flags)
2007 edge e;
2008 gimple stmt;
2010 stmt = last_stmt (bb);
2012 if (stmt && gimple_code (stmt) == GIMPLE_COND)
2014 edge true_edge, false_edge;
2016 /* When we are emitting the code or changing CFG, it is possible that
2017 the edges are not yet created. When we are using debug_bb in such
2018 a situation, we do not want it to crash. */
2019 if (EDGE_COUNT (bb->succs) != 2)
2020 return;
2021 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2023 INDENT (indent + 2);
2024 pp_cfg_jump (buffer, true_edge->dest);
2025 newline_and_indent (buffer, indent);
2026 pp_string (buffer, "else");
2027 newline_and_indent (buffer, indent + 2);
2028 pp_cfg_jump (buffer, false_edge->dest);
2029 pp_newline (buffer);
2030 return;
2033 /* If there is a fallthru edge, we may need to add an artificial
2034 goto to the dump. */
2035 e = find_fallthru_edge (bb->succs);
2037 if (e && e->dest != bb->next_bb)
2039 INDENT (indent);
2041 if ((flags & TDF_LINENO)
2042 && e->goto_locus != UNKNOWN_LOCATION
2045 expanded_location goto_xloc;
2046 goto_xloc = expand_location (e->goto_locus);
2047 pp_character (buffer, '[');
2048 if (goto_xloc.file)
2050 pp_string (buffer, goto_xloc.file);
2051 pp_string (buffer, " : ");
2053 pp_decimal_int (buffer, goto_xloc.line);
2054 pp_string (buffer, " : ");
2055 pp_decimal_int (buffer, goto_xloc.column);
2056 pp_string (buffer, "] ");
2059 pp_cfg_jump (buffer, e->dest);
2060 pp_newline (buffer);
2065 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2066 indented by INDENT spaces. */
2068 static void
2069 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2070 int flags)
2072 gimple_stmt_iterator gsi;
2073 gimple stmt;
2074 int label_indent = indent - 2;
2076 if (label_indent < 0)
2077 label_indent = 0;
2079 dump_bb_header (buffer, bb, indent, flags);
2080 dump_phi_nodes (buffer, bb, indent, flags);
2082 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2084 int curr_indent;
2086 stmt = gsi_stmt (gsi);
2088 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2090 INDENT (curr_indent);
2091 dump_gimple_stmt (buffer, stmt, curr_indent, flags);
2092 pp_newline (buffer);
2093 dump_histograms_for_stmt (cfun, buffer->buffer->stream, stmt);
2096 dump_implicit_edges (buffer, bb, indent, flags);
2098 if (flags & TDF_BLOCKS)
2099 dump_bb_end (buffer, bb, indent, flags);
2103 /* Dumps basic block BB to FILE with details described by FLAGS and
2104 indented by INDENT spaces. */
2106 void
2107 gimple_dump_bb (basic_block bb, FILE *file, int indent, int flags)
2109 maybe_init_pretty_print (file);
2110 gimple_dump_bb_buff (&buffer, bb, indent, flags);
2111 pp_flush (&buffer);