2011-04-21 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / cgraph.h
blob032c837a228634216278cca7a1c32cd0ed353c50
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 /* Information about thunk, used only for same body aliases. */
63 struct GTY(()) cgraph_thunk_info {
64 /* Information about the thunk. */
65 HOST_WIDE_INT fixed_offset;
66 HOST_WIDE_INT virtual_value;
67 tree alias;
68 bool this_adjusting;
69 bool virtual_offset_p;
70 /* Set to true when alias node is thunk. */
71 bool thunk_p;
74 /* Information about the function collected locally.
75 Available after function is analyzed. */
77 struct GTY(()) cgraph_local_info {
78 /* File stream where this node is being written to. */
79 struct lto_file_decl_data * lto_file_data;
81 /* Set when function function is visible in current compilation unit only
82 and its address is never taken. */
83 unsigned local : 1;
85 /* Set when function is visible by other units. */
86 unsigned externally_visible : 1;
88 /* Set once it has been finalized so we consider it to be output. */
89 unsigned finalized : 1;
91 /* False when function calling convention and signature can not be changed.
92 This is the case when __builtin_apply_args is used. */
93 unsigned can_change_signature : 1;
95 /* True when the function has been originally extern inline, but it is
96 redefined now. */
97 unsigned redefined_extern_inline : 1;
100 /* Information about the function that needs to be computed globally
101 once compilation is finished. Available only with -funit-at-a-time. */
103 struct GTY(()) cgraph_global_info {
104 /* For inline clones this points to the function they will be
105 inlined into. */
106 struct cgraph_node *inlined_to;
109 /* Information about the function that is propagated by the RTL backend.
110 Available only for functions that has been already assembled. */
112 struct GTY(()) cgraph_rtl_info {
113 unsigned int preferred_incoming_stack_boundary;
116 /* Represent which DECL tree (or reference to such tree)
117 will be replaced by another tree while versioning. */
118 struct GTY(()) ipa_replace_map
120 /* The tree that will be replaced. */
121 tree old_tree;
122 /* The new (replacing) tree. */
123 tree new_tree;
124 /* Parameter number to replace, when old_tree is NULL. */
125 int parm_num;
126 /* True when a substitution should be done, false otherwise. */
127 bool replace_p;
128 /* True when we replace a reference to old_tree. */
129 bool ref_p;
131 typedef struct ipa_replace_map *ipa_replace_map_p;
132 DEF_VEC_P(ipa_replace_map_p);
133 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
135 struct GTY(()) cgraph_clone_info
137 VEC(ipa_replace_map_p,gc)* tree_map;
138 bitmap args_to_skip;
139 bitmap combined_args_to_skip;
143 /* The cgraph data structure.
144 Each function decl has assigned cgraph_node listing callees and callers. */
146 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
147 tree decl;
148 struct cgraph_edge *callees;
149 struct cgraph_edge *callers;
150 struct cgraph_node *next;
151 struct cgraph_node *previous;
152 /* List of edges representing indirect calls with a yet undetermined
153 callee. */
154 struct cgraph_edge *indirect_calls;
155 /* For nested functions points to function the node is nested in. */
156 struct cgraph_node *origin;
157 /* Points to first nested function, if any. */
158 struct cgraph_node *nested;
159 /* Pointer to the next function with same origin, if any. */
160 struct cgraph_node *next_nested;
161 /* Pointer to the next function in cgraph_nodes_queue. */
162 struct cgraph_node *next_needed;
163 /* Pointer to the next clone. */
164 struct cgraph_node *next_sibling_clone;
165 struct cgraph_node *prev_sibling_clone;
166 struct cgraph_node *clones;
167 struct cgraph_node *clone_of;
168 /* For normal nodes pointer to the list of alias and thunk nodes,
169 in alias/thunk nodes pointer to the normal node. */
170 struct cgraph_node *same_body;
171 /* Circular list of nodes in the same comdat group if non-NULL. */
172 struct cgraph_node *same_comdat_group;
173 /* For functions with many calls sites it holds map from call expression
174 to the edge to speed up cgraph_edge function. */
175 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
176 /* Declaration node used to be clone of. */
177 tree former_clone_of;
179 PTR GTY ((skip)) aux;
181 /* Interprocedural passes scheduled to have their transform functions
182 applied next time we execute local pass on them. We maintain it
183 per-function in order to allow IPA passes to introduce new functions. */
184 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
186 struct ipa_ref_list ref_list;
187 struct cgraph_local_info local;
188 struct cgraph_global_info global;
189 struct cgraph_rtl_info rtl;
190 struct cgraph_clone_info clone;
191 struct cgraph_thunk_info thunk;
193 /* Expected number of executions: calculated in profile.c. */
194 gcov_type count;
195 /* How to scale counts at materialization time; used to merge
196 LTO units with different number of profile runs. */
197 int count_materialization_scale;
198 /* Unique id of the node. */
199 int uid;
200 /* Ordering of all cgraph nodes. */
201 int order;
203 /* unique id for profiling. pid is not suitable because of different
204 number of cfg nodes with -fprofile-generate and -fprofile-use */
205 int pid;
206 enum ld_plugin_symbol_resolution resolution;
208 /* Set when function must be output for some reason. The primary
209 use of this flag is to mark functions needed to be output for
210 non-standard reason. Functions that are externally visible
211 or reachable from functions needed to be output are marked
212 by specialized flags. */
213 unsigned needed : 1;
214 /* Set when function has address taken.
215 In current implementation it imply needed flag. */
216 unsigned address_taken : 1;
217 /* Set when decl is an abstract function pointed to by the
218 ABSTRACT_DECL_ORIGIN of a reachable function. */
219 unsigned abstract_and_needed : 1;
220 /* Set when function is reachable by call from other function
221 that is either reachable or needed.
222 This flag is computed at original cgraph construction and then
223 updated in cgraph_remove_unreachable_nodes. Note that after
224 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
225 nodes when they are needed for virtual clone instantiation. */
226 unsigned reachable : 1;
227 /* Set when function is reachable by call from other LTRANS partition. */
228 unsigned reachable_from_other_partition : 1;
229 /* Set once the function is lowered (i.e. its CFG is built). */
230 unsigned lowered : 1;
231 /* Set once the function has been instantiated and its callee
232 lists created. */
233 unsigned analyzed : 1;
234 /* Set when function is available in the other LTRANS partition.
235 During WPA output it is used to mark nodes that are present in
236 multiple partitions. */
237 unsigned in_other_partition : 1;
238 /* Set when function is scheduled to be processed by local passes. */
239 unsigned process : 1;
240 /* Set for aliases once they got through assemble_alias. */
241 unsigned alias : 1;
242 /* Set for alias and thunk nodes, same_body points to the node they are alias
243 of and they are linked through the next/previous pointers. */
244 unsigned same_body_alias : 1;
245 /* How commonly executed the node is. Initialized during branch
246 probabilities pass. */
247 ENUM_BITFIELD (node_frequency) frequency : 2;
248 /* True when function can only be called at startup (from static ctor). */
249 unsigned only_called_at_startup : 1;
250 /* True when function can only be called at startup (from static dtor). */
251 unsigned only_called_at_exit : 1;
254 typedef struct cgraph_node *cgraph_node_ptr;
256 DEF_VEC_P(cgraph_node_ptr);
257 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
258 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
260 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
261 can appear in multiple sets. */
262 struct GTY(()) cgraph_node_set_def
264 htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
265 VEC(cgraph_node_ptr, gc) *nodes;
268 typedef struct varpool_node *varpool_node_ptr;
270 DEF_VEC_P(varpool_node_ptr);
271 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
272 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
274 /* A varpool node set is a collection of varpool nodes. A varpool node
275 can appear in multiple sets. */
276 struct GTY(()) varpool_node_set_def
278 htab_t GTY((param_is (struct varpool_node_set_element_def))) hashtab;
279 VEC(varpool_node_ptr, gc) *nodes;
282 typedef struct cgraph_node_set_def *cgraph_node_set;
284 DEF_VEC_P(cgraph_node_set);
285 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
286 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
288 typedef struct varpool_node_set_def *varpool_node_set;
290 DEF_VEC_P(varpool_node_set);
291 DEF_VEC_ALLOC_P(varpool_node_set,gc);
292 DEF_VEC_ALLOC_P(varpool_node_set,heap);
294 /* A cgraph node set element contains an index in the vector of nodes in
295 the set. */
296 struct GTY(()) cgraph_node_set_element_def
298 struct cgraph_node *node;
299 HOST_WIDE_INT index;
302 typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
303 typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
305 /* Iterator structure for cgraph node sets. */
306 typedef struct
308 cgraph_node_set set;
309 unsigned index;
310 } cgraph_node_set_iterator;
312 /* A varpool node set element contains an index in the vector of nodes in
313 the set. */
314 struct GTY(()) varpool_node_set_element_def
316 struct varpool_node *node;
317 HOST_WIDE_INT index;
320 typedef struct varpool_node_set_element_def *varpool_node_set_element;
321 typedef const struct varpool_node_set_element_def *const_varpool_node_set_element;
323 /* Iterator structure for varpool node sets. */
324 typedef struct
326 varpool_node_set set;
327 unsigned index;
328 } varpool_node_set_iterator;
330 #define DEFCIFCODE(code, string) CIF_ ## code,
331 /* Reasons for inlining failures. */
332 typedef enum {
333 #include "cif-code.def"
334 CIF_N_REASONS
335 } cgraph_inline_failed_t;
337 /* Structure containing additional information about an indirect call. */
339 struct GTY(()) cgraph_indirect_call_info
341 /* Offset accumulated from ancestor jump functions of inlined call graph
342 edges. */
343 HOST_WIDE_INT anc_offset;
344 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
345 HOST_WIDE_INT otr_token;
346 /* Delta by which must be added to this parameter to compensate for a skipped
347 this adjusting thunk. */
348 HOST_WIDE_INT thunk_delta;
349 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
350 tree otr_type;
351 /* Index of the parameter that is called. */
352 int param_index;
353 /* ECF flags determined from the caller. */
354 int ecf_flags;
356 /* Set when the call is a virtual call with the parameter being the
357 associated object pointer rather than a simple direct call. */
358 unsigned polymorphic : 1;
361 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
362 /* Expected number of executions: calculated in profile.c. */
363 gcov_type count;
364 struct cgraph_node *caller;
365 struct cgraph_node *callee;
366 struct cgraph_edge *prev_caller;
367 struct cgraph_edge *next_caller;
368 struct cgraph_edge *prev_callee;
369 struct cgraph_edge *next_callee;
370 gimple call_stmt;
371 /* Additional information about an indirect call. Not cleared when an edge
372 becomes direct. */
373 struct cgraph_indirect_call_info *indirect_info;
374 PTR GTY ((skip (""))) aux;
375 /* When equal to CIF_OK, inline this call. Otherwise, points to the
376 explanation why function was not inlined. */
377 cgraph_inline_failed_t inline_failed;
378 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
379 when the function is serialized in. */
380 unsigned int lto_stmt_uid;
381 /* Expected frequency of executions within the function.
382 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
383 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
384 int frequency;
385 /* Unique id of the edge. */
386 int uid;
387 /* Estimated size and time of the call statement. */
388 int call_stmt_size;
389 int call_stmt_time;
390 /* Depth of loop nest, 1 means no loop nest. */
391 unsigned short int loop_nest;
392 /* Whether this edge was made direct by indirect inlining. */
393 unsigned int indirect_inlining_edge : 1;
394 /* Whether this edge describes an indirect call with an undetermined
395 callee. */
396 unsigned int indirect_unknown_callee : 1;
397 /* Whether this edge is still a dangling */
398 /* True if the corresponding CALL stmt cannot be inlined. */
399 unsigned int call_stmt_cannot_inline_p : 1;
400 /* Can this call throw externally? */
401 unsigned int can_throw_external : 1;
404 #define CGRAPH_FREQ_BASE 1000
405 #define CGRAPH_FREQ_MAX 100000
407 typedef struct cgraph_edge *cgraph_edge_p;
409 DEF_VEC_P(cgraph_edge_p);
410 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
412 /* The varpool data structure.
413 Each static variable decl has assigned varpool_node. */
415 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
416 tree decl;
417 /* Pointer to the next function in varpool_nodes. */
418 struct varpool_node *next, *prev;
419 /* Pointer to the next function in varpool_nodes_queue. */
420 struct varpool_node *next_needed, *prev_needed;
421 /* For normal nodes a pointer to the first extra name alias. For alias
422 nodes a pointer to the normal node. */
423 struct varpool_node *extra_name;
424 /* Circular list of nodes in the same comdat group if non-NULL. */
425 struct varpool_node *same_comdat_group;
426 struct ipa_ref_list ref_list;
427 /* File stream where this node is being written to. */
428 struct lto_file_decl_data * lto_file_data;
429 PTR GTY ((skip)) aux;
430 /* Ordering of all cgraph nodes. */
431 int order;
432 enum ld_plugin_symbol_resolution resolution;
434 /* Set when function must be output - it is externally visible
435 or its address is taken. */
436 unsigned needed : 1;
437 /* Needed variables might become dead by optimization. This flag
438 forces the variable to be output even if it appears dead otherwise. */
439 unsigned force_output : 1;
440 /* Set once the variable has been instantiated and its callee
441 lists created. */
442 unsigned analyzed : 1;
443 /* Set once it has been finalized so we consider it to be output. */
444 unsigned finalized : 1;
445 /* Set when variable is scheduled to be assembled. */
446 unsigned output : 1;
447 /* Set when function is visible by other units. */
448 unsigned externally_visible : 1;
449 /* Set for aliases once they got through assemble_alias. Also set for
450 extra name aliases in varpool_extra_name_alias. */
451 unsigned alias : 1;
452 /* Set when variable is used from other LTRANS partition. */
453 unsigned used_from_other_partition : 1;
454 /* Set when variable is available in the other LTRANS partition.
455 During WPA output it is used to mark nodes that are present in
456 multiple partitions. */
457 unsigned in_other_partition : 1;
460 /* Every top level asm statement is put into a cgraph_asm_node. */
462 struct GTY(()) cgraph_asm_node {
463 /* Next asm node. */
464 struct cgraph_asm_node *next;
465 /* String for this asm node. */
466 tree asm_str;
467 /* Ordering of all cgraph nodes. */
468 int order;
471 extern GTY(()) struct cgraph_node *cgraph_nodes;
472 extern GTY(()) int cgraph_n_nodes;
473 extern GTY(()) int cgraph_max_uid;
474 extern GTY(()) int cgraph_edge_max_uid;
475 extern GTY(()) int cgraph_max_pid;
476 extern bool cgraph_global_info_ready;
477 enum cgraph_state
479 /* Callgraph is being constructed. It is safe to add new functions. */
480 CGRAPH_STATE_CONSTRUCTION,
481 /* Callgraph is built and IPA passes are being run. */
482 CGRAPH_STATE_IPA,
483 /* Callgraph is built and all functions are transformed to SSA form. */
484 CGRAPH_STATE_IPA_SSA,
485 /* Functions are now ordered and being passed to RTL expanders. */
486 CGRAPH_STATE_EXPANSION,
487 /* All cgraph expansion is done. */
488 CGRAPH_STATE_FINISHED
490 extern enum cgraph_state cgraph_state;
491 extern bool cgraph_function_flags_ready;
492 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
493 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
495 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
496 extern GTY(()) int cgraph_order;
498 /* In cgraph.c */
499 void dump_cgraph (FILE *);
500 void debug_cgraph (void);
501 void dump_cgraph_node (FILE *, struct cgraph_node *);
502 void debug_cgraph_node (struct cgraph_node *);
503 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
504 void cgraph_remove_edge (struct cgraph_edge *);
505 void cgraph_remove_node (struct cgraph_node *);
506 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
507 void cgraph_release_function_body (struct cgraph_node *);
508 void cgraph_node_remove_callees (struct cgraph_node *node);
509 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
510 struct cgraph_node *,
511 gimple, gcov_type, int, int);
512 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
513 int, gcov_type, int, int);
514 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
515 struct cgraph_node * cgraph_get_node (const_tree);
516 struct cgraph_node * cgraph_get_node_or_alias (const_tree);
517 struct cgraph_node * cgraph_create_node (tree);
518 struct cgraph_node * cgraph_get_create_node (tree);
519 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
520 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
521 HOST_WIDE_INT, tree, tree);
522 void cgraph_remove_same_body_alias (struct cgraph_node *);
523 struct cgraph_node *cgraph_node_for_asm (tree);
524 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
525 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
526 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
527 void cgraph_create_edge_including_clones (struct cgraph_node *,
528 struct cgraph_node *,
529 gimple, gimple, gcov_type, int, int,
530 cgraph_inline_failed_t);
531 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
532 struct cgraph_local_info *cgraph_local_info (tree);
533 struct cgraph_global_info *cgraph_global_info (tree);
534 struct cgraph_rtl_info *cgraph_rtl_info (tree);
535 const char * cgraph_node_name (struct cgraph_node *);
536 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
537 struct cgraph_node *, gimple,
538 unsigned, gcov_type, int, int, bool);
539 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type, int,
540 int, bool, VEC(cgraph_edge_p,heap) *);
542 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
543 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *,
544 HOST_WIDE_INT);
546 struct cgraph_asm_node *cgraph_add_asm_node (tree);
548 bool cgraph_function_possibly_inlined_p (tree);
549 void cgraph_unnest_node (struct cgraph_node *);
551 enum availability cgraph_function_body_availability (struct cgraph_node *);
552 void cgraph_add_new_function (tree, bool);
553 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
554 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
555 VEC(cgraph_edge_p,heap)*,
556 VEC(ipa_replace_map_p,gc)* tree_map,
557 bitmap args_to_skip,
558 const char *clone_name);
560 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
561 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
562 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
563 tree clone_function_name (tree decl, const char *);
564 bool cgraph_node_cannot_return (struct cgraph_node *);
565 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
566 bool cgraph_will_be_removed_from_program_if_no_direct_calls
567 (struct cgraph_node *node);
568 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
569 (struct cgraph_node *node);
570 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution);
571 bool cgraph_used_from_object_file_p (struct cgraph_node *node);
572 bool varpool_used_from_object_file_p (struct varpool_node *node);
574 /* In cgraphunit.c */
575 extern FILE *cgraph_dump_file;
576 void cgraph_finalize_function (tree, bool);
577 void cgraph_mark_if_needed (tree);
578 void cgraph_analyze_function (struct cgraph_node *);
579 void cgraph_finalize_compilation_unit (void);
580 void cgraph_optimize (void);
581 void cgraph_mark_needed_node (struct cgraph_node *);
582 void cgraph_mark_address_taken_node (struct cgraph_node *);
583 void cgraph_mark_reachable_node (struct cgraph_node *);
584 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
585 bool cgraph_preserve_function_body_p (tree);
586 void verify_cgraph (void);
587 void verify_cgraph_node (struct cgraph_node *);
588 void cgraph_build_static_cdtor (char which, tree body, int priority);
589 void cgraph_reset_static_var_maps (void);
590 void init_cgraph (void);
591 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
592 VEC(cgraph_edge_p,heap)*,
593 VEC(ipa_replace_map_p,gc)*,
594 bitmap, bitmap, basic_block,
595 const char *);
596 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
597 bitmap, basic_block);
598 void record_references_in_initializer (tree, bool);
599 bool cgraph_process_new_functions (void);
601 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
603 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
604 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
605 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
606 void *);
607 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
608 void *);
609 struct cgraph_edge_hook_list;
610 struct cgraph_node_hook_list;
611 struct cgraph_2edge_hook_list;
612 struct cgraph_2node_hook_list;
613 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
614 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
615 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
616 void *);
617 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
618 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
619 void *);
620 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
621 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
622 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
623 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
624 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
625 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
626 void cgraph_materialize_all_clones (void);
627 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
628 bool cgraph_propagate_frequency (struct cgraph_node *node);
629 /* In cgraphbuild.c */
630 unsigned int rebuild_cgraph_edges (void);
631 void cgraph_rebuild_references (void);
632 void reset_inline_failed (struct cgraph_node *);
633 int compute_call_stmt_bb_frequency (tree, basic_block bb);
635 /* In ipa.c */
636 bool cgraph_remove_unreachable_nodes (bool, FILE *);
637 int cgraph_postorder (struct cgraph_node **);
638 cgraph_node_set cgraph_node_set_new (void);
639 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
640 struct cgraph_node *);
641 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
642 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
643 void dump_cgraph_node_set (FILE *, cgraph_node_set);
644 void debug_cgraph_node_set (cgraph_node_set);
646 varpool_node_set varpool_node_set_new (void);
647 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
648 struct varpool_node *);
649 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
650 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
651 void dump_varpool_node_set (FILE *, varpool_node_set);
652 void debug_varpool_node_set (varpool_node_set);
653 void ipa_discover_readonly_nonaddressable_vars (void);
654 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
656 /* In predict.c */
657 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
658 bool cgraph_optimize_for_size_p (struct cgraph_node *);
660 /* In varpool.c */
661 extern GTY(()) struct varpool_node *varpool_nodes_queue;
662 extern GTY(()) struct varpool_node *varpool_nodes;
664 struct varpool_node *varpool_node (tree);
665 struct varpool_node *varpool_node_for_asm (tree asmname);
666 void varpool_mark_needed_node (struct varpool_node *);
667 void debug_varpool (void);
668 void dump_varpool (FILE *);
669 void dump_varpool_node (FILE *, struct varpool_node *);
671 void varpool_finalize_decl (tree);
672 bool decide_is_variable_needed (struct varpool_node *, tree);
673 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
674 void cgraph_make_decl_local (tree);
675 void cgraph_make_node_local (struct cgraph_node *);
676 bool cgraph_node_can_be_local_p (struct cgraph_node *);
679 struct varpool_node * varpool_get_node (const_tree decl);
680 void varpool_remove_node (struct varpool_node *node);
681 void varpool_finalize_named_section_flags (struct varpool_node *node);
682 bool varpool_assemble_pending_decls (void);
683 bool varpool_assemble_decl (struct varpool_node *node);
684 bool varpool_analyze_pending_decls (void);
685 void varpool_remove_unreferenced_decls (void);
686 void varpool_empty_needed_queue (void);
687 struct varpool_node * varpool_extra_name_alias (tree, tree);
688 const char * varpool_node_name (struct varpool_node *node);
689 void varpool_reset_queue (void);
690 bool const_value_known_p (tree);
692 /* Walk all reachable static variables. */
693 #define FOR_EACH_STATIC_VARIABLE(node) \
694 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
696 /* Return first reachable static variable with initializer. */
697 static inline struct varpool_node *
698 varpool_first_static_initializer (void)
700 struct varpool_node *node;
701 for (node = varpool_nodes_queue; node; node = node->next_needed)
703 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
704 if (DECL_INITIAL (node->decl))
705 return node;
707 return NULL;
710 /* Return next reachable static variable with initializer after NODE. */
711 static inline struct varpool_node *
712 varpool_next_static_initializer (struct varpool_node *node)
714 for (node = node->next_needed; node; node = node->next_needed)
716 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
717 if (DECL_INITIAL (node->decl))
718 return node;
720 return NULL;
723 /* Walk all static variables with initializer set. */
724 #define FOR_EACH_STATIC_INITIALIZER(node) \
725 for ((node) = varpool_first_static_initializer (); (node); \
726 (node) = varpool_next_static_initializer (node))
728 /* In ipa-inline.c */
729 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
730 void compute_inline_parameters (struct cgraph_node *);
731 cgraph_inline_failed_t cgraph_edge_inlinable_p (struct cgraph_edge *);
734 /* Create a new static variable of type TYPE. */
735 tree add_new_static_var (tree type);
737 /* Return true if iterator CSI points to nothing. */
738 static inline bool
739 csi_end_p (cgraph_node_set_iterator csi)
741 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
744 /* Advance iterator CSI. */
745 static inline void
746 csi_next (cgraph_node_set_iterator *csi)
748 csi->index++;
751 /* Return the node pointed to by CSI. */
752 static inline struct cgraph_node *
753 csi_node (cgraph_node_set_iterator csi)
755 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
758 /* Return an iterator to the first node in SET. */
759 static inline cgraph_node_set_iterator
760 csi_start (cgraph_node_set set)
762 cgraph_node_set_iterator csi;
764 csi.set = set;
765 csi.index = 0;
766 return csi;
769 /* Return true if SET contains NODE. */
770 static inline bool
771 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
773 cgraph_node_set_iterator csi;
774 csi = cgraph_node_set_find (set, node);
775 return !csi_end_p (csi);
778 /* Return number of nodes in SET. */
779 static inline size_t
780 cgraph_node_set_size (cgraph_node_set set)
782 return htab_elements (set->hashtab);
785 /* Return true if iterator VSI points to nothing. */
786 static inline bool
787 vsi_end_p (varpool_node_set_iterator vsi)
789 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
792 /* Advance iterator VSI. */
793 static inline void
794 vsi_next (varpool_node_set_iterator *vsi)
796 vsi->index++;
799 /* Return the node pointed to by VSI. */
800 static inline struct varpool_node *
801 vsi_node (varpool_node_set_iterator vsi)
803 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
806 /* Return an iterator to the first node in SET. */
807 static inline varpool_node_set_iterator
808 vsi_start (varpool_node_set set)
810 varpool_node_set_iterator vsi;
812 vsi.set = set;
813 vsi.index = 0;
814 return vsi;
817 /* Return true if SET contains NODE. */
818 static inline bool
819 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
821 varpool_node_set_iterator vsi;
822 vsi = varpool_node_set_find (set, node);
823 return !vsi_end_p (vsi);
826 /* Return number of nodes in SET. */
827 static inline size_t
828 varpool_node_set_size (varpool_node_set set)
830 return htab_elements (set->hashtab);
833 /* Uniquize all constants that appear in memory.
834 Each constant in memory thus far output is recorded
835 in `const_desc_table'. */
837 struct GTY(()) constant_descriptor_tree {
838 /* A MEM for the constant. */
839 rtx rtl;
841 /* The value of the constant. */
842 tree value;
844 /* Hash of value. Computing the hash from value each time
845 hashfn is called can't work properly, as that means recursive
846 use of the hash table during hash table expansion. */
847 hashval_t hash;
850 /* Return true if set is nonempty. */
851 static inline bool
852 cgraph_node_set_nonempty_p (cgraph_node_set set)
854 return !VEC_empty (cgraph_node_ptr, set->nodes);
857 /* Return true if set is nonempty. */
858 static inline bool
859 varpool_node_set_nonempty_p (varpool_node_set set)
861 return !VEC_empty (varpool_node_ptr, set->nodes);
864 /* Return true when function NODE is only called directly.
865 i.e. it is not externally visible, address was not taken and
866 it is not used in any other non-standard way. */
868 static inline bool
869 cgraph_only_called_directly_p (struct cgraph_node *node)
871 gcc_assert (!node->global.inlined_to);
872 return (!node->needed && !node->address_taken
873 && !node->reachable_from_other_partition
874 && !DECL_STATIC_CONSTRUCTOR (node->decl)
875 && !DECL_STATIC_DESTRUCTOR (node->decl)
876 && !node->local.externally_visible);
879 /* Return true when function NODE can be removed from callgraph
880 if all direct calls are eliminated. */
882 static inline bool
883 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
885 /* Extern inlines can always go, we will use the external definition. */
886 if (DECL_EXTERNAL (node->decl))
887 return true;
888 return !node->address_taken && cgraph_can_remove_if_no_direct_calls_and_refs_p (node);
891 /* Return true when function NODE can be removed from callgraph
892 if all direct calls are eliminated. */
894 static inline bool
895 varpool_can_remove_if_no_refs (struct varpool_node *node)
897 return (!node->force_output && !node->used_from_other_partition
898 && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
899 || DECL_ARTIFICIAL (node->decl))
900 && (DECL_COMDAT (node->decl) || !node->externally_visible));
903 /* Return true when all references to VNODE must be visible in ipa_ref_list.
904 i.e. if the variable is not externally visible or not used in some magic
905 way (asm statement or such).
906 The magic uses are all summarized in force_output flag. */
908 static inline bool
909 varpool_all_refs_explicit_p (struct varpool_node *vnode)
911 return (!vnode->externally_visible
912 && !vnode->used_from_other_partition
913 && !vnode->force_output);
916 /* Constant pool accessor function. */
917 htab_t constant_pool_htab (void);
919 /* Return true when the edge E represents a direct recursion. */
920 static inline bool
921 cgraph_edge_recursive_p (struct cgraph_edge *e)
923 if (e->caller->global.inlined_to)
924 return e->caller->global.inlined_to->decl == e->callee->decl;
925 else
926 return e->caller->decl == e->callee->decl;
929 /* FIXME: inappropriate dependency of cgraph on IPA. */
930 #include "ipa-ref-inline.h"
932 #endif /* GCC_CGRAPH_H */