LCOV - code coverage report
Current view: top level - gcc - lto-streamer-out.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.3 % 1900 1754
Test Date: 2026-12-05 16:10:02 Functions: 98.6 % 74 73
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Write the GIMPLE representation to a file stream.
       2              : 
       3              :    Copyright (C) 2009-2026 Free Software Foundation, Inc.
       4              :    Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
       5              :    Re-implemented by Diego Novillo <dnovillo@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              : #include "config.h"
      24              : #include "system.h"
      25              : #include "coretypes.h"
      26              : #include "backend.h"
      27              : #include "target.h"
      28              : #include "rtl.h"
      29              : #include "tree.h"
      30              : #include "gimple.h"
      31              : #include "tree-pass.h"
      32              : #include "ssa.h"
      33              : #include "gimple-streamer.h"
      34              : #include "alias.h"
      35              : #include "stor-layout.h"
      36              : #include "gimple-iterator.h"
      37              : #include "except.h"
      38              : #include "lto-symtab.h"
      39              : #include "cgraph.h"
      40              : #include "cfgloop.h"
      41              : #include "builtins.h"
      42              : #include "gomp-constants.h"
      43              : #include "debug.h"
      44              : #include "omp-offload.h"
      45              : #include "print-tree.h"
      46              : #include "tree-dfa.h"
      47              : #include "file-prefix-map.h" /* remap_debug_filename()  */
      48              : #include "output.h"
      49              : #include "ipa-utils.h"
      50              : #include "toplev.h"
      51              : 
      52              : 
      53              : static void lto_write_tree (struct output_block*, tree, bool);
      54              : 
      55              : /* Clear the line info stored in DATA_IN.  */
      56              : 
      57              : static void
      58       368454 : clear_line_info (struct output_block *ob)
      59              : {
      60              :   /* Initialize to something that will never appear as block,
      61              :      so that the first location with block in a function etc.
      62              :      always streams a change_block bit and the first block.  */
      63       368454 :   ob->current_block = void_node;
      64       368454 :   ob->current_discr = UINT_MAX;
      65       368454 :   ob->current_map_idx = 0;
      66       368454 :   ob->current_loc_offset = 0;
      67       368454 :   ob->current_linemap_id = -1U;
      68            0 : }
      69              : 
      70              : 
      71              : /* Create the output block and return it.  SECTION_TYPE is
      72              :    LTO_section_function_body or LTO_static_initializer.  */
      73              : 
      74              : struct output_block *
      75       368454 : create_output_block (enum lto_section_type section_type)
      76              : {
      77       368454 :   struct output_block *ob = XCNEW (struct output_block);
      78       368454 :   if (streamer_dump_file)
      79           44 :     fprintf (streamer_dump_file, "Creating output block for %s\n",
      80           44 :              lto_section_name[section_type]);
      81              : 
      82       368454 :   ob->section_type = section_type;
      83       368454 :   ob->decl_state = lto_get_out_decl_state ();
      84              :   /* Only global decl stream in non-wpa will ever be considered by tree
      85              :      merging.  */
      86       368454 :   if (!flag_wpa && section_type == LTO_section_decls)
      87        24845 :     ob->local_trees = new (hash_set <tree>);
      88       368454 :   ob->main_stream = XCNEW (struct lto_output_stream);
      89       368454 :   ob->string_stream = XCNEW (struct lto_output_stream);
      90       368454 :   ob->writer_cache = streamer_tree_cache_create (!flag_wpa, true, false);
      91              : 
      92       368454 :   if (section_type == LTO_section_function_body)
      93       122945 :     ob->cfg_stream = XCNEW (struct lto_output_stream);
      94              : 
      95       368454 :   clear_line_info (ob);
      96              : 
      97       368454 :   ob->string_hash_table = new hash_table<string_slot_hasher> (37);
      98       368454 :   gcc_obstack_init (&ob->obstack);
      99              : 
     100       368454 :   return ob;
     101              : }
     102              : 
     103              : 
     104              : /* Destroy the output block OB.  */
     105              : 
     106              : void
     107       368454 : destroy_output_block (struct output_block *ob)
     108              : {
     109       368454 :   enum lto_section_type section_type = ob->section_type;
     110              : 
     111       368454 :   delete ob->string_hash_table;
     112       368454 :   ob->string_hash_table = NULL;
     113       393299 :   delete ob->local_trees;
     114              : 
     115       368454 :   free (ob->main_stream);
     116       368454 :   free (ob->string_stream);
     117       368454 :   if (section_type == LTO_section_function_body)
     118       122945 :     free (ob->cfg_stream);
     119              : 
     120       368454 :   streamer_tree_cache_delete (ob->writer_cache);
     121       368454 :   obstack_free (&ob->obstack, NULL);
     122              : 
     123       368454 :   free (ob);
     124       368454 : }
     125              : 
     126              : 
     127              : /* Wrapper around variably_modified_type_p avoiding type modification
     128              :    during WPA streaming.  */
     129              : 
     130              : bool
     131     14793591 : lto_variably_modified_type_p (tree type)
     132              : {
     133     14793591 :   return (in_lto_p
     134     14793591 :           ? TYPE_LANG_FLAG_0 (TYPE_MAIN_VARIANT (type))
     135     14487105 :           : variably_modified_type_p (type, NULL_TREE));
     136              : }
     137              : 
     138              : 
     139              : /* Return true if tree node T is written to various tables.  For these
     140              :    nodes, we sometimes want to write their physical representation
     141              :    (via lto_output_tree), and sometimes we need to emit an index
     142              :    reference into a table (via lto_output_tree_ref).  */
     143              : 
     144              : static bool
     145     36881770 : tree_is_indexable (tree t)
     146              : {
     147              :   /* Parameters and return values of functions of variably modified types
     148              :      must go to global stream, because they may be used in the type
     149              :      definition.  */
     150     35760755 :   if ((TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL)
     151     37223140 :       && DECL_CONTEXT (t))
     152      1462385 :     return lto_variably_modified_type_p (TREE_TYPE (DECL_CONTEXT (t)));
     153              :   /* IMPORTED_DECL is put into BLOCK and thus it never can be shared.
     154              :      We should no longer need to stream it.  */
     155     35419385 :   else if (TREE_CODE (t) == IMPORTED_DECL)
     156            0 :     gcc_unreachable ();
     157     35419385 :   else if (TREE_CODE (t) == LABEL_DECL)
     158        85753 :     return FORCED_LABEL (t) || DECL_NONLOCAL (t);
     159      1732379 :   else if (((VAR_P (t) && !TREE_STATIC (t))
     160              :             || TREE_CODE (t) == TYPE_DECL
     161              :             || TREE_CODE (t) == CONST_DECL
     162              :             || TREE_CODE (t) == NAMELIST_DECL)
     163     36248112 :            && decl_function_context (t))
     164              :     return false;
     165     34429079 :   else if (TREE_CODE (t) == DEBUG_EXPR_DECL)
     166              :     return false;
     167              :   /* Variably modified types need to be streamed alongside function
     168              :      bodies because they can refer to local entities.  Together with
     169              :      them we have to localize their members as well.
     170              :      ???  In theory that includes non-FIELD_DECLs as well.  */
     171     34427145 :   else if (TYPE_P (t)
     172     34427145 :            && lto_variably_modified_type_p (t))
     173              :     return false;
     174     34415302 :   else if (TREE_CODE (t) == FIELD_DECL
     175     34415302 :            && lto_variably_modified_type_p (DECL_CONTEXT (t)))
     176              :     return false;
     177              :   else
     178     34414873 :     return (IS_TYPE_OR_DECL_P (t) || TREE_CODE (t) == SSA_NAME);
     179              : }
     180              : 
     181              : namespace {
     182              : 
     183              : /* Compute a 32-bit hash of the linemap details.  This is currently used to
     184              :    ensure that WPA streamed output will change whenever the linemap details
     185              :    change, otherwise there could be potential issues with the validity of
     186              :    the cache used to implement -flto-incremental.  */
     187              : 
     188              : hashval_t
     189        65670 : compute_map_hash (const line_map_ordinary *map)
     190              : {
     191        65670 :   inchash::hash h;
     192        65670 :   h.add_int (map->sysp);
     193        65670 :   h.add_int (map->m_column_and_range_bits - map->m_range_bits);
     194        65670 :   h.add_int (map->to_line);
     195        65670 :   h.add_object (map->included_from);
     196        65670 :   h.add (map->to_file, strlen (map->to_file));
     197        65670 :   return h.end ();
     198              : }
     199              : 
     200              : class location_output
     201              : {
     202              : public:
     203              : 
     204              :   struct map_id_t
     205              :   {
     206              :     size_t idx;
     207              :     unsigned linemap_id;
     208              :     hashval_t hash;
     209              :   };
     210              : 
     211              :   struct location_id_t
     212              :   {
     213              :     map_id_t map_id;
     214              :     location_t offset;
     215              :   };
     216              : 
     217              :   location_id_t record_location (location_t loc);
     218              : 
     219        21950 :   void register_map_id (size_t map_idx, unsigned linemap_id)
     220              :   {
     221        35106 :     gcc_checking_assert (LINEMAPS_ORDINARY_USED (line_table)
     222              :                          == orig_map_ids.length () + 1);
     223        21950 :     const auto map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
     224        21950 :     const hashval_t hash = compute_map_hash (map);
     225        21950 :     orig_map_ids.safe_push (map_id_t{map_idx, linemap_id, hash});
     226        21950 :   }
     227              : 
     228              :   void produce_linemap_section ();
     229              : 
     230              : private:
     231              :   struct map_data
     232              :   {
     233              :     size_t idx;
     234              :     hashval_t hash;
     235              :     location_t highest_location;
     236              :   };
     237              :   hash_map<nofree_ptr_hash<const line_map_ordinary>, map_data> map_data_map;
     238              :   vec<map_id_t> orig_map_ids = {};
     239              : };
     240              : 
     241              : location_output::location_id_t
     242      7125456 : location_output::record_location (location_t loc)
     243              : {
     244              :   /* Strip away any macro expansion data or embedded range information.  */
     245      7125456 :   loc = linemap_resolve_location (line_table, loc, LRK_MACRO_EXPANSION_POINT,
     246              :                                   nullptr);
     247      7125456 :   loc = get_pure_location (loc);
     248      7125456 :   location_id_t loc_id = {};
     249      7125456 :   if (loc < RESERVED_LOCATION_COUNT)
     250              :     {
     251              :       /* IDX 0 is for reserved locations.  */
     252      2496158 :       loc_id.offset = loc;
     253      2496158 :       return loc_id;
     254              :     }
     255              : 
     256      4629298 :   const auto map = linemap_check_ordinary (linemap_lookup (line_table, loc));
     257              : 
     258      4629298 :   if (flag_wpa || flag_incremental_link == INCREMENTAL_LINK_LTO)
     259              :     {
     260              :       /* In these modes, we don't create new locations, we only work with what
     261              :          was read, so we will re-output the locations in the same way.  */
     262       394740 :       gcc_checking_assert (orig_map_ids.length ()
     263              :                            == LINEMAPS_ORDINARY_USED (line_table));
     264       197370 :       gcc_checking_assert (!map->m_range_bits);
     265       197370 :       loc_id.map_id = orig_map_ids[map - line_table->info_ordinary.maps];
     266       197370 :       loc_id.offset = loc - map->start_location;
     267       197370 :       return loc_id;
     268              :     }
     269              : 
     270              :   /* Represent each location_t as the offset from the map start,
     271              :      without any range bits.  */
     272      4431928 :   map_data &md = map_data_map.get_or_insert (map);
     273      4431928 :   if (!md.idx)
     274              :     {
     275        43720 :       md.idx = map_data_map.elements ();
     276        43720 :       md.hash = compute_map_hash (map);
     277              :     }
     278      4431928 :   md.highest_location = MAX (md.highest_location, loc);
     279      4431928 :   loc_id.map_id.idx = md.idx;
     280      4431928 :   loc_id.map_id.hash = md.hash;
     281      4431928 :   loc_id.offset = (loc - map->start_location) >> map->m_range_bits;
     282      4431928 :   return loc_id;
     283              : }
     284              : 
     285              : /* Bitpack packing is more efficient for small values since every 4th bit is a
     286              :    continuation bit, so it helps to pack values as the delta from the previous
     287              :    if they can get large.  */
     288              : template<typename Int>
     289              : static void
     290      9086388 : bp_pack_delta (bitpack_d *bp, Int val, Int &prev)
     291              : {
     292      9086388 :   const bool decrease = (val < prev);
     293      9086388 :   bp_pack_value (bp, decrease, 1);
     294      9086388 :   bp_pack_var_len_unsigned (bp, decrease ? prev - val : val - prev);
     295      9086388 :   prev = val;
     296      9086388 : }
     297              : 
     298              : void
     299        24809 : location_output::produce_linemap_section ()
     300              : {
     301        24809 :   timevar_push (TV_IPA_LTO_LINEMAP_OUT);
     302              : 
     303        24809 :   const auto ob = create_output_block (LTO_section_linemap);
     304        24809 :   auto bp = bitpack_create (ob->main_stream);
     305              : 
     306              :   /* Prepare the diagnostic classification history.  To make life easier on the
     307              :      reader, which will need to build the line map before processing the
     308              :      classification history, we will stream it out after the line map data.  But
     309              :      we need to call record_location() now.  */
     310        24809 :   const auto &chist = global_dc->get_classification_history ();
     311        92473 :   for (auto &c : chist)
     312        64912 :     record_location (c.location);
     313              : 
     314              :   /* Sort the maps in the order they need to be inserted later.  */
     315        24809 :   const size_t nmaps = map_data_map.elements ();
     316        24809 :   using KV = std::pair<const line_map_ordinary *, map_data>;
     317        68529 :   const std::unique_ptr<KV[]> sorted_maps{new KV[nmaps]};
     318        24809 :   size_t map_i = 0;
     319        68529 :   for (auto iter = map_data_map.begin (), end = map_data_map.end ();
     320        68529 :        iter != end; ++iter)
     321        43720 :     sorted_maps[map_i++] = *iter;
     322        24809 :   gcc_qsort (sorted_maps.get (), nmaps, sizeof (KV),
     323              :              [] (const void *p1, const void *p2)
     324              :              {
     325              :                const auto map1 = static_cast<const KV *> (p1)->first;
     326              :                const auto map2 = static_cast<const KV *> (p2)->first;
     327              :                const location_t loc1 = map1->start_location;
     328              :                const location_t loc2 = map2->start_location;
     329              :                return (loc2 < loc1) - (loc1 < loc2);
     330              :              });
     331              : 
     332              :   /* Output the maps.  */
     333        24809 :   bp_pack_var_len_unsigned (&bp, nmaps);
     334        24809 :   const char *current_file = nullptr;
     335        24809 :   bool emit_pwd = true;
     336        24809 :   size_t prev_idx = 0;
     337        24809 :   linenum_type prev_line = 0;
     338        68529 :   for (map_i = 0; map_i != nmaps; ++map_i)
     339              :     {
     340        43720 :       const auto map = sorted_maps[map_i].first;
     341        43720 :       const map_data &md = sorted_maps[map_i].second;
     342        43720 :       bp_pack_delta (&bp, md.idx, prev_idx);
     343        43720 :       const auto num_lines
     344        43720 :         = 1 + ((md.highest_location - map->start_location)
     345        43720 :                >> map->m_column_and_range_bits);
     346        43720 :       bp_pack_var_len_unsigned (&bp, num_lines);
     347        43720 :       bp_pack_value (&bp, map->sysp != 0, 1);
     348        43720 :       bp_pack_value (&bp, map->m_column_and_range_bits - map->m_range_bits, 8);
     349        43720 :       bp_pack_delta (&bp, map->to_line, prev_line);
     350        43720 :       const bool file_change = (map->to_file != current_file);
     351        43720 :       bp_pack_value (&bp, file_change, 1);
     352        43720 :       if (file_change)
     353              :         {
     354        43720 :           bool stream_pwd = false;
     355        43720 :           const char *remapped = remap_debug_filename (map->to_file);
     356        43720 :           if (emit_pwd && remapped && !IS_ABSOLUTE_PATH (remapped))
     357              :             {
     358         2694 :               stream_pwd = true;
     359         2694 :               emit_pwd = false;
     360              :             }
     361        43720 :           bp_pack_value (&bp, stream_pwd, 1);
     362        43720 :           if (stream_pwd)
     363         2694 :             bp_pack_string (ob, &bp, get_src_pwd (), true);
     364        43720 :           bp_pack_string (ob, &bp, remapped, true);
     365              :         }
     366              :     }
     367              : 
     368              :   /* Output the diagnostics classification history.  */
     369        26185 :   bp_pack_var_len_unsigned (&bp, chist.length ());
     370        92473 :   for (auto &c : chist)
     371              :     {
     372        64912 :       const location_id_t loc_id = record_location (c.location);
     373        64912 :       bp_pack_var_len_unsigned (&bp, loc_id.map_id.idx);
     374        64912 :       bp_pack_var_len_unsigned (&bp, loc_id.offset);
     375        64912 :       bp_pack_var_len_int (&bp, c.option);
     376        64912 :       using DK = diagnostics::kind;
     377        64912 :       bp_pack_enum (&bp, DK, DK::tot_num_diagnostic_kinds, c.kind);
     378              :     }
     379              : 
     380              :   /* Finalize the section.  */
     381        24809 :   streamer_write_bitpack (&bp);
     382        24809 :   {
     383        24809 :     const auto section_name
     384        24809 :       = lto_get_section_name (LTO_section_linemap, nullptr, 0, nullptr);
     385        24809 :     lto_begin_section (section_name, true);
     386        24809 :     free (section_name);
     387              :   }
     388              : 
     389        24809 :   lto_simple_header_with_strings header = {};
     390        24809 :   header.main_size = ob->main_stream->total_size;
     391        24809 :   header.string_size = ob->string_stream->total_size;
     392        24809 :   lto_write_data (&header, sizeof header);
     393        24809 :   lto_write_stream (ob->main_stream);
     394        24809 :   lto_write_stream (ob->string_stream);
     395        24809 :   lto_end_section ();
     396        24809 :   destroy_output_block (ob);
     397              : 
     398        24809 :   timevar_pop (TV_IPA_LTO_LINEMAP_OUT);
     399        24809 : }
     400              : 
     401              : location_output loc_output;
     402              : 
     403              : } /* unnamed namespace */
     404              : 
     405              : /* Get a mapping index for LOC and stream it along with optional ancillary
     406              :    data.  */
     407              : 
     408              : static void
     409      6995632 : lto_output_location_1 (struct output_block *ob, struct bitpack_d *bp,
     410              :                        location_t loc, bool block_p)
     411              : {
     412      6995632 :   const auto loc_id = loc_output.record_location (loc);
     413      6995632 :   if (!loc_id.map_id.idx)
     414              :     {
     415      2496158 :       bp_pack_value (bp, true, 1);
     416      2496158 :       bp_pack_int_in_range (bp, 0, RESERVED_LOCATION_COUNT - 1, loc_id.offset);
     417              :     }
     418              :   else
     419              :     {
     420      4499474 :       bp_pack_value (bp, false, 1);
     421      4499474 :       if (loc_id.map_id.linemap_id == ob->current_linemap_id)
     422      4352066 :         bp_pack_value (bp, false, 1);
     423              :       else
     424              :         {
     425       147408 :           bp_pack_value (bp, true, 1);
     426       147408 :           bp_pack_var_len_unsigned (bp, loc_id.map_id.linemap_id);
     427       147408 :           ob->current_linemap_id = loc_id.map_id.linemap_id;
     428              :         }
     429      4499474 :       const bool is_new_map = (loc_id.map_id.idx != ob->current_map_idx);
     430      4499474 :       bp_pack_delta (bp, loc_id.map_id.idx, ob->current_map_idx);
     431      4499474 :       bp_pack_delta (bp, loc_id.offset, ob->current_loc_offset);
     432      4499474 :       if (is_new_map)
     433       230984 :         bp_pack_var_len_unsigned (bp, loc_id.map_id.hash);
     434      4499474 :       const unsigned discr = get_discriminator_from_loc (loc);
     435      4499474 :       bp_pack_value (bp, ob->current_discr != discr, 1);
     436      4499474 :       if (ob->current_discr != discr)
     437              :         {
     438      1355164 :           bp_pack_var_len_unsigned (bp, discr);
     439      1355164 :           ob->current_discr = discr;
     440              :         }
     441              :     }
     442              : 
     443      6995632 :   if (block_p)
     444              :     {
     445      3039374 :       tree block = LOCATION_BLOCK (loc);
     446      3039374 :       bp_pack_value (bp, ob->current_block != block, 1);
     447      3039374 :       streamer_write_bitpack (bp);
     448      3039374 :       if (ob->current_block != block)
     449              :         {
     450       664268 :           lto_output_tree (ob, block, true, true);
     451       664268 :           ob->current_block = block;
     452              :         }
     453              :     }
     454      6995632 : }
     455              : 
     456              : /* Output info about new location into bitpack BP.
     457              :    After outputting bitpack, lto_output_location_data has
     458              :    to be done to output actual data.  */
     459              : 
     460              : void
     461      3956258 : lto_output_location (struct output_block *ob, struct bitpack_d *bp,
     462              :                      location_t loc)
     463              : {
     464      3956258 :   lto_output_location_1 (ob, bp, loc, false);
     465      3956258 : }
     466              : 
     467              : /* Output info about new location into bitpack BP.
     468              :    After outputting bitpack, lto_output_location_data has
     469              :    to be done to output actual data.  Like lto_output_location, but
     470              :    additionally output LOCATION_BLOCK info too and write the BP bitpack.  */
     471              : 
     472              : void
     473      3039374 : lto_output_location_and_block (struct output_block *ob, struct bitpack_d *bp,
     474              :                                location_t loc)
     475              : {
     476      3039374 :   lto_output_location_1 (ob, bp, loc, true);
     477      3039374 : }
     478              : 
     479              : 
     480              : /* Lookup NAME in ENCODER.  If NAME is not found, create a new entry in
     481              :    ENCODER for NAME with the next available index of ENCODER,  then
     482              :    print the index to OBS.
     483              :    Return the index.  */
     484              : 
     485              : 
     486              : static unsigned
     487      8221150 : lto_get_index (struct lto_tree_ref_encoder *encoder, tree t)
     488              : {
     489      8221150 :   bool existed_p;
     490              : 
     491      8221150 :   unsigned int &index
     492      8221150 :     = encoder->tree_hash_table->get_or_insert (t, &existed_p);
     493      8221150 :   if (!existed_p)
     494              :     {
     495      2246649 :       index = encoder->trees.length ();
     496      2246649 :       if (streamer_dump_file)
     497              :         {
     498          176 :           print_node_brief (streamer_dump_file, "     Encoding indexable ",
     499              :                             t, 4);
     500          176 :           fprintf (streamer_dump_file, "  as %i \n", index);
     501              :         }
     502      2246649 :       encoder->trees.safe_push (t);
     503              :     }
     504              : 
     505      8221150 :   return index;
     506              : }
     507              : 
     508              : 
     509              : /* If EXPR is an indexable tree node, output a reference to it to
     510              :    output block OB.  Otherwise, output the physical representation of
     511              :    EXPR to OB.  */
     512              : 
     513              : static void
     514      9759818 : lto_indexable_tree_ref (struct output_block *ob, tree expr,
     515              :                         enum LTO_tags *tag, unsigned *index)
     516              : {
     517      9759818 :   gcc_checking_assert (tree_is_indexable (expr));
     518              : 
     519      9759818 :   if (TREE_CODE (expr) == SSA_NAME)
     520              :     {
     521      2259357 :       *tag = LTO_ssa_name_ref;
     522      2259357 :       *index = SSA_NAME_VERSION (expr);
     523              :     }
     524              :   else
     525              :     {
     526      7500461 :       *tag = LTO_global_stream_ref;
     527      7500461 :       *index = lto_get_index (&ob->decl_state->streams[LTO_DECL_STREAM], expr);
     528              :     }
     529      9759818 : }
     530              : 
     531              : 
     532              : /* Output a static or extern var DECL to OBS.  */
     533              : 
     534              : void
     535       291472 : lto_output_var_decl_ref (struct lto_out_decl_state *decl_state,
     536              :                          struct lto_output_stream * obs, tree decl)
     537              : {
     538       291472 :   gcc_checking_assert (VAR_P (decl));
     539       291472 :   streamer_write_uhwi_stream
     540       291472 :      (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM],
     541              :                           decl));
     542       291472 : }
     543              : 
     544              : 
     545              : /* Output a static or extern var DECL to OBS.  */
     546              : 
     547              : void
     548       429217 : lto_output_fn_decl_ref (struct lto_out_decl_state *decl_state,
     549              :                         struct lto_output_stream * obs, tree decl)
     550              : {
     551       429217 :   gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
     552       429217 :   streamer_write_uhwi_stream
     553       429217 :      (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM], decl));
     554       429217 : }
     555              : 
     556              : /* Return true if EXPR is a tree node that can be written to disk.  */
     557              : 
     558              : static inline bool
     559      7310011 : lto_is_streamable (tree expr)
     560              : {
     561      7310011 :   enum tree_code code = TREE_CODE (expr);
     562              : 
     563              :   /* Notice that we reject SSA_NAMEs as well.  We only emit the SSA
     564              :      name version in lto_output_tree_ref (see output_ssa_names).  */
     565      7310011 :   return !is_lang_specific (expr)
     566      7310011 :          && code != SSA_NAME
     567      7310011 :          && code != LANG_TYPE
     568              :          && code != MODIFY_EXPR
     569      7310011 :          && code != INIT_EXPR
     570      7310011 :          && code != TARGET_EXPR
     571      7310011 :          && code != BIND_EXPR
     572      7310011 :          && code != WITH_CLEANUP_EXPR
     573      7310011 :          && code != STATEMENT_LIST
     574      7310011 :          && (code == CASE_LABEL_EXPR
     575      7310011 :              || code == DECL_EXPR
     576      7301435 :              || code == ASM_EXPR
     577      7301395 :              || TREE_CODE_CLASS (code) != tcc_statement);
     578              : }
     579              : 
     580              : /* Very rough estimate of streaming size of the initializer.  If we ignored
     581              :    presence of strings, we could simply just count number of non-indexable
     582              :    tree nodes and number of references to indexable nodes.  Strings however
     583              :    may be very large and we do not want to dump them into the global stream.
     584              : 
     585              :    Count the size of initializer until the size in DATA is positive.  */
     586              : 
     587              : static tree
     588       103477 : subtract_estimated_size (tree *tp, int *ws, void *data)
     589              : {
     590       103477 :   long *sum = (long *)data;
     591       103477 :   if (tree_is_indexable (*tp))
     592              :     {
     593              :       /* Indexable tree is one reference to global stream.
     594              :          Guess it may be about 4 bytes.  */
     595         1599 :       *sum -= 4;
     596         1599 :       *ws = 0;
     597              :     }
     598              :   /* String table entry + base of tree node needs to be streamed.  */
     599       103477 :   if (TREE_CODE (*tp) == STRING_CST)
     600         8013 :     *sum -= TREE_STRING_LENGTH (*tp) + 8;
     601              :   else
     602              :     {
     603              :       /* Identifiers are also variable length but should not appear
     604              :          naked in constructor.  */
     605        95464 :       gcc_checking_assert (TREE_CODE (*tp) != IDENTIFIER_NODE);
     606              :       /* We do not really make attempt to work out size of pickled tree, as
     607              :          it is very variable. Make it bigger than the reference.  */
     608        95464 :       *sum -= 16;
     609              :     }
     610       103477 :   if (*sum < 0)
     611        33986 :     return *tp;
     612              :   return NULL_TREE;
     613              : }
     614              : 
     615              : 
     616              : /* For EXPR lookup and return what we want to stream to OB as DECL_INITIAL.  */
     617              : 
     618              : static tree
     619      2475217 : get_symbol_initial_value (lto_symtab_encoder_t encoder, tree expr)
     620              : {
     621      2475217 :   gcc_checking_assert (DECL_P (expr)
     622              :                        && TREE_CODE (expr) != FUNCTION_DECL
     623              :                        && TREE_CODE (expr) != TRANSLATION_UNIT_DECL);
     624              : 
     625              :   /* Handle DECL_INITIAL for symbols.  */
     626      2475217 :   tree initial = DECL_INITIAL (expr);
     627      2475217 :   if (VAR_P (expr)
     628      1228841 :       && (TREE_STATIC (expr) || DECL_EXTERNAL (expr))
     629       866657 :       && !DECL_IN_CONSTANT_POOL (expr)
     630      3341742 :       && initial)
     631              :     {
     632        87608 :       varpool_node *vnode;
     633              :       /* Extra section needs about 30 bytes; do not produce it for simple
     634              :          scalar values.  */
     635        87608 :       if (!(vnode = varpool_node::get (expr))
     636        87608 :           || !lto_symtab_encoder_encode_initializer_p (encoder, vnode))
     637         3289 :         initial = error_mark_node;
     638        87608 :       if (initial != error_mark_node)
     639              :         {
     640        70358 :           long max_size = 30;
     641        70358 :           if (walk_tree (&initial, subtract_estimated_size, (void *)&max_size,
     642              :                          NULL))
     643        33986 :             initial = error_mark_node;
     644              :         }
     645              :     }
     646              : 
     647      2475217 :   return initial;
     648              : }
     649              : 
     650              : 
     651              : /* Output reference to tree T to the stream.
     652              :    Assume that T is already in encoder cache.
     653              :    This is used to stream tree bodies where we know the DFS walk arranged
     654              :    everything to cache.  Must be matched with stream_read_tree_ref.  */
     655              : 
     656              : void
     657     33173766 : stream_write_tree_ref (struct output_block *ob, tree t)
     658              : {
     659     33173766 :   if (!t)
     660     12692007 :     streamer_write_zero (ob);
     661              :   else
     662              :     {
     663     20481759 :       unsigned int ix;
     664     20481759 :       bool existed_p = streamer_tree_cache_lookup (ob->writer_cache, t, &ix);
     665     20481759 :       if (existed_p)
     666     15895808 :         streamer_write_hwi (ob, ix + 1);
     667              :       else
     668              :         {
     669      4585951 :           enum LTO_tags tag;
     670      4585951 :           unsigned ix;
     671      4585951 :           int id = 0;
     672              : 
     673      4585951 :           lto_indexable_tree_ref (ob, t, &tag, &ix);
     674      4585951 :           if (tag == LTO_ssa_name_ref)
     675              :             id = 1;
     676              :           else
     677      4374422 :             gcc_checking_assert (tag == LTO_global_stream_ref);
     678      4585951 :           streamer_write_hwi (ob, -(int)(ix * 2 + id + 1));
     679              :         }
     680              :     }
     681     33173766 : }
     682              : 
     683              : 
     684              : 
     685              : /* Write a physical representation of tree node EXPR to output block
     686              :    OB.  If REF_P is true, the leaves of EXPR are emitted as references
     687              :    via lto_output_tree_ref.  IX is the index into the streamer cache
     688              :    where EXPR is stored.  */
     689              : 
     690              : static void
     691      7310011 : lto_write_tree_1 (struct output_block *ob, tree expr, bool ref_p)
     692              : {
     693      7310011 :   if (streamer_dump_file)
     694              :     {
     695          420 :       print_node_brief (streamer_dump_file, "     Streaming body of ",
     696              :                         expr, 4);
     697          420 :       fprintf (streamer_dump_file, "  to %s\n",
     698          420 :                lto_section_name[ob->section_type]);
     699              :     }
     700              : 
     701              :   /* Pack all the non-pointer fields in EXPR into a bitpack and write
     702              :      the resulting bitpack.  */
     703      7310011 :   streamer_write_tree_bitfields (ob, expr);
     704              : 
     705              :   /* Write all the pointer fields in EXPR.  */
     706      7310011 :   streamer_write_tree_body (ob, expr);
     707              : 
     708              :   /* Write any LTO-specific data to OB.  */
     709      7310011 :   if (DECL_P (expr)
     710      1569938 :       && TREE_CODE (expr) != FUNCTION_DECL
     711      1126486 :       && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
     712              :     {
     713              :       /* Handle DECL_INITIAL for symbols.  */
     714      1091981 :       tree initial = get_symbol_initial_value
     715      1091981 :                          (ob->decl_state->symtab_node_encoder, expr);
     716      1091981 :       stream_write_tree (ob, initial, ref_p);
     717              :     }
     718              : 
     719              :   /* Stream references to early generated DIEs.  Keep in sync with the
     720              :      trees handled in dwarf2out_die_ref_for_decl.  */
     721      7310011 :   if ((DECL_P (expr)
     722              :        && TREE_CODE (expr) != FIELD_DECL
     723              :        && TREE_CODE (expr) != DEBUG_EXPR_DECL
     724              :        && TREE_CODE (expr) != TYPE_DECL)
     725      5881621 :       || TREE_CODE (expr) == BLOCK)
     726              :     {
     727      1787914 :       const char *sym;
     728      1787914 :       unsigned HOST_WIDE_INT off;
     729      1787914 :       if (debug_info_level > DINFO_LEVEL_NONE
     730      1787914 :           && debug_hooks->die_ref_for_decl (expr, DEBUG_DIE_REF, &sym, &off))
     731              :         {
     732        50008 :           streamer_write_string (ob, ob->main_stream, sym, true);
     733        50008 :           streamer_write_uhwi (ob, off);
     734              :         }
     735              :       else
     736      1737906 :         streamer_write_string (ob, ob->main_stream, NULL, true);
     737              :     }
     738              : 
     739      7310011 :   if (lto_origin_ref_node_p (expr))
     740              :     {
     741       802976 :       const char *sym;
     742       802976 :       unsigned HOST_WIDE_INT off;
     743       802976 :       if (debug_info_level > DINFO_LEVEL_NONE
     744       802976 :           && debug_hooks->die_ref_for_decl (expr, DEBUG_ABSTRACT_ORIGIN_REF,
     745              :                                             &sym, &off))
     746              :         {
     747          816 :           streamer_write_uhwi (ob, LTO_ORIGIN_REF_DIE);
     748          816 :           streamer_write_string (ob, ob->main_stream, sym, true);
     749          816 :           streamer_write_uhwi (ob, off);
     750              :         }
     751       802160 :       else if (flag_wpa || flag_incremental_link == INCREMENTAL_LINK_LTO)
     752        86075 :         streamer_write_uhwi (ob, LTO_ORIGIN_REF_NONE);
     753              :       else
     754       716085 :         streamer_write_uhwi (ob, LTO_ORIGIN_REF_TREE);
     755              :     }
     756      7310011 : }
     757              : 
     758              : /* Write a physical representation of tree node EXPR to output block
     759              :    OB.  If REF_P is true, the leaves of EXPR are emitted as references
     760              :    via lto_output_tree_ref.  IX is the index into the streamer cache
     761              :    where EXPR is stored.  */
     762              : 
     763              : static void
     764      7026141 : lto_write_tree (struct output_block *ob, tree expr, bool ref_p)
     765              : {
     766      7026141 :   if (!lto_is_streamable (expr))
     767            0 :     internal_error ("tree code %qs is not supported in LTO streams",
     768            0 :                     get_tree_code_name (TREE_CODE (expr)));
     769              : 
     770              :   /* Write the header, containing everything needed to materialize
     771              :      EXPR on the reading side.  */
     772      7026141 :   streamer_write_tree_header (ob, expr);
     773              : 
     774      7026141 :   lto_write_tree_1 (ob, expr, ref_p);
     775      7026141 : }
     776              : 
     777              : /* Emit the physical representation of tree node EXPR to output block OB,
     778              :    If THIS_REF_P is true, the leaves of EXPR are emitted as references via
     779              :    lto_output_tree_ref.  REF_P is used for streaming siblings of EXPR.  */
     780              : 
     781              : static void
     782      8141487 : lto_output_tree_1 (struct output_block *ob, tree expr, hashval_t hash,
     783              :                    bool ref_p, bool this_ref_p)
     784              : {
     785      8141487 :   unsigned ix;
     786              : 
     787      8141487 :   gcc_checking_assert (expr != NULL_TREE
     788              :                        && !(this_ref_p && tree_is_indexable (expr)));
     789              : 
     790      8141487 :   bool exists_p = streamer_tree_cache_insert (ob->writer_cache,
     791              :                                               expr, hash, &ix);
     792      8141487 :   gcc_assert (!exists_p);
     793      8141487 :   if (TREE_CODE (expr) == INTEGER_CST
     794      8141487 :       && !TREE_OVERFLOW (expr))
     795              :     {
     796              :       /* Shared INTEGER_CST nodes are special because they need their
     797              :          original type to be materialized by the reader (to implement
     798              :          TYPE_CACHED_VALUES).  */
     799      1115346 :       streamer_write_integer_cst (ob, expr);
     800              :     }
     801              :   else
     802              :     {
     803              :       /* This is the first time we see EXPR, write its fields
     804              :          to OB.  */
     805      7026141 :       lto_write_tree (ob, expr, ref_p);
     806              :     }
     807      8141487 : }
     808              : 
     809              : class DFS
     810              : {
     811              : public:
     812              :   DFS (struct output_block *ob, tree expr, bool ref_p, bool this_ref_p,
     813              :        bool single_p);
     814              :   ~DFS ();
     815              : 
     816              :   struct scc_entry
     817              :   {
     818              :     tree t;
     819              :     hashval_t hash;
     820              :   };
     821              :   auto_vec<scc_entry,32> sccstack;
     822              : 
     823              : private:
     824              :   struct sccs
     825              :   {
     826              :     unsigned int dfsnum;
     827              :     unsigned int low;
     828              :   };
     829              :   struct worklist
     830              :   {
     831              :     tree expr;
     832              :     sccs *from_state;
     833              :     sccs *cstate;
     834              :     bool ref_p;
     835              :     bool this_ref_p;
     836              :   };
     837              :   /* Maximum index of scc stack containing a local tree.  */
     838              :   int max_local_entry;
     839              : 
     840              :   static int scc_entry_compare (const void *, const void *);
     841              : 
     842              :   void DFS_write_tree_body (struct output_block *ob,
     843              :                             tree expr, sccs *expr_state, bool ref_p);
     844              : 
     845              :   void DFS_write_tree (struct output_block *ob, sccs *from_state,
     846              :                        tree expr, bool ref_p, bool this_ref_p);
     847              : 
     848              :   hashval_t
     849              :   hash_scc (struct output_block *ob, unsigned first, unsigned size,
     850              :             bool ref_p, bool this_ref_p);
     851              : 
     852              :   hash_map<tree, sccs *> sccstate;
     853              :   auto_vec<worklist, 32> worklist_vec;
     854              :   struct obstack sccstate_obstack;
     855              : };
     856              : 
     857              : /* Return true if type can not be merged with structurally same tree in
     858              :    other translation unit.  During stream out this information is propagated
     859              :    to all trees referring to T and they are not streamed with additional
     860              :    information needed by the tree merging in lto-common.cc (in particular,
     861              :    scc hash codes are not streamed).
     862              : 
     863              :    TRANSLATION_UNIT_DECL is handled specially since references to it does
     864              :    not make other trees local as well.  */
     865              : 
     866              : static bool
     867      2948794 : local_tree_p (tree t)
     868              : {
     869      2948794 :   switch (TREE_CODE (t))
     870              :     {
     871              :     case LABEL_DECL:
     872              :       return true;
     873         1674 :     case NAMESPACE_DECL:
     874         1674 :       return !DECL_NAME (t);
     875       627052 :     case VAR_DECL:
     876       627052 :     case FUNCTION_DECL:
     877       627052 :       return !TREE_PUBLIC (t) && !DECL_EXTERNAL (t);
     878        75842 :     case RECORD_TYPE:
     879        75842 :     case UNION_TYPE:
     880        75842 :     case ENUMERAL_TYPE:
     881              :       /* Anonymous namespace types are local.
     882              :          Only work hard for main variants;
     883              :          variant types will inherit locality.  */
     884        75842 :       return TYPE_MAIN_VARIANT (t) == t
     885        60493 :              && odr_type_p (t) && type_with_linkage_p (t)
     886        96586 :              && type_in_anonymous_namespace_p (t);
     887              :     default:
     888              :       return false;
     889              :     }
     890              : }
     891              : 
     892              : /* Emit the physical representation of tree node EXPR to output block OB,
     893              :    using depth-first search on the subgraph.  If THIS_REF_P is true, the
     894              :    leaves of EXPR are emitted as references via lto_output_tree_ref.
     895              :    REF_P is used for streaming siblings of EXPR.  If SINGLE_P is true,
     896              :    this is for a rewalk of a single leaf SCC.  */
     897              : 
     898      3094269 : DFS::DFS (struct output_block *ob, tree expr, bool ref_p, bool this_ref_p,
     899      3094269 :           bool single_p)
     900              : {
     901      3094269 :   unsigned int next_dfs_num = 1;
     902              : 
     903      3094269 :   max_local_entry = -1;
     904      3094269 :   gcc_obstack_init (&sccstate_obstack);
     905      3094269 :   DFS_write_tree (ob, NULL, expr, ref_p, this_ref_p);
     906     22480926 :   while (!worklist_vec.is_empty ())
     907              :     {
     908     18431178 :       worklist &w = worklist_vec.last ();
     909     18431178 :       expr = w.expr;
     910     18431178 :       sccs *from_state = w.from_state;
     911     18431178 :       sccs *cstate = w.cstate;
     912     18431178 :       ref_p = w.ref_p;
     913     18431178 :       this_ref_p = w.this_ref_p;
     914     18431178 :       if (cstate == NULL)
     915              :         {
     916      9994871 :           sccs **slot = &sccstate.get_or_insert (expr);
     917      9994871 :           cstate = *slot;
     918      9994871 :           if (cstate)
     919              :             {
     920      1558564 :               gcc_checking_assert (from_state);
     921      1558564 :               if (cstate->dfsnum < from_state->dfsnum)
     922       198172 :                 from_state->low = MIN (cstate->dfsnum, from_state->low);
     923      1558564 :               worklist_vec.pop ();
     924      1558564 :               continue;
     925              :             }
     926              : 
     927      8436307 :           scc_entry e = { expr, 0 };
     928              :           /* Not yet visited.  DFS recurse and push it onto the stack.  */
     929      8436307 :           *slot = cstate = XOBNEW (&sccstate_obstack, struct sccs);
     930      8436307 :           if (ob->local_trees && local_tree_p (expr))
     931        89238 :             max_local_entry = sccstack.length ();
     932      8436307 :           sccstack.safe_push (e);
     933      8436307 :           cstate->dfsnum = next_dfs_num++;
     934      8436307 :           cstate->low = cstate->dfsnum;
     935      8436307 :           w.cstate = cstate;
     936              : 
     937      8436307 :           if (TREE_CODE (expr) == INTEGER_CST
     938      8436307 :               && !TREE_OVERFLOW (expr))
     939      1162376 :             DFS_write_tree (ob, cstate, TREE_TYPE (expr), ref_p, ref_p);
     940              :           else
     941              :             {
     942      7273931 :               DFS_write_tree_body (ob, expr, cstate, ref_p);
     943              : 
     944              :               /* Walk any LTO-specific edges.  */
     945      7273931 :               if (DECL_P (expr)
     946      1573648 :                   && TREE_CODE (expr) != FUNCTION_DECL
     947      1130196 :                   && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
     948              :                 {
     949              :                   /* Handle DECL_INITIAL for symbols.  */
     950      1095691 :                   tree initial
     951      1095691 :                     = get_symbol_initial_value (ob->decl_state->symtab_node_encoder,
     952              :                                                 expr);
     953      1095691 :                   DFS_write_tree (ob, cstate, initial, ref_p, ref_p);
     954              :                 }
     955              :             }
     956      8436307 :           continue;
     957      8436307 :         }
     958              : 
     959              :       /* See if we found an SCC.  */
     960      8436307 :       if (cstate->low == cstate->dfsnum)
     961              :         {
     962      8226463 :           unsigned first, size;
     963      8226463 :           tree x;
     964              : 
     965              :           /* If we are re-walking a single leaf SCC just pop it,
     966              :              let earlier worklist item access the sccstack.  */
     967      8226463 :           if (single_p)
     968              :             {
     969          347 :               worklist_vec.pop ();
     970          347 :               continue;
     971              :             }
     972              : 
     973              :           /* Pop the SCC and compute its size.  */
     974     16452232 :           first = sccstack.length ();
     975      8425357 :           do
     976              :             {
     977      8425357 :               x = sccstack[--first].t;
     978              :             }
     979      8425357 :           while (x != expr);
     980      8226116 :           size = sccstack.length () - first;
     981              : 
     982              :           /* No need to compute hashes for LTRANS units, we don't perform
     983              :              any merging there.  */
     984      8226116 :           hashval_t scc_hash = 0;
     985      8226116 :           unsigned scc_entry_len = 0;
     986     21941454 :           bool local_to_unit = !ob->local_trees
     987      8226116 :                                || max_local_entry >= (int)first;
     988              : 
     989              :           /* Remember that trees are local so info gets propagated to other
     990              :              SCCs.  */
     991      5489222 :           if (local_to_unit && ob->local_trees)
     992              :             {
     993        99382 :               for (unsigned i = 0; i < size; ++i)
     994        51175 :                 ob->local_trees->add (sccstack[first + i].t);
     995              :             }
     996              : 
     997              :           /* As a special case do not stream TRANSLATION_UNIT_DECL as shared
     998              :              tree.  We can not mark it local because references to it does not
     999              :              make other trees local (all global decls refer to it via
    1000              :              CONTEXT).  */
    1001      8226116 :           if (size == 1
    1002      8226116 :               && TREE_CODE (sccstack[first].t) == TRANSLATION_UNIT_DECL)
    1003              :             local_to_unit = true;
    1004              : 
    1005      8191611 :           if (!local_to_unit)
    1006              :             {
    1007      2712269 :               scc_hash = hash_scc (ob, first, size, ref_p, this_ref_p);
    1008              : 
    1009              :               /* Put the entries with the least number of collisions first.  */
    1010      2712269 :               unsigned entry_start = 0;
    1011      2712269 :               scc_entry_len = size + 1;
    1012      5574313 :               for (unsigned i = 0; i < size;)
    1013              :                 {
    1014      2862044 :                   unsigned from = i;
    1015      2862044 :                   for (i = i + 1; i < size
    1016      2862044 :                        && (sccstack[first + i].hash
    1017       149775 :                            == sccstack[first + from].hash); ++i)
    1018              :                     ;
    1019      2862044 :                   if (i - from < scc_entry_len)
    1020              :                     {
    1021      2712269 :                       scc_entry_len = i - from;
    1022      2712269 :                       entry_start = from;
    1023              :                     }
    1024              :                 }
    1025      5424538 :               for (unsigned i = 0; i < scc_entry_len; ++i)
    1026      2712269 :                 std::swap (sccstack[first + i],
    1027      2712269 :                            sccstack[first + entry_start + i]);
    1028              : 
    1029              :               /* We already sorted SCC deterministically in hash_scc.  */
    1030              : 
    1031              :               /* Check that we have only one SCC.
    1032              :                  Naturally we may have conflicts if hash function is not
    1033              :                  strong enough.  Lets see how far this gets.  */
    1034      2712269 :               gcc_checking_assert (scc_entry_len == 1);
    1035              :             }
    1036              : 
    1037      8226116 :           worklist_vec.pop ();
    1038              : 
    1039      8226116 :           unsigned int prev_size = ob->main_stream->total_size;
    1040              : 
    1041              :           /* Only global decl sections are considered by tree merging.  */
    1042      8226116 :           if (ob->section_type != LTO_section_decls)
    1043              :             {
    1044              :               /* If this is the original tree we stream and it forms SCC
    1045              :                  by itself then we do not need to stream SCC at all.  */
    1046      4674119 :               if (worklist_vec.is_empty () && first == 0 && size == 1)
    1047              :                  return;
    1048      2535329 :               if (streamer_dump_file)
    1049              :                 {
    1050          140 :                   fprintf (streamer_dump_file,
    1051              :                            "     Start of LTO_trees of size %i\n", size);
    1052              :                 }
    1053      2535329 :               streamer_write_record_start (ob, LTO_trees);
    1054      2535329 :               streamer_write_uhwi (ob, size);
    1055              :             }
    1056              :           /* Write LTO_tree_scc if tree merging is going to be performed.  */
    1057      3551997 :           else if (!local_to_unit
    1058              :                    /* These are special since sharing is not done by tree
    1059              :                       merging machinery.  We can not special case them earlier
    1060              :                       because we still need to compute hash for further sharing
    1061              :                       of trees referring to them.  */
    1062      3551997 :                    && (size != 1
    1063      2643894 :                        || (TREE_CODE (sccstack[first].t) != IDENTIFIER_NODE
    1064      1747869 :                            && (TREE_CODE (sccstack[first].t) != INTEGER_CST
    1065       161132 :                                || TREE_OVERFLOW (sccstack[first].t)))))
    1066              : 
    1067              :             {
    1068      1655114 :               gcc_checking_assert (ob->section_type == LTO_section_decls);
    1069      1655114 :               if (streamer_dump_file)
    1070              :                 {
    1071          172 :                   fprintf (streamer_dump_file,
    1072              :                            "     Start of LTO_tree_scc of size %i\n", size);
    1073              :                 }
    1074      1655114 :               streamer_write_record_start (ob, LTO_tree_scc);
    1075              :               /* In wast majority of cases scc_entry_len is 1 and size is small
    1076              :                  integer.  Use extra bit of size to stream info about
    1077              :                  exceptions.  */
    1078      1655114 :               streamer_write_uhwi (ob, size * 2 + (scc_entry_len != 1));
    1079      1655114 :               if (scc_entry_len != 1)
    1080            0 :                 streamer_write_uhwi (ob, scc_entry_len);
    1081      1655114 :               streamer_write_uhwi (ob, scc_hash);
    1082              :             }
    1083              :           /* Non-trivial SCCs must be packed to trees blocks so forward
    1084              :              references work correctly.  */
    1085      1896883 :           else if (size != 1)
    1086              :             {
    1087        16120 :               if (streamer_dump_file)
    1088              :                 {
    1089            0 :                   fprintf (streamer_dump_file,
    1090              :                            "     Start of LTO_trees of size %i\n", size);
    1091              :                 }
    1092        16120 :               streamer_write_record_start (ob, LTO_trees);
    1093        16120 :               streamer_write_uhwi (ob, size);
    1094              :             }
    1095      1880763 :           else if (streamer_dump_file)
    1096              :             {
    1097          108 :               fprintf (streamer_dump_file, "     Streaming single tree\n");
    1098              :             }
    1099              : 
    1100              :           /* Write size-1 SCCs without wrapping them inside SCC bundles.
    1101              :              All INTEGER_CSTs need to be handled this way as we need
    1102              :              their type to materialize them.  Also builtins are handled
    1103              :              this way.  */
    1104      6087326 :           if (size == 1)
    1105      6002697 :             lto_output_tree_1 (ob, expr, scc_hash, ref_p, this_ref_p);
    1106              :           else
    1107              :             {
    1108              : 
    1109              :               /* Write all headers and populate the streamer cache.  */
    1110       368499 :               for (unsigned i = 0; i < size; ++i)
    1111              :                 {
    1112       283870 :                   hashval_t hash = sccstack[first+i].hash;
    1113       283870 :                   tree t = sccstack[first+i].t;
    1114       283870 :                   bool exists_p = streamer_tree_cache_insert (ob->writer_cache,
    1115              :                                                               t, hash, NULL);
    1116       283870 :                   gcc_assert (!exists_p);
    1117              : 
    1118       283870 :                   if (!lto_is_streamable (t))
    1119            0 :                     internal_error ("tree code %qs is not supported "
    1120              :                                     "in LTO streams",
    1121            0 :                                     get_tree_code_name (TREE_CODE (t)));
    1122              : 
    1123              :                   /* Write the header, containing everything needed to
    1124              :                      materialize EXPR on the reading side.  */
    1125       283870 :                   streamer_write_tree_header (ob, t);
    1126              :                 }
    1127              : 
    1128              :               /* Write the bitpacks and tree references.  */
    1129       368499 :               for (unsigned i = 0; i < size; ++i)
    1130       283870 :                 lto_write_tree_1 (ob, sccstack[first+i].t, ref_p);
    1131              :             }
    1132      6087326 :           if (streamer_dump_file)
    1133          420 :             fprintf (streamer_dump_file, "     %u bytes\n",
    1134          420 :                      ob->main_stream->total_size - prev_size);
    1135              : 
    1136              :           /* Finally truncate the vector.  */
    1137      6087326 :           sccstack.truncate (first);
    1138      6087326 :           if ((int)first <= max_local_entry)
    1139        48207 :             max_local_entry = first - 1;
    1140              : 
    1141      6087326 :           if (from_state)
    1142      5132194 :             from_state->low = MIN (from_state->low, cstate->low);
    1143      6087326 :           continue;
    1144      6087326 :         }
    1145              : 
    1146       209844 :       gcc_checking_assert (from_state);
    1147       209844 :       from_state->low = MIN (from_state->low, cstate->low);
    1148       209844 :       if (cstate->dfsnum < from_state->dfsnum)
    1149            0 :         from_state->low = MIN (cstate->dfsnum, from_state->low);
    1150       209844 :       worklist_vec.pop ();
    1151              :     }
    1152              : }
    1153              : 
    1154      3094269 : DFS::~DFS ()
    1155              : {
    1156      3094269 :   obstack_free (&sccstate_obstack, NULL);
    1157      3094269 : }
    1158              : 
    1159              : /* Handle the tree EXPR in the DFS walk with SCC state EXPR_STATE and
    1160              :    DFS recurse for all tree edges originating from it.  */
    1161              : 
    1162              : void
    1163      7273931 : DFS::DFS_write_tree_body (struct output_block *ob,
    1164              :                           tree expr, sccs *expr_state, bool ref_p)
    1165              : {
    1166              : #define DFS_follow_tree_edge(DEST) \
    1167              :   DFS_write_tree (ob, expr_state, DEST, ref_p, ref_p)
    1168              : 
    1169      7273931 :   enum tree_code code;
    1170              : 
    1171      7273931 :   code = TREE_CODE (expr);
    1172              : 
    1173      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
    1174              :     {
    1175      6847048 :       if (TREE_CODE (expr) != IDENTIFIER_NODE)
    1176      5316536 :         DFS_follow_tree_edge (TREE_TYPE (expr));
    1177              :     }
    1178              : 
    1179      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
    1180              :     {
    1181         6172 :       unsigned int count = vector_cst_encoded_nelts (expr);
    1182        33031 :       for (unsigned int i = 0; i < count; ++i)
    1183        20687 :         DFS_follow_tree_edge (VECTOR_CST_ENCODED_ELT (expr, i));
    1184              :     }
    1185              : 
    1186      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_POLY_INT_CST))
    1187            0 :     for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
    1188            0 :       DFS_follow_tree_edge (POLY_INT_CST_COEFF (expr, i));
    1189              : 
    1190      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
    1191              :     {
    1192         8015 :       DFS_follow_tree_edge (TREE_REALPART (expr));
    1193         8015 :       DFS_follow_tree_edge (TREE_IMAGPART (expr));
    1194              :     }
    1195              : 
    1196      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
    1197              :     {
    1198              :       /* Drop names that were created for anonymous entities.  */
    1199      1573648 :       if (DECL_NAME (expr)
    1200      1383019 :           && TREE_CODE (DECL_NAME (expr)) == IDENTIFIER_NODE
    1201      2956667 :           && IDENTIFIER_ANON_P (DECL_NAME (expr)))
    1202              :         ;
    1203              :       else
    1204      1573035 :         DFS_follow_tree_edge (DECL_NAME (expr));
    1205      1573648 :       if (TREE_CODE (expr) != TRANSLATION_UNIT_DECL
    1206      1573648 :           && ! DECL_CONTEXT (expr))
    1207        15931 :         DFS_follow_tree_edge ((*all_translation_units)[0]);
    1208              :       else
    1209      1557717 :         DFS_follow_tree_edge (DECL_CONTEXT (expr));
    1210              :     }
    1211              : 
    1212      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
    1213              :     {
    1214      1573648 :       DFS_follow_tree_edge (DECL_SIZE (expr));
    1215      1573648 :       DFS_follow_tree_edge (DECL_SIZE_UNIT (expr));
    1216              : 
    1217              :       /* Note, DECL_INITIAL is not handled here.  Since DECL_INITIAL needs
    1218              :          special handling in LTO, it must be handled by streamer hooks.  */
    1219              : 
    1220      1573648 :       DFS_follow_tree_edge (DECL_ATTRIBUTES (expr));
    1221              : 
    1222              :       /* We use DECL_ABSTRACT_ORIGIN == error_mark_node to mark
    1223              :          declarations which should be eliminated by decl merging. Be sure none
    1224              :          leaks to this point.  */
    1225      1573648 :       gcc_assert (DECL_ABSTRACT_ORIGIN (expr) != error_mark_node);
    1226      1573648 :       DFS_follow_tree_edge (DECL_ABSTRACT_ORIGIN (expr));
    1227              : 
    1228      1573648 :       if ((VAR_P (expr)
    1229      1573648 :            || TREE_CODE (expr) == PARM_DECL)
    1230      1573648 :           && DECL_HAS_VALUE_EXPR_P (expr))
    1231         6633 :         DFS_follow_tree_edge (DECL_VALUE_EXPR (expr));
    1232      1573648 :       if (VAR_P (expr)
    1233      1573648 :           && DECL_HAS_DEBUG_EXPR_P (expr))
    1234         1705 :         DFS_follow_tree_edge (DECL_DEBUG_EXPR (expr));
    1235              :     }
    1236              : 
    1237      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
    1238              :     {
    1239              :       /* Make sure we don't inadvertently set the assembler name.  */
    1240       945230 :       if (DECL_ASSEMBLER_NAME_SET_P (expr))
    1241       760574 :         DFS_follow_tree_edge (DECL_ASSEMBLER_NAME (expr));
    1242              :     }
    1243              : 
    1244      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
    1245              :     {
    1246       115917 :       DFS_follow_tree_edge (DECL_FIELD_OFFSET (expr));
    1247       115917 :       DFS_follow_tree_edge (DECL_BIT_FIELD_TYPE (expr));
    1248       115917 :       DFS_follow_tree_edge (DECL_BIT_FIELD_REPRESENTATIVE (expr));
    1249       115917 :       DFS_follow_tree_edge (DECL_FIELD_BIT_OFFSET (expr));
    1250       115917 :       gcc_checking_assert (!DECL_FCONTEXT (expr));
    1251              :     }
    1252              : 
    1253      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
    1254              :     {
    1255       443452 :       gcc_checking_assert (DECL_VINDEX (expr) == NULL);
    1256       443452 :       DFS_follow_tree_edge (DECL_FUNCTION_PERSONALITY (expr));
    1257       443452 :       DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_TARGET (expr));
    1258       443452 :       DFS_follow_tree_edge (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (expr));
    1259              :     }
    1260              : 
    1261      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
    1262              :     {
    1263       681777 :       DFS_follow_tree_edge (TYPE_SIZE (expr));
    1264       681777 :       DFS_follow_tree_edge (TYPE_SIZE_UNIT (expr));
    1265       681777 :       DFS_follow_tree_edge (TYPE_ATTRIBUTES (expr));
    1266       681777 :       DFS_follow_tree_edge (TYPE_NAME (expr));
    1267              :       /* Do not follow TYPE_POINTER_TO or TYPE_REFERENCE_TO.  They will be
    1268              :          reconstructed during fixup.  */
    1269              :       /* Do not follow TYPE_NEXT_VARIANT, we reconstruct the variant lists
    1270              :          during fixup.  */
    1271       681777 :       DFS_follow_tree_edge (TYPE_MAIN_VARIANT (expr));
    1272       681777 :       DFS_follow_tree_edge (TYPE_CONTEXT (expr));
    1273              :       /* TYPE_CANONICAL is re-computed during type merging, so no need
    1274              :          to follow it here.  */
    1275              :       /* Do not stream TYPE_STUB_DECL; it is not needed by LTO but currently
    1276              :          it cannot be freed by free_lang_data without triggering ICEs in
    1277              :          langhooks.  */
    1278              :     }
    1279              : 
    1280      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
    1281              :     {
    1282       681777 :       if (TREE_CODE (expr) == ARRAY_TYPE)
    1283        48080 :         DFS_follow_tree_edge (TYPE_DOMAIN (expr));
    1284       633697 :       else if (RECORD_OR_UNION_TYPE_P (expr))
    1285       250612 :         for (tree t = TYPE_FIELDS (expr); t; t = TREE_CHAIN (t))
    1286       153662 :           DFS_follow_tree_edge (t);
    1287       536747 :       else if (FUNC_OR_METHOD_TYPE_P (expr))
    1288       182922 :         DFS_follow_tree_edge (TYPE_ARG_TYPES (expr));
    1289              : 
    1290       681777 :       if (!POINTER_TYPE_P (expr))
    1291       413765 :         DFS_follow_tree_edge (TYPE_MIN_VALUE_RAW (expr));
    1292       681777 :       DFS_follow_tree_edge (TYPE_MAX_VALUE_RAW (expr));
    1293              :     }
    1294              : 
    1295      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_LIST))
    1296              :     {
    1297       705039 :       DFS_follow_tree_edge (TREE_PURPOSE (expr));
    1298       705039 :       DFS_follow_tree_edge (TREE_VALUE (expr));
    1299       705039 :       DFS_follow_tree_edge (TREE_CHAIN (expr));
    1300              :     }
    1301              : 
    1302      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_VEC))
    1303              :     {
    1304           10 :       for (int i = 0; i < TREE_VEC_LENGTH (expr); i++)
    1305            8 :         DFS_follow_tree_edge (TREE_VEC_ELT (expr, i));
    1306              :     }
    1307              : 
    1308      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_EXP))
    1309              :     {
    1310      4422737 :       for (int i = 0; i < TREE_OPERAND_LENGTH (expr); i++)
    1311      2622557 :         DFS_follow_tree_edge (TREE_OPERAND (expr, i));
    1312      1800180 :       DFS_follow_tree_edge (TREE_BLOCK (expr));
    1313              :     }
    1314              : 
    1315      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_BLOCK))
    1316              :     {
    1317       509938 :       for (tree t = BLOCK_VARS (expr); t; t = TREE_CHAIN (t))
    1318              :         {
    1319              :           /* We would have to stream externals in the block chain as
    1320              :              non-references but we should have dropped them in
    1321              :              free-lang-data.  */
    1322       150414 :           gcc_assert (!VAR_OR_FUNCTION_DECL_P (t) || !DECL_EXTERNAL (t));
    1323       150414 :           DFS_follow_tree_edge (t);
    1324              :         }
    1325              : 
    1326       359524 :       DFS_follow_tree_edge (BLOCK_SUPERCONTEXT (expr));
    1327       359524 :       DFS_follow_tree_edge (BLOCK_ABSTRACT_ORIGIN (expr));
    1328              : 
    1329              :       /* Do not follow BLOCK_NONLOCALIZED_VARS.  We cannot handle debug
    1330              :          information for early inlined BLOCKs so drop it on the floor instead
    1331              :          of ICEing in dwarf2out.cc.  */
    1332              : 
    1333              :       /* BLOCK_FRAGMENT_ORIGIN and BLOCK_FRAGMENT_CHAIN is not live at LTO
    1334              :          streaming time.  */
    1335              : 
    1336              :       /* Do not output BLOCK_SUBBLOCKS.  Instead on streaming-in this
    1337              :          list is re-constructed from BLOCK_SUPERCONTEXT.  */
    1338              :     }
    1339              : 
    1340      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
    1341              :     {
    1342              :       unsigned i;
    1343              :       tree t;
    1344              : 
    1345              :       /* Note that the number of BINFO slots has already been emitted in
    1346              :          EXPR's header (see streamer_write_tree_header) because this length
    1347              :          is needed to build the empty BINFO node on the reader side.  */
    1348        20429 :       FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (expr), i, t)
    1349        10842 :         DFS_follow_tree_edge (t);
    1350         9587 :       DFS_follow_tree_edge (BINFO_OFFSET (expr));
    1351         9587 :       DFS_follow_tree_edge (BINFO_VTABLE (expr));
    1352              : 
    1353              :       /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX,
    1354              :          BINFO_BASE_ACCESSES and BINFO_VPTR_INDEX; these are used
    1355              :          by C++ FE only.  */
    1356              :     }
    1357              : 
    1358      7273931 :   if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
    1359              :     {
    1360              :       unsigned i;
    1361              :       tree index, value;
    1362              : 
    1363       773634 :       FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (expr), i, index, value)
    1364              :         {
    1365       534621 :           DFS_follow_tree_edge (index);
    1366       534621 :           DFS_follow_tree_edge (value);
    1367              :         }
    1368              :     }
    1369              : 
    1370      7273931 :   if (code == RAW_DATA_CST)
    1371           21 :     DFS_follow_tree_edge (RAW_DATA_OWNER (expr));
    1372              : 
    1373      7273931 :   if (code == OMP_CLAUSE)
    1374              :     {
    1375              :       int i;
    1376          635 :       for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (expr)]; i++)
    1377          406 :         DFS_follow_tree_edge (OMP_CLAUSE_OPERAND (expr, i));
    1378          229 :       DFS_follow_tree_edge (OMP_CLAUSE_CHAIN (expr));
    1379              :     }
    1380              : 
    1381              : #undef DFS_follow_tree_edge
    1382      7273931 : }
    1383              : 
    1384              : /* Return a hash value for the tree T.
    1385              :    CACHE holds hash values of trees outside current SCC.  MAP, if non-NULL,
    1386              :    may hold hash values if trees inside current SCC.  */
    1387              : 
    1388              : static hashval_t
    1389      2862044 : hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map, tree t)
    1390              : {
    1391      2862044 :   inchash::hash hstate;
    1392              : 
    1393              : #define visit(SIBLING) \
    1394              :   do { \
    1395              :     unsigned ix; \
    1396              :     if (!SIBLING) \
    1397              :       hstate.add_int (0); \
    1398              :     else if (streamer_tree_cache_lookup (cache, SIBLING, &ix)) \
    1399              :       hstate.add_int (streamer_tree_cache_get_hash (cache, ix)); \
    1400              :     else if (map) \
    1401              :       hstate.add_int (*map->get (SIBLING)); \
    1402              :     else \
    1403              :       hstate.add_int (1); \
    1404              :   } while (0)
    1405              : 
    1406              :   /* Hash TS_BASE.  */
    1407      2862044 :   enum tree_code code = TREE_CODE (t);
    1408      2862044 :   hstate.add_int (code);
    1409      2862044 :   if (!TYPE_P (t))
    1410              :     {
    1411      2389295 :       hstate.add_flag (TREE_SIDE_EFFECTS (t));
    1412      2389295 :       hstate.add_flag (TREE_CONSTANT (t));
    1413      2389295 :       hstate.add_flag (TREE_READONLY (t));
    1414      2389295 :       hstate.add_flag (TREE_PUBLIC (t));
    1415              :     }
    1416      2862044 :   hstate.add_flag (TREE_ADDRESSABLE (t));
    1417      2862044 :   hstate.add_flag (TREE_THIS_VOLATILE (t));
    1418      2862044 :   if (DECL_P (t))
    1419       691579 :     hstate.add_flag (DECL_UNSIGNED (t));
    1420      2170465 :   else if (TYPE_P (t))
    1421       472749 :     hstate.add_flag (TYPE_UNSIGNED (t));
    1422      2862044 :   if (TYPE_P (t))
    1423       472749 :     hstate.add_flag (TYPE_ARTIFICIAL (t));
    1424              :   else
    1425      2389295 :     hstate.add_flag (TREE_NO_WARNING (t));
    1426      2862044 :   hstate.add_flag (TREE_NOTHROW (t));
    1427      2862044 :   hstate.add_flag (TREE_STATIC (t));
    1428      2862044 :   hstate.add_flag (TREE_PROTECTED (t));
    1429      2862044 :   hstate.add_flag (TREE_DEPRECATED (t));
    1430      2862044 :   if (code != TREE_BINFO)
    1431      2855700 :     hstate.add_flag (TREE_PRIVATE (t));
    1432      2862044 :   if (TYPE_P (t))
    1433              :     {
    1434       472749 :       hstate.add_flag (AGGREGATE_TYPE_P (t)
    1435       472749 :                        ? TYPE_REVERSE_STORAGE_ORDER (t) : TYPE_SATURATING (t));
    1436       472749 :       hstate.add_flag (TYPE_ADDR_SPACE (t));
    1437              :     }
    1438      2389295 :   else if (code == SSA_NAME)
    1439            0 :     hstate.add_flag (SSA_NAME_IS_DEFAULT_DEF (t));
    1440      2862044 :   hstate.commit_flag ();
    1441              : 
    1442      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_INT_CST))
    1443       193562 :     hstate.add_wide_int (wi::to_widest (t));
    1444              : 
    1445      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_REAL_CST))
    1446              :     {
    1447         1714 :       REAL_VALUE_TYPE r = TREE_REAL_CST (t);
    1448         1714 :       hstate.add_flag (r.cl);
    1449         1714 :       hstate.add_flag (r.sign);
    1450         1714 :       hstate.add_flag (r.signalling);
    1451         1714 :       hstate.add_flag (r.canonical);
    1452         1714 :       hstate.commit_flag ();
    1453         1714 :       hstate.add_int (r.uexp);
    1454         1714 :       hstate.add (r.sig, sizeof (r.sig));
    1455              :     }
    1456              : 
    1457      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_FIXED_CST))
    1458              :     {
    1459            0 :       FIXED_VALUE_TYPE f = TREE_FIXED_CST (t);
    1460            0 :       hstate.add_int (f.mode);
    1461            0 :       hstate.add_int (f.data.low);
    1462            0 :       hstate.add_int (f.data.high);
    1463              :     }
    1464              : 
    1465      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
    1466              :     {
    1467              :       /* Similar to TYPE_MODE, avoid streaming out host-specific DECL_MODE
    1468              :          for aggregate type with offloading enabled, and while streaming-in
    1469              :          recompute appropriate DECL_MODE for accelerator.  */
    1470       691579 :       if (lto_stream_offload_p
    1471            0 :           && (VAR_P (t)
    1472            0 :               || TREE_CODE (t) == PARM_DECL
    1473            0 :               || TREE_CODE (t) == FIELD_DECL)
    1474       691579 :           && AGGREGATE_TYPE_P (TREE_TYPE (t)))
    1475            0 :         hstate.add_hwi (VOIDmode);
    1476              :       else
    1477       691579 :         hstate.add_hwi (DECL_MODE (t));
    1478       691579 :       hstate.add_flag (DECL_NONLOCAL (t));
    1479       691579 :       hstate.add_flag (DECL_VIRTUAL_P (t));
    1480       691579 :       hstate.add_flag (DECL_IGNORED_P (t));
    1481       691579 :       hstate.add_flag (DECL_ABSTRACT_P (t));
    1482       691579 :       hstate.add_flag (DECL_ARTIFICIAL (t));
    1483       691579 :       hstate.add_flag (DECL_USER_ALIGN (t));
    1484       691579 :       hstate.add_flag (DECL_PRESERVE_P (t));
    1485       691579 :       hstate.add_flag (DECL_EXTERNAL (t));
    1486       691579 :       hstate.add_flag (DECL_NOT_GIMPLE_REG_P (t));
    1487       691579 :       hstate.commit_flag ();
    1488       691579 :       hstate.add_int (DECL_ALIGN (t));
    1489       691579 :       if (code == LABEL_DECL)
    1490              :         {
    1491            0 :           hstate.add_int (EH_LANDING_PAD_NR (t));
    1492            0 :           hstate.add_int (LABEL_DECL_UID (t));
    1493              :         }
    1494       691579 :       else if (code == FIELD_DECL)
    1495              :         {
    1496        83126 :           hstate.add_flag (DECL_PACKED (t));
    1497        83126 :           hstate.add_flag (DECL_NONADDRESSABLE_P (t));
    1498        83126 :           hstate.add_flag (DECL_PADDING_P (t));
    1499        83126 :           if (DECL_BIT_FIELD (t))
    1500         5082 :             hstate.add_flag (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (t));
    1501              :           else
    1502       159957 :             hstate.add_flag (DECL_FIELD_ABI_IGNORED (t));
    1503        83126 :           hstate.add_int (DECL_OFFSET_ALIGN (t));
    1504              :         }
    1505       608453 :       else if (code == VAR_DECL)
    1506              :         {
    1507       236118 :           hstate.add_flag (DECL_HAS_DEBUG_EXPR_P (t));
    1508       236118 :           hstate.add_flag (DECL_NONLOCAL_FRAME (t));
    1509              :         }
    1510       691579 :       if (code == RESULT_DECL
    1511       691579 :           || code == PARM_DECL
    1512              :           || code == VAR_DECL)
    1513              :         {
    1514       236130 :           hstate.add_flag (DECL_BY_REFERENCE (t));
    1515       236130 :           if (code == VAR_DECL
    1516       236130 :               || code == PARM_DECL)
    1517       236130 :             hstate.add_flag (DECL_HAS_VALUE_EXPR_P (t));
    1518              :         }
    1519       691579 :       hstate.commit_flag ();
    1520              :     }
    1521              : 
    1522      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_DECL_WRTL))
    1523       608449 :     hstate.add_int (DECL_REGISTER (t));
    1524              : 
    1525      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
    1526              :     {
    1527       608437 :       hstate.add_flag (DECL_COMMON (t));
    1528       608437 :       hstate.add_flag (DECL_DLLIMPORT_P (t));
    1529       608437 :       hstate.add_flag (DECL_WEAK (t));
    1530       608437 :       hstate.add_flag (DECL_SEEN_IN_BIND_EXPR_P (t));
    1531       608437 :       hstate.add_flag (DECL_COMDAT (t));
    1532       608437 :       hstate.add_flag (DECL_VISIBILITY_SPECIFIED (t));
    1533       608437 :       hstate.add_int (DECL_VISIBILITY (t));
    1534       608437 :       if (code == VAR_DECL)
    1535              :         {
    1536              :           /* DECL_IN_TEXT_SECTION is set during final asm output only.  */
    1537       236118 :           hstate.add_flag (DECL_HARD_REGISTER (t));
    1538       236118 :           hstate.add_flag (DECL_IN_CONSTANT_POOL (t));
    1539              :         }
    1540       608437 :       if (TREE_CODE (t) == FUNCTION_DECL)
    1541              :         {
    1542       349153 :           hstate.add_flag (DECL_FINAL_P (t));
    1543       349153 :           hstate.add_flag (DECL_CXX_CONSTRUCTOR_P (t));
    1544       349153 :           hstate.add_flag (DECL_CXX_DESTRUCTOR_P (t));
    1545              :         }
    1546       608437 :       hstate.commit_flag ();
    1547              :     }
    1548              : 
    1549      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
    1550              :     {
    1551       349153 :       hstate.add_int (DECL_BUILT_IN_CLASS (t));
    1552       349153 :       hstate.add_flag (DECL_STATIC_CONSTRUCTOR (t));
    1553       349153 :       hstate.add_flag (DECL_STATIC_DESTRUCTOR (t));
    1554       349153 :       hstate.add_int ((unsigned)FUNCTION_DECL_DECL_TYPE (t));
    1555       349153 :       hstate.add_flag (DECL_UNINLINABLE (t));
    1556       349153 :       hstate.add_flag (DECL_POSSIBLY_INLINED (t));
    1557       349153 :       hstate.add_flag (DECL_IS_NOVOPS (t));
    1558       349153 :       hstate.add_flag (DECL_IS_RETURNS_TWICE (t));
    1559       349153 :       hstate.add_flag (DECL_IS_MALLOC (t));
    1560       349153 :       hstate.add_flag (DECL_DECLARED_INLINE_P (t));
    1561       349153 :       hstate.add_flag (DECL_STATIC_CHAIN (t));
    1562       349153 :       hstate.add_flag (DECL_NO_INLINE_WARNING_P (t));
    1563       349153 :       hstate.add_flag (DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (t));
    1564       349153 :       hstate.add_flag (DECL_NO_LIMIT_STACK (t));
    1565       349153 :       hstate.add_flag (DECL_DISREGARD_INLINE_LIMITS (t));
    1566       349153 :       hstate.add_flag (DECL_PURE_P (t));
    1567       349153 :       hstate.add_flag (DECL_LOOPING_CONST_OR_PURE_P (t));
    1568       349153 :       hstate.commit_flag ();
    1569       349153 :       if (DECL_BUILT_IN_CLASS (t) != NOT_BUILT_IN)
    1570        23066 :         hstate.add_int (DECL_UNCHECKED_FUNCTION_CODE (t));
    1571              :     }
    1572              : 
    1573      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
    1574              :     {
    1575              :       /* For offloading, avoid streaming out TYPE_MODE for aggregate type since
    1576              :          it may be host-specific. For eg, aarch64 uses OImode for ARRAY_TYPE
    1577              :          whose size is 256-bits, which is not representable on accelerator.
    1578              :          Instead stream out VOIDmode, and while streaming-in, recompute
    1579              :          appropriate TYPE_MODE for accelerator.  */
    1580       472749 :       if (lto_stream_offload_p
    1581            0 :           && (AGGREGATE_TYPE_P (t) || VECTOR_TYPE_P (t)))
    1582            0 :         hstate.add_hwi (VOIDmode);
    1583              :       /* for VECTOR_TYPE, TYPE_MODE reevaluates the mode using target_flags
    1584              :          not necessary valid in a global context.
    1585              :          Use the raw value previously set by layout_type.  */
    1586              :       else
    1587       472749 :         hstate.add_hwi (TYPE_MODE_RAW (t));
    1588              :       /* TYPE_NO_FORCE_BLK is private to stor-layout and need
    1589              :          no streaming.  */
    1590       472749 :       hstate.add_flag (TYPE_PACKED (t));
    1591       472749 :       hstate.add_flag (TYPE_RESTRICT (t));
    1592       472749 :       hstate.add_flag (TYPE_USER_ALIGN (t));
    1593       472749 :       hstate.add_flag (TYPE_READONLY (t));
    1594       472749 :       if (RECORD_OR_UNION_TYPE_P (t))
    1595              :         {
    1596        73049 :           hstate.add_flag (TYPE_TRANSPARENT_AGGR (t));
    1597        73049 :           hstate.add_flag (TYPE_FINAL_P (t));
    1598        73049 :           hstate.add_flag (TYPE_CXX_ODR_P (t));
    1599              :         }
    1600       399700 :       else if (code == ARRAY_TYPE)
    1601        30295 :         hstate.add_flag (TYPE_NONALIASED_COMPONENT (t));
    1602       472749 :       if (code == ARRAY_TYPE || code == INTEGER_TYPE)
    1603        76792 :         hstate.add_flag (TYPE_STRING_FLAG (t));
    1604       472749 :       if (AGGREGATE_TYPE_P (t))
    1605       103344 :         hstate.add_flag (TYPE_TYPELESS_STORAGE (t));
    1606       472749 :       hstate.commit_flag ();
    1607       472749 :       hstate.add_int (TYPE_PRECISION_RAW (t));
    1608       472749 :       hstate.add_int (TYPE_ALIGN (t));
    1609       472749 :       if (!lto_stream_offload_p)
    1610       472749 :         hstate.add_int (TYPE_EMPTY_P (t));
    1611              :     }
    1612              : 
    1613      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_TRANSLATION_UNIT_DECL))
    1614            0 :     hstate.add (TRANSLATION_UNIT_LANGUAGE (t),
    1615            0 :                         strlen (TRANSLATION_UNIT_LANGUAGE (t)));
    1616              : 
    1617      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION)
    1618              :       /* We don't stream these when passing things to a different target.  */
    1619        24335 :       && !lto_stream_offload_p)
    1620        24335 :     hstate.add_hwi (cl_target_option_hash (TREE_TARGET_OPTION (t)));
    1621              : 
    1622      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
    1623        24551 :     hstate.add_hwi (cl_optimization_hash (TREE_OPTIMIZATION (t)));
    1624              : 
    1625      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_IDENTIFIER))
    1626       896025 :     hstate.merge_hash (IDENTIFIER_HASH_VALUE (t));
    1627              : 
    1628      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_STRING))
    1629         4423 :     hstate.add (TREE_STRING_POINTER (t), TREE_STRING_LENGTH (t));
    1630              : 
    1631      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
    1632              :     {
    1633      2813158 :       if (code != IDENTIFIER_NODE)
    1634      1917133 :         visit (TREE_TYPE (t));
    1635              :     }
    1636              : 
    1637      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_VECTOR))
    1638              :     {
    1639            0 :       unsigned int count = vector_cst_encoded_nelts (t);
    1640            0 :       for (unsigned int i = 0; i < count; ++i)
    1641            0 :         visit (VECTOR_CST_ENCODED_ELT (t, i));
    1642              :     }
    1643              : 
    1644      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_POLY_INT_CST))
    1645            0 :     for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
    1646            0 :       visit (POLY_INT_CST_COEFF (t, i));
    1647              : 
    1648      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_COMPLEX))
    1649              :     {
    1650            0 :       visit (TREE_REALPART (t));
    1651            0 :       visit (TREE_IMAGPART (t));
    1652              :     }
    1653              : 
    1654      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
    1655              :     {
    1656              :       /* Drop names that were created for anonymous entities.  */
    1657       691579 :       if (DECL_NAME (t)
    1658       674092 :           && TREE_CODE (DECL_NAME (t)) == IDENTIFIER_NODE
    1659      1365671 :           && IDENTIFIER_ANON_P (DECL_NAME (t)))
    1660              :         ;
    1661              :       else
    1662       691222 :         visit (DECL_NAME (t));
    1663       691579 :       if (DECL_FILE_SCOPE_P (t))
    1664              :         ;
    1665              :       else
    1666       113664 :         visit (DECL_CONTEXT (t));
    1667              :     }
    1668              : 
    1669      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
    1670              :     {
    1671       691579 :       visit (DECL_SIZE (t));
    1672       691579 :       visit (DECL_SIZE_UNIT (t));
    1673       691579 :       visit (DECL_ATTRIBUTES (t));
    1674       691579 :       if ((code == VAR_DECL
    1675       691579 :            || code == PARM_DECL)
    1676       691579 :           && DECL_HAS_VALUE_EXPR_P (t))
    1677           20 :         visit (DECL_VALUE_EXPR (t));
    1678       691579 :       if (code == VAR_DECL
    1679       927697 :           && DECL_HAS_DEBUG_EXPR_P (t))
    1680            0 :         visit (DECL_DEBUG_EXPR (t));
    1681              :       /* ???  Hash DECL_INITIAL as streamed.  Needs the output-block to
    1682              :          be able to call get_symbol_initial_value.  */
    1683              :     }
    1684              : 
    1685      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
    1686              :     {
    1687       608437 :       if (DECL_ASSEMBLER_NAME_SET_P (t))
    1688       605959 :         visit (DECL_ASSEMBLER_NAME (t));
    1689              :     }
    1690              : 
    1691      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_FIELD_DECL))
    1692              :     {
    1693        83126 :       visit (DECL_FIELD_OFFSET (t));
    1694        83126 :       visit (DECL_BIT_FIELD_TYPE (t));
    1695        83126 :       visit (DECL_BIT_FIELD_REPRESENTATIVE (t));
    1696        83126 :       visit (DECL_FIELD_BIT_OFFSET (t));
    1697              :     }
    1698              : 
    1699      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_FUNCTION_DECL))
    1700              :     {
    1701       349153 :       visit (DECL_FUNCTION_PERSONALITY (t));
    1702       349153 :       visit (DECL_FUNCTION_SPECIFIC_TARGET (t));
    1703       349153 :       visit (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (t));
    1704              :     }
    1705              : 
    1706      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
    1707              :     {
    1708       472749 :       visit (TYPE_SIZE (t));
    1709       472749 :       visit (TYPE_SIZE_UNIT (t));
    1710       472749 :       visit (TYPE_ATTRIBUTES (t));
    1711       472749 :       visit (TYPE_NAME (t));
    1712       472749 :       visit (TYPE_MAIN_VARIANT (t));
    1713       472749 :       if (TYPE_FILE_SCOPE_P (t))
    1714              :         ;
    1715              :       else
    1716        16394 :         visit (TYPE_CONTEXT (t));
    1717              :     }
    1718              : 
    1719      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_TYPE_NON_COMMON))
    1720              :     {
    1721       472749 :       if (code == ARRAY_TYPE)
    1722        30295 :         visit (TYPE_DOMAIN (t));
    1723       442454 :       else if (RECORD_OR_UNION_TYPE_P (t))
    1724       180270 :         for (tree f = TYPE_FIELDS (t); f; f = TREE_CHAIN (f))
    1725       107221 :           visit (f);
    1726       369405 :       else if (code == FUNCTION_TYPE
    1727       369405 :                || code == METHOD_TYPE)
    1728       118868 :         visit (TYPE_ARG_TYPES (t));
    1729       472749 :       if (!POINTER_TYPE_P (t))
    1730       279439 :         visit (TYPE_MIN_VALUE_RAW (t));
    1731       472749 :       visit (TYPE_MAX_VALUE_RAW (t));
    1732              :     }
    1733              : 
    1734      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_LIST))
    1735              :     {
    1736       538627 :       visit (TREE_PURPOSE (t));
    1737       538627 :       visit (TREE_VALUE (t));
    1738       538627 :       visit (TREE_CHAIN (t));
    1739              :     }
    1740              : 
    1741      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_VEC))
    1742            0 :     for (int i = 0; i < TREE_VEC_LENGTH (t); ++i)
    1743            0 :       visit (TREE_VEC_ELT (t, i));
    1744              : 
    1745      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_EXP))
    1746              :     {
    1747         7577 :       hstate.add_hwi (TREE_OPERAND_LENGTH (t));
    1748        18988 :       for (int i = 0; i < TREE_OPERAND_LENGTH (t); ++i)
    1749        11411 :         visit (TREE_OPERAND (t, i));
    1750              :     }
    1751              : 
    1752      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_BINFO))
    1753              :     {
    1754              :       unsigned i;
    1755              :       tree b;
    1756        12757 :       FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (t), i, b)
    1757         6413 :         visit (b);
    1758         6344 :       visit (BINFO_OFFSET (t));
    1759         6344 :       visit (BINFO_VTABLE (t));
    1760              :       /* Do not walk BINFO_INHERITANCE_CHAIN, BINFO_SUBVTT_INDEX
    1761              :          BINFO_BASE_ACCESSES and BINFO_VPTR_INDEX; these are used
    1762              :          by C++ FE only.  */
    1763              :     }
    1764              : 
    1765      2862044 :   if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
    1766              :     {
    1767          404 :       unsigned i;
    1768          404 :       tree index, value;
    1769          622 :       hstate.add_hwi (CONSTRUCTOR_NELTS (t));
    1770         1761 :       FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), i, index, value)
    1771              :         {
    1772         1357 :           visit (index);
    1773         1357 :           visit (value);
    1774              :         }
    1775              :     }
    1776              : 
    1777      2862044 :   if (code == OMP_CLAUSE)
    1778              :     {
    1779          148 :       int i;
    1780          148 :       HOST_WIDE_INT val;
    1781              : 
    1782          148 :       hstate.add_hwi (OMP_CLAUSE_CODE (t));
    1783          148 :       switch (OMP_CLAUSE_CODE (t))
    1784              :         {
    1785            0 :         case OMP_CLAUSE_DEFAULT:
    1786            0 :           val = OMP_CLAUSE_DEFAULT_KIND (t);
    1787            0 :           break;
    1788            0 :         case OMP_CLAUSE_SCHEDULE:
    1789            0 :           val = OMP_CLAUSE_SCHEDULE_KIND (t);
    1790            0 :           break;
    1791            0 :         case OMP_CLAUSE_DEPEND:
    1792            0 :           val = OMP_CLAUSE_DEPEND_KIND (t);
    1793            0 :           break;
    1794            0 :         case OMP_CLAUSE_DOACROSS:
    1795            0 :           val = OMP_CLAUSE_DOACROSS_KIND (t);
    1796            0 :           break;
    1797            0 :         case OMP_CLAUSE_MAP:
    1798            0 :           val = OMP_CLAUSE_MAP_KIND (t);
    1799            0 :           break;
    1800            0 :         case OMP_CLAUSE_PROC_BIND:
    1801            0 :           val = OMP_CLAUSE_PROC_BIND_KIND (t);
    1802            0 :           break;
    1803            0 :         case OMP_CLAUSE_REDUCTION:
    1804            0 :         case OMP_CLAUSE_TASK_REDUCTION:
    1805            0 :         case OMP_CLAUSE_IN_REDUCTION:
    1806            0 :           val = OMP_CLAUSE_REDUCTION_CODE (t);
    1807            0 :           break;
    1808              :         default:
    1809              :           val = 0;
    1810              :           break;
    1811              :         }
    1812          148 :       hstate.add_hwi (val);
    1813          400 :       for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (t)]; i++)
    1814          252 :         visit (OMP_CLAUSE_OPERAND (t, i));
    1815          148 :       visit (OMP_CLAUSE_CHAIN (t));
    1816              :     }
    1817              : 
    1818      2862044 :   return hstate.end ();
    1819              : 
    1820              : #undef visit
    1821              : }
    1822              : 
    1823              : /* Compare two SCC entries by their hash value for qsorting them.  */
    1824              : 
    1825              : int
    1826      1588322 : DFS::scc_entry_compare (const void *p1_, const void *p2_)
    1827              : {
    1828      1588322 :   const scc_entry *p1 = (const scc_entry *) p1_;
    1829      1588322 :   const scc_entry *p2 = (const scc_entry *) p2_;
    1830      1588322 :   if (p1->hash < p2->hash)
    1831              :     return -1;
    1832       715460 :   else if (p1->hash > p2->hash)
    1833       694024 :     return 1;
    1834              :   return 0;
    1835              : }
    1836              : 
    1837              : /* Return a hash value for the SCC on the SCC stack from FIRST with SIZE.
    1838              :    THIS_REF_P and REF_P are as passed to lto_output_tree for FIRST.  */
    1839              : 
    1840              : hashval_t
    1841      2712269 : DFS::hash_scc (struct output_block *ob, unsigned first, unsigned size,
    1842              :                bool ref_p, bool this_ref_p)
    1843              : {
    1844      2712269 :   unsigned int last_classes = 0, iterations = 0;
    1845              : 
    1846              :   /* Compute hash values for the SCC members.  */
    1847      5574313 :   for (unsigned i = 0; i < size; ++i)
    1848      2862044 :     sccstack[first+i].hash
    1849      5724088 :       = hash_tree (ob->writer_cache, NULL, sccstack[first+i].t);
    1850              : 
    1851      2712269 :   if (size == 1)
    1852      2643894 :     return sccstack[first].hash;
    1853              : 
    1854              :   /* We aim to get unique hash for every tree within SCC and compute hash value
    1855              :      of the whole SCC by combining all values together in a stable (entry-point
    1856              :      independent) order.  This guarantees that the same SCC regions within
    1857              :      different translation units will get the same hash values and therefore
    1858              :      will be merged at WPA time.
    1859              : 
    1860              :      Often the hashes are already unique.  In that case we compute the SCC hash
    1861              :      by combining individual hash values in an increasing order.
    1862              : 
    1863              :      If there are duplicates, we seek at least one tree with unique hash (and
    1864              :      pick one with minimal hash and this property).  Then we obtain a stable
    1865              :      order by DFS walk starting from this unique tree and then use the index
    1866              :      within this order to make individual hash values unique.
    1867              : 
    1868              :      If there is no tree with unique hash, we iteratively propagate the hash
    1869              :      values across the internal edges of SCC.  This usually quickly leads
    1870              :      to unique hashes.  Consider, for example, an SCC containing two pointers
    1871              :      that are identical except for the types they point to and assume that
    1872              :      these types are also part of the SCC.  The propagation will add the
    1873              :      points-to type information into their hash values.  */
    1874        68375 :   do
    1875              :     {
    1876              :       /* Sort the SCC so we can easily check for uniqueness.  */
    1877        68375 :       qsort (&sccstack[first], size, sizeof (scc_entry), scc_entry_compare);
    1878              : 
    1879        68375 :       unsigned int classes = 1;
    1880        68375 :       int firstunique = -1;
    1881              : 
    1882              :       /* Find the tree with lowest unique hash (if it exists) and compute
    1883              :          the number of equivalence classes.  */
    1884        68375 :       if (sccstack[first].hash != sccstack[first+1].hash)
    1885        68372 :         firstunique = 0;
    1886       218150 :       for (unsigned i = 1; i < size; ++i)
    1887       149775 :         if (sccstack[first+i-1].hash != sccstack[first+i].hash)
    1888              :           {
    1889       147808 :             classes++;
    1890       147808 :             if (firstunique == -1
    1891       147808 :                 && (i == size - 1
    1892            3 :                     || sccstack[first+i+1].hash != sccstack[first+i].hash))
    1893            3 :               firstunique = i;
    1894              :           }
    1895              : 
    1896              :       /* If we found a tree with unique hash, stop the iteration.  */
    1897        68375 :       if (firstunique != -1
    1898              :           /* Also terminate if we run out of iterations or if the number of
    1899              :              equivalence classes is no longer increasing.
    1900              :              For example a cyclic list of trees that are all equivalent will
    1901              :              never have unique entry point; we however do not build such SCCs
    1902              :              in our IL.  */
    1903        68375 :           || classes <= last_classes || iterations > 16)
    1904              :         {
    1905        68375 :           hashval_t scc_hash;
    1906              : 
    1907              :           /* If some hashes are not unique (CLASSES != SIZE), use the DFS walk
    1908              :              starting from FIRSTUNIQUE to obtain a stable order.  */
    1909        68375 :           if (classes != size && firstunique != -1)
    1910              :             {
    1911          347 :               hash_map <tree, hashval_t> map(size*2);
    1912              : 
    1913              :               /* Store hash values into a map, so we can associate them with
    1914              :                  the reordered SCC.  */
    1915        11644 :               for (unsigned i = 0; i < size; ++i)
    1916        10950 :                 map.put (sccstack[first+i].t, sccstack[first+i].hash);
    1917              : 
    1918          347 :               DFS again (ob, sccstack[first+firstunique].t, ref_p, this_ref_p,
    1919          347 :                          true);
    1920          694 :               gcc_assert (again.sccstack.length () == size);
    1921              : 
    1922          347 :               memcpy (sccstack.address () + first,
    1923          347 :                       again.sccstack.address (),
    1924              :                       sizeof (scc_entry) * size);
    1925              : 
    1926              :               /* Update hash values of individual members by hashing in the
    1927              :                  index within the stable order.  This ensures uniqueness.
    1928              :                  Also compute the SCC hash by mixing in all hash values in
    1929              :                  the stable order we obtained.  */
    1930          347 :               sccstack[first].hash = *map.get (sccstack[first].t);
    1931          347 :               scc_hash = sccstack[first].hash;
    1932        10950 :               for (unsigned i = 1; i < size; ++i)
    1933              :                 {
    1934        31809 :                   sccstack[first+i].hash
    1935        10603 :                     = iterative_hash_hashval_t (i,
    1936        10603 :                                                 *map.get (sccstack[first+i].t));
    1937        10603 :                   scc_hash
    1938        10603 :                     = iterative_hash_hashval_t (scc_hash,
    1939        10603 :                                                 sccstack[first+i].hash);
    1940              :                 }
    1941          347 :             }
    1942              :           /* If we got a unique hash value for each tree, then sort already
    1943              :              ensured entry-point independent order.  Only compute the final
    1944              :              SCC hash.
    1945              : 
    1946              :              If we failed to find the unique entry point, we go by the same
    1947              :              route.  We will eventually introduce unwanted hash conflicts.  */
    1948              :           else
    1949              :             {
    1950              :               scc_hash = sccstack[first].hash;
    1951       207200 :               for (unsigned i = 1; i < size; ++i)
    1952       139172 :                 scc_hash
    1953       139172 :                   = iterative_hash_hashval_t (scc_hash, sccstack[first+i].hash);
    1954              : 
    1955              :               /* We cannot 100% guarantee that the hash won't conflict so as
    1956              :                  to make it impossible to find a unique hash.  This however
    1957              :                  should be an extremely rare case.  ICE for now so possible
    1958              :                  issues are found and evaluated.  */
    1959        68028 :               gcc_checking_assert (classes == size);
    1960              :             }
    1961              : 
    1962              :           /* To avoid conflicts across SCCs, iteratively hash the whole SCC
    1963              :              hash into the hash of each element.  */
    1964       286525 :           for (unsigned i = 0; i < size; ++i)
    1965       436300 :             sccstack[first+i].hash
    1966       218150 :               = iterative_hash_hashval_t (sccstack[first+i].hash, scc_hash);
    1967        68375 :           return scc_hash;
    1968              :         }
    1969              : 
    1970            0 :       last_classes = classes;
    1971            0 :       iterations++;
    1972              : 
    1973              :       /* We failed to identify the entry point; propagate hash values across
    1974              :          the edges.  */
    1975            0 :       hash_map <tree, hashval_t> map(size*2);
    1976              : 
    1977            0 :       for (unsigned i = 0; i < size; ++i)
    1978            0 :         map.put (sccstack[first+i].t, sccstack[first+i].hash);
    1979              : 
    1980            0 :       for (unsigned i = 0; i < size; i++)
    1981            0 :         sccstack[first+i].hash
    1982            0 :           = hash_tree (ob->writer_cache, &map, sccstack[first+i].t);
    1983            0 :     }
    1984              :   while (true);
    1985              : }
    1986              : 
    1987              : /* DFS walk EXPR and stream SCCs of tree bodies if they are not
    1988              :    already in the streamer cache.  Main routine called for
    1989              :    each visit of EXPR.  */
    1990              : 
    1991              : void
    1992     36787906 : DFS::DFS_write_tree (struct output_block *ob, sccs *from_state,
    1993              :                      tree expr, bool ref_p, bool this_ref_p)
    1994              : {
    1995              :   /* Handle special cases.  */
    1996     36787906 :   if (expr == NULL_TREE)
    1997     26793035 :     return;
    1998              : 
    1999              :   /* Do not DFS walk into indexable trees.  */
    2000     23998598 :   if (this_ref_p && tree_is_indexable (expr))
    2001              :     return;
    2002              : 
    2003              :   /* Check if we already streamed EXPR.  */
    2004     17515908 :   if (streamer_tree_cache_lookup (ob->writer_cache, expr, NULL))
    2005              :     {
    2006              :       /* Reference to a local tree makes entry also local.  We always process
    2007              :          top of stack entry, so set max to number of entries in stack - 1.  */
    2008      7521037 :       if (ob->local_trees
    2009      7521037 :           && ob->local_trees->contains (expr))
    2010        18250 :         max_local_entry = sccstack.length () - 1;
    2011              :       return;
    2012              :     }
    2013              : 
    2014      9994871 :   worklist w;
    2015      9994871 :   w.expr = expr;
    2016      9994871 :   w.from_state = from_state;
    2017      9994871 :   w.cstate = NULL;
    2018      9994871 :   w.ref_p = ref_p;
    2019      9994871 :   w.this_ref_p = this_ref_p;
    2020      9994871 :   worklist_vec.safe_push (w);
    2021              : }
    2022              : 
    2023              : 
    2024              : /* Emit the physical representation of tree node EXPR to output block OB.
    2025              :    If THIS_REF_P is true, the leaves of EXPR are emitted as references via
    2026              :    lto_output_tree_ref.  REF_P is used for streaming siblings of EXPR.  */
    2027              : 
    2028              : void
    2029     13045728 : lto_output_tree (struct output_block *ob, tree expr,
    2030              :                  bool ref_p, bool this_ref_p)
    2031              : {
    2032     13045728 :   unsigned ix;
    2033     13045728 :   bool existed_p;
    2034     13045728 :   unsigned int size = ob->main_stream->total_size;
    2035              :   /* This is the first time we see EXPR, write all reachable
    2036              :      trees to OB.  */
    2037     13045728 :   static bool in_dfs_walk;
    2038              : 
    2039     13045728 :   if (expr == NULL_TREE)
    2040              :     {
    2041      2880565 :       streamer_write_record_start (ob, LTO_null);
    2042     10934997 :       return;
    2043              :     }
    2044              : 
    2045     10165163 :   if (this_ref_p && tree_is_indexable (expr))
    2046              :     {
    2047      5173867 :       enum LTO_tags tag;
    2048      5173867 :       unsigned ix;
    2049              : 
    2050      5173867 :       lto_indexable_tree_ref (ob, expr, &tag, &ix);
    2051      5173867 :       streamer_write_record_start (ob, tag);
    2052      5173867 :       streamer_write_uhwi (ob, ix);
    2053      5173867 :       return;
    2054              :     }
    2055              : 
    2056      4991296 :   existed_p = streamer_tree_cache_lookup (ob->writer_cache, expr, &ix);
    2057      4991296 :   if (existed_p)
    2058              :     {
    2059      1897374 :       if (streamer_dump_file)
    2060              :         {
    2061           96 :           if (in_dfs_walk)
    2062            8 :             print_node_brief (streamer_dump_file, "     Streaming ref to ",
    2063              :                               expr, 4);
    2064              :           else
    2065           88 :             print_node_brief (streamer_dump_file, "   Streaming ref to ",
    2066              :                               expr, 4);
    2067           96 :           fprintf (streamer_dump_file, "\n");
    2068              :         }
    2069              :       /* If a node has already been streamed out, make sure that
    2070              :          we don't write it more than once.  Otherwise, the reader
    2071              :          will instantiate two different nodes for the same object.  */
    2072      1897374 :       streamer_write_record_start (ob, LTO_tree_pickle_reference);
    2073      1897374 :       streamer_write_uhwi (ob, ix);
    2074      1897374 :       lto_stats.num_pickle_refs_output++;
    2075              :     }
    2076              :   else
    2077              :     {
    2078              :       /* Protect against recursion which means disconnect between
    2079              :          what tree edges we walk in the DFS walk and what edges
    2080              :          we stream out.  */
    2081      3093922 :       gcc_assert (!in_dfs_walk);
    2082              : 
    2083      3093922 :       if (streamer_dump_file)
    2084              :         {
    2085          172 :           print_node_brief (streamer_dump_file, "   Streaming tree ",
    2086              :                             expr, 4);
    2087          172 :           fprintf (streamer_dump_file, "\n");
    2088              :         }
    2089              : 
    2090              :       /* Start the DFS walk.  */
    2091              :       /* Save ob state ... */
    2092              :       /* let's see ... */
    2093      3093922 :       in_dfs_walk = true;
    2094      3093922 :       DFS (ob, expr, ref_p, this_ref_p, false);
    2095              : 
    2096              :       /* Finally append a reference to the tree we were writing.  */
    2097      3093922 :       existed_p = streamer_tree_cache_lookup (ob->writer_cache, expr, &ix);
    2098              : 
    2099              :       /* DFS walk above possibly skipped streaming EXPR itself to let us inline
    2100              :          it.  */
    2101      3093922 :       if (!existed_p)
    2102      2138790 :         lto_output_tree_1 (ob, expr, 0, ref_p, this_ref_p);
    2103       955132 :       else if (this_ref_p)
    2104              :         {
    2105           10 :           if (streamer_dump_file)
    2106              :             {
    2107            0 :               print_node_brief (streamer_dump_file,
    2108              :                                 "   Streaming final ref to ",
    2109              :                                 expr, 4);
    2110            0 :               fprintf (streamer_dump_file, "\n");
    2111              :             }
    2112           10 :           streamer_write_record_start (ob, LTO_tree_pickle_reference);
    2113           10 :           streamer_write_uhwi (ob, ix);
    2114              :         }
    2115      3093922 :       in_dfs_walk = false;
    2116      3093922 :       lto_stats.num_pickle_refs_output++;
    2117              :     }
    2118      4991296 :   if (streamer_dump_file && !in_dfs_walk)
    2119          260 :     fprintf (streamer_dump_file, "    %u bytes\n",
    2120          260 :              ob->main_stream->total_size - size);
    2121              : }
    2122              : 
    2123              : 
    2124              : /* Output to OB a list of try/catch handlers starting with FIRST.  */
    2125              : 
    2126              : static void
    2127          313 : output_eh_try_list (struct output_block *ob, eh_catch first)
    2128              : {
    2129          313 :   eh_catch n;
    2130              : 
    2131          714 :   for (n = first; n; n = n->next_catch)
    2132              :     {
    2133          401 :       streamer_write_record_start (ob, LTO_eh_catch);
    2134          401 :       stream_write_tree (ob, n->type_list, true);
    2135          401 :       stream_write_tree (ob, n->filter_list, true);
    2136          401 :       stream_write_tree (ob, n->label, true);
    2137              :     }
    2138              : 
    2139          313 :   streamer_write_record_start (ob, LTO_null);
    2140          313 : }
    2141              : 
    2142              : 
    2143              : /* Output EH region R in function FN to OB.  CURR_RN is the slot index
    2144              :    that is being emitted in FN->EH->REGION_ARRAY.  This is used to
    2145              :    detect EH region sharing.  */
    2146              : 
    2147              : static void
    2148        18613 : output_eh_region (struct output_block *ob, eh_region r)
    2149              : {
    2150        18613 :   enum LTO_tags tag;
    2151              : 
    2152        18613 :   if (r == NULL)
    2153              :     {
    2154         7855 :       streamer_write_record_start (ob, LTO_null);
    2155         7855 :       return;
    2156              :     }
    2157              : 
    2158        10758 :   if (r->type == ERT_CLEANUP)
    2159              :     tag = LTO_ert_cleanup;
    2160              :   else if (r->type == ERT_TRY)
    2161              :     tag = LTO_ert_try;
    2162              :   else if (r->type == ERT_ALLOWED_EXCEPTIONS)
    2163              :     tag = LTO_ert_allowed_exceptions;
    2164              :   else if (r->type == ERT_MUST_NOT_THROW)
    2165              :     tag = LTO_ert_must_not_throw;
    2166              :   else
    2167            0 :     gcc_unreachable ();
    2168              : 
    2169        10758 :   streamer_write_record_start (ob, tag);
    2170        10758 :   streamer_write_hwi (ob, r->index);
    2171              : 
    2172        10758 :   if (r->outer)
    2173         3230 :     streamer_write_hwi (ob, r->outer->index);
    2174              :   else
    2175         7528 :     streamer_write_zero (ob);
    2176              : 
    2177        10758 :   if (r->inner)
    2178         1894 :     streamer_write_hwi (ob, r->inner->index);
    2179              :   else
    2180         8864 :     streamer_write_zero (ob);
    2181              : 
    2182        10758 :   if (r->next_peer)
    2183         4586 :     streamer_write_hwi (ob, r->next_peer->index);
    2184              :   else
    2185         6172 :     streamer_write_zero (ob);
    2186              : 
    2187        10758 :   if (r->type == ERT_TRY)
    2188              :     {
    2189          313 :       output_eh_try_list (ob, r->u.eh_try.first_catch);
    2190              :     }
    2191        10445 :   else if (r->type == ERT_ALLOWED_EXCEPTIONS)
    2192              :     {
    2193          332 :       stream_write_tree (ob, r->u.allowed.type_list, true);
    2194          332 :       stream_write_tree (ob, r->u.allowed.label, true);
    2195          332 :       streamer_write_uhwi (ob, r->u.allowed.filter);
    2196              :     }
    2197        10113 :   else if (r->type == ERT_MUST_NOT_THROW)
    2198              :     {
    2199         5354 :       stream_write_tree (ob, r->u.must_not_throw.failure_decl, true);
    2200         5354 :       bitpack_d bp = bitpack_create (ob->main_stream);
    2201         5354 :       stream_output_location (ob, &bp, r->u.must_not_throw.failure_loc);
    2202         5354 :       streamer_write_bitpack (&bp);
    2203              :     }
    2204              : 
    2205        10758 :   if (r->landing_pads)
    2206         3288 :     streamer_write_hwi (ob, r->landing_pads->index);
    2207              :   else
    2208         7470 :     streamer_write_zero (ob);
    2209              : }
    2210              : 
    2211              : 
    2212              : /* Output landing pad LP to OB.  */
    2213              : 
    2214              : static void
    2215         8537 : output_eh_lp (struct output_block *ob, eh_landing_pad lp)
    2216              : {
    2217         8537 :   if (lp == NULL)
    2218              :     {
    2219         5200 :       streamer_write_record_start (ob, LTO_null);
    2220         5200 :       return;
    2221              :     }
    2222              : 
    2223         3337 :   streamer_write_record_start (ob, LTO_eh_landing_pad);
    2224         3337 :   streamer_write_hwi (ob, lp->index);
    2225         3337 :   if (lp->next_lp)
    2226           49 :     streamer_write_hwi (ob, lp->next_lp->index);
    2227              :   else
    2228         3288 :     streamer_write_zero (ob);
    2229              : 
    2230         3337 :   if (lp->region)
    2231         3337 :     streamer_write_hwi (ob, lp->region->index);
    2232              :   else
    2233            0 :     streamer_write_zero (ob);
    2234              : 
    2235         3337 :   stream_write_tree (ob, lp->post_landing_pad, true);
    2236              : }
    2237              : 
    2238              : 
    2239              : /* Output the existing eh_table to OB.  */
    2240              : 
    2241              : static void
    2242       111498 : output_eh_regions (struct output_block *ob, struct function *fn)
    2243              : {
    2244       111498 :   if (fn->eh && fn->eh->region_tree)
    2245              :     {
    2246         4278 :       unsigned i;
    2247         4278 :       eh_region eh;
    2248         4278 :       eh_landing_pad lp;
    2249         4278 :       tree ttype;
    2250              : 
    2251         4278 :       streamer_write_record_start (ob, LTO_eh_table);
    2252              : 
    2253              :       /* Emit the index of the root of the EH region tree.  */
    2254         4278 :       streamer_write_hwi (ob, fn->eh->region_tree->index);
    2255              : 
    2256              :       /* Emit all the EH regions in the region array.  */
    2257         4278 :       streamer_write_hwi (ob, vec_safe_length (fn->eh->region_array));
    2258        27169 :       FOR_EACH_VEC_SAFE_ELT (fn->eh->region_array, i, eh)
    2259        18613 :         output_eh_region (ob, eh);
    2260              : 
    2261              :       /* Emit all landing pads.  */
    2262         4278 :       streamer_write_hwi (ob, vec_safe_length (fn->eh->lp_array));
    2263        17093 :       FOR_EACH_VEC_SAFE_ELT (fn->eh->lp_array, i, lp)
    2264         8537 :         output_eh_lp (ob, lp);
    2265              : 
    2266              :       /* Emit all the runtime type data.  */
    2267         4278 :       streamer_write_hwi (ob, vec_safe_length (fn->eh->ttype_data));
    2268         8556 :       FOR_EACH_VEC_SAFE_ELT (fn->eh->ttype_data, i, ttype)
    2269            0 :         stream_write_tree (ob, ttype, true);
    2270              : 
    2271              :       /* Emit the table of action chains.  */
    2272         4278 :       if (targetm.arm_eabi_unwinder)
    2273              :         {
    2274            0 :           tree t;
    2275            0 :           streamer_write_hwi (ob, vec_safe_length (fn->eh->ehspec_data.arm_eabi));
    2276            0 :           FOR_EACH_VEC_SAFE_ELT (fn->eh->ehspec_data.arm_eabi, i, t)
    2277            0 :             stream_write_tree (ob, t, true);
    2278              :         }
    2279              :       else
    2280              :         {
    2281         4278 :           uchar c;
    2282         4278 :           streamer_write_hwi (ob, vec_safe_length (fn->eh->ehspec_data.other));
    2283         8556 :           FOR_EACH_VEC_SAFE_ELT (fn->eh->ehspec_data.other, i, c)
    2284            0 :             streamer_write_char_stream (ob->main_stream, c);
    2285              :         }
    2286              :     }
    2287              : 
    2288              :   /* The LTO_null either terminates the record or indicates that there
    2289              :      are no eh_records at all.  */
    2290       111498 :   streamer_write_record_start (ob, LTO_null);
    2291       111498 : }
    2292              : 
    2293              : 
    2294              : /* Output all of the active ssa names to the ssa_names stream.  */
    2295              : 
    2296              : static void
    2297       111498 : output_ssa_names (struct output_block *ob, struct function *fn)
    2298              : {
    2299       111498 :   unsigned int i, len;
    2300              : 
    2301       111498 :   len = vec_safe_length (SSANAMES (fn));
    2302       111498 :   streamer_write_uhwi (ob, len);
    2303              : 
    2304      1904060 :   for (i = 1; i < len; i++)
    2305              :     {
    2306      1681064 :       tree ptr = (*SSANAMES (fn))[i];
    2307              : 
    2308      2317813 :       if (ptr == NULL_TREE
    2309      1674467 :           || SSA_NAME_IN_FREE_LIST (ptr)
    2310      1674467 :           || virtual_operand_p (ptr)
    2311              :           /* Simply skip unreleased SSA names.  */
    2312      2728287 :           || (! SSA_NAME_IS_DEFAULT_DEF (ptr)
    2313       936362 :               && (! SSA_NAME_DEF_STMT (ptr)
    2314       936362 :                   || ! gimple_bb (SSA_NAME_DEF_STMT (ptr)))))
    2315       636749 :         continue;
    2316              : 
    2317      1044315 :       streamer_write_uhwi (ob, i);
    2318      1044315 :       streamer_write_char_stream (ob->main_stream,
    2319      1044315 :                                   SSA_NAME_IS_DEFAULT_DEF (ptr));
    2320      1044315 :       if (SSA_NAME_VAR (ptr))
    2321       308566 :         stream_write_tree (ob, SSA_NAME_VAR (ptr), true);
    2322              :       else
    2323              :         /* ???  This drops SSA_NAME_IDENTIFIER on the floor.  */
    2324       735749 :         stream_write_tree (ob, TREE_TYPE (ptr), true);
    2325              :     }
    2326              : 
    2327       111498 :   streamer_write_zero (ob);
    2328       111498 : }
    2329              : 
    2330              : 
    2331              : 
    2332              : /* Output the cfg.  */
    2333              : 
    2334              : static void
    2335       111498 : output_cfg (struct output_block *ob, struct function *fn)
    2336              : {
    2337       111498 :   struct lto_output_stream *tmp_stream = ob->main_stream;
    2338       111498 :   basic_block bb;
    2339              : 
    2340       111498 :   ob->main_stream = ob->cfg_stream;
    2341              : 
    2342       111498 :   streamer_write_enum (ob->main_stream, profile_status_d, PROFILE_LAST,
    2343              :                        profile_status_for_fn (fn));
    2344              : 
    2345              :   /* Output the number of the highest basic block.  */
    2346       111498 :   streamer_write_uhwi (ob, last_basic_block_for_fn (fn));
    2347              : 
    2348      1043700 :   FOR_ALL_BB_FN (bb, fn)
    2349              :     {
    2350       932202 :       edge_iterator ei;
    2351       932202 :       edge e;
    2352              : 
    2353       932202 :       streamer_write_hwi (ob, bb->index);
    2354              : 
    2355              :       /* Output the predecessors and the edge flags.  We output
    2356              :          predecessors instead of successors so PHI argument order
    2357              :          is preserved when we reconstruct the CFG greedily in
    2358              :          input_cfg.  */
    2359      1752726 :       streamer_write_uhwi (ob, EDGE_COUNT (bb->preds));
    2360      1988335 :       FOR_EACH_EDGE (e, ei, bb->preds)
    2361              :         {
    2362      1056133 :           bitpack_d bp = bitpack_create (ob->main_stream);
    2363      1056133 :           bp_pack_var_len_unsigned (&bp, e->src->index);
    2364      1056133 :           bp_pack_var_len_unsigned (&bp, e->flags);
    2365      1056133 :           stream_output_location_and_block (ob, &bp, e->goto_locus);
    2366      1056133 :           e->probability.stream_out (ob);
    2367              :         }
    2368              :     }
    2369              : 
    2370       111498 :   streamer_write_hwi (ob, -1);
    2371              : 
    2372       111498 :   bb = ENTRY_BLOCK_PTR_FOR_FN (fn);
    2373       932202 :   while (bb->next_bb)
    2374              :     {
    2375       820704 :       streamer_write_hwi (ob, bb->next_bb->index);
    2376       820704 :       bb = bb->next_bb;
    2377              :     }
    2378              : 
    2379       111498 :   streamer_write_hwi (ob, -1);
    2380              : 
    2381              :   /* Output the number of loops.  */
    2382       111498 :   streamer_write_uhwi (ob, number_of_loops (fn));
    2383              : 
    2384              :   /* Output each loop, skipping the tree root which has number zero.  */
    2385       485760 :   for (unsigned i = 1; i < number_of_loops (fn); ++i)
    2386              :     {
    2387        75633 :       class loop *loop = get_loop (fn, i);
    2388              : 
    2389              :       /* Write the index of the loop header.  That's enough to rebuild
    2390              :          the loop tree on the reader side.  Stream -1 for an unused
    2391              :          loop entry.  */
    2392        75633 :       if (!loop)
    2393              :         {
    2394        25278 :           streamer_write_hwi (ob, -1);
    2395        25278 :           continue;
    2396              :         }
    2397              :       else
    2398        50355 :         streamer_write_hwi (ob, loop->header->index);
    2399              : 
    2400              :       /* Write everything copy_loop_info copies.  */
    2401        50355 :       streamer_write_enum (ob->main_stream,
    2402              :                            loop_estimation, EST_LAST, loop->estimate_state);
    2403        50355 :       streamer_write_hwi (ob, loop->any_upper_bound);
    2404        50355 :       if (loop->any_upper_bound)
    2405              :         {
    2406        41217 :           widest_int w = widest_int::from (loop->nb_iterations_upper_bound,
    2407        41217 :                                            SIGNED);
    2408        41217 :           streamer_write_widest_int (ob, w);
    2409        41217 :         }
    2410        50355 :       streamer_write_hwi (ob, loop->any_likely_upper_bound);
    2411        50355 :       if (loop->any_likely_upper_bound)
    2412              :         {
    2413        41221 :           widest_int w
    2414        41221 :             = widest_int::from (loop->nb_iterations_likely_upper_bound,
    2415        41221 :                                 SIGNED);
    2416        41221 :           streamer_write_widest_int (ob, w);
    2417        41221 :         }
    2418        50355 :       streamer_write_hwi (ob, loop->any_estimate);
    2419        50355 :       if (loop->any_estimate)
    2420              :         {
    2421        33599 :           widest_int w = widest_int::from (loop->nb_iterations_estimate,
    2422        33599 :                                            SIGNED);
    2423        33599 :           streamer_write_widest_int (ob, w);
    2424        33599 :         }
    2425              : 
    2426              :       /* Write OMP SIMD related info.  */
    2427        50355 :       streamer_write_hwi (ob, loop->safelen);
    2428        50355 :       streamer_write_hwi (ob, loop->unroll);
    2429        50355 :       streamer_write_hwi (ob, loop->owned_clique);
    2430        50355 :       streamer_write_hwi (ob, loop->dont_vectorize);
    2431        50355 :       streamer_write_hwi (ob, loop->force_vectorize);
    2432        50355 :       streamer_write_hwi (ob, loop->finite_p);
    2433        50355 :       streamer_write_hwi (ob, loop->can_be_parallel);
    2434        50355 :       stream_write_tree (ob, loop->simduid, true);
    2435              :     }
    2436              : 
    2437       111498 :   ob->main_stream = tmp_stream;
    2438       111498 : }
    2439              : 
    2440              : /* Create the header in the file using OB.  If the section type is for
    2441              :    a function, set FN to the decl for that function.  */
    2442              : 
    2443              : void
    2444       266763 : produce_symbol_asm (struct output_block *ob, tree fn, int output_order)
    2445              : {
    2446       266763 :   enum lto_section_type section_type = ob->section_type;
    2447       266763 :   struct lto_function_header header;
    2448       266763 :   char *section_name;
    2449              : 
    2450       266763 :   if (section_type == LTO_section_function_body)
    2451              :     {
    2452       122945 :       const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fn));
    2453       122945 :       section_name = lto_get_section_name (section_type, name,
    2454              :                                            output_order, NULL);
    2455              :     }
    2456              :   else
    2457       143818 :     section_name = lto_get_section_name (section_type, NULL, 0, NULL);
    2458              : 
    2459       266763 :   lto_begin_section (section_name, !flag_wpa);
    2460       266763 :   free (section_name);
    2461              : 
    2462              :   /* The entire header is stream computed here.  */
    2463       266763 :   memset (&header, 0, sizeof (struct lto_function_header));
    2464              : 
    2465       266763 :   if (section_type == LTO_section_function_body)
    2466       122945 :     header.cfg_size = ob->cfg_stream->total_size;
    2467       266763 :   header.main_size = ob->main_stream->total_size;
    2468       266763 :   header.string_size = ob->string_stream->total_size;
    2469       266763 :   lto_write_data (&header, sizeof header);
    2470              : 
    2471              :   /* Put all of the gimple and the string table out the asm file as a
    2472              :      block of text.  */
    2473       266763 :   if (section_type == LTO_section_function_body)
    2474       122945 :     lto_write_stream (ob->cfg_stream);
    2475       266763 :   lto_write_stream (ob->main_stream);
    2476       266763 :   lto_write_stream (ob->string_stream);
    2477              : 
    2478       266763 :   lto_end_section ();
    2479       266763 : }
    2480              : 
    2481              : /* Wrapper for unused arguments.  */
    2482              : 
    2483              : void
    2484       143818 : produce_asm (struct output_block *ob)
    2485              : {
    2486       143818 :   produce_symbol_asm (ob, NULL, -1);
    2487       143818 : }
    2488              : 
    2489              : 
    2490              : /* Output the base body of struct function FN using output block OB.  */
    2491              : 
    2492              : static void
    2493       111498 : output_struct_function_base (struct output_block *ob, struct function *fn)
    2494              : {
    2495       111498 :   struct bitpack_d bp;
    2496       111498 :   unsigned i;
    2497       111498 :   tree t;
    2498              : 
    2499              :   /* Output the static chain and non-local goto save area.  */
    2500       111498 :   stream_write_tree (ob, fn->static_chain_decl, true);
    2501       111498 :   stream_write_tree (ob, fn->nonlocal_goto_save_area, true);
    2502              : 
    2503              :   /* Output all the local variables in the function.  */
    2504       111498 :   streamer_write_hwi (ob, vec_safe_length (fn->local_decls));
    2505       394375 :   FOR_EACH_VEC_SAFE_ELT (fn->local_decls, i, t)
    2506       171379 :     stream_write_tree (ob, t, true);
    2507              : 
    2508              :   /* Output current IL state of the function.  */
    2509       111498 :   streamer_write_uhwi (ob, fn->curr_properties);
    2510              : 
    2511              :   /* Write all the attributes for FN.  */
    2512       111498 :   bp = bitpack_create (ob->main_stream);
    2513       111498 :   bp_pack_value (&bp, fn->is_thunk, 1);
    2514       111498 :   bp_pack_value (&bp, fn->has_local_explicit_reg_vars, 1);
    2515       111498 :   bp_pack_value (&bp, fn->returns_pcc_struct, 1);
    2516       111498 :   bp_pack_value (&bp, fn->returns_struct, 1);
    2517       111498 :   bp_pack_value (&bp, fn->can_throw_non_call_exceptions, 1);
    2518       111498 :   bp_pack_value (&bp, fn->can_delete_dead_exceptions, 1);
    2519       111498 :   bp_pack_value (&bp, fn->always_inline_functions_inlined, 1);
    2520       111498 :   bp_pack_value (&bp, fn->after_inlining, 1);
    2521       111498 :   bp_pack_value (&bp, fn->stdarg, 1);
    2522       111498 :   bp_pack_value (&bp, fn->has_nonlocal_label, 1);
    2523       111498 :   bp_pack_value (&bp, fn->has_forced_label_in_static, 1);
    2524       111498 :   bp_pack_value (&bp, fn->calls_alloca, 1);
    2525       111498 :   bp_pack_value (&bp, fn->calls_setjmp, 1);
    2526       111498 :   bp_pack_value (&bp, fn->calls_eh_return, 1);
    2527       111498 :   bp_pack_value (&bp, fn->has_force_vectorize_loops, 1);
    2528       111498 :   bp_pack_value (&bp, fn->has_simduid_loops, 1);
    2529       111498 :   bp_pack_value (&bp, fn->has_musttail, 1);
    2530       111498 :   bp_pack_value (&bp, fn->has_unroll, 1);
    2531       111498 :   bp_pack_value (&bp, fn->assume_function, 1);
    2532       111498 :   bp_pack_value (&bp, fn->va_list_fpr_size, 8);
    2533       111498 :   bp_pack_value (&bp, fn->va_list_gpr_size, 8);
    2534       111498 :   bp_pack_value (&bp, fn->last_clique, sizeof (short) * 8);
    2535              : 
    2536              :   /* Output the function start and end loci.  */
    2537       111498 :   stream_output_location (ob, &bp, fn->function_start_locus);
    2538       111498 :   stream_output_location (ob, &bp, fn->function_end_locus);
    2539              : 
    2540              :   /* Save the instance discriminator if present.  */
    2541       111498 :   int *instance_number_p = NULL;
    2542       111498 :   if (decl_to_instance_map)
    2543            0 :     instance_number_p = decl_to_instance_map->get (fn->decl);
    2544       111498 :   bp_pack_value (&bp, !!instance_number_p, 1);
    2545       111498 :   if (instance_number_p)
    2546            0 :     bp_pack_value (&bp, *instance_number_p, sizeof (int) * CHAR_BIT);
    2547              : 
    2548       111498 :   streamer_write_bitpack (&bp);
    2549       111498 : }
    2550              : 
    2551              : 
    2552              : /* Collect all leaf BLOCKs beyond ROOT into LEAFS.  */
    2553              : 
    2554              : static void
    2555       251583 : collect_block_tree_leafs (tree root, vec<tree> &leafs)
    2556              : {
    2557       470478 :   for (root = BLOCK_SUBBLOCKS (root); root; root = BLOCK_CHAIN (root))
    2558       218895 :     if (! BLOCK_SUBBLOCKS (root))
    2559        78810 :       leafs.safe_push (root);
    2560              :     else
    2561       140085 :       collect_block_tree_leafs (root, leafs);
    2562       251583 : }
    2563              : 
    2564              : /* This performs function body modifications that are needed for streaming
    2565              :    to work.  */
    2566              : 
    2567              : void
    2568       111488 : lto_prepare_function_for_streaming (struct cgraph_node *node)
    2569              : {
    2570       111488 :   struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
    2571       111488 :   basic_block bb;
    2572              : 
    2573       222976 :   if (number_of_loops (fn))
    2574              :     {
    2575       111488 :       push_cfun (fn);
    2576       111488 :       loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
    2577       111488 :       loop_optimizer_finalize ();
    2578       111488 :       pop_cfun ();
    2579              :     }
    2580              :   /* We will renumber the statements.  The code that does this uses
    2581              :      the same ordering that we use for serializing them so we can use
    2582              :      the same code on the other end and not have to write out the
    2583              :      statement numbers.  We do not assign UIDs to PHIs here because
    2584              :      virtual PHIs get re-computed on-the-fly which would make numbers
    2585              :      inconsistent.  */
    2586       111488 :   set_gimple_stmt_max_uid (fn, 0);
    2587      1043660 :   FOR_ALL_BB_FN (bb, fn)
    2588              :     {
    2589      1093963 :       for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
    2590       161791 :            gsi_next (&gsi))
    2591              :         {
    2592       161791 :           gphi *stmt = gsi.phi ();
    2593              : 
    2594              :           /* Virtual PHIs are not going to be streamed.  */
    2595       323582 :           if (!virtual_operand_p (gimple_phi_result (stmt)))
    2596        93927 :             gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
    2597              :         }
    2598      3602769 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
    2599      1738425 :            gsi_next (&gsi))
    2600              :         {
    2601      1738425 :           gimple *stmt = gsi_stmt (gsi);
    2602      1738425 :           gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
    2603              :         }
    2604              :     }
    2605              :   /* To avoid keeping duplicate gimple IDs in the statements, renumber
    2606              :      virtual phis now.  */
    2607      1043660 :   FOR_ALL_BB_FN (bb, fn)
    2608              :     {
    2609      1093963 :       for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
    2610       161791 :            gsi_next (&gsi))
    2611              :         {
    2612       161791 :           gphi *stmt = gsi.phi ();
    2613       391446 :           if (virtual_operand_p (gimple_phi_result (stmt)))
    2614        67864 :             gimple_set_uid (stmt, inc_gimple_stmt_max_uid (fn));
    2615              :         }
    2616              :     }
    2617              : 
    2618       111488 : }
    2619              : 
    2620              : /* Emit the chain of tree nodes starting at T.  OB is the output block
    2621              :    to write to.  REF_P is true if chain elements should be emitted
    2622              :    as references.  */
    2623              : 
    2624              : static void
    2625       111652 : streamer_write_chain (struct output_block *ob, tree t, bool ref_p)
    2626              : {
    2627       434923 :   while (t)
    2628              :     {
    2629              :       /* We avoid outputting external vars or functions by reference
    2630              :          to the global decls section as we do not want to have them
    2631              :          enter decl merging.  We should not need to do this anymore because
    2632              :          free_lang_data removes them from block scopes.  */
    2633       323271 :       gcc_assert (!VAR_OR_FUNCTION_DECL_P (t) || !DECL_EXTERNAL (t));
    2634       323271 :       stream_write_tree (ob, t, ref_p);
    2635              : 
    2636       323271 :       t = TREE_CHAIN (t);
    2637              :     }
    2638              : 
    2639              :   /* Write a sentinel to terminate the chain.  */
    2640       111652 :   stream_write_tree (ob, NULL_TREE, ref_p);
    2641       111652 : }
    2642              : 
    2643              : /* Output the body of function NODE->DECL.  */
    2644              : 
    2645              : static void
    2646       111652 : output_function (struct cgraph_node *node, int output_order)
    2647              : {
    2648       111652 :   tree function;
    2649       111652 :   struct function *fn;
    2650       111652 :   basic_block bb;
    2651       111652 :   struct output_block *ob;
    2652              : 
    2653       111652 :   if (streamer_dump_file)
    2654            8 :     fprintf (streamer_dump_file, "\nStreaming body of %s\n",
    2655              :              node->dump_name ());
    2656              : 
    2657       111652 :   function = node->decl;
    2658       111652 :   fn = DECL_STRUCT_FUNCTION (function);
    2659       111652 :   ob = create_output_block (LTO_section_function_body);
    2660              : 
    2661       111652 :   ob->symbol = node;
    2662              : 
    2663       111652 :   gcc_assert (current_function_decl == NULL_TREE && cfun == NULL);
    2664              : 
    2665              :   /* Make string 0 be a NULL string.  */
    2666       111652 :   streamer_write_char_stream (ob->string_stream, 0);
    2667              : 
    2668       111652 :   streamer_write_record_start (ob, LTO_function);
    2669              : 
    2670              :   /* Output decls for parameters and args.  */
    2671       111652 :   stream_write_tree (ob, DECL_RESULT (function), true);
    2672       111652 :   streamer_write_chain (ob, DECL_ARGUMENTS (function), true);
    2673              : 
    2674              :   /* Output debug args if available. */
    2675       111652 :   vec<tree, va_gc> **debugargs = decl_debug_args_lookup (function);
    2676       111652 :   if (! debugargs)
    2677       111623 :     streamer_write_uhwi (ob, 0);
    2678              :   else
    2679              :     {
    2680           29 :       streamer_write_uhwi (ob, (*debugargs)->length ());
    2681          132 :       for (unsigned i = 0; i < (*debugargs)->length (); ++i)
    2682           74 :         stream_write_tree (ob, (**debugargs)[i], true);
    2683              :     }
    2684              : 
    2685              :   /* Output DECL_INITIAL for the function, which contains the tree of
    2686              :      lexical scopes.  */
    2687       111652 :   stream_write_tree (ob, DECL_INITIAL (function), true);
    2688              :   /* As we do not recurse into BLOCK_SUBBLOCKS but only BLOCK_SUPERCONTEXT
    2689              :      collect block tree leafs and stream those.  */
    2690       111652 :   auto_vec<tree> block_tree_leafs;
    2691       111652 :   if (DECL_INITIAL (function) && DECL_INITIAL (function) != error_mark_node)
    2692       111498 :     collect_block_tree_leafs (DECL_INITIAL (function), block_tree_leafs);
    2693       111652 :   streamer_write_uhwi (ob, block_tree_leafs.length ());
    2694       302114 :   for (unsigned i = 0; i < block_tree_leafs.length (); ++i)
    2695        78810 :     stream_write_tree (ob, block_tree_leafs[i], true);
    2696              : 
    2697              :   /* We also stream abstract functions where we stream only stuff needed for
    2698              :      debug info.  */
    2699       111652 :   if (gimple_has_body_p (function))
    2700              :     {
    2701       111498 :       streamer_write_uhwi (ob, 1);
    2702       111498 :       output_struct_function_base (ob, fn);
    2703              : 
    2704       111498 :       output_cfg (ob, fn);
    2705              : 
    2706              :       /* Output all the SSA names used in the function.  */
    2707       111498 :       output_ssa_names (ob, fn);
    2708              : 
    2709              :       /* Output any exception handling regions.  */
    2710       111498 :       output_eh_regions (ob, fn);
    2711              : 
    2712              :       /* Output the code for the function.  */
    2713      1043700 :       FOR_ALL_BB_FN (bb, fn)
    2714       932202 :         output_bb (ob, bb, fn);
    2715              : 
    2716              :       /* The terminator for this function.  */
    2717       111498 :       streamer_write_record_start (ob, LTO_null);
    2718              :    }
    2719              :   else
    2720          154 :     streamer_write_uhwi (ob, 0);
    2721              : 
    2722              :   /* Create a section to hold the pickled output of this function.   */
    2723       111652 :   produce_symbol_asm (ob, function, output_order);
    2724              : 
    2725       111652 :   destroy_output_block (ob);
    2726       111652 :   if (streamer_dump_file)
    2727            8 :     fprintf (streamer_dump_file, "Finished streaming %s\n",
    2728              :              node->dump_name ());
    2729       111652 : }
    2730              : 
    2731              : /* Output the body of function NODE->DECL.  */
    2732              : 
    2733              : static void
    2734        11293 : output_constructor (struct varpool_node *node, int output_order)
    2735              : {
    2736        11293 :   tree var = node->decl;
    2737        11293 :   struct output_block *ob;
    2738              : 
    2739        11293 :   if (streamer_dump_file)
    2740            4 :     fprintf (streamer_dump_file, "\nStreaming constructor of %s\n",
    2741              :              node->dump_name ());
    2742              : 
    2743        11293 :   timevar_push (TV_IPA_LTO_CTORS_OUT);
    2744        11293 :   ob = create_output_block (LTO_section_function_body);
    2745              : 
    2746        11293 :   ob->symbol = node;
    2747              : 
    2748              :   /* Make string 0 be a NULL string.  */
    2749        11293 :   streamer_write_char_stream (ob->string_stream, 0);
    2750              : 
    2751              :   /* Output DECL_INITIAL for the function, which contains the tree of
    2752              :      lexical scopes.  */
    2753        11293 :   stream_write_tree (ob, DECL_INITIAL (var), true);
    2754              : 
    2755              :   /* Create a section to hold the pickled output of this function.   */
    2756        11293 :   produce_symbol_asm (ob, var, output_order);
    2757              : 
    2758        11293 :   destroy_output_block (ob);
    2759        11293 :   if (streamer_dump_file)
    2760            4 :     fprintf (streamer_dump_file, "Finished streaming %s\n",
    2761              :              node->dump_name ());
    2762        11293 :   timevar_pop (TV_IPA_LTO_CTORS_OUT);
    2763        11293 : }
    2764              : 
    2765              : 
    2766              : /* Emit toplevel asms.  */
    2767              : 
    2768              : void
    2769        34001 : lto_output_toplevel_asms (lto_symtab_encoder_t encoder)
    2770              : {
    2771        34001 :   struct output_block *ob;
    2772        34001 :   char *section_name;
    2773        34001 :   struct lto_simple_header_with_strings header;
    2774              : 
    2775        34001 :   unsigned asm_count = 0;
    2776      1502177 :   for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
    2777      1434416 :     if (is_a <asm_node*> (lto_symtab_encoder_deref (encoder, i)))
    2778          156 :       asm_count++;
    2779              : 
    2780        34001 :   if (!asm_count)
    2781        33886 :     return;
    2782              : 
    2783          115 :   ob = create_output_block (LTO_section_asm);
    2784              : 
    2785              :   /* Stream the length.  */
    2786          115 :   streamer_write_uhwi (ob, asm_count);
    2787        26185 :   for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
    2788              :     {
    2789        12920 :       toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
    2790        12920 :       asm_node *anode = dyn_cast <asm_node*> (tnode);
    2791        12920 :       if (!anode)
    2792        12764 :         continue;
    2793              : 
    2794          156 :       int output_order = *encoder->order_remap->get (anode->order);
    2795          156 :       stream_write_tree (ob, anode->asm_str, true);
    2796          156 :       streamer_write_hwi (ob, output_order);
    2797              :     }
    2798              : 
    2799          115 :   section_name = lto_get_section_name (LTO_section_asm, NULL, 0, NULL);
    2800          115 :   lto_begin_section (section_name, !flag_wpa);
    2801          115 :   free (section_name);
    2802              : 
    2803              :   /* The entire header stream is computed here.  */
    2804          115 :   memset (&header, 0, sizeof (header));
    2805              : 
    2806          115 :   header.main_size = ob->main_stream->total_size;
    2807          115 :   header.string_size = ob->string_stream->total_size;
    2808          115 :   lto_write_data (&header, sizeof header);
    2809              : 
    2810              :   /* Put all of the gimple and the string table out the asm file as a
    2811              :      block of text.  */
    2812          115 :   lto_write_stream (ob->main_stream);
    2813          115 :   lto_write_stream (ob->string_stream);
    2814              : 
    2815          115 :   lto_end_section ();
    2816              : 
    2817          115 :   destroy_output_block (ob);
    2818              : }
    2819              : 
    2820              : 
    2821              : /* Copy the function body or variable constructor of NODE without deserializing. */
    2822              : 
    2823              : static void
    2824        36306 : copy_function_or_variable (struct symtab_node *node, int output_order)
    2825              : {
    2826        36306 :   tree function = node->decl;
    2827        36306 :   struct lto_file_decl_data *file_data = node->lto_file_data;
    2828        36306 :   const char *data;
    2829        36306 :   size_t len;
    2830        36306 :   const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function));
    2831        36306 :   char *section_name =
    2832        36306 :     lto_get_section_name (LTO_section_function_body, name, output_order, NULL);
    2833        36306 :   size_t i, j;
    2834        36306 :   struct lto_in_decl_state *in_state;
    2835        36306 :   struct lto_out_decl_state *out_state = lto_get_out_decl_state ();
    2836              : 
    2837        36306 :   if (streamer_dump_file)
    2838            0 :     fprintf (streamer_dump_file, "Copying section for %s\n", name);
    2839        36306 :   lto_begin_section (section_name, false);
    2840        36306 :   free (section_name);
    2841              : 
    2842              :   /* We may have renamed the declaration, e.g., a static function.  */
    2843        36306 :   name = lto_get_decl_name_mapping (file_data, name);
    2844              : 
    2845        72612 :   data = lto_get_raw_section_data (file_data, LTO_section_function_body,
    2846        36306 :                                    name, node->order - file_data->order_base,
    2847              :                                    &len);
    2848        36306 :   gcc_assert (data);
    2849              : 
    2850              :   /* Do a bit copy of the function body.  */
    2851        36306 :   lto_write_raw_data (data, len);
    2852              : 
    2853              :   /* Copy decls. */
    2854        36306 :   in_state =
    2855        36306 :     lto_get_function_in_decl_state (node->lto_file_data, function);
    2856        36306 :   out_state->compressed = in_state->compressed;
    2857        36306 :   gcc_assert (in_state);
    2858              : 
    2859        36306 :   unsigned nrefs = vec_safe_length (in_state->origin_refs);
    2860        36306 :   out_state->origin_refs.reserve_exact (nrefs);
    2861        90305 :   for (unsigned k = 0; k < nrefs; ++k)
    2862        17693 :     out_state->origin_refs.quick_push ((*in_state->origin_refs)[k]);
    2863        72612 :   for (i = 0; i < LTO_N_DECL_STREAMS; i++)
    2864              :     {
    2865        36306 :       size_t n = vec_safe_length (in_state->streams[i]);
    2866        36306 :       vec<tree, va_gc> *trees = in_state->streams[i];
    2867        36306 :       struct lto_tree_ref_encoder *encoder = &(out_state->streams[i]);
    2868              : 
    2869              :       /* The out state must have the same indices and the in state.
    2870              :          So just copy the vector.  All the encoders in the in state
    2871              :          must be empty where we reach here. */
    2872        36306 :       gcc_assert (lto_tree_ref_encoder_size (encoder) == 0);
    2873        36306 :       encoder->trees.reserve_exact (n);
    2874       543019 :       for (j = 0; j < n; j++)
    2875       470407 :         encoder->trees.safe_push ((*trees)[j]);
    2876              :     }
    2877              : 
    2878        36306 :   lto_free_raw_section_data (file_data, LTO_section_function_body, name,
    2879              :                              data, len);
    2880        36306 :   lto_end_section ();
    2881              : 
    2882              :   /* Make sure the reader knows which linemap section to use.  */
    2883        36306 :   out_state->linemap_id = lto_linemap_output_id (in_state->linemap_id,
    2884              :                                                  file_data);
    2885        36306 : }
    2886              : 
    2887              : /* Wrap symbol references in *TP inside a type-preserving MEM_REF.  */
    2888              : 
    2889              : static tree
    2890       795787 : wrap_refs (tree *tp, int *ws, void *)
    2891              : {
    2892       795787 :   tree t = *tp;
    2893       795787 :   if (handled_component_p (t)
    2894          178 :       && VAR_P (TREE_OPERAND (t, 0))
    2895          121 :       && TREE_PUBLIC (TREE_OPERAND (t, 0)))
    2896              :     {
    2897           82 :       tree decl = TREE_OPERAND (t, 0);
    2898           82 :       tree ptrtype = build_pointer_type (TREE_TYPE (decl));
    2899           82 :       TREE_OPERAND (t, 0) = build2 (MEM_REF, TREE_TYPE (decl),
    2900              :                                     build1 (ADDR_EXPR, ptrtype, decl),
    2901              :                                     build_int_cst (ptrtype, 0));
    2902           82 :       TREE_THIS_VOLATILE (TREE_OPERAND (t, 0)) = TREE_THIS_VOLATILE (decl);
    2903           82 :       *ws = 0;
    2904              :     }
    2905       795705 :   else if (TREE_CODE (t) == CONSTRUCTOR)
    2906              :     ;
    2907       577715 :   else if (!EXPR_P (t))
    2908       337698 :     *ws = 0;
    2909       795787 :   return NULL_TREE;
    2910              : }
    2911              : 
    2912              : /* Remove functions that are no longer used from offload_funcs, and mark the
    2913              :    remaining ones with DECL_PRESERVE_P.  */
    2914              : 
    2915              : static void
    2916        34001 : prune_offload_funcs (void)
    2917              : {
    2918        34001 :   if (!offload_funcs)
    2919        34001 :     return;
    2920              : 
    2921            0 :   unsigned ix, ix2;
    2922            0 :   tree *elem_ptr;
    2923            0 :   VEC_ORDERED_REMOVE_IF (*offload_funcs, ix, ix2, elem_ptr,
    2924            0 :                          cgraph_node::get (*elem_ptr) == NULL);
    2925              : 
    2926            0 :   tree fn_decl;
    2927            0 :   FOR_EACH_VEC_ELT (*offload_funcs, ix, fn_decl)
    2928            0 :     DECL_PRESERVE_P (fn_decl) = 1;
    2929              : }
    2930              : 
    2931              : /* Produce LTO section that contains global information
    2932              :    about LTO bytecode.  */
    2933              : 
    2934              : static void
    2935        42766 : produce_lto_section ()
    2936              : {
    2937              :   /* Stream LTO meta section.  */
    2938        42766 :   output_block *ob = create_output_block (LTO_section_lto);
    2939              : 
    2940        42766 :   char * section_name = lto_get_section_name (LTO_section_lto, NULL, 0, NULL);
    2941        42766 :   lto_begin_section (section_name, false);
    2942        42766 :   free (section_name);
    2943              : 
    2944              : #ifdef HAVE_ZSTD_H
    2945        42766 :   lto_compression compression = ZSTD;
    2946              : #else
    2947              :   lto_compression compression = ZLIB;
    2948              : #endif
    2949              : 
    2950        42766 :   bool slim_object = flag_generate_lto && !flag_fat_lto_objects;
    2951        42766 :   lto_section s
    2952        42766 :     = { LTO_major_version, LTO_minor_version, slim_object, 0, 0 };
    2953        42766 :   s.set_compression (compression);
    2954        42766 :   lto_write_data (&s, sizeof s);
    2955        42766 :   lto_end_section ();
    2956        42766 :   destroy_output_block (ob);
    2957        42766 : }
    2958              : 
    2959              : /* If we have copied a function, we need to make sure the linemap it refers to
    2960              :    is also streamed out.  */
    2961              : 
    2962              : static void
    2963         9596 : copy_linemap_section (lto_file_decl_data *file_data, unsigned order)
    2964              : {
    2965         9596 :   const auto in_section_name
    2966         9596 :     = lto_get_section_name (LTO_section_linemap, nullptr, order, file_data);
    2967         9596 :   const auto out_section_name
    2968        19192 :     = lto_get_section_name (LTO_section_linemap, nullptr,
    2969         9596 :                             lto_linemap_output_id (order, file_data), nullptr);
    2970              : 
    2971         9596 :   if (streamer_dump_file)
    2972            0 :     fprintf (streamer_dump_file, "Copying linemap section from %s to %s\n",
    2973              :              in_section_name, out_section_name);
    2974              : 
    2975         9596 :   size_t len;
    2976         9596 :   const auto data = lto_get_raw_section_data (file_data, LTO_section_linemap,
    2977              :                                               nullptr, order, &len);
    2978         9596 :   gcc_assert (data);
    2979         9596 :   lto_begin_section (out_section_name, false);
    2980         9596 :   free (in_section_name);
    2981         9596 :   free (out_section_name);
    2982         9596 :   lto_write_raw_data (data, len);
    2983         9596 :   lto_free_raw_section_data (file_data, LTO_section_linemap,
    2984              :                              nullptr, data, len);
    2985         9596 :   lto_end_section ();
    2986         9596 : }
    2987              : 
    2988              : static void
    2989         9594 : copy_linemap_sections (lto_file_decl_data *file_data)
    2990              : {
    2991        19190 :   for (unsigned i = 0; i != file_data->num_linemap_sections; ++i)
    2992         9596 :     copy_linemap_section (file_data, i);
    2993         9594 : }
    2994              : 
    2995              : /* Copy all the linemaps we read into an object file so LTRANS can find them
    2996              :    later.  */
    2997              : 
    2998              : void
    2999         8801 : lto_copy_linemaps ()
    3000              : {
    3001         8801 :   timevar_push (TV_IPA_LTO_LINEMAP_COPY);
    3002         8801 :   lto_streamer_init ();
    3003         8801 :   lto_push_out_decl_state (nullptr);
    3004              : 
    3005              :   /* In WPA, we write these out to a standalone file; give it an LTO header
    3006              :      section.  */
    3007         8801 :   if (flag_wpa)
    3008         8765 :     produce_lto_section ();
    3009              : 
    3010        18395 :   for (auto file_data = lto_get_file_decl_data (); *file_data; ++file_data)
    3011         9594 :     copy_linemap_sections (*file_data);
    3012              : 
    3013         8801 :   lto_pop_out_decl_state ();
    3014         8801 :   timevar_pop (TV_IPA_LTO_LINEMAP_COPY);
    3015         8801 : }
    3016              : 
    3017              : /* Compare symbols to get them sorted by filename (to optimize streaming)  */
    3018              : 
    3019              : static int
    3020      3409782 : cmp_symbol_files (const void *pn1, const void *pn2, void *id_map_)
    3021              : {
    3022      3409782 :   const symtab_node *n1 = *(const symtab_node * const *)pn1;
    3023      3409782 :   const symtab_node *n2 = *(const symtab_node * const *)pn2;
    3024      3409782 :   hash_map<lto_file_decl_data *, int> *id_map
    3025              :     = (hash_map<lto_file_decl_data *, int> *)id_map_;
    3026              : 
    3027      3409782 :   int file_order1 = n1->lto_file_data ? n1->lto_file_data->order : -1;
    3028      3409782 :   int file_order2 = n2->lto_file_data ? n2->lto_file_data->order : -1;
    3029              : 
    3030              :   /* Order files same way as they appeared in the command line to reduce
    3031              :      seeking while copying sections.  */
    3032      3409782 :   if (file_order1 != file_order2)
    3033        10529 :     return file_order1 - file_order2;
    3034              : 
    3035              :   /* Order within static library.  */
    3036      3399253 :   if (n1->lto_file_data && n1->lto_file_data->id != n2->lto_file_data->id)
    3037            0 :     return *id_map->get (n1->lto_file_data) - *id_map->get (n2->lto_file_data);
    3038              : 
    3039              :   /* And finally order by the definition order.  */
    3040      3399253 :   return n1->order - n2->order;
    3041              : }
    3042              : 
    3043              : /* Compare ints, callback for qsort.  */
    3044              : 
    3045              : static int
    3046     31954365 : cmp_int (const void *a, const void *b)
    3047              : {
    3048     31954365 :   int ia = *(int const*) a;
    3049     31954365 :   int ib = *(int const*) b;
    3050     31954365 :   return ia - ib;
    3051              : }
    3052              : 
    3053              : /* Create order mapping independent on symbols outside of the partition.
    3054              :    Results in stable order values for incremental LTO.
    3055              : 
    3056              :    Remapping is not done in place, because symbols can be used
    3057              :    by multiple partitions.  */
    3058              : 
    3059              : static void
    3060        34001 : create_order_remap (lto_symtab_encoder_t encoder)
    3061              : {
    3062        34001 :   auto_vec<int> orders;
    3063        34001 :   unsigned i;
    3064        34001 :   encoder->order_remap = new hash_map<int_hash<int, -1, -2>, int>;
    3065        34001 :   unsigned n_nodes = lto_symtab_encoder_size (encoder);
    3066              : 
    3067       751209 :   for (i = 0; i < n_nodes; i++)
    3068       717208 :     orders.safe_push (lto_symtab_encoder_deref (encoder, i)->order);
    3069              : 
    3070        34001 :   orders.qsort (cmp_int);
    3071        34001 :   int ord = 0;
    3072        34001 :   int last_order = -1;
    3073       751209 :   for (i = 0; i < orders.length (); i++)
    3074              :     {
    3075       717208 :       int order = orders[i];
    3076       717208 :       if (order != last_order)
    3077              :         {
    3078       693770 :           last_order = order;
    3079       693770 :           encoder->order_remap->put (order, ord);
    3080       693770 :           ord++;
    3081              :         }
    3082              :     }
    3083        34001 : }
    3084              : 
    3085              : /* When WPA writes out its outputs, there are two different ways a location
    3086              :    may be streamed out: either streamed freshly, e.g. when trees are
    3087              :    streamed out in the decls section, or else copied verbatim from the input
    3088              :    files.  In the former case, we need to remember how a location_t was
    3089              :    originally referenced in the input data, so we can stream it out the same
    3090              :    way; otherwise it would be necessary to stream out a new linemap section
    3091              :    just for WPA-generated locations, which would a) be wasteful given that
    3092              :    all locations originated from one of the linemap sections that already
    3093              :    exists and b) inhibit incremental LTO since a change to one partition
    3094              :    would affect the linemap for all of them.  */
    3095              : 
    3096        21950 : void lto_register_linemap_for_output (size_t map_idx, unsigned linemap_id)
    3097              : {
    3098        21950 :   loc_output.register_map_id (map_idx, linemap_id);
    3099        21950 : }
    3100              : 
    3101              : /* Main entry point from the pass manager.  */
    3102              : 
    3103              : void
    3104        34001 : lto_output (void)
    3105              : {
    3106        34001 :   struct lto_out_decl_state *decl_state;
    3107        34001 :   bitmap output = NULL;
    3108        34001 :   bitmap_obstack output_obstack;
    3109        34001 :   unsigned int i, n_nodes;
    3110        34001 :   lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder;
    3111        34001 :   auto_vec<symtab_node *> symbols_to_copy;
    3112              : 
    3113        34001 :   create_order_remap (encoder);
    3114              : 
    3115        34001 :   prune_offload_funcs ();
    3116              : 
    3117        34001 :   if (flag_checking)
    3118              :     {
    3119        33995 :       bitmap_obstack_initialize (&output_obstack);
    3120        33995 :       output = BITMAP_ALLOC (&output_obstack);
    3121              :     }
    3122              : 
    3123              :   /* Initialize the streamer.  */
    3124        34001 :   lto_streamer_init ();
    3125              : 
    3126        34001 :   produce_lto_section ();
    3127              : 
    3128        34001 :   n_nodes = lto_symtab_encoder_size (encoder);
    3129              :   /* Prepare vector of functions to output and then sort it to optimize
    3130              :      section copying.  */
    3131       751209 :   for (i = 0; i < n_nodes; i++)
    3132              :     {
    3133       717208 :       toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
    3134       717208 :       symtab_node *node = dyn_cast <symtab_node *> (tnode);
    3135       717052 :       if (!node || node->alias)
    3136        12986 :         continue;
    3137              : 
    3138       704222 :       if (cgraph_node *node = dyn_cast <cgraph_node *> (tnode))
    3139              :         {
    3140       416677 :           if (lto_symtab_encoder_encode_body_p (encoder, node)
    3141       416677 :               && !node->clone_of)
    3142       143305 :             symbols_to_copy.safe_push (node);
    3143              :         }
    3144      1004753 :       else if (varpool_node *node = dyn_cast <varpool_node *> (tnode))
    3145              :         {
    3146              :           /* Wrap symbol references inside the ctor in a type
    3147              :              preserving MEM_REF.  */
    3148       287545 :           tree ctor = DECL_INITIAL (node->decl);
    3149       287545 :           if (ctor && !in_lto_p)
    3150        19722 :             walk_tree (&ctor, wrap_refs, NULL, NULL);
    3151       287545 :           if (get_symbol_initial_value (encoder, node->decl) == error_mark_node
    3152       287545 :               && lto_symtab_encoder_encode_initializer_p (encoder, node))
    3153        15946 :             symbols_to_copy.safe_push (node);
    3154              :         }
    3155              :     }
    3156              :   /* Map the section hash to an order it appears in symbols_to_copy
    3157              :      since we want to sort same ID symbols next to each other but need
    3158              :      to avoid making overall order depend on the actual hash value.  */
    3159        34001 :   int order = 0;
    3160        34001 :   hash_map<lto_file_decl_data *, int> id_map;
    3161       227253 :   for (i = 0; i < symbols_to_copy.length (); ++i)
    3162              :     {
    3163       159251 :       symtab_node *snode = symbols_to_copy[i];
    3164       159251 :       if (snode->lto_file_data)
    3165              :         {
    3166        41963 :           bool existed_p = false;
    3167        41963 :           int &ord = id_map.get_or_insert (snode->lto_file_data, &existed_p);
    3168        41963 :           if (!existed_p)
    3169         9676 :             ord = order++;
    3170              :         }
    3171              :     }
    3172        34001 :   symbols_to_copy.sort (cmp_symbol_files, (void *)&id_map);
    3173       193252 :   for (i = 0; i < symbols_to_copy.length (); i++)
    3174              :     {
    3175       159251 :       symtab_node *snode = symbols_to_copy[i];
    3176       159251 :       cgraph_node *cnode;
    3177       159251 :       varpool_node *vnode;
    3178              : 
    3179       159251 :       int output_order = *encoder->order_remap->get (snode->order);
    3180              : 
    3181       159251 :       if (flag_checking)
    3182       159249 :         gcc_assert (bitmap_set_bit (output, DECL_UID (snode->decl)));
    3183              : 
    3184       159251 :       decl_state = lto_new_out_decl_state ();
    3185       159251 :       lto_push_out_decl_state (decl_state);
    3186              : 
    3187       159251 :       if ((cnode = dyn_cast <cgraph_node *> (snode))
    3188       143305 :           && (gimple_has_body_p (cnode->decl)
    3189        31807 :               || (!flag_wpa
    3190          301 :                   && flag_incremental_link != INCREMENTAL_LINK_LTO)
    3191              :               /* Thunks have no body but they may be synthesized
    3192              :                  at WPA time.  */
    3193        31653 :               || DECL_ARGUMENTS (cnode->decl)))
    3194       111652 :         output_function (cnode, output_order);
    3195        47599 :       else if ((vnode = dyn_cast <varpool_node *> (snode))
    3196        15946 :                && (DECL_INITIAL (vnode->decl) != error_mark_node
    3197         4653 :                    || (!flag_wpa
    3198           42 :                        && flag_incremental_link != INCREMENTAL_LINK_LTO)))
    3199        11293 :         output_constructor (vnode, output_order);
    3200              :       else
    3201        36306 :         copy_function_or_variable (snode, output_order);
    3202       159251 :       gcc_assert (lto_get_out_decl_state () == decl_state);
    3203       159251 :       lto_pop_out_decl_state ();
    3204       159251 :       lto_record_function_out_decl_state (snode->decl, decl_state);
    3205              :     }
    3206              : 
    3207              :   /* Emit the callgraph after emitting function bodies.  This needs to
    3208              :      be done now to make sure that all the statements in every function
    3209              :      have been renumbered so that edges can be associated with call
    3210              :      statements using the statement UIDs.  */
    3211        34001 :   output_symtab ();
    3212              : 
    3213        34001 :   if (lto_get_out_decl_state ()->output_offload_tables_p)
    3214         8765 :     output_offload_tables ();
    3215              : 
    3216        34001 :   if (flag_checking)
    3217              :     {
    3218        33995 :       BITMAP_FREE (output);
    3219        33995 :       bitmap_obstack_release (&output_obstack);
    3220              :     }
    3221        34001 : }
    3222              : 
    3223              : /* Write each node in encoded by ENCODER to OB, as well as those reachable
    3224              :    from it and required for correct representation of its semantics.
    3225              :    Each node in ENCODER must be a global declaration or a type.  A node
    3226              :    is written only once, even if it appears multiple times in the
    3227              :    vector.  Certain transitively-reachable nodes, such as those
    3228              :    representing expressions, may be duplicated, but such nodes
    3229              :    must not appear in ENCODER itself.  */
    3230              : 
    3231              : static void
    3232       193252 : write_global_stream (struct output_block *ob,
    3233              :                      struct lto_tree_ref_encoder *encoder)
    3234              : {
    3235       193252 :   tree t;
    3236       193252 :   size_t index;
    3237       193252 :   const size_t size = lto_tree_ref_encoder_size (encoder);
    3238              : 
    3239      2910308 :   for (index = 0; index < size; index++)
    3240              :     {
    3241      2717056 :       t = lto_tree_ref_encoder_get_tree (encoder, index);
    3242      2717056 :       if (streamer_dump_file)
    3243              :         {
    3244          176 :           fprintf (streamer_dump_file, " %i:", (int)index);
    3245          176 :           print_node_brief (streamer_dump_file, "", t, 4);
    3246          176 :           fprintf (streamer_dump_file, "\n");
    3247              :         }
    3248      2717056 :       if (!streamer_tree_cache_lookup (ob->writer_cache, t, NULL))
    3249       955122 :         stream_write_tree (ob, t, false);
    3250              :     }
    3251       193252 : }
    3252              : 
    3253              : 
    3254              : /* Write a sequence of indices into the globals vector corresponding
    3255              :    to the trees in ENCODER.  These are used by the reader to map the
    3256              :    indices used to refer to global entities within function bodies to
    3257              :    their referents.  */
    3258              : 
    3259              : static void
    3260       193252 : write_global_references (struct output_block *ob,
    3261              :                          struct lto_tree_ref_encoder *encoder)
    3262              : {
    3263       193252 :   tree t;
    3264       193252 :   uint32_t index;
    3265       193252 :   const uint32_t size = lto_tree_ref_encoder_size (encoder);
    3266              : 
    3267              :   /* Write size and slot indexes as 32-bit unsigned numbers. */
    3268       193252 :   uint32_t *data = XNEWVEC (uint32_t, size + 1);
    3269       193252 :   data[0] = size;
    3270              : 
    3271      2910308 :   for (index = 0; index < size; index++)
    3272              :     {
    3273      2717056 :       unsigned slot_num;
    3274              : 
    3275      2717056 :       t = lto_tree_ref_encoder_get_tree (encoder, index);
    3276      2717056 :       streamer_tree_cache_lookup (ob->writer_cache, t, &slot_num);
    3277      2717056 :       gcc_assert (slot_num != (unsigned)-1);
    3278      2717056 :       data[index + 1] = slot_num;
    3279              :     }
    3280              : 
    3281       193252 :   lto_write_data (data, sizeof (int32_t) * (size + 1));
    3282       193252 :   free (data);
    3283       193252 : }
    3284              : 
    3285              : 
    3286              : /* Write all the streams in an lto_out_decl_state STATE using
    3287              :    output block OB and output stream OUT_STREAM.  */
    3288              : 
    3289              : void
    3290       193252 : lto_output_decl_state_streams (struct output_block *ob,
    3291              :                                struct lto_out_decl_state *state)
    3292              : {
    3293       193252 :   int i;
    3294              : 
    3295       386504 :   for (i = 0;  i < LTO_N_DECL_STREAMS; i++)
    3296       193252 :     write_global_stream (ob, &state->streams[i]);
    3297       193252 : }
    3298              : 
    3299              : 
    3300              : /* Write all the references in an lto_out_decl_state STATE using
    3301              :    output block OB and output stream OUT_STREAM.  */
    3302              : 
    3303              : void
    3304       193252 : lto_output_decl_state_refs (struct output_block *ob,
    3305              :                             struct lto_out_decl_state *state)
    3306              : {
    3307       193252 :   unsigned i;
    3308       193252 :   uint32_t ref, lm_order;
    3309       193252 :   tree decl;
    3310              : 
    3311              :   /* Write reference to FUNCTION_DECL.  If there is not function,
    3312              :      write reference to void_type_node. */
    3313       193252 :   decl = (state->fn_decl) ? state->fn_decl : void_type_node;
    3314       193252 :   streamer_tree_cache_lookup (ob->writer_cache, decl, &ref);
    3315       193252 :   gcc_assert (ref != (uint32_t)-1);
    3316       193252 :   ref = ref * 2 + (state->compressed ? 1 : 0);
    3317       193252 :   lto_write_data (&ref, sizeof (uint32_t));
    3318       193252 :   if (state->fn_decl)
    3319              :     {
    3320       159251 :       lm_order = state->linemap_id;
    3321       159251 :       lto_write_data (&lm_order, sizeof (lm_order));
    3322              :     }
    3323       386504 :   for (i = 0;  i < LTO_N_DECL_STREAMS; i++)
    3324       193252 :     write_global_references (ob, &state->streams[i]);
    3325       193252 : }
    3326              : 
    3327              : /* Only LGEN output may derive slot origins.  All subsequent outputs carry
    3328              :    explicit lists, including empty ones, since their trees may be shared.  */
    3329              : 
    3330              : static void
    3331       193252 : lto_output_decl_origin_refs (output_block *ob, lto_output_stream *stream,
    3332              :                              lto_out_decl_state *state)
    3333              : {
    3334       193252 :   bool explicit_p = (flag_wpa
    3335       193252 :                      || flag_incremental_link == INCREMENTAL_LINK_LTO);
    3336       193252 :   streamer_write_uhwi_stream (stream, explicit_p
    3337        57592 :                              ? state->origin_refs.length () + 1 : 0);
    3338       193252 :   if (explicit_p)
    3339        81714 :     for (const auto &entry : state->origin_refs)
    3340              :       {
    3341        17693 :         streamer_write_uhwi_stream (stream, entry.index);
    3342        17693 :         streamer_write_string (ob, stream, entry.ref.sym, true);
    3343        17693 :         streamer_write_uhwi_stream (stream, entry.ref.off);
    3344              :       }
    3345       193252 : }
    3346              : 
    3347              : 
    3348              : /* Return the written size of STATE. */
    3349              : 
    3350              : static size_t
    3351       193252 : lto_out_decl_state_written_size (struct lto_out_decl_state *state)
    3352              : {
    3353       193252 :   int i;
    3354       193252 :   size_t size;
    3355              : 
    3356       193252 :   size = sizeof (int32_t);      /* fn_ref. */
    3357       193252 :   if (state->fn_decl)
    3358       159251 :     size += sizeof (int32_t);   /* linemap_id.  */
    3359       386504 :   for (i = 0; i < LTO_N_DECL_STREAMS; i++)
    3360              :     {
    3361       193252 :       size += sizeof (int32_t); /* vector size. */
    3362       193252 :       size += (lto_tree_ref_encoder_size (&state->streams[i])
    3363       193252 :                * sizeof (int32_t));
    3364              :     }
    3365       193252 :   return size;
    3366              : }
    3367              : 
    3368              : 
    3369              : /* Write symbol T into STREAM in CACHE. SEEN specifies symbols we wrote
    3370              :    so far.  */
    3371              : 
    3372              : static void
    3373       547994 : write_symbol (struct streamer_tree_cache_d *cache,
    3374              :               tree t, hash_set<const char *> *seen, bool alias)
    3375              : {
    3376       547994 :   const char *name;
    3377       547994 :   enum gcc_plugin_symbol_kind kind;
    3378       547994 :   enum gcc_plugin_symbol_visibility visibility = GCCPV_DEFAULT;
    3379       547994 :   unsigned slot_num;
    3380       547994 :   uint64_t size;
    3381       547994 :   const char *comdat;
    3382       547994 :   unsigned char c;
    3383              : 
    3384       547994 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (t));
    3385              : 
    3386       547994 :   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t));
    3387              : 
    3388              :   /* This behaves like assemble_name_raw in varasm.cc, performing the
    3389              :      same name manipulations that ASM_OUTPUT_LABELREF does. */
    3390       547994 :   name = IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name) (name));
    3391              : 
    3392       547994 :   if (seen->add (name))
    3393          769 :     return;
    3394              : 
    3395       547225 :   streamer_tree_cache_lookup (cache, t, &slot_num);
    3396       547225 :   gcc_assert (slot_num != (unsigned)-1);
    3397              : 
    3398       547225 :   if (DECL_EXTERNAL (t))
    3399              :     {
    3400       215911 :       if (DECL_WEAK (t))
    3401              :         kind = GCCPK_WEAKUNDEF;
    3402              :       else
    3403       215873 :         kind = GCCPK_UNDEF;
    3404              :     }
    3405              :   else
    3406              :     {
    3407       331314 :       if (DECL_WEAK (t))
    3408              :         kind = GCCPK_WEAKDEF;
    3409       319163 :       else if (DECL_COMMON (t))
    3410              :         kind = GCCPK_COMMON;
    3411              :       else
    3412       319102 :         kind = GCCPK_DEF;
    3413              : 
    3414              :       /* When something is defined, it should have node attached.  */
    3415       331314 :       gcc_assert (alias || !VAR_P (t) || varpool_node::get (t)->definition);
    3416       331314 :       gcc_assert (alias || TREE_CODE (t) != FUNCTION_DECL
    3417              :                   || (cgraph_node::get (t)
    3418              :                       && cgraph_node::get (t)->definition));
    3419              :     }
    3420              : 
    3421              :   /* Imitate what default_elf_asm_output_external do.
    3422              :      When symbol is external, we need to output it with DEFAULT visibility
    3423              :      when compiling with -fvisibility=default, while with HIDDEN visibility
    3424              :      when symbol has attribute (visibility("hidden")) specified.
    3425              :      targetm.binds_local_p check DECL_VISIBILITY_SPECIFIED and gets this
    3426              :      right. */
    3427              : 
    3428       547225 :   if (DECL_EXTERNAL (t)
    3429       547225 :       && !targetm.binds_local_p (t))
    3430              :     visibility = GCCPV_DEFAULT;
    3431              :   else
    3432       331368 :     switch (DECL_VISIBILITY (t))
    3433              :       {
    3434              :       case VISIBILITY_DEFAULT:
    3435              :         visibility = GCCPV_DEFAULT;
    3436              :         break;
    3437              :       case VISIBILITY_PROTECTED:
    3438       547225 :         visibility = GCCPV_PROTECTED;
    3439              :         break;
    3440              :       case VISIBILITY_HIDDEN:
    3441              :         visibility = GCCPV_HIDDEN;
    3442              :         break;
    3443              :       case VISIBILITY_INTERNAL:
    3444              :         visibility = GCCPV_INTERNAL;
    3445              :         break;
    3446              :       }
    3447              : 
    3448       547225 :   if (kind == GCCPK_COMMON
    3449           61 :       && DECL_SIZE_UNIT (t)
    3450       547286 :       && TREE_CODE (DECL_SIZE_UNIT (t)) == INTEGER_CST)
    3451           61 :     size = TREE_INT_CST_LOW (DECL_SIZE_UNIT (t));
    3452              :   else
    3453       547164 :     size = 0;
    3454              : 
    3455       547225 :   if (DECL_ONE_ONLY (t))
    3456        12114 :     comdat = IDENTIFIER_POINTER (decl_comdat_group_id (t));
    3457              :   else
    3458              :     comdat = "";
    3459              : 
    3460       547225 :   lto_write_data (name, strlen (name) + 1);
    3461       547225 :   lto_write_data (comdat, strlen (comdat) + 1);
    3462       547225 :   c = (unsigned char) kind;
    3463       547225 :   lto_write_data (&c, 1);
    3464       547225 :   c = (unsigned char) visibility;
    3465       547225 :   lto_write_data (&c, 1);
    3466       547225 :   lto_write_data (&size, 8);
    3467       547225 :   lto_write_data (&slot_num, 4);
    3468              : }
    3469              : 
    3470              : /* Write extension information for symbols (symbol type, section flags).  */
    3471              : 
    3472              : static void
    3473       547994 : write_symbol_extension_info (tree t)
    3474              : {
    3475       547994 :   unsigned char c;
    3476       547994 :   c = ((unsigned char) TREE_CODE (t) == VAR_DECL
    3477              :        ? GCCST_VARIABLE : GCCST_FUNCTION);
    3478       547994 :   lto_write_data (&c, 1);
    3479       547994 :   unsigned char section_kind = 0;
    3480       547994 :   if (VAR_P (t))
    3481              :     {
    3482       235037 :       section *s = get_variable_section (t, false);
    3483       235037 :       if (s->common.flags & SECTION_BSS)
    3484       224953 :         section_kind |= GCCSSK_BSS;
    3485              :     }
    3486       547994 :   lto_write_data (&section_kind, 1);
    3487       547994 : }
    3488              : 
    3489              : /* Write an IL symbol table to OB.
    3490              :    SET and VSET are cgraph/varpool node sets we are outputting.  */
    3491              : 
    3492              : static unsigned int
    3493        24845 : produce_symtab (struct output_block *ob)
    3494              : {
    3495        24845 :   unsigned int streamed_symbols = 0;
    3496        24845 :   struct streamer_tree_cache_d *cache = ob->writer_cache;
    3497        24845 :   char *section_name = lto_get_section_name (LTO_section_symtab, NULL, 0, NULL);
    3498        24845 :   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
    3499        24845 :   lto_symtab_encoder_iterator lsei;
    3500              : 
    3501        24845 :   lto_begin_section (section_name, false);
    3502        24845 :   free (section_name);
    3503              : 
    3504        24845 :   hash_set<const char *> seen;
    3505              : 
    3506              :   /* Write the symbol table.
    3507              :      First write everything defined and then all declarations.
    3508              :      This is necessary to handle cases where we have duplicated symbols.  */
    3509        24845 :   for (lsei = lsei_start (encoder);
    3510       630368 :        !lsei_end_p (lsei); lsei_next (&lsei))
    3511              :     {
    3512       605523 :       toplevel_node *tnode = lsei_node (lsei);
    3513       605523 :       symtab_node *node = dyn_cast<symtab_node*> (tnode);
    3514       605523 :       if (!node)
    3515           84 :         continue;
    3516              : 
    3517       605439 :       if (DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
    3518       274125 :         continue;
    3519       331314 :       write_symbol (cache, node->decl, &seen, false);
    3520       331314 :       ++streamed_symbols;
    3521              :     }
    3522        24845 :   for (lsei = lsei_start (encoder);
    3523       630368 :        !lsei_end_p (lsei); lsei_next (&lsei))
    3524              :     {
    3525       605523 :       toplevel_node *tnode = lsei_node (lsei);
    3526       605523 :       symtab_node *node = dyn_cast<symtab_node*> (tnode);
    3527       605523 :       if (!node)
    3528           84 :         continue;
    3529              : 
    3530       605439 :       if (!DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
    3531       388759 :         continue;
    3532       216680 :       write_symbol (cache, node->decl, &seen, false);
    3533       216680 :       ++streamed_symbols;
    3534              :     }
    3535              : 
    3536        24845 :   lto_end_section ();
    3537              : 
    3538        24845 :   return streamed_symbols;
    3539        24845 : }
    3540              : 
    3541              : /* Symtab extension version.  */
    3542              : #define LTO_SYMTAB_EXTENSION_VERSION 1
    3543              : 
    3544              : /* Write an IL symbol table extension to OB.
    3545              :    SET and VSET are cgraph/varpool node sets we are outputting.  */
    3546              : 
    3547              : static void
    3548        24845 : produce_symtab_extension (struct output_block *ob,
    3549              :                           unsigned int previous_streamed_symbols)
    3550              : {
    3551        24845 :   unsigned int streamed_symbols = 0;
    3552        24845 :   char *section_name = lto_get_section_name (LTO_section_symtab_extension,
    3553              :                                              NULL, 0, NULL);
    3554        24845 :   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
    3555        24845 :   lto_symtab_encoder_iterator lsei;
    3556              : 
    3557        24845 :   lto_begin_section (section_name, false);
    3558        24845 :   free (section_name);
    3559              : 
    3560        24845 :   unsigned char version = LTO_SYMTAB_EXTENSION_VERSION;
    3561        24845 :   lto_write_data (&version, 1);
    3562              : 
    3563              :   /* Write the symbol table.
    3564              :      First write everything defined and then all declarations.
    3565              :      This is necessary to handle cases where we have duplicated symbols.  */
    3566        24845 :   for (lsei = lsei_start (encoder);
    3567       630368 :        !lsei_end_p (lsei); lsei_next (&lsei))
    3568              :     {
    3569       605523 :       toplevel_node *tnode = lsei_node (lsei);
    3570       605523 :       symtab_node *node = dyn_cast<symtab_node*> (tnode);
    3571       605523 :       if (!node)
    3572           84 :         continue;
    3573              : 
    3574       605439 :       if (DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
    3575       274125 :         continue;
    3576       331314 :       write_symbol_extension_info (node->decl);
    3577       331314 :       ++streamed_symbols;
    3578              :     }
    3579        24845 :   for (lsei = lsei_start (encoder);
    3580       630368 :        !lsei_end_p (lsei); lsei_next (&lsei))
    3581              :     {
    3582       605523 :       toplevel_node *tnode = lsei_node (lsei);
    3583       605523 :       symtab_node *node = dyn_cast<symtab_node*> (tnode);
    3584       605523 :       if (!node)
    3585           84 :         continue;
    3586              : 
    3587       605439 :       if (!DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ())
    3588       388759 :         continue;
    3589       216680 :       write_symbol_extension_info (node->decl);
    3590       216680 :       ++streamed_symbols;
    3591              :     }
    3592              : 
    3593        24845 :   gcc_assert (previous_streamed_symbols == streamed_symbols);
    3594        24845 :   lto_end_section ();
    3595        24845 : }
    3596              : 
    3597              : 
    3598              : /* Init the streamer_mode_table for output, where we collect info on what
    3599              :    machine_mode values have been streamed.  */
    3600              : void
    3601        34001 : lto_output_init_mode_table (void)
    3602              : {
    3603        34001 :   memset (streamer_mode_table, '\0', MAX_MACHINE_MODE);
    3604        34001 : }
    3605              : 
    3606              : 
    3607              : /* Write the mode table.  */
    3608              : static void
    3609            0 : lto_write_mode_table (void)
    3610              : {
    3611            0 :   struct output_block *ob;
    3612            0 :   ob = create_output_block (LTO_section_mode_table);
    3613            0 :   bitpack_d bp = bitpack_create (ob->main_stream);
    3614              : 
    3615            0 :   if (lto_stream_offload_p)
    3616            0 :     bp_pack_value (&bp, NUM_POLY_INT_COEFFS, MAX_NUM_POLY_INT_COEFFS_BITS);
    3617              : 
    3618              :   /* Ensure that for GET_MODE_INNER (m) != m we have
    3619              :      also the inner mode marked.  */
    3620            0 :   for (int i = 0; i < (int) MAX_MACHINE_MODE; i++)
    3621            0 :     if (streamer_mode_table[i])
    3622              :       {
    3623            0 :         machine_mode m = (machine_mode) i;
    3624            0 :         machine_mode inner_m = GET_MODE_INNER (m);
    3625            0 :         if (inner_m != m)
    3626            0 :           streamer_mode_table[(int) inner_m] = 1;
    3627              :       }
    3628              : 
    3629              :   /* Pack the mode_bits value within 5 bits (up to 31) in the beginning.  */
    3630            0 :   unsigned mode_bits = ceil_log2 (MAX_MACHINE_MODE);
    3631            0 :   bp_pack_value (&bp, mode_bits, 5);
    3632              : 
    3633              :   /* First stream modes that have GET_MODE_INNER (m) == m,
    3634              :      so that we can refer to them afterwards.  */
    3635            0 :   for (int pass = 0; pass < 2; pass++)
    3636            0 :     for (int i = 0; i < (int) MAX_MACHINE_MODE; i++)
    3637            0 :       if (streamer_mode_table[i] && i != (int) VOIDmode && i != (int) BLKmode)
    3638              :         {
    3639            0 :           machine_mode m = (machine_mode) i;
    3640            0 :           if ((GET_MODE_INNER (m) == m) ^ (pass == 0))
    3641            0 :             continue;
    3642            0 :           bp_pack_value (&bp, m, mode_bits);
    3643            0 :           bp_pack_enum (&bp, mode_class, MAX_MODE_CLASS, GET_MODE_CLASS (m));
    3644            0 :           bp_pack_poly_value (&bp, GET_MODE_SIZE (m), 16);
    3645            0 :           bp_pack_poly_value (&bp, GET_MODE_PRECISION (m), 16);
    3646            0 :           bp_pack_value (&bp, GET_MODE_INNER (m), mode_bits);
    3647            0 :           bp_pack_poly_value (&bp, GET_MODE_NUNITS (m), 16);
    3648            0 :           switch (GET_MODE_CLASS (m))
    3649              :             {
    3650            0 :             case MODE_FRACT:
    3651            0 :             case MODE_UFRACT:
    3652            0 :             case MODE_ACCUM:
    3653            0 :             case MODE_UACCUM:
    3654            0 :               bp_pack_value (&bp, GET_MODE_IBIT (m), 8);
    3655            0 :               bp_pack_value (&bp, GET_MODE_FBIT (m), 8);
    3656            0 :               break;
    3657            0 :             case MODE_FLOAT:
    3658            0 :             case MODE_DECIMAL_FLOAT:
    3659            0 :               bp_pack_string (ob, &bp, REAL_MODE_FORMAT (m)->name, true);
    3660            0 :               break;
    3661              :             default:
    3662              :               break;
    3663              :             }
    3664            0 :           bp_pack_string (ob, &bp, GET_MODE_NAME (m), true);
    3665              :         }
    3666            0 :   bp_pack_value (&bp, VOIDmode, mode_bits);
    3667              : 
    3668            0 :   streamer_write_bitpack (&bp);
    3669              : 
    3670            0 :   char *section_name
    3671            0 :     = lto_get_section_name (LTO_section_mode_table, NULL, 0, NULL);
    3672            0 :   lto_begin_section (section_name, !flag_wpa);
    3673            0 :   free (section_name);
    3674              : 
    3675              :   /* The entire header stream is computed here.  */
    3676            0 :   struct lto_simple_header_with_strings header;
    3677            0 :   memset (&header, 0, sizeof (header));
    3678              : 
    3679            0 :   header.main_size = ob->main_stream->total_size;
    3680            0 :   header.string_size = ob->string_stream->total_size;
    3681            0 :   lto_write_data (&header, sizeof header);
    3682              : 
    3683              :   /* Put all of the gimple and the string table out the asm file as a
    3684              :      block of text.  */
    3685            0 :   lto_write_stream (ob->main_stream);
    3686            0 :   lto_write_stream (ob->string_stream);
    3687              : 
    3688            0 :   lto_end_section ();
    3689            0 :   destroy_output_block (ob);
    3690            0 : }
    3691              : 
    3692              : 
    3693              : /* This pass is run after all of the functions are serialized and all
    3694              :    of the IPA passes have written their serialized forms.  This pass
    3695              :    causes the vector of all of the global decls and types used from
    3696              :    this file to be written in to a section that can then be read in to
    3697              :    recover these on other side.  */
    3698              : 
    3699              : void
    3700        34001 : produce_asm_for_decls (void)
    3701              : {
    3702        34001 :   struct lto_out_decl_state *out_state;
    3703        34001 :   struct lto_out_decl_state *fn_out_state;
    3704        34001 :   struct lto_decl_header header;
    3705        34001 :   char *section_name;
    3706        34001 :   struct output_block *ob;
    3707        34001 :   unsigned idx, num_fns;
    3708        34001 :   size_t decl_state_size;
    3709        34001 :   int32_t num_decl_states;
    3710              : 
    3711        34001 :   ob = create_output_block (LTO_section_decls);
    3712              : 
    3713        34001 :   memset (&header, 0, sizeof (struct lto_decl_header));
    3714              : 
    3715        34001 :   section_name = lto_get_section_name (LTO_section_decls, NULL, 0, NULL);
    3716        34001 :   lto_begin_section (section_name, !flag_wpa);
    3717        34001 :   free (section_name);
    3718              : 
    3719              :   /* Make string 0 be a NULL string.  */
    3720        34001 :   streamer_write_char_stream (ob->string_stream, 0);
    3721              : 
    3722        34001 :   gcc_assert (!alias_pairs);
    3723              : 
    3724              :   /* Get rid of the global decl state hash tables to save some memory.  */
    3725        34001 :   out_state = lto_get_out_decl_state ();
    3726       102003 :   for (int i = 0; i < LTO_N_DECL_STREAMS; i++)
    3727        34001 :     if (out_state->streams[i].tree_hash_table)
    3728              :       {
    3729        34001 :         delete out_state->streams[i].tree_hash_table;
    3730        34001 :         out_state->streams[i].tree_hash_table = NULL;
    3731              :       }
    3732              : 
    3733              :   /* Write the global symbols.  */
    3734        34001 :   if (streamer_dump_file)
    3735            4 :     fprintf (streamer_dump_file, "Outputting global stream\n");
    3736        34001 :   lto_output_decl_state_streams (ob, out_state);
    3737        34001 :   num_fns = lto_function_decl_states.length ();
    3738       193252 :   for (idx = 0; idx < num_fns; idx++)
    3739              :     {
    3740       159251 :       fn_out_state =
    3741       159251 :         lto_function_decl_states[idx];
    3742       159251 :       if (streamer_dump_file)
    3743           24 :         fprintf (streamer_dump_file, "Outputting stream for %s\n",
    3744           12 :                  IDENTIFIER_POINTER
    3745              :                     (DECL_ASSEMBLER_NAME (fn_out_state->fn_decl)));
    3746       159251 :       lto_output_decl_state_streams (ob, fn_out_state);
    3747              :     }
    3748              : 
    3749              :   /* Currently not used.  This field would allow us to preallocate
    3750              :      the globals vector, so that it need not be resized as it is extended.  */
    3751        34001 :   header.num_nodes = -1;
    3752              : 
    3753        34001 :   lto_output_stream debug_refs = {};
    3754        34001 :   lto_output_decl_origin_refs (ob, &debug_refs, out_state);
    3755       227253 :   for (idx = 0; idx < num_fns; idx++)
    3756       159251 :     lto_output_decl_origin_refs (ob, &debug_refs,
    3757       159251 :                                  lto_function_decl_states[idx]);
    3758        34001 :   header.debug_ref_size = debug_refs.total_size;
    3759              : 
    3760              :   /* Compute the total size of all decl out states. */
    3761        34001 :   decl_state_size = sizeof (int32_t);
    3762        34001 :   decl_state_size += lto_out_decl_state_written_size (out_state);
    3763       193252 :   for (idx = 0; idx < num_fns; idx++)
    3764              :     {
    3765       159251 :       fn_out_state =
    3766       159251 :         lto_function_decl_states[idx];
    3767       159251 :       decl_state_size += lto_out_decl_state_written_size (fn_out_state);
    3768              :     }
    3769        34001 :   header.decl_state_size = decl_state_size;
    3770              : 
    3771        34001 :   header.main_size = ob->main_stream->total_size;
    3772        34001 :   header.string_size = ob->string_stream->total_size;
    3773              : 
    3774        34001 :   lto_write_data (&header, sizeof header);
    3775              : 
    3776              :   /* Write the main out-decl state, followed by out-decl states of
    3777              :      functions. */
    3778        34001 :   num_decl_states = num_fns + 1;
    3779        34001 :   lto_write_data (&num_decl_states, sizeof (num_decl_states));
    3780        34001 :   lto_output_decl_state_refs (ob, out_state);
    3781       227253 :   for (idx = 0; idx < num_fns; idx++)
    3782              :     {
    3783       159251 :       fn_out_state = lto_function_decl_states[idx];
    3784       159251 :       lto_output_decl_state_refs (ob, fn_out_state);
    3785              :     }
    3786              : 
    3787        34001 :   lto_write_stream (ob->main_stream);
    3788        34001 :   lto_write_stream (&debug_refs);
    3789        34001 :   lto_write_stream (ob->string_stream);
    3790              : 
    3791        34001 :   lto_end_section ();
    3792              : 
    3793              :   /* Write the symbol table.  It is used by linker to determine dependencies
    3794              :      and thus we can skip it for WPA.  */
    3795        34001 :   if (!flag_wpa)
    3796              :     {
    3797        24845 :       unsigned int streamed_symbols = produce_symtab (ob);
    3798        24845 :       produce_symtab_extension (ob, streamed_symbols);
    3799              :     }
    3800              : 
    3801              :   /* Write command line opts.  */
    3802        34001 :   lto_write_options ();
    3803              : 
    3804              :   /* Deallocate memory and clean up.  */
    3805       227253 :   for (idx = 0; idx < num_fns; idx++)
    3806              :     {
    3807       159251 :       fn_out_state =
    3808       159251 :         lto_function_decl_states[idx];
    3809       159251 :       lto_delete_out_decl_state (fn_out_state);
    3810              :     }
    3811        34001 :   lto_symtab_encoder_delete (ob->decl_state->symtab_node_encoder);
    3812        34001 :   lto_function_decl_states.release ();
    3813        34001 :   destroy_output_block (ob);
    3814        34001 :   if (lto_stream_offload_p)
    3815            0 :     lto_write_mode_table ();
    3816              : 
    3817              :   /* Copy or write the linemap section(s) as needed.  For incremental LTO, we
    3818              :      copy them into the output file now.  For WPA, we will copy them into a
    3819              :      dedicated file later.  Otherwise, we create a new one from scratch and
    3820              :      output it now.  */
    3821        34001 :   if (flag_incremental_link == INCREMENTAL_LINK_LTO)
    3822           36 :     lto_copy_linemaps ();
    3823        33965 :   else if (!flag_wpa)
    3824              :     {
    3825        24809 :       gcc_checking_assert (!in_lto_p);
    3826        24809 :       loc_output.produce_linemap_section ();
    3827              :     }
    3828        34001 : }
        

Generated by: LCOV version 2.6-beta

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