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