]>
Commit | Line | Data |
---|---|---|
1c4a429a | 1 | /* Callgraph handling code. |
23a5b65a | 2 | Copyright (C) 2003-2014 Free Software Foundation, Inc. |
1c4a429a JH |
3 | Contributed by Jan Hubicka |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
1c4a429a JH |
10 | version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
1c4a429a JH |
20 | |
21 | #ifndef GCC_CGRAPH_H | |
22 | #define GCC_CGRAPH_H | |
7a8cba34 | 23 | |
b787e7a2 | 24 | #include "hash-map.h" |
5d59b5e1 | 25 | #include "is-a.h" |
051f8cc6 | 26 | #include "plugin-api.h" |
7a8cba34 | 27 | #include "vec.h" |
4d648807 | 28 | #include "basic-block.h" |
7a8cba34 | 29 | #include "function.h" |
1f00098b JH |
30 | #include "ipa-ref.h" |
31 | ||
32 | /* Symbol table consists of functions and variables. | |
e70670cf | 33 | TODO: add labels and CONST_DECLs. */ |
1f00098b JH |
34 | enum symtab_type |
35 | { | |
960bfb69 | 36 | SYMTAB_SYMBOL, |
1f00098b JH |
37 | SYMTAB_FUNCTION, |
38 | SYMTAB_VARIABLE | |
39 | }; | |
40 | ||
f961457f JH |
41 | /* Section names are stored as reference counted strings in GGC safe hashtable |
42 | (to make them survive through PCH). */ | |
43 | ||
44 | struct GTY(()) section_hash_entry_d | |
45 | { | |
46 | int ref_count; | |
47 | char *name; /* As long as this datastructure stays in GGC, we can not put | |
48 | string at the tail of structure of GGC dies in horrible | |
49 | way */ | |
50 | }; | |
51 | ||
52 | typedef struct section_hash_entry_d section_hash_entry; | |
53 | ||
d52f5295 ML |
54 | enum availability |
55 | { | |
56 | /* Not yet set by cgraph_function_body_availability. */ | |
57 | AVAIL_UNSET, | |
58 | /* Function body/variable initializer is unknown. */ | |
59 | AVAIL_NOT_AVAILABLE, | |
60 | /* Function body/variable initializer is known but might be replaced | |
61 | by a different one from other compilation unit and thus needs to | |
62 | be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have | |
63 | arbitrary side effects on escaping variables and functions, while | |
64 | like AVAILABLE it might access static variables. */ | |
65 | AVAIL_INTERPOSABLE, | |
66 | /* Function body/variable initializer is known and will be used in final | |
67 | program. */ | |
68 | AVAIL_AVAILABLE, | |
69 | /* Function body/variable initializer is known and all it's uses are | |
70 | explicitly visible within current unit (ie it's address is never taken and | |
71 | it is not exported to other units). Currently used only for functions. */ | |
72 | AVAIL_LOCAL | |
73 | }; | |
74 | ||
75 | /* Classification of symbols WRT partitioning. */ | |
76 | enum symbol_partitioning_class | |
77 | { | |
78 | /* External declarations are ignored by partitioning algorithms and they are | |
79 | added into the boundary later via compute_ltrans_boundary. */ | |
80 | SYMBOL_EXTERNAL, | |
81 | /* Partitioned symbols are pur into one of partitions. */ | |
82 | SYMBOL_PARTITION, | |
83 | /* Duplicated symbols (such as comdat or constant pool references) are | |
84 | copied into every node needing them via add_symbol_to_partition. */ | |
85 | SYMBOL_DUPLICATE | |
86 | }; | |
87 | ||
1f00098b JH |
88 | /* Base of all entries in the symbol table. |
89 | The symtab_node is inherited by cgraph and varpol nodes. */ | |
a3bfa8b8 DM |
90 | class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"), |
91 | chain_next ("%h.next"), chain_prev ("%h.previous"))) | |
5e20cdc9 | 92 | symtab_node |
1f00098b | 93 | { |
a3bfa8b8 | 94 | public: |
fec39fa6 TS |
95 | /* Return name. */ |
96 | const char *name () const; | |
97 | ||
98 | /* Return asm name. */ | |
99 | const char * asm_name () const; | |
100 | ||
d52f5295 ML |
101 | /* Add node into symbol table. This function is not used directly, but via |
102 | cgraph/varpool node creation routines. */ | |
103 | void register_symbol (void); | |
104 | ||
105 | /* Remove symbol from symbol table. */ | |
106 | void remove (void); | |
107 | ||
108 | /* Dump symtab node to F. */ | |
109 | void dump (FILE *f); | |
110 | ||
111 | /* Dump symtab node to stderr. */ | |
112 | void DEBUG_FUNCTION debug (void); | |
113 | ||
114 | /* Verify consistency of node. */ | |
115 | void DEBUG_FUNCTION verify (void); | |
116 | ||
117 | /* Return ipa reference from this symtab_node to | |
118 | REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type | |
119 | of the use and STMT the statement (if it exists). */ | |
120 | struct ipa_ref *add_reference (symtab_node *referred_node, | |
121 | enum ipa_ref_use use_type); | |
122 | ||
123 | /* Return ipa reference from this symtab_node to | |
124 | REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type | |
125 | of the use and STMT the statement (if it exists). */ | |
126 | struct ipa_ref *add_reference (symtab_node *referred_node, | |
127 | enum ipa_ref_use use_type, gimple stmt); | |
128 | ||
129 | /* If VAL is a reference to a function or a variable, add a reference from | |
130 | this symtab_node to the corresponding symbol table node. USE_TYPE specify | |
131 | type of the use and STMT the statement (if it exists). Return the new | |
132 | reference or NULL if none was created. */ | |
133 | struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type, | |
134 | gimple stmt); | |
135 | ||
136 | /* Clone all references from symtab NODE to this symtab_node. */ | |
137 | void clone_references (symtab_node *node); | |
138 | ||
139 | /* Remove all stmt references in non-speculative references. | |
140 | Those are not maintained during inlining & clonning. | |
141 | The exception are speculative references that are updated along | |
142 | with callgraph edges associated with them. */ | |
143 | void clone_referring (symtab_node *node); | |
144 | ||
145 | /* Clone reference REF to this symtab_node and set its stmt to STMT. */ | |
146 | struct ipa_ref *clone_reference (struct ipa_ref *ref, gimple stmt); | |
147 | ||
148 | /* Find the structure describing a reference to REFERRED_NODE | |
149 | and associated with statement STMT. */ | |
150 | struct ipa_ref *find_reference (symtab_node *referred_node, gimple stmt, | |
151 | unsigned int lto_stmt_uid); | |
152 | ||
153 | /* Remove all references that are associated with statement STMT. */ | |
154 | void remove_stmt_references (gimple stmt); | |
155 | ||
156 | /* Remove all stmt references in non-speculative references. | |
157 | Those are not maintained during inlining & clonning. | |
158 | The exception are speculative references that are updated along | |
159 | with callgraph edges associated with them. */ | |
160 | void clear_stmts_in_references (void); | |
161 | ||
162 | /* Remove all references in ref list. */ | |
163 | void remove_all_references (void); | |
164 | ||
165 | /* Remove all referring items in ref list. */ | |
166 | void remove_all_referring (void); | |
167 | ||
168 | /* Dump references in ref list to FILE. */ | |
169 | void dump_references (FILE *file); | |
170 | ||
171 | /* Dump referring in list to FILE. */ | |
172 | void dump_referring (FILE *); | |
173 | ||
174 | /* Iterates I-th reference in the list, REF is also set. */ | |
175 | struct ipa_ref *iterate_reference (unsigned i, struct ipa_ref *&ref); | |
176 | ||
177 | /* Iterates I-th referring item in the list, REF is also set. */ | |
178 | struct ipa_ref *iterate_referring (unsigned i, struct ipa_ref *&ref); | |
179 | ||
180 | /* Iterates I-th referring alias item in the list, REF is also set. */ | |
181 | struct ipa_ref *iterate_direct_aliases (unsigned i, struct ipa_ref *&ref); | |
182 | ||
183 | /* Return true if symtab node and TARGET represents | |
184 | semantically equivalent symbols. */ | |
185 | bool semantically_equivalent_p (symtab_node *target); | |
186 | ||
187 | /* Classify symbol symtab node for partitioning. */ | |
188 | enum symbol_partitioning_class get_partitioning_class (void); | |
189 | ||
190 | /* Return comdat group. */ | |
191 | tree get_comdat_group () | |
192 | { | |
193 | return x_comdat_group; | |
194 | } | |
195 | ||
196 | /* Return comdat group as identifier_node. */ | |
197 | tree get_comdat_group_id () | |
198 | { | |
199 | if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE) | |
200 | x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group); | |
201 | return x_comdat_group; | |
202 | } | |
203 | ||
204 | /* Set comdat group. */ | |
205 | void set_comdat_group (tree group) | |
206 | { | |
207 | gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE | |
208 | || DECL_P (group)); | |
209 | x_comdat_group = group; | |
210 | } | |
211 | ||
212 | /* Return section as string. */ | |
213 | const char * get_section () | |
214 | { | |
215 | if (!x_section) | |
216 | return NULL; | |
217 | return x_section->name; | |
218 | } | |
219 | ||
220 | /* Remove node from same comdat group. */ | |
221 | void remove_from_same_comdat_group (void); | |
222 | ||
223 | /* Add this symtab_node to the same comdat group that OLD is in. */ | |
224 | void add_to_same_comdat_group (symtab_node *old_node); | |
225 | ||
226 | /* Dissolve the same_comdat_group list in which NODE resides. */ | |
227 | void dissolve_same_comdat_group_list (void); | |
228 | ||
229 | /* Return true when symtab_node is known to be used from other (non-LTO) | |
230 | object file. Known only when doing LTO via linker plugin. */ | |
231 | bool used_from_object_file_p (void); | |
232 | ||
233 | /* Walk the alias chain to return the symbol NODE is alias of. | |
234 | If NODE is not an alias, return NODE. | |
235 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ | |
236 | symtab_node *ultimate_alias_target (enum availability *avail = NULL); | |
237 | ||
238 | /* Return next reachable static symbol with initializer after NODE. */ | |
239 | inline symtab_node *next_defined_symbol (void); | |
240 | ||
241 | /* Add reference recording that symtab node is alias of TARGET. | |
242 | The function can fail in the case of aliasing cycles; in this case | |
243 | it returns false. */ | |
244 | bool resolve_alias (symtab_node *target); | |
245 | ||
246 | /* C++ FE sometimes change linkage flags after producing same | |
247 | body aliases. */ | |
248 | void fixup_same_cpp_alias_visibility (symtab_node *target); | |
249 | ||
250 | /* Call calback on symtab node and aliases associated to this node. | |
251 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are | |
252 | skipped. */ | |
253 | bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *), | |
254 | void *data, | |
255 | bool include_overwrite); | |
256 | ||
257 | /* If node can not be interposable by static or dynamic linker to point to | |
258 | different definition, return this symbol. Otherwise look for alias with | |
259 | such property and if none exists, introduce new one. */ | |
260 | symtab_node *noninterposable_alias (void); | |
261 | ||
262 | /* Return node that alias is aliasing. */ | |
263 | inline symtab_node *get_alias_target (void); | |
264 | ||
265 | /* Set section for symbol and its aliases. */ | |
266 | void set_section (const char *section); | |
267 | ||
268 | /* Set section, do not recurse into aliases. | |
269 | When one wants to change section of symbol and its aliases, | |
270 | use set_section. */ | |
271 | void set_section_for_node (const char *section); | |
272 | ||
273 | /* Set initialization priority to PRIORITY. */ | |
274 | void set_init_priority (priority_type priority); | |
275 | ||
276 | /* Return the initialization priority. */ | |
277 | priority_type get_init_priority (); | |
278 | ||
279 | /* Return availability of NODE. */ | |
280 | enum availability get_availability (void); | |
281 | ||
282 | /* Make DECL local. */ | |
283 | void make_decl_local (void); | |
284 | ||
285 | /* Return true if list contains an alias. */ | |
286 | bool has_aliases_p (void); | |
287 | ||
288 | /* Return true when the symbol is real symbol, i.e. it is not inline clone | |
289 | or abstract function kept for debug info purposes only. */ | |
290 | bool real_symbol_p (void); | |
291 | ||
292 | /* Return true if NODE can be discarded by linker from the binary. */ | |
293 | inline bool | |
294 | can_be_discarded_p (void) | |
295 | { | |
296 | return (DECL_EXTERNAL (decl) | |
297 | || (get_comdat_group () | |
298 | && resolution != LDPR_PREVAILING_DEF | |
299 | && resolution != LDPR_PREVAILING_DEF_IRONLY | |
300 | && resolution != LDPR_PREVAILING_DEF_IRONLY_EXP)); | |
301 | } | |
302 | ||
303 | /* Return true if NODE is local to a particular COMDAT group, and must not | |
304 | be named from outside the COMDAT. This is used for C++ decloned | |
305 | constructors. */ | |
306 | inline bool comdat_local_p (void) | |
307 | { | |
308 | return (same_comdat_group && !TREE_PUBLIC (decl)); | |
309 | } | |
310 | ||
311 | /* Return true if ONE and TWO are part of the same COMDAT group. */ | |
312 | inline bool in_same_comdat_group_p (symtab_node *target); | |
313 | ||
314 | /* Return true when there is a reference to node and it is not vtable. */ | |
315 | bool address_taken_from_non_vtable_p (void); | |
316 | ||
317 | /* Return true if symbol is known to be nonzero. */ | |
318 | bool nonzero_address (); | |
319 | ||
320 | /* Return symbol table node associated with DECL, if any, | |
321 | and NULL otherwise. */ | |
322 | static inline symtab_node *get (const_tree decl) | |
323 | { | |
324 | #ifdef ENABLE_CHECKING | |
325 | /* Check that we are called for sane type of object - functions | |
326 | and static or external variables. */ | |
327 | gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL | |
328 | || (TREE_CODE (decl) == VAR_DECL | |
329 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl) | |
330 | || in_lto_p))); | |
331 | /* Check that the mapping is sane - perhaps this check can go away, | |
332 | but at the moment frontends tends to corrupt the mapping by calling | |
333 | memcpy/memset on the tree nodes. */ | |
334 | gcc_checking_assert (!decl->decl_with_vis.symtab_node | |
335 | || decl->decl_with_vis.symtab_node->decl == decl); | |
336 | #endif | |
337 | return decl->decl_with_vis.symtab_node; | |
338 | } | |
339 | ||
340 | /* Dump symbol table to F. */ | |
341 | static void dump_table (FILE *); | |
342 | ||
343 | /* Dump symbol table to stderr. */ | |
344 | static inline DEBUG_FUNCTION void debug_symtab (void) | |
345 | { | |
346 | dump_table (stderr); | |
347 | } | |
348 | ||
349 | /* Verify symbol table for internal consistency. */ | |
350 | static DEBUG_FUNCTION void verify_symtab_nodes (void); | |
351 | ||
352 | /* Return true when NODE is known to be used from other (non-LTO) | |
353 | object file. Known only when doing LTO via linker plugin. */ | |
354 | static bool used_from_object_file_p_worker (symtab_node *node); | |
355 | ||
1f00098b | 356 | /* Type of the symbol. */ |
b8dbdb12 RG |
357 | ENUM_BITFIELD (symtab_type) type : 8; |
358 | ||
359 | /* The symbols resolution. */ | |
360 | ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8; | |
361 | ||
e70670cf JH |
362 | /*** Flags representing the symbol type. ***/ |
363 | ||
364 | /* True when symbol corresponds to a definition in current unit. | |
365 | set via cgraph_finalize_function or varpool_finalize_decl */ | |
366 | unsigned definition : 1; | |
9041d2e6 ML |
367 | /* True when symbol is an alias. |
368 | Set by ssemble_alias. */ | |
e70670cf | 369 | unsigned alias : 1; |
08346abd JH |
370 | /* True when alias is a weakref. */ |
371 | unsigned weakref : 1; | |
40a7fe1e | 372 | /* C++ frontend produce same body aliases and extra name aliases for |
688010ba | 373 | virtual functions and vtables that are obviously equivalent. |
40a7fe1e JH |
374 | Those aliases are bit special, especially because C++ frontend |
375 | visibility code is so ugly it can not get them right at first time | |
376 | and their visibility needs to be copied from their "masters" at | |
377 | the end of parsing. */ | |
378 | unsigned cpp_implicit_alias : 1; | |
e70670cf JH |
379 | /* Set once the definition was analyzed. The list of references and |
380 | other properties are built during analysis. */ | |
381 | unsigned analyzed : 1; | |
6de88c6a JH |
382 | /* Set for write-only variables. */ |
383 | unsigned writeonly : 1; | |
e70670cf JH |
384 | |
385 | ||
386 | /*** Visibility and linkage flags. ***/ | |
387 | ||
b8dbdb12 RG |
388 | /* Set when function is visible by other units. */ |
389 | unsigned externally_visible : 1; | |
4bcfd75c | 390 | /* The symbol will be assumed to be used in an invisible way (like |
edb983b2 | 391 | by an toplevel asm statement). */ |
b8dbdb12 | 392 | unsigned force_output : 1; |
edb983b2 JH |
393 | /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be |
394 | exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted | |
395 | to static and it does not inhibit optimization. */ | |
396 | unsigned forced_by_abi : 1; | |
702d8703 JH |
397 | /* True when the name is known to be unique and thus it does not need mangling. */ |
398 | unsigned unique_name : 1; | |
e257a17c JH |
399 | /* Specify whether the section was set by user or by |
400 | compiler via -ffunction-sections. */ | |
401 | unsigned implicit_section : 1; | |
3d8d0043 MJ |
402 | /* True when body and other characteristics have been removed by |
403 | symtab_remove_unreachable_nodes. */ | |
404 | unsigned body_removed : 1; | |
b8dbdb12 | 405 | |
e70670cf JH |
406 | /*** WHOPR Partitioning flags. |
407 | These flags are used at ltrans stage when only part of the callgraph is | |
408 | available. ***/ | |
b8dbdb12 | 409 | |
e70670cf JH |
410 | /* Set when variable is used from other LTRANS partition. */ |
411 | unsigned used_from_other_partition : 1; | |
9041d2e6 | 412 | /* Set when function is available in the other LTRANS partition. |
e70670cf JH |
413 | During WPA output it is used to mark nodes that are present in |
414 | multiple partitions. */ | |
415 | unsigned in_other_partition : 1; | |
b8dbdb12 | 416 | |
b8dbdb12 | 417 | |
e70670cf JH |
418 | |
419 | /*** other flags. ***/ | |
420 | ||
421 | /* Set when symbol has address taken. */ | |
422 | unsigned address_taken : 1; | |
569b1784 JH |
423 | /* Set when init priority is set. */ |
424 | unsigned in_init_priority_hash : 1; | |
e70670cf JH |
425 | |
426 | ||
427 | /* Ordering of all symtab entries. */ | |
428 | int order; | |
429 | ||
430 | /* Declaration representing the symbol. */ | |
431 | tree decl; | |
960bfb69 | 432 | |
2aae7680 | 433 | /* Linked list of symbol table entries starting with symtab_nodes. */ |
5e20cdc9 DM |
434 | symtab_node *next; |
435 | symtab_node *previous; | |
e70670cf | 436 | |
1ab24192 | 437 | /* Linked list of symbols with the same asm name. There may be multiple |
e70670cf JH |
438 | entries for single symbol name during LTO, because symbols are renamed |
439 | only after partitioning. | |
440 | ||
441 | Because inline clones are kept in the assembler name has, they also produce | |
442 | duplicate entries. | |
443 | ||
444 | There are also several long standing bugs where frontends and builtin | |
445 | code produce duplicated decls. */ | |
5e20cdc9 DM |
446 | symtab_node *next_sharing_asm_name; |
447 | symtab_node *previous_sharing_asm_name; | |
2aae7680 | 448 | |
d52f5295 ML |
449 | /* Circular list of nodes in the same comdat group if non-NULL. */ |
450 | symtab_node *same_comdat_group; | |
e55637b7 | 451 | |
e70670cf JH |
452 | /* Vectors of referring and referenced entities. */ |
453 | struct ipa_ref_list ref_list; | |
454 | ||
40a7fe1e JH |
455 | /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer |
456 | depending to what was known to frontend on the creation time. | |
457 | Once alias is resolved, this pointer become NULL. */ | |
458 | tree alias_target; | |
459 | ||
e70670cf JH |
460 | /* File stream where this node is being written to. */ |
461 | struct lto_file_decl_data * lto_file_data; | |
462 | ||
960bfb69 | 463 | PTR GTY ((skip)) aux; |
aede2c10 JH |
464 | |
465 | /* Comdat group the symbol is in. Can be private if GGC allowed that. */ | |
f961457f | 466 | tree x_comdat_group; |
24d047a3 JH |
467 | |
468 | /* Section name. Again can be private, if allowed. */ | |
f961457f | 469 | section_hash_entry *x_section; |
e257a17c | 470 | |
d52f5295 ML |
471 | protected: |
472 | /* Dump base fields of symtab nodes to F. Not to be used directly. */ | |
473 | void dump_base (FILE *); | |
569b1784 | 474 | |
d52f5295 ML |
475 | /* Verify common part of symtab node. */ |
476 | bool DEBUG_FUNCTION verify_base (void); | |
89330618 | 477 | |
d52f5295 ML |
478 | /* Remove node from symbol table. This function is not used directly, but via |
479 | cgraph/varpool node removal routines. */ | |
480 | void unregister (void); | |
481 | ||
482 | /* Return the initialization and finalization priority information for | |
483 | DECL. If there is no previous priority information, a freshly | |
484 | allocated structure is returned. */ | |
485 | struct symbol_priority_map *priority_info (void); | |
486 | ||
487 | private: | |
488 | /* Worker for set_section. */ | |
489 | static bool set_section (symtab_node *n, void *s); | |
490 | ||
491 | /* Worker for symtab_resolve_alias. */ | |
492 | static bool set_implicit_section (symtab_node *n, void *); | |
493 | ||
494 | /* Worker searching noninterposable alias. */ | |
495 | static bool noninterposable_alias (symtab_node *node, void *data); | |
1f00098b | 496 | }; |
1c4a429a | 497 | |
e55637b7 ML |
498 | /* Walk all aliases for NODE. */ |
499 | #define FOR_EACH_ALIAS(node, alias) \ | |
d52f5295 | 500 | for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++) |
6b02a499 | 501 | |
d7f09764 DN |
502 | /* This is the information that is put into the cgraph local structure |
503 | to recover a function. */ | |
504 | struct lto_file_decl_data; | |
505 | ||
8a4a83ed | 506 | extern const char * const cgraph_availability_names[]; |
430c6ceb | 507 | extern const char * const ld_plugin_symbol_resolution_names[]; |
714c800f | 508 | extern const char * const tls_model_names[]; |
8a4a83ed | 509 | |
6744a6ab JH |
510 | /* Information about thunk, used only for same body aliases. */ |
511 | ||
512 | struct GTY(()) cgraph_thunk_info { | |
513 | /* Information about the thunk. */ | |
514 | HOST_WIDE_INT fixed_offset; | |
515 | HOST_WIDE_INT virtual_value; | |
516 | tree alias; | |
517 | bool this_adjusting; | |
518 | bool virtual_offset_p; | |
519 | /* Set to true when alias node is thunk. */ | |
520 | bool thunk_p; | |
521 | }; | |
522 | ||
dafc5b82 | 523 | /* Information about the function collected locally. |
25c84396 | 524 | Available after function is analyzed. */ |
dafc5b82 | 525 | |
d1b38208 | 526 | struct GTY(()) cgraph_local_info { |
e0bb17a8 | 527 | /* Set when function function is visible in current compilation unit only |
e2209b03 | 528 | and its address is never taken. */ |
b4e19405 | 529 | unsigned local : 1; |
6674a6ce | 530 | |
124f1be6 MJ |
531 | /* False when there is something makes versioning impossible. */ |
532 | unsigned versionable : 1; | |
533 | ||
61e03ffc JH |
534 | /* False when function calling convention and signature can not be changed. |
535 | This is the case when __builtin_apply_args is used. */ | |
536 | unsigned can_change_signature : 1; | |
537 | ||
95c755e9 JH |
538 | /* True when the function has been originally extern inline, but it is |
539 | redefined now. */ | |
b4e19405 | 540 | unsigned redefined_extern_inline : 1; |
0a35513e AH |
541 | |
542 | /* True if the function may enter serial irrevocable mode. */ | |
543 | unsigned tm_may_enter_irr : 1; | |
dafc5b82 JH |
544 | }; |
545 | ||
546 | /* Information about the function that needs to be computed globally | |
726a989a | 547 | once compilation is finished. Available only with -funit-at-a-time. */ |
dafc5b82 | 548 | |
d1b38208 | 549 | struct GTY(()) cgraph_global_info { |
726a989a RB |
550 | /* For inline clones this points to the function they will be |
551 | inlined into. */ | |
d52f5295 | 552 | cgraph_node *inlined_to; |
dafc5b82 JH |
553 | }; |
554 | ||
b255a036 JH |
555 | /* Information about the function that is propagated by the RTL backend. |
556 | Available only for functions that has been already assembled. */ | |
557 | ||
d1b38208 | 558 | struct GTY(()) cgraph_rtl_info { |
17b29c0a | 559 | unsigned int preferred_incoming_stack_boundary; |
27c07cc5 RO |
560 | |
561 | /* Call unsaved hard registers really used by the corresponding | |
562 | function (including ones used by functions called by the | |
563 | function). */ | |
564 | HARD_REG_SET function_used_regs; | |
565 | /* Set if function_used_regs is valid. */ | |
566 | unsigned function_used_regs_valid: 1; | |
b255a036 JH |
567 | }; |
568 | ||
9187e02d JH |
569 | /* Represent which DECL tree (or reference to such tree) |
570 | will be replaced by another tree while versioning. */ | |
571 | struct GTY(()) ipa_replace_map | |
572 | { | |
573 | /* The tree that will be replaced. */ | |
574 | tree old_tree; | |
575 | /* The new (replacing) tree. */ | |
576 | tree new_tree; | |
922f15c2 JH |
577 | /* Parameter number to replace, when old_tree is NULL. */ |
578 | int parm_num; | |
9187e02d JH |
579 | /* True when a substitution should be done, false otherwise. */ |
580 | bool replace_p; | |
581 | /* True when we replace a reference to old_tree. */ | |
582 | bool ref_p; | |
583 | }; | |
9187e02d JH |
584 | |
585 | struct GTY(()) cgraph_clone_info | |
586 | { | |
d52f5295 | 587 | vec<ipa_replace_map *, va_gc> *tree_map; |
9187e02d | 588 | bitmap args_to_skip; |
08ad1d6d | 589 | bitmap combined_args_to_skip; |
9187e02d JH |
590 | }; |
591 | ||
0136f8f0 AH |
592 | enum cgraph_simd_clone_arg_type |
593 | { | |
594 | SIMD_CLONE_ARG_TYPE_VECTOR, | |
595 | SIMD_CLONE_ARG_TYPE_UNIFORM, | |
596 | SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP, | |
597 | SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, | |
598 | SIMD_CLONE_ARG_TYPE_MASK | |
599 | }; | |
600 | ||
601 | /* Function arguments in the original function of a SIMD clone. | |
602 | Supplementary data for `struct simd_clone'. */ | |
603 | ||
604 | struct GTY(()) cgraph_simd_clone_arg { | |
605 | /* Original function argument as it originally existed in | |
606 | DECL_ARGUMENTS. */ | |
607 | tree orig_arg; | |
608 | ||
609 | /* orig_arg's function (or for extern functions type from | |
610 | TYPE_ARG_TYPES). */ | |
611 | tree orig_type; | |
612 | ||
613 | /* If argument is a vector, this holds the vector version of | |
614 | orig_arg that after adjusting the argument types will live in | |
615 | DECL_ARGUMENTS. Otherwise, this is NULL. | |
616 | ||
617 | This basically holds: | |
618 | vector(simdlen) __typeof__(orig_arg) new_arg. */ | |
619 | tree vector_arg; | |
620 | ||
621 | /* vector_arg's type (or for extern functions new vector type. */ | |
622 | tree vector_type; | |
623 | ||
624 | /* If argument is a vector, this holds the array where the simd | |
625 | argument is held while executing the simd clone function. This | |
626 | is a local variable in the cloned function. Its content is | |
627 | copied from vector_arg upon entry to the clone. | |
628 | ||
629 | This basically holds: | |
630 | __typeof__(orig_arg) simd_array[simdlen]. */ | |
631 | tree simd_array; | |
632 | ||
633 | /* A SIMD clone's argument can be either linear (constant or | |
634 | variable), uniform, or vector. */ | |
635 | enum cgraph_simd_clone_arg_type arg_type; | |
636 | ||
637 | /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is | |
638 | the constant linear step, if arg_type is | |
639 | SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of | |
640 | the uniform argument holding the step, otherwise 0. */ | |
641 | HOST_WIDE_INT linear_step; | |
642 | ||
643 | /* Variable alignment if available, otherwise 0. */ | |
644 | unsigned int alignment; | |
645 | }; | |
646 | ||
647 | /* Specific data for a SIMD function clone. */ | |
648 | ||
649 | struct GTY(()) cgraph_simd_clone { | |
650 | /* Number of words in the SIMD lane associated with this clone. */ | |
651 | unsigned int simdlen; | |
652 | ||
653 | /* Number of annotated function arguments in `args'. This is | |
654 | usually the number of named arguments in FNDECL. */ | |
655 | unsigned int nargs; | |
656 | ||
657 | /* Max hardware vector size in bits for integral vectors. */ | |
658 | unsigned int vecsize_int; | |
659 | ||
660 | /* Max hardware vector size in bits for floating point vectors. */ | |
661 | unsigned int vecsize_float; | |
662 | ||
663 | /* The mangling character for a given vector size. This is is used | |
664 | to determine the ISA mangling bit as specified in the Intel | |
665 | Vector ABI. */ | |
666 | unsigned char vecsize_mangle; | |
667 | ||
668 | /* True if this is the masked, in-branch version of the clone, | |
669 | otherwise false. */ | |
670 | unsigned int inbranch : 1; | |
671 | ||
672 | /* True if this is a Cilk Plus variant. */ | |
673 | unsigned int cilk_elemental : 1; | |
674 | ||
675 | /* Doubly linked list of SIMD clones. */ | |
d52f5295 | 676 | cgraph_node *prev_clone, *next_clone; |
0136f8f0 AH |
677 | |
678 | /* Original cgraph node the SIMD clones were created for. */ | |
d52f5295 | 679 | cgraph_node *origin; |
0136f8f0 AH |
680 | |
681 | /* Annotated function arguments for the original function. */ | |
682 | struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1]; | |
683 | }; | |
684 | ||
d52f5295 ML |
685 | /* Function Multiversioning info. */ |
686 | struct GTY(()) cgraph_function_version_info { | |
687 | /* The cgraph_node for which the function version info is stored. */ | |
688 | cgraph_node *this_node; | |
689 | /* Chains all the semantically identical function versions. The | |
690 | first function in this chain is the version_info node of the | |
691 | default function. */ | |
692 | struct cgraph_function_version_info *prev; | |
693 | /* If this version node corresponds to a dispatcher for function | |
694 | versions, this points to the version info node of the default | |
695 | function, the first node in the chain. */ | |
696 | struct cgraph_function_version_info *next; | |
697 | /* If this node corresponds to a function version, this points | |
698 | to the dispatcher function decl, which is the function that must | |
699 | be called to execute the right function version at run-time. | |
700 | ||
701 | If this cgraph node is a dispatcher (if dispatcher_function is | |
702 | true, in the cgraph_node struct) for function versions, this | |
703 | points to resolver function, which holds the function body of the | |
704 | dispatcher. The dispatcher decl is an alias to the resolver | |
705 | function decl. */ | |
706 | tree dispatcher_resolver; | |
707 | }; | |
708 | ||
709 | #define DEFCIFCODE(code, type, string) CIF_ ## code, | |
710 | /* Reasons for inlining failures. */ | |
711 | ||
712 | enum cgraph_inline_failed_t { | |
713 | #include "cif-code.def" | |
714 | CIF_N_REASONS | |
715 | }; | |
716 | ||
717 | enum cgraph_inline_failed_type_t | |
718 | { | |
719 | CIF_FINAL_NORMAL = 0, | |
720 | CIF_FINAL_ERROR | |
721 | }; | |
722 | ||
723 | struct cgraph_edge; | |
5fefcf92 | 724 | |
ba228239 | 725 | /* The cgraph data structure. |
e0bb17a8 | 726 | Each function decl has assigned cgraph_node listing callees and callers. */ |
1c4a429a | 727 | |
5e20cdc9 | 728 | struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node { |
a3bfa8b8 | 729 | public: |
d52f5295 ML |
730 | /* Remove the node from cgraph and all inline clones inlined into it. |
731 | Skip however removal of FORBIDDEN_NODE and return true if it needs to be | |
732 | removed. This allows to call the function from outer loop walking clone | |
733 | tree. */ | |
734 | bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL); | |
735 | ||
736 | /* Record all references from cgraph_node that are taken | |
737 | in statement STMT. */ | |
738 | void record_stmt_references (gimple stmt); | |
739 | ||
740 | /* Like cgraph_set_call_stmt but walk the clone tree and update all | |
741 | clones sharing the same function body. | |
742 | When WHOLE_SPECULATIVE_EDGES is true, all three components of | |
743 | speculative edge gets updated. Otherwise we update only direct | |
744 | call. */ | |
745 | void set_call_stmt_including_clones (gimple old_stmt, gimple new_stmt, | |
746 | bool update_speculative = true); | |
747 | ||
748 | /* Walk the alias chain to return the function cgraph_node is alias of. | |
749 | Walk through thunk, too. | |
750 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ | |
751 | cgraph_node *function_symbol (enum availability *avail = NULL); | |
752 | ||
753 | /* Create node representing clone of N executed COUNT times. Decrease | |
754 | the execution counts from original node too. | |
755 | The new clone will have decl set to DECL that may or may not be the same | |
756 | as decl of N. | |
757 | ||
758 | When UPDATE_ORIGINAL is true, the counts are subtracted from the original | |
759 | function's profile to reflect the fact that part of execution is handled | |
760 | by node. | |
761 | When CALL_DUPLICATOIN_HOOK is true, the ipa passes are acknowledged about | |
762 | the new clone. Otherwise the caller is responsible for doing so later. | |
763 | ||
764 | If the new node is being inlined into another one, NEW_INLINED_TO should be | |
765 | the outline function the new one is (even indirectly) inlined to. | |
766 | All hooks will see this in node's global.inlined_to, when invoked. | |
767 | Can be NULL if the node is not inlined. */ | |
768 | cgraph_node *create_clone (tree decl, gcov_type count, int freq, | |
769 | bool update_original, | |
770 | vec<cgraph_edge *> redirect_callers, | |
771 | bool call_duplication_hook, | |
772 | struct cgraph_node *new_inlined_to, | |
773 | bitmap args_to_skip); | |
774 | ||
775 | /* Create callgraph node clone with new declaration. The actual body will | |
776 | be copied later at compilation stage. */ | |
777 | cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers, | |
778 | vec<ipa_replace_map *, va_gc> *tree_map, | |
779 | bitmap args_to_skip, const char * suffix); | |
780 | ||
781 | /* cgraph node being removed from symbol table; see if its entry can be | |
782 | replaced by other inline clone. */ | |
783 | cgraph_node *find_replacement (void); | |
784 | ||
785 | /* Create a new cgraph node which is the new version of | |
786 | callgraph node. REDIRECT_CALLERS holds the callers | |
787 | edges which should be redirected to point to | |
788 | NEW_VERSION. ALL the callees edges of the node | |
789 | are cloned to the new version node. Return the new | |
790 | version node. | |
791 | ||
792 | If non-NULL BLOCK_TO_COPY determine what basic blocks | |
793 | was copied to prevent duplications of calls that are dead | |
794 | in the clone. */ | |
795 | ||
796 | cgraph_node *create_version_clone (tree new_decl, | |
797 | vec<cgraph_edge *> redirect_callers, | |
798 | bitmap bbs_to_copy); | |
799 | ||
800 | /* Perform function versioning. | |
801 | Function versioning includes copying of the tree and | |
802 | a callgraph update (creating a new cgraph node and updating | |
803 | its callees and callers). | |
804 | ||
805 | REDIRECT_CALLERS varray includes the edges to be redirected | |
806 | to the new version. | |
807 | ||
808 | TREE_MAP is a mapping of tree nodes we want to replace with | |
809 | new ones (according to results of prior analysis). | |
810 | ||
811 | If non-NULL ARGS_TO_SKIP determine function parameters to remove | |
812 | from new version. | |
813 | If SKIP_RETURN is true, the new version will return void. | |
814 | If non-NULL BLOCK_TO_COPY determine what basic blocks to copy. | |
815 | If non_NULL NEW_ENTRY determine new entry BB of the clone. | |
816 | ||
817 | Return the new version's cgraph node. */ | |
818 | cgraph_node *create_version_clone_with_body | |
819 | (vec<cgraph_edge *> redirect_callers, | |
820 | vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip, | |
821 | bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block, | |
822 | const char *clone_name); | |
823 | ||
824 | /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab | |
825 | corresponding to cgraph_node. */ | |
826 | struct cgraph_function_version_info *insert_new_function_version (void); | |
827 | ||
828 | /* Get the cgraph_function_version_info node corresponding to node. */ | |
829 | struct cgraph_function_version_info *function_version (void); | |
830 | ||
831 | /* Discover all functions and variables that are trivially needed, analyze | |
832 | them as well as all functions and variables referred by them */ | |
833 | void analyze (void); | |
834 | ||
835 | /* Add thunk alias into callgraph. The alias declaration is ALIAS and it | |
836 | aliases DECL with an adjustments made into the first parameter. | |
837 | See comments in thunk_adjust for detail on the parameters. */ | |
838 | cgraph_node * create_thunk (tree alias, tree, bool this_adjusting, | |
839 | HOST_WIDE_INT fixed_offset, | |
840 | HOST_WIDE_INT virtual_value, | |
841 | tree virtual_offset, | |
842 | tree real_alias); | |
843 | ||
844 | ||
845 | /* Return node that alias is aliasing. */ | |
846 | inline cgraph_node *get_alias_target (void); | |
847 | ||
848 | /* Given function symbol, walk the alias chain to return the function node | |
849 | is alias of. Do not walk through thunks. | |
850 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ | |
851 | ||
852 | cgraph_node *ultimate_alias_target (availability *availability = NULL); | |
853 | ||
854 | /* Expand thunk NODE to gimple if possible. | |
855 | When FORCE_GIMPLE_THUNK is true, gimple thunk is created and | |
856 | no assembler is produced. | |
857 | When OUTPUT_ASM_THUNK is true, also produce assembler for | |
858 | thunks that are not lowered. */ | |
859 | bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk); | |
860 | ||
861 | /* As an GCC extension we allow redefinition of the function. The | |
862 | semantics when both copies of bodies differ is not well defined. | |
863 | We replace the old body with new body so in unit at a time mode | |
864 | we always use new body, while in normal mode we may end up with | |
865 | old body inlined into some functions and new body expanded and | |
866 | inlined in others. */ | |
867 | void reset (void); | |
868 | ||
869 | /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this | |
870 | kind of wrapper method. */ | |
871 | void create_wrapper (cgraph_node *target); | |
872 | ||
873 | /* Verify cgraph nodes of the cgraph node. */ | |
874 | void DEBUG_FUNCTION verify_node (void); | |
875 | ||
876 | /* Remove function from symbol table. */ | |
877 | void remove (void); | |
878 | ||
879 | /* Dump call graph node to file F. */ | |
880 | void dump (FILE *f); | |
881 | ||
882 | /* Dump call graph node to stderr. */ | |
883 | void DEBUG_FUNCTION debug (void); | |
884 | ||
885 | /* When doing LTO, read cgraph_node's body from disk if it is not already | |
886 | present. */ | |
887 | bool get_body (void); | |
888 | ||
889 | /* Release memory used to represent body of function. | |
890 | Use this only for functions that are released before being translated to | |
891 | target code (i.e. RTL). Functions that are compiled to RTL and beyond | |
892 | are free'd in final.c via free_after_compilation(). */ | |
893 | void release_body (void); | |
894 | ||
895 | /* cgraph_node is no longer nested function; update cgraph accordingly. */ | |
896 | void unnest (void); | |
897 | ||
898 | /* Bring cgraph node local. */ | |
899 | void make_local (void); | |
900 | ||
901 | /* Likewise indicate that a node is having address taken. */ | |
902 | void mark_address_taken (void); | |
903 | ||
904 | /* Set fialization priority to PRIORITY. */ | |
905 | void set_fini_priority (priority_type priority); | |
906 | ||
907 | /* Return the finalization priority. */ | |
908 | priority_type get_fini_priority (void); | |
909 | ||
910 | /* Create edge from a given function to CALLEE in the cgraph. */ | |
911 | struct cgraph_edge *create_edge (cgraph_node *callee, | |
912 | gimple call_stmt, gcov_type count, | |
913 | int freq); | |
914 | /* Create an indirect edge with a yet-undetermined callee where the call | |
915 | statement destination is a formal parameter of the caller with index | |
916 | PARAM_INDEX. */ | |
917 | struct cgraph_edge *create_indirect_edge (gimple call_stmt, int ecf_flags, | |
d34af022 IE |
918 | gcov_type count, int freq, |
919 | bool compute_indirect_info = true); | |
d52f5295 ML |
920 | |
921 | /* Like cgraph_create_edge walk the clone tree and update all clones sharing | |
922 | same function body. If clones already have edge for OLD_STMT; only | |
923 | update the edge same way as cgraph_set_call_stmt_including_clones does. */ | |
924 | void create_edge_including_clones (struct cgraph_node *callee, | |
925 | gimple old_stmt, gimple stmt, | |
926 | gcov_type count, | |
927 | int freq, | |
928 | cgraph_inline_failed_t reason); | |
929 | ||
930 | /* Return the callgraph edge representing the GIMPLE_CALL statement | |
931 | CALL_STMT. */ | |
932 | cgraph_edge *get_edge (gimple call_stmt); | |
933 | ||
934 | /* Collect all callers of cgraph_node and its aliases that are known to lead | |
935 | to NODE (i.e. are not overwritable). */ | |
936 | vec<cgraph_edge *> collect_callers (void); | |
937 | ||
938 | /* Remove all callers from the node. */ | |
939 | void remove_callers (void); | |
940 | ||
941 | /* Remove all callees from the node. */ | |
942 | void remove_callees (void); | |
943 | ||
944 | /* Return function availability. See cgraph.h for description of individual | |
945 | return values. */ | |
946 | enum availability get_availability (void); | |
947 | ||
948 | /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node | |
949 | if any to NOTHROW. */ | |
950 | void set_nothrow_flag (bool nothrow); | |
951 | ||
952 | /* Set TREE_READONLY on cgraph_node's decl and on aliases of the node | |
953 | if any to READONLY. */ | |
954 | void set_const_flag (bool readonly, bool looping); | |
955 | ||
956 | /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node | |
957 | if any to PURE. */ | |
958 | void set_pure_flag (bool pure, bool looping); | |
959 | ||
960 | /* Call all node duplication hooks. */ | |
961 | void call_duplication_hooks (cgraph_node *node2); | |
962 | ||
963 | /* Call calback on function and aliases associated to the function. | |
964 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are | |
965 | skipped. */ | |
966 | ||
967 | bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *, | |
968 | void *), | |
969 | void *data, bool include_overwritable); | |
970 | ||
971 | /* Call calback on cgraph_node, thunks and aliases associated to NODE. | |
972 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are | |
973 | skipped. */ | |
974 | bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node, | |
975 | void *data), | |
976 | void *data, | |
977 | bool include_overwritable); | |
978 | ||
979 | /* Call all node insertion hooks. */ | |
980 | void call_function_insertion_hooks (void); | |
981 | ||
982 | /* Likewise indicate that a node is needed, i.e. reachable via some | |
983 | external means. */ | |
984 | inline void mark_force_output (void); | |
985 | ||
986 | /* Return true when function can be marked local. */ | |
987 | bool local_p (void); | |
988 | ||
989 | /* Return true if cgraph_node can be made local for API change. | |
990 | Extern inline functions and C++ COMDAT functions can be made local | |
991 | at the expense of possible code size growth if function is used in multiple | |
992 | compilation units. */ | |
993 | bool can_be_local_p (void); | |
994 | ||
995 | /* Return true when cgraph_node can not return or throw and thus | |
996 | it is safe to ignore its side effects for IPA analysis. */ | |
997 | bool cannot_return_p (void); | |
998 | ||
999 | /* Return true when function cgraph_node and all its aliases are only called | |
1000 | directly. | |
1001 | i.e. it is not externally visible, address was not taken and | |
1002 | it is not used in any other non-standard way. */ | |
1003 | bool only_called_directly_p (void); | |
1004 | ||
1005 | /* Return true when function is only called directly or it has alias. | |
1006 | i.e. it is not externally visible, address was not taken and | |
1007 | it is not used in any other non-standard way. */ | |
1008 | inline bool only_called_directly_or_aliased_p (void); | |
1009 | ||
1010 | /* Return true when function cgraph_node can be expected to be removed | |
1011 | from program when direct calls in this compilation unit are removed. | |
1012 | ||
1013 | As a special case COMDAT functions are | |
1014 | cgraph_can_remove_if_no_direct_calls_p while the are not | |
1015 | cgraph_only_called_directly_p (it is possible they are called from other | |
1016 | unit) | |
1017 | ||
1018 | This function behaves as cgraph_only_called_directly_p because eliminating | |
1019 | all uses of COMDAT function does not make it necessarily disappear from | |
1020 | the program unless we are compiling whole program or we do LTO. In this | |
1021 | case we know we win since dynamic linking will not really discard the | |
1022 | linkonce section. */ | |
1023 | bool will_be_removed_from_program_if_no_direct_calls_p (void); | |
1024 | ||
1025 | /* Return true when function can be removed from callgraph | |
1026 | if all direct calls are eliminated. */ | |
1027 | bool can_remove_if_no_direct_calls_and_refs_p (void); | |
1028 | ||
1029 | /* Return true when function cgraph_node and its aliases can be removed from | |
1030 | callgraph if all direct calls are eliminated. */ | |
1031 | bool can_remove_if_no_direct_calls_p (void); | |
1032 | ||
1033 | /* Return true when callgraph node is a function with Gimple body defined | |
1034 | in current unit. Functions can also be define externally or they | |
1035 | can be thunks with no Gimple representation. | |
1036 | ||
1037 | Note that at WPA stage, the function body may not be present in memory. */ | |
1038 | inline bool has_gimple_body_p (void); | |
1039 | ||
1040 | /* Return true if function should be optimized for size. */ | |
1041 | bool optimize_for_size_p (void); | |
1042 | ||
1043 | /* Dump the callgraph to file F. */ | |
1044 | static void dump_cgraph (FILE *f); | |
1045 | ||
1046 | /* Dump the call graph to stderr. */ | |
1047 | static inline void debug_cgraph (void) | |
1048 | { | |
1049 | dump_cgraph (stderr); | |
1050 | } | |
1051 | ||
1052 | /* Record that DECL1 and DECL2 are semantically identical function | |
1053 | versions. */ | |
1054 | static void record_function_versions (tree decl1, tree decl2); | |
1055 | ||
1056 | /* Remove the cgraph_function_version_info and cgraph_node for DECL. This | |
1057 | DECL is a duplicate declaration. */ | |
1058 | static void delete_function_version (tree decl); | |
1059 | ||
1060 | /* Add the function FNDECL to the call graph. | |
1061 | Unlike cgraph_finalize_function, this function is intended to be used | |
1062 | by middle end and allows insertion of new function at arbitrary point | |
1063 | of compilation. The function can be either in high, low or SSA form | |
1064 | GIMPLE. | |
1065 | ||
1066 | The function is assumed to be reachable and have address taken (so no | |
1067 | API breaking optimizations are performed on it). | |
1068 | ||
1069 | Main work done by this function is to enqueue the function for later | |
1070 | processing to avoid need the passes to be re-entrant. */ | |
1071 | static void add_new_function (tree fndecl, bool lowered); | |
1072 | ||
1073 | /* Return callgraph node for given symbol and check it is a function. */ | |
1074 | static inline cgraph_node *get (const_tree decl) | |
1075 | { | |
1076 | gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL); | |
1077 | return dyn_cast <cgraph_node *> (symtab_node::get (decl)); | |
1078 | } | |
1079 | ||
1080 | /* Return cgraph node assigned to DECL. Create new one when needed. */ | |
1081 | static cgraph_node * create (tree decl); | |
1082 | ||
1083 | /* Allocate new callgraph node and insert it into basic data structures. */ | |
1084 | static cgraph_node * create_empty (void); | |
1085 | ||
1086 | /* Try to find a call graph node for declaration DECL and if it does not | |
1087 | exist or if it corresponds to an inline clone, create a new one. */ | |
1088 | static cgraph_node * get_create (tree); | |
1089 | ||
1090 | /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME. | |
1091 | Return NULL if there's no such node. */ | |
1092 | static cgraph_node *get_for_asmname (tree asmname); | |
1093 | ||
1094 | /* Attempt to mark ALIAS as an alias to DECL. Return alias node if | |
1095 | successful and NULL otherwise. | |
1096 | Same body aliases are output whenever the body of DECL is output, | |
1097 | and cgraph_node::get (ALIAS) transparently | |
1098 | returns cgraph_node::get (DECL). */ | |
1099 | static cgraph_node * create_same_body_alias (tree alias, tree decl); | |
1100 | ||
1101 | /* Worker for cgraph_can_remove_if_no_direct_calls_p. */ | |
1102 | static bool used_from_object_file_p_worker (cgraph_node *node, void *) | |
1103 | { | |
1104 | return node->used_from_object_file_p (); | |
1105 | } | |
1106 | ||
1107 | /* Return true when cgraph_node can not be local. | |
1108 | Worker for cgraph_local_node_p. */ | |
1109 | static bool non_local_p (cgraph_node *node, void *); | |
1110 | ||
1111 | /* Verify whole cgraph structure. */ | |
1112 | static void DEBUG_FUNCTION verify_cgraph_nodes (void); | |
1113 | ||
1114 | /* Worker to bring NODE local. */ | |
1115 | static bool make_local (cgraph_node *node, void *); | |
1116 | ||
1117 | /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing | |
1118 | the function body is associated | |
1119 | with (not necessarily cgraph_node (DECL). */ | |
1120 | static cgraph_node *create_alias (tree alias, tree target); | |
1121 | ||
1122 | static cgraph_edge * create_edge (cgraph_node *caller, cgraph_node *callee, | |
1123 | gimple call_stmt, gcov_type count, | |
1124 | int freq, | |
1125 | bool indir_unknown_callee); | |
1126 | ||
1c4a429a JH |
1127 | struct cgraph_edge *callees; |
1128 | struct cgraph_edge *callers; | |
e33c6cd6 MJ |
1129 | /* List of edges representing indirect calls with a yet undetermined |
1130 | callee. */ | |
1131 | struct cgraph_edge *indirect_calls; | |
1c4a429a | 1132 | /* For nested functions points to function the node is nested in. */ |
d52f5295 | 1133 | cgraph_node *origin; |
1c4a429a | 1134 | /* Points to first nested function, if any. */ |
d52f5295 | 1135 | cgraph_node *nested; |
1c4a429a | 1136 | /* Pointer to the next function with same origin, if any. */ |
d52f5295 | 1137 | cgraph_node *next_nested; |
18c6ada9 | 1138 | /* Pointer to the next clone. */ |
d52f5295 ML |
1139 | cgraph_node *next_sibling_clone; |
1140 | cgraph_node *prev_sibling_clone; | |
1141 | cgraph_node *clones; | |
1142 | cgraph_node *clone_of; | |
70d539ce JH |
1143 | /* For functions with many calls sites it holds map from call expression |
1144 | to the edge to speed up cgraph_edge function. */ | |
1145 | htab_t GTY((param_is (struct cgraph_edge))) call_site_hash; | |
97ba0040 JH |
1146 | /* Declaration node used to be clone of. */ |
1147 | tree former_clone_of; | |
c22cacf3 | 1148 | |
0136f8f0 AH |
1149 | /* If this is a SIMD clone, this points to the SIMD specific |
1150 | information for it. */ | |
1151 | struct cgraph_simd_clone *simdclone; | |
1152 | /* If this function has SIMD clones, this points to the first clone. */ | |
d52f5295 | 1153 | cgraph_node *simd_clones; |
0136f8f0 | 1154 | |
0e3776db JH |
1155 | /* Interprocedural passes scheduled to have their transform functions |
1156 | applied next time we execute local pass on them. We maintain it | |
1157 | per-function in order to allow IPA passes to introduce new functions. */ | |
9771b263 | 1158 | vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply; |
0e3776db | 1159 | |
95c755e9 JH |
1160 | struct cgraph_local_info local; |
1161 | struct cgraph_global_info global; | |
1162 | struct cgraph_rtl_info rtl; | |
9187e02d | 1163 | struct cgraph_clone_info clone; |
6744a6ab | 1164 | struct cgraph_thunk_info thunk; |
c22cacf3 | 1165 | |
e42922b1 JH |
1166 | /* Expected number of executions: calculated in profile.c. */ |
1167 | gcov_type count; | |
db0bf14f JH |
1168 | /* How to scale counts at materialization time; used to merge |
1169 | LTO units with different number of profile runs. */ | |
1170 | int count_materialization_scale; | |
95c755e9 JH |
1171 | /* Unique id of the node. */ |
1172 | int uid; | |
2fa3d31b JH |
1173 | /* ID assigned by the profiling. */ |
1174 | unsigned int profile_id; | |
86ce5d2f ML |
1175 | /* Time profiler: first run of function. */ |
1176 | int tp_first_run; | |
3691626c | 1177 | |
6b20f353 DS |
1178 | /* Set when decl is an abstract function pointed to by the |
1179 | ABSTRACT_DECL_ORIGIN of a reachable function. */ | |
c0c123ef | 1180 | unsigned used_as_abstract_origin : 1; |
50674e96 | 1181 | /* Set once the function is lowered (i.e. its CFG is built). */ |
b4e19405 | 1182 | unsigned lowered : 1; |
25c84396 RH |
1183 | /* Set once the function has been instantiated and its callee |
1184 | lists created. */ | |
257eb6e3 | 1185 | unsigned process : 1; |
5fefcf92 JH |
1186 | /* How commonly executed the node is. Initialized during branch |
1187 | probabilities pass. */ | |
1188 | ENUM_BITFIELD (node_frequency) frequency : 2; | |
844db5d0 JH |
1189 | /* True when function can only be called at startup (from static ctor). */ |
1190 | unsigned only_called_at_startup : 1; | |
1191 | /* True when function can only be called at startup (from static dtor). */ | |
1192 | unsigned only_called_at_exit : 1; | |
0a35513e AH |
1193 | /* True when function is the transactional clone of a function which |
1194 | is called only from inside transactions. */ | |
1195 | /* ?? We should be able to remove this. We have enough bits in | |
1196 | cgraph to calculate it. */ | |
1197 | unsigned tm_clone : 1; | |
3649b9b7 ST |
1198 | /* True if this decl is a dispatcher for function versions. */ |
1199 | unsigned dispatcher_function : 1; | |
1f26ac87 JM |
1200 | /* True if this decl calls a COMDAT-local function. This is set up in |
1201 | compute_inline_parameters and inline_call. */ | |
1202 | unsigned calls_comdat_local : 1; | |
3649b9b7 ST |
1203 | }; |
1204 | ||
fed5ae11 DK |
1205 | /* A cgraph node set is a collection of cgraph nodes. A cgraph node |
1206 | can appear in multiple sets. */ | |
1cb1a99f | 1207 | struct cgraph_node_set_def |
fed5ae11 | 1208 | { |
b787e7a2 | 1209 | hash_map<cgraph_node *, size_t> *map; |
d52f5295 | 1210 | vec<cgraph_node *> nodes; |
fed5ae11 DK |
1211 | }; |
1212 | ||
d52f5295 ML |
1213 | typedef cgraph_node_set_def *cgraph_node_set; |
1214 | typedef struct varpool_node_set_def *varpool_node_set; | |
2942c502 | 1215 | |
d52f5295 | 1216 | class varpool_node; |
2942c502 JH |
1217 | |
1218 | /* A varpool node set is a collection of varpool nodes. A varpool node | |
1219 | can appear in multiple sets. */ | |
1cb1a99f | 1220 | struct varpool_node_set_def |
2942c502 | 1221 | { |
b787e7a2 | 1222 | hash_map<varpool_node *, size_t> * map; |
d52f5295 | 1223 | vec<varpool_node *> nodes; |
2942c502 JH |
1224 | }; |
1225 | ||
fed5ae11 | 1226 | /* Iterator structure for cgraph node sets. */ |
84562394 | 1227 | struct cgraph_node_set_iterator |
fed5ae11 DK |
1228 | { |
1229 | cgraph_node_set set; | |
1230 | unsigned index; | |
84562394 | 1231 | }; |
fed5ae11 | 1232 | |
2942c502 | 1233 | /* Iterator structure for varpool node sets. */ |
84562394 | 1234 | struct varpool_node_set_iterator |
2942c502 JH |
1235 | { |
1236 | varpool_node_set set; | |
1237 | unsigned index; | |
84562394 | 1238 | }; |
2942c502 | 1239 | |
e33c6cd6 MJ |
1240 | /* Structure containing additional information about an indirect call. */ |
1241 | ||
1242 | struct GTY(()) cgraph_indirect_call_info | |
1243 | { | |
8b7773a4 MJ |
1244 | /* When polymorphic is set, this field contains offset where the object which |
1245 | was actually used in the polymorphic resides within a larger structure. | |
1246 | If agg_contents is set, the field contains the offset within the aggregate | |
1247 | from which the address to call was loaded. */ | |
3339f0bc | 1248 | HOST_WIDE_INT offset, speculative_offset; |
b258210c MJ |
1249 | /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */ |
1250 | HOST_WIDE_INT otr_token; | |
1251 | /* Type of the object from OBJ_TYPE_REF_OBJECT. */ | |
3339f0bc | 1252 | tree otr_type, outer_type, speculative_outer_type; |
e33c6cd6 MJ |
1253 | /* Index of the parameter that is called. */ |
1254 | int param_index; | |
5f902d76 JH |
1255 | /* ECF flags determined from the caller. */ |
1256 | int ecf_flags; | |
634ab819 JH |
1257 | /* Profile_id of common target obtrained from profile. */ |
1258 | int common_target_id; | |
1259 | /* Probability that call will land in function with COMMON_TARGET_ID. */ | |
1260 | int common_target_probability; | |
b258210c MJ |
1261 | |
1262 | /* Set when the call is a virtual call with the parameter being the | |
1263 | associated object pointer rather than a simple direct call. */ | |
1264 | unsigned polymorphic : 1; | |
8b7773a4 MJ |
1265 | /* Set when the call is a call of a pointer loaded from contents of an |
1266 | aggregate at offset. */ | |
1267 | unsigned agg_contents : 1; | |
c13bc3d9 MJ |
1268 | /* Set when this is a call through a member pointer. */ |
1269 | unsigned member_ptr : 1; | |
8b7773a4 MJ |
1270 | /* When the previous bit is set, this one determines whether the destination |
1271 | is loaded from a parameter passed by reference. */ | |
1272 | unsigned by_ref : 1; | |
68377e53 JH |
1273 | unsigned int maybe_in_construction : 1; |
1274 | unsigned int maybe_derived_type : 1; | |
3339f0bc | 1275 | unsigned int speculative_maybe_derived_type : 1; |
e33c6cd6 MJ |
1276 | }; |
1277 | ||
d1b38208 | 1278 | struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge { |
6009ee7b MJ |
1279 | /* Expected number of executions: calculated in profile.c. */ |
1280 | gcov_type count; | |
d52f5295 ML |
1281 | cgraph_node *caller; |
1282 | cgraph_node *callee; | |
2563c224 | 1283 | struct cgraph_edge *prev_caller; |
1c4a429a | 1284 | struct cgraph_edge *next_caller; |
2563c224 | 1285 | struct cgraph_edge *prev_callee; |
1c4a429a | 1286 | struct cgraph_edge *next_callee; |
726a989a | 1287 | gimple call_stmt; |
e33c6cd6 MJ |
1288 | /* Additional information about an indirect call. Not cleared when an edge |
1289 | becomes direct. */ | |
1290 | struct cgraph_indirect_call_info *indirect_info; | |
18c6ada9 | 1291 | PTR GTY ((skip (""))) aux; |
61a05df1 JH |
1292 | /* When equal to CIF_OK, inline this call. Otherwise, points to the |
1293 | explanation why function was not inlined. */ | |
84562394 | 1294 | enum cgraph_inline_failed_t inline_failed; |
6009ee7b MJ |
1295 | /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt |
1296 | when the function is serialized in. */ | |
1297 | unsigned int lto_stmt_uid; | |
b8698a0f | 1298 | /* Expected frequency of executions within the function. |
45a80bb9 JH |
1299 | When set to CGRAPH_FREQ_BASE, the edge is expected to be called once |
1300 | per function call. The range is 0 to CGRAPH_FREQ_MAX. */ | |
1301 | int frequency; | |
6009ee7b MJ |
1302 | /* Unique id of the edge. */ |
1303 | int uid; | |
e33c6cd6 MJ |
1304 | /* Whether this edge was made direct by indirect inlining. */ |
1305 | unsigned int indirect_inlining_edge : 1; | |
1306 | /* Whether this edge describes an indirect call with an undetermined | |
1307 | callee. */ | |
1308 | unsigned int indirect_unknown_callee : 1; | |
1309 | /* Whether this edge is still a dangling */ | |
d7f09764 DN |
1310 | /* True if the corresponding CALL stmt cannot be inlined. */ |
1311 | unsigned int call_stmt_cannot_inline_p : 1; | |
2505c5ed JH |
1312 | /* Can this call throw externally? */ |
1313 | unsigned int can_throw_external : 1; | |
042ae7d2 JH |
1314 | /* Edges with SPECULATIVE flag represents indirect calls that was |
1315 | speculatively turned into direct (i.e. by profile feedback). | |
1316 | The final code sequence will have form: | |
1317 | ||
1318 | if (call_target == expected_fn) | |
1319 | expected_fn (); | |
1320 | else | |
1321 | call_target (); | |
1322 | ||
1323 | Every speculative call is represented by three components attached | |
1324 | to a same call statement: | |
1325 | 1) a direct call (to expected_fn) | |
1326 | 2) an indirect call (to call_target) | |
1327 | 3) a IPA_REF_ADDR refrence to expected_fn. | |
1328 | ||
1329 | Optimizers may later redirect direct call to clone, so 1) and 3) | |
1330 | do not need to necesarily agree with destination. */ | |
1331 | unsigned int speculative : 1; | |
1c4a429a JH |
1332 | }; |
1333 | ||
45a80bb9 JH |
1334 | #define CGRAPH_FREQ_BASE 1000 |
1335 | #define CGRAPH_FREQ_MAX 100000 | |
1336 | ||
8a4a83ed JH |
1337 | /* The varpool data structure. |
1338 | Each static variable decl has assigned varpool_node. */ | |
e69529cd | 1339 | |
5e20cdc9 | 1340 | class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node { |
a3bfa8b8 | 1341 | public: |
9041d2e6 ML |
1342 | /* Dump given varpool node to F. */ |
1343 | void dump (FILE *f); | |
1344 | ||
1345 | /* Dump given varpool node to stderr. */ | |
1346 | void DEBUG_FUNCTION debug (void); | |
1347 | ||
1348 | /* Remove variable from symbol table. */ | |
1349 | void remove (void); | |
1350 | ||
1351 | /* Remove node initializer when it is no longer needed. */ | |
1352 | void remove_initializer (void); | |
1353 | ||
1354 | void analyze (void); | |
1355 | ||
1356 | /* Return variable availability. */ | |
1357 | availability get_availability (void); | |
1358 | ||
1359 | /* When doing LTO, read variable's constructor from disk if | |
1360 | it is not already present. */ | |
1361 | tree get_constructor (void); | |
1362 | ||
1363 | /* Return true if variable has constructor that can be used for folding. */ | |
1364 | bool ctor_useable_for_folding_p (void); | |
1365 | ||
1366 | /* For given variable pool node, walk the alias chain to return the function | |
1367 | the variable is alias of. Do not walk through thunks. | |
1368 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ | |
1369 | inline varpool_node *ultimate_alias_target | |
1370 | (availability *availability = NULL); | |
1371 | ||
1372 | /* Return node that alias is aliasing. */ | |
1373 | inline varpool_node *get_alias_target (void); | |
1374 | ||
1375 | /* Output one variable, if necessary. Return whether we output it. */ | |
1376 | bool assemble_decl (void); | |
1377 | ||
1378 | /* For variables in named sections make sure get_variable_section | |
1379 | is called before we switch to those sections. Then section | |
1380 | conflicts between read-only and read-only requiring relocations | |
1381 | sections can be resolved. */ | |
1382 | void finalize_named_section_flags (void); | |
1383 | ||
1384 | /* Call calback on varpool symbol and aliases associated to varpool symbol. | |
1385 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are | |
1386 | skipped. */ | |
1387 | bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *), | |
1388 | void *data, | |
1389 | bool include_overwritable); | |
1390 | ||
1391 | /* Return true when variable should be considered externally visible. */ | |
1392 | bool externally_visible_p (void); | |
1393 | ||
1394 | /* Return true when all references to variable must be visible | |
1395 | in ipa_ref_list. | |
1396 | i.e. if the variable is not externally visible or not used in some magic | |
1397 | way (asm statement or such). | |
1398 | The magic uses are all summarized in force_output flag. */ | |
1399 | inline bool all_refs_explicit_p (); | |
1400 | ||
1401 | /* Return true when variable can be removed from variable pool | |
1402 | if all direct calls are eliminated. */ | |
1403 | inline bool can_remove_if_no_refs_p (void); | |
1404 | ||
1405 | /* Return varpool node for given symbol and check it is a function. */ | |
1406 | static inline varpool_node *get (const_tree decl); | |
1407 | ||
1408 | /* Mark DECL as finalized. By finalizing the declaration, frontend instruct | |
1409 | the middle end to output the variable to asm file, if needed or externally | |
1410 | visible. */ | |
1411 | static void finalize_decl (tree decl); | |
1412 | ||
1413 | /* Output all variables enqueued to be assembled. */ | |
1414 | static bool output_variables (void); | |
1415 | ||
1416 | /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful. | |
1417 | Extra name aliases are output whenever DECL is output. */ | |
1418 | static varpool_node * create_extra_name_alias (tree alias, tree decl); | |
1419 | ||
1420 | /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful. | |
1421 | Extra name aliases are output whenever DECL is output. */ | |
1422 | static varpool_node * create_alias (tree, tree); | |
1423 | ||
1424 | /* Dump the variable pool to F. */ | |
1425 | static void dump_varpool (FILE *f); | |
1426 | ||
1427 | /* Dump the variable pool to stderr. */ | |
1428 | static void DEBUG_FUNCTION debug_varpool (void); | |
1429 | ||
1430 | /* Allocate new callgraph node and insert it into basic data structures. */ | |
1431 | static varpool_node *create_empty (void); | |
1432 | ||
1433 | /* Return varpool node assigned to DECL. Create new one when needed. */ | |
1434 | static varpool_node *get_create (tree decl); | |
1435 | ||
1436 | /* Given an assembler name, lookup node. */ | |
1437 | static varpool_node *get_for_asmname (tree asmname); | |
1438 | ||
6b02a499 | 1439 | /* Set when variable is scheduled to be assembled. */ |
b4e19405 | 1440 | unsigned output : 1; |
eb1d8159 | 1441 | |
59b36ecf JJ |
1442 | /* Set if the variable is dynamically initialized, except for |
1443 | function local statics. */ | |
1444 | unsigned dynamically_initialized : 1; | |
56363ffd JH |
1445 | |
1446 | ENUM_BITFIELD(tls_model) tls_model : 3; | |
eb6a09a7 JH |
1447 | |
1448 | /* Set if the variable is known to be used by single function only. | |
1449 | This is computed by ipa_signle_use pass and used by late optimizations | |
1450 | in places where optimization would be valid for local static variable | |
1451 | if we did not do any inter-procedural code movement. */ | |
1452 | unsigned used_by_single_function : 1; | |
d52f5295 | 1453 | |
9041d2e6 ML |
1454 | private: |
1455 | /* Assemble thunks and aliases associated to varpool node. */ | |
1456 | void assemble_aliases (void); | |
e69529cd JH |
1457 | }; |
1458 | ||
65d630d4 | 1459 | /* Every top level asm statement is put into a asm_node. */ |
474eccc6 | 1460 | |
65d630d4 | 1461 | struct GTY(()) asm_node { |
474eccc6 | 1462 | /* Next asm node. */ |
65d630d4 | 1463 | struct asm_node *next; |
474eccc6 ILT |
1464 | /* String for this asm node. */ |
1465 | tree asm_str; | |
1466 | /* Ordering of all cgraph nodes. */ | |
1467 | int order; | |
1468 | }; | |
1469 | ||
5d59b5e1 LC |
1470 | /* Report whether or not THIS symtab node is a function, aka cgraph_node. */ |
1471 | ||
1472 | template <> | |
1473 | template <> | |
1474 | inline bool | |
7de90a6c | 1475 | is_a_helper <cgraph_node *>::test (symtab_node *p) |
5d59b5e1 | 1476 | { |
d52f5295 | 1477 | return p && p->type == SYMTAB_FUNCTION; |
5d59b5e1 LC |
1478 | } |
1479 | ||
1480 | /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */ | |
1481 | ||
1482 | template <> | |
1483 | template <> | |
1484 | inline bool | |
7de90a6c | 1485 | is_a_helper <varpool_node *>::test (symtab_node *p) |
5d59b5e1 | 1486 | { |
d52f5295 | 1487 | return p && p->type == SYMTAB_VARIABLE; |
5d59b5e1 LC |
1488 | } |
1489 | ||
5e20cdc9 | 1490 | extern GTY(()) symtab_node *symtab_nodes; |
ed2df68b | 1491 | extern GTY(()) int cgraph_n_nodes; |
b58b1157 | 1492 | extern GTY(()) int cgraph_max_uid; |
9088c1cc | 1493 | extern GTY(()) int cgraph_edge_max_uid; |
dafc5b82 | 1494 | extern bool cgraph_global_info_ready; |
f45e0ad1 JH |
1495 | enum cgraph_state |
1496 | { | |
66058468 JH |
1497 | /* Frontend is parsing and finalizing functions. */ |
1498 | CGRAPH_STATE_PARSING, | |
f45e0ad1 JH |
1499 | /* Callgraph is being constructed. It is safe to add new functions. */ |
1500 | CGRAPH_STATE_CONSTRUCTION, | |
ca0f62a8 JH |
1501 | /* Callgraph is being at LTO time. */ |
1502 | CGRAPH_LTO_STREAMING, | |
f45e0ad1 JH |
1503 | /* Callgraph is built and IPA passes are being run. */ |
1504 | CGRAPH_STATE_IPA, | |
7a388ee4 JH |
1505 | /* Callgraph is built and all functions are transformed to SSA form. */ |
1506 | CGRAPH_STATE_IPA_SSA, | |
f45e0ad1 JH |
1507 | /* Functions are now ordered and being passed to RTL expanders. */ |
1508 | CGRAPH_STATE_EXPANSION, | |
1509 | /* All cgraph expansion is done. */ | |
1510 | CGRAPH_STATE_FINISHED | |
1511 | }; | |
1512 | extern enum cgraph_state cgraph_state; | |
e7d6beb0 | 1513 | extern bool cgraph_function_flags_ready; |
31acf1bb | 1514 | extern vec<cgraph_node *> cgraph_new_nodes; |
1c4a429a | 1515 | |
65d630d4 | 1516 | extern GTY(()) struct asm_node *asm_nodes; |
2aae7680 | 1517 | extern GTY(()) int symtab_order; |
40a7fe1e | 1518 | extern bool cpp_implicit_aliases_done; |
e69529cd | 1519 | |
2aae7680 | 1520 | /* In symtab.c */ |
5e20cdc9 | 1521 | symtab_node *symtab_node_for_asm (const_tree asmname); |
2aae7680 | 1522 | |
1c4a429a | 1523 | /* In cgraph.c */ |
12123452 | 1524 | void release_function_body (tree); |
ce47fda3 | 1525 | struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void); |
d52f5295 ML |
1526 | void cgraph_remove_edge (struct cgraph_edge *); |
1527 | ||
042ae7d2 | 1528 | void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true); |
4b685e14 | 1529 | void cgraph_update_edges_for_call_stmt (gimple, tree, gimple); |
439f7bc3 AJ |
1530 | struct cgraph_local_info *cgraph_local_info (tree); |
1531 | struct cgraph_global_info *cgraph_global_info (tree); | |
1532 | struct cgraph_rtl_info *cgraph_rtl_info (tree); | |
66a20fc2 JH |
1533 | void cgraph_call_edge_duplication_hooks (struct cgraph_edge *, |
1534 | struct cgraph_edge *); | |
1c4a429a | 1535 | |
1bb17c21 | 1536 | bool cgraph_function_possibly_inlined_p (tree); |
d52f5295 ML |
1537 | bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *); |
1538 | void cgraph_redirect_edge_callee (struct cgraph_edge *, cgraph_node *); | |
1539 | struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, | |
1540 | cgraph_node *); | |
1bb17c21 | 1541 | |
61a05df1 | 1542 | const char* cgraph_inline_failed_string (cgraph_inline_failed_t); |
1cf11770 | 1543 | cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t); |
6b02a499 | 1544 | |
be330ed4 | 1545 | bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution); |
9088c1cc | 1546 | typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *); |
d52f5295 | 1547 | typedef void (*cgraph_node_hook)(cgraph_node *, void *); |
2c8326a5 | 1548 | typedef void (*varpool_node_hook)(varpool_node *, void *); |
9088c1cc MJ |
1549 | typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *, |
1550 | void *); | |
d52f5295 | 1551 | typedef void (*cgraph_2node_hook)(cgraph_node *, cgraph_node *, |
9088c1cc MJ |
1552 | void *); |
1553 | struct cgraph_edge_hook_list; | |
1554 | struct cgraph_node_hook_list; | |
26e5b0fd | 1555 | struct varpool_node_hook_list; |
9088c1cc MJ |
1556 | struct cgraph_2edge_hook_list; |
1557 | struct cgraph_2node_hook_list; | |
1558 | struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *); | |
1559 | void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *); | |
d52f5295 | 1560 | cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook, |
9088c1cc | 1561 | void *); |
d52f5295 | 1562 | void cgraph_remove_node_removal_hook (cgraph_node_hook_list *); |
26e5b0fd JH |
1563 | struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook, |
1564 | void *); | |
1565 | void varpool_remove_node_removal_hook (struct varpool_node_hook_list *); | |
d52f5295 | 1566 | cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook, |
129a37fc | 1567 | void *); |
d52f5295 | 1568 | void cgraph_remove_function_insertion_hook (cgraph_node_hook_list *); |
26e5b0fd JH |
1569 | struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook, |
1570 | void *); | |
1571 | void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *); | |
9088c1cc MJ |
1572 | struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *); |
1573 | void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *); | |
1574 | struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *); | |
1575 | void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *); | |
8132a837 | 1576 | gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *); |
09ce3660 | 1577 | struct cgraph_edge * |
042ae7d2 | 1578 | cgraph_turn_edge_to_speculative (struct cgraph_edge *, |
d52f5295 | 1579 | cgraph_node *, |
042ae7d2 JH |
1580 | gcov_type, int); |
1581 | void cgraph_speculative_call_info (struct cgraph_edge *, | |
1582 | struct cgraph_edge *&, | |
1583 | struct cgraph_edge *&, | |
1584 | struct ipa_ref *&); | |
4484a35a | 1585 | extern bool gimple_check_call_matching_types (gimple, tree, bool); |
9c8305f8 JH |
1586 | |
1587 | /* In cgraphunit.c */ | |
65d630d4 | 1588 | struct asm_node *add_asm_node (tree); |
9c8305f8 JH |
1589 | extern FILE *cgraph_dump_file; |
1590 | void cgraph_finalize_function (tree, bool); | |
65d630d4 JH |
1591 | void finalize_compilation_unit (void); |
1592 | void compile (void); | |
9c8305f8 | 1593 | void init_cgraph (void); |
b4d05578 | 1594 | void cgraph_process_new_functions (void); |
66a20fc2 | 1595 | void cgraph_process_same_body_aliases (void); |
3649b9b7 ST |
1596 | /* Initialize datastructures so DECL is a function in lowered gimple form. |
1597 | IN_SSA is true if the gimple is in SSA. */ | |
e70670cf | 1598 | basic_block init_lowered_empty_function (tree, bool); |
66a20fc2 JH |
1599 | |
1600 | /* In cgraphclones.c */ | |
1601 | ||
1602 | struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *, | |
d52f5295 | 1603 | cgraph_node *, gimple, |
66a20fc2 | 1604 | unsigned, gcov_type, int, bool); |
66a20fc2 | 1605 | tree clone_function_name (tree decl, const char *); |
d52f5295 | 1606 | |
66a20fc2 | 1607 | void cgraph_materialize_all_clones (void); |
d52f5295 | 1608 | void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *, |
9c8305f8 | 1609 | bool, bitmap, bool, bitmap, basic_block); |
09ce3660 | 1610 | struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree); |
9c8305f8 | 1611 | |
917948d3 ZD |
1612 | /* In cgraphbuild.c */ |
1613 | unsigned int rebuild_cgraph_edges (void); | |
99b766fc | 1614 | void cgraph_rebuild_references (void); |
9187e02d | 1615 | int compute_call_stmt_bb_frequency (tree, basic_block bb); |
9c8305f8 | 1616 | void record_references_in_initializer (tree, bool); |
917948d3 | 1617 | |
ca31b95f | 1618 | /* In ipa.c */ |
04142cc3 | 1619 | bool symtab_remove_unreachable_nodes (bool, FILE *); |
9c8305f8 | 1620 | void cgraph_build_static_cdtor (char which, tree body, int priority); |
4a444e58 | 1621 | void ipa_discover_readonly_nonaddressable_vars (void); |
ca31b95f | 1622 | |
fed5ae11 | 1623 | /* In predict.c */ |
ca30a539 JH |
1624 | bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e); |
1625 | ||
8a4a83ed | 1626 | /* In varpool.c */ |
b34fd25c | 1627 | void varpool_reset_queue (void); |
6a6dac52 | 1628 | tree ctor_for_folding (tree); |
38877e98 | 1629 | void varpool_add_new_variable (tree); |
b5493fb2 | 1630 | void symtab_initialize_asm_name_hash (void); |
5e20cdc9 | 1631 | void symtab_prevail_in_asm_name_hash (symtab_node *node); |
8a4a83ed | 1632 | |
d8a2d370 DN |
1633 | /* In cgraph.c */ |
1634 | extern void change_decl_assembler_name (tree, tree); | |
68e56cc4 | 1635 | |
d52f5295 ML |
1636 | /* Return true when the symbol is real symbol, i.e. it is not inline clone |
1637 | or abstract function kept for debug info purposes only. */ | |
1638 | inline bool | |
1639 | symtab_node::real_symbol_p (void) | |
1640 | { | |
1641 | cgraph_node *cnode; | |
1642 | ||
1643 | if (DECL_ABSTRACT (decl)) | |
1644 | return false; | |
1645 | if (!is_a <cgraph_node *> (this)) | |
1646 | return true; | |
1647 | cnode = dyn_cast <cgraph_node *> (this); | |
1648 | if (cnode->global.inlined_to) | |
1649 | return false; | |
1650 | return true; | |
1651 | } | |
1652 | ||
89330618 JH |
1653 | /* Return true if DECL should have entry in symbol table if used. |
1654 | Those are functions and static & external veriables*/ | |
1655 | ||
0241e486 | 1656 | static inline bool |
89330618 JH |
1657 | decl_in_symtab_p (const_tree decl) |
1658 | { | |
1659 | return (TREE_CODE (decl) == FUNCTION_DECL | |
1660 | || (TREE_CODE (decl) == VAR_DECL | |
1661 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))); | |
1662 | } | |
1663 | ||
d52f5295 ML |
1664 | inline bool |
1665 | symtab_node::in_same_comdat_group_p (symtab_node *target) | |
aede2c10 | 1666 | { |
d52f5295 | 1667 | symtab_node *source = this; |
aede2c10 | 1668 | |
d52f5295 ML |
1669 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (target)) |
1670 | { | |
1671 | if (cn->global.inlined_to) | |
1672 | source = cn->global.inlined_to; | |
1673 | } | |
1674 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (target)) | |
1675 | { | |
1676 | if (cn->global.inlined_to) | |
1677 | target = cn->global.inlined_to; | |
1678 | } | |
1679 | ||
1680 | return source->get_comdat_group () == target->get_comdat_group (); | |
1f00098b JH |
1681 | } |
1682 | ||
d52f5295 ML |
1683 | /* Return node that alias is aliasing. */ |
1684 | ||
1685 | inline symtab_node * | |
1686 | symtab_node::get_alias_target (void) | |
1f00098b | 1687 | { |
d52f5295 ML |
1688 | struct ipa_ref *ref = NULL; |
1689 | iterate_reference (0, ref); | |
1690 | gcc_checking_assert (ref->use == IPA_REF_ALIAS); | |
1691 | return ref->referred; | |
1f00098b JH |
1692 | } |
1693 | ||
d52f5295 ML |
1694 | /* Return next reachable static symbol with initializer after the node. */ |
1695 | inline symtab_node * | |
1696 | symtab_node::next_defined_symbol (void) | |
1ab24192 | 1697 | { |
d52f5295 ML |
1698 | symtab_node *node1 = next; |
1699 | ||
1700 | for (; node1; node1 = node1->next) | |
1701 | if (node1->definition) | |
1702 | return node1; | |
1703 | ||
1704 | return NULL; | |
1ab24192 JH |
1705 | } |
1706 | ||
1707 | /* Return varpool node for given symbol and check it is a function. */ | |
9041d2e6 ML |
1708 | inline varpool_node * |
1709 | varpool_node::get (const_tree decl) | |
1ab24192 JH |
1710 | { |
1711 | gcc_checking_assert (TREE_CODE (decl) == VAR_DECL); | |
d52f5295 | 1712 | return dyn_cast<varpool_node *> (symtab_node::get (decl)); |
1ab24192 JH |
1713 | } |
1714 | ||
1715 | /* Walk all symbols. */ | |
1716 | #define FOR_EACH_SYMBOL(node) \ | |
67348ccc | 1717 | for ((node) = symtab_nodes; (node); (node) = (node)->next) |
1f00098b | 1718 | |
d6d229c6 JH |
1719 | /* Return first static symbol with definition. */ |
1720 | static inline symtab_node * | |
1721 | symtab_first_defined_symbol (void) | |
1722 | { | |
1723 | symtab_node *node; | |
1724 | ||
1725 | for (node = symtab_nodes; node; node = node->next) | |
1726 | if (node->definition) | |
1727 | return node; | |
1728 | ||
1729 | return NULL; | |
1730 | } | |
1731 | ||
d6d229c6 JH |
1732 | /* Walk all symbols with definitions in current unit. */ |
1733 | #define FOR_EACH_DEFINED_SYMBOL(node) \ | |
1734 | for ((node) = symtab_first_defined_symbol (); (node); \ | |
d52f5295 | 1735 | (node) = node->next_defined_symbol ()) |
66058468 JH |
1736 | |
1737 | /* Return first variable. */ | |
2c8326a5 | 1738 | static inline varpool_node * |
66058468 JH |
1739 | varpool_first_variable (void) |
1740 | { | |
5e20cdc9 | 1741 | symtab_node *node; |
67348ccc | 1742 | for (node = symtab_nodes; node; node = node->next) |
7de90a6c | 1743 | if (varpool_node *vnode = dyn_cast <varpool_node *> (node)) |
5d59b5e1 | 1744 | return vnode; |
66058468 JH |
1745 | return NULL; |
1746 | } | |
1747 | ||
1748 | /* Return next variable after NODE. */ | |
2c8326a5 OE |
1749 | static inline varpool_node * |
1750 | varpool_next_variable (varpool_node *node) | |
66058468 | 1751 | { |
5e20cdc9 | 1752 | symtab_node *node1 = node->next; |
67348ccc | 1753 | for (; node1; node1 = node1->next) |
7de90a6c | 1754 | if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1)) |
5d59b5e1 | 1755 | return vnode1; |
66058468 JH |
1756 | return NULL; |
1757 | } | |
1758 | /* Walk all variables. */ | |
1759 | #define FOR_EACH_VARIABLE(node) \ | |
1760 | for ((node) = varpool_first_variable (); \ | |
1761 | (node); \ | |
1762 | (node) = varpool_next_variable ((node))) | |
1763 | ||
d6d229c6 | 1764 | /* Return first static variable with initializer. */ |
2c8326a5 | 1765 | static inline varpool_node * |
68e56cc4 JH |
1766 | varpool_first_static_initializer (void) |
1767 | { | |
5e20cdc9 | 1768 | symtab_node *node; |
67348ccc | 1769 | for (node = symtab_nodes; node; node = node->next) |
68e56cc4 | 1770 | { |
7de90a6c | 1771 | varpool_node *vnode = dyn_cast <varpool_node *> (node); |
67348ccc | 1772 | if (vnode && DECL_INITIAL (node->decl)) |
5d59b5e1 | 1773 | return vnode; |
68e56cc4 JH |
1774 | } |
1775 | return NULL; | |
1776 | } | |
1777 | ||
d6d229c6 | 1778 | /* Return next static variable with initializer after NODE. */ |
2c8326a5 OE |
1779 | static inline varpool_node * |
1780 | varpool_next_static_initializer (varpool_node *node) | |
68e56cc4 | 1781 | { |
5e20cdc9 | 1782 | symtab_node *node1 = node->next; |
67348ccc | 1783 | for (; node1; node1 = node1->next) |
68e56cc4 | 1784 | { |
7de90a6c | 1785 | varpool_node *vnode1 = dyn_cast <varpool_node *> (node1); |
67348ccc | 1786 | if (vnode1 && DECL_INITIAL (node1->decl)) |
5d59b5e1 | 1787 | return vnode1; |
68e56cc4 JH |
1788 | } |
1789 | return NULL; | |
1790 | } | |
1791 | ||
1792 | /* Walk all static variables with initializer set. */ | |
1793 | #define FOR_EACH_STATIC_INITIALIZER(node) \ | |
1794 | for ((node) = varpool_first_static_initializer (); (node); \ | |
1795 | (node) = varpool_next_static_initializer (node)) | |
2aae7680 | 1796 | |
d6d229c6 | 1797 | /* Return first static variable with definition. */ |
2c8326a5 | 1798 | static inline varpool_node * |
66058468 | 1799 | varpool_first_defined_variable (void) |
2aae7680 | 1800 | { |
5e20cdc9 | 1801 | symtab_node *node; |
67348ccc | 1802 | for (node = symtab_nodes; node; node = node->next) |
2aae7680 | 1803 | { |
7de90a6c | 1804 | varpool_node *vnode = dyn_cast <varpool_node *> (node); |
67348ccc | 1805 | if (vnode && vnode->definition) |
5d59b5e1 | 1806 | return vnode; |
2aae7680 JH |
1807 | } |
1808 | return NULL; | |
1809 | } | |
1810 | ||
d6d229c6 | 1811 | /* Return next static variable with definition after NODE. */ |
2c8326a5 OE |
1812 | static inline varpool_node * |
1813 | varpool_next_defined_variable (varpool_node *node) | |
2aae7680 | 1814 | { |
5e20cdc9 | 1815 | symtab_node *node1 = node->next; |
67348ccc | 1816 | for (; node1; node1 = node1->next) |
2aae7680 | 1817 | { |
7de90a6c | 1818 | varpool_node *vnode1 = dyn_cast <varpool_node *> (node1); |
67348ccc | 1819 | if (vnode1 && vnode1->definition) |
5d59b5e1 | 1820 | return vnode1; |
2aae7680 JH |
1821 | } |
1822 | return NULL; | |
1823 | } | |
65c70e6b JH |
1824 | /* Walk all variables with definitions in current unit. */ |
1825 | #define FOR_EACH_DEFINED_VARIABLE(node) \ | |
66058468 JH |
1826 | for ((node) = varpool_first_defined_variable (); (node); \ |
1827 | (node) = varpool_next_defined_variable (node)) | |
68e56cc4 | 1828 | |
c47d0034 | 1829 | /* Return first function with body defined. */ |
d52f5295 | 1830 | static inline cgraph_node * |
c47d0034 JH |
1831 | cgraph_first_defined_function (void) |
1832 | { | |
5e20cdc9 | 1833 | symtab_node *node; |
67348ccc | 1834 | for (node = symtab_nodes; node; node = node->next) |
c47d0034 | 1835 | { |
7de90a6c | 1836 | cgraph_node *cn = dyn_cast <cgraph_node *> (node); |
67348ccc | 1837 | if (cn && cn->definition) |
5d59b5e1 | 1838 | return cn; |
c47d0034 JH |
1839 | } |
1840 | return NULL; | |
1841 | } | |
1842 | ||
45896127 | 1843 | /* Return next function with body defined after NODE. */ |
d52f5295 ML |
1844 | static inline cgraph_node * |
1845 | cgraph_next_defined_function (cgraph_node *node) | |
c47d0034 | 1846 | { |
5e20cdc9 | 1847 | symtab_node *node1 = node->next; |
67348ccc | 1848 | for (; node1; node1 = node1->next) |
c47d0034 | 1849 | { |
7de90a6c | 1850 | cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1); |
67348ccc | 1851 | if (cn1 && cn1->definition) |
5d59b5e1 | 1852 | return cn1; |
c47d0034 JH |
1853 | } |
1854 | return NULL; | |
1855 | } | |
1856 | ||
1857 | /* Walk all functions with body defined. */ | |
1858 | #define FOR_EACH_DEFINED_FUNCTION(node) \ | |
1859 | for ((node) = cgraph_first_defined_function (); (node); \ | |
2aae7680 JH |
1860 | (node) = cgraph_next_defined_function ((node))) |
1861 | ||
1862 | /* Return first function. */ | |
d52f5295 | 1863 | static inline cgraph_node * |
2aae7680 JH |
1864 | cgraph_first_function (void) |
1865 | { | |
5e20cdc9 | 1866 | symtab_node *node; |
67348ccc | 1867 | for (node = symtab_nodes; node; node = node->next) |
7de90a6c | 1868 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (node)) |
5d59b5e1 | 1869 | return cn; |
2aae7680 JH |
1870 | return NULL; |
1871 | } | |
1872 | ||
1873 | /* Return next function. */ | |
d52f5295 ML |
1874 | static inline cgraph_node * |
1875 | cgraph_next_function (cgraph_node *node) | |
2aae7680 | 1876 | { |
5e20cdc9 | 1877 | symtab_node *node1 = node->next; |
67348ccc | 1878 | for (; node1; node1 = node1->next) |
7de90a6c | 1879 | if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1)) |
5d59b5e1 | 1880 | return cn1; |
2aae7680 JH |
1881 | return NULL; |
1882 | } | |
65c70e6b JH |
1883 | /* Walk all functions. */ |
1884 | #define FOR_EACH_FUNCTION(node) \ | |
2aae7680 JH |
1885 | for ((node) = cgraph_first_function (); (node); \ |
1886 | (node) = cgraph_next_function ((node))) | |
c47d0034 | 1887 | |
d52f5295 | 1888 | /* Return true when callgraph node is a function with Gimple body defined |
c47d0034 JH |
1889 | in current unit. Functions can also be define externally or they |
1890 | can be thunks with no Gimple representation. | |
1891 | ||
1892 | Note that at WPA stage, the function body may not be present in memory. */ | |
1893 | ||
d52f5295 ML |
1894 | inline bool |
1895 | cgraph_node::has_gimple_body_p (void) | |
c47d0034 | 1896 | { |
d52f5295 | 1897 | return definition && !thunk.thunk_p && !alias; |
c47d0034 JH |
1898 | } |
1899 | ||
1900 | /* Return first function with body defined. */ | |
d52f5295 | 1901 | static inline cgraph_node * |
c47d0034 JH |
1902 | cgraph_first_function_with_gimple_body (void) |
1903 | { | |
5e20cdc9 | 1904 | symtab_node *node; |
67348ccc | 1905 | for (node = symtab_nodes; node; node = node->next) |
c47d0034 | 1906 | { |
7de90a6c | 1907 | cgraph_node *cn = dyn_cast <cgraph_node *> (node); |
d52f5295 | 1908 | if (cn && cn->has_gimple_body_p ()) |
5d59b5e1 | 1909 | return cn; |
c47d0034 JH |
1910 | } |
1911 | return NULL; | |
1912 | } | |
1913 | ||
1914 | /* Return next reachable static variable with initializer after NODE. */ | |
d52f5295 ML |
1915 | static inline cgraph_node * |
1916 | cgraph_next_function_with_gimple_body (cgraph_node *node) | |
c47d0034 | 1917 | { |
5e20cdc9 | 1918 | symtab_node *node1 = node->next; |
67348ccc | 1919 | for (; node1; node1 = node1->next) |
c47d0034 | 1920 | { |
7de90a6c | 1921 | cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1); |
d52f5295 | 1922 | if (cn1 && cn1->has_gimple_body_p ()) |
5d59b5e1 | 1923 | return cn1; |
c47d0034 JH |
1924 | } |
1925 | return NULL; | |
1926 | } | |
1927 | ||
1928 | /* Walk all functions with body defined. */ | |
1929 | #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \ | |
1930 | for ((node) = cgraph_first_function_with_gimple_body (); (node); \ | |
1931 | (node) = cgraph_next_function_with_gimple_body (node)) | |
1932 | ||
43d861a5 RL |
1933 | /* Create a new static variable of type TYPE. */ |
1934 | tree add_new_static_var (tree type); | |
1935 | ||
d48e9cea OR |
1936 | /* Uniquize all constants that appear in memory. |
1937 | Each constant in memory thus far output is recorded | |
1938 | in `const_desc_table'. */ | |
1939 | ||
1940 | struct GTY(()) constant_descriptor_tree { | |
1941 | /* A MEM for the constant. */ | |
1942 | rtx rtl; | |
b8698a0f | 1943 | |
d48e9cea OR |
1944 | /* The value of the constant. */ |
1945 | tree value; | |
1946 | ||
1947 | /* Hash of value. Computing the hash from value each time | |
1948 | hashfn is called can't work properly, as that means recursive | |
1949 | use of the hash table during hash table expansion. */ | |
1950 | hashval_t hash; | |
1951 | }; | |
1952 | ||
d52f5295 | 1953 | /* Return true when function is only called directly or it has alias. |
b20996ff JH |
1954 | i.e. it is not externally visible, address was not taken and |
1955 | it is not used in any other non-standard way. */ | |
1956 | ||
d52f5295 ML |
1957 | inline bool |
1958 | cgraph_node::only_called_directly_or_aliased_p (void) | |
1959 | { | |
1960 | gcc_assert (!global.inlined_to); | |
1961 | return (!force_output && !address_taken | |
1962 | && !used_from_other_partition | |
1963 | && !DECL_VIRTUAL_P (decl) | |
1964 | && !DECL_STATIC_CONSTRUCTOR (decl) | |
1965 | && !DECL_STATIC_DESTRUCTOR (decl) | |
1966 | && !externally_visible); | |
b20996ff JH |
1967 | } |
1968 | ||
9041d2e6 | 1969 | /* Return true when variable can be removed from variable pool |
df7705b1 JH |
1970 | if all direct calls are eliminated. */ |
1971 | ||
9041d2e6 ML |
1972 | inline bool |
1973 | varpool_node::can_remove_if_no_refs_p (void) | |
df7705b1 | 1974 | { |
9041d2e6 | 1975 | if (DECL_EXTERNAL (decl)) |
6649df51 | 1976 | return true; |
9041d2e6 ML |
1977 | return (!force_output && !used_from_other_partition |
1978 | && ((DECL_COMDAT (decl) | |
1979 | && !forced_by_abi | |
1980 | && !used_from_object_file_p ()) | |
1981 | || !externally_visible | |
1982 | || DECL_HAS_VALUE_EXPR_P (decl))); | |
df7705b1 JH |
1983 | } |
1984 | ||
9041d2e6 | 1985 | /* Return true when all references to variable must be visible in ipa_ref_list. |
4a444e58 JH |
1986 | i.e. if the variable is not externally visible or not used in some magic |
1987 | way (asm statement or such). | |
61502ca8 | 1988 | The magic uses are all summarized in force_output flag. */ |
4a444e58 | 1989 | |
9041d2e6 ML |
1990 | inline bool |
1991 | varpool_node::all_refs_explicit_p () | |
4a444e58 | 1992 | { |
9041d2e6 ML |
1993 | return (definition |
1994 | && !externally_visible | |
1995 | && !used_from_other_partition | |
1996 | && !force_output); | |
4a444e58 JH |
1997 | } |
1998 | ||
d48e9cea OR |
1999 | /* Constant pool accessor function. */ |
2000 | htab_t constant_pool_htab (void); | |
fed5ae11 | 2001 | |
d52f5295 | 2002 | /* Return node that alias is aliasing. */ |
39e2db00 | 2003 | |
d52f5295 ML |
2004 | inline cgraph_node * |
2005 | cgraph_node::get_alias_target (void) | |
cd35bcf7 | 2006 | { |
d52f5295 | 2007 | return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ()); |
cd35bcf7 JH |
2008 | } |
2009 | ||
9041d2e6 ML |
2010 | /* Return node that alias is aliasing. */ |
2011 | ||
2012 | inline varpool_node * | |
2013 | varpool_node::get_alias_target (void) | |
be330ed4 | 2014 | { |
9041d2e6 | 2015 | return dyn_cast <varpool_node *> (symtab_node::get_alias_target ()); |
be330ed4 JH |
2016 | } |
2017 | ||
d52f5295 ML |
2018 | /* Given function symbol, walk the alias chain to return the function node |
2019 | is alias of. Do not walk through thunks. | |
073a8998 | 2020 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ |
be330ed4 | 2021 | |
d52f5295 ML |
2022 | inline cgraph_node * |
2023 | cgraph_node::ultimate_alias_target (enum availability *availability) | |
be330ed4 | 2024 | { |
d52f5295 ML |
2025 | cgraph_node *n = dyn_cast <cgraph_node *> (symtab_node::ultimate_alias_target |
2026 | (availability)); | |
40a7fe1e | 2027 | if (!n && availability) |
39e2db00 | 2028 | *availability = AVAIL_NOT_AVAILABLE; |
e70670cf | 2029 | return n; |
be330ed4 | 2030 | } |
9041d2e6 ML |
2031 | |
2032 | /* For given variable pool node, walk the alias chain to return the function | |
2033 | the variable is alias of. Do not walk through thunks. | |
073a8998 | 2034 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ |
cd35bcf7 | 2035 | |
9041d2e6 ML |
2036 | inline varpool_node * |
2037 | varpool_node::ultimate_alias_target (availability *availability) | |
cd35bcf7 | 2038 | { |
9041d2e6 ML |
2039 | varpool_node *n = dyn_cast <varpool_node *> |
2040 | (symtab_node::ultimate_alias_target (availability)); | |
ff36fcbe | 2041 | |
40a7fe1e | 2042 | if (!n && availability) |
cd35bcf7 | 2043 | *availability = AVAIL_NOT_AVAILABLE; |
e70670cf | 2044 | return n; |
cd35bcf7 JH |
2045 | } |
2046 | ||
d7d1d041 RG |
2047 | /* Return true when the edge E represents a direct recursion. */ |
2048 | static inline bool | |
2049 | cgraph_edge_recursive_p (struct cgraph_edge *e) | |
2050 | { | |
d52f5295 | 2051 | cgraph_node *callee = e->callee->ultimate_alias_target (); |
d7d1d041 | 2052 | if (e->caller->global.inlined_to) |
67348ccc | 2053 | return e->caller->global.inlined_to->decl == callee->decl; |
d7d1d041 | 2054 | else |
67348ccc | 2055 | return e->caller->decl == callee->decl; |
d7d1d041 | 2056 | } |
0a35513e AH |
2057 | |
2058 | /* Return true if the TM_CLONE bit is set for a given FNDECL. */ | |
2059 | static inline bool | |
2060 | decl_is_tm_clone (const_tree fndecl) | |
2061 | { | |
d52f5295 | 2062 | cgraph_node *n = cgraph_node::get (fndecl); |
0a35513e AH |
2063 | if (n) |
2064 | return n->tm_clone; | |
2065 | return false; | |
2066 | } | |
9c8305f8 JH |
2067 | |
2068 | /* Likewise indicate that a node is needed, i.e. reachable via some | |
2069 | external means. */ | |
2070 | ||
d52f5295 ML |
2071 | inline void |
2072 | cgraph_node::mark_force_output (void) | |
1f26ac87 | 2073 | { |
d52f5295 ML |
2074 | force_output = 1; |
2075 | gcc_checking_assert (!global.inlined_to); | |
1f26ac87 JM |
2076 | } |
2077 | ||
1c4a429a | 2078 | #endif /* GCC_CGRAPH_H */ |