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
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
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/>. */
25 #include "plugin-api.h"
27 #include "basic-block.h"
31 /* Symbol table consists of functions and variables.
32 TODO: add labels and CONST_DECLs. */
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
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
51 typedef struct section_hash_entry_d section_hash_entry
;
53 /* Base of all entries in the symbol table.
54 The symtab_node is inherited by cgraph and varpol nodes. */
55 class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
56 chain_next ("%h.next"), chain_prev ("%h.previous")))
61 const char *name () const;
63 /* Return asm name. */
64 const char * asm_name () const;
66 /* Type of the symbol. */
67 ENUM_BITFIELD (symtab_type
) type
: 8;
69 /* The symbols resolution. */
70 ENUM_BITFIELD (ld_plugin_symbol_resolution
) resolution
: 8;
72 /*** Flags representing the symbol type. ***/
74 /* True when symbol corresponds to a definition in current unit.
75 set via cgraph_finalize_function or varpool_finalize_decl */
76 unsigned definition
: 1;
77 /* True when symbol is an alias.
78 Set by assemble_alias. */
80 /* True when alias is a weakref. */
82 /* C++ frontend produce same body aliases and extra name aliases for
83 virtual functions and vtables that are obviously equivalent.
84 Those aliases are bit special, especially because C++ frontend
85 visibility code is so ugly it can not get them right at first time
86 and their visibility needs to be copied from their "masters" at
87 the end of parsing. */
88 unsigned cpp_implicit_alias
: 1;
89 /* Set once the definition was analyzed. The list of references and
90 other properties are built during analysis. */
91 unsigned analyzed
: 1;
92 /* Set for write-only variables. */
93 unsigned writeonly
: 1;
96 /*** Visibility and linkage flags. ***/
98 /* Set when function is visible by other units. */
99 unsigned externally_visible
: 1;
100 /* The symbol will be assumed to be used in an invisible way (like
101 by an toplevel asm statement). */
102 unsigned force_output
: 1;
103 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
104 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
105 to static and it does not inhibit optimization. */
106 unsigned forced_by_abi
: 1;
107 /* True when the name is known to be unique and thus it does not need mangling. */
108 unsigned unique_name
: 1;
109 /* Specify whether the section was set by user or by
110 compiler via -ffunction-sections. */
111 unsigned implicit_section
: 1;
112 /* True when body and other characteristics have been removed by
113 symtab_remove_unreachable_nodes. */
114 unsigned body_removed
: 1;
116 /*** WHOPR Partitioning flags.
117 These flags are used at ltrans stage when only part of the callgraph is
120 /* Set when variable is used from other LTRANS partition. */
121 unsigned used_from_other_partition
: 1;
122 /* Set when function is available in the other LTRANS partition.
123 During WPA output it is used to mark nodes that are present in
124 multiple partitions. */
125 unsigned in_other_partition
: 1;
129 /*** other flags. ***/
131 /* Set when symbol has address taken. */
132 unsigned address_taken
: 1;
133 /* Set when init priority is set. */
134 unsigned in_init_priority_hash
: 1;
137 /* Ordering of all symtab entries. */
140 /* Declaration representing the symbol. */
143 /* Linked list of symbol table entries starting with symtab_nodes. */
145 symtab_node
*previous
;
147 /* Linked list of symbols with the same asm name. There may be multiple
148 entries for single symbol name during LTO, because symbols are renamed
149 only after partitioning.
151 Because inline clones are kept in the assembler name has, they also produce
154 There are also several long standing bugs where frontends and builtin
155 code produce duplicated decls. */
156 symtab_node
*next_sharing_asm_name
;
157 symtab_node
*previous_sharing_asm_name
;
159 /* Circular list of nodes in the same comdat group if non-NULL. */
160 symtab_node
*same_comdat_group
;
162 /* Return comdat group. */
163 tree
get_comdat_group ()
165 return x_comdat_group
;
168 /* Return comdat group as identifier_node. */
169 tree
get_comdat_group_id ()
171 if (x_comdat_group
&& TREE_CODE (x_comdat_group
) != IDENTIFIER_NODE
)
172 x_comdat_group
= DECL_ASSEMBLER_NAME (x_comdat_group
);
173 return x_comdat_group
;
176 /* Set comdat group. */
177 void set_comdat_group (tree group
)
179 gcc_checking_assert (!group
|| TREE_CODE (group
) == IDENTIFIER_NODE
181 x_comdat_group
= group
;
184 /* Return section as string. */
185 const char * get_section ()
189 return x_section
->name
;
192 /* Return ipa reference from this symtab_node to
193 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
194 of the use and STMT the statement (if it exists). */
195 struct ipa_ref
*add_reference (symtab_node
*referred_node
,
196 enum ipa_ref_use use_type
);
198 /* Return ipa reference from this symtab_node to
199 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
200 of the use and STMT the statement (if it exists). */
201 struct ipa_ref
*add_reference (symtab_node
*referred_node
,
202 enum ipa_ref_use use_type
, gimple stmt
);
204 /* If VAL is a reference to a function or a variable, add a reference from
205 this symtab_node to the corresponding symbol table node. USE_TYPE specify
206 type of the use and STMT the statement (if it exists). Return the new
207 reference or NULL if none was created. */
208 struct ipa_ref
*maybe_add_reference (tree val
, enum ipa_ref_use use_type
,
211 /* Clone all references from symtab NODE to this symtab_node. */
212 void clone_references (symtab_node
*node
);
214 /* Remove all stmt references in non-speculative references.
215 Those are not maintained during inlining & clonning.
216 The exception are speculative references that are updated along
217 with callgraph edges associated with them. */
218 void clone_referring (symtab_node
*node
);
220 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
221 struct ipa_ref
*clone_reference (struct ipa_ref
*ref
, gimple stmt
);
223 /* Find the structure describing a reference to REFERRED_NODE
224 and associated with statement STMT. */
225 struct ipa_ref
*find_reference (symtab_node
*, gimple
, unsigned int);
227 /* Remove all references that are associated with statement STMT. */
228 void remove_stmt_references (gimple stmt
);
230 /* Remove all stmt references in non-speculative references.
231 Those are not maintained during inlining & clonning.
232 The exception are speculative references that are updated along
233 with callgraph edges associated with them. */
234 void clear_stmts_in_references (void);
236 /* Remove all references in ref list. */
237 void remove_all_references (void);
239 /* Remove all referring items in ref list. */
240 void remove_all_referring (void);
242 /* Dump references in ref list to FILE. */
243 void dump_references (FILE *file
);
245 /* Dump referring in list to FILE. */
246 void dump_referring (FILE *);
248 /* Return true if list contains an alias. */
249 bool has_aliases_p (void);
251 /* Iterates I-th reference in the list, REF is also set. */
252 struct ipa_ref
*iterate_reference (unsigned i
, struct ipa_ref
*&ref
);
254 /* Iterates I-th referring item in the list, REF is also set. */
255 struct ipa_ref
*iterate_referring (unsigned i
, struct ipa_ref
*&ref
);
257 /* Vectors of referring and referenced entities. */
258 struct ipa_ref_list ref_list
;
260 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
261 depending to what was known to frontend on the creation time.
262 Once alias is resolved, this pointer become NULL. */
265 /* File stream where this node is being written to. */
266 struct lto_file_decl_data
* lto_file_data
;
268 PTR
GTY ((skip
)) aux
;
270 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
273 /* Section name. Again can be private, if allowed. */
274 section_hash_entry
*x_section
;
276 /* Set section for symbol and its aliases. */
277 void set_section (const char *section
);
278 void set_section_for_node (const char *section
);
280 void set_init_priority (priority_type priority
);
281 priority_type
get_init_priority ();
286 /* Not yet set by cgraph_function_body_availability. */
288 /* Function body/variable initializer is unknown. */
290 /* Function body/variable initializer is known but might be replaced
291 by a different one from other compilation unit and thus needs to
292 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
293 arbitrary side effects on escaping variables and functions, while
294 like AVAILABLE it might access static variables. */
296 /* Function body/variable initializer is known and will be used in final
299 /* Function body/variable initializer is known and all it's uses are explicitly
300 visible within current unit (ie it's address is never taken and it is not
301 exported to other units).
302 Currently used only for functions. */
306 /* This is the information that is put into the cgraph local structure
307 to recover a function. */
308 struct lto_file_decl_data
;
310 extern const char * const cgraph_availability_names
[];
311 extern const char * const ld_plugin_symbol_resolution_names
[];
312 extern const char * const tls_model_names
[];
314 /* Information about thunk, used only for same body aliases. */
316 struct GTY(()) cgraph_thunk_info
{
317 /* Information about the thunk. */
318 HOST_WIDE_INT fixed_offset
;
319 HOST_WIDE_INT virtual_value
;
322 bool virtual_offset_p
;
323 /* Set to true when alias node is thunk. */
327 /* Information about the function collected locally.
328 Available after function is analyzed. */
330 struct GTY(()) cgraph_local_info
{
331 /* Set when function function is visible in current compilation unit only
332 and its address is never taken. */
335 /* False when there is something makes versioning impossible. */
336 unsigned versionable
: 1;
338 /* False when function calling convention and signature can not be changed.
339 This is the case when __builtin_apply_args is used. */
340 unsigned can_change_signature
: 1;
342 /* True when the function has been originally extern inline, but it is
344 unsigned redefined_extern_inline
: 1;
346 /* True if the function may enter serial irrevocable mode. */
347 unsigned tm_may_enter_irr
: 1;
350 /* Information about the function that needs to be computed globally
351 once compilation is finished. Available only with -funit-at-a-time. */
353 struct GTY(()) cgraph_global_info
{
354 /* For inline clones this points to the function they will be
356 struct cgraph_node
*inlined_to
;
359 /* Information about the function that is propagated by the RTL backend.
360 Available only for functions that has been already assembled. */
362 struct GTY(()) cgraph_rtl_info
{
363 unsigned int preferred_incoming_stack_boundary
;
365 /* Call unsaved hard registers really used by the corresponding
366 function (including ones used by functions called by the
368 HARD_REG_SET function_used_regs
;
369 /* Set if function_used_regs is valid. */
370 unsigned function_used_regs_valid
: 1;
373 /* Represent which DECL tree (or reference to such tree)
374 will be replaced by another tree while versioning. */
375 struct GTY(()) ipa_replace_map
377 /* The tree that will be replaced. */
379 /* The new (replacing) tree. */
381 /* Parameter number to replace, when old_tree is NULL. */
383 /* True when a substitution should be done, false otherwise. */
385 /* True when we replace a reference to old_tree. */
388 typedef struct ipa_replace_map
*ipa_replace_map_p
;
390 struct GTY(()) cgraph_clone_info
392 vec
<ipa_replace_map_p
, va_gc
> *tree_map
;
394 bitmap combined_args_to_skip
;
397 enum cgraph_simd_clone_arg_type
399 SIMD_CLONE_ARG_TYPE_VECTOR
,
400 SIMD_CLONE_ARG_TYPE_UNIFORM
,
401 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP
,
402 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP
,
403 SIMD_CLONE_ARG_TYPE_MASK
406 /* Function arguments in the original function of a SIMD clone.
407 Supplementary data for `struct simd_clone'. */
409 struct GTY(()) cgraph_simd_clone_arg
{
410 /* Original function argument as it originally existed in
414 /* orig_arg's function (or for extern functions type from
418 /* If argument is a vector, this holds the vector version of
419 orig_arg that after adjusting the argument types will live in
420 DECL_ARGUMENTS. Otherwise, this is NULL.
422 This basically holds:
423 vector(simdlen) __typeof__(orig_arg) new_arg. */
426 /* vector_arg's type (or for extern functions new vector type. */
429 /* If argument is a vector, this holds the array where the simd
430 argument is held while executing the simd clone function. This
431 is a local variable in the cloned function. Its content is
432 copied from vector_arg upon entry to the clone.
434 This basically holds:
435 __typeof__(orig_arg) simd_array[simdlen]. */
438 /* A SIMD clone's argument can be either linear (constant or
439 variable), uniform, or vector. */
440 enum cgraph_simd_clone_arg_type arg_type
;
442 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
443 the constant linear step, if arg_type is
444 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
445 the uniform argument holding the step, otherwise 0. */
446 HOST_WIDE_INT linear_step
;
448 /* Variable alignment if available, otherwise 0. */
449 unsigned int alignment
;
452 /* Specific data for a SIMD function clone. */
454 struct GTY(()) cgraph_simd_clone
{
455 /* Number of words in the SIMD lane associated with this clone. */
456 unsigned int simdlen
;
458 /* Number of annotated function arguments in `args'. This is
459 usually the number of named arguments in FNDECL. */
462 /* Max hardware vector size in bits for integral vectors. */
463 unsigned int vecsize_int
;
465 /* Max hardware vector size in bits for floating point vectors. */
466 unsigned int vecsize_float
;
468 /* The mangling character for a given vector size. This is is used
469 to determine the ISA mangling bit as specified in the Intel
471 unsigned char vecsize_mangle
;
473 /* True if this is the masked, in-branch version of the clone,
475 unsigned int inbranch
: 1;
477 /* True if this is a Cilk Plus variant. */
478 unsigned int cilk_elemental
: 1;
480 /* Doubly linked list of SIMD clones. */
481 struct cgraph_node
*prev_clone
, *next_clone
;
483 /* Original cgraph node the SIMD clones were created for. */
484 struct cgraph_node
*origin
;
486 /* Annotated function arguments for the original function. */
487 struct cgraph_simd_clone_arg
GTY((length ("%h.nargs"))) args
[1];
491 /* The cgraph data structure.
492 Each function decl has assigned cgraph_node listing callees and callers. */
494 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node
: public symtab_node
{
496 struct cgraph_edge
*callees
;
497 struct cgraph_edge
*callers
;
498 /* List of edges representing indirect calls with a yet undetermined
500 struct cgraph_edge
*indirect_calls
;
501 /* For nested functions points to function the node is nested in. */
502 struct cgraph_node
*origin
;
503 /* Points to first nested function, if any. */
504 struct cgraph_node
*nested
;
505 /* Pointer to the next function with same origin, if any. */
506 struct cgraph_node
*next_nested
;
507 /* Pointer to the next clone. */
508 struct cgraph_node
*next_sibling_clone
;
509 struct cgraph_node
*prev_sibling_clone
;
510 struct cgraph_node
*clones
;
511 struct cgraph_node
*clone_of
;
512 /* For functions with many calls sites it holds map from call expression
513 to the edge to speed up cgraph_edge function. */
514 htab_t
GTY((param_is (struct cgraph_edge
))) call_site_hash
;
515 /* Declaration node used to be clone of. */
516 tree former_clone_of
;
518 /* If this is a SIMD clone, this points to the SIMD specific
519 information for it. */
520 struct cgraph_simd_clone
*simdclone
;
521 /* If this function has SIMD clones, this points to the first clone. */
522 struct cgraph_node
*simd_clones
;
524 /* Interprocedural passes scheduled to have their transform functions
525 applied next time we execute local pass on them. We maintain it
526 per-function in order to allow IPA passes to introduce new functions. */
527 vec
<ipa_opt_pass
> GTY((skip
)) ipa_transforms_to_apply
;
529 struct cgraph_local_info local
;
530 struct cgraph_global_info global
;
531 struct cgraph_rtl_info rtl
;
532 struct cgraph_clone_info clone
;
533 struct cgraph_thunk_info thunk
;
535 /* Expected number of executions: calculated in profile.c. */
537 /* How to scale counts at materialization time; used to merge
538 LTO units with different number of profile runs. */
539 int count_materialization_scale
;
540 /* Unique id of the node. */
542 /* ID assigned by the profiling. */
543 unsigned int profile_id
;
544 /* Time profiler: first run of function. */
547 /* Set when decl is an abstract function pointed to by the
548 ABSTRACT_DECL_ORIGIN of a reachable function. */
549 unsigned used_as_abstract_origin
: 1;
550 /* Set once the function is lowered (i.e. its CFG is built). */
551 unsigned lowered
: 1;
552 /* Set once the function has been instantiated and its callee
554 unsigned process
: 1;
555 /* How commonly executed the node is. Initialized during branch
556 probabilities pass. */
557 ENUM_BITFIELD (node_frequency
) frequency
: 2;
558 /* True when function can only be called at startup (from static ctor). */
559 unsigned only_called_at_startup
: 1;
560 /* True when function can only be called at startup (from static dtor). */
561 unsigned only_called_at_exit
: 1;
562 /* True when function is the transactional clone of a function which
563 is called only from inside transactions. */
564 /* ?? We should be able to remove this. We have enough bits in
565 cgraph to calculate it. */
566 unsigned tm_clone
: 1;
567 /* True if this decl is a dispatcher for function versions. */
568 unsigned dispatcher_function
: 1;
569 /* True if this decl calls a COMDAT-local function. This is set up in
570 compute_inline_parameters and inline_call. */
571 unsigned calls_comdat_local
: 1;
573 void set_fini_priority (priority_type priority
);
574 priority_type
get_fini_priority ();
578 typedef struct cgraph_node
*cgraph_node_ptr
;
581 /* Function Multiversioning info. */
582 struct GTY(()) cgraph_function_version_info
{
583 /* The cgraph_node for which the function version info is stored. */
584 struct cgraph_node
*this_node
;
585 /* Chains all the semantically identical function versions. The
586 first function in this chain is the version_info node of the
588 struct cgraph_function_version_info
*prev
;
589 /* If this version node corresponds to a dispatcher for function
590 versions, this points to the version info node of the default
591 function, the first node in the chain. */
592 struct cgraph_function_version_info
*next
;
593 /* If this node corresponds to a function version, this points
594 to the dispatcher function decl, which is the function that must
595 be called to execute the right function version at run-time.
597 If this cgraph node is a dispatcher (if dispatcher_function is
598 true, in the cgraph_node struct) for function versions, this
599 points to resolver function, which holds the function body of the
600 dispatcher. The dispatcher decl is an alias to the resolver
602 tree dispatcher_resolver
;
605 /* Get the cgraph_function_version_info node corresponding to node. */
606 struct cgraph_function_version_info
*
607 get_cgraph_node_version (struct cgraph_node
*node
);
609 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
610 corresponding to cgraph_node NODE. */
611 struct cgraph_function_version_info
*
612 insert_new_cgraph_node_version (struct cgraph_node
*node
);
614 /* Record that DECL1 and DECL2 are semantically identical function
616 void record_function_versions (tree decl1
, tree decl2
);
618 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
619 DECL is a duplicate declaration. */
620 void delete_function_version (tree decl
);
622 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
623 can appear in multiple sets. */
624 struct cgraph_node_set_def
626 struct pointer_map_t
*map
;
627 vec
<cgraph_node_ptr
> nodes
;
631 typedef varpool_node
*varpool_node_ptr
;
634 /* A varpool node set is a collection of varpool nodes. A varpool node
635 can appear in multiple sets. */
636 struct varpool_node_set_def
638 struct pointer_map_t
* map
;
639 vec
<varpool_node_ptr
> nodes
;
642 typedef struct cgraph_node_set_def
*cgraph_node_set
;
645 typedef struct varpool_node_set_def
*varpool_node_set
;
648 /* Iterator structure for cgraph node sets. */
649 struct cgraph_node_set_iterator
655 /* Iterator structure for varpool node sets. */
656 struct varpool_node_set_iterator
658 varpool_node_set set
;
662 #define DEFCIFCODE(code, type, string) CIF_ ## code,
663 /* Reasons for inlining failures. */
664 enum cgraph_inline_failed_t
{
665 #include "cif-code.def"
669 enum cgraph_inline_failed_type_t
671 CIF_FINAL_NORMAL
= 0,
675 /* Structure containing additional information about an indirect call. */
677 struct GTY(()) cgraph_indirect_call_info
679 /* When polymorphic is set, this field contains offset where the object which
680 was actually used in the polymorphic resides within a larger structure.
681 If agg_contents is set, the field contains the offset within the aggregate
682 from which the address to call was loaded. */
683 HOST_WIDE_INT offset
;
684 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
685 HOST_WIDE_INT otr_token
;
686 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
687 tree otr_type
, outer_type
;
688 /* Index of the parameter that is called. */
690 /* ECF flags determined from the caller. */
692 /* Profile_id of common target obtrained from profile. */
693 int common_target_id
;
694 /* Probability that call will land in function with COMMON_TARGET_ID. */
695 int common_target_probability
;
697 /* Set when the call is a virtual call with the parameter being the
698 associated object pointer rather than a simple direct call. */
699 unsigned polymorphic
: 1;
700 /* Set when the call is a call of a pointer loaded from contents of an
701 aggregate at offset. */
702 unsigned agg_contents
: 1;
703 /* Set when this is a call through a member pointer. */
704 unsigned member_ptr
: 1;
705 /* When the previous bit is set, this one determines whether the destination
706 is loaded from a parameter passed by reference. */
708 unsigned int maybe_in_construction
: 1;
709 unsigned int maybe_derived_type
: 1;
712 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge
{
713 /* Expected number of executions: calculated in profile.c. */
715 struct cgraph_node
*caller
;
716 struct cgraph_node
*callee
;
717 struct cgraph_edge
*prev_caller
;
718 struct cgraph_edge
*next_caller
;
719 struct cgraph_edge
*prev_callee
;
720 struct cgraph_edge
*next_callee
;
722 /* Additional information about an indirect call. Not cleared when an edge
724 struct cgraph_indirect_call_info
*indirect_info
;
725 PTR
GTY ((skip (""))) aux
;
726 /* When equal to CIF_OK, inline this call. Otherwise, points to the
727 explanation why function was not inlined. */
728 enum cgraph_inline_failed_t inline_failed
;
729 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
730 when the function is serialized in. */
731 unsigned int lto_stmt_uid
;
732 /* Expected frequency of executions within the function.
733 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
734 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
736 /* Unique id of the edge. */
738 /* Whether this edge was made direct by indirect inlining. */
739 unsigned int indirect_inlining_edge
: 1;
740 /* Whether this edge describes an indirect call with an undetermined
742 unsigned int indirect_unknown_callee
: 1;
743 /* Whether this edge is still a dangling */
744 /* True if the corresponding CALL stmt cannot be inlined. */
745 unsigned int call_stmt_cannot_inline_p
: 1;
746 /* Can this call throw externally? */
747 unsigned int can_throw_external
: 1;
748 /* Edges with SPECULATIVE flag represents indirect calls that was
749 speculatively turned into direct (i.e. by profile feedback).
750 The final code sequence will have form:
752 if (call_target == expected_fn)
757 Every speculative call is represented by three components attached
758 to a same call statement:
759 1) a direct call (to expected_fn)
760 2) an indirect call (to call_target)
761 3) a IPA_REF_ADDR refrence to expected_fn.
763 Optimizers may later redirect direct call to clone, so 1) and 3)
764 do not need to necesarily agree with destination. */
765 unsigned int speculative
: 1;
768 #define CGRAPH_FREQ_BASE 1000
769 #define CGRAPH_FREQ_MAX 100000
771 typedef struct cgraph_edge
*cgraph_edge_p
;
774 /* The varpool data structure.
775 Each static variable decl has assigned varpool_node. */
777 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node
: public symtab_node
{
779 /* Set when variable is scheduled to be assembled. */
782 /* Set if the variable is dynamically initialized, except for
783 function local statics. */
784 unsigned dynamically_initialized
: 1;
786 ENUM_BITFIELD(tls_model
) tls_model
: 3;
788 /* Set if the variable is known to be used by single function only.
789 This is computed by ipa_signle_use pass and used by late optimizations
790 in places where optimization would be valid for local static variable
791 if we did not do any inter-procedural code movement. */
792 unsigned used_by_single_function
: 1;
795 /* Every top level asm statement is put into a asm_node. */
797 struct GTY(()) asm_node
{
799 struct asm_node
*next
;
800 /* String for this asm node. */
802 /* Ordering of all cgraph nodes. */
806 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
811 is_a_helper
<cgraph_node
*>::test (symtab_node
*p
)
813 return p
->type
== SYMTAB_FUNCTION
;
816 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
821 is_a_helper
<varpool_node
*>::test (symtab_node
*p
)
823 return p
->type
== SYMTAB_VARIABLE
;
826 extern GTY(()) symtab_node
*symtab_nodes
;
827 extern GTY(()) int cgraph_n_nodes
;
828 extern GTY(()) int cgraph_max_uid
;
829 extern GTY(()) int cgraph_edge_max_uid
;
830 extern bool cgraph_global_info_ready
;
833 /* Frontend is parsing and finalizing functions. */
834 CGRAPH_STATE_PARSING
,
835 /* Callgraph is being constructed. It is safe to add new functions. */
836 CGRAPH_STATE_CONSTRUCTION
,
837 /* Callgraph is being at LTO time. */
838 CGRAPH_LTO_STREAMING
,
839 /* Callgraph is built and IPA passes are being run. */
841 /* Callgraph is built and all functions are transformed to SSA form. */
842 CGRAPH_STATE_IPA_SSA
,
843 /* Functions are now ordered and being passed to RTL expanders. */
844 CGRAPH_STATE_EXPANSION
,
845 /* All cgraph expansion is done. */
846 CGRAPH_STATE_FINISHED
848 extern enum cgraph_state cgraph_state
;
849 extern bool cgraph_function_flags_ready
;
850 extern cgraph_node_set cgraph_new_nodes
;
852 extern GTY(()) struct asm_node
*asm_nodes
;
853 extern GTY(()) int symtab_order
;
854 extern bool cpp_implicit_aliases_done
;
856 /* Classifcation of symbols WRT partitioning. */
857 enum symbol_partitioning_class
859 /* External declarations are ignored by partitioning algorithms and they are
860 added into the boundary later via compute_ltrans_boundary. */
862 /* Partitioned symbols are pur into one of partitions. */
864 /* Duplicated symbols (such as comdat or constant pool references) are
865 copied into every node needing them via add_symbol_to_partition. */
871 void symtab_register_node (symtab_node
*);
872 void symtab_unregister_node (symtab_node
*);
873 void symtab_remove_from_same_comdat_group (symtab_node
*);
874 void symtab_remove_node (symtab_node
*);
875 symtab_node
*symtab_node_for_asm (const_tree asmname
);
876 void symtab_add_to_same_comdat_group (symtab_node
*, symtab_node
*);
877 void symtab_dissolve_same_comdat_group_list (symtab_node
*node
);
878 void dump_symtab (FILE *);
879 void debug_symtab (void);
880 void dump_symtab_node (FILE *, symtab_node
*);
881 void debug_symtab_node (symtab_node
*);
882 void dump_symtab_base (FILE *, symtab_node
*);
883 void verify_symtab (void);
884 void verify_symtab_node (symtab_node
*);
885 bool verify_symtab_base (symtab_node
*);
886 bool symtab_used_from_object_file_p (symtab_node
*);
887 void symtab_make_decl_local (tree
);
888 symtab_node
*symtab_alias_ultimate_target (symtab_node
*,
889 enum availability
*avail
= NULL
);
890 bool symtab_resolve_alias (symtab_node
*node
, symtab_node
*target
);
891 void fixup_same_cpp_alias_visibility (symtab_node
*node
, symtab_node
*target
);
892 bool symtab_for_node_and_aliases (symtab_node
*,
893 bool (*) (symtab_node
*, void *),
896 symtab_node
*symtab_nonoverwritable_alias (symtab_node
*);
897 enum availability
symtab_node_availability (symtab_node
*);
898 bool symtab_semantically_equivalent_p (symtab_node
*, symtab_node
*);
899 enum symbol_partitioning_class
symtab_get_symbol_partitioning_class (symtab_node
*);
902 void dump_cgraph (FILE *);
903 void debug_cgraph (void);
904 void dump_cgraph_node (FILE *, struct cgraph_node
*);
905 void debug_cgraph_node (struct cgraph_node
*);
906 void cgraph_remove_edge (struct cgraph_edge
*);
907 void cgraph_remove_node (struct cgraph_node
*);
908 void cgraph_release_function_body (struct cgraph_node
*);
909 void release_function_body (tree
);
910 void cgraph_node_remove_callees (struct cgraph_node
*node
);
911 struct cgraph_edge
*cgraph_create_edge (struct cgraph_node
*,
912 struct cgraph_node
*,
913 gimple
, gcov_type
, int);
914 struct cgraph_edge
*cgraph_create_indirect_edge (struct cgraph_node
*, gimple
,
915 int, gcov_type
, int);
916 struct cgraph_indirect_call_info
*cgraph_allocate_init_indirect_info (void);
917 struct cgraph_node
* cgraph_create_node (tree
);
918 struct cgraph_node
* cgraph_create_empty_node (void);
919 struct cgraph_node
* cgraph_get_create_node (tree
);
920 struct cgraph_node
* cgraph_same_body_alias (struct cgraph_node
*, tree
, tree
);
921 struct cgraph_node
* cgraph_add_thunk (struct cgraph_node
*, tree
, tree
, bool, HOST_WIDE_INT
,
922 HOST_WIDE_INT
, tree
, tree
);
923 struct cgraph_node
*cgraph_node_for_asm (tree
);
924 struct cgraph_edge
*cgraph_edge (struct cgraph_node
*, gimple
);
925 void cgraph_set_call_stmt (struct cgraph_edge
*, gimple
, bool update_speculative
= true);
926 void cgraph_update_edges_for_call_stmt (gimple
, tree
, gimple
);
927 struct cgraph_local_info
*cgraph_local_info (tree
);
928 struct cgraph_global_info
*cgraph_global_info (tree
);
929 struct cgraph_rtl_info
*cgraph_rtl_info (tree
);
930 struct cgraph_node
*cgraph_create_function_alias (tree
, tree
);
931 void cgraph_call_node_duplication_hooks (struct cgraph_node
*,
932 struct cgraph_node
*);
933 void cgraph_call_edge_duplication_hooks (struct cgraph_edge
*,
934 struct cgraph_edge
*);
936 void cgraph_redirect_edge_callee (struct cgraph_edge
*, struct cgraph_node
*);
937 struct cgraph_edge
*cgraph_make_edge_direct (struct cgraph_edge
*, struct cgraph_node
*);
938 bool cgraph_only_called_directly_p (struct cgraph_node
*);
940 bool cgraph_function_possibly_inlined_p (tree
);
941 void cgraph_unnest_node (struct cgraph_node
*);
943 enum availability
cgraph_function_body_availability (struct cgraph_node
*);
944 void cgraph_add_new_function (tree
, bool);
945 const char* cgraph_inline_failed_string (cgraph_inline_failed_t
);
946 cgraph_inline_failed_type_t
cgraph_inline_failed_type (cgraph_inline_failed_t
);
948 void cgraph_set_nothrow_flag (struct cgraph_node
*, bool);
949 void cgraph_set_const_flag (struct cgraph_node
*, bool, bool);
950 void cgraph_set_pure_flag (struct cgraph_node
*, bool, bool);
951 bool cgraph_node_cannot_return (struct cgraph_node
*);
952 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge
*);
953 bool cgraph_will_be_removed_from_program_if_no_direct_calls
954 (struct cgraph_node
*node
);
955 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
956 (struct cgraph_node
*node
);
957 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node
*node
);
958 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution
);
959 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node
*,
960 bool (*) (struct cgraph_node
*, void *),
963 bool cgraph_for_node_and_aliases (struct cgraph_node
*,
964 bool (*) (struct cgraph_node
*, void *),
966 vec
<cgraph_edge_p
> collect_callers_of_node (struct cgraph_node
*node
);
967 void verify_cgraph (void);
968 void verify_cgraph_node (struct cgraph_node
*);
969 void cgraph_mark_address_taken_node (struct cgraph_node
*);
971 typedef void (*cgraph_edge_hook
)(struct cgraph_edge
*, void *);
972 typedef void (*cgraph_node_hook
)(struct cgraph_node
*, void *);
973 typedef void (*varpool_node_hook
)(varpool_node
*, void *);
974 typedef void (*cgraph_2edge_hook
)(struct cgraph_edge
*, struct cgraph_edge
*,
976 typedef void (*cgraph_2node_hook
)(struct cgraph_node
*, struct cgraph_node
*,
978 struct cgraph_edge_hook_list
;
979 struct cgraph_node_hook_list
;
980 struct varpool_node_hook_list
;
981 struct cgraph_2edge_hook_list
;
982 struct cgraph_2node_hook_list
;
983 struct cgraph_edge_hook_list
*cgraph_add_edge_removal_hook (cgraph_edge_hook
, void *);
984 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list
*);
985 struct cgraph_node_hook_list
*cgraph_add_node_removal_hook (cgraph_node_hook
,
987 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list
*);
988 struct varpool_node_hook_list
*varpool_add_node_removal_hook (varpool_node_hook
,
990 void varpool_remove_node_removal_hook (struct varpool_node_hook_list
*);
991 struct cgraph_node_hook_list
*cgraph_add_function_insertion_hook (cgraph_node_hook
,
993 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list
*);
994 struct varpool_node_hook_list
*varpool_add_variable_insertion_hook (varpool_node_hook
,
996 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list
*);
997 void cgraph_call_function_insertion_hooks (struct cgraph_node
*node
);
998 struct cgraph_2edge_hook_list
*cgraph_add_edge_duplication_hook (cgraph_2edge_hook
, void *);
999 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list
*);
1000 struct cgraph_2node_hook_list
*cgraph_add_node_duplication_hook (cgraph_2node_hook
, void *);
1001 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list
*);
1002 gimple
cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge
*);
1003 struct cgraph_node
* cgraph_function_node (struct cgraph_node
*,
1004 enum availability
*avail
= NULL
);
1005 bool cgraph_get_body (struct cgraph_node
*node
);
1006 struct cgraph_edge
*
1007 cgraph_turn_edge_to_speculative (struct cgraph_edge
*,
1008 struct cgraph_node
*,
1010 void cgraph_speculative_call_info (struct cgraph_edge
*,
1011 struct cgraph_edge
*&,
1012 struct cgraph_edge
*&,
1014 extern bool gimple_check_call_matching_types (gimple
, tree
, bool);
1016 /* In cgraphunit.c */
1017 struct asm_node
*add_asm_node (tree
);
1018 extern FILE *cgraph_dump_file
;
1019 void cgraph_finalize_function (tree
, bool);
1020 void finalize_compilation_unit (void);
1021 void compile (void);
1022 void init_cgraph (void);
1023 void cgraph_process_new_functions (void);
1024 void cgraph_process_same_body_aliases (void);
1025 void fixup_same_cpp_alias_visibility (symtab_node
*, symtab_node
*target
, tree
);
1026 /* Initialize datastructures so DECL is a function in lowered gimple form.
1027 IN_SSA is true if the gimple is in SSA. */
1028 basic_block
init_lowered_empty_function (tree
, bool);
1029 void cgraph_reset_node (struct cgraph_node
*);
1030 bool expand_thunk (struct cgraph_node
*, bool, bool);
1031 void cgraph_make_wrapper (struct cgraph_node
*source
,
1032 struct cgraph_node
*target
);
1034 /* In cgraphclones.c */
1036 struct cgraph_edge
* cgraph_clone_edge (struct cgraph_edge
*,
1037 struct cgraph_node
*, gimple
,
1038 unsigned, gcov_type
, int, bool);
1039 struct cgraph_node
* cgraph_clone_node (struct cgraph_node
*, tree
, gcov_type
,
1040 int, bool, vec
<cgraph_edge_p
>,
1041 bool, struct cgraph_node
*, bitmap
);
1042 tree
clone_function_name (tree decl
, const char *);
1043 struct cgraph_node
* cgraph_create_virtual_clone (struct cgraph_node
*old_node
,
1045 vec
<ipa_replace_map_p
, va_gc
> *tree_map
,
1046 bitmap args_to_skip
,
1047 const char *clone_name
);
1048 struct cgraph_node
*cgraph_find_replacement_node (struct cgraph_node
*);
1049 bool cgraph_remove_node_and_inline_clones (struct cgraph_node
*, struct cgraph_node
*);
1050 void cgraph_set_call_stmt_including_clones (struct cgraph_node
*, gimple
, gimple
,
1051 bool update_speculative
= true);
1052 void cgraph_create_edge_including_clones (struct cgraph_node
*,
1053 struct cgraph_node
*,
1054 gimple
, gimple
, gcov_type
, int,
1055 cgraph_inline_failed_t
);
1056 void cgraph_materialize_all_clones (void);
1057 struct cgraph_node
* cgraph_copy_node_for_versioning (struct cgraph_node
*,
1058 tree
, vec
<cgraph_edge_p
>, bitmap
);
1059 struct cgraph_node
*cgraph_function_versioning (struct cgraph_node
*,
1061 vec
<ipa_replace_map_p
, va_gc
> *,
1062 bitmap
, bool, bitmap
,
1063 basic_block
, const char *);
1064 void tree_function_versioning (tree
, tree
, vec
<ipa_replace_map_p
, va_gc
> *,
1065 bool, bitmap
, bool, bitmap
, basic_block
);
1066 struct cgraph_edge
*cgraph_resolve_speculation (struct cgraph_edge
*, tree
);
1068 /* In cgraphbuild.c */
1069 unsigned int rebuild_cgraph_edges (void);
1070 void cgraph_rebuild_references (void);
1071 int compute_call_stmt_bb_frequency (tree
, basic_block bb
);
1072 void record_references_in_initializer (tree
, bool);
1073 void ipa_record_stmt_references (struct cgraph_node
*, gimple
);
1076 bool symtab_remove_unreachable_nodes (bool, FILE *);
1077 cgraph_node_set
cgraph_node_set_new (void);
1078 cgraph_node_set_iterator
cgraph_node_set_find (cgraph_node_set
,
1079 struct cgraph_node
*);
1080 void cgraph_node_set_add (cgraph_node_set
, struct cgraph_node
*);
1081 void cgraph_node_set_remove (cgraph_node_set
, struct cgraph_node
*);
1082 void dump_cgraph_node_set (FILE *, cgraph_node_set
);
1083 void debug_cgraph_node_set (cgraph_node_set
);
1084 void free_cgraph_node_set (cgraph_node_set
);
1085 void cgraph_build_static_cdtor (char which
, tree body
, int priority
);
1087 varpool_node_set
varpool_node_set_new (void);
1088 varpool_node_set_iterator
varpool_node_set_find (varpool_node_set
,
1090 void varpool_node_set_add (varpool_node_set
, varpool_node
*);
1091 void varpool_node_set_remove (varpool_node_set
, varpool_node
*);
1092 void dump_varpool_node_set (FILE *, varpool_node_set
);
1093 void debug_varpool_node_set (varpool_node_set
);
1094 void free_varpool_node_set (varpool_node_set
);
1095 void ipa_discover_readonly_nonaddressable_vars (void);
1096 bool varpool_externally_visible_p (varpool_node
*);
1098 /* In ipa-visibility.c */
1099 bool cgraph_local_node_p (struct cgraph_node
*);
1100 bool address_taken_from_non_vtable_p (symtab_node
*node
);
1104 bool cgraph_maybe_hot_edge_p (struct cgraph_edge
*e
);
1105 bool cgraph_optimize_for_size_p (struct cgraph_node
*);
1108 varpool_node
*varpool_create_empty_node (void);
1109 varpool_node
*varpool_node_for_decl (tree
);
1110 varpool_node
*varpool_node_for_asm (tree asmname
);
1111 void varpool_mark_needed_node (varpool_node
*);
1112 void debug_varpool (void);
1113 void dump_varpool (FILE *);
1114 void dump_varpool_node (FILE *, varpool_node
*);
1116 void varpool_finalize_decl (tree
);
1117 enum availability
cgraph_variable_initializer_availability (varpool_node
*);
1118 void cgraph_make_node_local (struct cgraph_node
*);
1119 bool cgraph_node_can_be_local_p (struct cgraph_node
*);
1122 void varpool_remove_node (varpool_node
*node
);
1123 void varpool_finalize_named_section_flags (varpool_node
*node
);
1124 bool varpool_output_variables (void);
1125 bool varpool_assemble_decl (varpool_node
*node
);
1126 void varpool_analyze_node (varpool_node
*);
1127 varpool_node
* varpool_extra_name_alias (tree
, tree
);
1128 varpool_node
* varpool_create_variable_alias (tree
, tree
);
1129 void varpool_reset_queue (void);
1130 tree
ctor_for_folding (tree
);
1131 bool varpool_for_node_and_aliases (varpool_node
*,
1132 bool (*) (varpool_node
*, void *),
1134 void varpool_add_new_variable (tree
);
1135 void symtab_initialize_asm_name_hash (void);
1136 void symtab_prevail_in_asm_name_hash (symtab_node
*node
);
1137 void varpool_remove_initializer (varpool_node
*);
1140 extern void change_decl_assembler_name (tree
, tree
);
1142 /* Return symbol table node associated with DECL, if any,
1143 and NULL otherwise. */
1145 static inline symtab_node
*
1146 symtab_get_node (const_tree decl
)
1148 #ifdef ENABLE_CHECKING
1149 /* Check that we are called for sane type of object - functions
1150 and static or external variables. */
1151 gcc_checking_assert (TREE_CODE (decl
) == FUNCTION_DECL
1152 || (TREE_CODE (decl
) == VAR_DECL
1153 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
1155 /* Check that the mapping is sane - perhaps this check can go away,
1156 but at the moment frontends tends to corrupt the mapping by calling
1157 memcpy/memset on the tree nodes. */
1158 gcc_checking_assert (!decl
->decl_with_vis
.symtab_node
1159 || decl
->decl_with_vis
.symtab_node
->decl
== decl
);
1161 return decl
->decl_with_vis
.symtab_node
;
1164 /* Return callgraph node for given symbol and check it is a function. */
1165 static inline struct cgraph_node
*
1166 cgraph (symtab_node
*node
)
1168 gcc_checking_assert (!node
|| node
->type
== SYMTAB_FUNCTION
);
1169 return (struct cgraph_node
*)node
;
1172 /* Return varpool node for given symbol and check it is a variable. */
1173 static inline varpool_node
*
1174 varpool (symtab_node
*node
)
1176 gcc_checking_assert (!node
|| node
->type
== SYMTAB_VARIABLE
);
1177 return (varpool_node
*)node
;
1180 /* Return callgraph node for given symbol and check it is a function. */
1181 static inline struct cgraph_node
*
1182 cgraph_get_node (const_tree decl
)
1184 gcc_checking_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1185 return cgraph (symtab_get_node (decl
));
1188 /* Return varpool node for given symbol and check it is a function. */
1189 static inline varpool_node
*
1190 varpool_get_node (const_tree decl
)
1192 gcc_checking_assert (TREE_CODE (decl
) == VAR_DECL
);
1193 return varpool (symtab_get_node (decl
));
1196 /* Walk all symbols. */
1197 #define FOR_EACH_SYMBOL(node) \
1198 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1200 /* Return first static symbol with definition. */
1201 static inline symtab_node
*
1202 symtab_first_defined_symbol (void)
1206 for (node
= symtab_nodes
; node
; node
= node
->next
)
1207 if (node
->definition
)
1213 /* Return next reachable static symbol with initializer after NODE. */
1214 static inline symtab_node
*
1215 symtab_next_defined_symbol (symtab_node
*node
)
1217 symtab_node
*node1
= node
->next
;
1219 for (; node1
; node1
= node1
->next
)
1220 if (node1
->definition
)
1225 /* Walk all symbols with definitions in current unit. */
1226 #define FOR_EACH_DEFINED_SYMBOL(node) \
1227 for ((node) = symtab_first_defined_symbol (); (node); \
1228 (node) = symtab_next_defined_symbol (node))
1230 /* Return first variable. */
1231 static inline varpool_node
*
1232 varpool_first_variable (void)
1235 for (node
= symtab_nodes
; node
; node
= node
->next
)
1236 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
1241 /* Return next variable after NODE. */
1242 static inline varpool_node
*
1243 varpool_next_variable (varpool_node
*node
)
1245 symtab_node
*node1
= node
->next
;
1246 for (; node1
; node1
= node1
->next
)
1247 if (varpool_node
*vnode1
= dyn_cast
<varpool_node
*> (node1
))
1251 /* Walk all variables. */
1252 #define FOR_EACH_VARIABLE(node) \
1253 for ((node) = varpool_first_variable (); \
1255 (node) = varpool_next_variable ((node)))
1257 /* Return first static variable with initializer. */
1258 static inline varpool_node
*
1259 varpool_first_static_initializer (void)
1262 for (node
= symtab_nodes
; node
; node
= node
->next
)
1264 varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
);
1265 if (vnode
&& DECL_INITIAL (node
->decl
))
1271 /* Return next static variable with initializer after NODE. */
1272 static inline varpool_node
*
1273 varpool_next_static_initializer (varpool_node
*node
)
1275 symtab_node
*node1
= node
->next
;
1276 for (; node1
; node1
= node1
->next
)
1278 varpool_node
*vnode1
= dyn_cast
<varpool_node
*> (node1
);
1279 if (vnode1
&& DECL_INITIAL (node1
->decl
))
1285 /* Walk all static variables with initializer set. */
1286 #define FOR_EACH_STATIC_INITIALIZER(node) \
1287 for ((node) = varpool_first_static_initializer (); (node); \
1288 (node) = varpool_next_static_initializer (node))
1290 /* Return first static variable with definition. */
1291 static inline varpool_node
*
1292 varpool_first_defined_variable (void)
1295 for (node
= symtab_nodes
; node
; node
= node
->next
)
1297 varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
);
1298 if (vnode
&& vnode
->definition
)
1304 /* Return next static variable with definition after NODE. */
1305 static inline varpool_node
*
1306 varpool_next_defined_variable (varpool_node
*node
)
1308 symtab_node
*node1
= node
->next
;
1309 for (; node1
; node1
= node1
->next
)
1311 varpool_node
*vnode1
= dyn_cast
<varpool_node
*> (node1
);
1312 if (vnode1
&& vnode1
->definition
)
1317 /* Walk all variables with definitions in current unit. */
1318 #define FOR_EACH_DEFINED_VARIABLE(node) \
1319 for ((node) = varpool_first_defined_variable (); (node); \
1320 (node) = varpool_next_defined_variable (node))
1322 /* Return first function with body defined. */
1323 static inline struct cgraph_node
*
1324 cgraph_first_defined_function (void)
1327 for (node
= symtab_nodes
; node
; node
= node
->next
)
1329 cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (node
);
1330 if (cn
&& cn
->definition
)
1336 /* Return next function with body defined after NODE. */
1337 static inline struct cgraph_node
*
1338 cgraph_next_defined_function (struct cgraph_node
*node
)
1340 symtab_node
*node1
= node
->next
;
1341 for (; node1
; node1
= node1
->next
)
1343 cgraph_node
*cn1
= dyn_cast
<cgraph_node
*> (node1
);
1344 if (cn1
&& cn1
->definition
)
1350 /* Walk all functions with body defined. */
1351 #define FOR_EACH_DEFINED_FUNCTION(node) \
1352 for ((node) = cgraph_first_defined_function (); (node); \
1353 (node) = cgraph_next_defined_function ((node)))
1355 /* Return first function. */
1356 static inline struct cgraph_node
*
1357 cgraph_first_function (void)
1360 for (node
= symtab_nodes
; node
; node
= node
->next
)
1361 if (cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (node
))
1366 /* Return next function. */
1367 static inline struct cgraph_node
*
1368 cgraph_next_function (struct cgraph_node
*node
)
1370 symtab_node
*node1
= node
->next
;
1371 for (; node1
; node1
= node1
->next
)
1372 if (cgraph_node
*cn1
= dyn_cast
<cgraph_node
*> (node1
))
1376 /* Walk all functions. */
1377 #define FOR_EACH_FUNCTION(node) \
1378 for ((node) = cgraph_first_function (); (node); \
1379 (node) = cgraph_next_function ((node)))
1381 /* Return true when NODE is a function with Gimple body defined
1382 in current unit. Functions can also be define externally or they
1383 can be thunks with no Gimple representation.
1385 Note that at WPA stage, the function body may not be present in memory. */
1388 cgraph_function_with_gimple_body_p (struct cgraph_node
*node
)
1390 return node
->definition
&& !node
->thunk
.thunk_p
&& !node
->alias
;
1393 /* Return first function with body defined. */
1394 static inline struct cgraph_node
*
1395 cgraph_first_function_with_gimple_body (void)
1398 for (node
= symtab_nodes
; node
; node
= node
->next
)
1400 cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (node
);
1401 if (cn
&& cgraph_function_with_gimple_body_p (cn
))
1407 /* Return next reachable static variable with initializer after NODE. */
1408 static inline struct cgraph_node
*
1409 cgraph_next_function_with_gimple_body (struct cgraph_node
*node
)
1411 symtab_node
*node1
= node
->next
;
1412 for (; node1
; node1
= node1
->next
)
1414 cgraph_node
*cn1
= dyn_cast
<cgraph_node
*> (node1
);
1415 if (cn1
&& cgraph_function_with_gimple_body_p (cn1
))
1421 /* Walk all functions with body defined. */
1422 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1423 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1424 (node) = cgraph_next_function_with_gimple_body (node))
1426 /* Create a new static variable of type TYPE. */
1427 tree
add_new_static_var (tree type
);
1429 /* Return true if iterator CSI points to nothing. */
1431 csi_end_p (cgraph_node_set_iterator csi
)
1433 return csi
.index
>= csi
.set
->nodes
.length ();
1436 /* Advance iterator CSI. */
1438 csi_next (cgraph_node_set_iterator
*csi
)
1443 /* Return the node pointed to by CSI. */
1444 static inline struct cgraph_node
*
1445 csi_node (cgraph_node_set_iterator csi
)
1447 return csi
.set
->nodes
[csi
.index
];
1450 /* Return an iterator to the first node in SET. */
1451 static inline cgraph_node_set_iterator
1452 csi_start (cgraph_node_set set
)
1454 cgraph_node_set_iterator csi
;
1461 /* Return true if SET contains NODE. */
1463 cgraph_node_in_set_p (struct cgraph_node
*node
, cgraph_node_set set
)
1465 cgraph_node_set_iterator csi
;
1466 csi
= cgraph_node_set_find (set
, node
);
1467 return !csi_end_p (csi
);
1470 /* Return number of nodes in SET. */
1471 static inline size_t
1472 cgraph_node_set_size (cgraph_node_set set
)
1474 return set
->nodes
.length ();
1477 /* Return true if iterator VSI points to nothing. */
1479 vsi_end_p (varpool_node_set_iterator vsi
)
1481 return vsi
.index
>= vsi
.set
->nodes
.length ();
1484 /* Advance iterator VSI. */
1486 vsi_next (varpool_node_set_iterator
*vsi
)
1491 /* Return the node pointed to by VSI. */
1492 static inline varpool_node
*
1493 vsi_node (varpool_node_set_iterator vsi
)
1495 return vsi
.set
->nodes
[vsi
.index
];
1498 /* Return an iterator to the first node in SET. */
1499 static inline varpool_node_set_iterator
1500 vsi_start (varpool_node_set set
)
1502 varpool_node_set_iterator vsi
;
1509 /* Return true if SET contains NODE. */
1511 varpool_node_in_set_p (varpool_node
*node
, varpool_node_set set
)
1513 varpool_node_set_iterator vsi
;
1514 vsi
= varpool_node_set_find (set
, node
);
1515 return !vsi_end_p (vsi
);
1518 /* Return number of nodes in SET. */
1519 static inline size_t
1520 varpool_node_set_size (varpool_node_set set
)
1522 return set
->nodes
.length ();
1525 /* Uniquize all constants that appear in memory.
1526 Each constant in memory thus far output is recorded
1527 in `const_desc_table'. */
1529 struct GTY(()) constant_descriptor_tree
{
1530 /* A MEM for the constant. */
1533 /* The value of the constant. */
1536 /* Hash of value. Computing the hash from value each time
1537 hashfn is called can't work properly, as that means recursive
1538 use of the hash table during hash table expansion. */
1542 /* Return true if set is nonempty. */
1544 cgraph_node_set_nonempty_p (cgraph_node_set set
)
1546 return !set
->nodes
.is_empty ();
1549 /* Return true if set is nonempty. */
1551 varpool_node_set_nonempty_p (varpool_node_set set
)
1553 return !set
->nodes
.is_empty ();
1556 /* Return true when function NODE is only called directly or it has alias.
1557 i.e. it is not externally visible, address was not taken and
1558 it is not used in any other non-standard way. */
1561 cgraph_only_called_directly_or_aliased_p (struct cgraph_node
*node
)
1563 gcc_assert (!node
->global
.inlined_to
);
1564 return (!node
->force_output
&& !node
->address_taken
1565 && !node
->used_from_other_partition
1566 && !DECL_VIRTUAL_P (node
->decl
)
1567 && !DECL_STATIC_CONSTRUCTOR (node
->decl
)
1568 && !DECL_STATIC_DESTRUCTOR (node
->decl
)
1569 && !node
->externally_visible
);
1572 /* Return true when function NODE can be removed from callgraph
1573 if all direct calls are eliminated. */
1576 varpool_can_remove_if_no_refs (varpool_node
*node
)
1578 if (DECL_EXTERNAL (node
->decl
))
1580 return (!node
->force_output
&& !node
->used_from_other_partition
1581 && ((DECL_COMDAT (node
->decl
)
1582 && !node
->forced_by_abi
1583 && !symtab_used_from_object_file_p (node
))
1584 || !node
->externally_visible
1585 || DECL_HAS_VALUE_EXPR_P (node
->decl
)));
1588 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1589 i.e. if the variable is not externally visible or not used in some magic
1590 way (asm statement or such).
1591 The magic uses are all summarized in force_output flag. */
1594 varpool_all_refs_explicit_p (varpool_node
*vnode
)
1596 return (vnode
->definition
1597 && !vnode
->externally_visible
1598 && !vnode
->used_from_other_partition
1599 && !vnode
->force_output
);
1602 /* Constant pool accessor function. */
1603 htab_t
constant_pool_htab (void);
1605 /* Return node that alias N is aliasing. */
1607 static inline symtab_node
*
1608 symtab_alias_target (symtab_node
*n
)
1610 struct ipa_ref
*ref
= NULL
;
1611 n
->iterate_reference (0, ref
);
1612 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1613 return ref
->referred
;
1616 static inline struct cgraph_node
*
1617 cgraph_alias_target (struct cgraph_node
*n
)
1619 return dyn_cast
<cgraph_node
*> (symtab_alias_target (n
));
1622 static inline varpool_node
*
1623 varpool_alias_target (varpool_node
*n
)
1625 return dyn_cast
<varpool_node
*> (symtab_alias_target (n
));
1628 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1629 Do not walk through thunks.
1630 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1632 static inline struct cgraph_node
*
1633 cgraph_function_or_thunk_node (struct cgraph_node
*node
,
1634 enum availability
*availability
= NULL
)
1636 struct cgraph_node
*n
;
1638 n
= dyn_cast
<cgraph_node
*> (symtab_alias_ultimate_target (node
,
1640 if (!n
&& availability
)
1641 *availability
= AVAIL_NOT_AVAILABLE
;
1644 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1645 Do not walk through thunks.
1646 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1648 static inline varpool_node
*
1649 varpool_variable_node (varpool_node
*node
,
1650 enum availability
*availability
= NULL
)
1655 n
= dyn_cast
<varpool_node
*> (symtab_alias_ultimate_target (node
,
1660 if (!n
&& availability
)
1661 *availability
= AVAIL_NOT_AVAILABLE
;
1665 /* Return true when the edge E represents a direct recursion. */
1667 cgraph_edge_recursive_p (struct cgraph_edge
*e
)
1669 struct cgraph_node
*callee
= cgraph_function_or_thunk_node (e
->callee
, NULL
);
1670 if (e
->caller
->global
.inlined_to
)
1671 return e
->caller
->global
.inlined_to
->decl
== callee
->decl
;
1673 return e
->caller
->decl
== callee
->decl
;
1676 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1678 decl_is_tm_clone (const_tree fndecl
)
1680 struct cgraph_node
*n
= cgraph_get_node (fndecl
);
1686 /* Likewise indicate that a node is needed, i.e. reachable via some
1690 cgraph_mark_force_output_node (struct cgraph_node
*node
)
1692 node
->force_output
= 1;
1693 gcc_checking_assert (!node
->global
.inlined_to
);
1696 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1697 or abstract function kept for debug info purposes only. */
1700 symtab_real_symbol_p (symtab_node
*node
)
1702 struct cgraph_node
*cnode
;
1704 if (DECL_ABSTRACT (node
->decl
))
1706 if (!is_a
<cgraph_node
*> (node
))
1708 cnode
= cgraph (node
);
1709 if (cnode
->global
.inlined_to
)
1714 /* Return true if NODE can be discarded by linker from the binary. */
1717 symtab_can_be_discarded (symtab_node
*node
)
1719 return (DECL_EXTERNAL (node
->decl
)
1720 || (node
->get_comdat_group ()
1721 && node
->resolution
!= LDPR_PREVAILING_DEF
1722 && node
->resolution
!= LDPR_PREVAILING_DEF_IRONLY
1723 && node
->resolution
!= LDPR_PREVAILING_DEF_IRONLY_EXP
));
1726 /* Return true if NODE is local to a particular COMDAT group, and must not
1727 be named from outside the COMDAT. This is used for C++ decloned
1731 symtab_comdat_local_p (symtab_node
*node
)
1733 return (node
->same_comdat_group
&& !TREE_PUBLIC (node
->decl
));
1736 /* Return true if ONE and TWO are part of the same COMDAT group. */
1739 symtab_in_same_comdat_p (symtab_node
*one
, symtab_node
*two
)
1741 if (cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (one
))
1743 if (cn
->global
.inlined_to
)
1744 one
= cn
->global
.inlined_to
;
1746 if (cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (two
))
1748 if (cn
->global
.inlined_to
)
1749 two
= cn
->global
.inlined_to
;
1752 return one
->get_comdat_group () == two
->get_comdat_group ();
1754 #endif /* GCC_CGRAPH_H */