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