Line data Source code
1 : /* Callgraph handling code.
2 : Copyright (C) 2003-2026 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 : #include "attr-callback.h"
73 : #include "callback-info.h"
74 :
75 : /* FIXME: Only for PROP_loops, but cgraph shouldn't have to know about this. */
76 : #include "tree-pass.h"
77 :
78 : /* Symbol table global context. */
79 : symbol_table *symtab;
80 :
81 : /* List of hooks triggered on cgraph_edge events. */
82 : struct cgraph_edge_hook_list {
83 : cgraph_edge_hook hook;
84 : void *data;
85 : struct cgraph_edge_hook_list *next;
86 : };
87 :
88 : /* List of hooks triggered on cgraph_node events. */
89 : struct cgraph_node_hook_list {
90 : cgraph_node_hook hook;
91 : void *data;
92 : struct cgraph_node_hook_list *next;
93 : };
94 :
95 : /* List of hooks triggered on events involving two cgraph_edges. */
96 : struct cgraph_2edge_hook_list {
97 : cgraph_2edge_hook hook;
98 : void *data;
99 : struct cgraph_2edge_hook_list *next;
100 : };
101 :
102 : /* List of hooks triggered on events involving two cgraph_nodes. */
103 : struct cgraph_2node_hook_list {
104 : cgraph_2node_hook hook;
105 : void *data;
106 : struct cgraph_2node_hook_list *next;
107 : };
108 :
109 : /* Hash descriptor for cgraph_function_version_info. */
110 :
111 : struct function_version_hasher : ggc_ptr_hash<cgraph_function_version_info>
112 : {
113 : static hashval_t hash (cgraph_function_version_info *);
114 : static bool equal (cgraph_function_version_info *,
115 : cgraph_function_version_info *);
116 : };
117 :
118 : /* Map a cgraph_node to cgraph_function_version_info using this htab.
119 : The cgraph_function_version_info has a THIS_NODE field that is the
120 : corresponding cgraph_node.. */
121 :
122 : static GTY(()) hash_table<function_version_hasher> *cgraph_fnver_htab = NULL;
123 :
124 : /* Hash function for cgraph_fnver_htab. */
125 : hashval_t
126 317877 : function_version_hasher::hash (cgraph_function_version_info *ptr)
127 : {
128 317877 : int uid = ptr->this_node->get_uid ();
129 317877 : return (hashval_t)(uid);
130 : }
131 :
132 : /* eq function for cgraph_fnver_htab. */
133 : bool
134 288779 : function_version_hasher::equal (cgraph_function_version_info *n1,
135 : cgraph_function_version_info *n2)
136 : {
137 288779 : return n1->this_node->get_uid () == n2->this_node->get_uid ();
138 : }
139 :
140 : /* Mark as GC root all allocated nodes. */
141 : static GTY(()) struct cgraph_function_version_info *
142 : version_info_node = NULL;
143 :
144 : /* Return true if NODE's address can be compared. */
145 :
146 : bool
147 5111996 : symtab_node::address_can_be_compared_p ()
148 : {
149 : /* Address of virtual tables and functions is never compared. */
150 5111996 : if (DECL_VIRTUAL_P (decl))
151 : return false;
152 : /* Address of C++ cdtors is never compared. */
153 5011395 : if (is_a <cgraph_node *> (this)
154 561530 : && (DECL_CXX_CONSTRUCTOR_P (decl)
155 557179 : || DECL_CXX_DESTRUCTOR_P (decl)))
156 : return false;
157 : /* Constant pool symbols addresses are never compared.
158 : flag_merge_constants permits us to assume the same on readonly vars. */
159 5005605 : if (is_a <varpool_node *> (this)
160 4449865 : && (DECL_IN_CONSTANT_POOL (decl)
161 4449862 : || ((flag_merge_constants >= 2 || DECL_MERGEABLE (decl))
162 3750 : && TREE_READONLY (decl) && !TREE_THIS_VOLATILE (decl))))
163 3746 : return false;
164 : return true;
165 : }
166 :
167 : /* Get the cgraph_function_version_info node corresponding to node. */
168 : cgraph_function_version_info *
169 141326498 : cgraph_node::function_version (void)
170 : {
171 141326498 : cgraph_function_version_info key;
172 141326498 : key.this_node = this;
173 :
174 141326498 : if (cgraph_fnver_htab == NULL)
175 : return NULL;
176 :
177 50942 : return cgraph_fnver_htab->find (&key);
178 : }
179 :
180 : /* If profile is IPA, turn it into local one. */
181 : void
182 0 : cgraph_node::make_profile_local ()
183 : {
184 0 : if (!count.ipa ().initialized_p ())
185 : return;
186 0 : if (!(count == profile_count::zero ()))
187 0 : count = count.guessed_local ();
188 0 : for (cgraph_edge *e = callees; e; e = e->next_callee)
189 : {
190 0 : if (!e->inline_failed)
191 0 : e->callee->make_profile_local ();
192 0 : if (!(e->count == profile_count::zero ()))
193 0 : e->count = e->count.guessed_local ();
194 : }
195 0 : for (cgraph_edge *e = indirect_calls; e; e = e->next_callee)
196 0 : if (!(e->count == profile_count::zero ()))
197 0 : e->count = e->count.guessed_local ();
198 : }
199 :
200 : /* Turn profile to global0. Walk into inlined functions.
201 : QUALITY must be GUESSED_GLOBAL0, GUESSED_GLOBAL0_ADJUSTED
202 : or GUESSED_GLOBAL0_AFDO */
203 : void
204 26 : cgraph_node::make_profile_global0 (profile_quality quality)
205 : {
206 26 : if (count == profile_count::zero ())
207 : ;
208 26 : else if (quality == GUESSED_GLOBAL0)
209 : {
210 23 : if (count.quality () == GUESSED_GLOBAL0)
211 : return;
212 23 : count = count.global0 ();
213 : }
214 3 : else if (quality == GUESSED_GLOBAL0_ADJUSTED)
215 : {
216 3 : if (count.quality () == GUESSED_GLOBAL0
217 3 : || count.quality () == GUESSED_GLOBAL0_ADJUSTED)
218 : return;
219 3 : count = count.global0adjusted ();
220 : }
221 0 : else if (quality == GUESSED_GLOBAL0_AFDO)
222 : {
223 0 : if (count.quality () == GUESSED_GLOBAL0
224 0 : || count.quality () == GUESSED_GLOBAL0_ADJUSTED
225 0 : || count.quality () == GUESSED_GLOBAL0_AFDO)
226 : return;
227 0 : count = count.global0afdo ();
228 : }
229 : else
230 0 : gcc_unreachable ();
231 68 : for (cgraph_edge *e = callees; e; e = e->next_callee)
232 : {
233 42 : if (!e->inline_failed)
234 0 : e->callee->make_profile_global0 (quality);
235 52 : if (e->count == profile_count::zero ())
236 : ;
237 32 : else if (quality == GUESSED_GLOBAL0)
238 28 : e->count = e->count.global0 ();
239 4 : else if (quality == GUESSED_GLOBAL0_ADJUSTED)
240 4 : e->count = e->count.global0adjusted ();
241 0 : else if (quality == GUESSED_GLOBAL0_AFDO)
242 0 : e->count = e->count.global0afdo ();
243 : else
244 0 : gcc_unreachable ();
245 : }
246 29 : for (cgraph_edge *e = indirect_calls; e; e = e->next_callee)
247 3 : if (e->count == profile_count::zero ())
248 : ;
249 3 : else if (quality == GUESSED_GLOBAL0)
250 1 : e->count = e->count.global0 ();
251 2 : else if (quality == GUESSED_GLOBAL0_ADJUSTED)
252 2 : e->count = e->count.global0adjusted ();
253 0 : else if (quality == GUESSED_GLOBAL0_AFDO)
254 0 : e->count = e->count.global0afdo ();
255 : else
256 0 : gcc_unreachable ();
257 : }
258 :
259 : /* Scale profile by NUM/DEN. Walk into inlined functions. */
260 :
261 : void
262 1682756 : cgraph_node::apply_scale (profile_count num, profile_count den)
263 : {
264 1814876 : if (num == den && !(num == profile_count::zero ()))
265 130205 : return;
266 :
267 2944729 : for (cgraph_edge *e = callees; e; e = e->next_callee)
268 : {
269 1392178 : if (!e->inline_failed)
270 182234 : e->callee->apply_scale (num, den);
271 1392178 : e->count = e->count.apply_scale (num, den);
272 : }
273 1579896 : for (cgraph_edge *e = indirect_calls; e; e = e->next_callee)
274 27345 : e->count = e->count.apply_scale (num, den);
275 1552551 : count = count.apply_scale (num, den);
276 : }
277 :
278 : /* Scale profile to given IPA_COUNT.
279 : IPA_COUNT should pass ipa_p () with a single exception.
280 : It can be also GUESSED_LOCAL in case we want to
281 : drop any IPA info about the profile. */
282 :
283 : void
284 114 : cgraph_node::scale_profile_to (profile_count ipa_count)
285 : {
286 : /* If we do not know the adjustment, it is better to keep profile
287 : as it is. */
288 114 : if (!ipa_count.initialized_p ()
289 114 : || ipa_count == count)
290 49 : return;
291 : /* ipa-cp converts value to guessed-local in case it believes
292 : that we lost track of IPA profile. */
293 91 : if (ipa_count.quality () == GUESSED_LOCAL)
294 : {
295 0 : make_profile_local ();
296 0 : return;
297 : }
298 91 : if (ipa_count == profile_count::zero ())
299 : {
300 23 : make_profile_global0 (GUESSED_GLOBAL0);
301 23 : return;
302 : }
303 68 : if (ipa_count == profile_count::adjusted_zero ())
304 : {
305 3 : make_profile_global0 (GUESSED_GLOBAL0_ADJUSTED);
306 3 : return;
307 : }
308 130 : gcc_assert (ipa_count.ipa () == ipa_count
309 : && !inlined_to);
310 65 : profile_count num = count.combine_with_ipa_count (ipa_count);
311 65 : profile_count den = count;
312 65 : profile_count::adjust_for_ipa_scaling (&num, &den);
313 65 : apply_scale (num, den);
314 : }
315 :
316 : /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
317 : corresponding to cgraph_node NODE. */
318 : cgraph_function_version_info *
319 1595 : cgraph_node::insert_new_function_version (void)
320 : {
321 1595 : version_info_node = NULL;
322 1595 : version_info_node = ggc_cleared_alloc<cgraph_function_version_info> ();
323 1595 : version_info_node->this_node = this;
324 1595 : version_info_node->assembler_name = DECL_ASSEMBLER_NAME (this->decl);
325 :
326 1595 : if (cgraph_fnver_htab == NULL)
327 209 : cgraph_fnver_htab = hash_table<function_version_hasher>::create_ggc (2);
328 :
329 1595 : *cgraph_fnver_htab->find_slot (version_info_node, INSERT)
330 1595 : = version_info_node;
331 1595 : return version_info_node;
332 : }
333 :
334 : /* Remove the cgraph_function_version_info node given by DECL_V. */
335 : void
336 109043597 : cgraph_node::delete_function_version (cgraph_function_version_info *decl_v)
337 : {
338 109043597 : if (decl_v == NULL)
339 : return;
340 :
341 270 : if (version_info_node == decl_v)
342 206 : version_info_node = NULL;
343 :
344 270 : if (decl_v->prev != NULL)
345 159 : decl_v->prev->next = decl_v->next;
346 :
347 270 : if (decl_v->next != NULL)
348 231 : decl_v->next->prev = decl_v->prev;
349 :
350 270 : if (cgraph_fnver_htab != NULL)
351 270 : 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 8993 : cgraph_node::add_function_version (cgraph_function_version_info *fn_v,
374 : tree decl)
375 : {
376 8993 : cgraph_node *decl_node = cgraph_node::get_create (decl);
377 8993 : cgraph_function_version_info *decl_v = NULL;
378 :
379 8993 : gcc_assert (decl_node != NULL);
380 :
381 8993 : decl_v = decl_node->function_version ();
382 :
383 : /* If the nodes are already linked, skip. */
384 8993 : if (decl_v != NULL && (decl_v->next || decl_v->prev))
385 : return;
386 :
387 194 : if (decl_v == NULL)
388 194 : decl_v = decl_node->insert_new_function_version ();
389 :
390 194 : gcc_assert (decl_v);
391 1091 : gcc_assert (fn_v);
392 :
393 : /* Go to start of the FMV structure. */
394 5594 : while (fn_v->prev)
395 : fn_v = fn_v->prev;
396 :
397 1091 : cgraph_function_version_info *insert_point_before = NULL;
398 1091 : 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 1091 : if (!is_function_default_version (decl))
403 : while (insert_point_after
404 10208 : && (targetm.compare_version_priority
405 4899 : (decl, insert_point_after->this_node->decl) > 0
406 703 : || is_function_default_version
407 703 : (insert_point_after->this_node->decl)
408 582 : || lookup_attribute
409 582 : ("target_clones",
410 582 : DECL_ATTRIBUTES (insert_point_after->this_node->decl))))
411 : {
412 4317 : insert_point_before = insert_point_after;
413 4317 : insert_point_after = insert_point_after->next;
414 : }
415 :
416 1091 : decl_v->prev = insert_point_before;
417 1091 : decl_v->next= insert_point_after;
418 :
419 1091 : if (insert_point_before)
420 956 : insert_point_before->next = decl_v;
421 1091 : if (insert_point_after)
422 681 : insert_point_after->prev = decl_v;
423 : }
424 :
425 : /* Initialize callgraph dump file. */
426 :
427 : void
428 318031 : symbol_table::initialize (void)
429 : {
430 318031 : if (!dump_file)
431 318029 : dump_file = dump_begin (TDI_cgraph, NULL);
432 :
433 318031 : if (!ipa_clones_dump_file)
434 318031 : ipa_clones_dump_file = dump_begin (TDI_clones, NULL);
435 318031 : }
436 :
437 : /* Allocate new callgraph node and insert it into basic data structures. */
438 :
439 : cgraph_node *
440 112903884 : symbol_table::create_empty (void)
441 : {
442 112903884 : cgraph_count++;
443 112903884 : 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 2262943 : symbol_table::add_edge_removal_hook (cgraph_edge_hook hook, void *data)
449 : {
450 2262943 : cgraph_edge_hook_list *entry;
451 4525886 : cgraph_edge_hook_list **ptr = &m_first_edge_removal_hook;
452 :
453 2262943 : entry = (cgraph_edge_hook_list *) xmalloc (sizeof (*entry));
454 2262943 : entry->hook = hook;
455 2262943 : entry->data = data;
456 2262943 : entry->next = NULL;
457 8944254 : while (*ptr)
458 6681311 : ptr = &(*ptr)->next;
459 2262943 : *ptr = entry;
460 2262943 : return entry;
461 : }
462 :
463 : /* Remove ENTRY from the list of hooks called on removing edges. */
464 : void
465 2262527 : symbol_table::remove_edge_removal_hook (cgraph_edge_hook_list *entry)
466 : {
467 2262527 : cgraph_edge_hook_list **ptr = &m_first_edge_removal_hook;
468 :
469 6971087 : while (*ptr != entry)
470 4708560 : ptr = &(*ptr)->next;
471 2262527 : *ptr = entry->next;
472 2262527 : free (entry);
473 2262527 : }
474 :
475 : /* Call all edge removal hooks. */
476 : void
477 46713842 : symbol_table::call_edge_removal_hooks (cgraph_edge *e)
478 : {
479 46713842 : cgraph_edge_hook_list *entry = m_first_edge_removal_hook;
480 90877898 : while (entry)
481 : {
482 44164056 : entry->hook (e, entry->data);
483 44164056 : entry = entry->next;
484 : }
485 46713842 : }
486 :
487 : /* Register HOOK to be called with DATA on each removed node. */
488 : cgraph_node_hook_list *
489 8334289 : symbol_table::add_cgraph_removal_hook (cgraph_node_hook hook, void *data)
490 : {
491 8334289 : cgraph_node_hook_list *entry;
492 16668578 : cgraph_node_hook_list **ptr = &m_first_cgraph_removal_hook;
493 :
494 8334289 : entry = (cgraph_node_hook_list *) xmalloc (sizeof (*entry));
495 8334289 : entry->hook = hook;
496 8334289 : entry->data = data;
497 8334289 : entry->next = NULL;
498 43305418 : while (*ptr)
499 34971129 : ptr = &(*ptr)->next;
500 8334289 : *ptr = entry;
501 8334289 : return entry;
502 : }
503 :
504 : /* Remove ENTRY from the list of hooks called on removing nodes. */
505 : void
506 8219543 : symbol_table::remove_cgraph_removal_hook (cgraph_node_hook_list *entry)
507 : {
508 8219543 : cgraph_node_hook_list **ptr = &m_first_cgraph_removal_hook;
509 :
510 38575348 : while (*ptr != entry)
511 30355805 : ptr = &(*ptr)->next;
512 8219543 : *ptr = entry->next;
513 8219543 : free (entry);
514 8219543 : }
515 :
516 : /* Call all node removal hooks. */
517 : void
518 109077213 : symbol_table::call_cgraph_removal_hooks (cgraph_node *node)
519 : {
520 109077213 : cgraph_node_hook_list *entry = m_first_cgraph_removal_hook;
521 153050601 : while (entry)
522 : {
523 43973388 : entry->hook (node, entry->data);
524 43973388 : entry = entry->next;
525 : }
526 109077213 : }
527 :
528 : /* Call all node removal hooks. */
529 : void
530 125870 : symbol_table::call_cgraph_insertion_hooks (cgraph_node *node)
531 : {
532 125870 : cgraph_node_hook_list *entry = m_first_cgraph_insertion_hook;
533 376874 : while (entry)
534 : {
535 251004 : entry->hook (node, entry->data);
536 251004 : entry = entry->next;
537 : }
538 125870 : }
539 :
540 :
541 : /* Register HOOK to be called with DATA on each inserted node. */
542 : cgraph_node_hook_list *
543 8843660 : symbol_table::add_cgraph_insertion_hook (cgraph_node_hook hook, void *data)
544 : {
545 8843660 : cgraph_node_hook_list *entry;
546 17687320 : cgraph_node_hook_list **ptr = &m_first_cgraph_insertion_hook;
547 :
548 8843660 : entry = (cgraph_node_hook_list *) xmalloc (sizeof (*entry));
549 8843660 : entry->hook = hook;
550 8843660 : entry->data = data;
551 8843660 : entry->next = NULL;
552 26165678 : while (*ptr)
553 17322018 : ptr = &(*ptr)->next;
554 8843660 : *ptr = entry;
555 8843660 : return entry;
556 : }
557 :
558 : /* Remove ENTRY from the list of hooks called on inserted nodes. */
559 : void
560 8689912 : symbol_table::remove_cgraph_insertion_hook (cgraph_node_hook_list *entry)
561 : {
562 8689912 : cgraph_node_hook_list **ptr = &m_first_cgraph_insertion_hook;
563 :
564 23937047 : while (*ptr != entry)
565 15247135 : ptr = &(*ptr)->next;
566 8689912 : *ptr = entry->next;
567 8689912 : free (entry);
568 8689912 : }
569 :
570 : /* Register HOOK to be called with DATA on each duplicated edge. */
571 : cgraph_2edge_hook_list *
572 2019508 : symbol_table::add_edge_duplication_hook (cgraph_2edge_hook hook, void *data)
573 : {
574 2019508 : cgraph_2edge_hook_list *entry;
575 4039016 : cgraph_2edge_hook_list **ptr = &m_first_edge_duplicated_hook;
576 :
577 2019508 : entry = (cgraph_2edge_hook_list *) xmalloc (sizeof (*entry));
578 2019508 : entry->hook = hook;
579 2019508 : entry->data = data;
580 2019508 : entry->next = NULL;
581 7422321 : while (*ptr)
582 5402813 : ptr = &(*ptr)->next;
583 2019508 : *ptr = entry;
584 2019508 : return entry;
585 : }
586 :
587 : /* Remove ENTRY from the list of hooks called on duplicating edges. */
588 : void
589 2019092 : symbol_table::remove_edge_duplication_hook (cgraph_2edge_hook_list *entry)
590 : {
591 2019092 : cgraph_2edge_hook_list **ptr = &m_first_edge_duplicated_hook;
592 :
593 5449154 : while (*ptr != entry)
594 3430062 : ptr = &(*ptr)->next;
595 2019092 : *ptr = entry->next;
596 2019092 : free (entry);
597 2019092 : }
598 :
599 : /* Call all edge duplication hooks. */
600 : void
601 7849272 : symbol_table::call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2)
602 : {
603 7849272 : cgraph_2edge_hook_list *entry = m_first_edge_duplicated_hook;
604 29457831 : while (entry)
605 : {
606 21608559 : entry->hook (cs1, cs2, entry->data);
607 21608559 : entry = entry->next;
608 : }
609 7849272 : }
610 :
611 : /* Register HOOK to be called with DATA on each duplicated node. */
612 : cgraph_2node_hook_list *
613 8186694 : symbol_table::add_cgraph_duplication_hook (cgraph_2node_hook hook, void *data)
614 : {
615 8186694 : cgraph_2node_hook_list *entry;
616 16373388 : cgraph_2node_hook_list **ptr = &m_first_cgraph_duplicated_hook;
617 :
618 8186694 : entry = (cgraph_2node_hook_list *) xmalloc (sizeof (*entry));
619 8186694 : entry->hook = hook;
620 8186694 : entry->data = data;
621 8186694 : entry->next = NULL;
622 40325710 : while (*ptr)
623 32139016 : ptr = &(*ptr)->next;
624 8186694 : *ptr = entry;
625 8186694 : return entry;
626 : }
627 :
628 : /* Remove ENTRY from the list of hooks called on duplicating nodes. */
629 : void
630 8085428 : symbol_table::remove_cgraph_duplication_hook (cgraph_2node_hook_list *entry)
631 : {
632 8085428 : cgraph_2node_hook_list **ptr = &m_first_cgraph_duplicated_hook;
633 :
634 36584314 : while (*ptr != entry)
635 28498886 : ptr = &(*ptr)->next;
636 8085428 : *ptr = entry->next;
637 8085428 : free (entry);
638 8085428 : }
639 :
640 : /* Call all node duplication hooks. */
641 : void
642 3303505 : symbol_table::call_cgraph_duplication_hooks (cgraph_node *node,
643 : cgraph_node *node2)
644 : {
645 3303505 : cgraph_2node_hook_list *entry = m_first_cgraph_duplicated_hook;
646 23398429 : while (entry)
647 : {
648 20094924 : entry->hook (node, node2, entry->data);
649 20094924 : entry = entry->next;
650 : }
651 3303505 : }
652 :
653 : /* Return cgraph node assigned to DECL. Create new one when needed. */
654 :
655 : cgraph_node *
656 109397398 : cgraph_node::create (tree decl)
657 : {
658 109397398 : cgraph_node *node = symtab->create_empty ();
659 109397398 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
660 :
661 109397398 : node->decl = decl;
662 109397398 : node->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition);
663 :
664 109337181 : if ((flag_openacc || flag_openmp)
665 109676014 : && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
666 : {
667 8575 : node->offloadable = 1;
668 8575 : if (ENABLE_OFFLOADING)
669 : g->have_offload = true;
670 : }
671 :
672 109397398 : if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
673 124 : node->ifunc_resolver = true;
674 :
675 109397398 : node->register_symbol ();
676 109397398 : maybe_record_nested_function (node);
677 :
678 109397398 : 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 608915746 : cgraph_node::get_create (tree decl)
686 : {
687 608915746 : cgraph_node *first_clone = cgraph_node::get (decl);
688 :
689 608915746 : if (first_clone && !first_clone->inlined_to)
690 : return first_clone;
691 :
692 109327482 : cgraph_node *node = cgraph_node::create (decl);
693 109327482 : 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 109327474 : else if (dump_file && symtab->state != PARSING)
706 1856 : 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 8146281 : cgraph_node::create_alias (tree alias, tree target)
717 : {
718 8146281 : cgraph_node *alias_node;
719 :
720 8146281 : gcc_assert (TREE_CODE (target) == FUNCTION_DECL
721 : || TREE_CODE (target) == IDENTIFIER_NODE);
722 8146281 : gcc_assert (TREE_CODE (alias) == FUNCTION_DECL);
723 8146281 : alias_node = cgraph_node::get_create (alias);
724 8146281 : gcc_assert (!alias_node->definition);
725 8146281 : alias_node->alias_target = target;
726 8146281 : alias_node->definition = true;
727 8146281 : alias_node->alias = true;
728 8146281 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias)) != NULL)
729 47 : alias_node->transparent_alias = alias_node->weakref = true;
730 8146281 : if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (alias)))
731 337 : alias_node->ifunc_resolver = true;
732 8146281 : 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 8126392 : cgraph_node::create_same_body_alias (tree alias, tree decl)
743 : {
744 8126392 : cgraph_node *n;
745 :
746 : /* If aliases aren't supported by the assembler, fail. */
747 8126392 : 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 8126392 : if (symtab->global_info_ready)
753 : return NULL;
754 :
755 8126392 : n = cgraph_node::create_alias (alias, decl);
756 8126392 : n->cpp_implicit_alias = true;
757 8126392 : if (symtab->cpp_implicit_aliases_done)
758 3734236 : 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 4622 : 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 4622 : cgraph_node *node;
775 :
776 4622 : node = cgraph_node::get (alias);
777 4622 : if (node)
778 3896 : node->reset ();
779 : else
780 726 : node = cgraph_node::create (alias);
781 :
782 : /* Make sure that if VIRTUAL_OFFSET is in sync with VIRTUAL_VALUE. */
783 4622 : gcc_checking_assert (virtual_offset
784 : ? virtual_value == wi::to_wide (virtual_offset)
785 : : virtual_value == 0);
786 :
787 4622 : node->thunk = true;
788 4622 : node->definition = true;
789 :
790 4622 : thunk_info *i;
791 4622 : thunk_info local_info;
792 4622 : if (symtab->state < CONSTRUCTION)
793 : i = &local_info;
794 : else
795 0 : i = thunk_info::get_create (node);
796 4622 : i->fixed_offset = fixed_offset;
797 4622 : i->virtual_value = virtual_value;
798 4622 : i->indirect_offset = indirect_offset;
799 4622 : i->alias = real_alias;
800 4622 : i->this_adjusting = this_adjusting;
801 4622 : i->virtual_offset_p = virtual_offset != NULL;
802 4622 : if (symtab->state < CONSTRUCTION)
803 4622 : i->register_early (node);
804 :
805 4622 : 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 234922133 : 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 234922133 : 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 46955158 : 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 46955158 : 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 287792699 : cgraph_edge_hasher::equal (cgraph_edge *x, gimple *y)
850 : {
851 287792699 : 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 4676 : cgraph_update_edge_in_call_site_hash (cgraph_edge *e)
858 : {
859 4676 : gimple *call = e->call_stmt;
860 4676 : *e->caller->call_site_hash->find_slot_with_hash
861 4676 : (call, cgraph_edge_hasher::hash (call), INSERT) = e;
862 4676 : }
863 :
864 : /* Add call graph edge E to call site hash of its caller. */
865 :
866 : static inline void
867 8884921 : 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 8884921 : if (e->speculative && e->indirect_unknown_callee)
872 : return;
873 : /* Callback edges share the call statement of the carrying edge, so hash
874 : the carrying edge instead. Internal callback edges have no carrying
875 : edge, so hash the callback edge directly. */
876 8884834 : if (e->callback_with_carrying_edge_p ())
877 : return;
878 8884824 : cgraph_edge **slot = e->caller->call_site_hash->find_slot_with_hash
879 8884824 : (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt), INSERT);
880 8884824 : if (*slot)
881 : {
882 4774 : cgraph_edge *edge = (cgraph_edge *) *slot;
883 4774 : gcc_assert (edge->speculative || edge->has_callback);
884 4774 : if (edge->has_callback)
885 : /* If the slot is already occupied, then the hashed edge is the
886 : callback-carrying edge, which is desired behavior. In some cases,
887 : the callback flag of E is not set yet and so the early exit above is
888 : not taken. */
889 : return;
890 4682 : if (e->callee && (!e->prev_callee
891 4 : || !e->prev_callee->speculative
892 4 : || e->prev_callee->call_stmt != e->call_stmt))
893 1126 : *slot = e;
894 : return;
895 : }
896 8880050 : gcc_assert (!*slot || e->speculative);
897 8880050 : *slot = e;
898 : }
899 :
900 : /* Return the callgraph edge representing the GIMPLE_CALL statement
901 : CALL_STMT. */
902 :
903 : cgraph_edge *
904 218149516 : cgraph_node::get_edge (gimple *call_stmt)
905 : {
906 218149516 : cgraph_edge *e, *e2;
907 218149516 : int n = 0;
908 :
909 218149516 : if (call_site_hash)
910 36808635 : return call_site_hash->find_with_hash
911 36808635 : (call_stmt, cgraph_edge_hasher::hash (call_stmt));
912 :
913 : /* This loop may turn out to be performance problem. In such case adding
914 : hashtables into call nodes with very many edges is probably best
915 : solution. It is not good idea to add pointer into CALL_EXPR itself
916 : because we want to make possible having multiple cgraph nodes representing
917 : different clones of the same body before the body is actually cloned. */
918 1791607033 : for (e = callees; e; e = e->next_callee)
919 : {
920 1741938792 : if (e->call_stmt == call_stmt)
921 : break;
922 1610266152 : n++;
923 : }
924 :
925 181340881 : if (!e)
926 63831356 : for (e = indirect_calls; e; e = e->next_callee)
927 : {
928 17076042 : if (e->call_stmt == call_stmt)
929 : break;
930 14163115 : n++;
931 : }
932 :
933 : /* We want to work with the callback-carrying edge whenever possible. When it
934 : comes to callback edges, a call statement might have multiple callback
935 : edges attached to it. These can be easily obtained from the carrying edge
936 : instead. */
937 181340881 : if (e && e->callback_with_carrying_edge_p ())
938 57032 : e = e->get_callback_carrying_edge ();
939 :
940 181340881 : if (n > 100)
941 : {
942 32894 : call_site_hash = hash_table<cgraph_edge_hasher>::create_ggc (120);
943 3372146 : for (e2 = callees; e2; e2 = e2->next_callee)
944 3339252 : cgraph_add_edge_to_call_site_hash (e2);
945 120239 : for (e2 = indirect_calls; e2; e2 = e2->next_callee)
946 87345 : cgraph_add_edge_to_call_site_hash (e2);
947 : }
948 :
949 : return e;
950 : }
951 :
952 : /* Change field call_stmt of edge E to NEW_STMT. If UPDATE_DERIVED_EDGES and E
953 : is any component of speculative edge, then update all components.
954 : speculations can be resolved in the process and edge can be removed and
955 : deallocated. if update_derived_edges and e is a part of a callback pair,
956 : update all associated edges and return their carrying edge. return the edge
957 : that now represents the call. */
958 :
959 : cgraph_edge *
960 3106997 : cgraph_edge::set_call_stmt (cgraph_edge *e, gcall *new_stmt,
961 : bool update_derived_edges)
962 : {
963 3107750 : tree decl;
964 :
965 3107750 : cgraph_node *new_direct_callee = NULL;
966 3078568 : if ((e->indirect_unknown_callee || e->speculative)
967 3153031 : && (decl = gimple_call_fndecl (new_stmt)))
968 : {
969 : /* Constant propagation and especially inlining can turn an indirect call
970 : into a direct one. */
971 0 : new_direct_callee = cgraph_node::get (decl);
972 0 : gcc_checking_assert (new_direct_callee);
973 : }
974 :
975 : /* Speculative edges has three component, update all of them
976 : when asked to. */
977 3107750 : if (update_derived_edges && e->speculative
978 : /* If we are about to resolve the speculation by calling make_direct
979 : below, do not bother going over all the speculative edges now. */
980 7059 : && !new_direct_callee)
981 : {
982 7059 : cgraph_edge *direct, *indirect, *next;
983 7059 : ipa_ref *ref;
984 7059 : bool e_indirect = e->indirect_unknown_callee;
985 7059 : int n = 0;
986 :
987 7059 : direct = e->first_speculative_call_target ();
988 7059 : indirect = e->speculative_call_indirect_edge ();
989 :
990 7059 : gcall *old_stmt = direct->call_stmt;
991 16099 : for (cgraph_edge *d = direct; d; d = next)
992 : {
993 9040 : next = d->next_speculative_call_target ();
994 9040 : cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
995 9040 : gcc_assert (d2 == d);
996 9040 : n++;
997 : }
998 7059 : gcc_checking_assert (indirect->num_speculative_call_targets_p () == n);
999 26902 : for (unsigned int i = 0; e->caller->iterate_reference (i, ref); i++)
1000 19843 : if (ref->speculative && ref->stmt == old_stmt)
1001 : {
1002 9040 : ref->stmt = new_stmt;
1003 9040 : n--;
1004 : }
1005 :
1006 7059 : indirect = set_call_stmt (indirect, new_stmt, false);
1007 7059 : return e_indirect ? indirect : direct;
1008 : }
1009 :
1010 3100691 : if (new_direct_callee)
1011 0 : e = make_direct (e, new_direct_callee);
1012 :
1013 : /* When updating a callback or a callback-carrying edge, update every edge
1014 : involved. */
1015 3100691 : if (update_derived_edges
1016 3100691 : && (e->callback_with_carrying_edge_p () || e->has_callback))
1017 : {
1018 753 : cgraph_edge *current, *next, *carrying;
1019 753 : carrying = e->has_callback ? e : e->get_callback_carrying_edge ();
1020 :
1021 753 : current = e->first_callback_edge ();
1022 753 : if (current)
1023 : {
1024 101 : for (cgraph_edge *d = current; d; d = next)
1025 : {
1026 51 : next = d->next_callback_edge ();
1027 51 : cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
1028 51 : gcc_assert (d2 == d);
1029 : }
1030 : }
1031 753 : carrying = set_call_stmt (carrying, new_stmt, false);
1032 753 : return carrying;
1033 : }
1034 :
1035 : /* Only direct speculative edges go to call_site_hash. */
1036 3099938 : if (e->caller->call_site_hash
1037 611275 : && (!e->speculative || !e->indirect_unknown_callee)
1038 : /* It is possible that edge was previously speculative. In this case
1039 : we have different value in call stmt hash which needs preserving. */
1040 3711180 : && e->caller->get_edge (e->call_stmt) == e)
1041 606566 : e->caller->call_site_hash->remove_elt_with_hash
1042 606566 : (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt));
1043 :
1044 3099938 : e->call_stmt = new_stmt;
1045 :
1046 3099938 : function *fun = DECL_STRUCT_FUNCTION (e->caller->decl);
1047 3099938 : e->can_throw_external = stmt_can_throw_external (fun, new_stmt);
1048 : /* Update call stite hash. For speculative calls we only record the first
1049 : direct edge. */
1050 3099938 : if (e->caller->call_site_hash
1051 611275 : && (!e->speculative
1052 66 : || (e->callee
1053 33 : && (!e->prev_callee || !e->prev_callee->speculative
1054 20 : || e->prev_callee->call_stmt != e->call_stmt))
1055 33 : || (e->speculative && !e->callee)))
1056 611275 : cgraph_add_edge_to_call_site_hash (e);
1057 : return e;
1058 : }
1059 :
1060 : /* Allocate a cgraph_edge structure and fill it with data according to the
1061 : parameters of which only CALLEE can be NULL (when creating an indirect call
1062 : edge). CLONING_P should be set if properties that are copied from an
1063 : original edge should not be calculated. */
1064 :
1065 : cgraph_edge *
1066 47158125 : symbol_table::create_edge (cgraph_node *caller, cgraph_node *callee,
1067 : gcall *call_stmt, profile_count count,
1068 : bool indir_unknown_callee, bool cloning_p)
1069 : {
1070 47158125 : cgraph_edge *edge;
1071 :
1072 : /* LTO does not actually have access to the call_stmt since these
1073 : have not been loaded yet. */
1074 47158125 : if (call_stmt)
1075 : {
1076 : /* This is a rather expensive check possibly triggering
1077 : construction of call stmt hashtable. */
1078 46290039 : cgraph_edge *e;
1079 46290039 : gcc_checking_assert (!(e = caller->get_edge (call_stmt))
1080 : || e->speculative || e->has_callback || e->callback);
1081 :
1082 46290039 : gcc_assert (is_gimple_call (call_stmt));
1083 : }
1084 :
1085 47158125 : edge = ggc_alloc<cgraph_edge> ();
1086 47158125 : edge->m_summary_id = -1;
1087 47158125 : edges_count++;
1088 :
1089 47158125 : ++edges_max_uid;
1090 47158125 : gcc_assert (edges_max_uid != 0);
1091 47158125 : edge->m_uid = edges_max_uid;
1092 47158125 : edge->aux = NULL;
1093 47158125 : edge->caller = caller;
1094 47158125 : edge->callee = callee;
1095 47158125 : edge->prev_caller = NULL;
1096 47158125 : edge->next_caller = NULL;
1097 47158125 : edge->prev_callee = NULL;
1098 47158125 : edge->next_callee = NULL;
1099 47158125 : edge->lto_stmt_uid = 0;
1100 47158125 : edge->speculative_id = 0;
1101 :
1102 47158125 : edge->count = count;
1103 47158125 : edge->call_stmt = call_stmt;
1104 47158125 : edge->indirect_info = NULL;
1105 47158125 : edge->indirect_inlining_edge = 0;
1106 47158125 : edge->speculative = false;
1107 47158125 : edge->has_callback = false;
1108 47158125 : edge->callback = false;
1109 47158125 : edge->indirect_unknown_callee = indir_unknown_callee;
1110 47158125 : if (call_stmt && caller->call_site_hash)
1111 4847049 : cgraph_add_edge_to_call_site_hash (edge);
1112 :
1113 47158125 : if (cloning_p)
1114 : return edge;
1115 :
1116 39338346 : edge->can_throw_external
1117 39338346 : = call_stmt ? stmt_can_throw_external (DECL_STRUCT_FUNCTION (caller->decl),
1118 : call_stmt) : false;
1119 39338346 : edge->inline_failed = CIF_FUNCTION_NOT_CONSIDERED;
1120 39338346 : edge->call_stmt_cannot_inline_p = false;
1121 :
1122 39338346 : if (opt_for_fn (edge->caller->decl, flag_devirtualize)
1123 39338346 : && call_stmt && DECL_STRUCT_FUNCTION (caller->decl))
1124 30871183 : edge->in_polymorphic_cdtor
1125 30871183 : = decl_maybe_in_construction_p (NULL, NULL, call_stmt,
1126 : caller->decl);
1127 : else
1128 8467163 : edge->in_polymorphic_cdtor = caller->thunk;
1129 :
1130 38655164 : if (callee && symtab->state != LTO_STREAMING
1131 77388190 : && edge->callee->comdat_local_p ())
1132 7295 : edge->caller->calls_comdat_local = true;
1133 :
1134 : return edge;
1135 : }
1136 :
1137 : /* Create edge from a given function to CALLEE in the cgraph. CLONING_P should
1138 : be set if properties that are copied from an original edge should not be
1139 : calculated. */
1140 :
1141 : cgraph_edge *
1142 46292505 : cgraph_node::create_edge (cgraph_node *callee,
1143 : gcall *call_stmt, profile_count count, bool cloning_p)
1144 : {
1145 46292505 : cgraph_edge *edge = symtab->create_edge (this, callee, call_stmt, count,
1146 : false, cloning_p);
1147 :
1148 46292505 : if (!cloning_p)
1149 38655164 : initialize_inline_failed (edge);
1150 :
1151 46292505 : edge->next_caller = callee->callers;
1152 46292505 : if (callee->callers)
1153 36153554 : callee->callers->prev_caller = edge;
1154 46292505 : edge->next_callee = callees;
1155 46292505 : if (callees)
1156 35878195 : callees->prev_callee = edge;
1157 46292505 : callees = edge;
1158 46292505 : callee->callers = edge;
1159 :
1160 46292505 : return edge;
1161 : }
1162 :
1163 : /* Create an indirect edge to a (yet-)undetermined callee. CALL_STMT is the
1164 : corresponding statement, if available, ECF_FLAGS and COUNT are corresponding
1165 : gimple call flags and profiling count respectively. CLONING_P should be set
1166 : if properties that are copied from an original edge should not be
1167 : calculated. */
1168 :
1169 : cgraph_edge *
1170 865620 : cgraph_node::create_indirect_edge (gcall *call_stmt, int ecf_flags,
1171 : profile_count count, bool cloning_p)
1172 : {
1173 865620 : cgraph_edge *edge = symtab->create_edge (this, NULL, call_stmt, count, true,
1174 : cloning_p);
1175 :
1176 865620 : if (!cloning_p)
1177 : {
1178 683182 : initialize_inline_failed (edge);
1179 :
1180 683182 : tree target = NULL_TREE;
1181 683182 : if (call_stmt)
1182 683182 : target = gimple_call_fn (call_stmt);
1183 683182 : if (target && virtual_method_call_p (target))
1184 : {
1185 96638 : ipa_polymorphic_call_context context (decl, target, call_stmt);
1186 96638 : HOST_WIDE_INT token = tree_to_shwi (OBJ_TYPE_REF_TOKEN (target));
1187 96638 : tree type = obj_type_ref_class (target);
1188 96638 : edge->indirect_info
1189 96638 : = (new (ggc_alloc<cgraph_polymorphic_indirect_info> ())
1190 : cgraph_polymorphic_indirect_info (ecf_flags, context, token,
1191 96638 : type));
1192 : }
1193 586544 : else if (target && TREE_CODE (target) == SSA_NAME)
1194 579501 : edge->indirect_info
1195 579501 : = (new (ggc_alloc<cgraph_simple_indirect_info> ())
1196 579501 : cgraph_simple_indirect_info (ecf_flags));
1197 : else
1198 7043 : edge->indirect_info
1199 7043 : = (new (ggc_alloc<cgraph_indirect_call_info> ())
1200 7043 : cgraph_indirect_call_info(CIIK_UNSPECIFIED, ecf_flags));
1201 : }
1202 :
1203 865620 : edge->next_callee = indirect_calls;
1204 865620 : if (indirect_calls)
1205 414142 : indirect_calls->prev_callee = edge;
1206 865620 : indirect_calls = edge;
1207 :
1208 865620 : return edge;
1209 : }
1210 :
1211 : /* Remove the edge from the list of the callees of the caller. */
1212 :
1213 : void
1214 4794076 : cgraph_edge::remove_caller (void)
1215 : {
1216 4794076 : if (prev_callee)
1217 3940254 : prev_callee->next_callee = next_callee;
1218 4794076 : if (next_callee)
1219 3284279 : next_callee->prev_callee = prev_callee;
1220 4794076 : if (!prev_callee)
1221 : {
1222 853822 : if (indirect_unknown_callee)
1223 1281 : caller->indirect_calls = next_callee;
1224 : else
1225 852541 : caller->callees = next_callee;
1226 : }
1227 4794076 : if (caller->call_site_hash
1228 4794076 : && this == caller->get_edge (call_stmt))
1229 650457 : caller->call_site_hash->remove_elt_with_hash
1230 650457 : (call_stmt, cgraph_edge_hasher::hash (call_stmt));
1231 4794076 : }
1232 :
1233 : /* Put the edge onto the free list. */
1234 :
1235 : void
1236 46713842 : symbol_table::free_edge (cgraph_edge *e)
1237 : {
1238 46713842 : edges_count--;
1239 46713842 : if (e->m_summary_id != -1)
1240 22088380 : edge_released_summary_ids.safe_push (e->m_summary_id);
1241 :
1242 46713842 : if (e->indirect_info)
1243 857949 : ggc_free (e->indirect_info);
1244 46713842 : ggc_free (e);
1245 46713842 : }
1246 :
1247 : /* Remove the edge in the cgraph. */
1248 :
1249 : void
1250 116139 : cgraph_edge::remove (cgraph_edge *edge)
1251 : {
1252 : /* Call all edge removal hooks. */
1253 116139 : symtab->call_edge_removal_hooks (edge);
1254 :
1255 116139 : if (!edge->indirect_unknown_callee)
1256 : /* Remove from callers list of the callee. */
1257 113467 : edge->remove_callee ();
1258 :
1259 : /* Remove from callees list of the callers. */
1260 116139 : edge->remove_caller ();
1261 :
1262 : /* Put the edge onto the free list. */
1263 116139 : symtab->free_edge (edge);
1264 116139 : }
1265 :
1266 : /* Returns the next speculative_id based on currently in use
1267 : for the given statement for the edge.
1268 : Returns 0 if no speculative edges exist for this statement. */
1269 :
1270 : int
1271 17614 : cgraph_edge::get_next_speculative_id ()
1272 : {
1273 17614 : int max_id = -1;
1274 :
1275 : /* If this edge is not yet speculative, there are no existing speculative
1276 : edges for this call site, so return 0. */
1277 17614 : if (!speculative)
1278 : return 0;
1279 :
1280 : /* Iterate only through speculative edges for this specific call site. */
1281 0 : for (cgraph_edge *e = first_speculative_call_target ();
1282 0 : e;
1283 0 : e = e->next_speculative_call_target ())
1284 : {
1285 0 : if (e->speculative_id > max_id)
1286 : max_id = e->speculative_id;
1287 : }
1288 :
1289 0 : return max_id + 1;
1290 : }
1291 :
1292 :
1293 : /* Turn edge into speculative call calling N2. Update
1294 : the profile so the direct call is taken COUNT times
1295 : with FREQUENCY.
1296 :
1297 : At clone materialization time, the indirect call E will
1298 : be expanded as:
1299 :
1300 : if (call_dest == N2)
1301 : n2 ();
1302 : else
1303 : call call_dest
1304 :
1305 : At this time the function just creates the direct call,
1306 : the reference representing the if conditional and attaches
1307 : them all to the original indirect call statement.
1308 :
1309 : speculative_id is used to link direct calls with their corresponding
1310 : IPA_REF_ADDR references when representing speculative calls.
1311 :
1312 : Return direct edge created. */
1313 :
1314 : cgraph_edge *
1315 15994 : cgraph_edge::make_speculative (cgraph_node *n2, profile_count direct_count,
1316 : unsigned int speculative_id)
1317 : {
1318 15994 : cgraph_node *n = caller;
1319 15994 : ipa_ref *ref = NULL;
1320 15994 : cgraph_edge *e2;
1321 :
1322 15994 : if (dump_file)
1323 29 : fprintf (dump_file, "Indirect call -> speculative call %s => %s\n",
1324 : n->dump_name (), n2->dump_name ());
1325 15994 : speculative = true;
1326 15994 : e2 = n->create_edge (n2, call_stmt, direct_count);
1327 15994 : initialize_inline_failed (e2);
1328 15994 : e2->speculative = true;
1329 15994 : if (TREE_NOTHROW (n2->decl))
1330 : e2->can_throw_external = false;
1331 : else
1332 5367 : e2->can_throw_external = can_throw_external;
1333 15994 : e2->lto_stmt_uid = lto_stmt_uid;
1334 15994 : e2->speculative_id = speculative_id;
1335 15994 : e2->in_polymorphic_cdtor = in_polymorphic_cdtor;
1336 15994 : indirect_info->num_speculative_call_targets++;
1337 15994 : count -= e2->count;
1338 15994 : symtab->call_edge_duplication_hooks (this, e2);
1339 15994 : ref = n->create_reference (n2, IPA_REF_ADDR, call_stmt);
1340 15994 : ref->lto_stmt_uid = lto_stmt_uid;
1341 15994 : ref->speculative_id = speculative_id;
1342 15994 : ref->speculative = speculative;
1343 15994 : n2->mark_address_taken ();
1344 15994 : return e2;
1345 : }
1346 :
1347 : /* Create a callback edge calling N2. Callback edges
1348 : never get turned into actual calls, they are just used
1349 : as clues and allow for optimizing functions which do not
1350 : have any callsites during compile time, e.g. functions
1351 : passed to standard library functions.
1352 :
1353 : The edge will be attached to the same call statement as
1354 : the callback-carrying edge, which is the instance this method
1355 : is called on.
1356 :
1357 : FN_IDX is the index of the callback function in dispatching function's
1358 : argument list. ATTR is the attribute used to derive the edge.
1359 :
1360 : Return the resulting callback edge. */
1361 :
1362 : cgraph_edge *
1363 15903 : cgraph_edge::make_callback (cgraph_node *n2, unsigned fn_idx, tree attr)
1364 : {
1365 15903 : cgraph_node *n = caller;
1366 15903 : cgraph_edge *e2;
1367 :
1368 15903 : has_callback = true;
1369 15903 : e2 = n->create_edge (n2, call_stmt, count);
1370 15903 : if (dump_file)
1371 6 : fprintf (
1372 : dump_file,
1373 : "Created callback edge %s -> %s belonging to carrying edge %s -> %s\n",
1374 6 : e2->caller->dump_name (), e2->callee->dump_name (), caller->dump_name (),
1375 6 : callee->dump_name ());
1376 15903 : e2->inline_failed = CIF_CALLBACK_EDGE;
1377 15903 : e2->callback = true;
1378 15903 : if (TREE_NOTHROW (n2->decl))
1379 : e2->can_throw_external = false;
1380 : else
1381 309 : e2->can_throw_external = can_throw_external;
1382 15903 : e2->lto_stmt_uid = lto_stmt_uid;
1383 15903 : callback_info *ci = callback_info_sum->get_create (e2);
1384 15903 : ci->init (e2, fn_idx, attr);
1385 15903 : symtab->call_edge_duplication_hooks (this, e2);
1386 15903 : n2->mark_address_taken ();
1387 15903 : return e2;
1388 : }
1389 :
1390 : /* Create a callback edge, representing an indirect call to target
1391 : passed to an internal function by argument. As internal calls are not
1392 : represented in the callgraph, the created edge won't have any associated
1393 : dispatching edge. The created callback edge will be attached to the
1394 : internal call statement STMT. Returns created callback edge. */
1395 :
1396 : cgraph_edge *
1397 211 : cgraph_edge::make_callback_internal (cgraph_node *caller, cgraph_node *target,
1398 : gcall *call_stmt)
1399 : {
1400 211 : cgraph_edge *ret;
1401 :
1402 211 : ret
1403 211 : = caller->create_edge (target, call_stmt, profile_count::uninitialized ());
1404 211 : if (dump_file)
1405 : {
1406 13 : fprintf (dump_file,
1407 : "Created callback edge %s -> %s belonging to internal call ",
1408 13 : ret->caller->dump_name (), ret->callee->dump_name ());
1409 13 : print_gimple_stmt (dump_file, call_stmt, 0);
1410 : }
1411 211 : ret->inline_failed = CIF_CALLBACK_EDGE;
1412 211 : ret->callback = true;
1413 211 : if (TREE_NOTHROW (target->decl))
1414 184 : ret->can_throw_external = false;
1415 211 : target->mark_address_taken ();
1416 211 : callback_info::create_internal_summary (ret, IFN_ASSUME);
1417 211 : return ret;
1418 : }
1419 :
1420 : /* Returns the callback_carrying edge of a callback edge on which
1421 : it is called on or NULL when no such edge can be found.
1422 :
1423 : An edge is taken to be the callback-carrying if it has it's has_callback
1424 : flag set and the edges share their call statements. */
1425 :
1426 : cgraph_edge *
1427 86002 : cgraph_edge::get_callback_carrying_edge ()
1428 : {
1429 86002 : gcc_checking_assert (callback);
1430 86002 : cgraph_edge *e;
1431 654673 : for (e = caller->callees; e; e = e->next_callee)
1432 : {
1433 653160 : if (e->has_callback && e->call_stmt == call_stmt
1434 84489 : && e->lto_stmt_uid == lto_stmt_uid)
1435 : break;
1436 : }
1437 86002 : return e;
1438 : }
1439 :
1440 : /* Returns TRUE iff THIS is a callback edge with a carrying edge. */
1441 : bool
1442 146557325 : cgraph_edge::callback_with_carrying_edge_p () const
1443 : {
1444 : /* Callback edges are always direct, i.e. callee != NULL. */
1445 146557325 : return callback && !callee->assume_function;
1446 : }
1447 :
1448 : /* Returns the first callback edge in the list of callees of the caller node.
1449 : Note that the edges might be in arbitrary order. Must be called on a
1450 : callback or callback-carrying edge. */
1451 :
1452 : cgraph_edge *
1453 50650 : cgraph_edge::first_callback_edge ()
1454 : {
1455 50650 : gcc_checking_assert (has_callback || callback);
1456 50650 : cgraph_edge *e = NULL;
1457 230082 : for (e = caller->callees; e; e = e->next_callee)
1458 : {
1459 212198 : if (e->callback && e->call_stmt == call_stmt
1460 32766 : && e->lto_stmt_uid == lto_stmt_uid)
1461 : break;
1462 : }
1463 50650 : return e;
1464 : }
1465 :
1466 : /* Given a callback edge, returns the next callback edge belonging to the same
1467 : carrying edge. Must be called on a callback edge, not the callback-carrying
1468 : edge. */
1469 :
1470 : cgraph_edge *
1471 32774 : cgraph_edge::next_callback_edge ()
1472 : {
1473 32774 : gcc_checking_assert (callback);
1474 32774 : cgraph_edge *e = NULL;
1475 316855 : for (e = next_callee; e; e = e->next_callee)
1476 : {
1477 284089 : if (e->callback && e->call_stmt == call_stmt
1478 8 : && e->lto_stmt_uid == lto_stmt_uid)
1479 : break;
1480 : }
1481 32774 : return e;
1482 : }
1483 :
1484 : /* When called on a callback-carrying edge, removes all of its attached callback
1485 : edges and sets has_callback to FALSE. */
1486 :
1487 : void
1488 3 : cgraph_edge::purge_callback_edges ()
1489 : {
1490 3 : gcc_checking_assert (has_callback);
1491 3 : cgraph_edge *e, *next;
1492 6 : for (e = first_callback_edge (); e; e = next)
1493 : {
1494 3 : next = e->next_callback_edge ();
1495 3 : cgraph_edge::remove (e);
1496 : }
1497 3 : has_callback = false;
1498 3 : }
1499 :
1500 : /* Speculative call consists of an indirect edge and one or more
1501 : direct edge+ref pairs.
1502 :
1503 : Given an edge which is part of speculative call, return the first
1504 : direct call edge in the speculative call sequence. */
1505 :
1506 : cgraph_edge *
1507 50395 : cgraph_edge::first_speculative_call_target ()
1508 : {
1509 50395 : cgraph_edge *e = this;
1510 :
1511 50395 : gcc_checking_assert (e->speculative);
1512 50395 : if (e->callee)
1513 : {
1514 14975 : while (e->prev_callee && e->prev_callee->speculative
1515 1391 : && e->prev_callee->call_stmt == e->call_stmt
1516 40765 : && e->prev_callee->lto_stmt_uid == e->lto_stmt_uid)
1517 : e = e->prev_callee;
1518 : return e;
1519 : }
1520 : /* Call stmt site hash always points to the first target of the
1521 : speculative call sequence. */
1522 9630 : if (e->call_stmt)
1523 9589 : return e->caller->get_edge (e->call_stmt);
1524 57 : for (cgraph_edge *e2 = e->caller->callees; true; e2 = e2->next_callee)
1525 57 : if (e2->speculative
1526 47 : && e->call_stmt == e2->call_stmt
1527 47 : && e->lto_stmt_uid == e2->lto_stmt_uid)
1528 : return e2;
1529 : }
1530 :
1531 : /* We always maintain first direct edge in the call site hash, if one
1532 : exists. E is going to be removed. See if it is first one and update
1533 : hash accordingly. INDIRECT is the indirect edge of speculative call.
1534 : We assume that INDIRECT->num_speculative_call_targets_p () is already
1535 : updated for removal of E. */
1536 : static void
1537 39521 : update_call_stmt_hash_for_removing_direct_edge (cgraph_edge *e,
1538 : cgraph_edge *indirect)
1539 : {
1540 39521 : if (e->caller->call_site_hash)
1541 : {
1542 4676 : if (e->caller->get_edge (e->call_stmt) != e)
1543 : ;
1544 4676 : else if (!indirect->num_speculative_call_targets_p ())
1545 3891 : cgraph_update_edge_in_call_site_hash (indirect);
1546 : else
1547 : {
1548 785 : gcc_checking_assert (e->next_callee && e->next_callee->speculative
1549 : && e->next_callee->call_stmt == e->call_stmt);
1550 785 : cgraph_update_edge_in_call_site_hash (e->next_callee);
1551 : }
1552 : }
1553 39521 : }
1554 :
1555 : /* Speculative call EDGE turned out to be direct call to CALLEE_DECL. Remove
1556 : the speculative call sequence and return edge representing the call, the
1557 : original EDGE can be removed and deallocated. Return the edge that now
1558 : represents the call.
1559 :
1560 : For "speculative" indirect call that contains multiple "speculative"
1561 : targets (i.e. edge->indirect_info->num_speculative_call_targets > 1),
1562 : decrease the count and only remove current direct edge.
1563 :
1564 : If no speculative direct call left to the speculative indirect call, remove
1565 : the speculative of both the indirect call and corresponding direct edge.
1566 :
1567 : It is up to caller to iteratively resolve each "speculative" direct call and
1568 : redirect the call as appropriate. */
1569 :
1570 : cgraph_edge *
1571 5815 : cgraph_edge::resolve_speculation (cgraph_edge *edge, tree callee_decl)
1572 : {
1573 5815 : cgraph_edge *e2;
1574 5815 : ipa_ref *ref;
1575 :
1576 5815 : gcc_assert (edge->speculative && (!callee_decl || edge->callee));
1577 5815 : if (!edge->callee)
1578 0 : e2 = edge->first_speculative_call_target ();
1579 : else
1580 : e2 = edge;
1581 5815 : ref = e2->speculative_call_target_ref ();
1582 5815 : edge = edge->speculative_call_indirect_edge ();
1583 5815 : symtab_node *callee;
1584 5815 : if (!callee_decl
1585 1199 : || !(callee = symtab_node::get (callee_decl))
1586 7014 : || !ref->referred->semantically_equivalent_p (callee))
1587 : {
1588 4927 : if (dump_file)
1589 : {
1590 78 : if (callee_decl)
1591 : {
1592 0 : fprintf (dump_file, "Speculative indirect call %s => %s has "
1593 : "turned out to have contradicting known target ",
1594 0 : edge->caller->dump_name (),
1595 0 : e2->callee->dump_name ());
1596 0 : print_generic_expr (dump_file, callee_decl);
1597 0 : fprintf (dump_file, "\n");
1598 : }
1599 : else
1600 : {
1601 78 : fprintf (dump_file, "Removing speculative call %s => %s\n",
1602 78 : edge->caller->dump_name (),
1603 78 : e2->callee->dump_name ());
1604 : }
1605 : }
1606 : }
1607 : else
1608 : {
1609 888 : cgraph_edge *tmp = edge;
1610 888 : if (dump_file)
1611 99 : fprintf (dump_file, "Speculative call turned into direct call.\n");
1612 : edge = e2;
1613 : e2 = tmp;
1614 : /* FIXME: If EDGE is inlined, we should scale up the frequencies
1615 : and counts in the functions inlined through it. */
1616 : }
1617 5815 : edge->count += e2->count;
1618 5815 : if (edge->num_speculative_call_targets_p ())
1619 : {
1620 : /* The indirect edge has multiple speculative targets, don't remove
1621 : speculative until all related direct edges are resolved. */
1622 4927 : edge->indirect_info->num_speculative_call_targets--;
1623 4927 : if (!edge->indirect_info->num_speculative_call_targets)
1624 1023 : edge->speculative = false;
1625 : }
1626 : else
1627 888 : edge->speculative = false;
1628 5815 : e2->speculative = false;
1629 5815 : update_call_stmt_hash_for_removing_direct_edge (e2, edge);
1630 5815 : ref->remove_reference ();
1631 5815 : if (e2->indirect_unknown_callee || e2->inline_failed)
1632 5302 : remove (e2);
1633 : else
1634 513 : e2->callee->remove_symbol_and_inline_clones ();
1635 5815 : return edge;
1636 : }
1637 :
1638 : /* Return edge corresponding to speculative call to a given target.
1639 : NULL if speculative call does not have one. */
1640 :
1641 : cgraph_edge *
1642 0 : cgraph_edge::speculative_call_for_target (cgraph_node *target)
1643 : {
1644 0 : for (cgraph_edge *direct = first_speculative_call_target ();
1645 0 : direct;
1646 0 : direct = direct->next_speculative_call_target ())
1647 0 : if (direct->speculative_call_target_ref ()
1648 0 : ->referred->semantically_equivalent_p (target))
1649 : return direct;
1650 : return NULL;
1651 : }
1652 :
1653 : /* Make an indirect or speculative EDGE with an unknown callee an ordinary edge
1654 : leading to CALLEE. Speculations can be resolved in the process and EDGE can
1655 : be removed and deallocated. Return the edge that now represents the
1656 : call. */
1657 :
1658 : cgraph_edge *
1659 4987 : cgraph_edge::make_direct (cgraph_edge *edge, cgraph_node *callee)
1660 : {
1661 4987 : gcc_assert (edge->indirect_unknown_callee || edge->speculative);
1662 :
1663 : /* If we are redirecting speculative call, make it non-speculative. */
1664 4987 : if (edge->speculative)
1665 : {
1666 1033 : cgraph_edge *found = NULL;
1667 1033 : cgraph_edge *direct, *next;
1668 :
1669 1033 : edge = edge->speculative_call_indirect_edge ();
1670 :
1671 : /* Look all speculative targets and remove all but one corresponding
1672 : to callee (if it exists). */
1673 1033 : for (direct = edge->first_speculative_call_target ();
1674 2486 : direct;
1675 1453 : direct = next)
1676 : {
1677 1453 : next = direct->next_speculative_call_target ();
1678 :
1679 : /* Compare ref not direct->callee. Direct edge is possibly
1680 : inlined or redirected. */
1681 1453 : if (!direct->speculative_call_target_ref ()
1682 1453 : ->referred->semantically_equivalent_p (callee)
1683 1453 : || found)
1684 565 : edge = direct->resolve_speculation (direct, NULL);
1685 : else
1686 : found = direct;
1687 : }
1688 :
1689 : /* On successful speculation just remove the indirect edge and
1690 : return the pre existing direct edge.
1691 : It is important to not remove it and redirect because the direct
1692 : edge may be inlined or redirected. */
1693 1033 : if (found)
1694 : {
1695 888 : cgraph_edge *e2 = resolve_speculation (found, callee->decl);
1696 888 : gcc_checking_assert (!found->speculative && e2 == found);
1697 : return found;
1698 : }
1699 145 : gcc_checking_assert (!edge->speculative);
1700 : }
1701 :
1702 4099 : edge->indirect_unknown_callee = 0;
1703 4099 : ggc_free (edge->indirect_info);
1704 4099 : edge->indirect_info = NULL;
1705 :
1706 : /* Get the edge out of the indirect edge list. */
1707 4099 : if (edge->prev_callee)
1708 115 : edge->prev_callee->next_callee = edge->next_callee;
1709 4099 : if (edge->next_callee)
1710 560 : edge->next_callee->prev_callee = edge->prev_callee;
1711 4099 : if (!edge->prev_callee)
1712 3984 : edge->caller->indirect_calls = edge->next_callee;
1713 :
1714 : /* Put it into the normal callee list */
1715 4099 : edge->prev_callee = NULL;
1716 4099 : edge->next_callee = edge->caller->callees;
1717 4099 : if (edge->caller->callees)
1718 2683 : edge->caller->callees->prev_callee = edge;
1719 4099 : edge->caller->callees = edge;
1720 :
1721 : /* Insert to callers list of the new callee. */
1722 4099 : edge->set_callee (callee);
1723 :
1724 : /* We need to re-determine the inlining status of the edge. */
1725 4099 : initialize_inline_failed (edge);
1726 4099 : return edge;
1727 : }
1728 :
1729 : /* Redirect callee of the edge to N. The function does not update underlying
1730 : call expression. */
1731 :
1732 : void
1733 4710478 : cgraph_edge::redirect_callee (cgraph_node *n)
1734 : {
1735 4710478 : bool loc = callee->comdat_local_p ();
1736 4710478 : cgraph_node *old_callee = callee;
1737 :
1738 : /* Remove from callers list of the current callee. */
1739 4710478 : remove_callee ();
1740 :
1741 : /* Insert to callers list of the new callee. */
1742 4710478 : set_callee (n);
1743 :
1744 4710478 : if (callback)
1745 : {
1746 : /* When redirecting a callback callee, redirect its ref as well. */
1747 333 : ipa_ref *old_ref = caller->find_reference (old_callee, call_stmt,
1748 333 : lto_stmt_uid, IPA_REF_ADDR);
1749 333 : gcc_checking_assert (old_ref);
1750 333 : old_ref->remove_reference ();
1751 333 : ipa_ref *new_ref = caller->create_reference (n, IPA_REF_ADDR, call_stmt);
1752 333 : new_ref->lto_stmt_uid = lto_stmt_uid;
1753 : /* If the last reference to OLD_CALLEE has been redirected, unset
1754 : address_taken. old_ref is only used as a placeholder when looking for
1755 : a different reference. */
1756 333 : if (!old_callee->iterate_referring (0, old_ref))
1757 253 : old_callee->address_taken = 0;
1758 333 : n->mark_address_taken ();
1759 333 : callback_info *ci = callback_info_sum->get (this);
1760 333 : ci->redirected = true;
1761 : }
1762 :
1763 4710478 : if (!inline_failed)
1764 : return;
1765 803594 : if (!loc && n->comdat_local_p ())
1766 : {
1767 56 : cgraph_node *to = caller->inlined_to ? caller->inlined_to : caller;
1768 56 : to->calls_comdat_local = true;
1769 : }
1770 803538 : else if (loc && !n->comdat_local_p ())
1771 : {
1772 114 : cgraph_node *to = caller->inlined_to ? caller->inlined_to : caller;
1773 114 : gcc_checking_assert (to->calls_comdat_local);
1774 114 : to->calls_comdat_local = to->check_calls_comdat_local_p ();
1775 : }
1776 : }
1777 :
1778 : /* If necessary, change the function declaration in the call statement
1779 : associated with E so that it corresponds to the edge callee. Speculations
1780 : can be resolved in the process and EDGE can be removed and deallocated.
1781 :
1782 : The edge could be one of speculative direct call generated from speculative
1783 : indirect call. In this circumstance, decrease the speculative targets
1784 : count (i.e. num_speculative_call_targets) and redirect call stmt to the
1785 : corresponding i-th target. If no speculative direct call left to the
1786 : speculative indirect call, remove "speculative" of the indirect call and
1787 : also redirect stmt to it's final direct target.
1788 :
1789 : When called from within tree-inline, KILLED_SSAs has to contain the pointer
1790 : to killed_new_ssa_names within the copy_body_data structure and SSAs
1791 : discovered to be useless (if LHS is removed) will be added to it, otherwise
1792 : it needs to be NULL.
1793 :
1794 : It is up to caller to iteratively transform each "speculative"
1795 : direct call as appropriate. */
1796 :
1797 : gimple *
1798 10343905 : cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
1799 : hash_set <tree> *killed_ssas)
1800 : {
1801 10343905 : tree decl = gimple_call_fndecl (e->call_stmt);
1802 10343905 : gcall *new_stmt;
1803 :
1804 10343905 : if (e->speculative)
1805 : {
1806 : /* If there already is an direct call (i.e. as a result of inliner's
1807 : substitution), forget about speculating. */
1808 33706 : if (decl)
1809 0 : e = make_direct (e->speculative_call_indirect_edge (),
1810 : cgraph_node::get (decl));
1811 : else
1812 : {
1813 : /* Be sure we redirect all speculative targets before poking
1814 : about indirect edge. */
1815 33706 : gcc_checking_assert (e->callee);
1816 33706 : cgraph_edge *indirect = e->speculative_call_indirect_edge ();
1817 33706 : gcall *new_stmt;
1818 33706 : ipa_ref *ref;
1819 :
1820 : /* Expand speculation into GIMPLE code. */
1821 33706 : if (dump_file)
1822 : {
1823 150 : fprintf (dump_file,
1824 : "Expanding speculative call of %s -> %s count: ",
1825 75 : e->caller->dump_name (),
1826 : e->callee->dump_name ());
1827 75 : e->count.dump (dump_file);
1828 75 : fprintf (dump_file, "\n");
1829 : }
1830 33706 : push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
1831 :
1832 33706 : profile_count all = indirect->count;
1833 33706 : for (cgraph_edge *e2 = e->first_speculative_call_target ();
1834 76713 : e2;
1835 43007 : e2 = e2->next_speculative_call_target ())
1836 43007 : all = all + e2->count;
1837 33706 : profile_probability prob = e->count.probability_in (all);
1838 33706 : if (!prob.initialized_p ())
1839 160 : prob = profile_probability::even ();
1840 33706 : ref = e->speculative_call_target_ref ();
1841 67412 : new_stmt = gimple_ic (e->call_stmt,
1842 : dyn_cast<cgraph_node *> (ref->referred),
1843 : prob);
1844 33706 : e->speculative = false;
1845 33706 : if (indirect->num_speculative_call_targets_p ())
1846 : {
1847 : /* The indirect edge has multiple speculative targets, don't
1848 : remove speculative until all related direct edges are
1849 : redirected. */
1850 33706 : indirect->indirect_info->num_speculative_call_targets--;
1851 33706 : if (!indirect->indirect_info->num_speculative_call_targets)
1852 26020 : indirect->speculative = false;
1853 : }
1854 : else
1855 0 : indirect->speculative = false;
1856 : /* Indirect edges are not both in the call site hash.
1857 : get it updated. */
1858 33706 : update_call_stmt_hash_for_removing_direct_edge (e, indirect);
1859 33706 : cgraph_edge::set_call_stmt (e, new_stmt, false);
1860 33706 : e->count = gimple_bb (e->call_stmt)->count;
1861 :
1862 : /* Once we are done with expanding the sequence, update also indirect
1863 : call probability. Until then the basic block accounts for the
1864 : sum of indirect edge and all non-expanded speculations. */
1865 33706 : if (!indirect->speculative)
1866 26020 : indirect->count = gimple_bb (indirect->call_stmt)->count;
1867 33706 : ref->speculative = false;
1868 33706 : ref->stmt = NULL;
1869 33706 : pop_cfun ();
1870 : /* Continue redirecting E to proper target. */
1871 : }
1872 : }
1873 :
1874 :
1875 10343905 : if (e->indirect_unknown_callee
1876 10259884 : || decl == e->callee->decl)
1877 9156431 : return e->call_stmt;
1878 :
1879 1187474 : clone_info *callee_info = clone_info::get (e->callee);
1880 1187474 : if (symtab->dump_file)
1881 : {
1882 2 : fprintf (symtab->dump_file,
1883 1 : "updating call of %s -> %s: ", e->caller->dump_name (),
1884 : e->callee->dump_name ());
1885 1 : print_gimple_stmt (symtab->dump_file, e->call_stmt, 0, dump_flags);
1886 1 : if (callee_info && callee_info->param_adjustments)
1887 0 : callee_info->param_adjustments->dump (symtab->dump_file);
1888 : }
1889 :
1890 : /* When redirecting a callback edge, all we need to do is replace
1891 : the original address with the address of the function we are
1892 : redirecting to. */
1893 1187474 : if (e->callback_with_carrying_edge_p ())
1894 : {
1895 3301 : cgraph_edge *carrying = e->get_callback_carrying_edge ();
1896 3301 : if (!callback_is_special_cased (carrying->callee->decl, e->call_stmt)
1897 5843 : && !lookup_attribute ("callback_only",
1898 2542 : DECL_ATTRIBUTES (carrying->callee->decl)))
1899 : /* Callback attribute is removed if the dispatching function changes
1900 : signature, as the indices wouldn't be correct anymore. These edges
1901 : will get cleaned up later, ignore their redirection for now. */
1902 0 : return e->call_stmt;
1903 3301 : callback_redirect_edge (e);
1904 3301 : return e->call_stmt;
1905 : }
1906 : /* Callback calls to .ASSUME bodies might need to have their statement
1907 : rebuilt. */
1908 1184173 : else if (e->callback && e->callee->assume_function)
1909 : {
1910 280 : ipa_param_adjustments *padjs
1911 204 : = callee_info ? callee_info->param_adjustments : NULL;
1912 :
1913 : /* If there are no param adjustments, replace the address in the call
1914 : statement. */
1915 76 : if (!padjs)
1916 128 : callback_redirect_edge (e);
1917 : else
1918 : {
1919 76 : new_stmt = padjs->modify_call (e, false, killed_ssas);
1920 76 : gcc_checking_assert (callback_ifn_assume_call_p (new_stmt));
1921 76 : e->caller->set_call_stmt_including_clones (e->call_stmt, new_stmt,
1922 : false);
1923 : }
1924 204 : return e->call_stmt;
1925 : }
1926 1183969 : gcc_checking_assert (!e->callback);
1927 :
1928 1183969 : if (decl && ipa_saved_clone_sources)
1929 : {
1930 959172 : tree *p = ipa_saved_clone_sources->get (e->callee);
1931 959172 : if (p && decl == *p)
1932 : {
1933 35332 : gimple_call_set_fndecl (e->call_stmt, e->callee->decl);
1934 35332 : return e->call_stmt;
1935 : }
1936 : }
1937 1148637 : if (flag_checking && decl)
1938 : {
1939 1111116 : if (cgraph_node *node = cgraph_node::get (decl))
1940 : {
1941 967408 : clone_info *info = clone_info::get (node);
1942 967408 : gcc_assert (!info || !info->param_adjustments);
1943 : }
1944 : }
1945 :
1946 630936 : if (ipa_param_adjustments *padjs
1947 1148637 : = callee_info ? callee_info->param_adjustments : NULL)
1948 : {
1949 : /* We need to defer cleaning EH info on the new statement to
1950 : fixup-cfg. We may not have dominator information at this point
1951 : and thus would end up with unreachable blocks and have no way
1952 : to communicate that we need to run CFG cleanup then. */
1953 623766 : int lp_nr = lookup_stmt_eh_lp (e->call_stmt);
1954 623766 : if (lp_nr != 0)
1955 154783 : remove_stmt_from_eh_lp (e->call_stmt);
1956 :
1957 623766 : tree old_fntype = gimple_call_fntype (e->call_stmt);
1958 623766 : new_stmt = padjs->modify_call (e, false, killed_ssas);
1959 623766 : cgraph_node *origin = e->callee;
1960 908237 : while (origin->clone_of)
1961 : origin = origin->clone_of;
1962 :
1963 623766 : if ((origin->former_clone_of
1964 487180 : && old_fntype == TREE_TYPE (origin->former_clone_of))
1965 627717 : || old_fntype == TREE_TYPE (origin->decl))
1966 483231 : gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
1967 : else
1968 : {
1969 140535 : tree new_fntype = padjs->build_new_function_type (old_fntype, true);
1970 140535 : gimple_call_set_fntype (new_stmt, new_fntype);
1971 : }
1972 :
1973 623766 : if (lp_nr != 0)
1974 154783 : add_stmt_to_eh_lp (new_stmt, lp_nr);
1975 : }
1976 : else
1977 : {
1978 524871 : if (flag_checking
1979 524871 : && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
1980 : BUILT_IN_UNREACHABLE_TRAP))
1981 314197 : ipa_verify_edge_has_no_modifications (e);
1982 524871 : new_stmt = e->call_stmt;
1983 524871 : gimple_call_set_fndecl (new_stmt, e->callee->decl);
1984 524871 : update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
1985 : }
1986 :
1987 : /* If changing the call to __cxa_pure_virtual or similar noreturn function,
1988 : adjust gimple_call_fntype too. */
1989 1148637 : if (gimple_call_noreturn_p (new_stmt)
1990 213823 : && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (e->callee->decl)))
1991 213750 : && TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl))
1992 1362381 : && (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl)))
1993 213744 : == void_type_node))
1994 212820 : gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
1995 :
1996 : /* If the call becomes noreturn, remove the LHS if possible. */
1997 1148637 : tree lhs = gimple_call_lhs (new_stmt);
1998 1148637 : if (lhs
1999 340160 : && gimple_call_noreturn_p (new_stmt)
2000 1183795 : && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (new_stmt)))
2001 58 : || should_remove_lhs_p (lhs)))
2002 : {
2003 35119 : gimple_call_set_lhs (new_stmt, NULL_TREE);
2004 : /* We need to fix up the SSA name to avoid checking errors. */
2005 35119 : if (TREE_CODE (lhs) == SSA_NAME)
2006 : {
2007 29873 : tree var = create_tmp_reg_fn (DECL_STRUCT_FUNCTION (e->caller->decl),
2008 29873 : TREE_TYPE (lhs), NULL);
2009 29873 : SET_SSA_NAME_VAR_OR_IDENTIFIER (lhs, var);
2010 29873 : SSA_NAME_DEF_STMT (lhs) = gimple_build_nop ();
2011 29873 : set_ssa_default_def (DECL_STRUCT_FUNCTION (e->caller->decl),
2012 : var, lhs);
2013 : }
2014 35119 : update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
2015 : }
2016 :
2017 : /* If new callee has no static chain, remove it. */
2018 1148637 : if (gimple_call_chain (new_stmt) && !DECL_STATIC_CHAIN (e->callee->decl))
2019 : {
2020 58 : gimple_call_set_chain (new_stmt, NULL);
2021 58 : update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
2022 : }
2023 :
2024 1148637 : maybe_remove_unused_call_args (DECL_STRUCT_FUNCTION (e->caller->decl),
2025 : new_stmt);
2026 :
2027 : /* Update callback edges if setting the carrying edge's statement, or else
2028 : their pairing would fall apart. */
2029 1148637 : e->caller->set_call_stmt_including_clones (e->call_stmt, new_stmt, e->has_callback);
2030 :
2031 1148637 : if (symtab->dump_file)
2032 : {
2033 0 : fprintf (symtab->dump_file, " updated to:");
2034 0 : print_gimple_stmt (symtab->dump_file, e->call_stmt, 0, dump_flags);
2035 : }
2036 : return new_stmt;
2037 : }
2038 :
2039 : /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
2040 : OLD_STMT changed into NEW_STMT. OLD_CALL is gimple_call_fndecl
2041 : of OLD_STMT if it was previously call statement.
2042 : If NEW_STMT is NULL, the call has been dropped without any
2043 : replacement. */
2044 :
2045 : static void
2046 120171 : cgraph_update_edges_for_call_stmt_node (cgraph_node *node,
2047 : gimple *old_stmt, tree old_call,
2048 : gimple *new_stmt)
2049 : {
2050 120171 : tree new_call = (new_stmt && is_gimple_call (new_stmt))
2051 126703 : ? gimple_call_fndecl (new_stmt) : 0;
2052 :
2053 : /* We are seeing indirect calls, then there is nothing to update. */
2054 120171 : if (!new_call && !old_call)
2055 : return;
2056 : /* See if we turned indirect call into direct call or folded call to one builtin
2057 : into different builtin. */
2058 118372 : if (old_call != new_call)
2059 : {
2060 116786 : cgraph_edge *e = node->get_edge (old_stmt);
2061 116786 : cgraph_edge *ne = NULL;
2062 116786 : profile_count count;
2063 :
2064 116786 : if (e)
2065 : {
2066 : /* If call was devirtualized during cloning, mark edge
2067 : as resolved. */
2068 95477 : if (e->speculative)
2069 : {
2070 0 : if (new_stmt && is_gimple_call (new_stmt))
2071 : {
2072 0 : tree decl = gimple_call_fndecl (new_stmt);
2073 0 : if (decl)
2074 0 : e = cgraph_edge::make_direct
2075 0 : (e, cgraph_node::get_create (decl));
2076 : }
2077 : else
2078 0 : gcc_unreachable ();
2079 : }
2080 : /* Keep calls marked as dead dead. */
2081 95477 : if (new_stmt && is_gimple_call (new_stmt) && e->callee
2082 97103 : && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
2083 : BUILT_IN_UNREACHABLE_TRAP))
2084 : {
2085 3 : cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
2086 : as_a <gcall *> (new_stmt));
2087 28 : return;
2088 : }
2089 : /* See if the edge is already there and has the correct callee. It
2090 : might be so because of indirect inlining has already updated
2091 : it. We also might've cloned and redirected the edge. */
2092 95474 : if (new_call && e->callee)
2093 : {
2094 : cgraph_node *callee = e->callee;
2095 3247 : while (callee)
2096 : {
2097 1646 : if (callee->decl == new_call
2098 1646 : || callee->former_clone_of == new_call)
2099 : {
2100 22 : cgraph_edge::set_call_stmt (e, as_a <gcall *> (new_stmt));
2101 22 : return;
2102 : }
2103 1624 : callee = callee->clone_of;
2104 : }
2105 : }
2106 :
2107 : /* Otherwise remove edge and create new one; we can't simply redirect
2108 : since function has changed, so inline plan and other information
2109 : attached to edge is invalid. */
2110 95452 : count = e->count;
2111 95452 : if (e->indirect_unknown_callee || e->inline_failed)
2112 95452 : cgraph_edge::remove (e);
2113 : else
2114 0 : e->callee->remove_symbol_and_inline_clones ();
2115 : }
2116 21309 : else if (new_call)
2117 : {
2118 : /* We are seeing new direct call; compute profile info based on BB. */
2119 4 : basic_block bb = gimple_bb (new_stmt);
2120 4 : count = bb->count;
2121 : }
2122 :
2123 95456 : if (new_call)
2124 : {
2125 3371 : ne = node->create_edge (cgraph_node::get_create (new_call),
2126 : as_a <gcall *> (new_stmt), count);
2127 3371 : gcc_assert (ne->inline_failed);
2128 : }
2129 : }
2130 : /* We only updated the call stmt; update pointer in cgraph edge.. */
2131 1586 : else if (old_stmt != new_stmt)
2132 0 : cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
2133 : as_a <gcall *> (new_stmt));
2134 : }
2135 :
2136 : /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
2137 : OLD_STMT changed into NEW_STMT. OLD_DECL is gimple_call_fndecl
2138 : of OLD_STMT before it was updated (updating can happen inplace). */
2139 :
2140 : void
2141 98497 : cgraph_update_edges_for_call_stmt (gimple *old_stmt, tree old_decl,
2142 : gimple *new_stmt)
2143 : {
2144 98497 : cgraph_node *orig = cgraph_node::get (cfun->decl);
2145 98497 : cgraph_node *node;
2146 :
2147 98497 : gcc_checking_assert (orig);
2148 98497 : gcc_assert (!orig->thunk);
2149 98497 : cgraph_update_edges_for_call_stmt_node (orig, old_stmt, old_decl, new_stmt);
2150 98497 : if (orig->clones)
2151 42684 : for (node = orig->clones; node != orig;)
2152 : {
2153 : /* Do not attempt to adjust bodies of yet unexpanded thunks. */
2154 21676 : if (!node->thunk)
2155 21674 : cgraph_update_edges_for_call_stmt_node (node, old_stmt, old_decl,
2156 : new_stmt);
2157 21676 : if (node->clones)
2158 : node = node->clones;
2159 21661 : else if (node->next_sibling_clone)
2160 : node = node->next_sibling_clone;
2161 : else
2162 : {
2163 42031 : while (node != orig && !node->next_sibling_clone)
2164 21023 : node = node->clone_of;
2165 21008 : if (node != orig)
2166 0 : node = node->next_sibling_clone;
2167 : }
2168 : }
2169 98497 : }
2170 :
2171 :
2172 : /* Remove all callees from the node. */
2173 :
2174 : void
2175 241272768 : cgraph_node::remove_callees (void)
2176 : {
2177 241272768 : cgraph_edge *e, *f;
2178 :
2179 241272768 : calls_comdat_local = false;
2180 :
2181 : /* It is sufficient to remove the edges from the lists of callers of
2182 : the callees. The callee list of the node can be zapped with one
2183 : assignment. */
2184 282337257 : for (e = callees; e; e = f)
2185 : {
2186 41064489 : f = e->next_callee;
2187 41064489 : symtab->call_edge_removal_hooks (e);
2188 41064489 : if (!e->indirect_unknown_callee)
2189 41064489 : e->remove_callee ();
2190 41064489 : symtab->free_edge (e);
2191 : }
2192 242128045 : for (e = indirect_calls; e; e = f)
2193 : {
2194 855277 : f = e->next_callee;
2195 855277 : symtab->call_edge_removal_hooks (e);
2196 855277 : if (!e->indirect_unknown_callee)
2197 0 : e->remove_callee ();
2198 855277 : symtab->free_edge (e);
2199 : }
2200 241272768 : indirect_calls = NULL;
2201 241272768 : callees = NULL;
2202 241272768 : if (call_site_hash)
2203 : {
2204 32819 : call_site_hash->empty ();
2205 32819 : call_site_hash = NULL;
2206 : }
2207 241272768 : }
2208 :
2209 : /* Remove all callers from the node. */
2210 :
2211 : void
2212 109043393 : cgraph_node::remove_callers (void)
2213 : {
2214 109043393 : cgraph_edge *e, *f;
2215 :
2216 : /* It is sufficient to remove the edges from the lists of callees of
2217 : the callers. The caller list of the node can be zapped with one
2218 : assignment. */
2219 113721330 : for (e = callers; e; e = f)
2220 : {
2221 4677937 : f = e->next_caller;
2222 : /* When removing a callback-carrying edge, remove all its attached edges
2223 : as well. */
2224 4677937 : if (e->has_callback)
2225 : {
2226 2 : cgraph_edge *cbe, *next_cbe = NULL;
2227 2 : for (cbe = e->first_callback_edge (); cbe; cbe = next_cbe)
2228 : {
2229 0 : next_cbe = cbe->next_callback_edge ();
2230 0 : cgraph_edge::remove (cbe);
2231 : }
2232 : }
2233 4677937 : symtab->call_edge_removal_hooks (e);
2234 4677937 : e->remove_caller ();
2235 4677937 : symtab->free_edge (e);
2236 : }
2237 109043393 : callers = NULL;
2238 109043393 : }
2239 :
2240 : /* Helper function for cgraph_release_function_body and free_lang_data.
2241 : It releases body from function DECL without having to inspect its
2242 : possibly non-existent symtab node. */
2243 :
2244 : void
2245 119282489 : release_function_body (tree decl)
2246 : {
2247 119282489 : function *fn = DECL_STRUCT_FUNCTION (decl);
2248 119282489 : if (fn)
2249 : {
2250 107474481 : if (fn->cfg
2251 107474481 : && loops_for_fn (fn))
2252 : {
2253 1784061 : fn->curr_properties &= ~PROP_loops;
2254 1784061 : loop_optimizer_finalize (fn);
2255 : }
2256 107474481 : if (fn->gimple_df)
2257 : {
2258 1792936 : delete_tree_ssa (fn);
2259 1792936 : fn->eh = NULL;
2260 : }
2261 107474481 : if (fn->cfg)
2262 : {
2263 1784062 : gcc_assert (!dom_info_available_p (fn, CDI_DOMINATORS));
2264 1784062 : gcc_assert (!dom_info_available_p (fn, CDI_POST_DOMINATORS));
2265 1784062 : delete_tree_cfg_annotations (fn);
2266 1784062 : free_cfg (fn);
2267 1784062 : fn->cfg = NULL;
2268 : }
2269 107474481 : if (fn->value_histograms)
2270 13 : free_histograms (fn);
2271 107474481 : gimple_set_body (decl, NULL);
2272 : /* Struct function hangs a lot of data that would leak if we didn't
2273 : removed all pointers to it. */
2274 107474481 : ggc_free (fn);
2275 107474481 : DECL_STRUCT_FUNCTION (decl) = NULL;
2276 : }
2277 119282489 : DECL_SAVED_TREE (decl) = NULL;
2278 119282489 : }
2279 :
2280 : /* Release memory used to represent body of function.
2281 : Use this only for functions that are released before being translated to
2282 : target code (i.e. RTL). Functions that are compiled to RTL and beyond
2283 : are free'd in final.cc via free_after_compilation().
2284 : KEEP_ARGUMENTS are useful only if you want to rebuild body as thunk. */
2285 :
2286 : void
2287 119270514 : cgraph_node::release_body (bool keep_arguments)
2288 : {
2289 119270514 : ipa_transforms_to_apply.release ();
2290 119270514 : if (!used_as_abstract_origin && symtab->state != PARSING)
2291 : {
2292 118676436 : DECL_RESULT (decl) = NULL;
2293 :
2294 118676436 : if (!keep_arguments)
2295 118644660 : DECL_ARGUMENTS (decl) = NULL;
2296 : }
2297 : /* If the node is abstract and needed, then do not clear
2298 : DECL_INITIAL of its associated function declaration because it's
2299 : needed to emit debug info later. */
2300 119270514 : if (!used_as_abstract_origin && DECL_INITIAL (decl))
2301 106947840 : DECL_INITIAL (decl) = error_mark_node;
2302 119270514 : release_function_body (decl);
2303 119270514 : lto_free_function_in_decl_state_for_node (this);
2304 119270514 : if (flag_checking && clones)
2305 : {
2306 : /* It is invalid to release body before materializing clones except
2307 : for thunks that don't really need a body. Verify also that we do
2308 : not leak pointers to the call statements. */
2309 53 : for (cgraph_node *node = clones; node;
2310 31 : node = node->next_sibling_clone)
2311 31 : gcc_assert (node->thunk && !node->callees->call_stmt);
2312 : }
2313 119270514 : remove_callees ();
2314 119270514 : remove_all_references ();
2315 119270514 : }
2316 :
2317 : /* Remove function from symbol table. */
2318 :
2319 : void
2320 109043393 : cgraph_node::remove (void)
2321 : {
2322 109043393 : bool clone_info_set = false;
2323 109043393 : clone_info *info, saved_info;
2324 109043393 : if (symtab->ipa_clones_dump_file && symtab->cloned_nodes.contains (this))
2325 13 : fprintf (symtab->ipa_clones_dump_file,
2326 : "Callgraph removal;%s;%d;%s;%d;%d\n", asm_name (), get_uid (),
2327 13 : DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
2328 26 : DECL_SOURCE_COLUMN (decl));
2329 :
2330 109043393 : if ((info = clone_info::get (this)) != NULL)
2331 : {
2332 439444 : saved_info = *info;
2333 439444 : clone_info_set = true;
2334 : }
2335 109043393 : symtab->call_cgraph_removal_hooks (this);
2336 109043393 : remove_callers ();
2337 109043393 : remove_callees ();
2338 109043393 : ipa_transforms_to_apply.release ();
2339 109043393 : delete_function_version (function_version ());
2340 :
2341 : /* Incremental inlining access removed nodes stored in the postorder list.
2342 : */
2343 109043393 : force_output = false;
2344 109043393 : forced_by_abi = false;
2345 :
2346 217647342 : unregister (clone_info_set ? &saved_info : NULL);
2347 109043393 : if (prev_sibling_clone)
2348 797059 : prev_sibling_clone->next_sibling_clone = next_sibling_clone;
2349 108246334 : else if (clone_of)
2350 : {
2351 1899776 : clone_of->clones = next_sibling_clone;
2352 1899776 : if (!clones)
2353 : {
2354 1896696 : bool need_body = false;
2355 1896696 : for (cgraph_node *n = clone_of; n; n = n->clone_of)
2356 1891179 : if (n->analyzed || n->clones)
2357 : {
2358 : need_body = true;
2359 : break;
2360 : }
2361 1891176 : if (!need_body)
2362 5517 : clone_of->release_body ();
2363 : }
2364 : }
2365 109043393 : if (next_sibling_clone)
2366 1042623 : next_sibling_clone->prev_sibling_clone = prev_sibling_clone;
2367 109043393 : if (clones)
2368 : {
2369 41077 : cgraph_node *n, *next;
2370 :
2371 41077 : if (clone_of)
2372 : {
2373 177138 : for (n = clones; n->next_sibling_clone; n = n->next_sibling_clone)
2374 136061 : n->clone_of = clone_of;
2375 41077 : n->clone_of = clone_of;
2376 41077 : n->next_sibling_clone = clone_of->clones;
2377 41077 : if (clone_of->clones)
2378 36001 : clone_of->clones->prev_sibling_clone = n;
2379 41077 : clone_of->clones = clones;
2380 : }
2381 : else
2382 : {
2383 : /* We are removing node with clones. This makes clones inconsistent,
2384 : but assume they will be removed subsequently and just keep clone
2385 : tree intact. This can happen in unreachable function removal since
2386 : we remove unreachable functions in random order, not by bottom-up
2387 : walk of clone trees. */
2388 0 : for (n = clones; n; n = next)
2389 : {
2390 0 : next = n->next_sibling_clone;
2391 0 : n->next_sibling_clone = NULL;
2392 0 : n->prev_sibling_clone = NULL;
2393 0 : n->clone_of = NULL;
2394 : }
2395 : }
2396 : }
2397 :
2398 : /* While all the clones are removed after being proceeded, the function
2399 : itself is kept in the cgraph even after it is compiled. Check whether
2400 : we are done with this body and reclaim it proactively if this is the case.
2401 : */
2402 109043393 : if (symtab->state != LTO_STREAMING)
2403 : {
2404 109041210 : cgraph_node *n = cgraph_node::get (decl);
2405 109041210 : if (!n
2406 109041210 : || (!n->clones && !n->clone_of && !n->inlined_to
2407 1177263 : && ((symtab->global_info_ready || in_lto_p)
2408 10471 : && (TREE_ASM_WRITTEN (n->decl)
2409 10439 : || DECL_EXTERNAL (n->decl)
2410 5683 : || !n->analyzed
2411 5487 : || (!flag_wpa && n->in_other_partition)))))
2412 105938607 : release_body ();
2413 : }
2414 : else
2415 2183 : lto_free_function_in_decl_state_for_node (this);
2416 :
2417 109043393 : decl = NULL;
2418 109043393 : if (call_site_hash)
2419 : {
2420 0 : call_site_hash->empty ();
2421 0 : call_site_hash = NULL;
2422 : }
2423 :
2424 109043393 : symtab->release_symbol (this);
2425 109043393 : }
2426 :
2427 : /* Likewise indicate that a node is having address taken. */
2428 :
2429 : void
2430 4890889 : cgraph_node::mark_address_taken (void)
2431 : {
2432 : /* Indirect inlining can figure out that all uses of the address are
2433 : inlined. */
2434 4890889 : if (inlined_to)
2435 : {
2436 0 : gcc_assert (cfun->after_inlining);
2437 0 : gcc_assert (callers->indirect_inlining_edge);
2438 : return;
2439 : }
2440 : /* FIXME: address_taken flag is used both as a shortcut for testing whether
2441 : IPA_REF_ADDR reference exists (and thus it should be set on node
2442 : representing alias we take address of) and as a test whether address
2443 : of the object was taken (and thus it should be set on node alias is
2444 : referring to). We should remove the first use and the remove the
2445 : following set. */
2446 4890889 : address_taken = 1;
2447 4890889 : cgraph_node *node = ultimate_alias_target ();
2448 4890889 : node->address_taken = 1;
2449 : }
2450 :
2451 : /* Return local info node for the compiled function. */
2452 :
2453 : cgraph_node *
2454 13035996 : cgraph_node::local_info_node (tree decl)
2455 : {
2456 13035996 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
2457 13035996 : cgraph_node *node = get (decl);
2458 13035996 : if (!node)
2459 : return NULL;
2460 13035996 : return node->ultimate_alias_target ();
2461 : }
2462 :
2463 : /* Return RTL info for the compiled function. */
2464 :
2465 : cgraph_rtl_info *
2466 56532145 : cgraph_node::rtl_info (const_tree decl)
2467 : {
2468 56532145 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
2469 56532145 : cgraph_node *node = get (decl);
2470 56532145 : if (!node)
2471 : return NULL;
2472 56373398 : enum availability avail;
2473 56373398 : node = node->ultimate_alias_target (&avail);
2474 56373398 : if (decl != current_function_decl
2475 53340412 : && (avail < AVAIL_AVAILABLE
2476 47694353 : || (node->decl != current_function_decl
2477 47628215 : && !TREE_ASM_WRITTEN (node->decl))))
2478 : return NULL;
2479 : /* Allocate if it doesn't exist. */
2480 47614220 : if (node->rtl == NULL)
2481 : {
2482 1398123 : node->rtl = ggc_cleared_alloc<cgraph_rtl_info> ();
2483 1398123 : SET_HARD_REG_SET (node->rtl->function_used_regs);
2484 : }
2485 47614220 : return node->rtl;
2486 : }
2487 :
2488 : /* Return a string describing the failure REASON. */
2489 :
2490 : const char*
2491 11657 : cgraph_inline_failed_string (cgraph_inline_failed_t reason)
2492 : {
2493 : #undef DEFCIFCODE
2494 : #define DEFCIFCODE(code, type, string) string,
2495 :
2496 11657 : static const char *cif_string_table[CIF_N_REASONS] = {
2497 : #include "cif-code.def"
2498 : };
2499 :
2500 : /* Signedness of an enum type is implementation defined, so cast it
2501 : to unsigned before testing. */
2502 11657 : gcc_assert ((unsigned) reason < CIF_N_REASONS);
2503 11657 : return cif_string_table[reason];
2504 : }
2505 :
2506 : /* Return a type describing the failure REASON. */
2507 :
2508 : cgraph_inline_failed_type_t
2509 75886795 : cgraph_inline_failed_type (cgraph_inline_failed_t reason)
2510 : {
2511 : #undef DEFCIFCODE
2512 : #define DEFCIFCODE(code, type, string) type,
2513 :
2514 75886795 : static cgraph_inline_failed_type_t cif_type_table[CIF_N_REASONS] = {
2515 : #include "cif-code.def"
2516 : };
2517 :
2518 : /* Signedness of an enum type is implementation defined, so cast it
2519 : to unsigned before testing. */
2520 75886795 : gcc_assert ((unsigned) reason < CIF_N_REASONS);
2521 75886795 : return cif_type_table[reason];
2522 : }
2523 :
2524 : /* Names used to print out the availability enum. */
2525 : const char * const cgraph_availability_names[] =
2526 : {"unset", "not_available", "overwritable", "available", "local"};
2527 :
2528 : /* Output flags of edge to a file F. */
2529 :
2530 : void
2531 29463 : cgraph_edge::dump_edge_flags (FILE *f)
2532 : {
2533 29463 : if (speculative)
2534 220 : fprintf (f, "(speculative) ");
2535 29463 : if (callback)
2536 64 : fprintf (f, "(callback) ");
2537 29463 : if (has_callback)
2538 12 : fprintf (f, "(has_callback) ");
2539 29463 : if (!inline_failed)
2540 2514 : fprintf (f, "(inlined) ");
2541 29463 : if (call_stmt_cannot_inline_p)
2542 0 : fprintf (f, "(call_stmt_cannot_inline_p) ");
2543 29463 : if (indirect_inlining_edge)
2544 335 : fprintf (f, "(indirect_inlining) ");
2545 29463 : if (count.initialized_p ())
2546 : {
2547 28324 : fprintf (f, "(");
2548 28324 : count.dump (f);
2549 28324 : fprintf (f, ",");
2550 28324 : fprintf (f, "%.2f per call) ", sreal_frequency ().to_double ());
2551 : }
2552 29463 : if (can_throw_external)
2553 2352 : fprintf (f, "(can throw external) ");
2554 29463 : }
2555 :
2556 : /* Dump edge to stderr. */
2557 :
2558 : void
2559 0 : cgraph_edge::debug (void)
2560 : {
2561 0 : fprintf (stderr, "%s -> %s ", caller->dump_asm_name (),
2562 0 : callee == NULL ? "(null)" : callee->dump_asm_name ());
2563 0 : dump_edge_flags (stderr);
2564 0 : fprintf (stderr, "\n\n");
2565 0 : caller->debug ();
2566 0 : if (callee != NULL)
2567 0 : callee->debug ();
2568 0 : }
2569 :
2570 : /* Dump call graph node to file F. */
2571 :
2572 : void
2573 6585 : cgraph_node::dump (FILE *f)
2574 : {
2575 6585 : cgraph_edge *edge;
2576 :
2577 6585 : dump_base (f);
2578 :
2579 6585 : if (inlined_to)
2580 925 : fprintf (f, " Function %s is inline copy in %s\n",
2581 : dump_name (),
2582 : inlined_to->dump_name ());
2583 6585 : if (clone_of)
2584 899 : fprintf (f, " Clone of %s\n", clone_of->dump_asm_name ());
2585 6585 : if (symtab->function_flags_ready)
2586 12066 : fprintf (f, " Availability: %s\n",
2587 6033 : cgraph_availability_names [get_availability ()]);
2588 :
2589 6585 : if (profile_id)
2590 193 : fprintf (f, " Profile id: %i\n",
2591 : profile_id);
2592 6585 : if (unit_id)
2593 261 : fprintf (f, " Unit id: %i\n",
2594 : unit_id);
2595 6585 : cgraph_function_version_info *vi = function_version ();
2596 6585 : if (vi != NULL)
2597 : {
2598 0 : fprintf (f, " Version info: ");
2599 0 : if (vi->prev != NULL)
2600 : {
2601 0 : fprintf (f, "prev: ");
2602 0 : fprintf (f, "%s ", vi->prev->this_node->dump_asm_name ());
2603 : }
2604 0 : if (vi->next != NULL)
2605 : {
2606 0 : fprintf (f, "next: ");
2607 0 : fprintf (f, "%s ", vi->next->this_node->dump_asm_name ());
2608 : }
2609 0 : if (vi->dispatcher_resolver != NULL_TREE)
2610 0 : fprintf (f, "dispatcher: %s",
2611 0 : lang_hooks.decl_printable_name (vi->dispatcher_resolver, 2));
2612 :
2613 0 : fprintf (f, "\n");
2614 : }
2615 6585 : fprintf (f, " Function flags:");
2616 6585 : if (count.initialized_p ())
2617 : {
2618 4216 : fprintf (f, " count:");
2619 4216 : count.dump (f);
2620 : }
2621 6585 : if (tp_first_run > 0)
2622 89 : fprintf (f, " first_run:%" PRId64, (int64_t) tp_first_run);
2623 6585 : if (cgraph_node *origin = nested_function_origin (this))
2624 0 : fprintf (f, " nested in:%s", origin->dump_asm_name ());
2625 6585 : if (gimple_has_body_p (decl))
2626 4379 : fprintf (f, " body");
2627 6585 : if (process)
2628 0 : fprintf (f, " process");
2629 6585 : if (local)
2630 1321 : fprintf (f, " local");
2631 6585 : if (redefined_extern_inline)
2632 0 : fprintf (f, " redefined_extern_inline");
2633 6585 : if (only_called_at_startup)
2634 467 : fprintf (f, " only_called_at_startup");
2635 6585 : if (only_called_at_exit)
2636 7 : fprintf (f, " only_called_at_exit");
2637 6585 : if (tm_clone)
2638 0 : fprintf (f, " tm_clone");
2639 6585 : if (calls_comdat_local)
2640 9 : fprintf (f, " calls_comdat_local");
2641 6585 : if (icf_merged)
2642 32 : fprintf (f, " icf_merged");
2643 6585 : if (assume_function)
2644 60 : fprintf (f, " assume_function");
2645 6585 : if (merged_comdat)
2646 0 : fprintf (f, " merged_comdat");
2647 6585 : if (merged_extern_inline)
2648 0 : fprintf (f, " merged_extern_inline");
2649 6585 : if (split_part)
2650 23 : fprintf (f, " split_part");
2651 6585 : if (indirect_call_target)
2652 213 : fprintf (f, " indirect_call_target");
2653 6585 : if (nonfreeing_fn)
2654 358 : fprintf (f, " nonfreeing_fn");
2655 6585 : if (DECL_STATIC_CONSTRUCTOR (decl))
2656 48 : fprintf (f," static_constructor (priority:%i)", get_init_priority ());
2657 6585 : if (DECL_STATIC_DESTRUCTOR (decl))
2658 7 : fprintf (f," static_destructor (priority:%i)", get_fini_priority ());
2659 6585 : if (frequency == NODE_FREQUENCY_HOT)
2660 80 : fprintf (f, " hot");
2661 6585 : if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
2662 40 : fprintf (f, " unlikely_executed");
2663 6585 : if (frequency == NODE_FREQUENCY_EXECUTED_ONCE)
2664 880 : fprintf (f, " executed_once");
2665 6585 : if (opt_for_fn (decl, optimize_size))
2666 343 : fprintf (f, " optimize_size");
2667 6585 : if (parallelized_function)
2668 4 : fprintf (f, " parallelized_function");
2669 6585 : if (DECL_IS_MALLOC (decl))
2670 74 : fprintf (f, " decl_is_malloc");
2671 6585 : if (DECL_IS_OPERATOR_NEW_P (decl))
2672 35 : fprintf (f, " %soperator_new",
2673 35 : DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
2674 6585 : if (DECL_IS_OPERATOR_DELETE_P (decl))
2675 26 : fprintf (f, " %soperator_delete",
2676 26 : DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
2677 :
2678 6585 : if (DECL_STATIC_CHAIN (decl))
2679 6 : fprintf (f, " static_chain");
2680 :
2681 6585 : fprintf (f, "\n");
2682 :
2683 6585 : if (thunk)
2684 : {
2685 49 : fprintf (f, " Thunk");
2686 49 : thunk_info::get (this)->dump (f);
2687 : }
2688 6536 : else if (former_thunk_p ())
2689 : {
2690 21 : fprintf (f, " Former thunk ");
2691 21 : thunk_info::get (this)->dump (f);
2692 : }
2693 6515 : else gcc_checking_assert (!thunk_info::get (this));
2694 :
2695 6585 : fprintf (f, " Called by: ");
2696 :
2697 6585 : profile_count sum = profile_count::zero ();
2698 15676 : for (edge = callers; edge; edge = edge->next_caller)
2699 : {
2700 9091 : fprintf (f, "%s ", edge->caller->dump_asm_name ());
2701 9091 : edge->dump_edge_flags (f);
2702 9091 : if (edge->count.initialized_p ())
2703 8802 : sum += edge->count.ipa ();
2704 : }
2705 :
2706 6585 : fprintf (f, "\n Calls: ");
2707 26957 : for (edge = callees; edge; edge = edge->next_callee)
2708 : {
2709 20372 : fprintf (f, "%s ", edge->callee->dump_asm_name ());
2710 20372 : edge->dump_edge_flags (f);
2711 : }
2712 6585 : fprintf (f, "\n");
2713 :
2714 6585 : if (!body_removed && count.ipa ().initialized_p ())
2715 : {
2716 129 : bool ok = true;
2717 129 : bool min = false;
2718 : ipa_ref *ref;
2719 :
2720 129 : FOR_EACH_ALIAS (this, ref)
2721 0 : if (dyn_cast <cgraph_node *> (ref->referring)->count.initialized_p ())
2722 0 : sum += dyn_cast <cgraph_node *> (ref->referring)->count.ipa ();
2723 :
2724 129 : if (inlined_to
2725 129 : || (symtab->state < EXPANSION
2726 129 : && ultimate_alias_target () == this && only_called_directly_p ()))
2727 3 : ok = !count.ipa ().differs_from_p (sum);
2728 126 : else if (count.ipa () > profile_count::from_gcov_type (100)
2729 126 : && count.ipa () < sum.apply_scale (99, 100))
2730 0 : ok = false, min = true;
2731 129 : if (!ok)
2732 : {
2733 0 : fprintf (f, " Invalid sum of caller counts ");
2734 0 : sum.dump (f);
2735 0 : if (min)
2736 0 : fprintf (f, ", should be at most ");
2737 : else
2738 0 : fprintf (f, ", should be ");
2739 0 : count.ipa ().dump (f);
2740 0 : fprintf (f, "\n");
2741 : }
2742 : }
2743 :
2744 7358 : for (edge = indirect_calls; edge; edge = edge->next_callee)
2745 : {
2746 773 : fprintf (f, " ");
2747 773 : edge->indirect_info->dump (f);
2748 : }
2749 6585 : }
2750 :
2751 : /* Dump call graph node to file F in graphviz format. */
2752 :
2753 : void
2754 0 : cgraph_node::dump_graphviz (FILE *f)
2755 : {
2756 0 : cgraph_edge *edge;
2757 :
2758 0 : for (edge = callees; edge; edge = edge->next_callee)
2759 : {
2760 0 : cgraph_node *callee = edge->callee;
2761 :
2762 0 : fprintf (f, "\t\"%s\" -> \"%s\"\n", dump_name (), callee->dump_name ());
2763 : }
2764 0 : }
2765 :
2766 :
2767 : /* Dump call graph node NODE to stderr. */
2768 :
2769 : DEBUG_FUNCTION void
2770 0 : cgraph_node::debug (void)
2771 : {
2772 0 : dump (stderr);
2773 0 : }
2774 :
2775 : /* Dump the callgraph to file F. */
2776 :
2777 : void
2778 77 : cgraph_node::dump_cgraph (FILE *f)
2779 : {
2780 77 : cgraph_node *node;
2781 :
2782 77 : fprintf (f, "callgraph:\n\n");
2783 362 : FOR_EACH_FUNCTION (node)
2784 285 : node->dump (f);
2785 77 : }
2786 :
2787 : /* Dump human readable information about the indirect call to F. If NEWLINE
2788 : is true, it will be terminated by a newline. */
2789 :
2790 : void
2791 921 : cgraph_indirect_call_info::dump (FILE *f, bool newline) const
2792 : {
2793 921 : if (const cgraph_polymorphic_indirect_info *pii
2794 921 : = dyn_cast <const cgraph_polymorphic_indirect_info *> (this))
2795 : {
2796 512 : fprintf (f, " indirect polymorphic callsite, %s, "
2797 : "calling param %i, offset " HOST_WIDE_INT_PRINT_DEC
2798 : "otr_token " HOST_WIDE_INT_PRINT_DEC ", otr_type ",
2799 512 : pii->vptr_changed ? "vptr_changed" : "vptr not changed",
2800 512 : pii->param_index, pii->offset, pii->otr_token);
2801 512 : print_generic_expr (f, pii->otr_type);
2802 512 : fprintf (f, ", context ");
2803 512 : pii->context.dump (f, false);
2804 : }
2805 409 : else if (const cgraph_simple_indirect_info *sii
2806 409 : = dyn_cast <const cgraph_simple_indirect_info *> (this))
2807 : {
2808 409 : if (sii->agg_contents)
2809 53 : fprintf (f, " indirect %s callsite, calling param %i, "
2810 : "offset " HOST_WIDE_INT_PRINT_DEC ", %s",
2811 53 : sii->member_ptr ? "member ptr" : "aggregate",
2812 53 : sii->param_index, sii->offset,
2813 53 : sii->by_ref ? "by reference" : "by_value");
2814 356 : else if (sii->param_index >= 0)
2815 9 : fprintf (f, " indirect simple callsite, calling param %i",
2816 : sii->param_index);
2817 : else
2818 347 : fprintf (f, " indirect simple callsite, not calling a known "
2819 : "parameter");
2820 : }
2821 : else
2822 0 : fprintf (f, " indirect callsite");
2823 :
2824 921 : fprintf (f, ", flags %i, num speculative call targets: %i", ecf_flags,
2825 921 : num_speculative_call_targets);
2826 921 : if (newline)
2827 773 : fprintf (f, "\n");
2828 921 : }
2829 :
2830 : /* Dump human readable information about the indirect call to stderr. */
2831 :
2832 : void
2833 0 : cgraph_indirect_call_info::debug () const
2834 : {
2835 0 : dump (stderr);
2836 0 : }
2837 :
2838 : /* Return true when the DECL can possibly be inlined. */
2839 :
2840 : bool
2841 100455312 : cgraph_function_possibly_inlined_p (tree decl)
2842 : {
2843 100455312 : if (!symtab->global_info_ready)
2844 92560728 : return !DECL_UNINLINABLE (decl);
2845 7894584 : return DECL_POSSIBLY_INLINED (decl);
2846 : }
2847 :
2848 : /* Return function availability. See cgraph.h for description of individual
2849 : return values. */
2850 : enum availability
2851 847453083 : cgraph_node::get_availability (symtab_node *ref)
2852 : {
2853 847453083 : if (ref)
2854 : {
2855 602475776 : cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
2856 602475776 : if (cref)
2857 602475776 : ref = cref->inlined_to;
2858 : }
2859 847453083 : enum availability avail;
2860 847453083 : if (!analyzed && !in_other_partition)
2861 509240112 : avail = AVAIL_NOT_AVAILABLE;
2862 338212971 : else if (local)
2863 98173184 : avail = AVAIL_LOCAL;
2864 240039787 : else if (inlined_to)
2865 2140628 : avail = AVAIL_AVAILABLE;
2866 237899159 : else if (transparent_alias)
2867 134 : ultimate_alias_target (&avail, ref);
2868 237899025 : else if (ifunc_resolver
2869 237899025 : || lookup_attribute ("noipa", DECL_ATTRIBUTES (decl)))
2870 4746219 : avail = AVAIL_INTERPOSABLE;
2871 233152806 : else if (!externally_visible)
2872 30280553 : avail = AVAIL_AVAILABLE;
2873 : /* If this is a reference from symbol itself and there are no aliases, we
2874 : may be sure that the symbol was not interposed by something else because
2875 : the symbol itself would be unreachable otherwise.
2876 :
2877 : Also comdat groups are always resolved in groups. */
2878 20174 : else if ((this == ref && !has_aliases_p ())
2879 202872972 : || (ref && get_comdat_group ()
2880 1185422 : && get_comdat_group () == ref->get_comdat_group ()))
2881 22917 : avail = AVAIL_AVAILABLE;
2882 : /* Inline functions are safe to be analyzed even if their symbol can
2883 : be overwritten at runtime. It is not meaningful to enforce any sane
2884 : behavior on replacing inline function by different body. */
2885 202849336 : else if (DECL_DECLARED_INLINE_P (decl))
2886 74917753 : avail = AVAIL_AVAILABLE;
2887 :
2888 : /* If the function can be overwritten, return OVERWRITABLE. Take
2889 : care at least of two notable extensions - the COMDAT functions
2890 : used to share template instantiations in C++ (this is symmetric
2891 : to code cp_cannot_inline_tree_fn and probably shall be shared and
2892 : the inlinability hooks completely eliminated). */
2893 :
2894 127931583 : else if (decl_replaceable_p (decl, semantic_interposition)
2895 127931583 : && !DECL_EXTERNAL (decl))
2896 9404981 : avail = AVAIL_INTERPOSABLE;
2897 118526602 : else avail = AVAIL_AVAILABLE;
2898 :
2899 847453083 : return avail;
2900 : }
2901 :
2902 : /* Worker for cgraph_node_can_be_local_p. */
2903 : static bool
2904 787571 : cgraph_node_cannot_be_local_p_1 (cgraph_node *node, void *)
2905 : {
2906 787571 : return !(!node->force_output
2907 766275 : && !node->ref_by_asm
2908 766271 : && !node->ifunc_resolver
2909 : /* Limitation of gas requires us to output targets of symver aliases
2910 : as global symbols. This is binutils PR 25295. */
2911 766231 : && !node->symver
2912 766231 : && ((DECL_COMDAT (node->decl)
2913 306129 : && !node->forced_by_abi
2914 288084 : && !node->used_from_object_file_p ()
2915 288084 : && !node->same_comdat_group)
2916 519615 : || !node->externally_visible)
2917 400971 : && !DECL_STATIC_CONSTRUCTOR (node->decl)
2918 399071 : && !DECL_STATIC_DESTRUCTOR (node->decl));
2919 : }
2920 :
2921 : /* Return true if cgraph_node can be made local for API change.
2922 : Extern inline functions and C++ COMDAT functions can be made local
2923 : at the expense of possible code size growth if function is used in multiple
2924 : compilation units. */
2925 : bool
2926 1066169 : cgraph_node::can_be_local_p (void)
2927 : {
2928 1066169 : return (!address_taken
2929 1066169 : && !call_for_symbol_thunks_and_aliases (cgraph_node_cannot_be_local_p_1,
2930 1066169 : NULL, true));
2931 : }
2932 :
2933 : /* Call callback on cgraph_node, thunks and aliases associated to cgraph_node.
2934 : When INCLUDE_OVERWRITABLE is false, overwritable symbols are
2935 : skipped. When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
2936 : skipped. */
2937 : bool
2938 164427616 : cgraph_node::call_for_symbol_thunks_and_aliases (bool (*callback)
2939 : (cgraph_node *, void *),
2940 : void *data,
2941 : bool include_overwritable,
2942 : bool exclude_virtual_thunks)
2943 : {
2944 164427616 : cgraph_edge *e;
2945 164427616 : ipa_ref *ref;
2946 164427616 : enum availability avail = AVAIL_AVAILABLE;
2947 :
2948 164427616 : if (include_overwritable
2949 164427616 : || (avail = get_availability ()) > AVAIL_INTERPOSABLE)
2950 : {
2951 164416371 : if (callback (this, data))
2952 : return true;
2953 : }
2954 175184349 : FOR_EACH_ALIAS (this, ref)
2955 : {
2956 16201000 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
2957 16201000 : if (include_overwritable
2958 16201000 : || alias->get_availability () > AVAIL_INTERPOSABLE)
2959 16200898 : if (alias->call_for_symbol_thunks_and_aliases (callback, data,
2960 : include_overwritable,
2961 : exclude_virtual_thunks))
2962 : return true;
2963 : }
2964 158983349 : if (avail <= AVAIL_INTERPOSABLE)
2965 : return false;
2966 165371739 : for (e = callers; e; e = e->next_caller)
2967 6399635 : if (e->caller->thunk
2968 2628 : && (include_overwritable
2969 211 : || e->caller->get_availability () > AVAIL_INTERPOSABLE)
2970 6402263 : && !(exclude_virtual_thunks
2971 22 : && thunk_info::get (e->caller)->virtual_offset_p))
2972 2616 : if (e->caller->call_for_symbol_thunks_and_aliases (callback, data,
2973 : include_overwritable,
2974 : exclude_virtual_thunks))
2975 : return true;
2976 :
2977 : return false;
2978 : }
2979 :
2980 : /* Worker to bring NODE local. */
2981 :
2982 : bool
2983 0 : cgraph_node::make_local (cgraph_node *node, void *)
2984 : {
2985 0 : gcc_checking_assert (node->can_be_local_p ());
2986 0 : if (DECL_COMDAT (node->decl) || DECL_EXTERNAL (node->decl))
2987 : {
2988 0 : node->make_decl_local ();
2989 0 : node->set_section (NULL);
2990 0 : node->set_comdat_group (NULL);
2991 0 : node->externally_visible = false;
2992 0 : node->forced_by_abi = false;
2993 0 : node->local = true;
2994 0 : node->unique_name = ((node->resolution == LDPR_PREVAILING_DEF_IRONLY
2995 0 : || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
2996 0 : && !flag_incremental_link);
2997 0 : node->resolution = LDPR_PREVAILING_DEF_IRONLY;
2998 0 : gcc_assert (node->get_availability () == AVAIL_LOCAL);
2999 : }
3000 0 : return false;
3001 : }
3002 :
3003 : /* Bring cgraph node local. */
3004 :
3005 : void
3006 0 : cgraph_node::make_local (void)
3007 : {
3008 0 : call_for_symbol_thunks_and_aliases (cgraph_node::make_local, NULL, true);
3009 0 : }
3010 :
3011 : /* Worker to set nothrow flag. */
3012 :
3013 : static void
3014 1000140 : set_nothrow_flag_1 (cgraph_node *node, bool nothrow, bool non_call,
3015 : bool *changed)
3016 : {
3017 1000140 : cgraph_edge *e;
3018 :
3019 1000140 : if (nothrow && !TREE_NOTHROW (node->decl))
3020 : {
3021 : /* With non-call exceptions we can't say for sure if other function body
3022 : was not possibly optimized to still throw. */
3023 1000115 : if (!non_call || node->binds_to_current_def_p ())
3024 : {
3025 995197 : TREE_NOTHROW (node->decl) = true;
3026 995197 : *changed = true;
3027 2422779 : for (e = node->callers; e; e = e->next_caller)
3028 1427582 : e->can_throw_external = false;
3029 : }
3030 : }
3031 0 : else if (!nothrow && TREE_NOTHROW (node->decl))
3032 : {
3033 0 : TREE_NOTHROW (node->decl) = false;
3034 0 : *changed = true;
3035 : }
3036 1000140 : ipa_ref *ref;
3037 1055508 : FOR_EACH_ALIAS (node, ref)
3038 : {
3039 55368 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
3040 55368 : if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
3041 54943 : set_nothrow_flag_1 (alias, nothrow, non_call, changed);
3042 : }
3043 2464621 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
3044 1464481 : if (e->caller->thunk
3045 1464481 : && (!nothrow || e->caller->get_availability () > AVAIL_INTERPOSABLE))
3046 138 : set_nothrow_flag_1 (e->caller, nothrow, non_call, changed);
3047 1000140 : }
3048 :
3049 : /* Set TREE_NOTHROW on NODE's decl and on aliases of NODE
3050 : if any to NOTHROW. */
3051 :
3052 : bool
3053 952378 : cgraph_node::set_nothrow_flag (bool nothrow)
3054 : {
3055 952378 : bool changed = false;
3056 952378 : bool non_call = opt_for_fn (decl, flag_non_call_exceptions);
3057 :
3058 952378 : if (!nothrow || get_availability () > AVAIL_INTERPOSABLE)
3059 944952 : set_nothrow_flag_1 (this, nothrow, non_call, &changed);
3060 : else
3061 : {
3062 : ipa_ref *ref;
3063 :
3064 14989 : FOR_EACH_ALIAS (this, ref)
3065 : {
3066 7563 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
3067 7563 : if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
3068 107 : set_nothrow_flag_1 (alias, nothrow, non_call, &changed);
3069 : }
3070 : }
3071 952378 : return changed;
3072 : }
3073 :
3074 : /* Worker to set malloc flag. */
3075 : static void
3076 29874 : set_malloc_flag_1 (cgraph_node *node, bool malloc_p, bool *changed)
3077 : {
3078 29874 : if (malloc_p && !DECL_IS_MALLOC (node->decl))
3079 : {
3080 29470 : DECL_IS_MALLOC (node->decl) = true;
3081 29470 : *changed = true;
3082 : }
3083 :
3084 29874 : ipa_ref *ref;
3085 29875 : FOR_EACH_ALIAS (node, ref)
3086 : {
3087 1 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
3088 1 : if (!malloc_p || alias->get_availability () > AVAIL_INTERPOSABLE)
3089 1 : set_malloc_flag_1 (alias, malloc_p, changed);
3090 : }
3091 :
3092 61824 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
3093 31950 : if (e->caller->thunk
3094 31950 : && (!malloc_p || e->caller->get_availability () > AVAIL_INTERPOSABLE))
3095 0 : set_malloc_flag_1 (e->caller, malloc_p, changed);
3096 29874 : }
3097 :
3098 : /* Set DECL_IS_MALLOC on NODE's decl and on NODE's aliases if any. */
3099 :
3100 : bool
3101 29873 : cgraph_node::set_malloc_flag (bool malloc_p)
3102 : {
3103 29873 : bool changed = false;
3104 :
3105 29873 : if (!malloc_p || get_availability () > AVAIL_INTERPOSABLE)
3106 29873 : set_malloc_flag_1 (this, malloc_p, &changed);
3107 : else
3108 : {
3109 : ipa_ref *ref;
3110 :
3111 0 : FOR_EACH_ALIAS (this, ref)
3112 : {
3113 0 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
3114 0 : if (!malloc_p || alias->get_availability () > AVAIL_INTERPOSABLE)
3115 0 : set_malloc_flag_1 (alias, malloc_p, &changed);
3116 : }
3117 : }
3118 29873 : return changed;
3119 : }
3120 :
3121 : /* Worker to set malloc flag. */
3122 : static void
3123 247455 : add_detected_attribute_1 (cgraph_node *node, const char *attr, bool *changed)
3124 : {
3125 247455 : if (!lookup_attribute (attr, DECL_ATTRIBUTES (node->decl)))
3126 : {
3127 223179 : DECL_ATTRIBUTES (node->decl) = tree_cons (get_identifier (attr),
3128 223179 : NULL_TREE, DECL_ATTRIBUTES (node->decl));
3129 223179 : *changed = true;
3130 : }
3131 :
3132 247455 : ipa_ref *ref;
3133 248042 : FOR_EACH_ALIAS (node, ref)
3134 : {
3135 587 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
3136 587 : if (alias->get_availability () > AVAIL_INTERPOSABLE)
3137 134 : add_detected_attribute_1 (alias, attr, changed);
3138 : }
3139 :
3140 798961 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
3141 551506 : if (e->caller->thunk
3142 551506 : && (e->caller->get_availability () > AVAIL_INTERPOSABLE))
3143 17 : add_detected_attribute_1 (e->caller, attr, changed);
3144 247455 : }
3145 :
3146 : /* Add attribute ATTR to function and its aliases. */
3147 :
3148 : bool
3149 251220 : cgraph_node::add_detected_attribute (const char *attr)
3150 : {
3151 251220 : bool changed = false;
3152 :
3153 251220 : if (get_availability () > AVAIL_INTERPOSABLE)
3154 247304 : add_detected_attribute_1 (this, attr, &changed);
3155 : else
3156 : {
3157 : ipa_ref *ref;
3158 :
3159 3940 : FOR_EACH_ALIAS (this, ref)
3160 : {
3161 24 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
3162 24 : if (alias->get_availability () > AVAIL_INTERPOSABLE)
3163 0 : add_detected_attribute_1 (alias, attr, &changed);
3164 : }
3165 : }
3166 251220 : return changed;
3167 : }
3168 :
3169 : /* Worker to set noreturng flag. */
3170 : static void
3171 27777 : set_noreturn_flag_1 (cgraph_node *node, bool noreturn_p, bool *changed)
3172 : {
3173 27777 : if (noreturn_p && !TREE_THIS_VOLATILE (node->decl))
3174 : {
3175 27777 : TREE_THIS_VOLATILE (node->decl) = true;
3176 27777 : *changed = true;
3177 : }
3178 :
3179 27777 : ipa_ref *ref;
3180 28423 : FOR_EACH_ALIAS (node, ref)
3181 : {
3182 646 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
3183 646 : if (!noreturn_p || alias->get_availability () > AVAIL_INTERPOSABLE)
3184 646 : set_noreturn_flag_1 (alias, noreturn_p, changed);
3185 : }
3186 :
3187 43972 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
3188 16195 : if (e->caller->thunk
3189 16195 : && (!noreturn_p || e->caller->get_availability () > AVAIL_INTERPOSABLE))
3190 20 : set_noreturn_flag_1 (e->caller, noreturn_p, changed);
3191 27777 : }
3192 :
3193 : /* Set TREE_THIS_VOLATILE on NODE's decl and on NODE's aliases if any. */
3194 :
3195 : bool
3196 27119 : cgraph_node::set_noreturn_flag (bool noreturn_p)
3197 : {
3198 27119 : bool changed = false;
3199 :
3200 27119 : if (!noreturn_p || get_availability () > AVAIL_INTERPOSABLE)
3201 27102 : set_noreturn_flag_1 (this, noreturn_p, &changed);
3202 : else
3203 : {
3204 : ipa_ref *ref;
3205 :
3206 34 : FOR_EACH_ALIAS (this, ref)
3207 : {
3208 17 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
3209 17 : if (!noreturn_p || alias->get_availability () > AVAIL_INTERPOSABLE)
3210 9 : set_noreturn_flag_1 (alias, noreturn_p, &changed);
3211 : }
3212 : }
3213 27119 : return changed;
3214 : }
3215 :
3216 : /* Worker to set_const_flag. */
3217 :
3218 : static void
3219 1000513 : set_const_flag_1 (cgraph_node *node, bool set_const, bool looping,
3220 : bool *changed)
3221 : {
3222 : /* Static constructors and destructors without a side effect can be
3223 : optimized out. */
3224 1000513 : if (set_const && !looping)
3225 : {
3226 993994 : if (DECL_STATIC_CONSTRUCTOR (node->decl))
3227 : {
3228 233 : DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
3229 233 : *changed = true;
3230 : }
3231 993994 : if (DECL_STATIC_DESTRUCTOR (node->decl))
3232 : {
3233 1 : DECL_STATIC_DESTRUCTOR (node->decl) = 0;
3234 1 : *changed = true;
3235 : }
3236 : }
3237 1000513 : if (!set_const)
3238 : {
3239 2702 : if (TREE_READONLY (node->decl))
3240 : {
3241 158 : TREE_READONLY (node->decl) = 0;
3242 158 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
3243 158 : *changed = true;
3244 : }
3245 : }
3246 : else
3247 : {
3248 : /* Consider function:
3249 :
3250 : bool a(int *p)
3251 : {
3252 : return *p==*p;
3253 : }
3254 :
3255 : During early optimization we will turn this into:
3256 :
3257 : bool a(int *p)
3258 : {
3259 : return true;
3260 : }
3261 :
3262 : Now if this function will be detected as CONST however when interposed
3263 : it may end up being just pure. We always must assume the worst
3264 : scenario here. */
3265 997811 : if (TREE_READONLY (node->decl))
3266 : {
3267 736 : if (!looping && DECL_LOOPING_CONST_OR_PURE_P (node->decl))
3268 : {
3269 391 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
3270 391 : *changed = true;
3271 : }
3272 : }
3273 997075 : else if (node->binds_to_current_def_p ())
3274 : {
3275 176754 : TREE_READONLY (node->decl) = true;
3276 176754 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
3277 176754 : DECL_PURE_P (node->decl) = false;
3278 176754 : *changed = true;
3279 : }
3280 : else
3281 : {
3282 820321 : if (dump_file && (dump_flags & TDF_DETAILS))
3283 0 : fprintf (dump_file, "Dropping state to PURE because function does "
3284 : "not bind to current def.\n");
3285 820321 : if (!DECL_PURE_P (node->decl))
3286 : {
3287 391064 : DECL_PURE_P (node->decl) = true;
3288 391064 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
3289 391064 : *changed = true;
3290 : }
3291 429257 : else if (!looping && DECL_LOOPING_CONST_OR_PURE_P (node->decl))
3292 : {
3293 140 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
3294 140 : *changed = true;
3295 : }
3296 : }
3297 : }
3298 :
3299 1000513 : ipa_ref *ref;
3300 1106971 : FOR_EACH_ALIAS (node, ref)
3301 : {
3302 106458 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
3303 106458 : if (!set_const || alias->get_availability () > AVAIL_INTERPOSABLE)
3304 106395 : set_const_flag_1 (alias, set_const, looping, changed);
3305 : }
3306 1000609 : for (struct cgraph_node *n = node->simd_clones; n != NULL;
3307 96 : n = n->simdclone->next_clone)
3308 96 : set_const_flag_1 (n, set_const, looping, changed);
3309 2713635 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
3310 1713122 : if (e->caller->thunk
3311 1713122 : && (!set_const || e->caller->get_availability () > AVAIL_INTERPOSABLE))
3312 : {
3313 : /* Virtual thunks access virtual offset in the vtable, so they can
3314 : only be pure, never const. */
3315 369 : if (set_const
3316 369 : && (thunk_info::get (e->caller)->virtual_offset_p
3317 238 : || !node->binds_to_current_def_p (e->caller)))
3318 131 : *changed |= e->caller->set_pure_flag (true, looping);
3319 : else
3320 238 : set_const_flag_1 (e->caller, set_const, looping, changed);
3321 : }
3322 1000513 : }
3323 :
3324 : /* If SET_CONST is true, mark function, aliases and thunks to be ECF_CONST.
3325 : If SET_CONST if false, clear the flag.
3326 :
3327 : When setting the flag be careful about possible interposition and
3328 : do not set the flag for functions that can be interposed and set pure
3329 : flag for functions that can bind to other definition.
3330 :
3331 : Return true if any change was done. */
3332 :
3333 : bool
3334 922715 : cgraph_node::set_const_flag (bool set_const, bool looping)
3335 : {
3336 922715 : bool changed = false;
3337 922715 : if (!set_const || get_availability () > AVAIL_INTERPOSABLE)
3338 893552 : set_const_flag_1 (this, set_const, looping, &changed);
3339 : else
3340 : {
3341 : ipa_ref *ref;
3342 :
3343 30079 : FOR_EACH_ALIAS (this, ref)
3344 : {
3345 916 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
3346 916 : if (!set_const || alias->get_availability () > AVAIL_INTERPOSABLE)
3347 232 : set_const_flag_1 (alias, set_const, looping, &changed);
3348 : }
3349 : }
3350 922715 : return changed;
3351 : }
3352 :
3353 : /* Info used by set_pure_flag_1. */
3354 :
3355 : struct set_pure_flag_info
3356 : {
3357 : bool pure;
3358 : bool looping;
3359 : bool changed;
3360 : };
3361 :
3362 : /* Worker to set_pure_flag. */
3363 :
3364 : static bool
3365 370655 : set_pure_flag_1 (cgraph_node *node, void *data)
3366 : {
3367 370655 : struct set_pure_flag_info *info = (struct set_pure_flag_info *)data;
3368 : /* Static constructors and destructors without a side effect can be
3369 : optimized out. */
3370 370655 : if (info->pure && !info->looping)
3371 : {
3372 301905 : if (DECL_STATIC_CONSTRUCTOR (node->decl))
3373 : {
3374 0 : DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
3375 0 : info->changed = true;
3376 : }
3377 301905 : if (DECL_STATIC_DESTRUCTOR (node->decl))
3378 : {
3379 0 : DECL_STATIC_DESTRUCTOR (node->decl) = 0;
3380 0 : info->changed = true;
3381 : }
3382 : }
3383 370655 : if (info->pure)
3384 : {
3385 367953 : if (!DECL_PURE_P (node->decl) && !TREE_READONLY (node->decl))
3386 : {
3387 367420 : DECL_PURE_P (node->decl) = true;
3388 367420 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = info->looping;
3389 367420 : info->changed = true;
3390 : }
3391 533 : else if (DECL_LOOPING_CONST_OR_PURE_P (node->decl)
3392 533 : && !info->looping)
3393 : {
3394 264 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
3395 264 : info->changed = true;
3396 : }
3397 : }
3398 : else
3399 : {
3400 2702 : if (DECL_PURE_P (node->decl))
3401 : {
3402 75 : DECL_PURE_P (node->decl) = false;
3403 75 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
3404 75 : info->changed = true;
3405 : }
3406 : }
3407 370655 : return false;
3408 : }
3409 :
3410 : /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
3411 : if any to PURE.
3412 :
3413 : When setting the flag, be careful about possible interposition.
3414 : Return true if any change was done. */
3415 :
3416 : bool
3417 380888 : cgraph_node::set_pure_flag (bool pure, bool looping)
3418 : {
3419 380888 : struct set_pure_flag_info info = {pure, looping, false};
3420 380888 : call_for_symbol_thunks_and_aliases (set_pure_flag_1, &info, !pure, true);
3421 380888 : for (struct cgraph_node *n = simd_clones; n != NULL;
3422 0 : n = n->simdclone->next_clone)
3423 0 : set_pure_flag_1 (n, &info);
3424 380888 : return info.changed;
3425 : }
3426 :
3427 : /* Return true when cgraph_node cannot return or throw and thus
3428 : it is safe to ignore its side effects for IPA analysis. */
3429 :
3430 : bool
3431 14892905 : cgraph_node::cannot_return_p (void)
3432 : {
3433 14892905 : int flags = flags_from_decl_or_type (decl);
3434 14892905 : if (!opt_for_fn (decl, flag_exceptions))
3435 4866639 : return (flags & ECF_NORETURN) != 0;
3436 : else
3437 10026266 : return ((flags & (ECF_NORETURN | ECF_NOTHROW))
3438 10026266 : == (ECF_NORETURN | ECF_NOTHROW));
3439 : }
3440 :
3441 : /* Return true when call of edge cannot lead to return from caller
3442 : and thus it is safe to ignore its side effects for IPA analysis
3443 : when computing side effects of the caller.
3444 : FIXME: We could actually mark all edges that have no reaching
3445 : patch to the exit block or throw to get better results. */
3446 : bool
3447 3152186 : cgraph_edge::cannot_lead_to_return_p (void)
3448 : {
3449 3152186 : if (caller->cannot_return_p ())
3450 : return true;
3451 3062530 : if (indirect_unknown_callee)
3452 : {
3453 87401 : int flags = indirect_info->ecf_flags;
3454 87401 : if (!opt_for_fn (caller->decl, flag_exceptions))
3455 20561 : return (flags & ECF_NORETURN) != 0;
3456 : else
3457 66840 : return ((flags & (ECF_NORETURN | ECF_NOTHROW))
3458 66840 : == (ECF_NORETURN | ECF_NOTHROW));
3459 : }
3460 : else
3461 2975129 : return callee->cannot_return_p ();
3462 : }
3463 :
3464 : /* Return true if the edge after scaling it profile by SCALE
3465 : may be considered hot. */
3466 :
3467 : bool
3468 5726089 : cgraph_edge::maybe_hot_p (sreal scale)
3469 : {
3470 : /* Never consider calls in functions optimized for size hot. */
3471 5726089 : if (opt_for_fn (caller->decl, optimize_size))
3472 : return false;
3473 :
3474 : /* If reliable IPA count is available, just use it. */
3475 5662268 : profile_count c = count.ipa ();
3476 5662268 : if (c.reliable_p ()
3477 5662268 : || (c.quality () == AFDO && c.nonzero_p ()))
3478 790913 : return maybe_hot_count_p (NULL, c * scale);
3479 :
3480 : /* In auto-FDO, count 0 may lead to hot code in case the
3481 : call is simply not called often enough to receive some samples. */
3482 4871355 : if ((c.quality () == AFDO
3483 4871355 : || count.quality () == GUESSED_GLOBAL0_ADJUSTED)
3484 4871355 : && callee && callee->count.quality () == AFDO)
3485 0 : return maybe_hot_count_p (NULL, c.force_nonzero () * scale);
3486 :
3487 : /* See if we can determine hotness using caller frequency. */
3488 4871355 : if (caller->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
3489 4867071 : || (callee
3490 4451884 : && callee->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED))
3491 : return false;
3492 4864791 : if (caller->frequency > NODE_FREQUENCY_UNLIKELY_EXECUTED
3493 4864791 : && (callee
3494 4449604 : && callee->frequency <= NODE_FREQUENCY_EXECUTED_ONCE))
3495 : return false;
3496 : /* ??? This may make sense for hot functions determined by
3497 : user attribute, but if function is hot by profile, it may
3498 : contains non-hot calls. In most practical cases this case
3499 : is handled by the reliable ipa count above, but i.e. after
3500 : inlining function with no profile to function with profile
3501 : we get here.. */
3502 4803347 : if (caller->frequency == NODE_FREQUENCY_HOT)
3503 : return true;
3504 :
3505 : /* Use IPA count and if it s not available apply local heuristics. */
3506 4803345 : if (c.initialized_p ())
3507 : {
3508 : /* A special case; AFDO zero means that function may quite possibly
3509 : be executed few times per execution. If scale is large, we still
3510 : want to consider the call hot. */
3511 0 : if (c.quality () == AFDO)
3512 0 : c = c.force_nonzero ();
3513 0 : return maybe_hot_count_p (NULL, c * scale);
3514 : }
3515 4803345 : if (!count.initialized_p ())
3516 : return true;
3517 3489249 : cgraph_node *where = caller->inlined_to ? caller->inlined_to : caller;
3518 3489249 : if (!where->count.initialized_p ())
3519 : return true;
3520 3489249 : c = count * scale;
3521 3489249 : if (caller->frequency == NODE_FREQUENCY_EXECUTED_ONCE)
3522 : {
3523 80114 : if (c * 2 < where->count * 3)
3524 21257 : return false;
3525 : }
3526 3409135 : else if (c * param_hot_bb_frequency_fraction < where->count)
3527 391893 : return false;
3528 : return true;
3529 : }
3530 :
3531 : /* Return true if the edge may be considered hot. */
3532 :
3533 : bool
3534 2296843 : cgraph_edge::maybe_hot_p ()
3535 : {
3536 2296843 : return maybe_hot_p (1);
3537 : }
3538 :
3539 : /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
3540 :
3541 : static bool
3542 700824 : nonremovable_p (cgraph_node *node, void *)
3543 : {
3544 700824 : return !node->can_remove_if_no_direct_calls_and_refs_p ();
3545 : }
3546 :
3547 : /* Return true if whole comdat group can be removed if there are no direct
3548 : calls to THIS. */
3549 :
3550 : bool
3551 945855 : cgraph_node::can_remove_if_no_direct_calls_p (bool will_inline)
3552 : {
3553 945855 : struct ipa_ref *ref;
3554 :
3555 : /* For local symbols or non-comdat group it is the same as
3556 : can_remove_if_no_direct_calls_p. */
3557 945855 : if (!externally_visible || !same_comdat_group)
3558 : {
3559 706509 : if (DECL_EXTERNAL (decl))
3560 : return true;
3561 706509 : if (address_taken)
3562 : return false;
3563 673768 : return !call_for_symbol_and_aliases (nonremovable_p, NULL, true);
3564 : }
3565 :
3566 239346 : if (will_inline && address_taken)
3567 : return false;
3568 :
3569 : /* Otherwise check if we can remove the symbol itself and then verify
3570 : that only uses of the comdat groups are direct call to THIS
3571 : or its aliases. */
3572 239346 : if (!can_remove_if_no_direct_calls_and_refs_p ())
3573 : return false;
3574 :
3575 : /* Check that all refs come from within the comdat group. */
3576 460616 : for (int i = 0; iterate_referring (i, ref); i++)
3577 234253 : if (ref->referring->get_comdat_group () != get_comdat_group ())
3578 : return false;
3579 :
3580 226363 : struct cgraph_node *target = ultimate_alias_target ();
3581 452726 : for (cgraph_node *next = dyn_cast<cgraph_node *> (same_comdat_group);
3582 681787 : next != this; next = dyn_cast<cgraph_node *> (next->same_comdat_group))
3583 : {
3584 239561 : if (!externally_visible)
3585 0 : continue;
3586 239561 : if (!next->alias
3587 239561 : && !next->can_remove_if_no_direct_calls_and_refs_p ())
3588 : return false;
3589 :
3590 : /* If we see different symbol than THIS, be sure to check calls. */
3591 239561 : if (next->ultimate_alias_target () != target)
3592 22056 : for (cgraph_edge *e = next->callers; e; e = e->next_caller)
3593 4889 : if (e->caller->get_comdat_group () != get_comdat_group ()
3594 4889 : || will_inline)
3595 : return false;
3596 :
3597 : /* If function is not being inlined, we care only about
3598 : references outside of the comdat group. */
3599 237692 : if (!will_inline)
3600 238854 : for (int i = 0; next->iterate_referring (i, ref); i++)
3601 11142 : if (ref->referring->get_comdat_group () != get_comdat_group ())
3602 : return false;
3603 : }
3604 : return true;
3605 : }
3606 :
3607 : /* Return true when function cgraph_node can be expected to be removed
3608 : from program when direct calls in this compilation unit are removed.
3609 :
3610 : As a special case COMDAT functions are
3611 : cgraph_can_remove_if_no_direct_calls_p while the are not
3612 : cgraph_only_called_directly_p (it is possible they are called from other
3613 : unit)
3614 :
3615 : This function behaves as cgraph_only_called_directly_p because eliminating
3616 : all uses of COMDAT function does not make it necessarily disappear from
3617 : the program unless we are compiling whole program or we do LTO. In this
3618 : case we know we win since dynamic linking will not really discard the
3619 : linkonce section. */
3620 :
3621 : bool
3622 3215498 : cgraph_node::will_be_removed_from_program_if_no_direct_calls_p
3623 : (bool will_inline)
3624 : {
3625 3215498 : gcc_assert (!inlined_to);
3626 3215498 : if (DECL_EXTERNAL (decl))
3627 : return true;
3628 :
3629 3215498 : if (!in_lto_p && !flag_whole_program)
3630 : {
3631 : /* If the symbol is in comdat group, we need to verify that whole comdat
3632 : group becomes unreachable. Technically we could skip references from
3633 : within the group, too. */
3634 2995841 : if (!only_called_directly_p ())
3635 : return false;
3636 773238 : if (same_comdat_group && externally_visible)
3637 : {
3638 0 : struct cgraph_node *target = ultimate_alias_target ();
3639 :
3640 0 : if (will_inline && address_taken)
3641 : return true;
3642 0 : for (cgraph_node *next = dyn_cast<cgraph_node *> (same_comdat_group);
3643 0 : next != this;
3644 0 : next = dyn_cast<cgraph_node *> (next->same_comdat_group))
3645 : {
3646 0 : if (!externally_visible)
3647 0 : continue;
3648 0 : if (!next->alias
3649 0 : && !next->only_called_directly_p ())
3650 : return false;
3651 :
3652 : /* If we see different symbol than THIS,
3653 : be sure to check calls. */
3654 0 : if (next->ultimate_alias_target () != target)
3655 0 : for (cgraph_edge *e = next->callers; e; e = e->next_caller)
3656 0 : if (e->caller->get_comdat_group () != get_comdat_group ()
3657 0 : || will_inline)
3658 : return false;
3659 : }
3660 : }
3661 : return true;
3662 : }
3663 : else
3664 219657 : return can_remove_if_no_direct_calls_p (will_inline);
3665 : }
3666 :
3667 :
3668 : /* Worker for cgraph_only_called_directly_p. */
3669 :
3670 : static bool
3671 16632642 : cgraph_not_only_called_directly_p_1 (cgraph_node *node, void *)
3672 : {
3673 16632642 : return !node->only_called_directly_or_aliased_p ();
3674 : }
3675 :
3676 : /* Return true when function cgraph_node and all its aliases are only called
3677 : directly.
3678 : i.e. it is not externally visible, address was not taken and
3679 : it is not used in any other non-standard way. */
3680 :
3681 : bool
3682 16415706 : cgraph_node::only_called_directly_p (void)
3683 : {
3684 16415706 : gcc_assert (ultimate_alias_target () == this);
3685 16415706 : return !call_for_symbol_and_aliases (cgraph_not_only_called_directly_p_1,
3686 16415706 : NULL, true);
3687 : }
3688 :
3689 : /* Returns TRUE iff THIS is a descendant of N in the clone tree. */
3690 :
3691 : bool
3692 29 : cgraph_node::is_clone_of (cgraph_node *n) const
3693 : {
3694 29 : for (cgraph_node *walker = clone_of; walker; walker = walker->clone_of)
3695 0 : if (walker == n)
3696 : return true;
3697 : return false;
3698 : }
3699 :
3700 : /* Collect all callers of NODE. Worker for collect_callers_of_node. */
3701 :
3702 : static bool
3703 139984 : collect_callers_of_node_1 (cgraph_node *node, void *data)
3704 : {
3705 139984 : vec<cgraph_edge *> *redirect_callers = (vec<cgraph_edge *> *)data;
3706 139984 : cgraph_edge *cs;
3707 139984 : enum availability avail;
3708 139984 : node->ultimate_alias_target (&avail);
3709 :
3710 139984 : if (avail > AVAIL_INTERPOSABLE)
3711 478484 : for (cs = node->callers; cs != NULL; cs = cs->next_caller)
3712 338500 : if (!cs->indirect_inlining_edge
3713 338500 : && !cs->caller->thunk)
3714 338500 : redirect_callers->safe_push (cs);
3715 139984 : return false;
3716 : }
3717 :
3718 : /* Collect all callers of cgraph_node and its aliases that are known to lead to
3719 : cgraph_node (i.e. are not overwritable). */
3720 :
3721 : auto_vec<cgraph_edge *>
3722 138759 : cgraph_node::collect_callers (void)
3723 : {
3724 138759 : auto_vec<cgraph_edge *> redirect_callers;
3725 138759 : call_for_symbol_thunks_and_aliases (collect_callers_of_node_1,
3726 : &redirect_callers, false);
3727 138759 : return redirect_callers;
3728 : }
3729 :
3730 :
3731 : /* Return TRUE if NODE2 a clone of NODE or is equivalent to it. Return
3732 : optimistically true if this cannot be determined. */
3733 :
3734 : static bool
3735 30396 : clone_of_p (cgraph_node *node, cgraph_node *node2)
3736 : {
3737 30396 : node = node->ultimate_alias_target ();
3738 30396 : node2 = node2->ultimate_alias_target ();
3739 :
3740 30396 : if (node2->clone_of == node
3741 2382 : || node2->former_clone_of == node->decl)
3742 : return true;
3743 :
3744 2382 : if (!node->thunk && !node->former_thunk_p ())
3745 : {
3746 : while (node2
3747 7145 : && node->decl != node2->decl
3748 11909 : && node->decl != node2->former_clone_of)
3749 4763 : node2 = node2->clone_of;
3750 2382 : return node2 != NULL;
3751 : }
3752 :
3753 : /* There are no virtual clones of thunks so check former_clone_of or if we
3754 : might have skipped thunks because this adjustments are no longer
3755 : necessary. */
3756 0 : while (node->thunk || node->former_thunk_p ())
3757 : {
3758 0 : if (!thunk_info::get (node)->this_adjusting)
3759 : return false;
3760 : /* In case of instrumented expanded thunks, which can have multiple calls
3761 : in them, we do not know how to continue and just have to be
3762 : optimistic. The same applies if all calls have already been inlined
3763 : into the thunk. */
3764 0 : if (!node->callees || node->callees->next_callee)
3765 : return true;
3766 0 : node = node->callees->callee->ultimate_alias_target ();
3767 :
3768 0 : clone_info *info = clone_info::get (node2);
3769 0 : if (!info || !info->param_adjustments
3770 0 : || info->param_adjustments->first_param_intact_p ())
3771 : return false;
3772 0 : if (node2->former_clone_of == node->decl
3773 0 : || node2->former_clone_of == node->former_clone_of)
3774 : return true;
3775 :
3776 : cgraph_node *n2 = node2;
3777 0 : while (n2 && node->decl != n2->decl)
3778 0 : n2 = n2->clone_of;
3779 0 : if (n2)
3780 : return true;
3781 : }
3782 :
3783 : return false;
3784 : }
3785 :
3786 : /* Verify edge count and frequency. */
3787 :
3788 : bool
3789 205149250 : cgraph_edge::verify_count ()
3790 : {
3791 205149250 : bool error_found = false;
3792 205149250 : if (!count.verify ())
3793 : {
3794 0 : error ("caller edge count invalid");
3795 0 : error_found = true;
3796 : }
3797 205149250 : return error_found;
3798 : }
3799 :
3800 : /* Switch to THIS_CFUN if needed and print STMT to stderr. */
3801 : static void
3802 0 : cgraph_debug_gimple_stmt (function *this_cfun, gimple *stmt)
3803 : {
3804 0 : bool fndecl_was_null = false;
3805 : /* debug_gimple_stmt needs correct cfun */
3806 0 : if (cfun != this_cfun)
3807 0 : set_cfun (this_cfun);
3808 : /* ...and an actual current_function_decl */
3809 0 : if (!current_function_decl)
3810 : {
3811 0 : current_function_decl = this_cfun->decl;
3812 0 : fndecl_was_null = true;
3813 : }
3814 0 : debug_gimple_stmt (stmt);
3815 0 : if (fndecl_was_null)
3816 0 : current_function_decl = NULL;
3817 0 : }
3818 :
3819 : /* Verify that call graph edge corresponds to DECL from the associated
3820 : statement. Return true if the verification should fail. */
3821 :
3822 : bool
3823 101100890 : cgraph_edge::verify_corresponds_to_fndecl (tree decl)
3824 : {
3825 101100890 : cgraph_node *node;
3826 :
3827 101100890 : if (!decl || callee->inlined_to)
3828 : return false;
3829 97280628 : if (symtab->state == LTO_STREAMING)
3830 : return false;
3831 97280628 : node = cgraph_node::get (decl);
3832 :
3833 : /* We do not know if a node from a different partition is an alias or what it
3834 : aliases and therefore cannot do the former_clone_of check reliably. When
3835 : body_removed is set, we have lost all information about what was alias or
3836 : thunk of and also cannot proceed. */
3837 97280628 : if (!node
3838 97199670 : || node->body_removed
3839 96215884 : || node->in_other_partition
3840 96215884 : || callee->icf_merged
3841 96107585 : || callee->in_other_partition)
3842 : return false;
3843 :
3844 96107585 : node = node->ultimate_alias_target ();
3845 :
3846 : /* Optimizers can redirect unreachable calls or calls triggering undefined
3847 : behavior to __builtin_unreachable or __builtin_unreachable trap. */
3848 :
3849 96107585 : if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE,
3850 : BUILT_IN_UNREACHABLE_TRAP))
3851 : return false;
3852 :
3853 93163158 : if (callee->former_clone_of != node->decl
3854 93161381 : && (node != callee->ultimate_alias_target ())
3855 93193554 : && !clone_of_p (node, callee))
3856 : return true;
3857 : else
3858 93163158 : return false;
3859 : }
3860 :
3861 : /* Disable warnings about missing quoting in GCC diagnostics for
3862 : the verification errors. Their format strings don't follow GCC
3863 : diagnostic conventions and the calls are ultimately followed by
3864 : one to internal_error. */
3865 : #if __GNUC__ >= 10
3866 : # pragma GCC diagnostic push
3867 : # pragma GCC diagnostic ignored "-Wformat-diag"
3868 : #endif
3869 :
3870 : /* Verify consistency of speculative call in NODE corresponding to STMT
3871 : and LTO_STMT_UID. If INDIRECT is set, assume that it is the indirect
3872 : edge of call sequence. Return true if error is found.
3873 :
3874 : This function is called to every component of indirect call (direct edges,
3875 : indirect edge and refs). To save duplicated work, do full testing only
3876 : in that case. */
3877 : static bool
3878 444288 : verify_speculative_call (struct cgraph_node *node, gimple *stmt,
3879 : unsigned int lto_stmt_uid,
3880 : struct cgraph_edge *indirect)
3881 : {
3882 444288 : if (indirect == NULL)
3883 : {
3884 541328 : for (indirect = node->indirect_calls; indirect;
3885 215680 : indirect = indirect->next_callee)
3886 541328 : if (indirect->call_stmt == stmt
3887 325814 : && indirect->lto_stmt_uid == lto_stmt_uid)
3888 : break;
3889 325648 : if (!indirect)
3890 : {
3891 0 : error ("missing indirect call in speculative call sequence");
3892 0 : return true;
3893 : }
3894 325648 : if (!indirect->speculative)
3895 : {
3896 0 : error ("indirect call in speculative call sequence has no "
3897 : "speculative flag");
3898 0 : return true;
3899 : }
3900 : return false;
3901 : }
3902 :
3903 : /* Maximal number of targets. We probably will never want to have more than
3904 : this. */
3905 : const unsigned int num = 256;
3906 : cgraph_edge *direct_calls[num];
3907 : ipa_ref *refs[num];
3908 :
3909 30490480 : for (unsigned int i = 0; i < num; i++)
3910 : {
3911 30371840 : direct_calls[i] = NULL;
3912 30371840 : refs[i] = NULL;
3913 : }
3914 :
3915 118640 : cgraph_edge *first_call = NULL;
3916 118640 : cgraph_edge *prev_call = NULL;
3917 :
3918 1438869 : for (cgraph_edge *direct = node->callees; direct;
3919 1320229 : direct = direct->next_callee)
3920 1320229 : if (direct->call_stmt == stmt && direct->lto_stmt_uid == lto_stmt_uid)
3921 : {
3922 162824 : if (!first_call)
3923 118640 : first_call = direct;
3924 162824 : if (prev_call && direct != prev_call->next_callee)
3925 : {
3926 0 : error ("speculative edges are not adjacent");
3927 0 : return true;
3928 : }
3929 162824 : prev_call = direct;
3930 162824 : if (!direct->speculative)
3931 : {
3932 0 : error ("direct call to %s in speculative call sequence has no "
3933 0 : "speculative flag", direct->callee->dump_name ());
3934 0 : return true;
3935 : }
3936 162824 : if (direct->speculative_id >= num)
3937 : {
3938 0 : error ("direct call to %s in speculative call sequence has "
3939 : "speculative_id %i out of range",
3940 0 : direct->callee->dump_name (), direct->speculative_id);
3941 0 : return true;
3942 : }
3943 162824 : if (direct_calls[direct->speculative_id])
3944 : {
3945 0 : error ("duplicate direct call to %s in speculative call sequence "
3946 : "with speculative_id %i",
3947 0 : direct->callee->dump_name (), direct->speculative_id);
3948 0 : return true;
3949 : }
3950 162824 : direct_calls[direct->speculative_id] = direct;
3951 : }
3952 :
3953 118640 : if (first_call->call_stmt
3954 118640 : && first_call != node->get_edge (first_call->call_stmt))
3955 : {
3956 0 : error ("call stmt hash does not point to first direct edge of "
3957 : "speculative call sequence");
3958 0 : return true;
3959 : }
3960 :
3961 : ipa_ref *ref;
3962 1584622 : for (int i = 0; node->iterate_reference (i, ref); i++)
3963 1465982 : if (ref->speculative
3964 284134 : && ref->stmt == stmt && ref->lto_stmt_uid == lto_stmt_uid)
3965 : {
3966 162824 : if (ref->speculative_id >= num)
3967 : {
3968 0 : error ("direct call to %s in speculative call sequence has "
3969 : "speculative_id %i out of range",
3970 0 : ref->referred->dump_name (), ref->speculative_id);
3971 0 : return true;
3972 : }
3973 162824 : if (refs[ref->speculative_id])
3974 : {
3975 0 : error ("duplicate reference %s in speculative call sequence "
3976 : "with speculative_id %i",
3977 0 : ref->referred->dump_name (), ref->speculative_id);
3978 0 : return true;
3979 : }
3980 162824 : refs[ref->speculative_id] = ref;
3981 : }
3982 :
3983 : int num_targets = 0;
3984 30490480 : for (unsigned int i = 0 ; i < num ; i++)
3985 : {
3986 30371840 : if (refs[i] && !direct_calls[i])
3987 : {
3988 0 : error ("missing direct call for speculation %i", i);
3989 0 : return true;
3990 : }
3991 30371840 : if (!refs[i] && direct_calls[i])
3992 : {
3993 0 : error ("missing ref for speculation %i", i);
3994 0 : return true;
3995 : }
3996 30371840 : if (refs[i] != NULL)
3997 162824 : num_targets++;
3998 : }
3999 :
4000 118640 : if (num_targets != indirect->num_speculative_call_targets_p ())
4001 : {
4002 0 : error ("number of speculative targets %i mismatched with "
4003 : "num_speculative_call_targets %i",
4004 : num_targets,
4005 : indirect->num_speculative_call_targets_p ());
4006 0 : return true;
4007 : }
4008 : return false;
4009 : }
4010 :
4011 : /* Verify cgraph nodes of given cgraph node. */
4012 : DEBUG_FUNCTION void
4013 53680584 : cgraph_node::verify_node (void)
4014 : {
4015 53680584 : cgraph_edge *e;
4016 53680584 : function *this_cfun = DECL_STRUCT_FUNCTION (decl);
4017 53680584 : basic_block this_block;
4018 53680584 : gimple_stmt_iterator gsi;
4019 53680584 : bool error_found = false;
4020 53680584 : int i;
4021 53680584 : ipa_ref *ref = NULL;
4022 :
4023 53680584 : if (seen_error ())
4024 53680584 : return;
4025 :
4026 53680584 : timevar_push (TV_CGRAPH_VERIFY);
4027 53680584 : error_found |= verify_base ();
4028 163958110 : for (e = callees; e; e = e->next_callee)
4029 110277526 : if (e->aux)
4030 : {
4031 0 : error ("aux field set for edge %s->%s",
4032 0 : identifier_to_locale (e->caller->name ()),
4033 0 : identifier_to_locale (e->callee->name ()));
4034 0 : error_found = true;
4035 : }
4036 53680584 : if (!count.verify ())
4037 : {
4038 0 : error ("cgraph count invalid");
4039 0 : error_found = true;
4040 : }
4041 53680584 : if (inlined_to && same_comdat_group)
4042 : {
4043 0 : error ("inline clone in same comdat group list");
4044 0 : error_found = true;
4045 : }
4046 53680584 : if (inlined_to && !count.compatible_p (inlined_to->count))
4047 : {
4048 0 : error ("inline clone count is not compatible");
4049 0 : count.debug ();
4050 0 : inlined_to->count.debug ();
4051 0 : error_found = true;
4052 : }
4053 53680584 : if (tp_first_run < 0)
4054 : {
4055 0 : error ("tp_first_run must be non-negative");
4056 0 : error_found = true;
4057 : }
4058 53680584 : if (!definition && !in_other_partition && local)
4059 : {
4060 0 : error ("local symbols must be defined");
4061 0 : error_found = true;
4062 : }
4063 53680584 : if (inlined_to && externally_visible)
4064 : {
4065 0 : error ("externally visible inline clone");
4066 0 : error_found = true;
4067 : }
4068 53680584 : if (inlined_to && address_taken)
4069 : {
4070 0 : error ("inline clone with address taken");
4071 0 : error_found = true;
4072 : }
4073 53680584 : if (inlined_to && force_output)
4074 : {
4075 0 : error ("inline clone is forced to output");
4076 0 : error_found = true;
4077 : }
4078 53680584 : if (inlined_to && ref_by_asm)
4079 : {
4080 0 : error ("inline clone is referenced by assembly");
4081 0 : error_found = true;
4082 : }
4083 53680584 : if (symtab->state != LTO_STREAMING)
4084 : {
4085 53565840 : if (calls_comdat_local && !same_comdat_group)
4086 : {
4087 0 : error ("calls_comdat_local is set outside of a comdat group");
4088 0 : error_found = true;
4089 : }
4090 53565840 : if (!inlined_to && calls_comdat_local != check_calls_comdat_local_p ())
4091 : {
4092 0 : error ("invalid calls_comdat_local flag");
4093 0 : error_found = true;
4094 : }
4095 : }
4096 53680584 : if (DECL_IS_MALLOC (decl)
4097 53680584 : && !POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
4098 : {
4099 0 : error ("malloc attribute should be used for a function that "
4100 : "returns a pointer");
4101 0 : error_found = true;
4102 : }
4103 53680584 : if (definition
4104 36329235 : && externally_visible
4105 : /* For aliases in lto1 free_lang_data doesn't guarantee preservation
4106 : of opt_for_fn (decl, flag_semantic_interposition). See PR105399. */
4107 19608143 : && (!alias || !in_lto_p)
4108 53680584 : && semantic_interposition
4109 19605208 : != opt_for_fn (decl, flag_semantic_interposition))
4110 : {
4111 0 : error ("semantic interposition mismatch");
4112 0 : error_found = true;
4113 : }
4114 56070126 : for (e = indirect_calls; e; e = e->next_callee)
4115 : {
4116 2389542 : if (e->aux)
4117 : {
4118 0 : error ("aux field set for indirect edge from %s",
4119 0 : identifier_to_locale (e->caller->name ()));
4120 0 : error_found = true;
4121 : }
4122 2389542 : if (!e->count.compatible_p (count))
4123 : {
4124 0 : error ("edge count is not compatible with function count");
4125 0 : e->count.debug ();
4126 0 : count.debug ();
4127 0 : error_found = true;
4128 : }
4129 2389542 : if (inlined_to && !e->count.compatible_p (inlined_to->count))
4130 : {
4131 0 : error ("edge count is not compatible with inlined to function count");
4132 0 : e->count.debug ();
4133 0 : count.debug ();
4134 0 : error_found = true;
4135 : }
4136 2389542 : if (!e->indirect_unknown_callee
4137 2389542 : || !e->indirect_info)
4138 : {
4139 0 : error ("An indirect edge from %s is not marked as indirect or has "
4140 : "associated indirect_info, the corresponding statement is: ",
4141 0 : identifier_to_locale (e->caller->name ()));
4142 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
4143 0 : error_found = true;
4144 : }
4145 2389542 : if (e->call_stmt && e->lto_stmt_uid)
4146 : {
4147 0 : error ("edge has both call_stmt and lto_stmt_uid set");
4148 0 : error_found = true;
4149 : }
4150 : }
4151 53680584 : bool check_comdat = comdat_local_p ();
4152 146162766 : for (e = callers; e; e = e->next_caller)
4153 : {
4154 92482182 : if (e->verify_count ())
4155 0 : error_found = true;
4156 92482182 : if (check_comdat
4157 92482182 : && !in_same_comdat_group_p (e->caller))
4158 : {
4159 0 : error ("comdat-local function called by %s outside its comdat",
4160 : identifier_to_locale (e->caller->name ()));
4161 0 : error_found = true;
4162 : }
4163 92482182 : if (!e->inline_failed)
4164 : {
4165 8553404 : if (inlined_to
4166 8553404 : != (e->caller->inlined_to
4167 8553404 : ? e->caller->inlined_to : e->caller))
4168 : {
4169 0 : error ("inlined_to pointer is wrong");
4170 0 : error_found = true;
4171 : }
4172 8553404 : if (callers->next_caller)
4173 : {
4174 0 : error ("multiple inline callers");
4175 0 : error_found = true;
4176 : }
4177 : }
4178 : else
4179 83928778 : if (inlined_to)
4180 : {
4181 0 : error ("inlined_to pointer set for noninline callers");
4182 0 : error_found = true;
4183 : }
4184 : }
4185 163958110 : for (e = callees; e; e = e->next_callee)
4186 : {
4187 110277526 : if (e->verify_count ())
4188 0 : error_found = true;
4189 110277526 : if (!e->count.compatible_p (count))
4190 : {
4191 0 : error ("edge count is not compatible with function count");
4192 0 : e->count.debug ();
4193 0 : count.debug ();
4194 0 : error_found = true;
4195 : }
4196 110277526 : if (gimple_has_body_p (e->caller->decl)
4197 103445480 : && !e->caller->inlined_to
4198 94233798 : && !e->speculative
4199 94176936 : && !e->callback
4200 94152880 : && !e->has_callback
4201 : /* Optimized out calls are redirected to __builtin_unreachable. */
4202 94059644 : && (e->count.nonzero_p ()
4203 54589725 : || ! e->callee->decl
4204 54589725 : || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
4205 : BUILT_IN_UNREACHABLE_TRAP))
4206 : && count
4207 92281394 : == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
4208 202550749 : && (!e->count.ipa_p ()
4209 41442162 : && e->count.differs_from_p (gimple_bb (e->call_stmt)->count)))
4210 : {
4211 0 : error ("caller edge count does not match BB count");
4212 0 : fprintf (stderr, "edge count: ");
4213 0 : e->count.dump (stderr);
4214 0 : fprintf (stderr, "\n bb count: ");
4215 0 : gimple_bb (e->call_stmt)->count.dump (stderr);
4216 0 : fprintf (stderr, "\n");
4217 0 : error_found = true;
4218 : }
4219 110277526 : if (e->call_stmt && e->lto_stmt_uid)
4220 : {
4221 0 : error ("edge has both call_stmt and lto_stmt_uid set");
4222 0 : error_found = true;
4223 : }
4224 110277526 : if (e->speculative
4225 110277526 : && verify_speculative_call (e->caller, e->call_stmt, e->lto_stmt_uid,
4226 : NULL))
4227 : error_found = true;
4228 110277526 : if (e->callback && e->has_callback)
4229 : {
4230 0 : error ("edge has both callback and has_callback set");
4231 0 : error_found = true;
4232 : }
4233 110277526 : if (e->callback)
4234 : {
4235 25669 : cgraph_edge *carrying = e->get_callback_carrying_edge ();
4236 25669 : if (!carrying && !e->callee->assume_function)
4237 : {
4238 0 : error ("callback edge %s->%s has no callback-carrying edge",
4239 0 : identifier_to_locale (e->caller->dump_name ()),
4240 : identifier_to_locale (e->callee->dump_name ()));
4241 0 : error_found = true;
4242 : }
4243 24344 : else if (carrying && e->callee->assume_function)
4244 : {
4245 0 : error ("internal callback edge %s->%s should not have a "
4246 : "callback-carrying edge",
4247 0 : identifier_to_locale (e->caller->dump_name ()),
4248 : identifier_to_locale (e->callee->dump_name ()));
4249 0 : error_found = true;
4250 : }
4251 : }
4252 110277526 : if (e->has_callback
4253 101564 : && !callback_is_special_cased (e->callee->decl, e->call_stmt)
4254 110368151 : && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
4255 : {
4256 90578 : int ncallbacks = 0;
4257 90578 : int nfound_edges = 0;
4258 90578 : for (tree cb = lookup_attribute ("callback_only",
4259 90578 : DECL_ATTRIBUTES (e->callee->decl));
4260 181169 : cb; cb = lookup_attribute ("callback_only", TREE_CHAIN (cb)),
4261 : ncallbacks++)
4262 : ;
4263 792431 : for (cgraph_edge *cbe = callees; cbe; cbe = cbe->next_callee)
4264 : {
4265 701853 : if (cbe->callback && cbe->call_stmt == e->call_stmt
4266 20948 : && cbe->lto_stmt_uid == e->lto_stmt_uid)
4267 : {
4268 20948 : nfound_edges++;
4269 : }
4270 : }
4271 90578 : if (ncallbacks < nfound_edges)
4272 : {
4273 0 : error ("callback edge %s->%s callback edge count mismatch, "
4274 : "expected at most %d, found %d",
4275 0 : identifier_to_locale (e->caller->name ()),
4276 0 : identifier_to_locale (e->callee->name ()), ncallbacks,
4277 : nfound_edges);
4278 0 : error_found = true;
4279 : }
4280 : }
4281 110277526 : if (e->has_callback
4282 110277526 : && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
4283 62 : for (cgraph_edge *cbe = e->first_callback_edge (); cbe;
4284 15 : cbe = cbe->next_callback_edge ())
4285 15 : if (!fndecl_built_in_p (cbe->callee->decl, BUILT_IN_UNREACHABLE))
4286 : {
4287 0 : error ("callback-carrying edge is pointing towards "
4288 : "__builtin_unreachable, but its callback edge %s -> %s "
4289 : "is not",
4290 0 : cbe->caller->name (), cbe->callee->name ());
4291 0 : error_found = true;
4292 : }
4293 : }
4294 56070126 : for (e = indirect_calls; e; e = e->next_callee)
4295 : {
4296 2389542 : if (e->verify_count ())
4297 0 : error_found = true;
4298 2389542 : if (gimple_has_body_p (e->caller->decl)
4299 2341531 : && !e->caller->inlined_to
4300 2096636 : && !e->speculative
4301 : && count
4302 2054610 : == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
4303 4444088 : && (!e->count.ipa_p ()
4304 1276794 : && e->count.differs_from_p (gimple_bb (e->call_stmt)->count)))
4305 : {
4306 0 : error ("indirect call count does not match BB count");
4307 0 : fprintf (stderr, "edge count: ");
4308 0 : e->count.dump (stderr);
4309 0 : fprintf (stderr, "\n bb count: ");
4310 0 : gimple_bb (e->call_stmt)->count.dump (stderr);
4311 0 : fprintf (stderr, "\n");
4312 0 : error_found = true;
4313 : }
4314 2389542 : if (e->speculative
4315 2389542 : && verify_speculative_call (e->caller, e->call_stmt, e->lto_stmt_uid,
4316 : e))
4317 : error_found = true;
4318 : }
4319 122131998 : for (i = 0; iterate_reference (i, ref); i++)
4320 : {
4321 68451414 : if (ref->stmt && ref->lto_stmt_uid)
4322 : {
4323 0 : error ("reference has both stmt and lto_stmt_uid set");
4324 0 : error_found = true;
4325 : }
4326 68451414 : if (ref->speculative
4327 68451414 : && verify_speculative_call (this, ref->stmt,
4328 : ref->lto_stmt_uid, NULL))
4329 : error_found = true;
4330 : }
4331 :
4332 53680584 : if (!callers && inlined_to)
4333 : {
4334 0 : error ("inlined_to pointer is set but no predecessors found");
4335 0 : error_found = true;
4336 : }
4337 53680584 : if (inlined_to == this)
4338 : {
4339 0 : error ("inlined_to pointer refers to itself");
4340 0 : error_found = true;
4341 : }
4342 :
4343 53680584 : if (clone_of)
4344 : {
4345 6268519 : cgraph_node *first_clone = clone_of->clones;
4346 6268519 : if (first_clone != this)
4347 : {
4348 3142119 : if (prev_sibling_clone->clone_of != clone_of)
4349 : {
4350 0 : error ("cgraph_node has wrong clone_of");
4351 0 : error_found = true;
4352 : }
4353 : }
4354 : }
4355 53680584 : if (clones)
4356 : {
4357 : cgraph_node *n;
4358 8352086 : for (n = clones; n; n = n->next_sibling_clone)
4359 6637739 : if (n->clone_of != this)
4360 : break;
4361 1714347 : if (n)
4362 : {
4363 0 : error ("cgraph_node has wrong clone list");
4364 0 : error_found = true;
4365 : }
4366 : }
4367 53680584 : if ((prev_sibling_clone || next_sibling_clone) && !clone_of)
4368 : {
4369 0 : error ("cgraph_node is in clone list but it is not clone");
4370 0 : error_found = true;
4371 : }
4372 53680584 : if (!prev_sibling_clone && clone_of && clone_of->clones != this)
4373 : {
4374 0 : error ("cgraph_node has wrong prev_clone pointer");
4375 0 : error_found = true;
4376 : }
4377 53680584 : if (prev_sibling_clone && prev_sibling_clone->next_sibling_clone != this)
4378 : {
4379 0 : error ("double linked list of clones corrupted");
4380 0 : error_found = true;
4381 : }
4382 :
4383 53680584 : if (analyzed && alias)
4384 : {
4385 1444062 : bool ref_found = false;
4386 1444062 : int i;
4387 1444062 : ipa_ref *ref = NULL;
4388 :
4389 1444062 : if (callees)
4390 : {
4391 0 : error ("Alias has call edges");
4392 0 : error_found = true;
4393 : }
4394 2888124 : for (i = 0; iterate_reference (i, ref); i++)
4395 1444062 : if (ref->use != IPA_REF_ALIAS)
4396 : {
4397 0 : error ("Alias has non-alias reference");
4398 0 : error_found = true;
4399 : }
4400 1444062 : else if (ref_found)
4401 : {
4402 0 : error ("Alias has more than one alias reference");
4403 0 : error_found = true;
4404 : }
4405 : else
4406 : ref_found = true;
4407 1444062 : if (!ref_found)
4408 : {
4409 0 : error ("Analyzed alias has no reference");
4410 0 : error_found = true;
4411 : }
4412 : }
4413 :
4414 53680584 : if (analyzed && thunk)
4415 : {
4416 23304 : if (!callees)
4417 : {
4418 0 : error ("No edge out of thunk node");
4419 0 : error_found = true;
4420 : }
4421 23304 : else if (callees->next_callee)
4422 : {
4423 0 : error ("More than one edge out of thunk node");
4424 0 : error_found = true;
4425 : }
4426 23304 : if (gimple_has_body_p (decl) && !inlined_to)
4427 : {
4428 0 : error ("Thunk is not supposed to have body");
4429 0 : error_found = true;
4430 : }
4431 : }
4432 36303829 : else if (analyzed && gimple_has_body_p (decl)
4433 31296659 : && !TREE_ASM_WRITTEN (decl)
4434 31296659 : && (!DECL_EXTERNAL (decl) || inlined_to)
4435 83936542 : && !flag_wpa)
4436 : {
4437 30252599 : if ((this_cfun->curr_properties & PROP_assumptions_done) != 0)
4438 : ;
4439 30252423 : else if (this_cfun->cfg)
4440 : {
4441 30252423 : hash_set<gimple *> stmts;
4442 :
4443 : /* Reach the trees by walking over the CFG, and note the
4444 : enclosing basic-blocks in the call edges. */
4445 251768389 : FOR_EACH_BB_FN (this_block, this_cfun)
4446 : {
4447 221515966 : for (gsi = gsi_start_phis (this_block);
4448 267272841 : !gsi_end_p (gsi); gsi_next (&gsi))
4449 45756875 : stmts.add (gsi_stmt (gsi));
4450 443031932 : for (gsi = gsi_start_bb (this_block);
4451 1362902071 : !gsi_end_p (gsi);
4452 1141386105 : gsi_next (&gsi))
4453 : {
4454 1141386105 : gimple *stmt = gsi_stmt (gsi);
4455 1141386105 : stmts.add (stmt);
4456 1141386105 : if (is_gimple_call (stmt))
4457 : {
4458 108173479 : cgraph_edge *e = get_edge (stmt);
4459 108173479 : tree decl = gimple_call_fndecl (stmt);
4460 108173479 : if (e)
4461 : {
4462 103312454 : if (e->aux)
4463 : {
4464 0 : error ("shared call_stmt:");
4465 0 : cgraph_debug_gimple_stmt (this_cfun, stmt);
4466 0 : error_found = true;
4467 : }
4468 103312454 : if (!e->indirect_unknown_callee)
4469 : {
4470 : /* Callback edges violate this assertion
4471 : because their call statement doesn't exist,
4472 : their associated statement belongs to the
4473 : callback-dispatching function. */
4474 101102071 : if (!e->callback
4475 101102071 : && e->verify_corresponds_to_fndecl (decl))
4476 : {
4477 0 : error ("edge points to wrong declaration:");
4478 0 : debug_tree (e->callee->decl);
4479 0 : fprintf (stderr," Instead of:");
4480 0 : debug_tree (decl);
4481 0 : error_found = true;
4482 : }
4483 : }
4484 2210383 : else if (decl)
4485 : {
4486 0 : error ("an indirect edge with unknown callee "
4487 : "corresponding to a call_stmt with "
4488 : "a known declaration:");
4489 0 : error_found = true;
4490 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
4491 : }
4492 103312454 : e->aux = (void *)1;
4493 : }
4494 4861025 : else if (decl)
4495 : {
4496 0 : error ("missing callgraph edge for call stmt:");
4497 0 : cgraph_debug_gimple_stmt (this_cfun, stmt);
4498 0 : error_found = true;
4499 : }
4500 : }
4501 : }
4502 : }
4503 102884640 : for (i = 0; iterate_reference (i, ref); i++)
4504 63453953 : if (ref->stmt && !stmts.contains (ref->stmt))
4505 : {
4506 0 : error ("reference to dead statement");
4507 0 : cgraph_debug_gimple_stmt (this_cfun, ref->stmt);
4508 0 : error_found = true;
4509 : }
4510 30252423 : }
4511 : else
4512 : /* No CFG available?! */
4513 0 : gcc_unreachable ();
4514 :
4515 131419367 : for (e = callees; e; e = e->next_callee)
4516 : {
4517 101166768 : if (!e->aux && !e->speculative && !e->callback && !e->has_callback)
4518 : {
4519 0 : error ("edge %s->%s has no corresponding call_stmt",
4520 0 : identifier_to_locale (e->caller->name ()),
4521 0 : identifier_to_locale (e->callee->name ()));
4522 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
4523 0 : error_found = true;
4524 : }
4525 101166768 : e->aux = 0;
4526 : }
4527 32571806 : for (e = indirect_calls; e; e = e->next_callee)
4528 : {
4529 2319207 : if (!e->aux && !e->speculative)
4530 : {
4531 0 : error ("an indirect edge from %s has no corresponding call_stmt",
4532 0 : identifier_to_locale (e->caller->name ()));
4533 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
4534 0 : error_found = true;
4535 : }
4536 2319207 : e->aux = 0;
4537 : }
4538 : }
4539 :
4540 53680584 : if (nested_function_info *info = nested_function_info::get (this))
4541 : {
4542 0 : if (info->nested != NULL)
4543 : {
4544 0 : for (cgraph_node *n = info->nested; n != NULL;
4545 0 : n = next_nested_function (n))
4546 : {
4547 0 : nested_function_info *ninfo = nested_function_info::get (n);
4548 0 : if (ninfo->origin == NULL)
4549 : {
4550 0 : error ("missing origin for a node in a nested list");
4551 0 : error_found = true;
4552 : }
4553 0 : else if (ninfo->origin != this)
4554 : {
4555 0 : error ("origin points to a different parent");
4556 0 : error_found = true;
4557 0 : break;
4558 : }
4559 : }
4560 : }
4561 0 : if (info->next_nested != NULL && info->origin == NULL)
4562 : {
4563 0 : error ("missing origin for a node in a nested list");
4564 0 : error_found = true;
4565 : }
4566 : }
4567 :
4568 53680584 : if (error_found)
4569 : {
4570 0 : dump (stderr);
4571 0 : internal_error ("verify_cgraph_node failed");
4572 : }
4573 53680584 : timevar_pop (TV_CGRAPH_VERIFY);
4574 : }
4575 :
4576 : /* Verify whole cgraph structure. */
4577 : DEBUG_FUNCTION void
4578 886 : cgraph_node::verify_cgraph_nodes (void)
4579 : {
4580 886 : cgraph_node *node;
4581 :
4582 886 : if (seen_error ())
4583 : return;
4584 :
4585 5266 : FOR_EACH_FUNCTION (node)
4586 4404 : node->verify ();
4587 : }
4588 :
4589 : #if __GNUC__ >= 10
4590 : # pragma GCC diagnostic pop
4591 : #endif
4592 :
4593 : /* Walk the alias chain to return the function cgraph_node is alias of.
4594 : Walk through thunks, too.
4595 : When AVAILABILITY is non-NULL, get minimal availability in the chain.
4596 : When REF is non-NULL, assume that reference happens in symbol REF
4597 : when determining the availability. */
4598 :
4599 : cgraph_node *
4600 138878309 : cgraph_node::function_symbol (enum availability *availability,
4601 : struct symtab_node *ref)
4602 : {
4603 138878309 : cgraph_node *node = ultimate_alias_target (availability, ref);
4604 :
4605 277762252 : while (node->thunk)
4606 : {
4607 5634 : enum availability a;
4608 :
4609 5634 : ref = node;
4610 5634 : node = node->callees->callee;
4611 9819 : node = node->ultimate_alias_target (availability ? &a : NULL, ref);
4612 5634 : if (availability && a < *availability)
4613 38 : *availability = a;
4614 : }
4615 138878309 : return node;
4616 : }
4617 :
4618 : /* Walk the alias chain to return the function cgraph_node is alias of.
4619 : Walk through non virtual thunks, too. Thus we return either a function
4620 : or a virtual thunk node.
4621 : When AVAILABILITY is non-NULL, get minimal availability in the chain.
4622 : When REF is non-NULL, assume that reference happens in symbol REF
4623 : when determining the availability. */
4624 :
4625 : cgraph_node *
4626 34896670 : cgraph_node::function_or_virtual_thunk_symbol
4627 : (enum availability *availability,
4628 : struct symtab_node *ref)
4629 : {
4630 34896670 : cgraph_node *node = ultimate_alias_target (availability, ref);
4631 :
4632 69794394 : while (node->thunk && !thunk_info::get (node)->virtual_offset_p)
4633 : {
4634 1054 : enum availability a;
4635 :
4636 1054 : ref = node;
4637 1054 : node = node->callees->callee;
4638 1054 : node = node->ultimate_alias_target (availability ? &a : NULL, ref);
4639 1054 : if (availability && a < *availability)
4640 305 : *availability = a;
4641 : }
4642 34896670 : return node;
4643 : }
4644 :
4645 : /* When doing LTO, read cgraph_node's body from disk if it is not already
4646 : present. Also perform any necessary clone materializations. */
4647 :
4648 : bool
4649 6494185 : cgraph_node::get_untransformed_body ()
4650 : {
4651 6494185 : lto_file_decl_data *file_data;
4652 6494185 : const char *data, *name;
4653 6494185 : size_t len;
4654 6494185 : tree decl = this->decl;
4655 :
4656 : /* See if there is clone to be materialized.
4657 : (inline clones does not need materialization, but we can be seeing
4658 : an inline clone of real clone). */
4659 6494185 : cgraph_node *p = this;
4660 9376758 : for (cgraph_node *c = clone_of; c; c = c->clone_of)
4661 : {
4662 2882573 : if (c->decl != decl)
4663 142131 : p->materialize_clone ();
4664 2882573 : p = c;
4665 : }
4666 :
4667 : /* Check if body is already there. Either we have gimple body or
4668 : the function is thunk and in that case we set DECL_ARGUMENTS. */
4669 6494185 : if (DECL_ARGUMENTS (decl) || gimple_has_body_p (decl))
4670 : return false;
4671 :
4672 173870 : gcc_assert (in_lto_p && !DECL_RESULT (decl));
4673 :
4674 86935 : timevar_push (TV_IPA_LTO_GIMPLE_IN);
4675 :
4676 86935 : file_data = lto_file_data;
4677 86935 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4678 :
4679 : /* We may have renamed the declaration, e.g., a static function. */
4680 86935 : name = lto_get_decl_name_mapping (file_data, name);
4681 86935 : struct lto_in_decl_state *decl_state
4682 86935 : = lto_get_function_in_decl_state (file_data, decl);
4683 :
4684 86935 : cgraph_node *origin = this;
4685 174094 : while (origin->clone_of)
4686 : origin = origin->clone_of;
4687 :
4688 86935 : int stream_order = origin->order - file_data->order_base;
4689 86935 : data = lto_get_section_data (file_data, LTO_section_function_body,
4690 : name, stream_order, &len,
4691 : decl_state->compressed);
4692 86935 : if (!data)
4693 0 : fatal_error (input_location, "%s: section %s.%d is missing",
4694 : file_data->file_name, name, stream_order);
4695 :
4696 86935 : gcc_assert (DECL_STRUCT_FUNCTION (decl) == NULL);
4697 :
4698 86935 : if (!quiet_flag)
4699 0 : fprintf (stderr, " in:%s", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4700 86935 : lto_input_function_body (file_data, this, data);
4701 86935 : lto_stats.num_function_bodies++;
4702 86935 : lto_free_section_data (file_data, LTO_section_function_body, name,
4703 : data, len, decl_state->compressed);
4704 86935 : lto_free_function_in_decl_state_for_node (this);
4705 : /* Keep lto file data so ipa-inline-analysis knows about cross module
4706 : inlining. */
4707 :
4708 86935 : timevar_pop (TV_IPA_LTO_GIMPLE_IN);
4709 :
4710 86935 : return true;
4711 : }
4712 :
4713 : /* Prepare function body. When doing LTO, read cgraph_node's body from disk
4714 : if it is not already present. When some IPA transformations are scheduled,
4715 : apply them. */
4716 :
4717 : bool
4718 29107 : cgraph_node::get_body (void)
4719 : {
4720 29107 : bool updated;
4721 :
4722 29107 : updated = get_untransformed_body ();
4723 :
4724 : /* Getting transformed body makes no sense for inline clones;
4725 : we should never use this on real clones because they are materialized
4726 : early.
4727 : TODO: Materializing clones here will likely lead to smaller LTRANS
4728 : footprint. */
4729 29107 : gcc_assert (!inlined_to && !clone_of);
4730 29107 : if (ipa_transforms_to_apply.exists ())
4731 : {
4732 12473 : opt_pass *saved_current_pass = current_pass;
4733 12473 : FILE *saved_dump_file = dump_file;
4734 12473 : const char *saved_dump_file_name = dump_file_name;
4735 12473 : dump_flags_t saved_dump_flags = dump_flags;
4736 12473 : dump_file_name = NULL;
4737 12473 : set_dump_file (NULL);
4738 :
4739 12473 : push_cfun (DECL_STRUCT_FUNCTION (decl));
4740 :
4741 12473 : update_ssa (TODO_update_ssa_only_virtuals);
4742 12473 : execute_all_ipa_transforms (true);
4743 12473 : cgraph_edge::rebuild_edges ();
4744 12473 : free_dominance_info (CDI_DOMINATORS);
4745 12473 : free_dominance_info (CDI_POST_DOMINATORS);
4746 12473 : pop_cfun ();
4747 12473 : updated = true;
4748 :
4749 12473 : current_pass = saved_current_pass;
4750 12473 : set_dump_file (saved_dump_file);
4751 12473 : dump_file_name = saved_dump_file_name;
4752 12473 : dump_flags = saved_dump_flags;
4753 : }
4754 29107 : return updated;
4755 : }
4756 :
4757 : /* Return the DECL_STRUCT_FUNCTION of the function. */
4758 :
4759 : struct function *
4760 112757 : cgraph_node::get_fun () const
4761 : {
4762 112757 : const cgraph_node *node = this;
4763 112757 : struct function *fun = DECL_STRUCT_FUNCTION (node->decl);
4764 :
4765 112757 : while (!fun && node->clone_of)
4766 : {
4767 0 : node = node->clone_of;
4768 0 : fun = DECL_STRUCT_FUNCTION (node->decl);
4769 : }
4770 :
4771 112757 : return fun;
4772 : }
4773 :
4774 : /* Reset all state within cgraph.cc so that we can rerun the compiler
4775 : within the same process. For use by toplev::finalize. */
4776 :
4777 : void
4778 272484 : cgraph_cc_finalize (void)
4779 : {
4780 272484 : nested_function_info::release ();
4781 272484 : thunk_info::release ();
4782 272484 : clone_info::release ();
4783 272484 : callback_info_sum_t::free_info_sum ();
4784 272484 : symtab = NULL;
4785 :
4786 272484 : cgraph_fnver_htab = NULL;
4787 272484 : version_info_node = NULL;
4788 272484 : }
4789 :
4790 : /* A worker for call_for_symbol_and_aliases. */
4791 :
4792 : bool
4793 750674 : cgraph_node::call_for_symbol_and_aliases_1 (bool (*callback) (cgraph_node *,
4794 : void *),
4795 : void *data,
4796 : bool include_overwritable)
4797 : {
4798 750674 : ipa_ref *ref;
4799 1581763 : FOR_EACH_ALIAS (this, ref)
4800 : {
4801 942241 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
4802 942241 : if (include_overwritable
4803 942241 : || alias->get_availability () > AVAIL_INTERPOSABLE)
4804 942241 : if (alias->call_for_symbol_and_aliases (callback, data,
4805 : include_overwritable))
4806 : return true;
4807 : }
4808 : return false;
4809 : }
4810 :
4811 : /* Return true if NODE has thunk. */
4812 :
4813 : bool
4814 36598 : cgraph_node::has_thunk_p (cgraph_node *node, void *)
4815 : {
4816 71074 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
4817 34476 : if (e->caller->thunk)
4818 : return true;
4819 : return false;
4820 : }
4821 :
4822 : /* Expected frequency of executions within the function. */
4823 :
4824 : sreal
4825 212278217 : cgraph_edge::sreal_frequency ()
4826 : {
4827 212278217 : return count.to_sreal_scale (caller->inlined_to
4828 212278217 : ? caller->inlined_to->count
4829 212278217 : : caller->count);
4830 : }
4831 :
4832 : /* Expected frequency of executions within the function.
4833 : If edge is speculative, sum all its indirect targets. */
4834 :
4835 : sreal
4836 4698 : cgraph_edge::combined_sreal_frequency ()
4837 : {
4838 4698 : if (!speculative)
4839 4401 : return sreal_frequency ();
4840 297 : cgraph_edge *e = this;
4841 297 : if (e->callee)
4842 0 : e = e->speculative_call_indirect_edge ();
4843 297 : sreal sum = e->sreal_frequency ();
4844 297 : for (e = e->first_speculative_call_target ();
4845 644 : e;
4846 347 : e = e->next_speculative_call_target ())
4847 347 : sum += e->sreal_frequency ();
4848 297 : return sum;
4849 : }
4850 :
4851 :
4852 : /* During LTO stream in this can be used to check whether call can possibly
4853 : be internal to the current translation unit. */
4854 :
4855 : bool
4856 486106 : cgraph_edge::possibly_call_in_translation_unit_p (void)
4857 : {
4858 486106 : gcc_checking_assert (in_lto_p && caller->prevailing_p ());
4859 :
4860 : /* While incremental linking we may end up getting function body later. */
4861 486106 : if (flag_incremental_link == INCREMENTAL_LINK_LTO)
4862 : return true;
4863 :
4864 : /* We may be smarter here and avoid streaming in indirect calls we can't
4865 : track, but that would require arranging streaming the indirect call
4866 : summary first. */
4867 485839 : if (!callee)
4868 : return true;
4869 :
4870 : /* If callee is local to the original translation unit, it will be
4871 : defined. */
4872 483046 : if (!TREE_PUBLIC (callee->decl) && !DECL_EXTERNAL (callee->decl))
4873 : return true;
4874 :
4875 : /* Otherwise we need to lookup prevailing symbol (symbol table is not merged,
4876 : yet) and see if it is a definition. In fact we may also resolve aliases,
4877 : but that is probably not too important. */
4878 485870 : symtab_node *node = callee;
4879 485870 : for (int n = 10; node->previous_sharing_asm_name && n ; n--)
4880 10255 : node = node->previous_sharing_asm_name;
4881 475615 : if (node->previous_sharing_asm_name)
4882 234 : node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (callee->decl));
4883 475615 : gcc_assert (TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl));
4884 475615 : return node->get_availability () >= AVAIL_INTERPOSABLE;
4885 : }
4886 :
4887 : /* Return num_speculative_targets of this edge. */
4888 :
4889 : int
4890 190119 : cgraph_edge::num_speculative_call_targets_p (void)
4891 : {
4892 190119 : return indirect_info ? indirect_info->num_speculative_call_targets : 0;
4893 : }
4894 :
4895 : /* Check if function calls comdat local. This is used to recompute
4896 : calls_comdat_local flag after function transformations. */
4897 : bool
4898 50308653 : cgraph_node::check_calls_comdat_local_p ()
4899 : {
4900 163398706 : for (cgraph_edge *e = callees; e; e = e->next_callee)
4901 116962820 : if (e->inline_failed
4902 122075885 : ? e->callee->comdat_local_p ()
4903 3816642 : : e->callee->check_calls_comdat_local_p ())
4904 : return true;
4905 : return false;
4906 : }
4907 :
4908 : /* Return true if this node represents a former, i.e. an expanded, thunk. */
4909 :
4910 : bool
4911 5172928 : cgraph_node::former_thunk_p (void)
4912 : {
4913 5172928 : if (thunk)
4914 : return false;
4915 5172928 : thunk_info *i = thunk_info::get (this);
4916 5172928 : if (!i)
4917 : return false;
4918 25 : gcc_checking_assert (i->fixed_offset || i->virtual_offset_p
4919 : || i->indirect_offset);
4920 : return true;
4921 : }
4922 :
4923 : /* A stashed copy of "symtab" for use by selftest::symbol_table_test.
4924 : This needs to be a global so that it can be a GC root, and thus
4925 : prevent the stashed copy from being garbage-collected if the GC runs
4926 : during a symbol_table_test. */
4927 :
4928 : symbol_table *saved_symtab;
4929 :
4930 : #if CHECKING_P
4931 :
4932 : namespace selftest {
4933 :
4934 : /* class selftest::symbol_table_test. */
4935 :
4936 : /* Constructor. Store the old value of symtab, and create a new one. */
4937 :
4938 64 : symbol_table_test::symbol_table_test ()
4939 : {
4940 64 : gcc_assert (saved_symtab == NULL);
4941 64 : saved_symtab = symtab;
4942 64 : symtab = new (ggc_alloc<symbol_table> ()) symbol_table ();
4943 64 : }
4944 :
4945 : /* Destructor. Restore the old value of symtab. */
4946 :
4947 64 : symbol_table_test::~symbol_table_test ()
4948 : {
4949 64 : gcc_assert (saved_symtab != NULL);
4950 64 : symtab = saved_symtab;
4951 64 : saved_symtab = NULL;
4952 64 : }
4953 :
4954 : /* Verify that symbol_table_test works. */
4955 :
4956 : static void
4957 4 : test_symbol_table_test ()
4958 : {
4959 : /* Simulate running two selftests involving symbol tables. */
4960 12 : for (int i = 0; i < 2; i++)
4961 : {
4962 8 : symbol_table_test stt;
4963 8 : tree test_decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
4964 : get_identifier ("test_decl"),
4965 : build_function_type_list (void_type_node,
4966 : NULL_TREE));
4967 8 : cgraph_node *node = cgraph_node::get_create (test_decl);
4968 8 : gcc_assert (node);
4969 :
4970 : /* Verify that the node has order 0 on both iterations,
4971 : and thus that nodes have predictable dump names in selftests. */
4972 8 : ASSERT_EQ (node->order, 0);
4973 8 : ASSERT_STREQ (node->dump_name (), "test_decl/1");
4974 8 : }
4975 4 : }
4976 :
4977 : /* Run all of the selftests within this file. */
4978 :
4979 : void
4980 4 : cgraph_cc_tests ()
4981 : {
4982 4 : test_symbol_table_test ();
4983 4 : }
4984 :
4985 : } // namespace selftest
4986 :
4987 : #endif /* CHECKING_P */
4988 :
4989 : #include "gt-cgraph.h"
|