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