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"
30 #include "ipa-ref.h" /* FIXME: inappropriate dependency of cgraph on IPA. */
34 /* Not yet set by cgraph_function_body_availability. */
36 /* Function body/variable initializer is unknown. */
38 /* Function body/variable initializer is known but might be replaced
39 by a different one from other compilation unit and thus needs to
40 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
41 arbitrary side effects on escaping variables and functions, while
42 like AVAILABLE it might access static variables. */
44 /* Function body/variable initializer is known and will be used in final
47 /* Function body/variable initializer is known and all it's uses are explicitly
48 visible within current unit (ie it's address is never taken and it is not
49 exported to other units).
50 Currently used only for functions. */
54 /* This is the information that is put into the cgraph local structure
55 to recover a function. */
56 struct lto_file_decl_data;
58 extern const char * const cgraph_availability_names[];
59 extern const char * const ld_plugin_symbol_resolution_names[];
61 /* Information about thunk, used only for same body aliases. */
63 struct GTY(()) cgraph_thunk_info {
64 /* Information about the thunk. */
65 HOST_WIDE_INT fixed_offset;
66 HOST_WIDE_INT virtual_value;
69 bool virtual_offset_p;
70 /* Set to true when alias node is thunk. */
74 /* Information about the function collected locally.
75 Available after function is analyzed. */
77 struct GTY(()) cgraph_local_info {
78 /* File stream where this node is being written to. */
79 struct lto_file_decl_data * lto_file_data;
81 /* Set when function function is visible in current compilation unit only
82 and its address is never taken. */
85 /* Set when function is visible by other units. */
86 unsigned externally_visible : 1;
88 /* Set once it has been finalized so we consider it to be output. */
89 unsigned finalized : 1;
91 /* False when function calling convention and signature can not be changed.
92 This is the case when __builtin_apply_args is used. */
93 unsigned can_change_signature : 1;
95 /* True when the function has been originally extern inline, but it is
97 unsigned redefined_extern_inline : 1;
100 /* Information about the function that needs to be computed globally
101 once compilation is finished. Available only with -funit-at-a-time. */
103 struct GTY(()) cgraph_global_info {
104 /* For inline clones this points to the function they will be
106 struct cgraph_node *inlined_to;
109 /* Information about the function that is propagated by the RTL backend.
110 Available only for functions that has been already assembled. */
112 struct GTY(()) cgraph_rtl_info {
113 unsigned int preferred_incoming_stack_boundary;
116 /* Represent which DECL tree (or reference to such tree)
117 will be replaced by another tree while versioning. */
118 struct GTY(()) ipa_replace_map
120 /* The tree that will be replaced. */
122 /* The new (replacing) tree. */
124 /* Parameter number to replace, when old_tree is NULL. */
126 /* True when a substitution should be done, false otherwise. */
128 /* True when we replace a reference to old_tree. */
131 typedef struct ipa_replace_map *ipa_replace_map_p;
132 DEF_VEC_P(ipa_replace_map_p);
133 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
135 struct GTY(()) cgraph_clone_info
137 VEC(ipa_replace_map_p,gc)* tree_map;
139 bitmap combined_args_to_skip;
143 /* The cgraph data structure.
144 Each function decl has assigned cgraph_node listing callees and callers. */
146 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
148 struct cgraph_edge *callees;
149 struct cgraph_edge *callers;
150 struct cgraph_node *next;
151 struct cgraph_node *previous;
152 /* List of edges representing indirect calls with a yet undetermined
154 struct cgraph_edge *indirect_calls;
155 /* For nested functions points to function the node is nested in. */
156 struct cgraph_node *origin;
157 /* Points to first nested function, if any. */
158 struct cgraph_node *nested;
159 /* Pointer to the next function with same origin, if any. */
160 struct cgraph_node *next_nested;
161 /* Pointer to the next function in cgraph_nodes_queue. */
162 struct cgraph_node *next_needed;
163 /* Pointer to the next clone. */
164 struct cgraph_node *next_sibling_clone;
165 struct cgraph_node *prev_sibling_clone;
166 struct cgraph_node *clones;
167 struct cgraph_node *clone_of;
168 /* For normal nodes pointer to the list of alias and thunk nodes,
169 in alias/thunk nodes pointer to the normal node. */
170 struct cgraph_node *same_body;
171 /* Circular list of nodes in the same comdat group if non-NULL. */
172 struct cgraph_node *same_comdat_group;
173 /* For functions with many calls sites it holds map from call expression
174 to the edge to speed up cgraph_edge function. */
175 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
176 /* Declaration node used to be clone of. */
177 tree former_clone_of;
179 PTR GTY ((skip)) aux;
181 /* Interprocedural passes scheduled to have their transform functions
182 applied next time we execute local pass on them. We maintain it
183 per-function in order to allow IPA passes to introduce new functions. */
184 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
186 struct ipa_ref_list ref_list;
187 struct cgraph_local_info local;
188 struct cgraph_global_info global;
189 struct cgraph_rtl_info rtl;
190 struct cgraph_clone_info clone;
191 struct cgraph_thunk_info thunk;
193 /* Expected number of executions: calculated in profile.c. */
195 /* How to scale counts at materialization time; used to merge
196 LTO units with different number of profile runs. */
197 int count_materialization_scale;
198 /* Unique id of the node. */
200 /* Ordering of all cgraph nodes. */
203 enum ld_plugin_symbol_resolution resolution;
205 /* Set when function must be output for some reason. The primary
206 use of this flag is to mark functions needed to be output for
207 non-standard reason. Functions that are externally visible
208 or reachable from functions needed to be output are marked
209 by specialized flags. */
211 /* Set when function has address taken.
212 In current implementation it imply needed flag. */
213 unsigned address_taken : 1;
214 /* Set when decl is an abstract function pointed to by the
215 ABSTRACT_DECL_ORIGIN of a reachable function. */
216 unsigned abstract_and_needed : 1;
217 /* Set when function is reachable by call from other function
218 that is either reachable or needed.
219 This flag is computed at original cgraph construction and then
220 updated in cgraph_remove_unreachable_nodes. Note that after
221 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
222 nodes when they are needed for virtual clone instantiation. */
223 unsigned reachable : 1;
224 /* Set when function is reachable by call from other LTRANS partition. */
225 unsigned reachable_from_other_partition : 1;
226 /* Set once the function is lowered (i.e. its CFG is built). */
227 unsigned lowered : 1;
228 /* Set once the function has been instantiated and its callee
230 unsigned analyzed : 1;
231 /* Set when function is available in the other LTRANS partition.
232 During WPA output it is used to mark nodes that are present in
233 multiple partitions. */
234 unsigned in_other_partition : 1;
235 /* Set when function is scheduled to be processed by local passes. */
236 unsigned process : 1;
237 /* Set for aliases once they got through assemble_alias. */
239 /* Set for alias and thunk nodes, same_body points to the node they are alias
240 of and they are linked through the next/previous pointers. */
241 unsigned same_body_alias : 1;
242 /* How commonly executed the node is. Initialized during branch
243 probabilities pass. */
244 ENUM_BITFIELD (node_frequency) frequency : 2;
245 /* True when function can only be called at startup (from static ctor). */
246 unsigned only_called_at_startup : 1;
247 /* True when function can only be called at startup (from static dtor). */
248 unsigned only_called_at_exit : 1;
251 typedef struct cgraph_node *cgraph_node_ptr;
253 DEF_VEC_P(cgraph_node_ptr);
254 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
255 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
257 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
258 can appear in multiple sets. */
259 struct cgraph_node_set_def
261 struct pointer_map_t *map;
262 VEC(cgraph_node_ptr, heap) *nodes;
265 typedef struct varpool_node *varpool_node_ptr;
267 DEF_VEC_P(varpool_node_ptr);
268 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
269 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
271 /* A varpool node set is a collection of varpool nodes. A varpool node
272 can appear in multiple sets. */
273 struct varpool_node_set_def
275 struct pointer_map_t * map;
276 VEC(varpool_node_ptr, heap) *nodes;
279 typedef struct cgraph_node_set_def *cgraph_node_set;
281 DEF_VEC_P(cgraph_node_set);
282 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
283 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
285 typedef struct varpool_node_set_def *varpool_node_set;
287 DEF_VEC_P(varpool_node_set);
288 DEF_VEC_ALLOC_P(varpool_node_set,gc);
289 DEF_VEC_ALLOC_P(varpool_node_set,heap);
291 /* Iterator structure for cgraph node sets. */
296 } cgraph_node_set_iterator;
298 /* Iterator structure for varpool node sets. */
301 varpool_node_set set;
303 } varpool_node_set_iterator;
305 #define DEFCIFCODE(code, string) CIF_ ## code,
306 /* Reasons for inlining failures. */
308 #include "cif-code.def"
310 } cgraph_inline_failed_t;
312 /* Structure containing additional information about an indirect call. */
314 struct GTY(()) cgraph_indirect_call_info
316 /* Offset accumulated from ancestor jump functions of inlined call graph
318 HOST_WIDE_INT anc_offset;
319 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
320 HOST_WIDE_INT otr_token;
321 /* Delta by which must be added to this parameter to compensate for a skipped
322 this adjusting thunk. */
323 HOST_WIDE_INT thunk_delta;
324 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
326 /* Index of the parameter that is called. */
328 /* ECF flags determined from the caller. */
331 /* Set when the call is a virtual call with the parameter being the
332 associated object pointer rather than a simple direct call. */
333 unsigned polymorphic : 1;
336 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
337 /* Expected number of executions: calculated in profile.c. */
339 struct cgraph_node *caller;
340 struct cgraph_node *callee;
341 struct cgraph_edge *prev_caller;
342 struct cgraph_edge *next_caller;
343 struct cgraph_edge *prev_callee;
344 struct cgraph_edge *next_callee;
346 /* Additional information about an indirect call. Not cleared when an edge
348 struct cgraph_indirect_call_info *indirect_info;
349 PTR GTY ((skip (""))) aux;
350 /* When equal to CIF_OK, inline this call. Otherwise, points to the
351 explanation why function was not inlined. */
352 cgraph_inline_failed_t inline_failed;
353 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
354 when the function is serialized in. */
355 unsigned int lto_stmt_uid;
356 /* Expected frequency of executions within the function.
357 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
358 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
360 /* Unique id of the edge. */
362 /* Whether this edge was made direct by indirect inlining. */
363 unsigned int indirect_inlining_edge : 1;
364 /* Whether this edge describes an indirect call with an undetermined
366 unsigned int indirect_unknown_callee : 1;
367 /* Whether this edge is still a dangling */
368 /* True if the corresponding CALL stmt cannot be inlined. */
369 unsigned int call_stmt_cannot_inline_p : 1;
370 /* Can this call throw externally? */
371 unsigned int can_throw_external : 1;
374 #define CGRAPH_FREQ_BASE 1000
375 #define CGRAPH_FREQ_MAX 100000
377 typedef struct cgraph_edge *cgraph_edge_p;
379 DEF_VEC_P(cgraph_edge_p);
380 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
382 /* The varpool data structure.
383 Each static variable decl has assigned varpool_node. */
385 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
387 /* Pointer to the next function in varpool_nodes. */
388 struct varpool_node *next, *prev;
389 /* Pointer to the next function in varpool_nodes_queue. */
390 struct varpool_node *next_needed, *prev_needed;
391 /* For normal nodes a pointer to the first extra name alias. For alias
392 nodes a pointer to the normal node. */
393 struct varpool_node *extra_name;
394 /* Circular list of nodes in the same comdat group if non-NULL. */
395 struct varpool_node *same_comdat_group;
396 struct ipa_ref_list ref_list;
397 /* File stream where this node is being written to. */
398 struct lto_file_decl_data * lto_file_data;
399 PTR GTY ((skip)) aux;
400 /* Ordering of all cgraph nodes. */
402 enum ld_plugin_symbol_resolution resolution;
404 /* Set when function must be output - it is externally visible
405 or its address is taken. */
407 /* Needed variables might become dead by optimization. This flag
408 forces the variable to be output even if it appears dead otherwise. */
409 unsigned force_output : 1;
410 /* Set once the variable has been instantiated and its callee
412 unsigned analyzed : 1;
413 /* Set once it has been finalized so we consider it to be output. */
414 unsigned finalized : 1;
415 /* Set when variable is scheduled to be assembled. */
417 /* Set when function is visible by other units. */
418 unsigned externally_visible : 1;
419 /* Set for aliases once they got through assemble_alias. Also set for
420 extra name aliases in varpool_extra_name_alias. */
422 /* Set when variable is used from other LTRANS partition. */
423 unsigned used_from_other_partition : 1;
424 /* Set when variable is available in the other LTRANS partition.
425 During WPA output it is used to mark nodes that are present in
426 multiple partitions. */
427 unsigned in_other_partition : 1;
430 /* Every top level asm statement is put into a cgraph_asm_node. */
432 struct GTY(()) cgraph_asm_node {
434 struct cgraph_asm_node *next;
435 /* String for this asm node. */
437 /* Ordering of all cgraph nodes. */
441 extern GTY(()) struct cgraph_node *cgraph_nodes;
442 extern GTY(()) int cgraph_n_nodes;
443 extern GTY(()) int cgraph_max_uid;
444 extern GTY(()) int cgraph_edge_max_uid;
445 extern bool cgraph_global_info_ready;
448 /* Callgraph is being constructed. It is safe to add new functions. */
449 CGRAPH_STATE_CONSTRUCTION,
450 /* Callgraph is built and IPA passes are being run. */
452 /* Callgraph is built and all functions are transformed to SSA form. */
453 CGRAPH_STATE_IPA_SSA,
454 /* Functions are now ordered and being passed to RTL expanders. */
455 CGRAPH_STATE_EXPANSION,
456 /* All cgraph expansion is done. */
457 CGRAPH_STATE_FINISHED
459 extern enum cgraph_state cgraph_state;
460 extern bool cgraph_function_flags_ready;
461 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
462 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
464 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
465 extern GTY(()) int cgraph_order;
468 void dump_cgraph (FILE *);
469 void debug_cgraph (void);
470 void dump_cgraph_node (FILE *, struct cgraph_node *);
471 void debug_cgraph_node (struct cgraph_node *);
472 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
473 void cgraph_remove_edge (struct cgraph_edge *);
474 void cgraph_remove_node (struct cgraph_node *);
475 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
476 void cgraph_release_function_body (struct cgraph_node *);
477 void cgraph_node_remove_callees (struct cgraph_node *node);
478 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
479 struct cgraph_node *,
480 gimple, gcov_type, int);
481 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
482 int, gcov_type, int);
483 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
484 struct cgraph_node * cgraph_get_node (const_tree);
485 struct cgraph_node * cgraph_get_node_or_alias (const_tree);
486 struct cgraph_node * cgraph_create_node (tree);
487 struct cgraph_node * cgraph_get_create_node (tree);
488 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
489 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
490 HOST_WIDE_INT, tree, tree);
491 void cgraph_remove_same_body_alias (struct cgraph_node *);
492 struct cgraph_node *cgraph_node_for_asm (tree);
493 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
494 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
495 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
496 void cgraph_create_edge_including_clones (struct cgraph_node *,
497 struct cgraph_node *,
498 gimple, gimple, gcov_type, int,
499 cgraph_inline_failed_t);
500 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
501 struct cgraph_local_info *cgraph_local_info (tree);
502 struct cgraph_global_info *cgraph_global_info (tree);
503 struct cgraph_rtl_info *cgraph_rtl_info (tree);
504 const char * cgraph_node_name (struct cgraph_node *);
505 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
506 struct cgraph_node *, gimple,
507 unsigned, gcov_type, int, bool);
508 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
509 int, bool, VEC(cgraph_edge_p,heap) *);
511 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
512 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *,
515 struct cgraph_asm_node *cgraph_add_asm_node (tree);
517 bool cgraph_function_possibly_inlined_p (tree);
518 void cgraph_unnest_node (struct cgraph_node *);
520 enum availability cgraph_function_body_availability (struct cgraph_node *);
521 void cgraph_add_new_function (tree, bool);
522 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
523 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
524 VEC(cgraph_edge_p,heap)*,
525 VEC(ipa_replace_map_p,gc)* tree_map,
527 const char *clone_name);
529 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
530 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
531 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
532 tree clone_function_name (tree decl, const char *);
533 bool cgraph_node_cannot_return (struct cgraph_node *);
534 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
535 bool cgraph_will_be_removed_from_program_if_no_direct_calls
536 (struct cgraph_node *node);
537 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
538 (struct cgraph_node *node);
539 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution);
540 bool cgraph_used_from_object_file_p (struct cgraph_node *node);
541 bool varpool_used_from_object_file_p (struct varpool_node *node);
543 /* In cgraphunit.c */
544 extern FILE *cgraph_dump_file;
545 void cgraph_finalize_function (tree, bool);
546 void cgraph_mark_if_needed (tree);
547 void cgraph_analyze_function (struct cgraph_node *);
548 void cgraph_finalize_compilation_unit (void);
549 void cgraph_optimize (void);
550 void cgraph_mark_needed_node (struct cgraph_node *);
551 void cgraph_mark_address_taken_node (struct cgraph_node *);
552 void cgraph_mark_reachable_node (struct cgraph_node *);
553 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
554 bool cgraph_preserve_function_body_p (struct cgraph_node *);
555 void verify_cgraph (void);
556 void verify_cgraph_node (struct cgraph_node *);
557 void cgraph_build_static_cdtor (char which, tree body, int priority);
558 void cgraph_reset_static_var_maps (void);
559 void init_cgraph (void);
560 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
561 VEC(cgraph_edge_p,heap)*,
562 VEC(ipa_replace_map_p,gc)*,
563 bitmap, bitmap, basic_block,
565 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
566 bitmap, basic_block);
567 void record_references_in_initializer (tree, bool);
568 bool cgraph_process_new_functions (void);
570 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
572 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
573 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
574 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
576 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
578 struct cgraph_edge_hook_list;
579 struct cgraph_node_hook_list;
580 struct cgraph_2edge_hook_list;
581 struct cgraph_2node_hook_list;
582 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
583 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
584 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
586 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
587 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
589 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
590 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
591 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
592 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
593 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
594 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
595 void cgraph_materialize_all_clones (void);
596 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
597 bool cgraph_propagate_frequency (struct cgraph_node *node);
598 /* In cgraphbuild.c */
599 unsigned int rebuild_cgraph_edges (void);
600 void cgraph_rebuild_references (void);
601 void reset_inline_failed (struct cgraph_node *);
602 int compute_call_stmt_bb_frequency (tree, basic_block bb);
605 bool cgraph_remove_unreachable_nodes (bool, FILE *);
606 cgraph_node_set cgraph_node_set_new (void);
607 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
608 struct cgraph_node *);
609 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
610 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
611 void dump_cgraph_node_set (FILE *, cgraph_node_set);
612 void debug_cgraph_node_set (cgraph_node_set);
613 void free_cgraph_node_set (cgraph_node_set);
615 varpool_node_set varpool_node_set_new (void);
616 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
617 struct varpool_node *);
618 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
619 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
620 void dump_varpool_node_set (FILE *, varpool_node_set);
621 void debug_varpool_node_set (varpool_node_set);
622 void free_varpool_node_set (varpool_node_set);
623 void ipa_discover_readonly_nonaddressable_vars (void);
624 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
627 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
628 bool cgraph_optimize_for_size_p (struct cgraph_node *);
631 extern GTY(()) struct varpool_node *varpool_nodes_queue;
632 extern GTY(()) struct varpool_node *varpool_nodes;
634 struct varpool_node *varpool_node (tree);
635 struct varpool_node *varpool_node_for_asm (tree asmname);
636 void varpool_mark_needed_node (struct varpool_node *);
637 void debug_varpool (void);
638 void dump_varpool (FILE *);
639 void dump_varpool_node (FILE *, struct varpool_node *);
641 void varpool_finalize_decl (tree);
642 bool decide_is_variable_needed (struct varpool_node *, tree);
643 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
644 void cgraph_make_decl_local (tree);
645 void cgraph_make_node_local (struct cgraph_node *);
646 bool cgraph_node_can_be_local_p (struct cgraph_node *);
649 struct varpool_node * varpool_get_node (const_tree decl);
650 void varpool_remove_node (struct varpool_node *node);
651 void varpool_finalize_named_section_flags (struct varpool_node *node);
652 bool varpool_assemble_pending_decls (void);
653 bool varpool_assemble_decl (struct varpool_node *node);
654 bool varpool_analyze_pending_decls (void);
655 void varpool_remove_unreferenced_decls (void);
656 void varpool_empty_needed_queue (void);
657 struct varpool_node * varpool_extra_name_alias (tree, tree);
658 const char * varpool_node_name (struct varpool_node *node);
659 void varpool_reset_queue (void);
660 bool const_value_known_p (tree);
662 /* Walk all reachable static variables. */
663 #define FOR_EACH_STATIC_VARIABLE(node) \
664 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
666 /* Return first reachable static variable with initializer. */
667 static inline struct varpool_node *
668 varpool_first_static_initializer (void)
670 struct varpool_node *node;
671 for (node = varpool_nodes_queue; node; node = node->next_needed)
673 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
674 if (DECL_INITIAL (node->decl))
680 /* Return next reachable static variable with initializer after NODE. */
681 static inline struct varpool_node *
682 varpool_next_static_initializer (struct varpool_node *node)
684 for (node = node->next_needed; node; node = node->next_needed)
686 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
687 if (DECL_INITIAL (node->decl))
693 /* Walk all static variables with initializer set. */
694 #define FOR_EACH_STATIC_INITIALIZER(node) \
695 for ((node) = varpool_first_static_initializer (); (node); \
696 (node) = varpool_next_static_initializer (node))
698 /* Return first function with body defined. */
699 static inline struct cgraph_node *
700 cgraph_first_defined_function (void)
702 struct cgraph_node *node;
703 for (node = cgraph_nodes; node; node = node->next)
711 /* Return next reachable static variable with initializer after NODE. */
712 static inline struct cgraph_node *
713 cgraph_next_defined_function (struct cgraph_node *node)
715 for (node = node->next; node; node = node->next)
723 /* Walk all functions with body defined. */
724 #define FOR_EACH_DEFINED_FUNCTION(node) \
725 for ((node) = cgraph_first_defined_function (); (node); \
726 (node) = cgraph_next_defined_function (node))
729 /* Return true when NODE is a function with Gimple body defined
730 in current unit. Functions can also be define externally or they
731 can be thunks with no Gimple representation.
733 Note that at WPA stage, the function body may not be present in memory. */
736 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
738 return node->analyzed && !node->thunk.thunk_p;
741 /* Return first function with body defined. */
742 static inline struct cgraph_node *
743 cgraph_first_function_with_gimple_body (void)
745 struct cgraph_node *node;
746 for (node = cgraph_nodes; node; node = node->next)
748 if (cgraph_function_with_gimple_body_p (node))
754 /* Return next reachable static variable with initializer after NODE. */
755 static inline struct cgraph_node *
756 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
758 for (node = node->next; node; node = node->next)
760 if (cgraph_function_with_gimple_body_p (node))
766 /* Walk all functions with body defined. */
767 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
768 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
769 (node) = cgraph_next_function_with_gimple_body (node))
771 /* Create a new static variable of type TYPE. */
772 tree add_new_static_var (tree type);
774 /* Return true if iterator CSI points to nothing. */
776 csi_end_p (cgraph_node_set_iterator csi)
778 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
781 /* Advance iterator CSI. */
783 csi_next (cgraph_node_set_iterator *csi)
788 /* Return the node pointed to by CSI. */
789 static inline struct cgraph_node *
790 csi_node (cgraph_node_set_iterator csi)
792 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
795 /* Return an iterator to the first node in SET. */
796 static inline cgraph_node_set_iterator
797 csi_start (cgraph_node_set set)
799 cgraph_node_set_iterator csi;
806 /* Return true if SET contains NODE. */
808 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
810 cgraph_node_set_iterator csi;
811 csi = cgraph_node_set_find (set, node);
812 return !csi_end_p (csi);
815 /* Return number of nodes in SET. */
817 cgraph_node_set_size (cgraph_node_set set)
819 return VEC_length (cgraph_node_ptr, set->nodes);
822 /* Return true if iterator VSI points to nothing. */
824 vsi_end_p (varpool_node_set_iterator vsi)
826 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
829 /* Advance iterator VSI. */
831 vsi_next (varpool_node_set_iterator *vsi)
836 /* Return the node pointed to by VSI. */
837 static inline struct varpool_node *
838 vsi_node (varpool_node_set_iterator vsi)
840 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
843 /* Return an iterator to the first node in SET. */
844 static inline varpool_node_set_iterator
845 vsi_start (varpool_node_set set)
847 varpool_node_set_iterator vsi;
854 /* Return true if SET contains NODE. */
856 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
858 varpool_node_set_iterator vsi;
859 vsi = varpool_node_set_find (set, node);
860 return !vsi_end_p (vsi);
863 /* Return number of nodes in SET. */
865 varpool_node_set_size (varpool_node_set set)
867 return VEC_length (varpool_node_ptr, set->nodes);
870 /* Uniquize all constants that appear in memory.
871 Each constant in memory thus far output is recorded
872 in `const_desc_table'. */
874 struct GTY(()) constant_descriptor_tree {
875 /* A MEM for the constant. */
878 /* The value of the constant. */
881 /* Hash of value. Computing the hash from value each time
882 hashfn is called can't work properly, as that means recursive
883 use of the hash table during hash table expansion. */
887 /* Return true if set is nonempty. */
889 cgraph_node_set_nonempty_p (cgraph_node_set set)
891 return !VEC_empty (cgraph_node_ptr, set->nodes);
894 /* Return true if set is nonempty. */
896 varpool_node_set_nonempty_p (varpool_node_set set)
898 return !VEC_empty (varpool_node_ptr, set->nodes);
901 /* Return true when function NODE is only called directly.
902 i.e. it is not externally visible, address was not taken and
903 it is not used in any other non-standard way. */
906 cgraph_only_called_directly_p (struct cgraph_node *node)
908 gcc_assert (!node->global.inlined_to);
909 return (!node->needed && !node->address_taken
910 && !node->reachable_from_other_partition
911 && !DECL_STATIC_CONSTRUCTOR (node->decl)
912 && !DECL_STATIC_DESTRUCTOR (node->decl)
913 && !node->local.externally_visible);
916 /* Return true when function NODE can be removed from callgraph
917 if all direct calls are eliminated. */
920 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
922 /* Extern inlines can always go, we will use the external definition. */
923 if (DECL_EXTERNAL (node->decl))
925 return !node->address_taken && cgraph_can_remove_if_no_direct_calls_and_refs_p (node);
928 /* Return true when function NODE can be removed from callgraph
929 if all direct calls are eliminated. */
932 varpool_can_remove_if_no_refs (struct varpool_node *node)
934 return (!node->force_output && !node->used_from_other_partition
935 && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
936 || DECL_ARTIFICIAL (node->decl))
937 && (DECL_COMDAT (node->decl) || !node->externally_visible));
940 /* Return true when all references to VNODE must be visible in ipa_ref_list.
941 i.e. if the variable is not externally visible or not used in some magic
942 way (asm statement or such).
943 The magic uses are all summarized in force_output flag. */
946 varpool_all_refs_explicit_p (struct varpool_node *vnode)
948 return (!vnode->externally_visible
949 && !vnode->used_from_other_partition
950 && !vnode->force_output);
953 /* Constant pool accessor function. */
954 htab_t constant_pool_htab (void);
956 /* Return true when the edge E represents a direct recursion. */
958 cgraph_edge_recursive_p (struct cgraph_edge *e)
960 if (e->caller->global.inlined_to)
961 return e->caller->global.inlined_to->decl == e->callee->decl;
963 return e->caller->decl == e->callee->decl;
966 /* FIXME: inappropriate dependency of cgraph on IPA. */
967 #include "ipa-ref-inline.h"
969 #endif /* GCC_CGRAPH_H */