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