1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
3 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/>. */
26 #include "plugin-api.h"
29 #include "basic-block.h"
33 /* Symbol table consists of functions and variables.
34 TODO: add labels, constant pool and aliases. */
42 /* Base of all entries in the symbol table.
43 The symtab_node is inherited by cgraph and varpol nodes. */
44 struct GTY(()) symtab_node_base
46 /* Type of the symbol. */
47 ENUM_BITFIELD (symtab_type
) type
: 8;
49 /* The symbols resolution. */
50 ENUM_BITFIELD (ld_plugin_symbol_resolution
) resolution
: 8;
52 /* Set when function has address taken.
53 In current implementation it imply needed flag. */
54 unsigned address_taken
: 1;
55 /* Set when variable is used from other LTRANS partition. */
56 unsigned used_from_other_partition
: 1;
57 /* Set when function is available in the other LTRANS partition.
58 During WPA output it is used to mark nodes that are present in
59 multiple partitions. */
60 unsigned in_other_partition
: 1;
61 /* Set when function is visible by other units. */
62 unsigned externally_visible
: 1;
63 /* Needed variables might become dead by optimization. This flag
64 forces the variable to be output even if it appears dead otherwise. */
65 unsigned force_output
: 1;
67 /* Ordering of all symtab entries. */
72 /* Vectors of referring and referenced entities. */
73 struct ipa_ref_list ref_list
;
75 /* Circular list of nodes in the same comdat group if non-NULL. */
76 symtab_node same_comdat_group
;
78 /* File stream where this node is being written to. */
79 struct lto_file_decl_data
* lto_file_data
;
81 /* Linked list of symbol table entries starting with symtab_nodes. */
84 /* Linked list of symbols with the same asm name. There may be multiple
85 entries for single symbol name in the case of LTO resolutions,
86 existence of inline clones, or duplicated declaration. The last case
87 is a long standing bug frontends and builtin handling. */
88 symtab_node next_sharing_asm_name
;
89 symtab_node previous_sharing_asm_name
;
96 /* Not yet set by cgraph_function_body_availability. */
98 /* Function body/variable initializer is unknown. */
100 /* Function body/variable initializer is known but might be replaced
101 by a different one from other compilation unit and thus needs to
102 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
103 arbitrary side effects on escaping variables and functions, while
104 like AVAILABLE it might access static variables. */
106 /* Function body/variable initializer is known and will be used in final
109 /* Function body/variable initializer is known and all it's uses are explicitly
110 visible within current unit (ie it's address is never taken and it is not
111 exported to other units).
112 Currently used only for functions. */
116 /* This is the information that is put into the cgraph local structure
117 to recover a function. */
118 struct lto_file_decl_data
;
120 extern const char * const cgraph_availability_names
[];
121 extern const char * const ld_plugin_symbol_resolution_names
[];
123 /* Information about thunk, used only for same body aliases. */
125 struct GTY(()) cgraph_thunk_info
{
126 /* Information about the thunk. */
127 HOST_WIDE_INT fixed_offset
;
128 HOST_WIDE_INT virtual_value
;
131 bool virtual_offset_p
;
132 /* Set to true when alias node is thunk. */
136 /* Information about the function collected locally.
137 Available after function is analyzed. */
139 struct GTY(()) cgraph_local_info
{
140 /* Set when function function is visible in current compilation unit only
141 and its address is never taken. */
144 /* Set once it has been finalized so we consider it to be output. */
145 unsigned finalized
: 1;
147 /* False when there is something makes versioning impossible. */
148 unsigned versionable
: 1;
150 /* False when function calling convention and signature can not be changed.
151 This is the case when __builtin_apply_args is used. */
152 unsigned can_change_signature
: 1;
154 /* True when the function has been originally extern inline, but it is
156 unsigned redefined_extern_inline
: 1;
158 /* True if the function may enter serial irrevocable mode. */
159 unsigned tm_may_enter_irr
: 1;
162 /* Information about the function that needs to be computed globally
163 once compilation is finished. Available only with -funit-at-a-time. */
165 struct GTY(()) cgraph_global_info
{
166 /* For inline clones this points to the function they will be
168 struct cgraph_node
*inlined_to
;
171 /* Information about the function that is propagated by the RTL backend.
172 Available only for functions that has been already assembled. */
174 struct GTY(()) cgraph_rtl_info
{
175 unsigned int preferred_incoming_stack_boundary
;
178 /* Represent which DECL tree (or reference to such tree)
179 will be replaced by another tree while versioning. */
180 struct GTY(()) ipa_replace_map
182 /* The tree that will be replaced. */
184 /* The new (replacing) tree. */
186 /* Parameter number to replace, when old_tree is NULL. */
188 /* True when a substitution should be done, false otherwise. */
190 /* True when we replace a reference to old_tree. */
193 typedef struct ipa_replace_map
*ipa_replace_map_p
;
194 DEF_VEC_P(ipa_replace_map_p
);
195 DEF_VEC_ALLOC_P(ipa_replace_map_p
,gc
);
197 struct GTY(()) cgraph_clone_info
199 VEC(ipa_replace_map_p
,gc
)* tree_map
;
201 bitmap combined_args_to_skip
;
205 /* The cgraph data structure.
206 Each function decl has assigned cgraph_node listing callees and callers. */
208 struct GTY(()) cgraph_node
{
209 struct symtab_node_base symbol
;
210 struct cgraph_edge
*callees
;
211 struct cgraph_edge
*callers
;
212 /* List of edges representing indirect calls with a yet undetermined
214 struct cgraph_edge
*indirect_calls
;
215 /* For nested functions points to function the node is nested in. */
217 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
219 /* Points to first nested function, if any. */
221 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
223 /* Pointer to the next function with same origin, if any. */
225 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
227 /* Pointer to the next clone. */
228 struct cgraph_node
*next_sibling_clone
;
229 struct cgraph_node
*prev_sibling_clone
;
230 struct cgraph_node
*clones
;
231 struct cgraph_node
*clone_of
;
232 /* For functions with many calls sites it holds map from call expression
233 to the edge to speed up cgraph_edge function. */
234 htab_t
GTY((param_is (struct cgraph_edge
))) call_site_hash
;
235 /* Declaration node used to be clone of. */
236 tree former_clone_of
;
238 /* Interprocedural passes scheduled to have their transform functions
239 applied next time we execute local pass on them. We maintain it
240 per-function in order to allow IPA passes to introduce new functions. */
241 VEC(ipa_opt_pass
,heap
) * GTY((skip
)) ipa_transforms_to_apply
;
243 struct cgraph_local_info local
;
244 struct cgraph_global_info global
;
245 struct cgraph_rtl_info rtl
;
246 struct cgraph_clone_info clone
;
247 struct cgraph_thunk_info thunk
;
249 /* Expected number of executions: calculated in profile.c. */
251 /* How to scale counts at materialization time; used to merge
252 LTO units with different number of profile runs. */
253 int count_materialization_scale
;
254 /* Unique id of the node. */
257 /* Set when decl is an abstract function pointed to by the
258 ABSTRACT_DECL_ORIGIN of a reachable function. */
259 unsigned abstract_and_needed
: 1;
260 /* Set once the function is lowered (i.e. its CFG is built). */
261 unsigned lowered
: 1;
262 /* Set once the function has been instantiated and its callee
264 unsigned analyzed
: 1;
265 /* Set when function is scheduled to be processed by local passes. */
266 unsigned process
: 1;
267 /* Set for aliases once they got through assemble_alias. */
269 /* Set for aliases created as C++ same body aliases. */
270 unsigned same_body_alias
: 1;
271 /* How commonly executed the node is. Initialized during branch
272 probabilities pass. */
273 ENUM_BITFIELD (node_frequency
) frequency
: 2;
274 /* True when function can only be called at startup (from static ctor). */
275 unsigned only_called_at_startup
: 1;
276 /* True when function can only be called at startup (from static dtor). */
277 unsigned only_called_at_exit
: 1;
278 /* True when function is the transactional clone of a function which
279 is called only from inside transactions. */
280 /* ?? We should be able to remove this. We have enough bits in
281 cgraph to calculate it. */
282 unsigned tm_clone
: 1;
285 DEF_VEC_P(symtab_node
);
286 DEF_VEC_ALLOC_P(symtab_node
,heap
);
287 DEF_VEC_ALLOC_P(symtab_node
,gc
);
289 typedef struct cgraph_node
*cgraph_node_ptr
;
291 DEF_VEC_P(cgraph_node_ptr
);
292 DEF_VEC_ALLOC_P(cgraph_node_ptr
,heap
);
293 DEF_VEC_ALLOC_P(cgraph_node_ptr
,gc
);
295 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
296 can appear in multiple sets. */
297 struct cgraph_node_set_def
299 struct pointer_map_t
*map
;
300 VEC(cgraph_node_ptr
, heap
) *nodes
;
303 typedef struct varpool_node
*varpool_node_ptr
;
305 DEF_VEC_P(varpool_node_ptr
);
306 DEF_VEC_ALLOC_P(varpool_node_ptr
,heap
);
307 DEF_VEC_ALLOC_P(varpool_node_ptr
,gc
);
309 /* A varpool node set is a collection of varpool nodes. A varpool node
310 can appear in multiple sets. */
311 struct varpool_node_set_def
313 struct pointer_map_t
* map
;
314 VEC(varpool_node_ptr
, heap
) *nodes
;
317 typedef struct cgraph_node_set_def
*cgraph_node_set
;
319 DEF_VEC_P(cgraph_node_set
);
320 DEF_VEC_ALLOC_P(cgraph_node_set
,gc
);
321 DEF_VEC_ALLOC_P(cgraph_node_set
,heap
);
323 typedef struct varpool_node_set_def
*varpool_node_set
;
325 DEF_VEC_P(varpool_node_set
);
326 DEF_VEC_ALLOC_P(varpool_node_set
,gc
);
327 DEF_VEC_ALLOC_P(varpool_node_set
,heap
);
329 /* Iterator structure for cgraph node sets. */
334 } cgraph_node_set_iterator
;
336 /* Iterator structure for varpool node sets. */
339 varpool_node_set set
;
341 } varpool_node_set_iterator
;
343 #define DEFCIFCODE(code, string) CIF_ ## code,
344 /* Reasons for inlining failures. */
345 typedef enum cgraph_inline_failed_enum
{
346 #include "cif-code.def"
348 } cgraph_inline_failed_t
;
350 /* Structure containing additional information about an indirect call. */
352 struct GTY(()) cgraph_indirect_call_info
354 /* When polymorphic is set, this field contains offset where the object which
355 was actually used in the polymorphic resides within a larger structure.
356 If agg_contents is set, the field contains the offset within the aggregate
357 from which the address to call was loaded. */
358 HOST_WIDE_INT offset
;
359 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
360 HOST_WIDE_INT otr_token
;
361 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
363 /* Index of the parameter that is called. */
365 /* ECF flags determined from the caller. */
368 /* Set when the call is a virtual call with the parameter being the
369 associated object pointer rather than a simple direct call. */
370 unsigned polymorphic
: 1;
371 /* Set when the call is a call of a pointer loaded from contents of an
372 aggregate at offset. */
373 unsigned agg_contents
: 1;
374 /* When the previous bit is set, this one determines whether the destination
375 is loaded from a parameter passed by reference. */
379 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge
{
380 /* Expected number of executions: calculated in profile.c. */
382 struct cgraph_node
*caller
;
383 struct cgraph_node
*callee
;
384 struct cgraph_edge
*prev_caller
;
385 struct cgraph_edge
*next_caller
;
386 struct cgraph_edge
*prev_callee
;
387 struct cgraph_edge
*next_callee
;
389 /* Additional information about an indirect call. Not cleared when an edge
391 struct cgraph_indirect_call_info
*indirect_info
;
392 PTR
GTY ((skip (""))) aux
;
393 /* When equal to CIF_OK, inline this call. Otherwise, points to the
394 explanation why function was not inlined. */
395 cgraph_inline_failed_t inline_failed
;
396 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
397 when the function is serialized in. */
398 unsigned int lto_stmt_uid
;
399 /* Expected frequency of executions within the function.
400 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
401 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
403 /* Unique id of the edge. */
405 /* Whether this edge was made direct by indirect inlining. */
406 unsigned int indirect_inlining_edge
: 1;
407 /* Whether this edge describes an indirect call with an undetermined
409 unsigned int indirect_unknown_callee
: 1;
410 /* Whether this edge is still a dangling */
411 /* True if the corresponding CALL stmt cannot be inlined. */
412 unsigned int call_stmt_cannot_inline_p
: 1;
413 /* Can this call throw externally? */
414 unsigned int can_throw_external
: 1;
417 #define CGRAPH_FREQ_BASE 1000
418 #define CGRAPH_FREQ_MAX 100000
420 typedef struct cgraph_edge
*cgraph_edge_p
;
422 DEF_VEC_P(cgraph_edge_p
);
423 DEF_VEC_ALLOC_P(cgraph_edge_p
,heap
);
425 /* The varpool data structure.
426 Each static variable decl has assigned varpool_node. */
428 struct GTY(()) varpool_node
{
429 struct symtab_node_base symbol
;
430 /* For aliases points to declaration DECL is alias of. */
433 /* Set once the variable has been instantiated and its callee
435 unsigned analyzed
: 1;
436 /* Set once it has been finalized so we consider it to be output. */
437 unsigned finalized
: 1;
438 /* Set when variable is scheduled to be assembled. */
440 /* Set for aliases once they got through assemble_alias. Also set for
441 extra name aliases in varpool_extra_name_alias. */
443 unsigned extra_name_alias
: 1;
446 /* Every top level asm statement is put into a asm_node. */
448 struct GTY(()) asm_node
{
450 struct asm_node
*next
;
451 /* String for this asm node. */
453 /* Ordering of all cgraph nodes. */
457 /* Symbol table entry. */
458 union GTY((desc ("%h.symbol.type"), chain_next ("%h.symbol.next"),
459 chain_prev ("%h.symbol.previous"))) symtab_node_def
{
460 struct symtab_node_base
GTY ((tag ("SYMTAB_SYMBOL"))) symbol
;
461 /* To access the following fields,
462 use the use dyn_cast or as_a to obtain the concrete type. */
463 struct cgraph_node
GTY ((tag ("SYMTAB_FUNCTION"))) x_function
;
464 struct varpool_node
GTY ((tag ("SYMTAB_VARIABLE"))) x_variable
;
467 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
472 is_a_helper
<cgraph_node
>::test (symtab_node_def
*p
)
474 return p
->symbol
.type
== SYMTAB_FUNCTION
;
477 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
482 is_a_helper
<varpool_node
>::test (symtab_node_def
*p
)
484 return p
->symbol
.type
== SYMTAB_VARIABLE
;
487 extern GTY(()) symtab_node symtab_nodes
;
488 extern GTY(()) int cgraph_n_nodes
;
489 extern GTY(()) int cgraph_max_uid
;
490 extern GTY(()) int cgraph_edge_max_uid
;
491 extern bool cgraph_global_info_ready
;
494 /* Frontend is parsing and finalizing functions. */
495 CGRAPH_STATE_PARSING
,
496 /* Callgraph is being constructed. It is safe to add new functions. */
497 CGRAPH_STATE_CONSTRUCTION
,
498 /* Callgraph is built and IPA passes are being run. */
500 /* Callgraph is built and all functions are transformed to SSA form. */
501 CGRAPH_STATE_IPA_SSA
,
502 /* Functions are now ordered and being passed to RTL expanders. */
503 CGRAPH_STATE_EXPANSION
,
504 /* All cgraph expansion is done. */
505 CGRAPH_STATE_FINISHED
507 extern enum cgraph_state cgraph_state
;
508 extern bool cgraph_function_flags_ready
;
509 extern cgraph_node_set cgraph_new_nodes
;
511 extern GTY(()) struct asm_node
*asm_nodes
;
512 extern GTY(()) int symtab_order
;
513 extern bool same_body_aliases_done
;
516 void symtab_register_node (symtab_node
);
517 void symtab_unregister_node (symtab_node
);
518 void symtab_remove_node (symtab_node
);
519 symtab_node
symtab_get_node (const_tree
);
520 symtab_node
symtab_node_for_asm (const_tree asmname
);
521 const char * symtab_node_asm_name (symtab_node
);
522 const char * symtab_node_name (symtab_node
);
523 void symtab_insert_node_to_hashtable (symtab_node
);
524 void symtab_add_to_same_comdat_group (symtab_node
, symtab_node
);
525 void symtab_dissolve_same_comdat_group_list (symtab_node node
);
526 void dump_symtab (FILE *);
527 void debug_symtab (void);
528 void dump_symtab_node (FILE *, symtab_node
);
529 void debug_symtab_node (symtab_node
);
530 void dump_symtab_base (FILE *, symtab_node
);
531 void verify_symtab (void);
532 void verify_symtab_node (symtab_node
);
533 bool verify_symtab_base (symtab_node
);
534 bool symtab_used_from_object_file_p (symtab_node
);
535 void symtab_make_decl_local (tree
);
538 void dump_cgraph (FILE *);
539 void debug_cgraph (void);
540 void dump_cgraph_node (FILE *, struct cgraph_node
*);
541 void debug_cgraph_node (struct cgraph_node
*);
542 void cgraph_remove_edge (struct cgraph_edge
*);
543 void cgraph_remove_node (struct cgraph_node
*);
544 void cgraph_release_function_body (struct cgraph_node
*);
545 void cgraph_node_remove_callees (struct cgraph_node
*node
);
546 struct cgraph_edge
*cgraph_create_edge (struct cgraph_node
*,
547 struct cgraph_node
*,
548 gimple
, gcov_type
, int);
549 struct cgraph_edge
*cgraph_create_indirect_edge (struct cgraph_node
*, gimple
,
550 int, gcov_type
, int);
551 struct cgraph_indirect_call_info
*cgraph_allocate_init_indirect_info (void);
552 struct cgraph_node
* cgraph_create_node (tree
);
553 struct cgraph_node
* cgraph_create_empty_node (void);
554 struct cgraph_node
* cgraph_get_create_node (tree
);
555 struct cgraph_node
* cgraph_same_body_alias (struct cgraph_node
*, tree
, tree
);
556 struct cgraph_node
* cgraph_add_thunk (struct cgraph_node
*, tree
, tree
, bool, HOST_WIDE_INT
,
557 HOST_WIDE_INT
, tree
, tree
);
558 struct cgraph_node
*cgraph_node_for_asm (tree
);
559 struct cgraph_edge
*cgraph_edge (struct cgraph_node
*, gimple
);
560 void cgraph_set_call_stmt (struct cgraph_edge
*, gimple
);
561 void cgraph_update_edges_for_call_stmt (gimple
, tree
, gimple
);
562 struct cgraph_local_info
*cgraph_local_info (tree
);
563 struct cgraph_global_info
*cgraph_global_info (tree
);
564 struct cgraph_rtl_info
*cgraph_rtl_info (tree
);
565 struct cgraph_node
*cgraph_create_function_alias (tree
, tree
);
566 void cgraph_call_node_duplication_hooks (struct cgraph_node
*,
567 struct cgraph_node
*);
568 void cgraph_call_edge_duplication_hooks (struct cgraph_edge
*,
569 struct cgraph_edge
*);
571 void cgraph_redirect_edge_callee (struct cgraph_edge
*, struct cgraph_node
*);
572 void cgraph_make_edge_direct (struct cgraph_edge
*, struct cgraph_node
*);
573 bool cgraph_only_called_directly_p (struct cgraph_node
*);
575 bool cgraph_function_possibly_inlined_p (tree
);
576 void cgraph_unnest_node (struct cgraph_node
*);
578 enum availability
cgraph_function_body_availability (struct cgraph_node
*);
579 void cgraph_add_new_function (tree
, bool);
580 const char* cgraph_inline_failed_string (cgraph_inline_failed_t
);
582 void cgraph_set_nothrow_flag (struct cgraph_node
*, bool);
583 void cgraph_set_const_flag (struct cgraph_node
*, bool, bool);
584 void cgraph_set_pure_flag (struct cgraph_node
*, bool, bool);
585 bool cgraph_node_cannot_return (struct cgraph_node
*);
586 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge
*);
587 bool cgraph_will_be_removed_from_program_if_no_direct_calls
588 (struct cgraph_node
*node
);
589 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
590 (struct cgraph_node
*node
);
591 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node
*node
);
592 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution
);
593 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node
*,
594 bool (*) (struct cgraph_node
*, void *),
597 bool cgraph_for_node_and_aliases (struct cgraph_node
*,
598 bool (*) (struct cgraph_node
*, void *),
600 VEC (cgraph_edge_p
, heap
) * collect_callers_of_node (struct cgraph_node
*node
);
601 void verify_cgraph (void);
602 void verify_cgraph_node (struct cgraph_node
*);
603 void cgraph_mark_address_taken_node (struct cgraph_node
*);
605 typedef void (*cgraph_edge_hook
)(struct cgraph_edge
*, void *);
606 typedef void (*cgraph_node_hook
)(struct cgraph_node
*, void *);
607 typedef void (*cgraph_2edge_hook
)(struct cgraph_edge
*, struct cgraph_edge
*,
609 typedef void (*cgraph_2node_hook
)(struct cgraph_node
*, struct cgraph_node
*,
611 struct cgraph_edge_hook_list
;
612 struct cgraph_node_hook_list
;
613 struct cgraph_2edge_hook_list
;
614 struct cgraph_2node_hook_list
;
615 struct cgraph_edge_hook_list
*cgraph_add_edge_removal_hook (cgraph_edge_hook
, void *);
616 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list
*);
617 struct cgraph_node_hook_list
*cgraph_add_node_removal_hook (cgraph_node_hook
,
619 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list
*);
620 struct cgraph_node_hook_list
*cgraph_add_function_insertion_hook (cgraph_node_hook
,
622 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list
*);
623 void cgraph_call_function_insertion_hooks (struct cgraph_node
*node
);
624 struct cgraph_2edge_hook_list
*cgraph_add_edge_duplication_hook (cgraph_2edge_hook
, void *);
625 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list
*);
626 struct cgraph_2node_hook_list
*cgraph_add_node_duplication_hook (cgraph_2node_hook
, void *);
627 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list
*);
628 gimple
cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge
*);
629 bool cgraph_propagate_frequency (struct cgraph_node
*node
);
631 /* In cgraphunit.c */
632 struct asm_node
*add_asm_node (tree
);
633 extern FILE *cgraph_dump_file
;
634 void cgraph_finalize_function (tree
, bool);
635 void finalize_compilation_unit (void);
637 void init_cgraph (void);
638 bool cgraph_process_new_functions (void);
639 void cgraph_process_same_body_aliases (void);
640 void fixup_same_cpp_alias_visibility (symtab_node node
, symtab_node target
, tree alias
);
642 /* In cgraphclones.c */
644 struct cgraph_edge
* cgraph_clone_edge (struct cgraph_edge
*,
645 struct cgraph_node
*, gimple
,
646 unsigned, gcov_type
, int, bool);
647 struct cgraph_node
* cgraph_clone_node (struct cgraph_node
*, tree
, gcov_type
,
648 int, bool, VEC(cgraph_edge_p
,heap
) *,
650 tree
clone_function_name (tree decl
, const char *);
651 struct cgraph_node
* cgraph_create_virtual_clone (struct cgraph_node
*old_node
,
652 VEC(cgraph_edge_p
,heap
)*,
653 VEC(ipa_replace_map_p
,gc
)* tree_map
,
655 const char *clone_name
);
656 struct cgraph_node
*cgraph_find_replacement_node (struct cgraph_node
*);
657 bool cgraph_remove_node_and_inline_clones (struct cgraph_node
*, struct cgraph_node
*);
658 void cgraph_set_call_stmt_including_clones (struct cgraph_node
*, gimple
, gimple
);
659 void cgraph_create_edge_including_clones (struct cgraph_node
*,
660 struct cgraph_node
*,
661 gimple
, gimple
, gcov_type
, int,
662 cgraph_inline_failed_t
);
663 void cgraph_materialize_all_clones (void);
664 struct cgraph_node
* cgraph_copy_node_for_versioning (struct cgraph_node
*,
665 tree
, VEC(cgraph_edge_p
,heap
)*, bitmap
);
666 struct cgraph_node
*cgraph_function_versioning (struct cgraph_node
*,
667 VEC(cgraph_edge_p
,heap
)*,
668 VEC(ipa_replace_map_p
,gc
)*,
669 bitmap
, bool, bitmap
,
670 basic_block
, const char *);
671 void tree_function_versioning (tree
, tree
, VEC (ipa_replace_map_p
,gc
)*,
672 bool, bitmap
, bool, bitmap
, basic_block
);
674 /* In cgraphbuild.c */
675 unsigned int rebuild_cgraph_edges (void);
676 void cgraph_rebuild_references (void);
677 int compute_call_stmt_bb_frequency (tree
, basic_block bb
);
678 void record_references_in_initializer (tree
, bool);
681 bool symtab_remove_unreachable_nodes (bool, FILE *);
682 cgraph_node_set
cgraph_node_set_new (void);
683 cgraph_node_set_iterator
cgraph_node_set_find (cgraph_node_set
,
684 struct cgraph_node
*);
685 void cgraph_node_set_add (cgraph_node_set
, struct cgraph_node
*);
686 void cgraph_node_set_remove (cgraph_node_set
, struct cgraph_node
*);
687 void dump_cgraph_node_set (FILE *, cgraph_node_set
);
688 void debug_cgraph_node_set (cgraph_node_set
);
689 void free_cgraph_node_set (cgraph_node_set
);
690 void cgraph_build_static_cdtor (char which
, tree body
, int priority
);
692 varpool_node_set
varpool_node_set_new (void);
693 varpool_node_set_iterator
varpool_node_set_find (varpool_node_set
,
694 struct varpool_node
*);
695 void varpool_node_set_add (varpool_node_set
, struct varpool_node
*);
696 void varpool_node_set_remove (varpool_node_set
, struct varpool_node
*);
697 void dump_varpool_node_set (FILE *, varpool_node_set
);
698 void debug_varpool_node_set (varpool_node_set
);
699 void free_varpool_node_set (varpool_node_set
);
700 void ipa_discover_readonly_nonaddressable_vars (void);
701 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node
*);
702 bool varpool_externally_visible_p (struct varpool_node
*, bool);
705 bool cgraph_maybe_hot_edge_p (struct cgraph_edge
*e
);
706 bool cgraph_optimize_for_size_p (struct cgraph_node
*);
709 struct varpool_node
*varpool_node_for_decl (tree
);
710 struct varpool_node
*varpool_node_for_asm (tree asmname
);
711 void varpool_mark_needed_node (struct varpool_node
*);
712 void debug_varpool (void);
713 void dump_varpool (FILE *);
714 void dump_varpool_node (FILE *, struct varpool_node
*);
716 void varpool_finalize_decl (tree
);
717 bool decide_is_variable_needed (struct varpool_node
*, tree
);
718 enum availability
cgraph_variable_initializer_availability (struct varpool_node
*);
719 void cgraph_make_node_local (struct cgraph_node
*);
720 bool cgraph_node_can_be_local_p (struct cgraph_node
*);
723 void varpool_remove_node (struct varpool_node
*node
);
724 void varpool_finalize_named_section_flags (struct varpool_node
*node
);
725 bool varpool_output_variables (void);
726 bool varpool_assemble_decl (struct varpool_node
*node
);
727 void varpool_analyze_node (struct varpool_node
*);
728 struct varpool_node
* varpool_extra_name_alias (tree
, tree
);
729 struct varpool_node
* varpool_create_variable_alias (tree
, tree
);
730 void varpool_reset_queue (void);
731 bool const_value_known_p (tree
);
732 bool varpool_for_node_and_aliases (struct varpool_node
*,
733 bool (*) (struct varpool_node
*, void *),
735 void varpool_add_new_variable (tree
);
736 void symtab_initialize_asm_name_hash (void);
737 void symtab_prevail_in_asm_name_hash (symtab_node node
);
740 /* Return callgraph node for given symbol and check it is a function. */
741 static inline struct cgraph_node
*
742 cgraph (symtab_node node
)
744 gcc_checking_assert (!node
|| node
->symbol
.type
== SYMTAB_FUNCTION
);
745 return (struct cgraph_node
*)node
;
748 /* Return varpool node for given symbol and check it is a variable. */
749 static inline struct varpool_node
*
750 varpool (symtab_node node
)
752 gcc_checking_assert (!node
|| node
->symbol
.type
== SYMTAB_VARIABLE
);
753 return (struct varpool_node
*)node
;
756 /* Return callgraph node for given symbol and check it is a function. */
757 static inline struct cgraph_node
*
758 cgraph_get_node (const_tree decl
)
760 gcc_checking_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
761 return cgraph (symtab_get_node (decl
));
764 /* Return varpool node for given symbol and check it is a function. */
765 static inline struct varpool_node
*
766 varpool_get_node (const_tree decl
)
768 gcc_checking_assert (TREE_CODE (decl
) == VAR_DECL
);
769 return varpool (symtab_get_node (decl
));
772 /* Return asm name of cgraph node. */
773 static inline const char *
774 cgraph_node_asm_name(struct cgraph_node
*node
)
776 return symtab_node_asm_name ((symtab_node
)node
);
779 /* Return asm name of varpool node. */
780 static inline const char *
781 varpool_node_asm_name(struct varpool_node
*node
)
783 return symtab_node_asm_name ((symtab_node
)node
);
786 /* Return name of cgraph node. */
787 static inline const char *
788 cgraph_node_name(struct cgraph_node
*node
)
790 return symtab_node_name ((symtab_node
)node
);
793 /* Return name of varpool node. */
794 static inline const char *
795 varpool_node_name(struct varpool_node
*node
)
797 return symtab_node_name ((symtab_node
)node
);
800 /* Walk all symbols. */
801 #define FOR_EACH_SYMBOL(node) \
802 for ((node) = symtab_nodes; (node); (node) = (node)->symbol.next)
805 /* Return first variable. */
806 static inline struct varpool_node
*
807 varpool_first_variable (void)
810 for (node
= symtab_nodes
; node
; node
= node
->symbol
.next
)
811 if (varpool_node
*vnode
= dyn_cast
<varpool_node
> (node
))
816 /* Return next variable after NODE. */
817 static inline struct varpool_node
*
818 varpool_next_variable (struct varpool_node
*node
)
820 symtab_node node1
= (symtab_node
) node
->symbol
.next
;
821 for (; node1
; node1
= node1
->symbol
.next
)
822 if (varpool_node
*vnode1
= dyn_cast
<varpool_node
> (node1
))
826 /* Walk all variables. */
827 #define FOR_EACH_VARIABLE(node) \
828 for ((node) = varpool_first_variable (); \
830 (node) = varpool_next_variable ((node)))
832 /* Return first reachable static variable with initializer. */
833 static inline struct varpool_node
*
834 varpool_first_static_initializer (void)
837 for (node
= symtab_nodes
; node
; node
= node
->symbol
.next
)
839 varpool_node
*vnode
= dyn_cast
<varpool_node
> (node
);
840 if (vnode
&& DECL_INITIAL (node
->symbol
.decl
))
846 /* Return next reachable static variable with initializer after NODE. */
847 static inline struct varpool_node
*
848 varpool_next_static_initializer (struct varpool_node
*node
)
850 symtab_node node1
= (symtab_node
) node
->symbol
.next
;
851 for (; node1
; node1
= node1
->symbol
.next
)
853 varpool_node
*vnode1
= dyn_cast
<varpool_node
> (node1
);
854 if (vnode1
&& DECL_INITIAL (node1
->symbol
.decl
))
860 /* Walk all static variables with initializer set. */
861 #define FOR_EACH_STATIC_INITIALIZER(node) \
862 for ((node) = varpool_first_static_initializer (); (node); \
863 (node) = varpool_next_static_initializer (node))
865 /* Return first reachable static variable with initializer. */
866 static inline struct varpool_node
*
867 varpool_first_defined_variable (void)
870 for (node
= symtab_nodes
; node
; node
= node
->symbol
.next
)
872 varpool_node
*vnode
= dyn_cast
<varpool_node
> (node
);
873 if (vnode
&& vnode
->analyzed
)
879 /* Return next reachable static variable with initializer after NODE. */
880 static inline struct varpool_node
*
881 varpool_next_defined_variable (struct varpool_node
*node
)
883 symtab_node node1
= (symtab_node
) node
->symbol
.next
;
884 for (; node1
; node1
= node1
->symbol
.next
)
886 varpool_node
*vnode1
= dyn_cast
<varpool_node
> (node1
);
887 if (vnode1
&& vnode1
->analyzed
)
892 /* Walk all variables with definitions in current unit. */
893 #define FOR_EACH_DEFINED_VARIABLE(node) \
894 for ((node) = varpool_first_defined_variable (); (node); \
895 (node) = varpool_next_defined_variable (node))
897 /* Return first function with body defined. */
898 static inline struct cgraph_node
*
899 cgraph_first_defined_function (void)
902 for (node
= symtab_nodes
; node
; node
= node
->symbol
.next
)
904 cgraph_node
*cn
= dyn_cast
<cgraph_node
> (node
);
905 if (cn
&& cn
->analyzed
)
911 /* Return next function with body defined after NODE. */
912 static inline struct cgraph_node
*
913 cgraph_next_defined_function (struct cgraph_node
*node
)
915 symtab_node node1
= (symtab_node
) node
->symbol
.next
;
916 for (; node1
; node1
= node1
->symbol
.next
)
918 cgraph_node
*cn1
= dyn_cast
<cgraph_node
> (node1
);
919 if (cn1
&& cn1
->analyzed
)
925 /* Walk all functions with body defined. */
926 #define FOR_EACH_DEFINED_FUNCTION(node) \
927 for ((node) = cgraph_first_defined_function (); (node); \
928 (node) = cgraph_next_defined_function ((node)))
930 /* Return first function. */
931 static inline struct cgraph_node
*
932 cgraph_first_function (void)
935 for (node
= symtab_nodes
; node
; node
= node
->symbol
.next
)
936 if (cgraph_node
*cn
= dyn_cast
<cgraph_node
> (node
))
941 /* Return next function. */
942 static inline struct cgraph_node
*
943 cgraph_next_function (struct cgraph_node
*node
)
945 symtab_node node1
= (symtab_node
) node
->symbol
.next
;
946 for (; node1
; node1
= node1
->symbol
.next
)
947 if (cgraph_node
*cn1
= dyn_cast
<cgraph_node
> (node1
))
951 /* Walk all functions. */
952 #define FOR_EACH_FUNCTION(node) \
953 for ((node) = cgraph_first_function (); (node); \
954 (node) = cgraph_next_function ((node)))
956 /* Return true when NODE is a function with Gimple body defined
957 in current unit. Functions can also be define externally or they
958 can be thunks with no Gimple representation.
960 Note that at WPA stage, the function body may not be present in memory. */
963 cgraph_function_with_gimple_body_p (struct cgraph_node
*node
)
965 return node
->analyzed
&& !node
->thunk
.thunk_p
&& !node
->alias
;
968 /* Return first function with body defined. */
969 static inline struct cgraph_node
*
970 cgraph_first_function_with_gimple_body (void)
973 for (node
= symtab_nodes
; node
; node
= node
->symbol
.next
)
975 cgraph_node
*cn
= dyn_cast
<cgraph_node
> (node
);
976 if (cn
&& cgraph_function_with_gimple_body_p (cn
))
982 /* Return next reachable static variable with initializer after NODE. */
983 static inline struct cgraph_node
*
984 cgraph_next_function_with_gimple_body (struct cgraph_node
*node
)
986 symtab_node node1
= node
->symbol
.next
;
987 for (; node1
; node1
= node1
->symbol
.next
)
989 cgraph_node
*cn1
= dyn_cast
<cgraph_node
> (node1
);
990 if (cn1
&& cgraph_function_with_gimple_body_p (cn1
))
996 /* Walk all functions with body defined. */
997 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
998 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
999 (node) = cgraph_next_function_with_gimple_body (node))
1001 /* Create a new static variable of type TYPE. */
1002 tree
add_new_static_var (tree type
);
1004 /* Return true if iterator CSI points to nothing. */
1006 csi_end_p (cgraph_node_set_iterator csi
)
1008 return csi
.index
>= VEC_length (cgraph_node_ptr
, csi
.set
->nodes
);
1011 /* Advance iterator CSI. */
1013 csi_next (cgraph_node_set_iterator
*csi
)
1018 /* Return the node pointed to by CSI. */
1019 static inline struct cgraph_node
*
1020 csi_node (cgraph_node_set_iterator csi
)
1022 return VEC_index (cgraph_node_ptr
, csi
.set
->nodes
, csi
.index
);
1025 /* Return an iterator to the first node in SET. */
1026 static inline cgraph_node_set_iterator
1027 csi_start (cgraph_node_set set
)
1029 cgraph_node_set_iterator csi
;
1036 /* Return true if SET contains NODE. */
1038 cgraph_node_in_set_p (struct cgraph_node
*node
, cgraph_node_set set
)
1040 cgraph_node_set_iterator csi
;
1041 csi
= cgraph_node_set_find (set
, node
);
1042 return !csi_end_p (csi
);
1045 /* Return number of nodes in SET. */
1046 static inline size_t
1047 cgraph_node_set_size (cgraph_node_set set
)
1049 return VEC_length (cgraph_node_ptr
, set
->nodes
);
1052 /* Return true if iterator VSI points to nothing. */
1054 vsi_end_p (varpool_node_set_iterator vsi
)
1056 return vsi
.index
>= VEC_length (varpool_node_ptr
, vsi
.set
->nodes
);
1059 /* Advance iterator VSI. */
1061 vsi_next (varpool_node_set_iterator
*vsi
)
1066 /* Return the node pointed to by VSI. */
1067 static inline struct varpool_node
*
1068 vsi_node (varpool_node_set_iterator vsi
)
1070 return VEC_index (varpool_node_ptr
, vsi
.set
->nodes
, vsi
.index
);
1073 /* Return an iterator to the first node in SET. */
1074 static inline varpool_node_set_iterator
1075 vsi_start (varpool_node_set set
)
1077 varpool_node_set_iterator vsi
;
1084 /* Return true if SET contains NODE. */
1086 varpool_node_in_set_p (struct varpool_node
*node
, varpool_node_set set
)
1088 varpool_node_set_iterator vsi
;
1089 vsi
= varpool_node_set_find (set
, node
);
1090 return !vsi_end_p (vsi
);
1093 /* Return number of nodes in SET. */
1094 static inline size_t
1095 varpool_node_set_size (varpool_node_set set
)
1097 return VEC_length (varpool_node_ptr
, set
->nodes
);
1100 /* Uniquize all constants that appear in memory.
1101 Each constant in memory thus far output is recorded
1102 in `const_desc_table'. */
1104 struct GTY(()) constant_descriptor_tree
{
1105 /* A MEM for the constant. */
1108 /* The value of the constant. */
1111 /* Hash of value. Computing the hash from value each time
1112 hashfn is called can't work properly, as that means recursive
1113 use of the hash table during hash table expansion. */
1117 /* Return true if set is nonempty. */
1119 cgraph_node_set_nonempty_p (cgraph_node_set set
)
1121 return !VEC_empty (cgraph_node_ptr
, set
->nodes
);
1124 /* Return true if set is nonempty. */
1126 varpool_node_set_nonempty_p (varpool_node_set set
)
1128 return !VEC_empty (varpool_node_ptr
, set
->nodes
);
1131 /* Return true when function NODE is only called directly or it has alias.
1132 i.e. it is not externally visible, address was not taken and
1133 it is not used in any other non-standard way. */
1136 cgraph_only_called_directly_or_aliased_p (struct cgraph_node
*node
)
1138 gcc_assert (!node
->global
.inlined_to
);
1139 return (!node
->symbol
.force_output
&& !node
->symbol
.address_taken
1140 && !node
->symbol
.used_from_other_partition
1141 && !DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
)
1142 && !DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
)
1143 && !node
->symbol
.externally_visible
);
1146 /* Return true when function NODE can be removed from callgraph
1147 if all direct calls are eliminated. */
1150 varpool_can_remove_if_no_refs (struct varpool_node
*node
)
1152 if (DECL_EXTERNAL (node
->symbol
.decl
))
1154 return (!node
->symbol
.force_output
&& !node
->symbol
.used_from_other_partition
1155 && ((DECL_COMDAT (node
->symbol
.decl
)
1156 && !symtab_used_from_object_file_p ((symtab_node
) node
))
1157 || !node
->symbol
.externally_visible
1158 || DECL_HAS_VALUE_EXPR_P (node
->symbol
.decl
)));
1161 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1162 i.e. if the variable is not externally visible or not used in some magic
1163 way (asm statement or such).
1164 The magic uses are all summarized in force_output flag. */
1167 varpool_all_refs_explicit_p (struct varpool_node
*vnode
)
1169 return (vnode
->analyzed
1170 && !vnode
->symbol
.externally_visible
1171 && !vnode
->symbol
.used_from_other_partition
1172 && !vnode
->symbol
.force_output
);
1175 /* Constant pool accessor function. */
1176 htab_t
constant_pool_htab (void);
1178 /* FIXME: inappropriate dependency of cgraph on IPA. */
1179 #include "ipa-ref-inline.h"
1181 /* Return node that alias N is aliasing. */
1183 static inline struct cgraph_node
*
1184 cgraph_alias_aliased_node (struct cgraph_node
*n
)
1186 struct ipa_ref
*ref
;
1188 ipa_ref_list_reference_iterate (&n
->symbol
.ref_list
, 0, ref
);
1189 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1190 if (is_a
<cgraph_node
> (ref
->referred
))
1191 return ipa_ref_node (ref
);
1195 /* Return node that alias N is aliasing. */
1197 static inline struct varpool_node
*
1198 varpool_alias_aliased_node (struct varpool_node
*n
)
1200 struct ipa_ref
*ref
;
1202 ipa_ref_list_reference_iterate (&n
->symbol
.ref_list
, 0, ref
);
1203 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1204 if (is_a
<varpool_node
> (ref
->referred
))
1205 return ipa_ref_varpool_node (ref
);
1209 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1210 Walk through thunk, too.
1211 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1213 static inline struct cgraph_node
*
1214 cgraph_function_node (struct cgraph_node
*node
, enum availability
*availability
)
1217 *availability
= cgraph_function_body_availability (node
);
1220 if (node
->alias
&& node
->analyzed
)
1221 node
= cgraph_alias_aliased_node (node
);
1222 else if (node
->thunk
.thunk_p
)
1223 node
= node
->callees
->callee
;
1226 if (node
&& availability
)
1228 enum availability a
;
1229 a
= cgraph_function_body_availability (node
);
1230 if (a
< *availability
)
1235 *availability
= AVAIL_NOT_AVAILABLE
;
1239 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1240 Do not walk through thunks.
1241 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1243 static inline struct cgraph_node
*
1244 cgraph_function_or_thunk_node (struct cgraph_node
*node
, enum availability
*availability
)
1247 *availability
= cgraph_function_body_availability (node
);
1250 if (node
->alias
&& node
->analyzed
)
1251 node
= cgraph_alias_aliased_node (node
);
1254 if (node
&& availability
)
1256 enum availability a
;
1257 a
= cgraph_function_body_availability (node
);
1258 if (a
< *availability
)
1263 *availability
= AVAIL_NOT_AVAILABLE
;
1267 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1268 Do not walk through thunks.
1269 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1271 static inline struct varpool_node
*
1272 varpool_variable_node (struct varpool_node
*node
, enum availability
*availability
)
1275 *availability
= cgraph_variable_initializer_availability (node
);
1278 if (node
->alias
&& node
->analyzed
)
1279 node
= varpool_alias_aliased_node (node
);
1282 if (node
&& availability
)
1284 enum availability a
;
1285 a
= cgraph_variable_initializer_availability (node
);
1286 if (a
< *availability
)
1291 *availability
= AVAIL_NOT_AVAILABLE
;
1295 /* Return true when the edge E represents a direct recursion. */
1297 cgraph_edge_recursive_p (struct cgraph_edge
*e
)
1299 struct cgraph_node
*callee
= cgraph_function_or_thunk_node (e
->callee
, NULL
);
1300 if (e
->caller
->global
.inlined_to
)
1301 return e
->caller
->global
.inlined_to
->symbol
.decl
== callee
->symbol
.decl
;
1303 return e
->caller
->symbol
.decl
== callee
->symbol
.decl
;
1306 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1308 decl_is_tm_clone (const_tree fndecl
)
1310 struct cgraph_node
*n
= cgraph_get_node (fndecl
);
1316 /* Likewise indicate that a node is needed, i.e. reachable via some
1320 cgraph_mark_force_output_node (struct cgraph_node
*node
)
1322 node
->symbol
.force_output
= 1;
1323 gcc_checking_assert (!node
->global
.inlined_to
);
1326 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1327 or extern function kept around just for inlining. */
1330 symtab_real_symbol_p (symtab_node node
)
1332 struct cgraph_node
*cnode
;
1333 struct ipa_ref
*ref
;
1335 if (!is_a
<cgraph_node
> (node
))
1337 cnode
= cgraph (node
);
1338 if (cnode
->global
.inlined_to
)
1340 if (cnode
->abstract_and_needed
)
1342 /* We keep virtual clones in symtab. */
1343 if (!cnode
->analyzed
1344 || DECL_EXTERNAL (cnode
->symbol
.decl
))
1345 return (cnode
->callers
1346 || ipa_ref_list_referring_iterate (&cnode
->symbol
.ref_list
, 0, ref
));
1349 #endif /* GCC_CGRAPH_H */