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