LCOV - code coverage report
Current view: top level - gcc - lto-streamer-in.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 77.7 % 1164 904
Test Date: 2026-12-05 16:10:02 Functions: 88.7 % 53 47
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      1452544 : lto_tag_check_set (enum LTO_tags actual, int ntags, ...)
     111              : {
     112      1452544 :   va_list ap;
     113      1452544 :   int i;
     114              : 
     115      1452544 :   va_start (ap, ntags);
     116      2899927 :   for (i = 0; i < ntags; i++)
     117      2899927 :     if ((unsigned) actual == va_arg (ap, unsigned))
     118              :       {
     119      1452544 :         va_end (ap);
     120      1452544 :         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        54036 : canon_file_name (const char *relative_prefix, const char *string)
     346              : {
     347        54036 :   if (relative_prefix && !IS_ABSOLUTE_PATH (string))
     348            0 :     return canon_relative_file_name (relative_prefix, string);
     349              : 
     350        54036 :   string_slot **slot;
     351        54036 :   struct string_slot s_slot;
     352        54036 :   size_t len = strlen (string);
     353              : 
     354        54036 :   s_slot.s = string;
     355        54036 :   s_slot.len = len;
     356              : 
     357        54036 :   slot = file_name_hash_table->find_slot (&s_slot, INSERT);
     358        54036 :   if (*slot == NULL)
     359              :     {
     360        49802 :       char *saved_string;
     361        49802 :       struct string_slot *new_slot;
     362              : 
     363        49802 :       saved_string = XOBNEWVEC (&file_name_obstack, char, len + 1);
     364        49802 :       new_slot = string_slot_allocator->allocate ();
     365        49802 :       memcpy (saved_string, string, len + 1);
     366        49802 :       new_slot->s = saved_string;
     367        49802 :       new_slot->len = len;
     368        49802 :       *slot = new_slot;
     369        49802 :       return saved_string;
     370              :     }
     371              :   else
     372              :     {
     373         4234 :       struct string_slot *old_slot = *slot;
     374         4234 :       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      3109014 : get_location_from_idx (size_t map_idx, location_t offset,
     383              :                        const lto_loc_map *loc_map)
     384              : {
     385      3109014 :   if (!map_idx)
     386              :     return offset;
     387      3109014 :   gcc_checking_assert (loc_map);
     388      3109014 :   --map_idx;
     389      3109014 :   gcc_assert (map_idx < loc_map->nmaps);
     390      3109014 :   const auto map = LINEMAPS_ORDINARY_MAP_AT (line_table, loc_map->map[map_idx]);
     391      3109014 :   const location_t res = map->start_location + offset;
     392      3109014 :   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       649318 : lto_location_cache::apply_location_cache ()
     407              : {
     408       649318 :   if (loc_cache.is_empty ())
     409              :     return true;
     410              : 
     411      2036101 :   for (const auto &cloc: loc_cache)
     412              :     {
     413      1751678 :       const location_t loc = cloc.loc;
     414      1751678 :       const auto range = source_range::from_location (loc);
     415      1751678 :       *cloc.dest = line_table->get_or_create_combined_loc (loc, range,
     416      1751678 :                                                            cloc.block,
     417      1751678 :                                                            cloc.discr);
     418              :     }
     419       568846 :   current_cloc = loc_cache[loc_cache.length () - 1];
     420       284423 :   current_loc = *current_cloc.dest;
     421       284423 :   loc_cache.truncate (0);
     422       284423 :   accepted_length = 0;
     423       284423 :   return true;
     424              : }
     425              : 
     426              : /* Tree merging did not succeed; mark all changes in the cache as accepted.  */
     427              : 
     428              : void
     429      1943909 : lto_location_cache::accept_location_cache ()
     430              : {
     431      1943909 :   gcc_assert (current_cache == this);
     432      1943909 :   accepted_length = loc_cache.length ();
     433      1943909 : }
     434              : 
     435              : /* Tree merging did succeed; throw away recent changes.  */
     436              : 
     437              : void
     438       150097 : lto_location_cache::revert_location_cache ()
     439              : {
     440       150097 :   loc_cache.truncate (accepted_length);
     441       150097 : }
     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      6146918 : bp_unpack_delta (bitpack_d *bp, Int &prev)
     449              : {
     450      6146918 :   const bool decrease = bp_unpack_value (bp, 1);
     451      6146918 :   const Int delta = bp_unpack_var_len_unsigned (bp);
     452      6146918 :   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        24415 : create_loc_map (lto_file_decl_data *file_data, unsigned linemap_id)
     462              : {
     463        24415 :   timevar_push (TV_IPA_LTO_LINEMAP_IN);
     464              : 
     465        24415 :   size_t len;
     466        24415 :   const auto data = lto_get_section_data (file_data, LTO_section_linemap,
     467              :                                           nullptr, linemap_id, &len, true);
     468        24415 :   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        24415 :   const auto header = (const lto_simple_header_with_strings *) data;
     474        24415 :   const char *const main_begin = data + sizeof (*header);
     475        24415 :   const auto data_in
     476        48830 :     = lto_data_in_create (file_data, main_begin + header->main_size,
     477        24415 :                           header->string_size, vNULL, false);
     478        24415 :   lto_input_block ib (main_begin, header->main_size, file_data);
     479        24415 :   bitpack_d bp = streamer_read_bitpack (&ib);
     480              : 
     481              :   /* Create the location map object.  */
     482        24415 :   const size_t nmaps = bp_unpack_var_len_unsigned (&bp);
     483        24415 :   size_t loc_map_sz = sizeof (lto_loc_map);
     484        24415 :   if (nmaps > 1)
     485         5728 :     loc_map_sz += (nmaps - 1) * sizeof (size_t);
     486        24415 :   const auto loc_map = (lto_loc_map *) ggc_internal_alloc (loc_map_sz);
     487        24415 :   loc_map->nmaps = nmaps;
     488              : 
     489              :   /* Read the line map data.  */
     490        24415 :   const char *stream_relative_path_prefix = nullptr;
     491        24415 :   const char *stream_file = nullptr;
     492        24415 :   size_t cur_map_idx = 0;
     493        24415 :   linenum_type cur_line = 0;
     494        78451 :   for (size_t i = 0; i != nmaps; ++i)
     495              :     {
     496        54036 :       const size_t map_idx = bp_unpack_delta (&bp, cur_map_idx);
     497        54036 :       gcc_assert (map_idx && map_idx <= nmaps);
     498        54036 :       const line_map_uint_t num_lines = bp_unpack_var_len_unsigned (&bp);
     499        54036 :       const bool sysp = bp_unpack_value (&bp, 1);
     500        54036 :       const unsigned int column_bits = bp_unpack_value (&bp, 8);
     501        54036 :       const linenum_type to_line = bp_unpack_delta (&bp, cur_line);
     502        54036 :       const bool file_change = bp_unpack_value (&bp, 1);
     503        54036 :       if (file_change)
     504              :         {
     505        54036 :           const bool pwd_change = bp_unpack_value (&bp, 1);
     506        54036 :           if (pwd_change)
     507              :             {
     508         3876 :               const char *pwd = bp_unpack_string (data_in, &bp);
     509         3876 :               const char *src_pwd = get_src_pwd ();
     510         3876 :               stream_relative_path_prefix
     511         3876 :                 = strcmp (pwd, src_pwd) == 0 ? nullptr
     512            0 :                 : canon_relative_path_prefix (pwd, src_pwd);
     513              :             }
     514        54036 :           stream_file = canon_file_name (stream_relative_path_prefix,
     515              :                                          bp_unpack_string (data_in, &bp));
     516              :         }
     517        54036 :       gcc_assert (stream_file);
     518        54036 :       const auto map
     519        54036 :         = linemap_add_raw_map (line_table,
     520        54036 :                                line_table->depth ? LC_RENAME : LC_ENTER,
     521        54036 :                                line_table->highest_location + 1, sysp,
     522              :                                column_bits, 0, stream_file, to_line, num_lines);
     523        54036 :       if (!map)
     524            0 :         fatal_error (UNKNOWN_LOCATION,
     525              :                      "Ran out of locations while reading linemap section #%u",
     526              :                      linemap_id);
     527        54036 :       loc_map->map[map_idx - 1] = map - line_table->info_ordinary.maps;
     528        54036 :       if (flag_wpa || flag_incremental_link == INCREMENTAL_LINK_LTO)
     529              :         {
     530        21950 :           const auto out_id = lto_linemap_output_id (linemap_id, file_data);
     531        21950 :           lto_register_linemap_for_output (map_idx, out_id);
     532              :         }
     533              :     }
     534              : 
     535              :   /* Process the diagnostics classification history.  */
     536        24415 :   auto &chist = global_dc->get_classification_history ();
     537        24415 :   const int pop_offset = chist.length ();
     538        24415 :   using DK = diagnostics::kind;
     539       114006 :   for (size_t i = 0, nc = bp_unpack_var_len_unsigned (&bp); i != nc; ++i)
     540              :     {
     541        89591 :       const size_t map_idx = bp_unpack_var_len_unsigned (&bp);
     542        89591 :       const location_t offset = bp_unpack_var_len_unsigned (&bp);
     543        89591 :       const location_t loc = get_location_from_idx (map_idx, offset, loc_map);
     544        89591 :       const int option = bp_unpack_var_len_int (&bp);
     545        89591 :       const auto kind = bp_unpack_enum (&bp, diagnostics::kind,
     546              :                                         DK::tot_num_diagnostic_kinds);
     547        89591 :       if (kind == DK::pop)
     548              :         {
     549        46149 :           diagnostics::option_classifier::classification_change_t c = {};
     550        46149 :           c.location = loc;
     551        46149 :           c.option = option + pop_offset;
     552        46149 :           c.kind = kind;
     553        46149 :           chist.safe_push (c);
     554              :         }
     555              :       else
     556        43442 :         global_dc->classify_diagnostic (option, kind, loc);
     557              :     }
     558              :   /* Make sure we reset back to the baseline.  */
     559        24415 :   {
     560        24415 :     diagnostics::option_classifier::classification_change_t c = {};
     561        24415 :     c.location = line_table->highest_location;
     562        24415 :     c.kind = DK::pop;
     563        24415 :     chist.safe_push (c);
     564              :   }
     565              : 
     566        24415 :   lto_data_in_delete (data_in);
     567        24415 :   lto_free_section_data (file_data, LTO_section_linemap, nullptr,
     568              :                          data, len, true);
     569              : 
     570        24415 :   timevar_pop (TV_IPA_LTO_LINEMAP_IN);
     571        24415 :   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       112201 : 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       159461 :   while (file_data->loc_map_decl_data)
     582              :     file_data = file_data->loc_map_decl_data;
     583              : 
     584       112201 :   if (vec_safe_length (file_data->loc_maps) <= linemap_id)
     585        24184 :     vec_safe_grow_cleared (file_data->loc_maps, linemap_id + 1);
     586       112201 :   auto &res = (*file_data->loc_maps)[linemap_id];
     587       112201 :   if (!res)
     588        24415 :     res = create_loc_map (file_data, linemap_id);
     589       112201 :   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      5135885 : 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      5135885 :   gcc_checking_assert (decl_data);
     604              : 
     605      5135885 :   location_t loc;
     606      5135885 :   unsigned this_discr;
     607      5135885 :   const bool is_reserved = bp_unpack_value (bp, 1);
     608      5135885 :   if (is_reserved)
     609              :     {
     610      2116462 :       loc = bp_unpack_int_in_range (bp, "loc", 0, RESERVED_LOCATION_COUNT - 1);
     611      2116462 :       this_discr = 0;
     612              :     }
     613              :   else
     614              :     {
     615      3019423 :       const bool linemap_change = bp_unpack_value (bp, 1);
     616      3019423 :       if (linemap_change)
     617              :         {
     618       112201 :           const unsigned linemap_id = bp_unpack_var_len_unsigned (bp);
     619       112201 :           cur_loc_map = get_loc_map (decl_data, linemap_id + linemap_offset);
     620              :         }
     621      3019423 :       const auto prev_idx = stream_map_idx;
     622      3019423 :       bp_unpack_delta (bp, stream_map_idx);
     623      3019423 :       bp_unpack_delta (bp, stream_loc_offset);
     624      3019423 :       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       190294 :         bp_unpack_var_len_unsigned (bp);
     628              : 
     629      3019423 :       loc = get_location_from_idx (stream_map_idx, stream_loc_offset,
     630              :                                    cur_loc_map);
     631      3019423 :       if (bp_unpack_value (bp, 1))
     632      1145749 :         stream_discr = bp_unpack_var_len_unsigned (bp);
     633      3019423 :       this_discr = stream_discr;
     634              :     }
     635              : 
     636      5135885 :   tree this_block = NULL_TREE;
     637      5135885 :   if (ib)
     638              :     {
     639      2517579 :       if (bp_unpack_value (bp, 1))
     640       531584 :         stream_block = stream_read_tree (ib, data_in);
     641      2517579 :       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      5135885 :   if (!(this_discr || this_block))
     647              :     {
     648      3361288 :       *dest = loc;
     649      3384207 :       return;
     650              :     }
     651              : 
     652              :   /* This optimization saves location cache operations during gimple
     653              :      streaming.  */
     654      1774597 :   if (loc == current_cloc.loc
     655       192256 :       && this_block == current_cloc.block
     656       108096 :       && this_discr == current_cloc.discr)
     657              :     {
     658        22919 :       *dest = current_loc;
     659        22919 :       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      1751678 :   *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      1751678 :   cached_location entry = {};
     669      1751678 :   entry.dest = dest;
     670      1751678 :   entry.loc = loc;
     671      1751678 :   entry.block = this_block;
     672      1751678 :   entry.discr = this_discr;
     673      1751678 :   loc_cache.safe_push (entry);
     674              : }
     675              : 
     676              : void
     677      2618306 : lto_location_cache::input_location (location_t *dest, struct bitpack_d *bp,
     678              :                                     class data_in *data_in)
     679              : {
     680      2618306 :   return input_location_and_block (dest, bp, NULL, data_in);
     681              : }
     682              : 
     683              : void
     684      2618306 : lto_input_location (location_t *loc, struct bitpack_d *bp,
     685              :                     class data_in *data_in)
     686              : {
     687      2618306 :   data_in->location_cache.input_location (loc, bp, data_in);
     688      2618306 : }
     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      4164210 : lto_input_tree_ref (class lto_input_block *ib, class data_in *data_in,
     699              :                     struct function *fn, enum LTO_tags tag)
     700              : {
     701      4164210 :   unsigned HOST_WIDE_INT ix_u;
     702      4164210 :   tree result = NULL_TREE;
     703              : 
     704      4164210 :   if (tag == LTO_ssa_name_ref)
     705              :     {
     706      1650513 :       ix_u = streamer_read_uhwi (ib);
     707      1650513 :       result = (*SSANAMES (fn))[ix_u];
     708              :     }
     709              :   else
     710              :     {
     711      2513697 :       gcc_checking_assert (tag == LTO_global_stream_ref);
     712      2513697 :       ix_u = streamer_read_uhwi (ib);
     713      2513697 :       result = (*data_in->file_data->current_decl_state
     714      2513697 :                 ->streams[LTO_DECL_STREAM])[ix_u];
     715              :     }
     716              : 
     717      4164210 :   gcc_assert (result);
     718              : 
     719      4164210 :   return result;
     720              : }
     721              : 
     722              : /* Read VAR_DECL reference to DATA from IB.  */
     723              : 
     724              : tree
     725        75858 : lto_input_var_decl_ref (lto_input_block *ib, lto_file_decl_data *file_data)
     726              : {
     727        75858 :   unsigned int ix_u = streamer_read_uhwi (ib);
     728        75858 :   tree result = (*file_data->current_decl_state
     729        75858 :                  ->streams[LTO_DECL_STREAM])[ix_u];
     730        75858 :   gcc_assert (VAR_P (result));
     731        75858 :   return result;
     732              : }
     733              : 
     734              : /* Read VAR_DECL reference to DATA from IB.  */
     735              : 
     736              : tree
     737       202999 : lto_input_fn_decl_ref (lto_input_block *ib, lto_file_decl_data *file_data)
     738              : {
     739       202999 :   unsigned int ix_u = streamer_read_uhwi (ib);
     740       202999 :   tree result = (*file_data->current_decl_state
     741       202999 :                  ->streams[LTO_DECL_STREAM])[ix_u];
     742       202999 :   gcc_assert (TREE_CODE (result) == FUNCTION_DECL);
     743       202999 :   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          213 : lto_input_eh_catch_list (class lto_input_block *ib, class data_in *data_in,
     752              :                          eh_catch *last_p)
     753              : {
     754          213 :   eh_catch first;
     755          213 :   enum LTO_tags tag;
     756              : 
     757          213 :   *last_p = first = NULL;
     758          213 :   tag = streamer_read_record_start (ib);
     759          454 :   while (tag)
     760              :     {
     761          241 :       tree list;
     762          241 :       eh_catch n;
     763              : 
     764          241 :       lto_tag_check_range (tag, LTO_eh_catch, LTO_eh_catch);
     765              : 
     766              :       /* Read the catch node.  */
     767          241 :       n = ggc_cleared_alloc<eh_catch_d> ();
     768          241 :       n->type_list = stream_read_tree (ib, data_in);
     769          241 :       n->filter_list = stream_read_tree (ib, data_in);
     770          241 :       n->label = stream_read_tree (ib, data_in);
     771              : 
     772              :       /* Register all the types in N->FILTER_LIST.  */
     773          241 :       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          241 :       if (*last_p)
     778           44 :         (*last_p)->next_catch = n;
     779          241 :       n->prev_catch = *last_p;
     780          241 :       *last_p = n;
     781              : 
     782              :       /* Set the head of the list the first time through the loop.  */
     783          241 :       if (first == NULL)
     784          197 :         first = n;
     785              : 
     786          241 :       tag = streamer_read_record_start (ib);
     787              :     }
     788              : 
     789          213 :   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        15726 : input_eh_region (class lto_input_block *ib, class data_in *data_in, int ix)
     798              : {
     799        15726 :   enum LTO_tags tag;
     800        15726 :   eh_region r;
     801              : 
     802              :   /* Read the region header.  */
     803        15726 :   tag = streamer_read_record_start (ib);
     804        15726 :   if (tag == LTO_null)
     805              :     return NULL;
     806              : 
     807         9607 :   r = ggc_cleared_alloc<eh_region_d> ();
     808         9607 :   r->index = streamer_read_hwi (ib);
     809              : 
     810         9607 :   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         9607 :   r->outer = (eh_region) (intptr_t) streamer_read_hwi (ib);
     815         9607 :   r->inner = (eh_region) (intptr_t) streamer_read_hwi (ib);
     816         9607 :   r->next_peer = (eh_region) (intptr_t) streamer_read_hwi (ib);
     817              : 
     818         9607 :   switch (tag)
     819              :     {
     820         4030 :       case LTO_ert_cleanup:
     821         4030 :         r->type = ERT_CLEANUP;
     822         4030 :         break;
     823              : 
     824          213 :       case LTO_ert_try:
     825          213 :         {
     826          213 :           struct eh_catch_d *last_catch;
     827          213 :           r->type = ERT_TRY;
     828          213 :           r->u.eh_try.first_catch = lto_input_eh_catch_list (ib, data_in,
     829              :                                                              &last_catch);
     830          213 :           r->u.eh_try.last_catch = last_catch;
     831          213 :           break;
     832              :         }
     833              : 
     834          329 :       case LTO_ert_allowed_exceptions:
     835          329 :         {
     836          329 :           tree l;
     837              : 
     838          329 :           r->type = ERT_ALLOWED_EXCEPTIONS;
     839          329 :           r->u.allowed.type_list = stream_read_tree (ib, data_in);
     840          329 :           r->u.allowed.label = stream_read_tree (ib, data_in);
     841          329 :           r->u.allowed.filter = streamer_read_uhwi (ib);
     842              : 
     843          331 :           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         5035 :       case LTO_ert_must_not_throw:
     849         5035 :         {
     850         5035 :           r->type = ERT_MUST_NOT_THROW;
     851         5035 :           r->u.must_not_throw.failure_decl = stream_read_tree (ib, data_in);
     852         5035 :           bitpack_d bp = streamer_read_bitpack (ib);
     853         5035 :           stream_input_location (&r->u.must_not_throw.failure_loc,
     854              :                                  &bp, data_in);
     855              :         }
     856         5035 :         break;
     857              : 
     858            0 :       default:
     859            0 :         gcc_unreachable ();
     860              :     }
     861              : 
     862         9607 :   r->landing_pads = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
     863              : 
     864         9607 :   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         6893 : input_eh_lp (class lto_input_block *ib, class data_in *data_in, int ix)
     873              : {
     874         6893 :   enum LTO_tags tag;
     875         6893 :   eh_landing_pad lp;
     876              : 
     877              :   /* Read the landing pad header.  */
     878         6893 :   tag = streamer_read_record_start (ib);
     879         6893 :   if (tag == LTO_null)
     880              :     return NULL;
     881              : 
     882         2593 :   lto_tag_check_range (tag, LTO_eh_landing_pad, LTO_eh_landing_pad);
     883              : 
     884         2593 :   lp = ggc_cleared_alloc<eh_landing_pad_d> ();
     885         2593 :   lp->index = streamer_read_hwi (ib);
     886         2593 :   gcc_assert (lp->index == ix);
     887         2593 :   lp->next_lp = (eh_landing_pad) (intptr_t) streamer_read_hwi (ib);
     888         2593 :   lp->region = (eh_region) (intptr_t) streamer_read_hwi (ib);
     889         2593 :   lp->post_landing_pad = stream_read_tree (ib, data_in);
     890              : 
     891         2593 :   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         3692 : fixup_eh_region_pointers (struct function *fn, HOST_WIDE_INT root_region)
     902              : {
     903         3692 :   unsigned i;
     904         3692 :   vec<eh_region, va_gc> *eh_array = fn->eh->region_array;
     905         3692 :   vec<eh_landing_pad, va_gc> *lp_array = fn->eh->lp_array;
     906         3692 :   eh_region r;
     907         3692 :   eh_landing_pad lp;
     908              : 
     909         3692 :   gcc_assert (eh_array && lp_array);
     910              : 
     911         3692 :   gcc_assert (root_region >= 0);
     912         3692 :   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        19418 :   FOR_EACH_VEC_ELT (*eh_array, i, r)
     920              :     {
     921              :       /* The array may contain NULL regions.  */
     922        15726 :       if (r == NULL)
     923         6119 :         continue;
     924              : 
     925         9607 :       gcc_assert (i == (unsigned) r->index);
     926         9607 :       FIXUP_EH_REGION (r->outer);
     927         9607 :       FIXUP_EH_REGION (r->inner);
     928         9607 :       FIXUP_EH_REGION (r->next_peer);
     929         9607 :       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        10585 :   FOR_EACH_VEC_ELT (*lp_array, i, lp)
     935              :     {
     936              :       /* The array may contain NULL landing pads.  */
     937         6893 :       if (lp == NULL)
     938         4300 :         continue;
     939              : 
     940         2593 :       gcc_assert (i == (unsigned) lp->index);
     941         2593 :       FIXUP_EH_LP (lp->next_lp);
     942         2593 :       FIXUP_EH_REGION (lp->region);
     943              :     }
     944              : 
     945              : #undef FIXUP_EH_REGION
     946              : #undef FIXUP_EH_LP
     947         3692 : }
     948              : 
     949              : 
     950              : /* Initialize EH support.  */
     951              : 
     952              : void
     953        44296 : lto_init_eh (void)
     954              : {
     955        44296 :   static bool eh_initialized_p = false;
     956              : 
     957        44296 :   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         4503 :   flag_exceptions = 1;
     966         4503 :   init_eh ();
     967              : 
     968         4503 :   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        86860 : input_eh_regions (class lto_input_block *ib, class data_in *data_in,
     977              :                   struct function *fn)
     978              : {
     979        86860 :   HOST_WIDE_INT i, root_region, len;
     980        86860 :   enum LTO_tags tag;
     981              : 
     982        86860 :   tag = streamer_read_record_start (ib);
     983        86860 :   if (tag == LTO_null)
     984              :     return;
     985              : 
     986         3692 :   lto_tag_check_range (tag, LTO_eh_table, LTO_eh_table);
     987              : 
     988         3692 :   gcc_assert (fn->eh);
     989              : 
     990         3692 :   root_region = streamer_read_hwi (ib);
     991         3692 :   gcc_assert (root_region == (int) root_region);
     992              : 
     993              :   /* Read the EH region array.  */
     994         3692 :   len = streamer_read_hwi (ib);
     995         3692 :   gcc_assert (len == (int) len);
     996         3692 :   if (len > 0)
     997              :     {
     998         3692 :       vec_safe_grow_cleared (fn->eh->region_array, len, true);
     999        23110 :       for (i = 0; i < len; i++)
    1000              :         {
    1001        15726 :           eh_region r = input_eh_region (ib, data_in, i);
    1002        15726 :           (*fn->eh->region_array)[i] = r;
    1003              :         }
    1004              :     }
    1005              : 
    1006              :   /* Read the landing pads.  */
    1007         3692 :   len = streamer_read_hwi (ib);
    1008         3692 :   gcc_assert (len == (int) len);
    1009         3692 :   if (len > 0)
    1010              :     {
    1011         3692 :       vec_safe_grow_cleared (fn->eh->lp_array, len, true);
    1012        14277 :       for (i = 0; i < len; i++)
    1013              :         {
    1014         6893 :           eh_landing_pad lp = input_eh_lp (ib, data_in, i);
    1015         6893 :           (*fn->eh->lp_array)[i] = lp;
    1016              :         }
    1017              :     }
    1018              : 
    1019              :   /* Read the runtime type data.  */
    1020         3692 :   len = streamer_read_hwi (ib);
    1021         3692 :   gcc_assert (len == (int) len);
    1022         3692 :   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         3692 :   len = streamer_read_hwi (ib);
    1034         3692 :   gcc_assert (len == (int) len);
    1035         3692 :   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         3692 :   fixup_eh_region_pointers (fn, root_region);
    1060              : 
    1061         3692 :   tag = streamer_read_record_start (ib);
    1062         3692 :   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       593565 : make_new_block (struct function *fn, unsigned int index)
    1070              : {
    1071       593565 :   basic_block bb = alloc_block ();
    1072       593565 :   bb->index = index;
    1073       593565 :   SET_BASIC_BLOCK_FOR_FN (fn, index, bb);
    1074       593565 :   n_basic_blocks_for_fn (fn)++;
    1075       593565 :   return bb;
    1076              : }
    1077              : 
    1078              : 
    1079              : /* Read the CFG for function FN from input block IB.  */
    1080              : 
    1081              : static void
    1082        86860 : input_cfg (class lto_input_block *ib, class data_in *data_in,
    1083              :            struct function *fn)
    1084              : {
    1085        86860 :   unsigned int bb_count;
    1086        86860 :   basic_block p_bb;
    1087        86860 :   unsigned int i;
    1088        86860 :   int index;
    1089        86860 :   bool full_profile = false;
    1090              : 
    1091        86860 :   init_empty_tree_cfg_for_function (fn);
    1092              : 
    1093        86860 :   profile_status_for_fn (fn) = streamer_read_enum (ib, profile_status_d,
    1094              :                                                    PROFILE_LAST);
    1095              : 
    1096        86860 :   bb_count = streamer_read_uhwi (ib);
    1097              : 
    1098        86860 :   last_basic_block_for_fn (fn) = bb_count;
    1099        86860 :   if (bb_count > basic_block_info_for_fn (fn)->length ())
    1100         2258 :     vec_safe_grow_cleared (basic_block_info_for_fn (fn), bb_count, true);
    1101              : 
    1102        86860 :   if (bb_count > label_to_block_map_for_fn (fn)->length ())
    1103         2258 :     vec_safe_grow_cleared (label_to_block_map_for_fn (fn), bb_count, true);
    1104              : 
    1105        86860 :   index = streamer_read_hwi (ib);
    1106       854145 :   while (index != -1)
    1107              :     {
    1108       767285 :       basic_block bb = BASIC_BLOCK_FOR_FN (fn, index);
    1109       767285 :       unsigned int edge_count;
    1110              : 
    1111       767285 :       if (bb == NULL)
    1112       553770 :         bb = make_new_block (fn, index);
    1113              : 
    1114       767285 :       edge_count = streamer_read_uhwi (ib);
    1115       767285 :       vec_safe_reserve (bb->preds, edge_count);
    1116              : 
    1117              :       /* Connect up the CFG.  */
    1118      2413706 :       for (i = 0; i < edge_count; i++)
    1119              :         {
    1120       879136 :           bitpack_d bp = streamer_read_bitpack (ib);
    1121       879136 :           unsigned int src_index = bp_unpack_var_len_unsigned (&bp);
    1122       879136 :           unsigned int edge_flags = bp_unpack_var_len_unsigned (&bp);
    1123       879136 :           basic_block src = BASIC_BLOCK_FOR_FN (fn, src_index);
    1124              : 
    1125       879136 :           if (src == NULL)
    1126        39795 :             src = make_new_block (fn, src_index);
    1127              : 
    1128       879136 :           edge e = make_edge (src, bb, edge_flags);
    1129       879136 :           data_in->location_cache.input_location_and_block (&e->goto_locus,
    1130              :                                                             &bp, ib, data_in);
    1131       879136 :           e->probability = profile_probability::stream_in (ib);
    1132       879136 :           if (!e->probability.initialized_p ())
    1133       879136 :             full_profile = false;
    1134              :         }
    1135              : 
    1136       767285 :       index = streamer_read_hwi (ib);
    1137              :     }
    1138              : 
    1139        86860 :   p_bb = ENTRY_BLOCK_PTR_FOR_FN (fn);
    1140        86860 :   index = streamer_read_hwi (ib);
    1141       767285 :   while (index != -1)
    1142              :     {
    1143       680425 :       basic_block bb = BASIC_BLOCK_FOR_FN (fn, index);
    1144       680425 :       bb->prev_bb = p_bb;
    1145       680425 :       p_bb->next_bb = bb;
    1146       680425 :       p_bb = bb;
    1147       680425 :       index = streamer_read_hwi (ib);
    1148              :     }
    1149              : 
    1150              :   /* ???  The cfgloop interface is tied to cfun.  */
    1151        86860 :   gcc_assert (cfun == fn);
    1152              : 
    1153              :   /* Input the loop tree.  */
    1154        86860 :   unsigned n_loops = streamer_read_uhwi (ib);
    1155        86860 :   if (n_loops == 0)
    1156              :     return;
    1157              : 
    1158        86860 :   struct loops *loops = ggc_cleared_alloc<struct loops> ();
    1159        86860 :   init_loops_structure (fn, loops, n_loops);
    1160        86860 :   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       233743 :   for (unsigned i = 1; i < n_loops; ++i)
    1165              :     {
    1166        60023 :       int header_index = streamer_read_hwi (ib);
    1167        60023 :       if (header_index == -1)
    1168              :         {
    1169        21388 :           loops->larray->quick_push (NULL);
    1170        21388 :           continue;
    1171              :         }
    1172              : 
    1173        38635 :       class loop *loop = alloc_loop ();
    1174        38635 :       loop->header = BASIC_BLOCK_FOR_FN (fn, header_index);
    1175        38635 :       loop->header->loop_father = loop;
    1176              : 
    1177              :       /* Read everything copy_loop_info copies.  */
    1178        38635 :       loop->estimate_state = streamer_read_enum (ib, loop_estimation, EST_LAST);
    1179        38635 :       loop->any_upper_bound = streamer_read_hwi (ib);
    1180        38635 :       if (loop->any_upper_bound)
    1181        33549 :         loop->nb_iterations_upper_bound
    1182        33549 :           = bound_wide_int::from (streamer_read_widest_int (ib), SIGNED);
    1183        38635 :       loop->any_likely_upper_bound = streamer_read_hwi (ib);
    1184        38635 :       if (loop->any_likely_upper_bound)
    1185        33553 :         loop->nb_iterations_likely_upper_bound
    1186        33553 :           = bound_wide_int::from (streamer_read_widest_int (ib), SIGNED);
    1187        38635 :       loop->any_estimate = streamer_read_hwi (ib);
    1188        38635 :       if (loop->any_estimate)
    1189        27610 :         loop->nb_iterations_estimate
    1190        27610 :           = bound_wide_int::from (streamer_read_widest_int (ib), SIGNED);
    1191              : 
    1192              :       /* Read OMP SIMD related info.  */
    1193        38635 :       loop->safelen = streamer_read_hwi (ib);
    1194        38635 :       loop->unroll = streamer_read_hwi (ib);
    1195        38635 :       loop->owned_clique = streamer_read_hwi (ib);
    1196        38635 :       loop->dont_vectorize = streamer_read_hwi (ib);
    1197        38635 :       loop->force_vectorize = streamer_read_hwi (ib);
    1198        38635 :       loop->finite_p = streamer_read_hwi (ib);
    1199        38635 :       loop->can_be_parallel = streamer_read_hwi (ib);
    1200        38635 :       loop->simduid = stream_read_tree (ib, data_in);
    1201              : 
    1202        38635 :       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        38635 :       flow_loop_tree_node_add (loops->tree_root, loop);
    1207              :     }
    1208              : 
    1209              :   /* Rebuild the loop tree.  */
    1210        86860 :   flow_loops_find (loops);
    1211        86860 :   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        86860 : input_ssa_names (class lto_input_block *ib, class data_in *data_in,
    1220              :                  struct function *fn)
    1221              : {
    1222        86860 :   unsigned int i, size;
    1223              : 
    1224        86860 :   size = streamer_read_uhwi (ib);
    1225        86860 :   init_tree_ssa (fn, size);
    1226        86860 :   cfun->gimple_df->in_ssa_p = true;
    1227        86860 :   init_ssa_operands (fn);
    1228              : 
    1229        86860 :   i = streamer_read_uhwi (ib);
    1230       933481 :   while (i)
    1231              :     {
    1232              :       tree ssa_name, name;
    1233              :       bool is_default_def;
    1234              : 
    1235              :       /* Skip over the elements that had been freed.  */
    1236      1134481 :       while (SSANAMES (fn)->length () < i)
    1237       287860 :         SSANAMES (fn)->quick_push (NULL_TREE);
    1238              : 
    1239       846621 :       is_default_def = (streamer_read_uchar (ib) != 0);
    1240       846621 :       name = stream_read_tree (ib, data_in);
    1241       846621 :       ssa_name = make_ssa_name_fn (fn, name, NULL);
    1242              : 
    1243       846621 :       if (is_default_def)
    1244              :         {
    1245        87369 :           set_ssa_default_def (cfun, SSA_NAME_VAR (ssa_name), ssa_name);
    1246        87369 :           SSA_NAME_DEF_STMT (ssa_name) = gimple_build_nop ();
    1247              :         }
    1248              : 
    1249       846621 :       i = streamer_read_uhwi (ib);
    1250              :     }
    1251        86860 : }
    1252              : 
    1253              : 
    1254              : /* Go through all NODE edges and fixup call_stmt pointers
    1255              :    so they point to STMTS.  */
    1256              : 
    1257              : static void
    1258       113358 : 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       113358 :   struct cgraph_edge *cedge;
    1265       113358 :   struct ipa_ref *ref = NULL;
    1266       113358 :   unsigned int i;
    1267              : 
    1268       487162 :   for (cedge = node->callees; cedge; cedge = cedge->next_callee)
    1269              :     {
    1270       373804 :       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       373804 :       cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
    1274       373804 :       cedge->lto_stmt_uid = 0;
    1275       373804 :       if (!cedge->call_stmt)
    1276              :         fatal_error (input_location,
    1277              :                      "Cgraph edge statement index not found");
    1278              :     }
    1279       115079 :   for (cedge = node->indirect_calls; cedge; cedge = cedge->next_callee)
    1280              :     {
    1281         1721 :       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         1721 :       cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
    1285         1721 :       cedge->lto_stmt_uid = 0;
    1286         1721 :       if (!cedge->call_stmt)
    1287              :         fatal_error (input_location, "Cgraph edge statement index not found");
    1288              :     }
    1289       373878 :   for (i = 0; node->iterate_reference (i, ref); i++)
    1290       260520 :     if (ref->lto_stmt_uid)
    1291              :       {
    1292       255107 :         if (STMT_UID_NOT_IN_RANGE (ref->lto_stmt_uid))
    1293            0 :           fatal_error (input_location,
    1294              :                        "Reference statement index out of range");
    1295       255107 :         ref->stmt = stmts[ref->lto_stmt_uid - 1];
    1296       255107 :         ref->lto_stmt_uid = 0;
    1297       255107 :         if (!ref->stmt)
    1298            0 :           fatal_error (input_location, "Reference statement index not found");
    1299              :       }
    1300       113358 : }
    1301              : 
    1302              : 
    1303              : /* Fixup call_stmt pointers in NODE and all clones.  */
    1304              : 
    1305              : static void
    1306        86860 : fixup_call_stmt_edges (struct cgraph_node *orig, gimple **stmts)
    1307              : {
    1308        86860 :   struct cgraph_node *node;
    1309        86860 :   struct function *fn;
    1310              : 
    1311        87084 :   while (orig->clone_of)
    1312              :     orig = orig->clone_of;
    1313        86860 :   fn = DECL_STRUCT_FUNCTION (orig->decl);
    1314              : 
    1315        86860 :   if (!orig->thunk)
    1316        86860 :     fixup_call_stmt_edges_1 (orig, stmts, fn);
    1317        86860 :   if (orig->clones)
    1318        31588 :     for (node = orig->clones; node != orig;)
    1319              :       {
    1320        26500 :         if (!node->thunk)
    1321        26498 :           fixup_call_stmt_edges_1 (node, stmts, fn);
    1322        26500 :         if (node->clones)
    1323              :           node = node->clones;
    1324        23968 :         else if (node->next_sibling_clone)
    1325              :           node = node->next_sibling_clone;
    1326              :         else
    1327              :           {
    1328        13365 :             while (node != orig && !node->next_sibling_clone)
    1329         7620 :               node = node->clone_of;
    1330         5745 :             if (node != orig)
    1331          657 :               node = node->next_sibling_clone;
    1332              :           }
    1333              :       }
    1334        86860 : }
    1335              : 
    1336              : 
    1337              : /* Input the base body of struct function FN from DATA_IN
    1338              :    using input block IB.  */
    1339              : 
    1340              : static void
    1341        86860 : input_struct_function_base (struct function *fn, class data_in *data_in,
    1342              :                             class lto_input_block *ib)
    1343              : {
    1344        86860 :   struct bitpack_d bp;
    1345        86860 :   int len;
    1346              : 
    1347              :   /* Read the static chain and non-local goto save area.  */
    1348        86860 :   fn->static_chain_decl = stream_read_tree (ib, data_in);
    1349        86860 :   fn->nonlocal_goto_save_area = stream_read_tree (ib, data_in);
    1350              : 
    1351              :   /* Read all the local symbols.  */
    1352        86860 :   len = streamer_read_hwi (ib);
    1353        86860 :   if (len > 0)
    1354              :     {
    1355        23948 :       int i;
    1356        23948 :       vec_safe_grow_cleared (fn->local_decls, len, true);
    1357       190523 :       for (i = 0; i < len; i++)
    1358              :         {
    1359       142627 :           tree t = stream_read_tree (ib, data_in);
    1360       142627 :           (*fn->local_decls)[i] = t;
    1361              :         }
    1362              :     }
    1363              : 
    1364              :   /* Input the current IL state of the function.  */
    1365        86860 :   fn->curr_properties = streamer_read_uhwi (ib);
    1366              : 
    1367              :   /* Read all the attributes for FN.  */
    1368        86860 :   bp = streamer_read_bitpack (ib);
    1369        86860 :   fn->is_thunk = bp_unpack_value (&bp, 1);
    1370        86860 :   fn->has_local_explicit_reg_vars = bp_unpack_value (&bp, 1);
    1371        86860 :   fn->returns_pcc_struct = bp_unpack_value (&bp, 1);
    1372        86860 :   fn->returns_struct = bp_unpack_value (&bp, 1);
    1373        86860 :   fn->can_throw_non_call_exceptions = bp_unpack_value (&bp, 1);
    1374        86860 :   fn->can_delete_dead_exceptions = bp_unpack_value (&bp, 1);
    1375        86860 :   fn->always_inline_functions_inlined = bp_unpack_value (&bp, 1);
    1376        86860 :   fn->after_inlining = bp_unpack_value (&bp, 1);
    1377        86860 :   fn->stdarg = bp_unpack_value (&bp, 1);
    1378        86860 :   fn->has_nonlocal_label = bp_unpack_value (&bp, 1);
    1379        86860 :   fn->has_forced_label_in_static = bp_unpack_value (&bp, 1);
    1380        86860 :   fn->calls_alloca = bp_unpack_value (&bp, 1);
    1381        86860 :   fn->calls_setjmp = bp_unpack_value (&bp, 1);
    1382        86860 :   fn->calls_eh_return = bp_unpack_value (&bp, 1);
    1383        86860 :   fn->has_force_vectorize_loops = bp_unpack_value (&bp, 1);
    1384        86860 :   fn->has_simduid_loops = bp_unpack_value (&bp, 1);
    1385        86860 :   fn->has_musttail = bp_unpack_value (&bp, 1);
    1386        86860 :   fn->has_unroll = bp_unpack_value (&bp, 1);
    1387        86860 :   fn->assume_function = bp_unpack_value (&bp, 1);
    1388        86860 :   fn->va_list_fpr_size = bp_unpack_value (&bp, 8);
    1389        86860 :   fn->va_list_gpr_size = bp_unpack_value (&bp, 8);
    1390        86860 :   fn->last_clique = bp_unpack_value (&bp, sizeof (short) * 8);
    1391              : 
    1392              :   /* Input the function start and end loci.  */
    1393        86860 :   stream_input_location (&fn->function_start_locus, &bp, data_in);
    1394        86860 :   stream_input_location (&fn->function_end_locus, &bp, data_in);
    1395              : 
    1396              :   /* Restore the instance discriminators if present.  */
    1397        86860 :   int instance_number = bp_unpack_value (&bp, 1);
    1398        86860 :   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        86860 : }
    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        86935 : streamer_read_chain (class lto_input_block *ib, class data_in *data_in)
    1410              : {
    1411        86935 :   tree first, prev, curr;
    1412              : 
    1413              :   /* The chain is written as NULL terminated list of trees.  */
    1414        86935 :   first = prev = NULL_TREE;
    1415       178770 :   do
    1416              :     {
    1417       178770 :       curr = stream_read_tree (ib, data_in);
    1418       178770 :       if (prev)
    1419        91835 :         TREE_CHAIN (prev) = curr;
    1420              :       else
    1421              :         first = curr;
    1422              : 
    1423       178770 :       prev = curr;
    1424              :     }
    1425       178770 :   while (curr);
    1426              : 
    1427        86935 :   return first;
    1428              : }
    1429              : 
    1430              : /* Read the body of function FN_DECL from DATA_IN using input block IB.  */
    1431              : 
    1432              : static void
    1433        86935 : 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        86935 :   struct function *fn;
    1438        86935 :   enum LTO_tags tag;
    1439        86935 :   gimple **stmts;
    1440        86935 :   basic_block bb;
    1441              : 
    1442        86935 :   tag = streamer_read_record_start (ib);
    1443        86935 :   lto_tag_check (tag, LTO_function);
    1444              : 
    1445              :   /* Read decls for parameters and args.  */
    1446        86935 :   DECL_RESULT (fn_decl) = stream_read_tree (ib, data_in);
    1447        86935 :   DECL_ARGUMENTS (fn_decl) = streamer_read_chain (ib, data_in);
    1448              : 
    1449              :   /* Read debug args if available.  */
    1450        86935 :   unsigned n_debugargs = streamer_read_uhwi (ib);
    1451        86935 :   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        86935 :   DECL_INITIAL (fn_decl) = stream_read_tree (ib, data_in);
    1461        86935 :   unsigned block_leaf_count = streamer_read_uhwi (ib);
    1462       150284 :   while (block_leaf_count--)
    1463        63349 :     stream_read_tree (ib, data_in);
    1464              : 
    1465        86935 :   if (!streamer_read_uhwi (ib))
    1466              :     return;
    1467              : 
    1468        86860 :   push_struct_function (fn_decl);
    1469        86860 :   fn = DECL_STRUCT_FUNCTION (fn_decl);
    1470              : 
    1471        86860 :   gimple_register_cfg_hooks ();
    1472              : 
    1473        86860 :   input_struct_function_base (fn, data_in, ib);
    1474        86860 :   input_cfg (ib_cfg, data_in, fn);
    1475              : 
    1476              :   /* Read all the SSA names.  */
    1477        86860 :   input_ssa_names (ib, data_in, fn);
    1478              : 
    1479              :   /* Read the exception handling regions in the function.  */
    1480        86860 :   input_eh_regions (ib, data_in, fn);
    1481              : 
    1482        86860 :   gcc_assert (DECL_INITIAL (fn_decl));
    1483        86860 :   DECL_SAVED_TREE (fn_decl) = NULL_TREE;
    1484              : 
    1485              :   /* Read all the basic blocks.  */
    1486        86860 :   tag = streamer_read_record_start (ib);
    1487       854145 :   while (tag)
    1488              :     {
    1489       767285 :       input_bb (ib, tag, data_in, fn,
    1490              :                 node->count_materialization_scale);
    1491       767285 :       tag = streamer_read_record_start (ib);
    1492              :     }
    1493              : 
    1494              :   /* Finalize gimple_location/gimple_block of stmts and phis.  */
    1495        86860 :   data_in->location_cache.apply_location_cache ();
    1496              : 
    1497              :   /* Fix up the call statements that are mentioned in the callgraph
    1498              :      edges.  */
    1499        86860 :   set_gimple_stmt_max_uid (cfun, 0);
    1500       854145 :   FOR_ALL_BB_FN (bb, cfun)
    1501              :     {
    1502       767285 :       gimple_stmt_iterator gsi;
    1503       839390 :       for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    1504              :         {
    1505        72105 :           gimple *stmt = gsi_stmt (gsi);
    1506        72105 :           gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
    1507              :         }
    1508      2987114 :       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    1509              :         {
    1510      1452544 :           gimple *stmt = gsi_stmt (gsi);
    1511      1452544 :           gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
    1512              :         }
    1513              :     }
    1514        86860 :   stmts = (gimple **) xcalloc (gimple_stmt_max_uid (fn), sizeof (gimple *));
    1515       854145 :   FOR_ALL_BB_FN (bb, cfun)
    1516              :     {
    1517       767285 :       gimple_stmt_iterator bsi = gsi_start_phis (bb);
    1518       839390 :       while (!gsi_end_p (bsi))
    1519              :         {
    1520        72105 :           gimple *stmt = gsi_stmt (bsi);
    1521        72105 :           gsi_next (&bsi);
    1522        72105 :           stmts[gimple_uid (stmt)] = stmt;
    1523              :         }
    1524       767285 :       bsi = gsi_start_bb (bb);
    1525      2219829 :       while (!gsi_end_p (bsi))
    1526              :         {
    1527      1452544 :           gimple *stmt = gsi_stmt (bsi);
    1528      1452544 :           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      1452544 :           if (!flag_wpa)
    1536              :             {
    1537      1359824 :               if (is_gimple_debug (stmt)
    1538      1359824 :                   && (gimple_debug_nonbind_marker_p (stmt)
    1539         8241 :                       ? !MAY_HAVE_DEBUG_MARKER_STMTS
    1540         6053 :                       : !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      1359824 :               tree block;
    1546      1359824 :               if (gimple_debug_inline_entry_p (stmt)
    1547        14294 :                   && (((block = gimple_block (stmt))
    1548          999 :                        && !inlined_function_outer_scope_p (block))
    1549          999 :                       || !debug_inline_points))
    1550              :                 remove = true;
    1551      1359824 :               if (is_gimple_call (stmt)
    1552      1359824 :                   && gimple_call_internal_p (stmt))
    1553              :                 {
    1554        21637 :                   bool replace = false;
    1555        21637 :                   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      1359824 :           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      1452540 :               gsi_next (&bsi);
    1608      1452540 :               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      1452540 :               if (!cfun->debug_nonbind_markers
    1614      2881518 :                   && gimple_debug_nonbind_marker_p (stmt))
    1615         1399 :                 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        86860 :   {
    1625        86860 :     edge_iterator ei = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs);
    1626       173720 :     gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));
    1627              :   }
    1628              : 
    1629        86860 :   update_max_bb_count ();
    1630        86860 :   fixup_call_stmt_edges (node, stmts);
    1631        86860 :   execute_all_ipa_stmt_fixups (node, stmts);
    1632              : 
    1633        86860 :   free_dominance_info (CDI_DOMINATORS);
    1634        86860 :   free_dominance_info (CDI_POST_DOMINATORS);
    1635        86860 :   free (stmts);
    1636        86860 :   pop_cfun ();
    1637              : }
    1638              : 
    1639              : /* Read the body of function FN_DECL from DATA_IN using input block IB.  */
    1640              : 
    1641              : static void
    1642         7964 : input_constructor (tree var, class data_in *data_in,
    1643              :                    class lto_input_block *ib)
    1644              : {
    1645         7964 :   DECL_INITIAL (var) = stream_read_tree (ib, data_in);
    1646         7964 : }
    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        94899 : 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        94899 :   const struct lto_function_header *header;
    1660        94899 :   class data_in *data_in;
    1661        94899 :   int cfg_offset;
    1662        94899 :   int main_offset;
    1663        94899 :   int string_offset;
    1664        94899 :   tree fn_decl = node->decl;
    1665              : 
    1666        94899 :   header = (const struct lto_function_header *) data;
    1667        94899 :   if (TREE_CODE (node->decl) == FUNCTION_DECL)
    1668              :     {
    1669        86935 :       cfg_offset = sizeof (struct lto_function_header);
    1670        86935 :       main_offset = cfg_offset + header->cfg_size;
    1671        86935 :       string_offset = main_offset + header->main_size;
    1672              :     }
    1673              :   else
    1674              :     {
    1675         7964 :       main_offset = sizeof (struct lto_function_header);
    1676         7964 :       string_offset = main_offset + header->main_size;
    1677              :     }
    1678              : 
    1679        94899 :   data_in = lto_data_in_create (file_data, data + string_offset,
    1680        94899 :                               header->string_size, vNULL);
    1681              : 
    1682        94899 :   if (section_type == LTO_section_function_body)
    1683              :     {
    1684        94899 :       struct lto_in_decl_state *decl_state;
    1685        94899 :       unsigned from;
    1686              : 
    1687        94899 :       gcc_checking_assert (node);
    1688              : 
    1689              :       /* Use the function's decl state. */
    1690        94899 :       decl_state = lto_get_function_in_decl_state (file_data, fn_decl);
    1691        94899 :       gcc_assert (decl_state);
    1692        94899 :       file_data->current_decl_state = decl_state;
    1693        94899 :       data_in->location_cache.set_linemap_offset (decl_state->linemap_id);
    1694              : 
    1695              :       /* Set up the struct function.  */
    1696        94899 :       from = data_in->reader_cache->nodes.length ();
    1697        94899 :       lto_input_block ib_main (data + main_offset, header->main_size,
    1698        94899 :                                file_data);
    1699        94899 :       if (TREE_CODE (node->decl) == FUNCTION_DECL)
    1700              :         {
    1701        86935 :           lto_input_block ib_cfg (data + cfg_offset, header->cfg_size,
    1702        86935 :                                   file_data);
    1703        86935 :           input_function (fn_decl, data_in, &ib_main, &ib_cfg,
    1704              :                           dyn_cast <cgraph_node *>(node));
    1705              :         }
    1706              :       else
    1707         7964 :         input_constructor (fn_decl, data_in, &ib_main);
    1708        94899 :       data_in->location_cache.apply_location_cache ();
    1709              :       /* And fixup types we streamed locally.  */
    1710        94899 :         {
    1711        94899 :           struct streamer_tree_cache_d *cache = data_in->reader_cache;
    1712        94899 :           unsigned len = cache->nodes.length ();
    1713        94899 :           unsigned i;
    1714      3025219 :           for (i = len; i-- > from;)
    1715              :             {
    1716      2930320 :               tree t = streamer_tree_cache_get_tree (cache, i);
    1717      2930320 :               if (t == NULL_TREE)
    1718            0 :                 continue;
    1719              : 
    1720      2930320 :               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        94899 :       file_data->current_decl_state = file_data->global_decl_state;
    1739              :     }
    1740              : 
    1741        94899 :   lto_data_in_delete (data_in);
    1742        94899 : }
    1743              : 
    1744              : 
    1745              : /* Read the body of NODE using DATA.  FILE_DATA holds the global
    1746              :    decls and types.  */
    1747              : 
    1748              : void
    1749        86935 : lto_input_function_body (struct lto_file_decl_data *file_data,
    1750              :                          struct cgraph_node *node, const char *data)
    1751              : {
    1752        86935 :   lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body);
    1753        86935 : }
    1754              : 
    1755              : /* Read the body of NODE using DATA.  FILE_DATA holds the global
    1756              :    decls and types.  */
    1757              : 
    1758              : void
    1759         7964 : lto_input_variable_constructor (struct lto_file_decl_data *file_data,
    1760              :                                 struct varpool_node *node, const char *data)
    1761              : {
    1762         7964 :   lto_read_body_or_constructor (file_data, node, data, LTO_section_function_body);
    1763         7964 : }
    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              : /* Save REF for reader-cache slot INDEX before its tree can be replaced.  */
    1771              : 
    1772              : void
    1773        21834 : data_in::save_die_ref (unsigned index, lto_die_ref ref)
    1774              : {
    1775        21834 :   if (!die_refs)
    1776         1849 :     die_refs = new lto_die_ref_map;
    1777        21834 :   ref.sym = IDENTIFIER_POINTER (get_identifier (ref.sym));
    1778        21834 :   die_refs->put (index, ref);
    1779        21834 : }
    1780              : 
    1781              : /* Resolve and register origins for retained trees.  SCC unification does
    1782              :    not change the saved slot-to-DIE mappings.  */
    1783              : 
    1784              : void
    1785     11096571 : data_in::register_origin_refs ()
    1786              : {
    1787     11668991 :   for (const auto &entry : pending_origin_refs)
    1788              :     {
    1789        12456 :       const lto_die_ref *ref = &entry.ref;
    1790        12456 :       if (entry.origin > 0 && die_refs)
    1791         1568 :         ref = die_refs->get (entry.origin - 1);
    1792        10888 :       else if (entry.origin < 0)
    1793              :         {
    1794              :           /* Decode the decl-state slot as in stream_read_tree_ref.  */
    1795         3691 :           unsigned ix = -entry.origin - 1;
    1796         3691 :           gcc_checking_assert (!(ix & 1));
    1797         3691 :           ref = lto_decl_origin_ref_at
    1798         3691 :             (file_data->current_decl_state, ix / 2);
    1799              :         }
    1800        12456 :       if (ref && ref->sym)
    1801              :         {
    1802         5533 :           tree owner = streamer_tree_cache_get_tree (reader_cache, entry.index);
    1803         5533 :           debug_hooks->register_external_die
    1804         5533 :             (owner, DEBUG_ABSTRACT_ORIGIN_REF, ref->sym, ref->off);
    1805              :         }
    1806              :     }
    1807     11096571 :   pending_origin_refs.truncate (0);
    1808     11096571 : }
    1809              : 
    1810              : /* Read the physical representation of a tree node EXPR from
    1811              :    input block IB using the per-file context in DATA_IN.  */
    1812              : 
    1813              : static void
    1814      4571721 : lto_read_tree_1 (class lto_input_block *ib, class data_in *data_in, tree expr,
    1815              :                  unsigned index)
    1816              : {
    1817              :   /* Read all the bitfield values in EXPR.  Note that for LTO, we
    1818              :      only write language-independent bitfields, so no more unpacking is
    1819              :      needed.  */
    1820      4571721 :   streamer_read_tree_bitfields (ib, data_in, expr);
    1821              : 
    1822              :   /* Read all the pointer fields in EXPR.  */
    1823      4571721 :   int origin = 0;
    1824      4571721 :   streamer_read_tree_body (ib, data_in, expr, &origin);
    1825              : 
    1826              :   /* Read any LTO-specific data not read by the tree streamer.  Do not use
    1827              :      stream_read_tree here since that flushes the dref_queue in mids of
    1828              :      SCC reading.  */
    1829      4571721 :   if (DECL_P (expr)
    1830       770532 :       && TREE_CODE (expr) != FUNCTION_DECL
    1831       557552 :       && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
    1832      1066290 :     DECL_INITIAL (expr)
    1833      1066290 :       = lto_input_tree_1 (ib, data_in, streamer_read_record_start (ib), 0);
    1834              : 
    1835              :   /* Stream references to early generated DIEs.  Keep in sync with the
    1836              :      trees handled in dwarf2out_register_external_die.  */
    1837      4571721 :   if ((DECL_P (expr)
    1838              :        && TREE_CODE (expr) != FIELD_DECL
    1839              :        && TREE_CODE (expr) != DEBUG_EXPR_DECL
    1840              :        && TREE_CODE (expr) != TYPE_DECL)
    1841      3900591 :       || TREE_CODE (expr) == BLOCK)
    1842              :     {
    1843       960467 :       const char *str = streamer_read_string (data_in, ib);
    1844       960467 :       if (str)
    1845              :         {
    1846        44940 :           unsigned HOST_WIDE_INT off = streamer_read_uhwi (ib);
    1847        44940 :           dref_entry e = { expr, str, off };
    1848        44940 :           dref_queue.safe_push (e);
    1849        44940 :           if (debug_info_level > DINFO_LEVEL_NONE
    1850        89880 :               && lto_origin_ref_node_p (expr))
    1851        21834 :             data_in->save_die_ref (index, { str, off });
    1852              :         }
    1853              :       /* When there's no early DIE to refer to but dwarf2out set up
    1854              :          things in a way to expect that fixup.  This tends to happen
    1855              :          with -g1, see for example PR113488.  */
    1856       915527 :       else if (DECL_P (expr) && DECL_ABSTRACT_ORIGIN (expr) == expr)
    1857            0 :         DECL_ABSTRACT_ORIGIN (expr) = NULL_TREE;
    1858              :     }
    1859              : 
    1860      4571721 :   if (lto_origin_ref_node_p (expr))
    1861              :     {
    1862       502317 :       lto_die_ref ref = {};
    1863              : 
    1864       502317 :       unsigned kind = streamer_read_uhwi (ib);
    1865       502317 :       if (kind != LTO_ORIGIN_REF_TREE)
    1866        86546 :         origin = 0;
    1867        86546 :       if (kind == LTO_ORIGIN_REF_DIE)
    1868              :         {
    1869          811 :           const char *sym = streamer_read_string (data_in, ib);
    1870          811 :           ref = { IDENTIFIER_POINTER (get_identifier (sym)),
    1871          811 :                   streamer_read_uhwi (ib) };
    1872              :         }
    1873       502317 :       if (debug_info_level > DINFO_LEVEL_NONE
    1874        52139 :           && (ref.sym || (origin && origin != (int) index + 1)))
    1875        12458 :         data_in->pending_origin_refs.safe_push ({ index, origin, ref });
    1876              :     }
    1877              : 
    1878              : #ifdef ACCEL_COMPILER
    1879              :   if ((VAR_P (expr)
    1880              :        || TREE_CODE (expr) == PARM_DECL
    1881              :        || TREE_CODE (expr) == FIELD_DECL)
    1882              :       && DECL_MODE (expr) == VOIDmode)
    1883              :     {
    1884              :       tree type = TREE_TYPE (expr);
    1885              :       if (AGGREGATE_TYPE_P (type))
    1886              :         SET_DECL_MODE (expr, TYPE_MODE (type));
    1887              :       else if (VECTOR_TYPE_P (type))
    1888              :         SET_DECL_MODE (expr, TYPE_MODE_RAW (type));
    1889              :     }
    1890              : 
    1891              :   if (VECTOR_TYPE_P (expr) && TYPE_MODE (expr) == VOIDmode)
    1892              :     {
    1893              :       poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (expr);
    1894              :       tree innertype = TREE_TYPE (expr);
    1895              :       machine_mode vmode
    1896              :         = mode_for_vector (SCALAR_TYPE_MODE (innertype), nunits).else_blk ();
    1897              :       SET_TYPE_MODE (expr, vmode);
    1898              :     }
    1899              : #endif
    1900      4571721 : }
    1901              : 
    1902              : /* Read the physical representation of a tree node with tag TAG from
    1903              :    input block IB using the per-file context in DATA_IN.  */
    1904              : 
    1905              : static tree
    1906      4378154 : lto_read_tree (class lto_input_block *ib, class data_in *data_in,
    1907              :                enum LTO_tags tag, hashval_t hash)
    1908              : {
    1909              :   /* Instantiate a new tree node.  */
    1910      4378154 :   tree result = streamer_alloc_tree (ib, data_in, tag);
    1911              : 
    1912              :   /* Enter RESULT in the reader cache.  This will make RESULT
    1913              :      available so that circular references in the rest of the tree
    1914              :      structure can be resolved in subsequent calls to stream_read_tree.  */
    1915      4378154 :   streamer_tree_cache_append (data_in->reader_cache, result, hash);
    1916              : 
    1917      8756308 :   lto_read_tree_1 (ib, data_in, result,
    1918      8756308 :                    data_in->reader_cache->nodes.length () - 1);
    1919              : 
    1920      4378154 :   return result;
    1921              : }
    1922              : 
    1923              : 
    1924              : /* Populate the reader cache with trees materialized from the SCC
    1925              :    following in the IB, DATA_IN stream.
    1926              :    If SHARED_SCC is true we input LTO_tree_scc.  */
    1927              : 
    1928              : hashval_t
    1929      2200919 : lto_input_scc (class lto_input_block *ib, class data_in *data_in,
    1930              :                unsigned *len, unsigned *entry_len, bool shared_scc)
    1931              : {
    1932      2200919 :   unsigned size = streamer_read_uhwi (ib);
    1933      2200919 :   hashval_t scc_hash = 0;
    1934      2200919 :   unsigned scc_entry_len = 1;
    1935              : 
    1936      2200919 :   if (shared_scc)
    1937              :     {
    1938       783710 :       if (size & 1)
    1939            0 :         scc_entry_len = streamer_read_uhwi (ib);
    1940       783710 :       size /= 2;
    1941       783710 :       scc_hash = streamer_read_uhwi (ib);
    1942              :     }
    1943              : 
    1944      2200919 :   if (size == 1)
    1945              :     {
    1946      2151874 :       enum LTO_tags tag = streamer_read_record_start (ib);
    1947      2151874 :       lto_input_tree_1 (ib, data_in, tag, scc_hash);
    1948              :     }
    1949              :   else
    1950              :     {
    1951        49045 :       unsigned int first = data_in->reader_cache->nodes.length ();
    1952        49045 :       tree result;
    1953              : 
    1954              :       /* Materialize size trees by reading their headers.  */
    1955       242612 :       for (unsigned i = 0; i < size; ++i)
    1956              :         {
    1957       193567 :           enum LTO_tags tag = streamer_read_record_start (ib);
    1958       193567 :           if (tag == LTO_null
    1959       193567 :               || tag == LTO_global_stream_ref
    1960       193567 :               || tag == LTO_tree_pickle_reference
    1961       193567 :               || tag == LTO_integer_cst
    1962              :               || tag == LTO_tree_scc
    1963       193567 :               || tag == LTO_trees)
    1964            0 :             gcc_unreachable ();
    1965              : 
    1966       193567 :           result = streamer_alloc_tree (ib, data_in, tag);
    1967       193567 :           streamer_tree_cache_append (data_in->reader_cache, result, 0);
    1968              :         }
    1969              : 
    1970              :       /* Read the tree bitpacks and references.  */
    1971       242612 :       for (unsigned i = 0; i < size; ++i)
    1972              :         {
    1973       193567 :           result = streamer_tree_cache_get_tree (data_in->reader_cache,
    1974              :                                                  first + i);
    1975       193567 :           lto_read_tree_1 (ib, data_in, result, first + i);
    1976              :         }
    1977              :     }
    1978              : 
    1979      2200919 :   *len = size;
    1980      2200919 :   *entry_len = scc_entry_len;
    1981      2200919 :   return scc_hash;
    1982              : }
    1983              : 
    1984              : /* Read reference to tree from IB and DATA_IN.
    1985              :    This is used for streaming tree bodies where we know that
    1986              :    the tree is already in cache or is indexable and
    1987              :    must be matched with stream_write_tree_ref.  If REF is nonnull,
    1988              :    also return the encoded reference before resolving it to a tree.  */
    1989              : 
    1990              : tree
    1991     20562839 : stream_read_tree_ref (lto_input_block *ib, data_in *data_in, int *ref)
    1992              : {
    1993     20562839 :   int ix = streamer_read_hwi (ib);
    1994     20562839 :   if (ref)
    1995      1059869 :     *ref = ix;
    1996     20562839 :   if (!ix)
    1997              :     return NULL_TREE;
    1998     12642872 :   if (ix > 0)
    1999      9613520 :     return streamer_tree_cache_get_tree (data_in->reader_cache, ix - 1);
    2000              : 
    2001      3029352 :   ix = -ix - 1;
    2002      3029352 :   int id = ix & 1;
    2003      3029352 :   ix /= 2;
    2004              : 
    2005      3029352 :   tree ret;
    2006      3029352 :   if (!id)
    2007      2864583 :     ret = (*data_in->file_data->current_decl_state
    2008      2864583 :            ->streams[LTO_DECL_STREAM])[ix];
    2009              :   else
    2010       164769 :     ret = (*SSANAMES (cfun))[ix];
    2011              :   return ret;
    2012              : }
    2013              : 
    2014              : /* Read a tree from input block IB using the per-file context in
    2015              :    DATA_IN.  This context is used, for example, to resolve references
    2016              :    to previously read nodes.  */
    2017              : 
    2018              : tree
    2019     13131926 : lto_input_tree_1 (class lto_input_block *ib, class data_in *data_in,
    2020              :                   enum LTO_tags tag, hashval_t hash)
    2021              : {
    2022     13131926 :   tree result;
    2023              : 
    2024     13131926 :   gcc_assert ((unsigned) tag < (unsigned) LTO_NUM_TAGS);
    2025              : 
    2026     13131926 :   if (tag == LTO_null)
    2027              :     result = NULL_TREE;
    2028              :   else if (tag == LTO_global_stream_ref || tag == LTO_ssa_name_ref)
    2029              :     {
    2030              :       /* If TAG is a reference to an indexable tree, the next value
    2031              :          in IB is the index into the table where we expect to find
    2032              :          that tree.  */
    2033      4164210 :       result = lto_input_tree_ref (ib, data_in, cfun, tag);
    2034              :     }
    2035              :   else if (tag == LTO_tree_pickle_reference)
    2036              :     {
    2037              :       /* If TAG is a reference to a previously read tree, look it up in
    2038              :          the reader cache.  */
    2039      1624427 :       result = streamer_get_pickled_tree (ib, data_in);
    2040              :     }
    2041              :   else if (tag == LTO_integer_cst)
    2042              :     {
    2043              :       /* For shared integer constants in singletons we can use the
    2044              :          existing tree integer constant merging code.  */
    2045       727723 :       tree type = stream_read_tree_ref (ib, data_in);
    2046       727723 :       unsigned HOST_WIDE_INT len = streamer_read_uhwi (ib);
    2047       727723 :       unsigned HOST_WIDE_INT i;
    2048       727723 :       HOST_WIDE_INT abuf[WIDE_INT_MAX_INL_ELTS], *a = abuf;
    2049              : 
    2050       727723 :       if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS))
    2051            8 :         a = XALLOCAVEC (HOST_WIDE_INT, len);
    2052      1461172 :       for (i = 0; i < len; i++)
    2053       733449 :         a[i] = streamer_read_hwi (ib);
    2054       727723 :       gcc_assert (TYPE_PRECISION (type) <= WIDE_INT_MAX_PRECISION);
    2055       727723 :       result
    2056       727723 :         = wide_int_to_tree (type,
    2057       727723 :                             wide_int::from_array (a, len,
    2058       727723 :                                                   TYPE_PRECISION (type)));
    2059       727723 :       streamer_tree_cache_append (data_in->reader_cache, result, hash);
    2060              :     }
    2061              :   else if (tag == LTO_tree_scc || tag == LTO_trees)
    2062            0 :     gcc_unreachable ();
    2063              :   else
    2064              :     {
    2065              :       /* Otherwise, materialize a new node from IB.  */
    2066      4378154 :       result = lto_read_tree (ib, data_in, tag, hash);
    2067              :     }
    2068              : 
    2069     13131926 :   return result;
    2070              : }
    2071              : 
    2072              : tree
    2073      9152662 : lto_input_tree (class lto_input_block *ib, class data_in *data_in)
    2074              : {
    2075      9152662 :   enum LTO_tags tag;
    2076              : 
    2077              :   /* Input pickled trees needed to stream in the reference.  */
    2078     10553984 :   while ((tag = streamer_read_record_start (ib)) == LTO_trees)
    2079              :     {
    2080      1401322 :       unsigned len, entry_len;
    2081      1401322 :       lto_input_scc (ib, data_in, &len, &entry_len, false);
    2082              : 
    2083              :       /* Register DECLs with the debuginfo machinery.  */
    2084      2924790 :       while (!dref_queue.is_empty ())
    2085              :         {
    2086        10985 :           dref_entry e = dref_queue.pop ();
    2087        10985 :           debug_hooks->register_external_die (e.decl, DEBUG_DIE_REF,
    2088              :                                               e.sym, e.off);
    2089              :         }
    2090              :     }
    2091      9152662 :   tree t = lto_input_tree_1 (ib, data_in, tag, 0);
    2092              : 
    2093      9152662 :   if (!dref_queue.is_empty ())
    2094              :     {
    2095         9460 :       dref_entry e = dref_queue.pop ();
    2096         9460 :       debug_hooks->register_external_die (e.decl, DEBUG_DIE_REF,
    2097              :                                           e.sym, e.off);
    2098         9460 :       gcc_checking_assert (dref_queue.is_empty ());
    2099              :     }
    2100      9152662 :   data_in->register_origin_refs ();
    2101      9152662 :   return t;
    2102              : }
    2103              : 
    2104              : 
    2105              : /* Input toplevel asms.  */
    2106              : 
    2107              : void
    2108        23730 : lto_input_toplevel_asms (struct lto_file_decl_data *file_data, int order_base)
    2109              : {
    2110        23730 :   size_t len;
    2111        23730 :   const char *data
    2112        23730 :     = lto_get_summary_section_data (file_data, LTO_section_asm, &len);
    2113        23730 :   const struct lto_simple_header_with_strings *header
    2114              :     = (const struct lto_simple_header_with_strings *) data;
    2115        23730 :   int string_offset;
    2116        23730 :   class data_in *data_in;
    2117              : 
    2118        23730 :   if (! data)
    2119        23619 :     return;
    2120              : 
    2121          111 :   string_offset = sizeof (*header) + header->main_size;
    2122              : 
    2123          111 :   lto_input_block ib (data + sizeof (*header), header->main_size,
    2124          111 :                       file_data);
    2125              : 
    2126          111 :   data_in = lto_data_in_create (file_data, data + string_offset,
    2127          111 :                               header->string_size, vNULL);
    2128              : 
    2129          111 :   unsigned asm_count = streamer_read_uhwi (&ib);
    2130          263 :   for (unsigned i = 0; i < asm_count; i++)
    2131              :     {
    2132          152 :       tree str = stream_read_tree (&ib, data_in);
    2133          152 :       asm_node *node = symtab->finalize_toplevel_asm (str);
    2134          152 :       node->order = streamer_read_hwi (&ib) + order_base;
    2135          152 :       node->lto_file_data = file_data;
    2136          152 :       if (node->order >= symtab->order)
    2137            0 :         symtab->order = node->order + 1;
    2138              :     }
    2139              : 
    2140          111 :   lto_data_in_delete (data_in);
    2141              : 
    2142          111 :   lto_free_section_data (file_data, LTO_section_asm, NULL, data, len);
    2143              : }
    2144              : 
    2145              : 
    2146              : /* Input mode table.  */
    2147              : 
    2148              : void
    2149            0 : lto_input_mode_table (struct lto_file_decl_data *file_data)
    2150              : {
    2151            0 :   size_t len;
    2152            0 :   const char *data
    2153            0 :     = lto_get_summary_section_data (file_data, LTO_section_mode_table, &len);
    2154            0 :   if (! data)
    2155            0 :     internal_error ("cannot read LTO mode table from %s",
    2156              :                     file_data->file_name);
    2157              : 
    2158            0 :   const struct lto_simple_header_with_strings *header
    2159              :     = (const struct lto_simple_header_with_strings *) data;
    2160            0 :   int string_offset;
    2161            0 :   class data_in *data_in;
    2162            0 :   string_offset = sizeof (*header) + header->main_size;
    2163              : 
    2164            0 :   lto_input_block ib (data + sizeof (*header), header->main_size, NULL);
    2165            0 :   data_in = lto_data_in_create (file_data, data + string_offset,
    2166            0 :                                 header->string_size, vNULL);
    2167            0 :   bitpack_d bp = streamer_read_bitpack (&ib);
    2168              : 
    2169              : #ifdef ACCEL_COMPILER
    2170              :   host_num_poly_int_coeffs
    2171              :     = bp_unpack_value (&bp, MAX_NUM_POLY_INT_COEFFS_BITS);
    2172              : #endif
    2173              : 
    2174            0 :   unsigned mode_bits = bp_unpack_value (&bp, 5);
    2175            0 :   unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (1 << mode_bits);
    2176              : 
    2177            0 :   file_data->mode_table = table;
    2178            0 :   file_data->mode_bits = mode_bits;
    2179              : 
    2180            0 :   table[VOIDmode] = VOIDmode;
    2181            0 :   table[BLKmode] = BLKmode;
    2182            0 :   unsigned int m;
    2183            0 :   while ((m = bp_unpack_value (&bp, mode_bits)) != VOIDmode)
    2184              :     {
    2185            0 :       enum mode_class mclass
    2186            0 :         = bp_unpack_enum (&bp, mode_class, MAX_MODE_CLASS);
    2187            0 :       poly_uint16 size = bp_unpack_poly_value (&bp, 16);
    2188            0 :       poly_uint16 prec = bp_unpack_poly_value (&bp, 16);
    2189            0 :       machine_mode inner = (machine_mode) bp_unpack_value (&bp, mode_bits);
    2190            0 :       poly_uint16 nunits = bp_unpack_poly_value (&bp, 16);
    2191            0 :       unsigned int ibit = 0, fbit = 0;
    2192            0 :       unsigned int real_fmt_len = 0;
    2193            0 :       const char *real_fmt_name = NULL;
    2194            0 :       switch (mclass)
    2195              :         {
    2196            0 :         case MODE_FRACT:
    2197            0 :         case MODE_UFRACT:
    2198            0 :         case MODE_ACCUM:
    2199            0 :         case MODE_UACCUM:
    2200            0 :           ibit = bp_unpack_value (&bp, 8);
    2201            0 :           fbit = bp_unpack_value (&bp, 8);
    2202            0 :           break;
    2203            0 :         case MODE_FLOAT:
    2204            0 :         case MODE_DECIMAL_FLOAT:
    2205            0 :           real_fmt_name = bp_unpack_indexed_string (data_in, &bp,
    2206              :                                                     &real_fmt_len);
    2207            0 :           break;
    2208              :         default:
    2209              :           break;
    2210              :         }
    2211              :       /* First search just the GET_CLASS_NARROWEST_MODE to wider modes,
    2212              :          if not found, fallback to all modes.  When found, pass is 3 (2 + 1),
    2213              :          when not found, pass is 2 ('< 2' check + 1).  */
    2214            0 :       int pass;
    2215            0 :       for (pass = 0; pass < 2; pass++)
    2216            0 :         for (machine_mode mr = pass ? VOIDmode
    2217            0 :                                     : GET_CLASS_NARROWEST_MODE (mclass);
    2218            0 :              pass ? mr < MAX_MACHINE_MODE : mr != VOIDmode;
    2219            0 :              pass ? mr = (machine_mode) (mr + 1)
    2220            0 :                   : mr = GET_MODE_WIDER_MODE (mr).else_void ())
    2221            0 :           if (GET_MODE_CLASS (mr) != mclass
    2222            0 :               || maybe_ne (GET_MODE_SIZE (mr), size)
    2223            0 :               || maybe_ne (GET_MODE_PRECISION (mr), prec)
    2224            0 :               || (inner == m
    2225            0 :                   ? GET_MODE_INNER (mr) != mr
    2226            0 :                   : GET_MODE_INNER (mr) != table[(int) inner])
    2227            0 :               || GET_MODE_IBIT (mr) != ibit
    2228            0 :               || GET_MODE_FBIT (mr) != fbit
    2229            0 :               || maybe_ne (GET_MODE_NUNITS (mr), nunits))
    2230            0 :             continue;
    2231            0 :           else if ((mclass == MODE_FLOAT || mclass == MODE_DECIMAL_FLOAT)
    2232            0 :                    && strcmp (REAL_MODE_FORMAT (mr)->name, real_fmt_name) != 0)
    2233            0 :             continue;
    2234              :           else
    2235              :             {
    2236              :               /* Found.  */
    2237            0 :               table[m] = mr;
    2238            0 :               pass = 2;  /* Will be 3 after the outer loop.  */
    2239              : #ifdef ACCEL_COMPILER
    2240              :               /* A mode used by the host code - and generally supported by the
    2241              :                  offloading-target compiler might not actually be available,
    2242              :                  depending e.g. on -march or other other commandline options.
    2243              :                  Hence, check again and, if failing, diagnose it below.  */
    2244              :               if (scalar_mode::includes_p (mr)
    2245              :                   && !targetm.scalar_mode_supported_p (
    2246              :                         scalar_mode::from_int (mr)))
    2247              :                 pass = 1;  /* Such that pass == 2 after the outer loop. */
    2248              : #endif
    2249            0 :               break;
    2250              :             }
    2251            0 :       unsigned int mname_len;
    2252            0 :       const char *mname = bp_unpack_indexed_string (data_in, &bp, &mname_len);
    2253            0 :       if (pass == 2)
    2254              :         {
    2255            0 :           switch (mclass)
    2256              :             {
    2257            0 :             case MODE_VECTOR_BOOL:
    2258            0 :             case MODE_VECTOR_INT:
    2259            0 :             case MODE_VECTOR_FLOAT:
    2260            0 :             case MODE_VECTOR_FRACT:
    2261            0 :             case MODE_VECTOR_UFRACT:
    2262            0 :             case MODE_VECTOR_ACCUM:
    2263            0 :             case MODE_VECTOR_UACCUM:
    2264              :               /* Vector modes are recomputed on accel side and shouldn't have
    2265              :                  been streamed-out from host.  */
    2266            0 :               gcc_unreachable ();
    2267              :               /* FALLTHRU */
    2268            0 :             default:
    2269              :               /* This is only used for offloading-target compilations and
    2270              :                  is a user-facing error.  Give a better error message for
    2271              :                  the common modes; see also mode-classes.def.   */
    2272            0 :               if (mclass == MODE_FLOAT)
    2273            0 :                 fatal_error (UNKNOWN_LOCATION,
    2274              :                              "%s - %u-bit-precision floating-point numbers "
    2275              :                              "unsupported (mode %qs)", TARGET_MACHINE,
    2276            0 :                              prec.to_constant (), mname);
    2277            0 :               else if (mclass == MODE_DECIMAL_FLOAT)
    2278            0 :                 fatal_error (UNKNOWN_LOCATION,
    2279              :                              "%s - %u-bit-precision decimal floating-point "
    2280              :                              "numbers unsupported (mode %qs)", TARGET_MACHINE,
    2281            0 :                              prec.to_constant (), mname);
    2282            0 :               else if (mclass == MODE_COMPLEX_FLOAT)
    2283            0 :                 fatal_error (UNKNOWN_LOCATION,
    2284              :                              "%s - %u-bit-precision complex floating-point "
    2285              :                              "numbers unsupported (mode %qs)", TARGET_MACHINE,
    2286            0 :                              prec.to_constant (), mname);
    2287            0 :               else if (mclass == MODE_INT)
    2288            0 :                 fatal_error (UNKNOWN_LOCATION,
    2289              :                              "%s - %u-bit integer numbers unsupported (mode "
    2290            0 :                              "%qs)", TARGET_MACHINE, prec.to_constant (), mname);
    2291              :               else
    2292            0 :                 fatal_error (UNKNOWN_LOCATION, "%s - unsupported mode %qs",
    2293              :                              TARGET_MACHINE, mname);
    2294            0 :               break;
    2295              :             }
    2296              :         }
    2297              :     }
    2298            0 :   lto_data_in_delete (data_in);
    2299              : 
    2300            0 :   lto_free_section_data (file_data, LTO_section_mode_table, NULL, data, len);
    2301            0 : }
    2302              : 
    2303              : 
    2304              : /* Initialization for the LTO reader.  */
    2305              : 
    2306              : void
    2307        22609 : lto_reader_init (void)
    2308              : {
    2309        22609 :   lto_streamer_init ();
    2310        22609 :   file_name_hash_table
    2311        22609 :     = new hash_table<string_slot_hasher> (37);
    2312        45218 :   string_slot_allocator = new object_allocator <struct string_slot>
    2313        22609 :                                 ("line map file name hash");
    2314        22609 :   gcc_obstack_init (&file_name_obstack);
    2315        22609 : }
    2316              : 
    2317              : /* Free hash table used to stream in location file names.  */
    2318              : 
    2319              : void
    2320         8765 : lto_free_file_name_hash (void)
    2321              : {
    2322         8765 :   delete file_name_hash_table;
    2323         8765 :   file_name_hash_table = NULL;
    2324        17530 :   delete string_slot_allocator;
    2325         8765 :   string_slot_allocator = NULL;
    2326         8765 :   delete path_name_pair_hash_table;
    2327         8765 :   path_name_pair_hash_table = NULL;
    2328         8765 :   delete string_pair_map_allocator;
    2329         8765 :   string_pair_map_allocator = NULL;
    2330              :   /* file_name_obstack must stay allocated since it is referred to by
    2331              :      line map table.  */
    2332         8765 : }
    2333              : 
    2334              : 
    2335              : /* Create a new data_in object for FILE_DATA. STRINGS is the string
    2336              :    table to use with LEN strings.  RESOLUTIONS is the vector of linker
    2337              :    resolutions (NULL if not using a linker plugin).  */
    2338              : 
    2339              : class data_in *
    2340       237562 : lto_data_in_create (struct lto_file_decl_data *file_data, const char *strings,
    2341              :                     unsigned len,
    2342              :                     vec<ld_plugin_symbol_resolution_t> resolutions,
    2343              :                     bool need_location_cache)
    2344              : {
    2345       237562 :   const auto d = new data_in{need_location_cache ? file_data : nullptr};
    2346       237562 :   d->file_data = file_data;
    2347       237562 :   d->strings = strings;
    2348       237562 :   d->strings_len = len;
    2349       237562 :   d->globals_resolution = resolutions;
    2350       237562 :   d->reader_cache = streamer_tree_cache_create (false, false, true);
    2351       237562 :   return d;
    2352              : }
    2353              : 
    2354              : 
    2355              : /* Remove DATA_IN.  */
    2356              : 
    2357              : void
    2358       237562 : lto_data_in_delete (class data_in *data_in)
    2359              : {
    2360       237562 :   data_in->globals_resolution.release ();
    2361       237562 :   streamer_tree_cache_delete (data_in->reader_cache);
    2362       237562 :   delete data_in->die_refs;
    2363       239411 :   delete data_in;
    2364       237562 : }
        

Generated by: LCOV version 2.6-beta

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