1 /* Callgraph handling code.
2 Copyright (C) 2003-2013 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
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
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
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/>. */
21 /* This file contains basic routines manipulating call graph
23 The call-graph is a data structure designed for intra-procedural optimization.
24 It represents a multi-graph where nodes are functions and edges are call sites. */
28 #include "coretypes.h"
31 #include "tree-inline.h"
32 #include "langhooks.h"
39 #include "basic-block.h"
45 #include "tree-flow.h"
46 #include "value-prof.h"
48 #include "diagnostic-core.h"
50 #include "ipa-utils.h"
51 #include "lto-streamer.h"
52 #include "ipa-inline.h"
54 #include "gimple-pretty-print.h"
56 /* FIXME: Only for PROP_loops, but cgraph shouldn't have to know about this. */
57 #include "tree-pass.h"
59 static void cgraph_node_remove_callers (struct cgraph_node
*node
);
60 static inline void cgraph_edge_remove_caller (struct cgraph_edge
*e
);
61 static inline void cgraph_edge_remove_callee (struct cgraph_edge
*e
);
63 /* Queue of cgraph nodes scheduled to be lowered. */
64 symtab_node x_cgraph_nodes_queue
;
65 #define cgraph_nodes_queue ((struct cgraph_node *)x_cgraph_nodes_queue)
67 /* Number of nodes in existence. */
70 /* Maximal uid used in cgraph nodes. */
73 /* Maximal uid used in cgraph edges. */
74 int cgraph_edge_max_uid
;
76 /* Set when whole unit has been analyzed so we can access global info. */
77 bool cgraph_global_info_ready
= false;
79 /* What state callgraph is in right now. */
80 enum cgraph_state cgraph_state
= CGRAPH_STATE_PARSING
;
82 /* Set when the cgraph is fully build and the basic flags are computed. */
83 bool cgraph_function_flags_ready
= false;
85 /* List of hooks triggered on cgraph_edge events. */
86 struct cgraph_edge_hook_list
{
87 cgraph_edge_hook hook
;
89 struct cgraph_edge_hook_list
*next
;
92 /* List of hooks triggered on cgraph_node events. */
93 struct cgraph_node_hook_list
{
94 cgraph_node_hook hook
;
96 struct cgraph_node_hook_list
*next
;
99 /* List of hooks triggered on events involving two cgraph_edges. */
100 struct cgraph_2edge_hook_list
{
101 cgraph_2edge_hook hook
;
103 struct cgraph_2edge_hook_list
*next
;
106 /* List of hooks triggered on events involving two cgraph_nodes. */
107 struct cgraph_2node_hook_list
{
108 cgraph_2node_hook hook
;
110 struct cgraph_2node_hook_list
*next
;
113 /* List of hooks triggered when an edge is removed. */
114 struct cgraph_edge_hook_list
*first_cgraph_edge_removal_hook
;
115 /* List of hooks triggered when a node is removed. */
116 struct cgraph_node_hook_list
*first_cgraph_node_removal_hook
;
117 /* List of hooks triggered when an edge is duplicated. */
118 struct cgraph_2edge_hook_list
*first_cgraph_edge_duplicated_hook
;
119 /* List of hooks triggered when a node is duplicated. */
120 struct cgraph_2node_hook_list
*first_cgraph_node_duplicated_hook
;
121 /* List of hooks triggered when an function is inserted. */
122 struct cgraph_node_hook_list
*first_cgraph_function_insertion_hook
;
124 /* Head of a linked list of unused (freed) call graph nodes.
125 Do not GTY((delete)) this list so UIDs gets reliably recycled. */
126 static GTY(()) struct cgraph_node
*free_nodes
;
127 /* Head of a linked list of unused (freed) call graph edges.
128 Do not GTY((delete)) this list so UIDs gets reliably recycled. */
129 static GTY(()) struct cgraph_edge
*free_edges
;
131 /* Did procss_same_body_aliases run? */
132 bool cpp_implicit_aliases_done
;
134 /* Map a cgraph_node to cgraph_function_version_info using this htab.
135 The cgraph_function_version_info has a THIS_NODE field that is the
136 corresponding cgraph_node.. */
138 static htab_t
GTY((param_is (struct cgraph_function_version_info
*)))
139 cgraph_fnver_htab
= NULL
;
141 /* Hash function for cgraph_fnver_htab. */
143 cgraph_fnver_htab_hash (const void *ptr
)
145 int uid
= ((const struct cgraph_function_version_info
*)ptr
)->this_node
->uid
;
146 return (hashval_t
)(uid
);
149 /* eq function for cgraph_fnver_htab. */
151 cgraph_fnver_htab_eq (const void *p1
, const void *p2
)
153 const struct cgraph_function_version_info
*n1
154 = (const struct cgraph_function_version_info
*)p1
;
155 const struct cgraph_function_version_info
*n2
156 = (const struct cgraph_function_version_info
*)p2
;
158 return n1
->this_node
->uid
== n2
->this_node
->uid
;
161 /* Mark as GC root all allocated nodes. */
162 static GTY(()) struct cgraph_function_version_info
*
163 version_info_node
= NULL
;
165 /* Get the cgraph_function_version_info node corresponding to node. */
166 struct cgraph_function_version_info
*
167 get_cgraph_node_version (struct cgraph_node
*node
)
169 struct cgraph_function_version_info
*ret
;
170 struct cgraph_function_version_info key
;
171 key
.this_node
= node
;
173 if (cgraph_fnver_htab
== NULL
)
176 ret
= (struct cgraph_function_version_info
*)
177 htab_find (cgraph_fnver_htab
, &key
);
182 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
183 corresponding to cgraph_node NODE. */
184 struct cgraph_function_version_info
*
185 insert_new_cgraph_node_version (struct cgraph_node
*node
)
189 version_info_node
= NULL
;
190 version_info_node
= ggc_alloc_cleared_cgraph_function_version_info ();
191 version_info_node
->this_node
= node
;
193 if (cgraph_fnver_htab
== NULL
)
194 cgraph_fnver_htab
= htab_create_ggc (2, cgraph_fnver_htab_hash
,
195 cgraph_fnver_htab_eq
, NULL
);
197 slot
= htab_find_slot (cgraph_fnver_htab
, version_info_node
, INSERT
);
198 gcc_assert (slot
!= NULL
);
199 *slot
= version_info_node
;
200 return version_info_node
;
203 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
204 DECL is a duplicate declaration. */
206 delete_function_version (tree decl
)
208 struct cgraph_node
*decl_node
= cgraph_get_node (decl
);
209 struct cgraph_function_version_info
*decl_v
= NULL
;
211 if (decl_node
== NULL
)
214 decl_v
= get_cgraph_node_version (decl_node
);
219 if (decl_v
->prev
!= NULL
)
220 decl_v
->prev
->next
= decl_v
->next
;
222 if (decl_v
->next
!= NULL
)
223 decl_v
->next
->prev
= decl_v
->prev
;
225 if (cgraph_fnver_htab
!= NULL
)
226 htab_remove_elt (cgraph_fnver_htab
, decl_v
);
228 cgraph_remove_node (decl_node
);
231 /* Record that DECL1 and DECL2 are semantically identical function
234 record_function_versions (tree decl1
, tree decl2
)
236 struct cgraph_node
*decl1_node
= cgraph_get_create_node (decl1
);
237 struct cgraph_node
*decl2_node
= cgraph_get_create_node (decl2
);
238 struct cgraph_function_version_info
*decl1_v
= NULL
;
239 struct cgraph_function_version_info
*decl2_v
= NULL
;
240 struct cgraph_function_version_info
*before
;
241 struct cgraph_function_version_info
*after
;
243 gcc_assert (decl1_node
!= NULL
&& decl2_node
!= NULL
);
244 decl1_v
= get_cgraph_node_version (decl1_node
);
245 decl2_v
= get_cgraph_node_version (decl2_node
);
247 if (decl1_v
!= NULL
&& decl2_v
!= NULL
)
251 decl1_v
= insert_new_cgraph_node_version (decl1_node
);
254 decl2_v
= insert_new_cgraph_node_version (decl2_node
);
256 /* Chain decl2_v and decl1_v. All semantically identical versions
257 will be chained together. */
262 while (before
->next
!= NULL
)
263 before
= before
->next
;
265 while (after
->prev
!= NULL
)
268 before
->next
= after
;
269 after
->prev
= before
;
272 /* Macros to access the next item in the list of free cgraph nodes and
274 #define NEXT_FREE_NODE(NODE) cgraph ((NODE)->symbol.next)
275 #define SET_NEXT_FREE_NODE(NODE,NODE2) ((NODE))->symbol.next = (symtab_node)NODE2
276 #define NEXT_FREE_EDGE(EDGE) (EDGE)->prev_caller
278 /* Register HOOK to be called with DATA on each removed edge. */
279 struct cgraph_edge_hook_list
*
280 cgraph_add_edge_removal_hook (cgraph_edge_hook hook
, void *data
)
282 struct cgraph_edge_hook_list
*entry
;
283 struct cgraph_edge_hook_list
**ptr
= &first_cgraph_edge_removal_hook
;
285 entry
= (struct cgraph_edge_hook_list
*) xmalloc (sizeof (*entry
));
295 /* Remove ENTRY from the list of hooks called on removing edges. */
297 cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list
*entry
)
299 struct cgraph_edge_hook_list
**ptr
= &first_cgraph_edge_removal_hook
;
301 while (*ptr
!= entry
)
307 /* Call all edge removal hooks. */
309 cgraph_call_edge_removal_hooks (struct cgraph_edge
*e
)
311 struct cgraph_edge_hook_list
*entry
= first_cgraph_edge_removal_hook
;
314 entry
->hook (e
, entry
->data
);
319 /* Register HOOK to be called with DATA on each removed node. */
320 struct cgraph_node_hook_list
*
321 cgraph_add_node_removal_hook (cgraph_node_hook hook
, void *data
)
323 struct cgraph_node_hook_list
*entry
;
324 struct cgraph_node_hook_list
**ptr
= &first_cgraph_node_removal_hook
;
326 entry
= (struct cgraph_node_hook_list
*) xmalloc (sizeof (*entry
));
336 /* Remove ENTRY from the list of hooks called on removing nodes. */
338 cgraph_remove_node_removal_hook (struct cgraph_node_hook_list
*entry
)
340 struct cgraph_node_hook_list
**ptr
= &first_cgraph_node_removal_hook
;
342 while (*ptr
!= entry
)
348 /* Call all node removal hooks. */
350 cgraph_call_node_removal_hooks (struct cgraph_node
*node
)
352 struct cgraph_node_hook_list
*entry
= first_cgraph_node_removal_hook
;
355 entry
->hook (node
, entry
->data
);
360 /* Register HOOK to be called with DATA on each inserted node. */
361 struct cgraph_node_hook_list
*
362 cgraph_add_function_insertion_hook (cgraph_node_hook hook
, void *data
)
364 struct cgraph_node_hook_list
*entry
;
365 struct cgraph_node_hook_list
**ptr
= &first_cgraph_function_insertion_hook
;
367 entry
= (struct cgraph_node_hook_list
*) xmalloc (sizeof (*entry
));
377 /* Remove ENTRY from the list of hooks called on inserted nodes. */
379 cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list
*entry
)
381 struct cgraph_node_hook_list
**ptr
= &first_cgraph_function_insertion_hook
;
383 while (*ptr
!= entry
)
389 /* Call all node insertion hooks. */
391 cgraph_call_function_insertion_hooks (struct cgraph_node
*node
)
393 struct cgraph_node_hook_list
*entry
= first_cgraph_function_insertion_hook
;
396 entry
->hook (node
, entry
->data
);
401 /* Register HOOK to be called with DATA on each duplicated edge. */
402 struct cgraph_2edge_hook_list
*
403 cgraph_add_edge_duplication_hook (cgraph_2edge_hook hook
, void *data
)
405 struct cgraph_2edge_hook_list
*entry
;
406 struct cgraph_2edge_hook_list
**ptr
= &first_cgraph_edge_duplicated_hook
;
408 entry
= (struct cgraph_2edge_hook_list
*) xmalloc (sizeof (*entry
));
418 /* Remove ENTRY from the list of hooks called on duplicating edges. */
420 cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list
*entry
)
422 struct cgraph_2edge_hook_list
**ptr
= &first_cgraph_edge_duplicated_hook
;
424 while (*ptr
!= entry
)
430 /* Call all edge duplication hooks. */
432 cgraph_call_edge_duplication_hooks (struct cgraph_edge
*cs1
,
433 struct cgraph_edge
*cs2
)
435 struct cgraph_2edge_hook_list
*entry
= first_cgraph_edge_duplicated_hook
;
438 entry
->hook (cs1
, cs2
, entry
->data
);
443 /* Register HOOK to be called with DATA on each duplicated node. */
444 struct cgraph_2node_hook_list
*
445 cgraph_add_node_duplication_hook (cgraph_2node_hook hook
, void *data
)
447 struct cgraph_2node_hook_list
*entry
;
448 struct cgraph_2node_hook_list
**ptr
= &first_cgraph_node_duplicated_hook
;
450 entry
= (struct cgraph_2node_hook_list
*) xmalloc (sizeof (*entry
));
460 /* Remove ENTRY from the list of hooks called on duplicating nodes. */
462 cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list
*entry
)
464 struct cgraph_2node_hook_list
**ptr
= &first_cgraph_node_duplicated_hook
;
466 while (*ptr
!= entry
)
472 /* Call all node duplication hooks. */
474 cgraph_call_node_duplication_hooks (struct cgraph_node
*node1
,
475 struct cgraph_node
*node2
)
477 struct cgraph_2node_hook_list
*entry
= first_cgraph_node_duplicated_hook
;
480 entry
->hook (node1
, node2
, entry
->data
);
485 /* Allocate new callgraph node. */
487 static inline struct cgraph_node
*
488 cgraph_allocate_node (void)
490 struct cgraph_node
*node
;
495 free_nodes
= NEXT_FREE_NODE (node
);
499 node
= ggc_alloc_cleared_cgraph_node ();
500 node
->uid
= cgraph_max_uid
++;
506 /* Allocate new callgraph node and insert it into basic data structures. */
509 cgraph_create_empty_node (void)
511 struct cgraph_node
*node
= cgraph_allocate_node ();
513 node
->symbol
.type
= SYMTAB_FUNCTION
;
514 node
->frequency
= NODE_FREQUENCY_NORMAL
;
515 node
->count_materialization_scale
= REG_BR_PROB_BASE
;
520 /* Return cgraph node assigned to DECL. Create new one when needed. */
523 cgraph_create_node (tree decl
)
525 struct cgraph_node
*node
= cgraph_create_empty_node ();
526 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
528 node
->symbol
.decl
= decl
;
529 symtab_register_node ((symtab_node
) node
);
531 if (DECL_CONTEXT (decl
) && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
533 node
->origin
= cgraph_get_create_node (DECL_CONTEXT (decl
));
534 node
->next_nested
= node
->origin
->nested
;
535 node
->origin
->nested
= node
;
540 /* Try to find a call graph node for declaration DECL and if it does not exist,
544 cgraph_get_create_node (tree decl
)
546 struct cgraph_node
*node
;
548 node
= cgraph_get_node (decl
);
552 return cgraph_create_node (decl
);
555 /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
556 the function body is associated with (not necessarily cgraph_node (DECL). */
559 cgraph_create_function_alias (tree alias
, tree target
)
561 struct cgraph_node
*alias_node
;
563 gcc_assert (TREE_CODE (target
) == FUNCTION_DECL
564 || TREE_CODE (target
) == IDENTIFIER_NODE
);
565 gcc_assert (TREE_CODE (alias
) == FUNCTION_DECL
);
566 alias_node
= cgraph_get_create_node (alias
);
567 gcc_assert (!alias_node
->symbol
.definition
);
568 alias_node
->symbol
.alias_target
= target
;
569 alias_node
->symbol
.definition
= true;
570 alias_node
->symbol
.alias
= true;
571 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias
)) != NULL
)
572 alias_node
->symbol
.weakref
= true;
576 /* Attempt to mark ALIAS as an alias to DECL. Return alias node if successful
578 Same body aliases are output whenever the body of DECL is output,
579 and cgraph_get_node (ALIAS) transparently returns cgraph_get_node (DECL). */
582 cgraph_same_body_alias (struct cgraph_node
*decl_node ATTRIBUTE_UNUSED
, tree alias
, tree decl
)
584 struct cgraph_node
*n
;
585 #ifndef ASM_OUTPUT_DEF
586 /* If aliases aren't supported by the assembler, fail. */
589 /* Langhooks can create same body aliases of symbols not defined.
590 Those are useless. Drop them on the floor. */
591 if (cgraph_global_info_ready
)
594 n
= cgraph_create_function_alias (alias
, decl
);
595 n
->symbol
.cpp_implicit_alias
= true;
596 if (cpp_implicit_aliases_done
)
597 symtab_resolve_alias ((symtab_node
)n
,
598 (symtab_node
)cgraph_get_node (decl
));
602 /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
603 aliases DECL with an adjustments made into the first parameter.
604 See comments in thunk_adjust for detail on the parameters. */
607 cgraph_add_thunk (struct cgraph_node
*decl_node ATTRIBUTE_UNUSED
,
608 tree alias
, tree decl ATTRIBUTE_UNUSED
,
610 HOST_WIDE_INT fixed_offset
, HOST_WIDE_INT virtual_value
,
614 struct cgraph_node
*node
;
616 node
= cgraph_get_node (alias
);
619 gcc_assert (node
->symbol
.definition
);
620 gcc_assert (!node
->symbol
.alias
);
621 gcc_assert (!node
->thunk
.thunk_p
);
622 cgraph_remove_node (node
);
625 node
= cgraph_create_node (alias
);
626 gcc_checking_assert (!virtual_offset
627 || tree_to_double_int (virtual_offset
) ==
628 double_int::from_shwi (virtual_value
));
629 node
->thunk
.fixed_offset
= fixed_offset
;
630 node
->thunk
.this_adjusting
= this_adjusting
;
631 node
->thunk
.virtual_value
= virtual_value
;
632 node
->thunk
.virtual_offset_p
= virtual_offset
!= NULL
;
633 node
->thunk
.alias
= real_alias
;
634 node
->thunk
.thunk_p
= true;
635 node
->symbol
.definition
= true;
640 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
641 Return NULL if there's no such node. */
644 cgraph_node_for_asm (tree asmname
)
646 /* We do not want to look at inline clones. */
647 for (symtab_node node
= symtab_node_for_asm (asmname
);
649 node
= node
->symbol
.next_sharing_asm_name
)
651 cgraph_node
*cn
= dyn_cast
<cgraph_node
> (node
);
652 if (cn
&& !cn
->global
.inlined_to
)
658 /* Returns a hash value for X (which really is a cgraph_edge). */
661 edge_hash (const void *x
)
663 return htab_hash_pointer (((const struct cgraph_edge
*) x
)->call_stmt
);
666 /* Return nonzero if the call_stmt of of cgraph_edge X is stmt *Y. */
669 edge_eq (const void *x
, const void *y
)
671 return ((const struct cgraph_edge
*) x
)->call_stmt
== y
;
674 /* Add call graph edge E to call site hash of its caller. */
677 cgraph_update_edge_in_call_site_hash (struct cgraph_edge
*e
)
680 slot
= htab_find_slot_with_hash (e
->caller
->call_site_hash
,
682 htab_hash_pointer (e
->call_stmt
),
687 /* Add call graph edge E to call site hash of its caller. */
690 cgraph_add_edge_to_call_site_hash (struct cgraph_edge
*e
)
693 /* There are two speculative edges for every statement (one direct,
694 one indirect); always hash the direct one. */
695 if (e
->speculative
&& e
->indirect_unknown_callee
)
697 slot
= htab_find_slot_with_hash (e
->caller
->call_site_hash
,
699 htab_hash_pointer (e
->call_stmt
),
703 gcc_assert (((struct cgraph_edge
*)*slot
)->speculative
);
706 gcc_assert (!*slot
|| e
->speculative
);
710 /* Return the callgraph edge representing the GIMPLE_CALL statement
714 cgraph_edge (struct cgraph_node
*node
, gimple call_stmt
)
716 struct cgraph_edge
*e
, *e2
;
719 if (node
->call_site_hash
)
720 return (struct cgraph_edge
*)
721 htab_find_with_hash (node
->call_site_hash
, call_stmt
,
722 htab_hash_pointer (call_stmt
));
724 /* This loop may turn out to be performance problem. In such case adding
725 hashtables into call nodes with very many edges is probably best
726 solution. It is not good idea to add pointer into CALL_EXPR itself
727 because we want to make possible having multiple cgraph nodes representing
728 different clones of the same body before the body is actually cloned. */
729 for (e
= node
->callees
; e
; e
= e
->next_callee
)
731 if (e
->call_stmt
== call_stmt
)
737 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
739 if (e
->call_stmt
== call_stmt
)
746 node
->call_site_hash
= htab_create_ggc (120, edge_hash
, edge_eq
, NULL
);
747 for (e2
= node
->callees
; e2
; e2
= e2
->next_callee
)
748 cgraph_add_edge_to_call_site_hash (e2
);
749 for (e2
= node
->indirect_calls
; e2
; e2
= e2
->next_callee
)
750 cgraph_add_edge_to_call_site_hash (e2
);
757 /* Change field call_stmt of edge E to NEW_STMT.
758 If UPDATE_SPECULATIVE and E is any component of speculative
759 edge, then update all components. */
762 cgraph_set_call_stmt (struct cgraph_edge
*e
, gimple new_stmt
,
763 bool update_speculative
)
767 /* Speculative edges has three component, update all of them
769 if (update_speculative
&& e
->speculative
)
771 struct cgraph_edge
*direct
, *indirect
;
774 cgraph_speculative_call_info (e
, direct
, indirect
, ref
);
775 cgraph_set_call_stmt (direct
, new_stmt
, false);
776 cgraph_set_call_stmt (indirect
, new_stmt
, false);
777 ref
->stmt
= new_stmt
;
781 /* Only direct speculative edges go to call_site_hash. */
782 if (e
->caller
->call_site_hash
783 && (!e
->speculative
|| !e
->indirect_unknown_callee
))
785 htab_remove_elt_with_hash (e
->caller
->call_site_hash
,
787 htab_hash_pointer (e
->call_stmt
));
790 e
->call_stmt
= new_stmt
;
791 if (e
->indirect_unknown_callee
792 && (decl
= gimple_call_fndecl (new_stmt
)))
794 /* Constant propagation (and possibly also inlining?) can turn an
795 indirect call into a direct one. */
796 struct cgraph_node
*new_callee
= cgraph_get_node (decl
);
798 gcc_checking_assert (new_callee
);
799 e
= cgraph_make_edge_direct (e
, new_callee
);
802 push_cfun (DECL_STRUCT_FUNCTION (e
->caller
->symbol
.decl
));
803 e
->can_throw_external
= stmt_can_throw_external (new_stmt
);
805 if (e
->caller
->call_site_hash
)
806 cgraph_add_edge_to_call_site_hash (e
);
809 /* Allocate a cgraph_edge structure and fill it with data according to the
810 parameters of which only CALLEE can be NULL (when creating an indirect call
813 static struct cgraph_edge
*
814 cgraph_create_edge_1 (struct cgraph_node
*caller
, struct cgraph_node
*callee
,
815 gimple call_stmt
, gcov_type count
, int freq
)
817 struct cgraph_edge
*edge
;
819 /* LTO does not actually have access to the call_stmt since these
820 have not been loaded yet. */
823 /* This is a rather expensive check possibly triggering
824 construction of call stmt hashtable. */
825 #ifdef ENABLE_CHECKING
826 struct cgraph_edge
*e
;
827 gcc_checking_assert (!(e
=cgraph_edge (caller
, call_stmt
)) || e
->speculative
);
830 gcc_assert (is_gimple_call (call_stmt
));
836 free_edges
= NEXT_FREE_EDGE (edge
);
840 edge
= ggc_alloc_cgraph_edge ();
841 edge
->uid
= cgraph_edge_max_uid
++;
845 edge
->caller
= caller
;
846 edge
->callee
= callee
;
847 edge
->prev_caller
= NULL
;
848 edge
->next_caller
= NULL
;
849 edge
->prev_callee
= NULL
;
850 edge
->next_callee
= NULL
;
851 edge
->lto_stmt_uid
= 0;
854 gcc_assert (count
>= 0);
855 edge
->frequency
= freq
;
856 gcc_assert (freq
>= 0);
857 gcc_assert (freq
<= CGRAPH_FREQ_MAX
);
859 edge
->call_stmt
= call_stmt
;
860 push_cfun (DECL_STRUCT_FUNCTION (caller
->symbol
.decl
));
861 edge
->can_throw_external
862 = call_stmt
? stmt_can_throw_external (call_stmt
) : false;
865 && callee
&& callee
->symbol
.decl
866 && !gimple_check_call_matching_types (call_stmt
, callee
->symbol
.decl
,
868 edge
->call_stmt_cannot_inline_p
= true;
870 edge
->call_stmt_cannot_inline_p
= false;
871 if (call_stmt
&& caller
->call_site_hash
)
872 cgraph_add_edge_to_call_site_hash (edge
);
874 edge
->indirect_info
= NULL
;
875 edge
->indirect_inlining_edge
= 0;
876 edge
->speculative
= false;
881 /* Create edge from CALLER to CALLEE in the cgraph. */
884 cgraph_create_edge (struct cgraph_node
*caller
, struct cgraph_node
*callee
,
885 gimple call_stmt
, gcov_type count
, int freq
)
887 struct cgraph_edge
*edge
= cgraph_create_edge_1 (caller
, callee
, call_stmt
,
890 edge
->indirect_unknown_callee
= 0;
891 initialize_inline_failed (edge
);
893 edge
->next_caller
= callee
->callers
;
895 callee
->callers
->prev_caller
= edge
;
896 edge
->next_callee
= caller
->callees
;
898 caller
->callees
->prev_callee
= edge
;
899 caller
->callees
= edge
;
900 callee
->callers
= edge
;
905 /* Allocate cgraph_indirect_call_info and set its fields to default values. */
907 struct cgraph_indirect_call_info
*
908 cgraph_allocate_init_indirect_info (void)
910 struct cgraph_indirect_call_info
*ii
;
912 ii
= ggc_alloc_cleared_cgraph_indirect_call_info ();
913 ii
->param_index
= -1;
917 /* Create an indirect edge with a yet-undetermined callee where the call
918 statement destination is a formal parameter of the caller with index
922 cgraph_create_indirect_edge (struct cgraph_node
*caller
, gimple call_stmt
,
924 gcov_type count
, int freq
)
926 struct cgraph_edge
*edge
= cgraph_create_edge_1 (caller
, NULL
, call_stmt
,
929 edge
->indirect_unknown_callee
= 1;
930 initialize_inline_failed (edge
);
932 edge
->indirect_info
= cgraph_allocate_init_indirect_info ();
933 edge
->indirect_info
->ecf_flags
= ecf_flags
;
935 edge
->next_callee
= caller
->indirect_calls
;
936 if (caller
->indirect_calls
)
937 caller
->indirect_calls
->prev_callee
= edge
;
938 caller
->indirect_calls
= edge
;
943 /* Remove the edge E from the list of the callers of the callee. */
946 cgraph_edge_remove_callee (struct cgraph_edge
*e
)
948 gcc_assert (!e
->indirect_unknown_callee
);
950 e
->prev_caller
->next_caller
= e
->next_caller
;
952 e
->next_caller
->prev_caller
= e
->prev_caller
;
954 e
->callee
->callers
= e
->next_caller
;
957 /* Remove the edge E from the list of the callees of the caller. */
960 cgraph_edge_remove_caller (struct cgraph_edge
*e
)
963 e
->prev_callee
->next_callee
= e
->next_callee
;
965 e
->next_callee
->prev_callee
= e
->prev_callee
;
968 if (e
->indirect_unknown_callee
)
969 e
->caller
->indirect_calls
= e
->next_callee
;
971 e
->caller
->callees
= e
->next_callee
;
973 if (e
->caller
->call_site_hash
)
974 htab_remove_elt_with_hash (e
->caller
->call_site_hash
,
976 htab_hash_pointer (e
->call_stmt
));
979 /* Put the edge onto the free list. */
982 cgraph_free_edge (struct cgraph_edge
*e
)
986 if (e
->indirect_info
)
987 ggc_free (e
->indirect_info
);
989 /* Clear out the edge so we do not dangle pointers. */
990 memset (e
, 0, sizeof (*e
));
992 NEXT_FREE_EDGE (e
) = free_edges
;
996 /* Remove the edge E in the cgraph. */
999 cgraph_remove_edge (struct cgraph_edge
*e
)
1001 /* Call all edge removal hooks. */
1002 cgraph_call_edge_removal_hooks (e
);
1004 if (!e
->indirect_unknown_callee
)
1005 /* Remove from callers list of the callee. */
1006 cgraph_edge_remove_callee (e
);
1008 /* Remove from callees list of the callers. */
1009 cgraph_edge_remove_caller (e
);
1011 /* Put the edge onto the free list. */
1012 cgraph_free_edge (e
);
1015 /* Set callee of call graph edge E and add it to the corresponding set of
1019 cgraph_set_edge_callee (struct cgraph_edge
*e
, struct cgraph_node
*n
)
1021 e
->prev_caller
= NULL
;
1023 n
->callers
->prev_caller
= e
;
1024 e
->next_caller
= n
->callers
;
1029 /* Turn edge E into speculative call calling N2. Update
1030 the profile so the direct call is taken COUNT times
1033 At clone materialization time, the indirect call E will
1036 if (call_dest == N2)
1041 At this time the function just creates the direct call,
1042 the referencd representing the if conditional and attaches
1043 them all to the orginal indirect call statement.
1045 Return direct edge created. */
1047 struct cgraph_edge
*
1048 cgraph_turn_edge_to_speculative (struct cgraph_edge
*e
,
1049 struct cgraph_node
*n2
,
1050 gcov_type direct_count
,
1051 int direct_frequency
)
1053 struct cgraph_node
*n
= e
->caller
;
1054 struct ipa_ref
*ref
;
1055 struct cgraph_edge
*e2
;
1059 fprintf (dump_file
, "Indirect call -> direct call from"
1060 " other module %s/%i => %s/%i\n",
1061 xstrdup (cgraph_node_name (n
)), n
->symbol
.order
,
1062 xstrdup (cgraph_node_name (n2
)), n2
->symbol
.order
);
1064 e
->speculative
= true;
1065 e2
= cgraph_create_edge (n
, n2
, e
->call_stmt
, direct_count
, direct_frequency
);
1066 initialize_inline_failed (e2
);
1067 e2
->speculative
= true;
1068 e2
->call_stmt
= e
->call_stmt
;
1069 e2
->can_throw_external
= e
->can_throw_external
;
1070 e2
->lto_stmt_uid
= e
->lto_stmt_uid
;
1071 e
->count
-= e2
->count
;
1072 e
->frequency
-= e2
->frequency
;
1073 cgraph_call_edge_duplication_hooks (e
, e2
);
1074 ref
= ipa_record_reference ((symtab_node
)n
, (symtab_node
)n2
,
1075 IPA_REF_ADDR
, e
->call_stmt
);
1076 ref
->lto_stmt_uid
= e
->lto_stmt_uid
;
1077 ref
->speculative
= e
->speculative
;
1081 /* Speculative call consist of three components:
1082 1) an indirect edge representing the original call
1083 2) an direct edge representing the new call
1084 3) ADDR_EXPR reference representing the speculative check.
1085 All three components are attached to single statement (the indirect
1086 call) and if one of them exists, all of them must exist.
1088 Given speculative call edge E, return all three components.
1092 cgraph_speculative_call_info (struct cgraph_edge
*e
,
1093 struct cgraph_edge
*&indirect
,
1094 struct cgraph_edge
*&direct
,
1095 struct ipa_ref
*&reference
)
1097 struct ipa_ref
*ref
;
1099 struct cgraph_edge
*e2
;
1101 if (!e
->indirect_unknown_callee
)
1102 for (e2
= e
->caller
->indirect_calls
;
1103 e2
->call_stmt
!= e
->call_stmt
|| e2
->lto_stmt_uid
!= e
->lto_stmt_uid
;
1104 e2
= e2
->next_callee
)
1109 /* We can take advantage of the call stmt hash. */
1112 e
= cgraph_edge (e
->caller
, e2
->call_stmt
);
1113 gcc_assert (e
->speculative
&& !e
->indirect_unknown_callee
);
1116 for (e
= e
->caller
->callees
;
1117 e2
->call_stmt
!= e
->call_stmt
|| e2
->lto_stmt_uid
!= e
->lto_stmt_uid
;
1121 gcc_assert (e
->speculative
&& e2
->speculative
);
1126 for (i
= 0; ipa_ref_list_reference_iterate (&e
->caller
->symbol
.ref_list
, i
, ref
); i
++)
1127 if (ref
->speculative
1128 && ((ref
->stmt
&& ref
->stmt
== e
->call_stmt
)
1129 || (ref
->lto_stmt_uid
== e
->lto_stmt_uid
)))
1136 /* Redirect callee of E to N. The function does not update underlying
1140 cgraph_redirect_edge_callee (struct cgraph_edge
*e
, struct cgraph_node
*n
)
1142 /* Remove from callers list of the current callee. */
1143 cgraph_edge_remove_callee (e
);
1145 /* Insert to callers list of the new callee. */
1146 cgraph_set_edge_callee (e
, n
);
1149 /* Speculative call EDGE turned out to be direct call to CALLE_DECL.
1150 Remove the speculative call sequence and return edge representing the call.
1151 It is up to caller to redirect the call as appropriate. */
1153 struct cgraph_edge
*
1154 cgraph_resolve_speculation (struct cgraph_edge
*edge
, tree callee_decl
)
1156 struct cgraph_edge
*e2
;
1157 struct ipa_ref
*ref
;
1159 gcc_assert (edge
->speculative
);
1160 cgraph_speculative_call_info (edge
, e2
, edge
, ref
);
1161 if (ref
->referred
->symbol
.decl
!= callee_decl
)
1167 fprintf (dump_file
, "Speculative indirect call %s/%i => %s/%i has "
1168 "turned out to have contradicting known target ",
1169 xstrdup (cgraph_node_name (edge
->caller
)), edge
->caller
->symbol
.order
,
1170 xstrdup (cgraph_node_name (e2
->callee
)), e2
->callee
->symbol
.order
);
1171 print_generic_expr (dump_file
, callee_decl
, 0);
1172 fprintf (dump_file
, "\n");
1176 fprintf (dump_file
, "Removing speculative call %s/%i => %s/%i\n",
1177 xstrdup (cgraph_node_name (edge
->caller
)), edge
->caller
->symbol
.order
,
1178 xstrdup (cgraph_node_name (e2
->callee
)), e2
->callee
->symbol
.order
);
1184 struct cgraph_edge
*tmp
= edge
;
1186 fprintf (dump_file
, "Speculative call turned into direct call.\n");
1190 edge
->count
+= e2
->count
;
1191 edge
->frequency
+= e2
->frequency
;
1192 if (edge
->frequency
> CGRAPH_FREQ_MAX
)
1193 edge
->frequency
= CGRAPH_FREQ_MAX
;
1194 edge
->speculative
= false;
1195 e2
->speculative
= false;
1196 if (e2
->indirect_unknown_callee
|| e2
->inline_failed
)
1197 cgraph_remove_edge (e2
);
1199 cgraph_remove_node_and_inline_clones (e2
->callee
, NULL
);
1200 if (edge
->caller
->call_site_hash
)
1201 cgraph_update_edge_in_call_site_hash (edge
);
1202 ipa_remove_reference (ref
);
1206 /* Make an indirect EDGE with an unknown callee an ordinary edge leading to
1207 CALLEE. DELTA is an integer constant that is to be added to the this
1208 pointer (first parameter) to compensate for skipping a thunk adjustment. */
1210 struct cgraph_edge
*
1211 cgraph_make_edge_direct (struct cgraph_edge
*edge
, struct cgraph_node
*callee
)
1213 gcc_assert (edge
->indirect_unknown_callee
);
1215 /* If we are redirecting speculative call, make it non-speculative. */
1216 if (edge
->indirect_unknown_callee
&& edge
->speculative
)
1218 edge
= cgraph_resolve_speculation (edge
, callee
->symbol
.decl
);
1220 /* On successful speculation just return the pre existing direct edge. */
1221 if (!edge
->indirect_unknown_callee
)
1225 edge
->indirect_unknown_callee
= 0;
1226 ggc_free (edge
->indirect_info
);
1227 edge
->indirect_info
= NULL
;
1229 /* Get the edge out of the indirect edge list. */
1230 if (edge
->prev_callee
)
1231 edge
->prev_callee
->next_callee
= edge
->next_callee
;
1232 if (edge
->next_callee
)
1233 edge
->next_callee
->prev_callee
= edge
->prev_callee
;
1234 if (!edge
->prev_callee
)
1235 edge
->caller
->indirect_calls
= edge
->next_callee
;
1237 /* Put it into the normal callee list */
1238 edge
->prev_callee
= NULL
;
1239 edge
->next_callee
= edge
->caller
->callees
;
1240 if (edge
->caller
->callees
)
1241 edge
->caller
->callees
->prev_callee
= edge
;
1242 edge
->caller
->callees
= edge
;
1244 /* Insert to callers list of the new callee. */
1245 cgraph_set_edge_callee (edge
, callee
);
1247 if (edge
->call_stmt
)
1248 edge
->call_stmt_cannot_inline_p
1249 = !gimple_check_call_matching_types (edge
->call_stmt
, callee
->symbol
.decl
,
1252 /* We need to re-determine the inlining status of the edge. */
1253 initialize_inline_failed (edge
);
1257 /* If necessary, change the function declaration in the call statement
1258 associated with E so that it corresponds to the edge callee. */
1261 cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge
*e
)
1263 tree decl
= gimple_call_fndecl (e
->call_stmt
);
1265 gimple_stmt_iterator gsi
;
1266 #ifdef ENABLE_CHECKING
1267 struct cgraph_node
*node
;
1272 struct cgraph_edge
*e2
;
1274 struct ipa_ref
*ref
;
1276 cgraph_speculative_call_info (e
, e
, e2
, ref
);
1277 if (gimple_call_fndecl (e
->call_stmt
))
1278 e
= cgraph_resolve_speculation (e
, gimple_call_fndecl (e
->call_stmt
));
1279 if (!gimple_check_call_matching_types (e
->call_stmt
, e
->callee
->symbol
.decl
,
1282 e
= cgraph_resolve_speculation (e
, NULL
);
1284 fprintf (dump_file
, "Not expanding speculative call of %s/%i -> %s/%i\n"
1286 xstrdup (cgraph_node_name (e
->caller
)), e
->caller
->symbol
.order
,
1287 xstrdup (cgraph_node_name (e
->callee
)), e
->callee
->symbol
.order
);
1292 fprintf (dump_file
, "Expanding speculative call of %s/%i -> %s/%i count:"
1293 HOST_WIDEST_INT_PRINT_DEC
"\n",
1294 xstrdup (cgraph_node_name (e
->caller
)), e
->caller
->symbol
.order
,
1295 xstrdup (cgraph_node_name (e
->callee
)), e
->callee
->symbol
.order
,
1296 (HOST_WIDEST_INT
)e
->count
);
1297 gcc_assert (e2
->speculative
);
1298 push_cfun (DECL_STRUCT_FUNCTION (e
->caller
->symbol
.decl
));
1299 new_stmt
= gimple_ic (e
->call_stmt
, cgraph (ref
->referred
),
1300 e
->count
|| e2
->count
1301 ? RDIV (e
->count
* REG_BR_PROB_BASE
,
1302 e
->count
+ e2
->count
)
1303 : e
->frequency
|| e2
->frequency
1304 ? RDIV (e
->frequency
* REG_BR_PROB_BASE
,
1305 e
->frequency
+ e2
->frequency
)
1306 : REG_BR_PROB_BASE
/ 2,
1307 e
->count
, e
->count
+ e2
->count
);
1308 e
->speculative
= false;
1309 cgraph_set_call_stmt_including_clones (e
->caller
, e
->call_stmt
, new_stmt
, false);
1310 e
->frequency
= compute_call_stmt_bb_frequency (e
->caller
->symbol
.decl
,
1311 gimple_bb (e
->call_stmt
));
1312 e2
->frequency
= compute_call_stmt_bb_frequency (e2
->caller
->symbol
.decl
,
1313 gimple_bb (e2
->call_stmt
));
1314 e2
->speculative
= false;
1315 ref
->speculative
= false;
1317 /* Indirect edges are not both in the call site hash.
1319 if (e
->caller
->call_site_hash
)
1320 cgraph_update_edge_in_call_site_hash (e2
);
1322 /* Continue redirecting E to proper target. */
1326 if (e
->indirect_unknown_callee
1327 || decl
== e
->callee
->symbol
.decl
)
1328 return e
->call_stmt
;
1330 #ifdef ENABLE_CHECKING
1333 node
= cgraph_get_node (decl
);
1334 gcc_assert (!node
|| !node
->clone
.combined_args_to_skip
);
1338 if (cgraph_dump_file
)
1340 fprintf (cgraph_dump_file
, "updating call of %s/%i -> %s/%i: ",
1341 xstrdup (cgraph_node_name (e
->caller
)), e
->caller
->symbol
.order
,
1342 xstrdup (cgraph_node_name (e
->callee
)), e
->callee
->symbol
.order
);
1343 print_gimple_stmt (cgraph_dump_file
, e
->call_stmt
, 0, dump_flags
);
1344 if (e
->callee
->clone
.combined_args_to_skip
)
1346 fprintf (cgraph_dump_file
, " combined args to skip: ");
1347 dump_bitmap (cgraph_dump_file
,
1348 e
->callee
->clone
.combined_args_to_skip
);
1352 if (e
->callee
->clone
.combined_args_to_skip
)
1357 = gimple_call_copy_skip_args (e
->call_stmt
,
1358 e
->callee
->clone
.combined_args_to_skip
);
1359 gimple_call_set_fndecl (new_stmt
, e
->callee
->symbol
.decl
);
1360 gimple_call_set_fntype (new_stmt
, gimple_call_fntype (e
->call_stmt
));
1362 if (gimple_vdef (new_stmt
)
1363 && TREE_CODE (gimple_vdef (new_stmt
)) == SSA_NAME
)
1364 SSA_NAME_DEF_STMT (gimple_vdef (new_stmt
)) = new_stmt
;
1366 gsi
= gsi_for_stmt (e
->call_stmt
);
1367 gsi_replace (&gsi
, new_stmt
, false);
1368 /* We need to defer cleaning EH info on the new statement to
1369 fixup-cfg. We may not have dominator information at this point
1370 and thus would end up with unreachable blocks and have no way
1371 to communicate that we need to run CFG cleanup then. */
1372 lp_nr
= lookup_stmt_eh_lp (e
->call_stmt
);
1375 remove_stmt_from_eh_lp (e
->call_stmt
);
1376 add_stmt_to_eh_lp (new_stmt
, lp_nr
);
1381 new_stmt
= e
->call_stmt
;
1382 gimple_call_set_fndecl (new_stmt
, e
->callee
->symbol
.decl
);
1383 update_stmt (new_stmt
);
1386 cgraph_set_call_stmt_including_clones (e
->caller
, e
->call_stmt
, new_stmt
, false);
1388 if (cgraph_dump_file
)
1390 fprintf (cgraph_dump_file
, " updated to:");
1391 print_gimple_stmt (cgraph_dump_file
, e
->call_stmt
, 0, dump_flags
);
1396 /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
1397 OLD_STMT changed into NEW_STMT. OLD_CALL is gimple_call_fndecl
1398 of OLD_STMT if it was previously call statement.
1399 If NEW_STMT is NULL, the call has been dropped without any
1403 cgraph_update_edges_for_call_stmt_node (struct cgraph_node
*node
,
1404 gimple old_stmt
, tree old_call
,
1407 tree new_call
= (new_stmt
&& is_gimple_call (new_stmt
))
1408 ? gimple_call_fndecl (new_stmt
) : 0;
1410 /* We are seeing indirect calls, then there is nothing to update. */
1411 if (!new_call
&& !old_call
)
1413 /* See if we turned indirect call into direct call or folded call to one builtin
1414 into different builtin. */
1415 if (old_call
!= new_call
)
1417 struct cgraph_edge
*e
= cgraph_edge (node
, old_stmt
);
1418 struct cgraph_edge
*ne
= NULL
;
1424 /* See if the edge is already there and has the correct callee. It
1425 might be so because of indirect inlining has already updated
1426 it. We also might've cloned and redirected the edge. */
1427 if (new_call
&& e
->callee
)
1429 struct cgraph_node
*callee
= e
->callee
;
1432 if (callee
->symbol
.decl
== new_call
1433 || callee
->former_clone_of
== new_call
)
1435 callee
= callee
->clone_of
;
1439 /* Otherwise remove edge and create new one; we can't simply redirect
1440 since function has changed, so inline plan and other information
1441 attached to edge is invalid. */
1443 frequency
= e
->frequency
;
1444 cgraph_remove_edge (e
);
1448 /* We are seeing new direct call; compute profile info based on BB. */
1449 basic_block bb
= gimple_bb (new_stmt
);
1451 frequency
= compute_call_stmt_bb_frequency (current_function_decl
,
1457 ne
= cgraph_create_edge (node
, cgraph_get_create_node (new_call
),
1458 new_stmt
, count
, frequency
);
1459 gcc_assert (ne
->inline_failed
);
1462 /* We only updated the call stmt; update pointer in cgraph edge.. */
1463 else if (old_stmt
!= new_stmt
)
1464 cgraph_set_call_stmt (cgraph_edge (node
, old_stmt
), new_stmt
);
1467 /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
1468 OLD_STMT changed into NEW_STMT. OLD_DECL is gimple_call_fndecl
1469 of OLD_STMT before it was updated (updating can happen inplace). */
1472 cgraph_update_edges_for_call_stmt (gimple old_stmt
, tree old_decl
, gimple new_stmt
)
1474 struct cgraph_node
*orig
= cgraph_get_node (cfun
->decl
);
1475 struct cgraph_node
*node
;
1477 gcc_checking_assert (orig
);
1478 cgraph_update_edges_for_call_stmt_node (orig
, old_stmt
, old_decl
, new_stmt
);
1480 for (node
= orig
->clones
; node
!= orig
;)
1482 cgraph_update_edges_for_call_stmt_node (node
, old_stmt
, old_decl
, new_stmt
);
1484 node
= node
->clones
;
1485 else if (node
->next_sibling_clone
)
1486 node
= node
->next_sibling_clone
;
1489 while (node
!= orig
&& !node
->next_sibling_clone
)
1490 node
= node
->clone_of
;
1492 node
= node
->next_sibling_clone
;
1498 /* Remove all callees from the node. */
1501 cgraph_node_remove_callees (struct cgraph_node
*node
)
1503 struct cgraph_edge
*e
, *f
;
1505 /* It is sufficient to remove the edges from the lists of callers of
1506 the callees. The callee list of the node can be zapped with one
1508 for (e
= node
->callees
; e
; e
= f
)
1511 cgraph_call_edge_removal_hooks (e
);
1512 if (!e
->indirect_unknown_callee
)
1513 cgraph_edge_remove_callee (e
);
1514 cgraph_free_edge (e
);
1516 for (e
= node
->indirect_calls
; e
; e
= f
)
1519 cgraph_call_edge_removal_hooks (e
);
1520 if (!e
->indirect_unknown_callee
)
1521 cgraph_edge_remove_callee (e
);
1522 cgraph_free_edge (e
);
1524 node
->indirect_calls
= NULL
;
1525 node
->callees
= NULL
;
1526 if (node
->call_site_hash
)
1528 htab_delete (node
->call_site_hash
);
1529 node
->call_site_hash
= NULL
;
1533 /* Remove all callers from the node. */
1536 cgraph_node_remove_callers (struct cgraph_node
*node
)
1538 struct cgraph_edge
*e
, *f
;
1540 /* It is sufficient to remove the edges from the lists of callees of
1541 the callers. The caller list of the node can be zapped with one
1543 for (e
= node
->callers
; e
; e
= f
)
1546 cgraph_call_edge_removal_hooks (e
);
1547 cgraph_edge_remove_caller (e
);
1548 cgraph_free_edge (e
);
1550 node
->callers
= NULL
;
1553 /* Helper function for cgraph_release_function_body and free_lang_data.
1554 It releases body from function DECL without having to inspect its
1555 possibly non-existent symtab node. */
1558 release_function_body (tree decl
)
1560 if (DECL_STRUCT_FUNCTION (decl
))
1562 push_cfun (DECL_STRUCT_FUNCTION (decl
));
1566 cfun
->curr_properties
&= ~PROP_loops
;
1567 loop_optimizer_finalize ();
1569 if (cfun
->gimple_df
)
1572 delete_tree_cfg_annotations ();
1577 gcc_assert (dom_computed
[0] == DOM_NONE
);
1578 gcc_assert (dom_computed
[1] == DOM_NONE
);
1582 if (cfun
->value_histograms
)
1585 gimple_set_body (decl
, NULL
);
1586 /* Struct function hangs a lot of data that would leak if we didn't
1587 removed all pointers to it. */
1588 ggc_free (DECL_STRUCT_FUNCTION (decl
));
1589 DECL_STRUCT_FUNCTION (decl
) = NULL
;
1591 DECL_SAVED_TREE (decl
) = NULL
;
1594 /* Release memory used to represent body of function NODE.
1595 Use this only for functions that are released before being translated to
1596 target code (i.e. RTL). Functions that are compiled to RTL and beyond
1597 are free'd in final.c via free_after_compilation(). */
1600 cgraph_release_function_body (struct cgraph_node
*node
)
1602 node
->ipa_transforms_to_apply
.release ();
1603 if (!node
->used_as_abstract_origin
&& cgraph_state
!= CGRAPH_STATE_PARSING
)
1605 DECL_RESULT (node
->symbol
.decl
) = NULL
;
1606 DECL_ARGUMENTS (node
->symbol
.decl
) = NULL
;
1608 /* If the node is abstract and needed, then do not clear DECL_INITIAL
1609 of its associated function function declaration because it's
1610 needed to emit debug info later. */
1611 if (!node
->used_as_abstract_origin
&& DECL_INITIAL (node
->symbol
.decl
))
1612 DECL_INITIAL (node
->symbol
.decl
) = error_mark_node
;
1613 release_function_body (node
->symbol
.decl
);
1616 /* Remove the node from cgraph. */
1619 cgraph_remove_node (struct cgraph_node
*node
)
1621 struct cgraph_node
*n
;
1622 int uid
= node
->uid
;
1624 cgraph_call_node_removal_hooks (node
);
1625 cgraph_node_remove_callers (node
);
1626 cgraph_node_remove_callees (node
);
1627 node
->ipa_transforms_to_apply
.release ();
1629 /* Incremental inlining access removed nodes stored in the postorder list.
1631 node
->symbol
.force_output
= false;
1632 node
->symbol
.forced_by_abi
= false;
1633 for (n
= node
->nested
; n
; n
= n
->next_nested
)
1635 node
->nested
= NULL
;
1638 struct cgraph_node
**node2
= &node
->origin
->nested
;
1640 while (*node2
!= node
)
1641 node2
= &(*node2
)->next_nested
;
1642 *node2
= node
->next_nested
;
1644 symtab_unregister_node ((symtab_node
)node
);
1645 if (node
->prev_sibling_clone
)
1646 node
->prev_sibling_clone
->next_sibling_clone
= node
->next_sibling_clone
;
1647 else if (node
->clone_of
)
1648 node
->clone_of
->clones
= node
->next_sibling_clone
;
1649 if (node
->next_sibling_clone
)
1650 node
->next_sibling_clone
->prev_sibling_clone
= node
->prev_sibling_clone
;
1653 struct cgraph_node
*n
, *next
;
1657 for (n
= node
->clones
; n
->next_sibling_clone
; n
= n
->next_sibling_clone
)
1658 n
->clone_of
= node
->clone_of
;
1659 n
->clone_of
= node
->clone_of
;
1660 n
->next_sibling_clone
= node
->clone_of
->clones
;
1661 if (node
->clone_of
->clones
)
1662 node
->clone_of
->clones
->prev_sibling_clone
= n
;
1663 node
->clone_of
->clones
= node
->clones
;
1667 /* We are removing node with clones. This makes clones inconsistent,
1668 but assume they will be removed subsequently and just keep clone
1669 tree intact. This can happen in unreachable function removal since
1670 we remove unreachable functions in random order, not by bottom-up
1671 walk of clone trees. */
1672 for (n
= node
->clones
; n
; n
= next
)
1674 next
= n
->next_sibling_clone
;
1675 n
->next_sibling_clone
= NULL
;
1676 n
->prev_sibling_clone
= NULL
;
1682 /* While all the clones are removed after being proceeded, the function
1683 itself is kept in the cgraph even after it is compiled. Check whether
1684 we are done with this body and reclaim it proactively if this is the case.
1686 if (cgraph_state
!= CGRAPH_LTO_STREAMING
)
1688 n
= cgraph_get_node (node
->symbol
.decl
);
1690 || (!n
->clones
&& !n
->clone_of
&& !n
->global
.inlined_to
1691 && (cgraph_global_info_ready
1692 && (TREE_ASM_WRITTEN (n
->symbol
.decl
)
1693 || DECL_EXTERNAL (n
->symbol
.decl
)
1694 || !n
->symbol
.analyzed
1695 || (!flag_wpa
&& n
->symbol
.in_other_partition
)))))
1696 cgraph_release_function_body (node
);
1699 node
->symbol
.decl
= NULL
;
1700 if (node
->call_site_hash
)
1702 htab_delete (node
->call_site_hash
);
1703 node
->call_site_hash
= NULL
;
1707 /* Clear out the node to NULL all pointers and add the node to the free
1709 memset (node
, 0, sizeof(*node
));
1710 node
->symbol
.type
= SYMTAB_FUNCTION
;
1712 SET_NEXT_FREE_NODE (node
, free_nodes
);
1716 /* Likewise indicate that a node is having address taken. */
1719 cgraph_mark_address_taken_node (struct cgraph_node
*node
)
1721 /* Indirect inlining can figure out that all uses of the address are
1723 if (node
->global
.inlined_to
)
1725 gcc_assert (cfun
->after_inlining
);
1726 gcc_assert (node
->callers
->indirect_inlining_edge
);
1729 /* FIXME: address_taken flag is used both as a shortcut for testing whether
1730 IPA_REF_ADDR reference exists (and thus it should be set on node
1731 representing alias we take address of) and as a test whether address
1732 of the object was taken (and thus it should be set on node alias is
1733 referring to). We should remove the first use and the remove the
1735 node
->symbol
.address_taken
= 1;
1736 node
= cgraph_function_or_thunk_node (node
, NULL
);
1737 node
->symbol
.address_taken
= 1;
1740 /* Return local info for the compiled function. */
1742 struct cgraph_local_info
*
1743 cgraph_local_info (tree decl
)
1745 struct cgraph_node
*node
;
1747 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1748 node
= cgraph_get_node (decl
);
1751 return &node
->local
;
1754 /* Return local info for the compiled function. */
1756 struct cgraph_global_info
*
1757 cgraph_global_info (tree decl
)
1759 struct cgraph_node
*node
;
1761 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
&& cgraph_global_info_ready
);
1762 node
= cgraph_get_node (decl
);
1765 return &node
->global
;
1768 /* Return local info for the compiled function. */
1770 struct cgraph_rtl_info
*
1771 cgraph_rtl_info (tree decl
)
1773 struct cgraph_node
*node
;
1775 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1776 node
= cgraph_get_node (decl
);
1778 || (decl
!= current_function_decl
1779 && !TREE_ASM_WRITTEN (node
->symbol
.decl
)))
1784 /* Return a string describing the failure REASON. */
1787 cgraph_inline_failed_string (cgraph_inline_failed_t reason
)
1790 #define DEFCIFCODE(code, string) string,
1792 static const char *cif_string_table
[CIF_N_REASONS
] = {
1793 #include "cif-code.def"
1796 /* Signedness of an enum type is implementation defined, so cast it
1797 to unsigned before testing. */
1798 gcc_assert ((unsigned) reason
< CIF_N_REASONS
);
1799 return cif_string_table
[reason
];
1802 /* Names used to print out the availability enum. */
1803 const char * const cgraph_availability_names
[] =
1804 {"unset", "not_available", "overwritable", "available", "local"};
1807 /* Dump call graph node NODE to file F. */
1810 dump_cgraph_node (FILE *f
, struct cgraph_node
*node
)
1812 struct cgraph_edge
*edge
;
1813 int indirect_calls_count
= 0;
1815 dump_symtab_base (f
, (symtab_node
) node
);
1817 if (node
->global
.inlined_to
)
1818 fprintf (f
, " Function %s/%i is inline copy in %s/%i\n",
1819 xstrdup (cgraph_node_name (node
)),
1821 xstrdup (cgraph_node_name (node
->global
.inlined_to
)),
1822 node
->global
.inlined_to
->symbol
.order
);
1824 fprintf (f
, " Clone of %s/%i\n",
1825 cgraph_node_asm_name (node
->clone_of
),
1826 node
->clone_of
->symbol
.order
);
1827 if (cgraph_function_flags_ready
)
1828 fprintf (f
, " Availability: %s\n",
1829 cgraph_availability_names
[cgraph_function_body_availability (node
)]);
1831 if (node
->profile_id
)
1832 fprintf (f
, " Profile id: %i\n",
1834 fprintf (f
, " Function flags:");
1836 fprintf (f
, " executed "HOST_WIDEST_INT_PRINT_DEC
"x",
1837 (HOST_WIDEST_INT
)node
->count
);
1839 fprintf (f
, " nested in: %s", cgraph_node_asm_name (node
->origin
));
1840 if (gimple_has_body_p (node
->symbol
.decl
))
1841 fprintf (f
, " body");
1843 fprintf (f
, " process");
1844 if (node
->local
.local
)
1845 fprintf (f
, " local");
1846 if (node
->local
.redefined_extern_inline
)
1847 fprintf (f
, " redefined_extern_inline");
1848 if (node
->only_called_at_startup
)
1849 fprintf (f
, " only_called_at_startup");
1850 if (node
->only_called_at_exit
)
1851 fprintf (f
, " only_called_at_exit");
1853 fprintf (f
, " tm_clone");
1857 if (node
->thunk
.thunk_p
)
1859 fprintf (f
, " Thunk");
1860 if (node
->thunk
.alias
)
1861 fprintf (f
, " of %s (asm: %s)",
1862 lang_hooks
.decl_printable_name (node
->thunk
.alias
, 2),
1863 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->thunk
.alias
)));
1864 fprintf (f
, " fixed offset %i virtual value %i has "
1865 "virtual offset %i)\n",
1866 (int)node
->thunk
.fixed_offset
,
1867 (int)node
->thunk
.virtual_value
,
1868 (int)node
->thunk
.virtual_offset_p
);
1870 if (node
->symbol
.alias
&& node
->thunk
.alias
1871 && DECL_P (node
->thunk
.alias
))
1873 fprintf (f
, " Alias of %s",
1874 lang_hooks
.decl_printable_name (node
->thunk
.alias
, 2));
1875 if (DECL_ASSEMBLER_NAME_SET_P (node
->thunk
.alias
))
1876 fprintf (f
, " (asm: %s)",
1877 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->thunk
.alias
)));
1881 fprintf (f
, " Called by: ");
1883 for (edge
= node
->callers
; edge
; edge
= edge
->next_caller
)
1885 fprintf (f
, "%s/%i ", cgraph_node_asm_name (edge
->caller
),
1886 edge
->caller
->symbol
.order
);
1888 fprintf (f
, "("HOST_WIDEST_INT_PRINT_DEC
"x) ",
1889 (HOST_WIDEST_INT
)edge
->count
);
1890 if (edge
->frequency
)
1891 fprintf (f
, "(%.2f per call) ",
1892 edge
->frequency
/ (double)CGRAPH_FREQ_BASE
);
1893 if (edge
->speculative
)
1894 fprintf(f
, "(speculative) ");
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_asm_name (edge
->callee
),
1907 edge
->callee
->symbol
.order
);
1908 if (edge
->speculative
)
1909 fprintf(f
, "(speculative) ");
1910 if (!edge
->inline_failed
)
1911 fprintf(f
, "(inlined) ");
1912 if (edge
->indirect_inlining_edge
)
1913 fprintf(f
, "(indirect_inlining) ");
1915 fprintf (f
, "("HOST_WIDEST_INT_PRINT_DEC
"x) ",
1916 (HOST_WIDEST_INT
)edge
->count
);
1917 if (edge
->frequency
)
1918 fprintf (f
, "(%.2f per call) ",
1919 edge
->frequency
/ (double)CGRAPH_FREQ_BASE
);
1920 if (edge
->can_throw_external
)
1921 fprintf(f
, "(can throw external) ");
1925 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
1926 indirect_calls_count
++;
1927 if (indirect_calls_count
)
1928 fprintf (f
, " Has %i outgoing edges for indirect calls.\n",
1929 indirect_calls_count
);
1933 /* Dump call graph node NODE to stderr. */
1936 debug_cgraph_node (struct cgraph_node
*node
)
1938 dump_cgraph_node (stderr
, node
);
1942 /* Dump the callgraph to file F. */
1945 dump_cgraph (FILE *f
)
1947 struct cgraph_node
*node
;
1949 fprintf (f
, "callgraph:\n\n");
1950 FOR_EACH_FUNCTION (node
)
1951 dump_cgraph_node (f
, node
);
1955 /* Dump the call graph to stderr. */
1960 dump_cgraph (stderr
);
1963 /* Return true when the DECL can possibly be inlined. */
1965 cgraph_function_possibly_inlined_p (tree decl
)
1967 if (!cgraph_global_info_ready
)
1968 return !DECL_UNINLINABLE (decl
);
1969 return DECL_POSSIBLY_INLINED (decl
);
1972 /* NODE is no longer nested function; update cgraph accordingly. */
1974 cgraph_unnest_node (struct cgraph_node
*node
)
1976 struct cgraph_node
**node2
= &node
->origin
->nested
;
1977 gcc_assert (node
->origin
);
1979 while (*node2
!= node
)
1980 node2
= &(*node2
)->next_nested
;
1981 *node2
= node
->next_nested
;
1982 node
->origin
= NULL
;
1985 /* Return function availability. See cgraph.h for description of individual
1988 cgraph_function_body_availability (struct cgraph_node
*node
)
1990 enum availability avail
;
1991 if (!node
->symbol
.analyzed
)
1992 avail
= AVAIL_NOT_AVAILABLE
;
1993 else if (node
->local
.local
)
1994 avail
= AVAIL_LOCAL
;
1995 else if (!node
->symbol
.externally_visible
)
1996 avail
= AVAIL_AVAILABLE
;
1997 /* Inline functions are safe to be analyzed even if their symbol can
1998 be overwritten at runtime. It is not meaningful to enforce any sane
1999 behaviour on replacing inline function by different body. */
2000 else if (DECL_DECLARED_INLINE_P (node
->symbol
.decl
))
2001 avail
= AVAIL_AVAILABLE
;
2003 /* If the function can be overwritten, return OVERWRITABLE. Take
2004 care at least of two notable extensions - the COMDAT functions
2005 used to share template instantiations in C++ (this is symmetric
2006 to code cp_cannot_inline_tree_fn and probably shall be shared and
2007 the inlinability hooks completely eliminated).
2009 ??? Does the C++ one definition rule allow us to always return
2010 AVAIL_AVAILABLE here? That would be good reason to preserve this
2013 else if (decl_replaceable_p (node
->symbol
.decl
)
2014 && !DECL_EXTERNAL (node
->symbol
.decl
))
2015 avail
= AVAIL_OVERWRITABLE
;
2016 else avail
= AVAIL_AVAILABLE
;
2021 /* Worker for cgraph_node_can_be_local_p. */
2023 cgraph_node_cannot_be_local_p_1 (struct cgraph_node
*node
,
2024 void *data ATTRIBUTE_UNUSED
)
2026 return !(!node
->symbol
.force_output
2027 && ((DECL_COMDAT (node
->symbol
.decl
)
2028 && !node
->symbol
.forced_by_abi
2029 && !symtab_used_from_object_file_p ((symtab_node
) node
)
2030 && !node
->symbol
.same_comdat_group
)
2031 || !node
->symbol
.externally_visible
));
2034 /* Return true if NODE can be made local for API change.
2035 Extern inline functions and C++ COMDAT functions can be made local
2036 at the expense of possible code size growth if function is used in multiple
2037 compilation units. */
2039 cgraph_node_can_be_local_p (struct cgraph_node
*node
)
2041 return (!node
->symbol
.address_taken
2042 && !cgraph_for_node_and_aliases (node
,
2043 cgraph_node_cannot_be_local_p_1
,
2047 /* Call calback on NODE, thunks and aliases associated to NODE.
2048 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
2052 cgraph_for_node_thunks_and_aliases (struct cgraph_node
*node
,
2053 bool (*callback
) (struct cgraph_node
*, void *),
2055 bool include_overwritable
)
2057 struct cgraph_edge
*e
;
2059 struct ipa_ref
*ref
;
2061 if (callback (node
, data
))
2063 for (e
= node
->callers
; e
; e
= e
->next_caller
)
2064 if (e
->caller
->thunk
.thunk_p
2065 && (include_overwritable
2066 || cgraph_function_body_availability (e
->caller
) > AVAIL_OVERWRITABLE
))
2067 if (cgraph_for_node_thunks_and_aliases (e
->caller
, callback
, data
,
2068 include_overwritable
))
2070 for (i
= 0; ipa_ref_list_referring_iterate (&node
->symbol
.ref_list
, i
, ref
); i
++)
2071 if (ref
->use
== IPA_REF_ALIAS
)
2073 struct cgraph_node
*alias
= ipa_ref_referring_node (ref
);
2074 if (include_overwritable
2075 || cgraph_function_body_availability (alias
) > AVAIL_OVERWRITABLE
)
2076 if (cgraph_for_node_thunks_and_aliases (alias
, callback
, data
,
2077 include_overwritable
))
2083 /* Call calback on NODE and aliases associated to NODE.
2084 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
2088 cgraph_for_node_and_aliases (struct cgraph_node
*node
,
2089 bool (*callback
) (struct cgraph_node
*, void *),
2091 bool include_overwritable
)
2094 struct ipa_ref
*ref
;
2096 if (callback (node
, data
))
2098 for (i
= 0; ipa_ref_list_referring_iterate (&node
->symbol
.ref_list
, i
, ref
); i
++)
2099 if (ref
->use
== IPA_REF_ALIAS
)
2101 struct cgraph_node
*alias
= ipa_ref_referring_node (ref
);
2102 if (include_overwritable
2103 || cgraph_function_body_availability (alias
) > AVAIL_OVERWRITABLE
)
2104 if (cgraph_for_node_and_aliases (alias
, callback
, data
,
2105 include_overwritable
))
2111 /* Worker to bring NODE local. */
2114 cgraph_make_node_local_1 (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
2116 gcc_checking_assert (cgraph_node_can_be_local_p (node
));
2117 if (DECL_COMDAT (node
->symbol
.decl
) || DECL_EXTERNAL (node
->symbol
.decl
))
2119 symtab_make_decl_local (node
->symbol
.decl
);
2121 node
->symbol
.externally_visible
= false;
2122 node
->symbol
.forced_by_abi
= false;
2123 node
->local
.local
= true;
2124 node
->symbol
.unique_name
= (node
->symbol
.resolution
== LDPR_PREVAILING_DEF_IRONLY
2125 || node
->symbol
.resolution
== LDPR_PREVAILING_DEF_IRONLY_EXP
);
2126 node
->symbol
.resolution
= LDPR_PREVAILING_DEF_IRONLY
;
2127 gcc_assert (cgraph_function_body_availability (node
) == AVAIL_LOCAL
);
2132 /* Bring NODE local. */
2135 cgraph_make_node_local (struct cgraph_node
*node
)
2137 cgraph_for_node_thunks_and_aliases (node
, cgraph_make_node_local_1
,
2141 /* Worker to set nothrow flag. */
2144 cgraph_set_nothrow_flag_1 (struct cgraph_node
*node
, void *data
)
2146 struct cgraph_edge
*e
;
2148 TREE_NOTHROW (node
->symbol
.decl
) = data
!= NULL
;
2151 for (e
= node
->callers
; e
; e
= e
->next_caller
)
2152 e
->can_throw_external
= false;
2156 /* Set TREE_NOTHROW on NODE's decl and on aliases of NODE
2157 if any to NOTHROW. */
2160 cgraph_set_nothrow_flag (struct cgraph_node
*node
, bool nothrow
)
2162 cgraph_for_node_thunks_and_aliases (node
, cgraph_set_nothrow_flag_1
,
2163 (void *)(size_t)nothrow
, false);
2166 /* Worker to set const flag. */
2169 cgraph_set_const_flag_1 (struct cgraph_node
*node
, void *data
)
2171 /* Static constructors and destructors without a side effect can be
2173 if (data
&& !((size_t)data
& 2))
2175 if (DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
))
2176 DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
) = 0;
2177 if (DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
))
2178 DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
) = 0;
2180 TREE_READONLY (node
->symbol
.decl
) = data
!= NULL
;
2181 DECL_LOOPING_CONST_OR_PURE_P (node
->symbol
.decl
) = ((size_t)data
& 2) != 0;
2185 /* Set TREE_READONLY on NODE's decl and on aliases of NODE
2186 if any to READONLY. */
2189 cgraph_set_const_flag (struct cgraph_node
*node
, bool readonly
, bool looping
)
2191 cgraph_for_node_thunks_and_aliases (node
, cgraph_set_const_flag_1
,
2192 (void *)(size_t)(readonly
+ (int)looping
* 2),
2196 /* Worker to set pure flag. */
2199 cgraph_set_pure_flag_1 (struct cgraph_node
*node
, void *data
)
2201 /* Static constructors and destructors without a side effect can be
2203 if (data
&& !((size_t)data
& 2))
2205 if (DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
))
2206 DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
) = 0;
2207 if (DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
))
2208 DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
) = 0;
2210 DECL_PURE_P (node
->symbol
.decl
) = data
!= NULL
;
2211 DECL_LOOPING_CONST_OR_PURE_P (node
->symbol
.decl
) = ((size_t)data
& 2) != 0;
2215 /* Set DECL_PURE_P on NODE's decl and on aliases of NODE
2219 cgraph_set_pure_flag (struct cgraph_node
*node
, bool pure
, bool looping
)
2221 cgraph_for_node_thunks_and_aliases (node
, cgraph_set_pure_flag_1
,
2222 (void *)(size_t)(pure
+ (int)looping
* 2),
2226 /* Data used by cgraph_propagate_frequency. */
2228 struct cgraph_propagate_frequency_data
2230 bool maybe_unlikely_executed
;
2231 bool maybe_executed_once
;
2232 bool only_called_at_startup
;
2233 bool only_called_at_exit
;
2236 /* Worker for cgraph_propagate_frequency_1. */
2239 cgraph_propagate_frequency_1 (struct cgraph_node
*node
, void *data
)
2241 struct cgraph_propagate_frequency_data
*d
;
2242 struct cgraph_edge
*edge
;
2244 d
= (struct cgraph_propagate_frequency_data
*)data
;
2245 for (edge
= node
->callers
;
2246 edge
&& (d
->maybe_unlikely_executed
|| d
->maybe_executed_once
2247 || d
->only_called_at_startup
|| d
->only_called_at_exit
);
2248 edge
= edge
->next_caller
)
2250 if (edge
->caller
!= node
)
2252 d
->only_called_at_startup
&= edge
->caller
->only_called_at_startup
;
2253 /* It makes sense to put main() together with the static constructors.
2254 It will be executed for sure, but rest of functions called from
2255 main are definitely not at startup only. */
2256 if (MAIN_NAME_P (DECL_NAME (edge
->caller
->symbol
.decl
)))
2257 d
->only_called_at_startup
= 0;
2258 d
->only_called_at_exit
&= edge
->caller
->only_called_at_exit
;
2260 if (!edge
->frequency
)
2262 switch (edge
->caller
->frequency
)
2264 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
2266 case NODE_FREQUENCY_EXECUTED_ONCE
:
2267 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2268 fprintf (dump_file
, " Called by %s that is executed once\n",
2269 cgraph_node_name (edge
->caller
));
2270 d
->maybe_unlikely_executed
= false;
2271 if (inline_edge_summary (edge
)->loop_depth
)
2273 d
->maybe_executed_once
= false;
2274 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2275 fprintf (dump_file
, " Called in loop\n");
2278 case NODE_FREQUENCY_HOT
:
2279 case NODE_FREQUENCY_NORMAL
:
2280 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2281 fprintf (dump_file
, " Called by %s that is normal or hot\n",
2282 cgraph_node_name (edge
->caller
));
2283 d
->maybe_unlikely_executed
= false;
2284 d
->maybe_executed_once
= false;
2288 return edge
!= NULL
;
2291 /* See if the frequency of NODE can be updated based on frequencies of its
2294 cgraph_propagate_frequency (struct cgraph_node
*node
)
2296 struct cgraph_propagate_frequency_data d
= {true, true, true, true};
2297 bool changed
= false;
2299 if (!node
->local
.local
)
2301 gcc_assert (node
->symbol
.analyzed
);
2302 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2303 fprintf (dump_file
, "Processing frequency %s\n", cgraph_node_name (node
));
2305 cgraph_for_node_and_aliases (node
, cgraph_propagate_frequency_1
, &d
, true);
2307 if ((d
.only_called_at_startup
&& !d
.only_called_at_exit
)
2308 && !node
->only_called_at_startup
)
2310 node
->only_called_at_startup
= true;
2312 fprintf (dump_file
, "Node %s promoted to only called at startup.\n",
2313 cgraph_node_name (node
));
2316 if ((d
.only_called_at_exit
&& !d
.only_called_at_startup
)
2317 && !node
->only_called_at_exit
)
2319 node
->only_called_at_exit
= true;
2321 fprintf (dump_file
, "Node %s promoted to only called at exit.\n",
2322 cgraph_node_name (node
));
2325 /* These come either from profile or user hints; never update them. */
2326 if (node
->frequency
== NODE_FREQUENCY_HOT
2327 || node
->frequency
== NODE_FREQUENCY_UNLIKELY_EXECUTED
)
2329 if (d
.maybe_unlikely_executed
)
2331 node
->frequency
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
2333 fprintf (dump_file
, "Node %s promoted to unlikely executed.\n",
2334 cgraph_node_name (node
));
2337 else if (d
.maybe_executed_once
&& node
->frequency
!= NODE_FREQUENCY_EXECUTED_ONCE
)
2339 node
->frequency
= NODE_FREQUENCY_EXECUTED_ONCE
;
2341 fprintf (dump_file
, "Node %s promoted to executed once.\n",
2342 cgraph_node_name (node
));
2348 /* Return true when NODE can not return or throw and thus
2349 it is safe to ignore its side effects for IPA analysis. */
2352 cgraph_node_cannot_return (struct cgraph_node
*node
)
2354 int flags
= flags_from_decl_or_type (node
->symbol
.decl
);
2355 if (!flag_exceptions
)
2356 return (flags
& ECF_NORETURN
) != 0;
2358 return ((flags
& (ECF_NORETURN
| ECF_NOTHROW
))
2359 == (ECF_NORETURN
| ECF_NOTHROW
));
2362 /* Return true when call of E can not lead to return from caller
2363 and thus it is safe to ignore its side effects for IPA analysis
2364 when computing side effects of the caller.
2365 FIXME: We could actually mark all edges that have no reaching
2366 patch to EXIT_BLOCK_PTR or throw to get better results. */
2368 cgraph_edge_cannot_lead_to_return (struct cgraph_edge
*e
)
2370 if (cgraph_node_cannot_return (e
->caller
))
2372 if (e
->indirect_unknown_callee
)
2374 int flags
= e
->indirect_info
->ecf_flags
;
2375 if (!flag_exceptions
)
2376 return (flags
& ECF_NORETURN
) != 0;
2378 return ((flags
& (ECF_NORETURN
| ECF_NOTHROW
))
2379 == (ECF_NORETURN
| ECF_NOTHROW
));
2382 return cgraph_node_cannot_return (e
->callee
);
2385 /* Return true when function NODE can be removed from callgraph
2386 if all direct calls are eliminated. */
2389 cgraph_can_remove_if_no_direct_calls_and_refs_p (struct cgraph_node
*node
)
2391 gcc_assert (!node
->global
.inlined_to
);
2392 /* Extern inlines can always go, we will use the external definition. */
2393 if (DECL_EXTERNAL (node
->symbol
.decl
))
2395 /* When function is needed, we can not remove it. */
2396 if (node
->symbol
.force_output
|| node
->symbol
.used_from_other_partition
)
2398 if (DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
)
2399 || DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
))
2401 /* Only COMDAT functions can be removed if externally visible. */
2402 if (node
->symbol
.externally_visible
2403 && (!DECL_COMDAT (node
->symbol
.decl
)
2404 || node
->symbol
.forced_by_abi
2405 || symtab_used_from_object_file_p ((symtab_node
) node
)))
2410 /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
2413 nonremovable_p (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
2415 return !cgraph_can_remove_if_no_direct_calls_and_refs_p (node
);
2418 /* Return true when function NODE and its aliases can be removed from callgraph
2419 if all direct calls are eliminated. */
2422 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node
*node
)
2424 /* Extern inlines can always go, we will use the external definition. */
2425 if (DECL_EXTERNAL (node
->symbol
.decl
))
2427 if (node
->symbol
.address_taken
)
2429 return !cgraph_for_node_and_aliases (node
, nonremovable_p
, NULL
, true);
2432 /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
2435 used_from_object_file_p (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
2437 return symtab_used_from_object_file_p ((symtab_node
) node
);
2440 /* Return true when function NODE can be expected to be removed
2441 from program when direct calls in this compilation unit are removed.
2443 As a special case COMDAT functions are
2444 cgraph_can_remove_if_no_direct_calls_p while the are not
2445 cgraph_only_called_directly_p (it is possible they are called from other
2448 This function behaves as cgraph_only_called_directly_p because eliminating
2449 all uses of COMDAT function does not make it necessarily disappear from
2450 the program unless we are compiling whole program or we do LTO. In this
2451 case we know we win since dynamic linking will not really discard the
2452 linkonce section. */
2455 cgraph_will_be_removed_from_program_if_no_direct_calls (struct cgraph_node
*node
)
2457 gcc_assert (!node
->global
.inlined_to
);
2458 if (cgraph_for_node_and_aliases (node
, used_from_object_file_p
, NULL
, true))
2460 if (!in_lto_p
&& !flag_whole_program
)
2461 return cgraph_only_called_directly_p (node
);
2464 if (DECL_EXTERNAL (node
->symbol
.decl
))
2466 return cgraph_can_remove_if_no_direct_calls_p (node
);
2471 /* Worker for cgraph_only_called_directly_p. */
2474 cgraph_not_only_called_directly_p_1 (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
2476 return !cgraph_only_called_directly_or_aliased_p (node
);
2479 /* Return true when function NODE and all its aliases are only called
2481 i.e. it is not externally visible, address was not taken and
2482 it is not used in any other non-standard way. */
2485 cgraph_only_called_directly_p (struct cgraph_node
*node
)
2487 gcc_assert (cgraph_function_or_thunk_node (node
, NULL
) == node
);
2488 return !cgraph_for_node_and_aliases (node
, cgraph_not_only_called_directly_p_1
,
2493 /* Collect all callers of NODE. Worker for collect_callers_of_node. */
2496 collect_callers_of_node_1 (struct cgraph_node
*node
, void *data
)
2498 vec
<cgraph_edge_p
> *redirect_callers
= (vec
<cgraph_edge_p
> *)data
;
2499 struct cgraph_edge
*cs
;
2500 enum availability avail
;
2501 cgraph_function_or_thunk_node (node
, &avail
);
2503 if (avail
> AVAIL_OVERWRITABLE
)
2504 for (cs
= node
->callers
; cs
!= NULL
; cs
= cs
->next_caller
)
2505 if (!cs
->indirect_inlining_edge
)
2506 redirect_callers
->safe_push (cs
);
2510 /* Collect all callers of NODE and its aliases that are known to lead to NODE
2511 (i.e. are not overwritable). */
2514 collect_callers_of_node (struct cgraph_node
*node
)
2516 vec
<cgraph_edge_p
> redirect_callers
= vNULL
;
2517 cgraph_for_node_and_aliases (node
, collect_callers_of_node_1
,
2518 &redirect_callers
, false);
2519 return redirect_callers
;
2522 /* Return TRUE if NODE2 is equivalent to NODE or its clone. */
2524 clone_of_p (struct cgraph_node
*node
, struct cgraph_node
*node2
)
2526 node
= cgraph_function_or_thunk_node (node
, NULL
);
2527 node2
= cgraph_function_or_thunk_node (node2
, NULL
);
2528 while (node
!= node2
&& node2
)
2529 node2
= node2
->clone_of
;
2530 return node2
!= NULL
;
2533 /* Verify edge E count and frequency. */
2536 verify_edge_count_and_frequency (struct cgraph_edge
*e
)
2538 bool error_found
= false;
2541 error ("caller edge count is negative");
2544 if (e
->frequency
< 0)
2546 error ("caller edge frequency is negative");
2549 if (e
->frequency
> CGRAPH_FREQ_MAX
)
2551 error ("caller edge frequency is too large");
2554 if (gimple_has_body_p (e
->caller
->symbol
.decl
)
2555 && !e
->caller
->global
.inlined_to
2557 /* FIXME: Inline-analysis sets frequency to 0 when edge is optimized out.
2558 Remove this once edges are actually removed from the function at that time. */
2560 || (inline_edge_summary_vec
.exists ()
2561 && ((inline_edge_summary_vec
.length () <= (unsigned) e
->uid
)
2562 || !inline_edge_summary (e
)->predicate
)))
2564 != compute_call_stmt_bb_frequency (e
->caller
->symbol
.decl
,
2565 gimple_bb (e
->call_stmt
))))
2567 error ("caller edge frequency %i does not match BB frequency %i",
2569 compute_call_stmt_bb_frequency (e
->caller
->symbol
.decl
,
2570 gimple_bb (e
->call_stmt
)));
2576 /* Switch to THIS_CFUN if needed and print STMT to stderr. */
2578 cgraph_debug_gimple_stmt (struct function
*this_cfun
, gimple stmt
)
2580 bool fndecl_was_null
= false;
2581 /* debug_gimple_stmt needs correct cfun */
2582 if (cfun
!= this_cfun
)
2583 set_cfun (this_cfun
);
2584 /* ...and an actual current_function_decl */
2585 if (!current_function_decl
)
2587 current_function_decl
= this_cfun
->decl
;
2588 fndecl_was_null
= true;
2590 debug_gimple_stmt (stmt
);
2591 if (fndecl_was_null
)
2592 current_function_decl
= NULL
;
2595 /* Verify that call graph edge E corresponds to DECL from the associated
2596 statement. Return true if the verification should fail. */
2599 verify_edge_corresponds_to_fndecl (struct cgraph_edge
*e
, tree decl
)
2601 struct cgraph_node
*node
;
2603 if (!decl
|| e
->callee
->global
.inlined_to
)
2605 if (cgraph_state
== CGRAPH_LTO_STREAMING
)
2607 node
= cgraph_get_node (decl
);
2609 /* We do not know if a node from a different partition is an alias or what it
2610 aliases and therefore cannot do the former_clone_of check reliably. */
2611 if (!node
|| node
->symbol
.in_other_partition
|| e
->callee
->symbol
.in_other_partition
)
2613 node
= cgraph_function_or_thunk_node (node
, NULL
);
2615 if (e
->callee
->former_clone_of
!= node
->symbol
.decl
2616 /* IPA-CP sometimes redirect edge to clone and then back to the former
2617 function. This ping-pong has to go, eventually. */
2618 && (node
!= cgraph_function_or_thunk_node (e
->callee
, NULL
))
2619 && !clone_of_p (cgraph_function_or_thunk_node (node
, NULL
), e
->callee
))
2625 /* Verify cgraph nodes of given cgraph node. */
2627 verify_cgraph_node (struct cgraph_node
*node
)
2629 struct cgraph_edge
*e
;
2630 struct function
*this_cfun
= DECL_STRUCT_FUNCTION (node
->symbol
.decl
);
2631 basic_block this_block
;
2632 gimple_stmt_iterator gsi
;
2633 bool error_found
= false;
2638 timevar_push (TV_CGRAPH_VERIFY
);
2639 error_found
|= verify_symtab_base ((symtab_node
) node
);
2640 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2643 error ("aux field set for edge %s->%s",
2644 identifier_to_locale (cgraph_node_name (e
->caller
)),
2645 identifier_to_locale (cgraph_node_name (e
->callee
)));
2648 if (node
->count
< 0)
2650 error ("execution count is negative");
2653 if (node
->global
.inlined_to
&& node
->symbol
.same_comdat_group
)
2655 error ("inline clone in same comdat group list");
2658 if (!node
->symbol
.definition
&& !node
->symbol
.in_other_partition
&& node
->local
.local
)
2660 error ("local symbols must be defined");
2663 if (node
->global
.inlined_to
&& node
->symbol
.externally_visible
)
2665 error ("externally visible inline clone");
2668 if (node
->global
.inlined_to
&& node
->symbol
.address_taken
)
2670 error ("inline clone with address taken");
2673 if (node
->global
.inlined_to
&& node
->symbol
.force_output
)
2675 error ("inline clone is forced to output");
2678 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2682 error ("aux field set for indirect edge from %s",
2683 identifier_to_locale (cgraph_node_name (e
->caller
)));
2686 if (!e
->indirect_unknown_callee
2687 || !e
->indirect_info
)
2689 error ("An indirect edge from %s is not marked as indirect or has "
2690 "associated indirect_info, the corresponding statement is: ",
2691 identifier_to_locale (cgraph_node_name (e
->caller
)));
2692 cgraph_debug_gimple_stmt (this_cfun
, e
->call_stmt
);
2696 for (e
= node
->callers
; e
; e
= e
->next_caller
)
2698 if (verify_edge_count_and_frequency (e
))
2700 if (!e
->inline_failed
)
2702 if (node
->global
.inlined_to
2703 != (e
->caller
->global
.inlined_to
2704 ? e
->caller
->global
.inlined_to
: e
->caller
))
2706 error ("inlined_to pointer is wrong");
2709 if (node
->callers
->next_caller
)
2711 error ("multiple inline callers");
2716 if (node
->global
.inlined_to
)
2718 error ("inlined_to pointer set for noninline callers");
2722 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2723 if (verify_edge_count_and_frequency (e
))
2725 if (!node
->callers
&& node
->global
.inlined_to
)
2727 error ("inlined_to pointer is set but no predecessors found");
2730 if (node
->global
.inlined_to
== node
)
2732 error ("inlined_to pointer refers to itself");
2738 struct cgraph_node
*n
;
2739 for (n
= node
->clone_of
->clones
; n
; n
= n
->next_sibling_clone
)
2744 error ("node has wrong clone_of");
2750 struct cgraph_node
*n
;
2751 for (n
= node
->clones
; n
; n
= n
->next_sibling_clone
)
2752 if (n
->clone_of
!= node
)
2756 error ("node has wrong clone list");
2760 if ((node
->prev_sibling_clone
|| node
->next_sibling_clone
) && !node
->clone_of
)
2762 error ("node is in clone list but it is not clone");
2765 if (!node
->prev_sibling_clone
&& node
->clone_of
&& node
->clone_of
->clones
!= node
)
2767 error ("node has wrong prev_clone pointer");
2770 if (node
->prev_sibling_clone
&& node
->prev_sibling_clone
->next_sibling_clone
!= node
)
2772 error ("double linked list of clones corrupted");
2776 if (node
->symbol
.analyzed
&& node
->symbol
.alias
)
2778 bool ref_found
= false;
2780 struct ipa_ref
*ref
;
2784 error ("Alias has call edges");
2787 for (i
= 0; ipa_ref_list_reference_iterate (&node
->symbol
.ref_list
,
2789 if (ref
->use
!= IPA_REF_ALIAS
)
2791 error ("Alias has non-alias reference");
2796 error ("Alias has more than one alias reference");
2803 error ("Analyzed alias has no reference");
2807 if (node
->symbol
.analyzed
&& node
->thunk
.thunk_p
)
2811 error ("No edge out of thunk node");
2814 else if (node
->callees
->next_callee
)
2816 error ("More than one edge out of thunk node");
2819 if (gimple_has_body_p (node
->symbol
.decl
))
2821 error ("Thunk is not supposed to have body");
2825 else if (node
->symbol
.analyzed
&& gimple_has_body_p (node
->symbol
.decl
)
2826 && !TREE_ASM_WRITTEN (node
->symbol
.decl
)
2827 && (!DECL_EXTERNAL (node
->symbol
.decl
) || node
->global
.inlined_to
)
2832 pointer_set_t
*stmts
= pointer_set_create ();
2834 struct ipa_ref
*ref
;
2836 /* Reach the trees by walking over the CFG, and note the
2837 enclosing basic-blocks in the call edges. */
2838 FOR_EACH_BB_FN (this_block
, this_cfun
)
2840 for (gsi
= gsi_start_phis (this_block
);
2841 !gsi_end_p (gsi
); gsi_next (&gsi
))
2842 pointer_set_insert (stmts
, gsi_stmt (gsi
));
2843 for (gsi
= gsi_start_bb (this_block
);
2847 gimple stmt
= gsi_stmt (gsi
);
2848 pointer_set_insert (stmts
, stmt
);
2849 if (is_gimple_call (stmt
))
2851 struct cgraph_edge
*e
= cgraph_edge (node
, stmt
);
2852 tree decl
= gimple_call_fndecl (stmt
);
2857 error ("shared call_stmt:");
2858 cgraph_debug_gimple_stmt (this_cfun
, stmt
);
2861 if (!e
->indirect_unknown_callee
)
2863 if (verify_edge_corresponds_to_fndecl (e
, decl
))
2865 error ("edge points to wrong declaration:");
2866 debug_tree (e
->callee
->symbol
.decl
);
2867 fprintf (stderr
," Instead of:");
2874 error ("an indirect edge with unknown callee "
2875 "corresponding to a call_stmt with "
2876 "a known declaration:");
2878 cgraph_debug_gimple_stmt (this_cfun
, e
->call_stmt
);
2884 error ("missing callgraph edge for call stmt:");
2885 cgraph_debug_gimple_stmt (this_cfun
, stmt
);
2892 ipa_ref_list_reference_iterate (&node
->symbol
.ref_list
, i
, ref
);
2894 if (ref
->stmt
&& !pointer_set_contains (stmts
, ref
->stmt
))
2896 error ("reference to dead statement");
2897 cgraph_debug_gimple_stmt (this_cfun
, ref
->stmt
);
2900 pointer_set_destroy (stmts
);
2903 /* No CFG available?! */
2906 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2910 error ("edge %s->%s has no corresponding call_stmt",
2911 identifier_to_locale (cgraph_node_name (e
->caller
)),
2912 identifier_to_locale (cgraph_node_name (e
->callee
)));
2913 cgraph_debug_gimple_stmt (this_cfun
, e
->call_stmt
);
2918 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2920 if (!e
->aux
&& !e
->speculative
)
2922 error ("an indirect edge from %s has no corresponding call_stmt",
2923 identifier_to_locale (cgraph_node_name (e
->caller
)));
2924 cgraph_debug_gimple_stmt (this_cfun
, e
->call_stmt
);
2932 dump_cgraph_node (stderr
, node
);
2933 internal_error ("verify_cgraph_node failed");
2935 timevar_pop (TV_CGRAPH_VERIFY
);
2938 /* Verify whole cgraph structure. */
2940 verify_cgraph (void)
2942 struct cgraph_node
*node
;
2947 FOR_EACH_FUNCTION (node
)
2948 verify_cgraph_node (node
);
2951 /* Create external decl node for DECL.
2952 The difference i nbetween cgraph_get_create_node and
2953 cgraph_get_create_real_symbol_node is that cgraph_get_create_node
2954 may return inline clone, while cgraph_get_create_real_symbol_node
2955 will create a new node in this case.
2956 FIXME: This function should be removed once clones are put out of decl
2959 struct cgraph_node
*
2960 cgraph_get_create_real_symbol_node (tree decl
)
2962 struct cgraph_node
*first_clone
= cgraph_get_node (decl
);
2963 struct cgraph_node
*node
;
2964 /* create symbol table node. even if inline clone exists, we can not take
2965 it as a target of non-inlined call. */
2966 node
= cgraph_get_node (decl
);
2967 if (node
&& !node
->global
.inlined_to
)
2970 node
= cgraph_create_node (decl
);
2972 /* ok, we previously inlined the function, then removed the offline copy and
2973 now we want it back for external call. this can happen when devirtualizing
2974 while inlining function called once that happens after extern inlined and
2975 virtuals are already removed. in this case introduce the external node
2976 and make it available for call. */
2979 first_clone
->clone_of
= node
;
2980 node
->clones
= first_clone
;
2981 symtab_prevail_in_asm_name_hash ((symtab_node
) node
);
2982 symtab_insert_node_to_hashtable ((symtab_node
) node
);
2984 fprintf (dump_file
, "Introduced new external node "
2985 "(%s/%i) and turned into root of the clone tree.\n",
2986 xstrdup (cgraph_node_name (node
)), node
->symbol
.order
);
2989 fprintf (dump_file
, "Introduced new external node "
2990 "(%s/%i).\n", xstrdup (cgraph_node_name (node
)),
2991 node
->symbol
.order
);
2996 /* Given NODE, walk the alias chain to return the function NODE is alias of.
2997 Walk through thunk, too.
2998 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
3000 struct cgraph_node
*
3001 cgraph_function_node (struct cgraph_node
*node
, enum availability
*availability
)
3005 node
= cgraph_function_or_thunk_node (node
, availability
);
3006 if (node
->thunk
.thunk_p
)
3008 node
= node
->callees
->callee
;
3011 enum availability a
;
3012 a
= cgraph_function_body_availability (node
);
3013 if (a
< *availability
)
3016 node
= cgraph_function_or_thunk_node (node
, availability
);
3018 } while (node
&& node
->thunk
.thunk_p
);
3022 /* When doing LTO, read NODE's body from disk if it is not already present. */
3025 cgraph_get_body (struct cgraph_node
*node
)
3027 struct lto_file_decl_data
*file_data
;
3028 const char *data
, *name
;
3030 tree decl
= node
->symbol
.decl
;
3032 if (DECL_RESULT (decl
))
3035 gcc_assert (in_lto_p
);
3037 file_data
= node
->symbol
.lto_file_data
;
3038 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
3040 /* We may have renamed the declaration, e.g., a static function. */
3041 name
= lto_get_decl_name_mapping (file_data
, name
);
3043 data
= lto_get_section_data (file_data
, LTO_section_function_body
,
3047 dump_cgraph_node (stderr
, node
);
3048 fatal_error ("%s: section %s is missing",
3049 file_data
->file_name
,
3053 gcc_assert (DECL_STRUCT_FUNCTION (decl
) == NULL
);
3055 lto_input_function_body (file_data
, decl
, data
);
3056 lto_stats
.num_function_bodies
++;
3057 lto_free_section_data (file_data
, LTO_section_function_body
, name
,
3062 #include "gt-cgraph.h"