2011-04-23 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / cgraph.c
blob8526646728449720ea7dea67ad248940a34c3933
1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This file contains basic routines manipulating call graph
24 The callgraph:
26 The call-graph is data structure designed for intra-procedural optimization
27 but it is also used in non-unit-at-a-time compilation to allow easier code
28 sharing.
30 The call-graph consist of nodes and edges represented via linked lists.
31 Each function (external or not) corresponds to the unique node.
33 The mapping from declarations to call-graph nodes is done using hash table
34 based on DECL_UID. The call-graph nodes are created lazily using
35 cgraph_node function when called for unknown declaration.
37 The callgraph at the moment does not represent all indirect calls or calls
38 from other compilation units. Flag NEEDED is set for each node that may be
39 accessed in such an invisible way and it shall be considered an entry point
40 to the callgraph.
42 On the other hand, the callgraph currently does contain some edges for
43 indirect calls with unknown callees which can be accessed through
44 indirect_calls field of a node. It should be noted however that at the
45 moment only calls which are potential candidates for indirect inlining are
46 added there.
48 Interprocedural information:
50 Callgraph is place to store data needed for interprocedural optimization.
51 All data structures are divided into three components: local_info that
52 is produced while analyzing the function, global_info that is result
53 of global walking of the callgraph on the end of compilation and
54 rtl_info used by RTL backend to propagate data from already compiled
55 functions to their callers.
57 Moreover, each node has a uid which can be used to keep information in
58 on-the-side arrays. UIDs are reused and therefore reasonably dense.
60 Inlining plans:
62 The function inlining information is decided in advance and maintained
63 in the callgraph as so called inline plan.
64 For each inlined call, the callee's node is cloned to represent the
65 new function copy produced by inliner.
66 Each inlined call gets a unique corresponding clone node of the callee
67 and the data structure is updated while inlining is performed, so
68 the clones are eliminated and their callee edges redirected to the
69 caller.
71 Each edge has "inline_failed" field. When the field is set to NULL,
72 the call will be inlined. When it is non-NULL it contains a reason
73 why inlining wasn't performed. */
75 #include "config.h"
76 #include "system.h"
77 #include "coretypes.h"
78 #include "tm.h"
79 #include "tree.h"
80 #include "tree-inline.h"
81 #include "langhooks.h"
82 #include "hashtab.h"
83 #include "toplev.h"
84 #include "flags.h"
85 #include "ggc.h"
86 #include "debug.h"
87 #include "target.h"
88 #include "basic-block.h"
89 #include "cgraph.h"
90 #include "output.h"
91 #include "intl.h"
92 #include "gimple.h"
93 #include "tree-dump.h"
94 #include "tree-flow.h"
95 #include "value-prof.h"
96 #include "except.h"
97 #include "diagnostic-core.h"
98 #include "rtl.h"
99 #include "ipa-utils.h"
100 #include "lto-streamer.h"
101 #include "ipa-inline.h"
103 const char * const ld_plugin_symbol_resolution_names[]=
106 "undef",
107 "prevailing_def",
108 "prevailing_def_ironly",
109 "preempted_reg",
110 "preempted_ir",
111 "resolved_ir",
112 "resolved_exec",
113 "resolved_dyn"
116 static void cgraph_node_remove_callers (struct cgraph_node *node);
117 static inline void cgraph_edge_remove_caller (struct cgraph_edge *e);
118 static inline void cgraph_edge_remove_callee (struct cgraph_edge *e);
120 /* Hash table used to convert declarations into nodes. */
121 static GTY((param_is (struct cgraph_node))) htab_t cgraph_hash;
122 /* Hash table used to convert assembler names into nodes. */
123 static GTY((param_is (struct cgraph_node))) htab_t assembler_name_hash;
125 /* The linked list of cgraph nodes. */
126 struct cgraph_node *cgraph_nodes;
128 /* Queue of cgraph nodes scheduled to be lowered. */
129 struct cgraph_node *cgraph_nodes_queue;
131 /* Queue of cgraph nodes scheduled to be added into cgraph. This is a
132 secondary queue used during optimization to accommodate passes that
133 may generate new functions that need to be optimized and expanded. */
134 struct cgraph_node *cgraph_new_nodes;
136 /* Number of nodes in existence. */
137 int cgraph_n_nodes;
139 /* Maximal uid used in cgraph nodes. */
140 int cgraph_max_uid;
142 /* Maximal uid used in cgraph edges. */
143 int cgraph_edge_max_uid;
145 /* Set when whole unit has been analyzed so we can access global info. */
146 bool cgraph_global_info_ready = false;
148 /* What state callgraph is in right now. */
149 enum cgraph_state cgraph_state = CGRAPH_STATE_CONSTRUCTION;
151 /* Set when the cgraph is fully build and the basic flags are computed. */
152 bool cgraph_function_flags_ready = false;
154 /* Linked list of cgraph asm nodes. */
155 struct cgraph_asm_node *cgraph_asm_nodes;
157 /* Last node in cgraph_asm_nodes. */
158 static GTY(()) struct cgraph_asm_node *cgraph_asm_last_node;
160 /* The order index of the next cgraph node to be created. This is
161 used so that we can sort the cgraph nodes in order by when we saw
162 them, to support -fno-toplevel-reorder. */
163 int cgraph_order;
165 /* List of hooks triggered on cgraph_edge events. */
166 struct cgraph_edge_hook_list {
167 cgraph_edge_hook hook;
168 void *data;
169 struct cgraph_edge_hook_list *next;
172 /* List of hooks triggered on cgraph_node events. */
173 struct cgraph_node_hook_list {
174 cgraph_node_hook hook;
175 void *data;
176 struct cgraph_node_hook_list *next;
179 /* List of hooks triggered on events involving two cgraph_edges. */
180 struct cgraph_2edge_hook_list {
181 cgraph_2edge_hook hook;
182 void *data;
183 struct cgraph_2edge_hook_list *next;
186 /* List of hooks triggered on events involving two cgraph_nodes. */
187 struct cgraph_2node_hook_list {
188 cgraph_2node_hook hook;
189 void *data;
190 struct cgraph_2node_hook_list *next;
193 /* List of hooks triggered when an edge is removed. */
194 struct cgraph_edge_hook_list *first_cgraph_edge_removal_hook;
195 /* List of hooks triggered when a node is removed. */
196 struct cgraph_node_hook_list *first_cgraph_node_removal_hook;
197 /* List of hooks triggered when an edge is duplicated. */
198 struct cgraph_2edge_hook_list *first_cgraph_edge_duplicated_hook;
199 /* List of hooks triggered when a node is duplicated. */
200 struct cgraph_2node_hook_list *first_cgraph_node_duplicated_hook;
201 /* List of hooks triggered when an function is inserted. */
202 struct cgraph_node_hook_list *first_cgraph_function_insertion_hook;
204 /* Head of a linked list of unused (freed) call graph nodes.
205 Do not GTY((delete)) this list so UIDs gets reliably recycled. */
206 static GTY(()) struct cgraph_node *free_nodes;
207 /* Head of a linked list of unused (freed) call graph edges.
208 Do not GTY((delete)) this list so UIDs gets reliably recycled. */
209 static GTY(()) struct cgraph_edge *free_edges;
211 /* Macros to access the next item in the list of free cgraph nodes and
212 edges. */
213 #define NEXT_FREE_NODE(NODE) (NODE)->next
214 #define NEXT_FREE_EDGE(EDGE) (EDGE)->prev_caller
216 /* Register HOOK to be called with DATA on each removed edge. */
217 struct cgraph_edge_hook_list *
218 cgraph_add_edge_removal_hook (cgraph_edge_hook hook, void *data)
220 struct cgraph_edge_hook_list *entry;
221 struct cgraph_edge_hook_list **ptr = &first_cgraph_edge_removal_hook;
223 entry = (struct cgraph_edge_hook_list *) xmalloc (sizeof (*entry));
224 entry->hook = hook;
225 entry->data = data;
226 entry->next = NULL;
227 while (*ptr)
228 ptr = &(*ptr)->next;
229 *ptr = entry;
230 return entry;
233 /* Remove ENTRY from the list of hooks called on removing edges. */
234 void
235 cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *entry)
237 struct cgraph_edge_hook_list **ptr = &first_cgraph_edge_removal_hook;
239 while (*ptr != entry)
240 ptr = &(*ptr)->next;
241 *ptr = entry->next;
242 free (entry);
245 /* Call all edge removal hooks. */
246 static void
247 cgraph_call_edge_removal_hooks (struct cgraph_edge *e)
249 struct cgraph_edge_hook_list *entry = first_cgraph_edge_removal_hook;
250 while (entry)
252 entry->hook (e, entry->data);
253 entry = entry->next;
257 /* Register HOOK to be called with DATA on each removed node. */
258 struct cgraph_node_hook_list *
259 cgraph_add_node_removal_hook (cgraph_node_hook hook, void *data)
261 struct cgraph_node_hook_list *entry;
262 struct cgraph_node_hook_list **ptr = &first_cgraph_node_removal_hook;
264 entry = (struct cgraph_node_hook_list *) xmalloc (sizeof (*entry));
265 entry->hook = hook;
266 entry->data = data;
267 entry->next = NULL;
268 while (*ptr)
269 ptr = &(*ptr)->next;
270 *ptr = entry;
271 return entry;
274 /* Remove ENTRY from the list of hooks called on removing nodes. */
275 void
276 cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *entry)
278 struct cgraph_node_hook_list **ptr = &first_cgraph_node_removal_hook;
280 while (*ptr != entry)
281 ptr = &(*ptr)->next;
282 *ptr = entry->next;
283 free (entry);
286 /* Call all node removal hooks. */
287 static void
288 cgraph_call_node_removal_hooks (struct cgraph_node *node)
290 struct cgraph_node_hook_list *entry = first_cgraph_node_removal_hook;
291 while (entry)
293 entry->hook (node, entry->data);
294 entry = entry->next;
298 /* Register HOOK to be called with DATA on each inserted node. */
299 struct cgraph_node_hook_list *
300 cgraph_add_function_insertion_hook (cgraph_node_hook hook, void *data)
302 struct cgraph_node_hook_list *entry;
303 struct cgraph_node_hook_list **ptr = &first_cgraph_function_insertion_hook;
305 entry = (struct cgraph_node_hook_list *) xmalloc (sizeof (*entry));
306 entry->hook = hook;
307 entry->data = data;
308 entry->next = NULL;
309 while (*ptr)
310 ptr = &(*ptr)->next;
311 *ptr = entry;
312 return entry;
315 /* Remove ENTRY from the list of hooks called on inserted nodes. */
316 void
317 cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *entry)
319 struct cgraph_node_hook_list **ptr = &first_cgraph_function_insertion_hook;
321 while (*ptr != entry)
322 ptr = &(*ptr)->next;
323 *ptr = entry->next;
324 free (entry);
327 /* Call all node insertion hooks. */
328 void
329 cgraph_call_function_insertion_hooks (struct cgraph_node *node)
331 struct cgraph_node_hook_list *entry = first_cgraph_function_insertion_hook;
332 while (entry)
334 entry->hook (node, entry->data);
335 entry = entry->next;
339 /* Register HOOK to be called with DATA on each duplicated edge. */
340 struct cgraph_2edge_hook_list *
341 cgraph_add_edge_duplication_hook (cgraph_2edge_hook hook, void *data)
343 struct cgraph_2edge_hook_list *entry;
344 struct cgraph_2edge_hook_list **ptr = &first_cgraph_edge_duplicated_hook;
346 entry = (struct cgraph_2edge_hook_list *) xmalloc (sizeof (*entry));
347 entry->hook = hook;
348 entry->data = data;
349 entry->next = NULL;
350 while (*ptr)
351 ptr = &(*ptr)->next;
352 *ptr = entry;
353 return entry;
356 /* Remove ENTRY from the list of hooks called on duplicating edges. */
357 void
358 cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *entry)
360 struct cgraph_2edge_hook_list **ptr = &first_cgraph_edge_duplicated_hook;
362 while (*ptr != entry)
363 ptr = &(*ptr)->next;
364 *ptr = entry->next;
365 free (entry);
368 /* Call all edge duplication hooks. */
369 static void
370 cgraph_call_edge_duplication_hooks (struct cgraph_edge *cs1,
371 struct cgraph_edge *cs2)
373 struct cgraph_2edge_hook_list *entry = first_cgraph_edge_duplicated_hook;
374 while (entry)
376 entry->hook (cs1, cs2, entry->data);
377 entry = entry->next;
381 /* Register HOOK to be called with DATA on each duplicated node. */
382 struct cgraph_2node_hook_list *
383 cgraph_add_node_duplication_hook (cgraph_2node_hook hook, void *data)
385 struct cgraph_2node_hook_list *entry;
386 struct cgraph_2node_hook_list **ptr = &first_cgraph_node_duplicated_hook;
388 entry = (struct cgraph_2node_hook_list *) xmalloc (sizeof (*entry));
389 entry->hook = hook;
390 entry->data = data;
391 entry->next = NULL;
392 while (*ptr)
393 ptr = &(*ptr)->next;
394 *ptr = entry;
395 return entry;
398 /* Remove ENTRY from the list of hooks called on duplicating nodes. */
399 void
400 cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *entry)
402 struct cgraph_2node_hook_list **ptr = &first_cgraph_node_duplicated_hook;
404 while (*ptr != entry)
405 ptr = &(*ptr)->next;
406 *ptr = entry->next;
407 free (entry);
410 /* Call all node duplication hooks. */
411 static void
412 cgraph_call_node_duplication_hooks (struct cgraph_node *node1,
413 struct cgraph_node *node2)
415 struct cgraph_2node_hook_list *entry = first_cgraph_node_duplicated_hook;
416 while (entry)
418 entry->hook (node1, node2, entry->data);
419 entry = entry->next;
423 /* Returns a hash code for P. */
425 static hashval_t
426 hash_node (const void *p)
428 const struct cgraph_node *n = (const struct cgraph_node *) p;
429 return (hashval_t) DECL_UID (n->decl);
433 /* Returns nonzero if P1 and P2 are equal. */
435 static int
436 eq_node (const void *p1, const void *p2)
438 const struct cgraph_node *n1 = (const struct cgraph_node *) p1;
439 const struct cgraph_node *n2 = (const struct cgraph_node *) p2;
440 return DECL_UID (n1->decl) == DECL_UID (n2->decl);
443 /* Allocate new callgraph node. */
445 static inline struct cgraph_node *
446 cgraph_allocate_node (void)
448 struct cgraph_node *node;
450 if (free_nodes)
452 node = free_nodes;
453 free_nodes = NEXT_FREE_NODE (node);
455 else
457 node = ggc_alloc_cleared_cgraph_node ();
458 node->uid = cgraph_max_uid++;
461 return node;
464 /* Allocate new callgraph node and insert it into basic data structures. */
466 static struct cgraph_node *
467 cgraph_create_node_1 (void)
469 struct cgraph_node *node = cgraph_allocate_node ();
471 node->next = cgraph_nodes;
472 node->order = cgraph_order++;
473 if (cgraph_nodes)
474 cgraph_nodes->previous = node;
475 node->previous = NULL;
476 node->frequency = NODE_FREQUENCY_NORMAL;
477 node->count_materialization_scale = REG_BR_PROB_BASE;
478 ipa_empty_ref_list (&node->ref_list);
479 cgraph_nodes = node;
480 cgraph_n_nodes++;
481 return node;
484 /* Return cgraph node assigned to DECL. Create new one when needed. */
486 struct cgraph_node *
487 cgraph_create_node (tree decl)
489 struct cgraph_node key, *node, **slot;
491 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
493 if (!cgraph_hash)
494 cgraph_hash = htab_create_ggc (10, hash_node, eq_node, NULL);
496 key.decl = decl;
497 slot = (struct cgraph_node **) htab_find_slot (cgraph_hash, &key, INSERT);
498 gcc_assert (!*slot);
500 node = cgraph_create_node_1 ();
501 node->decl = decl;
502 *slot = node;
503 if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL)
505 node->origin = cgraph_get_create_node (DECL_CONTEXT (decl));
506 node->next_nested = node->origin->nested;
507 node->origin->nested = node;
509 if (assembler_name_hash)
511 void **aslot;
512 tree name = DECL_ASSEMBLER_NAME (decl);
514 aslot = htab_find_slot_with_hash (assembler_name_hash, name,
515 decl_assembler_name_hash (name),
516 INSERT);
517 /* We can have multiple declarations with same assembler name. For C++
518 it is __builtin_strlen and strlen, for instance. Do we need to
519 record them all? Original implementation marked just first one
520 so lets hope for the best. */
521 if (*aslot == NULL)
522 *aslot = node;
524 return node;
527 /* Try to find a call graph node for declaration DECL and if it does not exist,
528 create it. */
530 struct cgraph_node *
531 cgraph_get_create_node (tree decl)
533 struct cgraph_node *node;
535 node = cgraph_get_node (decl);
536 if (node)
537 return node;
539 return cgraph_create_node (decl);
542 /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
543 the function body is associated with (not neccesarily cgraph_node (DECL). */
545 static struct cgraph_node *
546 cgraph_same_body_alias_1 (struct cgraph_node *decl_node, tree alias, tree decl)
548 struct cgraph_node key, *alias_node, **slot;
550 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
551 gcc_assert (TREE_CODE (alias) == FUNCTION_DECL);
553 key.decl = alias;
555 slot = (struct cgraph_node **) htab_find_slot (cgraph_hash, &key, INSERT);
557 /* If the cgraph_node has been already created, fail. */
558 if (*slot)
559 return NULL;
561 alias_node = cgraph_allocate_node ();
562 alias_node->decl = alias;
563 alias_node->same_body_alias = 1;
564 alias_node->same_body = decl_node;
565 alias_node->previous = NULL;
566 if (decl_node->same_body)
567 decl_node->same_body->previous = alias_node;
568 alias_node->next = decl_node->same_body;
569 alias_node->thunk.alias = decl;
570 decl_node->same_body = alias_node;
571 *slot = alias_node;
572 return alias_node;
575 /* Attempt to mark ALIAS as an alias to DECL. Return alias node if successful
576 and NULL otherwise.
577 Same body aliases are output whenever the body of DECL is output,
578 and cgraph_get_node (ALIAS) transparently returns cgraph_get_node (DECL). */
580 struct cgraph_node *
581 cgraph_same_body_alias (struct cgraph_node *decl_node, tree alias, tree decl)
583 #ifndef ASM_OUTPUT_DEF
584 /* If aliases aren't supported by the assembler, fail. */
585 return NULL;
586 #endif
588 /*gcc_assert (!assembler_name_hash);*/
590 return cgraph_same_body_alias_1 (decl_node, alias, decl);
593 /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
594 aliases DECL with an adjustments made into the first parameter.
595 See comments in thunk_adjust for detail on the parameters. */
597 struct cgraph_node *
598 cgraph_add_thunk (struct cgraph_node *decl_node, tree alias, tree decl,
599 bool this_adjusting,
600 HOST_WIDE_INT fixed_offset, HOST_WIDE_INT virtual_value,
601 tree virtual_offset,
602 tree real_alias)
604 struct cgraph_node *node = cgraph_get_node (alias);
606 if (node)
608 gcc_assert (node->local.finalized);
609 gcc_assert (!node->same_body);
610 cgraph_remove_node (node);
613 node = cgraph_same_body_alias_1 (decl_node, alias, decl);
614 gcc_assert (node);
615 gcc_checking_assert (!virtual_offset
616 || tree_int_cst_equal (virtual_offset,
617 size_int (virtual_value)));
618 node->thunk.fixed_offset = fixed_offset;
619 node->thunk.this_adjusting = this_adjusting;
620 node->thunk.virtual_value = virtual_value;
621 node->thunk.virtual_offset_p = virtual_offset != NULL;
622 node->thunk.alias = real_alias;
623 node->thunk.thunk_p = true;
624 return node;
627 /* Returns the cgraph node assigned to DECL or NULL if no cgraph node
628 is assigned. */
630 struct cgraph_node *
631 cgraph_get_node_or_alias (const_tree decl)
633 struct cgraph_node key, *node = NULL, **slot;
635 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
637 if (!cgraph_hash)
638 return NULL;
640 key.decl = CONST_CAST2 (tree, const_tree, decl);
642 slot = (struct cgraph_node **) htab_find_slot (cgraph_hash, &key,
643 NO_INSERT);
645 if (slot && *slot)
646 node = *slot;
647 return node;
650 /* Returns the cgraph node assigned to DECL or NULL if no cgraph node
651 is assigned. */
653 struct cgraph_node *
654 cgraph_get_node (const_tree decl)
656 struct cgraph_node key, *node = NULL, **slot;
658 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
660 if (!cgraph_hash)
661 return NULL;
663 key.decl = CONST_CAST2 (tree, const_tree, decl);
665 slot = (struct cgraph_node **) htab_find_slot (cgraph_hash, &key,
666 NO_INSERT);
668 if (slot && *slot)
670 node = *slot;
671 if (node->same_body_alias)
672 node = node->same_body;
674 return node;
677 /* Insert already constructed node into hashtable. */
679 void
680 cgraph_insert_node_to_hashtable (struct cgraph_node *node)
682 struct cgraph_node **slot;
684 slot = (struct cgraph_node **) htab_find_slot (cgraph_hash, node, INSERT);
686 gcc_assert (!*slot);
687 *slot = node;
690 /* Returns a hash code for P. */
692 static hashval_t
693 hash_node_by_assembler_name (const void *p)
695 const struct cgraph_node *n = (const struct cgraph_node *) p;
696 return (hashval_t) decl_assembler_name_hash (DECL_ASSEMBLER_NAME (n->decl));
699 /* Returns nonzero if P1 and P2 are equal. */
701 static int
702 eq_assembler_name (const void *p1, const void *p2)
704 const struct cgraph_node *n1 = (const struct cgraph_node *) p1;
705 const_tree name = (const_tree)p2;
706 return (decl_assembler_name_equal (n1->decl, name));
709 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
710 Return NULL if there's no such node. */
712 struct cgraph_node *
713 cgraph_node_for_asm (tree asmname)
715 struct cgraph_node *node;
716 void **slot;
718 if (!assembler_name_hash)
720 assembler_name_hash =
721 htab_create_ggc (10, hash_node_by_assembler_name, eq_assembler_name,
722 NULL);
723 for (node = cgraph_nodes; node; node = node->next)
724 if (!node->global.inlined_to)
726 tree name = DECL_ASSEMBLER_NAME (node->decl);
727 slot = htab_find_slot_with_hash (assembler_name_hash, name,
728 decl_assembler_name_hash (name),
729 INSERT);
730 /* We can have multiple declarations with same assembler name. For C++
731 it is __builtin_strlen and strlen, for instance. Do we need to
732 record them all? Original implementation marked just first one
733 so lets hope for the best. */
734 if (!*slot)
735 *slot = node;
736 if (node->same_body)
738 struct cgraph_node *alias;
740 for (alias = node->same_body; alias; alias = alias->next)
742 hashval_t hash;
743 name = DECL_ASSEMBLER_NAME (alias->decl);
744 hash = decl_assembler_name_hash (name);
745 slot = htab_find_slot_with_hash (assembler_name_hash, name,
746 hash, INSERT);
747 if (!*slot)
748 *slot = alias;
754 slot = htab_find_slot_with_hash (assembler_name_hash, asmname,
755 decl_assembler_name_hash (asmname),
756 NO_INSERT);
758 if (slot)
760 node = (struct cgraph_node *) *slot;
761 if (node->same_body_alias)
762 node = node->same_body;
763 return node;
765 return NULL;
768 /* Returns a hash value for X (which really is a die_struct). */
770 static hashval_t
771 edge_hash (const void *x)
773 return htab_hash_pointer (((const struct cgraph_edge *) x)->call_stmt);
776 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
778 static int
779 edge_eq (const void *x, const void *y)
781 return ((const struct cgraph_edge *) x)->call_stmt == y;
784 /* Add call graph edge E to call site hash of its caller. */
786 static inline void
787 cgraph_add_edge_to_call_site_hash (struct cgraph_edge *e)
789 void **slot;
790 slot = htab_find_slot_with_hash (e->caller->call_site_hash,
791 e->call_stmt,
792 htab_hash_pointer (e->call_stmt),
793 INSERT);
794 gcc_assert (!*slot);
795 *slot = e;
798 /* Return the callgraph edge representing the GIMPLE_CALL statement
799 CALL_STMT. */
801 struct cgraph_edge *
802 cgraph_edge (struct cgraph_node *node, gimple call_stmt)
804 struct cgraph_edge *e, *e2;
805 int n = 0;
807 if (node->call_site_hash)
808 return (struct cgraph_edge *)
809 htab_find_with_hash (node->call_site_hash, call_stmt,
810 htab_hash_pointer (call_stmt));
812 /* This loop may turn out to be performance problem. In such case adding
813 hashtables into call nodes with very many edges is probably best
814 solution. It is not good idea to add pointer into CALL_EXPR itself
815 because we want to make possible having multiple cgraph nodes representing
816 different clones of the same body before the body is actually cloned. */
817 for (e = node->callees; e; e = e->next_callee)
819 if (e->call_stmt == call_stmt)
820 break;
821 n++;
824 if (!e)
825 for (e = node->indirect_calls; e; e = e->next_callee)
827 if (e->call_stmt == call_stmt)
828 break;
829 n++;
832 if (n > 100)
834 node->call_site_hash = htab_create_ggc (120, edge_hash, edge_eq, NULL);
835 for (e2 = node->callees; e2; e2 = e2->next_callee)
836 cgraph_add_edge_to_call_site_hash (e2);
837 for (e2 = node->indirect_calls; e2; e2 = e2->next_callee)
838 cgraph_add_edge_to_call_site_hash (e2);
841 return e;
845 /* Change field call_stmt of edge E to NEW_STMT. */
847 void
848 cgraph_set_call_stmt (struct cgraph_edge *e, gimple new_stmt)
850 tree decl;
852 if (e->caller->call_site_hash)
854 htab_remove_elt_with_hash (e->caller->call_site_hash,
855 e->call_stmt,
856 htab_hash_pointer (e->call_stmt));
859 e->call_stmt = new_stmt;
860 if (e->indirect_unknown_callee
861 && (decl = gimple_call_fndecl (new_stmt)))
863 /* Constant propagation (and possibly also inlining?) can turn an
864 indirect call into a direct one. */
865 struct cgraph_node *new_callee = cgraph_get_node (decl);
867 gcc_checking_assert (new_callee);
868 cgraph_make_edge_direct (e, new_callee, 0);
871 push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
872 e->can_throw_external = stmt_can_throw_external (new_stmt);
873 pop_cfun ();
874 if (e->caller->call_site_hash)
875 cgraph_add_edge_to_call_site_hash (e);
878 /* Like cgraph_set_call_stmt but walk the clone tree and update all
879 clones sharing the same function body. */
881 void
882 cgraph_set_call_stmt_including_clones (struct cgraph_node *orig,
883 gimple old_stmt, gimple new_stmt)
885 struct cgraph_node *node;
886 struct cgraph_edge *edge = cgraph_edge (orig, old_stmt);
888 if (edge)
889 cgraph_set_call_stmt (edge, new_stmt);
891 node = orig->clones;
892 if (node)
893 while (node != orig)
895 struct cgraph_edge *edge = cgraph_edge (node, old_stmt);
896 if (edge)
897 cgraph_set_call_stmt (edge, new_stmt);
898 if (node->clones)
899 node = node->clones;
900 else if (node->next_sibling_clone)
901 node = node->next_sibling_clone;
902 else
904 while (node != orig && !node->next_sibling_clone)
905 node = node->clone_of;
906 if (node != orig)
907 node = node->next_sibling_clone;
912 /* Like cgraph_create_edge walk the clone tree and update all clones sharing
913 same function body. If clones already have edge for OLD_STMT; only
914 update the edge same way as cgraph_set_call_stmt_including_clones does.
916 TODO: COUNT and LOOP_DEPTH should be properly distributed based on relative
917 frequencies of the clones. */
919 void
920 cgraph_create_edge_including_clones (struct cgraph_node *orig,
921 struct cgraph_node *callee,
922 gimple old_stmt,
923 gimple stmt, gcov_type count,
924 int freq, int loop_depth,
925 cgraph_inline_failed_t reason)
927 struct cgraph_node *node;
928 struct cgraph_edge *edge;
930 if (!cgraph_edge (orig, stmt))
932 edge = cgraph_create_edge (orig, callee, stmt, count, freq, loop_depth);
933 edge->inline_failed = reason;
936 node = orig->clones;
937 if (node)
938 while (node != orig)
940 struct cgraph_edge *edge = cgraph_edge (node, old_stmt);
942 /* It is possible that clones already contain the edge while
943 master didn't. Either we promoted indirect call into direct
944 call in the clone or we are processing clones of unreachable
945 master where edges has been removed. */
946 if (edge)
947 cgraph_set_call_stmt (edge, stmt);
948 else if (!cgraph_edge (node, stmt))
950 edge = cgraph_create_edge (node, callee, stmt, count,
951 freq, loop_depth);
952 edge->inline_failed = reason;
955 if (node->clones)
956 node = node->clones;
957 else if (node->next_sibling_clone)
958 node = node->next_sibling_clone;
959 else
961 while (node != orig && !node->next_sibling_clone)
962 node = node->clone_of;
963 if (node != orig)
964 node = node->next_sibling_clone;
969 /* Allocate a cgraph_edge structure and fill it with data according to the
970 parameters of which only CALLEE can be NULL (when creating an indirect call
971 edge). */
973 static struct cgraph_edge *
974 cgraph_create_edge_1 (struct cgraph_node *caller, struct cgraph_node *callee,
975 gimple call_stmt, gcov_type count, int freq, int nest)
977 struct cgraph_edge *edge;
979 /* LTO does not actually have access to the call_stmt since these
980 have not been loaded yet. */
981 if (call_stmt)
983 /* This is a rather expensive check possibly triggering
984 construction of call stmt hashtable. */
985 gcc_checking_assert (!cgraph_edge (caller, call_stmt));
987 gcc_assert (is_gimple_call (call_stmt));
990 if (free_edges)
992 edge = free_edges;
993 free_edges = NEXT_FREE_EDGE (edge);
995 else
997 edge = ggc_alloc_cgraph_edge ();
998 edge->uid = cgraph_edge_max_uid++;
1001 edge->aux = NULL;
1002 edge->caller = caller;
1003 edge->callee = callee;
1004 edge->prev_caller = NULL;
1005 edge->next_caller = NULL;
1006 edge->prev_callee = NULL;
1007 edge->next_callee = NULL;
1009 edge->count = count;
1010 gcc_assert (count >= 0);
1011 edge->frequency = freq;
1012 gcc_assert (freq >= 0);
1013 gcc_assert (freq <= CGRAPH_FREQ_MAX);
1014 edge->loop_nest = nest;
1016 edge->call_stmt = call_stmt;
1017 edge->call_stmt_size = 0;
1018 edge->call_stmt_time = 0;
1019 push_cfun (DECL_STRUCT_FUNCTION (caller->decl));
1020 edge->can_throw_external
1021 = call_stmt ? stmt_can_throw_external (call_stmt) : false;
1022 pop_cfun ();
1023 edge->call_stmt_cannot_inline_p =
1024 (call_stmt ? gimple_call_cannot_inline_p (call_stmt) : false);
1025 if (call_stmt && caller->call_site_hash)
1026 cgraph_add_edge_to_call_site_hash (edge);
1028 edge->indirect_info = NULL;
1029 edge->indirect_inlining_edge = 0;
1031 return edge;
1034 /* Create edge from CALLER to CALLEE in the cgraph. */
1036 struct cgraph_edge *
1037 cgraph_create_edge (struct cgraph_node *caller, struct cgraph_node *callee,
1038 gimple call_stmt, gcov_type count, int freq, int nest)
1040 struct cgraph_edge *edge = cgraph_create_edge_1 (caller, callee, call_stmt,
1041 count, freq, nest);
1043 edge->indirect_unknown_callee = 0;
1044 initialize_inline_failed (edge);
1046 edge->next_caller = callee->callers;
1047 if (callee->callers)
1048 callee->callers->prev_caller = edge;
1049 edge->next_callee = caller->callees;
1050 if (caller->callees)
1051 caller->callees->prev_callee = edge;
1052 caller->callees = edge;
1053 callee->callers = edge;
1055 return edge;
1058 /* Allocate cgraph_indirect_call_info and set its fields to default values. */
1060 struct cgraph_indirect_call_info *
1061 cgraph_allocate_init_indirect_info (void)
1063 struct cgraph_indirect_call_info *ii;
1065 ii = ggc_alloc_cleared_cgraph_indirect_call_info ();
1066 ii->param_index = -1;
1067 return ii;
1070 /* Create an indirect edge with a yet-undetermined callee where the call
1071 statement destination is a formal parameter of the caller with index
1072 PARAM_INDEX. */
1074 struct cgraph_edge *
1075 cgraph_create_indirect_edge (struct cgraph_node *caller, gimple call_stmt,
1076 int ecf_flags,
1077 gcov_type count, int freq, int nest)
1079 struct cgraph_edge *edge = cgraph_create_edge_1 (caller, NULL, call_stmt,
1080 count, freq, nest);
1082 edge->indirect_unknown_callee = 1;
1083 initialize_inline_failed (edge);
1085 edge->indirect_info = cgraph_allocate_init_indirect_info ();
1086 edge->indirect_info->ecf_flags = ecf_flags;
1088 edge->next_callee = caller->indirect_calls;
1089 if (caller->indirect_calls)
1090 caller->indirect_calls->prev_callee = edge;
1091 caller->indirect_calls = edge;
1093 return edge;
1096 /* Remove the edge E from the list of the callers of the callee. */
1098 static inline void
1099 cgraph_edge_remove_callee (struct cgraph_edge *e)
1101 gcc_assert (!e->indirect_unknown_callee);
1102 if (e->prev_caller)
1103 e->prev_caller->next_caller = e->next_caller;
1104 if (e->next_caller)
1105 e->next_caller->prev_caller = e->prev_caller;
1106 if (!e->prev_caller)
1107 e->callee->callers = e->next_caller;
1110 /* Remove the edge E from the list of the callees of the caller. */
1112 static inline void
1113 cgraph_edge_remove_caller (struct cgraph_edge *e)
1115 if (e->prev_callee)
1116 e->prev_callee->next_callee = e->next_callee;
1117 if (e->next_callee)
1118 e->next_callee->prev_callee = e->prev_callee;
1119 if (!e->prev_callee)
1121 if (e->indirect_unknown_callee)
1122 e->caller->indirect_calls = e->next_callee;
1123 else
1124 e->caller->callees = e->next_callee;
1126 if (e->caller->call_site_hash)
1127 htab_remove_elt_with_hash (e->caller->call_site_hash,
1128 e->call_stmt,
1129 htab_hash_pointer (e->call_stmt));
1132 /* Put the edge onto the free list. */
1134 static void
1135 cgraph_free_edge (struct cgraph_edge *e)
1137 int uid = e->uid;
1139 /* Clear out the edge so we do not dangle pointers. */
1140 memset (e, 0, sizeof (*e));
1141 e->uid = uid;
1142 NEXT_FREE_EDGE (e) = free_edges;
1143 free_edges = e;
1146 /* Remove the edge E in the cgraph. */
1148 void
1149 cgraph_remove_edge (struct cgraph_edge *e)
1151 /* Call all edge removal hooks. */
1152 cgraph_call_edge_removal_hooks (e);
1154 if (!e->indirect_unknown_callee)
1155 /* Remove from callers list of the callee. */
1156 cgraph_edge_remove_callee (e);
1158 /* Remove from callees list of the callers. */
1159 cgraph_edge_remove_caller (e);
1161 /* Put the edge onto the free list. */
1162 cgraph_free_edge (e);
1165 /* Set callee of call graph edge E and add it to the corresponding set of
1166 callers. */
1168 static void
1169 cgraph_set_edge_callee (struct cgraph_edge *e, struct cgraph_node *n)
1171 e->prev_caller = NULL;
1172 if (n->callers)
1173 n->callers->prev_caller = e;
1174 e->next_caller = n->callers;
1175 n->callers = e;
1176 e->callee = n;
1179 /* Redirect callee of E to N. The function does not update underlying
1180 call expression. */
1182 void
1183 cgraph_redirect_edge_callee (struct cgraph_edge *e, struct cgraph_node *n)
1185 /* Remove from callers list of the current callee. */
1186 cgraph_edge_remove_callee (e);
1188 /* Insert to callers list of the new callee. */
1189 cgraph_set_edge_callee (e, n);
1192 /* Make an indirect EDGE with an unknown callee an ordinary edge leading to
1193 CALLEE. DELTA is an integer constant that is to be added to the this
1194 pointer (first parameter) to compensate for skipping a thunk adjustment. */
1196 void
1197 cgraph_make_edge_direct (struct cgraph_edge *edge, struct cgraph_node *callee,
1198 HOST_WIDE_INT delta)
1200 edge->indirect_unknown_callee = 0;
1201 edge->indirect_info->thunk_delta = delta;
1203 /* Get the edge out of the indirect edge list. */
1204 if (edge->prev_callee)
1205 edge->prev_callee->next_callee = edge->next_callee;
1206 if (edge->next_callee)
1207 edge->next_callee->prev_callee = edge->prev_callee;
1208 if (!edge->prev_callee)
1209 edge->caller->indirect_calls = edge->next_callee;
1211 /* Put it into the normal callee list */
1212 edge->prev_callee = NULL;
1213 edge->next_callee = edge->caller->callees;
1214 if (edge->caller->callees)
1215 edge->caller->callees->prev_callee = edge;
1216 edge->caller->callees = edge;
1218 /* Insert to callers list of the new callee. */
1219 cgraph_set_edge_callee (edge, callee);
1221 /* We need to re-determine the inlining status of the edge. */
1222 initialize_inline_failed (edge);
1226 /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
1227 OLD_STMT changed into NEW_STMT. OLD_CALL is gimple_call_fndecl
1228 of OLD_STMT if it was previously call statement. */
1230 static void
1231 cgraph_update_edges_for_call_stmt_node (struct cgraph_node *node,
1232 gimple old_stmt, tree old_call, gimple new_stmt)
1234 tree new_call = (is_gimple_call (new_stmt)) ? gimple_call_fndecl (new_stmt) : 0;
1236 /* We are seeing indirect calls, then there is nothing to update. */
1237 if (!new_call && !old_call)
1238 return;
1239 /* See if we turned indirect call into direct call or folded call to one builtin
1240 into different builtin. */
1241 if (old_call != new_call)
1243 struct cgraph_edge *e = cgraph_edge (node, old_stmt);
1244 struct cgraph_edge *ne = NULL;
1245 gcov_type count;
1246 int frequency;
1247 int loop_nest;
1249 if (e)
1251 /* See if the edge is already there and has the correct callee. It
1252 might be so because of indirect inlining has already updated
1253 it. We also might've cloned and redirected the edge. */
1254 if (new_call && e->callee)
1256 struct cgraph_node *callee = e->callee;
1257 while (callee)
1259 if (callee->decl == new_call
1260 || callee->former_clone_of == new_call)
1261 return;
1262 callee = callee->clone_of;
1266 /* Otherwise remove edge and create new one; we can't simply redirect
1267 since function has changed, so inline plan and other information
1268 attached to edge is invalid. */
1269 count = e->count;
1270 frequency = e->frequency;
1271 loop_nest = e->loop_nest;
1272 cgraph_remove_edge (e);
1274 else
1276 /* We are seeing new direct call; compute profile info based on BB. */
1277 basic_block bb = gimple_bb (new_stmt);
1278 count = bb->count;
1279 frequency = compute_call_stmt_bb_frequency (current_function_decl,
1280 bb);
1281 loop_nest = bb->loop_depth;
1284 if (new_call)
1286 ne = cgraph_create_edge (node, cgraph_get_create_node (new_call),
1287 new_stmt, count, frequency,
1288 loop_nest);
1289 gcc_assert (ne->inline_failed);
1292 /* We only updated the call stmt; update pointer in cgraph edge.. */
1293 else if (old_stmt != new_stmt)
1294 cgraph_set_call_stmt (cgraph_edge (node, old_stmt), new_stmt);
1297 /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
1298 OLD_STMT changed into NEW_STMT. OLD_DECL is gimple_call_fndecl
1299 of OLD_STMT before it was updated (updating can happen inplace). */
1301 void
1302 cgraph_update_edges_for_call_stmt (gimple old_stmt, tree old_decl, gimple new_stmt)
1304 struct cgraph_node *orig = cgraph_get_node (cfun->decl);
1305 struct cgraph_node *node;
1307 gcc_checking_assert (orig);
1308 cgraph_update_edges_for_call_stmt_node (orig, old_stmt, old_decl, new_stmt);
1309 if (orig->clones)
1310 for (node = orig->clones; node != orig;)
1312 cgraph_update_edges_for_call_stmt_node (node, old_stmt, old_decl, new_stmt);
1313 if (node->clones)
1314 node = node->clones;
1315 else if (node->next_sibling_clone)
1316 node = node->next_sibling_clone;
1317 else
1319 while (node != orig && !node->next_sibling_clone)
1320 node = node->clone_of;
1321 if (node != orig)
1322 node = node->next_sibling_clone;
1328 /* Remove all callees from the node. */
1330 void
1331 cgraph_node_remove_callees (struct cgraph_node *node)
1333 struct cgraph_edge *e, *f;
1335 /* It is sufficient to remove the edges from the lists of callers of
1336 the callees. The callee list of the node can be zapped with one
1337 assignment. */
1338 for (e = node->callees; e; e = f)
1340 f = e->next_callee;
1341 cgraph_call_edge_removal_hooks (e);
1342 if (!e->indirect_unknown_callee)
1343 cgraph_edge_remove_callee (e);
1344 cgraph_free_edge (e);
1346 for (e = node->indirect_calls; e; e = f)
1348 f = e->next_callee;
1349 cgraph_call_edge_removal_hooks (e);
1350 if (!e->indirect_unknown_callee)
1351 cgraph_edge_remove_callee (e);
1352 cgraph_free_edge (e);
1354 node->indirect_calls = NULL;
1355 node->callees = NULL;
1356 if (node->call_site_hash)
1358 htab_delete (node->call_site_hash);
1359 node->call_site_hash = NULL;
1363 /* Remove all callers from the node. */
1365 static void
1366 cgraph_node_remove_callers (struct cgraph_node *node)
1368 struct cgraph_edge *e, *f;
1370 /* It is sufficient to remove the edges from the lists of callees of
1371 the callers. The caller list of the node can be zapped with one
1372 assignment. */
1373 for (e = node->callers; e; e = f)
1375 f = e->next_caller;
1376 cgraph_call_edge_removal_hooks (e);
1377 cgraph_edge_remove_caller (e);
1378 cgraph_free_edge (e);
1380 node->callers = NULL;
1383 /* Release memory used to represent body of function NODE. */
1385 void
1386 cgraph_release_function_body (struct cgraph_node *node)
1388 if (DECL_STRUCT_FUNCTION (node->decl))
1390 tree old_decl = current_function_decl;
1391 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1392 if (cfun->gimple_df)
1394 current_function_decl = node->decl;
1395 delete_tree_ssa ();
1396 delete_tree_cfg_annotations ();
1397 cfun->eh = NULL;
1398 current_function_decl = old_decl;
1400 if (cfun->cfg)
1402 gcc_assert (dom_computed[0] == DOM_NONE);
1403 gcc_assert (dom_computed[1] == DOM_NONE);
1404 clear_edges ();
1406 if (cfun->value_histograms)
1407 free_histograms ();
1408 gcc_assert (!current_loops);
1409 pop_cfun();
1410 gimple_set_body (node->decl, NULL);
1411 VEC_free (ipa_opt_pass, heap,
1412 node->ipa_transforms_to_apply);
1413 /* Struct function hangs a lot of data that would leak if we didn't
1414 removed all pointers to it. */
1415 ggc_free (DECL_STRUCT_FUNCTION (node->decl));
1416 DECL_STRUCT_FUNCTION (node->decl) = NULL;
1418 DECL_SAVED_TREE (node->decl) = NULL;
1419 /* If the node is abstract and needed, then do not clear DECL_INITIAL
1420 of its associated function function declaration because it's
1421 needed to emit debug info later. */
1422 if (!node->abstract_and_needed)
1423 DECL_INITIAL (node->decl) = error_mark_node;
1426 /* Remove same body alias node. */
1428 void
1429 cgraph_remove_same_body_alias (struct cgraph_node *node)
1431 void **slot;
1432 int uid = node->uid;
1434 gcc_assert (node->same_body_alias);
1435 if (node->previous)
1436 node->previous->next = node->next;
1437 else
1438 node->same_body->same_body = node->next;
1439 if (node->next)
1440 node->next->previous = node->previous;
1441 node->next = NULL;
1442 node->previous = NULL;
1443 slot = htab_find_slot (cgraph_hash, node, NO_INSERT);
1444 if (*slot == node)
1445 htab_clear_slot (cgraph_hash, slot);
1446 if (assembler_name_hash)
1448 tree name = DECL_ASSEMBLER_NAME (node->decl);
1449 slot = htab_find_slot_with_hash (assembler_name_hash, name,
1450 decl_assembler_name_hash (name),
1451 NO_INSERT);
1452 if (slot && *slot == node)
1453 htab_clear_slot (assembler_name_hash, slot);
1456 /* Clear out the node to NULL all pointers and add the node to the free
1457 list. */
1458 memset (node, 0, sizeof(*node));
1459 node->uid = uid;
1460 NEXT_FREE_NODE (node) = free_nodes;
1461 free_nodes = node;
1464 /* Remove the node from cgraph. */
1466 void
1467 cgraph_remove_node (struct cgraph_node *node)
1469 void **slot;
1470 bool kill_body = false;
1471 struct cgraph_node *n;
1472 int uid = node->uid;
1474 cgraph_call_node_removal_hooks (node);
1475 cgraph_node_remove_callers (node);
1476 cgraph_node_remove_callees (node);
1477 ipa_remove_all_references (&node->ref_list);
1478 ipa_remove_all_refering (&node->ref_list);
1479 VEC_free (ipa_opt_pass, heap,
1480 node->ipa_transforms_to_apply);
1482 /* Incremental inlining access removed nodes stored in the postorder list.
1484 node->needed = node->reachable = false;
1485 for (n = node->nested; n; n = n->next_nested)
1486 n->origin = NULL;
1487 node->nested = NULL;
1488 if (node->origin)
1490 struct cgraph_node **node2 = &node->origin->nested;
1492 while (*node2 != node)
1493 node2 = &(*node2)->next_nested;
1494 *node2 = node->next_nested;
1496 if (node->previous)
1497 node->previous->next = node->next;
1498 else
1499 cgraph_nodes = node->next;
1500 if (node->next)
1501 node->next->previous = node->previous;
1502 node->next = NULL;
1503 node->previous = NULL;
1504 slot = htab_find_slot (cgraph_hash, node, NO_INSERT);
1505 if (*slot == node)
1507 struct cgraph_node *next_inline_clone;
1509 for (next_inline_clone = node->clones;
1510 next_inline_clone && next_inline_clone->decl != node->decl;
1511 next_inline_clone = next_inline_clone->next_sibling_clone)
1514 /* If there is inline clone of the node being removed, we need
1515 to put it into the position of removed node and reorganize all
1516 other clones to be based on it. */
1517 if (next_inline_clone)
1519 struct cgraph_node *n;
1520 struct cgraph_node *new_clones;
1522 *slot = next_inline_clone;
1524 /* Unlink inline clone from the list of clones of removed node. */
1525 if (next_inline_clone->next_sibling_clone)
1526 next_inline_clone->next_sibling_clone->prev_sibling_clone
1527 = next_inline_clone->prev_sibling_clone;
1528 if (next_inline_clone->prev_sibling_clone)
1530 gcc_assert (node->clones != next_inline_clone);
1531 next_inline_clone->prev_sibling_clone->next_sibling_clone
1532 = next_inline_clone->next_sibling_clone;
1534 else
1536 gcc_assert (node->clones == next_inline_clone);
1537 node->clones = next_inline_clone->next_sibling_clone;
1540 new_clones = node->clones;
1541 node->clones = NULL;
1543 /* Copy clone info. */
1544 next_inline_clone->clone = node->clone;
1546 /* Now place it into clone tree at same level at NODE. */
1547 next_inline_clone->clone_of = node->clone_of;
1548 next_inline_clone->prev_sibling_clone = NULL;
1549 next_inline_clone->next_sibling_clone = NULL;
1550 if (node->clone_of)
1552 if (node->clone_of->clones)
1553 node->clone_of->clones->prev_sibling_clone = next_inline_clone;
1554 next_inline_clone->next_sibling_clone = node->clone_of->clones;
1555 node->clone_of->clones = next_inline_clone;
1558 /* Merge the clone list. */
1559 if (new_clones)
1561 if (!next_inline_clone->clones)
1562 next_inline_clone->clones = new_clones;
1563 else
1565 n = next_inline_clone->clones;
1566 while (n->next_sibling_clone)
1567 n = n->next_sibling_clone;
1568 n->next_sibling_clone = new_clones;
1569 new_clones->prev_sibling_clone = n;
1573 /* Update clone_of pointers. */
1574 n = new_clones;
1575 while (n)
1577 n->clone_of = next_inline_clone;
1578 n = n->next_sibling_clone;
1581 else
1583 htab_clear_slot (cgraph_hash, slot);
1584 kill_body = true;
1588 if (node->prev_sibling_clone)
1589 node->prev_sibling_clone->next_sibling_clone = node->next_sibling_clone;
1590 else if (node->clone_of)
1591 node->clone_of->clones = node->next_sibling_clone;
1592 if (node->next_sibling_clone)
1593 node->next_sibling_clone->prev_sibling_clone = node->prev_sibling_clone;
1594 if (node->clones)
1596 struct cgraph_node *n, *next;
1598 if (node->clone_of)
1600 for (n = node->clones; n->next_sibling_clone; n = n->next_sibling_clone)
1601 n->clone_of = node->clone_of;
1602 n->clone_of = node->clone_of;
1603 n->next_sibling_clone = node->clone_of->clones;
1604 if (node->clone_of->clones)
1605 node->clone_of->clones->prev_sibling_clone = n;
1606 node->clone_of->clones = node->clones;
1608 else
1610 /* We are removing node with clones. this makes clones inconsistent,
1611 but assume they will be removed subsequently and just keep clone
1612 tree intact. This can happen in unreachable function removal since
1613 we remove unreachable functions in random order, not by bottom-up
1614 walk of clone trees. */
1615 for (n = node->clones; n; n = next)
1617 next = n->next_sibling_clone;
1618 n->next_sibling_clone = NULL;
1619 n->prev_sibling_clone = NULL;
1620 n->clone_of = NULL;
1625 while (node->same_body)
1626 cgraph_remove_same_body_alias (node->same_body);
1628 if (node->same_comdat_group)
1630 struct cgraph_node *prev;
1631 for (prev = node->same_comdat_group;
1632 prev->same_comdat_group != node;
1633 prev = prev->same_comdat_group)
1635 if (node->same_comdat_group == prev)
1636 prev->same_comdat_group = NULL;
1637 else
1638 prev->same_comdat_group = node->same_comdat_group;
1639 node->same_comdat_group = NULL;
1642 /* While all the clones are removed after being proceeded, the function
1643 itself is kept in the cgraph even after it is compiled. Check whether
1644 we are done with this body and reclaim it proactively if this is the case.
1646 if (!kill_body && *slot)
1648 struct cgraph_node *n = (struct cgraph_node *) *slot;
1649 if (!n->clones && !n->clone_of && !n->global.inlined_to
1650 && (cgraph_global_info_ready
1651 && (TREE_ASM_WRITTEN (n->decl) || DECL_EXTERNAL (n->decl)
1652 || n->in_other_partition)))
1653 kill_body = true;
1655 if (assembler_name_hash)
1657 tree name = DECL_ASSEMBLER_NAME (node->decl);
1658 slot = htab_find_slot_with_hash (assembler_name_hash, name,
1659 decl_assembler_name_hash (name),
1660 NO_INSERT);
1661 /* Inline clones are not hashed. */
1662 if (slot && *slot == node)
1663 htab_clear_slot (assembler_name_hash, slot);
1666 if (kill_body)
1667 cgraph_release_function_body (node);
1668 node->decl = NULL;
1669 if (node->call_site_hash)
1671 htab_delete (node->call_site_hash);
1672 node->call_site_hash = NULL;
1674 cgraph_n_nodes--;
1676 /* Clear out the node to NULL all pointers and add the node to the free
1677 list. */
1678 memset (node, 0, sizeof(*node));
1679 node->uid = uid;
1680 NEXT_FREE_NODE (node) = free_nodes;
1681 free_nodes = node;
1684 /* Remove the node from cgraph. */
1686 void
1687 cgraph_remove_node_and_inline_clones (struct cgraph_node *node)
1689 struct cgraph_edge *e, *next;
1690 for (e = node->callees; e; e = next)
1692 next = e->next_callee;
1693 if (!e->inline_failed)
1694 cgraph_remove_node_and_inline_clones (e->callee);
1696 cgraph_remove_node (node);
1699 /* Notify finalize_compilation_unit that given node is reachable. */
1701 void
1702 cgraph_mark_reachable_node (struct cgraph_node *node)
1704 if (!node->reachable && node->local.finalized)
1706 if (cgraph_global_info_ready)
1708 /* Verify that function does not appear to be needed out of blue
1709 during the optimization process. This can happen for extern
1710 inlines when bodies was removed after inlining. */
1711 gcc_assert ((node->analyzed || node->in_other_partition
1712 || DECL_EXTERNAL (node->decl)));
1714 else
1715 notice_global_symbol (node->decl);
1716 node->reachable = 1;
1718 node->next_needed = cgraph_nodes_queue;
1719 cgraph_nodes_queue = node;
1723 /* Likewise indicate that a node is needed, i.e. reachable via some
1724 external means. */
1726 void
1727 cgraph_mark_needed_node (struct cgraph_node *node)
1729 node->needed = 1;
1730 gcc_assert (!node->global.inlined_to);
1731 cgraph_mark_reachable_node (node);
1734 /* Likewise indicate that a node is having address taken. */
1736 void
1737 cgraph_mark_address_taken_node (struct cgraph_node *node)
1739 gcc_assert (!node->global.inlined_to);
1740 cgraph_mark_reachable_node (node);
1741 node->address_taken = 1;
1744 /* Return local info for the compiled function. */
1746 struct cgraph_local_info *
1747 cgraph_local_info (tree decl)
1749 struct cgraph_node *node;
1751 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
1752 node = cgraph_get_node (decl);
1753 if (!node)
1754 return NULL;
1755 return &node->local;
1758 /* Return local info for the compiled function. */
1760 struct cgraph_global_info *
1761 cgraph_global_info (tree decl)
1763 struct cgraph_node *node;
1765 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL && cgraph_global_info_ready);
1766 node = cgraph_get_node (decl);
1767 if (!node)
1768 return NULL;
1769 return &node->global;
1772 /* Return local info for the compiled function. */
1774 struct cgraph_rtl_info *
1775 cgraph_rtl_info (tree decl)
1777 struct cgraph_node *node;
1779 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
1780 node = cgraph_get_node (decl);
1781 if (!node
1782 || (decl != current_function_decl
1783 && !TREE_ASM_WRITTEN (node->decl)))
1784 return NULL;
1785 return &node->rtl;
1788 /* Return a string describing the failure REASON. */
1790 const char*
1791 cgraph_inline_failed_string (cgraph_inline_failed_t reason)
1793 #undef DEFCIFCODE
1794 #define DEFCIFCODE(code, string) string,
1796 static const char *cif_string_table[CIF_N_REASONS] = {
1797 #include "cif-code.def"
1800 /* Signedness of an enum type is implementation defined, so cast it
1801 to unsigned before testing. */
1802 gcc_assert ((unsigned) reason < CIF_N_REASONS);
1803 return cif_string_table[reason];
1806 /* Return name of the node used in debug output. */
1807 const char *
1808 cgraph_node_name (struct cgraph_node *node)
1810 return lang_hooks.decl_printable_name (node->decl, 2);
1813 /* Names used to print out the availability enum. */
1814 const char * const cgraph_availability_names[] =
1815 {"unset", "not_available", "overwritable", "available", "local"};
1818 /* Dump call graph node NODE to file F. */
1820 void
1821 dump_cgraph_node (FILE *f, struct cgraph_node *node)
1823 struct cgraph_edge *edge;
1824 int indirect_calls_count = 0;
1826 fprintf (f, "%s/%i", cgraph_node_name (node), node->uid);
1827 dump_addr (f, " @", (void *)node);
1828 if (DECL_ASSEMBLER_NAME_SET_P (node->decl))
1829 fprintf (f, " (asm: %s)", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)));
1830 if (node->global.inlined_to)
1831 fprintf (f, " (inline copy in %s/%i)",
1832 cgraph_node_name (node->global.inlined_to),
1833 node->global.inlined_to->uid);
1834 if (node->same_comdat_group)
1835 fprintf (f, " (same comdat group as %s/%i)",
1836 cgraph_node_name (node->same_comdat_group),
1837 node->same_comdat_group->uid);
1838 if (node->clone_of)
1839 fprintf (f, " (clone of %s/%i)",
1840 cgraph_node_name (node->clone_of),
1841 node->clone_of->uid);
1842 if (cgraph_function_flags_ready)
1843 fprintf (f, " availability:%s",
1844 cgraph_availability_names [cgraph_function_body_availability (node)]);
1845 if (node->analyzed)
1846 fprintf (f, " analyzed");
1847 if (node->in_other_partition)
1848 fprintf (f, " in_other_partition");
1849 if (node->count)
1850 fprintf (f, " executed "HOST_WIDEST_INT_PRINT_DEC"x",
1851 (HOST_WIDEST_INT)node->count);
1852 if (node->origin)
1853 fprintf (f, " nested in: %s", cgraph_node_name (node->origin));
1854 if (node->needed)
1855 fprintf (f, " needed");
1856 if (node->address_taken)
1857 fprintf (f, " address_taken");
1858 else if (node->reachable)
1859 fprintf (f, " reachable");
1860 else if (node->reachable_from_other_partition)
1861 fprintf (f, " reachable_from_other_partition");
1862 if (gimple_has_body_p (node->decl))
1863 fprintf (f, " body");
1864 if (node->process)
1865 fprintf (f, " process");
1866 if (node->local.local)
1867 fprintf (f, " local");
1868 if (node->local.externally_visible)
1869 fprintf (f, " externally_visible");
1870 if (node->resolution != LDPR_UNKNOWN)
1871 fprintf (f, " %s",
1872 ld_plugin_symbol_resolution_names[(int)node->resolution]);
1873 if (node->local.finalized)
1874 fprintf (f, " finalized");
1875 if (node->local.redefined_extern_inline)
1876 fprintf (f, " redefined_extern_inline");
1877 if (TREE_ASM_WRITTEN (node->decl))
1878 fprintf (f, " asm_written");
1879 if (node->only_called_at_startup)
1880 fprintf (f, " only_called_at_startup");
1881 if (node->only_called_at_exit)
1882 fprintf (f, " only_called_at_exit");
1884 fprintf (f, "\n called by: ");
1885 for (edge = node->callers; edge; edge = edge->next_caller)
1887 fprintf (f, "%s/%i ", cgraph_node_name (edge->caller),
1888 edge->caller->uid);
1889 if (edge->count)
1890 fprintf (f, "("HOST_WIDEST_INT_PRINT_DEC"x) ",
1891 (HOST_WIDEST_INT)edge->count);
1892 if (edge->frequency)
1893 fprintf (f, "(%.2f per call) ",
1894 edge->frequency / (double)CGRAPH_FREQ_BASE);
1895 if (!edge->inline_failed)
1896 fprintf(f, "(inlined) ");
1897 if (edge->indirect_inlining_edge)
1898 fprintf(f, "(indirect_inlining) ");
1899 if (edge->can_throw_external)
1900 fprintf(f, "(can throw external) ");
1903 fprintf (f, "\n calls: ");
1904 for (edge = node->callees; edge; edge = edge->next_callee)
1906 fprintf (f, "%s/%i ", cgraph_node_name (edge->callee),
1907 edge->callee->uid);
1908 if (!edge->inline_failed)
1909 fprintf(f, "(inlined) ");
1910 if (edge->indirect_inlining_edge)
1911 fprintf(f, "(indirect_inlining) ");
1912 if (edge->count)
1913 fprintf (f, "("HOST_WIDEST_INT_PRINT_DEC"x) ",
1914 (HOST_WIDEST_INT)edge->count);
1915 if (edge->frequency)
1916 fprintf (f, "(%.2f per call) ",
1917 edge->frequency / (double)CGRAPH_FREQ_BASE);
1918 if (edge->loop_nest)
1919 fprintf (f, "(nested in %i loops) ", edge->loop_nest);
1920 if (edge->can_throw_external)
1921 fprintf(f, "(can throw external) ");
1923 fprintf (f, "\n");
1924 fprintf (f, " References: ");
1925 ipa_dump_references (f, &node->ref_list);
1926 fprintf (f, " Refering this function: ");
1927 ipa_dump_refering (f, &node->ref_list);
1929 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
1930 indirect_calls_count++;
1931 if (indirect_calls_count)
1932 fprintf (f, " has %i outgoing edges for indirect calls.\n",
1933 indirect_calls_count);
1935 if (node->same_body)
1937 struct cgraph_node *n;
1938 fprintf (f, " aliases & thunks:");
1939 for (n = node->same_body; n; n = n->next)
1941 fprintf (f, " %s/%i", cgraph_node_name (n), n->uid);
1942 if (n->thunk.thunk_p)
1944 fprintf (f, " (thunk of %s fixed offset %i virtual value %i has "
1945 "virtual offset %i",
1946 lang_hooks.decl_printable_name (n->thunk.alias, 2),
1947 (int)n->thunk.fixed_offset,
1948 (int)n->thunk.virtual_value,
1949 (int)n->thunk.virtual_offset_p);
1950 fprintf (f, ")");
1952 if (DECL_ASSEMBLER_NAME_SET_P (n->decl))
1953 fprintf (f, " (asm: %s)", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (n->decl)));
1955 fprintf (f, "\n");
1960 /* Dump call graph node NODE to stderr. */
1962 DEBUG_FUNCTION void
1963 debug_cgraph_node (struct cgraph_node *node)
1965 dump_cgraph_node (stderr, node);
1969 /* Dump the callgraph to file F. */
1971 void
1972 dump_cgraph (FILE *f)
1974 struct cgraph_node *node;
1976 fprintf (f, "callgraph:\n\n");
1977 for (node = cgraph_nodes; node; node = node->next)
1978 dump_cgraph_node (f, node);
1982 /* Dump the call graph to stderr. */
1984 DEBUG_FUNCTION void
1985 debug_cgraph (void)
1987 dump_cgraph (stderr);
1991 /* Set the DECL_ASSEMBLER_NAME and update cgraph hashtables. */
1993 void
1994 change_decl_assembler_name (tree decl, tree name)
1996 struct cgraph_node *node;
1997 void **slot;
1998 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
1999 SET_DECL_ASSEMBLER_NAME (decl, name);
2000 else
2002 if (name == DECL_ASSEMBLER_NAME (decl))
2003 return;
2005 if (assembler_name_hash
2006 && TREE_CODE (decl) == FUNCTION_DECL
2007 && (node = cgraph_get_node_or_alias (decl)) != NULL)
2009 tree old_name = DECL_ASSEMBLER_NAME (decl);
2010 slot = htab_find_slot_with_hash (assembler_name_hash, old_name,
2011 decl_assembler_name_hash (old_name),
2012 NO_INSERT);
2013 /* Inline clones are not hashed. */
2014 if (slot && *slot == node)
2015 htab_clear_slot (assembler_name_hash, slot);
2017 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2018 && DECL_RTL_SET_P (decl))
2019 warning (0, "%D renamed after being referenced in assembly", decl);
2021 SET_DECL_ASSEMBLER_NAME (decl, name);
2023 if (assembler_name_hash
2024 && TREE_CODE (decl) == FUNCTION_DECL
2025 && (node = cgraph_get_node_or_alias (decl)) != NULL)
2027 slot = htab_find_slot_with_hash (assembler_name_hash, name,
2028 decl_assembler_name_hash (name),
2029 INSERT);
2030 gcc_assert (!*slot);
2031 *slot = node;
2035 /* Add a top-level asm statement to the list. */
2037 struct cgraph_asm_node *
2038 cgraph_add_asm_node (tree asm_str)
2040 struct cgraph_asm_node *node;
2042 node = ggc_alloc_cleared_cgraph_asm_node ();
2043 node->asm_str = asm_str;
2044 node->order = cgraph_order++;
2045 node->next = NULL;
2046 if (cgraph_asm_nodes == NULL)
2047 cgraph_asm_nodes = node;
2048 else
2049 cgraph_asm_last_node->next = node;
2050 cgraph_asm_last_node = node;
2051 return node;
2054 /* Return true when the DECL can possibly be inlined. */
2055 bool
2056 cgraph_function_possibly_inlined_p (tree decl)
2058 if (!cgraph_global_info_ready)
2059 return !DECL_UNINLINABLE (decl);
2060 return DECL_POSSIBLY_INLINED (decl);
2063 /* Create clone of E in the node N represented by CALL_EXPR the callgraph. */
2064 struct cgraph_edge *
2065 cgraph_clone_edge (struct cgraph_edge *e, struct cgraph_node *n,
2066 gimple call_stmt, unsigned stmt_uid, gcov_type count_scale,
2067 int freq_scale, int loop_nest, bool update_original)
2069 struct cgraph_edge *new_edge;
2070 gcov_type count = e->count * count_scale / REG_BR_PROB_BASE;
2071 gcov_type freq;
2073 /* We do not want to ignore loop nest after frequency drops to 0. */
2074 if (!freq_scale)
2075 freq_scale = 1;
2076 freq = e->frequency * (gcov_type) freq_scale / CGRAPH_FREQ_BASE;
2077 if (freq > CGRAPH_FREQ_MAX)
2078 freq = CGRAPH_FREQ_MAX;
2080 if (e->indirect_unknown_callee)
2082 tree decl;
2084 if (call_stmt && (decl = gimple_call_fndecl (call_stmt)))
2086 struct cgraph_node *callee = cgraph_get_node (decl);
2087 gcc_checking_assert (callee);
2088 new_edge = cgraph_create_edge (n, callee, call_stmt, count, freq,
2089 e->loop_nest + loop_nest);
2091 else
2093 new_edge = cgraph_create_indirect_edge (n, call_stmt,
2094 e->indirect_info->ecf_flags,
2095 count, freq,
2096 e->loop_nest + loop_nest);
2097 *new_edge->indirect_info = *e->indirect_info;
2100 else
2102 new_edge = cgraph_create_edge (n, e->callee, call_stmt, count, freq,
2103 e->loop_nest + loop_nest);
2104 if (e->indirect_info)
2106 new_edge->indirect_info
2107 = ggc_alloc_cleared_cgraph_indirect_call_info ();
2108 *new_edge->indirect_info = *e->indirect_info;
2112 new_edge->call_stmt_size = e->call_stmt_size;
2113 new_edge->call_stmt_time = e->call_stmt_time;
2114 new_edge->inline_failed = e->inline_failed;
2115 new_edge->indirect_inlining_edge = e->indirect_inlining_edge;
2116 new_edge->lto_stmt_uid = stmt_uid;
2117 /* Clone flags that depend on call_stmt availability manually. */
2118 new_edge->can_throw_external = e->can_throw_external;
2119 new_edge->call_stmt_cannot_inline_p = e->call_stmt_cannot_inline_p;
2120 if (update_original)
2122 e->count -= new_edge->count;
2123 if (e->count < 0)
2124 e->count = 0;
2126 cgraph_call_edge_duplication_hooks (e, new_edge);
2127 return new_edge;
2130 /* Create node representing clone of N executed COUNT times. Decrease
2131 the execution counts from original node too.
2132 The new clone will have decl set to DECL that may or may not be the same
2133 as decl of N.
2135 When UPDATE_ORIGINAL is true, the counts are subtracted from the original
2136 function's profile to reflect the fact that part of execution is handled
2137 by node. */
2138 struct cgraph_node *
2139 cgraph_clone_node (struct cgraph_node *n, tree decl, gcov_type count, int freq,
2140 int loop_nest, bool update_original,
2141 VEC(cgraph_edge_p,heap) *redirect_callers)
2143 struct cgraph_node *new_node = cgraph_create_node_1 ();
2144 struct cgraph_edge *e;
2145 gcov_type count_scale;
2146 unsigned i;
2148 new_node->decl = decl;
2149 new_node->origin = n->origin;
2150 if (new_node->origin)
2152 new_node->next_nested = new_node->origin->nested;
2153 new_node->origin->nested = new_node;
2155 new_node->analyzed = n->analyzed;
2156 new_node->local = n->local;
2157 new_node->local.externally_visible = false;
2158 new_node->local.local = true;
2159 new_node->global = n->global;
2160 new_node->rtl = n->rtl;
2161 new_node->count = count;
2162 new_node->frequency = n->frequency;
2163 new_node->clone = n->clone;
2164 new_node->clone.tree_map = 0;
2165 if (n->count)
2167 if (new_node->count > n->count)
2168 count_scale = REG_BR_PROB_BASE;
2169 else
2170 count_scale = new_node->count * REG_BR_PROB_BASE / n->count;
2172 else
2173 count_scale = 0;
2174 if (update_original)
2176 n->count -= count;
2177 if (n->count < 0)
2178 n->count = 0;
2181 FOR_EACH_VEC_ELT (cgraph_edge_p, redirect_callers, i, e)
2183 /* Redirect calls to the old version node to point to its new
2184 version. */
2185 cgraph_redirect_edge_callee (e, new_node);
2189 for (e = n->callees;e; e=e->next_callee)
2190 cgraph_clone_edge (e, new_node, e->call_stmt, e->lto_stmt_uid,
2191 count_scale, freq, loop_nest, update_original);
2193 for (e = n->indirect_calls; e; e = e->next_callee)
2194 cgraph_clone_edge (e, new_node, e->call_stmt, e->lto_stmt_uid,
2195 count_scale, freq, loop_nest, update_original);
2196 ipa_clone_references (new_node, NULL, &n->ref_list);
2198 new_node->next_sibling_clone = n->clones;
2199 if (n->clones)
2200 n->clones->prev_sibling_clone = new_node;
2201 n->clones = new_node;
2202 new_node->clone_of = n;
2204 cgraph_call_node_duplication_hooks (n, new_node);
2205 if (n->decl != decl)
2207 struct cgraph_node **slot;
2208 slot = (struct cgraph_node **) htab_find_slot (cgraph_hash, new_node, INSERT);
2209 gcc_assert (!*slot);
2210 *slot = new_node;
2211 if (assembler_name_hash)
2213 void **aslot;
2214 tree name = DECL_ASSEMBLER_NAME (decl);
2216 aslot = htab_find_slot_with_hash (assembler_name_hash, name,
2217 decl_assembler_name_hash (name),
2218 INSERT);
2219 gcc_assert (!*aslot);
2220 *aslot = new_node;
2223 return new_node;
2226 /* Create a new name for clone of DECL, add SUFFIX. Returns an identifier. */
2228 static GTY(()) unsigned int clone_fn_id_num;
2230 tree
2231 clone_function_name (tree decl, const char *suffix)
2233 tree name = DECL_ASSEMBLER_NAME (decl);
2234 size_t len = IDENTIFIER_LENGTH (name);
2235 char *tmp_name, *prefix;
2237 prefix = XALLOCAVEC (char, len + strlen (suffix) + 2);
2238 memcpy (prefix, IDENTIFIER_POINTER (name), len);
2239 strcpy (prefix + len + 1, suffix);
2240 #ifndef NO_DOT_IN_LABEL
2241 prefix[len] = '.';
2242 #elif !defined NO_DOLLAR_IN_LABEL
2243 prefix[len] = '$';
2244 #else
2245 prefix[len] = '_';
2246 #endif
2247 ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix, clone_fn_id_num++);
2248 return get_identifier (tmp_name);
2251 /* Create callgraph node clone with new declaration. The actual body will
2252 be copied later at compilation stage.
2254 TODO: after merging in ipa-sra use function call notes instead of args_to_skip
2255 bitmap interface.
2257 struct cgraph_node *
2258 cgraph_create_virtual_clone (struct cgraph_node *old_node,
2259 VEC(cgraph_edge_p,heap) *redirect_callers,
2260 VEC(ipa_replace_map_p,gc) *tree_map,
2261 bitmap args_to_skip,
2262 const char * suffix)
2264 tree old_decl = old_node->decl;
2265 struct cgraph_node *new_node = NULL;
2266 tree new_decl;
2267 size_t i;
2268 struct ipa_replace_map *map;
2270 if (!flag_wpa)
2271 gcc_checking_assert (tree_versionable_function_p (old_decl));
2273 gcc_assert (old_node->local.can_change_signature || !args_to_skip);
2275 /* Make a new FUNCTION_DECL tree node */
2276 if (!args_to_skip)
2277 new_decl = copy_node (old_decl);
2278 else
2279 new_decl = build_function_decl_skip_args (old_decl, args_to_skip);
2280 DECL_STRUCT_FUNCTION (new_decl) = NULL;
2282 /* Generate a new name for the new version. */
2283 DECL_NAME (new_decl) = clone_function_name (old_decl, suffix);
2284 SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
2285 SET_DECL_RTL (new_decl, NULL);
2287 new_node = cgraph_clone_node (old_node, new_decl, old_node->count,
2288 CGRAPH_FREQ_BASE, 0, false,
2289 redirect_callers);
2290 /* Update the properties.
2291 Make clone visible only within this translation unit. Make sure
2292 that is not weak also.
2293 ??? We cannot use COMDAT linkage because there is no
2294 ABI support for this. */
2295 DECL_EXTERNAL (new_node->decl) = 0;
2296 if (DECL_ONE_ONLY (old_decl))
2297 DECL_SECTION_NAME (new_node->decl) = NULL;
2298 DECL_COMDAT_GROUP (new_node->decl) = 0;
2299 TREE_PUBLIC (new_node->decl) = 0;
2300 DECL_COMDAT (new_node->decl) = 0;
2301 DECL_WEAK (new_node->decl) = 0;
2302 new_node->clone.tree_map = tree_map;
2303 new_node->clone.args_to_skip = args_to_skip;
2304 FOR_EACH_VEC_ELT (ipa_replace_map_p, tree_map, i, map)
2306 tree var = map->new_tree;
2308 STRIP_NOPS (var);
2309 if (TREE_CODE (var) != ADDR_EXPR)
2310 continue;
2311 var = get_base_var (var);
2312 if (!var)
2313 continue;
2315 /* Record references of the future statement initializing the constant
2316 argument. */
2317 if (TREE_CODE (var) == FUNCTION_DECL)
2319 struct cgraph_node *ref_node = cgraph_get_node (var);
2320 gcc_checking_assert (ref_node);
2321 ipa_record_reference (new_node, NULL, ref_node, NULL, IPA_REF_ADDR,
2322 NULL);
2324 else if (TREE_CODE (var) == VAR_DECL)
2325 ipa_record_reference (new_node, NULL, NULL, varpool_node (var),
2326 IPA_REF_ADDR, NULL);
2328 if (!args_to_skip)
2329 new_node->clone.combined_args_to_skip = old_node->clone.combined_args_to_skip;
2330 else if (old_node->clone.combined_args_to_skip)
2332 int newi = 0, oldi = 0;
2333 tree arg;
2334 bitmap new_args_to_skip = BITMAP_GGC_ALLOC ();
2335 struct cgraph_node *orig_node;
2336 for (orig_node = old_node; orig_node->clone_of; orig_node = orig_node->clone_of)
2338 for (arg = DECL_ARGUMENTS (orig_node->decl); arg; arg = DECL_CHAIN (arg), oldi++)
2340 if (bitmap_bit_p (old_node->clone.combined_args_to_skip, oldi))
2342 bitmap_set_bit (new_args_to_skip, oldi);
2343 continue;
2345 if (bitmap_bit_p (args_to_skip, newi))
2346 bitmap_set_bit (new_args_to_skip, oldi);
2347 newi++;
2349 new_node->clone.combined_args_to_skip = new_args_to_skip;
2351 else
2352 new_node->clone.combined_args_to_skip = args_to_skip;
2353 new_node->local.externally_visible = 0;
2354 new_node->local.local = 1;
2355 new_node->lowered = true;
2356 new_node->reachable = true;
2359 return new_node;
2362 /* NODE is no longer nested function; update cgraph accordingly. */
2363 void
2364 cgraph_unnest_node (struct cgraph_node *node)
2366 struct cgraph_node **node2 = &node->origin->nested;
2367 gcc_assert (node->origin);
2369 while (*node2 != node)
2370 node2 = &(*node2)->next_nested;
2371 *node2 = node->next_nested;
2372 node->origin = NULL;
2375 /* Return function availability. See cgraph.h for description of individual
2376 return values. */
2377 enum availability
2378 cgraph_function_body_availability (struct cgraph_node *node)
2380 enum availability avail;
2381 gcc_assert (cgraph_function_flags_ready);
2382 if (!node->analyzed)
2383 avail = AVAIL_NOT_AVAILABLE;
2384 else if (node->local.local)
2385 avail = AVAIL_LOCAL;
2386 else if (!node->local.externally_visible)
2387 avail = AVAIL_AVAILABLE;
2388 /* Inline functions are safe to be analyzed even if their symbol can
2389 be overwritten at runtime. It is not meaningful to enforce any sane
2390 behaviour on replacing inline function by different body. */
2391 else if (DECL_DECLARED_INLINE_P (node->decl))
2392 avail = AVAIL_AVAILABLE;
2394 /* If the function can be overwritten, return OVERWRITABLE. Take
2395 care at least of two notable extensions - the COMDAT functions
2396 used to share template instantiations in C++ (this is symmetric
2397 to code cp_cannot_inline_tree_fn and probably shall be shared and
2398 the inlinability hooks completely eliminated).
2400 ??? Does the C++ one definition rule allow us to always return
2401 AVAIL_AVAILABLE here? That would be good reason to preserve this
2402 bit. */
2404 else if (decl_replaceable_p (node->decl) && !DECL_EXTERNAL (node->decl))
2405 avail = AVAIL_OVERWRITABLE;
2406 else avail = AVAIL_AVAILABLE;
2408 return avail;
2411 /* Add the function FNDECL to the call graph.
2412 Unlike cgraph_finalize_function, this function is intended to be used
2413 by middle end and allows insertion of new function at arbitrary point
2414 of compilation. The function can be either in high, low or SSA form
2415 GIMPLE.
2417 The function is assumed to be reachable and have address taken (so no
2418 API breaking optimizations are performed on it).
2420 Main work done by this function is to enqueue the function for later
2421 processing to avoid need the passes to be re-entrant. */
2423 void
2424 cgraph_add_new_function (tree fndecl, bool lowered)
2426 struct cgraph_node *node;
2427 switch (cgraph_state)
2429 case CGRAPH_STATE_CONSTRUCTION:
2430 /* Just enqueue function to be processed at nearest occurrence. */
2431 node = cgraph_create_node (fndecl);
2432 node->next_needed = cgraph_new_nodes;
2433 if (lowered)
2434 node->lowered = true;
2435 cgraph_new_nodes = node;
2436 break;
2438 case CGRAPH_STATE_IPA:
2439 case CGRAPH_STATE_IPA_SSA:
2440 case CGRAPH_STATE_EXPANSION:
2441 /* Bring the function into finalized state and enqueue for later
2442 analyzing and compilation. */
2443 node = cgraph_get_create_node (fndecl);
2444 node->local.local = false;
2445 node->local.finalized = true;
2446 node->reachable = node->needed = true;
2447 if (!lowered && cgraph_state == CGRAPH_STATE_EXPANSION)
2449 push_cfun (DECL_STRUCT_FUNCTION (fndecl));
2450 current_function_decl = fndecl;
2451 gimple_register_cfg_hooks ();
2452 tree_lowering_passes (fndecl);
2453 bitmap_obstack_initialize (NULL);
2454 if (!gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl)))
2455 execute_pass_list (pass_early_local_passes.pass.sub);
2456 bitmap_obstack_release (NULL);
2457 pop_cfun ();
2458 current_function_decl = NULL;
2460 lowered = true;
2462 if (lowered)
2463 node->lowered = true;
2464 node->next_needed = cgraph_new_nodes;
2465 cgraph_new_nodes = node;
2466 break;
2468 case CGRAPH_STATE_FINISHED:
2469 /* At the very end of compilation we have to do all the work up
2470 to expansion. */
2471 node = cgraph_create_node (fndecl);
2472 if (lowered)
2473 node->lowered = true;
2474 cgraph_analyze_function (node);
2475 push_cfun (DECL_STRUCT_FUNCTION (fndecl));
2476 current_function_decl = fndecl;
2477 gimple_register_cfg_hooks ();
2478 bitmap_obstack_initialize (NULL);
2479 if (!gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl)))
2480 execute_pass_list (pass_early_local_passes.pass.sub);
2481 bitmap_obstack_release (NULL);
2482 tree_rest_of_compilation (fndecl);
2483 pop_cfun ();
2484 current_function_decl = NULL;
2485 break;
2488 /* Set a personality if required and we already passed EH lowering. */
2489 if (lowered
2490 && (function_needs_eh_personality (DECL_STRUCT_FUNCTION (fndecl))
2491 == eh_personality_lang))
2492 DECL_FUNCTION_PERSONALITY (fndecl) = lang_hooks.eh_personality ();
2495 /* Return true if NODE can be made local for API change.
2496 Extern inline functions and C++ COMDAT functions can be made local
2497 at the expense of possible code size growth if function is used in multiple
2498 compilation units. */
2499 bool
2500 cgraph_node_can_be_local_p (struct cgraph_node *node)
2502 return (!node->needed && !node->address_taken
2503 && ((DECL_COMDAT (node->decl) && !node->same_comdat_group)
2504 || !node->local.externally_visible));
2507 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
2508 but other code such as notice_global_symbol generates rtl. */
2509 void
2510 cgraph_make_decl_local (tree decl)
2512 rtx rtl, symbol;
2514 if (TREE_CODE (decl) == VAR_DECL)
2515 DECL_COMMON (decl) = 0;
2516 else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
2518 if (DECL_COMDAT (decl))
2520 /* It is possible that we are linking against library defining same COMDAT
2521 function. To avoid conflict we need to rename our local name of the
2522 function just in the case WHOPR partitioning decide to make it hidden
2523 to avoid cross partition references. */
2524 if (flag_wpa)
2526 const char *old_name;
2528 old_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2529 if (TREE_CODE (decl) == FUNCTION_DECL)
2531 struct cgraph_node *node = cgraph_get_node_or_alias (decl);
2532 change_decl_assembler_name (decl,
2533 clone_function_name (decl, "local"));
2534 if (node->local.lto_file_data)
2535 lto_record_renamed_decl (node->local.lto_file_data,
2536 old_name,
2537 IDENTIFIER_POINTER
2538 (DECL_ASSEMBLER_NAME (decl)));
2540 else if (TREE_CODE (decl) == VAR_DECL)
2542 struct varpool_node *vnode = varpool_get_node (decl);
2543 /* change_decl_assembler_name will warn here on vtables because
2544 C++ frontend still sets TREE_SYMBOL_REFERENCED on them. */
2545 SET_DECL_ASSEMBLER_NAME (decl,
2546 clone_function_name (decl, "local"));
2547 if (vnode->lto_file_data)
2548 lto_record_renamed_decl (vnode->lto_file_data,
2549 old_name,
2550 IDENTIFIER_POINTER
2551 (DECL_ASSEMBLER_NAME (decl)));
2554 DECL_SECTION_NAME (decl) = 0;
2555 DECL_COMDAT (decl) = 0;
2557 DECL_COMDAT_GROUP (decl) = 0;
2558 DECL_WEAK (decl) = 0;
2559 DECL_EXTERNAL (decl) = 0;
2560 TREE_PUBLIC (decl) = 0;
2561 if (!DECL_RTL_SET_P (decl))
2562 return;
2564 /* Update rtl flags. */
2565 make_decl_rtl (decl);
2567 rtl = DECL_RTL (decl);
2568 if (!MEM_P (rtl))
2569 return;
2571 symbol = XEXP (rtl, 0);
2572 if (GET_CODE (symbol) != SYMBOL_REF)
2573 return;
2575 SYMBOL_REF_WEAK (symbol) = DECL_WEAK (decl);
2578 /* Bring NODE local. */
2579 void
2580 cgraph_make_node_local (struct cgraph_node *node)
2582 gcc_assert (cgraph_node_can_be_local_p (node));
2583 if (DECL_COMDAT (node->decl) || DECL_EXTERNAL (node->decl))
2585 struct cgraph_node *alias;
2586 cgraph_make_decl_local (node->decl);
2588 for (alias = node->same_body; alias; alias = alias->next)
2589 cgraph_make_decl_local (alias->decl);
2591 node->local.externally_visible = false;
2592 node->local.local = true;
2593 node->resolution = LDPR_PREVAILING_DEF_IRONLY;
2594 gcc_assert (cgraph_function_body_availability (node) == AVAIL_LOCAL);
2598 /* Set TREE_NOTHROW on NODE's decl and on same_body aliases of NODE
2599 if any to NOTHROW. */
2601 void
2602 cgraph_set_nothrow_flag (struct cgraph_node *node, bool nothrow)
2604 struct cgraph_node *alias;
2605 TREE_NOTHROW (node->decl) = nothrow;
2606 for (alias = node->same_body; alias; alias = alias->next)
2607 TREE_NOTHROW (alias->decl) = nothrow;
2610 /* Set TREE_READONLY on NODE's decl and on same_body aliases of NODE
2611 if any to READONLY. */
2613 void
2614 cgraph_set_const_flag (struct cgraph_node *node, bool readonly, bool looping)
2616 struct cgraph_node *alias;
2617 /* Static constructors and destructors without a side effect can be
2618 optimized out. */
2619 if (!looping && readonly)
2621 if (DECL_STATIC_CONSTRUCTOR (node->decl))
2622 DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
2623 if (DECL_STATIC_DESTRUCTOR (node->decl))
2624 DECL_STATIC_DESTRUCTOR (node->decl) = 0;
2626 TREE_READONLY (node->decl) = readonly;
2627 DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
2628 for (alias = node->same_body; alias; alias = alias->next)
2630 TREE_READONLY (alias->decl) = readonly;
2631 DECL_LOOPING_CONST_OR_PURE_P (alias->decl) = looping;
2635 /* Set DECL_PURE_P on NODE's decl and on same_body aliases of NODE
2636 if any to PURE. */
2638 void
2639 cgraph_set_pure_flag (struct cgraph_node *node, bool pure, bool looping)
2641 struct cgraph_node *alias;
2642 /* Static constructors and destructors without a side effect can be
2643 optimized out. */
2644 if (!looping && pure)
2646 if (DECL_STATIC_CONSTRUCTOR (node->decl))
2647 DECL_STATIC_CONSTRUCTOR (node->decl) = 0;
2648 if (DECL_STATIC_DESTRUCTOR (node->decl))
2649 DECL_STATIC_DESTRUCTOR (node->decl) = 0;
2651 DECL_PURE_P (node->decl) = pure;
2652 DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping;
2653 for (alias = node->same_body; alias; alias = alias->next)
2655 DECL_PURE_P (alias->decl) = pure;
2656 DECL_LOOPING_CONST_OR_PURE_P (alias->decl) = looping;
2660 /* See if the frequency of NODE can be updated based on frequencies of its
2661 callers. */
2662 bool
2663 cgraph_propagate_frequency (struct cgraph_node *node)
2665 bool maybe_unlikely_executed = true, maybe_executed_once = true;
2666 bool only_called_at_startup = true;
2667 bool only_called_at_exit = true;
2668 bool changed = false;
2669 struct cgraph_edge *edge;
2671 if (!node->local.local)
2672 return false;
2673 gcc_assert (node->analyzed);
2674 if (dump_file && (dump_flags & TDF_DETAILS))
2675 fprintf (dump_file, "Processing frequency %s\n", cgraph_node_name (node));
2677 for (edge = node->callers;
2678 edge && (maybe_unlikely_executed || maybe_executed_once
2679 || only_called_at_startup || only_called_at_exit);
2680 edge = edge->next_caller)
2682 if (edge->caller != node)
2684 only_called_at_startup &= edge->caller->only_called_at_startup;
2685 /* It makes sense to put main() together with the static constructors.
2686 It will be executed for sure, but rest of functions called from
2687 main are definitely not at startup only. */
2688 if (MAIN_NAME_P (DECL_NAME (edge->caller->decl)))
2689 only_called_at_startup = 0;
2690 only_called_at_exit &= edge->caller->only_called_at_exit;
2692 if (!edge->frequency)
2693 continue;
2694 switch (edge->caller->frequency)
2696 case NODE_FREQUENCY_UNLIKELY_EXECUTED:
2697 break;
2698 case NODE_FREQUENCY_EXECUTED_ONCE:
2699 if (dump_file && (dump_flags & TDF_DETAILS))
2700 fprintf (dump_file, " Called by %s that is executed once\n",
2701 cgraph_node_name (edge->caller));
2702 maybe_unlikely_executed = false;
2703 if (edge->loop_nest)
2705 maybe_executed_once = false;
2706 if (dump_file && (dump_flags & TDF_DETAILS))
2707 fprintf (dump_file, " Called in loop\n");
2709 break;
2710 case NODE_FREQUENCY_HOT:
2711 case NODE_FREQUENCY_NORMAL:
2712 if (dump_file && (dump_flags & TDF_DETAILS))
2713 fprintf (dump_file, " Called by %s that is normal or hot\n",
2714 cgraph_node_name (edge->caller));
2715 maybe_unlikely_executed = false;
2716 maybe_executed_once = false;
2717 break;
2720 if ((only_called_at_startup && !only_called_at_exit)
2721 && !node->only_called_at_startup)
2723 node->only_called_at_startup = true;
2724 if (dump_file)
2725 fprintf (dump_file, "Node %s promoted to only called at startup.\n",
2726 cgraph_node_name (node));
2727 changed = true;
2729 if ((only_called_at_exit && !only_called_at_startup)
2730 && !node->only_called_at_exit)
2732 node->only_called_at_exit = true;
2733 if (dump_file)
2734 fprintf (dump_file, "Node %s promoted to only called at exit.\n",
2735 cgraph_node_name (node));
2736 changed = true;
2738 /* These come either from profile or user hints; never update them. */
2739 if (node->frequency == NODE_FREQUENCY_HOT
2740 || node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
2741 return changed;
2742 if (maybe_unlikely_executed)
2744 node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
2745 if (dump_file)
2746 fprintf (dump_file, "Node %s promoted to unlikely executed.\n",
2747 cgraph_node_name (node));
2748 changed = true;
2750 else if (maybe_executed_once && node->frequency != NODE_FREQUENCY_EXECUTED_ONCE)
2752 node->frequency = NODE_FREQUENCY_EXECUTED_ONCE;
2753 if (dump_file)
2754 fprintf (dump_file, "Node %s promoted to executed once.\n",
2755 cgraph_node_name (node));
2756 changed = true;
2758 return changed;
2761 /* Return true when NODE can not return or throw and thus
2762 it is safe to ignore its side effects for IPA analysis. */
2764 bool
2765 cgraph_node_cannot_return (struct cgraph_node *node)
2767 int flags = flags_from_decl_or_type (node->decl);
2768 if (!flag_exceptions)
2769 return (flags & ECF_NORETURN) != 0;
2770 else
2771 return ((flags & (ECF_NORETURN | ECF_NOTHROW))
2772 == (ECF_NORETURN | ECF_NOTHROW));
2775 /* Return true when call of E can not lead to return from caller
2776 and thus it is safe to ignore its side effects for IPA analysis
2777 when computing side effects of the caller.
2778 FIXME: We could actually mark all edges that have no reaching
2779 patch to EXIT_BLOCK_PTR or throw to get better results. */
2780 bool
2781 cgraph_edge_cannot_lead_to_return (struct cgraph_edge *e)
2783 if (cgraph_node_cannot_return (e->caller))
2784 return true;
2785 if (e->indirect_unknown_callee)
2787 int flags = e->indirect_info->ecf_flags;
2788 if (!flag_exceptions)
2789 return (flags & ECF_NORETURN) != 0;
2790 else
2791 return ((flags & (ECF_NORETURN | ECF_NOTHROW))
2792 == (ECF_NORETURN | ECF_NOTHROW));
2794 else
2795 return cgraph_node_cannot_return (e->callee);
2798 /* Return true when function NODE can be removed from callgraph
2799 if all direct calls are eliminated. */
2801 bool
2802 cgraph_can_remove_if_no_direct_calls_and_refs_p (struct cgraph_node *node)
2804 gcc_assert (!node->global.inlined_to);
2805 /* Extern inlines can always go, we will use the external definition. */
2806 if (DECL_EXTERNAL (node->decl))
2807 return true;
2808 /* When function is needed, we can not remove it. */
2809 if (node->needed || node->reachable_from_other_partition)
2810 return false;
2811 if (DECL_STATIC_CONSTRUCTOR (node->decl)
2812 || DECL_STATIC_DESTRUCTOR (node->decl))
2813 return false;
2814 /* Only COMDAT functions can be removed if externally visible. */
2815 if (node->local.externally_visible
2816 && (!DECL_COMDAT (node->decl)
2817 || cgraph_used_from_object_file_p (node)))
2818 return false;
2819 return true;
2822 /* Return true when function NODE can be expected to be removed
2823 from program when direct calls in this compilation unit are removed.
2825 As a special case COMDAT functions are
2826 cgraph_can_remove_if_no_direct_calls_p while the are not
2827 cgraph_only_called_directly_p (it is possible they are called from other
2828 unit)
2830 This function behaves as cgraph_only_called_directly_p because eliminating
2831 all uses of COMDAT function does not make it necessarily disappear from
2832 the program unless we are compiling whole program or we do LTO. In this
2833 case we know we win since dynamic linking will not really discard the
2834 linkonce section. */
2836 bool
2837 cgraph_will_be_removed_from_program_if_no_direct_calls (struct cgraph_node *node)
2839 gcc_assert (!node->global.inlined_to);
2840 if (cgraph_used_from_object_file_p (node))
2841 return false;
2842 if (!in_lto_p && !flag_whole_program)
2843 return cgraph_only_called_directly_p (node);
2844 else
2846 if (DECL_EXTERNAL (node->decl))
2847 return true;
2848 return cgraph_can_remove_if_no_direct_calls_p (node);
2852 /* Return true when RESOLUTION indicate that linker will use
2853 the symbol from non-LTO object files. */
2855 bool
2856 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution)
2858 return (resolution == LDPR_PREVAILING_DEF
2859 || resolution == LDPR_PREEMPTED_REG
2860 || resolution == LDPR_RESOLVED_EXEC
2861 || resolution == LDPR_RESOLVED_DYN);
2864 /* Return true when NODE is known to be used from other (non-LTO) object file.
2865 Known only when doing LTO via linker plugin. */
2867 bool
2868 cgraph_used_from_object_file_p (struct cgraph_node *node)
2870 struct cgraph_node *alias;
2872 gcc_assert (!node->global.inlined_to);
2873 if (!TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl))
2874 return false;
2875 if (resolution_used_from_other_file_p (node->resolution))
2876 return true;
2877 for (alias = node->same_body; alias; alias = alias->next)
2878 if (TREE_PUBLIC (alias->decl)
2879 && resolution_used_from_other_file_p (alias->resolution))
2880 return true;
2881 return false;
2884 #include "gt-cgraph.h"