re PR target/66274 (gcc6: x86 -m32 emits 64bit register in inline asm)
[gcc.git] / gcc / print-tree.c
index 3b5edebed62d448fde73e0b5521e1bdbbbab66a9..6b36d0294bb8ed3107a0484b74a55c8c06c13ebf 100644 (file)
@@ -1,7 +1,5 @@
 /* Prints out tree in human readable form - GCC
-   Copyright (C) 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-   Free Software Foundation, Inc.
+   Copyright (C) 1990-2015 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -24,14 +22,38 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "vec.h"
+#include "double-int.h"
+#include "input.h"
+#include "alias.h"
+#include "symtab.h"
+#include "wide-int.h"
+#include "inchash.h"
+#include "real.h"
+#include "fixed-value.h"
 #include "tree.h"
+#include "varasm.h"
+#include "print-rtl.h"
+#include "stor-layout.h"
 #include "ggc.h"
 #include "langhooks.h"
 #include "tree-iterator.h"
 #include "diagnostic.h"
-#include "gimple-pretty-print.h"
-#include "tree-flow.h"
-#include "tree-pass.h"
+#include "gimple-pretty-print.h" /* FIXME */
+#include "hash-map.h"
+#include "is-a.h"
+#include "plugin-api.h"
+#include "hard-reg-set.h"
+#include "input.h"
+#include "function.h"
+#include "ipa-ref.h"
+#include "cgraph.h"
+#include "tree-cfg.h"
+#include "tree-dump.h"
+#include "dumpfile.h"
+#include "wide-int-print.h"
 
 /* Define the hash table of nodes already seen.
    Such nodes are not repeated; brief cross-references are used.  */
@@ -46,34 +68,6 @@ struct bucket
 
 static struct bucket **table;
 
-/* Print the node NODE on standard error, for debugging.
-   Most nodes referred to by this one are printed recursively
-   down to a depth of six.  */
-
-DEBUG_FUNCTION void
-debug_tree (tree node)
-{
-  table = XCNEWVEC (struct bucket *, HASH_SIZE);
-  print_node (stderr, "", node, 0);
-  free (table);
-  table = 0;
-  putc ('\n', stderr);
-}
-
-/* Print the vector of trees VEC on standard error, for debugging.
-   Most nodes referred to by this one are printed recursively
-   down to a depth of six.  */
-
-DEBUG_FUNCTION void
-debug_vec_tree (VEC(tree,gc) *vec)
-{
-  table = XCNEWVEC (struct bucket *, HASH_SIZE);
-  print_vec_tree (stderr, "", vec, 0);
-  free (table);
-  table = 0;
-  putc ('\n', stderr);
-}
-
 /* Print PREFIX and ADDR to FILE.  */
 void
 dump_addr (FILE *file, const char *prefix, const void *addr)
@@ -100,7 +94,7 @@ print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
      name if any.  */
   if (indent > 0)
     fprintf (file, " ");
-  fprintf (file, "%s <%s", prefix, tree_code_name[(int) TREE_CODE (node)]);
+  fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
   dump_addr (file, " ", node);
 
   if (tclass == tcc_declaration)
@@ -150,16 +144,7 @@ print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
        fprintf (file, " overflow");
 
       fprintf (file, " ");
-      if (TREE_INT_CST_HIGH (node) == 0)
-       fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED, TREE_INT_CST_LOW (node));
-      else if (TREE_INT_CST_HIGH (node) == -1
-              && TREE_INT_CST_LOW (node) != 0)
-       fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
-                -TREE_INT_CST_LOW (node));
-      else
-       fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
-                (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
-                (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
+      print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
     }
   if (TREE_CODE (node) == REAL_CST)
     {
@@ -216,7 +201,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
 {
   int hash;
   struct bucket *b;
-  enum machine_mode mode;
+  machine_mode mode;
   enum tree_code_class tclass;
   int len;
   int i;
@@ -255,7 +240,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
   /* Allow this function to be called if the table is not there.  */
   if (table)
     {
-      hash = ((unsigned long) node) % HASH_SIZE;
+      hash = ((uintptr_t) node) % HASH_SIZE;
 
       /* If node is in the table, just mention its address.  */
       for (b = table[hash]; b; b = b->next)
@@ -276,7 +261,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
   indent_to (file, indent);
 
   /* Print the slot this node is in, and its code, and address.  */
-  fprintf (file, "%s <%s", prefix, tree_code_name[(int) code]);
+  fprintf (file, "%s <%s", prefix, get_tree_code_name (code));
   dump_addr (file, " ", node);
 
   /* Print the name, if any.  */
@@ -321,7 +306,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
       if (indent <= 4)
        print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
     }
-  else
+  else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
     {
       print_node (file, "type", TREE_TYPE (node), indent + 4);
       if (TREE_TYPE (node))
@@ -333,6 +318,8 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
 
   if (TYPE_P (node) ? TYPE_READONLY (node) : TREE_READONLY (node))
     fputs (" readonly", file);
+  if (TYPE_P (node) && TYPE_ATOMIC (node))
+    fputs (" atomic", file);
   if (!TYPE_P (node) && TREE_CONSTANT (node))
     fputs (" constant", file);
   else if (TYPE_P (node) && TYPE_SIZES_GIMPLIFIED (node))
@@ -363,20 +350,24 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
     fputs (" deprecated", file);
   if (TREE_VISITED (node))
     fputs (" visited", file);
-  if (TREE_LANG_FLAG_0 (node))
-    fputs (" tree_0", file);
-  if (TREE_LANG_FLAG_1 (node))
-    fputs (" tree_1", file);
-  if (TREE_LANG_FLAG_2 (node))
-    fputs (" tree_2", file);
-  if (TREE_LANG_FLAG_3 (node))
-    fputs (" tree_3", file);
-  if (TREE_LANG_FLAG_4 (node))
-    fputs (" tree_4", file);
-  if (TREE_LANG_FLAG_5 (node))
-    fputs (" tree_5", file);
-  if (TREE_LANG_FLAG_6 (node))
-    fputs (" tree_6", file);
+
+  if (code != TREE_VEC && code != INTEGER_CST && code != SSA_NAME)
+    {
+      if (TREE_LANG_FLAG_0 (node))
+       fputs (" tree_0", file);
+      if (TREE_LANG_FLAG_1 (node))
+       fputs (" tree_1", file);
+      if (TREE_LANG_FLAG_2 (node))
+       fputs (" tree_2", file);
+      if (TREE_LANG_FLAG_3 (node))
+       fputs (" tree_3", file);
+      if (TREE_LANG_FLAG_4 (node))
+       fputs (" tree_4", file);
+      if (TREE_LANG_FLAG_5 (node))
+       fputs (" tree_5", file);
+      if (TREE_LANG_FLAG_6 (node))
+       fputs (" tree_6", file);
+    }
 
   /* DECL_ nodes have additional attributes.  */
 
@@ -389,7 +380,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
            fputs (" unsigned", file);
          if (DECL_IGNORED_P (node))
            fputs (" ignored", file);
-         if (DECL_ABSTRACT (node))
+         if (DECL_ABSTRACT_P (node))
            fputs (" abstract", file);
          if (DECL_EXTERNAL (node))
            fputs (" external", file);
@@ -424,6 +415,8 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
        fputs (" built-in", file);
       if (code == FUNCTION_DECL && DECL_STATIC_CHAIN (node))
        fputs (" static-chain", file);
+      if (TREE_CODE (node) == FUNCTION_DECL && decl_is_tm_clone (node))
+       fputs (" tm-clone", file);
 
       if (code == FIELD_DECL && DECL_PACKED (node))
        fputs (" packed", file);
@@ -432,8 +425,6 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
       if (code == FIELD_DECL && DECL_NONADDRESSABLE_P (node))
        fputs (" nonaddressable", file);
 
-      if (code == LABEL_DECL && DECL_ERROR_ISSUED (node))
-       fputs (" error-issued", file);
       if (code == LABEL_DECL && EH_LANDING_PAD_NR (node))
        fprintf (file, " landing-pad:%d", EH_LANDING_PAD_NR (node));
 
@@ -445,24 +436,8 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
        fputs (" common", file);
       if (code == VAR_DECL && DECL_THREAD_LOCAL_P (node))
        {
-         enum tls_model kind = DECL_TLS_MODEL (node);
-         switch (kind)
-           {
-             case TLS_MODEL_GLOBAL_DYNAMIC:
-               fputs (" tls-global-dynamic", file);
-               break;
-             case TLS_MODEL_LOCAL_DYNAMIC:
-               fputs (" tls-local-dynamic", file);
-               break;
-             case TLS_MODEL_INITIAL_EXEC:
-               fputs (" tls-initial-exec", file);
-               break;
-             case TLS_MODEL_LOCAL_EXEC:
-               fputs (" tls-local-exec", file);
-               break;
-             default:
-               gcc_unreachable ();
-           }
+         fputs (" ", file);
+         fputs (tls_model_names[DECL_TLS_MODEL (node)], file);
        }
 
       if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
@@ -557,7 +532,6 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
        }
       if (CODE_CONTAINS_STRUCT (code, TS_DECL_NON_COMMON))
        {
-         print_node (file, "arguments", DECL_ARGUMENT_FLD (node), indent + 4);
          print_node (file, "result", DECL_RESULT_FLD (node), indent + 4);
        }
 
@@ -583,6 +557,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
       else if (code == FUNCTION_DECL
               && DECL_STRUCT_FUNCTION (node) != 0)
        {
+         print_node (file, "arguments", DECL_ARGUMENTS (node), indent + 4);
          indent_to (file, indent + 4);
          dump_addr (file, "struct-function ", DECL_STRUCT_FUNCTION (node));
        }
@@ -602,19 +577,12 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
       if (TYPE_UNSIGNED (node))
        fputs (" unsigned", file);
 
-      /* The no-force-blk flag is used for different things in
-        different types.  */
-      if ((code == RECORD_TYPE
-          || code == UNION_TYPE
-          || code == QUAL_UNION_TYPE)
-         && TYPE_NO_FORCE_BLK (node))
+      if (TYPE_NO_FORCE_BLK (node))
        fputs (" no-force-blk", file);
-      else if (code == INTEGER_TYPE
-              && TYPE_IS_SIZETYPE (node))
-       fputs (" sizetype", file);
 
       if (TYPE_STRING_FLAG (node))
        fputs (" string-flag", file);
+
       if (TYPE_NEEDS_CONSTRUCTING (node))
        fputs (" needs-constructing", file);
 
@@ -769,17 +737,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
            fprintf (file, " overflow");
 
          fprintf (file, " ");
-         if (TREE_INT_CST_HIGH (node) == 0)
-           fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED,
-                    TREE_INT_CST_LOW (node));
-         else if (TREE_INT_CST_HIGH (node) == -1
-                  && TREE_INT_CST_LOW (node) != 0)
-           fprintf (file, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
-                    -TREE_INT_CST_LOW (node));
-         else
-           fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
-                    (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (node),
-                    (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (node));
+         print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
          break;
 
        case REAL_CST:
@@ -819,16 +777,13 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
 
        case VECTOR_CST:
          {
-           tree vals = TREE_VECTOR_CST_ELTS (node);
            char buf[10];
-           tree link;
-           int i;
+           unsigned i;
 
-           i = 0;
-           for (link = vals; link; link = TREE_CHAIN (link), ++i)
+           for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
              {
-               sprintf (buf, "elt%d: ", i);
-               print_node (file, buf, TREE_VALUE (link), indent + 4);
+               sprintf (buf, "elt%u: ", i);
+               print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
              }
          }
          break;
@@ -849,7 +804,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
                if (ch >= ' ' && ch < 127)
                  putc (ch, file);
                else
-                 fprintf(file, "\\%03o", ch & 0xFF);
+                 fprintf (file, "\\%03o", ch & 0xFF);
              }
            fputc ('\"', file);
          }
@@ -880,7 +835,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
          {
            unsigned HOST_WIDE_INT cnt;
            tree index, value;
-           len = VEC_length (constructor_elt, CONSTRUCTOR_ELTS (node));
+           len = vec_safe_length (CONSTRUCTOR_ELTS (node));
            fprintf (file, " lngt %d", len);
            FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
                                      cnt, index, value)
@@ -911,7 +866,6 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
                print_node (file, "stmt", tsi_stmt (i), indent + 4);
              }
          }
-         print_node (file, "chain", TREE_CHAIN (node), indent + 4);
          break;
 
        case BLOCK:
@@ -991,26 +945,171 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
   fprintf (file, ">");
 }
 
-/* Print the tree vector VEC in full on file FILE, preceded by PREFIX,
-   starting in column INDENT.  */
 
-void
-print_vec_tree (FILE *file, const char *prefix, VEC(tree,gc) *vec, int indent)
+/* Print the node NODE on standard error, for debugging.
+   Most nodes referred to by this one are printed recursively
+   down to a depth of six.  */
+
+DEBUG_FUNCTION void
+debug_tree (tree node)
+{
+  table = XCNEWVEC (struct bucket *, HASH_SIZE);
+  print_node (stderr, "", node, 0);
+  free (table);
+  table = 0;
+  putc ('\n', stderr);
+}
+
+DEBUG_FUNCTION void
+debug_raw (const tree_node &ref)
+{
+  debug_tree (const_cast <tree> (&ref));
+}
+
+DEBUG_FUNCTION void
+debug_raw (const tree_node *ptr)
+{
+  if (ptr)
+    debug_raw (*ptr);
+  else
+    fprintf (stderr, "<nil>\n");
+}
+
+static void
+dump_tree_via_hooks (const tree_node *ptr, int options)
+{
+  if (DECL_P (ptr))
+    lang_hooks.print_decl (stderr, const_cast <tree_node*> (ptr), 0);
+  else if (TYPE_P (ptr))
+    lang_hooks.print_type (stderr, const_cast <tree_node*> (ptr), 0);
+  else if (TREE_CODE (ptr) == IDENTIFIER_NODE)
+    lang_hooks.print_identifier (stderr, const_cast <tree_node*> (ptr), 0);
+  else
+    print_generic_expr (stderr, const_cast <tree_node*> (ptr), options);
+  fprintf (stderr, "\n");
+}
+
+DEBUG_FUNCTION void
+debug (const tree_node &ref)
+{
+  dump_tree_via_hooks (&ref, 0);
+}
+
+DEBUG_FUNCTION void
+debug (const tree_node *ptr)
+{
+  if (ptr)
+    debug (*ptr);
+  else
+    fprintf (stderr, "<nil>\n");
+}
+
+DEBUG_FUNCTION void
+debug_verbose (const tree_node &ref)
+{
+  dump_tree_via_hooks (&ref, TDF_VERBOSE);
+}
+
+DEBUG_FUNCTION void
+debug_verbose (const tree_node *ptr)
+{
+  if (ptr)
+    debug_verbose (*ptr);
+  else
+    fprintf (stderr, "<nil>\n");
+}
+
+DEBUG_FUNCTION void
+debug_head (const tree_node &ref)
+{
+  debug (ref);
+}
+
+DEBUG_FUNCTION void
+debug_head (const tree_node *ptr)
+{
+  if (ptr)
+    debug_head (*ptr);
+  else
+    fprintf (stderr, "<nil>\n");
+}
+
+DEBUG_FUNCTION void
+debug_body (const tree_node &ref)
+{
+  if (TREE_CODE (&ref) == FUNCTION_DECL)
+    dump_function_to_file (const_cast <tree_node*> (&ref), stderr, 0);
+  else
+    debug (ref);
+}
+
+DEBUG_FUNCTION void
+debug_body (const tree_node *ptr)
+{
+  if (ptr)
+    debug_body (*ptr);
+  else
+    fprintf (stderr, "<nil>\n");
+}
+
+/* Print the vector of trees VEC on standard error, for debugging.
+   Most nodes referred to by this one are printed recursively
+   down to a depth of six.  */
+
+DEBUG_FUNCTION void
+debug_raw (vec<tree, va_gc> &ref)
 {
   tree elt;
   unsigned ix;
 
-  /* Indent to the specified column, since this is the long form.  */
-  indent_to (file, indent);
+  /* Print the slot this node is in, and its code, and address.  */
+  fprintf (stderr, "<VEC");
+  dump_addr (stderr, " ", ref.address ());
+
+  FOR_EACH_VEC_ELT (ref, ix, elt)
+    {
+      fprintf (stderr, "elt %d ", ix);
+      debug_raw (elt);
+    }
+}
+
+DEBUG_FUNCTION void
+debug (vec<tree, va_gc> &ref)
+{
+  tree elt;
+  unsigned ix;
 
   /* Print the slot this node is in, and its code, and address.  */
-  fprintf (file, "%s <VEC", prefix);
-  dump_addr (file, " ", vec);
+  fprintf (stderr, "<VEC");
+  dump_addr (stderr, " ", ref.address ());
 
-  FOR_EACH_VEC_ELT (tree, vec, ix, elt)
+  FOR_EACH_VEC_ELT (ref, ix, elt)
     {
-      char temp[10];
-      sprintf (temp, "elt %d", ix);
-      print_node (file, temp, elt, indent + 4);
+      fprintf (stderr, "elt %d ", ix);
+      debug (elt);
     }
 }
+
+DEBUG_FUNCTION void
+debug (vec<tree, va_gc> *ptr)
+{
+  if (ptr)
+    debug (*ptr);
+  else
+    fprintf (stderr, "<nil>\n");
+}
+
+DEBUG_FUNCTION void
+debug_raw (vec<tree, va_gc> *ptr)
+{
+  if (ptr)
+    debug_raw (*ptr);
+  else
+    fprintf (stderr, "<nil>\n");
+}
+
+DEBUG_FUNCTION void
+debug_vec_tree (vec<tree, va_gc> *vec)
+{
+  debug_raw (vec);
+}