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
;
62 /* Set when function has address taken.
63 In current implementation it imply needed flag. */
64 unsigned address_taken
: 1;
65 /* Set when variable is used from other LTRANS partition. */
66 unsigned used_from_other_partition
: 1;
67 /* Set when function is available in the other LTRANS partition.
68 During WPA output it is used to mark nodes that are present in
69 multiple partitions. */
70 unsigned in_other_partition
: 1;
71 /* Set when function is visible by other units. */
72 unsigned externally_visible
: 1;
77 /* Not yet set by cgraph_function_body_availability. */
79 /* Function body/variable initializer is unknown. */
81 /* Function body/variable initializer is known but might be replaced
82 by a different one from other compilation unit and thus needs to
83 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
84 arbitrary side effects on escaping variables and functions, while
85 like AVAILABLE it might access static variables. */
87 /* Function body/variable initializer is known and will be used in final
90 /* Function body/variable initializer is known and all it's uses are explicitly
91 visible within current unit (ie it's address is never taken and it is not
92 exported to other units).
93 Currently used only for functions. */
97 /* This is the information that is put into the cgraph local structure
98 to recover a function. */
99 struct lto_file_decl_data
;
101 extern const char * const cgraph_availability_names
[];
102 extern const char * const ld_plugin_symbol_resolution_names
[];
104 /* Information about thunk, used only for same body aliases. */
106 struct GTY(()) cgraph_thunk_info
{
107 /* Information about the thunk. */
108 HOST_WIDE_INT fixed_offset
;
109 HOST_WIDE_INT virtual_value
;
112 bool virtual_offset_p
;
113 /* Set to true when alias node is thunk. */
117 /* Information about the function collected locally.
118 Available after function is analyzed. */
120 struct GTY(()) cgraph_local_info
{
121 /* Set when function function is visible in current compilation unit only
122 and its address is never taken. */
125 /* Set once it has been finalized so we consider it to be output. */
126 unsigned finalized
: 1;
128 /* False when there is something makes versioning impossible. */
129 unsigned versionable
: 1;
131 /* False when function calling convention and signature can not be changed.
132 This is the case when __builtin_apply_args is used. */
133 unsigned can_change_signature
: 1;
135 /* True when the function has been originally extern inline, but it is
137 unsigned redefined_extern_inline
: 1;
139 /* True if the function may enter serial irrevocable mode. */
140 unsigned tm_may_enter_irr
: 1;
143 /* Information about the function that needs to be computed globally
144 once compilation is finished. Available only with -funit-at-a-time. */
146 struct GTY(()) cgraph_global_info
{
147 /* For inline clones this points to the function they will be
149 struct cgraph_node
*inlined_to
;
152 /* Information about the function that is propagated by the RTL backend.
153 Available only for functions that has been already assembled. */
155 struct GTY(()) cgraph_rtl_info
{
156 unsigned int preferred_incoming_stack_boundary
;
159 /* Represent which DECL tree (or reference to such tree)
160 will be replaced by another tree while versioning. */
161 struct GTY(()) ipa_replace_map
163 /* The tree that will be replaced. */
165 /* The new (replacing) tree. */
167 /* Parameter number to replace, when old_tree is NULL. */
169 /* True when a substitution should be done, false otherwise. */
171 /* True when we replace a reference to old_tree. */
174 typedef struct ipa_replace_map
*ipa_replace_map_p
;
175 DEF_VEC_P(ipa_replace_map_p
);
176 DEF_VEC_ALLOC_P(ipa_replace_map_p
,gc
);
178 struct GTY(()) cgraph_clone_info
180 VEC(ipa_replace_map_p
,gc
)* tree_map
;
182 bitmap combined_args_to_skip
;
186 /* The cgraph data structure.
187 Each function decl has assigned cgraph_node listing callees and callers. */
189 struct GTY(()) cgraph_node
{
190 struct symtab_node_base symbol
;
191 struct cgraph_edge
*callees
;
192 struct cgraph_edge
*callers
;
194 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
197 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
199 /* List of edges representing indirect calls with a yet undetermined
201 struct cgraph_edge
*indirect_calls
;
202 /* For nested functions points to function the node is nested in. */
204 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
206 /* Points to first nested function, if any. */
208 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
210 /* Pointer to the next function with same origin, if any. */
212 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
214 /* Pointer to the next function in cgraph_nodes_queue. */
216 GTY ((nested_ptr (union symtab_node_def
, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
218 /* Pointer to the next clone. */
219 struct cgraph_node
*next_sibling_clone
;
220 struct cgraph_node
*prev_sibling_clone
;
221 struct cgraph_node
*clones
;
222 struct cgraph_node
*clone_of
;
223 /* For functions with many calls sites it holds map from call expression
224 to the edge to speed up cgraph_edge function. */
225 htab_t
GTY((param_is (struct cgraph_edge
))) call_site_hash
;
226 /* Declaration node used to be clone of. */
227 tree former_clone_of
;
229 /* Interprocedural passes scheduled to have their transform functions
230 applied next time we execute local pass on them. We maintain it
231 per-function in order to allow IPA passes to introduce new functions. */
232 VEC(ipa_opt_pass
,heap
) * GTY((skip
)) ipa_transforms_to_apply
;
234 struct cgraph_local_info local
;
235 struct cgraph_global_info global
;
236 struct cgraph_rtl_info rtl
;
237 struct cgraph_clone_info clone
;
238 struct cgraph_thunk_info thunk
;
240 /* Expected number of executions: calculated in profile.c. */
242 /* How to scale counts at materialization time; used to merge
243 LTO units with different number of profile runs. */
244 int count_materialization_scale
;
245 /* Unique id of the node. */
248 /* Set when function must be output for some reason. The primary
249 use of this flag is to mark functions needed to be output for
250 non-standard reason. Functions that are externally visible
251 or reachable from functions needed to be output are marked
252 by specialized flags. */
254 /* Set when decl is an abstract function pointed to by the
255 ABSTRACT_DECL_ORIGIN of a reachable function. */
256 unsigned abstract_and_needed
: 1;
257 /* Set when function is reachable by call from other function
258 that is either reachable or needed.
259 This flag is computed at original cgraph construction and then
260 updated in cgraph_remove_unreachable_nodes. Note that after
261 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
262 nodes when they are needed for virtual clone instantiation. */
263 unsigned reachable
: 1;
264 /* Set once the function is lowered (i.e. its CFG is built). */
265 unsigned lowered
: 1;
266 /* Set once the function has been instantiated and its callee
268 unsigned analyzed
: 1;
269 /* Set when function is scheduled to be processed by local passes. */
270 unsigned process
: 1;
271 /* Set for aliases once they got through assemble_alias. */
273 /* Set for aliases created as C++ same body aliases. */
274 unsigned same_body_alias
: 1;
275 /* How commonly executed the node is. Initialized during branch
276 probabilities pass. */
277 ENUM_BITFIELD (node_frequency
) frequency
: 2;
278 /* True when function can only be called at startup (from static ctor). */
279 unsigned only_called_at_startup
: 1;
280 /* True when function can only be called at startup (from static dtor). */
281 unsigned only_called_at_exit
: 1;
282 /* True when function is the transactional clone of a function which
283 is called only from inside transactions. */
284 /* ?? We should be able to remove this. We have enough bits in
285 cgraph to calculate it. */
286 unsigned tm_clone
: 1;
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 /* Offset accumulated from ancestor jump functions of inlined call graph
356 HOST_WIDE_INT anc_offset
;
357 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
358 HOST_WIDE_INT otr_token
;
359 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
361 /* Index of the parameter that is called. */
363 /* ECF flags determined from the caller. */
366 /* Set when the call is a virtual call with the parameter being the
367 associated object pointer rather than a simple direct call. */
368 unsigned polymorphic
: 1;
371 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge
{
372 /* Expected number of executions: calculated in profile.c. */
374 struct cgraph_node
*caller
;
375 struct cgraph_node
*callee
;
376 struct cgraph_edge
*prev_caller
;
377 struct cgraph_edge
*next_caller
;
378 struct cgraph_edge
*prev_callee
;
379 struct cgraph_edge
*next_callee
;
381 /* Additional information about an indirect call. Not cleared when an edge
383 struct cgraph_indirect_call_info
*indirect_info
;
384 PTR
GTY ((skip (""))) aux
;
385 /* When equal to CIF_OK, inline this call. Otherwise, points to the
386 explanation why function was not inlined. */
387 cgraph_inline_failed_t inline_failed
;
388 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
389 when the function is serialized in. */
390 unsigned int lto_stmt_uid
;
391 /* Expected frequency of executions within the function.
392 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
393 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
395 /* Unique id of the edge. */
397 /* Whether this edge was made direct by indirect inlining. */
398 unsigned int indirect_inlining_edge
: 1;
399 /* Whether this edge describes an indirect call with an undetermined
401 unsigned int indirect_unknown_callee
: 1;
402 /* Whether this edge is still a dangling */
403 /* True if the corresponding CALL stmt cannot be inlined. */
404 unsigned int call_stmt_cannot_inline_p
: 1;
405 /* Can this call throw externally? */
406 unsigned int can_throw_external
: 1;
409 #define CGRAPH_FREQ_BASE 1000
410 #define CGRAPH_FREQ_MAX 100000
412 typedef struct cgraph_edge
*cgraph_edge_p
;
414 DEF_VEC_P(cgraph_edge_p
);
415 DEF_VEC_ALLOC_P(cgraph_edge_p
,heap
);
417 /* The varpool data structure.
418 Each static variable decl has assigned varpool_node. */
420 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node
{
421 struct symtab_node_base symbol
;
422 /* For aliases points to declaration DECL is alias of. */
424 /* Pointer to the next function in varpool_nodes. */
425 struct varpool_node
*
426 GTY ((nested_ptr (union symtab_node_def
, "(struct varpool_node *)(%h)", "(symtab_node)%h")))
428 struct varpool_node
*
429 GTY ((nested_ptr (union symtab_node_def
, "(struct varpool_node *)(%h)", "(symtab_node)%h")))
431 /* Pointer to the next function in varpool_nodes_queue. */
432 struct varpool_node
*
433 GTY ((nested_ptr (union symtab_node_def
, "(struct varpool_node *)(%h)", "(symtab_node)%h")))
435 struct varpool_node
*
436 GTY ((nested_ptr (union symtab_node_def
, "(struct varpool_node *)(%h)", "(symtab_node)%h")))
439 /* Set when function must be output - it is externally visible
440 or its address is taken. */
442 /* Needed variables might become dead by optimization. This flag
443 forces the variable to be output even if it appears dead otherwise. */
444 unsigned force_output
: 1;
445 /* Set once the variable has been instantiated and its callee
447 unsigned analyzed
: 1;
448 /* Set once it has been finalized so we consider it to be output. */
449 unsigned finalized
: 1;
450 /* Set when variable is scheduled to be assembled. */
452 /* Set for aliases once they got through assemble_alias. Also set for
453 extra name aliases in varpool_extra_name_alias. */
455 unsigned extra_name_alias
: 1;
458 /* Every top level asm statement is put into a cgraph_asm_node. */
460 struct GTY(()) cgraph_asm_node
{
462 struct cgraph_asm_node
*next
;
463 /* String for this asm node. */
465 /* Ordering of all cgraph nodes. */
469 /* Symbol table entry. */
470 union GTY((desc ("%h.symbol.type"))) symtab_node_def
{
471 struct symtab_node_base
GTY ((tag ("SYMTAB_SYMBOL"))) symbol
;
472 /* Use cgraph (symbol) accessor to get cgraph_node. */
473 struct cgraph_node
GTY ((tag ("SYMTAB_FUNCTION"))) x_function
;
474 /* Use varpool (symbol) accessor to get varpool_node. */
475 struct varpool_node
GTY ((tag ("SYMTAB_VARIABLE"))) x_variable
;
478 extern GTY(()) symtab_node x_cgraph_nodes
;
479 #define cgraph_nodes ((struct cgraph_node *)x_cgraph_nodes)
480 extern GTY(()) int cgraph_n_nodes
;
481 extern GTY(()) int cgraph_max_uid
;
482 extern GTY(()) int cgraph_edge_max_uid
;
483 extern bool cgraph_global_info_ready
;
486 /* Callgraph is being constructed. It is safe to add new functions. */
487 CGRAPH_STATE_CONSTRUCTION
,
488 /* Callgraph is built and IPA passes are being run. */
490 /* Callgraph is built and all functions are transformed to SSA form. */
491 CGRAPH_STATE_IPA_SSA
,
492 /* Functions are now ordered and being passed to RTL expanders. */
493 CGRAPH_STATE_EXPANSION
,
494 /* All cgraph expansion is done. */
495 CGRAPH_STATE_FINISHED
497 extern enum cgraph_state cgraph_state
;
498 extern bool cgraph_function_flags_ready
;
499 extern GTY(()) symtab_node x_cgraph_nodes_queue
;
500 #define cgraph_nodes_queue ((struct cgraph_node *)x_cgraph_nodes_queue)
501 extern GTY(()) struct cgraph_node
*cgraph_new_nodes
;
503 extern GTY(()) struct cgraph_asm_node
*cgraph_asm_nodes
;
504 extern GTY(()) int cgraph_order
;
505 extern bool same_body_aliases_done
;
508 void dump_cgraph (FILE *);
509 void debug_cgraph (void);
510 void dump_cgraph_node (FILE *, struct cgraph_node
*);
511 void debug_cgraph_node (struct cgraph_node
*);
512 void cgraph_insert_node_to_hashtable (struct cgraph_node
*node
);
513 void cgraph_remove_edge (struct cgraph_edge
*);
514 void cgraph_remove_node (struct cgraph_node
*);
515 void cgraph_add_to_same_comdat_group (struct cgraph_node
*, struct cgraph_node
*);
516 bool cgraph_remove_node_and_inline_clones (struct cgraph_node
*, struct cgraph_node
*);
517 void cgraph_release_function_body (struct cgraph_node
*);
518 void cgraph_node_remove_callees (struct cgraph_node
*node
);
519 struct cgraph_edge
*cgraph_create_edge (struct cgraph_node
*,
520 struct cgraph_node
*,
521 gimple
, gcov_type
, int);
522 struct cgraph_edge
*cgraph_create_indirect_edge (struct cgraph_node
*, gimple
,
523 int, gcov_type
, int);
524 struct cgraph_indirect_call_info
*cgraph_allocate_init_indirect_info (void);
525 struct cgraph_node
* cgraph_get_node (const_tree
);
526 struct cgraph_node
* cgraph_create_node (tree
);
527 struct cgraph_node
* cgraph_get_create_node (tree
);
528 struct cgraph_node
* cgraph_same_body_alias (struct cgraph_node
*, tree
, tree
);
529 struct cgraph_node
* cgraph_add_thunk (struct cgraph_node
*, tree
, tree
, bool, HOST_WIDE_INT
,
530 HOST_WIDE_INT
, tree
, tree
);
531 struct cgraph_node
*cgraph_node_for_asm (tree
);
532 struct cgraph_edge
*cgraph_edge (struct cgraph_node
*, gimple
);
533 void cgraph_set_call_stmt (struct cgraph_edge
*, gimple
);
534 void cgraph_set_call_stmt_including_clones (struct cgraph_node
*, gimple
, gimple
);
535 void cgraph_create_edge_including_clones (struct cgraph_node
*,
536 struct cgraph_node
*,
537 gimple
, gimple
, gcov_type
, int,
538 cgraph_inline_failed_t
);
539 void cgraph_update_edges_for_call_stmt (gimple
, tree
, gimple
);
540 struct cgraph_local_info
*cgraph_local_info (tree
);
541 struct cgraph_global_info
*cgraph_global_info (tree
);
542 struct cgraph_rtl_info
*cgraph_rtl_info (tree
);
543 const char * cgraph_node_name (struct cgraph_node
*);
544 struct cgraph_edge
* cgraph_clone_edge (struct cgraph_edge
*,
545 struct cgraph_node
*, gimple
,
546 unsigned, gcov_type
, int, bool);
547 struct cgraph_node
* cgraph_clone_node (struct cgraph_node
*, tree
, gcov_type
,
548 int, bool, VEC(cgraph_edge_p
,heap
) *,
550 struct cgraph_node
*cgraph_create_function_alias (tree
, tree
);
551 void cgraph_call_node_duplication_hooks (struct cgraph_node
*node1
,
552 struct cgraph_node
*node2
);
554 void cgraph_redirect_edge_callee (struct cgraph_edge
*, struct cgraph_node
*);
555 void cgraph_make_edge_direct (struct cgraph_edge
*, struct cgraph_node
*);
556 bool cgraph_only_called_directly_p (struct cgraph_node
*);
558 struct cgraph_asm_node
*cgraph_add_asm_node (tree
);
560 bool cgraph_function_possibly_inlined_p (tree
);
561 void cgraph_unnest_node (struct cgraph_node
*);
563 enum availability
cgraph_function_body_availability (struct cgraph_node
*);
564 void cgraph_add_new_function (tree
, bool);
565 const char* cgraph_inline_failed_string (cgraph_inline_failed_t
);
566 struct cgraph_node
* cgraph_create_virtual_clone (struct cgraph_node
*old_node
,
567 VEC(cgraph_edge_p
,heap
)*,
568 VEC(ipa_replace_map_p
,gc
)* tree_map
,
570 const char *clone_name
);
572 void cgraph_set_nothrow_flag (struct cgraph_node
*, bool);
573 void cgraph_set_const_flag (struct cgraph_node
*, bool, bool);
574 void cgraph_set_pure_flag (struct cgraph_node
*, bool, bool);
575 tree
clone_function_name (tree decl
, const char *);
576 bool cgraph_node_cannot_return (struct cgraph_node
*);
577 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge
*);
578 bool cgraph_will_be_removed_from_program_if_no_direct_calls
579 (struct cgraph_node
*node
);
580 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
581 (struct cgraph_node
*node
);
582 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node
*node
);
583 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution
);
584 bool cgraph_used_from_object_file_p (struct cgraph_node
*);
585 bool varpool_used_from_object_file_p (struct varpool_node
*);
586 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node
*,
587 bool (*) (struct cgraph_node
*, void *),
590 bool cgraph_for_node_and_aliases (struct cgraph_node
*,
591 bool (*) (struct cgraph_node
*, void *),
593 VEC (cgraph_edge_p
, heap
) * collect_callers_of_node (struct cgraph_node
*node
);
596 /* In cgraphunit.c */
597 extern FILE *cgraph_dump_file
;
598 void cgraph_finalize_function (tree
, bool);
599 void cgraph_mark_if_needed (tree
);
600 void cgraph_analyze_function (struct cgraph_node
*);
601 void cgraph_finalize_compilation_unit (void);
602 void cgraph_optimize (void);
603 void cgraph_mark_needed_node (struct cgraph_node
*);
604 void cgraph_mark_address_taken_node (struct cgraph_node
*);
605 void cgraph_mark_reachable_node (struct cgraph_node
*);
606 bool cgraph_inline_p (struct cgraph_edge
*, cgraph_inline_failed_t
*reason
);
607 bool cgraph_preserve_function_body_p (struct cgraph_node
*);
608 void verify_cgraph (void);
609 void verify_cgraph_node (struct cgraph_node
*);
610 void cgraph_build_static_cdtor (char which
, tree body
, int priority
);
611 void cgraph_reset_static_var_maps (void);
612 void init_cgraph (void);
613 struct cgraph_node
* cgraph_copy_node_for_versioning (struct cgraph_node
*,
614 tree
, VEC(cgraph_edge_p
,heap
)*, bitmap
);
615 struct cgraph_node
*cgraph_function_versioning (struct cgraph_node
*,
616 VEC(cgraph_edge_p
,heap
)*,
617 VEC(ipa_replace_map_p
,gc
)*,
618 bitmap
, bool, bitmap
,
619 basic_block
, const char *);
620 void tree_function_versioning (tree
, tree
, VEC (ipa_replace_map_p
,gc
)*,
621 bool, bitmap
, bool, bitmap
, basic_block
);
622 void record_references_in_initializer (tree
, bool);
623 bool cgraph_process_new_functions (void);
624 void cgraph_process_same_body_aliases (void);
626 bool cgraph_decide_is_function_needed (struct cgraph_node
*, tree
);
628 typedef void (*cgraph_edge_hook
)(struct cgraph_edge
*, void *);
629 typedef void (*cgraph_node_hook
)(struct cgraph_node
*, void *);
630 typedef void (*cgraph_2edge_hook
)(struct cgraph_edge
*, struct cgraph_edge
*,
632 typedef void (*cgraph_2node_hook
)(struct cgraph_node
*, struct cgraph_node
*,
634 struct cgraph_edge_hook_list
;
635 struct cgraph_node_hook_list
;
636 struct cgraph_2edge_hook_list
;
637 struct cgraph_2node_hook_list
;
638 struct cgraph_edge_hook_list
*cgraph_add_edge_removal_hook (cgraph_edge_hook
, void *);
639 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list
*);
640 struct cgraph_node_hook_list
*cgraph_add_node_removal_hook (cgraph_node_hook
,
642 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list
*);
643 struct cgraph_node_hook_list
*cgraph_add_function_insertion_hook (cgraph_node_hook
,
645 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list
*);
646 void cgraph_call_function_insertion_hooks (struct cgraph_node
*node
);
647 struct cgraph_2edge_hook_list
*cgraph_add_edge_duplication_hook (cgraph_2edge_hook
, void *);
648 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list
*);
649 struct cgraph_2node_hook_list
*cgraph_add_node_duplication_hook (cgraph_2node_hook
, void *);
650 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list
*);
651 gimple
cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge
*);
652 bool cgraph_propagate_frequency (struct cgraph_node
*node
);
653 /* In cgraphbuild.c */
654 unsigned int rebuild_cgraph_edges (void);
655 void cgraph_rebuild_references (void);
656 int compute_call_stmt_bb_frequency (tree
, basic_block bb
);
659 bool cgraph_remove_unreachable_nodes (bool, FILE *);
660 cgraph_node_set
cgraph_node_set_new (void);
661 cgraph_node_set_iterator
cgraph_node_set_find (cgraph_node_set
,
662 struct cgraph_node
*);
663 void cgraph_node_set_add (cgraph_node_set
, struct cgraph_node
*);
664 void cgraph_node_set_remove (cgraph_node_set
, struct cgraph_node
*);
665 void dump_cgraph_node_set (FILE *, cgraph_node_set
);
666 void debug_cgraph_node_set (cgraph_node_set
);
667 void free_cgraph_node_set (cgraph_node_set
);
669 varpool_node_set
varpool_node_set_new (void);
670 varpool_node_set_iterator
varpool_node_set_find (varpool_node_set
,
671 struct varpool_node
*);
672 void varpool_node_set_add (varpool_node_set
, struct varpool_node
*);
673 void varpool_node_set_remove (varpool_node_set
, struct varpool_node
*);
674 void dump_varpool_node_set (FILE *, varpool_node_set
);
675 void debug_varpool_node_set (varpool_node_set
);
676 void free_varpool_node_set (varpool_node_set
);
677 void ipa_discover_readonly_nonaddressable_vars (void);
678 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node
*);
679 bool varpool_externally_visible_p (struct varpool_node
*, bool);
682 bool cgraph_maybe_hot_edge_p (struct cgraph_edge
*e
);
683 bool cgraph_optimize_for_size_p (struct cgraph_node
*);
686 extern GTY(()) symtab_node x_varpool_nodes_queue
;
687 extern GTY(()) symtab_node x_varpool_nodes
;
688 #define varpool_nodes_queue ((struct varpool_node *)x_varpool_nodes_queue)
689 #define varpool_nodes ((struct varpool_node *)x_varpool_nodes)
691 struct varpool_node
*varpool_node (tree
);
692 struct varpool_node
*varpool_node_for_asm (tree asmname
);
693 void varpool_mark_needed_node (struct varpool_node
*);
694 void debug_varpool (void);
695 void dump_varpool (FILE *);
696 void dump_varpool_node (FILE *, struct varpool_node
*);
698 void varpool_finalize_decl (tree
);
699 bool decide_is_variable_needed (struct varpool_node
*, tree
);
700 enum availability
cgraph_variable_initializer_availability (struct varpool_node
*);
701 void cgraph_make_decl_local (tree
);
702 void cgraph_make_node_local (struct cgraph_node
*);
703 bool cgraph_node_can_be_local_p (struct cgraph_node
*);
706 struct varpool_node
* varpool_get_node (const_tree decl
);
707 void varpool_remove_node (struct varpool_node
*node
);
708 void varpool_finalize_named_section_flags (struct varpool_node
*node
);
709 bool varpool_assemble_pending_decls (void);
710 bool varpool_assemble_decl (struct varpool_node
*node
);
711 bool varpool_analyze_pending_decls (void);
712 void varpool_remove_unreferenced_decls (void);
713 void varpool_empty_needed_queue (void);
714 struct varpool_node
* varpool_extra_name_alias (tree
, tree
);
715 struct varpool_node
* varpool_create_variable_alias (tree
, tree
);
716 const char * varpool_node_name (struct varpool_node
*node
);
717 void varpool_reset_queue (void);
718 bool const_value_known_p (tree
);
719 bool varpool_for_node_and_aliases (struct varpool_node
*,
720 bool (*) (struct varpool_node
*, void *),
722 void varpool_add_new_variable (tree
);
724 /* Walk all reachable static variables. */
725 #define FOR_EACH_STATIC_VARIABLE(node) \
726 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
728 /* Return callgraph node for given symbol and check it is a function. */
729 static inline struct cgraph_node
*
730 cgraph (symtab_node node
)
732 gcc_checking_assert (!node
|| node
->symbol
.type
== SYMTAB_FUNCTION
);
733 return &node
->x_function
;
736 /* Return varpool node for given symbol and check it is a variable. */
737 static inline struct varpool_node
*
738 varpool (symtab_node node
)
740 gcc_checking_assert (!node
|| node
->symbol
.type
== SYMTAB_VARIABLE
);
741 return &node
->x_variable
;
745 /* Return first reachable static variable with initializer. */
746 static inline struct varpool_node
*
747 varpool_first_static_initializer (void)
749 struct varpool_node
*node
;
750 for (node
= varpool_nodes_queue
; node
; node
= node
->next_needed
)
752 gcc_checking_assert (TREE_CODE (node
->symbol
.decl
) == VAR_DECL
);
753 if (DECL_INITIAL (node
->symbol
.decl
))
759 /* Return next reachable static variable with initializer after NODE. */
760 static inline struct varpool_node
*
761 varpool_next_static_initializer (struct varpool_node
*node
)
763 for (node
= node
->next_needed
; node
; node
= node
->next_needed
)
765 gcc_checking_assert (TREE_CODE (node
->symbol
.decl
) == VAR_DECL
);
766 if (DECL_INITIAL (node
->symbol
.decl
))
772 /* Walk all static variables with initializer set. */
773 #define FOR_EACH_STATIC_INITIALIZER(node) \
774 for ((node) = varpool_first_static_initializer (); (node); \
775 (node) = varpool_next_static_initializer (node))
777 /* Return first function with body defined. */
778 static inline struct cgraph_node
*
779 cgraph_first_defined_function (void)
781 struct cgraph_node
*node
;
782 for (node
= cgraph_nodes
; node
; node
= node
->next
)
790 /* Return next function with body defined after NODE. */
791 static inline struct cgraph_node
*
792 cgraph_next_defined_function (struct cgraph_node
*node
)
794 for (node
= node
->next
; node
; node
= node
->next
)
802 /* Walk all functions with body defined. */
803 #define FOR_EACH_DEFINED_FUNCTION(node) \
804 for ((node) = cgraph_first_defined_function (); (node); \
805 (node) = cgraph_next_defined_function (node))
808 /* Return true when NODE is a function with Gimple body defined
809 in current unit. Functions can also be define externally or they
810 can be thunks with no Gimple representation.
812 Note that at WPA stage, the function body may not be present in memory. */
815 cgraph_function_with_gimple_body_p (struct cgraph_node
*node
)
817 return node
->analyzed
&& !node
->thunk
.thunk_p
&& !node
->alias
;
820 /* Return first function with body defined. */
821 static inline struct cgraph_node
*
822 cgraph_first_function_with_gimple_body (void)
824 struct cgraph_node
*node
;
825 for (node
= cgraph_nodes
; node
; node
= node
->next
)
827 if (cgraph_function_with_gimple_body_p (node
))
833 /* Return next reachable static variable with initializer after NODE. */
834 static inline struct cgraph_node
*
835 cgraph_next_function_with_gimple_body (struct cgraph_node
*node
)
837 for (node
= node
->next
; node
; node
= node
->next
)
839 if (cgraph_function_with_gimple_body_p (node
))
845 /* Walk all functions with body defined. */
846 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
847 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
848 (node) = cgraph_next_function_with_gimple_body (node))
850 /* Create a new static variable of type TYPE. */
851 tree
add_new_static_var (tree type
);
853 /* Return true if iterator CSI points to nothing. */
855 csi_end_p (cgraph_node_set_iterator csi
)
857 return csi
.index
>= VEC_length (cgraph_node_ptr
, csi
.set
->nodes
);
860 /* Advance iterator CSI. */
862 csi_next (cgraph_node_set_iterator
*csi
)
867 /* Return the node pointed to by CSI. */
868 static inline struct cgraph_node
*
869 csi_node (cgraph_node_set_iterator csi
)
871 return VEC_index (cgraph_node_ptr
, csi
.set
->nodes
, csi
.index
);
874 /* Return an iterator to the first node in SET. */
875 static inline cgraph_node_set_iterator
876 csi_start (cgraph_node_set set
)
878 cgraph_node_set_iterator csi
;
885 /* Return true if SET contains NODE. */
887 cgraph_node_in_set_p (struct cgraph_node
*node
, cgraph_node_set set
)
889 cgraph_node_set_iterator csi
;
890 csi
= cgraph_node_set_find (set
, node
);
891 return !csi_end_p (csi
);
894 /* Return number of nodes in SET. */
896 cgraph_node_set_size (cgraph_node_set set
)
898 return VEC_length (cgraph_node_ptr
, set
->nodes
);
901 /* Return true if iterator VSI points to nothing. */
903 vsi_end_p (varpool_node_set_iterator vsi
)
905 return vsi
.index
>= VEC_length (varpool_node_ptr
, vsi
.set
->nodes
);
908 /* Advance iterator VSI. */
910 vsi_next (varpool_node_set_iterator
*vsi
)
915 /* Return the node pointed to by VSI. */
916 static inline struct varpool_node
*
917 vsi_node (varpool_node_set_iterator vsi
)
919 return VEC_index (varpool_node_ptr
, vsi
.set
->nodes
, vsi
.index
);
922 /* Return an iterator to the first node in SET. */
923 static inline varpool_node_set_iterator
924 vsi_start (varpool_node_set set
)
926 varpool_node_set_iterator vsi
;
933 /* Return true if SET contains NODE. */
935 varpool_node_in_set_p (struct varpool_node
*node
, varpool_node_set set
)
937 varpool_node_set_iterator vsi
;
938 vsi
= varpool_node_set_find (set
, node
);
939 return !vsi_end_p (vsi
);
942 /* Return number of nodes in SET. */
944 varpool_node_set_size (varpool_node_set set
)
946 return VEC_length (varpool_node_ptr
, set
->nodes
);
949 /* Uniquize all constants that appear in memory.
950 Each constant in memory thus far output is recorded
951 in `const_desc_table'. */
953 struct GTY(()) constant_descriptor_tree
{
954 /* A MEM for the constant. */
957 /* The value of the constant. */
960 /* Hash of value. Computing the hash from value each time
961 hashfn is called can't work properly, as that means recursive
962 use of the hash table during hash table expansion. */
966 /* Return true if set is nonempty. */
968 cgraph_node_set_nonempty_p (cgraph_node_set set
)
970 return !VEC_empty (cgraph_node_ptr
, set
->nodes
);
973 /* Return true if set is nonempty. */
975 varpool_node_set_nonempty_p (varpool_node_set set
)
977 return !VEC_empty (varpool_node_ptr
, set
->nodes
);
980 /* Return true when function NODE is only called directly or it has alias.
981 i.e. it is not externally visible, address was not taken and
982 it is not used in any other non-standard way. */
985 cgraph_only_called_directly_or_aliased_p (struct cgraph_node
*node
)
987 gcc_assert (!node
->global
.inlined_to
);
988 return (!node
->needed
&& !node
->symbol
.address_taken
989 && !node
->symbol
.used_from_other_partition
990 && !DECL_STATIC_CONSTRUCTOR (node
->symbol
.decl
)
991 && !DECL_STATIC_DESTRUCTOR (node
->symbol
.decl
)
992 && !node
->symbol
.externally_visible
);
995 /* Return true when function NODE can be removed from callgraph
996 if all direct calls are eliminated. */
999 varpool_can_remove_if_no_refs (struct varpool_node
*node
)
1001 return (!node
->force_output
&& !node
->symbol
.used_from_other_partition
1002 && (DECL_COMDAT (node
->symbol
.decl
)
1003 || !node
->symbol
.externally_visible
));
1006 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1007 i.e. if the variable is not externally visible or not used in some magic
1008 way (asm statement or such).
1009 The magic uses are all summarized in force_output flag. */
1012 varpool_all_refs_explicit_p (struct varpool_node
*vnode
)
1014 return (vnode
->analyzed
1015 && !vnode
->symbol
.externally_visible
1016 && !vnode
->symbol
.used_from_other_partition
1017 && !vnode
->force_output
);
1020 /* Constant pool accessor function. */
1021 htab_t
constant_pool_htab (void);
1023 /* FIXME: inappropriate dependency of cgraph on IPA. */
1024 #include "ipa-ref-inline.h"
1026 /* Return node that alias N is aliasing. */
1028 static inline struct cgraph_node
*
1029 cgraph_alias_aliased_node (struct cgraph_node
*n
)
1031 struct ipa_ref
*ref
;
1033 ipa_ref_list_reference_iterate (&n
->symbol
.ref_list
, 0, ref
);
1034 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1035 if (ref
->refered_type
== IPA_REF_CGRAPH
)
1036 return ipa_ref_node (ref
);
1040 /* Return node that alias N is aliasing. */
1042 static inline struct varpool_node
*
1043 varpool_alias_aliased_node (struct varpool_node
*n
)
1045 struct ipa_ref
*ref
;
1047 ipa_ref_list_reference_iterate (&n
->symbol
.ref_list
, 0, ref
);
1048 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1049 if (ref
->refered_type
== IPA_REF_VARPOOL
)
1050 return ipa_ref_varpool_node (ref
);
1054 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1055 Walk through thunk, too.
1056 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1058 static inline struct cgraph_node
*
1059 cgraph_function_node (struct cgraph_node
*node
, enum availability
*availability
)
1062 *availability
= cgraph_function_body_availability (node
);
1065 if (node
->alias
&& node
->analyzed
)
1066 node
= cgraph_alias_aliased_node (node
);
1067 else if (node
->thunk
.thunk_p
)
1068 node
= node
->callees
->callee
;
1071 if (node
&& availability
)
1073 enum availability a
;
1074 a
= cgraph_function_body_availability (node
);
1075 if (a
< *availability
)
1080 *availability
= AVAIL_NOT_AVAILABLE
;
1084 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1085 Do not walk through thunks.
1086 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1088 static inline struct cgraph_node
*
1089 cgraph_function_or_thunk_node (struct cgraph_node
*node
, enum availability
*availability
)
1092 *availability
= cgraph_function_body_availability (node
);
1095 if (node
->alias
&& node
->analyzed
)
1096 node
= cgraph_alias_aliased_node (node
);
1099 if (node
&& availability
)
1101 enum availability a
;
1102 a
= cgraph_function_body_availability (node
);
1103 if (a
< *availability
)
1108 *availability
= AVAIL_NOT_AVAILABLE
;
1112 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1113 Do not walk through thunks.
1114 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1116 static inline struct varpool_node
*
1117 varpool_variable_node (struct varpool_node
*node
, enum availability
*availability
)
1120 *availability
= cgraph_variable_initializer_availability (node
);
1123 if (node
->alias
&& node
->analyzed
)
1124 node
= varpool_alias_aliased_node (node
);
1127 if (node
&& availability
)
1129 enum availability a
;
1130 a
= cgraph_variable_initializer_availability (node
);
1131 if (a
< *availability
)
1136 *availability
= AVAIL_NOT_AVAILABLE
;
1140 /* Return true when the edge E represents a direct recursion. */
1142 cgraph_edge_recursive_p (struct cgraph_edge
*e
)
1144 struct cgraph_node
*callee
= cgraph_function_or_thunk_node (e
->callee
, NULL
);
1145 if (e
->caller
->global
.inlined_to
)
1146 return e
->caller
->global
.inlined_to
->symbol
.decl
== callee
->symbol
.decl
;
1148 return e
->caller
->symbol
.decl
== callee
->symbol
.decl
;
1151 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1153 decl_is_tm_clone (const_tree fndecl
)
1155 struct cgraph_node
*n
= cgraph_get_node (fndecl
);
1160 #endif /* GCC_CGRAPH_H */