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;
79 /* Set for write-only variables. */
80 unsigned writeonly
: 1;
83 /*** Visibility and linkage flags. ***/
85 /* Set when function is visible by other units. */
86 unsigned externally_visible
: 1;
87 /* The symbol will be assumed to be used in an invisible way (like
88 by an toplevel asm statement). */
89 unsigned force_output
: 1;
90 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
91 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
92 to static and it does not inhibit optimization. */
93 unsigned forced_by_abi
: 1;
94 /* True when the name is known to be unique and thus it does not need mangling. */
95 unsigned unique_name
: 1;
96 /* True when body and other characteristics have been removed by
97 symtab_remove_unreachable_nodes. */
98 unsigned body_removed
: 1;
100 /*** WHOPR Partitioning flags.
101 These flags are used at ltrans stage when only part of the callgraph is
104 /* Set when variable is used from other LTRANS partition. */
105 unsigned used_from_other_partition
: 1;
106 /* Set when function is available in the other LTRANS partition.
107 During WPA output it is used to mark nodes that are present in
108 multiple partitions. */
109 unsigned in_other_partition
: 1;
113 /*** other flags. ***/
115 /* Set when symbol has address taken. */
116 unsigned address_taken
: 1;
119 /* Ordering of all symtab entries. */
122 /* Declaration representing the symbol. */
125 /* Linked list of symbol table entries starting with symtab_nodes. */
127 symtab_node
*previous
;
129 /* Linked list of symbols with the same asm name. There may be multiple
130 entries for single symbol name during LTO, because symbols are renamed
131 only after partitioning.
133 Because inline clones are kept in the assembler name has, they also produce
136 There are also several long standing bugs where frontends and builtin
137 code produce duplicated decls. */
138 symtab_node
*next_sharing_asm_name
;
139 symtab_node
*previous_sharing_asm_name
;
141 /* Circular list of nodes in the same comdat group if non-NULL. */
142 symtab_node
*same_comdat_group
;
144 /* Return comdat group. */
145 tree
get_comdat_group ()
147 return comdat_group_
;
150 /* Set comdat group. */
151 void set_comdat_group (tree group
)
153 comdat_group_
= group
;
156 /* Vectors of referring and referenced entities. */
157 struct ipa_ref_list ref_list
;
159 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
160 depending to what was known to frontend on the creation time.
161 Once alias is resolved, this pointer become NULL. */
164 /* File stream where this node is being written to. */
165 struct lto_file_decl_data
* lto_file_data
;
167 PTR
GTY ((skip
)) aux
;
169 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
175 /* Not yet set by cgraph_function_body_availability. */
177 /* Function body/variable initializer is unknown. */
179 /* Function body/variable initializer is known but might be replaced
180 by a different one from other compilation unit and thus needs to
181 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
182 arbitrary side effects on escaping variables and functions, while
183 like AVAILABLE it might access static variables. */
185 /* Function body/variable initializer is known and will be used in final
188 /* Function body/variable initializer is known and all it's uses are explicitly
189 visible within current unit (ie it's address is never taken and it is not
190 exported to other units).
191 Currently used only for functions. */
195 /* This is the information that is put into the cgraph local structure
196 to recover a function. */
197 struct lto_file_decl_data
;
199 extern const char * const cgraph_availability_names
[];
200 extern const char * const ld_plugin_symbol_resolution_names
[];
202 /* Information about thunk, used only for same body aliases. */
204 struct GTY(()) cgraph_thunk_info
{
205 /* Information about the thunk. */
206 HOST_WIDE_INT fixed_offset
;
207 HOST_WIDE_INT virtual_value
;
210 bool virtual_offset_p
;
211 /* Set to true when alias node is thunk. */
215 /* Information about the function collected locally.
216 Available after function is analyzed. */
218 struct GTY(()) cgraph_local_info
{
219 /* Set when function function is visible in current compilation unit only
220 and its address is never taken. */
223 /* False when there is something makes versioning impossible. */
224 unsigned versionable
: 1;
226 /* False when function calling convention and signature can not be changed.
227 This is the case when __builtin_apply_args is used. */
228 unsigned can_change_signature
: 1;
230 /* True when the function has been originally extern inline, but it is
232 unsigned redefined_extern_inline
: 1;
234 /* True if the function may enter serial irrevocable mode. */
235 unsigned tm_may_enter_irr
: 1;
238 /* Information about the function that needs to be computed globally
239 once compilation is finished. Available only with -funit-at-a-time. */
241 struct GTY(()) cgraph_global_info
{
242 /* For inline clones this points to the function they will be
244 struct cgraph_node
*inlined_to
;
247 /* Information about the function that is propagated by the RTL backend.
248 Available only for functions that has been already assembled. */
250 struct GTY(()) cgraph_rtl_info
{
251 unsigned int preferred_incoming_stack_boundary
;
253 /* Call unsaved hard registers really used by the corresponding
254 function (including ones used by functions called by the
256 HARD_REG_SET function_used_regs
;
257 /* Set if function_used_regs is valid. */
258 unsigned function_used_regs_valid
: 1;
261 /* Represent which DECL tree (or reference to such tree)
262 will be replaced by another tree while versioning. */
263 struct GTY(()) ipa_replace_map
265 /* The tree that will be replaced. */
267 /* The new (replacing) tree. */
269 /* Parameter number to replace, when old_tree is NULL. */
271 /* True when a substitution should be done, false otherwise. */
273 /* True when we replace a reference to old_tree. */
276 typedef struct ipa_replace_map
*ipa_replace_map_p
;
278 struct GTY(()) cgraph_clone_info
280 vec
<ipa_replace_map_p
, va_gc
> *tree_map
;
282 bitmap combined_args_to_skip
;
285 enum cgraph_simd_clone_arg_type
287 SIMD_CLONE_ARG_TYPE_VECTOR
,
288 SIMD_CLONE_ARG_TYPE_UNIFORM
,
289 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP
,
290 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP
,
291 SIMD_CLONE_ARG_TYPE_MASK
294 /* Function arguments in the original function of a SIMD clone.
295 Supplementary data for `struct simd_clone'. */
297 struct GTY(()) cgraph_simd_clone_arg
{
298 /* Original function argument as it originally existed in
302 /* orig_arg's function (or for extern functions type from
306 /* If argument is a vector, this holds the vector version of
307 orig_arg that after adjusting the argument types will live in
308 DECL_ARGUMENTS. Otherwise, this is NULL.
310 This basically holds:
311 vector(simdlen) __typeof__(orig_arg) new_arg. */
314 /* vector_arg's type (or for extern functions new vector type. */
317 /* If argument is a vector, this holds the array where the simd
318 argument is held while executing the simd clone function. This
319 is a local variable in the cloned function. Its content is
320 copied from vector_arg upon entry to the clone.
322 This basically holds:
323 __typeof__(orig_arg) simd_array[simdlen]. */
326 /* A SIMD clone's argument can be either linear (constant or
327 variable), uniform, or vector. */
328 enum cgraph_simd_clone_arg_type arg_type
;
330 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
331 the constant linear step, if arg_type is
332 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
333 the uniform argument holding the step, otherwise 0. */
334 HOST_WIDE_INT linear_step
;
336 /* Variable alignment if available, otherwise 0. */
337 unsigned int alignment
;
340 /* Specific data for a SIMD function clone. */
342 struct GTY(()) cgraph_simd_clone
{
343 /* Number of words in the SIMD lane associated with this clone. */
344 unsigned int simdlen
;
346 /* Number of annotated function arguments in `args'. This is
347 usually the number of named arguments in FNDECL. */
350 /* Max hardware vector size in bits for integral vectors. */
351 unsigned int vecsize_int
;
353 /* Max hardware vector size in bits for floating point vectors. */
354 unsigned int vecsize_float
;
356 /* The mangling character for a given vector size. This is is used
357 to determine the ISA mangling bit as specified in the Intel
359 unsigned char vecsize_mangle
;
361 /* True if this is the masked, in-branch version of the clone,
363 unsigned int inbranch
: 1;
365 /* True if this is a Cilk Plus variant. */
366 unsigned int cilk_elemental
: 1;
368 /* Doubly linked list of SIMD clones. */
369 struct cgraph_node
*prev_clone
, *next_clone
;
371 /* Original cgraph node the SIMD clones were created for. */
372 struct cgraph_node
*origin
;
374 /* Annotated function arguments for the original function. */
375 struct cgraph_simd_clone_arg
GTY((length ("%h.nargs"))) args
[1];
379 /* The cgraph data structure.
380 Each function decl has assigned cgraph_node listing callees and callers. */
382 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node
: public symtab_node
{
384 struct cgraph_edge
*callees
;
385 struct cgraph_edge
*callers
;
386 /* List of edges representing indirect calls with a yet undetermined
388 struct cgraph_edge
*indirect_calls
;
389 /* For nested functions points to function the node is nested in. */
390 struct cgraph_node
*origin
;
391 /* Points to first nested function, if any. */
392 struct cgraph_node
*nested
;
393 /* Pointer to the next function with same origin, if any. */
394 struct cgraph_node
*next_nested
;
395 /* Pointer to the next clone. */
396 struct cgraph_node
*next_sibling_clone
;
397 struct cgraph_node
*prev_sibling_clone
;
398 struct cgraph_node
*clones
;
399 struct cgraph_node
*clone_of
;
400 /* For functions with many calls sites it holds map from call expression
401 to the edge to speed up cgraph_edge function. */
402 htab_t
GTY((param_is (struct cgraph_edge
))) call_site_hash
;
403 /* Declaration node used to be clone of. */
404 tree former_clone_of
;
406 /* If this is a SIMD clone, this points to the SIMD specific
407 information for it. */
408 struct cgraph_simd_clone
*simdclone
;
409 /* If this function has SIMD clones, this points to the first clone. */
410 struct cgraph_node
*simd_clones
;
412 /* Interprocedural passes scheduled to have their transform functions
413 applied next time we execute local pass on them. We maintain it
414 per-function in order to allow IPA passes to introduce new functions. */
415 vec
<ipa_opt_pass
> GTY((skip
)) ipa_transforms_to_apply
;
417 struct cgraph_local_info local
;
418 struct cgraph_global_info global
;
419 struct cgraph_rtl_info rtl
;
420 struct cgraph_clone_info clone
;
421 struct cgraph_thunk_info thunk
;
423 /* Expected number of executions: calculated in profile.c. */
425 /* How to scale counts at materialization time; used to merge
426 LTO units with different number of profile runs. */
427 int count_materialization_scale
;
428 /* Unique id of the node. */
430 /* ID assigned by the profiling. */
431 unsigned int profile_id
;
432 /* Time profiler: first run of function. */
435 /* Set when decl is an abstract function pointed to by the
436 ABSTRACT_DECL_ORIGIN of a reachable function. */
437 unsigned used_as_abstract_origin
: 1;
438 /* Set once the function is lowered (i.e. its CFG is built). */
439 unsigned lowered
: 1;
440 /* Set once the function has been instantiated and its callee
442 unsigned process
: 1;
443 /* How commonly executed the node is. Initialized during branch
444 probabilities pass. */
445 ENUM_BITFIELD (node_frequency
) frequency
: 2;
446 /* True when function can only be called at startup (from static ctor). */
447 unsigned only_called_at_startup
: 1;
448 /* True when function can only be called at startup (from static dtor). */
449 unsigned only_called_at_exit
: 1;
450 /* True when function is the transactional clone of a function which
451 is called only from inside transactions. */
452 /* ?? We should be able to remove this. We have enough bits in
453 cgraph to calculate it. */
454 unsigned tm_clone
: 1;
455 /* True if this decl is a dispatcher for function versions. */
456 unsigned dispatcher_function
: 1;
457 /* True if this decl calls a COMDAT-local function. This is set up in
458 compute_inline_parameters and inline_call. */
459 unsigned calls_comdat_local
: 1;
463 typedef struct cgraph_node
*cgraph_node_ptr
;
466 /* Function Multiversioning info. */
467 struct GTY(()) cgraph_function_version_info
{
468 /* The cgraph_node for which the function version info is stored. */
469 struct cgraph_node
*this_node
;
470 /* Chains all the semantically identical function versions. The
471 first function in this chain is the version_info node of the
473 struct cgraph_function_version_info
*prev
;
474 /* If this version node corresponds to a dispatcher for function
475 versions, this points to the version info node of the default
476 function, the first node in the chain. */
477 struct cgraph_function_version_info
*next
;
478 /* If this node corresponds to a function version, this points
479 to the dispatcher function decl, which is the function that must
480 be called to execute the right function version at run-time.
482 If this cgraph node is a dispatcher (if dispatcher_function is
483 true, in the cgraph_node struct) for function versions, this
484 points to resolver function, which holds the function body of the
485 dispatcher. The dispatcher decl is an alias to the resolver
487 tree dispatcher_resolver
;
490 /* Get the cgraph_function_version_info node corresponding to node. */
491 struct cgraph_function_version_info
*
492 get_cgraph_node_version (struct cgraph_node
*node
);
494 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
495 corresponding to cgraph_node NODE. */
496 struct cgraph_function_version_info
*
497 insert_new_cgraph_node_version (struct cgraph_node
*node
);
499 /* Record that DECL1 and DECL2 are semantically identical function
501 void record_function_versions (tree decl1
, tree decl2
);
503 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
504 DECL is a duplicate declaration. */
505 void delete_function_version (tree decl
);
507 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
508 can appear in multiple sets. */
509 struct cgraph_node_set_def
511 struct pointer_map_t
*map
;
512 vec
<cgraph_node_ptr
> nodes
;
516 typedef varpool_node
*varpool_node_ptr
;
519 /* A varpool node set is a collection of varpool nodes. A varpool node
520 can appear in multiple sets. */
521 struct varpool_node_set_def
523 struct pointer_map_t
* map
;
524 vec
<varpool_node_ptr
> nodes
;
527 typedef struct cgraph_node_set_def
*cgraph_node_set
;
530 typedef struct varpool_node_set_def
*varpool_node_set
;
533 /* Iterator structure for cgraph node sets. */
534 struct cgraph_node_set_iterator
540 /* Iterator structure for varpool node sets. */
541 struct varpool_node_set_iterator
543 varpool_node_set set
;
547 #define DEFCIFCODE(code, type, string) CIF_ ## code,
548 /* Reasons for inlining failures. */
549 enum cgraph_inline_failed_t
{
550 #include "cif-code.def"
554 enum cgraph_inline_failed_type_t
556 CIF_FINAL_NORMAL
= 0,
560 /* Structure containing additional information about an indirect call. */
562 struct GTY(()) cgraph_indirect_call_info
564 /* When polymorphic is set, this field contains offset where the object which
565 was actually used in the polymorphic resides within a larger structure.
566 If agg_contents is set, the field contains the offset within the aggregate
567 from which the address to call was loaded. */
568 HOST_WIDE_INT offset
;
569 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
570 HOST_WIDE_INT otr_token
;
571 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
572 tree otr_type
, outer_type
;
573 /* Index of the parameter that is called. */
575 /* ECF flags determined from the caller. */
577 /* Profile_id of common target obtrained from profile. */
578 int common_target_id
;
579 /* Probability that call will land in function with COMMON_TARGET_ID. */
580 int common_target_probability
;
582 /* Set when the call is a virtual call with the parameter being the
583 associated object pointer rather than a simple direct call. */
584 unsigned polymorphic
: 1;
585 /* Set when the call is a call of a pointer loaded from contents of an
586 aggregate at offset. */
587 unsigned agg_contents
: 1;
588 /* Set when this is a call through a member pointer. */
589 unsigned member_ptr
: 1;
590 /* When the previous bit is set, this one determines whether the destination
591 is loaded from a parameter passed by reference. */
593 unsigned int maybe_in_construction
: 1;
594 unsigned int maybe_derived_type
: 1;
597 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge
{
598 /* Expected number of executions: calculated in profile.c. */
600 struct cgraph_node
*caller
;
601 struct cgraph_node
*callee
;
602 struct cgraph_edge
*prev_caller
;
603 struct cgraph_edge
*next_caller
;
604 struct cgraph_edge
*prev_callee
;
605 struct cgraph_edge
*next_callee
;
607 /* Additional information about an indirect call. Not cleared when an edge
609 struct cgraph_indirect_call_info
*indirect_info
;
610 PTR
GTY ((skip (""))) aux
;
611 /* When equal to CIF_OK, inline this call. Otherwise, points to the
612 explanation why function was not inlined. */
613 enum cgraph_inline_failed_t inline_failed
;
614 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
615 when the function is serialized in. */
616 unsigned int lto_stmt_uid
;
617 /* Expected frequency of executions within the function.
618 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
619 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
621 /* Unique id of the edge. */
623 /* Whether this edge was made direct by indirect inlining. */
624 unsigned int indirect_inlining_edge
: 1;
625 /* Whether this edge describes an indirect call with an undetermined
627 unsigned int indirect_unknown_callee
: 1;
628 /* Whether this edge is still a dangling */
629 /* True if the corresponding CALL stmt cannot be inlined. */
630 unsigned int call_stmt_cannot_inline_p
: 1;
631 /* Can this call throw externally? */
632 unsigned int can_throw_external
: 1;
633 /* Edges with SPECULATIVE flag represents indirect calls that was
634 speculatively turned into direct (i.e. by profile feedback).
635 The final code sequence will have form:
637 if (call_target == expected_fn)
642 Every speculative call is represented by three components attached
643 to a same call statement:
644 1) a direct call (to expected_fn)
645 2) an indirect call (to call_target)
646 3) a IPA_REF_ADDR refrence to expected_fn.
648 Optimizers may later redirect direct call to clone, so 1) and 3)
649 do not need to necesarily agree with destination. */
650 unsigned int speculative
: 1;
653 #define CGRAPH_FREQ_BASE 1000
654 #define CGRAPH_FREQ_MAX 100000
656 typedef struct cgraph_edge
*cgraph_edge_p
;
659 /* The varpool data structure.
660 Each static variable decl has assigned varpool_node. */
662 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node
: public symtab_node
{
664 /* Set when variable is scheduled to be assembled. */
667 /* Set if the variable is dynamically initialized, except for
668 function local statics. */
669 unsigned dynamically_initialized
: 1;
672 /* Every top level asm statement is put into a asm_node. */
674 struct GTY(()) asm_node
{
676 struct asm_node
*next
;
677 /* String for this asm node. */
679 /* Ordering of all cgraph nodes. */
683 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
688 is_a_helper
<cgraph_node
*>::test (symtab_node
*p
)
690 return p
->type
== SYMTAB_FUNCTION
;
693 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
698 is_a_helper
<varpool_node
*>::test (symtab_node
*p
)
700 return p
->type
== SYMTAB_VARIABLE
;
703 extern GTY(()) symtab_node
*symtab_nodes
;
704 extern GTY(()) int cgraph_n_nodes
;
705 extern GTY(()) int cgraph_max_uid
;
706 extern GTY(()) int cgraph_edge_max_uid
;
707 extern bool cgraph_global_info_ready
;
710 /* Frontend is parsing and finalizing functions. */
711 CGRAPH_STATE_PARSING
,
712 /* Callgraph is being constructed. It is safe to add new functions. */
713 CGRAPH_STATE_CONSTRUCTION
,
714 /* Callgraph is being at LTO time. */
715 CGRAPH_LTO_STREAMING
,
716 /* Callgraph is built and IPA passes are being run. */
718 /* Callgraph is built and all functions are transformed to SSA form. */
719 CGRAPH_STATE_IPA_SSA
,
720 /* Functions are now ordered and being passed to RTL expanders. */
721 CGRAPH_STATE_EXPANSION
,
722 /* All cgraph expansion is done. */
723 CGRAPH_STATE_FINISHED
725 extern enum cgraph_state cgraph_state
;
726 extern bool cgraph_function_flags_ready
;
727 extern cgraph_node_set cgraph_new_nodes
;
729 extern GTY(()) struct asm_node
*asm_nodes
;
730 extern GTY(()) int symtab_order
;
731 extern bool cpp_implicit_aliases_done
;
733 /* Classifcation of symbols WRT partitioning. */
734 enum symbol_partitioning_class
736 /* External declarations are ignored by partitioning algorithms and they are
737 added into the boundary later via compute_ltrans_boundary. */
739 /* Partitioned symbols are pur into one of partitions. */
741 /* Duplicated symbols (such as comdat or constant pool references) are
742 copied into every node needing them via add_symbol_to_partition. */
748 void symtab_register_node (symtab_node
*);
749 void symtab_unregister_node (symtab_node
*);
750 void symtab_remove_from_same_comdat_group (symtab_node
*);
751 void symtab_remove_node (symtab_node
*);
752 symtab_node
*symtab_node_for_asm (const_tree asmname
);
753 void symtab_add_to_same_comdat_group (symtab_node
*, symtab_node
*);
754 void symtab_dissolve_same_comdat_group_list (symtab_node
*node
);
755 void dump_symtab (FILE *);
756 void debug_symtab (void);
757 void dump_symtab_node (FILE *, symtab_node
*);
758 void debug_symtab_node (symtab_node
*);
759 void dump_symtab_base (FILE *, symtab_node
*);
760 void verify_symtab (void);
761 void verify_symtab_node (symtab_node
*);
762 bool verify_symtab_base (symtab_node
*);
763 bool symtab_used_from_object_file_p (symtab_node
*);
764 void symtab_make_decl_local (tree
);
765 symtab_node
*symtab_alias_ultimate_target (symtab_node
*,
766 enum availability
*avail
= NULL
);
767 bool symtab_resolve_alias (symtab_node
*node
, symtab_node
*target
);
768 void fixup_same_cpp_alias_visibility (symtab_node
*node
, symtab_node
*target
);
769 bool symtab_for_node_and_aliases (symtab_node
*,
770 bool (*) (symtab_node
*, void *),
773 symtab_node
*symtab_nonoverwritable_alias (symtab_node
*);
774 enum availability
symtab_node_availability (symtab_node
*);
775 bool symtab_semantically_equivalent_p (symtab_node
*, symtab_node
*);
776 enum symbol_partitioning_class
symtab_get_symbol_partitioning_class (symtab_node
*);
779 void dump_cgraph (FILE *);
780 void debug_cgraph (void);
781 void dump_cgraph_node (FILE *, struct cgraph_node
*);
782 void debug_cgraph_node (struct cgraph_node
*);
783 void cgraph_remove_edge (struct cgraph_edge
*);
784 void cgraph_remove_node (struct cgraph_node
*);
785 void cgraph_release_function_body (struct cgraph_node
*);
786 void release_function_body (tree
);
787 void cgraph_node_remove_callees (struct cgraph_node
*node
);
788 struct cgraph_edge
*cgraph_create_edge (struct cgraph_node
*,
789 struct cgraph_node
*,
790 gimple
, gcov_type
, int);
791 struct cgraph_edge
*cgraph_create_indirect_edge (struct cgraph_node
*, gimple
,
792 int, gcov_type
, int);
793 struct cgraph_indirect_call_info
*cgraph_allocate_init_indirect_info (void);
794 struct cgraph_node
* cgraph_create_node (tree
);
795 struct cgraph_node
* cgraph_create_empty_node (void);
796 struct cgraph_node
* cgraph_get_create_node (tree
);
797 struct cgraph_node
* cgraph_same_body_alias (struct cgraph_node
*, tree
, tree
);
798 struct cgraph_node
* cgraph_add_thunk (struct cgraph_node
*, tree
, tree
, bool, HOST_WIDE_INT
,
799 HOST_WIDE_INT
, tree
, tree
);
800 struct cgraph_node
*cgraph_node_for_asm (tree
);
801 struct cgraph_edge
*cgraph_edge (struct cgraph_node
*, gimple
);
802 void cgraph_set_call_stmt (struct cgraph_edge
*, gimple
, bool update_speculative
= true);
803 void cgraph_update_edges_for_call_stmt (gimple
, tree
, gimple
);
804 struct cgraph_local_info
*cgraph_local_info (tree
);
805 struct cgraph_global_info
*cgraph_global_info (tree
);
806 struct cgraph_rtl_info
*cgraph_rtl_info (tree
);
807 struct cgraph_node
*cgraph_create_function_alias (tree
, tree
);
808 void cgraph_call_node_duplication_hooks (struct cgraph_node
*,
809 struct cgraph_node
*);
810 void cgraph_call_edge_duplication_hooks (struct cgraph_edge
*,
811 struct cgraph_edge
*);
813 void cgraph_redirect_edge_callee (struct cgraph_edge
*, struct cgraph_node
*);
814 struct cgraph_edge
*cgraph_make_edge_direct (struct cgraph_edge
*, struct cgraph_node
*);
815 bool cgraph_only_called_directly_p (struct cgraph_node
*);
817 bool cgraph_function_possibly_inlined_p (tree
);
818 void cgraph_unnest_node (struct cgraph_node
*);
820 enum availability
cgraph_function_body_availability (struct cgraph_node
*);
821 void cgraph_add_new_function (tree
, bool);
822 const char* cgraph_inline_failed_string (cgraph_inline_failed_t
);
823 cgraph_inline_failed_type_t
cgraph_inline_failed_type (cgraph_inline_failed_t
);
825 void cgraph_set_nothrow_flag (struct cgraph_node
*, bool);
826 void cgraph_set_const_flag (struct cgraph_node
*, bool, bool);
827 void cgraph_set_pure_flag (struct cgraph_node
*, bool, bool);
828 bool cgraph_node_cannot_return (struct cgraph_node
*);
829 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge
*);
830 bool cgraph_will_be_removed_from_program_if_no_direct_calls
831 (struct cgraph_node
*node
);
832 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
833 (struct cgraph_node
*node
);
834 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node
*node
);
835 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution
);
836 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node
*,
837 bool (*) (struct cgraph_node
*, void *),
840 bool cgraph_for_node_and_aliases (struct cgraph_node
*,
841 bool (*) (struct cgraph_node
*, void *),
843 vec
<cgraph_edge_p
> collect_callers_of_node (struct cgraph_node
*node
);
844 void verify_cgraph (void);
845 void verify_cgraph_node (struct cgraph_node
*);
846 void cgraph_mark_address_taken_node (struct cgraph_node
*);
848 typedef void (*cgraph_edge_hook
)(struct cgraph_edge
*, void *);
849 typedef void (*cgraph_node_hook
)(struct cgraph_node
*, void *);
850 typedef void (*varpool_node_hook
)(varpool_node
*, void *);
851 typedef void (*cgraph_2edge_hook
)(struct cgraph_edge
*, struct cgraph_edge
*,
853 typedef void (*cgraph_2node_hook
)(struct cgraph_node
*, struct cgraph_node
*,
855 struct cgraph_edge_hook_list
;
856 struct cgraph_node_hook_list
;
857 struct varpool_node_hook_list
;
858 struct cgraph_2edge_hook_list
;
859 struct cgraph_2node_hook_list
;
860 struct cgraph_edge_hook_list
*cgraph_add_edge_removal_hook (cgraph_edge_hook
, void *);
861 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list
*);
862 struct cgraph_node_hook_list
*cgraph_add_node_removal_hook (cgraph_node_hook
,
864 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list
*);
865 struct varpool_node_hook_list
*varpool_add_node_removal_hook (varpool_node_hook
,
867 void varpool_remove_node_removal_hook (struct varpool_node_hook_list
*);
868 struct cgraph_node_hook_list
*cgraph_add_function_insertion_hook (cgraph_node_hook
,
870 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list
*);
871 struct varpool_node_hook_list
*varpool_add_variable_insertion_hook (varpool_node_hook
,
873 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list
*);
874 void cgraph_call_function_insertion_hooks (struct cgraph_node
*node
);
875 struct cgraph_2edge_hook_list
*cgraph_add_edge_duplication_hook (cgraph_2edge_hook
, void *);
876 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list
*);
877 struct cgraph_2node_hook_list
*cgraph_add_node_duplication_hook (cgraph_2node_hook
, void *);
878 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list
*);
879 gimple
cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge
*);
880 struct cgraph_node
* cgraph_function_node (struct cgraph_node
*,
881 enum availability
*avail
= NULL
);
882 bool cgraph_get_body (struct cgraph_node
*node
);
884 cgraph_turn_edge_to_speculative (struct cgraph_edge
*,
885 struct cgraph_node
*,
887 void cgraph_speculative_call_info (struct cgraph_edge
*,
888 struct cgraph_edge
*&,
889 struct cgraph_edge
*&,
891 extern bool gimple_check_call_matching_types (gimple
, tree
, bool);
893 /* In cgraphunit.c */
894 struct asm_node
*add_asm_node (tree
);
895 extern FILE *cgraph_dump_file
;
896 void cgraph_finalize_function (tree
, bool);
897 void finalize_compilation_unit (void);
899 void init_cgraph (void);
900 void cgraph_process_new_functions (void);
901 void cgraph_process_same_body_aliases (void);
902 void fixup_same_cpp_alias_visibility (symtab_node
*, symtab_node
*target
, tree
);
903 /* Initialize datastructures so DECL is a function in lowered gimple form.
904 IN_SSA is true if the gimple is in SSA. */
905 basic_block
init_lowered_empty_function (tree
, bool);
906 void cgraph_reset_node (struct cgraph_node
*);
907 bool expand_thunk (struct cgraph_node
*, bool);
909 /* In cgraphclones.c */
911 struct cgraph_edge
* cgraph_clone_edge (struct cgraph_edge
*,
912 struct cgraph_node
*, gimple
,
913 unsigned, gcov_type
, int, bool);
914 struct cgraph_node
* cgraph_clone_node (struct cgraph_node
*, tree
, gcov_type
,
915 int, bool, vec
<cgraph_edge_p
>,
916 bool, struct cgraph_node
*, bitmap
);
917 tree
clone_function_name (tree decl
, const char *);
918 struct cgraph_node
* cgraph_create_virtual_clone (struct cgraph_node
*old_node
,
920 vec
<ipa_replace_map_p
, va_gc
> *tree_map
,
922 const char *clone_name
);
923 struct cgraph_node
*cgraph_find_replacement_node (struct cgraph_node
*);
924 bool cgraph_remove_node_and_inline_clones (struct cgraph_node
*, struct cgraph_node
*);
925 void cgraph_set_call_stmt_including_clones (struct cgraph_node
*, gimple
, gimple
,
926 bool update_speculative
= true);
927 void cgraph_create_edge_including_clones (struct cgraph_node
*,
928 struct cgraph_node
*,
929 gimple
, gimple
, gcov_type
, int,
930 cgraph_inline_failed_t
);
931 void cgraph_materialize_all_clones (void);
932 struct cgraph_node
* cgraph_copy_node_for_versioning (struct cgraph_node
*,
933 tree
, vec
<cgraph_edge_p
>, bitmap
);
934 struct cgraph_node
*cgraph_function_versioning (struct cgraph_node
*,
936 vec
<ipa_replace_map_p
, va_gc
> *,
937 bitmap
, bool, bitmap
,
938 basic_block
, const char *);
939 void tree_function_versioning (tree
, tree
, vec
<ipa_replace_map_p
, va_gc
> *,
940 bool, bitmap
, bool, bitmap
, basic_block
);
941 struct cgraph_edge
*cgraph_resolve_speculation (struct cgraph_edge
*, tree
);
943 /* In cgraphbuild.c */
944 unsigned int rebuild_cgraph_edges (void);
945 void cgraph_rebuild_references (void);
946 int compute_call_stmt_bb_frequency (tree
, basic_block bb
);
947 void record_references_in_initializer (tree
, bool);
948 void ipa_record_stmt_references (struct cgraph_node
*, gimple
);
951 bool symtab_remove_unreachable_nodes (bool, FILE *);
952 cgraph_node_set
cgraph_node_set_new (void);
953 cgraph_node_set_iterator
cgraph_node_set_find (cgraph_node_set
,
954 struct cgraph_node
*);
955 void cgraph_node_set_add (cgraph_node_set
, struct cgraph_node
*);
956 void cgraph_node_set_remove (cgraph_node_set
, struct cgraph_node
*);
957 void dump_cgraph_node_set (FILE *, cgraph_node_set
);
958 void debug_cgraph_node_set (cgraph_node_set
);
959 void free_cgraph_node_set (cgraph_node_set
);
960 void cgraph_build_static_cdtor (char which
, tree body
, int priority
);
962 varpool_node_set
varpool_node_set_new (void);
963 varpool_node_set_iterator
varpool_node_set_find (varpool_node_set
,
965 void varpool_node_set_add (varpool_node_set
, varpool_node
*);
966 void varpool_node_set_remove (varpool_node_set
, varpool_node
*);
967 void dump_varpool_node_set (FILE *, varpool_node_set
);
968 void debug_varpool_node_set (varpool_node_set
);
969 void free_varpool_node_set (varpool_node_set
);
970 void ipa_discover_readonly_nonaddressable_vars (void);
971 bool varpool_externally_visible_p (varpool_node
*);
973 /* In ipa-visibility.c */
974 bool cgraph_local_node_p (struct cgraph_node
*);
978 bool cgraph_maybe_hot_edge_p (struct cgraph_edge
*e
);
979 bool cgraph_optimize_for_size_p (struct cgraph_node
*);
982 varpool_node
*varpool_create_empty_node (void);
983 varpool_node
*varpool_node_for_decl (tree
);
984 varpool_node
*varpool_node_for_asm (tree asmname
);
985 void varpool_mark_needed_node (varpool_node
*);
986 void debug_varpool (void);
987 void dump_varpool (FILE *);
988 void dump_varpool_node (FILE *, varpool_node
*);
990 void varpool_finalize_decl (tree
);
991 enum availability
cgraph_variable_initializer_availability (varpool_node
*);
992 void cgraph_make_node_local (struct cgraph_node
*);
993 bool cgraph_node_can_be_local_p (struct cgraph_node
*);
996 void varpool_remove_node (varpool_node
*node
);
997 void varpool_finalize_named_section_flags (varpool_node
*node
);
998 bool varpool_output_variables (void);
999 bool varpool_assemble_decl (varpool_node
*node
);
1000 void varpool_analyze_node (varpool_node
*);
1001 varpool_node
* varpool_extra_name_alias (tree
, tree
);
1002 varpool_node
* varpool_create_variable_alias (tree
, tree
);
1003 void varpool_reset_queue (void);
1004 tree
ctor_for_folding (tree
);
1005 bool varpool_for_node_and_aliases (varpool_node
*,
1006 bool (*) (varpool_node
*, void *),
1008 void varpool_add_new_variable (tree
);
1009 void symtab_initialize_asm_name_hash (void);
1010 void symtab_prevail_in_asm_name_hash (symtab_node
*node
);
1011 void varpool_remove_initializer (varpool_node
*);
1014 extern void change_decl_assembler_name (tree
, tree
);
1016 /* Return symbol table node associated with DECL, if any,
1017 and NULL otherwise. */
1019 static inline symtab_node
*
1020 symtab_get_node (const_tree decl
)
1022 #ifdef ENABLE_CHECKING
1023 /* Check that we are called for sane type of object - functions
1024 and static or external variables. */
1025 gcc_checking_assert (TREE_CODE (decl
) == FUNCTION_DECL
1026 || (TREE_CODE (decl
) == VAR_DECL
1027 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)
1029 /* Check that the mapping is sane - perhaps this check can go away,
1030 but at the moment frontends tends to corrupt the mapping by calling
1031 memcpy/memset on the tree nodes. */
1032 gcc_checking_assert (!decl
->decl_with_vis
.symtab_node
1033 || decl
->decl_with_vis
.symtab_node
->decl
== decl
);
1035 return decl
->decl_with_vis
.symtab_node
;
1038 /* Return callgraph node for given symbol and check it is a function. */
1039 static inline struct cgraph_node
*
1040 cgraph (symtab_node
*node
)
1042 gcc_checking_assert (!node
|| node
->type
== SYMTAB_FUNCTION
);
1043 return (struct cgraph_node
*)node
;
1046 /* Return varpool node for given symbol and check it is a variable. */
1047 static inline varpool_node
*
1048 varpool (symtab_node
*node
)
1050 gcc_checking_assert (!node
|| node
->type
== SYMTAB_VARIABLE
);
1051 return (varpool_node
*)node
;
1054 /* Return callgraph node for given symbol and check it is a function. */
1055 static inline struct cgraph_node
*
1056 cgraph_get_node (const_tree decl
)
1058 gcc_checking_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
1059 return cgraph (symtab_get_node (decl
));
1062 /* Return varpool node for given symbol and check it is a function. */
1063 static inline varpool_node
*
1064 varpool_get_node (const_tree decl
)
1066 gcc_checking_assert (TREE_CODE (decl
) == VAR_DECL
);
1067 return varpool (symtab_get_node (decl
));
1070 /* Walk all symbols. */
1071 #define FOR_EACH_SYMBOL(node) \
1072 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1074 /* Return first static symbol with definition. */
1075 static inline symtab_node
*
1076 symtab_first_defined_symbol (void)
1080 for (node
= symtab_nodes
; node
; node
= node
->next
)
1081 if (node
->definition
)
1087 /* Return next reachable static symbol with initializer after NODE. */
1088 static inline symtab_node
*
1089 symtab_next_defined_symbol (symtab_node
*node
)
1091 symtab_node
*node1
= node
->next
;
1093 for (; node1
; node1
= node1
->next
)
1094 if (node1
->definition
)
1099 /* Walk all symbols with definitions in current unit. */
1100 #define FOR_EACH_DEFINED_SYMBOL(node) \
1101 for ((node) = symtab_first_defined_symbol (); (node); \
1102 (node) = symtab_next_defined_symbol (node))
1104 /* Return first variable. */
1105 static inline varpool_node
*
1106 varpool_first_variable (void)
1109 for (node
= symtab_nodes
; node
; node
= node
->next
)
1110 if (varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
))
1115 /* Return next variable after NODE. */
1116 static inline varpool_node
*
1117 varpool_next_variable (varpool_node
*node
)
1119 symtab_node
*node1
= node
->next
;
1120 for (; node1
; node1
= node1
->next
)
1121 if (varpool_node
*vnode1
= dyn_cast
<varpool_node
*> (node1
))
1125 /* Walk all variables. */
1126 #define FOR_EACH_VARIABLE(node) \
1127 for ((node) = varpool_first_variable (); \
1129 (node) = varpool_next_variable ((node)))
1131 /* Return first static variable with initializer. */
1132 static inline varpool_node
*
1133 varpool_first_static_initializer (void)
1136 for (node
= symtab_nodes
; node
; node
= node
->next
)
1138 varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
);
1139 if (vnode
&& DECL_INITIAL (node
->decl
))
1145 /* Return next static variable with initializer after NODE. */
1146 static inline varpool_node
*
1147 varpool_next_static_initializer (varpool_node
*node
)
1149 symtab_node
*node1
= node
->next
;
1150 for (; node1
; node1
= node1
->next
)
1152 varpool_node
*vnode1
= dyn_cast
<varpool_node
*> (node1
);
1153 if (vnode1
&& DECL_INITIAL (node1
->decl
))
1159 /* Walk all static variables with initializer set. */
1160 #define FOR_EACH_STATIC_INITIALIZER(node) \
1161 for ((node) = varpool_first_static_initializer (); (node); \
1162 (node) = varpool_next_static_initializer (node))
1164 /* Return first static variable with definition. */
1165 static inline varpool_node
*
1166 varpool_first_defined_variable (void)
1169 for (node
= symtab_nodes
; node
; node
= node
->next
)
1171 varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
);
1172 if (vnode
&& vnode
->definition
)
1178 /* Return next static variable with definition after NODE. */
1179 static inline varpool_node
*
1180 varpool_next_defined_variable (varpool_node
*node
)
1182 symtab_node
*node1
= node
->next
;
1183 for (; node1
; node1
= node1
->next
)
1185 varpool_node
*vnode1
= dyn_cast
<varpool_node
*> (node1
);
1186 if (vnode1
&& vnode1
->definition
)
1191 /* Walk all variables with definitions in current unit. */
1192 #define FOR_EACH_DEFINED_VARIABLE(node) \
1193 for ((node) = varpool_first_defined_variable (); (node); \
1194 (node) = varpool_next_defined_variable (node))
1196 /* Return first function with body defined. */
1197 static inline struct cgraph_node
*
1198 cgraph_first_defined_function (void)
1201 for (node
= symtab_nodes
; node
; node
= node
->next
)
1203 cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (node
);
1204 if (cn
&& cn
->definition
)
1210 /* Return next function with body defined after NODE. */
1211 static inline struct cgraph_node
*
1212 cgraph_next_defined_function (struct cgraph_node
*node
)
1214 symtab_node
*node1
= node
->next
;
1215 for (; node1
; node1
= node1
->next
)
1217 cgraph_node
*cn1
= dyn_cast
<cgraph_node
*> (node1
);
1218 if (cn1
&& cn1
->definition
)
1224 /* Walk all functions with body defined. */
1225 #define FOR_EACH_DEFINED_FUNCTION(node) \
1226 for ((node) = cgraph_first_defined_function (); (node); \
1227 (node) = cgraph_next_defined_function ((node)))
1229 /* Return first function. */
1230 static inline struct cgraph_node
*
1231 cgraph_first_function (void)
1234 for (node
= symtab_nodes
; node
; node
= node
->next
)
1235 if (cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (node
))
1240 /* Return next function. */
1241 static inline struct cgraph_node
*
1242 cgraph_next_function (struct cgraph_node
*node
)
1244 symtab_node
*node1
= node
->next
;
1245 for (; node1
; node1
= node1
->next
)
1246 if (cgraph_node
*cn1
= dyn_cast
<cgraph_node
*> (node1
))
1250 /* Walk all functions. */
1251 #define FOR_EACH_FUNCTION(node) \
1252 for ((node) = cgraph_first_function (); (node); \
1253 (node) = cgraph_next_function ((node)))
1255 /* Return true when NODE is a function with Gimple body defined
1256 in current unit. Functions can also be define externally or they
1257 can be thunks with no Gimple representation.
1259 Note that at WPA stage, the function body may not be present in memory. */
1262 cgraph_function_with_gimple_body_p (struct cgraph_node
*node
)
1264 return node
->definition
&& !node
->thunk
.thunk_p
&& !node
->alias
;
1267 /* Return first function with body defined. */
1268 static inline struct cgraph_node
*
1269 cgraph_first_function_with_gimple_body (void)
1272 for (node
= symtab_nodes
; node
; node
= node
->next
)
1274 cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (node
);
1275 if (cn
&& cgraph_function_with_gimple_body_p (cn
))
1281 /* Return next reachable static variable with initializer after NODE. */
1282 static inline struct cgraph_node
*
1283 cgraph_next_function_with_gimple_body (struct cgraph_node
*node
)
1285 symtab_node
*node1
= node
->next
;
1286 for (; node1
; node1
= node1
->next
)
1288 cgraph_node
*cn1
= dyn_cast
<cgraph_node
*> (node1
);
1289 if (cn1
&& cgraph_function_with_gimple_body_p (cn1
))
1295 /* Walk all functions with body defined. */
1296 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1297 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1298 (node) = cgraph_next_function_with_gimple_body (node))
1300 /* Create a new static variable of type TYPE. */
1301 tree
add_new_static_var (tree type
);
1303 /* Return true if iterator CSI points to nothing. */
1305 csi_end_p (cgraph_node_set_iterator csi
)
1307 return csi
.index
>= csi
.set
->nodes
.length ();
1310 /* Advance iterator CSI. */
1312 csi_next (cgraph_node_set_iterator
*csi
)
1317 /* Return the node pointed to by CSI. */
1318 static inline struct cgraph_node
*
1319 csi_node (cgraph_node_set_iterator csi
)
1321 return csi
.set
->nodes
[csi
.index
];
1324 /* Return an iterator to the first node in SET. */
1325 static inline cgraph_node_set_iterator
1326 csi_start (cgraph_node_set set
)
1328 cgraph_node_set_iterator csi
;
1335 /* Return true if SET contains NODE. */
1337 cgraph_node_in_set_p (struct cgraph_node
*node
, cgraph_node_set set
)
1339 cgraph_node_set_iterator csi
;
1340 csi
= cgraph_node_set_find (set
, node
);
1341 return !csi_end_p (csi
);
1344 /* Return number of nodes in SET. */
1345 static inline size_t
1346 cgraph_node_set_size (cgraph_node_set set
)
1348 return set
->nodes
.length ();
1351 /* Return true if iterator VSI points to nothing. */
1353 vsi_end_p (varpool_node_set_iterator vsi
)
1355 return vsi
.index
>= vsi
.set
->nodes
.length ();
1358 /* Advance iterator VSI. */
1360 vsi_next (varpool_node_set_iterator
*vsi
)
1365 /* Return the node pointed to by VSI. */
1366 static inline varpool_node
*
1367 vsi_node (varpool_node_set_iterator vsi
)
1369 return vsi
.set
->nodes
[vsi
.index
];
1372 /* Return an iterator to the first node in SET. */
1373 static inline varpool_node_set_iterator
1374 vsi_start (varpool_node_set set
)
1376 varpool_node_set_iterator vsi
;
1383 /* Return true if SET contains NODE. */
1385 varpool_node_in_set_p (varpool_node
*node
, varpool_node_set set
)
1387 varpool_node_set_iterator vsi
;
1388 vsi
= varpool_node_set_find (set
, node
);
1389 return !vsi_end_p (vsi
);
1392 /* Return number of nodes in SET. */
1393 static inline size_t
1394 varpool_node_set_size (varpool_node_set set
)
1396 return set
->nodes
.length ();
1399 /* Uniquize all constants that appear in memory.
1400 Each constant in memory thus far output is recorded
1401 in `const_desc_table'. */
1403 struct GTY(()) constant_descriptor_tree
{
1404 /* A MEM for the constant. */
1407 /* The value of the constant. */
1410 /* Hash of value. Computing the hash from value each time
1411 hashfn is called can't work properly, as that means recursive
1412 use of the hash table during hash table expansion. */
1416 /* Return true if set is nonempty. */
1418 cgraph_node_set_nonempty_p (cgraph_node_set set
)
1420 return !set
->nodes
.is_empty ();
1423 /* Return true if set is nonempty. */
1425 varpool_node_set_nonempty_p (varpool_node_set set
)
1427 return !set
->nodes
.is_empty ();
1430 /* Return true when function NODE is only called directly or it has alias.
1431 i.e. it is not externally visible, address was not taken and
1432 it is not used in any other non-standard way. */
1435 cgraph_only_called_directly_or_aliased_p (struct cgraph_node
*node
)
1437 gcc_assert (!node
->global
.inlined_to
);
1438 return (!node
->force_output
&& !node
->address_taken
1439 && !node
->used_from_other_partition
1440 && !DECL_VIRTUAL_P (node
->decl
)
1441 && !DECL_STATIC_CONSTRUCTOR (node
->decl
)
1442 && !DECL_STATIC_DESTRUCTOR (node
->decl
)
1443 && !node
->externally_visible
);
1446 /* Return true when function NODE can be removed from callgraph
1447 if all direct calls are eliminated. */
1450 varpool_can_remove_if_no_refs (varpool_node
*node
)
1452 if (DECL_EXTERNAL (node
->decl
))
1454 return (!node
->force_output
&& !node
->used_from_other_partition
1455 && ((DECL_COMDAT (node
->decl
)
1456 && !node
->forced_by_abi
1457 && !symtab_used_from_object_file_p (node
))
1458 || !node
->externally_visible
1459 || DECL_HAS_VALUE_EXPR_P (node
->decl
)));
1462 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1463 i.e. if the variable is not externally visible or not used in some magic
1464 way (asm statement or such).
1465 The magic uses are all summarized in force_output flag. */
1468 varpool_all_refs_explicit_p (varpool_node
*vnode
)
1470 return (vnode
->definition
1471 && !vnode
->externally_visible
1472 && !vnode
->used_from_other_partition
1473 && !vnode
->force_output
);
1476 /* Constant pool accessor function. */
1477 htab_t
constant_pool_htab (void);
1479 /* FIXME: inappropriate dependency of cgraph on IPA. */
1480 #include "ipa-ref-inline.h"
1482 /* Return node that alias N is aliasing. */
1484 static inline symtab_node
*
1485 symtab_alias_target (symtab_node
*n
)
1487 struct ipa_ref
*ref
;
1488 ipa_ref_list_reference_iterate (&n
->ref_list
, 0, ref
);
1489 gcc_checking_assert (ref
->use
== IPA_REF_ALIAS
);
1490 return ref
->referred
;
1493 static inline struct cgraph_node
*
1494 cgraph_alias_target (struct cgraph_node
*n
)
1496 return dyn_cast
<cgraph_node
*> (symtab_alias_target (n
));
1499 static inline varpool_node
*
1500 varpool_alias_target (varpool_node
*n
)
1502 return dyn_cast
<varpool_node
*> (symtab_alias_target (n
));
1505 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1506 Do not walk through thunks.
1507 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1509 static inline struct cgraph_node
*
1510 cgraph_function_or_thunk_node (struct cgraph_node
*node
,
1511 enum availability
*availability
= NULL
)
1513 struct cgraph_node
*n
;
1515 n
= dyn_cast
<cgraph_node
*> (symtab_alias_ultimate_target (node
,
1517 if (!n
&& availability
)
1518 *availability
= AVAIL_NOT_AVAILABLE
;
1521 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1522 Do not walk through thunks.
1523 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1525 static inline varpool_node
*
1526 varpool_variable_node (varpool_node
*node
,
1527 enum availability
*availability
= NULL
)
1532 n
= dyn_cast
<varpool_node
*> (symtab_alias_ultimate_target (node
,
1537 if (!n
&& availability
)
1538 *availability
= AVAIL_NOT_AVAILABLE
;
1542 /* Return true when the edge E represents a direct recursion. */
1544 cgraph_edge_recursive_p (struct cgraph_edge
*e
)
1546 struct cgraph_node
*callee
= cgraph_function_or_thunk_node (e
->callee
, NULL
);
1547 if (e
->caller
->global
.inlined_to
)
1548 return e
->caller
->global
.inlined_to
->decl
== callee
->decl
;
1550 return e
->caller
->decl
== callee
->decl
;
1553 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1555 decl_is_tm_clone (const_tree fndecl
)
1557 struct cgraph_node
*n
= cgraph_get_node (fndecl
);
1563 /* Likewise indicate that a node is needed, i.e. reachable via some
1567 cgraph_mark_force_output_node (struct cgraph_node
*node
)
1569 node
->force_output
= 1;
1570 gcc_checking_assert (!node
->global
.inlined_to
);
1573 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1574 or abstract function kept for debug info purposes only. */
1577 symtab_real_symbol_p (symtab_node
*node
)
1579 struct cgraph_node
*cnode
;
1581 if (DECL_ABSTRACT (node
->decl
))
1583 if (!is_a
<cgraph_node
*> (node
))
1585 cnode
= cgraph (node
);
1586 if (cnode
->global
.inlined_to
)
1591 /* Return true if NODE can be discarded by linker from the binary. */
1594 symtab_can_be_discarded (symtab_node
*node
)
1596 return (DECL_EXTERNAL (node
->decl
)
1597 || (node
->get_comdat_group ()
1598 && node
->resolution
!= LDPR_PREVAILING_DEF
1599 && node
->resolution
!= LDPR_PREVAILING_DEF_IRONLY
1600 && node
->resolution
!= LDPR_PREVAILING_DEF_IRONLY_EXP
));
1603 /* Return true if NODE is local to a particular COMDAT group, and must not
1604 be named from outside the COMDAT. This is used for C++ decloned
1608 symtab_comdat_local_p (symtab_node
*node
)
1610 return (node
->same_comdat_group
&& !TREE_PUBLIC (node
->decl
));
1613 /* Return true if ONE and TWO are part of the same COMDAT group. */
1616 symtab_in_same_comdat_p (symtab_node
*one
, symtab_node
*two
)
1618 if (cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (one
))
1620 if (cn
->global
.inlined_to
)
1621 one
= cn
->global
.inlined_to
;
1623 if (cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (two
))
1625 if (cn
->global
.inlined_to
)
1626 two
= cn
->global
.inlined_to
;
1629 return one
->get_comdat_group () == two
->get_comdat_group ();
1631 #endif /* GCC_CGRAPH_H */