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 /* Ordering of all cgraph nodes. */
445 /* Set when function must be output - it is externally visible
446 or its address is taken. */
448 /* Needed variables might become dead by optimization. This flag
449 forces the variable to be output even if it appears dead otherwise. */
450 unsigned force_output : 1;
451 /* Set once the variable has been instantiated and its callee
453 unsigned analyzed : 1;
454 /* Set once it has been finalized so we consider it to be output. */
455 unsigned finalized : 1;
456 /* Set when variable is scheduled to be assembled. */
458 /* Set when function is visible by other units. */
459 unsigned externally_visible : 1;
460 /* Set for aliases once they got through assemble_alias. Also set for
461 extra name aliases in varpool_extra_name_alias. */
463 /* Set when variable is used from other LTRANS partition. */
464 unsigned used_from_other_partition : 1;
465 /* Set when variable is available in the other LTRANS partition. */
466 unsigned in_other_partition : 1;
469 /* Every top level asm statement is put into a cgraph_asm_node. */
471 struct GTY(()) cgraph_asm_node {
473 struct cgraph_asm_node *next;
474 /* String for this asm node. */
476 /* Ordering of all cgraph nodes. */
480 extern GTY(()) struct cgraph_node *cgraph_nodes;
481 extern GTY(()) int cgraph_n_nodes;
482 extern GTY(()) int cgraph_max_uid;
483 extern GTY(()) int cgraph_edge_max_uid;
484 extern GTY(()) int cgraph_max_pid;
485 extern bool cgraph_global_info_ready;
488 /* Callgraph is being constructed. It is safe to add new functions. */
489 CGRAPH_STATE_CONSTRUCTION,
490 /* Callgraph is built and IPA passes are being run. */
492 /* Callgraph is built and all functions are transformed to SSA form. */
493 CGRAPH_STATE_IPA_SSA,
494 /* Functions are now ordered and being passed to RTL expanders. */
495 CGRAPH_STATE_EXPANSION,
496 /* All cgraph expansion is done. */
497 CGRAPH_STATE_FINISHED
499 extern enum cgraph_state cgraph_state;
500 extern bool cgraph_function_flags_ready;
501 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
502 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
504 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
505 extern GTY(()) int cgraph_order;
508 void dump_cgraph (FILE *);
509 void debug_cgraph (void);
510 void dump_cgraph_node (FILE *, struct cgraph_node *);
511 void debug_cgraph_node (struct cgraph_node *);
512 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
513 void cgraph_remove_edge (struct cgraph_edge *);
514 void cgraph_remove_node (struct cgraph_node *);
515 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
516 void cgraph_release_function_body (struct cgraph_node *);
517 void cgraph_node_remove_callees (struct cgraph_node *node);
518 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
519 struct cgraph_node *,
520 gimple, gcov_type, int, int);
521 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
522 gcov_type, int, int);
523 struct cgraph_node * cgraph_get_node (tree);
524 struct cgraph_node *cgraph_node (tree);
525 bool cgraph_same_body_alias (tree, tree);
526 void cgraph_add_thunk (tree, tree, bool, HOST_WIDE_INT, HOST_WIDE_INT, tree, tree);
527 void cgraph_remove_same_body_alias (struct cgraph_node *);
528 struct cgraph_node *cgraph_node_for_asm (tree);
529 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
530 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
531 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
532 void cgraph_create_edge_including_clones (struct cgraph_node *,
533 struct cgraph_node *,
534 gimple, gimple, gcov_type, int, int,
535 cgraph_inline_failed_t);
536 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
537 struct cgraph_local_info *cgraph_local_info (tree);
538 struct cgraph_global_info *cgraph_global_info (tree);
539 struct cgraph_rtl_info *cgraph_rtl_info (tree);
540 const char * cgraph_node_name (struct cgraph_node *);
541 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
542 struct cgraph_node *, gimple,
543 unsigned, gcov_type, int, int, bool);
544 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, int,
545 int, bool, VEC(cgraph_edge_p,heap) *);
547 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
548 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
550 struct cgraph_asm_node *cgraph_add_asm_node (tree);
552 bool cgraph_function_possibly_inlined_p (tree);
553 void cgraph_unnest_node (struct cgraph_node *);
555 enum availability cgraph_function_body_availability (struct cgraph_node *);
556 void cgraph_add_new_function (tree, bool);
557 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
558 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
559 VEC(cgraph_edge_p,heap)*,
560 VEC(ipa_replace_map_p,gc)* tree_map,
561 bitmap args_to_skip);
563 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
564 void cgraph_set_readonly_flag (struct cgraph_node *, bool);
565 void cgraph_set_pure_flag (struct cgraph_node *, bool);
566 void cgraph_set_looping_const_or_pure_flag (struct cgraph_node *, bool);
568 /* In cgraphunit.c */
569 void cgraph_finalize_function (tree, bool);
570 void cgraph_mark_if_needed (tree);
571 void cgraph_finalize_compilation_unit (void);
572 void cgraph_optimize (void);
573 void cgraph_mark_needed_node (struct cgraph_node *);
574 void cgraph_mark_address_taken_node (struct cgraph_node *);
575 void cgraph_mark_reachable_node (struct cgraph_node *);
576 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
577 bool cgraph_preserve_function_body_p (tree);
578 void verify_cgraph (void);
579 void verify_cgraph_node (struct cgraph_node *);
580 void cgraph_build_static_cdtor (char which, tree body, int priority);
581 void cgraph_reset_static_var_maps (void);
582 void init_cgraph (void);
583 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
584 VEC(cgraph_edge_p,heap)*,
585 VEC(ipa_replace_map_p,gc)*,
587 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap);
588 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
589 void record_references_in_initializer (tree, bool);
590 bool cgraph_process_new_functions (void);
592 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
594 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
595 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
596 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
598 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
600 struct cgraph_edge_hook_list;
601 struct cgraph_node_hook_list;
602 struct cgraph_2edge_hook_list;
603 struct cgraph_2node_hook_list;
604 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
605 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
606 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
608 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
609 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
611 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
612 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
613 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
614 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
615 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
616 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
617 void cgraph_materialize_all_clones (void);
618 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
619 bool cgraph_propagate_frequency (struct cgraph_node *node);
620 /* In cgraphbuild.c */
621 unsigned int rebuild_cgraph_edges (void);
622 void reset_inline_failed (struct cgraph_node *);
623 int compute_call_stmt_bb_frequency (tree, basic_block bb);
626 bool cgraph_remove_unreachable_nodes (bool, FILE *);
627 int cgraph_postorder (struct cgraph_node **);
628 cgraph_node_set cgraph_node_set_new (void);
629 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
630 struct cgraph_node *);
631 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
632 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
633 void dump_cgraph_node_set (FILE *, cgraph_node_set);
634 void debug_cgraph_node_set (cgraph_node_set);
636 varpool_node_set varpool_node_set_new (void);
637 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
638 struct varpool_node *);
639 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
640 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
641 void dump_varpool_node_set (FILE *, varpool_node_set);
642 void debug_varpool_node_set (varpool_node_set);
645 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
648 extern GTY(()) struct varpool_node *varpool_nodes_queue;
649 extern GTY(()) struct varpool_node *varpool_nodes;
651 struct varpool_node *varpool_node (tree);
652 struct varpool_node *varpool_node_for_asm (tree asmname);
653 void varpool_mark_needed_node (struct varpool_node *);
654 void debug_varpool (void);
655 void dump_varpool (FILE *);
656 void dump_varpool_node (FILE *, struct varpool_node *);
658 void varpool_finalize_decl (tree);
659 bool decide_is_variable_needed (struct varpool_node *, tree);
660 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
661 void cgraph_make_decl_local (tree);
662 void cgraph_make_node_local (struct cgraph_node *);
663 bool cgraph_node_can_be_local_p (struct cgraph_node *);
666 struct varpool_node * varpool_get_node (tree decl);
667 void varpool_remove_node (struct varpool_node *node);
668 bool varpool_assemble_pending_decls (void);
669 bool varpool_assemble_decl (struct varpool_node *node);
670 bool varpool_analyze_pending_decls (void);
671 void varpool_remove_unreferenced_decls (void);
672 void varpool_empty_needed_queue (void);
673 bool varpool_extra_name_alias (tree, tree);
674 const char * varpool_node_name (struct varpool_node *node);
676 /* Walk all reachable static variables. */
677 #define FOR_EACH_STATIC_VARIABLE(node) \
678 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
680 /* Return first reachable static variable with initializer. */
681 static inline struct varpool_node *
682 varpool_first_static_initializer (void)
684 struct varpool_node *node;
685 for (node = varpool_nodes_queue; node; node = node->next_needed)
687 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
688 if (DECL_INITIAL (node->decl))
694 /* Return next reachable static variable with initializer after NODE. */
695 static inline struct varpool_node *
696 varpool_next_static_initializer (struct varpool_node *node)
698 for (node = node->next_needed; node; node = node->next_needed)
700 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
701 if (DECL_INITIAL (node->decl))
707 /* Walk all static variables with initializer set. */
708 #define FOR_EACH_STATIC_INITIALIZER(node) \
709 for ((node) = varpool_first_static_initializer (); (node); \
710 (node) = varpool_next_static_initializer (node))
712 /* In ipa-inline.c */
713 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
714 unsigned int compute_inline_parameters (struct cgraph_node *);
717 /* Create a new static variable of type TYPE. */
718 tree add_new_static_var (tree type);
720 /* Return true if iterator CSI points to nothing. */
722 csi_end_p (cgraph_node_set_iterator csi)
724 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
727 /* Advance iterator CSI. */
729 csi_next (cgraph_node_set_iterator *csi)
734 /* Return the node pointed to by CSI. */
735 static inline struct cgraph_node *
736 csi_node (cgraph_node_set_iterator csi)
738 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
741 /* Return an iterator to the first node in SET. */
742 static inline cgraph_node_set_iterator
743 csi_start (cgraph_node_set set)
745 cgraph_node_set_iterator csi;
752 /* Return true if SET contains NODE. */
754 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
756 cgraph_node_set_iterator csi;
757 csi = cgraph_node_set_find (set, node);
758 return !csi_end_p (csi);
761 /* Return number of nodes in SET. */
763 cgraph_node_set_size (cgraph_node_set set)
765 return htab_elements (set->hashtab);
768 /* Return true if iterator VSI points to nothing. */
770 vsi_end_p (varpool_node_set_iterator vsi)
772 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
775 /* Advance iterator VSI. */
777 vsi_next (varpool_node_set_iterator *vsi)
782 /* Return the node pointed to by VSI. */
783 static inline struct varpool_node *
784 vsi_node (varpool_node_set_iterator vsi)
786 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
789 /* Return an iterator to the first node in SET. */
790 static inline varpool_node_set_iterator
791 vsi_start (varpool_node_set set)
793 varpool_node_set_iterator vsi;
800 /* Return true if SET contains NODE. */
802 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
804 varpool_node_set_iterator vsi;
805 vsi = varpool_node_set_find (set, node);
806 return !vsi_end_p (vsi);
809 /* Return number of nodes in SET. */
811 varpool_node_set_size (varpool_node_set set)
813 return htab_elements (set->hashtab);
816 /* Uniquize all constants that appear in memory.
817 Each constant in memory thus far output is recorded
818 in `const_desc_table'. */
820 struct GTY(()) constant_descriptor_tree {
821 /* A MEM for the constant. */
824 /* The value of the constant. */
827 /* Hash of value. Computing the hash from value each time
828 hashfn is called can't work properly, as that means recursive
829 use of the hash table during hash table expansion. */
833 /* Return true if set is nonempty. */
835 cgraph_node_set_nonempty_p (cgraph_node_set set)
837 return VEC_length (cgraph_node_ptr, set->nodes);
840 /* Return true if set is nonempty. */
842 varpool_node_set_nonempty_p (varpool_node_set set)
844 return VEC_length (varpool_node_ptr, set->nodes);
847 /* Return true when function NODE is only called directly.
848 i.e. it is not externally visible, address was not taken and
849 it is not used in any other non-standard way. */
852 cgraph_only_called_directly_p (struct cgraph_node *node)
854 return !node->needed && !node->local.externally_visible;
857 /* Return true when function NODE can be removed from callgraph
858 if all direct calls are eliminated. */
861 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
863 return (!node->needed && !node->reachable_from_other_partition
864 && (DECL_COMDAT (node->decl) || !node->local.externally_visible));
867 /* Constant pool accessor function. */
868 htab_t constant_pool_htab (void);
870 #include "ipa-ref-inline.h"
872 #endif /* GCC_CGRAPH_H */