2011-11-16 Matthew Gretton-Dann <matthew.gretton-dann@arm.com>
[official-gcc.git] / gcc / cgraph.h
blob834d3d4a44318c5cb36e10a99ebbe9f89b40b22d
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 there is something makes versioning impossible. */
92 unsigned versionable : 1;
94 /* False when function calling convention and signature can not be changed.
95 This is the case when __builtin_apply_args is used. */
96 unsigned can_change_signature : 1;
98 /* True when the function has been originally extern inline, but it is
99 redefined now. */
100 unsigned redefined_extern_inline : 1;
102 /* True if the function may enter serial irrevocable mode. */
103 unsigned tm_may_enter_irr : 1;
106 /* Information about the function that needs to be computed globally
107 once compilation is finished. Available only with -funit-at-a-time. */
109 struct GTY(()) cgraph_global_info {
110 /* For inline clones this points to the function they will be
111 inlined into. */
112 struct cgraph_node *inlined_to;
115 /* Information about the function that is propagated by the RTL backend.
116 Available only for functions that has been already assembled. */
118 struct GTY(()) cgraph_rtl_info {
119 unsigned int preferred_incoming_stack_boundary;
122 /* Represent which DECL tree (or reference to such tree)
123 will be replaced by another tree while versioning. */
124 struct GTY(()) ipa_replace_map
126 /* The tree that will be replaced. */
127 tree old_tree;
128 /* The new (replacing) tree. */
129 tree new_tree;
130 /* Parameter number to replace, when old_tree is NULL. */
131 int parm_num;
132 /* True when a substitution should be done, false otherwise. */
133 bool replace_p;
134 /* True when we replace a reference to old_tree. */
135 bool ref_p;
137 typedef struct ipa_replace_map *ipa_replace_map_p;
138 DEF_VEC_P(ipa_replace_map_p);
139 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
141 struct GTY(()) cgraph_clone_info
143 VEC(ipa_replace_map_p,gc)* tree_map;
144 bitmap args_to_skip;
145 bitmap combined_args_to_skip;
149 /* The cgraph data structure.
150 Each function decl has assigned cgraph_node listing callees and callers. */
152 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
153 tree decl;
154 struct cgraph_edge *callees;
155 struct cgraph_edge *callers;
156 struct cgraph_node *next;
157 struct cgraph_node *previous;
158 /* List of edges representing indirect calls with a yet undetermined
159 callee. */
160 struct cgraph_edge *indirect_calls;
161 /* For nested functions points to function the node is nested in. */
162 struct cgraph_node *origin;
163 /* Points to first nested function, if any. */
164 struct cgraph_node *nested;
165 /* Pointer to the next function with same origin, if any. */
166 struct cgraph_node *next_nested;
167 /* Pointer to the next function in cgraph_nodes_queue. */
168 struct cgraph_node *next_needed;
169 /* Pointer to the next clone. */
170 struct cgraph_node *next_sibling_clone;
171 struct cgraph_node *prev_sibling_clone;
172 struct cgraph_node *clones;
173 struct cgraph_node *clone_of;
174 /* Circular list of nodes in the same comdat group if non-NULL. */
175 struct cgraph_node *same_comdat_group;
176 /* For functions with many calls sites it holds map from call expression
177 to the edge to speed up cgraph_edge function. */
178 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
179 /* Declaration node used to be clone of. */
180 tree former_clone_of;
182 PTR GTY ((skip)) aux;
184 /* Interprocedural passes scheduled to have their transform functions
185 applied next time we execute local pass on them. We maintain it
186 per-function in order to allow IPA passes to introduce new functions. */
187 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
189 struct ipa_ref_list ref_list;
190 struct cgraph_local_info local;
191 struct cgraph_global_info global;
192 struct cgraph_rtl_info rtl;
193 struct cgraph_clone_info clone;
194 struct cgraph_thunk_info thunk;
196 /* Expected number of executions: calculated in profile.c. */
197 gcov_type count;
198 /* How to scale counts at materialization time; used to merge
199 LTO units with different number of profile runs. */
200 int count_materialization_scale;
201 /* Unique id of the node. */
202 int uid;
203 /* Ordering of all cgraph nodes. */
204 int order;
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 aliases created as C++ same body aliases. */
243 unsigned same_body_alias : 1;
244 /* How commonly executed the node is. Initialized during branch
245 probabilities pass. */
246 ENUM_BITFIELD (node_frequency) frequency : 2;
247 /* True when function can only be called at startup (from static ctor). */
248 unsigned only_called_at_startup : 1;
249 /* True when function can only be called at startup (from static dtor). */
250 unsigned only_called_at_exit : 1;
251 /* True when function is the transactional clone of a function which
252 is called only from inside transactions. */
253 /* ?? We should be able to remove this. We have enough bits in
254 cgraph to calculate it. */
255 unsigned tm_clone : 1;
258 typedef struct cgraph_node *cgraph_node_ptr;
260 DEF_VEC_P(cgraph_node_ptr);
261 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
262 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
264 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
265 can appear in multiple sets. */
266 struct cgraph_node_set_def
268 struct pointer_map_t *map;
269 VEC(cgraph_node_ptr, heap) *nodes;
272 typedef struct varpool_node *varpool_node_ptr;
274 DEF_VEC_P(varpool_node_ptr);
275 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
276 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
278 /* A varpool node set is a collection of varpool nodes. A varpool node
279 can appear in multiple sets. */
280 struct varpool_node_set_def
282 struct pointer_map_t * map;
283 VEC(varpool_node_ptr, heap) *nodes;
286 typedef struct cgraph_node_set_def *cgraph_node_set;
288 DEF_VEC_P(cgraph_node_set);
289 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
290 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
292 typedef struct varpool_node_set_def *varpool_node_set;
294 DEF_VEC_P(varpool_node_set);
295 DEF_VEC_ALLOC_P(varpool_node_set,gc);
296 DEF_VEC_ALLOC_P(varpool_node_set,heap);
298 /* Iterator structure for cgraph node sets. */
299 typedef struct
301 cgraph_node_set set;
302 unsigned index;
303 } cgraph_node_set_iterator;
305 /* Iterator structure for varpool node sets. */
306 typedef struct
308 varpool_node_set set;
309 unsigned index;
310 } varpool_node_set_iterator;
312 #define DEFCIFCODE(code, string) CIF_ ## code,
313 /* Reasons for inlining failures. */
314 typedef enum cgraph_inline_failed_enum {
315 #include "cif-code.def"
316 CIF_N_REASONS
317 } cgraph_inline_failed_t;
319 /* Structure containing additional information about an indirect call. */
321 struct GTY(()) cgraph_indirect_call_info
323 /* Offset accumulated from ancestor jump functions of inlined call graph
324 edges. */
325 HOST_WIDE_INT anc_offset;
326 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
327 HOST_WIDE_INT otr_token;
328 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
329 tree otr_type;
330 /* Index of the parameter that is called. */
331 int param_index;
332 /* ECF flags determined from the caller. */
333 int ecf_flags;
335 /* Set when the call is a virtual call with the parameter being the
336 associated object pointer rather than a simple direct call. */
337 unsigned polymorphic : 1;
340 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
341 /* Expected number of executions: calculated in profile.c. */
342 gcov_type count;
343 struct cgraph_node *caller;
344 struct cgraph_node *callee;
345 struct cgraph_edge *prev_caller;
346 struct cgraph_edge *next_caller;
347 struct cgraph_edge *prev_callee;
348 struct cgraph_edge *next_callee;
349 gimple call_stmt;
350 /* Additional information about an indirect call. Not cleared when an edge
351 becomes direct. */
352 struct cgraph_indirect_call_info *indirect_info;
353 PTR GTY ((skip (""))) aux;
354 /* When equal to CIF_OK, inline this call. Otherwise, points to the
355 explanation why function was not inlined. */
356 cgraph_inline_failed_t inline_failed;
357 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
358 when the function is serialized in. */
359 unsigned int lto_stmt_uid;
360 /* Expected frequency of executions within the function.
361 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
362 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
363 int frequency;
364 /* Unique id of the edge. */
365 int uid;
366 /* Whether this edge was made direct by indirect inlining. */
367 unsigned int indirect_inlining_edge : 1;
368 /* Whether this edge describes an indirect call with an undetermined
369 callee. */
370 unsigned int indirect_unknown_callee : 1;
371 /* Whether this edge is still a dangling */
372 /* True if the corresponding CALL stmt cannot be inlined. */
373 unsigned int call_stmt_cannot_inline_p : 1;
374 /* Can this call throw externally? */
375 unsigned int can_throw_external : 1;
378 #define CGRAPH_FREQ_BASE 1000
379 #define CGRAPH_FREQ_MAX 100000
381 typedef struct cgraph_edge *cgraph_edge_p;
383 DEF_VEC_P(cgraph_edge_p);
384 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
386 /* The varpool data structure.
387 Each static variable decl has assigned varpool_node. */
389 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
390 tree decl;
391 /* For aliases points to declaration DECL is alias of. */
392 tree alias_of;
393 /* Pointer to the next function in varpool_nodes. */
394 struct varpool_node *next, *prev;
395 /* Pointer to the next function in varpool_nodes_queue. */
396 struct varpool_node *next_needed, *prev_needed;
397 /* Circular list of nodes in the same comdat group if non-NULL. */
398 struct varpool_node *same_comdat_group;
399 struct ipa_ref_list ref_list;
400 /* File stream where this node is being written to. */
401 struct lto_file_decl_data * lto_file_data;
402 PTR GTY ((skip)) aux;
403 /* Ordering of all cgraph nodes. */
404 int order;
405 enum ld_plugin_symbol_resolution resolution;
407 /* Set when function must be output - it is externally visible
408 or its address is taken. */
409 unsigned needed : 1;
410 /* Needed variables might become dead by optimization. This flag
411 forces the variable to be output even if it appears dead otherwise. */
412 unsigned force_output : 1;
413 /* Set once the variable has been instantiated and its callee
414 lists created. */
415 unsigned analyzed : 1;
416 /* Set once it has been finalized so we consider it to be output. */
417 unsigned finalized : 1;
418 /* Set when variable is scheduled to be assembled. */
419 unsigned output : 1;
420 /* Set when function is visible by other units. */
421 unsigned externally_visible : 1;
422 /* Set for aliases once they got through assemble_alias. Also set for
423 extra name aliases in varpool_extra_name_alias. */
424 unsigned alias : 1;
425 unsigned extra_name_alias : 1;
426 /* Set when variable is used from other LTRANS partition. */
427 unsigned used_from_other_partition : 1;
428 /* Set when variable is available in the other LTRANS partition.
429 During WPA output it is used to mark nodes that are present in
430 multiple partitions. */
431 unsigned in_other_partition : 1;
434 /* Every top level asm statement is put into a cgraph_asm_node. */
436 struct GTY(()) cgraph_asm_node {
437 /* Next asm node. */
438 struct cgraph_asm_node *next;
439 /* String for this asm node. */
440 tree asm_str;
441 /* Ordering of all cgraph nodes. */
442 int order;
445 extern GTY(()) struct cgraph_node *cgraph_nodes;
446 extern GTY(()) int cgraph_n_nodes;
447 extern GTY(()) int cgraph_max_uid;
448 extern GTY(()) int cgraph_edge_max_uid;
449 extern bool cgraph_global_info_ready;
450 enum cgraph_state
452 /* Callgraph is being constructed. It is safe to add new functions. */
453 CGRAPH_STATE_CONSTRUCTION,
454 /* Callgraph is built and IPA passes are being run. */
455 CGRAPH_STATE_IPA,
456 /* Callgraph is built and all functions are transformed to SSA form. */
457 CGRAPH_STATE_IPA_SSA,
458 /* Functions are now ordered and being passed to RTL expanders. */
459 CGRAPH_STATE_EXPANSION,
460 /* All cgraph expansion is done. */
461 CGRAPH_STATE_FINISHED
463 extern enum cgraph_state cgraph_state;
464 extern bool cgraph_function_flags_ready;
465 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
466 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
468 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
469 extern GTY(()) int cgraph_order;
470 extern bool same_body_aliases_done;
472 /* In cgraph.c */
473 void dump_cgraph (FILE *);
474 void debug_cgraph (void);
475 void dump_cgraph_node (FILE *, struct cgraph_node *);
476 void debug_cgraph_node (struct cgraph_node *);
477 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
478 void cgraph_remove_edge (struct cgraph_edge *);
479 void cgraph_remove_node (struct cgraph_node *);
480 void cgraph_add_to_same_comdat_group (struct cgraph_node *, struct cgraph_node *);
481 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
482 void cgraph_release_function_body (struct cgraph_node *);
483 void cgraph_node_remove_callees (struct cgraph_node *node);
484 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
485 struct cgraph_node *,
486 gimple, gcov_type, int);
487 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
488 int, gcov_type, int);
489 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
490 struct cgraph_node * cgraph_get_node (const_tree);
491 struct cgraph_node * cgraph_create_node (tree);
492 struct cgraph_node * cgraph_get_create_node (tree);
493 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
494 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
495 HOST_WIDE_INT, tree, tree);
496 struct cgraph_node *cgraph_node_for_asm (tree);
497 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
498 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
499 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
500 void cgraph_create_edge_including_clones (struct cgraph_node *,
501 struct cgraph_node *,
502 gimple, gimple, gcov_type, int,
503 cgraph_inline_failed_t);
504 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
505 struct cgraph_local_info *cgraph_local_info (tree);
506 struct cgraph_global_info *cgraph_global_info (tree);
507 struct cgraph_rtl_info *cgraph_rtl_info (tree);
508 const char * cgraph_node_name (struct cgraph_node *);
509 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
510 struct cgraph_node *, gimple,
511 unsigned, gcov_type, int, bool);
512 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
513 int, bool, VEC(cgraph_edge_p,heap) *,
514 bool);
515 struct cgraph_node *cgraph_create_function_alias (tree, tree);
517 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
518 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
519 bool cgraph_only_called_directly_p (struct cgraph_node *);
521 struct cgraph_asm_node *cgraph_add_asm_node (tree);
523 bool cgraph_function_possibly_inlined_p (tree);
524 void cgraph_unnest_node (struct cgraph_node *);
526 enum availability cgraph_function_body_availability (struct cgraph_node *);
527 void cgraph_add_new_function (tree, bool);
528 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
529 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
530 VEC(cgraph_edge_p,heap)*,
531 VEC(ipa_replace_map_p,gc)* tree_map,
532 bitmap args_to_skip,
533 const char *clone_name);
535 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
536 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
537 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
538 tree clone_function_name (tree decl, const char *);
539 bool cgraph_node_cannot_return (struct cgraph_node *);
540 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
541 bool cgraph_will_be_removed_from_program_if_no_direct_calls
542 (struct cgraph_node *node);
543 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
544 (struct cgraph_node *node);
545 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
546 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
547 bool cgraph_used_from_object_file_p (struct cgraph_node *);
548 bool varpool_used_from_object_file_p (struct varpool_node *);
549 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
550 bool (*) (struct cgraph_node *, void *),
551 void *,
552 bool);
553 bool cgraph_for_node_and_aliases (struct cgraph_node *,
554 bool (*) (struct cgraph_node *, void *),
555 void *, bool);
556 VEC (cgraph_edge_p, heap) * collect_callers_of_node (struct cgraph_node *node);
559 /* In cgraphunit.c */
560 extern FILE *cgraph_dump_file;
561 void cgraph_finalize_function (tree, bool);
562 void cgraph_mark_if_needed (tree);
563 void cgraph_analyze_function (struct cgraph_node *);
564 void cgraph_finalize_compilation_unit (void);
565 void cgraph_optimize (void);
566 void cgraph_mark_needed_node (struct cgraph_node *);
567 void cgraph_mark_address_taken_node (struct cgraph_node *);
568 void cgraph_mark_reachable_node (struct cgraph_node *);
569 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
570 bool cgraph_preserve_function_body_p (struct cgraph_node *);
571 void verify_cgraph (void);
572 void verify_cgraph_node (struct cgraph_node *);
573 void cgraph_build_static_cdtor (char which, tree body, int priority);
574 void cgraph_reset_static_var_maps (void);
575 void init_cgraph (void);
576 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
577 tree, VEC(cgraph_edge_p,heap)*, bitmap);
578 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
579 VEC(cgraph_edge_p,heap)*,
580 VEC(ipa_replace_map_p,gc)*,
581 bitmap, bitmap, basic_block,
582 const char *);
583 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
584 bitmap, basic_block);
585 void record_references_in_initializer (tree, bool);
586 bool cgraph_process_new_functions (void);
587 void cgraph_process_same_body_aliases (void);
589 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
591 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
592 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
593 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
594 void *);
595 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
596 void *);
597 struct cgraph_edge_hook_list;
598 struct cgraph_node_hook_list;
599 struct cgraph_2edge_hook_list;
600 struct cgraph_2node_hook_list;
601 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
602 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
603 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
604 void *);
605 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
606 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
607 void *);
608 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
609 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
610 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
611 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
612 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
613 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
614 void cgraph_materialize_all_clones (void);
615 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
616 bool cgraph_propagate_frequency (struct cgraph_node *node);
617 /* In cgraphbuild.c */
618 unsigned int rebuild_cgraph_edges (void);
619 void cgraph_rebuild_references (void);
620 void reset_inline_failed (struct cgraph_node *);
621 int compute_call_stmt_bb_frequency (tree, basic_block bb);
623 /* In ipa.c */
624 bool cgraph_remove_unreachable_nodes (bool, FILE *);
625 cgraph_node_set cgraph_node_set_new (void);
626 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
627 struct cgraph_node *);
628 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
629 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
630 void dump_cgraph_node_set (FILE *, cgraph_node_set);
631 void debug_cgraph_node_set (cgraph_node_set);
632 void free_cgraph_node_set (cgraph_node_set);
634 varpool_node_set varpool_node_set_new (void);
635 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
636 struct varpool_node *);
637 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
638 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
639 void dump_varpool_node_set (FILE *, varpool_node_set);
640 void debug_varpool_node_set (varpool_node_set);
641 void free_varpool_node_set (varpool_node_set);
642 void ipa_discover_readonly_nonaddressable_vars (void);
643 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
644 bool varpool_externally_visible_p (struct varpool_node *, bool);
646 /* In predict.c */
647 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
648 bool cgraph_optimize_for_size_p (struct cgraph_node *);
650 /* In varpool.c */
651 extern GTY(()) struct varpool_node *varpool_nodes_queue;
652 extern GTY(()) struct varpool_node *varpool_nodes;
654 struct varpool_node *varpool_node (tree);
655 struct varpool_node *varpool_node_for_asm (tree asmname);
656 void varpool_mark_needed_node (struct varpool_node *);
657 void debug_varpool (void);
658 void dump_varpool (FILE *);
659 void dump_varpool_node (FILE *, struct varpool_node *);
661 void varpool_finalize_decl (tree);
662 bool decide_is_variable_needed (struct varpool_node *, tree);
663 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
664 void cgraph_make_decl_local (tree);
665 void cgraph_make_node_local (struct cgraph_node *);
666 bool cgraph_node_can_be_local_p (struct cgraph_node *);
669 struct varpool_node * varpool_get_node (const_tree decl);
670 void varpool_remove_node (struct varpool_node *node);
671 void varpool_finalize_named_section_flags (struct varpool_node *node);
672 bool varpool_assemble_pending_decls (void);
673 bool varpool_assemble_decl (struct varpool_node *node);
674 bool varpool_analyze_pending_decls (void);
675 void varpool_remove_unreferenced_decls (void);
676 void varpool_empty_needed_queue (void);
677 struct varpool_node * varpool_extra_name_alias (tree, tree);
678 struct varpool_node * varpool_create_variable_alias (tree, tree);
679 const char * varpool_node_name (struct varpool_node *node);
680 void varpool_reset_queue (void);
681 bool const_value_known_p (tree);
682 bool varpool_for_node_and_aliases (struct varpool_node *,
683 bool (*) (struct varpool_node *, void *),
684 void *, bool);
685 void varpool_add_new_variable (tree);
687 /* Walk all reachable static variables. */
688 #define FOR_EACH_STATIC_VARIABLE(node) \
689 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
691 /* Return first reachable static variable with initializer. */
692 static inline struct varpool_node *
693 varpool_first_static_initializer (void)
695 struct varpool_node *node;
696 for (node = varpool_nodes_queue; node; node = node->next_needed)
698 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
699 if (DECL_INITIAL (node->decl))
700 return node;
702 return NULL;
705 /* Return next reachable static variable with initializer after NODE. */
706 static inline struct varpool_node *
707 varpool_next_static_initializer (struct varpool_node *node)
709 for (node = node->next_needed; node; node = node->next_needed)
711 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
712 if (DECL_INITIAL (node->decl))
713 return node;
715 return NULL;
718 /* Walk all static variables with initializer set. */
719 #define FOR_EACH_STATIC_INITIALIZER(node) \
720 for ((node) = varpool_first_static_initializer (); (node); \
721 (node) = varpool_next_static_initializer (node))
723 /* Return first function with body defined. */
724 static inline struct cgraph_node *
725 cgraph_first_defined_function (void)
727 struct cgraph_node *node;
728 for (node = cgraph_nodes; node; node = node->next)
730 if (node->analyzed)
731 return node;
733 return NULL;
736 /* Return next reachable static variable with initializer after NODE. */
737 static inline struct cgraph_node *
738 cgraph_next_defined_function (struct cgraph_node *node)
740 for (node = node->next; node; node = node->next)
742 if (node->analyzed)
743 return node;
745 return NULL;
748 /* Walk all functions with body defined. */
749 #define FOR_EACH_DEFINED_FUNCTION(node) \
750 for ((node) = cgraph_first_defined_function (); (node); \
751 (node) = cgraph_next_defined_function (node))
754 /* Return true when NODE is a function with Gimple body defined
755 in current unit. Functions can also be define externally or they
756 can be thunks with no Gimple representation.
758 Note that at WPA stage, the function body may not be present in memory. */
760 static inline bool
761 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
763 return node->analyzed && !node->thunk.thunk_p && !node->alias;
766 /* Return first function with body defined. */
767 static inline struct cgraph_node *
768 cgraph_first_function_with_gimple_body (void)
770 struct cgraph_node *node;
771 for (node = cgraph_nodes; node; node = node->next)
773 if (cgraph_function_with_gimple_body_p (node))
774 return node;
776 return NULL;
779 /* Return next reachable static variable with initializer after NODE. */
780 static inline struct cgraph_node *
781 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
783 for (node = node->next; node; node = node->next)
785 if (cgraph_function_with_gimple_body_p (node))
786 return node;
788 return NULL;
791 /* Walk all functions with body defined. */
792 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
793 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
794 (node) = cgraph_next_function_with_gimple_body (node))
796 /* Create a new static variable of type TYPE. */
797 tree add_new_static_var (tree type);
799 /* Return true if iterator CSI points to nothing. */
800 static inline bool
801 csi_end_p (cgraph_node_set_iterator csi)
803 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
806 /* Advance iterator CSI. */
807 static inline void
808 csi_next (cgraph_node_set_iterator *csi)
810 csi->index++;
813 /* Return the node pointed to by CSI. */
814 static inline struct cgraph_node *
815 csi_node (cgraph_node_set_iterator csi)
817 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
820 /* Return an iterator to the first node in SET. */
821 static inline cgraph_node_set_iterator
822 csi_start (cgraph_node_set set)
824 cgraph_node_set_iterator csi;
826 csi.set = set;
827 csi.index = 0;
828 return csi;
831 /* Return true if SET contains NODE. */
832 static inline bool
833 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
835 cgraph_node_set_iterator csi;
836 csi = cgraph_node_set_find (set, node);
837 return !csi_end_p (csi);
840 /* Return number of nodes in SET. */
841 static inline size_t
842 cgraph_node_set_size (cgraph_node_set set)
844 return VEC_length (cgraph_node_ptr, set->nodes);
847 /* Return true if iterator VSI points to nothing. */
848 static inline bool
849 vsi_end_p (varpool_node_set_iterator vsi)
851 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
854 /* Advance iterator VSI. */
855 static inline void
856 vsi_next (varpool_node_set_iterator *vsi)
858 vsi->index++;
861 /* Return the node pointed to by VSI. */
862 static inline struct varpool_node *
863 vsi_node (varpool_node_set_iterator vsi)
865 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
868 /* Return an iterator to the first node in SET. */
869 static inline varpool_node_set_iterator
870 vsi_start (varpool_node_set set)
872 varpool_node_set_iterator vsi;
874 vsi.set = set;
875 vsi.index = 0;
876 return vsi;
879 /* Return true if SET contains NODE. */
880 static inline bool
881 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
883 varpool_node_set_iterator vsi;
884 vsi = varpool_node_set_find (set, node);
885 return !vsi_end_p (vsi);
888 /* Return number of nodes in SET. */
889 static inline size_t
890 varpool_node_set_size (varpool_node_set set)
892 return VEC_length (varpool_node_ptr, set->nodes);
895 /* Uniquize all constants that appear in memory.
896 Each constant in memory thus far output is recorded
897 in `const_desc_table'. */
899 struct GTY(()) constant_descriptor_tree {
900 /* A MEM for the constant. */
901 rtx rtl;
903 /* The value of the constant. */
904 tree value;
906 /* Hash of value. Computing the hash from value each time
907 hashfn is called can't work properly, as that means recursive
908 use of the hash table during hash table expansion. */
909 hashval_t hash;
912 /* Return true if set is nonempty. */
913 static inline bool
914 cgraph_node_set_nonempty_p (cgraph_node_set set)
916 return !VEC_empty (cgraph_node_ptr, set->nodes);
919 /* Return true if set is nonempty. */
920 static inline bool
921 varpool_node_set_nonempty_p (varpool_node_set set)
923 return !VEC_empty (varpool_node_ptr, set->nodes);
926 /* Return true when function NODE is only called directly or it has alias.
927 i.e. it is not externally visible, address was not taken and
928 it is not used in any other non-standard way. */
930 static inline bool
931 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
933 gcc_assert (!node->global.inlined_to);
934 return (!node->needed && !node->address_taken
935 && !node->reachable_from_other_partition
936 && !DECL_STATIC_CONSTRUCTOR (node->decl)
937 && !DECL_STATIC_DESTRUCTOR (node->decl)
938 && !node->local.externally_visible);
941 /* Return true when function NODE can be removed from callgraph
942 if all direct calls are eliminated. */
944 static inline bool
945 varpool_can_remove_if_no_refs (struct varpool_node *node)
947 return (!node->force_output && !node->used_from_other_partition
948 && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
949 || DECL_ARTIFICIAL (node->decl))
950 && (DECL_COMDAT (node->decl) || !node->externally_visible));
953 /* Return true when all references to VNODE must be visible in ipa_ref_list.
954 i.e. if the variable is not externally visible or not used in some magic
955 way (asm statement or such).
956 The magic uses are all summarized in force_output flag. */
958 static inline bool
959 varpool_all_refs_explicit_p (struct varpool_node *vnode)
961 return (vnode->analyzed
962 && !vnode->externally_visible
963 && !vnode->used_from_other_partition
964 && !vnode->force_output);
967 /* Constant pool accessor function. */
968 htab_t constant_pool_htab (void);
970 /* FIXME: inappropriate dependency of cgraph on IPA. */
971 #include "ipa-ref-inline.h"
973 /* Return node that alias N is aliasing. */
975 static inline struct cgraph_node *
976 cgraph_alias_aliased_node (struct cgraph_node *n)
978 struct ipa_ref *ref;
980 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
981 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
982 if (ref->refered_type == IPA_REF_CGRAPH)
983 return ipa_ref_node (ref);
984 return NULL;
987 /* Return node that alias N is aliasing. */
989 static inline struct varpool_node *
990 varpool_alias_aliased_node (struct varpool_node *n)
992 struct ipa_ref *ref;
994 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
995 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
996 if (ref->refered_type == IPA_REF_VARPOOL)
997 return ipa_ref_varpool_node (ref);
998 return NULL;
1001 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1002 Walk through thunk, too.
1003 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1005 static inline struct cgraph_node *
1006 cgraph_function_node (struct cgraph_node *node, enum availability *availability)
1008 if (availability)
1009 *availability = cgraph_function_body_availability (node);
1010 while (node)
1012 if (node->alias && node->analyzed)
1013 node = cgraph_alias_aliased_node (node);
1014 else if (node->thunk.thunk_p)
1015 node = node->callees->callee;
1016 else
1017 return node;
1018 if (node && availability)
1020 enum availability a;
1021 a = cgraph_function_body_availability (node);
1022 if (a < *availability)
1023 *availability = a;
1026 if (availability)
1027 *availability = AVAIL_NOT_AVAILABLE;
1028 return NULL;
1031 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1032 Do not walk through thunks.
1033 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1035 static inline struct cgraph_node *
1036 cgraph_function_or_thunk_node (struct cgraph_node *node, enum availability *availability)
1038 if (availability)
1039 *availability = cgraph_function_body_availability (node);
1040 while (node)
1042 if (node->alias && node->analyzed)
1043 node = cgraph_alias_aliased_node (node);
1044 else
1045 return node;
1046 if (node && availability)
1048 enum availability a;
1049 a = cgraph_function_body_availability (node);
1050 if (a < *availability)
1051 *availability = a;
1054 if (availability)
1055 *availability = AVAIL_NOT_AVAILABLE;
1056 return NULL;
1059 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1060 Do not walk through thunks.
1061 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1063 static inline struct varpool_node *
1064 varpool_variable_node (struct varpool_node *node, enum availability *availability)
1066 if (availability)
1067 *availability = cgraph_variable_initializer_availability (node);
1068 while (node)
1070 if (node->alias && node->analyzed)
1071 node = varpool_alias_aliased_node (node);
1072 else
1073 return node;
1074 if (node && availability)
1076 enum availability a;
1077 a = cgraph_variable_initializer_availability (node);
1078 if (a < *availability)
1079 *availability = a;
1082 if (availability)
1083 *availability = AVAIL_NOT_AVAILABLE;
1084 return NULL;
1087 /* Return true when the edge E represents a direct recursion. */
1088 static inline bool
1089 cgraph_edge_recursive_p (struct cgraph_edge *e)
1091 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1092 if (e->caller->global.inlined_to)
1093 return e->caller->global.inlined_to->decl == callee->decl;
1094 else
1095 return e->caller->decl == callee->decl;
1098 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1099 static inline bool
1100 decl_is_tm_clone (const_tree fndecl)
1102 struct cgraph_node *n = cgraph_get_node (fndecl);
1103 if (n)
1104 return n->tm_clone;
1105 return false;
1107 #endif /* GCC_CGRAPH_H */