Branch data Line data Source code
1 : : /* Callgraph handling code.
2 : : Copyright (C) 2003-2025 Free Software Foundation, Inc.
3 : : Contributed by Jan Hubicka
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify it under
8 : : the terms of the GNU General Public License as published by the Free
9 : : Software Foundation; either version 3, or (at your option) any later
10 : : version.
11 : :
12 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : : for more details.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : : /* This file contains basic routines manipulating call graph
22 : :
23 : : The call-graph is a data structure designed for inter-procedural
24 : : optimization. It represents a multi-graph where nodes are functions
25 : : (symbols within symbol table) and edges are call sites. */
26 : :
27 : : #include "config.h"
28 : : #include "system.h"
29 : : #include "coretypes.h"
30 : : #include "backend.h"
31 : : #include "target.h"
32 : : #include "rtl.h"
33 : : #include "tree.h"
34 : : #include "gimple.h"
35 : : #include "predict.h"
36 : : #include "alloc-pool.h"
37 : : #include "gimple-ssa.h"
38 : : #include "cgraph.h"
39 : : #include "lto-streamer.h"
40 : : #include "fold-const.h"
41 : : #include "varasm.h"
42 : : #include "calls.h"
43 : : #include "print-tree.h"
44 : : #include "langhooks.h"
45 : : #include "intl.h"
46 : : #include "tree-eh.h"
47 : : #include "gimple-iterator.h"
48 : : #include "tree-cfg.h"
49 : : #include "tree-ssa.h"
50 : : #include "value-prof.h"
51 : : #include "ipa-utils.h"
52 : : #include "symbol-summary.h"
53 : : #include "tree-vrp.h"
54 : : #include "sreal.h"
55 : : #include "ipa-cp.h"
56 : : #include "ipa-prop.h"
57 : : #include "ipa-fnsummary.h"
58 : : #include "cfgloop.h"
59 : : #include "gimple-pretty-print.h"
60 : : #include "tree-dfa.h"
61 : : #include "profile.h"
62 : : #include "context.h"
63 : : #include "gimplify.h"
64 : : #include "stringpool.h"
65 : : #include "attribs.h"
66 : : #include "selftest.h"
67 : : #include "tree-into-ssa.h"
68 : : #include "ipa-inline.h"
69 : : #include "tree-nested.h"
70 : : #include "symtab-thunks.h"
71 : : #include "symtab-clones.h"
72 : :
73 : : /* FIXME: Only for PROP_loops, but cgraph shouldn't have to know about this. */
74 : : #include "tree-pass.h"
75 : :
76 : : /* Queue of cgraph nodes scheduled to be lowered. */
77 : : symtab_node *x_cgraph_nodes_queue;
78 : : #define cgraph_nodes_queue ((cgraph_node *)x_cgraph_nodes_queue)
79 : :
80 : : /* Symbol table global context. */
81 : : symbol_table *symtab;
82 : :
83 : : /* List of hooks triggered on cgraph_edge events. */
84 : : struct cgraph_edge_hook_list {
85 : : cgraph_edge_hook hook;
86 : : void *data;
87 : : struct cgraph_edge_hook_list *next;
88 : : };
89 : :
90 : : /* List of hooks triggered on cgraph_node events. */
91 : : struct cgraph_node_hook_list {
92 : : cgraph_node_hook hook;
93 : : void *data;
94 : : struct cgraph_node_hook_list *next;
95 : : };
96 : :
97 : : /* List of hooks triggered on events involving two cgraph_edges. */
98 : : struct cgraph_2edge_hook_list {
99 : : cgraph_2edge_hook hook;
100 : : void *data;
101 : : struct cgraph_2edge_hook_list *next;
102 : : };
103 : :
104 : : /* List of hooks triggered on events involving two cgraph_nodes. */
105 : : struct cgraph_2node_hook_list {
106 : : cgraph_2node_hook hook;
107 : : void *data;
108 : : struct cgraph_2node_hook_list *next;
109 : : };
110 : :
111 : : /* Hash descriptor for cgraph_function_version_info. */
112 : :
113 : : struct function_version_hasher : ggc_ptr_hash<cgraph_function_version_info>
114 : : {
115 : : static hashval_t hash (cgraph_function_version_info *);
116 : : static bool equal (cgraph_function_version_info *,
117 : : cgraph_function_version_info *);
118 : : };
119 : :
120 : : /* Map a cgraph_node to cgraph_function_version_info using this htab.
121 : : The cgraph_function_version_info has a THIS_NODE field that is the
122 : : corresponding cgraph_node.. */
123 : :
124 : : static GTY(()) hash_table<function_version_hasher> *cgraph_fnver_htab = NULL;
125 : :
126 : : /* Hash function for cgraph_fnver_htab. */
127 : : hashval_t
128 : 227546 : function_version_hasher::hash (cgraph_function_version_info *ptr)
129 : : {
130 : 227546 : int uid = ptr->this_node->get_uid ();
131 : 227546 : return (hashval_t)(uid);
132 : : }
133 : :
134 : : /* eq function for cgraph_fnver_htab. */
135 : : bool
136 : 207000 : function_version_hasher::equal (cgraph_function_version_info *n1,
137 : : cgraph_function_version_info *n2)
138 : : {
139 : 207000 : return n1->this_node->get_uid () == n2->this_node->get_uid ();
140 : : }
141 : :
142 : : /* Mark as GC root all allocated nodes. */
143 : : static GTY(()) struct cgraph_function_version_info *
144 : : version_info_node = NULL;
145 : :
146 : : /* Return true if NODE's address can be compared. */
147 : :
148 : : bool
149 : 5013010 : symtab_node::address_can_be_compared_p ()
150 : : {
151 : : /* Address of virtual tables and functions is never compared. */
152 : 5013010 : if (DECL_VIRTUAL_P (decl))
153 : : return false;
154 : : /* Address of C++ cdtors is never compared. */
155 : 4921096 : if (is_a <cgraph_node *> (this)
156 : 538210 : && (DECL_CXX_CONSTRUCTOR_P (decl)
157 : 533930 : || DECL_CXX_DESTRUCTOR_P (decl)))
158 : : return false;
159 : : /* Constant pool symbols addresses are never compared.
160 : : flag_merge_constants permits us to assume the same on readonly vars. */
161 : 4915370 : if (is_a <varpool_node *> (this)
162 : 4382886 : && (DECL_IN_CONSTANT_POOL (decl)
163 : 4382883 : || ((flag_merge_constants >= 2 || DECL_MERGEABLE (decl))
164 : 2248 : && TREE_READONLY (decl) && !TREE_THIS_VOLATILE (decl))))
165 : 2244 : return false;
166 : : return true;
167 : : }
168 : :
169 : : /* Get the cgraph_function_version_info node corresponding to node. */
170 : : cgraph_function_version_info *
171 : 98636558 : cgraph_node::function_version (void)
172 : : {
173 : 98636558 : cgraph_function_version_info key;
174 : 98636558 : key.this_node = this;
175 : :
176 : 98636558 : if (cgraph_fnver_htab == NULL)
177 : : return NULL;
178 : :
179 : 37647 : return cgraph_fnver_htab->find (&key);
180 : : }
181 : :
182 : : /* If profile is IPA, turn it into local one. */
183 : : void
184 : 0 : cgraph_node::make_profile_local ()
185 : : {
186 : 0 : if (!count.ipa ().initialized_p ())
187 : : return;
188 : 0 : if (!(count == profile_count::zero ()))
189 : 0 : count = count.guessed_local ();
190 : 0 : for (cgraph_edge *e = callees; e; e = e->next_callee)
191 : : {
192 : 0 : if (!e->inline_failed)
193 : 0 : e->callee->make_profile_local ();
194 : 0 : if (!(e->count == profile_count::zero ()))
195 : 0 : e->count = e->count.guessed_local ();
196 : : }
197 : 0 : for (cgraph_edge *e = indirect_calls; e; e = e->next_callee)
198 : 0 : if (!(e->count == profile_count::zero ()))
199 : 0 : e->count = e->count.guessed_local ();
200 : : }
201 : :
202 : : /* Turn profile to global0. Walk into inlined functions.
203 : : QUALITY must be GUESSED_GLOBAL0, GUESSED_GLOBAL0_ADJUSTED
204 : : or GUESSED_GLOBAL0_AFDO */
205 : : void
206 : 5 : cgraph_node::make_profile_global0 (profile_quality quality)
207 : : {
208 : 5 : if (count == profile_count::zero ())
209 : : ;
210 : 5 : else if (quality == GUESSED_GLOBAL0)
211 : : {
212 : 5 : if (count.quality () == GUESSED_GLOBAL0)
213 : : return;
214 : 5 : count = count.global0 ();
215 : : }
216 : 0 : else if (quality == GUESSED_GLOBAL0_ADJUSTED)
217 : : {
218 : 0 : if (count.quality () == GUESSED_GLOBAL0
219 : 0 : || count.quality () == GUESSED_GLOBAL0_ADJUSTED)
220 : : return;
221 : 0 : count = count.global0adjusted ();
222 : : }
223 : 0 : else if (quality == GUESSED_GLOBAL0_AFDO)
224 : : {
225 : 0 : if (count.quality () == GUESSED_GLOBAL0
226 : 0 : || count.quality () == GUESSED_GLOBAL0_ADJUSTED
227 : 0 : || count.quality () == GUESSED_GLOBAL0_AFDO)
228 : : return;
229 : 0 : count = count.global0afdo ();
230 : : }
231 : : else
232 : 0 : gcc_unreachable ();
233 : 6 : for (cgraph_edge *e = callees; e; e = e->next_callee)
234 : : {
235 : 1 : if (!e->inline_failed)
236 : 0 : e->callee->make_profile_global0 (quality);
237 : 1 : if (e->count == profile_count::zero ())
238 : : ;
239 : 1 : else if (quality == GUESSED_GLOBAL0)
240 : 1 : e->count = e->count.global0 ();
241 : 0 : else if (quality == GUESSED_GLOBAL0_ADJUSTED)
242 : 0 : e->count = e->count.global0adjusted ();
243 : 0 : else if (quality == GUESSED_GLOBAL0_AFDO)
244 : 0 : e->count = e->count.global0afdo ();
245 : : else
246 : 0 : gcc_unreachable ();
247 : : }
248 : 5 : for (cgraph_edge *e = indirect_calls; e; e = e->next_callee)
249 : 0 : if (e->count == profile_count::zero ())
250 : : ;
251 : 0 : else if (quality == GUESSED_GLOBAL0)
252 : 0 : e->count = e->count.global0 ();
253 : 0 : else if (quality == GUESSED_GLOBAL0_ADJUSTED)
254 : 0 : e->count = e->count.global0adjusted ();
255 : 0 : else if (quality == GUESSED_GLOBAL0_AFDO)
256 : 0 : e->count = e->count.global0afdo ();
257 : : else
258 : 0 : gcc_unreachable ();
259 : : }
260 : :
261 : : /* Scale profile by NUM/DEN. Walk into inlined functions. */
262 : :
263 : : void
264 : 1652683 : cgraph_node::apply_scale (profile_count num, profile_count den)
265 : : {
266 : 1768475 : if (num == den && !(num == profile_count::zero ()))
267 : 113781 : return;
268 : :
269 : 2750949 : for (cgraph_edge *e = callees; e; e = e->next_callee)
270 : : {
271 : 1212047 : if (!e->inline_failed)
272 : 152339 : e->callee->apply_scale (num, den);
273 : 1212047 : e->count = e->count.apply_scale (num, den);
274 : : }
275 : 1568892 : for (cgraph_edge *e = indirect_calls; e; e = e->next_callee)
276 : 29990 : e->count = e->count.apply_scale (num, den);
277 : 1538902 : count = count.apply_scale (num, den);
278 : : }
279 : :
280 : : /* Scale profile to given IPA_COUNT.
281 : : IPA_COUNT should pass ipa_p () with a single exception.
282 : : It can be also GUESSED_LOCAL in case we want to
283 : : drop any IPA info about the profile. */
284 : :
285 : : void
286 : 30 : cgraph_node::scale_profile_to (profile_count ipa_count)
287 : : {
288 : : /* If we do not know the adjustment, it is better to keep profile
289 : : as it is. */
290 : 30 : if (!ipa_count.initialized_p ()
291 : 30 : || ipa_count == count)
292 : 10 : return;
293 : : /* ipa-cp converts value to guessed-local in case it believes
294 : : that we lost track of IPA profile. */
295 : 25 : if (ipa_count.quality () == GUESSED_LOCAL)
296 : : {
297 : 0 : make_profile_local ();
298 : 0 : return;
299 : : }
300 : 25 : if (ipa_count == profile_count::zero ())
301 : : {
302 : 5 : make_profile_global0 (GUESSED_GLOBAL0);
303 : 5 : return;
304 : : }
305 : 20 : if (ipa_count == profile_count::adjusted_zero ())
306 : : {
307 : 0 : make_profile_global0 (GUESSED_GLOBAL0_ADJUSTED);
308 : 0 : return;
309 : : }
310 : 40 : gcc_assert (ipa_count.ipa () == ipa_count
311 : : && !inlined_to);
312 : 20 : profile_count num = count.combine_with_ipa_count (ipa_count);
313 : 20 : profile_count den = count;
314 : 20 : profile_count::adjust_for_ipa_scaling (&num, &den);
315 : : }
316 : :
317 : : /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
318 : : corresponding to cgraph_node NODE. */
319 : : cgraph_function_version_info *
320 : 1508 : cgraph_node::insert_new_function_version (void)
321 : : {
322 : 1508 : version_info_node = NULL;
323 : 1508 : version_info_node = ggc_cleared_alloc<cgraph_function_version_info> ();
324 : 1508 : version_info_node->this_node = this;
325 : :
326 : 1508 : if (cgraph_fnver_htab == NULL)
327 : 197 : cgraph_fnver_htab = hash_table<function_version_hasher>::create_ggc (2);
328 : :
329 : 1508 : *cgraph_fnver_htab->find_slot (version_info_node, INSERT)
330 : 1508 : = version_info_node;
331 : 1508 : return version_info_node;
332 : : }
333 : :
334 : : /* Remove the cgraph_function_version_info node given by DECL_V. */
335 : : static void
336 : 94988438 : delete_function_version (cgraph_function_version_info *decl_v)
337 : : {
338 : 94988438 : if (decl_v == NULL)
339 : : return;
340 : :
341 : 265 : if (version_info_node == decl_v)
342 : 205 : version_info_node = NULL;
343 : :
344 : 265 : if (decl_v->prev != NULL)
345 : 171 : decl_v->prev->next = decl_v->next;
346 : :
347 : 265 : if (decl_v->next != NULL)
348 : 226 : decl_v->next->prev = decl_v->prev;
349 : :
350 : 265 : if (cgraph_fnver_htab != NULL)
351 : 265 : cgraph_fnver_htab->remove_elt (decl_v);
352 : : }
353 : :
354 : : /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
355 : : DECL is a duplicate declaration. */
356 : : void
357 : 258 : cgraph_node::delete_function_version_by_decl (tree decl)
358 : : {
359 : 258 : cgraph_node *decl_node = cgraph_node::get (decl);
360 : :
361 : 258 : if (decl_node == NULL)
362 : : return;
363 : :
364 : 204 : delete_function_version (decl_node->function_version ());
365 : :
366 : 204 : decl_node->remove ();
367 : : }
368 : :
369 : : /* Add decl to the structure of semantically identical function versions.
370 : : The node is inserted at the point maintaining the priority ordering on the
371 : : versions. */
372 : : void
373 : 8673 : cgraph_node::add_function_version (cgraph_function_version_info *fn_v,
374 : : tree decl)
375 : : {
376 : 8673 : cgraph_node *decl_node = cgraph_node::get_create (decl);
377 : 8673 : cgraph_function_version_info *decl_v = NULL;
378 : :
379 : 8673 : gcc_assert (decl_node != NULL);
380 : :
381 : 8673 : decl_v = decl_node->function_version ();
382 : :
383 : : /* If the nodes are already linked, skip. */
384 : 8673 : if (decl_v != NULL && (decl_v->next || decl_v->prev))
385 : : return;
386 : :
387 : 900 : if (decl_v == NULL)
388 : 900 : decl_v = decl_node->insert_new_function_version ();
389 : :
390 : 900 : gcc_assert (decl_v);
391 : 900 : gcc_assert (fn_v);
392 : :
393 : : /* Go to start of the FMV structure. */
394 : 5280 : while (fn_v->prev)
395 : : fn_v = fn_v->prev;
396 : :
397 : 900 : cgraph_function_version_info *insert_point_before = NULL;
398 : 900 : cgraph_function_version_info *insert_point_after = fn_v;
399 : :
400 : : /* Find the insertion point for the new version to maintain ordering.
401 : : The default node must always go at the beginning. */
402 : 900 : if (!is_function_default_version (decl))
403 : : while (insert_point_after
404 : 9243 : && (targetm.compare_version_priority
405 : 4488 : (decl, insert_point_after->this_node->decl) > 0
406 : 639 : || is_function_default_version
407 : 639 : (insert_point_after->this_node->decl)
408 : 534 : || lookup_attribute
409 : 534 : ("target_clones",
410 : 534 : DECL_ATTRIBUTES (insert_point_after->this_node->decl))))
411 : : {
412 : 3954 : insert_point_before = insert_point_after;
413 : 3954 : insert_point_after = insert_point_after->next;
414 : : }
415 : :
416 : 900 : decl_v->prev = insert_point_before;
417 : 900 : decl_v->next= insert_point_after;
418 : :
419 : 900 : if (insert_point_before)
420 : 765 : insert_point_before->next = decl_v;
421 : 900 : if (insert_point_after)
422 : 633 : insert_point_after->prev = decl_v;
423 : : }
424 : :
425 : : /* Initialize callgraph dump file. */
426 : :
427 : : void
428 : 299115 : symbol_table::initialize (void)
429 : : {
430 : 299115 : if (!dump_file)
431 : 299113 : dump_file = dump_begin (TDI_cgraph, NULL);
432 : :
433 : 299115 : if (!ipa_clones_dump_file)
434 : 299115 : ipa_clones_dump_file = dump_begin (TDI_clones, NULL);
435 : 299115 : }
436 : :
437 : : /* Allocate new callgraph node and insert it into basic data structures. */
438 : :
439 : : cgraph_node *
440 : 98753989 : symbol_table::create_empty (void)
441 : : {
442 : 98753989 : cgraph_count++;
443 : 98753989 : return new (ggc_alloc<cgraph_node> ()) cgraph_node ();
444 : : }
445 : :
446 : : /* Register HOOK to be called with DATA on each removed edge. */
447 : : cgraph_edge_hook_list *
448 : 1886707 : symbol_table::add_edge_removal_hook (cgraph_edge_hook hook, void *data)
449 : : {
450 : 1886707 : cgraph_edge_hook_list *entry;
451 : 3773414 : cgraph_edge_hook_list **ptr = &m_first_edge_removal_hook;
452 : :
453 : 1886707 : entry = (cgraph_edge_hook_list *) xmalloc (sizeof (*entry));
454 : 1886707 : entry->hook = hook;
455 : 1886707 : entry->data = data;
456 : 1886707 : entry->next = NULL;
457 : 6526135 : while (*ptr)
458 : 4639428 : ptr = &(*ptr)->next;
459 : 1886707 : *ptr = entry;
460 : 1886707 : return entry;
461 : : }
462 : :
463 : : /* Remove ENTRY from the list of hooks called on removing edges. */
464 : : void
465 : 1886693 : symbol_table::remove_edge_removal_hook (cgraph_edge_hook_list *entry)
466 : : {
467 : 1886693 : cgraph_edge_hook_list **ptr = &m_first_edge_removal_hook;
468 : :
469 : 5143489 : while (*ptr != entry)
470 : 3256796 : ptr = &(*ptr)->next;
471 : 1886693 : *ptr = entry->next;
472 : 1886693 : free (entry);
473 : 1886693 : }
474 : :
475 : : /* Call all edge removal hooks. */
476 : : void
477 : 45015619 : symbol_table::call_edge_removal_hooks (cgraph_edge *e)
478 : : {
479 : 45015619 : cgraph_edge_hook_list *entry = m_first_edge_removal_hook;
480 : 72906700 : while (entry)
481 : : {
482 : 27891081 : entry->hook (e, entry->data);
483 : 27891081 : entry = entry->next;
484 : : }
485 : 45015619 : }
486 : :
487 : : /* Register HOOK to be called with DATA on each removed node. */
488 : : cgraph_node_hook_list *
489 : 8127588 : symbol_table::add_cgraph_removal_hook (cgraph_node_hook hook, void *data)
490 : : {
491 : 8127588 : cgraph_node_hook_list *entry;
492 : 16255176 : cgraph_node_hook_list **ptr = &m_first_cgraph_removal_hook;
493 : :
494 : 8127588 : entry = (cgraph_node_hook_list *) xmalloc (sizeof (*entry));
495 : 8127588 : entry->hook = hook;
496 : 8127588 : entry->data = data;
497 : 8127588 : entry->next = NULL;
498 : 42696607 : while (*ptr)
499 : 34569019 : ptr = &(*ptr)->next;
500 : 8127588 : *ptr = entry;
501 : 8127588 : return entry;
502 : : }
503 : :
504 : : /* Remove ENTRY from the list of hooks called on removing nodes. */
505 : : void
506 : 8019694 : symbol_table::remove_cgraph_removal_hook (cgraph_node_hook_list *entry)
507 : : {
508 : 8019694 : cgraph_node_hook_list **ptr = &m_first_cgraph_removal_hook;
509 : :
510 : 38193305 : while (*ptr != entry)
511 : 30173611 : ptr = &(*ptr)->next;
512 : 8019694 : *ptr = entry->next;
513 : 8019694 : free (entry);
514 : 8019694 : }
515 : :
516 : : /* Call all node removal hooks. */
517 : : void
518 : 95020960 : symbol_table::call_cgraph_removal_hooks (cgraph_node *node)
519 : : {
520 : 95020960 : cgraph_node_hook_list *entry = m_first_cgraph_removal_hook;
521 : 136112444 : while (entry)
522 : : {
523 : 41091484 : entry->hook (node, entry->data);
524 : 41091484 : entry = entry->next;
525 : : }
526 : 95020960 : }
527 : :
528 : : /* Call all node removal hooks. */
529 : : void
530 : 119613 : symbol_table::call_cgraph_insertion_hooks (cgraph_node *node)
531 : : {
532 : 119613 : cgraph_node_hook_list *entry = m_first_cgraph_insertion_hook;
533 : 360562 : while (entry)
534 : : {
535 : 240949 : entry->hook (node, entry->data);
536 : 240949 : entry = entry->next;
537 : : }
538 : 119613 : }
539 : :
540 : :
541 : : /* Register HOOK to be called with DATA on each inserted node. */
542 : : cgraph_node_hook_list *
543 : 8608187 : symbol_table::add_cgraph_insertion_hook (cgraph_node_hook hook, void *data)
544 : : {
545 : 8608187 : cgraph_node_hook_list *entry;
546 : 17216374 : cgraph_node_hook_list **ptr = &m_first_cgraph_insertion_hook;
547 : :
548 : 8608187 : entry = (cgraph_node_hook_list *) xmalloc (sizeof (*entry));
549 : 8608187 : entry->hook = hook;
550 : 8608187 : entry->data = data;
551 : 8608187 : entry->next = NULL;
552 : 25510537 : while (*ptr)
553 : 16902350 : ptr = &(*ptr)->next;
554 : 8608187 : *ptr = entry;
555 : 8608187 : return entry;
556 : : }
557 : :
558 : : /* Remove ENTRY from the list of hooks called on inserted nodes. */
559 : : void
560 : 8462558 : symbol_table::remove_cgraph_insertion_hook (cgraph_node_hook_list *entry)
561 : : {
562 : 8462558 : cgraph_node_hook_list **ptr = &m_first_cgraph_insertion_hook;
563 : :
564 : 23402906 : while (*ptr != entry)
565 : 14940348 : ptr = &(*ptr)->next;
566 : 8462558 : *ptr = entry->next;
567 : 8462558 : free (entry);
568 : 8462558 : }
569 : :
570 : : /* Register HOOK to be called with DATA on each duplicated edge. */
571 : : cgraph_2edge_hook_list *
572 : 1656627 : symbol_table::add_edge_duplication_hook (cgraph_2edge_hook hook, void *data)
573 : : {
574 : 1656627 : cgraph_2edge_hook_list *entry;
575 : 3313254 : cgraph_2edge_hook_list **ptr = &m_first_edge_duplicated_hook;
576 : :
577 : 1656627 : entry = (cgraph_2edge_hook_list *) xmalloc (sizeof (*entry));
578 : 1656627 : entry->hook = hook;
579 : 1656627 : entry->data = data;
580 : 1656627 : entry->next = NULL;
581 : 5317789 : while (*ptr)
582 : 3661162 : ptr = &(*ptr)->next;
583 : 1656627 : *ptr = entry;
584 : 1656627 : return entry;
585 : : }
586 : :
587 : : /* Remove ENTRY from the list of hooks called on duplicating edges. */
588 : : void
589 : 1656613 : symbol_table::remove_edge_duplication_hook (cgraph_2edge_hook_list *entry)
590 : : {
591 : 1656613 : cgraph_2edge_hook_list **ptr = &m_first_edge_duplicated_hook;
592 : :
593 : 3935143 : while (*ptr != entry)
594 : 2278530 : ptr = &(*ptr)->next;
595 : 1656613 : *ptr = entry->next;
596 : 1656613 : free (entry);
597 : 1656613 : }
598 : :
599 : : /* Call all edge duplication hooks. */
600 : : void
601 : 7045989 : symbol_table::call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2)
602 : : {
603 : 7045989 : cgraph_2edge_hook_list *entry = m_first_edge_duplicated_hook;
604 : 20672146 : while (entry)
605 : : {
606 : 13626157 : entry->hook (cs1, cs2, entry->data);
607 : 13626157 : entry = entry->next;
608 : : }
609 : 7045989 : }
610 : :
611 : : /* Register HOOK to be called with DATA on each duplicated node. */
612 : : cgraph_2node_hook_list *
613 : 7987253 : symbol_table::add_cgraph_duplication_hook (cgraph_2node_hook hook, void *data)
614 : : {
615 : 7987253 : cgraph_2node_hook_list *entry;
616 : 15974506 : cgraph_2node_hook_list **ptr = &m_first_cgraph_duplicated_hook;
617 : :
618 : 7987253 : entry = (cgraph_2node_hook_list *) xmalloc (sizeof (*entry));
619 : 7987253 : entry->hook = hook;
620 : 7987253 : entry->data = data;
621 : 7987253 : entry->next = NULL;
622 : 39636751 : while (*ptr)
623 : 31649498 : ptr = &(*ptr)->next;
624 : 7987253 : *ptr = entry;
625 : 7987253 : return entry;
626 : : }
627 : :
628 : : /* Remove ENTRY from the list of hooks called on duplicating nodes. */
629 : : void
630 : 7892525 : symbol_table::remove_cgraph_duplication_hook (cgraph_2node_hook_list *entry)
631 : : {
632 : 7892525 : cgraph_2node_hook_list **ptr = &m_first_cgraph_duplicated_hook;
633 : :
634 : 36086722 : while (*ptr != entry)
635 : 28194197 : ptr = &(*ptr)->next;
636 : 7892525 : *ptr = entry->next;
637 : 7892525 : free (entry);
638 : 7892525 : }
639 : :
640 : : /* Call all node duplication hooks. */
641 : : void
642 : 3223930 : symbol_table::call_cgraph_duplication_hooks (cgraph_node *node,
643 : : cgraph_node *node2)
644 : : {
645 : 3223930 : cgraph_2node_hook_list *entry = m_first_cgraph_duplicated_hook;
646 : 22843294 : while (entry)
647 : : {
648 : 19619364 : entry->hook (node, node2, entry->data);
649 : 19619364 : entry = entry->next;
650 : : }
651 : 3223930 : }
652 : :
653 : : /* Return cgraph node assigned to DECL. Create new one when needed. */
654 : :
655 : : cgraph_node *
656 : 95332395 : cgraph_node::create (tree decl)
657 : : {
658 : 95332395 : cgraph_node *node = symtab->create_empty ();
659 : 95332395 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
660 : :
661 : 95332395 : node->decl = decl;
662 : 95332395 : node->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition);
663 : :
664 : 95277028 : if ((flag_openacc || flag_openmp)
665 : 95567832 : && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
666 : : {
667 : 8375 : node->offloadable = 1;
668 : 8375 : if (ENABLE_OFFLOADING)
669 : : g->have_offload = true;
670 : : }
671 : :
672 : 95332395 : if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
673 : 119 : node->ifunc_resolver = true;
674 : :
675 : 95332395 : node->register_symbol ();
676 : 95332395 : maybe_record_nested_function (node);
677 : :
678 : 95332395 : return node;
679 : : }
680 : :
681 : : /* Try to find a call graph node for declaration DECL and if it does not exist
682 : : or if it corresponds to an inline clone, create a new one. */
683 : :
684 : : cgraph_node *
685 : 524154642 : cgraph_node::get_create (tree decl)
686 : : {
687 : 524154642 : cgraph_node *first_clone = cgraph_node::get (decl);
688 : :
689 : 524154642 : if (first_clone && !first_clone->inlined_to)
690 : : return first_clone;
691 : :
692 : 95265656 : cgraph_node *node = cgraph_node::create (decl);
693 : 95265656 : if (first_clone)
694 : : {
695 : 8 : first_clone->clone_of = node;
696 : 8 : node->clones = first_clone;
697 : 8 : node->order = first_clone->order;
698 : 8 : symtab->symtab_prevail_in_asm_name_hash (node);
699 : 8 : node->decl->decl_with_vis.symtab_node = node;
700 : 8 : if (dump_file && symtab->state != PARSING)
701 : 2 : fprintf (dump_file, "Introduced new external node "
702 : : "(%s) and turned into root of the clone tree.\n",
703 : : node->dump_name ());
704 : : }
705 : 95265648 : else if (dump_file && symtab->state != PARSING)
706 : 1139 : fprintf (dump_file, "Introduced new external node "
707 : : "(%s).\n", node->dump_name ());
708 : : return node;
709 : : }
710 : :
711 : : /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
712 : : the function body is associated with
713 : : (not necessarily cgraph_node (DECL)). */
714 : :
715 : : cgraph_node *
716 : 6930259 : cgraph_node::create_alias (tree alias, tree target)
717 : : {
718 : 6930259 : cgraph_node *alias_node;
719 : :
720 : 6930259 : gcc_assert (TREE_CODE (target) == FUNCTION_DECL
721 : : || TREE_CODE (target) == IDENTIFIER_NODE);
722 : 6930259 : gcc_assert (TREE_CODE (alias) == FUNCTION_DECL);
723 : 6930259 : alias_node = cgraph_node::get_create (alias);
724 : 6930259 : gcc_assert (!alias_node->definition);
725 : 6930259 : alias_node->alias_target = target;
726 : 6930259 : alias_node->definition = true;
727 : 6930259 : alias_node->alias = true;
728 : 6930259 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias)) != NULL)
729 : 47 : alias_node->transparent_alias = alias_node->weakref = true;
730 : 6930259 : if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (alias)))
731 : 314 : alias_node->ifunc_resolver = true;
732 : 6930259 : return alias_node;
733 : : }
734 : :
735 : : /* Attempt to mark ALIAS as an alias to DECL. Return alias node if successful
736 : : and NULL otherwise.
737 : : Same body aliases are output whenever the body of DECL is output,
738 : : and cgraph_node::get (ALIAS) transparently returns
739 : : cgraph_node::get (DECL). */
740 : :
741 : : cgraph_node *
742 : 6910913 : cgraph_node::create_same_body_alias (tree alias, tree decl)
743 : : {
744 : 6910913 : cgraph_node *n;
745 : :
746 : : /* If aliases aren't supported by the assembler, fail. */
747 : 6910913 : if (!TARGET_SUPPORTS_ALIASES)
748 : : return NULL;
749 : :
750 : : /* Langhooks can create same body aliases of symbols not defined.
751 : : Those are useless. Drop them on the floor. */
752 : 6910913 : if (symtab->global_info_ready)
753 : : return NULL;
754 : :
755 : 6910913 : n = cgraph_node::create_alias (alias, decl);
756 : 6910913 : n->cpp_implicit_alias = true;
757 : 6910913 : if (symtab->cpp_implicit_aliases_done)
758 : 3630521 : n->resolve_alias (cgraph_node::get (decl));
759 : : return n;
760 : : }
761 : :
762 : : /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
763 : : aliases DECL with an adjustments made into the first parameter.
764 : : See comments in struct cgraph_thunk_info for detail on the parameters. */
765 : :
766 : : cgraph_node *
767 : 4402 : cgraph_node::create_thunk (tree alias, tree, bool this_adjusting,
768 : : HOST_WIDE_INT fixed_offset,
769 : : HOST_WIDE_INT virtual_value,
770 : : HOST_WIDE_INT indirect_offset,
771 : : tree virtual_offset,
772 : : tree real_alias)
773 : : {
774 : 4402 : cgraph_node *node;
775 : :
776 : 4402 : node = cgraph_node::get (alias);
777 : 4402 : if (node)
778 : 3668 : node->reset ();
779 : : else
780 : 734 : node = cgraph_node::create (alias);
781 : :
782 : : /* Make sure that if VIRTUAL_OFFSET is in sync with VIRTUAL_VALUE. */
783 : 4402 : gcc_checking_assert (virtual_offset
784 : : ? virtual_value == wi::to_wide (virtual_offset)
785 : : : virtual_value == 0);
786 : :
787 : 4402 : node->thunk = true;
788 : 4402 : node->definition = true;
789 : :
790 : 4402 : thunk_info *i;
791 : 4402 : thunk_info local_info;
792 : 4402 : if (symtab->state < CONSTRUCTION)
793 : : i = &local_info;
794 : : else
795 : 0 : i = thunk_info::get_create (node);
796 : 4402 : i->fixed_offset = fixed_offset;
797 : 4402 : i->virtual_value = virtual_value;
798 : 4402 : i->indirect_offset = indirect_offset;
799 : 4402 : i->alias = real_alias;
800 : 4402 : i->this_adjusting = this_adjusting;
801 : 4402 : i->virtual_offset_p = virtual_offset != NULL;
802 : 4402 : if (symtab->state < CONSTRUCTION)
803 : 4402 : i->register_early (node);
804 : :
805 : 4402 : return node;
806 : : }
807 : :
808 : : /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
809 : : Return NULL if there's no such node. */
810 : :
811 : : cgraph_node *
812 : 0 : cgraph_node::get_for_asmname (tree asmname)
813 : : {
814 : : /* We do not want to look at inline clones. */
815 : 0 : for (symtab_node *node = symtab_node::get_for_asmname (asmname);
816 : 0 : node;
817 : 0 : node = node->next_sharing_asm_name)
818 : : {
819 : 0 : cgraph_node *cn = dyn_cast <cgraph_node *> (node);
820 : 0 : if (cn && !cn->inlined_to)
821 : : return cn;
822 : : }
823 : : return NULL;
824 : : }
825 : :
826 : : /* Returns a hash value for X (which really is a cgraph_edge). */
827 : :
828 : : hashval_t
829 : 220964660 : cgraph_edge_hasher::hash (cgraph_edge *e)
830 : : {
831 : : /* This is a really poor hash function, but it is what htab_hash_pointer
832 : : uses. */
833 : 220964660 : return (hashval_t) ((intptr_t)e->call_stmt >> 3);
834 : : }
835 : :
836 : : /* Returns a hash value for X (which really is a cgraph_edge). */
837 : :
838 : : hashval_t
839 : 44097594 : cgraph_edge_hasher::hash (gimple *call_stmt)
840 : : {
841 : : /* This is a really poor hash function, but it is what htab_hash_pointer
842 : : uses. */
843 : 44097594 : return (hashval_t) ((intptr_t)call_stmt >> 3);
844 : : }
845 : :
846 : : /* Return nonzero if the call_stmt of cgraph_edge X is stmt *Y. */
847 : :
848 : : inline bool
849 : 270279822 : cgraph_edge_hasher::equal (cgraph_edge *x, gimple *y)
850 : : {
851 : 270279822 : return x->call_stmt == y;
852 : : }
853 : :
854 : : /* Add call graph edge E to call site hash of its caller. */
855 : :
856 : : static inline void
857 : 3825 : cgraph_update_edge_in_call_site_hash (cgraph_edge *e)
858 : : {
859 : 3825 : gimple *call = e->call_stmt;
860 : 3825 : *e->caller->call_site_hash->find_slot_with_hash
861 : 3825 : (call, cgraph_edge_hasher::hash (call), INSERT) = e;
862 : 3825 : }
863 : :
864 : : /* Add call graph edge E to call site hash of its caller. */
865 : :
866 : : static inline void
867 : 8332619 : cgraph_add_edge_to_call_site_hash (cgraph_edge *e)
868 : : {
869 : : /* There are two speculative edges for every statement (one direct,
870 : : one indirect); always hash the direct one. */
871 : 8332619 : if (e->speculative && e->indirect_unknown_callee)
872 : : return;
873 : 8332615 : cgraph_edge **slot = e->caller->call_site_hash->find_slot_with_hash
874 : 8332615 : (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt), INSERT);
875 : 8332615 : if (*slot)
876 : : {
877 : 3821 : gcc_assert (((cgraph_edge *)*slot)->speculative);
878 : 3821 : if (e->callee && (!e->prev_callee
879 : 0 : || !e->prev_callee->speculative
880 : 0 : || e->prev_callee->call_stmt != e->call_stmt))
881 : 0 : *slot = e;
882 : 3821 : return;
883 : : }
884 : 8328794 : gcc_assert (!*slot || e->speculative);
885 : 8328794 : *slot = e;
886 : : }
887 : :
888 : : /* Return the callgraph edge representing the GIMPLE_CALL statement
889 : : CALL_STMT. */
890 : :
891 : : cgraph_edge *
892 : 208754216 : cgraph_node::get_edge (gimple *call_stmt)
893 : : {
894 : 208754216 : cgraph_edge *e, *e2;
895 : 208754216 : int n = 0;
896 : :
897 : 208754216 : if (call_site_hash)
898 : 34640157 : return call_site_hash->find_with_hash
899 : 34640157 : (call_stmt, cgraph_edge_hasher::hash (call_stmt));
900 : :
901 : : /* This loop may turn out to be performance problem. In such case adding
902 : : hashtables into call nodes with very many edges is probably best
903 : : solution. It is not good idea to add pointer into CALL_EXPR itself
904 : : because we want to make possible having multiple cgraph nodes representing
905 : : different clones of the same body before the body is actually cloned. */
906 : 1684992893 : for (e = callees; e; e = e->next_callee)
907 : : {
908 : 1638483609 : if (e->call_stmt == call_stmt)
909 : : break;
910 : 1510878834 : n++;
911 : : }
912 : :
913 : 174114059 : if (!e)
914 : 60018027 : for (e = indirect_calls; e; e = e->next_callee)
915 : : {
916 : 16455219 : if (e->call_stmt == call_stmt)
917 : : break;
918 : 13508743 : n++;
919 : : }
920 : :
921 : 174114059 : if (n > 100)
922 : : {
923 : 30177 : call_site_hash = hash_table<cgraph_edge_hasher>::create_ggc (120);
924 : 3099091 : for (e2 = callees; e2; e2 = e2->next_callee)
925 : 3068914 : cgraph_add_edge_to_call_site_hash (e2);
926 : 113403 : for (e2 = indirect_calls; e2; e2 = e2->next_callee)
927 : 83226 : cgraph_add_edge_to_call_site_hash (e2);
928 : : }
929 : :
930 : : return e;
931 : : }
932 : :
933 : :
934 : : /* Change field call_stmt of edge E to NEW_STMT. If UPDATE_SPECULATIVE and E
935 : : is any component of speculative edge, then update all components.
936 : : Speculations can be resolved in the process and EDGE can be removed and
937 : : deallocated. Return the edge that now represents the call. */
938 : :
939 : : cgraph_edge *
940 : 2678616 : cgraph_edge::set_call_stmt (cgraph_edge *e, gcall *new_stmt,
941 : : bool update_speculative)
942 : : {
943 : 2678616 : tree decl;
944 : :
945 : 2678616 : cgraph_node *new_direct_callee = NULL;
946 : 2647311 : if ((e->indirect_unknown_callee || e->speculative)
947 : 2713929 : && (decl = gimple_call_fndecl (new_stmt)))
948 : : {
949 : : /* Constant propagation and especially inlining can turn an indirect call
950 : : into a direct one. */
951 : 0 : new_direct_callee = cgraph_node::get (decl);
952 : 0 : gcc_checking_assert (new_direct_callee);
953 : : }
954 : :
955 : : /* Speculative edges has three component, update all of them
956 : : when asked to. */
957 : 2678616 : if (update_speculative && e->speculative
958 : : /* If we are about to resolve the speculation by calling make_direct
959 : : below, do not bother going over all the speculative edges now. */
960 : 2004 : && !new_direct_callee)
961 : : {
962 : 2004 : cgraph_edge *direct, *indirect, *next;
963 : 2004 : ipa_ref *ref;
964 : 2004 : bool e_indirect = e->indirect_unknown_callee;
965 : 2004 : int n = 0;
966 : :
967 : 2004 : direct = e->first_speculative_call_target ();
968 : 2004 : indirect = e->speculative_call_indirect_edge ();
969 : :
970 : 2004 : gcall *old_stmt = direct->call_stmt;
971 : 4008 : for (cgraph_edge *d = direct; d; d = next)
972 : : {
973 : 2004 : next = d->next_speculative_call_target ();
974 : 2004 : cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
975 : 2004 : gcc_assert (d2 == d);
976 : 2004 : n++;
977 : : }
978 : 2004 : gcc_checking_assert (indirect->num_speculative_call_targets_p () == n);
979 : 5153 : for (unsigned int i = 0; e->caller->iterate_reference (i, ref); i++)
980 : 3149 : if (ref->speculative && ref->stmt == old_stmt)
981 : : {
982 : 2004 : ref->stmt = new_stmt;
983 : 2004 : n--;
984 : : }
985 : :
986 : 2004 : indirect = set_call_stmt (indirect, new_stmt, false);
987 : 2004 : return e_indirect ? indirect : direct;
988 : : }
989 : :
990 : 2676612 : if (new_direct_callee)
991 : 0 : e = make_direct (e, new_direct_callee);
992 : :
993 : : /* Only direct speculative edges go to call_site_hash. */
994 : 2676612 : if (e->caller->call_site_hash
995 : 484360 : && (!e->speculative || !e->indirect_unknown_callee)
996 : : /* It is possible that edge was previously speculative. In this case
997 : : we have different value in call stmt hash which needs preserving. */
998 : 3160972 : && e->caller->get_edge (e->call_stmt) == e)
999 : 480535 : e->caller->call_site_hash->remove_elt_with_hash
1000 : 480535 : (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt));
1001 : :
1002 : 2676612 : e->call_stmt = new_stmt;
1003 : :
1004 : 2676612 : function *fun = DECL_STRUCT_FUNCTION (e->caller->decl);
1005 : 2676612 : e->can_throw_external = stmt_can_throw_external (fun, new_stmt);
1006 : : /* Update call stite hash. For speculative calls we only record the first
1007 : : direct edge. */
1008 : 2676612 : if (e->caller->call_site_hash
1009 : 484360 : && (!e->speculative
1010 : 0 : || (e->callee
1011 : 0 : && (!e->prev_callee || !e->prev_callee->speculative
1012 : 0 : || e->prev_callee->call_stmt != e->call_stmt))
1013 : 0 : || (e->speculative && !e->callee)))
1014 : 484360 : cgraph_add_edge_to_call_site_hash (e);
1015 : : return e;
1016 : : }
1017 : :
1018 : : /* Allocate a cgraph_edge structure and fill it with data according to the
1019 : : parameters of which only CALLEE can be NULL (when creating an indirect call
1020 : : edge). CLONING_P should be set if properties that are copied from an
1021 : : original edge should not be calculated. */
1022 : :
1023 : : cgraph_edge *
1024 : 45451856 : symbol_table::create_edge (cgraph_node *caller, cgraph_node *callee,
1025 : : gcall *call_stmt, profile_count count,
1026 : : bool indir_unknown_callee, bool cloning_p)
1027 : : {
1028 : 45451856 : cgraph_edge *edge;
1029 : :
1030 : : /* LTO does not actually have access to the call_stmt since these
1031 : : have not been loaded yet. */
1032 : 45451856 : if (call_stmt)
1033 : : {
1034 : : /* This is a rather expensive check possibly triggering
1035 : : construction of call stmt hashtable. */
1036 : 44601076 : cgraph_edge *e;
1037 : 44601076 : gcc_checking_assert (!(e = caller->get_edge (call_stmt))
1038 : : || e->speculative);
1039 : :
1040 : 44601076 : gcc_assert (is_gimple_call (call_stmt));
1041 : : }
1042 : :
1043 : 45451856 : edge = ggc_alloc<cgraph_edge> ();
1044 : 45451856 : edge->m_summary_id = -1;
1045 : 45451856 : edges_count++;
1046 : :
1047 : 45451856 : ++edges_max_uid;
1048 : 45451856 : gcc_assert (edges_max_uid != 0);
1049 : 45451856 : edge->m_uid = edges_max_uid;
1050 : 45451856 : edge->aux = NULL;
1051 : 45451856 : edge->caller = caller;
1052 : 45451856 : edge->callee = callee;
1053 : 45451856 : edge->prev_caller = NULL;
1054 : 45451856 : edge->next_caller = NULL;
1055 : 45451856 : edge->prev_callee = NULL;
1056 : 45451856 : edge->next_callee = NULL;
1057 : 45451856 : edge->lto_stmt_uid = 0;
1058 : 45451856 : edge->speculative_id = 0;
1059 : :
1060 : 45451856 : edge->count = count;
1061 : 45451856 : edge->call_stmt = call_stmt;
1062 : 45451856 : edge->indirect_info = NULL;
1063 : 45451856 : edge->indirect_inlining_edge = 0;
1064 : 45451856 : edge->speculative = false;
1065 : 45451856 : edge->indirect_unknown_callee = indir_unknown_callee;
1066 : 45451856 : if (call_stmt && caller->call_site_hash)
1067 : 4696119 : cgraph_add_edge_to_call_site_hash (edge);
1068 : :
1069 : 45451856 : if (cloning_p)
1070 : : return edge;
1071 : :
1072 : 38411288 : edge->can_throw_external
1073 : 38411288 : = call_stmt ? stmt_can_throw_external (DECL_STRUCT_FUNCTION (caller->decl),
1074 : : call_stmt) : false;
1075 : 38411288 : edge->inline_failed = CIF_FUNCTION_NOT_CONSIDERED;
1076 : 38411288 : edge->call_stmt_cannot_inline_p = false;
1077 : :
1078 : 38411288 : if (opt_for_fn (edge->caller->decl, flag_devirtualize)
1079 : 38411288 : && call_stmt && DECL_STRUCT_FUNCTION (caller->decl))
1080 : 30271980 : edge->in_polymorphic_cdtor
1081 : 30271980 : = decl_maybe_in_construction_p (NULL, NULL, call_stmt,
1082 : : caller->decl);
1083 : : else
1084 : 8139308 : edge->in_polymorphic_cdtor = caller->thunk;
1085 : :
1086 : 37738471 : if (callee && symtab->state != LTO_STREAMING
1087 : 75556292 : && edge->callee->comdat_local_p ())
1088 : 7605 : edge->caller->calls_comdat_local = true;
1089 : :
1090 : : return edge;
1091 : : }
1092 : :
1093 : : /* Create edge from a given function to CALLEE in the cgraph. CLONING_P should
1094 : : be set if properties that are copied from an original edge should not be
1095 : : calculated. */
1096 : :
1097 : : cgraph_edge *
1098 : 44596130 : cgraph_node::create_edge (cgraph_node *callee,
1099 : : gcall *call_stmt, profile_count count, bool cloning_p)
1100 : : {
1101 : 44596130 : cgraph_edge *edge = symtab->create_edge (this, callee, call_stmt, count,
1102 : : false, cloning_p);
1103 : :
1104 : 44596130 : if (!cloning_p)
1105 : 37738471 : initialize_inline_failed (edge);
1106 : :
1107 : 44596130 : edge->next_caller = callee->callers;
1108 : 44596130 : if (callee->callers)
1109 : 34663145 : callee->callers->prev_caller = edge;
1110 : 44596130 : edge->next_callee = callees;
1111 : 44596130 : if (callees)
1112 : 34465440 : callees->prev_callee = edge;
1113 : 44596130 : callees = edge;
1114 : 44596130 : callee->callers = edge;
1115 : :
1116 : 44596130 : return edge;
1117 : : }
1118 : :
1119 : : /* Allocate cgraph_indirect_call_info and set its fields to default values. */
1120 : :
1121 : : cgraph_indirect_call_info *
1122 : 855726 : cgraph_allocate_init_indirect_info (void)
1123 : : {
1124 : 855726 : cgraph_indirect_call_info *ii;
1125 : :
1126 : 855726 : ii = ggc_cleared_alloc<cgraph_indirect_call_info> ();
1127 : 855726 : ii->param_index = -1;
1128 : 855726 : return ii;
1129 : : }
1130 : :
1131 : : /* Create an indirect edge with a yet-undetermined callee where the call
1132 : : statement destination is a formal parameter of the caller with index
1133 : : PARAM_INDEX. CLONING_P should be set if properties that are copied from an
1134 : : original edge should not be calculated and indirect_info structure should
1135 : : not be calculated. */
1136 : :
1137 : : cgraph_edge *
1138 : 855726 : cgraph_node::create_indirect_edge (gcall *call_stmt, int ecf_flags,
1139 : : profile_count count,
1140 : : bool cloning_p)
1141 : : {
1142 : 855726 : cgraph_edge *edge = symtab->create_edge (this, NULL, call_stmt, count, true,
1143 : : cloning_p);
1144 : 855726 : tree target;
1145 : :
1146 : 855726 : if (!cloning_p)
1147 : 672817 : initialize_inline_failed (edge);
1148 : :
1149 : 855726 : edge->indirect_info = cgraph_allocate_init_indirect_info ();
1150 : 855726 : edge->indirect_info->ecf_flags = ecf_flags;
1151 : 855726 : edge->indirect_info->vptr_changed = true;
1152 : :
1153 : : /* Record polymorphic call info. */
1154 : 855726 : if (!cloning_p
1155 : 855726 : && call_stmt
1156 : 670641 : && (target = gimple_call_fn (call_stmt))
1157 : 1526367 : && virtual_method_call_p (target))
1158 : : {
1159 : 101347 : ipa_polymorphic_call_context context (decl, target, call_stmt);
1160 : :
1161 : : /* Only record types can have virtual calls. */
1162 : 101347 : edge->indirect_info->polymorphic = true;
1163 : 101347 : edge->indirect_info->param_index = -1;
1164 : 101347 : edge->indirect_info->otr_token
1165 : 101347 : = tree_to_uhwi (OBJ_TYPE_REF_TOKEN (target));
1166 : 101347 : edge->indirect_info->otr_type = obj_type_ref_class (target);
1167 : 101347 : gcc_assert (TREE_CODE (edge->indirect_info->otr_type) == RECORD_TYPE);
1168 : 101347 : edge->indirect_info->context = context;
1169 : : }
1170 : :
1171 : 855726 : edge->next_callee = indirect_calls;
1172 : 855726 : if (indirect_calls)
1173 : 407036 : indirect_calls->prev_callee = edge;
1174 : 855726 : indirect_calls = edge;
1175 : :
1176 : 855726 : return edge;
1177 : : }
1178 : :
1179 : : /* Remove the edge from the list of the callees of the caller. */
1180 : :
1181 : : void
1182 : 4715008 : cgraph_edge::remove_caller (void)
1183 : : {
1184 : 4715008 : if (prev_callee)
1185 : 3840255 : prev_callee->next_callee = next_callee;
1186 : 4715008 : if (next_callee)
1187 : 3218261 : next_callee->prev_callee = prev_callee;
1188 : 4715008 : if (!prev_callee)
1189 : : {
1190 : 874753 : if (indirect_unknown_callee)
1191 : 880 : caller->indirect_calls = next_callee;
1192 : : else
1193 : 873873 : caller->callees = next_callee;
1194 : : }
1195 : 4715008 : if (caller->call_site_hash
1196 : 4715008 : && this == caller->get_edge (call_stmt))
1197 : 640462 : caller->call_site_hash->remove_elt_with_hash
1198 : 640462 : (call_stmt, cgraph_edge_hasher::hash (call_stmt));
1199 : 4715008 : }
1200 : :
1201 : : /* Put the edge onto the free list. */
1202 : :
1203 : : void
1204 : 45015619 : symbol_table::free_edge (cgraph_edge *e)
1205 : : {
1206 : 45015619 : edges_count--;
1207 : 45015619 : if (e->m_summary_id != -1)
1208 : 21040235 : edge_released_summary_ids.safe_push (e->m_summary_id);
1209 : :
1210 : 45015619 : if (e->indirect_info)
1211 : 848980 : ggc_free (e->indirect_info);
1212 : 45015619 : ggc_free (e);
1213 : 45015619 : }
1214 : :
1215 : : /* Remove the edge in the cgraph. */
1216 : :
1217 : : void
1218 : 102511 : cgraph_edge::remove (cgraph_edge *edge)
1219 : : {
1220 : : /* Call all edge removal hooks. */
1221 : 102511 : symtab->call_edge_removal_hooks (edge);
1222 : :
1223 : 102511 : if (!edge->indirect_unknown_callee)
1224 : : /* Remove from callers list of the callee. */
1225 : 100240 : edge->remove_callee ();
1226 : :
1227 : : /* Remove from callees list of the callers. */
1228 : 102511 : edge->remove_caller ();
1229 : :
1230 : : /* Put the edge onto the free list. */
1231 : 102511 : symtab->free_edge (edge);
1232 : 102511 : }
1233 : :
1234 : : /* Turn edge into speculative call calling N2. Update
1235 : : the profile so the direct call is taken COUNT times
1236 : : with FREQUENCY.
1237 : :
1238 : : At clone materialization time, the indirect call E will
1239 : : be expanded as:
1240 : :
1241 : : if (call_dest == N2)
1242 : : n2 ();
1243 : : else
1244 : : call call_dest
1245 : :
1246 : : At this time the function just creates the direct call,
1247 : : the reference representing the if conditional and attaches
1248 : : them all to the original indirect call statement.
1249 : :
1250 : : speculative_id is used to link direct calls with their corresponding
1251 : : IPA_REF_ADDR references when representing speculative calls.
1252 : :
1253 : : Return direct edge created. */
1254 : :
1255 : : cgraph_edge *
1256 : 5390 : cgraph_edge::make_speculative (cgraph_node *n2, profile_count direct_count,
1257 : : unsigned int speculative_id)
1258 : : {
1259 : 5390 : cgraph_node *n = caller;
1260 : 5390 : ipa_ref *ref = NULL;
1261 : 5390 : cgraph_edge *e2;
1262 : :
1263 : 5390 : if (dump_file)
1264 : 26 : fprintf (dump_file, "Indirect call -> speculative call %s => %s\n",
1265 : : n->dump_name (), n2->dump_name ());
1266 : 5390 : speculative = true;
1267 : 5390 : e2 = n->create_edge (n2, call_stmt, direct_count);
1268 : 5390 : initialize_inline_failed (e2);
1269 : 5390 : e2->speculative = true;
1270 : 5390 : if (TREE_NOTHROW (n2->decl))
1271 : 3846 : e2->can_throw_external = false;
1272 : : else
1273 : 1544 : e2->can_throw_external = can_throw_external;
1274 : 5390 : e2->lto_stmt_uid = lto_stmt_uid;
1275 : 5390 : e2->speculative_id = speculative_id;
1276 : 5390 : e2->in_polymorphic_cdtor = in_polymorphic_cdtor;
1277 : 5390 : indirect_info->num_speculative_call_targets++;
1278 : 5390 : count -= e2->count;
1279 : 5390 : symtab->call_edge_duplication_hooks (this, e2);
1280 : 5390 : ref = n->create_reference (n2, IPA_REF_ADDR, call_stmt);
1281 : 5390 : ref->lto_stmt_uid = lto_stmt_uid;
1282 : 5390 : ref->speculative_id = speculative_id;
1283 : 5390 : ref->speculative = speculative;
1284 : 5390 : n2->mark_address_taken ();
1285 : 5390 : return e2;
1286 : : }
1287 : :
1288 : : /* Speculative call consists of an indirect edge and one or more
1289 : : direct edge+ref pairs.
1290 : :
1291 : : Given an edge which is part of speculative call, return the first
1292 : : direct call edge in the speculative call sequence. */
1293 : :
1294 : : cgraph_edge *
1295 : 22059 : cgraph_edge::first_speculative_call_target ()
1296 : : {
1297 : 22059 : cgraph_edge *e = this;
1298 : :
1299 : 22059 : gcc_checking_assert (e->speculative);
1300 : 22059 : if (e->callee)
1301 : : {
1302 : 2229 : while (e->prev_callee && e->prev_callee->speculative
1303 : 157 : && e->prev_callee->call_stmt == e->call_stmt
1304 : 16967 : && e->prev_callee->lto_stmt_uid == e->lto_stmt_uid)
1305 : : e = e->prev_callee;
1306 : : return e;
1307 : : }
1308 : : /* Call stmt site hash always points to the first target of the
1309 : : speculative call sequence. */
1310 : 5092 : if (e->call_stmt)
1311 : 5080 : return e->caller->get_edge (e->call_stmt);
1312 : 17 : for (cgraph_edge *e2 = e->caller->callees; true; e2 = e2->next_callee)
1313 : 17 : if (e2->speculative
1314 : 12 : && e->call_stmt == e2->call_stmt
1315 : 12 : && e->lto_stmt_uid == e2->lto_stmt_uid)
1316 : : return e2;
1317 : : }
1318 : :
1319 : : /* We always maintain first direct edge in the call site hash, if one
1320 : : exists. E is going to be removed. See if it is first one and update
1321 : : hash accordingly. INDIRECT is the indirect edge of speculative call.
1322 : : We assume that INDIRECT->num_speculative_call_targets_p () is already
1323 : : updated for removal of E. */
1324 : : static void
1325 : 16079 : update_call_stmt_hash_for_removing_direct_edge (cgraph_edge *e,
1326 : : cgraph_edge *indirect)
1327 : : {
1328 : 16079 : if (e->caller->call_site_hash)
1329 : : {
1330 : 3825 : if (e->caller->get_edge (e->call_stmt) != e)
1331 : : ;
1332 : 3825 : else if (!indirect->num_speculative_call_targets_p ())
1333 : 3825 : cgraph_update_edge_in_call_site_hash (indirect);
1334 : : else
1335 : : {
1336 : 0 : gcc_checking_assert (e->next_callee && e->next_callee->speculative
1337 : : && e->next_callee->call_stmt == e->call_stmt);
1338 : 0 : cgraph_update_edge_in_call_site_hash (e->next_callee);
1339 : : }
1340 : : }
1341 : 16079 : }
1342 : :
1343 : : /* Speculative call EDGE turned out to be direct call to CALLEE_DECL. Remove
1344 : : the speculative call sequence and return edge representing the call, the
1345 : : original EDGE can be removed and deallocated. Return the edge that now
1346 : : represents the call.
1347 : :
1348 : : For "speculative" indirect call that contains multiple "speculative"
1349 : : targets (i.e. edge->indirect_info->num_speculative_call_targets > 1),
1350 : : decrease the count and only remove current direct edge.
1351 : :
1352 : : If no speculative direct call left to the speculative indirect call, remove
1353 : : the speculative of both the indirect call and corresponding direct edge.
1354 : :
1355 : : It is up to caller to iteratively resolve each "speculative" direct call and
1356 : : redirect the call as appropriate. */
1357 : :
1358 : : cgraph_edge *
1359 : 1116 : cgraph_edge::resolve_speculation (cgraph_edge *edge, tree callee_decl)
1360 : : {
1361 : 1116 : cgraph_edge *e2;
1362 : 1116 : ipa_ref *ref;
1363 : :
1364 : 1116 : gcc_assert (edge->speculative && (!callee_decl || edge->callee));
1365 : 1116 : if (!edge->callee)
1366 : 0 : e2 = edge->first_speculative_call_target ();
1367 : : else
1368 : : e2 = edge;
1369 : 1116 : ref = e2->speculative_call_target_ref ();
1370 : 1116 : edge = edge->speculative_call_indirect_edge ();
1371 : 1116 : if (!callee_decl
1372 : 1828 : || !ref->referred->semantically_equivalent_p
1373 : 712 : (symtab_node::get (callee_decl)))
1374 : : {
1375 : 635 : if (dump_file)
1376 : : {
1377 : 0 : if (callee_decl)
1378 : : {
1379 : 0 : fprintf (dump_file, "Speculative indirect call %s => %s has "
1380 : : "turned out to have contradicting known target ",
1381 : 0 : edge->caller->dump_name (),
1382 : 0 : e2->callee->dump_name ());
1383 : 0 : print_generic_expr (dump_file, callee_decl);
1384 : 0 : fprintf (dump_file, "\n");
1385 : : }
1386 : : else
1387 : : {
1388 : 0 : fprintf (dump_file, "Removing speculative call %s => %s\n",
1389 : 0 : edge->caller->dump_name (),
1390 : 0 : e2->callee->dump_name ());
1391 : : }
1392 : : }
1393 : : }
1394 : : else
1395 : : {
1396 : 481 : cgraph_edge *tmp = edge;
1397 : 481 : if (dump_file)
1398 : 36 : fprintf (dump_file, "Speculative call turned into direct call.\n");
1399 : : edge = e2;
1400 : : e2 = tmp;
1401 : : /* FIXME: If EDGE is inlined, we should scale up the frequencies
1402 : : and counts in the functions inlined through it. */
1403 : : }
1404 : 1116 : edge->count += e2->count;
1405 : 1116 : if (edge->num_speculative_call_targets_p ())
1406 : : {
1407 : : /* The indirect edge has multiple speculative targets, don't remove
1408 : : speculative until all related direct edges are resolved. */
1409 : 635 : edge->indirect_info->num_speculative_call_targets--;
1410 : 635 : if (!edge->indirect_info->num_speculative_call_targets)
1411 : 631 : edge->speculative = false;
1412 : : }
1413 : : else
1414 : 481 : edge->speculative = false;
1415 : 1116 : e2->speculative = false;
1416 : 1116 : update_call_stmt_hash_for_removing_direct_edge (e2, edge);
1417 : 1116 : ref->remove_reference ();
1418 : 1116 : if (e2->indirect_unknown_callee || e2->inline_failed)
1419 : 1088 : remove (e2);
1420 : : else
1421 : 28 : e2->callee->remove_symbol_and_inline_clones ();
1422 : 1116 : return edge;
1423 : : }
1424 : :
1425 : : /* Return edge corresponding to speculative call to a given target.
1426 : : NULL if speculative call does not have one. */
1427 : :
1428 : : cgraph_edge *
1429 : 0 : cgraph_edge::speculative_call_for_target (cgraph_node *target)
1430 : : {
1431 : 0 : for (cgraph_edge *direct = first_speculative_call_target ();
1432 : 0 : direct;
1433 : 0 : direct = direct->next_speculative_call_target ())
1434 : 0 : if (direct->speculative_call_target_ref ()
1435 : 0 : ->referred->semantically_equivalent_p (target))
1436 : : return direct;
1437 : : return NULL;
1438 : : }
1439 : :
1440 : : /* Make an indirect or speculative EDGE with an unknown callee an ordinary edge
1441 : : leading to CALLEE. Speculations can be resolved in the process and EDGE can
1442 : : be removed and deallocated. Return the edge that now represents the
1443 : : call. */
1444 : :
1445 : : cgraph_edge *
1446 : 4603 : cgraph_edge::make_direct (cgraph_edge *edge, cgraph_node *callee)
1447 : : {
1448 : 4603 : gcc_assert (edge->indirect_unknown_callee || edge->speculative);
1449 : :
1450 : : /* If we are redirecting speculative call, make it non-speculative. */
1451 : 4603 : if (edge->speculative)
1452 : : {
1453 : 508 : cgraph_edge *found = NULL;
1454 : 508 : cgraph_edge *direct, *next;
1455 : :
1456 : 508 : edge = edge->speculative_call_indirect_edge ();
1457 : :
1458 : : /* Look all speculative targets and remove all but one corresponding
1459 : : to callee (if it exists). */
1460 : 508 : for (direct = edge->first_speculative_call_target ();
1461 : 1020 : direct;
1462 : : direct = next)
1463 : : {
1464 : 512 : next = direct->next_speculative_call_target ();
1465 : :
1466 : : /* Compare ref not direct->callee. Direct edge is possibly
1467 : : inlined or redirected. */
1468 : 512 : if (!direct->speculative_call_target_ref ()
1469 : 512 : ->referred->semantically_equivalent_p (callee)
1470 : 512 : || found)
1471 : 31 : edge = direct->resolve_speculation (direct, NULL);
1472 : : else
1473 : : found = direct;
1474 : : }
1475 : :
1476 : : /* On successful speculation just remove the indirect edge and
1477 : : return the pre existing direct edge.
1478 : : It is important to not remove it and redirect because the direct
1479 : : edge may be inlined or redirected. */
1480 : 508 : if (found)
1481 : : {
1482 : 481 : cgraph_edge *e2 = resolve_speculation (found, callee->decl);
1483 : 481 : gcc_checking_assert (!found->speculative && e2 == found);
1484 : : return found;
1485 : : }
1486 : 27 : gcc_checking_assert (!edge->speculative);
1487 : : }
1488 : :
1489 : 4122 : edge->indirect_unknown_callee = 0;
1490 : 4122 : ggc_free (edge->indirect_info);
1491 : 4122 : edge->indirect_info = NULL;
1492 : :
1493 : : /* Get the edge out of the indirect edge list. */
1494 : 4122 : if (edge->prev_callee)
1495 : 98 : edge->prev_callee->next_callee = edge->next_callee;
1496 : 4122 : if (edge->next_callee)
1497 : 708 : edge->next_callee->prev_callee = edge->prev_callee;
1498 : 4122 : if (!edge->prev_callee)
1499 : 4024 : edge->caller->indirect_calls = edge->next_callee;
1500 : :
1501 : : /* Put it into the normal callee list */
1502 : 4122 : edge->prev_callee = NULL;
1503 : 4122 : edge->next_callee = edge->caller->callees;
1504 : 4122 : if (edge->caller->callees)
1505 : 2652 : edge->caller->callees->prev_callee = edge;
1506 : 4122 : edge->caller->callees = edge;
1507 : :
1508 : : /* Insert to callers list of the new callee. */
1509 : 4122 : edge->set_callee (callee);
1510 : :
1511 : : /* We need to re-determine the inlining status of the edge. */
1512 : 4122 : initialize_inline_failed (edge);
1513 : 4122 : return edge;
1514 : : }
1515 : :
1516 : : /* Redirect callee of the edge to N. The function does not update underlying
1517 : : call expression. */
1518 : :
1519 : : void
1520 : 4465849 : cgraph_edge::redirect_callee (cgraph_node *n)
1521 : : {
1522 : 4465849 : bool loc = callee->comdat_local_p ();
1523 : : /* Remove from callers list of the current callee. */
1524 : 4465849 : remove_callee ();
1525 : :
1526 : : /* Insert to callers list of the new callee. */
1527 : 4465849 : set_callee (n);
1528 : :
1529 : 4465849 : if (!inline_failed)
1530 : : return;
1531 : 587902 : if (!loc && n->comdat_local_p ())
1532 : : {
1533 : 56 : cgraph_node *to = caller->inlined_to ? caller->inlined_to : caller;
1534 : 56 : to->calls_comdat_local = true;
1535 : : }
1536 : 587846 : else if (loc && !n->comdat_local_p ())
1537 : : {
1538 : 99 : cgraph_node *to = caller->inlined_to ? caller->inlined_to : caller;
1539 : 99 : gcc_checking_assert (to->calls_comdat_local);
1540 : 99 : to->calls_comdat_local = to->check_calls_comdat_local_p ();
1541 : : }
1542 : : }
1543 : :
1544 : : /* If necessary, change the function declaration in the call statement
1545 : : associated with E so that it corresponds to the edge callee. Speculations
1546 : : can be resolved in the process and EDGE can be removed and deallocated.
1547 : :
1548 : : The edge could be one of speculative direct call generated from speculative
1549 : : indirect call. In this circumstance, decrease the speculative targets
1550 : : count (i.e. num_speculative_call_targets) and redirect call stmt to the
1551 : : corresponding i-th target. If no speculative direct call left to the
1552 : : speculative indirect call, remove "speculative" of the indirect call and
1553 : : also redirect stmt to it's final direct target.
1554 : :
1555 : : When called from within tree-inline, KILLED_SSAs has to contain the pointer
1556 : : to killed_new_ssa_names within the copy_body_data structure and SSAs
1557 : : discovered to be useless (if LHS is removed) will be added to it, otherwise
1558 : : it needs to be NULL.
1559 : :
1560 : : It is up to caller to iteratively transform each "speculative"
1561 : : direct call as appropriate. */
1562 : :
1563 : : gimple *
1564 : 9776164 : cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
1565 : : hash_set <tree> *killed_ssas)
1566 : : {
1567 : 9776164 : tree decl = gimple_call_fndecl (e->call_stmt);
1568 : 9776164 : gcall *new_stmt;
1569 : :
1570 : 9776164 : if (e->speculative)
1571 : : {
1572 : : /* If there already is an direct call (i.e. as a result of inliner's
1573 : : substitution), forget about speculating. */
1574 : 14963 : if (decl)
1575 : 0 : e = make_direct (e->speculative_call_indirect_edge (),
1576 : : cgraph_node::get (decl));
1577 : : else
1578 : : {
1579 : : /* Be sure we redirect all speculative targets before poking
1580 : : about indirect edge. */
1581 : 14963 : gcc_checking_assert (e->callee);
1582 : 14963 : cgraph_edge *indirect = e->speculative_call_indirect_edge ();
1583 : 14963 : gcall *new_stmt;
1584 : 14963 : ipa_ref *ref;
1585 : :
1586 : : /* Expand speculation into GIMPLE code. */
1587 : 14963 : if (dump_file)
1588 : : {
1589 : 42 : fprintf (dump_file,
1590 : : "Expanding speculative call of %s -> %s count: ",
1591 : 21 : e->caller->dump_name (),
1592 : : e->callee->dump_name ());
1593 : 21 : e->count.dump (dump_file);
1594 : 21 : fprintf (dump_file, "\n");
1595 : : }
1596 : 14963 : push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
1597 : :
1598 : 14963 : profile_count all = indirect->count;
1599 : 14963 : for (cgraph_edge *e2 = e->first_speculative_call_target ();
1600 : 29929 : e2;
1601 : 14966 : e2 = e2->next_speculative_call_target ())
1602 : 14966 : all = all + e2->count;
1603 : 14963 : profile_probability prob = e->count.probability_in (all);
1604 : 14963 : if (!prob.initialized_p ())
1605 : 116 : prob = profile_probability::even ();
1606 : 14963 : ref = e->speculative_call_target_ref ();
1607 : 29926 : new_stmt = gimple_ic (e->call_stmt,
1608 : : dyn_cast<cgraph_node *> (ref->referred),
1609 : : prob);
1610 : 14963 : e->speculative = false;
1611 : 14963 : if (indirect->num_speculative_call_targets_p ())
1612 : : {
1613 : : /* The indirect edge has multiple speculative targets, don't
1614 : : remove speculative until all related direct edges are
1615 : : redirected. */
1616 : 14963 : indirect->indirect_info->num_speculative_call_targets--;
1617 : 14963 : if (!indirect->indirect_info->num_speculative_call_targets)
1618 : 14960 : indirect->speculative = false;
1619 : : }
1620 : : else
1621 : 0 : indirect->speculative = false;
1622 : : /* Indirect edges are not both in the call site hash.
1623 : : get it updated. */
1624 : 14963 : update_call_stmt_hash_for_removing_direct_edge (e, indirect);
1625 : 14963 : cgraph_edge::set_call_stmt (e, new_stmt, false);
1626 : 14963 : e->count = gimple_bb (e->call_stmt)->count;
1627 : :
1628 : : /* Once we are done with expanding the sequence, update also indirect
1629 : : call probability. Until then the basic block accounts for the
1630 : : sum of indirect edge and all non-expanded speculations. */
1631 : 14963 : if (!indirect->speculative)
1632 : 14960 : indirect->count = gimple_bb (indirect->call_stmt)->count;
1633 : 14963 : ref->speculative = false;
1634 : 14963 : ref->stmt = NULL;
1635 : 14963 : pop_cfun ();
1636 : : /* Continue redirecting E to proper target. */
1637 : : }
1638 : : }
1639 : :
1640 : :
1641 : 9776164 : if (e->indirect_unknown_callee
1642 : 9683884 : || decl == e->callee->decl)
1643 : 8784526 : return e->call_stmt;
1644 : :
1645 : 991638 : if (decl && ipa_saved_clone_sources)
1646 : : {
1647 : 818860 : tree *p = ipa_saved_clone_sources->get (e->callee);
1648 : 818860 : if (p && decl == *p)
1649 : : {
1650 : 33680 : gimple_call_set_fndecl (e->call_stmt, e->callee->decl);
1651 : 33680 : return e->call_stmt;
1652 : : }
1653 : : }
1654 : 957958 : if (flag_checking && decl)
1655 : : {
1656 : 939519 : if (cgraph_node *node = cgraph_node::get (decl))
1657 : : {
1658 : 800167 : clone_info *info = clone_info::get (node);
1659 : 800167 : gcc_assert (!info || !info->param_adjustments);
1660 : : }
1661 : : }
1662 : :
1663 : 957958 : clone_info *callee_info = clone_info::get (e->callee);
1664 : 957958 : if (symtab->dump_file)
1665 : : {
1666 : 0 : fprintf (symtab->dump_file, "updating call of %s -> %s: ",
1667 : 0 : e->caller->dump_name (), e->callee->dump_name ());
1668 : 0 : print_gimple_stmt (symtab->dump_file, e->call_stmt, 0, dump_flags);
1669 : 0 : if (callee_info && callee_info->param_adjustments)
1670 : 0 : callee_info->param_adjustments->dump (symtab->dump_file);
1671 : : }
1672 : :
1673 : 509227 : if (ipa_param_adjustments *padjs
1674 : 957958 : = callee_info ? callee_info->param_adjustments : NULL)
1675 : : {
1676 : : /* We need to defer cleaning EH info on the new statement to
1677 : : fixup-cfg. We may not have dominator information at this point
1678 : : and thus would end up with unreachable blocks and have no way
1679 : : to communicate that we need to run CFG cleanup then. */
1680 : 481294 : int lp_nr = lookup_stmt_eh_lp (e->call_stmt);
1681 : 481294 : if (lp_nr != 0)
1682 : 147235 : remove_stmt_from_eh_lp (e->call_stmt);
1683 : :
1684 : 481294 : tree old_fntype = gimple_call_fntype (e->call_stmt);
1685 : 481294 : new_stmt = padjs->modify_call (e, false, killed_ssas);
1686 : 481294 : cgraph_node *origin = e->callee;
1687 : 716276 : while (origin->clone_of)
1688 : : origin = origin->clone_of;
1689 : :
1690 : 481294 : if ((origin->former_clone_of
1691 : 371437 : && old_fntype == TREE_TYPE (origin->former_clone_of))
1692 : 483476 : || old_fntype == TREE_TYPE (origin->decl))
1693 : 369257 : gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
1694 : : else
1695 : : {
1696 : 112037 : tree new_fntype = padjs->build_new_function_type (old_fntype, true);
1697 : 112037 : gimple_call_set_fntype (new_stmt, new_fntype);
1698 : : }
1699 : :
1700 : 481294 : if (lp_nr != 0)
1701 : 147235 : add_stmt_to_eh_lp (new_stmt, lp_nr);
1702 : : }
1703 : : else
1704 : : {
1705 : 476664 : if (flag_checking
1706 : 476664 : && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
1707 : : BUILT_IN_UNREACHABLE_TRAP))
1708 : 317045 : ipa_verify_edge_has_no_modifications (e);
1709 : 476664 : new_stmt = e->call_stmt;
1710 : 476664 : gimple_call_set_fndecl (new_stmt, e->callee->decl);
1711 : 476664 : update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
1712 : : }
1713 : :
1714 : : /* If changing the call to __cxa_pure_virtual or similar noreturn function,
1715 : : adjust gimple_call_fntype too. */
1716 : 957958 : if (gimple_call_noreturn_p (new_stmt)
1717 : 162704 : && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (e->callee->decl)))
1718 : 162631 : && TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl))
1719 : 1120583 : && (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl)))
1720 : 162625 : == void_type_node))
1721 : 161893 : gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
1722 : :
1723 : : /* If the call becomes noreturn, remove the LHS if possible. */
1724 : 957958 : tree lhs = gimple_call_lhs (new_stmt);
1725 : 957958 : if (lhs
1726 : 273412 : && gimple_call_noreturn_p (new_stmt)
1727 : 1001661 : && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (new_stmt)))
1728 : 60 : || should_remove_lhs_p (lhs)))
1729 : : {
1730 : 43662 : gimple_call_set_lhs (new_stmt, NULL_TREE);
1731 : : /* We need to fix up the SSA name to avoid checking errors. */
1732 : 43662 : if (TREE_CODE (lhs) == SSA_NAME)
1733 : : {
1734 : 32815 : tree var = create_tmp_reg_fn (DECL_STRUCT_FUNCTION (e->caller->decl),
1735 : 32815 : TREE_TYPE (lhs), NULL);
1736 : 32815 : SET_SSA_NAME_VAR_OR_IDENTIFIER (lhs, var);
1737 : 32815 : SSA_NAME_DEF_STMT (lhs) = gimple_build_nop ();
1738 : 32815 : set_ssa_default_def (DECL_STRUCT_FUNCTION (e->caller->decl),
1739 : : var, lhs);
1740 : : }
1741 : 43662 : update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
1742 : : }
1743 : :
1744 : : /* If new callee has no static chain, remove it. */
1745 : 957958 : if (gimple_call_chain (new_stmt) && !DECL_STATIC_CHAIN (e->callee->decl))
1746 : : {
1747 : 56 : gimple_call_set_chain (new_stmt, NULL);
1748 : 56 : update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
1749 : : }
1750 : :
1751 : 957958 : maybe_remove_unused_call_args (DECL_STRUCT_FUNCTION (e->caller->decl),
1752 : : new_stmt);
1753 : :
1754 : 957958 : e->caller->set_call_stmt_including_clones (e->call_stmt, new_stmt, false);
1755 : :
1756 : 957958 : if (symtab->dump_file)
1757 : : {
1758 : 0 : fprintf (symtab->dump_file, " updated to:");
1759 : 0 : print_gimple_stmt (symtab->dump_file, e->call_stmt, 0, dump_flags);
1760 : : }
1761 : : return new_stmt;
1762 : : }
1763 : :
1764 : : /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
1765 : : OLD_STMT changed into NEW_STMT. OLD_CALL is gimple_call_fndecl
1766 : : of OLD_STMT if it was previously call statement.
1767 : : If NEW_STMT is NULL, the call has been dropped without any
1768 : : replacement. */
1769 : :
1770 : : static void
1771 : 124519 : cgraph_update_edges_for_call_stmt_node (cgraph_node *node,
1772 : : gimple *old_stmt, tree old_call,
1773 : : gimple *new_stmt)
1774 : : {
1775 : 124519 : tree new_call = (new_stmt && is_gimple_call (new_stmt))
1776 : 129551 : ? gimple_call_fndecl (new_stmt) : 0;
1777 : :
1778 : : /* We are seeing indirect calls, then there is nothing to update. */
1779 : 124519 : if (!new_call && !old_call)
1780 : : return;
1781 : : /* See if we turned indirect call into direct call or folded call to one builtin
1782 : : into different builtin. */
1783 : 122631 : if (old_call != new_call)
1784 : : {
1785 : 121642 : cgraph_edge *e = node->get_edge (old_stmt);
1786 : 121642 : cgraph_edge *ne = NULL;
1787 : 121642 : profile_count count;
1788 : :
1789 : 121642 : if (e)
1790 : : {
1791 : : /* If call was devirtualized during cloning, mark edge
1792 : : as resolved. */
1793 : 100379 : if (e->speculative)
1794 : : {
1795 : 1 : if (new_stmt && is_gimple_call (new_stmt))
1796 : : {
1797 : 1 : tree decl = gimple_call_fndecl (new_stmt);
1798 : 1 : if (decl)
1799 : 1 : e = cgraph_edge::resolve_speculation (e, decl);
1800 : : }
1801 : : else
1802 : 0 : e = cgraph_edge::resolve_speculation (e, NULL);
1803 : : }
1804 : : /* Keep calls marked as dead dead. */
1805 : 100379 : if (new_stmt && is_gimple_call (new_stmt) && e->callee
1806 : 100952 : && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
1807 : : BUILT_IN_UNREACHABLE_TRAP))
1808 : : {
1809 : 5 : cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
1810 : : as_a <gcall *> (new_stmt));
1811 : 32 : return;
1812 : : }
1813 : : /* See if the edge is already there and has the correct callee. It
1814 : : might be so because of indirect inlining has already updated
1815 : : it. We also might've cloned and redirected the edge. */
1816 : 100374 : if (new_call && e->callee)
1817 : : {
1818 : : cgraph_node *callee = e->callee;
1819 : 1137 : while (callee)
1820 : : {
1821 : 591 : if (callee->decl == new_call
1822 : 591 : || callee->former_clone_of == new_call)
1823 : : {
1824 : 22 : cgraph_edge::set_call_stmt (e, as_a <gcall *> (new_stmt));
1825 : 22 : return;
1826 : : }
1827 : 569 : callee = callee->clone_of;
1828 : : }
1829 : : }
1830 : :
1831 : : /* Otherwise remove edge and create new one; we can't simply redirect
1832 : : since function has changed, so inline plan and other information
1833 : : attached to edge is invalid. */
1834 : 100352 : count = e->count;
1835 : 100352 : if (e->indirect_unknown_callee || e->inline_failed)
1836 : 100352 : cgraph_edge::remove (e);
1837 : : else
1838 : 0 : e->callee->remove_symbol_and_inline_clones ();
1839 : : }
1840 : 21263 : else if (new_call)
1841 : : {
1842 : : /* We are seeing new direct call; compute profile info based on BB. */
1843 : 4 : basic_block bb = gimple_bb (new_stmt);
1844 : 4 : count = bb->count;
1845 : : }
1846 : :
1847 : 100356 : if (new_call)
1848 : : {
1849 : 2326 : ne = node->create_edge (cgraph_node::get_create (new_call),
1850 : : as_a <gcall *> (new_stmt), count);
1851 : 2326 : gcc_assert (ne->inline_failed);
1852 : : }
1853 : : }
1854 : : /* We only updated the call stmt; update pointer in cgraph edge.. */
1855 : 989 : else if (old_stmt != new_stmt)
1856 : 0 : cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
1857 : : as_a <gcall *> (new_stmt));
1858 : : }
1859 : :
1860 : : /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
1861 : : OLD_STMT changed into NEW_STMT. OLD_DECL is gimple_call_fndecl
1862 : : of OLD_STMT before it was updated (updating can happen inplace). */
1863 : :
1864 : : void
1865 : 102886 : cgraph_update_edges_for_call_stmt (gimple *old_stmt, tree old_decl,
1866 : : gimple *new_stmt)
1867 : : {
1868 : 102886 : cgraph_node *orig = cgraph_node::get (cfun->decl);
1869 : 102886 : cgraph_node *node;
1870 : :
1871 : 102886 : gcc_checking_assert (orig);
1872 : 102886 : gcc_assert (!orig->thunk);
1873 : 102886 : cgraph_update_edges_for_call_stmt_node (orig, old_stmt, old_decl, new_stmt);
1874 : 102886 : if (orig->clones)
1875 : 42626 : for (node = orig->clones; node != orig;)
1876 : : {
1877 : : /* Do not attempt to adjust bodies of yet unexpanded thunks. */
1878 : 21635 : if (!node->thunk)
1879 : 21633 : cgraph_update_edges_for_call_stmt_node (node, old_stmt, old_decl,
1880 : : new_stmt);
1881 : 21635 : if (node->clones)
1882 : : node = node->clones;
1883 : 21623 : else if (node->next_sibling_clone)
1884 : : node = node->next_sibling_clone;
1885 : : else
1886 : : {
1887 : 41994 : while (node != orig && !node->next_sibling_clone)
1888 : 21003 : node = node->clone_of;
1889 : 20991 : if (node != orig)
1890 : 0 : node = node->next_sibling_clone;
1891 : : }
1892 : : }
1893 : 102886 : }
1894 : :
1895 : :
1896 : : /* Remove all callees from the node. */
1897 : :
1898 : : void
1899 : 212842371 : cgraph_node::remove_callees (void)
1900 : : {
1901 : 212842371 : cgraph_edge *e, *f;
1902 : :
1903 : 212842371 : calls_comdat_local = false;
1904 : :
1905 : : /* It is sufficient to remove the edges from the lists of callers of
1906 : : the callees. The callee list of the node can be zapped with one
1907 : : assignment. */
1908 : 252296273 : for (e = callees; e; e = f)
1909 : : {
1910 : 39453902 : f = e->next_callee;
1911 : 39453902 : symtab->call_edge_removal_hooks (e);
1912 : 39453902 : if (!e->indirect_unknown_callee)
1913 : 39453902 : e->remove_callee ();
1914 : 39453902 : symtab->free_edge (e);
1915 : : }
1916 : 213689080 : for (e = indirect_calls; e; e = f)
1917 : : {
1918 : 846709 : f = e->next_callee;
1919 : 846709 : symtab->call_edge_removal_hooks (e);
1920 : 846709 : if (!e->indirect_unknown_callee)
1921 : 0 : e->remove_callee ();
1922 : 846709 : symtab->free_edge (e);
1923 : : }
1924 : 212842371 : indirect_calls = NULL;
1925 : 212842371 : callees = NULL;
1926 : 212842371 : if (call_site_hash)
1927 : : {
1928 : 30104 : call_site_hash->empty ();
1929 : 30104 : call_site_hash = NULL;
1930 : : }
1931 : 212842371 : }
1932 : :
1933 : : /* Remove all callers from the node. */
1934 : :
1935 : : void
1936 : 94988234 : cgraph_node::remove_callers (void)
1937 : : {
1938 : 94988234 : cgraph_edge *e, *f;
1939 : :
1940 : : /* It is sufficient to remove the edges from the lists of callees of
1941 : : the callers. The caller list of the node can be zapped with one
1942 : : assignment. */
1943 : 99600731 : for (e = callers; e; e = f)
1944 : : {
1945 : 4612497 : f = e->next_caller;
1946 : 4612497 : symtab->call_edge_removal_hooks (e);
1947 : 4612497 : e->remove_caller ();
1948 : 4612497 : symtab->free_edge (e);
1949 : : }
1950 : 94988234 : callers = NULL;
1951 : 94988234 : }
1952 : :
1953 : : /* Helper function for cgraph_release_function_body and free_lang_data.
1954 : : It releases body from function DECL without having to inspect its
1955 : : possibly non-existent symtab node. */
1956 : :
1957 : : void
1958 : 105093072 : release_function_body (tree decl)
1959 : : {
1960 : 105093072 : function *fn = DECL_STRUCT_FUNCTION (decl);
1961 : 105093072 : if (fn)
1962 : : {
1963 : 93441202 : if (fn->cfg
1964 : 93441202 : && loops_for_fn (fn))
1965 : : {
1966 : 1769411 : fn->curr_properties &= ~PROP_loops;
1967 : 1769411 : loop_optimizer_finalize (fn);
1968 : : }
1969 : 93441202 : if (fn->gimple_df)
1970 : : {
1971 : 1778045 : delete_tree_ssa (fn);
1972 : 1778045 : fn->eh = NULL;
1973 : : }
1974 : 93441202 : if (fn->cfg)
1975 : : {
1976 : 1769412 : gcc_assert (!dom_info_available_p (fn, CDI_DOMINATORS));
1977 : 1769412 : gcc_assert (!dom_info_available_p (fn, CDI_POST_DOMINATORS));
1978 : 1769412 : delete_tree_cfg_annotations (fn);
1979 : 1769412 : free_cfg (fn);
1980 : 1769412 : fn->cfg = NULL;
1981 : : }
1982 : 93441202 : if (fn->value_histograms)
1983 : 12 : free_histograms (fn);
1984 : 93441202 : gimple_set_body (decl, NULL);
1985 : : /* Struct function hangs a lot of data that would leak if we didn't
1986 : : removed all pointers to it. */
1987 : 93441202 : ggc_free (fn);
1988 : 93441202 : DECL_STRUCT_FUNCTION (decl) = NULL;
1989 : : }
1990 : 105093072 : DECL_SAVED_TREE (decl) = NULL;
1991 : 105093072 : }
1992 : :
1993 : : /* Release memory used to represent body of function.
1994 : : Use this only for functions that are released before being translated to
1995 : : target code (i.e. RTL). Functions that are compiled to RTL and beyond
1996 : : are free'd in final.cc via free_after_compilation().
1997 : : KEEP_ARGUMENTS are useful only if you want to rebuild body as thunk. */
1998 : :
1999 : : void
2000 : 105081534 : cgraph_node::release_body (bool keep_arguments)
2001 : : {
2002 : 105081534 : ipa_transforms_to_apply.release ();
2003 : 105081534 : if (!used_as_abstract_origin && symtab->state != PARSING)
2004 : : {
2005 : 104474774 : DECL_RESULT (decl) = NULL;
2006 : :
2007 : 104474774 : if (!keep_arguments)
2008 : 104444115 : DECL_ARGUMENTS (decl) = NULL;
2009 : : }
2010 : : /* If the node is abstract and needed, then do not clear
2011 : : DECL_INITIAL of its associated function declaration because it's
2012 : : needed to emit debug info later. */
2013 : 105081534 : if (!used_as_abstract_origin && DECL_INITIAL (decl))
2014 : 92879171 : DECL_INITIAL (decl) = error_mark_node;
2015 : 105081534 : release_function_body (decl);
2016 : 105081534 : if (lto_file_data)
2017 : : {
2018 : 49090 : lto_free_function_in_decl_state_for_node (this);
2019 : 49090 : lto_file_data = NULL;
2020 : : }
2021 : 105081534 : if (flag_checking && clones)
2022 : : {
2023 : : /* It is invalid to release body before materializing clones except
2024 : : for thunks that don't really need a body. Verify also that we do
2025 : : not leak pointers to the call statements. */
2026 : 30 : for (cgraph_node *node = clones; node;
2027 : 18 : node = node->next_sibling_clone)
2028 : 18 : gcc_assert (node->thunk && !node->callees->call_stmt);
2029 : : }
2030 : 105081534 : remove_callees ();
2031 : 105081534 : remove_all_references ();
2032 : 105081534 : }
2033 : :
2034 : : /* Remove function from symbol table. */
2035 : :
2036 : : void
2037 : 94988234 : cgraph_node::remove (void)
2038 : : {
2039 : 94988234 : bool clone_info_set = false;
2040 : 94988234 : clone_info *info, saved_info;
2041 : 94988234 : if (symtab->ipa_clones_dump_file && symtab->cloned_nodes.contains (this))
2042 : 4 : fprintf (symtab->ipa_clones_dump_file,
2043 : : "Callgraph removal;%s;%d;%s;%d;%d\n", asm_name (), get_uid (),
2044 : 4 : DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
2045 : 8 : DECL_SOURCE_COLUMN (decl));
2046 : :
2047 : 94988234 : if ((info = clone_info::get (this)) != NULL)
2048 : : {
2049 : 394956 : saved_info = *info;
2050 : 394956 : clone_info_set = true;
2051 : : }
2052 : 94988234 : symtab->call_cgraph_removal_hooks (this);
2053 : 94988234 : remove_callers ();
2054 : 94988234 : remove_callees ();
2055 : 94988234 : ipa_transforms_to_apply.release ();
2056 : 94988234 : delete_function_version (function_version ());
2057 : :
2058 : : /* Incremental inlining access removed nodes stored in the postorder list.
2059 : : */
2060 : 94988234 : force_output = false;
2061 : 94988234 : forced_by_abi = false;
2062 : :
2063 : 189581512 : unregister (clone_info_set ? &saved_info : NULL);
2064 : 94988234 : if (prev_sibling_clone)
2065 : 771871 : prev_sibling_clone->next_sibling_clone = next_sibling_clone;
2066 : 94216363 : else if (clone_of)
2067 : : {
2068 : 1841764 : clone_of->clones = next_sibling_clone;
2069 : 1841764 : if (!clones)
2070 : : {
2071 : 1838678 : bool need_body = false;
2072 : 1838678 : for (cgraph_node *n = clone_of; n; n = n->clone_of)
2073 : 1833174 : if (n->analyzed || n->clones)
2074 : : {
2075 : : need_body = true;
2076 : : break;
2077 : : }
2078 : 1833170 : if (!need_body)
2079 : 5504 : clone_of->release_body ();
2080 : : }
2081 : : }
2082 : 94988234 : if (next_sibling_clone)
2083 : 988555 : next_sibling_clone->prev_sibling_clone = prev_sibling_clone;
2084 : 94988234 : if (clones)
2085 : : {
2086 : 38086 : cgraph_node *n, *next;
2087 : :
2088 : 38086 : if (clone_of)
2089 : : {
2090 : 198051 : for (n = clones; n->next_sibling_clone; n = n->next_sibling_clone)
2091 : 159965 : n->clone_of = clone_of;
2092 : 38086 : n->clone_of = clone_of;
2093 : 38086 : n->next_sibling_clone = clone_of->clones;
2094 : 38086 : if (clone_of->clones)
2095 : 33298 : clone_of->clones->prev_sibling_clone = n;
2096 : 38086 : clone_of->clones = clones;
2097 : : }
2098 : : else
2099 : : {
2100 : : /* We are removing node with clones. This makes clones inconsistent,
2101 : : but assume they will be removed subsequently and just keep clone
2102 : : tree intact. This can happen in unreachable function removal since
2103 : : we remove unreachable functions in random order, not by bottom-up
2104 : : walk of clone trees. */
2105 : 0 : for (n = clones; n; n = next)
2106 : : {
2107 : 0 : next = n->next_sibling_clone;
2108 : 0 : n->next_sibling_clone = NULL;
2109 : 0 : n->prev_sibling_clone = NULL;
2110 : 0 : n->clone_of = NULL;
2111 : : }
2112 : : }
2113 : : }
2114 : :
2115 : : /* While all the clones are removed after being proceeded, the function
2116 : : itself is kept in the cgraph even after it is compiled. Check whether
2117 : : we are done with this body and reclaim it proactively if this is the case.
2118 : : */
2119 : 94988234 : if (symtab->state != LTO_STREAMING)
2120 : : {
2121 : 94986193 : cgraph_node *n = cgraph_node::get (decl);
2122 : 94986193 : if (!n
2123 : 94986193 : || (!n->clones && !n->clone_of && !n->inlined_to
2124 : 1161787 : && ((symtab->global_info_ready || in_lto_p)
2125 : 9962 : && (TREE_ASM_WRITTEN (n->decl)
2126 : 9943 : || DECL_EXTERNAL (n->decl)
2127 : 5248 : || !n->analyzed
2128 : 5184 : || (!flag_wpa && n->in_other_partition)))))
2129 : 91945435 : release_body ();
2130 : : }
2131 : : else
2132 : : {
2133 : 2041 : lto_free_function_in_decl_state_for_node (this);
2134 : 2041 : lto_file_data = NULL;
2135 : : }
2136 : :
2137 : 94988234 : decl = NULL;
2138 : 94988234 : if (call_site_hash)
2139 : : {
2140 : 0 : call_site_hash->empty ();
2141 : 0 : call_site_hash = NULL;
2142 : : }
2143 : :
2144 : 94988234 : symtab->release_symbol (this);
2145 : 94988234 : }
2146 : :
2147 : : /* Likewise indicate that a node is having address taken. */
2148 : :
2149 : : void
2150 : 4838847 : cgraph_node::mark_address_taken (void)
2151 : : {
2152 : : /* Indirect inlining can figure out that all uses of the address are
2153 : : inlined. */
2154 : 4838847 : if (inlined_to)
2155 : : {
2156 : 0 : gcc_assert (cfun->after_inlining);
2157 : 0 : gcc_assert (callers->indirect_inlining_edge);
2158 : : return;
2159 : : }
2160 : : /* FIXME: address_taken flag is used both as a shortcut for testing whether
2161 : : IPA_REF_ADDR reference exists (and thus it should be set on node
2162 : : representing alias we take address of) and as a test whether address
2163 : : of the object was taken (and thus it should be set on node alias is
2164 : : referring to). We should remove the first use and the remove the
2165 : : following set. */
2166 : 4838847 : address_taken = 1;
2167 : 4838847 : cgraph_node *node = ultimate_alias_target ();
2168 : 4838847 : node->address_taken = 1;
2169 : : }
2170 : :
2171 : : /* Return local info node for the compiled function. */
2172 : :
2173 : : cgraph_node *
2174 : 12759123 : cgraph_node::local_info_node (tree decl)
2175 : : {
2176 : 12759123 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
2177 : 12759123 : cgraph_node *node = get (decl);
2178 : 12759123 : if (!node)
2179 : : return NULL;
2180 : 12759123 : return node->ultimate_alias_target ();
2181 : : }
2182 : :
2183 : : /* Return RTL info for the compiled function. */
2184 : :
2185 : : cgraph_rtl_info *
2186 : 59634691 : cgraph_node::rtl_info (const_tree decl)
2187 : : {
2188 : 59634691 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
2189 : 59634691 : cgraph_node *node = get (decl);
2190 : 59634691 : if (!node)
2191 : : return NULL;
2192 : 59491353 : enum availability avail;
2193 : 59491353 : node = node->ultimate_alias_target (&avail);
2194 : 59491353 : if (decl != current_function_decl
2195 : 56493989 : && (avail < AVAIL_AVAILABLE
2196 : 51325564 : || (node->decl != current_function_decl
2197 : 51252468 : && !TREE_ASM_WRITTEN (node->decl))))
2198 : : return NULL;
2199 : : /* Allocate if it doesn't exist. */
2200 : 50778512 : if (node->rtl == NULL)
2201 : : {
2202 : 1354347 : node->rtl = ggc_cleared_alloc<cgraph_rtl_info> ();
2203 : 1354347 : SET_HARD_REG_SET (node->rtl->function_used_regs);
2204 : : }
2205 : 50778512 : return node->rtl;
2206 : : }
2207 : :
2208 : : /* Return a string describing the failure REASON. */
2209 : :
2210 : : const char*
2211 : 9723 : cgraph_inline_failed_string (cgraph_inline_failed_t reason)
2212 : : {
2213 : : #undef DEFCIFCODE
2214 : : #define DEFCIFCODE(code, type, string) string,
2215 : :
2216 : 9723 : static const char *cif_string_table[CIF_N_REASONS] = {
2217 : : #include "cif-code.def"
2218 : : };
2219 : :
2220 : : /* Signedness of an enum type is implementation defined, so cast it
2221 : : to unsigned before testing. */
2222 : 9723 : gcc_assert ((unsigned) reason < CIF_N_REASONS);
2223 : 9723 : return cif_string_table[reason];
2224 : : }
2225 : :
2226 : : /* Return a type describing the failure REASON. */
2227 : :
2228 : : cgraph_inline_failed_type_t
2229 : 73889422 : cgraph_inline_failed_type (cgraph_inline_failed_t reason)
2230 : : {
2231 : : #undef DEFCIFCODE
2232 : : #define DEFCIFCODE(code, type, string) type,
2233 : :
2234 : 73889422 : static cgraph_inline_failed_type_t cif_type_table[CIF_N_REASONS] = {
2235 : : #include "cif-code.def"
2236 : : };
2237 : :
2238 : : /* Signedness of an enum type is implementation defined, so cast it
2239 : : to unsigned before testing. */
2240 : 73889422 : gcc_assert ((unsigned) reason < CIF_N_REASONS);
2241 : 73889422 : return cif_type_table[reason];
2242 : : }
2243 : :
2244 : : /* Names used to print out the availability enum. */
2245 : : const char * const cgraph_availability_names[] =
2246 : : {"unset", "not_available", "overwritable", "available", "local"};
2247 : :
2248 : : /* Output flags of edge to a file F. */
2249 : :
2250 : : void
2251 : 22481 : cgraph_edge::dump_edge_flags (FILE *f)
2252 : : {
2253 : 22481 : if (speculative)
2254 : 141 : fprintf (f, "(speculative) ");
2255 : 22481 : if (!inline_failed)
2256 : 1660 : fprintf (f, "(inlined) ");
2257 : 22481 : if (call_stmt_cannot_inline_p)
2258 : 0 : fprintf (f, "(call_stmt_cannot_inline_p) ");
2259 : 22481 : if (indirect_inlining_edge)
2260 : 325 : fprintf (f, "(indirect_inlining) ");
2261 : 22481 : if (count.initialized_p ())
2262 : : {
2263 : 21722 : fprintf (f, "(");
2264 : 21722 : count.dump (f);
2265 : 21722 : fprintf (f, ",");
2266 : 21722 : fprintf (f, "%.2f per call) ", sreal_frequency ().to_double ());
2267 : : }
2268 : 22481 : if (can_throw_external)
2269 : 2744 : fprintf (f, "(can throw external) ");
2270 : 22481 : }
2271 : :
2272 : : /* Dump edge to stderr. */
2273 : :
2274 : : void
2275 : 0 : cgraph_edge::debug (void)
2276 : : {
2277 : 0 : fprintf (stderr, "%s -> %s ", caller->dump_asm_name (),
2278 : 0 : callee == NULL ? "(null)" : callee->dump_asm_name ());
2279 : 0 : dump_edge_flags (stderr);
2280 : 0 : fprintf (stderr, "\n\n");
2281 : 0 : caller->debug ();
2282 : 0 : if (callee != NULL)
2283 : 0 : callee->debug ();
2284 : 0 : }
2285 : :
2286 : : /* Dump call graph node to file F. */
2287 : :
2288 : : void
2289 : 5760 : cgraph_node::dump (FILE *f)
2290 : : {
2291 : 5760 : cgraph_edge *edge;
2292 : :
2293 : 5760 : dump_base (f);
2294 : :
2295 : 5760 : if (inlined_to)
2296 : 716 : fprintf (f, " Function %s is inline copy in %s\n",
2297 : : dump_name (),
2298 : : inlined_to->dump_name ());
2299 : 5760 : if (clone_of)
2300 : 697 : fprintf (f, " Clone of %s\n", clone_of->dump_asm_name ());
2301 : 5760 : if (symtab->function_flags_ready)
2302 : 10384 : fprintf (f, " Availability: %s\n",
2303 : 5192 : cgraph_availability_names [get_availability ()]);
2304 : :
2305 : 5760 : if (profile_id)
2306 : 155 : fprintf (f, " Profile id: %i\n",
2307 : : profile_id);
2308 : 5760 : if (unit_id)
2309 : 134 : fprintf (f, " Unit id: %i\n",
2310 : : unit_id);
2311 : 5760 : cgraph_function_version_info *vi = function_version ();
2312 : 5760 : if (vi != NULL)
2313 : : {
2314 : 0 : fprintf (f, " Version info: ");
2315 : 0 : if (vi->prev != NULL)
2316 : : {
2317 : 0 : fprintf (f, "prev: ");
2318 : 0 : fprintf (f, "%s ", vi->prev->this_node->dump_asm_name ());
2319 : : }
2320 : 0 : if (vi->next != NULL)
2321 : : {
2322 : 0 : fprintf (f, "next: ");
2323 : 0 : fprintf (f, "%s ", vi->next->this_node->dump_asm_name ());
2324 : : }
2325 : 0 : if (vi->dispatcher_resolver != NULL_TREE)
2326 : 0 : fprintf (f, "dispatcher: %s",
2327 : 0 : lang_hooks.decl_printable_name (vi->dispatcher_resolver, 2));
2328 : :
2329 : 0 : fprintf (f, "\n");
2330 : : }
2331 : 5760 : fprintf (f, " Function flags:");
2332 : 5760 : if (count.initialized_p ())
2333 : : {
2334 : 3533 : fprintf (f, " count:");
2335 : 3533 : count.dump (f);
2336 : : }
2337 : 5760 : if (tp_first_run > 0)
2338 : 70 : fprintf (f, " first_run:%" PRId64, (int64_t) tp_first_run);
2339 : 5760 : if (cgraph_node *origin = nested_function_origin (this))
2340 : 0 : fprintf (f, " nested in:%s", origin->dump_asm_name ());
2341 : 5760 : if (gimple_has_body_p (decl))
2342 : 3778 : fprintf (f, " body");
2343 : 5760 : if (process)
2344 : 0 : fprintf (f, " process");
2345 : 5760 : if (local)
2346 : 1068 : fprintf (f, " local");
2347 : 5760 : if (redefined_extern_inline)
2348 : 0 : fprintf (f, " redefined_extern_inline");
2349 : 5760 : if (only_called_at_startup)
2350 : 397 : fprintf (f, " only_called_at_startup");
2351 : 5760 : if (only_called_at_exit)
2352 : 7 : fprintf (f, " only_called_at_exit");
2353 : 5760 : if (tm_clone)
2354 : 0 : fprintf (f, " tm_clone");
2355 : 5760 : if (calls_comdat_local)
2356 : 9 : fprintf (f, " calls_comdat_local");
2357 : 5760 : if (icf_merged)
2358 : 24 : fprintf (f, " icf_merged");
2359 : 5760 : if (merged_comdat)
2360 : 0 : fprintf (f, " merged_comdat");
2361 : 5760 : if (merged_extern_inline)
2362 : 0 : fprintf (f, " merged_extern_inline");
2363 : 5760 : if (split_part)
2364 : 23 : fprintf (f, " split_part");
2365 : 5760 : if (indirect_call_target)
2366 : 218 : fprintf (f, " indirect_call_target");
2367 : 5760 : if (nonfreeing_fn)
2368 : 337 : fprintf (f, " nonfreeing_fn");
2369 : 5760 : if (DECL_STATIC_CONSTRUCTOR (decl))
2370 : 48 : fprintf (f," static_constructor (priority:%i)", get_init_priority ());
2371 : 5760 : if (DECL_STATIC_DESTRUCTOR (decl))
2372 : 7 : fprintf (f," static_destructor (priority:%i)", get_fini_priority ());
2373 : 5760 : if (frequency == NODE_FREQUENCY_HOT)
2374 : 62 : fprintf (f, " hot");
2375 : 5760 : if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
2376 : 40 : fprintf (f, " unlikely_executed");
2377 : 5760 : if (frequency == NODE_FREQUENCY_EXECUTED_ONCE)
2378 : 690 : fprintf (f, " executed_once");
2379 : 5760 : if (opt_for_fn (decl, optimize_size))
2380 : 176 : fprintf (f, " optimize_size");
2381 : 5760 : if (parallelized_function)
2382 : 0 : fprintf (f, " parallelized_function");
2383 : 5760 : if (DECL_IS_MALLOC (decl))
2384 : 72 : fprintf (f, " decl_is_malloc");
2385 : 5760 : if (DECL_IS_OPERATOR_NEW_P (decl))
2386 : 35 : fprintf (f, " %soperator_new",
2387 : 35 : DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
2388 : 5760 : if (DECL_IS_OPERATOR_DELETE_P (decl))
2389 : 26 : fprintf (f, " %soperator_delete",
2390 : 26 : DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
2391 : :
2392 : 5760 : if (DECL_STATIC_CHAIN (decl))
2393 : 6 : fprintf (f, " static_chain");
2394 : :
2395 : 5760 : fprintf (f, "\n");
2396 : :
2397 : 5760 : if (thunk)
2398 : : {
2399 : 43 : fprintf (f, " Thunk");
2400 : 43 : thunk_info::get (this)->dump (f);
2401 : : }
2402 : 5717 : else if (former_thunk_p ())
2403 : : {
2404 : 27 : fprintf (f, " Former thunk ");
2405 : 27 : thunk_info::get (this)->dump (f);
2406 : : }
2407 : 5690 : else gcc_checking_assert (!thunk_info::get (this));
2408 : :
2409 : 5760 : fprintf (f, " Called by: ");
2410 : :
2411 : 5760 : profile_count sum = profile_count::zero ();
2412 : 13396 : for (edge = callers; edge; edge = edge->next_caller)
2413 : : {
2414 : 7636 : fprintf (f, "%s ", edge->caller->dump_asm_name ());
2415 : 7636 : edge->dump_edge_flags (f);
2416 : 7636 : if (edge->count.initialized_p ())
2417 : 7376 : sum += edge->count.ipa ();
2418 : : }
2419 : :
2420 : 5760 : fprintf (f, "\n Calls: ");
2421 : 19850 : for (edge = callees; edge; edge = edge->next_callee)
2422 : : {
2423 : 14090 : fprintf (f, "%s ", edge->callee->dump_asm_name ());
2424 : 14090 : edge->dump_edge_flags (f);
2425 : : }
2426 : 5760 : fprintf (f, "\n");
2427 : :
2428 : 5760 : if (!body_removed && count.ipa ().initialized_p ())
2429 : : {
2430 : 110 : bool ok = true;
2431 : 110 : bool min = false;
2432 : : ipa_ref *ref;
2433 : :
2434 : 110 : FOR_EACH_ALIAS (this, ref)
2435 : 0 : if (dyn_cast <cgraph_node *> (ref->referring)->count.initialized_p ())
2436 : 0 : sum += dyn_cast <cgraph_node *> (ref->referring)->count.ipa ();
2437 : :
2438 : 110 : if (inlined_to
2439 : 110 : || (symtab->state < EXPANSION
2440 : 110 : && ultimate_alias_target () == this && only_called_directly_p ()))
2441 : 3 : ok = !count.ipa ().differs_from_p (sum);
2442 : 107 : else if (count.ipa () > profile_count::from_gcov_type (100)
2443 : 107 : && count.ipa () < sum.apply_scale (99, 100))
2444 : 0 : ok = false, min = true;
2445 : 110 : if (!ok)
2446 : : {
2447 : 0 : fprintf (f, " Invalid sum of caller counts ");
2448 : 0 : sum.dump (f);
2449 : 0 : if (min)
2450 : 0 : fprintf (f, ", should be at most ");
2451 : : else
2452 : 0 : fprintf (f, ", should be ");
2453 : 0 : count.ipa ().dump (f);
2454 : 0 : fprintf (f, "\n");
2455 : : }
2456 : : }
2457 : :
2458 : 6515 : for (edge = indirect_calls; edge; edge = edge->next_callee)
2459 : : {
2460 : 755 : if (edge->indirect_info->polymorphic)
2461 : : {
2462 : 281 : fprintf (f, " Polymorphic indirect call of type ");
2463 : 281 : print_generic_expr (f, edge->indirect_info->otr_type, TDF_SLIM);
2464 : 281 : fprintf (f, " token:%i", (int) edge->indirect_info->otr_token);
2465 : : }
2466 : : else
2467 : 474 : fprintf (f, " Indirect call");
2468 : 755 : edge->dump_edge_flags (f);
2469 : 755 : if (edge->indirect_info->param_index != -1)
2470 : : {
2471 : 205 : fprintf (f, "of param:%i ", edge->indirect_info->param_index);
2472 : 205 : if (edge->indirect_info->agg_contents)
2473 : 19 : fprintf (f, "loaded from %s %s at offset %i ",
2474 : 19 : edge->indirect_info->member_ptr ? "member ptr" : "aggregate",
2475 : 19 : edge->indirect_info->by_ref ? "passed by reference" : "",
2476 : 19 : (int)edge->indirect_info->offset);
2477 : 205 : if (edge->indirect_info->vptr_changed)
2478 : 23 : fprintf (f, "(vptr maybe changed) ");
2479 : : }
2480 : 755 : fprintf (f, "num speculative call targets: %i\n",
2481 : 755 : edge->indirect_info->num_speculative_call_targets);
2482 : 755 : if (edge->indirect_info->polymorphic)
2483 : 281 : edge->indirect_info->context.dump (f);
2484 : : }
2485 : 5760 : }
2486 : :
2487 : : /* Dump call graph node to file F in graphviz format. */
2488 : :
2489 : : void
2490 : 0 : cgraph_node::dump_graphviz (FILE *f)
2491 : : {
2492 : 0 : cgraph_edge *edge;
2493 : :
2494 : 0 : for (edge = callees; edge; edge = edge->next_callee)
2495 : : {
2496 : 0 : cgraph_node *callee = edge->callee;
2497 : :
2498 : 0 : fprintf (f, "\t\"%s\" -> \"%s\"\n", dump_name (), callee->dump_name ());
2499 : : }
2500 : 0 : }
2501 : :
2502 : :
2503 : : /* Dump call graph node NODE to stderr. */
2504 : :
2505 : : DEBUG_FUNCTION void
2506 : 0 : cgraph_node::debug (void)
2507 : : {
2508 : 0 : dump (stderr);
2509 : 0 : }
2510 : :
2511 : : /* Dump the callgraph to file F. */
2512 : :
2513 : : void
2514 : 77 : cgraph_node::dump_cgraph (FILE *f)
2515 : : {
2516 : 77 : cgraph_node *node;
2517 : :
2518 : 77 : fprintf (f, "callgraph:\n\n");
2519 : 724 : FOR_EACH_FUNCTION (node)
2520 : 285 : node->dump (f);
2521 : 77 : }
2522 : :
2523 : : /* Return true when the DECL can possibly be inlined. */
2524 : :
2525 : : bool
2526 : 86018549 : cgraph_function_possibly_inlined_p (tree decl)
2527 : : {
2528 : 86018549 : if (!symtab->global_info_ready)
2529 : 78242684 : return !DECL_UNINLINABLE (decl);
2530 : 7775865 : return DECL_POSSIBLY_INLINED (decl);
2531 : : }
2532 : :
2533 : : /* Return function availability. See cgraph.h for description of individual
2534 : : return values. */
2535 : : enum availability
2536 : 806905076 : cgraph_node::get_availability (symtab_node *ref)
2537 : : {
2538 : 806905076 : if (ref)
2539 : : {
2540 : 570171234 : cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
2541 : 570171234 : if (cref)
2542 : 570171234 : ref = cref->inlined_to;
2543 : : }
2544 : 806905076 : enum availability avail;
2545 : 806905076 : if (!analyzed && !in_other_partition)
2546 : 479889640 : avail = AVAIL_NOT_AVAILABLE;
2547 : 327015436 : else if (local)
2548 : 92449857 : avail = AVAIL_LOCAL;
2549 : 234565579 : else if (inlined_to)
2550 : 2258297 : avail = AVAIL_AVAILABLE;
2551 : 232307282 : else if (transparent_alias)
2552 : 134 : ultimate_alias_target (&avail, ref);
2553 : 232307148 : else if (ifunc_resolver
2554 : 232307148 : || lookup_attribute ("noipa", DECL_ATTRIBUTES (decl)))
2555 : 3396714 : avail = AVAIL_INTERPOSABLE;
2556 : 228910434 : else if (!externally_visible)
2557 : 30199869 : avail = AVAIL_AVAILABLE;
2558 : : /* If this is a reference from symbol itself and there are no aliases, we
2559 : : may be sure that the symbol was not interposed by something else because
2560 : : the symbol itself would be unreachable otherwise.
2561 : :
2562 : : Also comdat groups are always resolved in groups. */
2563 : 34388 : else if ((this == ref && !has_aliases_p ())
2564 : 198711280 : || (ref && get_comdat_group ()
2565 : 1455335 : && get_comdat_group () == ref->get_comdat_group ()))
2566 : 35992 : avail = AVAIL_AVAILABLE;
2567 : : /* Inline functions are safe to be analyzed even if their symbol can
2568 : : be overwritten at runtime. It is not meaningful to enforce any sane
2569 : : behavior on replacing inline function by different body. */
2570 : 198674573 : else if (DECL_DECLARED_INLINE_P (decl))
2571 : 68461258 : avail = AVAIL_AVAILABLE;
2572 : :
2573 : : /* If the function can be overwritten, return OVERWRITABLE. Take
2574 : : care at least of two notable extensions - the COMDAT functions
2575 : : used to share template instantiations in C++ (this is symmetric
2576 : : to code cp_cannot_inline_tree_fn and probably shall be shared and
2577 : : the inlinability hooks completely eliminated). */
2578 : :
2579 : 130213315 : else if (decl_replaceable_p (decl, semantic_interposition)
2580 : 130213315 : && !DECL_EXTERNAL (decl))
2581 : 9307587 : avail = AVAIL_INTERPOSABLE;
2582 : 120905728 : else avail = AVAIL_AVAILABLE;
2583 : :
2584 : 806905076 : return avail;
2585 : : }
2586 : :
2587 : : /* Worker for cgraph_node_can_be_local_p. */
2588 : : static bool
2589 : 868277 : cgraph_node_cannot_be_local_p_1 (cgraph_node *node, void *)
2590 : : {
2591 : 868277 : return !(!node->force_output
2592 : 847540 : && !node->ifunc_resolver
2593 : : /* Limitation of gas requires us to output targets of symver aliases
2594 : : as global symbols. This is binutils PR 25295. */
2595 : 847500 : && !node->symver
2596 : 847500 : && ((DECL_COMDAT (node->decl)
2597 : 368317 : && !node->forced_by_abi
2598 : 345914 : && !node->used_from_object_file_p ()
2599 : 345914 : && !node->same_comdat_group)
2600 : 552233 : || !node->externally_visible)
2601 : 440541 : && !DECL_STATIC_CONSTRUCTOR (node->decl)
2602 : 438793 : && !DECL_STATIC_DESTRUCTOR (node->decl));
2603 : : }
2604 : :
2605 : : /* Return true if cgraph_node can be made local for API change.
2606 : : Extern inline functions and C++ COMDAT functions can be made local
2607 : : at the expense of possible code size growth if function is used in multiple
2608 : : compilation units. */
2609 : : bool
2610 : 1175405 : cgraph_node::can_be_local_p (void)
2611 : : {
2612 : 1175405 : return (!address_taken
2613 : 1175405 : && !call_for_symbol_thunks_and_aliases (cgraph_node_cannot_be_local_p_1,
2614 : 1175405 : NULL, true));
2615 : : }
2616 : :
2617 : : /* Call callback on cgraph_node, thunks and aliases associated to cgraph_node.
2618 : : When INCLUDE_OVERWRITABLE is false, overwritable symbols are
2619 : : skipped. When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
2620 : : skipped. */
2621 : : bool
2622 : 126769253 : cgraph_node::call_for_symbol_thunks_and_aliases (bool (*callback)
2623 : : (cgraph_node *, void *),
2624 : : void *data,
2625 : : bool include_overwritable,
2626 : : bool exclude_virtual_thunks)
2627 : : {
2628 : 126769253 : cgraph_edge *e;
2629 : 126769253 : ipa_ref *ref;
2630 : 126769253 : enum availability avail = AVAIL_AVAILABLE;
2631 : :
2632 : 126769253 : if (include_overwritable
2633 : 126769253 : || (avail = get_availability ()) > AVAIL_INTERPOSABLE)
2634 : : {
2635 : 126757726 : if (callback (this, data))
2636 : : return true;
2637 : : }
2638 : 133806670 : FOR_EACH_ALIAS (this, ref)
2639 : : {
2640 : 12464838 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
2641 : 12464838 : if (include_overwritable
2642 : 12464838 : || alias->get_availability () > AVAIL_INTERPOSABLE)
2643 : 12464596 : if (alias->call_for_symbol_thunks_and_aliases (callback, data,
2644 : : include_overwritable,
2645 : : exclude_virtual_thunks))
2646 : : return true;
2647 : : }
2648 : 121341832 : if (avail <= AVAIL_INTERPOSABLE)
2649 : : return false;
2650 : 126946374 : for (e = callers; e; e = e->next_caller)
2651 : 5616069 : if (e->caller->thunk
2652 : 2768 : && (include_overwritable
2653 : 414 : || e->caller->get_availability () > AVAIL_INTERPOSABLE)
2654 : 5618837 : && !(exclude_virtual_thunks
2655 : 22 : && thunk_info::get (e->caller)->virtual_offset_p))
2656 : 2756 : if (e->caller->call_for_symbol_thunks_and_aliases (callback, data,
2657 : : include_overwritable,
2658 : : exclude_virtual_thunks))
2659 : : return true;
2660 : :
2661 : : return false;
2662 : : }
2663 : :
2664 : : /* Worker to bring NODE local. */
2665 : :
2666 : : bool
2667 : 0 : cgraph_node::make_local (cgraph_node *node, void *)
2668 : : {
2669 : 0 : gcc_checking_assert (node->can_be_local_p ());
2670 : 0 : if (DECL_COMDAT (node->decl) || DECL_EXTERNAL (node->decl))
2671 : : {
2672 : 0 : node->make_decl_local ();
2673 : 0 : node->set_section (NULL);
2674 : 0 : node->set_comdat_group (NULL);
2675 : 0 : node->externally_visible = false;
2676 : 0 : node->forced_by_abi = false;
2677 : 0 : node->local = true;
2678 : 0 : node->unique_name = ((node->resolution == LDPR_PREVAILING_DEF_IRONLY
2679 : 0 : || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
2680 : 0 : && !flag_incremental_link);
2681 : 0 : node->resolution = LDPR_PREVAILING_DEF_IRONLY;
2682 : 0 : gcc_assert (node->get_availability () == AVAIL_LOCAL);
2683 : : }
2684 : 0 : return false;
2685 : : }
2686 : :
2687 : : /* Bring cgraph node local. */
2688 : :
2689 : : void
2690 : 0 : cgraph_node::make_local (void)
2691 : : {
2692 : 0 : call_for_symbol_thunks_and_aliases (cgraph_node::make_local, NULL, true);
2693 : 0 : }
2694 : :
2695 : : /* Worker to set nothrow flag. */
2696 : :
2697 : : static void
2698 : 936903 : set_nothrow_flag_1 (cgraph_node *node, bool nothrow, bool non_call,
2699 : : bool *changed)
2700 : : {
2701 : 936903 : cgraph_edge *e;
2702 : :
2703 : 936903 : if (nothrow && !TREE_NOTHROW (node->decl))
2704 : : {
2705 : : /* With non-call exceptions we can't say for sure if other function body
2706 : : was not possibly optimized to still throw. */
2707 : 936878 : if (!non_call || node->binds_to_current_def_p ())
2708 : : {
2709 : 931156 : TREE_NOTHROW (node->decl) = true;
2710 : 931156 : *changed = true;
2711 : 2292348 : for (e = node->callers; e; e = e->next_caller)
2712 : 1361192 : e->can_throw_external = false;
2713 : : }
2714 : : }
2715 : 0 : else if (!nothrow && TREE_NOTHROW (node->decl))
2716 : : {
2717 : 0 : TREE_NOTHROW (node->decl) = false;
2718 : 0 : *changed = true;
2719 : : }
2720 : : ipa_ref *ref;
2721 : 992859 : FOR_EACH_ALIAS (node, ref)
2722 : : {
2723 : 55956 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
2724 : 55956 : if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
2725 : 55531 : set_nothrow_flag_1 (alias, nothrow, non_call, changed);
2726 : : }
2727 : 2335539 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
2728 : 1398636 : if (e->caller->thunk
2729 : 1398636 : && (!nothrow || e->caller->get_availability () > AVAIL_INTERPOSABLE))
2730 : 135 : set_nothrow_flag_1 (e->caller, nothrow, non_call, changed);
2731 : 936903 : }
2732 : :
2733 : : /* Set TREE_NOTHROW on NODE's decl and on aliases of NODE
2734 : : if any to NOTHROW. */
2735 : :
2736 : : bool
2737 : 893135 : cgraph_node::set_nothrow_flag (bool nothrow)
2738 : : {
2739 : 893135 : bool changed = false;
2740 : 893135 : bool non_call = opt_for_fn (decl, flag_non_call_exceptions);
2741 : :
2742 : 893135 : if (!nothrow || get_availability () > AVAIL_INTERPOSABLE)
2743 : 881130 : set_nothrow_flag_1 (this, nothrow, non_call, &changed);
2744 : : else
2745 : : {
2746 : : ipa_ref *ref;
2747 : :
2748 : 19336 : FOR_EACH_ALIAS (this, ref)
2749 : : {
2750 : 7331 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
2751 : 7331 : if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
2752 : 107 : set_nothrow_flag_1 (alias, nothrow, non_call, &changed);
2753 : : }
2754 : : }
2755 : 893135 : return changed;
2756 : : }
2757 : :
2758 : : /* Worker to set malloc flag. */
2759 : : static void
2760 : 24092 : set_malloc_flag_1 (cgraph_node *node, bool malloc_p, bool *changed)
2761 : : {
2762 : 24092 : if (malloc_p && !DECL_IS_MALLOC (node->decl))
2763 : : {
2764 : 23666 : DECL_IS_MALLOC (node->decl) = true;
2765 : 23666 : *changed = true;
2766 : : }
2767 : :
2768 : : ipa_ref *ref;
2769 : 24093 : FOR_EACH_ALIAS (node, ref)
2770 : : {
2771 : 1 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
2772 : 1 : if (!malloc_p || alias->get_availability () > AVAIL_INTERPOSABLE)
2773 : 1 : set_malloc_flag_1 (alias, malloc_p, changed);
2774 : : }
2775 : :
2776 : 53213 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
2777 : 29121 : if (e->caller->thunk
2778 : 29121 : && (!malloc_p || e->caller->get_availability () > AVAIL_INTERPOSABLE))
2779 : 0 : set_malloc_flag_1 (e->caller, malloc_p, changed);
2780 : 24092 : }
2781 : :
2782 : : /* Set DECL_IS_MALLOC on NODE's decl and on NODE's aliases if any. */
2783 : :
2784 : : bool
2785 : 24091 : cgraph_node::set_malloc_flag (bool malloc_p)
2786 : : {
2787 : 24091 : bool changed = false;
2788 : :
2789 : 24091 : if (!malloc_p || get_availability () > AVAIL_INTERPOSABLE)
2790 : 24091 : set_malloc_flag_1 (this, malloc_p, &changed);
2791 : : else
2792 : : {
2793 : : ipa_ref *ref;
2794 : :
2795 : 0 : FOR_EACH_ALIAS (this, ref)
2796 : : {
2797 : 0 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
2798 : 0 : if (!malloc_p || alias->get_availability () > AVAIL_INTERPOSABLE)
2799 : 0 : set_malloc_flag_1 (alias, malloc_p, &changed);
2800 : : }
2801 : : }
2802 : 24091 : return changed;
2803 : : }
2804 : :
2805 : : /* Worker to set malloc flag. */
2806 : : static void
2807 : 239055 : add_detected_attribute_1 (cgraph_node *node, const char *attr, bool *changed)
2808 : : {
2809 : 239055 : if (!lookup_attribute (attr, DECL_ATTRIBUTES (node->decl)))
2810 : : {
2811 : 212504 : DECL_ATTRIBUTES (node->decl) = tree_cons (get_identifier (attr),
2812 : 212504 : NULL_TREE, DECL_ATTRIBUTES (node->decl));
2813 : 212504 : *changed = true;
2814 : : }
2815 : :
2816 : : ipa_ref *ref;
2817 : 239532 : FOR_EACH_ALIAS (node, ref)
2818 : : {
2819 : 477 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
2820 : 477 : if (alias->get_availability () > AVAIL_INTERPOSABLE)
2821 : 68 : add_detected_attribute_1 (alias, attr, changed);
2822 : : }
2823 : :
2824 : 767974 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
2825 : 528919 : if (e->caller->thunk
2826 : 528919 : && (e->caller->get_availability () > AVAIL_INTERPOSABLE))
2827 : 14 : add_detected_attribute_1 (e->caller, attr, changed);
2828 : 239055 : }
2829 : :
2830 : : /* Add attribyte ATTR to function and its aliases. */
2831 : :
2832 : : bool
2833 : 242733 : cgraph_node::add_detected_attribute (const char *attr)
2834 : : {
2835 : 242733 : bool changed = false;
2836 : :
2837 : 242733 : if (get_availability () > AVAIL_INTERPOSABLE)
2838 : 238973 : add_detected_attribute_1 (this, attr, &changed);
2839 : : else
2840 : : {
2841 : : ipa_ref *ref;
2842 : :
2843 : 3784 : FOR_EACH_ALIAS (this, ref)
2844 : : {
2845 : 24 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
2846 : 24 : if (alias->get_availability () > AVAIL_INTERPOSABLE)
2847 : 0 : add_detected_attribute_1 (alias, attr, &changed);
2848 : : }
2849 : : }
2850 : 242733 : return changed;
2851 : : }
2852 : :
2853 : : /* Worker to set noreturng flag. */
2854 : : static void
2855 : 28086 : set_noreturn_flag_1 (cgraph_node *node, bool noreturn_p, bool *changed)
2856 : : {
2857 : 28086 : if (noreturn_p && !TREE_THIS_VOLATILE (node->decl))
2858 : : {
2859 : 28086 : TREE_THIS_VOLATILE (node->decl) = true;
2860 : 28086 : *changed = true;
2861 : : }
2862 : :
2863 : : ipa_ref *ref;
2864 : 28749 : FOR_EACH_ALIAS (node, ref)
2865 : : {
2866 : 663 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
2867 : 663 : if (!noreturn_p || alias->get_availability () > AVAIL_INTERPOSABLE)
2868 : 663 : set_noreturn_flag_1 (alias, noreturn_p, changed);
2869 : : }
2870 : :
2871 : 45643 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
2872 : 17557 : if (e->caller->thunk
2873 : 17557 : && (!noreturn_p || e->caller->get_availability () > AVAIL_INTERPOSABLE))
2874 : 20 : set_noreturn_flag_1 (e->caller, noreturn_p, changed);
2875 : 28086 : }
2876 : :
2877 : : /* Set TREE_THIS_VOLATILE on NODE's decl and on NODE's aliases if any. */
2878 : :
2879 : : bool
2880 : 27557 : cgraph_node::set_noreturn_flag (bool noreturn_p)
2881 : : {
2882 : 27557 : bool changed = false;
2883 : :
2884 : 27557 : if (!noreturn_p || get_availability () > AVAIL_INTERPOSABLE)
2885 : 27394 : set_noreturn_flag_1 (this, noreturn_p, &changed);
2886 : : else
2887 : : {
2888 : : ipa_ref *ref;
2889 : :
2890 : 180 : FOR_EACH_ALIAS (this, ref)
2891 : : {
2892 : 17 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
2893 : 17 : if (!noreturn_p || alias->get_availability () > AVAIL_INTERPOSABLE)
2894 : 9 : set_noreturn_flag_1 (alias, noreturn_p, &changed);
2895 : : }
2896 : : }
2897 : 27557 : return changed;
2898 : : }
2899 : :
2900 : : /* Worker to set_const_flag. */
2901 : :
2902 : : static void
2903 : 1100917 : set_const_flag_1 (cgraph_node *node, bool set_const, bool looping,
2904 : : bool *changed)
2905 : : {
2906 : : /* Static constructors and destructors without a side effect can be
2907 : : optimized out. */
2908 : 1100917 : if (set_const && !looping)
2909 : : {
2910 : 1094966 : if (DECL_STATIC_CONSTRUCTOR (node->decl))
2911 : : {
2912 : 287 : DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
2913 : 287 : *changed = true;
2914 : : }
2915 : 1094966 : if (DECL_STATIC_DESTRUCTOR (node->decl))
2916 : : {
2917 : 1 : DECL_STATIC_DESTRUCTOR (node->decl) = 0;
2918 : 1 : *changed = true;
2919 : : }
2920 : : }
2921 : 1100917 : if (!set_const)
2922 : : {
2923 : 2194 : if (TREE_READONLY (node->decl))
2924 : : {
2925 : 159 : TREE_READONLY (node->decl) = 0;
2926 : 159 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
2927 : 159 : *changed = true;
2928 : : }
2929 : : }
2930 : : else
2931 : : {
2932 : : /* Consider function:
2933 : :
2934 : : bool a(int *p)
2935 : : {
2936 : : return *p==*p;
2937 : : }
2938 : :
2939 : : During early optimization we will turn this into:
2940 : :
2941 : : bool a(int *p)
2942 : : {
2943 : : return true;
2944 : : }
2945 : :
2946 : : Now if this function will be detected as CONST however when interposed
2947 : : it may end up being just pure. We always must assume the worst
2948 : : scenario here. */
2949 : 1098723 : if (TREE_READONLY (node->decl))
2950 : : {
2951 : 731 : if (!looping && DECL_LOOPING_CONST_OR_PURE_P (node->decl))
2952 : : {
2953 : 420 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
2954 : 420 : *changed = true;
2955 : : }
2956 : : }
2957 : 1097992 : else if (node->binds_to_current_def_p ())
2958 : : {
2959 : 171824 : TREE_READONLY (node->decl) = true;
2960 : 171824 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
2961 : 171824 : DECL_PURE_P (node->decl) = false;
2962 : 171824 : *changed = true;
2963 : : }
2964 : : else
2965 : : {
2966 : 926168 : if (dump_file && (dump_flags & TDF_DETAILS))
2967 : 0 : fprintf (dump_file, "Dropping state to PURE because function does "
2968 : : "not bind to current def.\n");
2969 : 926168 : if (!DECL_PURE_P (node->decl))
2970 : : {
2971 : 444136 : DECL_PURE_P (node->decl) = true;
2972 : 444136 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
2973 : 444136 : *changed = true;
2974 : : }
2975 : 482032 : else if (!looping && DECL_LOOPING_CONST_OR_PURE_P (node->decl))
2976 : : {
2977 : 143 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
2978 : 143 : *changed = true;
2979 : : }
2980 : : }
2981 : : }
2982 : :
2983 : : ipa_ref *ref;
2984 : 1242072 : FOR_EACH_ALIAS (node, ref)
2985 : : {
2986 : 141155 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
2987 : 141155 : if (!set_const || alias->get_availability () > AVAIL_INTERPOSABLE)
2988 : 141092 : set_const_flag_1 (alias, set_const, looping, changed);
2989 : : }
2990 : 1101013 : for (struct cgraph_node *n = node->simd_clones; n != NULL;
2991 : 96 : n = n->simdclone->next_clone)
2992 : 96 : set_const_flag_1 (n, set_const, looping, changed);
2993 : 2890515 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
2994 : 1789598 : if (e->caller->thunk
2995 : 1789598 : && (!set_const || e->caller->get_availability () > AVAIL_INTERPOSABLE))
2996 : : {
2997 : : /* Virtual thunks access virtual offset in the vtable, so they can
2998 : : only be pure, never const. */
2999 : 369 : if (set_const
3000 : 369 : && (thunk_info::get (e->caller)->virtual_offset_p
3001 : 238 : || !node->binds_to_current_def_p (e->caller)))
3002 : 131 : *changed |= e->caller->set_pure_flag (true, looping);
3003 : : else
3004 : 238 : set_const_flag_1 (e->caller, set_const, looping, changed);
3005 : : }
3006 : 1100917 : }
3007 : :
3008 : : /* If SET_CONST is true, mark function, aliases and thunks to be ECF_CONST.
3009 : : If SET_CONST if false, clear the flag.
3010 : :
3011 : : When setting the flag be careful about possible interposition and
3012 : : do not set the flag for functions that can be interposed and set pure
3013 : : flag for functions that can bind to other definition.
3014 : :
3015 : : Return true if any change was done. */
3016 : :
3017 : : bool
3018 : 985262 : cgraph_node::set_const_flag (bool set_const, bool looping)
3019 : : {
3020 : 985262 : bool changed = false;
3021 : 985262 : if (!set_const || get_availability () > AVAIL_INTERPOSABLE)
3022 : 959304 : set_const_flag_1 (this, set_const, looping, &changed);
3023 : : else
3024 : : {
3025 : : ipa_ref *ref;
3026 : :
3027 : 26829 : FOR_EACH_ALIAS (this, ref)
3028 : : {
3029 : 871 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
3030 : 871 : if (!set_const || alias->get_availability () > AVAIL_INTERPOSABLE)
3031 : 187 : set_const_flag_1 (alias, set_const, looping, &changed);
3032 : : }
3033 : : }
3034 : 985262 : return changed;
3035 : : }
3036 : :
3037 : : /* Info used by set_pure_flag_1. */
3038 : :
3039 : : struct set_pure_flag_info
3040 : : {
3041 : : bool pure;
3042 : : bool looping;
3043 : : bool changed;
3044 : : };
3045 : :
3046 : : /* Worker to set_pure_flag. */
3047 : :
3048 : : static bool
3049 : 368663 : set_pure_flag_1 (cgraph_node *node, void *data)
3050 : : {
3051 : 368663 : struct set_pure_flag_info *info = (struct set_pure_flag_info *)data;
3052 : : /* Static constructors and destructors without a side effect can be
3053 : : optimized out. */
3054 : 368663 : if (info->pure && !info->looping)
3055 : : {
3056 : 302682 : if (DECL_STATIC_CONSTRUCTOR (node->decl))
3057 : : {
3058 : 0 : DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
3059 : 0 : info->changed = true;
3060 : : }
3061 : 302682 : if (DECL_STATIC_DESTRUCTOR (node->decl))
3062 : : {
3063 : 0 : DECL_STATIC_DESTRUCTOR (node->decl) = 0;
3064 : 0 : info->changed = true;
3065 : : }
3066 : : }
3067 : 368663 : if (info->pure)
3068 : : {
3069 : 366469 : if (!DECL_PURE_P (node->decl) && !TREE_READONLY (node->decl))
3070 : : {
3071 : 365887 : DECL_PURE_P (node->decl) = true;
3072 : 365887 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = info->looping;
3073 : 365887 : info->changed = true;
3074 : : }
3075 : 582 : else if (DECL_LOOPING_CONST_OR_PURE_P (node->decl)
3076 : 582 : && !info->looping)
3077 : : {
3078 : 305 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
3079 : 305 : info->changed = true;
3080 : : }
3081 : : }
3082 : : else
3083 : : {
3084 : 2194 : if (DECL_PURE_P (node->decl))
3085 : : {
3086 : 75 : DECL_PURE_P (node->decl) = false;
3087 : 75 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
3088 : 75 : info->changed = true;
3089 : : }
3090 : : }
3091 : 368663 : return false;
3092 : : }
3093 : :
3094 : : /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
3095 : : if any to PURE.
3096 : :
3097 : : When setting the flag, be careful about possible interposition.
3098 : : Return true if any change was done. */
3099 : :
3100 : : bool
3101 : 379342 : cgraph_node::set_pure_flag (bool pure, bool looping)
3102 : : {
3103 : 379342 : struct set_pure_flag_info info = {pure, looping, false};
3104 : 379342 : call_for_symbol_thunks_and_aliases (set_pure_flag_1, &info, !pure, true);
3105 : 379342 : for (struct cgraph_node *n = simd_clones; n != NULL;
3106 : 0 : n = n->simdclone->next_clone)
3107 : 0 : set_pure_flag_1 (n, &info);
3108 : 379342 : return info.changed;
3109 : : }
3110 : :
3111 : : /* Return true when cgraph_node cannot return or throw and thus
3112 : : it is safe to ignore its side effects for IPA analysis. */
3113 : :
3114 : : bool
3115 : 14462666 : cgraph_node::cannot_return_p (void)
3116 : : {
3117 : 14462666 : int flags = flags_from_decl_or_type (decl);
3118 : 14462666 : if (!opt_for_fn (decl, flag_exceptions))
3119 : 4659022 : return (flags & ECF_NORETURN) != 0;
3120 : : else
3121 : 9803644 : return ((flags & (ECF_NORETURN | ECF_NOTHROW))
3122 : 9803644 : == (ECF_NORETURN | ECF_NOTHROW));
3123 : : }
3124 : :
3125 : : /* Return true when call of edge cannot lead to return from caller
3126 : : and thus it is safe to ignore its side effects for IPA analysis
3127 : : when computing side effects of the caller.
3128 : : FIXME: We could actually mark all edges that have no reaching
3129 : : patch to the exit block or throw to get better results. */
3130 : : bool
3131 : 3023525 : cgraph_edge::cannot_lead_to_return_p (void)
3132 : : {
3133 : 3023525 : if (caller->cannot_return_p ())
3134 : : return true;
3135 : 2937005 : if (indirect_unknown_callee)
3136 : : {
3137 : 95038 : int flags = indirect_info->ecf_flags;
3138 : 95038 : if (!opt_for_fn (caller->decl, flag_exceptions))
3139 : 19296 : return (flags & ECF_NORETURN) != 0;
3140 : : else
3141 : 75742 : return ((flags & (ECF_NORETURN | ECF_NOTHROW))
3142 : 75742 : == (ECF_NORETURN | ECF_NOTHROW));
3143 : : }
3144 : : else
3145 : 2841967 : return callee->cannot_return_p ();
3146 : : }
3147 : :
3148 : : /* Return true if the edge after scaling it profile by SCALE
3149 : : may be considered hot. */
3150 : :
3151 : : bool
3152 : 5401254 : cgraph_edge::maybe_hot_p (sreal scale)
3153 : : {
3154 : : /* Never consider calls in functions optimized for size hot. */
3155 : 5401254 : if (opt_for_fn (caller->decl, optimize_size))
3156 : : return false;
3157 : :
3158 : : /* If reliable IPA count is available, just use it. */
3159 : 5346789 : profile_count c = count.ipa ();
3160 : 5346789 : if (c.reliable_p ())
3161 : 768731 : return maybe_hot_count_p (NULL, c * scale);
3162 : :
3163 : : /* See if we can determine hotness using caller frequency. */
3164 : 4578058 : if (caller->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
3165 : 4575000 : || (callee
3166 : 4176960 : && callee->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED))
3167 : : return false;
3168 : 4571489 : if (caller->frequency > NODE_FREQUENCY_UNLIKELY_EXECUTED
3169 : 4571489 : && (callee
3170 : 4173449 : && callee->frequency <= NODE_FREQUENCY_EXECUTED_ONCE))
3171 : : return false;
3172 : : /* ??? This may make sense for hot functions determined by
3173 : : user attribute, but if function is hot by profile, it may
3174 : : contains non-hot calls. In most practical cases this case
3175 : : is handled by the reliable ipa count above, but i.e. after
3176 : : inlining function with no profile to function with profile
3177 : : we get here.. */
3178 : 4517802 : if (caller->frequency == NODE_FREQUENCY_HOT)
3179 : : return true;
3180 : :
3181 : : /* Use IPA count and if it s not available appy local heuristics. */
3182 : 4517800 : if (c.initialized_p ())
3183 : : {
3184 : : /* A special case; AFDO zero means that function may quite possibly
3185 : : be executed few times per execution. If scale is large, we still
3186 : : want to consider the call hot. */
3187 : 0 : if (c.quality () == AFDO)
3188 : 0 : c = c.force_nonzero ();
3189 : 0 : return maybe_hot_count_p (NULL, c * scale);
3190 : : }
3191 : 4517800 : if (!count.initialized_p ())
3192 : : return true;
3193 : 3262030 : cgraph_node *where = caller->inlined_to ? caller->inlined_to : caller;
3194 : 3262030 : if (!where->count.initialized_p ())
3195 : : return true;
3196 : 3262030 : c = count * scale;
3197 : 3262030 : if (caller->frequency == NODE_FREQUENCY_EXECUTED_ONCE)
3198 : : {
3199 : 69464 : if (c * 2 < where->count * 3)
3200 : : return false;
3201 : : }
3202 : 3192566 : else if (c * param_hot_bb_frequency_fraction < where->count)
3203 : : return false;
3204 : : return true;
3205 : : }
3206 : :
3207 : : /* Return true if the edge may be considered hot. */
3208 : :
3209 : : bool
3210 : 2157361 : cgraph_edge::maybe_hot_p ()
3211 : : {
3212 : 2157361 : return maybe_hot_p (1);
3213 : : }
3214 : :
3215 : : /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
3216 : :
3217 : : static bool
3218 : 844233 : nonremovable_p (cgraph_node *node, void *)
3219 : : {
3220 : 844233 : return !node->can_remove_if_no_direct_calls_and_refs_p ();
3221 : : }
3222 : :
3223 : : /* Return true if whole comdat group can be removed if there are no direct
3224 : : calls to THIS. */
3225 : :
3226 : : bool
3227 : 1077308 : cgraph_node::can_remove_if_no_direct_calls_p (bool will_inline)
3228 : : {
3229 : 1077308 : struct ipa_ref *ref;
3230 : :
3231 : : /* For local symbols or non-comdat group it is the same as
3232 : : can_remove_if_no_direct_calls_p. */
3233 : 1077308 : if (!externally_visible || !same_comdat_group)
3234 : : {
3235 : 850927 : if (DECL_EXTERNAL (decl))
3236 : : return true;
3237 : 850927 : if (address_taken)
3238 : : return false;
3239 : 817280 : return !call_for_symbol_and_aliases (nonremovable_p, NULL, true);
3240 : : }
3241 : :
3242 : 226381 : if (will_inline && address_taken)
3243 : : return false;
3244 : :
3245 : : /* Otherwise check if we can remove the symbol itself and then verify
3246 : : that only uses of the comdat groups are direct call to THIS
3247 : : or its aliases. */
3248 : 226381 : if (!can_remove_if_no_direct_calls_and_refs_p ())
3249 : : return false;
3250 : :
3251 : : /* Check that all refs come from within the comdat group. */
3252 : 434669 : for (int i = 0; iterate_referring (i, ref); i++)
3253 : 220703 : if (ref->referring->get_comdat_group () != get_comdat_group ())
3254 : : return false;
3255 : :
3256 : 213966 : struct cgraph_node *target = ultimate_alias_target ();
3257 : 213966 : for (cgraph_node *next = dyn_cast<cgraph_node *> (same_comdat_group);
3258 : 650238 : next != this; next = dyn_cast<cgraph_node *> (next->same_comdat_group))
3259 : : {
3260 : 229731 : if (!externally_visible)
3261 : 0 : continue;
3262 : 229731 : if (!next->alias
3263 : 229731 : && !next->can_remove_if_no_direct_calls_and_refs_p ())
3264 : : return false;
3265 : :
3266 : : /* If we see different symbol than THIS, be sure to check calls. */
3267 : 229731 : if (next->ultimate_alias_target () != target)
3268 : 24632 : for (cgraph_edge *e = next->callers; e; e = e->next_caller)
3269 : 4384 : if (e->caller->get_comdat_group () != get_comdat_group ()
3270 : 4384 : || will_inline)
3271 : : return false;
3272 : :
3273 : : /* If function is not being inlined, we care only about
3274 : : references outside of the comdat group. */
3275 : 228201 : if (!will_inline)
3276 : 230109 : for (int i = 0; next->iterate_referring (i, ref); i++)
3277 : 11973 : if (ref->referring->get_comdat_group () != get_comdat_group ())
3278 : : return false;
3279 : : }
3280 : : return true;
3281 : : }
3282 : :
3283 : : /* Return true when function cgraph_node can be expected to be removed
3284 : : from program when direct calls in this compilation unit are removed.
3285 : :
3286 : : As a special case COMDAT functions are
3287 : : cgraph_can_remove_if_no_direct_calls_p while the are not
3288 : : cgraph_only_called_directly_p (it is possible they are called from other
3289 : : unit)
3290 : :
3291 : : This function behaves as cgraph_only_called_directly_p because eliminating
3292 : : all uses of COMDAT function does not make it necessarily disappear from
3293 : : the program unless we are compiling whole program or we do LTO. In this
3294 : : case we know we win since dynamic linking will not really discard the
3295 : : linkonce section. */
3296 : :
3297 : : bool
3298 : 3261950 : cgraph_node::will_be_removed_from_program_if_no_direct_calls_p
3299 : : (bool will_inline)
3300 : : {
3301 : 3261950 : gcc_assert (!inlined_to);
3302 : 3261950 : if (DECL_EXTERNAL (decl))
3303 : : return true;
3304 : :
3305 : 3261950 : if (!in_lto_p && !flag_whole_program)
3306 : : {
3307 : : /* If the symbol is in comdat group, we need to verify that whole comdat
3308 : : group becomes unreachable. Technically we could skip references from
3309 : : within the group, too. */
3310 : 3009414 : if (!only_called_directly_p ())
3311 : : return false;
3312 : 730283 : if (same_comdat_group && externally_visible)
3313 : : {
3314 : 0 : struct cgraph_node *target = ultimate_alias_target ();
3315 : :
3316 : 0 : if (will_inline && address_taken)
3317 : : return true;
3318 : 0 : for (cgraph_node *next = dyn_cast<cgraph_node *> (same_comdat_group);
3319 : 0 : next != this;
3320 : 0 : next = dyn_cast<cgraph_node *> (next->same_comdat_group))
3321 : : {
3322 : 0 : if (!externally_visible)
3323 : 0 : continue;
3324 : 0 : if (!next->alias
3325 : 0 : && !next->only_called_directly_p ())
3326 : : return false;
3327 : :
3328 : : /* If we see different symbol than THIS,
3329 : : be sure to check calls. */
3330 : 0 : if (next->ultimate_alias_target () != target)
3331 : 0 : for (cgraph_edge *e = next->callers; e; e = e->next_caller)
3332 : 0 : if (e->caller->get_comdat_group () != get_comdat_group ()
3333 : 0 : || will_inline)
3334 : : return false;
3335 : : }
3336 : : }
3337 : 730283 : return true;
3338 : : }
3339 : : else
3340 : 252536 : return can_remove_if_no_direct_calls_p (will_inline);
3341 : : }
3342 : :
3343 : :
3344 : : /* Worker for cgraph_only_called_directly_p. */
3345 : :
3346 : : static bool
3347 : 16072120 : cgraph_not_only_called_directly_p_1 (cgraph_node *node, void *)
3348 : : {
3349 : 16072120 : return !node->only_called_directly_or_aliased_p ();
3350 : : }
3351 : :
3352 : : /* Return true when function cgraph_node and all its aliases are only called
3353 : : directly.
3354 : : i.e. it is not externally visible, address was not taken and
3355 : : it is not used in any other non-standard way. */
3356 : :
3357 : : bool
3358 : 16004186 : cgraph_node::only_called_directly_p (void)
3359 : : {
3360 : 16004186 : gcc_assert (ultimate_alias_target () == this);
3361 : 16004186 : return !call_for_symbol_and_aliases (cgraph_not_only_called_directly_p_1,
3362 : 16004186 : NULL, true);
3363 : : }
3364 : :
3365 : :
3366 : : /* Collect all callers of NODE. Worker for collect_callers_of_node. */
3367 : :
3368 : : static bool
3369 : 131914 : collect_callers_of_node_1 (cgraph_node *node, void *data)
3370 : : {
3371 : 131914 : vec<cgraph_edge *> *redirect_callers = (vec<cgraph_edge *> *)data;
3372 : 131914 : cgraph_edge *cs;
3373 : 131914 : enum availability avail;
3374 : 131914 : node->ultimate_alias_target (&avail);
3375 : :
3376 : 131914 : if (avail > AVAIL_INTERPOSABLE)
3377 : 461808 : for (cs = node->callers; cs != NULL; cs = cs->next_caller)
3378 : 329894 : if (!cs->indirect_inlining_edge
3379 : 329894 : && !cs->caller->thunk)
3380 : 329854 : redirect_callers->safe_push (cs);
3381 : 131914 : return false;
3382 : : }
3383 : :
3384 : : /* Collect all callers of cgraph_node and its aliases that are known to lead to
3385 : : cgraph_node (i.e. are not overwritable). */
3386 : :
3387 : : auto_vec<cgraph_edge *>
3388 : 129866 : cgraph_node::collect_callers (void)
3389 : : {
3390 : 129866 : auto_vec<cgraph_edge *> redirect_callers;
3391 : 129866 : call_for_symbol_thunks_and_aliases (collect_callers_of_node_1,
3392 : : &redirect_callers, false);
3393 : 129866 : return redirect_callers;
3394 : : }
3395 : :
3396 : :
3397 : : /* Return TRUE if NODE2 a clone of NODE or is equivalent to it. Return
3398 : : optimistically true if this cannot be determined. */
3399 : :
3400 : : static bool
3401 : 34291 : clone_of_p (cgraph_node *node, cgraph_node *node2)
3402 : : {
3403 : 34291 : node = node->ultimate_alias_target ();
3404 : 34291 : node2 = node2->ultimate_alias_target ();
3405 : :
3406 : 34291 : if (node2->clone_of == node
3407 : 4042 : || node2->former_clone_of == node->decl)
3408 : : return true;
3409 : :
3410 : 4104 : if (!node->thunk && !node->former_thunk_p ())
3411 : : {
3412 : : while (node2
3413 : 11939 : && node->decl != node2->decl
3414 : 19899 : && node->decl != node2->former_clone_of)
3415 : 7959 : node2 = node2->clone_of;
3416 : 3980 : return node2 != NULL;
3417 : : }
3418 : :
3419 : : /* There are no virtual clones of thunks so check former_clone_of or if we
3420 : : might have skipped thunks because this adjustments are no longer
3421 : : necessary. */
3422 : 62 : while (node->thunk || node->former_thunk_p ())
3423 : : {
3424 : 62 : if (!thunk_info::get (node)->this_adjusting)
3425 : : return false;
3426 : : /* In case of instrumented expanded thunks, which can have multiple calls
3427 : : in them, we do not know how to continue and just have to be
3428 : : optimistic. The same applies if all calls have already been inlined
3429 : : into the thunk. */
3430 : 62 : if (!node->callees || node->callees->next_callee)
3431 : : return true;
3432 : 59 : node = node->callees->callee->ultimate_alias_target ();
3433 : :
3434 : 59 : clone_info *info = clone_info::get (node2);
3435 : 59 : if (!info || !info->param_adjustments
3436 : 118 : || info->param_adjustments->first_param_intact_p ())
3437 : 0 : return false;
3438 : 59 : if (node2->former_clone_of == node->decl
3439 : 59 : || node2->former_clone_of == node->former_clone_of)
3440 : : return true;
3441 : :
3442 : : cgraph_node *n2 = node2;
3443 : 0 : while (n2 && node->decl != n2->decl)
3444 : 0 : n2 = n2->clone_of;
3445 : 0 : if (n2)
3446 : : return true;
3447 : : }
3448 : :
3449 : : return false;
3450 : : }
3451 : :
3452 : : /* Verify edge count and frequency. */
3453 : :
3454 : : bool
3455 : 199547704 : cgraph_edge::verify_count ()
3456 : : {
3457 : 199547704 : bool error_found = false;
3458 : 199547704 : if (!count.verify ())
3459 : : {
3460 : 0 : error ("caller edge count invalid");
3461 : 0 : error_found = true;
3462 : : }
3463 : 199547704 : return error_found;
3464 : : }
3465 : :
3466 : : /* Switch to THIS_CFUN if needed and print STMT to stderr. */
3467 : : static void
3468 : 0 : cgraph_debug_gimple_stmt (function *this_cfun, gimple *stmt)
3469 : : {
3470 : 0 : bool fndecl_was_null = false;
3471 : : /* debug_gimple_stmt needs correct cfun */
3472 : 0 : if (cfun != this_cfun)
3473 : 0 : set_cfun (this_cfun);
3474 : : /* ...and an actual current_function_decl */
3475 : 0 : if (!current_function_decl)
3476 : : {
3477 : 0 : current_function_decl = this_cfun->decl;
3478 : 0 : fndecl_was_null = true;
3479 : : }
3480 : 0 : debug_gimple_stmt (stmt);
3481 : 0 : if (fndecl_was_null)
3482 : 0 : current_function_decl = NULL;
3483 : 0 : }
3484 : :
3485 : : /* Verify that call graph edge corresponds to DECL from the associated
3486 : : statement. Return true if the verification should fail. */
3487 : :
3488 : : bool
3489 : 98895176 : cgraph_edge::verify_corresponds_to_fndecl (tree decl)
3490 : : {
3491 : 98895176 : cgraph_node *node;
3492 : :
3493 : 98895176 : if (!decl || callee->inlined_to)
3494 : : return false;
3495 : 94949941 : if (symtab->state == LTO_STREAMING)
3496 : : return false;
3497 : 94949941 : node = cgraph_node::get (decl);
3498 : :
3499 : : /* We do not know if a node from a different partition is an alias or what it
3500 : : aliases and therefore cannot do the former_clone_of check reliably. When
3501 : : body_removed is set, we have lost all information about what was alias or
3502 : : thunk of and also cannot proceed. */
3503 : 94949941 : if (!node
3504 : 94845535 : || node->body_removed
3505 : 94026463 : || node->in_other_partition
3506 : 94026460 : || callee->icf_merged
3507 : 93930110 : || callee->in_other_partition)
3508 : : return false;
3509 : :
3510 : 93930110 : node = node->ultimate_alias_target ();
3511 : :
3512 : : /* Optimizers can redirect unreachable calls or calls triggering undefined
3513 : : behavior to __builtin_unreachable or __builtin_unreachable trap. */
3514 : :
3515 : 93930110 : if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE,
3516 : : BUILT_IN_UNREACHABLE_TRAP))
3517 : : return false;
3518 : :
3519 : 91077327 : if (callee->former_clone_of != node->decl
3520 : 91075639 : && (node != callee->ultimate_alias_target ())
3521 : 91111618 : && !clone_of_p (node, callee))
3522 : : return true;
3523 : : else
3524 : 91077327 : return false;
3525 : : }
3526 : :
3527 : : /* Disable warnings about missing quoting in GCC diagnostics for
3528 : : the verification errors. Their format strings don't follow GCC
3529 : : diagnostic conventions and the calls are ultimately followed by
3530 : : one to internal_error. */
3531 : : #if __GNUC__ >= 10
3532 : : # pragma GCC diagnostic push
3533 : : # pragma GCC diagnostic ignored "-Wformat-diag"
3534 : : #endif
3535 : :
3536 : : /* Verify consistency of speculative call in NODE corresponding to STMT
3537 : : and LTO_STMT_UID. If INDIRECT is set, assume that it is the indirect
3538 : : edge of call sequence. Return true if error is found.
3539 : :
3540 : : This function is called to every component of indirect call (direct edges,
3541 : : indirect edge and refs). To save duplicated work, do full testing only
3542 : : in that case. */
3543 : : static bool
3544 : 206539 : verify_speculative_call (struct cgraph_node *node, gimple *stmt,
3545 : : unsigned int lto_stmt_uid,
3546 : : struct cgraph_edge *indirect)
3547 : : {
3548 : 206539 : if (indirect == NULL)
3549 : : {
3550 : 173374 : for (indirect = node->indirect_calls; indirect;
3551 : 35666 : indirect = indirect->next_callee)
3552 : 173374 : if (indirect->call_stmt == stmt
3553 : 137826 : && indirect->lto_stmt_uid == lto_stmt_uid)
3554 : : break;
3555 : 137708 : if (!indirect)
3556 : : {
3557 : 0 : error ("missing indirect call in speculative call sequence");
3558 : 0 : return true;
3559 : : }
3560 : 137708 : if (!indirect->speculative)
3561 : : {
3562 : 0 : error ("indirect call in speculative call sequence has no "
3563 : : "speculative flag");
3564 : 0 : return true;
3565 : : }
3566 : : return false;
3567 : : }
3568 : :
3569 : : /* Maximal number of targets. We probably will never want to have more than
3570 : : this. */
3571 : : const unsigned int num = 256;
3572 : : cgraph_edge *direct_calls[num];
3573 : : ipa_ref *refs[num];
3574 : :
3575 : 17689567 : for (unsigned int i = 0; i < num; i++)
3576 : : {
3577 : 17620736 : direct_calls[i] = NULL;
3578 : 17620736 : refs[i] = NULL;
3579 : : }
3580 : :
3581 : 68831 : cgraph_edge *first_call = NULL;
3582 : 68831 : cgraph_edge *prev_call = NULL;
3583 : :
3584 : 363561 : for (cgraph_edge *direct = node->callees; direct;
3585 : 294730 : direct = direct->next_callee)
3586 : 294730 : if (direct->call_stmt == stmt && direct->lto_stmt_uid == lto_stmt_uid)
3587 : : {
3588 : 68854 : if (!first_call)
3589 : 68831 : first_call = direct;
3590 : 68854 : if (prev_call && direct != prev_call->next_callee)
3591 : : {
3592 : 0 : error ("speculative edges are not adjacent");
3593 : 0 : return true;
3594 : : }
3595 : 68854 : prev_call = direct;
3596 : 68854 : if (!direct->speculative)
3597 : : {
3598 : 0 : error ("direct call to %s in speculative call sequence has no "
3599 : 0 : "speculative flag", direct->callee->dump_name ());
3600 : 0 : return true;
3601 : : }
3602 : 68854 : if (direct->speculative_id >= num)
3603 : : {
3604 : 0 : error ("direct call to %s in speculative call sequence has "
3605 : : "speculative_id %i out of range",
3606 : 0 : direct->callee->dump_name (), direct->speculative_id);
3607 : 0 : return true;
3608 : : }
3609 : 68854 : if (direct_calls[direct->speculative_id])
3610 : : {
3611 : 0 : error ("duplicate direct call to %s in speculative call sequence "
3612 : : "with speculative_id %i",
3613 : 0 : direct->callee->dump_name (), direct->speculative_id);
3614 : 0 : return true;
3615 : : }
3616 : 68854 : direct_calls[direct->speculative_id] = direct;
3617 : : }
3618 : :
3619 : 68831 : if (first_call->call_stmt
3620 : 68831 : && first_call != node->get_edge (first_call->call_stmt))
3621 : : {
3622 : 0 : error ("call stmt hash does not point to first direct edge of "
3623 : : "speculative call sequence");
3624 : 0 : return true;
3625 : : }
3626 : :
3627 : : ipa_ref *ref;
3628 : 203585 : for (int i = 0; node->iterate_reference (i, ref); i++)
3629 : 134754 : if (ref->speculative
3630 : 93402 : && ref->stmt == stmt && ref->lto_stmt_uid == lto_stmt_uid)
3631 : : {
3632 : 68854 : if (ref->speculative_id >= num)
3633 : : {
3634 : 0 : error ("direct call to %s in speculative call sequence has "
3635 : : "speculative_id %i out of range",
3636 : 0 : ref->referred->dump_name (), ref->speculative_id);
3637 : 0 : return true;
3638 : : }
3639 : 68854 : if (refs[ref->speculative_id])
3640 : : {
3641 : 0 : error ("duplicate reference %s in speculative call sequence "
3642 : : "with speculative_id %i",
3643 : 0 : ref->referred->dump_name (), ref->speculative_id);
3644 : 0 : return true;
3645 : : }
3646 : 68854 : refs[ref->speculative_id] = ref;
3647 : : }
3648 : :
3649 : : int num_targets = 0;
3650 : 17689567 : for (unsigned int i = 0 ; i < num ; i++)
3651 : : {
3652 : 17620736 : if (refs[i] && !direct_calls[i])
3653 : : {
3654 : 0 : error ("missing direct call for speculation %i", i);
3655 : 0 : return true;
3656 : : }
3657 : 17620736 : if (!refs[i] && direct_calls[i])
3658 : : {
3659 : 0 : error ("missing ref for speculation %i", i);
3660 : 0 : return true;
3661 : : }
3662 : 17620736 : if (refs[i] != NULL)
3663 : 68854 : num_targets++;
3664 : : }
3665 : :
3666 : 68831 : if (num_targets != indirect->num_speculative_call_targets_p ())
3667 : : {
3668 : 0 : error ("number of speculative targets %i mismatched with "
3669 : : "num_speculative_call_targets %i",
3670 : : num_targets,
3671 : : indirect->num_speculative_call_targets_p ());
3672 : 0 : return true;
3673 : : }
3674 : : return false;
3675 : : }
3676 : :
3677 : : /* Verify cgraph nodes of given cgraph node. */
3678 : : DEBUG_FUNCTION void
3679 : 52976230 : cgraph_node::verify_node (void)
3680 : : {
3681 : 52976230 : cgraph_edge *e;
3682 : 52976230 : function *this_cfun = DECL_STRUCT_FUNCTION (decl);
3683 : 52976230 : basic_block this_block;
3684 : 52976230 : gimple_stmt_iterator gsi;
3685 : 52976230 : bool error_found = false;
3686 : 52976230 : int i;
3687 : 52976230 : ipa_ref *ref = NULL;
3688 : :
3689 : 52976230 : if (seen_error ())
3690 : 52976230 : return;
3691 : :
3692 : 52976230 : timevar_push (TV_CGRAPH_VERIFY);
3693 : 52976230 : error_found |= verify_base ();
3694 : 159760197 : for (e = callees; e; e = e->next_callee)
3695 : 106783967 : if (e->aux)
3696 : : {
3697 : 0 : error ("aux field set for edge %s->%s",
3698 : 0 : identifier_to_locale (e->caller->name ()),
3699 : 0 : identifier_to_locale (e->callee->name ()));
3700 : 0 : error_found = true;
3701 : : }
3702 : 52976230 : if (!count.verify ())
3703 : : {
3704 : 0 : error ("cgraph count invalid");
3705 : 0 : error_found = true;
3706 : : }
3707 : 52976230 : if (inlined_to && same_comdat_group)
3708 : : {
3709 : 0 : error ("inline clone in same comdat group list");
3710 : 0 : error_found = true;
3711 : : }
3712 : 52976230 : if (inlined_to && !count.compatible_p (inlined_to->count))
3713 : : {
3714 : 0 : error ("inline clone count is not compatible");
3715 : 0 : count.debug ();
3716 : 0 : inlined_to->count.debug ();
3717 : 0 : error_found = true;
3718 : : }
3719 : 52976230 : if (tp_first_run < 0)
3720 : : {
3721 : 0 : error ("tp_first_run must be non-negative");
3722 : 0 : error_found = true;
3723 : : }
3724 : 52976230 : if (!definition && !in_other_partition && local)
3725 : : {
3726 : 0 : error ("local symbols must be defined");
3727 : 0 : error_found = true;
3728 : : }
3729 : 52976230 : if (inlined_to && externally_visible)
3730 : : {
3731 : 0 : error ("externally visible inline clone");
3732 : 0 : error_found = true;
3733 : : }
3734 : 52976230 : if (inlined_to && address_taken)
3735 : : {
3736 : 0 : error ("inline clone with address taken");
3737 : 0 : error_found = true;
3738 : : }
3739 : 52976230 : if (inlined_to && force_output)
3740 : : {
3741 : 0 : error ("inline clone is forced to output");
3742 : 0 : error_found = true;
3743 : : }
3744 : 52976230 : if (symtab->state != LTO_STREAMING)
3745 : : {
3746 : 52867640 : if (calls_comdat_local && !same_comdat_group)
3747 : : {
3748 : 0 : error ("calls_comdat_local is set outside of a comdat group");
3749 : 0 : error_found = true;
3750 : : }
3751 : 52867640 : if (!inlined_to && calls_comdat_local != check_calls_comdat_local_p ())
3752 : : {
3753 : 0 : error ("invalid calls_comdat_local flag");
3754 : 0 : error_found = true;
3755 : : }
3756 : : }
3757 : 52976230 : if (DECL_IS_MALLOC (decl)
3758 : 52976230 : && !POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
3759 : : {
3760 : 0 : error ("malloc attribute should be used for a function that "
3761 : : "returns a pointer");
3762 : 0 : error_found = true;
3763 : : }
3764 : 52976230 : if (definition
3765 : 35887870 : && externally_visible
3766 : : /* For aliases in lto1 free_lang_data doesn't guarantee preservation
3767 : : of opt_for_fn (decl, flag_semantic_interposition). See PR105399. */
3768 : 19407471 : && (!alias || !in_lto_p)
3769 : 52976230 : && semantic_interposition
3770 : 19404553 : != opt_for_fn (decl, flag_semantic_interposition))
3771 : : {
3772 : 0 : error ("semantic interposition mismatch");
3773 : 0 : error_found = true;
3774 : : }
3775 : 55375594 : for (e = indirect_calls; e; e = e->next_callee)
3776 : : {
3777 : 2399364 : if (e->aux)
3778 : : {
3779 : 0 : error ("aux field set for indirect edge from %s",
3780 : 0 : identifier_to_locale (e->caller->name ()));
3781 : 0 : error_found = true;
3782 : : }
3783 : 2399364 : if (!e->count.compatible_p (count))
3784 : : {
3785 : 0 : error ("edge count is not compatible with function count");
3786 : 0 : e->count.debug ();
3787 : 0 : count.debug ();
3788 : 0 : error_found = true;
3789 : : }
3790 : 2399364 : if (inlined_to && !e->count.compatible_p (inlined_to->count))
3791 : : {
3792 : 0 : error ("edge count is not compatible with inlined to function count");
3793 : 0 : e->count.debug ();
3794 : 0 : count.debug ();
3795 : 0 : error_found = true;
3796 : : }
3797 : 2399364 : if (!e->indirect_unknown_callee
3798 : 2399364 : || !e->indirect_info)
3799 : : {
3800 : 0 : error ("An indirect edge from %s is not marked as indirect or has "
3801 : : "associated indirect_info, the corresponding statement is: ",
3802 : 0 : identifier_to_locale (e->caller->name ()));
3803 : 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
3804 : 0 : error_found = true;
3805 : : }
3806 : 2399364 : if (e->call_stmt && e->lto_stmt_uid)
3807 : : {
3808 : 0 : error ("edge has both call_stmt and lto_stmt_uid set");
3809 : 0 : error_found = true;
3810 : : }
3811 : : }
3812 : 52976230 : bool check_comdat = comdat_local_p ();
3813 : 143340603 : for (e = callers; e; e = e->next_caller)
3814 : : {
3815 : 90364373 : if (e->verify_count ())
3816 : 0 : error_found = true;
3817 : 90364373 : if (check_comdat
3818 : 90364373 : && !in_same_comdat_group_p (e->caller))
3819 : : {
3820 : 0 : error ("comdat-local function called by %s outside its comdat",
3821 : : identifier_to_locale (e->caller->name ()));
3822 : 0 : error_found = true;
3823 : : }
3824 : 90364373 : if (!e->inline_failed)
3825 : : {
3826 : 8552120 : if (inlined_to
3827 : 8552120 : != (e->caller->inlined_to
3828 : 8552120 : ? e->caller->inlined_to : e->caller))
3829 : : {
3830 : 0 : error ("inlined_to pointer is wrong");
3831 : 0 : error_found = true;
3832 : : }
3833 : 8552120 : if (callers->next_caller)
3834 : : {
3835 : 0 : error ("multiple inline callers");
3836 : 0 : error_found = true;
3837 : : }
3838 : : }
3839 : : else
3840 : 81812253 : if (inlined_to)
3841 : : {
3842 : 0 : error ("inlined_to pointer set for noninline callers");
3843 : 0 : error_found = true;
3844 : : }
3845 : : }
3846 : 159760197 : for (e = callees; e; e = e->next_callee)
3847 : : {
3848 : 106783967 : if (e->verify_count ())
3849 : 0 : error_found = true;
3850 : 106783967 : if (!e->count.compatible_p (count))
3851 : : {
3852 : 0 : error ("edge count is not compatible with function count");
3853 : 0 : e->count.debug ();
3854 : 0 : count.debug ();
3855 : 0 : error_found = true;
3856 : : }
3857 : 106783967 : if (gimple_has_body_p (e->caller->decl)
3858 : 100674279 : && !e->caller->inlined_to
3859 : 91780992 : && !e->speculative
3860 : : /* Optimized out calls are redirected to __builtin_unreachable. */
3861 : 91760308 : && (e->count.nonzero_p ()
3862 : 51348585 : || ! e->callee->decl
3863 : 51348585 : || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
3864 : : BUILT_IN_UNREACHABLE_TRAP))
3865 : : && count
3866 : 91257095 : == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
3867 : 198032692 : && (!e->count.ipa_p ()
3868 : 42326221 : && e->count.differs_from_p (gimple_bb (e->call_stmt)->count)))
3869 : : {
3870 : 0 : error ("caller edge count does not match BB count");
3871 : 0 : fprintf (stderr, "edge count: ");
3872 : 0 : e->count.dump (stderr);
3873 : 0 : fprintf (stderr, "\n bb count: ");
3874 : 0 : gimple_bb (e->call_stmt)->count.dump (stderr);
3875 : 0 : fprintf (stderr, "\n");
3876 : 0 : error_found = true;
3877 : : }
3878 : 106783967 : if (e->call_stmt && e->lto_stmt_uid)
3879 : : {
3880 : 0 : error ("edge has both call_stmt and lto_stmt_uid set");
3881 : 0 : error_found = true;
3882 : : }
3883 : 106783967 : if (e->speculative
3884 : 106783967 : && verify_speculative_call (e->caller, e->call_stmt, e->lto_stmt_uid,
3885 : : NULL))
3886 : : error_found = true;
3887 : : }
3888 : 55375594 : for (e = indirect_calls; e; e = e->next_callee)
3889 : : {
3890 : 2399364 : if (e->verify_count ())
3891 : 0 : error_found = true;
3892 : 2399364 : if (gimple_has_body_p (e->caller->decl)
3893 : 2346246 : && !e->caller->inlined_to
3894 : 2086345 : && !e->speculative
3895 : 2065667 : && e->count.ipa_p ()
3896 : : && count
3897 : 757606 : == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
3898 : 3156966 : && (!e->count.ipa_p ()
3899 : 0 : && e->count.differs_from_p (gimple_bb (e->call_stmt)->count)))
3900 : : {
3901 : 0 : error ("indirect call count does not match BB count");
3902 : 0 : fprintf (stderr, "edge count: ");
3903 : 0 : e->count.dump (stderr);
3904 : 0 : fprintf (stderr, "\n bb count: ");
3905 : 0 : gimple_bb (e->call_stmt)->count.dump (stderr);
3906 : 0 : fprintf (stderr, "\n");
3907 : 0 : error_found = true;
3908 : : }
3909 : 2399364 : if (e->speculative
3910 : 2399364 : && verify_speculative_call (e->caller, e->call_stmt, e->lto_stmt_uid,
3911 : : e))
3912 : : error_found = true;
3913 : : }
3914 : 118906026 : for (i = 0; iterate_reference (i, ref); i++)
3915 : : {
3916 : 65929796 : if (ref->stmt && ref->lto_stmt_uid)
3917 : : {
3918 : 0 : error ("reference has both stmt and lto_stmt_uid set");
3919 : 0 : error_found = true;
3920 : : }
3921 : 65929796 : if (ref->speculative
3922 : 65929796 : && verify_speculative_call (this, ref->stmt,
3923 : : ref->lto_stmt_uid, NULL))
3924 : : error_found = true;
3925 : : }
3926 : :
3927 : 52976230 : if (!callers && inlined_to)
3928 : : {
3929 : 0 : error ("inlined_to pointer is set but no predecessors found");
3930 : 0 : error_found = true;
3931 : : }
3932 : 52976230 : if (inlined_to == this)
3933 : : {
3934 : 0 : error ("inlined_to pointer refers to itself");
3935 : 0 : error_found = true;
3936 : : }
3937 : :
3938 : 52976230 : if (clone_of)
3939 : : {
3940 : 6213474 : cgraph_node *first_clone = clone_of->clones;
3941 : 6213474 : if (first_clone != this)
3942 : : {
3943 : 3217017 : if (prev_sibling_clone->clone_of != clone_of)
3944 : : {
3945 : 0 : error ("cgraph_node has wrong clone_of");
3946 : 0 : error_found = true;
3947 : : }
3948 : : }
3949 : : }
3950 : 52976230 : if (clones)
3951 : : {
3952 : : cgraph_node *n;
3953 : 8885520 : for (n = clones; n; n = n->next_sibling_clone)
3954 : 7228985 : if (n->clone_of != this)
3955 : : break;
3956 : 1656535 : if (n)
3957 : : {
3958 : 0 : error ("cgraph_node has wrong clone list");
3959 : 0 : error_found = true;
3960 : : }
3961 : : }
3962 : 52976230 : if ((prev_sibling_clone || next_sibling_clone) && !clone_of)
3963 : : {
3964 : 0 : error ("cgraph_node is in clone list but it is not clone");
3965 : 0 : error_found = true;
3966 : : }
3967 : 52976230 : if (!prev_sibling_clone && clone_of && clone_of->clones != this)
3968 : : {
3969 : 0 : error ("cgraph_node has wrong prev_clone pointer");
3970 : 0 : error_found = true;
3971 : : }
3972 : 52976230 : if (prev_sibling_clone && prev_sibling_clone->next_sibling_clone != this)
3973 : : {
3974 : 0 : error ("double linked list of clones corrupted");
3975 : 0 : error_found = true;
3976 : : }
3977 : :
3978 : 52976230 : if (analyzed && alias)
3979 : : {
3980 : 1484307 : bool ref_found = false;
3981 : 1484307 : int i;
3982 : 1484307 : ipa_ref *ref = NULL;
3983 : :
3984 : 1484307 : if (callees)
3985 : : {
3986 : 0 : error ("Alias has call edges");
3987 : 0 : error_found = true;
3988 : : }
3989 : 2968614 : for (i = 0; iterate_reference (i, ref); i++)
3990 : 1484307 : if (ref->use != IPA_REF_ALIAS)
3991 : : {
3992 : 0 : error ("Alias has non-alias reference");
3993 : 0 : error_found = true;
3994 : : }
3995 : 1484307 : else if (ref_found)
3996 : : {
3997 : 0 : error ("Alias has more than one alias reference");
3998 : 0 : error_found = true;
3999 : : }
4000 : : else
4001 : : ref_found = true;
4002 : 1484307 : if (!ref_found)
4003 : : {
4004 : 0 : error ("Analyzed alias has no reference");
4005 : 0 : error_found = true;
4006 : : }
4007 : : }
4008 : :
4009 : 52976230 : if (analyzed && thunk)
4010 : : {
4011 : 22162 : if (!callees)
4012 : : {
4013 : 0 : error ("No edge out of thunk node");
4014 : 0 : error_found = true;
4015 : : }
4016 : 22162 : else if (callees->next_callee)
4017 : : {
4018 : 0 : error ("More than one edge out of thunk node");
4019 : 0 : error_found = true;
4020 : : }
4021 : 22162 : if (gimple_has_body_p (decl) && !inlined_to)
4022 : : {
4023 : 0 : error ("Thunk is not supposed to have body");
4024 : 0 : error_found = true;
4025 : : }
4026 : : }
4027 : 35863749 : else if (analyzed && gimple_has_body_p (decl)
4028 : 30961649 : && !TREE_ASM_WRITTEN (decl)
4029 : 30961649 : && (!DECL_EXTERNAL (decl) || inlined_to)
4030 : 82992743 : && !flag_wpa)
4031 : : {
4032 : 30012359 : if ((this_cfun->curr_properties & PROP_assumptions_done) != 0)
4033 : : ;
4034 : 30012251 : else if (this_cfun->cfg)
4035 : : {
4036 : 30012251 : hash_set<gimple *> stmts;
4037 : :
4038 : : /* Reach the trees by walking over the CFG, and note the
4039 : : enclosing basic-blocks in the call edges. */
4040 : 249074998 : FOR_EACH_BB_FN (this_block, this_cfun)
4041 : : {
4042 : 219062747 : for (gsi = gsi_start_phis (this_block);
4043 : 265082002 : !gsi_end_p (gsi); gsi_next (&gsi))
4044 : 46019255 : stmts.add (gsi_stmt (gsi));
4045 : 438125494 : for (gsi = gsi_start_bb (this_block);
4046 : 1327785155 : !gsi_end_p (gsi);
4047 : 1108722408 : gsi_next (&gsi))
4048 : : {
4049 : 1108722408 : gimple *stmt = gsi_stmt (gsi);
4050 : 1108722408 : stmts.add (stmt);
4051 : 1108722408 : if (is_gimple_call (stmt))
4052 : : {
4053 : 104637646 : cgraph_edge *e = get_edge (stmt);
4054 : 104637646 : tree decl = gimple_call_fndecl (stmt);
4055 : 104637646 : if (e)
4056 : : {
4057 : 101150080 : if (e->aux)
4058 : : {
4059 : 0 : error ("shared call_stmt:");
4060 : 0 : cgraph_debug_gimple_stmt (this_cfun, stmt);
4061 : 0 : error_found = true;
4062 : : }
4063 : 101150080 : if (!e->indirect_unknown_callee)
4064 : : {
4065 : 98895176 : if (e->verify_corresponds_to_fndecl (decl))
4066 : : {
4067 : 0 : error ("edge points to wrong declaration:");
4068 : 0 : debug_tree (e->callee->decl);
4069 : 0 : fprintf (stderr," Instead of:");
4070 : 0 : debug_tree (decl);
4071 : 0 : error_found = true;
4072 : : }
4073 : : }
4074 : 2254904 : else if (decl)
4075 : : {
4076 : 0 : error ("an indirect edge with unknown callee "
4077 : : "corresponding to a call_stmt with "
4078 : : "a known declaration:");
4079 : 0 : error_found = true;
4080 : 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
4081 : : }
4082 : 101150080 : e->aux = (void *)1;
4083 : : }
4084 : 3487566 : else if (decl)
4085 : : {
4086 : 0 : error ("missing callgraph edge for call stmt:");
4087 : 0 : cgraph_debug_gimple_stmt (this_cfun, stmt);
4088 : 0 : error_found = true;
4089 : : }
4090 : : }
4091 : : }
4092 : : }
4093 : 100388582 : for (i = 0; iterate_reference (i, ref); i++)
4094 : 61352381 : if (ref->stmt && !stmts.contains (ref->stmt))
4095 : : {
4096 : 0 : error ("reference to dead statement");
4097 : 0 : cgraph_debug_gimple_stmt (this_cfun, ref->stmt);
4098 : 0 : error_found = true;
4099 : : }
4100 : 30012251 : }
4101 : : else
4102 : : /* No CFG available?! */
4103 : 0 : gcc_unreachable ();
4104 : :
4105 : 128907542 : for (e = callees; e; e = e->next_callee)
4106 : : {
4107 : 98895183 : if (!e->aux && !e->speculative)
4108 : : {
4109 : 0 : error ("edge %s->%s has no corresponding call_stmt",
4110 : 0 : identifier_to_locale (e->caller->name ()),
4111 : 0 : identifier_to_locale (e->callee->name ()));
4112 : 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
4113 : 0 : error_found = true;
4114 : : }
4115 : 98895183 : e->aux = 0;
4116 : : }
4117 : 32332900 : for (e = indirect_calls; e; e = e->next_callee)
4118 : : {
4119 : 2320541 : if (!e->aux && !e->speculative)
4120 : : {
4121 : 0 : error ("an indirect edge from %s has no corresponding call_stmt",
4122 : 0 : identifier_to_locale (e->caller->name ()));
4123 : 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
4124 : 0 : error_found = true;
4125 : : }
4126 : 2320541 : e->aux = 0;
4127 : : }
4128 : : }
4129 : :
4130 : 52976230 : if (nested_function_info *info = nested_function_info::get (this))
4131 : : {
4132 : 0 : if (info->nested != NULL)
4133 : : {
4134 : 0 : for (cgraph_node *n = info->nested; n != NULL;
4135 : 0 : n = next_nested_function (n))
4136 : : {
4137 : 0 : nested_function_info *ninfo = nested_function_info::get (n);
4138 : 0 : if (ninfo->origin == NULL)
4139 : : {
4140 : 0 : error ("missing origin for a node in a nested list");
4141 : 0 : error_found = true;
4142 : : }
4143 : 0 : else if (ninfo->origin != this)
4144 : : {
4145 : 0 : error ("origin points to a different parent");
4146 : 0 : error_found = true;
4147 : 0 : break;
4148 : : }
4149 : : }
4150 : : }
4151 : 0 : if (info->next_nested != NULL && info->origin == NULL)
4152 : : {
4153 : 0 : error ("missing origin for a node in a nested list");
4154 : 0 : error_found = true;
4155 : : }
4156 : : }
4157 : :
4158 : 52976230 : if (error_found)
4159 : : {
4160 : 0 : dump (stderr);
4161 : 0 : internal_error ("verify_cgraph_node failed");
4162 : : }
4163 : 52976230 : timevar_pop (TV_CGRAPH_VERIFY);
4164 : : }
4165 : :
4166 : : /* Verify whole cgraph structure. */
4167 : : DEBUG_FUNCTION void
4168 : 820 : cgraph_node::verify_cgraph_nodes (void)
4169 : : {
4170 : 820 : cgraph_node *node;
4171 : :
4172 : 820 : if (seen_error ())
4173 : : return;
4174 : :
4175 : 10294 : FOR_EACH_FUNCTION (node)
4176 : 4351 : node->verify ();
4177 : : }
4178 : :
4179 : : #if __GNUC__ >= 10
4180 : : # pragma GCC diagnostic pop
4181 : : #endif
4182 : :
4183 : : /* Walk the alias chain to return the function cgraph_node is alias of.
4184 : : Walk through thunks, too.
4185 : : When AVAILABILITY is non-NULL, get minimal availability in the chain.
4186 : : When REF is non-NULL, assume that reference happens in symbol REF
4187 : : when determining the availability. */
4188 : :
4189 : : cgraph_node *
4190 : 132388535 : cgraph_node::function_symbol (enum availability *availability,
4191 : : struct symtab_node *ref)
4192 : : {
4193 : 132388535 : cgraph_node *node = ultimate_alias_target (availability, ref);
4194 : :
4195 : 264781520 : while (node->thunk)
4196 : : {
4197 : 4450 : enum availability a;
4198 : :
4199 : 4450 : ref = node;
4200 : 4450 : node = node->callees->callee;
4201 : 8005 : node = node->ultimate_alias_target (availability ? &a : NULL, ref);
4202 : 4450 : if (availability && a < *availability)
4203 : 32 : *availability = a;
4204 : : }
4205 : 132388535 : return node;
4206 : : }
4207 : :
4208 : : /* Walk the alias chain to return the function cgraph_node is alias of.
4209 : : Walk through non virtual thunks, too. Thus we return either a function
4210 : : or a virtual thunk node.
4211 : : When AVAILABILITY is non-NULL, get minimal availability in the chain.
4212 : : When REF is non-NULL, assume that reference happens in symbol REF
4213 : : when determining the availability. */
4214 : :
4215 : : cgraph_node *
4216 : 33526946 : cgraph_node::function_or_virtual_thunk_symbol
4217 : : (enum availability *availability,
4218 : : struct symtab_node *ref)
4219 : : {
4220 : 33526946 : cgraph_node *node = ultimate_alias_target (availability, ref);
4221 : :
4222 : 67054817 : while (node->thunk && !thunk_info::get (node)->virtual_offset_p)
4223 : : {
4224 : 925 : enum availability a;
4225 : :
4226 : 925 : ref = node;
4227 : 925 : node = node->callees->callee;
4228 : 925 : node = node->ultimate_alias_target (availability ? &a : NULL, ref);
4229 : 925 : if (availability && a < *availability)
4230 : 296 : *availability = a;
4231 : : }
4232 : 33526946 : return node;
4233 : : }
4234 : :
4235 : : /* When doing LTO, read cgraph_node's body from disk if it is not already
4236 : : present. Also perform any necessary clone materializations. */
4237 : :
4238 : : bool
4239 : 6348160 : cgraph_node::get_untransformed_body ()
4240 : : {
4241 : 6348160 : lto_file_decl_data *file_data;
4242 : 6348160 : const char *data, *name;
4243 : 6348160 : size_t len;
4244 : 6348160 : tree decl = this->decl;
4245 : :
4246 : : /* See if there is clone to be materialized.
4247 : : (inline clones does not need materialization, but we can be seeing
4248 : : an inline clone of real clone). */
4249 : 6348160 : cgraph_node *p = this;
4250 : 9125706 : for (cgraph_node *c = clone_of; c; c = c->clone_of)
4251 : : {
4252 : 2777546 : if (c->decl != decl)
4253 : 128928 : p->materialize_clone ();
4254 : 2777546 : p = c;
4255 : : }
4256 : :
4257 : : /* Check if body is already there. Either we have gimple body or
4258 : : the function is thunk and in that case we set DECL_ARGUMENTS. */
4259 : 6348160 : if (DECL_ARGUMENTS (decl) || gimple_has_body_p (decl))
4260 : 6265132 : return false;
4261 : :
4262 : 166056 : gcc_assert (in_lto_p && !DECL_RESULT (decl));
4263 : :
4264 : 83028 : timevar_push (TV_IPA_LTO_GIMPLE_IN);
4265 : :
4266 : 83028 : file_data = lto_file_data;
4267 : 83028 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4268 : :
4269 : : /* We may have renamed the declaration, e.g., a static function. */
4270 : 83028 : name = lto_get_decl_name_mapping (file_data, name);
4271 : 83028 : struct lto_in_decl_state *decl_state
4272 : 83028 : = lto_get_function_in_decl_state (file_data, decl);
4273 : :
4274 : 83028 : cgraph_node *origin = this;
4275 : 166224 : while (origin->clone_of)
4276 : : origin = origin->clone_of;
4277 : :
4278 : 83028 : int stream_order = origin->order - file_data->order_base;
4279 : 166056 : data = lto_get_section_data (file_data, LTO_section_function_body,
4280 : : name, stream_order, &len,
4281 : 83028 : decl_state->compressed);
4282 : 83028 : if (!data)
4283 : 0 : fatal_error (input_location, "%s: section %s.%d is missing",
4284 : : file_data->file_name, name, stream_order);
4285 : :
4286 : 83028 : gcc_assert (DECL_STRUCT_FUNCTION (decl) == NULL);
4287 : :
4288 : 83028 : if (!quiet_flag)
4289 : 0 : fprintf (stderr, " in:%s", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4290 : 83028 : lto_input_function_body (file_data, this, data);
4291 : 83028 : lto_stats.num_function_bodies++;
4292 : 83028 : lto_free_section_data (file_data, LTO_section_function_body, name,
4293 : 83028 : data, len, decl_state->compressed);
4294 : 83028 : lto_free_function_in_decl_state_for_node (this);
4295 : : /* Keep lto file data so ipa-inline-analysis knows about cross module
4296 : : inlining. */
4297 : :
4298 : 83028 : timevar_pop (TV_IPA_LTO_GIMPLE_IN);
4299 : :
4300 : 83028 : return true;
4301 : : }
4302 : :
4303 : : /* Prepare function body. When doing LTO, read cgraph_node's body from disk
4304 : : if it is not already present. When some IPA transformations are scheduled,
4305 : : apply them. */
4306 : :
4307 : : bool
4308 : 28567 : cgraph_node::get_body (void)
4309 : : {
4310 : 28567 : bool updated;
4311 : :
4312 : 28567 : updated = get_untransformed_body ();
4313 : :
4314 : : /* Getting transformed body makes no sense for inline clones;
4315 : : we should never use this on real clones because they are materialized
4316 : : early.
4317 : : TODO: Materializing clones here will likely lead to smaller LTRANS
4318 : : footprint. */
4319 : 28567 : gcc_assert (!inlined_to && !clone_of);
4320 : 28567 : if (ipa_transforms_to_apply.exists ())
4321 : : {
4322 : 12241 : opt_pass *saved_current_pass = current_pass;
4323 : 12241 : FILE *saved_dump_file = dump_file;
4324 : 12241 : const char *saved_dump_file_name = dump_file_name;
4325 : 12241 : dump_flags_t saved_dump_flags = dump_flags;
4326 : 12241 : dump_file_name = NULL;
4327 : 12241 : set_dump_file (NULL);
4328 : :
4329 : 12241 : push_cfun (DECL_STRUCT_FUNCTION (decl));
4330 : :
4331 : 12241 : update_ssa (TODO_update_ssa_only_virtuals);
4332 : 12241 : execute_all_ipa_transforms (true);
4333 : 12241 : cgraph_edge::rebuild_edges ();
4334 : 12241 : free_dominance_info (CDI_DOMINATORS);
4335 : 12241 : free_dominance_info (CDI_POST_DOMINATORS);
4336 : 12241 : pop_cfun ();
4337 : 12241 : updated = true;
4338 : :
4339 : 12241 : current_pass = saved_current_pass;
4340 : 12241 : set_dump_file (saved_dump_file);
4341 : 12241 : dump_file_name = saved_dump_file_name;
4342 : 12241 : dump_flags = saved_dump_flags;
4343 : : }
4344 : 28567 : return updated;
4345 : : }
4346 : :
4347 : : /* Return the DECL_STRUCT_FUNCTION of the function. */
4348 : :
4349 : : struct function *
4350 : 220151 : cgraph_node::get_fun () const
4351 : : {
4352 : 220151 : const cgraph_node *node = this;
4353 : 220151 : struct function *fun = DECL_STRUCT_FUNCTION (node->decl);
4354 : :
4355 : 220151 : while (!fun && node->clone_of)
4356 : : {
4357 : 0 : node = node->clone_of;
4358 : 0 : fun = DECL_STRUCT_FUNCTION (node->decl);
4359 : : }
4360 : :
4361 : 220151 : return fun;
4362 : : }
4363 : :
4364 : : /* Reset all state within cgraph.cc so that we can rerun the compiler
4365 : : within the same process. For use by toplev::finalize. */
4366 : :
4367 : : void
4368 : 257130 : cgraph_cc_finalize (void)
4369 : : {
4370 : 257130 : nested_function_info::release ();
4371 : 257130 : thunk_info::release ();
4372 : 257130 : clone_info::release ();
4373 : 257130 : symtab = NULL;
4374 : :
4375 : 257130 : x_cgraph_nodes_queue = NULL;
4376 : :
4377 : 257130 : cgraph_fnver_htab = NULL;
4378 : 257130 : version_info_node = NULL;
4379 : 257130 : }
4380 : :
4381 : : /* A worker for call_for_symbol_and_aliases. */
4382 : :
4383 : : bool
4384 : 755951 : cgraph_node::call_for_symbol_and_aliases_1 (bool (*callback) (cgraph_node *,
4385 : : void *),
4386 : : void *data,
4387 : : bool include_overwritable)
4388 : : {
4389 : 755951 : ipa_ref *ref;
4390 : 1460834 : FOR_EACH_ALIAS (this, ref)
4391 : : {
4392 : 808406 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
4393 : 808406 : if (include_overwritable
4394 : 808406 : || alias->get_availability () > AVAIL_INTERPOSABLE)
4395 : 808406 : if (alias->call_for_symbol_and_aliases (callback, data,
4396 : : include_overwritable))
4397 : : return true;
4398 : : }
4399 : : return false;
4400 : : }
4401 : :
4402 : : /* Return true if NODE has thunk. */
4403 : :
4404 : : bool
4405 : 39101 : cgraph_node::has_thunk_p (cgraph_node *node, void *)
4406 : : {
4407 : 73252 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
4408 : 34151 : if (e->caller->thunk)
4409 : : return true;
4410 : : return false;
4411 : : }
4412 : :
4413 : : /* Expected frequency of executions within the function. */
4414 : :
4415 : : sreal
4416 : 219674481 : cgraph_edge::sreal_frequency ()
4417 : : {
4418 : 219674481 : return count.to_sreal_scale (caller->inlined_to
4419 : 219674481 : ? caller->inlined_to->count
4420 : 219674481 : : caller->count);
4421 : : }
4422 : :
4423 : : /* Expected frequency of executions within the function.
4424 : : If edge is speculative, sum all its indirect targets. */
4425 : :
4426 : : sreal
4427 : 921 : cgraph_edge::combined_sreal_frequency ()
4428 : : {
4429 : 921 : if (!speculative)
4430 : 857 : return sreal_frequency ();
4431 : 64 : cgraph_edge *e = this;
4432 : 64 : if (e->callee)
4433 : 0 : e = e->speculative_call_indirect_edge ();
4434 : 64 : sreal sum = e->sreal_frequency ();
4435 : 64 : for (e = e->first_speculative_call_target ();
4436 : 132 : e;
4437 : 68 : e = e->next_speculative_call_target ())
4438 : 68 : sum += e->sreal_frequency ();
4439 : 64 : return sum;
4440 : : }
4441 : :
4442 : :
4443 : : /* During LTO stream in this can be used to check whether call can possibly
4444 : : be internal to the current translation unit. */
4445 : :
4446 : : bool
4447 : 477402 : cgraph_edge::possibly_call_in_translation_unit_p (void)
4448 : : {
4449 : 477402 : gcc_checking_assert (in_lto_p && caller->prevailing_p ());
4450 : :
4451 : : /* While incremental linking we may end up getting function body later. */
4452 : 477402 : if (flag_incremental_link == INCREMENTAL_LINK_LTO)
4453 : : return true;
4454 : :
4455 : : /* We may be smarter here and avoid streaming in indirect calls we can't
4456 : : track, but that would require arranging streaming the indirect call
4457 : : summary first. */
4458 : 477173 : if (!callee)
4459 : : return true;
4460 : :
4461 : : /* If callee is local to the original translation unit, it will be
4462 : : defined. */
4463 : 474457 : if (!TREE_PUBLIC (callee->decl) && !DECL_EXTERNAL (callee->decl))
4464 : : return true;
4465 : :
4466 : : /* Otherwise we need to lookup prevailing symbol (symbol table is not merged,
4467 : : yet) and see if it is a definition. In fact we may also resolve aliases,
4468 : : but that is probably not too important. */
4469 : 478522 : symtab_node *node = callee;
4470 : 478522 : for (int n = 10; node->previous_sharing_asm_name && n ; n--)
4471 : 10096 : node = node->previous_sharing_asm_name;
4472 : 468426 : if (node->previous_sharing_asm_name)
4473 : 234 : node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (callee->decl));
4474 : 468426 : gcc_assert (TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl));
4475 : 468426 : return node->get_availability () >= AVAIL_INTERPOSABLE;
4476 : : }
4477 : :
4478 : : /* Return num_speculative_targets of this edge. */
4479 : :
4480 : : int
4481 : 103019 : cgraph_edge::num_speculative_call_targets_p (void)
4482 : : {
4483 : 103019 : return indirect_info ? indirect_info->num_speculative_call_targets : 0;
4484 : : }
4485 : :
4486 : : /* Check if function calls comdat local. This is used to recompute
4487 : : calls_comdat_local flag after function transformations. */
4488 : : bool
4489 : 49635234 : cgraph_node::check_calls_comdat_local_p ()
4490 : : {
4491 : 159182398 : for (cgraph_edge *e = callees; e; e = e->next_callee)
4492 : 3908712 : if (e->inline_failed
4493 : 118536369 : ? e->callee->comdat_local_p ()
4494 : 3908712 : : e->callee->check_calls_comdat_local_p ())
4495 : 52313 : return true;
4496 : : return false;
4497 : : }
4498 : :
4499 : : /* Return true if this node represents a former, i.e. an expanded, thunk. */
4500 : :
4501 : : bool
4502 : 5046723 : cgraph_node::former_thunk_p (void)
4503 : : {
4504 : 5046723 : if (thunk)
4505 : : return false;
4506 : 5046723 : thunk_info *i = thunk_info::get (this);
4507 : 5046723 : if (!i)
4508 : : return false;
4509 : 73 : gcc_checking_assert (i->fixed_offset || i->virtual_offset_p
4510 : : || i->indirect_offset);
4511 : : return true;
4512 : : }
4513 : :
4514 : : /* A stashed copy of "symtab" for use by selftest::symbol_table_test.
4515 : : This needs to be a global so that it can be a GC root, and thus
4516 : : prevent the stashed copy from being garbage-collected if the GC runs
4517 : : during a symbol_table_test. */
4518 : :
4519 : : symbol_table *saved_symtab;
4520 : :
4521 : : #if CHECKING_P
4522 : :
4523 : : namespace selftest {
4524 : :
4525 : : /* class selftest::symbol_table_test. */
4526 : :
4527 : : /* Constructor. Store the old value of symtab, and create a new one. */
4528 : :
4529 : 64 : symbol_table_test::symbol_table_test ()
4530 : : {
4531 : 64 : gcc_assert (saved_symtab == NULL);
4532 : 64 : saved_symtab = symtab;
4533 : 64 : symtab = new (ggc_alloc<symbol_table> ()) symbol_table ();
4534 : 64 : }
4535 : :
4536 : : /* Destructor. Restore the old value of symtab. */
4537 : :
4538 : 64 : symbol_table_test::~symbol_table_test ()
4539 : : {
4540 : 64 : gcc_assert (saved_symtab != NULL);
4541 : 64 : symtab = saved_symtab;
4542 : 64 : saved_symtab = NULL;
4543 : 64 : }
4544 : :
4545 : : /* Verify that symbol_table_test works. */
4546 : :
4547 : : static void
4548 : 4 : test_symbol_table_test ()
4549 : : {
4550 : : /* Simulate running two selftests involving symbol tables. */
4551 : 12 : for (int i = 0; i < 2; i++)
4552 : : {
4553 : 8 : symbol_table_test stt;
4554 : 8 : tree test_decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
4555 : : get_identifier ("test_decl"),
4556 : : build_function_type_list (void_type_node,
4557 : : NULL_TREE));
4558 : 8 : cgraph_node *node = cgraph_node::get_create (test_decl);
4559 : 8 : gcc_assert (node);
4560 : :
4561 : : /* Verify that the node has order 0 on both iterations,
4562 : : and thus that nodes have predictable dump names in selftests. */
4563 : 8 : ASSERT_EQ (node->order, 0);
4564 : 8 : ASSERT_STREQ (node->dump_name (), "test_decl/1");
4565 : 8 : }
4566 : 4 : }
4567 : :
4568 : : /* Run all of the selftests within this file. */
4569 : :
4570 : : void
4571 : 4 : cgraph_cc_tests ()
4572 : : {
4573 : 4 : test_symbol_table_test ();
4574 : 4 : }
4575 : :
4576 : : } // namespace selftest
4577 : :
4578 : : #endif /* CHECKING_P */
4579 : :
4580 : : #include "gt-cgraph.h"
|