]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/lto-streamer.c
Update copyright years.
[thirdparty/gcc.git] / gcc / lto-streamer.c
index 01a681fbd183c280b96ab6a8059b5e859fd7e834..f7d3f24b0b19dc032638ac4f7900a003f278c15f 100644 (file)
@@ -1,7 +1,7 @@
 /* Miscellaneous utilities for GIMPLE streaming.  Things that are used
    in both input and output are here.
 
-   Copyright 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2009-2020 Free Software Foundation, Inc.
    Contributed by Doug Kwan <dougkwan@google.com>
 
 This file is part of GCC.
@@ -23,27 +23,23 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
-#include "toplev.h"
-#include "flags.h"
+#include "backend.h"
 #include "tree.h"
 #include "gimple.h"
-#include "tree-flow.h"
-#include "diagnostic-core.h"
-#include "bitmap.h"
-#include "vec.h"
 #include "tree-streamer.h"
+#include "cgraph.h"
 #include "lto-streamer.h"
-#include "streamer-hooks.h"
+#include "toplev.h"
+#include "lto-section-names.h"
 
 /* Statistics gathered during LTO, WPA and LTRANS.  */
 struct lto_stats_d lto_stats;
 
-/* LTO uses bitmaps with different life-times.  So use a seperate
-   obstack for all LTO bitmaps.  */
-static bitmap_obstack lto_obstack;
-static bool lto_obstack_initialized;
+const char *section_name_prefix = LTO_SECTION_NAME_PREFIX;
+/* Set when streaming LTO for offloading compiler.  */
+bool lto_stream_offload_p;
 
+FILE *streamer_dump_file;
 
 /* Return a string representing LTO tag TAG.  */
 
@@ -54,7 +50,7 @@ lto_tag_name (enum LTO_tags tag)
     {
       /* For tags representing tree nodes, return the name of the
         associated tree code.  */
-      return tree_code_name[lto_tag_to_tree_code (tag)];
+      return get_tree_code_name (lto_tag_to_tree_code (tag));
     }
 
   if (lto_tag_is_gimple_code_p (tag))
@@ -112,35 +108,14 @@ lto_tag_name (enum LTO_tags tag)
 }
 
 
-/* Allocate a bitmap from heap.  Initializes the LTO obstack if necessary.  */
-
-bitmap
-lto_bitmap_alloc (void)
-{
-  if (!lto_obstack_initialized)
-    {
-      bitmap_obstack_initialize (&lto_obstack);
-      lto_obstack_initialized = true;
-    }
-  return BITMAP_ALLOC (&lto_obstack);
-}
-
-/* Free bitmap B.  */
-
-void
-lto_bitmap_free (bitmap b)
-{
-  BITMAP_FREE (b);
-}
-
-
 /* Get a section name for a particular type or name.  The NAME field
    is only used if SECTION_TYPE is LTO_section_function_body. For all
    others it is ignored.  The callee of this function is responsible
    to free the returned name.  */
 
 char *
-lto_get_section_name (int section_type, const char *name, struct lto_file_decl_data *f)
+lto_get_section_name (int section_type, const char *name,
+                     int node_order, struct lto_file_decl_data *f)
 {
   const char *add;
   char post[32];
@@ -151,7 +126,11 @@ lto_get_section_name (int section_type, const char *name, struct lto_file_decl_d
       gcc_assert (name != NULL);
       if (name[0] == '*')
        name++;
-      add = name;
+
+      char *buffer = (char *)xmalloc (strlen (name) + 32);
+      sprintf (buffer, "%s.%d", name, node_order);
+
+      add = buffer;
       sep = "";
     }
   else if (section_type < LTO_N_SECTION_TYPES)
@@ -166,26 +145,24 @@ lto_get_section_name (int section_type, const char *name, struct lto_file_decl_d
      doesn't confuse the reader with merged sections.
 
      For options don't add a ID, the option reader cannot deal with them
-     and merging should be ok here.
-
-     XXX: use crc64 to minimize collisions? */
+     and merging should be ok here. */
   if (section_type == LTO_section_opts)
     strcpy (post, "");
+  else if (f != NULL) 
+    sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE, f->id);
   else
-    sprintf (post, ".%x", f ? f->id : crc32_string(0, get_random_seed (false)));
-  return concat (LTO_SECTION_NAME_PREFIX, sep, add, post, NULL);
+    sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE, get_random_seed (false)); 
+  return concat (section_name_prefix, sep, add, post, NULL);
 }
 
 
 /* Show various memory usage statistics related to LTO.  */
 
 void
-print_lto_report (void)
+print_lto_report (const char *s)
 {
-  const char *s = (flag_lto) ? "LTO" : (flag_wpa) ? "WPA" : "LTRANS";
   unsigned i;
 
-  fprintf (stderr, "%s statistics\n", s);
   fprintf (stderr, "[%s] # of input files: "
           HOST_WIDE_INT_PRINT_UNSIGNED "\n", s, lto_stats.num_input_files);
 
@@ -197,14 +174,11 @@ print_lto_report (void)
           HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
           lto_stats.num_function_bodies);
 
-  fprintf (stderr, "[%s] ", s);
-  print_gimple_types_stats ();
-
   for (i = 0; i < NUM_TREE_CODES; i++)
     if (lto_stats.num_trees[i])
       fprintf (stderr, "[%s] # of '%s' objects read: "
               HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
-              tree_code_name[i], lto_stats.num_trees[i]);
+              get_tree_code_name ((enum tree_code) i), lto_stats.num_trees[i]);
 
   if (flag_lto)
     {
@@ -228,9 +202,16 @@ print_lto_report (void)
               HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
               lto_stats.num_output_files);
 
-      fprintf (stderr, "[%s] # of output cgraph nodes: "
+      fprintf (stderr, "[%s] # of output symtab nodes: "
               HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
-              lto_stats.num_output_cgraph_nodes);
+              lto_stats.num_output_symtab_nodes);
+
+      fprintf (stderr, "[%s] # of output tree pickle references: "
+              HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
+              lto_stats.num_pickle_refs_output);
+      fprintf (stderr, "[%s] # of output tree bodies: "
+              HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
+              lto_stats.num_tree_bodies_output);
 
       fprintf (stderr, "[%s] # callgraph partitions: "
               HOST_WIDE_INT_PRINT_UNSIGNED "\n", s,
@@ -256,32 +237,6 @@ print_lto_report (void)
             lto_section_name[i], lto_stats.section_size[i]);
 }
 
-
-#ifdef LTO_STREAMER_DEBUG
-static htab_t tree_htab;
-
-struct tree_hash_entry
-{
-  tree key;
-  intptr_t value;
-};
-
-static hashval_t
-hash_tree (const void *p)
-{
-  const struct tree_hash_entry *e = (const struct tree_hash_entry *) p;
-  return htab_hash_pointer (e->key);
-}
-
-static int
-eq_tree (const void *p1, const void *p2)
-{
-  const struct tree_hash_entry *e1 = (const struct tree_hash_entry *) p1;
-  const struct tree_hash_entry *e2 = (const struct tree_hash_entry *) p2;
-  return (e1->key == e2->key);
-}
-#endif
-
 /* Initialization common to the LTO reader and writer.  */
 
 void
@@ -291,11 +246,8 @@ lto_streamer_init (void)
      match exactly the structures defined in treestruct.def.  When a
      new TS_* astructure is added, the streamer should be updated to
      handle it.  */
-  check_handled_ts_structures ();
-
-#ifdef LTO_STREAMER_DEBUG
-  tree_htab = htab_create (31, hash_tree, eq_tree, NULL);
-#endif
+  if (flag_checking)
+    streamer_check_handled_ts_structures ();
 }
 
 
@@ -304,81 +256,21 @@ lto_streamer_init (void)
 bool
 gate_lto_out (void)
 {
-  return ((flag_generate_lto || in_lto_p)
+  return ((flag_generate_lto || flag_generate_offload || in_lto_p)
          /* Don't bother doing anything if the program has errors.  */
          && !seen_error ());
 }
 
-
-#ifdef LTO_STREAMER_DEBUG
-/* Add a mapping between T and ORIG_T, which is the numeric value of
-   the original address of T as it was seen by the LTO writer.  This
-   mapping is useful when debugging streaming problems.  A debugging
-   session can be started on both reader and writer using ORIG_T
-   as a breakpoint value in both sessions.
-
-   Note that this mapping is transient and only valid while T is
-   being reconstructed.  Once T is fully built, the mapping is
-   removed.  */
-
-void
-lto_orig_address_map (tree t, intptr_t orig_t)
-{
-  struct tree_hash_entry ent;
-  struct tree_hash_entry **slot;
-
-  ent.key = t;
-  ent.value = orig_t;
-  slot
-    = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, INSERT);
-  gcc_assert (!*slot);
-  *slot = XNEW (struct tree_hash_entry);
-  **slot = ent;
-}
-
-
-/* Get the original address of T as it was seen by the writer.  This
-   is only valid while T is being reconstructed.  */
-
-intptr_t
-lto_orig_address_get (tree t)
-{
-  struct tree_hash_entry ent;
-  struct tree_hash_entry **slot;
-
-  ent.key = t;
-  slot
-    = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, NO_INSERT);
-  return (slot ? (*slot)->value : 0);
-}
-
-
-/* Clear the mapping of T to its original address.  */
-
-void
-lto_orig_address_remove (tree t)
-{
-  struct tree_hash_entry ent;
-  struct tree_hash_entry **slot;
-
-  ent.key = t;
-  slot
-    = (struct tree_hash_entry **) htab_find_slot (tree_htab, &ent, NO_INSERT);
-  gcc_assert (slot);
-  free (*slot);
-  htab_clear_slot (tree_htab, (PTR *)slot);
-}
-#endif
-
-
 /* Check that the version MAJOR.MINOR is the correct version number.  */
 
 void
-lto_check_version (int major, int minor)
+lto_check_version (int major, int minor, const char *file_name)
 {
   if (major != LTO_major_version || minor != LTO_minor_version)
-    fatal_error ("bytecode stream generated with LTO version %d.%d instead "
-                "of the expected %d.%d",
+    fatal_error (input_location,
+                "bytecode stream in file %qs generated with LTO version "
+                "%d.%d instead of the expected %d.%d",
+                file_name,
                 major, minor,
                 LTO_major_version, LTO_minor_version);
 }
@@ -392,4 +284,6 @@ lto_streamer_hooks_init (void)
   streamer_hooks_init ();
   streamer_hooks.write_tree = lto_output_tree;
   streamer_hooks.read_tree = lto_input_tree;
+  streamer_hooks.input_location = lto_input_location;
+  streamer_hooks.output_location = lto_output_location;
 }