]>
Commit | Line | Data |
---|---|---|
1c4a429a | 1 | /* Callgraph handling code. |
960bfb69 JH |
2 | Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, |
3 | 2012 Free Software Foundation, Inc. | |
1c4a429a JH |
4 | Contributed by Jan Hubicka |
5 | ||
6 | This file is part of GCC. | |
7 | ||
8 | GCC is free software; you can redistribute it and/or modify it under | |
9 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 10 | Software Foundation; either version 3, or (at your option) any later |
1c4a429a JH |
11 | version. |
12 | ||
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
19 | along 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 | 29 | #include "function.h" |
1f00098b JH |
30 | #include "ipa-ref.h" |
31 | ||
32 | /* Symbol table consists of functions and variables. | |
33 | TODO: add labels, constant pool and aliases. */ | |
34 | enum symtab_type | |
35 | { | |
960bfb69 | 36 | SYMTAB_SYMBOL, |
1f00098b JH |
37 | SYMTAB_FUNCTION, |
38 | SYMTAB_VARIABLE | |
39 | }; | |
40 | ||
41 | /* Base of all entries in the symbol table. | |
42 | The symtab_node is inherited by cgraph and varpol nodes. */ | |
960bfb69 | 43 | struct GTY(()) symtab_node_base |
1f00098b JH |
44 | { |
45 | /* Type of the symbol. */ | |
46 | enum symtab_type type; | |
960bfb69 JH |
47 | tree decl; |
48 | struct ipa_ref_list ref_list; | |
49 | /* Circular list of nodes in the same comdat group if non-NULL. */ | |
50 | symtab_node same_comdat_group; | |
51 | /* Ordering of all symtab entries. */ | |
52 | int order; | |
53 | enum ld_plugin_symbol_resolution resolution; | |
54 | /* File stream where this node is being written to. */ | |
55 | struct lto_file_decl_data * lto_file_data; | |
56 | ||
2aae7680 JH |
57 | /* Linked list of symbol table entries starting with symtab_nodes. */ |
58 | symtab_node next; | |
59 | symtab_node previous; | |
1ab24192 JH |
60 | /* Linked list of symbols with the same asm name. There may be multiple |
61 | entries for single symbol name in the case of LTO resolutions, | |
62 | existence of inline clones, or duplicated declaration. The last case | |
63 | is a long standing bug frontends and builtin handling. */ | |
64 | symtab_node next_sharing_asm_name; | |
65 | symtab_node previous_sharing_asm_name; | |
2aae7680 | 66 | |
960bfb69 JH |
67 | PTR GTY ((skip)) aux; |
68 | ||
69 | /* Set when function has address taken. | |
70 | In current implementation it imply needed flag. */ | |
71 | unsigned address_taken : 1; | |
72 | /* Set when variable is used from other LTRANS partition. */ | |
73 | unsigned used_from_other_partition : 1; | |
74 | /* Set when function is available in the other LTRANS partition. | |
75 | During WPA output it is used to mark nodes that are present in | |
76 | multiple partitions. */ | |
77 | unsigned in_other_partition : 1; | |
78 | /* Set when function is visible by other units. */ | |
79 | unsigned externally_visible : 1; | |
ead84f73 JH |
80 | /* Needed variables might become dead by optimization. This flag |
81 | forces the variable to be output even if it appears dead otherwise. */ | |
82 | unsigned force_output : 1; | |
1f00098b | 83 | }; |
1c4a429a | 84 | |
6b02a499 JH |
85 | enum availability |
86 | { | |
87 | /* Not yet set by cgraph_function_body_availability. */ | |
88 | AVAIL_UNSET, | |
89 | /* Function body/variable initializer is unknown. */ | |
90 | AVAIL_NOT_AVAILABLE, | |
91 | /* Function body/variable initializer is known but might be replaced | |
92 | by a different one from other compilation unit and thus needs to | |
93 | be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have | |
94 | arbitrary side effects on escaping variables and functions, while | |
95 | like AVAILABLE it might access static variables. */ | |
96 | AVAIL_OVERWRITABLE, | |
97 | /* Function body/variable initializer is known and will be used in final | |
98 | program. */ | |
99 | AVAIL_AVAILABLE, | |
100 | /* Function body/variable initializer is known and all it's uses are explicitly | |
101 | visible within current unit (ie it's address is never taken and it is not | |
102 | exported to other units). | |
103 | Currently used only for functions. */ | |
104 | AVAIL_LOCAL | |
105 | }; | |
106 | ||
d7f09764 DN |
107 | /* This is the information that is put into the cgraph local structure |
108 | to recover a function. */ | |
109 | struct lto_file_decl_data; | |
110 | ||
8a4a83ed | 111 | extern const char * const cgraph_availability_names[]; |
430c6ceb | 112 | extern const char * const ld_plugin_symbol_resolution_names[]; |
8a4a83ed | 113 | |
6744a6ab JH |
114 | /* Information about thunk, used only for same body aliases. */ |
115 | ||
116 | struct GTY(()) cgraph_thunk_info { | |
117 | /* Information about the thunk. */ | |
118 | HOST_WIDE_INT fixed_offset; | |
119 | HOST_WIDE_INT virtual_value; | |
120 | tree alias; | |
121 | bool this_adjusting; | |
122 | bool virtual_offset_p; | |
123 | /* Set to true when alias node is thunk. */ | |
124 | bool thunk_p; | |
125 | }; | |
126 | ||
dafc5b82 | 127 | /* Information about the function collected locally. |
25c84396 | 128 | Available after function is analyzed. */ |
dafc5b82 | 129 | |
d1b38208 | 130 | struct GTY(()) cgraph_local_info { |
e0bb17a8 | 131 | /* Set when function function is visible in current compilation unit only |
e2209b03 | 132 | and its address is never taken. */ |
b4e19405 | 133 | unsigned local : 1; |
6674a6ce | 134 | |
f6981e16 | 135 | /* Set once it has been finalized so we consider it to be output. */ |
b4e19405 | 136 | unsigned finalized : 1; |
b58b1157 | 137 | |
124f1be6 MJ |
138 | /* False when there is something makes versioning impossible. */ |
139 | unsigned versionable : 1; | |
140 | ||
61e03ffc JH |
141 | /* False when function calling convention and signature can not be changed. |
142 | This is the case when __builtin_apply_args is used. */ | |
143 | unsigned can_change_signature : 1; | |
144 | ||
95c755e9 JH |
145 | /* True when the function has been originally extern inline, but it is |
146 | redefined now. */ | |
b4e19405 | 147 | unsigned redefined_extern_inline : 1; |
0a35513e AH |
148 | |
149 | /* True if the function may enter serial irrevocable mode. */ | |
150 | unsigned tm_may_enter_irr : 1; | |
dafc5b82 JH |
151 | }; |
152 | ||
153 | /* Information about the function that needs to be computed globally | |
726a989a | 154 | once compilation is finished. Available only with -funit-at-a-time. */ |
dafc5b82 | 155 | |
d1b38208 | 156 | struct GTY(()) cgraph_global_info { |
726a989a RB |
157 | /* For inline clones this points to the function they will be |
158 | inlined into. */ | |
18c6ada9 | 159 | struct cgraph_node *inlined_to; |
dafc5b82 JH |
160 | }; |
161 | ||
b255a036 JH |
162 | /* Information about the function that is propagated by the RTL backend. |
163 | Available only for functions that has been already assembled. */ | |
164 | ||
d1b38208 | 165 | struct GTY(()) cgraph_rtl_info { |
17b29c0a | 166 | unsigned int preferred_incoming_stack_boundary; |
b255a036 JH |
167 | }; |
168 | ||
9187e02d JH |
169 | /* Represent which DECL tree (or reference to such tree) |
170 | will be replaced by another tree while versioning. */ | |
171 | struct GTY(()) ipa_replace_map | |
172 | { | |
173 | /* The tree that will be replaced. */ | |
174 | tree old_tree; | |
175 | /* The new (replacing) tree. */ | |
176 | tree new_tree; | |
922f15c2 JH |
177 | /* Parameter number to replace, when old_tree is NULL. */ |
178 | int parm_num; | |
9187e02d JH |
179 | /* True when a substitution should be done, false otherwise. */ |
180 | bool replace_p; | |
181 | /* True when we replace a reference to old_tree. */ | |
182 | bool ref_p; | |
183 | }; | |
184 | typedef struct ipa_replace_map *ipa_replace_map_p; | |
185 | DEF_VEC_P(ipa_replace_map_p); | |
186 | DEF_VEC_ALLOC_P(ipa_replace_map_p,gc); | |
187 | ||
188 | struct GTY(()) cgraph_clone_info | |
189 | { | |
190 | VEC(ipa_replace_map_p,gc)* tree_map; | |
191 | bitmap args_to_skip; | |
08ad1d6d | 192 | bitmap combined_args_to_skip; |
9187e02d JH |
193 | }; |
194 | ||
5fefcf92 | 195 | |
ba228239 | 196 | /* The cgraph data structure. |
e0bb17a8 | 197 | Each function decl has assigned cgraph_node listing callees and callers. */ |
1c4a429a | 198 | |
960bfb69 JH |
199 | struct GTY(()) cgraph_node { |
200 | struct symtab_node_base symbol; | |
1c4a429a JH |
201 | struct cgraph_edge *callees; |
202 | struct cgraph_edge *callers; | |
e33c6cd6 MJ |
203 | /* List of edges representing indirect calls with a yet undetermined |
204 | callee. */ | |
205 | struct cgraph_edge *indirect_calls; | |
1c4a429a | 206 | /* For nested functions points to function the node is nested in. */ |
960bfb69 JH |
207 | struct cgraph_node * |
208 | GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h"))) | |
209 | origin; | |
1c4a429a | 210 | /* Points to first nested function, if any. */ |
960bfb69 JH |
211 | struct cgraph_node * |
212 | GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h"))) | |
213 | nested; | |
1c4a429a | 214 | /* Pointer to the next function with same origin, if any. */ |
960bfb69 JH |
215 | struct cgraph_node * |
216 | GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h"))) | |
217 | next_nested; | |
8bd87c4e | 218 | /* Pointer to the next function in cgraph_nodes_queue. */ |
960bfb69 JH |
219 | struct cgraph_node * |
220 | GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h"))) | |
221 | next_needed; | |
18c6ada9 | 222 | /* Pointer to the next clone. */ |
9187e02d JH |
223 | struct cgraph_node *next_sibling_clone; |
224 | struct cgraph_node *prev_sibling_clone; | |
225 | struct cgraph_node *clones; | |
226 | struct cgraph_node *clone_of; | |
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 | |
0e3776db JH |
233 | /* Interprocedural passes scheduled to have their transform functions |
234 | applied next time we execute local pass on them. We maintain it | |
235 | per-function in order to allow IPA passes to introduce new functions. */ | |
236 | VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply; | |
237 | ||
95c755e9 JH |
238 | struct cgraph_local_info local; |
239 | struct cgraph_global_info global; | |
240 | struct cgraph_rtl_info rtl; | |
9187e02d | 241 | struct cgraph_clone_info clone; |
6744a6ab | 242 | struct cgraph_thunk_info thunk; |
c22cacf3 | 243 | |
e42922b1 JH |
244 | /* Expected number of executions: calculated in profile.c. */ |
245 | gcov_type count; | |
db0bf14f JH |
246 | /* How to scale counts at materialization time; used to merge |
247 | LTO units with different number of profile runs. */ | |
248 | int count_materialization_scale; | |
95c755e9 JH |
249 | /* Unique id of the node. */ |
250 | int uid; | |
3691626c | 251 | |
6b20f353 DS |
252 | /* Set when decl is an abstract function pointed to by the |
253 | ABSTRACT_DECL_ORIGIN of a reachable function. */ | |
254 | unsigned abstract_and_needed : 1; | |
1c4a429a | 255 | /* Set when function is reachable by call from other function |
b8698a0f | 256 | that is either reachable or needed. |
0e3776db JH |
257 | This flag is computed at original cgraph construction and then |
258 | updated in cgraph_remove_unreachable_nodes. Note that after | |
259 | cgraph_remove_unreachable_nodes cgraph still can contain unreachable | |
260 | nodes when they are needed for virtual clone instantiation. */ | |
b4e19405 | 261 | unsigned reachable : 1; |
50674e96 | 262 | /* Set once the function is lowered (i.e. its CFG is built). */ |
b4e19405 | 263 | unsigned lowered : 1; |
25c84396 RH |
264 | /* Set once the function has been instantiated and its callee |
265 | lists created. */ | |
b4e19405 | 266 | unsigned analyzed : 1; |
257eb6e3 JH |
267 | /* Set when function is scheduled to be processed by local passes. */ |
268 | unsigned process : 1; | |
12527dce | 269 | /* Set for aliases once they got through assemble_alias. */ |
b4e19405 | 270 | unsigned alias : 1; |
39e2db00 | 271 | /* Set for aliases created as C++ same body aliases. */ |
b2583345 | 272 | unsigned same_body_alias : 1; |
5fefcf92 JH |
273 | /* How commonly executed the node is. Initialized during branch |
274 | probabilities pass. */ | |
275 | ENUM_BITFIELD (node_frequency) frequency : 2; | |
844db5d0 JH |
276 | /* True when function can only be called at startup (from static ctor). */ |
277 | unsigned only_called_at_startup : 1; | |
278 | /* True when function can only be called at startup (from static dtor). */ | |
279 | unsigned only_called_at_exit : 1; | |
0a35513e AH |
280 | /* True when function is the transactional clone of a function which |
281 | is called only from inside transactions. */ | |
282 | /* ?? We should be able to remove this. We have enough bits in | |
283 | cgraph to calculate it. */ | |
284 | unsigned tm_clone : 1; | |
1c4a429a JH |
285 | }; |
286 | ||
fed5ae11 DK |
287 | typedef struct cgraph_node *cgraph_node_ptr; |
288 | ||
289 | DEF_VEC_P(cgraph_node_ptr); | |
290 | DEF_VEC_ALLOC_P(cgraph_node_ptr,heap); | |
291 | DEF_VEC_ALLOC_P(cgraph_node_ptr,gc); | |
292 | ||
293 | /* A cgraph node set is a collection of cgraph nodes. A cgraph node | |
294 | can appear in multiple sets. */ | |
1cb1a99f | 295 | struct cgraph_node_set_def |
fed5ae11 | 296 | { |
1cb1a99f JH |
297 | struct pointer_map_t *map; |
298 | VEC(cgraph_node_ptr, heap) *nodes; | |
fed5ae11 DK |
299 | }; |
300 | ||
2942c502 JH |
301 | typedef struct varpool_node *varpool_node_ptr; |
302 | ||
303 | DEF_VEC_P(varpool_node_ptr); | |
304 | DEF_VEC_ALLOC_P(varpool_node_ptr,heap); | |
305 | DEF_VEC_ALLOC_P(varpool_node_ptr,gc); | |
306 | ||
307 | /* A varpool node set is a collection of varpool nodes. A varpool node | |
308 | can appear in multiple sets. */ | |
1cb1a99f | 309 | struct varpool_node_set_def |
2942c502 | 310 | { |
1cb1a99f JH |
311 | struct pointer_map_t * map; |
312 | VEC(varpool_node_ptr, heap) *nodes; | |
2942c502 JH |
313 | }; |
314 | ||
fed5ae11 DK |
315 | typedef struct cgraph_node_set_def *cgraph_node_set; |
316 | ||
317 | DEF_VEC_P(cgraph_node_set); | |
318 | DEF_VEC_ALLOC_P(cgraph_node_set,gc); | |
319 | DEF_VEC_ALLOC_P(cgraph_node_set,heap); | |
320 | ||
2942c502 JH |
321 | typedef struct varpool_node_set_def *varpool_node_set; |
322 | ||
323 | DEF_VEC_P(varpool_node_set); | |
324 | DEF_VEC_ALLOC_P(varpool_node_set,gc); | |
325 | DEF_VEC_ALLOC_P(varpool_node_set,heap); | |
326 | ||
fed5ae11 DK |
327 | /* Iterator structure for cgraph node sets. */ |
328 | typedef struct | |
329 | { | |
330 | cgraph_node_set set; | |
331 | unsigned index; | |
332 | } cgraph_node_set_iterator; | |
333 | ||
2942c502 JH |
334 | /* Iterator structure for varpool node sets. */ |
335 | typedef struct | |
336 | { | |
337 | varpool_node_set set; | |
338 | unsigned index; | |
339 | } varpool_node_set_iterator; | |
340 | ||
61a05df1 JH |
341 | #define DEFCIFCODE(code, string) CIF_ ## code, |
342 | /* Reasons for inlining failures. */ | |
533c07c5 | 343 | typedef enum cgraph_inline_failed_enum { |
61a05df1 JH |
344 | #include "cif-code.def" |
345 | CIF_N_REASONS | |
346 | } cgraph_inline_failed_t; | |
347 | ||
e33c6cd6 MJ |
348 | /* Structure containing additional information about an indirect call. */ |
349 | ||
350 | struct GTY(()) cgraph_indirect_call_info | |
351 | { | |
b258210c MJ |
352 | /* Offset accumulated from ancestor jump functions of inlined call graph |
353 | edges. */ | |
354 | HOST_WIDE_INT anc_offset; | |
355 | /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */ | |
356 | HOST_WIDE_INT otr_token; | |
357 | /* Type of the object from OBJ_TYPE_REF_OBJECT. */ | |
358 | tree otr_type; | |
e33c6cd6 MJ |
359 | /* Index of the parameter that is called. */ |
360 | int param_index; | |
5f902d76 JH |
361 | /* ECF flags determined from the caller. */ |
362 | int ecf_flags; | |
b258210c MJ |
363 | |
364 | /* Set when the call is a virtual call with the parameter being the | |
365 | associated object pointer rather than a simple direct call. */ | |
366 | unsigned polymorphic : 1; | |
e33c6cd6 MJ |
367 | }; |
368 | ||
d1b38208 | 369 | struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge { |
6009ee7b MJ |
370 | /* Expected number of executions: calculated in profile.c. */ |
371 | gcov_type count; | |
ed2df68b JH |
372 | struct cgraph_node *caller; |
373 | struct cgraph_node *callee; | |
2563c224 | 374 | struct cgraph_edge *prev_caller; |
1c4a429a | 375 | struct cgraph_edge *next_caller; |
2563c224 | 376 | struct cgraph_edge *prev_callee; |
1c4a429a | 377 | struct cgraph_edge *next_callee; |
726a989a | 378 | gimple call_stmt; |
e33c6cd6 MJ |
379 | /* Additional information about an indirect call. Not cleared when an edge |
380 | becomes direct. */ | |
381 | struct cgraph_indirect_call_info *indirect_info; | |
18c6ada9 | 382 | PTR GTY ((skip (""))) aux; |
61a05df1 JH |
383 | /* When equal to CIF_OK, inline this call. Otherwise, points to the |
384 | explanation why function was not inlined. */ | |
385 | cgraph_inline_failed_t inline_failed; | |
6009ee7b MJ |
386 | /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt |
387 | when the function is serialized in. */ | |
388 | unsigned int lto_stmt_uid; | |
b8698a0f | 389 | /* Expected frequency of executions within the function. |
45a80bb9 JH |
390 | When set to CGRAPH_FREQ_BASE, the edge is expected to be called once |
391 | per function call. The range is 0 to CGRAPH_FREQ_MAX. */ | |
392 | int frequency; | |
6009ee7b MJ |
393 | /* Unique id of the edge. */ |
394 | int uid; | |
e33c6cd6 MJ |
395 | /* Whether this edge was made direct by indirect inlining. */ |
396 | unsigned int indirect_inlining_edge : 1; | |
397 | /* Whether this edge describes an indirect call with an undetermined | |
398 | callee. */ | |
399 | unsigned int indirect_unknown_callee : 1; | |
400 | /* Whether this edge is still a dangling */ | |
d7f09764 DN |
401 | /* True if the corresponding CALL stmt cannot be inlined. */ |
402 | unsigned int call_stmt_cannot_inline_p : 1; | |
2505c5ed JH |
403 | /* Can this call throw externally? */ |
404 | unsigned int can_throw_external : 1; | |
1c4a429a JH |
405 | }; |
406 | ||
45a80bb9 JH |
407 | #define CGRAPH_FREQ_BASE 1000 |
408 | #define CGRAPH_FREQ_MAX 100000 | |
409 | ||
b2c0ad40 KH |
410 | typedef struct cgraph_edge *cgraph_edge_p; |
411 | ||
412 | DEF_VEC_P(cgraph_edge_p); | |
413 | DEF_VEC_ALLOC_P(cgraph_edge_p,heap); | |
414 | ||
8a4a83ed JH |
415 | /* The varpool data structure. |
416 | Each static variable decl has assigned varpool_node. */ | |
e69529cd | 417 | |
2aae7680 | 418 | struct GTY(()) varpool_node { |
960bfb69 | 419 | struct symtab_node_base symbol; |
cd35bcf7 JH |
420 | /* For aliases points to declaration DECL is alias of. */ |
421 | tree alias_of; | |
8a4a83ed | 422 | /* Pointer to the next function in varpool_nodes_queue. */ |
960bfb69 JH |
423 | struct varpool_node * |
424 | GTY ((nested_ptr (union symtab_node_def, "(struct varpool_node *)(%h)", "(symtab_node)%h"))) | |
425 | next_needed; | |
426 | struct varpool_node * | |
427 | GTY ((nested_ptr (union symtab_node_def, "(struct varpool_node *)(%h)", "(symtab_node)%h"))) | |
428 | prev_needed; | |
e69529cd JH |
429 | |
430 | /* Set when function must be output - it is externally visible | |
e2209b03 | 431 | or its address is taken. */ |
b4e19405 | 432 | unsigned needed : 1; |
cd9c7bd2 JH |
433 | /* Set once the variable has been instantiated and its callee |
434 | lists created. */ | |
b4e19405 | 435 | unsigned analyzed : 1; |
e69529cd | 436 | /* Set once it has been finalized so we consider it to be output. */ |
b4e19405 | 437 | unsigned finalized : 1; |
6b02a499 | 438 | /* Set when variable is scheduled to be assembled. */ |
b4e19405 | 439 | unsigned output : 1; |
2c71ac78 JM |
440 | /* Set for aliases once they got through assemble_alias. Also set for |
441 | extra name aliases in varpool_extra_name_alias. */ | |
b4e19405 | 442 | unsigned alias : 1; |
cd35bcf7 | 443 | unsigned extra_name_alias : 1; |
e69529cd JH |
444 | }; |
445 | ||
474eccc6 ILT |
446 | /* Every top level asm statement is put into a cgraph_asm_node. */ |
447 | ||
d1b38208 | 448 | struct GTY(()) cgraph_asm_node { |
474eccc6 ILT |
449 | /* Next asm node. */ |
450 | struct cgraph_asm_node *next; | |
451 | /* String for this asm node. */ | |
452 | tree asm_str; | |
453 | /* Ordering of all cgraph nodes. */ | |
454 | int order; | |
455 | }; | |
456 | ||
960bfb69 | 457 | /* Symbol table entry. */ |
2aae7680 JH |
458 | union GTY((desc ("%h.symbol.type"), chain_next ("%h.symbol.next"), |
459 | chain_prev ("%h.symbol.previous"))) symtab_node_def { | |
960bfb69 JH |
460 | struct symtab_node_base GTY ((tag ("SYMTAB_SYMBOL"))) symbol; |
461 | /* Use cgraph (symbol) accessor to get cgraph_node. */ | |
462 | struct cgraph_node GTY ((tag ("SYMTAB_FUNCTION"))) x_function; | |
463 | /* Use varpool (symbol) accessor to get varpool_node. */ | |
464 | struct varpool_node GTY ((tag ("SYMTAB_VARIABLE"))) x_variable; | |
465 | }; | |
466 | ||
2aae7680 | 467 | extern GTY(()) symtab_node symtab_nodes; |
ed2df68b | 468 | extern GTY(()) int cgraph_n_nodes; |
b58b1157 | 469 | extern GTY(()) int cgraph_max_uid; |
9088c1cc | 470 | extern GTY(()) int cgraph_edge_max_uid; |
dafc5b82 | 471 | extern bool cgraph_global_info_ready; |
f45e0ad1 JH |
472 | enum cgraph_state |
473 | { | |
474 | /* Callgraph is being constructed. It is safe to add new functions. */ | |
475 | CGRAPH_STATE_CONSTRUCTION, | |
476 | /* Callgraph is built and IPA passes are being run. */ | |
477 | CGRAPH_STATE_IPA, | |
7a388ee4 JH |
478 | /* Callgraph is built and all functions are transformed to SSA form. */ |
479 | CGRAPH_STATE_IPA_SSA, | |
f45e0ad1 JH |
480 | /* Functions are now ordered and being passed to RTL expanders. */ |
481 | CGRAPH_STATE_EXPANSION, | |
482 | /* All cgraph expansion is done. */ | |
483 | CGRAPH_STATE_FINISHED | |
484 | }; | |
485 | extern enum cgraph_state cgraph_state; | |
e7d6beb0 | 486 | extern bool cgraph_function_flags_ready; |
960bfb69 JH |
487 | extern GTY(()) symtab_node x_cgraph_nodes_queue; |
488 | #define cgraph_nodes_queue ((struct cgraph_node *)x_cgraph_nodes_queue) | |
f45e0ad1 | 489 | extern GTY(()) struct cgraph_node *cgraph_new_nodes; |
1c4a429a | 490 | |
474eccc6 | 491 | extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes; |
2aae7680 | 492 | extern GTY(()) int symtab_order; |
39e2db00 | 493 | extern bool same_body_aliases_done; |
e69529cd | 494 | |
2aae7680 JH |
495 | /* In symtab.c */ |
496 | void symtab_register_node (symtab_node); | |
497 | void symtab_unregister_node (symtab_node); | |
498 | void symtab_remove_node (symtab_node); | |
1ab24192 JH |
499 | symtab_node symtab_get_node (const_tree); |
500 | symtab_node symtab_node_for_asm (const_tree asmname); | |
8f940ee6 JH |
501 | const char * symtab_node_asm_name (symtab_node); |
502 | const char * symtab_node_name (symtab_node); | |
1ab24192 | 503 | void symtab_insert_node_to_hashtable (symtab_node); |
8f940ee6 JH |
504 | void dump_symtab (FILE *); |
505 | void debug_symtab (void); | |
506 | void dump_symtab_node (FILE *, symtab_node); | |
507 | void debug_symtab_node (symtab_node); | |
508 | void dump_symtab_base (FILE *, symtab_node); | |
474ffc72 JH |
509 | void verify_symtab (void); |
510 | void verify_symtab_node (symtab_node); | |
511 | bool verify_symtab_base (symtab_node); | |
2aae7680 | 512 | |
1c4a429a | 513 | /* In cgraph.c */ |
439f7bc3 | 514 | void dump_cgraph (FILE *); |
c4e622b6 | 515 | void debug_cgraph (void); |
18c6ada9 | 516 | void dump_cgraph_node (FILE *, struct cgraph_node *); |
c4e622b6 | 517 | void debug_cgraph_node (struct cgraph_node *); |
18c6ada9 | 518 | void cgraph_remove_edge (struct cgraph_edge *); |
439f7bc3 | 519 | void cgraph_remove_node (struct cgraph_node *); |
1ab24192 | 520 | struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *); |
2fda8e14 | 521 | void cgraph_add_to_same_comdat_group (struct cgraph_node *, struct cgraph_node *); |
b4e93f45 | 522 | bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *); |
3a40c18a | 523 | void cgraph_release_function_body (struct cgraph_node *); |
2563c224 | 524 | void cgraph_node_remove_callees (struct cgraph_node *node); |
18c6ada9 JH |
525 | struct cgraph_edge *cgraph_create_edge (struct cgraph_node *, |
526 | struct cgraph_node *, | |
898b8927 | 527 | gimple, gcov_type, int); |
ce47fda3 | 528 | struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple, |
898b8927 | 529 | int, gcov_type, int); |
ce47fda3 | 530 | struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void); |
a358e188 MJ |
531 | struct cgraph_node * cgraph_create_node (tree); |
532 | struct cgraph_node * cgraph_get_create_node (tree); | |
87e7b310 JH |
533 | struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree); |
534 | struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT, | |
051f8cc6 | 535 | HOST_WIDE_INT, tree, tree); |
4537ec0c | 536 | struct cgraph_node *cgraph_node_for_asm (tree); |
726a989a RB |
537 | struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple); |
538 | void cgraph_set_call_stmt (struct cgraph_edge *, gimple); | |
9187e02d JH |
539 | void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple); |
540 | void cgraph_create_edge_including_clones (struct cgraph_node *, | |
541 | struct cgraph_node *, | |
898b8927 | 542 | gimple, gimple, gcov_type, int, |
9187e02d | 543 | cgraph_inline_failed_t); |
4b685e14 | 544 | void cgraph_update_edges_for_call_stmt (gimple, tree, gimple); |
439f7bc3 AJ |
545 | struct cgraph_local_info *cgraph_local_info (tree); |
546 | struct cgraph_global_info *cgraph_global_info (tree); | |
547 | struct cgraph_rtl_info *cgraph_rtl_info (tree); | |
c5a4444c | 548 | struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *, |
d7f09764 | 549 | struct cgraph_node *, gimple, |
898b8927 JH |
550 | unsigned, gcov_type, int, bool); |
551 | struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type, | |
74605a11 JH |
552 | int, bool, VEC(cgraph_edge_p,heap) *, |
553 | bool); | |
39e2db00 | 554 | struct cgraph_node *cgraph_create_function_alias (tree, tree); |
b0d0a291 PM |
555 | void cgraph_call_node_duplication_hooks (struct cgraph_node *node1, |
556 | struct cgraph_node *node2); | |
1c4a429a | 557 | |
18c6ada9 | 558 | void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *); |
81fa35bd | 559 | void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *); |
be330ed4 | 560 | bool cgraph_only_called_directly_p (struct cgraph_node *); |
e69529cd | 561 | |
474eccc6 ILT |
562 | struct cgraph_asm_node *cgraph_add_asm_node (tree); |
563 | ||
1bb17c21 | 564 | bool cgraph_function_possibly_inlined_p (tree); |
e42922b1 | 565 | void cgraph_unnest_node (struct cgraph_node *); |
1bb17c21 | 566 | |
6b02a499 | 567 | enum availability cgraph_function_body_availability (struct cgraph_node *); |
f45e0ad1 | 568 | void cgraph_add_new_function (tree, bool); |
61a05df1 | 569 | const char* cgraph_inline_failed_string (cgraph_inline_failed_t); |
9187e02d JH |
570 | struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node, |
571 | VEC(cgraph_edge_p,heap)*, | |
572 | VEC(ipa_replace_map_p,gc)* tree_map, | |
036546e5 JH |
573 | bitmap args_to_skip, |
574 | const char *clone_name); | |
6b02a499 | 575 | |
20cdc2be | 576 | void cgraph_set_nothrow_flag (struct cgraph_node *, bool); |
530f3a1b JH |
577 | void cgraph_set_const_flag (struct cgraph_node *, bool, bool); |
578 | void cgraph_set_pure_flag (struct cgraph_node *, bool, bool); | |
036546e5 | 579 | tree clone_function_name (tree decl, const char *); |
d56026c2 JH |
580 | bool cgraph_node_cannot_return (struct cgraph_node *); |
581 | bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *); | |
508e4757 JH |
582 | bool cgraph_will_be_removed_from_program_if_no_direct_calls |
583 | (struct cgraph_node *node); | |
584 | bool cgraph_can_remove_if_no_direct_calls_and_refs_p | |
585 | (struct cgraph_node *node); | |
9aa3f5c5 | 586 | bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node); |
be330ed4 JH |
587 | bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution); |
588 | bool cgraph_used_from_object_file_p (struct cgraph_node *); | |
589 | bool varpool_used_from_object_file_p (struct varpool_node *); | |
590 | bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *, | |
591 | bool (*) (struct cgraph_node *, void *), | |
592 | void *, | |
593 | bool); | |
594 | bool cgraph_for_node_and_aliases (struct cgraph_node *, | |
595 | bool (*) (struct cgraph_node *, void *), | |
596 | void *, bool); | |
597 | VEC (cgraph_edge_p, heap) * collect_callers_of_node (struct cgraph_node *node); | |
598 | ||
20cdc2be | 599 | |
1c4a429a | 600 | /* In cgraphunit.c */ |
0a5fa5a1 | 601 | extern FILE *cgraph_dump_file; |
6b00c969 | 602 | void cgraph_finalize_function (tree, bool); |
f0c882ab | 603 | void cgraph_mark_if_needed (tree); |
322dd859 | 604 | void cgraph_analyze_function (struct cgraph_node *); |
439f7bc3 | 605 | void cgraph_finalize_compilation_unit (void); |
d7f09764 | 606 | void cgraph_optimize (void); |
ead84f73 | 607 | void cgraph_mark_force_output_node (struct cgraph_node *); |
39ff5a96 | 608 | void cgraph_mark_address_taken_node (struct cgraph_node *); |
8dafba3c | 609 | void cgraph_mark_reachable_node (struct cgraph_node *); |
61a05df1 | 610 | bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason); |
85ad2ef5 | 611 | bool cgraph_preserve_function_body_p (struct cgraph_node *); |
18c6ada9 JH |
612 | void verify_cgraph (void); |
613 | void verify_cgraph_node (struct cgraph_node *); | |
35b6fdcf | 614 | void cgraph_build_static_cdtor (char which, tree body, int priority); |
6674a6ce | 615 | void cgraph_reset_static_var_maps (void); |
9b3e897d | 616 | void init_cgraph (void); |
0a35513e AH |
617 | struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *, |
618 | tree, VEC(cgraph_edge_p,heap)*, bitmap); | |
57fb5341 | 619 | struct cgraph_node *cgraph_function_versioning (struct cgraph_node *, |
c22cacf3 | 620 | VEC(cgraph_edge_p,heap)*, |
9187e02d | 621 | VEC(ipa_replace_map_p,gc)*, |
1a2c27e9 EB |
622 | bitmap, bool, bitmap, |
623 | basic_block, const char *); | |
624 | void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, | |
625 | bool, bitmap, bool, bitmap, basic_block); | |
625f802c | 626 | void record_references_in_initializer (tree, bool); |
f45e0ad1 | 627 | bool cgraph_process_new_functions (void); |
39e2db00 | 628 | void cgraph_process_same_body_aliases (void); |
1c4a429a | 629 | |
d7f09764 DN |
630 | bool cgraph_decide_is_function_needed (struct cgraph_node *, tree); |
631 | ||
9088c1cc MJ |
632 | typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *); |
633 | typedef void (*cgraph_node_hook)(struct cgraph_node *, void *); | |
634 | typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *, | |
635 | void *); | |
636 | typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *, | |
637 | void *); | |
638 | struct cgraph_edge_hook_list; | |
639 | struct cgraph_node_hook_list; | |
640 | struct cgraph_2edge_hook_list; | |
641 | struct cgraph_2node_hook_list; | |
642 | struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *); | |
643 | void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *); | |
644 | struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook, | |
645 | void *); | |
646 | void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *); | |
129a37fc JH |
647 | struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook, |
648 | void *); | |
649 | void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *); | |
650 | void cgraph_call_function_insertion_hooks (struct cgraph_node *node); | |
9088c1cc MJ |
651 | struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *); |
652 | void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *); | |
653 | struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *); | |
654 | void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *); | |
8132a837 | 655 | gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *); |
fa5f5e27 | 656 | bool cgraph_propagate_frequency (struct cgraph_node *node); |
917948d3 ZD |
657 | /* In cgraphbuild.c */ |
658 | unsigned int rebuild_cgraph_edges (void); | |
99b766fc | 659 | void cgraph_rebuild_references (void); |
9187e02d | 660 | int compute_call_stmt_bb_frequency (tree, basic_block bb); |
917948d3 | 661 | |
ca31b95f JH |
662 | /* In ipa.c */ |
663 | bool cgraph_remove_unreachable_nodes (bool, FILE *); | |
fed5ae11 DK |
664 | cgraph_node_set cgraph_node_set_new (void); |
665 | cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set, | |
666 | struct cgraph_node *); | |
667 | void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *); | |
668 | void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *); | |
669 | void dump_cgraph_node_set (FILE *, cgraph_node_set); | |
670 | void debug_cgraph_node_set (cgraph_node_set); | |
1cb1a99f | 671 | void free_cgraph_node_set (cgraph_node_set); |
fed5ae11 | 672 | |
2942c502 JH |
673 | varpool_node_set varpool_node_set_new (void); |
674 | varpool_node_set_iterator varpool_node_set_find (varpool_node_set, | |
675 | struct varpool_node *); | |
676 | void varpool_node_set_add (varpool_node_set, struct varpool_node *); | |
677 | void varpool_node_set_remove (varpool_node_set, struct varpool_node *); | |
678 | void dump_varpool_node_set (FILE *, varpool_node_set); | |
679 | void debug_varpool_node_set (varpool_node_set); | |
1cb1a99f | 680 | void free_varpool_node_set (varpool_node_set); |
4a444e58 | 681 | void ipa_discover_readonly_nonaddressable_vars (void); |
430c6ceb | 682 | bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *); |
38877e98 | 683 | bool varpool_externally_visible_p (struct varpool_node *, bool); |
ca31b95f | 684 | |
fed5ae11 | 685 | /* In predict.c */ |
ca30a539 | 686 | bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e); |
e6416b30 | 687 | bool cgraph_optimize_for_size_p (struct cgraph_node *); |
ca30a539 | 688 | |
8a4a83ed | 689 | /* In varpool.c */ |
960bfb69 | 690 | extern GTY(()) symtab_node x_varpool_nodes_queue; |
960bfb69 | 691 | #define varpool_nodes_queue ((struct varpool_node *)x_varpool_nodes_queue) |
8a4a83ed JH |
692 | |
693 | struct varpool_node *varpool_node (tree); | |
694 | struct varpool_node *varpool_node_for_asm (tree asmname); | |
695 | void varpool_mark_needed_node (struct varpool_node *); | |
d85478c2 | 696 | void debug_varpool (void); |
8a4a83ed JH |
697 | void dump_varpool (FILE *); |
698 | void dump_varpool_node (FILE *, struct varpool_node *); | |
699 | ||
700 | void varpool_finalize_decl (tree); | |
701 | bool decide_is_variable_needed (struct varpool_node *, tree); | |
702 | enum availability cgraph_variable_initializer_availability (struct varpool_node *); | |
715a4e08 | 703 | void cgraph_make_decl_local (tree); |
a550d677 MJ |
704 | void cgraph_make_node_local (struct cgraph_node *); |
705 | bool cgraph_node_can_be_local_p (struct cgraph_node *); | |
8a4a83ed | 706 | |
2942c502 | 707 | |
2942c502 | 708 | void varpool_remove_node (struct varpool_node *node); |
7fece979 | 709 | void varpool_finalize_named_section_flags (struct varpool_node *node); |
8a4a83ed JH |
710 | bool varpool_assemble_pending_decls (void); |
711 | bool varpool_assemble_decl (struct varpool_node *node); | |
712 | bool varpool_analyze_pending_decls (void); | |
8a4a83ed | 713 | void varpool_remove_unreferenced_decls (void); |
7386e3ee | 714 | void varpool_empty_needed_queue (void); |
051f8cc6 | 715 | struct varpool_node * varpool_extra_name_alias (tree, tree); |
cd35bcf7 | 716 | struct varpool_node * varpool_create_variable_alias (tree, tree); |
b34fd25c | 717 | void varpool_reset_queue (void); |
64e0f5ff | 718 | bool const_value_known_p (tree); |
cd35bcf7 JH |
719 | bool varpool_for_node_and_aliases (struct varpool_node *, |
720 | bool (*) (struct varpool_node *, void *), | |
721 | void *, bool); | |
38877e98 | 722 | void varpool_add_new_variable (tree); |
8a4a83ed | 723 | |
2aae7680 JH |
724 | /* Return true when NODE is function. */ |
725 | static inline bool | |
726 | symtab_function_p (symtab_node node) | |
727 | { | |
728 | return node->symbol.type == SYMTAB_FUNCTION; | |
729 | } | |
730 | ||
731 | /* Return true when NODE is variable. */ | |
732 | static inline bool | |
733 | symtab_variable_p (symtab_node node) | |
734 | { | |
735 | return node->symbol.type == SYMTAB_VARIABLE; | |
736 | } | |
68e56cc4 | 737 | |
1f00098b JH |
738 | /* Return callgraph node for given symbol and check it is a function. */ |
739 | static inline struct cgraph_node * | |
960bfb69 | 740 | cgraph (symtab_node node) |
1f00098b | 741 | { |
960bfb69 | 742 | gcc_checking_assert (!node || node->symbol.type == SYMTAB_FUNCTION); |
1ab24192 | 743 | return (struct cgraph_node *)node; |
1f00098b JH |
744 | } |
745 | ||
746 | /* Return varpool node for given symbol and check it is a variable. */ | |
747 | static inline struct varpool_node * | |
960bfb69 | 748 | varpool (symtab_node node) |
1f00098b | 749 | { |
960bfb69 | 750 | gcc_checking_assert (!node || node->symbol.type == SYMTAB_VARIABLE); |
1ab24192 | 751 | return (struct varpool_node *)node; |
1f00098b JH |
752 | } |
753 | ||
1ab24192 JH |
754 | /* Return callgraph node for given symbol and check it is a function. */ |
755 | static inline struct cgraph_node * | |
756 | cgraph_get_node (const_tree decl) | |
757 | { | |
758 | gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL); | |
759 | return cgraph (symtab_get_node (decl)); | |
760 | } | |
761 | ||
762 | /* Return varpool node for given symbol and check it is a function. */ | |
763 | static inline struct varpool_node * | |
764 | varpool_get_node (const_tree decl) | |
765 | { | |
766 | gcc_checking_assert (TREE_CODE (decl) == VAR_DECL); | |
767 | return varpool (symtab_get_node (decl)); | |
768 | } | |
769 | ||
8f940ee6 JH |
770 | /* Return asm name of cgraph node. */ |
771 | static inline const char * | |
772 | cgraph_node_asm_name(struct cgraph_node *node) | |
773 | { | |
774 | return symtab_node_asm_name ((symtab_node)node); | |
775 | } | |
776 | ||
777 | /* Return asm name of varpool node. */ | |
778 | static inline const char * | |
779 | varpool_node_asm_name(struct varpool_node *node) | |
780 | { | |
781 | return symtab_node_asm_name ((symtab_node)node); | |
782 | } | |
783 | ||
784 | /* Return name of cgraph node. */ | |
785 | static inline const char * | |
786 | cgraph_node_name(struct cgraph_node *node) | |
787 | { | |
788 | return symtab_node_name ((symtab_node)node); | |
789 | } | |
790 | ||
791 | /* Return name of varpool node. */ | |
792 | static inline const char * | |
793 | varpool_node_name(struct varpool_node *node) | |
794 | { | |
795 | return symtab_node_name ((symtab_node)node); | |
796 | } | |
797 | ||
1ab24192 JH |
798 | /* Walk all symbols. */ |
799 | #define FOR_EACH_SYMBOL(node) \ | |
800 | for ((node) = symtab_nodes; (node); (node) = (node)->symbol.next) | |
1f00098b | 801 | |
68e56cc4 JH |
802 | /* Return first reachable static variable with initializer. */ |
803 | static inline struct varpool_node * | |
804 | varpool_first_static_initializer (void) | |
805 | { | |
806 | struct varpool_node *node; | |
807 | for (node = varpool_nodes_queue; node; node = node->next_needed) | |
808 | { | |
960bfb69 JH |
809 | gcc_checking_assert (TREE_CODE (node->symbol.decl) == VAR_DECL); |
810 | if (DECL_INITIAL (node->symbol.decl)) | |
68e56cc4 JH |
811 | return node; |
812 | } | |
813 | return NULL; | |
814 | } | |
815 | ||
816 | /* Return next reachable static variable with initializer after NODE. */ | |
817 | static inline struct varpool_node * | |
818 | varpool_next_static_initializer (struct varpool_node *node) | |
819 | { | |
820 | for (node = node->next_needed; node; node = node->next_needed) | |
821 | { | |
960bfb69 JH |
822 | gcc_checking_assert (TREE_CODE (node->symbol.decl) == VAR_DECL); |
823 | if (DECL_INITIAL (node->symbol.decl)) | |
68e56cc4 JH |
824 | return node; |
825 | } | |
826 | return NULL; | |
827 | } | |
828 | ||
2aae7680 JH |
829 | /* Walk all reachable static variables. */ |
830 | #define FOR_EACH_STATIC_VARIABLE(node) \ | |
831 | for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed) | |
68e56cc4 JH |
832 | /* Walk all static variables with initializer set. */ |
833 | #define FOR_EACH_STATIC_INITIALIZER(node) \ | |
834 | for ((node) = varpool_first_static_initializer (); (node); \ | |
835 | (node) = varpool_next_static_initializer (node)) | |
2aae7680 JH |
836 | |
837 | /* Return first variable. */ | |
838 | static inline struct varpool_node * | |
839 | varpool_first_variable (void) | |
840 | { | |
841 | symtab_node node; | |
842 | for (node = symtab_nodes; node; node = node->symbol.next) | |
843 | { | |
844 | if (symtab_variable_p (node)) | |
845 | return varpool (node); | |
846 | } | |
847 | return NULL; | |
848 | } | |
849 | ||
850 | /* Return next variable after NODE. */ | |
851 | static inline struct varpool_node * | |
852 | varpool_next_variable (struct varpool_node *node) | |
853 | { | |
854 | symtab_node node1 = (symtab_node) node->symbol.next; | |
855 | for (; node1; node1 = node1->symbol.next) | |
856 | { | |
857 | if (symtab_variable_p (node1)) | |
858 | return varpool (node1); | |
859 | } | |
860 | return NULL; | |
861 | } | |
65c70e6b JH |
862 | /* Walk all variables. */ |
863 | #define FOR_EACH_VARIABLE(node) \ | |
2aae7680 JH |
864 | for ((node) = varpool_first_variable (); \ |
865 | (node); \ | |
866 | (node) = varpool_next_variable ((node))) | |
65c70e6b JH |
867 | /* Walk all variables with definitions in current unit. */ |
868 | #define FOR_EACH_DEFINED_VARIABLE(node) \ | |
869 | for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed) | |
68e56cc4 | 870 | |
c47d0034 JH |
871 | /* Return first function with body defined. */ |
872 | static inline struct cgraph_node * | |
873 | cgraph_first_defined_function (void) | |
874 | { | |
2aae7680 JH |
875 | symtab_node node; |
876 | for (node = symtab_nodes; node; node = node->symbol.next) | |
c47d0034 | 877 | { |
2aae7680 JH |
878 | if (symtab_function_p (node) && cgraph (node)->analyzed) |
879 | return cgraph (node); | |
c47d0034 JH |
880 | } |
881 | return NULL; | |
882 | } | |
883 | ||
45896127 | 884 | /* Return next function with body defined after NODE. */ |
c47d0034 JH |
885 | static inline struct cgraph_node * |
886 | cgraph_next_defined_function (struct cgraph_node *node) | |
887 | { | |
2aae7680 JH |
888 | symtab_node node1 = (symtab_node) node->symbol.next; |
889 | for (; node1; node1 = node1->symbol.next) | |
c47d0034 | 890 | { |
2aae7680 JH |
891 | if (symtab_function_p (node1) && cgraph (node1)->analyzed) |
892 | return cgraph (node1); | |
c47d0034 JH |
893 | } |
894 | return NULL; | |
895 | } | |
896 | ||
897 | /* Walk all functions with body defined. */ | |
898 | #define FOR_EACH_DEFINED_FUNCTION(node) \ | |
899 | for ((node) = cgraph_first_defined_function (); (node); \ | |
2aae7680 JH |
900 | (node) = cgraph_next_defined_function ((node))) |
901 | ||
902 | /* Return first function. */ | |
903 | static inline struct cgraph_node * | |
904 | cgraph_first_function (void) | |
905 | { | |
906 | symtab_node node; | |
907 | for (node = symtab_nodes; node; node = node->symbol.next) | |
908 | { | |
909 | if (symtab_function_p (node)) | |
910 | return cgraph (node); | |
911 | } | |
912 | return NULL; | |
913 | } | |
914 | ||
915 | /* Return next function. */ | |
916 | static inline struct cgraph_node * | |
917 | cgraph_next_function (struct cgraph_node *node) | |
918 | { | |
919 | symtab_node node1 = (symtab_node) node->symbol.next; | |
920 | for (; node1; node1 = node1->symbol.next) | |
921 | { | |
922 | if (symtab_function_p (node1)) | |
923 | return cgraph (node1); | |
924 | } | |
925 | return NULL; | |
926 | } | |
65c70e6b JH |
927 | /* Walk all functions. */ |
928 | #define FOR_EACH_FUNCTION(node) \ | |
2aae7680 JH |
929 | for ((node) = cgraph_first_function (); (node); \ |
930 | (node) = cgraph_next_function ((node))) | |
c47d0034 JH |
931 | |
932 | /* Return true when NODE is a function with Gimple body defined | |
933 | in current unit. Functions can also be define externally or they | |
934 | can be thunks with no Gimple representation. | |
935 | ||
936 | Note that at WPA stage, the function body may not be present in memory. */ | |
937 | ||
938 | static inline bool | |
939 | cgraph_function_with_gimple_body_p (struct cgraph_node *node) | |
940 | { | |
39e2db00 | 941 | return node->analyzed && !node->thunk.thunk_p && !node->alias; |
c47d0034 JH |
942 | } |
943 | ||
944 | /* Return first function with body defined. */ | |
945 | static inline struct cgraph_node * | |
946 | cgraph_first_function_with_gimple_body (void) | |
947 | { | |
2aae7680 JH |
948 | symtab_node node; |
949 | for (node = symtab_nodes; node; node = node->symbol.next) | |
c47d0034 | 950 | { |
2aae7680 JH |
951 | if (symtab_function_p (node) |
952 | && cgraph_function_with_gimple_body_p (cgraph (node))) | |
953 | return cgraph (node); | |
c47d0034 JH |
954 | } |
955 | return NULL; | |
956 | } | |
957 | ||
958 | /* Return next reachable static variable with initializer after NODE. */ | |
959 | static inline struct cgraph_node * | |
960 | cgraph_next_function_with_gimple_body (struct cgraph_node *node) | |
961 | { | |
2aae7680 JH |
962 | symtab_node node1 = node->symbol.next; |
963 | for (; node1; node1 = node1->symbol.next) | |
c47d0034 | 964 | { |
2aae7680 JH |
965 | if (symtab_function_p (node1) |
966 | && cgraph_function_with_gimple_body_p (cgraph (node1))) | |
967 | return cgraph (node1); | |
c47d0034 JH |
968 | } |
969 | return NULL; | |
970 | } | |
971 | ||
972 | /* Walk all functions with body defined. */ | |
973 | #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \ | |
974 | for ((node) = cgraph_first_function_with_gimple_body (); (node); \ | |
975 | (node) = cgraph_next_function_with_gimple_body (node)) | |
976 | ||
43d861a5 RL |
977 | /* Create a new static variable of type TYPE. */ |
978 | tree add_new_static_var (tree type); | |
979 | ||
fed5ae11 DK |
980 | /* Return true if iterator CSI points to nothing. */ |
981 | static inline bool | |
982 | csi_end_p (cgraph_node_set_iterator csi) | |
983 | { | |
984 | return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes); | |
985 | } | |
986 | ||
987 | /* Advance iterator CSI. */ | |
988 | static inline void | |
989 | csi_next (cgraph_node_set_iterator *csi) | |
990 | { | |
991 | csi->index++; | |
992 | } | |
993 | ||
994 | /* Return the node pointed to by CSI. */ | |
995 | static inline struct cgraph_node * | |
996 | csi_node (cgraph_node_set_iterator csi) | |
997 | { | |
998 | return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index); | |
999 | } | |
1000 | ||
1001 | /* Return an iterator to the first node in SET. */ | |
1002 | static inline cgraph_node_set_iterator | |
1003 | csi_start (cgraph_node_set set) | |
1004 | { | |
1005 | cgraph_node_set_iterator csi; | |
1006 | ||
1007 | csi.set = set; | |
1008 | csi.index = 0; | |
1009 | return csi; | |
1010 | } | |
1011 | ||
1012 | /* Return true if SET contains NODE. */ | |
1013 | static inline bool | |
1014 | cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set) | |
1015 | { | |
1016 | cgraph_node_set_iterator csi; | |
1017 | csi = cgraph_node_set_find (set, node); | |
1018 | return !csi_end_p (csi); | |
1019 | } | |
1020 | ||
1021 | /* Return number of nodes in SET. */ | |
1022 | static inline size_t | |
1023 | cgraph_node_set_size (cgraph_node_set set) | |
1024 | { | |
1cb1a99f | 1025 | return VEC_length (cgraph_node_ptr, set->nodes); |
fed5ae11 DK |
1026 | } |
1027 | ||
2942c502 JH |
1028 | /* Return true if iterator VSI points to nothing. */ |
1029 | static inline bool | |
1030 | vsi_end_p (varpool_node_set_iterator vsi) | |
1031 | { | |
1032 | return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes); | |
1033 | } | |
1034 | ||
1035 | /* Advance iterator VSI. */ | |
1036 | static inline void | |
1037 | vsi_next (varpool_node_set_iterator *vsi) | |
1038 | { | |
1039 | vsi->index++; | |
1040 | } | |
1041 | ||
1042 | /* Return the node pointed to by VSI. */ | |
1043 | static inline struct varpool_node * | |
1044 | vsi_node (varpool_node_set_iterator vsi) | |
1045 | { | |
1046 | return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index); | |
1047 | } | |
1048 | ||
1049 | /* Return an iterator to the first node in SET. */ | |
1050 | static inline varpool_node_set_iterator | |
1051 | vsi_start (varpool_node_set set) | |
1052 | { | |
1053 | varpool_node_set_iterator vsi; | |
1054 | ||
1055 | vsi.set = set; | |
1056 | vsi.index = 0; | |
1057 | return vsi; | |
1058 | } | |
1059 | ||
1060 | /* Return true if SET contains NODE. */ | |
1061 | static inline bool | |
1062 | varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set) | |
1063 | { | |
1064 | varpool_node_set_iterator vsi; | |
1065 | vsi = varpool_node_set_find (set, node); | |
1066 | return !vsi_end_p (vsi); | |
1067 | } | |
1068 | ||
1069 | /* Return number of nodes in SET. */ | |
1070 | static inline size_t | |
1071 | varpool_node_set_size (varpool_node_set set) | |
1072 | { | |
1cb1a99f | 1073 | return VEC_length (varpool_node_ptr, set->nodes); |
2942c502 JH |
1074 | } |
1075 | ||
d48e9cea OR |
1076 | /* Uniquize all constants that appear in memory. |
1077 | Each constant in memory thus far output is recorded | |
1078 | in `const_desc_table'. */ | |
1079 | ||
1080 | struct GTY(()) constant_descriptor_tree { | |
1081 | /* A MEM for the constant. */ | |
1082 | rtx rtl; | |
b8698a0f | 1083 | |
d48e9cea OR |
1084 | /* The value of the constant. */ |
1085 | tree value; | |
1086 | ||
1087 | /* Hash of value. Computing the hash from value each time | |
1088 | hashfn is called can't work properly, as that means recursive | |
1089 | use of the hash table during hash table expansion. */ | |
1090 | hashval_t hash; | |
1091 | }; | |
1092 | ||
ace72c88 JH |
1093 | /* Return true if set is nonempty. */ |
1094 | static inline bool | |
1095 | cgraph_node_set_nonempty_p (cgraph_node_set set) | |
1096 | { | |
9eec9488 | 1097 | return !VEC_empty (cgraph_node_ptr, set->nodes); |
ace72c88 JH |
1098 | } |
1099 | ||
1100 | /* Return true if set is nonempty. */ | |
1101 | static inline bool | |
1102 | varpool_node_set_nonempty_p (varpool_node_set set) | |
1103 | { | |
9eec9488 | 1104 | return !VEC_empty (varpool_node_ptr, set->nodes); |
ace72c88 JH |
1105 | } |
1106 | ||
be330ed4 | 1107 | /* Return true when function NODE is only called directly or it has alias. |
b20996ff JH |
1108 | i.e. it is not externally visible, address was not taken and |
1109 | it is not used in any other non-standard way. */ | |
1110 | ||
1111 | static inline bool | |
be330ed4 | 1112 | cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node) |
b20996ff | 1113 | { |
530f3a1b | 1114 | gcc_assert (!node->global.inlined_to); |
ead84f73 | 1115 | return (!node->symbol.force_output && !node->symbol.address_taken |
960bfb69 JH |
1116 | && !node->symbol.used_from_other_partition |
1117 | && !DECL_STATIC_CONSTRUCTOR (node->symbol.decl) | |
1118 | && !DECL_STATIC_DESTRUCTOR (node->symbol.decl) | |
1119 | && !node->symbol.externally_visible); | |
b20996ff JH |
1120 | } |
1121 | ||
df7705b1 JH |
1122 | /* Return true when function NODE can be removed from callgraph |
1123 | if all direct calls are eliminated. */ | |
1124 | ||
1125 | static inline bool | |
1126 | varpool_can_remove_if_no_refs (struct varpool_node *node) | |
1127 | { | |
ead84f73 | 1128 | return (!node->symbol.force_output && !node->symbol.used_from_other_partition |
960bfb69 | 1129 | && (DECL_COMDAT (node->symbol.decl) |
ead84f73 JH |
1130 | || !node->symbol.externally_visible |
1131 | || DECL_EXTERNAL (node->symbol.decl))); | |
df7705b1 JH |
1132 | } |
1133 | ||
4a444e58 JH |
1134 | /* Return true when all references to VNODE must be visible in ipa_ref_list. |
1135 | i.e. if the variable is not externally visible or not used in some magic | |
1136 | way (asm statement or such). | |
61502ca8 | 1137 | The magic uses are all summarized in force_output flag. */ |
4a444e58 JH |
1138 | |
1139 | static inline bool | |
1140 | varpool_all_refs_explicit_p (struct varpool_node *vnode) | |
1141 | { | |
e8fdf1cd | 1142 | return (vnode->analyzed |
960bfb69 JH |
1143 | && !vnode->symbol.externally_visible |
1144 | && !vnode->symbol.used_from_other_partition | |
ead84f73 | 1145 | && !vnode->symbol.force_output); |
4a444e58 JH |
1146 | } |
1147 | ||
d48e9cea OR |
1148 | /* Constant pool accessor function. */ |
1149 | htab_t constant_pool_htab (void); | |
fed5ae11 | 1150 | |
be330ed4 JH |
1151 | /* FIXME: inappropriate dependency of cgraph on IPA. */ |
1152 | #include "ipa-ref-inline.h" | |
1153 | ||
39e2db00 JH |
1154 | /* Return node that alias N is aliasing. */ |
1155 | ||
1156 | static inline struct cgraph_node * | |
1157 | cgraph_alias_aliased_node (struct cgraph_node *n) | |
1158 | { | |
1159 | struct ipa_ref *ref; | |
1160 | ||
960bfb69 | 1161 | ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref); |
39e2db00 | 1162 | gcc_checking_assert (ref->use == IPA_REF_ALIAS); |
5932a4d4 | 1163 | if (symtab_function_p (ref->referred)) |
39e2db00 JH |
1164 | return ipa_ref_node (ref); |
1165 | return NULL; | |
1166 | } | |
1167 | ||
cd35bcf7 JH |
1168 | /* Return node that alias N is aliasing. */ |
1169 | ||
1170 | static inline struct varpool_node * | |
1171 | varpool_alias_aliased_node (struct varpool_node *n) | |
1172 | { | |
1173 | struct ipa_ref *ref; | |
1174 | ||
960bfb69 | 1175 | ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref); |
cd35bcf7 | 1176 | gcc_checking_assert (ref->use == IPA_REF_ALIAS); |
5932a4d4 | 1177 | if (symtab_variable_p (ref->referred)) |
cd35bcf7 JH |
1178 | return ipa_ref_varpool_node (ref); |
1179 | return NULL; | |
1180 | } | |
1181 | ||
be330ed4 JH |
1182 | /* Given NODE, walk the alias chain to return the function NODE is alias of. |
1183 | Walk through thunk, too. | |
1184 | When AVAILABILITY is non-NULL, get minimal availablity in the chain. */ | |
1185 | ||
1186 | static inline struct cgraph_node * | |
1187 | cgraph_function_node (struct cgraph_node *node, enum availability *availability) | |
1188 | { | |
1189 | if (availability) | |
1190 | *availability = cgraph_function_body_availability (node); | |
1191 | while (node) | |
1192 | { | |
39e2db00 JH |
1193 | if (node->alias && node->analyzed) |
1194 | node = cgraph_alias_aliased_node (node); | |
1195 | else if (node->thunk.thunk_p) | |
be330ed4 JH |
1196 | node = node->callees->callee; |
1197 | else | |
1198 | return node; | |
39e2db00 | 1199 | if (node && availability) |
be330ed4 JH |
1200 | { |
1201 | enum availability a; | |
1202 | a = cgraph_function_body_availability (node); | |
1203 | if (a < *availability) | |
1204 | *availability = a; | |
1205 | } | |
1206 | } | |
9c7c9f10 | 1207 | if (availability) |
39e2db00 | 1208 | *availability = AVAIL_NOT_AVAILABLE; |
be330ed4 JH |
1209 | return NULL; |
1210 | } | |
1211 | ||
1212 | /* Given NODE, walk the alias chain to return the function NODE is alias of. | |
1213 | Do not walk through thunks. | |
1214 | When AVAILABILITY is non-NULL, get minimal availablity in the chain. */ | |
1215 | ||
1216 | static inline struct cgraph_node * | |
1217 | cgraph_function_or_thunk_node (struct cgraph_node *node, enum availability *availability) | |
1218 | { | |
1219 | if (availability) | |
1220 | *availability = cgraph_function_body_availability (node); | |
39e2db00 JH |
1221 | while (node) |
1222 | { | |
1223 | if (node->alias && node->analyzed) | |
1224 | node = cgraph_alias_aliased_node (node); | |
1225 | else | |
1226 | return node; | |
1227 | if (node && availability) | |
1228 | { | |
1229 | enum availability a; | |
1230 | a = cgraph_function_body_availability (node); | |
1231 | if (a < *availability) | |
1232 | *availability = a; | |
1233 | } | |
1234 | } | |
9c7c9f10 | 1235 | if (availability) |
39e2db00 | 1236 | *availability = AVAIL_NOT_AVAILABLE; |
be330ed4 JH |
1237 | return NULL; |
1238 | } | |
1239 | ||
cd35bcf7 JH |
1240 | /* Given NODE, walk the alias chain to return the function NODE is alias of. |
1241 | Do not walk through thunks. | |
1242 | When AVAILABILITY is non-NULL, get minimal availablity in the chain. */ | |
1243 | ||
1244 | static inline struct varpool_node * | |
1245 | varpool_variable_node (struct varpool_node *node, enum availability *availability) | |
1246 | { | |
1247 | if (availability) | |
1248 | *availability = cgraph_variable_initializer_availability (node); | |
1249 | while (node) | |
1250 | { | |
1251 | if (node->alias && node->analyzed) | |
1252 | node = varpool_alias_aliased_node (node); | |
1253 | else | |
1254 | return node; | |
1255 | if (node && availability) | |
1256 | { | |
1257 | enum availability a; | |
1258 | a = cgraph_variable_initializer_availability (node); | |
1259 | if (a < *availability) | |
1260 | *availability = a; | |
1261 | } | |
1262 | } | |
9c7c9f10 | 1263 | if (availability) |
cd35bcf7 JH |
1264 | *availability = AVAIL_NOT_AVAILABLE; |
1265 | return NULL; | |
1266 | } | |
1267 | ||
d7d1d041 RG |
1268 | /* Return true when the edge E represents a direct recursion. */ |
1269 | static inline bool | |
1270 | cgraph_edge_recursive_p (struct cgraph_edge *e) | |
1271 | { | |
be330ed4 | 1272 | struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL); |
d7d1d041 | 1273 | if (e->caller->global.inlined_to) |
960bfb69 | 1274 | return e->caller->global.inlined_to->symbol.decl == callee->symbol.decl; |
d7d1d041 | 1275 | else |
960bfb69 | 1276 | return e->caller->symbol.decl == callee->symbol.decl; |
d7d1d041 | 1277 | } |
0a35513e AH |
1278 | |
1279 | /* Return true if the TM_CLONE bit is set for a given FNDECL. */ | |
1280 | static inline bool | |
1281 | decl_is_tm_clone (const_tree fndecl) | |
1282 | { | |
1283 | struct cgraph_node *n = cgraph_get_node (fndecl); | |
1284 | if (n) | |
1285 | return n->tm_clone; | |
1286 | return false; | |
1287 | } | |
1c4a429a | 1288 | #endif /* GCC_CGRAPH_H */ |