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. */
379 /* ECF flags determined from the caller. */
383 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
384 /* Expected number of executions: calculated in profile.c. */
386 struct cgraph_node *caller;
387 struct cgraph_node *callee;
388 struct cgraph_edge *prev_caller;
389 struct cgraph_edge *next_caller;
390 struct cgraph_edge *prev_callee;
391 struct cgraph_edge *next_callee;
393 /* Additional information about an indirect call. Not cleared when an edge
395 struct cgraph_indirect_call_info *indirect_info;
396 PTR GTY ((skip (""))) aux;
397 /* When equal to CIF_OK, inline this call. Otherwise, points to the
398 explanation why function was not inlined. */
399 cgraph_inline_failed_t inline_failed;
400 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
401 when the function is serialized in. */
402 unsigned int lto_stmt_uid;
403 /* Expected frequency of executions within the function.
404 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
405 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
407 /* Unique id of the edge. */
409 /* Depth of loop nest, 1 means no loop nest. */
410 unsigned short int loop_nest;
411 /* Whether this edge was made direct by indirect inlining. */
412 unsigned int indirect_inlining_edge : 1;
413 /* Whether this edge describes an indirect call with an undetermined
415 unsigned int indirect_unknown_callee : 1;
416 /* Whether this edge is still a dangling */
417 /* True if the corresponding CALL stmt cannot be inlined. */
418 unsigned int call_stmt_cannot_inline_p : 1;
419 /* Can this call throw externally? */
420 unsigned int can_throw_external : 1;
423 #define CGRAPH_FREQ_BASE 1000
424 #define CGRAPH_FREQ_MAX 100000
426 typedef struct cgraph_edge *cgraph_edge_p;
428 DEF_VEC_P(cgraph_edge_p);
429 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
431 /* The varpool data structure.
432 Each static variable decl has assigned varpool_node. */
434 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
436 /* Pointer to the next function in varpool_nodes. */
437 struct varpool_node *next, *prev;
438 /* Pointer to the next function in varpool_nodes_queue. */
439 struct varpool_node *next_needed, *prev_needed;
440 /* For normal nodes a pointer to the first extra name alias. For alias
441 nodes a pointer to the normal node. */
442 struct varpool_node *extra_name;
443 struct ipa_ref_list ref_list;
444 PTR GTY ((skip)) aux;
445 /* Ordering of all cgraph nodes. */
448 /* Set when function must be output - it is externally visible
449 or its address is taken. */
451 /* Needed variables might become dead by optimization. This flag
452 forces the variable to be output even if it appears dead otherwise. */
453 unsigned force_output : 1;
454 /* Set once the variable has been instantiated and its callee
456 unsigned analyzed : 1;
457 /* Set once it has been finalized so we consider it to be output. */
458 unsigned finalized : 1;
459 /* Set when variable is scheduled to be assembled. */
461 /* Set when function is visible by other units. */
462 unsigned externally_visible : 1;
463 /* Set for aliases once they got through assemble_alias. Also set for
464 extra name aliases in varpool_extra_name_alias. */
466 /* Set when variable is used from other LTRANS partition. */
467 unsigned used_from_other_partition : 1;
468 /* Set when variable is available in the other LTRANS partition. */
469 unsigned in_other_partition : 1;
472 /* Every top level asm statement is put into a cgraph_asm_node. */
474 struct GTY(()) cgraph_asm_node {
476 struct cgraph_asm_node *next;
477 /* String for this asm node. */
479 /* Ordering of all cgraph nodes. */
483 extern GTY(()) struct cgraph_node *cgraph_nodes;
484 extern GTY(()) int cgraph_n_nodes;
485 extern GTY(()) int cgraph_max_uid;
486 extern GTY(()) int cgraph_edge_max_uid;
487 extern GTY(()) int cgraph_max_pid;
488 extern bool cgraph_global_info_ready;
491 /* Callgraph is being constructed. It is safe to add new functions. */
492 CGRAPH_STATE_CONSTRUCTION,
493 /* Callgraph is built and IPA passes are being run. */
495 /* Callgraph is built and all functions are transformed to SSA form. */
496 CGRAPH_STATE_IPA_SSA,
497 /* Functions are now ordered and being passed to RTL expanders. */
498 CGRAPH_STATE_EXPANSION,
499 /* All cgraph expansion is done. */
500 CGRAPH_STATE_FINISHED
502 extern enum cgraph_state cgraph_state;
503 extern bool cgraph_function_flags_ready;
504 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
505 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
507 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
508 extern GTY(()) int cgraph_order;
511 void dump_cgraph (FILE *);
512 void debug_cgraph (void);
513 void dump_cgraph_node (FILE *, struct cgraph_node *);
514 void debug_cgraph_node (struct cgraph_node *);
515 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
516 void cgraph_remove_edge (struct cgraph_edge *);
517 void cgraph_remove_node (struct cgraph_node *);
518 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
519 void cgraph_release_function_body (struct cgraph_node *);
520 void cgraph_node_remove_callees (struct cgraph_node *node);
521 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
522 struct cgraph_node *,
523 gimple, gcov_type, int, int);
524 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple, int,
525 gcov_type, int, int);
526 struct cgraph_node * cgraph_get_node (tree);
527 struct cgraph_node *cgraph_node (tree);
528 bool cgraph_same_body_alias (tree, tree);
529 void cgraph_add_thunk (tree, tree, bool, HOST_WIDE_INT, HOST_WIDE_INT, tree, tree);
530 void cgraph_remove_same_body_alias (struct cgraph_node *);
531 struct cgraph_node *cgraph_node_for_asm (tree);
532 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
533 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
534 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
535 void cgraph_create_edge_including_clones (struct cgraph_node *,
536 struct cgraph_node *,
537 gimple, gimple, gcov_type, int, int,
538 cgraph_inline_failed_t);
539 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
540 struct cgraph_local_info *cgraph_local_info (tree);
541 struct cgraph_global_info *cgraph_global_info (tree);
542 struct cgraph_rtl_info *cgraph_rtl_info (tree);
543 const char * cgraph_node_name (struct cgraph_node *);
544 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
545 struct cgraph_node *, gimple,
546 unsigned, gcov_type, int, int, bool);
547 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, int,
548 int, bool, VEC(cgraph_edge_p,heap) *);
550 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
551 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
553 struct cgraph_asm_node *cgraph_add_asm_node (tree);
555 bool cgraph_function_possibly_inlined_p (tree);
556 void cgraph_unnest_node (struct cgraph_node *);
558 enum availability cgraph_function_body_availability (struct cgraph_node *);
559 void cgraph_add_new_function (tree, bool);
560 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
561 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
562 VEC(cgraph_edge_p,heap)*,
563 VEC(ipa_replace_map_p,gc)* tree_map,
564 bitmap args_to_skip);
566 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
567 void cgraph_set_readonly_flag (struct cgraph_node *, bool);
568 void cgraph_set_pure_flag (struct cgraph_node *, bool);
569 void cgraph_set_looping_const_or_pure_flag (struct cgraph_node *, bool);
571 /* In cgraphunit.c */
572 void cgraph_finalize_function (tree, bool);
573 void cgraph_mark_if_needed (tree);
574 void cgraph_finalize_compilation_unit (void);
575 void cgraph_optimize (void);
576 void cgraph_mark_needed_node (struct cgraph_node *);
577 void cgraph_mark_address_taken_node (struct cgraph_node *);
578 void cgraph_mark_reachable_node (struct cgraph_node *);
579 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
580 bool cgraph_preserve_function_body_p (tree);
581 void verify_cgraph (void);
582 void verify_cgraph_node (struct cgraph_node *);
583 void cgraph_build_static_cdtor (char which, tree body, int priority);
584 void cgraph_reset_static_var_maps (void);
585 void init_cgraph (void);
586 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
587 VEC(cgraph_edge_p,heap)*,
588 VEC(ipa_replace_map_p,gc)*,
590 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap);
591 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
592 void record_references_in_initializer (tree, bool);
593 bool cgraph_process_new_functions (void);
595 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
597 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
598 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
599 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
601 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
603 struct cgraph_edge_hook_list;
604 struct cgraph_node_hook_list;
605 struct cgraph_2edge_hook_list;
606 struct cgraph_2node_hook_list;
607 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
608 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
609 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
611 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
612 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
614 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
615 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
616 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
617 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
618 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
619 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
620 void cgraph_materialize_all_clones (void);
621 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
622 bool cgraph_propagate_frequency (struct cgraph_node *node);
623 /* In cgraphbuild.c */
624 unsigned int rebuild_cgraph_edges (void);
625 void cgraph_rebuild_references (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);
679 void varpool_reset_queue (void);
681 /* Walk all reachable static variables. */
682 #define FOR_EACH_STATIC_VARIABLE(node) \
683 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
685 /* Return first reachable static variable with initializer. */
686 static inline struct varpool_node *
687 varpool_first_static_initializer (void)
689 struct varpool_node *node;
690 for (node = varpool_nodes_queue; node; node = node->next_needed)
692 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
693 if (DECL_INITIAL (node->decl))
699 /* Return next reachable static variable with initializer after NODE. */
700 static inline struct varpool_node *
701 varpool_next_static_initializer (struct varpool_node *node)
703 for (node = node->next_needed; node; node = node->next_needed)
705 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
706 if (DECL_INITIAL (node->decl))
712 /* Walk all static variables with initializer set. */
713 #define FOR_EACH_STATIC_INITIALIZER(node) \
714 for ((node) = varpool_first_static_initializer (); (node); \
715 (node) = varpool_next_static_initializer (node))
717 /* In ipa-inline.c */
718 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
719 unsigned int compute_inline_parameters (struct cgraph_node *);
722 /* Create a new static variable of type TYPE. */
723 tree add_new_static_var (tree type);
725 /* Return true if iterator CSI points to nothing. */
727 csi_end_p (cgraph_node_set_iterator csi)
729 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
732 /* Advance iterator CSI. */
734 csi_next (cgraph_node_set_iterator *csi)
739 /* Return the node pointed to by CSI. */
740 static inline struct cgraph_node *
741 csi_node (cgraph_node_set_iterator csi)
743 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
746 /* Return an iterator to the first node in SET. */
747 static inline cgraph_node_set_iterator
748 csi_start (cgraph_node_set set)
750 cgraph_node_set_iterator csi;
757 /* Return true if SET contains NODE. */
759 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
761 cgraph_node_set_iterator csi;
762 csi = cgraph_node_set_find (set, node);
763 return !csi_end_p (csi);
766 /* Return number of nodes in SET. */
768 cgraph_node_set_size (cgraph_node_set set)
770 return htab_elements (set->hashtab);
773 /* Return true if iterator VSI points to nothing. */
775 vsi_end_p (varpool_node_set_iterator vsi)
777 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
780 /* Advance iterator VSI. */
782 vsi_next (varpool_node_set_iterator *vsi)
787 /* Return the node pointed to by VSI. */
788 static inline struct varpool_node *
789 vsi_node (varpool_node_set_iterator vsi)
791 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
794 /* Return an iterator to the first node in SET. */
795 static inline varpool_node_set_iterator
796 vsi_start (varpool_node_set set)
798 varpool_node_set_iterator vsi;
805 /* Return true if SET contains NODE. */
807 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
809 varpool_node_set_iterator vsi;
810 vsi = varpool_node_set_find (set, node);
811 return !vsi_end_p (vsi);
814 /* Return number of nodes in SET. */
816 varpool_node_set_size (varpool_node_set set)
818 return htab_elements (set->hashtab);
821 /* Uniquize all constants that appear in memory.
822 Each constant in memory thus far output is recorded
823 in `const_desc_table'. */
825 struct GTY(()) constant_descriptor_tree {
826 /* A MEM for the constant. */
829 /* The value of the constant. */
832 /* Hash of value. Computing the hash from value each time
833 hashfn is called can't work properly, as that means recursive
834 use of the hash table during hash table expansion. */
838 /* Return true if set is nonempty. */
840 cgraph_node_set_nonempty_p (cgraph_node_set set)
842 return VEC_length (cgraph_node_ptr, set->nodes);
845 /* Return true if set is nonempty. */
847 varpool_node_set_nonempty_p (varpool_node_set set)
849 return VEC_length (varpool_node_ptr, set->nodes);
852 /* Return true when function NODE is only called directly.
853 i.e. it is not externally visible, address was not taken and
854 it is not used in any other non-standard way. */
857 cgraph_only_called_directly_p (struct cgraph_node *node)
859 return !node->needed && !node->local.externally_visible;
862 /* Return true when function NODE can be removed from callgraph
863 if all direct calls are eliminated. */
866 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
868 return (!node->needed && !node->reachable_from_other_partition
869 && (DECL_COMDAT (node->decl) || !node->local.externally_visible));
872 /* Constant pool accessor function. */
873 htab_t constant_pool_htab (void);
875 #include "ipa-ref-inline.h"
877 #endif /* GCC_CGRAPH_H */