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