]>
Commit | Line | Data |
---|---|---|
1c4a429a | 1 | /* Callgraph handling code. |
99dee823 | 2 | Copyright (C) 2003-2021 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 | |
3995f3a2 | 24 | #include "profile-count.h" |
f0889939 AM |
25 | #include "ipa-ref.h" |
26 | #include "plugin-api.h" | |
ff6686d2 | 27 | #include "ipa-param-manipulation.h" |
f0889939 | 28 | |
efd9eb29 TV |
29 | extern void debuginfo_early_init (void); |
30 | extern void debuginfo_init (void); | |
31 | extern void debuginfo_fini (void); | |
32 | extern void debuginfo_start (void); | |
33 | extern void debuginfo_stop (void); | |
34 | extern void debuginfo_early_start (void); | |
35 | extern void debuginfo_early_stop (void); | |
36 | ||
f0889939 AM |
37 | class ipa_opt_pass_d; |
38 | typedef ipa_opt_pass_d *ipa_opt_pass; | |
1f00098b JH |
39 | |
40 | /* Symbol table consists of functions and variables. | |
e70670cf | 41 | TODO: add labels and CONST_DECLs. */ |
1f00098b JH |
42 | enum symtab_type |
43 | { | |
960bfb69 | 44 | SYMTAB_SYMBOL, |
1f00098b JH |
45 | SYMTAB_FUNCTION, |
46 | SYMTAB_VARIABLE | |
47 | }; | |
48 | ||
f961457f JH |
49 | /* Section names are stored as reference counted strings in GGC safe hashtable |
50 | (to make them survive through PCH). */ | |
51 | ||
50686850 | 52 | struct GTY((for_user)) section_hash_entry |
f961457f JH |
53 | { |
54 | int ref_count; | |
67914693 | 55 | char *name; /* As long as this datastructure stays in GGC, we cannot put |
f961457f JH |
56 | string at the tail of structure of GGC dies in horrible |
57 | way */ | |
58 | }; | |
59 | ||
ca752f39 | 60 | struct section_name_hasher : ggc_ptr_hash<section_hash_entry> |
2a22f99c TS |
61 | { |
62 | typedef const char *compare_type; | |
63 | ||
64 | static hashval_t hash (section_hash_entry *); | |
65 | static bool equal (section_hash_entry *, const char *); | |
66 | }; | |
67 | ||
d52f5295 ML |
68 | enum availability |
69 | { | |
70 | /* Not yet set by cgraph_function_body_availability. */ | |
71 | AVAIL_UNSET, | |
72 | /* Function body/variable initializer is unknown. */ | |
73 | AVAIL_NOT_AVAILABLE, | |
74 | /* Function body/variable initializer is known but might be replaced | |
75 | by a different one from other compilation unit and thus needs to | |
76 | be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have | |
77 | arbitrary side effects on escaping variables and functions, while | |
78 | like AVAILABLE it might access static variables. */ | |
79 | AVAIL_INTERPOSABLE, | |
80 | /* Function body/variable initializer is known and will be used in final | |
81 | program. */ | |
82 | AVAIL_AVAILABLE, | |
83 | /* Function body/variable initializer is known and all it's uses are | |
dfea3d6f JJ |
84 | explicitly visible within current unit (i.e. it's address is never taken |
85 | and it is not exported to other units). Currently used only for | |
86 | functions. */ | |
d52f5295 ML |
87 | AVAIL_LOCAL |
88 | }; | |
89 | ||
90 | /* Classification of symbols WRT partitioning. */ | |
91 | enum symbol_partitioning_class | |
92 | { | |
93 | /* External declarations are ignored by partitioning algorithms and they are | |
94 | added into the boundary later via compute_ltrans_boundary. */ | |
95 | SYMBOL_EXTERNAL, | |
dfea3d6f | 96 | /* Partitioned symbols are put into one of partitions. */ |
d52f5295 ML |
97 | SYMBOL_PARTITION, |
98 | /* Duplicated symbols (such as comdat or constant pool references) are | |
99 | copied into every node needing them via add_symbol_to_partition. */ | |
100 | SYMBOL_DUPLICATE | |
101 | }; | |
102 | ||
1f00098b JH |
103 | /* Base of all entries in the symbol table. |
104 | The symtab_node is inherited by cgraph and varpol nodes. */ | |
6c1dae73 MS |
105 | struct GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"), |
106 | chain_next ("%h.next"), chain_prev ("%h.previous"))) | |
5e20cdc9 | 107 | symtab_node |
1f00098b | 108 | { |
a3bfa8b8 | 109 | public: |
4325656f ML |
110 | friend class symbol_table; |
111 | ||
a65d584d ML |
112 | /* Constructor. */ |
113 | explicit symtab_node (symtab_type t) | |
114 | : type (t), resolution (LDPR_UNKNOWN), definition (false), alias (false), | |
115 | transparent_alias (false), weakref (false), cpp_implicit_alias (false), | |
116 | symver (false), analyzed (false), writeonly (false), | |
117 | refuse_visibility_changes (false), externally_visible (false), | |
118 | no_reorder (false), force_output (false), forced_by_abi (false), | |
119 | unique_name (false), implicit_section (false), body_removed (false), | |
120 | used_from_other_partition (false), in_other_partition (false), | |
121 | address_taken (false), in_init_priority_hash (false), | |
122 | need_lto_streaming (false), offloadable (false), ifunc_resolver (false), | |
123 | order (false), next_sharing_asm_name (NULL), | |
124 | previous_sharing_asm_name (NULL), same_comdat_group (NULL), ref_list (), | |
125 | alias_target (NULL), lto_file_data (NULL), aux (NULL), | |
126 | x_comdat_group (NULL_TREE), x_section (NULL) | |
127 | {} | |
128 | ||
fec39fa6 TS |
129 | /* Return name. */ |
130 | const char *name () const; | |
131 | ||
464d0118 ML |
132 | /* Return dump name. */ |
133 | const char *dump_name () const; | |
134 | ||
fec39fa6 | 135 | /* Return asm name. */ |
464d0118 ML |
136 | const char *asm_name () const; |
137 | ||
138 | /* Return dump name with assembler name. */ | |
139 | const char *dump_asm_name () const; | |
fec39fa6 | 140 | |
66d62d9f HK |
141 | /* Return visibility name. */ |
142 | const char *get_visibility_string () const; | |
143 | ||
144 | /* Return type_name name. */ | |
145 | const char *get_symtab_type_string () const; | |
146 | ||
d52f5295 ML |
147 | /* Add node into symbol table. This function is not used directly, but via |
148 | cgraph/varpool node creation routines. */ | |
149 | void register_symbol (void); | |
150 | ||
151 | /* Remove symbol from symbol table. */ | |
152 | void remove (void); | |
153 | ||
154 | /* Dump symtab node to F. */ | |
155 | void dump (FILE *f); | |
156 | ||
34e64622 GB |
157 | /* Dump symtab callgraph in graphviz format. */ |
158 | void dump_graphviz (FILE *f); | |
159 | ||
d52f5295 ML |
160 | /* Dump symtab node to stderr. */ |
161 | void DEBUG_FUNCTION debug (void); | |
162 | ||
163 | /* Verify consistency of node. */ | |
164 | void DEBUG_FUNCTION verify (void); | |
165 | ||
166 | /* Return ipa reference from this symtab_node to | |
dfea3d6f | 167 | REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type |
d52f5295 | 168 | of the use and STMT the statement (if it exists). */ |
3dafb85c ML |
169 | ipa_ref *create_reference (symtab_node *referred_node, |
170 | enum ipa_ref_use use_type); | |
d52f5295 ML |
171 | |
172 | /* Return ipa reference from this symtab_node to | |
dfea3d6f | 173 | REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type |
d52f5295 | 174 | of the use and STMT the statement (if it exists). */ |
3dafb85c | 175 | ipa_ref *create_reference (symtab_node *referred_node, |
355fe088 | 176 | enum ipa_ref_use use_type, gimple *stmt); |
d52f5295 ML |
177 | |
178 | /* If VAL is a reference to a function or a variable, add a reference from | |
2d8d3ae2 | 179 | this symtab_node to the corresponding symbol table node. Return the new |
d52f5295 | 180 | reference or NULL if none was created. */ |
2d8d3ae2 | 181 | ipa_ref *maybe_create_reference (tree val, gimple *stmt); |
d52f5295 ML |
182 | |
183 | /* Clone all references from symtab NODE to this symtab_node. */ | |
184 | void clone_references (symtab_node *node); | |
185 | ||
186 | /* Remove all stmt references in non-speculative references. | |
187 | Those are not maintained during inlining & clonning. | |
188 | The exception are speculative references that are updated along | |
189 | with callgraph edges associated with them. */ | |
190 | void clone_referring (symtab_node *node); | |
191 | ||
192 | /* Clone reference REF to this symtab_node and set its stmt to STMT. */ | |
355fe088 | 193 | ipa_ref *clone_reference (ipa_ref *ref, gimple *stmt); |
d52f5295 ML |
194 | |
195 | /* Find the structure describing a reference to REFERRED_NODE | |
196 | and associated with statement STMT. */ | |
355fe088 | 197 | ipa_ref *find_reference (symtab_node *referred_node, gimple *stmt, |
3dafb85c | 198 | unsigned int lto_stmt_uid); |
d52f5295 ML |
199 | |
200 | /* Remove all references that are associated with statement STMT. */ | |
355fe088 | 201 | void remove_stmt_references (gimple *stmt); |
d52f5295 ML |
202 | |
203 | /* Remove all stmt references in non-speculative references. | |
204 | Those are not maintained during inlining & clonning. | |
205 | The exception are speculative references that are updated along | |
206 | with callgraph edges associated with them. */ | |
207 | void clear_stmts_in_references (void); | |
208 | ||
209 | /* Remove all references in ref list. */ | |
210 | void remove_all_references (void); | |
211 | ||
212 | /* Remove all referring items in ref list. */ | |
213 | void remove_all_referring (void); | |
214 | ||
215 | /* Dump references in ref list to FILE. */ | |
216 | void dump_references (FILE *file); | |
217 | ||
218 | /* Dump referring in list to FILE. */ | |
219 | void dump_referring (FILE *); | |
220 | ||
b84d4347 ML |
221 | /* Get number of references for this node. */ |
222 | inline unsigned num_references (void) | |
223 | { | |
7144270e | 224 | return ref_list.references.length (); |
b84d4347 ML |
225 | } |
226 | ||
d52f5295 | 227 | /* Iterates I-th reference in the list, REF is also set. */ |
3dafb85c | 228 | ipa_ref *iterate_reference (unsigned i, ipa_ref *&ref); |
d52f5295 ML |
229 | |
230 | /* Iterates I-th referring item in the list, REF is also set. */ | |
3dafb85c | 231 | ipa_ref *iterate_referring (unsigned i, ipa_ref *&ref); |
d52f5295 ML |
232 | |
233 | /* Iterates I-th referring alias item in the list, REF is also set. */ | |
3dafb85c | 234 | ipa_ref *iterate_direct_aliases (unsigned i, ipa_ref *&ref); |
d52f5295 ML |
235 | |
236 | /* Return true if symtab node and TARGET represents | |
237 | semantically equivalent symbols. */ | |
238 | bool semantically_equivalent_p (symtab_node *target); | |
239 | ||
240 | /* Classify symbol symtab node for partitioning. */ | |
241 | enum symbol_partitioning_class get_partitioning_class (void); | |
242 | ||
243 | /* Return comdat group. */ | |
244 | tree get_comdat_group () | |
245 | { | |
246 | return x_comdat_group; | |
247 | } | |
248 | ||
249 | /* Return comdat group as identifier_node. */ | |
250 | tree get_comdat_group_id () | |
251 | { | |
252 | if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE) | |
253 | x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group); | |
254 | return x_comdat_group; | |
255 | } | |
256 | ||
257 | /* Set comdat group. */ | |
258 | void set_comdat_group (tree group) | |
259 | { | |
260 | gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE | |
261 | || DECL_P (group)); | |
262 | x_comdat_group = group; | |
263 | } | |
264 | ||
265 | /* Return section as string. */ | |
8b9a92f7 | 266 | const char * get_section () const |
d52f5295 ML |
267 | { |
268 | if (!x_section) | |
269 | return NULL; | |
270 | return x_section->name; | |
271 | } | |
272 | ||
273 | /* Remove node from same comdat group. */ | |
274 | void remove_from_same_comdat_group (void); | |
275 | ||
276 | /* Add this symtab_node to the same comdat group that OLD is in. */ | |
277 | void add_to_same_comdat_group (symtab_node *old_node); | |
278 | ||
279 | /* Dissolve the same_comdat_group list in which NODE resides. */ | |
280 | void dissolve_same_comdat_group_list (void); | |
281 | ||
282 | /* Return true when symtab_node is known to be used from other (non-LTO) | |
283 | object file. Known only when doing LTO via linker plugin. */ | |
284 | bool used_from_object_file_p (void); | |
285 | ||
286 | /* Walk the alias chain to return the symbol NODE is alias of. | |
287 | If NODE is not an alias, return NODE. | |
f13fe18b JH |
288 | When AVAILABILITY is non-NULL, get minimal availability in the chain. |
289 | When REF is non-NULL, assume that reference happens in symbol REF | |
290 | when determining the availability. */ | |
291 | symtab_node *ultimate_alias_target (enum availability *avail = NULL, | |
292 | struct symtab_node *ref = NULL); | |
d52f5295 ML |
293 | |
294 | /* Return next reachable static symbol with initializer after NODE. */ | |
295 | inline symtab_node *next_defined_symbol (void); | |
296 | ||
297 | /* Add reference recording that symtab node is alias of TARGET. | |
71e54687 | 298 | If TRANSPARENT is true make the alias to be transparent alias. |
d52f5295 ML |
299 | The function can fail in the case of aliasing cycles; in this case |
300 | it returns false. */ | |
71e54687 | 301 | bool resolve_alias (symtab_node *target, bool transparent = false); |
d52f5295 ML |
302 | |
303 | /* C++ FE sometimes change linkage flags after producing same | |
304 | body aliases. */ | |
305 | void fixup_same_cpp_alias_visibility (symtab_node *target); | |
306 | ||
6cbde2e3 | 307 | /* Call callback on symtab node and aliases associated to this node. |
d52f5295 | 308 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are |
6cbde2e3 | 309 | skipped. */ |
d52f5295 | 310 | bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *), |
a6a543bf JH |
311 | void *data, |
312 | bool include_overwrite); | |
d52f5295 | 313 | |
67914693 | 314 | /* If node cannot be interposable by static or dynamic linker to point to |
d52f5295 ML |
315 | different definition, return this symbol. Otherwise look for alias with |
316 | such property and if none exists, introduce new one. */ | |
317 | symtab_node *noninterposable_alias (void); | |
318 | ||
319 | /* Return node that alias is aliasing. */ | |
320 | inline symtab_node *get_alias_target (void); | |
321 | ||
f8e7f3f3 JM |
322 | /* Return DECL that alias is aliasing. */ |
323 | inline tree get_alias_target_tree (); | |
324 | ||
d52f5295 ML |
325 | /* Set section for symbol and its aliases. */ |
326 | void set_section (const char *section); | |
327 | ||
8b9a92f7 SN |
328 | /* Like set_section, but copying the section name from another node. */ |
329 | void set_section (const symtab_node &other); | |
330 | ||
d52f5295 ML |
331 | /* Set section, do not recurse into aliases. |
332 | When one wants to change section of symbol and its aliases, | |
333 | use set_section. */ | |
334 | void set_section_for_node (const char *section); | |
335 | ||
46564615 SN |
336 | /* Like set_section_for_node, but copying the section name from another |
337 | node. */ | |
338 | void set_section_for_node (const symtab_node &other); | |
339 | ||
d52f5295 ML |
340 | /* Set initialization priority to PRIORITY. */ |
341 | void set_init_priority (priority_type priority); | |
342 | ||
343 | /* Return the initialization priority. */ | |
344 | priority_type get_init_priority (); | |
345 | ||
f13fe18b JH |
346 | /* Return availability of NODE when referenced from REF. */ |
347 | enum availability get_availability (symtab_node *ref = NULL); | |
348 | ||
f714ecf5 JH |
349 | /* During LTO stream-in this predicate can be used to check whether node |
350 | in question prevails in the linking to save some memory usage. */ | |
351 | bool prevailing_p (void); | |
352 | ||
f13fe18b JH |
353 | /* Return true if NODE binds to current definition in final executable |
354 | when referenced from REF. If REF is NULL return conservative value | |
355 | for any reference. */ | |
356 | bool binds_to_current_def_p (symtab_node *ref = NULL); | |
d52f5295 ML |
357 | |
358 | /* Make DECL local. */ | |
359 | void make_decl_local (void); | |
360 | ||
ed2a53e7 JH |
361 | /* Copy visibility from N. */ |
362 | void copy_visibility_from (symtab_node *n); | |
363 | ||
428f0c67 JH |
364 | /* Return desired alignment of the definition. This is NOT alignment useful |
365 | to access THIS, because THIS may be interposable and DECL_ALIGN should | |
366 | be used instead. It however must be guaranteed when output definition | |
367 | of THIS. */ | |
368 | unsigned int definition_alignment (); | |
369 | ||
370 | /* Return true if alignment can be increased. */ | |
371 | bool can_increase_alignment_p (); | |
372 | ||
373 | /* Increase alignment of symbol to ALIGN. */ | |
374 | void increase_alignment (unsigned int align); | |
375 | ||
d52f5295 ML |
376 | /* Return true if list contains an alias. */ |
377 | bool has_aliases_p (void); | |
378 | ||
379 | /* Return true when the symbol is real symbol, i.e. it is not inline clone | |
380 | or abstract function kept for debug info purposes only. */ | |
381 | bool real_symbol_p (void); | |
382 | ||
39aa9b23 JH |
383 | /* Return true when the symbol needs to be output to the LTO symbol table. */ |
384 | bool output_to_lto_symbol_table_p (void); | |
385 | ||
3dafb85c ML |
386 | /* Determine if symbol declaration is needed. That is, visible to something |
387 | either outside this translation unit, something magic in the system | |
388 | configury. This function is used just during symbol creation. */ | |
389 | bool needed_p (void); | |
390 | ||
c2e84327 DM |
391 | /* Return true if this symbol is a function from the C frontend specified |
392 | directly in RTL form (with "__RTL"). */ | |
393 | bool native_rtl_p () const; | |
394 | ||
3dafb85c | 395 | /* Return true when there are references to the node. */ |
d7438551 | 396 | bool referred_to_p (bool include_self = true); |
3dafb85c | 397 | |
f1703a2e JH |
398 | /* Return true if symbol can be discarded by linker from the binary. |
399 | Assume that symbol is used (so there is no need to take into account | |
400 | garbage collecting linkers) | |
401 | ||
dfea3d6f | 402 | This can happen for comdats, commons and weaks when they are prevailed |
f1703a2e | 403 | by other definition at static linking time. */ |
d52f5295 ML |
404 | inline bool |
405 | can_be_discarded_p (void) | |
406 | { | |
407 | return (DECL_EXTERNAL (decl) | |
f1703a2e JH |
408 | || ((get_comdat_group () |
409 | || DECL_COMMON (decl) | |
410 | || (DECL_SECTION_NAME (decl) && DECL_WEAK (decl))) | |
411 | && ((resolution != LDPR_PREVAILING_DEF | |
412 | && resolution != LDPR_PREVAILING_DEF_IRONLY_EXP) | |
413 | || flag_incremental_link) | |
414 | && resolution != LDPR_PREVAILING_DEF_IRONLY)); | |
d52f5295 ML |
415 | } |
416 | ||
417 | /* Return true if NODE is local to a particular COMDAT group, and must not | |
418 | be named from outside the COMDAT. This is used for C++ decloned | |
419 | constructors. */ | |
420 | inline bool comdat_local_p (void) | |
421 | { | |
422 | return (same_comdat_group && !TREE_PUBLIC (decl)); | |
423 | } | |
424 | ||
425 | /* Return true if ONE and TWO are part of the same COMDAT group. */ | |
426 | inline bool in_same_comdat_group_p (symtab_node *target); | |
427 | ||
d52f5295 ML |
428 | /* Return true if symbol is known to be nonzero. */ |
429 | bool nonzero_address (); | |
430 | ||
3cb251b7 JH |
431 | /* Return 0 if symbol is known to have different address than S2, |
432 | Return 1 if symbol is known to have same address as S2, | |
b2539e1e JH |
433 | return 2 otherwise. |
434 | ||
435 | If MEMORY_ACCESSED is true, assume that both memory pointer to THIS | |
436 | and S2 is going to be accessed. This eliminates the situations when | |
dfea3d6f | 437 | either THIS or S2 is NULL and is useful for comparing bases when deciding |
b2539e1e JH |
438 | about memory aliasing. */ |
439 | int equal_address_to (symtab_node *s2, bool memory_accessed = false); | |
3cb251b7 | 440 | |
0a7246ee JH |
441 | /* Return true if symbol's address may possibly be compared to other |
442 | symbol's address. */ | |
443 | bool address_matters_p (); | |
444 | ||
445 | /* Return true if NODE's address can be compared. This use properties | |
446 | of NODE only and does not look if the address is actually taken in | |
447 | interesting way. For that use ADDRESS_MATTERS_P instead. */ | |
448 | bool address_can_be_compared_p (void); | |
449 | ||
d52f5295 ML |
450 | /* Return symbol table node associated with DECL, if any, |
451 | and NULL otherwise. */ | |
452 | static inline symtab_node *get (const_tree decl) | |
453 | { | |
d52f5295 ML |
454 | /* Check that we are called for sane type of object - functions |
455 | and static or external variables. */ | |
456 | gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL | |
457 | || (TREE_CODE (decl) == VAR_DECL | |
458 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl) | |
459 | || in_lto_p))); | |
460 | /* Check that the mapping is sane - perhaps this check can go away, | |
461 | but at the moment frontends tends to corrupt the mapping by calling | |
462 | memcpy/memset on the tree nodes. */ | |
463 | gcc_checking_assert (!decl->decl_with_vis.symtab_node | |
464 | || decl->decl_with_vis.symtab_node->decl == decl); | |
d52f5295 ML |
465 | return decl->decl_with_vis.symtab_node; |
466 | } | |
467 | ||
f7217cde JH |
468 | /* Try to find a symtab node for declaration DECL and if it does not |
469 | exist or if it corresponds to an inline clone, create a new one. */ | |
470 | static inline symtab_node * get_create (tree node); | |
471 | ||
3dafb85c ML |
472 | /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME. |
473 | Return NULL if there's no such node. */ | |
474 | static symtab_node *get_for_asmname (const_tree asmname); | |
475 | ||
d52f5295 ML |
476 | /* Verify symbol table for internal consistency. */ |
477 | static DEBUG_FUNCTION void verify_symtab_nodes (void); | |
478 | ||
b2b29377 MM |
479 | /* Perform internal consistency checks, if they are enabled. */ |
480 | static inline void checking_verify_symtab_nodes (void); | |
481 | ||
1f00098b | 482 | /* Type of the symbol. */ |
b8dbdb12 RG |
483 | ENUM_BITFIELD (symtab_type) type : 8; |
484 | ||
485 | /* The symbols resolution. */ | |
486 | ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8; | |
487 | ||
e70670cf JH |
488 | /*** Flags representing the symbol type. ***/ |
489 | ||
490 | /* True when symbol corresponds to a definition in current unit. | |
3dafb85c | 491 | set via finalize_function or finalize_decl */ |
e70670cf | 492 | unsigned definition : 1; |
9041d2e6 | 493 | /* True when symbol is an alias. |
dfea3d6f | 494 | Set by assemble_alias. */ |
e70670cf | 495 | unsigned alias : 1; |
71e54687 JH |
496 | /* When true the alias is translated into its target symbol either by GCC |
497 | or assembler (it also may just be a duplicate declaration of the same | |
498 | linker name). | |
499 | ||
500 | Currently transparent aliases come in three different flavors | |
501 | - aliases having the same assembler name as their target (aka duplicated | |
502 | declarations). In this case the assembler names compare via | |
503 | assembler_names_equal_p and weakref is false | |
504 | - aliases that are renamed at a time being output to final file | |
505 | by varasm.c. For those DECL_ASSEMBLER_NAME have | |
506 | IDENTIFIER_TRANSPARENT_ALIAS set and thus also their assembler | |
507 | name must be unique. | |
dfea3d6f | 508 | Weakrefs belong to this category when we target assembler without |
71e54687 JH |
509 | .weakref directive. |
510 | - weakrefs that are renamed by assembler via .weakref directive. | |
511 | In this case the alias may or may not be definition (depending if | |
512 | target declaration was seen by the compiler), weakref is set. | |
513 | Unless we are before renaming statics, assembler names are different. | |
514 | ||
515 | Given that we now support duplicate declarations, the second option is | |
516 | redundant and will be removed. */ | |
517 | unsigned transparent_alias : 1; | |
08346abd JH |
518 | /* True when alias is a weakref. */ |
519 | unsigned weakref : 1; | |
40a7fe1e | 520 | /* C++ frontend produce same body aliases and extra name aliases for |
688010ba | 521 | virtual functions and vtables that are obviously equivalent. |
40a7fe1e | 522 | Those aliases are bit special, especially because C++ frontend |
67914693 | 523 | visibility code is so ugly it cannot get them right at first time |
40a7fe1e JH |
524 | and their visibility needs to be copied from their "masters" at |
525 | the end of parsing. */ | |
526 | unsigned cpp_implicit_alias : 1; | |
d7ddfbcb JH |
527 | /* The alias is a symbol version. */ |
528 | unsigned symver : 1; | |
e70670cf JH |
529 | /* Set once the definition was analyzed. The list of references and |
530 | other properties are built during analysis. */ | |
531 | unsigned analyzed : 1; | |
6de88c6a JH |
532 | /* Set for write-only variables. */ |
533 | unsigned writeonly : 1; | |
f7217cde JH |
534 | /* Visibility of symbol was used for further optimization; do not |
535 | permit further changes. */ | |
536 | unsigned refuse_visibility_changes : 1; | |
e70670cf JH |
537 | |
538 | /*** Visibility and linkage flags. ***/ | |
539 | ||
b8dbdb12 RG |
540 | /* Set when function is visible by other units. */ |
541 | unsigned externally_visible : 1; | |
7861b648 AK |
542 | /* Don't reorder to other symbols having this set. */ |
543 | unsigned no_reorder : 1; | |
4bcfd75c | 544 | /* The symbol will be assumed to be used in an invisible way (like |
edb983b2 | 545 | by an toplevel asm statement). */ |
b8dbdb12 | 546 | unsigned force_output : 1; |
edb983b2 JH |
547 | /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be |
548 | exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted | |
549 | to static and it does not inhibit optimization. */ | |
550 | unsigned forced_by_abi : 1; | |
702d8703 JH |
551 | /* True when the name is known to be unique and thus it does not need mangling. */ |
552 | unsigned unique_name : 1; | |
e257a17c JH |
553 | /* Specify whether the section was set by user or by |
554 | compiler via -ffunction-sections. */ | |
555 | unsigned implicit_section : 1; | |
3d8d0043 MJ |
556 | /* True when body and other characteristics have been removed by |
557 | symtab_remove_unreachable_nodes. */ | |
558 | unsigned body_removed : 1; | |
b8dbdb12 | 559 | |
e70670cf JH |
560 | /*** WHOPR Partitioning flags. |
561 | These flags are used at ltrans stage when only part of the callgraph is | |
562 | available. ***/ | |
b8dbdb12 | 563 | |
e70670cf JH |
564 | /* Set when variable is used from other LTRANS partition. */ |
565 | unsigned used_from_other_partition : 1; | |
9041d2e6 | 566 | /* Set when function is available in the other LTRANS partition. |
e70670cf JH |
567 | During WPA output it is used to mark nodes that are present in |
568 | multiple partitions. */ | |
569 | unsigned in_other_partition : 1; | |
b8dbdb12 | 570 | |
b8dbdb12 | 571 | |
e70670cf JH |
572 | |
573 | /*** other flags. ***/ | |
574 | ||
575 | /* Set when symbol has address taken. */ | |
576 | unsigned address_taken : 1; | |
569b1784 JH |
577 | /* Set when init priority is set. */ |
578 | unsigned in_init_priority_hash : 1; | |
e70670cf | 579 | |
1f6be682 IV |
580 | /* Set when symbol needs to be streamed into LTO bytecode for LTO, or in case |
581 | of offloading, for separate compilation for a different target. */ | |
582 | unsigned need_lto_streaming : 1; | |
583 | ||
584 | /* Set when symbol can be streamed into bytecode for offloading. */ | |
585 | unsigned offloadable : 1; | |
586 | ||
aab778d3 L |
587 | /* Set when symbol is an IFUNC resolver. */ |
588 | unsigned ifunc_resolver : 1; | |
589 | ||
e70670cf JH |
590 | |
591 | /* Ordering of all symtab entries. */ | |
592 | int order; | |
593 | ||
594 | /* Declaration representing the symbol. */ | |
595 | tree decl; | |
960bfb69 | 596 | |
2aae7680 | 597 | /* Linked list of symbol table entries starting with symtab_nodes. */ |
5e20cdc9 DM |
598 | symtab_node *next; |
599 | symtab_node *previous; | |
e70670cf | 600 | |
1ab24192 | 601 | /* Linked list of symbols with the same asm name. There may be multiple |
e70670cf JH |
602 | entries for single symbol name during LTO, because symbols are renamed |
603 | only after partitioning. | |
604 | ||
605 | Because inline clones are kept in the assembler name has, they also produce | |
606 | duplicate entries. | |
607 | ||
608 | There are also several long standing bugs where frontends and builtin | |
609 | code produce duplicated decls. */ | |
5e20cdc9 DM |
610 | symtab_node *next_sharing_asm_name; |
611 | symtab_node *previous_sharing_asm_name; | |
2aae7680 | 612 | |
d52f5295 ML |
613 | /* Circular list of nodes in the same comdat group if non-NULL. */ |
614 | symtab_node *same_comdat_group; | |
e55637b7 | 615 | |
e70670cf | 616 | /* Vectors of referring and referenced entities. */ |
7144270e | 617 | ipa_ref_list GTY((skip)) ref_list; |
e70670cf | 618 | |
40a7fe1e JH |
619 | /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer |
620 | depending to what was known to frontend on the creation time. | |
621 | Once alias is resolved, this pointer become NULL. */ | |
622 | tree alias_target; | |
623 | ||
e70670cf JH |
624 | /* File stream where this node is being written to. */ |
625 | struct lto_file_decl_data * lto_file_data; | |
626 | ||
960bfb69 | 627 | PTR GTY ((skip)) aux; |
aede2c10 JH |
628 | |
629 | /* Comdat group the symbol is in. Can be private if GGC allowed that. */ | |
f961457f | 630 | tree x_comdat_group; |
24d047a3 JH |
631 | |
632 | /* Section name. Again can be private, if allowed. */ | |
f961457f | 633 | section_hash_entry *x_section; |
e257a17c | 634 | |
d52f5295 ML |
635 | protected: |
636 | /* Dump base fields of symtab nodes to F. Not to be used directly. */ | |
637 | void dump_base (FILE *); | |
569b1784 | 638 | |
d52f5295 ML |
639 | /* Verify common part of symtab node. */ |
640 | bool DEBUG_FUNCTION verify_base (void); | |
89330618 | 641 | |
d52f5295 ML |
642 | /* Remove node from symbol table. This function is not used directly, but via |
643 | cgraph/varpool node removal routines. */ | |
ab4664eb | 644 | void unregister (struct clone_info *); |
d52f5295 ML |
645 | |
646 | /* Return the initialization and finalization priority information for | |
647 | DECL. If there is no previous priority information, a freshly | |
648 | allocated structure is returned. */ | |
649 | struct symbol_priority_map *priority_info (void); | |
650 | ||
31de7606 JH |
651 | /* Worker for call_for_symbol_and_aliases_1. */ |
652 | bool call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *, void *), | |
653 | void *data, | |
654 | bool include_overwrite); | |
d52f5295 | 655 | private: |
46564615 SN |
656 | /* Workers for set_section. */ |
657 | static bool set_section_from_string (symtab_node *n, void *s); | |
658 | static bool set_section_from_node (symtab_node *n, void *o); | |
d52f5295 ML |
659 | |
660 | /* Worker for symtab_resolve_alias. */ | |
661 | static bool set_implicit_section (symtab_node *n, void *); | |
662 | ||
663 | /* Worker searching noninterposable alias. */ | |
664 | static bool noninterposable_alias (symtab_node *node, void *data); | |
31de7606 JH |
665 | |
666 | /* Worker for ultimate_alias_target. */ | |
f13fe18b JH |
667 | symtab_node *ultimate_alias_target_1 (enum availability *avail = NULL, |
668 | symtab_node *ref = NULL); | |
464d0118 ML |
669 | |
670 | /* Get dump name with normal or assembly name. */ | |
671 | const char *get_dump_name (bool asm_name_p) const; | |
1f00098b | 672 | }; |
1c4a429a | 673 | |
b2b29377 MM |
674 | inline void |
675 | symtab_node::checking_verify_symtab_nodes (void) | |
676 | { | |
677 | if (flag_checking) | |
678 | symtab_node::verify_symtab_nodes (); | |
679 | } | |
680 | ||
e55637b7 | 681 | /* Walk all aliases for NODE. */ |
b51a085b BE |
682 | #define FOR_EACH_ALIAS(NODE, ALIAS) \ |
683 | for (unsigned ALIAS##_iter_ = 0; \ | |
684 | (NODE)->iterate_direct_aliases (ALIAS##_iter_, ALIAS); \ | |
685 | ALIAS##_iter_++) | |
6b02a499 | 686 | |
d7f09764 DN |
687 | /* This is the information that is put into the cgraph local structure |
688 | to recover a function. */ | |
689 | struct lto_file_decl_data; | |
690 | ||
8a4a83ed | 691 | extern const char * const cgraph_availability_names[]; |
430c6ceb | 692 | extern const char * const ld_plugin_symbol_resolution_names[]; |
714c800f | 693 | extern const char * const tls_model_names[]; |
8a4a83ed | 694 | |
9187e02d JH |
695 | /* Represent which DECL tree (or reference to such tree) |
696 | will be replaced by another tree while versioning. */ | |
697 | struct GTY(()) ipa_replace_map | |
698 | { | |
9187e02d JH |
699 | /* The new (replacing) tree. */ |
700 | tree new_tree; | |
922f15c2 JH |
701 | /* Parameter number to replace, when old_tree is NULL. */ |
702 | int parm_num; | |
9187e02d | 703 | }; |
9187e02d | 704 | |
0136f8f0 AH |
705 | enum cgraph_simd_clone_arg_type |
706 | { | |
707 | SIMD_CLONE_ARG_TYPE_VECTOR, | |
708 | SIMD_CLONE_ARG_TYPE_UNIFORM, | |
d9a6bd32 | 709 | /* These are only for integer/pointer arguments passed by value. */ |
0136f8f0 AH |
710 | SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP, |
711 | SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, | |
e01d41e5 | 712 | /* These 6 are only for reference type arguments or arguments passed |
d9a6bd32 JJ |
713 | by reference. */ |
714 | SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP, | |
e01d41e5 | 715 | SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP, |
d9a6bd32 | 716 | SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP, |
e01d41e5 | 717 | SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP, |
d9a6bd32 | 718 | SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP, |
e01d41e5 | 719 | SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP, |
0136f8f0 AH |
720 | SIMD_CLONE_ARG_TYPE_MASK |
721 | }; | |
722 | ||
723 | /* Function arguments in the original function of a SIMD clone. | |
724 | Supplementary data for `struct simd_clone'. */ | |
725 | ||
726 | struct GTY(()) cgraph_simd_clone_arg { | |
727 | /* Original function argument as it originally existed in | |
728 | DECL_ARGUMENTS. */ | |
729 | tree orig_arg; | |
730 | ||
731 | /* orig_arg's function (or for extern functions type from | |
732 | TYPE_ARG_TYPES). */ | |
733 | tree orig_type; | |
734 | ||
735 | /* If argument is a vector, this holds the vector version of | |
736 | orig_arg that after adjusting the argument types will live in | |
737 | DECL_ARGUMENTS. Otherwise, this is NULL. | |
738 | ||
739 | This basically holds: | |
740 | vector(simdlen) __typeof__(orig_arg) new_arg. */ | |
741 | tree vector_arg; | |
742 | ||
743 | /* vector_arg's type (or for extern functions new vector type. */ | |
744 | tree vector_type; | |
745 | ||
746 | /* If argument is a vector, this holds the array where the simd | |
747 | argument is held while executing the simd clone function. This | |
748 | is a local variable in the cloned function. Its content is | |
749 | copied from vector_arg upon entry to the clone. | |
750 | ||
751 | This basically holds: | |
752 | __typeof__(orig_arg) simd_array[simdlen]. */ | |
753 | tree simd_array; | |
754 | ||
755 | /* A SIMD clone's argument can be either linear (constant or | |
756 | variable), uniform, or vector. */ | |
757 | enum cgraph_simd_clone_arg_type arg_type; | |
758 | ||
d9a6bd32 | 759 | /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_*CONSTANT_STEP this is |
0136f8f0 | 760 | the constant linear step, if arg_type is |
e01d41e5 | 761 | SIMD_CLONE_ARG_TYPE_LINEAR_*VARIABLE_STEP, this is index of |
0136f8f0 AH |
762 | the uniform argument holding the step, otherwise 0. */ |
763 | HOST_WIDE_INT linear_step; | |
764 | ||
765 | /* Variable alignment if available, otherwise 0. */ | |
766 | unsigned int alignment; | |
767 | }; | |
768 | ||
769 | /* Specific data for a SIMD function clone. */ | |
770 | ||
771 | struct GTY(()) cgraph_simd_clone { | |
772 | /* Number of words in the SIMD lane associated with this clone. */ | |
abe93733 | 773 | poly_uint64 simdlen; |
0136f8f0 AH |
774 | |
775 | /* Number of annotated function arguments in `args'. This is | |
776 | usually the number of named arguments in FNDECL. */ | |
777 | unsigned int nargs; | |
778 | ||
779 | /* Max hardware vector size in bits for integral vectors. */ | |
abe93733 | 780 | poly_uint64 vecsize_int; |
0136f8f0 AH |
781 | |
782 | /* Max hardware vector size in bits for floating point vectors. */ | |
abe93733 | 783 | poly_uint64 vecsize_float; |
0136f8f0 | 784 | |
5f490f9f JJ |
785 | /* Machine mode of the mask argument(s), if they are to be passed |
786 | as bitmasks in integer argument(s). VOIDmode if masks are passed | |
787 | as vectors of characteristic type. */ | |
788 | machine_mode mask_mode; | |
789 | ||
026c3cfd | 790 | /* The mangling character for a given vector size. This is used |
0136f8f0 AH |
791 | to determine the ISA mangling bit as specified in the Intel |
792 | Vector ABI. */ | |
793 | unsigned char vecsize_mangle; | |
794 | ||
795 | /* True if this is the masked, in-branch version of the clone, | |
796 | otherwise false. */ | |
797 | unsigned int inbranch : 1; | |
798 | ||
0136f8f0 | 799 | /* Doubly linked list of SIMD clones. */ |
d52f5295 | 800 | cgraph_node *prev_clone, *next_clone; |
0136f8f0 AH |
801 | |
802 | /* Original cgraph node the SIMD clones were created for. */ | |
d52f5295 | 803 | cgraph_node *origin; |
0136f8f0 AH |
804 | |
805 | /* Annotated function arguments for the original function. */ | |
3dafb85c | 806 | cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1]; |
0136f8f0 AH |
807 | }; |
808 | ||
d52f5295 | 809 | /* Function Multiversioning info. */ |
2a22f99c | 810 | struct GTY((for_user)) cgraph_function_version_info { |
d52f5295 ML |
811 | /* The cgraph_node for which the function version info is stored. */ |
812 | cgraph_node *this_node; | |
813 | /* Chains all the semantically identical function versions. The | |
814 | first function in this chain is the version_info node of the | |
815 | default function. */ | |
3dafb85c | 816 | cgraph_function_version_info *prev; |
d52f5295 ML |
817 | /* If this version node corresponds to a dispatcher for function |
818 | versions, this points to the version info node of the default | |
819 | function, the first node in the chain. */ | |
3dafb85c | 820 | cgraph_function_version_info *next; |
d52f5295 ML |
821 | /* If this node corresponds to a function version, this points |
822 | to the dispatcher function decl, which is the function that must | |
823 | be called to execute the right function version at run-time. | |
824 | ||
825 | If this cgraph node is a dispatcher (if dispatcher_function is | |
826 | true, in the cgraph_node struct) for function versions, this | |
827 | points to resolver function, which holds the function body of the | |
828 | dispatcher. The dispatcher decl is an alias to the resolver | |
829 | function decl. */ | |
830 | tree dispatcher_resolver; | |
831 | }; | |
832 | ||
833 | #define DEFCIFCODE(code, type, string) CIF_ ## code, | |
834 | /* Reasons for inlining failures. */ | |
835 | ||
836 | enum cgraph_inline_failed_t { | |
837 | #include "cif-code.def" | |
838 | CIF_N_REASONS | |
839 | }; | |
840 | ||
841 | enum cgraph_inline_failed_type_t | |
842 | { | |
843 | CIF_FINAL_NORMAL = 0, | |
844 | CIF_FINAL_ERROR | |
845 | }; | |
846 | ||
847 | struct cgraph_edge; | |
5fefcf92 | 848 | |
ca752f39 | 849 | struct cgraph_edge_hasher : ggc_ptr_hash<cgraph_edge> |
2a22f99c | 850 | { |
355fe088 | 851 | typedef gimple *compare_type; |
2a22f99c TS |
852 | |
853 | static hashval_t hash (cgraph_edge *); | |
355fe088 TS |
854 | static hashval_t hash (gimple *); |
855 | static bool equal (cgraph_edge *, gimple *); | |
2a22f99c TS |
856 | }; |
857 | ||
ba228239 | 858 | /* The cgraph data structure. |
e0bb17a8 | 859 | Each function decl has assigned cgraph_node listing callees and callers. */ |
1c4a429a | 860 | |
99b1c316 | 861 | struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node |
6c1dae73 | 862 | { |
4325656f ML |
863 | friend class symbol_table; |
864 | ||
a65d584d ML |
865 | /* Constructor. */ |
866 | explicit cgraph_node (int uid) | |
867 | : symtab_node (SYMTAB_FUNCTION), callees (NULL), callers (NULL), | |
89576d86 | 868 | indirect_calls (NULL), |
a65d584d ML |
869 | next_sibling_clone (NULL), prev_sibling_clone (NULL), clones (NULL), |
870 | clone_of (NULL), call_site_hash (NULL), former_clone_of (NULL), | |
871 | simdclone (NULL), simd_clones (NULL), ipa_transforms_to_apply (vNULL), | |
ae7a23a3 | 872 | inlined_to (NULL), rtl (NULL), |
59c7b29e | 873 | count (profile_count::uninitialized ()), |
a65d584d | 874 | count_materialization_scale (REG_BR_PROB_BASE), profile_id (0), |
67f3791f JH |
875 | unit_id (0), tp_first_run (0), thunk (false), |
876 | used_as_abstract_origin (false), | |
a65d584d ML |
877 | lowered (false), process (false), frequency (NODE_FREQUENCY_NORMAL), |
878 | only_called_at_startup (false), only_called_at_exit (false), | |
879 | tm_clone (false), dispatcher_function (false), calls_comdat_local (false), | |
880 | icf_merged (false), nonfreeing_fn (false), merged_comdat (false), | |
881 | merged_extern_inline (false), parallelized_function (false), | |
882 | split_part (false), indirect_call_target (false), local (false), | |
883 | versionable (false), can_change_signature (false), | |
884 | redefined_extern_inline (false), tm_may_enter_irr (false), | |
7a50e708 JJ |
885 | ipcp_clone (false), declare_variant_alt (false), |
886 | calls_declare_variant_alt (false), m_uid (uid), m_summary_id (-1) | |
a65d584d ML |
887 | {} |
888 | ||
d52f5295 ML |
889 | /* Remove the node from cgraph and all inline clones inlined into it. |
890 | Skip however removal of FORBIDDEN_NODE and return true if it needs to be | |
891 | removed. This allows to call the function from outer loop walking clone | |
892 | tree. */ | |
893 | bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL); | |
894 | ||
895 | /* Record all references from cgraph_node that are taken | |
896 | in statement STMT. */ | |
355fe088 | 897 | void record_stmt_references (gimple *stmt); |
d52f5295 ML |
898 | |
899 | /* Like cgraph_set_call_stmt but walk the clone tree and update all | |
900 | clones sharing the same function body. | |
901 | When WHOLE_SPECULATIVE_EDGES is true, all three components of | |
902 | speculative edge gets updated. Otherwise we update only direct | |
903 | call. */ | |
355fe088 | 904 | void set_call_stmt_including_clones (gimple *old_stmt, gcall *new_stmt, |
d52f5295 ML |
905 | bool update_speculative = true); |
906 | ||
907 | /* Walk the alias chain to return the function cgraph_node is alias of. | |
908 | Walk through thunk, too. | |
f13fe18b JH |
909 | When AVAILABILITY is non-NULL, get minimal availability in the chain. |
910 | When REF is non-NULL, assume that reference happens in symbol REF | |
911 | when determining the availability. */ | |
912 | cgraph_node *function_symbol (enum availability *avail = NULL, | |
913 | struct symtab_node *ref = NULL); | |
d52f5295 | 914 | |
6cbde2e3 BE |
915 | /* Walk the alias chain to return the function cgraph_node is alias of. |
916 | Walk through non virtual thunks, too. Thus we return either a function | |
917 | or a virtual thunk node. | |
f13fe18b JH |
918 | When AVAILABILITY is non-NULL, get minimal availability in the chain. |
919 | When REF is non-NULL, assume that reference happens in symbol REF | |
920 | when determining the availability. */ | |
6cbde2e3 | 921 | cgraph_node *function_or_virtual_thunk_symbol |
f13fe18b JH |
922 | (enum availability *avail = NULL, |
923 | struct symtab_node *ref = NULL); | |
6cbde2e3 | 924 | |
d52f5295 ML |
925 | /* Create node representing clone of N executed COUNT times. Decrease |
926 | the execution counts from original node too. | |
927 | The new clone will have decl set to DECL that may or may not be the same | |
928 | as decl of N. | |
929 | ||
930 | When UPDATE_ORIGINAL is true, the counts are subtracted from the original | |
931 | function's profile to reflect the fact that part of execution is handled | |
932 | by node. | |
dfea3d6f | 933 | When CALL_DUPLICATION_HOOK is true, the ipa passes are acknowledged about |
d52f5295 ML |
934 | the new clone. Otherwise the caller is responsible for doing so later. |
935 | ||
936 | If the new node is being inlined into another one, NEW_INLINED_TO should be | |
937 | the outline function the new one is (even indirectly) inlined to. | |
a62bfab5 | 938 | All hooks will see this in node's inlined_to, when invoked. |
0bdad123 ML |
939 | Can be NULL if the node is not inlined. SUFFIX is string that is appended |
940 | to the original name. */ | |
1bad9c18 | 941 | cgraph_node *create_clone (tree decl, profile_count count, |
d52f5295 ML |
942 | bool update_original, |
943 | vec<cgraph_edge *> redirect_callers, | |
944 | bool call_duplication_hook, | |
3dafb85c | 945 | cgraph_node *new_inlined_to, |
ff6686d2 MJ |
946 | ipa_param_adjustments *param_adjustments, |
947 | const char *suffix = NULL); | |
d52f5295 | 948 | |
53aedcce MP |
949 | /* Create callgraph node clone with new declaration. The actual body will be |
950 | copied later at compilation stage. The name of the new clone will be | |
951 | constructed from the name of the original node, SUFFIX and NUM_SUFFIX. */ | |
00dcc88a | 952 | cgraph_node *create_virtual_clone (const vec<cgraph_edge *> &redirect_callers, |
d52f5295 | 953 | vec<ipa_replace_map *, va_gc> *tree_map, |
ff6686d2 MJ |
954 | ipa_param_adjustments *param_adjustments, |
955 | const char * suffix, unsigned num_suffix); | |
d52f5295 | 956 | |
d0b1b67a MJ |
957 | /* Remove the node from the tree of virtual and inline clones and make it a |
958 | standalone node - not a clone any more. */ | |
959 | void remove_from_clone_tree (); | |
960 | ||
d52f5295 ML |
961 | /* cgraph node being removed from symbol table; see if its entry can be |
962 | replaced by other inline clone. */ | |
ab4664eb | 963 | cgraph_node *find_replacement (struct clone_info *); |
d52f5295 ML |
964 | |
965 | /* Create a new cgraph node which is the new version of | |
966 | callgraph node. REDIRECT_CALLERS holds the callers | |
967 | edges which should be redirected to point to | |
968 | NEW_VERSION. ALL the callees edges of the node | |
969 | are cloned to the new version node. Return the new | |
970 | version node. | |
971 | ||
972 | If non-NULL BLOCK_TO_COPY determine what basic blocks | |
973 | was copied to prevent duplications of calls that are dead | |
0bdad123 ML |
974 | in the clone. |
975 | ||
976 | SUFFIX is string that is appended to the original name. */ | |
d52f5295 ML |
977 | |
978 | cgraph_node *create_version_clone (tree new_decl, | |
979 | vec<cgraph_edge *> redirect_callers, | |
0bdad123 ML |
980 | bitmap bbs_to_copy, |
981 | const char *suffix = NULL); | |
d52f5295 ML |
982 | |
983 | /* Perform function versioning. | |
984 | Function versioning includes copying of the tree and | |
985 | a callgraph update (creating a new cgraph node and updating | |
986 | its callees and callers). | |
987 | ||
988 | REDIRECT_CALLERS varray includes the edges to be redirected | |
989 | to the new version. | |
990 | ||
991 | TREE_MAP is a mapping of tree nodes we want to replace with | |
992 | new ones (according to results of prior analysis). | |
993 | ||
994 | If non-NULL ARGS_TO_SKIP determine function parameters to remove | |
995 | from new version. | |
996 | If SKIP_RETURN is true, the new version will return void. | |
997 | If non-NULL BLOCK_TO_COPY determine what basic blocks to copy. | |
998 | If non_NULL NEW_ENTRY determine new entry BB of the clone. | |
999 | ||
5928bc2e ML |
1000 | If TARGET_ATTRIBUTES is non-null, when creating a new declaration, |
1001 | add the attributes to DECL_ATTRIBUTES. And call valid_attribute_p | |
1002 | that will promote value of the attribute DECL_FUNCTION_SPECIFIC_TARGET | |
1003 | of the declaration. | |
1004 | ||
d52f5295 ML |
1005 | Return the new version's cgraph node. */ |
1006 | cgraph_node *create_version_clone_with_body | |
1007 | (vec<cgraph_edge *> redirect_callers, | |
ff6686d2 MJ |
1008 | vec<ipa_replace_map *, va_gc> *tree_map, |
1009 | ipa_param_adjustments *param_adjustments, | |
1010 | bitmap bbs_to_copy, basic_block new_entry_block, const char *clone_name, | |
1011 | tree target_attributes = NULL_TREE); | |
d52f5295 ML |
1012 | |
1013 | /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab | |
1014 | corresponding to cgraph_node. */ | |
3dafb85c | 1015 | cgraph_function_version_info *insert_new_function_version (void); |
d52f5295 ML |
1016 | |
1017 | /* Get the cgraph_function_version_info node corresponding to node. */ | |
3dafb85c | 1018 | cgraph_function_version_info *function_version (void); |
d52f5295 ML |
1019 | |
1020 | /* Discover all functions and variables that are trivially needed, analyze | |
1021 | them as well as all functions and variables referred by them */ | |
1022 | void analyze (void); | |
1023 | ||
1024 | /* Add thunk alias into callgraph. The alias declaration is ALIAS and it | |
1025 | aliases DECL with an adjustments made into the first parameter. | |
67f3791f | 1026 | See comments in struct symtab-thunks.h for detail on the parameters. */ |
d52f5295 ML |
1027 | cgraph_node * create_thunk (tree alias, tree, bool this_adjusting, |
1028 | HOST_WIDE_INT fixed_offset, | |
1029 | HOST_WIDE_INT virtual_value, | |
44662f68 | 1030 | HOST_WIDE_INT indirect_offset, |
d52f5295 ML |
1031 | tree virtual_offset, |
1032 | tree real_alias); | |
1033 | ||
1034 | ||
1035 | /* Return node that alias is aliasing. */ | |
1036 | inline cgraph_node *get_alias_target (void); | |
1037 | ||
1038 | /* Given function symbol, walk the alias chain to return the function node | |
1039 | is alias of. Do not walk through thunks. | |
f13fe18b JH |
1040 | When AVAILABILITY is non-NULL, get minimal availability in the chain. |
1041 | When REF is non-NULL, assume that reference happens in symbol REF | |
1042 | when determining the availability. */ | |
d52f5295 | 1043 | |
f13fe18b JH |
1044 | cgraph_node *ultimate_alias_target (availability *availability = NULL, |
1045 | symtab_node *ref = NULL); | |
d52f5295 | 1046 | |
6a4bad95 MJ |
1047 | /* Call expand_thunk on all callers that are thunks and analyze those |
1048 | nodes that were expanded. */ | |
1049 | void expand_all_artificial_thunks (); | |
1050 | ||
3dafb85c ML |
1051 | /* Assemble thunks and aliases associated to node. */ |
1052 | void assemble_thunks_and_aliases (void); | |
1053 | ||
1054 | /* Expand function specified by node. */ | |
1055 | void expand (void); | |
1056 | ||
d52f5295 ML |
1057 | /* As an GCC extension we allow redefinition of the function. The |
1058 | semantics when both copies of bodies differ is not well defined. | |
1059 | We replace the old body with new body so in unit at a time mode | |
1060 | we always use new body, while in normal mode we may end up with | |
1061 | old body inlined into some functions and new body expanded and | |
1062 | inlined in others. */ | |
1063 | void reset (void); | |
1064 | ||
1065 | /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this | |
1066 | kind of wrapper method. */ | |
1067 | void create_wrapper (cgraph_node *target); | |
1068 | ||
1069 | /* Verify cgraph nodes of the cgraph node. */ | |
1070 | void DEBUG_FUNCTION verify_node (void); | |
1071 | ||
1072 | /* Remove function from symbol table. */ | |
1073 | void remove (void); | |
1074 | ||
1075 | /* Dump call graph node to file F. */ | |
1076 | void dump (FILE *f); | |
1077 | ||
34e64622 GB |
1078 | /* Dump call graph node to file F. */ |
1079 | void dump_graphviz (FILE *f); | |
1080 | ||
d52f5295 ML |
1081 | /* Dump call graph node to stderr. */ |
1082 | void DEBUG_FUNCTION debug (void); | |
1083 | ||
1084 | /* When doing LTO, read cgraph_node's body from disk if it is not already | |
1085 | present. */ | |
0e590b68 | 1086 | bool get_untransformed_body (); |
70486010 JH |
1087 | |
1088 | /* Prepare function body. When doing LTO, read cgraph_node's body from disk | |
1089 | if it is not already present. When some IPA transformations are scheduled, | |
1090 | apply them. */ | |
0e590b68 JH |
1091 | bool get_body (); |
1092 | ||
1093 | void materialize_clone (void); | |
d52f5295 ML |
1094 | |
1095 | /* Release memory used to represent body of function. | |
1096 | Use this only for functions that are released before being translated to | |
1097 | target code (i.e. RTL). Functions that are compiled to RTL and beyond | |
1098 | are free'd in final.c via free_after_compilation(). */ | |
bf898b30 | 1099 | void release_body (bool keep_arguments = false); |
d52f5295 | 1100 | |
8ccda8bc | 1101 | /* Return the DECL_STRUCT_FUNCTION of the function. */ |
975d043f | 1102 | struct function *get_fun () const; |
8ccda8bc | 1103 | |
d52f5295 ML |
1104 | /* Bring cgraph node local. */ |
1105 | void make_local (void); | |
1106 | ||
1107 | /* Likewise indicate that a node is having address taken. */ | |
1108 | void mark_address_taken (void); | |
1109 | ||
dfea3d6f | 1110 | /* Set finalization priority to PRIORITY. */ |
d52f5295 ML |
1111 | void set_fini_priority (priority_type priority); |
1112 | ||
1113 | /* Return the finalization priority. */ | |
1114 | priority_type get_fini_priority (void); | |
1115 | ||
1116 | /* Create edge from a given function to CALLEE in the cgraph. */ | |
3dafb85c | 1117 | cgraph_edge *create_edge (cgraph_node *callee, |
3187c8a5 MJ |
1118 | gcall *call_stmt, profile_count count, |
1119 | bool cloning_p = false); | |
3dafb85c | 1120 | |
d52f5295 ML |
1121 | /* Create an indirect edge with a yet-undetermined callee where the call |
1122 | statement destination is a formal parameter of the caller with index | |
1123 | PARAM_INDEX. */ | |
538dd0b7 | 1124 | cgraph_edge *create_indirect_edge (gcall *call_stmt, int ecf_flags, |
1bad9c18 | 1125 | profile_count count, |
3187c8a5 | 1126 | bool cloning_p = false); |
d52f5295 ML |
1127 | |
1128 | /* Like cgraph_create_edge walk the clone tree and update all clones sharing | |
1129 | same function body. If clones already have edge for OLD_STMT; only | |
1130 | update the edge same way as cgraph_set_call_stmt_including_clones does. */ | |
3dafb85c | 1131 | void create_edge_including_clones (cgraph_node *callee, |
355fe088 | 1132 | gimple *old_stmt, gcall *stmt, |
3995f3a2 | 1133 | profile_count count, |
d52f5295 ML |
1134 | cgraph_inline_failed_t reason); |
1135 | ||
1136 | /* Return the callgraph edge representing the GIMPLE_CALL statement | |
1137 | CALL_STMT. */ | |
355fe088 | 1138 | cgraph_edge *get_edge (gimple *call_stmt); |
d52f5295 ML |
1139 | |
1140 | /* Collect all callers of cgraph_node and its aliases that are known to lead | |
4a414de8 | 1141 | to NODE (i.e. are not overwritable) and that are not thunks. */ |
265af872 | 1142 | auto_vec<cgraph_edge *> collect_callers (void); |
d52f5295 ML |
1143 | |
1144 | /* Remove all callers from the node. */ | |
1145 | void remove_callers (void); | |
1146 | ||
1147 | /* Remove all callees from the node. */ | |
1148 | void remove_callees (void); | |
1149 | ||
1150 | /* Return function availability. See cgraph.h for description of individual | |
1151 | return values. */ | |
f13fe18b | 1152 | enum availability get_availability (symtab_node *ref = NULL); |
d52f5295 ML |
1153 | |
1154 | /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node | |
1155 | if any to NOTHROW. */ | |
a2b056a3 | 1156 | bool set_nothrow_flag (bool nothrow); |
d52f5295 | 1157 | |
0fab169b PK |
1158 | /* SET DECL_IS_MALLOC on cgraph_node's decl and on aliases of the node |
1159 | if any. */ | |
1160 | bool set_malloc_flag (bool malloc_p); | |
1161 | ||
69a4e898 JH |
1162 | /* If SET_CONST is true, mark function, aliases and thunks to be ECF_CONST. |
1163 | If SET_CONST if false, clear the flag. | |
1164 | ||
1165 | When setting the flag be careful about possible interposition and | |
dfea3d6f | 1166 | do not set the flag for functions that can be interposed and set pure |
69a4e898 JH |
1167 | flag for functions that can bind to other definition. |
1168 | ||
1169 | Return true if any change was done. */ | |
1170 | ||
1171 | bool set_const_flag (bool set_const, bool looping); | |
d52f5295 ML |
1172 | |
1173 | /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node | |
69a4e898 JH |
1174 | if any to PURE. |
1175 | ||
1176 | When setting the flag, be careful about possible interposition. | |
1177 | Return true if any change was done. */ | |
1178 | ||
1179 | bool set_pure_flag (bool pure, bool looping); | |
d52f5295 | 1180 | |
6cbde2e3 | 1181 | /* Call callback on function and aliases associated to the function. |
d52f5295 ML |
1182 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are |
1183 | skipped. */ | |
1184 | ||
1185 | bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *, | |
1186 | void *), | |
1187 | void *data, bool include_overwritable); | |
1188 | ||
6cbde2e3 | 1189 | /* Call callback on cgraph_node, thunks and aliases associated to NODE. |
d52f5295 | 1190 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are |
6cbde2e3 | 1191 | skipped. When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are |
d52f5295 ML |
1192 | skipped. */ |
1193 | bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node, | |
6cbde2e3 BE |
1194 | void *data), |
1195 | void *data, | |
1196 | bool include_overwritable, | |
1197 | bool exclude_virtual_thunks = false); | |
d52f5295 | 1198 | |
d52f5295 ML |
1199 | /* Likewise indicate that a node is needed, i.e. reachable via some |
1200 | external means. */ | |
1201 | inline void mark_force_output (void); | |
1202 | ||
1203 | /* Return true when function can be marked local. */ | |
1204 | bool local_p (void); | |
1205 | ||
1206 | /* Return true if cgraph_node can be made local for API change. | |
1207 | Extern inline functions and C++ COMDAT functions can be made local | |
1208 | at the expense of possible code size growth if function is used in multiple | |
1209 | compilation units. */ | |
1210 | bool can_be_local_p (void); | |
1211 | ||
67914693 | 1212 | /* Return true when cgraph_node cannot return or throw and thus |
d52f5295 ML |
1213 | it is safe to ignore its side effects for IPA analysis. */ |
1214 | bool cannot_return_p (void); | |
1215 | ||
1216 | /* Return true when function cgraph_node and all its aliases are only called | |
1217 | directly. | |
1218 | i.e. it is not externally visible, address was not taken and | |
1219 | it is not used in any other non-standard way. */ | |
1220 | bool only_called_directly_p (void); | |
1221 | ||
1222 | /* Return true when function is only called directly or it has alias. | |
1223 | i.e. it is not externally visible, address was not taken and | |
1224 | it is not used in any other non-standard way. */ | |
1225 | inline bool only_called_directly_or_aliased_p (void); | |
1226 | ||
1227 | /* Return true when function cgraph_node can be expected to be removed | |
1228 | from program when direct calls in this compilation unit are removed. | |
1229 | ||
1230 | As a special case COMDAT functions are | |
1231 | cgraph_can_remove_if_no_direct_calls_p while the are not | |
1232 | cgraph_only_called_directly_p (it is possible they are called from other | |
1233 | unit) | |
1234 | ||
1235 | This function behaves as cgraph_only_called_directly_p because eliminating | |
1236 | all uses of COMDAT function does not make it necessarily disappear from | |
1237 | the program unless we are compiling whole program or we do LTO. In this | |
1238 | case we know we win since dynamic linking will not really discard the | |
e0d514da JH |
1239 | linkonce section. |
1240 | ||
1241 | If WILL_INLINE is true, assume that function will be inlined into all the | |
1242 | direct calls. */ | |
1243 | bool will_be_removed_from_program_if_no_direct_calls_p | |
1244 | (bool will_inline = false); | |
d52f5295 ML |
1245 | |
1246 | /* Return true when function can be removed from callgraph | |
e0d514da JH |
1247 | if all direct calls and references are eliminated. The function does |
1248 | not take into account comdat groups. */ | |
d52f5295 ML |
1249 | bool can_remove_if_no_direct_calls_and_refs_p (void); |
1250 | ||
1251 | /* Return true when function cgraph_node and its aliases can be removed from | |
e0d514da JH |
1252 | callgraph if all direct calls are eliminated. |
1253 | If WILL_INLINE is true, assume that function will be inlined into all the | |
1254 | direct calls. */ | |
1255 | bool can_remove_if_no_direct_calls_p (bool will_inline = false); | |
d52f5295 ML |
1256 | |
1257 | /* Return true when callgraph node is a function with Gimple body defined | |
1258 | in current unit. Functions can also be define externally or they | |
1259 | can be thunks with no Gimple representation. | |
1260 | ||
1261 | Note that at WPA stage, the function body may not be present in memory. */ | |
1262 | inline bool has_gimple_body_p (void); | |
1263 | ||
1738b522 | 1264 | /* Return true if this node represents a former, i.e. an expanded, thunk. */ |
67f3791f | 1265 | bool former_thunk_p (void); |
1738b522 | 1266 | |
72b3bc89 JH |
1267 | /* Check if function calls comdat local. This is used to recompute |
1268 | calls_comdat_local flag after function transformations. */ | |
1269 | bool check_calls_comdat_local_p (); | |
1270 | ||
d52f5295 | 1271 | /* Return true if function should be optimized for size. */ |
f20a6c57 | 1272 | enum optimize_size_level optimize_for_size_p (void); |
d52f5295 ML |
1273 | |
1274 | /* Dump the callgraph to file F. */ | |
1275 | static void dump_cgraph (FILE *f); | |
1276 | ||
1277 | /* Dump the call graph to stderr. */ | |
3dafb85c ML |
1278 | static inline |
1279 | void debug_cgraph (void) | |
d52f5295 ML |
1280 | { |
1281 | dump_cgraph (stderr); | |
1282 | } | |
1283 | ||
4325656f ML |
1284 | /* Get unique identifier of the node. */ |
1285 | inline int get_uid () | |
1286 | { | |
1287 | return m_uid; | |
1288 | } | |
1289 | ||
db30281f ML |
1290 | /* Get summary id of the node. */ |
1291 | inline int get_summary_id () | |
1292 | { | |
1293 | return m_summary_id; | |
1294 | } | |
1295 | ||
d52f5295 ML |
1296 | /* Record that DECL1 and DECL2 are semantically identical function |
1297 | versions. */ | |
1298 | static void record_function_versions (tree decl1, tree decl2); | |
1299 | ||
1300 | /* Remove the cgraph_function_version_info and cgraph_node for DECL. This | |
1301 | DECL is a duplicate declaration. */ | |
9acb4592 | 1302 | static void delete_function_version_by_decl (tree decl); |
d52f5295 ML |
1303 | |
1304 | /* Add the function FNDECL to the call graph. | |
3dafb85c | 1305 | Unlike finalize_function, this function is intended to be used |
d52f5295 ML |
1306 | by middle end and allows insertion of new function at arbitrary point |
1307 | of compilation. The function can be either in high, low or SSA form | |
1308 | GIMPLE. | |
1309 | ||
1310 | The function is assumed to be reachable and have address taken (so no | |
1311 | API breaking optimizations are performed on it). | |
1312 | ||
1313 | Main work done by this function is to enqueue the function for later | |
1314 | processing to avoid need the passes to be re-entrant. */ | |
1315 | static void add_new_function (tree fndecl, bool lowered); | |
1316 | ||
1317 | /* Return callgraph node for given symbol and check it is a function. */ | |
1318 | static inline cgraph_node *get (const_tree decl) | |
1319 | { | |
1320 | gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL); | |
1321 | return dyn_cast <cgraph_node *> (symtab_node::get (decl)); | |
1322 | } | |
1323 | ||
3dafb85c ML |
1324 | /* DECL has been parsed. Take it, queue it, compile it at the whim of the |
1325 | logic in effect. If NO_COLLECT is true, then our caller cannot stand to | |
1326 | have the garbage collector run at the moment. We would need to either | |
1327 | create a new GC context, or just not compile right now. */ | |
1328 | static void finalize_function (tree, bool); | |
1329 | ||
d52f5295 ML |
1330 | /* Return cgraph node assigned to DECL. Create new one when needed. */ |
1331 | static cgraph_node * create (tree decl); | |
1332 | ||
d52f5295 ML |
1333 | /* Try to find a call graph node for declaration DECL and if it does not |
1334 | exist or if it corresponds to an inline clone, create a new one. */ | |
1335 | static cgraph_node * get_create (tree); | |
1336 | ||
3dafb85c | 1337 | /* Return local info for the compiled function. */ |
87f94429 | 1338 | static cgraph_node *local_info_node (tree decl); |
3dafb85c | 1339 | |
ef736163 | 1340 | /* Return RTL info for the compiled function. */ |
5a5a3bc5 | 1341 | static struct cgraph_rtl_info *rtl_info (const_tree); |
3dafb85c | 1342 | |
d52f5295 ML |
1343 | /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME. |
1344 | Return NULL if there's no such node. */ | |
1345 | static cgraph_node *get_for_asmname (tree asmname); | |
1346 | ||
1347 | /* Attempt to mark ALIAS as an alias to DECL. Return alias node if | |
1348 | successful and NULL otherwise. | |
1349 | Same body aliases are output whenever the body of DECL is output, | |
1350 | and cgraph_node::get (ALIAS) transparently | |
1351 | returns cgraph_node::get (DECL). */ | |
1352 | static cgraph_node * create_same_body_alias (tree alias, tree decl); | |
1353 | ||
d52f5295 ML |
1354 | /* Verify whole cgraph structure. */ |
1355 | static void DEBUG_FUNCTION verify_cgraph_nodes (void); | |
1356 | ||
b2b29377 MM |
1357 | /* Verify cgraph, if consistency checking is enabled. */ |
1358 | static inline void checking_verify_cgraph_nodes (void); | |
1359 | ||
d52f5295 ML |
1360 | /* Worker to bring NODE local. */ |
1361 | static bool make_local (cgraph_node *node, void *); | |
1362 | ||
1363 | /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing | |
1364 | the function body is associated | |
1365 | with (not necessarily cgraph_node (DECL). */ | |
1366 | static cgraph_node *create_alias (tree alias, tree target); | |
1367 | ||
17d1bf76 ML |
1368 | /* Return true if NODE has thunk. */ |
1369 | static bool has_thunk_p (cgraph_node *node, void *); | |
1370 | ||
3dafb85c ML |
1371 | cgraph_edge *callees; |
1372 | cgraph_edge *callers; | |
e33c6cd6 MJ |
1373 | /* List of edges representing indirect calls with a yet undetermined |
1374 | callee. */ | |
3dafb85c | 1375 | cgraph_edge *indirect_calls; |
d52f5295 ML |
1376 | cgraph_node *next_sibling_clone; |
1377 | cgraph_node *prev_sibling_clone; | |
1378 | cgraph_node *clones; | |
1379 | cgraph_node *clone_of; | |
70d539ce JH |
1380 | /* For functions with many calls sites it holds map from call expression |
1381 | to the edge to speed up cgraph_edge function. */ | |
2a22f99c | 1382 | hash_table<cgraph_edge_hasher> *GTY(()) call_site_hash; |
97ba0040 JH |
1383 | /* Declaration node used to be clone of. */ |
1384 | tree former_clone_of; | |
c22cacf3 | 1385 | |
0136f8f0 AH |
1386 | /* If this is a SIMD clone, this points to the SIMD specific |
1387 | information for it. */ | |
3dafb85c | 1388 | cgraph_simd_clone *simdclone; |
0136f8f0 | 1389 | /* If this function has SIMD clones, this points to the first clone. */ |
d52f5295 | 1390 | cgraph_node *simd_clones; |
0136f8f0 | 1391 | |
0e3776db JH |
1392 | /* Interprocedural passes scheduled to have their transform functions |
1393 | applied next time we execute local pass on them. We maintain it | |
1394 | per-function in order to allow IPA passes to introduce new functions. */ | |
40e67ab8 | 1395 | vec<ipa_opt_pass, va_heap, vl_ptr> GTY((skip)) ipa_transforms_to_apply; |
0e3776db | 1396 | |
a62bfab5 ML |
1397 | /* For inline clones this points to the function they will be |
1398 | inlined into. */ | |
1399 | cgraph_node *inlined_to; | |
1400 | ||
88f554b4 | 1401 | struct cgraph_rtl_info *rtl; |
c22cacf3 | 1402 | |
e42922b1 | 1403 | /* Expected number of executions: calculated in profile.c. */ |
3995f3a2 | 1404 | profile_count count; |
db0bf14f JH |
1405 | /* How to scale counts at materialization time; used to merge |
1406 | LTO units with different number of profile runs. */ | |
1407 | int count_materialization_scale; | |
2fa3d31b JH |
1408 | /* ID assigned by the profiling. */ |
1409 | unsigned int profile_id; | |
b74d8dc4 JH |
1410 | /* ID of the translation unit. */ |
1411 | int unit_id; | |
59c7b29e JH |
1412 | /* Time profiler: first run of function. */ |
1413 | int tp_first_run; | |
3691626c | 1414 | |
67f3791f JH |
1415 | /* True when symbol is a thunk. */ |
1416 | unsigned thunk : 1; | |
6b20f353 DS |
1417 | /* Set when decl is an abstract function pointed to by the |
1418 | ABSTRACT_DECL_ORIGIN of a reachable function. */ | |
c0c123ef | 1419 | unsigned used_as_abstract_origin : 1; |
50674e96 | 1420 | /* Set once the function is lowered (i.e. its CFG is built). */ |
b4e19405 | 1421 | unsigned lowered : 1; |
25c84396 RH |
1422 | /* Set once the function has been instantiated and its callee |
1423 | lists created. */ | |
257eb6e3 | 1424 | unsigned process : 1; |
5fefcf92 JH |
1425 | /* How commonly executed the node is. Initialized during branch |
1426 | probabilities pass. */ | |
1427 | ENUM_BITFIELD (node_frequency) frequency : 2; | |
844db5d0 JH |
1428 | /* True when function can only be called at startup (from static ctor). */ |
1429 | unsigned only_called_at_startup : 1; | |
1430 | /* True when function can only be called at startup (from static dtor). */ | |
1431 | unsigned only_called_at_exit : 1; | |
0a35513e AH |
1432 | /* True when function is the transactional clone of a function which |
1433 | is called only from inside transactions. */ | |
1434 | /* ?? We should be able to remove this. We have enough bits in | |
1435 | cgraph to calculate it. */ | |
1436 | unsigned tm_clone : 1; | |
3649b9b7 ST |
1437 | /* True if this decl is a dispatcher for function versions. */ |
1438 | unsigned dispatcher_function : 1; | |
1f26ac87 | 1439 | /* True if this decl calls a COMDAT-local function. This is set up in |
0bceb671 | 1440 | compute_fn_summary and inline_call. */ |
1f26ac87 | 1441 | unsigned calls_comdat_local : 1; |
b84d4347 ML |
1442 | /* True if node has been created by merge operation in IPA-ICF. */ |
1443 | unsigned icf_merged: 1; | |
8413ca87 JJ |
1444 | /* True if call to node can't result in a call to free, munmap or |
1445 | other operation that could make previously non-trapping memory | |
1446 | accesses trapping. */ | |
1447 | unsigned nonfreeing_fn : 1; | |
ebc8f0bb | 1448 | /* True if there was multiple COMDAT bodies merged by lto-symtab. */ |
88636b62 | 1449 | unsigned merged_comdat : 1; |
b74d8dc4 JH |
1450 | /* True if this def was merged with extern inlines. */ |
1451 | unsigned merged_extern_inline : 1; | |
a79b7ec5 TV |
1452 | /* True if function was created to be executed in parallel. */ |
1453 | unsigned parallelized_function : 1; | |
41f669d8 JH |
1454 | /* True if function is part split out by ipa-split. */ |
1455 | unsigned split_part : 1; | |
4f4ada6a JH |
1456 | /* True if the function appears as possible target of indirect call. */ |
1457 | unsigned indirect_call_target : 1; | |
87f94429 ML |
1458 | /* Set when function is visible in current compilation unit only and |
1459 | its address is never taken. */ | |
1460 | unsigned local : 1; | |
1461 | /* False when there is something makes versioning impossible. */ | |
1462 | unsigned versionable : 1; | |
1463 | /* False when function calling convention and signature cannot be changed. | |
1464 | This is the case when __builtin_apply_args is used. */ | |
1465 | unsigned can_change_signature : 1; | |
1466 | /* True when the function has been originally extern inline, but it is | |
1467 | redefined now. */ | |
1468 | unsigned redefined_extern_inline : 1; | |
1469 | /* True if the function may enter serial irrevocable mode. */ | |
1470 | unsigned tm_may_enter_irr : 1; | |
6cf67b62 JH |
1471 | /* True if this was a clone created by ipa-cp. */ |
1472 | unsigned ipcp_clone : 1; | |
7a50e708 JJ |
1473 | /* True if this is the deferred declare variant resolution artificial |
1474 | function. */ | |
1475 | unsigned declare_variant_alt : 1; | |
1476 | /* True if the function calls declare_variant_alt functions. */ | |
1477 | unsigned calls_declare_variant_alt : 1; | |
31de7606 JH |
1478 | |
1479 | private: | |
4325656f ML |
1480 | /* Unique id of the node. */ |
1481 | int m_uid; | |
1482 | ||
db30281f ML |
1483 | /* Summary id that is recycled. */ |
1484 | int m_summary_id; | |
1485 | ||
31de7606 JH |
1486 | /* Worker for call_for_symbol_and_aliases. */ |
1487 | bool call_for_symbol_and_aliases_1 (bool (*callback) (cgraph_node *, | |
1488 | void *), | |
1489 | void *data, bool include_overwritable); | |
3649b9b7 ST |
1490 | }; |
1491 | ||
fed5ae11 DK |
1492 | /* A cgraph node set is a collection of cgraph nodes. A cgraph node |
1493 | can appear in multiple sets. */ | |
1cb1a99f | 1494 | struct cgraph_node_set_def |
fed5ae11 | 1495 | { |
b787e7a2 | 1496 | hash_map<cgraph_node *, size_t> *map; |
d52f5295 | 1497 | vec<cgraph_node *> nodes; |
fed5ae11 DK |
1498 | }; |
1499 | ||
d52f5295 ML |
1500 | typedef cgraph_node_set_def *cgraph_node_set; |
1501 | typedef struct varpool_node_set_def *varpool_node_set; | |
2942c502 | 1502 | |
99b1c316 | 1503 | struct varpool_node; |
2942c502 JH |
1504 | |
1505 | /* A varpool node set is a collection of varpool nodes. A varpool node | |
1506 | can appear in multiple sets. */ | |
1cb1a99f | 1507 | struct varpool_node_set_def |
2942c502 | 1508 | { |
b787e7a2 | 1509 | hash_map<varpool_node *, size_t> * map; |
d52f5295 | 1510 | vec<varpool_node *> nodes; |
2942c502 JH |
1511 | }; |
1512 | ||
fed5ae11 | 1513 | /* Iterator structure for cgraph node sets. */ |
84562394 | 1514 | struct cgraph_node_set_iterator |
fed5ae11 DK |
1515 | { |
1516 | cgraph_node_set set; | |
1517 | unsigned index; | |
84562394 | 1518 | }; |
fed5ae11 | 1519 | |
2942c502 | 1520 | /* Iterator structure for varpool node sets. */ |
84562394 | 1521 | struct varpool_node_set_iterator |
2942c502 JH |
1522 | { |
1523 | varpool_node_set set; | |
1524 | unsigned index; | |
84562394 | 1525 | }; |
2942c502 | 1526 | |
ba392339 JH |
1527 | /* Context of polymorphic call. It represent information about the type of |
1528 | instance that may reach the call. This is used by ipa-devirt walkers of the | |
1529 | type inheritance graph. */ | |
1530 | ||
1531 | class GTY(()) ipa_polymorphic_call_context { | |
1532 | public: | |
1533 | /* The called object appears in an object of type OUTER_TYPE | |
1534 | at offset OFFSET. When information is not 100% reliable, we | |
1535 | use SPECULATIVE_OUTER_TYPE and SPECULATIVE_OFFSET. */ | |
1536 | HOST_WIDE_INT offset; | |
1537 | HOST_WIDE_INT speculative_offset; | |
1538 | tree outer_type; | |
1539 | tree speculative_outer_type; | |
1540 | /* True if outer object may be in construction or destruction. */ | |
4081ada2 | 1541 | unsigned maybe_in_construction : 1; |
ba392339 | 1542 | /* True if outer object may be of derived type. */ |
4081ada2 | 1543 | unsigned maybe_derived_type : 1; |
ba392339 JH |
1544 | /* True if speculative outer object may be of derived type. We always |
1545 | speculate that construction does not happen. */ | |
4081ada2 | 1546 | unsigned speculative_maybe_derived_type : 1; |
ba392339 JH |
1547 | /* True if the context is invalid and all calls should be redirected |
1548 | to BUILTIN_UNREACHABLE. */ | |
4081ada2 JH |
1549 | unsigned invalid : 1; |
1550 | /* True if the outer type is dynamic. */ | |
1551 | unsigned dynamic : 1; | |
ba392339 JH |
1552 | |
1553 | /* Build empty "I know nothing" context. */ | |
1554 | ipa_polymorphic_call_context (); | |
1555 | /* Build polymorphic call context for indirect call E. */ | |
1556 | ipa_polymorphic_call_context (cgraph_edge *e); | |
1557 | /* Build polymorphic call context for IP invariant CST. | |
1558 | If specified, OTR_TYPE specify the type of polymorphic call | |
dfea3d6f | 1559 | that takes CST+OFFSET as a parameter. */ |
ba392339 JH |
1560 | ipa_polymorphic_call_context (tree cst, tree otr_type = NULL, |
1561 | HOST_WIDE_INT offset = 0); | |
1562 | /* Build context for pointer REF contained in FNDECL at statement STMT. | |
1563 | if INSTANCE is non-NULL, return pointer to the object described by | |
1564 | the context. */ | |
355fe088 | 1565 | ipa_polymorphic_call_context (tree fndecl, tree ref, gimple *stmt, |
ba392339 JH |
1566 | tree *instance = NULL); |
1567 | ||
1568 | /* Look for vtable stores or constructor calls to work out dynamic type | |
1569 | of memory location. */ | |
c628d1c3 | 1570 | bool get_dynamic_type (tree, tree, tree, gimple *, unsigned *); |
ba392339 JH |
1571 | |
1572 | /* Make context non-speculative. */ | |
1573 | void clear_speculation (); | |
1574 | ||
dfea3d6f | 1575 | /* Produce context specifying all derived types of OTR_TYPE. If OTR_TYPE is |
6ff65dd7 MJ |
1576 | NULL, the context is set to dummy "I know nothing" setting. */ |
1577 | void clear_outer_type (tree otr_type = NULL); | |
1578 | ||
ba392339 | 1579 | /* Walk container types and modify context to point to actual class |
67a1b94c JH |
1580 | containing OTR_TYPE (if non-NULL) as base class. |
1581 | Return true if resulting context is valid. | |
1582 | ||
1583 | When CONSIDER_PLACEMENT_NEW is false, reject contexts that may be made | |
5764ee3c | 1584 | valid only via allocation of new polymorphic type inside by means |
67a1b94c JH |
1585 | of placement new. |
1586 | ||
1587 | When CONSIDER_BASES is false, only look for actual fields, not base types | |
1588 | of TYPE. */ | |
1589 | bool restrict_to_inner_class (tree otr_type, | |
1590 | bool consider_placement_new = true, | |
1591 | bool consider_bases = true); | |
1592 | ||
1593 | /* Adjust all offsets in contexts by given number of bits. */ | |
1594 | void offset_by (HOST_WIDE_INT); | |
67914693 | 1595 | /* Use when we cannot track dynamic type change. This speculatively assume |
4081ada2 | 1596 | type change is not happening. */ |
f9bb202b | 1597 | void possible_dynamic_type_change (bool, tree otr_type = NULL); |
dfea3d6f JJ |
1598 | /* Assume that both THIS and a given context is valid and strengthen THIS |
1599 | if possible. Return true if any strengthening was made. | |
67a1b94c JH |
1600 | If actual type the context is being used in is known, OTR_TYPE should be |
1601 | set accordingly. This improves quality of combined result. */ | |
1602 | bool combine_with (ipa_polymorphic_call_context, tree otr_type = NULL); | |
df0d8136 | 1603 | bool meet_with (ipa_polymorphic_call_context, tree otr_type = NULL); |
67a1b94c JH |
1604 | |
1605 | /* Return TRUE if context is fully useless. */ | |
1606 | bool useless_p () const; | |
44210a96 MJ |
1607 | /* Return TRUE if this context conveys the same information as X. */ |
1608 | bool equal_to (const ipa_polymorphic_call_context &x) const; | |
ba392339 | 1609 | |
44210a96 MJ |
1610 | /* Dump human readable context to F. If NEWLINE is true, it will be |
1611 | terminated by a newline. */ | |
1612 | void dump (FILE *f, bool newline = true) const; | |
ba392339 JH |
1613 | void DEBUG_FUNCTION debug () const; |
1614 | ||
1615 | /* LTO streaming. */ | |
1616 | void stream_out (struct output_block *) const; | |
99b1c316 | 1617 | void stream_in (class lto_input_block *, class data_in *data_in); |
ba392339 JH |
1618 | |
1619 | private: | |
67a1b94c | 1620 | bool combine_speculation_with (tree, HOST_WIDE_INT, bool, tree); |
df0d8136 | 1621 | bool meet_speculation_with (tree, HOST_WIDE_INT, bool, tree); |
ba392339 JH |
1622 | void set_by_decl (tree, HOST_WIDE_INT); |
1623 | bool set_by_invariant (tree, tree, HOST_WIDE_INT); | |
df0d8136 | 1624 | bool speculation_consistent_p (tree, HOST_WIDE_INT, bool, tree) const; |
4081ada2 | 1625 | void make_speculative (tree otr_type = NULL); |
ba392339 JH |
1626 | }; |
1627 | ||
e33c6cd6 MJ |
1628 | /* Structure containing additional information about an indirect call. */ |
1629 | ||
6c1dae73 | 1630 | class GTY(()) cgraph_indirect_call_info |
e33c6cd6 | 1631 | { |
6c1dae73 | 1632 | public: |
ba392339 JH |
1633 | /* When agg_content is set, an offset where the call pointer is located |
1634 | within the aggregate. */ | |
1635 | HOST_WIDE_INT offset; | |
1636 | /* Context of the polymorphic call; use only when POLYMORPHIC flag is set. */ | |
1637 | ipa_polymorphic_call_context context; | |
b258210c MJ |
1638 | /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */ |
1639 | HOST_WIDE_INT otr_token; | |
1640 | /* Type of the object from OBJ_TYPE_REF_OBJECT. */ | |
ba392339 | 1641 | tree otr_type; |
e33c6cd6 MJ |
1642 | /* Index of the parameter that is called. */ |
1643 | int param_index; | |
5f902d76 JH |
1644 | /* ECF flags determined from the caller. */ |
1645 | int ecf_flags; | |
f1ba88b1 XHL |
1646 | |
1647 | /* Number of speculative call targets, it's less than GCOV_TOPN_VALUES. */ | |
1648 | unsigned num_speculative_call_targets : 16; | |
b258210c MJ |
1649 | |
1650 | /* Set when the call is a virtual call with the parameter being the | |
1651 | associated object pointer rather than a simple direct call. */ | |
1652 | unsigned polymorphic : 1; | |
8b7773a4 MJ |
1653 | /* Set when the call is a call of a pointer loaded from contents of an |
1654 | aggregate at offset. */ | |
1655 | unsigned agg_contents : 1; | |
c13bc3d9 MJ |
1656 | /* Set when this is a call through a member pointer. */ |
1657 | unsigned member_ptr : 1; | |
91bb9f80 MJ |
1658 | /* When the agg_contents bit is set, this one determines whether the |
1659 | destination is loaded from a parameter passed by reference. */ | |
8b7773a4 | 1660 | unsigned by_ref : 1; |
91bb9f80 MJ |
1661 | /* When the agg_contents bit is set, this one determines whether we can |
1662 | deduce from the function body that the loaded value from the reference is | |
1663 | never modified between the invocation of the function and the load | |
1664 | point. */ | |
1665 | unsigned guaranteed_unmodified : 1; | |
0127c169 JH |
1666 | /* For polymorphic calls this specify whether the virtual table pointer |
1667 | may have changed in between function entry and the call. */ | |
1668 | unsigned vptr_changed : 1; | |
e33c6cd6 MJ |
1669 | }; |
1670 | ||
6c1dae73 MS |
1671 | class GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"), |
1672 | for_user)) cgraph_edge | |
1673 | { | |
1674 | public: | |
99b1c316 | 1675 | friend struct cgraph_node; |
8b25212d | 1676 | friend class symbol_table; |
3dafb85c | 1677 | |
27c5a177 MJ |
1678 | /* Remove EDGE from the cgraph. */ |
1679 | static void remove (cgraph_edge *edge); | |
3dafb85c | 1680 | |
27c5a177 MJ |
1681 | /* Change field call_stmt of edge E to NEW_STMT. If UPDATE_SPECULATIVE and E |
1682 | is any component of speculative edge, then update all components. | |
1683 | Speculations can be resolved in the process and EDGE can be removed and | |
1684 | deallocated. Return the edge that now represents the call. */ | |
1685 | static cgraph_edge *set_call_stmt (cgraph_edge *e, gcall *new_stmt, | |
1686 | bool update_speculative = true); | |
3dafb85c ML |
1687 | |
1688 | /* Redirect callee of the edge to N. The function does not update underlying | |
1689 | call expression. */ | |
1690 | void redirect_callee (cgraph_node *n); | |
1691 | ||
6a4bad95 MJ |
1692 | /* If the edge does not lead to a thunk, simply redirect it to N. Otherwise |
1693 | create one or more equivalent thunks for N and redirect E to the first in | |
1694 | the chain. Note that it is then necessary to call | |
1695 | n->expand_all_artificial_thunks once all callers are redirected. */ | |
1696 | void redirect_callee_duplicating_thunks (cgraph_node *n); | |
1697 | ||
3dafb85c | 1698 | /* Make an indirect edge with an unknown callee an ordinary edge leading to |
27c5a177 MJ |
1699 | CALLEE. Speculations can be resolved in the process and EDGE can be |
1700 | removed and deallocated. Return the edge that now represents the | |
1701 | call. */ | |
1702 | static cgraph_edge *make_direct (cgraph_edge *edge, cgraph_node *callee); | |
3dafb85c ML |
1703 | |
1704 | /* Turn edge into speculative call calling N2. Update | |
1705 | the profile so the direct call is taken COUNT times | |
f1ba88b1 XHL |
1706 | with FREQUENCY. speculative_id is used to link direct calls with their |
1707 | corresponding IPA_REF_ADDR references when representing speculative calls. | |
845bb366 | 1708 | */ |
f1ba88b1 | 1709 | cgraph_edge *make_speculative (cgraph_node *n2, profile_count direct_count, |
845bb366 | 1710 | unsigned int speculative_id = 0); |
f1ba88b1 | 1711 | |
845bb366 JH |
1712 | /* Speculative call consists of an indirect edge and one or more |
1713 | direct edge+ref pairs. Speculative will expand to the following sequence: | |
1714 | ||
1715 | if (call_dest == target1) // reference to target1 | |
1716 | target1 (); // direct call to target1 | |
1717 | else if (call_dest == target2) // reference to targt2 | |
1718 | target2 (); // direct call to target2 | |
1719 | else | |
1720 | call_dest (); // indirect call | |
1721 | ||
1722 | Before the expansion we will have indirect call and the direct call+ref | |
1723 | pairs all linked to single statement. | |
1724 | ||
1725 | Note that ref may point to different symbol than the corresponding call | |
1726 | becuase the speculated edge may have been optimized (redirected to | |
1727 | a clone) or inlined. | |
1728 | ||
1729 | Given an edge which is part of speculative call, return the first | |
1730 | direct call edge in the speculative call sequence. | |
1731 | ||
1732 | In the example above called on any cgraph edge in the sequence it will | |
1733 | return direct call to target1. */ | |
1734 | cgraph_edge *first_speculative_call_target (); | |
1735 | ||
1736 | /* Return next speculative call target or NULL if there is none. | |
1737 | All targets are required to form an interval in the callee list. | |
1738 | ||
1739 | In example above, if called on call to target1 it will return call to | |
1740 | target2. */ | |
1741 | cgraph_edge *next_speculative_call_target () | |
1742 | { | |
1743 | cgraph_edge *e = this; | |
1744 | gcc_checking_assert (speculative && callee); | |
1745 | ||
1746 | if (e->next_callee && e->next_callee->speculative | |
1747 | && e->next_callee->call_stmt == e->call_stmt | |
1748 | && e->next_callee->lto_stmt_uid == e->lto_stmt_uid) | |
1749 | return e->next_callee; | |
1750 | return NULL; | |
1751 | } | |
1752 | ||
1753 | /* When called on any edge in the speculative call return the (unique) | |
1754 | indirect call edge in the speculative call sequence. */ | |
1755 | cgraph_edge *speculative_call_indirect_edge () | |
1756 | { | |
1757 | gcc_checking_assert (speculative); | |
1758 | if (!callee) | |
1759 | return this; | |
1760 | for (cgraph_edge *e2 = caller->indirect_calls; | |
1761 | true; e2 = e2->next_callee) | |
1762 | if (e2->speculative | |
1763 | && call_stmt == e2->call_stmt | |
1764 | && lto_stmt_uid == e2->lto_stmt_uid) | |
1765 | return e2; | |
1766 | } | |
1767 | ||
1768 | /* When called on any edge in speculative call and when given any target | |
1769 | of ref which is speculated to it returns the corresponding direct call. | |
1770 | ||
1771 | In example above if called on function target2 it will return call to | |
1772 | target2. */ | |
1773 | cgraph_edge *speculative_call_for_target (cgraph_node *); | |
1774 | ||
1775 | /* Return REF corresponding to direct call in the specualtive call | |
1776 | sequence. */ | |
1777 | ipa_ref *speculative_call_target_ref () | |
1778 | { | |
1779 | ipa_ref *ref; | |
1780 | ||
1781 | gcc_checking_assert (speculative); | |
1782 | for (unsigned int i = 0; caller->iterate_reference (i, ref); i++) | |
1783 | if (ref->speculative && ref->speculative_id == speculative_id | |
1784 | && ref->stmt == (gimple *)call_stmt | |
1785 | && ref->lto_stmt_uid == lto_stmt_uid) | |
1786 | return ref; | |
1787 | gcc_unreachable (); | |
1788 | } | |
3dafb85c | 1789 | |
27c5a177 MJ |
1790 | /* Speculative call edge turned out to be direct call to CALLEE_DECL. Remove |
1791 | the speculative call sequence and return edge representing the call, the | |
1792 | original EDGE can be removed and deallocated. It is up to caller to | |
1793 | redirect the call as appropriate. Return the edge that now represents the | |
f1ba88b1 XHL |
1794 | call. |
1795 | ||
1796 | For "speculative" indirect call that contains multiple "speculative" | |
1797 | targets (i.e. edge->indirect_info->num_speculative_call_targets > 1), | |
1798 | decrease the count and only remove current direct edge. | |
1799 | ||
1800 | If no speculative direct call left to the speculative indirect call, remove | |
1801 | the speculative of both the indirect call and corresponding direct edge. | |
1802 | ||
1803 | It is up to caller to iteratively resolve each "speculative" direct call | |
1804 | and redirect the call as appropriate. */ | |
27c5a177 MJ |
1805 | static cgraph_edge *resolve_speculation (cgraph_edge *edge, |
1806 | tree callee_decl = NULL); | |
3dafb85c ML |
1807 | |
1808 | /* If necessary, change the function declaration in the call statement | |
27c5a177 MJ |
1809 | associated with edge E so that it corresponds to the edge callee. |
1810 | Speculations can be resolved in the process and EDGE can be removed and | |
f1ba88b1 XHL |
1811 | deallocated. |
1812 | ||
1813 | The edge could be one of speculative direct call generated from speculative | |
1814 | indirect call. In this circumstance, decrease the speculative targets | |
1815 | count (i.e. num_speculative_call_targets) and redirect call stmt to the | |
1816 | corresponding i-th target. If no speculative direct call left to the | |
1817 | speculative indirect call, remove "speculative" of the indirect call and | |
1818 | also redirect stmt to it's final direct target. | |
1819 | ||
1820 | It is up to caller to iteratively transform each "speculative" | |
1821 | direct call as appropriate. */ | |
27c5a177 | 1822 | static gimple *redirect_call_stmt_to_callee (cgraph_edge *e); |
3dafb85c ML |
1823 | |
1824 | /* Create clone of edge in the node N represented | |
1825 | by CALL_EXPR the callgraph. */ | |
538dd0b7 | 1826 | cgraph_edge * clone (cgraph_node *n, gcall *call_stmt, unsigned stmt_uid, |
1bad9c18 | 1827 | profile_count num, profile_count den, |
3995f3a2 | 1828 | bool update_original); |
3dafb85c | 1829 | |
90988f77 | 1830 | /* Verify edge count and frequency. */ |
1bad9c18 | 1831 | bool verify_count (); |
90988f77 | 1832 | |
67914693 | 1833 | /* Return true when call of edge cannot lead to return from caller |
3dafb85c ML |
1834 | and thus it is safe to ignore its side effects for IPA analysis |
1835 | when computing side effects of the caller. */ | |
1836 | bool cannot_lead_to_return_p (void); | |
1837 | ||
1838 | /* Return true when the edge represents a direct recursion. */ | |
1839 | bool recursive_p (void); | |
1840 | ||
bf321336 | 1841 | /* Return true if the edge may be considered hot. */ |
3dafb85c ML |
1842 | bool maybe_hot_p (void); |
1843 | ||
8b25212d ML |
1844 | /* Get unique identifier of the edge. */ |
1845 | inline int get_uid () | |
1846 | { | |
1847 | return m_uid; | |
1848 | } | |
1849 | ||
db30281f ML |
1850 | /* Get summary id of the edge. */ |
1851 | inline int get_summary_id () | |
1852 | { | |
1853 | return m_summary_id; | |
1854 | } | |
1855 | ||
3dafb85c ML |
1856 | /* Rebuild cgraph edges for current function node. This needs to be run after |
1857 | passes that don't update the cgraph. */ | |
1858 | static unsigned int rebuild_edges (void); | |
1859 | ||
1860 | /* Rebuild cgraph references for current function node. This needs to be run | |
1861 | after passes that don't update the cgraph. */ | |
1862 | static void rebuild_references (void); | |
1863 | ||
f714ecf5 JH |
1864 | /* During LTO stream in this can be used to check whether call can possibly |
1865 | be internal to the current translation unit. */ | |
1866 | bool possibly_call_in_translation_unit_p (void); | |
1867 | ||
f1ba88b1 XHL |
1868 | /* Return num_speculative_targets of this edge. */ |
1869 | int num_speculative_call_targets_p (void); | |
1870 | ||
6009ee7b | 1871 | /* Expected number of executions: calculated in profile.c. */ |
3995f3a2 | 1872 | profile_count count; |
d52f5295 ML |
1873 | cgraph_node *caller; |
1874 | cgraph_node *callee; | |
3dafb85c ML |
1875 | cgraph_edge *prev_caller; |
1876 | cgraph_edge *next_caller; | |
1877 | cgraph_edge *prev_callee; | |
1878 | cgraph_edge *next_callee; | |
538dd0b7 | 1879 | gcall *call_stmt; |
e33c6cd6 MJ |
1880 | /* Additional information about an indirect call. Not cleared when an edge |
1881 | becomes direct. */ | |
3dafb85c | 1882 | cgraph_indirect_call_info *indirect_info; |
18c6ada9 | 1883 | PTR GTY ((skip (""))) aux; |
61a05df1 JH |
1884 | /* When equal to CIF_OK, inline this call. Otherwise, points to the |
1885 | explanation why function was not inlined. */ | |
84562394 | 1886 | enum cgraph_inline_failed_t inline_failed; |
6009ee7b MJ |
1887 | /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt |
1888 | when the function is serialized in. */ | |
1889 | unsigned int lto_stmt_uid; | |
f1ba88b1 XHL |
1890 | /* speculative id is used to link direct calls with their corresponding |
1891 | IPA_REF_ADDR references when representing speculative calls. */ | |
1892 | unsigned int speculative_id : 16; | |
e33c6cd6 MJ |
1893 | /* Whether this edge was made direct by indirect inlining. */ |
1894 | unsigned int indirect_inlining_edge : 1; | |
1895 | /* Whether this edge describes an indirect call with an undetermined | |
1896 | callee. */ | |
1897 | unsigned int indirect_unknown_callee : 1; | |
1898 | /* Whether this edge is still a dangling */ | |
d7f09764 DN |
1899 | /* True if the corresponding CALL stmt cannot be inlined. */ |
1900 | unsigned int call_stmt_cannot_inline_p : 1; | |
2505c5ed JH |
1901 | /* Can this call throw externally? */ |
1902 | unsigned int can_throw_external : 1; | |
042ae7d2 JH |
1903 | /* Edges with SPECULATIVE flag represents indirect calls that was |
1904 | speculatively turned into direct (i.e. by profile feedback). | |
1905 | The final code sequence will have form: | |
1906 | ||
1907 | if (call_target == expected_fn) | |
1908 | expected_fn (); | |
1909 | else | |
1910 | call_target (); | |
1911 | ||
1912 | Every speculative call is represented by three components attached | |
1913 | to a same call statement: | |
1914 | 1) a direct call (to expected_fn) | |
1915 | 2) an indirect call (to call_target) | |
dfea3d6f | 1916 | 3) a IPA_REF_ADDR reference to expected_fn. |
042ae7d2 JH |
1917 | |
1918 | Optimizers may later redirect direct call to clone, so 1) and 3) | |
dfea3d6f | 1919 | do not need to necessarily agree with destination. */ |
042ae7d2 | 1920 | unsigned int speculative : 1; |
f9bb202b JH |
1921 | /* Set to true when caller is a constructor or destructor of polymorphic |
1922 | type. */ | |
1923 | unsigned in_polymorphic_cdtor : 1; | |
3dafb85c | 1924 | |
f13fe18b JH |
1925 | /* Return true if call must bind to current definition. */ |
1926 | bool binds_to_current_def_p (); | |
1927 | ||
1bad9c18 JH |
1928 | /* Expected frequency of executions within the function. |
1929 | When set to CGRAPH_FREQ_BASE, the edge is expected to be called once | |
1930 | per function call. The range is 0 to CGRAPH_FREQ_MAX. */ | |
1931 | int frequency (); | |
41f0e819 JH |
1932 | |
1933 | /* Expected frequency of executions within the function. */ | |
1934 | sreal sreal_frequency (); | |
3dafb85c | 1935 | private: |
8b25212d ML |
1936 | /* Unique id of the edge. */ |
1937 | int m_uid; | |
1938 | ||
db30281f ML |
1939 | /* Summary id that is recycled. */ |
1940 | int m_summary_id; | |
1941 | ||
3dafb85c ML |
1942 | /* Remove the edge from the list of the callers of the callee. */ |
1943 | void remove_caller (void); | |
1944 | ||
1945 | /* Remove the edge from the list of the callees of the caller. */ | |
1946 | void remove_callee (void); | |
90988f77 ML |
1947 | |
1948 | /* Set callee N of call graph edge and add it to the corresponding set of | |
1949 | callers. */ | |
1950 | void set_callee (cgraph_node *n); | |
1951 | ||
1952 | /* Output flags of edge to a file F. */ | |
1953 | void dump_edge_flags (FILE *f); | |
1954 | ||
b2784a96 ML |
1955 | /* Dump edge to stderr. */ |
1956 | void DEBUG_FUNCTION debug (void); | |
1957 | ||
90988f77 ML |
1958 | /* Verify that call graph edge corresponds to DECL from the associated |
1959 | statement. Return true if the verification should fail. */ | |
1960 | bool verify_corresponds_to_fndecl (tree decl); | |
1c4a429a JH |
1961 | }; |
1962 | ||
45a80bb9 JH |
1963 | #define CGRAPH_FREQ_BASE 1000 |
1964 | #define CGRAPH_FREQ_MAX 100000 | |
1965 | ||
8a4a83ed JH |
1966 | /* The varpool data structure. |
1967 | Each static variable decl has assigned varpool_node. */ | |
e69529cd | 1968 | |
6c1dae73 MS |
1969 | struct GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node |
1970 | { | |
a65d584d ML |
1971 | /* Constructor. */ |
1972 | explicit varpool_node () | |
1973 | : symtab_node (SYMTAB_VARIABLE), output (0), dynamically_initialized (0), | |
1974 | tls_model (TLS_MODEL_NONE), used_by_single_function (0) | |
1975 | {} | |
1976 | ||
9041d2e6 ML |
1977 | /* Dump given varpool node to F. */ |
1978 | void dump (FILE *f); | |
1979 | ||
1980 | /* Dump given varpool node to stderr. */ | |
1981 | void DEBUG_FUNCTION debug (void); | |
1982 | ||
1983 | /* Remove variable from symbol table. */ | |
1984 | void remove (void); | |
1985 | ||
1986 | /* Remove node initializer when it is no longer needed. */ | |
1987 | void remove_initializer (void); | |
1988 | ||
1989 | void analyze (void); | |
1990 | ||
1991 | /* Return variable availability. */ | |
f13fe18b | 1992 | availability get_availability (symtab_node *ref = NULL); |
9041d2e6 ML |
1993 | |
1994 | /* When doing LTO, read variable's constructor from disk if | |
1995 | it is not already present. */ | |
1996 | tree get_constructor (void); | |
1997 | ||
1998 | /* Return true if variable has constructor that can be used for folding. */ | |
1999 | bool ctor_useable_for_folding_p (void); | |
2000 | ||
2001 | /* For given variable pool node, walk the alias chain to return the function | |
2002 | the variable is alias of. Do not walk through thunks. | |
f13fe18b JH |
2003 | When AVAILABILITY is non-NULL, get minimal availability in the chain. |
2004 | When REF is non-NULL, assume that reference happens in symbol REF | |
2005 | when determining the availability. */ | |
9041d2e6 | 2006 | inline varpool_node *ultimate_alias_target |
f13fe18b | 2007 | (availability *availability = NULL, symtab_node *ref = NULL); |
9041d2e6 ML |
2008 | |
2009 | /* Return node that alias is aliasing. */ | |
2010 | inline varpool_node *get_alias_target (void); | |
2011 | ||
2012 | /* Output one variable, if necessary. Return whether we output it. */ | |
2013 | bool assemble_decl (void); | |
2014 | ||
2015 | /* For variables in named sections make sure get_variable_section | |
2016 | is called before we switch to those sections. Then section | |
2017 | conflicts between read-only and read-only requiring relocations | |
2018 | sections can be resolved. */ | |
2019 | void finalize_named_section_flags (void); | |
2020 | ||
dfea3d6f | 2021 | /* Call callback on varpool symbol and aliases associated to varpool symbol. |
9041d2e6 ML |
2022 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are |
2023 | skipped. */ | |
31de7606 JH |
2024 | bool call_for_symbol_and_aliases (bool (*callback) (varpool_node *, void *), |
2025 | void *data, | |
2026 | bool include_overwritable); | |
9041d2e6 ML |
2027 | |
2028 | /* Return true when variable should be considered externally visible. */ | |
2029 | bool externally_visible_p (void); | |
2030 | ||
2031 | /* Return true when all references to variable must be visible | |
2032 | in ipa_ref_list. | |
2033 | i.e. if the variable is not externally visible or not used in some magic | |
2034 | way (asm statement or such). | |
2035 | The magic uses are all summarized in force_output flag. */ | |
2036 | inline bool all_refs_explicit_p (); | |
2037 | ||
2038 | /* Return true when variable can be removed from variable pool | |
2039 | if all direct calls are eliminated. */ | |
2040 | inline bool can_remove_if_no_refs_p (void); | |
2041 | ||
3dafb85c ML |
2042 | /* Add the variable DECL to the varpool. |
2043 | Unlike finalize_decl function is intended to be used | |
2044 | by middle end and allows insertion of new variable at arbitrary point | |
2045 | of compilation. */ | |
2046 | static void add (tree decl); | |
2047 | ||
9041d2e6 ML |
2048 | /* Return varpool node for given symbol and check it is a function. */ |
2049 | static inline varpool_node *get (const_tree decl); | |
2050 | ||
2051 | /* Mark DECL as finalized. By finalizing the declaration, frontend instruct | |
2052 | the middle end to output the variable to asm file, if needed or externally | |
2053 | visible. */ | |
2054 | static void finalize_decl (tree decl); | |
2055 | ||
9041d2e6 ML |
2056 | /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful. |
2057 | Extra name aliases are output whenever DECL is output. */ | |
2058 | static varpool_node * create_extra_name_alias (tree alias, tree decl); | |
2059 | ||
2060 | /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful. | |
2061 | Extra name aliases are output whenever DECL is output. */ | |
2062 | static varpool_node * create_alias (tree, tree); | |
2063 | ||
2064 | /* Dump the variable pool to F. */ | |
2065 | static void dump_varpool (FILE *f); | |
2066 | ||
2067 | /* Dump the variable pool to stderr. */ | |
2068 | static void DEBUG_FUNCTION debug_varpool (void); | |
2069 | ||
2070 | /* Allocate new callgraph node and insert it into basic data structures. */ | |
2071 | static varpool_node *create_empty (void); | |
2072 | ||
2073 | /* Return varpool node assigned to DECL. Create new one when needed. */ | |
2074 | static varpool_node *get_create (tree decl); | |
2075 | ||
2076 | /* Given an assembler name, lookup node. */ | |
2077 | static varpool_node *get_for_asmname (tree asmname); | |
2078 | ||
6b02a499 | 2079 | /* Set when variable is scheduled to be assembled. */ |
b4e19405 | 2080 | unsigned output : 1; |
eb1d8159 | 2081 | |
59b36ecf JJ |
2082 | /* Set if the variable is dynamically initialized, except for |
2083 | function local statics. */ | |
2084 | unsigned dynamically_initialized : 1; | |
56363ffd JH |
2085 | |
2086 | ENUM_BITFIELD(tls_model) tls_model : 3; | |
eb6a09a7 JH |
2087 | |
2088 | /* Set if the variable is known to be used by single function only. | |
dfea3d6f | 2089 | This is computed by ipa_single_use pass and used by late optimizations |
eb6a09a7 JH |
2090 | in places where optimization would be valid for local static variable |
2091 | if we did not do any inter-procedural code movement. */ | |
2092 | unsigned used_by_single_function : 1; | |
d52f5295 | 2093 | |
9041d2e6 ML |
2094 | private: |
2095 | /* Assemble thunks and aliases associated to varpool node. */ | |
2096 | void assemble_aliases (void); | |
31de7606 JH |
2097 | |
2098 | /* Worker for call_for_node_and_aliases. */ | |
2099 | bool call_for_symbol_and_aliases_1 (bool (*callback) (varpool_node *, void *), | |
2100 | void *data, | |
2101 | bool include_overwritable); | |
e69529cd JH |
2102 | }; |
2103 | ||
65d630d4 | 2104 | /* Every top level asm statement is put into a asm_node. */ |
474eccc6 | 2105 | |
65d630d4 | 2106 | struct GTY(()) asm_node { |
474eccc6 | 2107 | /* Next asm node. */ |
3dafb85c | 2108 | asm_node *next; |
474eccc6 ILT |
2109 | /* String for this asm node. */ |
2110 | tree asm_str; | |
2111 | /* Ordering of all cgraph nodes. */ | |
2112 | int order; | |
2113 | }; | |
2114 | ||
5d59b5e1 LC |
2115 | /* Report whether or not THIS symtab node is a function, aka cgraph_node. */ |
2116 | ||
2117 | template <> | |
2118 | template <> | |
2119 | inline bool | |
7de90a6c | 2120 | is_a_helper <cgraph_node *>::test (symtab_node *p) |
5d59b5e1 | 2121 | { |
d52f5295 | 2122 | return p && p->type == SYMTAB_FUNCTION; |
5d59b5e1 LC |
2123 | } |
2124 | ||
dfea3d6f | 2125 | /* Report whether or not THIS symtab node is a variable, aka varpool_node. */ |
5d59b5e1 LC |
2126 | |
2127 | template <> | |
2128 | template <> | |
2129 | inline bool | |
7de90a6c | 2130 | is_a_helper <varpool_node *>::test (symtab_node *p) |
5d59b5e1 | 2131 | { |
d52f5295 | 2132 | return p && p->type == SYMTAB_VARIABLE; |
5d59b5e1 LC |
2133 | } |
2134 | ||
3dafb85c ML |
2135 | typedef void (*cgraph_edge_hook)(cgraph_edge *, void *); |
2136 | typedef void (*cgraph_node_hook)(cgraph_node *, void *); | |
2137 | typedef void (*varpool_node_hook)(varpool_node *, void *); | |
2138 | typedef void (*cgraph_2edge_hook)(cgraph_edge *, cgraph_edge *, void *); | |
2139 | typedef void (*cgraph_2node_hook)(cgraph_node *, cgraph_node *, void *); | |
2140 | ||
2141 | struct cgraph_edge_hook_list; | |
2142 | struct cgraph_node_hook_list; | |
2143 | struct varpool_node_hook_list; | |
2144 | struct cgraph_2edge_hook_list; | |
2145 | struct cgraph_2node_hook_list; | |
2146 | ||
2147 | /* Map from a symbol to initialization/finalization priorities. */ | |
2148 | struct GTY(()) symbol_priority_map { | |
3dafb85c ML |
2149 | priority_type init; |
2150 | priority_type fini; | |
2151 | }; | |
2152 | ||
2153 | enum symtab_state | |
f45e0ad1 | 2154 | { |
66058468 | 2155 | /* Frontend is parsing and finalizing functions. */ |
3dafb85c | 2156 | PARSING, |
f45e0ad1 | 2157 | /* Callgraph is being constructed. It is safe to add new functions. */ |
3dafb85c | 2158 | CONSTRUCTION, |
17e0fc92 | 2159 | /* Callgraph is being streamed-in at LTO time. */ |
3dafb85c | 2160 | LTO_STREAMING, |
17e0fc92 | 2161 | /* Callgraph is built and early IPA passes are being run. */ |
3dafb85c | 2162 | IPA, |
7a388ee4 | 2163 | /* Callgraph is built and all functions are transformed to SSA form. */ |
3dafb85c | 2164 | IPA_SSA, |
17e0fc92 JH |
2165 | /* All inline decisions are done; it is now possible to remove extern inline |
2166 | functions and virtual call targets. */ | |
2167 | IPA_SSA_AFTER_INLINING, | |
f45e0ad1 | 2168 | /* Functions are now ordered and being passed to RTL expanders. */ |
3dafb85c | 2169 | EXPANSION, |
f45e0ad1 | 2170 | /* All cgraph expansion is done. */ |
3dafb85c | 2171 | FINISHED |
f45e0ad1 | 2172 | }; |
1c4a429a | 2173 | |
7edd9b15 | 2174 | struct asmname_hasher : ggc_ptr_hash <symtab_node> |
2a22f99c | 2175 | { |
2a22f99c | 2176 | typedef const_tree compare_type; |
2a22f99c TS |
2177 | |
2178 | static hashval_t hash (symtab_node *n); | |
2179 | static bool equal (symtab_node *n, const_tree t); | |
2a22f99c TS |
2180 | }; |
2181 | ||
ae7a23a3 JH |
2182 | /* Core summaries maintained about symbols. */ |
2183 | ||
67f3791f JH |
2184 | struct thunk_info; |
2185 | template <class T> class function_summary; | |
2186 | typedef function_summary <thunk_info *> thunk_summary; | |
2187 | ||
ae7a23a3 JH |
2188 | struct clone_info; |
2189 | template <class T> class function_summary; | |
2190 | typedef function_summary <clone_info *> clone_summary; | |
2191 | ||
3dafb85c ML |
2192 | class GTY((tag ("SYMTAB"))) symbol_table |
2193 | { | |
2194 | public: | |
99b1c316 MS |
2195 | friend struct symtab_node; |
2196 | friend struct cgraph_node; | |
2197 | friend struct cgraph_edge; | |
3dafb85c | 2198 | |
019f36a6 JH |
2199 | symbol_table (): |
2200 | cgraph_count (0), cgraph_max_uid (1), cgraph_max_summary_id (0), | |
2201 | edges_count (0), edges_max_uid (1), edges_max_summary_id (0), | |
2202 | cgraph_released_summary_ids (), edge_released_summary_ids (), | |
2203 | nodes (NULL), asmnodes (NULL), asm_last_node (NULL), | |
b74d8dc4 | 2204 | order (0), max_unit (0), global_info_ready (false), state (PARSING), |
019f36a6 JH |
2205 | function_flags_ready (false), cpp_implicit_aliases_done (false), |
2206 | section_hash (NULL), assembler_name_hash (NULL), init_priority_hash (NULL), | |
2207 | dump_file (NULL), ipa_clones_dump_file (NULL), cloned_nodes (), | |
ae7a23a3 | 2208 | m_thunks (NULL), m_clones (NULL), |
019f36a6 JH |
2209 | m_first_edge_removal_hook (NULL), m_first_cgraph_removal_hook (NULL), |
2210 | m_first_edge_duplicated_hook (NULL), m_first_cgraph_duplicated_hook (NULL), | |
2211 | m_first_cgraph_insertion_hook (NULL), m_first_varpool_insertion_hook (NULL), | |
2212 | m_first_varpool_removal_hook (NULL) | |
4008290f ML |
2213 | { |
2214 | } | |
2215 | ||
3dafb85c | 2216 | /* Initialize callgraph dump file. */ |
c582198b | 2217 | void initialize (void); |
3dafb85c ML |
2218 | |
2219 | /* Register a top-level asm statement ASM_STR. */ | |
2220 | inline asm_node *finalize_toplevel_asm (tree asm_str); | |
2221 | ||
2222 | /* Analyze the whole compilation unit once it is parsed completely. */ | |
2223 | void finalize_compilation_unit (void); | |
2224 | ||
2225 | /* C++ frontend produce same body aliases all over the place, even before PCH | |
2226 | gets streamed out. It relies on us linking the aliases with their function | |
dfea3d6f JJ |
2227 | in order to do the fixups, but ipa-ref is not PCH safe. Consequently we |
2228 | first produce aliases without links, but once C++ FE is sure it won't | |
2229 | stream PCH we build the links via this function. */ | |
3dafb85c ML |
2230 | void process_same_body_aliases (void); |
2231 | ||
2232 | /* Perform simple optimizations based on callgraph. */ | |
2233 | void compile (void); | |
2234 | ||
2235 | /* Process CGRAPH_NEW_FUNCTIONS and perform actions necessary to add these | |
2236 | functions into callgraph in a way so they look like ordinary reachable | |
2237 | functions inserted into callgraph already at construction time. */ | |
2238 | void process_new_functions (void); | |
2239 | ||
3dafb85c ML |
2240 | /* Register a symbol NODE. */ |
2241 | inline void register_symbol (symtab_node *node); | |
2242 | ||
2243 | inline void | |
2244 | clear_asm_symbols (void) | |
2245 | { | |
2246 | asmnodes = NULL; | |
2247 | asm_last_node = NULL; | |
2248 | } | |
2249 | ||
2250 | /* Perform reachability analysis and reclaim all unreachable nodes. */ | |
17e0fc92 | 2251 | bool remove_unreachable_nodes (FILE *file); |
3dafb85c ML |
2252 | |
2253 | /* Optimization of function bodies might've rendered some variables as | |
2254 | unnecessary so we want to avoid these from being compiled. Re-do | |
2255 | reachability starting from variables that are either externally visible | |
2256 | or was referred from the asm output routines. */ | |
2257 | void remove_unreferenced_decls (void); | |
2258 | ||
2259 | /* Unregister a symbol NODE. */ | |
2260 | inline void unregister (symtab_node *node); | |
2261 | ||
2262 | /* Allocate new callgraph node and insert it into basic data structures. */ | |
2263 | cgraph_node *create_empty (void); | |
2264 | ||
74644756 ML |
2265 | /* Release a callgraph NODE. */ |
2266 | void release_symbol (cgraph_node *node); | |
3dafb85c ML |
2267 | |
2268 | /* Output all variables enqueued to be assembled. */ | |
2269 | bool output_variables (void); | |
2270 | ||
3dafb85c ML |
2271 | /* Weakrefs may be associated to external decls and thus not output |
2272 | at expansion time. Emit all necessary aliases. */ | |
2273 | void output_weakrefs (void); | |
2274 | ||
2275 | /* Return first static symbol with definition. */ | |
2276 | inline symtab_node *first_symbol (void); | |
2277 | ||
2278 | /* Return first assembler symbol. */ | |
2279 | inline asm_node * | |
2280 | first_asm_symbol (void) | |
2281 | { | |
2282 | return asmnodes; | |
2283 | } | |
2284 | ||
2285 | /* Return first static symbol with definition. */ | |
2286 | inline symtab_node *first_defined_symbol (void); | |
2287 | ||
2288 | /* Return first variable. */ | |
2289 | inline varpool_node *first_variable (void); | |
2290 | ||
2291 | /* Return next variable after NODE. */ | |
2292 | inline varpool_node *next_variable (varpool_node *node); | |
2293 | ||
2294 | /* Return first static variable with initializer. */ | |
2295 | inline varpool_node *first_static_initializer (void); | |
2296 | ||
2297 | /* Return next static variable with initializer after NODE. */ | |
2298 | inline varpool_node *next_static_initializer (varpool_node *node); | |
2299 | ||
2300 | /* Return first static variable with definition. */ | |
2301 | inline varpool_node *first_defined_variable (void); | |
2302 | ||
2303 | /* Return next static variable with definition after NODE. */ | |
2304 | inline varpool_node *next_defined_variable (varpool_node *node); | |
2305 | ||
2306 | /* Return first function with body defined. */ | |
2307 | inline cgraph_node *first_defined_function (void); | |
2308 | ||
2309 | /* Return next function with body defined after NODE. */ | |
2310 | inline cgraph_node *next_defined_function (cgraph_node *node); | |
2311 | ||
2312 | /* Return first function. */ | |
2313 | inline cgraph_node *first_function (void); | |
2314 | ||
2315 | /* Return next function. */ | |
2316 | inline cgraph_node *next_function (cgraph_node *node); | |
2317 | ||
2318 | /* Return first function with body defined. */ | |
2319 | cgraph_node *first_function_with_gimple_body (void); | |
2320 | ||
2321 | /* Return next reachable static variable with initializer after NODE. */ | |
2322 | inline cgraph_node *next_function_with_gimple_body (cgraph_node *node); | |
2323 | ||
2324 | /* Register HOOK to be called with DATA on each removed edge. */ | |
2325 | cgraph_edge_hook_list *add_edge_removal_hook (cgraph_edge_hook hook, | |
2326 | void *data); | |
2327 | ||
2328 | /* Remove ENTRY from the list of hooks called on removing edges. */ | |
2329 | void remove_edge_removal_hook (cgraph_edge_hook_list *entry); | |
2330 | ||
2331 | /* Register HOOK to be called with DATA on each removed node. */ | |
2332 | cgraph_node_hook_list *add_cgraph_removal_hook (cgraph_node_hook hook, | |
2333 | void *data); | |
2334 | ||
2335 | /* Remove ENTRY from the list of hooks called on removing nodes. */ | |
2336 | void remove_cgraph_removal_hook (cgraph_node_hook_list *entry); | |
2337 | ||
2338 | /* Register HOOK to be called with DATA on each removed node. */ | |
2339 | varpool_node_hook_list *add_varpool_removal_hook (varpool_node_hook hook, | |
2340 | void *data); | |
2341 | ||
2342 | /* Remove ENTRY from the list of hooks called on removing nodes. */ | |
2343 | void remove_varpool_removal_hook (varpool_node_hook_list *entry); | |
2344 | ||
2345 | /* Register HOOK to be called with DATA on each inserted node. */ | |
2346 | cgraph_node_hook_list *add_cgraph_insertion_hook (cgraph_node_hook hook, | |
2347 | void *data); | |
2348 | ||
2349 | /* Remove ENTRY from the list of hooks called on inserted nodes. */ | |
2350 | void remove_cgraph_insertion_hook (cgraph_node_hook_list *entry); | |
2351 | ||
2352 | /* Register HOOK to be called with DATA on each inserted node. */ | |
2353 | varpool_node_hook_list *add_varpool_insertion_hook (varpool_node_hook hook, | |
2354 | void *data); | |
2355 | ||
2356 | /* Remove ENTRY from the list of hooks called on inserted nodes. */ | |
2357 | void remove_varpool_insertion_hook (varpool_node_hook_list *entry); | |
2358 | ||
2359 | /* Register HOOK to be called with DATA on each duplicated edge. */ | |
2360 | cgraph_2edge_hook_list *add_edge_duplication_hook (cgraph_2edge_hook hook, | |
2361 | void *data); | |
2362 | /* Remove ENTRY from the list of hooks called on duplicating edges. */ | |
2363 | void remove_edge_duplication_hook (cgraph_2edge_hook_list *entry); | |
2364 | ||
2365 | /* Register HOOK to be called with DATA on each duplicated node. */ | |
2366 | cgraph_2node_hook_list *add_cgraph_duplication_hook (cgraph_2node_hook hook, | |
2367 | void *data); | |
2368 | ||
2369 | /* Remove ENTRY from the list of hooks called on duplicating nodes. */ | |
2370 | void remove_cgraph_duplication_hook (cgraph_2node_hook_list *entry); | |
2371 | ||
2372 | /* Call all edge removal hooks. */ | |
2373 | void call_edge_removal_hooks (cgraph_edge *e); | |
2374 | ||
2375 | /* Call all node insertion hooks. */ | |
2376 | void call_cgraph_insertion_hooks (cgraph_node *node); | |
2377 | ||
2378 | /* Call all node removal hooks. */ | |
2379 | void call_cgraph_removal_hooks (cgraph_node *node); | |
2380 | ||
2381 | /* Call all node duplication hooks. */ | |
2382 | void call_cgraph_duplication_hooks (cgraph_node *node, cgraph_node *node2); | |
2383 | ||
2384 | /* Call all edge duplication hooks. */ | |
2385 | void call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2); | |
2386 | ||
2387 | /* Call all node removal hooks. */ | |
2388 | void call_varpool_removal_hooks (varpool_node *node); | |
2389 | ||
2390 | /* Call all node insertion hooks. */ | |
2391 | void call_varpool_insertion_hooks (varpool_node *node); | |
2392 | ||
2393 | /* Arrange node to be first in its entry of assembler_name_hash. */ | |
2394 | void symtab_prevail_in_asm_name_hash (symtab_node *node); | |
2395 | ||
dfea3d6f | 2396 | /* Initialize asm name hash unless. */ |
3dafb85c ML |
2397 | void symtab_initialize_asm_name_hash (void); |
2398 | ||
2399 | /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */ | |
2400 | void change_decl_assembler_name (tree decl, tree name); | |
e69529cd | 2401 | |
6c52831d ML |
2402 | /* Dump symbol table to F. */ |
2403 | void dump (FILE *f); | |
2404 | ||
34e64622 GB |
2405 | /* Dump symbol table to F in graphviz format. */ |
2406 | void dump_graphviz (FILE *f); | |
2407 | ||
6c52831d | 2408 | /* Dump symbol table to stderr. */ |
e94497fb | 2409 | void DEBUG_FUNCTION debug (void); |
6c52831d | 2410 | |
db30281f ML |
2411 | /* Assign a new summary ID for the callgraph NODE. */ |
2412 | inline int assign_summary_id (cgraph_node *node) | |
2413 | { | |
fe248a88 ML |
2414 | if (!cgraph_released_summary_ids.is_empty ()) |
2415 | node->m_summary_id = cgraph_released_summary_ids.pop (); | |
2416 | else | |
2417 | node->m_summary_id = cgraph_max_summary_id++; | |
2418 | ||
db30281f ML |
2419 | return node->m_summary_id; |
2420 | } | |
2421 | ||
2422 | /* Assign a new summary ID for the callgraph EDGE. */ | |
2423 | inline int assign_summary_id (cgraph_edge *edge) | |
2424 | { | |
fe248a88 ML |
2425 | if (!edge_released_summary_ids.is_empty ()) |
2426 | edge->m_summary_id = edge_released_summary_ids.pop (); | |
2427 | else | |
2428 | edge->m_summary_id = edges_max_summary_id++; | |
2429 | ||
db30281f ML |
2430 | return edge->m_summary_id; |
2431 | } | |
2432 | ||
71e54687 JH |
2433 | /* Return true if assembler names NAME1 and NAME2 leads to the same symbol |
2434 | name. */ | |
2435 | static bool assembler_names_equal_p (const char *name1, const char *name2); | |
2436 | ||
3dafb85c ML |
2437 | int cgraph_count; |
2438 | int cgraph_max_uid; | |
db30281f | 2439 | int cgraph_max_summary_id; |
3dafb85c ML |
2440 | |
2441 | int edges_count; | |
2442 | int edges_max_uid; | |
db30281f | 2443 | int edges_max_summary_id; |
3dafb85c | 2444 | |
fe248a88 ML |
2445 | /* Vector of released summary IDS for cgraph nodes. */ |
2446 | vec<int> GTY ((skip)) cgraph_released_summary_ids; | |
2447 | ||
2448 | /* Vector of released summary IDS for cgraph nodes. */ | |
2449 | vec<int> GTY ((skip)) edge_released_summary_ids; | |
2450 | ||
019f36a6 JH |
2451 | /* Return symbol used to separate symbol name from suffix. */ |
2452 | static char symbol_suffix_separator (); | |
2453 | ||
3dafb85c ML |
2454 | symtab_node* GTY(()) nodes; |
2455 | asm_node* GTY(()) asmnodes; | |
2456 | asm_node* GTY(()) asm_last_node; | |
3dafb85c ML |
2457 | |
2458 | /* The order index of the next symtab node to be created. This is | |
2459 | used so that we can sort the cgraph nodes in order by when we saw | |
2460 | them, to support -fno-toplevel-reorder. */ | |
2461 | int order; | |
2462 | ||
b74d8dc4 JH |
2463 | /* Maximal unit ID used. */ |
2464 | int max_unit; | |
2465 | ||
3dafb85c ML |
2466 | /* Set when whole unit has been analyzed so we can access global info. */ |
2467 | bool global_info_ready; | |
2468 | /* What state callgraph is in right now. */ | |
2469 | enum symtab_state state; | |
2470 | /* Set when the cgraph is fully build and the basic flags are computed. */ | |
2471 | bool function_flags_ready; | |
2472 | ||
2473 | bool cpp_implicit_aliases_done; | |
2474 | ||
dfea3d6f | 2475 | /* Hash table used to hold sections. */ |
2a22f99c | 2476 | hash_table<section_name_hasher> *GTY(()) section_hash; |
3dafb85c ML |
2477 | |
2478 | /* Hash table used to convert assembler names into nodes. */ | |
2a22f99c | 2479 | hash_table<asmname_hasher> *assembler_name_hash; |
3dafb85c ML |
2480 | |
2481 | /* Hash table used to hold init priorities. */ | |
b086d530 | 2482 | hash_map<symtab_node *, symbol_priority_map> *init_priority_hash; |
3dafb85c ML |
2483 | |
2484 | FILE* GTY ((skip)) dump_file; | |
2485 | ||
0bdad123 ML |
2486 | FILE* GTY ((skip)) ipa_clones_dump_file; |
2487 | ||
2488 | hash_set <const cgraph_node *> GTY ((skip)) cloned_nodes; | |
2489 | ||
67f3791f JH |
2490 | /* Thunk annotations. */ |
2491 | thunk_summary *m_thunks; | |
2492 | ||
ae7a23a3 JH |
2493 | /* Virtual clone annotations. */ |
2494 | clone_summary *m_clones; | |
2495 | ||
3dafb85c | 2496 | private: |
3dafb85c | 2497 | /* Allocate a cgraph_edge structure and fill it with data according to the |
3187c8a5 MJ |
2498 | parameters of which only CALLEE can be NULL (when creating an indirect |
2499 | call edge). CLONING_P should be set if properties that are copied from an | |
2500 | original edge should not be calculated. */ | |
3dafb85c | 2501 | cgraph_edge *create_edge (cgraph_node *caller, cgraph_node *callee, |
1bad9c18 | 2502 | gcall *call_stmt, profile_count count, |
3187c8a5 | 2503 | bool indir_unknown_callee, bool cloning_p); |
3dafb85c ML |
2504 | |
2505 | /* Put the edge onto the free list. */ | |
2506 | void free_edge (cgraph_edge *e); | |
2507 | ||
2508 | /* Insert NODE to assembler name hash. */ | |
2509 | void insert_to_assembler_name_hash (symtab_node *node, bool with_clones); | |
2510 | ||
2511 | /* Remove NODE from assembler name hash. */ | |
2512 | void unlink_from_assembler_name_hash (symtab_node *node, bool with_clones); | |
2513 | ||
2514 | /* Hash asmnames ignoring the user specified marks. */ | |
2515 | static hashval_t decl_assembler_name_hash (const_tree asmname); | |
2516 | ||
2517 | /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */ | |
2518 | static bool decl_assembler_name_equal (tree decl, const_tree asmname); | |
2519 | ||
2a22f99c | 2520 | friend struct asmname_hasher; |
3dafb85c ML |
2521 | |
2522 | /* List of hooks triggered when an edge is removed. */ | |
2523 | cgraph_edge_hook_list * GTY((skip)) m_first_edge_removal_hook; | |
dfea3d6f | 2524 | /* List of hooks trigger_red when a cgraph node is removed. */ |
3dafb85c ML |
2525 | cgraph_node_hook_list * GTY((skip)) m_first_cgraph_removal_hook; |
2526 | /* List of hooks triggered when an edge is duplicated. */ | |
2527 | cgraph_2edge_hook_list * GTY((skip)) m_first_edge_duplicated_hook; | |
2528 | /* List of hooks triggered when a node is duplicated. */ | |
2529 | cgraph_2node_hook_list * GTY((skip)) m_first_cgraph_duplicated_hook; | |
2530 | /* List of hooks triggered when an function is inserted. */ | |
2531 | cgraph_node_hook_list * GTY((skip)) m_first_cgraph_insertion_hook; | |
2532 | /* List of hooks triggered when an variable is inserted. */ | |
2533 | varpool_node_hook_list * GTY((skip)) m_first_varpool_insertion_hook; | |
2534 | /* List of hooks triggered when a node is removed. */ | |
2535 | varpool_node_hook_list * GTY((skip)) m_first_varpool_removal_hook; | |
2536 | }; | |
2537 | ||
2538 | extern GTY(()) symbol_table *symtab; | |
2539 | ||
2540 | extern vec<cgraph_node *> cgraph_new_nodes; | |
2aae7680 | 2541 | |
2a22f99c TS |
2542 | inline hashval_t |
2543 | asmname_hasher::hash (symtab_node *n) | |
2544 | { | |
2545 | return symbol_table::decl_assembler_name_hash | |
2546 | (DECL_ASSEMBLER_NAME (n->decl)); | |
2547 | } | |
2548 | ||
2549 | inline bool | |
2550 | asmname_hasher::equal (symtab_node *n, const_tree t) | |
2551 | { | |
2552 | return symbol_table::decl_assembler_name_equal (n->decl, t); | |
2553 | } | |
2554 | ||
1c4a429a | 2555 | /* In cgraph.c */ |
3edf64aa | 2556 | void cgraph_c_finalize (void); |
12123452 | 2557 | void release_function_body (tree); |
3dafb85c | 2558 | cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void); |
d52f5295 | 2559 | |
355fe088 | 2560 | void cgraph_update_edges_for_call_stmt (gimple *, tree, gimple *); |
1bb17c21 JH |
2561 | bool cgraph_function_possibly_inlined_p (tree); |
2562 | ||
61a05df1 | 2563 | const char* cgraph_inline_failed_string (cgraph_inline_failed_t); |
1cf11770 | 2564 | cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t); |
6b02a499 | 2565 | |
9c8305f8 | 2566 | /* In cgraphunit.c */ |
3edf64aa | 2567 | void cgraphunit_c_finalize (void); |
6d8fd122 | 2568 | int tp_first_run_node_cmp (const void *pa, const void *pb); |
3edf64aa | 2569 | |
67f3791f JH |
2570 | /* In symtab-thunks.cc */ |
2571 | void symtab_thunks_cc_finalize (void); | |
2572 | ||
3649b9b7 ST |
2573 | /* Initialize datastructures so DECL is a function in lowered gimple form. |
2574 | IN_SSA is true if the gimple is in SSA. */ | |
3995f3a2 | 2575 | basic_block init_lowered_empty_function (tree, bool, profile_count); |
66a20fc2 | 2576 | |
44662f68 EB |
2577 | tree thunk_adjust (gimple_stmt_iterator *, tree, bool, HOST_WIDE_INT, tree, |
2578 | HOST_WIDE_INT); | |
66a20fc2 JH |
2579 | /* In cgraphclones.c */ |
2580 | ||
7958186b MP |
2581 | tree clone_function_name_numbered (const char *name, const char *suffix); |
2582 | tree clone_function_name_numbered (tree decl, const char *suffix); | |
2583 | tree clone_function_name (const char *name, const char *suffix, | |
2584 | unsigned long number); | |
53aedcce MP |
2585 | tree clone_function_name (tree decl, const char *suffix, |
2586 | unsigned long number); | |
7958186b | 2587 | tree clone_function_name (tree decl, const char *suffix); |
d52f5295 | 2588 | |
d52f5295 | 2589 | void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *, |
ff6686d2 MJ |
2590 | ipa_param_adjustments *, |
2591 | bool, bitmap, basic_block); | |
9c8305f8 | 2592 | |
0bdad123 ML |
2593 | void dump_callgraph_transformation (const cgraph_node *original, |
2594 | const cgraph_node *clone, | |
2595 | const char *suffix); | |
917948d3 | 2596 | /* In cgraphbuild.c */ |
9187e02d | 2597 | int compute_call_stmt_bb_frequency (tree, basic_block bb); |
9c8305f8 | 2598 | void record_references_in_initializer (tree, bool); |
917948d3 | 2599 | |
ca31b95f | 2600 | /* In ipa.c */ |
9c8305f8 | 2601 | void cgraph_build_static_cdtor (char which, tree body, int priority); |
2e14744f | 2602 | bool ipa_discover_variable_flags (void); |
ca31b95f | 2603 | |
8a4a83ed | 2604 | /* In varpool.c */ |
6a6dac52 | 2605 | tree ctor_for_folding (tree); |
68e56cc4 | 2606 | |
27d020cf JH |
2607 | /* In ipa-inline-analysis.c */ |
2608 | void initialize_inline_failed (struct cgraph_edge *); | |
2609 | bool speculation_useful_p (struct cgraph_edge *e, bool anticipate_inlining); | |
2610 | ||
d52f5295 ML |
2611 | /* Return true when the symbol is real symbol, i.e. it is not inline clone |
2612 | or abstract function kept for debug info purposes only. */ | |
2613 | inline bool | |
2614 | symtab_node::real_symbol_p (void) | |
2615 | { | |
2616 | cgraph_node *cnode; | |
2617 | ||
00de328a | 2618 | if (DECL_ABSTRACT_P (decl)) |
d52f5295 | 2619 | return false; |
71e54687 JH |
2620 | if (transparent_alias && definition) |
2621 | return false; | |
d52f5295 ML |
2622 | if (!is_a <cgraph_node *> (this)) |
2623 | return true; | |
2624 | cnode = dyn_cast <cgraph_node *> (this); | |
a62bfab5 | 2625 | if (cnode->inlined_to) |
d52f5295 ML |
2626 | return false; |
2627 | return true; | |
2628 | } | |
2629 | ||
89330618 | 2630 | /* Return true if DECL should have entry in symbol table if used. |
dfea3d6f | 2631 | Those are functions and static & external variables. */ |
89330618 | 2632 | |
0241e486 | 2633 | static inline bool |
89330618 JH |
2634 | decl_in_symtab_p (const_tree decl) |
2635 | { | |
2636 | return (TREE_CODE (decl) == FUNCTION_DECL | |
2637 | || (TREE_CODE (decl) == VAR_DECL | |
2638 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))); | |
2639 | } | |
2640 | ||
d52f5295 ML |
2641 | inline bool |
2642 | symtab_node::in_same_comdat_group_p (symtab_node *target) | |
aede2c10 | 2643 | { |
d52f5295 | 2644 | symtab_node *source = this; |
aede2c10 | 2645 | |
d52f5295 ML |
2646 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (target)) |
2647 | { | |
a62bfab5 ML |
2648 | if (cn->inlined_to) |
2649 | source = cn->inlined_to; | |
d52f5295 ML |
2650 | } |
2651 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (target)) | |
2652 | { | |
a62bfab5 ML |
2653 | if (cn->inlined_to) |
2654 | target = cn->inlined_to; | |
d52f5295 ML |
2655 | } |
2656 | ||
2657 | return source->get_comdat_group () == target->get_comdat_group (); | |
1f00098b JH |
2658 | } |
2659 | ||
d52f5295 ML |
2660 | /* Return node that alias is aliasing. */ |
2661 | ||
2662 | inline symtab_node * | |
2663 | symtab_node::get_alias_target (void) | |
1f00098b | 2664 | { |
3dafb85c | 2665 | ipa_ref *ref = NULL; |
d52f5295 ML |
2666 | iterate_reference (0, ref); |
2667 | gcc_checking_assert (ref->use == IPA_REF_ALIAS); | |
2668 | return ref->referred; | |
1f00098b JH |
2669 | } |
2670 | ||
f8e7f3f3 JM |
2671 | /* Return the DECL (or identifier) that alias is aliasing. Unlike the above, |
2672 | this works whether or not the alias has been analyzed already. */ | |
2673 | ||
2674 | inline tree | |
2675 | symtab_node::get_alias_target_tree () | |
2676 | { | |
2677 | if (alias_target) | |
2678 | return alias_target; | |
2679 | return get_alias_target ()->decl; | |
2680 | } | |
2681 | ||
d52f5295 | 2682 | /* Return next reachable static symbol with initializer after the node. */ |
31de7606 | 2683 | |
d52f5295 ML |
2684 | inline symtab_node * |
2685 | symtab_node::next_defined_symbol (void) | |
1ab24192 | 2686 | { |
d52f5295 ML |
2687 | symtab_node *node1 = next; |
2688 | ||
2689 | for (; node1; node1 = node1->next) | |
2690 | if (node1->definition) | |
2691 | return node1; | |
2692 | ||
2693 | return NULL; | |
1ab24192 JH |
2694 | } |
2695 | ||
31de7606 JH |
2696 | /* Iterates I-th reference in the list, REF is also set. */ |
2697 | ||
2698 | inline ipa_ref * | |
2699 | symtab_node::iterate_reference (unsigned i, ipa_ref *&ref) | |
2700 | { | |
7144270e | 2701 | ref_list.references.iterate (i, &ref); |
31de7606 JH |
2702 | |
2703 | return ref; | |
2704 | } | |
2705 | ||
2706 | /* Iterates I-th referring item in the list, REF is also set. */ | |
2707 | ||
2708 | inline ipa_ref * | |
2709 | symtab_node::iterate_referring (unsigned i, ipa_ref *&ref) | |
2710 | { | |
2711 | ref_list.referring.iterate (i, &ref); | |
2712 | ||
2713 | return ref; | |
2714 | } | |
2715 | ||
2716 | /* Iterates I-th referring alias item in the list, REF is also set. */ | |
2717 | ||
2718 | inline ipa_ref * | |
2719 | symtab_node::iterate_direct_aliases (unsigned i, ipa_ref *&ref) | |
2720 | { | |
2721 | ref_list.referring.iterate (i, &ref); | |
2722 | ||
2723 | if (ref && ref->use != IPA_REF_ALIAS) | |
2724 | return NULL; | |
2725 | ||
2726 | return ref; | |
2727 | } | |
2728 | ||
2729 | /* Return true if list contains an alias. */ | |
2730 | ||
2731 | inline bool | |
2732 | symtab_node::has_aliases_p (void) | |
2733 | { | |
2734 | ipa_ref *ref = NULL; | |
31de7606 | 2735 | |
190bbd0b | 2736 | return (iterate_direct_aliases (0, ref) != NULL); |
31de7606 JH |
2737 | } |
2738 | ||
2739 | /* Return true when RESOLUTION indicate that linker will use | |
2740 | the symbol from non-LTO object files. */ | |
2741 | ||
2742 | inline bool | |
2743 | resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution) | |
2744 | { | |
2745 | return (resolution == LDPR_PREVAILING_DEF | |
2746 | || resolution == LDPR_PREEMPTED_REG | |
2747 | || resolution == LDPR_RESOLVED_EXEC | |
2748 | || resolution == LDPR_RESOLVED_DYN); | |
2749 | } | |
2750 | ||
2751 | /* Return true when symtab_node is known to be used from other (non-LTO) | |
2752 | object file. Known only when doing LTO via linker plugin. */ | |
2753 | ||
2754 | inline bool | |
2755 | symtab_node::used_from_object_file_p (void) | |
2756 | { | |
2757 | if (!TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)) | |
2758 | return false; | |
2759 | if (resolution_used_from_other_file_p (resolution)) | |
2760 | return true; | |
2761 | return false; | |
2762 | } | |
2763 | ||
1ab24192 | 2764 | /* Return varpool node for given symbol and check it is a function. */ |
3dafb85c | 2765 | |
9041d2e6 ML |
2766 | inline varpool_node * |
2767 | varpool_node::get (const_tree decl) | |
1ab24192 JH |
2768 | { |
2769 | gcc_checking_assert (TREE_CODE (decl) == VAR_DECL); | |
d52f5295 | 2770 | return dyn_cast<varpool_node *> (symtab_node::get (decl)); |
1ab24192 JH |
2771 | } |
2772 | ||
3dafb85c ML |
2773 | /* Register a symbol NODE. */ |
2774 | ||
2775 | inline void | |
2776 | symbol_table::register_symbol (symtab_node *node) | |
2777 | { | |
2778 | node->next = nodes; | |
2779 | node->previous = NULL; | |
2780 | ||
2781 | if (nodes) | |
2782 | nodes->previous = node; | |
2783 | nodes = node; | |
2784 | ||
2785 | node->order = order++; | |
2786 | } | |
2787 | ||
2788 | /* Register a top-level asm statement ASM_STR. */ | |
2789 | ||
2790 | asm_node * | |
2791 | symbol_table::finalize_toplevel_asm (tree asm_str) | |
2792 | { | |
2793 | asm_node *node; | |
2794 | ||
2795 | node = ggc_cleared_alloc<asm_node> (); | |
2796 | node->asm_str = asm_str; | |
2797 | node->order = order++; | |
2798 | node->next = NULL; | |
2799 | ||
2800 | if (asmnodes == NULL) | |
2801 | asmnodes = node; | |
2802 | else | |
2803 | asm_last_node->next = node; | |
2804 | ||
2805 | asm_last_node = node; | |
2806 | return node; | |
2807 | } | |
2808 | ||
2809 | /* Unregister a symbol NODE. */ | |
2810 | inline void | |
2811 | symbol_table::unregister (symtab_node *node) | |
2812 | { | |
2813 | if (node->previous) | |
2814 | node->previous->next = node->next; | |
2815 | else | |
2816 | nodes = node->next; | |
2817 | ||
2818 | if (node->next) | |
2819 | node->next->previous = node->previous; | |
2820 | ||
2821 | node->next = NULL; | |
2822 | node->previous = NULL; | |
2823 | } | |
2824 | ||
3dafb85c ML |
2825 | /* Release a callgraph NODE with UID and put in to the list of free nodes. */ |
2826 | ||
2827 | inline void | |
74644756 | 2828 | symbol_table::release_symbol (cgraph_node *node) |
3dafb85c ML |
2829 | { |
2830 | cgraph_count--; | |
fe248a88 ML |
2831 | if (node->m_summary_id != -1) |
2832 | cgraph_released_summary_ids.safe_push (node->m_summary_id); | |
2833 | ggc_free (node); | |
3dafb85c ML |
2834 | } |
2835 | ||
3dafb85c ML |
2836 | /* Return first static symbol with definition. */ |
2837 | inline symtab_node * | |
2838 | symbol_table::first_symbol (void) | |
2839 | { | |
2840 | return nodes; | |
2841 | } | |
2842 | ||
1ab24192 JH |
2843 | /* Walk all symbols. */ |
2844 | #define FOR_EACH_SYMBOL(node) \ | |
3dafb85c | 2845 | for ((node) = symtab->first_symbol (); (node); (node) = (node)->next) |
1f00098b | 2846 | |
d6d229c6 | 2847 | /* Return first static symbol with definition. */ |
3dafb85c ML |
2848 | inline symtab_node * |
2849 | symbol_table::first_defined_symbol (void) | |
d6d229c6 JH |
2850 | { |
2851 | symtab_node *node; | |
2852 | ||
3dafb85c | 2853 | for (node = nodes; node; node = node->next) |
d6d229c6 JH |
2854 | if (node->definition) |
2855 | return node; | |
2856 | ||
2857 | return NULL; | |
2858 | } | |
2859 | ||
d6d229c6 JH |
2860 | /* Walk all symbols with definitions in current unit. */ |
2861 | #define FOR_EACH_DEFINED_SYMBOL(node) \ | |
3dafb85c | 2862 | for ((node) = symtab->first_defined_symbol (); (node); \ |
d52f5295 | 2863 | (node) = node->next_defined_symbol ()) |
66058468 JH |
2864 | |
2865 | /* Return first variable. */ | |
3dafb85c ML |
2866 | inline varpool_node * |
2867 | symbol_table::first_variable (void) | |
66058468 | 2868 | { |
5e20cdc9 | 2869 | symtab_node *node; |
3dafb85c | 2870 | for (node = nodes; node; node = node->next) |
7de90a6c | 2871 | if (varpool_node *vnode = dyn_cast <varpool_node *> (node)) |
5d59b5e1 | 2872 | return vnode; |
66058468 JH |
2873 | return NULL; |
2874 | } | |
2875 | ||
2876 | /* Return next variable after NODE. */ | |
3dafb85c ML |
2877 | inline varpool_node * |
2878 | symbol_table::next_variable (varpool_node *node) | |
66058468 | 2879 | { |
5e20cdc9 | 2880 | symtab_node *node1 = node->next; |
67348ccc | 2881 | for (; node1; node1 = node1->next) |
7de90a6c | 2882 | if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1)) |
5d59b5e1 | 2883 | return vnode1; |
66058468 JH |
2884 | return NULL; |
2885 | } | |
2886 | /* Walk all variables. */ | |
2887 | #define FOR_EACH_VARIABLE(node) \ | |
3dafb85c | 2888 | for ((node) = symtab->first_variable (); \ |
66058468 | 2889 | (node); \ |
3dafb85c | 2890 | (node) = symtab->next_variable ((node))) |
66058468 | 2891 | |
d6d229c6 | 2892 | /* Return first static variable with initializer. */ |
3dafb85c ML |
2893 | inline varpool_node * |
2894 | symbol_table::first_static_initializer (void) | |
68e56cc4 | 2895 | { |
5e20cdc9 | 2896 | symtab_node *node; |
3dafb85c | 2897 | for (node = nodes; node; node = node->next) |
68e56cc4 | 2898 | { |
7de90a6c | 2899 | varpool_node *vnode = dyn_cast <varpool_node *> (node); |
67348ccc | 2900 | if (vnode && DECL_INITIAL (node->decl)) |
5d59b5e1 | 2901 | return vnode; |
68e56cc4 JH |
2902 | } |
2903 | return NULL; | |
2904 | } | |
2905 | ||
d6d229c6 | 2906 | /* Return next static variable with initializer after NODE. */ |
3dafb85c ML |
2907 | inline varpool_node * |
2908 | symbol_table::next_static_initializer (varpool_node *node) | |
68e56cc4 | 2909 | { |
5e20cdc9 | 2910 | symtab_node *node1 = node->next; |
67348ccc | 2911 | for (; node1; node1 = node1->next) |
68e56cc4 | 2912 | { |
7de90a6c | 2913 | varpool_node *vnode1 = dyn_cast <varpool_node *> (node1); |
67348ccc | 2914 | if (vnode1 && DECL_INITIAL (node1->decl)) |
5d59b5e1 | 2915 | return vnode1; |
68e56cc4 JH |
2916 | } |
2917 | return NULL; | |
2918 | } | |
2919 | ||
2920 | /* Walk all static variables with initializer set. */ | |
2921 | #define FOR_EACH_STATIC_INITIALIZER(node) \ | |
3dafb85c ML |
2922 | for ((node) = symtab->first_static_initializer (); (node); \ |
2923 | (node) = symtab->next_static_initializer (node)) | |
2aae7680 | 2924 | |
d6d229c6 | 2925 | /* Return first static variable with definition. */ |
3dafb85c ML |
2926 | inline varpool_node * |
2927 | symbol_table::first_defined_variable (void) | |
2aae7680 | 2928 | { |
5e20cdc9 | 2929 | symtab_node *node; |
3dafb85c | 2930 | for (node = nodes; node; node = node->next) |
2aae7680 | 2931 | { |
7de90a6c | 2932 | varpool_node *vnode = dyn_cast <varpool_node *> (node); |
67348ccc | 2933 | if (vnode && vnode->definition) |
5d59b5e1 | 2934 | return vnode; |
2aae7680 JH |
2935 | } |
2936 | return NULL; | |
2937 | } | |
2938 | ||
d6d229c6 | 2939 | /* Return next static variable with definition after NODE. */ |
3dafb85c ML |
2940 | inline varpool_node * |
2941 | symbol_table::next_defined_variable (varpool_node *node) | |
2aae7680 | 2942 | { |
5e20cdc9 | 2943 | symtab_node *node1 = node->next; |
67348ccc | 2944 | for (; node1; node1 = node1->next) |
2aae7680 | 2945 | { |
7de90a6c | 2946 | varpool_node *vnode1 = dyn_cast <varpool_node *> (node1); |
67348ccc | 2947 | if (vnode1 && vnode1->definition) |
5d59b5e1 | 2948 | return vnode1; |
2aae7680 JH |
2949 | } |
2950 | return NULL; | |
2951 | } | |
65c70e6b JH |
2952 | /* Walk all variables with definitions in current unit. */ |
2953 | #define FOR_EACH_DEFINED_VARIABLE(node) \ | |
3dafb85c ML |
2954 | for ((node) = symtab->first_defined_variable (); (node); \ |
2955 | (node) = symtab->next_defined_variable (node)) | |
68e56cc4 | 2956 | |
c47d0034 | 2957 | /* Return first function with body defined. */ |
3dafb85c ML |
2958 | inline cgraph_node * |
2959 | symbol_table::first_defined_function (void) | |
c47d0034 | 2960 | { |
5e20cdc9 | 2961 | symtab_node *node; |
3dafb85c | 2962 | for (node = nodes; node; node = node->next) |
c47d0034 | 2963 | { |
7de90a6c | 2964 | cgraph_node *cn = dyn_cast <cgraph_node *> (node); |
67348ccc | 2965 | if (cn && cn->definition) |
5d59b5e1 | 2966 | return cn; |
c47d0034 JH |
2967 | } |
2968 | return NULL; | |
2969 | } | |
2970 | ||
45896127 | 2971 | /* Return next function with body defined after NODE. */ |
3dafb85c ML |
2972 | inline cgraph_node * |
2973 | symbol_table::next_defined_function (cgraph_node *node) | |
c47d0034 | 2974 | { |
5e20cdc9 | 2975 | symtab_node *node1 = node->next; |
67348ccc | 2976 | for (; node1; node1 = node1->next) |
c47d0034 | 2977 | { |
7de90a6c | 2978 | cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1); |
67348ccc | 2979 | if (cn1 && cn1->definition) |
5d59b5e1 | 2980 | return cn1; |
c47d0034 JH |
2981 | } |
2982 | return NULL; | |
2983 | } | |
2984 | ||
2985 | /* Walk all functions with body defined. */ | |
2986 | #define FOR_EACH_DEFINED_FUNCTION(node) \ | |
3dafb85c ML |
2987 | for ((node) = symtab->first_defined_function (); (node); \ |
2988 | (node) = symtab->next_defined_function ((node))) | |
2aae7680 JH |
2989 | |
2990 | /* Return first function. */ | |
3dafb85c ML |
2991 | inline cgraph_node * |
2992 | symbol_table::first_function (void) | |
2aae7680 | 2993 | { |
5e20cdc9 | 2994 | symtab_node *node; |
3dafb85c | 2995 | for (node = nodes; node; node = node->next) |
7de90a6c | 2996 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (node)) |
5d59b5e1 | 2997 | return cn; |
2aae7680 JH |
2998 | return NULL; |
2999 | } | |
3000 | ||
3001 | /* Return next function. */ | |
3dafb85c ML |
3002 | inline cgraph_node * |
3003 | symbol_table::next_function (cgraph_node *node) | |
2aae7680 | 3004 | { |
5e20cdc9 | 3005 | symtab_node *node1 = node->next; |
67348ccc | 3006 | for (; node1; node1 = node1->next) |
7de90a6c | 3007 | if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1)) |
5d59b5e1 | 3008 | return cn1; |
2aae7680 JH |
3009 | return NULL; |
3010 | } | |
c47d0034 JH |
3011 | |
3012 | /* Return first function with body defined. */ | |
3dafb85c ML |
3013 | inline cgraph_node * |
3014 | symbol_table::first_function_with_gimple_body (void) | |
c47d0034 | 3015 | { |
5e20cdc9 | 3016 | symtab_node *node; |
3dafb85c | 3017 | for (node = nodes; node; node = node->next) |
c47d0034 | 3018 | { |
7de90a6c | 3019 | cgraph_node *cn = dyn_cast <cgraph_node *> (node); |
d52f5295 | 3020 | if (cn && cn->has_gimple_body_p ()) |
5d59b5e1 | 3021 | return cn; |
c47d0034 JH |
3022 | } |
3023 | return NULL; | |
3024 | } | |
3025 | ||
3026 | /* Return next reachable static variable with initializer after NODE. */ | |
3dafb85c ML |
3027 | inline cgraph_node * |
3028 | symbol_table::next_function_with_gimple_body (cgraph_node *node) | |
c47d0034 | 3029 | { |
5e20cdc9 | 3030 | symtab_node *node1 = node->next; |
67348ccc | 3031 | for (; node1; node1 = node1->next) |
c47d0034 | 3032 | { |
7de90a6c | 3033 | cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1); |
d52f5295 | 3034 | if (cn1 && cn1->has_gimple_body_p ()) |
5d59b5e1 | 3035 | return cn1; |
c47d0034 JH |
3036 | } |
3037 | return NULL; | |
3038 | } | |
3039 | ||
3dafb85c ML |
3040 | /* Walk all functions. */ |
3041 | #define FOR_EACH_FUNCTION(node) \ | |
3042 | for ((node) = symtab->first_function (); (node); \ | |
3043 | (node) = symtab->next_function ((node))) | |
3044 | ||
3045 | /* Return true when callgraph node is a function with Gimple body defined | |
3046 | in current unit. Functions can also be define externally or they | |
3047 | can be thunks with no Gimple representation. | |
3048 | ||
3049 | Note that at WPA stage, the function body may not be present in memory. */ | |
3050 | ||
3051 | inline bool | |
3052 | cgraph_node::has_gimple_body_p (void) | |
3053 | { | |
67f3791f | 3054 | return definition && !thunk && !alias; |
1738b522 MJ |
3055 | } |
3056 | ||
c47d0034 JH |
3057 | /* Walk all functions with body defined. */ |
3058 | #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \ | |
3dafb85c ML |
3059 | for ((node) = symtab->first_function_with_gimple_body (); (node); \ |
3060 | (node) = symtab->next_function_with_gimple_body (node)) | |
c47d0034 | 3061 | |
d48e9cea OR |
3062 | /* Uniquize all constants that appear in memory. |
3063 | Each constant in memory thus far output is recorded | |
3064 | in `const_desc_table'. */ | |
3065 | ||
2a22f99c | 3066 | struct GTY((for_user)) constant_descriptor_tree { |
d48e9cea OR |
3067 | /* A MEM for the constant. */ |
3068 | rtx rtl; | |
b8698a0f | 3069 | |
d48e9cea OR |
3070 | /* The value of the constant. */ |
3071 | tree value; | |
3072 | ||
3073 | /* Hash of value. Computing the hash from value each time | |
3074 | hashfn is called can't work properly, as that means recursive | |
3075 | use of the hash table during hash table expansion. */ | |
3076 | hashval_t hash; | |
3077 | }; | |
3078 | ||
d52f5295 | 3079 | /* Return true when function is only called directly or it has alias. |
b20996ff JH |
3080 | i.e. it is not externally visible, address was not taken and |
3081 | it is not used in any other non-standard way. */ | |
3082 | ||
d52f5295 ML |
3083 | inline bool |
3084 | cgraph_node::only_called_directly_or_aliased_p (void) | |
3085 | { | |
a62bfab5 | 3086 | gcc_assert (!inlined_to); |
d52f5295 | 3087 | return (!force_output && !address_taken |
aab778d3 | 3088 | && !ifunc_resolver |
d52f5295 ML |
3089 | && !used_from_other_partition |
3090 | && !DECL_VIRTUAL_P (decl) | |
3091 | && !DECL_STATIC_CONSTRUCTOR (decl) | |
3092 | && !DECL_STATIC_DESTRUCTOR (decl) | |
a6a543bf | 3093 | && !used_from_object_file_p () |
d52f5295 | 3094 | && !externally_visible); |
b20996ff JH |
3095 | } |
3096 | ||
31de7606 JH |
3097 | /* Return true when function can be removed from callgraph |
3098 | if all direct calls are eliminated. */ | |
3099 | ||
3100 | inline bool | |
3101 | cgraph_node::can_remove_if_no_direct_calls_and_refs_p (void) | |
3102 | { | |
a62bfab5 | 3103 | gcc_checking_assert (!inlined_to); |
31de7606 JH |
3104 | /* Extern inlines can always go, we will use the external definition. */ |
3105 | if (DECL_EXTERNAL (decl)) | |
3106 | return true; | |
67914693 | 3107 | /* When function is needed, we cannot remove it. */ |
31de7606 JH |
3108 | if (force_output || used_from_other_partition) |
3109 | return false; | |
3110 | if (DECL_STATIC_CONSTRUCTOR (decl) | |
3111 | || DECL_STATIC_DESTRUCTOR (decl)) | |
3112 | return false; | |
3113 | /* Only COMDAT functions can be removed if externally visible. */ | |
3114 | if (externally_visible | |
b9dbb436 | 3115 | && ((!DECL_COMDAT (decl) || ifunc_resolver) |
31de7606 JH |
3116 | || forced_by_abi |
3117 | || used_from_object_file_p ())) | |
3118 | return false; | |
3119 | return true; | |
3120 | } | |
3121 | ||
b2b29377 MM |
3122 | /* Verify cgraph, if consistency checking is enabled. */ |
3123 | ||
3124 | inline void | |
3125 | cgraph_node::checking_verify_cgraph_nodes (void) | |
3126 | { | |
3127 | if (flag_checking) | |
3128 | cgraph_node::verify_cgraph_nodes (); | |
3129 | } | |
3130 | ||
9041d2e6 | 3131 | /* Return true when variable can be removed from variable pool |
df7705b1 JH |
3132 | if all direct calls are eliminated. */ |
3133 | ||
9041d2e6 ML |
3134 | inline bool |
3135 | varpool_node::can_remove_if_no_refs_p (void) | |
df7705b1 | 3136 | { |
9041d2e6 | 3137 | if (DECL_EXTERNAL (decl)) |
6649df51 | 3138 | return true; |
9041d2e6 ML |
3139 | return (!force_output && !used_from_other_partition |
3140 | && ((DECL_COMDAT (decl) | |
3141 | && !forced_by_abi | |
3142 | && !used_from_object_file_p ()) | |
3143 | || !externally_visible | |
3144 | || DECL_HAS_VALUE_EXPR_P (decl))); | |
df7705b1 JH |
3145 | } |
3146 | ||
9041d2e6 | 3147 | /* Return true when all references to variable must be visible in ipa_ref_list. |
4a444e58 JH |
3148 | i.e. if the variable is not externally visible or not used in some magic |
3149 | way (asm statement or such). | |
61502ca8 | 3150 | The magic uses are all summarized in force_output flag. */ |
4a444e58 | 3151 | |
9041d2e6 ML |
3152 | inline bool |
3153 | varpool_node::all_refs_explicit_p () | |
4a444e58 | 3154 | { |
9041d2e6 ML |
3155 | return (definition |
3156 | && !externally_visible | |
3157 | && !used_from_other_partition | |
3158 | && !force_output); | |
4a444e58 JH |
3159 | } |
3160 | ||
ca752f39 | 3161 | struct tree_descriptor_hasher : ggc_ptr_hash<constant_descriptor_tree> |
2a22f99c TS |
3162 | { |
3163 | static hashval_t hash (constant_descriptor_tree *); | |
3164 | static bool equal (constant_descriptor_tree *, constant_descriptor_tree *); | |
3165 | }; | |
3166 | ||
d48e9cea | 3167 | /* Constant pool accessor function. */ |
2a22f99c | 3168 | hash_table<tree_descriptor_hasher> *constant_pool_htab (void); |
fed5ae11 | 3169 | |
d52f5295 | 3170 | /* Return node that alias is aliasing. */ |
39e2db00 | 3171 | |
d52f5295 ML |
3172 | inline cgraph_node * |
3173 | cgraph_node::get_alias_target (void) | |
cd35bcf7 | 3174 | { |
d52f5295 | 3175 | return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ()); |
cd35bcf7 JH |
3176 | } |
3177 | ||
9041d2e6 ML |
3178 | /* Return node that alias is aliasing. */ |
3179 | ||
3180 | inline varpool_node * | |
3181 | varpool_node::get_alias_target (void) | |
be330ed4 | 3182 | { |
9041d2e6 | 3183 | return dyn_cast <varpool_node *> (symtab_node::get_alias_target ()); |
be330ed4 JH |
3184 | } |
3185 | ||
31de7606 JH |
3186 | /* Walk the alias chain to return the symbol NODE is alias of. |
3187 | If NODE is not an alias, return NODE. | |
f13fe18b JH |
3188 | When AVAILABILITY is non-NULL, get minimal availability in the chain. |
3189 | When REF is non-NULL, assume that reference happens in symbol REF | |
3190 | when determining the availability. */ | |
31de7606 JH |
3191 | |
3192 | inline symtab_node * | |
f13fe18b JH |
3193 | symtab_node::ultimate_alias_target (enum availability *availability, |
3194 | symtab_node *ref) | |
31de7606 JH |
3195 | { |
3196 | if (!alias) | |
3197 | { | |
3198 | if (availability) | |
f13fe18b | 3199 | *availability = get_availability (ref); |
31de7606 JH |
3200 | return this; |
3201 | } | |
3202 | ||
f13fe18b | 3203 | return ultimate_alias_target_1 (availability, ref); |
31de7606 JH |
3204 | } |
3205 | ||
d52f5295 ML |
3206 | /* Given function symbol, walk the alias chain to return the function node |
3207 | is alias of. Do not walk through thunks. | |
f13fe18b JH |
3208 | When AVAILABILITY is non-NULL, get minimal availability in the chain. |
3209 | When REF is non-NULL, assume that reference happens in symbol REF | |
3210 | when determining the availability. */ | |
be330ed4 | 3211 | |
d52f5295 | 3212 | inline cgraph_node * |
f13fe18b JH |
3213 | cgraph_node::ultimate_alias_target (enum availability *availability, |
3214 | symtab_node *ref) | |
be330ed4 | 3215 | { |
31de7606 | 3216 | cgraph_node *n = dyn_cast <cgraph_node *> |
f13fe18b | 3217 | (symtab_node::ultimate_alias_target (availability, ref)); |
40a7fe1e | 3218 | if (!n && availability) |
39e2db00 | 3219 | *availability = AVAIL_NOT_AVAILABLE; |
e70670cf | 3220 | return n; |
be330ed4 | 3221 | } |
9041d2e6 ML |
3222 | |
3223 | /* For given variable pool node, walk the alias chain to return the function | |
3224 | the variable is alias of. Do not walk through thunks. | |
f13fe18b JH |
3225 | When AVAILABILITY is non-NULL, get minimal availability in the chain. |
3226 | When REF is non-NULL, assume that reference happens in symbol REF | |
3227 | when determining the availability. */ | |
cd35bcf7 | 3228 | |
9041d2e6 | 3229 | inline varpool_node * |
f13fe18b JH |
3230 | varpool_node::ultimate_alias_target (availability *availability, |
3231 | symtab_node *ref) | |
cd35bcf7 | 3232 | { |
9041d2e6 | 3233 | varpool_node *n = dyn_cast <varpool_node *> |
f13fe18b | 3234 | (symtab_node::ultimate_alias_target (availability, ref)); |
ff36fcbe | 3235 | |
40a7fe1e | 3236 | if (!n && availability) |
cd35bcf7 | 3237 | *availability = AVAIL_NOT_AVAILABLE; |
e70670cf | 3238 | return n; |
cd35bcf7 JH |
3239 | } |
3240 | ||
90988f77 ML |
3241 | /* Set callee N of call graph edge and add it to the corresponding set of |
3242 | callers. */ | |
3243 | ||
3244 | inline void | |
3245 | cgraph_edge::set_callee (cgraph_node *n) | |
3246 | { | |
3247 | prev_caller = NULL; | |
3248 | if (n->callers) | |
3249 | n->callers->prev_caller = this; | |
3250 | next_caller = n->callers; | |
3251 | n->callers = this; | |
3252 | callee = n; | |
3253 | } | |
3254 | ||
3dafb85c | 3255 | /* Return true when the edge represents a direct recursion. */ |
31de7606 | 3256 | |
3dafb85c ML |
3257 | inline bool |
3258 | cgraph_edge::recursive_p (void) | |
d7d1d041 | 3259 | { |
3dafb85c | 3260 | cgraph_node *c = callee->ultimate_alias_target (); |
a62bfab5 ML |
3261 | if (caller->inlined_to) |
3262 | return caller->inlined_to->decl == c->decl; | |
d7d1d041 | 3263 | else |
3dafb85c | 3264 | return caller->decl == c->decl; |
d7d1d041 | 3265 | } |
0a35513e | 3266 | |
90988f77 ML |
3267 | /* Remove the edge from the list of the callers of the callee. */ |
3268 | ||
3269 | inline void | |
3270 | cgraph_edge::remove_callee (void) | |
3271 | { | |
3272 | gcc_assert (!indirect_unknown_callee); | |
3273 | if (prev_caller) | |
3274 | prev_caller->next_caller = next_caller; | |
3275 | if (next_caller) | |
3276 | next_caller->prev_caller = prev_caller; | |
3277 | if (!prev_caller) | |
3278 | callee->callers = next_caller; | |
3279 | } | |
3280 | ||
f13fe18b JH |
3281 | /* Return true if call must bind to current definition. */ |
3282 | ||
3283 | inline bool | |
3284 | cgraph_edge::binds_to_current_def_p () | |
3285 | { | |
3286 | if (callee) | |
3287 | return callee->binds_to_current_def_p (caller); | |
3288 | else | |
aff98801 | 3289 | return false; |
f13fe18b JH |
3290 | } |
3291 | ||
1bad9c18 JH |
3292 | /* Expected frequency of executions within the function. |
3293 | When set to CGRAPH_FREQ_BASE, the edge is expected to be called once | |
3294 | per function call. The range is 0 to CGRAPH_FREQ_MAX. */ | |
3295 | ||
3296 | inline int | |
3297 | cgraph_edge::frequency () | |
3298 | { | |
a62bfab5 ML |
3299 | return count.to_cgraph_frequency (caller->inlined_to |
3300 | ? caller->inlined_to->count | |
1bad9c18 JH |
3301 | : caller->count); |
3302 | } | |
3303 | ||
41f0e819 | 3304 | |
0a35513e AH |
3305 | /* Return true if the TM_CLONE bit is set for a given FNDECL. */ |
3306 | static inline bool | |
3307 | decl_is_tm_clone (const_tree fndecl) | |
3308 | { | |
d52f5295 | 3309 | cgraph_node *n = cgraph_node::get (fndecl); |
0a35513e AH |
3310 | if (n) |
3311 | return n->tm_clone; | |
3312 | return false; | |
3313 | } | |
9c8305f8 JH |
3314 | |
3315 | /* Likewise indicate that a node is needed, i.e. reachable via some | |
3316 | external means. */ | |
3317 | ||
d52f5295 ML |
3318 | inline void |
3319 | cgraph_node::mark_force_output (void) | |
1f26ac87 | 3320 | { |
d52f5295 | 3321 | force_output = 1; |
a62bfab5 | 3322 | gcc_checking_assert (!inlined_to); |
1f26ac87 JM |
3323 | } |
3324 | ||
893479de AM |
3325 | /* Return true if function should be optimized for size. */ |
3326 | ||
f20a6c57 | 3327 | inline enum optimize_size_level |
893479de AM |
3328 | cgraph_node::optimize_for_size_p (void) |
3329 | { | |
b065b669 | 3330 | if (opt_for_fn (decl, optimize_size)) |
f20a6c57 JH |
3331 | return OPTIMIZE_SIZE_MAX; |
3332 | if (count == profile_count::zero ()) | |
3333 | return OPTIMIZE_SIZE_MAX; | |
893479de | 3334 | if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED) |
f20a6c57 | 3335 | return OPTIMIZE_SIZE_BALANCED; |
893479de | 3336 | else |
f20a6c57 | 3337 | return OPTIMIZE_SIZE_NO; |
893479de AM |
3338 | } |
3339 | ||
31de7606 JH |
3340 | /* Return symtab_node for NODE or create one if it is not present |
3341 | in symtab. */ | |
3342 | ||
3343 | inline symtab_node * | |
3344 | symtab_node::get_create (tree node) | |
f7217cde JH |
3345 | { |
3346 | if (TREE_CODE (node) == VAR_DECL) | |
3347 | return varpool_node::get_create (node); | |
3348 | else | |
3349 | return cgraph_node::get_create (node); | |
3350 | } | |
3351 | ||
f13fe18b | 3352 | /* Return availability of NODE when referenced from REF. */ |
31de7606 JH |
3353 | |
3354 | inline enum availability | |
f13fe18b | 3355 | symtab_node::get_availability (symtab_node *ref) |
31de7606 JH |
3356 | { |
3357 | if (is_a <cgraph_node *> (this)) | |
f13fe18b | 3358 | return dyn_cast <cgraph_node *> (this)->get_availability (ref); |
31de7606 | 3359 | else |
f13fe18b | 3360 | return dyn_cast <varpool_node *> (this)->get_availability (ref); |
31de7606 JH |
3361 | } |
3362 | ||
dfea3d6f | 3363 | /* Call callback on symtab node and aliases associated to this node. |
6b715bf6 | 3364 | When INCLUDE_OVERWRITABLE is false, overwritable symbols are skipped. */ |
31de7606 JH |
3365 | |
3366 | inline bool | |
3367 | symtab_node::call_for_symbol_and_aliases (bool (*callback) (symtab_node *, | |
3368 | void *), | |
3369 | void *data, | |
3370 | bool include_overwritable) | |
3371 | { | |
6b715bf6 JH |
3372 | if (include_overwritable |
3373 | || get_availability () > AVAIL_INTERPOSABLE) | |
3374 | { | |
3375 | if (callback (this, data)) | |
3376 | return true; | |
3377 | } | |
190bbd0b | 3378 | if (has_aliases_p ()) |
31de7606 JH |
3379 | return call_for_symbol_and_aliases_1 (callback, data, include_overwritable); |
3380 | return false; | |
3381 | } | |
3382 | ||
3383 | /* Call callback on function and aliases associated to the function. | |
6b715bf6 | 3384 | When INCLUDE_OVERWRITABLE is false, overwritable symbols are |
31de7606 JH |
3385 | skipped. */ |
3386 | ||
3387 | inline bool | |
3388 | cgraph_node::call_for_symbol_and_aliases (bool (*callback) (cgraph_node *, | |
3389 | void *), | |
3390 | void *data, | |
3391 | bool include_overwritable) | |
3392 | { | |
6b715bf6 JH |
3393 | if (include_overwritable |
3394 | || get_availability () > AVAIL_INTERPOSABLE) | |
3395 | { | |
3396 | if (callback (this, data)) | |
3397 | return true; | |
3398 | } | |
190bbd0b | 3399 | if (has_aliases_p ()) |
31de7606 | 3400 | return call_for_symbol_and_aliases_1 (callback, data, include_overwritable); |
31de7606 JH |
3401 | return false; |
3402 | } | |
3403 | ||
dfea3d6f | 3404 | /* Call callback on varpool symbol and aliases associated to varpool symbol. |
6b715bf6 | 3405 | When INCLUDE_OVERWRITABLE is false, overwritable symbols are |
31de7606 JH |
3406 | skipped. */ |
3407 | ||
3408 | inline bool | |
3409 | varpool_node::call_for_symbol_and_aliases (bool (*callback) (varpool_node *, | |
3410 | void *), | |
3411 | void *data, | |
3412 | bool include_overwritable) | |
3413 | { | |
6b715bf6 JH |
3414 | if (include_overwritable |
3415 | || get_availability () > AVAIL_INTERPOSABLE) | |
3416 | { | |
3417 | if (callback (this, data)) | |
3418 | return true; | |
3419 | } | |
190bbd0b | 3420 | if (has_aliases_p ()) |
31de7606 | 3421 | return call_for_symbol_and_aliases_1 (callback, data, include_overwritable); |
31de7606 JH |
3422 | return false; |
3423 | } | |
3424 | ||
dfea3d6f | 3425 | /* Return true if reference may be used in address compare. */ |
0a7246ee JH |
3426 | |
3427 | inline bool | |
3428 | ipa_ref::address_matters_p () | |
3429 | { | |
3430 | if (use != IPA_REF_ADDR) | |
3431 | return false; | |
3432 | /* Addresses taken from virtual tables are never compared. */ | |
3433 | if (is_a <varpool_node *> (referring) | |
3434 | && DECL_VIRTUAL_P (referring->decl)) | |
3435 | return false; | |
3436 | return referred->address_can_be_compared_p (); | |
3437 | } | |
3438 | ||
ba392339 JH |
3439 | /* Build polymorphic call context for indirect call E. */ |
3440 | ||
3441 | inline | |
3442 | ipa_polymorphic_call_context::ipa_polymorphic_call_context (cgraph_edge *e) | |
3443 | { | |
3444 | gcc_checking_assert (e->indirect_info->polymorphic); | |
3445 | *this = e->indirect_info->context; | |
3446 | } | |
3447 | ||
3448 | /* Build empty "I know nothing" context. */ | |
3449 | ||
3450 | inline | |
3451 | ipa_polymorphic_call_context::ipa_polymorphic_call_context () | |
3452 | { | |
3453 | clear_speculation (); | |
3454 | clear_outer_type (); | |
3455 | invalid = false; | |
3456 | } | |
3457 | ||
3458 | /* Make context non-speculative. */ | |
3459 | ||
3460 | inline void | |
3461 | ipa_polymorphic_call_context::clear_speculation () | |
3462 | { | |
3463 | speculative_outer_type = NULL; | |
3464 | speculative_offset = 0; | |
3465 | speculative_maybe_derived_type = false; | |
3466 | } | |
3467 | ||
dfea3d6f | 3468 | /* Produce context specifying all derived types of OTR_TYPE. If OTR_TYPE is |
6ff65dd7 | 3469 | NULL, the context is set to dummy "I know nothing" setting. */ |
ba392339 JH |
3470 | |
3471 | inline void | |
3472 | ipa_polymorphic_call_context::clear_outer_type (tree otr_type) | |
3473 | { | |
3474 | outer_type = otr_type ? TYPE_MAIN_VARIANT (otr_type) : NULL; | |
3475 | offset = 0; | |
3476 | maybe_derived_type = true; | |
3477 | maybe_in_construction = true; | |
4081ada2 | 3478 | dynamic = true; |
ba392339 | 3479 | } |
67a1b94c JH |
3480 | |
3481 | /* Adjust all offsets in contexts by OFF bits. */ | |
3482 | ||
3483 | inline void | |
3484 | ipa_polymorphic_call_context::offset_by (HOST_WIDE_INT off) | |
3485 | { | |
3486 | if (outer_type) | |
3487 | offset += off; | |
3488 | if (speculative_outer_type) | |
3489 | speculative_offset += off; | |
3490 | } | |
3491 | ||
3492 | /* Return TRUE if context is fully useless. */ | |
3493 | ||
3494 | inline bool | |
3495 | ipa_polymorphic_call_context::useless_p () const | |
3496 | { | |
3497 | return (!outer_type && !speculative_outer_type); | |
3498 | } | |
d5e254e1 | 3499 | |
2a72a953 DM |
3500 | /* When using fprintf (or similar), problems can arise with |
3501 | transient generated strings. Many string-generation APIs | |
3502 | only support one result being alive at once (e.g. by | |
3503 | returning a pointer to a statically-allocated buffer). | |
3504 | ||
3505 | If there is more than one generated string within one | |
3506 | fprintf call: the first string gets evicted or overwritten | |
3507 | by the second, before fprintf is fully evaluated. | |
3508 | See e.g. PR/53136. | |
3509 | ||
3510 | This function provides a workaround for this, by providing | |
3511 | a simple way to create copies of these transient strings, | |
3512 | without the need to have explicit cleanup: | |
3513 | ||
3514 | fprintf (dumpfile, "string 1: %s string 2:%s\n", | |
3515 | xstrdup_for_dump (EXPR_1), | |
3516 | xstrdup_for_dump (EXPR_2)); | |
3517 | ||
3518 | This is actually a simple wrapper around ggc_strdup, but | |
3519 | the name documents the intent. We require that no GC can occur | |
3520 | within the fprintf call. */ | |
3521 | ||
3522 | static inline const char * | |
3523 | xstrdup_for_dump (const char *transient_str) | |
3524 | { | |
3525 | return ggc_strdup (transient_str); | |
3526 | } | |
3527 | ||
f714ecf5 JH |
3528 | /* During LTO stream-in this predicate can be used to check whether node |
3529 | in question prevails in the linking to save some memory usage. */ | |
3530 | inline bool | |
3531 | symtab_node::prevailing_p (void) | |
3532 | { | |
3533 | return definition && ((!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl)) | |
3534 | || previous_sharing_asm_name == NULL); | |
3535 | } | |
3536 | ||
212755ff DM |
3537 | extern GTY(()) symbol_table *saved_symtab; |
3538 | ||
3539 | #if CHECKING_P | |
3540 | ||
3541 | namespace selftest { | |
3542 | ||
3543 | /* An RAII-style class for use in selftests for temporarily using a different | |
3544 | symbol_table, so that such tests can be isolated from each other. */ | |
3545 | ||
3546 | class symbol_table_test | |
3547 | { | |
3548 | public: | |
3549 | /* Constructor. Override "symtab". */ | |
3550 | symbol_table_test (); | |
3551 | ||
3552 | /* Destructor. Restore the saved_symtab. */ | |
3553 | ~symbol_table_test (); | |
3554 | }; | |
3555 | ||
3556 | } // namespace selftest | |
3557 | ||
3558 | #endif /* CHECKING_P */ | |
3559 | ||
1c4a429a | 3560 | #endif /* GCC_CGRAPH_H */ |