]>
Commit | Line | Data |
---|---|---|
1c4a429a | 1 | /* Callgraph handling code. |
23a5b65a | 2 | Copyright (C) 2003-2014 Free Software Foundation, Inc. |
1c4a429a JH |
3 | Contributed by Jan Hubicka |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
1c4a429a JH |
10 | version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
1c4a429a JH |
20 | |
21 | #ifndef GCC_CGRAPH_H | |
22 | #define GCC_CGRAPH_H | |
7a8cba34 | 23 | |
5d59b5e1 | 24 | #include "is-a.h" |
051f8cc6 | 25 | #include "plugin-api.h" |
7a8cba34 | 26 | #include "vec.h" |
4d648807 | 27 | #include "basic-block.h" |
7a8cba34 | 28 | #include "function.h" |
1f00098b JH |
29 | #include "ipa-ref.h" |
30 | ||
31 | /* Symbol table consists of functions and variables. | |
e70670cf | 32 | TODO: add labels and CONST_DECLs. */ |
1f00098b JH |
33 | enum symtab_type |
34 | { | |
960bfb69 | 35 | SYMTAB_SYMBOL, |
1f00098b JH |
36 | SYMTAB_FUNCTION, |
37 | SYMTAB_VARIABLE | |
38 | }; | |
39 | ||
40 | /* Base of all entries in the symbol table. | |
41 | The symtab_node is inherited by cgraph and varpol nodes. */ | |
a3bfa8b8 DM |
42 | class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"), |
43 | chain_next ("%h.next"), chain_prev ("%h.previous"))) | |
5e20cdc9 | 44 | symtab_node |
1f00098b | 45 | { |
a3bfa8b8 | 46 | public: |
fec39fa6 TS |
47 | /* Return name. */ |
48 | const char *name () const; | |
49 | ||
50 | /* Return asm name. */ | |
51 | const char * asm_name () const; | |
52 | ||
1f00098b | 53 | /* Type of the symbol. */ |
b8dbdb12 RG |
54 | ENUM_BITFIELD (symtab_type) type : 8; |
55 | ||
56 | /* The symbols resolution. */ | |
57 | ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8; | |
58 | ||
e70670cf JH |
59 | /*** Flags representing the symbol type. ***/ |
60 | ||
61 | /* True when symbol corresponds to a definition in current unit. | |
62 | set via cgraph_finalize_function or varpool_finalize_decl */ | |
63 | unsigned definition : 1; | |
64 | /* True when symbol is an alias. | |
65 | Set by assemble_alias. */ | |
66 | unsigned alias : 1; | |
08346abd JH |
67 | /* True when alias is a weakref. */ |
68 | unsigned weakref : 1; | |
40a7fe1e | 69 | /* C++ frontend produce same body aliases and extra name aliases for |
688010ba | 70 | virtual functions and vtables that are obviously equivalent. |
40a7fe1e JH |
71 | Those aliases are bit special, especially because C++ frontend |
72 | visibility code is so ugly it can not get them right at first time | |
73 | and their visibility needs to be copied from their "masters" at | |
74 | the end of parsing. */ | |
75 | unsigned cpp_implicit_alias : 1; | |
e70670cf JH |
76 | /* Set once the definition was analyzed. The list of references and |
77 | other properties are built during analysis. */ | |
78 | unsigned analyzed : 1; | |
6de88c6a JH |
79 | /* Set for write-only variables. */ |
80 | unsigned writeonly : 1; | |
e70670cf JH |
81 | |
82 | ||
83 | /*** Visibility and linkage flags. ***/ | |
84 | ||
b8dbdb12 RG |
85 | /* Set when function is visible by other units. */ |
86 | unsigned externally_visible : 1; | |
4bcfd75c | 87 | /* The symbol will be assumed to be used in an invisible way (like |
edb983b2 | 88 | by an toplevel asm statement). */ |
b8dbdb12 | 89 | unsigned force_output : 1; |
edb983b2 JH |
90 | /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be |
91 | exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted | |
92 | to static and it does not inhibit optimization. */ | |
93 | unsigned forced_by_abi : 1; | |
702d8703 JH |
94 | /* True when the name is known to be unique and thus it does not need mangling. */ |
95 | unsigned unique_name : 1; | |
3d8d0043 MJ |
96 | /* True when body and other characteristics have been removed by |
97 | symtab_remove_unreachable_nodes. */ | |
98 | unsigned body_removed : 1; | |
b8dbdb12 | 99 | |
e70670cf JH |
100 | /*** WHOPR Partitioning flags. |
101 | These flags are used at ltrans stage when only part of the callgraph is | |
102 | available. ***/ | |
b8dbdb12 | 103 | |
e70670cf JH |
104 | /* Set when variable is used from other LTRANS partition. */ |
105 | unsigned used_from_other_partition : 1; | |
106 | /* Set when function is available in the other LTRANS partition. | |
107 | During WPA output it is used to mark nodes that are present in | |
108 | multiple partitions. */ | |
109 | unsigned in_other_partition : 1; | |
b8dbdb12 | 110 | |
b8dbdb12 | 111 | |
e70670cf JH |
112 | |
113 | /*** other flags. ***/ | |
114 | ||
115 | /* Set when symbol has address taken. */ | |
116 | unsigned address_taken : 1; | |
117 | ||
118 | ||
119 | /* Ordering of all symtab entries. */ | |
120 | int order; | |
121 | ||
122 | /* Declaration representing the symbol. */ | |
123 | tree decl; | |
960bfb69 | 124 | |
2aae7680 | 125 | /* Linked list of symbol table entries starting with symtab_nodes. */ |
5e20cdc9 DM |
126 | symtab_node *next; |
127 | symtab_node *previous; | |
e70670cf | 128 | |
1ab24192 | 129 | /* Linked list of symbols with the same asm name. There may be multiple |
e70670cf JH |
130 | entries for single symbol name during LTO, because symbols are renamed |
131 | only after partitioning. | |
132 | ||
133 | Because inline clones are kept in the assembler name has, they also produce | |
134 | duplicate entries. | |
135 | ||
136 | There are also several long standing bugs where frontends and builtin | |
137 | code produce duplicated decls. */ | |
5e20cdc9 DM |
138 | symtab_node *next_sharing_asm_name; |
139 | symtab_node *previous_sharing_asm_name; | |
2aae7680 | 140 | |
e70670cf | 141 | /* Circular list of nodes in the same comdat group if non-NULL. */ |
5e20cdc9 | 142 | symtab_node *same_comdat_group; |
e70670cf | 143 | |
aede2c10 JH |
144 | /* Return comdat group. */ |
145 | tree get_comdat_group () | |
146 | { | |
147 | return comdat_group_; | |
148 | } | |
149 | ||
d67ff7b7 JM |
150 | tree get_comdat_group_id () |
151 | { | |
152 | if (comdat_group_ && TREE_CODE (comdat_group_) != IDENTIFIER_NODE) | |
153 | comdat_group_ = DECL_ASSEMBLER_NAME (comdat_group_); | |
154 | return comdat_group_; | |
155 | } | |
156 | ||
aede2c10 JH |
157 | /* Set comdat group. */ |
158 | void set_comdat_group (tree group) | |
159 | { | |
160 | comdat_group_ = group; | |
161 | } | |
162 | ||
e70670cf JH |
163 | /* Vectors of referring and referenced entities. */ |
164 | struct ipa_ref_list ref_list; | |
165 | ||
40a7fe1e JH |
166 | /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer |
167 | depending to what was known to frontend on the creation time. | |
168 | Once alias is resolved, this pointer become NULL. */ | |
169 | tree alias_target; | |
170 | ||
e70670cf JH |
171 | /* File stream where this node is being written to. */ |
172 | struct lto_file_decl_data * lto_file_data; | |
173 | ||
960bfb69 | 174 | PTR GTY ((skip)) aux; |
aede2c10 JH |
175 | |
176 | /* Comdat group the symbol is in. Can be private if GGC allowed that. */ | |
177 | tree comdat_group_; | |
1f00098b | 178 | }; |
1c4a429a | 179 | |
6b02a499 JH |
180 | enum availability |
181 | { | |
182 | /* Not yet set by cgraph_function_body_availability. */ | |
183 | AVAIL_UNSET, | |
184 | /* Function body/variable initializer is unknown. */ | |
185 | AVAIL_NOT_AVAILABLE, | |
186 | /* Function body/variable initializer is known but might be replaced | |
187 | by a different one from other compilation unit and thus needs to | |
188 | be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have | |
189 | arbitrary side effects on escaping variables and functions, while | |
190 | like AVAILABLE it might access static variables. */ | |
191 | AVAIL_OVERWRITABLE, | |
192 | /* Function body/variable initializer is known and will be used in final | |
193 | program. */ | |
194 | AVAIL_AVAILABLE, | |
195 | /* Function body/variable initializer is known and all it's uses are explicitly | |
196 | visible within current unit (ie it's address is never taken and it is not | |
197 | exported to other units). | |
198 | Currently used only for functions. */ | |
199 | AVAIL_LOCAL | |
200 | }; | |
201 | ||
d7f09764 DN |
202 | /* This is the information that is put into the cgraph local structure |
203 | to recover a function. */ | |
204 | struct lto_file_decl_data; | |
205 | ||
8a4a83ed | 206 | extern const char * const cgraph_availability_names[]; |
430c6ceb | 207 | extern const char * const ld_plugin_symbol_resolution_names[]; |
8a4a83ed | 208 | |
6744a6ab JH |
209 | /* Information about thunk, used only for same body aliases. */ |
210 | ||
211 | struct GTY(()) cgraph_thunk_info { | |
212 | /* Information about the thunk. */ | |
213 | HOST_WIDE_INT fixed_offset; | |
214 | HOST_WIDE_INT virtual_value; | |
215 | tree alias; | |
216 | bool this_adjusting; | |
217 | bool virtual_offset_p; | |
218 | /* Set to true when alias node is thunk. */ | |
219 | bool thunk_p; | |
220 | }; | |
221 | ||
dafc5b82 | 222 | /* Information about the function collected locally. |
25c84396 | 223 | Available after function is analyzed. */ |
dafc5b82 | 224 | |
d1b38208 | 225 | struct GTY(()) cgraph_local_info { |
e0bb17a8 | 226 | /* Set when function function is visible in current compilation unit only |
e2209b03 | 227 | and its address is never taken. */ |
b4e19405 | 228 | unsigned local : 1; |
6674a6ce | 229 | |
124f1be6 MJ |
230 | /* False when there is something makes versioning impossible. */ |
231 | unsigned versionable : 1; | |
232 | ||
61e03ffc JH |
233 | /* False when function calling convention and signature can not be changed. |
234 | This is the case when __builtin_apply_args is used. */ | |
235 | unsigned can_change_signature : 1; | |
236 | ||
95c755e9 JH |
237 | /* True when the function has been originally extern inline, but it is |
238 | redefined now. */ | |
b4e19405 | 239 | unsigned redefined_extern_inline : 1; |
0a35513e AH |
240 | |
241 | /* True if the function may enter serial irrevocable mode. */ | |
242 | unsigned tm_may_enter_irr : 1; | |
dafc5b82 JH |
243 | }; |
244 | ||
245 | /* Information about the function that needs to be computed globally | |
726a989a | 246 | once compilation is finished. Available only with -funit-at-a-time. */ |
dafc5b82 | 247 | |
d1b38208 | 248 | struct GTY(()) cgraph_global_info { |
726a989a RB |
249 | /* For inline clones this points to the function they will be |
250 | inlined into. */ | |
18c6ada9 | 251 | struct cgraph_node *inlined_to; |
dafc5b82 JH |
252 | }; |
253 | ||
b255a036 JH |
254 | /* Information about the function that is propagated by the RTL backend. |
255 | Available only for functions that has been already assembled. */ | |
256 | ||
d1b38208 | 257 | struct GTY(()) cgraph_rtl_info { |
17b29c0a | 258 | unsigned int preferred_incoming_stack_boundary; |
27c07cc5 RO |
259 | |
260 | /* Call unsaved hard registers really used by the corresponding | |
261 | function (including ones used by functions called by the | |
262 | function). */ | |
263 | HARD_REG_SET function_used_regs; | |
264 | /* Set if function_used_regs is valid. */ | |
265 | unsigned function_used_regs_valid: 1; | |
b255a036 JH |
266 | }; |
267 | ||
9187e02d JH |
268 | /* Represent which DECL tree (or reference to such tree) |
269 | will be replaced by another tree while versioning. */ | |
270 | struct GTY(()) ipa_replace_map | |
271 | { | |
272 | /* The tree that will be replaced. */ | |
273 | tree old_tree; | |
274 | /* The new (replacing) tree. */ | |
275 | tree new_tree; | |
922f15c2 JH |
276 | /* Parameter number to replace, when old_tree is NULL. */ |
277 | int parm_num; | |
9187e02d JH |
278 | /* True when a substitution should be done, false otherwise. */ |
279 | bool replace_p; | |
280 | /* True when we replace a reference to old_tree. */ | |
281 | bool ref_p; | |
282 | }; | |
283 | typedef struct ipa_replace_map *ipa_replace_map_p; | |
9187e02d JH |
284 | |
285 | struct GTY(()) cgraph_clone_info | |
286 | { | |
9771b263 | 287 | vec<ipa_replace_map_p, va_gc> *tree_map; |
9187e02d | 288 | bitmap args_to_skip; |
08ad1d6d | 289 | bitmap combined_args_to_skip; |
9187e02d JH |
290 | }; |
291 | ||
0136f8f0 AH |
292 | enum cgraph_simd_clone_arg_type |
293 | { | |
294 | SIMD_CLONE_ARG_TYPE_VECTOR, | |
295 | SIMD_CLONE_ARG_TYPE_UNIFORM, | |
296 | SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP, | |
297 | SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, | |
298 | SIMD_CLONE_ARG_TYPE_MASK | |
299 | }; | |
300 | ||
301 | /* Function arguments in the original function of a SIMD clone. | |
302 | Supplementary data for `struct simd_clone'. */ | |
303 | ||
304 | struct GTY(()) cgraph_simd_clone_arg { | |
305 | /* Original function argument as it originally existed in | |
306 | DECL_ARGUMENTS. */ | |
307 | tree orig_arg; | |
308 | ||
309 | /* orig_arg's function (or for extern functions type from | |
310 | TYPE_ARG_TYPES). */ | |
311 | tree orig_type; | |
312 | ||
313 | /* If argument is a vector, this holds the vector version of | |
314 | orig_arg that after adjusting the argument types will live in | |
315 | DECL_ARGUMENTS. Otherwise, this is NULL. | |
316 | ||
317 | This basically holds: | |
318 | vector(simdlen) __typeof__(orig_arg) new_arg. */ | |
319 | tree vector_arg; | |
320 | ||
321 | /* vector_arg's type (or for extern functions new vector type. */ | |
322 | tree vector_type; | |
323 | ||
324 | /* If argument is a vector, this holds the array where the simd | |
325 | argument is held while executing the simd clone function. This | |
326 | is a local variable in the cloned function. Its content is | |
327 | copied from vector_arg upon entry to the clone. | |
328 | ||
329 | This basically holds: | |
330 | __typeof__(orig_arg) simd_array[simdlen]. */ | |
331 | tree simd_array; | |
332 | ||
333 | /* A SIMD clone's argument can be either linear (constant or | |
334 | variable), uniform, or vector. */ | |
335 | enum cgraph_simd_clone_arg_type arg_type; | |
336 | ||
337 | /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is | |
338 | the constant linear step, if arg_type is | |
339 | SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of | |
340 | the uniform argument holding the step, otherwise 0. */ | |
341 | HOST_WIDE_INT linear_step; | |
342 | ||
343 | /* Variable alignment if available, otherwise 0. */ | |
344 | unsigned int alignment; | |
345 | }; | |
346 | ||
347 | /* Specific data for a SIMD function clone. */ | |
348 | ||
349 | struct GTY(()) cgraph_simd_clone { | |
350 | /* Number of words in the SIMD lane associated with this clone. */ | |
351 | unsigned int simdlen; | |
352 | ||
353 | /* Number of annotated function arguments in `args'. This is | |
354 | usually the number of named arguments in FNDECL. */ | |
355 | unsigned int nargs; | |
356 | ||
357 | /* Max hardware vector size in bits for integral vectors. */ | |
358 | unsigned int vecsize_int; | |
359 | ||
360 | /* Max hardware vector size in bits for floating point vectors. */ | |
361 | unsigned int vecsize_float; | |
362 | ||
363 | /* The mangling character for a given vector size. This is is used | |
364 | to determine the ISA mangling bit as specified in the Intel | |
365 | Vector ABI. */ | |
366 | unsigned char vecsize_mangle; | |
367 | ||
368 | /* True if this is the masked, in-branch version of the clone, | |
369 | otherwise false. */ | |
370 | unsigned int inbranch : 1; | |
371 | ||
372 | /* True if this is a Cilk Plus variant. */ | |
373 | unsigned int cilk_elemental : 1; | |
374 | ||
375 | /* Doubly linked list of SIMD clones. */ | |
376 | struct cgraph_node *prev_clone, *next_clone; | |
377 | ||
378 | /* Original cgraph node the SIMD clones were created for. */ | |
379 | struct cgraph_node *origin; | |
380 | ||
381 | /* Annotated function arguments for the original function. */ | |
382 | struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1]; | |
383 | }; | |
384 | ||
5fefcf92 | 385 | |
ba228239 | 386 | /* The cgraph data structure. |
e0bb17a8 | 387 | Each function decl has assigned cgraph_node listing callees and callers. */ |
1c4a429a | 388 | |
5e20cdc9 | 389 | struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node { |
a3bfa8b8 | 390 | public: |
1c4a429a JH |
391 | struct cgraph_edge *callees; |
392 | struct cgraph_edge *callers; | |
e33c6cd6 MJ |
393 | /* List of edges representing indirect calls with a yet undetermined |
394 | callee. */ | |
395 | struct cgraph_edge *indirect_calls; | |
1c4a429a | 396 | /* For nested functions points to function the node is nested in. */ |
a3bfa8b8 | 397 | struct cgraph_node *origin; |
1c4a429a | 398 | /* Points to first nested function, if any. */ |
a3bfa8b8 | 399 | struct cgraph_node *nested; |
1c4a429a | 400 | /* Pointer to the next function with same origin, if any. */ |
a3bfa8b8 | 401 | struct cgraph_node *next_nested; |
18c6ada9 | 402 | /* Pointer to the next clone. */ |
9187e02d JH |
403 | struct cgraph_node *next_sibling_clone; |
404 | struct cgraph_node *prev_sibling_clone; | |
405 | struct cgraph_node *clones; | |
406 | struct cgraph_node *clone_of; | |
70d539ce JH |
407 | /* For functions with many calls sites it holds map from call expression |
408 | to the edge to speed up cgraph_edge function. */ | |
409 | htab_t GTY((param_is (struct cgraph_edge))) call_site_hash; | |
97ba0040 JH |
410 | /* Declaration node used to be clone of. */ |
411 | tree former_clone_of; | |
c22cacf3 | 412 | |
0136f8f0 AH |
413 | /* If this is a SIMD clone, this points to the SIMD specific |
414 | information for it. */ | |
415 | struct cgraph_simd_clone *simdclone; | |
416 | /* If this function has SIMD clones, this points to the first clone. */ | |
417 | struct cgraph_node *simd_clones; | |
418 | ||
0e3776db JH |
419 | /* Interprocedural passes scheduled to have their transform functions |
420 | applied next time we execute local pass on them. We maintain it | |
421 | per-function in order to allow IPA passes to introduce new functions. */ | |
9771b263 | 422 | vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply; |
0e3776db | 423 | |
95c755e9 JH |
424 | struct cgraph_local_info local; |
425 | struct cgraph_global_info global; | |
426 | struct cgraph_rtl_info rtl; | |
9187e02d | 427 | struct cgraph_clone_info clone; |
6744a6ab | 428 | struct cgraph_thunk_info thunk; |
c22cacf3 | 429 | |
e42922b1 JH |
430 | /* Expected number of executions: calculated in profile.c. */ |
431 | gcov_type count; | |
db0bf14f JH |
432 | /* How to scale counts at materialization time; used to merge |
433 | LTO units with different number of profile runs. */ | |
434 | int count_materialization_scale; | |
95c755e9 JH |
435 | /* Unique id of the node. */ |
436 | int uid; | |
2fa3d31b JH |
437 | /* ID assigned by the profiling. */ |
438 | unsigned int profile_id; | |
86ce5d2f ML |
439 | /* Time profiler: first run of function. */ |
440 | int tp_first_run; | |
3691626c | 441 | |
6b20f353 DS |
442 | /* Set when decl is an abstract function pointed to by the |
443 | ABSTRACT_DECL_ORIGIN of a reachable function. */ | |
c0c123ef | 444 | unsigned used_as_abstract_origin : 1; |
50674e96 | 445 | /* Set once the function is lowered (i.e. its CFG is built). */ |
b4e19405 | 446 | unsigned lowered : 1; |
25c84396 RH |
447 | /* Set once the function has been instantiated and its callee |
448 | lists created. */ | |
257eb6e3 | 449 | unsigned process : 1; |
5fefcf92 JH |
450 | /* How commonly executed the node is. Initialized during branch |
451 | probabilities pass. */ | |
452 | ENUM_BITFIELD (node_frequency) frequency : 2; | |
844db5d0 JH |
453 | /* True when function can only be called at startup (from static ctor). */ |
454 | unsigned only_called_at_startup : 1; | |
455 | /* True when function can only be called at startup (from static dtor). */ | |
456 | unsigned only_called_at_exit : 1; | |
0a35513e AH |
457 | /* True when function is the transactional clone of a function which |
458 | is called only from inside transactions. */ | |
459 | /* ?? We should be able to remove this. We have enough bits in | |
460 | cgraph to calculate it. */ | |
461 | unsigned tm_clone : 1; | |
3649b9b7 ST |
462 | /* True if this decl is a dispatcher for function versions. */ |
463 | unsigned dispatcher_function : 1; | |
1f26ac87 JM |
464 | /* True if this decl calls a COMDAT-local function. This is set up in |
465 | compute_inline_parameters and inline_call. */ | |
466 | unsigned calls_comdat_local : 1; | |
1c4a429a JH |
467 | }; |
468 | ||
7380e6ef | 469 | |
fed5ae11 DK |
470 | typedef struct cgraph_node *cgraph_node_ptr; |
471 | ||
fed5ae11 | 472 | |
3649b9b7 ST |
473 | /* Function Multiversioning info. */ |
474 | struct GTY(()) cgraph_function_version_info { | |
475 | /* The cgraph_node for which the function version info is stored. */ | |
476 | struct cgraph_node *this_node; | |
477 | /* Chains all the semantically identical function versions. The | |
478 | first function in this chain is the version_info node of the | |
479 | default function. */ | |
480 | struct cgraph_function_version_info *prev; | |
481 | /* If this version node corresponds to a dispatcher for function | |
482 | versions, this points to the version info node of the default | |
483 | function, the first node in the chain. */ | |
484 | struct cgraph_function_version_info *next; | |
485 | /* If this node corresponds to a function version, this points | |
486 | to the dispatcher function decl, which is the function that must | |
487 | be called to execute the right function version at run-time. | |
488 | ||
489 | If this cgraph node is a dispatcher (if dispatcher_function is | |
490 | true, in the cgraph_node struct) for function versions, this | |
491 | points to resolver function, which holds the function body of the | |
492 | dispatcher. The dispatcher decl is an alias to the resolver | |
493 | function decl. */ | |
494 | tree dispatcher_resolver; | |
495 | }; | |
496 | ||
497 | /* Get the cgraph_function_version_info node corresponding to node. */ | |
498 | struct cgraph_function_version_info * | |
499 | get_cgraph_node_version (struct cgraph_node *node); | |
500 | ||
501 | /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab | |
502 | corresponding to cgraph_node NODE. */ | |
503 | struct cgraph_function_version_info * | |
504 | insert_new_cgraph_node_version (struct cgraph_node *node); | |
505 | ||
506 | /* Record that DECL1 and DECL2 are semantically identical function | |
507 | versions. */ | |
508 | void record_function_versions (tree decl1, tree decl2); | |
509 | ||
510 | /* Remove the cgraph_function_version_info and cgraph_node for DECL. This | |
511 | DECL is a duplicate declaration. */ | |
512 | void delete_function_version (tree decl); | |
513 | ||
fed5ae11 DK |
514 | /* A cgraph node set is a collection of cgraph nodes. A cgraph node |
515 | can appear in multiple sets. */ | |
1cb1a99f | 516 | struct cgraph_node_set_def |
fed5ae11 | 517 | { |
1cb1a99f | 518 | struct pointer_map_t *map; |
9771b263 | 519 | vec<cgraph_node_ptr> nodes; |
fed5ae11 DK |
520 | }; |
521 | ||
2c8326a5 OE |
522 | class varpool_node; |
523 | typedef varpool_node *varpool_node_ptr; | |
2942c502 | 524 | |
2942c502 JH |
525 | |
526 | /* A varpool node set is a collection of varpool nodes. A varpool node | |
527 | can appear in multiple sets. */ | |
1cb1a99f | 528 | struct varpool_node_set_def |
2942c502 | 529 | { |
1cb1a99f | 530 | struct pointer_map_t * map; |
9771b263 | 531 | vec<varpool_node_ptr> nodes; |
2942c502 JH |
532 | }; |
533 | ||
fed5ae11 DK |
534 | typedef struct cgraph_node_set_def *cgraph_node_set; |
535 | ||
fed5ae11 | 536 | |
2942c502 JH |
537 | typedef struct varpool_node_set_def *varpool_node_set; |
538 | ||
2942c502 | 539 | |
fed5ae11 | 540 | /* Iterator structure for cgraph node sets. */ |
84562394 | 541 | struct cgraph_node_set_iterator |
fed5ae11 DK |
542 | { |
543 | cgraph_node_set set; | |
544 | unsigned index; | |
84562394 | 545 | }; |
fed5ae11 | 546 | |
2942c502 | 547 | /* Iterator structure for varpool node sets. */ |
84562394 | 548 | struct varpool_node_set_iterator |
2942c502 JH |
549 | { |
550 | varpool_node_set set; | |
551 | unsigned index; | |
84562394 | 552 | }; |
2942c502 | 553 | |
1cf11770 | 554 | #define DEFCIFCODE(code, type, string) CIF_ ## code, |
61a05df1 | 555 | /* Reasons for inlining failures. */ |
84562394 | 556 | enum cgraph_inline_failed_t { |
61a05df1 JH |
557 | #include "cif-code.def" |
558 | CIF_N_REASONS | |
84562394 | 559 | }; |
61a05df1 | 560 | |
1cf11770 L |
561 | enum cgraph_inline_failed_type_t |
562 | { | |
563 | CIF_FINAL_NORMAL = 0, | |
564 | CIF_FINAL_ERROR | |
565 | }; | |
566 | ||
e33c6cd6 MJ |
567 | /* Structure containing additional information about an indirect call. */ |
568 | ||
569 | struct GTY(()) cgraph_indirect_call_info | |
570 | { | |
8b7773a4 MJ |
571 | /* When polymorphic is set, this field contains offset where the object which |
572 | was actually used in the polymorphic resides within a larger structure. | |
573 | If agg_contents is set, the field contains the offset within the aggregate | |
574 | from which the address to call was loaded. */ | |
575 | HOST_WIDE_INT offset; | |
b258210c MJ |
576 | /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */ |
577 | HOST_WIDE_INT otr_token; | |
578 | /* Type of the object from OBJ_TYPE_REF_OBJECT. */ | |
68377e53 | 579 | tree otr_type, outer_type; |
e33c6cd6 MJ |
580 | /* Index of the parameter that is called. */ |
581 | int param_index; | |
5f902d76 JH |
582 | /* ECF flags determined from the caller. */ |
583 | int ecf_flags; | |
634ab819 JH |
584 | /* Profile_id of common target obtrained from profile. */ |
585 | int common_target_id; | |
586 | /* Probability that call will land in function with COMMON_TARGET_ID. */ | |
587 | int common_target_probability; | |
b258210c MJ |
588 | |
589 | /* Set when the call is a virtual call with the parameter being the | |
590 | associated object pointer rather than a simple direct call. */ | |
591 | unsigned polymorphic : 1; | |
8b7773a4 MJ |
592 | /* Set when the call is a call of a pointer loaded from contents of an |
593 | aggregate at offset. */ | |
594 | unsigned agg_contents : 1; | |
c13bc3d9 MJ |
595 | /* Set when this is a call through a member pointer. */ |
596 | unsigned member_ptr : 1; | |
8b7773a4 MJ |
597 | /* When the previous bit is set, this one determines whether the destination |
598 | is loaded from a parameter passed by reference. */ | |
599 | unsigned by_ref : 1; | |
68377e53 JH |
600 | unsigned int maybe_in_construction : 1; |
601 | unsigned int maybe_derived_type : 1; | |
e33c6cd6 MJ |
602 | }; |
603 | ||
d1b38208 | 604 | struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge { |
6009ee7b MJ |
605 | /* Expected number of executions: calculated in profile.c. */ |
606 | gcov_type count; | |
ed2df68b JH |
607 | struct cgraph_node *caller; |
608 | struct cgraph_node *callee; | |
2563c224 | 609 | struct cgraph_edge *prev_caller; |
1c4a429a | 610 | struct cgraph_edge *next_caller; |
2563c224 | 611 | struct cgraph_edge *prev_callee; |
1c4a429a | 612 | struct cgraph_edge *next_callee; |
726a989a | 613 | gimple call_stmt; |
e33c6cd6 MJ |
614 | /* Additional information about an indirect call. Not cleared when an edge |
615 | becomes direct. */ | |
616 | struct cgraph_indirect_call_info *indirect_info; | |
18c6ada9 | 617 | PTR GTY ((skip (""))) aux; |
61a05df1 JH |
618 | /* When equal to CIF_OK, inline this call. Otherwise, points to the |
619 | explanation why function was not inlined. */ | |
84562394 | 620 | enum cgraph_inline_failed_t inline_failed; |
6009ee7b MJ |
621 | /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt |
622 | when the function is serialized in. */ | |
623 | unsigned int lto_stmt_uid; | |
b8698a0f | 624 | /* Expected frequency of executions within the function. |
45a80bb9 JH |
625 | When set to CGRAPH_FREQ_BASE, the edge is expected to be called once |
626 | per function call. The range is 0 to CGRAPH_FREQ_MAX. */ | |
627 | int frequency; | |
6009ee7b MJ |
628 | /* Unique id of the edge. */ |
629 | int uid; | |
e33c6cd6 MJ |
630 | /* Whether this edge was made direct by indirect inlining. */ |
631 | unsigned int indirect_inlining_edge : 1; | |
632 | /* Whether this edge describes an indirect call with an undetermined | |
633 | callee. */ | |
634 | unsigned int indirect_unknown_callee : 1; | |
635 | /* Whether this edge is still a dangling */ | |
d7f09764 DN |
636 | /* True if the corresponding CALL stmt cannot be inlined. */ |
637 | unsigned int call_stmt_cannot_inline_p : 1; | |
2505c5ed JH |
638 | /* Can this call throw externally? */ |
639 | unsigned int can_throw_external : 1; | |
042ae7d2 JH |
640 | /* Edges with SPECULATIVE flag represents indirect calls that was |
641 | speculatively turned into direct (i.e. by profile feedback). | |
642 | The final code sequence will have form: | |
643 | ||
644 | if (call_target == expected_fn) | |
645 | expected_fn (); | |
646 | else | |
647 | call_target (); | |
648 | ||
649 | Every speculative call is represented by three components attached | |
650 | to a same call statement: | |
651 | 1) a direct call (to expected_fn) | |
652 | 2) an indirect call (to call_target) | |
653 | 3) a IPA_REF_ADDR refrence to expected_fn. | |
654 | ||
655 | Optimizers may later redirect direct call to clone, so 1) and 3) | |
656 | do not need to necesarily agree with destination. */ | |
657 | unsigned int speculative : 1; | |
1c4a429a JH |
658 | }; |
659 | ||
45a80bb9 JH |
660 | #define CGRAPH_FREQ_BASE 1000 |
661 | #define CGRAPH_FREQ_MAX 100000 | |
662 | ||
b2c0ad40 KH |
663 | typedef struct cgraph_edge *cgraph_edge_p; |
664 | ||
b2c0ad40 | 665 | |
8a4a83ed JH |
666 | /* The varpool data structure. |
667 | Each static variable decl has assigned varpool_node. */ | |
e69529cd | 668 | |
5e20cdc9 | 669 | class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node { |
a3bfa8b8 | 670 | public: |
6b02a499 | 671 | /* Set when variable is scheduled to be assembled. */ |
b4e19405 | 672 | unsigned output : 1; |
eb1d8159 | 673 | |
59b36ecf JJ |
674 | /* Set if the variable is dynamically initialized, except for |
675 | function local statics. */ | |
676 | unsigned dynamically_initialized : 1; | |
e69529cd JH |
677 | }; |
678 | ||
65d630d4 | 679 | /* Every top level asm statement is put into a asm_node. */ |
474eccc6 | 680 | |
65d630d4 | 681 | struct GTY(()) asm_node { |
474eccc6 | 682 | /* Next asm node. */ |
65d630d4 | 683 | struct asm_node *next; |
474eccc6 ILT |
684 | /* String for this asm node. */ |
685 | tree asm_str; | |
686 | /* Ordering of all cgraph nodes. */ | |
687 | int order; | |
688 | }; | |
689 | ||
5d59b5e1 LC |
690 | /* Report whether or not THIS symtab node is a function, aka cgraph_node. */ |
691 | ||
692 | template <> | |
693 | template <> | |
694 | inline bool | |
7de90a6c | 695 | is_a_helper <cgraph_node *>::test (symtab_node *p) |
5d59b5e1 | 696 | { |
67348ccc | 697 | return p->type == SYMTAB_FUNCTION; |
5d59b5e1 LC |
698 | } |
699 | ||
700 | /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */ | |
701 | ||
702 | template <> | |
703 | template <> | |
704 | inline bool | |
7de90a6c | 705 | is_a_helper <varpool_node *>::test (symtab_node *p) |
5d59b5e1 | 706 | { |
67348ccc | 707 | return p->type == SYMTAB_VARIABLE; |
5d59b5e1 LC |
708 | } |
709 | ||
5e20cdc9 | 710 | extern GTY(()) symtab_node *symtab_nodes; |
ed2df68b | 711 | extern GTY(()) int cgraph_n_nodes; |
b58b1157 | 712 | extern GTY(()) int cgraph_max_uid; |
9088c1cc | 713 | extern GTY(()) int cgraph_edge_max_uid; |
dafc5b82 | 714 | extern bool cgraph_global_info_ready; |
f45e0ad1 JH |
715 | enum cgraph_state |
716 | { | |
66058468 JH |
717 | /* Frontend is parsing and finalizing functions. */ |
718 | CGRAPH_STATE_PARSING, | |
f45e0ad1 JH |
719 | /* Callgraph is being constructed. It is safe to add new functions. */ |
720 | CGRAPH_STATE_CONSTRUCTION, | |
ca0f62a8 JH |
721 | /* Callgraph is being at LTO time. */ |
722 | CGRAPH_LTO_STREAMING, | |
f45e0ad1 JH |
723 | /* Callgraph is built and IPA passes are being run. */ |
724 | CGRAPH_STATE_IPA, | |
7a388ee4 JH |
725 | /* Callgraph is built and all functions are transformed to SSA form. */ |
726 | CGRAPH_STATE_IPA_SSA, | |
f45e0ad1 JH |
727 | /* Functions are now ordered and being passed to RTL expanders. */ |
728 | CGRAPH_STATE_EXPANSION, | |
729 | /* All cgraph expansion is done. */ | |
730 | CGRAPH_STATE_FINISHED | |
731 | }; | |
732 | extern enum cgraph_state cgraph_state; | |
e7d6beb0 | 733 | extern bool cgraph_function_flags_ready; |
66058468 | 734 | extern cgraph_node_set cgraph_new_nodes; |
1c4a429a | 735 | |
65d630d4 | 736 | extern GTY(()) struct asm_node *asm_nodes; |
2aae7680 | 737 | extern GTY(()) int symtab_order; |
40a7fe1e | 738 | extern bool cpp_implicit_aliases_done; |
e69529cd | 739 | |
96451279 JH |
740 | /* Classifcation of symbols WRT partitioning. */ |
741 | enum symbol_partitioning_class | |
742 | { | |
743 | /* External declarations are ignored by partitioning algorithms and they are | |
744 | added into the boundary later via compute_ltrans_boundary. */ | |
745 | SYMBOL_EXTERNAL, | |
746 | /* Partitioned symbols are pur into one of partitions. */ | |
747 | SYMBOL_PARTITION, | |
748 | /* Duplicated symbols (such as comdat or constant pool references) are | |
749 | copied into every node needing them via add_symbol_to_partition. */ | |
750 | SYMBOL_DUPLICATE | |
751 | }; | |
752 | ||
753 | ||
2aae7680 | 754 | /* In symtab.c */ |
5e20cdc9 DM |
755 | void symtab_register_node (symtab_node *); |
756 | void symtab_unregister_node (symtab_node *); | |
7b3376a0 | 757 | void symtab_remove_from_same_comdat_group (symtab_node *); |
5e20cdc9 | 758 | void symtab_remove_node (symtab_node *); |
5e20cdc9 | 759 | symtab_node *symtab_node_for_asm (const_tree asmname); |
5e20cdc9 DM |
760 | void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *); |
761 | void symtab_dissolve_same_comdat_group_list (symtab_node *node); | |
8f940ee6 JH |
762 | void dump_symtab (FILE *); |
763 | void debug_symtab (void); | |
5e20cdc9 DM |
764 | void dump_symtab_node (FILE *, symtab_node *); |
765 | void debug_symtab_node (symtab_node *); | |
766 | void dump_symtab_base (FILE *, symtab_node *); | |
474ffc72 | 767 | void verify_symtab (void); |
5e20cdc9 DM |
768 | void verify_symtab_node (symtab_node *); |
769 | bool verify_symtab_base (symtab_node *); | |
770 | bool symtab_used_from_object_file_p (symtab_node *); | |
65d630d4 | 771 | void symtab_make_decl_local (tree); |
5e20cdc9 | 772 | symtab_node *symtab_alias_ultimate_target (symtab_node *, |
40a7fe1e | 773 | enum availability *avail = NULL); |
5e20cdc9 DM |
774 | bool symtab_resolve_alias (symtab_node *node, symtab_node *target); |
775 | void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target); | |
776 | bool symtab_for_node_and_aliases (symtab_node *, | |
777 | bool (*) (symtab_node *, void *), | |
af15184a JH |
778 | void *, |
779 | bool); | |
5e20cdc9 DM |
780 | symtab_node *symtab_nonoverwritable_alias (symtab_node *); |
781 | enum availability symtab_node_availability (symtab_node *); | |
782 | bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *); | |
96451279 | 783 | enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *); |
2aae7680 | 784 | |
1c4a429a | 785 | /* In cgraph.c */ |
439f7bc3 | 786 | void dump_cgraph (FILE *); |
c4e622b6 | 787 | void debug_cgraph (void); |
18c6ada9 | 788 | void dump_cgraph_node (FILE *, struct cgraph_node *); |
c4e622b6 | 789 | void debug_cgraph_node (struct cgraph_node *); |
18c6ada9 | 790 | void cgraph_remove_edge (struct cgraph_edge *); |
439f7bc3 | 791 | void cgraph_remove_node (struct cgraph_node *); |
3a40c18a | 792 | void cgraph_release_function_body (struct cgraph_node *); |
12123452 | 793 | void release_function_body (tree); |
2563c224 | 794 | void cgraph_node_remove_callees (struct cgraph_node *node); |
18c6ada9 JH |
795 | struct cgraph_edge *cgraph_create_edge (struct cgraph_node *, |
796 | struct cgraph_node *, | |
898b8927 | 797 | gimple, gcov_type, int); |
ce47fda3 | 798 | struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple, |
898b8927 | 799 | int, gcov_type, int); |
ce47fda3 | 800 | struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void); |
a358e188 | 801 | struct cgraph_node * cgraph_create_node (tree); |
66a20fc2 | 802 | struct cgraph_node * cgraph_create_empty_node (void); |
a358e188 | 803 | struct cgraph_node * cgraph_get_create_node (tree); |
87e7b310 JH |
804 | struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree); |
805 | struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT, | |
051f8cc6 | 806 | HOST_WIDE_INT, tree, tree); |
4537ec0c | 807 | struct cgraph_node *cgraph_node_for_asm (tree); |
726a989a | 808 | struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple); |
042ae7d2 | 809 | void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true); |
4b685e14 | 810 | void cgraph_update_edges_for_call_stmt (gimple, tree, gimple); |
439f7bc3 AJ |
811 | struct cgraph_local_info *cgraph_local_info (tree); |
812 | struct cgraph_global_info *cgraph_global_info (tree); | |
813 | struct cgraph_rtl_info *cgraph_rtl_info (tree); | |
39e2db00 | 814 | struct cgraph_node *cgraph_create_function_alias (tree, tree); |
66a20fc2 JH |
815 | void cgraph_call_node_duplication_hooks (struct cgraph_node *, |
816 | struct cgraph_node *); | |
817 | void cgraph_call_edge_duplication_hooks (struct cgraph_edge *, | |
818 | struct cgraph_edge *); | |
1c4a429a | 819 | |
18c6ada9 | 820 | void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *); |
042ae7d2 | 821 | struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *); |
be330ed4 | 822 | bool cgraph_only_called_directly_p (struct cgraph_node *); |
e69529cd | 823 | |
1bb17c21 | 824 | bool cgraph_function_possibly_inlined_p (tree); |
e42922b1 | 825 | void cgraph_unnest_node (struct cgraph_node *); |
1bb17c21 | 826 | |
6b02a499 | 827 | enum availability cgraph_function_body_availability (struct cgraph_node *); |
f45e0ad1 | 828 | void cgraph_add_new_function (tree, bool); |
61a05df1 | 829 | const char* cgraph_inline_failed_string (cgraph_inline_failed_t); |
1cf11770 | 830 | cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t); |
6b02a499 | 831 | |
20cdc2be | 832 | void cgraph_set_nothrow_flag (struct cgraph_node *, bool); |
530f3a1b JH |
833 | void cgraph_set_const_flag (struct cgraph_node *, bool, bool); |
834 | void cgraph_set_pure_flag (struct cgraph_node *, bool, bool); | |
d56026c2 JH |
835 | bool cgraph_node_cannot_return (struct cgraph_node *); |
836 | bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *); | |
508e4757 JH |
837 | bool cgraph_will_be_removed_from_program_if_no_direct_calls |
838 | (struct cgraph_node *node); | |
839 | bool cgraph_can_remove_if_no_direct_calls_and_refs_p | |
840 | (struct cgraph_node *node); | |
9aa3f5c5 | 841 | bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node); |
be330ed4 | 842 | bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution); |
be330ed4 JH |
843 | bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *, |
844 | bool (*) (struct cgraph_node *, void *), | |
845 | void *, | |
846 | bool); | |
847 | bool cgraph_for_node_and_aliases (struct cgraph_node *, | |
848 | bool (*) (struct cgraph_node *, void *), | |
849 | void *, bool); | |
9771b263 | 850 | vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node); |
18c6ada9 JH |
851 | void verify_cgraph (void); |
852 | void verify_cgraph_node (struct cgraph_node *); | |
9c8305f8 | 853 | void cgraph_mark_address_taken_node (struct cgraph_node *); |
d7f09764 | 854 | |
9088c1cc MJ |
855 | typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *); |
856 | typedef void (*cgraph_node_hook)(struct cgraph_node *, void *); | |
2c8326a5 | 857 | typedef void (*varpool_node_hook)(varpool_node *, void *); |
9088c1cc MJ |
858 | typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *, |
859 | void *); | |
860 | typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *, | |
861 | void *); | |
862 | struct cgraph_edge_hook_list; | |
863 | struct cgraph_node_hook_list; | |
26e5b0fd | 864 | struct varpool_node_hook_list; |
9088c1cc MJ |
865 | struct cgraph_2edge_hook_list; |
866 | struct cgraph_2node_hook_list; | |
867 | struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *); | |
868 | void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *); | |
869 | struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook, | |
870 | void *); | |
871 | void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *); | |
26e5b0fd JH |
872 | struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook, |
873 | void *); | |
874 | void varpool_remove_node_removal_hook (struct varpool_node_hook_list *); | |
129a37fc JH |
875 | struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook, |
876 | void *); | |
877 | void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *); | |
26e5b0fd JH |
878 | struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook, |
879 | void *); | |
880 | void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *); | |
129a37fc | 881 | void cgraph_call_function_insertion_hooks (struct cgraph_node *node); |
9088c1cc MJ |
882 | struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *); |
883 | void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *); | |
884 | struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *); | |
885 | void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *); | |
8132a837 | 886 | gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *); |
40a7fe1e JH |
887 | struct cgraph_node * cgraph_function_node (struct cgraph_node *, |
888 | enum availability *avail = NULL); | |
a2e2a668 | 889 | bool cgraph_get_body (struct cgraph_node *node); |
09ce3660 | 890 | struct cgraph_edge * |
042ae7d2 JH |
891 | cgraph_turn_edge_to_speculative (struct cgraph_edge *, |
892 | struct cgraph_node *, | |
893 | gcov_type, int); | |
894 | void cgraph_speculative_call_info (struct cgraph_edge *, | |
895 | struct cgraph_edge *&, | |
896 | struct cgraph_edge *&, | |
897 | struct ipa_ref *&); | |
4484a35a | 898 | extern bool gimple_check_call_matching_types (gimple, tree, bool); |
9c8305f8 JH |
899 | |
900 | /* In cgraphunit.c */ | |
65d630d4 | 901 | struct asm_node *add_asm_node (tree); |
9c8305f8 JH |
902 | extern FILE *cgraph_dump_file; |
903 | void cgraph_finalize_function (tree, bool); | |
65d630d4 JH |
904 | void finalize_compilation_unit (void); |
905 | void compile (void); | |
9c8305f8 | 906 | void init_cgraph (void); |
b4d05578 | 907 | void cgraph_process_new_functions (void); |
66a20fc2 | 908 | void cgraph_process_same_body_aliases (void); |
5e20cdc9 | 909 | void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree); |
3649b9b7 ST |
910 | /* Initialize datastructures so DECL is a function in lowered gimple form. |
911 | IN_SSA is true if the gimple is in SSA. */ | |
e70670cf JH |
912 | basic_block init_lowered_empty_function (tree, bool); |
913 | void cgraph_reset_node (struct cgraph_node *); | |
d211e471 | 914 | bool expand_thunk (struct cgraph_node *, bool, bool); |
8be2dc8c ML |
915 | void cgraph_make_wrapper (struct cgraph_node *source, |
916 | struct cgraph_node *target); | |
66a20fc2 JH |
917 | |
918 | /* In cgraphclones.c */ | |
919 | ||
920 | struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *, | |
921 | struct cgraph_node *, gimple, | |
922 | unsigned, gcov_type, int, bool); | |
923 | struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type, | |
9771b263 | 924 | int, bool, vec<cgraph_edge_p>, |
610c8ef0 | 925 | bool, struct cgraph_node *, bitmap); |
66a20fc2 JH |
926 | tree clone_function_name (tree decl, const char *); |
927 | struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node, | |
9771b263 DN |
928 | vec<cgraph_edge_p>, |
929 | vec<ipa_replace_map_p, va_gc> *tree_map, | |
66a20fc2 JH |
930 | bitmap args_to_skip, |
931 | const char *clone_name); | |
932 | struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *); | |
933 | bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *); | |
042ae7d2 JH |
934 | void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple, |
935 | bool update_speculative = true); | |
66a20fc2 JH |
936 | void cgraph_create_edge_including_clones (struct cgraph_node *, |
937 | struct cgraph_node *, | |
938 | gimple, gimple, gcov_type, int, | |
939 | cgraph_inline_failed_t); | |
940 | void cgraph_materialize_all_clones (void); | |
9c8305f8 | 941 | struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *, |
9771b263 | 942 | tree, vec<cgraph_edge_p>, bitmap); |
9c8305f8 | 943 | struct cgraph_node *cgraph_function_versioning (struct cgraph_node *, |
9771b263 DN |
944 | vec<cgraph_edge_p>, |
945 | vec<ipa_replace_map_p, va_gc> *, | |
9c8305f8 JH |
946 | bitmap, bool, bitmap, |
947 | basic_block, const char *); | |
9771b263 | 948 | void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *, |
9c8305f8 | 949 | bool, bitmap, bool, bitmap, basic_block); |
09ce3660 | 950 | struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree); |
9c8305f8 | 951 | |
917948d3 ZD |
952 | /* In cgraphbuild.c */ |
953 | unsigned int rebuild_cgraph_edges (void); | |
99b766fc | 954 | void cgraph_rebuild_references (void); |
9187e02d | 955 | int compute_call_stmt_bb_frequency (tree, basic_block bb); |
9c8305f8 | 956 | void record_references_in_initializer (tree, bool); |
82338059 | 957 | void ipa_record_stmt_references (struct cgraph_node *, gimple); |
917948d3 | 958 | |
ca31b95f | 959 | /* In ipa.c */ |
04142cc3 | 960 | bool symtab_remove_unreachable_nodes (bool, FILE *); |
fed5ae11 DK |
961 | cgraph_node_set cgraph_node_set_new (void); |
962 | cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set, | |
963 | struct cgraph_node *); | |
964 | void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *); | |
965 | void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *); | |
966 | void dump_cgraph_node_set (FILE *, cgraph_node_set); | |
967 | void debug_cgraph_node_set (cgraph_node_set); | |
1cb1a99f | 968 | void free_cgraph_node_set (cgraph_node_set); |
9c8305f8 | 969 | void cgraph_build_static_cdtor (char which, tree body, int priority); |
fed5ae11 | 970 | |
2942c502 JH |
971 | varpool_node_set varpool_node_set_new (void); |
972 | varpool_node_set_iterator varpool_node_set_find (varpool_node_set, | |
2c8326a5 OE |
973 | varpool_node *); |
974 | void varpool_node_set_add (varpool_node_set, varpool_node *); | |
975 | void varpool_node_set_remove (varpool_node_set, varpool_node *); | |
2942c502 JH |
976 | void dump_varpool_node_set (FILE *, varpool_node_set); |
977 | void debug_varpool_node_set (varpool_node_set); | |
1cb1a99f | 978 | void free_varpool_node_set (varpool_node_set); |
4a444e58 | 979 | void ipa_discover_readonly_nonaddressable_vars (void); |
2c8326a5 | 980 | bool varpool_externally_visible_p (varpool_node *); |
ca31b95f | 981 | |
7f7beb3f JH |
982 | /* In ipa-visibility.c */ |
983 | bool cgraph_local_node_p (struct cgraph_node *); | |
d211e471 | 984 | bool address_taken_from_non_vtable_p (symtab_node *node); |
7f7beb3f JH |
985 | |
986 | ||
fed5ae11 | 987 | /* In predict.c */ |
ca30a539 | 988 | bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e); |
e6416b30 | 989 | bool cgraph_optimize_for_size_p (struct cgraph_node *); |
ca30a539 | 990 | |
8a4a83ed | 991 | /* In varpool.c */ |
2c8326a5 OE |
992 | varpool_node *varpool_create_empty_node (void); |
993 | varpool_node *varpool_node_for_decl (tree); | |
994 | varpool_node *varpool_node_for_asm (tree asmname); | |
995 | void varpool_mark_needed_node (varpool_node *); | |
d85478c2 | 996 | void debug_varpool (void); |
8a4a83ed | 997 | void dump_varpool (FILE *); |
2c8326a5 | 998 | void dump_varpool_node (FILE *, varpool_node *); |
8a4a83ed JH |
999 | |
1000 | void varpool_finalize_decl (tree); | |
2c8326a5 | 1001 | enum availability cgraph_variable_initializer_availability (varpool_node *); |
a550d677 MJ |
1002 | void cgraph_make_node_local (struct cgraph_node *); |
1003 | bool cgraph_node_can_be_local_p (struct cgraph_node *); | |
8a4a83ed | 1004 | |
2942c502 | 1005 | |
2c8326a5 OE |
1006 | void varpool_remove_node (varpool_node *node); |
1007 | void varpool_finalize_named_section_flags (varpool_node *node); | |
65d630d4 | 1008 | bool varpool_output_variables (void); |
2c8326a5 OE |
1009 | bool varpool_assemble_decl (varpool_node *node); |
1010 | void varpool_analyze_node (varpool_node *); | |
1011 | varpool_node * varpool_extra_name_alias (tree, tree); | |
1012 | varpool_node * varpool_create_variable_alias (tree, tree); | |
b34fd25c | 1013 | void varpool_reset_queue (void); |
6a6dac52 | 1014 | tree ctor_for_folding (tree); |
2c8326a5 OE |
1015 | bool varpool_for_node_and_aliases (varpool_node *, |
1016 | bool (*) (varpool_node *, void *), | |
cd35bcf7 | 1017 | void *, bool); |
38877e98 | 1018 | void varpool_add_new_variable (tree); |
b5493fb2 | 1019 | void symtab_initialize_asm_name_hash (void); |
5e20cdc9 | 1020 | void symtab_prevail_in_asm_name_hash (symtab_node *node); |
2c8326a5 | 1021 | void varpool_remove_initializer (varpool_node *); |
8a4a83ed | 1022 | |
d8a2d370 DN |
1023 | /* In cgraph.c */ |
1024 | extern void change_decl_assembler_name (tree, tree); | |
68e56cc4 | 1025 | |
aede2c10 JH |
1026 | /* Return symbol table node associated with DECL, if any, |
1027 | and NULL otherwise. */ | |
1028 | ||
1029 | static inline symtab_node * | |
1030 | symtab_get_node (const_tree decl) | |
1031 | { | |
1032 | #ifdef ENABLE_CHECKING | |
1033 | /* Check that we are called for sane type of object - functions | |
1034 | and static or external variables. */ | |
1035 | gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL | |
1036 | || (TREE_CODE (decl) == VAR_DECL | |
1037 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl) | |
1038 | || in_lto_p))); | |
1039 | /* Check that the mapping is sane - perhaps this check can go away, | |
1040 | but at the moment frontends tends to corrupt the mapping by calling | |
1041 | memcpy/memset on the tree nodes. */ | |
1042 | gcc_checking_assert (!decl->decl_with_vis.symtab_node | |
1043 | || decl->decl_with_vis.symtab_node->decl == decl); | |
1044 | #endif | |
1045 | return decl->decl_with_vis.symtab_node; | |
1046 | } | |
1047 | ||
1f00098b JH |
1048 | /* Return callgraph node for given symbol and check it is a function. */ |
1049 | static inline struct cgraph_node * | |
5e20cdc9 | 1050 | cgraph (symtab_node *node) |
1f00098b | 1051 | { |
67348ccc | 1052 | gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION); |
1ab24192 | 1053 | return (struct cgraph_node *)node; |
1f00098b JH |
1054 | } |
1055 | ||
1056 | /* Return varpool node for given symbol and check it is a variable. */ | |
2c8326a5 | 1057 | static inline varpool_node * |
5e20cdc9 | 1058 | varpool (symtab_node *node) |
1f00098b | 1059 | { |
67348ccc | 1060 | gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE); |
2c8326a5 | 1061 | return (varpool_node *)node; |
1f00098b JH |
1062 | } |
1063 | ||
1ab24192 JH |
1064 | /* Return callgraph node for given symbol and check it is a function. */ |
1065 | static inline struct cgraph_node * | |
1066 | cgraph_get_node (const_tree decl) | |
1067 | { | |
1068 | gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL); | |
1069 | return cgraph (symtab_get_node (decl)); | |
1070 | } | |
1071 | ||
1072 | /* Return varpool node for given symbol and check it is a function. */ | |
2c8326a5 | 1073 | static inline varpool_node * |
1ab24192 JH |
1074 | varpool_get_node (const_tree decl) |
1075 | { | |
1076 | gcc_checking_assert (TREE_CODE (decl) == VAR_DECL); | |
1077 | return varpool (symtab_get_node (decl)); | |
1078 | } | |
1079 | ||
1080 | /* Walk all symbols. */ | |
1081 | #define FOR_EACH_SYMBOL(node) \ | |
67348ccc | 1082 | for ((node) = symtab_nodes; (node); (node) = (node)->next) |
1f00098b | 1083 | |
d6d229c6 JH |
1084 | /* Return first static symbol with definition. */ |
1085 | static inline symtab_node * | |
1086 | symtab_first_defined_symbol (void) | |
1087 | { | |
1088 | symtab_node *node; | |
1089 | ||
1090 | for (node = symtab_nodes; node; node = node->next) | |
1091 | if (node->definition) | |
1092 | return node; | |
1093 | ||
1094 | return NULL; | |
1095 | } | |
1096 | ||
1097 | /* Return next reachable static symbol with initializer after NODE. */ | |
1098 | static inline symtab_node * | |
1099 | symtab_next_defined_symbol (symtab_node *node) | |
1100 | { | |
1101 | symtab_node *node1 = node->next; | |
1102 | ||
1103 | for (; node1; node1 = node1->next) | |
1104 | if (node1->definition) | |
1105 | return node1; | |
1106 | ||
1107 | return NULL; | |
1108 | } | |
1109 | /* Walk all symbols with definitions in current unit. */ | |
1110 | #define FOR_EACH_DEFINED_SYMBOL(node) \ | |
1111 | for ((node) = symtab_first_defined_symbol (); (node); \ | |
1112 | (node) = symtab_next_defined_symbol (node)) | |
66058468 JH |
1113 | |
1114 | /* Return first variable. */ | |
2c8326a5 | 1115 | static inline varpool_node * |
66058468 JH |
1116 | varpool_first_variable (void) |
1117 | { | |
5e20cdc9 | 1118 | symtab_node *node; |
67348ccc | 1119 | for (node = symtab_nodes; node; node = node->next) |
7de90a6c | 1120 | if (varpool_node *vnode = dyn_cast <varpool_node *> (node)) |
5d59b5e1 | 1121 | return vnode; |
66058468 JH |
1122 | return NULL; |
1123 | } | |
1124 | ||
1125 | /* Return next variable after NODE. */ | |
2c8326a5 OE |
1126 | static inline varpool_node * |
1127 | varpool_next_variable (varpool_node *node) | |
66058468 | 1128 | { |
5e20cdc9 | 1129 | symtab_node *node1 = node->next; |
67348ccc | 1130 | for (; node1; node1 = node1->next) |
7de90a6c | 1131 | if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1)) |
5d59b5e1 | 1132 | return vnode1; |
66058468 JH |
1133 | return NULL; |
1134 | } | |
1135 | /* Walk all variables. */ | |
1136 | #define FOR_EACH_VARIABLE(node) \ | |
1137 | for ((node) = varpool_first_variable (); \ | |
1138 | (node); \ | |
1139 | (node) = varpool_next_variable ((node))) | |
1140 | ||
d6d229c6 | 1141 | /* Return first static variable with initializer. */ |
2c8326a5 | 1142 | static inline varpool_node * |
68e56cc4 JH |
1143 | varpool_first_static_initializer (void) |
1144 | { | |
5e20cdc9 | 1145 | symtab_node *node; |
67348ccc | 1146 | for (node = symtab_nodes; node; node = node->next) |
68e56cc4 | 1147 | { |
7de90a6c | 1148 | varpool_node *vnode = dyn_cast <varpool_node *> (node); |
67348ccc | 1149 | if (vnode && DECL_INITIAL (node->decl)) |
5d59b5e1 | 1150 | return vnode; |
68e56cc4 JH |
1151 | } |
1152 | return NULL; | |
1153 | } | |
1154 | ||
d6d229c6 | 1155 | /* Return next static variable with initializer after NODE. */ |
2c8326a5 OE |
1156 | static inline varpool_node * |
1157 | varpool_next_static_initializer (varpool_node *node) | |
68e56cc4 | 1158 | { |
5e20cdc9 | 1159 | symtab_node *node1 = node->next; |
67348ccc | 1160 | for (; node1; node1 = node1->next) |
68e56cc4 | 1161 | { |
7de90a6c | 1162 | varpool_node *vnode1 = dyn_cast <varpool_node *> (node1); |
67348ccc | 1163 | if (vnode1 && DECL_INITIAL (node1->decl)) |
5d59b5e1 | 1164 | return vnode1; |
68e56cc4 JH |
1165 | } |
1166 | return NULL; | |
1167 | } | |
1168 | ||
1169 | /* Walk all static variables with initializer set. */ | |
1170 | #define FOR_EACH_STATIC_INITIALIZER(node) \ | |
1171 | for ((node) = varpool_first_static_initializer (); (node); \ | |
1172 | (node) = varpool_next_static_initializer (node)) | |
2aae7680 | 1173 | |
d6d229c6 | 1174 | /* Return first static variable with definition. */ |
2c8326a5 | 1175 | static inline varpool_node * |
66058468 | 1176 | varpool_first_defined_variable (void) |
2aae7680 | 1177 | { |
5e20cdc9 | 1178 | symtab_node *node; |
67348ccc | 1179 | for (node = symtab_nodes; node; node = node->next) |
2aae7680 | 1180 | { |
7de90a6c | 1181 | varpool_node *vnode = dyn_cast <varpool_node *> (node); |
67348ccc | 1182 | if (vnode && vnode->definition) |
5d59b5e1 | 1183 | return vnode; |
2aae7680 JH |
1184 | } |
1185 | return NULL; | |
1186 | } | |
1187 | ||
d6d229c6 | 1188 | /* Return next static variable with definition after NODE. */ |
2c8326a5 OE |
1189 | static inline varpool_node * |
1190 | varpool_next_defined_variable (varpool_node *node) | |
2aae7680 | 1191 | { |
5e20cdc9 | 1192 | symtab_node *node1 = node->next; |
67348ccc | 1193 | for (; node1; node1 = node1->next) |
2aae7680 | 1194 | { |
7de90a6c | 1195 | varpool_node *vnode1 = dyn_cast <varpool_node *> (node1); |
67348ccc | 1196 | if (vnode1 && vnode1->definition) |
5d59b5e1 | 1197 | return vnode1; |
2aae7680 JH |
1198 | } |
1199 | return NULL; | |
1200 | } | |
65c70e6b JH |
1201 | /* Walk all variables with definitions in current unit. */ |
1202 | #define FOR_EACH_DEFINED_VARIABLE(node) \ | |
66058468 JH |
1203 | for ((node) = varpool_first_defined_variable (); (node); \ |
1204 | (node) = varpool_next_defined_variable (node)) | |
68e56cc4 | 1205 | |
c47d0034 JH |
1206 | /* Return first function with body defined. */ |
1207 | static inline struct cgraph_node * | |
1208 | cgraph_first_defined_function (void) | |
1209 | { | |
5e20cdc9 | 1210 | symtab_node *node; |
67348ccc | 1211 | for (node = symtab_nodes; node; node = node->next) |
c47d0034 | 1212 | { |
7de90a6c | 1213 | cgraph_node *cn = dyn_cast <cgraph_node *> (node); |
67348ccc | 1214 | if (cn && cn->definition) |
5d59b5e1 | 1215 | return cn; |
c47d0034 JH |
1216 | } |
1217 | return NULL; | |
1218 | } | |
1219 | ||
45896127 | 1220 | /* Return next function with body defined after NODE. */ |
c47d0034 JH |
1221 | static inline struct cgraph_node * |
1222 | cgraph_next_defined_function (struct cgraph_node *node) | |
1223 | { | |
5e20cdc9 | 1224 | symtab_node *node1 = node->next; |
67348ccc | 1225 | for (; node1; node1 = node1->next) |
c47d0034 | 1226 | { |
7de90a6c | 1227 | cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1); |
67348ccc | 1228 | if (cn1 && cn1->definition) |
5d59b5e1 | 1229 | return cn1; |
c47d0034 JH |
1230 | } |
1231 | return NULL; | |
1232 | } | |
1233 | ||
1234 | /* Walk all functions with body defined. */ | |
1235 | #define FOR_EACH_DEFINED_FUNCTION(node) \ | |
1236 | for ((node) = cgraph_first_defined_function (); (node); \ | |
2aae7680 JH |
1237 | (node) = cgraph_next_defined_function ((node))) |
1238 | ||
1239 | /* Return first function. */ | |
1240 | static inline struct cgraph_node * | |
1241 | cgraph_first_function (void) | |
1242 | { | |
5e20cdc9 | 1243 | symtab_node *node; |
67348ccc | 1244 | for (node = symtab_nodes; node; node = node->next) |
7de90a6c | 1245 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (node)) |
5d59b5e1 | 1246 | return cn; |
2aae7680 JH |
1247 | return NULL; |
1248 | } | |
1249 | ||
1250 | /* Return next function. */ | |
1251 | static inline struct cgraph_node * | |
1252 | cgraph_next_function (struct cgraph_node *node) | |
1253 | { | |
5e20cdc9 | 1254 | symtab_node *node1 = node->next; |
67348ccc | 1255 | for (; node1; node1 = node1->next) |
7de90a6c | 1256 | if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1)) |
5d59b5e1 | 1257 | return cn1; |
2aae7680 JH |
1258 | return NULL; |
1259 | } | |
65c70e6b JH |
1260 | /* Walk all functions. */ |
1261 | #define FOR_EACH_FUNCTION(node) \ | |
2aae7680 JH |
1262 | for ((node) = cgraph_first_function (); (node); \ |
1263 | (node) = cgraph_next_function ((node))) | |
c47d0034 JH |
1264 | |
1265 | /* Return true when NODE is a function with Gimple body defined | |
1266 | in current unit. Functions can also be define externally or they | |
1267 | can be thunks with no Gimple representation. | |
1268 | ||
1269 | Note that at WPA stage, the function body may not be present in memory. */ | |
1270 | ||
1271 | static inline bool | |
1272 | cgraph_function_with_gimple_body_p (struct cgraph_node *node) | |
1273 | { | |
67348ccc | 1274 | return node->definition && !node->thunk.thunk_p && !node->alias; |
c47d0034 JH |
1275 | } |
1276 | ||
1277 | /* Return first function with body defined. */ | |
1278 | static inline struct cgraph_node * | |
1279 | cgraph_first_function_with_gimple_body (void) | |
1280 | { | |
5e20cdc9 | 1281 | symtab_node *node; |
67348ccc | 1282 | for (node = symtab_nodes; node; node = node->next) |
c47d0034 | 1283 | { |
7de90a6c | 1284 | cgraph_node *cn = dyn_cast <cgraph_node *> (node); |
5d59b5e1 LC |
1285 | if (cn && cgraph_function_with_gimple_body_p (cn)) |
1286 | return cn; | |
c47d0034 JH |
1287 | } |
1288 | return NULL; | |
1289 | } | |
1290 | ||
1291 | /* Return next reachable static variable with initializer after NODE. */ | |
1292 | static inline struct cgraph_node * | |
1293 | cgraph_next_function_with_gimple_body (struct cgraph_node *node) | |
1294 | { | |
5e20cdc9 | 1295 | symtab_node *node1 = node->next; |
67348ccc | 1296 | for (; node1; node1 = node1->next) |
c47d0034 | 1297 | { |
7de90a6c | 1298 | cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1); |
5d59b5e1 LC |
1299 | if (cn1 && cgraph_function_with_gimple_body_p (cn1)) |
1300 | return cn1; | |
c47d0034 JH |
1301 | } |
1302 | return NULL; | |
1303 | } | |
1304 | ||
1305 | /* Walk all functions with body defined. */ | |
1306 | #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \ | |
1307 | for ((node) = cgraph_first_function_with_gimple_body (); (node); \ | |
1308 | (node) = cgraph_next_function_with_gimple_body (node)) | |
1309 | ||
43d861a5 RL |
1310 | /* Create a new static variable of type TYPE. */ |
1311 | tree add_new_static_var (tree type); | |
1312 | ||
fed5ae11 DK |
1313 | /* Return true if iterator CSI points to nothing. */ |
1314 | static inline bool | |
1315 | csi_end_p (cgraph_node_set_iterator csi) | |
1316 | { | |
9771b263 | 1317 | return csi.index >= csi.set->nodes.length (); |
fed5ae11 DK |
1318 | } |
1319 | ||
1320 | /* Advance iterator CSI. */ | |
1321 | static inline void | |
1322 | csi_next (cgraph_node_set_iterator *csi) | |
1323 | { | |
1324 | csi->index++; | |
1325 | } | |
1326 | ||
1327 | /* Return the node pointed to by CSI. */ | |
1328 | static inline struct cgraph_node * | |
1329 | csi_node (cgraph_node_set_iterator csi) | |
1330 | { | |
9771b263 | 1331 | return csi.set->nodes[csi.index]; |
fed5ae11 DK |
1332 | } |
1333 | ||
1334 | /* Return an iterator to the first node in SET. */ | |
1335 | static inline cgraph_node_set_iterator | |
1336 | csi_start (cgraph_node_set set) | |
1337 | { | |
1338 | cgraph_node_set_iterator csi; | |
1339 | ||
1340 | csi.set = set; | |
1341 | csi.index = 0; | |
1342 | return csi; | |
1343 | } | |
1344 | ||
1345 | /* Return true if SET contains NODE. */ | |
1346 | static inline bool | |
1347 | cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set) | |
1348 | { | |
1349 | cgraph_node_set_iterator csi; | |
1350 | csi = cgraph_node_set_find (set, node); | |
1351 | return !csi_end_p (csi); | |
1352 | } | |
1353 | ||
1354 | /* Return number of nodes in SET. */ | |
1355 | static inline size_t | |
1356 | cgraph_node_set_size (cgraph_node_set set) | |
1357 | { | |
9771b263 | 1358 | return set->nodes.length (); |
fed5ae11 DK |
1359 | } |
1360 | ||
2942c502 JH |
1361 | /* Return true if iterator VSI points to nothing. */ |
1362 | static inline bool | |
1363 | vsi_end_p (varpool_node_set_iterator vsi) | |
1364 | { | |
9771b263 | 1365 | return vsi.index >= vsi.set->nodes.length (); |
2942c502 JH |
1366 | } |
1367 | ||
1368 | /* Advance iterator VSI. */ | |
1369 | static inline void | |
1370 | vsi_next (varpool_node_set_iterator *vsi) | |
1371 | { | |
1372 | vsi->index++; | |
1373 | } | |
1374 | ||
1375 | /* Return the node pointed to by VSI. */ | |
2c8326a5 | 1376 | static inline varpool_node * |
2942c502 JH |
1377 | vsi_node (varpool_node_set_iterator vsi) |
1378 | { | |
9771b263 | 1379 | return vsi.set->nodes[vsi.index]; |
2942c502 JH |
1380 | } |
1381 | ||
1382 | /* Return an iterator to the first node in SET. */ | |
1383 | static inline varpool_node_set_iterator | |
1384 | vsi_start (varpool_node_set set) | |
1385 | { | |
1386 | varpool_node_set_iterator vsi; | |
1387 | ||
1388 | vsi.set = set; | |
1389 | vsi.index = 0; | |
1390 | return vsi; | |
1391 | } | |
1392 | ||
1393 | /* Return true if SET contains NODE. */ | |
1394 | static inline bool | |
2c8326a5 | 1395 | varpool_node_in_set_p (varpool_node *node, varpool_node_set set) |
2942c502 JH |
1396 | { |
1397 | varpool_node_set_iterator vsi; | |
1398 | vsi = varpool_node_set_find (set, node); | |
1399 | return !vsi_end_p (vsi); | |
1400 | } | |
1401 | ||
1402 | /* Return number of nodes in SET. */ | |
1403 | static inline size_t | |
1404 | varpool_node_set_size (varpool_node_set set) | |
1405 | { | |
9771b263 | 1406 | return set->nodes.length (); |
2942c502 JH |
1407 | } |
1408 | ||
d48e9cea OR |
1409 | /* Uniquize all constants that appear in memory. |
1410 | Each constant in memory thus far output is recorded | |
1411 | in `const_desc_table'. */ | |
1412 | ||
1413 | struct GTY(()) constant_descriptor_tree { | |
1414 | /* A MEM for the constant. */ | |
1415 | rtx rtl; | |
b8698a0f | 1416 | |
d48e9cea OR |
1417 | /* The value of the constant. */ |
1418 | tree value; | |
1419 | ||
1420 | /* Hash of value. Computing the hash from value each time | |
1421 | hashfn is called can't work properly, as that means recursive | |
1422 | use of the hash table during hash table expansion. */ | |
1423 | hashval_t hash; | |
1424 | }; | |
1425 | ||
ace72c88 JH |
1426 | /* Return true if set is nonempty. */ |
1427 | static inline bool | |
1428 | cgraph_node_set_nonempty_p (cgraph_node_set set) | |
1429 | { | |
9771b263 | 1430 | return !set->nodes.is_empty (); |
ace72c88 JH |
1431 | } |
1432 | ||
1433 | /* Return true if set is nonempty. */ | |
1434 | static inline bool | |
1435 | varpool_node_set_nonempty_p (varpool_node_set set) | |
1436 | { | |
9771b263 | 1437 | return !set->nodes.is_empty (); |
ace72c88 JH |
1438 | } |
1439 | ||
be330ed4 | 1440 | /* Return true when function NODE is only called directly or it has alias. |
b20996ff JH |
1441 | i.e. it is not externally visible, address was not taken and |
1442 | it is not used in any other non-standard way. */ | |
1443 | ||
1444 | static inline bool | |
be330ed4 | 1445 | cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node) |
b20996ff | 1446 | { |
530f3a1b | 1447 | gcc_assert (!node->global.inlined_to); |
67348ccc DM |
1448 | return (!node->force_output && !node->address_taken |
1449 | && !node->used_from_other_partition | |
1450 | && !DECL_VIRTUAL_P (node->decl) | |
1451 | && !DECL_STATIC_CONSTRUCTOR (node->decl) | |
1452 | && !DECL_STATIC_DESTRUCTOR (node->decl) | |
1453 | && !node->externally_visible); | |
b20996ff JH |
1454 | } |
1455 | ||
df7705b1 JH |
1456 | /* Return true when function NODE can be removed from callgraph |
1457 | if all direct calls are eliminated. */ | |
1458 | ||
1459 | static inline bool | |
2c8326a5 | 1460 | varpool_can_remove_if_no_refs (varpool_node *node) |
df7705b1 | 1461 | { |
67348ccc | 1462 | if (DECL_EXTERNAL (node->decl)) |
6649df51 | 1463 | return true; |
67348ccc DM |
1464 | return (!node->force_output && !node->used_from_other_partition |
1465 | && ((DECL_COMDAT (node->decl) | |
1466 | && !node->forced_by_abi | |
1467 | && !symtab_used_from_object_file_p (node)) | |
1468 | || !node->externally_visible | |
1469 | || DECL_HAS_VALUE_EXPR_P (node->decl))); | |
df7705b1 JH |
1470 | } |
1471 | ||
4a444e58 JH |
1472 | /* Return true when all references to VNODE must be visible in ipa_ref_list. |
1473 | i.e. if the variable is not externally visible or not used in some magic | |
1474 | way (asm statement or such). | |
61502ca8 | 1475 | The magic uses are all summarized in force_output flag. */ |
4a444e58 JH |
1476 | |
1477 | static inline bool | |
2c8326a5 | 1478 | varpool_all_refs_explicit_p (varpool_node *vnode) |
4a444e58 | 1479 | { |
67348ccc DM |
1480 | return (vnode->definition |
1481 | && !vnode->externally_visible | |
1482 | && !vnode->used_from_other_partition | |
1483 | && !vnode->force_output); | |
4a444e58 JH |
1484 | } |
1485 | ||
d48e9cea OR |
1486 | /* Constant pool accessor function. */ |
1487 | htab_t constant_pool_htab (void); | |
fed5ae11 | 1488 | |
be330ed4 JH |
1489 | /* FIXME: inappropriate dependency of cgraph on IPA. */ |
1490 | #include "ipa-ref-inline.h" | |
1491 | ||
39e2db00 JH |
1492 | /* Return node that alias N is aliasing. */ |
1493 | ||
5e20cdc9 DM |
1494 | static inline symtab_node * |
1495 | symtab_alias_target (symtab_node *n) | |
39e2db00 JH |
1496 | { |
1497 | struct ipa_ref *ref; | |
67348ccc | 1498 | ipa_ref_list_reference_iterate (&n->ref_list, 0, ref); |
39e2db00 | 1499 | gcc_checking_assert (ref->use == IPA_REF_ALIAS); |
e70670cf | 1500 | return ref->referred; |
39e2db00 JH |
1501 | } |
1502 | ||
e70670cf JH |
1503 | static inline struct cgraph_node * |
1504 | cgraph_alias_target (struct cgraph_node *n) | |
cd35bcf7 | 1505 | { |
7de90a6c | 1506 | return dyn_cast <cgraph_node *> (symtab_alias_target (n)); |
cd35bcf7 JH |
1507 | } |
1508 | ||
2c8326a5 OE |
1509 | static inline varpool_node * |
1510 | varpool_alias_target (varpool_node *n) | |
be330ed4 | 1511 | { |
7de90a6c | 1512 | return dyn_cast <varpool_node *> (symtab_alias_target (n)); |
be330ed4 JH |
1513 | } |
1514 | ||
1515 | /* Given NODE, walk the alias chain to return the function NODE is alias of. | |
1516 | Do not walk through thunks. | |
073a8998 | 1517 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ |
be330ed4 JH |
1518 | |
1519 | static inline struct cgraph_node * | |
40a7fe1e JH |
1520 | cgraph_function_or_thunk_node (struct cgraph_node *node, |
1521 | enum availability *availability = NULL) | |
be330ed4 | 1522 | { |
e70670cf JH |
1523 | struct cgraph_node *n; |
1524 | ||
7de90a6c DM |
1525 | n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node, |
1526 | availability)); | |
40a7fe1e | 1527 | if (!n && availability) |
39e2db00 | 1528 | *availability = AVAIL_NOT_AVAILABLE; |
e70670cf | 1529 | return n; |
be330ed4 | 1530 | } |
cd35bcf7 JH |
1531 | /* Given NODE, walk the alias chain to return the function NODE is alias of. |
1532 | Do not walk through thunks. | |
073a8998 | 1533 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ |
cd35bcf7 | 1534 | |
2c8326a5 OE |
1535 | static inline varpool_node * |
1536 | varpool_variable_node (varpool_node *node, | |
40a7fe1e | 1537 | enum availability *availability = NULL) |
cd35bcf7 | 1538 | { |
2c8326a5 | 1539 | varpool_node *n; |
e70670cf | 1540 | |
ff36fcbe | 1541 | if (node) |
7de90a6c DM |
1542 | n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node, |
1543 | availability)); | |
ff36fcbe EB |
1544 | else |
1545 | n = NULL; | |
1546 | ||
40a7fe1e | 1547 | if (!n && availability) |
cd35bcf7 | 1548 | *availability = AVAIL_NOT_AVAILABLE; |
e70670cf | 1549 | return n; |
cd35bcf7 JH |
1550 | } |
1551 | ||
d7d1d041 RG |
1552 | /* Return true when the edge E represents a direct recursion. */ |
1553 | static inline bool | |
1554 | cgraph_edge_recursive_p (struct cgraph_edge *e) | |
1555 | { | |
be330ed4 | 1556 | struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL); |
d7d1d041 | 1557 | if (e->caller->global.inlined_to) |
67348ccc | 1558 | return e->caller->global.inlined_to->decl == callee->decl; |
d7d1d041 | 1559 | else |
67348ccc | 1560 | return e->caller->decl == callee->decl; |
d7d1d041 | 1561 | } |
0a35513e AH |
1562 | |
1563 | /* Return true if the TM_CLONE bit is set for a given FNDECL. */ | |
1564 | static inline bool | |
1565 | decl_is_tm_clone (const_tree fndecl) | |
1566 | { | |
1567 | struct cgraph_node *n = cgraph_get_node (fndecl); | |
1568 | if (n) | |
1569 | return n->tm_clone; | |
1570 | return false; | |
1571 | } | |
9c8305f8 JH |
1572 | |
1573 | /* Likewise indicate that a node is needed, i.e. reachable via some | |
1574 | external means. */ | |
1575 | ||
1576 | static inline void | |
1577 | cgraph_mark_force_output_node (struct cgraph_node *node) | |
1578 | { | |
67348ccc | 1579 | node->force_output = 1; |
9c8305f8 JH |
1580 | gcc_checking_assert (!node->global.inlined_to); |
1581 | } | |
65d630d4 | 1582 | |
b5493fb2 | 1583 | /* Return true when the symbol is real symbol, i.e. it is not inline clone |
e70670cf | 1584 | or abstract function kept for debug info purposes only. */ |
b5493fb2 JH |
1585 | |
1586 | static inline bool | |
5e20cdc9 | 1587 | symtab_real_symbol_p (symtab_node *node) |
b5493fb2 JH |
1588 | { |
1589 | struct cgraph_node *cnode; | |
b5493fb2 | 1590 | |
67348ccc | 1591 | if (DECL_ABSTRACT (node->decl)) |
c0c123ef | 1592 | return false; |
7de90a6c | 1593 | if (!is_a <cgraph_node *> (node)) |
b5493fb2 JH |
1594 | return true; |
1595 | cnode = cgraph (node); | |
1596 | if (cnode->global.inlined_to) | |
1597 | return false; | |
b5493fb2 JH |
1598 | return true; |
1599 | } | |
09ce3660 JH |
1600 | |
1601 | /* Return true if NODE can be discarded by linker from the binary. */ | |
1602 | ||
1603 | static inline bool | |
5e20cdc9 | 1604 | symtab_can_be_discarded (symtab_node *node) |
09ce3660 | 1605 | { |
67348ccc | 1606 | return (DECL_EXTERNAL (node->decl) |
aede2c10 | 1607 | || (node->get_comdat_group () |
67348ccc DM |
1608 | && node->resolution != LDPR_PREVAILING_DEF |
1609 | && node->resolution != LDPR_PREVAILING_DEF_IRONLY | |
1610 | && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP)); | |
09ce3660 | 1611 | } |
1f26ac87 JM |
1612 | |
1613 | /* Return true if NODE is local to a particular COMDAT group, and must not | |
1614 | be named from outside the COMDAT. This is used for C++ decloned | |
1615 | constructors. */ | |
1616 | ||
1617 | static inline bool | |
1618 | symtab_comdat_local_p (symtab_node *node) | |
1619 | { | |
1620 | return (node->same_comdat_group && !TREE_PUBLIC (node->decl)); | |
1621 | } | |
1622 | ||
1623 | /* Return true if ONE and TWO are part of the same COMDAT group. */ | |
1624 | ||
1625 | static inline bool | |
1626 | symtab_in_same_comdat_p (symtab_node *one, symtab_node *two) | |
1627 | { | |
d6d229c6 JH |
1628 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (one)) |
1629 | { | |
1630 | if (cn->global.inlined_to) | |
1631 | one = cn->global.inlined_to; | |
1632 | } | |
1633 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (two)) | |
1634 | { | |
1635 | if (cn->global.inlined_to) | |
1636 | two = cn->global.inlined_to; | |
1637 | } | |
1638 | ||
aede2c10 JH |
1639 | return one->get_comdat_group () == two->get_comdat_group (); |
1640 | } | |
1c4a429a | 1641 | #endif /* GCC_CGRAPH_H */ |