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