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))
776 /* Walk all variables. */
777 #define FOR_EACH_VARIABLE(node) \
778 for ((node) = varpool_nodes; (node); (node) = (node)->next)
779 /* Walk all variables with definitions in current unit. */
780 #define FOR_EACH_DEFINED_VARIABLE(node) \
781 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
783 /* Return first function with body defined. */
784 static inline struct cgraph_node *
785 cgraph_first_defined_function (void)
787 struct cgraph_node *node;
788 for (node = cgraph_nodes; node; node = node->next)
796 /* Return next function with body defined after NODE. */
797 static inline struct cgraph_node *
798 cgraph_next_defined_function (struct cgraph_node *node)
800 for (node = node->next; node; node = node->next)
808 /* Walk all functions with body defined. */
809 #define FOR_EACH_DEFINED_FUNCTION(node) \
810 for ((node) = cgraph_first_defined_function (); (node); \
811 (node) = cgraph_next_defined_function (node))
812 /* Walk all functions. */
813 #define FOR_EACH_FUNCTION(node) \
814 for ((node) = cgraph_nodes; (node); (node) = (node)->next)
816 /* Return true when NODE is a function with Gimple body defined
817 in current unit. Functions can also be define externally or they
818 can be thunks with no Gimple representation.
820 Note that at WPA stage, the function body may not be present in memory. */
823 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
825 return node->analyzed && !node->thunk.thunk_p && !node->alias;
828 /* Return first function with body defined. */
829 static inline struct cgraph_node *
830 cgraph_first_function_with_gimple_body (void)
832 struct cgraph_node *node;
833 for (node = cgraph_nodes; node; node = node->next)
835 if (cgraph_function_with_gimple_body_p (node))
841 /* Return next reachable static variable with initializer after NODE. */
842 static inline struct cgraph_node *
843 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
845 for (node = node->next; node; node = node->next)
847 if (cgraph_function_with_gimple_body_p (node))
853 /* Walk all functions with body defined. */
854 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
855 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
856 (node) = cgraph_next_function_with_gimple_body (node))
858 /* Create a new static variable of type TYPE. */
859 tree add_new_static_var (tree type);
861 /* Return true if iterator CSI points to nothing. */
863 csi_end_p (cgraph_node_set_iterator csi)
865 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
868 /* Advance iterator CSI. */
870 csi_next (cgraph_node_set_iterator *csi)
875 /* Return the node pointed to by CSI. */
876 static inline struct cgraph_node *
877 csi_node (cgraph_node_set_iterator csi)
879 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
882 /* Return an iterator to the first node in SET. */
883 static inline cgraph_node_set_iterator
884 csi_start (cgraph_node_set set)
886 cgraph_node_set_iterator csi;
893 /* Return true if SET contains NODE. */
895 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
897 cgraph_node_set_iterator csi;
898 csi = cgraph_node_set_find (set, node);
899 return !csi_end_p (csi);
902 /* Return number of nodes in SET. */
904 cgraph_node_set_size (cgraph_node_set set)
906 return VEC_length (cgraph_node_ptr, set->nodes);
909 /* Return true if iterator VSI points to nothing. */
911 vsi_end_p (varpool_node_set_iterator vsi)
913 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
916 /* Advance iterator VSI. */
918 vsi_next (varpool_node_set_iterator *vsi)
923 /* Return the node pointed to by VSI. */
924 static inline struct varpool_node *
925 vsi_node (varpool_node_set_iterator vsi)
927 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
930 /* Return an iterator to the first node in SET. */
931 static inline varpool_node_set_iterator
932 vsi_start (varpool_node_set set)
934 varpool_node_set_iterator vsi;
941 /* Return true if SET contains NODE. */
943 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
945 varpool_node_set_iterator vsi;
946 vsi = varpool_node_set_find (set, node);
947 return !vsi_end_p (vsi);
950 /* Return number of nodes in SET. */
952 varpool_node_set_size (varpool_node_set set)
954 return VEC_length (varpool_node_ptr, set->nodes);
957 /* Uniquize all constants that appear in memory.
958 Each constant in memory thus far output is recorded
959 in `const_desc_table'. */
961 struct GTY(()) constant_descriptor_tree {
962 /* A MEM for the constant. */
965 /* The value of the constant. */
968 /* Hash of value. Computing the hash from value each time
969 hashfn is called can't work properly, as that means recursive
970 use of the hash table during hash table expansion. */
974 /* Return true if set is nonempty. */
976 cgraph_node_set_nonempty_p (cgraph_node_set set)
978 return !VEC_empty (cgraph_node_ptr, set->nodes);
981 /* Return true if set is nonempty. */
983 varpool_node_set_nonempty_p (varpool_node_set set)
985 return !VEC_empty (varpool_node_ptr, set->nodes);
988 /* Return true when function NODE is only called directly or it has alias.
989 i.e. it is not externally visible, address was not taken and
990 it is not used in any other non-standard way. */
993 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
995 gcc_assert (!node->global.inlined_to);
996 return (!node->needed && !node->symbol.address_taken
997 && !node->symbol.used_from_other_partition
998 && !DECL_STATIC_CONSTRUCTOR (node->symbol.decl)
999 && !DECL_STATIC_DESTRUCTOR (node->symbol.decl)
1000 && !node->symbol.externally_visible);
1003 /* Return true when function NODE can be removed from callgraph
1004 if all direct calls are eliminated. */
1007 varpool_can_remove_if_no_refs (struct varpool_node *node)
1009 return (!node->force_output && !node->symbol.used_from_other_partition
1010 && (DECL_COMDAT (node->symbol.decl)
1011 || !node->symbol.externally_visible));
1014 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1015 i.e. if the variable is not externally visible or not used in some magic
1016 way (asm statement or such).
1017 The magic uses are all summarized in force_output flag. */
1020 varpool_all_refs_explicit_p (struct varpool_node *vnode)
1022 return (vnode->analyzed
1023 && !vnode->symbol.externally_visible
1024 && !vnode->symbol.used_from_other_partition
1025 && !vnode->force_output);
1028 /* Constant pool accessor function. */
1029 htab_t constant_pool_htab (void);
1031 /* FIXME: inappropriate dependency of cgraph on IPA. */
1032 #include "ipa-ref-inline.h"
1034 /* Return node that alias N is aliasing. */
1036 static inline struct cgraph_node *
1037 cgraph_alias_aliased_node (struct cgraph_node *n)
1039 struct ipa_ref *ref;
1041 ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref);
1042 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1043 if (ref->refered_type == IPA_REF_CGRAPH)
1044 return ipa_ref_node (ref);
1048 /* Return node that alias N is aliasing. */
1050 static inline struct varpool_node *
1051 varpool_alias_aliased_node (struct varpool_node *n)
1053 struct ipa_ref *ref;
1055 ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref);
1056 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1057 if (ref->refered_type == IPA_REF_VARPOOL)
1058 return ipa_ref_varpool_node (ref);
1062 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1063 Walk through thunk, too.
1064 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1066 static inline struct cgraph_node *
1067 cgraph_function_node (struct cgraph_node *node, enum availability *availability)
1070 *availability = cgraph_function_body_availability (node);
1073 if (node->alias && node->analyzed)
1074 node = cgraph_alias_aliased_node (node);
1075 else if (node->thunk.thunk_p)
1076 node = node->callees->callee;
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 cgraph_node *
1097 cgraph_function_or_thunk_node (struct cgraph_node *node, enum availability *availability)
1100 *availability = cgraph_function_body_availability (node);
1103 if (node->alias && node->analyzed)
1104 node = cgraph_alias_aliased_node (node);
1107 if (node && availability)
1109 enum availability a;
1110 a = cgraph_function_body_availability (node);
1111 if (a < *availability)
1116 *availability = AVAIL_NOT_AVAILABLE;
1120 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1121 Do not walk through thunks.
1122 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1124 static inline struct varpool_node *
1125 varpool_variable_node (struct varpool_node *node, enum availability *availability)
1128 *availability = cgraph_variable_initializer_availability (node);
1131 if (node->alias && node->analyzed)
1132 node = varpool_alias_aliased_node (node);
1135 if (node && availability)
1137 enum availability a;
1138 a = cgraph_variable_initializer_availability (node);
1139 if (a < *availability)
1144 *availability = AVAIL_NOT_AVAILABLE;
1148 /* Return true when the edge E represents a direct recursion. */
1150 cgraph_edge_recursive_p (struct cgraph_edge *e)
1152 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1153 if (e->caller->global.inlined_to)
1154 return e->caller->global.inlined_to->symbol.decl == callee->symbol.decl;
1156 return e->caller->symbol.decl == callee->symbol.decl;
1159 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1161 decl_is_tm_clone (const_tree fndecl)
1163 struct cgraph_node *n = cgraph_get_node (fndecl);
1168 #endif /* GCC_CGRAPH_H */