2011-04-04 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / cgraph.h
blobe774c00eb3850157de3629399e543dfc45773667
1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
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 /* False when function calling convention and signature can not be changed.
118 This is the case when __builtin_apply_args is used. */
119 unsigned can_change_signature : 1;
121 /* True when function should be inlined independently on its size. */
122 unsigned disregard_inline_limits : 1;
124 /* True when the function has been originally extern inline, but it is
125 redefined now. */
126 unsigned redefined_extern_inline : 1;
128 /* True if the function is going to be emitted in some other translation
129 unit, referenced from vtable. */
130 unsigned vtable_method : 1;
133 /* Information about the function that needs to be computed globally
134 once compilation is finished. Available only with -funit-at-a-time. */
136 struct GTY(()) cgraph_global_info {
137 /* Estimated stack frame consumption by the function. */
138 HOST_WIDE_INT estimated_stack_size;
139 /* Expected offset of the stack frame of inlined function. */
140 HOST_WIDE_INT stack_frame_offset;
142 /* For inline clones this points to the function they will be
143 inlined into. */
144 struct cgraph_node *inlined_to;
146 /* Estimated size of the function after inlining. */
147 int time;
148 int size;
150 /* Estimated growth after inlining. INT_MIN if not computed. */
151 int estimated_growth;
154 /* Information about the function that is propagated by the RTL backend.
155 Available only for functions that has been already assembled. */
157 struct GTY(()) cgraph_rtl_info {
158 unsigned int preferred_incoming_stack_boundary;
161 /* Represent which DECL tree (or reference to such tree)
162 will be replaced by another tree while versioning. */
163 struct GTY(()) ipa_replace_map
165 /* The tree that will be replaced. */
166 tree old_tree;
167 /* The new (replacing) tree. */
168 tree new_tree;
169 /* Parameter number to replace, when old_tree is NULL. */
170 int parm_num;
171 /* True when a substitution should be done, false otherwise. */
172 bool replace_p;
173 /* True when we replace a reference to old_tree. */
174 bool ref_p;
176 typedef struct ipa_replace_map *ipa_replace_map_p;
177 DEF_VEC_P(ipa_replace_map_p);
178 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
180 struct GTY(()) cgraph_clone_info
182 VEC(ipa_replace_map_p,gc)* tree_map;
183 bitmap args_to_skip;
184 bitmap combined_args_to_skip;
188 /* The cgraph data structure.
189 Each function decl has assigned cgraph_node listing callees and callers. */
191 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
192 tree decl;
193 struct cgraph_edge *callees;
194 struct cgraph_edge *callers;
195 struct cgraph_node *next;
196 struct cgraph_node *previous;
197 /* List of edges representing indirect calls with a yet undetermined
198 callee. */
199 struct cgraph_edge *indirect_calls;
200 /* For nested functions points to function the node is nested in. */
201 struct cgraph_node *origin;
202 /* Points to first nested function, if any. */
203 struct cgraph_node *nested;
204 /* Pointer to the next function with same origin, if any. */
205 struct cgraph_node *next_nested;
206 /* Pointer to the next function in cgraph_nodes_queue. */
207 struct cgraph_node *next_needed;
208 /* Pointer to the next clone. */
209 struct cgraph_node *next_sibling_clone;
210 struct cgraph_node *prev_sibling_clone;
211 struct cgraph_node *clones;
212 struct cgraph_node *clone_of;
213 /* For normal nodes pointer to the list of alias and thunk nodes,
214 in alias/thunk nodes pointer to the normal node. */
215 struct cgraph_node *same_body;
216 /* Circular list of nodes in the same comdat group if non-NULL. */
217 struct cgraph_node *same_comdat_group;
218 /* For functions with many calls sites it holds map from call expression
219 to the edge to speed up cgraph_edge function. */
220 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
221 /* Declaration node used to be clone of. */
222 tree former_clone_of;
224 PTR GTY ((skip)) aux;
226 /* Interprocedural passes scheduled to have their transform functions
227 applied next time we execute local pass on them. We maintain it
228 per-function in order to allow IPA passes to introduce new functions. */
229 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
231 struct ipa_ref_list ref_list;
232 struct cgraph_local_info local;
233 struct cgraph_global_info global;
234 struct cgraph_rtl_info rtl;
235 struct cgraph_clone_info clone;
236 struct cgraph_thunk_info thunk;
238 /* Expected number of executions: calculated in profile.c. */
239 gcov_type count;
240 /* How to scale counts at materialization time; used to merge
241 LTO units with different number of profile runs. */
242 int count_materialization_scale;
243 /* Unique id of the node. */
244 int uid;
245 /* Ordering of all cgraph nodes. */
246 int order;
248 /* unique id for profiling. pid is not suitable because of different
249 number of cfg nodes with -fprofile-generate and -fprofile-use */
250 int pid;
251 enum ld_plugin_symbol_resolution resolution;
253 /* Set when function must be output for some reason. The primary
254 use of this flag is to mark functions needed to be output for
255 non-standard reason. Functions that are externally visible
256 or reachable from functions needed to be output are marked
257 by specialized flags. */
258 unsigned needed : 1;
259 /* Set when function has address taken.
260 In current implementation it imply needed flag. */
261 unsigned address_taken : 1;
262 /* Set when decl is an abstract function pointed to by the
263 ABSTRACT_DECL_ORIGIN of a reachable function. */
264 unsigned abstract_and_needed : 1;
265 /* Set when function is reachable by call from other function
266 that is either reachable or needed.
267 This flag is computed at original cgraph construction and then
268 updated in cgraph_remove_unreachable_nodes. Note that after
269 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
270 nodes when they are needed for virtual clone instantiation. */
271 unsigned reachable : 1;
272 /* Set when function is reachable by call from other LTRANS partition. */
273 unsigned reachable_from_other_partition : 1;
274 /* Set once the function is lowered (i.e. its CFG is built). */
275 unsigned lowered : 1;
276 /* Set once the function has been instantiated and its callee
277 lists created. */
278 unsigned analyzed : 1;
279 /* Set when function is available in the other LTRANS partition.
280 During WPA output it is used to mark nodes that are present in
281 multiple partitions. */
282 unsigned in_other_partition : 1;
283 /* Set when function is scheduled to be processed by local passes. */
284 unsigned process : 1;
285 /* Set for aliases once they got through assemble_alias. */
286 unsigned alias : 1;
287 /* Set for nodes that was constructed and finalized by frontend. */
288 unsigned finalized_by_frontend : 1;
289 /* Set for alias and thunk nodes, same_body points to the node they are alias
290 of and they are linked through the next/previous pointers. */
291 unsigned same_body_alias : 1;
292 /* How commonly executed the node is. Initialized during branch
293 probabilities pass. */
294 ENUM_BITFIELD (node_frequency) frequency : 2;
295 /* True when function can only be called at startup (from static ctor). */
296 unsigned only_called_at_startup : 1;
297 /* True when function can only be called at startup (from static dtor). */
298 unsigned only_called_at_exit : 1;
301 typedef struct cgraph_node *cgraph_node_ptr;
303 DEF_VEC_P(cgraph_node_ptr);
304 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
305 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
307 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
308 can appear in multiple sets. */
309 struct GTY(()) cgraph_node_set_def
311 htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
312 VEC(cgraph_node_ptr, gc) *nodes;
315 typedef struct varpool_node *varpool_node_ptr;
317 DEF_VEC_P(varpool_node_ptr);
318 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
319 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
321 /* A varpool node set is a collection of varpool nodes. A varpool node
322 can appear in multiple sets. */
323 struct GTY(()) varpool_node_set_def
325 htab_t GTY((param_is (struct varpool_node_set_element_def))) hashtab;
326 VEC(varpool_node_ptr, gc) *nodes;
329 typedef struct cgraph_node_set_def *cgraph_node_set;
331 DEF_VEC_P(cgraph_node_set);
332 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
333 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
335 typedef struct varpool_node_set_def *varpool_node_set;
337 DEF_VEC_P(varpool_node_set);
338 DEF_VEC_ALLOC_P(varpool_node_set,gc);
339 DEF_VEC_ALLOC_P(varpool_node_set,heap);
341 /* A cgraph node set element contains an index in the vector of nodes in
342 the set. */
343 struct GTY(()) cgraph_node_set_element_def
345 struct cgraph_node *node;
346 HOST_WIDE_INT index;
349 typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
350 typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
352 /* Iterator structure for cgraph node sets. */
353 typedef struct
355 cgraph_node_set set;
356 unsigned index;
357 } cgraph_node_set_iterator;
359 /* A varpool node set element contains an index in the vector of nodes in
360 the set. */
361 struct GTY(()) varpool_node_set_element_def
363 struct varpool_node *node;
364 HOST_WIDE_INT index;
367 typedef struct varpool_node_set_element_def *varpool_node_set_element;
368 typedef const struct varpool_node_set_element_def *const_varpool_node_set_element;
370 /* Iterator structure for varpool node sets. */
371 typedef struct
373 varpool_node_set set;
374 unsigned index;
375 } varpool_node_set_iterator;
377 #define DEFCIFCODE(code, string) CIF_ ## code,
378 /* Reasons for inlining failures. */
379 typedef enum {
380 #include "cif-code.def"
381 CIF_N_REASONS
382 } cgraph_inline_failed_t;
384 /* Structure containing additional information about an indirect call. */
386 struct GTY(()) cgraph_indirect_call_info
388 /* Offset accumulated from ancestor jump functions of inlined call graph
389 edges. */
390 HOST_WIDE_INT anc_offset;
391 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
392 HOST_WIDE_INT otr_token;
393 /* Delta by which must be added to this parameter to compensate for a skipped
394 this adjusting thunk. */
395 HOST_WIDE_INT thunk_delta;
396 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
397 tree otr_type;
398 /* Index of the parameter that is called. */
399 int param_index;
400 /* ECF flags determined from the caller. */
401 int ecf_flags;
403 /* Set when the call is a virtual call with the parameter being the
404 associated object pointer rather than a simple direct call. */
405 unsigned polymorphic : 1;
408 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
409 /* Expected number of executions: calculated in profile.c. */
410 gcov_type count;
411 struct cgraph_node *caller;
412 struct cgraph_node *callee;
413 struct cgraph_edge *prev_caller;
414 struct cgraph_edge *next_caller;
415 struct cgraph_edge *prev_callee;
416 struct cgraph_edge *next_callee;
417 gimple call_stmt;
418 /* Additional information about an indirect call. Not cleared when an edge
419 becomes direct. */
420 struct cgraph_indirect_call_info *indirect_info;
421 PTR GTY ((skip (""))) aux;
422 /* When equal to CIF_OK, inline this call. Otherwise, points to the
423 explanation why function was not inlined. */
424 cgraph_inline_failed_t inline_failed;
425 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
426 when the function is serialized in. */
427 unsigned int lto_stmt_uid;
428 /* Expected frequency of executions within the function.
429 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
430 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
431 int frequency;
432 /* Unique id of the edge. */
433 int uid;
434 /* Depth of loop nest, 1 means no loop nest. */
435 unsigned short int loop_nest;
436 /* Whether this edge was made direct by indirect inlining. */
437 unsigned int indirect_inlining_edge : 1;
438 /* Whether this edge describes an indirect call with an undetermined
439 callee. */
440 unsigned int indirect_unknown_callee : 1;
441 /* Whether this edge is still a dangling */
442 /* True if the corresponding CALL stmt cannot be inlined. */
443 unsigned int call_stmt_cannot_inline_p : 1;
444 /* Can this call throw externally? */
445 unsigned int can_throw_external : 1;
448 #define CGRAPH_FREQ_BASE 1000
449 #define CGRAPH_FREQ_MAX 100000
451 typedef struct cgraph_edge *cgraph_edge_p;
453 DEF_VEC_P(cgraph_edge_p);
454 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
456 /* The varpool data structure.
457 Each static variable decl has assigned varpool_node. */
459 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
460 tree decl;
461 /* Pointer to the next function in varpool_nodes. */
462 struct varpool_node *next, *prev;
463 /* Pointer to the next function in varpool_nodes_queue. */
464 struct varpool_node *next_needed, *prev_needed;
465 /* For normal nodes a pointer to the first extra name alias. For alias
466 nodes a pointer to the normal node. */
467 struct varpool_node *extra_name;
468 /* Circular list of nodes in the same comdat group if non-NULL. */
469 struct varpool_node *same_comdat_group;
470 struct ipa_ref_list ref_list;
471 /* File stream where this node is being written to. */
472 struct lto_file_decl_data * lto_file_data;
473 PTR GTY ((skip)) aux;
474 /* Ordering of all cgraph nodes. */
475 int order;
476 enum ld_plugin_symbol_resolution resolution;
478 /* Set when function must be output - it is externally visible
479 or its address is taken. */
480 unsigned needed : 1;
481 /* Needed variables might become dead by optimization. This flag
482 forces the variable to be output even if it appears dead otherwise. */
483 unsigned force_output : 1;
484 /* Set once the variable has been instantiated and its callee
485 lists created. */
486 unsigned analyzed : 1;
487 /* Set once it has been finalized so we consider it to be output. */
488 unsigned finalized : 1;
489 /* Set when variable is scheduled to be assembled. */
490 unsigned output : 1;
491 /* Set when function is visible by other units. */
492 unsigned externally_visible : 1;
493 /* Set for aliases once they got through assemble_alias. Also set for
494 extra name aliases in varpool_extra_name_alias. */
495 unsigned alias : 1;
496 /* Set when variable is used from other LTRANS partition. */
497 unsigned used_from_other_partition : 1;
498 /* Set when variable is available in the other LTRANS partition.
499 During WPA output it is used to mark nodes that are present in
500 multiple partitions. */
501 unsigned in_other_partition : 1;
504 /* Every top level asm statement is put into a cgraph_asm_node. */
506 struct GTY(()) cgraph_asm_node {
507 /* Next asm node. */
508 struct cgraph_asm_node *next;
509 /* String for this asm node. */
510 tree asm_str;
511 /* Ordering of all cgraph nodes. */
512 int order;
515 extern GTY(()) struct cgraph_node *cgraph_nodes;
516 extern GTY(()) int cgraph_n_nodes;
517 extern GTY(()) int cgraph_max_uid;
518 extern GTY(()) int cgraph_edge_max_uid;
519 extern GTY(()) int cgraph_max_pid;
520 extern bool cgraph_global_info_ready;
521 enum cgraph_state
523 /* Callgraph is being constructed. It is safe to add new functions. */
524 CGRAPH_STATE_CONSTRUCTION,
525 /* Callgraph is built and IPA passes are being run. */
526 CGRAPH_STATE_IPA,
527 /* Callgraph is built and all functions are transformed to SSA form. */
528 CGRAPH_STATE_IPA_SSA,
529 /* Functions are now ordered and being passed to RTL expanders. */
530 CGRAPH_STATE_EXPANSION,
531 /* All cgraph expansion is done. */
532 CGRAPH_STATE_FINISHED
534 extern enum cgraph_state cgraph_state;
535 extern bool cgraph_function_flags_ready;
536 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
537 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
539 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
540 extern GTY(()) int cgraph_order;
542 /* In cgraph.c */
543 void dump_cgraph (FILE *);
544 void debug_cgraph (void);
545 void dump_cgraph_node (FILE *, struct cgraph_node *);
546 void debug_cgraph_node (struct cgraph_node *);
547 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
548 void cgraph_remove_edge (struct cgraph_edge *);
549 void cgraph_remove_node (struct cgraph_node *);
550 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
551 void cgraph_release_function_body (struct cgraph_node *);
552 void cgraph_node_remove_callees (struct cgraph_node *node);
553 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
554 struct cgraph_node *,
555 gimple, gcov_type, int, int);
556 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
557 int, gcov_type, int, int);
558 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
559 struct cgraph_node * cgraph_get_node (const_tree);
560 struct cgraph_node * cgraph_get_node_or_alias (const_tree);
561 struct cgraph_node * cgraph_node (tree);
562 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
563 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
564 HOST_WIDE_INT, tree, tree);
565 void cgraph_remove_same_body_alias (struct cgraph_node *);
566 struct cgraph_node *cgraph_node_for_asm (tree);
567 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
568 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
569 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
570 void cgraph_create_edge_including_clones (struct cgraph_node *,
571 struct cgraph_node *,
572 gimple, gimple, gcov_type, int, int,
573 cgraph_inline_failed_t);
574 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
575 struct cgraph_local_info *cgraph_local_info (tree);
576 struct cgraph_global_info *cgraph_global_info (tree);
577 struct cgraph_rtl_info *cgraph_rtl_info (tree);
578 const char * cgraph_node_name (struct cgraph_node *);
579 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
580 struct cgraph_node *, gimple,
581 unsigned, gcov_type, int, int, bool);
582 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type, int,
583 int, bool, VEC(cgraph_edge_p,heap) *);
585 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
586 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *,
587 HOST_WIDE_INT);
589 struct cgraph_asm_node *cgraph_add_asm_node (tree);
591 bool cgraph_function_possibly_inlined_p (tree);
592 void cgraph_unnest_node (struct cgraph_node *);
594 enum availability cgraph_function_body_availability (struct cgraph_node *);
595 void cgraph_add_new_function (tree, bool);
596 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
597 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
598 VEC(cgraph_edge_p,heap)*,
599 VEC(ipa_replace_map_p,gc)* tree_map,
600 bitmap args_to_skip,
601 const char *clone_name);
603 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
604 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
605 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
606 tree clone_function_name (tree decl, const char *);
607 bool cgraph_node_cannot_return (struct cgraph_node *);
608 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
609 bool cgraph_will_be_removed_from_program_if_no_direct_calls
610 (struct cgraph_node *node);
611 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
612 (struct cgraph_node *node);
613 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution);
614 bool cgraph_used_from_object_file_p (struct cgraph_node *node);
615 bool varpool_used_from_object_file_p (struct varpool_node *node);
617 /* In cgraphunit.c */
618 extern FILE *cgraph_dump_file;
619 void cgraph_finalize_function (tree, bool);
620 void cgraph_mark_if_needed (tree);
621 void cgraph_analyze_function (struct cgraph_node *);
622 void cgraph_finalize_compilation_unit (void);
623 void cgraph_optimize (void);
624 void cgraph_mark_needed_node (struct cgraph_node *);
625 void cgraph_mark_address_taken_node (struct cgraph_node *);
626 void cgraph_mark_reachable_node (struct cgraph_node *);
627 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
628 bool cgraph_preserve_function_body_p (tree);
629 void verify_cgraph (void);
630 void verify_cgraph_node (struct cgraph_node *);
631 void cgraph_build_static_cdtor (char which, tree body, int priority);
632 void cgraph_reset_static_var_maps (void);
633 void init_cgraph (void);
634 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
635 VEC(cgraph_edge_p,heap)*,
636 VEC(ipa_replace_map_p,gc)*,
637 bitmap, bitmap, basic_block,
638 const char *);
639 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
640 bitmap, basic_block);
641 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
642 void record_references_in_initializer (tree, bool);
643 bool cgraph_process_new_functions (void);
645 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
647 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
648 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
649 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
650 void *);
651 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
652 void *);
653 struct cgraph_edge_hook_list;
654 struct cgraph_node_hook_list;
655 struct cgraph_2edge_hook_list;
656 struct cgraph_2node_hook_list;
657 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
658 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
659 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
660 void *);
661 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
662 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
663 void *);
664 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
665 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
666 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
667 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
668 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
669 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
670 void cgraph_materialize_all_clones (void);
671 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
672 bool cgraph_propagate_frequency (struct cgraph_node *node);
673 /* In cgraphbuild.c */
674 unsigned int rebuild_cgraph_edges (void);
675 void cgraph_rebuild_references (void);
676 void reset_inline_failed (struct cgraph_node *);
677 int compute_call_stmt_bb_frequency (tree, basic_block bb);
679 /* In ipa.c */
680 bool cgraph_remove_unreachable_nodes (bool, FILE *);
681 int cgraph_postorder (struct cgraph_node **);
682 cgraph_node_set cgraph_node_set_new (void);
683 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
684 struct cgraph_node *);
685 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
686 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
687 void dump_cgraph_node_set (FILE *, cgraph_node_set);
688 void debug_cgraph_node_set (cgraph_node_set);
690 varpool_node_set varpool_node_set_new (void);
691 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
692 struct varpool_node *);
693 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
694 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
695 void dump_varpool_node_set (FILE *, varpool_node_set);
696 void debug_varpool_node_set (varpool_node_set);
697 void ipa_discover_readonly_nonaddressable_vars (void);
698 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
700 /* In predict.c */
701 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
703 /* In varpool.c */
704 extern GTY(()) struct varpool_node *varpool_nodes_queue;
705 extern GTY(()) struct varpool_node *varpool_nodes;
707 struct varpool_node *varpool_node (tree);
708 struct varpool_node *varpool_node_for_asm (tree asmname);
709 void varpool_mark_needed_node (struct varpool_node *);
710 void debug_varpool (void);
711 void dump_varpool (FILE *);
712 void dump_varpool_node (FILE *, struct varpool_node *);
714 void varpool_finalize_decl (tree);
715 bool decide_is_variable_needed (struct varpool_node *, tree);
716 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
717 void cgraph_make_decl_local (tree);
718 void cgraph_make_node_local (struct cgraph_node *);
719 bool cgraph_node_can_be_local_p (struct cgraph_node *);
722 struct varpool_node * varpool_get_node (const_tree decl);
723 void varpool_remove_node (struct varpool_node *node);
724 void varpool_finalize_named_section_flags (struct varpool_node *node);
725 bool varpool_assemble_pending_decls (void);
726 bool varpool_assemble_decl (struct varpool_node *node);
727 bool varpool_analyze_pending_decls (void);
728 void varpool_remove_unreferenced_decls (void);
729 void varpool_empty_needed_queue (void);
730 struct varpool_node * varpool_extra_name_alias (tree, tree);
731 const char * varpool_node_name (struct varpool_node *node);
732 void varpool_reset_queue (void);
733 bool const_value_known_p (tree);
735 /* Walk all reachable static variables. */
736 #define FOR_EACH_STATIC_VARIABLE(node) \
737 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
739 /* Return first reachable static variable with initializer. */
740 static inline struct varpool_node *
741 varpool_first_static_initializer (void)
743 struct varpool_node *node;
744 for (node = varpool_nodes_queue; node; node = node->next_needed)
746 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
747 if (DECL_INITIAL (node->decl))
748 return node;
750 return NULL;
753 /* Return next reachable static variable with initializer after NODE. */
754 static inline struct varpool_node *
755 varpool_next_static_initializer (struct varpool_node *node)
757 for (node = node->next_needed; node; node = node->next_needed)
759 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
760 if (DECL_INITIAL (node->decl))
761 return node;
763 return NULL;
766 /* Walk all static variables with initializer set. */
767 #define FOR_EACH_STATIC_INITIALIZER(node) \
768 for ((node) = varpool_first_static_initializer (); (node); \
769 (node) = varpool_next_static_initializer (node))
771 /* In ipa-inline.c */
772 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
773 void compute_inline_parameters (struct cgraph_node *);
776 /* Create a new static variable of type TYPE. */
777 tree add_new_static_var (tree type);
779 /* Return true if iterator CSI points to nothing. */
780 static inline bool
781 csi_end_p (cgraph_node_set_iterator csi)
783 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
786 /* Advance iterator CSI. */
787 static inline void
788 csi_next (cgraph_node_set_iterator *csi)
790 csi->index++;
793 /* Return the node pointed to by CSI. */
794 static inline struct cgraph_node *
795 csi_node (cgraph_node_set_iterator csi)
797 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
800 /* Return an iterator to the first node in SET. */
801 static inline cgraph_node_set_iterator
802 csi_start (cgraph_node_set set)
804 cgraph_node_set_iterator csi;
806 csi.set = set;
807 csi.index = 0;
808 return csi;
811 /* Return true if SET contains NODE. */
812 static inline bool
813 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
815 cgraph_node_set_iterator csi;
816 csi = cgraph_node_set_find (set, node);
817 return !csi_end_p (csi);
820 /* Return number of nodes in SET. */
821 static inline size_t
822 cgraph_node_set_size (cgraph_node_set set)
824 return htab_elements (set->hashtab);
827 /* Return true if iterator VSI points to nothing. */
828 static inline bool
829 vsi_end_p (varpool_node_set_iterator vsi)
831 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
834 /* Advance iterator VSI. */
835 static inline void
836 vsi_next (varpool_node_set_iterator *vsi)
838 vsi->index++;
841 /* Return the node pointed to by VSI. */
842 static inline struct varpool_node *
843 vsi_node (varpool_node_set_iterator vsi)
845 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
848 /* Return an iterator to the first node in SET. */
849 static inline varpool_node_set_iterator
850 vsi_start (varpool_node_set set)
852 varpool_node_set_iterator vsi;
854 vsi.set = set;
855 vsi.index = 0;
856 return vsi;
859 /* Return true if SET contains NODE. */
860 static inline bool
861 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
863 varpool_node_set_iterator vsi;
864 vsi = varpool_node_set_find (set, node);
865 return !vsi_end_p (vsi);
868 /* Return number of nodes in SET. */
869 static inline size_t
870 varpool_node_set_size (varpool_node_set set)
872 return htab_elements (set->hashtab);
875 /* Uniquize all constants that appear in memory.
876 Each constant in memory thus far output is recorded
877 in `const_desc_table'. */
879 struct GTY(()) constant_descriptor_tree {
880 /* A MEM for the constant. */
881 rtx rtl;
883 /* The value of the constant. */
884 tree value;
886 /* Hash of value. Computing the hash from value each time
887 hashfn is called can't work properly, as that means recursive
888 use of the hash table during hash table expansion. */
889 hashval_t hash;
892 /* Return true if set is nonempty. */
893 static inline bool
894 cgraph_node_set_nonempty_p (cgraph_node_set set)
896 return !VEC_empty (cgraph_node_ptr, set->nodes);
899 /* Return true if set is nonempty. */
900 static inline bool
901 varpool_node_set_nonempty_p (varpool_node_set set)
903 return !VEC_empty (varpool_node_ptr, set->nodes);
906 /* Return true when function NODE is only called directly.
907 i.e. it is not externally visible, address was not taken and
908 it is not used in any other non-standard way. */
910 static inline bool
911 cgraph_only_called_directly_p (struct cgraph_node *node)
913 gcc_assert (!node->global.inlined_to);
914 return (!node->needed && !node->address_taken
915 && !node->reachable_from_other_partition
916 && !DECL_STATIC_CONSTRUCTOR (node->decl)
917 && !DECL_STATIC_DESTRUCTOR (node->decl)
918 && !node->local.externally_visible);
921 /* Return true when function NODE can be removed from callgraph
922 if all direct calls are eliminated. */
924 static inline bool
925 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
927 /* Extern inlines can always go, we will use the external definition. */
928 if (DECL_EXTERNAL (node->decl))
929 return true;
930 return !node->address_taken && cgraph_can_remove_if_no_direct_calls_and_refs_p (node);
933 /* Return true when function NODE can be removed from callgraph
934 if all direct calls are eliminated. */
936 static inline bool
937 varpool_can_remove_if_no_refs (struct varpool_node *node)
939 return (!node->force_output && !node->used_from_other_partition
940 && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
941 || DECL_ARTIFICIAL (node->decl))
942 && (DECL_COMDAT (node->decl) || !node->externally_visible));
945 /* Return true when all references to VNODE must be visible in ipa_ref_list.
946 i.e. if the variable is not externally visible or not used in some magic
947 way (asm statement or such).
948 The magic uses are all summarized in force_output flag. */
950 static inline bool
951 varpool_all_refs_explicit_p (struct varpool_node *vnode)
953 return (!vnode->externally_visible
954 && !vnode->used_from_other_partition
955 && !vnode->force_output);
958 /* Constant pool accessor function. */
959 htab_t constant_pool_htab (void);
961 /* FIXME: inappropriate dependency of cgraph on IPA. */
962 #include "ipa-ref-inline.h"
964 #endif /* GCC_CGRAPH_H */