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