* config/rs6000/rs6000.c (rs6000_output_symbol_ref): Move storage
[official-gcc.git] / gcc / cgraph.h
blobecafe63a5363e5b47ac4e670d73d77b2bfcb8b4b
1 /* Callgraph handling code.
2 Copyright (C) 2003-2016 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 "ipa-ref.h"
25 #include "plugin-api.h"
27 class ipa_opt_pass_d;
28 typedef ipa_opt_pass_d *ipa_opt_pass;
30 /* Symbol table consists of functions and variables.
31 TODO: add labels and CONST_DECLs. */
32 enum symtab_type
34 SYMTAB_SYMBOL,
35 SYMTAB_FUNCTION,
36 SYMTAB_VARIABLE
39 /* Section names are stored as reference counted strings in GGC safe hashtable
40 (to make them survive through PCH). */
42 struct GTY((for_user)) section_hash_entry
44 int ref_count;
45 char *name; /* As long as this datastructure stays in GGC, we can not put
46 string at the tail of structure of GGC dies in horrible
47 way */
50 struct section_name_hasher : ggc_ptr_hash<section_hash_entry>
52 typedef const char *compare_type;
54 static hashval_t hash (section_hash_entry *);
55 static bool equal (section_hash_entry *, const char *);
58 enum availability
60 /* Not yet set by cgraph_function_body_availability. */
61 AVAIL_UNSET,
62 /* Function body/variable initializer is unknown. */
63 AVAIL_NOT_AVAILABLE,
64 /* Function body/variable initializer is known but might be replaced
65 by a different one from other compilation unit and thus needs to
66 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
67 arbitrary side effects on escaping variables and functions, while
68 like AVAILABLE it might access static variables. */
69 AVAIL_INTERPOSABLE,
70 /* Function body/variable initializer is known and will be used in final
71 program. */
72 AVAIL_AVAILABLE,
73 /* Function body/variable initializer is known and all it's uses are
74 explicitly visible within current unit (ie it's address is never taken and
75 it is not exported to other units). Currently used only for functions. */
76 AVAIL_LOCAL
79 /* Classification of symbols WRT partitioning. */
80 enum symbol_partitioning_class
82 /* External declarations are ignored by partitioning algorithms and they are
83 added into the boundary later via compute_ltrans_boundary. */
84 SYMBOL_EXTERNAL,
85 /* Partitioned symbols are pur into one of partitions. */
86 SYMBOL_PARTITION,
87 /* Duplicated symbols (such as comdat or constant pool references) are
88 copied into every node needing them via add_symbol_to_partition. */
89 SYMBOL_DUPLICATE
92 /* Base of all entries in the symbol table.
93 The symtab_node is inherited by cgraph and varpol nodes. */
94 class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
95 chain_next ("%h.next"), chain_prev ("%h.previous")))
96 symtab_node
98 public:
99 /* Return name. */
100 const char *name () const;
102 /* Return asm name. */
103 const char * asm_name () const;
105 /* Add node into symbol table. This function is not used directly, but via
106 cgraph/varpool node creation routines. */
107 void register_symbol (void);
109 /* Remove symbol from symbol table. */
110 void remove (void);
112 /* Dump symtab node to F. */
113 void dump (FILE *f);
115 /* Dump symtab node to stderr. */
116 void DEBUG_FUNCTION debug (void);
118 /* Verify consistency of node. */
119 void DEBUG_FUNCTION verify (void);
121 /* Return ipa reference from this symtab_node to
122 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
123 of the use and STMT the statement (if it exists). */
124 ipa_ref *create_reference (symtab_node *referred_node,
125 enum ipa_ref_use use_type);
127 /* Return ipa reference from this symtab_node to
128 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
129 of the use and STMT the statement (if it exists). */
130 ipa_ref *create_reference (symtab_node *referred_node,
131 enum ipa_ref_use use_type, gimple *stmt);
133 /* If VAL is a reference to a function or a variable, add a reference from
134 this symtab_node to the corresponding symbol table node. USE_TYPE specify
135 type of the use and STMT the statement (if it exists). Return the new
136 reference or NULL if none was created. */
137 ipa_ref *maybe_create_reference (tree val, enum ipa_ref_use use_type,
138 gimple *stmt);
140 /* Clone all references from symtab NODE to this symtab_node. */
141 void clone_references (symtab_node *node);
143 /* Remove all stmt references in non-speculative references.
144 Those are not maintained during inlining & clonning.
145 The exception are speculative references that are updated along
146 with callgraph edges associated with them. */
147 void clone_referring (symtab_node *node);
149 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
150 ipa_ref *clone_reference (ipa_ref *ref, gimple *stmt);
152 /* Find the structure describing a reference to REFERRED_NODE
153 and associated with statement STMT. */
154 ipa_ref *find_reference (symtab_node *referred_node, gimple *stmt,
155 unsigned int lto_stmt_uid);
157 /* Remove all references that are associated with statement STMT. */
158 void remove_stmt_references (gimple *stmt);
160 /* Remove all stmt references in non-speculative references.
161 Those are not maintained during inlining & clonning.
162 The exception are speculative references that are updated along
163 with callgraph edges associated with them. */
164 void clear_stmts_in_references (void);
166 /* Remove all references in ref list. */
167 void remove_all_references (void);
169 /* Remove all referring items in ref list. */
170 void remove_all_referring (void);
172 /* Dump references in ref list to FILE. */
173 void dump_references (FILE *file);
175 /* Dump referring in list to FILE. */
176 void dump_referring (FILE *);
178 /* Get number of references for this node. */
179 inline unsigned num_references (void)
181 return ref_list.references ? ref_list.references->length () : 0;
184 /* Iterates I-th reference in the list, REF is also set. */
185 ipa_ref *iterate_reference (unsigned i, ipa_ref *&ref);
187 /* Iterates I-th referring item in the list, REF is also set. */
188 ipa_ref *iterate_referring (unsigned i, ipa_ref *&ref);
190 /* Iterates I-th referring alias item in the list, REF is also set. */
191 ipa_ref *iterate_direct_aliases (unsigned i, ipa_ref *&ref);
193 /* Return true if symtab node and TARGET represents
194 semantically equivalent symbols. */
195 bool semantically_equivalent_p (symtab_node *target);
197 /* Classify symbol symtab node for partitioning. */
198 enum symbol_partitioning_class get_partitioning_class (void);
200 /* Return comdat group. */
201 tree get_comdat_group ()
203 return x_comdat_group;
206 /* Return comdat group as identifier_node. */
207 tree get_comdat_group_id ()
209 if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE)
210 x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group);
211 return x_comdat_group;
214 /* Set comdat group. */
215 void set_comdat_group (tree group)
217 gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE
218 || DECL_P (group));
219 x_comdat_group = group;
222 /* Return section as string. */
223 const char * get_section ()
225 if (!x_section)
226 return NULL;
227 return x_section->name;
230 /* Remove node from same comdat group. */
231 void remove_from_same_comdat_group (void);
233 /* Add this symtab_node to the same comdat group that OLD is in. */
234 void add_to_same_comdat_group (symtab_node *old_node);
236 /* Dissolve the same_comdat_group list in which NODE resides. */
237 void dissolve_same_comdat_group_list (void);
239 /* Return true when symtab_node is known to be used from other (non-LTO)
240 object file. Known only when doing LTO via linker plugin. */
241 bool used_from_object_file_p (void);
243 /* Walk the alias chain to return the symbol NODE is alias of.
244 If NODE is not an alias, return NODE.
245 When AVAILABILITY is non-NULL, get minimal availability in the chain.
246 When REF is non-NULL, assume that reference happens in symbol REF
247 when determining the availability. */
248 symtab_node *ultimate_alias_target (enum availability *avail = NULL,
249 struct symtab_node *ref = NULL);
251 /* Return next reachable static symbol with initializer after NODE. */
252 inline symtab_node *next_defined_symbol (void);
254 /* Add reference recording that symtab node is alias of TARGET.
255 If TRANSPARENT is true make the alias to be transparent alias.
256 The function can fail in the case of aliasing cycles; in this case
257 it returns false. */
258 bool resolve_alias (symtab_node *target, bool transparent = false);
260 /* C++ FE sometimes change linkage flags after producing same
261 body aliases. */
262 void fixup_same_cpp_alias_visibility (symtab_node *target);
264 /* Call callback on symtab node and aliases associated to this node.
265 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
266 skipped. */
267 bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *),
268 void *data,
269 bool include_overwrite);
271 /* If node can not be interposable by static or dynamic linker to point to
272 different definition, return this symbol. Otherwise look for alias with
273 such property and if none exists, introduce new one. */
274 symtab_node *noninterposable_alias (void);
276 /* Return node that alias is aliasing. */
277 inline symtab_node *get_alias_target (void);
279 /* Set section for symbol and its aliases. */
280 void set_section (const char *section);
282 /* Set section, do not recurse into aliases.
283 When one wants to change section of symbol and its aliases,
284 use set_section. */
285 void set_section_for_node (const char *section);
287 /* Set initialization priority to PRIORITY. */
288 void set_init_priority (priority_type priority);
290 /* Return the initialization priority. */
291 priority_type get_init_priority ();
293 /* Return availability of NODE when referenced from REF. */
294 enum availability get_availability (symtab_node *ref = NULL);
296 /* Return true if NODE binds to current definition in final executable
297 when referenced from REF. If REF is NULL return conservative value
298 for any reference. */
299 bool binds_to_current_def_p (symtab_node *ref = NULL);
301 /* Make DECL local. */
302 void make_decl_local (void);
304 /* Copy visibility from N. */
305 void copy_visibility_from (symtab_node *n);
307 /* Return desired alignment of the definition. This is NOT alignment useful
308 to access THIS, because THIS may be interposable and DECL_ALIGN should
309 be used instead. It however must be guaranteed when output definition
310 of THIS. */
311 unsigned int definition_alignment ();
313 /* Return true if alignment can be increased. */
314 bool can_increase_alignment_p ();
316 /* Increase alignment of symbol to ALIGN. */
317 void increase_alignment (unsigned int align);
319 /* Return true if list contains an alias. */
320 bool has_aliases_p (void);
322 /* Return true when the symbol is real symbol, i.e. it is not inline clone
323 or abstract function kept for debug info purposes only. */
324 bool real_symbol_p (void);
326 /* Determine if symbol declaration is needed. That is, visible to something
327 either outside this translation unit, something magic in the system
328 configury. This function is used just during symbol creation. */
329 bool needed_p (void);
331 /* Return true when there are references to the node. */
332 bool referred_to_p (bool include_self = true);
334 /* Return true if symbol can be discarded by linker from the binary.
335 Assume that symbol is used (so there is no need to take into account
336 garbage collecting linkers)
338 This can happen for comdats, commons and weaks when they are previaled
339 by other definition at static linking time. */
340 inline bool
341 can_be_discarded_p (void)
343 return (DECL_EXTERNAL (decl)
344 || ((get_comdat_group ()
345 || DECL_COMMON (decl)
346 || (DECL_SECTION_NAME (decl) && DECL_WEAK (decl)))
347 && ((resolution != LDPR_PREVAILING_DEF
348 && resolution != LDPR_PREVAILING_DEF_IRONLY_EXP)
349 || flag_incremental_link)
350 && resolution != LDPR_PREVAILING_DEF_IRONLY));
353 /* Return true if NODE is local to a particular COMDAT group, and must not
354 be named from outside the COMDAT. This is used for C++ decloned
355 constructors. */
356 inline bool comdat_local_p (void)
358 return (same_comdat_group && !TREE_PUBLIC (decl));
361 /* Return true if ONE and TWO are part of the same COMDAT group. */
362 inline bool in_same_comdat_group_p (symtab_node *target);
364 /* Return true if symbol is known to be nonzero. */
365 bool nonzero_address ();
367 /* Return 0 if symbol is known to have different address than S2,
368 Return 1 if symbol is known to have same address as S2,
369 return 2 otherwise.
371 If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
372 and S2 is going to be accessed. This eliminates the situations when
373 either THIS or S2 is NULL and is seful for comparing bases when deciding
374 about memory aliasing. */
375 int equal_address_to (symtab_node *s2, bool memory_accessed = false);
377 /* Return true if symbol's address may possibly be compared to other
378 symbol's address. */
379 bool address_matters_p ();
381 /* Return true if NODE's address can be compared. This use properties
382 of NODE only and does not look if the address is actually taken in
383 interesting way. For that use ADDRESS_MATTERS_P instead. */
384 bool address_can_be_compared_p (void);
386 /* Return symbol table node associated with DECL, if any,
387 and NULL otherwise. */
388 static inline symtab_node *get (const_tree decl)
390 /* Check that we are called for sane type of object - functions
391 and static or external variables. */
392 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
393 || (TREE_CODE (decl) == VAR_DECL
394 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
395 || in_lto_p)));
396 /* Check that the mapping is sane - perhaps this check can go away,
397 but at the moment frontends tends to corrupt the mapping by calling
398 memcpy/memset on the tree nodes. */
399 gcc_checking_assert (!decl->decl_with_vis.symtab_node
400 || decl->decl_with_vis.symtab_node->decl == decl);
401 return decl->decl_with_vis.symtab_node;
404 /* Try to find a symtab node for declaration DECL and if it does not
405 exist or if it corresponds to an inline clone, create a new one. */
406 static inline symtab_node * get_create (tree node);
408 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
409 Return NULL if there's no such node. */
410 static symtab_node *get_for_asmname (const_tree asmname);
412 /* Dump symbol table to F. */
413 static void dump_table (FILE *);
415 /* Dump symbol table to stderr. */
416 static inline DEBUG_FUNCTION void debug_symtab (void)
418 dump_table (stderr);
421 /* Verify symbol table for internal consistency. */
422 static DEBUG_FUNCTION void verify_symtab_nodes (void);
424 /* Perform internal consistency checks, if they are enabled. */
425 static inline void checking_verify_symtab_nodes (void);
427 /* Type of the symbol. */
428 ENUM_BITFIELD (symtab_type) type : 8;
430 /* The symbols resolution. */
431 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
433 /*** Flags representing the symbol type. ***/
435 /* True when symbol corresponds to a definition in current unit.
436 set via finalize_function or finalize_decl */
437 unsigned definition : 1;
438 /* True when symbol is an alias.
439 Set by ssemble_alias. */
440 unsigned alias : 1;
441 /* When true the alias is translated into its target symbol either by GCC
442 or assembler (it also may just be a duplicate declaration of the same
443 linker name).
445 Currently transparent aliases come in three different flavors
446 - aliases having the same assembler name as their target (aka duplicated
447 declarations). In this case the assembler names compare via
448 assembler_names_equal_p and weakref is false
449 - aliases that are renamed at a time being output to final file
450 by varasm.c. For those DECL_ASSEMBLER_NAME have
451 IDENTIFIER_TRANSPARENT_ALIAS set and thus also their assembler
452 name must be unique.
453 Weakrefs belong to this cateogry when we target assembler without
454 .weakref directive.
455 - weakrefs that are renamed by assembler via .weakref directive.
456 In this case the alias may or may not be definition (depending if
457 target declaration was seen by the compiler), weakref is set.
458 Unless we are before renaming statics, assembler names are different.
460 Given that we now support duplicate declarations, the second option is
461 redundant and will be removed. */
462 unsigned transparent_alias : 1;
463 /* True when alias is a weakref. */
464 unsigned weakref : 1;
465 /* C++ frontend produce same body aliases and extra name aliases for
466 virtual functions and vtables that are obviously equivalent.
467 Those aliases are bit special, especially because C++ frontend
468 visibility code is so ugly it can not get them right at first time
469 and their visibility needs to be copied from their "masters" at
470 the end of parsing. */
471 unsigned cpp_implicit_alias : 1;
472 /* Set once the definition was analyzed. The list of references and
473 other properties are built during analysis. */
474 unsigned analyzed : 1;
475 /* Set for write-only variables. */
476 unsigned writeonly : 1;
477 /* Visibility of symbol was used for further optimization; do not
478 permit further changes. */
479 unsigned refuse_visibility_changes : 1;
481 /*** Visibility and linkage flags. ***/
483 /* Set when function is visible by other units. */
484 unsigned externally_visible : 1;
485 /* Don't reorder to other symbols having this set. */
486 unsigned no_reorder : 1;
487 /* The symbol will be assumed to be used in an invisible way (like
488 by an toplevel asm statement). */
489 unsigned force_output : 1;
490 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
491 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
492 to static and it does not inhibit optimization. */
493 unsigned forced_by_abi : 1;
494 /* True when the name is known to be unique and thus it does not need mangling. */
495 unsigned unique_name : 1;
496 /* Specify whether the section was set by user or by
497 compiler via -ffunction-sections. */
498 unsigned implicit_section : 1;
499 /* True when body and other characteristics have been removed by
500 symtab_remove_unreachable_nodes. */
501 unsigned body_removed : 1;
503 /*** WHOPR Partitioning flags.
504 These flags are used at ltrans stage when only part of the callgraph is
505 available. ***/
507 /* Set when variable is used from other LTRANS partition. */
508 unsigned used_from_other_partition : 1;
509 /* Set when function is available in the other LTRANS partition.
510 During WPA output it is used to mark nodes that are present in
511 multiple partitions. */
512 unsigned in_other_partition : 1;
516 /*** other flags. ***/
518 /* Set when symbol has address taken. */
519 unsigned address_taken : 1;
520 /* Set when init priority is set. */
521 unsigned in_init_priority_hash : 1;
523 /* Set when symbol needs to be streamed into LTO bytecode for LTO, or in case
524 of offloading, for separate compilation for a different target. */
525 unsigned need_lto_streaming : 1;
527 /* Set when symbol can be streamed into bytecode for offloading. */
528 unsigned offloadable : 1;
531 /* Ordering of all symtab entries. */
532 int order;
534 /* Declaration representing the symbol. */
535 tree decl;
537 /* Linked list of symbol table entries starting with symtab_nodes. */
538 symtab_node *next;
539 symtab_node *previous;
541 /* Linked list of symbols with the same asm name. There may be multiple
542 entries for single symbol name during LTO, because symbols are renamed
543 only after partitioning.
545 Because inline clones are kept in the assembler name has, they also produce
546 duplicate entries.
548 There are also several long standing bugs where frontends and builtin
549 code produce duplicated decls. */
550 symtab_node *next_sharing_asm_name;
551 symtab_node *previous_sharing_asm_name;
553 /* Circular list of nodes in the same comdat group if non-NULL. */
554 symtab_node *same_comdat_group;
556 /* Vectors of referring and referenced entities. */
557 ipa_ref_list ref_list;
559 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
560 depending to what was known to frontend on the creation time.
561 Once alias is resolved, this pointer become NULL. */
562 tree alias_target;
564 /* File stream where this node is being written to. */
565 struct lto_file_decl_data * lto_file_data;
567 PTR GTY ((skip)) aux;
569 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
570 tree x_comdat_group;
572 /* Section name. Again can be private, if allowed. */
573 section_hash_entry *x_section;
575 protected:
576 /* Dump base fields of symtab nodes to F. Not to be used directly. */
577 void dump_base (FILE *);
579 /* Verify common part of symtab node. */
580 bool DEBUG_FUNCTION verify_base (void);
582 /* Remove node from symbol table. This function is not used directly, but via
583 cgraph/varpool node removal routines. */
584 void unregister (void);
586 /* Return the initialization and finalization priority information for
587 DECL. If there is no previous priority information, a freshly
588 allocated structure is returned. */
589 struct symbol_priority_map *priority_info (void);
591 /* Worker for call_for_symbol_and_aliases_1. */
592 bool call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *, void *),
593 void *data,
594 bool include_overwrite);
595 private:
596 /* Worker for set_section. */
597 static bool set_section (symtab_node *n, void *s);
599 /* Worker for symtab_resolve_alias. */
600 static bool set_implicit_section (symtab_node *n, void *);
602 /* Worker searching noninterposable alias. */
603 static bool noninterposable_alias (symtab_node *node, void *data);
605 /* Worker for ultimate_alias_target. */
606 symtab_node *ultimate_alias_target_1 (enum availability *avail = NULL,
607 symtab_node *ref = NULL);
610 inline void
611 symtab_node::checking_verify_symtab_nodes (void)
613 if (flag_checking)
614 symtab_node::verify_symtab_nodes ();
617 /* Walk all aliases for NODE. */
618 #define FOR_EACH_ALIAS(node, alias) \
619 for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++)
621 /* This is the information that is put into the cgraph local structure
622 to recover a function. */
623 struct lto_file_decl_data;
625 extern const char * const cgraph_availability_names[];
626 extern const char * const ld_plugin_symbol_resolution_names[];
627 extern const char * const tls_model_names[];
629 /* Information about thunk, used only for same body aliases. */
631 struct GTY(()) cgraph_thunk_info {
632 /* Information about the thunk. */
633 HOST_WIDE_INT fixed_offset;
634 HOST_WIDE_INT virtual_value;
635 tree alias;
636 bool this_adjusting;
637 bool virtual_offset_p;
638 bool add_pointer_bounds_args;
639 /* Set to true when alias node is thunk. */
640 bool thunk_p;
643 /* Information about the function collected locally.
644 Available after function is analyzed. */
646 struct GTY(()) cgraph_local_info {
647 /* Set when function is visible in current compilation unit only and
648 its address is never taken. */
649 unsigned local : 1;
651 /* False when there is something makes versioning impossible. */
652 unsigned versionable : 1;
654 /* False when function calling convention and signature can not be changed.
655 This is the case when __builtin_apply_args is used. */
656 unsigned can_change_signature : 1;
658 /* True when the function has been originally extern inline, but it is
659 redefined now. */
660 unsigned redefined_extern_inline : 1;
662 /* True if the function may enter serial irrevocable mode. */
663 unsigned tm_may_enter_irr : 1;
666 /* Information about the function that needs to be computed globally
667 once compilation is finished. Available only with -funit-at-a-time. */
669 struct GTY(()) cgraph_global_info {
670 /* For inline clones this points to the function they will be
671 inlined into. */
672 cgraph_node *inlined_to;
675 /* Represent which DECL tree (or reference to such tree)
676 will be replaced by another tree while versioning. */
677 struct GTY(()) ipa_replace_map
679 /* The tree that will be replaced. */
680 tree old_tree;
681 /* The new (replacing) tree. */
682 tree new_tree;
683 /* Parameter number to replace, when old_tree is NULL. */
684 int parm_num;
685 /* True when a substitution should be done, false otherwise. */
686 bool replace_p;
687 /* True when we replace a reference to old_tree. */
688 bool ref_p;
691 struct GTY(()) cgraph_clone_info
693 vec<ipa_replace_map *, va_gc> *tree_map;
694 bitmap args_to_skip;
695 bitmap combined_args_to_skip;
698 enum cgraph_simd_clone_arg_type
700 SIMD_CLONE_ARG_TYPE_VECTOR,
701 SIMD_CLONE_ARG_TYPE_UNIFORM,
702 /* These are only for integer/pointer arguments passed by value. */
703 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
704 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
705 /* These 6 are only for reference type arguments or arguments passed
706 by reference. */
707 SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP,
708 SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP,
709 SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP,
710 SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP,
711 SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP,
712 SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP,
713 SIMD_CLONE_ARG_TYPE_MASK
716 /* Function arguments in the original function of a SIMD clone.
717 Supplementary data for `struct simd_clone'. */
719 struct GTY(()) cgraph_simd_clone_arg {
720 /* Original function argument as it originally existed in
721 DECL_ARGUMENTS. */
722 tree orig_arg;
724 /* orig_arg's function (or for extern functions type from
725 TYPE_ARG_TYPES). */
726 tree orig_type;
728 /* If argument is a vector, this holds the vector version of
729 orig_arg that after adjusting the argument types will live in
730 DECL_ARGUMENTS. Otherwise, this is NULL.
732 This basically holds:
733 vector(simdlen) __typeof__(orig_arg) new_arg. */
734 tree vector_arg;
736 /* vector_arg's type (or for extern functions new vector type. */
737 tree vector_type;
739 /* If argument is a vector, this holds the array where the simd
740 argument is held while executing the simd clone function. This
741 is a local variable in the cloned function. Its content is
742 copied from vector_arg upon entry to the clone.
744 This basically holds:
745 __typeof__(orig_arg) simd_array[simdlen]. */
746 tree simd_array;
748 /* A SIMD clone's argument can be either linear (constant or
749 variable), uniform, or vector. */
750 enum cgraph_simd_clone_arg_type arg_type;
752 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_*CONSTANT_STEP this is
753 the constant linear step, if arg_type is
754 SIMD_CLONE_ARG_TYPE_LINEAR_*VARIABLE_STEP, this is index of
755 the uniform argument holding the step, otherwise 0. */
756 HOST_WIDE_INT linear_step;
758 /* Variable alignment if available, otherwise 0. */
759 unsigned int alignment;
762 /* Specific data for a SIMD function clone. */
764 struct GTY(()) cgraph_simd_clone {
765 /* Number of words in the SIMD lane associated with this clone. */
766 unsigned int simdlen;
768 /* Number of annotated function arguments in `args'. This is
769 usually the number of named arguments in FNDECL. */
770 unsigned int nargs;
772 /* Max hardware vector size in bits for integral vectors. */
773 unsigned int vecsize_int;
775 /* Max hardware vector size in bits for floating point vectors. */
776 unsigned int vecsize_float;
778 /* Machine mode of the mask argument(s), if they are to be passed
779 as bitmasks in integer argument(s). VOIDmode if masks are passed
780 as vectors of characteristic type. */
781 machine_mode mask_mode;
783 /* The mangling character for a given vector size. This is used
784 to determine the ISA mangling bit as specified in the Intel
785 Vector ABI. */
786 unsigned char vecsize_mangle;
788 /* True if this is the masked, in-branch version of the clone,
789 otherwise false. */
790 unsigned int inbranch : 1;
792 /* True if this is a Cilk Plus variant. */
793 unsigned int cilk_elemental : 1;
795 /* Doubly linked list of SIMD clones. */
796 cgraph_node *prev_clone, *next_clone;
798 /* Original cgraph node the SIMD clones were created for. */
799 cgraph_node *origin;
801 /* Annotated function arguments for the original function. */
802 cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
805 /* Function Multiversioning info. */
806 struct GTY((for_user)) cgraph_function_version_info {
807 /* The cgraph_node for which the function version info is stored. */
808 cgraph_node *this_node;
809 /* Chains all the semantically identical function versions. The
810 first function in this chain is the version_info node of the
811 default function. */
812 cgraph_function_version_info *prev;
813 /* If this version node corresponds to a dispatcher for function
814 versions, this points to the version info node of the default
815 function, the first node in the chain. */
816 cgraph_function_version_info *next;
817 /* If this node corresponds to a function version, this points
818 to the dispatcher function decl, which is the function that must
819 be called to execute the right function version at run-time.
821 If this cgraph node is a dispatcher (if dispatcher_function is
822 true, in the cgraph_node struct) for function versions, this
823 points to resolver function, which holds the function body of the
824 dispatcher. The dispatcher decl is an alias to the resolver
825 function decl. */
826 tree dispatcher_resolver;
829 #define DEFCIFCODE(code, type, string) CIF_ ## code,
830 /* Reasons for inlining failures. */
832 enum cgraph_inline_failed_t {
833 #include "cif-code.def"
834 CIF_N_REASONS
837 enum cgraph_inline_failed_type_t
839 CIF_FINAL_NORMAL = 0,
840 CIF_FINAL_ERROR
843 struct cgraph_edge;
845 struct cgraph_edge_hasher : ggc_ptr_hash<cgraph_edge>
847 typedef gimple *compare_type;
849 static hashval_t hash (cgraph_edge *);
850 static hashval_t hash (gimple *);
851 static bool equal (cgraph_edge *, gimple *);
854 /* The cgraph data structure.
855 Each function decl has assigned cgraph_node listing callees and callers. */
857 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
858 public:
859 /* Remove the node from cgraph and all inline clones inlined into it.
860 Skip however removal of FORBIDDEN_NODE and return true if it needs to be
861 removed. This allows to call the function from outer loop walking clone
862 tree. */
863 bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL);
865 /* Record all references from cgraph_node that are taken
866 in statement STMT. */
867 void record_stmt_references (gimple *stmt);
869 /* Like cgraph_set_call_stmt but walk the clone tree and update all
870 clones sharing the same function body.
871 When WHOLE_SPECULATIVE_EDGES is true, all three components of
872 speculative edge gets updated. Otherwise we update only direct
873 call. */
874 void set_call_stmt_including_clones (gimple *old_stmt, gcall *new_stmt,
875 bool update_speculative = true);
877 /* Walk the alias chain to return the function cgraph_node is alias of.
878 Walk through thunk, too.
879 When AVAILABILITY is non-NULL, get minimal availability in the chain.
880 When REF is non-NULL, assume that reference happens in symbol REF
881 when determining the availability. */
882 cgraph_node *function_symbol (enum availability *avail = NULL,
883 struct symtab_node *ref = NULL);
885 /* Walk the alias chain to return the function cgraph_node is alias of.
886 Walk through non virtual thunks, too. Thus we return either a function
887 or a virtual thunk node.
888 When AVAILABILITY is non-NULL, get minimal availability in the chain.
889 When REF is non-NULL, assume that reference happens in symbol REF
890 when determining the availability. */
891 cgraph_node *function_or_virtual_thunk_symbol
892 (enum availability *avail = NULL,
893 struct symtab_node *ref = NULL);
895 /* Create node representing clone of N executed COUNT times. Decrease
896 the execution counts from original node too.
897 The new clone will have decl set to DECL that may or may not be the same
898 as decl of N.
900 When UPDATE_ORIGINAL is true, the counts are subtracted from the original
901 function's profile to reflect the fact that part of execution is handled
902 by node.
903 When CALL_DUPLICATOIN_HOOK is true, the ipa passes are acknowledged about
904 the new clone. Otherwise the caller is responsible for doing so later.
906 If the new node is being inlined into another one, NEW_INLINED_TO should be
907 the outline function the new one is (even indirectly) inlined to.
908 All hooks will see this in node's global.inlined_to, when invoked.
909 Can be NULL if the node is not inlined. */
910 cgraph_node *create_clone (tree decl, gcov_type count, int freq,
911 bool update_original,
912 vec<cgraph_edge *> redirect_callers,
913 bool call_duplication_hook,
914 cgraph_node *new_inlined_to,
915 bitmap args_to_skip);
917 /* Create callgraph node clone with new declaration. The actual body will
918 be copied later at compilation stage. */
919 cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers,
920 vec<ipa_replace_map *, va_gc> *tree_map,
921 bitmap args_to_skip, const char * suffix);
923 /* cgraph node being removed from symbol table; see if its entry can be
924 replaced by other inline clone. */
925 cgraph_node *find_replacement (void);
927 /* Create a new cgraph node which is the new version of
928 callgraph node. REDIRECT_CALLERS holds the callers
929 edges which should be redirected to point to
930 NEW_VERSION. ALL the callees edges of the node
931 are cloned to the new version node. Return the new
932 version node.
934 If non-NULL BLOCK_TO_COPY determine what basic blocks
935 was copied to prevent duplications of calls that are dead
936 in the clone. */
938 cgraph_node *create_version_clone (tree new_decl,
939 vec<cgraph_edge *> redirect_callers,
940 bitmap bbs_to_copy);
942 /* Perform function versioning.
943 Function versioning includes copying of the tree and
944 a callgraph update (creating a new cgraph node and updating
945 its callees and callers).
947 REDIRECT_CALLERS varray includes the edges to be redirected
948 to the new version.
950 TREE_MAP is a mapping of tree nodes we want to replace with
951 new ones (according to results of prior analysis).
953 If non-NULL ARGS_TO_SKIP determine function parameters to remove
954 from new version.
955 If SKIP_RETURN is true, the new version will return void.
956 If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
957 If non_NULL NEW_ENTRY determine new entry BB of the clone.
959 Return the new version's cgraph node. */
960 cgraph_node *create_version_clone_with_body
961 (vec<cgraph_edge *> redirect_callers,
962 vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip,
963 bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block,
964 const char *clone_name);
966 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
967 corresponding to cgraph_node. */
968 cgraph_function_version_info *insert_new_function_version (void);
970 /* Get the cgraph_function_version_info node corresponding to node. */
971 cgraph_function_version_info *function_version (void);
973 /* Discover all functions and variables that are trivially needed, analyze
974 them as well as all functions and variables referred by them */
975 void analyze (void);
977 /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
978 aliases DECL with an adjustments made into the first parameter.
979 See comments in thunk_adjust for detail on the parameters. */
980 cgraph_node * create_thunk (tree alias, tree, bool this_adjusting,
981 HOST_WIDE_INT fixed_offset,
982 HOST_WIDE_INT virtual_value,
983 tree virtual_offset,
984 tree real_alias);
987 /* Return node that alias is aliasing. */
988 inline cgraph_node *get_alias_target (void);
990 /* Given function symbol, walk the alias chain to return the function node
991 is alias of. Do not walk through thunks.
992 When AVAILABILITY is non-NULL, get minimal availability in the chain.
993 When REF is non-NULL, assume that reference happens in symbol REF
994 when determining the availability. */
996 cgraph_node *ultimate_alias_target (availability *availability = NULL,
997 symtab_node *ref = NULL);
999 /* Expand thunk NODE to gimple if possible.
1000 When FORCE_GIMPLE_THUNK is true, gimple thunk is created and
1001 no assembler is produced.
1002 When OUTPUT_ASM_THUNK is true, also produce assembler for
1003 thunks that are not lowered. */
1004 bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk);
1006 /* Call expand_thunk on all callers that are thunks and analyze those
1007 nodes that were expanded. */
1008 void expand_all_artificial_thunks ();
1010 /* Assemble thunks and aliases associated to node. */
1011 void assemble_thunks_and_aliases (void);
1013 /* Expand function specified by node. */
1014 void expand (void);
1016 /* As an GCC extension we allow redefinition of the function. The
1017 semantics when both copies of bodies differ is not well defined.
1018 We replace the old body with new body so in unit at a time mode
1019 we always use new body, while in normal mode we may end up with
1020 old body inlined into some functions and new body expanded and
1021 inlined in others. */
1022 void reset (void);
1024 /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this
1025 kind of wrapper method. */
1026 void create_wrapper (cgraph_node *target);
1028 /* Verify cgraph nodes of the cgraph node. */
1029 void DEBUG_FUNCTION verify_node (void);
1031 /* Remove function from symbol table. */
1032 void remove (void);
1034 /* Dump call graph node to file F. */
1035 void dump (FILE *f);
1037 /* Dump call graph node to stderr. */
1038 void DEBUG_FUNCTION debug (void);
1040 /* When doing LTO, read cgraph_node's body from disk if it is not already
1041 present. */
1042 bool get_untransformed_body (void);
1044 /* Prepare function body. When doing LTO, read cgraph_node's body from disk
1045 if it is not already present. When some IPA transformations are scheduled,
1046 apply them. */
1047 bool get_body (void);
1049 /* Release memory used to represent body of function.
1050 Use this only for functions that are released before being translated to
1051 target code (i.e. RTL). Functions that are compiled to RTL and beyond
1052 are free'd in final.c via free_after_compilation(). */
1053 void release_body (bool keep_arguments = false);
1055 /* Return the DECL_STRUCT_FUNCTION of the function. */
1056 struct function *get_fun (void);
1058 /* cgraph_node is no longer nested function; update cgraph accordingly. */
1059 void unnest (void);
1061 /* Bring cgraph node local. */
1062 void make_local (void);
1064 /* Likewise indicate that a node is having address taken. */
1065 void mark_address_taken (void);
1067 /* Set fialization priority to PRIORITY. */
1068 void set_fini_priority (priority_type priority);
1070 /* Return the finalization priority. */
1071 priority_type get_fini_priority (void);
1073 /* Create edge from a given function to CALLEE in the cgraph. */
1074 cgraph_edge *create_edge (cgraph_node *callee,
1075 gcall *call_stmt, gcov_type count,
1076 int freq);
1078 /* Create an indirect edge with a yet-undetermined callee where the call
1079 statement destination is a formal parameter of the caller with index
1080 PARAM_INDEX. */
1081 cgraph_edge *create_indirect_edge (gcall *call_stmt, int ecf_flags,
1082 gcov_type count, int freq,
1083 bool compute_indirect_info = true);
1085 /* Like cgraph_create_edge walk the clone tree and update all clones sharing
1086 same function body. If clones already have edge for OLD_STMT; only
1087 update the edge same way as cgraph_set_call_stmt_including_clones does. */
1088 void create_edge_including_clones (cgraph_node *callee,
1089 gimple *old_stmt, gcall *stmt,
1090 gcov_type count,
1091 int freq,
1092 cgraph_inline_failed_t reason);
1094 /* Return the callgraph edge representing the GIMPLE_CALL statement
1095 CALL_STMT. */
1096 cgraph_edge *get_edge (gimple *call_stmt);
1098 /* Collect all callers of cgraph_node and its aliases that are known to lead
1099 to NODE (i.e. are not overwritable) and that are not thunks. */
1100 vec<cgraph_edge *> collect_callers (void);
1102 /* Remove all callers from the node. */
1103 void remove_callers (void);
1105 /* Remove all callees from the node. */
1106 void remove_callees (void);
1108 /* Return function availability. See cgraph.h for description of individual
1109 return values. */
1110 enum availability get_availability (symtab_node *ref = NULL);
1112 /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node
1113 if any to NOTHROW. */
1114 bool set_nothrow_flag (bool nothrow);
1116 /* If SET_CONST is true, mark function, aliases and thunks to be ECF_CONST.
1117 If SET_CONST if false, clear the flag.
1119 When setting the flag be careful about possible interposition and
1120 do not set the flag for functions that can be interposet and set pure
1121 flag for functions that can bind to other definition.
1123 Return true if any change was done. */
1125 bool set_const_flag (bool set_const, bool looping);
1127 /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
1128 if any to PURE.
1130 When setting the flag, be careful about possible interposition.
1131 Return true if any change was done. */
1133 bool set_pure_flag (bool pure, bool looping);
1135 /* Call callback on function and aliases associated to the function.
1136 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1137 skipped. */
1139 bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
1140 void *),
1141 void *data, bool include_overwritable);
1143 /* Call callback on cgraph_node, thunks and aliases associated to NODE.
1144 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1145 skipped. When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
1146 skipped. */
1147 bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node,
1148 void *data),
1149 void *data,
1150 bool include_overwritable,
1151 bool exclude_virtual_thunks = false);
1153 /* Likewise indicate that a node is needed, i.e. reachable via some
1154 external means. */
1155 inline void mark_force_output (void);
1157 /* Return true when function can be marked local. */
1158 bool local_p (void);
1160 /* Return true if cgraph_node can be made local for API change.
1161 Extern inline functions and C++ COMDAT functions can be made local
1162 at the expense of possible code size growth if function is used in multiple
1163 compilation units. */
1164 bool can_be_local_p (void);
1166 /* Return true when cgraph_node can not return or throw and thus
1167 it is safe to ignore its side effects for IPA analysis. */
1168 bool cannot_return_p (void);
1170 /* Return true when function cgraph_node and all its aliases are only called
1171 directly.
1172 i.e. it is not externally visible, address was not taken and
1173 it is not used in any other non-standard way. */
1174 bool only_called_directly_p (void);
1176 /* Return true when function is only called directly or it has alias.
1177 i.e. it is not externally visible, address was not taken and
1178 it is not used in any other non-standard way. */
1179 inline bool only_called_directly_or_aliased_p (void);
1181 /* Return true when function cgraph_node can be expected to be removed
1182 from program when direct calls in this compilation unit are removed.
1184 As a special case COMDAT functions are
1185 cgraph_can_remove_if_no_direct_calls_p while the are not
1186 cgraph_only_called_directly_p (it is possible they are called from other
1187 unit)
1189 This function behaves as cgraph_only_called_directly_p because eliminating
1190 all uses of COMDAT function does not make it necessarily disappear from
1191 the program unless we are compiling whole program or we do LTO. In this
1192 case we know we win since dynamic linking will not really discard the
1193 linkonce section.
1195 If WILL_INLINE is true, assume that function will be inlined into all the
1196 direct calls. */
1197 bool will_be_removed_from_program_if_no_direct_calls_p
1198 (bool will_inline = false);
1200 /* Return true when function can be removed from callgraph
1201 if all direct calls and references are eliminated. The function does
1202 not take into account comdat groups. */
1203 bool can_remove_if_no_direct_calls_and_refs_p (void);
1205 /* Return true when function cgraph_node and its aliases can be removed from
1206 callgraph if all direct calls are eliminated.
1207 If WILL_INLINE is true, assume that function will be inlined into all the
1208 direct calls. */
1209 bool can_remove_if_no_direct_calls_p (bool will_inline = false);
1211 /* Return true when callgraph node is a function with Gimple body defined
1212 in current unit. Functions can also be define externally or they
1213 can be thunks with no Gimple representation.
1215 Note that at WPA stage, the function body may not be present in memory. */
1216 inline bool has_gimple_body_p (void);
1218 /* Return true if function should be optimized for size. */
1219 bool optimize_for_size_p (void);
1221 /* Dump the callgraph to file F. */
1222 static void dump_cgraph (FILE *f);
1224 /* Dump the call graph to stderr. */
1225 static inline
1226 void debug_cgraph (void)
1228 dump_cgraph (stderr);
1231 /* Record that DECL1 and DECL2 are semantically identical function
1232 versions. */
1233 static void record_function_versions (tree decl1, tree decl2);
1235 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
1236 DECL is a duplicate declaration. */
1237 static void delete_function_version (tree decl);
1239 /* Add the function FNDECL to the call graph.
1240 Unlike finalize_function, this function is intended to be used
1241 by middle end and allows insertion of new function at arbitrary point
1242 of compilation. The function can be either in high, low or SSA form
1243 GIMPLE.
1245 The function is assumed to be reachable and have address taken (so no
1246 API breaking optimizations are performed on it).
1248 Main work done by this function is to enqueue the function for later
1249 processing to avoid need the passes to be re-entrant. */
1250 static void add_new_function (tree fndecl, bool lowered);
1252 /* Return callgraph node for given symbol and check it is a function. */
1253 static inline cgraph_node *get (const_tree decl)
1255 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1256 return dyn_cast <cgraph_node *> (symtab_node::get (decl));
1259 /* DECL has been parsed. Take it, queue it, compile it at the whim of the
1260 logic in effect. If NO_COLLECT is true, then our caller cannot stand to
1261 have the garbage collector run at the moment. We would need to either
1262 create a new GC context, or just not compile right now. */
1263 static void finalize_function (tree, bool);
1265 /* Return cgraph node assigned to DECL. Create new one when needed. */
1266 static cgraph_node * create (tree decl);
1268 /* Try to find a call graph node for declaration DECL and if it does not
1269 exist or if it corresponds to an inline clone, create a new one. */
1270 static cgraph_node * get_create (tree);
1272 /* Return local info for the compiled function. */
1273 static cgraph_local_info *local_info (tree decl);
1275 /* Return local info for the compiled function. */
1276 static struct cgraph_rtl_info *rtl_info (tree);
1278 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
1279 Return NULL if there's no such node. */
1280 static cgraph_node *get_for_asmname (tree asmname);
1282 /* Attempt to mark ALIAS as an alias to DECL. Return alias node if
1283 successful and NULL otherwise.
1284 Same body aliases are output whenever the body of DECL is output,
1285 and cgraph_node::get (ALIAS) transparently
1286 returns cgraph_node::get (DECL). */
1287 static cgraph_node * create_same_body_alias (tree alias, tree decl);
1289 /* Verify whole cgraph structure. */
1290 static void DEBUG_FUNCTION verify_cgraph_nodes (void);
1292 /* Verify cgraph, if consistency checking is enabled. */
1293 static inline void checking_verify_cgraph_nodes (void);
1295 /* Worker to bring NODE local. */
1296 static bool make_local (cgraph_node *node, void *);
1298 /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
1299 the function body is associated
1300 with (not necessarily cgraph_node (DECL). */
1301 static cgraph_node *create_alias (tree alias, tree target);
1303 /* Return true if NODE has thunk. */
1304 static bool has_thunk_p (cgraph_node *node, void *);
1306 cgraph_edge *callees;
1307 cgraph_edge *callers;
1308 /* List of edges representing indirect calls with a yet undetermined
1309 callee. */
1310 cgraph_edge *indirect_calls;
1311 /* For nested functions points to function the node is nested in. */
1312 cgraph_node *origin;
1313 /* Points to first nested function, if any. */
1314 cgraph_node *nested;
1315 /* Pointer to the next function with same origin, if any. */
1316 cgraph_node *next_nested;
1317 /* Pointer to the next clone. */
1318 cgraph_node *next_sibling_clone;
1319 cgraph_node *prev_sibling_clone;
1320 cgraph_node *clones;
1321 cgraph_node *clone_of;
1322 /* If instrumentation_clone is 1 then instrumented_version points
1323 to the original function used to make instrumented version.
1324 Otherwise points to instrumented version of the function. */
1325 cgraph_node *instrumented_version;
1326 /* If instrumentation_clone is 1 then orig_decl is the original
1327 function declaration. */
1328 tree orig_decl;
1329 /* For functions with many calls sites it holds map from call expression
1330 to the edge to speed up cgraph_edge function. */
1331 hash_table<cgraph_edge_hasher> *GTY(()) call_site_hash;
1332 /* Declaration node used to be clone of. */
1333 tree former_clone_of;
1335 /* If this is a SIMD clone, this points to the SIMD specific
1336 information for it. */
1337 cgraph_simd_clone *simdclone;
1338 /* If this function has SIMD clones, this points to the first clone. */
1339 cgraph_node *simd_clones;
1341 /* Interprocedural passes scheduled to have their transform functions
1342 applied next time we execute local pass on them. We maintain it
1343 per-function in order to allow IPA passes to introduce new functions. */
1344 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
1346 cgraph_local_info local;
1347 cgraph_global_info global;
1348 struct cgraph_rtl_info *rtl;
1349 cgraph_clone_info clone;
1350 cgraph_thunk_info thunk;
1352 /* Expected number of executions: calculated in profile.c. */
1353 gcov_type count;
1354 /* How to scale counts at materialization time; used to merge
1355 LTO units with different number of profile runs. */
1356 int count_materialization_scale;
1357 /* Unique id of the node. */
1358 int uid;
1359 /* Summary unique id of the node. */
1360 int summary_uid;
1361 /* ID assigned by the profiling. */
1362 unsigned int profile_id;
1363 /* Time profiler: first run of function. */
1364 int tp_first_run;
1366 /* Set when decl is an abstract function pointed to by the
1367 ABSTRACT_DECL_ORIGIN of a reachable function. */
1368 unsigned used_as_abstract_origin : 1;
1369 /* Set once the function is lowered (i.e. its CFG is built). */
1370 unsigned lowered : 1;
1371 /* Set once the function has been instantiated and its callee
1372 lists created. */
1373 unsigned process : 1;
1374 /* How commonly executed the node is. Initialized during branch
1375 probabilities pass. */
1376 ENUM_BITFIELD (node_frequency) frequency : 2;
1377 /* True when function can only be called at startup (from static ctor). */
1378 unsigned only_called_at_startup : 1;
1379 /* True when function can only be called at startup (from static dtor). */
1380 unsigned only_called_at_exit : 1;
1381 /* True when function is the transactional clone of a function which
1382 is called only from inside transactions. */
1383 /* ?? We should be able to remove this. We have enough bits in
1384 cgraph to calculate it. */
1385 unsigned tm_clone : 1;
1386 /* True if this decl is a dispatcher for function versions. */
1387 unsigned dispatcher_function : 1;
1388 /* True if this decl calls a COMDAT-local function. This is set up in
1389 compute_inline_parameters and inline_call. */
1390 unsigned calls_comdat_local : 1;
1391 /* True if node has been created by merge operation in IPA-ICF. */
1392 unsigned icf_merged: 1;
1393 /* True when function is clone created for Pointer Bounds Checker
1394 instrumentation. */
1395 unsigned instrumentation_clone : 1;
1396 /* True if call to node can't result in a call to free, munmap or
1397 other operation that could make previously non-trapping memory
1398 accesses trapping. */
1399 unsigned nonfreeing_fn : 1;
1400 /* True if there was multiple COMDAT bodies merged by lto-symtab. */
1401 unsigned merged_comdat : 1;
1402 /* True if function was created to be executed in parallel. */
1403 unsigned parallelized_function : 1;
1404 /* True if function is part split out by ipa-split. */
1405 unsigned split_part : 1;
1406 /* True if the function appears as possible target of indirect call. */
1407 unsigned indirect_call_target : 1;
1409 private:
1410 /* Worker for call_for_symbol_and_aliases. */
1411 bool call_for_symbol_and_aliases_1 (bool (*callback) (cgraph_node *,
1412 void *),
1413 void *data, bool include_overwritable);
1416 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
1417 can appear in multiple sets. */
1418 struct cgraph_node_set_def
1420 hash_map<cgraph_node *, size_t> *map;
1421 vec<cgraph_node *> nodes;
1424 typedef cgraph_node_set_def *cgraph_node_set;
1425 typedef struct varpool_node_set_def *varpool_node_set;
1427 class varpool_node;
1429 /* A varpool node set is a collection of varpool nodes. A varpool node
1430 can appear in multiple sets. */
1431 struct varpool_node_set_def
1433 hash_map<varpool_node *, size_t> * map;
1434 vec<varpool_node *> nodes;
1437 /* Iterator structure for cgraph node sets. */
1438 struct cgraph_node_set_iterator
1440 cgraph_node_set set;
1441 unsigned index;
1444 /* Iterator structure for varpool node sets. */
1445 struct varpool_node_set_iterator
1447 varpool_node_set set;
1448 unsigned index;
1451 /* Context of polymorphic call. It represent information about the type of
1452 instance that may reach the call. This is used by ipa-devirt walkers of the
1453 type inheritance graph. */
1455 class GTY(()) ipa_polymorphic_call_context {
1456 public:
1457 /* The called object appears in an object of type OUTER_TYPE
1458 at offset OFFSET. When information is not 100% reliable, we
1459 use SPECULATIVE_OUTER_TYPE and SPECULATIVE_OFFSET. */
1460 HOST_WIDE_INT offset;
1461 HOST_WIDE_INT speculative_offset;
1462 tree outer_type;
1463 tree speculative_outer_type;
1464 /* True if outer object may be in construction or destruction. */
1465 unsigned maybe_in_construction : 1;
1466 /* True if outer object may be of derived type. */
1467 unsigned maybe_derived_type : 1;
1468 /* True if speculative outer object may be of derived type. We always
1469 speculate that construction does not happen. */
1470 unsigned speculative_maybe_derived_type : 1;
1471 /* True if the context is invalid and all calls should be redirected
1472 to BUILTIN_UNREACHABLE. */
1473 unsigned invalid : 1;
1474 /* True if the outer type is dynamic. */
1475 unsigned dynamic : 1;
1477 /* Build empty "I know nothing" context. */
1478 ipa_polymorphic_call_context ();
1479 /* Build polymorphic call context for indirect call E. */
1480 ipa_polymorphic_call_context (cgraph_edge *e);
1481 /* Build polymorphic call context for IP invariant CST.
1482 If specified, OTR_TYPE specify the type of polymorphic call
1483 that takes CST+OFFSET as a prameter. */
1484 ipa_polymorphic_call_context (tree cst, tree otr_type = NULL,
1485 HOST_WIDE_INT offset = 0);
1486 /* Build context for pointer REF contained in FNDECL at statement STMT.
1487 if INSTANCE is non-NULL, return pointer to the object described by
1488 the context. */
1489 ipa_polymorphic_call_context (tree fndecl, tree ref, gimple *stmt,
1490 tree *instance = NULL);
1492 /* Look for vtable stores or constructor calls to work out dynamic type
1493 of memory location. */
1494 bool get_dynamic_type (tree, tree, tree, gimple *);
1496 /* Make context non-speculative. */
1497 void clear_speculation ();
1499 /* Produce context specifying all derrived types of OTR_TYPE. If OTR_TYPE is
1500 NULL, the context is set to dummy "I know nothing" setting. */
1501 void clear_outer_type (tree otr_type = NULL);
1503 /* Walk container types and modify context to point to actual class
1504 containing OTR_TYPE (if non-NULL) as base class.
1505 Return true if resulting context is valid.
1507 When CONSIDER_PLACEMENT_NEW is false, reject contexts that may be made
1508 valid only via alocation of new polymorphic type inside by means
1509 of placement new.
1511 When CONSIDER_BASES is false, only look for actual fields, not base types
1512 of TYPE. */
1513 bool restrict_to_inner_class (tree otr_type,
1514 bool consider_placement_new = true,
1515 bool consider_bases = true);
1517 /* Adjust all offsets in contexts by given number of bits. */
1518 void offset_by (HOST_WIDE_INT);
1519 /* Use when we can not track dynamic type change. This speculatively assume
1520 type change is not happening. */
1521 void possible_dynamic_type_change (bool, tree otr_type = NULL);
1522 /* Assume that both THIS and a given context is valid and strenghten THIS
1523 if possible. Return true if any strenghtening was made.
1524 If actual type the context is being used in is known, OTR_TYPE should be
1525 set accordingly. This improves quality of combined result. */
1526 bool combine_with (ipa_polymorphic_call_context, tree otr_type = NULL);
1527 bool meet_with (ipa_polymorphic_call_context, tree otr_type = NULL);
1529 /* Return TRUE if context is fully useless. */
1530 bool useless_p () const;
1531 /* Return TRUE if this context conveys the same information as X. */
1532 bool equal_to (const ipa_polymorphic_call_context &x) const;
1534 /* Dump human readable context to F. If NEWLINE is true, it will be
1535 terminated by a newline. */
1536 void dump (FILE *f, bool newline = true) const;
1537 void DEBUG_FUNCTION debug () const;
1539 /* LTO streaming. */
1540 void stream_out (struct output_block *) const;
1541 void stream_in (struct lto_input_block *, struct data_in *data_in);
1543 private:
1544 bool combine_speculation_with (tree, HOST_WIDE_INT, bool, tree);
1545 bool meet_speculation_with (tree, HOST_WIDE_INT, bool, tree);
1546 void set_by_decl (tree, HOST_WIDE_INT);
1547 bool set_by_invariant (tree, tree, HOST_WIDE_INT);
1548 bool speculation_consistent_p (tree, HOST_WIDE_INT, bool, tree) const;
1549 void make_speculative (tree otr_type = NULL);
1552 /* Structure containing additional information about an indirect call. */
1554 struct GTY(()) cgraph_indirect_call_info
1556 /* When agg_content is set, an offset where the call pointer is located
1557 within the aggregate. */
1558 HOST_WIDE_INT offset;
1559 /* Context of the polymorphic call; use only when POLYMORPHIC flag is set. */
1560 ipa_polymorphic_call_context context;
1561 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
1562 HOST_WIDE_INT otr_token;
1563 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
1564 tree otr_type;
1565 /* Index of the parameter that is called. */
1566 int param_index;
1567 /* ECF flags determined from the caller. */
1568 int ecf_flags;
1569 /* Profile_id of common target obtrained from profile. */
1570 int common_target_id;
1571 /* Probability that call will land in function with COMMON_TARGET_ID. */
1572 int common_target_probability;
1574 /* Set when the call is a virtual call with the parameter being the
1575 associated object pointer rather than a simple direct call. */
1576 unsigned polymorphic : 1;
1577 /* Set when the call is a call of a pointer loaded from contents of an
1578 aggregate at offset. */
1579 unsigned agg_contents : 1;
1580 /* Set when this is a call through a member pointer. */
1581 unsigned member_ptr : 1;
1582 /* When the agg_contents bit is set, this one determines whether the
1583 destination is loaded from a parameter passed by reference. */
1584 unsigned by_ref : 1;
1585 /* When the agg_contents bit is set, this one determines whether we can
1586 deduce from the function body that the loaded value from the reference is
1587 never modified between the invocation of the function and the load
1588 point. */
1589 unsigned guaranteed_unmodified : 1;
1590 /* For polymorphic calls this specify whether the virtual table pointer
1591 may have changed in between function entry and the call. */
1592 unsigned vptr_changed : 1;
1595 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"),
1596 for_user)) cgraph_edge {
1597 friend class cgraph_node;
1599 /* Remove the edge in the cgraph. */
1600 void remove (void);
1602 /* Change field call_stmt of edge to NEW_STMT.
1603 If UPDATE_SPECULATIVE and E is any component of speculative
1604 edge, then update all components. */
1605 void set_call_stmt (gcall *new_stmt, bool update_speculative = true);
1607 /* Redirect callee of the edge to N. The function does not update underlying
1608 call expression. */
1609 void redirect_callee (cgraph_node *n);
1611 /* If the edge does not lead to a thunk, simply redirect it to N. Otherwise
1612 create one or more equivalent thunks for N and redirect E to the first in
1613 the chain. Note that it is then necessary to call
1614 n->expand_all_artificial_thunks once all callers are redirected. */
1615 void redirect_callee_duplicating_thunks (cgraph_node *n);
1617 /* Make an indirect edge with an unknown callee an ordinary edge leading to
1618 CALLEE. DELTA is an integer constant that is to be added to the this
1619 pointer (first parameter) to compensate for skipping
1620 a thunk adjustment. */
1621 cgraph_edge *make_direct (cgraph_node *callee);
1623 /* Turn edge into speculative call calling N2. Update
1624 the profile so the direct call is taken COUNT times
1625 with FREQUENCY. */
1626 cgraph_edge *make_speculative (cgraph_node *n2, gcov_type direct_count,
1627 int direct_frequency);
1629 /* Given speculative call edge, return all three components. */
1630 void speculative_call_info (cgraph_edge *&direct, cgraph_edge *&indirect,
1631 ipa_ref *&reference);
1633 /* Speculative call edge turned out to be direct call to CALLE_DECL.
1634 Remove the speculative call sequence and return edge representing the call.
1635 It is up to caller to redirect the call as appropriate. */
1636 cgraph_edge *resolve_speculation (tree callee_decl = NULL);
1638 /* If necessary, change the function declaration in the call statement
1639 associated with the edge so that it corresponds to the edge callee. */
1640 gimple *redirect_call_stmt_to_callee (void);
1642 /* Create clone of edge in the node N represented
1643 by CALL_EXPR the callgraph. */
1644 cgraph_edge * clone (cgraph_node *n, gcall *call_stmt, unsigned stmt_uid,
1645 gcov_type count_scale, int freq_scale, bool update_original);
1647 /* Verify edge count and frequency. */
1648 bool verify_count_and_frequency ();
1650 /* Return true when call of edge can not lead to return from caller
1651 and thus it is safe to ignore its side effects for IPA analysis
1652 when computing side effects of the caller. */
1653 bool cannot_lead_to_return_p (void);
1655 /* Return true when the edge represents a direct recursion. */
1656 bool recursive_p (void);
1658 /* Return true if the call can be hot. */
1659 bool maybe_hot_p (void);
1661 /* Rebuild cgraph edges for current function node. This needs to be run after
1662 passes that don't update the cgraph. */
1663 static unsigned int rebuild_edges (void);
1665 /* Rebuild cgraph references for current function node. This needs to be run
1666 after passes that don't update the cgraph. */
1667 static void rebuild_references (void);
1669 /* Expected number of executions: calculated in profile.c. */
1670 gcov_type count;
1671 cgraph_node *caller;
1672 cgraph_node *callee;
1673 cgraph_edge *prev_caller;
1674 cgraph_edge *next_caller;
1675 cgraph_edge *prev_callee;
1676 cgraph_edge *next_callee;
1677 gcall *call_stmt;
1678 /* Additional information about an indirect call. Not cleared when an edge
1679 becomes direct. */
1680 cgraph_indirect_call_info *indirect_info;
1681 PTR GTY ((skip (""))) aux;
1682 /* When equal to CIF_OK, inline this call. Otherwise, points to the
1683 explanation why function was not inlined. */
1684 enum cgraph_inline_failed_t inline_failed;
1685 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
1686 when the function is serialized in. */
1687 unsigned int lto_stmt_uid;
1688 /* Expected frequency of executions within the function.
1689 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
1690 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
1691 int frequency;
1692 /* Unique id of the edge. */
1693 int uid;
1694 /* Whether this edge was made direct by indirect inlining. */
1695 unsigned int indirect_inlining_edge : 1;
1696 /* Whether this edge describes an indirect call with an undetermined
1697 callee. */
1698 unsigned int indirect_unknown_callee : 1;
1699 /* Whether this edge is still a dangling */
1700 /* True if the corresponding CALL stmt cannot be inlined. */
1701 unsigned int call_stmt_cannot_inline_p : 1;
1702 /* Can this call throw externally? */
1703 unsigned int can_throw_external : 1;
1704 /* Edges with SPECULATIVE flag represents indirect calls that was
1705 speculatively turned into direct (i.e. by profile feedback).
1706 The final code sequence will have form:
1708 if (call_target == expected_fn)
1709 expected_fn ();
1710 else
1711 call_target ();
1713 Every speculative call is represented by three components attached
1714 to a same call statement:
1715 1) a direct call (to expected_fn)
1716 2) an indirect call (to call_target)
1717 3) a IPA_REF_ADDR refrence to expected_fn.
1719 Optimizers may later redirect direct call to clone, so 1) and 3)
1720 do not need to necesarily agree with destination. */
1721 unsigned int speculative : 1;
1722 /* Set to true when caller is a constructor or destructor of polymorphic
1723 type. */
1724 unsigned in_polymorphic_cdtor : 1;
1726 /* Return true if call must bind to current definition. */
1727 bool binds_to_current_def_p ();
1729 private:
1730 /* Remove the edge from the list of the callers of the callee. */
1731 void remove_caller (void);
1733 /* Remove the edge from the list of the callees of the caller. */
1734 void remove_callee (void);
1736 /* Set callee N of call graph edge and add it to the corresponding set of
1737 callers. */
1738 void set_callee (cgraph_node *n);
1740 /* Output flags of edge to a file F. */
1741 void dump_edge_flags (FILE *f);
1743 /* Verify that call graph edge corresponds to DECL from the associated
1744 statement. Return true if the verification should fail. */
1745 bool verify_corresponds_to_fndecl (tree decl);
1748 #define CGRAPH_FREQ_BASE 1000
1749 #define CGRAPH_FREQ_MAX 100000
1751 /* The varpool data structure.
1752 Each static variable decl has assigned varpool_node. */
1754 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
1755 public:
1756 /* Dump given varpool node to F. */
1757 void dump (FILE *f);
1759 /* Dump given varpool node to stderr. */
1760 void DEBUG_FUNCTION debug (void);
1762 /* Remove variable from symbol table. */
1763 void remove (void);
1765 /* Remove node initializer when it is no longer needed. */
1766 void remove_initializer (void);
1768 void analyze (void);
1770 /* Return variable availability. */
1771 availability get_availability (symtab_node *ref = NULL);
1773 /* When doing LTO, read variable's constructor from disk if
1774 it is not already present. */
1775 tree get_constructor (void);
1777 /* Return true if variable has constructor that can be used for folding. */
1778 bool ctor_useable_for_folding_p (void);
1780 /* For given variable pool node, walk the alias chain to return the function
1781 the variable is alias of. Do not walk through thunks.
1782 When AVAILABILITY is non-NULL, get minimal availability in the chain.
1783 When REF is non-NULL, assume that reference happens in symbol REF
1784 when determining the availability. */
1785 inline varpool_node *ultimate_alias_target
1786 (availability *availability = NULL, symtab_node *ref = NULL);
1788 /* Return node that alias is aliasing. */
1789 inline varpool_node *get_alias_target (void);
1791 /* Output one variable, if necessary. Return whether we output it. */
1792 bool assemble_decl (void);
1794 /* For variables in named sections make sure get_variable_section
1795 is called before we switch to those sections. Then section
1796 conflicts between read-only and read-only requiring relocations
1797 sections can be resolved. */
1798 void finalize_named_section_flags (void);
1800 /* Call calback on varpool symbol and aliases associated to varpool symbol.
1801 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1802 skipped. */
1803 bool call_for_symbol_and_aliases (bool (*callback) (varpool_node *, void *),
1804 void *data,
1805 bool include_overwritable);
1807 /* Return true when variable should be considered externally visible. */
1808 bool externally_visible_p (void);
1810 /* Return true when all references to variable must be visible
1811 in ipa_ref_list.
1812 i.e. if the variable is not externally visible or not used in some magic
1813 way (asm statement or such).
1814 The magic uses are all summarized in force_output flag. */
1815 inline bool all_refs_explicit_p ();
1817 /* Return true when variable can be removed from variable pool
1818 if all direct calls are eliminated. */
1819 inline bool can_remove_if_no_refs_p (void);
1821 /* Add the variable DECL to the varpool.
1822 Unlike finalize_decl function is intended to be used
1823 by middle end and allows insertion of new variable at arbitrary point
1824 of compilation. */
1825 static void add (tree decl);
1827 /* Return varpool node for given symbol and check it is a function. */
1828 static inline varpool_node *get (const_tree decl);
1830 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct
1831 the middle end to output the variable to asm file, if needed or externally
1832 visible. */
1833 static void finalize_decl (tree decl);
1835 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
1836 Extra name aliases are output whenever DECL is output. */
1837 static varpool_node * create_extra_name_alias (tree alias, tree decl);
1839 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
1840 Extra name aliases are output whenever DECL is output. */
1841 static varpool_node * create_alias (tree, tree);
1843 /* Dump the variable pool to F. */
1844 static void dump_varpool (FILE *f);
1846 /* Dump the variable pool to stderr. */
1847 static void DEBUG_FUNCTION debug_varpool (void);
1849 /* Allocate new callgraph node and insert it into basic data structures. */
1850 static varpool_node *create_empty (void);
1852 /* Return varpool node assigned to DECL. Create new one when needed. */
1853 static varpool_node *get_create (tree decl);
1855 /* Given an assembler name, lookup node. */
1856 static varpool_node *get_for_asmname (tree asmname);
1858 /* Set when variable is scheduled to be assembled. */
1859 unsigned output : 1;
1861 /* Set when variable has statically initialized pointer
1862 or is a static bounds variable and needs initalization. */
1863 unsigned need_bounds_init : 1;
1865 /* Set if the variable is dynamically initialized, except for
1866 function local statics. */
1867 unsigned dynamically_initialized : 1;
1869 ENUM_BITFIELD(tls_model) tls_model : 3;
1871 /* Set if the variable is known to be used by single function only.
1872 This is computed by ipa_signle_use pass and used by late optimizations
1873 in places where optimization would be valid for local static variable
1874 if we did not do any inter-procedural code movement. */
1875 unsigned used_by_single_function : 1;
1877 private:
1878 /* Assemble thunks and aliases associated to varpool node. */
1879 void assemble_aliases (void);
1881 /* Worker for call_for_node_and_aliases. */
1882 bool call_for_symbol_and_aliases_1 (bool (*callback) (varpool_node *, void *),
1883 void *data,
1884 bool include_overwritable);
1887 /* Every top level asm statement is put into a asm_node. */
1889 struct GTY(()) asm_node {
1892 /* Next asm node. */
1893 asm_node *next;
1894 /* String for this asm node. */
1895 tree asm_str;
1896 /* Ordering of all cgraph nodes. */
1897 int order;
1900 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
1902 template <>
1903 template <>
1904 inline bool
1905 is_a_helper <cgraph_node *>::test (symtab_node *p)
1907 return p && p->type == SYMTAB_FUNCTION;
1910 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
1912 template <>
1913 template <>
1914 inline bool
1915 is_a_helper <varpool_node *>::test (symtab_node *p)
1917 return p && p->type == SYMTAB_VARIABLE;
1920 /* Macros to access the next item in the list of free cgraph nodes and
1921 edges. */
1922 #define NEXT_FREE_NODE(NODE) dyn_cast<cgraph_node *> ((NODE)->next)
1923 #define SET_NEXT_FREE_NODE(NODE,NODE2) ((NODE))->next = NODE2
1924 #define NEXT_FREE_EDGE(EDGE) (EDGE)->prev_caller
1926 typedef void (*cgraph_edge_hook)(cgraph_edge *, void *);
1927 typedef void (*cgraph_node_hook)(cgraph_node *, void *);
1928 typedef void (*varpool_node_hook)(varpool_node *, void *);
1929 typedef void (*cgraph_2edge_hook)(cgraph_edge *, cgraph_edge *, void *);
1930 typedef void (*cgraph_2node_hook)(cgraph_node *, cgraph_node *, void *);
1932 struct cgraph_edge_hook_list;
1933 struct cgraph_node_hook_list;
1934 struct varpool_node_hook_list;
1935 struct cgraph_2edge_hook_list;
1936 struct cgraph_2node_hook_list;
1938 /* Map from a symbol to initialization/finalization priorities. */
1939 struct GTY(()) symbol_priority_map {
1940 priority_type init;
1941 priority_type fini;
1944 enum symtab_state
1946 /* Frontend is parsing and finalizing functions. */
1947 PARSING,
1948 /* Callgraph is being constructed. It is safe to add new functions. */
1949 CONSTRUCTION,
1950 /* Callgraph is being streamed-in at LTO time. */
1951 LTO_STREAMING,
1952 /* Callgraph is built and early IPA passes are being run. */
1953 IPA,
1954 /* Callgraph is built and all functions are transformed to SSA form. */
1955 IPA_SSA,
1956 /* All inline decisions are done; it is now possible to remove extern inline
1957 functions and virtual call targets. */
1958 IPA_SSA_AFTER_INLINING,
1959 /* Functions are now ordered and being passed to RTL expanders. */
1960 EXPANSION,
1961 /* All cgraph expansion is done. */
1962 FINISHED
1965 struct asmname_hasher : ggc_ptr_hash <symtab_node>
1967 typedef const_tree compare_type;
1969 static hashval_t hash (symtab_node *n);
1970 static bool equal (symtab_node *n, const_tree t);
1973 class GTY((tag ("SYMTAB"))) symbol_table
1975 public:
1976 friend class symtab_node;
1977 friend class cgraph_node;
1978 friend class cgraph_edge;
1980 symbol_table (): cgraph_max_summary_uid (1)
1984 /* Initialize callgraph dump file. */
1985 void initialize (void);
1987 /* Register a top-level asm statement ASM_STR. */
1988 inline asm_node *finalize_toplevel_asm (tree asm_str);
1990 /* Analyze the whole compilation unit once it is parsed completely. */
1991 void finalize_compilation_unit (void);
1993 /* C++ frontend produce same body aliases all over the place, even before PCH
1994 gets streamed out. It relies on us linking the aliases with their function
1995 in order to do the fixups, but ipa-ref is not PCH safe. Consequentely we
1996 first produce aliases without links, but once C++ FE is sure he won't sream
1997 PCH we build the links via this function. */
1998 void process_same_body_aliases (void);
2000 /* Perform simple optimizations based on callgraph. */
2001 void compile (void);
2003 /* Process CGRAPH_NEW_FUNCTIONS and perform actions necessary to add these
2004 functions into callgraph in a way so they look like ordinary reachable
2005 functions inserted into callgraph already at construction time. */
2006 void process_new_functions (void);
2008 /* Once all functions from compilation unit are in memory, produce all clones
2009 and update all calls. We might also do this on demand if we don't want to
2010 bring all functions to memory prior compilation, but current WHOPR
2011 implementation does that and it is bit easier to keep everything right
2012 in this order. */
2013 void materialize_all_clones (void);
2015 /* Register a symbol NODE. */
2016 inline void register_symbol (symtab_node *node);
2018 inline void
2019 clear_asm_symbols (void)
2021 asmnodes = NULL;
2022 asm_last_node = NULL;
2025 /* Perform reachability analysis and reclaim all unreachable nodes. */
2026 bool remove_unreachable_nodes (FILE *file);
2028 /* Optimization of function bodies might've rendered some variables as
2029 unnecessary so we want to avoid these from being compiled. Re-do
2030 reachability starting from variables that are either externally visible
2031 or was referred from the asm output routines. */
2032 void remove_unreferenced_decls (void);
2034 /* Unregister a symbol NODE. */
2035 inline void unregister (symtab_node *node);
2037 /* Allocate new callgraph node and insert it into basic data structures. */
2038 cgraph_node *create_empty (void);
2040 /* Release a callgraph NODE with UID and put in to the list
2041 of free nodes. */
2042 void release_symbol (cgraph_node *node, int uid);
2044 /* Output all variables enqueued to be assembled. */
2045 bool output_variables (void);
2047 /* Weakrefs may be associated to external decls and thus not output
2048 at expansion time. Emit all necessary aliases. */
2049 void output_weakrefs (void);
2051 /* Return first static symbol with definition. */
2052 inline symtab_node *first_symbol (void);
2054 /* Return first assembler symbol. */
2055 inline asm_node *
2056 first_asm_symbol (void)
2058 return asmnodes;
2061 /* Return first static symbol with definition. */
2062 inline symtab_node *first_defined_symbol (void);
2064 /* Return first variable. */
2065 inline varpool_node *first_variable (void);
2067 /* Return next variable after NODE. */
2068 inline varpool_node *next_variable (varpool_node *node);
2070 /* Return first static variable with initializer. */
2071 inline varpool_node *first_static_initializer (void);
2073 /* Return next static variable with initializer after NODE. */
2074 inline varpool_node *next_static_initializer (varpool_node *node);
2076 /* Return first static variable with definition. */
2077 inline varpool_node *first_defined_variable (void);
2079 /* Return next static variable with definition after NODE. */
2080 inline varpool_node *next_defined_variable (varpool_node *node);
2082 /* Return first function with body defined. */
2083 inline cgraph_node *first_defined_function (void);
2085 /* Return next function with body defined after NODE. */
2086 inline cgraph_node *next_defined_function (cgraph_node *node);
2088 /* Return first function. */
2089 inline cgraph_node *first_function (void);
2091 /* Return next function. */
2092 inline cgraph_node *next_function (cgraph_node *node);
2094 /* Return first function with body defined. */
2095 cgraph_node *first_function_with_gimple_body (void);
2097 /* Return next reachable static variable with initializer after NODE. */
2098 inline cgraph_node *next_function_with_gimple_body (cgraph_node *node);
2100 /* Register HOOK to be called with DATA on each removed edge. */
2101 cgraph_edge_hook_list *add_edge_removal_hook (cgraph_edge_hook hook,
2102 void *data);
2104 /* Remove ENTRY from the list of hooks called on removing edges. */
2105 void remove_edge_removal_hook (cgraph_edge_hook_list *entry);
2107 /* Register HOOK to be called with DATA on each removed node. */
2108 cgraph_node_hook_list *add_cgraph_removal_hook (cgraph_node_hook hook,
2109 void *data);
2111 /* Remove ENTRY from the list of hooks called on removing nodes. */
2112 void remove_cgraph_removal_hook (cgraph_node_hook_list *entry);
2114 /* Register HOOK to be called with DATA on each removed node. */
2115 varpool_node_hook_list *add_varpool_removal_hook (varpool_node_hook hook,
2116 void *data);
2118 /* Remove ENTRY from the list of hooks called on removing nodes. */
2119 void remove_varpool_removal_hook (varpool_node_hook_list *entry);
2121 /* Register HOOK to be called with DATA on each inserted node. */
2122 cgraph_node_hook_list *add_cgraph_insertion_hook (cgraph_node_hook hook,
2123 void *data);
2125 /* Remove ENTRY from the list of hooks called on inserted nodes. */
2126 void remove_cgraph_insertion_hook (cgraph_node_hook_list *entry);
2128 /* Register HOOK to be called with DATA on each inserted node. */
2129 varpool_node_hook_list *add_varpool_insertion_hook (varpool_node_hook hook,
2130 void *data);
2132 /* Remove ENTRY from the list of hooks called on inserted nodes. */
2133 void remove_varpool_insertion_hook (varpool_node_hook_list *entry);
2135 /* Register HOOK to be called with DATA on each duplicated edge. */
2136 cgraph_2edge_hook_list *add_edge_duplication_hook (cgraph_2edge_hook hook,
2137 void *data);
2138 /* Remove ENTRY from the list of hooks called on duplicating edges. */
2139 void remove_edge_duplication_hook (cgraph_2edge_hook_list *entry);
2141 /* Register HOOK to be called with DATA on each duplicated node. */
2142 cgraph_2node_hook_list *add_cgraph_duplication_hook (cgraph_2node_hook hook,
2143 void *data);
2145 /* Remove ENTRY from the list of hooks called on duplicating nodes. */
2146 void remove_cgraph_duplication_hook (cgraph_2node_hook_list *entry);
2148 /* Call all edge removal hooks. */
2149 void call_edge_removal_hooks (cgraph_edge *e);
2151 /* Call all node insertion hooks. */
2152 void call_cgraph_insertion_hooks (cgraph_node *node);
2154 /* Call all node removal hooks. */
2155 void call_cgraph_removal_hooks (cgraph_node *node);
2157 /* Call all node duplication hooks. */
2158 void call_cgraph_duplication_hooks (cgraph_node *node, cgraph_node *node2);
2160 /* Call all edge duplication hooks. */
2161 void call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2);
2163 /* Call all node removal hooks. */
2164 void call_varpool_removal_hooks (varpool_node *node);
2166 /* Call all node insertion hooks. */
2167 void call_varpool_insertion_hooks (varpool_node *node);
2169 /* Arrange node to be first in its entry of assembler_name_hash. */
2170 void symtab_prevail_in_asm_name_hash (symtab_node *node);
2172 /* Initalize asm name hash unless. */
2173 void symtab_initialize_asm_name_hash (void);
2175 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
2176 void change_decl_assembler_name (tree decl, tree name);
2178 /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
2179 name. */
2180 static bool assembler_names_equal_p (const char *name1, const char *name2);
2182 int cgraph_count;
2183 int cgraph_max_uid;
2184 int cgraph_max_summary_uid;
2186 int edges_count;
2187 int edges_max_uid;
2189 symtab_node* GTY(()) nodes;
2190 asm_node* GTY(()) asmnodes;
2191 asm_node* GTY(()) asm_last_node;
2192 cgraph_node* GTY(()) free_nodes;
2194 /* Head of a linked list of unused (freed) call graph edges.
2195 Do not GTY((delete)) this list so UIDs gets reliably recycled. */
2196 cgraph_edge * GTY(()) free_edges;
2198 /* The order index of the next symtab node to be created. This is
2199 used so that we can sort the cgraph nodes in order by when we saw
2200 them, to support -fno-toplevel-reorder. */
2201 int order;
2203 /* Set when whole unit has been analyzed so we can access global info. */
2204 bool global_info_ready;
2205 /* What state callgraph is in right now. */
2206 enum symtab_state state;
2207 /* Set when the cgraph is fully build and the basic flags are computed. */
2208 bool function_flags_ready;
2210 bool cpp_implicit_aliases_done;
2212 /* Hash table used to hold sectoons. */
2213 hash_table<section_name_hasher> *GTY(()) section_hash;
2215 /* Hash table used to convert assembler names into nodes. */
2216 hash_table<asmname_hasher> *assembler_name_hash;
2218 /* Hash table used to hold init priorities. */
2219 hash_map<symtab_node *, symbol_priority_map> *init_priority_hash;
2221 FILE* GTY ((skip)) dump_file;
2223 /* Return symbol used to separate symbol name from suffix. */
2224 static char symbol_suffix_separator ();
2226 private:
2227 /* Allocate new callgraph node. */
2228 inline cgraph_node * allocate_cgraph_symbol (void);
2230 /* Allocate a cgraph_edge structure and fill it with data according to the
2231 parameters of which only CALLEE can be NULL (when creating an indirect call
2232 edge). */
2233 cgraph_edge *create_edge (cgraph_node *caller, cgraph_node *callee,
2234 gcall *call_stmt, gcov_type count, int freq,
2235 bool indir_unknown_callee);
2237 /* Put the edge onto the free list. */
2238 void free_edge (cgraph_edge *e);
2240 /* Insert NODE to assembler name hash. */
2241 void insert_to_assembler_name_hash (symtab_node *node, bool with_clones);
2243 /* Remove NODE from assembler name hash. */
2244 void unlink_from_assembler_name_hash (symtab_node *node, bool with_clones);
2246 /* Hash asmnames ignoring the user specified marks. */
2247 static hashval_t decl_assembler_name_hash (const_tree asmname);
2249 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
2250 static bool decl_assembler_name_equal (tree decl, const_tree asmname);
2252 friend struct asmname_hasher;
2254 /* List of hooks triggered when an edge is removed. */
2255 cgraph_edge_hook_list * GTY((skip)) m_first_edge_removal_hook;
2256 /* List of hooks triggem_red when a cgraph node is removed. */
2257 cgraph_node_hook_list * GTY((skip)) m_first_cgraph_removal_hook;
2258 /* List of hooks triggered when an edge is duplicated. */
2259 cgraph_2edge_hook_list * GTY((skip)) m_first_edge_duplicated_hook;
2260 /* List of hooks triggered when a node is duplicated. */
2261 cgraph_2node_hook_list * GTY((skip)) m_first_cgraph_duplicated_hook;
2262 /* List of hooks triggered when an function is inserted. */
2263 cgraph_node_hook_list * GTY((skip)) m_first_cgraph_insertion_hook;
2264 /* List of hooks triggered when an variable is inserted. */
2265 varpool_node_hook_list * GTY((skip)) m_first_varpool_insertion_hook;
2266 /* List of hooks triggered when a node is removed. */
2267 varpool_node_hook_list * GTY((skip)) m_first_varpool_removal_hook;
2270 extern GTY(()) symbol_table *symtab;
2272 extern vec<cgraph_node *> cgraph_new_nodes;
2274 inline hashval_t
2275 asmname_hasher::hash (symtab_node *n)
2277 return symbol_table::decl_assembler_name_hash
2278 (DECL_ASSEMBLER_NAME (n->decl));
2281 inline bool
2282 asmname_hasher::equal (symtab_node *n, const_tree t)
2284 return symbol_table::decl_assembler_name_equal (n->decl, t);
2287 /* In cgraph.c */
2288 void cgraph_c_finalize (void);
2289 void release_function_body (tree);
2290 cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
2292 void cgraph_update_edges_for_call_stmt (gimple *, tree, gimple *);
2293 bool cgraph_function_possibly_inlined_p (tree);
2295 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
2296 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
2298 extern bool gimple_check_call_matching_types (gimple *, tree, bool);
2300 /* In cgraphunit.c */
2301 void cgraphunit_c_finalize (void);
2303 /* Initialize datastructures so DECL is a function in lowered gimple form.
2304 IN_SSA is true if the gimple is in SSA. */
2305 basic_block init_lowered_empty_function (tree, bool, gcov_type);
2307 tree thunk_adjust (gimple_stmt_iterator *, tree, bool, HOST_WIDE_INT, tree);
2308 /* In cgraphclones.c */
2310 tree clone_function_name_1 (const char *, const char *);
2311 tree clone_function_name (tree decl, const char *);
2313 void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *,
2314 bool, bitmap, bool, bitmap, basic_block);
2316 /* In cgraphbuild.c */
2317 int compute_call_stmt_bb_frequency (tree, basic_block bb);
2318 void record_references_in_initializer (tree, bool);
2320 /* In ipa.c */
2321 void cgraph_build_static_cdtor (char which, tree body, int priority);
2322 bool ipa_discover_readonly_nonaddressable_vars (void);
2324 /* In varpool.c */
2325 tree ctor_for_folding (tree);
2327 /* In tree-chkp.c */
2328 extern bool chkp_function_instrumented_p (tree fndecl);
2330 /* Return true when the symbol is real symbol, i.e. it is not inline clone
2331 or abstract function kept for debug info purposes only. */
2332 inline bool
2333 symtab_node::real_symbol_p (void)
2335 cgraph_node *cnode;
2337 if (DECL_ABSTRACT_P (decl))
2338 return false;
2339 if (transparent_alias && definition)
2340 return false;
2341 if (!is_a <cgraph_node *> (this))
2342 return true;
2343 cnode = dyn_cast <cgraph_node *> (this);
2344 if (cnode->global.inlined_to)
2345 return false;
2346 return true;
2349 /* Return true if DECL should have entry in symbol table if used.
2350 Those are functions and static & external veriables*/
2352 static inline bool
2353 decl_in_symtab_p (const_tree decl)
2355 return (TREE_CODE (decl) == FUNCTION_DECL
2356 || (TREE_CODE (decl) == VAR_DECL
2357 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))));
2360 inline bool
2361 symtab_node::in_same_comdat_group_p (symtab_node *target)
2363 symtab_node *source = this;
2365 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
2367 if (cn->global.inlined_to)
2368 source = cn->global.inlined_to;
2370 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
2372 if (cn->global.inlined_to)
2373 target = cn->global.inlined_to;
2376 return source->get_comdat_group () == target->get_comdat_group ();
2379 /* Return node that alias is aliasing. */
2381 inline symtab_node *
2382 symtab_node::get_alias_target (void)
2384 ipa_ref *ref = NULL;
2385 iterate_reference (0, ref);
2386 if (ref->use == IPA_REF_CHKP)
2387 iterate_reference (1, ref);
2388 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
2389 return ref->referred;
2392 /* Return next reachable static symbol with initializer after the node. */
2394 inline symtab_node *
2395 symtab_node::next_defined_symbol (void)
2397 symtab_node *node1 = next;
2399 for (; node1; node1 = node1->next)
2400 if (node1->definition)
2401 return node1;
2403 return NULL;
2406 /* Iterates I-th reference in the list, REF is also set. */
2408 inline ipa_ref *
2409 symtab_node::iterate_reference (unsigned i, ipa_ref *&ref)
2411 vec_safe_iterate (ref_list.references, i, &ref);
2413 return ref;
2416 /* Iterates I-th referring item in the list, REF is also set. */
2418 inline ipa_ref *
2419 symtab_node::iterate_referring (unsigned i, ipa_ref *&ref)
2421 ref_list.referring.iterate (i, &ref);
2423 return ref;
2426 /* Iterates I-th referring alias item in the list, REF is also set. */
2428 inline ipa_ref *
2429 symtab_node::iterate_direct_aliases (unsigned i, ipa_ref *&ref)
2431 ref_list.referring.iterate (i, &ref);
2433 if (ref && ref->use != IPA_REF_ALIAS)
2434 return NULL;
2436 return ref;
2439 /* Return true if list contains an alias. */
2441 inline bool
2442 symtab_node::has_aliases_p (void)
2444 ipa_ref *ref = NULL;
2446 return (iterate_direct_aliases (0, ref) != NULL);
2449 /* Return true when RESOLUTION indicate that linker will use
2450 the symbol from non-LTO object files. */
2452 inline bool
2453 resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution)
2455 return (resolution == LDPR_PREVAILING_DEF
2456 || resolution == LDPR_PREEMPTED_REG
2457 || resolution == LDPR_RESOLVED_EXEC
2458 || resolution == LDPR_RESOLVED_DYN);
2461 /* Return true when symtab_node is known to be used from other (non-LTO)
2462 object file. Known only when doing LTO via linker plugin. */
2464 inline bool
2465 symtab_node::used_from_object_file_p (void)
2467 if (!TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
2468 return false;
2469 if (resolution_used_from_other_file_p (resolution))
2470 return true;
2471 return false;
2474 /* Return varpool node for given symbol and check it is a function. */
2476 inline varpool_node *
2477 varpool_node::get (const_tree decl)
2479 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
2480 return dyn_cast<varpool_node *> (symtab_node::get (decl));
2483 /* Register a symbol NODE. */
2485 inline void
2486 symbol_table::register_symbol (symtab_node *node)
2488 node->next = nodes;
2489 node->previous = NULL;
2491 if (nodes)
2492 nodes->previous = node;
2493 nodes = node;
2495 node->order = order++;
2498 /* Register a top-level asm statement ASM_STR. */
2500 asm_node *
2501 symbol_table::finalize_toplevel_asm (tree asm_str)
2503 asm_node *node;
2505 node = ggc_cleared_alloc<asm_node> ();
2506 node->asm_str = asm_str;
2507 node->order = order++;
2508 node->next = NULL;
2510 if (asmnodes == NULL)
2511 asmnodes = node;
2512 else
2513 asm_last_node->next = node;
2515 asm_last_node = node;
2516 return node;
2519 /* Unregister a symbol NODE. */
2520 inline void
2521 symbol_table::unregister (symtab_node *node)
2523 if (node->previous)
2524 node->previous->next = node->next;
2525 else
2526 nodes = node->next;
2528 if (node->next)
2529 node->next->previous = node->previous;
2531 node->next = NULL;
2532 node->previous = NULL;
2535 /* Release a callgraph NODE with UID and put in to the list of free nodes. */
2537 inline void
2538 symbol_table::release_symbol (cgraph_node *node, int uid)
2540 cgraph_count--;
2542 /* Clear out the node to NULL all pointers and add the node to the free
2543 list. */
2544 memset (node, 0, sizeof (*node));
2545 node->type = SYMTAB_FUNCTION;
2546 node->uid = uid;
2547 SET_NEXT_FREE_NODE (node, free_nodes);
2548 free_nodes = node;
2551 /* Allocate new callgraph node. */
2553 inline cgraph_node *
2554 symbol_table::allocate_cgraph_symbol (void)
2556 cgraph_node *node;
2558 if (free_nodes)
2560 node = free_nodes;
2561 free_nodes = NEXT_FREE_NODE (node);
2563 else
2565 node = ggc_cleared_alloc<cgraph_node> ();
2566 node->uid = cgraph_max_uid++;
2569 node->summary_uid = cgraph_max_summary_uid++;
2570 return node;
2574 /* Return first static symbol with definition. */
2575 inline symtab_node *
2576 symbol_table::first_symbol (void)
2578 return nodes;
2581 /* Walk all symbols. */
2582 #define FOR_EACH_SYMBOL(node) \
2583 for ((node) = symtab->first_symbol (); (node); (node) = (node)->next)
2585 /* Return first static symbol with definition. */
2586 inline symtab_node *
2587 symbol_table::first_defined_symbol (void)
2589 symtab_node *node;
2591 for (node = nodes; node; node = node->next)
2592 if (node->definition)
2593 return node;
2595 return NULL;
2598 /* Walk all symbols with definitions in current unit. */
2599 #define FOR_EACH_DEFINED_SYMBOL(node) \
2600 for ((node) = symtab->first_defined_symbol (); (node); \
2601 (node) = node->next_defined_symbol ())
2603 /* Return first variable. */
2604 inline varpool_node *
2605 symbol_table::first_variable (void)
2607 symtab_node *node;
2608 for (node = nodes; node; node = node->next)
2609 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
2610 return vnode;
2611 return NULL;
2614 /* Return next variable after NODE. */
2615 inline varpool_node *
2616 symbol_table::next_variable (varpool_node *node)
2618 symtab_node *node1 = node->next;
2619 for (; node1; node1 = node1->next)
2620 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
2621 return vnode1;
2622 return NULL;
2624 /* Walk all variables. */
2625 #define FOR_EACH_VARIABLE(node) \
2626 for ((node) = symtab->first_variable (); \
2627 (node); \
2628 (node) = symtab->next_variable ((node)))
2630 /* Return first static variable with initializer. */
2631 inline varpool_node *
2632 symbol_table::first_static_initializer (void)
2634 symtab_node *node;
2635 for (node = nodes; node; node = node->next)
2637 varpool_node *vnode = dyn_cast <varpool_node *> (node);
2638 if (vnode && DECL_INITIAL (node->decl))
2639 return vnode;
2641 return NULL;
2644 /* Return next static variable with initializer after NODE. */
2645 inline varpool_node *
2646 symbol_table::next_static_initializer (varpool_node *node)
2648 symtab_node *node1 = node->next;
2649 for (; node1; node1 = node1->next)
2651 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
2652 if (vnode1 && DECL_INITIAL (node1->decl))
2653 return vnode1;
2655 return NULL;
2658 /* Walk all static variables with initializer set. */
2659 #define FOR_EACH_STATIC_INITIALIZER(node) \
2660 for ((node) = symtab->first_static_initializer (); (node); \
2661 (node) = symtab->next_static_initializer (node))
2663 /* Return first static variable with definition. */
2664 inline varpool_node *
2665 symbol_table::first_defined_variable (void)
2667 symtab_node *node;
2668 for (node = nodes; node; node = node->next)
2670 varpool_node *vnode = dyn_cast <varpool_node *> (node);
2671 if (vnode && vnode->definition)
2672 return vnode;
2674 return NULL;
2677 /* Return next static variable with definition after NODE. */
2678 inline varpool_node *
2679 symbol_table::next_defined_variable (varpool_node *node)
2681 symtab_node *node1 = node->next;
2682 for (; node1; node1 = node1->next)
2684 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
2685 if (vnode1 && vnode1->definition)
2686 return vnode1;
2688 return NULL;
2690 /* Walk all variables with definitions in current unit. */
2691 #define FOR_EACH_DEFINED_VARIABLE(node) \
2692 for ((node) = symtab->first_defined_variable (); (node); \
2693 (node) = symtab->next_defined_variable (node))
2695 /* Return first function with body defined. */
2696 inline cgraph_node *
2697 symbol_table::first_defined_function (void)
2699 symtab_node *node;
2700 for (node = nodes; node; node = node->next)
2702 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
2703 if (cn && cn->definition)
2704 return cn;
2706 return NULL;
2709 /* Return next function with body defined after NODE. */
2710 inline cgraph_node *
2711 symbol_table::next_defined_function (cgraph_node *node)
2713 symtab_node *node1 = node->next;
2714 for (; node1; node1 = node1->next)
2716 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
2717 if (cn1 && cn1->definition)
2718 return cn1;
2720 return NULL;
2723 /* Walk all functions with body defined. */
2724 #define FOR_EACH_DEFINED_FUNCTION(node) \
2725 for ((node) = symtab->first_defined_function (); (node); \
2726 (node) = symtab->next_defined_function ((node)))
2728 /* Return first function. */
2729 inline cgraph_node *
2730 symbol_table::first_function (void)
2732 symtab_node *node;
2733 for (node = nodes; node; node = node->next)
2734 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
2735 return cn;
2736 return NULL;
2739 /* Return next function. */
2740 inline cgraph_node *
2741 symbol_table::next_function (cgraph_node *node)
2743 symtab_node *node1 = node->next;
2744 for (; node1; node1 = node1->next)
2745 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
2746 return cn1;
2747 return NULL;
2750 /* Return first function with body defined. */
2751 inline cgraph_node *
2752 symbol_table::first_function_with_gimple_body (void)
2754 symtab_node *node;
2755 for (node = nodes; node; node = node->next)
2757 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
2758 if (cn && cn->has_gimple_body_p ())
2759 return cn;
2761 return NULL;
2764 /* Return next reachable static variable with initializer after NODE. */
2765 inline cgraph_node *
2766 symbol_table::next_function_with_gimple_body (cgraph_node *node)
2768 symtab_node *node1 = node->next;
2769 for (; node1; node1 = node1->next)
2771 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
2772 if (cn1 && cn1->has_gimple_body_p ())
2773 return cn1;
2775 return NULL;
2778 /* Walk all functions. */
2779 #define FOR_EACH_FUNCTION(node) \
2780 for ((node) = symtab->first_function (); (node); \
2781 (node) = symtab->next_function ((node)))
2783 /* Return true when callgraph node is a function with Gimple body defined
2784 in current unit. Functions can also be define externally or they
2785 can be thunks with no Gimple representation.
2787 Note that at WPA stage, the function body may not be present in memory. */
2789 inline bool
2790 cgraph_node::has_gimple_body_p (void)
2792 return definition && !thunk.thunk_p && !alias;
2795 /* Walk all functions with body defined. */
2796 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
2797 for ((node) = symtab->first_function_with_gimple_body (); (node); \
2798 (node) = symtab->next_function_with_gimple_body (node))
2800 /* Uniquize all constants that appear in memory.
2801 Each constant in memory thus far output is recorded
2802 in `const_desc_table'. */
2804 struct GTY((for_user)) constant_descriptor_tree {
2805 /* A MEM for the constant. */
2806 rtx rtl;
2808 /* The value of the constant. */
2809 tree value;
2811 /* Hash of value. Computing the hash from value each time
2812 hashfn is called can't work properly, as that means recursive
2813 use of the hash table during hash table expansion. */
2814 hashval_t hash;
2817 /* Return true when function is only called directly or it has alias.
2818 i.e. it is not externally visible, address was not taken and
2819 it is not used in any other non-standard way. */
2821 inline bool
2822 cgraph_node::only_called_directly_or_aliased_p (void)
2824 gcc_assert (!global.inlined_to);
2825 return (!force_output && !address_taken
2826 && !used_from_other_partition
2827 && !DECL_VIRTUAL_P (decl)
2828 && !DECL_STATIC_CONSTRUCTOR (decl)
2829 && !DECL_STATIC_DESTRUCTOR (decl)
2830 && !used_from_object_file_p ()
2831 && !externally_visible);
2834 /* Return true when function can be removed from callgraph
2835 if all direct calls are eliminated. */
2837 inline bool
2838 cgraph_node::can_remove_if_no_direct_calls_and_refs_p (void)
2840 gcc_checking_assert (!global.inlined_to);
2841 /* Instrumentation clones should not be removed before
2842 instrumentation happens. New callers may appear after
2843 instrumentation. */
2844 if (instrumentation_clone
2845 && !chkp_function_instrumented_p (decl))
2846 return false;
2847 /* Extern inlines can always go, we will use the external definition. */
2848 if (DECL_EXTERNAL (decl))
2849 return true;
2850 /* When function is needed, we can not remove it. */
2851 if (force_output || used_from_other_partition)
2852 return false;
2853 if (DECL_STATIC_CONSTRUCTOR (decl)
2854 || DECL_STATIC_DESTRUCTOR (decl))
2855 return false;
2856 /* Only COMDAT functions can be removed if externally visible. */
2857 if (externally_visible
2858 && (!DECL_COMDAT (decl)
2859 || forced_by_abi
2860 || used_from_object_file_p ()))
2861 return false;
2862 return true;
2865 /* Verify cgraph, if consistency checking is enabled. */
2867 inline void
2868 cgraph_node::checking_verify_cgraph_nodes (void)
2870 if (flag_checking)
2871 cgraph_node::verify_cgraph_nodes ();
2874 /* Return true when variable can be removed from variable pool
2875 if all direct calls are eliminated. */
2877 inline bool
2878 varpool_node::can_remove_if_no_refs_p (void)
2880 if (DECL_EXTERNAL (decl))
2881 return true;
2882 return (!force_output && !used_from_other_partition
2883 && ((DECL_COMDAT (decl)
2884 && !forced_by_abi
2885 && !used_from_object_file_p ())
2886 || !externally_visible
2887 || DECL_HAS_VALUE_EXPR_P (decl)));
2890 /* Return true when all references to variable must be visible in ipa_ref_list.
2891 i.e. if the variable is not externally visible or not used in some magic
2892 way (asm statement or such).
2893 The magic uses are all summarized in force_output flag. */
2895 inline bool
2896 varpool_node::all_refs_explicit_p ()
2898 return (definition
2899 && !externally_visible
2900 && !used_from_other_partition
2901 && !force_output);
2904 struct tree_descriptor_hasher : ggc_ptr_hash<constant_descriptor_tree>
2906 static hashval_t hash (constant_descriptor_tree *);
2907 static bool equal (constant_descriptor_tree *, constant_descriptor_tree *);
2910 /* Constant pool accessor function. */
2911 hash_table<tree_descriptor_hasher> *constant_pool_htab (void);
2913 /* Return node that alias is aliasing. */
2915 inline cgraph_node *
2916 cgraph_node::get_alias_target (void)
2918 return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ());
2921 /* Return node that alias is aliasing. */
2923 inline varpool_node *
2924 varpool_node::get_alias_target (void)
2926 return dyn_cast <varpool_node *> (symtab_node::get_alias_target ());
2929 /* Walk the alias chain to return the symbol NODE is alias of.
2930 If NODE is not an alias, return NODE.
2931 When AVAILABILITY is non-NULL, get minimal availability in the chain.
2932 When REF is non-NULL, assume that reference happens in symbol REF
2933 when determining the availability. */
2935 inline symtab_node *
2936 symtab_node::ultimate_alias_target (enum availability *availability,
2937 symtab_node *ref)
2939 if (!alias)
2941 if (availability)
2942 *availability = get_availability (ref);
2943 return this;
2946 return ultimate_alias_target_1 (availability, ref);
2949 /* Given function symbol, walk the alias chain to return the function node
2950 is alias of. Do not walk through thunks.
2951 When AVAILABILITY is non-NULL, get minimal availability in the chain.
2952 When REF is non-NULL, assume that reference happens in symbol REF
2953 when determining the availability. */
2955 inline cgraph_node *
2956 cgraph_node::ultimate_alias_target (enum availability *availability,
2957 symtab_node *ref)
2959 cgraph_node *n = dyn_cast <cgraph_node *>
2960 (symtab_node::ultimate_alias_target (availability, ref));
2961 if (!n && availability)
2962 *availability = AVAIL_NOT_AVAILABLE;
2963 return n;
2966 /* For given variable pool node, walk the alias chain to return the function
2967 the variable is alias of. Do not walk through thunks.
2968 When AVAILABILITY is non-NULL, get minimal availability in the chain.
2969 When REF is non-NULL, assume that reference happens in symbol REF
2970 when determining the availability. */
2972 inline varpool_node *
2973 varpool_node::ultimate_alias_target (availability *availability,
2974 symtab_node *ref)
2976 varpool_node *n = dyn_cast <varpool_node *>
2977 (symtab_node::ultimate_alias_target (availability, ref));
2979 if (!n && availability)
2980 *availability = AVAIL_NOT_AVAILABLE;
2981 return n;
2984 /* Set callee N of call graph edge and add it to the corresponding set of
2985 callers. */
2987 inline void
2988 cgraph_edge::set_callee (cgraph_node *n)
2990 prev_caller = NULL;
2991 if (n->callers)
2992 n->callers->prev_caller = this;
2993 next_caller = n->callers;
2994 n->callers = this;
2995 callee = n;
2998 /* Redirect callee of the edge to N. The function does not update underlying
2999 call expression. */
3001 inline void
3002 cgraph_edge::redirect_callee (cgraph_node *n)
3004 /* Remove from callers list of the current callee. */
3005 remove_callee ();
3007 /* Insert to callers list of the new callee. */
3008 set_callee (n);
3011 /* Return true when the edge represents a direct recursion. */
3013 inline bool
3014 cgraph_edge::recursive_p (void)
3016 cgraph_node *c = callee->ultimate_alias_target ();
3017 if (caller->global.inlined_to)
3018 return caller->global.inlined_to->decl == c->decl;
3019 else
3020 return caller->decl == c->decl;
3023 /* Remove the edge from the list of the callers of the callee. */
3025 inline void
3026 cgraph_edge::remove_callee (void)
3028 gcc_assert (!indirect_unknown_callee);
3029 if (prev_caller)
3030 prev_caller->next_caller = next_caller;
3031 if (next_caller)
3032 next_caller->prev_caller = prev_caller;
3033 if (!prev_caller)
3034 callee->callers = next_caller;
3037 /* Return true if call must bind to current definition. */
3039 inline bool
3040 cgraph_edge::binds_to_current_def_p ()
3042 if (callee)
3043 return callee->binds_to_current_def_p (caller);
3044 else
3045 return NULL;
3048 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
3049 static inline bool
3050 decl_is_tm_clone (const_tree fndecl)
3052 cgraph_node *n = cgraph_node::get (fndecl);
3053 if (n)
3054 return n->tm_clone;
3055 return false;
3058 /* Likewise indicate that a node is needed, i.e. reachable via some
3059 external means. */
3061 inline void
3062 cgraph_node::mark_force_output (void)
3064 force_output = 1;
3065 gcc_checking_assert (!global.inlined_to);
3068 /* Return true if function should be optimized for size. */
3070 inline bool
3071 cgraph_node::optimize_for_size_p (void)
3073 if (opt_for_fn (decl, optimize_size))
3074 return true;
3075 if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
3076 return true;
3077 else
3078 return false;
3081 /* Return symtab_node for NODE or create one if it is not present
3082 in symtab. */
3084 inline symtab_node *
3085 symtab_node::get_create (tree node)
3087 if (TREE_CODE (node) == VAR_DECL)
3088 return varpool_node::get_create (node);
3089 else
3090 return cgraph_node::get_create (node);
3093 /* Return availability of NODE when referenced from REF. */
3095 inline enum availability
3096 symtab_node::get_availability (symtab_node *ref)
3098 if (is_a <cgraph_node *> (this))
3099 return dyn_cast <cgraph_node *> (this)->get_availability (ref);
3100 else
3101 return dyn_cast <varpool_node *> (this)->get_availability (ref);
3104 /* Call calback on symtab node and aliases associated to this node.
3105 When INCLUDE_OVERWRITABLE is false, overwritable symbols are skipped. */
3107 inline bool
3108 symtab_node::call_for_symbol_and_aliases (bool (*callback) (symtab_node *,
3109 void *),
3110 void *data,
3111 bool include_overwritable)
3113 if (include_overwritable
3114 || get_availability () > AVAIL_INTERPOSABLE)
3116 if (callback (this, data))
3117 return true;
3119 if (has_aliases_p ())
3120 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
3121 return false;
3124 /* Call callback on function and aliases associated to the function.
3125 When INCLUDE_OVERWRITABLE is false, overwritable symbols are
3126 skipped. */
3128 inline bool
3129 cgraph_node::call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
3130 void *),
3131 void *data,
3132 bool include_overwritable)
3134 if (include_overwritable
3135 || get_availability () > AVAIL_INTERPOSABLE)
3137 if (callback (this, data))
3138 return true;
3140 if (has_aliases_p ())
3141 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
3142 return false;
3145 /* Call calback on varpool symbol and aliases associated to varpool symbol.
3146 When INCLUDE_OVERWRITABLE is false, overwritable symbols are
3147 skipped. */
3149 inline bool
3150 varpool_node::call_for_symbol_and_aliases (bool (*callback) (varpool_node *,
3151 void *),
3152 void *data,
3153 bool include_overwritable)
3155 if (include_overwritable
3156 || get_availability () > AVAIL_INTERPOSABLE)
3158 if (callback (this, data))
3159 return true;
3161 if (has_aliases_p ())
3162 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
3163 return false;
3166 /* Return true if refernece may be used in address compare. */
3168 inline bool
3169 ipa_ref::address_matters_p ()
3171 if (use != IPA_REF_ADDR)
3172 return false;
3173 /* Addresses taken from virtual tables are never compared. */
3174 if (is_a <varpool_node *> (referring)
3175 && DECL_VIRTUAL_P (referring->decl))
3176 return false;
3177 return referred->address_can_be_compared_p ();
3180 /* Build polymorphic call context for indirect call E. */
3182 inline
3183 ipa_polymorphic_call_context::ipa_polymorphic_call_context (cgraph_edge *e)
3185 gcc_checking_assert (e->indirect_info->polymorphic);
3186 *this = e->indirect_info->context;
3189 /* Build empty "I know nothing" context. */
3191 inline
3192 ipa_polymorphic_call_context::ipa_polymorphic_call_context ()
3194 clear_speculation ();
3195 clear_outer_type ();
3196 invalid = false;
3199 /* Make context non-speculative. */
3201 inline void
3202 ipa_polymorphic_call_context::clear_speculation ()
3204 speculative_outer_type = NULL;
3205 speculative_offset = 0;
3206 speculative_maybe_derived_type = false;
3209 /* Produce context specifying all derrived types of OTR_TYPE. If OTR_TYPE is
3210 NULL, the context is set to dummy "I know nothing" setting. */
3212 inline void
3213 ipa_polymorphic_call_context::clear_outer_type (tree otr_type)
3215 outer_type = otr_type ? TYPE_MAIN_VARIANT (otr_type) : NULL;
3216 offset = 0;
3217 maybe_derived_type = true;
3218 maybe_in_construction = true;
3219 dynamic = true;
3222 /* Adjust all offsets in contexts by OFF bits. */
3224 inline void
3225 ipa_polymorphic_call_context::offset_by (HOST_WIDE_INT off)
3227 if (outer_type)
3228 offset += off;
3229 if (speculative_outer_type)
3230 speculative_offset += off;
3233 /* Return TRUE if context is fully useless. */
3235 inline bool
3236 ipa_polymorphic_call_context::useless_p () const
3238 return (!outer_type && !speculative_outer_type);
3241 /* Return true if NODE is local. Instrumentation clones are counted as local
3242 only when original function is local. */
3244 static inline bool
3245 cgraph_local_p (cgraph_node *node)
3247 if (!node->instrumentation_clone || !node->instrumented_version)
3248 return node->local.local;
3250 return node->local.local && node->instrumented_version->local.local;
3253 /* When using fprintf (or similar), problems can arise with
3254 transient generated strings. Many string-generation APIs
3255 only support one result being alive at once (e.g. by
3256 returning a pointer to a statically-allocated buffer).
3258 If there is more than one generated string within one
3259 fprintf call: the first string gets evicted or overwritten
3260 by the second, before fprintf is fully evaluated.
3261 See e.g. PR/53136.
3263 This function provides a workaround for this, by providing
3264 a simple way to create copies of these transient strings,
3265 without the need to have explicit cleanup:
3267 fprintf (dumpfile, "string 1: %s string 2:%s\n",
3268 xstrdup_for_dump (EXPR_1),
3269 xstrdup_for_dump (EXPR_2));
3271 This is actually a simple wrapper around ggc_strdup, but
3272 the name documents the intent. We require that no GC can occur
3273 within the fprintf call. */
3275 static inline const char *
3276 xstrdup_for_dump (const char *transient_str)
3278 return ggc_strdup (transient_str);
3281 #endif /* GCC_CGRAPH_H */