2014-07-31 Robert Dewar <dewar@adacore.com>
[official-gcc.git] / gcc / cgraph.h
blobd8651e2f6f390730bdb7814cd07e8bcc4423fb85
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, speculative_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, speculative_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;
1273 unsigned int speculative_maybe_derived_type : 1;
1276 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
1277 /* Expected number of executions: calculated in profile.c. */
1278 gcov_type count;
1279 cgraph_node *caller;
1280 cgraph_node *callee;
1281 struct cgraph_edge *prev_caller;
1282 struct cgraph_edge *next_caller;
1283 struct cgraph_edge *prev_callee;
1284 struct cgraph_edge *next_callee;
1285 gimple call_stmt;
1286 /* Additional information about an indirect call. Not cleared when an edge
1287 becomes direct. */
1288 struct cgraph_indirect_call_info *indirect_info;
1289 PTR GTY ((skip (""))) aux;
1290 /* When equal to CIF_OK, inline this call. Otherwise, points to the
1291 explanation why function was not inlined. */
1292 enum cgraph_inline_failed_t inline_failed;
1293 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
1294 when the function is serialized in. */
1295 unsigned int lto_stmt_uid;
1296 /* Expected frequency of executions within the function.
1297 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
1298 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
1299 int frequency;
1300 /* Unique id of the edge. */
1301 int uid;
1302 /* Whether this edge was made direct by indirect inlining. */
1303 unsigned int indirect_inlining_edge : 1;
1304 /* Whether this edge describes an indirect call with an undetermined
1305 callee. */
1306 unsigned int indirect_unknown_callee : 1;
1307 /* Whether this edge is still a dangling */
1308 /* True if the corresponding CALL stmt cannot be inlined. */
1309 unsigned int call_stmt_cannot_inline_p : 1;
1310 /* Can this call throw externally? */
1311 unsigned int can_throw_external : 1;
1312 /* Edges with SPECULATIVE flag represents indirect calls that was
1313 speculatively turned into direct (i.e. by profile feedback).
1314 The final code sequence will have form:
1316 if (call_target == expected_fn)
1317 expected_fn ();
1318 else
1319 call_target ();
1321 Every speculative call is represented by three components attached
1322 to a same call statement:
1323 1) a direct call (to expected_fn)
1324 2) an indirect call (to call_target)
1325 3) a IPA_REF_ADDR refrence to expected_fn.
1327 Optimizers may later redirect direct call to clone, so 1) and 3)
1328 do not need to necesarily agree with destination. */
1329 unsigned int speculative : 1;
1332 #define CGRAPH_FREQ_BASE 1000
1333 #define CGRAPH_FREQ_MAX 100000
1335 /* The varpool data structure.
1336 Each static variable decl has assigned varpool_node. */
1338 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
1339 public:
1340 /* Dump given varpool node to F. */
1341 void dump (FILE *f);
1343 /* Dump given varpool node to stderr. */
1344 void DEBUG_FUNCTION debug (void);
1346 /* Remove variable from symbol table. */
1347 void remove (void);
1349 /* Remove node initializer when it is no longer needed. */
1350 void remove_initializer (void);
1352 void analyze (void);
1354 /* Return variable availability. */
1355 availability get_availability (void);
1357 /* When doing LTO, read variable's constructor from disk if
1358 it is not already present. */
1359 tree get_constructor (void);
1361 /* Return true if variable has constructor that can be used for folding. */
1362 bool ctor_useable_for_folding_p (void);
1364 /* For given variable pool node, walk the alias chain to return the function
1365 the variable is alias of. Do not walk through thunks.
1366 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1367 inline varpool_node *ultimate_alias_target
1368 (availability *availability = NULL);
1370 /* Return node that alias is aliasing. */
1371 inline varpool_node *get_alias_target (void);
1373 /* Output one variable, if necessary. Return whether we output it. */
1374 bool assemble_decl (void);
1376 /* For variables in named sections make sure get_variable_section
1377 is called before we switch to those sections. Then section
1378 conflicts between read-only and read-only requiring relocations
1379 sections can be resolved. */
1380 void finalize_named_section_flags (void);
1382 /* Call calback on varpool symbol and aliases associated to varpool symbol.
1383 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1384 skipped. */
1385 bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *),
1386 void *data,
1387 bool include_overwritable);
1389 /* Return true when variable should be considered externally visible. */
1390 bool externally_visible_p (void);
1392 /* Return true when all references to variable must be visible
1393 in ipa_ref_list.
1394 i.e. if the variable is not externally visible or not used in some magic
1395 way (asm statement or such).
1396 The magic uses are all summarized in force_output flag. */
1397 inline bool all_refs_explicit_p ();
1399 /* Return true when variable can be removed from variable pool
1400 if all direct calls are eliminated. */
1401 inline bool can_remove_if_no_refs_p (void);
1403 /* Return varpool node for given symbol and check it is a function. */
1404 static inline varpool_node *get (const_tree decl);
1406 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct
1407 the middle end to output the variable to asm file, if needed or externally
1408 visible. */
1409 static void finalize_decl (tree decl);
1411 /* Output all variables enqueued to be assembled. */
1412 static bool output_variables (void);
1414 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
1415 Extra name aliases are output whenever DECL is output. */
1416 static varpool_node * create_extra_name_alias (tree alias, tree decl);
1418 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
1419 Extra name aliases are output whenever DECL is output. */
1420 static varpool_node * create_alias (tree, tree);
1422 /* Dump the variable pool to F. */
1423 static void dump_varpool (FILE *f);
1425 /* Dump the variable pool to stderr. */
1426 static void DEBUG_FUNCTION debug_varpool (void);
1428 /* Allocate new callgraph node and insert it into basic data structures. */
1429 static varpool_node *create_empty (void);
1431 /* Return varpool node assigned to DECL. Create new one when needed. */
1432 static varpool_node *get_create (tree decl);
1434 /* Given an assembler name, lookup node. */
1435 static varpool_node *get_for_asmname (tree asmname);
1437 /* Set when variable is scheduled to be assembled. */
1438 unsigned output : 1;
1440 /* Set if the variable is dynamically initialized, except for
1441 function local statics. */
1442 unsigned dynamically_initialized : 1;
1444 ENUM_BITFIELD(tls_model) tls_model : 3;
1446 /* Set if the variable is known to be used by single function only.
1447 This is computed by ipa_signle_use pass and used by late optimizations
1448 in places where optimization would be valid for local static variable
1449 if we did not do any inter-procedural code movement. */
1450 unsigned used_by_single_function : 1;
1452 private:
1453 /* Assemble thunks and aliases associated to varpool node. */
1454 void assemble_aliases (void);
1457 /* Every top level asm statement is put into a asm_node. */
1459 struct GTY(()) asm_node {
1460 /* Next asm node. */
1461 struct asm_node *next;
1462 /* String for this asm node. */
1463 tree asm_str;
1464 /* Ordering of all cgraph nodes. */
1465 int order;
1468 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
1470 template <>
1471 template <>
1472 inline bool
1473 is_a_helper <cgraph_node *>::test (symtab_node *p)
1475 return p && p->type == SYMTAB_FUNCTION;
1478 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
1480 template <>
1481 template <>
1482 inline bool
1483 is_a_helper <varpool_node *>::test (symtab_node *p)
1485 return p && p->type == SYMTAB_VARIABLE;
1488 extern GTY(()) symtab_node *symtab_nodes;
1489 extern GTY(()) int cgraph_n_nodes;
1490 extern GTY(()) int cgraph_max_uid;
1491 extern GTY(()) int cgraph_edge_max_uid;
1492 extern bool cgraph_global_info_ready;
1493 enum cgraph_state
1495 /* Frontend is parsing and finalizing functions. */
1496 CGRAPH_STATE_PARSING,
1497 /* Callgraph is being constructed. It is safe to add new functions. */
1498 CGRAPH_STATE_CONSTRUCTION,
1499 /* Callgraph is being at LTO time. */
1500 CGRAPH_LTO_STREAMING,
1501 /* Callgraph is built and IPA passes are being run. */
1502 CGRAPH_STATE_IPA,
1503 /* Callgraph is built and all functions are transformed to SSA form. */
1504 CGRAPH_STATE_IPA_SSA,
1505 /* Functions are now ordered and being passed to RTL expanders. */
1506 CGRAPH_STATE_EXPANSION,
1507 /* All cgraph expansion is done. */
1508 CGRAPH_STATE_FINISHED
1510 extern enum cgraph_state cgraph_state;
1511 extern bool cgraph_function_flags_ready;
1512 extern cgraph_node_set cgraph_new_nodes;
1514 extern GTY(()) struct asm_node *asm_nodes;
1515 extern GTY(()) int symtab_order;
1516 extern bool cpp_implicit_aliases_done;
1518 /* In symtab.c */
1519 symtab_node *symtab_node_for_asm (const_tree asmname);
1521 /* In cgraph.c */
1522 void release_function_body (tree);
1523 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
1524 void cgraph_remove_edge (struct cgraph_edge *);
1526 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
1527 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
1528 struct cgraph_local_info *cgraph_local_info (tree);
1529 struct cgraph_global_info *cgraph_global_info (tree);
1530 struct cgraph_rtl_info *cgraph_rtl_info (tree);
1531 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
1532 struct cgraph_edge *);
1534 bool cgraph_function_possibly_inlined_p (tree);
1535 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
1536 void cgraph_redirect_edge_callee (struct cgraph_edge *, cgraph_node *);
1537 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *,
1538 cgraph_node *);
1540 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
1541 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
1543 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
1544 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
1545 typedef void (*cgraph_node_hook)(cgraph_node *, void *);
1546 typedef void (*varpool_node_hook)(varpool_node *, void *);
1547 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
1548 void *);
1549 typedef void (*cgraph_2node_hook)(cgraph_node *, cgraph_node *,
1550 void *);
1551 struct cgraph_edge_hook_list;
1552 struct cgraph_node_hook_list;
1553 struct varpool_node_hook_list;
1554 struct cgraph_2edge_hook_list;
1555 struct cgraph_2node_hook_list;
1556 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
1557 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
1558 cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
1559 void *);
1560 void cgraph_remove_node_removal_hook (cgraph_node_hook_list *);
1561 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
1562 void *);
1563 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
1564 cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
1565 void *);
1566 void cgraph_remove_function_insertion_hook (cgraph_node_hook_list *);
1567 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
1568 void *);
1569 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
1570 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
1571 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
1572 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
1573 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
1574 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
1575 struct cgraph_edge *
1576 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
1577 cgraph_node *,
1578 gcov_type, int);
1579 void cgraph_speculative_call_info (struct cgraph_edge *,
1580 struct cgraph_edge *&,
1581 struct cgraph_edge *&,
1582 struct ipa_ref *&);
1583 extern bool gimple_check_call_matching_types (gimple, tree, bool);
1585 /* In cgraphunit.c */
1586 struct asm_node *add_asm_node (tree);
1587 extern FILE *cgraph_dump_file;
1588 void cgraph_finalize_function (tree, bool);
1589 void finalize_compilation_unit (void);
1590 void compile (void);
1591 void init_cgraph (void);
1592 void cgraph_process_new_functions (void);
1593 void cgraph_process_same_body_aliases (void);
1594 /* Initialize datastructures so DECL is a function in lowered gimple form.
1595 IN_SSA is true if the gimple is in SSA. */
1596 basic_block init_lowered_empty_function (tree, bool);
1598 /* In cgraphclones.c */
1600 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
1601 cgraph_node *, gimple,
1602 unsigned, gcov_type, int, bool);
1603 tree clone_function_name (tree decl, const char *);
1605 void cgraph_materialize_all_clones (void);
1606 void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *,
1607 bool, bitmap, bool, bitmap, basic_block);
1608 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
1610 /* In cgraphbuild.c */
1611 unsigned int rebuild_cgraph_edges (void);
1612 void cgraph_rebuild_references (void);
1613 int compute_call_stmt_bb_frequency (tree, basic_block bb);
1614 void record_references_in_initializer (tree, bool);
1616 /* In ipa.c */
1617 bool symtab_remove_unreachable_nodes (bool, FILE *);
1618 cgraph_node_set cgraph_node_set_new (void);
1619 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
1620 cgraph_node *);
1621 void cgraph_node_set_add (cgraph_node_set, cgraph_node *);
1622 void cgraph_node_set_remove (cgraph_node_set, cgraph_node *);
1623 void dump_cgraph_node_set (FILE *, cgraph_node_set);
1624 void debug_cgraph_node_set (cgraph_node_set);
1625 void free_cgraph_node_set (cgraph_node_set);
1626 void cgraph_build_static_cdtor (char which, tree body, int priority);
1628 varpool_node_set varpool_node_set_new (void);
1629 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
1630 varpool_node *);
1631 void varpool_node_set_add (varpool_node_set, varpool_node *);
1632 void varpool_node_set_remove (varpool_node_set, varpool_node *);
1633 void dump_varpool_node_set (FILE *, varpool_node_set);
1634 void debug_varpool_node_set (varpool_node_set);
1635 void free_varpool_node_set (varpool_node_set);
1636 void ipa_discover_readonly_nonaddressable_vars (void);
1638 /* In predict.c */
1639 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
1641 /* In varpool.c */
1642 void varpool_reset_queue (void);
1643 tree ctor_for_folding (tree);
1644 void varpool_add_new_variable (tree);
1645 void symtab_initialize_asm_name_hash (void);
1646 void symtab_prevail_in_asm_name_hash (symtab_node *node);
1648 /* In cgraph.c */
1649 extern void change_decl_assembler_name (tree, tree);
1651 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1652 or abstract function kept for debug info purposes only. */
1653 inline bool
1654 symtab_node::real_symbol_p (void)
1656 cgraph_node *cnode;
1658 if (DECL_ABSTRACT (decl))
1659 return false;
1660 if (!is_a <cgraph_node *> (this))
1661 return true;
1662 cnode = dyn_cast <cgraph_node *> (this);
1663 if (cnode->global.inlined_to)
1664 return false;
1665 return true;
1668 /* Return true if DECL should have entry in symbol table if used.
1669 Those are functions and static & external veriables*/
1671 static inline bool
1672 decl_in_symtab_p (const_tree decl)
1674 return (TREE_CODE (decl) == FUNCTION_DECL
1675 || (TREE_CODE (decl) == VAR_DECL
1676 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))));
1679 inline bool
1680 symtab_node::in_same_comdat_group_p (symtab_node *target)
1682 symtab_node *source = this;
1684 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
1686 if (cn->global.inlined_to)
1687 source = cn->global.inlined_to;
1689 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
1691 if (cn->global.inlined_to)
1692 target = cn->global.inlined_to;
1695 return source->get_comdat_group () == target->get_comdat_group ();
1698 /* Return node that alias is aliasing. */
1700 inline symtab_node *
1701 symtab_node::get_alias_target (void)
1703 struct ipa_ref *ref = NULL;
1704 iterate_reference (0, ref);
1705 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1706 return ref->referred;
1709 /* Return next reachable static symbol with initializer after the node. */
1710 inline symtab_node *
1711 symtab_node::next_defined_symbol (void)
1713 symtab_node *node1 = next;
1715 for (; node1; node1 = node1->next)
1716 if (node1->definition)
1717 return node1;
1719 return NULL;
1722 /* Return varpool node for given symbol and check it is a function. */
1723 inline varpool_node *
1724 varpool_node::get (const_tree decl)
1726 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1727 return dyn_cast<varpool_node *> (symtab_node::get (decl));
1730 /* Walk all symbols. */
1731 #define FOR_EACH_SYMBOL(node) \
1732 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1734 /* Return first static symbol with definition. */
1735 static inline symtab_node *
1736 symtab_first_defined_symbol (void)
1738 symtab_node *node;
1740 for (node = symtab_nodes; node; node = node->next)
1741 if (node->definition)
1742 return node;
1744 return NULL;
1747 /* Walk all symbols with definitions in current unit. */
1748 #define FOR_EACH_DEFINED_SYMBOL(node) \
1749 for ((node) = symtab_first_defined_symbol (); (node); \
1750 (node) = node->next_defined_symbol ())
1752 /* Return first variable. */
1753 static inline varpool_node *
1754 varpool_first_variable (void)
1756 symtab_node *node;
1757 for (node = symtab_nodes; node; node = node->next)
1758 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1759 return vnode;
1760 return NULL;
1763 /* Return next variable after NODE. */
1764 static inline varpool_node *
1765 varpool_next_variable (varpool_node *node)
1767 symtab_node *node1 = node->next;
1768 for (; node1; node1 = node1->next)
1769 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1770 return vnode1;
1771 return NULL;
1773 /* Walk all variables. */
1774 #define FOR_EACH_VARIABLE(node) \
1775 for ((node) = varpool_first_variable (); \
1776 (node); \
1777 (node) = varpool_next_variable ((node)))
1779 /* Return first static variable with initializer. */
1780 static inline varpool_node *
1781 varpool_first_static_initializer (void)
1783 symtab_node *node;
1784 for (node = symtab_nodes; node; node = node->next)
1786 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1787 if (vnode && DECL_INITIAL (node->decl))
1788 return vnode;
1790 return NULL;
1793 /* Return next static variable with initializer after NODE. */
1794 static inline varpool_node *
1795 varpool_next_static_initializer (varpool_node *node)
1797 symtab_node *node1 = node->next;
1798 for (; node1; node1 = node1->next)
1800 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1801 if (vnode1 && DECL_INITIAL (node1->decl))
1802 return vnode1;
1804 return NULL;
1807 /* Walk all static variables with initializer set. */
1808 #define FOR_EACH_STATIC_INITIALIZER(node) \
1809 for ((node) = varpool_first_static_initializer (); (node); \
1810 (node) = varpool_next_static_initializer (node))
1812 /* Return first static variable with definition. */
1813 static inline varpool_node *
1814 varpool_first_defined_variable (void)
1816 symtab_node *node;
1817 for (node = symtab_nodes; node; node = node->next)
1819 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1820 if (vnode && vnode->definition)
1821 return vnode;
1823 return NULL;
1826 /* Return next static variable with definition after NODE. */
1827 static inline varpool_node *
1828 varpool_next_defined_variable (varpool_node *node)
1830 symtab_node *node1 = node->next;
1831 for (; node1; node1 = node1->next)
1833 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1834 if (vnode1 && vnode1->definition)
1835 return vnode1;
1837 return NULL;
1839 /* Walk all variables with definitions in current unit. */
1840 #define FOR_EACH_DEFINED_VARIABLE(node) \
1841 for ((node) = varpool_first_defined_variable (); (node); \
1842 (node) = varpool_next_defined_variable (node))
1844 /* Return first function with body defined. */
1845 static inline cgraph_node *
1846 cgraph_first_defined_function (void)
1848 symtab_node *node;
1849 for (node = symtab_nodes; node; node = node->next)
1851 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1852 if (cn && cn->definition)
1853 return cn;
1855 return NULL;
1858 /* Return next function with body defined after NODE. */
1859 static inline cgraph_node *
1860 cgraph_next_defined_function (cgraph_node *node)
1862 symtab_node *node1 = node->next;
1863 for (; node1; node1 = node1->next)
1865 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1866 if (cn1 && cn1->definition)
1867 return cn1;
1869 return NULL;
1872 /* Walk all functions with body defined. */
1873 #define FOR_EACH_DEFINED_FUNCTION(node) \
1874 for ((node) = cgraph_first_defined_function (); (node); \
1875 (node) = cgraph_next_defined_function ((node)))
1877 /* Return first function. */
1878 static inline cgraph_node *
1879 cgraph_first_function (void)
1881 symtab_node *node;
1882 for (node = symtab_nodes; node; node = node->next)
1883 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1884 return cn;
1885 return NULL;
1888 /* Return next function. */
1889 static inline cgraph_node *
1890 cgraph_next_function (cgraph_node *node)
1892 symtab_node *node1 = node->next;
1893 for (; node1; node1 = node1->next)
1894 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1895 return cn1;
1896 return NULL;
1898 /* Walk all functions. */
1899 #define FOR_EACH_FUNCTION(node) \
1900 for ((node) = cgraph_first_function (); (node); \
1901 (node) = cgraph_next_function ((node)))
1903 /* Return true when callgraph node is a function with Gimple body defined
1904 in current unit. Functions can also be define externally or they
1905 can be thunks with no Gimple representation.
1907 Note that at WPA stage, the function body may not be present in memory. */
1909 inline bool
1910 cgraph_node::has_gimple_body_p (void)
1912 return definition && !thunk.thunk_p && !alias;
1915 /* Return first function with body defined. */
1916 static inline cgraph_node *
1917 cgraph_first_function_with_gimple_body (void)
1919 symtab_node *node;
1920 for (node = symtab_nodes; node; node = node->next)
1922 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1923 if (cn && cn->has_gimple_body_p ())
1924 return cn;
1926 return NULL;
1929 /* Return next reachable static variable with initializer after NODE. */
1930 static inline cgraph_node *
1931 cgraph_next_function_with_gimple_body (cgraph_node *node)
1933 symtab_node *node1 = node->next;
1934 for (; node1; node1 = node1->next)
1936 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1937 if (cn1 && cn1->has_gimple_body_p ())
1938 return cn1;
1940 return NULL;
1943 /* Walk all functions with body defined. */
1944 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1945 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1946 (node) = cgraph_next_function_with_gimple_body (node))
1948 /* Create a new static variable of type TYPE. */
1949 tree add_new_static_var (tree type);
1951 /* Return true if iterator CSI points to nothing. */
1952 static inline bool
1953 csi_end_p (cgraph_node_set_iterator csi)
1955 return csi.index >= csi.set->nodes.length ();
1958 /* Advance iterator CSI. */
1959 static inline void
1960 csi_next (cgraph_node_set_iterator *csi)
1962 csi->index++;
1965 /* Return the node pointed to by CSI. */
1966 static inline cgraph_node *
1967 csi_node (cgraph_node_set_iterator csi)
1969 return csi.set->nodes[csi.index];
1972 /* Return an iterator to the first node in SET. */
1973 static inline cgraph_node_set_iterator
1974 csi_start (cgraph_node_set set)
1976 cgraph_node_set_iterator csi;
1978 csi.set = set;
1979 csi.index = 0;
1980 return csi;
1983 /* Return true if SET contains NODE. */
1984 static inline bool
1985 cgraph_node_in_set_p (cgraph_node *node, cgraph_node_set set)
1987 cgraph_node_set_iterator csi;
1988 csi = cgraph_node_set_find (set, node);
1989 return !csi_end_p (csi);
1992 /* Return number of nodes in SET. */
1993 static inline size_t
1994 cgraph_node_set_size (cgraph_node_set set)
1996 return set->nodes.length ();
1999 /* Return true if iterator VSI points to nothing. */
2000 static inline bool
2001 vsi_end_p (varpool_node_set_iterator vsi)
2003 return vsi.index >= vsi.set->nodes.length ();
2006 /* Advance iterator VSI. */
2007 static inline void
2008 vsi_next (varpool_node_set_iterator *vsi)
2010 vsi->index++;
2013 /* Return the node pointed to by VSI. */
2014 static inline varpool_node *
2015 vsi_node (varpool_node_set_iterator vsi)
2017 return vsi.set->nodes[vsi.index];
2020 /* Return an iterator to the first node in SET. */
2021 static inline varpool_node_set_iterator
2022 vsi_start (varpool_node_set set)
2024 varpool_node_set_iterator vsi;
2026 vsi.set = set;
2027 vsi.index = 0;
2028 return vsi;
2031 /* Return number of nodes in SET. */
2032 static inline size_t
2033 varpool_node_set_size (varpool_node_set set)
2035 return set->nodes.length ();
2038 /* Uniquize all constants that appear in memory.
2039 Each constant in memory thus far output is recorded
2040 in `const_desc_table'. */
2042 struct GTY(()) constant_descriptor_tree {
2043 /* A MEM for the constant. */
2044 rtx rtl;
2046 /* The value of the constant. */
2047 tree value;
2049 /* Hash of value. Computing the hash from value each time
2050 hashfn is called can't work properly, as that means recursive
2051 use of the hash table during hash table expansion. */
2052 hashval_t hash;
2055 /* Return true if set is nonempty. */
2056 static inline bool
2057 cgraph_node_set_nonempty_p (cgraph_node_set set)
2059 return !set->nodes.is_empty ();
2062 /* Return true if set is nonempty. */
2063 static inline bool
2064 varpool_node_set_nonempty_p (varpool_node_set set)
2066 return !set->nodes.is_empty ();
2069 /* Return true when function is only called directly or it has alias.
2070 i.e. it is not externally visible, address was not taken and
2071 it is not used in any other non-standard way. */
2073 inline bool
2074 cgraph_node::only_called_directly_or_aliased_p (void)
2076 gcc_assert (!global.inlined_to);
2077 return (!force_output && !address_taken
2078 && !used_from_other_partition
2079 && !DECL_VIRTUAL_P (decl)
2080 && !DECL_STATIC_CONSTRUCTOR (decl)
2081 && !DECL_STATIC_DESTRUCTOR (decl)
2082 && !externally_visible);
2085 /* Return true when variable can be removed from variable pool
2086 if all direct calls are eliminated. */
2088 inline bool
2089 varpool_node::can_remove_if_no_refs_p (void)
2091 if (DECL_EXTERNAL (decl))
2092 return true;
2093 return (!force_output && !used_from_other_partition
2094 && ((DECL_COMDAT (decl)
2095 && !forced_by_abi
2096 && !used_from_object_file_p ())
2097 || !externally_visible
2098 || DECL_HAS_VALUE_EXPR_P (decl)));
2101 /* Return true when all references to variable must be visible in ipa_ref_list.
2102 i.e. if the variable is not externally visible or not used in some magic
2103 way (asm statement or such).
2104 The magic uses are all summarized in force_output flag. */
2106 inline bool
2107 varpool_node::all_refs_explicit_p ()
2109 return (definition
2110 && !externally_visible
2111 && !used_from_other_partition
2112 && !force_output);
2115 /* Constant pool accessor function. */
2116 htab_t constant_pool_htab (void);
2118 /* Return node that alias is aliasing. */
2120 inline cgraph_node *
2121 cgraph_node::get_alias_target (void)
2123 return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ());
2126 /* Return node that alias is aliasing. */
2128 inline varpool_node *
2129 varpool_node::get_alias_target (void)
2131 return dyn_cast <varpool_node *> (symtab_node::get_alias_target ());
2134 /* Given function symbol, walk the alias chain to return the function node
2135 is alias of. Do not walk through thunks.
2136 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
2138 inline cgraph_node *
2139 cgraph_node::ultimate_alias_target (enum availability *availability)
2141 cgraph_node *n = dyn_cast <cgraph_node *> (symtab_node::ultimate_alias_target
2142 (availability));
2143 if (!n && availability)
2144 *availability = AVAIL_NOT_AVAILABLE;
2145 return n;
2148 /* For given variable pool node, walk the alias chain to return the function
2149 the variable is alias of. Do not walk through thunks.
2150 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
2152 inline varpool_node *
2153 varpool_node::ultimate_alias_target (availability *availability)
2155 varpool_node *n = dyn_cast <varpool_node *>
2156 (symtab_node::ultimate_alias_target (availability));
2158 if (!n && availability)
2159 *availability = AVAIL_NOT_AVAILABLE;
2160 return n;
2163 /* Return true when the edge E represents a direct recursion. */
2164 static inline bool
2165 cgraph_edge_recursive_p (struct cgraph_edge *e)
2167 cgraph_node *callee = e->callee->ultimate_alias_target ();
2168 if (e->caller->global.inlined_to)
2169 return e->caller->global.inlined_to->decl == callee->decl;
2170 else
2171 return e->caller->decl == callee->decl;
2174 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
2175 static inline bool
2176 decl_is_tm_clone (const_tree fndecl)
2178 cgraph_node *n = cgraph_node::get (fndecl);
2179 if (n)
2180 return n->tm_clone;
2181 return false;
2184 /* Likewise indicate that a node is needed, i.e. reachable via some
2185 external means. */
2187 inline void
2188 cgraph_node::mark_force_output (void)
2190 force_output = 1;
2191 gcc_checking_assert (!global.inlined_to);
2194 #endif /* GCC_CGRAPH_H */