fwprop: Fix single_use_p calculation
[official-gcc.git] / gcc / cgraph.h
blob4a1f89920f56b685c1f33843fb86848b5847cbeb
1 /* Callgraph handling code.
2 Copyright (C) 2003-2021 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
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.
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.
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/>. */
21 #ifndef GCC_CGRAPH_H
22 #define GCC_CGRAPH_H
24 #include "profile-count.h"
25 #include "ipa-ref.h"
26 #include "plugin-api.h"
27 #include "ipa-param-manipulation.h"
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);
37 class ipa_opt_pass_d;
38 typedef ipa_opt_pass_d *ipa_opt_pass;
40 /* Symbol table consists of functions and variables.
41 TODO: add labels and CONST_DECLs. */
42 enum symtab_type
44 SYMTAB_SYMBOL,
45 SYMTAB_FUNCTION,
46 SYMTAB_VARIABLE
49 /* Section names are stored as reference counted strings in GGC safe hashtable
50 (to make them survive through PCH). */
52 struct GTY((for_user)) section_hash_entry
54 int ref_count;
55 char *name; /* As long as this datastructure stays in GGC, we cannot put
56 string at the tail of structure of GGC dies in horrible
57 way */
60 struct section_name_hasher : ggc_ptr_hash<section_hash_entry>
62 typedef const char *compare_type;
64 static hashval_t hash (section_hash_entry *);
65 static bool equal (section_hash_entry *, const char *);
68 enum availability
70 /* Not yet set by cgraph_function_body_availability. */
71 AVAIL_UNSET,
72 /* Function body/variable initializer is unknown. */
73 AVAIL_NOT_AVAILABLE,
74 /* Function body/variable initializer is known but might be replaced
75 by a different one from other compilation unit and thus needs to
76 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
77 arbitrary side effects on escaping variables and functions, while
78 like AVAILABLE it might access static variables. */
79 AVAIL_INTERPOSABLE,
80 /* Function body/variable initializer is known and will be used in final
81 program. */
82 AVAIL_AVAILABLE,
83 /* Function body/variable initializer is known and all it's uses are
84 explicitly visible within current unit (i.e. it's address is never taken
85 and it is not exported to other units). Currently used only for
86 functions. */
87 AVAIL_LOCAL
90 /* Classification of symbols WRT partitioning. */
91 enum symbol_partitioning_class
93 /* External declarations are ignored by partitioning algorithms and they are
94 added into the boundary later via compute_ltrans_boundary. */
95 SYMBOL_EXTERNAL,
96 /* Partitioned symbols are put into one of partitions. */
97 SYMBOL_PARTITION,
98 /* Duplicated symbols (such as comdat or constant pool references) are
99 copied into every node needing them via add_symbol_to_partition. */
100 SYMBOL_DUPLICATE
103 /* Base of all entries in the symbol table.
104 The symtab_node is inherited by cgraph and varpol nodes. */
105 struct GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
106 chain_next ("%h.next"), chain_prev ("%h.previous")))
107 symtab_node
109 public:
110 friend class symbol_table;
112 /* Constructor. */
113 explicit symtab_node (symtab_type t)
114 : type (t), resolution (LDPR_UNKNOWN), definition (false), alias (false),
115 transparent_alias (false), weakref (false), cpp_implicit_alias (false),
116 symver (false), analyzed (false), writeonly (false),
117 refuse_visibility_changes (false), externally_visible (false),
118 no_reorder (false), force_output (false), forced_by_abi (false),
119 unique_name (false), implicit_section (false), body_removed (false),
120 used_from_other_partition (false), in_other_partition (false),
121 address_taken (false), in_init_priority_hash (false),
122 need_lto_streaming (false), offloadable (false), ifunc_resolver (false),
123 order (false), next_sharing_asm_name (NULL),
124 previous_sharing_asm_name (NULL), same_comdat_group (NULL), ref_list (),
125 alias_target (NULL), lto_file_data (NULL), aux (NULL),
126 x_comdat_group (NULL_TREE), x_section (NULL)
129 /* Return name. */
130 const char *name () const;
132 /* Return dump name. */
133 const char *dump_name () const;
135 /* Return asm name. */
136 const char *asm_name () const;
138 /* Return dump name with assembler name. */
139 const char *dump_asm_name () const;
141 /* Return visibility name. */
142 const char *get_visibility_string () const;
144 /* Return type_name name. */
145 const char *get_symtab_type_string () const;
147 /* Add node into symbol table. This function is not used directly, but via
148 cgraph/varpool node creation routines. */
149 void register_symbol (void);
151 /* Remove symbol from symbol table. */
152 void remove (void);
154 /* Dump symtab node to F. */
155 void dump (FILE *f);
157 /* Dump symtab callgraph in graphviz format. */
158 void dump_graphviz (FILE *f);
160 /* Dump symtab node to stderr. */
161 void DEBUG_FUNCTION debug (void);
163 /* Verify consistency of node. */
164 void DEBUG_FUNCTION verify (void);
166 /* Return ipa reference from this symtab_node to
167 REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type
168 of the use and STMT the statement (if it exists). */
169 ipa_ref *create_reference (symtab_node *referred_node,
170 enum ipa_ref_use use_type);
172 /* Return ipa reference from this symtab_node to
173 REFERRED_NODE or REFERRED_VARPOOL_NODE. USE_TYPE specify type
174 of the use and STMT the statement (if it exists). */
175 ipa_ref *create_reference (symtab_node *referred_node,
176 enum ipa_ref_use use_type, gimple *stmt);
178 /* If VAL is a reference to a function or a variable, add a reference from
179 this symtab_node to the corresponding symbol table node. Return the new
180 reference or NULL if none was created. */
181 ipa_ref *maybe_create_reference (tree val, gimple *stmt);
183 /* Clone all references from symtab NODE to this symtab_node. */
184 void clone_references (symtab_node *node);
186 /* Remove all stmt references in non-speculative references.
187 Those are not maintained during inlining & clonning.
188 The exception are speculative references that are updated along
189 with callgraph edges associated with them. */
190 void clone_referring (symtab_node *node);
192 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
193 ipa_ref *clone_reference (ipa_ref *ref, gimple *stmt);
195 /* Find the structure describing a reference to REFERRED_NODE
196 and associated with statement STMT. */
197 ipa_ref *find_reference (symtab_node *referred_node, gimple *stmt,
198 unsigned int lto_stmt_uid);
200 /* Remove all references that are associated with statement STMT. */
201 void remove_stmt_references (gimple *stmt);
203 /* Remove all stmt references in non-speculative references.
204 Those are not maintained during inlining & clonning.
205 The exception are speculative references that are updated along
206 with callgraph edges associated with them. */
207 void clear_stmts_in_references (void);
209 /* Remove all references in ref list. */
210 void remove_all_references (void);
212 /* Remove all referring items in ref list. */
213 void remove_all_referring (void);
215 /* Dump references in ref list to FILE. */
216 void dump_references (FILE *file);
218 /* Dump referring in list to FILE. */
219 void dump_referring (FILE *);
221 /* Get number of references for this node. */
222 inline unsigned num_references (void)
224 return ref_list.references.length ();
227 /* Iterates I-th reference in the list, REF is also set. */
228 ipa_ref *iterate_reference (unsigned i, ipa_ref *&ref);
230 /* Iterates I-th referring item in the list, REF is also set. */
231 ipa_ref *iterate_referring (unsigned i, ipa_ref *&ref);
233 /* Iterates I-th referring alias item in the list, REF is also set. */
234 ipa_ref *iterate_direct_aliases (unsigned i, ipa_ref *&ref);
236 /* Return true if symtab node and TARGET represents
237 semantically equivalent symbols. */
238 bool semantically_equivalent_p (symtab_node *target);
240 /* Classify symbol symtab node for partitioning. */
241 enum symbol_partitioning_class get_partitioning_class (void);
243 /* Return comdat group. */
244 tree get_comdat_group ()
246 return x_comdat_group;
249 /* Return comdat group as identifier_node. */
250 tree get_comdat_group_id ()
252 if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE)
253 x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group);
254 return x_comdat_group;
257 /* Set comdat group. */
258 void set_comdat_group (tree group)
260 gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE
261 || DECL_P (group));
262 x_comdat_group = group;
265 /* Return section as string. */
266 const char * get_section () const
268 if (!x_section)
269 return NULL;
270 return x_section->name;
273 /* Remove node from same comdat group. */
274 void remove_from_same_comdat_group (void);
276 /* Add this symtab_node to the same comdat group that OLD is in. */
277 void add_to_same_comdat_group (symtab_node *old_node);
279 /* Dissolve the same_comdat_group list in which NODE resides. */
280 void dissolve_same_comdat_group_list (void);
282 /* Return true when symtab_node is known to be used from other (non-LTO)
283 object file. Known only when doing LTO via linker plugin. */
284 bool used_from_object_file_p (void);
286 /* Walk the alias chain to return the symbol NODE is alias of.
287 If NODE is not an alias, return NODE.
288 When AVAILABILITY is non-NULL, get minimal availability in the chain.
289 When REF is non-NULL, assume that reference happens in symbol REF
290 when determining the availability. */
291 symtab_node *ultimate_alias_target (enum availability *avail = NULL,
292 struct symtab_node *ref = NULL);
294 /* Return next reachable static symbol with initializer after NODE. */
295 inline symtab_node *next_defined_symbol (void);
297 /* Add reference recording that symtab node is alias of TARGET.
298 If TRANSPARENT is true make the alias to be transparent alias.
299 The function can fail in the case of aliasing cycles; in this case
300 it returns false. */
301 bool resolve_alias (symtab_node *target, bool transparent = false);
303 /* C++ FE sometimes change linkage flags after producing same
304 body aliases. */
305 void fixup_same_cpp_alias_visibility (symtab_node *target);
307 /* Call callback on symtab node and aliases associated to this node.
308 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
309 skipped. */
310 bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *),
311 void *data,
312 bool include_overwrite);
314 /* If node cannot be interposable by static or dynamic linker to point to
315 different definition, return this symbol. Otherwise look for alias with
316 such property and if none exists, introduce new one. */
317 symtab_node *noninterposable_alias (void);
319 /* Return node that alias is aliasing. */
320 inline symtab_node *get_alias_target (void);
322 /* Return DECL that alias is aliasing. */
323 inline tree get_alias_target_tree ();
325 /* Set section for symbol and its aliases. */
326 void set_section (const char *section);
328 /* Like set_section, but copying the section name from another node. */
329 void set_section (const symtab_node &other);
331 /* Set section, do not recurse into aliases.
332 When one wants to change section of symbol and its aliases,
333 use set_section. */
334 void set_section_for_node (const char *section);
336 /* Like set_section_for_node, but copying the section name from another
337 node. */
338 void set_section_for_node (const symtab_node &other);
340 /* Set initialization priority to PRIORITY. */
341 void set_init_priority (priority_type priority);
343 /* Return the initialization priority. */
344 priority_type get_init_priority ();
346 /* Return availability of NODE when referenced from REF. */
347 enum availability get_availability (symtab_node *ref = NULL);
349 /* During LTO stream-in this predicate can be used to check whether node
350 in question prevails in the linking to save some memory usage. */
351 bool prevailing_p (void);
353 /* Return true if NODE binds to current definition in final executable
354 when referenced from REF. If REF is NULL return conservative value
355 for any reference. */
356 bool binds_to_current_def_p (symtab_node *ref = NULL);
358 /* Make DECL local. */
359 void make_decl_local (void);
361 /* Copy visibility from N. */
362 void copy_visibility_from (symtab_node *n);
364 /* Return desired alignment of the definition. This is NOT alignment useful
365 to access THIS, because THIS may be interposable and DECL_ALIGN should
366 be used instead. It however must be guaranteed when output definition
367 of THIS. */
368 unsigned int definition_alignment ();
370 /* Return true if alignment can be increased. */
371 bool can_increase_alignment_p ();
373 /* Increase alignment of symbol to ALIGN. */
374 void increase_alignment (unsigned int align);
376 /* Return true if list contains an alias. */
377 bool has_aliases_p (void);
379 /* Return true when the symbol is real symbol, i.e. it is not inline clone
380 or abstract function kept for debug info purposes only. */
381 bool real_symbol_p (void);
383 /* Return true when the symbol needs to be output to the LTO symbol table. */
384 bool output_to_lto_symbol_table_p (void);
386 /* Determine if symbol declaration is needed. That is, visible to something
387 either outside this translation unit, something magic in the system
388 configury. This function is used just during symbol creation. */
389 bool needed_p (void);
391 /* Return true if this symbol is a function from the C frontend specified
392 directly in RTL form (with "__RTL"). */
393 bool native_rtl_p () const;
395 /* Return true when there are references to the node. */
396 bool referred_to_p (bool include_self = true);
398 /* Return true if symbol can be discarded by linker from the binary.
399 Assume that symbol is used (so there is no need to take into account
400 garbage collecting linkers)
402 This can happen for comdats, commons and weaks when they are prevailed
403 by other definition at static linking time. */
404 inline bool
405 can_be_discarded_p (void)
407 return (DECL_EXTERNAL (decl)
408 || ((get_comdat_group ()
409 || DECL_COMMON (decl)
410 || (DECL_SECTION_NAME (decl) && DECL_WEAK (decl)))
411 && ((resolution != LDPR_PREVAILING_DEF
412 && resolution != LDPR_PREVAILING_DEF_IRONLY_EXP)
413 || flag_incremental_link)
414 && resolution != LDPR_PREVAILING_DEF_IRONLY));
417 /* Return true if NODE is local to a particular COMDAT group, and must not
418 be named from outside the COMDAT. This is used for C++ decloned
419 constructors. */
420 inline bool comdat_local_p (void)
422 return (same_comdat_group && !TREE_PUBLIC (decl));
425 /* Return true if ONE and TWO are part of the same COMDAT group. */
426 inline bool in_same_comdat_group_p (symtab_node *target);
428 /* Return true if symbol is known to be nonzero. */
429 bool nonzero_address ();
431 /* Return 0 if symbol is known to have different address than S2,
432 Return 1 if symbol is known to have same address as S2,
433 return 2 otherwise.
435 If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
436 and S2 is going to be accessed. This eliminates the situations when
437 either THIS or S2 is NULL and is useful for comparing bases when deciding
438 about memory aliasing. */
439 int equal_address_to (symtab_node *s2, bool memory_accessed = false);
441 /* Return true if symbol's address may possibly be compared to other
442 symbol's address. */
443 bool address_matters_p ();
445 /* Return true if NODE's address can be compared. This use properties
446 of NODE only and does not look if the address is actually taken in
447 interesting way. For that use ADDRESS_MATTERS_P instead. */
448 bool address_can_be_compared_p (void);
450 /* Return symbol table node associated with DECL, if any,
451 and NULL otherwise. */
452 static inline symtab_node *get (const_tree decl)
454 /* Check that we are called for sane type of object - functions
455 and static or external variables. */
456 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
457 || (TREE_CODE (decl) == VAR_DECL
458 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
459 || in_lto_p)));
460 /* Check that the mapping is sane - perhaps this check can go away,
461 but at the moment frontends tends to corrupt the mapping by calling
462 memcpy/memset on the tree nodes. */
463 gcc_checking_assert (!decl->decl_with_vis.symtab_node
464 || decl->decl_with_vis.symtab_node->decl == decl);
465 return decl->decl_with_vis.symtab_node;
468 /* Try to find a symtab node for declaration DECL and if it does not
469 exist or if it corresponds to an inline clone, create a new one. */
470 static inline symtab_node * get_create (tree node);
472 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
473 Return NULL if there's no such node. */
474 static symtab_node *get_for_asmname (const_tree asmname);
476 /* Verify symbol table for internal consistency. */
477 static DEBUG_FUNCTION void verify_symtab_nodes (void);
479 /* Perform internal consistency checks, if they are enabled. */
480 static inline void checking_verify_symtab_nodes (void);
482 /* Type of the symbol. */
483 ENUM_BITFIELD (symtab_type) type : 8;
485 /* The symbols resolution. */
486 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
488 /*** Flags representing the symbol type. ***/
490 /* True when symbol corresponds to a definition in current unit.
491 set via finalize_function or finalize_decl */
492 unsigned definition : 1;
493 /* True when symbol is an alias.
494 Set by assemble_alias. */
495 unsigned alias : 1;
496 /* When true the alias is translated into its target symbol either by GCC
497 or assembler (it also may just be a duplicate declaration of the same
498 linker name).
500 Currently transparent aliases come in three different flavors
501 - aliases having the same assembler name as their target (aka duplicated
502 declarations). In this case the assembler names compare via
503 assembler_names_equal_p and weakref is false
504 - aliases that are renamed at a time being output to final file
505 by varasm.c. For those DECL_ASSEMBLER_NAME have
506 IDENTIFIER_TRANSPARENT_ALIAS set and thus also their assembler
507 name must be unique.
508 Weakrefs belong to this category when we target assembler without
509 .weakref directive.
510 - weakrefs that are renamed by assembler via .weakref directive.
511 In this case the alias may or may not be definition (depending if
512 target declaration was seen by the compiler), weakref is set.
513 Unless we are before renaming statics, assembler names are different.
515 Given that we now support duplicate declarations, the second option is
516 redundant and will be removed. */
517 unsigned transparent_alias : 1;
518 /* True when alias is a weakref. */
519 unsigned weakref : 1;
520 /* C++ frontend produce same body aliases and extra name aliases for
521 virtual functions and vtables that are obviously equivalent.
522 Those aliases are bit special, especially because C++ frontend
523 visibility code is so ugly it cannot get them right at first time
524 and their visibility needs to be copied from their "masters" at
525 the end of parsing. */
526 unsigned cpp_implicit_alias : 1;
527 /* The alias is a symbol version. */
528 unsigned symver : 1;
529 /* Set once the definition was analyzed. The list of references and
530 other properties are built during analysis. */
531 unsigned analyzed : 1;
532 /* Set for write-only variables. */
533 unsigned writeonly : 1;
534 /* Visibility of symbol was used for further optimization; do not
535 permit further changes. */
536 unsigned refuse_visibility_changes : 1;
538 /*** Visibility and linkage flags. ***/
540 /* Set when function is visible by other units. */
541 unsigned externally_visible : 1;
542 /* Don't reorder to other symbols having this set. */
543 unsigned no_reorder : 1;
544 /* The symbol will be assumed to be used in an invisible way (like
545 by an toplevel asm statement). */
546 unsigned force_output : 1;
547 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
548 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
549 to static and it does not inhibit optimization. */
550 unsigned forced_by_abi : 1;
551 /* True when the name is known to be unique and thus it does not need mangling. */
552 unsigned unique_name : 1;
553 /* Specify whether the section was set by user or by
554 compiler via -ffunction-sections. */
555 unsigned implicit_section : 1;
556 /* True when body and other characteristics have been removed by
557 symtab_remove_unreachable_nodes. */
558 unsigned body_removed : 1;
560 /*** WHOPR Partitioning flags.
561 These flags are used at ltrans stage when only part of the callgraph is
562 available. ***/
564 /* Set when variable is used from other LTRANS partition. */
565 unsigned used_from_other_partition : 1;
566 /* Set when function is available in the other LTRANS partition.
567 During WPA output it is used to mark nodes that are present in
568 multiple partitions. */
569 unsigned in_other_partition : 1;
573 /*** other flags. ***/
575 /* Set when symbol has address taken. */
576 unsigned address_taken : 1;
577 /* Set when init priority is set. */
578 unsigned in_init_priority_hash : 1;
580 /* Set when symbol needs to be streamed into LTO bytecode for LTO, or in case
581 of offloading, for separate compilation for a different target. */
582 unsigned need_lto_streaming : 1;
584 /* Set when symbol can be streamed into bytecode for offloading. */
585 unsigned offloadable : 1;
587 /* Set when symbol is an IFUNC resolver. */
588 unsigned ifunc_resolver : 1;
591 /* Ordering of all symtab entries. */
592 int order;
594 /* Declaration representing the symbol. */
595 tree decl;
597 /* Linked list of symbol table entries starting with symtab_nodes. */
598 symtab_node *next;
599 symtab_node *previous;
601 /* Linked list of symbols with the same asm name. There may be multiple
602 entries for single symbol name during LTO, because symbols are renamed
603 only after partitioning.
605 Because inline clones are kept in the assembler name has, they also produce
606 duplicate entries.
608 There are also several long standing bugs where frontends and builtin
609 code produce duplicated decls. */
610 symtab_node *next_sharing_asm_name;
611 symtab_node *previous_sharing_asm_name;
613 /* Circular list of nodes in the same comdat group if non-NULL. */
614 symtab_node *same_comdat_group;
616 /* Vectors of referring and referenced entities. */
617 ipa_ref_list GTY((skip)) ref_list;
619 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
620 depending to what was known to frontend on the creation time.
621 Once alias is resolved, this pointer become NULL. */
622 tree alias_target;
624 /* File stream where this node is being written to. */
625 struct lto_file_decl_data * lto_file_data;
627 PTR GTY ((skip)) aux;
629 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
630 tree x_comdat_group;
632 /* Section name. Again can be private, if allowed. */
633 section_hash_entry *x_section;
635 protected:
636 /* Dump base fields of symtab nodes to F. Not to be used directly. */
637 void dump_base (FILE *);
639 /* Verify common part of symtab node. */
640 bool DEBUG_FUNCTION verify_base (void);
642 /* Remove node from symbol table. This function is not used directly, but via
643 cgraph/varpool node removal routines. */
644 void unregister (struct clone_info *);
646 /* Return the initialization and finalization priority information for
647 DECL. If there is no previous priority information, a freshly
648 allocated structure is returned. */
649 struct symbol_priority_map *priority_info (void);
651 /* Worker for call_for_symbol_and_aliases_1. */
652 bool call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *, void *),
653 void *data,
654 bool include_overwrite);
655 private:
656 /* Workers for set_section. */
657 static bool set_section_from_string (symtab_node *n, void *s);
658 static bool set_section_from_node (symtab_node *n, void *o);
660 /* Worker for symtab_resolve_alias. */
661 static bool set_implicit_section (symtab_node *n, void *);
663 /* Worker searching noninterposable alias. */
664 static bool noninterposable_alias (symtab_node *node, void *data);
666 /* Worker for ultimate_alias_target. */
667 symtab_node *ultimate_alias_target_1 (enum availability *avail = NULL,
668 symtab_node *ref = NULL);
670 /* Get dump name with normal or assembly name. */
671 const char *get_dump_name (bool asm_name_p) const;
674 inline void
675 symtab_node::checking_verify_symtab_nodes (void)
677 if (flag_checking)
678 symtab_node::verify_symtab_nodes ();
681 /* Walk all aliases for NODE. */
682 #define FOR_EACH_ALIAS(NODE, ALIAS) \
683 for (unsigned ALIAS##_iter_ = 0; \
684 (NODE)->iterate_direct_aliases (ALIAS##_iter_, ALIAS); \
685 ALIAS##_iter_++)
687 /* This is the information that is put into the cgraph local structure
688 to recover a function. */
689 struct lto_file_decl_data;
691 extern const char * const cgraph_availability_names[];
692 extern const char * const ld_plugin_symbol_resolution_names[];
693 extern const char * const tls_model_names[];
695 /* Represent which DECL tree (or reference to such tree)
696 will be replaced by another tree while versioning. */
697 struct GTY(()) ipa_replace_map
699 /* The new (replacing) tree. */
700 tree new_tree;
701 /* Parameter number to replace, when old_tree is NULL. */
702 int parm_num;
705 enum cgraph_simd_clone_arg_type
707 SIMD_CLONE_ARG_TYPE_VECTOR,
708 SIMD_CLONE_ARG_TYPE_UNIFORM,
709 /* These are only for integer/pointer arguments passed by value. */
710 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
711 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
712 /* These 6 are only for reference type arguments or arguments passed
713 by reference. */
714 SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP,
715 SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP,
716 SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP,
717 SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP,
718 SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP,
719 SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP,
720 SIMD_CLONE_ARG_TYPE_MASK
723 /* Function arguments in the original function of a SIMD clone.
724 Supplementary data for `struct simd_clone'. */
726 struct GTY(()) cgraph_simd_clone_arg {
727 /* Original function argument as it originally existed in
728 DECL_ARGUMENTS. */
729 tree orig_arg;
731 /* orig_arg's function (or for extern functions type from
732 TYPE_ARG_TYPES). */
733 tree orig_type;
735 /* If argument is a vector, this holds the vector version of
736 orig_arg that after adjusting the argument types will live in
737 DECL_ARGUMENTS. Otherwise, this is NULL.
739 This basically holds:
740 vector(simdlen) __typeof__(orig_arg) new_arg. */
741 tree vector_arg;
743 /* vector_arg's type (or for extern functions new vector type. */
744 tree vector_type;
746 /* If argument is a vector, this holds the array where the simd
747 argument is held while executing the simd clone function. This
748 is a local variable in the cloned function. Its content is
749 copied from vector_arg upon entry to the clone.
751 This basically holds:
752 __typeof__(orig_arg) simd_array[simdlen]. */
753 tree simd_array;
755 /* A SIMD clone's argument can be either linear (constant or
756 variable), uniform, or vector. */
757 enum cgraph_simd_clone_arg_type arg_type;
759 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_*CONSTANT_STEP this is
760 the constant linear step, if arg_type is
761 SIMD_CLONE_ARG_TYPE_LINEAR_*VARIABLE_STEP, this is index of
762 the uniform argument holding the step, otherwise 0. */
763 HOST_WIDE_INT linear_step;
765 /* Variable alignment if available, otherwise 0. */
766 unsigned int alignment;
769 /* Specific data for a SIMD function clone. */
771 struct GTY(()) cgraph_simd_clone {
772 /* Number of words in the SIMD lane associated with this clone. */
773 poly_uint64 simdlen;
775 /* Number of annotated function arguments in `args'. This is
776 usually the number of named arguments in FNDECL. */
777 unsigned int nargs;
779 /* Max hardware vector size in bits for integral vectors. */
780 poly_uint64 vecsize_int;
782 /* Max hardware vector size in bits for floating point vectors. */
783 poly_uint64 vecsize_float;
785 /* Machine mode of the mask argument(s), if they are to be passed
786 as bitmasks in integer argument(s). VOIDmode if masks are passed
787 as vectors of characteristic type. */
788 machine_mode mask_mode;
790 /* The mangling character for a given vector size. This is used
791 to determine the ISA mangling bit as specified in the Intel
792 Vector ABI. */
793 unsigned char vecsize_mangle;
795 /* True if this is the masked, in-branch version of the clone,
796 otherwise false. */
797 unsigned int inbranch : 1;
799 /* Doubly linked list of SIMD clones. */
800 cgraph_node *prev_clone, *next_clone;
802 /* Original cgraph node the SIMD clones were created for. */
803 cgraph_node *origin;
805 /* Annotated function arguments for the original function. */
806 cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
809 /* Function Multiversioning info. */
810 struct GTY((for_user)) cgraph_function_version_info {
811 /* The cgraph_node for which the function version info is stored. */
812 cgraph_node *this_node;
813 /* Chains all the semantically identical function versions. The
814 first function in this chain is the version_info node of the
815 default function. */
816 cgraph_function_version_info *prev;
817 /* If this version node corresponds to a dispatcher for function
818 versions, this points to the version info node of the default
819 function, the first node in the chain. */
820 cgraph_function_version_info *next;
821 /* If this node corresponds to a function version, this points
822 to the dispatcher function decl, which is the function that must
823 be called to execute the right function version at run-time.
825 If this cgraph node is a dispatcher (if dispatcher_function is
826 true, in the cgraph_node struct) for function versions, this
827 points to resolver function, which holds the function body of the
828 dispatcher. The dispatcher decl is an alias to the resolver
829 function decl. */
830 tree dispatcher_resolver;
833 #define DEFCIFCODE(code, type, string) CIF_ ## code,
834 /* Reasons for inlining failures. */
836 enum cgraph_inline_failed_t {
837 #include "cif-code.def"
838 CIF_N_REASONS
841 enum cgraph_inline_failed_type_t
843 CIF_FINAL_NORMAL = 0,
844 CIF_FINAL_ERROR
847 struct cgraph_edge;
849 struct cgraph_edge_hasher : ggc_ptr_hash<cgraph_edge>
851 typedef gimple *compare_type;
853 static hashval_t hash (cgraph_edge *);
854 static hashval_t hash (gimple *);
855 static bool equal (cgraph_edge *, gimple *);
858 /* The cgraph data structure.
859 Each function decl has assigned cgraph_node listing callees and callers. */
861 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node
863 friend class symbol_table;
865 /* Constructor. */
866 explicit cgraph_node (int uid)
867 : symtab_node (SYMTAB_FUNCTION), callees (NULL), callers (NULL),
868 indirect_calls (NULL),
869 next_sibling_clone (NULL), prev_sibling_clone (NULL), clones (NULL),
870 clone_of (NULL), call_site_hash (NULL), former_clone_of (NULL),
871 simdclone (NULL), simd_clones (NULL), ipa_transforms_to_apply (vNULL),
872 inlined_to (NULL), rtl (NULL),
873 count (profile_count::uninitialized ()),
874 count_materialization_scale (REG_BR_PROB_BASE), profile_id (0),
875 unit_id (0), tp_first_run (0), thunk (false),
876 used_as_abstract_origin (false),
877 lowered (false), process (false), frequency (NODE_FREQUENCY_NORMAL),
878 only_called_at_startup (false), only_called_at_exit (false),
879 tm_clone (false), dispatcher_function (false), calls_comdat_local (false),
880 icf_merged (false), nonfreeing_fn (false), merged_comdat (false),
881 merged_extern_inline (false), parallelized_function (false),
882 split_part (false), indirect_call_target (false), local (false),
883 versionable (false), can_change_signature (false),
884 redefined_extern_inline (false), tm_may_enter_irr (false),
885 ipcp_clone (false), declare_variant_alt (false),
886 calls_declare_variant_alt (false), m_uid (uid), m_summary_id (-1)
889 /* Remove the node from cgraph and all inline clones inlined into it.
890 Skip however removal of FORBIDDEN_NODE and return true if it needs to be
891 removed. This allows to call the function from outer loop walking clone
892 tree. */
893 bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL);
895 /* Record all references from cgraph_node that are taken
896 in statement STMT. */
897 void record_stmt_references (gimple *stmt);
899 /* Like cgraph_set_call_stmt but walk the clone tree and update all
900 clones sharing the same function body.
901 When WHOLE_SPECULATIVE_EDGES is true, all three components of
902 speculative edge gets updated. Otherwise we update only direct
903 call. */
904 void set_call_stmt_including_clones (gimple *old_stmt, gcall *new_stmt,
905 bool update_speculative = true);
907 /* Walk the alias chain to return the function cgraph_node is alias of.
908 Walk through thunk, too.
909 When AVAILABILITY is non-NULL, get minimal availability in the chain.
910 When REF is non-NULL, assume that reference happens in symbol REF
911 when determining the availability. */
912 cgraph_node *function_symbol (enum availability *avail = NULL,
913 struct symtab_node *ref = NULL);
915 /* Walk the alias chain to return the function cgraph_node is alias of.
916 Walk through non virtual thunks, too. Thus we return either a function
917 or a virtual thunk node.
918 When AVAILABILITY is non-NULL, get minimal availability in the chain.
919 When REF is non-NULL, assume that reference happens in symbol REF
920 when determining the availability. */
921 cgraph_node *function_or_virtual_thunk_symbol
922 (enum availability *avail = NULL,
923 struct symtab_node *ref = NULL);
925 /* Create node representing clone of N executed COUNT times. Decrease
926 the execution counts from original node too.
927 The new clone will have decl set to DECL that may or may not be the same
928 as decl of N.
930 When UPDATE_ORIGINAL is true, the counts are subtracted from the original
931 function's profile to reflect the fact that part of execution is handled
932 by node.
933 When CALL_DUPLICATION_HOOK is true, the ipa passes are acknowledged about
934 the new clone. Otherwise the caller is responsible for doing so later.
936 If the new node is being inlined into another one, NEW_INLINED_TO should be
937 the outline function the new one is (even indirectly) inlined to.
938 All hooks will see this in node's inlined_to, when invoked.
939 Can be NULL if the node is not inlined. SUFFIX is string that is appended
940 to the original name. */
941 cgraph_node *create_clone (tree decl, profile_count count,
942 bool update_original,
943 vec<cgraph_edge *> redirect_callers,
944 bool call_duplication_hook,
945 cgraph_node *new_inlined_to,
946 ipa_param_adjustments *param_adjustments,
947 const char *suffix = NULL);
949 /* Create callgraph node clone with new declaration. The actual body will be
950 copied later at compilation stage. The name of the new clone will be
951 constructed from the name of the original node, SUFFIX and NUM_SUFFIX. */
952 cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers,
953 vec<ipa_replace_map *, va_gc> *tree_map,
954 ipa_param_adjustments *param_adjustments,
955 const char * suffix, unsigned num_suffix);
957 /* Remove the node from the tree of virtual and inline clones and make it a
958 standalone node - not a clone any more. */
959 void remove_from_clone_tree ();
961 /* cgraph node being removed from symbol table; see if its entry can be
962 replaced by other inline clone. */
963 cgraph_node *find_replacement (struct clone_info *);
965 /* Create a new cgraph node which is the new version of
966 callgraph node. REDIRECT_CALLERS holds the callers
967 edges which should be redirected to point to
968 NEW_VERSION. ALL the callees edges of the node
969 are cloned to the new version node. Return the new
970 version node.
972 If non-NULL BLOCK_TO_COPY determine what basic blocks
973 was copied to prevent duplications of calls that are dead
974 in the clone.
976 SUFFIX is string that is appended to the original name. */
978 cgraph_node *create_version_clone (tree new_decl,
979 vec<cgraph_edge *> redirect_callers,
980 bitmap bbs_to_copy,
981 const char *suffix = NULL);
983 /* Perform function versioning.
984 Function versioning includes copying of the tree and
985 a callgraph update (creating a new cgraph node and updating
986 its callees and callers).
988 REDIRECT_CALLERS varray includes the edges to be redirected
989 to the new version.
991 TREE_MAP is a mapping of tree nodes we want to replace with
992 new ones (according to results of prior analysis).
994 If non-NULL ARGS_TO_SKIP determine function parameters to remove
995 from new version.
996 If SKIP_RETURN is true, the new version will return void.
997 If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
998 If non_NULL NEW_ENTRY determine new entry BB of the clone.
1000 If TARGET_ATTRIBUTES is non-null, when creating a new declaration,
1001 add the attributes to DECL_ATTRIBUTES. And call valid_attribute_p
1002 that will promote value of the attribute DECL_FUNCTION_SPECIFIC_TARGET
1003 of the declaration.
1005 Return the new version's cgraph node. */
1006 cgraph_node *create_version_clone_with_body
1007 (vec<cgraph_edge *> redirect_callers,
1008 vec<ipa_replace_map *, va_gc> *tree_map,
1009 ipa_param_adjustments *param_adjustments,
1010 bitmap bbs_to_copy, basic_block new_entry_block, const char *clone_name,
1011 tree target_attributes = NULL_TREE);
1013 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
1014 corresponding to cgraph_node. */
1015 cgraph_function_version_info *insert_new_function_version (void);
1017 /* Get the cgraph_function_version_info node corresponding to node. */
1018 cgraph_function_version_info *function_version (void);
1020 /* Discover all functions and variables that are trivially needed, analyze
1021 them as well as all functions and variables referred by them */
1022 void analyze (void);
1024 /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
1025 aliases DECL with an adjustments made into the first parameter.
1026 See comments in struct symtab-thunks.h for detail on the parameters. */
1027 cgraph_node * create_thunk (tree alias, tree, bool this_adjusting,
1028 HOST_WIDE_INT fixed_offset,
1029 HOST_WIDE_INT virtual_value,
1030 HOST_WIDE_INT indirect_offset,
1031 tree virtual_offset,
1032 tree real_alias);
1035 /* Return node that alias is aliasing. */
1036 inline cgraph_node *get_alias_target (void);
1038 /* Given function symbol, walk the alias chain to return the function node
1039 is alias of. Do not walk through thunks.
1040 When AVAILABILITY is non-NULL, get minimal availability in the chain.
1041 When REF is non-NULL, assume that reference happens in symbol REF
1042 when determining the availability. */
1044 cgraph_node *ultimate_alias_target (availability *availability = NULL,
1045 symtab_node *ref = NULL);
1047 /* Call expand_thunk on all callers that are thunks and analyze those
1048 nodes that were expanded. */
1049 void expand_all_artificial_thunks ();
1051 /* Assemble thunks and aliases associated to node. */
1052 void assemble_thunks_and_aliases (void);
1054 /* Expand function specified by node. */
1055 void expand (void);
1057 /* As an GCC extension we allow redefinition of the function. The
1058 semantics when both copies of bodies differ is not well defined.
1059 We replace the old body with new body so in unit at a time mode
1060 we always use new body, while in normal mode we may end up with
1061 old body inlined into some functions and new body expanded and
1062 inlined in others. */
1063 void reset (void);
1065 /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this
1066 kind of wrapper method. */
1067 void create_wrapper (cgraph_node *target);
1069 /* Verify cgraph nodes of the cgraph node. */
1070 void DEBUG_FUNCTION verify_node (void);
1072 /* Remove function from symbol table. */
1073 void remove (void);
1075 /* Dump call graph node to file F. */
1076 void dump (FILE *f);
1078 /* Dump call graph node to file F. */
1079 void dump_graphviz (FILE *f);
1081 /* Dump call graph node to stderr. */
1082 void DEBUG_FUNCTION debug (void);
1084 /* When doing LTO, read cgraph_node's body from disk if it is not already
1085 present. */
1086 bool get_untransformed_body ();
1088 /* Prepare function body. When doing LTO, read cgraph_node's body from disk
1089 if it is not already present. When some IPA transformations are scheduled,
1090 apply them. */
1091 bool get_body ();
1093 void materialize_clone (void);
1095 /* Release memory used to represent body of function.
1096 Use this only for functions that are released before being translated to
1097 target code (i.e. RTL). Functions that are compiled to RTL and beyond
1098 are free'd in final.c via free_after_compilation(). */
1099 void release_body (bool keep_arguments = false);
1101 /* Return the DECL_STRUCT_FUNCTION of the function. */
1102 struct function *get_fun () const;
1104 /* Bring cgraph node local. */
1105 void make_local (void);
1107 /* Likewise indicate that a node is having address taken. */
1108 void mark_address_taken (void);
1110 /* Set finalization priority to PRIORITY. */
1111 void set_fini_priority (priority_type priority);
1113 /* Return the finalization priority. */
1114 priority_type get_fini_priority (void);
1116 /* Create edge from a given function to CALLEE in the cgraph. */
1117 cgraph_edge *create_edge (cgraph_node *callee,
1118 gcall *call_stmt, profile_count count,
1119 bool cloning_p = false);
1121 /* Create an indirect edge with a yet-undetermined callee where the call
1122 statement destination is a formal parameter of the caller with index
1123 PARAM_INDEX. */
1124 cgraph_edge *create_indirect_edge (gcall *call_stmt, int ecf_flags,
1125 profile_count count,
1126 bool cloning_p = false);
1128 /* Like cgraph_create_edge walk the clone tree and update all clones sharing
1129 same function body. If clones already have edge for OLD_STMT; only
1130 update the edge same way as cgraph_set_call_stmt_including_clones does. */
1131 void create_edge_including_clones (cgraph_node *callee,
1132 gimple *old_stmt, gcall *stmt,
1133 profile_count count,
1134 cgraph_inline_failed_t reason);
1136 /* Return the callgraph edge representing the GIMPLE_CALL statement
1137 CALL_STMT. */
1138 cgraph_edge *get_edge (gimple *call_stmt);
1140 /* Collect all callers of cgraph_node and its aliases that are known to lead
1141 to NODE (i.e. are not overwritable) and that are not thunks. */
1142 vec<cgraph_edge *> collect_callers (void);
1144 /* Remove all callers from the node. */
1145 void remove_callers (void);
1147 /* Remove all callees from the node. */
1148 void remove_callees (void);
1150 /* Return function availability. See cgraph.h for description of individual
1151 return values. */
1152 enum availability get_availability (symtab_node *ref = NULL);
1154 /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node
1155 if any to NOTHROW. */
1156 bool set_nothrow_flag (bool nothrow);
1158 /* SET DECL_IS_MALLOC on cgraph_node's decl and on aliases of the node
1159 if any. */
1160 bool set_malloc_flag (bool malloc_p);
1162 /* If SET_CONST is true, mark function, aliases and thunks to be ECF_CONST.
1163 If SET_CONST if false, clear the flag.
1165 When setting the flag be careful about possible interposition and
1166 do not set the flag for functions that can be interposed and set pure
1167 flag for functions that can bind to other definition.
1169 Return true if any change was done. */
1171 bool set_const_flag (bool set_const, bool looping);
1173 /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
1174 if any to PURE.
1176 When setting the flag, be careful about possible interposition.
1177 Return true if any change was done. */
1179 bool set_pure_flag (bool pure, bool looping);
1181 /* Call callback on function and aliases associated to the function.
1182 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1183 skipped. */
1185 bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
1186 void *),
1187 void *data, bool include_overwritable);
1189 /* Call callback on cgraph_node, thunks and aliases associated to NODE.
1190 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1191 skipped. When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
1192 skipped. */
1193 bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node,
1194 void *data),
1195 void *data,
1196 bool include_overwritable,
1197 bool exclude_virtual_thunks = false);
1199 /* Likewise indicate that a node is needed, i.e. reachable via some
1200 external means. */
1201 inline void mark_force_output (void);
1203 /* Return true when function can be marked local. */
1204 bool local_p (void);
1206 /* Return true if cgraph_node can be made local for API change.
1207 Extern inline functions and C++ COMDAT functions can be made local
1208 at the expense of possible code size growth if function is used in multiple
1209 compilation units. */
1210 bool can_be_local_p (void);
1212 /* Return true when cgraph_node cannot return or throw and thus
1213 it is safe to ignore its side effects for IPA analysis. */
1214 bool cannot_return_p (void);
1216 /* Return true when function cgraph_node and all its aliases are only called
1217 directly.
1218 i.e. it is not externally visible, address was not taken and
1219 it is not used in any other non-standard way. */
1220 bool only_called_directly_p (void);
1222 /* Return true when function is only called directly or it has alias.
1223 i.e. it is not externally visible, address was not taken and
1224 it is not used in any other non-standard way. */
1225 inline bool only_called_directly_or_aliased_p (void);
1227 /* Return true when function cgraph_node can be expected to be removed
1228 from program when direct calls in this compilation unit are removed.
1230 As a special case COMDAT functions are
1231 cgraph_can_remove_if_no_direct_calls_p while the are not
1232 cgraph_only_called_directly_p (it is possible they are called from other
1233 unit)
1235 This function behaves as cgraph_only_called_directly_p because eliminating
1236 all uses of COMDAT function does not make it necessarily disappear from
1237 the program unless we are compiling whole program or we do LTO. In this
1238 case we know we win since dynamic linking will not really discard the
1239 linkonce section.
1241 If WILL_INLINE is true, assume that function will be inlined into all the
1242 direct calls. */
1243 bool will_be_removed_from_program_if_no_direct_calls_p
1244 (bool will_inline = false);
1246 /* Return true when function can be removed from callgraph
1247 if all direct calls and references are eliminated. The function does
1248 not take into account comdat groups. */
1249 bool can_remove_if_no_direct_calls_and_refs_p (void);
1251 /* Return true when function cgraph_node and its aliases can be removed from
1252 callgraph if all direct calls are eliminated.
1253 If WILL_INLINE is true, assume that function will be inlined into all the
1254 direct calls. */
1255 bool can_remove_if_no_direct_calls_p (bool will_inline = false);
1257 /* Return true when callgraph node is a function with Gimple body defined
1258 in current unit. Functions can also be define externally or they
1259 can be thunks with no Gimple representation.
1261 Note that at WPA stage, the function body may not be present in memory. */
1262 inline bool has_gimple_body_p (void);
1264 /* Return true if this node represents a former, i.e. an expanded, thunk. */
1265 bool former_thunk_p (void);
1267 /* Check if function calls comdat local. This is used to recompute
1268 calls_comdat_local flag after function transformations. */
1269 bool check_calls_comdat_local_p ();
1271 /* Return true if function should be optimized for size. */
1272 enum optimize_size_level optimize_for_size_p (void);
1274 /* Dump the callgraph to file F. */
1275 static void dump_cgraph (FILE *f);
1277 /* Dump the call graph to stderr. */
1278 static inline
1279 void debug_cgraph (void)
1281 dump_cgraph (stderr);
1284 /* Get unique identifier of the node. */
1285 inline int get_uid ()
1287 return m_uid;
1290 /* Get summary id of the node. */
1291 inline int get_summary_id ()
1293 return m_summary_id;
1296 /* Record that DECL1 and DECL2 are semantically identical function
1297 versions. */
1298 static void record_function_versions (tree decl1, tree decl2);
1300 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
1301 DECL is a duplicate declaration. */
1302 static void delete_function_version_by_decl (tree decl);
1304 /* Add the function FNDECL to the call graph.
1305 Unlike finalize_function, this function is intended to be used
1306 by middle end and allows insertion of new function at arbitrary point
1307 of compilation. The function can be either in high, low or SSA form
1308 GIMPLE.
1310 The function is assumed to be reachable and have address taken (so no
1311 API breaking optimizations are performed on it).
1313 Main work done by this function is to enqueue the function for later
1314 processing to avoid need the passes to be re-entrant. */
1315 static void add_new_function (tree fndecl, bool lowered);
1317 /* Return callgraph node for given symbol and check it is a function. */
1318 static inline cgraph_node *get (const_tree decl)
1320 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1321 return dyn_cast <cgraph_node *> (symtab_node::get (decl));
1324 /* DECL has been parsed. Take it, queue it, compile it at the whim of the
1325 logic in effect. If NO_COLLECT is true, then our caller cannot stand to
1326 have the garbage collector run at the moment. We would need to either
1327 create a new GC context, or just not compile right now. */
1328 static void finalize_function (tree, bool);
1330 /* Return cgraph node assigned to DECL. Create new one when needed. */
1331 static cgraph_node * create (tree decl);
1333 /* Try to find a call graph node for declaration DECL and if it does not
1334 exist or if it corresponds to an inline clone, create a new one. */
1335 static cgraph_node * get_create (tree);
1337 /* Return local info for the compiled function. */
1338 static cgraph_node *local_info_node (tree decl);
1340 /* Return RTL info for the compiled function. */
1341 static struct cgraph_rtl_info *rtl_info (const_tree);
1343 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
1344 Return NULL if there's no such node. */
1345 static cgraph_node *get_for_asmname (tree asmname);
1347 /* Attempt to mark ALIAS as an alias to DECL. Return alias node if
1348 successful and NULL otherwise.
1349 Same body aliases are output whenever the body of DECL is output,
1350 and cgraph_node::get (ALIAS) transparently
1351 returns cgraph_node::get (DECL). */
1352 static cgraph_node * create_same_body_alias (tree alias, tree decl);
1354 /* Verify whole cgraph structure. */
1355 static void DEBUG_FUNCTION verify_cgraph_nodes (void);
1357 /* Verify cgraph, if consistency checking is enabled. */
1358 static inline void checking_verify_cgraph_nodes (void);
1360 /* Worker to bring NODE local. */
1361 static bool make_local (cgraph_node *node, void *);
1363 /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
1364 the function body is associated
1365 with (not necessarily cgraph_node (DECL). */
1366 static cgraph_node *create_alias (tree alias, tree target);
1368 /* Return true if NODE has thunk. */
1369 static bool has_thunk_p (cgraph_node *node, void *);
1371 cgraph_edge *callees;
1372 cgraph_edge *callers;
1373 /* List of edges representing indirect calls with a yet undetermined
1374 callee. */
1375 cgraph_edge *indirect_calls;
1376 cgraph_node *next_sibling_clone;
1377 cgraph_node *prev_sibling_clone;
1378 cgraph_node *clones;
1379 cgraph_node *clone_of;
1380 /* For functions with many calls sites it holds map from call expression
1381 to the edge to speed up cgraph_edge function. */
1382 hash_table<cgraph_edge_hasher> *GTY(()) call_site_hash;
1383 /* Declaration node used to be clone of. */
1384 tree former_clone_of;
1386 /* If this is a SIMD clone, this points to the SIMD specific
1387 information for it. */
1388 cgraph_simd_clone *simdclone;
1389 /* If this function has SIMD clones, this points to the first clone. */
1390 cgraph_node *simd_clones;
1392 /* Interprocedural passes scheduled to have their transform functions
1393 applied next time we execute local pass on them. We maintain it
1394 per-function in order to allow IPA passes to introduce new functions. */
1395 vec<ipa_opt_pass, va_heap, vl_ptr> GTY((skip)) ipa_transforms_to_apply;
1397 /* For inline clones this points to the function they will be
1398 inlined into. */
1399 cgraph_node *inlined_to;
1401 struct cgraph_rtl_info *rtl;
1403 /* Expected number of executions: calculated in profile.c. */
1404 profile_count count;
1405 /* How to scale counts at materialization time; used to merge
1406 LTO units with different number of profile runs. */
1407 int count_materialization_scale;
1408 /* ID assigned by the profiling. */
1409 unsigned int profile_id;
1410 /* ID of the translation unit. */
1411 int unit_id;
1412 /* Time profiler: first run of function. */
1413 int tp_first_run;
1415 /* True when symbol is a thunk. */
1416 unsigned thunk : 1;
1417 /* Set when decl is an abstract function pointed to by the
1418 ABSTRACT_DECL_ORIGIN of a reachable function. */
1419 unsigned used_as_abstract_origin : 1;
1420 /* Set once the function is lowered (i.e. its CFG is built). */
1421 unsigned lowered : 1;
1422 /* Set once the function has been instantiated and its callee
1423 lists created. */
1424 unsigned process : 1;
1425 /* How commonly executed the node is. Initialized during branch
1426 probabilities pass. */
1427 ENUM_BITFIELD (node_frequency) frequency : 2;
1428 /* True when function can only be called at startup (from static ctor). */
1429 unsigned only_called_at_startup : 1;
1430 /* True when function can only be called at startup (from static dtor). */
1431 unsigned only_called_at_exit : 1;
1432 /* True when function is the transactional clone of a function which
1433 is called only from inside transactions. */
1434 /* ?? We should be able to remove this. We have enough bits in
1435 cgraph to calculate it. */
1436 unsigned tm_clone : 1;
1437 /* True if this decl is a dispatcher for function versions. */
1438 unsigned dispatcher_function : 1;
1439 /* True if this decl calls a COMDAT-local function. This is set up in
1440 compute_fn_summary and inline_call. */
1441 unsigned calls_comdat_local : 1;
1442 /* True if node has been created by merge operation in IPA-ICF. */
1443 unsigned icf_merged: 1;
1444 /* True if call to node can't result in a call to free, munmap or
1445 other operation that could make previously non-trapping memory
1446 accesses trapping. */
1447 unsigned nonfreeing_fn : 1;
1448 /* True if there was multiple COMDAT bodies merged by lto-symtab. */
1449 unsigned merged_comdat : 1;
1450 /* True if this def was merged with extern inlines. */
1451 unsigned merged_extern_inline : 1;
1452 /* True if function was created to be executed in parallel. */
1453 unsigned parallelized_function : 1;
1454 /* True if function is part split out by ipa-split. */
1455 unsigned split_part : 1;
1456 /* True if the function appears as possible target of indirect call. */
1457 unsigned indirect_call_target : 1;
1458 /* Set when function is visible in current compilation unit only and
1459 its address is never taken. */
1460 unsigned local : 1;
1461 /* False when there is something makes versioning impossible. */
1462 unsigned versionable : 1;
1463 /* False when function calling convention and signature cannot be changed.
1464 This is the case when __builtin_apply_args is used. */
1465 unsigned can_change_signature : 1;
1466 /* True when the function has been originally extern inline, but it is
1467 redefined now. */
1468 unsigned redefined_extern_inline : 1;
1469 /* True if the function may enter serial irrevocable mode. */
1470 unsigned tm_may_enter_irr : 1;
1471 /* True if this was a clone created by ipa-cp. */
1472 unsigned ipcp_clone : 1;
1473 /* True if this is the deferred declare variant resolution artificial
1474 function. */
1475 unsigned declare_variant_alt : 1;
1476 /* True if the function calls declare_variant_alt functions. */
1477 unsigned calls_declare_variant_alt : 1;
1479 private:
1480 /* Unique id of the node. */
1481 int m_uid;
1483 /* Summary id that is recycled. */
1484 int m_summary_id;
1486 /* Worker for call_for_symbol_and_aliases. */
1487 bool call_for_symbol_and_aliases_1 (bool (*callback) (cgraph_node *,
1488 void *),
1489 void *data, bool include_overwritable);
1492 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
1493 can appear in multiple sets. */
1494 struct cgraph_node_set_def
1496 hash_map<cgraph_node *, size_t> *map;
1497 vec<cgraph_node *> nodes;
1500 typedef cgraph_node_set_def *cgraph_node_set;
1501 typedef struct varpool_node_set_def *varpool_node_set;
1503 struct varpool_node;
1505 /* A varpool node set is a collection of varpool nodes. A varpool node
1506 can appear in multiple sets. */
1507 struct varpool_node_set_def
1509 hash_map<varpool_node *, size_t> * map;
1510 vec<varpool_node *> nodes;
1513 /* Iterator structure for cgraph node sets. */
1514 struct cgraph_node_set_iterator
1516 cgraph_node_set set;
1517 unsigned index;
1520 /* Iterator structure for varpool node sets. */
1521 struct varpool_node_set_iterator
1523 varpool_node_set set;
1524 unsigned index;
1527 /* Context of polymorphic call. It represent information about the type of
1528 instance that may reach the call. This is used by ipa-devirt walkers of the
1529 type inheritance graph. */
1531 class GTY(()) ipa_polymorphic_call_context {
1532 public:
1533 /* The called object appears in an object of type OUTER_TYPE
1534 at offset OFFSET. When information is not 100% reliable, we
1535 use SPECULATIVE_OUTER_TYPE and SPECULATIVE_OFFSET. */
1536 HOST_WIDE_INT offset;
1537 HOST_WIDE_INT speculative_offset;
1538 tree outer_type;
1539 tree speculative_outer_type;
1540 /* True if outer object may be in construction or destruction. */
1541 unsigned maybe_in_construction : 1;
1542 /* True if outer object may be of derived type. */
1543 unsigned maybe_derived_type : 1;
1544 /* True if speculative outer object may be of derived type. We always
1545 speculate that construction does not happen. */
1546 unsigned speculative_maybe_derived_type : 1;
1547 /* True if the context is invalid and all calls should be redirected
1548 to BUILTIN_UNREACHABLE. */
1549 unsigned invalid : 1;
1550 /* True if the outer type is dynamic. */
1551 unsigned dynamic : 1;
1553 /* Build empty "I know nothing" context. */
1554 ipa_polymorphic_call_context ();
1555 /* Build polymorphic call context for indirect call E. */
1556 ipa_polymorphic_call_context (cgraph_edge *e);
1557 /* Build polymorphic call context for IP invariant CST.
1558 If specified, OTR_TYPE specify the type of polymorphic call
1559 that takes CST+OFFSET as a parameter. */
1560 ipa_polymorphic_call_context (tree cst, tree otr_type = NULL,
1561 HOST_WIDE_INT offset = 0);
1562 /* Build context for pointer REF contained in FNDECL at statement STMT.
1563 if INSTANCE is non-NULL, return pointer to the object described by
1564 the context. */
1565 ipa_polymorphic_call_context (tree fndecl, tree ref, gimple *stmt,
1566 tree *instance = NULL);
1568 /* Look for vtable stores or constructor calls to work out dynamic type
1569 of memory location. */
1570 bool get_dynamic_type (tree, tree, tree, gimple *, unsigned *);
1572 /* Make context non-speculative. */
1573 void clear_speculation ();
1575 /* Produce context specifying all derived types of OTR_TYPE. If OTR_TYPE is
1576 NULL, the context is set to dummy "I know nothing" setting. */
1577 void clear_outer_type (tree otr_type = NULL);
1579 /* Walk container types and modify context to point to actual class
1580 containing OTR_TYPE (if non-NULL) as base class.
1581 Return true if resulting context is valid.
1583 When CONSIDER_PLACEMENT_NEW is false, reject contexts that may be made
1584 valid only via allocation of new polymorphic type inside by means
1585 of placement new.
1587 When CONSIDER_BASES is false, only look for actual fields, not base types
1588 of TYPE. */
1589 bool restrict_to_inner_class (tree otr_type,
1590 bool consider_placement_new = true,
1591 bool consider_bases = true);
1593 /* Adjust all offsets in contexts by given number of bits. */
1594 void offset_by (HOST_WIDE_INT);
1595 /* Use when we cannot track dynamic type change. This speculatively assume
1596 type change is not happening. */
1597 void possible_dynamic_type_change (bool, tree otr_type = NULL);
1598 /* Assume that both THIS and a given context is valid and strengthen THIS
1599 if possible. Return true if any strengthening was made.
1600 If actual type the context is being used in is known, OTR_TYPE should be
1601 set accordingly. This improves quality of combined result. */
1602 bool combine_with (ipa_polymorphic_call_context, tree otr_type = NULL);
1603 bool meet_with (ipa_polymorphic_call_context, tree otr_type = NULL);
1605 /* Return TRUE if context is fully useless. */
1606 bool useless_p () const;
1607 /* Return TRUE if this context conveys the same information as X. */
1608 bool equal_to (const ipa_polymorphic_call_context &x) const;
1610 /* Dump human readable context to F. If NEWLINE is true, it will be
1611 terminated by a newline. */
1612 void dump (FILE *f, bool newline = true) const;
1613 void DEBUG_FUNCTION debug () const;
1615 /* LTO streaming. */
1616 void stream_out (struct output_block *) const;
1617 void stream_in (class lto_input_block *, class data_in *data_in);
1619 private:
1620 bool combine_speculation_with (tree, HOST_WIDE_INT, bool, tree);
1621 bool meet_speculation_with (tree, HOST_WIDE_INT, bool, tree);
1622 void set_by_decl (tree, HOST_WIDE_INT);
1623 bool set_by_invariant (tree, tree, HOST_WIDE_INT);
1624 bool speculation_consistent_p (tree, HOST_WIDE_INT, bool, tree) const;
1625 void make_speculative (tree otr_type = NULL);
1628 /* Structure containing additional information about an indirect call. */
1630 class GTY(()) cgraph_indirect_call_info
1632 public:
1633 /* When agg_content is set, an offset where the call pointer is located
1634 within the aggregate. */
1635 HOST_WIDE_INT offset;
1636 /* Context of the polymorphic call; use only when POLYMORPHIC flag is set. */
1637 ipa_polymorphic_call_context context;
1638 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
1639 HOST_WIDE_INT otr_token;
1640 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
1641 tree otr_type;
1642 /* Index of the parameter that is called. */
1643 int param_index;
1644 /* ECF flags determined from the caller. */
1645 int ecf_flags;
1647 /* Number of speculative call targets, it's less than GCOV_TOPN_VALUES. */
1648 unsigned num_speculative_call_targets : 16;
1650 /* Set when the call is a virtual call with the parameter being the
1651 associated object pointer rather than a simple direct call. */
1652 unsigned polymorphic : 1;
1653 /* Set when the call is a call of a pointer loaded from contents of an
1654 aggregate at offset. */
1655 unsigned agg_contents : 1;
1656 /* Set when this is a call through a member pointer. */
1657 unsigned member_ptr : 1;
1658 /* When the agg_contents bit is set, this one determines whether the
1659 destination is loaded from a parameter passed by reference. */
1660 unsigned by_ref : 1;
1661 /* When the agg_contents bit is set, this one determines whether we can
1662 deduce from the function body that the loaded value from the reference is
1663 never modified between the invocation of the function and the load
1664 point. */
1665 unsigned guaranteed_unmodified : 1;
1666 /* For polymorphic calls this specify whether the virtual table pointer
1667 may have changed in between function entry and the call. */
1668 unsigned vptr_changed : 1;
1671 class GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"),
1672 for_user)) cgraph_edge
1674 public:
1675 friend struct cgraph_node;
1676 friend class symbol_table;
1678 /* Remove EDGE from the cgraph. */
1679 static void remove (cgraph_edge *edge);
1681 /* Change field call_stmt of edge E to NEW_STMT. If UPDATE_SPECULATIVE and E
1682 is any component of speculative edge, then update all components.
1683 Speculations can be resolved in the process and EDGE can be removed and
1684 deallocated. Return the edge that now represents the call. */
1685 static cgraph_edge *set_call_stmt (cgraph_edge *e, gcall *new_stmt,
1686 bool update_speculative = true);
1688 /* Redirect callee of the edge to N. The function does not update underlying
1689 call expression. */
1690 void redirect_callee (cgraph_node *n);
1692 /* If the edge does not lead to a thunk, simply redirect it to N. Otherwise
1693 create one or more equivalent thunks for N and redirect E to the first in
1694 the chain. Note that it is then necessary to call
1695 n->expand_all_artificial_thunks once all callers are redirected. */
1696 void redirect_callee_duplicating_thunks (cgraph_node *n);
1698 /* Make an indirect edge with an unknown callee an ordinary edge leading to
1699 CALLEE. Speculations can be resolved in the process and EDGE can be
1700 removed and deallocated. Return the edge that now represents the
1701 call. */
1702 static cgraph_edge *make_direct (cgraph_edge *edge, cgraph_node *callee);
1704 /* Turn edge into speculative call calling N2. Update
1705 the profile so the direct call is taken COUNT times
1706 with FREQUENCY. speculative_id is used to link direct calls with their
1707 corresponding IPA_REF_ADDR references when representing speculative calls.
1709 cgraph_edge *make_speculative (cgraph_node *n2, profile_count direct_count,
1710 unsigned int speculative_id = 0);
1712 /* Speculative call consists of an indirect edge and one or more
1713 direct edge+ref pairs. Speculative will expand to the following sequence:
1715 if (call_dest == target1) // reference to target1
1716 target1 (); // direct call to target1
1717 else if (call_dest == target2) // reference to targt2
1718 target2 (); // direct call to target2
1719 else
1720 call_dest (); // indirect call
1722 Before the expansion we will have indirect call and the direct call+ref
1723 pairs all linked to single statement.
1725 Note that ref may point to different symbol than the corresponding call
1726 becuase the speculated edge may have been optimized (redirected to
1727 a clone) or inlined.
1729 Given an edge which is part of speculative call, return the first
1730 direct call edge in the speculative call sequence.
1732 In the example above called on any cgraph edge in the sequence it will
1733 return direct call to target1. */
1734 cgraph_edge *first_speculative_call_target ();
1736 /* Return next speculative call target or NULL if there is none.
1737 All targets are required to form an interval in the callee list.
1739 In example above, if called on call to target1 it will return call to
1740 target2. */
1741 cgraph_edge *next_speculative_call_target ()
1743 cgraph_edge *e = this;
1744 gcc_checking_assert (speculative && callee);
1746 if (e->next_callee && e->next_callee->speculative
1747 && e->next_callee->call_stmt == e->call_stmt
1748 && e->next_callee->lto_stmt_uid == e->lto_stmt_uid)
1749 return e->next_callee;
1750 return NULL;
1753 /* When called on any edge in the speculative call return the (unique)
1754 indirect call edge in the speculative call sequence. */
1755 cgraph_edge *speculative_call_indirect_edge ()
1757 gcc_checking_assert (speculative);
1758 if (!callee)
1759 return this;
1760 for (cgraph_edge *e2 = caller->indirect_calls;
1761 true; e2 = e2->next_callee)
1762 if (e2->speculative
1763 && call_stmt == e2->call_stmt
1764 && lto_stmt_uid == e2->lto_stmt_uid)
1765 return e2;
1768 /* When called on any edge in speculative call and when given any target
1769 of ref which is speculated to it returns the corresponding direct call.
1771 In example above if called on function target2 it will return call to
1772 target2. */
1773 cgraph_edge *speculative_call_for_target (cgraph_node *);
1775 /* Return REF corresponding to direct call in the specualtive call
1776 sequence. */
1777 ipa_ref *speculative_call_target_ref ()
1779 ipa_ref *ref;
1781 gcc_checking_assert (speculative);
1782 for (unsigned int i = 0; caller->iterate_reference (i, ref); i++)
1783 if (ref->speculative && ref->speculative_id == speculative_id
1784 && ref->stmt == (gimple *)call_stmt
1785 && ref->lto_stmt_uid == lto_stmt_uid)
1786 return ref;
1787 gcc_unreachable ();
1790 /* Speculative call edge turned out to be direct call to CALLEE_DECL. Remove
1791 the speculative call sequence and return edge representing the call, the
1792 original EDGE can be removed and deallocated. It is up to caller to
1793 redirect the call as appropriate. Return the edge that now represents the
1794 call.
1796 For "speculative" indirect call that contains multiple "speculative"
1797 targets (i.e. edge->indirect_info->num_speculative_call_targets > 1),
1798 decrease the count and only remove current direct edge.
1800 If no speculative direct call left to the speculative indirect call, remove
1801 the speculative of both the indirect call and corresponding direct edge.
1803 It is up to caller to iteratively resolve each "speculative" direct call
1804 and redirect the call as appropriate. */
1805 static cgraph_edge *resolve_speculation (cgraph_edge *edge,
1806 tree callee_decl = NULL);
1808 /* If necessary, change the function declaration in the call statement
1809 associated with edge E so that it corresponds to the edge callee.
1810 Speculations can be resolved in the process and EDGE can be removed and
1811 deallocated.
1813 The edge could be one of speculative direct call generated from speculative
1814 indirect call. In this circumstance, decrease the speculative targets
1815 count (i.e. num_speculative_call_targets) and redirect call stmt to the
1816 corresponding i-th target. If no speculative direct call left to the
1817 speculative indirect call, remove "speculative" of the indirect call and
1818 also redirect stmt to it's final direct target.
1820 It is up to caller to iteratively transform each "speculative"
1821 direct call as appropriate. */
1822 static gimple *redirect_call_stmt_to_callee (cgraph_edge *e);
1824 /* Create clone of edge in the node N represented
1825 by CALL_EXPR the callgraph. */
1826 cgraph_edge * clone (cgraph_node *n, gcall *call_stmt, unsigned stmt_uid,
1827 profile_count num, profile_count den,
1828 bool update_original);
1830 /* Verify edge count and frequency. */
1831 bool verify_count ();
1833 /* Return true when call of edge cannot lead to return from caller
1834 and thus it is safe to ignore its side effects for IPA analysis
1835 when computing side effects of the caller. */
1836 bool cannot_lead_to_return_p (void);
1838 /* Return true when the edge represents a direct recursion. */
1839 bool recursive_p (void);
1841 /* Return true if the edge may be considered hot. */
1842 bool maybe_hot_p (void);
1844 /* Get unique identifier of the edge. */
1845 inline int get_uid ()
1847 return m_uid;
1850 /* Get summary id of the edge. */
1851 inline int get_summary_id ()
1853 return m_summary_id;
1856 /* Rebuild cgraph edges for current function node. This needs to be run after
1857 passes that don't update the cgraph. */
1858 static unsigned int rebuild_edges (void);
1860 /* Rebuild cgraph references for current function node. This needs to be run
1861 after passes that don't update the cgraph. */
1862 static void rebuild_references (void);
1864 /* During LTO stream in this can be used to check whether call can possibly
1865 be internal to the current translation unit. */
1866 bool possibly_call_in_translation_unit_p (void);
1868 /* Return num_speculative_targets of this edge. */
1869 int num_speculative_call_targets_p (void);
1871 /* Expected number of executions: calculated in profile.c. */
1872 profile_count count;
1873 cgraph_node *caller;
1874 cgraph_node *callee;
1875 cgraph_edge *prev_caller;
1876 cgraph_edge *next_caller;
1877 cgraph_edge *prev_callee;
1878 cgraph_edge *next_callee;
1879 gcall *call_stmt;
1880 /* Additional information about an indirect call. Not cleared when an edge
1881 becomes direct. */
1882 cgraph_indirect_call_info *indirect_info;
1883 PTR GTY ((skip (""))) aux;
1884 /* When equal to CIF_OK, inline this call. Otherwise, points to the
1885 explanation why function was not inlined. */
1886 enum cgraph_inline_failed_t inline_failed;
1887 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
1888 when the function is serialized in. */
1889 unsigned int lto_stmt_uid;
1890 /* speculative id is used to link direct calls with their corresponding
1891 IPA_REF_ADDR references when representing speculative calls. */
1892 unsigned int speculative_id : 16;
1893 /* Whether this edge was made direct by indirect inlining. */
1894 unsigned int indirect_inlining_edge : 1;
1895 /* Whether this edge describes an indirect call with an undetermined
1896 callee. */
1897 unsigned int indirect_unknown_callee : 1;
1898 /* Whether this edge is still a dangling */
1899 /* True if the corresponding CALL stmt cannot be inlined. */
1900 unsigned int call_stmt_cannot_inline_p : 1;
1901 /* Can this call throw externally? */
1902 unsigned int can_throw_external : 1;
1903 /* Edges with SPECULATIVE flag represents indirect calls that was
1904 speculatively turned into direct (i.e. by profile feedback).
1905 The final code sequence will have form:
1907 if (call_target == expected_fn)
1908 expected_fn ();
1909 else
1910 call_target ();
1912 Every speculative call is represented by three components attached
1913 to a same call statement:
1914 1) a direct call (to expected_fn)
1915 2) an indirect call (to call_target)
1916 3) a IPA_REF_ADDR reference to expected_fn.
1918 Optimizers may later redirect direct call to clone, so 1) and 3)
1919 do not need to necessarily agree with destination. */
1920 unsigned int speculative : 1;
1921 /* Set to true when caller is a constructor or destructor of polymorphic
1922 type. */
1923 unsigned in_polymorphic_cdtor : 1;
1925 /* Return true if call must bind to current definition. */
1926 bool binds_to_current_def_p ();
1928 /* Expected frequency of executions within the function.
1929 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
1930 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
1931 int frequency ();
1933 /* Expected frequency of executions within the function. */
1934 sreal sreal_frequency ();
1935 private:
1936 /* Unique id of the edge. */
1937 int m_uid;
1939 /* Summary id that is recycled. */
1940 int m_summary_id;
1942 /* Remove the edge from the list of the callers of the callee. */
1943 void remove_caller (void);
1945 /* Remove the edge from the list of the callees of the caller. */
1946 void remove_callee (void);
1948 /* Set callee N of call graph edge and add it to the corresponding set of
1949 callers. */
1950 void set_callee (cgraph_node *n);
1952 /* Output flags of edge to a file F. */
1953 void dump_edge_flags (FILE *f);
1955 /* Dump edge to stderr. */
1956 void DEBUG_FUNCTION debug (void);
1958 /* Verify that call graph edge corresponds to DECL from the associated
1959 statement. Return true if the verification should fail. */
1960 bool verify_corresponds_to_fndecl (tree decl);
1963 #define CGRAPH_FREQ_BASE 1000
1964 #define CGRAPH_FREQ_MAX 100000
1966 /* The varpool data structure.
1967 Each static variable decl has assigned varpool_node. */
1969 struct GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node
1971 /* Constructor. */
1972 explicit varpool_node ()
1973 : symtab_node (SYMTAB_VARIABLE), output (0), dynamically_initialized (0),
1974 tls_model (TLS_MODEL_NONE), used_by_single_function (0)
1977 /* Dump given varpool node to F. */
1978 void dump (FILE *f);
1980 /* Dump given varpool node to stderr. */
1981 void DEBUG_FUNCTION debug (void);
1983 /* Remove variable from symbol table. */
1984 void remove (void);
1986 /* Remove node initializer when it is no longer needed. */
1987 void remove_initializer (void);
1989 void analyze (void);
1991 /* Return variable availability. */
1992 availability get_availability (symtab_node *ref = NULL);
1994 /* When doing LTO, read variable's constructor from disk if
1995 it is not already present. */
1996 tree get_constructor (void);
1998 /* Return true if variable has constructor that can be used for folding. */
1999 bool ctor_useable_for_folding_p (void);
2001 /* For given variable pool node, walk the alias chain to return the function
2002 the variable is alias of. Do not walk through thunks.
2003 When AVAILABILITY is non-NULL, get minimal availability in the chain.
2004 When REF is non-NULL, assume that reference happens in symbol REF
2005 when determining the availability. */
2006 inline varpool_node *ultimate_alias_target
2007 (availability *availability = NULL, symtab_node *ref = NULL);
2009 /* Return node that alias is aliasing. */
2010 inline varpool_node *get_alias_target (void);
2012 /* Output one variable, if necessary. Return whether we output it. */
2013 bool assemble_decl (void);
2015 /* For variables in named sections make sure get_variable_section
2016 is called before we switch to those sections. Then section
2017 conflicts between read-only and read-only requiring relocations
2018 sections can be resolved. */
2019 void finalize_named_section_flags (void);
2021 /* Call callback on varpool symbol and aliases associated to varpool symbol.
2022 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
2023 skipped. */
2024 bool call_for_symbol_and_aliases (bool (*callback) (varpool_node *, void *),
2025 void *data,
2026 bool include_overwritable);
2028 /* Return true when variable should be considered externally visible. */
2029 bool externally_visible_p (void);
2031 /* Return true when all references to variable must be visible
2032 in ipa_ref_list.
2033 i.e. if the variable is not externally visible or not used in some magic
2034 way (asm statement or such).
2035 The magic uses are all summarized in force_output flag. */
2036 inline bool all_refs_explicit_p ();
2038 /* Return true when variable can be removed from variable pool
2039 if all direct calls are eliminated. */
2040 inline bool can_remove_if_no_refs_p (void);
2042 /* Add the variable DECL to the varpool.
2043 Unlike finalize_decl function is intended to be used
2044 by middle end and allows insertion of new variable at arbitrary point
2045 of compilation. */
2046 static void add (tree decl);
2048 /* Return varpool node for given symbol and check it is a function. */
2049 static inline varpool_node *get (const_tree decl);
2051 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct
2052 the middle end to output the variable to asm file, if needed or externally
2053 visible. */
2054 static void finalize_decl (tree decl);
2056 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
2057 Extra name aliases are output whenever DECL is output. */
2058 static varpool_node * create_extra_name_alias (tree alias, tree decl);
2060 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
2061 Extra name aliases are output whenever DECL is output. */
2062 static varpool_node * create_alias (tree, tree);
2064 /* Dump the variable pool to F. */
2065 static void dump_varpool (FILE *f);
2067 /* Dump the variable pool to stderr. */
2068 static void DEBUG_FUNCTION debug_varpool (void);
2070 /* Allocate new callgraph node and insert it into basic data structures. */
2071 static varpool_node *create_empty (void);
2073 /* Return varpool node assigned to DECL. Create new one when needed. */
2074 static varpool_node *get_create (tree decl);
2076 /* Given an assembler name, lookup node. */
2077 static varpool_node *get_for_asmname (tree asmname);
2079 /* Set when variable is scheduled to be assembled. */
2080 unsigned output : 1;
2082 /* Set if the variable is dynamically initialized, except for
2083 function local statics. */
2084 unsigned dynamically_initialized : 1;
2086 ENUM_BITFIELD(tls_model) tls_model : 3;
2088 /* Set if the variable is known to be used by single function only.
2089 This is computed by ipa_single_use pass and used by late optimizations
2090 in places where optimization would be valid for local static variable
2091 if we did not do any inter-procedural code movement. */
2092 unsigned used_by_single_function : 1;
2094 private:
2095 /* Assemble thunks and aliases associated to varpool node. */
2096 void assemble_aliases (void);
2098 /* Worker for call_for_node_and_aliases. */
2099 bool call_for_symbol_and_aliases_1 (bool (*callback) (varpool_node *, void *),
2100 void *data,
2101 bool include_overwritable);
2104 /* Every top level asm statement is put into a asm_node. */
2106 struct GTY(()) asm_node {
2107 /* Next asm node. */
2108 asm_node *next;
2109 /* String for this asm node. */
2110 tree asm_str;
2111 /* Ordering of all cgraph nodes. */
2112 int order;
2115 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
2117 template <>
2118 template <>
2119 inline bool
2120 is_a_helper <cgraph_node *>::test (symtab_node *p)
2122 return p && p->type == SYMTAB_FUNCTION;
2125 /* Report whether or not THIS symtab node is a variable, aka varpool_node. */
2127 template <>
2128 template <>
2129 inline bool
2130 is_a_helper <varpool_node *>::test (symtab_node *p)
2132 return p && p->type == SYMTAB_VARIABLE;
2135 typedef void (*cgraph_edge_hook)(cgraph_edge *, void *);
2136 typedef void (*cgraph_node_hook)(cgraph_node *, void *);
2137 typedef void (*varpool_node_hook)(varpool_node *, void *);
2138 typedef void (*cgraph_2edge_hook)(cgraph_edge *, cgraph_edge *, void *);
2139 typedef void (*cgraph_2node_hook)(cgraph_node *, cgraph_node *, void *);
2141 struct cgraph_edge_hook_list;
2142 struct cgraph_node_hook_list;
2143 struct varpool_node_hook_list;
2144 struct cgraph_2edge_hook_list;
2145 struct cgraph_2node_hook_list;
2147 /* Map from a symbol to initialization/finalization priorities. */
2148 struct GTY(()) symbol_priority_map {
2149 priority_type init;
2150 priority_type fini;
2153 enum symtab_state
2155 /* Frontend is parsing and finalizing functions. */
2156 PARSING,
2157 /* Callgraph is being constructed. It is safe to add new functions. */
2158 CONSTRUCTION,
2159 /* Callgraph is being streamed-in at LTO time. */
2160 LTO_STREAMING,
2161 /* Callgraph is built and early IPA passes are being run. */
2162 IPA,
2163 /* Callgraph is built and all functions are transformed to SSA form. */
2164 IPA_SSA,
2165 /* All inline decisions are done; it is now possible to remove extern inline
2166 functions and virtual call targets. */
2167 IPA_SSA_AFTER_INLINING,
2168 /* Functions are now ordered and being passed to RTL expanders. */
2169 EXPANSION,
2170 /* All cgraph expansion is done. */
2171 FINISHED
2174 struct asmname_hasher : ggc_ptr_hash <symtab_node>
2176 typedef const_tree compare_type;
2178 static hashval_t hash (symtab_node *n);
2179 static bool equal (symtab_node *n, const_tree t);
2182 /* Core summaries maintained about symbols. */
2184 struct thunk_info;
2185 template <class T> class function_summary;
2186 typedef function_summary <thunk_info *> thunk_summary;
2188 struct clone_info;
2189 template <class T> class function_summary;
2190 typedef function_summary <clone_info *> clone_summary;
2192 class GTY((tag ("SYMTAB"))) symbol_table
2194 public:
2195 friend struct symtab_node;
2196 friend struct cgraph_node;
2197 friend struct cgraph_edge;
2199 symbol_table ():
2200 cgraph_count (0), cgraph_max_uid (1), cgraph_max_summary_id (0),
2201 edges_count (0), edges_max_uid (1), edges_max_summary_id (0),
2202 cgraph_released_summary_ids (), edge_released_summary_ids (),
2203 nodes (NULL), asmnodes (NULL), asm_last_node (NULL),
2204 order (0), max_unit (0), global_info_ready (false), state (PARSING),
2205 function_flags_ready (false), cpp_implicit_aliases_done (false),
2206 section_hash (NULL), assembler_name_hash (NULL), init_priority_hash (NULL),
2207 dump_file (NULL), ipa_clones_dump_file (NULL), cloned_nodes (),
2208 m_thunks (NULL), m_clones (NULL),
2209 m_first_edge_removal_hook (NULL), m_first_cgraph_removal_hook (NULL),
2210 m_first_edge_duplicated_hook (NULL), m_first_cgraph_duplicated_hook (NULL),
2211 m_first_cgraph_insertion_hook (NULL), m_first_varpool_insertion_hook (NULL),
2212 m_first_varpool_removal_hook (NULL)
2216 /* Initialize callgraph dump file. */
2217 void initialize (void);
2219 /* Register a top-level asm statement ASM_STR. */
2220 inline asm_node *finalize_toplevel_asm (tree asm_str);
2222 /* Analyze the whole compilation unit once it is parsed completely. */
2223 void finalize_compilation_unit (void);
2225 /* C++ frontend produce same body aliases all over the place, even before PCH
2226 gets streamed out. It relies on us linking the aliases with their function
2227 in order to do the fixups, but ipa-ref is not PCH safe. Consequently we
2228 first produce aliases without links, but once C++ FE is sure it won't
2229 stream PCH we build the links via this function. */
2230 void process_same_body_aliases (void);
2232 /* Perform simple optimizations based on callgraph. */
2233 void compile (void);
2235 /* Process CGRAPH_NEW_FUNCTIONS and perform actions necessary to add these
2236 functions into callgraph in a way so they look like ordinary reachable
2237 functions inserted into callgraph already at construction time. */
2238 void process_new_functions (void);
2240 /* Register a symbol NODE. */
2241 inline void register_symbol (symtab_node *node);
2243 inline void
2244 clear_asm_symbols (void)
2246 asmnodes = NULL;
2247 asm_last_node = NULL;
2250 /* Perform reachability analysis and reclaim all unreachable nodes. */
2251 bool remove_unreachable_nodes (FILE *file);
2253 /* Optimization of function bodies might've rendered some variables as
2254 unnecessary so we want to avoid these from being compiled. Re-do
2255 reachability starting from variables that are either externally visible
2256 or was referred from the asm output routines. */
2257 void remove_unreferenced_decls (void);
2259 /* Unregister a symbol NODE. */
2260 inline void unregister (symtab_node *node);
2262 /* Allocate new callgraph node and insert it into basic data structures. */
2263 cgraph_node *create_empty (void);
2265 /* Release a callgraph NODE. */
2266 void release_symbol (cgraph_node *node);
2268 /* Output all variables enqueued to be assembled. */
2269 bool output_variables (void);
2271 /* Weakrefs may be associated to external decls and thus not output
2272 at expansion time. Emit all necessary aliases. */
2273 void output_weakrefs (void);
2275 /* Return first static symbol with definition. */
2276 inline symtab_node *first_symbol (void);
2278 /* Return first assembler symbol. */
2279 inline asm_node *
2280 first_asm_symbol (void)
2282 return asmnodes;
2285 /* Return first static symbol with definition. */
2286 inline symtab_node *first_defined_symbol (void);
2288 /* Return first variable. */
2289 inline varpool_node *first_variable (void);
2291 /* Return next variable after NODE. */
2292 inline varpool_node *next_variable (varpool_node *node);
2294 /* Return first static variable with initializer. */
2295 inline varpool_node *first_static_initializer (void);
2297 /* Return next static variable with initializer after NODE. */
2298 inline varpool_node *next_static_initializer (varpool_node *node);
2300 /* Return first static variable with definition. */
2301 inline varpool_node *first_defined_variable (void);
2303 /* Return next static variable with definition after NODE. */
2304 inline varpool_node *next_defined_variable (varpool_node *node);
2306 /* Return first function with body defined. */
2307 inline cgraph_node *first_defined_function (void);
2309 /* Return next function with body defined after NODE. */
2310 inline cgraph_node *next_defined_function (cgraph_node *node);
2312 /* Return first function. */
2313 inline cgraph_node *first_function (void);
2315 /* Return next function. */
2316 inline cgraph_node *next_function (cgraph_node *node);
2318 /* Return first function with body defined. */
2319 cgraph_node *first_function_with_gimple_body (void);
2321 /* Return next reachable static variable with initializer after NODE. */
2322 inline cgraph_node *next_function_with_gimple_body (cgraph_node *node);
2324 /* Register HOOK to be called with DATA on each removed edge. */
2325 cgraph_edge_hook_list *add_edge_removal_hook (cgraph_edge_hook hook,
2326 void *data);
2328 /* Remove ENTRY from the list of hooks called on removing edges. */
2329 void remove_edge_removal_hook (cgraph_edge_hook_list *entry);
2331 /* Register HOOK to be called with DATA on each removed node. */
2332 cgraph_node_hook_list *add_cgraph_removal_hook (cgraph_node_hook hook,
2333 void *data);
2335 /* Remove ENTRY from the list of hooks called on removing nodes. */
2336 void remove_cgraph_removal_hook (cgraph_node_hook_list *entry);
2338 /* Register HOOK to be called with DATA on each removed node. */
2339 varpool_node_hook_list *add_varpool_removal_hook (varpool_node_hook hook,
2340 void *data);
2342 /* Remove ENTRY from the list of hooks called on removing nodes. */
2343 void remove_varpool_removal_hook (varpool_node_hook_list *entry);
2345 /* Register HOOK to be called with DATA on each inserted node. */
2346 cgraph_node_hook_list *add_cgraph_insertion_hook (cgraph_node_hook hook,
2347 void *data);
2349 /* Remove ENTRY from the list of hooks called on inserted nodes. */
2350 void remove_cgraph_insertion_hook (cgraph_node_hook_list *entry);
2352 /* Register HOOK to be called with DATA on each inserted node. */
2353 varpool_node_hook_list *add_varpool_insertion_hook (varpool_node_hook hook,
2354 void *data);
2356 /* Remove ENTRY from the list of hooks called on inserted nodes. */
2357 void remove_varpool_insertion_hook (varpool_node_hook_list *entry);
2359 /* Register HOOK to be called with DATA on each duplicated edge. */
2360 cgraph_2edge_hook_list *add_edge_duplication_hook (cgraph_2edge_hook hook,
2361 void *data);
2362 /* Remove ENTRY from the list of hooks called on duplicating edges. */
2363 void remove_edge_duplication_hook (cgraph_2edge_hook_list *entry);
2365 /* Register HOOK to be called with DATA on each duplicated node. */
2366 cgraph_2node_hook_list *add_cgraph_duplication_hook (cgraph_2node_hook hook,
2367 void *data);
2369 /* Remove ENTRY from the list of hooks called on duplicating nodes. */
2370 void remove_cgraph_duplication_hook (cgraph_2node_hook_list *entry);
2372 /* Call all edge removal hooks. */
2373 void call_edge_removal_hooks (cgraph_edge *e);
2375 /* Call all node insertion hooks. */
2376 void call_cgraph_insertion_hooks (cgraph_node *node);
2378 /* Call all node removal hooks. */
2379 void call_cgraph_removal_hooks (cgraph_node *node);
2381 /* Call all node duplication hooks. */
2382 void call_cgraph_duplication_hooks (cgraph_node *node, cgraph_node *node2);
2384 /* Call all edge duplication hooks. */
2385 void call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2);
2387 /* Call all node removal hooks. */
2388 void call_varpool_removal_hooks (varpool_node *node);
2390 /* Call all node insertion hooks. */
2391 void call_varpool_insertion_hooks (varpool_node *node);
2393 /* Arrange node to be first in its entry of assembler_name_hash. */
2394 void symtab_prevail_in_asm_name_hash (symtab_node *node);
2396 /* Initialize asm name hash unless. */
2397 void symtab_initialize_asm_name_hash (void);
2399 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
2400 void change_decl_assembler_name (tree decl, tree name);
2402 /* Dump symbol table to F. */
2403 void dump (FILE *f);
2405 /* Dump symbol table to F in graphviz format. */
2406 void dump_graphviz (FILE *f);
2408 /* Dump symbol table to stderr. */
2409 void DEBUG_FUNCTION debug (void);
2411 /* Assign a new summary ID for the callgraph NODE. */
2412 inline int assign_summary_id (cgraph_node *node)
2414 if (!cgraph_released_summary_ids.is_empty ())
2415 node->m_summary_id = cgraph_released_summary_ids.pop ();
2416 else
2417 node->m_summary_id = cgraph_max_summary_id++;
2419 return node->m_summary_id;
2422 /* Assign a new summary ID for the callgraph EDGE. */
2423 inline int assign_summary_id (cgraph_edge *edge)
2425 if (!edge_released_summary_ids.is_empty ())
2426 edge->m_summary_id = edge_released_summary_ids.pop ();
2427 else
2428 edge->m_summary_id = edges_max_summary_id++;
2430 return edge->m_summary_id;
2433 /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
2434 name. */
2435 static bool assembler_names_equal_p (const char *name1, const char *name2);
2437 int cgraph_count;
2438 int cgraph_max_uid;
2439 int cgraph_max_summary_id;
2441 int edges_count;
2442 int edges_max_uid;
2443 int edges_max_summary_id;
2445 /* Vector of released summary IDS for cgraph nodes. */
2446 vec<int> GTY ((skip)) cgraph_released_summary_ids;
2448 /* Vector of released summary IDS for cgraph nodes. */
2449 vec<int> GTY ((skip)) edge_released_summary_ids;
2451 /* Return symbol used to separate symbol name from suffix. */
2452 static char symbol_suffix_separator ();
2454 symtab_node* GTY(()) nodes;
2455 asm_node* GTY(()) asmnodes;
2456 asm_node* GTY(()) asm_last_node;
2458 /* The order index of the next symtab node to be created. This is
2459 used so that we can sort the cgraph nodes in order by when we saw
2460 them, to support -fno-toplevel-reorder. */
2461 int order;
2463 /* Maximal unit ID used. */
2464 int max_unit;
2466 /* Set when whole unit has been analyzed so we can access global info. */
2467 bool global_info_ready;
2468 /* What state callgraph is in right now. */
2469 enum symtab_state state;
2470 /* Set when the cgraph is fully build and the basic flags are computed. */
2471 bool function_flags_ready;
2473 bool cpp_implicit_aliases_done;
2475 /* Hash table used to hold sections. */
2476 hash_table<section_name_hasher> *GTY(()) section_hash;
2478 /* Hash table used to convert assembler names into nodes. */
2479 hash_table<asmname_hasher> *assembler_name_hash;
2481 /* Hash table used to hold init priorities. */
2482 hash_map<symtab_node *, symbol_priority_map> *init_priority_hash;
2484 FILE* GTY ((skip)) dump_file;
2486 FILE* GTY ((skip)) ipa_clones_dump_file;
2488 hash_set <const cgraph_node *> GTY ((skip)) cloned_nodes;
2490 /* Thunk annotations. */
2491 thunk_summary *m_thunks;
2493 /* Virtual clone annotations. */
2494 clone_summary *m_clones;
2496 private:
2497 /* Allocate a cgraph_edge structure and fill it with data according to the
2498 parameters of which only CALLEE can be NULL (when creating an indirect
2499 call edge). CLONING_P should be set if properties that are copied from an
2500 original edge should not be calculated. */
2501 cgraph_edge *create_edge (cgraph_node *caller, cgraph_node *callee,
2502 gcall *call_stmt, profile_count count,
2503 bool indir_unknown_callee, bool cloning_p);
2505 /* Put the edge onto the free list. */
2506 void free_edge (cgraph_edge *e);
2508 /* Insert NODE to assembler name hash. */
2509 void insert_to_assembler_name_hash (symtab_node *node, bool with_clones);
2511 /* Remove NODE from assembler name hash. */
2512 void unlink_from_assembler_name_hash (symtab_node *node, bool with_clones);
2514 /* Hash asmnames ignoring the user specified marks. */
2515 static hashval_t decl_assembler_name_hash (const_tree asmname);
2517 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
2518 static bool decl_assembler_name_equal (tree decl, const_tree asmname);
2520 friend struct asmname_hasher;
2522 /* List of hooks triggered when an edge is removed. */
2523 cgraph_edge_hook_list * GTY((skip)) m_first_edge_removal_hook;
2524 /* List of hooks trigger_red when a cgraph node is removed. */
2525 cgraph_node_hook_list * GTY((skip)) m_first_cgraph_removal_hook;
2526 /* List of hooks triggered when an edge is duplicated. */
2527 cgraph_2edge_hook_list * GTY((skip)) m_first_edge_duplicated_hook;
2528 /* List of hooks triggered when a node is duplicated. */
2529 cgraph_2node_hook_list * GTY((skip)) m_first_cgraph_duplicated_hook;
2530 /* List of hooks triggered when an function is inserted. */
2531 cgraph_node_hook_list * GTY((skip)) m_first_cgraph_insertion_hook;
2532 /* List of hooks triggered when an variable is inserted. */
2533 varpool_node_hook_list * GTY((skip)) m_first_varpool_insertion_hook;
2534 /* List of hooks triggered when a node is removed. */
2535 varpool_node_hook_list * GTY((skip)) m_first_varpool_removal_hook;
2538 extern GTY(()) symbol_table *symtab;
2540 extern vec<cgraph_node *> cgraph_new_nodes;
2542 inline hashval_t
2543 asmname_hasher::hash (symtab_node *n)
2545 return symbol_table::decl_assembler_name_hash
2546 (DECL_ASSEMBLER_NAME (n->decl));
2549 inline bool
2550 asmname_hasher::equal (symtab_node *n, const_tree t)
2552 return symbol_table::decl_assembler_name_equal (n->decl, t);
2555 /* In cgraph.c */
2556 void cgraph_c_finalize (void);
2557 void release_function_body (tree);
2558 cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
2560 void cgraph_update_edges_for_call_stmt (gimple *, tree, gimple *);
2561 bool cgraph_function_possibly_inlined_p (tree);
2563 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
2564 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
2566 /* In cgraphunit.c */
2567 void cgraphunit_c_finalize (void);
2568 int tp_first_run_node_cmp (const void *pa, const void *pb);
2570 /* In symtab-thunks.cc */
2571 void symtab_thunks_cc_finalize (void);
2573 /* Initialize datastructures so DECL is a function in lowered gimple form.
2574 IN_SSA is true if the gimple is in SSA. */
2575 basic_block init_lowered_empty_function (tree, bool, profile_count);
2577 tree thunk_adjust (gimple_stmt_iterator *, tree, bool, HOST_WIDE_INT, tree,
2578 HOST_WIDE_INT);
2579 /* In cgraphclones.c */
2581 tree clone_function_name_numbered (const char *name, const char *suffix);
2582 tree clone_function_name_numbered (tree decl, const char *suffix);
2583 tree clone_function_name (const char *name, const char *suffix,
2584 unsigned long number);
2585 tree clone_function_name (tree decl, const char *suffix,
2586 unsigned long number);
2587 tree clone_function_name (tree decl, const char *suffix);
2589 void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *,
2590 ipa_param_adjustments *,
2591 bool, bitmap, basic_block);
2593 void dump_callgraph_transformation (const cgraph_node *original,
2594 const cgraph_node *clone,
2595 const char *suffix);
2596 /* In cgraphbuild.c */
2597 int compute_call_stmt_bb_frequency (tree, basic_block bb);
2598 void record_references_in_initializer (tree, bool);
2600 /* In ipa.c */
2601 void cgraph_build_static_cdtor (char which, tree body, int priority);
2602 bool ipa_discover_variable_flags (void);
2604 /* In varpool.c */
2605 tree ctor_for_folding (tree);
2607 /* In ipa-inline-analysis.c */
2608 void initialize_inline_failed (struct cgraph_edge *);
2609 bool speculation_useful_p (struct cgraph_edge *e, bool anticipate_inlining);
2611 /* Return true when the symbol is real symbol, i.e. it is not inline clone
2612 or abstract function kept for debug info purposes only. */
2613 inline bool
2614 symtab_node::real_symbol_p (void)
2616 cgraph_node *cnode;
2618 if (DECL_ABSTRACT_P (decl))
2619 return false;
2620 if (transparent_alias && definition)
2621 return false;
2622 if (!is_a <cgraph_node *> (this))
2623 return true;
2624 cnode = dyn_cast <cgraph_node *> (this);
2625 if (cnode->inlined_to)
2626 return false;
2627 return true;
2630 /* Return true if DECL should have entry in symbol table if used.
2631 Those are functions and static & external variables. */
2633 static inline bool
2634 decl_in_symtab_p (const_tree decl)
2636 return (TREE_CODE (decl) == FUNCTION_DECL
2637 || (TREE_CODE (decl) == VAR_DECL
2638 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))));
2641 inline bool
2642 symtab_node::in_same_comdat_group_p (symtab_node *target)
2644 symtab_node *source = this;
2646 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
2648 if (cn->inlined_to)
2649 source = cn->inlined_to;
2651 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
2653 if (cn->inlined_to)
2654 target = cn->inlined_to;
2657 return source->get_comdat_group () == target->get_comdat_group ();
2660 /* Return node that alias is aliasing. */
2662 inline symtab_node *
2663 symtab_node::get_alias_target (void)
2665 ipa_ref *ref = NULL;
2666 iterate_reference (0, ref);
2667 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
2668 return ref->referred;
2671 /* Return the DECL (or identifier) that alias is aliasing. Unlike the above,
2672 this works whether or not the alias has been analyzed already. */
2674 inline tree
2675 symtab_node::get_alias_target_tree ()
2677 if (alias_target)
2678 return alias_target;
2679 return get_alias_target ()->decl;
2682 /* Return next reachable static symbol with initializer after the node. */
2684 inline symtab_node *
2685 symtab_node::next_defined_symbol (void)
2687 symtab_node *node1 = next;
2689 for (; node1; node1 = node1->next)
2690 if (node1->definition)
2691 return node1;
2693 return NULL;
2696 /* Iterates I-th reference in the list, REF is also set. */
2698 inline ipa_ref *
2699 symtab_node::iterate_reference (unsigned i, ipa_ref *&ref)
2701 ref_list.references.iterate (i, &ref);
2703 return ref;
2706 /* Iterates I-th referring item in the list, REF is also set. */
2708 inline ipa_ref *
2709 symtab_node::iterate_referring (unsigned i, ipa_ref *&ref)
2711 ref_list.referring.iterate (i, &ref);
2713 return ref;
2716 /* Iterates I-th referring alias item in the list, REF is also set. */
2718 inline ipa_ref *
2719 symtab_node::iterate_direct_aliases (unsigned i, ipa_ref *&ref)
2721 ref_list.referring.iterate (i, &ref);
2723 if (ref && ref->use != IPA_REF_ALIAS)
2724 return NULL;
2726 return ref;
2729 /* Return true if list contains an alias. */
2731 inline bool
2732 symtab_node::has_aliases_p (void)
2734 ipa_ref *ref = NULL;
2736 return (iterate_direct_aliases (0, ref) != NULL);
2739 /* Return true when RESOLUTION indicate that linker will use
2740 the symbol from non-LTO object files. */
2742 inline bool
2743 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution)
2745 return (resolution == LDPR_PREVAILING_DEF
2746 || resolution == LDPR_PREEMPTED_REG
2747 || resolution == LDPR_RESOLVED_EXEC
2748 || resolution == LDPR_RESOLVED_DYN);
2751 /* Return true when symtab_node is known to be used from other (non-LTO)
2752 object file. Known only when doing LTO via linker plugin. */
2754 inline bool
2755 symtab_node::used_from_object_file_p (void)
2757 if (!TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
2758 return false;
2759 if (resolution_used_from_other_file_p (resolution))
2760 return true;
2761 return false;
2764 /* Return varpool node for given symbol and check it is a function. */
2766 inline varpool_node *
2767 varpool_node::get (const_tree decl)
2769 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
2770 return dyn_cast<varpool_node *> (symtab_node::get (decl));
2773 /* Register a symbol NODE. */
2775 inline void
2776 symbol_table::register_symbol (symtab_node *node)
2778 node->next = nodes;
2779 node->previous = NULL;
2781 if (nodes)
2782 nodes->previous = node;
2783 nodes = node;
2785 node->order = order++;
2788 /* Register a top-level asm statement ASM_STR. */
2790 asm_node *
2791 symbol_table::finalize_toplevel_asm (tree asm_str)
2793 asm_node *node;
2795 node = ggc_cleared_alloc<asm_node> ();
2796 node->asm_str = asm_str;
2797 node->order = order++;
2798 node->next = NULL;
2800 if (asmnodes == NULL)
2801 asmnodes = node;
2802 else
2803 asm_last_node->next = node;
2805 asm_last_node = node;
2806 return node;
2809 /* Unregister a symbol NODE. */
2810 inline void
2811 symbol_table::unregister (symtab_node *node)
2813 if (node->previous)
2814 node->previous->next = node->next;
2815 else
2816 nodes = node->next;
2818 if (node->next)
2819 node->next->previous = node->previous;
2821 node->next = NULL;
2822 node->previous = NULL;
2825 /* Release a callgraph NODE with UID and put in to the list of free nodes. */
2827 inline void
2828 symbol_table::release_symbol (cgraph_node *node)
2830 cgraph_count--;
2831 if (node->m_summary_id != -1)
2832 cgraph_released_summary_ids.safe_push (node->m_summary_id);
2833 ggc_free (node);
2836 /* Return first static symbol with definition. */
2837 inline symtab_node *
2838 symbol_table::first_symbol (void)
2840 return nodes;
2843 /* Walk all symbols. */
2844 #define FOR_EACH_SYMBOL(node) \
2845 for ((node) = symtab->first_symbol (); (node); (node) = (node)->next)
2847 /* Return first static symbol with definition. */
2848 inline symtab_node *
2849 symbol_table::first_defined_symbol (void)
2851 symtab_node *node;
2853 for (node = nodes; node; node = node->next)
2854 if (node->definition)
2855 return node;
2857 return NULL;
2860 /* Walk all symbols with definitions in current unit. */
2861 #define FOR_EACH_DEFINED_SYMBOL(node) \
2862 for ((node) = symtab->first_defined_symbol (); (node); \
2863 (node) = node->next_defined_symbol ())
2865 /* Return first variable. */
2866 inline varpool_node *
2867 symbol_table::first_variable (void)
2869 symtab_node *node;
2870 for (node = nodes; node; node = node->next)
2871 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
2872 return vnode;
2873 return NULL;
2876 /* Return next variable after NODE. */
2877 inline varpool_node *
2878 symbol_table::next_variable (varpool_node *node)
2880 symtab_node *node1 = node->next;
2881 for (; node1; node1 = node1->next)
2882 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
2883 return vnode1;
2884 return NULL;
2886 /* Walk all variables. */
2887 #define FOR_EACH_VARIABLE(node) \
2888 for ((node) = symtab->first_variable (); \
2889 (node); \
2890 (node) = symtab->next_variable ((node)))
2892 /* Return first static variable with initializer. */
2893 inline varpool_node *
2894 symbol_table::first_static_initializer (void)
2896 symtab_node *node;
2897 for (node = nodes; node; node = node->next)
2899 varpool_node *vnode = dyn_cast <varpool_node *> (node);
2900 if (vnode && DECL_INITIAL (node->decl))
2901 return vnode;
2903 return NULL;
2906 /* Return next static variable with initializer after NODE. */
2907 inline varpool_node *
2908 symbol_table::next_static_initializer (varpool_node *node)
2910 symtab_node *node1 = node->next;
2911 for (; node1; node1 = node1->next)
2913 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
2914 if (vnode1 && DECL_INITIAL (node1->decl))
2915 return vnode1;
2917 return NULL;
2920 /* Walk all static variables with initializer set. */
2921 #define FOR_EACH_STATIC_INITIALIZER(node) \
2922 for ((node) = symtab->first_static_initializer (); (node); \
2923 (node) = symtab->next_static_initializer (node))
2925 /* Return first static variable with definition. */
2926 inline varpool_node *
2927 symbol_table::first_defined_variable (void)
2929 symtab_node *node;
2930 for (node = nodes; node; node = node->next)
2932 varpool_node *vnode = dyn_cast <varpool_node *> (node);
2933 if (vnode && vnode->definition)
2934 return vnode;
2936 return NULL;
2939 /* Return next static variable with definition after NODE. */
2940 inline varpool_node *
2941 symbol_table::next_defined_variable (varpool_node *node)
2943 symtab_node *node1 = node->next;
2944 for (; node1; node1 = node1->next)
2946 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
2947 if (vnode1 && vnode1->definition)
2948 return vnode1;
2950 return NULL;
2952 /* Walk all variables with definitions in current unit. */
2953 #define FOR_EACH_DEFINED_VARIABLE(node) \
2954 for ((node) = symtab->first_defined_variable (); (node); \
2955 (node) = symtab->next_defined_variable (node))
2957 /* Return first function with body defined. */
2958 inline cgraph_node *
2959 symbol_table::first_defined_function (void)
2961 symtab_node *node;
2962 for (node = nodes; node; node = node->next)
2964 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
2965 if (cn && cn->definition)
2966 return cn;
2968 return NULL;
2971 /* Return next function with body defined after NODE. */
2972 inline cgraph_node *
2973 symbol_table::next_defined_function (cgraph_node *node)
2975 symtab_node *node1 = node->next;
2976 for (; node1; node1 = node1->next)
2978 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
2979 if (cn1 && cn1->definition)
2980 return cn1;
2982 return NULL;
2985 /* Walk all functions with body defined. */
2986 #define FOR_EACH_DEFINED_FUNCTION(node) \
2987 for ((node) = symtab->first_defined_function (); (node); \
2988 (node) = symtab->next_defined_function ((node)))
2990 /* Return first function. */
2991 inline cgraph_node *
2992 symbol_table::first_function (void)
2994 symtab_node *node;
2995 for (node = nodes; node; node = node->next)
2996 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
2997 return cn;
2998 return NULL;
3001 /* Return next function. */
3002 inline cgraph_node *
3003 symbol_table::next_function (cgraph_node *node)
3005 symtab_node *node1 = node->next;
3006 for (; node1; node1 = node1->next)
3007 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
3008 return cn1;
3009 return NULL;
3012 /* Return first function with body defined. */
3013 inline cgraph_node *
3014 symbol_table::first_function_with_gimple_body (void)
3016 symtab_node *node;
3017 for (node = nodes; node; node = node->next)
3019 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
3020 if (cn && cn->has_gimple_body_p ())
3021 return cn;
3023 return NULL;
3026 /* Return next reachable static variable with initializer after NODE. */
3027 inline cgraph_node *
3028 symbol_table::next_function_with_gimple_body (cgraph_node *node)
3030 symtab_node *node1 = node->next;
3031 for (; node1; node1 = node1->next)
3033 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
3034 if (cn1 && cn1->has_gimple_body_p ())
3035 return cn1;
3037 return NULL;
3040 /* Walk all functions. */
3041 #define FOR_EACH_FUNCTION(node) \
3042 for ((node) = symtab->first_function (); (node); \
3043 (node) = symtab->next_function ((node)))
3045 /* Return true when callgraph node is a function with Gimple body defined
3046 in current unit. Functions can also be define externally or they
3047 can be thunks with no Gimple representation.
3049 Note that at WPA stage, the function body may not be present in memory. */
3051 inline bool
3052 cgraph_node::has_gimple_body_p (void)
3054 return definition && !thunk && !alias;
3057 /* Walk all functions with body defined. */
3058 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
3059 for ((node) = symtab->first_function_with_gimple_body (); (node); \
3060 (node) = symtab->next_function_with_gimple_body (node))
3062 /* Uniquize all constants that appear in memory.
3063 Each constant in memory thus far output is recorded
3064 in `const_desc_table'. */
3066 struct GTY((for_user)) constant_descriptor_tree {
3067 /* A MEM for the constant. */
3068 rtx rtl;
3070 /* The value of the constant. */
3071 tree value;
3073 /* Hash of value. Computing the hash from value each time
3074 hashfn is called can't work properly, as that means recursive
3075 use of the hash table during hash table expansion. */
3076 hashval_t hash;
3079 /* Return true when function is only called directly or it has alias.
3080 i.e. it is not externally visible, address was not taken and
3081 it is not used in any other non-standard way. */
3083 inline bool
3084 cgraph_node::only_called_directly_or_aliased_p (void)
3086 gcc_assert (!inlined_to);
3087 return (!force_output && !address_taken
3088 && !ifunc_resolver
3089 && !used_from_other_partition
3090 && !DECL_VIRTUAL_P (decl)
3091 && !DECL_STATIC_CONSTRUCTOR (decl)
3092 && !DECL_STATIC_DESTRUCTOR (decl)
3093 && !used_from_object_file_p ()
3094 && !externally_visible);
3097 /* Return true when function can be removed from callgraph
3098 if all direct calls are eliminated. */
3100 inline bool
3101 cgraph_node::can_remove_if_no_direct_calls_and_refs_p (void)
3103 gcc_checking_assert (!inlined_to);
3104 /* Extern inlines can always go, we will use the external definition. */
3105 if (DECL_EXTERNAL (decl))
3106 return true;
3107 /* When function is needed, we cannot remove it. */
3108 if (force_output || used_from_other_partition)
3109 return false;
3110 if (DECL_STATIC_CONSTRUCTOR (decl)
3111 || DECL_STATIC_DESTRUCTOR (decl))
3112 return false;
3113 /* Only COMDAT functions can be removed if externally visible. */
3114 if (externally_visible
3115 && ((!DECL_COMDAT (decl) || ifunc_resolver)
3116 || forced_by_abi
3117 || used_from_object_file_p ()))
3118 return false;
3119 return true;
3122 /* Verify cgraph, if consistency checking is enabled. */
3124 inline void
3125 cgraph_node::checking_verify_cgraph_nodes (void)
3127 if (flag_checking)
3128 cgraph_node::verify_cgraph_nodes ();
3131 /* Return true when variable can be removed from variable pool
3132 if all direct calls are eliminated. */
3134 inline bool
3135 varpool_node::can_remove_if_no_refs_p (void)
3137 if (DECL_EXTERNAL (decl))
3138 return true;
3139 return (!force_output && !used_from_other_partition
3140 && ((DECL_COMDAT (decl)
3141 && !forced_by_abi
3142 && !used_from_object_file_p ())
3143 || !externally_visible
3144 || DECL_HAS_VALUE_EXPR_P (decl)));
3147 /* Return true when all references to variable must be visible in ipa_ref_list.
3148 i.e. if the variable is not externally visible or not used in some magic
3149 way (asm statement or such).
3150 The magic uses are all summarized in force_output flag. */
3152 inline bool
3153 varpool_node::all_refs_explicit_p ()
3155 return (definition
3156 && !externally_visible
3157 && !used_from_other_partition
3158 && !force_output);
3161 struct tree_descriptor_hasher : ggc_ptr_hash<constant_descriptor_tree>
3163 static hashval_t hash (constant_descriptor_tree *);
3164 static bool equal (constant_descriptor_tree *, constant_descriptor_tree *);
3167 /* Constant pool accessor function. */
3168 hash_table<tree_descriptor_hasher> *constant_pool_htab (void);
3170 /* Return node that alias is aliasing. */
3172 inline cgraph_node *
3173 cgraph_node::get_alias_target (void)
3175 return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ());
3178 /* Return node that alias is aliasing. */
3180 inline varpool_node *
3181 varpool_node::get_alias_target (void)
3183 return dyn_cast <varpool_node *> (symtab_node::get_alias_target ());
3186 /* Walk the alias chain to return the symbol NODE is alias of.
3187 If NODE is not an alias, return NODE.
3188 When AVAILABILITY is non-NULL, get minimal availability in the chain.
3189 When REF is non-NULL, assume that reference happens in symbol REF
3190 when determining the availability. */
3192 inline symtab_node *
3193 symtab_node::ultimate_alias_target (enum availability *availability,
3194 symtab_node *ref)
3196 if (!alias)
3198 if (availability)
3199 *availability = get_availability (ref);
3200 return this;
3203 return ultimate_alias_target_1 (availability, ref);
3206 /* Given function symbol, walk the alias chain to return the function node
3207 is alias of. Do not walk through thunks.
3208 When AVAILABILITY is non-NULL, get minimal availability in the chain.
3209 When REF is non-NULL, assume that reference happens in symbol REF
3210 when determining the availability. */
3212 inline cgraph_node *
3213 cgraph_node::ultimate_alias_target (enum availability *availability,
3214 symtab_node *ref)
3216 cgraph_node *n = dyn_cast <cgraph_node *>
3217 (symtab_node::ultimate_alias_target (availability, ref));
3218 if (!n && availability)
3219 *availability = AVAIL_NOT_AVAILABLE;
3220 return n;
3223 /* For given variable pool node, walk the alias chain to return the function
3224 the variable is alias of. Do not walk through thunks.
3225 When AVAILABILITY is non-NULL, get minimal availability in the chain.
3226 When REF is non-NULL, assume that reference happens in symbol REF
3227 when determining the availability. */
3229 inline varpool_node *
3230 varpool_node::ultimate_alias_target (availability *availability,
3231 symtab_node *ref)
3233 varpool_node *n = dyn_cast <varpool_node *>
3234 (symtab_node::ultimate_alias_target (availability, ref));
3236 if (!n && availability)
3237 *availability = AVAIL_NOT_AVAILABLE;
3238 return n;
3241 /* Set callee N of call graph edge and add it to the corresponding set of
3242 callers. */
3244 inline void
3245 cgraph_edge::set_callee (cgraph_node *n)
3247 prev_caller = NULL;
3248 if (n->callers)
3249 n->callers->prev_caller = this;
3250 next_caller = n->callers;
3251 n->callers = this;
3252 callee = n;
3255 /* Return true when the edge represents a direct recursion. */
3257 inline bool
3258 cgraph_edge::recursive_p (void)
3260 cgraph_node *c = callee->ultimate_alias_target ();
3261 if (caller->inlined_to)
3262 return caller->inlined_to->decl == c->decl;
3263 else
3264 return caller->decl == c->decl;
3267 /* Remove the edge from the list of the callers of the callee. */
3269 inline void
3270 cgraph_edge::remove_callee (void)
3272 gcc_assert (!indirect_unknown_callee);
3273 if (prev_caller)
3274 prev_caller->next_caller = next_caller;
3275 if (next_caller)
3276 next_caller->prev_caller = prev_caller;
3277 if (!prev_caller)
3278 callee->callers = next_caller;
3281 /* Return true if call must bind to current definition. */
3283 inline bool
3284 cgraph_edge::binds_to_current_def_p ()
3286 if (callee)
3287 return callee->binds_to_current_def_p (caller);
3288 else
3289 return false;
3292 /* Expected frequency of executions within the function.
3293 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
3294 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
3296 inline int
3297 cgraph_edge::frequency ()
3299 return count.to_cgraph_frequency (caller->inlined_to
3300 ? caller->inlined_to->count
3301 : caller->count);
3305 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
3306 static inline bool
3307 decl_is_tm_clone (const_tree fndecl)
3309 cgraph_node *n = cgraph_node::get (fndecl);
3310 if (n)
3311 return n->tm_clone;
3312 return false;
3315 /* Likewise indicate that a node is needed, i.e. reachable via some
3316 external means. */
3318 inline void
3319 cgraph_node::mark_force_output (void)
3321 force_output = 1;
3322 gcc_checking_assert (!inlined_to);
3325 /* Return true if function should be optimized for size. */
3327 inline enum optimize_size_level
3328 cgraph_node::optimize_for_size_p (void)
3330 if (opt_for_fn (decl, optimize_size))
3331 return OPTIMIZE_SIZE_MAX;
3332 if (count == profile_count::zero ())
3333 return OPTIMIZE_SIZE_MAX;
3334 if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
3335 return OPTIMIZE_SIZE_BALANCED;
3336 else
3337 return OPTIMIZE_SIZE_NO;
3340 /* Return symtab_node for NODE or create one if it is not present
3341 in symtab. */
3343 inline symtab_node *
3344 symtab_node::get_create (tree node)
3346 if (TREE_CODE (node) == VAR_DECL)
3347 return varpool_node::get_create (node);
3348 else
3349 return cgraph_node::get_create (node);
3352 /* Return availability of NODE when referenced from REF. */
3354 inline enum availability
3355 symtab_node::get_availability (symtab_node *ref)
3357 if (is_a <cgraph_node *> (this))
3358 return dyn_cast <cgraph_node *> (this)->get_availability (ref);
3359 else
3360 return dyn_cast <varpool_node *> (this)->get_availability (ref);
3363 /* Call callback on symtab node and aliases associated to this node.
3364 When INCLUDE_OVERWRITABLE is false, overwritable symbols are skipped. */
3366 inline bool
3367 symtab_node::call_for_symbol_and_aliases (bool (*callback) (symtab_node *,
3368 void *),
3369 void *data,
3370 bool include_overwritable)
3372 if (include_overwritable
3373 || get_availability () > AVAIL_INTERPOSABLE)
3375 if (callback (this, data))
3376 return true;
3378 if (has_aliases_p ())
3379 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
3380 return false;
3383 /* Call callback on function and aliases associated to the function.
3384 When INCLUDE_OVERWRITABLE is false, overwritable symbols are
3385 skipped. */
3387 inline bool
3388 cgraph_node::call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
3389 void *),
3390 void *data,
3391 bool include_overwritable)
3393 if (include_overwritable
3394 || get_availability () > AVAIL_INTERPOSABLE)
3396 if (callback (this, data))
3397 return true;
3399 if (has_aliases_p ())
3400 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
3401 return false;
3404 /* Call callback on varpool symbol and aliases associated to varpool symbol.
3405 When INCLUDE_OVERWRITABLE is false, overwritable symbols are
3406 skipped. */
3408 inline bool
3409 varpool_node::call_for_symbol_and_aliases (bool (*callback) (varpool_node *,
3410 void *),
3411 void *data,
3412 bool include_overwritable)
3414 if (include_overwritable
3415 || get_availability () > AVAIL_INTERPOSABLE)
3417 if (callback (this, data))
3418 return true;
3420 if (has_aliases_p ())
3421 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
3422 return false;
3425 /* Return true if reference may be used in address compare. */
3427 inline bool
3428 ipa_ref::address_matters_p ()
3430 if (use != IPA_REF_ADDR)
3431 return false;
3432 /* Addresses taken from virtual tables are never compared. */
3433 if (is_a <varpool_node *> (referring)
3434 && DECL_VIRTUAL_P (referring->decl))
3435 return false;
3436 return referred->address_can_be_compared_p ();
3439 /* Build polymorphic call context for indirect call E. */
3441 inline
3442 ipa_polymorphic_call_context::ipa_polymorphic_call_context (cgraph_edge *e)
3444 gcc_checking_assert (e->indirect_info->polymorphic);
3445 *this = e->indirect_info->context;
3448 /* Build empty "I know nothing" context. */
3450 inline
3451 ipa_polymorphic_call_context::ipa_polymorphic_call_context ()
3453 clear_speculation ();
3454 clear_outer_type ();
3455 invalid = false;
3458 /* Make context non-speculative. */
3460 inline void
3461 ipa_polymorphic_call_context::clear_speculation ()
3463 speculative_outer_type = NULL;
3464 speculative_offset = 0;
3465 speculative_maybe_derived_type = false;
3468 /* Produce context specifying all derived types of OTR_TYPE. If OTR_TYPE is
3469 NULL, the context is set to dummy "I know nothing" setting. */
3471 inline void
3472 ipa_polymorphic_call_context::clear_outer_type (tree otr_type)
3474 outer_type = otr_type ? TYPE_MAIN_VARIANT (otr_type) : NULL;
3475 offset = 0;
3476 maybe_derived_type = true;
3477 maybe_in_construction = true;
3478 dynamic = true;
3481 /* Adjust all offsets in contexts by OFF bits. */
3483 inline void
3484 ipa_polymorphic_call_context::offset_by (HOST_WIDE_INT off)
3486 if (outer_type)
3487 offset += off;
3488 if (speculative_outer_type)
3489 speculative_offset += off;
3492 /* Return TRUE if context is fully useless. */
3494 inline bool
3495 ipa_polymorphic_call_context::useless_p () const
3497 return (!outer_type && !speculative_outer_type);
3500 /* When using fprintf (or similar), problems can arise with
3501 transient generated strings. Many string-generation APIs
3502 only support one result being alive at once (e.g. by
3503 returning a pointer to a statically-allocated buffer).
3505 If there is more than one generated string within one
3506 fprintf call: the first string gets evicted or overwritten
3507 by the second, before fprintf is fully evaluated.
3508 See e.g. PR/53136.
3510 This function provides a workaround for this, by providing
3511 a simple way to create copies of these transient strings,
3512 without the need to have explicit cleanup:
3514 fprintf (dumpfile, "string 1: %s string 2:%s\n",
3515 xstrdup_for_dump (EXPR_1),
3516 xstrdup_for_dump (EXPR_2));
3518 This is actually a simple wrapper around ggc_strdup, but
3519 the name documents the intent. We require that no GC can occur
3520 within the fprintf call. */
3522 static inline const char *
3523 xstrdup_for_dump (const char *transient_str)
3525 return ggc_strdup (transient_str);
3528 /* During LTO stream-in this predicate can be used to check whether node
3529 in question prevails in the linking to save some memory usage. */
3530 inline bool
3531 symtab_node::prevailing_p (void)
3533 return definition && ((!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
3534 || previous_sharing_asm_name == NULL);
3537 extern GTY(()) symbol_table *saved_symtab;
3539 #if CHECKING_P
3541 namespace selftest {
3543 /* An RAII-style class for use in selftests for temporarily using a different
3544 symbol_table, so that such tests can be isolated from each other. */
3546 class symbol_table_test
3548 public:
3549 /* Constructor. Override "symtab". */
3550 symbol_table_test ();
3552 /* Destructor. Restore the saved_symtab. */
3553 ~symbol_table_test ();
3556 } // namespace selftest
3558 #endif /* CHECKING_P */
3560 #endif /* GCC_CGRAPH_H */