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
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
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
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
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
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
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.
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
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. */
77 #include "coretypes.h"
80 #include "tree-inline.h"
81 #include "langhooks.h"
88 #include "basic-block.h"
93 #include "tree-dump.h"
94 #include "tree-flow.h"
95 #include "value-prof.h"
97 #include "diagnostic-core.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
[]=
108 "prevailing_def_ironly",
114 "prevailing_def_ironly_exp"
117 static void cgraph_node_remove_callers (struct cgraph_node
*node
);
118 static inline void cgraph_edge_remove_caller (struct cgraph_edge
*e
);
119 static inline void cgraph_edge_remove_callee (struct cgraph_edge
*e
);
121 /* Hash table used to convert declarations into nodes. */
122 static GTY((param_is (struct cgraph_node
))) htab_t cgraph_hash
;
123 /* Hash table used to convert assembler names into nodes. */
124 static GTY((param_is (struct cgraph_node
))) htab_t assembler_name_hash
;
126 /* The linked list of cgraph nodes. */
127 struct cgraph_node
*cgraph_nodes
;
129 /* Queue of cgraph nodes scheduled to be lowered. */
130 struct cgraph_node
*cgraph_nodes_queue
;
132 /* Queue of cgraph nodes scheduled to be added into cgraph. This is a
133 secondary queue used during optimization to accommodate passes that
134 may generate new functions that need to be optimized and expanded. */
135 struct cgraph_node
*cgraph_new_nodes
;
137 /* Number of nodes in existence. */
140 /* Maximal uid used in cgraph nodes. */
143 /* Maximal uid used in cgraph edges. */
144 int cgraph_edge_max_uid
;
146 /* Set when whole unit has been analyzed so we can access global info. */
147 bool cgraph_global_info_ready
= false;
149 /* What state callgraph is in right now. */
150 enum cgraph_state cgraph_state
= CGRAPH_STATE_CONSTRUCTION
;
152 /* Set when the cgraph is fully build and the basic flags are computed. */
153 bool cgraph_function_flags_ready
= false;
155 /* Linked list of cgraph asm nodes. */
156 struct cgraph_asm_node
*cgraph_asm_nodes
;
158 /* Last node in cgraph_asm_nodes. */
159 static GTY(()) struct cgraph_asm_node
*cgraph_asm_last_node
;
161 /* The order index of the next cgraph node to be created. This is
162 used so that we can sort the cgraph nodes in order by when we saw
163 them, to support -fno-toplevel-reorder. */
166 /* List of hooks triggered on cgraph_edge events. */
167 struct cgraph_edge_hook_list
{
168 cgraph_edge_hook hook
;
170 struct cgraph_edge_hook_list
*next
;
173 /* List of hooks triggered on cgraph_node events. */
174 struct cgraph_node_hook_list
{
175 cgraph_node_hook hook
;
177 struct cgraph_node_hook_list
*next
;
180 /* List of hooks triggered on events involving two cgraph_edges. */
181 struct cgraph_2edge_hook_list
{
182 cgraph_2edge_hook hook
;
184 struct cgraph_2edge_hook_list
*next
;
187 /* List of hooks triggered on events involving two cgraph_nodes. */
188 struct cgraph_2node_hook_list
{
189 cgraph_2node_hook hook
;
191 struct cgraph_2node_hook_list
*next
;
194 /* List of hooks triggered when an edge is removed. */
195 struct cgraph_edge_hook_list
*first_cgraph_edge_removal_hook
;
196 /* List of hooks triggered when a node is removed. */
197 struct cgraph_node_hook_list
*first_cgraph_node_removal_hook
;
198 /* List of hooks triggered when an edge is duplicated. */
199 struct cgraph_2edge_hook_list
*first_cgraph_edge_duplicated_hook
;
200 /* List of hooks triggered when a node is duplicated. */
201 struct cgraph_2node_hook_list
*first_cgraph_node_duplicated_hook
;
202 /* List of hooks triggered when an function is inserted. */
203 struct cgraph_node_hook_list
*first_cgraph_function_insertion_hook
;
205 /* Head of a linked list of unused (freed) call graph nodes.
206 Do not GTY((delete)) this list so UIDs gets reliably recycled. */
207 static GTY(()) struct cgraph_node
*free_nodes
;
208 /* Head of a linked list of unused (freed) call graph edges.
209 Do not GTY((delete)) this list so UIDs gets reliably recycled. */
210 static GTY(()) struct cgraph_edge
*free_edges
;
212 /* Did procss_same_body_aliases run? */
213 bool same_body_aliases_done
;
215 /* Macros to access the next item in the list of free cgraph nodes and
217 #define NEXT_FREE_NODE(NODE) (NODE)->next
218 #define NEXT_FREE_EDGE(EDGE) (EDGE)->prev_caller
220 /* Register HOOK to be called with DATA on each removed edge. */
221 struct cgraph_edge_hook_list
*
222 cgraph_add_edge_removal_hook (cgraph_edge_hook hook
, void *data
)
224 struct cgraph_edge_hook_list
*entry
;
225 struct cgraph_edge_hook_list
**ptr
= &first_cgraph_edge_removal_hook
;
227 entry
= (struct cgraph_edge_hook_list
*) xmalloc (sizeof (*entry
));
237 /* Remove ENTRY from the list of hooks called on removing edges. */
239 cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list
*entry
)
241 struct cgraph_edge_hook_list
**ptr
= &first_cgraph_edge_removal_hook
;
243 while (*ptr
!= entry
)
249 /* Call all edge removal hooks. */
251 cgraph_call_edge_removal_hooks (struct cgraph_edge
*e
)
253 struct cgraph_edge_hook_list
*entry
= first_cgraph_edge_removal_hook
;
256 entry
->hook (e
, entry
->data
);
261 /* Register HOOK to be called with DATA on each removed node. */
262 struct cgraph_node_hook_list
*
263 cgraph_add_node_removal_hook (cgraph_node_hook hook
, void *data
)
265 struct cgraph_node_hook_list
*entry
;
266 struct cgraph_node_hook_list
**ptr
= &first_cgraph_node_removal_hook
;
268 entry
= (struct cgraph_node_hook_list
*) xmalloc (sizeof (*entry
));
278 /* Remove ENTRY from the list of hooks called on removing nodes. */
280 cgraph_remove_node_removal_hook (struct cgraph_node_hook_list
*entry
)
282 struct cgraph_node_hook_list
**ptr
= &first_cgraph_node_removal_hook
;
284 while (*ptr
!= entry
)
290 /* Call all node removal hooks. */
292 cgraph_call_node_removal_hooks (struct cgraph_node
*node
)
294 struct cgraph_node_hook_list
*entry
= first_cgraph_node_removal_hook
;
297 entry
->hook (node
, entry
->data
);
302 /* Register HOOK to be called with DATA on each inserted node. */
303 struct cgraph_node_hook_list
*
304 cgraph_add_function_insertion_hook (cgraph_node_hook hook
, void *data
)
306 struct cgraph_node_hook_list
*entry
;
307 struct cgraph_node_hook_list
**ptr
= &first_cgraph_function_insertion_hook
;
309 entry
= (struct cgraph_node_hook_list
*) xmalloc (sizeof (*entry
));
319 /* Remove ENTRY from the list of hooks called on inserted nodes. */
321 cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list
*entry
)
323 struct cgraph_node_hook_list
**ptr
= &first_cgraph_function_insertion_hook
;
325 while (*ptr
!= entry
)
331 /* Call all node insertion hooks. */
333 cgraph_call_function_insertion_hooks (struct cgraph_node
*node
)
335 struct cgraph_node_hook_list
*entry
= first_cgraph_function_insertion_hook
;
338 entry
->hook (node
, entry
->data
);
343 /* Register HOOK to be called with DATA on each duplicated edge. */
344 struct cgraph_2edge_hook_list
*
345 cgraph_add_edge_duplication_hook (cgraph_2edge_hook hook
, void *data
)
347 struct cgraph_2edge_hook_list
*entry
;
348 struct cgraph_2edge_hook_list
**ptr
= &first_cgraph_edge_duplicated_hook
;
350 entry
= (struct cgraph_2edge_hook_list
*) xmalloc (sizeof (*entry
));
360 /* Remove ENTRY from the list of hooks called on duplicating edges. */
362 cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list
*entry
)
364 struct cgraph_2edge_hook_list
**ptr
= &first_cgraph_edge_duplicated_hook
;
366 while (*ptr
!= entry
)
372 /* Call all edge duplication hooks. */
374 cgraph_call_edge_duplication_hooks (struct cgraph_edge
*cs1
,
375 struct cgraph_edge
*cs2
)
377 struct cgraph_2edge_hook_list
*entry
= first_cgraph_edge_duplicated_hook
;
380 entry
->hook (cs1
, cs2
, entry
->data
);
385 /* Register HOOK to be called with DATA on each duplicated node. */
386 struct cgraph_2node_hook_list
*
387 cgraph_add_node_duplication_hook (cgraph_2node_hook hook
, void *data
)
389 struct cgraph_2node_hook_list
*entry
;
390 struct cgraph_2node_hook_list
**ptr
= &first_cgraph_node_duplicated_hook
;
392 entry
= (struct cgraph_2node_hook_list
*) xmalloc (sizeof (*entry
));
402 /* Remove ENTRY from the list of hooks called on duplicating nodes. */
404 cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list
*entry
)
406 struct cgraph_2node_hook_list
**ptr
= &first_cgraph_node_duplicated_hook
;
408 while (*ptr
!= entry
)
414 /* Call all node duplication hooks. */
416 cgraph_call_node_duplication_hooks (struct cgraph_node
*node1
,
417 struct cgraph_node
*node2
)
419 struct cgraph_2node_hook_list
*entry
= first_cgraph_node_duplicated_hook
;
422 entry
->hook (node1
, node2
, entry
->data
);
427 /* Returns a hash code for P. */
430 hash_node (const void *p
)
432 const struct cgraph_node
*n
= (const struct cgraph_node
*) p
;
433 return (hashval_t
) DECL_UID (n
->decl
);
437 /* Returns nonzero if P1 and P2 are equal. */
440 eq_node (const void *p1
, const void *p2
)
442 const struct cgraph_node
*n1
= (const struct cgraph_node
*) p1
;
443 const struct cgraph_node
*n2
= (const struct cgraph_node
*) p2
;
444 return DECL_UID (n1
->decl
) == DECL_UID (n2
->decl
);
447 /* Allocate new callgraph node. */
449 static inline struct cgraph_node
*
450 cgraph_allocate_node (void)
452 struct cgraph_node
*node
;
457 free_nodes
= NEXT_FREE_NODE (node
);
461 node
= ggc_alloc_cleared_cgraph_node ();
462 node
->uid
= cgraph_max_uid
++;
468 /* Allocate new callgraph node and insert it into basic data structures. */
470 static struct cgraph_node
*
471 cgraph_create_node_1 (void)
473 struct cgraph_node
*node
= cgraph_allocate_node ();
475 node
->next
= cgraph_nodes
;
476 node
->order
= cgraph_order
++;
478 cgraph_nodes
->previous
= node
;
479 node
->previous
= NULL
;
480 node
->frequency
= NODE_FREQUENCY_NORMAL
;
481 node
->count_materialization_scale
= REG_BR_PROB_BASE
;
482 ipa_empty_ref_list (&node
->ref_list
);
488 /* Return cgraph node assigned to DECL. Create new one when needed. */
491 cgraph_create_node (tree decl
)
493 struct cgraph_node key
, *node
, **slot
;
495 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
498 cgraph_hash
= htab_create_ggc (10, hash_node
, eq_node
, NULL
);
501 slot
= (struct cgraph_node
**) htab_find_slot (cgraph_hash
, &key
, INSERT
);
504 node
= cgraph_create_node_1 ();
507 if (DECL_CONTEXT (decl
) && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
509 node
->origin
= cgraph_get_create_node (DECL_CONTEXT (decl
));
510 node
->next_nested
= node
->origin
->nested
;
511 node
->origin
->nested
= node
;
513 if (assembler_name_hash
)
516 tree name
= DECL_ASSEMBLER_NAME (decl
);
518 aslot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
519 decl_assembler_name_hash (name
),
521 /* We can have multiple declarations with same assembler name. For C++
522 it is __builtin_strlen and strlen, for instance. Do we need to
523 record them all? Original implementation marked just first one
524 so lets hope for the best. */
531 /* Try to find a call graph node for declaration DECL and if it does not exist,
535 cgraph_get_create_node (tree decl
)
537 struct cgraph_node
*node
;
539 node
= cgraph_get_node (decl
);
543 return cgraph_create_node (decl
);
546 /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
547 the function body is associated with (not neccesarily cgraph_node (DECL). */
550 cgraph_create_function_alias (tree alias
, tree decl
)
552 struct cgraph_node
*alias_node
;
554 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
555 gcc_assert (TREE_CODE (alias
) == FUNCTION_DECL
);
556 alias_node
= cgraph_get_create_node (alias
);
557 gcc_assert (!alias_node
->local
.finalized
);
558 alias_node
->thunk
.alias
= decl
;
559 alias_node
->local
.finalized
= true;
560 alias_node
->alias
= 1;
562 if ((TREE_PUBLIC (alias
) && !DECL_COMDAT (alias
) && !DECL_EXTERNAL (alias
))
563 || (DECL_VIRTUAL_P (alias
)
564 && (DECL_COMDAT (alias
) || DECL_EXTERNAL (alias
))))
565 cgraph_mark_reachable_node (alias_node
);
569 /* Attempt to mark ALIAS as an alias to DECL. Return alias node if successful
571 Same body aliases are output whenever the body of DECL is output,
572 and cgraph_get_node (ALIAS) transparently returns cgraph_get_node (DECL). */
575 cgraph_same_body_alias (struct cgraph_node
*decl_node ATTRIBUTE_UNUSED
, tree alias
, tree decl
)
577 struct cgraph_node
*n
;
578 #ifndef ASM_OUTPUT_DEF
579 /* If aliases aren't supported by the assembler, fail. */
582 /* Langhooks can create same body aliases of symbols not defined.
583 Those are useless. Drop them on the floor. */
584 if (cgraph_global_info_ready
)
587 n
= cgraph_create_function_alias (alias
, decl
);
588 n
->same_body_alias
= true;
589 if (same_body_aliases_done
)
590 ipa_record_reference (n
, NULL
, cgraph_get_node (decl
), NULL
, IPA_REF_ALIAS
,
595 /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
596 aliases DECL with an adjustments made into the first parameter.
597 See comments in thunk_adjust for detail on the parameters. */
600 cgraph_add_thunk (struct cgraph_node
*decl_node ATTRIBUTE_UNUSED
,
601 tree alias
, tree decl
,
603 HOST_WIDE_INT fixed_offset
, HOST_WIDE_INT virtual_value
,
607 struct cgraph_node
*node
;
609 node
= cgraph_get_node (alias
);
612 gcc_assert (node
->local
.finalized
);
613 gcc_assert (!node
->alias
);
614 gcc_assert (!node
->thunk
.thunk_p
);
615 cgraph_remove_node (node
);
618 node
= cgraph_create_node (alias
);
619 gcc_checking_assert (!virtual_offset
620 || double_int_equal_p
621 (tree_to_double_int (virtual_offset
),
622 shwi_to_double_int (virtual_value
)));
623 node
->thunk
.fixed_offset
= fixed_offset
;
624 node
->thunk
.this_adjusting
= this_adjusting
;
625 node
->thunk
.virtual_value
= virtual_value
;
626 node
->thunk
.virtual_offset_p
= virtual_offset
!= NULL
;
627 node
->thunk
.alias
= real_alias
;
628 node
->thunk
.thunk_p
= true;
629 node
->local
.finalized
= true;
631 if (cgraph_decide_is_function_needed (node
, decl
))
632 cgraph_mark_needed_node (node
);
634 if ((TREE_PUBLIC (decl
) && !DECL_COMDAT (decl
) && !DECL_EXTERNAL (decl
))
635 || (DECL_VIRTUAL_P (decl
)
636 && (DECL_COMDAT (decl
) || DECL_EXTERNAL (decl
))))
637 cgraph_mark_reachable_node (node
);
642 /* Returns the cgraph node assigned to DECL or NULL if no cgraph node
646 cgraph_get_node (const_tree decl
)
648 struct cgraph_node key
, *node
= NULL
, **slot
;
650 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
655 key
.decl
= CONST_CAST2 (tree
, const_tree
, decl
);
657 slot
= (struct cgraph_node
**) htab_find_slot (cgraph_hash
, &key
,
665 /* Insert already constructed node into hashtable. */
668 cgraph_insert_node_to_hashtable (struct cgraph_node
*node
)
670 struct cgraph_node
**slot
;
672 slot
= (struct cgraph_node
**) htab_find_slot (cgraph_hash
, node
, INSERT
);
678 /* Returns a hash code for P. */
681 hash_node_by_assembler_name (const void *p
)
683 const struct cgraph_node
*n
= (const struct cgraph_node
*) p
;
684 return (hashval_t
) decl_assembler_name_hash (DECL_ASSEMBLER_NAME (n
->decl
));
687 /* Returns nonzero if P1 and P2 are equal. */
690 eq_assembler_name (const void *p1
, const void *p2
)
692 const struct cgraph_node
*n1
= (const struct cgraph_node
*) p1
;
693 const_tree name
= (const_tree
)p2
;
694 return (decl_assembler_name_equal (n1
->decl
, name
));
697 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
698 Return NULL if there's no such node. */
701 cgraph_node_for_asm (tree asmname
)
703 struct cgraph_node
*node
;
706 if (!assembler_name_hash
)
708 assembler_name_hash
=
709 htab_create_ggc (10, hash_node_by_assembler_name
, eq_assembler_name
,
711 for (node
= cgraph_nodes
; node
; node
= node
->next
)
712 if (!node
->global
.inlined_to
)
714 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
715 slot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
716 decl_assembler_name_hash (name
),
718 /* We can have multiple declarations with same assembler name. For C++
719 it is __builtin_strlen and strlen, for instance. Do we need to
720 record them all? Original implementation marked just first one
721 so lets hope for the best. */
727 slot
= htab_find_slot_with_hash (assembler_name_hash
, asmname
,
728 decl_assembler_name_hash (asmname
),
733 node
= (struct cgraph_node
*) *slot
;
739 /* Returns a hash value for X (which really is a die_struct). */
742 edge_hash (const void *x
)
744 return htab_hash_pointer (((const struct cgraph_edge
*) x
)->call_stmt
);
747 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
750 edge_eq (const void *x
, const void *y
)
752 return ((const struct cgraph_edge
*) x
)->call_stmt
== y
;
755 /* Add call graph edge E to call site hash of its caller. */
758 cgraph_add_edge_to_call_site_hash (struct cgraph_edge
*e
)
761 slot
= htab_find_slot_with_hash (e
->caller
->call_site_hash
,
763 htab_hash_pointer (e
->call_stmt
),
769 /* Return the callgraph edge representing the GIMPLE_CALL statement
773 cgraph_edge (struct cgraph_node
*node
, gimple call_stmt
)
775 struct cgraph_edge
*e
, *e2
;
778 if (node
->call_site_hash
)
779 return (struct cgraph_edge
*)
780 htab_find_with_hash (node
->call_site_hash
, call_stmt
,
781 htab_hash_pointer (call_stmt
));
783 /* This loop may turn out to be performance problem. In such case adding
784 hashtables into call nodes with very many edges is probably best
785 solution. It is not good idea to add pointer into CALL_EXPR itself
786 because we want to make possible having multiple cgraph nodes representing
787 different clones of the same body before the body is actually cloned. */
788 for (e
= node
->callees
; e
; e
= e
->next_callee
)
790 if (e
->call_stmt
== call_stmt
)
796 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
798 if (e
->call_stmt
== call_stmt
)
805 node
->call_site_hash
= htab_create_ggc (120, edge_hash
, edge_eq
, NULL
);
806 for (e2
= node
->callees
; e2
; e2
= e2
->next_callee
)
807 cgraph_add_edge_to_call_site_hash (e2
);
808 for (e2
= node
->indirect_calls
; e2
; e2
= e2
->next_callee
)
809 cgraph_add_edge_to_call_site_hash (e2
);
816 /* Change field call_stmt of edge E to NEW_STMT. */
819 cgraph_set_call_stmt (struct cgraph_edge
*e
, gimple new_stmt
)
823 if (e
->caller
->call_site_hash
)
825 htab_remove_elt_with_hash (e
->caller
->call_site_hash
,
827 htab_hash_pointer (e
->call_stmt
));
830 e
->call_stmt
= new_stmt
;
831 if (e
->indirect_unknown_callee
832 && (decl
= gimple_call_fndecl (new_stmt
)))
834 /* Constant propagation (and possibly also inlining?) can turn an
835 indirect call into a direct one. */
836 struct cgraph_node
*new_callee
= cgraph_get_node (decl
);
838 gcc_checking_assert (new_callee
);
839 cgraph_make_edge_direct (e
, new_callee
);
842 push_cfun (DECL_STRUCT_FUNCTION (e
->caller
->decl
));
843 e
->can_throw_external
= stmt_can_throw_external (new_stmt
);
845 if (e
->caller
->call_site_hash
)
846 cgraph_add_edge_to_call_site_hash (e
);
849 /* Like cgraph_set_call_stmt but walk the clone tree and update all
850 clones sharing the same function body. */
853 cgraph_set_call_stmt_including_clones (struct cgraph_node
*orig
,
854 gimple old_stmt
, gimple new_stmt
)
856 struct cgraph_node
*node
;
857 struct cgraph_edge
*edge
= cgraph_edge (orig
, old_stmt
);
860 cgraph_set_call_stmt (edge
, new_stmt
);
866 struct cgraph_edge
*edge
= cgraph_edge (node
, old_stmt
);
868 cgraph_set_call_stmt (edge
, new_stmt
);
871 else if (node
->next_sibling_clone
)
872 node
= node
->next_sibling_clone
;
875 while (node
!= orig
&& !node
->next_sibling_clone
)
876 node
= node
->clone_of
;
878 node
= node
->next_sibling_clone
;
883 /* Like cgraph_create_edge walk the clone tree and update all clones sharing
884 same function body. If clones already have edge for OLD_STMT; only
885 update the edge same way as cgraph_set_call_stmt_including_clones does.
887 TODO: COUNT and LOOP_DEPTH should be properly distributed based on relative
888 frequencies of the clones. */
891 cgraph_create_edge_including_clones (struct cgraph_node
*orig
,
892 struct cgraph_node
*callee
,
894 gimple stmt
, gcov_type count
,
896 cgraph_inline_failed_t reason
)
898 struct cgraph_node
*node
;
899 struct cgraph_edge
*edge
;
901 if (!cgraph_edge (orig
, stmt
))
903 edge
= cgraph_create_edge (orig
, callee
, stmt
, count
, freq
);
904 edge
->inline_failed
= reason
;
911 struct cgraph_edge
*edge
= cgraph_edge (node
, old_stmt
);
913 /* It is possible that clones already contain the edge while
914 master didn't. Either we promoted indirect call into direct
915 call in the clone or we are processing clones of unreachable
916 master where edges has been removed. */
918 cgraph_set_call_stmt (edge
, stmt
);
919 else if (!cgraph_edge (node
, stmt
))
921 edge
= cgraph_create_edge (node
, callee
, stmt
, count
,
923 edge
->inline_failed
= reason
;
928 else if (node
->next_sibling_clone
)
929 node
= node
->next_sibling_clone
;
932 while (node
!= orig
&& !node
->next_sibling_clone
)
933 node
= node
->clone_of
;
935 node
= node
->next_sibling_clone
;
940 /* Allocate a cgraph_edge structure and fill it with data according to the
941 parameters of which only CALLEE can be NULL (when creating an indirect call
944 static struct cgraph_edge
*
945 cgraph_create_edge_1 (struct cgraph_node
*caller
, struct cgraph_node
*callee
,
946 gimple call_stmt
, gcov_type count
, int freq
)
948 struct cgraph_edge
*edge
;
950 /* LTO does not actually have access to the call_stmt since these
951 have not been loaded yet. */
954 /* This is a rather expensive check possibly triggering
955 construction of call stmt hashtable. */
956 gcc_checking_assert (!cgraph_edge (caller
, call_stmt
));
958 gcc_assert (is_gimple_call (call_stmt
));
964 free_edges
= NEXT_FREE_EDGE (edge
);
968 edge
= ggc_alloc_cgraph_edge ();
969 edge
->uid
= cgraph_edge_max_uid
++;
973 edge
->caller
= caller
;
974 edge
->callee
= callee
;
975 edge
->prev_caller
= NULL
;
976 edge
->next_caller
= NULL
;
977 edge
->prev_callee
= NULL
;
978 edge
->next_callee
= NULL
;
981 gcc_assert (count
>= 0);
982 edge
->frequency
= freq
;
983 gcc_assert (freq
>= 0);
984 gcc_assert (freq
<= CGRAPH_FREQ_MAX
);
986 edge
->call_stmt
= call_stmt
;
987 push_cfun (DECL_STRUCT_FUNCTION (caller
->decl
));
988 edge
->can_throw_external
989 = call_stmt
? stmt_can_throw_external (call_stmt
) : false;
992 && callee
&& callee
->decl
993 && !gimple_check_call_matching_types (call_stmt
, callee
->decl
))
994 edge
->call_stmt_cannot_inline_p
= true;
996 edge
->call_stmt_cannot_inline_p
= false;
997 if (call_stmt
&& caller
->call_site_hash
)
998 cgraph_add_edge_to_call_site_hash (edge
);
1000 edge
->indirect_info
= NULL
;
1001 edge
->indirect_inlining_edge
= 0;
1006 /* Create edge from CALLER to CALLEE in the cgraph. */
1008 struct cgraph_edge
*
1009 cgraph_create_edge (struct cgraph_node
*caller
, struct cgraph_node
*callee
,
1010 gimple call_stmt
, gcov_type count
, int freq
)
1012 struct cgraph_edge
*edge
= cgraph_create_edge_1 (caller
, callee
, call_stmt
,
1015 edge
->indirect_unknown_callee
= 0;
1016 initialize_inline_failed (edge
);
1018 edge
->next_caller
= callee
->callers
;
1019 if (callee
->callers
)
1020 callee
->callers
->prev_caller
= edge
;
1021 edge
->next_callee
= caller
->callees
;
1022 if (caller
->callees
)
1023 caller
->callees
->prev_callee
= edge
;
1024 caller
->callees
= edge
;
1025 callee
->callers
= edge
;
1030 /* Allocate cgraph_indirect_call_info and set its fields to default values. */
1032 struct cgraph_indirect_call_info
*
1033 cgraph_allocate_init_indirect_info (void)
1035 struct cgraph_indirect_call_info
*ii
;
1037 ii
= ggc_alloc_cleared_cgraph_indirect_call_info ();
1038 ii
->param_index
= -1;
1042 /* Create an indirect edge with a yet-undetermined callee where the call
1043 statement destination is a formal parameter of the caller with index
1046 struct cgraph_edge
*
1047 cgraph_create_indirect_edge (struct cgraph_node
*caller
, gimple call_stmt
,
1049 gcov_type count
, int freq
)
1051 struct cgraph_edge
*edge
= cgraph_create_edge_1 (caller
, NULL
, call_stmt
,
1054 edge
->indirect_unknown_callee
= 1;
1055 initialize_inline_failed (edge
);
1057 edge
->indirect_info
= cgraph_allocate_init_indirect_info ();
1058 edge
->indirect_info
->ecf_flags
= ecf_flags
;
1060 edge
->next_callee
= caller
->indirect_calls
;
1061 if (caller
->indirect_calls
)
1062 caller
->indirect_calls
->prev_callee
= edge
;
1063 caller
->indirect_calls
= edge
;
1068 /* Remove the edge E from the list of the callers of the callee. */
1071 cgraph_edge_remove_callee (struct cgraph_edge
*e
)
1073 gcc_assert (!e
->indirect_unknown_callee
);
1075 e
->prev_caller
->next_caller
= e
->next_caller
;
1077 e
->next_caller
->prev_caller
= e
->prev_caller
;
1078 if (!e
->prev_caller
)
1079 e
->callee
->callers
= e
->next_caller
;
1082 /* Remove the edge E from the list of the callees of the caller. */
1085 cgraph_edge_remove_caller (struct cgraph_edge
*e
)
1088 e
->prev_callee
->next_callee
= e
->next_callee
;
1090 e
->next_callee
->prev_callee
= e
->prev_callee
;
1091 if (!e
->prev_callee
)
1093 if (e
->indirect_unknown_callee
)
1094 e
->caller
->indirect_calls
= e
->next_callee
;
1096 e
->caller
->callees
= e
->next_callee
;
1098 if (e
->caller
->call_site_hash
)
1099 htab_remove_elt_with_hash (e
->caller
->call_site_hash
,
1101 htab_hash_pointer (e
->call_stmt
));
1104 /* Put the edge onto the free list. */
1107 cgraph_free_edge (struct cgraph_edge
*e
)
1111 /* Clear out the edge so we do not dangle pointers. */
1112 memset (e
, 0, sizeof (*e
));
1114 NEXT_FREE_EDGE (e
) = free_edges
;
1118 /* Remove the edge E in the cgraph. */
1121 cgraph_remove_edge (struct cgraph_edge
*e
)
1123 /* Call all edge removal hooks. */
1124 cgraph_call_edge_removal_hooks (e
);
1126 if (!e
->indirect_unknown_callee
)
1127 /* Remove from callers list of the callee. */
1128 cgraph_edge_remove_callee (e
);
1130 /* Remove from callees list of the callers. */
1131 cgraph_edge_remove_caller (e
);
1133 /* Put the edge onto the free list. */
1134 cgraph_free_edge (e
);
1137 /* Set callee of call graph edge E and add it to the corresponding set of
1141 cgraph_set_edge_callee (struct cgraph_edge
*e
, struct cgraph_node
*n
)
1143 e
->prev_caller
= NULL
;
1145 n
->callers
->prev_caller
= e
;
1146 e
->next_caller
= n
->callers
;
1151 /* Redirect callee of E to N. The function does not update underlying
1155 cgraph_redirect_edge_callee (struct cgraph_edge
*e
, struct cgraph_node
*n
)
1157 /* Remove from callers list of the current callee. */
1158 cgraph_edge_remove_callee (e
);
1160 /* Insert to callers list of the new callee. */
1161 cgraph_set_edge_callee (e
, n
);
1164 /* Make an indirect EDGE with an unknown callee an ordinary edge leading to
1165 CALLEE. DELTA is an integer constant that is to be added to the this
1166 pointer (first parameter) to compensate for skipping a thunk adjustment. */
1169 cgraph_make_edge_direct (struct cgraph_edge
*edge
, struct cgraph_node
*callee
)
1171 edge
->indirect_unknown_callee
= 0;
1173 /* Get the edge out of the indirect edge list. */
1174 if (edge
->prev_callee
)
1175 edge
->prev_callee
->next_callee
= edge
->next_callee
;
1176 if (edge
->next_callee
)
1177 edge
->next_callee
->prev_callee
= edge
->prev_callee
;
1178 if (!edge
->prev_callee
)
1179 edge
->caller
->indirect_calls
= edge
->next_callee
;
1181 /* Put it into the normal callee list */
1182 edge
->prev_callee
= NULL
;
1183 edge
->next_callee
= edge
->caller
->callees
;
1184 if (edge
->caller
->callees
)
1185 edge
->caller
->callees
->prev_callee
= edge
;
1186 edge
->caller
->callees
= edge
;
1188 /* Insert to callers list of the new callee. */
1189 cgraph_set_edge_callee (edge
, callee
);
1191 if (edge
->call_stmt
)
1192 edge
->call_stmt_cannot_inline_p
1193 = !gimple_check_call_matching_types (edge
->call_stmt
, callee
->decl
);
1195 /* We need to re-determine the inlining status of the edge. */
1196 initialize_inline_failed (edge
);
1200 /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
1201 OLD_STMT changed into NEW_STMT. OLD_CALL is gimple_call_fndecl
1202 of OLD_STMT if it was previously call statement.
1203 If NEW_STMT is NULL, the call has been dropped without any
1207 cgraph_update_edges_for_call_stmt_node (struct cgraph_node
*node
,
1208 gimple old_stmt
, tree old_call
,
1211 tree new_call
= (new_stmt
&& is_gimple_call (new_stmt
))
1212 ? gimple_call_fndecl (new_stmt
) : 0;
1214 /* We are seeing indirect calls, then there is nothing to update. */
1215 if (!new_call
&& !old_call
)
1217 /* See if we turned indirect call into direct call or folded call to one builtin
1218 into different builtin. */
1219 if (old_call
!= new_call
)
1221 struct cgraph_edge
*e
= cgraph_edge (node
, old_stmt
);
1222 struct cgraph_edge
*ne
= NULL
;
1228 /* See if the edge is already there and has the correct callee. It
1229 might be so because of indirect inlining has already updated
1230 it. We also might've cloned and redirected the edge. */
1231 if (new_call
&& e
->callee
)
1233 struct cgraph_node
*callee
= e
->callee
;
1236 if (callee
->decl
== new_call
1237 || callee
->former_clone_of
== new_call
)
1239 callee
= callee
->clone_of
;
1243 /* Otherwise remove edge and create new one; we can't simply redirect
1244 since function has changed, so inline plan and other information
1245 attached to edge is invalid. */
1247 frequency
= e
->frequency
;
1248 cgraph_remove_edge (e
);
1252 /* We are seeing new direct call; compute profile info based on BB. */
1253 basic_block bb
= gimple_bb (new_stmt
);
1255 frequency
= compute_call_stmt_bb_frequency (current_function_decl
,
1261 ne
= cgraph_create_edge (node
, cgraph_get_create_node (new_call
),
1262 new_stmt
, count
, frequency
);
1263 gcc_assert (ne
->inline_failed
);
1266 /* We only updated the call stmt; update pointer in cgraph edge.. */
1267 else if (old_stmt
!= new_stmt
)
1268 cgraph_set_call_stmt (cgraph_edge (node
, old_stmt
), new_stmt
);
1271 /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
1272 OLD_STMT changed into NEW_STMT. OLD_DECL is gimple_call_fndecl
1273 of OLD_STMT before it was updated (updating can happen inplace). */
1276 cgraph_update_edges_for_call_stmt (gimple old_stmt
, tree old_decl
, gimple new_stmt
)
1278 struct cgraph_node
*orig
= cgraph_get_node (cfun
->decl
);
1279 struct cgraph_node
*node
;
1281 gcc_checking_assert (orig
);
1282 cgraph_update_edges_for_call_stmt_node (orig
, old_stmt
, old_decl
, new_stmt
);
1284 for (node
= orig
->clones
; node
!= orig
;)
1286 cgraph_update_edges_for_call_stmt_node (node
, old_stmt
, old_decl
, new_stmt
);
1288 node
= node
->clones
;
1289 else if (node
->next_sibling_clone
)
1290 node
= node
->next_sibling_clone
;
1293 while (node
!= orig
&& !node
->next_sibling_clone
)
1294 node
= node
->clone_of
;
1296 node
= node
->next_sibling_clone
;
1302 /* Remove all callees from the node. */
1305 cgraph_node_remove_callees (struct cgraph_node
*node
)
1307 struct cgraph_edge
*e
, *f
;
1309 /* It is sufficient to remove the edges from the lists of callers of
1310 the callees. The callee list of the node can be zapped with one
1312 for (e
= node
->callees
; e
; e
= f
)
1315 cgraph_call_edge_removal_hooks (e
);
1316 if (!e
->indirect_unknown_callee
)
1317 cgraph_edge_remove_callee (e
);
1318 cgraph_free_edge (e
);
1320 for (e
= node
->indirect_calls
; e
; e
= f
)
1323 cgraph_call_edge_removal_hooks (e
);
1324 if (!e
->indirect_unknown_callee
)
1325 cgraph_edge_remove_callee (e
);
1326 cgraph_free_edge (e
);
1328 node
->indirect_calls
= NULL
;
1329 node
->callees
= NULL
;
1330 if (node
->call_site_hash
)
1332 htab_delete (node
->call_site_hash
);
1333 node
->call_site_hash
= NULL
;
1337 /* Remove all callers from the node. */
1340 cgraph_node_remove_callers (struct cgraph_node
*node
)
1342 struct cgraph_edge
*e
, *f
;
1344 /* It is sufficient to remove the edges from the lists of callees of
1345 the callers. The caller list of the node can be zapped with one
1347 for (e
= node
->callers
; e
; e
= f
)
1350 cgraph_call_edge_removal_hooks (e
);
1351 cgraph_edge_remove_caller (e
);
1352 cgraph_free_edge (e
);
1354 node
->callers
= NULL
;
1357 /* Release memory used to represent body of function NODE. */
1360 cgraph_release_function_body (struct cgraph_node
*node
)
1362 if (DECL_STRUCT_FUNCTION (node
->decl
))
1364 tree old_decl
= current_function_decl
;
1365 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
1366 if (cfun
->gimple_df
)
1368 current_function_decl
= node
->decl
;
1370 delete_tree_cfg_annotations ();
1372 current_function_decl
= old_decl
;
1376 gcc_assert (dom_computed
[0] == DOM_NONE
);
1377 gcc_assert (dom_computed
[1] == DOM_NONE
);
1380 if (cfun
->value_histograms
)
1382 gcc_assert (!current_loops
);
1384 gimple_set_body (node
->decl
, NULL
);
1385 VEC_free (ipa_opt_pass
, heap
,
1386 node
->ipa_transforms_to_apply
);
1387 /* Struct function hangs a lot of data that would leak if we didn't
1388 removed all pointers to it. */
1389 ggc_free (DECL_STRUCT_FUNCTION (node
->decl
));
1390 DECL_STRUCT_FUNCTION (node
->decl
) = NULL
;
1392 DECL_SAVED_TREE (node
->decl
) = NULL
;
1393 /* If the node is abstract and needed, then do not clear DECL_INITIAL
1394 of its associated function function declaration because it's
1395 needed to emit debug info later. */
1396 if (!node
->abstract_and_needed
)
1397 DECL_INITIAL (node
->decl
) = error_mark_node
;
1400 /* Remove the node from cgraph. */
1403 cgraph_remove_node (struct cgraph_node
*node
)
1406 bool kill_body
= false;
1407 struct cgraph_node
*n
;
1408 int uid
= node
->uid
;
1410 cgraph_call_node_removal_hooks (node
);
1411 cgraph_node_remove_callers (node
);
1412 cgraph_node_remove_callees (node
);
1413 ipa_remove_all_references (&node
->ref_list
);
1414 ipa_remove_all_refering (&node
->ref_list
);
1415 VEC_free (ipa_opt_pass
, heap
,
1416 node
->ipa_transforms_to_apply
);
1418 /* Incremental inlining access removed nodes stored in the postorder list.
1420 node
->needed
= node
->reachable
= false;
1421 for (n
= node
->nested
; n
; n
= n
->next_nested
)
1423 node
->nested
= NULL
;
1426 struct cgraph_node
**node2
= &node
->origin
->nested
;
1428 while (*node2
!= node
)
1429 node2
= &(*node2
)->next_nested
;
1430 *node2
= node
->next_nested
;
1433 node
->previous
->next
= node
->next
;
1435 cgraph_nodes
= node
->next
;
1437 node
->next
->previous
= node
->previous
;
1439 node
->previous
= NULL
;
1440 slot
= htab_find_slot (cgraph_hash
, node
, NO_INSERT
);
1443 struct cgraph_node
*next_inline_clone
;
1445 for (next_inline_clone
= node
->clones
;
1446 next_inline_clone
&& next_inline_clone
->decl
!= node
->decl
;
1447 next_inline_clone
= next_inline_clone
->next_sibling_clone
)
1450 /* If there is inline clone of the node being removed, we need
1451 to put it into the position of removed node and reorganize all
1452 other clones to be based on it. */
1453 if (next_inline_clone
)
1455 struct cgraph_node
*n
;
1456 struct cgraph_node
*new_clones
;
1458 *slot
= next_inline_clone
;
1460 /* Unlink inline clone from the list of clones of removed node. */
1461 if (next_inline_clone
->next_sibling_clone
)
1462 next_inline_clone
->next_sibling_clone
->prev_sibling_clone
1463 = next_inline_clone
->prev_sibling_clone
;
1464 if (next_inline_clone
->prev_sibling_clone
)
1466 gcc_assert (node
->clones
!= next_inline_clone
);
1467 next_inline_clone
->prev_sibling_clone
->next_sibling_clone
1468 = next_inline_clone
->next_sibling_clone
;
1472 gcc_assert (node
->clones
== next_inline_clone
);
1473 node
->clones
= next_inline_clone
->next_sibling_clone
;
1476 new_clones
= node
->clones
;
1477 node
->clones
= NULL
;
1479 /* Copy clone info. */
1480 next_inline_clone
->clone
= node
->clone
;
1482 /* Now place it into clone tree at same level at NODE. */
1483 next_inline_clone
->clone_of
= node
->clone_of
;
1484 next_inline_clone
->prev_sibling_clone
= NULL
;
1485 next_inline_clone
->next_sibling_clone
= NULL
;
1488 if (node
->clone_of
->clones
)
1489 node
->clone_of
->clones
->prev_sibling_clone
= next_inline_clone
;
1490 next_inline_clone
->next_sibling_clone
= node
->clone_of
->clones
;
1491 node
->clone_of
->clones
= next_inline_clone
;
1494 /* Merge the clone list. */
1497 if (!next_inline_clone
->clones
)
1498 next_inline_clone
->clones
= new_clones
;
1501 n
= next_inline_clone
->clones
;
1502 while (n
->next_sibling_clone
)
1503 n
= n
->next_sibling_clone
;
1504 n
->next_sibling_clone
= new_clones
;
1505 new_clones
->prev_sibling_clone
= n
;
1509 /* Update clone_of pointers. */
1513 n
->clone_of
= next_inline_clone
;
1514 n
= n
->next_sibling_clone
;
1519 htab_clear_slot (cgraph_hash
, slot
);
1524 if (node
->prev_sibling_clone
)
1525 node
->prev_sibling_clone
->next_sibling_clone
= node
->next_sibling_clone
;
1526 else if (node
->clone_of
)
1527 node
->clone_of
->clones
= node
->next_sibling_clone
;
1528 if (node
->next_sibling_clone
)
1529 node
->next_sibling_clone
->prev_sibling_clone
= node
->prev_sibling_clone
;
1532 struct cgraph_node
*n
, *next
;
1536 for (n
= node
->clones
; n
->next_sibling_clone
; n
= n
->next_sibling_clone
)
1537 n
->clone_of
= node
->clone_of
;
1538 n
->clone_of
= node
->clone_of
;
1539 n
->next_sibling_clone
= node
->clone_of
->clones
;
1540 if (node
->clone_of
->clones
)
1541 node
->clone_of
->clones
->prev_sibling_clone
= n
;
1542 node
->clone_of
->clones
= node
->clones
;
1546 /* We are removing node with clones. this makes clones inconsistent,
1547 but assume they will be removed subsequently and just keep clone
1548 tree intact. This can happen in unreachable function removal since
1549 we remove unreachable functions in random order, not by bottom-up
1550 walk of clone trees. */
1551 for (n
= node
->clones
; n
; n
= next
)
1553 next
= n
->next_sibling_clone
;
1554 n
->next_sibling_clone
= NULL
;
1555 n
->prev_sibling_clone
= NULL
;
1561 if (node
->same_comdat_group
)
1563 struct cgraph_node
*prev
;
1564 for (prev
= node
->same_comdat_group
;
1565 prev
->same_comdat_group
!= node
;
1566 prev
= prev
->same_comdat_group
)
1568 if (node
->same_comdat_group
== prev
)
1569 prev
->same_comdat_group
= NULL
;
1571 prev
->same_comdat_group
= node
->same_comdat_group
;
1572 node
->same_comdat_group
= NULL
;
1575 /* While all the clones are removed after being proceeded, the function
1576 itself is kept in the cgraph even after it is compiled. Check whether
1577 we are done with this body and reclaim it proactively if this is the case.
1579 if (!kill_body
&& *slot
)
1581 struct cgraph_node
*n
= (struct cgraph_node
*) *slot
;
1582 if (!n
->clones
&& !n
->clone_of
&& !n
->global
.inlined_to
1583 && (cgraph_global_info_ready
1584 && (TREE_ASM_WRITTEN (n
->decl
) || DECL_EXTERNAL (n
->decl
)
1585 || n
->in_other_partition
)))
1588 if (assembler_name_hash
)
1590 tree name
= DECL_ASSEMBLER_NAME (node
->decl
);
1591 slot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
1592 decl_assembler_name_hash (name
),
1594 /* Inline clones are not hashed. */
1595 if (slot
&& *slot
== node
)
1596 htab_clear_slot (assembler_name_hash
, slot
);
1600 cgraph_release_function_body (node
);
1602 if (node
->call_site_hash
)
1604 htab_delete (node
->call_site_hash
);
1605 node
->call_site_hash
= NULL
;
1609 /* Clear out the node to NULL all pointers and add the node to the free
1611 memset (node
, 0, sizeof(*node
));
1613 NEXT_FREE_NODE (node
) = free_nodes
;
1617 /* Add NEW_ to the same comdat group that OLD is in. */
1620 cgraph_add_to_same_comdat_group (struct cgraph_node
*new_
,
1621 struct cgraph_node
*old
)
1623 gcc_assert (DECL_ONE_ONLY (old
->decl
));
1624 gcc_assert (!new_
->same_comdat_group
);
1625 gcc_assert (new_
!= old
);
1627 DECL_COMDAT_GROUP (new_
->decl
) = DECL_COMDAT_GROUP (old
->decl
);
1628 new_
->same_comdat_group
= old
;
1629 if (!old
->same_comdat_group
)
1630 old
->same_comdat_group
= new_
;
1633 struct cgraph_node
*n
;
1634 for (n
= old
->same_comdat_group
;
1635 n
->same_comdat_group
!= old
;
1636 n
= n
->same_comdat_group
)
1638 n
->same_comdat_group
= new_
;
1642 /* Remove the node from cgraph. */
1645 cgraph_remove_node_and_inline_clones (struct cgraph_node
*node
)
1647 struct cgraph_edge
*e
, *next
;
1648 for (e
= node
->callees
; e
; e
= next
)
1650 next
= e
->next_callee
;
1651 if (!e
->inline_failed
)
1652 cgraph_remove_node_and_inline_clones (e
->callee
);
1654 cgraph_remove_node (node
);
1657 /* Notify finalize_compilation_unit that given node is reachable. */
1660 cgraph_mark_reachable_node (struct cgraph_node
*node
)
1662 if (!node
->reachable
&& node
->local
.finalized
)
1664 if (cgraph_global_info_ready
)
1666 /* Verify that function does not appear to be needed out of blue
1667 during the optimization process. This can happen for extern
1668 inlines when bodies was removed after inlining. */
1669 gcc_assert ((node
->analyzed
|| node
->in_other_partition
1670 || DECL_EXTERNAL (node
->decl
)));
1673 notice_global_symbol (node
->decl
);
1674 node
->reachable
= 1;
1676 node
->next_needed
= cgraph_nodes_queue
;
1677 cgraph_nodes_queue
= node
;
1681 /* Likewise indicate that a node is needed, i.e. reachable via some
1685 cgraph_mark_needed_node (struct cgraph_node
*node
)
1688 gcc_assert (!node
->global
.inlined_to
);
1689 cgraph_mark_reachable_node (node
);
1692 /* Likewise indicate that a node is having address taken. */
1695 cgraph_mark_address_taken_node (struct cgraph_node
*node
)
1697 gcc_assert (!node
->global
.inlined_to
);
1698 cgraph_mark_reachable_node (node
);
1699 /* FIXME: address_taken flag is used both as a shortcut for testing whether
1700 IPA_REF_ADDR reference exists (and thus it should be set on node
1701 representing alias we take address of) and as a test whether address
1702 of the object was taken (and thus it should be set on node alias is
1703 referring to). We should remove the first use and the remove the
1705 node
->address_taken
= 1;
1706 node
= cgraph_function_or_thunk_node (node
, NULL
);
1707 node
->address_taken
= 1;
1710 /* Return local info for the compiled function. */
1712 struct cgraph_local_info
*
1713 cgraph_local_info (tree decl
)
1715 struct cgraph_node
*node
;
1717 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1718 node
= cgraph_get_node (decl
);
1721 return &node
->local
;
1724 /* Return local info for the compiled function. */
1726 struct cgraph_global_info
*
1727 cgraph_global_info (tree decl
)
1729 struct cgraph_node
*node
;
1731 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
&& cgraph_global_info_ready
);
1732 node
= cgraph_get_node (decl
);
1735 return &node
->global
;
1738 /* Return local info for the compiled function. */
1740 struct cgraph_rtl_info
*
1741 cgraph_rtl_info (tree decl
)
1743 struct cgraph_node
*node
;
1745 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1746 node
= cgraph_get_node (decl
);
1748 || (decl
!= current_function_decl
1749 && !TREE_ASM_WRITTEN (node
->decl
)))
1754 /* Return a string describing the failure REASON. */
1757 cgraph_inline_failed_string (cgraph_inline_failed_t reason
)
1760 #define DEFCIFCODE(code, string) string,
1762 static const char *cif_string_table
[CIF_N_REASONS
] = {
1763 #include "cif-code.def"
1766 /* Signedness of an enum type is implementation defined, so cast it
1767 to unsigned before testing. */
1768 gcc_assert ((unsigned) reason
< CIF_N_REASONS
);
1769 return cif_string_table
[reason
];
1772 /* Return name of the node used in debug output. */
1774 cgraph_node_name (struct cgraph_node
*node
)
1776 return lang_hooks
.decl_printable_name (node
->decl
, 2);
1779 /* Names used to print out the availability enum. */
1780 const char * const cgraph_availability_names
[] =
1781 {"unset", "not_available", "overwritable", "available", "local"};
1784 /* Dump call graph node NODE to file F. */
1787 dump_cgraph_node (FILE *f
, struct cgraph_node
*node
)
1789 struct cgraph_edge
*edge
;
1790 int indirect_calls_count
= 0;
1792 fprintf (f
, "%s/%i", cgraph_node_name (node
), node
->uid
);
1793 dump_addr (f
, " @", (void *)node
);
1794 if (DECL_ASSEMBLER_NAME_SET_P (node
->decl
))
1795 fprintf (f
, " (asm: %s)", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->decl
)));
1796 if (node
->global
.inlined_to
)
1797 fprintf (f
, " (inline copy in %s/%i)",
1798 cgraph_node_name (node
->global
.inlined_to
),
1799 node
->global
.inlined_to
->uid
);
1800 if (node
->same_comdat_group
)
1801 fprintf (f
, " (same comdat group as %s/%i)",
1802 cgraph_node_name (node
->same_comdat_group
),
1803 node
->same_comdat_group
->uid
);
1805 fprintf (f
, " (clone of %s/%i)",
1806 cgraph_node_name (node
->clone_of
),
1807 node
->clone_of
->uid
);
1808 if (cgraph_function_flags_ready
)
1809 fprintf (f
, " availability:%s",
1810 cgraph_availability_names
[cgraph_function_body_availability (node
)]);
1812 fprintf (f
, " analyzed");
1813 if (node
->in_other_partition
)
1814 fprintf (f
, " in_other_partition");
1816 fprintf (f
, " executed "HOST_WIDEST_INT_PRINT_DEC
"x",
1817 (HOST_WIDEST_INT
)node
->count
);
1819 fprintf (f
, " nested in: %s", cgraph_node_name (node
->origin
));
1821 fprintf (f
, " needed");
1822 if (node
->address_taken
)
1823 fprintf (f
, " address_taken");
1824 else if (node
->reachable
)
1825 fprintf (f
, " reachable");
1826 else if (node
->reachable_from_other_partition
)
1827 fprintf (f
, " reachable_from_other_partition");
1828 if (gimple_has_body_p (node
->decl
))
1829 fprintf (f
, " body");
1831 fprintf (f
, " process");
1832 if (node
->local
.local
)
1833 fprintf (f
, " local");
1834 if (node
->local
.externally_visible
)
1835 fprintf (f
, " externally_visible");
1836 if (node
->resolution
!= LDPR_UNKNOWN
)
1838 ld_plugin_symbol_resolution_names
[(int)node
->resolution
]);
1839 if (node
->local
.finalized
)
1840 fprintf (f
, " finalized");
1841 if (node
->local
.redefined_extern_inline
)
1842 fprintf (f
, " redefined_extern_inline");
1843 if (TREE_ASM_WRITTEN (node
->decl
))
1844 fprintf (f
, " asm_written");
1845 if (node
->only_called_at_startup
)
1846 fprintf (f
, " only_called_at_startup");
1847 if (node
->only_called_at_exit
)
1848 fprintf (f
, " only_called_at_exit");
1849 else if (node
->alias
)
1850 fprintf (f
, " alias");
1852 fprintf (f
, " tm_clone");
1856 if (node
->thunk
.thunk_p
)
1858 fprintf (f
, " thunk of %s (asm: %s) fixed offset %i virtual value %i has "
1859 "virtual offset %i)\n",
1860 lang_hooks
.decl_printable_name (node
->thunk
.alias
, 2),
1861 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->thunk
.alias
)),
1862 (int)node
->thunk
.fixed_offset
,
1863 (int)node
->thunk
.virtual_value
,
1864 (int)node
->thunk
.virtual_offset_p
);
1866 if (node
->alias
&& node
->thunk
.alias
)
1868 fprintf (f
, " alias of %s",
1869 lang_hooks
.decl_printable_name (node
->thunk
.alias
, 2));
1870 if (DECL_ASSEMBLER_NAME_SET_P (node
->thunk
.alias
))
1871 fprintf (f
, " (asm: %s)",
1872 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->thunk
.alias
)));
1876 fprintf (f
, " called by: ");
1878 for (edge
= node
->callers
; edge
; edge
= edge
->next_caller
)
1880 fprintf (f
, "%s/%i ", cgraph_node_name (edge
->caller
),
1883 fprintf (f
, "("HOST_WIDEST_INT_PRINT_DEC
"x) ",
1884 (HOST_WIDEST_INT
)edge
->count
);
1885 if (edge
->frequency
)
1886 fprintf (f
, "(%.2f per call) ",
1887 edge
->frequency
/ (double)CGRAPH_FREQ_BASE
);
1888 if (!edge
->inline_failed
)
1889 fprintf(f
, "(inlined) ");
1890 if (edge
->indirect_inlining_edge
)
1891 fprintf(f
, "(indirect_inlining) ");
1892 if (edge
->can_throw_external
)
1893 fprintf(f
, "(can throw external) ");
1896 fprintf (f
, "\n calls: ");
1897 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1899 fprintf (f
, "%s/%i ", cgraph_node_name (edge
->callee
),
1901 if (!edge
->inline_failed
)
1902 fprintf(f
, "(inlined) ");
1903 if (edge
->indirect_inlining_edge
)
1904 fprintf(f
, "(indirect_inlining) ");
1906 fprintf (f
, "("HOST_WIDEST_INT_PRINT_DEC
"x) ",
1907 (HOST_WIDEST_INT
)edge
->count
);
1908 if (edge
->frequency
)
1909 fprintf (f
, "(%.2f per call) ",
1910 edge
->frequency
/ (double)CGRAPH_FREQ_BASE
);
1911 if (edge
->can_throw_external
)
1912 fprintf(f
, "(can throw external) ");
1915 fprintf (f
, " References: ");
1916 ipa_dump_references (f
, &node
->ref_list
);
1917 fprintf (f
, " Refering this function: ");
1918 ipa_dump_refering (f
, &node
->ref_list
);
1920 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
1921 indirect_calls_count
++;
1922 if (indirect_calls_count
)
1923 fprintf (f
, " has %i outgoing edges for indirect calls.\n",
1924 indirect_calls_count
);
1928 /* Dump call graph node NODE to stderr. */
1931 debug_cgraph_node (struct cgraph_node
*node
)
1933 dump_cgraph_node (stderr
, node
);
1937 /* Dump the callgraph to file F. */
1940 dump_cgraph (FILE *f
)
1942 struct cgraph_node
*node
;
1944 fprintf (f
, "callgraph:\n\n");
1945 for (node
= cgraph_nodes
; node
; node
= node
->next
)
1946 dump_cgraph_node (f
, node
);
1950 /* Dump the call graph to stderr. */
1955 dump_cgraph (stderr
);
1959 /* Set the DECL_ASSEMBLER_NAME and update cgraph hashtables. */
1962 change_decl_assembler_name (tree decl
, tree name
)
1964 struct cgraph_node
*node
;
1966 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
1967 SET_DECL_ASSEMBLER_NAME (decl
, name
);
1970 if (name
== DECL_ASSEMBLER_NAME (decl
))
1973 if (assembler_name_hash
1974 && TREE_CODE (decl
) == FUNCTION_DECL
1975 && (node
= cgraph_get_node (decl
)) != NULL
)
1977 tree old_name
= DECL_ASSEMBLER_NAME (decl
);
1978 slot
= htab_find_slot_with_hash (assembler_name_hash
, old_name
,
1979 decl_assembler_name_hash (old_name
),
1981 /* Inline clones are not hashed. */
1982 if (slot
&& *slot
== node
)
1983 htab_clear_slot (assembler_name_hash
, slot
);
1985 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
1986 && DECL_RTL_SET_P (decl
))
1987 warning (0, "%D renamed after being referenced in assembly", decl
);
1989 SET_DECL_ASSEMBLER_NAME (decl
, name
);
1991 if (assembler_name_hash
1992 && TREE_CODE (decl
) == FUNCTION_DECL
1993 && (node
= cgraph_get_node (decl
)) != NULL
)
1995 slot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
1996 decl_assembler_name_hash (name
),
1998 gcc_assert (!*slot
);
2003 /* Add a top-level asm statement to the list. */
2005 struct cgraph_asm_node
*
2006 cgraph_add_asm_node (tree asm_str
)
2008 struct cgraph_asm_node
*node
;
2010 node
= ggc_alloc_cleared_cgraph_asm_node ();
2011 node
->asm_str
= asm_str
;
2012 node
->order
= cgraph_order
++;
2014 if (cgraph_asm_nodes
== NULL
)
2015 cgraph_asm_nodes
= node
;
2017 cgraph_asm_last_node
->next
= node
;
2018 cgraph_asm_last_node
= node
;
2022 /* Return true when the DECL can possibly be inlined. */
2024 cgraph_function_possibly_inlined_p (tree decl
)
2026 if (!cgraph_global_info_ready
)
2027 return !DECL_UNINLINABLE (decl
);
2028 return DECL_POSSIBLY_INLINED (decl
);
2031 /* Create clone of E in the node N represented by CALL_EXPR the callgraph. */
2032 struct cgraph_edge
*
2033 cgraph_clone_edge (struct cgraph_edge
*e
, struct cgraph_node
*n
,
2034 gimple call_stmt
, unsigned stmt_uid
, gcov_type count_scale
,
2035 int freq_scale
, bool update_original
)
2037 struct cgraph_edge
*new_edge
;
2038 gcov_type count
= e
->count
* count_scale
/ REG_BR_PROB_BASE
;
2041 /* We do not want to ignore loop nest after frequency drops to 0. */
2044 freq
= e
->frequency
* (gcov_type
) freq_scale
/ CGRAPH_FREQ_BASE
;
2045 if (freq
> CGRAPH_FREQ_MAX
)
2046 freq
= CGRAPH_FREQ_MAX
;
2048 if (e
->indirect_unknown_callee
)
2052 if (call_stmt
&& (decl
= gimple_call_fndecl (call_stmt
)))
2054 struct cgraph_node
*callee
= cgraph_get_node (decl
);
2055 gcc_checking_assert (callee
);
2056 new_edge
= cgraph_create_edge (n
, callee
, call_stmt
, count
, freq
);
2060 new_edge
= cgraph_create_indirect_edge (n
, call_stmt
,
2061 e
->indirect_info
->ecf_flags
,
2063 *new_edge
->indirect_info
= *e
->indirect_info
;
2068 new_edge
= cgraph_create_edge (n
, e
->callee
, call_stmt
, count
, freq
);
2069 if (e
->indirect_info
)
2071 new_edge
->indirect_info
2072 = ggc_alloc_cleared_cgraph_indirect_call_info ();
2073 *new_edge
->indirect_info
= *e
->indirect_info
;
2077 new_edge
->inline_failed
= e
->inline_failed
;
2078 new_edge
->indirect_inlining_edge
= e
->indirect_inlining_edge
;
2079 new_edge
->lto_stmt_uid
= stmt_uid
;
2080 /* Clone flags that depend on call_stmt availability manually. */
2081 new_edge
->can_throw_external
= e
->can_throw_external
;
2082 new_edge
->call_stmt_cannot_inline_p
= e
->call_stmt_cannot_inline_p
;
2083 if (update_original
)
2085 e
->count
-= new_edge
->count
;
2089 cgraph_call_edge_duplication_hooks (e
, new_edge
);
2094 /* Create node representing clone of N executed COUNT times. Decrease
2095 the execution counts from original node too.
2096 The new clone will have decl set to DECL that may or may not be the same
2099 When UPDATE_ORIGINAL is true, the counts are subtracted from the original
2100 function's profile to reflect the fact that part of execution is handled
2102 When CALL_DUPLICATOIN_HOOK is true, the ipa passes are acknowledged about
2103 the new clone. Otherwise the caller is responsible for doing so later. */
2105 struct cgraph_node
*
2106 cgraph_clone_node (struct cgraph_node
*n
, tree decl
, gcov_type count
, int freq
,
2107 bool update_original
,
2108 VEC(cgraph_edge_p
,heap
) *redirect_callers
,
2109 bool call_duplication_hook
)
2111 struct cgraph_node
*new_node
= cgraph_create_node_1 ();
2112 struct cgraph_edge
*e
;
2113 gcov_type count_scale
;
2116 new_node
->decl
= decl
;
2117 new_node
->origin
= n
->origin
;
2118 if (new_node
->origin
)
2120 new_node
->next_nested
= new_node
->origin
->nested
;
2121 new_node
->origin
->nested
= new_node
;
2123 new_node
->analyzed
= n
->analyzed
;
2124 new_node
->local
= n
->local
;
2125 new_node
->local
.externally_visible
= false;
2126 new_node
->local
.local
= true;
2127 new_node
->global
= n
->global
;
2128 new_node
->rtl
= n
->rtl
;
2129 new_node
->count
= count
;
2130 new_node
->frequency
= n
->frequency
;
2131 new_node
->clone
= n
->clone
;
2132 new_node
->clone
.tree_map
= 0;
2135 if (new_node
->count
> n
->count
)
2136 count_scale
= REG_BR_PROB_BASE
;
2138 count_scale
= new_node
->count
* REG_BR_PROB_BASE
/ n
->count
;
2142 if (update_original
)
2149 FOR_EACH_VEC_ELT (cgraph_edge_p
, redirect_callers
, i
, e
)
2151 /* Redirect calls to the old version node to point to its new
2153 cgraph_redirect_edge_callee (e
, new_node
);
2157 for (e
= n
->callees
;e
; e
=e
->next_callee
)
2158 cgraph_clone_edge (e
, new_node
, e
->call_stmt
, e
->lto_stmt_uid
,
2159 count_scale
, freq
, update_original
);
2161 for (e
= n
->indirect_calls
; e
; e
= e
->next_callee
)
2162 cgraph_clone_edge (e
, new_node
, e
->call_stmt
, e
->lto_stmt_uid
,
2163 count_scale
, freq
, update_original
);
2164 ipa_clone_references (new_node
, NULL
, &n
->ref_list
);
2166 new_node
->next_sibling_clone
= n
->clones
;
2168 n
->clones
->prev_sibling_clone
= new_node
;
2169 n
->clones
= new_node
;
2170 new_node
->clone_of
= n
;
2172 if (n
->decl
!= decl
)
2174 struct cgraph_node
**slot
;
2175 slot
= (struct cgraph_node
**) htab_find_slot (cgraph_hash
, new_node
, INSERT
);
2176 gcc_assert (!*slot
);
2178 if (assembler_name_hash
)
2181 tree name
= DECL_ASSEMBLER_NAME (decl
);
2183 aslot
= htab_find_slot_with_hash (assembler_name_hash
, name
,
2184 decl_assembler_name_hash (name
),
2186 gcc_assert (!*aslot
);
2191 if (call_duplication_hook
)
2192 cgraph_call_node_duplication_hooks (n
, new_node
);
2196 /* Create a new name for clone of DECL, add SUFFIX. Returns an identifier. */
2198 static GTY(()) unsigned int clone_fn_id_num
;
2201 clone_function_name (tree decl
, const char *suffix
)
2203 tree name
= DECL_ASSEMBLER_NAME (decl
);
2204 size_t len
= IDENTIFIER_LENGTH (name
);
2205 char *tmp_name
, *prefix
;
2207 prefix
= XALLOCAVEC (char, len
+ strlen (suffix
) + 2);
2208 memcpy (prefix
, IDENTIFIER_POINTER (name
), len
);
2209 strcpy (prefix
+ len
+ 1, suffix
);
2210 #ifndef NO_DOT_IN_LABEL
2212 #elif !defined NO_DOLLAR_IN_LABEL
2217 ASM_FORMAT_PRIVATE_NAME (tmp_name
, prefix
, clone_fn_id_num
++);
2218 return get_identifier (tmp_name
);
2221 /* Create callgraph node clone with new declaration. The actual body will
2222 be copied later at compilation stage.
2224 TODO: after merging in ipa-sra use function call notes instead of args_to_skip
2227 struct cgraph_node
*
2228 cgraph_create_virtual_clone (struct cgraph_node
*old_node
,
2229 VEC(cgraph_edge_p
,heap
) *redirect_callers
,
2230 VEC(ipa_replace_map_p
,gc
) *tree_map
,
2231 bitmap args_to_skip
,
2232 const char * suffix
)
2234 tree old_decl
= old_node
->decl
;
2235 struct cgraph_node
*new_node
= NULL
;
2238 struct ipa_replace_map
*map
;
2241 gcc_checking_assert (tree_versionable_function_p (old_decl
));
2243 gcc_assert (old_node
->local
.can_change_signature
|| !args_to_skip
);
2245 /* Make a new FUNCTION_DECL tree node */
2247 new_decl
= copy_node (old_decl
);
2249 new_decl
= build_function_decl_skip_args (old_decl
, args_to_skip
);
2250 DECL_STRUCT_FUNCTION (new_decl
) = NULL
;
2252 /* Generate a new name for the new version. */
2253 DECL_NAME (new_decl
) = clone_function_name (old_decl
, suffix
);
2254 SET_DECL_ASSEMBLER_NAME (new_decl
, DECL_NAME (new_decl
));
2255 SET_DECL_RTL (new_decl
, NULL
);
2257 new_node
= cgraph_clone_node (old_node
, new_decl
, old_node
->count
,
2258 CGRAPH_FREQ_BASE
, false,
2259 redirect_callers
, false);
2260 /* Update the properties.
2261 Make clone visible only within this translation unit. Make sure
2262 that is not weak also.
2263 ??? We cannot use COMDAT linkage because there is no
2264 ABI support for this. */
2265 DECL_EXTERNAL (new_node
->decl
) = 0;
2266 if (DECL_ONE_ONLY (old_decl
))
2267 DECL_SECTION_NAME (new_node
->decl
) = NULL
;
2268 DECL_COMDAT_GROUP (new_node
->decl
) = 0;
2269 TREE_PUBLIC (new_node
->decl
) = 0;
2270 DECL_COMDAT (new_node
->decl
) = 0;
2271 DECL_WEAK (new_node
->decl
) = 0;
2272 DECL_STATIC_CONSTRUCTOR (new_node
->decl
) = 0;
2273 DECL_STATIC_DESTRUCTOR (new_node
->decl
) = 0;
2274 new_node
->clone
.tree_map
= tree_map
;
2275 new_node
->clone
.args_to_skip
= args_to_skip
;
2276 FOR_EACH_VEC_ELT (ipa_replace_map_p
, tree_map
, i
, map
)
2278 tree var
= map
->new_tree
;
2281 if (TREE_CODE (var
) != ADDR_EXPR
)
2283 var
= get_base_var (var
);
2287 /* Record references of the future statement initializing the constant
2289 if (TREE_CODE (var
) == FUNCTION_DECL
)
2291 struct cgraph_node
*ref_node
= cgraph_get_node (var
);
2292 gcc_checking_assert (ref_node
);
2293 ipa_record_reference (new_node
, NULL
, ref_node
, NULL
, IPA_REF_ADDR
,
2296 else if (TREE_CODE (var
) == VAR_DECL
)
2297 ipa_record_reference (new_node
, NULL
, NULL
, varpool_node (var
),
2298 IPA_REF_ADDR
, NULL
);
2301 new_node
->clone
.combined_args_to_skip
= old_node
->clone
.combined_args_to_skip
;
2302 else if (old_node
->clone
.combined_args_to_skip
)
2304 int newi
= 0, oldi
= 0;
2306 bitmap new_args_to_skip
= BITMAP_GGC_ALLOC ();
2307 struct cgraph_node
*orig_node
;
2308 for (orig_node
= old_node
; orig_node
->clone_of
; orig_node
= orig_node
->clone_of
)
2310 for (arg
= DECL_ARGUMENTS (orig_node
->decl
); arg
; arg
= DECL_CHAIN (arg
), oldi
++)
2312 if (bitmap_bit_p (old_node
->clone
.combined_args_to_skip
, oldi
))
2314 bitmap_set_bit (new_args_to_skip
, oldi
);
2317 if (bitmap_bit_p (args_to_skip
, newi
))
2318 bitmap_set_bit (new_args_to_skip
, oldi
);
2321 new_node
->clone
.combined_args_to_skip
= new_args_to_skip
;
2324 new_node
->clone
.combined_args_to_skip
= args_to_skip
;
2325 new_node
->local
.externally_visible
= 0;
2326 new_node
->local
.local
= 1;
2327 new_node
->lowered
= true;
2328 new_node
->reachable
= true;
2330 cgraph_call_node_duplication_hooks (old_node
, new_node
);
2336 /* NODE is no longer nested function; update cgraph accordingly. */
2338 cgraph_unnest_node (struct cgraph_node
*node
)
2340 struct cgraph_node
**node2
= &node
->origin
->nested
;
2341 gcc_assert (node
->origin
);
2343 while (*node2
!= node
)
2344 node2
= &(*node2
)->next_nested
;
2345 *node2
= node
->next_nested
;
2346 node
->origin
= NULL
;
2349 /* Return function availability. See cgraph.h for description of individual
2352 cgraph_function_body_availability (struct cgraph_node
*node
)
2354 enum availability avail
;
2355 gcc_assert (cgraph_function_flags_ready
);
2356 if (!node
->analyzed
)
2357 avail
= AVAIL_NOT_AVAILABLE
;
2358 else if (node
->local
.local
)
2359 avail
= AVAIL_LOCAL
;
2360 else if (!node
->local
.externally_visible
)
2361 avail
= AVAIL_AVAILABLE
;
2362 /* Inline functions are safe to be analyzed even if their symbol can
2363 be overwritten at runtime. It is not meaningful to enforce any sane
2364 behaviour on replacing inline function by different body. */
2365 else if (DECL_DECLARED_INLINE_P (node
->decl
))
2366 avail
= AVAIL_AVAILABLE
;
2368 /* If the function can be overwritten, return OVERWRITABLE. Take
2369 care at least of two notable extensions - the COMDAT functions
2370 used to share template instantiations in C++ (this is symmetric
2371 to code cp_cannot_inline_tree_fn and probably shall be shared and
2372 the inlinability hooks completely eliminated).
2374 ??? Does the C++ one definition rule allow us to always return
2375 AVAIL_AVAILABLE here? That would be good reason to preserve this
2378 else if (decl_replaceable_p (node
->decl
) && !DECL_EXTERNAL (node
->decl
))
2379 avail
= AVAIL_OVERWRITABLE
;
2380 else avail
= AVAIL_AVAILABLE
;
2385 /* Add the function FNDECL to the call graph.
2386 Unlike cgraph_finalize_function, this function is intended to be used
2387 by middle end and allows insertion of new function at arbitrary point
2388 of compilation. The function can be either in high, low or SSA form
2391 The function is assumed to be reachable and have address taken (so no
2392 API breaking optimizations are performed on it).
2394 Main work done by this function is to enqueue the function for later
2395 processing to avoid need the passes to be re-entrant. */
2398 cgraph_add_new_function (tree fndecl
, bool lowered
)
2400 struct cgraph_node
*node
;
2401 switch (cgraph_state
)
2403 case CGRAPH_STATE_CONSTRUCTION
:
2404 /* Just enqueue function to be processed at nearest occurrence. */
2405 node
= cgraph_create_node (fndecl
);
2406 node
->next_needed
= cgraph_new_nodes
;
2408 node
->lowered
= true;
2409 cgraph_new_nodes
= node
;
2412 case CGRAPH_STATE_IPA
:
2413 case CGRAPH_STATE_IPA_SSA
:
2414 case CGRAPH_STATE_EXPANSION
:
2415 /* Bring the function into finalized state and enqueue for later
2416 analyzing and compilation. */
2417 node
= cgraph_get_create_node (fndecl
);
2418 node
->local
.local
= false;
2419 node
->local
.finalized
= true;
2420 node
->reachable
= node
->needed
= true;
2421 if (!lowered
&& cgraph_state
== CGRAPH_STATE_EXPANSION
)
2423 push_cfun (DECL_STRUCT_FUNCTION (fndecl
));
2424 current_function_decl
= fndecl
;
2425 gimple_register_cfg_hooks ();
2426 tree_lowering_passes (fndecl
);
2427 bitmap_obstack_initialize (NULL
);
2428 if (!gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl
)))
2429 execute_pass_list (pass_early_local_passes
.pass
.sub
);
2430 bitmap_obstack_release (NULL
);
2432 current_function_decl
= NULL
;
2437 node
->lowered
= true;
2438 node
->next_needed
= cgraph_new_nodes
;
2439 cgraph_new_nodes
= node
;
2442 case CGRAPH_STATE_FINISHED
:
2443 /* At the very end of compilation we have to do all the work up
2445 node
= cgraph_create_node (fndecl
);
2447 node
->lowered
= true;
2448 cgraph_analyze_function (node
);
2449 push_cfun (DECL_STRUCT_FUNCTION (fndecl
));
2450 current_function_decl
= fndecl
;
2451 gimple_register_cfg_hooks ();
2452 bitmap_obstack_initialize (NULL
);
2453 if (!gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl
)))
2454 execute_pass_list (pass_early_local_passes
.pass
.sub
);
2455 bitmap_obstack_release (NULL
);
2456 tree_rest_of_compilation (fndecl
);
2458 current_function_decl
= NULL
;
2462 /* Set a personality if required and we already passed EH lowering. */
2464 && (function_needs_eh_personality (DECL_STRUCT_FUNCTION (fndecl
))
2465 == eh_personality_lang
))
2466 DECL_FUNCTION_PERSONALITY (fndecl
) = lang_hooks
.eh_personality ();
2469 /* Worker for cgraph_node_can_be_local_p. */
2471 cgraph_node_cannot_be_local_p_1 (struct cgraph_node
*node
,
2472 void *data ATTRIBUTE_UNUSED
)
2474 return !(!node
->needed
2475 && ((DECL_COMDAT (node
->decl
) && !node
->same_comdat_group
)
2476 || !node
->local
.externally_visible
));
2479 /* Return true if NODE can be made local for API change.
2480 Extern inline functions and C++ COMDAT functions can be made local
2481 at the expense of possible code size growth if function is used in multiple
2482 compilation units. */
2484 cgraph_node_can_be_local_p (struct cgraph_node
*node
)
2486 return (!node
->address_taken
2487 && !cgraph_for_node_and_aliases (node
,
2488 cgraph_node_cannot_be_local_p_1
,
2492 /* Make DECL local. FIXME: We shouldn't need to mess with rtl this early,
2493 but other code such as notice_global_symbol generates rtl. */
2495 cgraph_make_decl_local (tree decl
)
2499 if (TREE_CODE (decl
) == VAR_DECL
)
2500 DECL_COMMON (decl
) = 0;
2501 else gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
2503 if (DECL_ONE_ONLY (decl
) || DECL_COMDAT (decl
))
2505 /* It is possible that we are linking against library defining same COMDAT
2506 function. To avoid conflict we need to rename our local name of the
2507 function just in the case WHOPR partitioning decide to make it hidden
2508 to avoid cross partition references. */
2511 const char *old_name
;
2513 old_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2514 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2516 struct cgraph_node
*node
= cgraph_get_node (decl
);
2517 change_decl_assembler_name (decl
,
2518 clone_function_name (decl
, "local"));
2519 if (node
->local
.lto_file_data
)
2520 lto_record_renamed_decl (node
->local
.lto_file_data
,
2523 (DECL_ASSEMBLER_NAME (decl
)));
2525 else if (TREE_CODE (decl
) == VAR_DECL
)
2527 struct varpool_node
*vnode
= varpool_get_node (decl
);
2528 /* change_decl_assembler_name will warn here on vtables because
2529 C++ frontend still sets TREE_SYMBOL_REFERENCED on them. */
2530 SET_DECL_ASSEMBLER_NAME (decl
,
2531 clone_function_name (decl
, "local"));
2532 if (vnode
->lto_file_data
)
2533 lto_record_renamed_decl (vnode
->lto_file_data
,
2536 (DECL_ASSEMBLER_NAME (decl
)));
2539 DECL_SECTION_NAME (decl
) = 0;
2540 DECL_COMDAT (decl
) = 0;
2542 DECL_COMDAT_GROUP (decl
) = 0;
2543 DECL_WEAK (decl
) = 0;
2544 DECL_EXTERNAL (decl
) = 0;
2545 TREE_PUBLIC (decl
) = 0;
2546 if (!DECL_RTL_SET_P (decl
))
2549 /* Update rtl flags. */
2550 make_decl_rtl (decl
);
2552 rtl
= DECL_RTL (decl
);
2556 symbol
= XEXP (rtl
, 0);
2557 if (GET_CODE (symbol
) != SYMBOL_REF
)
2560 SYMBOL_REF_WEAK (symbol
) = DECL_WEAK (decl
);
2563 /* Call calback on NODE, thunks and aliases asociated to NODE.
2564 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
2568 cgraph_for_node_thunks_and_aliases (struct cgraph_node
*node
,
2569 bool (*callback
) (struct cgraph_node
*, void *),
2571 bool include_overwritable
)
2573 struct cgraph_edge
*e
;
2575 struct ipa_ref
*ref
;
2577 if (callback (node
, data
))
2579 for (e
= node
->callers
; e
; e
= e
->next_caller
)
2580 if (e
->caller
->thunk
.thunk_p
2581 && (include_overwritable
2582 || cgraph_function_body_availability (e
->caller
) > AVAIL_OVERWRITABLE
))
2583 if (cgraph_for_node_thunks_and_aliases (e
->caller
, callback
, data
,
2584 include_overwritable
))
2586 for (i
= 0; ipa_ref_list_refering_iterate (&node
->ref_list
, i
, ref
); i
++)
2587 if (ref
->use
== IPA_REF_ALIAS
)
2589 struct cgraph_node
*alias
= ipa_ref_refering_node (ref
);
2590 if (include_overwritable
2591 || cgraph_function_body_availability (alias
) > AVAIL_OVERWRITABLE
)
2592 if (cgraph_for_node_thunks_and_aliases (alias
, callback
, data
,
2593 include_overwritable
))
2599 /* Call calback on NODE and aliases asociated to NODE.
2600 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
2604 cgraph_for_node_and_aliases (struct cgraph_node
*node
,
2605 bool (*callback
) (struct cgraph_node
*, void *),
2607 bool include_overwritable
)
2610 struct ipa_ref
*ref
;
2612 if (callback (node
, data
))
2614 for (i
= 0; ipa_ref_list_refering_iterate (&node
->ref_list
, i
, ref
); i
++)
2615 if (ref
->use
== IPA_REF_ALIAS
)
2617 struct cgraph_node
*alias
= ipa_ref_refering_node (ref
);
2618 if (include_overwritable
2619 || cgraph_function_body_availability (alias
) > AVAIL_OVERWRITABLE
)
2620 if (cgraph_for_node_and_aliases (alias
, callback
, data
,
2621 include_overwritable
))
2627 /* Worker to bring NODE local. */
2630 cgraph_make_node_local_1 (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
2632 gcc_checking_assert (cgraph_node_can_be_local_p (node
));
2633 if (DECL_COMDAT (node
->decl
) || DECL_EXTERNAL (node
->decl
))
2635 cgraph_make_decl_local (node
->decl
);
2637 node
->local
.externally_visible
= false;
2638 node
->local
.local
= true;
2639 node
->resolution
= LDPR_PREVAILING_DEF_IRONLY
;
2640 gcc_assert (cgraph_function_body_availability (node
) == AVAIL_LOCAL
);
2645 /* Bring NODE local. */
2648 cgraph_make_node_local (struct cgraph_node
*node
)
2650 cgraph_for_node_thunks_and_aliases (node
, cgraph_make_node_local_1
,
2654 /* Worker to set nothrow flag. */
2657 cgraph_set_nothrow_flag_1 (struct cgraph_node
*node
, void *data
)
2659 struct cgraph_edge
*e
;
2661 TREE_NOTHROW (node
->decl
) = data
!= NULL
;
2664 for (e
= node
->callers
; e
; e
= e
->next_caller
)
2665 e
->can_throw_external
= false;
2669 /* Set TREE_NOTHROW on NODE's decl and on aliases of NODE
2670 if any to NOTHROW. */
2673 cgraph_set_nothrow_flag (struct cgraph_node
*node
, bool nothrow
)
2675 cgraph_for_node_thunks_and_aliases (node
, cgraph_set_nothrow_flag_1
,
2676 (void *)(size_t)nothrow
, false);
2679 /* Worker to set const flag. */
2682 cgraph_set_const_flag_1 (struct cgraph_node
*node
, void *data
)
2684 /* Static constructors and destructors without a side effect can be
2686 if (data
&& !((size_t)data
& 2))
2688 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
2689 DECL_STATIC_CONSTRUCTOR (node
->decl
) = 0;
2690 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
2691 DECL_STATIC_DESTRUCTOR (node
->decl
) = 0;
2693 TREE_READONLY (node
->decl
) = data
!= NULL
;
2694 DECL_LOOPING_CONST_OR_PURE_P (node
->decl
) = ((size_t)data
& 2) != 0;
2698 /* Set TREE_READONLY on NODE's decl and on aliases of NODE
2699 if any to READONLY. */
2702 cgraph_set_const_flag (struct cgraph_node
*node
, bool readonly
, bool looping
)
2704 cgraph_for_node_thunks_and_aliases (node
, cgraph_set_const_flag_1
,
2705 (void *)(size_t)(readonly
+ (int)looping
* 2),
2709 /* Worker to set pure flag. */
2712 cgraph_set_pure_flag_1 (struct cgraph_node
*node
, void *data
)
2714 /* Static pureructors and destructors without a side effect can be
2716 if (data
&& !((size_t)data
& 2))
2718 if (DECL_STATIC_CONSTRUCTOR (node
->decl
))
2719 DECL_STATIC_CONSTRUCTOR (node
->decl
) = 0;
2720 if (DECL_STATIC_DESTRUCTOR (node
->decl
))
2721 DECL_STATIC_DESTRUCTOR (node
->decl
) = 0;
2723 DECL_PURE_P (node
->decl
) = data
!= NULL
;
2724 DECL_LOOPING_CONST_OR_PURE_P (node
->decl
) = ((size_t)data
& 2) != 0;
2728 /* Set DECL_PURE_P on NODE's decl and on aliases of NODE
2732 cgraph_set_pure_flag (struct cgraph_node
*node
, bool pure
, bool looping
)
2734 cgraph_for_node_thunks_and_aliases (node
, cgraph_set_pure_flag_1
,
2735 (void *)(size_t)(pure
+ (int)looping
* 2),
2739 /* Data used by cgraph_propagate_frequency. */
2741 struct cgraph_propagate_frequency_data
2743 bool maybe_unlikely_executed
;
2744 bool maybe_executed_once
;
2745 bool only_called_at_startup
;
2746 bool only_called_at_exit
;
2749 /* Worker for cgraph_propagate_frequency_1. */
2752 cgraph_propagate_frequency_1 (struct cgraph_node
*node
, void *data
)
2754 struct cgraph_propagate_frequency_data
*d
;
2755 struct cgraph_edge
*edge
;
2757 d
= (struct cgraph_propagate_frequency_data
*)data
;
2758 for (edge
= node
->callers
;
2759 edge
&& (d
->maybe_unlikely_executed
|| d
->maybe_executed_once
2760 || d
->only_called_at_startup
|| d
->only_called_at_exit
);
2761 edge
= edge
->next_caller
)
2763 if (edge
->caller
!= node
)
2765 d
->only_called_at_startup
&= edge
->caller
->only_called_at_startup
;
2766 /* It makes sense to put main() together with the static constructors.
2767 It will be executed for sure, but rest of functions called from
2768 main are definitely not at startup only. */
2769 if (MAIN_NAME_P (DECL_NAME (edge
->caller
->decl
)))
2770 d
->only_called_at_startup
= 0;
2771 d
->only_called_at_exit
&= edge
->caller
->only_called_at_exit
;
2773 if (!edge
->frequency
)
2775 switch (edge
->caller
->frequency
)
2777 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
2779 case NODE_FREQUENCY_EXECUTED_ONCE
:
2780 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2781 fprintf (dump_file
, " Called by %s that is executed once\n",
2782 cgraph_node_name (edge
->caller
));
2783 d
->maybe_unlikely_executed
= false;
2784 if (inline_edge_summary (edge
)->loop_depth
)
2786 d
->maybe_executed_once
= false;
2787 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2788 fprintf (dump_file
, " Called in loop\n");
2791 case NODE_FREQUENCY_HOT
:
2792 case NODE_FREQUENCY_NORMAL
:
2793 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2794 fprintf (dump_file
, " Called by %s that is normal or hot\n",
2795 cgraph_node_name (edge
->caller
));
2796 d
->maybe_unlikely_executed
= false;
2797 d
->maybe_executed_once
= false;
2801 return edge
!= NULL
;
2804 /* See if the frequency of NODE can be updated based on frequencies of its
2807 cgraph_propagate_frequency (struct cgraph_node
*node
)
2809 struct cgraph_propagate_frequency_data d
= {true, true, true, true};
2810 bool changed
= false;
2812 if (!node
->local
.local
)
2814 gcc_assert (node
->analyzed
);
2815 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2816 fprintf (dump_file
, "Processing frequency %s\n", cgraph_node_name (node
));
2818 cgraph_for_node_and_aliases (node
, cgraph_propagate_frequency_1
, &d
, true);
2820 if ((d
.only_called_at_startup
&& !d
.only_called_at_exit
)
2821 && !node
->only_called_at_startup
)
2823 node
->only_called_at_startup
= true;
2825 fprintf (dump_file
, "Node %s promoted to only called at startup.\n",
2826 cgraph_node_name (node
));
2829 if ((d
.only_called_at_exit
&& !d
.only_called_at_startup
)
2830 && !node
->only_called_at_exit
)
2832 node
->only_called_at_exit
= true;
2834 fprintf (dump_file
, "Node %s promoted to only called at exit.\n",
2835 cgraph_node_name (node
));
2838 /* These come either from profile or user hints; never update them. */
2839 if (node
->frequency
== NODE_FREQUENCY_HOT
2840 || node
->frequency
== NODE_FREQUENCY_UNLIKELY_EXECUTED
)
2842 if (d
.maybe_unlikely_executed
)
2844 node
->frequency
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
2846 fprintf (dump_file
, "Node %s promoted to unlikely executed.\n",
2847 cgraph_node_name (node
));
2850 else if (d
.maybe_executed_once
&& node
->frequency
!= NODE_FREQUENCY_EXECUTED_ONCE
)
2852 node
->frequency
= NODE_FREQUENCY_EXECUTED_ONCE
;
2854 fprintf (dump_file
, "Node %s promoted to executed once.\n",
2855 cgraph_node_name (node
));
2861 /* Return true when NODE can not return or throw and thus
2862 it is safe to ignore its side effects for IPA analysis. */
2865 cgraph_node_cannot_return (struct cgraph_node
*node
)
2867 int flags
= flags_from_decl_or_type (node
->decl
);
2868 if (!flag_exceptions
)
2869 return (flags
& ECF_NORETURN
) != 0;
2871 return ((flags
& (ECF_NORETURN
| ECF_NOTHROW
))
2872 == (ECF_NORETURN
| ECF_NOTHROW
));
2875 /* Return true when call of E can not lead to return from caller
2876 and thus it is safe to ignore its side effects for IPA analysis
2877 when computing side effects of the caller.
2878 FIXME: We could actually mark all edges that have no reaching
2879 patch to EXIT_BLOCK_PTR or throw to get better results. */
2881 cgraph_edge_cannot_lead_to_return (struct cgraph_edge
*e
)
2883 if (cgraph_node_cannot_return (e
->caller
))
2885 if (e
->indirect_unknown_callee
)
2887 int flags
= e
->indirect_info
->ecf_flags
;
2888 if (!flag_exceptions
)
2889 return (flags
& ECF_NORETURN
) != 0;
2891 return ((flags
& (ECF_NORETURN
| ECF_NOTHROW
))
2892 == (ECF_NORETURN
| ECF_NOTHROW
));
2895 return cgraph_node_cannot_return (e
->callee
);
2898 /* Return true when function NODE can be removed from callgraph
2899 if all direct calls are eliminated. */
2902 cgraph_can_remove_if_no_direct_calls_and_refs_p (struct cgraph_node
*node
)
2904 gcc_assert (!node
->global
.inlined_to
);
2905 /* Extern inlines can always go, we will use the external definition. */
2906 if (DECL_EXTERNAL (node
->decl
))
2908 /* When function is needed, we can not remove it. */
2909 if (node
->needed
|| node
->reachable_from_other_partition
)
2911 if (DECL_STATIC_CONSTRUCTOR (node
->decl
)
2912 || DECL_STATIC_DESTRUCTOR (node
->decl
))
2914 /* Only COMDAT functions can be removed if externally visible. */
2915 if (node
->local
.externally_visible
2916 && (!DECL_COMDAT (node
->decl
)
2917 || cgraph_used_from_object_file_p (node
)))
2922 /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
2925 nonremovable_p (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
2927 return !cgraph_can_remove_if_no_direct_calls_and_refs_p (node
);
2930 /* Return true when function NODE and its aliases can be removed from callgraph
2931 if all direct calls are eliminated. */
2934 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node
*node
)
2936 /* Extern inlines can always go, we will use the external definition. */
2937 if (DECL_EXTERNAL (node
->decl
))
2939 if (node
->address_taken
)
2941 return !cgraph_for_node_and_aliases (node
, nonremovable_p
, NULL
, true);
2944 /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
2947 used_from_object_file_p (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
2949 return cgraph_used_from_object_file_p (node
);
2952 /* Return true when function NODE can be expected to be removed
2953 from program when direct calls in this compilation unit are removed.
2955 As a special case COMDAT functions are
2956 cgraph_can_remove_if_no_direct_calls_p while the are not
2957 cgraph_only_called_directly_p (it is possible they are called from other
2960 This function behaves as cgraph_only_called_directly_p because eliminating
2961 all uses of COMDAT function does not make it necessarily disappear from
2962 the program unless we are compiling whole program or we do LTO. In this
2963 case we know we win since dynamic linking will not really discard the
2964 linkonce section. */
2967 cgraph_will_be_removed_from_program_if_no_direct_calls (struct cgraph_node
*node
)
2969 gcc_assert (!node
->global
.inlined_to
);
2970 if (cgraph_for_node_and_aliases (node
, used_from_object_file_p
, NULL
, true))
2972 if (!in_lto_p
&& !flag_whole_program
)
2973 return cgraph_only_called_directly_p (node
);
2976 if (DECL_EXTERNAL (node
->decl
))
2978 return cgraph_can_remove_if_no_direct_calls_p (node
);
2982 /* Return true when RESOLUTION indicate that linker will use
2983 the symbol from non-LTO object files. */
2986 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution
)
2988 return (resolution
== LDPR_PREVAILING_DEF
2989 || resolution
== LDPR_PREEMPTED_REG
2990 || resolution
== LDPR_RESOLVED_EXEC
2991 || resolution
== LDPR_RESOLVED_DYN
);
2995 /* Return true when NODE is known to be used from other (non-LTO) object file.
2996 Known only when doing LTO via linker plugin. */
2999 cgraph_used_from_object_file_p (struct cgraph_node
*node
)
3001 gcc_assert (!node
->global
.inlined_to
);
3002 if (!TREE_PUBLIC (node
->decl
) || DECL_EXTERNAL (node
->decl
))
3004 if (resolution_used_from_other_file_p (node
->resolution
))
3009 /* Worker for cgraph_only_called_directly_p. */
3012 cgraph_not_only_called_directly_p_1 (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
3014 return !cgraph_only_called_directly_or_aliased_p (node
);
3017 /* Return true when function NODE and all its aliases are only called
3019 i.e. it is not externally visible, address was not taken and
3020 it is not used in any other non-standard way. */
3023 cgraph_only_called_directly_p (struct cgraph_node
*node
)
3025 gcc_assert (cgraph_function_or_thunk_node (node
, NULL
) == node
);
3026 return !cgraph_for_node_and_aliases (node
, cgraph_not_only_called_directly_p_1
,
3031 /* Collect all callers of NODE. Worker for collect_callers_of_node. */
3034 collect_callers_of_node_1 (struct cgraph_node
*node
, void *data
)
3036 VEC (cgraph_edge_p
, heap
) ** redirect_callers
= (VEC (cgraph_edge_p
, heap
) **)data
;
3037 struct cgraph_edge
*cs
;
3038 enum availability avail
;
3039 cgraph_function_or_thunk_node (node
, &avail
);
3041 if (avail
> AVAIL_OVERWRITABLE
)
3042 for (cs
= node
->callers
; cs
!= NULL
; cs
= cs
->next_caller
)
3043 if (!cs
->indirect_inlining_edge
)
3044 VEC_safe_push (cgraph_edge_p
, heap
, *redirect_callers
, cs
);
3048 /* Collect all callers of NODE and its aliases that are known to lead to NODE
3049 (i.e. are not overwritable). */
3051 VEC (cgraph_edge_p
, heap
) *
3052 collect_callers_of_node (struct cgraph_node
*node
)
3054 VEC (cgraph_edge_p
, heap
) * redirect_callers
= NULL
;
3055 cgraph_for_node_and_aliases (node
, collect_callers_of_node_1
,
3056 &redirect_callers
, false);
3057 return redirect_callers
;
3060 #include "gt-cgraph.h"