LCOV - code coverage report
Current view: top level - gcc - lto-streamer-in.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 76.8 % 1121 861
Test Date: 2026-10-17 16:30:31 Functions: 88.2 % 51 45
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Read the GIMPLE representation from 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 "cfghooks.h"
      32              : #include "tree-pass.h"
      33              : #include "ssa.h"
      34              : #include "gimple-streamer.h"
      35              : #include "toplev.h"
      36              : #include "gimple-iterator.h"
      37              : #include "tree-cfg.h"
      38              : #include "tree-into-ssa.h"
      39              : #include "tree-dfa.h"
      40              : #include "tree-ssa.h"
      41              : #include "except.h"
      42              : #include "cgraph.h"
      43              : #include "cfgloop.h"
      44              : #include "debug.h"
      45              : #include "alloc-pool.h"
      46              : 
      47              : /* Allocator used to hold string slot entries for line map streaming.  */
      48              : static struct object_allocator<struct string_slot> *string_slot_allocator;
      49              : 
      50              : /* The table to hold the file names.  */
      51              : static hash_table<string_slot_hasher> *file_name_hash_table;
      52              : 
      53              : /* The table to hold the relative pathname prefixes.  */
      54              : 
      55              : /* This obstack holds file names used in locators. Line map datastructures
      56              :    points here and thus it needs to be kept allocated as long as linemaps
      57              :    exists.  */
      58              : static struct obstack file_name_obstack;
      59              : 
      60              : /* Map a pair of nul terminated strings where the first one can be
      61              :    pointer compared, but the second can't, to another string.  */
      62              : struct string_pair_map
      63              : {
      64              :   const char *str1;
      65              :   const char *str2;
      66              :   const char *str3;
      67              :   hashval_t hash;
      68              :   bool prefix;
      69              : };
      70              : 
      71              : /* Allocator used to hold string pair map entries for line map streaming.  */
      72              : static struct object_allocator<struct string_pair_map>
      73              :   *string_pair_map_allocator;
      74              : 
      75              : struct string_pair_map_hasher : nofree_ptr_hash <string_pair_map>
      76              : {
      77              :   static inline hashval_t hash (const string_pair_map *);
      78              :   static inline bool equal (const string_pair_map *, const string_pair_map *);
      79              : };
      80              : 
      81              : inline hashval_t
      82            0 : string_pair_map_hasher::hash (const string_pair_map *spm)
      83              : {
      84            0 :   return spm->hash;
      85              : }
      86              : 
      87              : inline bool
      88            0 : string_pair_map_hasher::equal (const string_pair_map *spm1,
      89              :                                const string_pair_map *spm2)
      90              : {
      91            0 :   return (spm1->hash == spm2->hash
      92            0 :           && spm1->str1 == spm2->str1
      93            0 :           && spm1->prefix == spm2->prefix
      94            0 :           && strcmp (spm1->str2, spm2->str2) == 0);
      95              : }
      96              : 
      97              : /* The table to hold the pairs of pathnames and corresponding
      98              :    resulting pathname.  Used for both mapping of get_src_pwd ()
      99              :    and recorded source working directory to relative path prefix
     100              :    from current working directory to the recorded one, and for
     101              :    mapping of that relative path prefix and some relative path
     102              :    to those concatenated.  */
     103              : static hash_table<string_pair_map_hasher> *path_name_pair_hash_table;
     104              : 
     105              : 
     106              : /* Check that tag ACTUAL has one of the given values.  NUM_TAGS is the
     107              :    number of valid tag values to check.  */
     108              : 
     109              : void
     110      1416609 : lto_tag_check_set (enum LTO_tags actual, int ntags, ...)
     111              : {
     112      1416609 :   va_list ap;
     113      1416609 :   int i;
     114              : 
     115      1416609 :   va_start (ap, ntags);
     116      2828101 :   for (i = 0; i < ntags; i++)
     117      2828101 :     if ((unsigned) actual == va_arg (ap, unsigned))
     118              :       {
     119      1416609 :         va_end (ap);
     120      1416609 :         return;
     121              :       }
     122              : 
     123            0 :   va_end (ap);
     124            0 :   internal_error ("bytecode stream: unexpected tag %s", lto_tag_name (actual));
     125              : }
     126              : 
     127              : 
     128              : /* Read LENGTH bytes from STREAM to ADDR.  */
     129              : 
     130              : void
     131            0 : lto_input_data_block (class lto_input_block *ib, void *addr, size_t length)
     132              : {
     133            0 :   size_t i;
     134            0 :   unsigned char *const buffer = (unsigned char *) addr;
     135              : 
     136            0 :   for (i = 0; i < length; i++)
     137            0 :     buffer[i] = streamer_read_uchar (ib);
     138            0 : }
     139              : 
     140              : /* Compute the relative path to get to DATA_WD (absolute directory name)
     141              :    from CWD (another absolute directory name).  E.g. for
     142              :    DATA_WD of "/tmp/foo/bar" and CWD of "/tmp/baz/qux" return
     143              :    "../../foo/bar".  Returned string should be freed by the caller.
     144              :    Return NULL if absolute file name needs to be used.  */
     145              : 
     146              : static char *
     147            0 : relative_path_prefix (const char *data_wd, const char *cwd)
     148              : {
     149            0 :   const char *d = data_wd;
     150            0 :   const char *c = cwd;
     151              : #ifdef HAVE_DOS_BASED_FILE_SYSTEM
     152              :   if (d[1] == ':')
     153              :     {
     154              :       if (!IS_DIR_SEPARATOR (d[2]))
     155              :         return NULL;
     156              :       if (c[0] == d[0] && c[1] == ':' && IS_DIR_SEPARATOR (c[2]))
     157              :         {
     158              :           c += 3;
     159              :           d += 3;
     160              :         }
     161              :       else
     162              :         return NULL;
     163              :     }
     164              :   else if (c[1] == ':')
     165              :     return NULL;
     166              : #endif
     167              :   do
     168              :     {
     169            0 :       while (IS_DIR_SEPARATOR (*d))
     170            0 :         d++;
     171            0 :       while (IS_DIR_SEPARATOR (*c))
     172            0 :         c++;
     173              :       size_t i;
     174            0 :       for (i = 0; c[i] && !IS_DIR_SEPARATOR (c[i]) && c[i] == d[i]; i++)
     175              :         ;
     176            0 :       if ((c[i] == '\0' || IS_DIR_SEPARATOR (c[i]))
     177            0 :           && (d[i] == '\0' || IS_DIR_SEPARATOR (d[i])))
     178              :         {
     179            0 :           c += i;
     180            0 :           d += i;
     181            0 :           if (*c == '\0' || *d == '\0')
     182              :             break;
     183              :         }
     184              :       else
     185              :         break;
     186              :     }
     187              :   while (1);
     188            0 :   size_t num_up = 0;
     189              :   do
     190              :     {
     191            0 :       while (IS_DIR_SEPARATOR (*c))
     192            0 :         c++;
     193            0 :       if (*c == '\0')
     194              :         break;
     195            0 :       num_up++;
     196            0 :       while (*c && !IS_DIR_SEPARATOR (*c))
     197            0 :         c++;
     198              :     }
     199              :   while (1);
     200            0 :   while (IS_DIR_SEPARATOR (*d))
     201            0 :     d++;
     202            0 :   size_t len = strlen (d);
     203            0 :   if (len == 0 && num_up == 0)
     204            0 :     return xstrdup (".");
     205            0 :   char *ret = XNEWVEC (char, num_up * 3 + len + 1);
     206            0 :   char *p = ret;
     207            0 :   for (; num_up; num_up--)
     208              :     {
     209            0 :       const char dir_up[3] = { '.', '.', DIR_SEPARATOR };
     210            0 :       memcpy (p, dir_up, 3);
     211            0 :       p += 3;
     212              :     }
     213            0 :   memcpy (p, d, len + 1);
     214            0 :   return ret;
     215              : }
     216              : 
     217              : /* Look up DATA_WD in hash table of relative prefixes.  If found,
     218              :    return relative path from CWD to DATA_WD from the hash table,
     219              :    otherwise create it.  */
     220              : 
     221              : static const char *
     222            0 : canon_relative_path_prefix (const char *data_wd, const char *cwd)
     223              : {
     224            0 :   if (!IS_ABSOLUTE_PATH (data_wd) || !IS_ABSOLUTE_PATH (cwd))
     225              :     return NULL;
     226              : 
     227            0 :   if (!path_name_pair_hash_table)
     228              :     {
     229            0 :       path_name_pair_hash_table
     230            0 :         = new hash_table<string_pair_map_hasher> (37);
     231            0 :       string_pair_map_allocator
     232            0 :         = new object_allocator <struct string_pair_map>
     233            0 :                 ("line map string pair map hash");
     234              :     }
     235              : 
     236            0 :   inchash::hash h;
     237            0 :   h.add_ptr (cwd);
     238            0 :   h.merge_hash (htab_hash_string (data_wd));
     239            0 :   h.add_int (true);
     240              : 
     241            0 :   string_pair_map s_slot;
     242            0 :   s_slot.str1 = cwd;
     243            0 :   s_slot.str2 = data_wd;
     244            0 :   s_slot.str3 = NULL;
     245            0 :   s_slot.hash = h.end ();
     246            0 :   s_slot.prefix = true;
     247              : 
     248            0 :   string_pair_map **slot
     249            0 :     = path_name_pair_hash_table->find_slot (&s_slot, INSERT);
     250            0 :   if (*slot == NULL)
     251              :     {
     252              :       /* Compute relative path from cwd directory to data_wd directory.
     253              :          E.g. if cwd is /tmp/foo/bar and data_wd is /tmp/baz/qux ,
     254              :          it will return ../../baz/qux .  */
     255            0 :       char *relative_path = relative_path_prefix (data_wd, cwd);
     256            0 :       const char *relative = relative_path ? relative_path : data_wd;
     257            0 :       size_t relative_len = strlen (relative);
     258            0 :       gcc_assert (relative_len);
     259              : 
     260            0 :       size_t data_wd_len = strlen (data_wd);
     261            0 :       bool add_separator = false;
     262            0 :       if (!IS_DIR_SEPARATOR (relative[relative_len - 1]))
     263            0 :         add_separator = true;
     264              : 
     265            0 :       size_t len = relative_len + 1 + data_wd_len + 1 + add_separator;
     266              : 
     267            0 :       char *saved_string = XOBNEWVEC (&file_name_obstack, char, len);
     268            0 :       struct string_pair_map *new_slot
     269            0 :         = string_pair_map_allocator->allocate ();
     270            0 :       memcpy (saved_string, data_wd, data_wd_len + 1);
     271            0 :       memcpy (saved_string + data_wd_len + 1, relative, relative_len);
     272            0 :       if (add_separator)
     273            0 :         saved_string[len - 2] = DIR_SEPARATOR;
     274            0 :       saved_string[len - 1] = '\0';
     275            0 :       new_slot->str1 = cwd;
     276            0 :       new_slot->str2 = saved_string;
     277            0 :       new_slot->str3 = saved_string + data_wd_len + 1;
     278            0 :       if (relative_len == 1 && relative[0] == '.')
     279            0 :         new_slot->str3 = NULL;
     280            0 :       new_slot->hash = s_slot.hash;
     281            0 :       new_slot->prefix = true;
     282            0 :       *slot = new_slot;
     283            0 :       free (relative_path);
     284            0 :       return new_slot->str3;
     285              :     }
     286              :   else
     287              :     {
     288            0 :       string_pair_map *old_slot = *slot;
     289            0 :       return old_slot->str3;
     290              :     }
     291              : }
     292              : 
     293              : /* Look up the pair of RELATIVE_PREFIX and STRING strings in a hash table.
     294              :    If found, return the concatenation of those from the hash table,
     295              :    otherwise concatenate them.  */
     296              : 
     297              : static const char *
     298            0 : canon_relative_file_name (const char *relative_prefix, const char *string)
     299              : {
     300            0 :   inchash::hash h;
     301            0 :   h.add_ptr (relative_prefix);
     302            0 :   h.merge_hash (htab_hash_string (string));
     303              : 
     304            0 :   string_pair_map s_slot;
     305            0 :   s_slot.str1 = relative_prefix;
     306            0 :   s_slot.str2 = string;
     307            0 :   s_slot.str3 = NULL;
     308            0 :   s_slot.hash = h.end ();
     309            0 :   s_slot.prefix = false;
     310              : 
     311            0 :   string_pair_map **slot
     312            0 :     = path_name_pair_hash_table->find_slot (&s_slot, INSERT);
     313            0 :   if (*slot == NULL)
     314              :     {
     315            0 :       size_t relative_prefix_len = strlen (relative_prefix);
     316            0 :       size_t string_len = strlen (string);
     317            0 :       size_t len = relative_prefix_len + string_len + 1;
     318              : 
     319            0 :       char *saved_string = XOBNEWVEC (&file_name_obstack, char, len);
     320            0 :       struct string_pair_map *new_slot
     321            0 :         = string_pair_map_allocator->allocate ();
     322            0 :       memcpy (saved_string, relative_prefix, relative_prefix_len);
     323            0 :       memcpy (saved_string + relative_prefix_len, string, string_len + 1);
     324            0 :       new_slot->str1 = relative_prefix;
     325            0 :       new_slot->str2 = saved_string + relative_prefix_len;
     326            0 :       new_slot->str3 = saved_string;
     327            0 :       new_slot->hash = s_slot.hash;
     328            0 :       new_slot->prefix = false;
     329            0 :       *slot = new_slot;
     330            0 :       return new_slot->str3;
     331              :     }
     332              :   else
     333              :     {
     334            0 :       string_pair_map *old_slot = *slot;
     335            0 :       return old_slot->str3;
     336              :     }
     337              : }
     338              : 
     339              : /* Lookup STRING in file_name_hash_table.  If found, return the existing
     340              :    string, otherwise insert STRING as the canonical version.
     341              :    If STRING is a relative pathname and RELATIVE_PREFIX is non-NULL, use
     342              :    canon_relative_file_name instead.  */
     343              : 
     344              : static const char *
     345        51476 : canon_file_name (const char *relative_prefix, const char *string)
     346              : {
     347        51476 :   if (relative_prefix && !IS_ABSOLUTE_PATH (string))
     348            0 :     return canon_relative_file_name (relative_prefix, string);
     349              : 
     350        51476 :   string_slot **slot;
     351        51476 :   struct string_slot s_slot;
     352        51476 :   size_t len = strlen (string);
     353              : 
     354        51476 :   s_slot.s = string;
     355        51476 :   s_slot.len = len;
     356              : 
     357        51476 :   slot = file_name_hash_table->find_slot (&s_slot, INSERT);
     358        51476 :   if (*slot == NULL)
     359              :     {
     360        47293 :       char *saved_string;
     361        47293 :       struct string_slot *new_slot;
     362              : 
     363        47293 :       saved_string = XOBNEWVEC (&file_name_obstack, char, len + 1);
     364        47293 :       new_slot = string_slot_allocator->allocate ();
     365        47293 :       memcpy (saved_string, string, len + 1);
     366        47293 :       new_slot->s = saved_string;
     367        47293 :       new_slot->len = len;
     368        47293 :       *slot = new_slot;
     369        47293 :       return saved_string;
     370              :     }
     371              :   else
     372              :     {
     373         4183 :       struct string_slot *old_slot = *slot;
     374         4183 :       return old_slot->s;
     375              :     }
     376              : }
     377              : 
     378              : /* Given a map index and offset from the streamed data, convert it to a
     379              :    location_t in the global line map.  */
     380              : 
     381              : static location_t
     382      3030991 : get_location_from_idx (size_t map_idx, location_t offset,
     383              :                        const lto_loc_map *loc_map)
     384              : {
     385      3030991 :   if (!map_idx)
     386              :     return offset;
     387      3030991 :   gcc_checking_assert (loc_map);
     388      3030991 :   --map_idx;
     389      3030991 :   gcc_assert (map_idx < loc_map->nmaps);
     390      3030991 :   const auto map = LINEMAPS_ORDINARY_MAP_AT (line_table, loc_map->map[map_idx]);
     391      3030991 :   const location_t res = map->start_location + offset;
     392      3030991 :   gcc_checking_assert (res < (map == LINEMAPS_LAST_ORDINARY_MAP (line_table)
     393              :                               ? line_table->highest_location + 1
     394              :                               : map[1].start_location));
     395              :   return res;
     396              : }
     397              : 
     398              : /* Pointer to currently alive instance of lto_location_cache.  */
     399              : 
     400              : lto_location_cache *lto_location_cache::current_cache;
     401              : 
     402              : /* Apply all changes in location cache.  Add locations into linemap and patch
     403              :    trees.  */
     404              : 
     405              : bool
     406       630510 : lto_location_cache::apply_location_cache ()
     407              : {
     408       630510 :   if (loc_cache.is_empty ())
     409              :     return true;
     410              : 
     411      1994378 :   for (const auto &cloc: loc_cache)
     412              :     {
     413      1712825 :       const location_t loc = cloc.loc;
     414      1712825 :       const auto range = source_range::from_location (loc);
     415      1712825 :       *cloc.dest = line_table->get_or_create_combined_loc (loc, range,
     416      1712825 :                                                            cloc.block,
     417      1712825 :                                                            cloc.discr);
     418              :     }
     419       563106 :   current_cloc = loc_cache[loc_cache.length () - 1];
     420       281553 :   current_loc = *current_cloc.dest;
     421       281553 :   loc_cache.truncate (0);
     422       281553 :   accepted_length = 0;
     423       281553 :   return true;
     424              : }
     425              : 
     426              : /* Tree merging did not succeed; mark all changes in the cache as accepted.  */
     427              : 
     428              : void
     429      1889334 : lto_location_cache::accept_location_cache ()
     430              : {
     431      1889334 :   gcc_assert (current_cache == this);
     432      1889334 :   accepted_length = loc_cache.length ();
     433      1889334 : }
     434              : 
     435              : /* Tree merging did succeed; throw away recent changes.  */
     436              : 
     437              : void
     438       147477 : lto_location_cache::revert_location_cache ()
     439              : {
     440       147477 :   loc_cache.truncate (accepted_length);
     441       147477 : }
     442              : 
     443              : /* Bitpack packing is more efficient for small values since every 4th bit is a
     444              :    continuation bit, so it helps to pack values as the delta from the previous
     445              :    if they can get large.  */
     446              : template<typename Int>
     447              : static Int
     448      5988396 : bp_unpack_delta (bitpack_d *bp, Int &prev)
     449              : {
     450      5988396 :   const bool decrease = bp_unpack_value (bp, 1);
     451      5988396 :   const Int delta = bp_unpack_var_len_unsigned (bp);
     452      5988396 :   return prev = (decrease ? prev - delta : prev + delta);
     453              : }
     454              : 
     455              : /* Read the linemap section of order LINEMAP_ID from FILE_DATA and create an
     456              :    lto_loc_map object that can be used to find which ordinary map in the
     457              :    global line_table corresponds to a given streamed-out map index.  Always
     458              :    either returns a non-NULL pointer, or calls fatal_error().  */
     459              : 
     460              : static lto_loc_map *
     461        22398 : create_loc_map (lto_file_decl_data *file_data, unsigned linemap_id)
     462              : {
     463        22398 :   timevar_push (TV_IPA_LTO_LINEMAP_IN);
     464              : 
     465        22398 :   size_t len;
     466        22398 :   const auto data = lto_get_section_data (file_data, LTO_section_linemap,
     467              :                                           nullptr, linemap_id, &len, true);
     468        22398 :   if (!data)
     469            0 :     fatal_error (UNKNOWN_LOCATION,
     470              :                  "linemap section #%u not found in file %qs",
     471              :                  linemap_id, file_data->file_name);
     472              : 
     473        22398 :   const auto header = (const lto_simple_header_with_strings *) data;
     474        22398 :   const char *const main_begin = data + sizeof (*header);
     475        22398 :   const auto data_in
     476        44796 :     = lto_data_in_create (file_data, main_begin + header->main_size,
     477        22398 :                           header->string_size, vNULL, false);
     478        22398 :   lto_input_block ib (main_begin, header->main_size, file_data);
     479        22398 :   bitpack_d bp = streamer_read_bitpack (&ib);
     480              : 
     481              :   /* Create the location map object.  */
     482        22398 :   const size_t nmaps = bp_unpack_var_len_unsigned (&bp);
     483        22398 :   size_t loc_map_sz = sizeof (lto_loc_map);
     484        22398 :   if (nmaps > 1)
     485         5572 :     loc_map_sz += (nmaps - 1) * sizeof (size_t);
     486        22398 :   const auto loc_map = (lto_loc_map *) ggc_internal_alloc (loc_map_sz);
     487        22398 :   loc_map->nmaps = nmaps;
     488              : 
     489              :   /* Read the line map data.  */
     490        22398 :   const char *stream_relative_path_prefix = nullptr;
     491        22398 :   const char *stream_file = nullptr;
     492        22398 :   size_t cur_map_idx = 0;
     493        22398 :   linenum_type cur_line = 0;
     494        73874 :   for (size_t i = 0; i != nmaps; ++i)
     495              :     {
     496        51476 :       const size_t map_idx = bp_unpack_delta (&bp, cur_map_idx);
     497        51476 :       gcc_assert (map_idx && map_idx <= nmaps);
     498        51476 :       const line_map_uint_t num_lines = bp_unpack_var_len_unsigned (&bp);
     499        51476 :       const bool sysp = bp_unpack_value (&bp, 1);
     500        51476 :       const unsigned int column_bits = bp_unpack_value (&bp, 8);
     501        51476 :       const linenum_type to_line = bp_unpack_delta (&bp, cur_line);
     502        51476 :       const bool file_change = bp_unpack_value (&bp, 1);
     503        51476 :       if (file_change)
     504              :         {
     505        51476 :           const bool pwd_change = bp_unpack_value (&bp, 1);
     506        51476 :           if (pwd_change)
     507              :             {
     508         2507 :               const char *pwd = bp_unpack_string (data_in, &bp);
     509         2507 :               const char *src_pwd = get_src_pwd ();
     510         2507 :               stream_relative_path_prefix
     511         2507 :                 = strcmp (pwd, src_pwd) == 0 ? nullptr
     512            0 :                 : canon_relative_path_prefix (pwd, src_pwd);
     513              :             }
     514        51476 :           stream_file = canon_file_name (stream_relative_path_prefix,
     515              :                                          bp_unpack_string (data_in, &bp));
     516              :         }
     517        51476 :       gcc_assert (stream_file);
     518        51476 :       const auto map
     519        51476 :         = linemap_add_raw_map (line_table,
     520        51476 :                                line_table->depth ? LC_RENAME : LC_ENTER,
     521        51476 :                                line_table->highest_location + 1, sysp,
     522              :                                column_bits, 0, stream_file, to_line, num_lines);
     523        51476 :       if (!map)
     524            0 :         fatal_error (UNKNOWN_LOCATION,
     525              :                      "Ran out of locations while reading linemap section #%u",
     526              :                      linemap_id);
     527        51476 :       loc_map->map[map_idx - 1] = map - line_table->info_ordinary.maps;
     528        51476 :       if (flag_wpa || flag_incremental_link == INCREMENTAL_LINK_LTO)
     529              :         {
     530        20768 :           const auto out_id = lto_linemap_output_id (linemap_id, file_data);
     531        20768 :           lto_register_linemap_for_output (map_idx, out_id);
     532              :         }
     533              :     }
     534              : 
     535              :   /* Process the diagnostics classification history.  */
     536        22398 :   auto &chist = global_dc->get_classification_history ();
     537        22398 :   const int pop_offset = chist.length ();
     538        22398 :   using DK = diagnostics::kind;
     539       110667 :   for (size_t i = 0, nc = bp_unpack_var_len_unsigned (&bp); i != nc; ++i)
     540              :     {
     541        88269 :       const size_t map_idx = bp_unpack_var_len_unsigned (&bp);
     542        88269 :       const location_t offset = bp_unpack_var_len_unsigned (&bp);
     543        88269 :       const location_t loc = get_location_from_idx (map_idx, offset, loc_map);
     544        88269 :       const int option = bp_unpack_var_len_int (&bp);
     545        88269 :       const auto kind = bp_unpack_enum (&bp, diagnostics::kind,
     546              :                                         DK::tot_num_diagnostic_kinds);
     547        88269 :       if (kind == DK::pop)
     548              :         {
     549        45511 :           diagnostics::option_classifier::classification_change_t c = {};
     550        45511 :           c.location = loc;
     551        45511 :           c.option = option + pop_offset;
     552        45511 :           c.kind = kind;
     553        45511 :           chist.safe_push (c);
     554              :         }
     555              :       else
     556        42758 :         global_dc->classify_diagnostic (option, kind, loc);
     557              :     }
     558              :   /* Make sure we reset back to the baseline.  */
     559        22398 :   {
     560        22398 :     diagnostics::option_classifier::classification_change_t c = {};
     561        22398 :     c.location = line_table->highest_location;
     562        22398 :     c.kind = DK::pop;
     563        22398 :     chist.safe_push (c);
     564              :   }
     565              : 
     566        22398 :   lto_data_in_delete (data_in);
     567        22398 :   lto_free_section_data (file_data, LTO_section_linemap, nullptr,
     568              :                          data, len, true);
     569              : 
     570        22398 :   timevar_pop (TV_IPA_LTO_LINEMAP_IN);
     571        22398 :   return loc_map;
     572              : }
     573              : 
     574              : /* Return the location map with given ID, reading it from the LTO object if
     575              :    necessary.  */
     576              : 
     577              : static const lto_loc_map *
     578       108078 : get_loc_map (lto_file_decl_data *file_data, unsigned linemap_id)
     579              : {
     580              :   /* During LTRANS, the location maps are stored in a different object.  */
     581       152865 :   while (file_data->loc_map_decl_data)
     582              :     file_data = file_data->loc_map_decl_data;
     583              : 
     584       108078 :   if (vec_safe_length (file_data->loc_maps) <= linemap_id)
     585        22171 :     vec_safe_grow_cleared (file_data->loc_maps, linemap_id + 1);
     586       108078 :   auto &res = (*file_data->loc_maps)[linemap_id];
     587       108078 :   if (!res)
     588        22398 :     res = create_loc_map (file_data, linemap_id);
     589       108078 :   return res;
     590              : }
     591              : 
     592              : 
     593              : /* Read a location bitpack from bit pack BP and either update *LOC directly or
     594              :    add it to the location cache.  It is necessary to call apply_location_cache
     595              :    to guarantee that *LOC has been updated.  */
     596              : 
     597              : void
     598      4997988 : lto_location_cache::input_location_and_block (location_t *dest,
     599              :                                               struct bitpack_d *bp,
     600              :                                               class lto_input_block *ib,
     601              :                                               class data_in *data_in)
     602              : {
     603      4997988 :   gcc_checking_assert (decl_data);
     604              : 
     605      4997988 :   location_t loc;
     606      4997988 :   unsigned this_discr;
     607      4997988 :   const bool is_reserved = bp_unpack_value (bp, 1);
     608      4997988 :   if (is_reserved)
     609              :     {
     610      2055266 :       loc = bp_unpack_int_in_range (bp, "loc", 0, RESERVED_LOCATION_COUNT - 1);
     611      2055266 :       this_discr = 0;
     612              :     }
     613              :   else
     614              :     {
     615      2942722 :       const bool linemap_change = bp_unpack_value (bp, 1);
     616      2942722 :       if (linemap_change)
     617              :         {
     618       108078 :           const unsigned linemap_id = bp_unpack_var_len_unsigned (bp);
     619       108078 :           cur_loc_map = get_loc_map (decl_data, linemap_id + linemap_offset);
     620              :         }
     621      2942722 :       const auto prev_idx = stream_map_idx;
     622      2942722 :       bp_unpack_delta (bp, stream_map_idx);
     623      2942722 :       bp_unpack_delta (bp, stream_loc_offset);
     624      2942722 :       if (stream_map_idx != prev_idx)
     625              :         /* The hash code is only there for the benefit of -flto-incremental;
     626              :            we don't need to do anything with it here.  */
     627       185208 :         bp_unpack_var_len_unsigned (bp);
     628              : 
     629      2942722 :       loc = get_location_from_idx (stream_map_idx, stream_loc_offset,
     630              :                                    cur_loc_map);
     631      2942722 :       if (bp_unpack_value (bp, 1))
     632      1114841 :         stream_discr = bp_unpack_var_len_unsigned (bp);
     633      2942722 :       this_discr = stream_discr;
     634              :     }
     635              : 
     636      4997988 :   tree this_block = NULL_TREE;
     637      4997988 :   if (ib)
     638              :     {
     639      2465565 :       if (bp_unpack_value (bp, 1))
     640       519754 :         stream_block = stream_read_tree (ib, data_in);
     641      2465565 :       this_block = stream_block;
     642              :     }
     643              : 
     644              :   /* If this location can be ordinary rather than ad-hoc, then there is no more
     645              :      overhead associated with it, so we may as well finalize it now.  */
     646      4997988 :   if (!(this_discr || this_block))
     647              :     {
     648      3262355 :       *dest = loc;
     649      3285163 :       return;
     650              :     }
     651              : 
     652              :   /* This optimization saves location cache operations during gimple
     653              :      streaming.  */
     654      1735633 :   if (loc == current_cloc.loc
     655       190791 :       && this_block == current_cloc.block
     656       107546 :       && this_discr == current_cloc.discr)
     657              :     {
     658        22808 :       *dest = current_loc;
     659        22808 :       return;
     660              :     }
     661              : 
     662              :   /* Keep value RESERVED_LOCATION_COUNT in *dest so linemap lookups will ICE on
     663              :      it if we erroneously try to use the location before it is ready.  */
     664      1712825 :   *dest = RESERVED_LOCATION_COUNT;
     665              : 
     666              :   /* This location needs to be ad-hoc; remember the details for now and create
     667              :      the ad-hoc location later once we know we need it.  */
     668      1712825 :   cached_location entry = {};
     669      1712825 :   entry.dest = dest;
     670      1712825 :   entry.loc = loc;
     671      1712825 :   entry.block = this_block;
     672      1712825 :   entry.discr = this_discr;
     673      1712825 :   loc_cache.safe_push (entry);
     674              : }
     675              : 
     676              : void
     677      2532423 : lto_location_cache::input_location (location_t *dest, struct bitpack_d *bp,
     678              :                                     class data_in *data_in)
     679              : {
     680      2532423 :   return input_location_and_block (dest, bp, NULL, data_in);
     681              : }
     682              : 
     683              : void
     684      2532423 : lto_input_location (location_t *loc, struct bitpack_d *bp,
     685              :                     class data_in *data_in)
     686              : {
     687      2532423 :   data_in->location_cache.input_location (loc, bp, data_in);
     688      2532423 : }
     689              : 
     690              : /* Read a reference to a tree node from DATA_IN using input block IB.
     691              :    TAG is the expected node that should be found in IB, if TAG belongs
     692              :    to one of the indexable trees, expect to read a reference index to
     693              :    be looked up in one of the symbol tables, otherwise read the physical
     694              :    representation of the tree using stream_read_tree.  FN is the
     695              :    function scope for the read tree.  */
     696              : 
     697              : tree
     698      4074487 : lto_input_tree_ref (class lto_input_block *ib, class data_in *data_in,
     699              :                     struct function *fn, enum LTO_tags tag)
     700              : {
     701      4074487 :   unsigned HOST_WIDE_INT ix_u;
     702      4074487 :   tree result = NULL_TREE;
     703              : 
     704      4074487 :   if (tag == LTO_ssa_name_ref)
     705              :     {
     706      1626453 :       ix_u = streamer_read_uhwi (ib);
     707      1626453 :       result = (*SSANAMES (fn))[ix_u];
     708              :     }
     709              :   else
     710              :     {
     711      2448034 :       gcc_checking_assert (tag == LTO_global_stream_ref);
     712      2448034 :       ix_u = streamer_read_uhwi (ib);
     713      2448034 :       result = (*data_in->file_data->current_decl_state
     714      2448034 :                 ->streams[LTO_DECL_STREAM])[ix_u];
     715              :     }
     716              : 
     717      4074487 :   gcc_assert (result);
     718              : 
     719      4074487 :   return result;
     720              : }
     721              : 
     722              : /* Read VAR_DECL reference to DATA from IB.  */
     723              : 
     724              : tree
     725        74955 : lto_input_var_decl_ref (lto_input_block *ib, lto_file_decl_data *file_data)
     726              : {
     727        74955 :   unsigned int ix_u = streamer_read_uhwi (ib);
     728        74955 :   tree result = (*file_data->current_decl_state
     729        74955 :                  ->streams[LTO_DECL_STREAM])[ix_u];
     730        74955 :   gcc_assert (VAR_P (result));
     731        74955 :   return result;
     732              : }
     733              : 
     734              : /* Read VAR_DECL reference to DATA from IB.  */
     735              : 
     736              : tree
     737       198151 : lto_input_fn_decl_ref (lto_input_block *ib, lto_file_decl_data *file_data)
     738              : {
     739       198151 :   unsigned int ix_u = streamer_read_uhwi (ib);
     740       198151 :   tree result = (*file_data->current_decl_state
     741       198151 :                  ->streams[LTO_DECL_STREAM])[ix_u];
     742       198151 :   gcc_assert (TREE_CODE (result) == FUNCTION_DECL);
     743       198151 :   return result;
     744              : }
     745              : 
     746              : 
     747              : /* Read and return a double-linked list of catch handlers from input
     748              :    block IB, using descriptors in DATA_IN.  */
     749              : 
     750              : static struct eh_catch_d *
     751          211 : lto_input_eh_catch_list (class lto_input_block *ib, class data_in *data_in,
     752              :                          eh_catch *last_p)
     753              : {
     754          211 :   eh_catch first;
     755          211 :   enum LTO_tags tag;
     756              : 
     757          211 :   *last_p = first = NULL;
     758          211 :   tag = streamer_read_record_start (ib);
     759          450 :   while (tag)
     760              :     {
     761          239 :       tree list;
     762          239 :       eh_catch n;
     763              : 
     764          239 :       lto_tag_check_range (tag, LTO_eh_catch, LTO_eh_catch);
     765              : 
     766              :       /* Read the catch node.  */
     767          239 :       n = ggc_cleared_alloc<eh_catch_d> ();
     768          239 :       n->type_list = stream_read_tree (ib, data_in);
     769          239 :       n->filter_list = stream_read_tree (ib, data_in);
     770          239 :       n->label = stream_read_tree (ib, data_in);
     771              : 
     772              :       /* Register all the types in N->FILTER_LIST.  */
     773          239 :       for (list = n->filter_list; list; list = TREE_CHAIN (list))
     774            0 :         add_type_for_runtime (TREE_VALUE (list));
     775              : 
     776              :       /* Chain N to the end of the list.  */
     777          239 :       if (*last_p)
     778           44 :         (*last_p)->next_catch = n;
     779          239 :       n->prev_catch = *last_p;
     780          239 :       *last_p = n;
     781              : 
     782              :       /* Set the head of the list the first time through the loop.  */
     783          239 :       if (first == NULL)
     784          195 :         first = n;
     785              : 
     786          239 :       tag = streamer_read_record_start (ib);
     787              :     }
     788              : 
     789          211 :   return first;
     790              : }
     791              : 
     792              : 
     793              : /* Read and return EH region IX from input block IB, using descriptors
     794              :    in DATA_IN.  */
     795              : 
     796              : static eh_region
     797        15653 : input_eh_region (class lto_input_block *ib, class data_in *data_in, int ix)
     798              : {
     799        15653 :   enum LTO_tags tag;
     800        15653 :   eh_region r;
     801              : 
     802              :   /* Read the region header.  */
     803        15653 :   tag = streamer_read_record_start (ib);
     804        15653 :   if (tag == LTO_null)
     805              :     return NULL;
     806              : 
     807         9543 :   r = ggc_cleared_alloc<eh_region_d> ();
     808         9543 :   r->index = streamer_read_hwi (ib);
     809              : 
     810         9543 :   gcc_assert (r->index == ix);
     811              : 
     812              :   /* Read all the region pointers as region numbers.  We'll fix up
     813              :      the pointers once the whole array has been read.  */
     814         9543 :   r->outer = (eh_region) (intptr_t) streamer_read_hwi (ib);
     815         9543 :   r->inner = (eh_region) (intptr_t) streamer_read_hwi (ib);
     816         9543 :   r->next_peer = (eh_region) (intptr_t) streamer_read_hwi (ib);
     817              : 
     818         9543 :   switch (tag)
     819              :     {
     820         4003 :       case LTO_ert_cleanup:
     821         4003 :         r->type = ERT_CLEANUP;
     822         4003 :         break;
     823              : 
     824          211 :       case LTO_ert_try:
     825          211 :         {
     826          211 :           struct eh_catch_d *last_catch;
     827          211 :           r->type = ERT_TRY;
     828          211 :           r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
     829              :                                                              &last_catch);
     830          211 :           r->u.eh_try.last_catch = last_catch;
     831          211 :           break;
     832              :         }
     833              : 
     834          321 :       case LTO_ert_allowed_exceptions:
     835          321 :         {
     836          321 :           tree l;
     837              : 
     838          321 :           r->type = ERT_ALLOWED_EXCEPTIONS;
     839          321 :           r->u.allowed.type_list = stream_read_tree (ib, data_in);
     840          321 :           r->u.allowed.label = stream_read_tree (ib, data_in);
     841          321 :           r->u.allowed.filter = streamer_read_uhwi (ib);
     842              : 
     843          323 :           for (l = r->u.allowed.type_list; l ; l = TREE_CHAIN (l))
     844            2 :             add_type_for_runtime (TREE_VALUE (l));
     845              :         }
     846              :         break;
     847              : 
     848         5008 :       case LTO_ert_must_not_throw:
     849         5008 :         {
     850         5008 :           r->type = ERT_MUST_NOT_THROW;
     851         5008 :           r->u.must_not_throw.failure_decl = stream_read_tree (ib, data_in);
     852         5008 :           bitpack_d bp = streamer_read_bitpack (ib);
     853         5008 :           stream_input_location (&r->u.must_not_throw.failure_loc,
     854              :                                  &bp, data_in);
     855              :         }
     856         5008 :         break;
     857              : 
     858            0 :       default:
     859            0 :         gcc_unreachable ();
     860              :     }
     861              : 
     862         9543 :   r->landing_pads = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
     863              : 
     864         9543 :   return r;
     865              : }
     866              : 
     867              : 
     868              : /* Read and return EH landing pad IX from input block IB, using descriptors
     869              :    in DATA_IN.  */
     870              : 
     871              : static eh_landing_pad
     872         6867 : input_eh_lp (class lto_input_block *ib, class data_in *data_in, int ix)
     873              : {
     874         6867 :   enum LTO_tags tag;
     875         6867 :   eh_landing_pad lp;
     876              : 
     877              :   /* Read the landing pad header.  */
     878         6867 :   tag = streamer_read_record_start (ib);
     879         6867 :   if (tag == LTO_null)
     880              :     return NULL;
     881              : 
     882         2570 :   lto_tag_check_range (tag, LTO_eh_landing_pad, LTO_eh_landing_pad);
     883              : 
     884         2570 :   lp = ggc_cleared_alloc<eh_landing_pad_d> ();
     885         2570 :   lp->index = streamer_read_hwi (ib);
     886         2570 :   gcc_assert (lp->index == ix);
     887         2570 :   lp->next_lp = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
     888         2570 :   lp->region = (eh_region) (intptr_t) streamer_read_hwi (ib);
     889         2570 :   lp->post_landing_pad = stream_read_tree (ib, data_in);
     890              : 
     891         2570 :   return lp;
     892              : }
     893              : 
     894              : 
     895              : /* After reading the EH regions, pointers to peer and children regions
     896              :    are region numbers.  This converts all these region numbers into
     897              :    real pointers into the rematerialized regions for FN.  ROOT_REGION
     898              :    is the region number for the root EH region in FN.  */
     899              : 
     900              : static void
     901         3691 : fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region)
     902              : {
     903         3691 :   unsigned i;
     904         3691 :   vec<eh_region, va_gc> *eh_array = fn->eh->region_array;
     905         3691 :   vec<eh_landing_pad, va_gc> *lp_array = fn->eh->lp_array;
     906         3691 :   eh_region r;
     907         3691 :   eh_landing_pad lp;
     908              : 
     909         3691 :   gcc_assert (eh_array && lp_array);
     910              : 
     911         3691 :   gcc_assert (root_region >= 0);
     912         3691 :   fn->eh->region_tree = (*eh_array)[root_region];
     913              : 
     914              : #define FIXUP_EH_REGION(r) (r) = (*eh_array)[(HOST_WIDE_INT) (intptr_t) (r)]
     915              : #define FIXUP_EH_LP(p) (p) = (*lp_array)[(HOST_WIDE_INT) (intptr_t) (p)]
     916              : 
     917              :   /* Convert all the index numbers stored in pointer fields into
     918              :      pointers to the corresponding slots in the EH region array.  */
     919        19344 :   FOR_EACH_VEC_ELT (*eh_array, i, r)
     920              :     {
     921              :       /* The array may contain NULL regions.  */
     922        15653 :       if (r == NULL)
     923         6110 :         continue;
     924              : 
     925         9543 :       gcc_assert (i == (unsigned) r->index);
     926         9543 :       FIXUP_EH_REGION (r->outer);
     927         9543 :       FIXUP_EH_REGION (r->inner);
     928         9543 :       FIXUP_EH_REGION (r->next_peer);
     929         9543 :       FIXUP_EH_LP (r->landing_pads);
     930              :     }
     931              : 
     932              :   /* Convert all the index numbers stored in pointer fields into
     933              :      pointers to the corresponding slots in the EH landing pad array.  */
     934        10558 :   FOR_EACH_VEC_ELT (*lp_array, i, lp)
     935              :     {
     936              :       /* The array may contain NULL landing pads.  */
     937         6867 :       if (lp == NULL)
     938         4297 :         continue;
     939              : 
     940         2570 :       gcc_assert (i == (unsigned) lp->index);
     941         2570 :       FIXUP_EH_LP (lp->next_lp);
     942         2570 :       FIXUP_EH_REGION (lp->region);
     943              :     }
     944              : 
     945              : #undef FIXUP_EH_REGION
     946              : #undef FIXUP_EH_LP
     947         3691 : }
     948              : 
     949              : 
     950              : /* Initialize EH support.  */
     951              : 
     952              : void
     953        43403 : lto_init_eh (void)
     954              : {
     955        43403 :   static bool eh_initialized_p = false;
     956              : 
     957        43403 :   if (eh_initialized_p)
     958              :     return;
     959              : 
     960              :   /* Contrary to most other FEs, we only initialize EH support when at
     961              :      least one of the files in the set contains exception regions in
     962              :      it.  Since this happens much later than the call to init_eh in
     963              :      lang_dependent_init, we have to set flag_exceptions and call
     964              :      init_eh again to initialize the EH tables.  */
     965         3842 :   flag_exceptions = 1;
     966         3842 :   init_eh ();
     967              : 
     968         3842 :   eh_initialized_p = true;
     969              : }
     970              : 
     971              : 
     972              : /* Read the exception table for FN from IB using the data descriptors
     973              :    in DATA_IN.  */
     974              : 
     975              : static void
     976        84776 : input_eh_regions (class lto_input_block *ib, class data_in *data_in,
     977              :                   struct function *fn)
     978              : {
     979        84776 :   HOST_WIDE_INT i, root_region, len;
     980        84776 :   enum LTO_tags tag;
     981              : 
     982        84776 :   tag = streamer_read_record_start (ib);
     983        84776 :   if (tag == LTO_null)
     984              :     return;
     985              : 
     986         3691 :   lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table);
     987              : 
     988         3691 :   gcc_assert (fn->eh);
     989              : 
     990         3691 :   root_region = streamer_read_hwi (ib);
     991         3691 :   gcc_assert (root_region == (int) root_region);
     992              : 
     993              :   /* Read the EH region array.  */
     994         3691 :   len = streamer_read_hwi (ib);
     995         3691 :   gcc_assert (len == (int) len);
     996         3691 :   if (len > 0)
     997              :     {
     998         3691 :       vec_safe_grow_cleared (fn->eh->region_array, len, true);
     999        23035 :       for (i = 0; i < len; i++)
    1000              :         {
    1001        15653 :           eh_region r = input_eh_region (ib, data_in, i);
    1002        15653 :           (*fn->eh->region_array)[i] = r;
    1003              :         }
    1004              :     }
    1005              : 
    1006              :   /* Read the landing pads.  */
    1007         3691 :   len = streamer_read_hwi (ib);
    1008         3691 :   gcc_assert (len == (int) len);
    1009         3691 :   if (len > 0)
    1010              :     {
    1011         3691 :       vec_safe_grow_cleared (fn->eh->lp_array, len, true);
    1012        14249 :       for (i = 0; i < len; i++)
    1013              :         {
    1014         6867 :           eh_landing_pad lp = input_eh_lp (ib, data_in, i);
    1015         6867 :           (*fn->eh->lp_array)[i] = lp;
    1016              :         }
    1017              :     }
    1018              : 
    1019              :   /* Read the runtime type data.  */
    1020         3691 :   len = streamer_read_hwi (ib);
    1021         3691 :   gcc_assert (len == (int) len);
    1022         3691 :   if (len > 0)
    1023              :     {
    1024            0 :       vec_safe_grow_cleared (fn->eh->ttype_data, len, true);
    1025            0 :       for (i = 0; i < len; i++)
    1026              :         {
    1027            0 :           tree ttype = stream_read_tree (ib, data_in);
    1028            0 :           (*fn->eh->ttype_data)[i] = ttype;
    1029              :         }
    1030              :     }
    1031              : 
    1032              :   /* Read the table of action chains.  */
    1033         3691 :   len = streamer_read_hwi (ib);
    1034         3691 :   gcc_assert (len == (int) len);
    1035         3691 :   if (len > 0)
    1036              :     {
    1037            0 :       if (targetm.arm_eabi_unwinder)
    1038              :         {
    1039            0 :           vec_safe_grow_cleared (fn->eh->ehspec_data.arm_eabi, len, true);
    1040            0 :           for (i = 0; i < len; i++)
    1041              :             {
    1042            0 :               tree t = stream_read_tree (ib, data_in);
    1043            0 :               (*fn->eh->ehspec_data.arm_eabi)[i] = t;
    1044              :             }
    1045              :         }
    1046              :       else
    1047              :         {
    1048            0 :           vec_safe_grow_cleared (fn->eh->ehspec_data.other, len, true);
    1049            0 :           for (i = 0; i < len; i++)
    1050              :             {
    1051            0 :               uchar c = streamer_read_uchar (ib);
    1052            0 :               (*fn->eh->ehspec_data.other)[i] = c;
    1053              :             }
    1054              :         }
    1055              :     }
    1056              : 
    1057              :   /* Reconstruct the EH region tree by fixing up the peer/children
    1058              :      pointers.  */
    1059         3691 :   fixup_eh_region_pointers (fn, root_region);
    1060              : 
    1061         3691 :   tag = streamer_read_record_start (ib);
    1062         3691 :   lto_tag_check_range (tag, LTO_null, LTO_null);
    1063              : }
    1064              : 
    1065              : 
    1066              : /* Make a new basic block with index INDEX in function FN.  */
    1067              : 
    1068              : static basic_block
    1069       585140 : make_new_block (struct function *fn, unsigned int index)
    1070              : {
    1071       585140 :   basic_block bb = alloc_block ();
    1072       585140 :   bb->index = index;
    1073       585140 :   SET_BASIC_BLOCK_FOR_FN (fn, index, bb);
    1074       585140 :   n_basic_blocks_for_fn (fn)++;
    1075       585140 :   return bb;
    1076              : }
    1077              : 
    1078              : 
    1079              : /* Read the CFG for function FN from input block IB.  */
    1080              : 
    1081              : static void
    1082        84776 : input_cfg (class lto_input_block *ib, class data_in *data_in,
    1083              :            struct function *fn)
    1084              : {
    1085        84776 :   unsigned int bb_count;
    1086        84776 :   basic_block p_bb;
    1087        84776 :   unsigned int i;
    1088        84776 :   int index;
    1089        84776 :   bool full_profile = false;
    1090              : 
    1091        84776 :   init_empty_tree_cfg_for_function (fn);
    1092              : 
    1093        84776 :   profile_status_for_fn (fn) = streamer_read_enum (ib, profile_status_d,
    1094              :                                                    PROFILE_LAST);
    1095              : 
    1096        84776 :   bb_count = streamer_read_uhwi (ib);
    1097              : 
    1098        84776 :   last_basic_block_for_fn (fn) = bb_count;
    1099        84776 :   if (bb_count > basic_block_info_for_fn (fn)->length ())
    1100         2221 :     vec_safe_grow_cleared (basic_block_info_for_fn (fn), bb_count, true);
    1101              : 
    1102        84776 :   if (bb_count > label_to_block_map_for_fn (fn)->length ())
    1103         2221 :     vec_safe_grow_cleared (label_to_block_map_for_fn (fn), bb_count, true);
    1104              : 
    1105        84776 :   index = streamer_read_hwi (ib);
    1106       839468 :   while (index != -1)
    1107              :     {
    1108       754692 :       basic_block bb = BASIC_BLOCK_FOR_FN (fn, index);
    1109       754692 :       unsigned int edge_count;
    1110              : 
    1111       754692 :       if (bb == NULL)
    1112       546306 :         bb = make_new_block (fn, index);
    1113              : 
    1114       754692 :       edge_count = streamer_read_uhwi (ib);
    1115       754692 :       vec_safe_reserve (bb->preds, edge_count);
    1116              : 
    1117              :       /* Connect up the CFG.  */
    1118      2375743 :       for (i = 0; i < edge_count; i++)
    1119              :         {
    1120       866359 :           bitpack_d bp = streamer_read_bitpack (ib);
    1121       866359 :           unsigned int src_index = bp_unpack_var_len_unsigned (&bp);
    1122       866359 :           unsigned int edge_flags = bp_unpack_var_len_unsigned (&bp);
    1123       866359 :           basic_block src = BASIC_BLOCK_FOR_FN (fn, src_index);
    1124              : 
    1125       866359 :           if (src == NULL)
    1126        38834 :             src = make_new_block (fn, src_index);
    1127              : 
    1128       866359 :           edge e = make_edge (src, bb, edge_flags);
    1129       866359 :           data_in->location_cache.input_location_and_block (&e->goto_locus,
    1130              :                                                             &bp, ib, data_in);
    1131       866359 :           e->probability = profile_probability::stream_in (ib);
    1132       866359 :           if (!e->probability.initialized_p ())
    1133       866359 :             full_profile = false;
    1134              :         }
    1135              : 
    1136       754692 :       index = streamer_read_hwi (ib);
    1137              :     }
    1138              : 
    1139        84776 :   p_bb = ENTRY_BLOCK_PTR_FOR_FN (fn);
    1140        84776 :   index = streamer_read_hwi (ib);
    1141       754692 :   while (index != -1)
    1142              :     {
    1143       669916 :       basic_block bb = BASIC_BLOCK_FOR_FN (fn, index);
    1144       669916 :       bb->prev_bb = p_bb;
    1145       669916 :       p_bb->next_bb = bb;
    1146       669916 :       p_bb = bb;
    1147       669916 :       index = streamer_read_hwi (ib);
    1148              :     }
    1149              : 
    1150              :   /* ???  The cfgloop interface is tied to cfun.  */
    1151        84776 :   gcc_assert (cfun == fn);
    1152              : 
    1153              :   /* Input the loop tree.  */
    1154        84776 :   unsigned n_loops = streamer_read_uhwi (ib);
    1155        84776 :   if (n_loops == 0)
    1156              :     return;
    1157              : 
    1158        84776 :   struct loops *loops = ggc_cleared_alloc<struct loops> ();
    1159        84776 :   init_loops_structure (fn, loops, n_loops);
    1160        84776 :   set_loops_for_fn (fn, loops);
    1161              : 
    1162              :   /* Input each loop and associate it with its loop header so
    1163              :      flow_loops_find can rebuild the loop tree.  */
    1164       228929 :   for (unsigned i = 1; i < n_loops; ++i)
    1165              :     {
    1166        59377 :       int header_index = streamer_read_hwi (ib);
    1167        59377 :       if (header_index == -1)
    1168              :         {
    1169        21452 :           loops->larray->quick_push (NULL);
    1170        21452 :           continue;
    1171              :         }
    1172              : 
    1173        37925 :       class loop *loop = alloc_loop ();
    1174        37925 :       loop->header = BASIC_BLOCK_FOR_FN (fn, header_index);
    1175        37925 :       loop->header->loop_father = loop;
    1176              : 
    1177              :       /* Read everything copy_loop_info copies.  */
    1178        37925 :       loop->estimate_state = streamer_read_enum (ib, loop_estimation, EST_LAST);
    1179        37925 :       loop->any_upper_bound = streamer_read_hwi (ib);
    1180        37925 :       if (loop->any_upper_bound)
    1181        32930 :         loop->nb_iterations_upper_bound
    1182        32930 :           = bound_wide_int::from (streamer_read_widest_int (ib), SIGNED);
    1183        37925 :       loop->any_likely_upper_bound = streamer_read_hwi (ib);
    1184        37925 :       if (loop->any_likely_upper_bound)
    1185        32930 :         loop->nb_iterations_likely_upper_bound
    1186        32930 :           = bound_wide_int::from (streamer_read_widest_int (ib), SIGNED);
    1187        37925 :       loop->any_estimate = streamer_read_hwi (ib);
    1188        37925 :       if (loop->any_estimate)
    1189        27391 :         loop->nb_iterations_estimate
    1190        27391 :           = bound_wide_int::from (streamer_read_widest_int (ib), SIGNED);
    1191              : 
    1192              :       /* Read OMP SIMD related info.  */
    1193        37925 :       loop->safelen = streamer_read_hwi (ib);
    1194        37925 :       loop->unroll = streamer_read_hwi (ib);
    1195        37925 :       loop->owned_clique = streamer_read_hwi (ib);
    1196        37925 :       loop->dont_vectorize = streamer_read_hwi (ib);
    1197        37925 :       loop->force_vectorize = streamer_read_hwi (ib);
    1198        37925 :       loop->finite_p = streamer_read_hwi (ib);
    1199        37925 :       loop->can_be_parallel = streamer_read_hwi (ib);
    1200        37925 :       loop->simduid = stream_read_tree (ib, data_in);
    1201              : 
    1202        37925 :       place_new_loop (fn, loop);
    1203              : 
    1204              :       /* flow_loops_find doesn't like loops not in the tree, hook them
    1205              :          all as siblings of the tree root temporarily.  */
    1206        37925 :       flow_loop_tree_node_add (loops->tree_root, loop);
    1207              :     }
    1208              : 
    1209              :   /* Rebuild the loop tree.  */
    1210        84776 :   flow_loops_find (loops);
    1211        84776 :   cfun->cfg->full_profile = full_profile;
    1212              : }
    1213              : 
    1214              : 
    1215              : /* Read the SSA names array for function FN from DATA_IN using input
    1216              :    block IB.  */
    1217              : 
    1218              : static void
    1219        84776 : input_ssa_names (class lto_input_block *ib, class data_in *data_in,
    1220              :                  struct function *fn)
    1221              : {
    1222        84776 :   unsigned int i, size;
    1223              : 
    1224        84776 :   size = streamer_read_uhwi (ib);
    1225        84776 :   init_tree_ssa (fn, size);
    1226        84776 :   cfun->gimple_df->in_ssa_p = true;
    1227        84776 :   init_ssa_operands (fn);
    1228              : 
    1229        84776 :   i = streamer_read_uhwi (ib);
    1230       918741 :   while (i)
    1231              :     {
    1232              :       tree ssa_name, name;
    1233              :       bool is_default_def;
    1234              : 
    1235              :       /* Skip over the elements that had been freed.  */
    1236      1101050 :       while (SSANAMES (fn)->length () < i)
    1237       267085 :         SSANAMES (fn)->quick_push (NULL_TREE);
    1238              : 
    1239       833965 :       is_default_def = (streamer_read_uchar (ib) != 0);
    1240       833965 :       name = stream_read_tree (ib, data_in);
    1241       833965 :       ssa_name = make_ssa_name_fn (fn, name, NULL);
    1242              : 
    1243       833965 :       if (is_default_def)
    1244              :         {
    1245        85750 :           set_ssa_default_def (cfun, SSA_NAME_VAR (ssa_name), ssa_name);
    1246        85750 :           SSA_NAME_DEF_STMT (ssa_name) = gimple_build_nop ();
    1247              :         }
    1248              : 
    1249       833965 :       i = streamer_read_uhwi (ib);
    1250              :     }
    1251        84776 : }
    1252              : 
    1253              : 
    1254              : /* Go through all NODE edges and fixup call_stmt pointers
    1255              :    so they point to STMTS.  */
    1256              : 
    1257              : static void
    1258       111074 : fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple **stmts,
    1259              :                          struct function *fn)
    1260              : {
    1261              : #define STMT_UID_NOT_IN_RANGE(uid) \
    1262              :   (gimple_stmt_max_uid (fn) < uid || uid == 0)
    1263              : 
    1264       111074 :   struct cgraph_edge *cedge;
    1265       111074 :   struct ipa_ref *ref = NULL;
    1266       111074 :   unsigned int i;
    1267              : 
    1268       482004 :   for (cedge = node->callees; cedge; cedge = cedge->next_callee)
    1269              :     {
    1270       370930 :       if (STMT_UID_NOT_IN_RANGE (cedge->lto_stmt_uid))
    1271            0 :         fatal_error (input_location,
    1272              :                      "Cgraph edge statement index out of range");
    1273       370930 :       cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
    1274       370930 :       cedge->lto_stmt_uid = 0;
    1275       370930 :       if (!cedge->call_stmt)
    1276              :         fatal_error (input_location,
    1277              :                      "Cgraph edge statement index not found");
    1278              :     }
    1279       112788 :   for (cedge = node->indirect_calls; cedge; cedge = cedge->next_callee)
    1280              :     {
    1281         1714 :       if (STMT_UID_NOT_IN_RANGE (cedge->lto_stmt_uid))
    1282            0 :         fatal_error (input_location,
    1283              :                      "Cgraph edge statement index out of range");
    1284         1714 :       cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
    1285         1714 :       cedge->lto_stmt_uid = 0;
    1286         1714 :       if (!cedge->call_stmt)
    1287              :         fatal_error (input_location, "Cgraph edge statement index not found");
    1288              :     }
    1289       353420 :   for (i = 0; node->iterate_reference (i, ref); i++)
    1290       242346 :     if (ref->lto_stmt_uid)
    1291              :       {
    1292       236952 :         if (STMT_UID_NOT_IN_RANGE (ref->lto_stmt_uid))
    1293            0 :           fatal_error (input_location,
    1294              :                        "Reference statement index out of range");
    1295       236952 :         ref->stmt = stmts[ref->lto_stmt_uid - 1];
    1296       236952 :         ref->lto_stmt_uid = 0;
    1297       236952 :         if (!ref->stmt)
    1298            0 :           fatal_error (input_location, "Reference statement index not found");
    1299              :       }
    1300       111074 : }
    1301              : 
    1302              : 
    1303              : /* Fixup call_stmt pointers in NODE and all clones.  */
    1304              : 
    1305              : static void
    1306        84776 : fixup_call_stmt_edges (struct cgraph_node *orig, gimple **stmts)
    1307              : {
    1308        84776 :   struct cgraph_node *node;
    1309        84776 :   struct function *fn;
    1310              : 
    1311        84992 :   while (orig->clone_of)
    1312              :     orig = orig->clone_of;
    1313        84776 :   fn = DECL_STRUCT_FUNCTION (orig->decl);
    1314              : 
    1315        84776 :   if (!orig->thunk)
    1316        84776 :     fixup_call_stmt_edges_1 (orig, stmts, fn);
    1317        84776 :   if (orig->clones)
    1318        31283 :     for (node = orig->clones; node != orig;)
    1319              :       {
    1320        26300 :         if (!node->thunk)
    1321        26298 :           fixup_call_stmt_edges_1 (node, stmts, fn);
    1322        26300 :         if (node->clones)
    1323              :           node = node->clones;
    1324        23780 :         else if (node->next_sibling_clone)
    1325              :           node = node->next_sibling_clone;
    1326              :         else
    1327              :           {
    1328        13142 :             while (node != orig && !node->next_sibling_clone)
    1329         7503 :               node = node->clone_of;
    1330         5639 :             if (node != orig)
    1331          656 :               node = node->next_sibling_clone;
    1332              :           }
    1333              :       }
    1334        84776 : }
    1335              : 
    1336              : 
    1337              : /* Input the base body of struct function FN from DATA_IN
    1338              :    using input block IB.  */
    1339              : 
    1340              : static void
    1341        84776 : input_struct_function_base (struct function *fn, class data_in *data_in,
    1342              :                             class lto_input_block *ib)
    1343              : {
    1344        84776 :   struct bitpack_d bp;
    1345        84776 :   int len;
    1346              : 
    1347              :   /* Read the static chain and non-local goto save area.  */
    1348        84776 :   fn->static_chain_decl = stream_read_tree (ib, data_in);
    1349        84776 :   fn->nonlocal_goto_save_area = stream_read_tree (ib, data_in);
    1350              : 
    1351              :   /* Read all the local symbols.  */
    1352        84776 :   len = streamer_read_hwi (ib);
    1353        84776 :   if (len > 0)
    1354              :     {
    1355        22488 :       int i;
    1356        22488 :       vec_safe_grow_cleared (fn->local_decls, len, true);
    1357       184218 :       for (i = 0; i < len; i++)
    1358              :         {
    1359       139242 :           tree t = stream_read_tree (ib, data_in);
    1360       139242 :           (*fn->local_decls)[i] = t;
    1361              :         }
    1362              :     }
    1363              : 
    1364              :   /* Input the current IL state of the function.  */
    1365        84776 :   fn->curr_properties = streamer_read_uhwi (ib);
    1366              : 
    1367              :   /* Read all the attributes for FN.  */
    1368        84776 :   bp = streamer_read_bitpack (ib);
    1369        84776 :   fn->is_thunk = bp_unpack_value (&bp, 1);
    1370        84776 :   fn->has_local_explicit_reg_vars = bp_unpack_value (&bp, 1);
    1371        84776 :   fn->returns_pcc_struct = bp_unpack_value (&bp, 1);
    1372        84776 :   fn->returns_struct = bp_unpack_value (&bp, 1);
    1373        84776 :   fn->can_throw_non_call_exceptions = bp_unpack_value (&bp, 1);
    1374        84776 :   fn->can_delete_dead_exceptions = bp_unpack_value (&bp, 1);
    1375        84776 :   fn->always_inline_functions_inlined = bp_unpack_value (&bp, 1);
    1376        84776 :   fn->after_inlining = bp_unpack_value (&bp, 1);
    1377        84776 :   fn->stdarg = bp_unpack_value (&bp, 1);
    1378        84776 :   fn->has_nonlocal_label = bp_unpack_value (&bp, 1);
    1379        84776 :   fn->has_forced_label_in_static = bp_unpack_value (&bp, 1);
    1380        84776 :   fn->calls_alloca = bp_unpack_value (&bp, 1);
    1381        84776 :   fn->calls_setjmp = bp_unpack_value (&bp, 1);
    1382        84776 :   fn->calls_eh_return = bp_unpack_value (&bp, 1);
    1383        84776 :   fn->has_force_vectorize_loops = bp_unpack_value (&bp, 1);
    1384        84776 :   fn->has_simduid_loops = bp_unpack_value (&bp, 1);
    1385        84776 :   fn->has_musttail = bp_unpack_value (&bp, 1);
    1386        84776 :   fn->has_unroll = bp_unpack_value (&bp, 1);
    1387        84776 :   fn->assume_function = bp_unpack_value (&bp, 1);
    1388        84776 :   fn->va_list_fpr_size = bp_unpack_value (&bp, 8);
    1389        84776 :   fn->va_list_gpr_size = bp_unpack_value (&bp, 8);
    1390        84776 :   fn->last_clique = bp_unpack_value (&bp, sizeof (short) * 8);
    1391              : 
    1392              :   /* Input the function start and end loci.  */
    1393        84776 :   stream_input_location (&fn->function_start_locus, &bp, data_in);
    1394        84776 :   stream_input_location (&fn->function_end_locus, &bp, data_in);
    1395              : 
    1396              :   /* Restore the instance discriminators if present.  */
    1397        84776 :   int instance_number = bp_unpack_value (&bp, 1);
    1398        84776 :   if (instance_number)
    1399              :     {
    1400            0 :       instance_number = bp_unpack_value (&bp, sizeof (int) * CHAR_BIT);
    1401            0 :       maybe_create_decl_to_instance_map ()->put (fn->decl, instance_number);
    1402              :     }
    1403        84776 : }
    1404              : 
    1405              : /* Read a chain of tree nodes from input block IB.  DATA_IN contains
    1406              :    tables and descriptors for the file being read.  */
    1407              : 
    1408              : static tree
    1409        84851 : streamer_read_chain (class lto_input_block *ib, class data_in *data_in)
    1410              : {
    1411        84851 :   tree first, prev, curr;
    1412              : 
    1413              :   /* The chain is written as NULL terminated list of trees.  */
    1414        84851 :   first = prev = NULL_TREE;
    1415       175161 :   do
    1416              :     {
    1417       175161 :       curr = stream_read_tree (ib, data_in);
    1418       175161 :       if (prev)
    1419        90310 :         TREE_CHAIN (prev) = curr;
    1420              :       else
    1421              :         first = curr;
    1422              : 
    1423       175161 :       prev = curr;
    1424              :     }
    1425       175161 :   while (curr);
    1426              : 
    1427        84851 :   return first;
    1428              : }
    1429              : 
    1430              : /* Read the body of function FN_DECL from DATA_IN using input block IB.  */
    1431              : 
    1432              : static void
    1433        84851 : input_function (tree fn_decl, class data_in *data_in,
    1434              :                 class lto_input_block *ib, class lto_input_block *ib_cfg,
    1435              :                 cgraph_node *node)
    1436              : {
    1437        84851 :   struct function *fn;
    1438        84851 :   enum LTO_tags tag;
    1439        84851 :   gimple **stmts;
    1440        84851 :   basic_block bb;
    1441              : 
    1442        84851 :   tag = streamer_read_record_start (ib);
    1443        84851 :   lto_tag_check (tag, LTO_function);
    1444              : 
    1445              :   /* Read decls for parameters and args.  */
    1446        84851 :   DECL_RESULT (fn_decl) = stream_read_tree (ib, data_in);
    1447        84851 :   DECL_ARGUMENTS (fn_decl) = streamer_read_chain (ib, data_in);
    1448              : 
    1449              :   /* Read debug args if available.  */
    1450        84851 :   unsigned n_debugargs = streamer_read_uhwi (ib);
    1451        84851 :   if (n_debugargs)
    1452              :     {
    1453           23 :       vec<tree, va_gc> **debugargs = decl_debug_args_insert (fn_decl);
    1454           23 :       vec_safe_grow (*debugargs, n_debugargs, true);
    1455          108 :       for (unsigned i = 0; i < n_debugargs; ++i)
    1456           62 :         (**debugargs)[i] = stream_read_tree (ib, data_in);
    1457              :     }
    1458              : 
    1459              :   /* Read the tree of lexical scopes for the function.  */
    1460        84851 :   DECL_INITIAL (fn_decl) = stream_read_tree (ib, data_in);
    1461        84851 :   unsigned block_leaf_count = streamer_read_uhwi (ib);
    1462       147355 :   while (block_leaf_count--)
    1463        62504 :     stream_read_tree (ib, data_in);
    1464              : 
    1465        84851 :   if (!streamer_read_uhwi (ib))
    1466              :     return;
    1467              : 
    1468        84776 :   push_struct_function (fn_decl);
    1469        84776 :   fn = DECL_STRUCT_FUNCTION (fn_decl);
    1470              : 
    1471        84776 :   gimple_register_cfg_hooks ();
    1472              : 
    1473        84776 :   input_struct_function_base (fn, data_in, ib);
    1474        84776 :   input_cfg (ib_cfg, data_in, fn);
    1475              : 
    1476              :   /* Read all the SSA names.  */
    1477        84776 :   input_ssa_names (ib, data_in, fn);
    1478              : 
    1479              :   /* Read the exception handling regions in the function.  */
    1480        84776 :   input_eh_regions (ib, data_in, fn);
    1481              : 
    1482        84776 :   gcc_assert (DECL_INITIAL (fn_decl));
    1483        84776 :   DECL_SAVED_TREE (fn_decl) = NULL_TREE;
    1484              : 
    1485              :   /* Read all the basic blocks.  */
    1486        84776 :   tag = streamer_read_record_start (ib);
    1487       839468 :   while (tag)
    1488              :     {
    1489       754692 :       input_bb (ib, tag, data_in, fn,
    1490              :                 node->count_materialization_scale);
    1491       754692 :       tag = streamer_read_record_start (ib);
    1492              :     }
    1493              : 
    1494              :   /* Finalize gimple_location/gimple_block of stmts and phis.  */
    1495        84776 :   data_in->location_cache.apply_location_cache ();
    1496              : 
    1497              :   /* Fix up the call statements that are mentioned in the callgraph
    1498              :      edges.  */
    1499        84776 :   set_gimple_stmt_max_uid (cfun, 0);
    1500       839468 :   FOR_ALL_BB_FN (bb, cfun)
    1501              :     {
    1502       754692 :       gimple_stmt_iterator gsi;
    1503       825436 :       for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    1504              :         {
    1505        70744 :           gimple *stmt = gsi_stmt (gsi);
    1506        70744 :           gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
    1507              :         }
    1508      2925993 :       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    1509              :         {
    1510      1416609 :           gimple *stmt = gsi_stmt (gsi);
    1511      1416609 :           gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
    1512              :         }
    1513              :     }
    1514        84776 :   stmts = (gimple **) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple *));
    1515       839468 :   FOR_ALL_BB_FN (bb, cfun)
    1516              :     {
    1517       754692 :       gimple_stmt_iterator bsi = gsi_start_phis (bb);
    1518       825436 :       while (!gsi_end_p (bsi))
    1519              :         {
    1520        70744 :           gimple *stmt = gsi_stmt (bsi);
    1521        70744 :           gsi_next (&bsi);
    1522        70744 :           stmts[gimple_uid (stmt)] = stmt;
    1523              :         }
    1524       754692 :       bsi = gsi_start_bb (bb);
    1525      2171301 :       while (!gsi_end_p (bsi))
    1526              :         {
    1527      1416609 :           gimple *stmt = gsi_stmt (bsi);
    1528      1416609 :           bool remove = false;
    1529              :           /* If we're recompiling LTO objects with debug stmts but
    1530              :              we're not supposed to have debug stmts, remove them now.
    1531              :              We can't remove them earlier because this would cause uid
    1532              :              mismatches in fixups, but we can do it at this point, as
    1533              :              long as debug stmts don't require fixups.
    1534              :              Similarly remove all IFN_*SAN_* internal calls   */
    1535      1416609 :           if (!flag_wpa)
    1536              :             {
    1537      1324085 :               if (is_gimple_debug (stmt)
    1538      1324085 :                   && (gimple_debug_nonbind_marker_p (stmt)
    1539         8112 :                       ? !MAY_HAVE_DEBUG_MARKER_STMTS
    1540         6017 :                       : !MAY_HAVE_DEBUG_BIND_STMTS))
    1541              :                 remove = true;
    1542              :               /* In case the linemap overflows locations can be dropped
    1543              :                  to zero.  Thus do not keep nonsensical inline entry markers
    1544              :                  we'd later ICE on.  */
    1545      1324085 :               tree block;
    1546      1324085 :               if (gimple_debug_inline_entry_p (stmt)
    1547        14129 :                   && (((block = gimple_block (stmt))
    1548          989 :                        && !inlined_function_outer_scope_p (block))
    1549          989 :                       || !debug_inline_points))
    1550              :                 remove = true;
    1551      1324085 :               if (is_gimple_call (stmt)
    1552      1324085 :                   && gimple_call_internal_p (stmt))
    1553              :                 {
    1554        21496 :                   bool replace = false;
    1555        21496 :                   switch (gimple_call_internal_fn (stmt))
    1556              :                     {
    1557          252 :                     case IFN_UBSAN_NULL:
    1558          252 :                       if ((flag_sanitize
    1559          252 :                           & (SANITIZE_NULL | SANITIZE_ALIGNMENT)) == 0)
    1560              :                         replace = true;
    1561              :                       break;
    1562          235 :                     case IFN_UBSAN_BOUNDS:
    1563          235 :                       if ((flag_sanitize & SANITIZE_BOUNDS) == 0)
    1564              :                         replace = true;
    1565              :                       break;
    1566            0 :                     case IFN_UBSAN_VPTR:
    1567            0 :                       if ((flag_sanitize & SANITIZE_VPTR) == 0)
    1568              :                         replace = true;
    1569              :                       break;
    1570          178 :                     case IFN_UBSAN_OBJECT_SIZE:
    1571          178 :                       if ((flag_sanitize & SANITIZE_OBJECT_SIZE) == 0)
    1572              :                         replace = true;
    1573              :                       break;
    1574          166 :                     case IFN_UBSAN_PTR:
    1575          166 :                       if ((flag_sanitize & SANITIZE_POINTER_OVERFLOW) == 0)
    1576              :                         replace = true;
    1577              :                       break;
    1578          934 :                     case IFN_ASAN_MARK:
    1579          934 :                       if ((flag_sanitize & SANITIZE_ADDRESS) == 0)
    1580              :                         replace = true;
    1581              :                       break;
    1582            0 :                     case IFN_TSAN_FUNC_EXIT:
    1583            0 :                       if ((flag_sanitize & SANITIZE_THREAD) == 0)
    1584              :                         replace = true;
    1585              :                       break;
    1586              :                     default:
    1587              :                       break;
    1588              :                     }
    1589              :                   if (replace)
    1590              :                     {
    1591            2 :                       gimple_call_set_internal_fn (as_a <gcall *> (stmt),
    1592              :                                                    IFN_NOP);
    1593            2 :                       update_stmt (stmt);
    1594              :                     }
    1595              :                 }
    1596              :             }
    1597      1324085 :           if (remove)
    1598              :             {
    1599            4 :               gimple_stmt_iterator gsi = bsi;
    1600            4 :               gsi_next (&bsi);
    1601            4 :               unlink_stmt_vdef (stmt);
    1602            4 :               release_defs (stmt);
    1603            4 :               gsi_remove (&gsi, true);
    1604              :             }
    1605              :           else
    1606              :             {
    1607      1416605 :               gsi_next (&bsi);
    1608      1416605 :               stmts[gimple_uid (stmt)] = stmt;
    1609              : 
    1610              :               /* Remember that the input function has begin stmt
    1611              :                  markers, so that we know to expect them when emitting
    1612              :                  debug info.  */
    1613      1416605 :               if (!cfun->debug_nonbind_markers
    1614      2810008 :                   && gimple_debug_nonbind_marker_p (stmt))
    1615         1363 :                 cfun->debug_nonbind_markers = true;
    1616              :             }
    1617              :         }
    1618              :     }
    1619              : 
    1620              :   /* Set the gimple body to the statement sequence in the entry
    1621              :      basic block.  FIXME lto, this is fairly hacky.  The existence
    1622              :      of a gimple body is used by the cgraph routines, but we should
    1623              :      really use the presence of the CFG.  */
    1624        84776 :   {
    1625        84776 :     edge_iterator ei = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs);
    1626       169552 :     gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));
    1627              :   }
    1628              : 
    1629        84776 :   update_max_bb_count ();
    1630        84776 :   fixup_call_stmt_edges (node, stmts);
    1631        84776 :   execute_all_ipa_stmt_fixups (node, stmts);
    1632              : 
    1633        84776 :   free_dominance_info (CDI_DOMINATORS);
    1634        84776 :   free_dominance_info (CDI_POST_DOMINATORS);
    1635        84776 :   free (stmts);
    1636        84776 :   pop_cfun ();
    1637              : }
    1638              : 
    1639              : /* Read the body of function FN_DECL from DATA_IN using input block IB.  */
    1640              : 
    1641              : static void
    1642         7785 : input_constructor (tree var, class data_in *data_in,
    1643              :                    class lto_input_block *ib)
    1644              : {
    1645         7785 :   DECL_INITIAL (var) = stream_read_tree (ib, data_in);
    1646         7785 : }
    1647              : 
    1648              : 
    1649              : /* Read the body from DATA for function NODE and fill it in.
    1650              :    FILE_DATA are the global decls and types.  SECTION_TYPE is either
    1651              :    LTO_section_function_body or LTO_section_static_initializer.  If
    1652              :    section type is LTO_section_function_body, FN must be the decl for
    1653              :    that function.  */
    1654              : 
    1655              : static void
    1656        92636 : lto_read_body_or_constructor (struct lto_file_decl_data *file_data, struct symtab_node *node,
    1657              :                               const char *data, enum lto_section_type section_type)
    1658              : {
    1659        92636 :   const struct lto_function_header *header;
    1660        92636 :   class data_in *data_in;
    1661        92636 :   int cfg_offset;
    1662        92636 :   int main_offset;
    1663        92636 :   int string_offset;
    1664        92636 :   tree fn_decl = node->decl;
    1665              : 
    1666        92636 :   header = (const struct lto_function_header *) data;
    1667        92636 :   if (TREE_CODE (node->decl) == FUNCTION_DECL)
    1668              :     {
    1669        84851 :       cfg_offset = sizeof (struct lto_function_header);
    1670        84851 :       main_offset = cfg_offset + header->cfg_size;
    1671        84851 :       string_offset = main_offset + header->main_size;
    1672              :     }
    1673              :   else
    1674              :     {
    1675         7785 :       main_offset = sizeof (struct lto_function_header);
    1676         7785 :       string_offset = main_offset + header->main_size;
    1677              :     }
    1678              : 
    1679        92636 :   data_in = lto_data_in_create (file_data, data + string_offset,
    1680        92636 :                               header->string_size, vNULL);
    1681              : 
    1682        92636 :   if (section_type == LTO_section_function_body)
    1683              :     {
    1684        92636 :       struct lto_in_decl_state *decl_state;
    1685        92636 :       unsigned from;
    1686              : 
    1687        92636 :       gcc_checking_assert (node);
    1688              : 
    1689              :       /* Use the function's decl state. */
    1690        92636 :       decl_state = lto_get_function_in_decl_state (file_data, fn_decl);
    1691        92636 :       gcc_assert (decl_state);
    1692        92636 :       file_data->current_decl_state = decl_state;
    1693        92636 :       data_in->location_cache.set_linemap_offset (decl_state->linemap_id);
    1694              : 
    1695              :       /* Set up the struct function.  */
    1696        92636 :       from = data_in->reader_cache->nodes.length ();
    1697        92636 :       lto_input_block ib_main (data + main_offset, header->main_size,
    1698        92636 :                                file_data);
    1699        92636 :       if (TREE_CODE (node->decl) == FUNCTION_DECL)
    1700              :         {
    1701        84851 :           lto_input_block ib_cfg (data + cfg_offset, header->cfg_size,
    1702        84851 :                                   file_data);
    1703        84851 :           input_function (fn_decl, data_in, &ib_main, &ib_cfg,
    1704              :                           dyn_cast <cgraph_node *>(node));
    1705              :         }
    1706              :       else
    1707         7785 :         input_constructor (fn_decl, data_in, &ib_main);
    1708        92636 :       data_in->location_cache.apply_location_cache ();
    1709              :       /* And fixup types we streamed locally.  */
    1710        92636 :         {
    1711        92636 :           struct streamer_tree_cache_d *cache = data_in->reader_cache;
    1712        92636 :           unsigned len = cache->nodes.length ();
    1713        92636 :           unsigned i;
    1714      2913034 :           for (i = len; i-- > from;)
    1715              :             {
    1716      2820398 :               tree t = streamer_tree_cache_get_tree (cache, i);
    1717      2820398 :               if (t == NULL_TREE)
    1718            0 :                 continue;
    1719              : 
    1720      2820398 :               if (TYPE_P (t))
    1721              :                 {
    1722         1734 :                   gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t));
    1723         1734 :                   if (type_with_alias_set_p (t)
    1724         1734 :                       && canonical_type_used_p (t))
    1725          570 :                     TYPE_CANONICAL (t) = TYPE_MAIN_VARIANT (t);
    1726         1734 :                   if (TYPE_MAIN_VARIANT (t) != t)
    1727              :                     {
    1728          129 :                       gcc_assert (TYPE_NEXT_VARIANT (t) == NULL_TREE);
    1729          258 :                       TYPE_NEXT_VARIANT (t)
    1730          129 :                         = TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t));
    1731          129 :                       TYPE_NEXT_VARIANT (TYPE_MAIN_VARIANT (t)) = t;
    1732              :                     }
    1733              :                 }
    1734              :             }
    1735              :         }
    1736              : 
    1737              :       /* Restore decl state */
    1738        92636 :       file_data->current_decl_state = file_data->global_decl_state;
    1739              :     }
    1740              : 
    1741        92636 :   lto_data_in_delete (data_in);
    1742        92636 : }
    1743              : 
    1744              : 
    1745              : /* Read the body of NODE using DATA.  FILE_DATA holds the global
    1746              :    decls and types.  */
    1747              : 
    1748              : void
    1749        84851 : lto_input_function_body (struct lto_file_decl_data *file_data,
    1750              :                          struct cgraph_node *node, const char *data)
    1751              : {
    1752        84851 :   lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body);
    1753        84851 : }
    1754              : 
    1755              : /* Read the body of NODE using DATA.  FILE_DATA holds the global
    1756              :    decls and types.  */
    1757              : 
    1758              : void
    1759         7785 : lto_input_variable_constructor (struct lto_file_decl_data *file_data,
    1760              :                                 struct varpool_node *node, const char *data)
    1761              : {
    1762         7785 :   lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body);
    1763         7785 : }
    1764              : 
    1765              : 
    1766              : /* Queue of acummulated decl -> DIE mappings.  Similar to locations those
    1767              :    are only applied to prevailing tree nodes during tree merging.  */
    1768              : vec<dref_entry> dref_queue;
    1769              : 
    1770              : /* Read the physical representation of a tree node EXPR from
    1771              :    input block IB using the per-file context in DATA_IN.  */
    1772              : 
    1773              : static void
    1774      4437496 : lto_read_tree_1 (class lto_input_block *ib, class data_in *data_in, tree expr)
    1775              : {
    1776              :   /* Read all the bitfield values in EXPR.  Note that for LTO, we
    1777              :      only write language-independent bitfields, so no more unpacking is
    1778              :      needed.  */
    1779      4437496 :   streamer_read_tree_bitfields (ib, data_in, expr);
    1780              : 
    1781              :   /* Read all the pointer fields in EXPR.  */
    1782      4437496 :   streamer_read_tree_body (ib, data_in, expr);
    1783              : 
    1784              :   /* Read any LTO-specific data not read by the tree streamer.  Do not use
    1785              :      stream_read_tree here since that flushes the dref_queue in mids of
    1786              :      SCC reading.  */
    1787      4437496 :   if (DECL_P (expr)
    1788       753413 :       && TREE_CODE (expr) != FUNCTION_DECL
    1789       545641 :       && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
    1790      1046504 :     DECL_INITIAL (expr)
    1791      1046504 :       = lto_input_tree_1 (ib, data_in, streamer_read_record_start (ib), 0);
    1792              : 
    1793              :   /* Stream references to early generated DIEs.  Keep in sync with the
    1794              :      trees handled in dwarf2out_register_external_die.  */
    1795      4437496 :   if ((DECL_P (expr)
    1796              :        && TREE_CODE (expr) != FIELD_DECL
    1797              :        && TREE_CODE (expr) != DEBUG_EXPR_DECL
    1798              :        && TREE_CODE (expr) != TYPE_DECL)
    1799      3782964 :       || TREE_CODE (expr) == BLOCK)
    1800              :     {
    1801       939929 :       const char *str = streamer_read_string (data_in, ib);
    1802       939929 :       if (str)
    1803              :         {
    1804        44380 :           unsigned HOST_WIDE_INT off = streamer_read_uhwi (ib);
    1805        44380 :           dref_entry e = { expr, str, off };
    1806        44380 :           dref_queue.safe_push (e);
    1807              :         }
    1808              :       /* When there's no early DIE to refer to but dwarf2out set up
    1809              :          things in a way to expect that fixup.  This tends to happen
    1810              :          with -g1, see for example PR113488.  */
    1811       895549 :       else if (DECL_P (expr) && DECL_ABSTRACT_ORIGIN (expr) == expr)
    1812            0 :         DECL_ABSTRACT_ORIGIN (expr) = NULL_TREE;
    1813              :     }
    1814              : 
    1815              : #ifdef ACCEL_COMPILER
    1816              :   if ((VAR_P (expr)
    1817              :        || TREE_CODE (expr) == PARM_DECL
    1818              :        || TREE_CODE (expr) == FIELD_DECL)
    1819              :       && DECL_MODE (expr) == VOIDmode)
    1820              :     {
    1821              :       tree type = TREE_TYPE (expr);
    1822              :       if (AGGREGATE_TYPE_P (type))
    1823              :         SET_DECL_MODE (expr, TYPE_MODE (type));
    1824              :       else if (VECTOR_TYPE_P (type))
    1825              :         SET_DECL_MODE (expr, TYPE_MODE_RAW (type));
    1826              :     }
    1827              : 
    1828              :   if (VECTOR_TYPE_P (expr) && TYPE_MODE (expr) == VOIDmode)
    1829              :     {
    1830              :       poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (expr);
    1831              :       tree innertype = TREE_TYPE (expr);
    1832              :       machine_mode vmode
    1833              :         = mode_for_vector (SCALAR_TYPE_MODE (innertype), nunits).else_blk ();
    1834              :       SET_TYPE_MODE (expr, vmode);
    1835              :     }
    1836              : #endif
    1837      4437496 : }
    1838              : 
    1839              : /* Read the physical representation of a tree node with tag TAG from
    1840              :    input block IB using the per-file context in DATA_IN.  */
    1841              : 
    1842              : static tree
    1843      4246351 : lto_read_tree (class lto_input_block *ib, class data_in *data_in,
    1844              :                enum LTO_tags tag, hashval_t hash)
    1845              : {
    1846              :   /* Instantiate a new tree node.  */
    1847      4246351 :   tree result = streamer_alloc_tree (ib, data_in, tag);
    1848              : 
    1849              :   /* Enter RESULT in the reader cache.  This will make RESULT
    1850              :      available so that circular references in the rest of the tree
    1851              :      structure can be resolved in subsequent calls to stream_read_tree.  */
    1852      4246351 :   streamer_tree_cache_append (data_in->reader_cache, result, hash);
    1853              : 
    1854      4246351 :   lto_read_tree_1 (ib, data_in, result);
    1855              : 
    1856      4246351 :   return result;
    1857              : }
    1858              : 
    1859              : 
    1860              : /* Populate the reader cache with trees materialized from the SCC
    1861              :    following in the IB, DATA_IN stream.
    1862              :    If SHARED_SCC is true we input LTO_tree_scc.  */
    1863              : 
    1864              : hashval_t
    1865      2125169 : lto_input_scc (class lto_input_block *ib, class data_in *data_in,
    1866              :                unsigned *len, unsigned *entry_len, bool shared_scc)
    1867              : {
    1868      2125169 :   unsigned size = streamer_read_uhwi (ib);
    1869      2125169 :   hashval_t scc_hash = 0;
    1870      2125169 :   unsigned scc_entry_len = 1;
    1871              : 
    1872      2125169 :   if (shared_scc)
    1873              :     {
    1874       763763 :       if (size & 1)
    1875            0 :         scc_entry_len = streamer_read_uhwi (ib);
    1876       763763 :       size /= 2;
    1877       763763 :       scc_hash = streamer_read_uhwi (ib);
    1878              :     }
    1879              : 
    1880      2125169 :   if (size == 1)
    1881              :     {
    1882      2076913 :       enum LTO_tags tag = streamer_read_record_start (ib);
    1883      2076913 :       lto_input_tree_1 (ib, data_in, tag, scc_hash);
    1884              :     }
    1885              :   else
    1886              :     {
    1887        48256 :       unsigned int first = data_in->reader_cache->nodes.length ();
    1888        48256 :       tree result;
    1889              : 
    1890              :       /* Materialize size trees by reading their headers.  */
    1891       239401 :       for (unsigned i = 0; i < size; ++i)
    1892              :         {
    1893       191145 :           enum LTO_tags tag = streamer_read_record_start (ib);
    1894       191145 :           if (tag == LTO_null
    1895       191145 :               || tag == LTO_global_stream_ref
    1896       191145 :               || tag == LTO_tree_pickle_reference
    1897       191145 :               || tag == LTO_integer_cst
    1898              :               || tag == LTO_tree_scc
    1899       191145 :               || tag == LTO_trees)
    1900            0 :             gcc_unreachable ();
    1901              : 
    1902       191145 :           result = streamer_alloc_tree (ib, data_in, tag);
    1903       191145 :           streamer_tree_cache_append (data_in->reader_cache, result, 0);
    1904              :         }
    1905              : 
    1906              :       /* Read the tree bitpacks and references.  */
    1907       239401 :       for (unsigned i = 0; i < size; ++i)
    1908              :         {
    1909       191145 :           result = streamer_tree_cache_get_tree (data_in->reader_cache,
    1910              :                                                  first + i);
    1911       191145 :           lto_read_tree_1 (ib, data_in, result);
    1912              :         }
    1913              :     }
    1914              : 
    1915      2125169 :   *len = size;
    1916      2125169 :   *entry_len = scc_entry_len;
    1917      2125169 :   return scc_hash;
    1918              : }
    1919              : 
    1920              : /* Read reference to tree from IB and DATA_IN.
    1921              :    This is used for streaming tree bodies where we know that
    1922              :    the tree is already in cache or is indexable and
    1923              :    must be matched with stream_write_tree_ref.  */
    1924              : 
    1925              : tree
    1926     19930149 : stream_read_tree_ref (lto_input_block *ib, data_in *data_in)
    1927              : {
    1928     19930149 :   int ix = streamer_read_hwi (ib);
    1929     19930149 :   if (!ix)
    1930              :     return NULL_TREE;
    1931     12269832 :   if (ix > 0)
    1932      9339897 :     return streamer_tree_cache_get_tree (data_in->reader_cache, ix - 1);
    1933              : 
    1934      2929935 :   ix = -ix - 1;
    1935      2929935 :   int id = ix & 1;
    1936      2929935 :   ix /= 2;
    1937              : 
    1938      2929935 :   tree ret;
    1939      2929935 :   if (!id)
    1940      2767591 :     ret = (*data_in->file_data->current_decl_state
    1941      2767591 :            ->streams[LTO_DECL_STREAM])[ix];
    1942              :   else
    1943       162344 :     ret = (*SSANAMES (cfun))[ix];
    1944              :   return ret;
    1945              : }
    1946              : 
    1947              : /* Read a tree from input block IB using the per-file context in
    1948              :    DATA_IN.  This context is used, for example, to resolve references
    1949              :    to previously read nodes.  */
    1950              : 
    1951              : tree
    1952     12814503 : lto_input_tree_1 (class lto_input_block *ib, class data_in *data_in,
    1953              :                   enum LTO_tags tag, hashval_t hash)
    1954              : {
    1955     12814503 :   tree result;
    1956              : 
    1957     12814503 :   gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS);
    1958              : 
    1959     12814503 :   if (tag == LTO_null)
    1960              :     result = NULL_TREE;
    1961              :   else if (tag == LTO_global_stream_ref || tag == LTO_ssa_name_ref)
    1962              :     {
    1963              :       /* If TAG is a reference to an indexable tree, the next value
    1964              :          in IB is the index into the table where we expect to find
    1965              :          that tree.  */
    1966      4074487 :       result = lto_input_tree_ref (ib, data_in, cfun, tag);
    1967              :     }
    1968              :   else if (tag == LTO_tree_pickle_reference)
    1969              :     {
    1970              :       /* If TAG is a reference to a previously read tree, look it up in
    1971              :          the reader cache.  */
    1972      1599841 :       result = streamer_get_pickled_tree (ib, data_in);
    1973              :     }
    1974              :   else if (tag == LTO_integer_cst)
    1975              :     {
    1976              :       /* For shared integer constants in singletons we can use the
    1977              :          existing tree integer constant merging code.  */
    1978       691294 :       tree type = stream_read_tree_ref (ib, data_in);
    1979       691294 :       unsigned HOST_WIDE_INT len = streamer_read_uhwi (ib);
    1980       691294 :       unsigned HOST_WIDE_INT i;
    1981       691294 :       HOST_WIDE_INT abuf[WIDE_INT_MAX_INL_ELTS], *a = abuf;
    1982              : 
    1983       691294 :       if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS))
    1984            8 :         a = XALLOCAVEC (HOST_WIDE_INT, len);
    1985      1388222 :       for (i = 0; i < len; i++)
    1986       696928 :         a[i] = streamer_read_hwi (ib);
    1987       691294 :       gcc_assert (TYPE_PRECISION (type) <= WIDE_INT_MAX_PRECISION);
    1988       691294 :       result
    1989       691294 :         = wide_int_to_tree (type,
    1990       691294 :                             wide_int::from_array (a, len,
    1991       691294 :                                                   TYPE_PRECISION (type)));
    1992       691294 :       streamer_tree_cache_append (data_in->reader_cache, result, hash);
    1993              :     }
    1994              :   else if (tag == LTO_tree_scc || tag == LTO_trees)
    1995            0 :     gcc_unreachable ();
    1996              :   else
    1997              :     {
    1998              :       /* Otherwise, materialize a new node from IB.  */
    1999      4246351 :       result = lto_read_tree (ib, data_in, tag, hash);
    2000              :     }
    2001              : 
    2002     12814503 :   return result;
    2003              : }
    2004              : 
    2005              : tree
    2006      8957051 : lto_input_tree (class lto_input_block *ib, class data_in *data_in)
    2007              : {
    2008      8957051 :   enum LTO_tags tag;
    2009              : 
    2010              :   /* Input pickled trees needed to stream in the reference.  */
    2011     10302860 :   while ((tag = streamer_read_record_start (ib)) == LTO_trees)
    2012              :     {
    2013      1345809 :       unsigned len, entry_len;
    2014      1345809 :       lto_input_scc (ib, data_in, &len, &entry_len, false);
    2015              : 
    2016              :       /* Register DECLs with the debuginfo machinery.  */
    2017      2812902 :       while (!dref_queue.is_empty ())
    2018              :         {
    2019        10908 :           dref_entry e = dref_queue.pop ();
    2020        10908 :           debug_hooks->register_external_die (e.decl, e.sym, e.off);
    2021              :         }
    2022              :     }
    2023      8957051 :   tree t = lto_input_tree_1 (ib, data_in, tag, 0);
    2024              : 
    2025      8957051 :   if (!dref_queue.is_empty ())
    2026              :     {
    2027         9425 :       dref_entry e = dref_queue.pop ();
    2028         9425 :       debug_hooks->register_external_die (e.decl, e.sym, e.off);
    2029         9425 :       gcc_checking_assert (dref_queue.is_empty ());
    2030              :     }
    2031      8957051 :   return t;
    2032              : }
    2033              : 
    2034              : 
    2035              : /* Input toplevel asms.  */
    2036              : 
    2037              : void
    2038        21741 : lto_input_toplevel_asms (struct lto_file_decl_data *file_data, int order_base)
    2039              : {
    2040        21741 :   size_t len;
    2041        21741 :   const char *data
    2042        21741 :     = lto_get_summary_section_data (file_data, LTO_section_asm, &len);
    2043        21741 :   const struct lto_simple_header_with_strings *header
    2044              :     = (const struct lto_simple_header_with_strings *) data;
    2045        21741 :   int string_offset;
    2046        21741 :   class data_in *data_in;
    2047              : 
    2048        21741 :   if (! data)
    2049        21630 :     return;
    2050              : 
    2051          111 :   string_offset = sizeof (*header) + header->main_size;
    2052              : 
    2053          111 :   lto_input_block ib (data + sizeof (*header), header->main_size,
    2054          111 :                       file_data);
    2055              : 
    2056          111 :   data_in = lto_data_in_create (file_data, data + string_offset,
    2057          111 :                               header->string_size, vNULL);
    2058              : 
    2059          111 :   unsigned asm_count = streamer_read_uhwi (&ib);
    2060          263 :   for (unsigned i = 0; i < asm_count; i++)
    2061              :     {
    2062          152 :       tree str = stream_read_tree (&ib, data_in);
    2063          152 :       asm_node *node = symtab->finalize_toplevel_asm (str);
    2064          152 :       node->order = streamer_read_hwi (&ib) + order_base;
    2065          152 :       node->lto_file_data = file_data;
    2066          152 :       if (node->order >= symtab->order)
    2067            0 :         symtab->order = node->order + 1;
    2068              :     }
    2069              : 
    2070          111 :   lto_data_in_delete (data_in);
    2071              : 
    2072          111 :   lto_free_section_data (file_data, LTO_section_asm, NULL, data, len);
    2073              : }
    2074              : 
    2075              : 
    2076              : /* Input mode table.  */
    2077              : 
    2078              : void
    2079            0 : lto_input_mode_table (struct lto_file_decl_data *file_data)
    2080              : {
    2081            0 :   size_t len;
    2082            0 :   const char *data
    2083            0 :     = lto_get_summary_section_data (file_data, LTO_section_mode_table, &len);
    2084            0 :   if (! data)
    2085            0 :     internal_error ("cannot read LTO mode table from %s",
    2086              :                     file_data->file_name);
    2087              : 
    2088            0 :   const struct lto_simple_header_with_strings *header
    2089              :     = (const struct lto_simple_header_with_strings *) data;
    2090            0 :   int string_offset;
    2091            0 :   class data_in *data_in;
    2092            0 :   string_offset = sizeof (*header) + header->main_size;
    2093              : 
    2094            0 :   lto_input_block ib (data + sizeof (*header), header->main_size, NULL);
    2095            0 :   data_in = lto_data_in_create (file_data, data + string_offset,
    2096            0 :                                 header->string_size, vNULL);
    2097            0 :   bitpack_d bp = streamer_read_bitpack (&ib);
    2098              : 
    2099              : #ifdef ACCEL_COMPILER
    2100              :   host_num_poly_int_coeffs
    2101              :     = bp_unpack_value (&bp, MAX_NUM_POLY_INT_COEFFS_BITS);
    2102              : #endif
    2103              : 
    2104            0 :   unsigned mode_bits = bp_unpack_value (&bp, 5);
    2105            0 :   unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (1 << mode_bits);
    2106              : 
    2107            0 :   file_data->mode_table = table;
    2108            0 :   file_data->mode_bits = mode_bits;
    2109              : 
    2110            0 :   table[VOIDmode] = VOIDmode;
    2111            0 :   table[BLKmode] = BLKmode;
    2112            0 :   unsigned int m;
    2113            0 :   while ((m = bp_unpack_value (&bp, mode_bits)) != VOIDmode)
    2114              :     {
    2115            0 :       enum mode_class mclass
    2116            0 :         = bp_unpack_enum (&bp, mode_class, MAX_MODE_CLASS);
    2117            0 :       poly_uint16 size = bp_unpack_poly_value (&bp, 16);
    2118            0 :       poly_uint16 prec = bp_unpack_poly_value (&bp, 16);
    2119            0 :       machine_mode inner = (machine_mode) bp_unpack_value (&bp, mode_bits);
    2120            0 :       poly_uint16 nunits = bp_unpack_poly_value (&bp, 16);
    2121            0 :       unsigned int ibit = 0, fbit = 0;
    2122            0 :       unsigned int real_fmt_len = 0;
    2123            0 :       const char *real_fmt_name = NULL;
    2124            0 :       switch (mclass)
    2125              :         {
    2126            0 :         case MODE_FRACT:
    2127            0 :         case MODE_UFRACT:
    2128            0 :         case MODE_ACCUM:
    2129            0 :         case MODE_UACCUM:
    2130            0 :           ibit = bp_unpack_value (&bp, 8);
    2131            0 :           fbit = bp_unpack_value (&bp, 8);
    2132            0 :           break;
    2133            0 :         case MODE_FLOAT:
    2134            0 :         case MODE_DECIMAL_FLOAT:
    2135            0 :           real_fmt_name = bp_unpack_indexed_string (data_in, &bp,
    2136              :                                                     &real_fmt_len);
    2137            0 :           break;
    2138              :         default:
    2139              :           break;
    2140              :         }
    2141              :       /* First search just the GET_CLASS_NARROWEST_MODE to wider modes,
    2142              :          if not found, fallback to all modes.  When found, pass is 3 (2 + 1),
    2143              :          when not found, pass is 2 ('< 2' check + 1).  */
    2144            0 :       int pass;
    2145            0 :       for (pass = 0; pass < 2; pass++)
    2146            0 :         for (machine_mode mr = pass ? VOIDmode
    2147            0 :                                     : GET_CLASS_NARROWEST_MODE (mclass);
    2148            0 :              pass ? mr < MAX_MACHINE_MODE : mr != VOIDmode;
    2149            0 :              pass ? mr = (machine_mode) (mr + 1)
    2150            0 :                   : mr = GET_MODE_WIDER_MODE (mr).else_void ())
    2151            0 :           if (GET_MODE_CLASS (mr) != mclass
    2152            0 :               || maybe_ne (GET_MODE_SIZE (mr), size)
    2153            0 :               || maybe_ne (GET_MODE_PRECISION (mr), prec)
    2154            0 :               || (inner == m
    2155            0 :                   ? GET_MODE_INNER (mr) != mr
    2156            0 :                   : GET_MODE_INNER (mr) != table[(int) inner])
    2157            0 :               || GET_MODE_IBIT (mr) != ibit
    2158            0 :               || GET_MODE_FBIT (mr) != fbit
    2159            0 :               || maybe_ne (GET_MODE_NUNITS (mr), nunits))
    2160            0 :             continue;
    2161            0 :           else if ((mclass == MODE_FLOAT || mclass == MODE_DECIMAL_FLOAT)
    2162            0 :                    && strcmp (REAL_MODE_FORMAT (mr)->name, real_fmt_name) != 0)
    2163            0 :             continue;
    2164              :           else
    2165              :             {
    2166              :               /* Found.  */
    2167            0 :               table[m] = mr;
    2168            0 :               pass = 2;  /* Will be 3 after the outer loop.  */
    2169              : #ifdef ACCEL_COMPILER
    2170              :               /* A mode used by the host code - and generally supported by the
    2171              :                  offloading-target compiler might not actually be available,
    2172              :                  depending e.g. on -march or other other commandline options.
    2173              :                  Hence, check again and, if failing, diagnose it below.  */
    2174              :               if (scalar_mode::includes_p (mr)
    2175              :                   && !targetm.scalar_mode_supported_p (
    2176              :                         scalar_mode::from_int (mr)))
    2177              :                 pass = 1;  /* Such that pass == 2 after the outer loop. */
    2178              : #endif
    2179            0 :               break;
    2180              :             }
    2181            0 :       unsigned int mname_len;
    2182            0 :       const char *mname = bp_unpack_indexed_string (data_in, &bp, &mname_len);
    2183            0 :       if (pass == 2)
    2184              :         {
    2185            0 :           switch (mclass)
    2186              :             {
    2187            0 :             case MODE_VECTOR_BOOL:
    2188            0 :             case MODE_VECTOR_INT:
    2189            0 :             case MODE_VECTOR_FLOAT:
    2190            0 :             case MODE_VECTOR_FRACT:
    2191            0 :             case MODE_VECTOR_UFRACT:
    2192            0 :             case MODE_VECTOR_ACCUM:
    2193            0 :             case MODE_VECTOR_UACCUM:
    2194              :               /* Vector modes are recomputed on accel side and shouldn't have
    2195              :                  been streamed-out from host.  */
    2196            0 :               gcc_unreachable ();
    2197              :               /* FALLTHRU */
    2198            0 :             default:
    2199              :               /* This is only used for offloading-target compilations and
    2200              :                  is a user-facing error.  Give a better error message for
    2201              :                  the common modes; see also mode-classes.def.   */
    2202            0 :               if (mclass == MODE_FLOAT)
    2203            0 :                 fatal_error (UNKNOWN_LOCATION,
    2204              :                              "%s - %u-bit-precision floating-point numbers "
    2205              :                              "unsupported (mode %qs)", TARGET_MACHINE,
    2206            0 :                              prec.to_constant (), mname);
    2207            0 :               else if (mclass == MODE_DECIMAL_FLOAT)
    2208            0 :                 fatal_error (UNKNOWN_LOCATION,
    2209              :                              "%s - %u-bit-precision decimal floating-point "
    2210              :                              "numbers unsupported (mode %qs)", TARGET_MACHINE,
    2211            0 :                              prec.to_constant (), mname);
    2212            0 :               else if (mclass == MODE_COMPLEX_FLOAT)
    2213            0 :                 fatal_error (UNKNOWN_LOCATION,
    2214              :                              "%s - %u-bit-precision complex floating-point "
    2215              :                              "numbers unsupported (mode %qs)", TARGET_MACHINE,
    2216            0 :                              prec.to_constant (), mname);
    2217            0 :               else if (mclass == MODE_INT)
    2218            0 :                 fatal_error (UNKNOWN_LOCATION,
    2219              :                              "%s - %u-bit integer numbers unsupported (mode "
    2220            0 :                              "%qs)", TARGET_MACHINE, prec.to_constant (), mname);
    2221              :               else
    2222            0 :                 fatal_error (UNKNOWN_LOCATION, "%s - unsupported mode %qs",
    2223              :                              TARGET_MACHINE, mname);
    2224            0 :               break;
    2225              :             }
    2226              :         }
    2227              :     }
    2228            0 :   lto_data_in_delete (data_in);
    2229              : 
    2230            0 :   lto_free_section_data (file_data, LTO_section_mode_table, NULL, data, len);
    2231            0 : }
    2232              : 
    2233              : 
    2234              : /* Initialization for the LTO reader.  */
    2235              : 
    2236              : void
    2237        20649 : lto_reader_init (void)
    2238              : {
    2239        20649 :   lto_streamer_init ();
    2240        20649 :   file_name_hash_table
    2241        20649 :     = new hash_table<string_slot_hasher> (37);
    2242        41298 :   string_slot_allocator = new object_allocator <struct string_slot>
    2243        20649 :                                 ("line map file name hash");
    2244        20649 :   gcc_obstack_init (&file_name_obstack);
    2245        20649 : }
    2246              : 
    2247              : /* Free hash table used to stream in location file names.  */
    2248              : 
    2249              : void
    2250         7862 : lto_free_file_name_hash (void)
    2251              : {
    2252         7862 :   delete file_name_hash_table;
    2253         7862 :   file_name_hash_table = NULL;
    2254        15724 :   delete string_slot_allocator;
    2255         7862 :   string_slot_allocator = NULL;
    2256         7862 :   delete path_name_pair_hash_table;
    2257         7862 :   path_name_pair_hash_table = NULL;
    2258         7862 :   delete string_pair_map_allocator;
    2259         7862 :   string_pair_map_allocator = NULL;
    2260              :   /* file_name_obstack must stay allocated since it is referred to by
    2261              :      line map table.  */
    2262         7862 : }
    2263              : 
    2264              : 
    2265              : /* Create a new data_in object for FILE_DATA. STRINGS is the string
    2266              :    table to use with LEN strings.  RESOLUTIONS is the vector of linker
    2267              :    resolutions (NULL if not using a linker plugin).  */
    2268              : 
    2269              : class data_in *
    2270       224589 : lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings,
    2271              :                     unsigned len,
    2272              :                     vec<ld_plugin_symbol_resolution_t> resolutions,
    2273              :                     bool need_location_cache)
    2274              : {
    2275       224589 :   const auto d = new data_in{need_location_cache ? file_data : nullptr};
    2276       224589 :   d->file_data = file_data;
    2277       224589 :   d->strings = strings;
    2278       224589 :   d->strings_len = len;
    2279       224589 :   d->globals_resolution = resolutions;
    2280       224589 :   d->reader_cache = streamer_tree_cache_create (false, false, true);
    2281       224589 :   return d;
    2282              : }
    2283              : 
    2284              : 
    2285              : /* Remove DATA_IN.  */
    2286              : 
    2287              : void
    2288       224589 : lto_data_in_delete (class data_in *data_in)
    2289              : {
    2290       224589 :   data_in->globals_resolution.release ();
    2291       224589 :   streamer_tree_cache_delete (data_in->reader_cache);
    2292       224589 :   delete data_in;
    2293       224589 : }
        

Generated by: LCOV version 2.5.0-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.