cgraph.h: Remove misledaing comment on ipa-ref.h.
[official-gcc.git] / gcc / cgraph.h
blob8740fba7c4731d83254802344e2dfc7be24a7940
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"
32 /* Symbol table consists of functions and variables.
33 TODO: add labels, constant pool and aliases. */
34 enum symtab_type
36 SYMTAB_FUNCTION,
37 SYMTAB_VARIABLE
40 /* Base of all entries in the symbol table.
41 The symtab_node is inherited by cgraph and varpol nodes. */
42 struct GTY(()) symtab_node
44 /* Type of the symbol. */
45 enum symtab_type type;
48 enum availability
50 /* Not yet set by cgraph_function_body_availability. */
51 AVAIL_UNSET,
52 /* Function body/variable initializer is unknown. */
53 AVAIL_NOT_AVAILABLE,
54 /* Function body/variable initializer is known but might be replaced
55 by a different one from other compilation unit and thus needs to
56 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
57 arbitrary side effects on escaping variables and functions, while
58 like AVAILABLE it might access static variables. */
59 AVAIL_OVERWRITABLE,
60 /* Function body/variable initializer is known and will be used in final
61 program. */
62 AVAIL_AVAILABLE,
63 /* Function body/variable initializer is known and all it's uses are explicitly
64 visible within current unit (ie it's address is never taken and it is not
65 exported to other units).
66 Currently used only for functions. */
67 AVAIL_LOCAL
70 /* This is the information that is put into the cgraph local structure
71 to recover a function. */
72 struct lto_file_decl_data;
74 extern const char * const cgraph_availability_names[];
75 extern const char * const ld_plugin_symbol_resolution_names[];
77 /* Information about thunk, used only for same body aliases. */
79 struct GTY(()) cgraph_thunk_info {
80 /* Information about the thunk. */
81 HOST_WIDE_INT fixed_offset;
82 HOST_WIDE_INT virtual_value;
83 tree alias;
84 bool this_adjusting;
85 bool virtual_offset_p;
86 /* Set to true when alias node is thunk. */
87 bool thunk_p;
90 /* Information about the function collected locally.
91 Available after function is analyzed. */
93 struct GTY(()) cgraph_local_info {
94 /* File stream where this node is being written to. */
95 struct lto_file_decl_data * lto_file_data;
97 /* Set when function function is visible in current compilation unit only
98 and its address is never taken. */
99 unsigned local : 1;
101 /* Set when function is visible by other units. */
102 unsigned externally_visible : 1;
104 /* Set once it has been finalized so we consider it to be output. */
105 unsigned finalized : 1;
107 /* False when there is something makes versioning impossible. */
108 unsigned versionable : 1;
110 /* False when function calling convention and signature can not be changed.
111 This is the case when __builtin_apply_args is used. */
112 unsigned can_change_signature : 1;
114 /* True when the function has been originally extern inline, but it is
115 redefined now. */
116 unsigned redefined_extern_inline : 1;
118 /* True if the function may enter serial irrevocable mode. */
119 unsigned tm_may_enter_irr : 1;
122 /* Information about the function that needs to be computed globally
123 once compilation is finished. Available only with -funit-at-a-time. */
125 struct GTY(()) cgraph_global_info {
126 /* For inline clones this points to the function they will be
127 inlined into. */
128 struct cgraph_node *inlined_to;
131 /* Information about the function that is propagated by the RTL backend.
132 Available only for functions that has been already assembled. */
134 struct GTY(()) cgraph_rtl_info {
135 unsigned int preferred_incoming_stack_boundary;
138 /* Represent which DECL tree (or reference to such tree)
139 will be replaced by another tree while versioning. */
140 struct GTY(()) ipa_replace_map
142 /* The tree that will be replaced. */
143 tree old_tree;
144 /* The new (replacing) tree. */
145 tree new_tree;
146 /* Parameter number to replace, when old_tree is NULL. */
147 int parm_num;
148 /* True when a substitution should be done, false otherwise. */
149 bool replace_p;
150 /* True when we replace a reference to old_tree. */
151 bool ref_p;
153 typedef struct ipa_replace_map *ipa_replace_map_p;
154 DEF_VEC_P(ipa_replace_map_p);
155 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
157 struct GTY(()) cgraph_clone_info
159 VEC(ipa_replace_map_p,gc)* tree_map;
160 bitmap args_to_skip;
161 bitmap combined_args_to_skip;
165 /* The cgraph data structure.
166 Each function decl has assigned cgraph_node listing callees and callers. */
168 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
169 struct symtab_node symbol;
170 tree decl;
171 struct cgraph_edge *callees;
172 struct cgraph_edge *callers;
173 struct cgraph_node *next;
174 struct cgraph_node *previous;
175 /* List of edges representing indirect calls with a yet undetermined
176 callee. */
177 struct cgraph_edge *indirect_calls;
178 /* For nested functions points to function the node is nested in. */
179 struct cgraph_node *origin;
180 /* Points to first nested function, if any. */
181 struct cgraph_node *nested;
182 /* Pointer to the next function with same origin, if any. */
183 struct cgraph_node *next_nested;
184 /* Pointer to the next function in cgraph_nodes_queue. */
185 struct cgraph_node *next_needed;
186 /* Pointer to the next clone. */
187 struct cgraph_node *next_sibling_clone;
188 struct cgraph_node *prev_sibling_clone;
189 struct cgraph_node *clones;
190 struct cgraph_node *clone_of;
191 /* Circular list of nodes in the same comdat group if non-NULL. */
192 struct cgraph_node *same_comdat_group;
193 /* For functions with many calls sites it holds map from call expression
194 to the edge to speed up cgraph_edge function. */
195 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
196 /* Declaration node used to be clone of. */
197 tree former_clone_of;
199 PTR GTY ((skip)) aux;
201 /* Interprocedural passes scheduled to have their transform functions
202 applied next time we execute local pass on them. We maintain it
203 per-function in order to allow IPA passes to introduce new functions. */
204 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
206 struct ipa_ref_list ref_list;
207 struct cgraph_local_info local;
208 struct cgraph_global_info global;
209 struct cgraph_rtl_info rtl;
210 struct cgraph_clone_info clone;
211 struct cgraph_thunk_info thunk;
213 /* Expected number of executions: calculated in profile.c. */
214 gcov_type count;
215 /* How to scale counts at materialization time; used to merge
216 LTO units with different number of profile runs. */
217 int count_materialization_scale;
218 /* Unique id of the node. */
219 int uid;
220 /* Ordering of all cgraph nodes. */
221 int order;
223 enum ld_plugin_symbol_resolution resolution;
225 /* Set when function must be output for some reason. The primary
226 use of this flag is to mark functions needed to be output for
227 non-standard reason. Functions that are externally visible
228 or reachable from functions needed to be output are marked
229 by specialized flags. */
230 unsigned needed : 1;
231 /* Set when function has address taken.
232 In current implementation it imply needed flag. */
233 unsigned address_taken : 1;
234 /* Set when decl is an abstract function pointed to by the
235 ABSTRACT_DECL_ORIGIN of a reachable function. */
236 unsigned abstract_and_needed : 1;
237 /* Set when function is reachable by call from other function
238 that is either reachable or needed.
239 This flag is computed at original cgraph construction and then
240 updated in cgraph_remove_unreachable_nodes. Note that after
241 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
242 nodes when they are needed for virtual clone instantiation. */
243 unsigned reachable : 1;
244 /* Set when function is reachable by call from other LTRANS partition. */
245 unsigned reachable_from_other_partition : 1;
246 /* Set once the function is lowered (i.e. its CFG is built). */
247 unsigned lowered : 1;
248 /* Set once the function has been instantiated and its callee
249 lists created. */
250 unsigned analyzed : 1;
251 /* Set when function is available in the other LTRANS partition.
252 During WPA output it is used to mark nodes that are present in
253 multiple partitions. */
254 unsigned in_other_partition : 1;
255 /* Set when function is scheduled to be processed by local passes. */
256 unsigned process : 1;
257 /* Set for aliases once they got through assemble_alias. */
258 unsigned alias : 1;
259 /* Set for aliases created as C++ same body aliases. */
260 unsigned same_body_alias : 1;
261 /* How commonly executed the node is. Initialized during branch
262 probabilities pass. */
263 ENUM_BITFIELD (node_frequency) frequency : 2;
264 /* True when function can only be called at startup (from static ctor). */
265 unsigned only_called_at_startup : 1;
266 /* True when function can only be called at startup (from static dtor). */
267 unsigned only_called_at_exit : 1;
268 /* True when function is the transactional clone of a function which
269 is called only from inside transactions. */
270 /* ?? We should be able to remove this. We have enough bits in
271 cgraph to calculate it. */
272 unsigned tm_clone : 1;
275 typedef struct cgraph_node *cgraph_node_ptr;
277 DEF_VEC_P(cgraph_node_ptr);
278 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
279 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
281 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
282 can appear in multiple sets. */
283 struct cgraph_node_set_def
285 struct pointer_map_t *map;
286 VEC(cgraph_node_ptr, heap) *nodes;
289 typedef struct varpool_node *varpool_node_ptr;
291 DEF_VEC_P(varpool_node_ptr);
292 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
293 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
295 /* A varpool node set is a collection of varpool nodes. A varpool node
296 can appear in multiple sets. */
297 struct varpool_node_set_def
299 struct pointer_map_t * map;
300 VEC(varpool_node_ptr, heap) *nodes;
303 typedef struct cgraph_node_set_def *cgraph_node_set;
305 DEF_VEC_P(cgraph_node_set);
306 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
307 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
309 typedef struct varpool_node_set_def *varpool_node_set;
311 DEF_VEC_P(varpool_node_set);
312 DEF_VEC_ALLOC_P(varpool_node_set,gc);
313 DEF_VEC_ALLOC_P(varpool_node_set,heap);
315 /* Iterator structure for cgraph node sets. */
316 typedef struct
318 cgraph_node_set set;
319 unsigned index;
320 } cgraph_node_set_iterator;
322 /* Iterator structure for varpool node sets. */
323 typedef struct
325 varpool_node_set set;
326 unsigned index;
327 } varpool_node_set_iterator;
329 #define DEFCIFCODE(code, string) CIF_ ## code,
330 /* Reasons for inlining failures. */
331 typedef enum cgraph_inline_failed_enum {
332 #include "cif-code.def"
333 CIF_N_REASONS
334 } cgraph_inline_failed_t;
336 /* Structure containing additional information about an indirect call. */
338 struct GTY(()) cgraph_indirect_call_info
340 /* Offset accumulated from ancestor jump functions of inlined call graph
341 edges. */
342 HOST_WIDE_INT anc_offset;
343 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
344 HOST_WIDE_INT otr_token;
345 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
346 tree otr_type;
347 /* Index of the parameter that is called. */
348 int param_index;
349 /* ECF flags determined from the caller. */
350 int ecf_flags;
352 /* Set when the call is a virtual call with the parameter being the
353 associated object pointer rather than a simple direct call. */
354 unsigned polymorphic : 1;
357 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
358 /* Expected number of executions: calculated in profile.c. */
359 gcov_type count;
360 struct cgraph_node *caller;
361 struct cgraph_node *callee;
362 struct cgraph_edge *prev_caller;
363 struct cgraph_edge *next_caller;
364 struct cgraph_edge *prev_callee;
365 struct cgraph_edge *next_callee;
366 gimple call_stmt;
367 /* Additional information about an indirect call. Not cleared when an edge
368 becomes direct. */
369 struct cgraph_indirect_call_info *indirect_info;
370 PTR GTY ((skip (""))) aux;
371 /* When equal to CIF_OK, inline this call. Otherwise, points to the
372 explanation why function was not inlined. */
373 cgraph_inline_failed_t inline_failed;
374 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
375 when the function is serialized in. */
376 unsigned int lto_stmt_uid;
377 /* Expected frequency of executions within the function.
378 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
379 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
380 int frequency;
381 /* Unique id of the edge. */
382 int uid;
383 /* Whether this edge was made direct by indirect inlining. */
384 unsigned int indirect_inlining_edge : 1;
385 /* Whether this edge describes an indirect call with an undetermined
386 callee. */
387 unsigned int indirect_unknown_callee : 1;
388 /* Whether this edge is still a dangling */
389 /* True if the corresponding CALL stmt cannot be inlined. */
390 unsigned int call_stmt_cannot_inline_p : 1;
391 /* Can this call throw externally? */
392 unsigned int can_throw_external : 1;
395 #define CGRAPH_FREQ_BASE 1000
396 #define CGRAPH_FREQ_MAX 100000
398 typedef struct cgraph_edge *cgraph_edge_p;
400 DEF_VEC_P(cgraph_edge_p);
401 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
403 /* The varpool data structure.
404 Each static variable decl has assigned varpool_node. */
406 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
407 struct symtab_node symbol;
408 tree decl;
409 /* For aliases points to declaration DECL is alias of. */
410 tree alias_of;
411 /* Pointer to the next function in varpool_nodes. */
412 struct varpool_node *next, *prev;
413 /* Pointer to the next function in varpool_nodes_queue. */
414 struct varpool_node *next_needed, *prev_needed;
415 /* Circular list of nodes in the same comdat group if non-NULL. */
416 struct varpool_node *same_comdat_group;
417 struct ipa_ref_list ref_list;
418 /* File stream where this node is being written to. */
419 struct lto_file_decl_data * lto_file_data;
420 PTR GTY ((skip)) aux;
421 /* Ordering of all cgraph nodes. */
422 int order;
423 enum ld_plugin_symbol_resolution resolution;
425 /* Set when function must be output - it is externally visible
426 or its address is taken. */
427 unsigned needed : 1;
428 /* Needed variables might become dead by optimization. This flag
429 forces the variable to be output even if it appears dead otherwise. */
430 unsigned force_output : 1;
431 /* Set once the variable has been instantiated and its callee
432 lists created. */
433 unsigned analyzed : 1;
434 /* Set once it has been finalized so we consider it to be output. */
435 unsigned finalized : 1;
436 /* Set when variable is scheduled to be assembled. */
437 unsigned output : 1;
438 /* Set when function is visible by other units. */
439 unsigned externally_visible : 1;
440 /* Set for aliases once they got through assemble_alias. Also set for
441 extra name aliases in varpool_extra_name_alias. */
442 unsigned alias : 1;
443 unsigned extra_name_alias : 1;
444 /* Set when variable is used from other LTRANS partition. */
445 unsigned used_from_other_partition : 1;
446 /* Set when variable is available in the other LTRANS partition.
447 During WPA output it is used to mark nodes that are present in
448 multiple partitions. */
449 unsigned in_other_partition : 1;
452 /* Every top level asm statement is put into a cgraph_asm_node. */
454 struct GTY(()) cgraph_asm_node {
455 /* Next asm node. */
456 struct cgraph_asm_node *next;
457 /* String for this asm node. */
458 tree asm_str;
459 /* Ordering of all cgraph nodes. */
460 int order;
463 extern GTY(()) struct cgraph_node *cgraph_nodes;
464 extern GTY(()) int cgraph_n_nodes;
465 extern GTY(()) int cgraph_max_uid;
466 extern GTY(()) int cgraph_edge_max_uid;
467 extern bool cgraph_global_info_ready;
468 enum cgraph_state
470 /* Callgraph is being constructed. It is safe to add new functions. */
471 CGRAPH_STATE_CONSTRUCTION,
472 /* Callgraph is built and IPA passes are being run. */
473 CGRAPH_STATE_IPA,
474 /* Callgraph is built and all functions are transformed to SSA form. */
475 CGRAPH_STATE_IPA_SSA,
476 /* Functions are now ordered and being passed to RTL expanders. */
477 CGRAPH_STATE_EXPANSION,
478 /* All cgraph expansion is done. */
479 CGRAPH_STATE_FINISHED
481 extern enum cgraph_state cgraph_state;
482 extern bool cgraph_function_flags_ready;
483 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
484 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
486 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
487 extern GTY(()) int cgraph_order;
488 extern bool same_body_aliases_done;
490 /* In cgraph.c */
491 void dump_cgraph (FILE *);
492 void debug_cgraph (void);
493 void dump_cgraph_node (FILE *, struct cgraph_node *);
494 void debug_cgraph_node (struct cgraph_node *);
495 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
496 void cgraph_remove_edge (struct cgraph_edge *);
497 void cgraph_remove_node (struct cgraph_node *);
498 void cgraph_add_to_same_comdat_group (struct cgraph_node *, struct cgraph_node *);
499 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
500 void cgraph_release_function_body (struct cgraph_node *);
501 void cgraph_node_remove_callees (struct cgraph_node *node);
502 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
503 struct cgraph_node *,
504 gimple, gcov_type, int);
505 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
506 int, gcov_type, int);
507 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
508 struct cgraph_node * cgraph_get_node (const_tree);
509 struct cgraph_node * cgraph_create_node (tree);
510 struct cgraph_node * cgraph_get_create_node (tree);
511 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
512 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
513 HOST_WIDE_INT, tree, tree);
514 struct cgraph_node *cgraph_node_for_asm (tree);
515 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
516 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
517 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
518 void cgraph_create_edge_including_clones (struct cgraph_node *,
519 struct cgraph_node *,
520 gimple, gimple, gcov_type, int,
521 cgraph_inline_failed_t);
522 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
523 struct cgraph_local_info *cgraph_local_info (tree);
524 struct cgraph_global_info *cgraph_global_info (tree);
525 struct cgraph_rtl_info *cgraph_rtl_info (tree);
526 const char * cgraph_node_name (struct cgraph_node *);
527 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
528 struct cgraph_node *, gimple,
529 unsigned, gcov_type, int, bool);
530 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
531 int, bool, VEC(cgraph_edge_p,heap) *,
532 bool);
533 struct cgraph_node *cgraph_create_function_alias (tree, tree);
534 void cgraph_call_node_duplication_hooks (struct cgraph_node *node1,
535 struct cgraph_node *node2);
537 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
538 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
539 bool cgraph_only_called_directly_p (struct cgraph_node *);
541 struct cgraph_asm_node *cgraph_add_asm_node (tree);
543 bool cgraph_function_possibly_inlined_p (tree);
544 void cgraph_unnest_node (struct cgraph_node *);
546 enum availability cgraph_function_body_availability (struct cgraph_node *);
547 void cgraph_add_new_function (tree, bool);
548 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
549 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
550 VEC(cgraph_edge_p,heap)*,
551 VEC(ipa_replace_map_p,gc)* tree_map,
552 bitmap args_to_skip,
553 const char *clone_name);
555 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
556 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
557 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
558 tree clone_function_name (tree decl, const char *);
559 bool cgraph_node_cannot_return (struct cgraph_node *);
560 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
561 bool cgraph_will_be_removed_from_program_if_no_direct_calls
562 (struct cgraph_node *node);
563 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
564 (struct cgraph_node *node);
565 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
566 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
567 bool cgraph_used_from_object_file_p (struct cgraph_node *);
568 bool varpool_used_from_object_file_p (struct varpool_node *);
569 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
570 bool (*) (struct cgraph_node *, void *),
571 void *,
572 bool);
573 bool cgraph_for_node_and_aliases (struct cgraph_node *,
574 bool (*) (struct cgraph_node *, void *),
575 void *, bool);
576 VEC (cgraph_edge_p, heap) * collect_callers_of_node (struct cgraph_node *node);
579 /* In cgraphunit.c */
580 extern FILE *cgraph_dump_file;
581 void cgraph_finalize_function (tree, bool);
582 void cgraph_mark_if_needed (tree);
583 void cgraph_analyze_function (struct cgraph_node *);
584 void cgraph_finalize_compilation_unit (void);
585 void cgraph_optimize (void);
586 void tree_rest_of_compilation (struct cgraph_node *);
587 void cgraph_mark_needed_node (struct cgraph_node *);
588 void cgraph_mark_address_taken_node (struct cgraph_node *);
589 void cgraph_mark_reachable_node (struct cgraph_node *);
590 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
591 bool cgraph_preserve_function_body_p (struct cgraph_node *);
592 void verify_cgraph (void);
593 void verify_cgraph_node (struct cgraph_node *);
594 void cgraph_build_static_cdtor (char which, tree body, int priority);
595 void cgraph_reset_static_var_maps (void);
596 void init_cgraph (void);
597 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
598 tree, VEC(cgraph_edge_p,heap)*, bitmap);
599 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
600 VEC(cgraph_edge_p,heap)*,
601 VEC(ipa_replace_map_p,gc)*,
602 bitmap, bool, bitmap,
603 basic_block, const char *);
604 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*,
605 bool, bitmap, bool, bitmap, basic_block);
606 void record_references_in_initializer (tree, bool);
607 bool cgraph_process_new_functions (void);
608 void cgraph_process_same_body_aliases (void);
610 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
612 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
613 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
614 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
615 void *);
616 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
617 void *);
618 struct cgraph_edge_hook_list;
619 struct cgraph_node_hook_list;
620 struct cgraph_2edge_hook_list;
621 struct cgraph_2node_hook_list;
622 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
623 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
624 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
625 void *);
626 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
627 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
628 void *);
629 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
630 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
631 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
632 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
633 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
634 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
635 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
636 bool cgraph_propagate_frequency (struct cgraph_node *node);
637 /* In cgraphbuild.c */
638 unsigned int rebuild_cgraph_edges (void);
639 void cgraph_rebuild_references (void);
640 int compute_call_stmt_bb_frequency (tree, basic_block bb);
642 /* In ipa.c */
643 bool cgraph_remove_unreachable_nodes (bool, FILE *);
644 cgraph_node_set cgraph_node_set_new (void);
645 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
646 struct cgraph_node *);
647 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
648 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
649 void dump_cgraph_node_set (FILE *, cgraph_node_set);
650 void debug_cgraph_node_set (cgraph_node_set);
651 void free_cgraph_node_set (cgraph_node_set);
653 varpool_node_set varpool_node_set_new (void);
654 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
655 struct varpool_node *);
656 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
657 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
658 void dump_varpool_node_set (FILE *, varpool_node_set);
659 void debug_varpool_node_set (varpool_node_set);
660 void free_varpool_node_set (varpool_node_set);
661 void ipa_discover_readonly_nonaddressable_vars (void);
662 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
663 bool varpool_externally_visible_p (struct varpool_node *, bool);
665 /* In predict.c */
666 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
667 bool cgraph_optimize_for_size_p (struct cgraph_node *);
669 /* In varpool.c */
670 extern GTY(()) struct varpool_node *varpool_nodes_queue;
671 extern GTY(()) struct varpool_node *varpool_nodes;
673 struct varpool_node *varpool_node (tree);
674 struct varpool_node *varpool_node_for_asm (tree asmname);
675 void varpool_mark_needed_node (struct varpool_node *);
676 void debug_varpool (void);
677 void dump_varpool (FILE *);
678 void dump_varpool_node (FILE *, struct varpool_node *);
680 void varpool_finalize_decl (tree);
681 bool decide_is_variable_needed (struct varpool_node *, tree);
682 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
683 void cgraph_make_decl_local (tree);
684 void cgraph_make_node_local (struct cgraph_node *);
685 bool cgraph_node_can_be_local_p (struct cgraph_node *);
688 struct varpool_node * varpool_get_node (const_tree decl);
689 void varpool_remove_node (struct varpool_node *node);
690 void varpool_finalize_named_section_flags (struct varpool_node *node);
691 bool varpool_assemble_pending_decls (void);
692 bool varpool_assemble_decl (struct varpool_node *node);
693 bool varpool_analyze_pending_decls (void);
694 void varpool_remove_unreferenced_decls (void);
695 void varpool_empty_needed_queue (void);
696 struct varpool_node * varpool_extra_name_alias (tree, tree);
697 struct varpool_node * varpool_create_variable_alias (tree, tree);
698 const char * varpool_node_name (struct varpool_node *node);
699 void varpool_reset_queue (void);
700 bool const_value_known_p (tree);
701 bool varpool_for_node_and_aliases (struct varpool_node *,
702 bool (*) (struct varpool_node *, void *),
703 void *, bool);
704 void varpool_add_new_variable (tree);
706 /* Walk all reachable static variables. */
707 #define FOR_EACH_STATIC_VARIABLE(node) \
708 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
710 /* Return callgraph node for given symbol and check it is a function. */
711 static inline struct cgraph_node *
712 cgraph (struct symtab_node *node)
714 gcc_checking_assert (node->type == SYMTAB_FUNCTION);
715 return (struct cgraph_node *)node;
718 /* Return varpool node for given symbol and check it is a variable. */
719 static inline struct varpool_node *
720 varpool (struct symtab_node *node)
722 gcc_checking_assert (node->type == SYMTAB_FUNCTION);
723 return (struct varpool_node *)node;
727 /* Return first reachable static variable with initializer. */
728 static inline struct varpool_node *
729 varpool_first_static_initializer (void)
731 struct varpool_node *node;
732 for (node = varpool_nodes_queue; node; node = node->next_needed)
734 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
735 if (DECL_INITIAL (node->decl))
736 return node;
738 return NULL;
741 /* Return next reachable static variable with initializer after NODE. */
742 static inline struct varpool_node *
743 varpool_next_static_initializer (struct varpool_node *node)
745 for (node = node->next_needed; node; node = node->next_needed)
747 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
748 if (DECL_INITIAL (node->decl))
749 return node;
751 return NULL;
754 /* Walk all static variables with initializer set. */
755 #define FOR_EACH_STATIC_INITIALIZER(node) \
756 for ((node) = varpool_first_static_initializer (); (node); \
757 (node) = varpool_next_static_initializer (node))
759 /* Return first function with body defined. */
760 static inline struct cgraph_node *
761 cgraph_first_defined_function (void)
763 struct cgraph_node *node;
764 for (node = cgraph_nodes; node; node = node->next)
766 if (node->analyzed)
767 return node;
769 return NULL;
772 /* Return next function with body defined after NODE. */
773 static inline struct cgraph_node *
774 cgraph_next_defined_function (struct cgraph_node *node)
776 for (node = node->next; node; node = node->next)
778 if (node->analyzed)
779 return node;
781 return NULL;
784 /* Walk all functions with body defined. */
785 #define FOR_EACH_DEFINED_FUNCTION(node) \
786 for ((node) = cgraph_first_defined_function (); (node); \
787 (node) = cgraph_next_defined_function (node))
790 /* Return true when NODE is a function with Gimple body defined
791 in current unit. Functions can also be define externally or they
792 can be thunks with no Gimple representation.
794 Note that at WPA stage, the function body may not be present in memory. */
796 static inline bool
797 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
799 return node->analyzed && !node->thunk.thunk_p && !node->alias;
802 /* Return first function with body defined. */
803 static inline struct cgraph_node *
804 cgraph_first_function_with_gimple_body (void)
806 struct cgraph_node *node;
807 for (node = cgraph_nodes; node; node = node->next)
809 if (cgraph_function_with_gimple_body_p (node))
810 return node;
812 return NULL;
815 /* Return next reachable static variable with initializer after NODE. */
816 static inline struct cgraph_node *
817 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
819 for (node = node->next; node; node = node->next)
821 if (cgraph_function_with_gimple_body_p (node))
822 return node;
824 return NULL;
827 /* Walk all functions with body defined. */
828 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
829 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
830 (node) = cgraph_next_function_with_gimple_body (node))
832 /* Create a new static variable of type TYPE. */
833 tree add_new_static_var (tree type);
835 /* Return true if iterator CSI points to nothing. */
836 static inline bool
837 csi_end_p (cgraph_node_set_iterator csi)
839 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
842 /* Advance iterator CSI. */
843 static inline void
844 csi_next (cgraph_node_set_iterator *csi)
846 csi->index++;
849 /* Return the node pointed to by CSI. */
850 static inline struct cgraph_node *
851 csi_node (cgraph_node_set_iterator csi)
853 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
856 /* Return an iterator to the first node in SET. */
857 static inline cgraph_node_set_iterator
858 csi_start (cgraph_node_set set)
860 cgraph_node_set_iterator csi;
862 csi.set = set;
863 csi.index = 0;
864 return csi;
867 /* Return true if SET contains NODE. */
868 static inline bool
869 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
871 cgraph_node_set_iterator csi;
872 csi = cgraph_node_set_find (set, node);
873 return !csi_end_p (csi);
876 /* Return number of nodes in SET. */
877 static inline size_t
878 cgraph_node_set_size (cgraph_node_set set)
880 return VEC_length (cgraph_node_ptr, set->nodes);
883 /* Return true if iterator VSI points to nothing. */
884 static inline bool
885 vsi_end_p (varpool_node_set_iterator vsi)
887 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
890 /* Advance iterator VSI. */
891 static inline void
892 vsi_next (varpool_node_set_iterator *vsi)
894 vsi->index++;
897 /* Return the node pointed to by VSI. */
898 static inline struct varpool_node *
899 vsi_node (varpool_node_set_iterator vsi)
901 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
904 /* Return an iterator to the first node in SET. */
905 static inline varpool_node_set_iterator
906 vsi_start (varpool_node_set set)
908 varpool_node_set_iterator vsi;
910 vsi.set = set;
911 vsi.index = 0;
912 return vsi;
915 /* Return true if SET contains NODE. */
916 static inline bool
917 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
919 varpool_node_set_iterator vsi;
920 vsi = varpool_node_set_find (set, node);
921 return !vsi_end_p (vsi);
924 /* Return number of nodes in SET. */
925 static inline size_t
926 varpool_node_set_size (varpool_node_set set)
928 return VEC_length (varpool_node_ptr, set->nodes);
931 /* Uniquize all constants that appear in memory.
932 Each constant in memory thus far output is recorded
933 in `const_desc_table'. */
935 struct GTY(()) constant_descriptor_tree {
936 /* A MEM for the constant. */
937 rtx rtl;
939 /* The value of the constant. */
940 tree value;
942 /* Hash of value. Computing the hash from value each time
943 hashfn is called can't work properly, as that means recursive
944 use of the hash table during hash table expansion. */
945 hashval_t hash;
948 /* Return true if set is nonempty. */
949 static inline bool
950 cgraph_node_set_nonempty_p (cgraph_node_set set)
952 return !VEC_empty (cgraph_node_ptr, set->nodes);
955 /* Return true if set is nonempty. */
956 static inline bool
957 varpool_node_set_nonempty_p (varpool_node_set set)
959 return !VEC_empty (varpool_node_ptr, set->nodes);
962 /* Return true when function NODE is only called directly or it has alias.
963 i.e. it is not externally visible, address was not taken and
964 it is not used in any other non-standard way. */
966 static inline bool
967 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
969 gcc_assert (!node->global.inlined_to);
970 return (!node->needed && !node->address_taken
971 && !node->reachable_from_other_partition
972 && !DECL_STATIC_CONSTRUCTOR (node->decl)
973 && !DECL_STATIC_DESTRUCTOR (node->decl)
974 && !node->local.externally_visible);
977 /* Return true when function NODE can be removed from callgraph
978 if all direct calls are eliminated. */
980 static inline bool
981 varpool_can_remove_if_no_refs (struct varpool_node *node)
983 return (!node->force_output && !node->used_from_other_partition
984 && (DECL_COMDAT (node->decl) || !node->externally_visible));
987 /* Return true when all references to VNODE must be visible in ipa_ref_list.
988 i.e. if the variable is not externally visible or not used in some magic
989 way (asm statement or such).
990 The magic uses are all summarized in force_output flag. */
992 static inline bool
993 varpool_all_refs_explicit_p (struct varpool_node *vnode)
995 return (vnode->analyzed
996 && !vnode->externally_visible
997 && !vnode->used_from_other_partition
998 && !vnode->force_output);
1001 /* Constant pool accessor function. */
1002 htab_t constant_pool_htab (void);
1004 /* FIXME: inappropriate dependency of cgraph on IPA. */
1005 #include "ipa-ref-inline.h"
1007 /* Return node that alias N is aliasing. */
1009 static inline struct cgraph_node *
1010 cgraph_alias_aliased_node (struct cgraph_node *n)
1012 struct ipa_ref *ref;
1014 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1015 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1016 if (ref->refered_type == IPA_REF_CGRAPH)
1017 return ipa_ref_node (ref);
1018 return NULL;
1021 /* Return node that alias N is aliasing. */
1023 static inline struct varpool_node *
1024 varpool_alias_aliased_node (struct varpool_node *n)
1026 struct ipa_ref *ref;
1028 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1029 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1030 if (ref->refered_type == IPA_REF_VARPOOL)
1031 return ipa_ref_varpool_node (ref);
1032 return NULL;
1035 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1036 Walk through thunk, too.
1037 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1039 static inline struct cgraph_node *
1040 cgraph_function_node (struct cgraph_node *node, enum availability *availability)
1042 if (availability)
1043 *availability = cgraph_function_body_availability (node);
1044 while (node)
1046 if (node->alias && node->analyzed)
1047 node = cgraph_alias_aliased_node (node);
1048 else if (node->thunk.thunk_p)
1049 node = node->callees->callee;
1050 else
1051 return node;
1052 if (node && availability)
1054 enum availability a;
1055 a = cgraph_function_body_availability (node);
1056 if (a < *availability)
1057 *availability = a;
1060 if (availability)
1061 *availability = AVAIL_NOT_AVAILABLE;
1062 return NULL;
1065 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1066 Do not walk through thunks.
1067 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1069 static inline struct cgraph_node *
1070 cgraph_function_or_thunk_node (struct cgraph_node *node, enum availability *availability)
1072 if (availability)
1073 *availability = cgraph_function_body_availability (node);
1074 while (node)
1076 if (node->alias && node->analyzed)
1077 node = cgraph_alias_aliased_node (node);
1078 else
1079 return node;
1080 if (node && availability)
1082 enum availability a;
1083 a = cgraph_function_body_availability (node);
1084 if (a < *availability)
1085 *availability = a;
1088 if (availability)
1089 *availability = AVAIL_NOT_AVAILABLE;
1090 return NULL;
1093 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1094 Do not walk through thunks.
1095 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1097 static inline struct varpool_node *
1098 varpool_variable_node (struct varpool_node *node, enum availability *availability)
1100 if (availability)
1101 *availability = cgraph_variable_initializer_availability (node);
1102 while (node)
1104 if (node->alias && node->analyzed)
1105 node = varpool_alias_aliased_node (node);
1106 else
1107 return node;
1108 if (node && availability)
1110 enum availability a;
1111 a = cgraph_variable_initializer_availability (node);
1112 if (a < *availability)
1113 *availability = a;
1116 if (availability)
1117 *availability = AVAIL_NOT_AVAILABLE;
1118 return NULL;
1121 /* Return true when the edge E represents a direct recursion. */
1122 static inline bool
1123 cgraph_edge_recursive_p (struct cgraph_edge *e)
1125 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1126 if (e->caller->global.inlined_to)
1127 return e->caller->global.inlined_to->decl == callee->decl;
1128 else
1129 return e->caller->decl == callee->decl;
1132 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1133 static inline bool
1134 decl_is_tm_clone (const_tree fndecl)
1136 struct cgraph_node *n = cgraph_get_node (fndecl);
1137 if (n)
1138 return n->tm_clone;
1139 return false;
1141 #endif /* GCC_CGRAPH_H */