]>
Commit | Line | Data |
---|---|---|
ae01b312 | 1 | /* Callgraph handling code. |
3aea1f79 | 2 | Copyright (C) 2003-2014 Free Software Foundation, Inc. |
ae01b312 | 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 | |
8c4c00c1 | 9 | Software Foundation; either version 3, or (at your option) any later |
ae01b312 | 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 | |
8c4c00c1 | 18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
ae01b312 | 20 | |
21 | #ifndef GCC_CGRAPH_H | |
22 | #define GCC_CGRAPH_H | |
0f71a633 | 23 | |
06ecf488 | 24 | #include "hash-map.h" |
2dc9831f | 25 | #include "is-a.h" |
9ced88d0 | 26 | #include "plugin-api.h" |
0f71a633 | 27 | #include "vec.h" |
41a8aa41 | 28 | #include "basic-block.h" |
0f71a633 | 29 | #include "function.h" |
b6c89d32 | 30 | #include "ipa-ref.h" |
31 | ||
32 | /* Symbol table consists of functions and variables. | |
15ca8f90 | 33 | TODO: add labels and CONST_DECLs. */ |
b6c89d32 | 34 | enum symtab_type |
35 | { | |
7d0d0ce1 | 36 | SYMTAB_SYMBOL, |
b6c89d32 | 37 | SYMTAB_FUNCTION, |
38 | SYMTAB_VARIABLE | |
39 | }; | |
40 | ||
738a6bda | 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 | ||
415d1b9a | 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 | ||
b6c89d32 | 88 | /* Base of all entries in the symbol table. |
89 | The symtab_node is inherited by cgraph and varpol nodes. */ | |
2043dfcc | 90 | class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"), |
91 | chain_next ("%h.next"), chain_prev ("%h.previous"))) | |
452659af | 92 | symtab_node |
b6c89d32 | 93 | { |
2043dfcc | 94 | public: |
f1c8b4d7 | 95 | /* Return name. */ |
96 | const char *name () const; | |
97 | ||
98 | /* Return asm name. */ | |
99 | const char * asm_name () const; | |
100 | ||
415d1b9a | 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 | ||
b6c89d32 | 356 | /* Type of the symbol. */ |
a83af0c5 | 357 | ENUM_BITFIELD (symtab_type) type : 8; |
358 | ||
359 | /* The symbols resolution. */ | |
360 | ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8; | |
361 | ||
15ca8f90 | 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; | |
97221fd7 | 367 | /* True when symbol is an alias. |
368 | Set by ssemble_alias. */ | |
15ca8f90 | 369 | unsigned alias : 1; |
f2526cce | 370 | /* True when alias is a weakref. */ |
371 | unsigned weakref : 1; | |
48669653 | 372 | /* C++ frontend produce same body aliases and extra name aliases for |
a04e8d62 | 373 | virtual functions and vtables that are obviously equivalent. |
48669653 | 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; | |
15ca8f90 | 379 | /* Set once the definition was analyzed. The list of references and |
380 | other properties are built during analysis. */ | |
381 | unsigned analyzed : 1; | |
703ad42c | 382 | /* Set for write-only variables. */ |
383 | unsigned writeonly : 1; | |
15ca8f90 | 384 | |
385 | ||
386 | /*** Visibility and linkage flags. ***/ | |
387 | ||
a83af0c5 | 388 | /* Set when function is visible by other units. */ |
389 | unsigned externally_visible : 1; | |
bce6ce2d | 390 | /* The symbol will be assumed to be used in an invisible way (like |
6a1c0403 | 391 | by an toplevel asm statement). */ |
a83af0c5 | 392 | unsigned force_output : 1; |
6a1c0403 | 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; | |
5c368d8a | 397 | /* True when the name is known to be unique and thus it does not need mangling. */ |
398 | unsigned unique_name : 1; | |
e4c07a06 | 399 | /* Specify whether the section was set by user or by |
400 | compiler via -ffunction-sections. */ | |
401 | unsigned implicit_section : 1; | |
fa4052b3 | 402 | /* True when body and other characteristics have been removed by |
403 | symtab_remove_unreachable_nodes. */ | |
404 | unsigned body_removed : 1; | |
a83af0c5 | 405 | |
15ca8f90 | 406 | /*** WHOPR Partitioning flags. |
407 | These flags are used at ltrans stage when only part of the callgraph is | |
408 | available. ***/ | |
a83af0c5 | 409 | |
15ca8f90 | 410 | /* Set when variable is used from other LTRANS partition. */ |
411 | unsigned used_from_other_partition : 1; | |
97221fd7 | 412 | /* Set when function is available in the other LTRANS partition. |
15ca8f90 | 413 | During WPA output it is used to mark nodes that are present in |
414 | multiple partitions. */ | |
415 | unsigned in_other_partition : 1; | |
a83af0c5 | 416 | |
a83af0c5 | 417 | |
15ca8f90 | 418 | |
419 | /*** other flags. ***/ | |
420 | ||
421 | /* Set when symbol has address taken. */ | |
422 | unsigned address_taken : 1; | |
9db80d42 | 423 | /* Set when init priority is set. */ |
424 | unsigned in_init_priority_hash : 1; | |
15ca8f90 | 425 | |
426 | ||
427 | /* Ordering of all symtab entries. */ | |
428 | int order; | |
429 | ||
430 | /* Declaration representing the symbol. */ | |
431 | tree decl; | |
7d0d0ce1 | 432 | |
0704fb2e | 433 | /* Linked list of symbol table entries starting with symtab_nodes. */ |
452659af | 434 | symtab_node *next; |
435 | symtab_node *previous; | |
15ca8f90 | 436 | |
cfbe30aa | 437 | /* Linked list of symbols with the same asm name. There may be multiple |
15ca8f90 | 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. */ | |
452659af | 446 | symtab_node *next_sharing_asm_name; |
447 | symtab_node *previous_sharing_asm_name; | |
0704fb2e | 448 | |
415d1b9a | 449 | /* Circular list of nodes in the same comdat group if non-NULL. */ |
450 | symtab_node *same_comdat_group; | |
e4a2b488 | 451 | |
15ca8f90 | 452 | /* Vectors of referring and referenced entities. */ |
453 | struct ipa_ref_list ref_list; | |
454 | ||
48669653 | 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 | ||
15ca8f90 | 460 | /* File stream where this node is being written to. */ |
461 | struct lto_file_decl_data * lto_file_data; | |
462 | ||
7d0d0ce1 | 463 | PTR GTY ((skip)) aux; |
8c016392 | 464 | |
465 | /* Comdat group the symbol is in. Can be private if GGC allowed that. */ | |
738a6bda | 466 | tree x_comdat_group; |
71e19e54 | 467 | |
468 | /* Section name. Again can be private, if allowed. */ | |
738a6bda | 469 | section_hash_entry *x_section; |
e4c07a06 | 470 | |
415d1b9a | 471 | protected: |
472 | /* Dump base fields of symtab nodes to F. Not to be used directly. */ | |
473 | void dump_base (FILE *); | |
9db80d42 | 474 | |
415d1b9a | 475 | /* Verify common part of symtab node. */ |
476 | bool DEBUG_FUNCTION verify_base (void); | |
56ac70ed | 477 | |
415d1b9a | 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); | |
b6c89d32 | 496 | }; |
ae01b312 | 497 | |
e4a2b488 | 498 | /* Walk all aliases for NODE. */ |
499 | #define FOR_EACH_ALIAS(node, alias) \ | |
415d1b9a | 500 | for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++) |
e1be32b8 | 501 | |
7bfefa9d | 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 | ||
1d416bd7 | 506 | extern const char * const cgraph_availability_names[]; |
6e673e69 | 507 | extern const char * const ld_plugin_symbol_resolution_names[]; |
b7393cee | 508 | extern const char * const tls_model_names[]; |
1d416bd7 | 509 | |
28454517 | 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 | ||
80a85d8a | 523 | /* Information about the function collected locally. |
ec1e35b2 | 524 | Available after function is analyzed. */ |
80a85d8a | 525 | |
fb1e4f4a | 526 | struct GTY(()) cgraph_local_info { |
d01481af | 527 | /* Set when function function is visible in current compilation unit only |
9cd50731 | 528 | and its address is never taken. */ |
a16eb452 | 529 | unsigned local : 1; |
acc70efa | 530 | |
c8d92fc1 | 531 | /* False when there is something makes versioning impossible. */ |
532 | unsigned versionable : 1; | |
533 | ||
3c97c75d | 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 | ||
69435b7f | 538 | /* True when the function has been originally extern inline, but it is |
539 | redefined now. */ | |
a16eb452 | 540 | unsigned redefined_extern_inline : 1; |
4c0315d0 | 541 | |
542 | /* True if the function may enter serial irrevocable mode. */ | |
543 | unsigned tm_may_enter_irr : 1; | |
80a85d8a | 544 | }; |
545 | ||
546 | /* Information about the function that needs to be computed globally | |
75a70cf9 | 547 | once compilation is finished. Available only with -funit-at-a-time. */ |
80a85d8a | 548 | |
fb1e4f4a | 549 | struct GTY(()) cgraph_global_info { |
75a70cf9 | 550 | /* For inline clones this points to the function they will be |
551 | inlined into. */ | |
415d1b9a | 552 | cgraph_node *inlined_to; |
80a85d8a | 553 | }; |
554 | ||
28992b23 | 555 | /* Information about the function that is propagated by the RTL backend. |
556 | Available only for functions that has been already assembled. */ | |
557 | ||
fb1e4f4a | 558 | struct GTY(()) cgraph_rtl_info { |
9a27561f | 559 | unsigned int preferred_incoming_stack_boundary; |
9ac9a758 | 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; | |
28992b23 | 567 | }; |
568 | ||
ccf4ab6b | 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; | |
1bf41320 | 577 | /* Parameter number to replace, when old_tree is NULL. */ |
578 | int parm_num; | |
ccf4ab6b | 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 | }; | |
ccf4ab6b | 584 | |
585 | struct GTY(()) cgraph_clone_info | |
586 | { | |
415d1b9a | 587 | vec<ipa_replace_map *, va_gc> *tree_map; |
ccf4ab6b | 588 | bitmap args_to_skip; |
e20422ea | 589 | bitmap combined_args_to_skip; |
ccf4ab6b | 590 | }; |
591 | ||
d09768a4 | 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. */ | |
415d1b9a | 676 | cgraph_node *prev_clone, *next_clone; |
d09768a4 | 677 | |
678 | /* Original cgraph node the SIMD clones were created for. */ | |
415d1b9a | 679 | cgraph_node *origin; |
d09768a4 | 680 | |
681 | /* Annotated function arguments for the original function. */ | |
682 | struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1]; | |
683 | }; | |
684 | ||
415d1b9a | 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; | |
125b6d78 | 724 | |
c7bf1374 | 725 | /* The cgraph data structure. |
d01481af | 726 | Each function decl has assigned cgraph_node listing callees and callers. */ |
ae01b312 | 727 | |
452659af | 728 | struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node { |
2043dfcc | 729 | public: |
415d1b9a | 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, | |
918 | gcov_type count, int freq); | |
919 | ||
920 | /* Like cgraph_create_edge walk the clone tree and update all clones sharing | |
921 | same function body. If clones already have edge for OLD_STMT; only | |
922 | update the edge same way as cgraph_set_call_stmt_including_clones does. */ | |
923 | void create_edge_including_clones (struct cgraph_node *callee, | |
924 | gimple old_stmt, gimple stmt, | |
925 | gcov_type count, | |
926 | int freq, | |
927 | cgraph_inline_failed_t reason); | |
928 | ||
929 | /* Return the callgraph edge representing the GIMPLE_CALL statement | |
930 | CALL_STMT. */ | |
931 | cgraph_edge *get_edge (gimple call_stmt); | |
932 | ||
933 | /* Collect all callers of cgraph_node and its aliases that are known to lead | |
934 | to NODE (i.e. are not overwritable). */ | |
935 | vec<cgraph_edge *> collect_callers (void); | |
936 | ||
937 | /* Remove all callers from the node. */ | |
938 | void remove_callers (void); | |
939 | ||
940 | /* Remove all callees from the node. */ | |
941 | void remove_callees (void); | |
942 | ||
943 | /* Return function availability. See cgraph.h for description of individual | |
944 | return values. */ | |
945 | enum availability get_availability (void); | |
946 | ||
947 | /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node | |
948 | if any to NOTHROW. */ | |
949 | void set_nothrow_flag (bool nothrow); | |
950 | ||
951 | /* Set TREE_READONLY on cgraph_node's decl and on aliases of the node | |
952 | if any to READONLY. */ | |
953 | void set_const_flag (bool readonly, bool looping); | |
954 | ||
955 | /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node | |
956 | if any to PURE. */ | |
957 | void set_pure_flag (bool pure, bool looping); | |
958 | ||
959 | /* Call all node duplication hooks. */ | |
960 | void call_duplication_hooks (cgraph_node *node2); | |
961 | ||
962 | /* Call calback on function and aliases associated to the function. | |
963 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are | |
964 | skipped. */ | |
965 | ||
966 | bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *, | |
967 | void *), | |
968 | void *data, bool include_overwritable); | |
969 | ||
970 | /* Call calback on cgraph_node, thunks and aliases associated to NODE. | |
971 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are | |
972 | skipped. */ | |
973 | bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node, | |
974 | void *data), | |
975 | void *data, | |
976 | bool include_overwritable); | |
977 | ||
978 | /* Call all node insertion hooks. */ | |
979 | void call_function_insertion_hooks (void); | |
980 | ||
981 | /* Likewise indicate that a node is needed, i.e. reachable via some | |
982 | external means. */ | |
983 | inline void mark_force_output (void); | |
984 | ||
985 | /* Return true when function can be marked local. */ | |
986 | bool local_p (void); | |
987 | ||
988 | /* Return true if cgraph_node can be made local for API change. | |
989 | Extern inline functions and C++ COMDAT functions can be made local | |
990 | at the expense of possible code size growth if function is used in multiple | |
991 | compilation units. */ | |
992 | bool can_be_local_p (void); | |
993 | ||
994 | /* Return true when cgraph_node can not return or throw and thus | |
995 | it is safe to ignore its side effects for IPA analysis. */ | |
996 | bool cannot_return_p (void); | |
997 | ||
998 | /* Return true when function cgraph_node and all its aliases are only called | |
999 | directly. | |
1000 | i.e. it is not externally visible, address was not taken and | |
1001 | it is not used in any other non-standard way. */ | |
1002 | bool only_called_directly_p (void); | |
1003 | ||
1004 | /* Return true when function is only called directly or it has alias. | |
1005 | i.e. it is not externally visible, address was not taken and | |
1006 | it is not used in any other non-standard way. */ | |
1007 | inline bool only_called_directly_or_aliased_p (void); | |
1008 | ||
1009 | /* Return true when function cgraph_node can be expected to be removed | |
1010 | from program when direct calls in this compilation unit are removed. | |
1011 | ||
1012 | As a special case COMDAT functions are | |
1013 | cgraph_can_remove_if_no_direct_calls_p while the are not | |
1014 | cgraph_only_called_directly_p (it is possible they are called from other | |
1015 | unit) | |
1016 | ||
1017 | This function behaves as cgraph_only_called_directly_p because eliminating | |
1018 | all uses of COMDAT function does not make it necessarily disappear from | |
1019 | the program unless we are compiling whole program or we do LTO. In this | |
1020 | case we know we win since dynamic linking will not really discard the | |
1021 | linkonce section. */ | |
1022 | bool will_be_removed_from_program_if_no_direct_calls_p (void); | |
1023 | ||
1024 | /* Return true when function can be removed from callgraph | |
1025 | if all direct calls are eliminated. */ | |
1026 | bool can_remove_if_no_direct_calls_and_refs_p (void); | |
1027 | ||
1028 | /* Return true when function cgraph_node and its aliases can be removed from | |
1029 | callgraph if all direct calls are eliminated. */ | |
1030 | bool can_remove_if_no_direct_calls_p (void); | |
1031 | ||
1032 | /* Return true when callgraph node is a function with Gimple body defined | |
1033 | in current unit. Functions can also be define externally or they | |
1034 | can be thunks with no Gimple representation. | |
1035 | ||
1036 | Note that at WPA stage, the function body may not be present in memory. */ | |
1037 | inline bool has_gimple_body_p (void); | |
1038 | ||
1039 | /* Return true if function should be optimized for size. */ | |
1040 | bool optimize_for_size_p (void); | |
1041 | ||
1042 | /* Dump the callgraph to file F. */ | |
1043 | static void dump_cgraph (FILE *f); | |
1044 | ||
1045 | /* Dump the call graph to stderr. */ | |
1046 | static inline void debug_cgraph (void) | |
1047 | { | |
1048 | dump_cgraph (stderr); | |
1049 | } | |
1050 | ||
1051 | /* Record that DECL1 and DECL2 are semantically identical function | |
1052 | versions. */ | |
1053 | static void record_function_versions (tree decl1, tree decl2); | |
1054 | ||
1055 | /* Remove the cgraph_function_version_info and cgraph_node for DECL. This | |
1056 | DECL is a duplicate declaration. */ | |
1057 | static void delete_function_version (tree decl); | |
1058 | ||
1059 | /* Add the function FNDECL to the call graph. | |
1060 | Unlike cgraph_finalize_function, this function is intended to be used | |
1061 | by middle end and allows insertion of new function at arbitrary point | |
1062 | of compilation. The function can be either in high, low or SSA form | |
1063 | GIMPLE. | |
1064 | ||
1065 | The function is assumed to be reachable and have address taken (so no | |
1066 | API breaking optimizations are performed on it). | |
1067 | ||
1068 | Main work done by this function is to enqueue the function for later | |
1069 | processing to avoid need the passes to be re-entrant. */ | |
1070 | static void add_new_function (tree fndecl, bool lowered); | |
1071 | ||
1072 | /* Return callgraph node for given symbol and check it is a function. */ | |
1073 | static inline cgraph_node *get (const_tree decl) | |
1074 | { | |
1075 | gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL); | |
1076 | return dyn_cast <cgraph_node *> (symtab_node::get (decl)); | |
1077 | } | |
1078 | ||
1079 | /* Return cgraph node assigned to DECL. Create new one when needed. */ | |
1080 | static cgraph_node * create (tree decl); | |
1081 | ||
1082 | /* Allocate new callgraph node and insert it into basic data structures. */ | |
1083 | static cgraph_node * create_empty (void); | |
1084 | ||
1085 | /* Try to find a call graph node for declaration DECL and if it does not | |
1086 | exist or if it corresponds to an inline clone, create a new one. */ | |
1087 | static cgraph_node * get_create (tree); | |
1088 | ||
1089 | /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME. | |
1090 | Return NULL if there's no such node. */ | |
1091 | static cgraph_node *get_for_asmname (tree asmname); | |
1092 | ||
1093 | /* Attempt to mark ALIAS as an alias to DECL. Return alias node if | |
1094 | successful and NULL otherwise. | |
1095 | Same body aliases are output whenever the body of DECL is output, | |
1096 | and cgraph_node::get (ALIAS) transparently | |
1097 | returns cgraph_node::get (DECL). */ | |
1098 | static cgraph_node * create_same_body_alias (tree alias, tree decl); | |
1099 | ||
1100 | /* Worker for cgraph_can_remove_if_no_direct_calls_p. */ | |
1101 | static bool used_from_object_file_p_worker (cgraph_node *node, void *) | |
1102 | { | |
1103 | return node->used_from_object_file_p (); | |
1104 | } | |
1105 | ||
1106 | /* Return true when cgraph_node can not be local. | |
1107 | Worker for cgraph_local_node_p. */ | |
1108 | static bool non_local_p (cgraph_node *node, void *); | |
1109 | ||
1110 | /* Verify whole cgraph structure. */ | |
1111 | static void DEBUG_FUNCTION verify_cgraph_nodes (void); | |
1112 | ||
1113 | /* Worker to bring NODE local. */ | |
1114 | static bool make_local (cgraph_node *node, void *); | |
1115 | ||
1116 | /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing | |
1117 | the function body is associated | |
1118 | with (not necessarily cgraph_node (DECL). */ | |
1119 | static cgraph_node *create_alias (tree alias, tree target); | |
1120 | ||
1121 | static cgraph_edge * create_edge (cgraph_node *caller, cgraph_node *callee, | |
1122 | gimple call_stmt, gcov_type count, | |
1123 | int freq, | |
1124 | bool indir_unknown_callee); | |
1125 | ||
ae01b312 | 1126 | struct cgraph_edge *callees; |
1127 | struct cgraph_edge *callers; | |
799c8711 | 1128 | /* List of edges representing indirect calls with a yet undetermined |
1129 | callee. */ | |
1130 | struct cgraph_edge *indirect_calls; | |
ae01b312 | 1131 | /* For nested functions points to function the node is nested in. */ |
415d1b9a | 1132 | cgraph_node *origin; |
ae01b312 | 1133 | /* Points to first nested function, if any. */ |
415d1b9a | 1134 | cgraph_node *nested; |
ae01b312 | 1135 | /* Pointer to the next function with same origin, if any. */ |
415d1b9a | 1136 | cgraph_node *next_nested; |
b0cdf642 | 1137 | /* Pointer to the next clone. */ |
415d1b9a | 1138 | cgraph_node *next_sibling_clone; |
1139 | cgraph_node *prev_sibling_clone; | |
1140 | cgraph_node *clones; | |
1141 | cgraph_node *clone_of; | |
8df22c5c | 1142 | /* For functions with many calls sites it holds map from call expression |
1143 | to the edge to speed up cgraph_edge function. */ | |
1144 | htab_t GTY((param_is (struct cgraph_edge))) call_site_hash; | |
b9ffeffb | 1145 | /* Declaration node used to be clone of. */ |
1146 | tree former_clone_of; | |
a0c938f0 | 1147 | |
d09768a4 | 1148 | /* If this is a SIMD clone, this points to the SIMD specific |
1149 | information for it. */ | |
1150 | struct cgraph_simd_clone *simdclone; | |
1151 | /* If this function has SIMD clones, this points to the first clone. */ | |
415d1b9a | 1152 | cgraph_node *simd_clones; |
d09768a4 | 1153 | |
6d1cc52c | 1154 | /* Interprocedural passes scheduled to have their transform functions |
1155 | applied next time we execute local pass on them. We maintain it | |
1156 | per-function in order to allow IPA passes to introduce new functions. */ | |
f1f41a6c | 1157 | vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply; |
6d1cc52c | 1158 | |
69435b7f | 1159 | struct cgraph_local_info local; |
1160 | struct cgraph_global_info global; | |
1161 | struct cgraph_rtl_info rtl; | |
ccf4ab6b | 1162 | struct cgraph_clone_info clone; |
28454517 | 1163 | struct cgraph_thunk_info thunk; |
a0c938f0 | 1164 | |
edc6a4c0 | 1165 | /* Expected number of executions: calculated in profile.c. */ |
1166 | gcov_type count; | |
c470c5a9 | 1167 | /* How to scale counts at materialization time; used to merge |
1168 | LTO units with different number of profile runs. */ | |
1169 | int count_materialization_scale; | |
69435b7f | 1170 | /* Unique id of the node. */ |
1171 | int uid; | |
fe37be54 | 1172 | /* ID assigned by the profiling. */ |
1173 | unsigned int profile_id; | |
38fe12e3 | 1174 | /* Time profiler: first run of function. */ |
1175 | int tp_first_run; | |
9fac1c66 | 1176 | |
d544ceff | 1177 | /* Set when decl is an abstract function pointed to by the |
1178 | ABSTRACT_DECL_ORIGIN of a reachable function. */ | |
abb1a237 | 1179 | unsigned used_as_abstract_origin : 1; |
773c5ba7 | 1180 | /* Set once the function is lowered (i.e. its CFG is built). */ |
a16eb452 | 1181 | unsigned lowered : 1; |
ec1e35b2 | 1182 | /* Set once the function has been instantiated and its callee |
1183 | lists created. */ | |
09fc9532 | 1184 | unsigned process : 1; |
125b6d78 | 1185 | /* How commonly executed the node is. Initialized during branch |
1186 | probabilities pass. */ | |
1187 | ENUM_BITFIELD (node_frequency) frequency : 2; | |
0f9fb931 | 1188 | /* True when function can only be called at startup (from static ctor). */ |
1189 | unsigned only_called_at_startup : 1; | |
1190 | /* True when function can only be called at startup (from static dtor). */ | |
1191 | unsigned only_called_at_exit : 1; | |
4c0315d0 | 1192 | /* True when function is the transactional clone of a function which |
1193 | is called only from inside transactions. */ | |
1194 | /* ?? We should be able to remove this. We have enough bits in | |
1195 | cgraph to calculate it. */ | |
1196 | unsigned tm_clone : 1; | |
cc8ef84f | 1197 | /* True if this decl is a dispatcher for function versions. */ |
1198 | unsigned dispatcher_function : 1; | |
468088ac | 1199 | /* True if this decl calls a COMDAT-local function. This is set up in |
1200 | compute_inline_parameters and inline_call. */ | |
1201 | unsigned calls_comdat_local : 1; | |
cc8ef84f | 1202 | }; |
1203 | ||
13f90d63 | 1204 | /* A cgraph node set is a collection of cgraph nodes. A cgraph node |
1205 | can appear in multiple sets. */ | |
19ad01f7 | 1206 | struct cgraph_node_set_def |
13f90d63 | 1207 | { |
06ecf488 | 1208 | hash_map<cgraph_node *, size_t> *map; |
415d1b9a | 1209 | vec<cgraph_node *> nodes; |
13f90d63 | 1210 | }; |
1211 | ||
415d1b9a | 1212 | typedef cgraph_node_set_def *cgraph_node_set; |
1213 | typedef struct varpool_node_set_def *varpool_node_set; | |
0cddb138 | 1214 | |
415d1b9a | 1215 | class varpool_node; |
0cddb138 | 1216 | |
1217 | /* A varpool node set is a collection of varpool nodes. A varpool node | |
1218 | can appear in multiple sets. */ | |
19ad01f7 | 1219 | struct varpool_node_set_def |
0cddb138 | 1220 | { |
06ecf488 | 1221 | hash_map<varpool_node *, size_t> * map; |
415d1b9a | 1222 | vec<varpool_node *> nodes; |
0cddb138 | 1223 | }; |
1224 | ||
13f90d63 | 1225 | /* Iterator structure for cgraph node sets. */ |
b3e7c666 | 1226 | struct cgraph_node_set_iterator |
13f90d63 | 1227 | { |
1228 | cgraph_node_set set; | |
1229 | unsigned index; | |
b3e7c666 | 1230 | }; |
13f90d63 | 1231 | |
0cddb138 | 1232 | /* Iterator structure for varpool node sets. */ |
b3e7c666 | 1233 | struct varpool_node_set_iterator |
0cddb138 | 1234 | { |
1235 | varpool_node_set set; | |
1236 | unsigned index; | |
b3e7c666 | 1237 | }; |
0cddb138 | 1238 | |
799c8711 | 1239 | /* Structure containing additional information about an indirect call. */ |
1240 | ||
1241 | struct GTY(()) cgraph_indirect_call_info | |
1242 | { | |
0d491188 | 1243 | /* When polymorphic is set, this field contains offset where the object which |
1244 | was actually used in the polymorphic resides within a larger structure. | |
1245 | If agg_contents is set, the field contains the offset within the aggregate | |
1246 | from which the address to call was loaded. */ | |
283c8750 | 1247 | HOST_WIDE_INT offset, speculative_offset; |
6378ffb3 | 1248 | /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */ |
1249 | HOST_WIDE_INT otr_token; | |
1250 | /* Type of the object from OBJ_TYPE_REF_OBJECT. */ | |
283c8750 | 1251 | tree otr_type, outer_type, speculative_outer_type; |
799c8711 | 1252 | /* Index of the parameter that is called. */ |
1253 | int param_index; | |
f8b7e3ec | 1254 | /* ECF flags determined from the caller. */ |
1255 | int ecf_flags; | |
6a261305 | 1256 | /* Profile_id of common target obtrained from profile. */ |
1257 | int common_target_id; | |
1258 | /* Probability that call will land in function with COMMON_TARGET_ID. */ | |
1259 | int common_target_probability; | |
6378ffb3 | 1260 | |
1261 | /* Set when the call is a virtual call with the parameter being the | |
1262 | associated object pointer rather than a simple direct call. */ | |
1263 | unsigned polymorphic : 1; | |
0d491188 | 1264 | /* Set when the call is a call of a pointer loaded from contents of an |
1265 | aggregate at offset. */ | |
1266 | unsigned agg_contents : 1; | |
2f6c1cf4 | 1267 | /* Set when this is a call through a member pointer. */ |
1268 | unsigned member_ptr : 1; | |
0d491188 | 1269 | /* When the previous bit is set, this one determines whether the destination |
1270 | is loaded from a parameter passed by reference. */ | |
1271 | unsigned by_ref : 1; | |
3af5e0b7 | 1272 | unsigned int maybe_in_construction : 1; |
1273 | unsigned int maybe_derived_type : 1; | |
283c8750 | 1274 | unsigned int speculative_maybe_derived_type : 1; |
799c8711 | 1275 | }; |
1276 | ||
fb1e4f4a | 1277 | struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge { |
3e994825 | 1278 | /* Expected number of executions: calculated in profile.c. */ |
1279 | gcov_type count; | |
415d1b9a | 1280 | cgraph_node *caller; |
1281 | cgraph_node *callee; | |
bb4c7a44 | 1282 | struct cgraph_edge *prev_caller; |
ae01b312 | 1283 | struct cgraph_edge *next_caller; |
bb4c7a44 | 1284 | struct cgraph_edge *prev_callee; |
ae01b312 | 1285 | struct cgraph_edge *next_callee; |
75a70cf9 | 1286 | gimple call_stmt; |
799c8711 | 1287 | /* Additional information about an indirect call. Not cleared when an edge |
1288 | becomes direct. */ | |
1289 | struct cgraph_indirect_call_info *indirect_info; | |
b0cdf642 | 1290 | PTR GTY ((skip (""))) aux; |
326a9581 | 1291 | /* When equal to CIF_OK, inline this call. Otherwise, points to the |
1292 | explanation why function was not inlined. */ | |
b3e7c666 | 1293 | enum cgraph_inline_failed_t inline_failed; |
3e994825 | 1294 | /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt |
1295 | when the function is serialized in. */ | |
1296 | unsigned int lto_stmt_uid; | |
48e1416a | 1297 | /* Expected frequency of executions within the function. |
4ae20857 | 1298 | When set to CGRAPH_FREQ_BASE, the edge is expected to be called once |
1299 | per function call. The range is 0 to CGRAPH_FREQ_MAX. */ | |
1300 | int frequency; | |
3e994825 | 1301 | /* Unique id of the edge. */ |
1302 | int uid; | |
799c8711 | 1303 | /* Whether this edge was made direct by indirect inlining. */ |
1304 | unsigned int indirect_inlining_edge : 1; | |
1305 | /* Whether this edge describes an indirect call with an undetermined | |
1306 | callee. */ | |
1307 | unsigned int indirect_unknown_callee : 1; | |
1308 | /* Whether this edge is still a dangling */ | |
7bfefa9d | 1309 | /* True if the corresponding CALL stmt cannot be inlined. */ |
1310 | unsigned int call_stmt_cannot_inline_p : 1; | |
17b28e52 | 1311 | /* Can this call throw externally? */ |
1312 | unsigned int can_throw_external : 1; | |
4d044066 | 1313 | /* Edges with SPECULATIVE flag represents indirect calls that was |
1314 | speculatively turned into direct (i.e. by profile feedback). | |
1315 | The final code sequence will have form: | |
1316 | ||
1317 | if (call_target == expected_fn) | |
1318 | expected_fn (); | |
1319 | else | |
1320 | call_target (); | |
1321 | ||
1322 | Every speculative call is represented by three components attached | |
1323 | to a same call statement: | |
1324 | 1) a direct call (to expected_fn) | |
1325 | 2) an indirect call (to call_target) | |
1326 | 3) a IPA_REF_ADDR refrence to expected_fn. | |
1327 | ||
1328 | Optimizers may later redirect direct call to clone, so 1) and 3) | |
1329 | do not need to necesarily agree with destination. */ | |
1330 | unsigned int speculative : 1; | |
ae01b312 | 1331 | }; |
1332 | ||
4ae20857 | 1333 | #define CGRAPH_FREQ_BASE 1000 |
1334 | #define CGRAPH_FREQ_MAX 100000 | |
1335 | ||
1d416bd7 | 1336 | /* The varpool data structure. |
1337 | Each static variable decl has assigned varpool_node. */ | |
229dcfae | 1338 | |
452659af | 1339 | class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node { |
2043dfcc | 1340 | public: |
97221fd7 | 1341 | /* Dump given varpool node to F. */ |
1342 | void dump (FILE *f); | |
1343 | ||
1344 | /* Dump given varpool node to stderr. */ | |
1345 | void DEBUG_FUNCTION debug (void); | |
1346 | ||
1347 | /* Remove variable from symbol table. */ | |
1348 | void remove (void); | |
1349 | ||
1350 | /* Remove node initializer when it is no longer needed. */ | |
1351 | void remove_initializer (void); | |
1352 | ||
1353 | void analyze (void); | |
1354 | ||
1355 | /* Return variable availability. */ | |
1356 | availability get_availability (void); | |
1357 | ||
1358 | /* When doing LTO, read variable's constructor from disk if | |
1359 | it is not already present. */ | |
1360 | tree get_constructor (void); | |
1361 | ||
1362 | /* Return true if variable has constructor that can be used for folding. */ | |
1363 | bool ctor_useable_for_folding_p (void); | |
1364 | ||
1365 | /* For given variable pool node, walk the alias chain to return the function | |
1366 | the variable is alias of. Do not walk through thunks. | |
1367 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ | |
1368 | inline varpool_node *ultimate_alias_target | |
1369 | (availability *availability = NULL); | |
1370 | ||
1371 | /* Return node that alias is aliasing. */ | |
1372 | inline varpool_node *get_alias_target (void); | |
1373 | ||
1374 | /* Output one variable, if necessary. Return whether we output it. */ | |
1375 | bool assemble_decl (void); | |
1376 | ||
1377 | /* For variables in named sections make sure get_variable_section | |
1378 | is called before we switch to those sections. Then section | |
1379 | conflicts between read-only and read-only requiring relocations | |
1380 | sections can be resolved. */ | |
1381 | void finalize_named_section_flags (void); | |
1382 | ||
1383 | /* Call calback on varpool symbol and aliases associated to varpool symbol. | |
1384 | When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are | |
1385 | skipped. */ | |
1386 | bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *), | |
1387 | void *data, | |
1388 | bool include_overwritable); | |
1389 | ||
1390 | /* Return true when variable should be considered externally visible. */ | |
1391 | bool externally_visible_p (void); | |
1392 | ||
1393 | /* Return true when all references to variable must be visible | |
1394 | in ipa_ref_list. | |
1395 | i.e. if the variable is not externally visible or not used in some magic | |
1396 | way (asm statement or such). | |
1397 | The magic uses are all summarized in force_output flag. */ | |
1398 | inline bool all_refs_explicit_p (); | |
1399 | ||
1400 | /* Return true when variable can be removed from variable pool | |
1401 | if all direct calls are eliminated. */ | |
1402 | inline bool can_remove_if_no_refs_p (void); | |
1403 | ||
1404 | /* Return varpool node for given symbol and check it is a function. */ | |
1405 | static inline varpool_node *get (const_tree decl); | |
1406 | ||
1407 | /* Mark DECL as finalized. By finalizing the declaration, frontend instruct | |
1408 | the middle end to output the variable to asm file, if needed or externally | |
1409 | visible. */ | |
1410 | static void finalize_decl (tree decl); | |
1411 | ||
1412 | /* Output all variables enqueued to be assembled. */ | |
1413 | static bool output_variables (void); | |
1414 | ||
1415 | /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful. | |
1416 | Extra name aliases are output whenever DECL is output. */ | |
1417 | static varpool_node * create_extra_name_alias (tree alias, tree decl); | |
1418 | ||
1419 | /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful. | |
1420 | Extra name aliases are output whenever DECL is output. */ | |
1421 | static varpool_node * create_alias (tree, tree); | |
1422 | ||
1423 | /* Dump the variable pool to F. */ | |
1424 | static void dump_varpool (FILE *f); | |
1425 | ||
1426 | /* Dump the variable pool to stderr. */ | |
1427 | static void DEBUG_FUNCTION debug_varpool (void); | |
1428 | ||
1429 | /* Allocate new callgraph node and insert it into basic data structures. */ | |
1430 | static varpool_node *create_empty (void); | |
1431 | ||
1432 | /* Return varpool node assigned to DECL. Create new one when needed. */ | |
1433 | static varpool_node *get_create (tree decl); | |
1434 | ||
1435 | /* Given an assembler name, lookup node. */ | |
1436 | static varpool_node *get_for_asmname (tree asmname); | |
1437 | ||
e1be32b8 | 1438 | /* Set when variable is scheduled to be assembled. */ |
a16eb452 | 1439 | unsigned output : 1; |
e43059ff | 1440 | |
085f6ebf | 1441 | /* Set if the variable is dynamically initialized, except for |
1442 | function local statics. */ | |
1443 | unsigned dynamically_initialized : 1; | |
5e68df57 | 1444 | |
1445 | ENUM_BITFIELD(tls_model) tls_model : 3; | |
3f1f2be0 | 1446 | |
1447 | /* Set if the variable is known to be used by single function only. | |
1448 | This is computed by ipa_signle_use pass and used by late optimizations | |
1449 | in places where optimization would be valid for local static variable | |
1450 | if we did not do any inter-procedural code movement. */ | |
1451 | unsigned used_by_single_function : 1; | |
415d1b9a | 1452 | |
97221fd7 | 1453 | private: |
1454 | /* Assemble thunks and aliases associated to varpool node. */ | |
1455 | void assemble_aliases (void); | |
229dcfae | 1456 | }; |
1457 | ||
cf951b1a | 1458 | /* Every top level asm statement is put into a asm_node. */ |
56af936e | 1459 | |
cf951b1a | 1460 | struct GTY(()) asm_node { |
56af936e | 1461 | /* Next asm node. */ |
cf951b1a | 1462 | struct asm_node *next; |
56af936e | 1463 | /* String for this asm node. */ |
1464 | tree asm_str; | |
1465 | /* Ordering of all cgraph nodes. */ | |
1466 | int order; | |
1467 | }; | |
1468 | ||
2dc9831f | 1469 | /* Report whether or not THIS symtab node is a function, aka cgraph_node. */ |
1470 | ||
1471 | template <> | |
1472 | template <> | |
1473 | inline bool | |
13cbeaac | 1474 | is_a_helper <cgraph_node *>::test (symtab_node *p) |
2dc9831f | 1475 | { |
415d1b9a | 1476 | return p && p->type == SYMTAB_FUNCTION; |
2dc9831f | 1477 | } |
1478 | ||
1479 | /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */ | |
1480 | ||
1481 | template <> | |
1482 | template <> | |
1483 | inline bool | |
13cbeaac | 1484 | is_a_helper <varpool_node *>::test (symtab_node *p) |
2dc9831f | 1485 | { |
415d1b9a | 1486 | return p && p->type == SYMTAB_VARIABLE; |
2dc9831f | 1487 | } |
1488 | ||
452659af | 1489 | extern GTY(()) symtab_node *symtab_nodes; |
5d31fea4 | 1490 | extern GTY(()) int cgraph_n_nodes; |
d7c6d889 | 1491 | extern GTY(()) int cgraph_max_uid; |
dd1c9157 | 1492 | extern GTY(()) int cgraph_edge_max_uid; |
80a85d8a | 1493 | extern bool cgraph_global_info_ready; |
523c1122 | 1494 | enum cgraph_state |
1495 | { | |
ff2a5ada | 1496 | /* Frontend is parsing and finalizing functions. */ |
1497 | CGRAPH_STATE_PARSING, | |
523c1122 | 1498 | /* Callgraph is being constructed. It is safe to add new functions. */ |
1499 | CGRAPH_STATE_CONSTRUCTION, | |
da4b8721 | 1500 | /* Callgraph is being at LTO time. */ |
1501 | CGRAPH_LTO_STREAMING, | |
523c1122 | 1502 | /* Callgraph is built and IPA passes are being run. */ |
1503 | CGRAPH_STATE_IPA, | |
f517b36e | 1504 | /* Callgraph is built and all functions are transformed to SSA form. */ |
1505 | CGRAPH_STATE_IPA_SSA, | |
523c1122 | 1506 | /* Functions are now ordered and being passed to RTL expanders. */ |
1507 | CGRAPH_STATE_EXPANSION, | |
1508 | /* All cgraph expansion is done. */ | |
1509 | CGRAPH_STATE_FINISHED | |
1510 | }; | |
1511 | extern enum cgraph_state cgraph_state; | |
3f82b628 | 1512 | extern bool cgraph_function_flags_ready; |
ff2a5ada | 1513 | extern cgraph_node_set cgraph_new_nodes; |
ae01b312 | 1514 | |
cf951b1a | 1515 | extern GTY(()) struct asm_node *asm_nodes; |
0704fb2e | 1516 | extern GTY(()) int symtab_order; |
48669653 | 1517 | extern bool cpp_implicit_aliases_done; |
229dcfae | 1518 | |
0704fb2e | 1519 | /* In symtab.c */ |
452659af | 1520 | symtab_node *symtab_node_for_asm (const_tree asmname); |
0704fb2e | 1521 | |
ae01b312 | 1522 | /* In cgraph.c */ |
adf64732 | 1523 | void release_function_body (tree); |
9bab6a70 | 1524 | struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void); |
415d1b9a | 1525 | void cgraph_remove_edge (struct cgraph_edge *); |
1526 | ||
4d044066 | 1527 | void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true); |
8d8c4f3e | 1528 | void cgraph_update_edges_for_call_stmt (gimple, tree, gimple); |
eeba438a | 1529 | struct cgraph_local_info *cgraph_local_info (tree); |
1530 | struct cgraph_global_info *cgraph_global_info (tree); | |
1531 | struct cgraph_rtl_info *cgraph_rtl_info (tree); | |
f41db742 | 1532 | void cgraph_call_edge_duplication_hooks (struct cgraph_edge *, |
1533 | struct cgraph_edge *); | |
ae01b312 | 1534 | |
5bd74231 | 1535 | bool cgraph_function_possibly_inlined_p (tree); |
415d1b9a | 1536 | bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *); |
1537 | void cgraph_redirect_edge_callee (struct cgraph_edge *, cgraph_node *); | |
1538 | struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, | |
1539 | cgraph_node *); | |
5bd74231 | 1540 | |
326a9581 | 1541 | const char* cgraph_inline_failed_string (cgraph_inline_failed_t); |
4f13e575 | 1542 | cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t); |
e1be32b8 | 1543 | |
74fa5f1c | 1544 | bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution); |
dd1c9157 | 1545 | typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *); |
415d1b9a | 1546 | typedef void (*cgraph_node_hook)(cgraph_node *, void *); |
098f44bc | 1547 | typedef void (*varpool_node_hook)(varpool_node *, void *); |
dd1c9157 | 1548 | typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *, |
1549 | void *); | |
415d1b9a | 1550 | typedef void (*cgraph_2node_hook)(cgraph_node *, cgraph_node *, |
dd1c9157 | 1551 | void *); |
1552 | struct cgraph_edge_hook_list; | |
1553 | struct cgraph_node_hook_list; | |
332db80a | 1554 | struct varpool_node_hook_list; |
dd1c9157 | 1555 | struct cgraph_2edge_hook_list; |
1556 | struct cgraph_2node_hook_list; | |
1557 | struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *); | |
1558 | void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *); | |
415d1b9a | 1559 | cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook, |
dd1c9157 | 1560 | void *); |
415d1b9a | 1561 | void cgraph_remove_node_removal_hook (cgraph_node_hook_list *); |
332db80a | 1562 | struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook, |
1563 | void *); | |
1564 | void varpool_remove_node_removal_hook (struct varpool_node_hook_list *); | |
415d1b9a | 1565 | cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook, |
50828ed8 | 1566 | void *); |
415d1b9a | 1567 | void cgraph_remove_function_insertion_hook (cgraph_node_hook_list *); |
332db80a | 1568 | struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook, |
1569 | void *); | |
1570 | void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *); | |
dd1c9157 | 1571 | struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *); |
1572 | void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *); | |
1573 | struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *); | |
1574 | void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *); | |
c596d830 | 1575 | gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *); |
12d5ae9f | 1576 | struct cgraph_edge * |
4d044066 | 1577 | cgraph_turn_edge_to_speculative (struct cgraph_edge *, |
415d1b9a | 1578 | cgraph_node *, |
4d044066 | 1579 | gcov_type, int); |
1580 | void cgraph_speculative_call_info (struct cgraph_edge *, | |
1581 | struct cgraph_edge *&, | |
1582 | struct cgraph_edge *&, | |
1583 | struct ipa_ref *&); | |
424a4a92 | 1584 | extern bool gimple_check_call_matching_types (gimple, tree, bool); |
da5e1e7c | 1585 | |
1586 | /* In cgraphunit.c */ | |
cf951b1a | 1587 | struct asm_node *add_asm_node (tree); |
da5e1e7c | 1588 | extern FILE *cgraph_dump_file; |
1589 | void cgraph_finalize_function (tree, bool); | |
cf951b1a | 1590 | void finalize_compilation_unit (void); |
1591 | void compile (void); | |
da5e1e7c | 1592 | void init_cgraph (void); |
3cb3fce5 | 1593 | void cgraph_process_new_functions (void); |
f41db742 | 1594 | void cgraph_process_same_body_aliases (void); |
cc8ef84f | 1595 | /* Initialize datastructures so DECL is a function in lowered gimple form. |
1596 | IN_SSA is true if the gimple is in SSA. */ | |
15ca8f90 | 1597 | basic_block init_lowered_empty_function (tree, bool); |
f41db742 | 1598 | |
1599 | /* In cgraphclones.c */ | |
1600 | ||
1601 | struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *, | |
415d1b9a | 1602 | cgraph_node *, gimple, |
f41db742 | 1603 | unsigned, gcov_type, int, bool); |
f41db742 | 1604 | tree clone_function_name (tree decl, const char *); |
415d1b9a | 1605 | |
f41db742 | 1606 | void cgraph_materialize_all_clones (void); |
415d1b9a | 1607 | void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *, |
da5e1e7c | 1608 | bool, bitmap, bool, bitmap, basic_block); |
12d5ae9f | 1609 | struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree); |
da5e1e7c | 1610 | |
79acaae1 | 1611 | /* In cgraphbuild.c */ |
1612 | unsigned int rebuild_cgraph_edges (void); | |
ea7e866e | 1613 | void cgraph_rebuild_references (void); |
ccf4ab6b | 1614 | int compute_call_stmt_bb_frequency (tree, basic_block bb); |
da5e1e7c | 1615 | void record_references_in_initializer (tree, bool); |
79acaae1 | 1616 | |
65c1a668 | 1617 | /* In ipa.c */ |
91f0ab48 | 1618 | bool symtab_remove_unreachable_nodes (bool, FILE *); |
13f90d63 | 1619 | cgraph_node_set cgraph_node_set_new (void); |
1620 | cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set, | |
415d1b9a | 1621 | cgraph_node *); |
1622 | void cgraph_node_set_add (cgraph_node_set, cgraph_node *); | |
1623 | void cgraph_node_set_remove (cgraph_node_set, cgraph_node *); | |
13f90d63 | 1624 | void dump_cgraph_node_set (FILE *, cgraph_node_set); |
1625 | void debug_cgraph_node_set (cgraph_node_set); | |
19ad01f7 | 1626 | void free_cgraph_node_set (cgraph_node_set); |
da5e1e7c | 1627 | void cgraph_build_static_cdtor (char which, tree body, int priority); |
13f90d63 | 1628 | |
0cddb138 | 1629 | varpool_node_set varpool_node_set_new (void); |
1630 | varpool_node_set_iterator varpool_node_set_find (varpool_node_set, | |
098f44bc | 1631 | varpool_node *); |
1632 | void varpool_node_set_add (varpool_node_set, varpool_node *); | |
1633 | void varpool_node_set_remove (varpool_node_set, varpool_node *); | |
0cddb138 | 1634 | void dump_varpool_node_set (FILE *, varpool_node_set); |
1635 | void debug_varpool_node_set (varpool_node_set); | |
19ad01f7 | 1636 | void free_varpool_node_set (varpool_node_set); |
8dfbf71d | 1637 | void ipa_discover_readonly_nonaddressable_vars (void); |
65c1a668 | 1638 | |
13f90d63 | 1639 | /* In predict.c */ |
11b73810 | 1640 | bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e); |
1641 | ||
1d416bd7 | 1642 | /* In varpool.c */ |
6f932b06 | 1643 | void varpool_reset_queue (void); |
df8d3e89 | 1644 | tree ctor_for_folding (tree); |
124f4875 | 1645 | void varpool_add_new_variable (tree); |
c9aa6453 | 1646 | void symtab_initialize_asm_name_hash (void); |
452659af | 1647 | void symtab_prevail_in_asm_name_hash (symtab_node *node); |
1d416bd7 | 1648 | |
9ed99284 | 1649 | /* In cgraph.c */ |
1650 | extern void change_decl_assembler_name (tree, tree); | |
960df590 | 1651 | |
415d1b9a | 1652 | /* Return true when the symbol is real symbol, i.e. it is not inline clone |
1653 | or abstract function kept for debug info purposes only. */ | |
1654 | inline bool | |
1655 | symtab_node::real_symbol_p (void) | |
1656 | { | |
1657 | cgraph_node *cnode; | |
1658 | ||
1659 | if (DECL_ABSTRACT (decl)) | |
1660 | return false; | |
1661 | if (!is_a <cgraph_node *> (this)) | |
1662 | return true; | |
1663 | cnode = dyn_cast <cgraph_node *> (this); | |
1664 | if (cnode->global.inlined_to) | |
1665 | return false; | |
1666 | return true; | |
1667 | } | |
1668 | ||
56ac70ed | 1669 | /* Return true if DECL should have entry in symbol table if used. |
1670 | Those are functions and static & external veriables*/ | |
1671 | ||
85d7c6da | 1672 | static inline bool |
56ac70ed | 1673 | decl_in_symtab_p (const_tree decl) |
1674 | { | |
1675 | return (TREE_CODE (decl) == FUNCTION_DECL | |
1676 | || (TREE_CODE (decl) == VAR_DECL | |
1677 | && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))); | |
1678 | } | |
1679 | ||
415d1b9a | 1680 | inline bool |
1681 | symtab_node::in_same_comdat_group_p (symtab_node *target) | |
8c016392 | 1682 | { |
415d1b9a | 1683 | symtab_node *source = this; |
8c016392 | 1684 | |
415d1b9a | 1685 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (target)) |
1686 | { | |
1687 | if (cn->global.inlined_to) | |
1688 | source = cn->global.inlined_to; | |
1689 | } | |
1690 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (target)) | |
1691 | { | |
1692 | if (cn->global.inlined_to) | |
1693 | target = cn->global.inlined_to; | |
1694 | } | |
1695 | ||
1696 | return source->get_comdat_group () == target->get_comdat_group (); | |
b6c89d32 | 1697 | } |
1698 | ||
415d1b9a | 1699 | /* Return node that alias is aliasing. */ |
1700 | ||
1701 | inline symtab_node * | |
1702 | symtab_node::get_alias_target (void) | |
b6c89d32 | 1703 | { |
415d1b9a | 1704 | struct ipa_ref *ref = NULL; |
1705 | iterate_reference (0, ref); | |
1706 | gcc_checking_assert (ref->use == IPA_REF_ALIAS); | |
1707 | return ref->referred; | |
b6c89d32 | 1708 | } |
1709 | ||
415d1b9a | 1710 | /* Return next reachable static symbol with initializer after the node. */ |
1711 | inline symtab_node * | |
1712 | symtab_node::next_defined_symbol (void) | |
cfbe30aa | 1713 | { |
415d1b9a | 1714 | symtab_node *node1 = next; |
1715 | ||
1716 | for (; node1; node1 = node1->next) | |
1717 | if (node1->definition) | |
1718 | return node1; | |
1719 | ||
1720 | return NULL; | |
cfbe30aa | 1721 | } |
1722 | ||
1723 | /* Return varpool node for given symbol and check it is a function. */ | |
97221fd7 | 1724 | inline varpool_node * |
1725 | varpool_node::get (const_tree decl) | |
cfbe30aa | 1726 | { |
1727 | gcc_checking_assert (TREE_CODE (decl) == VAR_DECL); | |
415d1b9a | 1728 | return dyn_cast<varpool_node *> (symtab_node::get (decl)); |
cfbe30aa | 1729 | } |
1730 | ||
1731 | /* Walk all symbols. */ | |
1732 | #define FOR_EACH_SYMBOL(node) \ | |
02774f2d | 1733 | for ((node) = symtab_nodes; (node); (node) = (node)->next) |
b6c89d32 | 1734 | |
52638b9c | 1735 | /* Return first static symbol with definition. */ |
1736 | static inline symtab_node * | |
1737 | symtab_first_defined_symbol (void) | |
1738 | { | |
1739 | symtab_node *node; | |
1740 | ||
1741 | for (node = symtab_nodes; node; node = node->next) | |
1742 | if (node->definition) | |
1743 | return node; | |
1744 | ||
1745 | return NULL; | |
1746 | } | |
1747 | ||
52638b9c | 1748 | /* Walk all symbols with definitions in current unit. */ |
1749 | #define FOR_EACH_DEFINED_SYMBOL(node) \ | |
1750 | for ((node) = symtab_first_defined_symbol (); (node); \ | |
415d1b9a | 1751 | (node) = node->next_defined_symbol ()) |
ff2a5ada | 1752 | |
1753 | /* Return first variable. */ | |
098f44bc | 1754 | static inline varpool_node * |
ff2a5ada | 1755 | varpool_first_variable (void) |
1756 | { | |
452659af | 1757 | symtab_node *node; |
02774f2d | 1758 | for (node = symtab_nodes; node; node = node->next) |
13cbeaac | 1759 | if (varpool_node *vnode = dyn_cast <varpool_node *> (node)) |
2dc9831f | 1760 | return vnode; |
ff2a5ada | 1761 | return NULL; |
1762 | } | |
1763 | ||
1764 | /* Return next variable after NODE. */ | |
098f44bc | 1765 | static inline varpool_node * |
1766 | varpool_next_variable (varpool_node *node) | |
ff2a5ada | 1767 | { |
452659af | 1768 | symtab_node *node1 = node->next; |
02774f2d | 1769 | for (; node1; node1 = node1->next) |
13cbeaac | 1770 | if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1)) |
2dc9831f | 1771 | return vnode1; |
ff2a5ada | 1772 | return NULL; |
1773 | } | |
1774 | /* Walk all variables. */ | |
1775 | #define FOR_EACH_VARIABLE(node) \ | |
1776 | for ((node) = varpool_first_variable (); \ | |
1777 | (node); \ | |
1778 | (node) = varpool_next_variable ((node))) | |
1779 | ||
52638b9c | 1780 | /* Return first static variable with initializer. */ |
098f44bc | 1781 | static inline varpool_node * |
960df590 | 1782 | varpool_first_static_initializer (void) |
1783 | { | |
452659af | 1784 | symtab_node *node; |
02774f2d | 1785 | for (node = symtab_nodes; node; node = node->next) |
960df590 | 1786 | { |
13cbeaac | 1787 | varpool_node *vnode = dyn_cast <varpool_node *> (node); |
02774f2d | 1788 | if (vnode && DECL_INITIAL (node->decl)) |
2dc9831f | 1789 | return vnode; |
960df590 | 1790 | } |
1791 | return NULL; | |
1792 | } | |
1793 | ||
52638b9c | 1794 | /* Return next static variable with initializer after NODE. */ |
098f44bc | 1795 | static inline varpool_node * |
1796 | varpool_next_static_initializer (varpool_node *node) | |
960df590 | 1797 | { |
452659af | 1798 | symtab_node *node1 = node->next; |
02774f2d | 1799 | for (; node1; node1 = node1->next) |
960df590 | 1800 | { |
13cbeaac | 1801 | varpool_node *vnode1 = dyn_cast <varpool_node *> (node1); |
02774f2d | 1802 | if (vnode1 && DECL_INITIAL (node1->decl)) |
2dc9831f | 1803 | return vnode1; |
960df590 | 1804 | } |
1805 | return NULL; | |
1806 | } | |
1807 | ||
1808 | /* Walk all static variables with initializer set. */ | |
1809 | #define FOR_EACH_STATIC_INITIALIZER(node) \ | |
1810 | for ((node) = varpool_first_static_initializer (); (node); \ | |
1811 | (node) = varpool_next_static_initializer (node)) | |
0704fb2e | 1812 | |
52638b9c | 1813 | /* Return first static variable with definition. */ |
098f44bc | 1814 | static inline varpool_node * |
ff2a5ada | 1815 | varpool_first_defined_variable (void) |
0704fb2e | 1816 | { |
452659af | 1817 | symtab_node *node; |
02774f2d | 1818 | for (node = symtab_nodes; node; node = node->next) |
0704fb2e | 1819 | { |
13cbeaac | 1820 | varpool_node *vnode = dyn_cast <varpool_node *> (node); |
02774f2d | 1821 | if (vnode && vnode->definition) |
2dc9831f | 1822 | return vnode; |
0704fb2e | 1823 | } |
1824 | return NULL; | |
1825 | } | |
1826 | ||
52638b9c | 1827 | /* Return next static variable with definition after NODE. */ |
098f44bc | 1828 | static inline varpool_node * |
1829 | varpool_next_defined_variable (varpool_node *node) | |
0704fb2e | 1830 | { |
452659af | 1831 | symtab_node *node1 = node->next; |
02774f2d | 1832 | for (; node1; node1 = node1->next) |
0704fb2e | 1833 | { |
13cbeaac | 1834 | varpool_node *vnode1 = dyn_cast <varpool_node *> (node1); |
02774f2d | 1835 | if (vnode1 && vnode1->definition) |
2dc9831f | 1836 | return vnode1; |
0704fb2e | 1837 | } |
1838 | return NULL; | |
1839 | } | |
7c455d87 | 1840 | /* Walk all variables with definitions in current unit. */ |
1841 | #define FOR_EACH_DEFINED_VARIABLE(node) \ | |
ff2a5ada | 1842 | for ((node) = varpool_first_defined_variable (); (node); \ |
1843 | (node) = varpool_next_defined_variable (node)) | |
960df590 | 1844 | |
91bf9d9a | 1845 | /* Return first function with body defined. */ |
415d1b9a | 1846 | static inline cgraph_node * |
91bf9d9a | 1847 | cgraph_first_defined_function (void) |
1848 | { | |
452659af | 1849 | symtab_node *node; |
02774f2d | 1850 | for (node = symtab_nodes; node; node = node->next) |
91bf9d9a | 1851 | { |
13cbeaac | 1852 | cgraph_node *cn = dyn_cast <cgraph_node *> (node); |
02774f2d | 1853 | if (cn && cn->definition) |
2dc9831f | 1854 | return cn; |
91bf9d9a | 1855 | } |
1856 | return NULL; | |
1857 | } | |
1858 | ||
11ec81bd | 1859 | /* Return next function with body defined after NODE. */ |
415d1b9a | 1860 | static inline cgraph_node * |
1861 | cgraph_next_defined_function (cgraph_node *node) | |
91bf9d9a | 1862 | { |
452659af | 1863 | symtab_node *node1 = node->next; |
02774f2d | 1864 | for (; node1; node1 = node1->next) |
91bf9d9a | 1865 | { |
13cbeaac | 1866 | cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1); |
02774f2d | 1867 | if (cn1 && cn1->definition) |
2dc9831f | 1868 | return cn1; |
91bf9d9a | 1869 | } |
1870 | return NULL; | |
1871 | } | |
1872 | ||
1873 | /* Walk all functions with body defined. */ | |
1874 | #define FOR_EACH_DEFINED_FUNCTION(node) \ | |
1875 | for ((node) = cgraph_first_defined_function (); (node); \ | |
0704fb2e | 1876 | (node) = cgraph_next_defined_function ((node))) |
1877 | ||
1878 | /* Return first function. */ | |
415d1b9a | 1879 | static inline cgraph_node * |
0704fb2e | 1880 | cgraph_first_function (void) |
1881 | { | |
452659af | 1882 | symtab_node *node; |
02774f2d | 1883 | for (node = symtab_nodes; node; node = node->next) |
13cbeaac | 1884 | if (cgraph_node *cn = dyn_cast <cgraph_node *> (node)) |
2dc9831f | 1885 | return cn; |
0704fb2e | 1886 | return NULL; |
1887 | } | |
1888 | ||
1889 | /* Return next function. */ | |
415d1b9a | 1890 | static inline cgraph_node * |
1891 | cgraph_next_function (cgraph_node *node) | |
0704fb2e | 1892 | { |
452659af | 1893 | symtab_node *node1 = node->next; |
02774f2d | 1894 | for (; node1; node1 = node1->next) |
13cbeaac | 1895 | if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1)) |
2dc9831f | 1896 | return cn1; |
0704fb2e | 1897 | return NULL; |
1898 | } | |
7c455d87 | 1899 | /* Walk all functions. */ |
1900 | #define FOR_EACH_FUNCTION(node) \ | |
0704fb2e | 1901 | for ((node) = cgraph_first_function (); (node); \ |
1902 | (node) = cgraph_next_function ((node))) | |
91bf9d9a | 1903 | |
415d1b9a | 1904 | /* Return true when callgraph node is a function with Gimple body defined |
91bf9d9a | 1905 | in current unit. Functions can also be define externally or they |
1906 | can be thunks with no Gimple representation. | |
1907 | ||
1908 | Note that at WPA stage, the function body may not be present in memory. */ | |
1909 | ||
415d1b9a | 1910 | inline bool |
1911 | cgraph_node::has_gimple_body_p (void) | |
91bf9d9a | 1912 | { |
415d1b9a | 1913 | return definition && !thunk.thunk_p && !alias; |
91bf9d9a | 1914 | } |
1915 | ||
1916 | /* Return first function with body defined. */ | |
415d1b9a | 1917 | static inline cgraph_node * |
91bf9d9a | 1918 | cgraph_first_function_with_gimple_body (void) |
1919 | { | |
452659af | 1920 | symtab_node *node; |
02774f2d | 1921 | for (node = symtab_nodes; node; node = node->next) |
91bf9d9a | 1922 | { |
13cbeaac | 1923 | cgraph_node *cn = dyn_cast <cgraph_node *> (node); |
415d1b9a | 1924 | if (cn && cn->has_gimple_body_p ()) |
2dc9831f | 1925 | return cn; |
91bf9d9a | 1926 | } |
1927 | return NULL; | |
1928 | } | |
1929 | ||
1930 | /* Return next reachable static variable with initializer after NODE. */ | |
415d1b9a | 1931 | static inline cgraph_node * |
1932 | cgraph_next_function_with_gimple_body (cgraph_node *node) | |
91bf9d9a | 1933 | { |
452659af | 1934 | symtab_node *node1 = node->next; |
02774f2d | 1935 | for (; node1; node1 = node1->next) |
91bf9d9a | 1936 | { |
13cbeaac | 1937 | cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1); |
415d1b9a | 1938 | if (cn1 && cn1->has_gimple_body_p ()) |
2dc9831f | 1939 | return cn1; |
91bf9d9a | 1940 | } |
1941 | return NULL; | |
1942 | } | |
1943 | ||
1944 | /* Walk all functions with body defined. */ | |
1945 | #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \ | |
1946 | for ((node) = cgraph_first_function_with_gimple_body (); (node); \ | |
1947 | (node) = cgraph_next_function_with_gimple_body (node)) | |
1948 | ||
604cde73 | 1949 | /* Create a new static variable of type TYPE. */ |
1950 | tree add_new_static_var (tree type); | |
1951 | ||
13f90d63 | 1952 | /* Return true if iterator CSI points to nothing. */ |
1953 | static inline bool | |
1954 | csi_end_p (cgraph_node_set_iterator csi) | |
1955 | { | |
f1f41a6c | 1956 | return csi.index >= csi.set->nodes.length (); |
13f90d63 | 1957 | } |
1958 | ||
1959 | /* Advance iterator CSI. */ | |
1960 | static inline void | |
1961 | csi_next (cgraph_node_set_iterator *csi) | |
1962 | { | |
1963 | csi->index++; | |
1964 | } | |
1965 | ||
1966 | /* Return the node pointed to by CSI. */ | |
415d1b9a | 1967 | static inline cgraph_node * |
13f90d63 | 1968 | csi_node (cgraph_node_set_iterator csi) |
1969 | { | |
f1f41a6c | 1970 | return csi.set->nodes[csi.index]; |
13f90d63 | 1971 | } |
1972 | ||
1973 | /* Return an iterator to the first node in SET. */ | |
1974 | static inline cgraph_node_set_iterator | |
1975 | csi_start (cgraph_node_set set) | |
1976 | { | |
1977 | cgraph_node_set_iterator csi; | |
1978 | ||
1979 | csi.set = set; | |
1980 | csi.index = 0; | |
1981 | return csi; | |
1982 | } | |
1983 | ||
1984 | /* Return true if SET contains NODE. */ | |
1985 | static inline bool | |
415d1b9a | 1986 | cgraph_node_in_set_p (cgraph_node *node, cgraph_node_set set) |
13f90d63 | 1987 | { |
1988 | cgraph_node_set_iterator csi; | |
1989 | csi = cgraph_node_set_find (set, node); | |
1990 | return !csi_end_p (csi); | |
1991 | } | |
1992 | ||
1993 | /* Return number of nodes in SET. */ | |
1994 | static inline size_t | |
1995 | cgraph_node_set_size (cgraph_node_set set) | |
1996 | { | |
f1f41a6c | 1997 | return set->nodes.length (); |
13f90d63 | 1998 | } |
1999 | ||
0cddb138 | 2000 | /* Return true if iterator VSI points to nothing. */ |
2001 | static inline bool | |
2002 | vsi_end_p (varpool_node_set_iterator vsi) | |
2003 | { | |
f1f41a6c | 2004 | return vsi.index >= vsi.set->nodes.length (); |
0cddb138 | 2005 | } |
2006 | ||
2007 | /* Advance iterator VSI. */ | |
2008 | static inline void | |
2009 | vsi_next (varpool_node_set_iterator *vsi) | |
2010 | { | |
2011 | vsi->index++; | |
2012 | } | |
2013 | ||
2014 | /* Return the node pointed to by VSI. */ | |
098f44bc | 2015 | static inline varpool_node * |
0cddb138 | 2016 | vsi_node (varpool_node_set_iterator vsi) |
2017 | { | |
f1f41a6c | 2018 | return vsi.set->nodes[vsi.index]; |
0cddb138 | 2019 | } |
2020 | ||
2021 | /* Return an iterator to the first node in SET. */ | |
2022 | static inline varpool_node_set_iterator | |
2023 | vsi_start (varpool_node_set set) | |
2024 | { | |
2025 | varpool_node_set_iterator vsi; | |
2026 | ||
2027 | vsi.set = set; | |
2028 | vsi.index = 0; | |
2029 | return vsi; | |
2030 | } | |
2031 | ||
0cddb138 | 2032 | /* Return number of nodes in SET. */ |
2033 | static inline size_t | |
2034 | varpool_node_set_size (varpool_node_set set) | |
2035 | { | |
f1f41a6c | 2036 | return set->nodes.length (); |
0cddb138 | 2037 | } |
2038 | ||
9261e5d9 | 2039 | /* Uniquize all constants that appear in memory. |
2040 | Each constant in memory thus far output is recorded | |
2041 | in `const_desc_table'. */ | |
2042 | ||
2043 | struct GTY(()) constant_descriptor_tree { | |
2044 | /* A MEM for the constant. */ | |
2045 | rtx rtl; | |
48e1416a | 2046 | |
9261e5d9 | 2047 | /* The value of the constant. */ |
2048 | tree value; | |
2049 | ||
2050 | /* Hash of value. Computing the hash from value each time | |
2051 | hashfn is called can't work properly, as that means recursive | |
2052 | use of the hash table during hash table expansion. */ | |
2053 | hashval_t hash; | |
2054 | }; | |
2055 | ||
bf7d782b | 2056 | /* Return true if set is nonempty. */ |
2057 | static inline bool | |
2058 | cgraph_node_set_nonempty_p (cgraph_node_set set) | |
2059 | { | |
f1f41a6c | 2060 | return !set->nodes.is_empty (); |
bf7d782b | 2061 | } |
2062 | ||
2063 | /* Return true if set is nonempty. */ | |
2064 | static inline bool | |
2065 | varpool_node_set_nonempty_p (varpool_node_set set) | |
2066 | { | |
f1f41a6c | 2067 | return !set->nodes.is_empty (); |
bf7d782b | 2068 | } |
2069 | ||
415d1b9a | 2070 | /* Return true when function is only called directly or it has alias. |
59dd4830 | 2071 | i.e. it is not externally visible, address was not taken and |
2072 | it is not used in any other non-standard way. */ | |
2073 | ||
415d1b9a | 2074 | inline bool |
2075 | cgraph_node::only_called_directly_or_aliased_p (void) | |
2076 | { | |
2077 | gcc_assert (!global.inlined_to); | |
2078 | return (!force_output && !address_taken | |
2079 | && !used_from_other_partition | |
2080 | && !DECL_VIRTUAL_P (decl) | |
2081 | && !DECL_STATIC_CONSTRUCTOR (decl) | |
2082 | && !DECL_STATIC_DESTRUCTOR (decl) | |
2083 | && !externally_visible); | |
59dd4830 | 2084 | } |
2085 | ||
97221fd7 | 2086 | /* Return true when variable can be removed from variable pool |
7410370b | 2087 | if all direct calls are eliminated. */ |
2088 | ||
97221fd7 | 2089 | inline bool |
2090 | varpool_node::can_remove_if_no_refs_p (void) | |
7410370b | 2091 | { |
97221fd7 | 2092 | if (DECL_EXTERNAL (decl)) |
aa419a52 | 2093 | return true; |
97221fd7 | 2094 | return (!force_output && !used_from_other_partition |
2095 | && ((DECL_COMDAT (decl) | |
2096 | && !forced_by_abi | |
2097 | && !used_from_object_file_p ()) | |
2098 | || !externally_visible | |
2099 | || DECL_HAS_VALUE_EXPR_P (decl))); | |
7410370b | 2100 | } |
2101 | ||
97221fd7 | 2102 | /* Return true when all references to variable must be visible in ipa_ref_list. |
8dfbf71d | 2103 | i.e. if the variable is not externally visible or not used in some magic |
2104 | way (asm statement or such). | |
0a10fd82 | 2105 | The magic uses are all summarized in force_output flag. */ |
8dfbf71d | 2106 | |
97221fd7 | 2107 | inline bool |
2108 | varpool_node::all_refs_explicit_p () | |
8dfbf71d | 2109 | { |
97221fd7 | 2110 | return (definition |
2111 | && !externally_visible | |
2112 | && !used_from_other_partition | |
2113 | && !force_output); | |
8dfbf71d | 2114 | } |
2115 | ||
9261e5d9 | 2116 | /* Constant pool accessor function. */ |
2117 | htab_t constant_pool_htab (void); | |
13f90d63 | 2118 | |
415d1b9a | 2119 | /* Return node that alias is aliasing. */ |
c70f46b0 | 2120 | |
415d1b9a | 2121 | inline cgraph_node * |
2122 | cgraph_node::get_alias_target (void) | |
e0eaac80 | 2123 | { |
415d1b9a | 2124 | return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ()); |
e0eaac80 | 2125 | } |
2126 | ||
97221fd7 | 2127 | /* Return node that alias is aliasing. */ |
2128 | ||
2129 | inline varpool_node * | |
2130 | varpool_node::get_alias_target (void) | |
74fa5f1c | 2131 | { |
97221fd7 | 2132 | return dyn_cast <varpool_node *> (symtab_node::get_alias_target ()); |
74fa5f1c | 2133 | } |
2134 | ||
415d1b9a | 2135 | /* Given function symbol, walk the alias chain to return the function node |
2136 | is alias of. Do not walk through thunks. | |
9d75589a | 2137 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ |
74fa5f1c | 2138 | |
415d1b9a | 2139 | inline cgraph_node * |
2140 | cgraph_node::ultimate_alias_target (enum availability *availability) | |
74fa5f1c | 2141 | { |
415d1b9a | 2142 | cgraph_node *n = dyn_cast <cgraph_node *> (symtab_node::ultimate_alias_target |
2143 | (availability)); | |
48669653 | 2144 | if (!n && availability) |
c70f46b0 | 2145 | *availability = AVAIL_NOT_AVAILABLE; |
15ca8f90 | 2146 | return n; |
74fa5f1c | 2147 | } |
97221fd7 | 2148 | |
2149 | /* For given variable pool node, walk the alias chain to return the function | |
2150 | the variable is alias of. Do not walk through thunks. | |
9d75589a | 2151 | When AVAILABILITY is non-NULL, get minimal availability in the chain. */ |
e0eaac80 | 2152 | |
97221fd7 | 2153 | inline varpool_node * |
2154 | varpool_node::ultimate_alias_target (availability *availability) | |
e0eaac80 | 2155 | { |
97221fd7 | 2156 | varpool_node *n = dyn_cast <varpool_node *> |
2157 | (symtab_node::ultimate_alias_target (availability)); | |
6cdce0f6 | 2158 | |
48669653 | 2159 | if (!n && availability) |
e0eaac80 | 2160 | *availability = AVAIL_NOT_AVAILABLE; |
15ca8f90 | 2161 | return n; |
e0eaac80 | 2162 | } |
2163 | ||
17c205c9 | 2164 | /* Return true when the edge E represents a direct recursion. */ |
2165 | static inline bool | |
2166 | cgraph_edge_recursive_p (struct cgraph_edge *e) | |
2167 | { | |
415d1b9a | 2168 | cgraph_node *callee = e->callee->ultimate_alias_target (); |
17c205c9 | 2169 | if (e->caller->global.inlined_to) |
02774f2d | 2170 | return e->caller->global.inlined_to->decl == callee->decl; |
17c205c9 | 2171 | else |
02774f2d | 2172 | return e->caller->decl == callee->decl; |
17c205c9 | 2173 | } |
4c0315d0 | 2174 | |
2175 | /* Return true if the TM_CLONE bit is set for a given FNDECL. */ | |
2176 | static inline bool | |
2177 | decl_is_tm_clone (const_tree fndecl) | |
2178 | { | |
415d1b9a | 2179 | cgraph_node *n = cgraph_node::get (fndecl); |
4c0315d0 | 2180 | if (n) |
2181 | return n->tm_clone; | |
2182 | return false; | |
2183 | } | |
da5e1e7c | 2184 | |
2185 | /* Likewise indicate that a node is needed, i.e. reachable via some | |
2186 | external means. */ | |
2187 | ||
415d1b9a | 2188 | inline void |
2189 | cgraph_node::mark_force_output (void) | |
468088ac | 2190 | { |
415d1b9a | 2191 | force_output = 1; |
2192 | gcc_checking_assert (!global.inlined_to); | |
468088ac | 2193 | } |
2194 | ||
ae01b312 | 2195 | #endif /* GCC_CGRAPH_H */ |