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"
30 /* Not yet set by cgraph_function_body_availability. */
32 /* Function body/variable initializer is unknown. */
34 /* Function body/variable initializer is known but might be replaced
35 by a different one from other compilation unit and thus needs to
36 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
37 arbitrary side effects on escaping variables and functions, while
38 like AVAILABLE it might access static variables. */
40 /* Function body/variable initializer is known and will be used in final
43 /* Function body/variable initializer is known and all it's uses are explicitly
44 visible within current unit (ie it's address is never taken and it is not
45 exported to other units).
46 Currently used only for functions. */
50 /* This is the information that is put into the cgraph local structure
51 to recover a function. */
52 struct lto_file_decl_data;
54 extern const char * const cgraph_availability_names[];
56 /* Function inlining information. */
58 struct GTY(()) inline_summary
60 /* Estimated stack frame consumption by the function. */
61 HOST_WIDE_INT estimated_self_stack_size;
63 /* Size of the function body. */
65 /* How many instructions are likely going to disappear after inlining. */
66 int size_inlining_benefit;
67 /* Estimated time spent executing the function body. */
69 /* How much time is going to be saved by inlining. */
70 int time_inlining_benefit;
73 /* Information about thunk, used only for same body aliases. */
75 struct GTY(()) cgraph_thunk_info {
76 /* Information about the thunk. */
77 HOST_WIDE_INT fixed_offset;
78 HOST_WIDE_INT virtual_value;
81 bool virtual_offset_p;
82 /* Set to true when alias node is thunk. */
86 /* Information about the function collected locally.
87 Available after function is analyzed. */
89 struct GTY(()) cgraph_local_info {
90 /* File stream where this node is being written to. */
91 struct lto_file_decl_data * lto_file_data;
93 struct inline_summary inline_summary;
95 /* Set when function function is visible in current compilation unit only
96 and its address is never taken. */
99 /* Set when function is visible by other units. */
100 unsigned externally_visible : 1;
102 /* Set once it has been finalized so we consider it to be output. */
103 unsigned finalized : 1;
105 /* False when there something makes inlining impossible (such as va_arg). */
106 unsigned inlinable : 1;
108 /* True when function should be inlined independently on its size. */
109 unsigned disregard_inline_limits : 1;
111 /* True when the function has been originally extern inline, but it is
113 unsigned redefined_extern_inline : 1;
115 /* True if the function is going to be emitted in some other translation
116 unit, referenced from vtable. */
117 unsigned vtable_method : 1;
120 /* Information about the function that needs to be computed globally
121 once compilation is finished. Available only with -funit-at-a-time. */
123 struct GTY(()) cgraph_global_info {
124 /* Estimated stack frame consumption by the function. */
125 HOST_WIDE_INT estimated_stack_size;
126 /* Expected offset of the stack frame of inlined function. */
127 HOST_WIDE_INT stack_frame_offset;
129 /* For inline clones this points to the function they will be
131 struct cgraph_node *inlined_to;
133 /* Estimated size of the function after inlining. */
137 /* Estimated growth after inlining. INT_MIN if not computed. */
138 int estimated_growth;
141 /* Information about the function that is propagated by the RTL backend.
142 Available only for functions that has been already assembled. */
144 struct GTY(()) cgraph_rtl_info {
145 unsigned int preferred_incoming_stack_boundary;
148 /* Represent which DECL tree (or reference to such tree)
149 will be replaced by another tree while versioning. */
150 struct GTY(()) ipa_replace_map
152 /* The tree that will be replaced. */
154 /* The new (replacing) tree. */
156 /* True when a substitution should be done, false otherwise. */
158 /* True when we replace a reference to old_tree. */
161 typedef struct ipa_replace_map *ipa_replace_map_p;
162 DEF_VEC_P(ipa_replace_map_p);
163 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
165 struct GTY(()) cgraph_clone_info
167 VEC(ipa_replace_map_p,gc)* tree_map;
169 bitmap combined_args_to_skip;
172 enum node_frequency {
173 /* This function most likely won't be executed at all.
174 (set only when profile feedback is available or via function attribute). */
175 NODE_FREQUENCY_UNLIKELY_EXECUTED,
176 /* For functions that are known to be executed once (i.e. constructors, destructors
177 and main function. */
178 NODE_FREQUENCY_EXECUTED_ONCE,
179 /* The default value. */
180 NODE_FREQUENCY_NORMAL,
181 /* Optimize this function hard
182 (set only when profile feedback is available or via function attribute). */
187 /* The cgraph data structure.
188 Each function decl has assigned cgraph_node listing callees and callers. */
190 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
192 struct cgraph_edge *callees;
193 struct cgraph_edge *callers;
194 struct cgraph_node *next;
195 struct cgraph_node *previous;
196 /* List of edges representing indirect calls with a yet undetermined
198 struct cgraph_edge *indirect_calls;
199 /* For nested functions points to function the node is nested in. */
200 struct cgraph_node *origin;
201 /* Points to first nested function, if any. */
202 struct cgraph_node *nested;
203 /* Pointer to the next function with same origin, if any. */
204 struct cgraph_node *next_nested;
205 /* Pointer to the next function in cgraph_nodes_queue. */
206 struct cgraph_node *next_needed;
207 /* Pointer to the next clone. */
208 struct cgraph_node *next_sibling_clone;
209 struct cgraph_node *prev_sibling_clone;
210 struct cgraph_node *clones;
211 struct cgraph_node *clone_of;
212 /* For normal nodes pointer to the list of alias and thunk nodes,
213 in alias/thunk nodes pointer to the normal node. */
214 struct cgraph_node *same_body;
215 /* Circular list of nodes in the same comdat group if non-NULL. */
216 struct cgraph_node *same_comdat_group;
217 /* For functions with many calls sites it holds map from call expression
218 to the edge to speed up cgraph_edge function. */
219 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
221 PTR GTY ((skip)) aux;
223 /* Interprocedural passes scheduled to have their transform functions
224 applied next time we execute local pass on them. We maintain it
225 per-function in order to allow IPA passes to introduce new functions. */
226 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
228 struct ipa_ref_list ref_list;
229 struct cgraph_local_info local;
230 struct cgraph_global_info global;
231 struct cgraph_rtl_info rtl;
232 struct cgraph_clone_info clone;
233 struct cgraph_thunk_info thunk;
235 /* Expected number of executions: calculated in profile.c. */
237 /* Unique id of the node. */
239 /* Ordering of all cgraph nodes. */
242 /* unique id for profiling. pid is not suitable because of different
243 number of cfg nodes with -fprofile-generate and -fprofile-use */
246 /* Set when function must be output for some reason. The primary
247 use of this flag is to mark functions needed to be output for
248 non-standard reason. Functions that are externally visible
249 or reachable from functions needed to be output are marked
250 by specialized flags. */
252 /* Set when function has address taken.
253 In current implementation it imply needed flag. */
254 unsigned address_taken : 1;
255 /* Set when decl is an abstract function pointed to by the
256 ABSTRACT_DECL_ORIGIN of a reachable function. */
257 unsigned abstract_and_needed : 1;
258 /* Set when function is reachable by call from other function
259 that is either reachable or needed.
260 This flag is computed at original cgraph construction and then
261 updated in cgraph_remove_unreachable_nodes. Note that after
262 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
263 nodes when they are needed for virtual clone instantiation. */
264 unsigned reachable : 1;
265 /* Set when function is reachable by call from other LTRANS partition. */
266 unsigned reachable_from_other_partition : 1;
267 /* Set once the function is lowered (i.e. its CFG is built). */
268 unsigned lowered : 1;
269 /* Set once the function has been instantiated and its callee
271 unsigned analyzed : 1;
272 /* Set when function is available in the other LTRANS partition. */
273 unsigned in_other_partition : 1;
274 /* Set when function is scheduled to be processed by local passes. */
275 unsigned process : 1;
276 /* Set for aliases once they got through assemble_alias. */
278 /* Set for nodes that was constructed and finalized by frontend. */
279 unsigned finalized_by_frontend : 1;
280 /* Set for alias and thunk nodes, same_body points to the node they are alias
281 of and they are linked through the next/previous pointers. */
282 unsigned same_body_alias : 1;
283 /* How commonly executed the node is. Initialized during branch
284 probabilities pass. */
285 ENUM_BITFIELD (node_frequency) frequency : 2;
288 typedef struct cgraph_node *cgraph_node_ptr;
290 DEF_VEC_P(cgraph_node_ptr);
291 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
292 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
294 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
295 can appear in multiple sets. */
296 struct GTY(()) cgraph_node_set_def
298 htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
299 VEC(cgraph_node_ptr, gc) *nodes;
300 PTR GTY ((skip)) aux;
303 typedef struct varpool_node *varpool_node_ptr;
305 DEF_VEC_P(varpool_node_ptr);
306 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
307 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
309 /* A varpool node set is a collection of varpool nodes. A varpool node
310 can appear in multiple sets. */
311 struct GTY(()) varpool_node_set_def
313 htab_t GTY((param_is (struct varpool_node_set_element_def))) hashtab;
314 VEC(varpool_node_ptr, gc) *nodes;
315 PTR GTY ((skip)) aux;
318 typedef struct cgraph_node_set_def *cgraph_node_set;
320 DEF_VEC_P(cgraph_node_set);
321 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
322 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
324 typedef struct varpool_node_set_def *varpool_node_set;
326 DEF_VEC_P(varpool_node_set);
327 DEF_VEC_ALLOC_P(varpool_node_set,gc);
328 DEF_VEC_ALLOC_P(varpool_node_set,heap);
330 /* A cgraph node set element contains an index in the vector of nodes in
332 struct GTY(()) cgraph_node_set_element_def
334 struct cgraph_node *node;
338 typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
339 typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
341 /* Iterator structure for cgraph node sets. */
346 } cgraph_node_set_iterator;
348 /* A varpool node set element contains an index in the vector of nodes in
350 struct GTY(()) varpool_node_set_element_def
352 struct varpool_node *node;
356 typedef struct varpool_node_set_element_def *varpool_node_set_element;
357 typedef const struct varpool_node_set_element_def *const_varpool_node_set_element;
359 /* Iterator structure for varpool node sets. */
362 varpool_node_set set;
364 } varpool_node_set_iterator;
366 #define DEFCIFCODE(code, string) CIF_ ## code,
367 /* Reasons for inlining failures. */
369 #include "cif-code.def"
371 } cgraph_inline_failed_t;
373 /* Structure containing additional information about an indirect call. */
375 struct GTY(()) cgraph_indirect_call_info
377 /* Index of the parameter that is called. */
381 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
382 /* Expected number of executions: calculated in profile.c. */
384 struct cgraph_node *caller;
385 struct cgraph_node *callee;
386 struct cgraph_edge *prev_caller;
387 struct cgraph_edge *next_caller;
388 struct cgraph_edge *prev_callee;
389 struct cgraph_edge *next_callee;
391 /* Additional information about an indirect call. Not cleared when an edge
393 struct cgraph_indirect_call_info *indirect_info;
394 PTR GTY ((skip (""))) aux;
395 /* When equal to CIF_OK, inline this call. Otherwise, points to the
396 explanation why function was not inlined. */
397 cgraph_inline_failed_t inline_failed;
398 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
399 when the function is serialized in. */
400 unsigned int lto_stmt_uid;
401 /* Expected frequency of executions within the function.
402 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
403 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
405 /* Unique id of the edge. */
407 /* Depth of loop nest, 1 means no loop nest. */
408 unsigned short int loop_nest;
409 /* Whether this edge was made direct by indirect inlining. */
410 unsigned int indirect_inlining_edge : 1;
411 /* Whether this edge describes an indirect call with an undetermined
413 unsigned int indirect_unknown_callee : 1;
414 /* Whether this edge is still a dangling */
415 /* True if the corresponding CALL stmt cannot be inlined. */
416 unsigned int call_stmt_cannot_inline_p : 1;
417 /* Can this call throw externally? */
418 unsigned int can_throw_external : 1;
421 #define CGRAPH_FREQ_BASE 1000
422 #define CGRAPH_FREQ_MAX 100000
424 typedef struct cgraph_edge *cgraph_edge_p;
426 DEF_VEC_P(cgraph_edge_p);
427 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
429 /* The varpool data structure.
430 Each static variable decl has assigned varpool_node. */
432 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
434 /* Pointer to the next function in varpool_nodes. */
435 struct varpool_node *next, *prev;
436 /* Pointer to the next function in varpool_nodes_queue. */
437 struct varpool_node *next_needed, *prev_needed;
438 /* For normal nodes a pointer to the first extra name alias. For alias
439 nodes a pointer to the normal node. */
440 struct varpool_node *extra_name;
441 struct ipa_ref_list ref_list;
442 PTR GTY ((skip)) aux;
443 /* Ordering of all cgraph nodes. */
446 /* Set when function must be output - it is externally visible
447 or its address is taken. */
449 /* Needed variables might become dead by optimization. This flag
450 forces the variable to be output even if it appears dead otherwise. */
451 unsigned force_output : 1;
452 /* Set once the variable has been instantiated and its callee
454 unsigned analyzed : 1;
455 /* Set once it has been finalized so we consider it to be output. */
456 unsigned finalized : 1;
457 /* Set when variable is scheduled to be assembled. */
459 /* Set when function is visible by other units. */
460 unsigned externally_visible : 1;
461 /* Set for aliases once they got through assemble_alias. Also set for
462 extra name aliases in varpool_extra_name_alias. */
464 /* Set when variable is used from other LTRANS partition. */
465 unsigned used_from_other_partition : 1;
466 /* Set when variable is available in the other LTRANS partition. */
467 unsigned in_other_partition : 1;
470 /* Every top level asm statement is put into a cgraph_asm_node. */
472 struct GTY(()) cgraph_asm_node {
474 struct cgraph_asm_node *next;
475 /* String for this asm node. */
477 /* Ordering of all cgraph nodes. */
481 extern GTY(()) struct cgraph_node *cgraph_nodes;
482 extern GTY(()) int cgraph_n_nodes;
483 extern GTY(()) int cgraph_max_uid;
484 extern GTY(()) int cgraph_edge_max_uid;
485 extern GTY(()) int cgraph_max_pid;
486 extern bool cgraph_global_info_ready;
489 /* Callgraph is being constructed. It is safe to add new functions. */
490 CGRAPH_STATE_CONSTRUCTION,
491 /* Callgraph is built and IPA passes are being run. */
493 /* Callgraph is built and all functions are transformed to SSA form. */
494 CGRAPH_STATE_IPA_SSA,
495 /* Functions are now ordered and being passed to RTL expanders. */
496 CGRAPH_STATE_EXPANSION,
497 /* All cgraph expansion is done. */
498 CGRAPH_STATE_FINISHED
500 extern enum cgraph_state cgraph_state;
501 extern bool cgraph_function_flags_ready;
502 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
503 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
505 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
506 extern GTY(()) int cgraph_order;
509 void dump_cgraph (FILE *);
510 void debug_cgraph (void);
511 void dump_cgraph_node (FILE *, struct cgraph_node *);
512 void debug_cgraph_node (struct cgraph_node *);
513 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
514 void cgraph_remove_edge (struct cgraph_edge *);
515 void cgraph_remove_node (struct cgraph_node *);
516 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
517 void cgraph_release_function_body (struct cgraph_node *);
518 void cgraph_node_remove_callees (struct cgraph_node *node);
519 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
520 struct cgraph_node *,
521 gimple, gcov_type, int, int);
522 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
523 gcov_type, int, int);
524 struct cgraph_node * cgraph_get_node (tree);
525 struct cgraph_node *cgraph_node (tree);
526 bool cgraph_same_body_alias (tree, tree);
527 void cgraph_add_thunk (tree, tree, bool, HOST_WIDE_INT, HOST_WIDE_INT, tree, tree);
528 void cgraph_remove_same_body_alias (struct cgraph_node *);
529 struct cgraph_node *cgraph_node_for_asm (tree);
530 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
531 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
532 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
533 void cgraph_create_edge_including_clones (struct cgraph_node *,
534 struct cgraph_node *,
535 gimple, gimple, gcov_type, int, int,
536 cgraph_inline_failed_t);
537 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
538 struct cgraph_local_info *cgraph_local_info (tree);
539 struct cgraph_global_info *cgraph_global_info (tree);
540 struct cgraph_rtl_info *cgraph_rtl_info (tree);
541 const char * cgraph_node_name (struct cgraph_node *);
542 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
543 struct cgraph_node *, gimple,
544 unsigned, gcov_type, int, int, bool);
545 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, int,
546 int, bool, VEC(cgraph_edge_p,heap) *);
548 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
549 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
551 struct cgraph_asm_node *cgraph_add_asm_node (tree);
553 bool cgraph_function_possibly_inlined_p (tree);
554 void cgraph_unnest_node (struct cgraph_node *);
556 enum availability cgraph_function_body_availability (struct cgraph_node *);
557 void cgraph_add_new_function (tree, bool);
558 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
559 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
560 VEC(cgraph_edge_p,heap)*,
561 VEC(ipa_replace_map_p,gc)* tree_map,
562 bitmap args_to_skip);
564 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
565 void cgraph_set_readonly_flag (struct cgraph_node *, bool);
566 void cgraph_set_pure_flag (struct cgraph_node *, bool);
567 void cgraph_set_looping_const_or_pure_flag (struct cgraph_node *, bool);
569 /* In cgraphunit.c */
570 void cgraph_finalize_function (tree, bool);
571 void cgraph_mark_if_needed (tree);
572 void cgraph_finalize_compilation_unit (void);
573 void cgraph_optimize (void);
574 void cgraph_mark_needed_node (struct cgraph_node *);
575 void cgraph_mark_address_taken_node (struct cgraph_node *);
576 void cgraph_mark_reachable_node (struct cgraph_node *);
577 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
578 bool cgraph_preserve_function_body_p (tree);
579 void verify_cgraph (void);
580 void verify_cgraph_node (struct cgraph_node *);
581 void cgraph_build_static_cdtor (char which, tree body, int priority);
582 void cgraph_reset_static_var_maps (void);
583 void init_cgraph (void);
584 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
585 VEC(cgraph_edge_p,heap)*,
586 VEC(ipa_replace_map_p,gc)*,
588 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap);
589 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
590 void record_references_in_initializer (tree, bool);
591 bool cgraph_process_new_functions (void);
593 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
595 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
596 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
597 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
599 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
601 struct cgraph_edge_hook_list;
602 struct cgraph_node_hook_list;
603 struct cgraph_2edge_hook_list;
604 struct cgraph_2node_hook_list;
605 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
606 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
607 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
609 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
610 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
612 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
613 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
614 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
615 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
616 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
617 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
618 void cgraph_materialize_all_clones (void);
619 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
620 bool cgraph_propagate_frequency (struct cgraph_node *node);
621 /* In cgraphbuild.c */
622 unsigned int rebuild_cgraph_edges (void);
623 void cgraph_rebuild_references (void);
624 void reset_inline_failed (struct cgraph_node *);
625 int compute_call_stmt_bb_frequency (tree, basic_block bb);
628 bool cgraph_remove_unreachable_nodes (bool, FILE *);
629 int cgraph_postorder (struct cgraph_node **);
630 cgraph_node_set cgraph_node_set_new (void);
631 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
632 struct cgraph_node *);
633 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
634 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
635 void dump_cgraph_node_set (FILE *, cgraph_node_set);
636 void debug_cgraph_node_set (cgraph_node_set);
638 varpool_node_set varpool_node_set_new (void);
639 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
640 struct varpool_node *);
641 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
642 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
643 void dump_varpool_node_set (FILE *, varpool_node_set);
644 void debug_varpool_node_set (varpool_node_set);
647 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
650 extern GTY(()) struct varpool_node *varpool_nodes_queue;
651 extern GTY(()) struct varpool_node *varpool_nodes;
653 struct varpool_node *varpool_node (tree);
654 struct varpool_node *varpool_node_for_asm (tree asmname);
655 void varpool_mark_needed_node (struct varpool_node *);
656 void debug_varpool (void);
657 void dump_varpool (FILE *);
658 void dump_varpool_node (FILE *, struct varpool_node *);
660 void varpool_finalize_decl (tree);
661 bool decide_is_variable_needed (struct varpool_node *, tree);
662 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
663 void cgraph_make_decl_local (tree);
664 void cgraph_make_node_local (struct cgraph_node *);
665 bool cgraph_node_can_be_local_p (struct cgraph_node *);
668 struct varpool_node * varpool_get_node (tree decl);
669 void varpool_remove_node (struct varpool_node *node);
670 bool varpool_assemble_pending_decls (void);
671 bool varpool_assemble_decl (struct varpool_node *node);
672 bool varpool_analyze_pending_decls (void);
673 void varpool_remove_unreferenced_decls (void);
674 void varpool_empty_needed_queue (void);
675 bool varpool_extra_name_alias (tree, tree);
676 const char * varpool_node_name (struct varpool_node *node);
677 void varpool_reset_queue (void);
679 /* Walk all reachable static variables. */
680 #define FOR_EACH_STATIC_VARIABLE(node) \
681 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
683 /* Return first reachable static variable with initializer. */
684 static inline struct varpool_node *
685 varpool_first_static_initializer (void)
687 struct varpool_node *node;
688 for (node = varpool_nodes_queue; node; node = node->next_needed)
690 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
691 if (DECL_INITIAL (node->decl))
697 /* Return next reachable static variable with initializer after NODE. */
698 static inline struct varpool_node *
699 varpool_next_static_initializer (struct varpool_node *node)
701 for (node = node->next_needed; node; node = node->next_needed)
703 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
704 if (DECL_INITIAL (node->decl))
710 /* Walk all static variables with initializer set. */
711 #define FOR_EACH_STATIC_INITIALIZER(node) \
712 for ((node) = varpool_first_static_initializer (); (node); \
713 (node) = varpool_next_static_initializer (node))
715 /* In ipa-inline.c */
716 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
717 unsigned int compute_inline_parameters (struct cgraph_node *);
720 /* Create a new static variable of type TYPE. */
721 tree add_new_static_var (tree type);
723 /* Return true if iterator CSI points to nothing. */
725 csi_end_p (cgraph_node_set_iterator csi)
727 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
730 /* Advance iterator CSI. */
732 csi_next (cgraph_node_set_iterator *csi)
737 /* Return the node pointed to by CSI. */
738 static inline struct cgraph_node *
739 csi_node (cgraph_node_set_iterator csi)
741 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
744 /* Return an iterator to the first node in SET. */
745 static inline cgraph_node_set_iterator
746 csi_start (cgraph_node_set set)
748 cgraph_node_set_iterator csi;
755 /* Return true if SET contains NODE. */
757 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
759 cgraph_node_set_iterator csi;
760 csi = cgraph_node_set_find (set, node);
761 return !csi_end_p (csi);
764 /* Return number of nodes in SET. */
766 cgraph_node_set_size (cgraph_node_set set)
768 return htab_elements (set->hashtab);
771 /* Return true if iterator VSI points to nothing. */
773 vsi_end_p (varpool_node_set_iterator vsi)
775 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
778 /* Advance iterator VSI. */
780 vsi_next (varpool_node_set_iterator *vsi)
785 /* Return the node pointed to by VSI. */
786 static inline struct varpool_node *
787 vsi_node (varpool_node_set_iterator vsi)
789 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
792 /* Return an iterator to the first node in SET. */
793 static inline varpool_node_set_iterator
794 vsi_start (varpool_node_set set)
796 varpool_node_set_iterator vsi;
803 /* Return true if SET contains NODE. */
805 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
807 varpool_node_set_iterator vsi;
808 vsi = varpool_node_set_find (set, node);
809 return !vsi_end_p (vsi);
812 /* Return number of nodes in SET. */
814 varpool_node_set_size (varpool_node_set set)
816 return htab_elements (set->hashtab);
819 /* Uniquize all constants that appear in memory.
820 Each constant in memory thus far output is recorded
821 in `const_desc_table'. */
823 struct GTY(()) constant_descriptor_tree {
824 /* A MEM for the constant. */
827 /* The value of the constant. */
830 /* Hash of value. Computing the hash from value each time
831 hashfn is called can't work properly, as that means recursive
832 use of the hash table during hash table expansion. */
836 /* Return true if set is nonempty. */
838 cgraph_node_set_nonempty_p (cgraph_node_set set)
840 return VEC_length (cgraph_node_ptr, set->nodes);
843 /* Return true if set is nonempty. */
845 varpool_node_set_nonempty_p (varpool_node_set set)
847 return VEC_length (varpool_node_ptr, set->nodes);
850 /* Return true when function NODE is only called directly.
851 i.e. it is not externally visible, address was not taken and
852 it is not used in any other non-standard way. */
855 cgraph_only_called_directly_p (struct cgraph_node *node)
857 return !node->needed && !node->local.externally_visible;
860 /* Return true when function NODE can be removed from callgraph
861 if all direct calls are eliminated. */
864 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
866 return (!node->needed && !node->reachable_from_other_partition
867 && (DECL_COMDAT (node->decl) || !node->local.externally_visible));
870 /* Constant pool accessor function. */
871 htab_t constant_pool_htab (void);
873 #include "ipa-ref-inline.h"
875 #endif /* GCC_CGRAPH_H */