1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
3 2011, 2012 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
24 The call-graph is a data structure designed for intra-procedural optimization.
25 It represents a multi-graph where nodes are functions and edges are call sites. */
29 #include "coretypes.h"
32 #include "tree-inline.h"
33 #include "langhooks.h"
40 #include "basic-block.h"
44 #include "tree-dump.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 static void cgraph_node_remove_callers (struct cgraph_node
*node
);
57 static inline void cgraph_edge_remove_caller (struct cgraph_edge
*e
);
58 static inline void cgraph_edge_remove_callee (struct cgraph_edge
*e
);
60 /* Queue of cgraph nodes scheduled to be lowered. */
61 symtab_node x_cgraph_nodes_queue
;
62 #define cgraph_nodes_queue ((struct cgraph_node *)x_cgraph_nodes_queue)
64 /* Number of nodes in existence. */
67 /* Maximal uid used in cgraph nodes. */
70 /* Maximal uid used in cgraph edges. */
71 int cgraph_edge_max_uid
;
73 /* Set when whole unit has been analyzed so we can access global info. */
74 bool cgraph_global_info_ready
= false;
76 /* What state callgraph is in right now. */
77 enum cgraph_state cgraph_state
= CGRAPH_STATE_PARSING
;
79 /* Set when the cgraph is fully build and the basic flags are computed. */
80 bool cgraph_function_flags_ready
= false;
82 /* List of hooks triggered on cgraph_edge events. */
83 struct cgraph_edge_hook_list
{
84 cgraph_edge_hook hook
;
86 struct cgraph_edge_hook_list
*next
;
89 /* List of hooks triggered on cgraph_node events. */
90 struct cgraph_node_hook_list
{
91 cgraph_node_hook hook
;
93 struct cgraph_node_hook_list
*next
;
96 /* List of hooks triggered on events involving two cgraph_edges. */
97 struct cgraph_2edge_hook_list
{
98 cgraph_2edge_hook hook
;
100 struct cgraph_2edge_hook_list
*next
;
103 /* List of hooks triggered on events involving two cgraph_nodes. */
104 struct cgraph_2node_hook_list
{
105 cgraph_2node_hook hook
;
107 struct cgraph_2node_hook_list
*next
;
110 /* List of hooks triggered when an edge is removed. */
111 struct cgraph_edge_hook_list
*first_cgraph_edge_removal_hook
;
112 /* List of hooks triggered when a node is removed. */
113 struct cgraph_node_hook_list
*first_cgraph_node_removal_hook
;
114 /* List of hooks triggered when an edge is duplicated. */
115 struct cgraph_2edge_hook_list
*first_cgraph_edge_duplicated_hook
;
116 /* List of hooks triggered when a node is duplicated. */
117 struct cgraph_2node_hook_list
*first_cgraph_node_duplicated_hook
;
118 /* List of hooks triggered when an function is inserted. */
119 struct cgraph_node_hook_list
*first_cgraph_function_insertion_hook
;
121 /* Head of a linked list of unused (freed) call graph nodes.
122 Do not GTY((delete)) this list so UIDs gets reliably recycled. */
123 static GTY(()) struct cgraph_node
*free_nodes
;
124 /* Head of a linked list of unused (freed) call graph edges.
125 Do not GTY((delete)) this list so UIDs gets reliably recycled. */
126 static GTY(()) struct cgraph_edge
*free_edges
;
128 /* Did procss_same_body_aliases run? */
129 bool same_body_aliases_done
;
131 /* Macros to access the next item in the list of free cgraph nodes and
133 #define NEXT_FREE_NODE(NODE) cgraph ((NODE)->symbol.next)
134 #define SET_NEXT_FREE_NODE(NODE,NODE2) ((NODE))->symbol.next = (symtab_node)NODE2
135 #define NEXT_FREE_EDGE(EDGE) (EDGE)->prev_caller
137 /* Register HOOK to be called with DATA on each removed edge. */
138 struct cgraph_edge_hook_list
*
139 cgraph_add_edge_removal_hook (cgraph_edge_hook hook
, void *data
)
141 struct cgraph_edge_hook_list
*entry
;
142 struct cgraph_edge_hook_list
**ptr
= &first_cgraph_edge_removal_hook
;
144 entry
= (struct cgraph_edge_hook_list
*) xmalloc (sizeof (*entry
));
154 /* Remove ENTRY from the list of hooks called on removing edges. */
156 cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list
*entry
)
158 struct cgraph_edge_hook_list
**ptr
= &first_cgraph_edge_removal_hook
;
160 while (*ptr
!= entry
)
166 /* Call all edge removal hooks. */
168 cgraph_call_edge_removal_hooks (struct cgraph_edge
*e
)
170 struct cgraph_edge_hook_list
*entry
= first_cgraph_edge_removal_hook
;
173 entry
->hook (e
, entry
->data
);
178 /* Register HOOK to be called with DATA on each removed node. */
179 struct cgraph_node_hook_list
*
180 cgraph_add_node_removal_hook (cgraph_node_hook hook
, void *data
)
182 struct cgraph_node_hook_list
*entry
;
183 struct cgraph_node_hook_list
**ptr
= &first_cgraph_node_removal_hook
;
185 entry
= (struct cgraph_node_hook_list
*) xmalloc (sizeof (*entry
));
195 /* Remove ENTRY from the list of hooks called on removing nodes. */
197 cgraph_remove_node_removal_hook (struct cgraph_node_hook_list
*entry
)
199 struct cgraph_node_hook_list
**ptr
= &first_cgraph_node_removal_hook
;
201 while (*ptr
!= entry
)
207 /* Call all node removal hooks. */
209 cgraph_call_node_removal_hooks (struct cgraph_node
*node
)
211 struct cgraph_node_hook_list
*entry
= first_cgraph_node_removal_hook
;
214 entry
->hook (node
, entry
->data
);
219 /* Register HOOK to be called with DATA on each inserted node. */
220 struct cgraph_node_hook_list
*
221 cgraph_add_function_insertion_hook (cgraph_node_hook hook
, void *data
)
223 struct cgraph_node_hook_list
*entry
;
224 struct cgraph_node_hook_list
**ptr
= &first_cgraph_function_insertion_hook
;
226 entry
= (struct cgraph_node_hook_list
*) xmalloc (sizeof (*entry
));
236 /* Remove ENTRY from the list of hooks called on inserted nodes. */
238 cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list
*entry
)
240 struct cgraph_node_hook_list
**ptr
= &first_cgraph_function_insertion_hook
;
242 while (*ptr
!= entry
)
248 /* Call all node insertion hooks. */
250 cgraph_call_function_insertion_hooks (struct cgraph_node
*node
)
252 struct cgraph_node_hook_list
*entry
= first_cgraph_function_insertion_hook
;
255 entry
->hook (node
, entry
->data
);
260 /* Register HOOK to be called with DATA on each duplicated edge. */
261 struct cgraph_2edge_hook_list
*
262 cgraph_add_edge_duplication_hook (cgraph_2edge_hook hook
, void *data
)
264 struct cgraph_2edge_hook_list
*entry
;
265 struct cgraph_2edge_hook_list
**ptr
= &first_cgraph_edge_duplicated_hook
;
267 entry
= (struct cgraph_2edge_hook_list
*) xmalloc (sizeof (*entry
));
277 /* Remove ENTRY from the list of hooks called on duplicating edges. */
279 cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list
*entry
)
281 struct cgraph_2edge_hook_list
**ptr
= &first_cgraph_edge_duplicated_hook
;
283 while (*ptr
!= entry
)
289 /* Call all edge duplication hooks. */
291 cgraph_call_edge_duplication_hooks (struct cgraph_edge
*cs1
,
292 struct cgraph_edge
*cs2
)
294 struct cgraph_2edge_hook_list
*entry
= first_cgraph_edge_duplicated_hook
;
297 entry
->hook (cs1
, cs2
, entry
->data
);
302 /* Register HOOK to be called with DATA on each duplicated node. */
303 struct cgraph_2node_hook_list
*
304 cgraph_add_node_duplication_hook (cgraph_2node_hook hook
, void *data
)
306 struct cgraph_2node_hook_list
*entry
;
307 struct cgraph_2node_hook_list
**ptr
= &first_cgraph_node_duplicated_hook
;
309 entry
= (struct cgraph_2node_hook_list
*) xmalloc (sizeof (*entry
));
319 /* Remove ENTRY from the list of hooks called on duplicating nodes. */
321 cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list
*entry
)
323 struct cgraph_2node_hook_list
**ptr
= &first_cgraph_node_duplicated_hook
;
325 while (*ptr
!= entry
)
331 /* Call all node duplication hooks. */
333 cgraph_call_node_duplication_hooks (struct cgraph_node
*node1
,
334 struct cgraph_node
*node2
)
336 struct cgraph_2node_hook_list
*entry
= first_cgraph_node_duplicated_hook
;
339 entry
->hook (node1
, node2
, entry
->data
);
344 /* Allocate new callgraph node. */
346 static inline struct cgraph_node
*
347 cgraph_allocate_node (void)
349 struct cgraph_node
*node
;
354 free_nodes
= NEXT_FREE_NODE (node
);
358 node
= ggc_alloc_cleared_cgraph_node ();
359 node
->uid
= cgraph_max_uid
++;
365 /* Allocate new callgraph node and insert it into basic data structures. */
368 cgraph_create_empty_node (void)
370 struct cgraph_node
*node
= cgraph_allocate_node ();
372 node
->symbol
.type
= SYMTAB_FUNCTION
;
373 node
->frequency
= NODE_FREQUENCY_NORMAL
;
374 node
->count_materialization_scale
= REG_BR_PROB_BASE
;
379 /* Return cgraph node assigned to DECL. Create new one when needed. */
382 cgraph_create_node (tree decl
)
384 struct cgraph_node
*node
= cgraph_create_empty_node ();
385 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
387 node
->symbol
.decl
= decl
;
388 symtab_register_node ((symtab_node
) node
);
390 if (DECL_CONTEXT (decl
) && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
392 node
->origin
= cgraph_get_create_node (DECL_CONTEXT (decl
));
393 node
->next_nested
= node
->origin
->nested
;
394 node
->origin
->nested
= node
;
399 /* Try to find a call graph node for declaration DECL and if it does not exist,
403 cgraph_get_create_node (tree decl
)
405 struct cgraph_node
*node
;
407 node
= cgraph_get_node (decl
);
411 return cgraph_create_node (decl
);
414 /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
415 the function body is associated with (not necessarily cgraph_node (DECL). */
418 cgraph_create_function_alias (tree alias
, tree decl
)
420 struct cgraph_node
*alias_node
;
422 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
423 gcc_assert (TREE_CODE (alias
) == FUNCTION_DECL
);
424 alias_node
= cgraph_get_create_node (alias
);
425 gcc_assert (!alias_node
->local
.finalized
);
426 alias_node
->thunk
.alias
= decl
;
427 alias_node
->local
.finalized
= true;
428 alias_node
->alias
= 1;
432 /* Attempt to mark ALIAS as an alias to DECL. Return alias node if successful
434 Same body aliases are output whenever the body of DECL is output,
435 and cgraph_get_node (ALIAS) transparently returns cgraph_get_node (DECL). */
438 cgraph_same_body_alias (struct cgraph_node
*decl_node ATTRIBUTE_UNUSED
, tree alias
, tree decl
)
440 struct cgraph_node
*n
;
441 #ifndef ASM_OUTPUT_DEF
442 /* If aliases aren't supported by the assembler, fail. */
445 /* Langhooks can create same body aliases of symbols not defined.
446 Those are useless. Drop them on the floor. */
447 if (cgraph_global_info_ready
)
450 n
= cgraph_create_function_alias (alias
, decl
);
451 n
->same_body_alias
= true;
452 if (same_body_aliases_done
)
453 ipa_record_reference ((symtab_node
)n
, (symtab_node
)cgraph_get_node (decl
),
454 IPA_REF_ALIAS
, NULL
);
458 /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
459 aliases DECL with an adjustments made into the first parameter.
460 See comments in thunk_adjust for detail on the parameters. */
463 cgraph_add_thunk (struct cgraph_node
*decl_node ATTRIBUTE_UNUSED
,
464 tree alias
, tree decl ATTRIBUTE_UNUSED
,
466 HOST_WIDE_INT fixed_offset
, HOST_WIDE_INT virtual_value
,
470 struct cgraph_node
*node
;
472 node
= cgraph_get_node (alias
);
475 gcc_assert (node
->local
.finalized
);
476 gcc_assert (!node
->alias
);
477 gcc_assert (!node
->thunk
.thunk_p
);
478 cgraph_remove_node (node
);
481 node
= cgraph_create_node (alias
);
482 gcc_checking_assert (!virtual_offset
483 || double_int_equal_p
484 (tree_to_double_int (virtual_offset
),
485 shwi_to_double_int (virtual_value
)));
486 node
->thunk
.fixed_offset
= fixed_offset
;
487 node
->thunk
.this_adjusting
= this_adjusting
;
488 node
->thunk
.virtual_value
= virtual_value
;
489 node
->thunk
.virtual_offset_p
= virtual_offset
!= NULL
;
490 node
->thunk
.alias
= real_alias
;
491 node
->thunk
.thunk_p
= true;
492 node
->local
.finalized
= true;
497 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
498 Return NULL if there's no such node. */
501 cgraph_node_for_asm (tree asmname
)
503 symtab_node node
= symtab_node_for_asm (asmname
);
505 /* We do not want to look at inline clones. */
506 for (node
= symtab_node_for_asm (asmname
); node
; node
= node
->symbol
.next_sharing_asm_name
)
507 if (symtab_function_p (node
) && !cgraph(node
)->global
.inlined_to
)
508 return cgraph (node
);
512 /* Returns a hash value for X (which really is a die_struct). */
515 edge_hash (const void *x
)
517 return htab_hash_pointer (((const struct cgraph_edge
*) x
)->call_stmt
);
520 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
523 edge_eq (const void *x
, const void *y
)
525 return ((const struct cgraph_edge
*) x
)->call_stmt
== y
;
528 /* Add call graph edge E to call site hash of its caller. */
531 cgraph_add_edge_to_call_site_hash (struct cgraph_edge
*e
)
534 slot
= htab_find_slot_with_hash (e
->caller
->call_site_hash
,
536 htab_hash_pointer (e
->call_stmt
),
542 /* Return the callgraph edge representing the GIMPLE_CALL statement
546 cgraph_edge (struct cgraph_node
*node
, gimple call_stmt
)
548 struct cgraph_edge
*e
, *e2
;
551 if (node
->call_site_hash
)
552 return (struct cgraph_edge
*)
553 htab_find_with_hash (node
->call_site_hash
, call_stmt
,
554 htab_hash_pointer (call_stmt
));
556 /* This loop may turn out to be performance problem. In such case adding
557 hashtables into call nodes with very many edges is probably best
558 solution. It is not good idea to add pointer into CALL_EXPR itself
559 because we want to make possible having multiple cgraph nodes representing
560 different clones of the same body before the body is actually cloned. */
561 for (e
= node
->callees
; e
; e
= e
->next_callee
)
563 if (e
->call_stmt
== call_stmt
)
569 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
571 if (e
->call_stmt
== call_stmt
)
578 node
->call_site_hash
= htab_create_ggc (120, edge_hash
, edge_eq
, NULL
);
579 for (e2
= node
->callees
; e2
; e2
= e2
->next_callee
)
580 cgraph_add_edge_to_call_site_hash (e2
);
581 for (e2
= node
->indirect_calls
; e2
; e2
= e2
->next_callee
)
582 cgraph_add_edge_to_call_site_hash (e2
);
589 /* Change field call_stmt of edge E to NEW_STMT. */
592 cgraph_set_call_stmt (struct cgraph_edge
*e
, gimple new_stmt
)
596 if (e
->caller
->call_site_hash
)
598 htab_remove_elt_with_hash (e
->caller
->call_site_hash
,
600 htab_hash_pointer (e
->call_stmt
));
603 e
->call_stmt
= new_stmt
;
604 if (e
->indirect_unknown_callee
605 && (decl
= gimple_call_fndecl (new_stmt
)))
607 /* Constant propagation (and possibly also inlining?) can turn an
608 indirect call into a direct one. */
609 struct cgraph_node
*new_callee
= cgraph_get_node (decl
);
611 gcc_checking_assert (new_callee
);
612 cgraph_make_edge_direct (e
, new_callee
);
615 push_cfun (DECL_STRUCT_FUNCTION (e
->caller
->symbol
.decl
));
616 e
->can_throw_external
= stmt_can_throw_external (new_stmt
);
618 if (e
->caller
->call_site_hash
)
619 cgraph_add_edge_to_call_site_hash (e
);
622 /* Allocate a cgraph_edge structure and fill it with data according to the
623 parameters of which only CALLEE can be NULL (when creating an indirect call
626 static struct cgraph_edge
*
627 cgraph_create_edge_1 (struct cgraph_node
*caller
, struct cgraph_node
*callee
,
628 gimple call_stmt
, gcov_type count
, int freq
)
630 struct cgraph_edge
*edge
;
632 /* LTO does not actually have access to the call_stmt since these
633 have not been loaded yet. */
636 /* This is a rather expensive check possibly triggering
637 construction of call stmt hashtable. */
638 gcc_checking_assert (!cgraph_edge (caller
, call_stmt
));
640 gcc_assert (is_gimple_call (call_stmt
));
646 free_edges
= NEXT_FREE_EDGE (edge
);
650 edge
= ggc_alloc_cgraph_edge ();
651 edge
->uid
= cgraph_edge_max_uid
++;
655 edge
->caller
= caller
;
656 edge
->callee
= callee
;
657 edge
->prev_caller
= NULL
;
658 edge
->next_caller
= NULL
;
659 edge
->prev_callee
= NULL
;
660 edge
->next_callee
= NULL
;
663 gcc_assert (count
>= 0);
664 edge
->frequency
= freq
;
665 gcc_assert (freq
>= 0);
666 gcc_assert (freq
<= CGRAPH_FREQ_MAX
);
668 edge
->call_stmt
= call_stmt
;
669 push_cfun (DECL_STRUCT_FUNCTION (caller
->symbol
.decl
));
670 edge
->can_throw_external
671 = call_stmt
? stmt_can_throw_external (call_stmt
) : false;
674 && callee
&& callee
->symbol
.decl
675 && !gimple_check_call_matching_types (call_stmt
, callee
->symbol
.decl
))
676 edge
->call_stmt_cannot_inline_p
= true;
678 edge
->call_stmt_cannot_inline_p
= false;
679 if (call_stmt
&& caller
->call_site_hash
)
680 cgraph_add_edge_to_call_site_hash (edge
);
682 edge
->indirect_info
= NULL
;
683 edge
->indirect_inlining_edge
= 0;
688 /* Create edge from CALLER to CALLEE in the cgraph. */
691 cgraph_create_edge (struct cgraph_node
*caller
, struct cgraph_node
*callee
,
692 gimple call_stmt
, gcov_type count
, int freq
)
694 struct cgraph_edge
*edge
= cgraph_create_edge_1 (caller
, callee
, call_stmt
,
697 edge
->indirect_unknown_callee
= 0;
698 initialize_inline_failed (edge
);
700 edge
->next_caller
= callee
->callers
;
702 callee
->callers
->prev_caller
= edge
;
703 edge
->next_callee
= caller
->callees
;
705 caller
->callees
->prev_callee
= edge
;
706 caller
->callees
= edge
;
707 callee
->callers
= edge
;
712 /* Allocate cgraph_indirect_call_info and set its fields to default values. */
714 struct cgraph_indirect_call_info
*
715 cgraph_allocate_init_indirect_info (void)
717 struct cgraph_indirect_call_info
*ii
;
719 ii
= ggc_alloc_cleared_cgraph_indirect_call_info ();
720 ii
->param_index
= -1;
724 /* Create an indirect edge with a yet-undetermined callee where the call
725 statement destination is a formal parameter of the caller with index
729 cgraph_create_indirect_edge (struct cgraph_node
*caller
, gimple call_stmt
,
731 gcov_type count
, int freq
)
733 struct cgraph_edge
*edge
= cgraph_create_edge_1 (caller
, NULL
, call_stmt
,
736 edge
->indirect_unknown_callee
= 1;
737 initialize_inline_failed (edge
);
739 edge
->indirect_info
= cgraph_allocate_init_indirect_info ();
740 edge
->indirect_info
->ecf_flags
= ecf_flags
;
742 edge
->next_callee
= caller
->indirect_calls
;
743 if (caller
->indirect_calls
)
744 caller
->indirect_calls
->prev_callee
= edge
;
745 caller
->indirect_calls
= edge
;
750 /* Remove the edge E from the list of the callers of the callee. */
753 cgraph_edge_remove_callee (struct cgraph_edge
*e
)
755 gcc_assert (!e
->indirect_unknown_callee
);
757 e
->prev_caller
->next_caller
= e
->next_caller
;
759 e
->next_caller
->prev_caller
= e
->prev_caller
;
761 e
->callee
->callers
= e
->next_caller
;
764 /* Remove the edge E from the list of the callees of the caller. */
767 cgraph_edge_remove_caller (struct cgraph_edge
*e
)
770 e
->prev_callee
->next_callee
= e
->next_callee
;
772 e
->next_callee
->prev_callee
= e
->prev_callee
;
775 if (e
->indirect_unknown_callee
)
776 e
->caller
->indirect_calls
= e
->next_callee
;
778 e
->caller
->callees
= e
->next_callee
;
780 if (e
->caller
->call_site_hash
)
781 htab_remove_elt_with_hash (e
->caller
->call_site_hash
,
783 htab_hash_pointer (e
->call_stmt
));
786 /* Put the edge onto the free list. */
789 cgraph_free_edge (struct cgraph_edge
*e
)
793 /* Clear out the edge so we do not dangle pointers. */
794 memset (e
, 0, sizeof (*e
));
796 NEXT_FREE_EDGE (e
) = free_edges
;
800 /* Remove the edge E in the cgraph. */
803 cgraph_remove_edge (struct cgraph_edge
*e
)
805 /* Call all edge removal hooks. */
806 cgraph_call_edge_removal_hooks (e
);
808 if (!e
->indirect_unknown_callee
)
809 /* Remove from callers list of the callee. */
810 cgraph_edge_remove_callee (e
);
812 /* Remove from callees list of the callers. */
813 cgraph_edge_remove_caller (e
);
815 /* Put the edge onto the free list. */
816 cgraph_free_edge (e
);
819 /* Set callee of call graph edge E and add it to the corresponding set of
823 cgraph_set_edge_callee (struct cgraph_edge
*e
, struct cgraph_node
*n
)
825 e
->prev_caller
= NULL
;
827 n
->callers
->prev_caller
= e
;
828 e
->next_caller
= n
->callers
;
833 /* Redirect callee of E to N. The function does not update underlying
837 cgraph_redirect_edge_callee (struct cgraph_edge
*e
, struct cgraph_node
*n
)
839 /* Remove from callers list of the current callee. */
840 cgraph_edge_remove_callee (e
);
842 /* Insert to callers list of the new callee. */
843 cgraph_set_edge_callee (e
, n
);
846 /* Make an indirect EDGE with an unknown callee an ordinary edge leading to
847 CALLEE. DELTA is an integer constant that is to be added to the this
848 pointer (first parameter) to compensate for skipping a thunk adjustment. */
851 cgraph_make_edge_direct (struct cgraph_edge
*edge
, struct cgraph_node
*callee
)
853 edge
->indirect_unknown_callee
= 0;
855 /* Get the edge out of the indirect edge list. */
856 if (edge
->prev_callee
)
857 edge
->prev_callee
->next_callee
= edge
->next_callee
;
858 if (edge
->next_callee
)
859 edge
->next_callee
->prev_callee
= edge
->prev_callee
;
860 if (!edge
->prev_callee
)
861 edge
->caller
->indirect_calls
= edge
->next_callee
;
863 /* Put it into the normal callee list */
864 edge
->prev_callee
= NULL
;
865 edge
->next_callee
= edge
->caller
->callees
;
866 if (edge
->caller
->callees
)
867 edge
->caller
->callees
->prev_callee
= edge
;
868 edge
->caller
->callees
= edge
;
870 /* Insert to callers list of the new callee. */
871 cgraph_set_edge_callee (edge
, callee
);
874 edge
->call_stmt_cannot_inline_p
875 = !gimple_check_call_matching_types (edge
->call_stmt
, callee
->symbol
.decl
);
877 /* We need to re-determine the inlining status of the edge. */
878 initialize_inline_failed (edge
);
881 /* If necessary, change the function declaration in the call statement
882 associated with E so that it corresponds to the edge callee. */
885 cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge
*e
)
887 tree decl
= gimple_call_fndecl (e
->call_stmt
);
889 gimple_stmt_iterator gsi
;
890 #ifdef ENABLE_CHECKING
891 struct cgraph_node
*node
;
894 if (e
->indirect_unknown_callee
895 || decl
== e
->callee
->symbol
.decl
)
898 #ifdef ENABLE_CHECKING
901 node
= cgraph_get_node (decl
);
902 gcc_assert (!node
|| !node
->clone
.combined_args_to_skip
);
906 if (cgraph_dump_file
)
908 fprintf (cgraph_dump_file
, "updating call of %s/%i -> %s/%i: ",
909 xstrdup (cgraph_node_name (e
->caller
)), e
->caller
->uid
,
910 xstrdup (cgraph_node_name (e
->callee
)), e
->callee
->uid
);
911 print_gimple_stmt (cgraph_dump_file
, e
->call_stmt
, 0, dump_flags
);
912 if (e
->callee
->clone
.combined_args_to_skip
)
914 fprintf (cgraph_dump_file
, " combined args to skip: ");
915 dump_bitmap (cgraph_dump_file
,
916 e
->callee
->clone
.combined_args_to_skip
);
920 if (e
->callee
->clone
.combined_args_to_skip
)
925 = gimple_call_copy_skip_args (e
->call_stmt
,
926 e
->callee
->clone
.combined_args_to_skip
);
927 gimple_call_set_fndecl (new_stmt
, e
->callee
->symbol
.decl
);
929 if (gimple_vdef (new_stmt
)
930 && TREE_CODE (gimple_vdef (new_stmt
)) == SSA_NAME
)
931 SSA_NAME_DEF_STMT (gimple_vdef (new_stmt
)) = new_stmt
;
933 gsi
= gsi_for_stmt (e
->call_stmt
);
934 gsi_replace (&gsi
, new_stmt
, false);
935 /* We need to defer cleaning EH info on the new statement to
936 fixup-cfg. We may not have dominator information at this point
937 and thus would end up with unreachable blocks and have no way
938 to communicate that we need to run CFG cleanup then. */
939 lp_nr
= lookup_stmt_eh_lp (e
->call_stmt
);
942 remove_stmt_from_eh_lp (e
->call_stmt
);
943 add_stmt_to_eh_lp (new_stmt
, lp_nr
);
948 new_stmt
= e
->call_stmt
;
949 gimple_call_set_fndecl (new_stmt
, e
->callee
->symbol
.decl
);
950 update_stmt (new_stmt
);
953 cgraph_set_call_stmt_including_clones (e
->caller
, e
->call_stmt
, new_stmt
);
955 if (cgraph_dump_file
)
957 fprintf (cgraph_dump_file
, " updated to:");
958 print_gimple_stmt (cgraph_dump_file
, e
->call_stmt
, 0, dump_flags
);
963 /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
964 OLD_STMT changed into NEW_STMT. OLD_CALL is gimple_call_fndecl
965 of OLD_STMT if it was previously call statement.
966 If NEW_STMT is NULL, the call has been dropped without any
970 cgraph_update_edges_for_call_stmt_node (struct cgraph_node
*node
,
971 gimple old_stmt
, tree old_call
,
974 tree new_call
= (new_stmt
&& is_gimple_call (new_stmt
))
975 ? gimple_call_fndecl (new_stmt
) : 0;
977 /* We are seeing indirect calls, then there is nothing to update. */
978 if (!new_call
&& !old_call
)
980 /* See if we turned indirect call into direct call or folded call to one builtin
981 into different builtin. */
982 if (old_call
!= new_call
)
984 struct cgraph_edge
*e
= cgraph_edge (node
, old_stmt
);
985 struct cgraph_edge
*ne
= NULL
;
991 /* See if the edge is already there and has the correct callee. It
992 might be so because of indirect inlining has already updated
993 it. We also might've cloned and redirected the edge. */
994 if (new_call
&& e
->callee
)
996 struct cgraph_node
*callee
= e
->callee
;
999 if (callee
->symbol
.decl
== new_call
1000 || callee
->former_clone_of
== new_call
)
1002 callee
= callee
->clone_of
;
1006 /* Otherwise remove edge and create new one; we can't simply redirect
1007 since function has changed, so inline plan and other information
1008 attached to edge is invalid. */
1010 frequency
= e
->frequency
;
1011 cgraph_remove_edge (e
);
1015 /* We are seeing new direct call; compute profile info based on BB. */
1016 basic_block bb
= gimple_bb (new_stmt
);
1018 frequency
= compute_call_stmt_bb_frequency (current_function_decl
,
1024 ne
= cgraph_create_edge (node
, cgraph_get_create_node (new_call
),
1025 new_stmt
, count
, frequency
);
1026 gcc_assert (ne
->inline_failed
);
1029 /* We only updated the call stmt; update pointer in cgraph edge.. */
1030 else if (old_stmt
!= new_stmt
)
1031 cgraph_set_call_stmt (cgraph_edge (node
, old_stmt
), new_stmt
);
1034 /* Update or remove the corresponding cgraph edge if a GIMPLE_CALL
1035 OLD_STMT changed into NEW_STMT. OLD_DECL is gimple_call_fndecl
1036 of OLD_STMT before it was updated (updating can happen inplace). */
1039 cgraph_update_edges_for_call_stmt (gimple old_stmt
, tree old_decl
, gimple new_stmt
)
1041 struct cgraph_node
*orig
= cgraph_get_node (cfun
->decl
);
1042 struct cgraph_node
*node
;
1044 gcc_checking_assert (orig
);
1045 cgraph_update_edges_for_call_stmt_node (orig
, old_stmt
, old_decl
, new_stmt
);
1047 for (node
= orig
->clones
; node
!= orig
;)
1049 cgraph_update_edges_for_call_stmt_node (node
, old_stmt
, old_decl
, new_stmt
);
1051 node
= node
->clones
;
1052 else if (node
->next_sibling_clone
)
1053 node
= node
->next_sibling_clone
;
1056 while (node
!= orig
&& !node
->next_sibling_clone
)
1057 node
= node
->clone_of
;
1059 node
= node
->next_sibling_clone
;
1065 /* Remove all callees from the node. */
1068 cgraph_node_remove_callees (struct cgraph_node
*node
)
1070 struct cgraph_edge
*e
, *f
;
1072 /* It is sufficient to remove the edges from the lists of callers of
1073 the callees. The callee list of the node can be zapped with one
1075 for (e
= node
->callees
; e
; e
= f
)
1078 cgraph_call_edge_removal_hooks (e
);
1079 if (!e
->indirect_unknown_callee
)
1080 cgraph_edge_remove_callee (e
);
1081 cgraph_free_edge (e
);
1083 for (e
= node
->indirect_calls
; e
; e
= f
)
1086 cgraph_call_edge_removal_hooks (e
);
1087 if (!e
->indirect_unknown_callee
)
1088 cgraph_edge_remove_callee (e
);
1089 cgraph_free_edge (e
);
1091 node
->indirect_calls
= NULL
;
1092 node
->callees
= NULL
;
1093 if (node
->call_site_hash
)
1095 htab_delete (node
->call_site_hash
);
1096 node
->call_site_hash
= NULL
;
1100 /* Remove all callers from the node. */
1103 cgraph_node_remove_callers (struct cgraph_node
*node
)
1105 struct cgraph_edge
*e
, *f
;
1107 /* It is sufficient to remove the edges from the lists of callees of
1108 the callers. The caller list of the node can be zapped with one
1110 for (e
= node
->callers
; e
; e
= f
)
1113 cgraph_call_edge_removal_hooks (e
);
1114 cgraph_edge_remove_caller (e
);
1115 cgraph_free_edge (e
);
1117 node
->callers
= NULL
;
1120 /* Release memory used to represent body of function NODE. */
1123 cgraph_release_function_body (struct cgraph_node
*node
)
1125 if (DECL_STRUCT_FUNCTION (node
->symbol
.decl
))
1127 tree old_decl
= current_function_decl
;
1128 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1132 cfun
->curr_properties
&= ~PROP_loops
;
1133 loop_optimizer_finalize ();
1135 if (cfun
->gimple_df
)
1137 current_function_decl
= node
->symbol
.decl
;
1139 delete_tree_cfg_annotations ();
1141 current_function_decl
= old_decl
;
1145 gcc_assert (dom_computed
[0] == DOM_NONE
);
1146 gcc_assert (dom_computed
[1] == DOM_NONE
);
1149 if (cfun
->value_histograms
)
1152 gimple_set_body (node
->symbol
.decl
, NULL
);
1153 VEC_free (ipa_opt_pass
, heap
,
1154 node
->ipa_transforms_to_apply
);
1155 /* Struct function hangs a lot of data that would leak if we didn't
1156 removed all pointers to it. */
1157 ggc_free (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
1158 DECL_STRUCT_FUNCTION (node
->symbol
.decl
) = NULL
;
1160 DECL_SAVED_TREE (node
->symbol
.decl
) = NULL
;
1161 /* If the node is abstract and needed, then do not clear DECL_INITIAL
1162 of its associated function function declaration because it's
1163 needed to emit debug info later. */
1164 if (!node
->abstract_and_needed
&& DECL_INITIAL (node
->symbol
.decl
))
1165 DECL_INITIAL (node
->symbol
.decl
) = error_mark_node
;
1168 /* Remove the node from cgraph. */
1171 cgraph_remove_node (struct cgraph_node
*node
)
1173 struct cgraph_node
*n
;
1174 int uid
= node
->uid
;
1176 cgraph_call_node_removal_hooks (node
);
1177 cgraph_node_remove_callers (node
);
1178 cgraph_node_remove_callees (node
);
1179 VEC_free (ipa_opt_pass
, heap
,
1180 node
->ipa_transforms_to_apply
);
1182 /* Incremental inlining access removed nodes stored in the postorder list.
1184 node
->symbol
.force_output
= false;
1185 for (n
= node
->nested
; n
; n
= n
->next_nested
)
1187 node
->nested
= NULL
;
1190 struct cgraph_node
**node2
= &node
->origin
->nested
;
1192 while (*node2
!= node
)
1193 node2
= &(*node2
)->next_nested
;
1194 *node2
= node
->next_nested
;
1196 symtab_unregister_node ((symtab_node
)node
);
1197 if (node
->prev_sibling_clone
)
1198 node
->prev_sibling_clone
->next_sibling_clone
= node
->next_sibling_clone
;
1199 else if (node
->clone_of
)
1200 node
->clone_of
->clones
= node
->next_sibling_clone
;
1201 if (node
->next_sibling_clone
)
1202 node
->next_sibling_clone
->prev_sibling_clone
= node
->prev_sibling_clone
;
1205 struct cgraph_node
*n
, *next
;
1209 for (n
= node
->clones
; n
->next_sibling_clone
; n
= n
->next_sibling_clone
)
1210 n
->clone_of
= node
->clone_of
;
1211 n
->clone_of
= node
->clone_of
;
1212 n
->next_sibling_clone
= node
->clone_of
->clones
;
1213 if (node
->clone_of
->clones
)
1214 node
->clone_of
->clones
->prev_sibling_clone
= n
;
1215 node
->clone_of
->clones
= node
->clones
;
1219 /* We are removing node with clones. This makes clones inconsistent,
1220 but assume they will be removed subsequently and just keep clone
1221 tree intact. This can happen in unreachable function removal since
1222 we remove unreachable functions in random order, not by bottom-up
1223 walk of clone trees. */
1224 for (n
= node
->clones
; n
; n
= next
)
1226 next
= n
->next_sibling_clone
;
1227 n
->next_sibling_clone
= NULL
;
1228 n
->prev_sibling_clone
= NULL
;
1234 /* While all the clones are removed after being proceeded, the function
1235 itself is kept in the cgraph even after it is compiled. Check whether
1236 we are done with this body and reclaim it proactively if this is the case.
1238 n
= cgraph_get_node (node
->symbol
.decl
);
1240 || (!n
->clones
&& !n
->clone_of
&& !n
->global
.inlined_to
1241 && (cgraph_global_info_ready
1242 && (TREE_ASM_WRITTEN (n
->symbol
.decl
)
1243 || DECL_EXTERNAL (n
->symbol
.decl
)
1245 || n
->symbol
.in_other_partition
))))
1246 cgraph_release_function_body (node
);
1248 node
->symbol
.decl
= NULL
;
1249 if (node
->call_site_hash
)
1251 htab_delete (node
->call_site_hash
);
1252 node
->call_site_hash
= NULL
;
1256 /* Clear out the node to NULL all pointers and add the node to the free
1258 memset (node
, 0, sizeof(*node
));
1259 node
->symbol
.type
= SYMTAB_FUNCTION
;
1261 SET_NEXT_FREE_NODE (node
, free_nodes
);
1265 /* Likewise indicate that a node is having address taken. */
1268 cgraph_mark_address_taken_node (struct cgraph_node
*node
)
1270 gcc_assert (!node
->global
.inlined_to
);
1271 /* FIXME: address_taken flag is used both as a shortcut for testing whether
1272 IPA_REF_ADDR reference exists (and thus it should be set on node
1273 representing alias we take address of) and as a test whether address
1274 of the object was taken (and thus it should be set on node alias is
1275 referring to). We should remove the first use and the remove the
1277 node
->symbol
.address_taken
= 1;
1278 node
= cgraph_function_or_thunk_node (node
, NULL
);
1279 node
->symbol
.address_taken
= 1;
1282 /* Return local info for the compiled function. */
1284 struct cgraph_local_info
*
1285 cgraph_local_info (tree decl
)
1287 struct cgraph_node
*node
;
1289 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1290 node
= cgraph_get_node (decl
);
1293 return &node
->local
;
1296 /* Return local info for the compiled function. */
1298 struct cgraph_global_info
*
1299 cgraph_global_info (tree decl
)
1301 struct cgraph_node
*node
;
1303 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
&& cgraph_global_info_ready
);
1304 node
= cgraph_get_node (decl
);
1307 return &node
->global
;
1310 /* Return local info for the compiled function. */
1312 struct cgraph_rtl_info
*
1313 cgraph_rtl_info (tree decl
)
1315 struct cgraph_node
*node
;
1317 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1318 node
= cgraph_get_node (decl
);
1320 || (decl
!= current_function_decl
1321 && !TREE_ASM_WRITTEN (node
->symbol
.decl
)))
1326 /* Return a string describing the failure REASON. */
1329 cgraph_inline_failed_string (cgraph_inline_failed_t reason
)
1332 #define DEFCIFCODE(code, string) string,
1334 static const char *cif_string_table
[CIF_N_REASONS
] = {
1335 #include "cif-code.def"
1338 /* Signedness of an enum type is implementation defined, so cast it
1339 to unsigned before testing. */
1340 gcc_assert ((unsigned) reason
< CIF_N_REASONS
);
1341 return cif_string_table
[reason
];
1344 /* Names used to print out the availability enum. */
1345 const char * const cgraph_availability_names
[] =
1346 {"unset", "not_available", "overwritable", "available", "local"};
1349 /* Dump call graph node NODE to file F. */
1352 dump_cgraph_node (FILE *f
, struct cgraph_node
*node
)
1354 struct cgraph_edge
*edge
;
1355 int indirect_calls_count
= 0;
1357 dump_symtab_base (f
, (symtab_node
) node
);
1359 if (node
->global
.inlined_to
)
1360 fprintf (f
, " Function %s/%i is inline copy in %s/%i\n",
1361 xstrdup (cgraph_node_name (node
)),
1363 xstrdup (cgraph_node_name (node
->global
.inlined_to
)),
1364 node
->global
.inlined_to
->symbol
.order
);
1366 fprintf (f
, " Clone of %s/%i\n",
1367 cgraph_node_asm_name (node
->clone_of
),
1368 node
->clone_of
->symbol
.order
);
1369 if (cgraph_function_flags_ready
)
1370 fprintf (f
, " Availability: %s\n",
1371 cgraph_availability_names
[cgraph_function_body_availability (node
)]);
1373 fprintf (f
, " Function flags:");
1375 fprintf (f
, " analyzed");
1377 fprintf (f
, " executed "HOST_WIDEST_INT_PRINT_DEC
"x",
1378 (HOST_WIDEST_INT
)node
->count
);
1380 fprintf (f
, " nested in: %s", cgraph_node_asm_name (node
->origin
));
1381 if (gimple_has_body_p (node
->symbol
.decl
))
1382 fprintf (f
, " body");
1384 fprintf (f
, " process");
1385 if (node
->local
.local
)
1386 fprintf (f
, " local");
1387 if (node
->local
.finalized
)
1388 fprintf (f
, " finalized");
1389 if (node
->local
.redefined_extern_inline
)
1390 fprintf (f
, " redefined_extern_inline");
1391 if (node
->only_called_at_startup
)
1392 fprintf (f
, " only_called_at_startup");
1393 if (node
->only_called_at_exit
)
1394 fprintf (f
, " only_called_at_exit");
1395 else if (node
->alias
)
1396 fprintf (f
, " alias");
1398 fprintf (f
, " tm_clone");
1402 if (node
->thunk
.thunk_p
)
1404 fprintf (f
, " Thunk of %s (asm: %s) fixed offset %i virtual value %i has "
1405 "virtual offset %i)\n",
1406 lang_hooks
.decl_printable_name (node
->thunk
.alias
, 2),
1407 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->thunk
.alias
)),
1408 (int)node
->thunk
.fixed_offset
,
1409 (int)node
->thunk
.virtual_value
,
1410 (int)node
->thunk
.virtual_offset_p
);
1412 if (node
->alias
&& node
->thunk
.alias
)
1414 fprintf (f
, " Alias of %s",
1415 lang_hooks
.decl_printable_name (node
->thunk
.alias
, 2));
1416 if (DECL_ASSEMBLER_NAME_SET_P (node
->thunk
.alias
))
1417 fprintf (f
, " (asm: %s)",
1418 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->thunk
.alias
)));
1422 fprintf (f
, " Called by: ");
1424 for (edge
= node
->callers
; edge
; edge
= edge
->next_caller
)
1426 fprintf (f
, "%s/%i ", cgraph_node_asm_name (edge
->caller
),
1427 edge
->caller
->symbol
.order
);
1429 fprintf (f
, "("HOST_WIDEST_INT_PRINT_DEC
"x) ",
1430 (HOST_WIDEST_INT
)edge
->count
);
1431 if (edge
->frequency
)
1432 fprintf (f
, "(%.2f per call) ",
1433 edge
->frequency
/ (double)CGRAPH_FREQ_BASE
);
1434 if (!edge
->inline_failed
)
1435 fprintf(f
, "(inlined) ");
1436 if (edge
->indirect_inlining_edge
)
1437 fprintf(f
, "(indirect_inlining) ");
1438 if (edge
->can_throw_external
)
1439 fprintf(f
, "(can throw external) ");
1442 fprintf (f
, "\n Calls: ");
1443 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1445 fprintf (f
, "%s/%i ", cgraph_node_asm_name (edge
->callee
),
1446 edge
->callee
->symbol
.order
);
1447 if (!edge
->inline_failed
)
1448 fprintf(f
, "(inlined) ");
1449 if (edge
->indirect_inlining_edge
)
1450 fprintf(f
, "(indirect_inlining) ");
1452 fprintf (f
, "("HOST_WIDEST_INT_PRINT_DEC
"x) ",
1453 (HOST_WIDEST_INT
)edge
->count
);
1454 if (edge
->frequency
)
1455 fprintf (f
, "(%.2f per call) ",
1456 edge
->frequency
/ (double)CGRAPH_FREQ_BASE
);
1457 if (edge
->can_throw_external
)
1458 fprintf(f
, "(can throw external) ");
1462 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
1463 indirect_calls_count
++;
1464 if (indirect_calls_count
)
1465 fprintf (f
, " Has %i outgoing edges for indirect calls.\n",
1466 indirect_calls_count
);
1470 /* Dump call graph node NODE to stderr. */
1473 debug_cgraph_node (struct cgraph_node
*node
)
1475 dump_cgraph_node (stderr
, node
);
1479 /* Dump the callgraph to file F. */
1482 dump_cgraph (FILE *f
)
1484 struct cgraph_node
*node
;
1486 fprintf (f
, "callgraph:\n\n");
1487 FOR_EACH_FUNCTION (node
)
1488 dump_cgraph_node (f
, node
);
1492 /* Dump the call graph to stderr. */
1497 dump_cgraph (stderr
);
1500 /* Return true when the DECL can possibly be inlined. */
1502 cgraph_function_possibly_inlined_p (tree decl
)
1504 if (!cgraph_global_info_ready
)
1505 return !DECL_UNINLINABLE (decl
);
1506 return DECL_POSSIBLY_INLINED (decl
);
1509 /* NODE is no longer nested function; update cgraph accordingly. */
1511 cgraph_unnest_node (struct cgraph_node
*node
)
1513 struct cgraph_node
**node2
= &node
->origin
->nested
;
1514 gcc_assert (node
->origin
);
1516 while (*node2
!= node
)
1517 node2
= &(*node2
)->next_nested
;
1518 *node2
= node
->next_nested
;
1519 node
->origin
= NULL
;
1522 /* Return function availability. See cgraph.h for description of individual
1525 cgraph_function_body_availability (struct cgraph_node
*node
)
1527 enum availability avail
;
1528 gcc_assert (cgraph_function_flags_ready
);
1529 if (!node
->analyzed
)
1530 avail
= AVAIL_NOT_AVAILABLE
;
1531 else if (node
->local
.local
)
1532 avail
= AVAIL_LOCAL
;
1533 else if (!node
->symbol
.externally_visible
)
1534 avail
= AVAIL_AVAILABLE
;
1535 /* Inline functions are safe to be analyzed even if their symbol can
1536 be overwritten at runtime. It is not meaningful to enforce any sane
1537 behaviour on replacing inline function by different body. */
1538 else if (DECL_DECLARED_INLINE_P (node
->symbol
.decl
))
1539 avail
= AVAIL_AVAILABLE
;
1541 /* If the function can be overwritten, return OVERWRITABLE. Take
1542 care at least of two notable extensions - the COMDAT functions
1543 used to share template instantiations in C++ (this is symmetric
1544 to code cp_cannot_inline_tree_fn and probably shall be shared and
1545 the inlinability hooks completely eliminated).
1547 ??? Does the C++ one definition rule allow us to always return
1548 AVAIL_AVAILABLE here? That would be good reason to preserve this
1551 else if (decl_replaceable_p (node
->symbol
.decl
)
1552 && !DECL_EXTERNAL (node
->symbol
.decl
))
1553 avail
= AVAIL_OVERWRITABLE
;
1554 else avail
= AVAIL_AVAILABLE
;
1559 /* Worker for cgraph_node_can_be_local_p. */
1561 cgraph_node_cannot_be_local_p_1 (struct cgraph_node
*node
,
1562 void *data ATTRIBUTE_UNUSED
)
1564 return !(!node
->symbol
.force_output
1565 && ((DECL_COMDAT (node
->symbol
.decl
)
1566 && !node
->symbol
.same_comdat_group
)
1567 || !node
->symbol
.externally_visible
));
1570 /* Return true if NODE can be made local for API change.
1571 Extern inline functions and C++ COMDAT functions can be made local
1572 at the expense of possible code size growth if function is used in multiple
1573 compilation units. */
1575 cgraph_node_can_be_local_p (struct cgraph_node
*node
)
1577 return (!node
->symbol
.address_taken
1578 && !cgraph_for_node_and_aliases (node
,
1579 cgraph_node_cannot_be_local_p_1
,
1583 /* Call calback on NODE, thunks and aliases associated to NODE.
1584 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1588 cgraph_for_node_thunks_and_aliases (struct cgraph_node
*node
,
1589 bool (*callback
) (struct cgraph_node
*, void *),
1591 bool include_overwritable
)
1593 struct cgraph_edge
*e
;
1595 struct ipa_ref
*ref
;
1597 if (callback (node
, data
))
1599 for (e
= node
->callers
; e
; e
= e
->next_caller
)
1600 if (e
->caller
->thunk
.thunk_p
1601 && (include_overwritable
1602 || cgraph_function_body_availability (e
->caller
) > AVAIL_OVERWRITABLE
))
1603 if (cgraph_for_node_thunks_and_aliases (e
->caller
, callback
, data
,
1604 include_overwritable
))
1606 for (i
= 0; ipa_ref_list_referring_iterate (&node
->symbol
.ref_list
, i
, ref
); i
++)
1607 if (ref
->use
== IPA_REF_ALIAS
)
1609 struct cgraph_node
*alias
= ipa_ref_referring_node (ref
);
1610 if (include_overwritable
1611 || cgraph_function_body_availability (alias
) > AVAIL_OVERWRITABLE
)
1612 if (cgraph_for_node_thunks_and_aliases (alias
, callback
, data
,
1613 include_overwritable
))
1619 /* Call calback on NODE and aliases associated to NODE.
1620 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1624 cgraph_for_node_and_aliases (struct cgraph_node
*node
,
1625 bool (*callback
) (struct cgraph_node
*, void *),
1627 bool include_overwritable
)
1630 struct ipa_ref
*ref
;
1632 if (callback (node
, data
))
1634 for (i
= 0; ipa_ref_list_referring_iterate (&node
->symbol
.ref_list
, i
, ref
); i
++)
1635 if (ref
->use
== IPA_REF_ALIAS
)
1637 struct cgraph_node
*alias
= ipa_ref_referring_node (ref
);
1638 if (include_overwritable
1639 || cgraph_function_body_availability (alias
) > AVAIL_OVERWRITABLE
)
1640 if (cgraph_for_node_and_aliases (alias
, callback
, data
,
1641 include_overwritable
))
1647 /* Worker to bring NODE local. */
1650 cgraph_make_node_local_1 (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
1652 gcc_checking_assert (cgraph_node_can_be_local_p (node
));
1653 if (DECL_COMDAT (node
->symbol
.decl
) || DECL_EXTERNAL (node
->symbol
.decl
))
1655 symtab_make_decl_local (node
->symbol
.decl
);
1657 node
->symbol
.externally_visible
= false;
1658 node
->local
.local
= true;
1659 node
->symbol
.resolution
= LDPR_PREVAILING_DEF_IRONLY
;
1660 gcc_assert (cgraph_function_body_availability (node
) == AVAIL_LOCAL
);
1665 /* Bring NODE local. */
1668 cgraph_make_node_local (struct cgraph_node
*node
)
1670 cgraph_for_node_thunks_and_aliases (node
, cgraph_make_node_local_1
,
1674 /* Worker to set nothrow flag. */
1677 cgraph_set_nothrow_flag_1 (struct cgraph_node
*node
, void *data
)
1679 struct cgraph_edge
*e
;
1681 TREE_NOTHROW (node
->symbol
.decl
) = data
!= NULL
;
1684 for (e
= node
->callers
; e
; e
= e
->next_caller
)
1685 e
->can_throw_external
= false;
1689 /* Set TREE_NOTHROW on NODE's decl and on aliases of NODE
1690 if any to NOTHROW. */
1693 cgraph_set_nothrow_flag (struct cgraph_node
*node
, bool nothrow
)
1695 cgraph_for_node_thunks_and_aliases (node
, cgraph_set_nothrow_flag_1
,
1696 (void *)(size_t)nothrow
, false);
1699 /* Worker to set const flag. */
1702 cgraph_set_const_flag_1 (struct cgraph_node
*node
, void *data
)
1704 /* Static constructors and destructors without a side effect can be
1706 if (data
&& !((size_t)data
& 2))
1708 if (DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
))
1709 DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
) = 0;
1710 if (DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
))
1711 DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
) = 0;
1713 TREE_READONLY (node
->symbol
.decl
) = data
!= NULL
;
1714 DECL_LOOPING_CONST_OR_PURE_P (node
->symbol
.decl
) = ((size_t)data
& 2) != 0;
1718 /* Set TREE_READONLY on NODE's decl and on aliases of NODE
1719 if any to READONLY. */
1722 cgraph_set_const_flag (struct cgraph_node
*node
, bool readonly
, bool looping
)
1724 cgraph_for_node_thunks_and_aliases (node
, cgraph_set_const_flag_1
,
1725 (void *)(size_t)(readonly
+ (int)looping
* 2),
1729 /* Worker to set pure flag. */
1732 cgraph_set_pure_flag_1 (struct cgraph_node
*node
, void *data
)
1734 /* Static pureructors and destructors without a side effect can be
1736 if (data
&& !((size_t)data
& 2))
1738 if (DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
))
1739 DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
) = 0;
1740 if (DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
))
1741 DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
) = 0;
1743 DECL_PURE_P (node
->symbol
.decl
) = data
!= NULL
;
1744 DECL_LOOPING_CONST_OR_PURE_P (node
->symbol
.decl
) = ((size_t)data
& 2) != 0;
1748 /* Set DECL_PURE_P on NODE's decl and on aliases of NODE
1752 cgraph_set_pure_flag (struct cgraph_node
*node
, bool pure
, bool looping
)
1754 cgraph_for_node_thunks_and_aliases (node
, cgraph_set_pure_flag_1
,
1755 (void *)(size_t)(pure
+ (int)looping
* 2),
1759 /* Data used by cgraph_propagate_frequency. */
1761 struct cgraph_propagate_frequency_data
1763 bool maybe_unlikely_executed
;
1764 bool maybe_executed_once
;
1765 bool only_called_at_startup
;
1766 bool only_called_at_exit
;
1769 /* Worker for cgraph_propagate_frequency_1. */
1772 cgraph_propagate_frequency_1 (struct cgraph_node
*node
, void *data
)
1774 struct cgraph_propagate_frequency_data
*d
;
1775 struct cgraph_edge
*edge
;
1777 d
= (struct cgraph_propagate_frequency_data
*)data
;
1778 for (edge
= node
->callers
;
1779 edge
&& (d
->maybe_unlikely_executed
|| d
->maybe_executed_once
1780 || d
->only_called_at_startup
|| d
->only_called_at_exit
);
1781 edge
= edge
->next_caller
)
1783 if (edge
->caller
!= node
)
1785 d
->only_called_at_startup
&= edge
->caller
->only_called_at_startup
;
1786 /* It makes sense to put main() together with the static constructors.
1787 It will be executed for sure, but rest of functions called from
1788 main are definitely not at startup only. */
1789 if (MAIN_NAME_P (DECL_NAME (edge
->caller
->symbol
.decl
)))
1790 d
->only_called_at_startup
= 0;
1791 d
->only_called_at_exit
&= edge
->caller
->only_called_at_exit
;
1793 if (!edge
->frequency
)
1795 switch (edge
->caller
->frequency
)
1797 case NODE_FREQUENCY_UNLIKELY_EXECUTED
:
1799 case NODE_FREQUENCY_EXECUTED_ONCE
:
1800 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1801 fprintf (dump_file
, " Called by %s that is executed once\n",
1802 cgraph_node_name (edge
->caller
));
1803 d
->maybe_unlikely_executed
= false;
1804 if (inline_edge_summary (edge
)->loop_depth
)
1806 d
->maybe_executed_once
= false;
1807 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1808 fprintf (dump_file
, " Called in loop\n");
1811 case NODE_FREQUENCY_HOT
:
1812 case NODE_FREQUENCY_NORMAL
:
1813 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1814 fprintf (dump_file
, " Called by %s that is normal or hot\n",
1815 cgraph_node_name (edge
->caller
));
1816 d
->maybe_unlikely_executed
= false;
1817 d
->maybe_executed_once
= false;
1821 return edge
!= NULL
;
1824 /* See if the frequency of NODE can be updated based on frequencies of its
1827 cgraph_propagate_frequency (struct cgraph_node
*node
)
1829 struct cgraph_propagate_frequency_data d
= {true, true, true, true};
1830 bool changed
= false;
1832 if (!node
->local
.local
)
1834 gcc_assert (node
->analyzed
);
1835 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1836 fprintf (dump_file
, "Processing frequency %s\n", cgraph_node_name (node
));
1838 cgraph_for_node_and_aliases (node
, cgraph_propagate_frequency_1
, &d
, true);
1840 if ((d
.only_called_at_startup
&& !d
.only_called_at_exit
)
1841 && !node
->only_called_at_startup
)
1843 node
->only_called_at_startup
= true;
1845 fprintf (dump_file
, "Node %s promoted to only called at startup.\n",
1846 cgraph_node_name (node
));
1849 if ((d
.only_called_at_exit
&& !d
.only_called_at_startup
)
1850 && !node
->only_called_at_exit
)
1852 node
->only_called_at_exit
= true;
1854 fprintf (dump_file
, "Node %s promoted to only called at exit.\n",
1855 cgraph_node_name (node
));
1858 /* These come either from profile or user hints; never update them. */
1859 if (node
->frequency
== NODE_FREQUENCY_HOT
1860 || node
->frequency
== NODE_FREQUENCY_UNLIKELY_EXECUTED
)
1862 if (d
.maybe_unlikely_executed
)
1864 node
->frequency
= NODE_FREQUENCY_UNLIKELY_EXECUTED
;
1866 fprintf (dump_file
, "Node %s promoted to unlikely executed.\n",
1867 cgraph_node_name (node
));
1870 else if (d
.maybe_executed_once
&& node
->frequency
!= NODE_FREQUENCY_EXECUTED_ONCE
)
1872 node
->frequency
= NODE_FREQUENCY_EXECUTED_ONCE
;
1874 fprintf (dump_file
, "Node %s promoted to executed once.\n",
1875 cgraph_node_name (node
));
1881 /* Return true when NODE can not return or throw and thus
1882 it is safe to ignore its side effects for IPA analysis. */
1885 cgraph_node_cannot_return (struct cgraph_node
*node
)
1887 int flags
= flags_from_decl_or_type (node
->symbol
.decl
);
1888 if (!flag_exceptions
)
1889 return (flags
& ECF_NORETURN
) != 0;
1891 return ((flags
& (ECF_NORETURN
| ECF_NOTHROW
))
1892 == (ECF_NORETURN
| ECF_NOTHROW
));
1895 /* Return true when call of E can not lead to return from caller
1896 and thus it is safe to ignore its side effects for IPA analysis
1897 when computing side effects of the caller.
1898 FIXME: We could actually mark all edges that have no reaching
1899 patch to EXIT_BLOCK_PTR or throw to get better results. */
1901 cgraph_edge_cannot_lead_to_return (struct cgraph_edge
*e
)
1903 if (cgraph_node_cannot_return (e
->caller
))
1905 if (e
->indirect_unknown_callee
)
1907 int flags
= e
->indirect_info
->ecf_flags
;
1908 if (!flag_exceptions
)
1909 return (flags
& ECF_NORETURN
) != 0;
1911 return ((flags
& (ECF_NORETURN
| ECF_NOTHROW
))
1912 == (ECF_NORETURN
| ECF_NOTHROW
));
1915 return cgraph_node_cannot_return (e
->callee
);
1918 /* Return true when function NODE can be removed from callgraph
1919 if all direct calls are eliminated. */
1922 cgraph_can_remove_if_no_direct_calls_and_refs_p (struct cgraph_node
*node
)
1924 gcc_assert (!node
->global
.inlined_to
);
1925 /* Extern inlines can always go, we will use the external definition. */
1926 if (DECL_EXTERNAL (node
->symbol
.decl
))
1928 /* When function is needed, we can not remove it. */
1929 if (node
->symbol
.force_output
|| node
->symbol
.used_from_other_partition
)
1931 if (DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
)
1932 || DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
))
1934 /* Only COMDAT functions can be removed if externally visible. */
1935 if (node
->symbol
.externally_visible
1936 && (!DECL_COMDAT (node
->symbol
.decl
)
1937 || symtab_used_from_object_file_p ((symtab_node
) node
)))
1942 /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
1945 nonremovable_p (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
1947 return !cgraph_can_remove_if_no_direct_calls_and_refs_p (node
);
1950 /* Return true when function NODE and its aliases can be removed from callgraph
1951 if all direct calls are eliminated. */
1954 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node
*node
)
1956 /* Extern inlines can always go, we will use the external definition. */
1957 if (DECL_EXTERNAL (node
->symbol
.decl
))
1959 if (node
->symbol
.address_taken
)
1961 return !cgraph_for_node_and_aliases (node
, nonremovable_p
, NULL
, true);
1964 /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
1967 used_from_object_file_p (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
1969 return symtab_used_from_object_file_p ((symtab_node
) node
);
1972 /* Return true when function NODE can be expected to be removed
1973 from program when direct calls in this compilation unit are removed.
1975 As a special case COMDAT functions are
1976 cgraph_can_remove_if_no_direct_calls_p while the are not
1977 cgraph_only_called_directly_p (it is possible they are called from other
1980 This function behaves as cgraph_only_called_directly_p because eliminating
1981 all uses of COMDAT function does not make it necessarily disappear from
1982 the program unless we are compiling whole program or we do LTO. In this
1983 case we know we win since dynamic linking will not really discard the
1984 linkonce section. */
1987 cgraph_will_be_removed_from_program_if_no_direct_calls (struct cgraph_node
*node
)
1989 gcc_assert (!node
->global
.inlined_to
);
1990 if (cgraph_for_node_and_aliases (node
, used_from_object_file_p
, NULL
, true))
1992 if (!in_lto_p
&& !flag_whole_program
)
1993 return cgraph_only_called_directly_p (node
);
1996 if (DECL_EXTERNAL (node
->symbol
.decl
))
1998 return cgraph_can_remove_if_no_direct_calls_p (node
);
2003 /* Worker for cgraph_only_called_directly_p. */
2006 cgraph_not_only_called_directly_p_1 (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
2008 return !cgraph_only_called_directly_or_aliased_p (node
);
2011 /* Return true when function NODE and all its aliases are only called
2013 i.e. it is not externally visible, address was not taken and
2014 it is not used in any other non-standard way. */
2017 cgraph_only_called_directly_p (struct cgraph_node
*node
)
2019 gcc_assert (cgraph_function_or_thunk_node (node
, NULL
) == node
);
2020 return !cgraph_for_node_and_aliases (node
, cgraph_not_only_called_directly_p_1
,
2025 /* Collect all callers of NODE. Worker for collect_callers_of_node. */
2028 collect_callers_of_node_1 (struct cgraph_node
*node
, void *data
)
2030 VEC (cgraph_edge_p
, heap
) ** redirect_callers
= (VEC (cgraph_edge_p
, heap
) **)data
;
2031 struct cgraph_edge
*cs
;
2032 enum availability avail
;
2033 cgraph_function_or_thunk_node (node
, &avail
);
2035 if (avail
> AVAIL_OVERWRITABLE
)
2036 for (cs
= node
->callers
; cs
!= NULL
; cs
= cs
->next_caller
)
2037 if (!cs
->indirect_inlining_edge
)
2038 VEC_safe_push (cgraph_edge_p
, heap
, *redirect_callers
, cs
);
2042 /* Collect all callers of NODE and its aliases that are known to lead to NODE
2043 (i.e. are not overwritable). */
2045 VEC (cgraph_edge_p
, heap
) *
2046 collect_callers_of_node (struct cgraph_node
*node
)
2048 VEC (cgraph_edge_p
, heap
) * redirect_callers
= NULL
;
2049 cgraph_for_node_and_aliases (node
, collect_callers_of_node_1
,
2050 &redirect_callers
, false);
2051 return redirect_callers
;
2054 /* Return TRUE if NODE2 is equivalent to NODE or its clone. */
2056 clone_of_p (struct cgraph_node
*node
, struct cgraph_node
*node2
)
2058 node
= cgraph_function_or_thunk_node (node
, NULL
);
2059 node2
= cgraph_function_or_thunk_node (node2
, NULL
);
2060 while (node
!= node2
&& node2
)
2061 node2
= node2
->clone_of
;
2062 return node2
!= NULL
;
2065 /* Verify edge E count and frequency. */
2068 verify_edge_count_and_frequency (struct cgraph_edge
*e
)
2070 bool error_found
= false;
2073 error ("caller edge count is negative");
2076 if (e
->frequency
< 0)
2078 error ("caller edge frequency is negative");
2081 if (e
->frequency
> CGRAPH_FREQ_MAX
)
2083 error ("caller edge frequency is too large");
2086 if (gimple_has_body_p (e
->caller
->symbol
.decl
)
2087 && !e
->caller
->global
.inlined_to
2088 /* FIXME: Inline-analysis sets frequency to 0 when edge is optimized out.
2089 Remove this once edges are actually removed from the function at that time. */
2091 || (inline_edge_summary_vec
2092 && ((VEC_length(inline_edge_summary_t
, inline_edge_summary_vec
)
2093 <= (unsigned) e
->uid
)
2094 || !inline_edge_summary (e
)->predicate
)))
2096 != compute_call_stmt_bb_frequency (e
->caller
->symbol
.decl
,
2097 gimple_bb (e
->call_stmt
))))
2099 error ("caller edge frequency %i does not match BB frequency %i",
2101 compute_call_stmt_bb_frequency (e
->caller
->symbol
.decl
,
2102 gimple_bb (e
->call_stmt
)));
2108 /* Switch to THIS_CFUN if needed and print STMT to stderr. */
2110 cgraph_debug_gimple_stmt (struct function
*this_cfun
, gimple stmt
)
2112 /* debug_gimple_stmt needs correct cfun */
2113 if (cfun
!= this_cfun
)
2114 set_cfun (this_cfun
);
2115 debug_gimple_stmt (stmt
);
2118 /* Verify that call graph edge E corresponds to DECL from the associated
2119 statement. Return true if the verification should fail. */
2122 verify_edge_corresponds_to_fndecl (struct cgraph_edge
*e
, tree decl
)
2124 struct cgraph_node
*node
;
2126 if (!decl
|| e
->callee
->global
.inlined_to
)
2128 node
= cgraph_get_node (decl
);
2130 /* We do not know if a node from a different partition is an alias or what it
2131 aliases and therefore cannot do the former_clone_of check reliably. */
2132 if (!node
|| node
->symbol
.in_other_partition
)
2134 node
= cgraph_function_or_thunk_node (node
, NULL
);
2136 if ((e
->callee
->former_clone_of
!= node
->symbol
.decl
2137 && (!node
->same_body_alias
2138 || e
->callee
->former_clone_of
!= node
->thunk
.alias
))
2139 /* IPA-CP sometimes redirect edge to clone and then back to the former
2140 function. This ping-pong has to go, eventually. */
2141 && (node
!= cgraph_function_or_thunk_node (e
->callee
, NULL
))
2142 && !clone_of_p (node
, e
->callee
)
2143 /* If decl is a same body alias of some other decl, allow e->callee to be
2144 a clone of a clone of that other decl too. */
2145 && (!node
->same_body_alias
2146 || !clone_of_p (cgraph_get_node (node
->thunk
.alias
), e
->callee
)))
2152 /* Verify cgraph nodes of given cgraph node. */
2154 verify_cgraph_node (struct cgraph_node
*node
)
2156 struct cgraph_edge
*e
;
2157 struct function
*this_cfun
= DECL_STRUCT_FUNCTION (node
->symbol
.decl
);
2158 basic_block this_block
;
2159 gimple_stmt_iterator gsi
;
2160 bool error_found
= false;
2165 timevar_push (TV_CGRAPH_VERIFY
);
2166 error_found
|= verify_symtab_base ((symtab_node
) node
);
2167 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2170 error ("aux field set for edge %s->%s",
2171 identifier_to_locale (cgraph_node_name (e
->caller
)),
2172 identifier_to_locale (cgraph_node_name (e
->callee
)));
2175 if (node
->count
< 0)
2177 error ("execution count is negative");
2180 if (node
->global
.inlined_to
&& node
->symbol
.same_comdat_group
)
2182 error ("inline clone in same comdat group list");
2185 if (node
->global
.inlined_to
&& node
->symbol
.externally_visible
)
2187 error ("externally visible inline clone");
2190 if (node
->global
.inlined_to
&& node
->symbol
.address_taken
)
2192 error ("inline clone with address taken");
2195 if (node
->global
.inlined_to
&& node
->symbol
.force_output
)
2197 error ("inline clone is forced to output");
2200 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2204 error ("aux field set for indirect edge from %s",
2205 identifier_to_locale (cgraph_node_name (e
->caller
)));
2208 if (!e
->indirect_unknown_callee
2209 || !e
->indirect_info
)
2211 error ("An indirect edge from %s is not marked as indirect or has "
2212 "associated indirect_info, the corresponding statement is: ",
2213 identifier_to_locale (cgraph_node_name (e
->caller
)));
2214 cgraph_debug_gimple_stmt (this_cfun
, e
->call_stmt
);
2218 for (e
= node
->callers
; e
; e
= e
->next_caller
)
2220 if (verify_edge_count_and_frequency (e
))
2222 if (!e
->inline_failed
)
2224 if (node
->global
.inlined_to
2225 != (e
->caller
->global
.inlined_to
2226 ? e
->caller
->global
.inlined_to
: e
->caller
))
2228 error ("inlined_to pointer is wrong");
2231 if (node
->callers
->next_caller
)
2233 error ("multiple inline callers");
2238 if (node
->global
.inlined_to
)
2240 error ("inlined_to pointer set for noninline callers");
2244 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2245 if (verify_edge_count_and_frequency (e
))
2247 if (!node
->callers
&& node
->global
.inlined_to
)
2249 error ("inlined_to pointer is set but no predecessors found");
2252 if (node
->global
.inlined_to
== node
)
2254 error ("inlined_to pointer refers to itself");
2260 struct cgraph_node
*n
;
2261 for (n
= node
->clone_of
->clones
; n
; n
= n
->next_sibling_clone
)
2266 error ("node has wrong clone_of");
2272 struct cgraph_node
*n
;
2273 for (n
= node
->clones
; n
; n
= n
->next_sibling_clone
)
2274 if (n
->clone_of
!= node
)
2278 error ("node has wrong clone list");
2282 if ((node
->prev_sibling_clone
|| node
->next_sibling_clone
) && !node
->clone_of
)
2284 error ("node is in clone list but it is not clone");
2287 if (!node
->prev_sibling_clone
&& node
->clone_of
&& node
->clone_of
->clones
!= node
)
2289 error ("node has wrong prev_clone pointer");
2292 if (node
->prev_sibling_clone
&& node
->prev_sibling_clone
->next_sibling_clone
!= node
)
2294 error ("double linked list of clones corrupted");
2298 if (node
->analyzed
&& node
->alias
)
2300 bool ref_found
= false;
2302 struct ipa_ref
*ref
;
2306 error ("Alias has call edges");
2309 for (i
= 0; ipa_ref_list_reference_iterate (&node
->symbol
.ref_list
,
2311 if (ref
->use
!= IPA_REF_ALIAS
)
2313 error ("Alias has non-alias reference");
2318 error ("Alias has more than one alias reference");
2325 error ("Analyzed alias has no reference");
2329 if (node
->analyzed
&& node
->thunk
.thunk_p
)
2333 error ("No edge out of thunk node");
2336 else if (node
->callees
->next_callee
)
2338 error ("More than one edge out of thunk node");
2341 if (gimple_has_body_p (node
->symbol
.decl
))
2343 error ("Thunk is not supposed to have body");
2347 else if (node
->analyzed
&& gimple_has_body_p (node
->symbol
.decl
)
2348 && !TREE_ASM_WRITTEN (node
->symbol
.decl
)
2349 && (!DECL_EXTERNAL (node
->symbol
.decl
) || node
->global
.inlined_to
)
2354 /* The nodes we're interested in are never shared, so walk
2355 the tree ignoring duplicates. */
2356 struct pointer_set_t
*visited_nodes
= pointer_set_create ();
2357 /* Reach the trees by walking over the CFG, and note the
2358 enclosing basic-blocks in the call edges. */
2359 FOR_EACH_BB_FN (this_block
, this_cfun
)
2360 for (gsi
= gsi_start_bb (this_block
);
2364 gimple stmt
= gsi_stmt (gsi
);
2365 if (is_gimple_call (stmt
))
2367 struct cgraph_edge
*e
= cgraph_edge (node
, stmt
);
2368 tree decl
= gimple_call_fndecl (stmt
);
2373 error ("shared call_stmt:");
2374 cgraph_debug_gimple_stmt (this_cfun
, stmt
);
2377 if (!e
->indirect_unknown_callee
)
2379 if (verify_edge_corresponds_to_fndecl (e
, decl
))
2381 error ("edge points to wrong declaration:");
2382 debug_tree (e
->callee
->symbol
.decl
);
2383 fprintf (stderr
," Instead of:");
2390 error ("an indirect edge with unknown callee "
2391 "corresponding to a call_stmt with "
2392 "a known declaration:");
2394 cgraph_debug_gimple_stmt (this_cfun
, e
->call_stmt
);
2400 error ("missing callgraph edge for call stmt:");
2401 cgraph_debug_gimple_stmt (this_cfun
, stmt
);
2406 pointer_set_destroy (visited_nodes
);
2409 /* No CFG available?! */
2412 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2416 error ("edge %s->%s has no corresponding call_stmt",
2417 identifier_to_locale (cgraph_node_name (e
->caller
)),
2418 identifier_to_locale (cgraph_node_name (e
->callee
)));
2419 cgraph_debug_gimple_stmt (this_cfun
, e
->call_stmt
);
2424 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2428 error ("an indirect edge from %s has no corresponding call_stmt",
2429 identifier_to_locale (cgraph_node_name (e
->caller
)));
2430 cgraph_debug_gimple_stmt (this_cfun
, e
->call_stmt
);
2438 dump_cgraph_node (stderr
, node
);
2439 internal_error ("verify_cgraph_node failed");
2441 timevar_pop (TV_CGRAPH_VERIFY
);
2444 /* Verify whole cgraph structure. */
2446 verify_cgraph (void)
2448 struct cgraph_node
*node
;
2453 FOR_EACH_FUNCTION (node
)
2454 verify_cgraph_node (node
);
2456 #include "gt-cgraph.h"