tree-optimization/113126 - vector extension compare optimization
[official-gcc.git] / gcc / print-tree.cc
blob7d38ed631d7381a1b2ac0380c5537fb0257e66ae
1 /* Prints out tree in human readable form - GCC
2 Copyright (C) 1990-2024 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "cgraph.h"
27 #include "diagnostic.h"
28 #include "varasm.h"
29 #include "print-rtl.h"
30 #include "stor-layout.h"
31 #include "langhooks.h"
32 #include "tree-iterator.h"
33 #include "gimple-pretty-print.h" /* FIXME */
34 #include "tree-cfg.h"
35 #include "dumpfile.h"
36 #include "print-tree.h"
37 #include "file-prefix-map.h"
39 /* Define the hash table of nodes already seen.
40 Such nodes are not repeated; brief cross-references are used. */
42 #define HASH_SIZE 37
44 static hash_set<tree> *table = NULL;
46 /* Print PREFIX and ADDR to FILE. */
47 void
48 dump_addr (FILE *file, const char *prefix, const void *addr)
50 if (flag_dump_noaddr || flag_dump_unnumbered)
51 fprintf (file, "%s#", prefix);
52 else
53 fprintf (file, "%s" HOST_PTR_PRINTF, prefix, addr);
56 /* Print to FILE a NODE representing a REAL_CST constant, including
57 Infinity and NaN. Be verbose when BFRIEF is false. */
59 static void
60 print_real_cst (FILE *file, const_tree node, bool brief)
62 if (TREE_OVERFLOW (node))
63 fprintf (file, " overflow");
65 REAL_VALUE_TYPE d = TREE_REAL_CST (node);
66 if (REAL_VALUE_ISINF (d))
67 fprintf (file, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
68 else if (REAL_VALUE_ISNAN (d))
70 /* Print a NaN in the format [-][Q]NaN[(significand[exponent])]
71 where significand is a hexadecimal string that starts with
72 the 0x prefix followed by 0 if the number is not canonical
73 and a non-zero digit if it is, and exponent is decimal. */
74 unsigned start = 0;
75 const char *psig = (const char *) d.sig;
76 for (unsigned i = 0; i != sizeof d.sig; ++i)
77 if (psig[i])
79 start = i;
80 break;
83 fprintf (file, " %s%sNaN", d.sign ? "-" : "",
84 d.signalling ? "S" : "Q");
86 if (brief)
87 return;
89 if (start)
90 fprintf (file, "(0x%s", d.canonical ? "" : "0");
91 else if (d.uexp)
92 fprintf (file, "(%s", d.canonical ? "" : "0");
93 else if (!d.canonical)
95 fprintf (file, "(0)");
96 return;
99 if (psig[start])
101 for (unsigned i = start; i != sizeof d.sig; ++i)
102 if (i == start)
103 fprintf (file, "%x", psig[i]);
104 else
105 fprintf (file, "%02x", psig[i]);
108 if (d.uexp)
109 fprintf (file, "%se%u)", psig[start] ? "," : "", d.uexp);
110 else if (psig[start])
111 fputc (')', file);
113 else
115 char string[64];
116 real_to_decimal (string, &d, sizeof (string), 0, 1);
117 fprintf (file, " %s", string);
121 /* Print a node in brief fashion, with just the code, address and name. */
123 void
124 print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
126 enum tree_code_class tclass;
128 if (node == 0)
129 return;
131 tclass = TREE_CODE_CLASS (TREE_CODE (node));
133 /* Always print the slot this node is in, and its code, address and
134 name if any. */
135 if (indent > 0)
136 fprintf (file, " ");
137 fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
138 dump_addr (file, " ", node);
140 if (tclass == tcc_declaration)
142 if (DECL_NAME (node))
143 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
144 else if (TREE_CODE (node) == LABEL_DECL
145 && LABEL_DECL_UID (node) != -1)
147 if (dump_flags & TDF_NOUID)
148 fprintf (file, " L.xxxx");
149 else
150 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
152 else
154 if (dump_flags & TDF_NOUID)
155 fprintf (file, " %c.xxxx",
156 TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
157 else
158 fprintf (file, " %c.%u",
159 TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
160 DECL_UID (node));
163 else if (tclass == tcc_type)
165 if (TYPE_NAME (node))
167 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
168 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
169 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
170 && DECL_NAME (TYPE_NAME (node)))
171 fprintf (file, " %s",
172 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
174 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
175 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
177 if (TREE_CODE (node) == IDENTIFIER_NODE)
178 fprintf (file, " %s", IDENTIFIER_POINTER (node));
180 /* We might as well always print the value of an integer or real. */
181 if (TREE_CODE (node) == INTEGER_CST)
183 if (TREE_OVERFLOW (node))
184 fprintf (file, " overflow");
186 fprintf (file, " ");
187 print_dec (wi::to_wide (node), file, TYPE_SIGN (TREE_TYPE (node)));
189 if (TREE_CODE (node) == REAL_CST)
190 print_real_cst (file, node, true);
191 if (TREE_CODE (node) == FIXED_CST)
193 FIXED_VALUE_TYPE f;
194 char string[60];
196 if (TREE_OVERFLOW (node))
197 fprintf (file, " overflow");
199 f = TREE_FIXED_CST (node);
200 fixed_to_decimal (string, &f, sizeof (string));
201 fprintf (file, " %s", string);
204 fprintf (file, ">");
207 void
208 indent_to (FILE *file, int column)
210 int i;
212 /* Since this is the long way, indent to desired column. */
213 if (column > 0)
214 fprintf (file, "\n");
215 for (i = 0; i < column; i++)
216 fprintf (file, " ");
219 /* Print the node NODE in full on file FILE, preceded by PREFIX,
220 starting in column INDENT. */
222 void
223 print_node (FILE *file, const char *prefix, tree node, int indent,
224 bool brief_for_visited)
226 machine_mode mode;
227 enum tree_code_class tclass;
228 int len;
229 int i;
230 expanded_location xloc;
231 enum tree_code code;
233 if (node == 0)
234 return;
236 code = TREE_CODE (node);
238 /* It is unsafe to look at any other fields of a node with ERROR_MARK or
239 invalid code. */
240 if (code == ERROR_MARK || code >= MAX_TREE_CODES)
242 print_node_brief (file, prefix, node, indent);
243 return;
246 tclass = TREE_CODE_CLASS (code);
248 /* Don't get too deep in nesting. If the user wants to see deeper,
249 it is easy to use the address of a lowest-level node
250 as an argument in another call to debug_tree. */
252 if (indent > 24)
254 print_node_brief (file, prefix, node, indent);
255 return;
258 if (indent > 8 && (tclass == tcc_type || tclass == tcc_declaration))
260 print_node_brief (file, prefix, node, indent);
261 return;
264 /* Allow this function to be called if the table is not there. */
265 if (table)
267 /* If node is in the table, just mention its address. */
268 if (table->contains (node) && brief_for_visited)
270 print_node_brief (file, prefix, node, indent);
271 return;
274 table->add (node);
277 /* Indent to the specified column, since this is the long form. */
278 indent_to (file, indent);
280 /* Print the slot this node is in, and its code, and address. */
281 fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
282 dump_addr (file, " ", node);
284 /* Print the name, if any. */
285 if (tclass == tcc_declaration)
287 if (DECL_NAME (node))
288 fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
289 else if (code == LABEL_DECL
290 && LABEL_DECL_UID (node) != -1)
292 if (dump_flags & TDF_NOUID)
293 fprintf (file, " L.xxxx");
294 else
295 fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
297 else
299 if (dump_flags & TDF_NOUID)
300 fprintf (file, " %c.xxxx", code == CONST_DECL ? 'C' : 'D');
301 else
302 fprintf (file, " %c.%u", code == CONST_DECL ? 'C' : 'D',
303 DECL_UID (node));
306 else if (tclass == tcc_type)
308 if (TYPE_NAME (node))
310 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
311 fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
312 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
313 && DECL_NAME (TYPE_NAME (node)))
314 fprintf (file, " %s",
315 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
318 if (code == IDENTIFIER_NODE)
319 fprintf (file, " %s", IDENTIFIER_POINTER (node));
321 if (code == INTEGER_CST)
323 if (indent <= 4)
324 print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
326 else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
328 print_node (file, "type", TREE_TYPE (node), indent + 4);
329 if (TREE_TYPE (node))
330 indent_to (file, indent + 3);
333 if (!TYPE_P (node) && TREE_SIDE_EFFECTS (node))
334 fputs (" side-effects", file);
336 if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
337 fputs (" readonly", file);
338 if (TYPE_P (node) && TYPE_ATOMIC (node))
339 fputs (" atomic", file);
340 if (!TYPE_P (node) && TREE_CONSTANT (node))
341 fputs (" constant", file);
342 else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
343 fputs (" sizes-gimplified", file);
345 if (TYPE_P (node) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
346 fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
348 if (TREE_ADDRESSABLE (node))
349 fputs (" addressable", file);
350 if (TREE_THIS_VOLATILE (node))
351 fputs (" volatile", file);
352 if (TREE_ASM_WRITTEN (node))
353 fputs (" asm_written", file);
354 if (TREE_USED (node))
355 fputs (" used", file);
356 if (TREE_NOTHROW (node))
357 fputs (" nothrow", file);
358 if (TREE_PUBLIC (node))
359 fputs (" public", file);
360 if (TREE_PRIVATE (node))
361 fputs (" private", file);
362 if (TREE_PROTECTED (node))
363 fputs (" protected", file);
364 if (TREE_STATIC (node))
365 fputs (code == CALL_EXPR ? " must-tail-call" : " static", file);
366 if (TREE_DEPRECATED (node))
367 fputs (" deprecated", file);
368 if (TREE_VISITED (node))
369 fputs (" visited", file);
371 if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
373 if (TREE_UNAVAILABLE (node))
374 fputs (" unavailable", file);
375 if (TREE_LANG_FLAG_0 (node))
376 fputs (" tree_0", file);
377 if (TREE_LANG_FLAG_1 (node))
378 fputs (" tree_1", file);
379 if (TREE_LANG_FLAG_2 (node))
380 fputs (" tree_2", file);
381 if (TREE_LANG_FLAG_3 (node))
382 fputs (" tree_3", file);
383 if (TREE_LANG_FLAG_4 (node))
384 fputs (" tree_4", file);
385 if (TREE_LANG_FLAG_5 (node))
386 fputs (" tree_5", file);
387 if (TREE_LANG_FLAG_6 (node))
388 fputs (" tree_6", file);
391 /* DECL_ nodes have additional attributes. */
393 switch (TREE_CODE_CLASS (code))
395 case tcc_declaration:
396 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
398 if (DECL_UNSIGNED (node))
399 fputs (" unsigned", file);
400 if (DECL_IGNORED_P (node))
401 fputs (" ignored", file);
402 if (DECL_ABSTRACT_P (node))
403 fputs (" abstract", file);
404 if (DECL_EXTERNAL (node))
405 fputs (" external", file);
406 if (DECL_NONLOCAL (node))
407 fputs (" nonlocal", file);
409 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
411 if (DECL_WEAK (node))
412 fputs (" weak", file);
413 if (DECL_IN_SYSTEM_HEADER (node))
414 fputs (" in_system_header", file);
416 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL)
417 && code != LABEL_DECL
418 && code != FUNCTION_DECL
419 && DECL_REGISTER (node))
420 fputs (" regdecl", file);
422 if (code == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
423 fputs (" suppress-debug", file);
425 if (code == FUNCTION_DECL
426 && DECL_FUNCTION_SPECIFIC_TARGET (node))
427 fputs (" function-specific-target", file);
428 if (code == FUNCTION_DECL
429 && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node))
430 fputs (" function-specific-opt", file);
431 if (code == FUNCTION_DECL && DECL_DECLARED_INLINE_P (node))
432 fputs (" autoinline", file);
433 if (code == FUNCTION_DECL && DECL_UNINLINABLE (node))
434 fputs (" uninlinable", file);
435 if (code == FUNCTION_DECL && fndecl_built_in_p (node))
436 fputs (" built-in", file);
437 if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
438 fputs (" static-chain", file);
439 if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
440 fputs (" tm-clone", file);
442 if (code == FIELD_DECL && DECL_PACKED (node))
443 fputs (" packed", file);
444 if (code == FIELD_DECL && DECL_BIT_FIELD (node))
445 fputs (" bit-field", file);
446 if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
447 fputs (" nonaddressable", file);
449 if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
450 fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
452 if (code == VAR_DECL && DECL_IN_TEXT_SECTION (node))
453 fputs (" in-text-section", file);
454 if (code == VAR_DECL && DECL_IN_CONSTANT_POOL (node))
455 fputs (" in-constant-pool", file);
456 if (code == VAR_DECL && DECL_COMMON (node))
457 fputs (" common", file);
458 if ((code == VAR_DECL || code == PARM_DECL) && DECL_READ_P (node))
459 fputs (" read", file);
460 if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
462 fputs (" ", file);
463 fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
466 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
468 if (DECL_VIRTUAL_P (node))
469 fputs (" virtual", file);
470 if (DECL_PRESERVE_P (node))
471 fputs (" preserve", file);
472 if (DECL_LANG_FLAG_0 (node))
473 fputs (" decl_0", file);
474 if (DECL_LANG_FLAG_1 (node))
475 fputs (" decl_1", file);
476 if (DECL_LANG_FLAG_2 (node))
477 fputs (" decl_2", file);
478 if (DECL_LANG_FLAG_3 (node))
479 fputs (" decl_3", file);
480 if (DECL_LANG_FLAG_4 (node))
481 fputs (" decl_4", file);
482 if (DECL_LANG_FLAG_5 (node))
483 fputs (" decl_5", file);
484 if (DECL_LANG_FLAG_6 (node))
485 fputs (" decl_6", file);
486 if (DECL_LANG_FLAG_7 (node))
487 fputs (" decl_7", file);
488 if (DECL_LANG_FLAG_8 (node))
489 fputs (" decl_8", file);
491 mode = DECL_MODE (node);
492 fprintf (file, " %s", GET_MODE_NAME (mode));
495 if ((code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
496 && DECL_BY_REFERENCE (node))
497 fputs (" passed-by-reference", file);
499 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS) && DECL_DEFER_OUTPUT (node))
500 fputs (" defer-output", file);
503 xloc = expand_location (DECL_SOURCE_LOCATION (node));
504 fprintf (file, " %s:%d:%d", xloc.file, xloc.line,
505 xloc.column);
507 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
509 print_node (file, "size", DECL_SIZE (node), indent + 4);
510 print_node (file, "unit-size", DECL_SIZE_UNIT (node), indent + 4);
512 if (code != FUNCTION_DECL || fndecl_built_in_p (node))
513 indent_to (file, indent + 3);
515 if (DECL_USER_ALIGN (node))
516 fprintf (file, " user");
518 fprintf (file, " align:%d warn_if_not_align:%d",
519 DECL_ALIGN (node), DECL_WARN_IF_NOT_ALIGN (node));
520 if (code == FIELD_DECL)
522 fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
523 DECL_OFFSET_ALIGN (node));
524 fprintf (file, " decl_not_flexarray: %d",
525 DECL_NOT_FLEXARRAY (node));
528 if (code == FUNCTION_DECL && fndecl_built_in_p (node))
530 if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
531 fprintf (file, " built-in: BUILT_IN_MD:%d",
532 DECL_MD_FUNCTION_CODE (node));
533 else if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_FRONTEND)
534 fprintf (file, " built-in: BUILT_IN_FRONTEND:%d",
535 DECL_FE_FUNCTION_CODE (node));
536 else
537 fprintf (file, " built-in: %s:%s",
538 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
539 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
542 if (code == FIELD_DECL)
544 print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
545 print_node (file, "bit-offset", DECL_FIELD_BIT_OFFSET (node),
546 indent + 4);
547 if (DECL_BIT_FIELD_TYPE (node))
548 print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
549 indent + 4);
552 print_node_brief (file, "context", DECL_CONTEXT (node), indent + 4);
554 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
556 print_node (file, "attributes",
557 DECL_ATTRIBUTES (node), indent + 4);
558 if (code != PARM_DECL)
559 print_node_brief (file, "initial", DECL_INITIAL (node),
560 indent + 4);
562 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
564 print_node_brief (file, "abstract_origin",
565 DECL_ABSTRACT_ORIGIN (node), indent + 4);
567 if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
569 print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
572 lang_hooks.print_decl (file, node, indent);
574 if (DECL_RTL_SET_P (node))
576 indent_to (file, indent + 4);
577 print_rtl (file, DECL_RTL (node));
580 if (code == PARM_DECL)
582 print_node (file, "arg-type", DECL_ARG_TYPE (node), indent + 4);
584 if (DECL_INCOMING_RTL (node) != 0)
586 indent_to (file, indent + 4);
587 fprintf (file, "incoming-rtl ");
588 print_rtl (file, DECL_INCOMING_RTL (node));
591 else if (code == FUNCTION_DECL
592 && DECL_STRUCT_FUNCTION (node) != 0)
594 print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
595 indent_to (file, indent + 4);
596 dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
599 if ((code == VAR_DECL || code == PARM_DECL)
600 && DECL_HAS_VALUE_EXPR_P (node))
601 print_node (file, "value-expr", DECL_VALUE_EXPR (node), indent + 4);
603 /* Print the decl chain only if decl is at second level. */
604 if (indent == 4)
605 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
606 else
607 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
608 break;
610 case tcc_type:
611 if (TYPE_UNSIGNED (node))
612 fputs (" unsigned", file);
614 if (TYPE_NO_FORCE_BLK (node))
615 fputs (" no-force-blk", file);
617 if (code == ARRAY_TYPE && TYPE_STRING_FLAG (node))
618 fputs (" string-flag", file);
620 if (TYPE_NEEDS_CONSTRUCTING (node))
621 fputs (" needs-constructing", file);
623 if ((code == RECORD_TYPE
624 || code == UNION_TYPE
625 || code == QUAL_UNION_TYPE
626 || code == ARRAY_TYPE)
627 && TYPE_REVERSE_STORAGE_ORDER (node))
628 fputs (" reverse-storage-order", file);
630 if ((code == RECORD_TYPE
631 || code == UNION_TYPE)
632 && TYPE_CXX_ODR_P (node))
633 fputs (" cxx-odr-p", file);
635 if ((code == RECORD_TYPE
636 || code == UNION_TYPE)
637 && TYPE_INCLUDES_FLEXARRAY (node))
638 fputs (" includes-flexarray", file);
640 /* The transparent-union flag is used for different things in
641 different nodes. */
642 if ((code == UNION_TYPE || code == RECORD_TYPE)
643 && TYPE_TRANSPARENT_AGGR (node))
644 fputs (" transparent-aggr", file);
645 else if (code == ARRAY_TYPE
646 && TYPE_NONALIASED_COMPONENT (node))
647 fputs (" nonaliased-component", file);
649 if (TYPE_PACKED (node))
650 fputs (" packed", file);
652 if (TYPE_RESTRICT (node))
653 fputs (" restrict", file);
655 if (TYPE_LANG_FLAG_0 (node))
656 fputs (" type_0", file);
657 if (TYPE_LANG_FLAG_1 (node))
658 fputs (" type_1", file);
659 if (TYPE_LANG_FLAG_2 (node))
660 fputs (" type_2", file);
661 if (TYPE_LANG_FLAG_3 (node))
662 fputs (" type_3", file);
663 if (TYPE_LANG_FLAG_4 (node))
664 fputs (" type_4", file);
665 if (TYPE_LANG_FLAG_5 (node))
666 fputs (" type_5", file);
667 if (TYPE_LANG_FLAG_6 (node))
668 fputs (" type_6", file);
669 if (TYPE_LANG_FLAG_7 (node))
670 fputs (" type_7", file);
672 mode = TYPE_MODE (node);
673 fprintf (file, " %s", GET_MODE_NAME (mode));
675 print_node (file, "size", TYPE_SIZE (node), indent + 4);
676 print_node (file, "unit-size", TYPE_SIZE_UNIT (node), indent + 4);
677 indent_to (file, indent + 3);
679 if (TYPE_USER_ALIGN (node))
680 fprintf (file, " user");
682 fprintf (file, " align:%d warn_if_not_align:%d symtab:%d alias-set "
683 HOST_WIDE_INT_PRINT_DEC,
684 TYPE_ALIGN (node), TYPE_WARN_IF_NOT_ALIGN (node),
685 TYPE_SYMTAB_ADDRESS (node),
686 (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
688 if (TYPE_STRUCTURAL_EQUALITY_P (node))
689 fprintf (file, " structural-equality");
690 else
691 dump_addr (file, " canonical-type ", TYPE_CANONICAL (node));
693 print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
695 if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
696 || code == FIXED_POINT_TYPE)
698 fprintf (file, " precision:%d", TYPE_PRECISION (node));
699 print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
700 print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
703 if (code == ENUMERAL_TYPE)
704 print_node (file, "values", TYPE_VALUES (node), indent + 4);
705 else if (code == ARRAY_TYPE)
706 print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
707 else if (code == VECTOR_TYPE)
709 fprintf (file, " nunits:");
710 print_dec (TYPE_VECTOR_SUBPARTS (node), file);
712 else if (code == RECORD_TYPE
713 || code == UNION_TYPE
714 || code == QUAL_UNION_TYPE)
715 print_node (file, "fields", TYPE_FIELDS (node), indent + 4);
716 else if (code == FUNCTION_TYPE
717 || code == METHOD_TYPE)
719 if (TYPE_METHOD_BASETYPE (node))
720 print_node_brief (file, "method basetype",
721 TYPE_METHOD_BASETYPE (node), indent + 4);
722 print_node (file, "arg-types", TYPE_ARG_TYPES (node), indent + 4);
724 else if (code == OFFSET_TYPE)
725 print_node_brief (file, "basetype", TYPE_OFFSET_BASETYPE (node),
726 indent + 4);
728 if (TYPE_CONTEXT (node))
729 print_node_brief (file, "context", TYPE_CONTEXT (node), indent + 4);
731 lang_hooks.print_type (file, node, indent);
733 if (TYPE_POINTER_TO (node) || TREE_CHAIN (node))
734 indent_to (file, indent + 3);
736 print_node_brief (file, "pointer_to_this", TYPE_POINTER_TO (node),
737 indent + 4);
738 print_node_brief (file, "reference_to_this", TYPE_REFERENCE_TO (node),
739 indent + 4);
740 print_node_brief (file, "chain", TREE_CHAIN (node), indent + 4);
741 break;
743 case tcc_expression:
744 case tcc_comparison:
745 case tcc_unary:
746 case tcc_binary:
747 case tcc_reference:
748 case tcc_statement:
749 case tcc_vl_exp:
750 if (code == BIND_EXPR)
752 print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
753 print_node (file, "body", TREE_OPERAND (node, 1), indent + 4);
754 print_node (file, "block", TREE_OPERAND (node, 2), indent + 4);
755 break;
757 if (code == CALL_EXPR)
759 print_node (file, "fn", CALL_EXPR_FN (node), indent + 4);
760 print_node (file, "static_chain", CALL_EXPR_STATIC_CHAIN (node),
761 indent + 4);
763 call_expr_arg_iterator iter;
764 init_call_expr_arg_iterator (node, &iter);
765 while (more_call_expr_args_p (&iter))
767 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
768 the text. */
769 char temp[15];
770 sprintf (temp, "arg:%u", iter.i);
771 tree arg = next_call_expr_arg (&iter);
772 if (arg)
773 print_node (file, temp, arg, indent + 4);
774 else
776 indent_to (file, indent + 4);
777 fprintf (file, "%s NULL", temp);
781 else
783 len = TREE_OPERAND_LENGTH (node);
785 for (i = 0; i < len; i++)
787 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
788 the text. */
789 char temp[16];
791 sprintf (temp, "arg:%d", i);
792 print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
795 if (CODE_CONTAINS_STRUCT (code, TS_COMMON))
796 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
797 break;
799 case tcc_constant:
800 case tcc_exceptional:
801 switch (code)
803 case INTEGER_CST:
804 if (TREE_OVERFLOW (node))
805 fprintf (file, " overflow");
807 fprintf (file, " ");
808 print_dec (wi::to_wide (node), file, TYPE_SIGN (TREE_TYPE (node)));
809 break;
811 case REAL_CST:
812 print_real_cst (file, node, false);
813 break;
815 case FIXED_CST:
817 FIXED_VALUE_TYPE f;
818 char string[64];
820 if (TREE_OVERFLOW (node))
821 fprintf (file, " overflow");
823 f = TREE_FIXED_CST (node);
824 fixed_to_decimal (string, &f, sizeof (string));
825 fprintf (file, " %s", string);
827 break;
829 case VECTOR_CST:
831 /* Big enough for UINT_MAX plus the string below. */
832 char buf[32];
834 fprintf (file, " npatterns:%u nelts-per-pattern:%u",
835 VECTOR_CST_NPATTERNS (node),
836 VECTOR_CST_NELTS_PER_PATTERN (node));
837 unsigned int count = vector_cst_encoded_nelts (node);
838 for (unsigned int i = 0; i < count; ++i)
840 sprintf (buf, "elt:%u: ", i);
841 print_node (file, buf, VECTOR_CST_ENCODED_ELT (node, i),
842 indent + 4);
845 break;
847 case COMPLEX_CST:
848 print_node (file, "real", TREE_REALPART (node), indent + 4);
849 print_node (file, "imag", TREE_IMAGPART (node), indent + 4);
850 break;
852 case STRING_CST:
854 const char *p = TREE_STRING_POINTER (node);
855 int i = TREE_STRING_LENGTH (node);
856 fputs (" \"", file);
857 while (--i >= 0)
859 char ch = *p++;
860 if (ch >= ' ' && ch < 127)
861 putc (ch, file);
862 else
863 fprintf (file, "\\%03o", ch & 0xFF);
865 fputc ('\"', file);
867 break;
869 case POLY_INT_CST:
871 char buf[10];
872 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
874 snprintf (buf, sizeof (buf), "elt%u:", i);
875 print_node (file, buf, POLY_INT_CST_COEFF (node, i),
876 indent + 4);
879 break;
881 case IDENTIFIER_NODE:
882 lang_hooks.print_identifier (file, node, indent);
883 break;
885 case TREE_LIST:
886 print_node (file, "purpose", TREE_PURPOSE (node), indent + 4);
887 print_node (file, "value", TREE_VALUE (node), indent + 4);
888 print_node (file, "chain", TREE_CHAIN (node), indent + 4);
889 break;
891 case TREE_VEC:
892 len = TREE_VEC_LENGTH (node);
893 fprintf (file, " length:%d", len);
894 for (i = 0; i < len; i++)
895 if (TREE_VEC_ELT (node, i))
897 /* Buffer big enough to format a 32-bit UINT_MAX into, plus
898 the text. */
899 char temp[16];
900 sprintf (temp, "elt:%d", i);
901 print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
903 break;
905 case CONSTRUCTOR:
907 unsigned HOST_WIDE_INT cnt;
908 tree index, value;
909 len = CONSTRUCTOR_NELTS (node);
910 fprintf (file, " length:%d", len);
911 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
912 cnt, index, value)
914 print_node (file, "idx", index, indent + 4, false);
915 print_node (file, "val", value, indent + 4, false);
918 break;
920 case STATEMENT_LIST:
921 dump_addr (file, " head ", node->stmt_list.head);
922 dump_addr (file, " tail ", node->stmt_list.tail);
923 fprintf (file, " stmts");
925 tree_stmt_iterator i;
926 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
928 /* Not printing the addresses of the (not-a-tree)
929 'struct tree_stmt_list_node's. */
930 dump_addr (file, " ", tsi_stmt (i));
932 fprintf (file, "\n");
933 for (i = tsi_start (node); !tsi_end_p (i); tsi_next (&i))
935 /* Not printing the addresses of the (not-a-tree)
936 'struct tree_stmt_list_node's. */
937 print_node (file, "stmt", tsi_stmt (i), indent + 4);
940 break;
942 case BLOCK:
943 print_node (file, "vars", BLOCK_VARS (node), indent + 4);
944 print_node (file, "supercontext", BLOCK_SUPERCONTEXT (node),
945 indent + 4);
946 print_node (file, "subblocks", BLOCK_SUBBLOCKS (node), indent + 4);
947 print_node (file, "chain", BLOCK_CHAIN (node), indent + 4);
948 print_node (file, "abstract_origin",
949 BLOCK_ABSTRACT_ORIGIN (node), indent + 4);
950 break;
952 case SSA_NAME:
953 print_node_brief (file, "var", SSA_NAME_VAR (node), indent + 4);
954 indent_to (file, indent + 4);
955 fprintf (file, "def_stmt ");
957 pretty_printer buffer;
958 buffer.buffer->stream = file;
959 pp_gimple_stmt_1 (&buffer, SSA_NAME_DEF_STMT (node), indent + 4,
960 TDF_NONE);
961 pp_flush (&buffer);
964 indent_to (file, indent + 4);
965 fprintf (file, "version:%u", SSA_NAME_VERSION (node));
966 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
967 fprintf (file, " in-abnormal-phi");
968 if (SSA_NAME_IN_FREE_LIST (node))
969 fprintf (file, " in-free-list");
971 if (SSA_NAME_PTR_INFO (node))
973 indent_to (file, indent + 3);
974 if (SSA_NAME_PTR_INFO (node))
975 dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
977 break;
979 case OMP_CLAUSE:
981 int i;
982 fprintf (file, " %s",
983 omp_clause_code_name[OMP_CLAUSE_CODE (node)]);
984 for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
986 indent_to (file, indent + 4);
987 fprintf (file, "op-%d:", i);
988 print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
991 break;
993 case OPTIMIZATION_NODE:
994 cl_optimization_print (file, indent + 4, TREE_OPTIMIZATION (node));
995 break;
997 case TARGET_OPTION_NODE:
998 cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
999 break;
1000 case IMPORTED_DECL:
1001 fprintf (file, " imported-declaration");
1002 print_node_brief (file, "associated-declaration",
1003 IMPORTED_DECL_ASSOCIATED_DECL (node),
1004 indent + 4);
1005 break;
1007 case TREE_BINFO:
1008 fprintf (file, " bases:%d",
1009 vec_safe_length (BINFO_BASE_BINFOS (node)));
1010 print_node_brief (file, "offset", BINFO_OFFSET (node), indent + 4);
1011 print_node_brief (file, "virtuals", BINFO_VIRTUALS (node),
1012 indent + 4);
1013 print_node_brief (file, "inheritance-chain",
1014 BINFO_INHERITANCE_CHAIN (node),
1015 indent + 4);
1016 break;
1018 default:
1019 lang_hooks.print_xnode (file, node, indent);
1020 break;
1023 break;
1026 if (EXPR_HAS_LOCATION (node))
1028 expanded_location xloc = expand_location (EXPR_LOCATION (node));
1029 indent_to (file, indent+4);
1030 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
1032 /* Print the range, if any */
1033 source_range r = EXPR_LOCATION_RANGE (node);
1034 if (r.m_start)
1036 xloc = expand_location (r.m_start);
1037 fprintf (file, " start: %s:%d:%d", xloc.file, xloc.line, xloc.column);
1039 else
1041 fprintf (file, " start: unknown");
1043 if (r.m_finish)
1045 xloc = expand_location (r.m_finish);
1046 fprintf (file, " finish: %s:%d:%d", xloc.file, xloc.line, xloc.column);
1048 else
1050 fprintf (file, " finish: unknown");
1054 fprintf (file, ">");
1057 /* Print the identifier for DECL according to FLAGS. */
1059 void
1060 print_decl_identifier (FILE *file, tree decl, int flags)
1062 bool needs_colon = false;
1063 const char *name;
1064 char c;
1066 if (flags & PRINT_DECL_ORIGIN)
1068 if (DECL_IS_UNDECLARED_BUILTIN (decl))
1069 fputs ("<built-in>", file);
1070 else
1072 expanded_location loc
1073 = expand_location (DECL_SOURCE_LOCATION (decl));
1074 const char *f = flags & PRINT_DECL_REMAP_DEBUG
1075 ? remap_debug_filename (loc.file)
1076 : loc.file;
1077 fprintf (file, "%s:%d:%d", f, loc.line, loc.column);
1079 needs_colon = true;
1082 if (flags & PRINT_DECL_UNIQUE_NAME)
1084 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1085 if (!TREE_PUBLIC (decl)
1086 || (DECL_WEAK (decl) && !DECL_EXTERNAL (decl)))
1087 /* The symbol has internal or weak linkage so its assembler name
1088 is not necessarily unique among the compilation units of the
1089 program. We therefore have to further mangle it. But we can't
1090 simply use DECL_SOURCE_FILE because it contains the name of the
1091 file the symbol originates from so, e.g. for function templates
1092 in C++ where the templates are defined in a header file, we can
1093 have symbols with the same assembler name and DECL_SOURCE_FILE.
1094 That's why we use the name of the top-level source file of the
1095 compilation unit. ??? Unnecessary for Ada. */
1096 name = ACONCAT ((main_input_filename, ":", name, NULL));
1098 else if (flags & PRINT_DECL_NAME)
1100 /* We don't want to print the full qualified name because it can be long,
1101 so we strip the scope prefix, but we may need to deal with the suffix
1102 created by the compiler. */
1103 const char *suffix = strchr (IDENTIFIER_POINTER (DECL_NAME (decl)), '.');
1104 name = lang_hooks.decl_printable_name (decl, 2);
1105 if (suffix)
1107 const char *dot = strchr (name, '.');
1108 while (dot && strcasecmp (dot, suffix) != 0)
1110 name = dot + 1;
1111 dot = strchr (name, '.');
1114 else
1116 const char *dot = strrchr (name, '.');
1117 if (dot)
1118 name = dot + 1;
1121 else
1122 return;
1124 if (needs_colon)
1125 fputc (':', file);
1127 while ((c = *name++) != '\0')
1129 /* Strip double-quotes because of VCG. */
1130 if (c == '"')
1131 continue;
1132 fputc (c, file);
1137 /* Print the node NODE on standard error, for debugging.
1138 Most nodes referred to by this one are printed recursively
1139 down to a depth of six. */
1141 DEBUG_FUNCTION void
1142 debug_tree (tree node)
1144 table = new hash_set<tree> (HASH_SIZE);
1145 print_node (stderr, "", node, 0);
1146 delete table;
1147 table = NULL;
1148 putc ('\n', stderr);
1151 DEBUG_FUNCTION void
1152 debug_raw (const tree_node &ref)
1154 debug_tree (const_cast <tree> (&ref));
1157 DEBUG_FUNCTION void
1158 debug_raw (const tree_node *ptr)
1160 if (ptr)
1161 debug_raw (*ptr);
1162 else
1163 fprintf (stderr, "<nil>\n");
1166 static void
1167 dump_tree_via_hooks (const tree_node *ptr, dump_flags_t options)
1169 if (DECL_P (ptr))
1170 lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
1171 else if (TYPE_P (ptr))
1172 lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
1173 else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
1174 lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
1175 else
1176 print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
1177 fprintf (stderr, "\n");
1180 DEBUG_FUNCTION void
1181 debug (const tree_node &ref)
1183 dump_tree_via_hooks (&ref, TDF_NONE);
1186 DEBUG_FUNCTION void
1187 debug (const tree_node *ptr)
1189 if (ptr)
1190 debug (*ptr);
1191 else
1192 fprintf (stderr, "<nil>\n");
1195 DEBUG_FUNCTION void
1196 debug_head (const tree_node &ref)
1198 debug (ref);
1201 DEBUG_FUNCTION void
1202 debug_head (const tree_node *ptr)
1204 if (ptr)
1205 debug_head (*ptr);
1206 else
1207 fprintf (stderr, "<nil>\n");
1210 DEBUG_FUNCTION void
1211 debug_body (const tree_node &ref)
1213 if (TREE_CODE (&ref) == FUNCTION_DECL)
1214 dump_function_to_file (const_cast <tree_node*> (&ref), stderr, TDF_NONE);
1215 else
1216 debug (ref);
1219 DEBUG_FUNCTION void
1220 debug_body (const tree_node *ptr)
1222 if (ptr)
1223 debug_body (*ptr);
1224 else
1225 fprintf (stderr, "<nil>\n");
1228 /* Print the vector of trees VEC on standard error, for debugging.
1229 Most nodes referred to by this one are printed recursively
1230 down to a depth of six. */
1232 DEBUG_FUNCTION void
1233 debug_raw (vec<tree, va_gc> &ref)
1235 tree elt;
1236 unsigned ix;
1238 /* Print the slot this node is in, and its code, and address. */
1239 fprintf (stderr, "<VEC");
1240 dump_addr (stderr, " ", ref.address ());
1242 FOR_EACH_VEC_ELT (ref, ix, elt)
1244 fprintf (stderr, "elt:%d ", ix);
1245 debug_raw (elt);
1249 DEBUG_FUNCTION void
1250 debug_raw (vec<tree, va_gc> *ptr)
1252 if (ptr)
1253 debug_raw (*ptr);
1254 else
1255 fprintf (stderr, "<nil>\n");
1258 static void
1259 debug_slim (tree t)
1261 print_node_brief (stderr, "", t, 0);
1264 DEFINE_DEBUG_VEC (tree)
1265 DEFINE_DEBUG_HASH_SET (tree)