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 315426 : function_version_hasher::hash (cgraph_function_version_info *ptr)
127 : {
128 315426 : int uid = ptr->this_node->get_uid ();
129 315426 : return (hashval_t)(uid);
130 : }
131 :
132 : /* eq function for cgraph_fnver_htab. */
133 : bool
134 286509 : function_version_hasher::equal (cgraph_function_version_info *n1,
135 : cgraph_function_version_info *n2)
136 : {
137 286509 : 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 5102637 : symtab_node::address_can_be_compared_p ()
148 : {
149 : /* Address of virtual tables and functions is never compared. */
150 5102637 : if (DECL_VIRTUAL_P (decl))
151 : return false;
152 : /* Address of C++ cdtors is never compared. */
153 5001734 : if (is_a <cgraph_node *> (this)
154 559914 : && (DECL_CXX_CONSTRUCTOR_P (decl)
155 555541 : || 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 4995918 : if (is_a <varpool_node *> (this)
160 4441820 : && (DECL_IN_CONSTANT_POOL (decl)
161 4441817 : || ((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 141216095 : cgraph_node::function_version (void)
170 : {
171 141216095 : cgraph_function_version_info key;
172 141216095 : key.this_node = this;
173 :
174 141216095 : if (cgraph_fnver_htab == NULL)
175 : return NULL;
176 :
177 50563 : 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 1685730 : cgraph_node::apply_scale (profile_count num, profile_count den)
263 : {
264 1818154 : if (num == den && !(num == profile_count::zero ()))
265 130505 : return;
266 :
267 2949338 : for (cgraph_edge *e = callees; e; e = e->next_callee)
268 : {
269 1394113 : if (!e->inline_failed)
270 183437 : e->callee->apply_scale (num, den);
271 1394113 : e->count = e->count.apply_scale (num, den);
272 : }
273 1582456 : for (cgraph_edge *e = indirect_calls; e; e = e->next_callee)
274 27231 : e->count = e->count.apply_scale (num, den);
275 1555225 : 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 1565 : cgraph_node::insert_new_function_version (void)
320 : {
321 1565 : version_info_node = NULL;
322 1565 : version_info_node = ggc_cleared_alloc<cgraph_function_version_info> ();
323 1565 : version_info_node->this_node = this;
324 1565 : version_info_node->assembler_name = DECL_ASSEMBLER_NAME (this->decl);
325 :
326 1565 : if (cgraph_fnver_htab == NULL)
327 204 : cgraph_fnver_htab = hash_table<function_version_hasher>::create_ggc (2);
328 :
329 1565 : *cgraph_fnver_htab->find_slot (version_info_node, INSERT)
330 1565 : = version_info_node;
331 1565 : return version_info_node;
332 : }
333 :
334 : /* Remove the cgraph_function_version_info node given by DECL_V. */
335 : void
336 109062536 : cgraph_node::delete_function_version (cgraph_function_version_info *decl_v)
337 : {
338 109062536 : if (decl_v == NULL)
339 : return;
340 :
341 266 : if (version_info_node == decl_v)
342 205 : version_info_node = NULL;
343 :
344 266 : if (decl_v->prev != NULL)
345 159 : decl_v->prev->next = decl_v->next;
346 :
347 266 : if (decl_v->next != NULL)
348 227 : decl_v->next->prev = decl_v->prev;
349 :
350 266 : if (cgraph_fnver_htab != NULL)
351 266 : 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 8983 : cgraph_node::add_function_version (cgraph_function_version_info *fn_v,
374 : tree decl)
375 : {
376 8983 : cgraph_node *decl_node = cgraph_node::get_create (decl);
377 8983 : cgraph_function_version_info *decl_v = NULL;
378 :
379 8983 : gcc_assert (decl_node != NULL);
380 :
381 8983 : decl_v = decl_node->function_version ();
382 :
383 : /* If the nodes are already linked, skip. */
384 8983 : if (decl_v != NULL && (decl_v->next || decl_v->prev))
385 : return;
386 :
387 184 : if (decl_v == NULL)
388 184 : decl_v = decl_node->insert_new_function_version ();
389 :
390 184 : gcc_assert (decl_v);
391 1081 : gcc_assert (fn_v);
392 :
393 : /* Go to start of the FMV structure. */
394 5584 : while (fn_v->prev)
395 : fn_v = fn_v->prev;
396 :
397 1081 : cgraph_function_version_info *insert_point_before = NULL;
398 1081 : 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 1081 : if (!is_function_default_version (decl))
403 : while (insert_point_after
404 10178 : && (targetm.compare_version_priority
405 4889 : (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 4307 : insert_point_before = insert_point_after;
413 4307 : insert_point_after = insert_point_after->next;
414 : }
415 :
416 1081 : decl_v->prev = insert_point_before;
417 1081 : decl_v->next= insert_point_after;
418 :
419 1081 : if (insert_point_before)
420 946 : insert_point_before->next = decl_v;
421 1081 : if (insert_point_after)
422 681 : insert_point_after->prev = decl_v;
423 : }
424 :
425 : /* Initialize callgraph dump file. */
426 :
427 : void
428 310958 : symbol_table::initialize (void)
429 : {
430 310958 : if (!dump_file)
431 310956 : dump_file = dump_begin (TDI_cgraph, NULL);
432 :
433 310958 : if (!ipa_clones_dump_file)
434 310958 : ipa_clones_dump_file = dump_begin (TDI_clones, NULL);
435 310958 : }
436 :
437 : /* Allocate new callgraph node and insert it into basic data structures. */
438 :
439 : cgraph_node *
440 112897143 : symbol_table::create_empty (void)
441 : {
442 112897143 : cgraph_count++;
443 112897143 : 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 2226837 : symbol_table::add_edge_removal_hook (cgraph_edge_hook hook, void *data)
449 : {
450 2226837 : cgraph_edge_hook_list *entry;
451 4453674 : cgraph_edge_hook_list **ptr = &m_first_edge_removal_hook;
452 :
453 2226837 : entry = (cgraph_edge_hook_list *) xmalloc (sizeof (*entry));
454 2226837 : entry->hook = hook;
455 2226837 : entry->data = data;
456 2226837 : entry->next = NULL;
457 8818907 : while (*ptr)
458 6592070 : ptr = &(*ptr)->next;
459 2226837 : *ptr = entry;
460 2226837 : return entry;
461 : }
462 :
463 : /* Remove ENTRY from the list of hooks called on removing edges. */
464 : void
465 2226422 : symbol_table::remove_edge_removal_hook (cgraph_edge_hook_list *entry)
466 : {
467 2226422 : cgraph_edge_hook_list **ptr = &m_first_edge_removal_hook;
468 :
469 6871376 : while (*ptr != entry)
470 4644954 : ptr = &(*ptr)->next;
471 2226422 : *ptr = entry->next;
472 2226422 : free (entry);
473 2226422 : }
474 :
475 : /* Call all edge removal hooks. */
476 : void
477 46629595 : symbol_table::call_edge_removal_hooks (cgraph_edge *e)
478 : {
479 46629595 : cgraph_edge_hook_list *entry = m_first_edge_removal_hook;
480 90776647 : while (entry)
481 : {
482 44147052 : entry->hook (e, entry->data);
483 44147052 : entry = entry->next;
484 : }
485 46629595 : }
486 :
487 : /* Register HOOK to be called with DATA on each removed node. */
488 : cgraph_node_hook_list *
489 8279561 : symbol_table::add_cgraph_removal_hook (cgraph_node_hook hook, void *data)
490 : {
491 8279561 : cgraph_node_hook_list *entry;
492 16559122 : cgraph_node_hook_list **ptr = &m_first_cgraph_removal_hook;
493 :
494 8279561 : entry = (cgraph_node_hook_list *) xmalloc (sizeof (*entry));
495 8279561 : entry->hook = hook;
496 8279561 : entry->data = data;
497 8279561 : entry->next = NULL;
498 43142569 : while (*ptr)
499 34863008 : ptr = &(*ptr)->next;
500 8279561 : *ptr = entry;
501 8279561 : return entry;
502 : }
503 :
504 : /* Remove ENTRY from the list of hooks called on removing nodes. */
505 : void
506 8165906 : symbol_table::remove_cgraph_removal_hook (cgraph_node_hook_list *entry)
507 : {
508 8165906 : cgraph_node_hook_list **ptr = &m_first_cgraph_removal_hook;
509 :
510 38466520 : while (*ptr != entry)
511 30300614 : ptr = &(*ptr)->next;
512 8165906 : *ptr = entry->next;
513 8165906 : free (entry);
514 8165906 : }
515 :
516 : /* Call all node removal hooks. */
517 : void
518 109096137 : symbol_table::call_cgraph_removal_hooks (cgraph_node *node)
519 : {
520 109096137 : cgraph_node_hook_list *entry = m_first_cgraph_removal_hook;
521 153205768 : while (entry)
522 : {
523 44109631 : entry->hook (node, entry->data);
524 44109631 : entry = entry->next;
525 : }
526 109096137 : }
527 :
528 : /* Call all node removal hooks. */
529 : void
530 124363 : symbol_table::call_cgraph_insertion_hooks (cgraph_node *node)
531 : {
532 124363 : cgraph_node_hook_list *entry = m_first_cgraph_insertion_hook;
533 375575 : while (entry)
534 : {
535 251212 : entry->hook (node, entry->data);
536 251212 : entry = entry->next;
537 : }
538 124363 : }
539 :
540 :
541 : /* Register HOOK to be called with DATA on each inserted node. */
542 : cgraph_node_hook_list *
543 8779153 : symbol_table::add_cgraph_insertion_hook (cgraph_node_hook hook, void *data)
544 : {
545 8779153 : cgraph_node_hook_list *entry;
546 17558306 : cgraph_node_hook_list **ptr = &m_first_cgraph_insertion_hook;
547 :
548 8779153 : entry = (cgraph_node_hook_list *) xmalloc (sizeof (*entry));
549 8779153 : entry->hook = hook;
550 8779153 : entry->data = data;
551 8779153 : entry->next = NULL;
552 26010600 : while (*ptr)
553 17231447 : ptr = &(*ptr)->next;
554 8779153 : *ptr = entry;
555 8779153 : return entry;
556 : }
557 :
558 : /* Remove ENTRY from the list of hooks called on inserted nodes. */
559 : void
560 8627181 : symbol_table::remove_cgraph_insertion_hook (cgraph_node_hook_list *entry)
561 : {
562 8627181 : cgraph_node_hook_list **ptr = &m_first_cgraph_insertion_hook;
563 :
564 23804721 : while (*ptr != entry)
565 15177540 : ptr = &(*ptr)->next;
566 8627181 : *ptr = entry->next;
567 8627181 : free (entry);
568 8627181 : }
569 :
570 : /* Register HOOK to be called with DATA on each duplicated edge. */
571 : cgraph_2edge_hook_list *
572 1987483 : symbol_table::add_edge_duplication_hook (cgraph_2edge_hook hook, void *data)
573 : {
574 1987483 : cgraph_2edge_hook_list *entry;
575 3974966 : cgraph_2edge_hook_list **ptr = &m_first_edge_duplicated_hook;
576 :
577 1987483 : entry = (cgraph_2edge_hook_list *) xmalloc (sizeof (*entry));
578 1987483 : entry->hook = hook;
579 1987483 : entry->data = data;
580 1987483 : entry->next = NULL;
581 7320959 : while (*ptr)
582 5333476 : ptr = &(*ptr)->next;
583 1987483 : *ptr = entry;
584 1987483 : return entry;
585 : }
586 :
587 : /* Remove ENTRY from the list of hooks called on duplicating edges. */
588 : void
589 1987068 : symbol_table::remove_edge_duplication_hook (cgraph_2edge_hook_list *entry)
590 : {
591 1987068 : cgraph_2edge_hook_list **ptr = &m_first_edge_duplicated_hook;
592 :
593 5373428 : while (*ptr != entry)
594 3386360 : ptr = &(*ptr)->next;
595 1987068 : *ptr = entry->next;
596 1987068 : free (entry);
597 1987068 : }
598 :
599 : /* Call all edge duplication hooks. */
600 : void
601 7870998 : symbol_table::call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2)
602 : {
603 7870998 : cgraph_2edge_hook_list *entry = m_first_edge_duplicated_hook;
604 29552010 : while (entry)
605 : {
606 21681012 : entry->hook (cs1, cs2, entry->data);
607 21681012 : entry = entry->next;
608 : }
609 7870998 : }
610 :
611 : /* Register HOOK to be called with DATA on each duplicated node. */
612 : cgraph_2node_hook_list *
613 8133637 : symbol_table::add_cgraph_duplication_hook (cgraph_2node_hook hook, void *data)
614 : {
615 8133637 : cgraph_2node_hook_list *entry;
616 16267274 : cgraph_2node_hook_list **ptr = &m_first_cgraph_duplicated_hook;
617 :
618 8133637 : entry = (cgraph_2node_hook_list *) xmalloc (sizeof (*entry));
619 8133637 : entry->hook = hook;
620 8133637 : entry->data = data;
621 8133637 : entry->next = NULL;
622 40165914 : while (*ptr)
623 32032277 : ptr = &(*ptr)->next;
624 8133637 : *ptr = entry;
625 8133637 : return entry;
626 : }
627 :
628 : /* Remove ENTRY from the list of hooks called on duplicating nodes. */
629 : void
630 8033427 : symbol_table::remove_cgraph_duplication_hook (cgraph_2node_hook_list *entry)
631 : {
632 8033427 : cgraph_2node_hook_list **ptr = &m_first_cgraph_duplicated_hook;
633 :
634 36467461 : while (*ptr != entry)
635 28434034 : ptr = &(*ptr)->next;
636 8033427 : *ptr = entry->next;
637 8033427 : free (entry);
638 8033427 : }
639 :
640 : /* Call all node duplication hooks. */
641 : void
642 3311855 : symbol_table::call_cgraph_duplication_hooks (cgraph_node *node,
643 : cgraph_node *node2)
644 : {
645 3311855 : cgraph_2node_hook_list *entry = m_first_cgraph_duplicated_hook;
646 23468234 : while (entry)
647 : {
648 20156379 : entry->hook (node, node2, entry->data);
649 20156379 : entry = entry->next;
650 : }
651 3311855 : }
652 :
653 : /* Return cgraph node assigned to DECL. Create new one when needed. */
654 :
655 : cgraph_node *
656 109384892 : cgraph_node::create (tree decl)
657 : {
658 109384892 : cgraph_node *node = symtab->create_empty ();
659 109384892 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
660 :
661 109384892 : node->decl = decl;
662 109384892 : node->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition);
663 :
664 109324723 : if ((flag_openacc || flag_openmp)
665 109658674 : && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
666 : {
667 8551 : node->offloadable = 1;
668 8551 : if (ENABLE_OFFLOADING)
669 : g->have_offload = true;
670 : }
671 :
672 109384892 : if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
673 114 : node->ifunc_resolver = true;
674 :
675 109384892 : node->register_symbol ();
676 109384892 : maybe_record_nested_function (node);
677 :
678 109384892 : 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 608850010 : cgraph_node::get_create (tree decl)
686 : {
687 608850010 : cgraph_node *first_clone = cgraph_node::get (decl);
688 :
689 608850010 : if (first_clone && !first_clone->inlined_to)
690 : return first_clone;
691 :
692 109315013 : cgraph_node *node = cgraph_node::create (decl);
693 109315013 : 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 109315005 : else if (dump_file && symtab->state != PARSING)
706 1420 : 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 8153550 : cgraph_node::create_alias (tree alias, tree target)
717 : {
718 8153550 : cgraph_node *alias_node;
719 :
720 8153550 : gcc_assert (TREE_CODE (target) == FUNCTION_DECL
721 : || TREE_CODE (target) == IDENTIFIER_NODE);
722 8153550 : gcc_assert (TREE_CODE (alias) == FUNCTION_DECL);
723 8153550 : alias_node = cgraph_node::get_create (alias);
724 8153550 : gcc_assert (!alias_node->definition);
725 8153550 : alias_node->alias_target = target;
726 8153550 : alias_node->definition = true;
727 8153550 : alias_node->alias = true;
728 8153550 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias)) != NULL)
729 47 : alias_node->transparent_alias = alias_node->weakref = true;
730 8153550 : if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (alias)))
731 317 : alias_node->ifunc_resolver = true;
732 8153550 : 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 8133636 : cgraph_node::create_same_body_alias (tree alias, tree decl)
743 : {
744 8133636 : cgraph_node *n;
745 :
746 : /* If aliases aren't supported by the assembler, fail. */
747 8133636 : 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 8133636 : if (symtab->global_info_ready)
753 : return NULL;
754 :
755 8133636 : n = cgraph_node::create_alias (alias, decl);
756 8133636 : n->cpp_implicit_alias = true;
757 8133636 : if (symtab->cpp_implicit_aliases_done)
758 3737441 : 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 234297099 : 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 234297099 : 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 47088359 : 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 47088359 : 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 287405262 : cgraph_edge_hasher::equal (cgraph_edge *x, gimple *y)
850 : {
851 287405262 : 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 4804 : cgraph_update_edge_in_call_site_hash (cgraph_edge *e)
858 : {
859 4804 : gimple *call = e->call_stmt;
860 4804 : *e->caller->call_site_hash->find_slot_with_hash
861 4804 : (call, cgraph_edge_hasher::hash (call), INSERT) = e;
862 4804 : }
863 :
864 : /* Add call graph edge E to call site hash of its caller. */
865 :
866 : static inline void
867 8908059 : 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 8908059 : 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 8907972 : if (e->callback_with_carrying_edge_p ())
877 : return;
878 8907962 : cgraph_edge **slot = e->caller->call_site_hash->find_slot_with_hash
879 8907962 : (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt), INSERT);
880 8907962 : if (*slot)
881 : {
882 4902 : cgraph_edge *edge = (cgraph_edge *) *slot;
883 4902 : gcc_assert (edge->speculative || edge->has_callback);
884 4902 : 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 4810 : 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 8903060 : gcc_assert (!*slot || e->speculative);
897 8903060 : *slot = e;
898 : }
899 :
900 : /* Return the callgraph edge representing the GIMPLE_CALL statement
901 : CALL_STMT. */
902 :
903 : cgraph_edge *
904 217679923 : cgraph_node::get_edge (gimple *call_stmt)
905 : {
906 217679923 : cgraph_edge *e, *e2;
907 217679923 : int n = 0;
908 :
909 217679923 : if (call_site_hash)
910 36909277 : return call_site_hash->find_with_hash
911 36909277 : (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 1785668711 : for (e = callees; e; e = e->next_callee)
919 : {
920 1736153686 : if (e->call_stmt == call_stmt)
921 : break;
922 1604898065 : n++;
923 : }
924 :
925 180770646 : if (!e)
926 63449866 : for (e = indirect_calls; e; e = e->next_callee)
927 : {
928 16828163 : if (e->call_stmt == call_stmt)
929 : break;
930 13934841 : 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 180770646 : if (e && e->callback_with_carrying_edge_p ())
938 54762 : e = e->get_callback_carrying_edge ();
939 :
940 180770646 : if (n > 100)
941 : {
942 32944 : call_site_hash = hash_table<cgraph_edge_hasher>::create_ggc (120);
943 3377352 : for (e2 = callees; e2; e2 = e2->next_callee)
944 3344408 : cgraph_add_edge_to_call_site_hash (e2);
945 120183 : for (e2 = indirect_calls; e2; e2 = e2->next_callee)
946 87239 : 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 3108398 : cgraph_edge::set_call_stmt (cgraph_edge *e, gcall *new_stmt,
961 : bool update_derived_edges)
962 : {
963 3109129 : tree decl;
964 :
965 3109129 : cgraph_node *new_direct_callee = NULL;
966 3079988 : if ((e->indirect_unknown_callee || e->speculative)
967 3154105 : && (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 3109129 : 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 6927 : && !new_direct_callee)
981 : {
982 6927 : cgraph_edge *direct, *indirect, *next;
983 6927 : ipa_ref *ref;
984 6927 : bool e_indirect = e->indirect_unknown_callee;
985 6927 : int n = 0;
986 :
987 6927 : direct = e->first_speculative_call_target ();
988 6927 : indirect = e->speculative_call_indirect_edge ();
989 :
990 6927 : gcall *old_stmt = direct->call_stmt;
991 15835 : for (cgraph_edge *d = direct; d; d = next)
992 : {
993 8908 : next = d->next_speculative_call_target ();
994 8908 : cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
995 8908 : gcc_assert (d2 == d);
996 8908 : n++;
997 : }
998 6927 : gcc_checking_assert (indirect->num_speculative_call_targets_p () == n);
999 25960 : for (unsigned int i = 0; e->caller->iterate_reference (i, ref); i++)
1000 19033 : if (ref->speculative && ref->stmt == old_stmt)
1001 : {
1002 8908 : ref->stmt = new_stmt;
1003 8908 : n--;
1004 : }
1005 :
1006 6927 : indirect = set_call_stmt (indirect, new_stmt, false);
1007 6927 : return e_indirect ? indirect : direct;
1008 : }
1009 :
1010 3102202 : 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 3102202 : if (update_derived_edges
1016 3102202 : && (e->callback_with_carrying_edge_p () || e->has_callback))
1017 : {
1018 731 : cgraph_edge *current, *next, *carrying;
1019 731 : carrying = e->has_callback ? e : e->get_callback_carrying_edge ();
1020 :
1021 731 : current = e->first_callback_edge ();
1022 731 : if (current)
1023 : {
1024 95 : for (cgraph_edge *d = current; d; d = next)
1025 : {
1026 48 : next = d->next_callback_edge ();
1027 48 : cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
1028 48 : gcc_assert (d2 == d);
1029 : }
1030 : }
1031 731 : carrying = set_call_stmt (carrying, new_stmt, false);
1032 731 : return carrying;
1033 : }
1034 :
1035 : /* Only direct speculative edges go to call_site_hash. */
1036 3101471 : if (e->caller->call_site_hash
1037 614003 : && (!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 3715441 : && e->caller->get_edge (e->call_stmt) == e)
1041 609166 : e->caller->call_site_hash->remove_elt_with_hash
1042 609166 : (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt));
1043 :
1044 3101471 : e->call_stmt = new_stmt;
1045 :
1046 3101471 : function *fun = DECL_STRUCT_FUNCTION (e->caller->decl);
1047 3101471 : 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 3101471 : if (e->caller->call_site_hash
1051 614003 : && (!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 614003 : 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 47072294 : 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 47072294 : cgraph_edge *edge;
1071 :
1072 : /* LTO does not actually have access to the call_stmt since these
1073 : have not been loaded yet. */
1074 47072294 : if (call_stmt)
1075 : {
1076 : /* This is a rather expensive check possibly triggering
1077 : construction of call stmt hashtable. */
1078 46206205 : cgraph_edge *e;
1079 46206205 : gcc_checking_assert (!(e = caller->get_edge (call_stmt))
1080 : || e->speculative || e->has_callback || e->callback);
1081 :
1082 46206205 : gcc_assert (is_gimple_call (call_stmt));
1083 : }
1084 :
1085 47072294 : edge = ggc_alloc<cgraph_edge> ();
1086 47072294 : edge->m_summary_id = -1;
1087 47072294 : edges_count++;
1088 :
1089 47072294 : ++edges_max_uid;
1090 47072294 : gcc_assert (edges_max_uid != 0);
1091 47072294 : edge->m_uid = edges_max_uid;
1092 47072294 : edge->aux = NULL;
1093 47072294 : edge->caller = caller;
1094 47072294 : edge->callee = callee;
1095 47072294 : edge->prev_caller = NULL;
1096 47072294 : edge->next_caller = NULL;
1097 47072294 : edge->prev_callee = NULL;
1098 47072294 : edge->next_callee = NULL;
1099 47072294 : edge->lto_stmt_uid = 0;
1100 47072294 : edge->speculative_id = 0;
1101 :
1102 47072294 : edge->count = count;
1103 47072294 : edge->call_stmt = call_stmt;
1104 47072294 : edge->indirect_info = NULL;
1105 47072294 : edge->indirect_inlining_edge = 0;
1106 47072294 : edge->speculative = false;
1107 47072294 : edge->has_callback = false;
1108 47072294 : edge->callback = false;
1109 47072294 : edge->indirect_unknown_callee = indir_unknown_callee;
1110 47072294 : if (call_stmt && caller->call_site_hash)
1111 4862409 : cgraph_add_edge_to_call_site_hash (edge);
1112 :
1113 47072294 : if (cloning_p)
1114 : return edge;
1115 :
1116 39230051 : edge->can_throw_external
1117 39230051 : = call_stmt ? stmt_can_throw_external (DECL_STRUCT_FUNCTION (caller->decl),
1118 : call_stmt) : false;
1119 39230051 : edge->inline_failed = CIF_FUNCTION_NOT_CONSIDERED;
1120 39230051 : edge->call_stmt_cannot_inline_p = false;
1121 :
1122 39230051 : if (opt_for_fn (edge->caller->decl, flag_devirtualize)
1123 39230051 : && call_stmt && DECL_STRUCT_FUNCTION (caller->decl))
1124 30844972 : edge->in_polymorphic_cdtor
1125 30844972 : = decl_maybe_in_construction_p (NULL, NULL, call_stmt,
1126 : caller->decl);
1127 : else
1128 8385079 : edge->in_polymorphic_cdtor = caller->thunk;
1129 :
1130 38551886 : if (callee && symtab->state != LTO_STREAMING
1131 77178438 : && 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 46211136 : cgraph_node::create_edge (cgraph_node *callee,
1143 : gcall *call_stmt, profile_count count, bool cloning_p)
1144 : {
1145 46211136 : cgraph_edge *edge = symtab->create_edge (this, callee, call_stmt, count,
1146 : false, cloning_p);
1147 :
1148 46211136 : if (!cloning_p)
1149 38551886 : initialize_inline_failed (edge);
1150 :
1151 46211136 : edge->next_caller = callee->callers;
1152 46211136 : if (callee->callers)
1153 36109108 : callee->callers->prev_caller = edge;
1154 46211136 : edge->next_callee = callees;
1155 46211136 : if (callees)
1156 35814135 : callees->prev_callee = edge;
1157 46211136 : callees = edge;
1158 46211136 : callee->callers = edge;
1159 :
1160 46211136 : 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 861158 : cgraph_node::create_indirect_edge (gcall *call_stmt, int ecf_flags,
1171 : profile_count count, bool cloning_p)
1172 : {
1173 861158 : cgraph_edge *edge = symtab->create_edge (this, NULL, call_stmt, count, true,
1174 : cloning_p);
1175 :
1176 861158 : if (!cloning_p)
1177 : {
1178 678165 : initialize_inline_failed (edge);
1179 :
1180 678165 : tree target = NULL_TREE;
1181 678165 : if (call_stmt)
1182 678165 : target = gimple_call_fn (call_stmt);
1183 678165 : if (target && virtual_method_call_p (target))
1184 : {
1185 96814 : ipa_polymorphic_call_context context (decl, target, call_stmt);
1186 96814 : HOST_WIDE_INT token = tree_to_shwi (OBJ_TYPE_REF_TOKEN (target));
1187 96814 : tree type = obj_type_ref_class (target);
1188 96814 : edge->indirect_info
1189 96814 : = (new (ggc_alloc<cgraph_polymorphic_indirect_info> ())
1190 : cgraph_polymorphic_indirect_info (ecf_flags, context, token,
1191 96814 : type));
1192 : }
1193 581351 : else if (target && TREE_CODE (target) == SSA_NAME)
1194 574333 : edge->indirect_info
1195 574333 : = (new (ggc_alloc<cgraph_simple_indirect_info> ())
1196 574333 : cgraph_simple_indirect_info (ecf_flags));
1197 : else
1198 7018 : edge->indirect_info
1199 7018 : = (new (ggc_alloc<cgraph_indirect_call_info> ())
1200 7018 : cgraph_indirect_call_info(CIIK_UNSPECIFIED, ecf_flags));
1201 : }
1202 :
1203 861158 : edge->next_callee = indirect_calls;
1204 861158 : if (indirect_calls)
1205 409727 : indirect_calls->prev_callee = edge;
1206 861158 : indirect_calls = edge;
1207 :
1208 861158 : return edge;
1209 : }
1210 :
1211 : /* Remove the edge from the list of the callees of the caller. */
1212 :
1213 : void
1214 4804344 : cgraph_edge::remove_caller (void)
1215 : {
1216 4804344 : if (prev_callee)
1217 3950118 : prev_callee->next_callee = next_callee;
1218 4804344 : if (next_callee)
1219 3292416 : next_callee->prev_callee = prev_callee;
1220 4804344 : if (!prev_callee)
1221 : {
1222 854226 : if (indirect_unknown_callee)
1223 1281 : caller->indirect_calls = next_callee;
1224 : else
1225 852945 : caller->callees = next_callee;
1226 : }
1227 4804344 : if (caller->call_site_hash
1228 4804344 : && this == caller->get_edge (call_stmt))
1229 657150 : caller->call_site_hash->remove_elt_with_hash
1230 657150 : (call_stmt, cgraph_edge_hasher::hash (call_stmt));
1231 4804344 : }
1232 :
1233 : /* Put the edge onto the free list. */
1234 :
1235 : void
1236 46629595 : symbol_table::free_edge (cgraph_edge *e)
1237 : {
1238 46629595 : edges_count--;
1239 46629595 : if (e->m_summary_id != -1)
1240 22043848 : edge_released_summary_ids.safe_push (e->m_summary_id);
1241 :
1242 46629595 : if (e->indirect_info)
1243 853510 : ggc_free (e->indirect_info);
1244 46629595 : ggc_free (e);
1245 46629595 : }
1246 :
1247 : /* Remove the edge in the cgraph. */
1248 :
1249 : void
1250 115829 : cgraph_edge::remove (cgraph_edge *edge)
1251 : {
1252 : /* Call all edge removal hooks. */
1253 115829 : symtab->call_edge_removal_hooks (edge);
1254 :
1255 115829 : if (!edge->indirect_unknown_callee)
1256 : /* Remove from callers list of the callee. */
1257 113157 : edge->remove_callee ();
1258 :
1259 : /* Remove from callees list of the callers. */
1260 115829 : edge->remove_caller ();
1261 :
1262 : /* Put the edge onto the free list. */
1263 115829 : symtab->free_edge (edge);
1264 115829 : }
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 17572 : cgraph_edge::get_next_speculative_id ()
1272 : {
1273 17572 : 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 17572 : 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 15952 : cgraph_edge::make_speculative (cgraph_node *n2, profile_count direct_count,
1316 : unsigned int speculative_id)
1317 : {
1318 15952 : cgraph_node *n = caller;
1319 15952 : ipa_ref *ref = NULL;
1320 15952 : cgraph_edge *e2;
1321 :
1322 15952 : if (dump_file)
1323 29 : fprintf (dump_file, "Indirect call -> speculative call %s => %s\n",
1324 : n->dump_name (), n2->dump_name ());
1325 15952 : speculative = true;
1326 15952 : e2 = n->create_edge (n2, call_stmt, direct_count);
1327 15952 : initialize_inline_failed (e2);
1328 15952 : e2->speculative = true;
1329 15952 : if (TREE_NOTHROW (n2->decl))
1330 : e2->can_throw_external = false;
1331 : else
1332 5367 : e2->can_throw_external = can_throw_external;
1333 15952 : e2->lto_stmt_uid = lto_stmt_uid;
1334 15952 : e2->speculative_id = speculative_id;
1335 15952 : e2->in_polymorphic_cdtor = in_polymorphic_cdtor;
1336 15952 : indirect_info->num_speculative_call_targets++;
1337 15952 : count -= e2->count;
1338 15952 : symtab->call_edge_duplication_hooks (this, e2);
1339 15952 : ref = n->create_reference (n2, IPA_REF_ADDR, call_stmt);
1340 15952 : ref->lto_stmt_uid = lto_stmt_uid;
1341 15952 : ref->speculative_id = speculative_id;
1342 15952 : ref->speculative = speculative;
1343 15952 : n2->mark_address_taken ();
1344 15952 : 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 15205 : cgraph_edge::make_callback (cgraph_node *n2, unsigned fn_idx, tree attr)
1364 : {
1365 15205 : cgraph_node *n = caller;
1366 15205 : cgraph_edge *e2;
1367 :
1368 15205 : has_callback = true;
1369 15205 : e2 = n->create_edge (n2, call_stmt, count);
1370 15205 : if (dump_file)
1371 5 : fprintf (
1372 : dump_file,
1373 : "Created callback edge %s -> %s belonging to carrying edge %s -> %s\n",
1374 5 : e2->caller->dump_name (), e2->callee->dump_name (), caller->dump_name (),
1375 5 : callee->dump_name ());
1376 15205 : e2->inline_failed = CIF_CALLBACK_EDGE;
1377 15205 : e2->callback = true;
1378 15205 : if (TREE_NOTHROW (n2->decl))
1379 : e2->can_throw_external = false;
1380 : else
1381 251 : e2->can_throw_external = can_throw_external;
1382 15205 : e2->lto_stmt_uid = lto_stmt_uid;
1383 15205 : callback_info *ci = callback_info_sum->get_create (e2);
1384 15205 : ci->init (e2, fn_idx, attr);
1385 15205 : symtab->call_edge_duplication_hooks (this, e2);
1386 15205 : n2->mark_address_taken ();
1387 15205 : 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 175 : cgraph_edge::make_callback_internal (cgraph_node *caller, cgraph_node *target,
1398 : gcall *call_stmt)
1399 : {
1400 175 : cgraph_edge *ret;
1401 :
1402 175 : ret
1403 175 : = caller->create_edge (target, call_stmt, profile_count::uninitialized ());
1404 175 : 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 175 : ret->inline_failed = CIF_CALLBACK_EDGE;
1412 175 : ret->callback = true;
1413 175 : if (TREE_NOTHROW (target->decl))
1414 148 : ret->can_throw_external = false;
1415 175 : target->mark_address_taken ();
1416 175 : callback_info::create_internal_summary (ret, IFN_ASSUME);
1417 175 : 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 82614 : cgraph_edge::get_callback_carrying_edge ()
1428 : {
1429 82614 : gcc_checking_assert (callback);
1430 82614 : cgraph_edge *e;
1431 641923 : for (e = caller->callees; e; e = e->next_callee)
1432 : {
1433 640650 : if (e->has_callback && e->call_stmt == call_stmt
1434 81341 : && e->lto_stmt_uid == lto_stmt_uid)
1435 : break;
1436 : }
1437 82614 : return e;
1438 : }
1439 :
1440 : /* Returns TRUE iff THIS is a callback edge with a carrying edge. */
1441 : bool
1442 146145334 : cgraph_edge::callback_with_carrying_edge_p () const
1443 : {
1444 : /* Callback edges are always direct, i.e. callee != NULL. */
1445 146145334 : 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 48428 : cgraph_edge::first_callback_edge ()
1454 : {
1455 48428 : gcc_checking_assert (has_callback || callback);
1456 48428 : cgraph_edge *e = NULL;
1457 224276 : for (e = caller->callees; e; e = e->next_callee)
1458 : {
1459 207165 : if (e->callback && e->call_stmt == call_stmt
1460 31317 : && e->lto_stmt_uid == lto_stmt_uid)
1461 : break;
1462 : }
1463 48428 : 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 31325 : cgraph_edge::next_callback_edge ()
1472 : {
1473 31325 : gcc_checking_assert (callback);
1474 31325 : cgraph_edge *e = NULL;
1475 309292 : for (e = next_callee; e; e = e->next_callee)
1476 : {
1477 277975 : if (e->callback && e->call_stmt == call_stmt
1478 8 : && e->lto_stmt_uid == lto_stmt_uid)
1479 : break;
1480 : }
1481 31325 : 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 2 : cgraph_edge::purge_callback_edges ()
1489 : {
1490 2 : gcc_checking_assert (has_callback);
1491 2 : cgraph_edge *e, *next;
1492 4 : for (e = first_callback_edge (); e; e = next)
1493 : {
1494 2 : next = e->next_callback_edge ();
1495 2 : cgraph_edge::remove (e);
1496 : }
1497 2 : has_callback = false;
1498 2 : }
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 50425 : cgraph_edge::first_speculative_call_target ()
1508 : {
1509 50425 : cgraph_edge *e = this;
1510 :
1511 50425 : gcc_checking_assert (e->speculative);
1512 50425 : if (e->callee)
1513 : {
1514 14768 : while (e->prev_callee && e->prev_callee->speculative
1515 1303 : && e->prev_callee->call_stmt == e->call_stmt
1516 40770 : && 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 9655 : if (e->call_stmt)
1523 9614 : 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 39652 : update_call_stmt_hash_for_removing_direct_edge (cgraph_edge *e,
1538 : cgraph_edge *indirect)
1539 : {
1540 39652 : if (e->caller->call_site_hash)
1541 : {
1542 4804 : if (e->caller->get_edge (e->call_stmt) != e)
1543 : ;
1544 4804 : else if (!indirect->num_speculative_call_targets_p ())
1545 4019 : 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 39652 : }
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 5809 : cgraph_edge::resolve_speculation (cgraph_edge *edge, tree callee_decl)
1572 : {
1573 5809 : cgraph_edge *e2;
1574 5809 : ipa_ref *ref;
1575 :
1576 5809 : gcc_assert (edge->speculative && (!callee_decl || edge->callee));
1577 5809 : if (!edge->callee)
1578 0 : e2 = edge->first_speculative_call_target ();
1579 : else
1580 : e2 = edge;
1581 5809 : ref = e2->speculative_call_target_ref ();
1582 5809 : edge = edge->speculative_call_indirect_edge ();
1583 5809 : symtab_node *callee;
1584 5809 : if (!callee_decl
1585 1199 : || !(callee = symtab_node::get (callee_decl))
1586 7008 : || !ref->referred->semantically_equivalent_p (callee))
1587 : {
1588 4921 : 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 5809 : edge->count += e2->count;
1618 5809 : 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 4921 : edge->indirect_info->num_speculative_call_targets--;
1623 4921 : if (!edge->indirect_info->num_speculative_call_targets)
1624 1017 : edge->speculative = false;
1625 : }
1626 : else
1627 888 : edge->speculative = false;
1628 5809 : e2->speculative = false;
1629 5809 : update_call_stmt_hash_for_removing_direct_edge (e2, edge);
1630 5809 : ref->remove_reference ();
1631 5809 : if (e2->indirect_unknown_callee || e2->inline_failed)
1632 5296 : remove (e2);
1633 : else
1634 513 : e2->callee->remove_symbol_and_inline_clones ();
1635 5809 : 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 4966 : cgraph_edge::make_direct (cgraph_edge *edge, cgraph_node *callee)
1660 : {
1661 4966 : gcc_assert (edge->indirect_unknown_callee || edge->speculative);
1662 :
1663 : /* If we are redirecting speculative call, make it non-speculative. */
1664 4966 : 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 4078 : edge->indirect_unknown_callee = 0;
1703 4078 : ggc_free (edge->indirect_info);
1704 4078 : edge->indirect_info = NULL;
1705 :
1706 : /* Get the edge out of the indirect edge list. */
1707 4078 : if (edge->prev_callee)
1708 109 : edge->prev_callee->next_callee = edge->next_callee;
1709 4078 : if (edge->next_callee)
1710 560 : edge->next_callee->prev_callee = edge->prev_callee;
1711 4078 : if (!edge->prev_callee)
1712 3969 : edge->caller->indirect_calls = edge->next_callee;
1713 :
1714 : /* Put it into the normal callee list */
1715 4078 : edge->prev_callee = NULL;
1716 4078 : edge->next_callee = edge->caller->callees;
1717 4078 : if (edge->caller->callees)
1718 2663 : edge->caller->callees->prev_callee = edge;
1719 4078 : edge->caller->callees = edge;
1720 :
1721 : /* Insert to callers list of the new callee. */
1722 4078 : edge->set_callee (callee);
1723 :
1724 : /* We need to re-determine the inlining status of the edge. */
1725 4078 : initialize_inline_failed (edge);
1726 4078 : 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 4720213 : cgraph_edge::redirect_callee (cgraph_node *n)
1734 : {
1735 4720213 : bool loc = callee->comdat_local_p ();
1736 4720213 : cgraph_node *old_callee = callee;
1737 :
1738 : /* Remove from callers list of the current callee. */
1739 4720213 : remove_callee ();
1740 :
1741 : /* Insert to callers list of the new callee. */
1742 4720213 : set_callee (n);
1743 :
1744 4720213 : if (callback)
1745 : {
1746 : /* When redirecting a callback callee, redirect its ref as well. */
1747 301 : ipa_ref *old_ref = caller->find_reference (old_callee, call_stmt,
1748 301 : lto_stmt_uid, IPA_REF_ADDR);
1749 301 : gcc_checking_assert (old_ref);
1750 301 : old_ref->remove_reference ();
1751 301 : ipa_ref *new_ref = caller->create_reference (n, IPA_REF_ADDR, call_stmt);
1752 301 : 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 301 : if (!old_callee->iterate_referring (0, old_ref))
1757 236 : old_callee->address_taken = 0;
1758 301 : n->mark_address_taken ();
1759 301 : callback_info *ci = callback_info_sum->get (this);
1760 301 : ci->redirected = true;
1761 : }
1762 :
1763 4720213 : if (!inline_failed)
1764 : return;
1765 800712 : 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 800656 : 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 10327521 : cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
1799 : hash_set <tree> *killed_ssas)
1800 : {
1801 10327521 : tree decl = gimple_call_fndecl (e->call_stmt);
1802 10327521 : gcall *new_stmt;
1803 :
1804 10327521 : 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 33843 : 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 33843 : gcc_checking_assert (e->callee);
1816 33843 : cgraph_edge *indirect = e->speculative_call_indirect_edge ();
1817 33843 : gcall *new_stmt;
1818 33843 : ipa_ref *ref;
1819 :
1820 : /* Expand speculation into GIMPLE code. */
1821 33843 : 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 33843 : push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
1831 :
1832 33843 : profile_count all = indirect->count;
1833 33843 : for (cgraph_edge *e2 = e->first_speculative_call_target ();
1834 76988 : e2;
1835 43145 : e2 = e2->next_speculative_call_target ())
1836 43145 : all = all + e2->count;
1837 33843 : profile_probability prob = e->count.probability_in (all);
1838 33843 : if (!prob.initialized_p ())
1839 160 : prob = profile_probability::even ();
1840 33843 : ref = e->speculative_call_target_ref ();
1841 67686 : new_stmt = gimple_ic (e->call_stmt,
1842 : dyn_cast<cgraph_node *> (ref->referred),
1843 : prob);
1844 33843 : e->speculative = false;
1845 33843 : 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 33843 : indirect->indirect_info->num_speculative_call_targets--;
1851 33843 : if (!indirect->indirect_info->num_speculative_call_targets)
1852 26156 : 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 33843 : update_call_stmt_hash_for_removing_direct_edge (e, indirect);
1859 33843 : cgraph_edge::set_call_stmt (e, new_stmt, false);
1860 33843 : 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 33843 : if (!indirect->speculative)
1866 26156 : indirect->count = gimple_bb (indirect->call_stmt)->count;
1867 33843 : ref->speculative = false;
1868 33843 : ref->stmt = NULL;
1869 33843 : pop_cfun ();
1870 : /* Continue redirecting E to proper target. */
1871 : }
1872 : }
1873 :
1874 :
1875 10327521 : if (e->indirect_unknown_callee
1876 10243363 : || decl == e->callee->decl)
1877 9139398 : return e->call_stmt;
1878 :
1879 1188123 : clone_info *callee_info = clone_info::get (e->callee);
1880 1188123 : 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 1188123 : if (e->callback_with_carrying_edge_p ())
1894 : {
1895 3248 : cgraph_edge *carrying = e->get_callback_carrying_edge ();
1896 3248 : if (!callback_is_special_cased (carrying->callee->decl, e->call_stmt)
1897 5737 : && !lookup_attribute ("callback_only",
1898 2489 : 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 3248 : callback_redirect_edge (e);
1904 3248 : return e->call_stmt;
1905 : }
1906 : /* Callback calls to .ASSUME bodies might need to have their statement
1907 : rebuilt. */
1908 1184875 : else if (e->callback && e->callee->assume_function)
1909 : {
1910 232 : ipa_param_adjustments *padjs
1911 168 : = callee_info ? callee_info->param_adjustments : NULL;
1912 :
1913 : /* If there are no param adjustments, replace the address in the call
1914 : statement. */
1915 64 : if (!padjs)
1916 104 : callback_redirect_edge (e);
1917 : else
1918 : {
1919 64 : new_stmt = padjs->modify_call (e, false, killed_ssas);
1920 64 : gcc_checking_assert (callback_ifn_assume_call_p (new_stmt));
1921 64 : e->caller->set_call_stmt_including_clones (e->call_stmt, new_stmt,
1922 : false);
1923 : }
1924 168 : return e->call_stmt;
1925 : }
1926 1184707 : gcc_checking_assert (!e->callback);
1927 :
1928 1184707 : if (decl && ipa_saved_clone_sources)
1929 : {
1930 962436 : tree *p = ipa_saved_clone_sources->get (e->callee);
1931 962436 : if (p && decl == *p)
1932 : {
1933 35248 : gimple_call_set_fndecl (e->call_stmt, e->callee->decl);
1934 35248 : return e->call_stmt;
1935 : }
1936 : }
1937 1149459 : if (flag_checking && decl)
1938 : {
1939 1111819 : if (cgraph_node *node = cgraph_node::get (decl))
1940 : {
1941 967640 : clone_info *info = clone_info::get (node);
1942 967640 : gcc_assert (!info || !info->param_adjustments);
1943 : }
1944 : }
1945 :
1946 633821 : if (ipa_param_adjustments *padjs
1947 1149459 : = 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 626848 : int lp_nr = lookup_stmt_eh_lp (e->call_stmt);
1954 626848 : if (lp_nr != 0)
1955 155989 : remove_stmt_from_eh_lp (e->call_stmt);
1956 :
1957 626848 : tree old_fntype = gimple_call_fntype (e->call_stmt);
1958 626848 : new_stmt = padjs->modify_call (e, false, killed_ssas);
1959 626848 : cgraph_node *origin = e->callee;
1960 912970 : while (origin->clone_of)
1961 : origin = origin->clone_of;
1962 :
1963 626848 : if ((origin->former_clone_of
1964 489081 : && old_fntype == TREE_TYPE (origin->former_clone_of))
1965 630829 : || old_fntype == TREE_TYPE (origin->decl))
1966 485102 : gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
1967 : else
1968 : {
1969 141746 : tree new_fntype = padjs->build_new_function_type (old_fntype, true);
1970 141746 : gimple_call_set_fntype (new_stmt, new_fntype);
1971 : }
1972 :
1973 626848 : if (lp_nr != 0)
1974 155989 : add_stmt_to_eh_lp (new_stmt, lp_nr);
1975 : }
1976 : else
1977 : {
1978 522611 : if (flag_checking
1979 522611 : && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
1980 : BUILT_IN_UNREACHABLE_TRAP))
1981 314663 : ipa_verify_edge_has_no_modifications (e);
1982 522611 : new_stmt = e->call_stmt;
1983 522611 : gimple_call_set_fndecl (new_stmt, e->callee->decl);
1984 522611 : 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 1149459 : if (gimple_call_noreturn_p (new_stmt)
1990 210905 : && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (e->callee->decl)))
1991 210832 : && TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl))
1992 1360285 : && (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (e->callee->decl)))
1993 210826 : == void_type_node))
1994 210032 : gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
1995 :
1996 : /* If the call becomes noreturn, remove the LHS if possible. */
1997 1149459 : tree lhs = gimple_call_lhs (new_stmt);
1998 1149459 : if (lhs
1999 340681 : && gimple_call_noreturn_p (new_stmt)
2000 1184393 : && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (new_stmt)))
2001 58 : || should_remove_lhs_p (lhs)))
2002 : {
2003 34895 : gimple_call_set_lhs (new_stmt, NULL_TREE);
2004 : /* We need to fix up the SSA name to avoid checking errors. */
2005 34895 : if (TREE_CODE (lhs) == SSA_NAME)
2006 : {
2007 29656 : tree var = create_tmp_reg_fn (DECL_STRUCT_FUNCTION (e->caller->decl),
2008 29656 : TREE_TYPE (lhs), NULL);
2009 29656 : SET_SSA_NAME_VAR_OR_IDENTIFIER (lhs, var);
2010 29656 : SSA_NAME_DEF_STMT (lhs) = gimple_build_nop ();
2011 29656 : set_ssa_default_def (DECL_STRUCT_FUNCTION (e->caller->decl),
2012 : var, lhs);
2013 : }
2014 34895 : update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
2015 : }
2016 :
2017 : /* If new callee has no static chain, remove it. */
2018 1149459 : if (gimple_call_chain (new_stmt) && !DECL_STATIC_CHAIN (e->callee->decl))
2019 : {
2020 56 : gimple_call_set_chain (new_stmt, NULL);
2021 56 : update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
2022 : }
2023 :
2024 1149459 : 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 1149459 : e->caller->set_call_stmt_including_clones (e->call_stmt, new_stmt, e->has_callback);
2030 :
2031 1149459 : 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 120549 : cgraph_update_edges_for_call_stmt_node (cgraph_node *node,
2047 : gimple *old_stmt, tree old_call,
2048 : gimple *new_stmt)
2049 : {
2050 120549 : tree new_call = (new_stmt && is_gimple_call (new_stmt))
2051 127049 : ? gimple_call_fndecl (new_stmt) : 0;
2052 :
2053 : /* We are seeing indirect calls, then there is nothing to update. */
2054 120549 : 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 118750 : if (old_call != new_call)
2059 : {
2060 117164 : cgraph_edge *e = node->get_edge (old_stmt);
2061 117164 : cgraph_edge *ne = NULL;
2062 117164 : profile_count count;
2063 :
2064 117164 : if (e)
2065 : {
2066 : /* If call was devirtualized during cloning, mark edge
2067 : as resolved. */
2068 95855 : 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 95855 : if (new_stmt && is_gimple_call (new_stmt) && e->callee
2082 97449 : && 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 95852 : if (new_call && e->callee)
2093 : {
2094 : cgraph_node *callee = e->callee;
2095 3183 : while (callee)
2096 : {
2097 1614 : if (callee->decl == new_call
2098 1614 : || 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 1592 : 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 95830 : count = e->count;
2111 95830 : if (e->indirect_unknown_callee || e->inline_failed)
2112 95830 : 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 95834 : if (new_call)
2124 : {
2125 3339 : ne = node->create_edge (cgraph_node::get_create (new_call),
2126 : as_a <gcall *> (new_stmt), count);
2127 3339 : 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 98875 : cgraph_update_edges_for_call_stmt (gimple *old_stmt, tree old_decl,
2142 : gimple *new_stmt)
2143 : {
2144 98875 : cgraph_node *orig = cgraph_node::get (cfun->decl);
2145 98875 : cgraph_node *node;
2146 :
2147 98875 : gcc_checking_assert (orig);
2148 98875 : gcc_assert (!orig->thunk);
2149 98875 : cgraph_update_edges_for_call_stmt_node (orig, old_stmt, old_decl, new_stmt);
2150 98875 : 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 98875 : }
2170 :
2171 :
2172 : /* Remove all callees from the node. */
2173 :
2174 : void
2175 241195229 : cgraph_node::remove_callees (void)
2176 : {
2177 241195229 : cgraph_edge *e, *f;
2178 :
2179 241195229 : 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 282169642 : for (e = callees; e; e = f)
2185 : {
2186 40974413 : f = e->next_callee;
2187 40974413 : symtab->call_edge_removal_hooks (e);
2188 40974413 : if (!e->indirect_unknown_callee)
2189 40974413 : e->remove_callee ();
2190 40974413 : symtab->free_edge (e);
2191 : }
2192 242046067 : for (e = indirect_calls; e; e = f)
2193 : {
2194 850838 : f = e->next_callee;
2195 850838 : symtab->call_edge_removal_hooks (e);
2196 850838 : if (!e->indirect_unknown_callee)
2197 0 : e->remove_callee ();
2198 850838 : symtab->free_edge (e);
2199 : }
2200 241195229 : indirect_calls = NULL;
2201 241195229 : callees = NULL;
2202 241195229 : if (call_site_hash)
2203 : {
2204 32869 : call_site_hash->empty ();
2205 32869 : call_site_hash = NULL;
2206 : }
2207 241195229 : }
2208 :
2209 : /* Remove all callers from the node. */
2210 :
2211 : void
2212 109062332 : cgraph_node::remove_callers (void)
2213 : {
2214 109062332 : 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 113750847 : for (e = callers; e; e = f)
2220 : {
2221 4688515 : f = e->next_caller;
2222 : /* When removing a callback-carrying edge, remove all its attached edges
2223 : as well. */
2224 4688515 : 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 4688515 : symtab->call_edge_removal_hooks (e);
2234 4688515 : e->remove_caller ();
2235 4688515 : symtab->free_edge (e);
2236 : }
2237 109062332 : callers = NULL;
2238 109062332 : }
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 119228959 : release_function_body (tree decl)
2246 : {
2247 119228959 : function *fn = DECL_STRUCT_FUNCTION (decl);
2248 119228959 : if (fn)
2249 : {
2250 107471751 : if (fn->cfg
2251 107471751 : && loops_for_fn (fn))
2252 : {
2253 1786621 : fn->curr_properties &= ~PROP_loops;
2254 1786621 : loop_optimizer_finalize (fn);
2255 : }
2256 107471751 : if (fn->gimple_df)
2257 : {
2258 1795493 : delete_tree_ssa (fn);
2259 1795493 : fn->eh = NULL;
2260 : }
2261 107471751 : if (fn->cfg)
2262 : {
2263 1786622 : gcc_assert (!dom_info_available_p (fn, CDI_DOMINATORS));
2264 1786622 : gcc_assert (!dom_info_available_p (fn, CDI_POST_DOMINATORS));
2265 1786622 : delete_tree_cfg_annotations (fn);
2266 1786622 : free_cfg (fn);
2267 1786622 : fn->cfg = NULL;
2268 : }
2269 107471751 : if (fn->value_histograms)
2270 13 : free_histograms (fn);
2271 107471751 : 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 107471751 : ggc_free (fn);
2275 107471751 : DECL_STRUCT_FUNCTION (decl) = NULL;
2276 : }
2277 119228959 : DECL_SAVED_TREE (decl) = NULL;
2278 119228959 : }
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 119217008 : cgraph_node::release_body (bool keep_arguments)
2288 : {
2289 119217008 : ipa_transforms_to_apply.release ();
2290 119217008 : if (!used_as_abstract_origin && symtab->state != PARSING)
2291 : {
2292 118621631 : DECL_RESULT (decl) = NULL;
2293 :
2294 118621631 : if (!keep_arguments)
2295 118589869 : 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 119217008 : if (!used_as_abstract_origin && DECL_INITIAL (decl))
2301 106943834 : DECL_INITIAL (decl) = error_mark_node;
2302 119217008 : release_function_body (decl);
2303 119217008 : lto_free_function_in_decl_state_for_node (this);
2304 119217008 : 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 119217008 : remove_callees ();
2314 119217008 : remove_all_references ();
2315 119217008 : }
2316 :
2317 : /* Remove function from symbol table. */
2318 :
2319 : void
2320 109062332 : cgraph_node::remove (void)
2321 : {
2322 109062332 : bool clone_info_set = false;
2323 109062332 : clone_info *info, saved_info;
2324 109062332 : 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 109062332 : if ((info = clone_info::get (this)) != NULL)
2331 : {
2332 441254 : saved_info = *info;
2333 441254 : clone_info_set = true;
2334 : }
2335 109062332 : symtab->call_cgraph_removal_hooks (this);
2336 109062332 : remove_callers ();
2337 109062332 : remove_callees ();
2338 109062332 : ipa_transforms_to_apply.release ();
2339 109062332 : delete_function_version (function_version ());
2340 :
2341 : /* Incremental inlining access removed nodes stored in the postorder list.
2342 : */
2343 109062332 : force_output = false;
2344 109062332 : forced_by_abi = false;
2345 :
2346 217683410 : unregister (clone_info_set ? &saved_info : NULL);
2347 109062332 : if (prev_sibling_clone)
2348 801418 : prev_sibling_clone->next_sibling_clone = next_sibling_clone;
2349 108260914 : else if (clone_of)
2350 : {
2351 1902418 : clone_of->clones = next_sibling_clone;
2352 1902418 : if (!clones)
2353 : {
2354 1899367 : bool need_body = false;
2355 1899367 : for (cgraph_node *n = clone_of; n; n = n->clone_of)
2356 1893798 : if (n->analyzed || n->clones)
2357 : {
2358 : need_body = true;
2359 : break;
2360 : }
2361 1893795 : if (!need_body)
2362 5569 : clone_of->release_body ();
2363 : }
2364 : }
2365 109062332 : if (next_sibling_clone)
2366 1046605 : next_sibling_clone->prev_sibling_clone = prev_sibling_clone;
2367 109062332 : if (clones)
2368 : {
2369 39584 : cgraph_node *n, *next;
2370 :
2371 39584 : if (clone_of)
2372 : {
2373 175072 : for (n = clones; n->next_sibling_clone; n = n->next_sibling_clone)
2374 135488 : n->clone_of = clone_of;
2375 39584 : n->clone_of = clone_of;
2376 39584 : n->next_sibling_clone = clone_of->clones;
2377 39584 : if (clone_of->clones)
2378 34514 : clone_of->clones->prev_sibling_clone = n;
2379 39584 : 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 109062332 : if (symtab->state != LTO_STREAMING)
2403 : {
2404 109060174 : cgraph_node *n = cgraph_node::get (decl);
2405 109060174 : if (!n
2406 109060174 : || (!n->clones && !n->clone_of && !n->inlined_to
2407 1178063 : && ((symtab->global_info_ready || in_lto_p)
2408 10463 : && (TREE_ASM_WRITTEN (n->decl)
2409 10431 : || DECL_EXTERNAL (n->decl)
2410 5621 : || !n->analyzed
2411 5426 : || (!flag_wpa && n->in_other_partition)))))
2412 105949117 : release_body ();
2413 : }
2414 : else
2415 2158 : lto_free_function_in_decl_state_for_node (this);
2416 :
2417 109062332 : decl = NULL;
2418 109062332 : if (call_site_hash)
2419 : {
2420 0 : call_site_hash->empty ();
2421 0 : call_site_hash = NULL;
2422 : }
2423 :
2424 109062332 : symtab->release_symbol (this);
2425 109062332 : }
2426 :
2427 : /* Likewise indicate that a node is having address taken. */
2428 :
2429 : void
2430 4875057 : cgraph_node::mark_address_taken (void)
2431 : {
2432 : /* Indirect inlining can figure out that all uses of the address are
2433 : inlined. */
2434 4875057 : 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 4875057 : address_taken = 1;
2447 4875057 : cgraph_node *node = ultimate_alias_target ();
2448 4875057 : node->address_taken = 1;
2449 : }
2450 :
2451 : /* Return local info node for the compiled function. */
2452 :
2453 : cgraph_node *
2454 12976623 : cgraph_node::local_info_node (tree decl)
2455 : {
2456 12976623 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
2457 12976623 : cgraph_node *node = get (decl);
2458 12976623 : if (!node)
2459 : return NULL;
2460 12976623 : return node->ultimate_alias_target ();
2461 : }
2462 :
2463 : /* Return RTL info for the compiled function. */
2464 :
2465 : cgraph_rtl_info *
2466 62402641 : cgraph_node::rtl_info (const_tree decl)
2467 : {
2468 62402641 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
2469 62402641 : cgraph_node *node = get (decl);
2470 62402641 : if (!node)
2471 : return NULL;
2472 62248733 : enum availability avail;
2473 62248733 : node = node->ultimate_alias_target (&avail);
2474 62248733 : if (decl != current_function_decl
2475 59142209 : && (avail < AVAIL_AVAILABLE
2476 53469557 : || (node->decl != current_function_decl
2477 53394441 : && !TREE_ASM_WRITTEN (node->decl))))
2478 : return NULL;
2479 : /* Allocate if it doesn't exist. */
2480 53000517 : if (node->rtl == NULL)
2481 : {
2482 1384556 : node->rtl = ggc_cleared_alloc<cgraph_rtl_info> ();
2483 1384556 : SET_HARD_REG_SET (node->rtl->function_used_regs);
2484 : }
2485 53000517 : return node->rtl;
2486 : }
2487 :
2488 : /* Return a string describing the failure REASON. */
2489 :
2490 : const char*
2491 9833 : cgraph_inline_failed_string (cgraph_inline_failed_t reason)
2492 : {
2493 : #undef DEFCIFCODE
2494 : #define DEFCIFCODE(code, type, string) string,
2495 :
2496 9833 : 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 9833 : gcc_assert ((unsigned) reason < CIF_N_REASONS);
2503 9833 : return cif_string_table[reason];
2504 : }
2505 :
2506 : /* Return a type describing the failure REASON. */
2507 :
2508 : cgraph_inline_failed_type_t
2509 75815850 : cgraph_inline_failed_type (cgraph_inline_failed_t reason)
2510 : {
2511 : #undef DEFCIFCODE
2512 : #define DEFCIFCODE(code, type, string) type,
2513 :
2514 75815850 : 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 75815850 : gcc_assert ((unsigned) reason < CIF_N_REASONS);
2521 75815850 : 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 22557 : cgraph_edge::dump_edge_flags (FILE *f)
2532 : {
2533 22557 : if (speculative)
2534 220 : fprintf (f, "(speculative) ");
2535 22557 : if (callback)
2536 64 : fprintf (f, "(callback) ");
2537 22557 : if (has_callback)
2538 12 : fprintf (f, "(has_callback) ");
2539 22557 : if (!inline_failed)
2540 1789 : fprintf (f, "(inlined) ");
2541 22557 : if (call_stmt_cannot_inline_p)
2542 0 : fprintf (f, "(call_stmt_cannot_inline_p) ");
2543 22557 : if (indirect_inlining_edge)
2544 325 : fprintf (f, "(indirect_inlining) ");
2545 22557 : if (count.initialized_p ())
2546 : {
2547 21960 : fprintf (f, "(");
2548 21960 : count.dump (f);
2549 21960 : fprintf (f, ",");
2550 21960 : fprintf (f, "%.2f per call) ", sreal_frequency ().to_double ());
2551 : }
2552 22557 : if (can_throw_external)
2553 2352 : fprintf (f, "(can throw external) ");
2554 22557 : }
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 6175 : cgraph_node::dump (FILE *f)
2574 : {
2575 6175 : cgraph_edge *edge;
2576 :
2577 6175 : dump_base (f);
2578 :
2579 6175 : if (inlined_to)
2580 776 : fprintf (f, " Function %s is inline copy in %s\n",
2581 : dump_name (),
2582 : inlined_to->dump_name ());
2583 6175 : if (clone_of)
2584 806 : fprintf (f, " Clone of %s\n", clone_of->dump_asm_name ());
2585 6175 : if (symtab->function_flags_ready)
2586 11246 : fprintf (f, " Availability: %s\n",
2587 5623 : cgraph_availability_names [get_availability ()]);
2588 :
2589 6175 : if (profile_id)
2590 193 : fprintf (f, " Profile id: %i\n",
2591 : profile_id);
2592 6175 : if (unit_id)
2593 210 : fprintf (f, " Unit id: %i\n",
2594 : unit_id);
2595 6175 : cgraph_function_version_info *vi = function_version ();
2596 6175 : 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 6175 : fprintf (f, " Function flags:");
2616 6175 : if (count.initialized_p ())
2617 : {
2618 3868 : fprintf (f, " count:");
2619 3868 : count.dump (f);
2620 : }
2621 6175 : if (tp_first_run > 0)
2622 89 : fprintf (f, " first_run:%" PRId64, (int64_t) tp_first_run);
2623 6175 : if (cgraph_node *origin = nested_function_origin (this))
2624 0 : fprintf (f, " nested in:%s", origin->dump_asm_name ());
2625 6175 : if (gimple_has_body_p (decl))
2626 4039 : fprintf (f, " body");
2627 6175 : if (process)
2628 0 : fprintf (f, " process");
2629 6175 : if (local)
2630 1147 : fprintf (f, " local");
2631 6175 : if (redefined_extern_inline)
2632 0 : fprintf (f, " redefined_extern_inline");
2633 6175 : if (only_called_at_startup)
2634 422 : fprintf (f, " only_called_at_startup");
2635 6175 : if (only_called_at_exit)
2636 7 : fprintf (f, " only_called_at_exit");
2637 6175 : if (tm_clone)
2638 0 : fprintf (f, " tm_clone");
2639 6175 : if (calls_comdat_local)
2640 9 : fprintf (f, " calls_comdat_local");
2641 6175 : if (icf_merged)
2642 26 : fprintf (f, " icf_merged");
2643 6175 : if (assume_function)
2644 60 : fprintf (f, " assume_function");
2645 6175 : if (merged_comdat)
2646 0 : fprintf (f, " merged_comdat");
2647 6175 : if (merged_extern_inline)
2648 0 : fprintf (f, " merged_extern_inline");
2649 6175 : if (split_part)
2650 23 : fprintf (f, " split_part");
2651 6175 : if (indirect_call_target)
2652 213 : fprintf (f, " indirect_call_target");
2653 6175 : if (nonfreeing_fn)
2654 343 : fprintf (f, " nonfreeing_fn");
2655 6175 : if (DECL_STATIC_CONSTRUCTOR (decl))
2656 48 : fprintf (f," static_constructor (priority:%i)", get_init_priority ());
2657 6175 : if (DECL_STATIC_DESTRUCTOR (decl))
2658 7 : fprintf (f," static_destructor (priority:%i)", get_fini_priority ());
2659 6175 : if (frequency == NODE_FREQUENCY_HOT)
2660 80 : fprintf (f, " hot");
2661 6175 : if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
2662 40 : fprintf (f, " unlikely_executed");
2663 6175 : if (frequency == NODE_FREQUENCY_EXECUTED_ONCE)
2664 743 : fprintf (f, " executed_once");
2665 6175 : if (opt_for_fn (decl, optimize_size))
2666 200 : fprintf (f, " optimize_size");
2667 6175 : if (parallelized_function)
2668 4 : fprintf (f, " parallelized_function");
2669 6175 : if (DECL_IS_MALLOC (decl))
2670 74 : fprintf (f, " decl_is_malloc");
2671 6175 : if (DECL_IS_OPERATOR_NEW_P (decl))
2672 35 : fprintf (f, " %soperator_new",
2673 35 : DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
2674 6175 : if (DECL_IS_OPERATOR_DELETE_P (decl))
2675 26 : fprintf (f, " %soperator_delete",
2676 26 : DECL_IS_REPLACEABLE_OPERATOR (decl) ? "replaceable_" : "");
2677 :
2678 6175 : if (DECL_STATIC_CHAIN (decl))
2679 6 : fprintf (f, " static_chain");
2680 :
2681 6175 : fprintf (f, "\n");
2682 :
2683 6175 : if (thunk)
2684 : {
2685 49 : fprintf (f, " Thunk");
2686 49 : thunk_info::get (this)->dump (f);
2687 : }
2688 6126 : else if (former_thunk_p ())
2689 : {
2690 21 : fprintf (f, " Former thunk ");
2691 21 : thunk_info::get (this)->dump (f);
2692 : }
2693 6105 : else gcc_checking_assert (!thunk_info::get (this));
2694 :
2695 6175 : fprintf (f, " Called by: ");
2696 :
2697 6175 : profile_count sum = profile_count::zero ();
2698 14216 : for (edge = callers; edge; edge = edge->next_caller)
2699 : {
2700 8041 : fprintf (f, "%s ", edge->caller->dump_asm_name ());
2701 8041 : edge->dump_edge_flags (f);
2702 8041 : if (edge->count.initialized_p ())
2703 7769 : sum += edge->count.ipa ();
2704 : }
2705 :
2706 6175 : fprintf (f, "\n Calls: ");
2707 20691 : for (edge = callees; edge; edge = edge->next_callee)
2708 : {
2709 14516 : fprintf (f, "%s ", edge->callee->dump_asm_name ());
2710 14516 : edge->dump_edge_flags (f);
2711 : }
2712 6175 : fprintf (f, "\n");
2713 :
2714 6175 : 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 6944 : for (edge = indirect_calls; edge; edge = edge->next_callee)
2745 : {
2746 769 : fprintf (f, " ");
2747 769 : edge->indirect_info->dump (f);
2748 : }
2749 6175 : }
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 916 : cgraph_indirect_call_info::dump (FILE *f, bool newline) const
2792 : {
2793 916 : if (const cgraph_polymorphic_indirect_info *pii
2794 916 : = 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 404 : else if (const cgraph_simple_indirect_info *sii
2806 404 : = dyn_cast <const cgraph_simple_indirect_info *> (this))
2807 : {
2808 404 : if (sii->agg_contents)
2809 49 : fprintf (f, " indirect %s callsite, calling param %i, "
2810 : "offset " HOST_WIDE_INT_PRINT_DEC ", %s",
2811 49 : sii->member_ptr ? "member ptr" : "aggregate",
2812 49 : sii->param_index, sii->offset,
2813 49 : sii->by_ref ? "by reference" : "by_value");
2814 355 : else if (sii->param_index >= 0)
2815 8 : 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 916 : fprintf (f, ", flags %i, num speculative call targets: %i", ecf_flags,
2825 916 : num_speculative_call_targets);
2826 916 : if (newline)
2827 769 : fprintf (f, "\n");
2828 916 : }
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 100638908 : cgraph_function_possibly_inlined_p (tree decl)
2842 : {
2843 100638908 : if (!symtab->global_info_ready)
2844 92709239 : return !DECL_UNINLINABLE (decl);
2845 7929669 : 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 843291532 : cgraph_node::get_availability (symtab_node *ref)
2852 : {
2853 843291532 : if (ref)
2854 : {
2855 592729327 : cgraph_node *cref = dyn_cast <cgraph_node *> (ref);
2856 592729327 : if (cref)
2857 592729327 : ref = cref->inlined_to;
2858 : }
2859 843291532 : enum availability avail;
2860 843291532 : if (!analyzed && !in_other_partition)
2861 500594526 : avail = AVAIL_NOT_AVAILABLE;
2862 342697006 : else if (local)
2863 100226153 : avail = AVAIL_LOCAL;
2864 242470853 : else if (inlined_to)
2865 2156368 : avail = AVAIL_AVAILABLE;
2866 240314485 : else if (transparent_alias)
2867 134 : ultimate_alias_target (&avail, ref);
2868 240314351 : else if (ifunc_resolver
2869 240314351 : || lookup_attribute ("noipa", DECL_ATTRIBUTES (decl)))
2870 4610867 : avail = AVAIL_INTERPOSABLE;
2871 235703484 : else if (!externally_visible)
2872 30793569 : 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 20279 : else if ((this == ref && !has_aliases_p ())
2879 204910634 : || (ref && get_comdat_group ()
2880 1188993 : && get_comdat_group () == ref->get_comdat_group ()))
2881 23022 : 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 204886893 : else if (DECL_DECLARED_INLINE_P (decl))
2886 74879968 : 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 130006925 : else if (decl_replaceable_p (decl, semantic_interposition)
2895 130006925 : && !DECL_EXTERNAL (decl))
2896 9291720 : avail = AVAIL_INTERPOSABLE;
2897 120715205 : else avail = AVAIL_AVAILABLE;
2898 :
2899 843291532 : return avail;
2900 : }
2901 :
2902 : /* Worker for cgraph_node_can_be_local_p. */
2903 : static bool
2904 786966 : cgraph_node_cannot_be_local_p_1 (cgraph_node *node, void *)
2905 : {
2906 786966 : return !(!node->force_output
2907 765703 : && !node->ref_by_asm
2908 765699 : && !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 765659 : && !node->symver
2912 765659 : && ((DECL_COMDAT (node->decl)
2913 307586 : && !node->forced_by_abi
2914 289541 : && !node->used_from_object_file_p ()
2915 289541 : && !node->same_comdat_group)
2916 517792 : || !node->externally_visible)
2917 401793 : && !DECL_STATIC_CONSTRUCTOR (node->decl)
2918 399894 : && !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 1064244 : cgraph_node::can_be_local_p (void)
2927 : {
2928 1064244 : return (!address_taken
2929 1064244 : && !call_for_symbol_thunks_and_aliases (cgraph_node_cannot_be_local_p_1,
2930 1064244 : 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 164491571 : 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 164491571 : cgraph_edge *e;
2945 164491571 : ipa_ref *ref;
2946 164491571 : enum availability avail = AVAIL_AVAILABLE;
2947 :
2948 164491571 : if (include_overwritable
2949 164491571 : || (avail = get_availability ()) > AVAIL_INTERPOSABLE)
2950 : {
2951 164480420 : if (callback (this, data))
2952 : return true;
2953 : }
2954 175281770 : FOR_EACH_ALIAS (this, ref)
2955 : {
2956 16212960 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
2957 16212960 : if (include_overwritable
2958 16212960 : || alias->get_availability () > AVAIL_INTERPOSABLE)
2959 16212858 : if (alias->call_for_symbol_thunks_and_aliases (callback, data,
2960 : include_overwritable,
2961 : exclude_virtual_thunks))
2962 : return true;
2963 : }
2964 159068810 : if (avail <= AVAIL_INTERPOSABLE)
2965 : return false;
2966 165470079 : for (e = callers; e; e = e->next_caller)
2967 6412420 : if (e->caller->thunk
2968 2628 : && (include_overwritable
2969 211 : || e->caller->get_availability () > AVAIL_INTERPOSABLE)
2970 6415048 : && !(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 993553 : set_nothrow_flag_1 (cgraph_node *node, bool nothrow, bool non_call,
3015 : bool *changed)
3016 : {
3017 993553 : cgraph_edge *e;
3018 :
3019 993553 : 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 993528 : if (!non_call || node->binds_to_current_def_p ())
3024 : {
3025 988610 : TREE_NOTHROW (node->decl) = true;
3026 988610 : *changed = true;
3027 2416114 : for (e = node->callers; e; e = e->next_caller)
3028 1427504 : 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 993553 : ipa_ref *ref;
3037 1049091 : FOR_EACH_ALIAS (node, ref)
3038 : {
3039 55538 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
3040 55538 : if (!nothrow || alias->get_availability () > AVAIL_INTERPOSABLE)
3041 55113 : set_nothrow_flag_1 (alias, nothrow, non_call, changed);
3042 : }
3043 2457956 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
3044 1464403 : if (e->caller->thunk
3045 1464403 : && (!nothrow || e->caller->get_availability () > AVAIL_INTERPOSABLE))
3046 138 : set_nothrow_flag_1 (e->caller, nothrow, non_call, changed);
3047 993553 : }
3048 :
3049 : /* Set TREE_NOTHROW on NODE's decl and on aliases of NODE
3050 : if any to NOTHROW. */
3051 :
3052 : bool
3053 945621 : cgraph_node::set_nothrow_flag (bool nothrow)
3054 : {
3055 945621 : bool changed = false;
3056 945621 : bool non_call = opt_for_fn (decl, flag_non_call_exceptions);
3057 :
3058 945621 : if (!nothrow || get_availability () > AVAIL_INTERPOSABLE)
3059 938195 : 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 945621 : return changed;
3072 : }
3073 :
3074 : /* Worker to set malloc flag. */
3075 : static void
3076 30049 : set_malloc_flag_1 (cgraph_node *node, bool malloc_p, bool *changed)
3077 : {
3078 30049 : if (malloc_p && !DECL_IS_MALLOC (node->decl))
3079 : {
3080 29645 : DECL_IS_MALLOC (node->decl) = true;
3081 29645 : *changed = true;
3082 : }
3083 :
3084 30049 : ipa_ref *ref;
3085 30050 : 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 62174 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
3093 32125 : if (e->caller->thunk
3094 32125 : && (!malloc_p || e->caller->get_availability () > AVAIL_INTERPOSABLE))
3095 0 : set_malloc_flag_1 (e->caller, malloc_p, changed);
3096 30049 : }
3097 :
3098 : /* Set DECL_IS_MALLOC on NODE's decl and on NODE's aliases if any. */
3099 :
3100 : bool
3101 30048 : cgraph_node::set_malloc_flag (bool malloc_p)
3102 : {
3103 30048 : bool changed = false;
3104 :
3105 30048 : if (!malloc_p || get_availability () > AVAIL_INTERPOSABLE)
3106 30048 : 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 30048 : return changed;
3119 : }
3120 :
3121 : /* Worker to set malloc flag. */
3122 : static void
3123 248495 : add_detected_attribute_1 (cgraph_node *node, const char *attr, bool *changed)
3124 : {
3125 248495 : if (!lookup_attribute (attr, DECL_ATTRIBUTES (node->decl)))
3126 : {
3127 224055 : DECL_ATTRIBUTES (node->decl) = tree_cons (get_identifier (attr),
3128 224055 : NULL_TREE, DECL_ATTRIBUTES (node->decl));
3129 224055 : *changed = true;
3130 : }
3131 :
3132 248495 : ipa_ref *ref;
3133 249060 : FOR_EACH_ALIAS (node, ref)
3134 : {
3135 565 : cgraph_node *alias = dyn_cast<cgraph_node *> (ref->referring);
3136 565 : if (alias->get_availability () > AVAIL_INTERPOSABLE)
3137 134 : add_detected_attribute_1 (alias, attr, changed);
3138 : }
3139 :
3140 802090 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
3141 553595 : if (e->caller->thunk
3142 553595 : && (e->caller->get_availability () > AVAIL_INTERPOSABLE))
3143 17 : add_detected_attribute_1 (e->caller, attr, changed);
3144 248495 : }
3145 :
3146 : /* Add attribute ATTR to function and its aliases. */
3147 :
3148 : bool
3149 252260 : cgraph_node::add_detected_attribute (const char *attr)
3150 : {
3151 252260 : bool changed = false;
3152 :
3153 252260 : if (get_availability () > AVAIL_INTERPOSABLE)
3154 248344 : 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 252260 : return changed;
3167 : }
3168 :
3169 : /* Worker to set noreturng flag. */
3170 : static void
3171 27683 : set_noreturn_flag_1 (cgraph_node *node, bool noreturn_p, bool *changed)
3172 : {
3173 27683 : if (noreturn_p && !TREE_THIS_VOLATILE (node->decl))
3174 : {
3175 27683 : TREE_THIS_VOLATILE (node->decl) = true;
3176 27683 : *changed = true;
3177 : }
3178 :
3179 27683 : ipa_ref *ref;
3180 28329 : 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 43980 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
3188 16297 : if (e->caller->thunk
3189 16297 : && (!noreturn_p || e->caller->get_availability () > AVAIL_INTERPOSABLE))
3190 20 : set_noreturn_flag_1 (e->caller, noreturn_p, changed);
3191 27683 : }
3192 :
3193 : /* Set TREE_THIS_VOLATILE on NODE's decl and on NODE's aliases if any. */
3194 :
3195 : bool
3196 27025 : cgraph_node::set_noreturn_flag (bool noreturn_p)
3197 : {
3198 27025 : bool changed = false;
3199 :
3200 27025 : if (!noreturn_p || get_availability () > AVAIL_INTERPOSABLE)
3201 27008 : 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 27025 : return changed;
3214 : }
3215 :
3216 : /* Worker to set_const_flag. */
3217 :
3218 : static void
3219 1002018 : 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 1002018 : if (set_const && !looping)
3225 : {
3226 995524 : if (DECL_STATIC_CONSTRUCTOR (node->decl))
3227 : {
3228 239 : DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
3229 239 : *changed = true;
3230 : }
3231 995524 : if (DECL_STATIC_DESTRUCTOR (node->decl))
3232 : {
3233 1 : DECL_STATIC_DESTRUCTOR (node->decl) = 0;
3234 1 : *changed = true;
3235 : }
3236 : }
3237 1002018 : 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 999316 : if (TREE_READONLY (node->decl))
3266 : {
3267 733 : if (!looping && DECL_LOOPING_CONST_OR_PURE_P (node->decl))
3268 : {
3269 388 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
3270 388 : *changed = true;
3271 : }
3272 : }
3273 998583 : else if (node->binds_to_current_def_p ())
3274 : {
3275 176138 : TREE_READONLY (node->decl) = true;
3276 176138 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
3277 176138 : DECL_PURE_P (node->decl) = false;
3278 176138 : *changed = true;
3279 : }
3280 : else
3281 : {
3282 822445 : 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 822445 : if (!DECL_PURE_P (node->decl))
3286 : {
3287 391998 : DECL_PURE_P (node->decl) = true;
3288 391998 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
3289 391998 : *changed = true;
3290 : }
3291 430447 : 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 1002018 : ipa_ref *ref;
3300 1108954 : FOR_EACH_ALIAS (node, ref)
3301 : {
3302 106936 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
3303 106936 : if (!set_const || alias->get_availability () > AVAIL_INTERPOSABLE)
3304 106873 : set_const_flag_1 (alias, set_const, looping, changed);
3305 : }
3306 1002114 : 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 2720724 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
3310 1718706 : if (e->caller->thunk
3311 1718706 : && (!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 1002018 : }
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 922653 : cgraph_node::set_const_flag (bool set_const, bool looping)
3335 : {
3336 922653 : bool changed = false;
3337 922653 : if (!set_const || get_availability () > AVAIL_INTERPOSABLE)
3338 894579 : set_const_flag_1 (this, set_const, looping, &changed);
3339 : else
3340 : {
3341 : ipa_ref *ref;
3342 :
3343 28990 : 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 922653 : 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 371380 : set_pure_flag_1 (cgraph_node *node, void *data)
3366 : {
3367 371380 : 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 371380 : if (info->pure && !info->looping)
3371 : {
3372 302905 : if (DECL_STATIC_CONSTRUCTOR (node->decl))
3373 : {
3374 0 : DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
3375 0 : info->changed = true;
3376 : }
3377 302905 : if (DECL_STATIC_DESTRUCTOR (node->decl))
3378 : {
3379 0 : DECL_STATIC_DESTRUCTOR (node->decl) = 0;
3380 0 : info->changed = true;
3381 : }
3382 : }
3383 371380 : if (info->pure)
3384 : {
3385 368678 : if (!DECL_PURE_P (node->decl) && !TREE_READONLY (node->decl))
3386 : {
3387 368147 : DECL_PURE_P (node->decl) = true;
3388 368147 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = info->looping;
3389 368147 : info->changed = true;
3390 : }
3391 531 : else if (DECL_LOOPING_CONST_OR_PURE_P (node->decl)
3392 531 : && !info->looping)
3393 : {
3394 262 : DECL_LOOPING_CONST_OR_PURE_P (node->decl) = false;
3395 262 : 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 371380 : 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 381519 : cgraph_node::set_pure_flag (bool pure, bool looping)
3418 : {
3419 381519 : struct set_pure_flag_info info = {pure, looping, false};
3420 381519 : call_for_symbol_thunks_and_aliases (set_pure_flag_1, &info, !pure, true);
3421 381519 : 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 381519 : 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 14896770 : cgraph_node::cannot_return_p (void)
3432 : {
3433 14896770 : int flags = flags_from_decl_or_type (decl);
3434 14896770 : if (!opt_for_fn (decl, flag_exceptions))
3435 4830197 : return (flags & ECF_NORETURN) != 0;
3436 : else
3437 10066573 : return ((flags & (ECF_NORETURN | ECF_NOTHROW))
3438 10066573 : == (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 3158787 : cgraph_edge::cannot_lead_to_return_p (void)
3448 : {
3449 3158787 : if (caller->cannot_return_p ())
3450 : return true;
3451 3068773 : if (indirect_unknown_callee)
3452 : {
3453 87454 : int flags = indirect_info->ecf_flags;
3454 87454 : if (!opt_for_fn (caller->decl, flag_exceptions))
3455 20343 : return (flags & ECF_NORETURN) != 0;
3456 : else
3457 67111 : return ((flags & (ECF_NORETURN | ECF_NOTHROW))
3458 67111 : == (ECF_NORETURN | ECF_NOTHROW));
3459 : }
3460 : else
3461 2981319 : 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 5741489 : cgraph_edge::maybe_hot_p (sreal scale)
3469 : {
3470 : /* Never consider calls in functions optimized for size hot. */
3471 5741489 : if (opt_for_fn (caller->decl, optimize_size))
3472 : return false;
3473 :
3474 : /* If reliable IPA count is available, just use it. */
3475 5676102 : profile_count c = count.ipa ();
3476 5676102 : if (c.reliable_p ()
3477 5676102 : || (c.quality () == AFDO && c.nonzero_p ()))
3478 798139 : 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 4877963 : if ((c.quality () == AFDO
3483 4877963 : || count.quality () == GUESSED_GLOBAL0_ADJUSTED)
3484 4877963 : && 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 4877963 : if (caller->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
3489 4873693 : || (callee
3490 4459667 : && callee->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED))
3491 : return false;
3492 4871413 : if (caller->frequency > NODE_FREQUENCY_UNLIKELY_EXECUTED
3493 4871413 : && (callee
3494 4457387 : && 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 4812874 : if (caller->frequency == NODE_FREQUENCY_HOT)
3503 : return true;
3504 :
3505 : /* Use IPA count and if it s not available apply local heuristics. */
3506 4812872 : 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 4812872 : if (!count.initialized_p ())
3516 : return true;
3517 3508043 : cgraph_node *where = caller->inlined_to ? caller->inlined_to : caller;
3518 3508043 : if (!where->count.initialized_p ())
3519 : return true;
3520 3508043 : c = count * scale;
3521 3508043 : if (caller->frequency == NODE_FREQUENCY_EXECUTED_ONCE)
3522 : {
3523 78821 : if (c * 2 < where->count * 3)
3524 20615 : return false;
3525 : }
3526 3429222 : else if (c * param_hot_bb_frequency_fraction < where->count)
3527 393087 : return false;
3528 : return true;
3529 : }
3530 :
3531 : /* Return true if the edge may be considered hot. */
3532 :
3533 : bool
3534 2288695 : cgraph_edge::maybe_hot_p ()
3535 : {
3536 2288695 : return maybe_hot_p (1);
3537 : }
3538 :
3539 : /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
3540 :
3541 : static bool
3542 701621 : nonremovable_p (cgraph_node *node, void *)
3543 : {
3544 701621 : 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 948612 : cgraph_node::can_remove_if_no_direct_calls_p (bool will_inline)
3552 : {
3553 948612 : 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 948612 : if (!externally_visible || !same_comdat_group)
3558 : {
3559 707286 : if (DECL_EXTERNAL (decl))
3560 : return true;
3561 707286 : if (address_taken)
3562 : return false;
3563 674504 : return !call_for_symbol_and_aliases (nonremovable_p, NULL, true);
3564 : }
3565 :
3566 241326 : 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 241326 : 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 464602 : for (int i = 0; iterate_referring (i, ref); i++)
3577 236264 : if (ref->referring->get_comdat_group () != get_comdat_group ())
3578 : return false;
3579 :
3580 228338 : struct cgraph_node *target = ultimate_alias_target ();
3581 456676 : for (cgraph_node *next = dyn_cast<cgraph_node *> (same_comdat_group);
3582 687552 : next != this; next = dyn_cast<cgraph_node *> (next->same_comdat_group))
3583 : {
3584 241591 : if (!externally_visible)
3585 0 : continue;
3586 241591 : if (!next->alias
3587 241591 : && !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 241591 : if (next->ultimate_alias_target () != target)
3592 22092 : for (cgraph_edge *e = next->callers; e; e = e->next_caller)
3593 4891 : if (e->caller->get_comdat_group () != get_comdat_group ()
3594 4891 : || 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 239716 : if (!will_inline)
3600 240884 : for (int i = 0; next->iterate_referring (i, ref); i++)
3601 11277 : 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 3212257 : cgraph_node::will_be_removed_from_program_if_no_direct_calls_p
3623 : (bool will_inline)
3624 : {
3625 3212257 : gcc_assert (!inlined_to);
3626 3212257 : if (DECL_EXTERNAL (decl))
3627 : return true;
3628 :
3629 3212257 : 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 2993737 : if (!only_called_directly_p ())
3635 : return false;
3636 771593 : 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 218520 : 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 16550715 : cgraph_not_only_called_directly_p_1 (cgraph_node *node, void *)
3672 : {
3673 16550715 : 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 16333662 : cgraph_node::only_called_directly_p (void)
3683 : {
3684 16333662 : gcc_assert (ultimate_alias_target () == this);
3685 16333662 : return !call_for_symbol_and_aliases (cgraph_not_only_called_directly_p_1,
3686 16333662 : 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 140371 : collect_callers_of_node_1 (cgraph_node *node, void *data)
3704 : {
3705 140371 : vec<cgraph_edge *> *redirect_callers = (vec<cgraph_edge *> *)data;
3706 140371 : cgraph_edge *cs;
3707 140371 : enum availability avail;
3708 140371 : node->ultimate_alias_target (&avail);
3709 :
3710 140371 : if (avail > AVAIL_INTERPOSABLE)
3711 480819 : for (cs = node->callers; cs != NULL; cs = cs->next_caller)
3712 340448 : if (!cs->indirect_inlining_edge
3713 340448 : && !cs->caller->thunk)
3714 340448 : redirect_callers->safe_push (cs);
3715 140371 : 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 139142 : cgraph_node::collect_callers (void)
3723 : {
3724 139142 : auto_vec<cgraph_edge *> redirect_callers;
3725 139142 : call_for_symbol_thunks_and_aliases (collect_callers_of_node_1,
3726 : &redirect_callers, false);
3727 139142 : 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 27353 : clone_of_p (cgraph_node *node, cgraph_node *node2)
3736 : {
3737 27353 : node = node->ultimate_alias_target ();
3738 27353 : node2 = node2->ultimate_alias_target ();
3739 :
3740 27353 : if (node2->clone_of == node
3741 2351 : || node2->former_clone_of == node->decl)
3742 : return true;
3743 :
3744 2351 : if (!node->thunk && !node->former_thunk_p ())
3745 : {
3746 : while (node2
3747 7052 : && node->decl != node2->decl
3748 11754 : && node->decl != node2->former_clone_of)
3749 4701 : node2 = node2->clone_of;
3750 2351 : 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 204714823 : cgraph_edge::verify_count ()
3790 : {
3791 204714823 : bool error_found = false;
3792 204714823 : if (!count.verify ())
3793 : {
3794 0 : error ("caller edge count invalid");
3795 0 : error_found = true;
3796 : }
3797 204714823 : 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 100843389 : cgraph_edge::verify_corresponds_to_fndecl (tree decl)
3824 : {
3825 100843389 : cgraph_node *node;
3826 :
3827 100843389 : if (!decl || callee->inlined_to)
3828 : return false;
3829 97008682 : if (symtab->state == LTO_STREAMING)
3830 : return false;
3831 97008682 : 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 97008682 : if (!node
3838 96927771 : || node->body_removed
3839 95936243 : || node->in_other_partition
3840 95936243 : || callee->icf_merged
3841 95828027 : || callee->in_other_partition)
3842 : return false;
3843 :
3844 95828027 : 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 95828027 : if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE,
3850 : BUILT_IN_UNREACHABLE_TRAP))
3851 : return false;
3852 :
3853 92880197 : if (callee->former_clone_of != node->decl
3854 92878656 : && (node != callee->ultimate_alias_target ())
3855 92907550 : && !clone_of_p (node, callee))
3856 : return true;
3857 : else
3858 92880197 : 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 445401 : verify_speculative_call (struct cgraph_node *node, gimple *stmt,
3879 : unsigned int lto_stmt_uid,
3880 : struct cgraph_edge *indirect)
3881 : {
3882 445401 : if (indirect == NULL)
3883 : {
3884 536920 : for (indirect = node->indirect_calls; indirect;
3885 210528 : indirect = indirect->next_callee)
3886 536920 : if (indirect->call_stmt == stmt
3887 326558 : && indirect->lto_stmt_uid == lto_stmt_uid)
3888 : break;
3889 326392 : if (!indirect)
3890 : {
3891 0 : error ("missing indirect call in speculative call sequence");
3892 0 : return true;
3893 : }
3894 326392 : 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 30585313 : for (unsigned int i = 0; i < num; i++)
3910 : {
3911 30466304 : direct_calls[i] = NULL;
3912 30466304 : refs[i] = NULL;
3913 : }
3914 :
3915 119009 : cgraph_edge *first_call = NULL;
3916 119009 : cgraph_edge *prev_call = NULL;
3917 :
3918 1377996 : for (cgraph_edge *direct = node->callees; direct;
3919 1258987 : direct = direct->next_callee)
3920 1258987 : if (direct->call_stmt == stmt && direct->lto_stmt_uid == lto_stmt_uid)
3921 : {
3922 163196 : if (!first_call)
3923 119009 : first_call = direct;
3924 163196 : if (prev_call && direct != prev_call->next_callee)
3925 : {
3926 0 : error ("speculative edges are not adjacent");
3927 0 : return true;
3928 : }
3929 163196 : prev_call = direct;
3930 163196 : 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 163196 : 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 163196 : 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 163196 : direct_calls[direct->speculative_id] = direct;
3951 : }
3952 :
3953 119009 : if (first_call->call_stmt
3954 119009 : && 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 1573554 : for (int i = 0; node->iterate_reference (i, ref); i++)
3963 1454545 : if (ref->speculative
3964 282978 : && ref->stmt == stmt && ref->lto_stmt_uid == lto_stmt_uid)
3965 : {
3966 163196 : 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 163196 : 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 163196 : refs[ref->speculative_id] = ref;
3981 : }
3982 :
3983 : int num_targets = 0;
3984 30585313 : for (unsigned int i = 0 ; i < num ; i++)
3985 : {
3986 30466304 : if (refs[i] && !direct_calls[i])
3987 : {
3988 0 : error ("missing direct call for speculation %i", i);
3989 0 : return true;
3990 : }
3991 30466304 : if (!refs[i] && direct_calls[i])
3992 : {
3993 0 : error ("missing ref for speculation %i", i);
3994 0 : return true;
3995 : }
3996 30466304 : if (refs[i] != NULL)
3997 163196 : num_targets++;
3998 : }
3999 :
4000 119009 : 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 53500268 : cgraph_node::verify_node (void)
4014 : {
4015 53500268 : cgraph_edge *e;
4016 53500268 : function *this_cfun = DECL_STRUCT_FUNCTION (decl);
4017 53500268 : basic_block this_block;
4018 53500268 : gimple_stmt_iterator gsi;
4019 53500268 : bool error_found = false;
4020 53500268 : int i;
4021 53500268 : ipa_ref *ref = NULL;
4022 :
4023 53500268 : if (seen_error ())
4024 53500268 : return;
4025 :
4026 53500268 : timevar_push (TV_CGRAPH_VERIFY);
4027 53500268 : error_found |= verify_base ();
4028 163532869 : for (e = callees; e; e = e->next_callee)
4029 110032601 : 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 53500268 : if (!count.verify ())
4037 : {
4038 0 : error ("cgraph count invalid");
4039 0 : error_found = true;
4040 : }
4041 53500268 : if (inlined_to && same_comdat_group)
4042 : {
4043 0 : error ("inline clone in same comdat group list");
4044 0 : error_found = true;
4045 : }
4046 53500268 : 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 53500268 : if (tp_first_run < 0)
4054 : {
4055 0 : error ("tp_first_run must be non-negative");
4056 0 : error_found = true;
4057 : }
4058 53500268 : if (!definition && !in_other_partition && local)
4059 : {
4060 0 : error ("local symbols must be defined");
4061 0 : error_found = true;
4062 : }
4063 53500268 : if (inlined_to && externally_visible)
4064 : {
4065 0 : error ("externally visible inline clone");
4066 0 : error_found = true;
4067 : }
4068 53500268 : if (inlined_to && address_taken)
4069 : {
4070 0 : error ("inline clone with address taken");
4071 0 : error_found = true;
4072 : }
4073 53500268 : if (inlined_to && force_output)
4074 : {
4075 0 : error ("inline clone is forced to output");
4076 0 : error_found = true;
4077 : }
4078 53500268 : if (inlined_to && ref_by_asm)
4079 : {
4080 0 : error ("inline clone is referenced by assembly");
4081 0 : error_found = true;
4082 : }
4083 53500268 : if (symtab->state != LTO_STREAMING)
4084 : {
4085 53386900 : 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 53386900 : 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 53500268 : if (DECL_IS_MALLOC (decl)
4097 53500268 : && !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 53500268 : if (definition
4104 36224767 : && 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 19530235 : && (!alias || !in_lto_p)
4108 53500268 : && semantic_interposition
4109 19527304 : != opt_for_fn (decl, flag_semantic_interposition))
4110 : {
4111 0 : error ("semantic interposition mismatch");
4112 0 : error_found = true;
4113 : }
4114 55875739 : for (e = indirect_calls; e; e = e->next_callee)
4115 : {
4116 2375471 : 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 2375471 : 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 2375471 : 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 2375471 : if (!e->indirect_unknown_callee
4137 2375471 : || !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 2375471 : 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 53500268 : bool check_comdat = comdat_local_p ();
4152 145807019 : for (e = callers; e; e = e->next_caller)
4153 : {
4154 92306751 : if (e->verify_count ())
4155 0 : error_found = true;
4156 92306751 : if (check_comdat
4157 92306751 : && !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 92306751 : if (!e->inline_failed)
4164 : {
4165 8574646 : if (inlined_to
4166 8574646 : != (e->caller->inlined_to
4167 8574646 : ? e->caller->inlined_to : e->caller))
4168 : {
4169 0 : error ("inlined_to pointer is wrong");
4170 0 : error_found = true;
4171 : }
4172 8574646 : if (callers->next_caller)
4173 : {
4174 0 : error ("multiple inline callers");
4175 0 : error_found = true;
4176 : }
4177 : }
4178 : else
4179 83732105 : if (inlined_to)
4180 : {
4181 0 : error ("inlined_to pointer set for noninline callers");
4182 0 : error_found = true;
4183 : }
4184 : }
4185 163532869 : for (e = callees; e; e = e->next_callee)
4186 : {
4187 110032601 : if (e->verify_count ())
4188 0 : error_found = true;
4189 110032601 : 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 110032601 : if (gimple_has_body_p (e->caller->decl)
4197 103210141 : && !e->caller->inlined_to
4198 93973291 : && !e->speculative
4199 93916609 : && !e->callback
4200 93893549 : && !e->has_callback
4201 : /* Optimized out calls are redirected to __builtin_unreachable. */
4202 93804629 : && (e->count.nonzero_p ()
4203 54394571 : || ! e->callee->decl
4204 54394571 : || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
4205 : BUILT_IN_UNREACHABLE_TRAP))
4206 : && count
4207 92015236 : == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
4208 202039666 : && (!e->count.ipa_p ()
4209 41382147 : && 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 110032601 : 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 110032601 : if (e->speculative
4225 110032601 : && verify_speculative_call (e->caller, e->call_stmt, e->lto_stmt_uid,
4226 : NULL))
4227 : error_found = true;
4228 110032601 : 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 110032601 : if (e->callback)
4234 : {
4235 24604 : cgraph_edge *carrying = e->get_callback_carrying_edge ();
4236 24604 : 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 23503 : 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 110032601 : if (e->has_callback
4253 97130 : && !callback_is_special_cased (e->callee->decl, e->call_stmt)
4254 110118812 : && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
4255 : {
4256 86199 : int ncallbacks = 0;
4257 86199 : int nfound_edges = 0;
4258 86199 : for (tree cb = lookup_attribute ("callback_only",
4259 86199 : DECL_ATTRIBUTES (e->callee->decl));
4260 172411 : cb; cb = lookup_attribute ("callback_only", TREE_CHAIN (cb)),
4261 : ncallbacks++)
4262 : ;
4263 767662 : for (cgraph_edge *cbe = callees; cbe; cbe = cbe->next_callee)
4264 : {
4265 681463 : if (cbe->callback && cbe->call_stmt == e->call_stmt
4266 20123 : && cbe->lto_stmt_uid == e->lto_stmt_uid)
4267 : {
4268 20123 : nfound_edges++;
4269 : }
4270 : }
4271 86199 : 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 : }
4279 : }
4280 110032601 : if (e->has_callback
4281 110032601 : && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
4282 12 : for (cgraph_edge *cbe = e->first_callback_edge (); cbe;
4283 0 : cbe = cbe->next_callback_edge ())
4284 0 : if (!fndecl_built_in_p (cbe->callee->decl, BUILT_IN_UNREACHABLE))
4285 0 : error ("callback-carrying edge is pointing towards "
4286 : "__builtin_unreachable, but its callback edge %s -> %s "
4287 : "is not",
4288 0 : cbe->caller->name (), cbe->callee->name ());
4289 : }
4290 55875739 : for (e = indirect_calls; e; e = e->next_callee)
4291 : {
4292 2375471 : if (e->verify_count ())
4293 0 : error_found = true;
4294 2375471 : if (gimple_has_body_p (e->caller->decl)
4295 2327723 : && !e->caller->inlined_to
4296 2081780 : && !e->speculative
4297 2039934 : && e->count.ipa_p ()
4298 : && count
4299 771302 : == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
4300 3146769 : && (!e->count.ipa_p ()
4301 0 : && e->count.differs_from_p (gimple_bb (e->call_stmt)->count)))
4302 : {
4303 0 : error ("indirect call count does not match BB count");
4304 0 : fprintf (stderr, "edge count: ");
4305 0 : e->count.dump (stderr);
4306 0 : fprintf (stderr, "\n bb count: ");
4307 0 : gimple_bb (e->call_stmt)->count.dump (stderr);
4308 0 : fprintf (stderr, "\n");
4309 0 : error_found = true;
4310 : }
4311 2375471 : if (e->speculative
4312 2375471 : && verify_speculative_call (e->caller, e->call_stmt, e->lto_stmt_uid,
4313 : e))
4314 : error_found = true;
4315 : }
4316 121641106 : for (i = 0; iterate_reference (i, ref); i++)
4317 : {
4318 68140838 : if (ref->stmt && ref->lto_stmt_uid)
4319 : {
4320 0 : error ("reference has both stmt and lto_stmt_uid set");
4321 0 : error_found = true;
4322 : }
4323 68140838 : if (ref->speculative
4324 68140838 : && verify_speculative_call (this, ref->stmt,
4325 : ref->lto_stmt_uid, NULL))
4326 : error_found = true;
4327 : }
4328 :
4329 53500268 : if (!callers && inlined_to)
4330 : {
4331 0 : error ("inlined_to pointer is set but no predecessors found");
4332 0 : error_found = true;
4333 : }
4334 53500268 : if (inlined_to == this)
4335 : {
4336 0 : error ("inlined_to pointer refers to itself");
4337 0 : error_found = true;
4338 : }
4339 :
4340 53500268 : if (clone_of)
4341 : {
4342 6285356 : cgraph_node *first_clone = clone_of->clones;
4343 6285356 : if (first_clone != this)
4344 : {
4345 3159135 : if (prev_sibling_clone->clone_of != clone_of)
4346 : {
4347 0 : error ("cgraph_node has wrong clone_of");
4348 0 : error_found = true;
4349 : }
4350 : }
4351 : }
4352 53500268 : if (clones)
4353 : {
4354 : cgraph_node *n;
4355 8366590 : for (n = clones; n; n = n->next_sibling_clone)
4356 6655000 : if (n->clone_of != this)
4357 : break;
4358 1711590 : if (n)
4359 : {
4360 0 : error ("cgraph_node has wrong clone list");
4361 0 : error_found = true;
4362 : }
4363 : }
4364 53500268 : if ((prev_sibling_clone || next_sibling_clone) && !clone_of)
4365 : {
4366 0 : error ("cgraph_node is in clone list but it is not clone");
4367 0 : error_found = true;
4368 : }
4369 53500268 : if (!prev_sibling_clone && clone_of && clone_of->clones != this)
4370 : {
4371 0 : error ("cgraph_node has wrong prev_clone pointer");
4372 0 : error_found = true;
4373 : }
4374 53500268 : if (prev_sibling_clone && prev_sibling_clone->next_sibling_clone != this)
4375 : {
4376 0 : error ("double linked list of clones corrupted");
4377 0 : error_found = true;
4378 : }
4379 :
4380 53500268 : if (analyzed && alias)
4381 : {
4382 1447576 : bool ref_found = false;
4383 1447576 : int i;
4384 1447576 : ipa_ref *ref = NULL;
4385 :
4386 1447576 : if (callees)
4387 : {
4388 0 : error ("Alias has call edges");
4389 0 : error_found = true;
4390 : }
4391 2895152 : for (i = 0; iterate_reference (i, ref); i++)
4392 1447576 : if (ref->use != IPA_REF_ALIAS)
4393 : {
4394 0 : error ("Alias has non-alias reference");
4395 0 : error_found = true;
4396 : }
4397 1447576 : else if (ref_found)
4398 : {
4399 0 : error ("Alias has more than one alias reference");
4400 0 : error_found = true;
4401 : }
4402 : else
4403 : ref_found = true;
4404 1447576 : if (!ref_found)
4405 : {
4406 0 : error ("Analyzed alias has no reference");
4407 0 : error_found = true;
4408 : }
4409 : }
4410 :
4411 53500268 : if (analyzed && thunk)
4412 : {
4413 23304 : if (!callees)
4414 : {
4415 0 : error ("No edge out of thunk node");
4416 0 : error_found = true;
4417 : }
4418 23304 : else if (callees->next_callee)
4419 : {
4420 0 : error ("More than one edge out of thunk node");
4421 0 : error_found = true;
4422 : }
4423 23304 : if (gimple_has_body_p (decl) && !inlined_to)
4424 : {
4425 0 : error ("Thunk is not supposed to have body");
4426 0 : error_found = true;
4427 : }
4428 : }
4429 36199361 : else if (analyzed && gimple_has_body_p (decl)
4430 31209293 : && !TREE_ASM_WRITTEN (decl)
4431 31209293 : && (!DECL_EXTERNAL (decl) || inlined_to)
4432 83657255 : && !flag_wpa)
4433 : {
4434 30153607 : if ((this_cfun->curr_properties & PROP_assumptions_done) != 0)
4435 : ;
4436 30153463 : else if (this_cfun->cfg)
4437 : {
4438 30153463 : hash_set<gimple *> stmts;
4439 :
4440 : /* Reach the trees by walking over the CFG, and note the
4441 : enclosing basic-blocks in the call edges. */
4442 250756673 : FOR_EACH_BB_FN (this_block, this_cfun)
4443 : {
4444 220603210 : for (gsi = gsi_start_phis (this_block);
4445 265993315 : !gsi_end_p (gsi); gsi_next (&gsi))
4446 45390105 : stmts.add (gsi_stmt (gsi));
4447 441206420 : for (gsi = gsi_start_bb (this_block);
4448 1359144048 : !gsi_end_p (gsi);
4449 1138540838 : gsi_next (&gsi))
4450 : {
4451 1138540838 : gimple *stmt = gsi_stmt (gsi);
4452 1138540838 : stmts.add (stmt);
4453 1138540838 : if (is_gimple_call (stmt))
4454 : {
4455 107870076 : cgraph_edge *e = get_edge (stmt);
4456 107870076 : tree decl = gimple_call_fndecl (stmt);
4457 107870076 : if (e)
4458 : {
4459 103040289 : if (e->aux)
4460 : {
4461 0 : error ("shared call_stmt:");
4462 0 : cgraph_debug_gimple_stmt (this_cfun, stmt);
4463 0 : error_found = true;
4464 : }
4465 103040289 : if (!e->indirect_unknown_callee)
4466 : {
4467 : /* Callback edges violate this assertion
4468 : because their call statement doesn't exist,
4469 : their associated statement belongs to the
4470 : callback-dispatching function. */
4471 100844385 : if (!e->callback
4472 100844385 : && e->verify_corresponds_to_fndecl (decl))
4473 : {
4474 0 : error ("edge points to wrong declaration:");
4475 0 : debug_tree (e->callee->decl);
4476 0 : fprintf (stderr," Instead of:");
4477 0 : debug_tree (decl);
4478 0 : error_found = true;
4479 : }
4480 : }
4481 2195904 : else if (decl)
4482 : {
4483 0 : error ("an indirect edge with unknown callee "
4484 : "corresponding to a call_stmt with "
4485 : "a known declaration:");
4486 0 : error_found = true;
4487 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
4488 : }
4489 103040289 : e->aux = (void *)1;
4490 : }
4491 4829787 : else if (decl)
4492 : {
4493 0 : error ("missing callgraph edge for call stmt:");
4494 0 : cgraph_debug_gimple_stmt (this_cfun, stmt);
4495 0 : error_found = true;
4496 : }
4497 : }
4498 : }
4499 : }
4500 102433087 : for (i = 0; iterate_reference (i, ref); i++)
4501 63144651 : if (ref->stmt && !stmts.contains (ref->stmt))
4502 : {
4503 0 : error ("reference to dead statement");
4504 0 : cgraph_debug_gimple_stmt (this_cfun, ref->stmt);
4505 0 : error_found = true;
4506 : }
4507 30153463 : }
4508 : else
4509 : /* No CFG available?! */
4510 0 : gcc_unreachable ();
4511 :
4512 131061851 : for (e = callees; e; e = e->next_callee)
4513 : {
4514 100908244 : if (!e->aux && !e->speculative && !e->callback && !e->has_callback)
4515 : {
4516 0 : error ("edge %s->%s has no corresponding call_stmt",
4517 0 : identifier_to_locale (e->caller->name ()),
4518 0 : identifier_to_locale (e->callee->name ()));
4519 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
4520 0 : error_found = true;
4521 : }
4522 100908244 : e->aux = 0;
4523 : }
4524 32458934 : for (e = indirect_calls; e; e = e->next_callee)
4525 : {
4526 2305327 : if (!e->aux && !e->speculative)
4527 : {
4528 0 : error ("an indirect edge from %s has no corresponding call_stmt",
4529 0 : identifier_to_locale (e->caller->name ()));
4530 0 : cgraph_debug_gimple_stmt (this_cfun, e->call_stmt);
4531 0 : error_found = true;
4532 : }
4533 2305327 : e->aux = 0;
4534 : }
4535 : }
4536 :
4537 53500268 : if (nested_function_info *info = nested_function_info::get (this))
4538 : {
4539 0 : if (info->nested != NULL)
4540 : {
4541 0 : for (cgraph_node *n = info->nested; n != NULL;
4542 0 : n = next_nested_function (n))
4543 : {
4544 0 : nested_function_info *ninfo = nested_function_info::get (n);
4545 0 : if (ninfo->origin == NULL)
4546 : {
4547 0 : error ("missing origin for a node in a nested list");
4548 0 : error_found = true;
4549 : }
4550 0 : else if (ninfo->origin != this)
4551 : {
4552 0 : error ("origin points to a different parent");
4553 0 : error_found = true;
4554 0 : break;
4555 : }
4556 : }
4557 : }
4558 0 : if (info->next_nested != NULL && info->origin == NULL)
4559 : {
4560 0 : error ("missing origin for a node in a nested list");
4561 0 : error_found = true;
4562 : }
4563 : }
4564 :
4565 53500268 : if (error_found)
4566 : {
4567 0 : dump (stderr);
4568 0 : internal_error ("verify_cgraph_node failed");
4569 : }
4570 53500268 : timevar_pop (TV_CGRAPH_VERIFY);
4571 : }
4572 :
4573 : /* Verify whole cgraph structure. */
4574 : DEBUG_FUNCTION void
4575 800 : cgraph_node::verify_cgraph_nodes (void)
4576 : {
4577 800 : cgraph_node *node;
4578 :
4579 800 : if (seen_error ())
4580 : return;
4581 :
4582 5094 : FOR_EACH_FUNCTION (node)
4583 4318 : node->verify ();
4584 : }
4585 :
4586 : #if __GNUC__ >= 10
4587 : # pragma GCC diagnostic pop
4588 : #endif
4589 :
4590 : /* Walk the alias chain to return the function cgraph_node is alias of.
4591 : Walk through thunks, too.
4592 : When AVAILABILITY is non-NULL, get minimal availability in the chain.
4593 : When REF is non-NULL, assume that reference happens in symbol REF
4594 : when determining the availability. */
4595 :
4596 : cgraph_node *
4597 138566020 : cgraph_node::function_symbol (enum availability *availability,
4598 : struct symtab_node *ref)
4599 : {
4600 138566020 : cgraph_node *node = ultimate_alias_target (availability, ref);
4601 :
4602 277137674 : while (node->thunk)
4603 : {
4604 5634 : enum availability a;
4605 :
4606 5634 : ref = node;
4607 5634 : node = node->callees->callee;
4608 9819 : node = node->ultimate_alias_target (availability ? &a : NULL, ref);
4609 5634 : if (availability && a < *availability)
4610 38 : *availability = a;
4611 : }
4612 138566020 : return node;
4613 : }
4614 :
4615 : /* Walk the alias chain to return the function cgraph_node is alias of.
4616 : Walk through non virtual thunks, too. Thus we return either a function
4617 : or a virtual thunk node.
4618 : When AVAILABILITY is non-NULL, get minimal availability in the chain.
4619 : When REF is non-NULL, assume that reference happens in symbol REF
4620 : when determining the availability. */
4621 :
4622 : cgraph_node *
4623 34877498 : cgraph_node::function_or_virtual_thunk_symbol
4624 : (enum availability *availability,
4625 : struct symtab_node *ref)
4626 : {
4627 34877498 : cgraph_node *node = ultimate_alias_target (availability, ref);
4628 :
4629 69756050 : while (node->thunk && !thunk_info::get (node)->virtual_offset_p)
4630 : {
4631 1054 : enum availability a;
4632 :
4633 1054 : ref = node;
4634 1054 : node = node->callees->callee;
4635 1054 : node = node->ultimate_alias_target (availability ? &a : NULL, ref);
4636 1054 : if (availability && a < *availability)
4637 305 : *availability = a;
4638 : }
4639 34877498 : return node;
4640 : }
4641 :
4642 : /* When doing LTO, read cgraph_node's body from disk if it is not already
4643 : present. Also perform any necessary clone materializations. */
4644 :
4645 : bool
4646 6490044 : cgraph_node::get_untransformed_body ()
4647 : {
4648 6490044 : lto_file_decl_data *file_data;
4649 6490044 : const char *data, *name;
4650 6490044 : size_t len;
4651 6490044 : tree decl = this->decl;
4652 :
4653 : /* See if there is clone to be materialized.
4654 : (inline clones does not need materialization, but we can be seeing
4655 : an inline clone of real clone). */
4656 6490044 : cgraph_node *p = this;
4657 9380047 : for (cgraph_node *c = clone_of; c; c = c->clone_of)
4658 : {
4659 2890003 : if (c->decl != decl)
4660 142177 : p->materialize_clone ();
4661 2890003 : p = c;
4662 : }
4663 :
4664 : /* Check if body is already there. Either we have gimple body or
4665 : the function is thunk and in that case we set DECL_ARGUMENTS. */
4666 6490044 : if (DECL_ARGUMENTS (decl) || gimple_has_body_p (decl))
4667 : return false;
4668 :
4669 171796 : gcc_assert (in_lto_p && !DECL_RESULT (decl));
4670 :
4671 85898 : timevar_push (TV_IPA_LTO_GIMPLE_IN);
4672 :
4673 85898 : file_data = lto_file_data;
4674 85898 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4675 :
4676 : /* We may have renamed the declaration, e.g., a static function. */
4677 85898 : name = lto_get_decl_name_mapping (file_data, name);
4678 85898 : struct lto_in_decl_state *decl_state
4679 85898 : = lto_get_function_in_decl_state (file_data, decl);
4680 :
4681 85898 : cgraph_node *origin = this;
4682 172024 : while (origin->clone_of)
4683 : origin = origin->clone_of;
4684 :
4685 85898 : int stream_order = origin->order - file_data->order_base;
4686 85898 : data = lto_get_section_data (file_data, LTO_section_function_body,
4687 : name, stream_order, &len,
4688 : decl_state->compressed);
4689 85898 : if (!data)
4690 0 : fatal_error (input_location, "%s: section %s.%d is missing",
4691 : file_data->file_name, name, stream_order);
4692 :
4693 85898 : gcc_assert (DECL_STRUCT_FUNCTION (decl) == NULL);
4694 :
4695 85898 : if (!quiet_flag)
4696 0 : fprintf (stderr, " in:%s", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4697 85898 : lto_input_function_body (file_data, this, data);
4698 85898 : lto_stats.num_function_bodies++;
4699 85898 : lto_free_section_data (file_data, LTO_section_function_body, name,
4700 : data, len, decl_state->compressed);
4701 85898 : lto_free_function_in_decl_state_for_node (this);
4702 : /* Keep lto file data so ipa-inline-analysis knows about cross module
4703 : inlining. */
4704 :
4705 85898 : timevar_pop (TV_IPA_LTO_GIMPLE_IN);
4706 :
4707 85898 : return true;
4708 : }
4709 :
4710 : /* Prepare function body. When doing LTO, read cgraph_node's body from disk
4711 : if it is not already present. When some IPA transformations are scheduled,
4712 : apply them. */
4713 :
4714 : bool
4715 29087 : cgraph_node::get_body (void)
4716 : {
4717 29087 : bool updated;
4718 :
4719 29087 : updated = get_untransformed_body ();
4720 :
4721 : /* Getting transformed body makes no sense for inline clones;
4722 : we should never use this on real clones because they are materialized
4723 : early.
4724 : TODO: Materializing clones here will likely lead to smaller LTRANS
4725 : footprint. */
4726 29087 : gcc_assert (!inlined_to && !clone_of);
4727 29087 : if (ipa_transforms_to_apply.exists ())
4728 : {
4729 12453 : opt_pass *saved_current_pass = current_pass;
4730 12453 : FILE *saved_dump_file = dump_file;
4731 12453 : const char *saved_dump_file_name = dump_file_name;
4732 12453 : dump_flags_t saved_dump_flags = dump_flags;
4733 12453 : dump_file_name = NULL;
4734 12453 : set_dump_file (NULL);
4735 :
4736 12453 : push_cfun (DECL_STRUCT_FUNCTION (decl));
4737 :
4738 12453 : update_ssa (TODO_update_ssa_only_virtuals);
4739 12453 : execute_all_ipa_transforms (true);
4740 12453 : cgraph_edge::rebuild_edges ();
4741 12453 : free_dominance_info (CDI_DOMINATORS);
4742 12453 : free_dominance_info (CDI_POST_DOMINATORS);
4743 12453 : pop_cfun ();
4744 12453 : updated = true;
4745 :
4746 12453 : current_pass = saved_current_pass;
4747 12453 : set_dump_file (saved_dump_file);
4748 12453 : dump_file_name = saved_dump_file_name;
4749 12453 : dump_flags = saved_dump_flags;
4750 : }
4751 29087 : return updated;
4752 : }
4753 :
4754 : /* Return the DECL_STRUCT_FUNCTION of the function. */
4755 :
4756 : struct function *
4757 112318 : cgraph_node::get_fun () const
4758 : {
4759 112318 : const cgraph_node *node = this;
4760 112318 : struct function *fun = DECL_STRUCT_FUNCTION (node->decl);
4761 :
4762 112318 : while (!fun && node->clone_of)
4763 : {
4764 0 : node = node->clone_of;
4765 0 : fun = DECL_STRUCT_FUNCTION (node->decl);
4766 : }
4767 :
4768 112318 : return fun;
4769 : }
4770 :
4771 : /* Reset all state within cgraph.cc so that we can rerun the compiler
4772 : within the same process. For use by toplev::finalize. */
4773 :
4774 : void
4775 266934 : cgraph_cc_finalize (void)
4776 : {
4777 266934 : nested_function_info::release ();
4778 266934 : thunk_info::release ();
4779 266934 : clone_info::release ();
4780 266934 : callback_info_sum_t::free_info_sum ();
4781 266934 : symtab = NULL;
4782 :
4783 266934 : cgraph_fnver_htab = NULL;
4784 266934 : version_info_node = NULL;
4785 266934 : }
4786 :
4787 : /* A worker for call_for_symbol_and_aliases. */
4788 :
4789 : bool
4790 751432 : cgraph_node::call_for_symbol_and_aliases_1 (bool (*callback) (cgraph_node *,
4791 : void *),
4792 : void *data,
4793 : bool include_overwritable)
4794 : {
4795 751432 : ipa_ref *ref;
4796 1584968 : FOR_EACH_ALIAS (this, ref)
4797 : {
4798 942747 : cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
4799 942747 : if (include_overwritable
4800 942747 : || alias->get_availability () > AVAIL_INTERPOSABLE)
4801 942747 : if (alias->call_for_symbol_and_aliases (callback, data,
4802 : include_overwritable))
4803 : return true;
4804 : }
4805 : return false;
4806 : }
4807 :
4808 : /* Return true if NODE has thunk. */
4809 :
4810 : bool
4811 36598 : cgraph_node::has_thunk_p (cgraph_node *node, void *)
4812 : {
4813 71074 : for (cgraph_edge *e = node->callers; e; e = e->next_caller)
4814 34476 : if (e->caller->thunk)
4815 : return true;
4816 : return false;
4817 : }
4818 :
4819 : /* Expected frequency of executions within the function. */
4820 :
4821 : sreal
4822 213478438 : cgraph_edge::sreal_frequency ()
4823 : {
4824 213478438 : return count.to_sreal_scale (caller->inlined_to
4825 213478438 : ? caller->inlined_to->count
4826 213478438 : : caller->count);
4827 : }
4828 :
4829 : /* Expected frequency of executions within the function.
4830 : If edge is speculative, sum all its indirect targets. */
4831 :
4832 : sreal
4833 4288 : cgraph_edge::combined_sreal_frequency ()
4834 : {
4835 4288 : if (!speculative)
4836 3991 : return sreal_frequency ();
4837 297 : cgraph_edge *e = this;
4838 297 : if (e->callee)
4839 0 : e = e->speculative_call_indirect_edge ();
4840 297 : sreal sum = e->sreal_frequency ();
4841 297 : for (e = e->first_speculative_call_target ();
4842 644 : e;
4843 347 : e = e->next_speculative_call_target ())
4844 347 : sum += e->sreal_frequency ();
4845 297 : return sum;
4846 : }
4847 :
4848 :
4849 : /* During LTO stream in this can be used to check whether call can possibly
4850 : be internal to the current translation unit. */
4851 :
4852 : bool
4853 484724 : cgraph_edge::possibly_call_in_translation_unit_p (void)
4854 : {
4855 484724 : gcc_checking_assert (in_lto_p && caller->prevailing_p ());
4856 :
4857 : /* While incremental linking we may end up getting function body later. */
4858 484724 : if (flag_incremental_link == INCREMENTAL_LINK_LTO)
4859 : return true;
4860 :
4861 : /* We may be smarter here and avoid streaming in indirect calls we can't
4862 : track, but that would require arranging streaming the indirect call
4863 : summary first. */
4864 484457 : if (!callee)
4865 : return true;
4866 :
4867 : /* If callee is local to the original translation unit, it will be
4868 : defined. */
4869 481666 : if (!TREE_PUBLIC (callee->decl) && !DECL_EXTERNAL (callee->decl))
4870 : return true;
4871 :
4872 : /* Otherwise we need to lookup prevailing symbol (symbol table is not merged,
4873 : yet) and see if it is a definition. In fact we may also resolve aliases,
4874 : but that is probably not too important. */
4875 484532 : symtab_node *node = callee;
4876 484532 : for (int n = 10; node->previous_sharing_asm_name && n ; n--)
4877 10185 : node = node->previous_sharing_asm_name;
4878 474347 : if (node->previous_sharing_asm_name)
4879 234 : node = symtab_node::get_for_asmname (DECL_ASSEMBLER_NAME (callee->decl));
4880 474347 : gcc_assert (TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl));
4881 474347 : return node->get_availability () >= AVAIL_INTERPOSABLE;
4882 : }
4883 :
4884 : /* Return num_speculative_targets of this edge. */
4885 :
4886 : int
4887 190815 : cgraph_edge::num_speculative_call_targets_p (void)
4888 : {
4889 190815 : return indirect_info ? indirect_info->num_speculative_call_targets : 0;
4890 : }
4891 :
4892 : /* Check if function calls comdat local. This is used to recompute
4893 : calls_comdat_local flag after function transformations. */
4894 : bool
4895 50121711 : cgraph_node::check_calls_comdat_local_p ()
4896 : {
4897 162952283 : for (cgraph_edge *e = callees; e; e = e->next_callee)
4898 116714890 : if (e->inline_failed
4899 121848148 : ? e->callee->comdat_local_p ()
4900 3828210 : : e->callee->check_calls_comdat_local_p ())
4901 : return true;
4902 : return false;
4903 : }
4904 :
4905 : /* Return true if this node represents a former, i.e. an expanded, thunk. */
4906 :
4907 : bool
4908 5171029 : cgraph_node::former_thunk_p (void)
4909 : {
4910 5171029 : if (thunk)
4911 : return false;
4912 5171029 : thunk_info *i = thunk_info::get (this);
4913 5171029 : if (!i)
4914 : return false;
4915 25 : gcc_checking_assert (i->fixed_offset || i->virtual_offset_p
4916 : || i->indirect_offset);
4917 : return true;
4918 : }
4919 :
4920 : /* A stashed copy of "symtab" for use by selftest::symbol_table_test.
4921 : This needs to be a global so that it can be a GC root, and thus
4922 : prevent the stashed copy from being garbage-collected if the GC runs
4923 : during a symbol_table_test. */
4924 :
4925 : symbol_table *saved_symtab;
4926 :
4927 : #if CHECKING_P
4928 :
4929 : namespace selftest {
4930 :
4931 : /* class selftest::symbol_table_test. */
4932 :
4933 : /* Constructor. Store the old value of symtab, and create a new one. */
4934 :
4935 64 : symbol_table_test::symbol_table_test ()
4936 : {
4937 64 : gcc_assert (saved_symtab == NULL);
4938 64 : saved_symtab = symtab;
4939 64 : symtab = new (ggc_alloc<symbol_table> ()) symbol_table ();
4940 64 : }
4941 :
4942 : /* Destructor. Restore the old value of symtab. */
4943 :
4944 64 : symbol_table_test::~symbol_table_test ()
4945 : {
4946 64 : gcc_assert (saved_symtab != NULL);
4947 64 : symtab = saved_symtab;
4948 64 : saved_symtab = NULL;
4949 64 : }
4950 :
4951 : /* Verify that symbol_table_test works. */
4952 :
4953 : static void
4954 4 : test_symbol_table_test ()
4955 : {
4956 : /* Simulate running two selftests involving symbol tables. */
4957 12 : for (int i = 0; i < 2; i++)
4958 : {
4959 8 : symbol_table_test stt;
4960 8 : tree test_decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
4961 : get_identifier ("test_decl"),
4962 : build_function_type_list (void_type_node,
4963 : NULL_TREE));
4964 8 : cgraph_node *node = cgraph_node::get_create (test_decl);
4965 8 : gcc_assert (node);
4966 :
4967 : /* Verify that the node has order 0 on both iterations,
4968 : and thus that nodes have predictable dump names in selftests. */
4969 8 : ASSERT_EQ (node->order, 0);
4970 8 : ASSERT_STREQ (node->dump_name (), "test_decl/1");
4971 8 : }
4972 4 : }
4973 :
4974 : /* Run all of the selftests within this file. */
4975 :
4976 : void
4977 4 : cgraph_cc_tests ()
4978 : {
4979 4 : test_symbol_table_test ();
4980 4 : }
4981 :
4982 : } // namespace selftest
4983 :
4984 : #endif /* CHECKING_P */
4985 :
4986 : #include "gt-cgraph.h"
|