Update copyright years in gcc/
[gcc.git] / gcc / gimple-pretty-print.c
1 /* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001-2013 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldyh@redhat.com> and
4 Diego Novillo <dnovillo@google.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "diagnostic.h"
28 #include "gimple-pretty-print.h"
29 #include "hashtab.h"
30 #include "tree-flow.h"
31 #include "dumpfile.h" /* for dump_flags */
32 #include "gimple.h"
33 #include "value-prof.h"
34 #include "trans-mem.h"
35
36 #define INDENT(SPACE) \
37 do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
38
39 static pretty_printer buffer;
40 static bool initialized = false;
41
42 #define GIMPLE_NIY do_niy (buffer,gs)
43
44 /* Try to print on BUFFER a default message for the unrecognized
45 gimple statement GS. */
46
47 static void
48 do_niy (pretty_printer *buffer, gimple gs)
49 {
50 pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
51 gimple_code_name[(int) gimple_code (gs)]);
52 }
53
54
55 /* Initialize the pretty printer on FILE if needed. */
56
57 static void
58 maybe_init_pretty_print (FILE *file)
59 {
60 if (!initialized)
61 {
62 pp_construct (&buffer, NULL, 0);
63 pp_needs_newline (&buffer) = true;
64 initialized = true;
65 }
66
67 buffer.buffer->stream = file;
68 }
69
70
71 /* Emit a newline and SPC indentation spaces to BUFFER. */
72
73 static void
74 newline_and_indent (pretty_printer *buffer, int spc)
75 {
76 pp_newline (buffer);
77 INDENT (spc);
78 }
79
80
81 /* Print the GIMPLE statement GS on stderr. */
82
83 DEBUG_FUNCTION void
84 debug_gimple_stmt (gimple gs)
85 {
86 print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
87 fprintf (stderr, "\n");
88 }
89
90
91 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
92 FLAGS as in pp_gimple_stmt_1. */
93
94 void
95 print_gimple_stmt (FILE *file, gimple g, int spc, int flags)
96 {
97 maybe_init_pretty_print (file);
98 pp_gimple_stmt_1 (&buffer, g, spc, flags);
99 pp_newline_and_flush (&buffer);
100 }
101
102
103 /* Print GIMPLE statement G to FILE using SPC indentation spaces and
104 FLAGS as in pp_gimple_stmt_1. Print only the right-hand side
105 of the statement. */
106
107 void
108 print_gimple_expr (FILE *file, gimple g, int spc, int flags)
109 {
110 flags |= TDF_RHS_ONLY;
111 maybe_init_pretty_print (file);
112 pp_gimple_stmt_1 (&buffer, g, spc, flags);
113 pp_flush (&buffer);
114 }
115
116
117 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentation
118 spaces and FLAGS as in pp_gimple_stmt_1.
119 The caller is responsible for calling pp_flush on BUFFER to finalize
120 the pretty printer. */
121
122 static void
123 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc, int flags)
124 {
125 gimple_stmt_iterator i;
126
127 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
128 {
129 gimple gs = gsi_stmt (i);
130 INDENT (spc);
131 pp_gimple_stmt_1 (buffer, gs, spc, flags);
132 if (!gsi_one_before_end_p (i))
133 pp_newline (buffer);
134 }
135 }
136
137
138 /* Print GIMPLE sequence SEQ to FILE using SPC indentation spaces and
139 FLAGS as in pp_gimple_stmt_1. */
140
141 void
142 print_gimple_seq (FILE *file, gimple_seq seq, int spc, int flags)
143 {
144 maybe_init_pretty_print (file);
145 dump_gimple_seq (&buffer, seq, spc, flags);
146 pp_newline_and_flush (&buffer);
147 }
148
149
150 /* Print the GIMPLE sequence SEQ on stderr. */
151
152 DEBUG_FUNCTION void
153 debug_gimple_seq (gimple_seq seq)
154 {
155 print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
156 }
157
158
159 /* A simple helper to pretty-print some of the gimple tuples in the printf
160 style. The format modifiers are preceded by '%' and are:
161 'G' - outputs a string corresponding to the code of the given gimple,
162 'S' - outputs a gimple_seq with indent of spc + 2,
163 'T' - outputs the tree t,
164 'd' - outputs an int as a decimal,
165 's' - outputs a string,
166 'n' - outputs a newline,
167 'x' - outputs an int as hexadecimal,
168 '+' - increases indent by 2 then outputs a newline,
169 '-' - decreases indent by 2 then outputs a newline. */
170
171 static void
172 dump_gimple_fmt (pretty_printer *buffer, int spc, int flags,
173 const char *fmt, ...)
174 {
175 va_list args;
176 const char *c;
177 const char *tmp;
178
179 va_start (args, fmt);
180 for (c = fmt; *c; c++)
181 {
182 if (*c == '%')
183 {
184 gimple_seq seq;
185 tree t;
186 gimple g;
187 switch (*++c)
188 {
189 case 'G':
190 g = va_arg (args, gimple);
191 tmp = gimple_code_name[gimple_code (g)];
192 pp_string (buffer, tmp);
193 break;
194
195 case 'S':
196 seq = va_arg (args, gimple_seq);
197 pp_newline (buffer);
198 dump_gimple_seq (buffer, seq, spc + 2, flags);
199 newline_and_indent (buffer, spc);
200 break;
201
202 case 'T':
203 t = va_arg (args, tree);
204 if (t == NULL_TREE)
205 pp_string (buffer, "NULL");
206 else
207 dump_generic_node (buffer, t, spc, flags, false);
208 break;
209
210 case 'd':
211 pp_decimal_int (buffer, va_arg (args, int));
212 break;
213
214 case 's':
215 pp_string (buffer, va_arg (args, char *));
216 break;
217
218 case 'n':
219 newline_and_indent (buffer, spc);
220 break;
221
222 case 'x':
223 pp_scalar (buffer, "%x", va_arg (args, int));
224 break;
225
226 case '+':
227 spc += 2;
228 newline_and_indent (buffer, spc);
229 break;
230
231 case '-':
232 spc -= 2;
233 newline_and_indent (buffer, spc);
234 break;
235
236 default:
237 gcc_unreachable ();
238 }
239 }
240 else
241 pp_character (buffer, *c);
242 }
243 va_end (args);
244 }
245
246
247 /* Helper for dump_gimple_assign. Print the unary RHS of the
248 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
249
250 static void
251 dump_unary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
252 {
253 enum tree_code rhs_code = gimple_assign_rhs_code (gs);
254 tree lhs = gimple_assign_lhs (gs);
255 tree rhs = gimple_assign_rhs1 (gs);
256
257 switch (rhs_code)
258 {
259 case VIEW_CONVERT_EXPR:
260 case ASSERT_EXPR:
261 dump_generic_node (buffer, rhs, spc, flags, false);
262 break;
263
264 case FIXED_CONVERT_EXPR:
265 case ADDR_SPACE_CONVERT_EXPR:
266 case FIX_TRUNC_EXPR:
267 case FLOAT_EXPR:
268 CASE_CONVERT:
269 pp_character (buffer, '(');
270 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
271 pp_string (buffer, ") ");
272 if (op_prio (rhs) < op_code_prio (rhs_code))
273 {
274 pp_character (buffer, '(');
275 dump_generic_node (buffer, rhs, spc, flags, false);
276 pp_character (buffer, ')');
277 }
278 else
279 dump_generic_node (buffer, rhs, spc, flags, false);
280 break;
281
282 case PAREN_EXPR:
283 pp_string (buffer, "((");
284 dump_generic_node (buffer, rhs, spc, flags, false);
285 pp_string (buffer, "))");
286 break;
287
288 case ABS_EXPR:
289 pp_string (buffer, "ABS_EXPR <");
290 dump_generic_node (buffer, rhs, spc, flags, false);
291 pp_character (buffer, '>');
292 break;
293
294 default:
295 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
296 || TREE_CODE_CLASS (rhs_code) == tcc_constant
297 || TREE_CODE_CLASS (rhs_code) == tcc_reference
298 || rhs_code == SSA_NAME
299 || rhs_code == ADDR_EXPR
300 || rhs_code == CONSTRUCTOR)
301 {
302 dump_generic_node (buffer, rhs, spc, flags, false);
303 break;
304 }
305 else if (rhs_code == BIT_NOT_EXPR)
306 pp_character (buffer, '~');
307 else if (rhs_code == TRUTH_NOT_EXPR)
308 pp_character (buffer, '!');
309 else if (rhs_code == NEGATE_EXPR)
310 pp_character (buffer, '-');
311 else
312 {
313 pp_character (buffer, '[');
314 pp_string (buffer, tree_code_name [rhs_code]);
315 pp_string (buffer, "] ");
316 }
317
318 if (op_prio (rhs) < op_code_prio (rhs_code))
319 {
320 pp_character (buffer, '(');
321 dump_generic_node (buffer, rhs, spc, flags, false);
322 pp_character (buffer, ')');
323 }
324 else
325 dump_generic_node (buffer, rhs, spc, flags, false);
326 break;
327 }
328 }
329
330
331 /* Helper for dump_gimple_assign. Print the binary RHS of the
332 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
333
334 static void
335 dump_binary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
336 {
337 const char *p;
338 enum tree_code code = gimple_assign_rhs_code (gs);
339 switch (code)
340 {
341 case COMPLEX_EXPR:
342 case MIN_EXPR:
343 case MAX_EXPR:
344 case VEC_WIDEN_MULT_HI_EXPR:
345 case VEC_WIDEN_MULT_LO_EXPR:
346 case VEC_WIDEN_MULT_EVEN_EXPR:
347 case VEC_WIDEN_MULT_ODD_EXPR:
348 case VEC_PACK_TRUNC_EXPR:
349 case VEC_PACK_SAT_EXPR:
350 case VEC_PACK_FIX_TRUNC_EXPR:
351 case VEC_WIDEN_LSHIFT_HI_EXPR:
352 case VEC_WIDEN_LSHIFT_LO_EXPR:
353 for (p = tree_code_name [(int) code]; *p; p++)
354 pp_character (buffer, TOUPPER (*p));
355 pp_string (buffer, " <");
356 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
357 pp_string (buffer, ", ");
358 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
359 pp_character (buffer, '>');
360 break;
361
362 default:
363 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
364 {
365 pp_character (buffer, '(');
366 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
367 false);
368 pp_character (buffer, ')');
369 }
370 else
371 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
372 pp_space (buffer);
373 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
374 pp_space (buffer);
375 if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
376 {
377 pp_character (buffer, '(');
378 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
379 false);
380 pp_character (buffer, ')');
381 }
382 else
383 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
384 }
385 }
386
387 /* Helper for dump_gimple_assign. Print the ternary RHS of the
388 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
389
390 static void
391 dump_ternary_rhs (pretty_printer *buffer, gimple gs, int spc, int flags)
392 {
393 const char *p;
394 enum tree_code code = gimple_assign_rhs_code (gs);
395 switch (code)
396 {
397 case WIDEN_MULT_PLUS_EXPR:
398 case WIDEN_MULT_MINUS_EXPR:
399 for (p = tree_code_name [(int) code]; *p; p++)
400 pp_character (buffer, TOUPPER (*p));
401 pp_string (buffer, " <");
402 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
403 pp_string (buffer, ", ");
404 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
405 pp_string (buffer, ", ");
406 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
407 pp_character (buffer, '>');
408 break;
409
410 case FMA_EXPR:
411 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
412 pp_string (buffer, " * ");
413 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
414 pp_string (buffer, " + ");
415 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
416 break;
417
418 case DOT_PROD_EXPR:
419 pp_string (buffer, "DOT_PROD_EXPR <");
420 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
421 pp_string (buffer, ", ");
422 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
423 pp_string (buffer, ", ");
424 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
425 pp_string (buffer, ">");
426 break;
427
428 case VEC_PERM_EXPR:
429 pp_string (buffer, "VEC_PERM_EXPR <");
430 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
431 pp_string (buffer, ", ");
432 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
433 pp_string (buffer, ", ");
434 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
435 pp_string (buffer, ">");
436 break;
437
438 case REALIGN_LOAD_EXPR:
439 pp_string (buffer, "REALIGN_LOAD <");
440 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
441 pp_string (buffer, ", ");
442 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
443 pp_string (buffer, ", ");
444 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
445 pp_string (buffer, ">");
446 break;
447
448 case COND_EXPR:
449 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
450 pp_string (buffer, " ? ");
451 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
452 pp_string (buffer, " : ");
453 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
454 break;
455
456 case VEC_COND_EXPR:
457 pp_string (buffer, "VEC_COND_EXPR <");
458 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
459 pp_string (buffer, ", ");
460 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
461 pp_string (buffer, ", ");
462 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
463 pp_string (buffer, ">");
464 break;
465
466 default:
467 gcc_unreachable ();
468 }
469 }
470
471
472 /* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
473 pp_gimple_stmt_1. */
474
475 static void
476 dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
477 {
478 if (flags & TDF_RAW)
479 {
480 tree arg1 = NULL;
481 tree arg2 = NULL;
482 tree arg3 = NULL;
483 switch (gimple_num_ops (gs))
484 {
485 case 4:
486 arg3 = gimple_assign_rhs3 (gs);
487 case 3:
488 arg2 = gimple_assign_rhs2 (gs);
489 case 2:
490 arg1 = gimple_assign_rhs1 (gs);
491 break;
492 default:
493 gcc_unreachable ();
494 }
495
496 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
497 tree_code_name[gimple_assign_rhs_code (gs)],
498 gimple_assign_lhs (gs), arg1, arg2, arg3);
499 }
500 else
501 {
502 if (!(flags & TDF_RHS_ONLY))
503 {
504 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
505 pp_space (buffer);
506 pp_character (buffer, '=');
507
508 if (gimple_assign_nontemporal_move_p (gs))
509 pp_string (buffer, "{nt}");
510
511 if (gimple_has_volatile_ops (gs))
512 pp_string (buffer, "{v}");
513
514 pp_space (buffer);
515 }
516
517 if (gimple_num_ops (gs) == 2)
518 dump_unary_rhs (buffer, gs, spc, flags);
519 else if (gimple_num_ops (gs) == 3)
520 dump_binary_rhs (buffer, gs, spc, flags);
521 else if (gimple_num_ops (gs) == 4)
522 dump_ternary_rhs (buffer, gs, spc, flags);
523 else
524 gcc_unreachable ();
525 if (!(flags & TDF_RHS_ONLY))
526 pp_semicolon(buffer);
527 }
528 }
529
530
531 /* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
532 pp_gimple_stmt_1. */
533
534 static void
535 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
536 {
537 tree t;
538
539 t = gimple_return_retval (gs);
540 if (flags & TDF_RAW)
541 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
542 else
543 {
544 pp_string (buffer, "return");
545 if (t)
546 {
547 pp_space (buffer);
548 dump_generic_node (buffer, t, spc, flags, false);
549 }
550 pp_semicolon (buffer);
551 }
552 }
553
554
555 /* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
556 dump_gimple_call. */
557
558 static void
559 dump_gimple_call_args (pretty_printer *buffer, gimple gs, int flags)
560 {
561 size_t i;
562
563 for (i = 0; i < gimple_call_num_args (gs); i++)
564 {
565 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
566 if (i < gimple_call_num_args (gs) - 1)
567 pp_string (buffer, ", ");
568 }
569
570 if (gimple_call_va_arg_pack_p (gs))
571 {
572 if (gimple_call_num_args (gs) > 0)
573 {
574 pp_character (buffer, ',');
575 pp_space (buffer);
576 }
577
578 pp_string (buffer, "__builtin_va_arg_pack ()");
579 }
580 }
581
582 /* Dump the points-to solution *PT to BUFFER. */
583
584 static void
585 pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
586 {
587 if (pt->anything)
588 {
589 pp_string (buffer, "anything ");
590 return;
591 }
592 if (pt->nonlocal)
593 pp_string (buffer, "nonlocal ");
594 if (pt->escaped)
595 pp_string (buffer, "escaped ");
596 if (pt->ipa_escaped)
597 pp_string (buffer, "unit-escaped ");
598 if (pt->null)
599 pp_string (buffer, "null ");
600 if (pt->vars
601 && !bitmap_empty_p (pt->vars))
602 {
603 bitmap_iterator bi;
604 unsigned i;
605 pp_string (buffer, "{ ");
606 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
607 {
608 pp_string (buffer, "D.");
609 pp_decimal_int (buffer, i);
610 pp_character (buffer, ' ');
611 }
612 pp_character (buffer, '}');
613 if (pt->vars_contains_global)
614 pp_string (buffer, " (glob)");
615 }
616 }
617
618 /* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
619 pp_gimple_stmt_1. */
620
621 static void
622 dump_gimple_call (pretty_printer *buffer, gimple gs, int spc, int flags)
623 {
624 tree lhs = gimple_call_lhs (gs);
625 tree fn = gimple_call_fn (gs);
626
627 if (flags & TDF_ALIAS)
628 {
629 struct pt_solution *pt;
630 pt = gimple_call_use_set (gs);
631 if (!pt_solution_empty_p (pt))
632 {
633 pp_string (buffer, "# USE = ");
634 pp_points_to_solution (buffer, pt);
635 newline_and_indent (buffer, spc);
636 }
637 pt = gimple_call_clobber_set (gs);
638 if (!pt_solution_empty_p (pt))
639 {
640 pp_string (buffer, "# CLB = ");
641 pp_points_to_solution (buffer, pt);
642 newline_and_indent (buffer, spc);
643 }
644 }
645
646 if (flags & TDF_RAW)
647 {
648 if (gimple_call_internal_p (gs))
649 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T", gs,
650 internal_fn_name (gimple_call_internal_fn (gs)), lhs);
651 else
652 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T", gs, fn, lhs);
653 if (gimple_call_num_args (gs) > 0)
654 {
655 pp_string (buffer, ", ");
656 dump_gimple_call_args (buffer, gs, flags);
657 }
658 pp_character (buffer, '>');
659 }
660 else
661 {
662 if (lhs && !(flags & TDF_RHS_ONLY))
663 {
664 dump_generic_node (buffer, lhs, spc, flags, false);
665 pp_string (buffer, " =");
666
667 if (gimple_has_volatile_ops (gs))
668 pp_string (buffer, "{v}");
669
670 pp_space (buffer);
671 }
672 if (gimple_call_internal_p (gs))
673 pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
674 else
675 print_call_name (buffer, fn, flags);
676 pp_string (buffer, " (");
677 dump_gimple_call_args (buffer, gs, flags);
678 pp_character (buffer, ')');
679 if (!(flags & TDF_RHS_ONLY))
680 pp_semicolon (buffer);
681 }
682
683 if (gimple_call_chain (gs))
684 {
685 pp_string (buffer, " [static-chain: ");
686 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
687 pp_character (buffer, ']');
688 }
689
690 if (gimple_call_return_slot_opt_p (gs))
691 pp_string (buffer, " [return slot optimization]");
692 if (gimple_call_tail_p (gs))
693 pp_string (buffer, " [tail call]");
694
695 if (fn == NULL)
696 return;
697
698 /* Dump the arguments of _ITM_beginTransaction sanely. */
699 if (TREE_CODE (fn) == ADDR_EXPR)
700 fn = TREE_OPERAND (fn, 0);
701 if (TREE_CODE (fn) == FUNCTION_DECL && decl_is_tm_clone (fn))
702 pp_string (buffer, " [tm-clone]");
703 if (TREE_CODE (fn) == FUNCTION_DECL
704 && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
705 && DECL_FUNCTION_CODE (fn) == BUILT_IN_TM_START
706 && gimple_call_num_args (gs) > 0)
707 {
708 tree t = gimple_call_arg (gs, 0);
709 unsigned HOST_WIDE_INT props;
710 gcc_assert (TREE_CODE (t) == INTEGER_CST);
711
712 pp_string (buffer, " [ ");
713
714 /* Get the transaction code properties. */
715 props = TREE_INT_CST_LOW (t);
716
717 if (props & PR_INSTRUMENTEDCODE)
718 pp_string (buffer, "instrumentedCode ");
719 if (props & PR_UNINSTRUMENTEDCODE)
720 pp_string (buffer, "uninstrumentedCode ");
721 if (props & PR_HASNOXMMUPDATE)
722 pp_string (buffer, "hasNoXMMUpdate ");
723 if (props & PR_HASNOABORT)
724 pp_string (buffer, "hasNoAbort ");
725 if (props & PR_HASNOIRREVOCABLE)
726 pp_string (buffer, "hasNoIrrevocable ");
727 if (props & PR_DOESGOIRREVOCABLE)
728 pp_string (buffer, "doesGoIrrevocable ");
729 if (props & PR_HASNOSIMPLEREADS)
730 pp_string (buffer, "hasNoSimpleReads ");
731 if (props & PR_AWBARRIERSOMITTED)
732 pp_string (buffer, "awBarriersOmitted ");
733 if (props & PR_RARBARRIERSOMITTED)
734 pp_string (buffer, "RaRBarriersOmitted ");
735 if (props & PR_UNDOLOGCODE)
736 pp_string (buffer, "undoLogCode ");
737 if (props & PR_PREFERUNINSTRUMENTED)
738 pp_string (buffer, "preferUninstrumented ");
739 if (props & PR_EXCEPTIONBLOCK)
740 pp_string (buffer, "exceptionBlock ");
741 if (props & PR_HASELSE)
742 pp_string (buffer, "hasElse ");
743 if (props & PR_READONLY)
744 pp_string (buffer, "readOnly ");
745
746 pp_string (buffer, "]");
747 }
748 }
749
750
751 /* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
752 pp_gimple_stmt_1. */
753
754 static void
755 dump_gimple_switch (pretty_printer *buffer, gimple gs, int spc, int flags)
756 {
757 unsigned int i;
758
759 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
760 if (flags & TDF_RAW)
761 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
762 gimple_switch_index (gs));
763 else
764 {
765 pp_string (buffer, "switch (");
766 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
767 pp_string (buffer, ") <");
768 }
769
770 for (i = 0; i < gimple_switch_num_labels (gs); i++)
771 {
772 tree case_label = gimple_switch_label (gs, i);
773 gcc_checking_assert (case_label != NULL_TREE);
774 dump_generic_node (buffer, case_label, spc, flags, false);
775 pp_character (buffer, ' ');
776 dump_generic_node (buffer, CASE_LABEL (case_label), spc, flags, false);
777 if (i < gimple_switch_num_labels (gs) - 1)
778 pp_string (buffer, ", ");
779 }
780 pp_character (buffer, '>');
781 }
782
783
784 /* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
785 pp_gimple_stmt_1. */
786
787 static void
788 dump_gimple_cond (pretty_printer *buffer, gimple gs, int spc, int flags)
789 {
790 if (flags & TDF_RAW)
791 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
792 tree_code_name [gimple_cond_code (gs)],
793 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
794 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
795 else
796 {
797 if (!(flags & TDF_RHS_ONLY))
798 pp_string (buffer, "if (");
799 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
800 pp_space (buffer);
801 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
802 pp_space (buffer);
803 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
804 if (!(flags & TDF_RHS_ONLY))
805 {
806 pp_character (buffer, ')');
807
808 if (gimple_cond_true_label (gs))
809 {
810 pp_string (buffer, " goto ");
811 dump_generic_node (buffer, gimple_cond_true_label (gs),
812 spc, flags, false);
813 pp_semicolon (buffer);
814 }
815 if (gimple_cond_false_label (gs))
816 {
817 pp_string (buffer, " else goto ");
818 dump_generic_node (buffer, gimple_cond_false_label (gs),
819 spc, flags, false);
820 pp_semicolon (buffer);
821 }
822 }
823 }
824 }
825
826
827 /* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
828 spaces of indent. FLAGS specifies details to show in the dump (see
829 TDF_* in dumpfils.h). */
830
831 static void
832 dump_gimple_label (pretty_printer *buffer, gimple gs, int spc, int flags)
833 {
834 tree label = gimple_label_label (gs);
835 if (flags & TDF_RAW)
836 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
837 else
838 {
839 dump_generic_node (buffer, label, spc, flags, false);
840 pp_character (buffer, ':');
841 }
842 if (DECL_NONLOCAL (label))
843 pp_string (buffer, " [non-local]");
844 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
845 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
846 }
847
848 /* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
849 spaces of indent. FLAGS specifies details to show in the dump (see
850 TDF_* in dumpfile.h). */
851
852 static void
853 dump_gimple_goto (pretty_printer *buffer, gimple gs, int spc, int flags)
854 {
855 tree label = gimple_goto_dest (gs);
856 if (flags & TDF_RAW)
857 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
858 else
859 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
860 }
861
862
863 /* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
864 spaces of indent. FLAGS specifies details to show in the dump (see
865 TDF_* in dumpfile.h). */
866
867 static void
868 dump_gimple_bind (pretty_printer *buffer, gimple gs, int spc, int flags)
869 {
870 if (flags & TDF_RAW)
871 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
872 else
873 pp_character (buffer, '{');
874 if (!(flags & TDF_SLIM))
875 {
876 tree var;
877
878 for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
879 {
880 newline_and_indent (buffer, 2);
881 print_declaration (buffer, var, spc, flags);
882 }
883 if (gimple_bind_vars (gs))
884 pp_newline (buffer);
885 }
886 pp_newline (buffer);
887 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
888 newline_and_indent (buffer, spc);
889 if (flags & TDF_RAW)
890 pp_character (buffer, '>');
891 else
892 pp_character (buffer, '}');
893 }
894
895
896 /* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
897 indent. FLAGS specifies details to show in the dump (see TDF_* in
898 dumpfile.h). */
899
900 static void
901 dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
902 {
903 if (flags & TDF_RAW)
904 {
905 const char *type;
906 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
907 type = "GIMPLE_TRY_CATCH";
908 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
909 type = "GIMPLE_TRY_FINALLY";
910 else
911 type = "UNKNOWN GIMPLE_TRY";
912 dump_gimple_fmt (buffer, spc, flags,
913 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
914 gimple_try_eval (gs), gimple_try_cleanup (gs));
915 }
916 else
917 {
918 pp_string (buffer, "try");
919 newline_and_indent (buffer, spc + 2);
920 pp_character (buffer, '{');
921 pp_newline (buffer);
922
923 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
924 newline_and_indent (buffer, spc + 2);
925 pp_character (buffer, '}');
926
927 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
928 {
929 newline_and_indent (buffer, spc);
930 pp_string (buffer, "catch");
931 newline_and_indent (buffer, spc + 2);
932 pp_character (buffer, '{');
933 }
934 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
935 {
936 newline_and_indent (buffer, spc);
937 pp_string (buffer, "finally");
938 newline_and_indent (buffer, spc + 2);
939 pp_character (buffer, '{');
940 }
941 else
942 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
943
944 pp_newline (buffer);
945 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
946 newline_and_indent (buffer, spc + 2);
947 pp_character (buffer, '}');
948 }
949 }
950
951
952 /* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
953 indent. FLAGS specifies details to show in the dump (see TDF_* in
954 dumpfile.h). */
955
956 static void
957 dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
958 {
959 if (flags & TDF_RAW)
960 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
961 gimple_catch_types (gs), gimple_catch_handler (gs));
962 else
963 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
964 gimple_catch_types (gs), gimple_catch_handler (gs));
965 }
966
967
968 /* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
969 indent. FLAGS specifies details to show in the dump (see TDF_* in
970 dumpfile.h). */
971
972 static void
973 dump_gimple_eh_filter (pretty_printer *buffer, gimple gs, int spc, int flags)
974 {
975 if (flags & TDF_RAW)
976 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
977 gimple_eh_filter_types (gs),
978 gimple_eh_filter_failure (gs));
979 else
980 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
981 gimple_eh_filter_types (gs),
982 gimple_eh_filter_failure (gs));
983 }
984
985
986 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
987
988 static void
989 dump_gimple_eh_must_not_throw (pretty_printer *buffer, gimple gs,
990 int spc, int flags)
991 {
992 if (flags & TDF_RAW)
993 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
994 gimple_eh_must_not_throw_fndecl (gs));
995 else
996 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
997 gimple_eh_must_not_throw_fndecl (gs));
998 }
999
1000
1001 /* Dump a GIMPLE_EH_ELSE tuple on the pretty_printer BUFFER, SPC spaces of
1002 indent. FLAGS specifies details to show in the dump (see TDF_* in
1003 dumpfile.h). */
1004
1005 static void
1006 dump_gimple_eh_else (pretty_printer *buffer, gimple gs, int spc, int flags)
1007 {
1008 if (flags & TDF_RAW)
1009 dump_gimple_fmt (buffer, spc, flags,
1010 "%G <%+N_BODY <%S>%nE_BODY <%S>%->", gs,
1011 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1012 else
1013 dump_gimple_fmt (buffer, spc, flags,
1014 "<<<if_normal_exit>>>%+{%S}%-<<<else_eh_exit>>>%+{%S}",
1015 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1016 }
1017
1018
1019 /* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
1020 indent. FLAGS specifies details to show in the dump (see TDF_* in
1021 dumpfile.h). */
1022
1023 static void
1024 dump_gimple_resx (pretty_printer *buffer, gimple gs, int spc, int flags)
1025 {
1026 if (flags & TDF_RAW)
1027 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1028 gimple_resx_region (gs));
1029 else
1030 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
1031 }
1032
1033 /* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
1034
1035 static void
1036 dump_gimple_eh_dispatch (pretty_printer *buffer, gimple gs, int spc, int flags)
1037 {
1038 if (flags & TDF_RAW)
1039 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1040 gimple_eh_dispatch_region (gs));
1041 else
1042 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
1043 gimple_eh_dispatch_region (gs));
1044 }
1045
1046 /* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
1047 of indent. FLAGS specifies details to show in the dump (see TDF_*
1048 in dumpfile.h). */
1049
1050 static void
1051 dump_gimple_debug (pretty_printer *buffer, gimple gs, int spc, int flags)
1052 {
1053 switch (gs->gsbase.subcode)
1054 {
1055 case GIMPLE_DEBUG_BIND:
1056 if (flags & TDF_RAW)
1057 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
1058 gimple_debug_bind_get_var (gs),
1059 gimple_debug_bind_get_value (gs));
1060 else
1061 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
1062 gimple_debug_bind_get_var (gs),
1063 gimple_debug_bind_get_value (gs));
1064 break;
1065
1066 case GIMPLE_DEBUG_SOURCE_BIND:
1067 if (flags & TDF_RAW)
1068 dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1069 gimple_debug_source_bind_get_var (gs),
1070 gimple_debug_source_bind_get_value (gs));
1071 else
1072 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1073 gimple_debug_source_bind_get_var (gs),
1074 gimple_debug_source_bind_get_value (gs));
1075 break;
1076
1077 default:
1078 gcc_unreachable ();
1079 }
1080 }
1081
1082 /* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
1083 static void
1084 dump_gimple_omp_for (pretty_printer *buffer, gimple gs, int spc, int flags)
1085 {
1086 size_t i;
1087
1088 if (flags & TDF_RAW)
1089 {
1090 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1091 gimple_omp_body (gs));
1092 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1093 dump_gimple_fmt (buffer, spc, flags, " >,");
1094 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1095 dump_gimple_fmt (buffer, spc, flags,
1096 "%+%T, %T, %T, %s, %T,%n",
1097 gimple_omp_for_index (gs, i),
1098 gimple_omp_for_initial (gs, i),
1099 gimple_omp_for_final (gs, i),
1100 tree_code_name[gimple_omp_for_cond (gs, i)],
1101 gimple_omp_for_incr (gs, i));
1102 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1103 gimple_omp_for_pre_body (gs));
1104 }
1105 else
1106 {
1107 pp_string (buffer, "#pragma omp for");
1108 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1109 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1110 {
1111 if (i)
1112 spc += 2;
1113 newline_and_indent (buffer, spc);
1114 pp_string (buffer, "for (");
1115 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1116 flags, false);
1117 pp_string (buffer, " = ");
1118 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1119 flags, false);
1120 pp_string (buffer, "; ");
1121
1122 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1123 flags, false);
1124 pp_space (buffer);
1125 switch (gimple_omp_for_cond (gs, i))
1126 {
1127 case LT_EXPR:
1128 pp_character (buffer, '<');
1129 break;
1130 case GT_EXPR:
1131 pp_character (buffer, '>');
1132 break;
1133 case LE_EXPR:
1134 pp_string (buffer, "<=");
1135 break;
1136 case GE_EXPR:
1137 pp_string (buffer, ">=");
1138 break;
1139 default:
1140 gcc_unreachable ();
1141 }
1142 pp_space (buffer);
1143 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1144 flags, false);
1145 pp_string (buffer, "; ");
1146
1147 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1148 flags, false);
1149 pp_string (buffer, " = ");
1150 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1151 flags, false);
1152 pp_character (buffer, ')');
1153 }
1154
1155 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1156 {
1157 newline_and_indent (buffer, spc + 2);
1158 pp_character (buffer, '{');
1159 pp_newline (buffer);
1160 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1161 newline_and_indent (buffer, spc + 2);
1162 pp_character (buffer, '}');
1163 }
1164 }
1165 }
1166
1167 /* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
1168
1169 static void
1170 dump_gimple_omp_continue (pretty_printer *buffer, gimple gs, int spc, int flags)
1171 {
1172 if (flags & TDF_RAW)
1173 {
1174 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1175 gimple_omp_continue_control_def (gs),
1176 gimple_omp_continue_control_use (gs));
1177 }
1178 else
1179 {
1180 pp_string (buffer, "#pragma omp continue (");
1181 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1182 spc, flags, false);
1183 pp_character (buffer, ',');
1184 pp_space (buffer);
1185 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1186 spc, flags, false);
1187 pp_character (buffer, ')');
1188 }
1189 }
1190
1191 /* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1192
1193 static void
1194 dump_gimple_omp_single (pretty_printer *buffer, gimple gs, int spc, int flags)
1195 {
1196 if (flags & TDF_RAW)
1197 {
1198 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1199 gimple_omp_body (gs));
1200 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1201 dump_gimple_fmt (buffer, spc, flags, " >");
1202 }
1203 else
1204 {
1205 pp_string (buffer, "#pragma omp single");
1206 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1207 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1208 {
1209 newline_and_indent (buffer, spc + 2);
1210 pp_character (buffer, '{');
1211 pp_newline (buffer);
1212 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1213 newline_and_indent (buffer, spc + 2);
1214 pp_character (buffer, '}');
1215 }
1216 }
1217 }
1218
1219 /* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1220
1221 static void
1222 dump_gimple_omp_sections (pretty_printer *buffer, gimple gs, int spc,
1223 int flags)
1224 {
1225 if (flags & TDF_RAW)
1226 {
1227 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1228 gimple_omp_body (gs));
1229 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1230 dump_gimple_fmt (buffer, spc, flags, " >");
1231 }
1232 else
1233 {
1234 pp_string (buffer, "#pragma omp sections");
1235 if (gimple_omp_sections_control (gs))
1236 {
1237 pp_string (buffer, " <");
1238 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1239 flags, false);
1240 pp_character (buffer, '>');
1241 }
1242 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1243 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1244 {
1245 newline_and_indent (buffer, spc + 2);
1246 pp_character (buffer, '{');
1247 pp_newline (buffer);
1248 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1249 newline_and_indent (buffer, spc + 2);
1250 pp_character (buffer, '}');
1251 }
1252 }
1253 }
1254
1255 /* Dump a GIMPLE_OMP_{MASTER,ORDERED,SECTION} tuple on the pretty_printer
1256 BUFFER. */
1257
1258 static void
1259 dump_gimple_omp_block (pretty_printer *buffer, gimple gs, int spc, int flags)
1260 {
1261 if (flags & TDF_RAW)
1262 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1263 gimple_omp_body (gs));
1264 else
1265 {
1266 switch (gimple_code (gs))
1267 {
1268 case GIMPLE_OMP_MASTER:
1269 pp_string (buffer, "#pragma omp master");
1270 break;
1271 case GIMPLE_OMP_ORDERED:
1272 pp_string (buffer, "#pragma omp ordered");
1273 break;
1274 case GIMPLE_OMP_SECTION:
1275 pp_string (buffer, "#pragma omp section");
1276 break;
1277 default:
1278 gcc_unreachable ();
1279 }
1280 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1281 {
1282 newline_and_indent (buffer, spc + 2);
1283 pp_character (buffer, '{');
1284 pp_newline (buffer);
1285 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1286 newline_and_indent (buffer, spc + 2);
1287 pp_character (buffer, '}');
1288 }
1289 }
1290 }
1291
1292 /* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1293
1294 static void
1295 dump_gimple_omp_critical (pretty_printer *buffer, gimple gs, int spc,
1296 int flags)
1297 {
1298 if (flags & TDF_RAW)
1299 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1300 gimple_omp_body (gs));
1301 else
1302 {
1303 pp_string (buffer, "#pragma omp critical");
1304 if (gimple_omp_critical_name (gs))
1305 {
1306 pp_string (buffer, " (");
1307 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1308 flags, false);
1309 pp_character (buffer, ')');
1310 }
1311 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1312 {
1313 newline_and_indent (buffer, spc + 2);
1314 pp_character (buffer, '{');
1315 pp_newline (buffer);
1316 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1317 newline_and_indent (buffer, spc + 2);
1318 pp_character (buffer, '}');
1319 }
1320 }
1321 }
1322
1323 /* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1324
1325 static void
1326 dump_gimple_omp_return (pretty_printer *buffer, gimple gs, int spc, int flags)
1327 {
1328 if (flags & TDF_RAW)
1329 {
1330 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d>", gs,
1331 (int) gimple_omp_return_nowait_p (gs));
1332 }
1333 else
1334 {
1335 pp_string (buffer, "#pragma omp return");
1336 if (gimple_omp_return_nowait_p (gs))
1337 pp_string (buffer, "(nowait)");
1338 }
1339 }
1340
1341 /* Dump a GIMPLE_TRANSACTION tuple on the pretty_printer BUFFER. */
1342
1343 static void
1344 dump_gimple_transaction (pretty_printer *buffer, gimple gs, int spc, int flags)
1345 {
1346 unsigned subcode = gimple_transaction_subcode (gs);
1347
1348 if (flags & TDF_RAW)
1349 {
1350 dump_gimple_fmt (buffer, spc, flags,
1351 "%G [SUBCODE=%x,LABEL=%T] <%+BODY <%S> >",
1352 gs, subcode, gimple_transaction_label (gs),
1353 gimple_transaction_body (gs));
1354 }
1355 else
1356 {
1357 if (subcode & GTMA_IS_OUTER)
1358 pp_string (buffer, "__transaction_atomic [[outer]]");
1359 else if (subcode & GTMA_IS_RELAXED)
1360 pp_string (buffer, "__transaction_relaxed");
1361 else
1362 pp_string (buffer, "__transaction_atomic");
1363 subcode &= ~GTMA_DECLARATION_MASK;
1364
1365 if (subcode || gimple_transaction_label (gs))
1366 {
1367 pp_string (buffer, " //");
1368 if (gimple_transaction_label (gs))
1369 {
1370 pp_string (buffer, " LABEL=");
1371 dump_generic_node (buffer, gimple_transaction_label (gs),
1372 spc, flags, false);
1373 }
1374 if (subcode)
1375 {
1376 pp_string (buffer, " SUBCODE=[ ");
1377 if (subcode & GTMA_HAVE_ABORT)
1378 {
1379 pp_string (buffer, "GTMA_HAVE_ABORT ");
1380 subcode &= ~GTMA_HAVE_ABORT;
1381 }
1382 if (subcode & GTMA_HAVE_LOAD)
1383 {
1384 pp_string (buffer, "GTMA_HAVE_LOAD ");
1385 subcode &= ~GTMA_HAVE_LOAD;
1386 }
1387 if (subcode & GTMA_HAVE_STORE)
1388 {
1389 pp_string (buffer, "GTMA_HAVE_STORE ");
1390 subcode &= ~GTMA_HAVE_STORE;
1391 }
1392 if (subcode & GTMA_MAY_ENTER_IRREVOCABLE)
1393 {
1394 pp_string (buffer, "GTMA_MAY_ENTER_IRREVOCABLE ");
1395 subcode &= ~GTMA_MAY_ENTER_IRREVOCABLE;
1396 }
1397 if (subcode & GTMA_DOES_GO_IRREVOCABLE)
1398 {
1399 pp_string (buffer, "GTMA_DOES_GO_IRREVOCABLE ");
1400 subcode &= ~GTMA_DOES_GO_IRREVOCABLE;
1401 }
1402 if (subcode)
1403 pp_printf (buffer, "0x%x ", subcode);
1404 pp_string (buffer, "]");
1405 }
1406 }
1407
1408 if (!gimple_seq_empty_p (gimple_transaction_body (gs)))
1409 {
1410 newline_and_indent (buffer, spc + 2);
1411 pp_character (buffer, '{');
1412 pp_newline (buffer);
1413 dump_gimple_seq (buffer, gimple_transaction_body (gs),
1414 spc + 4, flags);
1415 newline_and_indent (buffer, spc + 2);
1416 pp_character (buffer, '}');
1417 }
1418 }
1419 }
1420
1421 /* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1422 indent. FLAGS specifies details to show in the dump (see TDF_* in
1423 dumpfile.h). */
1424
1425 static void
1426 dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
1427 {
1428 unsigned int i, n, f, fields;
1429
1430 if (flags & TDF_RAW)
1431 {
1432 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1433 gimple_asm_string (gs));
1434
1435 n = gimple_asm_noutputs (gs);
1436 if (n)
1437 {
1438 newline_and_indent (buffer, spc + 2);
1439 pp_string (buffer, "OUTPUT: ");
1440 for (i = 0; i < n; i++)
1441 {
1442 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1443 spc, flags, false);
1444 if (i < n - 1)
1445 pp_string (buffer, ", ");
1446 }
1447 }
1448
1449 n = gimple_asm_ninputs (gs);
1450 if (n)
1451 {
1452 newline_and_indent (buffer, spc + 2);
1453 pp_string (buffer, "INPUT: ");
1454 for (i = 0; i < n; i++)
1455 {
1456 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1457 spc, flags, false);
1458 if (i < n - 1)
1459 pp_string (buffer, ", ");
1460 }
1461 }
1462
1463 n = gimple_asm_nclobbers (gs);
1464 if (n)
1465 {
1466 newline_and_indent (buffer, spc + 2);
1467 pp_string (buffer, "CLOBBER: ");
1468 for (i = 0; i < n; i++)
1469 {
1470 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1471 spc, flags, false);
1472 if (i < n - 1)
1473 pp_string (buffer, ", ");
1474 }
1475 }
1476
1477 n = gimple_asm_nlabels (gs);
1478 if (n)
1479 {
1480 newline_and_indent (buffer, spc + 2);
1481 pp_string (buffer, "LABEL: ");
1482 for (i = 0; i < n; i++)
1483 {
1484 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1485 spc, flags, false);
1486 if (i < n - 1)
1487 pp_string (buffer, ", ");
1488 }
1489 }
1490
1491 newline_and_indent (buffer, spc);
1492 pp_character (buffer, '>');
1493 }
1494 else
1495 {
1496 pp_string (buffer, "__asm__");
1497 if (gimple_asm_volatile_p (gs))
1498 pp_string (buffer, " __volatile__");
1499 if (gimple_asm_nlabels (gs))
1500 pp_string (buffer, " goto");
1501 pp_string (buffer, "(\"");
1502 pp_string (buffer, gimple_asm_string (gs));
1503 pp_string (buffer, "\"");
1504
1505 if (gimple_asm_nlabels (gs))
1506 fields = 4;
1507 else if (gimple_asm_nclobbers (gs))
1508 fields = 3;
1509 else if (gimple_asm_ninputs (gs))
1510 fields = 2;
1511 else if (gimple_asm_noutputs (gs))
1512 fields = 1;
1513 else
1514 fields = 0;
1515
1516 for (f = 0; f < fields; ++f)
1517 {
1518 pp_string (buffer, " : ");
1519
1520 switch (f)
1521 {
1522 case 0:
1523 n = gimple_asm_noutputs (gs);
1524 for (i = 0; i < n; i++)
1525 {
1526 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1527 spc, flags, false);
1528 if (i < n - 1)
1529 pp_string (buffer, ", ");
1530 }
1531 break;
1532
1533 case 1:
1534 n = gimple_asm_ninputs (gs);
1535 for (i = 0; i < n; i++)
1536 {
1537 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1538 spc, flags, false);
1539 if (i < n - 1)
1540 pp_string (buffer, ", ");
1541 }
1542 break;
1543
1544 case 2:
1545 n = gimple_asm_nclobbers (gs);
1546 for (i = 0; i < n; i++)
1547 {
1548 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
1549 spc, flags, false);
1550 if (i < n - 1)
1551 pp_string (buffer, ", ");
1552 }
1553 break;
1554
1555 case 3:
1556 n = gimple_asm_nlabels (gs);
1557 for (i = 0; i < n; i++)
1558 {
1559 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
1560 spc, flags, false);
1561 if (i < n - 1)
1562 pp_string (buffer, ", ");
1563 }
1564 break;
1565
1566 default:
1567 gcc_unreachable ();
1568 }
1569 }
1570
1571 pp_string (buffer, ");");
1572 }
1573 }
1574
1575
1576 /* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
1577 The caller is responsible for calling pp_flush on BUFFER to finalize
1578 pretty printer. */
1579
1580 static void
1581 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
1582 {
1583 size_t i;
1584 tree lhs = gimple_phi_result (phi);
1585
1586 if (flags & TDF_ALIAS
1587 && POINTER_TYPE_P (TREE_TYPE (lhs))
1588 && SSA_NAME_PTR_INFO (lhs))
1589 {
1590 unsigned int align, misalign;
1591 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
1592 pp_string (buffer, "PT = ");
1593 pp_points_to_solution (buffer, &pi->pt);
1594 newline_and_indent (buffer, spc);
1595 if (get_ptr_info_alignment (pi, &align, &misalign))
1596 {
1597 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u", align, misalign);
1598 newline_and_indent (buffer, spc);
1599 }
1600 pp_string (buffer, "# ");
1601 }
1602
1603 if (flags & TDF_RAW)
1604 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
1605 gimple_phi_result (phi));
1606 else
1607 {
1608 dump_generic_node (buffer, lhs, spc, flags, false);
1609 pp_string (buffer, " = PHI <");
1610 }
1611 for (i = 0; i < gimple_phi_num_args (phi); i++)
1612 {
1613 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
1614 {
1615 expanded_location xloc;
1616
1617 xloc = expand_location (gimple_phi_arg_location (phi, i));
1618 pp_character (buffer, '[');
1619 if (xloc.file)
1620 {
1621 pp_string (buffer, xloc.file);
1622 pp_string (buffer, " : ");
1623 }
1624 pp_decimal_int (buffer, xloc.line);
1625 pp_string (buffer, ":");
1626 pp_decimal_int (buffer, xloc.column);
1627 pp_string (buffer, "] ");
1628 }
1629 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
1630 false);
1631 pp_character (buffer, '(');
1632 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
1633 pp_character (buffer, ')');
1634 if (i < gimple_phi_num_args (phi) - 1)
1635 pp_string (buffer, ", ");
1636 }
1637 pp_character (buffer, '>');
1638 }
1639
1640
1641 /* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
1642 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1643 dumpfile.h). */
1644
1645 static void
1646 dump_gimple_omp_parallel (pretty_printer *buffer, gimple gs, int spc,
1647 int flags)
1648 {
1649 if (flags & TDF_RAW)
1650 {
1651 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1652 gimple_omp_body (gs));
1653 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1654 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1655 gimple_omp_parallel_child_fn (gs),
1656 gimple_omp_parallel_data_arg (gs));
1657 }
1658 else
1659 {
1660 gimple_seq body;
1661 pp_string (buffer, "#pragma omp parallel");
1662 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
1663 if (gimple_omp_parallel_child_fn (gs))
1664 {
1665 pp_string (buffer, " [child fn: ");
1666 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
1667 spc, flags, false);
1668 pp_string (buffer, " (");
1669 if (gimple_omp_parallel_data_arg (gs))
1670 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
1671 spc, flags, false);
1672 else
1673 pp_string (buffer, "???");
1674 pp_string (buffer, ")]");
1675 }
1676 body = gimple_omp_body (gs);
1677 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1678 {
1679 newline_and_indent (buffer, spc + 2);
1680 pp_character (buffer, '{');
1681 pp_newline (buffer);
1682 dump_gimple_seq (buffer, body, spc + 4, flags);
1683 newline_and_indent (buffer, spc + 2);
1684 pp_character (buffer, '}');
1685 }
1686 else if (body)
1687 {
1688 pp_newline (buffer);
1689 dump_gimple_seq (buffer, body, spc + 2, flags);
1690 }
1691 }
1692 }
1693
1694
1695 /* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
1696 of indent. FLAGS specifies details to show in the dump (see TDF_* in
1697 dumpfile.h). */
1698
1699 static void
1700 dump_gimple_omp_task (pretty_printer *buffer, gimple gs, int spc,
1701 int flags)
1702 {
1703 if (flags & TDF_RAW)
1704 {
1705 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1706 gimple_omp_body (gs));
1707 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1708 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
1709 gimple_omp_task_child_fn (gs),
1710 gimple_omp_task_data_arg (gs),
1711 gimple_omp_task_copy_fn (gs),
1712 gimple_omp_task_arg_size (gs),
1713 gimple_omp_task_arg_size (gs));
1714 }
1715 else
1716 {
1717 gimple_seq body;
1718 pp_string (buffer, "#pragma omp task");
1719 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
1720 if (gimple_omp_task_child_fn (gs))
1721 {
1722 pp_string (buffer, " [child fn: ");
1723 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
1724 spc, flags, false);
1725 pp_string (buffer, " (");
1726 if (gimple_omp_task_data_arg (gs))
1727 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
1728 spc, flags, false);
1729 else
1730 pp_string (buffer, "???");
1731 pp_string (buffer, ")]");
1732 }
1733 body = gimple_omp_body (gs);
1734 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1735 {
1736 newline_and_indent (buffer, spc + 2);
1737 pp_character (buffer, '{');
1738 pp_newline (buffer);
1739 dump_gimple_seq (buffer, body, spc + 4, flags);
1740 newline_and_indent (buffer, spc + 2);
1741 pp_character (buffer, '}');
1742 }
1743 else if (body)
1744 {
1745 pp_newline (buffer);
1746 dump_gimple_seq (buffer, body, spc + 2, flags);
1747 }
1748 }
1749 }
1750
1751
1752 /* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
1753 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1754 in dumpfile.h). */
1755
1756 static void
1757 dump_gimple_omp_atomic_load (pretty_printer *buffer, gimple gs, int spc,
1758 int flags)
1759 {
1760 if (flags & TDF_RAW)
1761 {
1762 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1763 gimple_omp_atomic_load_lhs (gs),
1764 gimple_omp_atomic_load_rhs (gs));
1765 }
1766 else
1767 {
1768 pp_string (buffer, "#pragma omp atomic_load");
1769 if (gimple_omp_atomic_need_value_p (gs))
1770 pp_string (buffer, " [needed]");
1771 newline_and_indent (buffer, spc + 2);
1772 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
1773 spc, flags, false);
1774 pp_space (buffer);
1775 pp_character (buffer, '=');
1776 pp_space (buffer);
1777 pp_character (buffer, '*');
1778 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
1779 spc, flags, false);
1780 }
1781 }
1782
1783 /* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
1784 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
1785 in dumpfile.h). */
1786
1787 static void
1788 dump_gimple_omp_atomic_store (pretty_printer *buffer, gimple gs, int spc,
1789 int flags)
1790 {
1791 if (flags & TDF_RAW)
1792 {
1793 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1794 gimple_omp_atomic_store_val (gs));
1795 }
1796 else
1797 {
1798 pp_string (buffer, "#pragma omp atomic_store ");
1799 if (gimple_omp_atomic_need_value_p (gs))
1800 pp_string (buffer, "[needed] ");
1801 pp_character (buffer, '(');
1802 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
1803 spc, flags, false);
1804 pp_character (buffer, ')');
1805 }
1806 }
1807
1808
1809 /* Dump all the memory operands for statement GS. BUFFER, SPC and
1810 FLAGS are as in pp_gimple_stmt_1. */
1811
1812 static void
1813 dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
1814 {
1815 tree vdef = gimple_vdef (gs);
1816 tree vuse = gimple_vuse (gs);
1817
1818 if (!ssa_operands_active (DECL_STRUCT_FUNCTION (current_function_decl))
1819 || !gimple_references_memory_p (gs))
1820 return;
1821
1822 if (vdef != NULL_TREE)
1823 {
1824 pp_string (buffer, "# ");
1825 dump_generic_node (buffer, vdef, spc + 2, flags, false);
1826 pp_string (buffer, " = VDEF <");
1827 dump_generic_node (buffer, vuse, spc + 2, flags, false);
1828 pp_character (buffer, '>');
1829 newline_and_indent (buffer, spc);
1830 }
1831 else if (vuse != NULL_TREE)
1832 {
1833 pp_string (buffer, "# VUSE <");
1834 dump_generic_node (buffer, vuse, spc + 2, flags, false);
1835 pp_character (buffer, '>');
1836 newline_and_indent (buffer, spc);
1837 }
1838 }
1839
1840
1841 /* Print the gimple statement GS on the pretty printer BUFFER, SPC
1842 spaces of indent. FLAGS specifies details to show in the dump (see
1843 TDF_* in dumpfile.h). The caller is responsible for calling
1844 pp_flush on BUFFER to finalize the pretty printer. */
1845
1846 void
1847 pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags)
1848 {
1849 if (!gs)
1850 return;
1851
1852 if (flags & TDF_STMTADDR)
1853 pp_printf (buffer, "<&%p> ", (void *) gs);
1854
1855 if ((flags & TDF_LINENO) && gimple_has_location (gs))
1856 {
1857 expanded_location xloc = expand_location (gimple_location (gs));
1858 pp_character (buffer, '[');
1859 if (xloc.file)
1860 {
1861 pp_string (buffer, xloc.file);
1862 pp_string (buffer, " : ");
1863 }
1864 pp_decimal_int (buffer, xloc.line);
1865 pp_string (buffer, ":");
1866 pp_decimal_int (buffer, xloc.column);
1867 pp_string (buffer, "] ");
1868 }
1869
1870 if (flags & TDF_EH)
1871 {
1872 int lp_nr = lookup_stmt_eh_lp (gs);
1873 if (lp_nr > 0)
1874 pp_printf (buffer, "[LP %d] ", lp_nr);
1875 else if (lp_nr < 0)
1876 pp_printf (buffer, "[MNT %d] ", -lp_nr);
1877 }
1878
1879 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
1880 && gimple_has_mem_ops (gs))
1881 dump_gimple_mem_ops (buffer, gs, spc, flags);
1882
1883 if ((flags & TDF_ALIAS)
1884 && gimple_has_lhs (gs))
1885 {
1886 tree lhs = gimple_get_lhs (gs);
1887 if (TREE_CODE (lhs) == SSA_NAME
1888 && POINTER_TYPE_P (TREE_TYPE (lhs))
1889 && SSA_NAME_PTR_INFO (lhs))
1890 {
1891 unsigned int align, misalign;
1892 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (lhs);
1893 pp_string (buffer, "# PT = ");
1894 pp_points_to_solution (buffer, &pi->pt);
1895 newline_and_indent (buffer, spc);
1896 if (get_ptr_info_alignment (pi, &align, &misalign))
1897 {
1898 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u",
1899 align, misalign);
1900 newline_and_indent (buffer, spc);
1901 }
1902 }
1903 }
1904
1905 switch (gimple_code (gs))
1906 {
1907 case GIMPLE_ASM:
1908 dump_gimple_asm (buffer, gs, spc, flags);
1909 break;
1910
1911 case GIMPLE_ASSIGN:
1912 dump_gimple_assign (buffer, gs, spc, flags);
1913 break;
1914
1915 case GIMPLE_BIND:
1916 dump_gimple_bind (buffer, gs, spc, flags);
1917 break;
1918
1919 case GIMPLE_CALL:
1920 dump_gimple_call (buffer, gs, spc, flags);
1921 break;
1922
1923 case GIMPLE_COND:
1924 dump_gimple_cond (buffer, gs, spc, flags);
1925 break;
1926
1927 case GIMPLE_LABEL:
1928 dump_gimple_label (buffer, gs, spc, flags);
1929 break;
1930
1931 case GIMPLE_GOTO:
1932 dump_gimple_goto (buffer, gs, spc, flags);
1933 break;
1934
1935 case GIMPLE_NOP:
1936 pp_string (buffer, "GIMPLE_NOP");
1937 break;
1938
1939 case GIMPLE_RETURN:
1940 dump_gimple_return (buffer, gs, spc, flags);
1941 break;
1942
1943 case GIMPLE_SWITCH:
1944 dump_gimple_switch (buffer, gs, spc, flags);
1945 break;
1946
1947 case GIMPLE_TRY:
1948 dump_gimple_try (buffer, gs, spc, flags);
1949 break;
1950
1951 case GIMPLE_PHI:
1952 dump_gimple_phi (buffer, gs, spc, flags);
1953 break;
1954
1955 case GIMPLE_OMP_PARALLEL:
1956 dump_gimple_omp_parallel (buffer, gs, spc, flags);
1957 break;
1958
1959 case GIMPLE_OMP_TASK:
1960 dump_gimple_omp_task (buffer, gs, spc, flags);
1961 break;
1962
1963 case GIMPLE_OMP_ATOMIC_LOAD:
1964 dump_gimple_omp_atomic_load (buffer, gs, spc, flags);
1965
1966 break;
1967
1968 case GIMPLE_OMP_ATOMIC_STORE:
1969 dump_gimple_omp_atomic_store (buffer, gs, spc, flags);
1970 break;
1971
1972 case GIMPLE_OMP_FOR:
1973 dump_gimple_omp_for (buffer, gs, spc, flags);
1974 break;
1975
1976 case GIMPLE_OMP_CONTINUE:
1977 dump_gimple_omp_continue (buffer, gs, spc, flags);
1978 break;
1979
1980 case GIMPLE_OMP_SINGLE:
1981 dump_gimple_omp_single (buffer, gs, spc, flags);
1982 break;
1983
1984 case GIMPLE_OMP_RETURN:
1985 dump_gimple_omp_return (buffer, gs, spc, flags);
1986 break;
1987
1988 case GIMPLE_OMP_SECTIONS:
1989 dump_gimple_omp_sections (buffer, gs, spc, flags);
1990 break;
1991
1992 case GIMPLE_OMP_SECTIONS_SWITCH:
1993 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
1994 break;
1995
1996 case GIMPLE_OMP_MASTER:
1997 case GIMPLE_OMP_ORDERED:
1998 case GIMPLE_OMP_SECTION:
1999 dump_gimple_omp_block (buffer, gs, spc, flags);
2000 break;
2001
2002 case GIMPLE_OMP_CRITICAL:
2003 dump_gimple_omp_critical (buffer, gs, spc, flags);
2004 break;
2005
2006 case GIMPLE_CATCH:
2007 dump_gimple_catch (buffer, gs, spc, flags);
2008 break;
2009
2010 case GIMPLE_EH_FILTER:
2011 dump_gimple_eh_filter (buffer, gs, spc, flags);
2012 break;
2013
2014 case GIMPLE_EH_MUST_NOT_THROW:
2015 dump_gimple_eh_must_not_throw (buffer, gs, spc, flags);
2016 break;
2017
2018 case GIMPLE_EH_ELSE:
2019 dump_gimple_eh_else (buffer, gs, spc, flags);
2020 break;
2021
2022 case GIMPLE_RESX:
2023 dump_gimple_resx (buffer, gs, spc, flags);
2024 break;
2025
2026 case GIMPLE_EH_DISPATCH:
2027 dump_gimple_eh_dispatch (buffer, gs, spc, flags);
2028 break;
2029
2030 case GIMPLE_DEBUG:
2031 dump_gimple_debug (buffer, gs, spc, flags);
2032 break;
2033
2034 case GIMPLE_PREDICT:
2035 pp_string (buffer, "// predicted ");
2036 if (gimple_predict_outcome (gs))
2037 pp_string (buffer, "likely by ");
2038 else
2039 pp_string (buffer, "unlikely by ");
2040 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
2041 pp_string (buffer, " predictor.");
2042 break;
2043
2044 case GIMPLE_TRANSACTION:
2045 dump_gimple_transaction (buffer, gs, spc, flags);
2046 break;
2047
2048 default:
2049 GIMPLE_NIY;
2050 }
2051 }
2052
2053
2054 /* Dumps header of basic block BB to OUTF indented by INDENT
2055 spaces and details described by flags. */
2056
2057 static void
2058 dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
2059 {
2060 if (flags & TDF_BLOCKS)
2061 {
2062 if (flags & TDF_LINENO)
2063 {
2064 gimple_stmt_iterator gsi;
2065
2066 if (flags & TDF_COMMENT)
2067 fputs (";; ", outf);
2068
2069 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2070 if (!is_gimple_debug (gsi_stmt (gsi))
2071 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
2072 {
2073 fprintf (outf, "%*sstarting at line %d",
2074 indent, "", get_lineno (gsi_stmt (gsi)));
2075 break;
2076 }
2077 if (bb->discriminator)
2078 fprintf (outf, ", discriminator %i", bb->discriminator);
2079 fputc ('\n', outf);
2080 }
2081 }
2082 else
2083 {
2084 gimple stmt = first_stmt (bb);
2085 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
2086 fprintf (outf, "%*s<bb %d>:\n", indent, "", bb->index);
2087 }
2088 }
2089
2090
2091 /* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2092 spaces. */
2093
2094 static void
2095 dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
2096 basic_block bb ATTRIBUTE_UNUSED,
2097 int indent ATTRIBUTE_UNUSED,
2098 int flags ATTRIBUTE_UNUSED)
2099 {
2100 /* There is currently no GIMPLE-specific basic block info to dump. */
2101 return;
2102 }
2103
2104
2105 /* Dump PHI nodes of basic block BB to BUFFER with details described
2106 by FLAGS and indented by INDENT spaces. */
2107
2108 static void
2109 dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent, int flags)
2110 {
2111 gimple_stmt_iterator i;
2112
2113 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2114 {
2115 gimple phi = gsi_stmt (i);
2116 if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2117 {
2118 INDENT (indent);
2119 pp_string (buffer, "# ");
2120 dump_gimple_phi (buffer, phi, indent, flags);
2121 pp_newline (buffer);
2122 }
2123 }
2124 }
2125
2126
2127 /* Dump jump to basic block BB that is represented implicitly in the cfg
2128 to BUFFER. */
2129
2130 static void
2131 pp_cfg_jump (pretty_printer *buffer, basic_block bb)
2132 {
2133 gimple stmt;
2134
2135 stmt = first_stmt (bb);
2136
2137 pp_string (buffer, "goto <bb ");
2138 pp_decimal_int (buffer, bb->index);
2139 pp_character (buffer, '>');
2140 if (stmt && gimple_code (stmt) == GIMPLE_LABEL)
2141 {
2142 pp_string (buffer, " (");
2143 dump_generic_node (buffer, gimple_label_label (stmt), 0, 0, false);
2144 pp_character (buffer, ')');
2145 pp_semicolon (buffer);
2146 }
2147 else
2148 pp_semicolon (buffer);
2149 }
2150
2151
2152 /* Dump edges represented implicitly in basic block BB to BUFFER, indented
2153 by INDENT spaces, with details given by FLAGS. */
2154
2155 static void
2156 dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2157 int flags)
2158 {
2159 edge e;
2160 gimple stmt;
2161
2162 stmt = last_stmt (bb);
2163
2164 if (stmt && gimple_code (stmt) == GIMPLE_COND)
2165 {
2166 edge true_edge, false_edge;
2167
2168 /* When we are emitting the code or changing CFG, it is possible that
2169 the edges are not yet created. When we are using debug_bb in such
2170 a situation, we do not want it to crash. */
2171 if (EDGE_COUNT (bb->succs) != 2)
2172 return;
2173 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2174
2175 INDENT (indent + 2);
2176 pp_cfg_jump (buffer, true_edge->dest);
2177 newline_and_indent (buffer, indent);
2178 pp_string (buffer, "else");
2179 newline_and_indent (buffer, indent + 2);
2180 pp_cfg_jump (buffer, false_edge->dest);
2181 pp_newline (buffer);
2182 return;
2183 }
2184
2185 /* If there is a fallthru edge, we may need to add an artificial
2186 goto to the dump. */
2187 e = find_fallthru_edge (bb->succs);
2188
2189 if (e && e->dest != bb->next_bb)
2190 {
2191 INDENT (indent);
2192
2193 if ((flags & TDF_LINENO)
2194 && e->goto_locus != UNKNOWN_LOCATION
2195 )
2196 {
2197 expanded_location goto_xloc;
2198 goto_xloc = expand_location (e->goto_locus);
2199 pp_character (buffer, '[');
2200 if (goto_xloc.file)
2201 {
2202 pp_string (buffer, goto_xloc.file);
2203 pp_string (buffer, " : ");
2204 }
2205 pp_decimal_int (buffer, goto_xloc.line);
2206 pp_string (buffer, " : ");
2207 pp_decimal_int (buffer, goto_xloc.column);
2208 pp_string (buffer, "] ");
2209 }
2210
2211 pp_cfg_jump (buffer, e->dest);
2212 pp_newline (buffer);
2213 }
2214 }
2215
2216
2217 /* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2218 indented by INDENT spaces. */
2219
2220 static void
2221 gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2222 int flags)
2223 {
2224 gimple_stmt_iterator gsi;
2225 gimple stmt;
2226 int label_indent = indent - 2;
2227
2228 if (label_indent < 0)
2229 label_indent = 0;
2230
2231 dump_phi_nodes (buffer, bb, indent, flags);
2232
2233 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2234 {
2235 int curr_indent;
2236
2237 stmt = gsi_stmt (gsi);
2238
2239 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2240
2241 INDENT (curr_indent);
2242 pp_gimple_stmt_1 (buffer, stmt, curr_indent, flags);
2243 pp_newline_and_flush (buffer);
2244 gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl));
2245 dump_histograms_for_stmt (DECL_STRUCT_FUNCTION (current_function_decl),
2246 buffer->buffer->stream, stmt);
2247 }
2248
2249 dump_implicit_edges (buffer, bb, indent, flags);
2250 pp_flush (buffer);
2251 }
2252
2253
2254 /* Dumps basic block BB to FILE with details described by FLAGS and
2255 indented by INDENT spaces. */
2256
2257 void
2258 gimple_dump_bb (FILE *file, basic_block bb, int indent, int flags)
2259 {
2260 dump_gimple_bb_header (file, bb, indent, flags);
2261 if (bb->index >= NUM_FIXED_BLOCKS)
2262 {
2263 maybe_init_pretty_print (file);
2264 gimple_dump_bb_buff (&buffer, bb, indent, flags);
2265 }
2266 dump_gimple_bb_footer (file, bb, indent, flags);
2267 }
2268
2269 /* Dumps basic block BB to pretty-printer PP with default dump flags and
2270 no indentation, for use as a label of a DOT graph record-node.
2271 ??? Should just use gimple_dump_bb_buff here, except that value profiling
2272 histogram dumping doesn't know about pretty-printers. */
2273
2274 void
2275 gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
2276 {
2277 gimple_stmt_iterator gsi;
2278
2279 pp_printf (pp, "<bb %d>:\n", bb->index);
2280 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2281
2282 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2283 {
2284 gimple phi = gsi_stmt (gsi);
2285 if (!virtual_operand_p (gimple_phi_result (phi))
2286 || (dump_flags & TDF_VOPS))
2287 {
2288 pp_character (pp, '|');
2289 pp_write_text_to_stream (pp);
2290 pp_string (pp, "# ");
2291 pp_gimple_stmt_1 (pp, phi, 0, dump_flags);
2292 pp_newline (pp);
2293 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2294 }
2295 }
2296
2297 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2298 {
2299 gimple stmt = gsi_stmt (gsi);
2300 pp_character (pp, '|');
2301 pp_write_text_to_stream (pp);
2302 pp_gimple_stmt_1 (pp, stmt, 0, dump_flags);
2303 pp_newline (pp);
2304 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2305 }
2306 dump_implicit_edges (pp, bb, 0, dump_flags);
2307 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2308 }
2309