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