LCOV - code coverage report
Current view: top level - gcc - lto-streamer.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 97.9 % 144 141
Test Date: 2026-08-22 16:33:35 Functions: 100.0 % 19 19
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Data structures and declarations used for reading and writing
       2              :    GIMPLE to a file stream.
       3              : 
       4              :    Copyright (C) 2009-2026 Free Software Foundation, Inc.
       5              :    Contributed by Doug Kwan <dougkwan@google.com>
       6              : 
       7              : This file is part of GCC.
       8              : 
       9              : GCC is free software; you can redistribute it and/or modify it under
      10              : the terms of the GNU General Public License as published by the Free
      11              : Software Foundation; either version 3, or (at your option) any later
      12              : version.
      13              : 
      14              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      15              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      16              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      17              : for more details.
      18              : 
      19              : You should have received a copy of the GNU General Public License
      20              : along with GCC; see the file COPYING3.  If not see
      21              : <http://www.gnu.org/licenses/>.  */
      22              : 
      23              : #ifndef GCC_LTO_STREAMER_H
      24              : #define GCC_LTO_STREAMER_H
      25              : 
      26              : #include "plugin-api.h"
      27              : #include "gcov-io.h"
      28              : #include "diagnostic.h"
      29              : #include "version.h"
      30              : 
      31              : /* The encoding for a function consists of the following sections:
      32              : 
      33              :    1)    The header.
      34              :    2)    FIELD_DECLS.
      35              :    3)    FUNCTION_DECLS.
      36              :    4)    global VAR_DECLS.
      37              :    5)    type_decls
      38              :    6)    types.
      39              :    7)    Names for the labels that have names
      40              :    8)    The SSA names.
      41              :    9)    The control flow graph.
      42              :    10-11)Gimple for local decls.
      43              :    12)   Gimple for the function.
      44              :    13)   Strings.
      45              : 
      46              :    1) THE HEADER.
      47              :    2-6) THE GLOBAL DECLS AND TYPES.
      48              : 
      49              :       The global decls and types are encoded in the same way.  For each
      50              :       entry, there is word with the offset within the section to the
      51              :       entry.
      52              : 
      53              :    7) THE LABEL NAMES.
      54              : 
      55              :       Since most labels do not have names, this section my be of zero
      56              :       length.  It consists of an array of string table references, one
      57              :       per label.  In the lto code, the labels are given either
      58              :       positive or negative indexes.  the positive ones have names and
      59              :       the negative ones do not.  The positive index can be used to
      60              :       find the name in this array.
      61              : 
      62              :    9) THE CFG.
      63              : 
      64              :    10) Index into the local decls.  Since local decls can have local
      65              :       decls inside them, they must be read in randomly in order to
      66              :       properly restore them.
      67              : 
      68              :    11-12) GIMPLE FOR THE LOCAL DECLS AND THE FUNCTION BODY.
      69              : 
      70              :      The gimple consists of a set of records.
      71              : 
      72              :      THE FUNCTION
      73              : 
      74              :      At the top level of (8) is the function. It consists of five
      75              :      pieces:
      76              : 
      77              :      LTO_function     - The tag.
      78              :      eh tree          - This is all of the exception handling regions
      79              :                         put out in a post order traversial of the
      80              :                         tree.  Siblings are output as lists terminated
      81              :                         by a 0.  The set of fields matches the fields
      82              :                         defined in except.cc.
      83              : 
      84              :      last_basic_block - in uleb128 form.
      85              : 
      86              :      basic blocks     - This is the set of basic blocks.
      87              : 
      88              :      zero             - The termination of the basic blocks.
      89              : 
      90              :      BASIC BLOCKS
      91              : 
      92              :      There are two forms of basic blocks depending on if they are
      93              :      empty or not.
      94              : 
      95              :      The basic block consists of:
      96              : 
      97              :      LTO_bb1 or LTO_bb0 - The tag.
      98              : 
      99              :      bb->index          - the index in uleb128 form.
     100              : 
     101              :      #succs             - The number of successors un uleb128 form.
     102              : 
     103              :      the successors     - For each edge, a pair.  The first of the
     104              :                           pair is the index of the successor in
     105              :                           uleb128 form and the second are the flags in
     106              :                           uleb128 form.
     107              : 
     108              :      the statements     - A gimple tree, as described above.
     109              :                           These are only present for LTO_BB1.
     110              :                           Following each statement is an optional
     111              :                           exception handling record LTO_eh_region
     112              :                           which contains the region number (for
     113              :                           regions >= 0).
     114              : 
     115              :      zero               - This is only present for LTO_BB1 and is used
     116              :                           to terminate the statements and exception
     117              :                           regions within this block.
     118              : 
     119              :    13) STRINGS
     120              : 
     121              :      String are represented in the table as pairs, a length in ULEB128
     122              :      form followed by the data for the string.  */
     123              : 
     124              : #define LTO_major_version GCC_major_version
     125              : #define LTO_minor_version 0
     126              : 
     127              : typedef unsigned char   lto_decl_flags_t;
     128              : 
     129              : /* Tags representing the various IL objects written to the bytecode file
     130              :    (GIMPLE statements, basic blocks, EH regions, tree nodes, etc).
     131              : 
     132              :    NOTE, when adding new LTO tags, also update lto_tag_name.  */
     133              : enum LTO_tags
     134              : {
     135              :   LTO_null = 0,
     136              : 
     137              :   /* Reference to previously-streamed node.  */
     138              :   LTO_tree_pickle_reference,
     139              : 
     140              :   /* References to indexable tree nodes.  These objects are stored in
     141              :      tables that are written separately from the function bodies
     142              :      and variable constructors that reference them.  This way they can be
     143              :      instantiated even when the referencing functions aren't (e.g., during WPA)
     144              :      and it also allows functions to be copied from one file to another without
     145              :      having to unpickle the body first (the references are location
     146              :      independent).  */
     147              :   LTO_global_stream_ref,
     148              : 
     149              :   LTO_ssa_name_ref,
     150              : 
     151              :   /* Special for global streamer.  A blob of unnamed tree nodes.  */
     152              :   LTO_tree_scc,
     153              : 
     154              :   /* Sequence of trees.  */
     155              :   LTO_trees,
     156              : 
     157              :   /* Shared INTEGER_CST node.  */
     158              :   LTO_integer_cst,
     159              : 
     160              :   /* Tags of trees are encoded as
     161              :      LTO_first_tree_tag + TREE_CODE.  */
     162              :   LTO_first_tree_tag,
     163              :   /* Tags of gimple tuples are encoded as
     164              :      LTO_first_gimple_tag + gimple_code.  */
     165              :   LTO_first_gimple_tag = LTO_first_tree_tag + MAX_TREE_CODES,
     166              : 
     167              :   /* Entry and exit basic blocks.  */
     168              :   LTO_bb0 = LTO_first_gimple_tag + LAST_AND_UNUSED_GIMPLE_CODE,
     169              :   LTO_bb1,
     170              : 
     171              :   /* EH region holding the previous statement.  */
     172              :   LTO_eh_region,
     173              : 
     174              :   /* Function body.  */
     175              :   LTO_function,
     176              : 
     177              :   /* EH table.  */
     178              :   LTO_eh_table,
     179              : 
     180              :   /* EH region types.  These mirror enum eh_region_type.  */
     181              :   LTO_ert_cleanup,
     182              :   LTO_ert_try,
     183              :   LTO_ert_allowed_exceptions,
     184              :   LTO_ert_must_not_throw,
     185              : 
     186              :   /* EH landing pad.  */
     187              :   LTO_eh_landing_pad,
     188              : 
     189              :   /* EH try/catch node.  */
     190              :   LTO_eh_catch,
     191              : 
     192              :   /* This tag must always be last.  */
     193              :   LTO_NUM_TAGS
     194              : };
     195              : 
     196              : 
     197              : /* Set of section types that are in an LTO file.  This list will grow
     198              :    as the number of IPA passes grows since each IPA pass will need its
     199              :    own section type to store its summary information.
     200              : 
     201              :    When adding a new section type, you must also extend the
     202              :    LTO_SECTION_NAME array in lto-section-in.cc.  */
     203              : enum lto_section_type
     204              : {
     205              :   LTO_section_decls = 0,
     206              :   LTO_section_function_body,
     207              :   LTO_section_static_initializer,
     208              :   LTO_section_symtab,
     209              :   LTO_section_symtab_extension,
     210              :   LTO_section_refs,
     211              :   LTO_section_asm,
     212              :   LTO_section_jump_functions,
     213              :   LTO_section_ipa_pure_const,
     214              :   LTO_section_ipa_reference,
     215              :   LTO_section_ipa_profile,
     216              :   LTO_section_symtab_nodes,
     217              :   LTO_section_opts,
     218              :   LTO_section_cgraph_opt_sum,
     219              :   LTO_section_ipa_fn_summary,
     220              :   LTO_section_ipcp_transform,
     221              :   LTO_section_ipa_icf,
     222              :   LTO_section_offload_table,
     223              :   LTO_section_mode_table,
     224              :   LTO_section_lto,
     225              :   LTO_section_ipa_sra,
     226              :   LTO_section_odr_types,
     227              :   LTO_section_ipa_modref,
     228              :   LTO_section_linemap,
     229              :   LTO_N_SECTION_TYPES           /* Must be last.  */
     230              : };
     231              : 
     232              : /* Indices to the various function, type and symbol streams. */
     233              : enum lto_decl_stream_e_t
     234              : {
     235              :   LTO_DECL_STREAM = 0,          /* Must be first.  */
     236              :   LTO_N_DECL_STREAMS
     237              : };
     238              : 
     239              : typedef enum ld_plugin_symbol_resolution ld_plugin_symbol_resolution_t;
     240              : 
     241              : /* Return a char pointer to the start of a data stream for an lto pass
     242              :    or function.  The first parameter is the file data that contains
     243              :    the information.  The second parameter is the type of information
     244              :    to be obtained.  The third parameter is the name of the function
     245              :    and is only used when finding a function body; otherwise it is
     246              :    NULL.  The fourth parameter is the length of the data returned.  */
     247              : typedef const char* (lto_get_section_data_f) (struct lto_file_decl_data *,
     248              :                                               enum lto_section_type,
     249              :                                               const char *,
     250              :                                               int,
     251              :                                               size_t *);
     252              : 
     253              : /* Return the data found from the above call.  The first three
     254              :    parameters are the same as above.  The fourth parameter is the data
     255              :    itself and the fifth is the length of the data. */
     256              : typedef void (lto_free_section_data_f) (struct lto_file_decl_data *,
     257              :                                         enum lto_section_type,
     258              :                                         const char *,
     259              :                                         const char *,
     260              :                                         size_t);
     261              : 
     262              : /* Structure to map ordinary_map indices from streamed-in data to
     263              :    the linemap they correspond to.  */
     264              : struct GTY(()) lto_loc_map
     265              : {
     266              :   size_t nmaps;
     267              :   size_t map[1];
     268              : };
     269              : 
     270              : /* The location cache holds the ancillary data for streamed in trees.  This is
     271              :    done to reduce memory usage in the libcpp linemap; we don't need to create an
     272              :    adhoc location and store the ancillary data if the tree ends up being
     273              :    merged.  */
     274              : class lto_location_cache
     275              : {
     276              : public:
     277              :   /* Apply all changes in location cache.  Add locations into linemap and patch
     278              :      trees.  */
     279              :   bool apply_location_cache ();
     280              :   /* Tree merging did not succeed; mark all changes in the cache as
     281              :      accepted.  */
     282              :   void accept_location_cache ();
     283              :   /* Tree merging did succeed; throw away recent changes.  */
     284              :   void revert_location_cache ();
     285              :   void input_location (location_t *dest, struct bitpack_d *bp,
     286              :                        class data_in *data_in);
     287              :   void input_location_and_block (location_t *dest, struct bitpack_d *bp,
     288              :                                  class lto_input_block *ib,
     289              :                                  class data_in *data_in);
     290        91983 :   void set_linemap_offset (unsigned offset) { linemap_offset = offset; }
     291              : 
     292       223639 :   explicit lto_location_cache (lto_file_decl_data *loc_data)
     293       223639 :     : decl_data{loc_data}
     294              :   {
     295       223639 :     if (decl_data)
     296              :       {
     297       201248 :         gcc_assert (!current_cache);
     298       201248 :         current_cache = this;
     299              :       }
     300       223639 :   }
     301       223639 :   ~lto_location_cache ()
     302              :   {
     303       223639 :     if (decl_data)
     304              :       {
     305       201248 :         apply_location_cache ();
     306       201248 :         gcc_assert (current_cache == this);
     307       201248 :         current_cache = NULL;
     308              :       }
     309       223639 :   }
     310              : 
     311              :   /* There can be at most one active instance of location_cache, so that IPA
     312              :      passes can find it if needed; point to current one.  */
     313              :   static lto_location_cache *current_cache;
     314              : 
     315              : private:
     316              :   struct cached_location
     317              :   {
     318              :     location_t *dest;
     319              :     location_t loc;
     320              :     tree block;
     321              :     unsigned discr;
     322              :   };
     323              : 
     324              :   /* Which linemap section we are using.  */
     325              :   lto_file_decl_data *const decl_data;
     326              :   const lto_loc_map *cur_loc_map = nullptr;
     327              :   unsigned linemap_offset = 0;
     328              : 
     329              :   /* The location cache.  */
     330              :   auto_vec<cached_location> loc_cache;
     331              : 
     332              :   /* These keep track of most recently seen values as they are streamed in.  */
     333              :   tree stream_block = NULL_TREE;
     334              :   unsigned stream_discr = 0;
     335              :   size_t stream_map_idx = 0;
     336              :   location_t stream_loc_offset = 0;
     337              : 
     338              :   /* These keep track of most recently accepted values.  */
     339              :   cached_location current_cloc = {};
     340              :   location_t current_loc = UNKNOWN_LOCATION;
     341              : 
     342              :   /* Accepted entries are ones used by trees that are known to be not unified
     343              :      by tree merging.  */
     344              :   unsigned accepted_length = 0;
     345              : };
     346              : 
     347              : /* Structure used as buffer for reading an LTO file.  */
     348              : class lto_input_block
     349              : {
     350              : public:
     351              :   /* Special constructor for the string table, it abuses this to
     352              :      do random access but use the uhwi decoder.  */
     353      1222013 :   lto_input_block (const char *data_, unsigned int p_, unsigned int len_,
     354              :                    const lto_file_decl_data *file_data_)
     355      1222013 :       : data (data_), file_data (file_data_), p (p_), len (len_) {}
     356       370954 :   lto_input_block (const char *data_, unsigned int len_,
     357              :                    const lto_file_decl_data *file_data_)
     358       286699 :       : data (data_), file_data (file_data_), p (0), len (len_) {}
     359              : 
     360              :   const char *data;
     361              :   const lto_file_decl_data *file_data;
     362              :   unsigned int p;
     363              :   unsigned int len;
     364              : };
     365              : 
     366              : /* Compression algorithm used for compression of LTO bytecode.  */
     367              : 
     368              : enum lto_compression
     369              : {
     370              :   ZLIB,
     371              :   ZSTD
     372              : };
     373              : 
     374              : /* Structure that represents LTO ELF section with information
     375              :    about the format.  */
     376              : 
     377              : struct lto_section
     378              : {
     379              :   int16_t major_version;
     380              :   int16_t minor_version;
     381              :   unsigned char slim_object;
     382              :   unsigned char _padding;
     383              : 
     384              :   /* Flags is a private field that is not defined publicly.  */
     385              :   uint16_t flags;
     386              : 
     387              :   /* Set compression to FLAGS.  */
     388        39583 :   inline void set_compression (lto_compression c)
     389              :   {
     390        39583 :     flags = c;
     391              :   }
     392              : 
     393              :   /* Get compression from FLAGS.  */
     394       234183 :   inline lto_compression get_compression ()
     395              :   {
     396       234183 :     return (lto_compression) flags;
     397              :   }
     398              : };
     399              : 
     400              : STATIC_ASSERT (sizeof (lto_section) == 8);
     401              : 
     402              : /* The is the first part of the record in an LTO file for many of the
     403              :    IPA passes.  */
     404              : struct lto_simple_header
     405              : {
     406              :   /* Size of main gimple body of function.  */
     407              :   int32_t main_size;
     408              : };
     409              : 
     410              : struct lto_simple_header_with_strings : lto_simple_header
     411              : {
     412              :   /* Size of the string table.  */
     413              :   int32_t string_size;
     414              : };
     415              : 
     416              : /* The header for a function body.  */
     417              : struct lto_function_header : lto_simple_header_with_strings
     418              : {
     419              :   /* Size of the cfg.  */
     420              :   int32_t cfg_size;
     421              : };
     422              : 
     423              : 
     424              : /* Structure describing a symbol section.  */
     425              : struct lto_decl_header : lto_simple_header_with_strings
     426              : {
     427              :   /* Size of region for decl state. */
     428              :   int32_t decl_state_size;
     429              : 
     430              :   /* Number of nodes in globals stream.  */
     431              :   int32_t num_nodes;
     432              : };
     433              : 
     434              : 
     435              : /* Statistics gathered during LTO, WPA and LTRANS.  */
     436              : struct lto_stats_d
     437              : {
     438              :   unsigned HOST_WIDE_INT num_input_cgraph_nodes;
     439              :   unsigned HOST_WIDE_INT num_output_symtab_nodes;
     440              :   unsigned HOST_WIDE_INT num_input_files;
     441              :   unsigned HOST_WIDE_INT num_output_files;
     442              :   unsigned HOST_WIDE_INT num_cgraph_partitions;
     443              :   unsigned HOST_WIDE_INT section_size[LTO_N_SECTION_TYPES];
     444              :   unsigned HOST_WIDE_INT num_function_bodies;
     445              :   unsigned HOST_WIDE_INT num_trees[NUM_TREE_CODES];
     446              :   unsigned HOST_WIDE_INT num_output_il_bytes;
     447              :   unsigned HOST_WIDE_INT num_compressed_il_bytes;
     448              :   unsigned HOST_WIDE_INT num_input_il_bytes;
     449              :   unsigned HOST_WIDE_INT num_uncompressed_il_bytes;
     450              :   unsigned HOST_WIDE_INT num_tree_bodies_output;
     451              :   unsigned HOST_WIDE_INT num_pickle_refs_output;
     452              : };
     453              : 
     454              : /* Entry of LTO symtab encoder.  */
     455              : struct lto_encoder_entry
     456              : {
     457              :   /* Constructor.  */
     458      1429064 :   lto_encoder_entry (toplevel_node* n)
     459      1429064 :     : node (n), in_partition (false), body (false), only_for_inlining (true),
     460      1429064 :       initializer (false)
     461              :   {}
     462              : 
     463              :   toplevel_node *node;
     464              :   /* Is the node in this partition (i.e. ltrans of this partition will
     465              :      be responsible for outputting it)? */
     466              :   unsigned int in_partition:1;
     467              :   /* Do we encode body in this partition?  */
     468              :   unsigned int body:1;
     469              :   /* Do we stream this node only for inlining?  */
     470              :   unsigned int only_for_inlining:1;
     471              :   /* Do we encode initializer in this partition?
     472              :      For example the readonly variable initializers are encoded to aid
     473              :      constant folding even if they are not in the partition.  */
     474              :   unsigned int initializer:1;
     475              : };
     476              : 
     477              : 
     478              : /* Encoder data structure used to stream callgraph nodes.  */
     479              : struct lto_symtab_encoder_d
     480              : {
     481              :   vec<lto_encoder_entry> nodes;
     482              :   hash_map<toplevel_node *, size_t> *map;
     483              : 
     484              :   /* Mapping of input order of nodes onto output order.  */
     485              :   hash_map<int_hash<int, -1, -2>, int> *order_remap;
     486              : };
     487              : 
     488              : typedef struct lto_symtab_encoder_d *lto_symtab_encoder_t;
     489              : 
     490              : /* Iterator structure for cgraph node sets.  */
     491              : struct lto_symtab_encoder_iterator
     492              : {
     493              :   lto_symtab_encoder_t encoder;
     494              :   unsigned index;
     495              : };
     496              : 
     497              : 
     498              : 
     499              : /* The lto_tree_ref_encoder struct is used to encode trees into indices. */
     500              : 
     501              : struct lto_tree_ref_encoder
     502              : {
     503              :   hash_map<tree, unsigned> *tree_hash_table;      /* Maps pointers to indices. */
     504              :   vec<tree> trees;                        /* Maps indices to pointers. */
     505              : };
     506              : 
     507              : 
     508              : /* Structure to hold states of input scope.  */
     509              : struct GTY((for_user)) lto_in_decl_state
     510              : {
     511              :   /* Array of lto_in_decl_buffers to store type and decls streams. */
     512              :   vec<tree, va_gc> *streams[LTO_N_DECL_STREAMS];
     513              : 
     514              :   /* If this in-decl state is associated with a function. FN_DECL
     515              :      point to the FUNCTION_DECL. */
     516              :   tree fn_decl;
     517              : 
     518              :   /* True if decl state is compressed.  */
     519              :   bool compressed;
     520              : 
     521              :   /* Order of the linemap section to be used for interpreting the locations
     522              :      streamed for this decl.  */
     523              :   unsigned linemap_id;
     524              : };
     525              : 
     526              : typedef struct lto_in_decl_state *lto_in_decl_state_ptr;
     527              : 
     528              : struct decl_state_hasher : ggc_ptr_hash<lto_in_decl_state>
     529              : {
     530              :   static hashval_t
     531      2004127 :   hash (lto_in_decl_state *s)
     532              :   {
     533      2004127 :     return htab_hash_pointer (s->fn_decl);
     534              :   }
     535              : 
     536              :   static bool
     537      1664820 :   equal (lto_in_decl_state *a, lto_in_decl_state *b)
     538              :   {
     539      1664820 :     return a->fn_decl == b->fn_decl;
     540              :   }
     541              : };
     542              : 
     543              : /* The structure that holds all of the vectors of global types,
     544              :    decls and cgraph nodes used in the serialization of this file.  */
     545              : struct lto_out_decl_state
     546              : {
     547              :   /* The buffers contain the sets of decls of various kinds and types we have
     548              :      seen so far and the indexes assigned to them.  */
     549              :   struct lto_tree_ref_encoder streams[LTO_N_DECL_STREAMS];
     550              : 
     551              :   /* Encoder for cgraph nodes.  */
     552              :   lto_symtab_encoder_t symtab_node_encoder;
     553              : 
     554              :   /* If this out-decl state belongs to a function, fn_decl points to that
     555              :      function.  Otherwise, it is NULL. */
     556              :   tree fn_decl;
     557              : 
     558              :   /* True if decl state is compressed.  */
     559              :   bool compressed;
     560              : 
     561              :   /* True if offload tables should be output. */
     562              :   bool output_offload_tables_p;
     563              : 
     564              :   /* Order of the linemap section to be used for interpreting the locations
     565              :      streamed for this decl.  */
     566              :   unsigned linemap_id;
     567              : };
     568              : 
     569              : typedef struct lto_out_decl_state *lto_out_decl_state_ptr;
     570              : 
     571              : 
     572              : /* Compact representation of a index <-> resolution pair. Unpacked to an
     573              :    vector later. */
     574              : struct res_pair
     575              : {
     576              :   ld_plugin_symbol_resolution_t res;
     577              :   unsigned index;
     578              : };
     579              : 
     580              : 
     581              : /* One of these is allocated for each object file that being compiled
     582              :    by lto.  This structure contains the tables that are needed by the
     583              :    serialized functions and ipa passes to connect themselves to the
     584              :    global types and decls as they are reconstituted.  */
     585              : struct GTY(()) lto_file_decl_data
     586              : {
     587              :   /* Decl state currently used. */
     588              :   struct lto_in_decl_state *current_decl_state;
     589              : 
     590              :   /* Decl state corresponding to regions outside of any functions
     591              :      in the compilation unit. */
     592              :   struct lto_in_decl_state *global_decl_state;
     593              : 
     594              :   /* Table of cgraph nodes present in this file.  */
     595              :   lto_symtab_encoder_t GTY((skip)) symtab_node_encoder;
     596              : 
     597              :   /* Hash table maps lto-related section names to location in file.  */
     598              :   hash_table<decl_state_hasher> *function_decl_states;
     599              : 
     600              :   /* The .o file that these offsets relate to.  */
     601              :   const char *GTY((skip)) file_name;
     602              : 
     603              :   /* Hash table maps lto-related section names to location in file.  */
     604              :   htab_t GTY((skip)) section_hash_table;
     605              : 
     606              :   /* Hash new name of renamed global declaration to its original name.  */
     607              :   htab_t GTY((skip)) renaming_hash_table;
     608              : 
     609              :   /* Linked list used temporarily in reader */
     610              :   struct lto_file_decl_data *next;
     611              : 
     612              :   /* Order in which the file appears on the command line.  */
     613              :   int order;
     614              : 
     615              :   /* Sub ID for merged objects. */
     616              :   unsigned HOST_WIDE_INT id;
     617              : 
     618              :   /* Symbol resolutions for this file */
     619              :   vec<res_pair>  GTY((skip)) respairs;
     620              :   unsigned max_index;
     621              : 
     622              :   gcov_summary GTY((skip)) profile_info;
     623              : 
     624              :   /* Map assigning declarations their resolutions.  */
     625              :   hash_map<tree, ld_plugin_symbol_resolution> * GTY((skip)) resolution_map;
     626              : 
     627              :   /* Mode translation table.  */
     628              :   const unsigned char *mode_table;
     629              : 
     630              :   /* Read LTO section.  */
     631              :   lto_section lto_section_header;
     632              : 
     633              :   int order_base;
     634              : 
     635              :   int unit_base;
     636              : 
     637              :   unsigned mode_bits;
     638              : 
     639              :   /* Number of linemap sections contained in this file.  There is typically only
     640              :      1, but WPA and INCREMENTAL_LINK_LTO modes may create files with more than
     641              :      one linemap.  */
     642              :   unsigned num_linemap_sections;
     643              : 
     644              :   /* Location maps for locations streamed in this file.  */
     645              :   lto_file_decl_data *loc_map_decl_data;
     646              :   vec<lto_loc_map *, va_gc> *loc_maps;
     647              : };
     648              : 
     649              : /* Given an input linemap ID, compute how it will be known in the output, given
     650              :    that the output could be the combination of multiple input files.  */
     651              : inline unsigned
     652        63858 : lto_linemap_output_id (unsigned linemap_id, const lto_file_decl_data *file_data)
     653              : {
     654        29409 :   return linemap_id + file_data->order;
     655              : }
     656              : 
     657              : typedef struct lto_file_decl_data *lto_file_decl_data_ptr;
     658              : 
     659              : struct lto_char_ptr_base
     660              : {
     661              :   char *ptr;
     662              : };
     663              : 
     664              : /* An incore byte stream to buffer the various parts of the function.
     665              :    The entire structure should be zeroed when created.  The record
     666              :    consists of a set of blocks.  The first sizeof (ptr) bytes are used
     667              :    as a chain, and the rest store the bytes to be written.  */
     668              : struct lto_output_stream
     669              : {
     670              :   /* The pointer to the first block in the stream.  */
     671              :   struct lto_char_ptr_base * first_block;
     672              : 
     673              :   /* The pointer to the last and current block in the stream.  */
     674              :   struct lto_char_ptr_base * current_block;
     675              : 
     676              :   /* The pointer to where the next char should be written.  */
     677              :   char * current_pointer;
     678              : 
     679              :   /* The number of characters left in the current block.  */
     680              :   unsigned int left_in_block;
     681              : 
     682              :   /* The block size of the last block allocated.  */
     683              :   unsigned int block_size;
     684              : 
     685              :   /* The total number of characters written.  */
     686              :   unsigned int total_size;
     687              : };
     688              : 
     689              : /* A simple output block.  This can be used for simple IPA passes that
     690              :    do not need more than one stream.  */
     691              : struct lto_simple_output_block
     692              : {
     693              :   enum lto_section_type section_type;
     694              :   struct lto_out_decl_state *decl_state;
     695              : 
     696              :   /* The stream that the main tree codes are written to.  */
     697              :   struct lto_output_stream *main_stream;
     698              : };
     699              : 
     700              : /* String hashing.  */
     701              : 
     702              : struct string_slot
     703              : {
     704              :   const char *s;
     705              :   int len;
     706              :   unsigned int slot_num;
     707              : };
     708              : 
     709              : /* Hashtable helpers.  */
     710              : 
     711              : struct string_slot_hasher : nofree_ptr_hash <string_slot>
     712              : {
     713              :   static inline hashval_t hash (const string_slot *);
     714              :   static inline bool equal (const string_slot *, const string_slot *);
     715              : };
     716              : 
     717              : /* Returns a hash code for DS.  Adapted from libiberty's htab_hash_string
     718              :    to support strings that may not end in '\0'.  */
     719              : 
     720              : inline hashval_t
     721     10350879 : string_slot_hasher::hash (const string_slot *ds)
     722              : {
     723     10350879 :   hashval_t r = ds->len;
     724     10350879 :   int i;
     725              : 
     726    217193147 :   for (i = 0; i < ds->len; i++)
     727    206842268 :      r = r * 67 + (unsigned)ds->s[i] - 113;
     728     10350879 :   return r;
     729              : }
     730              : 
     731              : /* Returns nonzero if DS1 and DS2 are equal.  */
     732              : 
     733              : inline bool
     734      8149186 : string_slot_hasher::equal (const string_slot *ds1, const string_slot *ds2)
     735              : {
     736      8149186 :   if (ds1->len == ds2->len)
     737      4741777 :     return memcmp (ds1->s, ds2->s, ds1->len) == 0;
     738              : 
     739              :   return 0;
     740              : }
     741              : 
     742              : /* Data structure holding all the data and descriptors used when writing
     743              :    an LTO file.  */
     744              : struct output_block
     745              : {
     746              :   enum lto_section_type section_type;
     747              :   struct lto_out_decl_state *decl_state;
     748              : 
     749              :   /* The stream that the main tree codes are written to.  */
     750              :   struct lto_output_stream *main_stream;
     751              : 
     752              :   /* The stream that contains the string table.  */
     753              :   struct lto_output_stream *string_stream;
     754              : 
     755              :   /* The stream that contains the cfg.  */
     756              :   struct lto_output_stream *cfg_stream;
     757              : 
     758              :   /* The hash table that contains the set of strings we have seen so
     759              :      far and the indexes assigned to them.  */
     760              :   hash_table<string_slot_hasher> *string_hash_table;
     761              : 
     762              :   /* The current symbol that we are currently serializing.  Null
     763              :      if we are serializing something else.  */
     764              :   symtab_node *symbol;
     765              : 
     766              :   /* These record the most-recently-streamed values, to avoid streaming
     767              :      them unnecessarily.  */
     768              :   tree current_block;
     769              :   unsigned current_discr;
     770              :   size_t current_map_idx;
     771              :   location_t current_loc_offset;
     772              :   unsigned current_linemap_id;
     773              : 
     774              :   /* Cache of nodes written in this section.  */
     775              :   struct streamer_tree_cache_d *writer_cache;
     776              : 
     777              :   /* All trees identified as local to the unit streamed.  */
     778              :   hash_set<tree> *local_trees;
     779              : 
     780              :   /* All data persistent across whole duration of output block
     781              :      can go here.  */
     782              :   struct obstack obstack;
     783              : };
     784              : 
     785              : 
     786              : /* Data and descriptors used when reading from an LTO file.  */
     787       223639 : class data_in
     788              : {
     789              : public:
     790              :   /* The global decls and types.  */
     791              :   struct lto_file_decl_data *file_data;
     792              : 
     793              :   /* The string table.  */
     794              :   const char *strings;
     795              : 
     796              :   /* The length of the string table.  */
     797              :   unsigned int strings_len;
     798              : 
     799              :   /* Maps each reference number to the resolution done by the linker. */
     800              :   vec<ld_plugin_symbol_resolution_t> globals_resolution;
     801              : 
     802              :   /* Cache of pickled nodes.  */
     803              :   struct streamer_tree_cache_d *reader_cache;
     804              : 
     805              :   /* Cache of source code location.  */
     806              :   lto_location_cache location_cache;
     807              : 
     808       223639 :   explicit data_in (lto_file_decl_data *data_for_loc)
     809       223639 :     : location_cache{data_for_loc}
     810              :   {}
     811              : };
     812              : 
     813              : 
     814              : /* In lto-section-in.cc  */
     815              : extern class lto_input_block * lto_create_simple_input_block (
     816              :                                struct lto_file_decl_data *,
     817              :                                enum lto_section_type, const char **, size_t *);
     818              : extern void
     819              : lto_destroy_simple_input_block (struct lto_file_decl_data *,
     820              :                                 enum lto_section_type,
     821              :                                 class lto_input_block *, const char *, size_t);
     822              : extern void lto_set_in_hooks (struct lto_file_decl_data **,
     823              :                               lto_get_section_data_f *,
     824              :                               lto_free_section_data_f *);
     825              : extern struct lto_file_decl_data **lto_get_file_decl_data (void);
     826              : extern const char *lto_get_section_data (struct lto_file_decl_data *,
     827              :                                          enum lto_section_type,
     828              :                                          const char *, int, size_t *,
     829              :                                          bool decompress = false);
     830              : extern const char *lto_get_summary_section_data (struct lto_file_decl_data *,
     831              :                                                  enum lto_section_type,
     832              :                                                  size_t *);
     833              : extern const char *lto_get_raw_section_data (struct lto_file_decl_data *,
     834              :                                              enum lto_section_type,
     835              :                                              const char *, int, size_t *);
     836              : extern void lto_free_section_data (struct lto_file_decl_data *,
     837              :                                    enum lto_section_type,
     838              :                                    const char *, const char *, size_t,
     839              :                                    bool decompress = false);
     840              : extern void lto_free_raw_section_data (struct lto_file_decl_data *,
     841              :                                        enum lto_section_type,
     842              :                                        const char *, const char *, size_t);
     843              : extern htab_t lto_create_renaming_table (void);
     844              : extern void lto_record_renamed_decl (struct lto_file_decl_data *,
     845              :                                      const char *, const char *);
     846              : extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data *,
     847              :                                               const char *);
     848              : extern struct lto_in_decl_state *lto_new_in_decl_state (void);
     849              : extern void lto_delete_in_decl_state (struct lto_in_decl_state *);
     850              : extern struct lto_in_decl_state *lto_get_function_in_decl_state (
     851              :                                       struct lto_file_decl_data *, tree);
     852              : extern void lto_free_function_in_decl_state (struct lto_in_decl_state *);
     853              : extern void lto_free_function_in_decl_state_for_node (symtab_node *);
     854              : extern void lto_section_overrun (class lto_input_block *) ATTRIBUTE_NORETURN;
     855              : extern void lto_value_range_error (const char *,
     856              :                                    HOST_WIDE_INT, HOST_WIDE_INT,
     857              :                                    HOST_WIDE_INT) ATTRIBUTE_NORETURN;
     858              : 
     859              : /* In lto-section-out.cc  */
     860              : extern void lto_begin_section (const char *, bool);
     861              : extern void lto_end_section (void);
     862              : extern void lto_write_data (const void *, unsigned int);
     863              : extern void lto_write_raw_data (const void *, unsigned int);
     864              : extern void lto_write_stream (struct lto_output_stream *);
     865              : extern struct lto_simple_output_block *lto_create_simple_output_block (
     866              :                                 enum lto_section_type);
     867              : extern void lto_destroy_simple_output_block (struct lto_simple_output_block *);
     868              : extern struct lto_out_decl_state *lto_new_out_decl_state (void);
     869              : extern void lto_delete_out_decl_state (struct lto_out_decl_state *);
     870              : extern struct lto_out_decl_state *lto_get_out_decl_state (void);
     871              : extern void lto_push_out_decl_state (struct lto_out_decl_state *);
     872              : extern struct lto_out_decl_state *lto_pop_out_decl_state (void);
     873              : extern void lto_record_function_out_decl_state (tree,
     874              :                                                 struct lto_out_decl_state *);
     875              : extern void lto_append_block (struct lto_output_stream *);
     876              : 
     877              : 
     878              : /* In lto-streamer.cc.  */
     879              : 
     880              : /* Set when streaming LTO for offloading compiler.  */
     881              : extern bool lto_stream_offload_p;
     882              : 
     883              : extern const char *lto_tag_name (enum LTO_tags);
     884              : extern char *lto_get_section_name (int, const char *, int,
     885              :                                    struct lto_file_decl_data *);
     886              : extern void print_lto_report (const char *);
     887              : extern void lto_streamer_init (void);
     888              : extern bool gate_lto_out (void);
     889              : extern void lto_check_version (int, int, const char *);
     890              : extern void lto_streamer_hooks_init (void);
     891              : 
     892              : /* In lto-streamer-in.cc */
     893              : extern void lto_input_cgraph (struct lto_file_decl_data *, const char *);
     894              : extern void lto_reader_init (void);
     895              : extern void lto_free_file_name_hash (void);
     896              : extern void lto_input_function_body (struct lto_file_decl_data *,
     897              :                                      struct cgraph_node *,
     898              :                                      const char *);
     899              : extern void lto_input_variable_constructor (struct lto_file_decl_data *,
     900              :                                             struct varpool_node *,
     901              :                                             const char *);
     902              : extern void lto_input_constructors_and_inits (struct lto_file_decl_data *,
     903              :                                               const char *);
     904              : extern void lto_input_toplevel_asms (struct lto_file_decl_data *, int);
     905              : extern void lto_input_mode_table (struct lto_file_decl_data *);
     906              : extern class data_in *lto_data_in_create (struct lto_file_decl_data *,
     907              :                                           const char *, unsigned,
     908              :                                           vec<ld_plugin_symbol_resolution_t>,
     909              :                                           bool need_location_cache = true);
     910              : extern void lto_data_in_delete (class data_in *);
     911              : extern void lto_input_data_block (class lto_input_block *, void *, size_t);
     912              : void lto_input_location (location_t *, struct bitpack_d *, class data_in *);
     913              : tree lto_input_tree_ref (class lto_input_block *, class data_in *,
     914              :                          struct function *, enum LTO_tags);
     915              : void lto_tag_check_set (enum LTO_tags, int, ...);
     916              : void lto_init_eh (void);
     917              : hashval_t lto_input_scc (class lto_input_block *, class data_in *,
     918              :                          unsigned *, unsigned *, bool);
     919              : tree lto_input_tree_1 (class lto_input_block *, class data_in *,
     920              :                        enum LTO_tags, hashval_t hash);
     921              : tree lto_input_tree (class lto_input_block *, class data_in *);
     922              : tree stream_read_tree_ref (class lto_input_block *, class data_in *);
     923              : 
     924              : 
     925              : /* In lto-streamer-out.cc  */
     926              : extern void lto_register_decl_definition (tree, struct lto_file_decl_data *);
     927              : extern struct output_block *create_output_block (enum lto_section_type);
     928              : extern void destroy_output_block (struct output_block *);
     929              : extern void lto_output_tree (struct output_block *, tree, bool, bool);
     930              : extern void stream_write_tree_ref (struct output_block *, tree);
     931              : extern void lto_output_var_decl_ref (struct lto_out_decl_state *,
     932              :                                      struct lto_output_stream *, tree);
     933              : extern void lto_output_fn_decl_ref (struct lto_out_decl_state *,
     934              :                                     struct lto_output_stream *, tree);
     935              : extern tree lto_input_var_decl_ref (lto_input_block *, lto_file_decl_data *);
     936              : extern tree lto_input_fn_decl_ref (lto_input_block *, lto_file_decl_data *);
     937              : extern void lto_output_toplevel_asms (lto_symtab_encoder_t);
     938              : extern void produce_asm (struct output_block *ob);
     939              : extern void lto_output ();
     940              : extern void produce_asm_for_decls ();
     941              : void lto_register_linemap_for_output (size_t, unsigned);
     942              : void lto_copy_linemaps ();
     943              : void lto_output_decl_state_streams (struct output_block *,
     944              :                                     struct lto_out_decl_state *);
     945              : void lto_output_decl_state_refs (struct output_block *,
     946              :                                  struct lto_output_stream *,
     947              :                                  struct lto_out_decl_state *);
     948              : bool lto_variably_modified_type_p (tree);
     949              : void lto_output_location (struct output_block *, struct bitpack_d *,
     950              :                           location_t);
     951              : void lto_output_location_and_block (struct output_block *, struct bitpack_d *,
     952              :                                     location_t);
     953              : void lto_output_init_mode_table (void);
     954              : void lto_prepare_function_for_streaming (cgraph_node *);
     955              : 
     956              : 
     957              : /* In lto-cgraph.cc  */
     958              : lto_symtab_encoder_t lto_symtab_encoder_new (bool);
     959              : int lto_symtab_encoder_encode (lto_symtab_encoder_t, toplevel_node *);
     960              : void lto_symtab_encoder_delete (lto_symtab_encoder_t);
     961              : bool lto_symtab_encoder_delete_node (lto_symtab_encoder_t, toplevel_node *);
     962              : bool lto_symtab_encoder_encode_body_p (lto_symtab_encoder_t,
     963              :                                        struct cgraph_node *);
     964              : bool lto_symtab_encoder_only_for_inlining_p (lto_symtab_encoder_t,
     965              :                                              struct cgraph_node *);
     966              : bool lto_symtab_encoder_in_partition_p (lto_symtab_encoder_t,
     967              :                                         toplevel_node *);
     968              : void lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t,
     969              :                                           toplevel_node *);
     970              : 
     971              : bool lto_symtab_encoder_encode_initializer_p (lto_symtab_encoder_t,
     972              :                                               varpool_node *);
     973              : void output_symtab (void);
     974              : void input_symtab (void);
     975              : void input_toplevel_asms (void);
     976              : void output_offload_tables (void);
     977              : void input_offload_tables (bool);
     978              : bool referenced_from_other_partition_p (struct ipa_ref_list *,
     979              :                                         lto_symtab_encoder_t);
     980              : bool reachable_from_other_partition_p (struct cgraph_node *,
     981              :                                        lto_symtab_encoder_t);
     982              : bool referenced_from_this_partition_p (symtab_node *,
     983              :                                         lto_symtab_encoder_t);
     984              : bool reachable_from_this_partition_p (struct cgraph_node *,
     985              :                                       lto_symtab_encoder_t);
     986              : lto_symtab_encoder_t compute_ltrans_boundary (lto_symtab_encoder_t encoder);
     987              : void select_what_to_stream (void);
     988              : 
     989              : /* In options-save.cc.  */
     990              : void cl_target_option_stream_out (struct output_block *, struct bitpack_d *,
     991              :                                   struct cl_target_option *);
     992              : 
     993              : void cl_target_option_stream_in (class data_in *,
     994              :                                  struct bitpack_d *,
     995              :                                  struct cl_target_option *);
     996              : 
     997              : void cl_optimization_stream_out (struct output_block *,
     998              :                                  struct bitpack_d *, struct cl_optimization *);
     999              : 
    1000              : void cl_optimization_stream_in (class data_in *,
    1001              :                                 struct bitpack_d *, struct cl_optimization *);
    1002              : 
    1003              : 
    1004              : 
    1005              : /* In lto-opts.cc.  */
    1006              : extern void lto_write_options (void);
    1007              : 
    1008              : 
    1009              : /* Statistics gathered during LTO, WPA and LTRANS.  */
    1010              : extern struct lto_stats_d lto_stats;
    1011              : 
    1012              : /* Section names corresponding to the values of enum lto_section_type.  */
    1013              : extern const char *lto_section_name[];
    1014              : 
    1015              : /* Holds all the out decl states of functions output so far in the
    1016              :    current output file.  */
    1017              : extern vec<lto_out_decl_state_ptr> lto_function_decl_states;
    1018              : 
    1019              : /* Return true if LTO tag TAG corresponds to a tree code.  */
    1020              : inline bool
    1021      4398952 : lto_tag_is_tree_code_p (enum LTO_tags tag)
    1022              : {
    1023      4398952 :   return tag > LTO_first_tree_tag && (unsigned) tag <= MAX_TREE_CODES;
    1024              : }
    1025              : 
    1026              : 
    1027              : /* Return true if LTO tag TAG corresponds to a gimple code.  */
    1028              : inline bool
    1029      1408978 : lto_tag_is_gimple_code_p (enum LTO_tags tag)
    1030              : {
    1031      1408978 :   return (unsigned) tag >= LTO_first_gimple_tag
    1032      1408978 :          && (unsigned) tag
    1033              :             < (unsigned) LTO_first_gimple_tag + LAST_AND_UNUSED_GIMPLE_CODE;
    1034              : }
    1035              : 
    1036              : 
    1037              : /* Return the LTO tag corresponding to gimple code CODE.  See enum
    1038              :    LTO_tags for details on the conversion.  */
    1039              : inline enum LTO_tags
    1040      1695651 : lto_gimple_code_to_tag (enum gimple_code code)
    1041              : {
    1042      1695651 :   return (enum LTO_tags) ((unsigned) code + LTO_first_gimple_tag);
    1043              : }
    1044              : 
    1045              : 
    1046              : /* Return the GIMPLE code corresponding to TAG.  See enum LTO_tags for
    1047              :    details on the conversion.  */
    1048              : inline enum gimple_code
    1049      1408978 : lto_tag_to_gimple_code (enum LTO_tags tag)
    1050              : {
    1051      1408978 :   gcc_assert (lto_tag_is_gimple_code_p (tag));
    1052      1408978 :   return (enum gimple_code) ((unsigned) tag - LTO_first_gimple_tag);
    1053              : }
    1054              : 
    1055              : 
    1056              : /* Return the LTO tag corresponding to tree code CODE.  See enum
    1057              :    LTO_tags for details on the conversion.  */
    1058              : inline enum LTO_tags
    1059      7128340 : lto_tree_code_to_tag (enum tree_code code)
    1060              : {
    1061      7128340 :   return (enum LTO_tags) ((unsigned) code + LTO_first_tree_tag);
    1062              : }
    1063              : 
    1064              : 
    1065              : /* Return the tree code corresponding to TAG.  See enum LTO_tags for
    1066              :    details on the conversion.  */
    1067              : inline enum tree_code
    1068      4398952 : lto_tag_to_tree_code (enum LTO_tags tag)
    1069              : {
    1070      4398952 :   gcc_assert (lto_tag_is_tree_code_p (tag));
    1071      4398952 :   return (enum tree_code) ((unsigned) tag - LTO_first_tree_tag);
    1072              : }
    1073              : 
    1074              : /* Check that tag ACTUAL == EXPECTED.  */
    1075              : inline void
    1076        84255 : lto_tag_check (enum LTO_tags actual, enum LTO_tags expected)
    1077              : {
    1078        84255 :   if (actual != expected)
    1079            0 :     internal_error ("bytecode stream: expected tag %s instead of %s",
    1080              :                     lto_tag_name (expected), lto_tag_name (actual));
    1081        84255 : }
    1082              : 
    1083              : /* Check that tag ACTUAL is in the range [TAG1, TAG2].  */
    1084              : inline void
    1085        10179 : lto_tag_check_range (enum LTO_tags actual, enum LTO_tags tag1,
    1086              :                      enum LTO_tags tag2)
    1087              : {
    1088        10179 :   if (actual < tag1 || actual > tag2)
    1089            0 :     internal_error ("bytecode stream: tag %s is not in the expected range "
    1090              :                     "[%s, %s]",
    1091              :                     lto_tag_name (actual),
    1092              :                     lto_tag_name (tag1),
    1093              :                     lto_tag_name (tag2));
    1094        10179 : }
    1095              : 
    1096              : /* Initialize an lto_out_decl_buffer ENCODER.  */
    1097              : inline void
    1098       185713 : lto_init_tree_ref_encoder (struct lto_tree_ref_encoder *encoder)
    1099              : {
    1100       185713 :   encoder->tree_hash_table = new hash_map<tree, unsigned> (251);
    1101       185713 :   encoder->trees.create (0);
    1102       185713 : }
    1103              : 
    1104              : 
    1105              : /* Destroy an lto_tree_ref_encoder ENCODER by freeing its contents.  The
    1106              :    memory used by ENCODER is not freed by this function.  */
    1107              : inline void
    1108       185713 : lto_destroy_tree_ref_encoder (struct lto_tree_ref_encoder *encoder)
    1109              : {
    1110              :   /* Hash table may be delete already.  */
    1111       185713 :   delete encoder->tree_hash_table;
    1112       185713 :   encoder->tree_hash_table = NULL;
    1113       185713 :   encoder->trees.release ();
    1114       185713 : }
    1115              : 
    1116              : /* Return the number of trees encoded in ENCODER. */
    1117              : inline unsigned int
    1118       591588 : lto_tree_ref_encoder_size (struct lto_tree_ref_encoder *encoder)
    1119              : {
    1120      1145991 :   return encoder->trees.length ();
    1121              : }
    1122              : 
    1123              : /* Return the IDX-th tree in ENCODER. */
    1124              : inline tree
    1125      5329274 : lto_tree_ref_encoder_get_tree (struct lto_tree_ref_encoder *encoder,
    1126              :                                unsigned int idx)
    1127              : {
    1128      5329274 :   return encoder->trees[idx];
    1129              : }
    1130              : 
    1131              : /* Return number of encoded nodes in ENCODER.  */
    1132              : inline int
    1133     20240771 : lto_symtab_encoder_size (lto_symtab_encoder_t encoder)
    1134              : {
    1135     32248911 :   return encoder->nodes.length ();
    1136              : }
    1137              : 
    1138              : /* Value used to represent failure of lto_symtab_encoder_lookup.  */
    1139              : #define LCC_NOT_FOUND   (-1)
    1140              : 
    1141              : /* Look up NODE in encoder.  Return NODE's reference if it has been encoded
    1142              :    or LCC_NOT_FOUND if it is not there.  */
    1143              : 
    1144              : inline int
    1145     12669921 : lto_symtab_encoder_lookup (lto_symtab_encoder_t encoder,
    1146              :                            toplevel_node *node)
    1147              : {
    1148     12669921 :   size_t *slot = encoder->map->get (node);
    1149     12669921 :   return (slot && *slot ? *(slot) - 1 : LCC_NOT_FOUND);
    1150              : }
    1151              : 
    1152              : /* Return true if iterator LSE points to nothing.  */
    1153              : inline bool
    1154     14899467 : lsei_end_p (lto_symtab_encoder_iterator lsei)
    1155              : {
    1156      6755693 :   return lsei.index >= (unsigned)lto_symtab_encoder_size (lsei.encoder);
    1157              : }
    1158              : 
    1159              : /* Advance iterator LSE.  */
    1160              : inline void
    1161     11929408 : lsei_next (lto_symtab_encoder_iterator *lsei)
    1162              : {
    1163     11169558 :   lsei->index++;
    1164              : }
    1165              : 
    1166              : /* Return the node pointed to by LSI.  */
    1167              : inline toplevel_node *
    1168     16733402 : lsei_node (lto_symtab_encoder_iterator lsei)
    1169              : {
    1170     12298894 :   return lsei.encoder->nodes[lsei.index].node;
    1171              : }
    1172              : 
    1173              : /* Return the node pointed to by LSI.  */
    1174              : inline struct cgraph_node *
    1175      1244089 : lsei_cgraph_node (lto_symtab_encoder_iterator lsei)
    1176              : {
    1177      1244089 :   return dyn_cast<cgraph_node *> (lsei.encoder->nodes[lsei.index].node);
    1178              : }
    1179              : 
    1180              : /* Return the node pointed to by LSI.  */
    1181              : inline varpool_node *
    1182       281825 : lsei_varpool_node (lto_symtab_encoder_iterator lsei)
    1183              : {
    1184       281825 :   return dyn_cast<varpool_node *> (lsei.encoder->nodes[lsei.index].node);
    1185              : }
    1186              : 
    1187              : /* Return the cgraph node corresponding to REF using ENCODER.  */
    1188              : 
    1189              : inline toplevel_node *
    1190      7866641 : lto_symtab_encoder_deref (lto_symtab_encoder_t encoder, int ref)
    1191              : {
    1192      7864753 :   if (ref == LCC_NOT_FOUND)
    1193              :     return NULL;
    1194              : 
    1195      7866641 :   return encoder->nodes[ref].node;
    1196              : }
    1197              : 
    1198              : /* Return an iterator to the first node in LSI.  */
    1199              : inline lto_symtab_encoder_iterator
    1200       414736 : lsei_start (lto_symtab_encoder_t encoder)
    1201              : {
    1202       414736 :   lto_symtab_encoder_iterator lsei;
    1203              : 
    1204       414736 :   lsei.encoder = encoder;
    1205       414736 :   lsei.index = 0;
    1206       383041 :   return lsei;
    1207              : }
    1208              : 
    1209              : /* Advance iterator LSE.  */
    1210              : inline void
    1211       698529 : lsei_next_in_partition (lto_symtab_encoder_iterator *lsei)
    1212              : {
    1213       698529 :   lsei_next (lsei);
    1214       698529 :   while (!lsei_end_p (*lsei)
    1215      2287753 :          && !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei)))
    1216       465366 :     lsei_next (lsei);
    1217       698529 : }
    1218              : 
    1219              : /* Return an iterator to the first node in LSI.  */
    1220              : inline lto_symtab_encoder_iterator
    1221        40421 : lsei_start_in_partition (lto_symtab_encoder_t encoder)
    1222              : {
    1223        40421 :   lto_symtab_encoder_iterator lsei = lsei_start (encoder);
    1224              : 
    1225        40421 :   if (lsei_end_p (lsei))
    1226          384 :     return lsei;
    1227        40037 :   if (!lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei)))
    1228            0 :     lsei_next_in_partition (&lsei);
    1229              : 
    1230        40037 :   return lsei;
    1231              : }
    1232              : 
    1233              : /* Advance iterator LSE.  */
    1234              : inline void
    1235      1248206 : lsei_next_function_in_partition (lto_symtab_encoder_iterator *lsei)
    1236              : {
    1237      1248206 :   lsei_next (lsei);
    1238      1248206 :   while (!lsei_end_p (*lsei)
    1239     17059831 :          && (!is_a <cgraph_node *> (lsei_node (*lsei))
    1240      3531344 :              || !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei))))
    1241      5644811 :     lsei_next (lsei);
    1242      1248206 : }
    1243              : 
    1244              : /* Return an iterator to the first node in LSI.  */
    1245              : inline lto_symtab_encoder_iterator
    1246       279232 : lsei_start_function_in_partition (lto_symtab_encoder_t encoder)
    1247              : {
    1248       279232 :   lto_symtab_encoder_iterator lsei = lsei_start (encoder);
    1249              : 
    1250       279232 :   if (lsei_end_p (lsei))
    1251         2532 :     return lsei;
    1252       549843 :   if (!is_a <cgraph_node *> (lsei_node (lsei))
    1253       273143 :       || !lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei)))
    1254         4117 :     lsei_next_function_in_partition (&lsei);
    1255              : 
    1256       276700 :   return lsei;
    1257              : }
    1258              : 
    1259              : /* Advance iterator LSE.  */
    1260              : inline void
    1261       312610 : lsei_next_variable_in_partition (lto_symtab_encoder_iterator *lsei)
    1262              : {
    1263       312610 :   lsei_next (lsei);
    1264       312610 :   while (!lsei_end_p (*lsei)
    1265      1154038 :          && (!is_a <varpool_node *> (lsei_node (*lsei))
    1266       281151 :              || !lto_symtab_encoder_in_partition_p (lsei->encoder, lsei_node (*lsei))))
    1267       139563 :     lsei_next (lsei);
    1268       312610 : }
    1269              : 
    1270              : /* Return an iterator to the first node in LSI.  */
    1271              : inline lto_symtab_encoder_iterator
    1272        31694 : lsei_start_variable_in_partition (lto_symtab_encoder_t encoder)
    1273              : {
    1274        31694 :   lto_symtab_encoder_iterator lsei = lsei_start (encoder);
    1275              : 
    1276        31694 :   if (lsei_end_p (lsei))
    1277          235 :     return lsei;
    1278        32133 :   if (!is_a <varpool_node *> (lsei_node (lsei))
    1279          674 :       || !lto_symtab_encoder_in_partition_p (encoder, lsei_node (lsei)))
    1280        30785 :     lsei_next_variable_in_partition (&lsei);
    1281              : 
    1282        31459 :   return lsei;
    1283              : }
    1284              : 
    1285              : /* Entry for the delayed registering of decl -> DIE references.  */
    1286              : struct dref_entry {
    1287              :     tree decl;
    1288              :     const char *sym;
    1289              :     unsigned HOST_WIDE_INT off;
    1290              : };
    1291              : 
    1292              : extern vec<dref_entry> dref_queue;
    1293              : 
    1294              : extern FILE *streamer_dump_file;
    1295              : 
    1296              : #endif /* GCC_LTO_STREAMER_H  */
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.