LCOV - code coverage report
Current view: top level - gcc - lto-streamer.h (source / functions) Hit Total Coverage
Test: gcc.info Lines: 131 136 96.3 %
Date: 2020-03-28 11:57:23 Functions: 12 12 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.0

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 --enable-host-shared. GCC test suite is run with the built compiler.