]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cgraph.h
2011-05-03 Stuart Henderson <shenders@gcc.gnu.org>
[thirdparty/gcc.git] / gcc / cgraph.h
CommitLineData
1c4a429a 1/* Callgraph handling code.
7fece979 2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
2bafad93 3 Free Software Foundation, Inc.
1c4a429a
JH
4 Contributed by Jan Hubicka
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
9dcd6f09 10Software Foundation; either version 3, or (at your option) any later
1c4a429a
JH
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
9dcd6f09
NC
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
1c4a429a
JH
21
22#ifndef GCC_CGRAPH_H
23#define GCC_CGRAPH_H
7a8cba34 24
051f8cc6 25#include "plugin-api.h"
7a8cba34 26#include "vec.h"
6674a6ce 27#include "tree.h"
e42922b1 28#include "basic-block.h"
7a8cba34
SB
29#include "function.h"
30#include "ipa-ref.h" /* FIXME: inappropriate dependency of cgraph on IPA. */
1c4a429a 31
6b02a499
JH
32enum availability
33{
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
52};
53
d7f09764
DN
54/* This is the information that is put into the cgraph local structure
55 to recover a function. */
56struct lto_file_decl_data;
57
8a4a83ed 58extern const char * const cgraph_availability_names[];
430c6ceb 59extern const char * const ld_plugin_symbol_resolution_names[];
8a4a83ed 60
6744a6ab
JH
61/* Information about thunk, used only for same body aliases. */
62
63struct 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;
72};
73
dafc5b82 74/* Information about the function collected locally.
25c84396 75 Available after function is analyzed. */
dafc5b82 76
d1b38208 77struct GTY(()) cgraph_local_info {
d7f09764 78 /* File stream where this node is being written to. */
49ba8180 79 struct lto_file_decl_data * lto_file_data;
d7f09764 80
e0bb17a8 81 /* Set when function function is visible in current compilation unit only
e2209b03 82 and its address is never taken. */
b4e19405 83 unsigned local : 1;
6674a6ce 84
e7d6beb0 85 /* Set when function is visible by other units. */
b4e19405 86 unsigned externally_visible : 1;
6d41cd02 87
f6981e16 88 /* Set once it has been finalized so we consider it to be output. */
b4e19405 89 unsigned finalized : 1;
b58b1157 90
61e03ffc
JH
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;
94
95c755e9
JH
95 /* True when the function has been originally extern inline, but it is
96 redefined now. */
b4e19405 97 unsigned redefined_extern_inline : 1;
dafc5b82
JH
98};
99
100/* Information about the function that needs to be computed globally
726a989a 101 once compilation is finished. Available only with -funit-at-a-time. */
dafc5b82 102
d1b38208 103struct GTY(()) cgraph_global_info {
726a989a
RB
104 /* For inline clones this points to the function they will be
105 inlined into. */
18c6ada9 106 struct cgraph_node *inlined_to;
dafc5b82
JH
107};
108
b255a036
JH
109/* Information about the function that is propagated by the RTL backend.
110 Available only for functions that has been already assembled. */
111
d1b38208 112struct GTY(()) cgraph_rtl_info {
17b29c0a 113 unsigned int preferred_incoming_stack_boundary;
b255a036
JH
114};
115
9187e02d
JH
116/* Represent which DECL tree (or reference to such tree)
117 will be replaced by another tree while versioning. */
118struct GTY(()) ipa_replace_map
119{
120 /* The tree that will be replaced. */
121 tree old_tree;
122 /* The new (replacing) tree. */
123 tree new_tree;
922f15c2
JH
124 /* Parameter number to replace, when old_tree is NULL. */
125 int parm_num;
9187e02d
JH
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;
130};
131typedef struct ipa_replace_map *ipa_replace_map_p;
132DEF_VEC_P(ipa_replace_map_p);
133DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
134
135struct GTY(()) cgraph_clone_info
136{
137 VEC(ipa_replace_map_p,gc)* tree_map;
138 bitmap args_to_skip;
08ad1d6d 139 bitmap combined_args_to_skip;
9187e02d
JH
140};
141
5fefcf92 142
ba228239 143/* The cgraph data structure.
e0bb17a8 144 Each function decl has assigned cgraph_node listing callees and callers. */
1c4a429a 145
d1b38208 146struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
1c4a429a
JH
147 tree decl;
148 struct cgraph_edge *callees;
149 struct cgraph_edge *callers;
ed2df68b
JH
150 struct cgraph_node *next;
151 struct cgraph_node *previous;
e33c6cd6
MJ
152 /* List of edges representing indirect calls with a yet undetermined
153 callee. */
154 struct cgraph_edge *indirect_calls;
1c4a429a
JH
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;
8bd87c4e
JH
161 /* Pointer to the next function in cgraph_nodes_queue. */
162 struct cgraph_node *next_needed;
18c6ada9 163 /* Pointer to the next clone. */
9187e02d
JH
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;
6744a6ab
JH
168 /* For normal nodes pointer to the list of alias and thunk nodes,
169 in alias/thunk nodes pointer to the normal node. */
b2583345 170 struct cgraph_node *same_body;
b66887e4
JJ
171 /* Circular list of nodes in the same comdat group if non-NULL. */
172 struct cgraph_node *same_comdat_group;
70d539ce
JH
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;
97ba0040
JH
176 /* Declaration node used to be clone of. */
177 tree former_clone_of;
c22cacf3 178
1431042e 179 PTR GTY ((skip)) aux;
1c4a429a 180
0e3776db
JH
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;
185
369451ec 186 struct ipa_ref_list ref_list;
95c755e9
JH
187 struct cgraph_local_info local;
188 struct cgraph_global_info global;
189 struct cgraph_rtl_info rtl;
9187e02d 190 struct cgraph_clone_info clone;
6744a6ab 191 struct cgraph_thunk_info thunk;
c22cacf3 192
e42922b1
JH
193 /* Expected number of executions: calculated in profile.c. */
194 gcov_type count;
db0bf14f
JH
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;
95c755e9
JH
198 /* Unique id of the node. */
199 int uid;
474eccc6
ILT
200 /* Ordering of all cgraph nodes. */
201 int order;
b4e19405 202
051f8cc6 203 enum ld_plugin_symbol_resolution resolution;
3691626c 204
0e3776db
JH
205 /* Set when function must be output for some reason. The primary
206 use of this flag is to mark functions needed to be output for
207 non-standard reason. Functions that are externally visible
208 or reachable from functions needed to be output are marked
209 by specialized flags. */
b4e19405 210 unsigned needed : 1;
0e3776db
JH
211 /* Set when function has address taken.
212 In current implementation it imply needed flag. */
39ff5a96 213 unsigned address_taken : 1;
6b20f353
DS
214 /* Set when decl is an abstract function pointed to by the
215 ABSTRACT_DECL_ORIGIN of a reachable function. */
216 unsigned abstract_and_needed : 1;
1c4a429a 217 /* Set when function is reachable by call from other function
b8698a0f 218 that is either reachable or needed.
0e3776db
JH
219 This flag is computed at original cgraph construction and then
220 updated in cgraph_remove_unreachable_nodes. Note that after
221 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
222 nodes when they are needed for virtual clone instantiation. */
b4e19405 223 unsigned reachable : 1;
a837268b
JH
224 /* Set when function is reachable by call from other LTRANS partition. */
225 unsigned reachable_from_other_partition : 1;
50674e96 226 /* Set once the function is lowered (i.e. its CFG is built). */
b4e19405 227 unsigned lowered : 1;
25c84396
RH
228 /* Set once the function has been instantiated and its callee
229 lists created. */
b4e19405 230 unsigned analyzed : 1;
92eb4438
JH
231 /* Set when function is available in the other LTRANS partition.
232 During WPA output it is used to mark nodes that are present in
233 multiple partitions. */
a837268b 234 unsigned in_other_partition : 1;
257eb6e3
JH
235 /* Set when function is scheduled to be processed by local passes. */
236 unsigned process : 1;
12527dce 237 /* Set for aliases once they got through assemble_alias. */
b4e19405 238 unsigned alias : 1;
6744a6ab
JH
239 /* Set for alias and thunk nodes, same_body points to the node they are alias
240 of and they are linked through the next/previous pointers. */
b2583345 241 unsigned same_body_alias : 1;
5fefcf92
JH
242 /* How commonly executed the node is. Initialized during branch
243 probabilities pass. */
244 ENUM_BITFIELD (node_frequency) frequency : 2;
844db5d0
JH
245 /* True when function can only be called at startup (from static ctor). */
246 unsigned only_called_at_startup : 1;
247 /* True when function can only be called at startup (from static dtor). */
248 unsigned only_called_at_exit : 1;
1c4a429a
JH
249};
250
fed5ae11
DK
251typedef struct cgraph_node *cgraph_node_ptr;
252
253DEF_VEC_P(cgraph_node_ptr);
254DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
255DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
256
257/* A cgraph node set is a collection of cgraph nodes. A cgraph node
258 can appear in multiple sets. */
d1b38208 259struct GTY(()) cgraph_node_set_def
fed5ae11
DK
260{
261 htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
262 VEC(cgraph_node_ptr, gc) *nodes;
fed5ae11
DK
263};
264
2942c502
JH
265typedef struct varpool_node *varpool_node_ptr;
266
267DEF_VEC_P(varpool_node_ptr);
268DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
269DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
270
271/* A varpool node set is a collection of varpool nodes. A varpool node
272 can appear in multiple sets. */
273struct GTY(()) varpool_node_set_def
274{
275 htab_t GTY((param_is (struct varpool_node_set_element_def))) hashtab;
276 VEC(varpool_node_ptr, gc) *nodes;
2942c502
JH
277};
278
fed5ae11
DK
279typedef struct cgraph_node_set_def *cgraph_node_set;
280
281DEF_VEC_P(cgraph_node_set);
282DEF_VEC_ALLOC_P(cgraph_node_set,gc);
283DEF_VEC_ALLOC_P(cgraph_node_set,heap);
284
2942c502
JH
285typedef struct varpool_node_set_def *varpool_node_set;
286
287DEF_VEC_P(varpool_node_set);
288DEF_VEC_ALLOC_P(varpool_node_set,gc);
289DEF_VEC_ALLOC_P(varpool_node_set,heap);
290
fed5ae11
DK
291/* A cgraph node set element contains an index in the vector of nodes in
292 the set. */
d1b38208 293struct GTY(()) cgraph_node_set_element_def
fed5ae11
DK
294{
295 struct cgraph_node *node;
296 HOST_WIDE_INT index;
297};
298
299typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
300typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
301
302/* Iterator structure for cgraph node sets. */
303typedef struct
304{
305 cgraph_node_set set;
306 unsigned index;
307} cgraph_node_set_iterator;
308
2942c502
JH
309/* A varpool node set element contains an index in the vector of nodes in
310 the set. */
311struct GTY(()) varpool_node_set_element_def
312{
313 struct varpool_node *node;
314 HOST_WIDE_INT index;
315};
316
317typedef struct varpool_node_set_element_def *varpool_node_set_element;
318typedef const struct varpool_node_set_element_def *const_varpool_node_set_element;
319
320/* Iterator structure for varpool node sets. */
321typedef struct
322{
323 varpool_node_set set;
324 unsigned index;
325} varpool_node_set_iterator;
326
61a05df1
JH
327#define DEFCIFCODE(code, string) CIF_ ## code,
328/* Reasons for inlining failures. */
329typedef enum {
330#include "cif-code.def"
331 CIF_N_REASONS
332} cgraph_inline_failed_t;
333
e33c6cd6
MJ
334/* Structure containing additional information about an indirect call. */
335
336struct GTY(()) cgraph_indirect_call_info
337{
b258210c
MJ
338 /* Offset accumulated from ancestor jump functions of inlined call graph
339 edges. */
340 HOST_WIDE_INT anc_offset;
341 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
342 HOST_WIDE_INT otr_token;
ce47fda3
MJ
343 /* Delta by which must be added to this parameter to compensate for a skipped
344 this adjusting thunk. */
345 HOST_WIDE_INT thunk_delta;
b258210c
MJ
346 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
347 tree otr_type;
e33c6cd6
MJ
348 /* Index of the parameter that is called. */
349 int param_index;
5f902d76
JH
350 /* ECF flags determined from the caller. */
351 int ecf_flags;
b258210c
MJ
352
353 /* Set when the call is a virtual call with the parameter being the
354 associated object pointer rather than a simple direct call. */
355 unsigned polymorphic : 1;
e33c6cd6
MJ
356};
357
d1b38208 358struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
6009ee7b
MJ
359 /* Expected number of executions: calculated in profile.c. */
360 gcov_type count;
ed2df68b
JH
361 struct cgraph_node *caller;
362 struct cgraph_node *callee;
2563c224 363 struct cgraph_edge *prev_caller;
1c4a429a 364 struct cgraph_edge *next_caller;
2563c224 365 struct cgraph_edge *prev_callee;
1c4a429a 366 struct cgraph_edge *next_callee;
726a989a 367 gimple call_stmt;
e33c6cd6
MJ
368 /* Additional information about an indirect call. Not cleared when an edge
369 becomes direct. */
370 struct cgraph_indirect_call_info *indirect_info;
18c6ada9 371 PTR GTY ((skip (""))) aux;
61a05df1
JH
372 /* When equal to CIF_OK, inline this call. Otherwise, points to the
373 explanation why function was not inlined. */
374 cgraph_inline_failed_t inline_failed;
6009ee7b
MJ
375 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
376 when the function is serialized in. */
377 unsigned int lto_stmt_uid;
b8698a0f 378 /* Expected frequency of executions within the function.
45a80bb9
JH
379 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
380 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
381 int frequency;
6009ee7b
MJ
382 /* Unique id of the edge. */
383 int uid;
e33c6cd6
MJ
384 /* Whether this edge was made direct by indirect inlining. */
385 unsigned int indirect_inlining_edge : 1;
386 /* Whether this edge describes an indirect call with an undetermined
387 callee. */
388 unsigned int indirect_unknown_callee : 1;
389 /* Whether this edge is still a dangling */
d7f09764
DN
390 /* True if the corresponding CALL stmt cannot be inlined. */
391 unsigned int call_stmt_cannot_inline_p : 1;
2505c5ed
JH
392 /* Can this call throw externally? */
393 unsigned int can_throw_external : 1;
1c4a429a
JH
394};
395
45a80bb9
JH
396#define CGRAPH_FREQ_BASE 1000
397#define CGRAPH_FREQ_MAX 100000
398
b2c0ad40
KH
399typedef struct cgraph_edge *cgraph_edge_p;
400
401DEF_VEC_P(cgraph_edge_p);
402DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
403
8a4a83ed
JH
404/* The varpool data structure.
405 Each static variable decl has assigned varpool_node. */
e69529cd 406
369451ec 407struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
e69529cd 408 tree decl;
8a4a83ed 409 /* Pointer to the next function in varpool_nodes. */
2942c502 410 struct varpool_node *next, *prev;
8a4a83ed 411 /* Pointer to the next function in varpool_nodes_queue. */
2942c502 412 struct varpool_node *next_needed, *prev_needed;
2c71ac78
JM
413 /* For normal nodes a pointer to the first extra name alias. For alias
414 nodes a pointer to the normal node. */
415 struct varpool_node *extra_name;
9f90e80a
JH
416 /* Circular list of nodes in the same comdat group if non-NULL. */
417 struct varpool_node *same_comdat_group;
369451ec 418 struct ipa_ref_list ref_list;
d4c0c9f6
RG
419 /* File stream where this node is being written to. */
420 struct lto_file_decl_data * lto_file_data;
b34fd25c 421 PTR GTY ((skip)) aux;
474eccc6
ILT
422 /* Ordering of all cgraph nodes. */
423 int order;
051f8cc6 424 enum ld_plugin_symbol_resolution resolution;
e69529cd
JH
425
426 /* Set when function must be output - it is externally visible
e2209b03 427 or its address is taken. */
b4e19405 428 unsigned needed : 1;
cd9c7bd2
JH
429 /* Needed variables might become dead by optimization. This flag
430 forces the variable to be output even if it appears dead otherwise. */
b4e19405 431 unsigned force_output : 1;
cd9c7bd2
JH
432 /* Set once the variable has been instantiated and its callee
433 lists created. */
b4e19405 434 unsigned analyzed : 1;
e69529cd 435 /* Set once it has been finalized so we consider it to be output. */
b4e19405 436 unsigned finalized : 1;
6b02a499 437 /* Set when variable is scheduled to be assembled. */
b4e19405 438 unsigned output : 1;
e7d6beb0 439 /* Set when function is visible by other units. */
b4e19405 440 unsigned externally_visible : 1;
2c71ac78
JM
441 /* Set for aliases once they got through assemble_alias. Also set for
442 extra name aliases in varpool_extra_name_alias. */
b4e19405 443 unsigned alias : 1;
2942c502
JH
444 /* Set when variable is used from other LTRANS partition. */
445 unsigned used_from_other_partition : 1;
92eb4438
JH
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. */
2942c502 449 unsigned in_other_partition : 1;
e69529cd
JH
450};
451
474eccc6
ILT
452/* Every top level asm statement is put into a cgraph_asm_node. */
453
d1b38208 454struct GTY(()) cgraph_asm_node {
474eccc6
ILT
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;
461};
462
ed2df68b
JH
463extern GTY(()) struct cgraph_node *cgraph_nodes;
464extern GTY(()) int cgraph_n_nodes;
b58b1157 465extern GTY(()) int cgraph_max_uid;
9088c1cc 466extern GTY(()) int cgraph_edge_max_uid;
dafc5b82 467extern bool cgraph_global_info_ready;
f45e0ad1
JH
468enum cgraph_state
469{
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,
7a388ee4
JH
474 /* Callgraph is built and all functions are transformed to SSA form. */
475 CGRAPH_STATE_IPA_SSA,
f45e0ad1
JH
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
480};
481extern enum cgraph_state cgraph_state;
e7d6beb0 482extern bool cgraph_function_flags_ready;
ed2df68b 483extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
f45e0ad1 484extern GTY(()) struct cgraph_node *cgraph_new_nodes;
1c4a429a 485
474eccc6
ILT
486extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
487extern GTY(()) int cgraph_order;
e69529cd 488
1c4a429a 489/* In cgraph.c */
439f7bc3 490void dump_cgraph (FILE *);
c4e622b6 491void debug_cgraph (void);
18c6ada9 492void dump_cgraph_node (FILE *, struct cgraph_node *);
c4e622b6 493void debug_cgraph_node (struct cgraph_node *);
ea99e0be 494void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
18c6ada9 495void cgraph_remove_edge (struct cgraph_edge *);
439f7bc3 496void cgraph_remove_node (struct cgraph_node *);
9187e02d 497void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
3a40c18a 498void cgraph_release_function_body (struct cgraph_node *);
2563c224 499void cgraph_node_remove_callees (struct cgraph_node *node);
18c6ada9
JH
500struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
501 struct cgraph_node *,
898b8927 502 gimple, gcov_type, int);
ce47fda3 503struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
898b8927 504 int, gcov_type, int);
ce47fda3 505struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
051f8cc6
JH
506struct cgraph_node * cgraph_get_node (const_tree);
507struct cgraph_node * cgraph_get_node_or_alias (const_tree);
a358e188
MJ
508struct cgraph_node * cgraph_create_node (tree);
509struct cgraph_node * cgraph_get_create_node (tree);
87e7b310
JH
510struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
511struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
051f8cc6 512 HOST_WIDE_INT, tree, tree);
b2583345 513void cgraph_remove_same_body_alias (struct cgraph_node *);
4537ec0c 514struct cgraph_node *cgraph_node_for_asm (tree);
726a989a
RB
515struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
516void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
9187e02d
JH
517void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
518void cgraph_create_edge_including_clones (struct cgraph_node *,
519 struct cgraph_node *,
898b8927 520 gimple, gimple, gcov_type, int,
9187e02d 521 cgraph_inline_failed_t);
4b685e14 522void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
439f7bc3
AJ
523struct cgraph_local_info *cgraph_local_info (tree);
524struct cgraph_global_info *cgraph_global_info (tree);
525struct cgraph_rtl_info *cgraph_rtl_info (tree);
526const char * cgraph_node_name (struct cgraph_node *);
c5a4444c 527struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
d7f09764 528 struct cgraph_node *, gimple,
898b8927
JH
529 unsigned, gcov_type, int, bool);
530struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
03ec7d01 531 int, bool, VEC(cgraph_edge_p,heap) *);
1c4a429a 532
18c6ada9 533void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
ce47fda3
MJ
534void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *,
535 HOST_WIDE_INT);
e69529cd 536
474eccc6
ILT
537struct cgraph_asm_node *cgraph_add_asm_node (tree);
538
1bb17c21 539bool cgraph_function_possibly_inlined_p (tree);
e42922b1 540void cgraph_unnest_node (struct cgraph_node *);
1bb17c21 541
6b02a499 542enum availability cgraph_function_body_availability (struct cgraph_node *);
f45e0ad1 543void cgraph_add_new_function (tree, bool);
61a05df1 544const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
9187e02d
JH
545struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
546 VEC(cgraph_edge_p,heap)*,
547 VEC(ipa_replace_map_p,gc)* tree_map,
036546e5
JH
548 bitmap args_to_skip,
549 const char *clone_name);
6b02a499 550
20cdc2be 551void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
530f3a1b
JH
552void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
553void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
036546e5 554tree clone_function_name (tree decl, const char *);
d56026c2
JH
555bool cgraph_node_cannot_return (struct cgraph_node *);
556bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
508e4757
JH
557bool cgraph_will_be_removed_from_program_if_no_direct_calls
558 (struct cgraph_node *node);
559bool cgraph_can_remove_if_no_direct_calls_and_refs_p
560 (struct cgraph_node *node);
051f8cc6
JH
561bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution);
562bool cgraph_used_from_object_file_p (struct cgraph_node *node);
563bool varpool_used_from_object_file_p (struct varpool_node *node);
20cdc2be 564
1c4a429a 565/* In cgraphunit.c */
0a5fa5a1 566extern FILE *cgraph_dump_file;
6b00c969 567void cgraph_finalize_function (tree, bool);
f0c882ab 568void cgraph_mark_if_needed (tree);
322dd859 569void cgraph_analyze_function (struct cgraph_node *);
439f7bc3 570void cgraph_finalize_compilation_unit (void);
d7f09764 571void cgraph_optimize (void);
8dafba3c 572void cgraph_mark_needed_node (struct cgraph_node *);
39ff5a96 573void cgraph_mark_address_taken_node (struct cgraph_node *);
8dafba3c 574void cgraph_mark_reachable_node (struct cgraph_node *);
61a05df1 575bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
85ad2ef5 576bool cgraph_preserve_function_body_p (struct cgraph_node *);
18c6ada9
JH
577void verify_cgraph (void);
578void verify_cgraph_node (struct cgraph_node *);
35b6fdcf 579void cgraph_build_static_cdtor (char which, tree body, int priority);
6674a6ce 580void cgraph_reset_static_var_maps (void);
9b3e897d 581void init_cgraph (void);
57fb5341 582struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
c22cacf3 583 VEC(cgraph_edge_p,heap)*,
9187e02d 584 VEC(ipa_replace_map_p,gc)*,
91382288
JH
585 bitmap, bitmap, basic_block,
586 const char *);
587void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
588 bitmap, basic_block);
625f802c 589void record_references_in_initializer (tree, bool);
f45e0ad1 590bool cgraph_process_new_functions (void);
1c4a429a 591
d7f09764
DN
592bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
593
9088c1cc
MJ
594typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
595typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
596typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
597 void *);
598typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
599 void *);
600struct cgraph_edge_hook_list;
601struct cgraph_node_hook_list;
602struct cgraph_2edge_hook_list;
603struct cgraph_2node_hook_list;
604struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
605void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
606struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
607 void *);
608void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
129a37fc
JH
609struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
610 void *);
611void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
612void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
9088c1cc
MJ
613struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
614void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
615struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
616void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
9187e02d 617void cgraph_materialize_all_clones (void);
8132a837 618gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
fa5f5e27 619bool cgraph_propagate_frequency (struct cgraph_node *node);
917948d3
ZD
620/* In cgraphbuild.c */
621unsigned int rebuild_cgraph_edges (void);
99b766fc 622void cgraph_rebuild_references (void);
d7f09764 623void reset_inline_failed (struct cgraph_node *);
9187e02d 624int compute_call_stmt_bb_frequency (tree, basic_block bb);
917948d3 625
ca31b95f
JH
626/* In ipa.c */
627bool cgraph_remove_unreachable_nodes (bool, FILE *);
fed5ae11
DK
628cgraph_node_set cgraph_node_set_new (void);
629cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
630 struct cgraph_node *);
631void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
632void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
633void dump_cgraph_node_set (FILE *, cgraph_node_set);
634void debug_cgraph_node_set (cgraph_node_set);
635
2942c502
JH
636varpool_node_set varpool_node_set_new (void);
637varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
638 struct varpool_node *);
639void varpool_node_set_add (varpool_node_set, struct varpool_node *);
640void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
641void dump_varpool_node_set (FILE *, varpool_node_set);
642void debug_varpool_node_set (varpool_node_set);
4a444e58 643void ipa_discover_readonly_nonaddressable_vars (void);
430c6ceb 644bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
ca31b95f 645
fed5ae11 646/* In predict.c */
ca30a539 647bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
e6416b30 648bool cgraph_optimize_for_size_p (struct cgraph_node *);
ca30a539 649
8a4a83ed 650/* In varpool.c */
8a4a83ed
JH
651extern GTY(()) struct varpool_node *varpool_nodes_queue;
652extern GTY(()) struct varpool_node *varpool_nodes;
653
654struct varpool_node *varpool_node (tree);
655struct varpool_node *varpool_node_for_asm (tree asmname);
656void varpool_mark_needed_node (struct varpool_node *);
d85478c2 657void debug_varpool (void);
8a4a83ed
JH
658void dump_varpool (FILE *);
659void dump_varpool_node (FILE *, struct varpool_node *);
660
661void varpool_finalize_decl (tree);
662bool decide_is_variable_needed (struct varpool_node *, tree);
663enum availability cgraph_variable_initializer_availability (struct varpool_node *);
715a4e08 664void cgraph_make_decl_local (tree);
a550d677
MJ
665void cgraph_make_node_local (struct cgraph_node *);
666bool cgraph_node_can_be_local_p (struct cgraph_node *);
8a4a83ed 667
2942c502 668
051f8cc6 669struct varpool_node * varpool_get_node (const_tree decl);
2942c502 670void varpool_remove_node (struct varpool_node *node);
7fece979 671void varpool_finalize_named_section_flags (struct varpool_node *node);
8a4a83ed
JH
672bool varpool_assemble_pending_decls (void);
673bool varpool_assemble_decl (struct varpool_node *node);
674bool varpool_analyze_pending_decls (void);
8a4a83ed 675void varpool_remove_unreferenced_decls (void);
7386e3ee 676void varpool_empty_needed_queue (void);
051f8cc6 677struct varpool_node * varpool_extra_name_alias (tree, tree);
a8289259 678const char * varpool_node_name (struct varpool_node *node);
b34fd25c 679void varpool_reset_queue (void);
64e0f5ff 680bool const_value_known_p (tree);
8a4a83ed 681
68e56cc4
JH
682/* Walk all reachable static variables. */
683#define FOR_EACH_STATIC_VARIABLE(node) \
684 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
685
686/* Return first reachable static variable with initializer. */
687static inline struct varpool_node *
688varpool_first_static_initializer (void)
689{
690 struct varpool_node *node;
691 for (node = varpool_nodes_queue; node; node = node->next_needed)
692 {
06795261 693 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
68e56cc4
JH
694 if (DECL_INITIAL (node->decl))
695 return node;
696 }
697 return NULL;
698}
699
700/* Return next reachable static variable with initializer after NODE. */
701static inline struct varpool_node *
702varpool_next_static_initializer (struct varpool_node *node)
703{
704 for (node = node->next_needed; node; node = node->next_needed)
705 {
06795261 706 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
68e56cc4
JH
707 if (DECL_INITIAL (node->decl))
708 return node;
709 }
710 return NULL;
711}
712
713/* Walk all static variables with initializer set. */
714#define FOR_EACH_STATIC_INITIALIZER(node) \
715 for ((node) = varpool_first_static_initializer (); (node); \
716 (node) = varpool_next_static_initializer (node))
717
43d861a5
RL
718/* Create a new static variable of type TYPE. */
719tree add_new_static_var (tree type);
720
fed5ae11
DK
721/* Return true if iterator CSI points to nothing. */
722static inline bool
723csi_end_p (cgraph_node_set_iterator csi)
724{
725 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
726}
727
728/* Advance iterator CSI. */
729static inline void
730csi_next (cgraph_node_set_iterator *csi)
731{
732 csi->index++;
733}
734
735/* Return the node pointed to by CSI. */
736static inline struct cgraph_node *
737csi_node (cgraph_node_set_iterator csi)
738{
739 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
740}
741
742/* Return an iterator to the first node in SET. */
743static inline cgraph_node_set_iterator
744csi_start (cgraph_node_set set)
745{
746 cgraph_node_set_iterator csi;
747
748 csi.set = set;
749 csi.index = 0;
750 return csi;
751}
752
753/* Return true if SET contains NODE. */
754static inline bool
755cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
756{
757 cgraph_node_set_iterator csi;
758 csi = cgraph_node_set_find (set, node);
759 return !csi_end_p (csi);
760}
761
762/* Return number of nodes in SET. */
763static inline size_t
764cgraph_node_set_size (cgraph_node_set set)
765{
766 return htab_elements (set->hashtab);
767}
768
2942c502
JH
769/* Return true if iterator VSI points to nothing. */
770static inline bool
771vsi_end_p (varpool_node_set_iterator vsi)
772{
773 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
774}
775
776/* Advance iterator VSI. */
777static inline void
778vsi_next (varpool_node_set_iterator *vsi)
779{
780 vsi->index++;
781}
782
783/* Return the node pointed to by VSI. */
784static inline struct varpool_node *
785vsi_node (varpool_node_set_iterator vsi)
786{
787 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
788}
789
790/* Return an iterator to the first node in SET. */
791static inline varpool_node_set_iterator
792vsi_start (varpool_node_set set)
793{
794 varpool_node_set_iterator vsi;
795
796 vsi.set = set;
797 vsi.index = 0;
798 return vsi;
799}
800
801/* Return true if SET contains NODE. */
802static inline bool
803varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
804{
805 varpool_node_set_iterator vsi;
806 vsi = varpool_node_set_find (set, node);
807 return !vsi_end_p (vsi);
808}
809
810/* Return number of nodes in SET. */
811static inline size_t
812varpool_node_set_size (varpool_node_set set)
813{
814 return htab_elements (set->hashtab);
815}
816
d48e9cea
OR
817/* Uniquize all constants that appear in memory.
818 Each constant in memory thus far output is recorded
819 in `const_desc_table'. */
820
821struct GTY(()) constant_descriptor_tree {
822 /* A MEM for the constant. */
823 rtx rtl;
b8698a0f 824
d48e9cea
OR
825 /* The value of the constant. */
826 tree value;
827
828 /* Hash of value. Computing the hash from value each time
829 hashfn is called can't work properly, as that means recursive
830 use of the hash table during hash table expansion. */
831 hashval_t hash;
832};
833
ace72c88
JH
834/* Return true if set is nonempty. */
835static inline bool
836cgraph_node_set_nonempty_p (cgraph_node_set set)
837{
9eec9488 838 return !VEC_empty (cgraph_node_ptr, set->nodes);
ace72c88
JH
839}
840
841/* Return true if set is nonempty. */
842static inline bool
843varpool_node_set_nonempty_p (varpool_node_set set)
844{
9eec9488 845 return !VEC_empty (varpool_node_ptr, set->nodes);
ace72c88
JH
846}
847
b20996ff
JH
848/* Return true when function NODE is only called directly.
849 i.e. it is not externally visible, address was not taken and
850 it is not used in any other non-standard way. */
851
852static inline bool
853cgraph_only_called_directly_p (struct cgraph_node *node)
854{
530f3a1b 855 gcc_assert (!node->global.inlined_to);
508e4757
JH
856 return (!node->needed && !node->address_taken
857 && !node->reachable_from_other_partition
858 && !DECL_STATIC_CONSTRUCTOR (node->decl)
859 && !DECL_STATIC_DESTRUCTOR (node->decl)
860 && !node->local.externally_visible);
b20996ff
JH
861}
862
bd3cdcc0
JH
863/* Return true when function NODE can be removed from callgraph
864 if all direct calls are eliminated. */
865
866static inline bool
867cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
868{
530f3a1b
JH
869 /* Extern inlines can always go, we will use the external definition. */
870 if (DECL_EXTERNAL (node->decl))
871 return true;
bd3cdcc0
JH
872 return !node->address_taken && cgraph_can_remove_if_no_direct_calls_and_refs_p (node);
873}
874
df7705b1
JH
875/* Return true when function NODE can be removed from callgraph
876 if all direct calls are eliminated. */
877
878static inline bool
879varpool_can_remove_if_no_refs (struct varpool_node *node)
880{
881 return (!node->force_output && !node->used_from_other_partition
882 && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
883 || DECL_ARTIFICIAL (node->decl))
884 && (DECL_COMDAT (node->decl) || !node->externally_visible));
885}
886
4a444e58
JH
887/* Return true when all references to VNODE must be visible in ipa_ref_list.
888 i.e. if the variable is not externally visible or not used in some magic
889 way (asm statement or such).
61502ca8 890 The magic uses are all summarized in force_output flag. */
4a444e58
JH
891
892static inline bool
893varpool_all_refs_explicit_p (struct varpool_node *vnode)
894{
895 return (!vnode->externally_visible
896 && !vnode->used_from_other_partition
897 && !vnode->force_output);
898}
899
d48e9cea
OR
900/* Constant pool accessor function. */
901htab_t constant_pool_htab (void);
fed5ae11 902
d7d1d041
RG
903/* Return true when the edge E represents a direct recursion. */
904static inline bool
905cgraph_edge_recursive_p (struct cgraph_edge *e)
906{
907 if (e->caller->global.inlined_to)
908 return e->caller->global.inlined_to->decl == e->callee->decl;
909 else
910 return e->caller->decl == e->callee->decl;
911}
912
7a8cba34 913/* FIXME: inappropriate dependency of cgraph on IPA. */
369451ec
JH
914#include "ipa-ref-inline.h"
915
1c4a429a 916#endif /* GCC_CGRAPH_H */