1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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. */
40 /* Base of all entries in the symbol table.
41 The symtab_node is inherited by cgraph and varpol nodes. */
42 struct GTY(()) symtab_node
44 /* Type of the symbol. */
45 enum symtab_type type
;
50 /* Not yet set by cgraph_function_body_availability. */
52 /* Function body/variable initializer is unknown. */
54 /* Function body/variable initializer is known but might be replaced
55 by a different one from other compilation unit and thus needs to
56 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
57 arbitrary side effects on escaping variables and functions, while
58 like AVAILABLE it might access static variables. */
60 /* Function body/variable initializer is known and will be used in final
63 /* Function body/variable initializer is known and all it's uses are explicitly
64 visible within current unit (ie it's address is never taken and it is not
65 exported to other units).
66 Currently used only for functions. */
70 /* This is the information that is put into the cgraph local structure
71 to recover a function. */
72 struct lto_file_decl_data
;
74 extern const char * const cgraph_availability_names
[];
75 extern const char * const ld_plugin_symbol_resolution_names
[];
77 /* Information about thunk, used only for same body aliases. */
79 struct GTY(()) cgraph_thunk_info
{
80 /* Information about the thunk. */
81 HOST_WIDE_INT fixed_offset
;
82 HOST_WIDE_INT virtual_value
;
85 bool virtual_offset_p
;
86 /* Set to true when alias node is thunk. */
90 /* Information about the function collected locally.
91 Available after function is analyzed. */
93 struct GTY(()) cgraph_local_info
{
94 /* File stream where this node is being written to. */
95 struct lto_file_decl_data
* lto_file_data
;
97 /* Set when function function is visible in current compilation unit only
98 and its address is never taken. */
101 /* Set when function is visible by other units. */
102 unsigned externally_visible
: 1;
104 /* Set once it has been finalized so we consider it to be output. */
105 unsigned finalized
: 1;
107 /* False when there is something makes versioning impossible. */
108 unsigned versionable
: 1;
110 /* False when function calling convention and signature can not be changed.
111 This is the case when __builtin_apply_args is used. */
112 unsigned can_change_signature
: 1;
114 /* True when the function has been originally extern inline, but it is
116 unsigned redefined_extern_inline
: 1;
118 /* True if the function may enter serial irrevocable mode. */
119 unsigned tm_may_enter_irr
: 1;
122 /* Information about the function that needs to be computed globally
123 once compilation is finished. Available only with -funit-at-a-time. */
125 struct GTY(()) cgraph_global_info
{
126 /* For inline clones this points to the function they will be
128 struct cgraph_node
*inlined_to
;
131 /* Information about the function that is propagated by the RTL backend.
132 Available only for functions that has been already assembled. */
134 struct GTY(()) cgraph_rtl_info
{
135 unsigned int preferred_incoming_stack_boundary
;
138 /* Represent which DECL tree (or reference to such tree)
139 will be replaced by another tree while versioning. */
140 struct GTY(()) ipa_replace_map
142 /* The tree that will be replaced. */
144 /* The new (replacing) tree. */
146 /* Parameter number to replace, when old_tree is NULL. */
148 /* True when a substitution should be done, false otherwise. */
150 /* True when we replace a reference to old_tree. */
153 typedef struct ipa_replace_map
*ipa_replace_map_p
;
154 DEF_VEC_P(ipa_replace_map_p
);
155 DEF_VEC_ALLOC_P(ipa_replace_map_p
,gc
);
157 struct GTY(()) cgraph_clone_info
159 VEC(ipa_replace_map_p
,gc
)* tree_map
;
161 bitmap combined_args_to_skip
;
165 /* The cgraph data structure.
166 Each function decl has assigned cgraph_node listing callees and callers. */
168 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node
{
169 struct symtab_node symbol
;
171 struct cgraph_edge
*callees
;
172 struct cgraph_edge
*callers
;
173 struct cgraph_node
*next
;
174 struct cgraph_node
*previous
;
175 /* List of edges representing indirect calls with a yet undetermined
177 struct cgraph_edge
*indirect_calls
;
178 /* For nested functions points to function the node is nested in. */
179 struct cgraph_node
*origin
;
180 /* Points to first nested function, if any. */
181 struct cgraph_node
*nested
;
182 /* Pointer to the next function with same origin, if any. */
183 struct cgraph_node
*next_nested
;
184 /* Pointer to the next function in cgraph_nodes_queue. */
185 struct cgraph_node
*next_needed
;
186 /* Pointer to the next clone. */
187 struct cgraph_node
*next_sibling_clone
;
188 struct cgraph_node
*prev_sibling_clone
;
189 struct cgraph_node
*clones
;
190 struct cgraph_node
*clone_of
;
191 /* Circular list of nodes in the same comdat group if non-NULL. */
192 struct cgraph_node
*same_comdat_group
;
193 /* For functions with many calls sites it holds map from call expression
194 to the edge to speed up cgraph_edge function. */
195 htab_t
GTY((param_is (struct cgraph_edge
))) call_site_hash
;
196 /* Declaration node used to be clone of. */
197 tree former_clone_of
;
199 PTR
GTY ((skip
)) aux
;
201 /* Interprocedural passes scheduled to have their transform functions
202 applied next time we execute local pass on them. We maintain it
203 per-function in order to allow IPA passes to introduce new functions. */
204 VEC(ipa_opt_pass
,heap
) * GTY((skip
)) ipa_transforms_to_apply
;
206 struct ipa_ref_list ref_list
;
207 struct cgraph_local_info local
;
208 struct cgraph_global_info global
;
209 struct cgraph_rtl_info rtl
;
210 struct cgraph_clone_info clone
;
211 struct cgraph_thunk_info thunk
;
213 /* Expected number of executions: calculated in profile.c. */
215 /* How to scale counts at materialization time; used to merge
216 LTO units with different number of profile runs. */
217 int count_materialization_scale
;
218 /* Unique id of the node. */
220 /* Ordering of all cgraph nodes. */
223 enum ld_plugin_symbol_resolution resolution
;
225 /* Set when function must be output for some reason. The primary
226 use of this flag is to mark functions needed to be output for
227 non-standard reason. Functions that are externally visible
228 or reachable from functions needed to be output are marked
229 by specialized flags. */
231 /* Set when function has address taken.
232 In current implementation it imply needed flag. */
233 unsigned address_taken
: 1;
234 /* Set when decl is an abstract function pointed to by the
235 ABSTRACT_DECL_ORIGIN of a reachable function. */
236 unsigned abstract_and_needed
: 1;
237 /* Set when function is reachable by call from other function
238 that is either reachable or needed.
239 This flag is computed at original cgraph construction and then
240 updated in cgraph_remove_unreachable_nodes. Note that after
241 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
242 nodes when they are needed for virtual clone instantiation. */
243 unsigned reachable
: 1;
244 /* Set when function is reachable by call from other LTRANS partition. */
245 unsigned reachable_from_other_partition
: 1;
246 /* Set once the function is lowered (i.e. its CFG is built). */
247 unsigned lowered
: 1;
248 /* Set once the function has been instantiated and its callee
250 unsigned analyzed
: 1;
251 /* Set when function is available in the other LTRANS partition.
252 During WPA output it is used to mark nodes that are present in
253 multiple partitions. */
254 unsigned in_other_partition
: 1;
255 /* Set when function is scheduled to be processed by local passes. */
256 unsigned process
: 1;
257 /* Set for aliases once they got through assemble_alias. */
259 /* Set for aliases created as C++ same body aliases. */
260 unsigned same_body_alias
: 1;
261 /* How commonly executed the node is. Initialized during branch
262 probabilities pass. */
263 ENUM_BITFIELD (node_frequency
) frequency
: 2;
264 /* True when function can only be called at startup (from static ctor). */
265 unsigned only_called_at_startup
: 1;
266 /* True when function can only be called at startup (from static dtor). */
267 unsigned only_called_at_exit
: 1;
268 /* True when function is the transactional clone of a function which
269 is called only from inside transactions. */
270 /* ?? We should be able to remove this. We have enough bits in
271 cgraph to calculate it. */
272 unsigned tm_clone
: 1;
275 typedef struct cgraph_node
*cgraph_node_ptr
;
277 DEF_VEC_P(cgraph_node_ptr
);
278 DEF_VEC_ALLOC_P(cgraph_node_ptr
,heap
);
279 DEF_VEC_ALLOC_P(cgraph_node_ptr
,gc
);
281 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
282 can appear in multiple sets. */
283 struct cgraph_node_set_def
285 struct pointer_map_t
*map
;
286 VEC(cgraph_node_ptr
, heap
) *nodes
;
289 typedef struct varpool_node
*varpool_node_ptr
;
291 DEF_VEC_P(varpool_node_ptr
);
292 DEF_VEC_ALLOC_P(varpool_node_ptr
,heap
);
293 DEF_VEC_ALLOC_P(varpool_node_ptr
,gc
);
295 /* A varpool node set is a collection of varpool nodes. A varpool node
296 can appear in multiple sets. */
297 struct varpool_node_set_def
299 struct pointer_map_t
* map
;
300 VEC(varpool_node_ptr
, heap
) *nodes
;
303 typedef struct cgraph_node_set_def
*cgraph_node_set
;
305 DEF_VEC_P(cgraph_node_set
);
306 DEF_VEC_ALLOC_P(cgraph_node_set
,gc
);
307 DEF_VEC_ALLOC_P(cgraph_node_set
,heap
);
309 typedef struct varpool_node_set_def
*varpool_node_set
;
311 DEF_VEC_P(varpool_node_set
);
312 DEF_VEC_ALLOC_P(varpool_node_set
,gc
);
313 DEF_VEC_ALLOC_P(varpool_node_set
,heap
);
315 /* Iterator structure for cgraph node sets. */
320 } cgraph_node_set_iterator
;
322 /* Iterator structure for varpool node sets. */
325 varpool_node_set set
;
327 } varpool_node_set_iterator
;
329 #define DEFCIFCODE(code, string) CIF_ ## code,
330 /* Reasons for inlining failures. */
331 typedef enum cgraph_inline_failed_enum
{
332 #include "cif-code.def"
334 } cgraph_inline_failed_t
;
336 /* Structure containing additional information about an indirect call. */
338 struct GTY(()) cgraph_indirect_call_info
340 /* Offset accumulated from ancestor jump functions of inlined call graph
342 HOST_WIDE_INT anc_offset
;
343 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
344 HOST_WIDE_INT otr_token
;
345 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
347 /* Index of the parameter that is called. */
349 /* ECF flags determined from the caller. */
352 /* Set when the call is a virtual call with the parameter being the
353 associated object pointer rather than a simple direct call. */
354 unsigned polymorphic
: 1;
357 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge
{
358 /* Expected number of executions: calculated in profile.c. */
360 struct cgraph_node
*caller
;
361 struct cgraph_node
*callee
;
362 struct cgraph_edge
*prev_caller
;
363 struct cgraph_edge
*next_caller
;
364 struct cgraph_edge
*prev_callee
;
365 struct cgraph_edge
*next_callee
;
367 /* Additional information about an indirect call. Not cleared when an edge
369 struct cgraph_indirect_call_info
*indirect_info
;
370 PTR
GTY ((skip (""))) aux
;
371 /* When equal to CIF_OK, inline this call. Otherwise, points to the
372 explanation why function was not inlined. */
373 cgraph_inline_failed_t inline_failed
;
374 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
375 when the function is serialized in. */
376 unsigned int lto_stmt_uid
;
377 /* Expected frequency of executions within the function.
378 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
379 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
381 /* Unique id of the edge. */
383 /* Whether this edge was made direct by indirect inlining. */
384 unsigned int indirect_inlining_edge
: 1;
385 /* Whether this edge describes an indirect call with an undetermined
387 unsigned int indirect_unknown_callee
: 1;
388 /* Whether this edge is still a dangling */
389 /* True if the corresponding CALL stmt cannot be inlined. */
390 unsigned int call_stmt_cannot_inline_p
: 1;
391 /* Can this call throw externally? */
392 unsigned int can_throw_external
: 1;
395 #define CGRAPH_FREQ_BASE 1000
396 #define CGRAPH_FREQ_MAX 100000
398 typedef struct cgraph_edge
*cgraph_edge_p
;
400 DEF_VEC_P(cgraph_edge_p
);
401 DEF_VEC_ALLOC_P(cgraph_edge_p
,heap
);
403 /* The varpool data structure.
404 Each static variable decl has assigned varpool_node. */
406 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node
{
407 struct symtab_node symbol
;
409 /* For aliases points to declaration DECL is alias of. */
411 /* Pointer to the next function in varpool_nodes. */
412 struct varpool_node
*next
, *prev
;
413 /* Pointer to the next function in varpool_nodes_queue. */
414 struct varpool_node
*next_needed
, *prev_needed
;
415 /* Circular list of nodes in the same comdat group if non-NULL. */
416 struct varpool_node
*same_comdat_group
;
417 struct ipa_ref_list ref_list
;
418 /* File stream where this node is being written to. */
419 struct lto_file_decl_data
* lto_file_data
;
420 PTR
GTY ((skip
)) aux
;
421 /* Ordering of all cgraph nodes. */
423 enum ld_plugin_symbol_resolution resolution
;
425 /* Set when function must be output - it is externally visible
426 or its address is taken. */
428 /* Needed variables might become dead by optimization. This flag
429 forces the variable to be output even if it appears dead otherwise. */
430 unsigned force_output
: 1;
431 /* Set once the variable has been instantiated and its callee
433 unsigned analyzed
: 1;
434 /* Set once it has been finalized so we consider it to be output. */
435 unsigned finalized
: 1;
436 /* Set when variable is scheduled to be assembled. */
438 /* Set when function is visible by other units. */
439 unsigned externally_visible
: 1;
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;
444 /* Set when variable is used from other LTRANS partition. */
445 unsigned used_from_other_partition
: 1;
446 /* Set when variable is available in the other LTRANS partition.
447 During WPA output it is used to mark nodes that are present in
448 multiple partitions. */
449 unsigned in_other_partition
: 1;
452 /* Every top level asm statement is put into a cgraph_asm_node. */
454 struct GTY(()) cgraph_asm_node
{
456 struct cgraph_asm_node
*next
;
457 /* String for this asm node. */
459 /* Ordering of all cgraph nodes. */
463 extern GTY(()) struct cgraph_node
*cgraph_nodes
;
464 extern GTY(()) int cgraph_n_nodes
;
465 extern GTY(()) int cgraph_max_uid
;
466 extern GTY(()) int cgraph_edge_max_uid
;
467 extern bool cgraph_global_info_ready
;
470 /* Callgraph is being constructed. It is safe to add new functions. */
471 CGRAPH_STATE_CONSTRUCTION
,
472 /* Callgraph is built and IPA passes are being run. */
474 /* Callgraph is built and all functions are transformed to SSA form. */
475 CGRAPH_STATE_IPA_SSA
,
476 /* Functions are now ordered and being passed to RTL expanders. */
477 CGRAPH_STATE_EXPANSION
,
478 /* All cgraph expansion is done. */
479 CGRAPH_STATE_FINISHED
481 extern enum cgraph_state cgraph_state
;
482 extern bool cgraph_function_flags_ready
;
483 extern GTY(()) struct cgraph_node
*cgraph_nodes_queue
;
484 extern GTY(()) struct cgraph_node
*cgraph_new_nodes
;
486 extern GTY(()) struct cgraph_asm_node
*cgraph_asm_nodes
;
487 extern GTY(()) int cgraph_order
;
488 extern bool same_body_aliases_done
;
491 void dump_cgraph (FILE *);
492 void debug_cgraph (void);
493 void dump_cgraph_node (FILE *, struct cgraph_node
*);
494 void debug_cgraph_node (struct cgraph_node
*);
495 void cgraph_insert_node_to_hashtable (struct cgraph_node
*node
);
496 void cgraph_remove_edge (struct cgraph_edge
*);
497 void cgraph_remove_node (struct cgraph_node
*);
498 void cgraph_add_to_same_comdat_group (struct cgraph_node
*, struct cgraph_node
*);
499 bool cgraph_remove_node_and_inline_clones (struct cgraph_node
*, struct cgraph_node
*);
500 void cgraph_release_function_body (struct cgraph_node
*);
501 void cgraph_node_remove_callees (struct cgraph_node
*node
);
502 struct cgraph_edge
*cgraph_create_edge (struct cgraph_node
*,
503 struct cgraph_node
*,
504 gimple
, gcov_type
, int);
505 struct cgraph_edge
*cgraph_create_indirect_edge (struct cgraph_node
*, gimple
,
506 int, gcov_type
, int);
507 struct cgraph_indirect_call_info
*cgraph_allocate_init_indirect_info (void);
508 struct cgraph_node
* cgraph_get_node (const_tree
);
509 struct cgraph_node
* cgraph_create_node (tree
);
510 struct cgraph_node
* cgraph_get_create_node (tree
);
511 struct cgraph_node
* cgraph_same_body_alias (struct cgraph_node
*, tree
, tree
);
512 struct cgraph_node
* cgraph_add_thunk (struct cgraph_node
*, tree
, tree
, bool, HOST_WIDE_INT
,
513 HOST_WIDE_INT
, tree
, tree
);
514 struct cgraph_node
*cgraph_node_for_asm (tree
);
515 struct cgraph_edge
*cgraph_edge (struct cgraph_node
*, gimple
);
516 void cgraph_set_call_stmt (struct cgraph_edge
*, gimple
);
517 void cgraph_set_call_stmt_including_clones (struct cgraph_node
*, gimple
, gimple
);
518 void cgraph_create_edge_including_clones (struct cgraph_node
*,
519 struct cgraph_node
*,
520 gimple
, gimple
, gcov_type
, int,
521 cgraph_inline_failed_t
);
522 void cgraph_update_edges_for_call_stmt (gimple
, tree
, gimple
);
523 struct cgraph_local_info
*cgraph_local_info (tree
);
524 struct cgraph_global_info
*cgraph_global_info (tree
);
525 struct cgraph_rtl_info
*cgraph_rtl_info (tree
);
526 const char * cgraph_node_name (struct cgraph_node
*);
527 struct cgraph_edge
* cgraph_clone_edge (struct cgraph_edge
*,
528 struct cgraph_node
*, gimple
,
529 unsigned, gcov_type
, int, bool);
530 struct cgraph_node
* cgraph_clone_node (struct cgraph_node
*, tree
, gcov_type
,
531 int, bool, VEC(cgraph_edge_p
,heap
) *,
533 struct cgraph_node
*cgraph_create_function_alias (tree
, tree
);
534 void cgraph_call_node_duplication_hooks (struct cgraph_node
*node1
,
535 struct cgraph_node
*node2
);
537 void cgraph_redirect_edge_callee (struct cgraph_edge
*, struct cgraph_node
*);
538 void cgraph_make_edge_direct (struct cgraph_edge
*, struct cgraph_node
*);
539 bool cgraph_only_called_directly_p (struct cgraph_node
*);
541 struct cgraph_asm_node
*cgraph_add_asm_node (tree
);
543 bool cgraph_function_possibly_inlined_p (tree
);
544 void cgraph_unnest_node (struct cgraph_node
*);
546 enum availability
cgraph_function_body_availability (struct cgraph_node
*);
547 void cgraph_add_new_function (tree
, bool);
548 const char* cgraph_inline_failed_string (cgraph_inline_failed_t
);
549 struct cgraph_node
* cgraph_create_virtual_clone (struct cgraph_node
*old_node
,
550 VEC(cgraph_edge_p
,heap
)*,
551 VEC(ipa_replace_map_p
,gc
)* tree_map
,
553 const char *clone_name
);
555 void cgraph_set_nothrow_flag (struct cgraph_node
*, bool);
556 void cgraph_set_const_flag (struct cgraph_node
*, bool, bool);
557 void cgraph_set_pure_flag (struct cgraph_node
*, bool, bool);
558 tree
clone_function_name (tree decl
, const char *);
559 bool cgraph_node_cannot_return (struct cgraph_node
*);
560 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge
*);
561 bool cgraph_will_be_removed_from_program_if_no_direct_calls
562 (struct cgraph_node
*node
);
563 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
564 (struct cgraph_node
*node
);
565 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node
*node
);
566 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution
);
567 bool cgraph_used_from_object_file_p (struct cgraph_node
*);
568 bool varpool_used_from_object_file_p (struct varpool_node
*);
569 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node
*,
570 bool (*) (struct cgraph_node
*, void *),
573 bool cgraph_for_node_and_aliases (struct cgraph_node
*,
574 bool (*) (struct cgraph_node
*, void *),
576 VEC (cgraph_edge_p
, heap
) * collect_callers_of_node (struct cgraph_node
*node
);
579 /* In cgraphunit.c */
580 extern FILE *cgraph_dump_file
;
581 void cgraph_finalize_function (tree
, bool);
582 void cgraph_mark_if_needed (tree
);
583 void cgraph_analyze_function (struct cgraph_node
*);
584 void cgraph_finalize_compilation_unit (void);
585 void cgraph_optimize (void);
586 void cgraph_mark_needed_node (struct cgraph_node
*);
587 void cgraph_mark_address_taken_node (struct cgraph_node
*);
588 void cgraph_mark_reachable_node (struct cgraph_node
*);
589 bool cgraph_inline_p (struct cgraph_edge
*, cgraph_inline_failed_t
*reason
);
590 bool cgraph_preserve_function_body_p (struct cgraph_node
*);
591 void verify_cgraph (void);
592 void verify_cgraph_node (struct cgraph_node
*);
593 void cgraph_build_static_cdtor (char which
, tree body
, int priority
);
594 void cgraph_reset_static_var_maps (void);
595 void init_cgraph (void);
596 struct cgraph_node
* cgraph_copy_node_for_versioning (struct cgraph_node
*,
597 tree
, VEC(cgraph_edge_p
,heap
)*, bitmap
);
598 struct cgraph_node
*cgraph_function_versioning (struct cgraph_node
*,
599 VEC(cgraph_edge_p
,heap
)*,
600 VEC(ipa_replace_map_p
,gc
)*,
601 bitmap
, bool, bitmap
,
602 basic_block
, const char *);
603 void tree_function_versioning (tree
, tree
, VEC (ipa_replace_map_p
,gc
)*,
604 bool, bitmap
, bool, bitmap
, basic_block
);
605 void record_references_in_initializer (tree
, bool);
606 bool cgraph_process_new_functions (void);
607 void cgraph_process_same_body_aliases (void);
609 bool cgraph_decide_is_function_needed (struct cgraph_node
*, tree
);
611 typedef void (*cgraph_edge_hook
)(struct cgraph_edge
*, void *);
612 typedef void (*cgraph_node_hook
)(struct cgraph_node
*, void *);
613 typedef void (*cgraph_2edge_hook
)(struct cgraph_edge
*, struct cgraph_edge
*,
615 typedef void (*cgraph_2node_hook
)(struct cgraph_node
*, struct cgraph_node
*,
617 struct cgraph_edge_hook_list
;
618 struct cgraph_node_hook_list
;
619 struct cgraph_2edge_hook_list
;
620 struct cgraph_2node_hook_list
;
621 struct cgraph_edge_hook_list
*cgraph_add_edge_removal_hook (cgraph_edge_hook
, void *);
622 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list
*);
623 struct cgraph_node_hook_list
*cgraph_add_node_removal_hook (cgraph_node_hook
,
625 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list
*);
626 struct cgraph_node_hook_list
*cgraph_add_function_insertion_hook (cgraph_node_hook
,
628 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list
*);
629 void cgraph_call_function_insertion_hooks (struct cgraph_node
*node
);
630 struct cgraph_2edge_hook_list
*cgraph_add_edge_duplication_hook (cgraph_2edge_hook
, void *);
631 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list
*);
632 struct cgraph_2node_hook_list
*cgraph_add_node_duplication_hook (cgraph_2node_hook
, void *);
633 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list
*);
634 gimple
cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge
*);
635 bool cgraph_propagate_frequency (struct cgraph_node
*node
);
636 /* In cgraphbuild.c */
637 unsigned int rebuild_cgraph_edges (void);
638 void cgraph_rebuild_references (void);
639 int compute_call_stmt_bb_frequency (tree
, basic_block bb
);
642 bool cgraph_remove_unreachable_nodes (bool, FILE *);
643 cgraph_node_set
cgraph_node_set_new (void);
644 cgraph_node_set_iterator
cgraph_node_set_find (cgraph_node_set
,
645 struct cgraph_node
*);
646 void cgraph_node_set_add (cgraph_node_set
, struct cgraph_node
*);
647 void cgraph_node_set_remove (cgraph_node_set
, struct cgraph_node
*);
648 void dump_cgraph_node_set (FILE *, cgraph_node_set
);
649 void debug_cgraph_node_set (cgraph_node_set
);
650 void free_cgraph_node_set (cgraph_node_set
);
652 varpool_node_set
varpool_node_set_new (void);
653 varpool_node_set_iterator
varpool_node_set_find (varpool_node_set
,
654 struct varpool_node
*);
655 void varpool_node_set_add (varpool_node_set
, struct varpool_node
*);
656 void varpool_node_set_remove (varpool_node_set
, struct varpool_node
*);
657 void dump_varpool_node_set (FILE *, varpool_node_set
);
658 void debug_varpool_node_set (varpool_node_set
);
659 void free_varpool_node_set (varpool_node_set
);
660 void ipa_discover_readonly_nonaddressable_vars (void);
661 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node
*);
662 bool varpool_externally_visible_p (struct varpool_node
*, bool);
665 bool cgraph_maybe_hot_edge_p (struct cgraph_edge
*e
);
666 bool cgraph_optimize_for_size_p (struct cgraph_node
*);
669 extern GTY(()) struct varpool_node
*varpool_nodes_queue
;
670 extern GTY(()) struct varpool_node
*varpool_nodes
;
672 struct varpool_node
*varpool_node (tree
);
673 struct varpool_node
*varpool_node_for_asm (tree asmname
);
674 void varpool_mark_needed_node (struct varpool_node
*);
675 void debug_varpool (void);
676 void dump_varpool (FILE *);
677 void dump_varpool_node (FILE *, struct varpool_node
*);
679 void varpool_finalize_decl (tree
);
680 bool decide_is_variable_needed (struct varpool_node
*, tree
);
681 enum availability
cgraph_variable_initializer_availability (struct varpool_node
*);
682 void cgraph_make_decl_local (tree
);
683 void cgraph_make_node_local (struct cgraph_node
*);
684 bool cgraph_node_can_be_local_p (struct cgraph_node
*);
687 struct varpool_node
* varpool_get_node (const_tree decl
);
688 void varpool_remove_node (struct varpool_node
*node
);
689 void varpool_finalize_named_section_flags (struct varpool_node
*node
);
690 bool varpool_assemble_pending_decls (void);
691 bool varpool_assemble_decl (struct varpool_node
*node
);
692 bool varpool_analyze_pending_decls (void);
693 void varpool_remove_unreferenced_decls (void);
694 void varpool_empty_needed_queue (void);
695 struct varpool_node
* varpool_extra_name_alias (tree
, tree
);
696 struct varpool_node
* varpool_create_variable_alias (tree
, tree
);
697 const char * varpool_node_name (struct varpool_node
*node
);
698 void varpool_reset_queue (void);
699 bool const_value_known_p (tree
);
700 bool varpool_for_node_and_aliases (struct varpool_node
*,
701 bool (*) (struct varpool_node
*, void *),
703 void varpool_add_new_variable (tree
);
705 /* Walk all reachable static variables. */
706 #define FOR_EACH_STATIC_VARIABLE(node) \
707 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
709 /* Return callgraph node for given symbol and check it is a function. */
710 static inline struct cgraph_node
*
711 cgraph (struct symtab_node
*node
)
713 gcc_checking_assert (node
->type
== SYMTAB_FUNCTION
);
714 return (struct cgraph_node
*)node
;
717 /* Return varpool node for given symbol and check it is a variable. */
718 static inline struct varpool_node
*
719 varpool (struct symtab_node
*node
)
721 gcc_checking_assert (node
->type
== SYMTAB_FUNCTION
);
722 return (struct varpool_node
*)node
;
726 /* Return first reachable static variable with initializer. */
727 static inline struct varpool_node
*
728 varpool_first_static_initializer (void)
730 struct varpool_node
*node
;
731 for (node
= varpool_nodes_queue
; node
; node
= node
->next_needed
)
733 gcc_checking_assert (TREE_CODE (node
->decl
) == VAR_DECL
);
734 if (DECL_INITIAL (node
->decl
))
740 /* Return next reachable static variable with initializer after NODE. */
741 static inline struct varpool_node
*
742 varpool_next_static_initializer (struct varpool_node
*node
)
744 for (node
= node
->next_needed
; node
; node
= node
->next_needed
)
746 gcc_checking_assert (TREE_CODE (node
->decl
) == VAR_DECL
);
747 if (DECL_INITIAL (node
->decl
))
753 /* Walk all static variables with initializer set. */
754 #define FOR_EACH_STATIC_INITIALIZER(node) \
755 for ((node) = varpool_first_static_initializer (); (node); \
756 (node) = varpool_next_static_initializer (node))
758 /* Return first function with body defined. */
759 static inline struct cgraph_node
*
760 cgraph_first_defined_function (void)
762 struct cgraph_node
*node
;
763 for (node
= cgraph_nodes
; node
; node
= node
->next
)
771 /* Return next function with body defined after NODE. */
772 static inline struct cgraph_node
*
773 cgraph_next_defined_function (struct cgraph_node
*node
)
775 for (node
= node
->next
; node
; node
= node
->next
)
783 /* Walk all functions with body defined. */
784 #define FOR_EACH_DEFINED_FUNCTION(node) \
785 for ((node) = cgraph_first_defined_function (); (node); \
786 (node) = cgraph_next_defined_function (node))
789 /* Return true when NODE is a function with Gimple body defined
790 in current unit. Functions can also be define externally or they
791 can be thunks with no Gimple representation.
793 Note that at WPA stage, the function body may not be present in memory. */
796 cgraph_function_with_gimple_body_p (struct cgraph_node
*node
)
798 return node
->analyzed
&& !node
->thunk
.thunk_p
&& !node
->alias
;
801 /* Return first function with body defined. */
802 static inline struct cgraph_node
*
803 cgraph_first_function_with_gimple_body (void)
805 struct cgraph_node
*node
;
806 for (node
= cgraph_nodes
; node
; node
= node
->next
)
808 if (cgraph_function_with_gimple_body_p (node
))
814 /* Return next reachable static variable with initializer after NODE. */
815 static inline struct cgraph_node
*
816 cgraph_next_function_with_gimple_body (struct cgraph_node
*node
)
818 for (node
= node
->next
; node
; node
= node
->next
)
820 if (cgraph_function_with_gimple_body_p (node
))
826 /* Walk all functions with body defined. */
827 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
828 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
829 (node) = cgraph_next_function_with_gimple_body (node))
831 /* Create a new static variable of type TYPE. */
832 tree
add_new_static_var (tree type
);
834 /* Return true if iterator CSI points to nothing. */
836 csi_end_p (cgraph_node_set_iterator csi
)
838 return csi
.index
>= VEC_length (cgraph_node_ptr
, csi
.set
->nodes
);
841 /* Advance iterator CSI. */
843 csi_next (cgraph_node_set_iterator
*csi
)
848 /* Return the node pointed to by CSI. */
849 static inline struct cgraph_node
*
850 csi_node (cgraph_node_set_iterator csi
)
852 return VEC_index (cgraph_node_ptr
, csi
.set
->nodes
, csi
.index
);
855 /* Return an iterator to the first node in SET. */
856 static inline cgraph_node_set_iterator
857 csi_start (cgraph_node_set set
)
859 cgraph_node_set_iterator csi
;
866 /* Return true if SET contains NODE. */
868 cgraph_node_in_set_p (struct cgraph_node
*node
, cgraph_node_set set
)
870 cgraph_node_set_iterator csi
;
871 csi
= cgraph_node_set_find (set
, node
);
872 return !csi_end_p (csi
);
875 /* Return number of nodes in SET. */
877 cgraph_node_set_size (cgraph_node_set set
)
879 return VEC_length (cgraph_node_ptr
, set
->nodes
);
882 /* Return true if iterator VSI points to nothing. */
884 vsi_end_p (varpool_node_set_iterator vsi
)
886 return vsi
.index
>= VEC_length (varpool_node_ptr
, vsi
.set
->nodes
);
889 /* Advance iterator VSI. */
891 vsi_next (varpool_node_set_iterator
*vsi
)
896 /* Return the node pointed to by VSI. */
897 static inline struct varpool_node
*
898 vsi_node (varpool_node_set_iterator vsi
)
900 return VEC_index (varpool_node_ptr
, vsi
.set
->nodes
, vsi
.index
);
903 /* Return an iterator to the first node in SET. */
904 static inline varpool_node_set_iterator
905 vsi_start (varpool_node_set set
)
907 varpool_node_set_iterator vsi
;
914 /* Return true if SET contains NODE. */
916 varpool_node_in_set_p (struct varpool_node
*node
, varpool_node_set set
)
918 varpool_node_set_iterator vsi
;
919 vsi
= varpool_node_set_find (set
, node
);
920 return !vsi_end_p (vsi
);
923 /* Return number of nodes in SET. */
925 varpool_node_set_size (varpool_node_set set
)
927 return VEC_length (varpool_node_ptr
, set
->nodes
);
930 /* Uniquize all constants that appear in memory.
931 Each constant in memory thus far output is recorded
932 in `const_desc_table'. */
934 struct GTY(()) constant_descriptor_tree
{
935 /* A MEM for the constant. */
938 /* The value of the constant. */
941 /* Hash of value. Computing the hash from value each time
942 hashfn is called can't work properly, as that means recursive
943 use of the hash table during hash table expansion. */
947 /* Return true if set is nonempty. */
949 cgraph_node_set_nonempty_p (cgraph_node_set set
)
951 return !VEC_empty (cgraph_node_ptr
, set
->nodes
);
954 /* Return true if set is nonempty. */
956 varpool_node_set_nonempty_p (varpool_node_set set
)
958 return !VEC_empty (varpool_node_ptr
, set
->nodes
);
961 /* Return true when function NODE is only called directly or it has alias.
962 i.e. it is not externally visible, address was not taken and
963 it is not used in any other non-standard way. */
966 cgraph_only_called_directly_or_aliased_p (struct cgraph_node
*node
)
968 gcc_assert (!node
->global
.inlined_to
);
969 return (!node
->needed
&& !node
->address_taken
970 && !node
->reachable_from_other_partition
971 && !DECL_STATIC_CONSTRUCTOR (node
->decl
)
972 && !DECL_STATIC_DESTRUCTOR (node
->decl
)
973 && !node
->local
.externally_visible
);
976 /* Return true when function NODE can be removed from callgraph
977 if all direct calls are eliminated. */
980 varpool_can_remove_if_no_refs (struct varpool_node
*node
)
982 return (!node
->force_output
&& !node
->used_from_other_partition
983 && (DECL_COMDAT (node
->decl
) || !node
->externally_visible
));
986 /* Return true when all references to VNODE must be visible in ipa_ref_list.
987 i.e. if the variable is not externally visible or not used in some magic
988 way (asm statement or such).
989 The magic uses are all summarized in force_output flag. */
992 varpool_all_refs_explicit_p (struct varpool_node
*vnode
)
994 return (vnode
->analyzed
995 && !vnode
->externally_visible
996 && !vnode
->used_from_other_partition
997 && !vnode
->force_output
);
1000 /* Constant pool accessor function. */
1001 htab_t
constant_pool_htab (void);
1003 /* FIXME: inappropriate dependency of cgraph on IPA. */
1004 #include "ipa-ref-inline.h"
1006 /* Return node that alias N is aliasing. */
1008 static inline struct cgraph_node
*
1009 cgraph_alias_aliased_node (struct cgraph_node
*n
)
1011 struct ipa_ref
*ref
;
1013 ipa_ref_list_reference_iterate (&n
->ref_list
, 0, ref
);
1014 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1015 if (ref
->refered_type
== IPA_REF_CGRAPH
)
1016 return ipa_ref_node (ref
);
1020 /* Return node that alias N is aliasing. */
1022 static inline struct varpool_node
*
1023 varpool_alias_aliased_node (struct varpool_node
*n
)
1025 struct ipa_ref
*ref
;
1027 ipa_ref_list_reference_iterate (&n
->ref_list
, 0, ref
);
1028 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1029 if (ref
->refered_type
== IPA_REF_VARPOOL
)
1030 return ipa_ref_varpool_node (ref
);
1034 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1035 Walk through thunk, too.
1036 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1038 static inline struct cgraph_node
*
1039 cgraph_function_node (struct cgraph_node
*node
, enum availability
*availability
)
1042 *availability
= cgraph_function_body_availability (node
);
1045 if (node
->alias
&& node
->analyzed
)
1046 node
= cgraph_alias_aliased_node (node
);
1047 else if (node
->thunk
.thunk_p
)
1048 node
= node
->callees
->callee
;
1051 if (node
&& availability
)
1053 enum availability a
;
1054 a
= cgraph_function_body_availability (node
);
1055 if (a
< *availability
)
1060 *availability
= AVAIL_NOT_AVAILABLE
;
1064 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1065 Do not walk through thunks.
1066 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1068 static inline struct cgraph_node
*
1069 cgraph_function_or_thunk_node (struct cgraph_node
*node
, enum availability
*availability
)
1072 *availability
= cgraph_function_body_availability (node
);
1075 if (node
->alias
&& node
->analyzed
)
1076 node
= cgraph_alias_aliased_node (node
);
1079 if (node
&& availability
)
1081 enum availability a
;
1082 a
= cgraph_function_body_availability (node
);
1083 if (a
< *availability
)
1088 *availability
= AVAIL_NOT_AVAILABLE
;
1092 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1093 Do not walk through thunks.
1094 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1096 static inline struct varpool_node
*
1097 varpool_variable_node (struct varpool_node
*node
, enum availability
*availability
)
1100 *availability
= cgraph_variable_initializer_availability (node
);
1103 if (node
->alias
&& node
->analyzed
)
1104 node
= varpool_alias_aliased_node (node
);
1107 if (node
&& availability
)
1109 enum availability a
;
1110 a
= cgraph_variable_initializer_availability (node
);
1111 if (a
< *availability
)
1116 *availability
= AVAIL_NOT_AVAILABLE
;
1120 /* Return true when the edge E represents a direct recursion. */
1122 cgraph_edge_recursive_p (struct cgraph_edge
*e
)
1124 struct cgraph_node
*callee
= cgraph_function_or_thunk_node (e
->callee
, NULL
);
1125 if (e
->caller
->global
.inlined_to
)
1126 return e
->caller
->global
.inlined_to
->decl
== callee
->decl
;
1128 return e
->caller
->decl
== callee
->decl
;
1131 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1133 decl_is_tm_clone (const_tree fndecl
)
1135 struct cgraph_node
*n
= cgraph_get_node (fndecl
);
1140 #endif /* GCC_CGRAPH_H */