2010-12-20 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / cgraph.h
blob69bc79c6b12ada10262463532c5e0ad4b1c0a76e
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
11 version.
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
16 for more details.
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/>. */
22 #ifndef GCC_CGRAPH_H
23 #define GCC_CGRAPH_H
25 #include "plugin-api.h"
26 #include "vec.h"
27 #include "tree.h"
28 #include "basic-block.h"
29 #include "function.h"
30 #include "ipa-ref.h" /* FIXME: inappropriate dependency of cgraph on IPA. */
32 enum availability
34 /* Not yet set by cgraph_function_body_availability. */
35 AVAIL_UNSET,
36 /* Function body/variable initializer is unknown. */
37 AVAIL_NOT_AVAILABLE,
38 /* Function body/variable initializer is known but might be replaced
39 by a different one from other compilation unit and thus needs to
40 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
41 arbitrary side effects on escaping variables and functions, while
42 like AVAILABLE it might access static variables. */
43 AVAIL_OVERWRITABLE,
44 /* Function body/variable initializer is known and will be used in final
45 program. */
46 AVAIL_AVAILABLE,
47 /* Function body/variable initializer is known and all it's uses are explicitly
48 visible within current unit (ie it's address is never taken and it is not
49 exported to other units).
50 Currently used only for functions. */
51 AVAIL_LOCAL
54 /* This is the information that is put into the cgraph local structure
55 to recover a function. */
56 struct lto_file_decl_data;
58 extern const char * const cgraph_availability_names[];
59 extern const char * const ld_plugin_symbol_resolution_names[];
61 /* Function inlining information. */
63 struct GTY(()) inline_summary
65 /* Estimated stack frame consumption by the function. */
66 HOST_WIDE_INT estimated_self_stack_size;
68 /* Size of the function body. */
69 int self_size;
70 /* How many instructions are likely going to disappear after inlining. */
71 int size_inlining_benefit;
72 /* Estimated time spent executing the function body. */
73 int self_time;
74 /* How much time is going to be saved by inlining. */
75 int time_inlining_benefit;
78 /* Information about thunk, used only for same body aliases. */
80 struct GTY(()) cgraph_thunk_info {
81 /* Information about the thunk. */
82 HOST_WIDE_INT fixed_offset;
83 HOST_WIDE_INT virtual_value;
84 tree alias;
85 bool this_adjusting;
86 bool virtual_offset_p;
87 /* Set to true when alias node is thunk. */
88 bool thunk_p;
91 /* Information about the function collected locally.
92 Available after function is analyzed. */
94 struct GTY(()) cgraph_local_info {
95 /* File stream where this node is being written to. */
96 struct lto_file_decl_data * lto_file_data;
98 struct inline_summary inline_summary;
100 /* Set when function function is visible in current compilation unit only
101 and its address is never taken. */
102 unsigned local : 1;
104 /* Set when function is visible by other units. */
105 unsigned externally_visible : 1;
107 /* Set once it has been finalized so we consider it to be output. */
108 unsigned finalized : 1;
110 /* False when there something makes inlining impossible (such as va_arg). */
111 unsigned inlinable : 1;
113 /* False when there something makes versioning impossible.
114 Currently computed and used only by ipa-cp. */
115 unsigned versionable : 1;
117 /* True when function should be inlined independently on its size. */
118 unsigned disregard_inline_limits : 1;
120 /* True when the function has been originally extern inline, but it is
121 redefined now. */
122 unsigned redefined_extern_inline : 1;
124 /* True if the function is going to be emitted in some other translation
125 unit, referenced from vtable. */
126 unsigned vtable_method : 1;
129 /* Information about the function that needs to be computed globally
130 once compilation is finished. Available only with -funit-at-a-time. */
132 struct GTY(()) cgraph_global_info {
133 /* Estimated stack frame consumption by the function. */
134 HOST_WIDE_INT estimated_stack_size;
135 /* Expected offset of the stack frame of inlined function. */
136 HOST_WIDE_INT stack_frame_offset;
138 /* For inline clones this points to the function they will be
139 inlined into. */
140 struct cgraph_node *inlined_to;
142 /* Estimated size of the function after inlining. */
143 int time;
144 int size;
146 /* Estimated growth after inlining. INT_MIN if not computed. */
147 int estimated_growth;
150 /* Information about the function that is propagated by the RTL backend.
151 Available only for functions that has been already assembled. */
153 struct GTY(()) cgraph_rtl_info {
154 unsigned int preferred_incoming_stack_boundary;
157 /* Represent which DECL tree (or reference to such tree)
158 will be replaced by another tree while versioning. */
159 struct GTY(()) ipa_replace_map
161 /* The tree that will be replaced. */
162 tree old_tree;
163 /* The new (replacing) tree. */
164 tree new_tree;
165 /* Parameter number to replace, when old_tree is NULL. */
166 int parm_num;
167 /* True when a substitution should be done, false otherwise. */
168 bool replace_p;
169 /* True when we replace a reference to old_tree. */
170 bool ref_p;
172 typedef struct ipa_replace_map *ipa_replace_map_p;
173 DEF_VEC_P(ipa_replace_map_p);
174 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
176 struct GTY(()) cgraph_clone_info
178 VEC(ipa_replace_map_p,gc)* tree_map;
179 bitmap args_to_skip;
180 bitmap combined_args_to_skip;
184 /* The cgraph data structure.
185 Each function decl has assigned cgraph_node listing callees and callers. */
187 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
188 tree decl;
189 struct cgraph_edge *callees;
190 struct cgraph_edge *callers;
191 struct cgraph_node *next;
192 struct cgraph_node *previous;
193 /* List of edges representing indirect calls with a yet undetermined
194 callee. */
195 struct cgraph_edge *indirect_calls;
196 /* For nested functions points to function the node is nested in. */
197 struct cgraph_node *origin;
198 /* Points to first nested function, if any. */
199 struct cgraph_node *nested;
200 /* Pointer to the next function with same origin, if any. */
201 struct cgraph_node *next_nested;
202 /* Pointer to the next function in cgraph_nodes_queue. */
203 struct cgraph_node *next_needed;
204 /* Pointer to the next clone. */
205 struct cgraph_node *next_sibling_clone;
206 struct cgraph_node *prev_sibling_clone;
207 struct cgraph_node *clones;
208 struct cgraph_node *clone_of;
209 /* For normal nodes pointer to the list of alias and thunk nodes,
210 in alias/thunk nodes pointer to the normal node. */
211 struct cgraph_node *same_body;
212 /* Circular list of nodes in the same comdat group if non-NULL. */
213 struct cgraph_node *same_comdat_group;
214 /* For functions with many calls sites it holds map from call expression
215 to the edge to speed up cgraph_edge function. */
216 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
217 /* Declaration node used to be clone of. */
218 tree former_clone_of;
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 ipa_ref_list ref_list;
228 struct cgraph_local_info local;
229 struct cgraph_global_info global;
230 struct cgraph_rtl_info rtl;
231 struct cgraph_clone_info clone;
232 struct cgraph_thunk_info thunk;
234 /* Expected number of executions: calculated in profile.c. */
235 gcov_type count;
236 /* How to scale counts at materialization time; used to merge
237 LTO units with different number of profile runs. */
238 int count_materialization_scale;
239 /* Unique id of the node. */
240 int uid;
241 /* Ordering of all cgraph nodes. */
242 int order;
244 /* unique id for profiling. pid is not suitable because of different
245 number of cfg nodes with -fprofile-generate and -fprofile-use */
246 int pid;
247 enum ld_plugin_symbol_resolution resolution;
249 /* Set when function must be output for some reason. The primary
250 use of this flag is to mark functions needed to be output for
251 non-standard reason. Functions that are externally visible
252 or reachable from functions needed to be output are marked
253 by specialized flags. */
254 unsigned needed : 1;
255 /* Set when function has address taken.
256 In current implementation it imply needed flag. */
257 unsigned address_taken : 1;
258 /* Set when decl is an abstract function pointed to by the
259 ABSTRACT_DECL_ORIGIN of a reachable function. */
260 unsigned abstract_and_needed : 1;
261 /* Set when function is reachable by call from other function
262 that is either reachable or needed.
263 This flag is computed at original cgraph construction and then
264 updated in cgraph_remove_unreachable_nodes. Note that after
265 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
266 nodes when they are needed for virtual clone instantiation. */
267 unsigned reachable : 1;
268 /* Set when function is reachable by call from other LTRANS partition. */
269 unsigned reachable_from_other_partition : 1;
270 /* Set once the function is lowered (i.e. its CFG is built). */
271 unsigned lowered : 1;
272 /* Set once the function has been instantiated and its callee
273 lists created. */
274 unsigned analyzed : 1;
275 /* Set when function is available in the other LTRANS partition.
276 During WPA output it is used to mark nodes that are present in
277 multiple partitions. */
278 unsigned in_other_partition : 1;
279 /* Set when function is scheduled to be processed by local passes. */
280 unsigned process : 1;
281 /* Set for aliases once they got through assemble_alias. */
282 unsigned alias : 1;
283 /* Set for nodes that was constructed and finalized by frontend. */
284 unsigned finalized_by_frontend : 1;
285 /* Set for alias and thunk nodes, same_body points to the node they are alias
286 of and they are linked through the next/previous pointers. */
287 unsigned same_body_alias : 1;
288 /* How commonly executed the node is. Initialized during branch
289 probabilities pass. */
290 ENUM_BITFIELD (node_frequency) frequency : 2;
291 /* True when function can only be called at startup (from static ctor). */
292 unsigned only_called_at_startup : 1;
293 /* True when function can only be called at startup (from static dtor). */
294 unsigned only_called_at_exit : 1;
297 typedef struct cgraph_node *cgraph_node_ptr;
299 DEF_VEC_P(cgraph_node_ptr);
300 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
301 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
303 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
304 can appear in multiple sets. */
305 struct GTY(()) cgraph_node_set_def
307 htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
308 VEC(cgraph_node_ptr, gc) *nodes;
311 typedef struct varpool_node *varpool_node_ptr;
313 DEF_VEC_P(varpool_node_ptr);
314 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
315 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
317 /* A varpool node set is a collection of varpool nodes. A varpool node
318 can appear in multiple sets. */
319 struct GTY(()) varpool_node_set_def
321 htab_t GTY((param_is (struct varpool_node_set_element_def))) hashtab;
322 VEC(varpool_node_ptr, gc) *nodes;
325 typedef struct cgraph_node_set_def *cgraph_node_set;
327 DEF_VEC_P(cgraph_node_set);
328 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
329 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
331 typedef struct varpool_node_set_def *varpool_node_set;
333 DEF_VEC_P(varpool_node_set);
334 DEF_VEC_ALLOC_P(varpool_node_set,gc);
335 DEF_VEC_ALLOC_P(varpool_node_set,heap);
337 /* A cgraph node set element contains an index in the vector of nodes in
338 the set. */
339 struct GTY(()) cgraph_node_set_element_def
341 struct cgraph_node *node;
342 HOST_WIDE_INT index;
345 typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
346 typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
348 /* Iterator structure for cgraph node sets. */
349 typedef struct
351 cgraph_node_set set;
352 unsigned index;
353 } cgraph_node_set_iterator;
355 /* A varpool node set element contains an index in the vector of nodes in
356 the set. */
357 struct GTY(()) varpool_node_set_element_def
359 struct varpool_node *node;
360 HOST_WIDE_INT index;
363 typedef struct varpool_node_set_element_def *varpool_node_set_element;
364 typedef const struct varpool_node_set_element_def *const_varpool_node_set_element;
366 /* Iterator structure for varpool node sets. */
367 typedef struct
369 varpool_node_set set;
370 unsigned index;
371 } varpool_node_set_iterator;
373 #define DEFCIFCODE(code, string) CIF_ ## code,
374 /* Reasons for inlining failures. */
375 typedef enum {
376 #include "cif-code.def"
377 CIF_N_REASONS
378 } cgraph_inline_failed_t;
380 /* Structure containing additional information about an indirect call. */
382 struct GTY(()) cgraph_indirect_call_info
384 /* Offset accumulated from ancestor jump functions of inlined call graph
385 edges. */
386 HOST_WIDE_INT anc_offset;
387 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
388 HOST_WIDE_INT otr_token;
389 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
390 tree otr_type;
391 /* Delta by which must be added to this parameter. For polymorphic calls
392 only. */
393 tree thunk_delta;
394 /* Index of the parameter that is called. */
395 int param_index;
396 /* ECF flags determined from the caller. */
397 int ecf_flags;
399 /* Set when the call is a virtual call with the parameter being the
400 associated object pointer rather than a simple direct call. */
401 unsigned polymorphic : 1;
404 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
405 /* Expected number of executions: calculated in profile.c. */
406 gcov_type count;
407 struct cgraph_node *caller;
408 struct cgraph_node *callee;
409 struct cgraph_edge *prev_caller;
410 struct cgraph_edge *next_caller;
411 struct cgraph_edge *prev_callee;
412 struct cgraph_edge *next_callee;
413 gimple call_stmt;
414 /* Additional information about an indirect call. Not cleared when an edge
415 becomes direct. */
416 struct cgraph_indirect_call_info *indirect_info;
417 PTR GTY ((skip (""))) aux;
418 /* When equal to CIF_OK, inline this call. Otherwise, points to the
419 explanation why function was not inlined. */
420 cgraph_inline_failed_t inline_failed;
421 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
422 when the function is serialized in. */
423 unsigned int lto_stmt_uid;
424 /* Expected frequency of executions within the function.
425 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
426 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
427 int frequency;
428 /* Unique id of the edge. */
429 int uid;
430 /* Depth of loop nest, 1 means no loop nest. */
431 unsigned short int loop_nest;
432 /* Whether this edge was made direct by indirect inlining. */
433 unsigned int indirect_inlining_edge : 1;
434 /* Whether this edge describes an indirect call with an undetermined
435 callee. */
436 unsigned int indirect_unknown_callee : 1;
437 /* Whether this edge is still a dangling */
438 /* True if the corresponding CALL stmt cannot be inlined. */
439 unsigned int call_stmt_cannot_inline_p : 1;
440 /* Can this call throw externally? */
441 unsigned int can_throw_external : 1;
444 #define CGRAPH_FREQ_BASE 1000
445 #define CGRAPH_FREQ_MAX 100000
447 typedef struct cgraph_edge *cgraph_edge_p;
449 DEF_VEC_P(cgraph_edge_p);
450 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
452 /* The varpool data structure.
453 Each static variable decl has assigned varpool_node. */
455 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
456 tree decl;
457 /* Pointer to the next function in varpool_nodes. */
458 struct varpool_node *next, *prev;
459 /* Pointer to the next function in varpool_nodes_queue. */
460 struct varpool_node *next_needed, *prev_needed;
461 /* For normal nodes a pointer to the first extra name alias. For alias
462 nodes a pointer to the normal node. */
463 struct varpool_node *extra_name;
464 /* Circular list of nodes in the same comdat group if non-NULL. */
465 struct varpool_node *same_comdat_group;
466 struct ipa_ref_list ref_list;
467 /* File stream where this node is being written to. */
468 struct lto_file_decl_data * lto_file_data;
469 PTR GTY ((skip)) aux;
470 /* Ordering of all cgraph nodes. */
471 int order;
472 enum ld_plugin_symbol_resolution resolution;
474 /* Set when function must be output - it is externally visible
475 or its address is taken. */
476 unsigned needed : 1;
477 /* Needed variables might become dead by optimization. This flag
478 forces the variable to be output even if it appears dead otherwise. */
479 unsigned force_output : 1;
480 /* Set once the variable has been instantiated and its callee
481 lists created. */
482 unsigned analyzed : 1;
483 /* Set once it has been finalized so we consider it to be output. */
484 unsigned finalized : 1;
485 /* Set when variable is scheduled to be assembled. */
486 unsigned output : 1;
487 /* Set when function is visible by other units. */
488 unsigned externally_visible : 1;
489 /* Set for aliases once they got through assemble_alias. Also set for
490 extra name aliases in varpool_extra_name_alias. */
491 unsigned alias : 1;
492 /* Set when variable is used from other LTRANS partition. */
493 unsigned used_from_other_partition : 1;
494 /* Set when variable is available in the other LTRANS partition.
495 During WPA output it is used to mark nodes that are present in
496 multiple partitions. */
497 unsigned in_other_partition : 1;
500 /* Every top level asm statement is put into a cgraph_asm_node. */
502 struct GTY(()) cgraph_asm_node {
503 /* Next asm node. */
504 struct cgraph_asm_node *next;
505 /* String for this asm node. */
506 tree asm_str;
507 /* Ordering of all cgraph nodes. */
508 int order;
511 extern GTY(()) struct cgraph_node *cgraph_nodes;
512 extern GTY(()) int cgraph_n_nodes;
513 extern GTY(()) int cgraph_max_uid;
514 extern GTY(()) int cgraph_edge_max_uid;
515 extern GTY(()) int cgraph_max_pid;
516 extern bool cgraph_global_info_ready;
517 enum cgraph_state
519 /* Callgraph is being constructed. It is safe to add new functions. */
520 CGRAPH_STATE_CONSTRUCTION,
521 /* Callgraph is built and IPA passes are being run. */
522 CGRAPH_STATE_IPA,
523 /* Callgraph is built and all functions are transformed to SSA form. */
524 CGRAPH_STATE_IPA_SSA,
525 /* Functions are now ordered and being passed to RTL expanders. */
526 CGRAPH_STATE_EXPANSION,
527 /* All cgraph expansion is done. */
528 CGRAPH_STATE_FINISHED
530 extern enum cgraph_state cgraph_state;
531 extern bool cgraph_function_flags_ready;
532 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
533 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
535 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
536 extern GTY(()) int cgraph_order;
538 /* In cgraph.c */
539 void dump_cgraph (FILE *);
540 void debug_cgraph (void);
541 void dump_cgraph_node (FILE *, struct cgraph_node *);
542 void debug_cgraph_node (struct cgraph_node *);
543 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
544 void cgraph_remove_edge (struct cgraph_edge *);
545 void cgraph_remove_node (struct cgraph_node *);
546 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
547 void cgraph_release_function_body (struct cgraph_node *);
548 void cgraph_node_remove_callees (struct cgraph_node *node);
549 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
550 struct cgraph_node *,
551 gimple, gcov_type, int, int);
552 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple, int,
553 gcov_type, int, int);
554 struct cgraph_node * cgraph_get_node (const_tree);
555 struct cgraph_node * cgraph_get_node_or_alias (const_tree);
556 struct cgraph_node * cgraph_node (tree);
557 struct cgraph_node * cgraph_same_body_alias (tree, tree);
558 struct cgraph_node * cgraph_add_thunk (tree, tree, bool, HOST_WIDE_INT,
559 HOST_WIDE_INT, tree, tree);
560 void cgraph_remove_same_body_alias (struct cgraph_node *);
561 struct cgraph_node *cgraph_node_for_asm (tree);
562 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
563 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
564 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
565 void cgraph_create_edge_including_clones (struct cgraph_node *,
566 struct cgraph_node *,
567 gimple, gimple, gcov_type, int, int,
568 cgraph_inline_failed_t);
569 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
570 struct cgraph_local_info *cgraph_local_info (tree);
571 struct cgraph_global_info *cgraph_global_info (tree);
572 struct cgraph_rtl_info *cgraph_rtl_info (tree);
573 const char * cgraph_node_name (struct cgraph_node *);
574 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
575 struct cgraph_node *, gimple,
576 unsigned, gcov_type, int, int, bool);
577 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type, int,
578 int, bool, VEC(cgraph_edge_p,heap) *);
580 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
581 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *, tree);
583 struct cgraph_asm_node *cgraph_add_asm_node (tree);
585 bool cgraph_function_possibly_inlined_p (tree);
586 void cgraph_unnest_node (struct cgraph_node *);
588 enum availability cgraph_function_body_availability (struct cgraph_node *);
589 void cgraph_add_new_function (tree, bool);
590 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
591 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
592 VEC(cgraph_edge_p,heap)*,
593 VEC(ipa_replace_map_p,gc)* tree_map,
594 bitmap args_to_skip,
595 const char *clone_name);
597 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
598 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
599 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
600 tree clone_function_name (tree decl, const char *);
601 bool cgraph_node_cannot_return (struct cgraph_node *);
602 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
603 bool cgraph_will_be_removed_from_program_if_no_direct_calls
604 (struct cgraph_node *node);
605 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
606 (struct cgraph_node *node);
607 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution);
608 bool cgraph_used_from_object_file_p (struct cgraph_node *node);
609 bool varpool_used_from_object_file_p (struct varpool_node *node);
611 /* In cgraphunit.c */
612 extern FILE *cgraph_dump_file;
613 void cgraph_finalize_function (tree, bool);
614 void cgraph_mark_if_needed (tree);
615 void cgraph_finalize_compilation_unit (void);
616 void cgraph_optimize (void);
617 void cgraph_mark_needed_node (struct cgraph_node *);
618 void cgraph_mark_address_taken_node (struct cgraph_node *);
619 void cgraph_mark_reachable_node (struct cgraph_node *);
620 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
621 bool cgraph_preserve_function_body_p (tree);
622 void verify_cgraph (void);
623 void verify_cgraph_node (struct cgraph_node *);
624 void cgraph_build_static_cdtor (char which, tree body, int priority);
625 void cgraph_reset_static_var_maps (void);
626 void init_cgraph (void);
627 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
628 VEC(cgraph_edge_p,heap)*,
629 VEC(ipa_replace_map_p,gc)*,
630 bitmap, bitmap, basic_block,
631 const char *);
632 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
633 bitmap, basic_block);
634 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
635 void record_references_in_initializer (tree, bool);
636 bool cgraph_process_new_functions (void);
638 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
640 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
641 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
642 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
643 void *);
644 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
645 void *);
646 struct cgraph_edge_hook_list;
647 struct cgraph_node_hook_list;
648 struct cgraph_2edge_hook_list;
649 struct cgraph_2node_hook_list;
650 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
651 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
652 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
653 void *);
654 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
655 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
656 void *);
657 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
658 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
659 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
660 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
661 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
662 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
663 void cgraph_materialize_all_clones (void);
664 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
665 bool cgraph_propagate_frequency (struct cgraph_node *node);
666 /* In cgraphbuild.c */
667 unsigned int rebuild_cgraph_edges (void);
668 void cgraph_rebuild_references (void);
669 void reset_inline_failed (struct cgraph_node *);
670 int compute_call_stmt_bb_frequency (tree, basic_block bb);
672 /* In ipa.c */
673 bool cgraph_remove_unreachable_nodes (bool, FILE *);
674 int cgraph_postorder (struct cgraph_node **);
675 cgraph_node_set cgraph_node_set_new (void);
676 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
677 struct cgraph_node *);
678 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
679 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
680 void dump_cgraph_node_set (FILE *, cgraph_node_set);
681 void debug_cgraph_node_set (cgraph_node_set);
683 varpool_node_set varpool_node_set_new (void);
684 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
685 struct varpool_node *);
686 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
687 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
688 void dump_varpool_node_set (FILE *, varpool_node_set);
689 void debug_varpool_node_set (varpool_node_set);
690 void ipa_discover_readonly_nonaddressable_vars (void);
691 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
693 /* In predict.c */
694 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
696 /* In varpool.c */
697 extern GTY(()) struct varpool_node *varpool_nodes_queue;
698 extern GTY(()) struct varpool_node *varpool_nodes;
700 struct varpool_node *varpool_node (tree);
701 struct varpool_node *varpool_node_for_asm (tree asmname);
702 void varpool_mark_needed_node (struct varpool_node *);
703 void debug_varpool (void);
704 void dump_varpool (FILE *);
705 void dump_varpool_node (FILE *, struct varpool_node *);
707 void varpool_finalize_decl (tree);
708 bool decide_is_variable_needed (struct varpool_node *, tree);
709 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
710 void cgraph_make_decl_local (tree);
711 void cgraph_make_node_local (struct cgraph_node *);
712 bool cgraph_node_can_be_local_p (struct cgraph_node *);
715 struct varpool_node * varpool_get_node (const_tree decl);
716 void varpool_remove_node (struct varpool_node *node);
717 bool varpool_assemble_pending_decls (void);
718 bool varpool_assemble_decl (struct varpool_node *node);
719 bool varpool_analyze_pending_decls (void);
720 void varpool_remove_unreferenced_decls (void);
721 void varpool_empty_needed_queue (void);
722 struct varpool_node * varpool_extra_name_alias (tree, tree);
723 const char * varpool_node_name (struct varpool_node *node);
724 void varpool_reset_queue (void);
725 bool const_value_known_p (tree);
727 /* Walk all reachable static variables. */
728 #define FOR_EACH_STATIC_VARIABLE(node) \
729 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
731 /* Return first reachable static variable with initializer. */
732 static inline struct varpool_node *
733 varpool_first_static_initializer (void)
735 struct varpool_node *node;
736 for (node = varpool_nodes_queue; node; node = node->next_needed)
738 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
739 if (DECL_INITIAL (node->decl))
740 return node;
742 return NULL;
745 /* Return next reachable static variable with initializer after NODE. */
746 static inline struct varpool_node *
747 varpool_next_static_initializer (struct varpool_node *node)
749 for (node = node->next_needed; node; node = node->next_needed)
751 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
752 if (DECL_INITIAL (node->decl))
753 return node;
755 return NULL;
758 /* Walk all static variables with initializer set. */
759 #define FOR_EACH_STATIC_INITIALIZER(node) \
760 for ((node) = varpool_first_static_initializer (); (node); \
761 (node) = varpool_next_static_initializer (node))
763 /* In ipa-inline.c */
764 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
765 unsigned int compute_inline_parameters (struct cgraph_node *);
768 /* Create a new static variable of type TYPE. */
769 tree add_new_static_var (tree type);
771 /* Return true if iterator CSI points to nothing. */
772 static inline bool
773 csi_end_p (cgraph_node_set_iterator csi)
775 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
778 /* Advance iterator CSI. */
779 static inline void
780 csi_next (cgraph_node_set_iterator *csi)
782 csi->index++;
785 /* Return the node pointed to by CSI. */
786 static inline struct cgraph_node *
787 csi_node (cgraph_node_set_iterator csi)
789 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
792 /* Return an iterator to the first node in SET. */
793 static inline cgraph_node_set_iterator
794 csi_start (cgraph_node_set set)
796 cgraph_node_set_iterator csi;
798 csi.set = set;
799 csi.index = 0;
800 return csi;
803 /* Return true if SET contains NODE. */
804 static inline bool
805 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
807 cgraph_node_set_iterator csi;
808 csi = cgraph_node_set_find (set, node);
809 return !csi_end_p (csi);
812 /* Return number of nodes in SET. */
813 static inline size_t
814 cgraph_node_set_size (cgraph_node_set set)
816 return htab_elements (set->hashtab);
819 /* Return true if iterator VSI points to nothing. */
820 static inline bool
821 vsi_end_p (varpool_node_set_iterator vsi)
823 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
826 /* Advance iterator VSI. */
827 static inline void
828 vsi_next (varpool_node_set_iterator *vsi)
830 vsi->index++;
833 /* Return the node pointed to by VSI. */
834 static inline struct varpool_node *
835 vsi_node (varpool_node_set_iterator vsi)
837 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
840 /* Return an iterator to the first node in SET. */
841 static inline varpool_node_set_iterator
842 vsi_start (varpool_node_set set)
844 varpool_node_set_iterator vsi;
846 vsi.set = set;
847 vsi.index = 0;
848 return vsi;
851 /* Return true if SET contains NODE. */
852 static inline bool
853 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
855 varpool_node_set_iterator vsi;
856 vsi = varpool_node_set_find (set, node);
857 return !vsi_end_p (vsi);
860 /* Return number of nodes in SET. */
861 static inline size_t
862 varpool_node_set_size (varpool_node_set set)
864 return htab_elements (set->hashtab);
867 /* Uniquize all constants that appear in memory.
868 Each constant in memory thus far output is recorded
869 in `const_desc_table'. */
871 struct GTY(()) constant_descriptor_tree {
872 /* A MEM for the constant. */
873 rtx rtl;
875 /* The value of the constant. */
876 tree value;
878 /* Hash of value. Computing the hash from value each time
879 hashfn is called can't work properly, as that means recursive
880 use of the hash table during hash table expansion. */
881 hashval_t hash;
884 /* Return true if set is nonempty. */
885 static inline bool
886 cgraph_node_set_nonempty_p (cgraph_node_set set)
888 return !VEC_empty (cgraph_node_ptr, set->nodes);
891 /* Return true if set is nonempty. */
892 static inline bool
893 varpool_node_set_nonempty_p (varpool_node_set set)
895 return !VEC_empty (varpool_node_ptr, set->nodes);
898 /* Return true when function NODE is only called directly.
899 i.e. it is not externally visible, address was not taken and
900 it is not used in any other non-standard way. */
902 static inline bool
903 cgraph_only_called_directly_p (struct cgraph_node *node)
905 gcc_assert (!node->global.inlined_to);
906 return (!node->needed && !node->address_taken
907 && !node->reachable_from_other_partition
908 && !DECL_STATIC_CONSTRUCTOR (node->decl)
909 && !DECL_STATIC_DESTRUCTOR (node->decl)
910 && !node->local.externally_visible);
913 /* Return true when function NODE can be removed from callgraph
914 if all direct calls are eliminated. */
916 static inline bool
917 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
919 /* Extern inlines can always go, we will use the external definition. */
920 if (DECL_EXTERNAL (node->decl))
921 return true;
922 return !node->address_taken && cgraph_can_remove_if_no_direct_calls_and_refs_p (node);
925 /* Return true when function NODE can be removed from callgraph
926 if all direct calls are eliminated. */
928 static inline bool
929 varpool_can_remove_if_no_refs (struct varpool_node *node)
931 return (!node->force_output && !node->used_from_other_partition
932 && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
933 || DECL_ARTIFICIAL (node->decl))
934 && (DECL_COMDAT (node->decl) || !node->externally_visible));
937 /* Return true when all references to VNODE must be visible in ipa_ref_list.
938 i.e. if the variable is not externally visible or not used in some magic
939 way (asm statement or such).
940 The magic uses are all sumarized in force_output flag. */
942 static inline bool
943 varpool_all_refs_explicit_p (struct varpool_node *vnode)
945 return (!vnode->externally_visible
946 && !vnode->used_from_other_partition
947 && !vnode->force_output);
950 /* Constant pool accessor function. */
951 htab_t constant_pool_htab (void);
953 /* FIXME: inappropriate dependency of cgraph on IPA. */
954 #include "ipa-ref-inline.h"
956 #endif /* GCC_CGRAPH_H */