]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cgraph.h
re PR target/48454 (gfortran.dg/char_result_13.f90 fails with -O3 -funroll-loops...
[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;
b66887e4
JJ
168 /* Circular list of nodes in the same comdat group if non-NULL. */
169 struct cgraph_node *same_comdat_group;
70d539ce
JH
170 /* For functions with many calls sites it holds map from call expression
171 to the edge to speed up cgraph_edge function. */
172 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
97ba0040
JH
173 /* Declaration node used to be clone of. */
174 tree former_clone_of;
c22cacf3 175
1431042e 176 PTR GTY ((skip)) aux;
1c4a429a 177
0e3776db
JH
178 /* Interprocedural passes scheduled to have their transform functions
179 applied next time we execute local pass on them. We maintain it
180 per-function in order to allow IPA passes to introduce new functions. */
181 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
182
369451ec 183 struct ipa_ref_list ref_list;
95c755e9
JH
184 struct cgraph_local_info local;
185 struct cgraph_global_info global;
186 struct cgraph_rtl_info rtl;
9187e02d 187 struct cgraph_clone_info clone;
6744a6ab 188 struct cgraph_thunk_info thunk;
c22cacf3 189
e42922b1
JH
190 /* Expected number of executions: calculated in profile.c. */
191 gcov_type count;
db0bf14f
JH
192 /* How to scale counts at materialization time; used to merge
193 LTO units with different number of profile runs. */
194 int count_materialization_scale;
95c755e9
JH
195 /* Unique id of the node. */
196 int uid;
474eccc6
ILT
197 /* Ordering of all cgraph nodes. */
198 int order;
b4e19405 199
051f8cc6 200 enum ld_plugin_symbol_resolution resolution;
3691626c 201
0e3776db
JH
202 /* Set when function must be output for some reason. The primary
203 use of this flag is to mark functions needed to be output for
204 non-standard reason. Functions that are externally visible
205 or reachable from functions needed to be output are marked
206 by specialized flags. */
b4e19405 207 unsigned needed : 1;
0e3776db
JH
208 /* Set when function has address taken.
209 In current implementation it imply needed flag. */
39ff5a96 210 unsigned address_taken : 1;
6b20f353
DS
211 /* Set when decl is an abstract function pointed to by the
212 ABSTRACT_DECL_ORIGIN of a reachable function. */
213 unsigned abstract_and_needed : 1;
1c4a429a 214 /* Set when function is reachable by call from other function
b8698a0f 215 that is either reachable or needed.
0e3776db
JH
216 This flag is computed at original cgraph construction and then
217 updated in cgraph_remove_unreachable_nodes. Note that after
218 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
219 nodes when they are needed for virtual clone instantiation. */
b4e19405 220 unsigned reachable : 1;
a837268b
JH
221 /* Set when function is reachable by call from other LTRANS partition. */
222 unsigned reachable_from_other_partition : 1;
50674e96 223 /* Set once the function is lowered (i.e. its CFG is built). */
b4e19405 224 unsigned lowered : 1;
25c84396
RH
225 /* Set once the function has been instantiated and its callee
226 lists created. */
b4e19405 227 unsigned analyzed : 1;
92eb4438
JH
228 /* Set when function is available in the other LTRANS partition.
229 During WPA output it is used to mark nodes that are present in
230 multiple partitions. */
a837268b 231 unsigned in_other_partition : 1;
257eb6e3
JH
232 /* Set when function is scheduled to be processed by local passes. */
233 unsigned process : 1;
12527dce 234 /* Set for aliases once they got through assemble_alias. */
b4e19405 235 unsigned alias : 1;
39e2db00 236 /* Set for aliases created as C++ same body aliases. */
b2583345 237 unsigned same_body_alias : 1;
5fefcf92
JH
238 /* How commonly executed the node is. Initialized during branch
239 probabilities pass. */
240 ENUM_BITFIELD (node_frequency) frequency : 2;
844db5d0
JH
241 /* True when function can only be called at startup (from static ctor). */
242 unsigned only_called_at_startup : 1;
243 /* True when function can only be called at startup (from static dtor). */
244 unsigned only_called_at_exit : 1;
1c4a429a
JH
245};
246
fed5ae11
DK
247typedef struct cgraph_node *cgraph_node_ptr;
248
249DEF_VEC_P(cgraph_node_ptr);
250DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
251DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
252
253/* A cgraph node set is a collection of cgraph nodes. A cgraph node
254 can appear in multiple sets. */
1cb1a99f 255struct cgraph_node_set_def
fed5ae11 256{
1cb1a99f
JH
257 struct pointer_map_t *map;
258 VEC(cgraph_node_ptr, heap) *nodes;
fed5ae11
DK
259};
260
2942c502
JH
261typedef struct varpool_node *varpool_node_ptr;
262
263DEF_VEC_P(varpool_node_ptr);
264DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
265DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
266
267/* A varpool node set is a collection of varpool nodes. A varpool node
268 can appear in multiple sets. */
1cb1a99f 269struct varpool_node_set_def
2942c502 270{
1cb1a99f
JH
271 struct pointer_map_t * map;
272 VEC(varpool_node_ptr, heap) *nodes;
2942c502
JH
273};
274
fed5ae11
DK
275typedef struct cgraph_node_set_def *cgraph_node_set;
276
277DEF_VEC_P(cgraph_node_set);
278DEF_VEC_ALLOC_P(cgraph_node_set,gc);
279DEF_VEC_ALLOC_P(cgraph_node_set,heap);
280
2942c502
JH
281typedef struct varpool_node_set_def *varpool_node_set;
282
283DEF_VEC_P(varpool_node_set);
284DEF_VEC_ALLOC_P(varpool_node_set,gc);
285DEF_VEC_ALLOC_P(varpool_node_set,heap);
286
fed5ae11
DK
287/* Iterator structure for cgraph node sets. */
288typedef struct
289{
290 cgraph_node_set set;
291 unsigned index;
292} cgraph_node_set_iterator;
293
2942c502
JH
294/* Iterator structure for varpool node sets. */
295typedef struct
296{
297 varpool_node_set set;
298 unsigned index;
299} varpool_node_set_iterator;
300
61a05df1
JH
301#define DEFCIFCODE(code, string) CIF_ ## code,
302/* Reasons for inlining failures. */
533c07c5 303typedef enum cgraph_inline_failed_enum {
61a05df1
JH
304#include "cif-code.def"
305 CIF_N_REASONS
306} cgraph_inline_failed_t;
307
e33c6cd6
MJ
308/* Structure containing additional information about an indirect call. */
309
310struct GTY(()) cgraph_indirect_call_info
311{
b258210c
MJ
312 /* Offset accumulated from ancestor jump functions of inlined call graph
313 edges. */
314 HOST_WIDE_INT anc_offset;
315 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
316 HOST_WIDE_INT otr_token;
ce47fda3
MJ
317 /* Delta by which must be added to this parameter to compensate for a skipped
318 this adjusting thunk. */
319 HOST_WIDE_INT thunk_delta;
b258210c
MJ
320 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
321 tree otr_type;
e33c6cd6
MJ
322 /* Index of the parameter that is called. */
323 int param_index;
5f902d76
JH
324 /* ECF flags determined from the caller. */
325 int ecf_flags;
b258210c
MJ
326
327 /* Set when the call is a virtual call with the parameter being the
328 associated object pointer rather than a simple direct call. */
329 unsigned polymorphic : 1;
e33c6cd6
MJ
330};
331
d1b38208 332struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
6009ee7b
MJ
333 /* Expected number of executions: calculated in profile.c. */
334 gcov_type count;
ed2df68b
JH
335 struct cgraph_node *caller;
336 struct cgraph_node *callee;
2563c224 337 struct cgraph_edge *prev_caller;
1c4a429a 338 struct cgraph_edge *next_caller;
2563c224 339 struct cgraph_edge *prev_callee;
1c4a429a 340 struct cgraph_edge *next_callee;
726a989a 341 gimple call_stmt;
e33c6cd6
MJ
342 /* Additional information about an indirect call. Not cleared when an edge
343 becomes direct. */
344 struct cgraph_indirect_call_info *indirect_info;
18c6ada9 345 PTR GTY ((skip (""))) aux;
61a05df1
JH
346 /* When equal to CIF_OK, inline this call. Otherwise, points to the
347 explanation why function was not inlined. */
348 cgraph_inline_failed_t inline_failed;
6009ee7b
MJ
349 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
350 when the function is serialized in. */
351 unsigned int lto_stmt_uid;
b8698a0f 352 /* Expected frequency of executions within the function.
45a80bb9
JH
353 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
354 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
355 int frequency;
6009ee7b
MJ
356 /* Unique id of the edge. */
357 int uid;
e33c6cd6
MJ
358 /* Whether this edge was made direct by indirect inlining. */
359 unsigned int indirect_inlining_edge : 1;
360 /* Whether this edge describes an indirect call with an undetermined
361 callee. */
362 unsigned int indirect_unknown_callee : 1;
363 /* Whether this edge is still a dangling */
d7f09764
DN
364 /* True if the corresponding CALL stmt cannot be inlined. */
365 unsigned int call_stmt_cannot_inline_p : 1;
2505c5ed
JH
366 /* Can this call throw externally? */
367 unsigned int can_throw_external : 1;
1c4a429a
JH
368};
369
45a80bb9
JH
370#define CGRAPH_FREQ_BASE 1000
371#define CGRAPH_FREQ_MAX 100000
372
b2c0ad40
KH
373typedef struct cgraph_edge *cgraph_edge_p;
374
375DEF_VEC_P(cgraph_edge_p);
376DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
377
8a4a83ed
JH
378/* The varpool data structure.
379 Each static variable decl has assigned varpool_node. */
e69529cd 380
369451ec 381struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
e69529cd 382 tree decl;
8a4a83ed 383 /* Pointer to the next function in varpool_nodes. */
2942c502 384 struct varpool_node *next, *prev;
8a4a83ed 385 /* Pointer to the next function in varpool_nodes_queue. */
2942c502 386 struct varpool_node *next_needed, *prev_needed;
2c71ac78
JM
387 /* For normal nodes a pointer to the first extra name alias. For alias
388 nodes a pointer to the normal node. */
389 struct varpool_node *extra_name;
9f90e80a
JH
390 /* Circular list of nodes in the same comdat group if non-NULL. */
391 struct varpool_node *same_comdat_group;
369451ec 392 struct ipa_ref_list ref_list;
d4c0c9f6
RG
393 /* File stream where this node is being written to. */
394 struct lto_file_decl_data * lto_file_data;
b34fd25c 395 PTR GTY ((skip)) aux;
474eccc6
ILT
396 /* Ordering of all cgraph nodes. */
397 int order;
051f8cc6 398 enum ld_plugin_symbol_resolution resolution;
e69529cd
JH
399
400 /* Set when function must be output - it is externally visible
e2209b03 401 or its address is taken. */
b4e19405 402 unsigned needed : 1;
cd9c7bd2
JH
403 /* Needed variables might become dead by optimization. This flag
404 forces the variable to be output even if it appears dead otherwise. */
b4e19405 405 unsigned force_output : 1;
cd9c7bd2
JH
406 /* Set once the variable has been instantiated and its callee
407 lists created. */
b4e19405 408 unsigned analyzed : 1;
e69529cd 409 /* Set once it has been finalized so we consider it to be output. */
b4e19405 410 unsigned finalized : 1;
6b02a499 411 /* Set when variable is scheduled to be assembled. */
b4e19405 412 unsigned output : 1;
e7d6beb0 413 /* Set when function is visible by other units. */
b4e19405 414 unsigned externally_visible : 1;
2c71ac78
JM
415 /* Set for aliases once they got through assemble_alias. Also set for
416 extra name aliases in varpool_extra_name_alias. */
b4e19405 417 unsigned alias : 1;
2942c502
JH
418 /* Set when variable is used from other LTRANS partition. */
419 unsigned used_from_other_partition : 1;
92eb4438
JH
420 /* Set when variable is available in the other LTRANS partition.
421 During WPA output it is used to mark nodes that are present in
422 multiple partitions. */
2942c502 423 unsigned in_other_partition : 1;
e69529cd
JH
424};
425
474eccc6
ILT
426/* Every top level asm statement is put into a cgraph_asm_node. */
427
d1b38208 428struct GTY(()) cgraph_asm_node {
474eccc6
ILT
429 /* Next asm node. */
430 struct cgraph_asm_node *next;
431 /* String for this asm node. */
432 tree asm_str;
433 /* Ordering of all cgraph nodes. */
434 int order;
435};
436
ed2df68b
JH
437extern GTY(()) struct cgraph_node *cgraph_nodes;
438extern GTY(()) int cgraph_n_nodes;
b58b1157 439extern GTY(()) int cgraph_max_uid;
9088c1cc 440extern GTY(()) int cgraph_edge_max_uid;
dafc5b82 441extern bool cgraph_global_info_ready;
f45e0ad1
JH
442enum cgraph_state
443{
444 /* Callgraph is being constructed. It is safe to add new functions. */
445 CGRAPH_STATE_CONSTRUCTION,
446 /* Callgraph is built and IPA passes are being run. */
447 CGRAPH_STATE_IPA,
7a388ee4
JH
448 /* Callgraph is built and all functions are transformed to SSA form. */
449 CGRAPH_STATE_IPA_SSA,
f45e0ad1
JH
450 /* Functions are now ordered and being passed to RTL expanders. */
451 CGRAPH_STATE_EXPANSION,
452 /* All cgraph expansion is done. */
453 CGRAPH_STATE_FINISHED
454};
455extern enum cgraph_state cgraph_state;
e7d6beb0 456extern bool cgraph_function_flags_ready;
ed2df68b 457extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
f45e0ad1 458extern GTY(()) struct cgraph_node *cgraph_new_nodes;
1c4a429a 459
474eccc6
ILT
460extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
461extern GTY(()) int cgraph_order;
39e2db00 462extern bool same_body_aliases_done;
e69529cd 463
1c4a429a 464/* In cgraph.c */
439f7bc3 465void dump_cgraph (FILE *);
c4e622b6 466void debug_cgraph (void);
18c6ada9 467void dump_cgraph_node (FILE *, struct cgraph_node *);
c4e622b6 468void debug_cgraph_node (struct cgraph_node *);
ea99e0be 469void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
18c6ada9 470void cgraph_remove_edge (struct cgraph_edge *);
439f7bc3 471void cgraph_remove_node (struct cgraph_node *);
9187e02d 472void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
3a40c18a 473void cgraph_release_function_body (struct cgraph_node *);
2563c224 474void cgraph_node_remove_callees (struct cgraph_node *node);
18c6ada9
JH
475struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
476 struct cgraph_node *,
898b8927 477 gimple, gcov_type, int);
ce47fda3 478struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
898b8927 479 int, gcov_type, int);
ce47fda3 480struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
051f8cc6
JH
481struct cgraph_node * cgraph_get_node (const_tree);
482struct cgraph_node * cgraph_get_node_or_alias (const_tree);
a358e188
MJ
483struct cgraph_node * cgraph_create_node (tree);
484struct cgraph_node * cgraph_get_create_node (tree);
87e7b310
JH
485struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
486struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
051f8cc6 487 HOST_WIDE_INT, tree, tree);
4537ec0c 488struct cgraph_node *cgraph_node_for_asm (tree);
726a989a
RB
489struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
490void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
9187e02d
JH
491void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
492void cgraph_create_edge_including_clones (struct cgraph_node *,
493 struct cgraph_node *,
898b8927 494 gimple, gimple, gcov_type, int,
9187e02d 495 cgraph_inline_failed_t);
4b685e14 496void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
439f7bc3
AJ
497struct cgraph_local_info *cgraph_local_info (tree);
498struct cgraph_global_info *cgraph_global_info (tree);
499struct cgraph_rtl_info *cgraph_rtl_info (tree);
500const char * cgraph_node_name (struct cgraph_node *);
c5a4444c 501struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
d7f09764 502 struct cgraph_node *, gimple,
898b8927
JH
503 unsigned, gcov_type, int, bool);
504struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
74605a11
JH
505 int, bool, VEC(cgraph_edge_p,heap) *,
506 bool);
39e2db00 507struct cgraph_node *cgraph_create_function_alias (tree, tree);
1c4a429a 508
18c6ada9 509void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
ce47fda3
MJ
510void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *,
511 HOST_WIDE_INT);
be330ed4 512bool cgraph_only_called_directly_p (struct cgraph_node *);
e69529cd 513
474eccc6
ILT
514struct cgraph_asm_node *cgraph_add_asm_node (tree);
515
1bb17c21 516bool cgraph_function_possibly_inlined_p (tree);
e42922b1 517void cgraph_unnest_node (struct cgraph_node *);
1bb17c21 518
6b02a499 519enum availability cgraph_function_body_availability (struct cgraph_node *);
f45e0ad1 520void cgraph_add_new_function (tree, bool);
61a05df1 521const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
9187e02d
JH
522struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
523 VEC(cgraph_edge_p,heap)*,
524 VEC(ipa_replace_map_p,gc)* tree_map,
036546e5
JH
525 bitmap args_to_skip,
526 const char *clone_name);
6b02a499 527
20cdc2be 528void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
530f3a1b
JH
529void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
530void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
036546e5 531tree clone_function_name (tree decl, const char *);
d56026c2
JH
532bool cgraph_node_cannot_return (struct cgraph_node *);
533bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
508e4757
JH
534bool cgraph_will_be_removed_from_program_if_no_direct_calls
535 (struct cgraph_node *node);
536bool cgraph_can_remove_if_no_direct_calls_and_refs_p
537 (struct cgraph_node *node);
be330ed4
JH
538bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
539bool cgraph_used_from_object_file_p (struct cgraph_node *);
540bool varpool_used_from_object_file_p (struct varpool_node *);
541bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
542 bool (*) (struct cgraph_node *, void *),
543 void *,
544 bool);
545bool cgraph_for_node_and_aliases (struct cgraph_node *,
546 bool (*) (struct cgraph_node *, void *),
547 void *, bool);
548VEC (cgraph_edge_p, heap) * collect_callers_of_node (struct cgraph_node *node);
549
20cdc2be 550
1c4a429a 551/* In cgraphunit.c */
0a5fa5a1 552extern FILE *cgraph_dump_file;
6b00c969 553void cgraph_finalize_function (tree, bool);
f0c882ab 554void cgraph_mark_if_needed (tree);
322dd859 555void cgraph_analyze_function (struct cgraph_node *);
439f7bc3 556void cgraph_finalize_compilation_unit (void);
d7f09764 557void cgraph_optimize (void);
8dafba3c 558void cgraph_mark_needed_node (struct cgraph_node *);
39ff5a96 559void cgraph_mark_address_taken_node (struct cgraph_node *);
8dafba3c 560void cgraph_mark_reachable_node (struct cgraph_node *);
61a05df1 561bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
85ad2ef5 562bool cgraph_preserve_function_body_p (struct cgraph_node *);
18c6ada9
JH
563void verify_cgraph (void);
564void verify_cgraph_node (struct cgraph_node *);
35b6fdcf 565void cgraph_build_static_cdtor (char which, tree body, int priority);
6674a6ce 566void cgraph_reset_static_var_maps (void);
9b3e897d 567void init_cgraph (void);
57fb5341 568struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
c22cacf3 569 VEC(cgraph_edge_p,heap)*,
9187e02d 570 VEC(ipa_replace_map_p,gc)*,
91382288
JH
571 bitmap, bitmap, basic_block,
572 const char *);
573void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
574 bitmap, basic_block);
625f802c 575void record_references_in_initializer (tree, bool);
f45e0ad1 576bool cgraph_process_new_functions (void);
39e2db00 577void cgraph_process_same_body_aliases (void);
1c4a429a 578
d7f09764
DN
579bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
580
9088c1cc
MJ
581typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
582typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
583typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
584 void *);
585typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
586 void *);
587struct cgraph_edge_hook_list;
588struct cgraph_node_hook_list;
589struct cgraph_2edge_hook_list;
590struct cgraph_2node_hook_list;
591struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
592void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
593struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
594 void *);
595void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
129a37fc
JH
596struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
597 void *);
598void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
599void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
9088c1cc
MJ
600struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
601void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
602struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
603void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
9187e02d 604void cgraph_materialize_all_clones (void);
8132a837 605gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
fa5f5e27 606bool cgraph_propagate_frequency (struct cgraph_node *node);
917948d3
ZD
607/* In cgraphbuild.c */
608unsigned int rebuild_cgraph_edges (void);
99b766fc 609void cgraph_rebuild_references (void);
d7f09764 610void reset_inline_failed (struct cgraph_node *);
9187e02d 611int compute_call_stmt_bb_frequency (tree, basic_block bb);
917948d3 612
ca31b95f
JH
613/* In ipa.c */
614bool cgraph_remove_unreachable_nodes (bool, FILE *);
fed5ae11
DK
615cgraph_node_set cgraph_node_set_new (void);
616cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
617 struct cgraph_node *);
618void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
619void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
620void dump_cgraph_node_set (FILE *, cgraph_node_set);
621void debug_cgraph_node_set (cgraph_node_set);
1cb1a99f 622void free_cgraph_node_set (cgraph_node_set);
fed5ae11 623
2942c502
JH
624varpool_node_set varpool_node_set_new (void);
625varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
626 struct varpool_node *);
627void varpool_node_set_add (varpool_node_set, struct varpool_node *);
628void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
629void dump_varpool_node_set (FILE *, varpool_node_set);
630void debug_varpool_node_set (varpool_node_set);
1cb1a99f 631void free_varpool_node_set (varpool_node_set);
4a444e58 632void ipa_discover_readonly_nonaddressable_vars (void);
430c6ceb 633bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
ca31b95f 634
fed5ae11 635/* In predict.c */
ca30a539 636bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
e6416b30 637bool cgraph_optimize_for_size_p (struct cgraph_node *);
ca30a539 638
8a4a83ed 639/* In varpool.c */
8a4a83ed
JH
640extern GTY(()) struct varpool_node *varpool_nodes_queue;
641extern GTY(()) struct varpool_node *varpool_nodes;
642
643struct varpool_node *varpool_node (tree);
644struct varpool_node *varpool_node_for_asm (tree asmname);
645void varpool_mark_needed_node (struct varpool_node *);
d85478c2 646void debug_varpool (void);
8a4a83ed
JH
647void dump_varpool (FILE *);
648void dump_varpool_node (FILE *, struct varpool_node *);
649
650void varpool_finalize_decl (tree);
651bool decide_is_variable_needed (struct varpool_node *, tree);
652enum availability cgraph_variable_initializer_availability (struct varpool_node *);
715a4e08 653void cgraph_make_decl_local (tree);
a550d677
MJ
654void cgraph_make_node_local (struct cgraph_node *);
655bool cgraph_node_can_be_local_p (struct cgraph_node *);
8a4a83ed 656
2942c502 657
051f8cc6 658struct varpool_node * varpool_get_node (const_tree decl);
2942c502 659void varpool_remove_node (struct varpool_node *node);
7fece979 660void varpool_finalize_named_section_flags (struct varpool_node *node);
8a4a83ed
JH
661bool varpool_assemble_pending_decls (void);
662bool varpool_assemble_decl (struct varpool_node *node);
663bool varpool_analyze_pending_decls (void);
8a4a83ed 664void varpool_remove_unreferenced_decls (void);
7386e3ee 665void varpool_empty_needed_queue (void);
051f8cc6 666struct varpool_node * varpool_extra_name_alias (tree, tree);
a8289259 667const char * varpool_node_name (struct varpool_node *node);
b34fd25c 668void varpool_reset_queue (void);
64e0f5ff 669bool const_value_known_p (tree);
8a4a83ed 670
68e56cc4
JH
671/* Walk all reachable static variables. */
672#define FOR_EACH_STATIC_VARIABLE(node) \
673 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
674
675/* Return first reachable static variable with initializer. */
676static inline struct varpool_node *
677varpool_first_static_initializer (void)
678{
679 struct varpool_node *node;
680 for (node = varpool_nodes_queue; node; node = node->next_needed)
681 {
06795261 682 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
68e56cc4
JH
683 if (DECL_INITIAL (node->decl))
684 return node;
685 }
686 return NULL;
687}
688
689/* Return next reachable static variable with initializer after NODE. */
690static inline struct varpool_node *
691varpool_next_static_initializer (struct varpool_node *node)
692{
693 for (node = node->next_needed; node; node = node->next_needed)
694 {
06795261 695 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
68e56cc4
JH
696 if (DECL_INITIAL (node->decl))
697 return node;
698 }
699 return NULL;
700}
701
702/* Walk all static variables with initializer set. */
703#define FOR_EACH_STATIC_INITIALIZER(node) \
704 for ((node) = varpool_first_static_initializer (); (node); \
705 (node) = varpool_next_static_initializer (node))
706
c47d0034
JH
707/* Return first function with body defined. */
708static inline struct cgraph_node *
709cgraph_first_defined_function (void)
710{
711 struct cgraph_node *node;
712 for (node = cgraph_nodes; node; node = node->next)
713 {
714 if (node->analyzed)
715 return node;
716 }
717 return NULL;
718}
719
720/* Return next reachable static variable with initializer after NODE. */
721static inline struct cgraph_node *
722cgraph_next_defined_function (struct cgraph_node *node)
723{
724 for (node = node->next; node; node = node->next)
725 {
726 if (node->analyzed)
727 return node;
728 }
729 return NULL;
730}
731
732/* Walk all functions with body defined. */
733#define FOR_EACH_DEFINED_FUNCTION(node) \
734 for ((node) = cgraph_first_defined_function (); (node); \
735 (node) = cgraph_next_defined_function (node))
736
737
738/* Return true when NODE is a function with Gimple body defined
739 in current unit. Functions can also be define externally or they
740 can be thunks with no Gimple representation.
741
742 Note that at WPA stage, the function body may not be present in memory. */
743
744static inline bool
745cgraph_function_with_gimple_body_p (struct cgraph_node *node)
746{
39e2db00 747 return node->analyzed && !node->thunk.thunk_p && !node->alias;
c47d0034
JH
748}
749
750/* Return first function with body defined. */
751static inline struct cgraph_node *
752cgraph_first_function_with_gimple_body (void)
753{
754 struct cgraph_node *node;
755 for (node = cgraph_nodes; node; node = node->next)
756 {
757 if (cgraph_function_with_gimple_body_p (node))
758 return node;
759 }
760 return NULL;
761}
762
763/* Return next reachable static variable with initializer after NODE. */
764static inline struct cgraph_node *
765cgraph_next_function_with_gimple_body (struct cgraph_node *node)
766{
767 for (node = node->next; node; node = node->next)
768 {
769 if (cgraph_function_with_gimple_body_p (node))
770 return node;
771 }
772 return NULL;
773}
774
775/* Walk all functions with body defined. */
776#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
777 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
778 (node) = cgraph_next_function_with_gimple_body (node))
779
43d861a5
RL
780/* Create a new static variable of type TYPE. */
781tree add_new_static_var (tree type);
782
fed5ae11
DK
783/* Return true if iterator CSI points to nothing. */
784static inline bool
785csi_end_p (cgraph_node_set_iterator csi)
786{
787 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
788}
789
790/* Advance iterator CSI. */
791static inline void
792csi_next (cgraph_node_set_iterator *csi)
793{
794 csi->index++;
795}
796
797/* Return the node pointed to by CSI. */
798static inline struct cgraph_node *
799csi_node (cgraph_node_set_iterator csi)
800{
801 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
802}
803
804/* Return an iterator to the first node in SET. */
805static inline cgraph_node_set_iterator
806csi_start (cgraph_node_set set)
807{
808 cgraph_node_set_iterator csi;
809
810 csi.set = set;
811 csi.index = 0;
812 return csi;
813}
814
815/* Return true if SET contains NODE. */
816static inline bool
817cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
818{
819 cgraph_node_set_iterator csi;
820 csi = cgraph_node_set_find (set, node);
821 return !csi_end_p (csi);
822}
823
824/* Return number of nodes in SET. */
825static inline size_t
826cgraph_node_set_size (cgraph_node_set set)
827{
1cb1a99f 828 return VEC_length (cgraph_node_ptr, set->nodes);
fed5ae11
DK
829}
830
2942c502
JH
831/* Return true if iterator VSI points to nothing. */
832static inline bool
833vsi_end_p (varpool_node_set_iterator vsi)
834{
835 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
836}
837
838/* Advance iterator VSI. */
839static inline void
840vsi_next (varpool_node_set_iterator *vsi)
841{
842 vsi->index++;
843}
844
845/* Return the node pointed to by VSI. */
846static inline struct varpool_node *
847vsi_node (varpool_node_set_iterator vsi)
848{
849 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
850}
851
852/* Return an iterator to the first node in SET. */
853static inline varpool_node_set_iterator
854vsi_start (varpool_node_set set)
855{
856 varpool_node_set_iterator vsi;
857
858 vsi.set = set;
859 vsi.index = 0;
860 return vsi;
861}
862
863/* Return true if SET contains NODE. */
864static inline bool
865varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
866{
867 varpool_node_set_iterator vsi;
868 vsi = varpool_node_set_find (set, node);
869 return !vsi_end_p (vsi);
870}
871
872/* Return number of nodes in SET. */
873static inline size_t
874varpool_node_set_size (varpool_node_set set)
875{
1cb1a99f 876 return VEC_length (varpool_node_ptr, set->nodes);
2942c502
JH
877}
878
d48e9cea
OR
879/* Uniquize all constants that appear in memory.
880 Each constant in memory thus far output is recorded
881 in `const_desc_table'. */
882
883struct GTY(()) constant_descriptor_tree {
884 /* A MEM for the constant. */
885 rtx rtl;
b8698a0f 886
d48e9cea
OR
887 /* The value of the constant. */
888 tree value;
889
890 /* Hash of value. Computing the hash from value each time
891 hashfn is called can't work properly, as that means recursive
892 use of the hash table during hash table expansion. */
893 hashval_t hash;
894};
895
ace72c88
JH
896/* Return true if set is nonempty. */
897static inline bool
898cgraph_node_set_nonempty_p (cgraph_node_set set)
899{
9eec9488 900 return !VEC_empty (cgraph_node_ptr, set->nodes);
ace72c88
JH
901}
902
903/* Return true if set is nonempty. */
904static inline bool
905varpool_node_set_nonempty_p (varpool_node_set set)
906{
9eec9488 907 return !VEC_empty (varpool_node_ptr, set->nodes);
ace72c88
JH
908}
909
be330ed4 910/* Return true when function NODE is only called directly or it has alias.
b20996ff
JH
911 i.e. it is not externally visible, address was not taken and
912 it is not used in any other non-standard way. */
913
914static inline bool
be330ed4 915cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
b20996ff 916{
530f3a1b 917 gcc_assert (!node->global.inlined_to);
508e4757
JH
918 return (!node->needed && !node->address_taken
919 && !node->reachable_from_other_partition
920 && !DECL_STATIC_CONSTRUCTOR (node->decl)
921 && !DECL_STATIC_DESTRUCTOR (node->decl)
922 && !node->local.externally_visible);
b20996ff
JH
923}
924
bd3cdcc0
JH
925/* Return true when function NODE can be removed from callgraph
926 if all direct calls are eliminated. */
927
928static inline bool
929cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
930{
530f3a1b
JH
931 /* Extern inlines can always go, we will use the external definition. */
932 if (DECL_EXTERNAL (node->decl))
933 return true;
be330ed4 934 return (!node->address_taken
39e2db00
JH
935 && cgraph_can_remove_if_no_direct_calls_and_refs_p (node)
936 && !ipa_ref_has_aliases_p (&node->ref_list));
bd3cdcc0
JH
937}
938
df7705b1
JH
939/* Return true when function NODE can be removed from callgraph
940 if all direct calls are eliminated. */
941
942static inline bool
943varpool_can_remove_if_no_refs (struct varpool_node *node)
944{
945 return (!node->force_output && !node->used_from_other_partition
946 && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
947 || DECL_ARTIFICIAL (node->decl))
948 && (DECL_COMDAT (node->decl) || !node->externally_visible));
949}
950
4a444e58
JH
951/* Return true when all references to VNODE must be visible in ipa_ref_list.
952 i.e. if the variable is not externally visible or not used in some magic
953 way (asm statement or such).
61502ca8 954 The magic uses are all summarized in force_output flag. */
4a444e58
JH
955
956static inline bool
957varpool_all_refs_explicit_p (struct varpool_node *vnode)
958{
959 return (!vnode->externally_visible
960 && !vnode->used_from_other_partition
961 && !vnode->force_output);
962}
963
d48e9cea
OR
964/* Constant pool accessor function. */
965htab_t constant_pool_htab (void);
fed5ae11 966
be330ed4
JH
967/* FIXME: inappropriate dependency of cgraph on IPA. */
968#include "ipa-ref-inline.h"
969
39e2db00
JH
970/* Return node that alias N is aliasing. */
971
972static inline struct cgraph_node *
973cgraph_alias_aliased_node (struct cgraph_node *n)
974{
975 struct ipa_ref *ref;
976
977 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
978 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
979 if (ref->refered_type == IPA_REF_CGRAPH)
980 return ipa_ref_node (ref);
981 return NULL;
982}
983
be330ed4
JH
984/* Given NODE, walk the alias chain to return the function NODE is alias of.
985 Walk through thunk, too.
986 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
987
988static inline struct cgraph_node *
989cgraph_function_node (struct cgraph_node *node, enum availability *availability)
990{
991 if (availability)
992 *availability = cgraph_function_body_availability (node);
993 while (node)
994 {
39e2db00
JH
995 if (node->alias && node->analyzed)
996 node = cgraph_alias_aliased_node (node);
997 else if (node->thunk.thunk_p)
be330ed4
JH
998 node = node->callees->callee;
999 else
1000 return node;
39e2db00 1001 if (node && availability)
be330ed4
JH
1002 {
1003 enum availability a;
1004 a = cgraph_function_body_availability (node);
1005 if (a < *availability)
1006 *availability = a;
1007 }
1008 }
39e2db00
JH
1009 if (*availability)
1010 *availability = AVAIL_NOT_AVAILABLE;
be330ed4
JH
1011 return NULL;
1012}
1013
1014/* Given NODE, walk the alias chain to return the function NODE is alias of.
1015 Do not walk through thunks.
1016 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1017
1018static inline struct cgraph_node *
1019cgraph_function_or_thunk_node (struct cgraph_node *node, enum availability *availability)
1020{
1021 if (availability)
1022 *availability = cgraph_function_body_availability (node);
39e2db00
JH
1023 while (node)
1024 {
1025 if (node->alias && node->analyzed)
1026 node = cgraph_alias_aliased_node (node);
1027 else
1028 return node;
1029 if (node && availability)
1030 {
1031 enum availability a;
1032 a = cgraph_function_body_availability (node);
1033 if (a < *availability)
1034 *availability = a;
1035 }
1036 }
1037 if (*availability)
1038 *availability = AVAIL_NOT_AVAILABLE;
be330ed4
JH
1039 return NULL;
1040}
1041
d7d1d041
RG
1042/* Return true when the edge E represents a direct recursion. */
1043static inline bool
1044cgraph_edge_recursive_p (struct cgraph_edge *e)
1045{
be330ed4 1046 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
d7d1d041 1047 if (e->caller->global.inlined_to)
be330ed4 1048 return e->caller->global.inlined_to->decl == callee->decl;
d7d1d041 1049 else
be330ed4 1050 return e->caller->decl == callee->decl;
d7d1d041 1051}
1c4a429a 1052#endif /* GCC_CGRAPH_H */