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 /* Base of all entries in the symbol table.
41 The symtab_node is inherited by cgraph and varpol nodes. */
42 class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
43 chain_next ("%h.next"), chain_prev ("%h.previous")))
48 const char *name () const;
50 /* Return asm name. */
51 const char * asm_name () const;
53 /* Type of the symbol. */
54 ENUM_BITFIELD (symtab_type
) type
: 8;
56 /* The symbols resolution. */
57 ENUM_BITFIELD (ld_plugin_symbol_resolution
) resolution
: 8;
59 /*** Flags representing the symbol type. ***/
61 /* True when symbol corresponds to a definition in current unit.
62 set via cgraph_finalize_function or varpool_finalize_decl */
63 unsigned definition
: 1;
64 /* True when symbol is an alias.
65 Set by assemble_alias. */
67 /* True when alias is a weakref. */
69 /* C++ frontend produce same body aliases and extra name aliases for
70 virtual functions and vtables that are obviously equivalent.
71 Those aliases are bit special, especially because C++ frontend
72 visibility code is so ugly it can not get them right at first time
73 and their visibility needs to be copied from their "masters" at
74 the end of parsing. */
75 unsigned cpp_implicit_alias
: 1;
76 /* Set once the definition was analyzed. The list of references and
77 other properties are built during analysis. */
78 unsigned analyzed
: 1;
81 /*** Visibility and linkage flags. ***/
83 /* Set when function is visible by other units. */
84 unsigned externally_visible
: 1;
85 /* The symbol will be assumed to be used in an invisible way (like
86 by an toplevel asm statement). */
87 unsigned force_output
: 1;
88 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
89 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
90 to static and it does not inhibit optimization. */
91 unsigned forced_by_abi
: 1;
92 /* True when the name is known to be unique and thus it does not need mangling. */
93 unsigned unique_name
: 1;
94 /* True when body and other characteristics have been removed by
95 symtab_remove_unreachable_nodes. */
96 unsigned body_removed
: 1;
98 /*** WHOPR Partitioning flags.
99 These flags are used at ltrans stage when only part of the callgraph is
102 /* Set when variable is used from other LTRANS partition. */
103 unsigned used_from_other_partition
: 1;
104 /* Set when function is available in the other LTRANS partition.
105 During WPA output it is used to mark nodes that are present in
106 multiple partitions. */
107 unsigned in_other_partition
: 1;
111 /*** other flags. ***/
113 /* Set when symbol has address taken. */
114 unsigned address_taken
: 1;
117 /* Ordering of all symtab entries. */
120 /* Declaration representing the symbol. */
123 /* Linked list of symbol table entries starting with symtab_nodes. */
125 symtab_node
*previous
;
127 /* Linked list of symbols with the same asm name. There may be multiple
128 entries for single symbol name during LTO, because symbols are renamed
129 only after partitioning.
131 Because inline clones are kept in the assembler name has, they also produce
134 There are also several long standing bugs where frontends and builtin
135 code produce duplicated decls. */
136 symtab_node
*next_sharing_asm_name
;
137 symtab_node
*previous_sharing_asm_name
;
139 /* Circular list of nodes in the same comdat group if non-NULL. */
140 symtab_node
*same_comdat_group
;
142 /* Vectors of referring and referenced entities. */
143 struct ipa_ref_list ref_list
;
145 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
146 depending to what was known to frontend on the creation time.
147 Once alias is resolved, this pointer become NULL. */
150 /* File stream where this node is being written to. */
151 struct lto_file_decl_data
* lto_file_data
;
153 PTR
GTY ((skip
)) aux
;
158 /* Not yet set by cgraph_function_body_availability. */
160 /* Function body/variable initializer is unknown. */
162 /* Function body/variable initializer is known but might be replaced
163 by a different one from other compilation unit and thus needs to
164 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
165 arbitrary side effects on escaping variables and functions, while
166 like AVAILABLE it might access static variables. */
168 /* Function body/variable initializer is known and will be used in final
171 /* Function body/variable initializer is known and all it's uses are explicitly
172 visible within current unit (ie it's address is never taken and it is not
173 exported to other units).
174 Currently used only for functions. */
178 /* This is the information that is put into the cgraph local structure
179 to recover a function. */
180 struct lto_file_decl_data
;
182 extern const char * const cgraph_availability_names
[];
183 extern const char * const ld_plugin_symbol_resolution_names
[];
185 /* Information about thunk, used only for same body aliases. */
187 struct GTY(()) cgraph_thunk_info
{
188 /* Information about the thunk. */
189 HOST_WIDE_INT fixed_offset
;
190 HOST_WIDE_INT virtual_value
;
193 bool virtual_offset_p
;
194 /* Set to true when alias node is thunk. */
198 /* Information about the function collected locally.
199 Available after function is analyzed. */
201 struct GTY(()) cgraph_local_info
{
202 /* Set when function function is visible in current compilation unit only
203 and its address is never taken. */
206 /* False when there is something makes versioning impossible. */
207 unsigned versionable
: 1;
209 /* False when function calling convention and signature can not be changed.
210 This is the case when __builtin_apply_args is used. */
211 unsigned can_change_signature
: 1;
213 /* True when the function has been originally extern inline, but it is
215 unsigned redefined_extern_inline
: 1;
217 /* True if the function may enter serial irrevocable mode. */
218 unsigned tm_may_enter_irr
: 1;
221 /* Information about the function that needs to be computed globally
222 once compilation is finished. Available only with -funit-at-a-time. */
224 struct GTY(()) cgraph_global_info
{
225 /* Estimated stack frame consumption by the function. */
226 HOST_WIDE_INT estimated_stack_size
;
228 /* For inline clones this points to the function they will be
230 struct cgraph_node
*inlined_to
;
233 /* Information about the function that is propagated by the RTL backend.
234 Available only for functions that has been already assembled. */
236 struct GTY(()) cgraph_rtl_info
{
237 unsigned int preferred_incoming_stack_boundary
;
240 /* Represent which DECL tree (or reference to such tree)
241 will be replaced by another tree while versioning. */
242 struct GTY(()) ipa_replace_map
244 /* The tree that will be replaced. */
246 /* The new (replacing) tree. */
248 /* Parameter number to replace, when old_tree is NULL. */
250 /* True when a substitution should be done, false otherwise. */
252 /* True when we replace a reference to old_tree. */
255 typedef struct ipa_replace_map
*ipa_replace_map_p
;
257 struct GTY(()) cgraph_clone_info
259 vec
<ipa_replace_map_p
, va_gc
> *tree_map
;
261 bitmap combined_args_to_skip
;
264 enum cgraph_simd_clone_arg_type
266 SIMD_CLONE_ARG_TYPE_VECTOR
,
267 SIMD_CLONE_ARG_TYPE_UNIFORM
,
268 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP
,
269 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP
,
270 SIMD_CLONE_ARG_TYPE_MASK
273 /* Function arguments in the original function of a SIMD clone.
274 Supplementary data for `struct simd_clone'. */
276 struct GTY(()) cgraph_simd_clone_arg
{
277 /* Original function argument as it originally existed in
281 /* orig_arg's function (or for extern functions type from
285 /* If argument is a vector, this holds the vector version of
286 orig_arg that after adjusting the argument types will live in
287 DECL_ARGUMENTS. Otherwise, this is NULL.
289 This basically holds:
290 vector(simdlen) __typeof__(orig_arg) new_arg. */
293 /* vector_arg's type (or for extern functions new vector type. */
296 /* If argument is a vector, this holds the array where the simd
297 argument is held while executing the simd clone function. This
298 is a local variable in the cloned function. Its content is
299 copied from vector_arg upon entry to the clone.
301 This basically holds:
302 __typeof__(orig_arg) simd_array[simdlen]. */
305 /* A SIMD clone's argument can be either linear (constant or
306 variable), uniform, or vector. */
307 enum cgraph_simd_clone_arg_type arg_type
;
309 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
310 the constant linear step, if arg_type is
311 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
312 the uniform argument holding the step, otherwise 0. */
313 HOST_WIDE_INT linear_step
;
315 /* Variable alignment if available, otherwise 0. */
316 unsigned int alignment
;
319 /* Specific data for a SIMD function clone. */
321 struct GTY(()) cgraph_simd_clone
{
322 /* Number of words in the SIMD lane associated with this clone. */
323 unsigned int simdlen
;
325 /* Number of annotated function arguments in `args'. This is
326 usually the number of named arguments in FNDECL. */
329 /* Max hardware vector size in bits for integral vectors. */
330 unsigned int vecsize_int
;
332 /* Max hardware vector size in bits for floating point vectors. */
333 unsigned int vecsize_float
;
335 /* The mangling character for a given vector size. This is is used
336 to determine the ISA mangling bit as specified in the Intel
338 unsigned char vecsize_mangle
;
340 /* True if this is the masked, in-branch version of the clone,
342 unsigned int inbranch
: 1;
344 /* True if this is a Cilk Plus variant. */
345 unsigned int cilk_elemental
: 1;
347 /* Doubly linked list of SIMD clones. */
348 struct cgraph_node
*prev_clone
, *next_clone
;
350 /* Original cgraph node the SIMD clones were created for. */
351 struct cgraph_node
*origin
;
353 /* Annotated function arguments for the original function. */
354 struct cgraph_simd_clone_arg
GTY((length ("%h.nargs"))) args
[1];
358 /* The cgraph data structure.
359 Each function decl has assigned cgraph_node listing callees and callers. */
361 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node
: public symtab_node
{
363 struct cgraph_edge
*callees
;
364 struct cgraph_edge
*callers
;
365 /* List of edges representing indirect calls with a yet undetermined
367 struct cgraph_edge
*indirect_calls
;
368 /* For nested functions points to function the node is nested in. */
369 struct cgraph_node
*origin
;
370 /* Points to first nested function, if any. */
371 struct cgraph_node
*nested
;
372 /* Pointer to the next function with same origin, if any. */
373 struct cgraph_node
*next_nested
;
374 /* Pointer to the next clone. */
375 struct cgraph_node
*next_sibling_clone
;
376 struct cgraph_node
*prev_sibling_clone
;
377 struct cgraph_node
*clones
;
378 struct cgraph_node
*clone_of
;
379 /* For functions with many calls sites it holds map from call expression
380 to the edge to speed up cgraph_edge function. */
381 htab_t
GTY((param_is (struct cgraph_edge
))) call_site_hash
;
382 /* Declaration node used to be clone of. */
383 tree former_clone_of
;
385 /* If this is a SIMD clone, this points to the SIMD specific
386 information for it. */
387 struct cgraph_simd_clone
*simdclone
;
388 /* If this function has SIMD clones, this points to the first clone. */
389 struct cgraph_node
*simd_clones
;
391 /* Interprocedural passes scheduled to have their transform functions
392 applied next time we execute local pass on them. We maintain it
393 per-function in order to allow IPA passes to introduce new functions. */
394 vec
<ipa_opt_pass
> GTY((skip
)) ipa_transforms_to_apply
;
396 struct cgraph_local_info local
;
397 struct cgraph_global_info global
;
398 struct cgraph_rtl_info rtl
;
399 struct cgraph_clone_info clone
;
400 struct cgraph_thunk_info thunk
;
402 /* Expected number of executions: calculated in profile.c. */
404 /* Maximum count of any basic block in the function. */
405 gcov_type max_bb_count
;
406 /* How to scale counts at materialization time; used to merge
407 LTO units with different number of profile runs. */
408 int count_materialization_scale
;
409 /* Unique id of the node. */
411 /* ID assigned by the profiling. */
412 unsigned int profile_id
;
413 /* Time profiler: first run of function. */
416 /* Set when decl is an abstract function pointed to by the
417 ABSTRACT_DECL_ORIGIN of a reachable function. */
418 unsigned used_as_abstract_origin
: 1;
419 /* Set once the function is lowered (i.e. its CFG is built). */
420 unsigned lowered
: 1;
421 /* Set once the function has been instantiated and its callee
423 unsigned process
: 1;
424 /* Is this function cloned during versioning ? */
425 unsigned is_versioned_clone
: 1;
426 /* How commonly executed the node is. Initialized during branch
427 probabilities pass. */
428 ENUM_BITFIELD (node_frequency
) frequency
: 2;
429 /* True when function can only be called at startup (from static ctor). */
430 unsigned only_called_at_startup
: 1;
431 /* True when function can only be called at startup (from static dtor). */
432 unsigned only_called_at_exit
: 1;
433 /* True when function is the transactional clone of a function which
434 is called only from inside transactions. */
435 /* ?? We should be able to remove this. We have enough bits in
436 cgraph to calculate it. */
437 unsigned tm_clone
: 1;
438 /* True if this decl is a dispatcher for function versions. */
439 unsigned dispatcher_function
: 1;
440 /* True if this decl calls a COMDAT-local function. This is set up in
441 compute_inline_parameters and inline_call. */
442 unsigned calls_comdat_local
: 1;
446 typedef struct cgraph_node
*cgraph_node_ptr
;
449 /* Function Multiversioning info. */
450 struct GTY(()) cgraph_function_version_info
{
451 /* The cgraph_node for which the function version info is stored. */
452 struct cgraph_node
*this_node
;
453 /* Chains all the semantically identical function versions. The
454 first function in this chain is the version_info node of the
456 struct cgraph_function_version_info
*prev
;
457 /* If this version node corresponds to a dispatcher for function
458 versions, this points to the version info node of the default
459 function, the first node in the chain. */
460 struct cgraph_function_version_info
*next
;
461 /* If this node corresponds to a function version, this points
462 to the dispatcher function decl, which is the function that must
463 be called to execute the right function version at run-time.
465 If this cgraph node is a dispatcher (if dispatcher_function is
466 true, in the cgraph_node struct) for function versions, this
467 points to resolver function, which holds the function body of the
468 dispatcher. The dispatcher decl is an alias to the resolver
470 tree dispatcher_resolver
;
473 /* Get the cgraph_function_version_info node corresponding to node. */
474 struct cgraph_function_version_info
*
475 get_cgraph_node_version (struct cgraph_node
*node
);
477 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
478 corresponding to cgraph_node NODE. */
479 struct cgraph_function_version_info
*
480 insert_new_cgraph_node_version (struct cgraph_node
*node
);
482 /* Record that DECL1 and DECL2 are semantically identical function
484 void record_function_versions (tree decl1
, tree decl2
);
486 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
487 DECL is a duplicate declaration. */
488 void delete_function_version (tree decl
);
490 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
491 can appear in multiple sets. */
492 struct cgraph_node_set_def
494 struct pointer_map_t
*map
;
495 vec
<cgraph_node_ptr
> nodes
;
499 typedef varpool_node
*varpool_node_ptr
;
502 /* A varpool node set is a collection of varpool nodes. A varpool node
503 can appear in multiple sets. */
504 struct varpool_node_set_def
506 struct pointer_map_t
* map
;
507 vec
<varpool_node_ptr
> nodes
;
510 typedef struct cgraph_node_set_def
*cgraph_node_set
;
513 typedef struct varpool_node_set_def
*varpool_node_set
;
516 /* Iterator structure for cgraph node sets. */
517 struct cgraph_node_set_iterator
523 /* Iterator structure for varpool node sets. */
524 struct varpool_node_set_iterator
526 varpool_node_set set
;
530 #define DEFCIFCODE(code, type, string) CIF_ ## code,
531 /* Reasons for inlining failures. */
532 enum cgraph_inline_failed_t
{
533 #include "cif-code.def"
537 enum cgraph_inline_failed_type_t
539 CIF_FINAL_NORMAL
= 0,
543 /* Structure containing additional information about an indirect call. */
545 struct GTY(()) cgraph_indirect_call_info
547 /* When polymorphic is set, this field contains offset where the object which
548 was actually used in the polymorphic resides within a larger structure.
549 If agg_contents is set, the field contains the offset within the aggregate
550 from which the address to call was loaded. */
551 HOST_WIDE_INT offset
;
552 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
553 HOST_WIDE_INT otr_token
;
554 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
555 tree otr_type
, outer_type
;
556 /* Index of the parameter that is called. */
558 /* ECF flags determined from the caller. */
560 /* Profile_id of common target obtrained from profile. */
561 int common_target_id
;
562 /* Probability that call will land in function with COMMON_TARGET_ID. */
563 int common_target_probability
;
565 /* Set when the call is a virtual call with the parameter being the
566 associated object pointer rather than a simple direct call. */
567 unsigned polymorphic
: 1;
568 /* Set when the call is a call of a pointer loaded from contents of an
569 aggregate at offset. */
570 unsigned agg_contents
: 1;
571 /* Set when this is a call through a member pointer. */
572 unsigned member_ptr
: 1;
573 /* When the previous bit is set, this one determines whether the destination
574 is loaded from a parameter passed by reference. */
576 unsigned int maybe_in_construction
: 1;
577 unsigned int maybe_derived_type
: 1;
580 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge
{
581 /* Expected number of executions: calculated in profile.c. */
583 struct cgraph_node
*caller
;
584 struct cgraph_node
*callee
;
585 struct cgraph_edge
*prev_caller
;
586 struct cgraph_edge
*next_caller
;
587 struct cgraph_edge
*prev_callee
;
588 struct cgraph_edge
*next_callee
;
590 /* Additional information about an indirect call. Not cleared when an edge
592 struct cgraph_indirect_call_info
*indirect_info
;
593 PTR
GTY ((skip (""))) aux
;
594 /* When equal to CIF_OK, inline this call. Otherwise, points to the
595 explanation why function was not inlined. */
596 enum cgraph_inline_failed_t inline_failed
;
597 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
598 when the function is serialized in. */
599 unsigned int lto_stmt_uid
;
600 /* Expected frequency of executions within the function.
601 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
602 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
604 /* Unique id of the edge. */
606 /* Whether this edge was made direct by indirect inlining. */
607 unsigned int indirect_inlining_edge
: 1;
608 /* Whether this edge describes an indirect call with an undetermined
610 unsigned int indirect_unknown_callee
: 1;
611 /* Whether this edge is still a dangling */
612 /* True if the corresponding CALL stmt cannot be inlined. */
613 unsigned int call_stmt_cannot_inline_p
: 1;
614 /* Can this call throw externally? */
615 unsigned int can_throw_external
: 1;
616 /* Edges with SPECULATIVE flag represents indirect calls that was
617 speculatively turned into direct (i.e. by profile feedback).
618 The final code sequence will have form:
620 if (call_target == expected_fn)
625 Every speculative call is represented by three components attached
626 to a same call statement:
627 1) a direct call (to expected_fn)
628 2) an indirect call (to call_target)
629 3) a IPA_REF_ADDR refrence to expected_fn.
631 Optimizers may later redirect direct call to clone, so 1) and 3)
632 do not need to necesarily agree with destination. */
633 unsigned int speculative
: 1;
636 #define CGRAPH_FREQ_BASE 1000
637 #define CGRAPH_FREQ_MAX 100000
639 typedef struct cgraph_edge
*cgraph_edge_p
;
642 /* The varpool data structure.
643 Each static variable decl has assigned varpool_node. */
645 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node
: public symtab_node
{
647 /* The module in which it is first declared. */
649 /* Set when variable is scheduled to be assembled. */
652 /* Set if the variable is dynamically initialized, except for
653 function local statics. */
654 unsigned dynamically_initialized
: 1;
657 /* Every top level asm statement is put into a asm_node. */
659 struct GTY(()) asm_node
{
661 struct asm_node
*next
;
662 /* String for this asm node. */
664 /* Ordering of all cgraph nodes. */
668 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
673 is_a_helper
<cgraph_node
>::test (symtab_node
*p
)
675 return p
->type
== SYMTAB_FUNCTION
;
678 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
683 is_a_helper
<varpool_node
>::test (symtab_node
*p
)
685 return p
->type
== SYMTAB_VARIABLE
;
688 extern GTY(()) symtab_node
*symtab_nodes
;
689 extern GTY(()) int cgraph_n_nodes
;
690 extern GTY(()) int cgraph_max_uid
;
691 extern GTY(()) int cgraph_edge_max_uid
;
692 extern bool cgraph_global_info_ready
;
695 /* Frontend is parsing and finalizing functions. */
696 CGRAPH_STATE_PARSING
,
697 /* Callgraph is being constructed. It is safe to add new functions. */
698 CGRAPH_STATE_CONSTRUCTION
,
699 /* Callgraph is being at LTO time. */
700 CGRAPH_LTO_STREAMING
,
701 /* Callgraph is built and IPA passes are being run. */
703 /* Callgraph is built and all functions are transformed to SSA form. */
704 CGRAPH_STATE_IPA_SSA
,
705 /* Functions are now ordered and being passed to RTL expanders. */
706 CGRAPH_STATE_EXPANSION
,
707 /* All cgraph expansion is done. */
708 CGRAPH_STATE_FINISHED
710 extern enum cgraph_state cgraph_state
;
711 extern bool cgraph_function_flags_ready
;
712 extern cgraph_node_set cgraph_new_nodes
;
714 extern GTY(()) struct asm_node
*asm_nodes
;
715 extern GTY(()) int symtab_order
;
716 extern bool cpp_implicit_aliases_done
;
718 /* Classifcation of symbols WRT partitioning. */
719 enum symbol_partitioning_class
721 /* External declarations are ignored by partitioning algorithms and they are
722 added into the boundary later via compute_ltrans_boundary. */
724 /* Partitioned symbols are pur into one of partitions. */
726 /* Duplicated symbols (such as comdat or constant pool references) are
727 copied into every node needing them via add_symbol_to_partition. */
733 hashval_t
decl_assembler_name_hash (const_tree
);
734 bool decl_assembler_name_equal (tree decl
, const_tree
);
735 void symtab_register_node (symtab_node
*);
736 void symtab_unregister_node (symtab_node
*);
737 void symtab_remove_node (symtab_node
*);
738 symtab_node
*symtab_get_node (const_tree
);
739 symtab_node
*symtab_node_for_asm (const_tree asmname
);
740 void symtab_insert_node_to_hashtable (symtab_node
*);
741 void symtab_add_to_same_comdat_group (symtab_node
*, symtab_node
*);
742 void symtab_dissolve_same_comdat_group_list (symtab_node
*node
);
743 void dump_symtab (FILE *);
744 void debug_symtab (void);
745 void dump_symtab_node (FILE *, symtab_node
*);
746 void debug_symtab_node (symtab_node
*);
747 void dump_symtab_base (FILE *, symtab_node
*);
748 void verify_symtab (void);
749 void verify_symtab_node (symtab_node
*);
750 bool verify_symtab_base (symtab_node
*);
751 bool symtab_used_from_object_file_p (symtab_node
*);
752 void symtab_make_decl_local (tree
);
753 void unlink_from_assembler_name_hash (symtab_node
*, bool);
754 void insert_to_assembler_name_hash (symtab_node
*, bool);
755 symtab_node
*symtab_alias_ultimate_target (symtab_node
*,
756 enum availability
*avail
= NULL
);
757 bool symtab_resolve_alias (symtab_node
*node
, symtab_node
*target
);
758 void fixup_same_cpp_alias_visibility (symtab_node
*node
, symtab_node
*target
);
759 bool symtab_for_node_and_aliases (symtab_node
*,
760 bool (*) (symtab_node
*, void *),
763 symtab_node
*symtab_nonoverwritable_alias (symtab_node
*);
764 enum availability
symtab_node_availability (symtab_node
*);
765 bool symtab_semantically_equivalent_p (symtab_node
*, symtab_node
*);
766 enum symbol_partitioning_class
symtab_get_symbol_partitioning_class (symtab_node
*);
769 void dump_cgraph (FILE *);
770 void debug_cgraph (void);
771 void dump_cgraph_node (FILE *, struct cgraph_node
*);
772 void debug_cgraph_node (struct cgraph_node
*);
773 void cgraph_remove_edge (struct cgraph_edge
*);
774 void cgraph_remove_node (struct cgraph_node
*);
775 void cgraph_remove_fake_indirect_call_in_edges (struct cgraph_node
*);
776 extern bool cgraph_pre_profiling_inlining_done
;
777 extern bool cgraph_is_fake_indirect_call_edge (struct cgraph_edge
*e
);
778 void cgraph_add_to_same_comdat_group (struct cgraph_node
*, struct cgraph_node
*);
779 void cgraph_remove_node_and_inline_clones (struct cgraph_node
*);
780 void cgraph_release_function_body (struct cgraph_node
*);
781 void release_function_body (tree
);
782 void cgraph_node_remove_callees (struct cgraph_node
*node
);
783 struct cgraph_edge
*cgraph_create_edge (struct cgraph_node
*,
784 struct cgraph_node
*,
785 gimple
, gcov_type
, int);
786 struct cgraph_edge
*cgraph_create_indirect_edge (struct cgraph_node
*, gimple
,
787 int, gcov_type
, int);
788 struct cgraph_indirect_call_info
*cgraph_allocate_init_indirect_info (void);
789 struct cgraph_node
* cgraph_create_node (tree
);
790 struct cgraph_node
* cgraph_create_empty_node (void);
791 struct cgraph_node
* cgraph_get_create_node (tree
);
792 struct cgraph_node
* cgraph_same_body_alias (struct cgraph_node
*, tree
, tree
);
793 struct cgraph_node
* cgraph_add_thunk (struct cgraph_node
*, tree
, tree
, bool, HOST_WIDE_INT
,
794 HOST_WIDE_INT
, tree
, tree
);
795 struct cgraph_node
*cgraph_node_for_asm (tree
);
796 struct cgraph_edge
*cgraph_edge (struct cgraph_node
*, gimple
);
797 void cgraph_set_call_stmt (struct cgraph_edge
*, gimple
, bool update_speculative
= true);
798 void cgraph_update_edges_for_call_stmt (gimple
, tree
, gimple
);
799 struct cgraph_local_info
*cgraph_local_info (tree
);
800 struct cgraph_global_info
*cgraph_global_info (tree
);
801 struct cgraph_rtl_info
*cgraph_rtl_info (tree
);
802 struct cgraph_node
*cgraph_create_function_alias (tree
, tree
);
803 void cgraph_call_node_duplication_hooks (struct cgraph_node
*,
804 struct cgraph_node
*);
805 void cgraph_call_edge_duplication_hooks (struct cgraph_edge
*,
806 struct cgraph_edge
*);
808 void cgraph_redirect_edge_callee (struct cgraph_edge
*, struct cgraph_node
*);
809 struct cgraph_edge
*cgraph_make_edge_direct (struct cgraph_edge
*, struct cgraph_node
*);
810 bool cgraph_only_called_directly_p (struct cgraph_node
*);
812 bool cgraph_function_possibly_inlined_p (tree
);
813 void cgraph_unnest_node (struct cgraph_node
*);
815 enum availability
cgraph_function_body_availability (struct cgraph_node
*);
816 void cgraph_add_new_function (tree
, bool);
817 const char* cgraph_inline_failed_string (cgraph_inline_failed_t
);
818 cgraph_inline_failed_type_t
cgraph_inline_failed_type (cgraph_inline_failed_t
);
820 void cgraph_set_nothrow_flag (struct cgraph_node
*, bool);
821 void cgraph_set_const_flag (struct cgraph_node
*, bool, bool);
822 void cgraph_set_pure_flag (struct cgraph_node
*, bool, bool);
823 bool cgraph_node_cannot_return (struct cgraph_node
*);
824 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge
*);
825 bool cgraph_will_be_removed_from_program_if_no_direct_calls
826 (struct cgraph_node
*node
);
827 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
828 (struct cgraph_node
*node
);
829 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node
*node
);
830 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution
);
831 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node
*,
832 bool (*) (struct cgraph_node
*, void *),
835 bool cgraph_for_node_and_aliases (struct cgraph_node
*,
836 bool (*) (struct cgraph_node
*, void *),
838 vec
<cgraph_edge_p
> collect_callers_of_node (struct cgraph_node
*node
);
839 void verify_cgraph (void);
840 void verify_cgraph_node (struct cgraph_node
*);
841 void cgraph_mark_address_taken_node (struct cgraph_node
*);
843 /* Module info structure. */
844 struct GTY (()) cgraph_mod_info
849 /* LIPO linker symbol table entry for function symbols. */
850 struct GTY (()) cgraph_sym
853 struct cgraph_node
*rep_node
;
855 htab_t
GTY ((param_is (struct cgraph_mod_info
))) def_module_hash
;
856 bool is_promoted_static
;
859 void cgraph_init_gid_map (void);
860 void cgraph_add_fake_indirect_call_edges (void);
861 void cgraph_remove_zero_count_fake_edges (void);
862 void cgraph_do_link (void);
863 struct cgraph_sym
*cgraph_link_node (struct cgraph_node
*);
864 tree
cgraph_find_decl (tree asm_name
);
865 void cgraph_remove_link_node (struct cgraph_node
*node
);
866 struct cgraph_node
*cgraph_lipo_get_resolved_node (tree decl
);
867 struct cgraph_node
*cgraph_lipo_get_resolved_node_1 (tree decl
, bool);
868 unsigned cgraph_get_module_id (tree fndecl
);
869 bool cgraph_is_auxiliary (tree fndecl
);
870 void cgraph_process_module_scope_statics (void);
871 bool cgraph_is_promoted_static_func (tree fndecl
);
872 bool cgraph_is_inline_body_available_in_module (tree fndecl
, unsigned module_id
);
873 bool cgraph_is_aux_decl_external (struct cgraph_node
*);
874 void cgraph_unify_type_alias_sets (void);
875 void varpool_do_link (void);
876 void varpool_link_node (struct varpool_node
*);
877 void varpool_remove_link_node (struct varpool_node
*node
);
878 struct varpool_node
*real_varpool_node (tree decl
);
879 bool varpool_is_auxiliary (struct varpool_node
*node
);
880 void varpool_get_referenced_asm_ids (vec
<tree
, va_gc
> **);
881 void varpool_clear_asm_id_reference_bit (void);
882 void varpool_reset_queue (void);
883 void varpool_remove_duplicate_weak_decls (void);
885 bool cgraph_decide_is_function_needed (struct cgraph_node
*, tree
);
887 typedef void (*cgraph_edge_hook
)(struct cgraph_edge
*, void *);
888 typedef void (*cgraph_node_hook
)(struct cgraph_node
*, void *);
889 typedef void (*varpool_node_hook
)(varpool_node
*, void *);
890 typedef void (*cgraph_2edge_hook
)(struct cgraph_edge
*, struct cgraph_edge
*,
892 typedef void (*cgraph_2node_hook
)(struct cgraph_node
*, struct cgraph_node
*,
894 struct cgraph_edge_hook_list
;
895 struct cgraph_node_hook_list
;
896 struct varpool_node_hook_list
;
897 struct cgraph_2edge_hook_list
;
898 struct cgraph_2node_hook_list
;
899 struct cgraph_edge_hook_list
*cgraph_add_edge_removal_hook (cgraph_edge_hook
, void *);
900 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list
*);
901 struct cgraph_node_hook_list
*cgraph_add_node_removal_hook (cgraph_node_hook
,
903 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list
*);
904 struct varpool_node_hook_list
*varpool_add_node_removal_hook (varpool_node_hook
,
906 void varpool_remove_node_removal_hook (struct varpool_node_hook_list
*);
907 struct cgraph_node_hook_list
*cgraph_add_function_insertion_hook (cgraph_node_hook
,
909 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list
*);
910 struct varpool_node_hook_list
*varpool_add_variable_insertion_hook (varpool_node_hook
,
912 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list
*);
913 void cgraph_call_function_insertion_hooks (struct cgraph_node
*node
);
914 struct cgraph_2edge_hook_list
*cgraph_add_edge_duplication_hook (cgraph_2edge_hook
, void *);
915 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list
*);
916 struct cgraph_2node_hook_list
*cgraph_add_node_duplication_hook (cgraph_2node_hook
, void *);
917 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list
*);
918 gimple
cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge
*);
919 struct cgraph_node
* cgraph_function_node (struct cgraph_node
*,
920 enum availability
*avail
= NULL
);
921 bool cgraph_get_body (struct cgraph_node
*node
);
923 cgraph_turn_edge_to_speculative (struct cgraph_edge
*,
924 struct cgraph_node
*,
926 void cgraph_speculative_call_info (struct cgraph_edge
*,
927 struct cgraph_edge
*&,
928 struct cgraph_edge
*&,
930 extern bool gimple_check_call_matching_types (gimple
, tree
, bool);
932 /* In cgraphunit.c */
933 struct asm_node
*add_asm_node (tree
);
934 extern FILE *cgraph_dump_file
;
935 void cgraph_finalize_function (tree
, bool);
936 void finalize_compilation_unit (void);
938 void init_cgraph (void);
939 void cgraph_process_new_functions (void);
940 void cgraph_process_same_body_aliases (void);
941 void fixup_same_cpp_alias_visibility (symtab_node
*, symtab_node
*target
, tree
);
942 /* Initialize datastructures so DECL is a function in lowered gimple form.
943 IN_SSA is true if the gimple is in SSA. */
944 basic_block
init_lowered_empty_function (tree
, bool);
945 void cgraph_reset_node (struct cgraph_node
*);
946 void cgraph_enqueue_node (struct cgraph_node
*);
947 bool expand_thunk (struct cgraph_node
*, bool);
949 /* In cgraphclones.c */
951 struct cgraph_edge
* cgraph_clone_edge (struct cgraph_edge
*,
952 struct cgraph_node
*, gimple
,
953 unsigned, gcov_type
, int, bool);
954 struct cgraph_node
* cgraph_clone_node (struct cgraph_node
*, tree
, gcov_type
,
955 int, bool, vec
<cgraph_edge_p
>,
956 bool, struct cgraph_node
*);
957 tree
clone_function_name (tree decl
, const char *);
958 struct cgraph_node
* cgraph_create_virtual_clone (struct cgraph_node
*old_node
,
960 vec
<ipa_replace_map_p
, va_gc
> *tree_map
,
962 const char *clone_name
);
963 struct cgraph_node
*cgraph_find_replacement_node (struct cgraph_node
*);
964 bool cgraph_remove_node_and_inline_clones (struct cgraph_node
*, struct cgraph_node
*);
965 void cgraph_set_call_stmt_including_clones (struct cgraph_node
*, gimple
, gimple
,
966 bool update_speculative
= true);
967 void cgraph_create_edge_including_clones (struct cgraph_node
*,
968 struct cgraph_node
*,
969 gimple
, gimple
, gcov_type
, int,
970 cgraph_inline_failed_t
);
971 void cgraph_materialize_all_clones (void);
972 struct cgraph_node
* cgraph_copy_node_for_versioning (struct cgraph_node
*,
973 tree
, vec
<cgraph_edge_p
>, bitmap
);
974 struct cgraph_node
*cgraph_function_versioning (struct cgraph_node
*,
976 vec
<ipa_replace_map_p
, va_gc
> *,
977 bitmap
, bool, bitmap
,
978 basic_block
, const char *);
979 void tree_function_versioning (tree
, tree
, vec
<ipa_replace_map_p
, va_gc
> *,
980 bool, bitmap
, bool, bitmap
, basic_block
);
981 struct cgraph_edge
*cgraph_resolve_speculation (struct cgraph_edge
*, tree
);
983 /* In cgraphbuild.c */
984 unsigned int rebuild_cgraph_edges (void);
985 void cgraph_rebuild_references (void);
986 int compute_call_stmt_bb_frequency (tree
, basic_block bb
);
987 void record_references_in_initializer (tree
, bool);
988 void ipa_record_stmt_references (struct cgraph_node
*, gimple
);
991 bool symtab_remove_unreachable_nodes (bool, FILE *);
992 cgraph_node_set
cgraph_node_set_new (void);
993 cgraph_node_set_iterator
cgraph_node_set_find (cgraph_node_set
,
994 struct cgraph_node
*);
995 void cgraph_node_set_add (cgraph_node_set
, struct cgraph_node
*);
996 void cgraph_node_set_remove (cgraph_node_set
, struct cgraph_node
*);
997 void dump_cgraph_node_set (FILE *, cgraph_node_set
);
998 void debug_cgraph_node_set (cgraph_node_set
);
999 void free_cgraph_node_set (cgraph_node_set
);
1000 void cgraph_build_static_cdtor (char which
, tree body
, int priority
);
1002 varpool_node_set
varpool_node_set_new (void);
1003 varpool_node_set_iterator
varpool_node_set_find (varpool_node_set
,
1005 void varpool_node_set_add (varpool_node_set
, varpool_node
*);
1006 void varpool_node_set_remove (varpool_node_set
, varpool_node
*);
1007 void dump_varpool_node_set (FILE *, varpool_node_set
);
1008 void debug_varpool_node_set (varpool_node_set
);
1009 void free_varpool_node_set (varpool_node_set
);
1010 void ipa_discover_readonly_nonaddressable_vars (void);
1011 bool varpool_externally_visible_p (varpool_node
*);
1014 bool cgraph_maybe_hot_edge_p (struct cgraph_edge
*e
);
1015 bool cgraph_optimize_for_size_p (struct cgraph_node
*);
1018 varpool_node
*varpool_create_empty_node (void);
1019 varpool_node
*varpool_node_for_decl (tree
);
1020 varpool_node
*varpool_node_for_asm (tree asmname
);
1021 void varpool_mark_needed_node (varpool_node
*);
1022 void debug_varpool (void);
1023 void dump_varpool (FILE *);
1024 void dump_varpool_node (FILE *, varpool_node
*);
1026 void varpool_finalize_decl (tree
);
1027 enum availability
cgraph_variable_initializer_availability (varpool_node
*);
1028 void cgraph_make_node_local (struct cgraph_node
*);
1029 bool cgraph_node_can_be_local_p (struct cgraph_node
*);
1032 void varpool_remove_node (varpool_node
*node
);
1033 void varpool_finalize_named_section_flags (varpool_node
*node
);
1034 bool varpool_output_variables (void);
1035 bool varpool_assemble_decl (varpool_node
*node
);
1036 void varpool_analyze_node (varpool_node
*);
1037 varpool_node
* varpool_extra_name_alias (tree
, tree
);
1038 varpool_node
* varpool_create_variable_alias (tree
, tree
);
1039 void varpool_reset_queue (void);
1040 tree
ctor_for_folding (tree
);
1041 bool varpool_for_node_and_aliases (varpool_node
*,
1042 bool (*) (varpool_node
*, void *),
1044 void varpool_add_new_variable (tree
);
1045 void symtab_initialize_asm_name_hash (void);
1046 void symtab_prevail_in_asm_name_hash (symtab_node
*node
);
1047 void varpool_remove_initializer (varpool_node
*);
1050 extern void change_decl_assembler_name (tree
, tree
);
1052 /* Return callgraph node for given symbol and check it is a function. */
1053 static inline struct cgraph_node
*
1054 cgraph (symtab_node
*node
)
1056 gcc_checking_assert (!node
|| node
->type
== SYMTAB_FUNCTION
);
1057 return (struct cgraph_node
*)node
;
1060 /* Return varpool node for given symbol and check it is a variable. */
1061 static inline varpool_node
*
1062 varpool (symtab_node
*node
)
1064 gcc_checking_assert (!node
|| node
->type
== SYMTAB_VARIABLE
);
1065 return (varpool_node
*)node
;
1068 /* Return callgraph node for given symbol and check it is a function. */
1069 static inline struct cgraph_node
*
1070 cgraph_get_node (const_tree decl
)
1072 gcc_checking_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1073 return cgraph (symtab_get_node (decl
));
1076 /* Return varpool node for given symbol and check it is a function. */
1077 static inline varpool_node
*
1078 varpool_get_node (const_tree decl
)
1080 gcc_checking_assert (TREE_CODE (decl
) == VAR_DECL
);
1081 return varpool (symtab_get_node (decl
));
1084 /* Walk all symbols. */
1085 #define FOR_EACH_SYMBOL(node) \
1086 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1089 /* Return first variable. */
1090 static inline varpool_node
*
1091 varpool_first_variable (void)
1094 for (node
= symtab_nodes
; node
; node
= node
->next
)
1095 if (varpool_node
*vnode
= dyn_cast
<varpool_node
> (node
))
1100 /* Return next variable after NODE. */
1101 static inline varpool_node
*
1102 varpool_next_variable (varpool_node
*node
)
1104 symtab_node
*node1
= node
->next
;
1105 for (; node1
; node1
= node1
->next
)
1106 if (varpool_node
*vnode1
= dyn_cast
<varpool_node
> (node1
))
1110 /* Walk all variables. */
1111 #define FOR_EACH_VARIABLE(node) \
1112 for ((node) = varpool_first_variable (); \
1114 (node) = varpool_next_variable ((node)))
1116 /* Return first reachable static variable with initializer. */
1117 static inline varpool_node
*
1118 varpool_first_static_initializer (void)
1121 for (node
= symtab_nodes
; node
; node
= node
->next
)
1123 varpool_node
*vnode
= dyn_cast
<varpool_node
> (node
);
1124 if (vnode
&& DECL_INITIAL (node
->decl
))
1130 /* Return next reachable static variable with initializer after NODE. */
1131 static inline varpool_node
*
1132 varpool_next_static_initializer (varpool_node
*node
)
1134 symtab_node
*node1
= node
->next
;
1135 for (; node1
; node1
= node1
->next
)
1137 varpool_node
*vnode1
= dyn_cast
<varpool_node
> (node1
);
1138 if (vnode1
&& DECL_INITIAL (node1
->decl
))
1144 /* Walk all static variables with initializer set. */
1145 #define FOR_EACH_STATIC_INITIALIZER(node) \
1146 for ((node) = varpool_first_static_initializer (); (node); \
1147 (node) = varpool_next_static_initializer (node))
1149 /* Return first reachable static variable with initializer. */
1150 static inline varpool_node
*
1151 varpool_first_defined_variable (void)
1154 for (node
= symtab_nodes
; node
; node
= node
->next
)
1156 varpool_node
*vnode
= dyn_cast
<varpool_node
> (node
);
1157 if (vnode
&& vnode
->definition
)
1163 /* Return next reachable static variable with initializer after NODE. */
1164 static inline varpool_node
*
1165 varpool_next_defined_variable (varpool_node
*node
)
1167 symtab_node
*node1
= node
->next
;
1168 for (; node1
; node1
= node1
->next
)
1170 varpool_node
*vnode1
= dyn_cast
<varpool_node
> (node1
);
1171 if (vnode1
&& vnode1
->definition
)
1176 /* Walk all variables with definitions in current unit. */
1177 #define FOR_EACH_DEFINED_VARIABLE(node) \
1178 for ((node) = varpool_first_defined_variable (); (node); \
1179 (node) = varpool_next_defined_variable (node))
1181 /* Return first function with body defined. */
1182 static inline struct cgraph_node
*
1183 cgraph_first_defined_function (void)
1186 for (node
= symtab_nodes
; node
; node
= node
->next
)
1188 cgraph_node
*cn
= dyn_cast
<cgraph_node
> (node
);
1189 if (cn
&& cn
->definition
)
1195 /* Return next function with body defined after NODE. */
1196 static inline struct cgraph_node
*
1197 cgraph_next_defined_function (struct cgraph_node
*node
)
1199 symtab_node
*node1
= node
->next
;
1200 for (; node1
; node1
= node1
->next
)
1202 cgraph_node
*cn1
= dyn_cast
<cgraph_node
> (node1
);
1203 if (cn1
&& cn1
->definition
)
1209 /* Walk all functions with body defined. */
1210 #define FOR_EACH_DEFINED_FUNCTION(node) \
1211 for ((node) = cgraph_first_defined_function (); (node); \
1212 (node) = cgraph_next_defined_function ((node)))
1214 /* Return first function. */
1215 static inline struct cgraph_node
*
1216 cgraph_first_function (void)
1219 for (node
= symtab_nodes
; node
; node
= node
->next
)
1220 if (cgraph_node
*cn
= dyn_cast
<cgraph_node
> (node
))
1225 /* Return next function. */
1226 static inline struct cgraph_node
*
1227 cgraph_next_function (struct cgraph_node
*node
)
1229 symtab_node
*node1
= node
->next
;
1230 for (; node1
; node1
= node1
->next
)
1231 if (cgraph_node
*cn1
= dyn_cast
<cgraph_node
> (node1
))
1235 /* Walk all functions. */
1236 #define FOR_EACH_FUNCTION(node) \
1237 for ((node) = cgraph_first_function (); (node); \
1238 (node) = cgraph_next_function ((node)))
1240 /* Return true when NODE is a function with Gimple body defined
1241 in current unit. Functions can also be define externally or they
1242 can be thunks with no Gimple representation.
1244 Note that at WPA stage, the function body may not be present in memory. */
1247 cgraph_function_with_gimple_body_p (struct cgraph_node
*node
)
1249 return node
->definition
&& !node
->thunk
.thunk_p
&& !node
->alias
;
1252 /* Return first function with body defined. */
1253 static inline struct cgraph_node
*
1254 cgraph_first_function_with_gimple_body (void)
1257 for (node
= symtab_nodes
; node
; node
= node
->next
)
1259 cgraph_node
*cn
= dyn_cast
<cgraph_node
> (node
);
1260 if (cn
&& cgraph_function_with_gimple_body_p (cn
))
1266 /* Return next reachable static variable with initializer after NODE. */
1267 static inline struct cgraph_node
*
1268 cgraph_next_function_with_gimple_body (struct cgraph_node
*node
)
1270 symtab_node
*node1
= node
->next
;
1271 for (; node1
; node1
= node1
->next
)
1273 cgraph_node
*cn1
= dyn_cast
<cgraph_node
> (node1
);
1274 if (cn1
&& cgraph_function_with_gimple_body_p (cn1
))
1280 /* Walk all functions with body defined. */
1281 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1282 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1283 (node) = cgraph_next_function_with_gimple_body (node))
1285 /* Create a new static variable of type TYPE. */
1286 tree
add_new_static_var (tree type
);
1288 /* Return true if iterator CSI points to nothing. */
1290 csi_end_p (cgraph_node_set_iterator csi
)
1292 return csi
.index
>= csi
.set
->nodes
.length ();
1295 /* Advance iterator CSI. */
1297 csi_next (cgraph_node_set_iterator
*csi
)
1302 /* Return the node pointed to by CSI. */
1303 static inline struct cgraph_node
*
1304 csi_node (cgraph_node_set_iterator csi
)
1306 return csi
.set
->nodes
[csi
.index
];
1309 /* Return an iterator to the first node in SET. */
1310 static inline cgraph_node_set_iterator
1311 csi_start (cgraph_node_set set
)
1313 cgraph_node_set_iterator csi
;
1320 /* Return true if SET contains NODE. */
1322 cgraph_node_in_set_p (struct cgraph_node
*node
, cgraph_node_set set
)
1324 cgraph_node_set_iterator csi
;
1325 csi
= cgraph_node_set_find (set
, node
);
1326 return !csi_end_p (csi
);
1329 /* Return number of nodes in SET. */
1330 static inline size_t
1331 cgraph_node_set_size (cgraph_node_set set
)
1333 return set
->nodes
.length ();
1336 /* Return true if iterator VSI points to nothing. */
1338 vsi_end_p (varpool_node_set_iterator vsi
)
1340 return vsi
.index
>= vsi
.set
->nodes
.length ();
1343 /* Advance iterator VSI. */
1345 vsi_next (varpool_node_set_iterator
*vsi
)
1350 /* Return the node pointed to by VSI. */
1351 static inline varpool_node
*
1352 vsi_node (varpool_node_set_iterator vsi
)
1354 return vsi
.set
->nodes
[vsi
.index
];
1357 /* Return an iterator to the first node in SET. */
1358 static inline varpool_node_set_iterator
1359 vsi_start (varpool_node_set set
)
1361 varpool_node_set_iterator vsi
;
1368 /* Return true if SET contains NODE. */
1370 varpool_node_in_set_p (varpool_node
*node
, varpool_node_set set
)
1372 varpool_node_set_iterator vsi
;
1373 vsi
= varpool_node_set_find (set
, node
);
1374 return !vsi_end_p (vsi
);
1377 /* Return number of nodes in SET. */
1378 static inline size_t
1379 varpool_node_set_size (varpool_node_set set
)
1381 return set
->nodes
.length ();
1384 /* Uniquize all constants that appear in memory.
1385 Each constant in memory thus far output is recorded
1386 in `const_desc_table'. */
1388 struct GTY(()) constant_descriptor_tree
{
1389 /* A MEM for the constant. */
1392 /* The value of the constant. */
1395 /* Hash of value. Computing the hash from value each time
1396 hashfn is called can't work properly, as that means recursive
1397 use of the hash table during hash table expansion. */
1401 /* Return true if set is nonempty. */
1403 cgraph_node_set_nonempty_p (cgraph_node_set set
)
1405 return !set
->nodes
.is_empty ();
1408 /* Return true if set is nonempty. */
1410 varpool_node_set_nonempty_p (varpool_node_set set
)
1412 return !set
->nodes
.is_empty ();
1415 /* Return true when function NODE is only called directly or it has alias.
1416 i.e. it is not externally visible, address was not taken and
1417 it is not used in any other non-standard way. */
1420 cgraph_only_called_directly_or_aliased_p (struct cgraph_node
*node
)
1422 gcc_assert (!node
->global
.inlined_to
);
1423 return (!node
->force_output
&& !node
->address_taken
1424 && !node
->used_from_other_partition
1425 && !DECL_VIRTUAL_P (node
->decl
)
1426 && !DECL_STATIC_CONSTRUCTOR (node
->decl
)
1427 && !DECL_STATIC_DESTRUCTOR (node
->decl
)
1428 && !node
->externally_visible
);
1431 /* Return true when function NODE can be removed from callgraph
1432 if all direct calls are eliminated. */
1435 varpool_can_remove_if_no_refs (varpool_node
*node
)
1437 if (DECL_EXTERNAL (node
->decl
))
1439 return (!node
->force_output
&& !node
->used_from_other_partition
1440 && ((DECL_COMDAT (node
->decl
)
1441 && !node
->forced_by_abi
1442 && !symtab_used_from_object_file_p (node
))
1443 || !node
->externally_visible
1444 || DECL_HAS_VALUE_EXPR_P (node
->decl
)));
1447 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1448 i.e. if the variable is not externally visible or not used in some magic
1449 way (asm statement or such).
1450 The magic uses are all summarized in force_output flag. */
1453 varpool_all_refs_explicit_p (varpool_node
*vnode
)
1455 return (vnode
->definition
1456 && !vnode
->externally_visible
1457 && !vnode
->used_from_other_partition
1458 && !vnode
->force_output
);
1461 /* Constant pool accessor function. */
1462 htab_t
constant_pool_htab (void);
1464 /* FIXME: inappropriate dependency of cgraph on IPA. */
1465 #include "ipa-ref-inline.h"
1467 /* Return node that alias N is aliasing. */
1469 static inline symtab_node
*
1470 symtab_alias_target (symtab_node
*n
)
1472 struct ipa_ref
*ref
;
1473 ipa_ref_list_reference_iterate (&n
->ref_list
, 0, ref
);
1474 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1475 return ref
->referred
;
1478 static inline struct cgraph_node
*
1479 cgraph_alias_target (struct cgraph_node
*n
)
1481 return dyn_cast
<cgraph_node
> (symtab_alias_target (n
));
1484 static inline varpool_node
*
1485 varpool_alias_target (varpool_node
*n
)
1487 return dyn_cast
<varpool_node
> (symtab_alias_target (n
));
1490 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1491 Do not walk through thunks.
1492 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1494 static inline struct cgraph_node
*
1495 cgraph_function_or_thunk_node (struct cgraph_node
*node
,
1496 enum availability
*availability
= NULL
)
1498 struct cgraph_node
*n
;
1500 n
= dyn_cast
<cgraph_node
> (symtab_alias_ultimate_target (node
,
1502 if (!n
&& availability
)
1503 *availability
= AVAIL_NOT_AVAILABLE
;
1506 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1507 Do not walk through thunks.
1508 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1510 static inline varpool_node
*
1511 varpool_variable_node (varpool_node
*node
,
1512 enum availability
*availability
= NULL
)
1517 n
= dyn_cast
<varpool_node
> (symtab_alias_ultimate_target (node
,
1522 if (!n
&& availability
)
1523 *availability
= AVAIL_NOT_AVAILABLE
;
1527 /* Return true when the edge E represents a direct recursion. */
1529 cgraph_edge_recursive_p (struct cgraph_edge
*e
)
1531 struct cgraph_node
*callee
= cgraph_function_or_thunk_node (e
->callee
, NULL
);
1532 if (e
->caller
->global
.inlined_to
)
1533 return e
->caller
->global
.inlined_to
->decl
== callee
->decl
;
1535 return e
->caller
->decl
== callee
->decl
;
1538 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1540 decl_is_tm_clone (const_tree fndecl
)
1542 struct cgraph_node
*n
= cgraph_get_node (fndecl
);
1548 /* Likewise indicate that a node is needed, i.e. reachable via some
1552 cgraph_mark_force_output_node (struct cgraph_node
*node
)
1554 node
->force_output
= 1;
1555 gcc_checking_assert (!node
->global
.inlined_to
);
1558 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1559 or abstract function kept for debug info purposes only. */
1562 symtab_real_symbol_p (symtab_node
*node
)
1564 struct cgraph_node
*cnode
;
1566 if (DECL_ABSTRACT (node
->decl
))
1568 if (!is_a
<cgraph_node
> (node
))
1570 cnode
= cgraph (node
);
1571 if (cnode
->global
.inlined_to
)
1576 /* Return true if NODE can be discarded by linker from the binary. */
1579 symtab_can_be_discarded (symtab_node
*node
)
1581 return (DECL_EXTERNAL (node
->decl
)
1582 || (DECL_ONE_ONLY (node
->decl
)
1583 && node
->resolution
!= LDPR_PREVAILING_DEF
1584 && node
->resolution
!= LDPR_PREVAILING_DEF_IRONLY
1585 && node
->resolution
!= LDPR_PREVAILING_DEF_IRONLY_EXP
));
1588 /* Return true if NODE is local to a particular COMDAT group, and must not
1589 be named from outside the COMDAT. This is used for C++ decloned
1593 symtab_comdat_local_p (symtab_node
*node
)
1595 return (node
->same_comdat_group
&& !TREE_PUBLIC (node
->decl
));
1598 /* Return true if ONE and TWO are part of the same COMDAT group. */
1601 symtab_in_same_comdat_p (symtab_node
*one
, symtab_node
*two
)
1603 return DECL_COMDAT_GROUP (one
->decl
) == DECL_COMDAT_GROUP (two
->decl
);
1605 #endif /* GCC_CGRAPH_H */