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