1/* Pretty formatting of GIMPLE statements and expressions.
2 Copyright (C) 2001-2017 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldyh@redhat.com> and
4 Diego Novillo <dnovillo@google.com>
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along 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 "dumpfile.h"
26#include "backend.h"
27#include "tree.h"
28#include "gimple.h"
29#include "gimple-predict.h"
30#include "ssa.h"
31#include "cgraph.h"
32#include "gimple-pretty-print.h"
33#include "internal-fn.h"
34#include "tree-eh.h"
35#include "gimple-iterator.h"
36#include "tree-cfg.h"
37#include "dumpfile.h" /* for dump_flags */
38#include "value-prof.h"
39#include "trans-mem.h"
40#include "cfganal.h"
41#include "stringpool.h"
42#include "attribs.h"
43#include "asan.h"
44
45#define INDENT(SPACE) \
46 do { int i; for (i = 0; i < SPACE; i++) pp_space (buffer); } while (0)
47
48#define GIMPLE_NIY do_niy (buffer,gs)
49
50/* Try to print on BUFFER a default message for the unrecognized
51 gimple statement GS. */
52
53static void
54do_niy (pretty_printer *buffer, gimple *gs)
55{
56 pp_printf (buffer, "<<< Unknown GIMPLE statement: %s >>>\n",
57 gimple_code_name[(int) gimple_code (gs)]);
58}
59
60
61/* Emit a newline and SPC indentation spaces to BUFFER. */
62
63static void
64newline_and_indent (pretty_printer *buffer, int spc)
65{
66 pp_newline (buffer);
67 INDENT (spc);
68}
69
70
71/* Print the GIMPLE statement GS on stderr. */
72
73DEBUG_FUNCTION void
74debug_gimple_stmt (gimple *gs)
75{
76 print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
77}
78
79
80/* Return formatted string of a VALUE probability
81 (biased by REG_BR_PROB_BASE). Returned string is allocated
82 by xstrdup_for_dump. */
83
84static const char *
85dump_profile (profile_count &count)
86{
87 char *buf = NULL;
88 if (!count.initialized_p ())
89 return "";
90 if (count.ipa_p ())
91 buf = xasprintf ("[count: %" PRId64 "]",
92 count.to_gcov_type ());
93 else if (count.initialized_p ())
94 buf = xasprintf ("[local count: %" PRId64 "]",
95 count.to_gcov_type ());
96
97 const char *ret = xstrdup_for_dump (buf);
98 free (buf);
99
100 return ret;
101}
102
103/* Return formatted string of a VALUE probability
104 (biased by REG_BR_PROB_BASE). Returned string is allocated
105 by xstrdup_for_dump. */
106
107static const char *
108dump_probability (profile_probability probability)
109{
110 float minimum = 0.01f;
111 float fvalue = -1;
112
113 if (probability.initialized_p ())
114 {
115 fvalue = probability.to_reg_br_prob_base () * 100.0f / REG_BR_PROB_BASE;
116 if (fvalue < minimum && probability.to_reg_br_prob_base ())
117 fvalue = minimum;
118 }
119
120 char *buf;
121 if (probability.initialized_p ())
122 buf = xasprintf ("[%.2f%%]", fvalue);
123 else
124 buf = xasprintf ("[INV]");
125
126 const char *ret = xstrdup_for_dump (buf);
127 free (buf);
128
129 return ret;
130}
131
132/* Dump E probability to BUFFER. */
133
134static void
135dump_edge_probability (pretty_printer *buffer, edge e)
136{
137 pp_scalar (buffer, " %s", dump_probability (e->probability));
138}
139
140/* Print GIMPLE statement G to FILE using SPC indentation spaces and
141 FLAGS as in pp_gimple_stmt_1. */
142
143void
144print_gimple_stmt (FILE *file, gimple *g, int spc, dump_flags_t flags)
145{
146 pretty_printer buffer;
147 pp_needs_newline (&buffer) = true;
148 buffer.buffer->stream = file;
149 pp_gimple_stmt_1 (&buffer, g, spc, flags);
150 pp_newline_and_flush (&buffer);
151}
152
153DEBUG_FUNCTION void
154debug (gimple &ref)
155{
156 print_gimple_stmt (stderr, &ref, 0, 0);
157}
158
159DEBUG_FUNCTION void
160debug (gimple *ptr)
161{
162 if (ptr)
163 debug (*ptr);
164 else
165 fprintf (stderr, "<nil>\n");
166}
167
168
169/* Print GIMPLE statement G to FILE using SPC indentation spaces and
170 FLAGS as in pp_gimple_stmt_1. Print only the right-hand side
171 of the statement. */
172
173void
174print_gimple_expr (FILE *file, gimple *g, int spc, dump_flags_t flags)
175{
176 flags |= TDF_RHS_ONLY;
177 pretty_printer buffer;
178 pp_needs_newline (&buffer) = true;
179 buffer.buffer->stream = file;
180 pp_gimple_stmt_1 (&buffer, g, spc, flags);
181 pp_flush (&buffer);
182}
183
184
185/* Print the GIMPLE sequence SEQ on BUFFER using SPC indentation
186 spaces and FLAGS as in pp_gimple_stmt_1.
187 The caller is responsible for calling pp_flush on BUFFER to finalize
188 the pretty printer. */
189
190static void
191dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc,
192 dump_flags_t flags)
193{
194 gimple_stmt_iterator i;
195
196 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
197 {
198 gimple *gs = gsi_stmt (i);
199 INDENT (spc);
200 pp_gimple_stmt_1 (buffer, gs, spc, flags);
201 if (!gsi_one_before_end_p (i))
202 pp_newline (buffer);
203 }
204}
205
206
207/* Print GIMPLE sequence SEQ to FILE using SPC indentation spaces and
208 FLAGS as in pp_gimple_stmt_1. */
209
210void
211print_gimple_seq (FILE *file, gimple_seq seq, int spc, dump_flags_t flags)
212{
213 pretty_printer buffer;
214 pp_needs_newline (&buffer) = true;
215 buffer.buffer->stream = file;
216 dump_gimple_seq (&buffer, seq, spc, flags);
217 pp_newline_and_flush (&buffer);
218}
219
220
221/* Print the GIMPLE sequence SEQ on stderr. */
222
223DEBUG_FUNCTION void
224debug_gimple_seq (gimple_seq seq)
225{
226 print_gimple_seq (stderr, seq, 0, TDF_VOPS|TDF_MEMSYMS);
227}
228
229
230/* A simple helper to pretty-print some of the gimple tuples in the printf
231 style. The format modifiers are preceded by '%' and are:
232 'G' - outputs a string corresponding to the code of the given gimple,
233 'S' - outputs a gimple_seq with indent of spc + 2,
234 'T' - outputs the tree t,
235 'd' - outputs an int as a decimal,
236 's' - outputs a string,
237 'n' - outputs a newline,
238 'x' - outputs an int as hexadecimal,
239 '+' - increases indent by 2 then outputs a newline,
240 '-' - decreases indent by 2 then outputs a newline. */
241
242static void
243dump_gimple_fmt (pretty_printer *buffer, int spc, dump_flags_t flags,
244 const char *fmt, ...)
245{
246 va_list args;
247 const char *c;
248 const char *tmp;
249
250 va_start (args, fmt);
251 for (c = fmt; *c; c++)
252 {
253 if (*c == '%')
254 {
255 gimple_seq seq;
256 tree t;
257 gimple *g;
258 switch (*++c)
259 {
260 case 'G':
261 g = va_arg (args, gimple *);
262 tmp = gimple_code_name[gimple_code (g)];
263 pp_string (buffer, tmp);
264 break;
265
266 case 'S':
267 seq = va_arg (args, gimple_seq);
268 pp_newline (buffer);
269 dump_gimple_seq (buffer, seq, spc + 2, flags);
270 newline_and_indent (buffer, spc);
271 break;
272
273 case 'T':
274 t = va_arg (args, tree);
275 if (t == NULL_TREE)
276 pp_string (buffer, "NULL");
277 else
278 dump_generic_node (buffer, t, spc, flags, false);
279 break;
280
281 case 'd':
282 pp_decimal_int (buffer, va_arg (args, int));
283 break;
284
285 case 's':
286 pp_string (buffer, va_arg (args, char *));
287 break;
288
289 case 'n':
290 newline_and_indent (buffer, spc);
291 break;
292
293 case 'x':
294 pp_scalar (buffer, "%x", va_arg (args, int));
295 break;
296
297 case '+':
298 spc += 2;
299 newline_and_indent (buffer, spc);
300 break;
301
302 case '-':
303 spc -= 2;
304 newline_and_indent (buffer, spc);
305 break;
306
307 default:
308 gcc_unreachable ();
309 }
310 }
311 else
312 pp_character (buffer, *c);
313 }
314 va_end (args);
315}
316
317
318/* Helper for dump_gimple_assign. Print the unary RHS of the
319 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
320
321static void
322dump_unary_rhs (pretty_printer *buffer, gassign *gs, int spc,
323 dump_flags_t flags)
324{
325 enum tree_code rhs_code = gimple_assign_rhs_code (gs);
326 tree lhs = gimple_assign_lhs (gs);
327 tree rhs = gimple_assign_rhs1 (gs);
328
329 switch (rhs_code)
330 {
331 case VIEW_CONVERT_EXPR:
332 case ASSERT_EXPR:
333 dump_generic_node (buffer, rhs, spc, flags, false);
334 break;
335
336 case FIXED_CONVERT_EXPR:
337 case ADDR_SPACE_CONVERT_EXPR:
338 case FIX_TRUNC_EXPR:
339 case FLOAT_EXPR:
340 CASE_CONVERT:
341 pp_left_paren (buffer);
342 dump_generic_node (buffer, TREE_TYPE (lhs), spc, flags, false);
343 pp_string (buffer, ") ");
344 if (op_prio (rhs) < op_code_prio (rhs_code))
345 {
346 pp_left_paren (buffer);
347 dump_generic_node (buffer, rhs, spc, flags, false);
348 pp_right_paren (buffer);
349 }
350 else
351 dump_generic_node (buffer, rhs, spc, flags, false);
352 break;
353
354 case PAREN_EXPR:
355 pp_string (buffer, "((");
356 dump_generic_node (buffer, rhs, spc, flags, false);
357 pp_string (buffer, "))");
358 break;
359
360 case ABS_EXPR:
361 if (flags & TDF_GIMPLE)
362 {
363 pp_string (buffer, "__ABS ");
364 dump_generic_node (buffer, rhs, spc, flags, false);
365 }
366 else
367 {
368 pp_string (buffer, "ABS_EXPR <");
369 dump_generic_node (buffer, rhs, spc, flags, false);
370 pp_greater (buffer);
371 }
372 break;
373
374 default:
375 if (TREE_CODE_CLASS (rhs_code) == tcc_declaration
376 || TREE_CODE_CLASS (rhs_code) == tcc_constant
377 || TREE_CODE_CLASS (rhs_code) == tcc_reference
378 || rhs_code == SSA_NAME
379 || rhs_code == ADDR_EXPR
380 || rhs_code == CONSTRUCTOR)
381 {
382 dump_generic_node (buffer, rhs, spc, flags, false);
383 break;
384 }
385 else if (rhs_code == BIT_NOT_EXPR)
386 pp_complement (buffer);
387 else if (rhs_code == TRUTH_NOT_EXPR)
388 pp_exclamation (buffer);
389 else if (rhs_code == NEGATE_EXPR)
390 pp_minus (buffer);
391 else
392 {
393 pp_left_bracket (buffer);
394 pp_string (buffer, get_tree_code_name (rhs_code));
395 pp_string (buffer, "] ");
396 }
397
398 if (op_prio (rhs) < op_code_prio (rhs_code))
399 {
400 pp_left_paren (buffer);
401 dump_generic_node (buffer, rhs, spc, flags, false);
402 pp_right_paren (buffer);
403 }
404 else
405 dump_generic_node (buffer, rhs, spc, flags, false);
406 break;
407 }
408}
409
410
411/* Helper for dump_gimple_assign. Print the binary RHS of the
412 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
413
414static void
415dump_binary_rhs (pretty_printer *buffer, gassign *gs, int spc,
416 dump_flags_t flags)
417{
418 const char *p;
419 enum tree_code code = gimple_assign_rhs_code (gs);
420 switch (code)
421 {
422 case COMPLEX_EXPR:
423 case MIN_EXPR:
424 case MAX_EXPR:
425 case VEC_WIDEN_MULT_HI_EXPR:
426 case VEC_WIDEN_MULT_LO_EXPR:
427 case VEC_WIDEN_MULT_EVEN_EXPR:
428 case VEC_WIDEN_MULT_ODD_EXPR:
429 case VEC_PACK_TRUNC_EXPR:
430 case VEC_PACK_SAT_EXPR:
431 case VEC_PACK_FIX_TRUNC_EXPR:
432 case VEC_WIDEN_LSHIFT_HI_EXPR:
433 case VEC_WIDEN_LSHIFT_LO_EXPR:
434 for (p = get_tree_code_name (code); *p; p++)
435 pp_character (buffer, TOUPPER (*p));
436 pp_string (buffer, " <");
437 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
438 pp_string (buffer, ", ");
439 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
440 pp_greater (buffer);
441 break;
442
443 default:
444 if (op_prio (gimple_assign_rhs1 (gs)) <= op_code_prio (code))
445 {
446 pp_left_paren (buffer);
447 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags,
448 false);
449 pp_right_paren (buffer);
450 }
451 else
452 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
453 pp_space (buffer);
454 pp_string (buffer, op_symbol_code (gimple_assign_rhs_code (gs)));
455 pp_space (buffer);
456 if (op_prio (gimple_assign_rhs2 (gs)) <= op_code_prio (code))
457 {
458 pp_left_paren (buffer);
459 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags,
460 false);
461 pp_right_paren (buffer);
462 }
463 else
464 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
465 }
466}
467
468/* Helper for dump_gimple_assign. Print the ternary RHS of the
469 assignment GS. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1. */
470
471static void
472dump_ternary_rhs (pretty_printer *buffer, gassign *gs, int spc,
473 dump_flags_t flags)
474{
475 const char *p;
476 enum tree_code code = gimple_assign_rhs_code (gs);
477 switch (code)
478 {
479 case WIDEN_MULT_PLUS_EXPR:
480 case WIDEN_MULT_MINUS_EXPR:
481 for (p = get_tree_code_name (code); *p; p++)
482 pp_character (buffer, TOUPPER (*p));
483 pp_string (buffer, " <");
484 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
485 pp_string (buffer, ", ");
486 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
487 pp_string (buffer, ", ");
488 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
489 pp_greater (buffer);
490 break;
491
492 case FMA_EXPR:
493 if (flags & TDF_GIMPLE)
494 {
495 pp_string (buffer, "__FMA (");
496 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
497 pp_comma (buffer);
498 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
499 pp_comma (buffer);
500 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
501 pp_right_paren (buffer);
502 }
503 else
504 {
505 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
506 pp_string (buffer, " * ");
507 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
508 pp_string (buffer, " + ");
509 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
510 }
511 break;
512
513 case DOT_PROD_EXPR:
514 pp_string (buffer, "DOT_PROD_EXPR <");
515 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
516 pp_string (buffer, ", ");
517 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
518 pp_string (buffer, ", ");
519 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
520 pp_greater (buffer);
521 break;
522
523 case SAD_EXPR:
524 pp_string (buffer, "SAD_EXPR <");
525 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
526 pp_string (buffer, ", ");
527 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
528 pp_string (buffer, ", ");
529 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
530 pp_greater (buffer);
531 break;
532
533 case VEC_PERM_EXPR:
534 pp_string (buffer, "VEC_PERM_EXPR <");
535 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
536 pp_string (buffer, ", ");
537 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
538 pp_string (buffer, ", ");
539 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
540 pp_greater (buffer);
541 break;
542
543 case REALIGN_LOAD_EXPR:
544 pp_string (buffer, "REALIGN_LOAD <");
545 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
546 pp_string (buffer, ", ");
547 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
548 pp_string (buffer, ", ");
549 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
550 pp_greater (buffer);
551 break;
552
553 case COND_EXPR:
554 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
555 pp_string (buffer, " ? ");
556 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
557 pp_string (buffer, " : ");
558 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
559 break;
560
561 case VEC_COND_EXPR:
562 pp_string (buffer, "VEC_COND_EXPR <");
563 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
564 pp_string (buffer, ", ");
565 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
566 pp_string (buffer, ", ");
567 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
568 pp_greater (buffer);
569 break;
570
571 case BIT_INSERT_EXPR:
572 pp_string (buffer, "BIT_INSERT_EXPR <");
573 dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
574 pp_string (buffer, ", ");
575 dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
576 pp_string (buffer, ", ");
577 dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
578 pp_string (buffer, " (");
579 if (INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs2 (gs))))
580 pp_decimal_int (buffer,
581 TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs2 (gs))));
582 else
583 dump_generic_node (buffer,
584 TYPE_SIZE (TREE_TYPE (gimple_assign_rhs2 (gs))),
585 spc, flags, false);
586 pp_string (buffer, " bits)>");
587 break;
588
589 default:
590 gcc_unreachable ();
591 }
592}
593
594
595/* Dump the gimple assignment GS. BUFFER, SPC and FLAGS are as in
596 pp_gimple_stmt_1. */
597
598static void
599dump_gimple_assign (pretty_printer *buffer, gassign *gs, int spc,
600 dump_flags_t flags)
601{
602 if (flags & TDF_RAW)
603 {
604 tree arg1 = NULL;
605 tree arg2 = NULL;
606 tree arg3 = NULL;
607 switch (gimple_num_ops (gs))
608 {
609 case 4:
610 arg3 = gimple_assign_rhs3 (gs);
611 /* FALLTHRU */
612 case 3:
613 arg2 = gimple_assign_rhs2 (gs);
614 /* FALLTHRU */
615 case 2:
616 arg1 = gimple_assign_rhs1 (gs);
617 break;
618 default:
619 gcc_unreachable ();
620 }
621
622 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
623 get_tree_code_name (gimple_assign_rhs_code (gs)),
624 gimple_assign_lhs (gs), arg1, arg2, arg3);
625 }
626 else
627 {
628 if (!(flags & TDF_RHS_ONLY))
629 {
630 dump_generic_node (buffer, gimple_assign_lhs (gs), spc, flags, false);
631 pp_space (buffer);
632 pp_equal (buffer);
633
634 if (gimple_assign_nontemporal_move_p (gs))
635 pp_string (buffer, "{nt}");
636
637 if (gimple_has_volatile_ops (gs))
638 pp_string (buffer, "{v}");
639
640 pp_space (buffer);
641 }
642
643 if (gimple_num_ops (gs) == 2)
644 dump_unary_rhs (buffer, gs, spc, flags);
645 else if (gimple_num_ops (gs) == 3)
646 dump_binary_rhs (buffer, gs, spc, flags);
647 else if (gimple_num_ops (gs) == 4)
648 dump_ternary_rhs (buffer, gs, spc, flags);
649 else
650 gcc_unreachable ();
651 if (!(flags & TDF_RHS_ONLY))
652 pp_semicolon (buffer);
653 }
654}
655
656
657/* Dump the return statement GS. BUFFER, SPC and FLAGS are as in
658 pp_gimple_stmt_1. */
659
660static void
661dump_gimple_return (pretty_printer *buffer, greturn *gs, int spc,
662 dump_flags_t flags)
663{
664 tree t, t2;
665
666 t = gimple_return_retval (gs);
667 t2 = gimple_return_retbnd (gs);
668 if (flags & TDF_RAW)
669 dump_gimple_fmt (buffer, spc, flags, "%G <%T %T>", gs, t, t2);
670 else
671 {
672 pp_string (buffer, "return");
673 if (t)
674 {
675 pp_space (buffer);
676 dump_generic_node (buffer, t, spc, flags, false);
677 }
678 if (t2)
679 {
680 pp_string (buffer, ", ");
681 dump_generic_node (buffer, t2, spc, flags, false);
682 }
683 pp_semicolon (buffer);
684 }
685}
686
687
688/* Dump the call arguments for a gimple call. BUFFER, FLAGS are as in
689 dump_gimple_call. */
690
691static void
692dump_gimple_call_args (pretty_printer *buffer, gcall *gs, dump_flags_t flags)
693{
694 size_t i = 0;
695
696 /* Pretty print first arg to certain internal fns. */
697 if (gimple_call_internal_p (gs))
698 {
699 const char *const *enums = NULL;
700 unsigned limit = 0;
701
702 switch (gimple_call_internal_fn (gs))
703 {
704 case IFN_UNIQUE:
705#define DEF(X) #X
706 static const char *const unique_args[] = {IFN_UNIQUE_CODES};
707#undef DEF
708 enums = unique_args;
709
710 limit = ARRAY_SIZE (unique_args);
711 break;
712
713 case IFN_GOACC_LOOP:
714#define DEF(X) #X
715 static const char *const loop_args[] = {IFN_GOACC_LOOP_CODES};
716#undef DEF
717 enums = loop_args;
718 limit = ARRAY_SIZE (loop_args);
719 break;
720
721 case IFN_GOACC_REDUCTION:
722#define DEF(X) #X
723 static const char *const reduction_args[]
724 = {IFN_GOACC_REDUCTION_CODES};
725#undef DEF
726 enums = reduction_args;
727 limit = ARRAY_SIZE (reduction_args);
728 break;
729
730 case IFN_ASAN_MARK:
731#define DEF(X) #X
732 static const char *const asan_mark_args[] = {IFN_ASAN_MARK_FLAGS};
733#undef DEF
734 enums = asan_mark_args;
735 limit = ARRAY_SIZE (asan_mark_args);
736 break;
737
738 default:
739 break;
740 }
741 if (limit)
742 {
743 tree arg0 = gimple_call_arg (gs, 0);
744 HOST_WIDE_INT v;
745
746 if (TREE_CODE (arg0) == INTEGER_CST
747 && tree_fits_shwi_p (arg0)
748 && (v = tree_to_shwi (arg0)) >= 0 && v < limit)
749 {
750 i++;
751 pp_string (buffer, enums[v]);
752 }
753 }
754 }
755
756 for (; i < gimple_call_num_args (gs); i++)
757 {
758 if (i)
759 pp_string (buffer, ", ");
760 dump_generic_node (buffer, gimple_call_arg (gs, i), 0, flags, false);
761 }
762
763 if (gimple_call_va_arg_pack_p (gs))
764 {
765 if (i)
766 pp_string (buffer, ", ");
767
768 pp_string (buffer, "__builtin_va_arg_pack ()");
769 }
770}
771
772/* Dump the points-to solution *PT to BUFFER. */
773
774static void
775pp_points_to_solution (pretty_printer *buffer, struct pt_solution *pt)
776{
777 if (pt->anything)
778 {
779 pp_string (buffer, "anything ");
780 return;
781 }
782 if (pt->nonlocal)
783 pp_string (buffer, "nonlocal ");
784 if (pt->escaped)
785 pp_string (buffer, "escaped ");
786 if (pt->ipa_escaped)
787 pp_string (buffer, "unit-escaped ");
788 if (pt->null)
789 pp_string (buffer, "null ");
790 if (pt->vars
791 && !bitmap_empty_p (pt->vars))
792 {
793 bitmap_iterator bi;
794 unsigned i;
795 pp_string (buffer, "{ ");
796 EXECUTE_IF_SET_IN_BITMAP (pt->vars, 0, i, bi)
797 {
798 pp_string (buffer, "D.");
799 pp_decimal_int (buffer, i);
800 pp_space (buffer);
801 }
802 pp_right_brace (buffer);
803 if (pt->vars_contains_nonlocal
804 || pt->vars_contains_escaped
805 || pt->vars_contains_escaped_heap
806 || pt->vars_contains_restrict)
807 {
808 const char *comma = "";
809 pp_string (buffer, " (");
810 if (pt->vars_contains_nonlocal)
811 {
812 pp_string (buffer, "nonlocal");
813 comma = ", ";
814 }
815 if (pt->vars_contains_escaped)
816 {
817 pp_string (buffer, comma);
818 pp_string (buffer, "escaped");
819 comma = ", ";
820 }
821 if (pt->vars_contains_escaped_heap)
822 {
823 pp_string (buffer, comma);
824 pp_string (buffer, "escaped heap");
825 comma = ", ";
826 }
827 if (pt->vars_contains_restrict)
828 {
829 pp_string (buffer, comma);
830 pp_string (buffer, "restrict");
831 comma = ", ";
832 }
833 if (pt->vars_contains_interposable)
834 {
835 pp_string (buffer, comma);
836 pp_string (buffer, "interposable");
837 }
838 pp_string (buffer, ")");
839 }
840
841 }
842}
843
844/* Dump the call statement GS. BUFFER, SPC and FLAGS are as in
845 pp_gimple_stmt_1. */
846
847static void
848dump_gimple_call (pretty_printer *buffer, gcall *gs, int spc,
849 dump_flags_t flags)
850{
851 tree lhs = gimple_call_lhs (gs);
852 tree fn = gimple_call_fn (gs);
853
854 if (flags & TDF_ALIAS)
855 {
856 struct pt_solution *pt;
857 pt = gimple_call_use_set (gs);
858 if (!pt_solution_empty_p (pt))
859 {
860 pp_string (buffer, "# USE = ");
861 pp_points_to_solution (buffer, pt);
862 newline_and_indent (buffer, spc);
863 }
864 pt = gimple_call_clobber_set (gs);
865 if (!pt_solution_empty_p (pt))
866 {
867 pp_string (buffer, "# CLB = ");
868 pp_points_to_solution (buffer, pt);
869 newline_and_indent (buffer, spc);
870 }
871 }
872
873 if (flags & TDF_RAW)
874 {
875 if (gimple_call_internal_p (gs))
876 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T", gs,
877 internal_fn_name (gimple_call_internal_fn (gs)), lhs);
878 else
879 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T", gs, fn, lhs);
880 if (gimple_call_num_args (gs) > 0)
881 {
882 pp_string (buffer, ", ");
883 dump_gimple_call_args (buffer, gs, flags);
884 }
885 pp_greater (buffer);
886 }
887 else
888 {
889 if (lhs && !(flags & TDF_RHS_ONLY))
890 {
891 dump_generic_node (buffer, lhs, spc, flags, false);
892 pp_string (buffer, " =");
893
894 if (gimple_has_volatile_ops (gs))
895 pp_string (buffer, "{v}");
896
897 pp_space (buffer);
898 }
899 if (gimple_call_internal_p (gs))
900 pp_string (buffer, internal_fn_name (gimple_call_internal_fn (gs)));
901 else
902 print_call_name (buffer, fn, flags);
903 pp_string (buffer, " (");
904 dump_gimple_call_args (buffer, gs, flags);
905 pp_right_paren (buffer);
906 if (!(flags & TDF_RHS_ONLY))
907 pp_semicolon (buffer);
908 }
909
910 if (gimple_call_chain (gs))
911 {
912 pp_string (buffer, " [static-chain: ");
913 dump_generic_node (buffer, gimple_call_chain (gs), spc, flags, false);
914 pp_right_bracket (buffer);
915 }
916
917 if (gimple_call_return_slot_opt_p (gs))
918 pp_string (buffer, " [return slot optimization]");
919 if (gimple_call_tail_p (gs))
920 pp_string (buffer, " [tail call]");
921 if (gimple_call_must_tail_p (gs))
922 pp_string (buffer, " [must tail call]");
923
924 if (fn == NULL)
925 return;
926
927 /* Dump the arguments of _ITM_beginTransaction sanely. */
928 if (TREE_CODE (fn) == ADDR_EXPR)
929 fn = TREE_OPERAND (fn, 0);
930 if (TREE_CODE (fn) == FUNCTION_DECL && decl_is_tm_clone (fn))
931 pp_string (buffer, " [tm-clone]");
932 if (TREE_CODE (fn) == FUNCTION_DECL
933 && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
934 && DECL_FUNCTION_CODE (fn) == BUILT_IN_TM_START
935 && gimple_call_num_args (gs) > 0)
936 {
937 tree t = gimple_call_arg (gs, 0);
938 unsigned HOST_WIDE_INT props;
939 gcc_assert (TREE_CODE (t) == INTEGER_CST);
940
941 pp_string (buffer, " [ ");
942
943 /* Get the transaction code properties. */
944 props = TREE_INT_CST_LOW (t);
945
946 if (props & PR_INSTRUMENTEDCODE)
947 pp_string (buffer, "instrumentedCode ");
948 if (props & PR_UNINSTRUMENTEDCODE)
949 pp_string (buffer, "uninstrumentedCode ");
950 if (props & PR_HASNOXMMUPDATE)
951 pp_string (buffer, "hasNoXMMUpdate ");
952 if (props & PR_HASNOABORT)
953 pp_string (buffer, "hasNoAbort ");
954 if (props & PR_HASNOIRREVOCABLE)
955 pp_string (buffer, "hasNoIrrevocable ");
956 if (props & PR_DOESGOIRREVOCABLE)
957 pp_string (buffer, "doesGoIrrevocable ");
958 if (props & PR_HASNOSIMPLEREADS)
959 pp_string (buffer, "hasNoSimpleReads ");
960 if (props & PR_AWBARRIERSOMITTED)
961 pp_string (buffer, "awBarriersOmitted ");
962 if (props & PR_RARBARRIERSOMITTED)
963 pp_string (buffer, "RaRBarriersOmitted ");
964 if (props & PR_UNDOLOGCODE)
965 pp_string (buffer, "undoLogCode ");
966 if (props & PR_PREFERUNINSTRUMENTED)
967 pp_string (buffer, "preferUninstrumented ");
968 if (props & PR_EXCEPTIONBLOCK)
969 pp_string (buffer, "exceptionBlock ");
970 if (props & PR_HASELSE)
971 pp_string (buffer, "hasElse ");
972 if (props & PR_READONLY)
973 pp_string (buffer, "readOnly ");
974
975 pp_right_bracket (buffer);
976 }
977}
978
979
980/* Dump the switch statement GS. BUFFER, SPC and FLAGS are as in
981 pp_gimple_stmt_1. */
982
983static void
984dump_gimple_switch (pretty_printer *buffer, gswitch *gs, int spc,
985 dump_flags_t flags)
986{
987 unsigned int i;
988
989 GIMPLE_CHECK (gs, GIMPLE_SWITCH);
990 if (flags & TDF_RAW)
991 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", gs,
992 gimple_switch_index (gs));
993 else
994 {
995 pp_string (buffer, "switch (");
996 dump_generic_node (buffer, gimple_switch_index (gs), spc, flags, true);
997 if (flags & TDF_GIMPLE)
998 pp_string (buffer, ") {");
999 else
1000 pp_string (buffer, ") <");
1001 }
1002
1003 for (i = 0; i < gimple_switch_num_labels (gs); i++)
1004 {
1005 tree case_label = gimple_switch_label (gs, i);
1006 gcc_checking_assert (case_label != NULL_TREE);
1007 dump_generic_node (buffer, case_label, spc, flags, false);
1008 pp_space (buffer);
1009 tree label = CASE_LABEL (case_label);
1010 dump_generic_node (buffer, label, spc, flags, false);
1011
1012 if (cfun && cfun->cfg)
1013 {
1014 basic_block dest = label_to_block (label);
1015 if (dest)
1016 {
1017 edge label_edge = find_edge (gimple_bb (gs), dest);
1018 if (label_edge && !(flags & TDF_GIMPLE))
1019 dump_edge_probability (buffer, label_edge);
1020 }
1021 }
1022
1023 if (i < gimple_switch_num_labels (gs) - 1)
1024 {
1025 if (flags & TDF_GIMPLE)
1026 pp_string (buffer, "; ");
1027 else
1028 pp_string (buffer, ", ");
1029 }
1030 }
1031 if (flags & TDF_GIMPLE)
1032 pp_string (buffer, "; }");
1033 else
1034 pp_greater (buffer);
1035}
1036
1037
1038/* Dump the gimple conditional GS. BUFFER, SPC and FLAGS are as in
1039 pp_gimple_stmt_1. */
1040
1041static void
1042dump_gimple_cond (pretty_printer *buffer, gcond *gs, int spc,
1043 dump_flags_t flags)
1044{
1045 if (flags & TDF_RAW)
1046 dump_gimple_fmt (buffer, spc, flags, "%G <%s, %T, %T, %T, %T>", gs,
1047 get_tree_code_name (gimple_cond_code (gs)),
1048 gimple_cond_lhs (gs), gimple_cond_rhs (gs),
1049 gimple_cond_true_label (gs), gimple_cond_false_label (gs));
1050 else
1051 {
1052 if (!(flags & TDF_RHS_ONLY))
1053 pp_string (buffer, "if (");
1054 dump_generic_node (buffer, gimple_cond_lhs (gs), spc, flags, false);
1055 pp_space (buffer);
1056 pp_string (buffer, op_symbol_code (gimple_cond_code (gs)));
1057 pp_space (buffer);
1058 dump_generic_node (buffer, gimple_cond_rhs (gs), spc, flags, false);
1059 if (!(flags & TDF_RHS_ONLY))
1060 {
1061 edge_iterator ei;
1062 edge e, true_edge = NULL, false_edge = NULL;
1063 basic_block bb = gimple_bb (gs);
1064
1065 if (bb)
1066 {
1067 FOR_EACH_EDGE (e, ei, bb->succs)
1068 {
1069 if (e->flags & EDGE_TRUE_VALUE)
1070 true_edge = e;
1071 else if (e->flags & EDGE_FALSE_VALUE)
1072 false_edge = e;
1073 }
1074 }
1075
1076 bool has_edge_info = true_edge != NULL && false_edge != NULL;
1077
1078 pp_right_paren (buffer);
1079
1080 if (gimple_cond_true_label (gs))
1081 {
1082 pp_string (buffer, " goto ");
1083 dump_generic_node (buffer, gimple_cond_true_label (gs),
1084 spc, flags, false);
1085 if (has_edge_info && !(flags & TDF_GIMPLE))
1086 dump_edge_probability (buffer, true_edge);
1087 pp_semicolon (buffer);
1088 }
1089 if (gimple_cond_false_label (gs))
1090 {
1091 pp_string (buffer, " else goto ");
1092 dump_generic_node (buffer, gimple_cond_false_label (gs),
1093 spc, flags, false);
1094 if (has_edge_info && !(flags & TDF_GIMPLE))
1095 dump_edge_probability (buffer, false_edge);
1096
1097 pp_semicolon (buffer);
1098 }
1099 }
1100 }
1101}
1102
1103
1104/* Dump a GIMPLE_LABEL tuple on the pretty_printer BUFFER, SPC
1105 spaces of indent. FLAGS specifies details to show in the dump (see
1106 TDF_* in dumpfils.h). */
1107
1108static void
1109dump_gimple_label (pretty_printer *buffer, glabel *gs, int spc,
1110 dump_flags_t flags)
1111{
1112 tree label = gimple_label_label (gs);
1113 if (flags & TDF_RAW)
1114 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
1115 else
1116 {
1117 dump_generic_node (buffer, label, spc, flags, false);
1118 pp_colon (buffer);
1119 }
1120 if (flags & TDF_GIMPLE)
1121 return;
1122 if (DECL_NONLOCAL (label))
1123 pp_string (buffer, " [non-local]");
1124 if ((flags & TDF_EH) && EH_LANDING_PAD_NR (label))
1125 pp_printf (buffer, " [LP %d]", EH_LANDING_PAD_NR (label));
1126}
1127
1128/* Dump a GIMPLE_GOTO tuple on the pretty_printer BUFFER, SPC
1129 spaces of indent. FLAGS specifies details to show in the dump (see
1130 TDF_* in dumpfile.h). */
1131
1132static void
1133dump_gimple_goto (pretty_printer *buffer, ggoto *gs, int spc,
1134 dump_flags_t flags)
1135{
1136 tree label = gimple_goto_dest (gs);
1137 if (flags & TDF_RAW)
1138 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, label);
1139 else
1140 dump_gimple_fmt (buffer, spc, flags, "goto %T;", label);
1141}
1142
1143
1144/* Dump a GIMPLE_BIND tuple on the pretty_printer BUFFER, SPC
1145 spaces of indent. FLAGS specifies details to show in the dump (see
1146 TDF_* in dumpfile.h). */
1147
1148static void
1149dump_gimple_bind (pretty_printer *buffer, gbind *gs, int spc,
1150 dump_flags_t flags)
1151{
1152 if (flags & TDF_RAW)
1153 dump_gimple_fmt (buffer, spc, flags, "%G <", gs);
1154 else
1155 pp_left_brace (buffer);
1156 if (!(flags & TDF_SLIM))
1157 {
1158 tree var;
1159
1160 for (var = gimple_bind_vars (gs); var; var = DECL_CHAIN (var))
1161 {
1162 newline_and_indent (buffer, 2);
1163 print_declaration (buffer, var, spc, flags);
1164 }
1165 if (gimple_bind_vars (gs))
1166 pp_newline (buffer);
1167 }
1168 pp_newline (buffer);
1169 dump_gimple_seq (buffer, gimple_bind_body (gs), spc + 2, flags);
1170 newline_and_indent (buffer, spc);
1171 if (flags & TDF_RAW)
1172 pp_greater (buffer);
1173 else
1174 pp_right_brace (buffer);
1175}
1176
1177
1178/* Dump a GIMPLE_TRY tuple on the pretty_printer BUFFER, SPC spaces of
1179 indent. FLAGS specifies details to show in the dump (see TDF_* in
1180 dumpfile.h). */
1181
1182static void
1183dump_gimple_try (pretty_printer *buffer, gtry *gs, int spc,
1184 dump_flags_t flags)
1185{
1186 if (flags & TDF_RAW)
1187 {
1188 const char *type;
1189 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
1190 type = "GIMPLE_TRY_CATCH";
1191 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
1192 type = "GIMPLE_TRY_FINALLY";
1193 else
1194 type = "UNKNOWN GIMPLE_TRY";
1195 dump_gimple_fmt (buffer, spc, flags,
1196 "%G <%s,%+EVAL <%S>%nCLEANUP <%S>%->", gs, type,
1197 gimple_try_eval (gs), gimple_try_cleanup (gs));
1198 }
1199 else
1200 {
1201 pp_string (buffer, "try");
1202 newline_and_indent (buffer, spc + 2);
1203 pp_left_brace (buffer);
1204 pp_newline (buffer);
1205
1206 dump_gimple_seq (buffer, gimple_try_eval (gs), spc + 4, flags);
1207 newline_and_indent (buffer, spc + 2);
1208 pp_right_brace (buffer);
1209
1210 if (gimple_try_kind (gs) == GIMPLE_TRY_CATCH)
1211 {
1212 newline_and_indent (buffer, spc);
1213 pp_string (buffer, "catch");
1214 newline_and_indent (buffer, spc + 2);
1215 pp_left_brace (buffer);
1216 }
1217 else if (gimple_try_kind (gs) == GIMPLE_TRY_FINALLY)
1218 {
1219 newline_and_indent (buffer, spc);
1220 pp_string (buffer, "finally");
1221 newline_and_indent (buffer, spc + 2);
1222 pp_left_brace (buffer);
1223 }
1224 else
1225 pp_string (buffer, " <UNKNOWN GIMPLE_TRY> {");
1226
1227 pp_newline (buffer);
1228 dump_gimple_seq (buffer, gimple_try_cleanup (gs), spc + 4, flags);
1229 newline_and_indent (buffer, spc + 2);
1230 pp_right_brace (buffer);
1231 }
1232}
1233
1234
1235/* Dump a GIMPLE_CATCH tuple on the pretty_printer BUFFER, SPC spaces of
1236 indent. FLAGS specifies details to show in the dump (see TDF_* in
1237 dumpfile.h). */
1238
1239static void
1240dump_gimple_catch (pretty_printer *buffer, gcatch *gs, int spc,
1241 dump_flags_t flags)
1242{
1243 if (flags & TDF_RAW)
1244 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
1245 gimple_catch_types (gs), gimple_catch_handler (gs));
1246 else
1247 dump_gimple_fmt (buffer, spc, flags, "catch (%T)%+{%S}",
1248 gimple_catch_types (gs), gimple_catch_handler (gs));
1249}
1250
1251
1252/* Dump a GIMPLE_EH_FILTER tuple on the pretty_printer BUFFER, SPC spaces of
1253 indent. FLAGS specifies details to show in the dump (see TDF_* in
1254 dumpfile.h). */
1255
1256static void
1257dump_gimple_eh_filter (pretty_printer *buffer, geh_filter *gs, int spc,
1258 dump_flags_t flags)
1259{
1260 if (flags & TDF_RAW)
1261 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+FAILURE <%S>%->", gs,
1262 gimple_eh_filter_types (gs),
1263 gimple_eh_filter_failure (gs));
1264 else
1265 dump_gimple_fmt (buffer, spc, flags, "<<<eh_filter (%T)>>>%+{%+%S%-}",
1266 gimple_eh_filter_types (gs),
1267 gimple_eh_filter_failure (gs));
1268}
1269
1270
1271/* Dump a GIMPLE_EH_MUST_NOT_THROW tuple. */
1272
1273static void
1274dump_gimple_eh_must_not_throw (pretty_printer *buffer,
1275 geh_mnt *gs, int spc, dump_flags_t flags)
1276{
1277 if (flags & TDF_RAW)
1278 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
1279 gimple_eh_must_not_throw_fndecl (gs));
1280 else
1281 dump_gimple_fmt (buffer, spc, flags, "<<<eh_must_not_throw (%T)>>>",
1282 gimple_eh_must_not_throw_fndecl (gs));
1283}
1284
1285
1286/* Dump a GIMPLE_EH_ELSE tuple on the pretty_printer BUFFER, SPC spaces of
1287 indent. FLAGS specifies details to show in the dump (see TDF_* in
1288 dumpfile.h). */
1289
1290static void
1291dump_gimple_eh_else (pretty_printer *buffer, geh_else *gs, int spc,
1292 dump_flags_t flags)
1293{
1294 if (flags & TDF_RAW)
1295 dump_gimple_fmt (buffer, spc, flags,
1296 "%G <%+N_BODY <%S>%nE_BODY <%S>%->", gs,
1297 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1298 else
1299 dump_gimple_fmt (buffer, spc, flags,
1300 "<<<if_normal_exit>>>%+{%S}%-<<<else_eh_exit>>>%+{%S}",
1301 gimple_eh_else_n_body (gs), gimple_eh_else_e_body (gs));
1302}
1303
1304
1305/* Dump a GIMPLE_RESX tuple on the pretty_printer BUFFER, SPC spaces of
1306 indent. FLAGS specifies details to show in the dump (see TDF_* in
1307 dumpfile.h). */
1308
1309static void
1310dump_gimple_resx (pretty_printer *buffer, gresx *gs, int spc,
1311 dump_flags_t flags)
1312{
1313 if (flags & TDF_RAW)
1314 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1315 gimple_resx_region (gs));
1316 else
1317 dump_gimple_fmt (buffer, spc, flags, "resx %d", gimple_resx_region (gs));
1318}
1319
1320/* Dump a GIMPLE_EH_DISPATCH tuple on the pretty_printer BUFFER. */
1321
1322static void
1323dump_gimple_eh_dispatch (pretty_printer *buffer, geh_dispatch *gs, int spc,
1324 dump_flags_t flags)
1325{
1326 if (flags & TDF_RAW)
1327 dump_gimple_fmt (buffer, spc, flags, "%G <%d>", gs,
1328 gimple_eh_dispatch_region (gs));
1329 else
1330 dump_gimple_fmt (buffer, spc, flags, "eh_dispatch %d",
1331 gimple_eh_dispatch_region (gs));
1332}
1333
1334/* Dump a GIMPLE_DEBUG tuple on the pretty_printer BUFFER, SPC spaces
1335 of indent. FLAGS specifies details to show in the dump (see TDF_*
1336 in dumpfile.h). */
1337
1338static void
1339dump_gimple_debug (pretty_printer *buffer, gdebug *gs, int spc,
1340 dump_flags_t flags)
1341{
1342 switch (gs->subcode)
1343 {
1344 case GIMPLE_DEBUG_BIND:
1345 if (flags & TDF_RAW)
1346 dump_gimple_fmt (buffer, spc, flags, "%G BIND <%T, %T>", gs,
1347 gimple_debug_bind_get_var (gs),
1348 gimple_debug_bind_get_value (gs));
1349 else
1350 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T => %T",
1351 gimple_debug_bind_get_var (gs),
1352 gimple_debug_bind_get_value (gs));
1353 break;
1354
1355 case GIMPLE_DEBUG_SOURCE_BIND:
1356 if (flags & TDF_RAW)
1357 dump_gimple_fmt (buffer, spc, flags, "%G SRCBIND <%T, %T>", gs,
1358 gimple_debug_source_bind_get_var (gs),
1359 gimple_debug_source_bind_get_value (gs));
1360 else
1361 dump_gimple_fmt (buffer, spc, flags, "# DEBUG %T s=> %T",
1362 gimple_debug_source_bind_get_var (gs),
1363 gimple_debug_source_bind_get_value (gs));
1364 break;
1365
1366 case GIMPLE_DEBUG_BEGIN_STMT:
1367 if (flags & TDF_RAW)
1368 dump_gimple_fmt (buffer, spc, flags, "%G BEGIN_STMT", gs);
1369 else
1370 dump_gimple_fmt (buffer, spc, flags, "# DEBUG BEGIN_STMT");
1371 break;
1372
1373 default:
1374 gcc_unreachable ();
1375 }
1376}
1377
1378/* Dump a GIMPLE_OMP_FOR tuple on the pretty_printer BUFFER. */
1379static void
1380dump_gimple_omp_for (pretty_printer *buffer, gomp_for *gs, int spc,
1381 dump_flags_t flags)
1382{
1383 size_t i;
1384
1385 if (flags & TDF_RAW)
1386 {
1387 const char *kind;
1388 switch (gimple_omp_for_kind (gs))
1389 {
1390 case GF_OMP_FOR_KIND_FOR:
1391 kind = "";
1392 break;
1393 case GF_OMP_FOR_KIND_DISTRIBUTE:
1394 kind = " distribute";
1395 break;
1396 case GF_OMP_FOR_KIND_TASKLOOP:
1397 kind = " taskloop";
1398 break;
1399 case GF_OMP_FOR_KIND_OACC_LOOP:
1400 kind = " oacc_loop";
1401 break;
1402 case GF_OMP_FOR_KIND_SIMD:
1403 kind = " simd";
1404 break;
1405 default:
1406 gcc_unreachable ();
1407 }
1408 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1409 kind, gimple_omp_body (gs));
1410 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1411 dump_gimple_fmt (buffer, spc, flags, " >,");
1412 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1413 dump_gimple_fmt (buffer, spc, flags,
1414 "%+%T, %T, %T, %s, %T,%n",
1415 gimple_omp_for_index (gs, i),
1416 gimple_omp_for_initial (gs, i),
1417 gimple_omp_for_final (gs, i),
1418 get_tree_code_name (gimple_omp_for_cond (gs, i)),
1419 gimple_omp_for_incr (gs, i));
1420 dump_gimple_fmt (buffer, spc, flags, "PRE_BODY <%S>%->",
1421 gimple_omp_for_pre_body (gs));
1422 }
1423 else
1424 {
1425 switch (gimple_omp_for_kind (gs))
1426 {
1427 case GF_OMP_FOR_KIND_FOR:
1428 pp_string (buffer, "#pragma omp for");
1429 break;
1430 case GF_OMP_FOR_KIND_DISTRIBUTE:
1431 pp_string (buffer, "#pragma omp distribute");
1432 break;
1433 case GF_OMP_FOR_KIND_TASKLOOP:
1434 pp_string (buffer, "#pragma omp taskloop");
1435 break;
1436 case GF_OMP_FOR_KIND_OACC_LOOP:
1437 pp_string (buffer, "#pragma acc loop");
1438 break;
1439 case GF_OMP_FOR_KIND_SIMD:
1440 pp_string (buffer, "#pragma omp simd");
1441 break;
1442 case GF_OMP_FOR_KIND_GRID_LOOP:
1443 pp_string (buffer, "#pragma omp for grid_loop");
1444 break;
1445 default:
1446 gcc_unreachable ();
1447 }
1448 dump_omp_clauses (buffer, gimple_omp_for_clauses (gs), spc, flags);
1449 for (i = 0; i < gimple_omp_for_collapse (gs); i++)
1450 {
1451 if (i)
1452 spc += 2;
1453 newline_and_indent (buffer, spc);
1454 pp_string (buffer, "for (");
1455 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1456 flags, false);
1457 pp_string (buffer, " = ");
1458 dump_generic_node (buffer, gimple_omp_for_initial (gs, i), spc,
1459 flags, false);
1460 pp_string (buffer, "; ");
1461
1462 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1463 flags, false);
1464 pp_space (buffer);
1465 switch (gimple_omp_for_cond (gs, i))
1466 {
1467 case LT_EXPR:
1468 pp_less (buffer);
1469 break;
1470 case GT_EXPR:
1471 pp_greater (buffer);
1472 break;
1473 case LE_EXPR:
1474 pp_less_equal (buffer);
1475 break;
1476 case GE_EXPR:
1477 pp_greater_equal (buffer);
1478 break;
1479 case NE_EXPR:
1480 pp_string (buffer, "!=");
1481 break;
1482 default:
1483 gcc_unreachable ();
1484 }
1485 pp_space (buffer);
1486 dump_generic_node (buffer, gimple_omp_for_final (gs, i), spc,
1487 flags, false);
1488 pp_string (buffer, "; ");
1489
1490 dump_generic_node (buffer, gimple_omp_for_index (gs, i), spc,
1491 flags, false);
1492 pp_string (buffer, " = ");
1493 dump_generic_node (buffer, gimple_omp_for_incr (gs, i), spc,
1494 flags, false);
1495 pp_right_paren (buffer);
1496 }
1497
1498 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1499 {
1500 newline_and_indent (buffer, spc + 2);
1501 pp_left_brace (buffer);
1502 pp_newline (buffer);
1503 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1504 newline_and_indent (buffer, spc + 2);
1505 pp_right_brace (buffer);
1506 }
1507 }
1508}
1509
1510/* Dump a GIMPLE_OMP_CONTINUE tuple on the pretty_printer BUFFER. */
1511
1512static void
1513dump_gimple_omp_continue (pretty_printer *buffer, gomp_continue *gs,
1514 int spc, dump_flags_t flags)
1515{
1516 if (flags & TDF_RAW)
1517 {
1518 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
1519 gimple_omp_continue_control_def (gs),
1520 gimple_omp_continue_control_use (gs));
1521 }
1522 else
1523 {
1524 pp_string (buffer, "#pragma omp continue (");
1525 dump_generic_node (buffer, gimple_omp_continue_control_def (gs),
1526 spc, flags, false);
1527 pp_comma (buffer);
1528 pp_space (buffer);
1529 dump_generic_node (buffer, gimple_omp_continue_control_use (gs),
1530 spc, flags, false);
1531 pp_right_paren (buffer);
1532 }
1533}
1534
1535/* Dump a GIMPLE_OMP_SINGLE tuple on the pretty_printer BUFFER. */
1536
1537static void
1538dump_gimple_omp_single (pretty_printer *buffer, gomp_single *gs,
1539 int spc, dump_flags_t flags)
1540{
1541 if (flags & TDF_RAW)
1542 {
1543 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1544 gimple_omp_body (gs));
1545 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1546 dump_gimple_fmt (buffer, spc, flags, " >");
1547 }
1548 else
1549 {
1550 pp_string (buffer, "#pragma omp single");
1551 dump_omp_clauses (buffer, gimple_omp_single_clauses (gs), spc, flags);
1552 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1553 {
1554 newline_and_indent (buffer, spc + 2);
1555 pp_left_brace (buffer);
1556 pp_newline (buffer);
1557 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1558 newline_and_indent (buffer, spc + 2);
1559 pp_right_brace (buffer);
1560 }
1561 }
1562}
1563
1564/* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer BUFFER. */
1565
1566static void
1567dump_gimple_omp_target (pretty_printer *buffer, gomp_target *gs,
1568 int spc, dump_flags_t flags)
1569{
1570 const char *kind;
1571 switch (gimple_omp_target_kind (gs))
1572 {
1573 case GF_OMP_TARGET_KIND_REGION:
1574 kind = "";
1575 break;
1576 case GF_OMP_TARGET_KIND_DATA:
1577 kind = " data";
1578 break;
1579 case GF_OMP_TARGET_KIND_UPDATE:
1580 kind = " update";
1581 break;
1582 case GF_OMP_TARGET_KIND_ENTER_DATA:
1583 kind = " enter data";
1584 break;
1585 case GF_OMP_TARGET_KIND_EXIT_DATA:
1586 kind = " exit data";
1587 break;
1588 case GF_OMP_TARGET_KIND_OACC_KERNELS:
1589 kind = " oacc_kernels";
1590 break;
1591 case GF_OMP_TARGET_KIND_OACC_PARALLEL:
1592 kind = " oacc_parallel";
1593 break;
1594 case GF_OMP_TARGET_KIND_OACC_DATA:
1595 kind = " oacc_data";
1596 break;
1597 case GF_OMP_TARGET_KIND_OACC_UPDATE:
1598 kind = " oacc_update";
1599 break;
1600 case GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA:
1601 kind = " oacc_enter_exit_data";
1602 break;
1603 case GF_OMP_TARGET_KIND_OACC_DECLARE:
1604 kind = " oacc_declare";
1605 break;
1606 case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
1607 kind = " oacc_host_data";
1608 break;
1609 default:
1610 gcc_unreachable ();
1611 }
1612 if (flags & TDF_RAW)
1613 {
1614 dump_gimple_fmt (buffer, spc, flags, "%G%s <%+BODY <%S>%nCLAUSES <", gs,
1615 kind, gimple_omp_body (gs));
1616 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1617 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
1618 gimple_omp_target_child_fn (gs),
1619 gimple_omp_target_data_arg (gs));
1620 }
1621 else
1622 {
1623 pp_string (buffer, "#pragma omp target");
1624 pp_string (buffer, kind);
1625 dump_omp_clauses (buffer, gimple_omp_target_clauses (gs), spc, flags);
1626 if (gimple_omp_target_child_fn (gs))
1627 {
1628 pp_string (buffer, " [child fn: ");
1629 dump_generic_node (buffer, gimple_omp_target_child_fn (gs),
1630 spc, flags, false);
1631 pp_string (buffer, " (");
1632 if (gimple_omp_target_data_arg (gs))
1633 dump_generic_node (buffer, gimple_omp_target_data_arg (gs),
1634 spc, flags, false);
1635 else
1636 pp_string (buffer, "???");
1637 pp_string (buffer, ")]");
1638 }
1639 gimple_seq body = gimple_omp_body (gs);
1640 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
1641 {
1642 newline_and_indent (buffer, spc + 2);
1643 pp_left_brace (buffer);
1644 pp_newline (buffer);
1645 dump_gimple_seq (buffer, body, spc + 4, flags);
1646 newline_and_indent (buffer, spc + 2);
1647 pp_right_brace (buffer);
1648 }
1649 else if (body)
1650 {
1651 pp_newline (buffer);
1652 dump_gimple_seq (buffer, body, spc + 2, flags);
1653 }
1654 }
1655}
1656
1657/* Dump a GIMPLE_OMP_TEAMS tuple on the pretty_printer BUFFER. */
1658
1659static void
1660dump_gimple_omp_teams (pretty_printer *buffer, gomp_teams *gs, int spc,
1661 dump_flags_t flags)
1662{
1663 if (flags & TDF_RAW)
1664 {
1665 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1666 gimple_omp_body (gs));
1667 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1668 dump_gimple_fmt (buffer, spc, flags, " >");
1669 }
1670 else
1671 {
1672 pp_string (buffer, "#pragma omp teams");
1673 dump_omp_clauses (buffer, gimple_omp_teams_clauses (gs), spc, flags);
1674 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1675 {
1676 newline_and_indent (buffer, spc + 2);
1677 pp_character (buffer, '{');
1678 pp_newline (buffer);
1679 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1680 newline_and_indent (buffer, spc + 2);
1681 pp_character (buffer, '}');
1682 }
1683 }
1684}
1685
1686/* Dump a GIMPLE_OMP_SECTIONS tuple on the pretty_printer BUFFER. */
1687
1688static void
1689dump_gimple_omp_sections (pretty_printer *buffer, gomp_sections *gs,
1690 int spc, dump_flags_t flags)
1691{
1692 if (flags & TDF_RAW)
1693 {
1694 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1695 gimple_omp_body (gs));
1696 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1697 dump_gimple_fmt (buffer, spc, flags, " >");
1698 }
1699 else
1700 {
1701 pp_string (buffer, "#pragma omp sections");
1702 if (gimple_omp_sections_control (gs))
1703 {
1704 pp_string (buffer, " <");
1705 dump_generic_node (buffer, gimple_omp_sections_control (gs), spc,
1706 flags, false);
1707 pp_greater (buffer);
1708 }
1709 dump_omp_clauses (buffer, gimple_omp_sections_clauses (gs), spc, flags);
1710 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1711 {
1712 newline_and_indent (buffer, spc + 2);
1713 pp_left_brace (buffer);
1714 pp_newline (buffer);
1715 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1716 newline_and_indent (buffer, spc + 2);
1717 pp_right_brace (buffer);
1718 }
1719 }
1720}
1721
1722/* Dump a GIMPLE_OMP_{MASTER,TASKGROUP,ORDERED,SECTION} tuple on the
1723 pretty_printer BUFFER. */
1724
1725static void
1726dump_gimple_omp_block (pretty_printer *buffer, gimple *gs, int spc,
1727 dump_flags_t flags)
1728{
1729 if (flags & TDF_RAW)
1730 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1731 gimple_omp_body (gs));
1732 else
1733 {
1734 switch (gimple_code (gs))
1735 {
1736 case GIMPLE_OMP_MASTER:
1737 pp_string (buffer, "#pragma omp master");
1738 break;
1739 case GIMPLE_OMP_TASKGROUP:
1740 pp_string (buffer, "#pragma omp taskgroup");
1741 break;
1742 case GIMPLE_OMP_SECTION:
1743 pp_string (buffer, "#pragma omp section");
1744 break;
1745 case GIMPLE_OMP_GRID_BODY:
1746 pp_string (buffer, "#pragma omp gridified body");
1747 break;
1748 default:
1749 gcc_unreachable ();
1750 }
1751 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1752 {
1753 newline_and_indent (buffer, spc + 2);
1754 pp_left_brace (buffer);
1755 pp_newline (buffer);
1756 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1757 newline_and_indent (buffer, spc + 2);
1758 pp_right_brace (buffer);
1759 }
1760 }
1761}
1762
1763/* Dump a GIMPLE_OMP_CRITICAL tuple on the pretty_printer BUFFER. */
1764
1765static void
1766dump_gimple_omp_critical (pretty_printer *buffer, gomp_critical *gs,
1767 int spc, dump_flags_t flags)
1768{
1769 if (flags & TDF_RAW)
1770 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1771 gimple_omp_body (gs));
1772 else
1773 {
1774 pp_string (buffer, "#pragma omp critical");
1775 if (gimple_omp_critical_name (gs))
1776 {
1777 pp_string (buffer, " (");
1778 dump_generic_node (buffer, gimple_omp_critical_name (gs), spc,
1779 flags, false);
1780 pp_right_paren (buffer);
1781 }
1782 dump_omp_clauses (buffer, gimple_omp_critical_clauses (gs), spc, flags);
1783 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1784 {
1785 newline_and_indent (buffer, spc + 2);
1786 pp_left_brace (buffer);
1787 pp_newline (buffer);
1788 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1789 newline_and_indent (buffer, spc + 2);
1790 pp_right_brace (buffer);
1791 }
1792 }
1793}
1794
1795/* Dump a GIMPLE_OMP_ORDERED tuple on the pretty_printer BUFFER. */
1796
1797static void
1798dump_gimple_omp_ordered (pretty_printer *buffer, gomp_ordered *gs,
1799 int spc, dump_flags_t flags)
1800{
1801 if (flags & TDF_RAW)
1802 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S> >", gs,
1803 gimple_omp_body (gs));
1804 else
1805 {
1806 pp_string (buffer, "#pragma omp ordered");
1807 dump_omp_clauses (buffer, gimple_omp_ordered_clauses (gs), spc, flags);
1808 if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1809 {
1810 newline_and_indent (buffer, spc + 2);
1811 pp_left_brace (buffer);
1812 pp_newline (buffer);
1813 dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1814 newline_and_indent (buffer, spc + 2);
1815 pp_right_brace (buffer);
1816 }
1817 }
1818}
1819
1820/* Dump a GIMPLE_OMP_RETURN tuple on the pretty_printer BUFFER. */
1821
1822static void
1823dump_gimple_omp_return (pretty_printer *buffer, gimple *gs, int spc,
1824 dump_flags_t flags)
1825{
1826 if (flags & TDF_RAW)
1827 {
1828 dump_gimple_fmt (buffer, spc, flags, "%G <nowait=%d", gs,
1829 (int) gimple_omp_return_nowait_p (gs));
1830 if (gimple_omp_return_lhs (gs))
1831 dump_gimple_fmt (buffer, spc, flags, ", lhs=%T>",
1832 gimple_omp_return_lhs (gs));
1833 else
1834 dump_gimple_fmt (buffer, spc, flags, ">");
1835 }
1836 else
1837 {
1838 pp_string (buffer, "#pragma omp return");
1839 if (gimple_omp_return_nowait_p (gs))
1840 pp_string (buffer, "(nowait)");
1841 if (gimple_omp_return_lhs (gs))
1842 {
1843 pp_string (buffer, " (set ");
1844 dump_generic_node (buffer, gimple_omp_return_lhs (gs),
1845 spc, flags, false);
1846 pp_character (buffer, ')');
1847 }
1848 }
1849}
1850
1851/* Dump a GIMPLE_TRANSACTION tuple on the pretty_printer BUFFER. */
1852
1853static void
1854dump_gimple_transaction (pretty_printer *buffer, gtransaction *gs,
1855 int spc, dump_flags_t flags)
1856{
1857 unsigned subcode = gimple_transaction_subcode (gs);
1858
1859 if (flags & TDF_RAW)
1860 {
1861 dump_gimple_fmt (buffer, spc, flags,
1862 "%G [SUBCODE=%x,NORM=%T,UNINST=%T,OVER=%T] "
1863 "<%+BODY <%S> >",
1864 gs, subcode, gimple_transaction_label_norm (gs),
1865 gimple_transaction_label_uninst (gs),
1866 gimple_transaction_label_over (gs),
1867 gimple_transaction_body (gs));
1868 }
1869 else
1870 {
1871 if (subcode & GTMA_IS_OUTER)
1872 pp_string (buffer, "__transaction_atomic [[outer]]");
1873 else if (subcode & GTMA_IS_RELAXED)
1874 pp_string (buffer, "__transaction_relaxed");
1875 else
1876 pp_string (buffer, "__transaction_atomic");
1877 subcode &= ~GTMA_DECLARATION_MASK;
1878
1879 if (gimple_transaction_body (gs))
1880 {
1881 newline_and_indent (buffer, spc + 2);
1882 pp_left_brace (buffer);
1883 pp_newline (buffer);
1884 dump_gimple_seq (buffer, gimple_transaction_body (gs),
1885 spc + 4, flags);
1886 newline_and_indent (buffer, spc + 2);
1887 pp_right_brace (buffer);
1888 }
1889 else
1890 {
1891 pp_string (buffer, " //");
1892 if (gimple_transaction_label_norm (gs))
1893 {
1894 pp_string (buffer, " NORM=");
1895 dump_generic_node (buffer, gimple_transaction_label_norm (gs),
1896 spc, flags, false);
1897 }
1898 if (gimple_transaction_label_uninst (gs))
1899 {
1900 pp_string (buffer, " UNINST=");
1901 dump_generic_node (buffer, gimple_transaction_label_uninst (gs),
1902 spc, flags, false);
1903 }
1904 if (gimple_transaction_label_over (gs))
1905 {
1906 pp_string (buffer, " OVER=");
1907 dump_generic_node (buffer, gimple_transaction_label_over (gs),
1908 spc, flags, false);
1909 }
1910 if (subcode)
1911 {
1912 pp_string (buffer, " SUBCODE=[ ");
1913 if (subcode & GTMA_HAVE_ABORT)
1914 {
1915 pp_string (buffer, "GTMA_HAVE_ABORT ");
1916 subcode &= ~GTMA_HAVE_ABORT;
1917 }
1918 if (subcode & GTMA_HAVE_LOAD)
1919 {
1920 pp_string (buffer, "GTMA_HAVE_LOAD ");
1921 subcode &= ~GTMA_HAVE_LOAD;
1922 }
1923 if (subcode & GTMA_HAVE_STORE)
1924 {
1925 pp_string (buffer, "GTMA_HAVE_STORE ");
1926 subcode &= ~GTMA_HAVE_STORE;
1927 }
1928 if (subcode & GTMA_MAY_ENTER_IRREVOCABLE)
1929 {
1930 pp_string (buffer, "GTMA_MAY_ENTER_IRREVOCABLE ");
1931 subcode &= ~GTMA_MAY_ENTER_IRREVOCABLE;
1932 }
1933 if (subcode & GTMA_DOES_GO_IRREVOCABLE)
1934 {
1935 pp_string (buffer, "GTMA_DOES_GO_IRREVOCABLE ");
1936 subcode &= ~GTMA_DOES_GO_IRREVOCABLE;
1937 }
1938 if (subcode & GTMA_HAS_NO_INSTRUMENTATION)
1939 {
1940 pp_string (buffer, "GTMA_HAS_NO_INSTRUMENTATION ");
1941 subcode &= ~GTMA_HAS_NO_INSTRUMENTATION;
1942 }
1943 if (subcode)
1944 pp_printf (buffer, "0x%x ", subcode);
1945 pp_right_bracket (buffer);
1946 }
1947 }
1948 }
1949}
1950
1951/* Dump a GIMPLE_ASM tuple on the pretty_printer BUFFER, SPC spaces of
1952 indent. FLAGS specifies details to show in the dump (see TDF_* in
1953 dumpfile.h). */
1954
1955static void
1956dump_gimple_asm (pretty_printer *buffer, gasm *gs, int spc, dump_flags_t flags)
1957{
1958 unsigned int i, n, f, fields;
1959
1960 if (flags & TDF_RAW)
1961 {
1962 dump_gimple_fmt (buffer, spc, flags, "%G <%+STRING <%n%s%n>", gs,
1963 gimple_asm_string (gs));
1964
1965 n = gimple_asm_noutputs (gs);
1966 if (n)
1967 {
1968 newline_and_indent (buffer, spc + 2);
1969 pp_string (buffer, "OUTPUT: ");
1970 for (i = 0; i < n; i++)
1971 {
1972 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
1973 spc, flags, false);
1974 if (i < n - 1)
1975 pp_string (buffer, ", ");
1976 }
1977 }
1978
1979 n = gimple_asm_ninputs (gs);
1980 if (n)
1981 {
1982 newline_and_indent (buffer, spc + 2);
1983 pp_string (buffer, "INPUT: ");
1984 for (i = 0; i < n; i++)
1985 {
1986 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
1987 spc, flags, false);
1988 if (i < n - 1)
1989 pp_string (buffer, ", ");
1990 }
1991 }
1992
1993 n = gimple_asm_nclobbers (gs);
1994 if (n)
1995 {
1996 newline_and_indent (buffer, spc + 2);
1997 pp_string (buffer, "CLOBBER: ");
1998 for (i = 0; i < n; i++)
1999 {
2000 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
2001 spc, flags, false);
2002 if (i < n - 1)
2003 pp_string (buffer, ", ");
2004 }
2005 }
2006
2007 n = gimple_asm_nlabels (gs);
2008 if (n)
2009 {
2010 newline_and_indent (buffer, spc + 2);
2011 pp_string (buffer, "LABEL: ");
2012 for (i = 0; i < n; i++)
2013 {
2014 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
2015 spc, flags, false);
2016 if (i < n - 1)
2017 pp_string (buffer, ", ");
2018 }
2019 }
2020
2021 newline_and_indent (buffer, spc);
2022 pp_greater (buffer);
2023 }
2024 else
2025 {
2026 pp_string (buffer, "__asm__");
2027 if (gimple_asm_volatile_p (gs))
2028 pp_string (buffer, " __volatile__");
2029 if (gimple_asm_nlabels (gs))
2030 pp_string (buffer, " goto");
2031 pp_string (buffer, "(\"");
2032 pp_string (buffer, gimple_asm_string (gs));
2033 pp_string (buffer, "\"");
2034
2035 if (gimple_asm_nlabels (gs))
2036 fields = 4;
2037 else if (gimple_asm_nclobbers (gs))
2038 fields = 3;
2039 else if (gimple_asm_ninputs (gs))
2040 fields = 2;
2041 else if (gimple_asm_noutputs (gs))
2042 fields = 1;
2043 else
2044 fields = 0;
2045
2046 for (f = 0; f < fields; ++f)
2047 {
2048 pp_string (buffer, " : ");
2049
2050 switch (f)
2051 {
2052 case 0:
2053 n = gimple_asm_noutputs (gs);
2054 for (i = 0; i < n; i++)
2055 {
2056 dump_generic_node (buffer, gimple_asm_output_op (gs, i),
2057 spc, flags, false);
2058 if (i < n - 1)
2059 pp_string (buffer, ", ");
2060 }
2061 break;
2062
2063 case 1:
2064 n = gimple_asm_ninputs (gs);
2065 for (i = 0; i < n; i++)
2066 {
2067 dump_generic_node (buffer, gimple_asm_input_op (gs, i),
2068 spc, flags, false);
2069 if (i < n - 1)
2070 pp_string (buffer, ", ");
2071 }
2072 break;
2073
2074 case 2:
2075 n = gimple_asm_nclobbers (gs);
2076 for (i = 0; i < n; i++)
2077 {
2078 dump_generic_node (buffer, gimple_asm_clobber_op (gs, i),
2079 spc, flags, false);
2080 if (i < n - 1)
2081 pp_string (buffer, ", ");
2082 }
2083 break;
2084
2085 case 3:
2086 n = gimple_asm_nlabels (gs);
2087 for (i = 0; i < n; i++)
2088 {
2089 dump_generic_node (buffer, gimple_asm_label_op (gs, i),
2090 spc, flags, false);
2091 if (i < n - 1)
2092 pp_string (buffer, ", ");
2093 }
2094 break;
2095
2096 default:
2097 gcc_unreachable ();
2098 }
2099 }
2100
2101 pp_string (buffer, ");");
2102 }
2103}
2104
2105/* Dump ptr_info and range_info for NODE on pretty_printer BUFFER with
2106 SPC spaces of indent. */
2107
2108static void
2109dump_ssaname_info (pretty_printer *buffer, tree node, int spc)
2110{
2111 if (TREE_CODE (node) != SSA_NAME)
2112 return;
2113
2114 if (POINTER_TYPE_P (TREE_TYPE (node))
2115 && SSA_NAME_PTR_INFO (node))
2116 {
2117 unsigned int align, misalign;
2118 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (node);
2119 pp_string (buffer, "# PT = ");
2120 pp_points_to_solution (buffer, &pi->pt);
2121 newline_and_indent (buffer, spc);
2122 if (get_ptr_info_alignment (pi, &align, &misalign))
2123 {
2124 pp_printf (buffer, "# ALIGN = %u, MISALIGN = %u", align, misalign);
2125 newline_and_indent (buffer, spc);
2126 }
2127 }
2128
2129 if (!POINTER_TYPE_P (TREE_TYPE (node))
2130 && SSA_NAME_RANGE_INFO (node))
2131 {
2132 wide_int min, max, nonzero_bits;
2133 value_range_type range_type = get_range_info (node, &min, &max);
2134
2135 if (range_type == VR_VARYING)
2136 pp_printf (buffer, "# RANGE VR_VARYING");
2137 else if (range_type == VR_RANGE || range_type == VR_ANTI_RANGE)
2138 {
2139 pp_printf (buffer, "# RANGE ");
2140 pp_printf (buffer, "%s[", range_type == VR_RANGE ? "" : "~");
2141 pp_wide_int (buffer, min, TYPE_SIGN (TREE_TYPE (node)));
2142 pp_printf (buffer, ", ");
2143 pp_wide_int (buffer, max, TYPE_SIGN (TREE_TYPE (node)));
2144 pp_printf (buffer, "]");
2145 }
2146 nonzero_bits = get_nonzero_bits (node);
2147 if (nonzero_bits != -1)
2148 {
2149 pp_string (buffer, " NONZERO ");
2150 pp_wide_int (buffer, nonzero_bits, UNSIGNED);
2151 }
2152 newline_and_indent (buffer, spc);
2153 }
2154}
2155
2156/* As dump_ssaname_info, but dump to FILE. */
2157
2158void
2159dump_ssaname_info_to_file (FILE *file, tree node, int spc)
2160{
2161 pretty_printer buffer;
2162 pp_needs_newline (&buffer) = true;
2163 buffer.buffer->stream = file;
2164 dump_ssaname_info (&buffer, node, spc);
2165 pp_flush (&buffer);
2166}
2167
2168/* Dump a PHI node PHI. BUFFER, SPC and FLAGS are as in pp_gimple_stmt_1.
2169 The caller is responsible for calling pp_flush on BUFFER to finalize
2170 pretty printer. If COMMENT is true, print this after #. */
2171
2172static void
2173dump_gimple_phi (pretty_printer *buffer, gphi *phi, int spc, bool comment,
2174 dump_flags_t flags)
2175{
2176 size_t i;
2177 tree lhs = gimple_phi_result (phi);
2178
2179 if (flags & TDF_ALIAS)
2180 dump_ssaname_info (buffer, lhs, spc);
2181
2182 if (comment)
2183 pp_string (buffer, "# ");
2184
2185 if (flags & TDF_RAW)
2186 dump_gimple_fmt (buffer, spc, flags, "%G <%T, ", phi,
2187 gimple_phi_result (phi));
2188 else
2189 {
2190 dump_generic_node (buffer, lhs, spc, flags, false);
2191 if (flags & TDF_GIMPLE)
2192 pp_string (buffer, " = __PHI (");
2193 else
2194 pp_string (buffer, " = PHI <");
2195 }
2196 for (i = 0; i < gimple_phi_num_args (phi); i++)
2197 {
2198 if ((flags & TDF_LINENO) && gimple_phi_arg_has_location (phi, i))
2199 dump_location (buffer, gimple_phi_arg_location (phi, i));
2200 if (flags & TDF_GIMPLE)
2201 {
2202 basic_block src = gimple_phi_arg_edge (phi, i)->src;
2203 gimple *stmt = first_stmt (src);
2204 if (!stmt || gimple_code (stmt) != GIMPLE_LABEL)
2205 {
2206 pp_string (buffer, "bb_");
2207 pp_decimal_int (buffer, src->index);
2208 }
2209 else
2210 dump_generic_node (buffer, gimple_label_label (as_a <glabel *> (stmt)), 0, flags,
2211 false);
2212 pp_string (buffer, ": ");
2213 }
2214 dump_generic_node (buffer, gimple_phi_arg_def (phi, i), spc, flags,
2215 false);
2216 if (! (flags & TDF_GIMPLE))
2217 {
2218 pp_left_paren (buffer);
2219 pp_decimal_int (buffer, gimple_phi_arg_edge (phi, i)->src->index);
2220 pp_right_paren (buffer);
2221 }
2222 if (i < gimple_phi_num_args (phi) - 1)
2223 pp_string (buffer, ", ");
2224 }
2225 if (flags & TDF_GIMPLE)
2226 pp_string (buffer, ");");
2227 else
2228 pp_greater (buffer);
2229}
2230
2231
2232/* Dump a GIMPLE_OMP_PARALLEL tuple on the pretty_printer BUFFER, SPC spaces
2233 of indent. FLAGS specifies details to show in the dump (see TDF_* in
2234 dumpfile.h). */
2235
2236static void
2237dump_gimple_omp_parallel (pretty_printer *buffer, gomp_parallel *gs,
2238 int spc, dump_flags_t flags)
2239{
2240 if (flags & TDF_RAW)
2241 {
2242 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2243 gimple_omp_body (gs));
2244 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
2245 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T%n>",
2246 gimple_omp_parallel_child_fn (gs),
2247 gimple_omp_parallel_data_arg (gs));
2248 }
2249 else
2250 {
2251 gimple_seq body;
2252 pp_string (buffer, "#pragma omp parallel");
2253 dump_omp_clauses (buffer, gimple_omp_parallel_clauses (gs), spc, flags);
2254 if (gimple_omp_parallel_child_fn (gs))
2255 {
2256 pp_string (buffer, " [child fn: ");
2257 dump_generic_node (buffer, gimple_omp_parallel_child_fn (gs),
2258 spc, flags, false);
2259 pp_string (buffer, " (");
2260 if (gimple_omp_parallel_data_arg (gs))
2261 dump_generic_node (buffer, gimple_omp_parallel_data_arg (gs),
2262 spc, flags, false);
2263 else
2264 pp_string (buffer, "???");
2265 pp_string (buffer, ")]");
2266 }
2267 body = gimple_omp_body (gs);
2268 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2269 {
2270 newline_and_indent (buffer, spc + 2);
2271 pp_left_brace (buffer);
2272 pp_newline (buffer);
2273 dump_gimple_seq (buffer, body, spc + 4, flags);
2274 newline_and_indent (buffer, spc + 2);
2275 pp_right_brace (buffer);
2276 }
2277 else if (body)
2278 {
2279 pp_newline (buffer);
2280 dump_gimple_seq (buffer, body, spc + 2, flags);
2281 }
2282 }
2283}
2284
2285
2286/* Dump a GIMPLE_OMP_TASK tuple on the pretty_printer BUFFER, SPC spaces
2287 of indent. FLAGS specifies details to show in the dump (see TDF_* in
2288 dumpfile.h). */
2289
2290static void
2291dump_gimple_omp_task (pretty_printer *buffer, gomp_task *gs, int spc,
2292 dump_flags_t flags)
2293{
2294 if (flags & TDF_RAW)
2295 {
2296 dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
2297 gimple_omp_body (gs));
2298 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2299 dump_gimple_fmt (buffer, spc, flags, " >, %T, %T, %T, %T, %T%n>",
2300 gimple_omp_task_child_fn (gs),
2301 gimple_omp_task_data_arg (gs),
2302 gimple_omp_task_copy_fn (gs),
2303 gimple_omp_task_arg_size (gs),
2304 gimple_omp_task_arg_size (gs));
2305 }
2306 else
2307 {
2308 gimple_seq body;
2309 if (gimple_omp_task_taskloop_p (gs))
2310 pp_string (buffer, "#pragma omp taskloop");
2311 else
2312 pp_string (buffer, "#pragma omp task");
2313 dump_omp_clauses (buffer, gimple_omp_task_clauses (gs), spc, flags);
2314 if (gimple_omp_task_child_fn (gs))
2315 {
2316 pp_string (buffer, " [child fn: ");
2317 dump_generic_node (buffer, gimple_omp_task_child_fn (gs),
2318 spc, flags, false);
2319 pp_string (buffer, " (");
2320 if (gimple_omp_task_data_arg (gs))
2321 dump_generic_node (buffer, gimple_omp_task_data_arg (gs),
2322 spc, flags, false);
2323 else
2324 pp_string (buffer, "???");
2325 pp_string (buffer, ")]");
2326 }
2327 body = gimple_omp_body (gs);
2328 if (body && gimple_code (gimple_seq_first_stmt (body)) != GIMPLE_BIND)
2329 {
2330 newline_and_indent (buffer, spc + 2);
2331 pp_left_brace (buffer);
2332 pp_newline (buffer);
2333 dump_gimple_seq (buffer, body, spc + 4, flags);
2334 newline_and_indent (buffer, spc + 2);
2335 pp_right_brace (buffer);
2336 }
2337 else if (body)
2338 {
2339 pp_newline (buffer);
2340 dump_gimple_seq (buffer, body, spc + 2, flags);
2341 }
2342 }
2343}
2344
2345
2346/* Dump a GIMPLE_OMP_ATOMIC_LOAD tuple on the pretty_printer BUFFER, SPC
2347 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2348 in dumpfile.h). */
2349
2350static void
2351dump_gimple_omp_atomic_load (pretty_printer *buffer, gomp_atomic_load *gs,
2352 int spc, dump_flags_t flags)
2353{
2354 if (flags & TDF_RAW)
2355 {
2356 dump_gimple_fmt (buffer, spc, flags, "%G <%T, %T>", gs,
2357 gimple_omp_atomic_load_lhs (gs),
2358 gimple_omp_atomic_load_rhs (gs));
2359 }
2360 else
2361 {
2362 pp_string (buffer, "#pragma omp atomic_load");
2363 if (gimple_omp_atomic_seq_cst_p (gs))
2364 pp_string (buffer, " seq_cst");
2365 if (gimple_omp_atomic_need_value_p (gs))
2366 pp_string (buffer, " [needed]");
2367 newline_and_indent (buffer, spc + 2);
2368 dump_generic_node (buffer, gimple_omp_atomic_load_lhs (gs),
2369 spc, flags, false);
2370 pp_space (buffer);
2371 pp_equal (buffer);
2372 pp_space (buffer);
2373 pp_star (buffer);
2374 dump_generic_node (buffer, gimple_omp_atomic_load_rhs (gs),
2375 spc, flags, false);
2376 }
2377}
2378
2379/* Dump a GIMPLE_OMP_ATOMIC_STORE tuple on the pretty_printer BUFFER, SPC
2380 spaces of indent. FLAGS specifies details to show in the dump (see TDF_*
2381 in dumpfile.h). */
2382
2383static void
2384dump_gimple_omp_atomic_store (pretty_printer *buffer,
2385 gomp_atomic_store *gs, int spc,
2386 dump_flags_t flags)
2387{
2388 if (flags & TDF_RAW)
2389 {
2390 dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
2391 gimple_omp_atomic_store_val (gs));
2392 }
2393 else
2394 {
2395 pp_string (buffer, "#pragma omp atomic_store ");
2396 if (gimple_omp_atomic_seq_cst_p (gs))
2397 pp_string (buffer, "seq_cst ");
2398 if (gimple_omp_atomic_need_value_p (gs))
2399 pp_string (buffer, "[needed] ");
2400 pp_left_paren (buffer);
2401 dump_generic_node (buffer, gimple_omp_atomic_store_val (gs),
2402 spc, flags, false);
2403 pp_right_paren (buffer);
2404 }
2405}
2406
2407
2408/* Dump all the memory operands for statement GS. BUFFER, SPC and
2409 FLAGS are as in pp_gimple_stmt_1. */
2410
2411static void
2412dump_gimple_mem_ops (pretty_printer *buffer, gimple *gs, int spc,
2413 dump_flags_t flags)
2414{
2415 tree vdef = gimple_vdef (gs);
2416 tree vuse = gimple_vuse (gs);
2417
2418 if (vdef != NULL_TREE)
2419 {
2420 pp_string (buffer, "# ");
2421 dump_generic_node (buffer, vdef, spc + 2, flags, false);
2422 pp_string (buffer, " = VDEF <");
2423 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2424 pp_greater (buffer);
2425 newline_and_indent (buffer, spc);
2426 }
2427 else if (vuse != NULL_TREE)
2428 {
2429 pp_string (buffer, "# VUSE <");
2430 dump_generic_node (buffer, vuse, spc + 2, flags, false);
2431 pp_greater (buffer);
2432 newline_and_indent (buffer, spc);
2433 }
2434}
2435
2436
2437/* Print the gimple statement GS on the pretty printer BUFFER, SPC
2438 spaces of indent. FLAGS specifies details to show in the dump (see
2439 TDF_* in dumpfile.h). The caller is responsible for calling
2440 pp_flush on BUFFER to finalize the pretty printer. */
2441
2442void
2443pp_gimple_stmt_1 (pretty_printer *buffer, gimple *gs, int spc,
2444 dump_flags_t flags)
2445{
2446 if (!gs)
2447 return;
2448
2449 if (flags & TDF_STMTADDR)
2450 pp_printf (buffer, "<&%p> ", (void *) gs);
2451
2452 if ((flags & TDF_LINENO) && gimple_has_location (gs))
2453 dump_location (buffer, gimple_location (gs));
2454
2455 if (flags & TDF_EH)
2456 {
2457 int lp_nr = lookup_stmt_eh_lp (gs);
2458 if (lp_nr > 0)
2459 pp_printf (buffer, "[LP %d] ", lp_nr);
2460 else if (lp_nr < 0)
2461 pp_printf (buffer, "[MNT %d] ", -lp_nr);
2462 }
2463
2464 if ((flags & (TDF_VOPS|TDF_MEMSYMS))
2465 && gimple_has_mem_ops (gs))
2466 dump_gimple_mem_ops (buffer, gs, spc, flags);
2467
2468 if (gimple_has_lhs (gs)
2469 && (flags & TDF_ALIAS))
2470 dump_ssaname_info (buffer, gimple_get_lhs (gs), spc);
2471
2472 switch (gimple_code (gs))
2473 {
2474 case GIMPLE_ASM:
2475 dump_gimple_asm (buffer, as_a <gasm *> (gs), spc, flags);
2476 break;
2477
2478 case GIMPLE_ASSIGN:
2479 dump_gimple_assign (buffer, as_a <gassign *> (gs), spc, flags);
2480 break;
2481
2482 case GIMPLE_BIND:
2483 dump_gimple_bind (buffer, as_a <gbind *> (gs), spc, flags);
2484 break;
2485
2486 case GIMPLE_CALL:
2487 dump_gimple_call (buffer, as_a <gcall *> (gs), spc, flags);
2488 break;
2489
2490 case GIMPLE_COND:
2491 dump_gimple_cond (buffer, as_a <gcond *> (gs), spc, flags);
2492 break;
2493
2494 case GIMPLE_LABEL:
2495 dump_gimple_label (buffer, as_a <glabel *> (gs), spc, flags);
2496 break;
2497
2498 case GIMPLE_GOTO:
2499 dump_gimple_goto (buffer, as_a <ggoto *> (gs), spc, flags);
2500 break;
2501
2502 case GIMPLE_NOP:
2503 pp_string (buffer, "GIMPLE_NOP");
2504 break;
2505
2506 case GIMPLE_RETURN:
2507 dump_gimple_return (buffer, as_a <greturn *> (gs), spc, flags);
2508 break;
2509
2510 case GIMPLE_SWITCH:
2511 dump_gimple_switch (buffer, as_a <gswitch *> (gs), spc, flags);
2512 break;
2513
2514 case GIMPLE_TRY:
2515 dump_gimple_try (buffer, as_a <gtry *> (gs), spc, flags);
2516 break;
2517
2518 case GIMPLE_PHI:
2519 dump_gimple_phi (buffer, as_a <gphi *> (gs), spc, false, flags);
2520 break;
2521
2522 case GIMPLE_OMP_PARALLEL:
2523 dump_gimple_omp_parallel (buffer, as_a <gomp_parallel *> (gs), spc,
2524 flags);
2525 break;
2526
2527 case GIMPLE_OMP_TASK:
2528 dump_gimple_omp_task (buffer, as_a <gomp_task *> (gs), spc, flags);
2529 break;
2530
2531 case GIMPLE_OMP_ATOMIC_LOAD:
2532 dump_gimple_omp_atomic_load (buffer, as_a <gomp_atomic_load *> (gs),
2533 spc, flags);
2534 break;
2535
2536 case GIMPLE_OMP_ATOMIC_STORE:
2537 dump_gimple_omp_atomic_store (buffer,
2538 as_a <gomp_atomic_store *> (gs),
2539 spc, flags);
2540 break;
2541
2542 case GIMPLE_OMP_FOR:
2543 dump_gimple_omp_for (buffer, as_a <gomp_for *> (gs), spc, flags);
2544 break;
2545
2546 case GIMPLE_OMP_CONTINUE:
2547 dump_gimple_omp_continue (buffer, as_a <gomp_continue *> (gs), spc,
2548 flags);
2549 break;
2550
2551 case GIMPLE_OMP_SINGLE:
2552 dump_gimple_omp_single (buffer, as_a <gomp_single *> (gs), spc,
2553 flags);
2554 break;
2555
2556 case GIMPLE_OMP_TARGET:
2557 dump_gimple_omp_target (buffer, as_a <gomp_target *> (gs), spc,
2558 flags);
2559 break;
2560
2561 case GIMPLE_OMP_TEAMS:
2562 dump_gimple_omp_teams (buffer, as_a <gomp_teams *> (gs), spc,
2563 flags);
2564 break;
2565
2566 case GIMPLE_OMP_RETURN:
2567 dump_gimple_omp_return (buffer, gs, spc, flags);
2568 break;
2569
2570 case GIMPLE_OMP_SECTIONS:
2571 dump_gimple_omp_sections (buffer, as_a <gomp_sections *> (gs),
2572 spc, flags);
2573 break;
2574
2575 case GIMPLE_OMP_SECTIONS_SWITCH:
2576 pp_string (buffer, "GIMPLE_SECTIONS_SWITCH");
2577 break;
2578
2579 case GIMPLE_OMP_MASTER:
2580 case GIMPLE_OMP_TASKGROUP:
2581 case GIMPLE_OMP_SECTION:
2582 case GIMPLE_OMP_GRID_BODY:
2583 dump_gimple_omp_block (buffer, gs, spc, flags);
2584 break;
2585
2586 case GIMPLE_OMP_ORDERED:
2587 dump_gimple_omp_ordered (buffer, as_a <gomp_ordered *> (gs), spc,
2588 flags);
2589 break;
2590
2591 case GIMPLE_OMP_CRITICAL:
2592 dump_gimple_omp_critical (buffer, as_a <gomp_critical *> (gs), spc,
2593 flags);
2594 break;
2595
2596 case GIMPLE_CATCH:
2597 dump_gimple_catch (buffer, as_a <gcatch *> (gs), spc, flags);
2598 break;
2599
2600 case GIMPLE_EH_FILTER:
2601 dump_gimple_eh_filter (buffer, as_a <geh_filter *> (gs), spc, flags);
2602 break;
2603
2604 case GIMPLE_EH_MUST_NOT_THROW:
2605 dump_gimple_eh_must_not_throw (buffer,
2606 as_a <geh_mnt *> (gs),
2607 spc, flags);
2608 break;
2609
2610 case GIMPLE_EH_ELSE:
2611 dump_gimple_eh_else (buffer, as_a <geh_else *> (gs), spc, flags);
2612 break;
2613
2614 case GIMPLE_RESX:
2615 dump_gimple_resx (buffer, as_a <gresx *> (gs), spc, flags);
2616 break;
2617
2618 case GIMPLE_EH_DISPATCH:
2619 dump_gimple_eh_dispatch (buffer, as_a <geh_dispatch *> (gs), spc,
2620 flags);
2621 break;
2622
2623 case GIMPLE_DEBUG:
2624 dump_gimple_debug (buffer, as_a <gdebug *> (gs), spc, flags);
2625 break;
2626
2627 case GIMPLE_PREDICT:
2628 pp_string (buffer, "// predicted ");
2629 if (gimple_predict_outcome (gs))
2630 pp_string (buffer, "likely by ");
2631 else
2632 pp_string (buffer, "unlikely by ");
2633 pp_string (buffer, predictor_name (gimple_predict_predictor (gs)));
2634 pp_string (buffer, " predictor.");
2635 break;
2636
2637 case GIMPLE_TRANSACTION:
2638 dump_gimple_transaction (buffer, as_a <gtransaction *> (gs), spc,
2639 flags);
2640 break;
2641
2642 default:
2643 GIMPLE_NIY;
2644 }
2645}
2646
2647
2648/* Dumps header of basic block BB to OUTF indented by INDENT
2649 spaces and details described by flags. */
2650
2651static void
2652dump_gimple_bb_header (FILE *outf, basic_block bb, int indent,
2653 dump_flags_t flags)
2654{
2655 if (flags & TDF_BLOCKS)
2656 {
2657 if (flags & TDF_LINENO)
2658 {
2659 gimple_stmt_iterator gsi;
2660
2661 fputs (";; ", outf);
2662
2663 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2664 if (!is_gimple_debug (gsi_stmt (gsi))
2665 && get_lineno (gsi_stmt (gsi)) != UNKNOWN_LOCATION)
2666 {
2667 fprintf (outf, "%*sstarting at line %d",
2668 indent, "", get_lineno (gsi_stmt (gsi)));
2669 break;
2670 }
2671 if (bb->discriminator)
2672 fprintf (outf, ", discriminator %i", bb->discriminator);
2673 fputc ('\n', outf);
2674 }
2675 }
2676 else
2677 {
2678 if (flags & TDF_GIMPLE)
2679 fprintf (outf, "%*sbb_%d:\n", indent, "", bb->index);
2680 else
2681 fprintf (outf, "%*s<bb %d> %s:\n",
2682 indent, "", bb->index, dump_profile (bb->count));
2683 }
2684}
2685
2686
2687/* Dumps end of basic block BB to buffer BUFFER indented by INDENT
2688 spaces. */
2689
2690static void
2691dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
2692 basic_block bb ATTRIBUTE_UNUSED,
2693 int indent ATTRIBUTE_UNUSED,
2694 dump_flags_t flags ATTRIBUTE_UNUSED)
2695{
2696 /* There is currently no GIMPLE-specific basic block info to dump. */
2697 return;
2698}
2699
2700
2701/* Dump PHI nodes of basic block BB to BUFFER with details described
2702 by FLAGS and indented by INDENT spaces. */
2703
2704static void
2705dump_phi_nodes (pretty_printer *buffer, basic_block bb, int indent,
2706 dump_flags_t flags)
2707{
2708 gphi_iterator i;
2709
2710 for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
2711 {
2712 gphi *phi = i.phi ();
2713 if (!virtual_operand_p (gimple_phi_result (phi)) || (flags & TDF_VOPS))
2714 {
2715 INDENT (indent);
2716 dump_gimple_phi (buffer, phi, indent,
2717 (flags & TDF_GIMPLE) ? false : true, flags);
2718 pp_newline (buffer);
2719 }
2720 }
2721}
2722
2723
2724/* Dump jump to basic block BB that is represented implicitly in the cfg
2725 to BUFFER. */
2726
2727static void
2728pp_cfg_jump (pretty_printer *buffer, edge e, dump_flags_t flags)
2729{
2730 if (flags & TDF_GIMPLE)
2731 {
2732 pp_string (buffer, "goto bb_");
2733 pp_decimal_int (buffer, e->dest->index);
2734 pp_semicolon (buffer);
2735 }
2736 else
2737 {
2738 pp_string (buffer, "goto <bb ");
2739 pp_decimal_int (buffer, e->dest->index);
2740 pp_greater (buffer);
2741 pp_semicolon (buffer);
2742
2743 dump_edge_probability (buffer, e);
2744 }
2745}
2746
2747
2748/* Dump edges represented implicitly in basic block BB to BUFFER, indented
2749 by INDENT spaces, with details given by FLAGS. */
2750
2751static void
2752dump_implicit_edges (pretty_printer *buffer, basic_block bb, int indent,
2753 dump_flags_t flags)
2754{
2755 edge e;
2756 gimple *stmt;
2757
2758 stmt = last_stmt (bb);
2759
2760 if (stmt && gimple_code (stmt) == GIMPLE_COND)
2761 {
2762 edge true_edge, false_edge;
2763
2764 /* When we are emitting the code or changing CFG, it is possible that
2765 the edges are not yet created. When we are using debug_bb in such
2766 a situation, we do not want it to crash. */
2767 if (EDGE_COUNT (bb->succs) != 2)
2768 return;
2769 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2770
2771 INDENT (indent + 2);
2772 pp_cfg_jump (buffer, true_edge, flags);
2773 newline_and_indent (buffer, indent);
2774 pp_string (buffer, "else");
2775 newline_and_indent (buffer, indent + 2);
2776 pp_cfg_jump (buffer, false_edge, flags);
2777 pp_newline (buffer);
2778 return;
2779 }
2780
2781 /* If there is a fallthru edge, we may need to add an artificial
2782 goto to the dump. */
2783 e = find_fallthru_edge (bb->succs);
2784
2785 if (e && e->dest != bb->next_bb)
2786 {
2787 INDENT (indent);
2788
2789 if ((flags & TDF_LINENO)
2790 && e->goto_locus != UNKNOWN_LOCATION)
2791 dump_location (buffer, e->goto_locus);
2792
2793 pp_cfg_jump (buffer, e, flags);
2794 pp_newline (buffer);
2795 }
2796}
2797
2798
2799/* Dumps basic block BB to buffer BUFFER with details described by FLAGS and
2800 indented by INDENT spaces. */
2801
2802static void
2803gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
2804 dump_flags_t flags)
2805{
2806 gimple_stmt_iterator gsi;
2807 gimple *stmt;
2808 int label_indent = indent - 2;
2809
2810 if (label_indent < 0)
2811 label_indent = 0;
2812
2813 dump_phi_nodes (buffer, bb, indent, flags);
2814
2815 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2816 {
2817 int curr_indent;
2818
2819 stmt = gsi_stmt (gsi);
2820
2821 curr_indent = gimple_code (stmt) == GIMPLE_LABEL ? label_indent : indent;
2822
2823 INDENT (curr_indent);
2824 pp_gimple_stmt_1 (buffer, stmt, curr_indent, flags);
2825 pp_newline_and_flush (buffer);
2826 gcc_checking_assert (DECL_STRUCT_FUNCTION (current_function_decl));
2827 dump_histograms_for_stmt (DECL_STRUCT_FUNCTION (current_function_decl),
2828 pp_buffer (buffer)->stream, stmt);
2829 }
2830
2831 dump_implicit_edges (buffer, bb, indent, flags);
2832 pp_flush (buffer);
2833}
2834
2835
2836/* Dumps basic block BB to FILE with details described by FLAGS and
2837 indented by INDENT spaces. */
2838
2839void
2840gimple_dump_bb (FILE *file, basic_block bb, int indent, dump_flags_t flags)
2841{
2842 dump_gimple_bb_header (file, bb, indent, flags);
2843 if (bb->index >= NUM_FIXED_BLOCKS)
2844 {
2845 pretty_printer buffer;
2846 pp_needs_newline (&buffer) = true;
2847 buffer.buffer->stream = file;
2848 gimple_dump_bb_buff (&buffer, bb, indent, flags);
2849 }
2850 dump_gimple_bb_footer (file, bb, indent, flags);
2851}
2852
2853/* Dumps basic block BB to pretty-printer PP with default dump flags and
2854 no indentation, for use as a label of a DOT graph record-node.
2855 ??? Should just use gimple_dump_bb_buff here, except that value profiling
2856 histogram dumping doesn't know about pretty-printers. */
2857
2858void
2859gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
2860{
2861 pp_printf (pp, "<bb %d>:\n", bb->index);
2862 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2863
2864 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
2865 gsi_next (&gsi))
2866 {
2867 gphi *phi = gsi.phi ();
2868 if (!virtual_operand_p (gimple_phi_result (phi))
2869 || (dump_flags & TDF_VOPS))
2870 {
2871 pp_bar (pp);
2872 pp_write_text_to_stream (pp);
2873 pp_string (pp, "# ");
2874 pp_gimple_stmt_1 (pp, phi, 0, dump_flags);
2875 pp_newline (pp);
2876 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2877 }
2878 }
2879
2880 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
2881 gsi_next (&gsi))
2882 {
2883 gimple *stmt = gsi_stmt (gsi);
2884 pp_bar (pp);
2885 pp_write_text_to_stream (pp);
2886 pp_gimple_stmt_1 (pp, stmt, 0, dump_flags);
2887 pp_newline (pp);
2888 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2889 }
2890 dump_implicit_edges (pp, bb, 0, dump_flags);
2891 pp_write_text_as_dot_label_to_stream (pp, /*for_record=*/true);
2892}
2893
2894
2895/* Handle the %G format for TEXT. Same as %K in handle_K_format in
2896 tree-pretty-print.c but with a Gimple call statement as an argument. */
2897
2898void
2899percent_G_format (text_info *text)
2900{
2901 gcall *stmt = va_arg (*text->args_ptr, gcall*);
2902
2903 /* Build a call expression from the Gimple call statement and
2904 pass it to the K formatter that knows how to format it. */
2905 tree exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3);
2906 CALL_EXPR_FN (exp) = gimple_call_fn (stmt);
2907 TREE_TYPE (exp) = gimple_call_return_type (stmt);
2908 CALL_EXPR_STATIC_CHAIN (exp) = gimple_call_chain (stmt);
2909 SET_EXPR_LOCATION (exp, gimple_location (stmt));
2910
2911 percent_K_format (text, exp);
2912}
2913