1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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 "basic-block.h"
29 /* Not yet set by cgraph_function_body_availability. */
31 /* Function body/variable initializer is unknown. */
33 /* Function body/variable initializer is known but might be replaced
34 by a different one from other compilation unit and thus needs to
35 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
36 arbitrary side effects on escaping variables and functions, while
37 like AVAILABLE it might access static variables. */
39 /* Function body/variable initializer is known and will be used in final
42 /* Function body/variable initializer is known and all it's uses are explicitly
43 visible within current unit (ie it's address is never taken and it is not
44 exported to other units).
45 Currently used only for functions. */
49 /* This is the information that is put into the cgraph local structure
50 to recover a function. */
51 struct lto_file_decl_data;
53 extern const char * const cgraph_availability_names[];
55 /* Function inlining information. */
57 struct GTY(()) inline_summary
59 /* Estimated stack frame consumption by the function. */
60 HOST_WIDE_INT estimated_self_stack_size;
62 /* Size of the function body. */
64 /* How many instructions are likely going to disappear after inlining. */
65 int size_inlining_benefit;
66 /* Estimated time spent executing the function body. */
68 /* How much time is going to be saved by inlining. */
69 int time_inlining_benefit;
72 /* Information about thunk, used only for same body aliases. */
74 struct GTY(()) cgraph_thunk_info {
75 /* Information about the thunk. */
76 HOST_WIDE_INT fixed_offset;
77 HOST_WIDE_INT virtual_value;
80 bool virtual_offset_p;
81 /* Set to true when alias node is thunk. */
85 /* Information about the function collected locally.
86 Available after function is analyzed. */
88 struct GTY(()) cgraph_local_info {
89 /* File stream where this node is being written to. */
90 struct lto_file_decl_data * lto_file_data;
92 struct inline_summary inline_summary;
94 /* Set when function function is visible in current compilation unit only
95 and its address is never taken. */
98 /* Set when function is visible by other units. */
99 unsigned externally_visible : 1;
101 /* Set once it has been finalized so we consider it to be output. */
102 unsigned finalized : 1;
104 /* False when there something makes inlining impossible (such as va_arg). */
105 unsigned inlinable : 1;
107 /* True when function should be inlined independently on its size. */
108 unsigned disregard_inline_limits : 1;
110 /* True when the function has been originally extern inline, but it is
112 unsigned redefined_extern_inline : 1;
114 /* True if statics_read_for_function and
115 statics_written_for_function contain valid data. */
116 unsigned for_functions_valid : 1;
118 /* True if the function is going to be emitted in some other translation
119 unit, referenced from vtable. */
120 unsigned vtable_method : 1;
123 /* Information about the function that needs to be computed globally
124 once compilation is finished. Available only with -funit-at-a-time. */
126 struct GTY(()) cgraph_global_info {
127 /* Estimated stack frame consumption by the function. */
128 HOST_WIDE_INT estimated_stack_size;
129 /* Expected offset of the stack frame of inlined function. */
130 HOST_WIDE_INT stack_frame_offset;
132 /* For inline clones this points to the function they will be
134 struct cgraph_node *inlined_to;
136 /* Estimated size of the function after inlining. */
140 /* Estimated growth after inlining. INT_MIN if not computed. */
141 int estimated_growth;
143 /* Set iff the function has been inlined at least once. */
147 /* Information about the function that is propagated by the RTL backend.
148 Available only for functions that has been already assembled. */
150 struct GTY(()) cgraph_rtl_info {
151 unsigned int preferred_incoming_stack_boundary;
154 /* Represent which DECL tree (or reference to such tree)
155 will be replaced by another tree while versioning. */
156 struct GTY(()) ipa_replace_map
158 /* The tree that will be replaced. */
160 /* The new (replacing) tree. */
162 /* True when a substitution should be done, false otherwise. */
164 /* True when we replace a reference to old_tree. */
167 typedef struct ipa_replace_map *ipa_replace_map_p;
168 DEF_VEC_P(ipa_replace_map_p);
169 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
171 struct GTY(()) cgraph_clone_info
173 VEC(ipa_replace_map_p,gc)* tree_map;
175 bitmap combined_args_to_skip;
178 enum node_frequency {
179 /* This function most likely won't be executed at all.
180 (set only when profile feedback is available or via function attribute). */
181 NODE_FREQUENCY_UNLIKELY_EXECUTED,
182 /* For functions that are known to be executed once (i.e. constructors, destructors
183 and main function. */
184 NODE_FREQUENCY_EXECUTED_ONCE,
185 /* The default value. */
186 NODE_FREQUENCY_NORMAL,
187 /* Optimize this function hard
188 (set only when profile feedback is available or via function attribute). */
193 /* The cgraph data structure.
194 Each function decl has assigned cgraph_node listing callees and callers. */
196 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
198 struct cgraph_edge *callees;
199 struct cgraph_edge *callers;
200 struct cgraph_node *next;
201 struct cgraph_node *previous;
202 /* List of edges representing indirect calls with a yet undetermined
204 struct cgraph_edge *indirect_calls;
205 /* For nested functions points to function the node is nested in. */
206 struct cgraph_node *origin;
207 /* Points to first nested function, if any. */
208 struct cgraph_node *nested;
209 /* Pointer to the next function with same origin, if any. */
210 struct cgraph_node *next_nested;
211 /* Pointer to the next function in cgraph_nodes_queue. */
212 struct cgraph_node *next_needed;
213 /* Pointer to the next clone. */
214 struct cgraph_node *next_sibling_clone;
215 struct cgraph_node *prev_sibling_clone;
216 struct cgraph_node *clones;
217 struct cgraph_node *clone_of;
218 /* For normal nodes pointer to the list of alias and thunk nodes,
219 in alias/thunk nodes pointer to the normal node. */
220 struct cgraph_node *same_body;
221 /* Circular list of nodes in the same comdat group if non-NULL. */
222 struct cgraph_node *same_comdat_group;
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;
227 PTR GTY ((skip)) aux;
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 /* Unique id of the node. */
244 /* Ordering of all cgraph nodes. */
247 /* unique id for profiling. pid is not suitable because of different
248 number of cfg nodes with -fprofile-generate and -fprofile-use */
251 /* Set when function must be output for some reason. The primary
252 use of this flag is to mark functions needed to be output for
253 non-standard reason. Functions that are externally visible
254 or reachable from functions needed to be output are marked
255 by specialized flags. */
257 /* Set when function has address taken.
258 In current implementation it imply needed flag. */
259 unsigned address_taken : 1;
260 /* Set when decl is an abstract function pointed to by the
261 ABSTRACT_DECL_ORIGIN of a reachable function. */
262 unsigned abstract_and_needed : 1;
263 /* Set when function is reachable by call from other function
264 that is either reachable or needed.
265 This flag is computed at original cgraph construction and then
266 updated in cgraph_remove_unreachable_nodes. Note that after
267 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
268 nodes when they are needed for virtual clone instantiation. */
269 unsigned reachable : 1;
270 /* Set when function is reachable by call from other LTRANS partition. */
271 unsigned reachable_from_other_partition : 1;
272 /* Set once the function is lowered (i.e. its CFG is built). */
273 unsigned lowered : 1;
274 /* Set once the function has been instantiated and its callee
276 unsigned analyzed : 1;
277 /* Set when function is available in the other LTRANS partition. */
278 unsigned in_other_partition : 1;
279 /* Set when function is scheduled to be processed by local passes. */
280 unsigned process : 1;
281 /* Set for aliases once they got through assemble_alias. */
283 /* Set for nodes that was constructed and finalized by frontend. */
284 unsigned finalized_by_frontend : 1;
285 /* Set for alias and thunk nodes, same_body points to the node they are alias
286 of and they are linked through the next/previous pointers. */
287 unsigned same_body_alias : 1;
288 /* How commonly executed the node is. Initialized during branch
289 probabilities pass. */
290 ENUM_BITFIELD (node_frequency) frequency : 2;
293 typedef struct cgraph_node *cgraph_node_ptr;
295 DEF_VEC_P(cgraph_node_ptr);
296 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
297 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
299 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
300 can appear in multiple sets. */
301 struct GTY(()) cgraph_node_set_def
303 htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
304 VEC(cgraph_node_ptr, gc) *nodes;
305 PTR GTY ((skip)) aux;
308 typedef struct varpool_node *varpool_node_ptr;
310 DEF_VEC_P(varpool_node_ptr);
311 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
312 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
314 /* A varpool node set is a collection of varpool nodes. A varpool node
315 can appear in multiple sets. */
316 struct GTY(()) varpool_node_set_def
318 htab_t GTY((param_is (struct varpool_node_set_element_def))) hashtab;
319 VEC(varpool_node_ptr, gc) *nodes;
320 PTR GTY ((skip)) aux;
323 typedef struct cgraph_node_set_def *cgraph_node_set;
325 DEF_VEC_P(cgraph_node_set);
326 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
327 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
329 typedef struct varpool_node_set_def *varpool_node_set;
331 DEF_VEC_P(varpool_node_set);
332 DEF_VEC_ALLOC_P(varpool_node_set,gc);
333 DEF_VEC_ALLOC_P(varpool_node_set,heap);
335 /* A cgraph node set element contains an index in the vector of nodes in
337 struct GTY(()) cgraph_node_set_element_def
339 struct cgraph_node *node;
343 typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
344 typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
346 /* Iterator structure for cgraph node sets. */
351 } cgraph_node_set_iterator;
353 /* A varpool node set element contains an index in the vector of nodes in
355 struct GTY(()) varpool_node_set_element_def
357 struct varpool_node *node;
361 typedef struct varpool_node_set_element_def *varpool_node_set_element;
362 typedef const struct varpool_node_set_element_def *const_varpool_node_set_element;
364 /* Iterator structure for varpool node sets. */
367 varpool_node_set set;
369 } varpool_node_set_iterator;
371 #define DEFCIFCODE(code, string) CIF_ ## code,
372 /* Reasons for inlining failures. */
374 #include "cif-code.def"
376 } cgraph_inline_failed_t;
378 /* Structure containing additional information about an indirect call. */
380 struct GTY(()) cgraph_indirect_call_info
382 /* Index of the parameter that is called. */
386 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
387 /* Expected number of executions: calculated in profile.c. */
389 struct cgraph_node *caller;
390 struct cgraph_node *callee;
391 struct cgraph_edge *prev_caller;
392 struct cgraph_edge *next_caller;
393 struct cgraph_edge *prev_callee;
394 struct cgraph_edge *next_callee;
396 /* Additional information about an indirect call. Not cleared when an edge
398 struct cgraph_indirect_call_info *indirect_info;
399 PTR GTY ((skip (""))) aux;
400 /* When equal to CIF_OK, inline this call. Otherwise, points to the
401 explanation why function was not inlined. */
402 cgraph_inline_failed_t inline_failed;
403 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
404 when the function is serialized in. */
405 unsigned int lto_stmt_uid;
406 /* Expected frequency of executions within the function.
407 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
408 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
410 /* Unique id of the edge. */
412 /* Depth of loop nest, 1 means no loop nest. */
413 unsigned short int loop_nest;
414 /* Whether this edge was made direct by indirect inlining. */
415 unsigned int indirect_inlining_edge : 1;
416 /* Whether this edge describes an indirect call with an undetermined
418 unsigned int indirect_unknown_callee : 1;
419 /* Whether this edge is still a dangling */
420 /* True if the corresponding CALL stmt cannot be inlined. */
421 unsigned int call_stmt_cannot_inline_p : 1;
422 /* Can this call throw externally? */
423 unsigned int can_throw_external : 1;
426 #define CGRAPH_FREQ_BASE 1000
427 #define CGRAPH_FREQ_MAX 100000
429 typedef struct cgraph_edge *cgraph_edge_p;
431 DEF_VEC_P(cgraph_edge_p);
432 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
434 /* The varpool data structure.
435 Each static variable decl has assigned varpool_node. */
437 struct GTY((chain_next ("%h.next"))) varpool_node {
439 /* Pointer to the next function in varpool_nodes. */
440 struct varpool_node *next, *prev;
441 /* Pointer to the next function in varpool_nodes_queue. */
442 struct varpool_node *next_needed, *prev_needed;
443 /* For normal nodes a pointer to the first extra name alias. For alias
444 nodes a pointer to the normal node. */
445 struct varpool_node *extra_name;
446 /* Ordering of all cgraph nodes. */
449 /* Set when function must be output - it is externally visible
450 or its address is taken. */
452 /* Needed variables might become dead by optimization. This flag
453 forces the variable to be output even if it appears dead otherwise. */
454 unsigned force_output : 1;
455 /* Set once the variable has been instantiated and its callee
457 unsigned analyzed : 1;
458 /* Set once it has been finalized so we consider it to be output. */
459 unsigned finalized : 1;
460 /* Set when variable is scheduled to be assembled. */
462 /* Set when function is visible by other units. */
463 unsigned externally_visible : 1;
464 /* Set for aliases once they got through assemble_alias. Also set for
465 extra name aliases in varpool_extra_name_alias. */
467 /* Set when variable is used from other LTRANS partition. */
468 unsigned used_from_other_partition : 1;
469 /* Set when variable is available in the other LTRANS partition. */
470 unsigned in_other_partition : 1;
473 /* Every top level asm statement is put into a cgraph_asm_node. */
475 struct GTY(()) cgraph_asm_node {
477 struct cgraph_asm_node *next;
478 /* String for this asm node. */
480 /* Ordering of all cgraph nodes. */
484 extern GTY(()) struct cgraph_node *cgraph_nodes;
485 extern GTY(()) int cgraph_n_nodes;
486 extern GTY(()) int cgraph_max_uid;
487 extern GTY(()) int cgraph_edge_max_uid;
488 extern GTY(()) int cgraph_max_pid;
489 extern bool cgraph_global_info_ready;
492 /* Callgraph is being constructed. It is safe to add new functions. */
493 CGRAPH_STATE_CONSTRUCTION,
494 /* Callgraph is built and IPA passes are being run. */
496 /* Callgraph is built and all functions are transformed to SSA form. */
497 CGRAPH_STATE_IPA_SSA,
498 /* Functions are now ordered and being passed to RTL expanders. */
499 CGRAPH_STATE_EXPANSION,
500 /* All cgraph expansion is done. */
501 CGRAPH_STATE_FINISHED
503 extern enum cgraph_state cgraph_state;
504 extern bool cgraph_function_flags_ready;
505 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
506 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
508 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
509 extern GTY(()) int cgraph_order;
512 void dump_cgraph (FILE *);
513 void debug_cgraph (void);
514 void dump_cgraph_node (FILE *, struct cgraph_node *);
515 void debug_cgraph_node (struct cgraph_node *);
516 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
517 void cgraph_remove_edge (struct cgraph_edge *);
518 void cgraph_remove_node (struct cgraph_node *);
519 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
520 void cgraph_release_function_body (struct cgraph_node *);
521 void cgraph_node_remove_callees (struct cgraph_node *node);
522 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
523 struct cgraph_node *,
524 gimple, gcov_type, int, int);
525 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
526 gcov_type, int, int);
527 struct cgraph_node * cgraph_get_node (tree);
528 struct cgraph_node *cgraph_node (tree);
529 bool cgraph_same_body_alias (tree, tree);
530 void cgraph_add_thunk (tree, tree, bool, HOST_WIDE_INT, HOST_WIDE_INT, tree, tree);
531 void cgraph_remove_same_body_alias (struct cgraph_node *);
532 struct cgraph_node *cgraph_node_for_asm (tree);
533 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
534 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
535 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
536 void cgraph_create_edge_including_clones (struct cgraph_node *,
537 struct cgraph_node *,
538 gimple, gimple, gcov_type, int, int,
539 cgraph_inline_failed_t);
540 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
541 struct cgraph_local_info *cgraph_local_info (tree);
542 struct cgraph_global_info *cgraph_global_info (tree);
543 struct cgraph_rtl_info *cgraph_rtl_info (tree);
544 const char * cgraph_node_name (struct cgraph_node *);
545 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
546 struct cgraph_node *, gimple,
547 unsigned, gcov_type, int, int, bool);
548 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, int,
549 int, bool, VEC(cgraph_edge_p,heap) *);
551 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
552 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
554 struct cgraph_asm_node *cgraph_add_asm_node (tree);
556 bool cgraph_function_possibly_inlined_p (tree);
557 void cgraph_unnest_node (struct cgraph_node *);
559 enum availability cgraph_function_body_availability (struct cgraph_node *);
560 void cgraph_add_new_function (tree, bool);
561 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
562 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
563 VEC(cgraph_edge_p,heap)*,
564 VEC(ipa_replace_map_p,gc)* tree_map,
565 bitmap args_to_skip);
567 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
568 void cgraph_set_readonly_flag (struct cgraph_node *, bool);
569 void cgraph_set_pure_flag (struct cgraph_node *, bool);
570 void cgraph_set_looping_const_or_pure_flag (struct cgraph_node *, bool);
572 /* In cgraphunit.c */
573 void cgraph_finalize_function (tree, bool);
574 void cgraph_mark_if_needed (tree);
575 void cgraph_finalize_compilation_unit (void);
576 void cgraph_optimize (void);
577 void cgraph_mark_needed_node (struct cgraph_node *);
578 void cgraph_mark_address_taken_node (struct cgraph_node *);
579 void cgraph_mark_reachable_node (struct cgraph_node *);
580 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
581 bool cgraph_preserve_function_body_p (tree);
582 void verify_cgraph (void);
583 void verify_cgraph_node (struct cgraph_node *);
584 void cgraph_build_static_cdtor (char which, tree body, int priority);
585 void cgraph_reset_static_var_maps (void);
586 void init_cgraph (void);
587 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
588 VEC(cgraph_edge_p,heap)*,
589 VEC(ipa_replace_map_p,gc)*,
591 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap);
592 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
593 void record_references_in_initializer (tree, bool);
594 bool cgraph_process_new_functions (void);
596 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
598 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
599 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
600 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
602 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
604 struct cgraph_edge_hook_list;
605 struct cgraph_node_hook_list;
606 struct cgraph_2edge_hook_list;
607 struct cgraph_2node_hook_list;
608 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
609 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
610 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
612 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
613 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
615 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
616 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
617 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
618 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
619 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
620 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
621 void cgraph_materialize_all_clones (void);
622 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
623 bool cgraph_propagate_frequency (struct cgraph_node *node);
624 /* In cgraphbuild.c */
625 unsigned int rebuild_cgraph_edges (void);
626 void reset_inline_failed (struct cgraph_node *);
627 int compute_call_stmt_bb_frequency (tree, basic_block bb);
630 bool cgraph_remove_unreachable_nodes (bool, FILE *);
631 int cgraph_postorder (struct cgraph_node **);
632 cgraph_node_set cgraph_node_set_new (void);
633 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
634 struct cgraph_node *);
635 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
636 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
637 void dump_cgraph_node_set (FILE *, cgraph_node_set);
638 void debug_cgraph_node_set (cgraph_node_set);
640 varpool_node_set varpool_node_set_new (void);
641 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
642 struct varpool_node *);
643 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
644 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
645 void dump_varpool_node_set (FILE *, varpool_node_set);
646 void debug_varpool_node_set (varpool_node_set);
649 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
652 extern GTY(()) struct varpool_node *varpool_nodes_queue;
653 extern GTY(()) struct varpool_node *varpool_nodes;
655 struct varpool_node *varpool_node (tree);
656 struct varpool_node *varpool_node_for_asm (tree asmname);
657 void varpool_mark_needed_node (struct varpool_node *);
658 void debug_varpool (void);
659 void dump_varpool (FILE *);
660 void dump_varpool_node (FILE *, struct varpool_node *);
662 void varpool_finalize_decl (tree);
663 bool decide_is_variable_needed (struct varpool_node *, tree);
664 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
665 void cgraph_make_decl_local (tree);
666 void cgraph_make_node_local (struct cgraph_node *);
667 bool cgraph_node_can_be_local_p (struct cgraph_node *);
670 struct varpool_node * varpool_get_node (tree decl);
671 void varpool_remove_node (struct varpool_node *node);
672 bool varpool_assemble_pending_decls (void);
673 bool varpool_assemble_decl (struct varpool_node *node);
674 bool varpool_analyze_pending_decls (void);
675 void varpool_remove_unreferenced_decls (void);
676 void varpool_empty_needed_queue (void);
677 bool varpool_extra_name_alias (tree, tree);
678 const char * varpool_node_name (struct varpool_node *node);
680 /* Walk all reachable static variables. */
681 #define FOR_EACH_STATIC_VARIABLE(node) \
682 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
684 /* Return first reachable static variable with initializer. */
685 static inline struct varpool_node *
686 varpool_first_static_initializer (void)
688 struct varpool_node *node;
689 for (node = varpool_nodes_queue; node; node = node->next_needed)
691 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
692 if (DECL_INITIAL (node->decl))
698 /* Return next reachable static variable with initializer after NODE. */
699 static inline struct varpool_node *
700 varpool_next_static_initializer (struct varpool_node *node)
702 for (node = node->next_needed; node; node = node->next_needed)
704 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
705 if (DECL_INITIAL (node->decl))
711 /* Walk all static variables with initializer set. */
712 #define FOR_EACH_STATIC_INITIALIZER(node) \
713 for ((node) = varpool_first_static_initializer (); (node); \
714 (node) = varpool_next_static_initializer (node))
716 /* In ipa-inline.c */
717 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
718 unsigned int compute_inline_parameters (struct cgraph_node *);
721 /* Create a new static variable of type TYPE. */
722 tree add_new_static_var (tree type);
728 /* Must leave 0 for the stopper. */
729 LTO_cgraph_avail_node = 1,
730 LTO_cgraph_overwritable_node,
731 LTO_cgraph_unavail_node,
733 LTO_cgraph_indirect_edge,
737 extern const char * LTO_cgraph_tag_names[LTO_cgraph_last_tag];
739 #define LCC_NOT_FOUND (-1)
742 /* Return true if iterator CSI points to nothing. */
744 csi_end_p (cgraph_node_set_iterator csi)
746 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
749 /* Advance iterator CSI. */
751 csi_next (cgraph_node_set_iterator *csi)
756 /* Return the node pointed to by CSI. */
757 static inline struct cgraph_node *
758 csi_node (cgraph_node_set_iterator csi)
760 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
763 /* Return an iterator to the first node in SET. */
764 static inline cgraph_node_set_iterator
765 csi_start (cgraph_node_set set)
767 cgraph_node_set_iterator csi;
774 /* Return true if SET contains NODE. */
776 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
778 cgraph_node_set_iterator csi;
779 csi = cgraph_node_set_find (set, node);
780 return !csi_end_p (csi);
783 /* Return number of nodes in SET. */
785 cgraph_node_set_size (cgraph_node_set set)
787 return htab_elements (set->hashtab);
790 /* Return true if iterator VSI points to nothing. */
792 vsi_end_p (varpool_node_set_iterator vsi)
794 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
797 /* Advance iterator VSI. */
799 vsi_next (varpool_node_set_iterator *vsi)
804 /* Return the node pointed to by VSI. */
805 static inline struct varpool_node *
806 vsi_node (varpool_node_set_iterator vsi)
808 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
811 /* Return an iterator to the first node in SET. */
812 static inline varpool_node_set_iterator
813 vsi_start (varpool_node_set set)
815 varpool_node_set_iterator vsi;
822 /* Return true if SET contains NODE. */
824 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
826 varpool_node_set_iterator vsi;
827 vsi = varpool_node_set_find (set, node);
828 return !vsi_end_p (vsi);
831 /* Return number of nodes in SET. */
833 varpool_node_set_size (varpool_node_set set)
835 return htab_elements (set->hashtab);
838 /* Uniquize all constants that appear in memory.
839 Each constant in memory thus far output is recorded
840 in `const_desc_table'. */
842 struct GTY(()) constant_descriptor_tree {
843 /* A MEM for the constant. */
846 /* The value of the constant. */
849 /* Hash of value. Computing the hash from value each time
850 hashfn is called can't work properly, as that means recursive
851 use of the hash table during hash table expansion. */
855 /* Return true when function NODE is only called directly.
856 i.e. it is not externally visible, address was not taken and
857 it is not used in any other non-standard way. */
860 cgraph_only_called_directly_p (struct cgraph_node *node)
862 return !node->needed && !node->local.externally_visible;
865 /* Return true when function NODE can be removed from callgraph
866 if all direct calls are eliminated. */
869 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
871 return (!node->needed && !node->reachable_from_other_partition
872 && (DECL_COMDAT (node->decl) || !node->local.externally_visible));
875 /* Constant pool accessor function. */
876 htab_t constant_pool_htab (void);
878 #endif /* GCC_CGRAPH_H */