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 the function is going to be emitted in some other translation
115 unit, referenced from vtable. */
116 unsigned vtable_method : 1;
119 /* Information about the function that needs to be computed globally
120 once compilation is finished. Available only with -funit-at-a-time. */
122 struct GTY(()) cgraph_global_info {
123 /* Estimated stack frame consumption by the function. */
124 HOST_WIDE_INT estimated_stack_size;
125 /* Expected offset of the stack frame of inlined function. */
126 HOST_WIDE_INT stack_frame_offset;
128 /* For inline clones this points to the function they will be
130 struct cgraph_node *inlined_to;
132 /* Estimated size of the function after inlining. */
136 /* Estimated growth after inlining. INT_MIN if not computed. */
137 int estimated_growth;
140 /* Information about the function that is propagated by the RTL backend.
141 Available only for functions that has been already assembled. */
143 struct GTY(()) cgraph_rtl_info {
144 unsigned int preferred_incoming_stack_boundary;
147 /* Represent which DECL tree (or reference to such tree)
148 will be replaced by another tree while versioning. */
149 struct GTY(()) ipa_replace_map
151 /* The tree that will be replaced. */
153 /* The new (replacing) tree. */
155 /* True when a substitution should be done, false otherwise. */
157 /* True when we replace a reference to old_tree. */
160 typedef struct ipa_replace_map *ipa_replace_map_p;
161 DEF_VEC_P(ipa_replace_map_p);
162 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
164 struct GTY(()) cgraph_clone_info
166 VEC(ipa_replace_map_p,gc)* tree_map;
168 bitmap combined_args_to_skip;
171 enum node_frequency {
172 /* This function most likely won't be executed at all.
173 (set only when profile feedback is available or via function attribute). */
174 NODE_FREQUENCY_UNLIKELY_EXECUTED,
175 /* For functions that are known to be executed once (i.e. constructors, destructors
176 and main function. */
177 NODE_FREQUENCY_EXECUTED_ONCE,
178 /* The default value. */
179 NODE_FREQUENCY_NORMAL,
180 /* Optimize this function hard
181 (set only when profile feedback is available or via function attribute). */
186 /* The cgraph data structure.
187 Each function decl has assigned cgraph_node listing callees and callers. */
189 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
191 struct cgraph_edge *callees;
192 struct cgraph_edge *callers;
193 struct cgraph_node *next;
194 struct cgraph_node *previous;
195 /* List of edges representing indirect calls with a yet undetermined
197 struct cgraph_edge *indirect_calls;
198 /* For nested functions points to function the node is nested in. */
199 struct cgraph_node *origin;
200 /* Points to first nested function, if any. */
201 struct cgraph_node *nested;
202 /* Pointer to the next function with same origin, if any. */
203 struct cgraph_node *next_nested;
204 /* Pointer to the next function in cgraph_nodes_queue. */
205 struct cgraph_node *next_needed;
206 /* Pointer to the next clone. */
207 struct cgraph_node *next_sibling_clone;
208 struct cgraph_node *prev_sibling_clone;
209 struct cgraph_node *clones;
210 struct cgraph_node *clone_of;
211 /* For normal nodes pointer to the list of alias and thunk nodes,
212 in alias/thunk nodes pointer to the normal node. */
213 struct cgraph_node *same_body;
214 /* Circular list of nodes in the same comdat group if non-NULL. */
215 struct cgraph_node *same_comdat_group;
216 /* For functions with many calls sites it holds map from call expression
217 to the edge to speed up cgraph_edge function. */
218 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
220 PTR GTY ((skip)) aux;
222 /* Interprocedural passes scheduled to have their transform functions
223 applied next time we execute local pass on them. We maintain it
224 per-function in order to allow IPA passes to introduce new functions. */
225 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
227 struct cgraph_local_info local;
228 struct cgraph_global_info global;
229 struct cgraph_rtl_info rtl;
230 struct cgraph_clone_info clone;
231 struct cgraph_thunk_info thunk;
233 /* Expected number of executions: calculated in profile.c. */
235 /* Unique id of the node. */
237 /* Ordering of all cgraph nodes. */
240 /* unique id for profiling. pid is not suitable because of different
241 number of cfg nodes with -fprofile-generate and -fprofile-use */
244 /* Set when function must be output for some reason. The primary
245 use of this flag is to mark functions needed to be output for
246 non-standard reason. Functions that are externally visible
247 or reachable from functions needed to be output are marked
248 by specialized flags. */
250 /* Set when function has address taken.
251 In current implementation it imply needed flag. */
252 unsigned address_taken : 1;
253 /* Set when decl is an abstract function pointed to by the
254 ABSTRACT_DECL_ORIGIN of a reachable function. */
255 unsigned abstract_and_needed : 1;
256 /* Set when function is reachable by call from other function
257 that is either reachable or needed.
258 This flag is computed at original cgraph construction and then
259 updated in cgraph_remove_unreachable_nodes. Note that after
260 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
261 nodes when they are needed for virtual clone instantiation. */
262 unsigned reachable : 1;
263 /* Set when function is reachable by call from other LTRANS partition. */
264 unsigned reachable_from_other_partition : 1;
265 /* Set once the function is lowered (i.e. its CFG is built). */
266 unsigned lowered : 1;
267 /* Set once the function has been instantiated and its callee
269 unsigned analyzed : 1;
270 /* Set when function is available in the other LTRANS partition. */
271 unsigned in_other_partition : 1;
272 /* Set when function is scheduled to be processed by local passes. */
273 unsigned process : 1;
274 /* Set for aliases once they got through assemble_alias. */
276 /* Set for nodes that was constructed and finalized by frontend. */
277 unsigned finalized_by_frontend : 1;
278 /* Set for alias and thunk nodes, same_body points to the node they are alias
279 of and they are linked through the next/previous pointers. */
280 unsigned same_body_alias : 1;
281 /* How commonly executed the node is. Initialized during branch
282 probabilities pass. */
283 ENUM_BITFIELD (node_frequency) frequency : 2;
286 typedef struct cgraph_node *cgraph_node_ptr;
288 DEF_VEC_P(cgraph_node_ptr);
289 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
290 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
292 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
293 can appear in multiple sets. */
294 struct GTY(()) cgraph_node_set_def
296 htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
297 VEC(cgraph_node_ptr, gc) *nodes;
298 PTR GTY ((skip)) aux;
301 typedef struct varpool_node *varpool_node_ptr;
303 DEF_VEC_P(varpool_node_ptr);
304 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
305 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
307 /* A varpool node set is a collection of varpool nodes. A varpool node
308 can appear in multiple sets. */
309 struct GTY(()) varpool_node_set_def
311 htab_t GTY((param_is (struct varpool_node_set_element_def))) hashtab;
312 VEC(varpool_node_ptr, gc) *nodes;
313 PTR GTY ((skip)) aux;
316 typedef struct cgraph_node_set_def *cgraph_node_set;
318 DEF_VEC_P(cgraph_node_set);
319 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
320 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
322 typedef struct varpool_node_set_def *varpool_node_set;
324 DEF_VEC_P(varpool_node_set);
325 DEF_VEC_ALLOC_P(varpool_node_set,gc);
326 DEF_VEC_ALLOC_P(varpool_node_set,heap);
328 /* A cgraph node set element contains an index in the vector of nodes in
330 struct GTY(()) cgraph_node_set_element_def
332 struct cgraph_node *node;
336 typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
337 typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
339 /* Iterator structure for cgraph node sets. */
344 } cgraph_node_set_iterator;
346 /* A varpool node set element contains an index in the vector of nodes in
348 struct GTY(()) varpool_node_set_element_def
350 struct varpool_node *node;
354 typedef struct varpool_node_set_element_def *varpool_node_set_element;
355 typedef const struct varpool_node_set_element_def *const_varpool_node_set_element;
357 /* Iterator structure for varpool node sets. */
360 varpool_node_set set;
362 } varpool_node_set_iterator;
364 #define DEFCIFCODE(code, string) CIF_ ## code,
365 /* Reasons for inlining failures. */
367 #include "cif-code.def"
369 } cgraph_inline_failed_t;
371 /* Structure containing additional information about an indirect call. */
373 struct GTY(()) cgraph_indirect_call_info
375 /* Index of the parameter that is called. */
379 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
380 /* Expected number of executions: calculated in profile.c. */
382 struct cgraph_node *caller;
383 struct cgraph_node *callee;
384 struct cgraph_edge *prev_caller;
385 struct cgraph_edge *next_caller;
386 struct cgraph_edge *prev_callee;
387 struct cgraph_edge *next_callee;
389 /* Additional information about an indirect call. Not cleared when an edge
391 struct cgraph_indirect_call_info *indirect_info;
392 PTR GTY ((skip (""))) aux;
393 /* When equal to CIF_OK, inline this call. Otherwise, points to the
394 explanation why function was not inlined. */
395 cgraph_inline_failed_t inline_failed;
396 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
397 when the function is serialized in. */
398 unsigned int lto_stmt_uid;
399 /* Expected frequency of executions within the function.
400 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
401 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
403 /* Unique id of the edge. */
405 /* Depth of loop nest, 1 means no loop nest. */
406 unsigned short int loop_nest;
407 /* Whether this edge was made direct by indirect inlining. */
408 unsigned int indirect_inlining_edge : 1;
409 /* Whether this edge describes an indirect call with an undetermined
411 unsigned int indirect_unknown_callee : 1;
412 /* Whether this edge is still a dangling */
413 /* True if the corresponding CALL stmt cannot be inlined. */
414 unsigned int call_stmt_cannot_inline_p : 1;
415 /* Can this call throw externally? */
416 unsigned int can_throw_external : 1;
419 #define CGRAPH_FREQ_BASE 1000
420 #define CGRAPH_FREQ_MAX 100000
422 typedef struct cgraph_edge *cgraph_edge_p;
424 DEF_VEC_P(cgraph_edge_p);
425 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
427 /* The varpool data structure.
428 Each static variable decl has assigned varpool_node. */
430 struct GTY((chain_next ("%h.next"))) varpool_node {
432 /* Pointer to the next function in varpool_nodes. */
433 struct varpool_node *next, *prev;
434 /* Pointer to the next function in varpool_nodes_queue. */
435 struct varpool_node *next_needed, *prev_needed;
436 /* For normal nodes a pointer to the first extra name alias. For alias
437 nodes a pointer to the normal node. */
438 struct varpool_node *extra_name;
439 /* Ordering of all cgraph nodes. */
442 /* Set when function must be output - it is externally visible
443 or its address is taken. */
445 /* Needed variables might become dead by optimization. This flag
446 forces the variable to be output even if it appears dead otherwise. */
447 unsigned force_output : 1;
448 /* Set once the variable has been instantiated and its callee
450 unsigned analyzed : 1;
451 /* Set once it has been finalized so we consider it to be output. */
452 unsigned finalized : 1;
453 /* Set when variable is scheduled to be assembled. */
455 /* Set when function is visible by other units. */
456 unsigned externally_visible : 1;
457 /* Set for aliases once they got through assemble_alias. Also set for
458 extra name aliases in varpool_extra_name_alias. */
460 /* Set when variable is used from other LTRANS partition. */
461 unsigned used_from_other_partition : 1;
462 /* Set when variable is available in the other LTRANS partition. */
463 unsigned in_other_partition : 1;
466 /* Every top level asm statement is put into a cgraph_asm_node. */
468 struct GTY(()) cgraph_asm_node {
470 struct cgraph_asm_node *next;
471 /* String for this asm node. */
473 /* Ordering of all cgraph nodes. */
477 extern GTY(()) struct cgraph_node *cgraph_nodes;
478 extern GTY(()) int cgraph_n_nodes;
479 extern GTY(()) int cgraph_max_uid;
480 extern GTY(()) int cgraph_edge_max_uid;
481 extern GTY(()) int cgraph_max_pid;
482 extern bool cgraph_global_info_ready;
485 /* Callgraph is being constructed. It is safe to add new functions. */
486 CGRAPH_STATE_CONSTRUCTION,
487 /* Callgraph is built and IPA passes are being run. */
489 /* Callgraph is built and all functions are transformed to SSA form. */
490 CGRAPH_STATE_IPA_SSA,
491 /* Functions are now ordered and being passed to RTL expanders. */
492 CGRAPH_STATE_EXPANSION,
493 /* All cgraph expansion is done. */
494 CGRAPH_STATE_FINISHED
496 extern enum cgraph_state cgraph_state;
497 extern bool cgraph_function_flags_ready;
498 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
499 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
501 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
502 extern GTY(()) int cgraph_order;
505 void dump_cgraph (FILE *);
506 void debug_cgraph (void);
507 void dump_cgraph_node (FILE *, struct cgraph_node *);
508 void debug_cgraph_node (struct cgraph_node *);
509 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
510 void cgraph_remove_edge (struct cgraph_edge *);
511 void cgraph_remove_node (struct cgraph_node *);
512 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
513 void cgraph_release_function_body (struct cgraph_node *);
514 void cgraph_node_remove_callees (struct cgraph_node *node);
515 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
516 struct cgraph_node *,
517 gimple, gcov_type, int, int);
518 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
519 gcov_type, int, int);
520 struct cgraph_node * cgraph_get_node (tree);
521 struct cgraph_node *cgraph_node (tree);
522 bool cgraph_same_body_alias (tree, tree);
523 void cgraph_add_thunk (tree, tree, bool, HOST_WIDE_INT, HOST_WIDE_INT, tree, tree);
524 void cgraph_remove_same_body_alias (struct cgraph_node *);
525 struct cgraph_node *cgraph_node_for_asm (tree);
526 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
527 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
528 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
529 void cgraph_create_edge_including_clones (struct cgraph_node *,
530 struct cgraph_node *,
531 gimple, gimple, gcov_type, int, int,
532 cgraph_inline_failed_t);
533 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
534 struct cgraph_local_info *cgraph_local_info (tree);
535 struct cgraph_global_info *cgraph_global_info (tree);
536 struct cgraph_rtl_info *cgraph_rtl_info (tree);
537 const char * cgraph_node_name (struct cgraph_node *);
538 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
539 struct cgraph_node *, gimple,
540 unsigned, gcov_type, int, int, bool);
541 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, int,
542 int, bool, VEC(cgraph_edge_p,heap) *);
544 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
545 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
547 struct cgraph_asm_node *cgraph_add_asm_node (tree);
549 bool cgraph_function_possibly_inlined_p (tree);
550 void cgraph_unnest_node (struct cgraph_node *);
552 enum availability cgraph_function_body_availability (struct cgraph_node *);
553 void cgraph_add_new_function (tree, bool);
554 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
555 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
556 VEC(cgraph_edge_p,heap)*,
557 VEC(ipa_replace_map_p,gc)* tree_map,
558 bitmap args_to_skip);
560 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
561 void cgraph_set_readonly_flag (struct cgraph_node *, bool);
562 void cgraph_set_pure_flag (struct cgraph_node *, bool);
563 void cgraph_set_looping_const_or_pure_flag (struct cgraph_node *, bool);
565 /* In cgraphunit.c */
566 void cgraph_finalize_function (tree, bool);
567 void cgraph_mark_if_needed (tree);
568 void cgraph_finalize_compilation_unit (void);
569 void cgraph_optimize (void);
570 void cgraph_mark_needed_node (struct cgraph_node *);
571 void cgraph_mark_address_taken_node (struct cgraph_node *);
572 void cgraph_mark_reachable_node (struct cgraph_node *);
573 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
574 bool cgraph_preserve_function_body_p (tree);
575 void verify_cgraph (void);
576 void verify_cgraph_node (struct cgraph_node *);
577 void cgraph_build_static_cdtor (char which, tree body, int priority);
578 void cgraph_reset_static_var_maps (void);
579 void init_cgraph (void);
580 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
581 VEC(cgraph_edge_p,heap)*,
582 VEC(ipa_replace_map_p,gc)*,
584 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap);
585 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
586 void record_references_in_initializer (tree, bool);
587 bool cgraph_process_new_functions (void);
589 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
591 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
592 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
593 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
595 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
597 struct cgraph_edge_hook_list;
598 struct cgraph_node_hook_list;
599 struct cgraph_2edge_hook_list;
600 struct cgraph_2node_hook_list;
601 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
602 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
603 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
605 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
606 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
608 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
609 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
610 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
611 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
612 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
613 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
614 void cgraph_materialize_all_clones (void);
615 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
616 bool cgraph_propagate_frequency (struct cgraph_node *node);
617 /* In cgraphbuild.c */
618 unsigned int rebuild_cgraph_edges (void);
619 void reset_inline_failed (struct cgraph_node *);
620 int compute_call_stmt_bb_frequency (tree, basic_block bb);
623 bool cgraph_remove_unreachable_nodes (bool, FILE *);
624 int cgraph_postorder (struct cgraph_node **);
625 cgraph_node_set cgraph_node_set_new (void);
626 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
627 struct cgraph_node *);
628 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
629 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
630 void dump_cgraph_node_set (FILE *, cgraph_node_set);
631 void debug_cgraph_node_set (cgraph_node_set);
633 varpool_node_set varpool_node_set_new (void);
634 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
635 struct varpool_node *);
636 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
637 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
638 void dump_varpool_node_set (FILE *, varpool_node_set);
639 void debug_varpool_node_set (varpool_node_set);
642 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
645 extern GTY(()) struct varpool_node *varpool_nodes_queue;
646 extern GTY(()) struct varpool_node *varpool_nodes;
648 struct varpool_node *varpool_node (tree);
649 struct varpool_node *varpool_node_for_asm (tree asmname);
650 void varpool_mark_needed_node (struct varpool_node *);
651 void debug_varpool (void);
652 void dump_varpool (FILE *);
653 void dump_varpool_node (FILE *, struct varpool_node *);
655 void varpool_finalize_decl (tree);
656 bool decide_is_variable_needed (struct varpool_node *, tree);
657 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
658 void cgraph_make_decl_local (tree);
659 void cgraph_make_node_local (struct cgraph_node *);
660 bool cgraph_node_can_be_local_p (struct cgraph_node *);
663 struct varpool_node * varpool_get_node (tree decl);
664 void varpool_remove_node (struct varpool_node *node);
665 bool varpool_assemble_pending_decls (void);
666 bool varpool_assemble_decl (struct varpool_node *node);
667 bool varpool_analyze_pending_decls (void);
668 void varpool_remove_unreferenced_decls (void);
669 void varpool_empty_needed_queue (void);
670 bool varpool_extra_name_alias (tree, tree);
671 const char * varpool_node_name (struct varpool_node *node);
673 /* Walk all reachable static variables. */
674 #define FOR_EACH_STATIC_VARIABLE(node) \
675 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
677 /* Return first reachable static variable with initializer. */
678 static inline struct varpool_node *
679 varpool_first_static_initializer (void)
681 struct varpool_node *node;
682 for (node = varpool_nodes_queue; node; node = node->next_needed)
684 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
685 if (DECL_INITIAL (node->decl))
691 /* Return next reachable static variable with initializer after NODE. */
692 static inline struct varpool_node *
693 varpool_next_static_initializer (struct varpool_node *node)
695 for (node = node->next_needed; node; node = node->next_needed)
697 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
698 if (DECL_INITIAL (node->decl))
704 /* Walk all static variables with initializer set. */
705 #define FOR_EACH_STATIC_INITIALIZER(node) \
706 for ((node) = varpool_first_static_initializer (); (node); \
707 (node) = varpool_next_static_initializer (node))
709 /* In ipa-inline.c */
710 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
711 unsigned int compute_inline_parameters (struct cgraph_node *);
714 /* Create a new static variable of type TYPE. */
715 tree add_new_static_var (tree type);
717 /* Return true if iterator CSI points to nothing. */
719 csi_end_p (cgraph_node_set_iterator csi)
721 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
724 /* Advance iterator CSI. */
726 csi_next (cgraph_node_set_iterator *csi)
731 /* Return the node pointed to by CSI. */
732 static inline struct cgraph_node *
733 csi_node (cgraph_node_set_iterator csi)
735 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
738 /* Return an iterator to the first node in SET. */
739 static inline cgraph_node_set_iterator
740 csi_start (cgraph_node_set set)
742 cgraph_node_set_iterator csi;
749 /* Return true if SET contains NODE. */
751 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
753 cgraph_node_set_iterator csi;
754 csi = cgraph_node_set_find (set, node);
755 return !csi_end_p (csi);
758 /* Return number of nodes in SET. */
760 cgraph_node_set_size (cgraph_node_set set)
762 return htab_elements (set->hashtab);
765 /* Return true if iterator VSI points to nothing. */
767 vsi_end_p (varpool_node_set_iterator vsi)
769 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
772 /* Advance iterator VSI. */
774 vsi_next (varpool_node_set_iterator *vsi)
779 /* Return the node pointed to by VSI. */
780 static inline struct varpool_node *
781 vsi_node (varpool_node_set_iterator vsi)
783 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
786 /* Return an iterator to the first node in SET. */
787 static inline varpool_node_set_iterator
788 vsi_start (varpool_node_set set)
790 varpool_node_set_iterator vsi;
797 /* Return true if SET contains NODE. */
799 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
801 varpool_node_set_iterator vsi;
802 vsi = varpool_node_set_find (set, node);
803 return !vsi_end_p (vsi);
806 /* Return number of nodes in SET. */
808 varpool_node_set_size (varpool_node_set set)
810 return htab_elements (set->hashtab);
813 /* Uniquize all constants that appear in memory.
814 Each constant in memory thus far output is recorded
815 in `const_desc_table'. */
817 struct GTY(()) constant_descriptor_tree {
818 /* A MEM for the constant. */
821 /* The value of the constant. */
824 /* Hash of value. Computing the hash from value each time
825 hashfn is called can't work properly, as that means recursive
826 use of the hash table during hash table expansion. */
830 /* Return true when function NODE is only called directly.
831 i.e. it is not externally visible, address was not taken and
832 it is not used in any other non-standard way. */
835 cgraph_only_called_directly_p (struct cgraph_node *node)
837 return !node->needed && !node->local.externally_visible;
840 /* Return true when function NODE can be removed from callgraph
841 if all direct calls are eliminated. */
844 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
846 return (!node->needed && !node->reachable_from_other_partition
847 && (DECL_COMDAT (node->decl) || !node->local.externally_visible));
850 /* Constant pool accessor function. */
851 htab_t constant_pool_htab (void);
853 #endif /* GCC_CGRAPH_H */