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

Generated by: LCOV version 2.4-beta

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