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/>. */
25 #include "plugin-api.h"
28 #include "basic-block.h"
32 /* Symbol table consists of functions and variables.
33 TODO: add labels, constant pool and aliases. */
41 union symtab_node_def
;
42 typedef union symtab_node_def
*symtab_node
;
44 /* Base of all entries in the symbol table.
45 The symtab_node is inherited by cgraph and varpol nodes. */
46 struct GTY(()) symtab_node_base
48 /* Type of the symbol. */
49 enum symtab_type type
;
51 struct ipa_ref_list ref_list
;
52 /* Circular list of nodes in the same comdat group if non-NULL. */
53 symtab_node same_comdat_group
;
54 /* Ordering of all symtab entries. */
56 enum ld_plugin_symbol_resolution resolution
;
57 /* File stream where this node is being written to. */
58 struct lto_file_decl_data
* lto_file_data
;
60 /* Linked list of symbol table entries starting with symtab_nodes. */
66 /* Set when function has address taken.
67 In current implementation it imply needed flag. */
68 unsigned address_taken
: 1;
69 /* Set when variable is used from other LTRANS partition. */
70 unsigned used_from_other_partition
: 1;
71 /* Set when function is available in the other LTRANS partition.
72 During WPA output it is used to mark nodes that are present in
73 multiple partitions. */
74 unsigned in_other_partition
: 1;
75 /* Set when function is visible by other units. */
76 unsigned externally_visible
: 1;
81 /* Not yet set by cgraph_function_body_availability. */
83 /* Function body/variable initializer is unknown. */
85 /* Function body/variable initializer is known but might be replaced
86 by a different one from other compilation unit and thus needs to
87 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
88 arbitrary side effects on escaping variables and functions, while
89 like AVAILABLE it might access static variables. */
91 /* Function body/variable initializer is known and will be used in final
94 /* Function body/variable initializer is known and all it's uses are explicitly
95 visible within current unit (ie it's address is never taken and it is not
96 exported to other units).
97 Currently used only for functions. */
101 /* This is the information that is put into the cgraph local structure
102 to recover a function. */
103 struct lto_file_decl_data
;
105 extern const char * const cgraph_availability_names
[];
106 extern const char * const ld_plugin_symbol_resolution_names
[];
108 /* Information about thunk, used only for same body aliases. */
110 struct GTY(()) cgraph_thunk_info
{
111 /* Information about the thunk. */
112 HOST_WIDE_INT fixed_offset
;
113 HOST_WIDE_INT virtual_value
;
116 bool virtual_offset_p
;
117 /* Set to true when alias node is thunk. */
121 /* Information about the function collected locally.
122 Available after function is analyzed. */
124 struct GTY(()) cgraph_local_info
{
125 /* Set when function function is visible in current compilation unit only
126 and its address is never taken. */
129 /* Set once it has been finalized so we consider it to be output. */
130 unsigned finalized
: 1;
132 /* False when there is something makes versioning impossible. */
133 unsigned versionable
: 1;
135 /* False when function calling convention and signature can not be changed.
136 This is the case when __builtin_apply_args is used. */
137 unsigned can_change_signature
: 1;
139 /* True when the function has been originally extern inline, but it is
141 unsigned redefined_extern_inline
: 1;
143 /* True if the function may enter serial irrevocable mode. */
144 unsigned tm_may_enter_irr
: 1;
147 /* Information about the function that needs to be computed globally
148 once compilation is finished. Available only with -funit-at-a-time. */
150 struct GTY(()) cgraph_global_info
{
151 /* For inline clones this points to the function they will be
153 struct cgraph_node
*inlined_to
;
156 /* Information about the function that is propagated by the RTL backend.
157 Available only for functions that has been already assembled. */
159 struct GTY(()) cgraph_rtl_info
{
160 unsigned int preferred_incoming_stack_boundary
;
163 /* Represent which DECL tree (or reference to such tree)
164 will be replaced by another tree while versioning. */
165 struct GTY(()) ipa_replace_map
167 /* The tree that will be replaced. */
169 /* The new (replacing) tree. */
171 /* Parameter number to replace, when old_tree is NULL. */
173 /* True when a substitution should be done, false otherwise. */
175 /* True when we replace a reference to old_tree. */
178 typedef struct ipa_replace_map
*ipa_replace_map_p
;
179 DEF_VEC_P(ipa_replace_map_p
);
180 DEF_VEC_ALLOC_P(ipa_replace_map_p
,gc
);
182 struct GTY(()) cgraph_clone_info
184 VEC(ipa_replace_map_p
,gc
)* tree_map
;
186 bitmap combined_args_to_skip
;
190 /* The cgraph data structure.
191 Each function decl has assigned cgraph_node listing callees and callers. */
193 struct GTY(()) cgraph_node
{
194 struct symtab_node_base symbol
;
195 struct cgraph_edge
*callees
;
196 struct cgraph_edge
*callers
;
197 /* List of edges representing indirect calls with a yet undetermined
199 struct cgraph_edge
*indirect_calls
;
200 /* For nested functions points to function the node is nested in. */
202 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
204 /* Points to first nested function, if any. */
206 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
208 /* Pointer to the next function with same origin, if any. */
210 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
212 /* Pointer to the next function in cgraph_nodes_queue. */
214 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
216 /* Pointer to the next clone. */
217 struct cgraph_node
*next_sibling_clone
;
218 struct cgraph_node
*prev_sibling_clone
;
219 struct cgraph_node
*clones
;
220 struct cgraph_node
*clone_of
;
221 /* For functions with many calls sites it holds map from call expression
222 to the edge to speed up cgraph_edge function. */
223 htab_t
GTY((param_is (struct cgraph_edge
))) call_site_hash
;
224 /* Declaration node used to be clone of. */
225 tree former_clone_of
;
227 /* Interprocedural passes scheduled to have their transform functions
228 applied next time we execute local pass on them. We maintain it
229 per-function in order to allow IPA passes to introduce new functions. */
230 VEC(ipa_opt_pass
,heap
) * GTY((skip
)) ipa_transforms_to_apply
;
232 struct cgraph_local_info local
;
233 struct cgraph_global_info global
;
234 struct cgraph_rtl_info rtl
;
235 struct cgraph_clone_info clone
;
236 struct cgraph_thunk_info thunk
;
238 /* Expected number of executions: calculated in profile.c. */
240 /* How to scale counts at materialization time; used to merge
241 LTO units with different number of profile runs. */
242 int count_materialization_scale
;
243 /* Unique id of the node. */
246 /* Set when function must be output for some reason. The primary
247 use of this flag is to mark functions needed to be output for
248 non-standard reason. Functions that are externally visible
249 or reachable from functions needed to be output are marked
250 by specialized flags. */
252 /* Set when decl is an abstract function pointed to by the
253 ABSTRACT_DECL_ORIGIN of a reachable function. */
254 unsigned abstract_and_needed
: 1;
255 /* Set when function is reachable by call from other function
256 that is either reachable or needed.
257 This flag is computed at original cgraph construction and then
258 updated in cgraph_remove_unreachable_nodes. Note that after
259 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
260 nodes when they are needed for virtual clone instantiation. */
261 unsigned reachable
: 1;
262 /* Set once the function is lowered (i.e. its CFG is built). */
263 unsigned lowered
: 1;
264 /* Set once the function has been instantiated and its callee
266 unsigned analyzed
: 1;
267 /* Set when function is scheduled to be processed by local passes. */
268 unsigned process
: 1;
269 /* Set for aliases once they got through assemble_alias. */
271 /* Set for aliases created as C++ same body aliases. */
272 unsigned same_body_alias
: 1;
273 /* How commonly executed the node is. Initialized during branch
274 probabilities pass. */
275 ENUM_BITFIELD (node_frequency
) frequency
: 2;
276 /* True when function can only be called at startup (from static ctor). */
277 unsigned only_called_at_startup
: 1;
278 /* True when function can only be called at startup (from static dtor). */
279 unsigned only_called_at_exit
: 1;
280 /* True when function is the transactional clone of a function which
281 is called only from inside transactions. */
282 /* ?? We should be able to remove this. We have enough bits in
283 cgraph to calculate it. */
284 unsigned tm_clone
: 1;
287 typedef struct cgraph_node
*cgraph_node_ptr
;
289 DEF_VEC_P(cgraph_node_ptr
);
290 DEF_VEC_ALLOC_P(cgraph_node_ptr
,heap
);
291 DEF_VEC_ALLOC_P(cgraph_node_ptr
,gc
);
293 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
294 can appear in multiple sets. */
295 struct cgraph_node_set_def
297 struct pointer_map_t
*map
;
298 VEC(cgraph_node_ptr
, heap
) *nodes
;
301 typedef struct varpool_node
*varpool_node_ptr
;
303 DEF_VEC_P(varpool_node_ptr
);
304 DEF_VEC_ALLOC_P(varpool_node_ptr
,heap
);
305 DEF_VEC_ALLOC_P(varpool_node_ptr
,gc
);
307 /* A varpool node set is a collection of varpool nodes. A varpool node
308 can appear in multiple sets. */
309 struct varpool_node_set_def
311 struct pointer_map_t
* map
;
312 VEC(varpool_node_ptr
, heap
) *nodes
;
315 typedef struct cgraph_node_set_def
*cgraph_node_set
;
317 DEF_VEC_P(cgraph_node_set
);
318 DEF_VEC_ALLOC_P(cgraph_node_set
,gc
);
319 DEF_VEC_ALLOC_P(cgraph_node_set
,heap
);
321 typedef struct varpool_node_set_def
*varpool_node_set
;
323 DEF_VEC_P(varpool_node_set
);
324 DEF_VEC_ALLOC_P(varpool_node_set
,gc
);
325 DEF_VEC_ALLOC_P(varpool_node_set
,heap
);
327 /* Iterator structure for cgraph node sets. */
332 } cgraph_node_set_iterator
;
334 /* Iterator structure for varpool node sets. */
337 varpool_node_set set
;
339 } varpool_node_set_iterator
;
341 #define DEFCIFCODE(code, string) CIF_ ## code,
342 /* Reasons for inlining failures. */
343 typedef enum cgraph_inline_failed_enum
{
344 #include "cif-code.def"
346 } cgraph_inline_failed_t
;
348 /* Structure containing additional information about an indirect call. */
350 struct GTY(()) cgraph_indirect_call_info
352 /* Offset accumulated from ancestor jump functions of inlined call graph
354 HOST_WIDE_INT anc_offset
;
355 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
356 HOST_WIDE_INT otr_token
;
357 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
359 /* Index of the parameter that is called. */
361 /* ECF flags determined from the caller. */
364 /* Set when the call is a virtual call with the parameter being the
365 associated object pointer rather than a simple direct call. */
366 unsigned polymorphic
: 1;
369 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge
{
370 /* Expected number of executions: calculated in profile.c. */
372 struct cgraph_node
*caller
;
373 struct cgraph_node
*callee
;
374 struct cgraph_edge
*prev_caller
;
375 struct cgraph_edge
*next_caller
;
376 struct cgraph_edge
*prev_callee
;
377 struct cgraph_edge
*next_callee
;
379 /* Additional information about an indirect call. Not cleared when an edge
381 struct cgraph_indirect_call_info
*indirect_info
;
382 PTR
GTY ((skip (""))) aux
;
383 /* When equal to CIF_OK, inline this call. Otherwise, points to the
384 explanation why function was not inlined. */
385 cgraph_inline_failed_t inline_failed
;
386 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
387 when the function is serialized in. */
388 unsigned int lto_stmt_uid
;
389 /* Expected frequency of executions within the function.
390 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
391 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
393 /* Unique id of the edge. */
395 /* Whether this edge was made direct by indirect inlining. */
396 unsigned int indirect_inlining_edge
: 1;
397 /* Whether this edge describes an indirect call with an undetermined
399 unsigned int indirect_unknown_callee
: 1;
400 /* Whether this edge is still a dangling */
401 /* True if the corresponding CALL stmt cannot be inlined. */
402 unsigned int call_stmt_cannot_inline_p
: 1;
403 /* Can this call throw externally? */
404 unsigned int can_throw_external
: 1;
407 #define CGRAPH_FREQ_BASE 1000
408 #define CGRAPH_FREQ_MAX 100000
410 typedef struct cgraph_edge
*cgraph_edge_p
;
412 DEF_VEC_P(cgraph_edge_p
);
413 DEF_VEC_ALLOC_P(cgraph_edge_p
,heap
);
415 /* The varpool data structure.
416 Each static variable decl has assigned varpool_node. */
418 struct GTY(()) varpool_node
{
419 struct symtab_node_base symbol
;
420 /* For aliases points to declaration DECL is alias of. */
422 /* Pointer to the next function in varpool_nodes_queue. */
423 struct varpool_node
*
424 GTY ((nested_ptr (union symtab_node_def
, "(struct varpool_node *)(%h)", "(symtab_node)%h")))
426 struct varpool_node
*
427 GTY ((nested_ptr (union symtab_node_def
, "(struct varpool_node *)(%h)", "(symtab_node)%h")))
430 /* Set when function must be output - it is externally visible
431 or its address is taken. */
433 /* Needed variables might become dead by optimization. This flag
434 forces the variable to be output even if it appears dead otherwise. */
435 unsigned force_output
: 1;
436 /* Set once the variable has been instantiated and its callee
438 unsigned analyzed
: 1;
439 /* Set once it has been finalized so we consider it to be output. */
440 unsigned finalized
: 1;
441 /* Set when variable is scheduled to be assembled. */
443 /* Set for aliases once they got through assemble_alias. Also set for
444 extra name aliases in varpool_extra_name_alias. */
446 unsigned extra_name_alias
: 1;
449 /* Every top level asm statement is put into a cgraph_asm_node. */
451 struct GTY(()) cgraph_asm_node
{
453 struct cgraph_asm_node
*next
;
454 /* String for this asm node. */
456 /* Ordering of all cgraph nodes. */
460 /* Symbol table entry. */
461 union GTY((desc ("%h.symbol.type"), chain_next ("%h.symbol.next"),
462 chain_prev ("%h.symbol.previous"))) symtab_node_def
{
463 struct symtab_node_base
GTY ((tag ("SYMTAB_SYMBOL"))) symbol
;
464 /* Use cgraph (symbol) accessor to get cgraph_node. */
465 struct cgraph_node
GTY ((tag ("SYMTAB_FUNCTION"))) x_function
;
466 /* Use varpool (symbol) accessor to get varpool_node. */
467 struct varpool_node
GTY ((tag ("SYMTAB_VARIABLE"))) x_variable
;
470 extern GTY(()) symtab_node symtab_nodes
;
471 extern GTY(()) int cgraph_n_nodes
;
472 extern GTY(()) int cgraph_max_uid
;
473 extern GTY(()) int cgraph_edge_max_uid
;
474 extern bool cgraph_global_info_ready
;
477 /* Callgraph is being constructed. It is safe to add new functions. */
478 CGRAPH_STATE_CONSTRUCTION
,
479 /* Callgraph is built and IPA passes are being run. */
481 /* Callgraph is built and all functions are transformed to SSA form. */
482 CGRAPH_STATE_IPA_SSA
,
483 /* Functions are now ordered and being passed to RTL expanders. */
484 CGRAPH_STATE_EXPANSION
,
485 /* All cgraph expansion is done. */
486 CGRAPH_STATE_FINISHED
488 extern enum cgraph_state cgraph_state
;
489 extern bool cgraph_function_flags_ready
;
490 extern GTY(()) symtab_node x_cgraph_nodes_queue
;
491 #define cgraph_nodes_queue ((struct cgraph_node *)x_cgraph_nodes_queue)
492 extern GTY(()) struct cgraph_node
*cgraph_new_nodes
;
494 extern GTY(()) struct cgraph_asm_node
*cgraph_asm_nodes
;
495 extern GTY(()) int symtab_order
;
496 extern bool same_body_aliases_done
;
499 void symtab_register_node (symtab_node
);
500 void symtab_unregister_node (symtab_node
);
501 void symtab_remove_node (symtab_node
);
504 void dump_cgraph (FILE *);
505 void debug_cgraph (void);
506 void dump_cgraph_node (FILE *, struct cgraph_node
*);
507 void debug_cgraph_node (struct cgraph_node
*);
508 void cgraph_insert_node_to_hashtable (struct cgraph_node
*node
);
509 void cgraph_remove_edge (struct cgraph_edge
*);
510 void cgraph_remove_node (struct cgraph_node
*);
511 void cgraph_add_to_same_comdat_group (struct cgraph_node
*, struct cgraph_node
*);
512 bool cgraph_remove_node_and_inline_clones (struct cgraph_node
*, struct cgraph_node
*);
513 void cgraph_release_function_body (struct cgraph_node
*);
514 void cgraph_node_remove_callees (struct cgraph_node
*node
);
515 struct cgraph_edge
*cgraph_create_edge (struct cgraph_node
*,
516 struct cgraph_node
*,
517 gimple
, gcov_type
, int);
518 struct cgraph_edge
*cgraph_create_indirect_edge (struct cgraph_node
*, gimple
,
519 int, gcov_type
, int);
520 struct cgraph_indirect_call_info
*cgraph_allocate_init_indirect_info (void);
521 struct cgraph_node
* cgraph_get_node (const_tree
);
522 struct cgraph_node
* cgraph_create_node (tree
);
523 struct cgraph_node
* cgraph_get_create_node (tree
);
524 struct cgraph_node
* cgraph_same_body_alias (struct cgraph_node
*, tree
, tree
);
525 struct cgraph_node
* cgraph_add_thunk (struct cgraph_node
*, tree
, tree
, bool, HOST_WIDE_INT
,
526 HOST_WIDE_INT
, tree
, tree
);
527 struct cgraph_node
*cgraph_node_for_asm (tree
);
528 struct cgraph_edge
*cgraph_edge (struct cgraph_node
*, gimple
);
529 void cgraph_set_call_stmt (struct cgraph_edge
*, gimple
);
530 void cgraph_set_call_stmt_including_clones (struct cgraph_node
*, gimple
, gimple
);
531 void cgraph_create_edge_including_clones (struct cgraph_node
*,
532 struct cgraph_node
*,
533 gimple
, gimple
, gcov_type
, int,
534 cgraph_inline_failed_t
);
535 void cgraph_update_edges_for_call_stmt (gimple
, tree
, gimple
);
536 struct cgraph_local_info
*cgraph_local_info (tree
);
537 struct cgraph_global_info
*cgraph_global_info (tree
);
538 struct cgraph_rtl_info
*cgraph_rtl_info (tree
);
539 const char * cgraph_node_name (struct cgraph_node
*);
540 struct cgraph_edge
* cgraph_clone_edge (struct cgraph_edge
*,
541 struct cgraph_node
*, gimple
,
542 unsigned, gcov_type
, int, bool);
543 struct cgraph_node
* cgraph_clone_node (struct cgraph_node
*, tree
, gcov_type
,
544 int, bool, VEC(cgraph_edge_p
,heap
) *,
546 struct cgraph_node
*cgraph_create_function_alias (tree
, tree
);
547 void cgraph_call_node_duplication_hooks (struct cgraph_node
*node1
,
548 struct cgraph_node
*node2
);
550 void cgraph_redirect_edge_callee (struct cgraph_edge
*, struct cgraph_node
*);
551 void cgraph_make_edge_direct (struct cgraph_edge
*, struct cgraph_node
*);
552 bool cgraph_only_called_directly_p (struct cgraph_node
*);
554 struct cgraph_asm_node
*cgraph_add_asm_node (tree
);
556 bool cgraph_function_possibly_inlined_p (tree
);
557 void cgraph_unnest_node (struct cgraph_node
*);
559 enum availability
cgraph_function_body_availability (struct cgraph_node
*);
560 void cgraph_add_new_function (tree
, bool);
561 const char* cgraph_inline_failed_string (cgraph_inline_failed_t
);
562 struct cgraph_node
* cgraph_create_virtual_clone (struct cgraph_node
*old_node
,
563 VEC(cgraph_edge_p
,heap
)*,
564 VEC(ipa_replace_map_p
,gc
)* tree_map
,
566 const char *clone_name
);
568 void cgraph_set_nothrow_flag (struct cgraph_node
*, bool);
569 void cgraph_set_const_flag (struct cgraph_node
*, bool, bool);
570 void cgraph_set_pure_flag (struct cgraph_node
*, bool, bool);
571 tree
clone_function_name (tree decl
, const char *);
572 bool cgraph_node_cannot_return (struct cgraph_node
*);
573 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge
*);
574 bool cgraph_will_be_removed_from_program_if_no_direct_calls
575 (struct cgraph_node
*node
);
576 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
577 (struct cgraph_node
*node
);
578 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node
*node
);
579 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution
);
580 bool cgraph_used_from_object_file_p (struct cgraph_node
*);
581 bool varpool_used_from_object_file_p (struct varpool_node
*);
582 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node
*,
583 bool (*) (struct cgraph_node
*, void *),
586 bool cgraph_for_node_and_aliases (struct cgraph_node
*,
587 bool (*) (struct cgraph_node
*, void *),
589 VEC (cgraph_edge_p
, heap
) * collect_callers_of_node (struct cgraph_node
*node
);
592 /* In cgraphunit.c */
593 extern FILE *cgraph_dump_file
;
594 void cgraph_finalize_function (tree
, bool);
595 void cgraph_mark_if_needed (tree
);
596 void cgraph_analyze_function (struct cgraph_node
*);
597 void cgraph_finalize_compilation_unit (void);
598 void cgraph_optimize (void);
599 void cgraph_mark_needed_node (struct cgraph_node
*);
600 void cgraph_mark_address_taken_node (struct cgraph_node
*);
601 void cgraph_mark_reachable_node (struct cgraph_node
*);
602 bool cgraph_inline_p (struct cgraph_edge
*, cgraph_inline_failed_t
*reason
);
603 bool cgraph_preserve_function_body_p (struct cgraph_node
*);
604 void verify_cgraph (void);
605 void verify_cgraph_node (struct cgraph_node
*);
606 void cgraph_build_static_cdtor (char which
, tree body
, int priority
);
607 void cgraph_reset_static_var_maps (void);
608 void init_cgraph (void);
609 struct cgraph_node
* cgraph_copy_node_for_versioning (struct cgraph_node
*,
610 tree
, VEC(cgraph_edge_p
,heap
)*, bitmap
);
611 struct cgraph_node
*cgraph_function_versioning (struct cgraph_node
*,
612 VEC(cgraph_edge_p
,heap
)*,
613 VEC(ipa_replace_map_p
,gc
)*,
614 bitmap
, bool, bitmap
,
615 basic_block
, const char *);
616 void tree_function_versioning (tree
, tree
, VEC (ipa_replace_map_p
,gc
)*,
617 bool, bitmap
, bool, bitmap
, basic_block
);
618 void record_references_in_initializer (tree
, bool);
619 bool cgraph_process_new_functions (void);
620 void cgraph_process_same_body_aliases (void);
622 bool cgraph_decide_is_function_needed (struct cgraph_node
*, tree
);
624 typedef void (*cgraph_edge_hook
)(struct cgraph_edge
*, void *);
625 typedef void (*cgraph_node_hook
)(struct cgraph_node
*, void *);
626 typedef void (*cgraph_2edge_hook
)(struct cgraph_edge
*, struct cgraph_edge
*,
628 typedef void (*cgraph_2node_hook
)(struct cgraph_node
*, struct cgraph_node
*,
630 struct cgraph_edge_hook_list
;
631 struct cgraph_node_hook_list
;
632 struct cgraph_2edge_hook_list
;
633 struct cgraph_2node_hook_list
;
634 struct cgraph_edge_hook_list
*cgraph_add_edge_removal_hook (cgraph_edge_hook
, void *);
635 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list
*);
636 struct cgraph_node_hook_list
*cgraph_add_node_removal_hook (cgraph_node_hook
,
638 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list
*);
639 struct cgraph_node_hook_list
*cgraph_add_function_insertion_hook (cgraph_node_hook
,
641 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list
*);
642 void cgraph_call_function_insertion_hooks (struct cgraph_node
*node
);
643 struct cgraph_2edge_hook_list
*cgraph_add_edge_duplication_hook (cgraph_2edge_hook
, void *);
644 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list
*);
645 struct cgraph_2node_hook_list
*cgraph_add_node_duplication_hook (cgraph_2node_hook
, void *);
646 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list
*);
647 gimple
cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge
*);
648 bool cgraph_propagate_frequency (struct cgraph_node
*node
);
649 /* In cgraphbuild.c */
650 unsigned int rebuild_cgraph_edges (void);
651 void cgraph_rebuild_references (void);
652 int compute_call_stmt_bb_frequency (tree
, basic_block bb
);
655 bool cgraph_remove_unreachable_nodes (bool, FILE *);
656 cgraph_node_set
cgraph_node_set_new (void);
657 cgraph_node_set_iterator
cgraph_node_set_find (cgraph_node_set
,
658 struct cgraph_node
*);
659 void cgraph_node_set_add (cgraph_node_set
, struct cgraph_node
*);
660 void cgraph_node_set_remove (cgraph_node_set
, struct cgraph_node
*);
661 void dump_cgraph_node_set (FILE *, cgraph_node_set
);
662 void debug_cgraph_node_set (cgraph_node_set
);
663 void free_cgraph_node_set (cgraph_node_set
);
665 varpool_node_set
varpool_node_set_new (void);
666 varpool_node_set_iterator
varpool_node_set_find (varpool_node_set
,
667 struct varpool_node
*);
668 void varpool_node_set_add (varpool_node_set
, struct varpool_node
*);
669 void varpool_node_set_remove (varpool_node_set
, struct varpool_node
*);
670 void dump_varpool_node_set (FILE *, varpool_node_set
);
671 void debug_varpool_node_set (varpool_node_set
);
672 void free_varpool_node_set (varpool_node_set
);
673 void ipa_discover_readonly_nonaddressable_vars (void);
674 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node
*);
675 bool varpool_externally_visible_p (struct varpool_node
*, bool);
678 bool cgraph_maybe_hot_edge_p (struct cgraph_edge
*e
);
679 bool cgraph_optimize_for_size_p (struct cgraph_node
*);
682 extern GTY(()) symtab_node x_varpool_nodes_queue
;
683 #define varpool_nodes_queue ((struct varpool_node *)x_varpool_nodes_queue)
685 struct varpool_node
*varpool_node (tree
);
686 struct varpool_node
*varpool_node_for_asm (tree asmname
);
687 void varpool_mark_needed_node (struct varpool_node
*);
688 void debug_varpool (void);
689 void dump_varpool (FILE *);
690 void dump_varpool_node (FILE *, struct varpool_node
*);
692 void varpool_finalize_decl (tree
);
693 bool decide_is_variable_needed (struct varpool_node
*, tree
);
694 enum availability
cgraph_variable_initializer_availability (struct varpool_node
*);
695 void cgraph_make_decl_local (tree
);
696 void cgraph_make_node_local (struct cgraph_node
*);
697 bool cgraph_node_can_be_local_p (struct cgraph_node
*);
700 struct varpool_node
* varpool_get_node (const_tree decl
);
701 void varpool_remove_node (struct varpool_node
*node
);
702 void varpool_finalize_named_section_flags (struct varpool_node
*node
);
703 bool varpool_assemble_pending_decls (void);
704 bool varpool_assemble_decl (struct varpool_node
*node
);
705 bool varpool_analyze_pending_decls (void);
706 void varpool_remove_unreferenced_decls (void);
707 void varpool_empty_needed_queue (void);
708 struct varpool_node
* varpool_extra_name_alias (tree
, tree
);
709 struct varpool_node
* varpool_create_variable_alias (tree
, tree
);
710 const char * varpool_node_name (struct varpool_node
*node
);
711 void varpool_reset_queue (void);
712 bool const_value_known_p (tree
);
713 bool varpool_for_node_and_aliases (struct varpool_node
*,
714 bool (*) (struct varpool_node
*, void *),
716 void varpool_add_new_variable (tree
);
718 /* Return true when NODE is function. */
720 symtab_function_p (symtab_node node
)
722 return node
->symbol
.type
== SYMTAB_FUNCTION
;
725 /* Return true when NODE is variable. */
727 symtab_variable_p (symtab_node node
)
729 return node
->symbol
.type
== SYMTAB_VARIABLE
;
732 /* Return callgraph node for given symbol and check it is a function. */
733 static inline struct cgraph_node
*
734 cgraph (symtab_node node
)
736 gcc_checking_assert (!node
|| node
->symbol
.type
== SYMTAB_FUNCTION
);
737 return &node
->x_function
;
740 /* Return varpool node for given symbol and check it is a variable. */
741 static inline struct varpool_node
*
742 varpool (symtab_node node
)
744 gcc_checking_assert (!node
|| node
->symbol
.type
== SYMTAB_VARIABLE
);
745 return &node
->x_variable
;
749 /* Return first reachable static variable with initializer. */
750 static inline struct varpool_node
*
751 varpool_first_static_initializer (void)
753 struct varpool_node
*node
;
754 for (node
= varpool_nodes_queue
; node
; node
= node
->next_needed
)
756 gcc_checking_assert (TREE_CODE (node
->symbol
.decl
) == VAR_DECL
);
757 if (DECL_INITIAL (node
->symbol
.decl
))
763 /* Return next reachable static variable with initializer after NODE. */
764 static inline struct varpool_node
*
765 varpool_next_static_initializer (struct varpool_node
*node
)
767 for (node
= node
->next_needed
; node
; node
= node
->next_needed
)
769 gcc_checking_assert (TREE_CODE (node
->symbol
.decl
) == VAR_DECL
);
770 if (DECL_INITIAL (node
->symbol
.decl
))
776 /* Walk all reachable static variables. */
777 #define FOR_EACH_STATIC_VARIABLE(node) \
778 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
779 /* Walk all static variables with initializer set. */
780 #define FOR_EACH_STATIC_INITIALIZER(node) \
781 for ((node) = varpool_first_static_initializer (); (node); \
782 (node) = varpool_next_static_initializer (node))
784 /* Return first variable. */
785 static inline struct varpool_node
*
786 varpool_first_variable (void)
789 for (node
= symtab_nodes
; node
; node
= node
->symbol
.next
)
791 if (symtab_variable_p (node
))
792 return varpool (node
);
797 /* Return next variable after NODE. */
798 static inline struct varpool_node
*
799 varpool_next_variable (struct varpool_node
*node
)
801 symtab_node node1
= (symtab_node
) node
->symbol
.next
;
802 for (; node1
; node1
= node1
->symbol
.next
)
804 if (symtab_variable_p (node1
))
805 return varpool (node1
);
809 /* Walk all variables. */
810 #define FOR_EACH_VARIABLE(node) \
811 for ((node) = varpool_first_variable (); \
813 (node) = varpool_next_variable ((node)))
814 /* Walk all variables with definitions in current unit. */
815 #define FOR_EACH_DEFINED_VARIABLE(node) \
816 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
818 /* Return first function with body defined. */
819 static inline struct cgraph_node
*
820 cgraph_first_defined_function (void)
823 for (node
= symtab_nodes
; node
; node
= node
->symbol
.next
)
825 if (symtab_function_p (node
) && cgraph (node
)->analyzed
)
826 return cgraph (node
);
831 /* Return next function with body defined after NODE. */
832 static inline struct cgraph_node
*
833 cgraph_next_defined_function (struct cgraph_node
*node
)
835 symtab_node node1
= (symtab_node
) node
->symbol
.next
;
836 for (; node1
; node1
= node1
->symbol
.next
)
838 if (symtab_function_p (node1
) && cgraph (node1
)->analyzed
)
839 return cgraph (node1
);
844 /* Walk all functions with body defined. */
845 #define FOR_EACH_DEFINED_FUNCTION(node) \
846 for ((node) = cgraph_first_defined_function (); (node); \
847 (node) = cgraph_next_defined_function ((node)))
849 /* Return first function. */
850 static inline struct cgraph_node
*
851 cgraph_first_function (void)
854 for (node
= symtab_nodes
; node
; node
= node
->symbol
.next
)
856 if (symtab_function_p (node
))
857 return cgraph (node
);
862 /* Return next function. */
863 static inline struct cgraph_node
*
864 cgraph_next_function (struct cgraph_node
*node
)
866 symtab_node node1
= (symtab_node
) node
->symbol
.next
;
867 for (; node1
; node1
= node1
->symbol
.next
)
869 if (symtab_function_p (node1
))
870 return cgraph (node1
);
874 /* Walk all functions. */
875 #define FOR_EACH_FUNCTION(node) \
876 for ((node) = cgraph_first_function (); (node); \
877 (node) = cgraph_next_function ((node)))
879 /* Return true when NODE is a function with Gimple body defined
880 in current unit. Functions can also be define externally or they
881 can be thunks with no Gimple representation.
883 Note that at WPA stage, the function body may not be present in memory. */
886 cgraph_function_with_gimple_body_p (struct cgraph_node
*node
)
888 return node
->analyzed
&& !node
->thunk
.thunk_p
&& !node
->alias
;
891 /* Return first function with body defined. */
892 static inline struct cgraph_node
*
893 cgraph_first_function_with_gimple_body (void)
896 for (node
= symtab_nodes
; node
; node
= node
->symbol
.next
)
898 if (symtab_function_p (node
)
899 && cgraph_function_with_gimple_body_p (cgraph (node
)))
900 return cgraph (node
);
905 /* Return next reachable static variable with initializer after NODE. */
906 static inline struct cgraph_node
*
907 cgraph_next_function_with_gimple_body (struct cgraph_node
*node
)
909 symtab_node node1
= node
->symbol
.next
;
910 for (; node1
; node1
= node1
->symbol
.next
)
912 if (symtab_function_p (node1
)
913 && cgraph_function_with_gimple_body_p (cgraph (node1
)))
914 return cgraph (node1
);
919 /* Walk all functions with body defined. */
920 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
921 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
922 (node) = cgraph_next_function_with_gimple_body (node))
924 /* Create a new static variable of type TYPE. */
925 tree
add_new_static_var (tree type
);
927 /* Return true if iterator CSI points to nothing. */
929 csi_end_p (cgraph_node_set_iterator csi
)
931 return csi
.index
>= VEC_length (cgraph_node_ptr
, csi
.set
->nodes
);
934 /* Advance iterator CSI. */
936 csi_next (cgraph_node_set_iterator
*csi
)
941 /* Return the node pointed to by CSI. */
942 static inline struct cgraph_node
*
943 csi_node (cgraph_node_set_iterator csi
)
945 return VEC_index (cgraph_node_ptr
, csi
.set
->nodes
, csi
.index
);
948 /* Return an iterator to the first node in SET. */
949 static inline cgraph_node_set_iterator
950 csi_start (cgraph_node_set set
)
952 cgraph_node_set_iterator csi
;
959 /* Return true if SET contains NODE. */
961 cgraph_node_in_set_p (struct cgraph_node
*node
, cgraph_node_set set
)
963 cgraph_node_set_iterator csi
;
964 csi
= cgraph_node_set_find (set
, node
);
965 return !csi_end_p (csi
);
968 /* Return number of nodes in SET. */
970 cgraph_node_set_size (cgraph_node_set set
)
972 return VEC_length (cgraph_node_ptr
, set
->nodes
);
975 /* Return true if iterator VSI points to nothing. */
977 vsi_end_p (varpool_node_set_iterator vsi
)
979 return vsi
.index
>= VEC_length (varpool_node_ptr
, vsi
.set
->nodes
);
982 /* Advance iterator VSI. */
984 vsi_next (varpool_node_set_iterator
*vsi
)
989 /* Return the node pointed to by VSI. */
990 static inline struct varpool_node
*
991 vsi_node (varpool_node_set_iterator vsi
)
993 return VEC_index (varpool_node_ptr
, vsi
.set
->nodes
, vsi
.index
);
996 /* Return an iterator to the first node in SET. */
997 static inline varpool_node_set_iterator
998 vsi_start (varpool_node_set set
)
1000 varpool_node_set_iterator vsi
;
1007 /* Return true if SET contains NODE. */
1009 varpool_node_in_set_p (struct varpool_node
*node
, varpool_node_set set
)
1011 varpool_node_set_iterator vsi
;
1012 vsi
= varpool_node_set_find (set
, node
);
1013 return !vsi_end_p (vsi
);
1016 /* Return number of nodes in SET. */
1017 static inline size_t
1018 varpool_node_set_size (varpool_node_set set
)
1020 return VEC_length (varpool_node_ptr
, set
->nodes
);
1023 /* Uniquize all constants that appear in memory.
1024 Each constant in memory thus far output is recorded
1025 in `const_desc_table'. */
1027 struct GTY(()) constant_descriptor_tree
{
1028 /* A MEM for the constant. */
1031 /* The value of the constant. */
1034 /* Hash of value. Computing the hash from value each time
1035 hashfn is called can't work properly, as that means recursive
1036 use of the hash table during hash table expansion. */
1040 /* Return true if set is nonempty. */
1042 cgraph_node_set_nonempty_p (cgraph_node_set set
)
1044 return !VEC_empty (cgraph_node_ptr
, set
->nodes
);
1047 /* Return true if set is nonempty. */
1049 varpool_node_set_nonempty_p (varpool_node_set set
)
1051 return !VEC_empty (varpool_node_ptr
, set
->nodes
);
1054 /* Return true when function NODE is only called directly or it has alias.
1055 i.e. it is not externally visible, address was not taken and
1056 it is not used in any other non-standard way. */
1059 cgraph_only_called_directly_or_aliased_p (struct cgraph_node
*node
)
1061 gcc_assert (!node
->global
.inlined_to
);
1062 return (!node
->needed
&& !node
->symbol
.address_taken
1063 && !node
->symbol
.used_from_other_partition
1064 && !DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
)
1065 && !DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
)
1066 && !node
->symbol
.externally_visible
);
1069 /* Return true when function NODE can be removed from callgraph
1070 if all direct calls are eliminated. */
1073 varpool_can_remove_if_no_refs (struct varpool_node
*node
)
1075 return (!node
->force_output
&& !node
->symbol
.used_from_other_partition
1076 && (DECL_COMDAT (node
->symbol
.decl
)
1077 || !node
->symbol
.externally_visible
));
1080 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1081 i.e. if the variable is not externally visible or not used in some magic
1082 way (asm statement or such).
1083 The magic uses are all summarized in force_output flag. */
1086 varpool_all_refs_explicit_p (struct varpool_node
*vnode
)
1088 return (vnode
->analyzed
1089 && !vnode
->symbol
.externally_visible
1090 && !vnode
->symbol
.used_from_other_partition
1091 && !vnode
->force_output
);
1094 /* Constant pool accessor function. */
1095 htab_t
constant_pool_htab (void);
1097 /* FIXME: inappropriate dependency of cgraph on IPA. */
1098 #include "ipa-ref-inline.h"
1100 /* Return node that alias N is aliasing. */
1102 static inline struct cgraph_node
*
1103 cgraph_alias_aliased_node (struct cgraph_node
*n
)
1105 struct ipa_ref
*ref
;
1107 ipa_ref_list_reference_iterate (&n
->symbol
.ref_list
, 0, ref
);
1108 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1109 if (ref
->refered_type
== IPA_REF_CGRAPH
)
1110 return ipa_ref_node (ref
);
1114 /* Return node that alias N is aliasing. */
1116 static inline struct varpool_node
*
1117 varpool_alias_aliased_node (struct varpool_node
*n
)
1119 struct ipa_ref
*ref
;
1121 ipa_ref_list_reference_iterate (&n
->symbol
.ref_list
, 0, ref
);
1122 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1123 if (ref
->refered_type
== IPA_REF_VARPOOL
)
1124 return ipa_ref_varpool_node (ref
);
1128 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1129 Walk through thunk, too.
1130 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1132 static inline struct cgraph_node
*
1133 cgraph_function_node (struct cgraph_node
*node
, enum availability
*availability
)
1136 *availability
= cgraph_function_body_availability (node
);
1139 if (node
->alias
&& node
->analyzed
)
1140 node
= cgraph_alias_aliased_node (node
);
1141 else if (node
->thunk
.thunk_p
)
1142 node
= node
->callees
->callee
;
1145 if (node
&& availability
)
1147 enum availability a
;
1148 a
= cgraph_function_body_availability (node
);
1149 if (a
< *availability
)
1154 *availability
= AVAIL_NOT_AVAILABLE
;
1158 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1159 Do not walk through thunks.
1160 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1162 static inline struct cgraph_node
*
1163 cgraph_function_or_thunk_node (struct cgraph_node
*node
, enum availability
*availability
)
1166 *availability
= cgraph_function_body_availability (node
);
1169 if (node
->alias
&& node
->analyzed
)
1170 node
= cgraph_alias_aliased_node (node
);
1173 if (node
&& availability
)
1175 enum availability a
;
1176 a
= cgraph_function_body_availability (node
);
1177 if (a
< *availability
)
1182 *availability
= AVAIL_NOT_AVAILABLE
;
1186 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1187 Do not walk through thunks.
1188 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1190 static inline struct varpool_node
*
1191 varpool_variable_node (struct varpool_node
*node
, enum availability
*availability
)
1194 *availability
= cgraph_variable_initializer_availability (node
);
1197 if (node
->alias
&& node
->analyzed
)
1198 node
= varpool_alias_aliased_node (node
);
1201 if (node
&& availability
)
1203 enum availability a
;
1204 a
= cgraph_variable_initializer_availability (node
);
1205 if (a
< *availability
)
1210 *availability
= AVAIL_NOT_AVAILABLE
;
1214 /* Return true when the edge E represents a direct recursion. */
1216 cgraph_edge_recursive_p (struct cgraph_edge
*e
)
1218 struct cgraph_node
*callee
= cgraph_function_or_thunk_node (e
->callee
, NULL
);
1219 if (e
->caller
->global
.inlined_to
)
1220 return e
->caller
->global
.inlined_to
->symbol
.decl
== callee
->symbol
.decl
;
1222 return e
->caller
->symbol
.decl
== callee
->symbol
.decl
;
1225 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1227 decl_is_tm_clone (const_tree fndecl
)
1229 struct cgraph_node
*n
= cgraph_get_node (fndecl
);
1234 #endif /* GCC_CGRAPH_H */