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