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

Generated by: LCOV version 2.4-beta

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