]>
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; | |
18c6ada9 | 218 | /* Pointer to the next clone. */ |
9187e02d JH |
219 | struct cgraph_node *next_sibling_clone; |
220 | struct cgraph_node *prev_sibling_clone; | |
221 | struct cgraph_node *clones; | |
222 | struct cgraph_node *clone_of; | |
70d539ce JH |
223 | /* For functions with many calls sites it holds map from call expression |
224 | to the edge to speed up cgraph_edge function. */ | |
225 | htab_t GTY((param_is (struct cgraph_edge))) call_site_hash; | |
97ba0040 JH |
226 | /* Declaration node used to be clone of. */ |
227 | tree former_clone_of; | |
c22cacf3 | 228 | |
0e3776db JH |
229 | /* Interprocedural passes scheduled to have their transform functions |
230 | applied next time we execute local pass on them. We maintain it | |
231 | per-function in order to allow IPA passes to introduce new functions. */ | |
232 | VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply; | |
233 | ||
95c755e9 JH |
234 | struct cgraph_local_info local; |
235 | struct cgraph_global_info global; | |
236 | struct cgraph_rtl_info rtl; | |
9187e02d | 237 | struct cgraph_clone_info clone; |
6744a6ab | 238 | struct cgraph_thunk_info thunk; |
c22cacf3 | 239 | |
e42922b1 JH |
240 | /* Expected number of executions: calculated in profile.c. */ |
241 | gcov_type count; | |
db0bf14f JH |
242 | /* How to scale counts at materialization time; used to merge |
243 | LTO units with different number of profile runs. */ | |
244 | int count_materialization_scale; | |
95c755e9 JH |
245 | /* Unique id of the node. */ |
246 | int uid; | |
3691626c | 247 | |
6b20f353 DS |
248 | /* Set when decl is an abstract function pointed to by the |
249 | ABSTRACT_DECL_ORIGIN of a reachable function. */ | |
250 | unsigned abstract_and_needed : 1; | |
50674e96 | 251 | /* Set once the function is lowered (i.e. its CFG is built). */ |
b4e19405 | 252 | unsigned lowered : 1; |
25c84396 RH |
253 | /* Set once the function has been instantiated and its callee |
254 | lists created. */ | |
b4e19405 | 255 | unsigned analyzed : 1; |
257eb6e3 JH |
256 | /* Set when function is scheduled to be processed by local passes. */ |
257 | unsigned process : 1; | |
12527dce | 258 | /* Set for aliases once they got through assemble_alias. */ |
b4e19405 | 259 | unsigned alias : 1; |
39e2db00 | 260 | /* Set for aliases created as C++ same body aliases. */ |
b2583345 | 261 | unsigned same_body_alias : 1; |
5fefcf92 JH |
262 | /* How commonly executed the node is. Initialized during branch |
263 | probabilities pass. */ | |
264 | ENUM_BITFIELD (node_frequency) frequency : 2; | |
844db5d0 JH |
265 | /* True when function can only be called at startup (from static ctor). */ |
266 | unsigned only_called_at_startup : 1; | |
267 | /* True when function can only be called at startup (from static dtor). */ | |
268 | unsigned only_called_at_exit : 1; | |
0a35513e AH |
269 | /* True when function is the transactional clone of a function which |
270 | is called only from inside transactions. */ | |
271 | /* ?? We should be able to remove this. We have enough bits in | |
272 | cgraph to calculate it. */ | |
273 | unsigned tm_clone : 1; | |
1c4a429a JH |
274 | }; |
275 | ||
fed5ae11 DK |
276 | typedef struct cgraph_node *cgraph_node_ptr; |
277 | ||
278 | DEF_VEC_P(cgraph_node_ptr); | |
279 | DEF_VEC_ALLOC_P(cgraph_node_ptr,heap); | |
280 | DEF_VEC_ALLOC_P(cgraph_node_ptr,gc); | |
281 | ||
282 | /* A cgraph node set is a collection of cgraph nodes. A cgraph node | |
283 | can appear in multiple sets. */ | |
1cb1a99f | 284 | struct cgraph_node_set_def |
fed5ae11 | 285 | { |
1cb1a99f JH |
286 | struct pointer_map_t *map; |
287 | VEC(cgraph_node_ptr, heap) *nodes; | |
fed5ae11 DK |
288 | }; |
289 | ||
2942c502 JH |
290 | typedef struct varpool_node *varpool_node_ptr; |
291 | ||
292 | DEF_VEC_P(varpool_node_ptr); | |
293 | DEF_VEC_ALLOC_P(varpool_node_ptr,heap); | |
294 | DEF_VEC_ALLOC_P(varpool_node_ptr,gc); | |
295 | ||
296 | /* A varpool node set is a collection of varpool nodes. A varpool node | |
297 | can appear in multiple sets. */ | |
1cb1a99f | 298 | struct varpool_node_set_def |
2942c502 | 299 | { |
1cb1a99f JH |
300 | struct pointer_map_t * map; |
301 | VEC(varpool_node_ptr, heap) *nodes; | |
2942c502 JH |
302 | }; |
303 | ||
fed5ae11 DK |
304 | typedef struct cgraph_node_set_def *cgraph_node_set; |
305 | ||
306 | DEF_VEC_P(cgraph_node_set); | |
307 | DEF_VEC_ALLOC_P(cgraph_node_set,gc); | |
308 | DEF_VEC_ALLOC_P(cgraph_node_set,heap); | |
309 | ||
2942c502 JH |
310 | typedef struct varpool_node_set_def *varpool_node_set; |
311 | ||
312 | DEF_VEC_P(varpool_node_set); | |
313 | DEF_VEC_ALLOC_P(varpool_node_set,gc); | |
314 | DEF_VEC_ALLOC_P(varpool_node_set,heap); | |
315 | ||
fed5ae11 DK |
316 | /* Iterator structure for cgraph node sets. */ |
317 | typedef struct | |
318 | { | |
319 | cgraph_node_set set; | |
320 | unsigned index; | |
321 | } cgraph_node_set_iterator; | |
322 | ||
2942c502 JH |
323 | /* Iterator structure for varpool node sets. */ |
324 | typedef struct | |
325 | { | |
326 | varpool_node_set set; | |
327 | unsigned index; | |
328 | } varpool_node_set_iterator; | |
329 | ||
61a05df1 JH |
330 | #define DEFCIFCODE(code, string) CIF_ ## code, |
331 | /* Reasons for inlining failures. */ | |
533c07c5 | 332 | typedef enum cgraph_inline_failed_enum { |
61a05df1 JH |
333 | #include "cif-code.def" |
334 | CIF_N_REASONS | |
335 | } cgraph_inline_failed_t; | |
336 | ||
e33c6cd6 MJ |
337 | /* Structure containing additional information about an indirect call. */ |
338 | ||
339 | struct GTY(()) cgraph_indirect_call_info | |
340 | { | |
b258210c MJ |
341 | /* Offset accumulated from ancestor jump functions of inlined call graph |
342 | edges. */ | |
343 | HOST_WIDE_INT anc_offset; | |
344 | /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */ | |
345 | HOST_WIDE_INT otr_token; | |
346 | /* Type of the object from OBJ_TYPE_REF_OBJECT. */ | |
347 | tree otr_type; | |
e33c6cd6 MJ |
348 | /* Index of the parameter that is called. */ |
349 | int param_index; | |
5f902d76 JH |
350 | /* ECF flags determined from the caller. */ |
351 | int ecf_flags; | |
b258210c MJ |
352 | |
353 | /* Set when the call is a virtual call with the parameter being the | |
354 | associated object pointer rather than a simple direct call. */ | |
355 | unsigned polymorphic : 1; | |
e33c6cd6 MJ |
356 | }; |
357 | ||
d1b38208 | 358 | struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge { |
6009ee7b MJ |
359 | /* Expected number of executions: calculated in profile.c. */ |
360 | gcov_type count; | |
ed2df68b JH |
361 | struct cgraph_node *caller; |
362 | struct cgraph_node *callee; | |
2563c224 | 363 | struct cgraph_edge *prev_caller; |
1c4a429a | 364 | struct cgraph_edge *next_caller; |
2563c224 | 365 | struct cgraph_edge *prev_callee; |
1c4a429a | 366 | struct cgraph_edge *next_callee; |
726a989a | 367 | gimple call_stmt; |
e33c6cd6 MJ |
368 | /* Additional information about an indirect call. Not cleared when an edge |
369 | becomes direct. */ | |
370 | struct cgraph_indirect_call_info *indirect_info; | |
18c6ada9 | 371 | PTR GTY ((skip (""))) aux; |
61a05df1 JH |
372 | /* When equal to CIF_OK, inline this call. Otherwise, points to the |
373 | explanation why function was not inlined. */ | |
374 | cgraph_inline_failed_t inline_failed; | |
6009ee7b MJ |
375 | /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt |
376 | when the function is serialized in. */ | |
377 | unsigned int lto_stmt_uid; | |
b8698a0f | 378 | /* Expected frequency of executions within the function. |
45a80bb9 JH |
379 | When set to CGRAPH_FREQ_BASE, the edge is expected to be called once |
380 | per function call. The range is 0 to CGRAPH_FREQ_MAX. */ | |
381 | int frequency; | |
6009ee7b MJ |
382 | /* Unique id of the edge. */ |
383 | int uid; | |
e33c6cd6 MJ |
384 | /* Whether this edge was made direct by indirect inlining. */ |
385 | unsigned int indirect_inlining_edge : 1; | |
386 | /* Whether this edge describes an indirect call with an undetermined | |
387 | callee. */ | |
388 | unsigned int indirect_unknown_callee : 1; | |
389 | /* Whether this edge is still a dangling */ | |
d7f09764 DN |
390 | /* True if the corresponding CALL stmt cannot be inlined. */ |
391 | unsigned int call_stmt_cannot_inline_p : 1; | |
2505c5ed JH |
392 | /* Can this call throw externally? */ |
393 | unsigned int can_throw_external : 1; | |
1c4a429a JH |
394 | }; |
395 | ||
45a80bb9 JH |
396 | #define CGRAPH_FREQ_BASE 1000 |
397 | #define CGRAPH_FREQ_MAX 100000 | |
398 | ||
b2c0ad40 KH |
399 | typedef struct cgraph_edge *cgraph_edge_p; |
400 | ||
401 | DEF_VEC_P(cgraph_edge_p); | |
402 | DEF_VEC_ALLOC_P(cgraph_edge_p,heap); | |
403 | ||
8a4a83ed JH |
404 | /* The varpool data structure. |
405 | Each static variable decl has assigned varpool_node. */ | |
e69529cd | 406 | |
2aae7680 | 407 | struct GTY(()) varpool_node { |
960bfb69 | 408 | struct symtab_node_base symbol; |
cd35bcf7 JH |
409 | /* For aliases points to declaration DECL is alias of. */ |
410 | tree alias_of; | |
e69529cd | 411 | |
cd9c7bd2 JH |
412 | /* Set once the variable has been instantiated and its callee |
413 | lists created. */ | |
b4e19405 | 414 | unsigned analyzed : 1; |
e69529cd | 415 | /* Set once it has been finalized so we consider it to be output. */ |
b4e19405 | 416 | unsigned finalized : 1; |
6b02a499 | 417 | /* Set when variable is scheduled to be assembled. */ |
b4e19405 | 418 | unsigned output : 1; |
2c71ac78 JM |
419 | /* Set for aliases once they got through assemble_alias. Also set for |
420 | extra name aliases in varpool_extra_name_alias. */ | |
b4e19405 | 421 | unsigned alias : 1; |
cd35bcf7 | 422 | unsigned extra_name_alias : 1; |
e69529cd JH |
423 | }; |
424 | ||
65d630d4 | 425 | /* Every top level asm statement is put into a asm_node. */ |
474eccc6 | 426 | |
65d630d4 | 427 | struct GTY(()) asm_node { |
474eccc6 | 428 | /* Next asm node. */ |
65d630d4 | 429 | struct asm_node *next; |
474eccc6 ILT |
430 | /* String for this asm node. */ |
431 | tree asm_str; | |
432 | /* Ordering of all cgraph nodes. */ | |
433 | int order; | |
434 | }; | |
435 | ||
960bfb69 | 436 | /* Symbol table entry. */ |
2aae7680 JH |
437 | union GTY((desc ("%h.symbol.type"), chain_next ("%h.symbol.next"), |
438 | chain_prev ("%h.symbol.previous"))) symtab_node_def { | |
960bfb69 JH |
439 | struct symtab_node_base GTY ((tag ("SYMTAB_SYMBOL"))) symbol; |
440 | /* Use cgraph (symbol) accessor to get cgraph_node. */ | |
441 | struct cgraph_node GTY ((tag ("SYMTAB_FUNCTION"))) x_function; | |
442 | /* Use varpool (symbol) accessor to get varpool_node. */ | |
443 | struct varpool_node GTY ((tag ("SYMTAB_VARIABLE"))) x_variable; | |
444 | }; | |
445 | ||
2aae7680 | 446 | extern GTY(()) symtab_node symtab_nodes; |
ed2df68b | 447 | extern GTY(()) int cgraph_n_nodes; |
b58b1157 | 448 | extern GTY(()) int cgraph_max_uid; |
9088c1cc | 449 | extern GTY(()) int cgraph_edge_max_uid; |
dafc5b82 | 450 | extern bool cgraph_global_info_ready; |
f45e0ad1 JH |
451 | enum cgraph_state |
452 | { | |
66058468 JH |
453 | /* Frontend is parsing and finalizing functions. */ |
454 | CGRAPH_STATE_PARSING, | |
f45e0ad1 JH |
455 | /* Callgraph is being constructed. It is safe to add new functions. */ |
456 | CGRAPH_STATE_CONSTRUCTION, | |
457 | /* Callgraph is built and IPA passes are being run. */ | |
458 | CGRAPH_STATE_IPA, | |
7a388ee4 JH |
459 | /* Callgraph is built and all functions are transformed to SSA form. */ |
460 | CGRAPH_STATE_IPA_SSA, | |
f45e0ad1 JH |
461 | /* Functions are now ordered and being passed to RTL expanders. */ |
462 | CGRAPH_STATE_EXPANSION, | |
463 | /* All cgraph expansion is done. */ | |
464 | CGRAPH_STATE_FINISHED | |
465 | }; | |
466 | extern enum cgraph_state cgraph_state; | |
e7d6beb0 | 467 | extern bool cgraph_function_flags_ready; |
66058468 | 468 | extern cgraph_node_set cgraph_new_nodes; |
1c4a429a | 469 | |
65d630d4 | 470 | extern GTY(()) struct asm_node *asm_nodes; |
2aae7680 | 471 | extern GTY(()) int symtab_order; |
39e2db00 | 472 | extern bool same_body_aliases_done; |
e69529cd | 473 | |
2aae7680 JH |
474 | /* In symtab.c */ |
475 | void symtab_register_node (symtab_node); | |
476 | void symtab_unregister_node (symtab_node); | |
477 | void symtab_remove_node (symtab_node); | |
1ab24192 JH |
478 | symtab_node symtab_get_node (const_tree); |
479 | symtab_node symtab_node_for_asm (const_tree asmname); | |
8f940ee6 JH |
480 | const char * symtab_node_asm_name (symtab_node); |
481 | const char * symtab_node_name (symtab_node); | |
1ab24192 | 482 | void symtab_insert_node_to_hashtable (symtab_node); |
65d630d4 JH |
483 | void symtab_add_to_same_comdat_group (symtab_node, symtab_node); |
484 | void symtab_dissolve_same_comdat_group_list (symtab_node node); | |
8f940ee6 JH |
485 | void dump_symtab (FILE *); |
486 | void debug_symtab (void); | |
487 | void dump_symtab_node (FILE *, symtab_node); | |
488 | void debug_symtab_node (symtab_node); | |
489 | void dump_symtab_base (FILE *, symtab_node); | |
474ffc72 JH |
490 | void verify_symtab (void); |
491 | void verify_symtab_node (symtab_node); | |
492 | bool verify_symtab_base (symtab_node); | |
65d630d4 JH |
493 | bool symtab_used_from_object_file_p (symtab_node); |
494 | void symtab_make_decl_local (tree); | |
2aae7680 | 495 | |
1c4a429a | 496 | /* In cgraph.c */ |
439f7bc3 | 497 | void dump_cgraph (FILE *); |
c4e622b6 | 498 | void debug_cgraph (void); |
18c6ada9 | 499 | void dump_cgraph_node (FILE *, struct cgraph_node *); |
c4e622b6 | 500 | void debug_cgraph_node (struct cgraph_node *); |
18c6ada9 | 501 | void cgraph_remove_edge (struct cgraph_edge *); |
439f7bc3 | 502 | void cgraph_remove_node (struct cgraph_node *); |
3a40c18a | 503 | void cgraph_release_function_body (struct cgraph_node *); |
2563c224 | 504 | void cgraph_node_remove_callees (struct cgraph_node *node); |
18c6ada9 JH |
505 | struct cgraph_edge *cgraph_create_edge (struct cgraph_node *, |
506 | struct cgraph_node *, | |
898b8927 | 507 | gimple, gcov_type, int); |
ce47fda3 | 508 | struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple, |
898b8927 | 509 | int, gcov_type, int); |
ce47fda3 | 510 | struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void); |
a358e188 | 511 | struct cgraph_node * cgraph_create_node (tree); |
66a20fc2 | 512 | struct cgraph_node * cgraph_create_empty_node (void); |
a358e188 | 513 | struct cgraph_node * cgraph_get_create_node (tree); |
87e7b310 JH |
514 | struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree); |
515 | struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT, | |
051f8cc6 | 516 | HOST_WIDE_INT, tree, tree); |
4537ec0c | 517 | struct cgraph_node *cgraph_node_for_asm (tree); |
726a989a RB |
518 | struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple); |
519 | void cgraph_set_call_stmt (struct cgraph_edge *, gimple); | |
4b685e14 | 520 | void cgraph_update_edges_for_call_stmt (gimple, tree, gimple); |
439f7bc3 AJ |
521 | struct cgraph_local_info *cgraph_local_info (tree); |
522 | struct cgraph_global_info *cgraph_global_info (tree); | |
523 | struct cgraph_rtl_info *cgraph_rtl_info (tree); | |
39e2db00 | 524 | struct cgraph_node *cgraph_create_function_alias (tree, tree); |
66a20fc2 JH |
525 | void cgraph_call_node_duplication_hooks (struct cgraph_node *, |
526 | struct cgraph_node *); | |
527 | void cgraph_call_edge_duplication_hooks (struct cgraph_edge *, | |
528 | struct cgraph_edge *); | |
1c4a429a | 529 | |
18c6ada9 | 530 | void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *); |
81fa35bd | 531 | void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *); |
be330ed4 | 532 | bool cgraph_only_called_directly_p (struct cgraph_node *); |
e69529cd | 533 | |
1bb17c21 | 534 | bool cgraph_function_possibly_inlined_p (tree); |
e42922b1 | 535 | void cgraph_unnest_node (struct cgraph_node *); |
1bb17c21 | 536 | |
6b02a499 | 537 | enum availability cgraph_function_body_availability (struct cgraph_node *); |
f45e0ad1 | 538 | void cgraph_add_new_function (tree, bool); |
61a05df1 | 539 | const char* cgraph_inline_failed_string (cgraph_inline_failed_t); |
6b02a499 | 540 | |
20cdc2be | 541 | void cgraph_set_nothrow_flag (struct cgraph_node *, bool); |
530f3a1b JH |
542 | void cgraph_set_const_flag (struct cgraph_node *, bool, bool); |
543 | void cgraph_set_pure_flag (struct cgraph_node *, bool, bool); | |
d56026c2 JH |
544 | bool cgraph_node_cannot_return (struct cgraph_node *); |
545 | bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *); | |
508e4757 JH |
546 | bool cgraph_will_be_removed_from_program_if_no_direct_calls |
547 | (struct cgraph_node *node); | |
548 | bool cgraph_can_remove_if_no_direct_calls_and_refs_p | |
549 | (struct cgraph_node *node); | |
9aa3f5c5 | 550 | bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node); |
be330ed4 | 551 | bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution); |
be330ed4 JH |
552 | bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *, |
553 | bool (*) (struct cgraph_node *, void *), | |
554 | void *, | |
555 | bool); | |
556 | bool cgraph_for_node_and_aliases (struct cgraph_node *, | |
557 | bool (*) (struct cgraph_node *, void *), | |
558 | void *, bool); | |
559 | VEC (cgraph_edge_p, heap) * collect_callers_of_node (struct cgraph_node *node); | |
18c6ada9 JH |
560 | void verify_cgraph (void); |
561 | void verify_cgraph_node (struct cgraph_node *); | |
9c8305f8 | 562 | void cgraph_mark_address_taken_node (struct cgraph_node *); |
d7f09764 | 563 | |
9088c1cc MJ |
564 | typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *); |
565 | typedef void (*cgraph_node_hook)(struct cgraph_node *, void *); | |
566 | typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *, | |
567 | void *); | |
568 | typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *, | |
569 | void *); | |
570 | struct cgraph_edge_hook_list; | |
571 | struct cgraph_node_hook_list; | |
572 | struct cgraph_2edge_hook_list; | |
573 | struct cgraph_2node_hook_list; | |
574 | struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *); | |
575 | void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *); | |
576 | struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook, | |
577 | void *); | |
578 | void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *); | |
129a37fc JH |
579 | struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook, |
580 | void *); | |
581 | void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *); | |
582 | void cgraph_call_function_insertion_hooks (struct cgraph_node *node); | |
9088c1cc MJ |
583 | struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *); |
584 | void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *); | |
585 | struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *); | |
586 | void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *); | |
8132a837 | 587 | gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *); |
fa5f5e27 | 588 | bool cgraph_propagate_frequency (struct cgraph_node *node); |
9c8305f8 JH |
589 | |
590 | /* In cgraphunit.c */ | |
65d630d4 | 591 | struct asm_node *add_asm_node (tree); |
9c8305f8 JH |
592 | extern FILE *cgraph_dump_file; |
593 | void cgraph_finalize_function (tree, bool); | |
65d630d4 JH |
594 | void finalize_compilation_unit (void); |
595 | void compile (void); | |
9c8305f8 | 596 | void init_cgraph (void); |
66a20fc2 JH |
597 | bool cgraph_process_new_functions (void); |
598 | void cgraph_process_same_body_aliases (void); | |
599 | void fixup_same_cpp_alias_visibility (symtab_node node, symtab_node target, tree alias); | |
600 | ||
601 | /* In cgraphclones.c */ | |
602 | ||
603 | struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *, | |
604 | struct cgraph_node *, gimple, | |
605 | unsigned, gcov_type, int, bool); | |
606 | struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type, | |
607 | int, bool, VEC(cgraph_edge_p,heap) *, | |
608 | bool); | |
609 | tree clone_function_name (tree decl, const char *); | |
610 | struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node, | |
611 | VEC(cgraph_edge_p,heap)*, | |
612 | VEC(ipa_replace_map_p,gc)* tree_map, | |
613 | bitmap args_to_skip, | |
614 | const char *clone_name); | |
615 | struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *); | |
616 | bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *); | |
617 | void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple); | |
618 | void cgraph_create_edge_including_clones (struct cgraph_node *, | |
619 | struct cgraph_node *, | |
620 | gimple, gimple, gcov_type, int, | |
621 | cgraph_inline_failed_t); | |
622 | void cgraph_materialize_all_clones (void); | |
9c8305f8 JH |
623 | struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *, |
624 | tree, VEC(cgraph_edge_p,heap)*, bitmap); | |
625 | struct cgraph_node *cgraph_function_versioning (struct cgraph_node *, | |
626 | VEC(cgraph_edge_p,heap)*, | |
627 | VEC(ipa_replace_map_p,gc)*, | |
628 | bitmap, bool, bitmap, | |
629 | basic_block, const char *); | |
630 | void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, | |
631 | bool, bitmap, bool, bitmap, basic_block); | |
9c8305f8 | 632 | |
917948d3 ZD |
633 | /* In cgraphbuild.c */ |
634 | unsigned int rebuild_cgraph_edges (void); | |
99b766fc | 635 | void cgraph_rebuild_references (void); |
9187e02d | 636 | int compute_call_stmt_bb_frequency (tree, basic_block bb); |
9c8305f8 | 637 | void record_references_in_initializer (tree, bool); |
917948d3 | 638 | |
ca31b95f JH |
639 | /* In ipa.c */ |
640 | bool cgraph_remove_unreachable_nodes (bool, FILE *); | |
fed5ae11 DK |
641 | cgraph_node_set cgraph_node_set_new (void); |
642 | cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set, | |
643 | struct cgraph_node *); | |
644 | void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *); | |
645 | void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *); | |
646 | void dump_cgraph_node_set (FILE *, cgraph_node_set); | |
647 | void debug_cgraph_node_set (cgraph_node_set); | |
1cb1a99f | 648 | void free_cgraph_node_set (cgraph_node_set); |
9c8305f8 | 649 | void cgraph_build_static_cdtor (char which, tree body, int priority); |
fed5ae11 | 650 | |
2942c502 JH |
651 | varpool_node_set varpool_node_set_new (void); |
652 | varpool_node_set_iterator varpool_node_set_find (varpool_node_set, | |
653 | struct varpool_node *); | |
654 | void varpool_node_set_add (varpool_node_set, struct varpool_node *); | |
655 | void varpool_node_set_remove (varpool_node_set, struct varpool_node *); | |
656 | void dump_varpool_node_set (FILE *, varpool_node_set); | |
657 | void debug_varpool_node_set (varpool_node_set); | |
1cb1a99f | 658 | void free_varpool_node_set (varpool_node_set); |
4a444e58 | 659 | void ipa_discover_readonly_nonaddressable_vars (void); |
430c6ceb | 660 | bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *); |
38877e98 | 661 | bool varpool_externally_visible_p (struct varpool_node *, bool); |
ca31b95f | 662 | |
fed5ae11 | 663 | /* In predict.c */ |
ca30a539 | 664 | bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e); |
e6416b30 | 665 | bool cgraph_optimize_for_size_p (struct cgraph_node *); |
ca30a539 | 666 | |
8a4a83ed | 667 | /* In varpool.c */ |
8a4a83ed JH |
668 | struct varpool_node *varpool_node (tree); |
669 | struct varpool_node *varpool_node_for_asm (tree asmname); | |
670 | void varpool_mark_needed_node (struct varpool_node *); | |
d85478c2 | 671 | void debug_varpool (void); |
8a4a83ed JH |
672 | void dump_varpool (FILE *); |
673 | void dump_varpool_node (FILE *, struct varpool_node *); | |
674 | ||
675 | void varpool_finalize_decl (tree); | |
676 | bool decide_is_variable_needed (struct varpool_node *, tree); | |
677 | enum availability cgraph_variable_initializer_availability (struct varpool_node *); | |
a550d677 MJ |
678 | void cgraph_make_node_local (struct cgraph_node *); |
679 | bool cgraph_node_can_be_local_p (struct cgraph_node *); | |
8a4a83ed | 680 | |
2942c502 | 681 | |
2942c502 | 682 | void varpool_remove_node (struct varpool_node *node); |
7fece979 | 683 | void varpool_finalize_named_section_flags (struct varpool_node *node); |
65d630d4 | 684 | bool varpool_output_variables (void); |
8a4a83ed | 685 | bool varpool_assemble_decl (struct varpool_node *node); |
66058468 | 686 | void varpool_analyze_node (struct varpool_node *); |
051f8cc6 | 687 | struct varpool_node * varpool_extra_name_alias (tree, tree); |
cd35bcf7 | 688 | struct varpool_node * varpool_create_variable_alias (tree, tree); |
b34fd25c | 689 | void varpool_reset_queue (void); |
64e0f5ff | 690 | bool const_value_known_p (tree); |
cd35bcf7 JH |
691 | bool varpool_for_node_and_aliases (struct varpool_node *, |
692 | bool (*) (struct varpool_node *, void *), | |
693 | void *, bool); | |
38877e98 | 694 | void varpool_add_new_variable (tree); |
8a4a83ed | 695 | |
2aae7680 JH |
696 | /* Return true when NODE is function. */ |
697 | static inline bool | |
698 | symtab_function_p (symtab_node node) | |
699 | { | |
700 | return node->symbol.type == SYMTAB_FUNCTION; | |
701 | } | |
702 | ||
703 | /* Return true when NODE is variable. */ | |
704 | static inline bool | |
705 | symtab_variable_p (symtab_node node) | |
706 | { | |
707 | return node->symbol.type == SYMTAB_VARIABLE; | |
708 | } | |
68e56cc4 | 709 | |
1f00098b JH |
710 | /* Return callgraph node for given symbol and check it is a function. */ |
711 | static inline struct cgraph_node * | |
960bfb69 | 712 | cgraph (symtab_node node) |
1f00098b | 713 | { |
960bfb69 | 714 | gcc_checking_assert (!node || node->symbol.type == SYMTAB_FUNCTION); |
1ab24192 | 715 | return (struct cgraph_node *)node; |
1f00098b JH |
716 | } |
717 | ||
718 | /* Return varpool node for given symbol and check it is a variable. */ | |
719 | static inline struct varpool_node * | |
960bfb69 | 720 | varpool (symtab_node node) |
1f00098b | 721 | { |
960bfb69 | 722 | gcc_checking_assert (!node || node->symbol.type == SYMTAB_VARIABLE); |
1ab24192 | 723 | return (struct varpool_node *)node; |
1f00098b JH |
724 | } |
725 | ||
1ab24192 JH |
726 | /* Return callgraph node for given symbol and check it is a function. */ |
727 | static inline struct cgraph_node * | |
728 | cgraph_get_node (const_tree decl) | |
729 | { | |
730 | gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL); | |
731 | return cgraph (symtab_get_node (decl)); | |
732 | } | |
733 | ||
734 | /* Return varpool node for given symbol and check it is a function. */ | |
735 | static inline struct varpool_node * | |
736 | varpool_get_node (const_tree decl) | |
737 | { | |
738 | gcc_checking_assert (TREE_CODE (decl) == VAR_DECL); | |
739 | return varpool (symtab_get_node (decl)); | |
740 | } | |
741 | ||
8f940ee6 JH |
742 | /* Return asm name of cgraph node. */ |
743 | static inline const char * | |
744 | cgraph_node_asm_name(struct cgraph_node *node) | |
745 | { | |
746 | return symtab_node_asm_name ((symtab_node)node); | |
747 | } | |
748 | ||
749 | /* Return asm name of varpool node. */ | |
750 | static inline const char * | |
751 | varpool_node_asm_name(struct varpool_node *node) | |
752 | { | |
753 | return symtab_node_asm_name ((symtab_node)node); | |
754 | } | |
755 | ||
756 | /* Return name of cgraph node. */ | |
757 | static inline const char * | |
758 | cgraph_node_name(struct cgraph_node *node) | |
759 | { | |
760 | return symtab_node_name ((symtab_node)node); | |
761 | } | |
762 | ||
763 | /* Return name of varpool node. */ | |
764 | static inline const char * | |
765 | varpool_node_name(struct varpool_node *node) | |
766 | { | |
767 | return symtab_node_name ((symtab_node)node); | |
768 | } | |
769 | ||
1ab24192 JH |
770 | /* Walk all symbols. */ |
771 | #define FOR_EACH_SYMBOL(node) \ | |
772 | for ((node) = symtab_nodes; (node); (node) = (node)->symbol.next) | |
1f00098b | 773 | |
66058468 JH |
774 | |
775 | /* Return first variable. */ | |
776 | static inline struct varpool_node * | |
777 | varpool_first_variable (void) | |
778 | { | |
779 | symtab_node node; | |
780 | for (node = symtab_nodes; node; node = node->symbol.next) | |
781 | { | |
782 | if (symtab_variable_p (node)) | |
783 | return varpool (node); | |
784 | } | |
785 | return NULL; | |
786 | } | |
787 | ||
788 | /* Return next variable after NODE. */ | |
789 | static inline struct varpool_node * | |
790 | varpool_next_variable (struct varpool_node *node) | |
791 | { | |
792 | symtab_node node1 = (symtab_node) node->symbol.next; | |
793 | for (; node1; node1 = node1->symbol.next) | |
794 | { | |
795 | if (symtab_variable_p (node1)) | |
796 | return varpool (node1); | |
797 | } | |
798 | return NULL; | |
799 | } | |
800 | /* Walk all variables. */ | |
801 | #define FOR_EACH_VARIABLE(node) \ | |
802 | for ((node) = varpool_first_variable (); \ | |
803 | (node); \ | |
804 | (node) = varpool_next_variable ((node))) | |
805 | ||
68e56cc4 JH |
806 | /* Return first reachable static variable with initializer. */ |
807 | static inline struct varpool_node * | |
808 | varpool_first_static_initializer (void) | |
809 | { | |
66058468 JH |
810 | symtab_node node; |
811 | for (node = symtab_nodes; node; node = node->symbol.next) | |
68e56cc4 | 812 | { |
66058468 JH |
813 | if (symtab_variable_p (node) |
814 | && DECL_INITIAL (node->symbol.decl)) | |
815 | return varpool (node); | |
68e56cc4 JH |
816 | } |
817 | return NULL; | |
818 | } | |
819 | ||
820 | /* Return next reachable static variable with initializer after NODE. */ | |
821 | static inline struct varpool_node * | |
822 | varpool_next_static_initializer (struct varpool_node *node) | |
823 | { | |
66058468 JH |
824 | symtab_node node1 = (symtab_node) node->symbol.next; |
825 | for (; node1; node1 = node1->symbol.next) | |
68e56cc4 | 826 | { |
66058468 JH |
827 | if (symtab_variable_p (node1) |
828 | && DECL_INITIAL (node1->symbol.decl)) | |
829 | return varpool (node1); | |
68e56cc4 JH |
830 | } |
831 | return NULL; | |
832 | } | |
833 | ||
834 | /* Walk all static variables with initializer set. */ | |
835 | #define FOR_EACH_STATIC_INITIALIZER(node) \ | |
836 | for ((node) = varpool_first_static_initializer (); (node); \ | |
837 | (node) = varpool_next_static_initializer (node)) | |
2aae7680 | 838 | |
66058468 | 839 | /* Return first reachable static variable with initializer. */ |
2aae7680 | 840 | static inline struct varpool_node * |
66058468 | 841 | varpool_first_defined_variable (void) |
2aae7680 JH |
842 | { |
843 | symtab_node node; | |
844 | for (node = symtab_nodes; node; node = node->symbol.next) | |
845 | { | |
66058468 | 846 | if (symtab_variable_p (node) && varpool (node)->analyzed) |
2aae7680 JH |
847 | return varpool (node); |
848 | } | |
849 | return NULL; | |
850 | } | |
851 | ||
66058468 | 852 | /* Return next reachable static variable with initializer after NODE. */ |
2aae7680 | 853 | static inline struct varpool_node * |
66058468 | 854 | varpool_next_defined_variable (struct varpool_node *node) |
2aae7680 JH |
855 | { |
856 | symtab_node node1 = (symtab_node) node->symbol.next; | |
857 | for (; node1; node1 = node1->symbol.next) | |
858 | { | |
66058468 | 859 | if (symtab_variable_p (node1) && varpool (node1)->analyzed) |
2aae7680 JH |
860 | return varpool (node1); |
861 | } | |
862 | return NULL; | |
863 | } | |
65c70e6b JH |
864 | /* Walk all variables with definitions in current unit. */ |
865 | #define FOR_EACH_DEFINED_VARIABLE(node) \ | |
66058468 JH |
866 | for ((node) = varpool_first_defined_variable (); (node); \ |
867 | (node) = varpool_next_defined_variable (node)) | |
68e56cc4 | 868 | |
c47d0034 JH |
869 | /* Return first function with body defined. */ |
870 | static inline struct cgraph_node * | |
871 | cgraph_first_defined_function (void) | |
872 | { | |
2aae7680 JH |
873 | symtab_node node; |
874 | for (node = symtab_nodes; node; node = node->symbol.next) | |
c47d0034 | 875 | { |
2aae7680 JH |
876 | if (symtab_function_p (node) && cgraph (node)->analyzed) |
877 | return cgraph (node); | |
c47d0034 JH |
878 | } |
879 | return NULL; | |
880 | } | |
881 | ||
45896127 | 882 | /* Return next function with body defined after NODE. */ |
c47d0034 JH |
883 | static inline struct cgraph_node * |
884 | cgraph_next_defined_function (struct cgraph_node *node) | |
885 | { | |
2aae7680 JH |
886 | symtab_node node1 = (symtab_node) node->symbol.next; |
887 | for (; node1; node1 = node1->symbol.next) | |
c47d0034 | 888 | { |
2aae7680 JH |
889 | if (symtab_function_p (node1) && cgraph (node1)->analyzed) |
890 | return cgraph (node1); | |
c47d0034 JH |
891 | } |
892 | return NULL; | |
893 | } | |
894 | ||
895 | /* Walk all functions with body defined. */ | |
896 | #define FOR_EACH_DEFINED_FUNCTION(node) \ | |
897 | for ((node) = cgraph_first_defined_function (); (node); \ | |
2aae7680 JH |
898 | (node) = cgraph_next_defined_function ((node))) |
899 | ||
900 | /* Return first function. */ | |
901 | static inline struct cgraph_node * | |
902 | cgraph_first_function (void) | |
903 | { | |
904 | symtab_node node; | |
905 | for (node = symtab_nodes; node; node = node->symbol.next) | |
906 | { | |
907 | if (symtab_function_p (node)) | |
908 | return cgraph (node); | |
909 | } | |
910 | return NULL; | |
911 | } | |
912 | ||
913 | /* Return next function. */ | |
914 | static inline struct cgraph_node * | |
915 | cgraph_next_function (struct cgraph_node *node) | |
916 | { | |
917 | symtab_node node1 = (symtab_node) node->symbol.next; | |
918 | for (; node1; node1 = node1->symbol.next) | |
919 | { | |
920 | if (symtab_function_p (node1)) | |
921 | return cgraph (node1); | |
922 | } | |
923 | return NULL; | |
924 | } | |
65c70e6b JH |
925 | /* Walk all functions. */ |
926 | #define FOR_EACH_FUNCTION(node) \ | |
2aae7680 JH |
927 | for ((node) = cgraph_first_function (); (node); \ |
928 | (node) = cgraph_next_function ((node))) | |
c47d0034 JH |
929 | |
930 | /* Return true when NODE is a function with Gimple body defined | |
931 | in current unit. Functions can also be define externally or they | |
932 | can be thunks with no Gimple representation. | |
933 | ||
934 | Note that at WPA stage, the function body may not be present in memory. */ | |
935 | ||
936 | static inline bool | |
937 | cgraph_function_with_gimple_body_p (struct cgraph_node *node) | |
938 | { | |
39e2db00 | 939 | return node->analyzed && !node->thunk.thunk_p && !node->alias; |
c47d0034 JH |
940 | } |
941 | ||
942 | /* Return first function with body defined. */ | |
943 | static inline struct cgraph_node * | |
944 | cgraph_first_function_with_gimple_body (void) | |
945 | { | |
2aae7680 JH |
946 | symtab_node node; |
947 | for (node = symtab_nodes; node; node = node->symbol.next) | |
c47d0034 | 948 | { |
2aae7680 JH |
949 | if (symtab_function_p (node) |
950 | && cgraph_function_with_gimple_body_p (cgraph (node))) | |
951 | return cgraph (node); | |
c47d0034 JH |
952 | } |
953 | return NULL; | |
954 | } | |
955 | ||
956 | /* Return next reachable static variable with initializer after NODE. */ | |
957 | static inline struct cgraph_node * | |
958 | cgraph_next_function_with_gimple_body (struct cgraph_node *node) | |
959 | { | |
2aae7680 JH |
960 | symtab_node node1 = node->symbol.next; |
961 | for (; node1; node1 = node1->symbol.next) | |
c47d0034 | 962 | { |
2aae7680 JH |
963 | if (symtab_function_p (node1) |
964 | && cgraph_function_with_gimple_body_p (cgraph (node1))) | |
965 | return cgraph (node1); | |
c47d0034 JH |
966 | } |
967 | return NULL; | |
968 | } | |
969 | ||
970 | /* Walk all functions with body defined. */ | |
971 | #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \ | |
972 | for ((node) = cgraph_first_function_with_gimple_body (); (node); \ | |
973 | (node) = cgraph_next_function_with_gimple_body (node)) | |
974 | ||
43d861a5 RL |
975 | /* Create a new static variable of type TYPE. */ |
976 | tree add_new_static_var (tree type); | |
977 | ||
fed5ae11 DK |
978 | /* Return true if iterator CSI points to nothing. */ |
979 | static inline bool | |
980 | csi_end_p (cgraph_node_set_iterator csi) | |
981 | { | |
982 | return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes); | |
983 | } | |
984 | ||
985 | /* Advance iterator CSI. */ | |
986 | static inline void | |
987 | csi_next (cgraph_node_set_iterator *csi) | |
988 | { | |
989 | csi->index++; | |
990 | } | |
991 | ||
992 | /* Return the node pointed to by CSI. */ | |
993 | static inline struct cgraph_node * | |
994 | csi_node (cgraph_node_set_iterator csi) | |
995 | { | |
996 | return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index); | |
997 | } | |
998 | ||
999 | /* Return an iterator to the first node in SET. */ | |
1000 | static inline cgraph_node_set_iterator | |
1001 | csi_start (cgraph_node_set set) | |
1002 | { | |
1003 | cgraph_node_set_iterator csi; | |
1004 | ||
1005 | csi.set = set; | |
1006 | csi.index = 0; | |
1007 | return csi; | |
1008 | } | |
1009 | ||
1010 | /* Return true if SET contains NODE. */ | |
1011 | static inline bool | |
1012 | cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set) | |
1013 | { | |
1014 | cgraph_node_set_iterator csi; | |
1015 | csi = cgraph_node_set_find (set, node); | |
1016 | return !csi_end_p (csi); | |
1017 | } | |
1018 | ||
1019 | /* Return number of nodes in SET. */ | |
1020 | static inline size_t | |
1021 | cgraph_node_set_size (cgraph_node_set set) | |
1022 | { | |
1cb1a99f | 1023 | return VEC_length (cgraph_node_ptr, set->nodes); |
fed5ae11 DK |
1024 | } |
1025 | ||
2942c502 JH |
1026 | /* Return true if iterator VSI points to nothing. */ |
1027 | static inline bool | |
1028 | vsi_end_p (varpool_node_set_iterator vsi) | |
1029 | { | |
1030 | return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes); | |
1031 | } | |
1032 | ||
1033 | /* Advance iterator VSI. */ | |
1034 | static inline void | |
1035 | vsi_next (varpool_node_set_iterator *vsi) | |
1036 | { | |
1037 | vsi->index++; | |
1038 | } | |
1039 | ||
1040 | /* Return the node pointed to by VSI. */ | |
1041 | static inline struct varpool_node * | |
1042 | vsi_node (varpool_node_set_iterator vsi) | |
1043 | { | |
1044 | return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index); | |
1045 | } | |
1046 | ||
1047 | /* Return an iterator to the first node in SET. */ | |
1048 | static inline varpool_node_set_iterator | |
1049 | vsi_start (varpool_node_set set) | |
1050 | { | |
1051 | varpool_node_set_iterator vsi; | |
1052 | ||
1053 | vsi.set = set; | |
1054 | vsi.index = 0; | |
1055 | return vsi; | |
1056 | } | |
1057 | ||
1058 | /* Return true if SET contains NODE. */ | |
1059 | static inline bool | |
1060 | varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set) | |
1061 | { | |
1062 | varpool_node_set_iterator vsi; | |
1063 | vsi = varpool_node_set_find (set, node); | |
1064 | return !vsi_end_p (vsi); | |
1065 | } | |
1066 | ||
1067 | /* Return number of nodes in SET. */ | |
1068 | static inline size_t | |
1069 | varpool_node_set_size (varpool_node_set set) | |
1070 | { | |
1cb1a99f | 1071 | return VEC_length (varpool_node_ptr, set->nodes); |
2942c502 JH |
1072 | } |
1073 | ||
d48e9cea OR |
1074 | /* Uniquize all constants that appear in memory. |
1075 | Each constant in memory thus far output is recorded | |
1076 | in `const_desc_table'. */ | |
1077 | ||
1078 | struct GTY(()) constant_descriptor_tree { | |
1079 | /* A MEM for the constant. */ | |
1080 | rtx rtl; | |
b8698a0f | 1081 | |
d48e9cea OR |
1082 | /* The value of the constant. */ |
1083 | tree value; | |
1084 | ||
1085 | /* Hash of value. Computing the hash from value each time | |
1086 | hashfn is called can't work properly, as that means recursive | |
1087 | use of the hash table during hash table expansion. */ | |
1088 | hashval_t hash; | |
1089 | }; | |
1090 | ||
ace72c88 JH |
1091 | /* Return true if set is nonempty. */ |
1092 | static inline bool | |
1093 | cgraph_node_set_nonempty_p (cgraph_node_set set) | |
1094 | { | |
9eec9488 | 1095 | return !VEC_empty (cgraph_node_ptr, set->nodes); |
ace72c88 JH |
1096 | } |
1097 | ||
1098 | /* Return true if set is nonempty. */ | |
1099 | static inline bool | |
1100 | varpool_node_set_nonempty_p (varpool_node_set set) | |
1101 | { | |
9eec9488 | 1102 | return !VEC_empty (varpool_node_ptr, set->nodes); |
ace72c88 JH |
1103 | } |
1104 | ||
be330ed4 | 1105 | /* Return true when function NODE is only called directly or it has alias. |
b20996ff JH |
1106 | i.e. it is not externally visible, address was not taken and |
1107 | it is not used in any other non-standard way. */ | |
1108 | ||
1109 | static inline bool | |
be330ed4 | 1110 | cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node) |
b20996ff | 1111 | { |
530f3a1b | 1112 | gcc_assert (!node->global.inlined_to); |
ead84f73 | 1113 | return (!node->symbol.force_output && !node->symbol.address_taken |
960bfb69 JH |
1114 | && !node->symbol.used_from_other_partition |
1115 | && !DECL_STATIC_CONSTRUCTOR (node->symbol.decl) | |
1116 | && !DECL_STATIC_DESTRUCTOR (node->symbol.decl) | |
1117 | && !node->symbol.externally_visible); | |
b20996ff JH |
1118 | } |
1119 | ||
df7705b1 JH |
1120 | /* Return true when function NODE can be removed from callgraph |
1121 | if all direct calls are eliminated. */ | |
1122 | ||
1123 | static inline bool | |
1124 | varpool_can_remove_if_no_refs (struct varpool_node *node) | |
1125 | { | |
ead84f73 | 1126 | return (!node->symbol.force_output && !node->symbol.used_from_other_partition |
960bfb69 | 1127 | && (DECL_COMDAT (node->symbol.decl) |
ead84f73 | 1128 | || !node->symbol.externally_visible |
0d6bf48c | 1129 | || DECL_HAS_VALUE_EXPR_P (node->symbol.decl) |
ead84f73 | 1130 | || DECL_EXTERNAL (node->symbol.decl))); |
df7705b1 JH |
1131 | } |
1132 | ||
4a444e58 JH |
1133 | /* Return true when all references to VNODE must be visible in ipa_ref_list. |
1134 | i.e. if the variable is not externally visible or not used in some magic | |
1135 | way (asm statement or such). | |
61502ca8 | 1136 | The magic uses are all summarized in force_output flag. */ |
4a444e58 JH |
1137 | |
1138 | static inline bool | |
1139 | varpool_all_refs_explicit_p (struct varpool_node *vnode) | |
1140 | { | |
e8fdf1cd | 1141 | return (vnode->analyzed |
960bfb69 JH |
1142 | && !vnode->symbol.externally_visible |
1143 | && !vnode->symbol.used_from_other_partition | |
ead84f73 | 1144 | && !vnode->symbol.force_output); |
4a444e58 JH |
1145 | } |
1146 | ||
d48e9cea OR |
1147 | /* Constant pool accessor function. */ |
1148 | htab_t constant_pool_htab (void); | |
fed5ae11 | 1149 | |
be330ed4 JH |
1150 | /* FIXME: inappropriate dependency of cgraph on IPA. */ |
1151 | #include "ipa-ref-inline.h" | |
1152 | ||
39e2db00 JH |
1153 | /* Return node that alias N is aliasing. */ |
1154 | ||
1155 | static inline struct cgraph_node * | |
1156 | cgraph_alias_aliased_node (struct cgraph_node *n) | |
1157 | { | |
1158 | struct ipa_ref *ref; | |
1159 | ||
960bfb69 | 1160 | ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref); |
39e2db00 | 1161 | gcc_checking_assert (ref->use == IPA_REF_ALIAS); |
5932a4d4 | 1162 | if (symtab_function_p (ref->referred)) |
39e2db00 JH |
1163 | return ipa_ref_node (ref); |
1164 | return NULL; | |
1165 | } | |
1166 | ||
cd35bcf7 JH |
1167 | /* Return node that alias N is aliasing. */ |
1168 | ||
1169 | static inline struct varpool_node * | |
1170 | varpool_alias_aliased_node (struct varpool_node *n) | |
1171 | { | |
1172 | struct ipa_ref *ref; | |
1173 | ||
960bfb69 | 1174 | ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref); |
cd35bcf7 | 1175 | gcc_checking_assert (ref->use == IPA_REF_ALIAS); |
5932a4d4 | 1176 | if (symtab_variable_p (ref->referred)) |
cd35bcf7 JH |
1177 | return ipa_ref_varpool_node (ref); |
1178 | return NULL; | |
1179 | } | |
1180 | ||
be330ed4 JH |
1181 | /* Given NODE, walk the alias chain to return the function NODE is alias of. |
1182 | Walk through thunk, too. | |
1183 | When AVAILABILITY is non-NULL, get minimal availablity in the chain. */ | |
1184 | ||
1185 | static inline struct cgraph_node * | |
1186 | cgraph_function_node (struct cgraph_node *node, enum availability *availability) | |
1187 | { | |
1188 | if (availability) | |
1189 | *availability = cgraph_function_body_availability (node); | |
1190 | while (node) | |
1191 | { | |
39e2db00 JH |
1192 | if (node->alias && node->analyzed) |
1193 | node = cgraph_alias_aliased_node (node); | |
1194 | else if (node->thunk.thunk_p) | |
be330ed4 JH |
1195 | node = node->callees->callee; |
1196 | else | |
1197 | return node; | |
39e2db00 | 1198 | if (node && availability) |
be330ed4 JH |
1199 | { |
1200 | enum availability a; | |
1201 | a = cgraph_function_body_availability (node); | |
1202 | if (a < *availability) | |
1203 | *availability = a; | |
1204 | } | |
1205 | } | |
9c7c9f10 | 1206 | if (availability) |
39e2db00 | 1207 | *availability = AVAIL_NOT_AVAILABLE; |
be330ed4 JH |
1208 | return NULL; |
1209 | } | |
1210 | ||
1211 | /* Given NODE, walk the alias chain to return the function NODE is alias of. | |
1212 | Do not walk through thunks. | |
1213 | When AVAILABILITY is non-NULL, get minimal availablity in the chain. */ | |
1214 | ||
1215 | static inline struct cgraph_node * | |
1216 | cgraph_function_or_thunk_node (struct cgraph_node *node, enum availability *availability) | |
1217 | { | |
1218 | if (availability) | |
1219 | *availability = cgraph_function_body_availability (node); | |
39e2db00 JH |
1220 | while (node) |
1221 | { | |
1222 | if (node->alias && node->analyzed) | |
1223 | node = cgraph_alias_aliased_node (node); | |
1224 | else | |
1225 | return node; | |
1226 | if (node && availability) | |
1227 | { | |
1228 | enum availability a; | |
1229 | a = cgraph_function_body_availability (node); | |
1230 | if (a < *availability) | |
1231 | *availability = a; | |
1232 | } | |
1233 | } | |
9c7c9f10 | 1234 | if (availability) |
39e2db00 | 1235 | *availability = AVAIL_NOT_AVAILABLE; |
be330ed4 JH |
1236 | return NULL; |
1237 | } | |
1238 | ||
cd35bcf7 JH |
1239 | /* Given NODE, walk the alias chain to return the function NODE is alias of. |
1240 | Do not walk through thunks. | |
1241 | When AVAILABILITY is non-NULL, get minimal availablity in the chain. */ | |
1242 | ||
1243 | static inline struct varpool_node * | |
1244 | varpool_variable_node (struct varpool_node *node, enum availability *availability) | |
1245 | { | |
1246 | if (availability) | |
1247 | *availability = cgraph_variable_initializer_availability (node); | |
1248 | while (node) | |
1249 | { | |
1250 | if (node->alias && node->analyzed) | |
1251 | node = varpool_alias_aliased_node (node); | |
1252 | else | |
1253 | return node; | |
1254 | if (node && availability) | |
1255 | { | |
1256 | enum availability a; | |
1257 | a = cgraph_variable_initializer_availability (node); | |
1258 | if (a < *availability) | |
1259 | *availability = a; | |
1260 | } | |
1261 | } | |
9c7c9f10 | 1262 | if (availability) |
cd35bcf7 JH |
1263 | *availability = AVAIL_NOT_AVAILABLE; |
1264 | return NULL; | |
1265 | } | |
1266 | ||
d7d1d041 RG |
1267 | /* Return true when the edge E represents a direct recursion. */ |
1268 | static inline bool | |
1269 | cgraph_edge_recursive_p (struct cgraph_edge *e) | |
1270 | { | |
be330ed4 | 1271 | struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL); |
d7d1d041 | 1272 | if (e->caller->global.inlined_to) |
960bfb69 | 1273 | return e->caller->global.inlined_to->symbol.decl == callee->symbol.decl; |
d7d1d041 | 1274 | else |
960bfb69 | 1275 | return e->caller->symbol.decl == callee->symbol.decl; |
d7d1d041 | 1276 | } |
0a35513e AH |
1277 | |
1278 | /* Return true if the TM_CLONE bit is set for a given FNDECL. */ | |
1279 | static inline bool | |
1280 | decl_is_tm_clone (const_tree fndecl) | |
1281 | { | |
1282 | struct cgraph_node *n = cgraph_get_node (fndecl); | |
1283 | if (n) | |
1284 | return n->tm_clone; | |
1285 | return false; | |
1286 | } | |
9c8305f8 JH |
1287 | |
1288 | /* Likewise indicate that a node is needed, i.e. reachable via some | |
1289 | external means. */ | |
1290 | ||
1291 | static inline void | |
1292 | cgraph_mark_force_output_node (struct cgraph_node *node) | |
1293 | { | |
1294 | node->symbol.force_output = 1; | |
1295 | gcc_checking_assert (!node->global.inlined_to); | |
1296 | } | |
65d630d4 | 1297 | |
1c4a429a | 1298 | #endif /* GCC_CGRAPH_H */ |