LCOV - code coverage report
Current view: top level - gcc - ipa-prop.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 95.5 % 3320 3169
Test Date: 2026-11-14 16:39:50 Functions: 97.5 % 160 156
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Interprocedural analyses.
       2              :    Copyright (C) 2005-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify it under
       7              : the terms of the GNU General Public License as published by the Free
       8              : Software Foundation; either version 3, or (at your option) any later
       9              : version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14              : for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : #include "config.h"
      21              : #include "system.h"
      22              : #include "coretypes.h"
      23              : #include "backend.h"
      24              : #include "rtl.h"
      25              : #include "tree.h"
      26              : #include "gimple.h"
      27              : #include "alloc-pool.h"
      28              : #include "tree-pass.h"
      29              : #include "ssa.h"
      30              : #include "tree-streamer.h"
      31              : #include "cgraph.h"
      32              : #include "diagnostic.h"
      33              : #include "fold-const.h"
      34              : #include "gimple-iterator.h"
      35              : #include "gimple-fold.h"
      36              : #include "tree-eh.h"
      37              : #include "calls.h"
      38              : #include "stor-layout.h"
      39              : #include "print-tree.h"
      40              : #include "gimplify.h"
      41              : #include "gimplify-me.h"
      42              : #include "gimple-walk.h"
      43              : #include "symbol-summary.h"
      44              : #include "sreal.h"
      45              : #include "ipa-cp.h"
      46              : #include "ipa-prop.h"
      47              : #include "tree-cfg.h"
      48              : #include "tree-dfa.h"
      49              : #include "tree-inline.h"
      50              : #include "ipa-fnsummary.h"
      51              : #include "gimple-pretty-print.h"
      52              : #include "ipa-utils.h"
      53              : #include "dbgcnt.h"
      54              : #include "domwalk.h"
      55              : #include "builtins.h"
      56              : #include "tree-cfgcleanup.h"
      57              : #include "options.h"
      58              : #include "symtab-clones.h"
      59              : #include "attr-fnspec.h"
      60              : #include "gimple-range.h"
      61              : #include "value-range-storage.h"
      62              : #include "vr-values.h"
      63              : #include "lto-streamer.h"
      64              : #include "attribs.h"
      65              : #include "attr-callback.h"
      66              : #include "callback-info.h"
      67              : 
      68              : /* Function summary where the parameter infos are actually stored. */
      69              : ipa_node_params_t *ipa_node_params_sum = NULL;
      70              : 
      71              : function_summary <ipcp_transformation *> *ipcp_transformation_sum = NULL;
      72              : 
      73              : /* Edge summary for IPA-CP edge information.  */
      74              : ipa_edge_args_sum_t *ipa_edge_args_sum;
      75              : 
      76              : /* Traits for a hash table for reusing ranges.  */
      77              : 
      78              : struct ipa_vr_ggc_hash_traits : public ggc_cache_remove <ipa_vr *>
      79              : {
      80              :   typedef ipa_vr *value_type;
      81              :   typedef const vrange *compare_type;
      82              :   static hashval_t
      83     22700808 :   hash (const ipa_vr *p)
      84              :     {
      85              :       // This never get called, except in the verification code, as
      86              :       // ipa_get_value_range() calculates the hash itself.  This
      87              :       // function is mostly here for completeness' sake.
      88     22700808 :       value_range vr;
      89     22700808 :       p->get_vrange (vr);
      90     22700808 :       inchash::hash hstate;
      91     22700808 :       add_vrange (vr, hstate);
      92     22700808 :       return hstate.end ();
      93     22700808 :     }
      94              :   static bool
      95     28273914 :   equal (const ipa_vr *a, const vrange *b)
      96              :     {
      97     28273914 :       return a->equal_p (*b);
      98              :     }
      99              :   static const bool empty_zero_p = true;
     100              :   static void
     101         2050 :   mark_empty (ipa_vr *&p)
     102              :     {
     103         2050 :       p = NULL;
     104              :     }
     105              :   static bool
     106              :   is_empty (const ipa_vr *p)
     107              :     {
     108              :       return p == NULL;
     109              :     }
     110              :   static bool
     111     78180273 :   is_deleted (const ipa_vr *p)
     112              :     {
     113     78180273 :       return p == reinterpret_cast<const ipa_vr *> (1);
     114              :     }
     115              :   static void
     116       845669 :   mark_deleted (ipa_vr *&p)
     117              :     {
     118       845669 :       p = reinterpret_cast<ipa_vr *> (1);
     119              :     }
     120              : };
     121              : 
     122              : /* Hash table for avoid repeated allocations of equal ranges.  */
     123              : static GTY ((cache)) hash_table<ipa_vr_ggc_hash_traits> *ipa_vr_hash_table;
     124              : 
     125              : /* Holders of ipa cgraph hooks: */
     126              : static struct cgraph_node_hook_list *function_insertion_hook_holder;
     127              : 
     128              : /* Description of a reference to an IPA constant.  */
     129              : struct ipa_cst_ref_desc
     130              : {
     131              :   /* Edge that corresponds to the statement which took the reference.  */
     132              :   struct cgraph_edge *cs;
     133              :   /* Linked list of duplicates created when call graph edges are cloned.  */
     134              :   struct ipa_cst_ref_desc *next_duplicate;
     135              :   /* Number of references in IPA structures, IPA_UNDESCRIBED_USE if the value
     136              :      is out of control.  */
     137              :   int refcount;
     138              : };
     139              : 
     140              : /* Allocation pool for reference descriptions.  */
     141              : 
     142              : static object_allocator<ipa_cst_ref_desc> ipa_refdesc_pool
     143              :   ("IPA-PROP ref descriptions");
     144              : 
     145       662321 : ipa_vr::ipa_vr ()
     146       662321 :   : m_storage (NULL),
     147       662321 :     m_type (NULL)
     148              : {
     149       662321 : }
     150              : 
     151      1690984 : ipa_vr::ipa_vr (const vrange &r)
     152      1690984 :   : m_storage (ggc_alloc_vrange_storage (r, false /* shared_p */)),
     153      1690984 :     m_type (r.type ())
     154              : {
     155      1690984 : }
     156              : 
     157              : bool
     158     28273914 : ipa_vr::equal_p (const vrange &r) const
     159              : {
     160     28273914 :   gcc_checking_assert (!r.undefined_p ());
     161     28273914 :   return (types_compatible_p (m_type, r.type ()) && m_storage->equal_p (r));
     162              : }
     163              : 
     164              : bool
     165        63034 : ipa_vr::equal_p (const ipa_vr &o) const
     166              : {
     167        63034 :   if (!known_p ())
     168            0 :     return !o.known_p ();
     169              : 
     170        63034 :   if (!types_compatible_p (m_type, o.m_type))
     171              :     return false;
     172              : 
     173        63034 :   value_range r;
     174        63034 :   o.get_vrange (r);
     175        63034 :   return m_storage->equal_p (r);
     176        63034 : }
     177              : 
     178              : void
     179     34449801 : ipa_vr::get_vrange (value_range &r) const
     180              : {
     181     34449801 :   r.set_range_class (m_type);
     182     34449801 :   m_storage->get_vrange (r, m_type);
     183     34449801 : }
     184              : 
     185              : void
     186         1942 : ipa_vr::set_unknown ()
     187              : {
     188         1942 :   if (m_storage)
     189         1942 :     ggc_free (m_storage);
     190              : 
     191         1942 :   m_storage = NULL;
     192         1942 : }
     193              : 
     194              : void
     195       617819 : ipa_vr::streamer_read (lto_input_block *ib, data_in *data_in)
     196              : {
     197       617819 :   struct bitpack_d bp = streamer_read_bitpack (ib);
     198       617819 :   bool known = bp_unpack_value (&bp, 1);
     199       617819 :   if (known)
     200              :     {
     201       442999 :       value_range vr;
     202       442999 :       streamer_read_value_range (ib, data_in, vr);
     203       442999 :       if (!m_storage || !m_storage->fits_p (vr))
     204              :         {
     205       442999 :           if (m_storage)
     206            0 :             ggc_free (m_storage);
     207       442999 :           m_storage = ggc_alloc_vrange_storage (vr);
     208              :         }
     209       442999 :       m_storage->set_vrange (vr);
     210       442999 :       m_type = vr.type ();
     211       442999 :     }
     212              :   else
     213              :     {
     214       174820 :       m_storage = NULL;
     215       174820 :       m_type = NULL;
     216              :     }
     217       617819 : }
     218              : 
     219              : void
     220       474216 : ipa_vr::streamer_write (output_block *ob) const
     221              : {
     222       474216 :   struct bitpack_d bp = bitpack_create (ob->main_stream);
     223       474216 :   bp_pack_value (&bp, !!m_storage, 1);
     224       474216 :   streamer_write_bitpack (&bp);
     225       474216 :   if (m_storage)
     226              :     {
     227       471685 :       value_range vr (m_type);
     228       471685 :       m_storage->get_vrange (vr, m_type);
     229       471685 :       streamer_write_vrange (ob, vr);
     230       471685 :     }
     231       474216 : }
     232              : 
     233              : void
     234          761 : ipa_vr::dump (FILE *out) const
     235              : {
     236          761 :   if (known_p ())
     237              :     {
     238          761 :       value_range vr (m_type);
     239          761 :       m_storage->get_vrange (vr, m_type);
     240          761 :       vr.dump (out);
     241          761 :     }
     242              :   else
     243            0 :     fprintf (out, "NO RANGE");
     244          761 : }
     245              : 
     246              : // These stubs are because we use an ipa_vr in a hash_traits and
     247              : // hash-traits.h defines an extern of gt_ggc_mx (T &) instead of
     248              : // picking up the gt_ggc_mx (T *) version.
     249              : void
     250            0 : gt_pch_nx (ipa_vr *&x)
     251              : {
     252            0 :   return gt_pch_nx ((ipa_vr *) x);
     253              : }
     254              : 
     255              : void
     256            0 : gt_ggc_mx (ipa_vr *&x)
     257              : {
     258            0 :   return gt_ggc_mx ((ipa_vr *) x);
     259              : }
     260              : 
     261              : /* Analysis summery of function call return value.  */
     262              : struct GTY(()) ipa_return_value_summary
     263              : {
     264              :   /* Known value range.
     265              :      This needs to be wrapped in struccture due to specific way
     266              :      we allocate ipa_vr. */
     267              :   ipa_vr *vr;
     268              : };
     269              : 
     270              : /* Function summary for return values.  */
     271              : class ipa_return_value_sum_t : public function_summary <ipa_return_value_summary *>
     272              : {
     273              : public:
     274        90070 :   ipa_return_value_sum_t (symbol_table *table, bool ggc):
     275       180140 :     function_summary <ipa_return_value_summary *> (table, ggc) { }
     276              : 
     277              :   /* Hook that is called by summary when a node is duplicated.  */
     278       580112 :   void duplicate (cgraph_node *,
     279              :                   cgraph_node *,
     280              :                   ipa_return_value_summary *data,
     281              :                   ipa_return_value_summary *data2) final override
     282              :   {
     283       580112 :     *data2=*data;
     284       580112 :   }
     285              : };
     286              : 
     287              : /* Structure holding the information that all stores to FLD_OFFSET (measured in
     288              :    bytes) of a particular record type REC_TYPE was storing a pointer to
     289              :    function FN or that there were multiple functions, which is denoted by fn
     290              :    being nullptr. */
     291              : 
     292              : struct GTY((for_user)) noted_fnptr_store
     293              : {
     294              :   tree rec_type;
     295              :   tree fn;
     296              :   unsigned fld_offset;
     297              : };
     298              : 
     299              : /* Hash traits to have a hash table of noted_fnptr_stores.  */
     300              : 
     301              : struct noted_fnptr_hasher : ggc_ptr_hash <noted_fnptr_store>
     302              : {
     303              :   static hashval_t hash (noted_fnptr_store *);
     304              :   static bool equal (noted_fnptr_store *,
     305              :                      noted_fnptr_store *);
     306              : };
     307              : 
     308              : hashval_t
     309       603331 : noted_fnptr_hasher::hash (noted_fnptr_store *val)
     310              : {
     311      1206662 :   return iterative_hash_host_wide_int (val->fld_offset,
     312       603331 :                                        TYPE_UID (val->rec_type));
     313              : }
     314              : 
     315              : bool
     316       522063 : noted_fnptr_hasher::equal (noted_fnptr_store *v1,
     317              :                            noted_fnptr_store *v2)
     318              : {
     319       522063 :   return (v1->rec_type == v2->rec_type
     320       522063 :           && v1->fld_offset == v2->fld_offset);
     321              : }
     322              : 
     323              : 
     324              : /* Structure holding the information that all stores to OFFSET of a particular
     325              :    record type RECTYPE was storing a pointer to specific function or that there
     326              :    were multiple such functions. */
     327              : 
     328              : static GTY(()) hash_table <noted_fnptr_hasher> *noted_fnptrs_in_records;
     329              : 
     330              : /* Variable hoding the return value summary.  */
     331              : static GTY(()) function_summary <ipa_return_value_summary *> *ipa_return_value_sum;
     332              : 
     333              : 
     334              : /* Return true if DECL_FUNCTION_SPECIFIC_OPTIMIZATION of the decl associated
     335              :    with NODE should prevent us from analyzing it for the purposes of IPA-CP.  */
     336              : 
     337              : static bool
     338      4194467 : ipa_func_spec_opts_forbid_analysis_p (struct cgraph_node *node)
     339              : {
     340      4194467 :   tree fs_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (node->decl);
     341              : 
     342      4194467 :   if (!fs_opts)
     343              :     return false;
     344       556176 :   return !opt_for_fn (node->decl, optimize) || !opt_for_fn (node->decl, flag_ipa_cp);
     345              : }
     346              : 
     347              : /* Return index of the formal whose tree is PTREE in function which corresponds
     348              :    to INFO.  */
     349              : 
     350              : static int
     351     43800097 : ipa_get_param_decl_index_1 (vec<ipa_param_descriptor, va_gc> *descriptors,
     352              :                             tree ptree)
     353              : {
     354     43800097 :   int i, count;
     355              : 
     356     43800097 :   count = vec_safe_length (descriptors);
     357     89444095 :   for (i = 0; i < count; i++)
     358     78689259 :     if ((*descriptors)[i].decl_or_type == ptree)
     359              :       return i;
     360              : 
     361              :   return -1;
     362              : }
     363              : 
     364              : /* Return index of the formal whose tree is PTREE in function which corresponds
     365              :    to INFO.  */
     366              : 
     367              : int
     368     27314978 : ipa_get_param_decl_index (class ipa_node_params *info, tree ptree)
     369              : {
     370     27314978 :   return ipa_get_param_decl_index_1 (info->descriptors, ptree);
     371              : }
     372              : 
     373              : static void
     374              : ipa_duplicate_jump_function (cgraph_edge *src, cgraph_edge *dst,
     375              :                              ipa_jump_func *src_jf, ipa_jump_func *dst_jf);
     376              : 
     377              : /* Populate the param_decl field in parameter DESCRIPTORS that correspond to
     378              :    NODE.  */
     379              : 
     380              : static void
     381      5671099 : ipa_populate_param_decls (struct cgraph_node *node,
     382              :                           vec<ipa_param_descriptor, va_gc> &descriptors)
     383              : {
     384      5671099 :   tree fndecl;
     385      5671099 :   tree fnargs;
     386      5671099 :   tree parm;
     387      5671099 :   int param_num;
     388              : 
     389      5671099 :   fndecl = node->decl;
     390      5671099 :   gcc_assert (gimple_has_body_p (fndecl));
     391      5671099 :   fnargs = DECL_ARGUMENTS (fndecl);
     392      5671099 :   param_num = 0;
     393     18671474 :   for (parm = fnargs; parm; parm = DECL_CHAIN (parm))
     394              :     {
     395     13000375 :       descriptors[param_num].decl_or_type = parm;
     396     13000375 :       unsigned int cost = estimate_move_cost (TREE_TYPE (parm), true);
     397     13000375 :       descriptors[param_num].move_cost = cost;
     398              :       /* Watch overflow, move_cost is a bitfield.  */
     399     13000375 :       gcc_checking_assert (cost == descriptors[param_num].move_cost);
     400     13000375 :       param_num++;
     401              :     }
     402      5671099 : }
     403              : 
     404              : /* Return how many formal parameters FNDECL has.  */
     405              : 
     406              : int
     407     15564330 : count_formal_params (tree fndecl)
     408              : {
     409     15564330 :   tree parm;
     410     15564330 :   int count = 0;
     411     15564330 :   gcc_assert (gimple_has_body_p (fndecl));
     412              : 
     413     48012720 :   for (parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
     414     32448390 :     count++;
     415              : 
     416     15564330 :   return count;
     417              : }
     418              : 
     419              : /* Return the declaration of Ith formal parameter of the function corresponding
     420              :    to INFO.  Note there is no setter function as this array is built just once
     421              :    using ipa_initialize_node_params. */
     422              : 
     423              : void
     424          826 : ipa_dump_param (FILE *file, class ipa_node_params *info, int i)
     425              : {
     426          826 :   fprintf (file, "param #%i", i);
     427          826 :   if ((*info->descriptors)[i].decl_or_type)
     428              :     {
     429          826 :       fprintf (file, " ");
     430          826 :       print_generic_expr (file, (*info->descriptors)[i].decl_or_type);
     431              :     }
     432          826 : }
     433              : 
     434              : /* If necessary, allocate vector of parameter descriptors in info of NODE.
     435              :    Return true if they were allocated, false if not.  */
     436              : 
     437              : static bool
     438      6580087 : ipa_alloc_node_params (struct cgraph_node *node, int param_count)
     439              : {
     440      6580087 :   ipa_node_params *info = ipa_node_params_sum->get_create (node);
     441              : 
     442      6580087 :   if (!info->descriptors && param_count)
     443              :     {
     444      5724200 :       vec_safe_grow_cleared (info->descriptors, param_count, true);
     445      5724200 :       return true;
     446              :     }
     447              :   else
     448              :     return false;
     449              : }
     450              : 
     451              : /* Initialize the ipa_node_params structure associated with NODE by counting
     452              :    the function parameters, creating the descriptors and populating their
     453              :    param_decls.  */
     454              : 
     455              : void
     456      6500382 : ipa_initialize_node_params (struct cgraph_node *node)
     457              : {
     458      6500382 :   ipa_node_params *info = ipa_node_params_sum->get_create (node);
     459              : 
     460      6500382 :   if (!info->descriptors
     461      6500382 :       && ipa_alloc_node_params (node, count_formal_params (node->decl)))
     462      5669760 :     ipa_populate_param_decls (node, *info->descriptors);
     463      6500382 : }
     464              : 
     465              : /* Print VAL which is extracted from a jump function to F.  */
     466              : 
     467              : void
     468         1407 : ipa_print_constant_value (FILE *f, tree val)
     469              : {
     470         1407 :   print_generic_expr (f, val);
     471              : 
     472              :   /* This is in keeping with values_equal_for_ipcp_p.  */
     473         1407 :   if (TREE_CODE (val) == ADDR_EXPR
     474         1407 :       && (TREE_CODE (TREE_OPERAND (val, 0)) == CONST_DECL
     475          267 :           || (TREE_CODE (TREE_OPERAND (val, 0)) == VAR_DECL
     476          105 :               && DECL_IN_CONSTANT_POOL (TREE_OPERAND (val, 0)))))
     477              :     {
     478            0 :       fputs (" -> ", f);
     479            0 :       print_generic_expr (f, DECL_INITIAL (TREE_OPERAND (val, 0)));
     480              :     }
     481         1407 : }
     482              : 
     483              : /* Print contents of JFUNC to F.  If CTX is non-NULL, dump it too.  */
     484              : 
     485              : DEBUG_FUNCTION void
     486         1094 : ipa_dump_jump_function (FILE *f, ipa_jump_func *jump_func,
     487              :                         class ipa_polymorphic_call_context *ctx)
     488              : {
     489         1094 :   enum jump_func_type type = jump_func->type;
     490              : 
     491         1094 :   if (type == IPA_JF_UNKNOWN)
     492          277 :     fprintf (f, "UNKNOWN\n");
     493          817 :   else if (type == IPA_JF_CONST)
     494              :     {
     495          324 :       fprintf (f, "CONST: ");
     496          324 :       ipa_print_constant_value (f, jump_func->value.constant.value);
     497          324 :       fprintf (f, "\n");
     498              :     }
     499          493 :   else if (type == IPA_JF_PASS_THROUGH)
     500              :     {
     501          432 :       fprintf (f, "PASS THROUGH: ");
     502          432 :       fprintf (f, "%d, op %s",
     503              :                jump_func->value.pass_through.formal_id,
     504              :                get_tree_code_name(jump_func->value.pass_through.operation));
     505          432 :       if (jump_func->value.pass_through.operation != NOP_EXPR)
     506              :         {
     507           32 :           fprintf (f, " ");
     508           32 :           if (jump_func->value.pass_through.operand)
     509           28 :             print_generic_expr (f, jump_func->value.pass_through.operand);
     510           32 :           fprintf (f, " (in type ");
     511           32 :           print_generic_expr (f, jump_func->value.pass_through.op_type);
     512           32 :           fprintf (f, ")");
     513              :         }
     514          432 :       if (jump_func->value.pass_through.agg_preserved)
     515          138 :         fprintf (f, ", agg_preserved");
     516          432 :       if (jump_func->value.pass_through.refdesc_decremented)
     517            0 :         fprintf (f, ", refdesc_decremented");
     518          432 :       fprintf (f, "\n");
     519              :     }
     520           61 :   else if (type == IPA_JF_ANCESTOR)
     521              :     {
     522           61 :       fprintf (f, "ANCESTOR: ");
     523           61 :       fprintf (f, "%d, offset " HOST_WIDE_INT_PRINT_DEC,
     524              :                jump_func->value.ancestor.formal_id,
     525              :                jump_func->value.ancestor.offset);
     526           61 :       if (jump_func->value.ancestor.agg_preserved)
     527           29 :         fprintf (f, ", agg_preserved");
     528           61 :       if (jump_func->value.ancestor.keep_null)
     529            4 :         fprintf (f, ", keep_null");
     530           61 :       fprintf (f, "\n");
     531              :     }
     532              : 
     533         1094 :   if (jump_func->agg.items)
     534              :     {
     535          104 :       struct ipa_agg_jf_item *item;
     536          104 :       int j;
     537              : 
     538          208 :       fprintf (f, "         Aggregate passed by %s:\n",
     539          104 :                jump_func->agg.by_ref ? "reference" : "value");
     540          432 :       FOR_EACH_VEC_ELT (*jump_func->agg.items, j, item)
     541              :         {
     542          224 :           fprintf (f, "           offset: " HOST_WIDE_INT_PRINT_DEC ", ",
     543              :                    item->offset);
     544          224 :           fprintf (f, "type: ");
     545          224 :           print_generic_expr (f, item->type);
     546          224 :           fprintf (f, ", ");
     547          224 :           if (item->jftype == IPA_JF_PASS_THROUGH)
     548           31 :             fprintf (f, "PASS THROUGH: %d,",
     549              :                      item->value.pass_through.formal_id);
     550          193 :           else if (item->jftype == IPA_JF_LOAD_AGG)
     551              :             {
     552           11 :               fprintf (f, "LOAD AGG: %d",
     553              :                        item->value.pass_through.formal_id);
     554           11 :               fprintf (f, " [offset: " HOST_WIDE_INT_PRINT_DEC ", by %s],",
     555              :                        item->value.load_agg.offset,
     556           11 :                        item->value.load_agg.by_ref ? "reference"
     557              :                        : "value");
     558              :             }
     559              : 
     560          224 :           if (item->jftype == IPA_JF_PASS_THROUGH
     561          224 :               || item->jftype == IPA_JF_LOAD_AGG)
     562              :             {
     563           42 :               fprintf (f, " op %s",
     564              :                        get_tree_code_name (item->value.pass_through.operation));
     565           42 :               if (item->value.pass_through.operation != NOP_EXPR)
     566              :                 {
     567            9 :                   fprintf (f, " ");
     568            9 :                   if (item->value.pass_through.operand)
     569            8 :                     print_generic_expr (f, item->value.pass_through.operand);
     570            9 :                   fprintf (f, " (in type ");
     571            9 :                   print_generic_expr (f, jump_func->value.pass_through.op_type);
     572            9 :                   fprintf (f, ")");
     573              :                 }
     574              :             }
     575          182 :           else if (item->jftype == IPA_JF_CONST)
     576              :             {
     577          182 :               fprintf (f, "CONST: ");
     578          182 :               ipa_print_constant_value (f, item->value.constant);
     579              :             }
     580            0 :           else if (item->jftype == IPA_JF_UNKNOWN)
     581            0 :             fprintf (f, "UNKNOWN: " HOST_WIDE_INT_PRINT_DEC " bits",
     582            0 :                      tree_to_uhwi (TYPE_SIZE (item->type)));
     583          224 :           fprintf (f, "\n");
     584              :         }
     585              :     }
     586              : 
     587         1094 :   if (ctx && !ctx->useless_p ())
     588              :     {
     589          384 :       fprintf (f, "         Context: ");
     590          384 :       ctx->dump (dump_file);
     591              :     }
     592              : 
     593         1094 :   if (jump_func->m_vr)
     594              :     {
     595          761 :       fprintf (f, "         ");
     596          761 :       jump_func->m_vr->dump (f);
     597          761 :       fprintf (f, "\n");
     598              :     }
     599              :   else
     600          333 :     fprintf (f, "         Unknown VR\n");
     601         1094 : }
     602              : 
     603              : /* Print the jump functions associated with call graph edge CS to file F.  */
     604              : 
     605              : static void
     606          769 : ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs)
     607              : {
     608          769 :   ipa_edge_args *args = ipa_edge_args_sum->get (cs);
     609          769 :   int count = ipa_get_cs_argument_count (args);
     610              : 
     611         1863 :   for (int i = 0; i < count; i++)
     612              :     {
     613         1094 :       struct ipa_jump_func *jump_func = ipa_get_ith_jump_func (args, i);
     614         1094 :       class ipa_polymorphic_call_context *ctx
     615         1094 :         = ipa_get_ith_polymorhic_call_context (args, i);
     616              : 
     617         1094 :       fprintf (f, "       param %d: ", i);
     618         1094 :       ipa_dump_jump_function (f, jump_func, ctx);
     619              :     }
     620          769 : }
     621              : 
     622              : 
     623              : /* Print the jump functions of all arguments on all call graph edges going from
     624              :    NODE to file F.  */
     625              : 
     626              : void
     627         1147 : ipa_print_node_jump_functions (FILE *f, struct cgraph_node *node)
     628              : {
     629         1147 :   struct cgraph_edge *cs;
     630              : 
     631         1147 :   fprintf (f, "  Jump functions of caller  %s:\n", node->dump_name ());
     632         2297 :   for (cs = node->callees; cs; cs = cs->next_callee)
     633              :     {
     634              : 
     635         1150 :       fprintf (f, "    callsite  %s -> %s : \n",
     636              :                node->dump_name (),
     637         1150 :                cs->callee->dump_name ());
     638         1150 :       if (!ipa_edge_args_info_available_for_edge_p (cs))
     639          528 :         fprintf (f, "       no arg info\n");
     640              :       else
     641          622 :         ipa_print_node_jump_functions_for_edge (f, cs);
     642              :     }
     643              : 
     644         1294 :   for (cs = node->indirect_calls; cs; cs = cs->next_callee)
     645              :     {
     646          147 :       fprintf (f, "    ");
     647          147 :       cs->indirect_info->dump (f, false);
     648          147 :       if (cs->call_stmt)
     649              :         {
     650          131 :           fprintf (f, ", for stmt ");
     651          131 :           print_gimple_stmt (f, cs->call_stmt, 0, TDF_SLIM);
     652              :         }
     653              :       else
     654           16 :         fprintf (f, "\n");
     655          147 :       if (!ipa_edge_args_info_available_for_edge_p (cs))
     656            0 :         fprintf (f, "       no arg info\n");
     657              :       else
     658          147 :         ipa_print_node_jump_functions_for_edge (f, cs);
     659              :     }
     660         1147 : }
     661              : 
     662              : /* Print ipa_jump_func data structures of all nodes in the call graph to F.  */
     663              : 
     664              : void
     665          175 : ipa_print_all_jump_functions (FILE *f)
     666              : {
     667          175 :   struct cgraph_node *node;
     668              : 
     669          175 :   fprintf (f, "\nJump functions:\n");
     670         1306 :   FOR_EACH_FUNCTION (node)
     671              :     {
     672         1131 :       ipa_print_node_jump_functions (f, node);
     673              :     }
     674          175 : }
     675              : 
     676              : /* Set jfunc to be a know-really nothing jump function.  */
     677              : 
     678              : static void
     679       555290 : ipa_set_jf_unknown (struct ipa_jump_func *jfunc)
     680              : {
     681       555290 :   jfunc->type = IPA_JF_UNKNOWN;
     682            0 : }
     683              : 
     684              : /* Set DST to be a copy of another SRC.  The two functions will share their
     685              :    rdesc.  */
     686              : 
     687              : static void
     688       932241 : ipa_set_jf_cst_copy (struct ipa_jump_func *dst,
     689              :                      struct ipa_jump_func *src)
     690              : 
     691              : {
     692       932241 :   gcc_checking_assert (src->type == IPA_JF_CONST);
     693       932241 :   dst->type = IPA_JF_CONST;
     694       932241 :   dst->value.constant = src->value.constant;
     695       932241 : }
     696              : 
     697              : /* Set DST to be a copy of another jump function SRC but possibly adjust it to
     698              :    a new passed type PARM_TYPE.  If the adjustment fails, the jump function can
     699              :    end up being set to the unknown type.  If the conversion is not necessary or
     700              :    it succeeds and if the destination rdesc has not been already used, the two
     701              :    functions will share their rdesc.  */
     702              : 
     703              : static void
     704       160488 : ipa_convert_prop_cst_jf (struct ipa_jump_func *dst,
     705              :                          struct ipa_jump_func *src,
     706              :                          tree parm_type)
     707              : 
     708              : {
     709       160488 :   gcc_checking_assert (src->type == IPA_JF_CONST);
     710       160488 :   tree new_val = ipacp_value_safe_for_type (parm_type,
     711              :                                             ipa_get_jf_constant (src));
     712       160488 :   if (new_val)
     713              :     {
     714       160487 :       bool rd = ipa_get_jf_pass_through_refdesc_decremented (dst);
     715              : 
     716       160487 :       dst->type = IPA_JF_CONST;
     717       160487 :       dst->value.constant.value = new_val;
     718       160487 :       if (!rd)
     719       160462 :         dst->value.constant.rdesc = src->value.constant.rdesc;
     720              :       else
     721           25 :         ipa_zap_jf_refdesc (dst);
     722              :     }
     723              :   else
     724            1 :     ipa_set_jf_unknown (dst);
     725       160488 : }
     726              : 
     727              : /* Set JFUNC to be a constant jmp function.  */
     728              : 
     729              : static void
     730      2823835 : ipa_set_jf_constant (struct ipa_jump_func *jfunc, tree constant,
     731              :                      struct cgraph_edge *cs)
     732              : {
     733      2823835 :   jfunc->type = IPA_JF_CONST;
     734      2823835 :   jfunc->value.constant.value = unshare_expr_without_location (constant);
     735              : 
     736      2823835 :   if (TREE_CODE (constant) == ADDR_EXPR
     737      2823835 :       && (TREE_CODE (TREE_OPERAND (constant, 0)) == FUNCTION_DECL
     738      1017820 :           || (VAR_P (TREE_OPERAND (constant, 0))
     739       366554 :               && TREE_STATIC (TREE_OPERAND (constant, 0)))))
     740              :     {
     741       393156 :       struct ipa_cst_ref_desc *rdesc;
     742              : 
     743       393156 :       rdesc = ipa_refdesc_pool.allocate ();
     744       393156 :       rdesc->cs = cs;
     745       393156 :       rdesc->next_duplicate = NULL;
     746       393156 :       rdesc->refcount = 1;
     747       393156 :       jfunc->value.constant.rdesc = rdesc;
     748              :     }
     749              :   else
     750      2430679 :     jfunc->value.constant.rdesc = NULL;
     751      2823835 : }
     752              : 
     753              : /* Set JFUNC to be a simple pass-through jump function.  */
     754              : static void
     755      1420641 : ipa_set_jf_simple_pass_through (struct ipa_jump_func *jfunc, int formal_id,
     756              :                                 bool agg_preserved)
     757              : {
     758      1420641 :   jfunc->type = IPA_JF_PASS_THROUGH;
     759      1420641 :   jfunc->value.pass_through.operand = NULL_TREE;
     760      1420641 :   jfunc->value.pass_through.op_type = NULL_TREE;
     761      1420641 :   jfunc->value.pass_through.formal_id = formal_id;
     762      1420641 :   jfunc->value.pass_through.operation = NOP_EXPR;
     763      1420641 :   jfunc->value.pass_through.agg_preserved = agg_preserved;
     764      1420641 :   jfunc->value.pass_through.refdesc_decremented = false;
     765            0 : }
     766              : 
     767              : /* Set JFUNC to be an unary pass through jump function.  */
     768              : 
     769              : static void
     770         1029 : ipa_set_jf_unary_pass_through (struct ipa_jump_func *jfunc, int formal_id,
     771              :                                enum tree_code operation, tree op_type)
     772              : {
     773         1029 :   jfunc->type = IPA_JF_PASS_THROUGH;
     774         1029 :   jfunc->value.pass_through.operand = NULL_TREE;
     775         1029 :   jfunc->value.pass_through.op_type = op_type;
     776         1029 :   jfunc->value.pass_through.formal_id = formal_id;
     777         1029 :   jfunc->value.pass_through.operation = operation;
     778         1029 :   jfunc->value.pass_through.agg_preserved = false;
     779         1029 :   jfunc->value.pass_through.refdesc_decremented = false;
     780            0 : }
     781              : /* Set JFUNC to be an arithmetic pass through jump function.  */
     782              : 
     783              : static void
     784        45837 : ipa_set_jf_arith_pass_through (struct ipa_jump_func *jfunc, int formal_id,
     785              :                                tree operand, enum tree_code operation,
     786              :                                tree op_type)
     787              : {
     788        45837 :   jfunc->type = IPA_JF_PASS_THROUGH;
     789            0 :   jfunc->value.pass_through.operand = unshare_expr_without_location (operand);
     790        45837 :   jfunc->value.pass_through.op_type = op_type;
     791        45837 :   jfunc->value.pass_through.formal_id = formal_id;
     792        45837 :   jfunc->value.pass_through.operation = operation;
     793        45837 :   jfunc->value.pass_through.agg_preserved = false;
     794        45837 :   jfunc->value.pass_through.refdesc_decremented = false;
     795            0 : }
     796              : 
     797              : /* Set JFUNC to be an ancestor jump function.  */
     798              : 
     799              : static void
     800       197751 : ipa_set_ancestor_jf (struct ipa_jump_func *jfunc, HOST_WIDE_INT offset,
     801              :                      int formal_id, bool agg_preserved, bool keep_null)
     802              : {
     803       197751 :   jfunc->type = IPA_JF_ANCESTOR;
     804       197751 :   jfunc->value.ancestor.formal_id = formal_id;
     805       197751 :   jfunc->value.ancestor.offset = offset;
     806       197751 :   jfunc->value.ancestor.agg_preserved = agg_preserved;
     807       197751 :   jfunc->value.ancestor.keep_null = keep_null;
     808            0 : }
     809              : 
     810              : /* Get IPA BB information about the given BB.  FBI is the context of analysis
     811              :    of this function body.  */
     812              : 
     813              : static struct ipa_bb_info *
     814     34521205 : ipa_get_bb_info (struct ipa_func_body_info *fbi, basic_block bb)
     815              : {
     816     28807199 :   gcc_checking_assert (fbi);
     817     34521205 :   return &fbi->bb_infos[bb->index];
     818              : }
     819              : 
     820              : /* Structure to be passed in between detect_type_change and
     821              :    check_stmt_for_type_change.  */
     822              : 
     823              : struct prop_type_change_info
     824              : {
     825              :   /* Offset into the object where there is the virtual method pointer we are
     826              :      looking for.  */
     827              :   HOST_WIDE_INT offset;
     828              :   /* The declaration or SSA_NAME pointer of the base that we are checking for
     829              :      type change.  */
     830              :   tree object;
     831              :   /* Set to true if dynamic type change has been detected.  */
     832              :   bool type_maybe_changed;
     833              : };
     834              : 
     835              : /* Return true if STMT can modify a virtual method table pointer.
     836              : 
     837              :    This function makes special assumptions about both constructors and
     838              :    destructors which are all the functions that are allowed to alter the VMT
     839              :    pointers.  It assumes that destructors begin with assignment into all VMT
     840              :    pointers and that constructors essentially look in the following way:
     841              : 
     842              :    1) The very first thing they do is that they call constructors of ancestor
     843              :    sub-objects that have them.
     844              : 
     845              :    2) Then VMT pointers of this and all its ancestors is set to new values
     846              :    corresponding to the type corresponding to the constructor.
     847              : 
     848              :    3) Only afterwards, other stuff such as constructor of member sub-objects
     849              :    and the code written by the user is run.  Only this may include calling
     850              :    virtual functions, directly or indirectly.
     851              : 
     852              :    There is no way to call a constructor of an ancestor sub-object in any
     853              :    other way.
     854              : 
     855              :    This means that we do not have to care whether constructors get the correct
     856              :    type information because they will always change it (in fact, if we define
     857              :    the type to be given by the VMT pointer, it is undefined).
     858              : 
     859              :    The most important fact to derive from the above is that if, for some
     860              :    statement in the section 3, we try to detect whether the dynamic type has
     861              :    changed, we can safely ignore all calls as we examine the function body
     862              :    backwards until we reach statements in section 2 because these calls cannot
     863              :    be ancestor constructors or destructors (if the input is not bogus) and so
     864              :    do not change the dynamic type (this holds true only for automatically
     865              :    allocated objects but at the moment we devirtualize only these).  We then
     866              :    must detect that statements in section 2 change the dynamic type and can try
     867              :    to derive the new type.  That is enough and we can stop, we will never see
     868              :    the calls into constructors of sub-objects in this code.  Therefore we can
     869              :    safely ignore all call statements that we traverse.
     870              :   */
     871              : 
     872              : static bool
     873            9 : stmt_may_be_vtbl_ptr_store (gimple *stmt)
     874              : {
     875            9 :   if (is_gimple_call (stmt))
     876              :     return false;
     877            0 :   if (gimple_clobber_p (stmt))
     878              :     return false;
     879            0 :   else if (is_gimple_assign (stmt))
     880              :     {
     881            0 :       tree lhs = gimple_assign_lhs (stmt);
     882              : 
     883            0 :       if (!AGGREGATE_TYPE_P (TREE_TYPE (lhs)))
     884              :         {
     885            0 :           if (flag_strict_aliasing
     886            0 :               && !POINTER_TYPE_P (TREE_TYPE (lhs)))
     887              :             return false;
     888              : 
     889            0 :           if (TREE_CODE (lhs) == COMPONENT_REF
     890            0 :               && !DECL_VIRTUAL_P (TREE_OPERAND (lhs, 1)))
     891            0 :             return false;
     892              :           /* In the future we might want to use get_ref_base_and_extent to find
     893              :              if there is a field corresponding to the offset and if so, proceed
     894              :              almost like if it was a component ref.  */
     895              :         }
     896              :     }
     897              :   return true;
     898              : }
     899              : 
     900              : /* Callback of walk_aliased_vdefs and a helper function for detect_type_change
     901              :    to check whether a particular statement may modify the virtual table
     902              :    pointerIt stores its result into DATA, which points to a
     903              :    prop_type_change_info structure.  */
     904              : 
     905              : static bool
     906            9 : check_stmt_for_type_change (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
     907              : {
     908            9 :   gimple *stmt = SSA_NAME_DEF_STMT (vdef);
     909            9 :   struct prop_type_change_info *tci = (struct prop_type_change_info *) data;
     910              : 
     911            9 :   if (stmt_may_be_vtbl_ptr_store (stmt))
     912              :     {
     913            0 :       tci->type_maybe_changed = true;
     914            0 :       return true;
     915              :     }
     916              :   else
     917              :     return false;
     918              : }
     919              : 
     920              : /* See if ARG is PARAM_DECl describing instance passed by pointer
     921              :    or reference in FUNCTION.  Return false if the dynamic type may change
     922              :    in between beginning of the function until CALL is invoked.
     923              : 
     924              :    Generally functions are not allowed to change type of such instances,
     925              :    but they call destructors.  We assume that methods cannot destroy the THIS
     926              :    pointer.  Also as a special cases, constructor and destructors may change
     927              :    type of the THIS pointer.  */
     928              : 
     929              : static bool
     930         9764 : param_type_may_change_p (tree function, tree arg, gimple *call)
     931              : {
     932              :   /* Pure functions cannot do any changes on the dynamic type;
     933              :      that require writing to memory.  */
     934         9764 :   if (flags_from_decl_or_type (function) & (ECF_PURE | ECF_CONST))
     935              :     return false;
     936              :   /* We need to check if we are within inlined constructor
     937              :      or destructor (ideally we would have way to check that the
     938              :      inline cdtor is actually working on ARG, but we don't have
     939              :      easy tie on this, so punt on all non-pure cdtors.
     940              :      We may also record the types of cdtors and once we know type
     941              :      of the instance match them.
     942              : 
     943              :      Also code unification optimizations may merge calls from
     944              :      different blocks making return values unreliable.  So
     945              :      do nothing during late optimization.  */
     946         9764 :   if (DECL_STRUCT_FUNCTION (function)->after_inlining)
     947              :     return true;
     948         9764 :   if (TREE_CODE (arg) == SSA_NAME
     949         9764 :       && SSA_NAME_IS_DEFAULT_DEF (arg)
     950        19528 :       && TREE_CODE (SSA_NAME_VAR (arg)) == PARM_DECL)
     951              :     {
     952              :       /* Normal (non-THIS) argument.  */
     953         9764 :       if ((SSA_NAME_VAR (arg) != DECL_ARGUMENTS (function)
     954         8974 :            || TREE_CODE (TREE_TYPE (function)) != METHOD_TYPE)
     955              :           /* THIS pointer of an method - here we want to watch constructors
     956              :              and destructors as those definitely may change the dynamic
     957              :              type.  */
     958        18135 :           || (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE
     959         8371 :               && !DECL_CXX_CONSTRUCTOR_P (function)
     960         8370 :               && !DECL_CXX_DESTRUCTOR_P (function)
     961         8369 :               && (SSA_NAME_VAR (arg) == DECL_ARGUMENTS (function))))
     962              :         {
     963              :           /* Walk the inline stack and watch out for ctors/dtors.  */
     964        41856 :           for (tree block = gimple_block (call); block && TREE_CODE (block) == BLOCK;
     965        16047 :                block = BLOCK_SUPERCONTEXT (block))
     966        16062 :             if (inlined_polymorphic_ctor_dtor_block_p (block, false))
     967              :               return true;
     968              :           return false;
     969              :         }
     970              :     }
     971              :   return true;
     972              : }
     973              : 
     974              : /* Detect whether the dynamic type of ARG of COMP_TYPE has changed (before
     975              :    callsite CALL) by looking for assignments to its virtual table pointer.  If
     976              :    it is, return true.  ARG is the object itself (not a pointer
     977              :    to it, unless dereferenced).  BASE is the base of the memory access as
     978              :    returned by get_ref_base_and_extent, as is the offset.
     979              : 
     980              :    This is helper function for detect_type_change and detect_type_change_ssa
     981              :    that does the heavy work which is usually unnecessary.  */
     982              : 
     983              : static bool
     984           17 : detect_type_change_from_memory_writes (ipa_func_body_info *fbi, tree arg,
     985              :                                        tree base, tree comp_type, gcall *call,
     986              :                                        HOST_WIDE_INT offset)
     987              : {
     988           17 :   struct prop_type_change_info tci;
     989           17 :   ao_ref ao;
     990              : 
     991           17 :   gcc_checking_assert (DECL_P (arg)
     992              :                        || TREE_CODE (arg) == MEM_REF
     993              :                        || handled_component_p (arg));
     994              : 
     995           17 :   comp_type = TYPE_MAIN_VARIANT (comp_type);
     996              : 
     997              :   /* Const calls cannot call virtual methods through VMT and so type changes do
     998              :      not matter.  */
     999           17 :   if (!flag_devirtualize || !gimple_vuse (call)
    1000              :       /* Be sure expected_type is polymorphic.  */
    1001           17 :       || !comp_type
    1002           17 :       || TREE_CODE (comp_type) != RECORD_TYPE
    1003           17 :       || !TYPE_BINFO (TYPE_MAIN_VARIANT (comp_type))
    1004           34 :       || !BINFO_VTABLE (TYPE_BINFO (TYPE_MAIN_VARIANT (comp_type))))
    1005              :     return true;
    1006              : 
    1007           17 :   if (fbi->aa_walk_budget == 0)
    1008              :     return false;
    1009              : 
    1010           17 :   ao_ref_init (&ao, arg);
    1011           17 :   ao.base = base;
    1012           17 :   ao.offset = offset;
    1013           17 :   ao.size = POINTER_SIZE;
    1014           17 :   ao.max_size = ao.size;
    1015              : 
    1016           17 :   tci.offset = offset;
    1017           17 :   tci.object = get_base_address (arg);
    1018           17 :   tci.type_maybe_changed = false;
    1019              : 
    1020           17 :   int walked
    1021           34 :     = walk_aliased_vdefs (&ao, gimple_vuse (call), check_stmt_for_type_change,
    1022              :                           &tci, NULL, NULL, fbi->aa_walk_budget);
    1023           17 :   if (walked >= 0)
    1024           17 :     fbi->aa_walk_budget -= walked;
    1025              :   else
    1026            0 :     fbi->aa_walk_budget = 0;
    1027              : 
    1028           17 :   if (walked >= 0 && !tci.type_maybe_changed)
    1029              :     return false;
    1030              : 
    1031              :   return true;
    1032              : }
    1033              : 
    1034              : /* Detect whether the dynamic type of ARG of COMP_TYPE may have changed.
    1035              :    If it is, return true.  ARG is the object itself (not a pointer
    1036              :    to it, unless dereferenced).  BASE is the base of the memory access as
    1037              :    returned by get_ref_base_and_extent, as is the offset.  */
    1038              : 
    1039              : static bool
    1040          857 : detect_type_change (ipa_func_body_info *fbi, tree arg, tree base,
    1041              :                     tree comp_type, gcall *call,
    1042              :                     HOST_WIDE_INT offset)
    1043              : {
    1044          857 :   if (!flag_devirtualize)
    1045              :     return false;
    1046              : 
    1047          857 :   if (TREE_CODE (base) == MEM_REF
    1048         1714 :       && !param_type_may_change_p (current_function_decl,
    1049          857 :                                    TREE_OPERAND (base, 0),
    1050              :                                    call))
    1051              :     return false;
    1052           12 :   return detect_type_change_from_memory_writes (fbi, arg, base, comp_type,
    1053           12 :                                                 call, offset);
    1054              : }
    1055              : 
    1056              : /* Like detect_type_change but ARG is supposed to be a non-dereferenced pointer
    1057              :    SSA name (its dereference will become the base and the offset is assumed to
    1058              :    be zero).  */
    1059              : 
    1060              : static bool
    1061         8907 : detect_type_change_ssa (ipa_func_body_info *fbi, tree arg, tree comp_type,
    1062              :                         gcall *call)
    1063              : {
    1064         8907 :   gcc_checking_assert (TREE_CODE (arg) == SSA_NAME);
    1065         8907 :   if (!flag_devirtualize
    1066         8907 :       || !POINTER_TYPE_P (TREE_TYPE (arg)))
    1067              :     return false;
    1068              : 
    1069         8907 :   if (!param_type_may_change_p (current_function_decl, arg, call))
    1070              :     return false;
    1071              : 
    1072            5 :   arg = build2 (MEM_REF, ptr_type_node, arg,
    1073              :                 build_int_cst (ptr_type_node, 0));
    1074              : 
    1075            5 :   return detect_type_change_from_memory_writes (fbi, arg, arg, comp_type,
    1076            5 :                                                 call, 0);
    1077              : }
    1078              : 
    1079              : /* Callback of walk_aliased_vdefs.  Flags that it has been invoked to the
    1080              :    boolean variable pointed to by DATA.  */
    1081              : 
    1082              : static bool
    1083      1687147 : mark_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED,
    1084              :                      void *data)
    1085              : {
    1086      1687147 :   bool *b = (bool *) data;
    1087      1687147 :   *b = true;
    1088      1687147 :   return true;
    1089              : }
    1090              : 
    1091              : /* Find the nearest valid aa status for parameter specified by INDEX that
    1092              :    dominates BB.  */
    1093              : 
    1094              : static struct ipa_param_aa_status *
    1095      4522792 : find_dominating_aa_status (struct ipa_func_body_info *fbi, basic_block bb,
    1096              :                            int index)
    1097              : {
    1098     13696992 :   while (true)
    1099              :     {
    1100     13696992 :       bb = get_immediate_dominator (CDI_DOMINATORS, bb);
    1101     13696992 :       if (!bb)
    1102              :         return NULL;
    1103     10638355 :       struct ipa_bb_info *bi = ipa_get_bb_info (fbi, bb);
    1104     12789782 :       if (!bi->param_aa_statuses.is_empty ()
    1105      2151427 :           && bi->param_aa_statuses[index].valid)
    1106      1464155 :         return &bi->param_aa_statuses[index];
    1107              :     }
    1108              : }
    1109              : 
    1110              : /* Get AA status structure for the given BB and parameter with INDEX.  Allocate
    1111              :    structures and/or initialize the result with a dominating description as
    1112              :    necessary.  */
    1113              : 
    1114              : static struct ipa_param_aa_status *
    1115      6804299 : parm_bb_aa_status_for_bb (struct ipa_func_body_info *fbi, basic_block bb,
    1116              :                           int index)
    1117              : {
    1118      6804299 :   gcc_checking_assert (fbi);
    1119      6804299 :   struct ipa_bb_info *bi = ipa_get_bb_info (fbi, bb);
    1120      6804299 :   if (bi->param_aa_statuses.is_empty ())
    1121      3893179 :     bi->param_aa_statuses.safe_grow_cleared (fbi->param_count, true);
    1122      6804299 :   struct ipa_param_aa_status *paa = &bi->param_aa_statuses[index];
    1123      6804299 :   if (!paa->valid)
    1124              :     {
    1125      4522792 :       gcc_checking_assert (!paa->parm_modified
    1126              :                            && !paa->ref_modified
    1127              :                            && !paa->pt_modified);
    1128      4522792 :       struct ipa_param_aa_status *dom_paa;
    1129      4522792 :       dom_paa = find_dominating_aa_status (fbi, bb, index);
    1130      4522792 :       if (dom_paa)
    1131      1464155 :         *paa = *dom_paa;
    1132              :       else
    1133      3058637 :         paa->valid = true;
    1134              :     }
    1135              : 
    1136      6804299 :   return paa;
    1137              : }
    1138              : 
    1139              : /* Return true if a load from a formal parameter PARM_LOAD is known to retrieve
    1140              :    a value known not to be modified in this function before reaching the
    1141              :    statement STMT.  FBI holds information about the function we have so far
    1142              :    gathered but do not survive the summary building stage.  */
    1143              : 
    1144              : static bool
    1145      1192640 : parm_preserved_before_stmt_p (struct ipa_func_body_info *fbi, int index,
    1146              :                               gimple *stmt, tree parm_load)
    1147              : {
    1148      1192640 :   struct ipa_param_aa_status *paa;
    1149      1192640 :   bool modified = false;
    1150      1192640 :   ao_ref refd;
    1151              : 
    1152      1192640 :   tree base = get_base_address (parm_load);
    1153      1192640 :   gcc_assert (TREE_CODE (base) == PARM_DECL);
    1154      1192640 :   if (TREE_READONLY (base))
    1155              :     return true;
    1156              : 
    1157      1105086 :   gcc_checking_assert (fbi);
    1158      1105086 :   paa = parm_bb_aa_status_for_bb (fbi, gimple_bb (stmt), index);
    1159      1105086 :   if (paa->parm_modified || fbi->aa_walk_budget == 0)
    1160              :     return false;
    1161              : 
    1162      1887854 :   gcc_checking_assert (gimple_vuse (stmt) != NULL_TREE);
    1163       943927 :   ao_ref_init (&refd, parm_load);
    1164      1887854 :   int walked = walk_aliased_vdefs (&refd, gimple_vuse (stmt), mark_modified,
    1165              :                                    &modified, NULL, NULL,
    1166              :                                    fbi->aa_walk_budget);
    1167       943927 :   if (walked < 0)
    1168              :     {
    1169            8 :       modified = true;
    1170            8 :       fbi->aa_walk_budget = 0;
    1171              :     }
    1172              :   else
    1173       943919 :     fbi->aa_walk_budget -= walked;
    1174       943927 :   if (paa && modified)
    1175       100503 :     paa->parm_modified = true;
    1176       943927 :   return !modified;
    1177              : }
    1178              : 
    1179              : /* If STMT is an assignment that loads a value from an parameter declaration,
    1180              :    return the index of the parameter in ipa_node_params which has not been
    1181              :    modified.  Otherwise return -1.  */
    1182              : 
    1183              : static int
    1184      6750408 : load_from_unmodified_param (struct ipa_func_body_info *fbi,
    1185              :                             vec<ipa_param_descriptor, va_gc> *descriptors,
    1186              :                             gimple *stmt)
    1187              : {
    1188      6750408 :   int index;
    1189      6750408 :   tree op1;
    1190              : 
    1191      6750408 :   if (!gimple_assign_single_p (stmt))
    1192              :     return -1;
    1193              : 
    1194      4481939 :   op1 = gimple_assign_rhs1 (stmt);
    1195      4481939 :   if (TREE_CODE (op1) != PARM_DECL)
    1196              :     return -1;
    1197              : 
    1198        70066 :   index = ipa_get_param_decl_index_1 (descriptors, op1);
    1199        70066 :   if (index < 0
    1200        70066 :       || !parm_preserved_before_stmt_p (fbi, index, stmt, op1))
    1201        24261 :     return -1;
    1202              : 
    1203              :   return index;
    1204              : }
    1205              : 
    1206              : /* Return true if memory reference REF (which must be a load through parameter
    1207              :    with INDEX) loads data that are known to be unmodified in this function
    1208              :    before reaching statement STMT.  */
    1209              : 
    1210              : static bool
    1211      4845765 : parm_ref_data_preserved_p (struct ipa_func_body_info *fbi,
    1212              :                            int index, gimple *stmt, tree ref)
    1213              : {
    1214      4845765 :   struct ipa_param_aa_status *paa;
    1215      4845765 :   bool modified = false;
    1216      4845765 :   ao_ref refd;
    1217              : 
    1218      4845765 :   gcc_checking_assert (fbi);
    1219      4845765 :   paa = parm_bb_aa_status_for_bb (fbi, gimple_bb (stmt), index);
    1220      4845765 :   if (paa->ref_modified || fbi->aa_walk_budget == 0)
    1221              :     return false;
    1222              : 
    1223      7556506 :   gcc_checking_assert (gimple_vuse (stmt));
    1224      3778253 :   ao_ref_init (&refd, ref);
    1225      7556506 :   int walked = walk_aliased_vdefs (&refd, gimple_vuse (stmt), mark_modified,
    1226              :                                    &modified, NULL, NULL,
    1227              :                                    fbi->aa_walk_budget);
    1228      3778253 :   if (walked < 0)
    1229              :     {
    1230            8 :       modified = true;
    1231            8 :       fbi->aa_walk_budget = 0;
    1232              :     }
    1233              :   else
    1234      3778245 :     fbi->aa_walk_budget -= walked;
    1235      3778253 :   if (modified)
    1236       650382 :     paa->ref_modified = true;
    1237      3778253 :   return !modified;
    1238              : }
    1239              : 
    1240              : /* Return true if the data pointed to by PARM (which is a parameter with INDEX)
    1241              :    is known to be unmodified in this function before reaching call statement
    1242              :    CALL into which it is passed.  FBI describes the function body.  */
    1243              : 
    1244              : static bool
    1245      1199198 : parm_ref_data_pass_through_p (struct ipa_func_body_info *fbi, int index,
    1246              :                               gimple *call, tree parm)
    1247              : {
    1248      1199198 :   bool modified = false;
    1249      1199198 :   ao_ref refd;
    1250              : 
    1251              :   /* It's unnecessary to calculate anything about memory contents for a const
    1252              :      function because it is not going to use it.  But do not cache the result
    1253              :      either.  Also, no such calculations for non-pointers.  */
    1254      1199198 :   if (!gimple_vuse (call)
    1255      1199198 :       || !POINTER_TYPE_P (TREE_TYPE (parm)))
    1256              :     return false;
    1257              : 
    1258       853448 :   struct ipa_param_aa_status *paa = parm_bb_aa_status_for_bb (fbi,
    1259              :                                                               gimple_bb (call),
    1260              :                                                               index);
    1261       853448 :   if (paa->pt_modified || fbi->aa_walk_budget == 0)
    1262              :     return false;
    1263              : 
    1264       730647 :   ao_ref_init_from_ptr_and_size (&refd, parm, NULL_TREE);
    1265      1461294 :   int walked = walk_aliased_vdefs (&refd, gimple_vuse (call), mark_modified,
    1266              :                                    &modified, NULL, NULL,
    1267              :                                    fbi->aa_walk_budget);
    1268       730647 :   if (walked < 0)
    1269              :     {
    1270            0 :       fbi->aa_walk_budget = 0;
    1271            0 :       modified = true;
    1272              :     }
    1273              :   else
    1274       730647 :     fbi->aa_walk_budget -= walked;
    1275       730647 :   if (modified)
    1276       273638 :     paa->pt_modified = true;
    1277       730647 :   return !modified;
    1278              : }
    1279              : 
    1280              : /* Return true if we can prove that OP is a memory reference loading
    1281              :    data from an aggregate passed as a parameter.
    1282              : 
    1283              :    The function works in two modes.  If GUARANTEED_UNMODIFIED is NULL, it return
    1284              :    false if it cannot prove that the value has not been modified before the
    1285              :    load in STMT.  If GUARANTEED_UNMODIFIED is not NULL, it will return true even
    1286              :    if it cannot prove the value has not been modified, in that case it will
    1287              :    store false to *GUARANTEED_UNMODIFIED, otherwise it will store true there.
    1288              : 
    1289              :    INFO and PARMS_AINFO describe parameters of the current function (but the
    1290              :    latter can be NULL), STMT is the load statement.  If function returns true,
    1291              :    *INDEX_P, *OFFSET_P and *BY_REF is filled with the parameter index, offset
    1292              :    within the aggregate and whether it is a load from a value passed by
    1293              :    reference respectively.
    1294              : 
    1295              :    Return false if the offset divided by BITS_PER_UNIT would not fit into an
    1296              :    unsigned int.  */
    1297              : 
    1298              : bool
    1299     26155438 : ipa_load_from_parm_agg (struct ipa_func_body_info *fbi,
    1300              :                         vec<ipa_param_descriptor, va_gc> *descriptors,
    1301              :                         gimple *stmt, tree op, int *index_p,
    1302              :                         HOST_WIDE_INT *offset_p, poly_int64 *size_p,
    1303              :                         bool *by_ref_p, bool *guaranteed_unmodified)
    1304              : {
    1305     26155438 :   int index;
    1306     26155438 :   HOST_WIDE_INT size;
    1307     26155438 :   bool reverse;
    1308     26155438 :   tree base = get_ref_base_and_extent_hwi (op, offset_p, &size, &reverse);
    1309              : 
    1310     26155438 :   if (!base
    1311     24738312 :       || (*offset_p / BITS_PER_UNIT) > UINT_MAX)
    1312              :     return false;
    1313              : 
    1314              :   /* We can not propagate across volatile loads.  */
    1315     24738281 :   if (TREE_THIS_VOLATILE (op))
    1316              :     return false;
    1317              : 
    1318     23517569 :   if (DECL_P (base))
    1319              :     {
    1320     11453720 :       int index = ipa_get_param_decl_index_1 (descriptors, base);
    1321     11453720 :       if (index >= 0
    1322     11453720 :           && parm_preserved_before_stmt_p (fbi, index, stmt, op))
    1323              :         {
    1324       819330 :           *index_p = index;
    1325       819330 :           *by_ref_p = false;
    1326       819330 :           if (size_p)
    1327        28226 :             *size_p = size;
    1328       819330 :           if (guaranteed_unmodified)
    1329          137 :             *guaranteed_unmodified = true;
    1330              :           return true;
    1331              :         }
    1332              :       return false;
    1333              :     }
    1334              : 
    1335     12063849 :   if (TREE_CODE (base) != MEM_REF
    1336     11173361 :            || TREE_CODE (TREE_OPERAND (base, 0)) != SSA_NAME
    1337     23233628 :            || !integer_zerop (TREE_OPERAND (base, 1)))
    1338              :     return false;
    1339              : 
    1340     10160952 :   if (SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0)))
    1341              :     {
    1342      4961333 :       tree parm = SSA_NAME_VAR (TREE_OPERAND (base, 0));
    1343      4961333 :       index = ipa_get_param_decl_index_1 (descriptors, parm);
    1344              :     }
    1345              :   else
    1346              :     {
    1347              :       /* This branch catches situations where a pointer parameter is not a
    1348              :          gimple register, for example:
    1349              : 
    1350              :          void hip7(S*) (struct S * p)
    1351              :          {
    1352              :          void (*<T2e4>) (struct S *) D.1867;
    1353              :          struct S * p.1;
    1354              : 
    1355              :          <bb 2>:
    1356              :          p.1_1 = p;
    1357              :          D.1867_2 = p.1_1->f;
    1358              :          D.1867_2 ();
    1359              :          gdp = &p;
    1360              :       */
    1361              : 
    1362      5199619 :       gimple *def = SSA_NAME_DEF_STMT (TREE_OPERAND (base, 0));
    1363      5199619 :       index = load_from_unmodified_param (fbi, descriptors, def);
    1364              :     }
    1365              : 
    1366     10160952 :   if (index >= 0)
    1367              :     {
    1368      4845462 :       bool data_preserved = parm_ref_data_preserved_p (fbi, index, stmt, op);
    1369      4845462 :       if (!data_preserved && !guaranteed_unmodified)
    1370              :         return false;
    1371              : 
    1372      3128176 :       *index_p = index;
    1373      3128176 :       *by_ref_p = true;
    1374      3128176 :       if (size_p)
    1375        30036 :         *size_p = size;
    1376      3128176 :       if (guaranteed_unmodified)
    1377         2193 :         *guaranteed_unmodified = data_preserved;
    1378              :       return true;
    1379              :     }
    1380              :   return false;
    1381              : }
    1382              : 
    1383              : /* If STMT is an assignment that loads a value from a parameter declaration,
    1384              :    or from an aggregate passed as the parameter either by value or reference,
    1385              :    return the index of the parameter in ipa_node_params.  Otherwise return -1.
    1386              : 
    1387              :    FBI holds gathered information about the function.  INFO describes
    1388              :    parameters of the function, STMT is the assignment statement.  If it is a
    1389              :    memory load from an aggregate, *OFFSET_P is filled with offset within the
    1390              :    aggregate, and *BY_REF_P specifies whether the aggregate is passed by
    1391              :    reference.  */
    1392              : 
    1393              : static int
    1394       380718 : load_from_unmodified_param_or_agg (struct ipa_func_body_info *fbi,
    1395              :                                    class ipa_node_params *info,
    1396              :                                    gimple *stmt,
    1397              :                                    HOST_WIDE_INT *offset_p,
    1398              :                                    bool *by_ref_p)
    1399              : {
    1400       380718 :   int index = load_from_unmodified_param (fbi, info->descriptors, stmt);
    1401       380718 :   poly_int64 size;
    1402              : 
    1403              :   /* Load value from a parameter declaration.  */
    1404       380718 :   if (index >= 0)
    1405              :     {
    1406          322 :       *offset_p = -1;
    1407          322 :       return index;
    1408              :     }
    1409              : 
    1410       380396 :   if (!gimple_assign_load_p (stmt))
    1411              :     return -1;
    1412              : 
    1413       195200 :   tree rhs = gimple_assign_rhs1 (stmt);
    1414              : 
    1415              :   /* Skip memory reference containing VIEW_CONVERT_EXPR.  */
    1416       550913 :   for (tree t = rhs; handled_component_p (t); t = TREE_OPERAND (t, 0))
    1417       160628 :     if (TREE_CODE (t) == VIEW_CONVERT_EXPR)
    1418              :       return -1;
    1419              : 
    1420              :   /* Skip memory reference containing bit-field.  */
    1421       195085 :   if (TREE_CODE (rhs) == BIT_FIELD_REF
    1422       195085 :       || contains_bitfld_component_ref_p (rhs))
    1423              :     return -1;
    1424              : 
    1425       195025 :   if (!ipa_load_from_parm_agg (fbi, info->descriptors, stmt, rhs, &index,
    1426              :                                offset_p, &size, by_ref_p))
    1427              :     return -1;
    1428              : 
    1429        55213 :   gcc_assert (!maybe_ne (tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (rhs))),
    1430              :                          size));
    1431        55213 :   if (!*by_ref_p)
    1432              :     {
    1433        27584 :       tree param_type = ipa_get_type (info, index);
    1434              : 
    1435        27584 :       if (!param_type || !AGGREGATE_TYPE_P (param_type))
    1436              :         return -1;
    1437              :     }
    1438        27629 :   else if (TREE_THIS_VOLATILE (rhs))
    1439              :     return -1;
    1440              : 
    1441        53764 :   return index;
    1442              : }
    1443              : 
    1444              : /* Walk pointer adjustemnts from OP (such as POINTER_PLUS and ADDR_EXPR)
    1445              :    to find original pointer.  Initialize RET to the pointer which results from
    1446              :    the walk.
    1447              :    If offset is known return true and initialize OFFSET_RET.  */
    1448              : 
    1449              : bool
    1450     16280718 : unadjusted_ptr_and_unit_offset (tree op, tree *ret, poly_int64 *offset_ret)
    1451              : {
    1452     16280718 :   poly_int64 offset = 0;
    1453     16280718 :   bool offset_known = true;
    1454     16280718 :   int i;
    1455              : 
    1456     21059060 :   for (i = 0; i < param_ipa_jump_function_lookups; i++)
    1457              :     {
    1458     21058046 :       if (TREE_CODE (op) == ADDR_EXPR)
    1459              :         {
    1460      1642838 :           poly_int64 extra_offset;
    1461      1642838 :           tree base = get_addr_base_and_unit_offset (TREE_OPERAND (op, 0),
    1462              :                                                      &extra_offset);
    1463      1642838 :           if (!base)
    1464              :             {
    1465        27719 :               base = get_base_address (TREE_OPERAND (op, 0));
    1466        27719 :               if (TREE_CODE (base) != MEM_REF)
    1467              :                 break;
    1468              :               offset_known = false;
    1469              :             }
    1470              :           else
    1471              :             {
    1472      1615119 :               if (TREE_CODE (base) != MEM_REF)
    1473              :                 break;
    1474       275323 :               offset += extra_offset;
    1475              :             }
    1476       275323 :           op = TREE_OPERAND (base, 0);
    1477       275323 :           if (mem_ref_offset (base).to_shwi (&extra_offset))
    1478       275323 :             offset += extra_offset;
    1479              :           else
    1480              :             offset_known = false;
    1481              :         }
    1482     19415208 :       else if (TREE_CODE (op) == SSA_NAME
    1483     19415208 :                && !SSA_NAME_IS_DEFAULT_DEF (op))
    1484              :         {
    1485      6684330 :           gimple *pstmt = SSA_NAME_DEF_STMT (op);
    1486              : 
    1487      6684330 :           if (gimple_assign_single_p (pstmt))
    1488      3261950 :             op = gimple_assign_rhs1 (pstmt);
    1489      3422380 :           else if (is_gimple_assign (pstmt)
    1490      3422380 :                    && gimple_assign_rhs_code (pstmt) == POINTER_PLUS_EXPR)
    1491              :             {
    1492      1241069 :               poly_int64 extra_offset = 0;
    1493      1241069 :               if (ptrdiff_tree_p (gimple_assign_rhs2 (pstmt),
    1494              :                   &extra_offset))
    1495      1241069 :                 offset += extra_offset;
    1496              :               else
    1497              :                 offset_known = false;
    1498      1241069 :               op = gimple_assign_rhs1 (pstmt);
    1499              :             }
    1500              :           else
    1501              :             break;
    1502              :         }
    1503              :       else
    1504              :         break;
    1505              :     }
    1506     16280718 :   *ret = op;
    1507     16280718 :   *offset_ret = offset;
    1508     16280718 :   return offset_known;
    1509              : }
    1510              : 
    1511              : /* Given that an actual argument is an SSA_NAME (given in NAME) and is a result
    1512              :    of an assignment statement STMT, try to determine whether we are actually
    1513              :    handling any of the following cases and construct an appropriate jump
    1514              :    function into JFUNC if so:
    1515              : 
    1516              :    1) The passed value is loaded from a formal parameter which is not a gimple
    1517              :    register (most probably because it is addressable, the value has to be
    1518              :    scalar) and we can guarantee the value has not changed.  This case can
    1519              :    therefore be described by a simple pass-through jump function.  For example:
    1520              : 
    1521              :       foo (int a)
    1522              :       {
    1523              :         int a.0;
    1524              : 
    1525              :         a.0_2 = a;
    1526              :         bar (a.0_2);
    1527              : 
    1528              :    2) The passed value can be described by a simple arithmetic pass-through
    1529              :    jump function. E.g.
    1530              : 
    1531              :       foo (int a)
    1532              :       {
    1533              :         int D.2064;
    1534              : 
    1535              :         D.2064_4 = a.1(D) + 4;
    1536              :         bar (D.2064_4);
    1537              : 
    1538              :    This case can also occur in combination of the previous one, e.g.:
    1539              : 
    1540              :       foo (int a, int z)
    1541              :       {
    1542              :         int a.0;
    1543              :         int D.2064;
    1544              : 
    1545              :         a.0_3 = a;
    1546              :         D.2064_4 = a.0_3 + 4;
    1547              :         foo (D.2064_4);
    1548              : 
    1549              :    3) The passed value is an address of an object within another one (which
    1550              :    also passed by reference).  Such situations are described by an ancestor
    1551              :    jump function and describe situations such as:
    1552              : 
    1553              :      B::foo() (struct B * const this)
    1554              :      {
    1555              :        struct A * D.1845;
    1556              : 
    1557              :        D.1845_2 = &this_1(D)->D.1748;
    1558              :        A::bar (D.1845_2);
    1559              : 
    1560              :    INFO is the structure describing individual parameters access different
    1561              :    stages of IPA optimizations.  PARMS_AINFO contains the information that is
    1562              :    only needed for intraprocedural analysis.  */
    1563              : 
    1564              : static void
    1565      1287831 : compute_complex_assign_jump_func (struct ipa_func_body_info *fbi,
    1566              :                                   class ipa_node_params *info,
    1567              :                                   struct ipa_jump_func *jfunc,
    1568              :                                   gcall *call, gimple *stmt, tree name,
    1569              :                                   tree param_type)
    1570              : {
    1571      1287831 :   HOST_WIDE_INT offset, size;
    1572      1287831 :   tree op1, tc_ssa, base, ssa;
    1573      1287831 :   bool reverse;
    1574      1287831 :   int index;
    1575              : 
    1576      1287831 :   op1 = gimple_assign_rhs1 (stmt);
    1577              : 
    1578      1287831 :   if (TREE_CODE (op1) == SSA_NAME)
    1579              :     {
    1580       408141 :       if (SSA_NAME_IS_DEFAULT_DEF (op1))
    1581       117760 :         index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op1));
    1582              :       else
    1583       290381 :         index = load_from_unmodified_param (fbi, info->descriptors,
    1584       290381 :                                             SSA_NAME_DEF_STMT (op1));
    1585              :       tc_ssa = op1;
    1586              :     }
    1587              :   else
    1588              :     {
    1589       879690 :       index = load_from_unmodified_param (fbi, info->descriptors, stmt);
    1590       879690 :       tc_ssa = gimple_assign_lhs (stmt);
    1591              :     }
    1592              : 
    1593      1287831 :   if (index >= 0)
    1594              :     {
    1595       119384 :       if (lto_variably_modified_type_p (TREE_TYPE (name)))
    1596      1113893 :         return;
    1597              : 
    1598       119338 :       switch (gimple_assign_rhs_class (stmt))
    1599              :         {
    1600        70723 :         case GIMPLE_BINARY_RHS:
    1601        70723 :           {
    1602        70723 :             tree op2 = gimple_assign_rhs2 (stmt);
    1603        70723 :             if (!is_gimple_ip_invariant (op2)
    1604        70723 :                 || ((TREE_CODE_CLASS (gimple_assign_rhs_code (stmt))
    1605              :                      != tcc_comparison)
    1606        33093 :                     && !useless_type_conversion_p (TREE_TYPE (name),
    1607        33093 :                                                    TREE_TYPE (op1))))
    1608              :               return;
    1609              : 
    1610        43928 :             ipa_set_jf_arith_pass_through (jfunc, index, op2,
    1611              :                                            gimple_assign_rhs_code (stmt),
    1612        43928 :                                            TREE_TYPE (name));
    1613        43928 :             break;
    1614              :           }
    1615         1218 :         case GIMPLE_SINGLE_RHS:
    1616         1218 :           {
    1617         1218 :             bool agg_p = parm_ref_data_pass_through_p (fbi, index, call,
    1618              :                                                        tc_ssa);
    1619         1218 :             ipa_set_jf_simple_pass_through (jfunc, index, agg_p);
    1620         1218 :             break;
    1621              :           }
    1622        47395 :         case GIMPLE_UNARY_RHS:
    1623        47395 :           if (!CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt)))
    1624         1002 :             ipa_set_jf_unary_pass_through (jfunc, index,
    1625              :                                            gimple_assign_rhs_code (stmt),
    1626         1002 :                                            TREE_TYPE (name));
    1627              :         default:;
    1628              :         }
    1629              :       return;
    1630              :     }
    1631              : 
    1632      1168447 :   if (TREE_CODE (op1) != ADDR_EXPR)
    1633              :     return;
    1634       249623 :   op1 = TREE_OPERAND (op1, 0);
    1635       249623 :   base = get_ref_base_and_extent_hwi (op1, &offset, &size, &reverse);
    1636       249623 :   offset_int mem_offset;
    1637       249623 :   if (!base
    1638       222101 :       || TREE_CODE (base) != MEM_REF
    1639       471724 :       || !mem_ref_offset (base).is_constant (&mem_offset))
    1640              :     return;
    1641       210552 :   offset += mem_offset.to_short_addr () * BITS_PER_UNIT;
    1642       210552 :   ssa = TREE_OPERAND (base, 0);
    1643       210552 :   if (TREE_CODE (ssa) != SSA_NAME
    1644       210552 :       || !SSA_NAME_IS_DEFAULT_DEF (ssa)
    1645       384589 :       || offset < 0)
    1646              :     return;
    1647              : 
    1648              :   /* Dynamic types are changed in constructors and destructors.  */
    1649       173938 :   index = ipa_get_param_decl_index (info, SSA_NAME_VAR (ssa));
    1650       173938 :   if (index >= 0 && param_type && POINTER_TYPE_P (param_type))
    1651       170768 :     ipa_set_ancestor_jf (jfunc, offset,  index,
    1652              :                          parm_ref_data_pass_through_p (fbi, index, call, ssa),
    1653              :                          false);
    1654              : }
    1655              : 
    1656              : /* Extract the base, offset and MEM_REF expression from a statement ASSIGN if
    1657              :    it looks like:
    1658              : 
    1659              :    iftmp.1_3 = &obj_2(D)->D.1762;
    1660              : 
    1661              :    The base of the MEM_REF must be a default definition SSA NAME of a
    1662              :    parameter.  Return NULL_TREE if it looks otherwise.  If case of success, the
    1663              :    whole MEM_REF expression is returned and the offset calculated from any
    1664              :    handled components and the MEM_REF itself is stored into *OFFSET.  The whole
    1665              :    RHS stripped off the ADDR_EXPR is stored into *OBJ_P.  */
    1666              : 
    1667              : static tree
    1668        16285 : get_ancestor_addr_info (gimple *assign, tree *obj_p, HOST_WIDE_INT *offset)
    1669              : {
    1670        16285 :   HOST_WIDE_INT size;
    1671        16285 :   tree expr, parm, obj;
    1672        16285 :   bool reverse;
    1673              : 
    1674        16285 :   if (!gimple_assign_single_p (assign))
    1675              :     return NULL_TREE;
    1676         9242 :   expr = gimple_assign_rhs1 (assign);
    1677              : 
    1678         9242 :   if (TREE_CODE (expr) != ADDR_EXPR)
    1679              :     return NULL_TREE;
    1680         4706 :   expr = TREE_OPERAND (expr, 0);
    1681         4706 :   obj = expr;
    1682         4706 :   expr = get_ref_base_and_extent_hwi (expr, offset, &size, &reverse);
    1683              : 
    1684         4706 :   offset_int mem_offset;
    1685         4706 :   if (!expr
    1686         4702 :       || TREE_CODE (expr) != MEM_REF
    1687         9408 :       || !mem_ref_offset (expr).is_constant (&mem_offset))
    1688              :     return NULL_TREE;
    1689         4702 :   parm = TREE_OPERAND (expr, 0);
    1690         4702 :   if (TREE_CODE (parm) != SSA_NAME
    1691         4702 :       || !SSA_NAME_IS_DEFAULT_DEF (parm)
    1692         5585 :       || TREE_CODE (SSA_NAME_VAR (parm)) != PARM_DECL)
    1693              :     return NULL_TREE;
    1694              : 
    1695          883 :   *offset += mem_offset.to_short_addr () * BITS_PER_UNIT;
    1696          883 :   *obj_p = obj;
    1697          883 :   return expr;
    1698              : }
    1699              : 
    1700              : 
    1701              : /* Given that an actual argument is an SSA_NAME that is a result of a phi
    1702              :    statement PHI, try to find out whether NAME is in fact a
    1703              :    multiple-inheritance typecast from a descendant into an ancestor of a formal
    1704              :    parameter and thus can be described by an ancestor jump function and if so,
    1705              :    write the appropriate function into JFUNC.
    1706              : 
    1707              :    Essentially we want to match the following pattern:
    1708              : 
    1709              :      if (obj_2(D) != 0B)
    1710              :        goto <bb 3>;
    1711              :      else
    1712              :        goto <bb 4>;
    1713              : 
    1714              :    <bb 3>:
    1715              :      iftmp.1_3 = &obj_2(D)->D.1762;
    1716              : 
    1717              :    <bb 4>:
    1718              :      # iftmp.1_1 = PHI <iftmp.1_3(3), 0B(2)>
    1719              :      D.1879_6 = middleman_1 (iftmp.1_1, i_5(D));
    1720              :      return D.1879_6;  */
    1721              : 
    1722              : static void
    1723        94868 : compute_complex_ancestor_jump_func (struct ipa_func_body_info *fbi,
    1724              :                                     class ipa_node_params *info,
    1725              :                                     struct ipa_jump_func *jfunc,
    1726              :                                     gcall *call, gphi *phi)
    1727              : {
    1728        94868 :   HOST_WIDE_INT offset;
    1729        94868 :   gimple *assign;
    1730        94868 :   basic_block phi_bb, assign_bb, cond_bb;
    1731        94868 :   tree tmp, parm, expr, obj;
    1732        94868 :   int index, i;
    1733              : 
    1734        94868 :   if (gimple_phi_num_args (phi) != 2)
    1735        94854 :     return;
    1736              : 
    1737        78752 :   if (integer_zerop (PHI_ARG_DEF (phi, 1)))
    1738         4507 :     tmp = PHI_ARG_DEF (phi, 0);
    1739        74245 :   else if (integer_zerop (PHI_ARG_DEF (phi, 0)))
    1740        13325 :     tmp = PHI_ARG_DEF (phi, 1);
    1741              :   else
    1742              :     return;
    1743        17832 :   if (TREE_CODE (tmp) != SSA_NAME
    1744        15466 :       || SSA_NAME_IS_DEFAULT_DEF (tmp)
    1745        15355 :       || !POINTER_TYPE_P (TREE_TYPE (tmp))
    1746        20621 :       || TREE_CODE (TREE_TYPE (TREE_TYPE (tmp))) != RECORD_TYPE)
    1747              :     return;
    1748              : 
    1749         1001 :   assign = SSA_NAME_DEF_STMT (tmp);
    1750         1001 :   assign_bb = gimple_bb (assign);
    1751        95435 :   if (!single_pred_p (assign_bb))
    1752              :     return;
    1753          581 :   expr = get_ancestor_addr_info (assign, &obj, &offset);
    1754          581 :   if (!expr)
    1755              :     return;
    1756           26 :   parm = TREE_OPERAND (expr, 0);
    1757           26 :   index = ipa_get_param_decl_index (info, SSA_NAME_VAR (parm));
    1758           26 :   if (index < 0)
    1759              :     return;
    1760              : 
    1761           26 :   cond_bb = single_pred (assign_bb);
    1762        94906 :   gcond *cond = safe_dyn_cast <gcond *> (*gsi_last_bb (cond_bb));
    1763           26 :   if (!cond
    1764           26 :       || gimple_cond_code (cond) != NE_EXPR
    1765           26 :       || gimple_cond_lhs (cond) != parm
    1766           14 :       || !integer_zerop (gimple_cond_rhs (cond)))
    1767              :     return;
    1768              : 
    1769           14 :   phi_bb = gimple_bb (phi);
    1770           42 :   for (i = 0; i < 2; i++)
    1771              :     {
    1772           28 :       basic_block pred = EDGE_PRED (phi_bb, i)->src;
    1773           28 :       if (pred != assign_bb && pred != cond_bb)
    1774              :         return;
    1775              :     }
    1776              : 
    1777           14 :   ipa_set_ancestor_jf (jfunc, offset, index,
    1778              :                        parm_ref_data_pass_through_p (fbi, index, call, parm),
    1779              :                        true);
    1780              : }
    1781              : 
    1782              : /* Inspect the given TYPE and return true iff it has the same structure (the
    1783              :    same number of fields of the same types) as a C++ member pointer.  If
    1784              :    METHOD_PTR and DELTA are non-NULL, store the trees representing the
    1785              :    corresponding fields there.  */
    1786              : 
    1787              : static bool
    1788          894 : type_like_member_ptr_p (tree type, tree *method_ptr, tree *delta)
    1789              : {
    1790          894 :   tree fld;
    1791              : 
    1792          894 :   if (TREE_CODE (type) != RECORD_TYPE)
    1793              :     return false;
    1794              : 
    1795          894 :   fld = TYPE_FIELDS (type);
    1796          894 :   if (!fld || !POINTER_TYPE_P (TREE_TYPE (fld))
    1797          894 :       || TREE_CODE (TREE_TYPE (TREE_TYPE (fld))) != METHOD_TYPE
    1798         1788 :       || !tree_fits_uhwi_p (DECL_FIELD_OFFSET (fld)))
    1799              :     return false;
    1800              : 
    1801          894 :   if (method_ptr)
    1802          894 :     *method_ptr = fld;
    1803              : 
    1804          894 :   fld = DECL_CHAIN (fld);
    1805          894 :   if (!fld || INTEGRAL_TYPE_P (fld)
    1806         1788 :       || !tree_fits_uhwi_p (DECL_FIELD_OFFSET (fld)))
    1807              :     return false;
    1808          894 :   if (delta)
    1809          894 :     *delta = fld;
    1810              : 
    1811          894 :   if (DECL_CHAIN (fld))
    1812            0 :     return false;
    1813              : 
    1814              :   return true;
    1815              : }
    1816              : 
    1817              : /* If RHS is an SSA_NAME and it is defined by a simple copy assign statement,
    1818              :    return the rhs of its defining statement, and this statement is stored in
    1819              :    *RHS_STMT.  Otherwise return RHS as it is.  */
    1820              : 
    1821              : static inline tree
    1822       134693 : get_ssa_def_if_simple_copy (tree rhs, gimple **rhs_stmt)
    1823              : {
    1824       183683 :   while (TREE_CODE (rhs) == SSA_NAME && !SSA_NAME_IS_DEFAULT_DEF (rhs))
    1825              :     {
    1826        99144 :       gimple *def_stmt = SSA_NAME_DEF_STMT (rhs);
    1827              : 
    1828        99144 :       if (gimple_assign_single_p (def_stmt))
    1829        48990 :         rhs = gimple_assign_rhs1 (def_stmt);
    1830              :       else
    1831              :         break;
    1832        48990 :       *rhs_stmt = def_stmt;
    1833              :     }
    1834       134693 :   return rhs;
    1835              : }
    1836              : 
    1837              : /* Simple linked list, describing contents of an aggregate before call.  */
    1838              : 
    1839              : struct ipa_known_agg_contents_list
    1840              : {
    1841              :   /* Offset and size of the described part of the aggregate.  */
    1842              :   HOST_WIDE_INT offset, size;
    1843              : 
    1844              :   /* Type of the described part of the aggregate.  */
    1845              :   tree type;
    1846              : 
    1847              :   /* Known constant value or jump function data describing contents.  */
    1848              :   struct ipa_load_agg_data value;
    1849              : 
    1850              :   /* Pointer to the next structure in the list.  */
    1851              :   struct ipa_known_agg_contents_list *next;
    1852              : };
    1853              : 
    1854              : /* Add an aggregate content item into a linked list of
    1855              :    ipa_known_agg_contents_list structure, in which all elements
    1856              :    are sorted ascendingly by offset.  */
    1857              : 
    1858              : static inline void
    1859      2868248 : add_to_agg_contents_list (struct ipa_known_agg_contents_list **plist,
    1860              :                           struct ipa_known_agg_contents_list *item)
    1861              : {
    1862      2868248 :   struct ipa_known_agg_contents_list *list = *plist;
    1863              : 
    1864      5266436 :   for (; list; list = list->next)
    1865              :     {
    1866      3993612 :       if (list->offset >= item->offset)
    1867              :         break;
    1868              : 
    1869      2398188 :       plist = &list->next;
    1870              :     }
    1871              : 
    1872      2868248 :   item->next = list;
    1873      2868248 :   *plist = item;
    1874              : }
    1875              : 
    1876              : /* Check whether a given aggregate content is clobbered by certain element in
    1877              :    a linked list of ipa_known_agg_contents_list.  */
    1878              : 
    1879              : static inline bool
    1880      1116517 : clobber_by_agg_contents_list_p (struct ipa_known_agg_contents_list *list,
    1881              :                                 struct ipa_known_agg_contents_list *item)
    1882              : {
    1883      2355349 :   for (; list; list = list->next)
    1884              :     {
    1885      1894855 :       if (list->offset >= item->offset)
    1886       643112 :         return list->offset < item->offset + item->size;
    1887              : 
    1888      1251743 :       if (list->offset + list->size > item->offset)
    1889              :         return true;
    1890              :     }
    1891              : 
    1892              :   return false;
    1893              : }
    1894              : 
    1895              : /* Build aggregate jump function from LIST, assuming there are exactly
    1896              :    VALUE_COUNT entries there and that offset of the passed argument
    1897              :    is ARG_OFFSET and store it into JFUNC.  */
    1898              : 
    1899              : static void
    1900       367743 : build_agg_jump_func_from_list (struct ipa_known_agg_contents_list *list,
    1901              :                                int value_count, HOST_WIDE_INT arg_offset,
    1902              :                                struct ipa_jump_func *jfunc)
    1903              : {
    1904       367743 :   vec_safe_reserve (jfunc->agg.items, value_count, true);
    1905      1789483 :   for (; list; list = list->next)
    1906              :     {
    1907      1053997 :       struct ipa_agg_jf_item item;
    1908      1053997 :       tree operand = list->value.pass_through.operand;
    1909              : 
    1910      1053997 :       if (list->value.pass_through.formal_id >= 0)
    1911              :         {
    1912              :           /* Content value is derived from some formal parameter.  */
    1913        95676 :           if (list->value.offset >= 0)
    1914              :             item.jftype = IPA_JF_LOAD_AGG;
    1915              :           else
    1916        43797 :             item.jftype = IPA_JF_PASS_THROUGH;
    1917              : 
    1918        95676 :           item.value.load_agg = list->value;
    1919        95676 :           if (operand)
    1920         9648 :             item.value.pass_through.operand
    1921         9648 :               = unshare_expr_without_location (operand);
    1922              :         }
    1923       958321 :       else if (operand)
    1924              :         {
    1925              :           /* Content value is known constant.  */
    1926       958321 :           item.jftype = IPA_JF_CONST;
    1927       958321 :           item.value.constant = unshare_expr_without_location (operand);
    1928              :         }
    1929              :       else
    1930            0 :         continue;
    1931              : 
    1932      1053997 :       item.type = list->type;
    1933      1053997 :       gcc_assert (tree_to_shwi (TYPE_SIZE (list->type)) == list->size);
    1934              : 
    1935      1053997 :       item.offset = list->offset - arg_offset;
    1936      1053997 :       gcc_assert ((item.offset % BITS_PER_UNIT) == 0);
    1937              : 
    1938      1053997 :       jfunc->agg.items->quick_push (item);
    1939              :     }
    1940       367743 : }
    1941              : 
    1942              : /* Given an assignment statement STMT, try to collect information into
    1943              :    AGG_VALUE that will be used to construct jump function for RHS of the
    1944              :    assignment, from which content value of an aggregate part comes.
    1945              : 
    1946              :    Besides constant and simple pass-through jump functions, also try to
    1947              :    identify whether it matches the following pattern that can be described by
    1948              :    a load-value-from-aggregate jump function, which is a derivative of simple
    1949              :    pass-through jump function.
    1950              : 
    1951              :      foo (int *p)
    1952              :      {
    1953              :        ...
    1954              : 
    1955              :        *(q_5 + 4) = *(p_3(D) + 28) op 1;
    1956              :        bar (q_5);
    1957              :      }
    1958              : 
    1959              :    Here IPA_LOAD_AGG_DATA data structure is informative enough to describe
    1960              :    constant, simple pass-through and load-vale-from-aggregate. If value
    1961              :    is constant, it will be kept in field OPERAND, and field FORMAL_ID is
    1962              :    set to -1. For simple pass-through and load-value-from-aggregate, field
    1963              :    FORMAL_ID specifies the related formal parameter index, and field
    1964              :    OFFSET can be used to distinguish them, -1 means simple pass-through,
    1965              :    otherwise means load-value-from-aggregate.  */
    1966              : 
    1967              : static void
    1968      1816533 : analyze_agg_content_value (struct ipa_func_body_info *fbi,
    1969              :                            struct ipa_load_agg_data *agg_value,
    1970              :                            gimple *stmt)
    1971              : {
    1972      1816533 :   tree lhs = gimple_assign_lhs (stmt);
    1973      1816533 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    1974      1816533 :   enum tree_code code;
    1975      1816533 :   int index = -1;
    1976              : 
    1977              :   /* Initialize jump function data for the aggregate part.  */
    1978      1816533 :   memset (agg_value, 0, sizeof (*agg_value));
    1979      1816533 :   agg_value->pass_through.operation = NOP_EXPR;
    1980      1816533 :   agg_value->pass_through.formal_id = -1;
    1981      1816533 :   agg_value->offset = -1;
    1982              : 
    1983      1816533 :   if (AGGREGATE_TYPE_P (TREE_TYPE (lhs))  /* TODO: Support aggregate type.  */
    1984      1618713 :       || TREE_THIS_VOLATILE (lhs)
    1985      1618037 :       || TREE_CODE (lhs) == BIT_FIELD_REF
    1986      1618029 :       || contains_bitfld_component_ref_p (lhs))
    1987              :     return;
    1988              : 
    1989              :   /* Skip SSA copies.  */
    1990      1906882 :   while (gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS)
    1991              :     {
    1992      1816202 :       if (TREE_CODE (rhs1) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (rhs1))
    1993              :         break;
    1994              : 
    1995       391894 :       stmt = SSA_NAME_DEF_STMT (rhs1);
    1996       391894 :       if (!is_gimple_assign (stmt))
    1997              :         break;
    1998              : 
    1999       298271 :       lhs = gimple_assign_lhs (stmt);
    2000       298271 :       rhs1 = gimple_assign_rhs1 (stmt);
    2001              :     }
    2002              : 
    2003      1608611 :   if (gphi *phi = dyn_cast<gphi *> (stmt))
    2004              :     {
    2005              :       /* Also special case like the following (a is a formal parameter):
    2006              : 
    2007              :            _12 = *a_11(D).dim[0].stride;
    2008              :            ...
    2009              :            # iftmp.22_9 = PHI <_12(2), 1(3)>
    2010              :            ...
    2011              :            parm.6.dim[0].stride = iftmp.22_9;
    2012              :            ...
    2013              :            __x_MOD_foo (&parm.6, b_31(D));
    2014              : 
    2015              :          The aggregate function describing parm.6.dim[0].stride is encoded as a
    2016              :          PASS-THROUGH jump function with ASSERT_EXPR operation with operand 1
    2017              :          (the constant from the PHI node).  */
    2018              : 
    2019        36080 :       if (gimple_phi_num_args (phi) != 2
    2020        36080 :           || lto_variably_modified_type_p (TREE_TYPE (lhs)))
    2021              :         return;
    2022        29035 :       tree arg0 = gimple_phi_arg_def (phi, 0);
    2023        29035 :       tree arg1 = gimple_phi_arg_def (phi, 1);
    2024        29035 :       tree operand;
    2025              : 
    2026        29035 :       if (is_gimple_ip_invariant (arg1))
    2027              :         {
    2028              :           operand = arg1;
    2029              :           rhs1 = arg0;
    2030              :         }
    2031        24069 :       else if (is_gimple_ip_invariant (arg0))
    2032              :         {
    2033              :           operand = arg0;
    2034              :           rhs1 = arg1;
    2035              :         }
    2036              :       else
    2037              :         return;
    2038              : 
    2039        11216 :       rhs1 = get_ssa_def_if_simple_copy (rhs1, &stmt);
    2040        11216 :       if (!is_gimple_assign (stmt))
    2041              :         return;
    2042              : 
    2043         5777 :       code = ASSERT_EXPR;
    2044         5777 :       agg_value->pass_through.operand = operand;
    2045         5777 :       agg_value->pass_through.op_type = TREE_TYPE (lhs);
    2046              :     }
    2047      1572531 :   else if (is_gimple_assign (stmt))
    2048              :     {
    2049      1514988 :       code = gimple_assign_rhs_code (stmt);
    2050      1514988 :       switch (gimple_assign_rhs_class (stmt))
    2051              :         {
    2052      1424308 :         case GIMPLE_SINGLE_RHS:
    2053      1424308 :           if (is_gimple_ip_invariant (rhs1))
    2054              :             {
    2055      1018669 :               agg_value->pass_through.operand = rhs1;
    2056      1018669 :               return;
    2057              :             }
    2058              :           code = NOP_EXPR;
    2059              :           break;
    2060              : 
    2061        29577 :         case GIMPLE_UNARY_RHS:
    2062              :           /* NOTE: A GIMPLE_UNARY_RHS operation might not be tcc_unary
    2063              :              (truth_not_expr is example), GIMPLE_BINARY_RHS does not imply
    2064              :              tcc_binary, this subtleness is somewhat misleading.
    2065              : 
    2066              :              Since tcc_unary is widely used in IPA-CP code to check an operation
    2067              :              with one operand, here we only allow tc_unary operation to avoid
    2068              :              possible problem.  Then we can use (opclass == tc_unary) or not to
    2069              :              distinguish unary and binary.  */
    2070        29577 :           if (TREE_CODE_CLASS (code) != tcc_unary || CONVERT_EXPR_CODE_P (code)
    2071        32242 :               || lto_variably_modified_type_p (TREE_TYPE (lhs)))
    2072              :             return;
    2073              : 
    2074         2665 :           rhs1 = get_ssa_def_if_simple_copy (rhs1, &stmt);
    2075         2665 :           agg_value->pass_through.op_type = TREE_TYPE (lhs);
    2076         2665 :           break;
    2077              : 
    2078        60410 :         case GIMPLE_BINARY_RHS:
    2079        60410 :           {
    2080        60410 :             gimple *rhs1_stmt = stmt;
    2081        60410 :             gimple *rhs2_stmt = stmt;
    2082        60410 :             tree rhs2 = gimple_assign_rhs2 (stmt);
    2083              : 
    2084        60410 :             if (lto_variably_modified_type_p (TREE_TYPE (lhs)))
    2085        31155 :               return;
    2086              : 
    2087        60406 :             rhs1 = get_ssa_def_if_simple_copy (rhs1, &rhs1_stmt);
    2088        60406 :             rhs2 = get_ssa_def_if_simple_copy (rhs2, &rhs2_stmt);
    2089              : 
    2090        60406 :             if (is_gimple_ip_invariant (rhs2))
    2091              :               {
    2092        29255 :                 agg_value->pass_through.operand = rhs2;
    2093        29255 :                 agg_value->pass_through.op_type = TREE_TYPE (lhs);
    2094        29255 :                 stmt = rhs1_stmt;
    2095              :               }
    2096        31151 :             else if (is_gimple_ip_invariant (rhs1))
    2097              :               {
    2098         2268 :                 if (TREE_CODE_CLASS (code) == tcc_comparison)
    2099            0 :                   code = swap_tree_comparison (code);
    2100         2268 :                 else if (!commutative_tree_code (code))
    2101              :                   return;
    2102              : 
    2103            0 :                 agg_value->pass_through.operand = rhs1;
    2104            0 :                 agg_value->pass_through.op_type = TREE_TYPE (lhs);
    2105            0 :                 stmt = rhs2_stmt;
    2106            0 :                 rhs1 = rhs2;
    2107              :               }
    2108              :             else
    2109              :               return;
    2110              : 
    2111        29255 :             if (TREE_CODE_CLASS (code) != tcc_comparison
    2112        58044 :                 && !useless_type_conversion_p (TREE_TYPE (lhs),
    2113        28789 :                                                TREE_TYPE (rhs1)))
    2114              :               return;
    2115              :           }
    2116        29255 :           break;
    2117              : 
    2118              :         default:
    2119              :           return;
    2120              :         }
    2121              :     }
    2122              :   else
    2123              :     return;
    2124              : 
    2125       443336 :   if (TREE_CODE (rhs1) != SSA_NAME)
    2126       380718 :     index = load_from_unmodified_param_or_agg (fbi, fbi->info, stmt,
    2127              :                                                &agg_value->offset,
    2128              :                                                &agg_value->by_ref);
    2129        62618 :   else if (SSA_NAME_IS_DEFAULT_DEF (rhs1))
    2130        47598 :     index = ipa_get_param_decl_index (fbi->info, SSA_NAME_VAR (rhs1));
    2131              : 
    2132       428316 :   if (index >= 0)
    2133              :     {
    2134        97848 :       if (agg_value->offset >= 0)
    2135        53764 :         agg_value->type = TREE_TYPE (rhs1);
    2136        97848 :       agg_value->pass_through.formal_id = index;
    2137        97848 :       agg_value->pass_through.operation = code;
    2138              :     }
    2139              :   else
    2140       345488 :     agg_value->pass_through.operand = NULL_TREE;
    2141              : }
    2142              : 
    2143              : /* If STMT is a memory store to the object whose address is BASE, extract
    2144              :    information (offset, size, and value) into CONTENT, and return true,
    2145              :    otherwise we conservatively assume the whole object is modified with
    2146              :    unknown content, and return false.  CHECK_REF means that access to object
    2147              :    is expected to be in form of MEM_REF expression.  */
    2148              : 
    2149              : static bool
    2150      2977272 : extract_mem_content (struct ipa_func_body_info *fbi,
    2151              :                      gimple *stmt, tree base, bool check_ref,
    2152              :                      struct ipa_known_agg_contents_list *content)
    2153              : {
    2154      2977272 :   HOST_WIDE_INT lhs_offset, lhs_size;
    2155      2977272 :   bool reverse;
    2156              : 
    2157      2977272 :   if (!is_gimple_assign (stmt))
    2158              :     return false;
    2159              : 
    2160      1935570 :   tree lhs = gimple_assign_lhs (stmt);
    2161      1935570 :   tree lhs_base = get_ref_base_and_extent_hwi (lhs, &lhs_offset, &lhs_size,
    2162              :                                                &reverse);
    2163      1935570 :   if (!lhs_base)
    2164              :     return false;
    2165              : 
    2166      1933880 :   if (check_ref)
    2167              :     {
    2168       154161 :       if (TREE_CODE (lhs_base) != MEM_REF
    2169       122473 :           || TREE_OPERAND (lhs_base, 0) != base
    2170       201740 :           || !integer_zerop (TREE_OPERAND (lhs_base, 1)))
    2171              :         return false;
    2172              :     }
    2173      1779719 :   else if (lhs_base != base)
    2174              :     return false;
    2175              : 
    2176      1816533 :   content->offset = lhs_offset;
    2177      1816533 :   content->size = lhs_size;
    2178      1816533 :   content->type = TREE_TYPE (lhs);
    2179      1816533 :   content->next = NULL;
    2180              : 
    2181      1816533 :   analyze_agg_content_value (fbi, &content->value, stmt);
    2182      1816533 :   return true;
    2183              : }
    2184              : 
    2185              : /* Traverse statements from CALL backwards, scanning whether an aggregate given
    2186              :    in ARG is filled in constants or values that are derived from caller's
    2187              :    formal parameter in the way described by some kinds of jump functions.  FBI
    2188              :    is the context of the caller function for interprocedural analysis.  ARG can
    2189              :    either be an aggregate expression or a pointer to an aggregate.  ARG_TYPE is
    2190              :    the type of the aggregate, JFUNC is the jump function for the aggregate.  */
    2191              : 
    2192              : static void
    2193      3532797 : determine_known_aggregate_parts (struct ipa_func_body_info *fbi,
    2194              :                                  gcall *call, tree arg,
    2195              :                                  tree arg_type,
    2196              :                                  struct ipa_jump_func *jfunc)
    2197              : {
    2198      3532797 :   struct ipa_known_agg_contents_list *list = NULL, *all_list = NULL;
    2199      3532797 :   bitmap visited = NULL;
    2200      3532797 :   int item_count = 0, value_count = 0;
    2201      3532797 :   HOST_WIDE_INT arg_offset, arg_size;
    2202      3532797 :   tree arg_base;
    2203      3532797 :   bool check_ref, by_ref;
    2204      3532797 :   ao_ref r;
    2205      3532797 :   int max_agg_items = opt_for_fn (fbi->node->decl, param_ipa_max_agg_items);
    2206              : 
    2207      3532797 :   if (max_agg_items == 0)
    2208       866195 :     return;
    2209              : 
    2210              :   /* The function operates in three stages.  First, we prepare check_ref, r,
    2211              :      arg_base and arg_offset based on what is actually passed as an actual
    2212              :      argument.  */
    2213              : 
    2214      3532797 :   if (POINTER_TYPE_P (arg_type))
    2215              :     {
    2216      3145742 :       by_ref = true;
    2217      3145742 :       if (TREE_CODE (arg) == SSA_NAME)
    2218              :         {
    2219      1145043 :           tree type_size;
    2220      1145043 :           if (!tree_fits_uhwi_p (TYPE_SIZE (TREE_TYPE (arg_type)))
    2221      1145043 :               || !POINTER_TYPE_P (TREE_TYPE (arg)))
    2222              :             return;
    2223       821345 :           check_ref = true;
    2224       821345 :           arg_base = arg;
    2225       821345 :           arg_offset = 0;
    2226       821345 :           type_size = TYPE_SIZE (TREE_TYPE (arg_type));
    2227       821345 :           arg_size = tree_to_uhwi (type_size);
    2228       821345 :           ao_ref_init_from_ptr_and_size (&r, arg_base, NULL_TREE);
    2229              :         }
    2230      2000699 :       else if (TREE_CODE (arg) == ADDR_EXPR)
    2231              :         {
    2232      1923700 :           bool reverse;
    2233              : 
    2234      1923700 :           arg = TREE_OPERAND (arg, 0);
    2235      1923700 :           arg_base = get_ref_base_and_extent_hwi (arg, &arg_offset,
    2236              :                                                   &arg_size, &reverse);
    2237      1923700 :           if (!arg_base)
    2238       465421 :             return;
    2239      1922481 :           if (DECL_P (arg_base))
    2240              :             {
    2241      1458279 :               check_ref = false;
    2242      1458279 :               ao_ref_init (&r, arg_base);
    2243              :             }
    2244              :           else
    2245              :             return;
    2246              :         }
    2247              :       else
    2248              :         return;
    2249              :     }
    2250              :   else
    2251              :     {
    2252       387055 :       bool reverse;
    2253              : 
    2254       387055 :       gcc_checking_assert (AGGREGATE_TYPE_P (TREE_TYPE (arg)));
    2255              : 
    2256       387055 :       by_ref = false;
    2257       387055 :       check_ref = false;
    2258       387055 :       arg_base = get_ref_base_and_extent_hwi (arg, &arg_offset,
    2259              :                                               &arg_size, &reverse);
    2260       387055 :       if (!arg_base)
    2261           77 :         return;
    2262              : 
    2263       386978 :       ao_ref_init (&r, arg);
    2264              :     }
    2265              : 
    2266              :   /* Second stage traverses virtual SSA web backwards starting from the call
    2267              :      statement, only looks at individual dominating virtual operand (its
    2268              :      definition dominates the call), as long as it is confident that content
    2269              :      of the aggregate is affected by definition of the virtual operand, it
    2270              :      builds a sorted linked list of ipa_agg_jf_list describing that.  */
    2271              : 
    2272      5333204 :   for (tree dom_vuse = gimple_vuse (call);
    2273     26562336 :        dom_vuse && fbi->aa_walk_budget > 0;)
    2274              :     {
    2275     26034273 :       gimple *stmt = SSA_NAME_DEF_STMT (dom_vuse);
    2276              : 
    2277     26034273 :       if (gphi *phi = dyn_cast <gphi *> (stmt))
    2278              :         {
    2279      2705720 :           dom_vuse = get_continuation_for_phi (phi, &r, true,
    2280      1352860 :                                                fbi->aa_walk_budget,
    2281              :                                                &visited, NULL, NULL);
    2282      1352860 :           continue;
    2283              :         }
    2284              : 
    2285     24681413 :       fbi->aa_walk_budget--;
    2286     24681413 :       if (stmt_may_clobber_ref_p_1 (stmt, &r))
    2287              :         {
    2288      2977272 :           struct ipa_known_agg_contents_list *content
    2289      2977272 :                         = XALLOCA (struct ipa_known_agg_contents_list);
    2290              : 
    2291      2977272 :           if (!extract_mem_content (fbi, stmt, arg_base, check_ref, content))
    2292              :             break;
    2293              : 
    2294              :           /* Now we get a dominating virtual operand, and need to check
    2295              :              whether its value is clobbered any other dominating one.  */
    2296      1816533 :           if ((content->value.pass_through.formal_id >= 0
    2297      1718685 :                || content->value.pass_through.operand)
    2298      1116517 :               && !clobber_by_agg_contents_list_p (all_list, content)
    2299              :               /* Since IPA-CP stores results with unsigned int offsets, we can
    2300              :                  discard those which would not fit now before we stream them to
    2301              :                  WPA.  */
    2302      2870668 :               && (content->offset + content->size - arg_offset
    2303              :                   <= (HOST_WIDE_INT) UINT_MAX * BITS_PER_UNIT))
    2304              :             {
    2305      1053997 :               struct ipa_known_agg_contents_list *copy
    2306      1053997 :                         = XALLOCA (struct ipa_known_agg_contents_list);
    2307              : 
    2308              :               /* Add to the list consisting of only dominating virtual
    2309              :                  operands, whose definitions can finally reach the call.  */
    2310      1053997 :               add_to_agg_contents_list (&list, (*copy = *content, copy));
    2311              : 
    2312      1053997 :               if (++value_count == max_agg_items)
    2313              :                 break;
    2314              :             }
    2315              : 
    2316              :           /* Add to the list consisting of all dominating virtual operands.  */
    2317      1814251 :           add_to_agg_contents_list (&all_list, content);
    2318              : 
    2319      1814251 :           if (++item_count == 2 * max_agg_items)
    2320              :             break;
    2321              :         }
    2322     46060062 :       dom_vuse = gimple_vuse (stmt);
    2323              :    }
    2324              : 
    2325      2666602 :   if (visited)
    2326       670196 :     BITMAP_FREE (visited);
    2327              : 
    2328              :   /* Third stage just goes over the list and creates an appropriate vector of
    2329              :      ipa_agg_jf_item structures out of it, of course only if there are
    2330              :      any meaningful items to begin with.  */
    2331              : 
    2332      2666602 :   if (value_count)
    2333              :     {
    2334       367743 :       jfunc->agg.by_ref = by_ref;
    2335       367743 :       build_agg_jump_func_from_list (list, value_count, arg_offset, jfunc);
    2336              :     }
    2337              : }
    2338              : 
    2339              : 
    2340              : /* Return the Ith param type of callee associated with call graph
    2341              :    edge E.  */
    2342              : 
    2343              : tree
    2344      6493142 : ipa_get_callee_param_type (struct cgraph_edge *e, int i)
    2345              : {
    2346      6493142 :   int n;
    2347      6493142 :   tree type = (e->callee
    2348      6493142 :                ? TREE_TYPE (e->callee->decl)
    2349      6493142 :                : gimple_call_fntype (e->call_stmt));
    2350      6493142 :   tree t = TYPE_ARG_TYPES (type);
    2351              : 
    2352     13428179 :   for (n = 0; n < i; n++)
    2353              :     {
    2354      7189617 :       if (!t)
    2355              :         break;
    2356      6935037 :       t = TREE_CHAIN (t);
    2357              :     }
    2358      6493142 :   if (t && t != void_list_node)
    2359      6143639 :     return TREE_VALUE (t);
    2360       349503 :   if (!e->callee)
    2361              :     return NULL;
    2362       325416 :   t = DECL_ARGUMENTS (e->callee->decl);
    2363       852262 :   for (n = 0; n < i; n++)
    2364              :     {
    2365       807689 :       if (!t)
    2366              :         return NULL;
    2367       526846 :       t = TREE_CHAIN (t);
    2368              :     }
    2369        44573 :   if (t)
    2370         2192 :     return TREE_TYPE (t);
    2371              :   return NULL;
    2372              : }
    2373              : 
    2374              : /* Return a pointer to an ipa_vr just like TMP, but either find it in
    2375              :    ipa_vr_hash_table or allocate it in GC memory.  */
    2376              : 
    2377              : static ipa_vr *
    2378      6001842 : ipa_get_value_range_1 (const vrange &tmp)
    2379              : {
    2380      6001842 :   inchash::hash hstate;
    2381      6001842 :   inchash::add_vrange (tmp, hstate);
    2382      6001842 :   hashval_t hash = hstate.end ();
    2383      6001842 :   ipa_vr **slot = ipa_vr_hash_table->find_slot_with_hash (&tmp, hash, INSERT);
    2384      6001842 :   if (*slot)
    2385              :     return *slot;
    2386              : 
    2387      1571910 :   ipa_vr *vr = new (ggc_alloc<ipa_vr> ()) ipa_vr (tmp);
    2388      1571910 :   *slot = vr;
    2389      1571910 :   return vr;
    2390              : }
    2391              : 
    2392              : /* Wrapper around ipa_get_value_range_1 which will remove any local pointer
    2393              :    information from prange.  */
    2394              : 
    2395              : static ipa_vr *
    2396      6001842 : ipa_get_value_range (const vrange &tmp)
    2397              : {
    2398              :   /* A points-to that names something only invariant within the caller --
    2399              :      the address of one of its locals, say -- must not travel to the callee.
    2400              :      Same restriction as ipa_record_return_value_range_1; see PR125857.
    2401              :      Drop just the points-to rather than the whole range, as the bounds and
    2402              :      the bitmask remain valid.  */
    2403      6001842 :   if (is_a <prange> (tmp))
    2404              :     {
    2405      3647460 :       prange pr = as_a <prange> (tmp);
    2406      3647460 :       if (pr.clear_function_local_addr ())
    2407              :         {
    2408      1051458 :           if (dump_file && (dump_flags & TDF_DETAILS))
    2409              :             {
    2410           76 :               fprintf (dump_file, "Dropping function-local address from ");
    2411           76 :               tmp.dump (dump_file);
    2412           76 :               fprintf (dump_file, "\n");
    2413              :             }
    2414              :         }
    2415      3647460 :       return ipa_get_value_range_1 (pr);
    2416      3647460 :     }
    2417      2354382 :   return ipa_get_value_range_1 (tmp);
    2418              : }
    2419              : 
    2420              : /* Assign to JF a pointer to a range just like TMP but either fetch a
    2421              :    copy from ipa_vr_hash_table or allocate a new on in GC memory.  */
    2422              : 
    2423              : static void
    2424      5229416 : ipa_set_jfunc_vr (ipa_jump_func *jf, const vrange &tmp)
    2425              : {
    2426      1980020 :   jf->m_vr = ipa_get_value_range (tmp);
    2427            0 : }
    2428              : 
    2429              : static void
    2430       613346 : ipa_set_jfunc_vr (ipa_jump_func *jf, const ipa_vr &vr)
    2431              : {
    2432       613346 :   value_range tmp;
    2433       613346 :   vr.get_vrange (tmp);
    2434       613346 :   ipa_set_jfunc_vr (jf, tmp);
    2435       613346 : }
    2436              : 
    2437              : /* Given VAL that conforms to is_gimple_ip_invariant, produce a VRANGE that
    2438              :    represents it as a range.  CONTEXT_NODE is the call graph node representing
    2439              :    the function for which optimization flags should be evaluated.  */
    2440              : 
    2441              : void
    2442      1713545 : ipa_get_range_from_ip_invariant (vrange &r, tree val, cgraph_node *context_node)
    2443              : {
    2444      1713545 :   if (TREE_CODE (val) == ADDR_EXPR)
    2445              :     {
    2446          999 :       symtab_node *symbol;
    2447          999 :       tree base = TREE_OPERAND (val, 0);
    2448          999 :       if (!DECL_P (base))
    2449              :         {
    2450          182 :           r.set_varying (TREE_TYPE (val));
    2451          182 :           return;
    2452              :         }
    2453          817 :       if (!decl_in_symtab_p (base))
    2454              :         {
    2455            0 :           r.set_nonzero (TREE_TYPE (val));
    2456            0 :           return;
    2457              :         }
    2458          817 :       if (!(symbol = symtab_node::get (base)))
    2459              :         {
    2460            0 :           r.set_varying (TREE_TYPE (val));
    2461            0 :           return;
    2462              :         }
    2463              : 
    2464          817 :       bool delete_null_pointer_checks
    2465          817 :         = opt_for_fn (context_node->decl, flag_delete_null_pointer_checks);
    2466          817 :       if (symbol->nonzero_address (delete_null_pointer_checks))
    2467          817 :         r.set_nonzero (TREE_TYPE (val));
    2468              :       else
    2469            0 :         r.set_varying (TREE_TYPE (val));
    2470              :     }
    2471              :   else
    2472      1712546 :     r.set (val, val);
    2473              : }
    2474              : 
    2475              : /* If T is an SSA_NAME that is the result of a simple type conversion statement
    2476              :    from an integer type to another integer type which is known to be able to
    2477              :    represent the values the operand of the conversion can hold, return the
    2478              :    operand of that conversion, otherwise return T.  */
    2479              : 
    2480              : static tree
    2481      6493142 : skip_a_safe_conversion_op (tree t)
    2482              : {
    2483      6493142 :   if (TREE_CODE (t) != SSA_NAME
    2484      6493142 :       || SSA_NAME_IS_DEFAULT_DEF (t))
    2485              :     return t;
    2486              : 
    2487      1591688 :   gimple *def = SSA_NAME_DEF_STMT (t);
    2488      1591688 :   if (!is_gimple_assign (def)
    2489      1313070 :       || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def))
    2490       258808 :       || !INTEGRAL_TYPE_P (TREE_TYPE (t))
    2491      1785258 :       || !INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (def))))
    2492              :     return t;
    2493              : 
    2494       185516 :   tree rhs1 = gimple_assign_rhs1 (def);
    2495       185516 :   if (TYPE_PRECISION (TREE_TYPE (t))
    2496       185516 :       >= TYPE_PRECISION (TREE_TYPE (rhs1)))
    2497              :     return gimple_assign_rhs1 (def);
    2498              : 
    2499         9371 :   value_range vr (TREE_TYPE (rhs1));
    2500        18742 :   if (!get_range_query (cfun)->range_of_expr (vr, rhs1, def)
    2501         9371 :       || vr.undefined_p ())
    2502              :     return t;
    2503              : 
    2504         9353 :   irange &ir = as_a <irange> (vr);
    2505         9353 :   if (range_fits_type_p (&ir, TYPE_PRECISION (TREE_TYPE (t)),
    2506         9353 :                          TYPE_SIGN (TREE_TYPE (t))))
    2507         4698 :       return gimple_assign_rhs1 (def);
    2508              : 
    2509              :   return t;
    2510         9371 : }
    2511              : 
    2512              : /* Compute jump function for all arguments of callsite CS and insert the
    2513              :    information in the jump_functions array in the ipa_edge_args corresponding
    2514              :    to this callsite.  */
    2515              : 
    2516              : static void
    2517      3074136 : ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
    2518              :                                      struct cgraph_edge *cs)
    2519              : {
    2520      3074136 :   ipa_node_params *info = ipa_node_params_sum->get (cs->caller);
    2521      3074136 :   ipa_edge_args *args = ipa_edge_args_sum->get_create (cs);
    2522      3074136 :   gcall *call = cs->call_stmt;
    2523      3074136 :   callback_info *ci = callback_info_sum->get (cs);
    2524      3074136 :   int n, arg_num = callback_call_num_args_summary (call, ci);
    2525      3074136 :   bool useful_context = false;
    2526              : 
    2527      3074136 :   if (arg_num == 0 || args->jump_functions)
    2528       279259 :     return;
    2529      2794877 :   vec_safe_grow_cleared (args->jump_functions, arg_num, true);
    2530      2794877 :   if (flag_devirtualize)
    2531      2609500 :     vec_safe_grow_cleared (args->polymorphic_call_contexts, arg_num, true);
    2532              : 
    2533      2794877 :   if (ipa_func_spec_opts_forbid_analysis_p (cs->caller))
    2534              :     return;
    2535              : 
    2536      2794877 :   auto_vec<cgraph_edge*> callback_edges;
    2537      9288019 :   for (n = 0; n < arg_num; n++)
    2538              :     {
    2539      6493142 :       struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, n);
    2540      6493142 :       tree arg;
    2541      6493142 :       if (cs->callback)
    2542              :         {
    2543          208 :           gcc_assert (cs->callee->assume_function);
    2544          208 :           int remapped_idx = ci->arg_mapping[n];
    2545          208 :           if (remapped_idx == ARG_MAPPING_UNKNOWN_IDX)
    2546        65699 :             continue;
    2547          208 :           arg = gimple_call_arg (call, remapped_idx);
    2548              :         }
    2549              :       else
    2550      6492934 :         arg = gimple_call_arg (call, n);
    2551      6493142 :       tree param_type = ipa_get_callee_param_type (cs, n);
    2552      6493142 :       if (flag_devirtualize && POINTER_TYPE_P (TREE_TYPE (arg)))
    2553              :         {
    2554      3368107 :           tree instance;
    2555      3368107 :           class ipa_polymorphic_call_context context (cs->caller->decl,
    2556      3368107 :                                                        arg, cs->call_stmt,
    2557      3368107 :                                                        &instance);
    2558      3368107 :           context.get_dynamic_type (instance, arg, NULL, cs->call_stmt,
    2559              :                                     &fbi->aa_walk_budget);
    2560      3368107 :           *ipa_get_ith_polymorhic_call_context (args, n) = context;
    2561      6736214 :           if (!context.useless_p ())
    2562       320369 :             useful_context = true;
    2563              :         }
    2564              : 
    2565      6493142 :       value_range vr (TREE_TYPE (arg));
    2566      6493142 :       if (POINTER_TYPE_P (TREE_TYPE (arg)))
    2567              :         {
    2568      7258988 :           if (!get_range_query (cfun)->range_of_expr (vr, arg, cs->call_stmt)
    2569      3629494 :               || vr.varying_p ()
    2570      6425397 :               || vr.undefined_p ())
    2571              :             {
    2572       834026 :               if (tree_single_nonzero_p (arg))
    2573            0 :                 vr.set_nonzero (TREE_TYPE (arg));
    2574              :               else
    2575       834026 :                 vr.set_varying (TREE_TYPE (arg));
    2576              :             }
    2577      3629494 :           gcc_assert (!vr.undefined_p ());
    2578      3629494 :           unsigned HOST_WIDE_INT bitpos;
    2579      3629494 :           unsigned align = BITS_PER_UNIT;
    2580              : 
    2581      3629494 :           if (!vr.singleton_p ())
    2582      3552885 :             get_pointer_alignment_1 (arg, &align, &bitpos);
    2583              : 
    2584      3629494 :           if (align > BITS_PER_UNIT
    2585      3629494 :               && opt_for_fn (cs->caller->decl, flag_ipa_bit_cp))
    2586              :             {
    2587      1366674 :               unsigned prec = TYPE_PRECISION (TREE_TYPE (arg));
    2588      1366674 :               wide_int mask
    2589      2733348 :                 = wi::bit_and_not (wi::mask (prec, false, prec),
    2590      1366674 :                                    wide_int::from (align / BITS_PER_UNIT - 1,
    2591      1366674 :                                                    prec, UNSIGNED));
    2592      1366674 :               wide_int value = wide_int::from (bitpos / BITS_PER_UNIT, prec,
    2593      1366674 :                                                UNSIGNED);
    2594      1366674 :               irange_bitmask bm (value, mask);
    2595      1366674 :               vr.update_bitmask (bm);
    2596      1366674 :               ipa_set_jfunc_vr (jfunc, vr);
    2597      1366674 :             }
    2598      2262820 :           else if (!vr.varying_p ())
    2599      1428798 :             ipa_set_jfunc_vr (jfunc, vr);
    2600              :           else
    2601       834022 :             gcc_assert (!jfunc->m_vr);
    2602              :         }
    2603              :       else
    2604              :         {
    2605      2863648 :           if (param_type
    2606      2551156 :               && ipa_vr_supported_type_p (TREE_TYPE (arg))
    2607      2863789 :               && ipa_vr_supported_type_p (param_type)
    2608      3787368 :               && get_range_query (cfun)->range_of_expr (vr, arg, cs->call_stmt)
    2609      4757332 :               && !vr.undefined_p ())
    2610              :             {
    2611      1893543 :               value_range resvr (vr);
    2612      1893543 :               range_cast (resvr, param_type);
    2613      1893543 :               if (!resvr.undefined_p () && !resvr.varying_p ())
    2614      1516794 :                 ipa_set_jfunc_vr (jfunc, resvr);
    2615              :               else
    2616       376749 :                 gcc_assert (!jfunc->m_vr);
    2617      1893543 :             }
    2618              :           else
    2619       970105 :             gcc_assert (!jfunc->m_vr);
    2620              :         }
    2621              : 
    2622      6493142 :       arg = skip_a_safe_conversion_op (arg);
    2623      6493142 :       if (is_gimple_ip_invariant (arg)
    2624      6493142 :           || (VAR_P (arg) && is_global_var (arg) && TREE_READONLY (arg)))
    2625              :         {
    2626      2372701 :           ipa_set_jf_constant (jfunc, arg, cs);
    2627      2372701 :           if (TREE_CODE (arg) == ADDR_EXPR)
    2628              :             {
    2629       902368 :               tree pointee = TREE_OPERAND (arg, 0);
    2630       902368 :               if (TREE_CODE (pointee) == FUNCTION_DECL && !cs->callback
    2631        44823 :                   && cs->callee)
    2632              :                 {
    2633              :                   /* Argument is a pointer to a function. Look for a callback
    2634              :                      attribute describing this argument.  */
    2635        44437 :                   tree callback_attr
    2636        44437 :                     = lookup_attribute ("callback_only",
    2637        44437 :                                         DECL_ATTRIBUTES (cs->callee->decl));
    2638        88875 :                   for (; callback_attr;
    2639              :                        callback_attr
    2640            1 :                        = lookup_attribute ("callback_only",
    2641            1 :                                            TREE_CHAIN (callback_attr)))
    2642        13415 :                     if (callback_get_fn_index (callback_attr) == n)
    2643              :                       break;
    2644              : 
    2645              :                   /* If no callback attribute is found, check if the function is
    2646              :                      a special case.  */
    2647        44437 :                   if (!callback_attr
    2648        44437 :                       && callback_is_special_cased (cs->callee->decl, call))
    2649              :                     {
    2650         1791 :                       callback_attr
    2651         1791 :                         = callback_special_case_attr (cs->callee->decl);
    2652              :                       /* Check if the special attribute describes the correct
    2653              :                          attribute, as a special cased function might have
    2654              :                          multiple callbacks.  */
    2655         1791 :                       if (callback_get_fn_index (callback_attr) != n)
    2656              :                         callback_attr = NULL;
    2657              :                     }
    2658              : 
    2659              :                   /* If a callback attribute describing this pointer is found,
    2660              :                      create a callback edge to the pointee function to
    2661              :                      allow for further optimizations.  */
    2662        44437 :                   if (callback_attr)
    2663              :                     {
    2664        15205 :                       cgraph_node *kernel_node
    2665        15205 :                         = cgraph_node::get_create (pointee);
    2666        15205 :                       cgraph_edge *cbe
    2667        15205 :                         = cs->make_callback (kernel_node, n, callback_attr);
    2668        15205 :                       callback_edges.safe_push (cbe);
    2669              :                     }
    2670              :                 }
    2671              :             }
    2672              :         }
    2673      4120441 :       else if (!is_gimple_reg_type (TREE_TYPE (arg))
    2674      4120441 :                && TREE_CODE (arg) == PARM_DECL)
    2675              :         {
    2676        80914 :           int index = ipa_get_param_decl_index (info, arg);
    2677              : 
    2678        80914 :           gcc_assert (index >=0);
    2679              :           /* Aggregate passed by value, check for pass-through, otherwise we
    2680              :              will attempt to fill in aggregate contents later in this
    2681              :              for cycle.  */
    2682        80914 :           if (parm_preserved_before_stmt_p (fbi, index, call, arg))
    2683              :             {
    2684        65699 :               ipa_set_jf_simple_pass_through (jfunc, index, false);
    2685        65699 :               continue;
    2686              :             }
    2687              :         }
    2688      4039527 :       else if (TREE_CODE (arg) == SSA_NAME)
    2689              :         {
    2690      2617656 :           if (SSA_NAME_IS_DEFAULT_DEF (arg))
    2691              :             {
    2692      1037116 :               int index = ipa_get_param_decl_index (info, SSA_NAME_VAR (arg));
    2693      1037116 :               if (index >= 0)
    2694              :                 {
    2695      1027198 :                   bool agg_p;
    2696      1027198 :                   agg_p = parm_ref_data_pass_through_p (fbi, index, call, arg);
    2697      1027198 :                   ipa_set_jf_simple_pass_through (jfunc, index, agg_p);
    2698              :                 }
    2699              :             }
    2700              :           else
    2701              :             {
    2702      1580540 :               gimple *stmt = SSA_NAME_DEF_STMT (arg);
    2703      1580540 :               if (is_gimple_assign (stmt))
    2704      1287831 :                 compute_complex_assign_jump_func (fbi, info, jfunc,
    2705              :                                                   call, stmt, arg, param_type);
    2706       292709 :               else if (gimple_code (stmt) == GIMPLE_PHI)
    2707        94868 :                 compute_complex_ancestor_jump_func (fbi, info, jfunc,
    2708              :                                                     call,
    2709              :                                                     as_a <gphi *> (stmt));
    2710              :             }
    2711              :         }
    2712              : 
    2713              :       /* If ARG is pointer, we cannot use its type to determine the type of aggregate
    2714              :          passed (because type conversions are ignored in gimple).  Usually we can
    2715              :          safely get type from function declaration, but in case of K&R prototypes or
    2716              :          variadic functions we can try our luck with type of the pointer passed.
    2717              :          TODO: Since we look for actual initialization of the memory object, we may better
    2718              :          work out the type based on the memory stores we find.  */
    2719      6427443 :       if (!param_type)
    2720       347309 :         param_type = TREE_TYPE (arg);
    2721              : 
    2722      6427443 :       if ((jfunc->type != IPA_JF_PASS_THROUGH
    2723      1073346 :               || !ipa_get_jf_pass_through_agg_preserved (jfunc))
    2724      6035807 :           && (jfunc->type != IPA_JF_ANCESTOR
    2725       170782 :               || !ipa_get_jf_ancestor_agg_preserved (jfunc))
    2726     12397877 :           && (AGGREGATE_TYPE_P (TREE_TYPE (arg))
    2727      5583344 :               || POINTER_TYPE_P (param_type)))
    2728      3532797 :         determine_known_aggregate_parts (fbi, call, arg, param_type, jfunc);
    2729      6493142 :     }
    2730              : 
    2731      2794877 :   if (!callback_edges.is_empty ())
    2732              :     {
    2733              :       /* For every callback edge, fetch jump functions of arguments
    2734              :          passed to them and copy them over to their respective summaries.
    2735              :          This avoids recalculating them for every callback edge, since their
    2736              :          arguments are just passed through.  */
    2737              :       unsigned j;
    2738        30409 :       for (j = 0; j < callback_edges.length (); j++)
    2739              :         {
    2740        15205 :           cgraph_edge *callback_edge = callback_edges[j];
    2741        15205 :           ipa_edge_args *cb_summary
    2742        15205 :             = ipa_edge_args_sum->get_create (callback_edge);
    2743        15205 :           callback_info *ci = callback_info_sum->get (callback_edge);
    2744        15205 :           auto_vec<int> &arg_mapping = ci->arg_mapping;
    2745        15205 :           unsigned i;
    2746        30411 :           for (i = 0; i < arg_mapping.length (); i++)
    2747              :             {
    2748        15206 :               if (arg_mapping[i] == ARG_MAPPING_UNKNOWN_IDX)
    2749            0 :                 continue;
    2750        15206 :               class ipa_jump_func *src
    2751        15206 :                 = ipa_get_ith_jump_func (args, arg_mapping[i]);
    2752        15206 :               class ipa_jump_func *dst = ipa_get_ith_jump_func (cb_summary, i);
    2753        15206 :               ipa_duplicate_jump_function (cs, callback_edge, src, dst);
    2754              :             }
    2755              :         }
    2756              :     }
    2757              : 
    2758      2794877 :   if (!useful_context)
    2759      4808491 :     vec_free (args->polymorphic_call_contexts);
    2760      2794877 : }
    2761              : 
    2762              : /* Compute jump functions for all edges - both direct and indirect - outgoing
    2763              :    from BB.  */
    2764              : 
    2765              : static void
    2766     11364545 : ipa_compute_jump_functions_for_bb (struct ipa_func_body_info *fbi, basic_block bb)
    2767              : {
    2768     11364545 :   struct ipa_bb_info *bi = ipa_get_bb_info (fbi, bb);
    2769     11364545 :   int i;
    2770     11364545 :   struct cgraph_edge *cs;
    2771              : 
    2772     21269731 :   FOR_EACH_VEC_ELT_REVERSE (bi->cg_edges, i, cs)
    2773              :     {
    2774      5714006 :       struct cgraph_node *callee = cs->callee;
    2775              : 
    2776      5714006 :       if (callee)
    2777              :         {
    2778      5572638 :           callee = callee->ultimate_alias_target ();
    2779              :           /* We do not need to bother analyzing calls to unknown functions
    2780              :              unless they may become known during lto/whopr.  */
    2781      3623126 :           if (!callee->definition && !flag_lto
    2782      5587829 :               && !gimple_call_fnspec (cs->call_stmt).known_p ()
    2783      8227874 :               && !callback_edge_callee_has_attr (cs))
    2784      2640045 :             continue;
    2785              :         }
    2786      3073961 :       ipa_compute_jump_functions_for_edge (fbi, cs);
    2787              :     }
    2788     11364545 : }
    2789              : 
    2790              : /* If REF is a memory access that loads a function pointer (but not a method
    2791              :    pointer) from a RECORD_TYPE, return true and store the type of the RECORD to
    2792              :    *REC_TYPE and the byte offset of the field to *FLD_OFFSET.  Otherwise return
    2793              :    false.  OHS es the "other hand side" which is used to check type
    2794              :    compatibility with field in question, when possible.  */
    2795              : 
    2796              : static bool
    2797       121243 : is_func_ptr_from_record (tree ref, tree *rec_type, unsigned *fld_offset,
    2798              :                          tree ohs)
    2799              : {
    2800       121257 :   if (!POINTER_TYPE_P (TREE_TYPE (ref))
    2801       121257 :       || TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
    2802              :     return false;
    2803              : 
    2804       106135 :   if (TREE_CODE (ref) == COMPONENT_REF
    2805       106135 :       && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
    2806              :     {
    2807        57300 :       gcc_assert (POINTER_TYPE_P (TREE_TYPE (ohs)));
    2808        57300 :       ohs = TREE_TYPE (TREE_TYPE (ohs));
    2809        57300 :       tree ftype = TREE_TYPE (TREE_OPERAND (ref, 1));
    2810        57300 :       if (!POINTER_TYPE_P (ftype))
    2811              :         return false;
    2812        57300 :       ftype = TREE_TYPE (ftype);
    2813        57300 :       if (!types_compatible_p (ohs, ftype))
    2814              :         return false;
    2815              : 
    2816        57171 :       tree tree_off = bit_position (TREE_OPERAND (ref, 1));
    2817        57171 :       if (!tree_fits_shwi_p (tree_off))
    2818              :         return false;
    2819        57171 :       HOST_WIDE_INT bit_offset = tree_to_shwi (tree_off);
    2820        57171 :       if (bit_offset % BITS_PER_UNIT)
    2821              :         return false;
    2822        57171 :       HOST_WIDE_INT unit_offset = bit_offset / BITS_PER_UNIT;
    2823        57171 :       if (unit_offset > UINT_MAX)
    2824              :         return false;
    2825        57171 :       *rec_type = TREE_TYPE (TREE_OPERAND (ref, 0));
    2826        57171 :       *fld_offset = unit_offset;
    2827        57171 :       return true;
    2828              :     }
    2829        48835 :   else if (TREE_CODE (ref) == MEM_REF
    2830         5272 :            && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (ref, 0)))
    2831         5272 :            && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (ref, 0))))
    2832              :                == RECORD_TYPE)
    2833        51330 :            && tree_fits_shwi_p (TREE_OPERAND (ref, 1)))
    2834              :     {
    2835         2495 :       HOST_WIDE_INT unit_offset = tree_to_shwi (TREE_OPERAND (ref, 1));
    2836         2495 :       if (unit_offset > UINT_MAX)
    2837              :         return false;
    2838         2495 :       *rec_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (ref, 0)));
    2839         2495 :       *fld_offset = unit_offset;
    2840         2495 :       return true;
    2841              :     }
    2842              :   return false;
    2843              : }
    2844              : 
    2845              : /* If STMT looks like a statement loading a value from a member pointer formal
    2846              :    parameter, return that parameter and store the offset of the field to
    2847              :    *OFFSET_P, if it is non-NULL.  Otherwise return NULL (but *OFFSET_P still
    2848              :    might be clobbered).  If USE_DELTA, then we look for a use of the delta
    2849              :    field rather than the pfn.  */
    2850              : 
    2851              : static tree
    2852         2209 : ipa_get_stmt_member_ptr_load_param (gimple *stmt, bool use_delta,
    2853              :                                     HOST_WIDE_INT *offset_p)
    2854              : {
    2855         2209 :   tree rhs, fld, ptr_field, delta_field;
    2856         2209 :   tree ref_field = NULL_TREE;
    2857         2209 :   tree ref_offset = NULL_TREE;
    2858              : 
    2859         2209 :   if (!gimple_assign_single_p (stmt))
    2860              :     return NULL_TREE;
    2861              : 
    2862         2209 :   rhs = gimple_assign_rhs1 (stmt);
    2863         2209 :   if (TREE_CODE (rhs) == COMPONENT_REF)
    2864              :     {
    2865         1328 :       ref_field = TREE_OPERAND (rhs, 1);
    2866         1328 :       rhs = TREE_OPERAND (rhs, 0);
    2867              :     }
    2868              : 
    2869         2209 :   if (TREE_CODE (rhs) == MEM_REF)
    2870              :     {
    2871         1489 :       ref_offset = TREE_OPERAND (rhs, 1);
    2872         1489 :       if (ref_field && integer_nonzerop (ref_offset))
    2873              :         return NULL_TREE;
    2874              :     }
    2875          720 :   else if (!ref_field)
    2876              :     return NULL_TREE;
    2877              : 
    2878         2209 :   if (TREE_CODE (rhs) == MEM_REF
    2879         1489 :       && TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME
    2880         3698 :       && SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (rhs, 0)))
    2881              :     {
    2882          606 :       rhs = TREE_OPERAND (rhs, 0);
    2883          606 :       if (TREE_CODE (SSA_NAME_VAR (rhs)) != PARM_DECL
    2884          606 :           || !type_like_member_ptr_p (TREE_TYPE (TREE_TYPE (rhs)), &ptr_field,
    2885              :                                       &delta_field))
    2886              :         return NULL_TREE;
    2887              :     }
    2888              :   else
    2889              :     {
    2890         1603 :       if (TREE_CODE (rhs) == MEM_REF
    2891         1603 :           && TREE_CODE (TREE_OPERAND (rhs, 0)) == ADDR_EXPR)
    2892            0 :         rhs = TREE_OPERAND (TREE_OPERAND (rhs, 0), 0);
    2893         1603 :       if (TREE_CODE (rhs) != PARM_DECL
    2894         1603 :           || !type_like_member_ptr_p (TREE_TYPE (rhs), &ptr_field,
    2895              :                                       &delta_field))
    2896              :         return NULL_TREE;
    2897              :     }
    2898              : 
    2899          894 :   if (use_delta)
    2900            0 :     fld = delta_field;
    2901              :   else
    2902          894 :     fld = ptr_field;
    2903              : 
    2904          894 :   if (ref_field)
    2905              :     {
    2906          894 :       if (ref_field != fld)
    2907              :         return NULL_TREE;
    2908              :     }
    2909            0 :   else if (!tree_int_cst_equal (byte_position (fld), ref_offset))
    2910              :     return NULL_TREE;
    2911              : 
    2912          894 :   if (offset_p)
    2913          447 :     *offset_p = int_bit_position (fld);
    2914              :   return rhs;
    2915              : }
    2916              : 
    2917              : /* Returns true iff T is an SSA_NAME defined by a statement.  */
    2918              : 
    2919              : static bool
    2920         3103 : ipa_is_ssa_with_stmt_def (tree t)
    2921              : {
    2922         3103 :   if (TREE_CODE (t) == SSA_NAME
    2923         3103 :       && !SSA_NAME_IS_DEFAULT_DEF (t))
    2924              :     return true;
    2925              :   else
    2926            0 :     return false;
    2927              : }
    2928              : 
    2929              : /* Analyze the CALL and examine uses of formal parameters of the caller NODE
    2930              :    (described by INFO).  PARMS_AINFO is a pointer to a vector containing
    2931              :    intermediate information about each formal parameter.  Currently it checks
    2932              :    whether the call calls a pointer that is a formal parameter and if so, the
    2933              :    parameter is marked with the called flag and an indirect call graph edge
    2934              :    describing the call is created.  This is very simple for ordinary pointers
    2935              :    represented in SSA but not-so-nice when it comes to member pointers.  The
    2936              :    ugly part of this function does nothing more than trying to match the
    2937              :    pattern of such a call.  Look up the documentation of macro
    2938              :    TARGET_PTRMEMFUNC_VBIT_LOCATION for details.  An example of such a pattern
    2939              :    is the gimple dump below, the call is on the last line:
    2940              : 
    2941              :      <bb 2>:
    2942              :        f$__delta_5 = f.__delta;
    2943              :        f$__pfn_24 = f.__pfn;
    2944              : 
    2945              :    or
    2946              :      <bb 2>:
    2947              :        f$__delta_5 = MEM[(struct  *)&f];
    2948              :        f$__pfn_24 = MEM[(struct  *)&f + 4B];
    2949              : 
    2950              :    and a few lines below:
    2951              : 
    2952              :      <bb 5>
    2953              :        D.2496_3 = (int) f$__pfn_24;
    2954              :        D.2497_4 = D.2496_3 & 1;
    2955              :        if (D.2497_4 != 0)
    2956              :          goto <bb 3>;
    2957              :        else
    2958              :          goto <bb 4>;
    2959              : 
    2960              :      <bb 6>:
    2961              :        D.2500_7 = (unsigned int) f$__delta_5;
    2962              :        D.2501_8 = &S + D.2500_7;
    2963              :        D.2502_9 = (int (*__vtbl_ptr_type) (void) * *) D.2501_8;
    2964              :        D.2503_10 = *D.2502_9;
    2965              :        D.2504_12 = f$__pfn_24 + -1;
    2966              :        D.2505_13 = (unsigned int) D.2504_12;
    2967              :        D.2506_14 = D.2503_10 + D.2505_13;
    2968              :        D.2507_15 = *D.2506_14;
    2969              :        iftmp.11_16 = (String:: *) D.2507_15;
    2970              : 
    2971              :      <bb 7>:
    2972              :        # iftmp.11_1 = PHI <iftmp.11_16(3), f$__pfn_24(2)>
    2973              :        D.2500_19 = (unsigned int) f$__delta_5;
    2974              :        D.2508_20 = &S + D.2500_19;
    2975              :        D.2493_21 = iftmp.11_1 (D.2508_20, 4);
    2976              : 
    2977              :    Such patterns are results of simple calls to a member pointer:
    2978              : 
    2979              :      int doprinting (int (MyString::* f)(int) const)
    2980              :      {
    2981              :        MyString S ("somestring");
    2982              : 
    2983              :        return (S.*f)(4);
    2984              :      }
    2985              : 
    2986              :    Moreover, the function also looks for called pointers loaded from aggregates
    2987              :    passed by value or reference.  */
    2988              : 
    2989              : static void
    2990       116042 : ipa_analyze_indirect_call_uses (struct ipa_func_body_info *fbi, gcall *call,
    2991              :                                 tree target)
    2992              : {
    2993       116042 :   class ipa_node_params *info = fbi->info;
    2994       116042 :   HOST_WIDE_INT offset;
    2995       116042 :   bool by_ref;
    2996              : 
    2997       116042 :   if (SSA_NAME_IS_DEFAULT_DEF (target))
    2998              :     {
    2999         3781 :       tree var = SSA_NAME_VAR (target);
    3000         3781 :       int index = ipa_get_param_decl_index (info, var);
    3001         3781 :       if (index >= 0)
    3002              :         {
    3003         3779 :           cgraph_edge *cs = fbi->node->get_edge (call);
    3004         3779 :           cgraph_simple_indirect_info *sii =
    3005         3779 :             as_a <cgraph_simple_indirect_info *> (cs->indirect_info);
    3006         3779 :           sii->param_index = index;
    3007         3779 :           gcc_assert (!sii->agg_contents && !sii->member_ptr);
    3008         3779 :           ipa_set_param_used_by_indirect_call (info, index, true);
    3009              :         }
    3010              :       return;
    3011              :     }
    3012              : 
    3013       112261 :   int index;
    3014       112261 :   gimple *def = SSA_NAME_DEF_STMT (target);
    3015       112261 :   bool guaranteed_unmodified;
    3016       112261 :   if (gimple_assign_single_p (def))
    3017              :     {
    3018        89711 :       cgraph_edge *cs = fbi->node->get_edge (call);
    3019        89711 :       cgraph_simple_indirect_info *sii =
    3020        89711 :         as_a <cgraph_simple_indirect_info *> (cs->indirect_info);
    3021        89711 :       tree rectype;
    3022        89711 :       unsigned fldoff;
    3023        89711 :       if (is_func_ptr_from_record (gimple_assign_rhs1 (def), &rectype, &fldoff,
    3024              :                                    target))
    3025              :         {
    3026        47934 :           sii->fnptr_loaded_from_record = 1;
    3027        47934 :           sii->fld_offset = fldoff;
    3028        47934 :           sii->rec_type = rectype;
    3029              :         }
    3030        89711 :       if (ipa_load_from_parm_agg (fbi, info->descriptors, def,
    3031              :                                   gimple_assign_rhs1 (def), &index, &offset,
    3032              :                                   NULL, &by_ref, &guaranteed_unmodified))
    3033              :         {
    3034         2330 :           sii->param_index = index;
    3035         2330 :           sii->offset = offset;
    3036         2330 :           sii->agg_contents = 1;
    3037         2330 :           sii->by_ref = by_ref;
    3038         2330 :           sii->guaranteed_unmodified = guaranteed_unmodified;
    3039         2330 :           ipa_set_param_used_by_indirect_call (info, index, true);
    3040         2330 :           return;
    3041              :         }
    3042              :     }
    3043              : 
    3044              :   /* Now we need to try to match the complex pattern of calling a member
    3045              :      pointer. */
    3046       109931 :   if (gimple_code (def) != GIMPLE_PHI
    3047         1156 :       || gimple_phi_num_args (def) != 2
    3048         1154 :       || !POINTER_TYPE_P (TREE_TYPE (target))
    3049       111085 :       || TREE_CODE (TREE_TYPE (TREE_TYPE (target))) != METHOD_TYPE)
    3050              :     return;
    3051              : 
    3052              :   /* First, we need to check whether one of these is a load from a member
    3053              :      pointer that is a parameter to this function. */
    3054          881 :   tree n1 = PHI_ARG_DEF (def, 0);
    3055          881 :   tree n2 = PHI_ARG_DEF (def, 1);
    3056         1762 :   if (!ipa_is_ssa_with_stmt_def (n1) || !ipa_is_ssa_with_stmt_def (n2))
    3057              :     return;
    3058          881 :   gimple *d1 = SSA_NAME_DEF_STMT (n1);
    3059          881 :   gimple *d2 = SSA_NAME_DEF_STMT (n2);
    3060              : 
    3061          881 :   tree rec;
    3062          881 :   basic_block bb, virt_bb;
    3063          881 :   basic_block join = gimple_bb (def);
    3064          881 :   if ((rec = ipa_get_stmt_member_ptr_load_param (d1, false, &offset)))
    3065              :     {
    3066            0 :       if (ipa_get_stmt_member_ptr_load_param (d2, false, NULL))
    3067              :         return;
    3068              : 
    3069            0 :       bb = EDGE_PRED (join, 0)->src;
    3070            0 :       virt_bb = gimple_bb (d2);
    3071              :     }
    3072          881 :   else if ((rec = ipa_get_stmt_member_ptr_load_param (d2, false, &offset)))
    3073              :     {
    3074          447 :       bb = EDGE_PRED (join, 1)->src;
    3075          447 :       virt_bb = gimple_bb (d1);
    3076              :     }
    3077              :   else
    3078              :     return;
    3079              : 
    3080              :   /* Second, we need to check that the basic blocks are laid out in the way
    3081              :      corresponding to the pattern. */
    3082              : 
    3083          894 :   if (!single_pred_p (virt_bb) || !single_succ_p (virt_bb)
    3084          894 :       || single_succ (virt_bb) != join)
    3085              :     return;
    3086              : 
    3087              : 
    3088          447 :   if (single_pred (virt_bb) != bb)
    3089              :     {
    3090              :       /* In cases when the distinction between a normal and a virtual
    3091              :          function is encoded in the delta field, the load of the
    3092              :          actual non-virtual function pointer can be in its own BB.  */
    3093              : 
    3094            0 :       if (!single_pred_p (bb) || !single_succ_p (bb))
    3095              :         return;
    3096            0 :       bb = single_pred (bb);
    3097            0 :       if (bb != single_pred (virt_bb))
    3098              :         return;
    3099              :     }
    3100              : 
    3101              :   /* Third, let's see that the branching is done depending on the least
    3102              :      significant bit of the pfn. */
    3103              : 
    3104          894 :   gcond *branch = safe_dyn_cast <gcond *> (*gsi_last_bb (bb));
    3105          447 :   if (!branch)
    3106              :     return;
    3107              : 
    3108          447 :   if ((gimple_cond_code (branch) != NE_EXPR
    3109            0 :        && gimple_cond_code (branch) != EQ_EXPR)
    3110          447 :       || !integer_zerop (gimple_cond_rhs (branch)))
    3111              :     return;
    3112              : 
    3113          447 :   tree cond = gimple_cond_lhs (branch);
    3114          447 :   if (!ipa_is_ssa_with_stmt_def (cond))
    3115              :     return;
    3116              : 
    3117          447 :   def = SSA_NAME_DEF_STMT (cond);
    3118          447 :   if (!is_gimple_assign (def)
    3119          447 :       || gimple_assign_rhs_code (def) != BIT_AND_EXPR
    3120          894 :       || !integer_onep (gimple_assign_rhs2 (def)))
    3121              :     return;
    3122              : 
    3123          447 :   cond = gimple_assign_rhs1 (def);
    3124          447 :   if (!ipa_is_ssa_with_stmt_def (cond))
    3125              :     return;
    3126              : 
    3127          447 :   def = SSA_NAME_DEF_STMT (cond);
    3128              : 
    3129          447 :   if (is_gimple_assign (def)
    3130          447 :       && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)))
    3131              :     {
    3132          447 :       cond = gimple_assign_rhs1 (def);
    3133          447 :       if (!ipa_is_ssa_with_stmt_def (cond))
    3134              :         return;
    3135          447 :       def = SSA_NAME_DEF_STMT (cond);
    3136              :     }
    3137              : 
    3138          447 :   tree rec2;
    3139          447 :   rec2 = ipa_get_stmt_member_ptr_load_param (def,
    3140              :                                              (TARGET_PTRMEMFUNC_VBIT_LOCATION
    3141              :                                               == ptrmemfunc_vbit_in_delta),
    3142              :                                              NULL);
    3143          447 :   if (rec != rec2)
    3144              :     return;
    3145              : 
    3146          447 :   if (TREE_CODE (rec) == SSA_NAME)
    3147              :     {
    3148          303 :       index = ipa_get_param_decl_index (info, SSA_NAME_VAR (rec));
    3149          303 :       if (index < 0
    3150          303 :           || !parm_ref_data_preserved_p (fbi, index, call,
    3151              :                                          gimple_assign_rhs1 (def)))
    3152              :         return;
    3153          299 :       by_ref = true;
    3154              :     }
    3155              :   else
    3156              :     {
    3157          144 :       index = ipa_get_param_decl_index (info, rec);
    3158          144 :       if (index < 0
    3159          144 :           || !parm_preserved_before_stmt_p (fbi, index, call, rec))
    3160              :         return;
    3161          144 :       by_ref = false;
    3162              :     }
    3163              : 
    3164          443 :   cgraph_edge *cs = fbi->node->get_edge (call);
    3165          443 :   cgraph_simple_indirect_info *sii =
    3166          443 :     as_a <cgraph_simple_indirect_info *> (cs->indirect_info);
    3167          443 :   sii->param_index = index;
    3168          443 :   sii->offset = offset;
    3169          443 :   sii->agg_contents = 1;
    3170          443 :   sii->member_ptr = 1;
    3171          443 :   sii->by_ref = by_ref;
    3172          443 :   sii->guaranteed_unmodified = 1;
    3173          443 :   ipa_set_param_used_by_indirect_call (info, index, true);
    3174          443 :   return;
    3175              : }
    3176              : 
    3177              : /* Analyze a CALL to an OBJ_TYPE_REF which is passed in TARGET and if the
    3178              :    object referenced in the expression is a formal parameter of the caller
    3179              :    FBI->node (described by FBI->info), create a call note for the
    3180              :    statement.  */
    3181              : 
    3182              : static void
    3183        25246 : ipa_analyze_virtual_call_uses (struct ipa_func_body_info *fbi,
    3184              :                                gcall *call, tree target)
    3185              : {
    3186        25246 :   tree obj = OBJ_TYPE_REF_OBJECT (target);
    3187        25246 :   int index;
    3188        25246 :   HOST_WIDE_INT anc_offset;
    3189              : 
    3190        25246 :   if (!flag_devirtualize)
    3191        15482 :     return;
    3192              : 
    3193        24976 :   if (TREE_CODE (obj) != SSA_NAME)
    3194              :     return;
    3195              : 
    3196        24611 :   class ipa_node_params *info = fbi->info;
    3197        24611 :   if (SSA_NAME_IS_DEFAULT_DEF (obj))
    3198              :     {
    3199         8907 :       if (TREE_CODE (SSA_NAME_VAR (obj)) != PARM_DECL)
    3200              :         return;
    3201              : 
    3202         8907 :       anc_offset = 0;
    3203         8907 :       index = ipa_get_param_decl_index (info, SSA_NAME_VAR (obj));
    3204         8907 :       gcc_assert (index >= 0);
    3205         8907 :       if (detect_type_change_ssa (fbi, obj, obj_type_ref_class (target),
    3206              :                                   call))
    3207              :         return;
    3208              :     }
    3209              :   else
    3210              :     {
    3211        15704 :       gimple *stmt = SSA_NAME_DEF_STMT (obj);
    3212        15704 :       tree expr;
    3213              : 
    3214        15704 :       expr = get_ancestor_addr_info (stmt, &obj, &anc_offset);
    3215        15704 :       if (!expr)
    3216              :         return;
    3217          857 :       index = ipa_get_param_decl_index (info,
    3218          857 :                                         SSA_NAME_VAR (TREE_OPERAND (expr, 0)));
    3219          857 :       gcc_assert (index >= 0);
    3220          857 :       if (detect_type_change (fbi, obj, expr, obj_type_ref_class (target),
    3221              :                               call, anc_offset))
    3222              :         return;
    3223              :     }
    3224              : 
    3225         9764 :   cgraph_edge *cs = fbi->node->get_edge (call);
    3226         9764 :   cgraph_polymorphic_indirect_info *pii =
    3227         9764 :     as_a <cgraph_polymorphic_indirect_info *> (cs->indirect_info);
    3228         9764 :   pii->param_index = index;
    3229         9764 :   pii->offset = anc_offset;
    3230         9764 :   gcc_assert (pii->otr_token == tree_to_shwi (OBJ_TYPE_REF_TOKEN (target)));
    3231         9764 :   gcc_assert (pii->otr_type = obj_type_ref_class (target));
    3232         9764 :   ipa_set_param_used_by_indirect_call (info, index, true);
    3233         9764 :   ipa_set_param_used_by_polymorphic_call (info, index, true);
    3234              : }
    3235              : 
    3236              : /* Analyze a call statement CALL whether and how it utilizes formal parameters
    3237              :    of the caller (described by INFO).  PARMS_AINFO is a pointer to a vector
    3238              :    containing intermediate information about each formal parameter.  */
    3239              : 
    3240              : static void
    3241      5946490 : ipa_analyze_call_uses (struct ipa_func_body_info *fbi, gcall *call)
    3242              : {
    3243      5946490 :   tree target = gimple_call_fn (call);
    3244              : 
    3245              :   /* Internal .ASSUME call.  Create a callback edge to its body, calculate its
    3246              :      jump functions and return.  This is done here as the main creation route in
    3247              :      ipa_compute_jump_functions_for_edge doesn't analyze call statements.  */
    3248      5946490 :   if (callback_ifn_assume_call_p (call))
    3249              :     {
    3250          175 :       tree callee_decl = TREE_OPERAND (gimple_call_arg (call, 0), 0);
    3251          175 :       cgraph_node *target = cgraph_node::get_create (callee_decl);
    3252          175 :       cgraph_edge *cbei
    3253          175 :         = cgraph_edge::make_callback_internal (fbi->node, target, call);
    3254          175 :       ipa_compute_jump_functions_for_edge (fbi, cbei);
    3255          175 :       return;
    3256              :     }
    3257              : 
    3258      5946315 :   if (!target
    3259      5946315 :       || (TREE_CODE (target) != SSA_NAME
    3260      5597964 :           && !virtual_method_call_p (target)))
    3261              :     return;
    3262              : 
    3263       141288 :   struct cgraph_edge *cs = fbi->node->get_edge (call);
    3264              :   /* If we previously turned the call into a direct call, there is
    3265              :      no need to analyze.  */
    3266       141288 :   if (cs && !cs->indirect_unknown_callee)
    3267              :     return;
    3268              : 
    3269       141288 :   cgraph_polymorphic_indirect_info *pii;
    3270       141288 :   if (flag_devirtualize
    3271       141288 :       && (pii
    3272       136810 :           = dyn_cast <cgraph_polymorphic_indirect_info *> (cs->indirect_info)))
    3273              :     {
    3274        24976 :       tree instance;
    3275        24976 :       tree target = gimple_call_fn (call);
    3276        24976 :       ipa_polymorphic_call_context context (current_function_decl,
    3277        24976 :                                             target, call, &instance);
    3278              : 
    3279        24976 :       gcc_checking_assert (pii->otr_type == obj_type_ref_class (target));
    3280        24976 :       gcc_checking_assert (pii->otr_token
    3281              :                            == tree_to_shwi (OBJ_TYPE_REF_TOKEN (target)));
    3282              : 
    3283        24976 :       pii->vptr_changed
    3284        49952 :         = !context.get_dynamic_type (instance,
    3285        24976 :                                      OBJ_TYPE_REF_OBJECT (target),
    3286              :                                      obj_type_ref_class (target), call,
    3287              :                                      &fbi->aa_walk_budget);
    3288        24976 :       pii->context = context;
    3289              :     }
    3290              : 
    3291       141288 :   if (TREE_CODE (target) == SSA_NAME)
    3292       116042 :     ipa_analyze_indirect_call_uses (fbi, call, target);
    3293        25246 :   else if (virtual_method_call_p (target))
    3294        25246 :     ipa_analyze_virtual_call_uses (fbi, call, target);
    3295              : }
    3296              : 
    3297              : /* Store that that there was a store of FN to a record of type REC_TYPE and
    3298              :    FLD_OFFSET.  */
    3299              : 
    3300              : static void
    3301        64072 : note_fnptr_in_record (tree rec_type, unsigned fld_offset, tree fn)
    3302              : {
    3303        64072 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
    3304        64072 :   gcc_assert (TREE_CODE (rec_type) == RECORD_TYPE);
    3305        64072 :   if (!noted_fnptrs_in_records)
    3306         6891 :     noted_fnptrs_in_records = hash_table<noted_fnptr_hasher>::create_ggc (37);
    3307              : 
    3308        64072 :   noted_fnptr_store repr;
    3309        64072 :   repr.rec_type = rec_type;
    3310        64072 :   repr.fld_offset = fld_offset;
    3311              : 
    3312        64072 :   noted_fnptr_store **slot = noted_fnptrs_in_records->find_slot (&repr,
    3313              :                                                                 NO_INSERT);
    3314        64072 :   if (slot)
    3315              :     {
    3316         8014 :       if ((*slot)->fn && (*slot)->fn != fn)
    3317          827 :         (*slot)->fn = nullptr;
    3318              :       return;
    3319              :     }
    3320              : 
    3321        56058 :   slot = noted_fnptrs_in_records->find_slot (&repr, INSERT);
    3322        56058 :   *slot = ggc_cleared_alloc<noted_fnptr_store> ();
    3323        56058 :   (*slot)->rec_type = rec_type;
    3324        56058 :   (*slot)->fn = fn;
    3325        56058 :   (*slot)->fld_offset = fld_offset;
    3326              : 
    3327        56058 :   return;
    3328              : }
    3329              : 
    3330              : /* Dump contents of noted_fnptrs_in_records to F in humad readable form.  */
    3331              : 
    3332              : void DEBUG_FUNCTION
    3333           41 : ipa_dump_noted_record_fnptrs (FILE *f)
    3334              : {
    3335           41 :   if (!noted_fnptrs_in_records)
    3336              :     {
    3337           38 :       fprintf (f, "No noted function pointers stored in records.\n\n");
    3338           38 :       return;
    3339              :     }
    3340              : 
    3341            3 :   fprintf (f, "Noted function pointers stored in records:\n");
    3342            7 :   for (auto iter = noted_fnptrs_in_records->begin ();
    3343            7 :        iter != noted_fnptrs_in_records->end ();
    3344            4 :        ++iter)
    3345              :     {
    3346            4 :       const noted_fnptr_store *elem = *iter;
    3347            4 :       fprintf (f, "  Type:");
    3348            4 :       print_generic_expr (f, elem->rec_type);
    3349            4 :       fprintf (f, ", offset %ul, function: ", elem->fld_offset);
    3350            4 :       print_generic_expr (f, elem->fn);
    3351            4 :       fprintf (f, "\n");
    3352              :     }
    3353            3 :   fprintf (f, "\n");
    3354              : }
    3355              : 
    3356              : /* Dump contents of noted_fnptrs_in_records to stderr in humad readable
    3357              :    form.  */
    3358              : 
    3359              : void DEBUG_FUNCTION
    3360            0 : ipa_debug_noted_record_fnptrs (void)
    3361              : {
    3362            0 :   ipa_dump_noted_record_fnptrs (stderr);
    3363            0 : }
    3364              : 
    3365              : 
    3366              : /* If we have noticed a single function pointer stored into a record of type
    3367              :    REC_TYPE at the given FLD_OFFSET (measured in bytes), return its
    3368              :    declaration.  Otherwise return NULL_TREE.  */
    3369              : 
    3370              : tree
    3371        38061 : ipa_single_noted_fnptr_in_record (tree rec_type, unsigned fld_offset)
    3372              : {
    3373        38061 :   if (!noted_fnptrs_in_records)
    3374              :     return NULL_TREE;
    3375              : 
    3376        35825 :   noted_fnptr_store repr;
    3377        35825 :   repr.rec_type = rec_type;
    3378        35825 :   repr.fld_offset = fld_offset;
    3379              : 
    3380        35825 :   noted_fnptr_store **slot = noted_fnptrs_in_records->find_slot (&repr,
    3381              :                                                                 NO_INSERT);
    3382        35825 :   if (!slot)
    3383              :     return NULL_TREE;
    3384         3742 :   return (*slot)->fn;
    3385              : }
    3386              : 
    3387              : /* Free the hash table storing the information about function pointers stored
    3388              :    to a particular position in record typed structures.  */
    3389              : 
    3390              : void
    3391       132665 : ipa_free_noted_fnptr_calls ()
    3392              : {
    3393       132665 :   if (noted_fnptrs_in_records)
    3394              :     {
    3395         6519 :       noted_fnptrs_in_records->empty ();
    3396         6519 :       noted_fnptrs_in_records = nullptr;
    3397              :     }
    3398       132665 : }
    3399              : 
    3400              : /* Analyze the call statement STMT with respect to formal parameters (described
    3401              :    in INFO) of caller given by FBI->NODE.  Also note any stores of function
    3402              :    pointers to record typed memory.   */
    3403              : 
    3404              : static void
    3405     32613669 : ipa_analyze_stmt_uses (struct ipa_func_body_info *fbi, gimple *stmt)
    3406              : {
    3407     32613669 :   if (is_gimple_call (stmt))
    3408      5946490 :     ipa_analyze_call_uses (fbi, as_a <gcall *> (stmt));
    3409     26667179 :   else if (gimple_assign_single_p (stmt)
    3410     14059778 :            && TREE_CODE (gimple_assign_rhs1 (stmt)) == ADDR_EXPR
    3411     27949748 :            && (TREE_CODE (TREE_OPERAND (gimple_assign_rhs1 (stmt), 0))
    3412              :                == FUNCTION_DECL))
    3413              :     {
    3414        31532 :       tree rec_type;
    3415        31532 :       unsigned fld_offset;
    3416        31532 :       if (is_func_ptr_from_record (gimple_assign_lhs (stmt), &rec_type,
    3417              :                                    &fld_offset, gimple_assign_rhs1 (stmt)))
    3418        11732 :         note_fnptr_in_record (rec_type, fld_offset,
    3419        11732 :                               TREE_OPERAND (gimple_assign_rhs1 (stmt), 0));
    3420              :     }
    3421     32613669 : }
    3422              : 
    3423              : /* Callback of walk_stmt_load_store_addr_ops for the visit_load.
    3424              :    If OP is a parameter declaration, mark it as used in the info structure
    3425              :    passed in DATA.  */
    3426              : 
    3427              : static bool
    3428     20408329 : visit_ref_for_mod_analysis (gimple *, tree op, tree, void *data)
    3429              : {
    3430     20408329 :   class ipa_node_params *info = (class ipa_node_params *) data;
    3431              : 
    3432     20408329 :   op = get_base_address (op);
    3433     20408329 :   if (op
    3434     20408329 :       && TREE_CODE (op) == PARM_DECL)
    3435              :     {
    3436       476657 :       int index = ipa_get_param_decl_index (info, op);
    3437       476657 :       gcc_assert (index >= 0);
    3438       476657 :       ipa_set_param_used (info, index, true);
    3439              :     }
    3440              : 
    3441     20408329 :   return false;
    3442              : }
    3443              : 
    3444              : /* Scan the statements in BB and inspect the uses of formal parameters.  Store
    3445              :    the findings in various structures of the associated ipa_node_params
    3446              :    structure, such as parameter flags, notes etc.  FBI holds various data about
    3447              :    the function being analyzed.  */
    3448              : 
    3449              : static void
    3450     11364545 : ipa_analyze_params_uses_in_bb (struct ipa_func_body_info *fbi, basic_block bb)
    3451              : {
    3452     11364545 :   gimple_stmt_iterator gsi;
    3453     81341432 :   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    3454              :     {
    3455     58612342 :       gimple *stmt = gsi_stmt (gsi);
    3456              : 
    3457     58612342 :       if (is_gimple_debug (stmt))
    3458     25998673 :         continue;
    3459              : 
    3460     32613669 :       ipa_analyze_stmt_uses (fbi, stmt);
    3461     32613669 :       walk_stmt_load_store_addr_ops (stmt, fbi->info,
    3462              :                                      visit_ref_for_mod_analysis,
    3463              :                                      visit_ref_for_mod_analysis,
    3464              :                                      visit_ref_for_mod_analysis);
    3465              :     }
    3466     14441895 :   for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    3467      3077350 :     walk_stmt_load_store_addr_ops (gsi_stmt (gsi), fbi->info,
    3468              :                                    visit_ref_for_mod_analysis,
    3469              :                                    visit_ref_for_mod_analysis,
    3470              :                                    visit_ref_for_mod_analysis);
    3471     11364545 : }
    3472              : 
    3473              : /* Return true EXPR is a load from a dereference of SSA_NAME NAME.  */
    3474              : 
    3475              : static bool
    3476      4319610 : load_from_dereferenced_name (tree expr, tree name)
    3477              : {
    3478      4319610 :   tree base = get_base_address (expr);
    3479      4319610 :   return (TREE_CODE (base) == MEM_REF
    3480      4319610 :           && TREE_OPERAND (base, 0) == name);
    3481              : }
    3482              : 
    3483              : /* Calculate controlled uses of parameters of NODE.  */
    3484              : 
    3485              : static void
    3486      1398503 : ipa_analyze_controlled_uses (struct cgraph_node *node)
    3487              : {
    3488      1398503 :   ipa_node_params *info = ipa_node_params_sum->get (node);
    3489              : 
    3490      7641053 :   for (int i = 0; i < ipa_get_param_count (info); i++)
    3491              :     {
    3492      2553199 :       tree parm = ipa_get_param (info, i);
    3493      2553199 :       int call_uses = 0;
    3494      2553199 :       bool load_dereferenced = false;
    3495              : 
    3496              :       /* For SSA regs see if parameter is used.  For non-SSA we compute
    3497              :          the flag during modification analysis.  */
    3498      2553199 :       if (is_gimple_reg (parm))
    3499              :         {
    3500      2315304 :           tree ddef = ssa_default_def (DECL_STRUCT_FUNCTION (node->decl),
    3501              :                                        parm);
    3502      2315304 :           if (ddef && !has_zero_uses (ddef))
    3503              :             {
    3504      2031301 :               imm_use_iterator imm_iter;
    3505      2031301 :               gimple *stmt;
    3506              : 
    3507      2031301 :               ipa_set_param_used (info, i, true);
    3508      4980550 :               FOR_EACH_IMM_USE_STMT (stmt, imm_iter, ddef)
    3509              :                 {
    3510      4110494 :                   if (is_gimple_debug (stmt))
    3511       800138 :                     continue;
    3512              : 
    3513      3310356 :                   int all_stmt_uses = 0;
    3514      3310356 :                   use_operand_p use_p;
    3515      6655119 :                   FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
    3516      3344763 :                     all_stmt_uses++;
    3517              : 
    3518      3310356 :                   if (is_gimple_call (stmt))
    3519              :                     {
    3520      1231354 :                       if (gimple_call_internal_p (stmt))
    3521              :                         {
    3522              :                           call_uses = IPA_UNDESCRIBED_USE;
    3523              :                           break;
    3524              :                         }
    3525      1175727 :                       int recognized_stmt_uses;
    3526      1175727 :                       if (gimple_call_fn (stmt) == ddef)
    3527              :                         recognized_stmt_uses = 1;
    3528              :                       else
    3529      1172013 :                         recognized_stmt_uses = 0;
    3530      1175727 :                       unsigned arg_count = gimple_call_num_args (stmt);
    3531      6395280 :                       for (unsigned i = 0; i < arg_count; i++)
    3532              :                         {
    3533      4043826 :                           tree arg = gimple_call_arg (stmt, i);
    3534      4043826 :                           if (arg == ddef)
    3535      1162160 :                             recognized_stmt_uses++;
    3536      2881666 :                           else if (load_from_dereferenced_name (arg, ddef))
    3537              :                             {
    3538        16226 :                               load_dereferenced = true;
    3539        16226 :                               recognized_stmt_uses++;
    3540              :                             }
    3541              :                         }
    3542              : 
    3543      1175727 :                       if (recognized_stmt_uses != all_stmt_uses)
    3544              :                         {
    3545              :                           call_uses = IPA_UNDESCRIBED_USE;
    3546              :                           break;
    3547              :                         }
    3548      1167805 :                       if (call_uses >= 0)
    3549      1167805 :                         call_uses += all_stmt_uses;
    3550              :                     }
    3551      2079002 :                   else if (gimple_assign_single_p (stmt))
    3552              :                     {
    3553      1438890 :                       tree rhs = gimple_assign_rhs1 (stmt);
    3554      1438890 :                       if (all_stmt_uses != 1
    3555      1438890 :                           || !load_from_dereferenced_name (rhs, ddef))
    3556              :                         {
    3557              :                           call_uses = IPA_UNDESCRIBED_USE;
    3558              :                           break;
    3559              :                         }
    3560              :                       load_dereferenced = true;
    3561              :                     }
    3562              :                   else
    3563              :                     {
    3564              :                       call_uses = IPA_UNDESCRIBED_USE;
    3565              :                       break;
    3566              :                     }
    3567      2031301 :                 }
    3568              :             }
    3569              :           else
    3570              :             call_uses = 0;
    3571              :         }
    3572              :       else
    3573              :         call_uses = IPA_UNDESCRIBED_USE;
    3574      2553199 :       ipa_set_controlled_uses (info, i, call_uses);
    3575      2553199 :       ipa_set_param_load_dereferenced (info, i, load_dereferenced);
    3576              :     }
    3577      1398503 : }
    3578              : 
    3579              : /* Free stuff in BI.  */
    3580              : 
    3581              : static void
    3582     65400141 : free_ipa_bb_info (struct ipa_bb_info *bi)
    3583              : {
    3584            0 :   bi->cg_edges.release ();
    3585     65400141 :   bi->param_aa_statuses.release ();
    3586            0 : }
    3587              : 
    3588              : /* Dominator walker driving the analysis.  */
    3589              : 
    3590      2797006 : class analysis_dom_walker : public dom_walker
    3591              : {
    3592              : public:
    3593      1398503 :   analysis_dom_walker (struct ipa_func_body_info *fbi)
    3594      2797006 :     : dom_walker (CDI_DOMINATORS), m_fbi (fbi) {}
    3595              : 
    3596              :   edge before_dom_children (basic_block) final override;
    3597              : 
    3598              : private:
    3599              :   struct ipa_func_body_info *m_fbi;
    3600              : };
    3601              : 
    3602              : edge
    3603     11364545 : analysis_dom_walker::before_dom_children (basic_block bb)
    3604              : {
    3605     11364545 :   ipa_analyze_params_uses_in_bb (m_fbi, bb);
    3606     11364545 :   ipa_compute_jump_functions_for_bb (m_fbi, bb);
    3607     11364545 :   return NULL;
    3608              : }
    3609              : 
    3610              : /* Release body info FBI.  */
    3611              : 
    3612              : void
    3613      8849217 : ipa_release_body_info (struct ipa_func_body_info *fbi)
    3614              : {
    3615      8849217 :   int i;
    3616      8849217 :   struct ipa_bb_info *bi;
    3617              : 
    3618     74224907 :   FOR_EACH_VEC_ELT (fbi->bb_infos, i, bi)
    3619    130751380 :     free_ipa_bb_info (bi);
    3620      8849217 :   fbi->bb_infos.release ();
    3621      8849217 : }
    3622              : 
    3623              : /* Initialize the array describing properties of formal parameters
    3624              :    of NODE, analyze their uses and compute jump functions associated
    3625              :    with actual arguments of calls from within NODE.  */
    3626              : 
    3627              : void
    3628      2743295 : ipa_analyze_node (struct cgraph_node *node)
    3629              : {
    3630      2743295 :   struct ipa_func_body_info fbi;
    3631      2743295 :   class ipa_node_params *info;
    3632              : 
    3633      2743295 :   ipa_check_create_node_params ();
    3634      2743295 :   ipa_check_create_edge_args ();
    3635      2743295 :   callback_info_sum_t::check_create_info_sum ();
    3636      2743295 :   info = ipa_node_params_sum->get_create (node);
    3637              : 
    3638      2743295 :   if (info->analysis_done)
    3639      1344792 :     return;
    3640      1399590 :   info->analysis_done = 1;
    3641              : 
    3642      1399590 :   if (ipa_func_spec_opts_forbid_analysis_p (node)
    3643      1399590 :       || (count_formal_params (node->decl)
    3644              :           >= (1 << IPA_PROP_ARG_INDEX_LIMIT_BITS)))
    3645              :     {
    3646      1344792 :       gcc_assert (!ipa_get_param_count (info));
    3647              :       return;
    3648              :     }
    3649              : 
    3650      1398503 :   struct function *func = DECL_STRUCT_FUNCTION (node->decl);
    3651      1398503 :   push_cfun (func);
    3652      1398503 :   calculate_dominance_info (CDI_DOMINATORS);
    3653      1398503 :   ipa_initialize_node_params (node);
    3654      1398503 :   ipa_analyze_controlled_uses (node);
    3655              : 
    3656      1398503 :   fbi.node = node;
    3657      1398503 :   fbi.info = info;
    3658      1398503 :   fbi.bb_infos = vNULL;
    3659      1398503 :   fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun), true);
    3660      1398503 :   fbi.param_count = ipa_get_param_count (info);
    3661      1398503 :   fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps);
    3662              : 
    3663      6971141 :   for (struct cgraph_edge *cs = node->callees; cs; cs = cs->next_callee)
    3664              :     {
    3665      5572638 :       ipa_bb_info *bi = ipa_get_bb_info (&fbi, gimple_bb (cs->call_stmt));
    3666      5572638 :       bi->cg_edges.safe_push (cs);
    3667              :     }
    3668              : 
    3669      1539871 :   for (struct cgraph_edge *cs = node->indirect_calls; cs; cs = cs->next_callee)
    3670              :     {
    3671       141368 :       ipa_bb_info *bi = ipa_get_bb_info (&fbi, gimple_bb (cs->call_stmt));
    3672       141368 :       bi->cg_edges.safe_push (cs);
    3673              :     }
    3674              : 
    3675      1398503 :   enable_ranger (cfun, false);
    3676      1398503 :   analysis_dom_walker (&fbi).walk (ENTRY_BLOCK_PTR_FOR_FN (cfun));
    3677      1398503 :   disable_ranger (cfun);
    3678              : 
    3679      1398503 :   ipa_release_body_info (&fbi);
    3680      1398503 :   free_dominance_info (CDI_DOMINATORS);
    3681      1398503 :   pop_cfun ();
    3682              : }
    3683              : 
    3684              : /* Analyze NODE and note any function pointers in record-typed static
    3685              :    initializers.
    3686              : 
    3687              :    TODO: The current implementation does not traverse the initializers to scan
    3688              :    records nested inside other types.  It should catch the most basic way of
    3689              :    writing "virtual functions" in C but can be extended, of course.
    3690              : */
    3691              : 
    3692              : void
    3693      1684542 : ipa_analyze_var_static_initializer (varpool_node *node)
    3694              : {
    3695      1684542 :   tree decl = node->decl;
    3696      1684542 :   tree rec_type = TREE_TYPE (decl);
    3697      1684542 :   if (TREE_CODE (rec_type) != RECORD_TYPE
    3698      1684542 :       || TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
    3699              :     return;
    3700              : 
    3701              :   unsigned ix;
    3702              :   tree index, val;
    3703      3868729 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)), ix, index,
    3704              :                             val)
    3705              :     {
    3706      5400022 :       if (TREE_CODE (val) != ADDR_EXPR
    3707      1014371 :           || TREE_CODE (TREE_OPERAND (val, 0)) != FUNCTION_DECL
    3708              :           /* ObjC can produce constructor elements with NULL indices.  */
    3709      2777522 :           || !index)
    3710      2674174 :         continue;
    3711        51674 :       HOST_WIDE_INT elt_offset = int_bit_position (index);
    3712        51674 :       if ((elt_offset % BITS_PER_UNIT) != 0)
    3713            0 :         continue;
    3714        51674 :       elt_offset = elt_offset / BITS_PER_UNIT;
    3715        51674 :       if (elt_offset > UINT_MAX)
    3716            0 :         continue;
    3717        51674 :       note_fnptr_in_record (rec_type, elt_offset, TREE_OPERAND (val, 0));
    3718              :     }
    3719              : }
    3720              : 
    3721              : /* Update the jump functions associated with call graph edge E when the call
    3722              :    graph edge CS is being inlined, assuming that E->caller is already (possibly
    3723              :    indirectly) inlined into CS->callee and that E has not been inlined.  */
    3724              : 
    3725              : static void
    3726      2795972 : update_jump_functions_after_inlining (struct cgraph_edge *cs,
    3727              :                                       struct cgraph_edge *e)
    3728              : {
    3729      2795972 :   ipa_edge_args *top = ipa_edge_args_sum->get (cs);
    3730      2795972 :   ipa_edge_args *args = ipa_edge_args_sum->get (e);
    3731      2795972 :   if (!args)
    3732              :     return;
    3733      1597151 :   ipa_node_params *old_inline_root_info = ipa_node_params_sum->get (cs->callee);
    3734      1597151 :   ipa_node_params *new_inline_root_info
    3735      1597151 :     = ipa_node_params_sum->get (cs->caller->inlined_to
    3736              :                                 ? cs->caller->inlined_to : cs->caller);
    3737      1597151 :   int count = ipa_get_cs_argument_count (args);
    3738      1597151 :   int i;
    3739              : 
    3740      4725456 :   for (i = 0; i < count; i++)
    3741              :     {
    3742      3128305 :       struct ipa_jump_func *dst = ipa_get_ith_jump_func (args, i);
    3743      3128305 :       class ipa_polymorphic_call_context *dst_ctx
    3744      3128305 :         = ipa_get_ith_polymorhic_call_context (args, i);
    3745              : 
    3746      3128305 :       if (dst->agg.items)
    3747              :         {
    3748              :           struct ipa_agg_jf_item *item;
    3749              :           int j;
    3750              : 
    3751       294119 :           FOR_EACH_VEC_ELT (*dst->agg.items, j, item)
    3752              :             {
    3753       199401 :               int dst_fid;
    3754       199401 :               struct ipa_jump_func *src;
    3755              : 
    3756       356755 :               if (item->jftype != IPA_JF_PASS_THROUGH
    3757       199401 :                   && item->jftype != IPA_JF_LOAD_AGG)
    3758       157354 :                 continue;
    3759              : 
    3760        42047 :               dst_fid = item->value.pass_through.formal_id;
    3761        84091 :               if (!top || dst_fid >= ipa_get_cs_argument_count (top))
    3762              :                 {
    3763            3 :                   item->jftype = IPA_JF_UNKNOWN;
    3764            3 :                   continue;
    3765              :                 }
    3766              : 
    3767        42044 :               item->value.pass_through.formal_id = -1;
    3768        42044 :               src = ipa_get_ith_jump_func (top, dst_fid);
    3769        42044 :               if (src->type == IPA_JF_CONST)
    3770              :                 {
    3771         2732 :                   if (item->jftype == IPA_JF_PASS_THROUGH
    3772         2323 :                       && item->value.pass_through.operation == NOP_EXPR)
    3773              :                     {
    3774         2255 :                       item->jftype = IPA_JF_CONST;
    3775         2255 :                       item->value.constant = src->value.constant.value;
    3776         2255 :                       continue;
    3777              :                     }
    3778              :                 }
    3779        39312 :               else if (src->type == IPA_JF_PASS_THROUGH
    3780         6032 :                        && src->value.pass_through.operation == NOP_EXPR)
    3781              :                 {
    3782         5869 :                   if (item->jftype == IPA_JF_PASS_THROUGH
    3783         3815 :                       || !item->value.load_agg.by_ref
    3784         2390 :                       || src->value.pass_through.agg_preserved)
    3785         4289 :                     item->value.pass_through.formal_id
    3786         4289 :                                 = src->value.pass_through.formal_id;
    3787              :                 }
    3788        33443 :               else if (src->type == IPA_JF_ANCESTOR)
    3789              :                 {
    3790         4568 :                   if (item->jftype == IPA_JF_PASS_THROUGH)
    3791              :                     {
    3792         1038 :                       if (!src->value.ancestor.offset)
    3793          729 :                         item->value.pass_through.formal_id
    3794          729 :                                 = src->value.ancestor.formal_id;
    3795              :                     }
    3796         3530 :                   else if (src->value.ancestor.agg_preserved)
    3797              :                     {
    3798         1472 :                       gcc_checking_assert (item->value.load_agg.by_ref);
    3799              : 
    3800         1472 :                       item->value.pass_through.formal_id
    3801         1472 :                                  = src->value.ancestor.formal_id;
    3802         1472 :                       item->value.load_agg.offset
    3803         1472 :                                 += src->value.ancestor.offset;
    3804              :                     }
    3805              :                 }
    3806              : 
    3807        39789 :               if (item->value.pass_through.formal_id < 0)
    3808        33299 :                 item->jftype = IPA_JF_UNKNOWN;
    3809              :             }
    3810              :         }
    3811              : 
    3812      3128305 :       if (!top)
    3813              :         {
    3814        13413 :           ipa_set_jf_unknown (dst);
    3815        13413 :           continue;
    3816              :         }
    3817              : 
    3818      3114892 :       if (dst->type == IPA_JF_ANCESTOR)
    3819              :         {
    3820       142989 :           struct ipa_jump_func *src;
    3821       142989 :           int dst_fid = dst->value.ancestor.formal_id;
    3822       142989 :           class ipa_polymorphic_call_context *src_ctx
    3823       142989 :             = ipa_get_ith_polymorhic_call_context (top, dst_fid);
    3824              : 
    3825              :           /* Variable number of arguments can cause havoc if we try to access
    3826              :              one that does not exist in the inlined edge.  So make sure we
    3827              :              don't.  */
    3828       285978 :           if (dst_fid >= ipa_get_cs_argument_count (top))
    3829              :             {
    3830            0 :               ipa_set_jf_unknown (dst);
    3831            0 :               continue;
    3832              :             }
    3833              : 
    3834       142989 :           src = ipa_get_ith_jump_func (top, dst_fid);
    3835              : 
    3836       142989 :           if (src_ctx && !src_ctx->useless_p ())
    3837              :             {
    3838        46579 :               class ipa_polymorphic_call_context ctx = *src_ctx;
    3839              : 
    3840              :               /* TODO: Make type preserved safe WRT contexts.  */
    3841        46579 :               if (!ipa_get_jf_ancestor_type_preserved (dst))
    3842        31989 :                 ctx.possible_dynamic_type_change (e->in_polymorphic_cdtor);
    3843        46579 :               ctx.offset_by (dst->value.ancestor.offset);
    3844        93158 :               if (!ctx.useless_p ())
    3845              :                 {
    3846        40740 :                   if (!dst_ctx)
    3847              :                     {
    3848         5351 :                       vec_safe_grow_cleared (args->polymorphic_call_contexts,
    3849              :                                              count, true);
    3850         5351 :                       dst_ctx = ipa_get_ith_polymorhic_call_context (args, i);
    3851              :                     }
    3852              : 
    3853        40740 :                   dst_ctx->combine_with (ctx);
    3854              :                 }
    3855              :             }
    3856              : 
    3857              :           /* Parameter and argument in ancestor jump function must be pointer
    3858              :              type, which means access to aggregate must be by-reference.  */
    3859       142989 :           gcc_assert (!src->agg.items || src->agg.by_ref);
    3860              : 
    3861       142989 :           if (src->agg.items && dst->value.ancestor.agg_preserved)
    3862              :             {
    3863         2413 :               struct ipa_agg_jf_item *item;
    3864         2413 :               int j;
    3865              : 
    3866              :               /* Currently we do not produce clobber aggregate jump functions,
    3867              :                  replace with merging when we do.  */
    3868         2413 :               gcc_assert (!dst->agg.items);
    3869              : 
    3870         2413 :               dst->agg.items = vec_safe_copy (src->agg.items);
    3871         2413 :               dst->agg.by_ref = src->agg.by_ref;
    3872         7671 :               FOR_EACH_VEC_SAFE_ELT (dst->agg.items, j, item)
    3873         5258 :                 item->offset -= dst->value.ancestor.offset;
    3874              :             }
    3875              : 
    3876       142989 :           if (src->type == IPA_JF_PASS_THROUGH
    3877        26039 :               && src->value.pass_through.operation == NOP_EXPR)
    3878              :             {
    3879        26035 :               dst->value.ancestor.formal_id = src->value.pass_through.formal_id;
    3880        26035 :               dst->value.ancestor.agg_preserved &=
    3881        26035 :                 src->value.pass_through.agg_preserved;
    3882              :             }
    3883       116954 :           else if (src->type == IPA_JF_ANCESTOR)
    3884              :             {
    3885         9780 :               dst->value.ancestor.formal_id = src->value.ancestor.formal_id;
    3886         9780 :               dst->value.ancestor.offset += src->value.ancestor.offset;
    3887         9780 :               dst->value.ancestor.agg_preserved &=
    3888         9780 :                 src->value.ancestor.agg_preserved;
    3889         9780 :               dst->value.ancestor.keep_null |= src->value.ancestor.keep_null;
    3890              :             }
    3891              :           else
    3892       107174 :             ipa_set_jf_unknown (dst);
    3893              :         }
    3894      2971903 :       else if (dst->type == IPA_JF_PASS_THROUGH)
    3895              :         {
    3896       827019 :           struct ipa_jump_func *src;
    3897              :           /* We must check range due to calls with variable number of arguments
    3898              :              and we cannot combine jump functions with operations.  */
    3899       827019 :           if (dst->value.pass_through.operation == NOP_EXPR
    3900       827019 :               && (top && dst->value.pass_through.formal_id
    3901       789581 :                   < ipa_get_cs_argument_count (top)))
    3902              :             {
    3903       789567 :               int dst_fid = dst->value.pass_through.formal_id;
    3904       789567 :               src = ipa_get_ith_jump_func (top, dst_fid);
    3905       789567 :               bool dst_agg_p = ipa_get_jf_pass_through_agg_preserved (dst);
    3906       789567 :               class ipa_polymorphic_call_context *src_ctx
    3907       915862 :                 = ipa_get_ith_polymorhic_call_context (top, dst_fid);
    3908              : 
    3909       126295 :               if (src_ctx && !src_ctx->useless_p ())
    3910              :                 {
    3911        73698 :                   class ipa_polymorphic_call_context ctx = *src_ctx;
    3912              : 
    3913              :                   /* TODO: Make type preserved safe WRT contexts.  */
    3914        73698 :                   if (!ipa_get_jf_pass_through_type_preserved (dst))
    3915        31404 :                     ctx.possible_dynamic_type_change (e->in_polymorphic_cdtor);
    3916       147396 :                   if (!ctx.useless_p ())
    3917              :                     {
    3918        70170 :                       if (!dst_ctx)
    3919              :                         {
    3920        13677 :                           vec_safe_grow_cleared (args->polymorphic_call_contexts,
    3921              :                                                  count, true);
    3922        13677 :                           dst_ctx = ipa_get_ith_polymorhic_call_context (args, i);
    3923              :                         }
    3924        70170 :                       dst_ctx->combine_with (ctx);
    3925              :                     }
    3926              :                 }
    3927       789567 :               switch (src->type)
    3928              :                 {
    3929       343932 :                 case IPA_JF_UNKNOWN:
    3930       343932 :                   ipa_set_jf_unknown (dst);
    3931       343932 :                   break;
    3932       160488 :                 case IPA_JF_CONST:
    3933       160488 :                   ipa_convert_prop_cst_jf (dst, src,
    3934              :                                            ipa_get_type (old_inline_root_info,
    3935              :                                                          dst_fid));
    3936       160488 :                   break;
    3937              : 
    3938       258870 :                 case IPA_JF_PASS_THROUGH:
    3939       258870 :                   {
    3940       258870 :                     int formal_id = ipa_get_jf_pass_through_formal_id (src);
    3941       258870 :                     enum tree_code operation;
    3942       258870 :                     operation = ipa_get_jf_pass_through_operation (src);
    3943              : 
    3944       258870 :                     tree old_ir_ptype = ipa_get_type (old_inline_root_info,
    3945              :                                                       dst_fid);
    3946       258870 :                     tree new_ir_ptype = ipa_get_type (new_inline_root_info,
    3947              :                                                       formal_id);
    3948       258870 :                     if (!useless_type_conversion_p (old_ir_ptype, new_ir_ptype))
    3949              :                       {
    3950              :                         /* Jump-function construction now permits type-casts
    3951              :                            from an integer to another if the latter can hold
    3952              :                            all values or has at least the same precision.
    3953              :                            However, as we're combining multiple pass-through
    3954              :                            functions together, we are losing information about
    3955              :                            signedness and thus if conversions should sign or
    3956              :                            zero extend.  Therefore we must prevent combining
    3957              :                            such jump-function if signednesses do not match.  */
    3958         1819 :                         if (!INTEGRAL_TYPE_P (old_ir_ptype)
    3959          956 :                             || !INTEGRAL_TYPE_P (new_ir_ptype)
    3960         1912 :                             || (TYPE_UNSIGNED (new_ir_ptype)
    3961          956 :                                 != TYPE_UNSIGNED (old_ir_ptype)))
    3962              :                           {
    3963          863 :                             ipa_set_jf_unknown (dst);
    3964          863 :                             continue;
    3965              :                           }
    3966              :                       }
    3967              : 
    3968       258007 :                     if (operation == NOP_EXPR)
    3969              :                       {
    3970       256643 :                         bool agg_p;
    3971       513286 :                         agg_p = dst_agg_p
    3972       256643 :                           && ipa_get_jf_pass_through_agg_preserved (src);
    3973       256643 :                         ipa_set_jf_simple_pass_through (dst, formal_id, agg_p);
    3974              :                       }
    3975         1364 :                     else if (TREE_CODE_CLASS (operation) == tcc_unary)
    3976              :                       {
    3977            8 :                         tree op_t = ipa_get_jf_pass_through_op_type (src);
    3978            8 :                         ipa_set_jf_unary_pass_through (dst, formal_id, operation,
    3979              :                                                        op_t);
    3980              :                       }
    3981              :                     else
    3982              :                       {
    3983         1356 :                         tree operand = ipa_get_jf_pass_through_operand (src);
    3984         1356 :                         tree op_t = ipa_get_jf_pass_through_op_type (src);
    3985         1356 :                         ipa_set_jf_arith_pass_through (dst, formal_id, operand,
    3986              :                                                        operation, op_t);
    3987              :                       }
    3988              :                     break;
    3989              :                   }
    3990        26277 :                 case IPA_JF_ANCESTOR:
    3991        26277 :                   {
    3992        26277 :                     bool agg_p;
    3993        52554 :                     agg_p = dst_agg_p
    3994        26277 :                       && ipa_get_jf_ancestor_agg_preserved (src);
    3995        26277 :                     ipa_set_ancestor_jf (dst,
    3996              :                                          ipa_get_jf_ancestor_offset (src),
    3997              :                                          ipa_get_jf_ancestor_formal_id (src),
    3998              :                                          agg_p,
    3999              :                                          ipa_get_jf_ancestor_keep_null (src));
    4000        26277 :                     break;
    4001              :                   }
    4002            0 :                 default:
    4003            0 :                   gcc_unreachable ();
    4004              :                 }
    4005              : 
    4006       788704 :               if (src->m_vr && src->m_vr->known_p ())
    4007              :                 {
    4008       527440 :                   value_range svr (src->m_vr->type ());
    4009       527440 :                   if (!dst->m_vr || !dst->m_vr->known_p ())
    4010       210905 :                     ipa_set_jfunc_vr (dst, *src->m_vr);
    4011       316535 :                   else if (ipa_vr_operation_and_type_effects (svr, *src->m_vr,
    4012              :                                                            NOP_EXPR,
    4013       316535 :                                                            dst->m_vr->type (),
    4014       316535 :                                                            src->m_vr->type ()))
    4015              :                     {
    4016       316526 :                       value_range dvr;
    4017       316526 :                       dst->m_vr->get_vrange (dvr);
    4018       316526 :                       dvr.intersect (svr);
    4019       316526 :                       if (!dvr.undefined_p ())
    4020       303804 :                         ipa_set_jfunc_vr (dst, dvr);
    4021       316526 :                     }
    4022       527440 :                 }
    4023              : 
    4024       788704 :               if (src->agg.items
    4025        31957 :                   && (dst_agg_p || !src->agg.by_ref))
    4026              :                 {
    4027              :                   /* Currently we do not produce clobber aggregate jump
    4028              :                      functions, replace with merging when we do.  */
    4029        23917 :                   gcc_assert (!dst->agg.items);
    4030              : 
    4031        23917 :                   dst->agg.by_ref = src->agg.by_ref;
    4032        23917 :                   dst->agg.items = vec_safe_copy (src->agg.items);
    4033              :                 }
    4034              :             }
    4035              :           else
    4036        37452 :             ipa_set_jf_unknown (dst);
    4037              :         }
    4038              :     }
    4039              : }
    4040              : 
    4041              : /* If TARGET is an addr_expr of a function declaration, make it the
    4042              :    (SPECULATIVE)destination of an indirect edge IE and return the edge.
    4043              :    Otherwise, return NULL.  */
    4044              : 
    4045              : struct cgraph_edge *
    4046         4165 : ipa_make_edge_direct_to_target (struct cgraph_edge *ie, tree target,
    4047              :                                 bool speculative)
    4048              : {
    4049         4165 :   struct cgraph_node *callee;
    4050         4165 :   bool unreachable = false;
    4051              : 
    4052         4165 :   if (TREE_CODE (target) == ADDR_EXPR)
    4053         1381 :     target = TREE_OPERAND (target, 0);
    4054         4165 :   if (TREE_CODE (target) != FUNCTION_DECL)
    4055              :     {
    4056           17 :       target = canonicalize_constructor_val (target, NULL);
    4057           17 :       if (!target || TREE_CODE (target) != FUNCTION_DECL)
    4058              :         {
    4059           17 :           cgraph_simple_indirect_info *sii
    4060           17 :             = dyn_cast <cgraph_simple_indirect_info *> (ie->indirect_info);
    4061              :           /* Member pointer call that goes through a VMT lookup.  */
    4062           17 :           if ((sii && sii->member_ptr)
    4063              :               /* Or if target is not an invariant expression and we do not
    4064              :                  know if it will evaluate to function at runtime.
    4065              :                  This can happen when folding through &VAR, where &VAR
    4066              :                  is IP invariant, but VAR itself is not.
    4067              : 
    4068              :                  TODO: It seems that we may try to fold the expression and see
    4069              :                  if VAR is readonly.  */
    4070           11 :               || !is_gimple_ip_invariant (target))
    4071              :             {
    4072            6 :               if (dump_enabled_p ())
    4073              :                 {
    4074            0 :                   dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, ie->call_stmt,
    4075              :                                    "discovered direct call non-invariant %s\n",
    4076            0 :                                    ie->caller->dump_name ());
    4077              :                 }
    4078              :               return NULL;
    4079              :             }
    4080              : 
    4081              : 
    4082           11 :           if (dump_enabled_p ())
    4083              :             {
    4084            0 :               dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, ie->call_stmt,
    4085              :                                "discovered direct call to non-function in %s, "
    4086              :                                "making it __builtin_unreachable\n",
    4087            0 :                                ie->caller->dump_name ());
    4088              :             }
    4089              : 
    4090           11 :           target = builtin_decl_unreachable ();
    4091           11 :           callee = cgraph_node::get_create (target);
    4092           11 :           unreachable = true;
    4093           11 :         }
    4094              :       else
    4095            0 :         callee = cgraph_node::get (target);
    4096              :     }
    4097              :   else
    4098         4148 :     callee = cgraph_node::get (target);
    4099              : 
    4100              :   /* Because may-edges are not explicitly represented and vtable may be external,
    4101              :      we may create the first reference to the object in the unit.  */
    4102         4159 :   if (!callee || callee->inlined_to)
    4103              :     {
    4104              : 
    4105              :       /* We are better to ensure we can refer to it.
    4106              :          In the case of static functions we are out of luck, since we already
    4107              :          removed its body.  In the case of public functions we may or may
    4108              :          not introduce the reference.  */
    4109            0 :       if (!canonicalize_constructor_val (target, NULL)
    4110            0 :           || !TREE_PUBLIC (target))
    4111              :         {
    4112            0 :           if (dump_file)
    4113            0 :             fprintf (dump_file, "ipa-prop: Discovered call to a known target "
    4114              :                      "(%s -> %s) but cannot refer to it.  Giving up.\n",
    4115            0 :                      ie->caller->dump_name (),
    4116            0 :                      ie->callee->dump_name ());
    4117              :           return NULL;
    4118              :         }
    4119            0 :       callee = cgraph_node::get_create (target);
    4120              :     }
    4121              : 
    4122              :   /* If the edge is already speculated.  */
    4123         4159 :   if (speculative && ie->speculative)
    4124              :     {
    4125            2 :       if (dump_file)
    4126              :         {
    4127            0 :           cgraph_edge *e2 = ie->speculative_call_for_target (callee);
    4128            0 :           if (!e2)
    4129              :             {
    4130            0 :               if (dump_file)
    4131            0 :                 fprintf (dump_file, "ipa-prop: Discovered call to a "
    4132              :                          "speculative target (%s -> %s) but the call is "
    4133              :                          "already speculated to different target.  "
    4134              :                          "Giving up.\n",
    4135            0 :                          ie->caller->dump_name (), callee->dump_name ());
    4136              :             }
    4137              :           else
    4138              :             {
    4139            0 :               if (dump_file)
    4140            0 :                 fprintf (dump_file,
    4141              :                          "ipa-prop: Discovered call to a speculative target "
    4142              :                          "(%s -> %s) this agree with previous speculation.\n",
    4143            0 :                          ie->caller->dump_name (), callee->dump_name ());
    4144              :             }
    4145              :         }
    4146              :       return NULL;
    4147              :     }
    4148              : 
    4149         4157 :   if (!dbg_cnt (devirt))
    4150              :     return NULL;
    4151              : 
    4152         4157 :   ipa_check_create_node_params ();
    4153              : 
    4154              :   /* We cannot make edges to inline clones.  It is bug that someone removed
    4155              :      the cgraph node too early.  */
    4156         4157 :   gcc_assert (!callee->inlined_to);
    4157              : 
    4158         4157 :   if (dump_file && !unreachable)
    4159              :     {
    4160          402 :       fprintf (dump_file, "ipa-prop: Discovered %s call to a %s target "
    4161              :                "(%s -> %s), for stmt ",
    4162          402 :                is_a <cgraph_polymorphic_indirect_info *> (ie->indirect_info)
    4163              :                ? "a virtual" : "an indirect",
    4164              :                speculative ? "speculative" : "known",
    4165          201 :                ie->caller->dump_name (),
    4166              :                callee->dump_name ());
    4167          201 :       if (ie->call_stmt)
    4168          193 :         print_gimple_stmt (dump_file, ie->call_stmt, 2, TDF_SLIM);
    4169              :       else
    4170            8 :         fprintf (dump_file, "with uid %i\n", ie->lto_stmt_uid);
    4171              :      }
    4172         4157 :   if (dump_enabled_p ())
    4173              :     {
    4174          402 :       dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, ie->call_stmt,
    4175              :                        "converting indirect call in %s to direct call to %s\n",
    4176          201 :                        ie->caller->dump_name (), callee->dump_name ());
    4177              :     }
    4178         4157 :   if (!speculative)
    4179              :     {
    4180         4120 :       struct cgraph_edge *orig = ie;
    4181         4120 :       ie = cgraph_edge::make_direct (ie, callee);
    4182              :       /* If we resolved speculative edge the cost is already up to date
    4183              :          for direct call (adjusted by inline_edge_duplication_hook).  */
    4184         4120 :       if (ie == orig)
    4185              :         {
    4186         3232 :           ipa_call_summary *es = ipa_call_summaries->get (ie);
    4187         3232 :           es->call_stmt_size -= (eni_size_weights.indirect_call_cost
    4188         3232 :                                  - eni_size_weights.call_cost);
    4189         3232 :           es->call_stmt_time -= (eni_time_weights.indirect_call_cost
    4190         3232 :                                  - eni_time_weights.call_cost);
    4191              :         }
    4192              :     }
    4193              :   else
    4194              :     {
    4195           37 :       if (!callee->can_be_discarded_p ())
    4196              :         {
    4197            4 :           cgraph_node *alias;
    4198            4 :           alias = dyn_cast<cgraph_node *> (callee->noninterposable_alias ());
    4199              :           if (alias)
    4200           37 :             callee = alias;
    4201              :         }
    4202              :       /* make_speculative will update ie's cost to direct call cost. */
    4203           37 :       ie = ie->make_speculative
    4204           37 :              (callee, ie->count.apply_scale (8, 10));
    4205              :     }
    4206              : 
    4207              :   return ie;
    4208              : }
    4209              : 
    4210              : /* Attempt to locate an interprocedural constant at a given REQ_OFFSET in
    4211              :    CONSTRUCTOR and return it.  Return NULL if the search fails for some
    4212              :    reason.  */
    4213              : 
    4214              : static tree
    4215        15927 : find_constructor_constant_at_offset (tree constructor, HOST_WIDE_INT req_offset)
    4216              : {
    4217        22571 :   tree type = TREE_TYPE (constructor);
    4218        22571 :   if (TREE_CODE (type) != ARRAY_TYPE
    4219        22571 :       && TREE_CODE (type) != RECORD_TYPE)
    4220              :     return NULL;
    4221              : 
    4222        22559 :   unsigned ix;
    4223        22559 :   tree index, val;
    4224        28672 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (constructor), ix, index, val)
    4225              :     {
    4226        28012 :       HOST_WIDE_INT elt_offset;
    4227        28012 :       if (TREE_CODE (type) == ARRAY_TYPE)
    4228              :        {
    4229          318 :          offset_int off;
    4230          318 :          tree unit_size = TYPE_SIZE_UNIT (TREE_TYPE (type));
    4231          318 :          gcc_assert (TREE_CODE (unit_size) == INTEGER_CST);
    4232              : 
    4233          318 :          if (index)
    4234              :            {
    4235          318 :              if (TREE_CODE (index) == RANGE_EXPR)
    4236           60 :                off = wi::to_offset (TREE_OPERAND (index, 0));
    4237              :              else
    4238          258 :                off = wi::to_offset (index);
    4239          318 :              if (TYPE_DOMAIN (type) && TYPE_MIN_VALUE (TYPE_DOMAIN (type)))
    4240              :                {
    4241          318 :                  tree low_bound = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
    4242          318 :                  gcc_assert (TREE_CODE (unit_size) == INTEGER_CST);
    4243          318 :                  off = wi::sext (off - wi::to_offset (low_bound),
    4244          318 :                                  TYPE_PRECISION (TREE_TYPE (index)));
    4245              :                }
    4246          318 :              off *= wi::to_offset (unit_size);
    4247              :              /* ???  Handle more than just the first index of a
    4248              :                 RANGE_EXPR.  */
    4249              :            }
    4250              :          else
    4251            0 :            off = wi::to_offset (unit_size) * ix;
    4252              : 
    4253          318 :          off = wi::lshift (off, LOG2_BITS_PER_UNIT);
    4254          318 :          if (!wi::fits_shwi_p (off) || wi::neg_p (off))
    4255            0 :            continue;
    4256          318 :          elt_offset = off.to_shwi ();
    4257              :        }
    4258        27694 :       else if (TREE_CODE (type) == RECORD_TYPE)
    4259              :        {
    4260        27694 :          gcc_checking_assert (index && TREE_CODE (index) == FIELD_DECL);
    4261        27694 :          if (DECL_BIT_FIELD (index))
    4262            0 :            continue;
    4263        27694 :          elt_offset = int_bit_position (index);
    4264              :        }
    4265              :       else
    4266            0 :        gcc_unreachable ();
    4267              : 
    4268        28012 :       if (elt_offset > req_offset)
    4269              :         return NULL;
    4270              : 
    4271        28012 :       if (TREE_CODE (val) == CONSTRUCTOR)
    4272         6644 :         return find_constructor_constant_at_offset (val,
    4273         6644 :                                                     req_offset - elt_offset);
    4274              : 
    4275        21368 :       if (elt_offset == req_offset
    4276        15915 :           && is_gimple_reg_type (TREE_TYPE (val))
    4277        37283 :           && is_gimple_ip_invariant (val))
    4278              :         return val;
    4279              :     }
    4280              :   return NULL;
    4281              : }
    4282              : 
    4283              : /* Check whether SCALAR could be used to look up an aggregate interprocedural
    4284              :    invariant from a static constructor and if so, return it.  Otherwise return
    4285              :    NULL. */
    4286              : 
    4287              : tree
    4288     14063705 : ipa_find_agg_cst_from_init (tree scalar, HOST_WIDE_INT offset, bool by_ref)
    4289              : {
    4290     14063705 :   if (by_ref)
    4291              :     {
    4292     14049859 :       if (TREE_CODE (scalar) != ADDR_EXPR)
    4293              :         return NULL;
    4294      4463742 :       scalar = TREE_OPERAND (scalar, 0);
    4295              :     }
    4296              : 
    4297      4477588 :   if (!VAR_P (scalar)
    4298      2927460 :       || !is_global_var (scalar)
    4299       311224 :       || !TREE_READONLY (scalar)
    4300        21800 :       || !DECL_INITIAL (scalar)
    4301      4496907 :       || TREE_CODE (DECL_INITIAL (scalar)) != CONSTRUCTOR)
    4302              :     return NULL;
    4303              : 
    4304        15927 :   return find_constructor_constant_at_offset (DECL_INITIAL (scalar), offset);
    4305              : }
    4306              : 
    4307              : /* Retrieve value from AGG_JFUNC for the given OFFSET or return NULL if there
    4308              :    is none.  BY_REF specifies whether the value has to be passed by reference
    4309              :    or by value.  */
    4310              : 
    4311              : static tree
    4312        24725 : ipa_find_agg_cst_from_jfunc_items (struct ipa_agg_jump_function *agg_jfunc,
    4313              :                                    ipa_node_params *src_info,
    4314              :                                    cgraph_node *src_node,
    4315              :                                    HOST_WIDE_INT offset, bool by_ref)
    4316              : {
    4317        24725 :   if (by_ref != agg_jfunc->by_ref)
    4318              :     return NULL_TREE;
    4319              : 
    4320         4457 :   for (const ipa_agg_jf_item &item : agg_jfunc->items)
    4321         1580 :     if (item.offset == offset)
    4322         1166 :       return ipa_agg_value_from_jfunc (src_info, src_node, &item);
    4323              : 
    4324              :   return NULL_TREE;
    4325              : }
    4326              : 
    4327              : /* Remove a reference to SYMBOL from the list of references of a node given by
    4328              :    reference description RDESC.  Return true if the reference has been
    4329              :    successfully found and removed.  */
    4330              : 
    4331              : static bool
    4332         9203 : remove_described_reference (symtab_node *symbol, struct ipa_cst_ref_desc *rdesc)
    4333              : {
    4334         9203 :   struct ipa_ref *to_del;
    4335         9203 :   struct cgraph_edge *origin;
    4336              : 
    4337         9203 :   origin = rdesc->cs;
    4338         9203 :   if (!origin)
    4339              :     return false;
    4340         9203 :   to_del = origin->caller->find_reference (symbol, origin->call_stmt,
    4341              :                                            origin->lto_stmt_uid, IPA_REF_ADDR);
    4342         9203 :   if (!to_del)
    4343              :     return false;
    4344              : 
    4345         9203 :   to_del->remove_reference ();
    4346         9203 :   if (dump_file)
    4347           26 :     fprintf (dump_file, "ipa-prop: Removed a reference from %s to %s.\n",
    4348           13 :              origin->caller->dump_name (), symbol->dump_name ());
    4349              :   return true;
    4350              : }
    4351              : 
    4352              : /* If JFUNC has a reference description with refcount different from
    4353              :    IPA_UNDESCRIBED_USE, return the reference description, otherwise return
    4354              :    NULL.  JFUNC must be a constant jump function.  */
    4355              : 
    4356              : static struct ipa_cst_ref_desc *
    4357      1366223 : jfunc_rdesc_usable (struct ipa_jump_func *jfunc)
    4358              : {
    4359      1366223 :   struct ipa_cst_ref_desc *rdesc = ipa_get_jf_constant_rdesc (jfunc);
    4360      1366223 :   if (rdesc && rdesc->refcount != IPA_UNDESCRIBED_USE)
    4361              :     return rdesc;
    4362              :   else
    4363      1170752 :     return NULL;
    4364              : }
    4365              : 
    4366              : /* If the value of constant jump function JFUNC is an address of a function
    4367              :    declaration, return the associated call graph node.  Otherwise return
    4368              :    NULL.  */
    4369              : 
    4370              : static symtab_node *
    4371         1826 : symtab_node_for_jfunc (struct ipa_jump_func *jfunc)
    4372              : {
    4373         1826 :   gcc_checking_assert (jfunc->type == IPA_JF_CONST);
    4374         1826 :   tree cst = ipa_get_jf_constant (jfunc);
    4375         1826 :   if (TREE_CODE (cst) != ADDR_EXPR
    4376         1826 :       || (TREE_CODE (TREE_OPERAND (cst, 0)) != FUNCTION_DECL
    4377           35 :           && TREE_CODE (TREE_OPERAND (cst, 0)) != VAR_DECL))
    4378              :     return NULL;
    4379              : 
    4380         1816 :   return symtab_node::get (TREE_OPERAND (cst, 0));
    4381              : }
    4382              : 
    4383              : 
    4384              : /* If JFUNC is a constant jump function with a usable rdesc, decrement its
    4385              :    refcount and if it hits zero, remove reference to SYMBOL from the caller of
    4386              :    the edge specified in the rdesc.  Return false if either the symbol or the
    4387              :    reference could not be found, otherwise return true.  */
    4388              : 
    4389              : static bool
    4390         1003 : try_decrement_rdesc_refcount (struct ipa_jump_func *jfunc)
    4391              : {
    4392         1003 :   struct ipa_cst_ref_desc *rdesc;
    4393         1003 :   if (jfunc->type == IPA_JF_CONST
    4394         1003 :       && (rdesc = jfunc_rdesc_usable (jfunc))
    4395         1979 :       && --rdesc->refcount == 0)
    4396              :     {
    4397          782 :       symtab_node *symbol = symtab_node_for_jfunc (jfunc);
    4398          782 :       if (!symbol)
    4399              :         return false;
    4400              : 
    4401          782 :       return remove_described_reference (symbol, rdesc);
    4402              :     }
    4403              :   return true;
    4404              : }
    4405              : 
    4406              : /* Try to find a destination for indirect edge IE that corresponds to a simple
    4407              :    call or a call of a member function pointer and where the destination is a
    4408              :    pointer formal parameter described by jump function JFUNC.  TARGET_TYPE is
    4409              :    the type of the parameter to which the result of JFUNC is passed.  If it can
    4410              :    be determined, return the newly direct edge, otherwise return NULL.
    4411              :    NEW_ROOT and NEW_ROOT_INFO is the node and its info that JFUNC lattices are
    4412              :    relative to.  */
    4413              : 
    4414              : static struct cgraph_edge *
    4415         9691 : try_make_edge_direct_simple_call (struct cgraph_edge *ie,
    4416              :                                   struct ipa_jump_func *jfunc, tree target_type,
    4417              :                                   struct cgraph_node *new_root,
    4418              :                                   class ipa_node_params *new_root_info)
    4419              : {
    4420         9691 :   tree target = NULL_TREE;
    4421         9691 :   cgraph_simple_indirect_info *sii
    4422         9691 :     = as_a <cgraph_simple_indirect_info *> (ie->indirect_info);
    4423         9691 :   bool agg_contents = sii->agg_contents;
    4424         9691 :   tree scalar = ipa_value_from_jfunc (new_root_info, jfunc, target_type);
    4425         9691 :   if (agg_contents)
    4426              :     {
    4427         7482 :       if (scalar)
    4428           23 :         target = ipa_find_agg_cst_from_init (scalar, sii->offset, sii->by_ref);
    4429         7482 :       if (!target && sii->guaranteed_unmodified)
    4430         6099 :         target = ipa_find_agg_cst_from_jfunc_items (&jfunc->agg, new_root_info,
    4431              :                                                     new_root, sii->offset,
    4432              :                                                     sii->by_ref);
    4433              :     }
    4434              :   else
    4435              :     target = scalar;
    4436         9690 :   if (!target)
    4437              :     return NULL;
    4438         1398 :   cgraph_edge *cs = ipa_make_edge_direct_to_target (ie, target);
    4439              : 
    4440         1398 :   if (cs && !agg_contents)
    4441              :     {
    4442         1003 :       bool ok;
    4443         1003 :       gcc_checking_assert (cs->callee
    4444              :                            && (cs != ie
    4445              :                                || jfunc->type != IPA_JF_CONST
    4446              :                                || !symtab_node_for_jfunc (jfunc)
    4447              :                                || cs->callee == symtab_node_for_jfunc (jfunc)));
    4448         1003 :       ok = try_decrement_rdesc_refcount (jfunc);
    4449         1003 :       gcc_checking_assert (ok);
    4450              :     }
    4451              : 
    4452              :   return cs;
    4453              : }
    4454              : 
    4455              : /* Return the target to be used in cases of impossible devirtualization.  IE
    4456              :    and target (the latter can be NULL) are dumped when dumping is enabled.  */
    4457              : 
    4458              : tree
    4459          508 : ipa_impossible_devirt_target (struct cgraph_edge *ie, tree target)
    4460              : {
    4461          508 :   if (dump_file)
    4462              :     {
    4463           57 :       if (target)
    4464           18 :         fprintf (dump_file,
    4465              :                  "Type inconsistent devirtualization: %s->%s\n",
    4466           18 :                  ie->caller->dump_name (),
    4467           18 :                  IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (target)));
    4468              :       else
    4469           39 :         fprintf (dump_file,
    4470              :                  "No devirtualization target in %s\n",
    4471           39 :                  ie->caller->dump_name ());
    4472              :     }
    4473          508 :   tree new_target = builtin_decl_unreachable ();
    4474          508 :   cgraph_node::get_create (new_target);
    4475          508 :   return new_target;
    4476              : }
    4477              : 
    4478              : /* Try to find a destination for indirect edge IE that corresponds to a virtual
    4479              :    call based on a formal parameter which is described by jump function JFUNC
    4480              :    and if it can be determined, make it direct and return the direct edge.
    4481              :    Otherwise, return NULL.  CTX describes the polymorphic context that the
    4482              :    parameter the call is based on brings along with it.  NEW_ROOT and
    4483              :    NEW_ROOT_INFO is the node and its info that JFUNC lattices are relative
    4484              :    to.  */
    4485              : 
    4486              : static struct cgraph_edge *
    4487        18629 : try_make_edge_direct_virtual_call (struct cgraph_edge *ie,
    4488              :                                    struct ipa_jump_func *jfunc,
    4489              :                                    class ipa_polymorphic_call_context ctx,
    4490              :                                    struct cgraph_node *new_root,
    4491              :                                    class ipa_node_params *new_root_info)
    4492              : {
    4493        18629 :   tree target = NULL;
    4494        18629 :   bool speculative = false;
    4495              : 
    4496        18629 :   if (!opt_for_fn (ie->caller->decl, flag_devirtualize))
    4497              :     return NULL;
    4498        18629 :   cgraph_polymorphic_indirect_info *pii
    4499        18629 :     = as_a <cgraph_polymorphic_indirect_info *> (ie->indirect_info);
    4500        18629 :   if (!pii->usable_p ())
    4501              :     return nullptr;
    4502              : 
    4503              :   /* Try to do lookup via known virtual table pointer value.  */
    4504        18629 :   if (!pii->vptr_changed
    4505        18629 :       || opt_for_fn (ie->caller->decl, flag_devirtualize_speculatively))
    4506              :     {
    4507        18629 :       tree vtable;
    4508        18629 :       unsigned HOST_WIDE_INT offset;
    4509        18629 :       tree t = NULL_TREE;
    4510        18629 :       if (jfunc->type == IPA_JF_CONST)
    4511          330 :         t = ipa_find_agg_cst_from_init (ipa_get_jf_constant (jfunc),
    4512              :                                         pii->offset, true);
    4513          330 :       if (!t)
    4514        18626 :         t = ipa_find_agg_cst_from_jfunc_items (&jfunc->agg, new_root_info,
    4515              :                                                new_root, pii->offset, true);
    4516        18629 :       if (t && vtable_pointer_value_to_vtable (t, &vtable, &offset))
    4517              :         {
    4518          754 :           bool can_refer;
    4519          754 :           t = gimple_get_virt_method_for_vtable (pii->otr_token, vtable, offset,
    4520              :                                                  &can_refer);
    4521          754 :           if (can_refer)
    4522              :             {
    4523          737 :               if (!t
    4524          737 :                   || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE,
    4525              :                                            BUILT_IN_UNREACHABLE_TRAP)
    4526         1426 :                   || !possible_polymorphic_call_target_p
    4527          689 :                        (ie, cgraph_node::get (t)))
    4528              :                 {
    4529              :                   /* Do not speculate builtin_unreachable, it is stupid!  */
    4530           90 :                   if (!pii->vptr_changed)
    4531           90 :                     target = ipa_impossible_devirt_target (ie, target);
    4532              :                   else
    4533              :                     target = NULL;
    4534              :                 }
    4535              :               else
    4536              :                 {
    4537          647 :                   target = t;
    4538          647 :                   speculative = pii->vptr_changed;
    4539              :                 }
    4540              :             }
    4541              :         }
    4542              :     }
    4543              : 
    4544        18629 :   ipa_polymorphic_call_context ie_context (ie);
    4545        18629 :   vec <cgraph_node *>targets;
    4546        18629 :   bool final;
    4547              : 
    4548        18629 :   ctx.offset_by (pii->offset);
    4549        18629 :   if (pii->vptr_changed)
    4550         6362 :     ctx.possible_dynamic_type_change (ie->in_polymorphic_cdtor,
    4551              :                                       pii->otr_type);
    4552        18629 :   ctx.combine_with (ie_context, pii->otr_type);
    4553        18629 :   targets = possible_polymorphic_call_targets (pii->otr_type, pii->otr_token,
    4554              :                                                ctx, &final);
    4555        20787 :   if (final && targets.length () <= 1)
    4556              :     {
    4557         2139 :       speculative = false;
    4558         2139 :       if (targets.length () == 1)
    4559         2088 :         target = targets[0]->decl;
    4560              :       else
    4561           51 :         target = ipa_impossible_devirt_target (ie, NULL_TREE);
    4562              :     }
    4563        16482 :   else if (!target && opt_for_fn (ie->caller->decl,
    4564              :                                   flag_devirtualize_speculatively)
    4565        32890 :            && !ie->speculative && ie->maybe_hot_p ())
    4566              :     {
    4567         9050 :       cgraph_node *n;
    4568         9050 :       n = try_speculative_devirtualization (pii->otr_type, pii->otr_token,
    4569              :                                             pii->context);
    4570         9050 :       if (n)
    4571              :         {
    4572           28 :           target = n->decl;
    4573           28 :           speculative = true;
    4574              :         }
    4575              :     }
    4576              : 
    4577        18629 :   if (target)
    4578              :     {
    4579         2175 :       if (!possible_polymorphic_call_target_p
    4580         2175 :           (ie, cgraph_node::get_create (target)))
    4581              :         {
    4582           51 :           if (speculative)
    4583              :             return NULL;
    4584           51 :           target = ipa_impossible_devirt_target (ie, target);
    4585              :         }
    4586         2175 :       return ipa_make_edge_direct_to_target (ie, target, speculative);
    4587              :     }
    4588              :   else
    4589              :     return NULL;
    4590              : }
    4591              : 
    4592              : /* Update the param called notes associated with NODE when CS is being inlined,
    4593              :    assuming NODE is (potentially indirectly) inlined into CS->callee.
    4594              :    Moreover, if the callee is discovered to be constant, create a new cgraph
    4595              :    edge for it.  Newly discovered indirect edges will be added to *NEW_EDGES,
    4596              :    unless NEW_EDGES is NULL.  Return true iff a new edge(s) were created.  */
    4597              : 
    4598              : static bool
    4599      1703451 : update_indirect_edges_after_inlining (struct cgraph_edge *cs,
    4600              :                                       struct cgraph_node *node,
    4601              :                                       vec<cgraph_edge *> *new_edges)
    4602              : {
    4603      1703451 :   bool res = false;
    4604              : 
    4605      1703451 :   ipa_check_create_edge_args ();
    4606      1703451 :   class ipa_edge_args *top = ipa_edge_args_sum->get (cs);
    4607      1156926 :   cgraph_node *new_root
    4608      1703451 :     = cs->caller->inlined_to ? cs->caller->inlined_to : cs->caller;
    4609      1703451 :   ipa_node_params *new_root_info = ipa_node_params_sum->get (new_root);
    4610      1703451 :   ipa_node_params *inlined_node_info
    4611      1703451 :     = ipa_node_params_sum->get (cs->callee->function_symbol ());
    4612              : 
    4613      1703451 :   cgraph_edge *next_ie;
    4614      1775191 :   for (cgraph_edge *ie = node->indirect_calls; ie; ie = next_ie)
    4615              :     {
    4616        71740 :       next_ie = ie->next_callee;
    4617              : 
    4618       114989 :       if (!top
    4619        71622 :           || ie->indirect_info->param_index < 0
    4620       128726 :           || ie->indirect_info->param_index >= ipa_get_cs_argument_count (top))
    4621              :         {
    4622        43249 :           ie->indirect_info->param_index = -1;
    4623        46780 :           continue;
    4624              :         }
    4625              : 
    4626        28491 :       int param_index = ie->indirect_info->param_index;
    4627        28491 :       cgraph_polymorphic_indirect_info *pii
    4628        28491 :         = dyn_cast <cgraph_polymorphic_indirect_info *> (ie->indirect_info);
    4629        28491 :       cgraph_simple_indirect_info *sii
    4630        28491 :         = dyn_cast <cgraph_simple_indirect_info *> (ie->indirect_info);
    4631        28491 :       struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (top, param_index);
    4632              : 
    4633        28491 :       auto_vec<cgraph_node *, 4> spec_targets;
    4634        28491 :       if (ie->speculative)
    4635         8325 :         for (cgraph_edge *direct = ie->first_speculative_call_target ();
    4636        21076 :              direct;
    4637        12751 :              direct = direct->next_speculative_call_target ())
    4638        12751 :           spec_targets.safe_push (direct->callee);
    4639              : 
    4640        28491 :       cgraph_edge *new_direct_edge;
    4641        28491 :       if (!opt_for_fn (node->decl, flag_indirect_inlining))
    4642          171 :         new_direct_edge = NULL;
    4643        28320 :       else if (pii)
    4644              :         {
    4645        18629 :           ipa_polymorphic_call_context ctx;
    4646        18629 :           ctx = ipa_context_from_jfunc (new_root_info, cs, param_index, jfunc);
    4647        18629 :           new_direct_edge = try_make_edge_direct_virtual_call (ie, jfunc, ctx,
    4648              :                                                                new_root,
    4649              :                                                                new_root_info);
    4650              :         }
    4651         9691 :       else if (sii)
    4652              :         {
    4653         9691 :           tree target_type =  ipa_get_type (inlined_node_info, param_index);
    4654         9691 :           new_direct_edge = try_make_edge_direct_simple_call (ie, jfunc,
    4655              :                                                               target_type,
    4656              :                                                               new_root,
    4657              :                                                               new_root_info);
    4658              :         }
    4659              :       else
    4660            0 :         gcc_unreachable ();
    4661              : 
    4662              :       /* If speculation was removed, then we need to do nothing.  */
    4663         3565 :       if (new_direct_edge && new_direct_edge != ie
    4664        29309 :           && spec_targets.contains (new_direct_edge->callee))
    4665              :         {
    4666          784 :           new_direct_edge->indirect_inlining_edge = 1;
    4667          784 :           res = true;
    4668          784 :           if (!new_direct_edge->speculative)
    4669          784 :             continue;
    4670              :         }
    4671        27707 :       else if (new_direct_edge)
    4672              :         {
    4673         2781 :           new_direct_edge->indirect_inlining_edge = 1;
    4674         2781 :           if (new_edges)
    4675              :             {
    4676         2775 :               new_edges->safe_push (new_direct_edge);
    4677         2775 :               res = true;
    4678              :             }
    4679              :           /* If speculative edge was introduced we still need to update
    4680              :              call info of the indirect edge.  */
    4681         2781 :           if (!new_direct_edge->speculative)
    4682         2747 :             continue;
    4683              :         }
    4684        24960 :       if (jfunc->type == IPA_JF_PASS_THROUGH
    4685        24960 :           && ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
    4686              :         {
    4687         6054 :           if (!pii
    4688         2677 :               && sii->agg_contents
    4689         7576 :               && !ipa_get_jf_pass_through_agg_preserved (jfunc))
    4690          989 :             ie->indirect_info->param_index = -1;
    4691              :           else
    4692              :             {
    4693         5065 :               param_index = ipa_get_jf_pass_through_formal_id (jfunc);
    4694         5065 :               ie->indirect_info->param_index = param_index;
    4695         5065 :               ipa_set_param_used_by_indirect_call (new_root_info, param_index,
    4696              :                                                    true);
    4697         5065 :               if (pii)
    4698              :                 {
    4699         3377 :                   if (!ipa_get_jf_pass_through_type_preserved (jfunc))
    4700         2227 :                     pii->vptr_changed = true;
    4701         3377 :                   ipa_set_param_used_by_polymorphic_call (new_root_info,
    4702              :                                                           param_index, true);
    4703              :                 }
    4704              :             }
    4705              :         }
    4706        18906 :       else if (jfunc->type == IPA_JF_ANCESTOR)
    4707              :         {
    4708          608 :           if (!pii
    4709          191 :               && sii->agg_contents
    4710          799 :               && !ipa_get_jf_ancestor_agg_preserved (jfunc))
    4711           79 :             ie->indirect_info->param_index = -1;
    4712              :           else
    4713              :             {
    4714          529 :               param_index = ipa_get_jf_ancestor_formal_id (jfunc);
    4715          529 :               ie->indirect_info->param_index = param_index;
    4716          529 :               ipa_set_param_used_by_indirect_call (new_root_info, param_index,
    4717              :                                                    true);
    4718          529 :               if (pii)
    4719              :                 {
    4720          417 :                   pii->offset += ipa_get_jf_ancestor_offset (jfunc);
    4721          417 :                   if (!ipa_get_jf_ancestor_type_preserved (jfunc))
    4722          377 :                     pii->vptr_changed = true;
    4723          417 :                   ipa_set_param_used_by_polymorphic_call (new_root_info,
    4724              :                                                           param_index, true);
    4725              :                 }
    4726              :               else
    4727          112 :                 sii->offset += ipa_get_jf_ancestor_offset (jfunc);
    4728              :             }
    4729              :         }
    4730              :       else
    4731              :         /* Either we can find a destination for this edge now or never. */
    4732        18298 :         ie->indirect_info->param_index = -1;
    4733        28491 :     }
    4734              : 
    4735      1703451 :   return res;
    4736              : }
    4737              : 
    4738              : /* Recursively traverse subtree of NODE (including node) made of inlined
    4739              :    cgraph_edges when CS has been inlined and invoke
    4740              :    update_indirect_edges_after_inlining on all nodes and
    4741              :    update_jump_functions_after_inlining on all non-inlined edges that lead out
    4742              :    of this subtree.  Newly discovered indirect edges will be added to
    4743              :    *NEW_EDGES, unless NEW_EDGES is NULL.  Return true iff a new edge(s) were
    4744              :    created.  */
    4745              : 
    4746              : static bool
    4747      1703451 : propagate_info_to_inlined_callees (struct cgraph_edge *cs,
    4748              :                                    struct cgraph_node *node,
    4749              :                                    vec<cgraph_edge *> *new_edges)
    4750              : {
    4751      1703451 :   struct cgraph_edge *e;
    4752      1703451 :   bool res;
    4753              : 
    4754      1703451 :   res = update_indirect_edges_after_inlining (cs, node, new_edges);
    4755              : 
    4756      5159105 :   for (e = node->callees; e; e = e->next_callee)
    4757      3455654 :     if (!e->inline_failed)
    4758       727891 :       res |= propagate_info_to_inlined_callees (cs, e->callee, new_edges);
    4759              :     else
    4760      2727763 :       update_jump_functions_after_inlining (cs, e);
    4761      1771660 :   for (e = node->indirect_calls; e; e = e->next_callee)
    4762        68209 :     update_jump_functions_after_inlining (cs, e);
    4763              : 
    4764      1703451 :   return res;
    4765              : }
    4766              : 
    4767              : /* Combine two controlled uses counts as done during inlining.  */
    4768              : 
    4769              : static int
    4770       407557 : combine_controlled_uses_counters (int c, int d)
    4771              : {
    4772            0 :   if (c == IPA_UNDESCRIBED_USE || d == IPA_UNDESCRIBED_USE)
    4773              :     return IPA_UNDESCRIBED_USE;
    4774              :   else
    4775       107440 :     return c + d - 1;
    4776              : }
    4777              : 
    4778              : /* Propagate number of controlled users from CS->callee to the new root of the
    4779              :    tree of inlined nodes.  */
    4780              : 
    4781              : static void
    4782       975560 : propagate_controlled_uses (struct cgraph_edge *cs)
    4783              : {
    4784       975560 :   ipa_edge_args *args = ipa_edge_args_sum->get (cs);
    4785       975560 :   if (!args)
    4786              :     return;
    4787       684629 :   struct cgraph_node *new_root = cs->caller->inlined_to
    4788       973739 :     ? cs->caller->inlined_to : cs->caller;
    4789       973739 :   ipa_node_params *new_root_info = ipa_node_params_sum->get (new_root);
    4790       973739 :   ipa_node_params *old_root_info = ipa_node_params_sum->get (cs->callee);
    4791       973739 :   int count, i;
    4792              : 
    4793       973739 :   if (!old_root_info)
    4794              :     return;
    4795              : 
    4796      1890388 :   count = MIN (ipa_get_cs_argument_count (args),
    4797              :                ipa_get_param_count (old_root_info));
    4798      2979916 :   for (i = 0; i < count; i++)
    4799              :     {
    4800      2006251 :       struct ipa_jump_func *jf = ipa_get_ith_jump_func (args, i);
    4801      2006251 :       struct ipa_cst_ref_desc *rdesc;
    4802              : 
    4803      2006251 :       if (jf->type == IPA_JF_PASS_THROUGH
    4804      2006251 :           && !ipa_get_jf_pass_through_refdesc_decremented (jf))
    4805              :         {
    4806       349514 :           int src_idx, c, d;
    4807       349514 :           src_idx = ipa_get_jf_pass_through_formal_id (jf);
    4808       349514 :           c = ipa_get_controlled_uses (new_root_info, src_idx);
    4809       349514 :           d = ipa_get_controlled_uses (old_root_info, i);
    4810              : 
    4811       349514 :           gcc_checking_assert (ipa_get_jf_pass_through_operation (jf)
    4812              :                                == NOP_EXPR || c == IPA_UNDESCRIBED_USE);
    4813       349514 :           c = combine_controlled_uses_counters (c, d);
    4814       349514 :           ipa_set_controlled_uses (new_root_info, src_idx, c);
    4815       349514 :           bool lderef = true;
    4816       349514 :           if (c != IPA_UNDESCRIBED_USE)
    4817              :             {
    4818        94601 :               lderef = (ipa_get_param_load_dereferenced (new_root_info, src_idx)
    4819        94601 :                         || ipa_get_param_load_dereferenced (old_root_info, i));
    4820        94601 :               ipa_set_param_load_dereferenced (new_root_info, src_idx, lderef);
    4821              :             }
    4822              : 
    4823       349514 :           if (c == 0 && !lderef && new_root_info->ipcp_orig_node)
    4824              :             {
    4825          181 :               struct cgraph_node *n;
    4826          181 :               struct ipa_ref *ref;
    4827          181 :               tree t = new_root_info->known_csts[src_idx];
    4828              : 
    4829          159 :               if (t && TREE_CODE (t) == ADDR_EXPR
    4830          139 :                   && TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
    4831            5 :                   && (n = cgraph_node::get (TREE_OPERAND (t, 0)))
    4832          186 :                   && (ref = new_root->find_reference (n, NULL, 0,
    4833              :                                                       IPA_REF_ADDR)))
    4834              :                 {
    4835            5 :                   if (dump_file)
    4836            1 :                     fprintf (dump_file, "ipa-prop: Removing cloning-created "
    4837              :                              "reference from %s to %s.\n",
    4838              :                              new_root->dump_name (),
    4839              :                              n->dump_name ());
    4840            5 :                   ref->remove_reference ();
    4841              :                 }
    4842              :             }
    4843              :         }
    4844      1656737 :       else if (jf->type == IPA_JF_CONST
    4845      1656737 :                && (rdesc = jfunc_rdesc_usable (jf)))
    4846              :         {
    4847        58043 :           int d = ipa_get_controlled_uses (old_root_info, i);
    4848        58043 :           int c = rdesc->refcount;
    4849        58043 :           tree cst = ipa_get_jf_constant (jf);
    4850        58043 :           rdesc->refcount = combine_controlled_uses_counters (c, d);
    4851        58043 :           if (rdesc->refcount != IPA_UNDESCRIBED_USE
    4852        12839 :               && ipa_get_param_load_dereferenced (old_root_info, i)
    4853         2849 :               && TREE_CODE (cst) == ADDR_EXPR
    4854        60892 :               && VAR_P (TREE_OPERAND (cst, 0)))
    4855              :             {
    4856         2848 :               symtab_node *n = symtab_node::get (TREE_OPERAND (cst, 0));
    4857         2848 :               new_root->create_reference (n, IPA_REF_LOAD, NULL);
    4858         2848 :               if (dump_file)
    4859            7 :                 fprintf (dump_file, "ipa-prop: Address IPA constant will reach "
    4860              :                          "a load so adding LOAD reference from %s to %s.\n",
    4861              :                          new_root->dump_name (), n->dump_name ());
    4862              :             }
    4863        58043 :           if (rdesc->refcount == 0)
    4864              :             {
    4865         8421 :               gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR
    4866              :                                    && ((TREE_CODE (TREE_OPERAND (cst, 0))
    4867              :                                         == FUNCTION_DECL)
    4868              :                                        || VAR_P (TREE_OPERAND (cst, 0))));
    4869              : 
    4870         8421 :               symtab_node *n = symtab_node::get (TREE_OPERAND (cst, 0));
    4871         8421 :               if (n)
    4872              :                 {
    4873         8421 :                   remove_described_reference (n, rdesc);
    4874         8421 :                   cgraph_node *clone = cs->caller;
    4875         8421 :                   while (clone->inlined_to
    4876         1668 :                          && clone->ipcp_clone
    4877         8649 :                          && clone != rdesc->cs->caller)
    4878              :                     {
    4879           95 :                       struct ipa_ref *ref;
    4880           95 :                       ref = clone->find_reference (n, NULL, 0, IPA_REF_ADDR);
    4881           95 :                       if (ref)
    4882              :                         {
    4883           92 :                           if (dump_file)
    4884            1 :                             fprintf (dump_file, "ipa-prop: Removing "
    4885              :                                      "cloning-created reference "
    4886              :                                      "from %s to %s.\n",
    4887              :                                      clone->dump_name (),
    4888              :                                      n->dump_name ());
    4889           92 :                           ref->remove_reference ();
    4890              :                         }
    4891           95 :                       clone = clone->callers->caller;
    4892              :                     }
    4893              :                 }
    4894              :             }
    4895              :         }
    4896              :     }
    4897              : 
    4898      1890484 :   for (i = ipa_get_param_count (old_root_info);
    4899      1891042 :        i < ipa_get_cs_argument_count (args);
    4900              :        i++)
    4901              :     {
    4902          327 :       struct ipa_jump_func *jf = ipa_get_ith_jump_func (args, i);
    4903              : 
    4904          327 :       if (jf->type == IPA_JF_CONST)
    4905              :         {
    4906          291 :           struct ipa_cst_ref_desc *rdesc = jfunc_rdesc_usable (jf);
    4907          291 :           if (rdesc)
    4908          235 :             rdesc->refcount = IPA_UNDESCRIBED_USE;
    4909              :         }
    4910           36 :       else if (jf->type == IPA_JF_PASS_THROUGH)
    4911            5 :         ipa_set_controlled_uses (new_root_info,
    4912              :                                  jf->value.pass_through.formal_id,
    4913              :                                  IPA_UNDESCRIBED_USE);
    4914              :     }
    4915              : }
    4916              : 
    4917              : /* Update jump functions and call note functions on inlining the call site CS.
    4918              :    CS is expected to lead to a node already cloned by
    4919              :    cgraph_clone_inline_nodes.  Newly discovered indirect edges will be added to
    4920              :    *NEW_EDGES, unless NEW_EDGES is NULL.  Return true iff a new edge(s) were +
    4921              :    created.  */
    4922              : 
    4923              : bool
    4924      4155494 : ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
    4925              :                                    vec<cgraph_edge *> *new_edges)
    4926              : {
    4927      4155494 :   bool changed;
    4928              :   /* Do nothing if the preparation phase has not been carried out yet
    4929              :      (i.e. during early inlining).  */
    4930      4155494 :   if (!ipa_node_params_sum)
    4931              :     return false;
    4932       975560 :   gcc_assert (ipa_edge_args_sum);
    4933              : 
    4934       975560 :   propagate_controlled_uses (cs);
    4935       975560 :   changed = propagate_info_to_inlined_callees (cs, cs->callee, new_edges);
    4936       975560 :   ipa_node_params_sum->remove (cs->callee);
    4937              : 
    4938       975560 :   ipa_edge_args *args = ipa_edge_args_sum->get (cs);
    4939       975560 :   if (args)
    4940              :     {
    4941       973739 :       bool ok = true;
    4942       973739 :       if (args->jump_functions)
    4943              :         {
    4944              :           struct ipa_jump_func *jf;
    4945              :           int i;
    4946      2722396 :           FOR_EACH_VEC_ELT (*args->jump_functions, i, jf)
    4947      1867111 :             if (jf->type == IPA_JF_CONST
    4948      1867111 :                 && ipa_get_jf_constant_rdesc (jf))
    4949              :               {
    4950              :                 ok = false;
    4951              :                 break;
    4952              :               }
    4953              :         }
    4954       916797 :       if (ok)
    4955       912227 :         ipa_edge_args_sum->remove (cs);
    4956              :     }
    4957       975560 :   if (ipcp_transformation_sum)
    4958       663880 :     ipcp_transformation_sum->remove (cs->callee);
    4959              : 
    4960              :   return changed;
    4961              : }
    4962              : 
    4963              : /* Ensure that array of edge arguments infos is big enough to accommodate a
    4964              :    structure for all edges and reallocates it if not.  Also, allocate
    4965              :    associated hash tables is they do not already exist.  */
    4966              : 
    4967              : void
    4968      4986051 : ipa_check_create_edge_args (void)
    4969              : {
    4970      4986051 :   if (!ipa_edge_args_sum)
    4971       252029 :     ipa_edge_args_sum
    4972       252029 :       = (new (ggc_alloc_no_dtor<ipa_edge_args_sum_t> ())
    4973       252029 :          ipa_edge_args_sum_t (symtab, true));
    4974      4986051 :   if (!ipa_vr_hash_table)
    4975       176429 :     ipa_vr_hash_table = hash_table<ipa_vr_ggc_hash_traits>::create_ggc (37);
    4976      4986051 : }
    4977              : 
    4978              : /* Free all ipa_edge structures.  */
    4979              : 
    4980              : void
    4981       478426 : ipa_free_all_edge_args (void)
    4982              : {
    4983       478426 :   if (!ipa_edge_args_sum)
    4984              :     return;
    4985              : 
    4986       239358 :   ggc_delete (ipa_edge_args_sum);
    4987       239358 :   ipa_edge_args_sum = NULL;
    4988              : }
    4989              : 
    4990              : /* Free all ipa_node_params structures.  */
    4991              : 
    4992              : void
    4993      5580291 : ipa_free_all_node_params (void)
    4994              : {
    4995      5580291 :   if (ipa_node_params_sum)
    4996      5341223 :     ggc_delete (ipa_node_params_sum);
    4997      5580291 :   ipa_node_params_sum = NULL;
    4998      5580291 : }
    4999              : 
    5000              : /* Initialize IPA CP transformation summary and also allocate any necessary hash
    5001              :    tables if they do not already exist.  */
    5002              : 
    5003              : void
    5004        93722 : ipcp_transformation_initialize (void)
    5005              : {
    5006        93722 :   if (!ipa_vr_hash_table)
    5007         1929 :     ipa_vr_hash_table = hash_table<ipa_vr_ggc_hash_traits>::create_ggc (37);
    5008        93722 :   if (ipcp_transformation_sum == NULL)
    5009              :     {
    5010        18363 :       ipcp_transformation_sum = ipcp_transformation_t::create_ggc (symtab);
    5011        18363 :       ipcp_transformation_sum->disable_insertion_hook ();
    5012              :     }
    5013        93722 : }
    5014              : 
    5015              : /* Release the IPA CP transformation summary.  */
    5016              : 
    5017              : void
    5018       266934 : ipcp_free_transformation_sum (void)
    5019              : {
    5020       266934 :   if (!ipcp_transformation_sum)
    5021              :     return;
    5022              : 
    5023        18354 :   ipcp_transformation_sum->~function_summary<ipcp_transformation *> ();
    5024        18354 :   ggc_free (ipcp_transformation_sum);
    5025        18354 :   ipcp_transformation_sum = NULL;
    5026              : }
    5027              : 
    5028              : /* Set the aggregate replacements of NODE to be AGGVALS.  */
    5029              : 
    5030              : void
    5031        19622 : ipa_set_node_agg_value_chain (struct cgraph_node *node,
    5032              :                               vec<ipa_argagg_value, va_gc> *aggs)
    5033              : {
    5034        19622 :   ipcp_transformation_initialize ();
    5035        19622 :   ipcp_transformation *s = ipcp_transformation_sum->get_create (node);
    5036        19622 :   s->m_agg_values = aggs;
    5037        19622 : }
    5038              : 
    5039              : /* Hook that is called by cgraph.cc when an edge is removed.  Adjust reference
    5040              :    count data structures accordingly.  */
    5041              : 
    5042              : void
    5043            0 : ipa_edge_args_sum_t::remove (cgraph_edge *cs, ipa_edge_args *args)
    5044              : {
    5045            0 :   if (args->jump_functions)
    5046              :     {
    5047              :       struct ipa_jump_func *jf;
    5048              :       int i;
    5049            0 :       FOR_EACH_VEC_ELT (*args->jump_functions, i, jf)
    5050              :         {
    5051            0 :           struct ipa_cst_ref_desc *rdesc;
    5052            0 :           try_decrement_rdesc_refcount (jf);
    5053            0 :           if (jf->type == IPA_JF_CONST
    5054            0 :               && (rdesc = ipa_get_jf_constant_rdesc (jf))
    5055            0 :               && rdesc->cs == cs)
    5056            0 :             rdesc->cs = NULL;
    5057              :         }
    5058              :     }
    5059            0 : }
    5060              : 
    5061              : /* Copy information from SRC_JF to DST_JF which correstpond to call graph edges
    5062              :    SRC and DST.  */
    5063              : 
    5064              : static void
    5065      2978059 : ipa_duplicate_jump_function (cgraph_edge *src, cgraph_edge *dst,
    5066              :                              ipa_jump_func *src_jf, ipa_jump_func *dst_jf)
    5067              : {
    5068      2978059 :   dst_jf->agg.items = vec_safe_copy (src_jf->agg.items);
    5069      2978059 :   dst_jf->agg.by_ref = src_jf->agg.by_ref;
    5070              : 
    5071              :   /* We can avoid calling ipa_set_jfunc_vr since it would only look up the
    5072              :      place in the hash_table where the source m_vr resides.  */
    5073      2978059 :   dst_jf->m_vr = src_jf->m_vr;
    5074              : 
    5075      2978059 :   if (src_jf->type == IPA_JF_CONST)
    5076              :     {
    5077       932241 :       ipa_set_jf_cst_copy (dst_jf, src_jf);
    5078       932241 :       struct ipa_cst_ref_desc *src_rdesc = jfunc_rdesc_usable (src_jf);
    5079              : 
    5080       932241 :       if (!src_rdesc)
    5081       796520 :         dst_jf->value.constant.rdesc = NULL;
    5082       135721 :       else if (src->caller == dst->caller)
    5083              :         {
    5084              :           /* Creation of a speculative edge.  If the source edge is the one
    5085              :              grabbing a reference, we must create a new (duplicate)
    5086              :              reference description.  Otherwise they refer to the same
    5087              :              description corresponding to a reference taken in a function
    5088              :              src->caller is inlined to.  In that case we just must
    5089              :              increment the refcount.  */
    5090           41 :           if (src_rdesc->cs == src)
    5091              :             {
    5092           41 :               symtab_node *n = symtab_node_for_jfunc (src_jf);
    5093           41 :               gcc_checking_assert (n);
    5094           41 :               ipa_ref *ref
    5095           41 :                 = src->caller->find_reference (n, src->call_stmt,
    5096              :                                                src->lto_stmt_uid,
    5097              :                                                IPA_REF_ADDR);
    5098           41 :               gcc_checking_assert (ref);
    5099           41 :               dst->caller->clone_reference (ref, ref->stmt);
    5100              : 
    5101           41 :               ipa_cst_ref_desc *dst_rdesc = ipa_refdesc_pool.allocate ();
    5102           41 :               dst_rdesc->cs = dst;
    5103           41 :               dst_rdesc->refcount = src_rdesc->refcount;
    5104           41 :               dst_rdesc->next_duplicate = NULL;
    5105           41 :               dst_jf->value.constant.rdesc = dst_rdesc;
    5106              :             }
    5107              :           else
    5108              :             {
    5109            0 :               src_rdesc->refcount++;
    5110            0 :               dst_jf->value.constant.rdesc = src_rdesc;
    5111              :             }
    5112              :         }
    5113       135680 :       else if (src_rdesc->cs == src)
    5114              :         {
    5115       135357 :           struct ipa_cst_ref_desc *dst_rdesc = ipa_refdesc_pool.allocate ();
    5116       135357 :           dst_rdesc->cs = dst;
    5117       135357 :           dst_rdesc->refcount = src_rdesc->refcount;
    5118       135357 :           dst_rdesc->next_duplicate = src_rdesc->next_duplicate;
    5119       135357 :           src_rdesc->next_duplicate = dst_rdesc;
    5120       135357 :           dst_jf->value.constant.rdesc = dst_rdesc;
    5121              :         }
    5122              :       else
    5123              :         {
    5124          323 :           struct ipa_cst_ref_desc *dst_rdesc;
    5125              :           /* This can happen during inlining, when a JFUNC can refer to a
    5126              :              reference taken in a function up in the tree of inline clones.
    5127              :              We need to find the duplicate that refers to our tree of
    5128              :              inline clones.  */
    5129              : 
    5130          323 :           gcc_assert (dst->caller->inlined_to);
    5131          323 :           for (dst_rdesc = src_rdesc->next_duplicate;
    5132          323 :                dst_rdesc;
    5133            0 :                dst_rdesc = dst_rdesc->next_duplicate)
    5134              :             {
    5135          323 :               struct cgraph_node *top;
    5136            2 :               top = dst_rdesc->cs->caller->inlined_to
    5137          323 :                 ? dst_rdesc->cs->caller->inlined_to
    5138              :                 : dst_rdesc->cs->caller;
    5139          323 :               if (dst->caller->inlined_to == top)
    5140              :                 break;
    5141              :             }
    5142          323 :           gcc_assert (dst_rdesc);
    5143          323 :           dst_jf->value.constant.rdesc = dst_rdesc;
    5144              :         }
    5145              :     }
    5146      2045818 :   else if (src_jf->type == IPA_JF_PASS_THROUGH)
    5147              :     {
    5148       734450 :       dst_jf->type = IPA_JF_PASS_THROUGH;
    5149       734450 :       dst_jf->value.pass_through = src_jf->value.pass_through;
    5150       734450 :       if (src->caller == dst->caller)
    5151              :         {
    5152        10321 :           struct cgraph_node *inline_root = dst->caller->inlined_to
    5153        10359 :             ? dst->caller->inlined_to : dst->caller;
    5154        10359 :           ipa_node_params *root_info = ipa_node_params_sum->get (inline_root);
    5155        10359 :           int idx = ipa_get_jf_pass_through_formal_id (dst_jf);
    5156              : 
    5157        10359 :           int c = ipa_get_controlled_uses (root_info, idx);
    5158        10359 :           if (c != IPA_UNDESCRIBED_USE)
    5159              :             {
    5160         2489 :               c++;
    5161         2489 :               ipa_set_controlled_uses (root_info, idx, c);
    5162              :             }
    5163              :         }
    5164              :     }
    5165      1311368 :   else if (src_jf->type == IPA_JF_ANCESTOR)
    5166              :     {
    5167       100098 :       dst_jf->type = IPA_JF_ANCESTOR;
    5168       100098 :       dst_jf->value.ancestor = src_jf->value.ancestor;
    5169              :     }
    5170              :   else
    5171      1211270 :     gcc_assert (src_jf->type == IPA_JF_UNKNOWN);
    5172      2978059 : }
    5173              : 
    5174              : /* Method invoked when an edge is duplicated.  Copy ipa_edge_args and adjust
    5175              :    reference count data structures accordingly.  */
    5176              : 
    5177              : void
    5178      1371614 : ipa_edge_args_sum_t::duplicate (cgraph_edge *src, cgraph_edge *dst,
    5179              :                                 ipa_edge_args *old_args, ipa_edge_args *new_args)
    5180              : {
    5181      1371614 :   unsigned int i;
    5182              : 
    5183      1371614 :   if (old_args->polymorphic_call_contexts)
    5184       193880 :     new_args->polymorphic_call_contexts
    5185       193880 :       = vec_safe_copy (old_args->polymorphic_call_contexts);
    5186              : 
    5187      1371614 :   if (!vec_safe_length (old_args->jump_functions))
    5188              :     {
    5189        59707 :       new_args->jump_functions = NULL;
    5190        59707 :       return;
    5191              :     }
    5192              : 
    5193      1311907 :   if (src->has_callback && dst->callback)
    5194              :     {
    5195        15205 :       gcc_assert (src->caller == dst->caller);
    5196        15205 :       tree attr = callback_fetch_attr_by_edge (dst, src);
    5197        15205 :       unsigned arg_count = callback_num_args (attr);
    5198        15205 :       vec_safe_grow_cleared (new_args->jump_functions, arg_count, true);
    5199              :       /* Duplication of jump functions is handled separately for callback
    5200              :          pairs.  */
    5201        15205 :       return;
    5202              :     }
    5203              : 
    5204      1296702 :   vec_safe_grow_cleared (new_args->jump_functions,
    5205      1296702 :                          old_args->jump_functions->length (), true);
    5206              : 
    5207      5556257 :   for (i = 0; i < vec_safe_length (old_args->jump_functions); i++)
    5208              :     {
    5209      2962853 :       struct ipa_jump_func *src_jf = ipa_get_ith_jump_func (old_args, i);
    5210      2962853 :       struct ipa_jump_func *dst_jf = ipa_get_ith_jump_func (new_args, i);
    5211              : 
    5212      2962853 :       ipa_duplicate_jump_function (src, dst, src_jf, dst_jf);
    5213              :     }
    5214              : }
    5215              : 
    5216              : /* Analyze newly added function into callgraph.  */
    5217              : 
    5218              : static void
    5219        42301 : ipa_add_new_function (cgraph_node *node, void *data ATTRIBUTE_UNUSED)
    5220              : {
    5221        42301 :   if (node->has_gimple_body_p ())
    5222        42301 :     ipa_analyze_node (node);
    5223        42301 : }
    5224              : 
    5225              : /* Hook that is called by summary when a node is duplicated.  */
    5226              : 
    5227              : void
    5228       800773 : ipa_node_params_t::duplicate(cgraph_node *, cgraph_node *,
    5229              :                              ipa_node_params *old_info,
    5230              :                              ipa_node_params *new_info)
    5231              : {
    5232       800773 :   new_info->descriptors = vec_safe_copy (old_info->descriptors);
    5233       800773 :   gcc_assert (new_info->lattices.is_empty ());
    5234       800773 :   new_info->ipcp_orig_node = old_info->ipcp_orig_node;
    5235       800773 :   new_info->known_csts = old_info->known_csts.copy ();
    5236       800773 :   new_info->known_contexts = old_info->known_contexts.copy ();
    5237              : 
    5238       800773 :   new_info->analysis_done = old_info->analysis_done;
    5239       800773 :   new_info->node_enqueued = old_info->node_enqueued;
    5240       800773 :   new_info->versionable = old_info->versionable;
    5241       800773 : }
    5242              : 
    5243              : /* Duplication of ipcp transformation summaries.  */
    5244              : 
    5245              : void
    5246        46022 : ipcp_transformation_t::duplicate(cgraph_node *, cgraph_node *dst,
    5247              :                                  ipcp_transformation *src_trans,
    5248              :                                  ipcp_transformation *dst_trans)
    5249              : {
    5250              :   /* Avoid redundant work of duplicating vectors we will never use.  */
    5251        46022 :   if (dst->inlined_to)
    5252              :     return;
    5253         8750 :   dst_trans->m_agg_values = vec_safe_copy (src_trans->m_agg_values);
    5254        16242 :   dst_trans->m_vr = vec_safe_copy (src_trans->m_vr);
    5255              : }
    5256              : 
    5257              : /* Register our cgraph hooks if they are not already there.  */
    5258              : 
    5259              : void
    5260       393816 : ipa_register_cgraph_hooks (void)
    5261              : {
    5262       393816 :   ipa_check_create_node_params ();
    5263       393816 :   ipa_check_create_edge_args ();
    5264       393816 :   callback_info_sum_t::check_create_info_sum ();
    5265              : 
    5266       787632 :   function_insertion_hook_holder =
    5267       393816 :       symtab->add_cgraph_insertion_hook (&ipa_add_new_function, NULL);
    5268       393816 : }
    5269              : 
    5270              : /* Unregister our cgraph hooks if they are not already there.  */
    5271              : 
    5272              : static void
    5273       478426 : ipa_unregister_cgraph_hooks (void)
    5274              : {
    5275       478426 :   if (function_insertion_hook_holder)
    5276       239358 :     symtab->remove_cgraph_insertion_hook (function_insertion_hook_holder);
    5277       478426 :   function_insertion_hook_holder = NULL;
    5278       478426 : }
    5279              : 
    5280              : /* Free all ipa_node_params and all ipa_edge_args structures if they are no
    5281              :    longer needed after ipa-cp.  */
    5282              : 
    5283              : void
    5284       132707 : ipa_free_all_structures_after_ipa_cp (void)
    5285              : {
    5286       132707 :   if (!optimize && !in_lto_p)
    5287              :     {
    5288            0 :       ipa_free_all_edge_args ();
    5289            0 :       ipa_free_all_node_params ();
    5290            0 :       ipcp_sources_pool.release ();
    5291            0 :       ipcp_cst_values_pool.release ();
    5292            0 :       ipcp_poly_ctx_values_pool.release ();
    5293            0 :       ipcp_agg_lattice_pool.release ();
    5294            0 :       ipa_unregister_cgraph_hooks ();
    5295            0 :       ipa_refdesc_pool.release ();
    5296              :     }
    5297       132707 : }
    5298              : 
    5299              : /* Free all ipa_node_params and all ipa_edge_args structures if they are no
    5300              :    longer needed after indirect inlining.  */
    5301              : 
    5302              : void
    5303       478426 : ipa_free_all_structures_after_iinln (void)
    5304              : {
    5305       478426 :   ipa_free_all_edge_args ();
    5306       478426 :   ipa_free_all_node_params ();
    5307       478426 :   ipa_unregister_cgraph_hooks ();
    5308       478426 :   ipcp_sources_pool.release ();
    5309       478426 :   ipcp_cst_values_pool.release ();
    5310       478426 :   ipcp_poly_ctx_values_pool.release ();
    5311       478426 :   ipcp_agg_lattice_pool.release ();
    5312       478426 :   ipa_refdesc_pool.release ();
    5313       478426 : }
    5314              : 
    5315              : /* Print ipa_tree_map data structures of all functions in the
    5316              :    callgraph to F.  */
    5317              : 
    5318              : void
    5319          312 : ipa_print_node_params (FILE *f, struct cgraph_node *node)
    5320              : {
    5321          312 :   int i, count;
    5322          312 :   class ipa_node_params *info;
    5323              : 
    5324          312 :   if (!node->definition)
    5325              :     return;
    5326          219 :   info = ipa_node_params_sum->get (node);
    5327          219 :   fprintf (f, "  function  %s parameter descriptors:\n", node->dump_name ());
    5328          219 :   if (!info)
    5329              :     {
    5330            0 :       fprintf (f, " no params return\n");
    5331            0 :       return;
    5332              :     }
    5333          219 :   count = ipa_get_param_count (info);
    5334          454 :   for (i = 0; i < count; i++)
    5335              :     {
    5336          235 :       int c;
    5337              : 
    5338          235 :       fprintf (f, "    ");
    5339          235 :       ipa_dump_param (f, info, i);
    5340          235 :       if (ipa_is_param_used (info, i))
    5341          228 :         fprintf (f, " used");
    5342          235 :       if (ipa_is_param_used_by_ipa_predicates (info, i))
    5343          142 :         fprintf (f, " used_by_ipa_predicates");
    5344          235 :       if (ipa_is_param_used_by_indirect_call (info, i))
    5345           10 :         fprintf (f, " used_by_indirect_call");
    5346          235 :       if (ipa_is_param_used_by_polymorphic_call (info, i))
    5347            0 :         fprintf (f, " used_by_polymorphic_call");
    5348          235 :       c = ipa_get_controlled_uses (info, i);
    5349          235 :       if (c == IPA_UNDESCRIBED_USE)
    5350          145 :         fprintf (f, " undescribed_use");
    5351              :       else
    5352          153 :         fprintf (f, "  controlled_uses=%i %s", c,
    5353           90 :                  ipa_get_param_load_dereferenced (info, i)
    5354              :                  ? "(load_dereferenced)" : "");
    5355          235 :       fprintf (f, "\n");
    5356              :     }
    5357              : }
    5358              : 
    5359              : /* Print ipa_tree_map data structures of all functions in the
    5360              :    callgraph to F.  */
    5361              : 
    5362              : void
    5363           61 : ipa_print_all_params (FILE * f)
    5364              : {
    5365           61 :   struct cgraph_node *node;
    5366              : 
    5367           61 :   fprintf (f, "\nFunction parameters:\n");
    5368          357 :   FOR_EACH_FUNCTION (node)
    5369          296 :     ipa_print_node_params (f, node);
    5370           61 : }
    5371              : 
    5372              : /* Stream out jump function JUMP_FUNC to OB.  */
    5373              : 
    5374              : static void
    5375       614386 : ipa_write_jump_function (struct output_block *ob,
    5376              :                          struct ipa_jump_func *jump_func)
    5377              : {
    5378       614386 :   struct ipa_agg_jf_item *item;
    5379       614386 :   struct bitpack_d bp;
    5380       614386 :   int i, count;
    5381       614386 :   int flag = 0;
    5382              : 
    5383              :   /* ADDR_EXPRs are very common IP invariants; save some streamer data
    5384              :      as well as WPA memory by handling them specially.  */
    5385       614386 :   if (jump_func->type == IPA_JF_CONST
    5386       467563 :       && TREE_CODE (jump_func->value.constant.value) == ADDR_EXPR)
    5387       614386 :     flag = 1;
    5388              : 
    5389       614386 :   streamer_write_uhwi (ob, jump_func->type * 2 + flag);
    5390       614386 :   switch (jump_func->type)
    5391              :     {
    5392              :     case IPA_JF_UNKNOWN:
    5393              :       break;
    5394       467563 :     case IPA_JF_CONST:
    5395       467563 :       gcc_assert (
    5396              :           EXPR_LOCATION (jump_func->value.constant.value) == UNKNOWN_LOCATION);
    5397       467563 :       stream_write_tree (ob,
    5398              :                          flag
    5399              :                          ? TREE_OPERAND (jump_func->value.constant.value, 0)
    5400              :                          : jump_func->value.constant.value, true);
    5401       467563 :       break;
    5402        77409 :     case IPA_JF_PASS_THROUGH:
    5403        77409 :       streamer_write_uhwi (ob, jump_func->value.pass_through.operation);
    5404        77409 :       if (jump_func->value.pass_through.operation == NOP_EXPR)
    5405              :         {
    5406        76550 :           streamer_write_uhwi (ob, jump_func->value.pass_through.formal_id);
    5407        76550 :           bp = bitpack_create (ob->main_stream);
    5408        76550 :           bp_pack_value (&bp, jump_func->value.pass_through.agg_preserved, 1);
    5409        76550 :           gcc_assert (!jump_func->value.pass_through.refdesc_decremented);
    5410        76550 :           streamer_write_bitpack (&bp);
    5411              :         }
    5412          859 :       else if (TREE_CODE_CLASS (jump_func->value.pass_through.operation)
    5413              :                == tcc_unary)
    5414              :         {
    5415           39 :           stream_write_tree (ob, jump_func->value.pass_through.op_type, true);
    5416           39 :           streamer_write_uhwi (ob, jump_func->value.pass_through.formal_id);
    5417              :         }
    5418              :       else
    5419              :         {
    5420          820 :           stream_write_tree (ob, jump_func->value.pass_through.op_type, true);
    5421          820 :           stream_write_tree (ob, jump_func->value.pass_through.operand, true);
    5422          820 :           streamer_write_uhwi (ob, jump_func->value.pass_through.formal_id);
    5423              :         }
    5424              :       break;
    5425         1365 :     case IPA_JF_ANCESTOR:
    5426         1365 :       streamer_write_uhwi (ob, jump_func->value.ancestor.offset);
    5427         1365 :       streamer_write_uhwi (ob, jump_func->value.ancestor.formal_id);
    5428         1365 :       bp = bitpack_create (ob->main_stream);
    5429         1365 :       bp_pack_value (&bp, jump_func->value.ancestor.agg_preserved, 1);
    5430         1365 :       bp_pack_value (&bp, jump_func->value.ancestor.keep_null, 1);
    5431         1365 :       streamer_write_bitpack (&bp);
    5432         1365 :       break;
    5433            0 :     default:
    5434            0 :       fatal_error (UNKNOWN_LOCATION, "invalid jump function in LTO stream");
    5435              :     }
    5436              : 
    5437       614386 :   count = vec_safe_length (jump_func->agg.items);
    5438       614386 :   streamer_write_uhwi (ob, count);
    5439       614386 :   if (count)
    5440              :     {
    5441         3442 :       bp = bitpack_create (ob->main_stream);
    5442         3442 :       bp_pack_value (&bp, jump_func->agg.by_ref, 1);
    5443         3442 :       streamer_write_bitpack (&bp);
    5444              :     }
    5445              : 
    5446       621264 :   FOR_EACH_VEC_SAFE_ELT (jump_func->agg.items, i, item)
    5447              :     {
    5448         6878 :       stream_write_tree (ob, item->type, true);
    5449         6878 :       streamer_write_uhwi (ob, item->offset);
    5450         6878 :       streamer_write_uhwi (ob, item->jftype);
    5451         6878 :       switch (item->jftype)
    5452              :         {
    5453              :         case IPA_JF_UNKNOWN:
    5454              :           break;
    5455         6304 :         case IPA_JF_CONST:
    5456         6304 :           stream_write_tree (ob, item->value.constant, true);
    5457         6304 :           break;
    5458          574 :         case IPA_JF_PASS_THROUGH:
    5459          574 :         case IPA_JF_LOAD_AGG:
    5460          574 :           streamer_write_uhwi (ob, item->value.pass_through.operation);
    5461          574 :           streamer_write_uhwi (ob, item->value.pass_through.formal_id);
    5462          574 :           if (item->value.pass_through.operation != NOP_EXPR)
    5463           12 :             stream_write_tree (ob, item->value.pass_through.op_type, true);
    5464          574 :           if (TREE_CODE_CLASS (item->value.pass_through.operation)
    5465              :                                                         != tcc_unary)
    5466           12 :             stream_write_tree (ob, item->value.pass_through.operand, true);
    5467          574 :           if (item->jftype == IPA_JF_LOAD_AGG)
    5468              :             {
    5469           97 :               stream_write_tree (ob, item->value.load_agg.type, true);
    5470           97 :               streamer_write_uhwi (ob, item->value.load_agg.offset);
    5471           97 :               bp = bitpack_create (ob->main_stream);
    5472           97 :               bp_pack_value (&bp, item->value.load_agg.by_ref, 1);
    5473           97 :               streamer_write_bitpack (&bp);
    5474              :             }
    5475              :           break;
    5476            0 :         default:
    5477            0 :           fatal_error (UNKNOWN_LOCATION,
    5478              :                        "invalid jump function in LTO stream");
    5479              :         }
    5480              :     }
    5481              : 
    5482       614386 :   bp = bitpack_create (ob->main_stream);
    5483       614386 :   if (jump_func->m_vr)
    5484       427545 :     jump_func->m_vr->streamer_write (ob);
    5485              :   else
    5486              :     {
    5487       186841 :       bp_pack_value (&bp, false, 1);
    5488       186841 :       streamer_write_bitpack (&bp);
    5489              :     }
    5490       614386 : }
    5491              : 
    5492              : /* Read in jump function JUMP_FUNC from IB.  */
    5493              : 
    5494              : static void
    5495       574736 : ipa_read_jump_function (class lto_input_block *ib,
    5496              :                         struct ipa_jump_func *jump_func,
    5497              :                         struct cgraph_edge *cs,
    5498              :                         class data_in *data_in,
    5499              :                         bool prevails)
    5500              : {
    5501       574736 :   enum jump_func_type jftype;
    5502       574736 :   enum tree_code operation;
    5503       574736 :   int i, count;
    5504       574736 :   int val = streamer_read_uhwi (ib);
    5505       574736 :   bool flag = val & 1;
    5506              : 
    5507       574736 :   jftype = (enum jump_func_type) (val / 2);
    5508       574736 :   switch (jftype)
    5509              :     {
    5510        52455 :     case IPA_JF_UNKNOWN:
    5511        52455 :       ipa_set_jf_unknown (jump_func);
    5512        52455 :       break;
    5513       451134 :     case IPA_JF_CONST:
    5514       451134 :       {
    5515       451134 :         tree t = stream_read_tree (ib, data_in);
    5516       451134 :         if (flag && prevails)
    5517       162176 :           t = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (t)), t);
    5518       451134 :         ipa_set_jf_constant (jump_func, t, cs);
    5519              :       }
    5520       451134 :       break;
    5521        70455 :     case IPA_JF_PASS_THROUGH:
    5522        70455 :       operation = (enum tree_code) streamer_read_uhwi (ib);
    5523        70455 :       if (operation == NOP_EXPR)
    5524              :         {
    5525        69883 :           int formal_id =  streamer_read_uhwi (ib);
    5526        69883 :           struct bitpack_d bp = streamer_read_bitpack (ib);
    5527        69883 :           bool agg_preserved = bp_unpack_value (&bp, 1);
    5528        69883 :           ipa_set_jf_simple_pass_through (jump_func, formal_id, agg_preserved);
    5529              :         }
    5530          572 :       else if (TREE_CODE_CLASS (operation) == tcc_unary)
    5531              :         {
    5532           19 :           tree op_type = stream_read_tree (ib, data_in);
    5533           19 :           int formal_id =  streamer_read_uhwi (ib);
    5534           19 :           ipa_set_jf_unary_pass_through (jump_func, formal_id, operation,
    5535              :                                          op_type);
    5536              :         }
    5537              :       else
    5538              :         {
    5539          553 :           tree op_type = stream_read_tree (ib, data_in);
    5540          553 :           tree operand = stream_read_tree (ib, data_in);
    5541          553 :           int formal_id =  streamer_read_uhwi (ib);
    5542          553 :           ipa_set_jf_arith_pass_through (jump_func, formal_id, operand,
    5543              :                                          operation, op_type);
    5544              :         }
    5545              :       break;
    5546          692 :     case IPA_JF_ANCESTOR:
    5547          692 :       {
    5548          692 :         HOST_WIDE_INT offset = streamer_read_uhwi (ib);
    5549          692 :         int formal_id = streamer_read_uhwi (ib);
    5550          692 :         struct bitpack_d bp = streamer_read_bitpack (ib);
    5551          692 :         bool agg_preserved = bp_unpack_value (&bp, 1);
    5552          692 :         bool keep_null = bp_unpack_value (&bp, 1);
    5553          692 :         ipa_set_ancestor_jf (jump_func, offset, formal_id, agg_preserved,
    5554              :                              keep_null);
    5555          692 :         break;
    5556              :       }
    5557            0 :     default:
    5558            0 :       fatal_error (UNKNOWN_LOCATION, "invalid jump function in LTO stream");
    5559              :     }
    5560              : 
    5561       574736 :   count = streamer_read_uhwi (ib);
    5562       574736 :   if (prevails)
    5563              :     {
    5564       574730 :       jump_func->agg.items = NULL;
    5565       574730 :       vec_safe_reserve (jump_func->agg.items, count, true);
    5566              :     }
    5567       574736 :   if (count)
    5568              :     {
    5569         3096 :       struct bitpack_d bp = streamer_read_bitpack (ib);
    5570         3096 :       jump_func->agg.by_ref = bp_unpack_value (&bp, 1);
    5571              :     }
    5572       581040 :   for (i = 0; i < count; i++)
    5573              :     {
    5574         6304 :       struct ipa_agg_jf_item item;
    5575         6304 :       item.type = stream_read_tree (ib, data_in);
    5576         6304 :       item.offset = streamer_read_uhwi (ib);
    5577         6304 :       item.jftype = (enum jump_func_type) streamer_read_uhwi (ib);
    5578              : 
    5579         6304 :       switch (item.jftype)
    5580              :         {
    5581              :         case IPA_JF_UNKNOWN:
    5582              :           break;
    5583         5814 :         case IPA_JF_CONST:
    5584         5814 :           item.value.constant = stream_read_tree (ib, data_in);
    5585         5814 :           break;
    5586          490 :         case IPA_JF_PASS_THROUGH:
    5587          490 :         case IPA_JF_LOAD_AGG:
    5588          490 :           operation = (enum tree_code) streamer_read_uhwi (ib);
    5589          490 :           item.value.pass_through.operation = operation;
    5590          490 :           item.value.pass_through.formal_id = streamer_read_uhwi (ib);
    5591          490 :           if (operation != NOP_EXPR)
    5592            8 :             item.value.pass_through.op_type = stream_read_tree (ib, data_in);
    5593              :           else
    5594              :             item.value.pass_through.op_type = NULL_TREE;
    5595          490 :           if (TREE_CODE_CLASS (operation) == tcc_unary)
    5596              :             item.value.pass_through.operand = NULL_TREE;
    5597              :           else
    5598            8 :             item.value.pass_through.operand = stream_read_tree (ib, data_in);
    5599          490 :           if (item.jftype == IPA_JF_LOAD_AGG)
    5600              :             {
    5601           57 :               struct bitpack_d bp;
    5602           57 :               item.value.load_agg.type = stream_read_tree (ib, data_in);
    5603           57 :               item.value.load_agg.offset = streamer_read_uhwi (ib);
    5604           57 :               bp = streamer_read_bitpack (ib);
    5605           57 :               item.value.load_agg.by_ref = bp_unpack_value (&bp, 1);
    5606              :             }
    5607              :           break;
    5608            0 :         default:
    5609            0 :           fatal_error (UNKNOWN_LOCATION,
    5610              :                        "invalid jump function in LTO stream");
    5611              :         }
    5612         6304 :       if (prevails)
    5613         6304 :         jump_func->agg.items->quick_push (item);
    5614              :     }
    5615              : 
    5616       574736 :   ipa_vr vr;
    5617       574736 :   vr.streamer_read (ib, data_in);
    5618       574736 :   if (vr.known_p ())
    5619              :     {
    5620       402447 :       if (prevails)
    5621       402441 :         ipa_set_jfunc_vr (jump_func, vr);
    5622              :     }
    5623              :   else
    5624       172289 :     jump_func->m_vr = NULL;
    5625       574736 : }
    5626              : 
    5627              : /* Stream out parts of cgraph_indirect_call_info corresponding to CS that are
    5628              :    relevant to indirect inlining to OB.  */
    5629              : 
    5630              : static void
    5631         2634 : ipa_write_indirect_edge_info (struct output_block *ob,
    5632              :                               struct cgraph_edge *cs)
    5633              : {
    5634         2634 :   struct bitpack_d bp;
    5635              : 
    5636         2634 :   bp = bitpack_create (ob->main_stream);
    5637         2634 :   bp_pack_enum (&bp, cgraph_indirect_info_kind, CIIK_N_KINDS,
    5638              :                 cs->indirect_info->kind);
    5639         2634 :   streamer_write_bitpack (&bp);
    5640              : 
    5641         2634 :   if (cgraph_polymorphic_indirect_info *pii
    5642         2634 :       = dyn_cast <cgraph_polymorphic_indirect_info *> (cs->indirect_info))
    5643              :     {
    5644         1025 :       bp = bitpack_create (ob->main_stream);
    5645         1025 :       bp_pack_value (&bp, pii->vptr_changed, 1);
    5646         1025 :       streamer_write_bitpack (&bp);
    5647              : 
    5648         1025 :       streamer_write_hwi (ob, pii->param_index);
    5649         1025 :       pii->context.stream_out (ob);
    5650         1025 :       streamer_write_hwi (ob, pii->otr_token);
    5651         1025 :       stream_write_tree (ob, pii->otr_type, true);
    5652         1025 :       streamer_write_hwi (ob, pii->offset);
    5653              :     }
    5654         1609 :   else if (cgraph_simple_indirect_info *sii
    5655         1609 :            = dyn_cast <cgraph_simple_indirect_info *> (cs->indirect_info))
    5656              :     {
    5657         1585 :       bp = bitpack_create (ob->main_stream);
    5658         1585 :       bp_pack_value (&bp, sii->agg_contents, 1);
    5659         1585 :       bp_pack_value (&bp, sii->member_ptr, 1);
    5660         1585 :       bp_pack_value (&bp, sii->fnptr_loaded_from_record, 1);
    5661         1585 :       bp_pack_value (&bp, sii->by_ref, 1);
    5662         1585 :       bp_pack_value (&bp, sii->guaranteed_unmodified, 1);
    5663         1585 :       streamer_write_bitpack (&bp);
    5664              : 
    5665         1585 :       streamer_write_hwi (ob, sii->param_index);
    5666         1585 :       if (sii->agg_contents)
    5667           56 :         streamer_write_hwi (ob, sii->offset);
    5668              :       else
    5669         1529 :         gcc_assert (sii->offset == 0);
    5670         1585 :       if (sii->fnptr_loaded_from_record)
    5671              :         {
    5672          136 :           stream_write_tree (ob, sii->rec_type, true);
    5673          136 :           streamer_write_uhwi (ob, sii->fld_offset);
    5674              :         }
    5675              :     }
    5676              :   else
    5677           24 :     gcc_assert (cs->indirect_info->param_index == -1);
    5678         2634 : }
    5679              : 
    5680              : /* Read in parts of cgraph_indirect_call_info corresponding to CS that are
    5681              :    relevant to indirect inlining from IB.  */
    5682              : 
    5683              : static void
    5684         1437 : ipa_read_indirect_edge_info (class lto_input_block *ib,
    5685              :                              class data_in *data_in,
    5686              :                              struct cgraph_edge *cs,
    5687              :                              class ipa_node_params *info)
    5688              : {
    5689         1437 :   struct bitpack_d bp;
    5690              : 
    5691         1437 :   bp = streamer_read_bitpack (ib);
    5692         1437 :   enum cgraph_indirect_info_kind ii_kind
    5693         1437 :     = bp_unpack_enum (&bp, cgraph_indirect_info_kind, CIIK_N_KINDS);
    5694         1437 :   gcc_assert (ii_kind == cs->indirect_info->kind);
    5695              : 
    5696         1437 :   if (cgraph_polymorphic_indirect_info *pii
    5697         1437 :       = dyn_cast <cgraph_polymorphic_indirect_info *> (cs->indirect_info))
    5698              :     {
    5699           95 :       bp = streamer_read_bitpack (ib);
    5700           95 :       pii->vptr_changed = bp_unpack_value (&bp, 1);
    5701              : 
    5702           95 :       pii->param_index = (int) streamer_read_hwi (ib);
    5703           95 :       pii->context.stream_in (ib, data_in);
    5704           95 :       pii->otr_token = (HOST_WIDE_INT) streamer_read_hwi (ib);
    5705           95 :       pii->otr_type = stream_read_tree (ib, data_in);
    5706           95 :       pii->offset = (HOST_WIDE_INT) streamer_read_hwi (ib);
    5707              : 
    5708           95 :       if (info && pii->param_index >= 0)
    5709              :         {
    5710           72 :           ipa_set_param_used_by_polymorphic_call (info, pii->param_index, true);
    5711           72 :           ipa_set_param_used_by_indirect_call (info, pii->param_index, true);
    5712              :         }
    5713              :     }
    5714         1342 :   else if (cgraph_simple_indirect_info *sii
    5715         1342 :            = dyn_cast <cgraph_simple_indirect_info *> (cs->indirect_info))
    5716              :     {
    5717         1333 :       bp = streamer_read_bitpack (ib);
    5718         1333 :       sii->agg_contents = bp_unpack_value (&bp, 1);
    5719         1333 :       sii->member_ptr = bp_unpack_value (&bp, 1);
    5720         1333 :       sii->fnptr_loaded_from_record = bp_unpack_value (&bp, 1);
    5721         1333 :       sii->by_ref = bp_unpack_value (&bp, 1);
    5722         1333 :       sii->guaranteed_unmodified = bp_unpack_value (&bp, 1);
    5723              : 
    5724         1333 :       sii->param_index = (int) streamer_read_hwi (ib);
    5725         1333 :       if (sii->agg_contents)
    5726           32 :         sii->offset = (HOST_WIDE_INT) streamer_read_hwi (ib);
    5727              :       else
    5728         1301 :         sii->offset = 0;
    5729         1333 :       if (sii->fnptr_loaded_from_record)
    5730              :         {
    5731           74 :           sii->rec_type = stream_read_tree (ib, data_in);
    5732           74 :           sii->fld_offset = (unsigned) streamer_read_uhwi (ib);
    5733              :         }
    5734         1333 :       if (info && sii->param_index >= 0)
    5735          266 :         ipa_set_param_used_by_indirect_call (info, sii->param_index, true);
    5736              :     }
    5737              :   else
    5738            9 :     cs->indirect_info->param_index = -1;
    5739         1437 : }
    5740              : 
    5741              : /* Stream out NODE info to OB.  */
    5742              : 
    5743              : static void
    5744        95403 : ipa_write_node_info (struct output_block *ob, struct cgraph_node *node)
    5745              : {
    5746        95403 :   int node_ref;
    5747        95403 :   lto_symtab_encoder_t encoder;
    5748        95403 :   ipa_node_params *info = ipa_node_params_sum->get (node);
    5749        95403 :   int j;
    5750        95403 :   struct cgraph_edge *e;
    5751        95403 :   struct bitpack_d bp;
    5752              : 
    5753        95403 :   encoder = ob->decl_state->symtab_node_encoder;
    5754        95403 :   node_ref = lto_symtab_encoder_encode (encoder, node);
    5755        95403 :   streamer_write_uhwi (ob, node_ref);
    5756              : 
    5757        95403 :   streamer_write_uhwi (ob, ipa_get_param_count (info));
    5758       463448 :   for (j = 0; j < ipa_get_param_count (info); j++)
    5759       104234 :     streamer_write_uhwi (ob, ipa_get_param_move_cost (info, j));
    5760        95403 :   bp = bitpack_create (ob->main_stream);
    5761        95403 :   gcc_assert (info->analysis_done
    5762              :               || ipa_get_param_count (info) == 0);
    5763        95403 :   gcc_assert (!info->node_enqueued);
    5764        95403 :   gcc_assert (!info->ipcp_orig_node);
    5765       368045 :   for (j = 0; j < ipa_get_param_count (info); j++)
    5766              :     {
    5767              :       /* TODO: We could just not stream the bit in the undescribed case. */
    5768       104234 :       bool d = (ipa_get_controlled_uses (info, j) != IPA_UNDESCRIBED_USE)
    5769       104234 :         ? ipa_get_param_load_dereferenced (info, j) : true;
    5770       104234 :       bp_pack_value (&bp, d, 1);
    5771       104234 :       bp_pack_value (&bp, ipa_is_param_used (info, j), 1);
    5772              :     }
    5773        95403 :   streamer_write_bitpack (&bp);
    5774       463448 :   for (j = 0; j < ipa_get_param_count (info); j++)
    5775              :     {
    5776       104234 :       streamer_write_hwi (ob, ipa_get_controlled_uses (info, j));
    5777       104234 :       stream_write_tree (ob, ipa_get_type (info, j), true);
    5778              :     }
    5779       462136 :   for (e = node->callees; e; e = e->next_callee)
    5780              :     {
    5781       366733 :       ipa_edge_args *args = ipa_edge_args_sum->get (e);
    5782              : 
    5783       366733 :       if (!args)
    5784              :         {
    5785          805 :           streamer_write_uhwi (ob, 0);
    5786          805 :           continue;
    5787              :         }
    5788              : 
    5789       365928 :       streamer_write_uhwi (ob,
    5790       365928 :                            ipa_get_cs_argument_count (args) * 2
    5791       365928 :                            + (args->polymorphic_call_contexts != NULL));
    5792      2209989 :       for (j = 0; j < ipa_get_cs_argument_count (args); j++)
    5793              :         {
    5794       611214 :           ipa_write_jump_function (ob, ipa_get_ith_jump_func (args, j));
    5795       611214 :           if (args->polymorphic_call_contexts != NULL)
    5796         2507 :             ipa_get_ith_polymorhic_call_context (args, j)->stream_out (ob);
    5797              :         }
    5798              :     }
    5799        98037 :   for (e = node->indirect_calls; e; e = e->next_callee)
    5800              :     {
    5801         2634 :       ipa_edge_args *args = ipa_edge_args_sum->get (e);
    5802         2634 :       if (!args)
    5803            6 :         streamer_write_uhwi (ob, 0);
    5804              :       else
    5805              :         {
    5806         2628 :           streamer_write_uhwi (ob,
    5807         2628 :                                ipa_get_cs_argument_count (args) * 2
    5808         2628 :                                + (args->polymorphic_call_contexts != NULL));
    5809        14088 :           for (j = 0; j < ipa_get_cs_argument_count (args); j++)
    5810              :             {
    5811         3172 :               ipa_write_jump_function (ob, ipa_get_ith_jump_func (args, j));
    5812         3172 :               if (args->polymorphic_call_contexts != NULL)
    5813         1327 :                 ipa_get_ith_polymorhic_call_context (args, j)->stream_out (ob);
    5814              :             }
    5815              :         }
    5816         2634 :       ipa_write_indirect_edge_info (ob, e);
    5817              :     }
    5818        95403 : }
    5819              : 
    5820              : /* Stream in edge E from IB.  */
    5821              : 
    5822              : static void
    5823       338219 : ipa_read_edge_info (class lto_input_block *ib,
    5824              :                     class data_in *data_in,
    5825              :                     struct cgraph_edge *e, bool prevails)
    5826              : {
    5827       338219 :   int count = streamer_read_uhwi (ib);
    5828       338219 :   bool contexts_computed = count & 1;
    5829              : 
    5830       338219 :   count /= 2;
    5831       338219 :   if (!count)
    5832              :     return;
    5833       236593 :   if (prevails
    5834       236593 :       && (e->possibly_call_in_translation_unit_p ()
    5835              :           /* Also stream in jump functions to builtins in hope that they
    5836              :              will get fnspecs.  */
    5837       116560 :           || fndecl_built_in_p (e->callee->decl, BUILT_IN_NORMAL)))
    5838              :     {
    5839       225174 :       ipa_edge_args *args = ipa_edge_args_sum->get_create (e);
    5840       225174 :       vec_safe_grow_cleared (args->jump_functions, count, true);
    5841       225174 :       if (contexts_computed)
    5842          670 :         vec_safe_grow_cleared (args->polymorphic_call_contexts, count, true);
    5843       781568 :       for (int k = 0; k < count; k++)
    5844              :         {
    5845       556394 :           ipa_read_jump_function (ib, ipa_get_ith_jump_func (args, k), e,
    5846              :                                   data_in, prevails);
    5847       556394 :           if (contexts_computed)
    5848         1047 :             ipa_get_ith_polymorhic_call_context (args, k)->stream_in
    5849         1047 :                                                              (ib, data_in);
    5850              :         }
    5851              :     }
    5852              :   else
    5853              :     {
    5854        29761 :       for (int k = 0; k < count; k++)
    5855              :         {
    5856        18342 :           struct ipa_jump_func dummy;
    5857        18342 :           ipa_read_jump_function (ib, &dummy, e,
    5858              :                                   data_in, prevails);
    5859        18342 :           if (contexts_computed)
    5860              :             {
    5861          467 :               class ipa_polymorphic_call_context ctx;
    5862          467 :               ctx.stream_in (ib, data_in);
    5863              :             }
    5864              :         }
    5865              :     }
    5866              : }
    5867              : 
    5868              : /* Stream in NODE info from IB.  */
    5869              : 
    5870              : static void
    5871        79723 : ipa_read_node_info (class lto_input_block *ib, struct cgraph_node *node,
    5872              :                     class data_in *data_in)
    5873              : {
    5874        79723 :   int k;
    5875        79723 :   struct cgraph_edge *e;
    5876        79723 :   struct bitpack_d bp;
    5877        79723 :   bool prevails = node->prevailing_p ();
    5878        79723 :   ipa_node_params *info
    5879        79723 :     = prevails ? ipa_node_params_sum->get_create (node) : NULL;
    5880              : 
    5881        79723 :   int param_count = streamer_read_uhwi (ib);
    5882        79723 :   if (prevails)
    5883              :     {
    5884        79705 :       ipa_alloc_node_params (node, param_count);
    5885       240341 :       for (k = 0; k < param_count; k++)
    5886        80931 :         (*info->descriptors)[k].move_cost = streamer_read_uhwi (ib);
    5887        79705 :       if (ipa_get_param_count (info) != 0)
    5888        54440 :         info->analysis_done = true;
    5889        79705 :       info->node_enqueued = false;
    5890              :     }
    5891              :   else
    5892           27 :     for (k = 0; k < param_count; k++)
    5893            9 :       streamer_read_uhwi (ib);
    5894              : 
    5895        79723 :   bp = streamer_read_bitpack (ib);
    5896       160663 :   for (k = 0; k < param_count; k++)
    5897              :     {
    5898        80940 :       bool load_dereferenced = bp_unpack_value (&bp, 1);
    5899        80940 :       bool used = bp_unpack_value (&bp, 1);
    5900              : 
    5901        80940 :       if (prevails)
    5902              :         {
    5903        80931 :           ipa_set_param_load_dereferenced (info, k, load_dereferenced);
    5904        80931 :           ipa_set_param_used (info, k, used);
    5905              :         }
    5906              :     }
    5907       160663 :   for (k = 0; k < param_count; k++)
    5908              :     {
    5909        80940 :       int nuses = streamer_read_hwi (ib);
    5910        80940 :       tree type = stream_read_tree (ib, data_in);
    5911              : 
    5912        80940 :       if (prevails)
    5913              :         {
    5914        80931 :           ipa_set_controlled_uses (info, k, nuses);
    5915        80931 :           (*info->descriptors)[k].decl_or_type = type;
    5916              :         }
    5917              :     }
    5918       416505 :   for (e = node->callees; e; e = e->next_callee)
    5919       336782 :     ipa_read_edge_info (ib, data_in, e, prevails);
    5920        81160 :   for (e = node->indirect_calls; e; e = e->next_callee)
    5921              :     {
    5922         1437 :       ipa_read_edge_info (ib, data_in, e, prevails);
    5923         1437 :       ipa_read_indirect_edge_info (ib, data_in, e, info);
    5924              :     }
    5925        79723 : }
    5926              : 
    5927              : /* Stream out ipa_return_summary.  */
    5928              : static void
    5929        32481 : ipa_write_return_summaries (output_block *ob)
    5930              : {
    5931        32481 :   if (!ipa_return_value_sum)
    5932              :     {
    5933        15168 :       streamer_write_uhwi (ob, 0);
    5934        15168 :       return;
    5935              :     }
    5936              : 
    5937        17313 :   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
    5938        17313 :   unsigned int count = 0;
    5939       452800 :   for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
    5940              :     {
    5941       209087 :       toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
    5942       418174 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (tnode);
    5943       171931 :       ipa_return_value_summary *v;
    5944              : 
    5945       171931 :       if (cnode && cnode->definition && !cnode->alias
    5946       126344 :           && (v = ipa_return_value_sum->get (cnode))
    5947        26125 :           && v->vr)
    5948        26125 :         count++;
    5949              :     }
    5950        17313 :   streamer_write_uhwi (ob, count);
    5951              : 
    5952       470113 :   for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
    5953              :     {
    5954       209087 :       toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
    5955       418174 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (tnode);
    5956       171931 :       ipa_return_value_summary *v;
    5957              : 
    5958       171931 :       if (cnode && cnode->definition && !cnode->alias
    5959       126344 :           && (v = ipa_return_value_sum->get (cnode))
    5960        26125 :           && v->vr)
    5961              :         {
    5962        26125 :           streamer_write_uhwi
    5963        26125 :             (ob,
    5964        26125 :              lto_symtab_encoder_encode (encoder, cnode));
    5965        26125 :           v->vr->streamer_write (ob);
    5966              :         }
    5967              :     }
    5968              : }
    5969              : 
    5970              : /* Write jump functions for nodes in SET.  */
    5971              : 
    5972              : void
    5973        23943 : ipa_prop_write_jump_functions (void)
    5974              : {
    5975        23943 :   struct output_block *ob;
    5976        23943 :   unsigned int count = 0;
    5977        23943 :   lto_symtab_encoder_iterator lsei;
    5978        23943 :   lto_symtab_encoder_t encoder;
    5979              : 
    5980        23943 :   if (!ipa_node_params_sum || !ipa_edge_args_sum)
    5981            0 :     return;
    5982              : 
    5983        23943 :   ob = create_output_block (LTO_section_jump_functions);
    5984        23943 :   encoder = ob->decl_state->symtab_node_encoder;
    5985        23943 :   ob->symbol = NULL;
    5986       131446 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5987       107503 :        lsei_next_function_in_partition (&lsei))
    5988              :     {
    5989       107503 :       cgraph_node *node = lsei_cgraph_node (lsei);
    5990       107503 :       if (node->has_gimple_body_p ()
    5991       107503 :           && ipa_node_params_sum->get (node) != NULL)
    5992        95403 :         count++;
    5993              :     }
    5994              : 
    5995        23943 :   streamer_write_uhwi (ob, count);
    5996              : 
    5997              :   /* Process all of the functions.  */
    5998       131446 :   for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
    5999       107503 :        lsei_next_function_in_partition (&lsei))
    6000              :     {
    6001       107503 :       cgraph_node *node = lsei_cgraph_node (lsei);
    6002       107503 :       if (node->has_gimple_body_p ()
    6003       107503 :           && ipa_node_params_sum->get (node) != NULL)
    6004        95403 :         ipa_write_node_info (ob, node);
    6005              :     }
    6006        23943 :   ipa_write_return_summaries (ob);
    6007              : 
    6008        23943 :   if (noted_fnptrs_in_records)
    6009              :     {
    6010          350 :       count = 0;
    6011         1081 :       for (auto iter = noted_fnptrs_in_records->begin ();
    6012         1081 :            iter != noted_fnptrs_in_records->end();
    6013          731 :            ++iter)
    6014          731 :         if ((*iter)->fn)
    6015          723 :           count++;
    6016          350 :       streamer_write_uhwi (ob, count);
    6017              : 
    6018         1081 :       for (auto iter = noted_fnptrs_in_records->begin ();
    6019         1431 :            iter != noted_fnptrs_in_records->end();
    6020          731 :            ++iter)
    6021          731 :         if ((*iter)->fn)
    6022              :           {
    6023          723 :             stream_write_tree (ob, (*iter)->rec_type, true);
    6024          723 :             stream_write_tree (ob, (*iter)->fn, true);
    6025          723 :             streamer_write_uhwi (ob, (*iter)->fld_offset);
    6026              :           }
    6027              :     }
    6028              :   else
    6029        23593 :     streamer_write_uhwi (ob, 0);
    6030              : 
    6031        23943 :   produce_asm (ob);
    6032        23943 :   destroy_output_block (ob);
    6033              : }
    6034              : 
    6035              : /* Record that return value range of N is VAL.  */
    6036              : 
    6037              : static void
    6038       772426 : ipa_record_return_value_range_1 (cgraph_node *n, value_range val)
    6039              : {
    6040       772426 :   if (!ipa_return_value_sum)
    6041              :     {
    6042        90070 :       if (!ipa_vr_hash_table)
    6043        78777 :         ipa_vr_hash_table = hash_table<ipa_vr_ggc_hash_traits>::create_ggc (37);
    6044        90070 :       ipa_return_value_sum = new (ggc_alloc_no_dtor <ipa_return_value_sum_t> ())
    6045        90070 :               ipa_return_value_sum_t (symtab, true);
    6046        90070 :       ipa_return_value_sum->disable_insertion_hook ();
    6047              :     }
    6048       772426 :   ipa_return_value_sum->get_create (n)->vr = ipa_get_value_range (val);
    6049       772426 :   if (dump_file && (dump_flags & TDF_DETAILS))
    6050              :     {
    6051           27 :       fprintf (dump_file, "Recording return range of %s:", n->dump_name ());
    6052           27 :       val.dump (dump_file);
    6053           27 :       fprintf (dump_file, "\n");
    6054              :     }
    6055       772426 : }
    6056              : 
    6057              : /* Stream out ipa_return_summary.  */
    6058              : static void
    6059        22434 : ipa_read_return_summaries (lto_input_block *ib,
    6060              :                            struct lto_file_decl_data *file_data,
    6061              :                            class data_in *data_in)
    6062              : {
    6063        22434 :   unsigned int f_count = streamer_read_uhwi (ib);
    6064        44971 :   for (unsigned int i = 0; i < f_count; i++)
    6065              :     {
    6066        22537 :       unsigned int index = streamer_read_uhwi (ib);
    6067        22537 :       lto_symtab_encoder_t encoder = file_data->symtab_node_encoder;
    6068        22537 :       struct cgraph_node *node
    6069              :               = dyn_cast <cgraph_node *>
    6070        22537 :                   (lto_symtab_encoder_deref (encoder, index));
    6071        22537 :       ipa_vr rvr;
    6072        22537 :       rvr.streamer_read (ib, data_in);
    6073        22537 :       if (node->prevailing_p ())
    6074              :         {
    6075        22535 :           value_range tmp;
    6076        22535 :           rvr.get_vrange (tmp);
    6077        22535 :           ipa_record_return_value_range_1 (node, tmp);
    6078        22535 :         }
    6079              :     }
    6080        22434 : }
    6081              : 
    6082              : /* Read section in file FILE_DATA of length LEN with data DATA.  */
    6083              : 
    6084              : static void
    6085        13896 : ipa_prop_read_section (struct lto_file_decl_data *file_data, const char *data,
    6086              :                        size_t len)
    6087              : {
    6088        13896 :   const struct lto_function_header *header =
    6089              :     (const struct lto_function_header *) data;
    6090        13896 :   const int cfg_offset = sizeof (struct lto_function_header);
    6091        13896 :   const int main_offset = cfg_offset + header->cfg_size;
    6092        13896 :   const int string_offset = main_offset + header->main_size;
    6093        13896 :   class data_in *data_in;
    6094        13896 :   unsigned int i;
    6095        13896 :   unsigned int count;
    6096              : 
    6097        13896 :   lto_input_block ib_main ((const char *) data + main_offset,
    6098        13896 :                            header->main_size, file_data);
    6099              : 
    6100        13896 :   data_in =
    6101        27792 :     lto_data_in_create (file_data, (const char *) data + string_offset,
    6102        13896 :                         header->string_size, vNULL);
    6103        13896 :   count = streamer_read_uhwi (&ib_main);
    6104              : 
    6105        93619 :   for (i = 0; i < count; i++)
    6106              :     {
    6107        79723 :       unsigned int index;
    6108        79723 :       struct cgraph_node *node;
    6109        79723 :       lto_symtab_encoder_t encoder;
    6110              : 
    6111        79723 :       index = streamer_read_uhwi (&ib_main);
    6112        79723 :       encoder = file_data->symtab_node_encoder;
    6113        79723 :       node = dyn_cast<cgraph_node *> (lto_symtab_encoder_deref (encoder,
    6114              :                                                                 index));
    6115        79723 :       gcc_assert (node->definition);
    6116        79723 :       ipa_read_node_info (&ib_main, node, data_in);
    6117              :     }
    6118        13896 :   ipa_read_return_summaries (&ib_main, file_data, data_in);
    6119              : 
    6120        13896 :   count = streamer_read_uhwi (&ib_main);
    6121        14562 :   for (i = 0; i < count; i++)
    6122              :     {
    6123          666 :       tree rec_type = stream_read_tree (&ib_main, data_in);
    6124          666 :       tree fn = stream_read_tree (&ib_main, data_in);
    6125          666 :       unsigned fld_offset = (unsigned) streamer_read_uhwi (&ib_main);
    6126          666 :       note_fnptr_in_record (rec_type, fld_offset, fn);
    6127              :     }
    6128              : 
    6129        13896 :   lto_free_section_data (file_data, LTO_section_jump_functions, NULL, data,
    6130              :                          len);
    6131        13896 :   lto_data_in_delete (data_in);
    6132        13896 : }
    6133              : 
    6134              : /* Read ipcp jump functions.  */
    6135              : 
    6136              : void
    6137        12782 : ipa_prop_read_jump_functions (void)
    6138              : {
    6139        12782 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    6140        12782 :   struct lto_file_decl_data *file_data;
    6141        12782 :   unsigned int j = 0;
    6142              : 
    6143        12782 :   ipa_check_create_node_params ();
    6144        12782 :   ipa_check_create_edge_args ();
    6145        12782 :   ipa_register_cgraph_hooks ();
    6146              : 
    6147        39460 :   while ((file_data = file_data_vec[j++]))
    6148              :     {
    6149        13896 :       size_t len;
    6150        13896 :       const char *data
    6151        13896 :         = lto_get_summary_section_data (file_data, LTO_section_jump_functions,
    6152              :                                         &len);
    6153        13896 :       if (data)
    6154        13896 :         ipa_prop_read_section (file_data, data, len);
    6155              :     }
    6156        12782 : }
    6157              : 
    6158              : /* Return true if the IPA-CP transformation summary TS is non-NULL and contains
    6159              :    useful info.  */
    6160              : static bool
    6161       169976 : useful_ipcp_transformation_info_p (ipcp_transformation *ts)
    6162              : {
    6163       169976 :   if (!ts)
    6164              :     return false;
    6165        24530 :   if (!vec_safe_is_empty (ts->m_agg_values)
    6166        24106 :       || !vec_safe_is_empty (ts->m_vr))
    6167        24232 :     return true;
    6168              :   return false;
    6169              : }
    6170              : 
    6171              : /* Write into OB IPA-CP transformation summary TS describing NODE.  */
    6172              : 
    6173              : void
    6174        12098 : write_ipcp_transformation_info (output_block *ob, cgraph_node *node,
    6175              :                                 ipcp_transformation *ts)
    6176              : {
    6177        12098 :   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
    6178        12098 :   int node_ref = lto_symtab_encoder_encode (encoder, node);
    6179        12098 :   streamer_write_uhwi (ob, node_ref);
    6180              : 
    6181        12307 :   streamer_write_uhwi (ob, vec_safe_length (ts->m_agg_values));
    6182        13755 :   for (const ipa_argagg_value &av : ts->m_agg_values)
    6183              :     {
    6184         1239 :       struct bitpack_d bp;
    6185              : 
    6186         1239 :       stream_write_tree (ob, av.value, true);
    6187         1239 :       streamer_write_uhwi (ob, av.unit_offset);
    6188         1239 :       streamer_write_uhwi (ob, av.index);
    6189              : 
    6190         1239 :       bp = bitpack_create (ob->main_stream);
    6191         1239 :       bp_pack_value (&bp, av.by_ref, 1);
    6192         1239 :       bp_pack_value (&bp, av.killed, 1);
    6193         1239 :       streamer_write_bitpack (&bp);
    6194              :     }
    6195              : 
    6196              :   /* If all instances of this node are inlined, ipcp info is not useful.  */
    6197        12098 :   if (!lto_symtab_encoder_only_for_inlining_p (encoder, node))
    6198              :     {
    6199        21824 :       streamer_write_uhwi (ob, vec_safe_length (ts->m_vr));
    6200        53278 :       for (const ipa_vr &parm_vr : ts->m_vr)
    6201        20546 :         parm_vr.streamer_write (ob);
    6202              :     }
    6203              :   else
    6204         1182 :     streamer_write_uhwi (ob, 0);
    6205        12098 : }
    6206              : 
    6207              : /* Stream in the aggregate value replacement chain for NODE from IB.  */
    6208              : 
    6209              : static void
    6210        12098 : read_ipcp_transformation_info (lto_input_block *ib, cgraph_node *node,
    6211              :                                data_in *data_in)
    6212              : {
    6213        12098 :   unsigned int count, i;
    6214        12098 :   ipcp_transformation_initialize ();
    6215        12098 :   ipcp_transformation *ts = ipcp_transformation_sum->get_create (node);
    6216              : 
    6217        12098 :   count = streamer_read_uhwi (ib);
    6218        12098 :   if (count > 0)
    6219              :     {
    6220          209 :       vec_safe_grow_cleared (ts->m_agg_values, count, true);
    6221         1657 :       for (i = 0; i <count; i++)
    6222              :         {
    6223         1239 :           ipa_argagg_value *av = &(*ts->m_agg_values)[i];;
    6224              : 
    6225         1239 :           av->value = stream_read_tree (ib, data_in);
    6226         1239 :           av->unit_offset = streamer_read_uhwi (ib);
    6227         1239 :           av->index = streamer_read_uhwi (ib);
    6228              : 
    6229         1239 :           bitpack_d bp = streamer_read_bitpack (ib);
    6230         1239 :           av->by_ref = bp_unpack_value (&bp, 1);
    6231         1239 :           av->killed = bp_unpack_value (&bp, 1);
    6232              :         }
    6233              :     }
    6234              : 
    6235        12098 :   count = streamer_read_uhwi (ib);
    6236        12098 :   if (count > 0)
    6237              :     {
    6238        10908 :       vec_safe_grow_cleared (ts->m_vr, count, true);
    6239        42362 :       for (i = 0; i < count; i++)
    6240              :         {
    6241        20546 :           ipa_vr *parm_vr;
    6242        20546 :           parm_vr = &(*ts->m_vr)[i];
    6243        20546 :           parm_vr->streamer_read (ib, data_in);
    6244              :         }
    6245              :     }
    6246        12098 : }
    6247              : 
    6248              : 
    6249              : /* Write all aggregate replacement for nodes in set.  */
    6250              : 
    6251              : void
    6252         8538 : ipcp_write_transformation_summaries (void)
    6253              : {
    6254         8538 :   struct output_block *ob;
    6255         8538 :   unsigned int count = 0;
    6256         8538 :   lto_symtab_encoder_t encoder;
    6257              : 
    6258         8538 :   ob = create_output_block (LTO_section_ipcp_transform);
    6259         8538 :   encoder = ob->decl_state->symtab_node_encoder;
    6260         8538 :   ob->symbol = NULL;
    6261              : 
    6262       237904 :   for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
    6263              :     {
    6264       110418 :       toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
    6265       110418 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (tnode);
    6266       110418 :       if (!cnode)
    6267        25430 :         continue;
    6268        84988 :       ipcp_transformation *ts = ipcp_get_transformation_summary (cnode);
    6269        84988 :       if (useful_ipcp_transformation_info_p (ts)
    6270        84988 :           && lto_symtab_encoder_encode_body_p (encoder, cnode))
    6271        12098 :         count++;
    6272              :     }
    6273              : 
    6274         8538 :   streamer_write_uhwi (ob, count);
    6275              : 
    6276       246442 :   for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
    6277              :     {
    6278       110418 :       toplevel_node *tnode = lto_symtab_encoder_deref (encoder, i);
    6279       110418 :       cgraph_node *cnode = dyn_cast <cgraph_node *> (tnode);
    6280       110418 :       if (!cnode)
    6281        25430 :         continue;
    6282        84988 :       ipcp_transformation *ts = ipcp_get_transformation_summary (cnode);
    6283        84988 :       if (useful_ipcp_transformation_info_p (ts)
    6284        84988 :           && lto_symtab_encoder_encode_body_p (encoder, cnode))
    6285        12098 :         write_ipcp_transformation_info (ob, cnode, ts);
    6286              :     }
    6287         8538 :   ipa_write_return_summaries (ob);
    6288         8538 :   produce_asm (ob);
    6289         8538 :   destroy_output_block (ob);
    6290         8538 : }
    6291              : 
    6292              : /* Read replacements section in file FILE_DATA of length LEN with data
    6293              :    DATA.  */
    6294              : 
    6295              : static void
    6296         8538 : read_replacements_section (struct lto_file_decl_data *file_data,
    6297              :                            const char *data,
    6298              :                            size_t len)
    6299              : {
    6300         8538 :   const struct lto_function_header *header =
    6301              :     (const struct lto_function_header *) data;
    6302         8538 :   const int cfg_offset = sizeof (struct lto_function_header);
    6303         8538 :   const int main_offset = cfg_offset + header->cfg_size;
    6304         8538 :   const int string_offset = main_offset + header->main_size;
    6305         8538 :   class data_in *data_in;
    6306         8538 :   unsigned int i;
    6307         8538 :   unsigned int count;
    6308              : 
    6309         8538 :   lto_input_block ib_main ((const char *) data + main_offset,
    6310         8538 :                            header->main_size, file_data);
    6311              : 
    6312         8538 :   data_in = lto_data_in_create (file_data, (const char *) data + string_offset,
    6313         8538 :                                 header->string_size, vNULL);
    6314         8538 :   count = streamer_read_uhwi (&ib_main);
    6315              : 
    6316        20636 :   for (i = 0; i < count; i++)
    6317              :     {
    6318        12098 :       unsigned int index;
    6319        12098 :       struct cgraph_node *node;
    6320        12098 :       lto_symtab_encoder_t encoder;
    6321              : 
    6322        12098 :       index = streamer_read_uhwi (&ib_main);
    6323        12098 :       encoder = file_data->symtab_node_encoder;
    6324        12098 :       node = dyn_cast<cgraph_node *> (lto_symtab_encoder_deref (encoder,
    6325              :                                                                 index));
    6326        12098 :       read_ipcp_transformation_info (&ib_main, node, data_in);
    6327              :     }
    6328         8538 :   ipa_read_return_summaries (&ib_main, file_data, data_in);
    6329         8538 :   lto_free_section_data (file_data, LTO_section_jump_functions, NULL, data,
    6330              :                          len);
    6331         8538 :   lto_data_in_delete (data_in);
    6332         8538 : }
    6333              : 
    6334              : /* Read IPA-CP aggregate replacements.  */
    6335              : 
    6336              : void
    6337         8538 : ipcp_read_transformation_summaries (void)
    6338              : {
    6339         8538 :   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
    6340         8538 :   struct lto_file_decl_data *file_data;
    6341         8538 :   unsigned int j = 0;
    6342              : 
    6343        25614 :   while ((file_data = file_data_vec[j++]))
    6344              :     {
    6345         8538 :       size_t len;
    6346         8538 :       const char *data
    6347         8538 :         = lto_get_summary_section_data (file_data, LTO_section_ipcp_transform,
    6348              :                                         &len);
    6349         8538 :       if (data)
    6350         8538 :         read_replacements_section (file_data, data, len);
    6351              :     }
    6352         8538 : }
    6353              : 
    6354              : /* Adjust the aggregate replacements in TS to reflect any parameter removals
    6355              :    which might have already taken place.  If after adjustments there are no
    6356              :    aggregate replacements left, the m_agg_values will be set to NULL.  In other
    6357              :    cases, it may be shrunk.  */
    6358              : 
    6359              : static void
    6360         1871 : adjust_agg_replacement_values (cgraph_node *node, ipcp_transformation *ts)
    6361              : {
    6362         1871 :   clone_info *cinfo = clone_info::get (node);
    6363         1871 :   if (!cinfo || !cinfo->param_adjustments)
    6364              :     return;
    6365              : 
    6366          916 :   auto_vec<int, 16> new_indices;
    6367          916 :   cinfo->param_adjustments->get_updated_indices (&new_indices);
    6368          916 :   bool removed_item = false;
    6369          916 :   unsigned dst_index = 0;
    6370          916 :   unsigned count = ts->m_agg_values->length ();
    6371         5269 :   for (unsigned i = 0; i < count; i++)
    6372              :     {
    6373         4353 :       ipa_argagg_value *v = &(*ts->m_agg_values)[i];
    6374         4353 :       gcc_checking_assert (v->index >= 0);
    6375              : 
    6376         4353 :       int new_idx = -1;
    6377         4353 :       if ((unsigned) v->index < new_indices.length ())
    6378         2748 :         new_idx = new_indices[v->index];
    6379              : 
    6380         2748 :       if (new_idx >= 0)
    6381              :         {
    6382         1736 :           v->index = new_idx;
    6383         1736 :           if (removed_item)
    6384           11 :             (*ts->m_agg_values)[dst_index] = *v;
    6385         1736 :           dst_index++;
    6386              :         }
    6387              :       else
    6388              :         removed_item = true;
    6389              :     }
    6390              : 
    6391          916 :   if (dst_index == 0)
    6392              :     {
    6393          532 :       ggc_free (ts->m_agg_values);
    6394          532 :       ts->m_agg_values = NULL;
    6395              :     }
    6396          384 :   else if (removed_item)
    6397           41 :     ts->m_agg_values->truncate (dst_index);
    6398              : 
    6399          916 :   return;
    6400          916 : }
    6401              : 
    6402              : /* Dominator walker driving the ipcp modification phase.  */
    6403              : 
    6404              : class ipcp_modif_dom_walker : public dom_walker
    6405              : {
    6406              : public:
    6407         1339 :   ipcp_modif_dom_walker (struct ipa_func_body_info *fbi,
    6408              :                          vec<ipa_param_descriptor, va_gc> *descs,
    6409              :                          ipcp_transformation *ts, bool *sc)
    6410         1339 :     : dom_walker (CDI_DOMINATORS), m_fbi (fbi), m_descriptors (descs),
    6411         1339 :       m_ts (ts), m_something_changed (sc) {}
    6412              : 
    6413              :   edge before_dom_children (basic_block) final override;
    6414         1339 :   bool cleanup_eh ()
    6415         1339 :     { return gimple_purge_all_dead_eh_edges (m_need_eh_cleanup); }
    6416              : 
    6417              : private:
    6418              :   struct ipa_func_body_info *m_fbi;
    6419              :   vec<ipa_param_descriptor, va_gc> *m_descriptors;
    6420              :   ipcp_transformation *m_ts;
    6421              :   bool *m_something_changed;
    6422              :   auto_bitmap m_need_eh_cleanup;
    6423              : };
    6424              : 
    6425              : edge
    6426        23112 : ipcp_modif_dom_walker::before_dom_children (basic_block bb)
    6427              : {
    6428        23112 :   gimple_stmt_iterator gsi;
    6429       128188 :   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    6430              :     {
    6431        81964 :       gimple *stmt = gsi_stmt (gsi);
    6432        81964 :       tree rhs, val, t;
    6433        81964 :       HOST_WIDE_INT bit_offset;
    6434        81964 :       poly_int64 size;
    6435        81964 :       int index;
    6436        81964 :       bool by_ref, vce;
    6437              : 
    6438        81964 :       if (!gimple_assign_load_p (stmt))
    6439        80392 :         continue;
    6440        12322 :       rhs = gimple_assign_rhs1 (stmt);
    6441        12322 :       if (!is_gimple_reg_type (TREE_TYPE (rhs)))
    6442          647 :         continue;
    6443              : 
    6444        27916 :       vce = false;
    6445              :       t = rhs;
    6446        27916 :       while (handled_component_p (t))
    6447              :         {
    6448              :           /* V_C_E can do things like convert an array of integers to one
    6449              :              bigger integer and similar things we do not handle below.  */
    6450        16241 :           if (TREE_CODE (t) == VIEW_CONVERT_EXPR)
    6451              :             {
    6452              :               vce = true;
    6453              :               break;
    6454              :             }
    6455        16241 :           t = TREE_OPERAND (t, 0);
    6456              :         }
    6457        11675 :       if (vce)
    6458            0 :         continue;
    6459              : 
    6460        11675 :       if (!ipa_load_from_parm_agg (m_fbi, m_descriptors, stmt, rhs, &index,
    6461              :                                    &bit_offset, &size, &by_ref)
    6462        11675 :           || (bit_offset % BITS_PER_UNIT) != 0)
    6463         8627 :         continue;
    6464         3048 :       unsigned unit_offset = bit_offset / BITS_PER_UNIT;
    6465         3048 :       ipa_argagg_value_list avl (m_ts);
    6466         3048 :       tree v = avl.get_value (index, unit_offset, by_ref);
    6467              : 
    6468         4524 :       if (!v
    6469         3048 :           || maybe_ne (tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (v))), size))
    6470         1476 :         continue;
    6471              : 
    6472         1572 :       gcc_checking_assert (is_gimple_ip_invariant (v));
    6473         1572 :       if (!useless_type_conversion_p (TREE_TYPE (rhs), TREE_TYPE (v)))
    6474              :         {
    6475            0 :           if (fold_convertible_p (TREE_TYPE (rhs), v))
    6476            0 :             val = fold_build1 (NOP_EXPR, TREE_TYPE (rhs), v);
    6477            0 :           else if (TYPE_SIZE (TREE_TYPE (rhs))
    6478            0 :                    == TYPE_SIZE (TREE_TYPE (v)))
    6479            0 :             val = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (rhs), v);
    6480              :           else
    6481              :             {
    6482            0 :               if (dump_file)
    6483              :                 {
    6484            0 :                   fprintf (dump_file, "    const ");
    6485            0 :                   print_generic_expr (dump_file, v);
    6486            0 :                   fprintf (dump_file, "  can't be converted to type of ");
    6487            0 :                   print_generic_expr (dump_file, rhs);
    6488            0 :                   fprintf (dump_file, "\n");
    6489              :                 }
    6490            0 :               continue;
    6491              :             }
    6492              :         }
    6493              :       else
    6494              :         val = v;
    6495              : 
    6496         1572 :       if (dump_file && (dump_flags & TDF_DETAILS))
    6497              :         {
    6498           41 :           fprintf (dump_file, "Modifying stmt:\n  ");
    6499           41 :           print_gimple_stmt (dump_file, stmt, 0);
    6500              :         }
    6501         1572 :       gimple_assign_set_rhs_from_tree (&gsi, val);
    6502         1572 :       update_stmt (stmt);
    6503              : 
    6504         1572 :       if (dump_file && (dump_flags & TDF_DETAILS))
    6505              :         {
    6506           41 :           fprintf (dump_file, "into:\n  ");
    6507           41 :           print_gimple_stmt (dump_file, stmt, 0);
    6508           41 :           fprintf (dump_file, "\n");
    6509              :         }
    6510              : 
    6511         1572 :       *m_something_changed = true;
    6512         1572 :       if (maybe_clean_eh_stmt (stmt))
    6513            0 :         bitmap_set_bit (m_need_eh_cleanup, bb->index);
    6514              :     }
    6515        23112 :   return NULL;
    6516              : }
    6517              : 
    6518              : /* If IPA-CP discovered a constant in parameter PARM at OFFSET of a given SIZE
    6519              :    - whether passed by reference or not is given by BY_REF - return that
    6520              :    constant.  Otherwise return NULL_TREE.  The is supposed to be used only
    6521              :    after clone materialization and transformation is done (because it asserts
    6522              :    that killed constants have been pruned). */
    6523              : 
    6524              : tree
    6525      4425302 : ipcp_get_aggregate_const (struct function *func, tree parm, bool by_ref,
    6526              :                           HOST_WIDE_INT bit_offset, HOST_WIDE_INT bit_size)
    6527              : {
    6528      4425302 :   cgraph_node *node = cgraph_node::get (func->decl);
    6529      4425302 :   ipcp_transformation *ts = ipcp_get_transformation_summary (node);
    6530              : 
    6531      4425302 :   if (!ts
    6532        88375 :       || !ts->m_agg_values
    6533        10090 :       || bit_offset < 0
    6534        10090 :       || (bit_offset % BITS_PER_UNIT) != 0
    6535        10087 :       || (HOST_WIDE_INT) (bit_offset / BITS_PER_UNIT) > UINT_MAX)
    6536              :     return NULL_TREE;
    6537              : 
    6538        10087 :   int index = ts->get_param_index (func->decl, parm);
    6539        10087 :   if (index < 0)
    6540              :     return NULL_TREE;
    6541              : 
    6542        10034 :   ipa_argagg_value_list avl (ts);
    6543        10034 :   unsigned unit_offset = bit_offset / BITS_PER_UNIT;
    6544        10034 :   const ipa_argagg_value *av = avl.get_elt (index, unit_offset);
    6545        10034 :   if (!av || av->by_ref != by_ref)
    6546              :     return NULL_TREE;
    6547         1894 :   gcc_assert (!av->killed);
    6548         1894 :   tree v = av->value;
    6549         1894 :   if (!v
    6550         1894 :       || maybe_ne (tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (v))), bit_size))
    6551              :     return NULL_TREE;
    6552              : 
    6553              :   return v;
    6554              : }
    6555              : 
    6556              : /* Return true if we have recorded VALUE and MASK about PARM.
    6557              :    Set VALUE and MASk accordingly.  */
    6558              : 
    6559              : bool
    6560      7804749 : ipcp_get_parm_bits (tree parm, tree *value, widest_int *mask)
    6561              : {
    6562      7804749 :   cgraph_node *cnode = cgraph_node::get (current_function_decl);
    6563      7804749 :   ipcp_transformation *ts = ipcp_get_transformation_summary (cnode);
    6564      7804749 :   if (!ts
    6565       121897 :       || vec_safe_length (ts->m_vr) == 0
    6566      7924189 :       || !ipa_vr_supported_type_p (TREE_TYPE (parm)))
    6567              :     return false;
    6568              : 
    6569       117161 :   int i = ts->get_param_index (current_function_decl, parm);
    6570       117161 :   if (i < 0)
    6571              :     return false;
    6572       115721 :   clone_info *cinfo = clone_info::get (cnode);
    6573       115721 :   if (cinfo && cinfo->param_adjustments)
    6574              :     {
    6575        34422 :       i = cinfo->param_adjustments->get_original_index (i);
    6576        34422 :       if (i < 0)
    6577              :         return false;
    6578              :     }
    6579              : 
    6580       106550 :   vec<ipa_vr, va_gc> &vr = *ts->m_vr;
    6581       106550 :   if (!vr[i].known_p ())
    6582              :     return false;
    6583        84751 :   value_range tmp;
    6584        84751 :   vr[i].get_vrange (tmp);
    6585        84751 :   if (tmp.undefined_p () || tmp.varying_p ())
    6586              :     return false;
    6587        84751 :   irange_bitmask bm;
    6588        84751 :   bm = tmp.get_bitmask ();
    6589        84751 :   *mask = widest_int::from (bm.mask (), TYPE_SIGN (TREE_TYPE (parm)));
    6590        84751 :   *value = wide_int_to_tree (TREE_TYPE (parm), bm.value ());
    6591        84751 :   return true;
    6592        84751 : }
    6593              : 
    6594              : /* Update value range of formal parameters of NODE as described in TS.  */
    6595              : 
    6596              : static void
    6597        23119 : ipcp_update_vr (struct cgraph_node *node, ipcp_transformation *ts)
    6598              : {
    6599        23119 :   if (vec_safe_is_empty (ts->m_vr))
    6600          495 :     return;
    6601        22624 :   const vec<ipa_vr, va_gc> &vr = *ts->m_vr;
    6602        22624 :   unsigned count = vr.length ();
    6603        22624 :   if (!count)
    6604              :     return;
    6605              : 
    6606        22624 :   auto_vec<int, 16> new_indices;
    6607        22624 :   bool need_remapping = false;
    6608        22624 :   clone_info *cinfo = clone_info::get (node);
    6609        22624 :   if (cinfo && cinfo->param_adjustments)
    6610              :     {
    6611         7900 :       cinfo->param_adjustments->get_updated_indices (&new_indices);
    6612         7900 :       need_remapping = true;
    6613              :     }
    6614        22624 :   auto_vec <tree, 16> parm_decls;
    6615        22624 :   push_function_arg_decls (&parm_decls, node->decl);
    6616              : 
    6617       101944 :   for (unsigned i = 0; i < count; ++i)
    6618              :     {
    6619        56696 :       tree parm;
    6620        56696 :       int remapped_idx;
    6621        56696 :       if (need_remapping)
    6622              :         {
    6623        23622 :           if (i >= new_indices.length ())
    6624        11398 :             continue;
    6625        12224 :           remapped_idx = new_indices[i];
    6626        12224 :           if (remapped_idx < 0)
    6627         2540 :             continue;
    6628              :         }
    6629              :       else
    6630        33074 :         remapped_idx = i;
    6631              : 
    6632        42758 :       parm = parm_decls[remapped_idx];
    6633              : 
    6634        42758 :       gcc_checking_assert (parm);
    6635        42758 :       tree ddef = ssa_default_def (DECL_STRUCT_FUNCTION (node->decl), parm);
    6636              : 
    6637        42758 :       if (!ddef || !is_gimple_reg (parm))
    6638         6260 :         continue;
    6639              : 
    6640        36498 :       if (vr[i].known_p ())
    6641              :         {
    6642        28257 :           value_range tmp;
    6643        28257 :           vr[i].get_vrange (tmp);
    6644              : 
    6645        28257 :           if (!tmp.undefined_p () && !tmp.varying_p ())
    6646              :             {
    6647        28257 :               if (dump_file)
    6648              :                 {
    6649          113 :                   fprintf (dump_file, "Setting value range of param %u "
    6650              :                            "(now %i) ", i, remapped_idx);
    6651          113 :                   tmp.dump (dump_file);
    6652          113 :                   fprintf (dump_file, "]\n");
    6653              :                 }
    6654        28257 :               set_range_info (ddef, tmp);
    6655              : 
    6656        28257 :               if (dump_file && (INTEGRAL_TYPE_P (TREE_TYPE (parm))
    6657           90 :                                 || POINTER_TYPE_P (TREE_TYPE (parm))))
    6658              :                 {
    6659          113 :                   irange_bitmask bm = tmp.get_bitmask ();
    6660          113 :                   if (!bm.unknown_p ())
    6661              :                     {
    6662          102 :                       fprintf (dump_file,
    6663              :                                "Adjusting mask for param %u to ", i);
    6664          102 :                       print_hex (bm.mask (), dump_file);
    6665          102 :                       fprintf (dump_file, "\n");
    6666              :                     }
    6667          113 :                 }
    6668              :             }
    6669        28257 :         }
    6670              :     }
    6671        22624 : }
    6672              : 
    6673              : /* IPCP transformation phase doing propagation of aggregate values.  */
    6674              : 
    6675              : unsigned int
    6676       985739 : ipcp_transform_function (struct cgraph_node *node)
    6677              : {
    6678       985739 :   struct ipa_func_body_info fbi;
    6679       985739 :   int param_count;
    6680              : 
    6681       985739 :   gcc_checking_assert (cfun);
    6682       985739 :   gcc_checking_assert (current_function_decl);
    6683              : 
    6684       985739 :   if (dump_file)
    6685          724 :     fprintf (dump_file, "Modification phase of node %s\n",
    6686              :              node->dump_name ());
    6687              : 
    6688       985739 :   ipcp_transformation *ts = ipcp_get_transformation_summary (node);
    6689       985739 :   if (!ts
    6690       985739 :       || (vec_safe_is_empty (ts->m_agg_values)
    6691        21705 :           && vec_safe_is_empty (ts->m_vr)))
    6692              :     return 0;
    6693              : 
    6694        23119 :   ts->maybe_create_parm_idx_map (cfun->decl);
    6695        23119 :   ipcp_update_vr (node, ts);
    6696        23119 :   if (vec_safe_is_empty (ts->m_agg_values))
    6697              :       return 0;
    6698         2119 :   param_count = count_formal_params (node->decl);
    6699         2119 :   if (param_count == 0)
    6700              :     return 0;
    6701              : 
    6702         1871 :   adjust_agg_replacement_values (node, ts);
    6703         1871 :   if (vec_safe_is_empty (ts->m_agg_values))
    6704              :     {
    6705          532 :       if (dump_file)
    6706           12 :         fprintf (dump_file, "  All affected aggregate parameters were either "
    6707              :                  "removed or converted into scalars, phase done.\n");
    6708              :       return 0;
    6709              :     }
    6710         1339 :   if (dump_file)
    6711              :     {
    6712           51 :       fprintf (dump_file, "     Aggregate replacements:");
    6713           51 :       ipa_argagg_value_list avs (ts);
    6714           51 :       avs.dump (dump_file);
    6715              :     }
    6716              : 
    6717         1339 :   fbi.node = node;
    6718         1339 :   fbi.info = NULL;
    6719         1339 :   fbi.bb_infos = vNULL;
    6720         1339 :   fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun), true);
    6721         1339 :   fbi.param_count = param_count;
    6722         1339 :   fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps);
    6723              : 
    6724         1339 :   vec<ipa_param_descriptor, va_gc> *descriptors = NULL;
    6725         1339 :   vec_safe_grow_cleared (descriptors, param_count, true);
    6726         1339 :   ipa_populate_param_decls (node, *descriptors);
    6727         1339 :   bool modified_mem_access = false;
    6728         1339 :   calculate_dominance_info (CDI_DOMINATORS);
    6729         1339 :   ipcp_modif_dom_walker walker (&fbi, descriptors, ts, &modified_mem_access);
    6730         1339 :   walker.walk (ENTRY_BLOCK_PTR_FOR_FN (cfun));
    6731         1339 :   free_dominance_info (CDI_DOMINATORS);
    6732         1339 :   bool cfg_changed = walker.cleanup_eh ();
    6733              : 
    6734         1339 :   int i;
    6735         1339 :   struct ipa_bb_info *bi;
    6736        27129 :   FOR_EACH_VEC_ELT (fbi.bb_infos, i, bi)
    6737        48902 :     free_ipa_bb_info (bi);
    6738         1339 :   fbi.bb_infos.release ();
    6739              : 
    6740         1339 :   ts->remove_argaggs_if ([](const ipa_argagg_value &v)
    6741              :     {
    6742         5161 :       return v.killed;
    6743              :     });
    6744              : 
    6745         1339 :   vec_free (descriptors);
    6746         1339 :   if (cfg_changed)
    6747            0 :     delete_unreachable_blocks_update_callgraph (node, false);
    6748              : 
    6749         1339 :   return modified_mem_access ? TODO_update_ssa_only_virtuals : 0;
    6750         1339 : }
    6751              : 
    6752              : /* Record that current function return value range is VAL.  */
    6753              : 
    6754              : void
    6755       749891 : ipa_record_return_value_range (value_range val)
    6756              : {
    6757       749891 :   ipa_record_return_value_range_1
    6758       749891 :           (cgraph_node::get (current_function_decl), val);
    6759       749891 : }
    6760              : 
    6761              : /* Return true if value range of DECL is known and if so initialize RANGE.  */
    6762              : 
    6763              : bool
    6764     12282990 : ipa_return_value_range (value_range &range, tree decl)
    6765              : {
    6766     12282990 :   cgraph_node *n = cgraph_node::get (decl);
    6767     12282990 :   if (!n || !ipa_return_value_sum)
    6768              :     return false;
    6769     10142814 :   enum availability avail;
    6770     10142814 :   n = n->ultimate_alias_target (&avail);
    6771     10142814 :   if (avail < AVAIL_AVAILABLE)
    6772              :     return false;
    6773      2202380 :   if (n->decl != decl && !useless_type_conversion_p (TREE_TYPE (decl), TREE_TYPE (n->decl)))
    6774              :     return false;
    6775      2202380 :   ipa_return_value_summary *v = ipa_return_value_sum->get (n);
    6776      2202380 :   if (!v)
    6777              :     return false;
    6778       599450 :   v->vr->get_vrange (range);
    6779       599450 :   return true;
    6780              : }
    6781              : 
    6782              : /* Reset all state within ipa-prop.cc so that we can rerun the compiler
    6783              :    within the same process.  For use by toplev::finalize.  */
    6784              : 
    6785              : void
    6786       266934 : ipa_prop_cc_finalize (void)
    6787              : {
    6788       266934 :   if (function_insertion_hook_holder)
    6789        12337 :     symtab->remove_cgraph_insertion_hook (function_insertion_hook_holder);
    6790       266934 :   function_insertion_hook_holder = NULL;
    6791              : 
    6792       266934 :   if (ipa_edge_args_sum)
    6793        12666 :     ggc_delete (ipa_edge_args_sum);
    6794       266934 :   ipa_edge_args_sum = NULL;
    6795              : 
    6796       266934 :   if (ipa_node_params_sum)
    6797        12666 :     ggc_delete (ipa_node_params_sum);
    6798       266934 :   ipa_node_params_sum = NULL;
    6799       266934 : }
    6800              : 
    6801              : /* Return true if the two pass_through components of two jump functions are
    6802              :    known to be equivalent.  AGG_JF denotes whether they are part of aggregate
    6803              :    functions or not.  The function can be used before the IPA phase of IPA-CP
    6804              :    or inlining because it cannot cope with refdesc changes these passes can
    6805              :    carry out.  */
    6806              : 
    6807              : static bool
    6808        26452 : ipa_agg_pass_through_jf_equivalent_p (ipa_pass_through_data *ipt1,
    6809              :                                       ipa_pass_through_data *ipt2,
    6810              :                                       bool agg_jf)
    6811              : 
    6812              : {
    6813        26452 :   gcc_assert (agg_jf ||
    6814              :               (!ipt1->refdesc_decremented && !ipt2->refdesc_decremented));
    6815        26452 :   if (ipt1->operation != ipt2->operation
    6816        26452 :       || ipt1->formal_id != ipt2->formal_id
    6817        26452 :       || (!agg_jf && (ipt1->agg_preserved != ipt2->agg_preserved)))
    6818              :     return false;
    6819        26452 :   if (ipt1->operation != NOP_EXPR
    6820        26452 :       && (TYPE_MAIN_VARIANT (ipt1->op_type)
    6821         4373 :           != TYPE_MAIN_VARIANT (ipt2->op_type)))
    6822              :     return false;
    6823        26444 :   if (((ipt1->operand != NULL_TREE) != (ipt2->operand != NULL_TREE))
    6824        26444 :       || (ipt1->operand
    6825         4365 :           && !values_equal_for_ipcp_p (ipt1->operand, ipt2->operand)))
    6826            0 :     return false;
    6827              :   return true;
    6828              : }
    6829              : 
    6830              : /* Return true if the two aggregate jump functions are known to be equivalent.
    6831              :    The function can be used before the IPA phase of IPA-CP or inlining because
    6832              :    it cannot cope with refdesc changes these passes can carry out.  */
    6833              : 
    6834              : static bool
    6835         2864 : ipa_agg_jump_functions_equivalent_p (ipa_agg_jf_item *ajf1,
    6836              :                                      ipa_agg_jf_item *ajf2)
    6837              : {
    6838         2864 :   if (ajf1->offset != ajf2->offset
    6839         2864 :       || ajf1->jftype != ajf2->jftype
    6840         5728 :       || !types_compatible_p (ajf1->type, ajf2->type))
    6841              :     return false;
    6842              : 
    6843         2864 :   switch (ajf1->jftype)
    6844              :     {
    6845         1696 :     case IPA_JF_CONST:
    6846         1696 :       if (!values_equal_for_ipcp_p (ajf1->value.constant,
    6847              :                                     ajf2->value.constant))
    6848              :         return false;
    6849              :       break;
    6850          319 :     case IPA_JF_PASS_THROUGH:
    6851          319 :       {
    6852          319 :         ipa_pass_through_data *ipt1 = &ajf1->value.pass_through;
    6853          319 :         ipa_pass_through_data *ipt2 = &ajf2->value.pass_through;
    6854          319 :         if (!ipa_agg_pass_through_jf_equivalent_p (ipt1, ipt2, true))
    6855              :           return false;
    6856              :       }
    6857              :       break;
    6858          849 :     case IPA_JF_LOAD_AGG:
    6859          849 :       {
    6860          849 :         ipa_load_agg_data *ila1 = &ajf1->value.load_agg;
    6861          849 :         ipa_load_agg_data *ila2 = &ajf2->value.load_agg;
    6862          849 :         if (!ipa_agg_pass_through_jf_equivalent_p (&ila1->pass_through,
    6863              :                                                    &ila2->pass_through, true))
    6864              :           return false;
    6865          849 :         if (ila1->offset != ila2->offset
    6866          849 :             || ila1->by_ref != ila2->by_ref
    6867         1698 :             || !types_compatible_p (ila1->type, ila2->type))
    6868            0 :           return false;
    6869              :       }
    6870              :       break;
    6871            0 :     default:
    6872            0 :         gcc_unreachable ();
    6873              :     }
    6874              :   return true;
    6875              : }
    6876              : 
    6877              : /* Return true if the two jump functions are known to be equivalent.  The
    6878              :    function can be used before the IPA phase of IPA-CP or inlining because it
    6879              :    cannot cope with refdesc changes these passes can carry out.  */
    6880              : 
    6881              : bool
    6882        79196 : ipa_jump_functions_equivalent_p (ipa_jump_func *jf1, ipa_jump_func *jf2)
    6883              : {
    6884        79196 :   if (jf1->type != jf2->type)
    6885              :     return false;
    6886              : 
    6887        79196 :   switch (jf1->type)
    6888              :     {
    6889              :     case IPA_JF_UNKNOWN:
    6890              :       break;
    6891        19516 :     case IPA_JF_CONST:
    6892        19516 :       {
    6893        19516 :         tree cst1 = ipa_get_jf_constant (jf1);
    6894        19516 :         tree cst2 = ipa_get_jf_constant (jf2);
    6895        19516 :         if (!values_equal_for_ipcp_p (cst1, cst2))
    6896              :           return false;
    6897              : 
    6898        19515 :         ipa_cst_ref_desc *rd1 = jfunc_rdesc_usable (jf1);
    6899        19515 :         ipa_cst_ref_desc *rd2 = jfunc_rdesc_usable (jf2);
    6900        19515 :         if (rd1 && rd2)
    6901              :           {
    6902          248 :             gcc_assert (rd1->refcount == 1
    6903              :                         && rd2->refcount == 1);
    6904          248 :             gcc_assert (!rd1->next_duplicate && !rd2->next_duplicate);
    6905              :           }
    6906        19267 :         else if (rd1)
    6907              :           return false;
    6908        19267 :         else if (rd2)
    6909              :           return false;
    6910              :       }
    6911              :       break;
    6912        25284 :     case IPA_JF_PASS_THROUGH:
    6913        25284 :       {
    6914        25284 :         ipa_pass_through_data *ipt1 = &jf1->value.pass_through;
    6915        25284 :         ipa_pass_through_data *ipt2 = &jf2->value.pass_through;
    6916        25284 :         if (!ipa_agg_pass_through_jf_equivalent_p (ipt1, ipt2, false))
    6917              :           return false;
    6918              :       }
    6919              :       break;
    6920        10681 :     case IPA_JF_ANCESTOR:
    6921        10681 :       {
    6922        10681 :         ipa_ancestor_jf_data *ia1 = &jf1->value.ancestor;
    6923        10681 :         ipa_ancestor_jf_data *ia2 = &jf2->value.ancestor;
    6924              : 
    6925        10681 :         if (ia1->formal_id != ia2->formal_id
    6926        10681 :             || ia1->agg_preserved != ia2->agg_preserved
    6927        10681 :             || ia1->keep_null != ia2->keep_null
    6928        10681 :             || ia1->offset != ia2->offset)
    6929              :           return false;
    6930              :       }
    6931              :       break;
    6932            0 :     default:
    6933            0 :       gcc_unreachable ();
    6934              :     }
    6935              : 
    6936        79187 :   if (((jf1->m_vr != nullptr) != (jf2->m_vr != nullptr))
    6937        79187 :       || (jf1->m_vr && !jf1->m_vr->equal_p (*jf2->m_vr)))
    6938              :     return false;
    6939              : 
    6940        77422 :   unsigned alen = vec_safe_length (jf1->agg.items);
    6941        79334 :   if (vec_safe_length (jf2->agg.items) != alen)
    6942              :     return false;
    6943              : 
    6944        77421 :   if (!alen)
    6945              :     return true;
    6946              : 
    6947         1912 :   if (jf1->agg.by_ref != jf2->agg.by_ref)
    6948              :     return false;
    6949              : 
    6950         4776 :   for (unsigned i = 0 ; i < alen; i++)
    6951         2864 :     if (!ipa_agg_jump_functions_equivalent_p (&(*jf1->agg.items)[i],
    6952         2864 :                                               &(*jf2->agg.items)[i]))
    6953              :       return false;
    6954              : 
    6955              :   return true;
    6956              : }
    6957              : 
    6958              : #include "gt-ipa-prop.h"
        

Generated by: LCOV version 2.5.0-beta

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