PR c/61077
[official-gcc.git] / gcc / cgraph.h
blobf8f76c42d6ca039809a96d7de353f4af888fef4f
1 /* Callgraph handling code.
2 Copyright (C) 2003-2014 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 "is-a.h"
25 #include "plugin-api.h"
26 #include "vec.h"
27 #include "basic-block.h"
28 #include "function.h"
29 #include "ipa-ref.h"
31 /* Symbol table consists of functions and variables.
32 TODO: add labels and CONST_DECLs. */
33 enum symtab_type
35 SYMTAB_SYMBOL,
36 SYMTAB_FUNCTION,
37 SYMTAB_VARIABLE
40 /* Section names are stored as reference counted strings in GGC safe hashtable
41 (to make them survive through PCH). */
43 struct GTY(()) section_hash_entry_d
45 int ref_count;
46 char *name; /* As long as this datastructure stays in GGC, we can not put
47 string at the tail of structure of GGC dies in horrible
48 way */
51 typedef struct section_hash_entry_d section_hash_entry;
53 enum availability
55 /* Not yet set by cgraph_function_body_availability. */
56 AVAIL_UNSET,
57 /* Function body/variable initializer is unknown. */
58 AVAIL_NOT_AVAILABLE,
59 /* Function body/variable initializer is known but might be replaced
60 by a different one from other compilation unit and thus needs to
61 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
62 arbitrary side effects on escaping variables and functions, while
63 like AVAILABLE it might access static variables. */
64 AVAIL_INTERPOSABLE,
65 /* Function body/variable initializer is known and will be used in final
66 program. */
67 AVAIL_AVAILABLE,
68 /* Function body/variable initializer is known and all it's uses are
69 explicitly visible within current unit (ie it's address is never taken and
70 it is not exported to other units). Currently used only for functions. */
71 AVAIL_LOCAL
74 /* Classification of symbols WRT partitioning. */
75 enum symbol_partitioning_class
77 /* External declarations are ignored by partitioning algorithms and they are
78 added into the boundary later via compute_ltrans_boundary. */
79 SYMBOL_EXTERNAL,
80 /* Partitioned symbols are pur into one of partitions. */
81 SYMBOL_PARTITION,
82 /* Duplicated symbols (such as comdat or constant pool references) are
83 copied into every node needing them via add_symbol_to_partition. */
84 SYMBOL_DUPLICATE
87 /* Base of all entries in the symbol table.
88 The symtab_node is inherited by cgraph and varpol nodes. */
89 class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
90 chain_next ("%h.next"), chain_prev ("%h.previous")))
91 symtab_node
93 public:
94 /* Return name. */
95 const char *name () const;
97 /* Return asm name. */
98 const char * asm_name () const;
100 /* Add node into symbol table. This function is not used directly, but via
101 cgraph/varpool node creation routines. */
102 void register_symbol (void);
104 /* Remove symbol from symbol table. */
105 void remove (void);
107 /* Dump symtab node to F. */
108 void dump (FILE *f);
110 /* Dump symtab node to stderr. */
111 void DEBUG_FUNCTION debug (void);
113 /* Verify consistency of node. */
114 void DEBUG_FUNCTION verify (void);
116 /* Return ipa reference from this symtab_node to
117 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
118 of the use and STMT the statement (if it exists). */
119 struct ipa_ref *add_reference (symtab_node *referred_node,
120 enum ipa_ref_use use_type);
122 /* Return ipa reference from this symtab_node to
123 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
124 of the use and STMT the statement (if it exists). */
125 struct ipa_ref *add_reference (symtab_node *referred_node,
126 enum ipa_ref_use use_type, gimple stmt);
128 /* If VAL is a reference to a function or a variable, add a reference from
129 this symtab_node to the corresponding symbol table node. USE_TYPE specify
130 type of the use and STMT the statement (if it exists). Return the new
131 reference or NULL if none was created. */
132 struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type,
133 gimple stmt);
135 /* Clone all references from symtab NODE to this symtab_node. */
136 void clone_references (symtab_node *node);
138 /* Remove all stmt references in non-speculative references.
139 Those are not maintained during inlining & clonning.
140 The exception are speculative references that are updated along
141 with callgraph edges associated with them. */
142 void clone_referring (symtab_node *node);
144 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
145 struct ipa_ref *clone_reference (struct ipa_ref *ref, gimple stmt);
147 /* Find the structure describing a reference to REFERRED_NODE
148 and associated with statement STMT. */
149 struct ipa_ref *find_reference (symtab_node *referred_node, gimple stmt,
150 unsigned int lto_stmt_uid);
152 /* Remove all references that are associated with statement STMT. */
153 void remove_stmt_references (gimple stmt);
155 /* Remove all stmt references in non-speculative references.
156 Those are not maintained during inlining & clonning.
157 The exception are speculative references that are updated along
158 with callgraph edges associated with them. */
159 void clear_stmts_in_references (void);
161 /* Remove all references in ref list. */
162 void remove_all_references (void);
164 /* Remove all referring items in ref list. */
165 void remove_all_referring (void);
167 /* Dump references in ref list to FILE. */
168 void dump_references (FILE *file);
170 /* Dump referring in list to FILE. */
171 void dump_referring (FILE *);
173 /* Iterates I-th reference in the list, REF is also set. */
174 struct ipa_ref *iterate_reference (unsigned i, struct ipa_ref *&ref);
176 /* Iterates I-th referring item in the list, REF is also set. */
177 struct ipa_ref *iterate_referring (unsigned i, struct ipa_ref *&ref);
179 /* Iterates I-th referring alias item in the list, REF is also set. */
180 struct ipa_ref *iterate_direct_aliases (unsigned i, struct ipa_ref *&ref);
182 /* Return true if symtab node and TARGET represents
183 semantically equivalent symbols. */
184 bool semantically_equivalent_p (symtab_node *target);
186 /* Classify symbol symtab node for partitioning. */
187 enum symbol_partitioning_class get_partitioning_class (void);
189 /* Return comdat group. */
190 tree get_comdat_group ()
192 return x_comdat_group;
195 /* Return comdat group as identifier_node. */
196 tree get_comdat_group_id ()
198 if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE)
199 x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group);
200 return x_comdat_group;
203 /* Set comdat group. */
204 void set_comdat_group (tree group)
206 gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE
207 || DECL_P (group));
208 x_comdat_group = group;
211 /* Return section as string. */
212 const char * get_section ()
214 if (!x_section)
215 return NULL;
216 return x_section->name;
219 /* Remove node from same comdat group. */
220 void remove_from_same_comdat_group (void);
222 /* Add this symtab_node to the same comdat group that OLD is in. */
223 void add_to_same_comdat_group (symtab_node *old_node);
225 /* Dissolve the same_comdat_group list in which NODE resides. */
226 void dissolve_same_comdat_group_list (void);
228 /* Return true when symtab_node is known to be used from other (non-LTO)
229 object file. Known only when doing LTO via linker plugin. */
230 bool used_from_object_file_p (void);
232 /* Walk the alias chain to return the symbol NODE is alias of.
233 If NODE is not an alias, return NODE.
234 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
235 symtab_node *ultimate_alias_target (enum availability *avail = NULL);
237 /* Return next reachable static symbol with initializer after NODE. */
238 inline symtab_node *next_defined_symbol (void);
240 /* Add reference recording that symtab node is alias of TARGET.
241 The function can fail in the case of aliasing cycles; in this case
242 it returns false. */
243 bool resolve_alias (symtab_node *target);
245 /* C++ FE sometimes change linkage flags after producing same
246 body aliases. */
247 void fixup_same_cpp_alias_visibility (symtab_node *target);
249 /* Call calback on symtab node and aliases associated to this node.
250 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
251 skipped. */
252 bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *),
253 void *data,
254 bool include_overwrite);
256 /* If node can not be interposable by static or dynamic linker to point to
257 different definition, return this symbol. Otherwise look for alias with
258 such property and if none exists, introduce new one. */
259 symtab_node *noninterposable_alias (void);
261 /* Return node that alias is aliasing. */
262 inline symtab_node *get_alias_target (void);
264 /* Set section for symbol and its aliases. */
265 void set_section (const char *section);
267 /* Set section, do not recurse into aliases.
268 When one wants to change section of symbol and its aliases,
269 use set_section. */
270 void set_section_for_node (const char *section);
272 /* Set initialization priority to PRIORITY. */
273 void set_init_priority (priority_type priority);
275 /* Return the initialization priority. */
276 priority_type get_init_priority ();
278 /* Return availability of NODE. */
279 enum availability get_availability (void);
281 /* Make DECL local. */
282 void make_decl_local (void);
284 /* Return true if list contains an alias. */
285 bool has_aliases_p (void);
287 /* Return true when the symbol is real symbol, i.e. it is not inline clone
288 or abstract function kept for debug info purposes only. */
289 bool real_symbol_p (void);
291 /* Return true if NODE can be discarded by linker from the binary. */
292 inline bool
293 can_be_discarded_p (void)
295 return (DECL_EXTERNAL (decl)
296 || (get_comdat_group ()
297 && resolution != LDPR_PREVAILING_DEF
298 && resolution != LDPR_PREVAILING_DEF_IRONLY
299 && resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
302 /* Return true if NODE is local to a particular COMDAT group, and must not
303 be named from outside the COMDAT. This is used for C++ decloned
304 constructors. */
305 inline bool comdat_local_p (void)
307 return (same_comdat_group && !TREE_PUBLIC (decl));
310 /* Return true if ONE and TWO are part of the same COMDAT group. */
311 inline bool in_same_comdat_group_p (symtab_node *target);
313 /* Return true when there is a reference to node and it is not vtable. */
314 bool address_taken_from_non_vtable_p (void);
316 /* Return true if symbol is known to be nonzero. */
317 bool nonzero_address ();
319 /* Return symbol table node associated with DECL, if any,
320 and NULL otherwise. */
321 static inline symtab_node *get (const_tree decl)
323 #ifdef ENABLE_CHECKING
324 /* Check that we are called for sane type of object - functions
325 and static or external variables. */
326 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
327 || (TREE_CODE (decl) == VAR_DECL
328 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
329 || in_lto_p)));
330 /* Check that the mapping is sane - perhaps this check can go away,
331 but at the moment frontends tends to corrupt the mapping by calling
332 memcpy/memset on the tree nodes. */
333 gcc_checking_assert (!decl->decl_with_vis.symtab_node
334 || decl->decl_with_vis.symtab_node->decl == decl);
335 #endif
336 return decl->decl_with_vis.symtab_node;
339 /* Dump symbol table to F. */
340 static void dump_table (FILE *);
342 /* Dump symbol table to stderr. */
343 static inline DEBUG_FUNCTION void debug_symtab (void)
345 dump_table (stderr);
348 /* Verify symbol table for internal consistency. */
349 static DEBUG_FUNCTION void verify_symtab_nodes (void);
351 /* Return true when NODE is known to be used from other (non-LTO)
352 object file. Known only when doing LTO via linker plugin. */
353 static bool used_from_object_file_p_worker (symtab_node *node);
355 /* Type of the symbol. */
356 ENUM_BITFIELD (symtab_type) type : 8;
358 /* The symbols resolution. */
359 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
361 /*** Flags representing the symbol type. ***/
363 /* True when symbol corresponds to a definition in current unit.
364 set via cgraph_finalize_function or varpool_finalize_decl */
365 unsigned definition : 1;
366 /* True when symbol is an alias.
367 Set by ssemble_alias. */
368 unsigned alias : 1;
369 /* True when alias is a weakref. */
370 unsigned weakref : 1;
371 /* C++ frontend produce same body aliases and extra name aliases for
372 virtual functions and vtables that are obviously equivalent.
373 Those aliases are bit special, especially because C++ frontend
374 visibility code is so ugly it can not get them right at first time
375 and their visibility needs to be copied from their "masters" at
376 the end of parsing. */
377 unsigned cpp_implicit_alias : 1;
378 /* Set once the definition was analyzed. The list of references and
379 other properties are built during analysis. */
380 unsigned analyzed : 1;
381 /* Set for write-only variables. */
382 unsigned writeonly : 1;
385 /*** Visibility and linkage flags. ***/
387 /* Set when function is visible by other units. */
388 unsigned externally_visible : 1;
389 /* The symbol will be assumed to be used in an invisible way (like
390 by an toplevel asm statement). */
391 unsigned force_output : 1;
392 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
393 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
394 to static and it does not inhibit optimization. */
395 unsigned forced_by_abi : 1;
396 /* True when the name is known to be unique and thus it does not need mangling. */
397 unsigned unique_name : 1;
398 /* Specify whether the section was set by user or by
399 compiler via -ffunction-sections. */
400 unsigned implicit_section : 1;
401 /* True when body and other characteristics have been removed by
402 symtab_remove_unreachable_nodes. */
403 unsigned body_removed : 1;
405 /*** WHOPR Partitioning flags.
406 These flags are used at ltrans stage when only part of the callgraph is
407 available. ***/
409 /* Set when variable is used from other LTRANS partition. */
410 unsigned used_from_other_partition : 1;
411 /* Set when function is available in the other LTRANS partition.
412 During WPA output it is used to mark nodes that are present in
413 multiple partitions. */
414 unsigned in_other_partition : 1;
418 /*** other flags. ***/
420 /* Set when symbol has address taken. */
421 unsigned address_taken : 1;
422 /* Set when init priority is set. */
423 unsigned in_init_priority_hash : 1;
426 /* Ordering of all symtab entries. */
427 int order;
429 /* Declaration representing the symbol. */
430 tree decl;
432 /* Linked list of symbol table entries starting with symtab_nodes. */
433 symtab_node *next;
434 symtab_node *previous;
436 /* Linked list of symbols with the same asm name. There may be multiple
437 entries for single symbol name during LTO, because symbols are renamed
438 only after partitioning.
440 Because inline clones are kept in the assembler name has, they also produce
441 duplicate entries.
443 There are also several long standing bugs where frontends and builtin
444 code produce duplicated decls. */
445 symtab_node *next_sharing_asm_name;
446 symtab_node *previous_sharing_asm_name;
448 /* Circular list of nodes in the same comdat group if non-NULL. */
449 symtab_node *same_comdat_group;
451 /* Vectors of referring and referenced entities. */
452 struct ipa_ref_list ref_list;
454 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
455 depending to what was known to frontend on the creation time.
456 Once alias is resolved, this pointer become NULL. */
457 tree alias_target;
459 /* File stream where this node is being written to. */
460 struct lto_file_decl_data * lto_file_data;
462 PTR GTY ((skip)) aux;
464 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
465 tree x_comdat_group;
467 /* Section name. Again can be private, if allowed. */
468 section_hash_entry *x_section;
470 protected:
471 /* Dump base fields of symtab nodes to F. Not to be used directly. */
472 void dump_base (FILE *);
474 /* Verify common part of symtab node. */
475 bool DEBUG_FUNCTION verify_base (void);
477 /* Remove node from symbol table. This function is not used directly, but via
478 cgraph/varpool node removal routines. */
479 void unregister (void);
481 /* Return the initialization and finalization priority information for
482 DECL. If there is no previous priority information, a freshly
483 allocated structure is returned. */
484 struct symbol_priority_map *priority_info (void);
486 private:
487 /* Worker for set_section. */
488 static bool set_section (symtab_node *n, void *s);
490 /* Worker for symtab_resolve_alias. */
491 static bool set_implicit_section (symtab_node *n, void *);
493 /* Worker searching noninterposable alias. */
494 static bool noninterposable_alias (symtab_node *node, void *data);
497 /* Walk all aliases for NODE. */
498 #define FOR_EACH_ALIAS(node, alias) \
499 for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++)
501 /* This is the information that is put into the cgraph local structure
502 to recover a function. */
503 struct lto_file_decl_data;
505 extern const char * const cgraph_availability_names[];
506 extern const char * const ld_plugin_symbol_resolution_names[];
507 extern const char * const tls_model_names[];
509 /* Information about thunk, used only for same body aliases. */
511 struct GTY(()) cgraph_thunk_info {
512 /* Information about the thunk. */
513 HOST_WIDE_INT fixed_offset;
514 HOST_WIDE_INT virtual_value;
515 tree alias;
516 bool this_adjusting;
517 bool virtual_offset_p;
518 /* Set to true when alias node is thunk. */
519 bool thunk_p;
522 /* Information about the function collected locally.
523 Available after function is analyzed. */
525 struct GTY(()) cgraph_local_info {
526 /* Set when function function is visible in current compilation unit only
527 and its address is never taken. */
528 unsigned local : 1;
530 /* False when there is something makes versioning impossible. */
531 unsigned versionable : 1;
533 /* False when function calling convention and signature can not be changed.
534 This is the case when __builtin_apply_args is used. */
535 unsigned can_change_signature : 1;
537 /* True when the function has been originally extern inline, but it is
538 redefined now. */
539 unsigned redefined_extern_inline : 1;
541 /* True if the function may enter serial irrevocable mode. */
542 unsigned tm_may_enter_irr : 1;
545 /* Information about the function that needs to be computed globally
546 once compilation is finished. Available only with -funit-at-a-time. */
548 struct GTY(()) cgraph_global_info {
549 /* For inline clones this points to the function they will be
550 inlined into. */
551 cgraph_node *inlined_to;
554 /* Information about the function that is propagated by the RTL backend.
555 Available only for functions that has been already assembled. */
557 struct GTY(()) cgraph_rtl_info {
558 unsigned int preferred_incoming_stack_boundary;
560 /* Call unsaved hard registers really used by the corresponding
561 function (including ones used by functions called by the
562 function). */
563 HARD_REG_SET function_used_regs;
564 /* Set if function_used_regs is valid. */
565 unsigned function_used_regs_valid: 1;
568 /* Represent which DECL tree (or reference to such tree)
569 will be replaced by another tree while versioning. */
570 struct GTY(()) ipa_replace_map
572 /* The tree that will be replaced. */
573 tree old_tree;
574 /* The new (replacing) tree. */
575 tree new_tree;
576 /* Parameter number to replace, when old_tree is NULL. */
577 int parm_num;
578 /* True when a substitution should be done, false otherwise. */
579 bool replace_p;
580 /* True when we replace a reference to old_tree. */
581 bool ref_p;
584 struct GTY(()) cgraph_clone_info
586 vec<ipa_replace_map *, va_gc> *tree_map;
587 bitmap args_to_skip;
588 bitmap combined_args_to_skip;
591 enum cgraph_simd_clone_arg_type
593 SIMD_CLONE_ARG_TYPE_VECTOR,
594 SIMD_CLONE_ARG_TYPE_UNIFORM,
595 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
596 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
597 SIMD_CLONE_ARG_TYPE_MASK
600 /* Function arguments in the original function of a SIMD clone.
601 Supplementary data for `struct simd_clone'. */
603 struct GTY(()) cgraph_simd_clone_arg {
604 /* Original function argument as it originally existed in
605 DECL_ARGUMENTS. */
606 tree orig_arg;
608 /* orig_arg's function (or for extern functions type from
609 TYPE_ARG_TYPES). */
610 tree orig_type;
612 /* If argument is a vector, this holds the vector version of
613 orig_arg that after adjusting the argument types will live in
614 DECL_ARGUMENTS. Otherwise, this is NULL.
616 This basically holds:
617 vector(simdlen) __typeof__(orig_arg) new_arg. */
618 tree vector_arg;
620 /* vector_arg's type (or for extern functions new vector type. */
621 tree vector_type;
623 /* If argument is a vector, this holds the array where the simd
624 argument is held while executing the simd clone function. This
625 is a local variable in the cloned function. Its content is
626 copied from vector_arg upon entry to the clone.
628 This basically holds:
629 __typeof__(orig_arg) simd_array[simdlen]. */
630 tree simd_array;
632 /* A SIMD clone's argument can be either linear (constant or
633 variable), uniform, or vector. */
634 enum cgraph_simd_clone_arg_type arg_type;
636 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
637 the constant linear step, if arg_type is
638 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
639 the uniform argument holding the step, otherwise 0. */
640 HOST_WIDE_INT linear_step;
642 /* Variable alignment if available, otherwise 0. */
643 unsigned int alignment;
646 /* Specific data for a SIMD function clone. */
648 struct GTY(()) cgraph_simd_clone {
649 /* Number of words in the SIMD lane associated with this clone. */
650 unsigned int simdlen;
652 /* Number of annotated function arguments in `args'. This is
653 usually the number of named arguments in FNDECL. */
654 unsigned int nargs;
656 /* Max hardware vector size in bits for integral vectors. */
657 unsigned int vecsize_int;
659 /* Max hardware vector size in bits for floating point vectors. */
660 unsigned int vecsize_float;
662 /* The mangling character for a given vector size. This is is used
663 to determine the ISA mangling bit as specified in the Intel
664 Vector ABI. */
665 unsigned char vecsize_mangle;
667 /* True if this is the masked, in-branch version of the clone,
668 otherwise false. */
669 unsigned int inbranch : 1;
671 /* True if this is a Cilk Plus variant. */
672 unsigned int cilk_elemental : 1;
674 /* Doubly linked list of SIMD clones. */
675 cgraph_node *prev_clone, *next_clone;
677 /* Original cgraph node the SIMD clones were created for. */
678 cgraph_node *origin;
680 /* Annotated function arguments for the original function. */
681 struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
684 /* Function Multiversioning info. */
685 struct GTY(()) cgraph_function_version_info {
686 /* The cgraph_node for which the function version info is stored. */
687 cgraph_node *this_node;
688 /* Chains all the semantically identical function versions. The
689 first function in this chain is the version_info node of the
690 default function. */
691 struct cgraph_function_version_info *prev;
692 /* If this version node corresponds to a dispatcher for function
693 versions, this points to the version info node of the default
694 function, the first node in the chain. */
695 struct cgraph_function_version_info *next;
696 /* If this node corresponds to a function version, this points
697 to the dispatcher function decl, which is the function that must
698 be called to execute the right function version at run-time.
700 If this cgraph node is a dispatcher (if dispatcher_function is
701 true, in the cgraph_node struct) for function versions, this
702 points to resolver function, which holds the function body of the
703 dispatcher. The dispatcher decl is an alias to the resolver
704 function decl. */
705 tree dispatcher_resolver;
708 #define DEFCIFCODE(code, type, string) CIF_ ## code,
709 /* Reasons for inlining failures. */
711 enum cgraph_inline_failed_t {
712 #include "cif-code.def"
713 CIF_N_REASONS
716 enum cgraph_inline_failed_type_t
718 CIF_FINAL_NORMAL = 0,
719 CIF_FINAL_ERROR
722 struct cgraph_edge;
724 /* The cgraph data structure.
725 Each function decl has assigned cgraph_node listing callees and callers. */
727 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
728 public:
729 /* Remove the node from cgraph and all inline clones inlined into it.
730 Skip however removal of FORBIDDEN_NODE and return true if it needs to be
731 removed. This allows to call the function from outer loop walking clone
732 tree. */
733 bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL);
735 /* Record all references from cgraph_node that are taken
736 in statement STMT. */
737 void record_stmt_references (gimple stmt);
739 /* Like cgraph_set_call_stmt but walk the clone tree and update all
740 clones sharing the same function body.
741 When WHOLE_SPECULATIVE_EDGES is true, all three components of
742 speculative edge gets updated. Otherwise we update only direct
743 call. */
744 void set_call_stmt_including_clones (gimple old_stmt, gimple new_stmt,
745 bool update_speculative = true);
747 /* Walk the alias chain to return the function cgraph_node is alias of.
748 Walk through thunk, too.
749 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
750 cgraph_node *function_symbol (enum availability *avail = NULL);
752 /* Create node representing clone of N executed COUNT times. Decrease
753 the execution counts from original node too.
754 The new clone will have decl set to DECL that may or may not be the same
755 as decl of N.
757 When UPDATE_ORIGINAL is true, the counts are subtracted from the original
758 function's profile to reflect the fact that part of execution is handled
759 by node.
760 When CALL_DUPLICATOIN_HOOK is true, the ipa passes are acknowledged about
761 the new clone. Otherwise the caller is responsible for doing so later.
763 If the new node is being inlined into another one, NEW_INLINED_TO should be
764 the outline function the new one is (even indirectly) inlined to.
765 All hooks will see this in node's global.inlined_to, when invoked.
766 Can be NULL if the node is not inlined. */
767 cgraph_node *create_clone (tree decl, gcov_type count, int freq,
768 bool update_original,
769 vec<cgraph_edge *> redirect_callers,
770 bool call_duplication_hook,
771 struct cgraph_node *new_inlined_to,
772 bitmap args_to_skip);
774 /* Create callgraph node clone with new declaration. The actual body will
775 be copied later at compilation stage. */
776 cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers,
777 vec<ipa_replace_map *, va_gc> *tree_map,
778 bitmap args_to_skip, const char * suffix);
780 /* cgraph node being removed from symbol table; see if its entry can be
781 replaced by other inline clone. */
782 cgraph_node *find_replacement (void);
784 /* Create a new cgraph node which is the new version of
785 callgraph node. REDIRECT_CALLERS holds the callers
786 edges which should be redirected to point to
787 NEW_VERSION. ALL the callees edges of the node
788 are cloned to the new version node. Return the new
789 version node.
791 If non-NULL BLOCK_TO_COPY determine what basic blocks
792 was copied to prevent duplications of calls that are dead
793 in the clone. */
795 cgraph_node *create_version_clone (tree new_decl,
796 vec<cgraph_edge *> redirect_callers,
797 bitmap bbs_to_copy);
799 /* Perform function versioning.
800 Function versioning includes copying of the tree and
801 a callgraph update (creating a new cgraph node and updating
802 its callees and callers).
804 REDIRECT_CALLERS varray includes the edges to be redirected
805 to the new version.
807 TREE_MAP is a mapping of tree nodes we want to replace with
808 new ones (according to results of prior analysis).
810 If non-NULL ARGS_TO_SKIP determine function parameters to remove
811 from new version.
812 If SKIP_RETURN is true, the new version will return void.
813 If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
814 If non_NULL NEW_ENTRY determine new entry BB of the clone.
816 Return the new version's cgraph node. */
817 cgraph_node *create_version_clone_with_body
818 (vec<cgraph_edge *> redirect_callers,
819 vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip,
820 bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block,
821 const char *clone_name);
823 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
824 corresponding to cgraph_node. */
825 struct cgraph_function_version_info *insert_new_function_version (void);
827 /* Get the cgraph_function_version_info node corresponding to node. */
828 struct cgraph_function_version_info *function_version (void);
830 /* Discover all functions and variables that are trivially needed, analyze
831 them as well as all functions and variables referred by them */
832 void analyze (void);
834 /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
835 aliases DECL with an adjustments made into the first parameter.
836 See comments in thunk_adjust for detail on the parameters. */
837 cgraph_node * create_thunk (tree alias, tree, bool this_adjusting,
838 HOST_WIDE_INT fixed_offset,
839 HOST_WIDE_INT virtual_value,
840 tree virtual_offset,
841 tree real_alias);
844 /* Return node that alias is aliasing. */
845 inline cgraph_node *get_alias_target (void);
847 /* Given function symbol, walk the alias chain to return the function node
848 is alias of. Do not walk through thunks.
849 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
851 cgraph_node *ultimate_alias_target (availability *availability = NULL);
853 /* Expand thunk NODE to gimple if possible.
854 When FORCE_GIMPLE_THUNK is true, gimple thunk is created and
855 no assembler is produced.
856 When OUTPUT_ASM_THUNK is true, also produce assembler for
857 thunks that are not lowered. */
858 bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk);
860 /* As an GCC extension we allow redefinition of the function. The
861 semantics when both copies of bodies differ is not well defined.
862 We replace the old body with new body so in unit at a time mode
863 we always use new body, while in normal mode we may end up with
864 old body inlined into some functions and new body expanded and
865 inlined in others. */
866 void reset (void);
868 /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this
869 kind of wrapper method. */
870 void create_wrapper (cgraph_node *target);
872 /* Verify cgraph nodes of the cgraph node. */
873 void DEBUG_FUNCTION verify_node (void);
875 /* Remove function from symbol table. */
876 void remove (void);
878 /* Dump call graph node to file F. */
879 void dump (FILE *f);
881 /* Dump call graph node to stderr. */
882 void DEBUG_FUNCTION debug (void);
884 /* When doing LTO, read cgraph_node's body from disk if it is not already
885 present. */
886 bool get_body (void);
888 /* Release memory used to represent body of function.
889 Use this only for functions that are released before being translated to
890 target code (i.e. RTL). Functions that are compiled to RTL and beyond
891 are free'd in final.c via free_after_compilation(). */
892 void release_body (void);
894 /* cgraph_node is no longer nested function; update cgraph accordingly. */
895 void unnest (void);
897 /* Bring cgraph node local. */
898 void make_local (void);
900 /* Likewise indicate that a node is having address taken. */
901 void mark_address_taken (void);
903 /* Set fialization priority to PRIORITY. */
904 void set_fini_priority (priority_type priority);
906 /* Return the finalization priority. */
907 priority_type get_fini_priority (void);
909 /* Create edge from a given function to CALLEE in the cgraph. */
910 struct cgraph_edge *create_edge (cgraph_node *callee,
911 gimple call_stmt, gcov_type count,
912 int freq);
913 /* Create an indirect edge with a yet-undetermined callee where the call
914 statement destination is a formal parameter of the caller with index
915 PARAM_INDEX. */
916 struct cgraph_edge *create_indirect_edge (gimple call_stmt, int ecf_flags,
917 gcov_type count, int freq);
919 /* Like cgraph_create_edge walk the clone tree and update all clones sharing
920 same function body. If clones already have edge for OLD_STMT; only
921 update the edge same way as cgraph_set_call_stmt_including_clones does. */
922 void create_edge_including_clones (struct cgraph_node *callee,
923 gimple old_stmt, gimple stmt,
924 gcov_type count,
925 int freq,
926 cgraph_inline_failed_t reason);
928 /* Return the callgraph edge representing the GIMPLE_CALL statement
929 CALL_STMT. */
930 cgraph_edge *get_edge (gimple call_stmt);
932 /* Collect all callers of cgraph_node and its aliases that are known to lead
933 to NODE (i.e. are not overwritable). */
934 vec<cgraph_edge *> collect_callers (void);
936 /* Remove all callers from the node. */
937 void remove_callers (void);
939 /* Remove all callees from the node. */
940 void remove_callees (void);
942 /* Return function availability. See cgraph.h for description of individual
943 return values. */
944 enum availability get_availability (void);
946 /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node
947 if any to NOTHROW. */
948 void set_nothrow_flag (bool nothrow);
950 /* Set TREE_READONLY on cgraph_node's decl and on aliases of the node
951 if any to READONLY. */
952 void set_const_flag (bool readonly, bool looping);
954 /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
955 if any to PURE. */
956 void set_pure_flag (bool pure, bool looping);
958 /* Call all node duplication hooks. */
959 void call_duplication_hooks (cgraph_node *node2);
961 /* Call calback on function and aliases associated to the function.
962 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
963 skipped. */
965 bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
966 void *),
967 void *data, bool include_overwritable);
969 /* Call calback on cgraph_node, thunks and aliases associated to NODE.
970 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
971 skipped. */
972 bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node,
973 void *data),
974 void *data,
975 bool include_overwritable);
977 /* Call all node insertion hooks. */
978 void call_function_insertion_hooks (void);
980 /* Likewise indicate that a node is needed, i.e. reachable via some
981 external means. */
982 inline void mark_force_output (void);
984 /* Return true when function can be marked local. */
985 bool local_p (void);
987 /* Return true if cgraph_node can be made local for API change.
988 Extern inline functions and C++ COMDAT functions can be made local
989 at the expense of possible code size growth if function is used in multiple
990 compilation units. */
991 bool can_be_local_p (void);
993 /* Return true when cgraph_node can not return or throw and thus
994 it is safe to ignore its side effects for IPA analysis. */
995 bool cannot_return_p (void);
997 /* Return true when function cgraph_node and all its aliases are only called
998 directly.
999 i.e. it is not externally visible, address was not taken and
1000 it is not used in any other non-standard way. */
1001 bool only_called_directly_p (void);
1003 /* Return true when function is only called directly or it has alias.
1004 i.e. it is not externally visible, address was not taken and
1005 it is not used in any other non-standard way. */
1006 inline bool only_called_directly_or_aliased_p (void);
1008 /* Return true when function cgraph_node can be expected to be removed
1009 from program when direct calls in this compilation unit are removed.
1011 As a special case COMDAT functions are
1012 cgraph_can_remove_if_no_direct_calls_p while the are not
1013 cgraph_only_called_directly_p (it is possible they are called from other
1014 unit)
1016 This function behaves as cgraph_only_called_directly_p because eliminating
1017 all uses of COMDAT function does not make it necessarily disappear from
1018 the program unless we are compiling whole program or we do LTO. In this
1019 case we know we win since dynamic linking will not really discard the
1020 linkonce section. */
1021 bool will_be_removed_from_program_if_no_direct_calls_p (void);
1023 /* Return true when function can be removed from callgraph
1024 if all direct calls are eliminated. */
1025 bool can_remove_if_no_direct_calls_and_refs_p (void);
1027 /* Return true when function cgraph_node and its aliases can be removed from
1028 callgraph if all direct calls are eliminated. */
1029 bool can_remove_if_no_direct_calls_p (void);
1031 /* Return true when callgraph node is a function with Gimple body defined
1032 in current unit. Functions can also be define externally or they
1033 can be thunks with no Gimple representation.
1035 Note that at WPA stage, the function body may not be present in memory. */
1036 inline bool has_gimple_body_p (void);
1038 /* Return true if function should be optimized for size. */
1039 bool optimize_for_size_p (void);
1041 /* Dump the callgraph to file F. */
1042 static void dump_cgraph (FILE *f);
1044 /* Dump the call graph to stderr. */
1045 static inline void debug_cgraph (void)
1047 dump_cgraph (stderr);
1050 /* Record that DECL1 and DECL2 are semantically identical function
1051 versions. */
1052 static void record_function_versions (tree decl1, tree decl2);
1054 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
1055 DECL is a duplicate declaration. */
1056 static void delete_function_version (tree decl);
1058 /* Add the function FNDECL to the call graph.
1059 Unlike cgraph_finalize_function, this function is intended to be used
1060 by middle end and allows insertion of new function at arbitrary point
1061 of compilation. The function can be either in high, low or SSA form
1062 GIMPLE.
1064 The function is assumed to be reachable and have address taken (so no
1065 API breaking optimizations are performed on it).
1067 Main work done by this function is to enqueue the function for later
1068 processing to avoid need the passes to be re-entrant. */
1069 static void add_new_function (tree fndecl, bool lowered);
1071 /* Return callgraph node for given symbol and check it is a function. */
1072 static inline cgraph_node *get (const_tree decl)
1074 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1075 return dyn_cast <cgraph_node *> (symtab_node::get (decl));
1078 /* Return cgraph node assigned to DECL. Create new one when needed. */
1079 static cgraph_node * create (tree decl);
1081 /* Allocate new callgraph node and insert it into basic data structures. */
1082 static cgraph_node * create_empty (void);
1084 /* Try to find a call graph node for declaration DECL and if it does not
1085 exist or if it corresponds to an inline clone, create a new one. */
1086 static cgraph_node * get_create (tree);
1088 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
1089 Return NULL if there's no such node. */
1090 static cgraph_node *get_for_asmname (tree asmname);
1092 /* Attempt to mark ALIAS as an alias to DECL. Return alias node if
1093 successful and NULL otherwise.
1094 Same body aliases are output whenever the body of DECL is output,
1095 and cgraph_node::get (ALIAS) transparently
1096 returns cgraph_node::get (DECL). */
1097 static cgraph_node * create_same_body_alias (tree alias, tree decl);
1099 /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
1100 static bool used_from_object_file_p_worker (cgraph_node *node, void *)
1102 return node->used_from_object_file_p ();
1105 /* Return true when cgraph_node can not be local.
1106 Worker for cgraph_local_node_p. */
1107 static bool non_local_p (cgraph_node *node, void *);
1109 /* Verify whole cgraph structure. */
1110 static void DEBUG_FUNCTION verify_cgraph_nodes (void);
1112 /* Worker to bring NODE local. */
1113 static bool make_local (cgraph_node *node, void *);
1115 /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
1116 the function body is associated
1117 with (not necessarily cgraph_node (DECL). */
1118 static cgraph_node *create_alias (tree alias, tree target);
1120 static cgraph_edge * create_edge (cgraph_node *caller, cgraph_node *callee,
1121 gimple call_stmt, gcov_type count,
1122 int freq,
1123 bool indir_unknown_callee);
1125 struct cgraph_edge *callees;
1126 struct cgraph_edge *callers;
1127 /* List of edges representing indirect calls with a yet undetermined
1128 callee. */
1129 struct cgraph_edge *indirect_calls;
1130 /* For nested functions points to function the node is nested in. */
1131 cgraph_node *origin;
1132 /* Points to first nested function, if any. */
1133 cgraph_node *nested;
1134 /* Pointer to the next function with same origin, if any. */
1135 cgraph_node *next_nested;
1136 /* Pointer to the next clone. */
1137 cgraph_node *next_sibling_clone;
1138 cgraph_node *prev_sibling_clone;
1139 cgraph_node *clones;
1140 cgraph_node *clone_of;
1141 /* For functions with many calls sites it holds map from call expression
1142 to the edge to speed up cgraph_edge function. */
1143 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
1144 /* Declaration node used to be clone of. */
1145 tree former_clone_of;
1147 /* If this is a SIMD clone, this points to the SIMD specific
1148 information for it. */
1149 struct cgraph_simd_clone *simdclone;
1150 /* If this function has SIMD clones, this points to the first clone. */
1151 cgraph_node *simd_clones;
1153 /* Interprocedural passes scheduled to have their transform functions
1154 applied next time we execute local pass on them. We maintain it
1155 per-function in order to allow IPA passes to introduce new functions. */
1156 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
1158 struct cgraph_local_info local;
1159 struct cgraph_global_info global;
1160 struct cgraph_rtl_info rtl;
1161 struct cgraph_clone_info clone;
1162 struct cgraph_thunk_info thunk;
1164 /* Expected number of executions: calculated in profile.c. */
1165 gcov_type count;
1166 /* How to scale counts at materialization time; used to merge
1167 LTO units with different number of profile runs. */
1168 int count_materialization_scale;
1169 /* Unique id of the node. */
1170 int uid;
1171 /* ID assigned by the profiling. */
1172 unsigned int profile_id;
1173 /* Time profiler: first run of function. */
1174 int tp_first_run;
1176 /* Set when decl is an abstract function pointed to by the
1177 ABSTRACT_DECL_ORIGIN of a reachable function. */
1178 unsigned used_as_abstract_origin : 1;
1179 /* Set once the function is lowered (i.e. its CFG is built). */
1180 unsigned lowered : 1;
1181 /* Set once the function has been instantiated and its callee
1182 lists created. */
1183 unsigned process : 1;
1184 /* How commonly executed the node is. Initialized during branch
1185 probabilities pass. */
1186 ENUM_BITFIELD (node_frequency) frequency : 2;
1187 /* True when function can only be called at startup (from static ctor). */
1188 unsigned only_called_at_startup : 1;
1189 /* True when function can only be called at startup (from static dtor). */
1190 unsigned only_called_at_exit : 1;
1191 /* True when function is the transactional clone of a function which
1192 is called only from inside transactions. */
1193 /* ?? We should be able to remove this. We have enough bits in
1194 cgraph to calculate it. */
1195 unsigned tm_clone : 1;
1196 /* True if this decl is a dispatcher for function versions. */
1197 unsigned dispatcher_function : 1;
1198 /* True if this decl calls a COMDAT-local function. This is set up in
1199 compute_inline_parameters and inline_call. */
1200 unsigned calls_comdat_local : 1;
1203 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
1204 can appear in multiple sets. */
1205 struct cgraph_node_set_def
1207 struct pointer_map_t *map;
1208 vec<cgraph_node *> nodes;
1211 typedef cgraph_node_set_def *cgraph_node_set;
1212 typedef struct varpool_node_set_def *varpool_node_set;
1214 class varpool_node;
1216 /* A varpool node set is a collection of varpool nodes. A varpool node
1217 can appear in multiple sets. */
1218 struct varpool_node_set_def
1220 struct pointer_map_t * map;
1221 vec<varpool_node *> nodes;
1224 /* Iterator structure for cgraph node sets. */
1225 struct cgraph_node_set_iterator
1227 cgraph_node_set set;
1228 unsigned index;
1231 /* Iterator structure for varpool node sets. */
1232 struct varpool_node_set_iterator
1234 varpool_node_set set;
1235 unsigned index;
1238 /* Structure containing additional information about an indirect call. */
1240 struct GTY(()) cgraph_indirect_call_info
1242 /* When polymorphic is set, this field contains offset where the object which
1243 was actually used in the polymorphic resides within a larger structure.
1244 If agg_contents is set, the field contains the offset within the aggregate
1245 from which the address to call was loaded. */
1246 HOST_WIDE_INT offset;
1247 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
1248 HOST_WIDE_INT otr_token;
1249 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
1250 tree otr_type, outer_type;
1251 /* Index of the parameter that is called. */
1252 int param_index;
1253 /* ECF flags determined from the caller. */
1254 int ecf_flags;
1255 /* Profile_id of common target obtrained from profile. */
1256 int common_target_id;
1257 /* Probability that call will land in function with COMMON_TARGET_ID. */
1258 int common_target_probability;
1260 /* Set when the call is a virtual call with the parameter being the
1261 associated object pointer rather than a simple direct call. */
1262 unsigned polymorphic : 1;
1263 /* Set when the call is a call of a pointer loaded from contents of an
1264 aggregate at offset. */
1265 unsigned agg_contents : 1;
1266 /* Set when this is a call through a member pointer. */
1267 unsigned member_ptr : 1;
1268 /* When the previous bit is set, this one determines whether the destination
1269 is loaded from a parameter passed by reference. */
1270 unsigned by_ref : 1;
1271 unsigned int maybe_in_construction : 1;
1272 unsigned int maybe_derived_type : 1;
1275 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
1276 /* Expected number of executions: calculated in profile.c. */
1277 gcov_type count;
1278 cgraph_node *caller;
1279 cgraph_node *callee;
1280 struct cgraph_edge *prev_caller;
1281 struct cgraph_edge *next_caller;
1282 struct cgraph_edge *prev_callee;
1283 struct cgraph_edge *next_callee;
1284 gimple call_stmt;
1285 /* Additional information about an indirect call. Not cleared when an edge
1286 becomes direct. */
1287 struct cgraph_indirect_call_info *indirect_info;
1288 PTR GTY ((skip (""))) aux;
1289 /* When equal to CIF_OK, inline this call. Otherwise, points to the
1290 explanation why function was not inlined. */
1291 enum cgraph_inline_failed_t inline_failed;
1292 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
1293 when the function is serialized in. */
1294 unsigned int lto_stmt_uid;
1295 /* Expected frequency of executions within the function.
1296 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
1297 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
1298 int frequency;
1299 /* Unique id of the edge. */
1300 int uid;
1301 /* Whether this edge was made direct by indirect inlining. */
1302 unsigned int indirect_inlining_edge : 1;
1303 /* Whether this edge describes an indirect call with an undetermined
1304 callee. */
1305 unsigned int indirect_unknown_callee : 1;
1306 /* Whether this edge is still a dangling */
1307 /* True if the corresponding CALL stmt cannot be inlined. */
1308 unsigned int call_stmt_cannot_inline_p : 1;
1309 /* Can this call throw externally? */
1310 unsigned int can_throw_external : 1;
1311 /* Edges with SPECULATIVE flag represents indirect calls that was
1312 speculatively turned into direct (i.e. by profile feedback).
1313 The final code sequence will have form:
1315 if (call_target == expected_fn)
1316 expected_fn ();
1317 else
1318 call_target ();
1320 Every speculative call is represented by three components attached
1321 to a same call statement:
1322 1) a direct call (to expected_fn)
1323 2) an indirect call (to call_target)
1324 3) a IPA_REF_ADDR refrence to expected_fn.
1326 Optimizers may later redirect direct call to clone, so 1) and 3)
1327 do not need to necesarily agree with destination. */
1328 unsigned int speculative : 1;
1331 #define CGRAPH_FREQ_BASE 1000
1332 #define CGRAPH_FREQ_MAX 100000
1334 /* The varpool data structure.
1335 Each static variable decl has assigned varpool_node. */
1337 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
1338 public:
1339 /* Dump given varpool node to F. */
1340 void dump (FILE *f);
1342 /* Dump given varpool node to stderr. */
1343 void DEBUG_FUNCTION debug (void);
1345 /* Remove variable from symbol table. */
1346 void remove (void);
1348 /* Remove node initializer when it is no longer needed. */
1349 void remove_initializer (void);
1351 void analyze (void);
1353 /* Return variable availability. */
1354 availability get_availability (void);
1356 /* When doing LTO, read variable's constructor from disk if
1357 it is not already present. */
1358 tree get_constructor (void);
1360 /* Return true if variable has constructor that can be used for folding. */
1361 bool ctor_useable_for_folding_p (void);
1363 /* For given variable pool node, walk the alias chain to return the function
1364 the variable is alias of. Do not walk through thunks.
1365 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1366 inline varpool_node *ultimate_alias_target
1367 (availability *availability = NULL);
1369 /* Return node that alias is aliasing. */
1370 inline varpool_node *get_alias_target (void);
1372 /* Output one variable, if necessary. Return whether we output it. */
1373 bool assemble_decl (void);
1375 /* For variables in named sections make sure get_variable_section
1376 is called before we switch to those sections. Then section
1377 conflicts between read-only and read-only requiring relocations
1378 sections can be resolved. */
1379 void finalize_named_section_flags (void);
1381 /* Call calback on varpool symbol and aliases associated to varpool symbol.
1382 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1383 skipped. */
1384 bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *),
1385 void *data,
1386 bool include_overwritable);
1388 /* Return true when variable should be considered externally visible. */
1389 bool externally_visible_p (void);
1391 /* Return true when all references to variable must be visible
1392 in ipa_ref_list.
1393 i.e. if the variable is not externally visible or not used in some magic
1394 way (asm statement or such).
1395 The magic uses are all summarized in force_output flag. */
1396 inline bool all_refs_explicit_p ();
1398 /* Return true when variable can be removed from variable pool
1399 if all direct calls are eliminated. */
1400 inline bool can_remove_if_no_refs_p (void);
1402 /* Return varpool node for given symbol and check it is a function. */
1403 static inline varpool_node *get (const_tree decl);
1405 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct
1406 the middle end to output the variable to asm file, if needed or externally
1407 visible. */
1408 static void finalize_decl (tree decl);
1410 /* Output all variables enqueued to be assembled. */
1411 static bool output_variables (void);
1413 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
1414 Extra name aliases are output whenever DECL is output. */
1415 static varpool_node * create_extra_name_alias (tree alias, tree decl);
1417 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
1418 Extra name aliases are output whenever DECL is output. */
1419 static varpool_node * create_alias (tree, tree);
1421 /* Dump the variable pool to F. */
1422 static void dump_varpool (FILE *f);
1424 /* Dump the variable pool to stderr. */
1425 static void DEBUG_FUNCTION debug_varpool (void);
1427 /* Allocate new callgraph node and insert it into basic data structures. */
1428 static varpool_node *create_empty (void);
1430 /* Return varpool node assigned to DECL. Create new one when needed. */
1431 static varpool_node *get_create (tree decl);
1433 /* Given an assembler name, lookup node. */
1434 static varpool_node *get_for_asmname (tree asmname);
1436 /* Set when variable is scheduled to be assembled. */
1437 unsigned output : 1;
1439 /* Set if the variable is dynamically initialized, except for
1440 function local statics. */
1441 unsigned dynamically_initialized : 1;
1443 ENUM_BITFIELD(tls_model) tls_model : 3;
1445 /* Set if the variable is known to be used by single function only.
1446 This is computed by ipa_signle_use pass and used by late optimizations
1447 in places where optimization would be valid for local static variable
1448 if we did not do any inter-procedural code movement. */
1449 unsigned used_by_single_function : 1;
1451 private:
1452 /* Assemble thunks and aliases associated to varpool node. */
1453 void assemble_aliases (void);
1456 /* Every top level asm statement is put into a asm_node. */
1458 struct GTY(()) asm_node {
1459 /* Next asm node. */
1460 struct asm_node *next;
1461 /* String for this asm node. */
1462 tree asm_str;
1463 /* Ordering of all cgraph nodes. */
1464 int order;
1467 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
1469 template <>
1470 template <>
1471 inline bool
1472 is_a_helper <cgraph_node *>::test (symtab_node *p)
1474 return p && p->type == SYMTAB_FUNCTION;
1477 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
1479 template <>
1480 template <>
1481 inline bool
1482 is_a_helper <varpool_node *>::test (symtab_node *p)
1484 return p && p->type == SYMTAB_VARIABLE;
1487 extern GTY(()) symtab_node *symtab_nodes;
1488 extern GTY(()) int cgraph_n_nodes;
1489 extern GTY(()) int cgraph_max_uid;
1490 extern GTY(()) int cgraph_edge_max_uid;
1491 extern bool cgraph_global_info_ready;
1492 enum cgraph_state
1494 /* Frontend is parsing and finalizing functions. */
1495 CGRAPH_STATE_PARSING,
1496 /* Callgraph is being constructed. It is safe to add new functions. */
1497 CGRAPH_STATE_CONSTRUCTION,
1498 /* Callgraph is being at LTO time. */
1499 CGRAPH_LTO_STREAMING,
1500 /* Callgraph is built and IPA passes are being run. */
1501 CGRAPH_STATE_IPA,
1502 /* Callgraph is built and all functions are transformed to SSA form. */
1503 CGRAPH_STATE_IPA_SSA,
1504 /* Functions are now ordered and being passed to RTL expanders. */
1505 CGRAPH_STATE_EXPANSION,
1506 /* All cgraph expansion is done. */
1507 CGRAPH_STATE_FINISHED
1509 extern enum cgraph_state cgraph_state;
1510 extern bool cgraph_function_flags_ready;
1511 extern cgraph_node_set cgraph_new_nodes;
1513 extern GTY(()) struct asm_node *asm_nodes;
1514 extern GTY(()) int symtab_order;
1515 extern bool cpp_implicit_aliases_done;
1517 /* In symtab.c */
1518 symtab_node *symtab_node_for_asm (const_tree asmname);
1520 /* In cgraph.c */
1521 void release_function_body (tree);
1522 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
1523 void cgraph_remove_edge (struct cgraph_edge *);
1525 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
1526 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
1527 struct cgraph_local_info *cgraph_local_info (tree);
1528 struct cgraph_global_info *cgraph_global_info (tree);
1529 struct cgraph_rtl_info *cgraph_rtl_info (tree);
1530 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
1531 struct cgraph_edge *);
1533 bool cgraph_function_possibly_inlined_p (tree);
1534 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
1535 void cgraph_redirect_edge_callee (struct cgraph_edge *, cgraph_node *);
1536 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *,
1537 cgraph_node *);
1539 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
1540 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
1542 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
1543 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
1544 typedef void (*cgraph_node_hook)(cgraph_node *, void *);
1545 typedef void (*varpool_node_hook)(varpool_node *, void *);
1546 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
1547 void *);
1548 typedef void (*cgraph_2node_hook)(cgraph_node *, cgraph_node *,
1549 void *);
1550 struct cgraph_edge_hook_list;
1551 struct cgraph_node_hook_list;
1552 struct varpool_node_hook_list;
1553 struct cgraph_2edge_hook_list;
1554 struct cgraph_2node_hook_list;
1555 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
1556 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
1557 cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
1558 void *);
1559 void cgraph_remove_node_removal_hook (cgraph_node_hook_list *);
1560 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
1561 void *);
1562 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
1563 cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
1564 void *);
1565 void cgraph_remove_function_insertion_hook (cgraph_node_hook_list *);
1566 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
1567 void *);
1568 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
1569 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
1570 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
1571 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
1572 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
1573 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
1574 struct cgraph_edge *
1575 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
1576 cgraph_node *,
1577 gcov_type, int);
1578 void cgraph_speculative_call_info (struct cgraph_edge *,
1579 struct cgraph_edge *&,
1580 struct cgraph_edge *&,
1581 struct ipa_ref *&);
1582 extern bool gimple_check_call_matching_types (gimple, tree, bool);
1584 /* In cgraphunit.c */
1585 struct asm_node *add_asm_node (tree);
1586 extern FILE *cgraph_dump_file;
1587 void cgraph_finalize_function (tree, bool);
1588 void finalize_compilation_unit (void);
1589 void compile (void);
1590 void init_cgraph (void);
1591 void cgraph_process_new_functions (void);
1592 void cgraph_process_same_body_aliases (void);
1593 /* Initialize datastructures so DECL is a function in lowered gimple form.
1594 IN_SSA is true if the gimple is in SSA. */
1595 basic_block init_lowered_empty_function (tree, bool);
1597 /* In cgraphclones.c */
1599 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
1600 cgraph_node *, gimple,
1601 unsigned, gcov_type, int, bool);
1602 tree clone_function_name (tree decl, const char *);
1604 void cgraph_materialize_all_clones (void);
1605 void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *,
1606 bool, bitmap, bool, bitmap, basic_block);
1607 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
1609 /* In cgraphbuild.c */
1610 unsigned int rebuild_cgraph_edges (void);
1611 void cgraph_rebuild_references (void);
1612 int compute_call_stmt_bb_frequency (tree, basic_block bb);
1613 void record_references_in_initializer (tree, bool);
1615 /* In ipa.c */
1616 bool symtab_remove_unreachable_nodes (bool, FILE *);
1617 cgraph_node_set cgraph_node_set_new (void);
1618 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
1619 cgraph_node *);
1620 void cgraph_node_set_add (cgraph_node_set, cgraph_node *);
1621 void cgraph_node_set_remove (cgraph_node_set, cgraph_node *);
1622 void dump_cgraph_node_set (FILE *, cgraph_node_set);
1623 void debug_cgraph_node_set (cgraph_node_set);
1624 void free_cgraph_node_set (cgraph_node_set);
1625 void cgraph_build_static_cdtor (char which, tree body, int priority);
1627 varpool_node_set varpool_node_set_new (void);
1628 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
1629 varpool_node *);
1630 void varpool_node_set_add (varpool_node_set, varpool_node *);
1631 void varpool_node_set_remove (varpool_node_set, varpool_node *);
1632 void dump_varpool_node_set (FILE *, varpool_node_set);
1633 void debug_varpool_node_set (varpool_node_set);
1634 void free_varpool_node_set (varpool_node_set);
1635 void ipa_discover_readonly_nonaddressable_vars (void);
1637 /* In predict.c */
1638 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
1640 /* In varpool.c */
1641 void varpool_reset_queue (void);
1642 tree ctor_for_folding (tree);
1643 void varpool_add_new_variable (tree);
1644 void symtab_initialize_asm_name_hash (void);
1645 void symtab_prevail_in_asm_name_hash (symtab_node *node);
1647 /* In cgraph.c */
1648 extern void change_decl_assembler_name (tree, tree);
1650 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1651 or abstract function kept for debug info purposes only. */
1652 inline bool
1653 symtab_node::real_symbol_p (void)
1655 cgraph_node *cnode;
1657 if (DECL_ABSTRACT (decl))
1658 return false;
1659 if (!is_a <cgraph_node *> (this))
1660 return true;
1661 cnode = dyn_cast <cgraph_node *> (this);
1662 if (cnode->global.inlined_to)
1663 return false;
1664 return true;
1667 /* Return true if DECL should have entry in symbol table if used.
1668 Those are functions and static & external veriables*/
1670 static inline bool
1671 decl_in_symtab_p (const_tree decl)
1673 return (TREE_CODE (decl) == FUNCTION_DECL
1674 || (TREE_CODE (decl) == VAR_DECL
1675 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))));
1678 inline bool
1679 symtab_node::in_same_comdat_group_p (symtab_node *target)
1681 symtab_node *source = this;
1683 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
1685 if (cn->global.inlined_to)
1686 source = cn->global.inlined_to;
1688 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
1690 if (cn->global.inlined_to)
1691 target = cn->global.inlined_to;
1694 return source->get_comdat_group () == target->get_comdat_group ();
1697 /* Return node that alias is aliasing. */
1699 inline symtab_node *
1700 symtab_node::get_alias_target (void)
1702 struct ipa_ref *ref = NULL;
1703 iterate_reference (0, ref);
1704 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1705 return ref->referred;
1708 /* Return next reachable static symbol with initializer after the node. */
1709 inline symtab_node *
1710 symtab_node::next_defined_symbol (void)
1712 symtab_node *node1 = next;
1714 for (; node1; node1 = node1->next)
1715 if (node1->definition)
1716 return node1;
1718 return NULL;
1721 /* Return varpool node for given symbol and check it is a function. */
1722 inline varpool_node *
1723 varpool_node::get (const_tree decl)
1725 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1726 return dyn_cast<varpool_node *> (symtab_node::get (decl));
1729 /* Walk all symbols. */
1730 #define FOR_EACH_SYMBOL(node) \
1731 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1733 /* Return first static symbol with definition. */
1734 static inline symtab_node *
1735 symtab_first_defined_symbol (void)
1737 symtab_node *node;
1739 for (node = symtab_nodes; node; node = node->next)
1740 if (node->definition)
1741 return node;
1743 return NULL;
1746 /* Walk all symbols with definitions in current unit. */
1747 #define FOR_EACH_DEFINED_SYMBOL(node) \
1748 for ((node) = symtab_first_defined_symbol (); (node); \
1749 (node) = node->next_defined_symbol ())
1751 /* Return first variable. */
1752 static inline varpool_node *
1753 varpool_first_variable (void)
1755 symtab_node *node;
1756 for (node = symtab_nodes; node; node = node->next)
1757 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1758 return vnode;
1759 return NULL;
1762 /* Return next variable after NODE. */
1763 static inline varpool_node *
1764 varpool_next_variable (varpool_node *node)
1766 symtab_node *node1 = node->next;
1767 for (; node1; node1 = node1->next)
1768 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1769 return vnode1;
1770 return NULL;
1772 /* Walk all variables. */
1773 #define FOR_EACH_VARIABLE(node) \
1774 for ((node) = varpool_first_variable (); \
1775 (node); \
1776 (node) = varpool_next_variable ((node)))
1778 /* Return first static variable with initializer. */
1779 static inline varpool_node *
1780 varpool_first_static_initializer (void)
1782 symtab_node *node;
1783 for (node = symtab_nodes; node; node = node->next)
1785 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1786 if (vnode && DECL_INITIAL (node->decl))
1787 return vnode;
1789 return NULL;
1792 /* Return next static variable with initializer after NODE. */
1793 static inline varpool_node *
1794 varpool_next_static_initializer (varpool_node *node)
1796 symtab_node *node1 = node->next;
1797 for (; node1; node1 = node1->next)
1799 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1800 if (vnode1 && DECL_INITIAL (node1->decl))
1801 return vnode1;
1803 return NULL;
1806 /* Walk all static variables with initializer set. */
1807 #define FOR_EACH_STATIC_INITIALIZER(node) \
1808 for ((node) = varpool_first_static_initializer (); (node); \
1809 (node) = varpool_next_static_initializer (node))
1811 /* Return first static variable with definition. */
1812 static inline varpool_node *
1813 varpool_first_defined_variable (void)
1815 symtab_node *node;
1816 for (node = symtab_nodes; node; node = node->next)
1818 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1819 if (vnode && vnode->definition)
1820 return vnode;
1822 return NULL;
1825 /* Return next static variable with definition after NODE. */
1826 static inline varpool_node *
1827 varpool_next_defined_variable (varpool_node *node)
1829 symtab_node *node1 = node->next;
1830 for (; node1; node1 = node1->next)
1832 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1833 if (vnode1 && vnode1->definition)
1834 return vnode1;
1836 return NULL;
1838 /* Walk all variables with definitions in current unit. */
1839 #define FOR_EACH_DEFINED_VARIABLE(node) \
1840 for ((node) = varpool_first_defined_variable (); (node); \
1841 (node) = varpool_next_defined_variable (node))
1843 /* Return first function with body defined. */
1844 static inline cgraph_node *
1845 cgraph_first_defined_function (void)
1847 symtab_node *node;
1848 for (node = symtab_nodes; node; node = node->next)
1850 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1851 if (cn && cn->definition)
1852 return cn;
1854 return NULL;
1857 /* Return next function with body defined after NODE. */
1858 static inline cgraph_node *
1859 cgraph_next_defined_function (cgraph_node *node)
1861 symtab_node *node1 = node->next;
1862 for (; node1; node1 = node1->next)
1864 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1865 if (cn1 && cn1->definition)
1866 return cn1;
1868 return NULL;
1871 /* Walk all functions with body defined. */
1872 #define FOR_EACH_DEFINED_FUNCTION(node) \
1873 for ((node) = cgraph_first_defined_function (); (node); \
1874 (node) = cgraph_next_defined_function ((node)))
1876 /* Return first function. */
1877 static inline cgraph_node *
1878 cgraph_first_function (void)
1880 symtab_node *node;
1881 for (node = symtab_nodes; node; node = node->next)
1882 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1883 return cn;
1884 return NULL;
1887 /* Return next function. */
1888 static inline cgraph_node *
1889 cgraph_next_function (cgraph_node *node)
1891 symtab_node *node1 = node->next;
1892 for (; node1; node1 = node1->next)
1893 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1894 return cn1;
1895 return NULL;
1897 /* Walk all functions. */
1898 #define FOR_EACH_FUNCTION(node) \
1899 for ((node) = cgraph_first_function (); (node); \
1900 (node) = cgraph_next_function ((node)))
1902 /* Return true when callgraph node is a function with Gimple body defined
1903 in current unit. Functions can also be define externally or they
1904 can be thunks with no Gimple representation.
1906 Note that at WPA stage, the function body may not be present in memory. */
1908 inline bool
1909 cgraph_node::has_gimple_body_p (void)
1911 return definition && !thunk.thunk_p && !alias;
1914 /* Return first function with body defined. */
1915 static inline cgraph_node *
1916 cgraph_first_function_with_gimple_body (void)
1918 symtab_node *node;
1919 for (node = symtab_nodes; node; node = node->next)
1921 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1922 if (cn && cn->has_gimple_body_p ())
1923 return cn;
1925 return NULL;
1928 /* Return next reachable static variable with initializer after NODE. */
1929 static inline cgraph_node *
1930 cgraph_next_function_with_gimple_body (cgraph_node *node)
1932 symtab_node *node1 = node->next;
1933 for (; node1; node1 = node1->next)
1935 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1936 if (cn1 && cn1->has_gimple_body_p ())
1937 return cn1;
1939 return NULL;
1942 /* Walk all functions with body defined. */
1943 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1944 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1945 (node) = cgraph_next_function_with_gimple_body (node))
1947 /* Create a new static variable of type TYPE. */
1948 tree add_new_static_var (tree type);
1950 /* Return true if iterator CSI points to nothing. */
1951 static inline bool
1952 csi_end_p (cgraph_node_set_iterator csi)
1954 return csi.index >= csi.set->nodes.length ();
1957 /* Advance iterator CSI. */
1958 static inline void
1959 csi_next (cgraph_node_set_iterator *csi)
1961 csi->index++;
1964 /* Return the node pointed to by CSI. */
1965 static inline cgraph_node *
1966 csi_node (cgraph_node_set_iterator csi)
1968 return csi.set->nodes[csi.index];
1971 /* Return an iterator to the first node in SET. */
1972 static inline cgraph_node_set_iterator
1973 csi_start (cgraph_node_set set)
1975 cgraph_node_set_iterator csi;
1977 csi.set = set;
1978 csi.index = 0;
1979 return csi;
1982 /* Return true if SET contains NODE. */
1983 static inline bool
1984 cgraph_node_in_set_p (cgraph_node *node, cgraph_node_set set)
1986 cgraph_node_set_iterator csi;
1987 csi = cgraph_node_set_find (set, node);
1988 return !csi_end_p (csi);
1991 /* Return number of nodes in SET. */
1992 static inline size_t
1993 cgraph_node_set_size (cgraph_node_set set)
1995 return set->nodes.length ();
1998 /* Return true if iterator VSI points to nothing. */
1999 static inline bool
2000 vsi_end_p (varpool_node_set_iterator vsi)
2002 return vsi.index >= vsi.set->nodes.length ();
2005 /* Advance iterator VSI. */
2006 static inline void
2007 vsi_next (varpool_node_set_iterator *vsi)
2009 vsi->index++;
2012 /* Return the node pointed to by VSI. */
2013 static inline varpool_node *
2014 vsi_node (varpool_node_set_iterator vsi)
2016 return vsi.set->nodes[vsi.index];
2019 /* Return an iterator to the first node in SET. */
2020 static inline varpool_node_set_iterator
2021 vsi_start (varpool_node_set set)
2023 varpool_node_set_iterator vsi;
2025 vsi.set = set;
2026 vsi.index = 0;
2027 return vsi;
2030 /* Return number of nodes in SET. */
2031 static inline size_t
2032 varpool_node_set_size (varpool_node_set set)
2034 return set->nodes.length ();
2037 /* Uniquize all constants that appear in memory.
2038 Each constant in memory thus far output is recorded
2039 in `const_desc_table'. */
2041 struct GTY(()) constant_descriptor_tree {
2042 /* A MEM for the constant. */
2043 rtx rtl;
2045 /* The value of the constant. */
2046 tree value;
2048 /* Hash of value. Computing the hash from value each time
2049 hashfn is called can't work properly, as that means recursive
2050 use of the hash table during hash table expansion. */
2051 hashval_t hash;
2054 /* Return true if set is nonempty. */
2055 static inline bool
2056 cgraph_node_set_nonempty_p (cgraph_node_set set)
2058 return !set->nodes.is_empty ();
2061 /* Return true if set is nonempty. */
2062 static inline bool
2063 varpool_node_set_nonempty_p (varpool_node_set set)
2065 return !set->nodes.is_empty ();
2068 /* Return true when function is only called directly or it has alias.
2069 i.e. it is not externally visible, address was not taken and
2070 it is not used in any other non-standard way. */
2072 inline bool
2073 cgraph_node::only_called_directly_or_aliased_p (void)
2075 gcc_assert (!global.inlined_to);
2076 return (!force_output && !address_taken
2077 && !used_from_other_partition
2078 && !DECL_VIRTUAL_P (decl)
2079 && !DECL_STATIC_CONSTRUCTOR (decl)
2080 && !DECL_STATIC_DESTRUCTOR (decl)
2081 && !externally_visible);
2084 /* Return true when variable can be removed from variable pool
2085 if all direct calls are eliminated. */
2087 inline bool
2088 varpool_node::can_remove_if_no_refs_p (void)
2090 if (DECL_EXTERNAL (decl))
2091 return true;
2092 return (!force_output && !used_from_other_partition
2093 && ((DECL_COMDAT (decl)
2094 && !forced_by_abi
2095 && !used_from_object_file_p ())
2096 || !externally_visible
2097 || DECL_HAS_VALUE_EXPR_P (decl)));
2100 /* Return true when all references to variable must be visible in ipa_ref_list.
2101 i.e. if the variable is not externally visible or not used in some magic
2102 way (asm statement or such).
2103 The magic uses are all summarized in force_output flag. */
2105 inline bool
2106 varpool_node::all_refs_explicit_p ()
2108 return (definition
2109 && !externally_visible
2110 && !used_from_other_partition
2111 && !force_output);
2114 /* Constant pool accessor function. */
2115 htab_t constant_pool_htab (void);
2117 /* Return node that alias is aliasing. */
2119 inline cgraph_node *
2120 cgraph_node::get_alias_target (void)
2122 return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ());
2125 /* Return node that alias is aliasing. */
2127 inline varpool_node *
2128 varpool_node::get_alias_target (void)
2130 return dyn_cast <varpool_node *> (symtab_node::get_alias_target ());
2133 /* Given function symbol, walk the alias chain to return the function node
2134 is alias of. Do not walk through thunks.
2135 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
2137 inline cgraph_node *
2138 cgraph_node::ultimate_alias_target (enum availability *availability)
2140 cgraph_node *n = dyn_cast <cgraph_node *> (symtab_node::ultimate_alias_target
2141 (availability));
2142 if (!n && availability)
2143 *availability = AVAIL_NOT_AVAILABLE;
2144 return n;
2147 /* For given variable pool node, walk the alias chain to return the function
2148 the variable is alias of. Do not walk through thunks.
2149 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
2151 inline varpool_node *
2152 varpool_node::ultimate_alias_target (availability *availability)
2154 varpool_node *n = dyn_cast <varpool_node *>
2155 (symtab_node::ultimate_alias_target (availability));
2157 if (!n && availability)
2158 *availability = AVAIL_NOT_AVAILABLE;
2159 return n;
2162 /* Return true when the edge E represents a direct recursion. */
2163 static inline bool
2164 cgraph_edge_recursive_p (struct cgraph_edge *e)
2166 cgraph_node *callee = e->callee->ultimate_alias_target ();
2167 if (e->caller->global.inlined_to)
2168 return e->caller->global.inlined_to->decl == callee->decl;
2169 else
2170 return e->caller->decl == callee->decl;
2173 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
2174 static inline bool
2175 decl_is_tm_clone (const_tree fndecl)
2177 cgraph_node *n = cgraph_node::get (fndecl);
2178 if (n)
2179 return n->tm_clone;
2180 return false;
2183 /* Likewise indicate that a node is needed, i.e. reachable via some
2184 external means. */
2186 inline void
2187 cgraph_node::mark_force_output (void)
2189 force_output = 1;
2190 gcc_checking_assert (!global.inlined_to);
2193 #endif /* GCC_CGRAPH_H */