OSDN Git Service

PR target/45250
[pf3gnuchains/gcc-fork.git] / gcc / lto-streamer.h
index c33feb6..35a0a9b 100644 (file)
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cgraph.h"
 #include "vec.h"
 #include "vecprim.h"
+#include "alloc-pool.h"
 
 /* Define when debugging the LTO streamer.  This causes the writer
    to output the numeric value for the memory address of the tree node
@@ -155,17 +156,14 @@ DEF_VEC_ALLOC_I(bitpack_word_t, heap);
 
 struct bitpack_d
 {
-  /* Total number of bits packed/unpacked so far.  */
-  size_t num_bits;
+  /* The position of the first unused or unconsumed bit in the word.  */
+  unsigned pos;
 
-  /* Values are stored contiguously, so there may be internal
-     fragmentation (words with unused bits).  Therefore, we need to
-     keep track of the first available bit in the last word of the
-     bitpack.  */
-  size_t first_unused_bit;
+  /* The current word we are (un)packing.  */
+  bitpack_word_t word;
 
-  /* Vector of words holding the packed values.  */
-  VEC(bitpack_word_t, heap) *values;
+  /* The lto_output_stream or the lto_input_block we are streaming to/from.  */
+  void *stream;
 };
 
 /* Tags representing the various IL objects written to the bytecode file
@@ -257,11 +255,13 @@ enum lto_section_type
   LTO_section_static_initializer,
   LTO_section_cgraph,
   LTO_section_varpool,
+  LTO_section_refs,
   LTO_section_jump_functions,
   LTO_section_ipa_pure_const,
   LTO_section_ipa_reference,
   LTO_section_symtab,
   LTO_section_opts,
+  LTO_section_cgraph_opt_sum,
   LTO_N_SECTION_TYPES          /* Must be last.  */
 };
 
@@ -345,11 +345,14 @@ struct lto_streamer_cache_d
   /* The mapping between tree nodes and slots into the nodes array.  */
   htab_t node_map;
 
+  /* Node map to store entries into.  */
+  alloc_pool node_map_entries;
+
   /* Next available slot in the nodes and offsets arrays.  */
   unsigned next_slot;
 
   /* The nodes pickled so far.  */
-  VEC(tree,gc) *nodes;
+  VEC(tree,heap) *nodes;
 
   /* Offset into the stream where the nodes have been written.  */
   VEC(unsigned,heap) *offsets;
@@ -462,15 +465,49 @@ struct lto_cgraph_encoder_d
 
   /* Map reference number to node. */
   VEC(cgraph_node_ptr,heap) *nodes;
+
+  /* Map of nodes where we want to output body.  */
+  struct pointer_set_t *body;
 };
 
 typedef struct lto_cgraph_encoder_d *lto_cgraph_encoder_t;
 
+/* Return number of encoded nodes in ENCODER.  */
+
+static inline int
+lto_cgraph_encoder_size (lto_cgraph_encoder_t encoder)
+{
+  return VEC_length (cgraph_node_ptr, encoder->nodes);
+}
+
+
+/* Encoder data structure used to stream callgraph nodes.  */
+struct lto_varpool_encoder_d
+{
+  /* Map nodes to reference number. */
+  struct pointer_map_t *map;
+
+  /* Map reference number to node. */
+  VEC(varpool_node_ptr,heap) *nodes;
+
+  /* Map of nodes where we want to output initializer.  */
+  struct pointer_set_t *initializer;
+};
+typedef struct lto_varpool_encoder_d *lto_varpool_encoder_t;
+
+/* Return number of encoded nodes in ENCODER.  */
+
+static inline int
+lto_varpool_encoder_size (lto_varpool_encoder_t encoder)
+{
+  return VEC_length (varpool_node_ptr, encoder->nodes);
+}
+
 /* Mapping from indices to trees.  */
-struct lto_tree_ref_table
+struct GTY(()) lto_tree_ref_table
 {
   /* Array of referenced trees . */
-  tree *trees;
+  tree * GTY((length ("%h.size"))) trees;
 
   /* Size of array. */
   unsigned int size;
@@ -496,7 +533,7 @@ struct lto_tree_ref_encoder
 
 
 /* Structure to hold states of input scope.  */
-struct lto_in_decl_state
+struct GTY(()) lto_in_decl_state
 {
   /* Array of lto_in_decl_buffers to store type and decls streams. */
   struct lto_tree_ref_table streams[LTO_N_DECL_STREAMS];
@@ -520,6 +557,9 @@ struct lto_out_decl_state
   /* Encoder for cgraph nodes.  */
   lto_cgraph_encoder_t cgraph_node_encoder;
 
+  /* Encoder for varpool nodes.  */
+  lto_varpool_encoder_t varpool_node_encoder;
+
   /* If this out-decl state belongs to a function, fn_decl points to that
      function.  Otherwise, it is NULL. */
   tree fn_decl;
@@ -534,7 +574,7 @@ DEF_VEC_ALLOC_P(lto_out_decl_state_ptr, heap);
    by lto.  This structure contains the tables that are needed by the
    serialized functions and ipa passes to connect themselves to the
    global types and decls as they are reconstituted.  */
-struct lto_file_decl_data
+struct GTY(()) lto_file_decl_data
 {
   /* Decl state currently used. */
   struct lto_in_decl_state *current_decl_state;
@@ -544,24 +584,35 @@ struct lto_file_decl_data
   struct lto_in_decl_state *global_decl_state;
 
   /* Table of cgraph nodes present in this file.  */
-  lto_cgraph_encoder_t cgraph_node_encoder;
+  lto_cgraph_encoder_t GTY((skip)) cgraph_node_encoder;
+
+  /* Table of varpool nodes present in this file.  */
+  lto_varpool_encoder_t GTY((skip)) varpool_node_encoder;
 
   /* Hash table maps lto-related section names to location in file.  */
-  htab_t function_decl_states;
+  htab_t GTY((param_is (struct lto_in_decl_state))) function_decl_states;
 
   /* The .o file that these offsets relate to.  */
-  const char *file_name;
-
-  /* Nonzero if this file should be recompiled with LTRANS.  */
-  unsigned needs_ltrans_p : 1;
+  const char *GTY((skip)) file_name;
 
   /* Hash table maps lto-related section names to location in file.  */
-  htab_t section_hash_table;
+  htab_t GTY((skip)) section_hash_table;
 
   /* Hash new name of renamed global declaration to its original name.  */
-  htab_t renaming_hash_table;
+  htab_t GTY((skip)) renaming_hash_table;
+
+  /* Linked list used temporarily in reader */
+  struct lto_file_decl_data *next;
+
+  /* Sub ID for merged objects. */
+  unsigned id;
+
+  /* Symbol resolutions for this file */
+  VEC(ld_plugin_symbol_resolution_t,heap) * GTY((skip)) resolutions;
 };
 
+typedef struct lto_file_decl_data *lto_file_decl_data_ptr;
+
 struct lto_char_ptr_base
 {
   char *ptr;
@@ -773,12 +824,8 @@ extern void lto_record_function_out_decl_state (tree,
 extern const char *lto_tag_name (enum LTO_tags);
 extern bitmap lto_bitmap_alloc (void);
 extern void lto_bitmap_free (bitmap);
-extern char *lto_get_section_name (int, const char *);
+extern char *lto_get_section_name (int, const char *, struct lto_file_decl_data *);
 extern void print_lto_report (void);
-extern struct bitpack_d *bitpack_create (void);
-extern void bitpack_delete (struct bitpack_d *);
-extern void bp_pack_value (struct bitpack_d *, bitpack_word_t, unsigned);
-extern bitpack_word_t bp_unpack_value (struct bitpack_d *, unsigned);
 extern bool lto_streamer_cache_insert (struct lto_streamer_cache_d *, tree,
                                       int *, unsigned *);
 extern bool lto_streamer_cache_insert_at (struct lto_streamer_cache_d *, tree,
@@ -806,7 +853,6 @@ extern void lto_input_function_body (struct lto_file_decl_data *, tree,
                                     const char *);
 extern void lto_input_constructors_and_inits (struct lto_file_decl_data *,
                                              const char *);
-extern struct bitpack_d *lto_input_bitpack (struct lto_input_block *);
 extern void lto_init_reader (void);
 extern struct data_in *lto_data_in_create (struct lto_file_decl_data *,
                                    const char *, unsigned,
@@ -819,7 +865,6 @@ extern void lto_register_decl_definition (tree, struct lto_file_decl_data *);
 extern struct output_block *create_output_block (enum lto_section_type);
 extern void destroy_output_block (struct output_block *);
 extern void lto_output_tree (struct output_block *, tree, bool);
-extern void lto_output_bitpack (struct lto_output_stream *, struct bitpack_d *);
 extern void produce_asm (struct output_block *ob, tree fn);
 
 
@@ -828,11 +873,33 @@ struct cgraph_node *lto_cgraph_encoder_deref (lto_cgraph_encoder_t, int);
 int lto_cgraph_encoder_lookup (lto_cgraph_encoder_t, struct cgraph_node *);
 lto_cgraph_encoder_t lto_cgraph_encoder_new (void);
 int lto_cgraph_encoder_encode (lto_cgraph_encoder_t, struct cgraph_node *);
-void lto_cgraph_encoder_delete (lto_cgraph_encoder_t encoder);
-void output_cgraph (cgraph_node_set);
+void lto_cgraph_encoder_delete (lto_cgraph_encoder_t);
+bool lto_cgraph_encoder_encode_body_p (lto_cgraph_encoder_t,
+                                      struct cgraph_node *);
+
+bool lto_varpool_encoder_encode_body_p (lto_varpool_encoder_t,
+                                       struct varpool_node *);
+struct varpool_node *lto_varpool_encoder_deref (lto_varpool_encoder_t, int);
+int lto_varpool_encoder_lookup (lto_varpool_encoder_t, struct varpool_node *);
+lto_varpool_encoder_t lto_varpool_encoder_new (void);
+int lto_varpool_encoder_encode (lto_varpool_encoder_t, struct varpool_node *);
+void lto_varpool_encoder_delete (lto_varpool_encoder_t);
+bool lto_varpool_encoder_encode_initializer_p (lto_varpool_encoder_t,
+                                              struct varpool_node *);
+void output_cgraph (cgraph_node_set, varpool_node_set);
 void input_cgraph (void);
-void output_varpool (varpool_node_set);
-void input_varpool (void);
+bool referenced_from_other_partition_p (struct ipa_ref_list *,
+                                       cgraph_node_set,
+                                       varpool_node_set vset);
+bool reachable_from_other_partition_p (struct cgraph_node *,
+                                      cgraph_node_set);
+bool referenced_from_this_partition_p (struct ipa_ref_list *,
+                                       cgraph_node_set,
+                                       varpool_node_set vset);
+bool reachable_from_this_partition_p (struct cgraph_node *,
+                                      cgraph_node_set);
+void compute_ltrans_boundary (struct lto_out_decl_state *state,
+                             cgraph_node_set, varpool_node_set);
 
 
 /* In lto-symtab.c.  */
@@ -842,6 +909,7 @@ extern void lto_symtab_merge_decls (void);
 extern void lto_symtab_merge_cgraph_nodes (void);
 extern tree lto_symtab_prevailing_decl (tree decl);
 extern enum ld_plugin_symbol_resolution lto_symtab_get_resolution (tree decl);
+extern void lto_symtab_free (void);
 
 
 /* In lto-opts.c.  */
@@ -922,38 +990,6 @@ lto_tag_to_tree_code (enum LTO_tags tag)
   return (enum tree_code) ((unsigned) tag - 1);
 }
 
-
-/* Return true if FILE needs to be compiled with LTRANS.  */
-static inline bool
-lto_file_needs_ltrans_p (struct lto_file_decl_data *file)
-{
-  return file->needs_ltrans_p != 0;
-}
-
-
-/* Mark FILE to be compiled with LTRANS.  */
-static inline void
-lto_mark_file_for_ltrans (struct lto_file_decl_data *file)
-{
-  file->needs_ltrans_p = 1;
-}
-
-
-/* Return true if any files in node set SET need to be compiled
-   with LTRANS.  */
-static inline bool
-cgraph_node_set_needs_ltrans_p (cgraph_node_set set)
-{
-  cgraph_node_set_iterator csi;
-
-  for (csi = csi_start (set); !csi_end_p (csi); csi_next (&csi))
-    if (lto_file_needs_ltrans_p (csi_node (csi)->local.lto_file_data))
-      return true;
-
-  return false;
-}
-
-
 /* Initialize an lto_out_decl_buffer ENCODER.  */
 static inline void
 lto_init_tree_ref_encoder (struct lto_tree_ref_encoder *encoder,
@@ -1041,4 +1077,85 @@ DEFINE_DECL_STREAM_FUNCS (TYPE_DECL, type_decl)
 DEFINE_DECL_STREAM_FUNCS (NAMESPACE_DECL, namespace_decl)
 DEFINE_DECL_STREAM_FUNCS (LABEL_DECL, label_decl)
 
+/* Returns a new bit-packing context for bit-packing into S.  */
+static inline struct bitpack_d
+bitpack_create (struct lto_output_stream *s)
+{
+  struct bitpack_d bp;
+  bp.pos = 0;
+  bp.word = 0;
+  bp.stream = (void *)s;
+  return bp;
+}
+
+/* Pack the NBITS bit sized value VAL into the bit-packing context BP.  */
+static inline void
+bp_pack_value (struct bitpack_d *bp, bitpack_word_t val, unsigned nbits)
+{
+  bitpack_word_t word = bp->word;
+  int pos = bp->pos;
+  /* If val does not fit into the current bitpack word switch to the
+     next one.  */
+  if (pos + nbits > BITS_PER_BITPACK_WORD)
+    {
+      lto_output_uleb128_stream ((struct lto_output_stream *) bp->stream, word);
+      word = val;
+      pos = nbits;
+    }
+  else
+    {
+      word |= val << pos;
+      pos += nbits;
+    }
+  bp->word = word;
+  bp->pos = pos;
+}
+
+/* Finishes bit-packing of BP.  */
+static inline void
+lto_output_bitpack (struct bitpack_d *bp)
+{
+  lto_output_uleb128_stream ((struct lto_output_stream *) bp->stream,
+                            bp->word);
+  bp->word = 0;
+  bp->pos = 0;
+}
+
+/* Returns a new bit-packing context for bit-unpacking from IB.  */
+static inline struct bitpack_d
+lto_input_bitpack (struct lto_input_block *ib)
+{
+  struct bitpack_d bp;
+  bp.word = lto_input_uleb128 (ib);
+  bp.pos = 0;
+  bp.stream = (void *)ib;
+  return bp;
+}
+
+/* Unpacks NBITS bits from the bit-packing context BP and returns them.  */
+static inline bitpack_word_t
+bp_unpack_value (struct bitpack_d *bp, unsigned nbits)
+{
+  bitpack_word_t mask, val;
+  int pos = bp->pos;
+
+  mask = (nbits == BITS_PER_BITPACK_WORD
+         ? (bitpack_word_t) -1
+         : ((bitpack_word_t) 1 << nbits) - 1);
+
+  /* If there are not continuous nbits in the current bitpack word
+     switch to the next one.  */
+  if (pos + nbits > BITS_PER_BITPACK_WORD)
+    {
+      bp->word = val = lto_input_uleb128 ((struct lto_input_block *)bp->stream);
+      bp->pos = nbits;
+      return val & mask;
+    }
+  val = bp->word;
+  val >>= pos;
+  bp->pos = pos + nbits;
+
+  return val & mask;
+}
+
 #endif /* GCC_LTO_STREAMER_H  */