gcc/cp
[official-gcc.git] / gcc / cgraph.h
blob9dc6f0186f18694bfddb7fcae2d5a6d3f52ddcd4
1 /* Callgraph handling code.
2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_CGRAPH_H
22 #define GCC_CGRAPH_H
24 #include "is-a.h"
25 #include "plugin-api.h"
26 #include "vec.h"
27 #include "basic-block.h"
28 #include "function.h"
29 #include "ipa-ref.h"
31 /* Symbol table consists of functions and variables.
32 TODO: add labels and CONST_DECLs. */
33 enum symtab_type
35 SYMTAB_SYMBOL,
36 SYMTAB_FUNCTION,
37 SYMTAB_VARIABLE
40 /* 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")))
44 symtab_node
46 public:
47 /* Return name. */
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. */
66 unsigned alias : 1;
67 /* True when alias is a weakref. */
68 unsigned weakref : 1;
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
102 available. ***/
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. */
120 int order;
122 /* Declaration representing the symbol. */
123 tree decl;
125 /* Linked list of symbol table entries starting with symtab_nodes. */
126 symtab_node *next;
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
134 duplicate entries.
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 /* Vectors of referring and referenced entities. */
145 struct ipa_ref_list ref_list;
147 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
148 depending to what was known to frontend on the creation time.
149 Once alias is resolved, this pointer become NULL. */
150 tree alias_target;
152 /* File stream where this node is being written to. */
153 struct lto_file_decl_data * lto_file_data;
155 PTR GTY ((skip)) aux;
158 enum availability
160 /* Not yet set by cgraph_function_body_availability. */
161 AVAIL_UNSET,
162 /* Function body/variable initializer is unknown. */
163 AVAIL_NOT_AVAILABLE,
164 /* Function body/variable initializer is known but might be replaced
165 by a different one from other compilation unit and thus needs to
166 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
167 arbitrary side effects on escaping variables and functions, while
168 like AVAILABLE it might access static variables. */
169 AVAIL_OVERWRITABLE,
170 /* Function body/variable initializer is known and will be used in final
171 program. */
172 AVAIL_AVAILABLE,
173 /* Function body/variable initializer is known and all it's uses are explicitly
174 visible within current unit (ie it's address is never taken and it is not
175 exported to other units).
176 Currently used only for functions. */
177 AVAIL_LOCAL
180 /* This is the information that is put into the cgraph local structure
181 to recover a function. */
182 struct lto_file_decl_data;
184 extern const char * const cgraph_availability_names[];
185 extern const char * const ld_plugin_symbol_resolution_names[];
187 /* Information about thunk, used only for same body aliases. */
189 struct GTY(()) cgraph_thunk_info {
190 /* Information about the thunk. */
191 HOST_WIDE_INT fixed_offset;
192 HOST_WIDE_INT virtual_value;
193 tree alias;
194 bool this_adjusting;
195 bool virtual_offset_p;
196 /* Set to true when alias node is thunk. */
197 bool thunk_p;
200 /* Information about the function collected locally.
201 Available after function is analyzed. */
203 struct GTY(()) cgraph_local_info {
204 /* Set when function function is visible in current compilation unit only
205 and its address is never taken. */
206 unsigned local : 1;
208 /* False when there is something makes versioning impossible. */
209 unsigned versionable : 1;
211 /* False when function calling convention and signature can not be changed.
212 This is the case when __builtin_apply_args is used. */
213 unsigned can_change_signature : 1;
215 /* True when the function has been originally extern inline, but it is
216 redefined now. */
217 unsigned redefined_extern_inline : 1;
219 /* True if the function may enter serial irrevocable mode. */
220 unsigned tm_may_enter_irr : 1;
223 /* Information about the function that needs to be computed globally
224 once compilation is finished. Available only with -funit-at-a-time. */
226 struct GTY(()) cgraph_global_info {
227 /* For inline clones this points to the function they will be
228 inlined into. */
229 struct cgraph_node *inlined_to;
232 /* Information about the function that is propagated by the RTL backend.
233 Available only for functions that has been already assembled. */
235 struct GTY(()) cgraph_rtl_info {
236 unsigned int preferred_incoming_stack_boundary;
239 /* Represent which DECL tree (or reference to such tree)
240 will be replaced by another tree while versioning. */
241 struct GTY(()) ipa_replace_map
243 /* The tree that will be replaced. */
244 tree old_tree;
245 /* The new (replacing) tree. */
246 tree new_tree;
247 /* Parameter number to replace, when old_tree is NULL. */
248 int parm_num;
249 /* True when a substitution should be done, false otherwise. */
250 bool replace_p;
251 /* True when we replace a reference to old_tree. */
252 bool ref_p;
254 typedef struct ipa_replace_map *ipa_replace_map_p;
256 struct GTY(()) cgraph_clone_info
258 vec<ipa_replace_map_p, va_gc> *tree_map;
259 bitmap args_to_skip;
260 bitmap combined_args_to_skip;
263 enum cgraph_simd_clone_arg_type
265 SIMD_CLONE_ARG_TYPE_VECTOR,
266 SIMD_CLONE_ARG_TYPE_UNIFORM,
267 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
268 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
269 SIMD_CLONE_ARG_TYPE_MASK
272 /* Function arguments in the original function of a SIMD clone.
273 Supplementary data for `struct simd_clone'. */
275 struct GTY(()) cgraph_simd_clone_arg {
276 /* Original function argument as it originally existed in
277 DECL_ARGUMENTS. */
278 tree orig_arg;
280 /* orig_arg's function (or for extern functions type from
281 TYPE_ARG_TYPES). */
282 tree orig_type;
284 /* If argument is a vector, this holds the vector version of
285 orig_arg that after adjusting the argument types will live in
286 DECL_ARGUMENTS. Otherwise, this is NULL.
288 This basically holds:
289 vector(simdlen) __typeof__(orig_arg) new_arg. */
290 tree vector_arg;
292 /* vector_arg's type (or for extern functions new vector type. */
293 tree vector_type;
295 /* If argument is a vector, this holds the array where the simd
296 argument is held while executing the simd clone function. This
297 is a local variable in the cloned function. Its content is
298 copied from vector_arg upon entry to the clone.
300 This basically holds:
301 __typeof__(orig_arg) simd_array[simdlen]. */
302 tree simd_array;
304 /* A SIMD clone's argument can be either linear (constant or
305 variable), uniform, or vector. */
306 enum cgraph_simd_clone_arg_type arg_type;
308 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
309 the constant linear step, if arg_type is
310 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
311 the uniform argument holding the step, otherwise 0. */
312 HOST_WIDE_INT linear_step;
314 /* Variable alignment if available, otherwise 0. */
315 unsigned int alignment;
318 /* Specific data for a SIMD function clone. */
320 struct GTY(()) cgraph_simd_clone {
321 /* Number of words in the SIMD lane associated with this clone. */
322 unsigned int simdlen;
324 /* Number of annotated function arguments in `args'. This is
325 usually the number of named arguments in FNDECL. */
326 unsigned int nargs;
328 /* Max hardware vector size in bits for integral vectors. */
329 unsigned int vecsize_int;
331 /* Max hardware vector size in bits for floating point vectors. */
332 unsigned int vecsize_float;
334 /* The mangling character for a given vector size. This is is used
335 to determine the ISA mangling bit as specified in the Intel
336 Vector ABI. */
337 unsigned char vecsize_mangle;
339 /* True if this is the masked, in-branch version of the clone,
340 otherwise false. */
341 unsigned int inbranch : 1;
343 /* True if this is a Cilk Plus variant. */
344 unsigned int cilk_elemental : 1;
346 /* Doubly linked list of SIMD clones. */
347 struct cgraph_node *prev_clone, *next_clone;
349 /* Original cgraph node the SIMD clones were created for. */
350 struct cgraph_node *origin;
352 /* Annotated function arguments for the original function. */
353 struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
357 /* The cgraph data structure.
358 Each function decl has assigned cgraph_node listing callees and callers. */
360 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
361 public:
362 struct cgraph_edge *callees;
363 struct cgraph_edge *callers;
364 /* List of edges representing indirect calls with a yet undetermined
365 callee. */
366 struct cgraph_edge *indirect_calls;
367 /* For nested functions points to function the node is nested in. */
368 struct cgraph_node *origin;
369 /* Points to first nested function, if any. */
370 struct cgraph_node *nested;
371 /* Pointer to the next function with same origin, if any. */
372 struct cgraph_node *next_nested;
373 /* Pointer to the next clone. */
374 struct cgraph_node *next_sibling_clone;
375 struct cgraph_node *prev_sibling_clone;
376 struct cgraph_node *clones;
377 struct cgraph_node *clone_of;
378 /* For functions with many calls sites it holds map from call expression
379 to the edge to speed up cgraph_edge function. */
380 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
381 /* Declaration node used to be clone of. */
382 tree former_clone_of;
384 /* If this is a SIMD clone, this points to the SIMD specific
385 information for it. */
386 struct cgraph_simd_clone *simdclone;
387 /* If this function has SIMD clones, this points to the first clone. */
388 struct cgraph_node *simd_clones;
390 /* Interprocedural passes scheduled to have their transform functions
391 applied next time we execute local pass on them. We maintain it
392 per-function in order to allow IPA passes to introduce new functions. */
393 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
395 struct cgraph_local_info local;
396 struct cgraph_global_info global;
397 struct cgraph_rtl_info rtl;
398 struct cgraph_clone_info clone;
399 struct cgraph_thunk_info thunk;
401 /* Expected number of executions: calculated in profile.c. */
402 gcov_type count;
403 /* How to scale counts at materialization time; used to merge
404 LTO units with different number of profile runs. */
405 int count_materialization_scale;
406 /* Unique id of the node. */
407 int uid;
408 /* ID assigned by the profiling. */
409 unsigned int profile_id;
410 /* Time profiler: first run of function. */
411 int tp_first_run;
413 /* Set when decl is an abstract function pointed to by the
414 ABSTRACT_DECL_ORIGIN of a reachable function. */
415 unsigned used_as_abstract_origin : 1;
416 /* Set once the function is lowered (i.e. its CFG is built). */
417 unsigned lowered : 1;
418 /* Set once the function has been instantiated and its callee
419 lists created. */
420 unsigned process : 1;
421 /* How commonly executed the node is. Initialized during branch
422 probabilities pass. */
423 ENUM_BITFIELD (node_frequency) frequency : 2;
424 /* True when function can only be called at startup (from static ctor). */
425 unsigned only_called_at_startup : 1;
426 /* True when function can only be called at startup (from static dtor). */
427 unsigned only_called_at_exit : 1;
428 /* True when function is the transactional clone of a function which
429 is called only from inside transactions. */
430 /* ?? We should be able to remove this. We have enough bits in
431 cgraph to calculate it. */
432 unsigned tm_clone : 1;
433 /* True if this decl is a dispatcher for function versions. */
434 unsigned dispatcher_function : 1;
435 /* True if this decl calls a COMDAT-local function. This is set up in
436 compute_inline_parameters and inline_call. */
437 unsigned calls_comdat_local : 1;
441 typedef struct cgraph_node *cgraph_node_ptr;
444 /* Function Multiversioning info. */
445 struct GTY(()) cgraph_function_version_info {
446 /* The cgraph_node for which the function version info is stored. */
447 struct cgraph_node *this_node;
448 /* Chains all the semantically identical function versions. The
449 first function in this chain is the version_info node of the
450 default function. */
451 struct cgraph_function_version_info *prev;
452 /* If this version node corresponds to a dispatcher for function
453 versions, this points to the version info node of the default
454 function, the first node in the chain. */
455 struct cgraph_function_version_info *next;
456 /* If this node corresponds to a function version, this points
457 to the dispatcher function decl, which is the function that must
458 be called to execute the right function version at run-time.
460 If this cgraph node is a dispatcher (if dispatcher_function is
461 true, in the cgraph_node struct) for function versions, this
462 points to resolver function, which holds the function body of the
463 dispatcher. The dispatcher decl is an alias to the resolver
464 function decl. */
465 tree dispatcher_resolver;
468 /* Get the cgraph_function_version_info node corresponding to node. */
469 struct cgraph_function_version_info *
470 get_cgraph_node_version (struct cgraph_node *node);
472 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
473 corresponding to cgraph_node NODE. */
474 struct cgraph_function_version_info *
475 insert_new_cgraph_node_version (struct cgraph_node *node);
477 /* Record that DECL1 and DECL2 are semantically identical function
478 versions. */
479 void record_function_versions (tree decl1, tree decl2);
481 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
482 DECL is a duplicate declaration. */
483 void delete_function_version (tree decl);
485 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
486 can appear in multiple sets. */
487 struct cgraph_node_set_def
489 struct pointer_map_t *map;
490 vec<cgraph_node_ptr> nodes;
493 class varpool_node;
494 typedef varpool_node *varpool_node_ptr;
497 /* A varpool node set is a collection of varpool nodes. A varpool node
498 can appear in multiple sets. */
499 struct varpool_node_set_def
501 struct pointer_map_t * map;
502 vec<varpool_node_ptr> nodes;
505 typedef struct cgraph_node_set_def *cgraph_node_set;
508 typedef struct varpool_node_set_def *varpool_node_set;
511 /* Iterator structure for cgraph node sets. */
512 struct cgraph_node_set_iterator
514 cgraph_node_set set;
515 unsigned index;
518 /* Iterator structure for varpool node sets. */
519 struct varpool_node_set_iterator
521 varpool_node_set set;
522 unsigned index;
525 #define DEFCIFCODE(code, type, string) CIF_ ## code,
526 /* Reasons for inlining failures. */
527 enum cgraph_inline_failed_t {
528 #include "cif-code.def"
529 CIF_N_REASONS
532 enum cgraph_inline_failed_type_t
534 CIF_FINAL_NORMAL = 0,
535 CIF_FINAL_ERROR
538 /* Structure containing additional information about an indirect call. */
540 struct GTY(()) cgraph_indirect_call_info
542 /* When polymorphic is set, this field contains offset where the object which
543 was actually used in the polymorphic resides within a larger structure.
544 If agg_contents is set, the field contains the offset within the aggregate
545 from which the address to call was loaded. */
546 HOST_WIDE_INT offset;
547 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
548 HOST_WIDE_INT otr_token;
549 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
550 tree otr_type, outer_type;
551 /* Index of the parameter that is called. */
552 int param_index;
553 /* ECF flags determined from the caller. */
554 int ecf_flags;
555 /* Profile_id of common target obtrained from profile. */
556 int common_target_id;
557 /* Probability that call will land in function with COMMON_TARGET_ID. */
558 int common_target_probability;
560 /* Set when the call is a virtual call with the parameter being the
561 associated object pointer rather than a simple direct call. */
562 unsigned polymorphic : 1;
563 /* Set when the call is a call of a pointer loaded from contents of an
564 aggregate at offset. */
565 unsigned agg_contents : 1;
566 /* Set when this is a call through a member pointer. */
567 unsigned member_ptr : 1;
568 /* When the previous bit is set, this one determines whether the destination
569 is loaded from a parameter passed by reference. */
570 unsigned by_ref : 1;
571 unsigned int maybe_in_construction : 1;
572 unsigned int maybe_derived_type : 1;
575 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
576 /* Expected number of executions: calculated in profile.c. */
577 gcov_type count;
578 struct cgraph_node *caller;
579 struct cgraph_node *callee;
580 struct cgraph_edge *prev_caller;
581 struct cgraph_edge *next_caller;
582 struct cgraph_edge *prev_callee;
583 struct cgraph_edge *next_callee;
584 gimple call_stmt;
585 /* Additional information about an indirect call. Not cleared when an edge
586 becomes direct. */
587 struct cgraph_indirect_call_info *indirect_info;
588 PTR GTY ((skip (""))) aux;
589 /* When equal to CIF_OK, inline this call. Otherwise, points to the
590 explanation why function was not inlined. */
591 enum cgraph_inline_failed_t inline_failed;
592 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
593 when the function is serialized in. */
594 unsigned int lto_stmt_uid;
595 /* Expected frequency of executions within the function.
596 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
597 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
598 int frequency;
599 /* Unique id of the edge. */
600 int uid;
601 /* Whether this edge was made direct by indirect inlining. */
602 unsigned int indirect_inlining_edge : 1;
603 /* Whether this edge describes an indirect call with an undetermined
604 callee. */
605 unsigned int indirect_unknown_callee : 1;
606 /* Whether this edge is still a dangling */
607 /* True if the corresponding CALL stmt cannot be inlined. */
608 unsigned int call_stmt_cannot_inline_p : 1;
609 /* Can this call throw externally? */
610 unsigned int can_throw_external : 1;
611 /* Edges with SPECULATIVE flag represents indirect calls that was
612 speculatively turned into direct (i.e. by profile feedback).
613 The final code sequence will have form:
615 if (call_target == expected_fn)
616 expected_fn ();
617 else
618 call_target ();
620 Every speculative call is represented by three components attached
621 to a same call statement:
622 1) a direct call (to expected_fn)
623 2) an indirect call (to call_target)
624 3) a IPA_REF_ADDR refrence to expected_fn.
626 Optimizers may later redirect direct call to clone, so 1) and 3)
627 do not need to necesarily agree with destination. */
628 unsigned int speculative : 1;
631 #define CGRAPH_FREQ_BASE 1000
632 #define CGRAPH_FREQ_MAX 100000
634 typedef struct cgraph_edge *cgraph_edge_p;
637 /* The varpool data structure.
638 Each static variable decl has assigned varpool_node. */
640 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
641 public:
642 /* Set when variable is scheduled to be assembled. */
643 unsigned output : 1;
645 /* Set if the variable is dynamically initialized, except for
646 function local statics. */
647 unsigned dynamically_initialized : 1;
650 /* Every top level asm statement is put into a asm_node. */
652 struct GTY(()) asm_node {
653 /* Next asm node. */
654 struct asm_node *next;
655 /* String for this asm node. */
656 tree asm_str;
657 /* Ordering of all cgraph nodes. */
658 int order;
661 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
663 template <>
664 template <>
665 inline bool
666 is_a_helper <cgraph_node *>::test (symtab_node *p)
668 return p->type == SYMTAB_FUNCTION;
671 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
673 template <>
674 template <>
675 inline bool
676 is_a_helper <varpool_node *>::test (symtab_node *p)
678 return p->type == SYMTAB_VARIABLE;
681 extern GTY(()) symtab_node *symtab_nodes;
682 extern GTY(()) int cgraph_n_nodes;
683 extern GTY(()) int cgraph_max_uid;
684 extern GTY(()) int cgraph_edge_max_uid;
685 extern bool cgraph_global_info_ready;
686 enum cgraph_state
688 /* Frontend is parsing and finalizing functions. */
689 CGRAPH_STATE_PARSING,
690 /* Callgraph is being constructed. It is safe to add new functions. */
691 CGRAPH_STATE_CONSTRUCTION,
692 /* Callgraph is being at LTO time. */
693 CGRAPH_LTO_STREAMING,
694 /* Callgraph is built and IPA passes are being run. */
695 CGRAPH_STATE_IPA,
696 /* Callgraph is built and all functions are transformed to SSA form. */
697 CGRAPH_STATE_IPA_SSA,
698 /* Functions are now ordered and being passed to RTL expanders. */
699 CGRAPH_STATE_EXPANSION,
700 /* All cgraph expansion is done. */
701 CGRAPH_STATE_FINISHED
703 extern enum cgraph_state cgraph_state;
704 extern bool cgraph_function_flags_ready;
705 extern cgraph_node_set cgraph_new_nodes;
707 extern GTY(()) struct asm_node *asm_nodes;
708 extern GTY(()) int symtab_order;
709 extern bool cpp_implicit_aliases_done;
711 /* Classifcation of symbols WRT partitioning. */
712 enum symbol_partitioning_class
714 /* External declarations are ignored by partitioning algorithms and they are
715 added into the boundary later via compute_ltrans_boundary. */
716 SYMBOL_EXTERNAL,
717 /* Partitioned symbols are pur into one of partitions. */
718 SYMBOL_PARTITION,
719 /* Duplicated symbols (such as comdat or constant pool references) are
720 copied into every node needing them via add_symbol_to_partition. */
721 SYMBOL_DUPLICATE
725 /* In symtab.c */
726 void symtab_register_node (symtab_node *);
727 void symtab_unregister_node (symtab_node *);
728 void symtab_remove_from_same_comdat_group (symtab_node *);
729 void symtab_remove_node (symtab_node *);
730 symtab_node *symtab_get_node (const_tree);
731 symtab_node *symtab_node_for_asm (const_tree asmname);
732 void symtab_insert_node_to_hashtable (symtab_node *);
733 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
734 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
735 void dump_symtab (FILE *);
736 void debug_symtab (void);
737 void dump_symtab_node (FILE *, symtab_node *);
738 void debug_symtab_node (symtab_node *);
739 void dump_symtab_base (FILE *, symtab_node *);
740 void verify_symtab (void);
741 void verify_symtab_node (symtab_node *);
742 bool verify_symtab_base (symtab_node *);
743 bool symtab_used_from_object_file_p (symtab_node *);
744 void symtab_make_decl_local (tree);
745 symtab_node *symtab_alias_ultimate_target (symtab_node *,
746 enum availability *avail = NULL);
747 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
748 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
749 bool symtab_for_node_and_aliases (symtab_node *,
750 bool (*) (symtab_node *, void *),
751 void *,
752 bool);
753 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
754 enum availability symtab_node_availability (symtab_node *);
755 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
756 enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
758 /* In cgraph.c */
759 void dump_cgraph (FILE *);
760 void debug_cgraph (void);
761 void dump_cgraph_node (FILE *, struct cgraph_node *);
762 void debug_cgraph_node (struct cgraph_node *);
763 void cgraph_remove_edge (struct cgraph_edge *);
764 void cgraph_remove_node (struct cgraph_node *);
765 void cgraph_release_function_body (struct cgraph_node *);
766 void release_function_body (tree);
767 void cgraph_node_remove_callees (struct cgraph_node *node);
768 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
769 struct cgraph_node *,
770 gimple, gcov_type, int);
771 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
772 int, gcov_type, int);
773 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
774 struct cgraph_node * cgraph_create_node (tree);
775 struct cgraph_node * cgraph_create_empty_node (void);
776 struct cgraph_node * cgraph_get_create_node (tree);
777 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
778 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
779 HOST_WIDE_INT, tree, tree);
780 struct cgraph_node *cgraph_node_for_asm (tree);
781 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
782 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
783 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
784 struct cgraph_local_info *cgraph_local_info (tree);
785 struct cgraph_global_info *cgraph_global_info (tree);
786 struct cgraph_rtl_info *cgraph_rtl_info (tree);
787 struct cgraph_node *cgraph_create_function_alias (tree, tree);
788 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
789 struct cgraph_node *);
790 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
791 struct cgraph_edge *);
793 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
794 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
795 bool cgraph_only_called_directly_p (struct cgraph_node *);
797 bool cgraph_function_possibly_inlined_p (tree);
798 void cgraph_unnest_node (struct cgraph_node *);
800 enum availability cgraph_function_body_availability (struct cgraph_node *);
801 void cgraph_add_new_function (tree, bool);
802 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
803 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
805 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
806 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
807 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
808 bool cgraph_node_cannot_return (struct cgraph_node *);
809 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
810 bool cgraph_will_be_removed_from_program_if_no_direct_calls
811 (struct cgraph_node *node);
812 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
813 (struct cgraph_node *node);
814 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
815 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
816 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
817 bool (*) (struct cgraph_node *, void *),
818 void *,
819 bool);
820 bool cgraph_for_node_and_aliases (struct cgraph_node *,
821 bool (*) (struct cgraph_node *, void *),
822 void *, bool);
823 vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
824 void verify_cgraph (void);
825 void verify_cgraph_node (struct cgraph_node *);
826 void cgraph_mark_address_taken_node (struct cgraph_node *);
828 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
829 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
830 typedef void (*varpool_node_hook)(varpool_node *, void *);
831 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
832 void *);
833 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
834 void *);
835 struct cgraph_edge_hook_list;
836 struct cgraph_node_hook_list;
837 struct varpool_node_hook_list;
838 struct cgraph_2edge_hook_list;
839 struct cgraph_2node_hook_list;
840 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
841 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
842 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
843 void *);
844 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
845 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
846 void *);
847 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
848 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
849 void *);
850 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
851 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
852 void *);
853 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
854 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
855 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
856 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
857 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
858 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
859 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
860 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
861 enum availability *avail = NULL);
862 bool cgraph_get_body (struct cgraph_node *node);
863 struct cgraph_edge *
864 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
865 struct cgraph_node *,
866 gcov_type, int);
867 void cgraph_speculative_call_info (struct cgraph_edge *,
868 struct cgraph_edge *&,
869 struct cgraph_edge *&,
870 struct ipa_ref *&);
871 extern bool gimple_check_call_matching_types (gimple, tree, bool);
873 /* In cgraphunit.c */
874 struct asm_node *add_asm_node (tree);
875 extern FILE *cgraph_dump_file;
876 void cgraph_finalize_function (tree, bool);
877 void finalize_compilation_unit (void);
878 void compile (void);
879 void init_cgraph (void);
880 void cgraph_process_new_functions (void);
881 void cgraph_process_same_body_aliases (void);
882 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
883 /* Initialize datastructures so DECL is a function in lowered gimple form.
884 IN_SSA is true if the gimple is in SSA. */
885 basic_block init_lowered_empty_function (tree, bool);
886 void cgraph_reset_node (struct cgraph_node *);
887 bool expand_thunk (struct cgraph_node *, bool);
889 /* In cgraphclones.c */
891 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
892 struct cgraph_node *, gimple,
893 unsigned, gcov_type, int, bool);
894 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
895 int, bool, vec<cgraph_edge_p>,
896 bool, struct cgraph_node *, bitmap);
897 tree clone_function_name (tree decl, const char *);
898 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
899 vec<cgraph_edge_p>,
900 vec<ipa_replace_map_p, va_gc> *tree_map,
901 bitmap args_to_skip,
902 const char *clone_name);
903 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
904 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
905 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
906 bool update_speculative = true);
907 void cgraph_create_edge_including_clones (struct cgraph_node *,
908 struct cgraph_node *,
909 gimple, gimple, gcov_type, int,
910 cgraph_inline_failed_t);
911 void cgraph_materialize_all_clones (void);
912 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
913 tree, vec<cgraph_edge_p>, bitmap);
914 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
915 vec<cgraph_edge_p>,
916 vec<ipa_replace_map_p, va_gc> *,
917 bitmap, bool, bitmap,
918 basic_block, const char *);
919 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
920 bool, bitmap, bool, bitmap, basic_block);
921 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
923 /* In cgraphbuild.c */
924 unsigned int rebuild_cgraph_edges (void);
925 void cgraph_rebuild_references (void);
926 int compute_call_stmt_bb_frequency (tree, basic_block bb);
927 void record_references_in_initializer (tree, bool);
928 void ipa_record_stmt_references (struct cgraph_node *, gimple);
930 /* In ipa.c */
931 bool symtab_remove_unreachable_nodes (bool, FILE *);
932 cgraph_node_set cgraph_node_set_new (void);
933 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
934 struct cgraph_node *);
935 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
936 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
937 void dump_cgraph_node_set (FILE *, cgraph_node_set);
938 void debug_cgraph_node_set (cgraph_node_set);
939 void free_cgraph_node_set (cgraph_node_set);
940 void cgraph_build_static_cdtor (char which, tree body, int priority);
942 varpool_node_set varpool_node_set_new (void);
943 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
944 varpool_node *);
945 void varpool_node_set_add (varpool_node_set, varpool_node *);
946 void varpool_node_set_remove (varpool_node_set, varpool_node *);
947 void dump_varpool_node_set (FILE *, varpool_node_set);
948 void debug_varpool_node_set (varpool_node_set);
949 void free_varpool_node_set (varpool_node_set);
950 void ipa_discover_readonly_nonaddressable_vars (void);
951 bool varpool_externally_visible_p (varpool_node *);
953 /* In predict.c */
954 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
955 bool cgraph_optimize_for_size_p (struct cgraph_node *);
957 /* In varpool.c */
958 varpool_node *varpool_create_empty_node (void);
959 varpool_node *varpool_node_for_decl (tree);
960 varpool_node *varpool_node_for_asm (tree asmname);
961 void varpool_mark_needed_node (varpool_node *);
962 void debug_varpool (void);
963 void dump_varpool (FILE *);
964 void dump_varpool_node (FILE *, varpool_node *);
966 void varpool_finalize_decl (tree);
967 enum availability cgraph_variable_initializer_availability (varpool_node *);
968 void cgraph_make_node_local (struct cgraph_node *);
969 bool cgraph_node_can_be_local_p (struct cgraph_node *);
972 void varpool_remove_node (varpool_node *node);
973 void varpool_finalize_named_section_flags (varpool_node *node);
974 bool varpool_output_variables (void);
975 bool varpool_assemble_decl (varpool_node *node);
976 void varpool_analyze_node (varpool_node *);
977 varpool_node * varpool_extra_name_alias (tree, tree);
978 varpool_node * varpool_create_variable_alias (tree, tree);
979 void varpool_reset_queue (void);
980 tree ctor_for_folding (tree);
981 bool varpool_for_node_and_aliases (varpool_node *,
982 bool (*) (varpool_node *, void *),
983 void *, bool);
984 void varpool_add_new_variable (tree);
985 void symtab_initialize_asm_name_hash (void);
986 void symtab_prevail_in_asm_name_hash (symtab_node *node);
987 void varpool_remove_initializer (varpool_node *);
989 /* In cgraph.c */
990 extern void change_decl_assembler_name (tree, tree);
992 /* Return callgraph node for given symbol and check it is a function. */
993 static inline struct cgraph_node *
994 cgraph (symtab_node *node)
996 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
997 return (struct cgraph_node *)node;
1000 /* Return varpool node for given symbol and check it is a variable. */
1001 static inline varpool_node *
1002 varpool (symtab_node *node)
1004 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
1005 return (varpool_node *)node;
1008 /* Return callgraph node for given symbol and check it is a function. */
1009 static inline struct cgraph_node *
1010 cgraph_get_node (const_tree decl)
1012 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1013 return cgraph (symtab_get_node (decl));
1016 /* Return varpool node for given symbol and check it is a function. */
1017 static inline varpool_node *
1018 varpool_get_node (const_tree decl)
1020 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1021 return varpool (symtab_get_node (decl));
1024 /* Walk all symbols. */
1025 #define FOR_EACH_SYMBOL(node) \
1026 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1028 /* Return first static symbol with definition. */
1029 static inline symtab_node *
1030 symtab_first_defined_symbol (void)
1032 symtab_node *node;
1034 for (node = symtab_nodes; node; node = node->next)
1035 if (node->definition)
1036 return node;
1038 return NULL;
1041 /* Return next reachable static symbol with initializer after NODE. */
1042 static inline symtab_node *
1043 symtab_next_defined_symbol (symtab_node *node)
1045 symtab_node *node1 = node->next;
1047 for (; node1; node1 = node1->next)
1048 if (node1->definition)
1049 return node1;
1051 return NULL;
1053 /* Walk all symbols with definitions in current unit. */
1054 #define FOR_EACH_DEFINED_SYMBOL(node) \
1055 for ((node) = symtab_first_defined_symbol (); (node); \
1056 (node) = symtab_next_defined_symbol (node))
1058 /* Return first variable. */
1059 static inline varpool_node *
1060 varpool_first_variable (void)
1062 symtab_node *node;
1063 for (node = symtab_nodes; node; node = node->next)
1064 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1065 return vnode;
1066 return NULL;
1069 /* Return next variable after NODE. */
1070 static inline varpool_node *
1071 varpool_next_variable (varpool_node *node)
1073 symtab_node *node1 = node->next;
1074 for (; node1; node1 = node1->next)
1075 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1076 return vnode1;
1077 return NULL;
1079 /* Walk all variables. */
1080 #define FOR_EACH_VARIABLE(node) \
1081 for ((node) = varpool_first_variable (); \
1082 (node); \
1083 (node) = varpool_next_variable ((node)))
1085 /* Return first static variable with initializer. */
1086 static inline varpool_node *
1087 varpool_first_static_initializer (void)
1089 symtab_node *node;
1090 for (node = symtab_nodes; node; node = node->next)
1092 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1093 if (vnode && DECL_INITIAL (node->decl))
1094 return vnode;
1096 return NULL;
1099 /* Return next static variable with initializer after NODE. */
1100 static inline varpool_node *
1101 varpool_next_static_initializer (varpool_node *node)
1103 symtab_node *node1 = node->next;
1104 for (; node1; node1 = node1->next)
1106 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1107 if (vnode1 && DECL_INITIAL (node1->decl))
1108 return vnode1;
1110 return NULL;
1113 /* Walk all static variables with initializer set. */
1114 #define FOR_EACH_STATIC_INITIALIZER(node) \
1115 for ((node) = varpool_first_static_initializer (); (node); \
1116 (node) = varpool_next_static_initializer (node))
1118 /* Return first static variable with definition. */
1119 static inline varpool_node *
1120 varpool_first_defined_variable (void)
1122 symtab_node *node;
1123 for (node = symtab_nodes; node; node = node->next)
1125 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1126 if (vnode && vnode->definition)
1127 return vnode;
1129 return NULL;
1132 /* Return next static variable with definition after NODE. */
1133 static inline varpool_node *
1134 varpool_next_defined_variable (varpool_node *node)
1136 symtab_node *node1 = node->next;
1137 for (; node1; node1 = node1->next)
1139 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1140 if (vnode1 && vnode1->definition)
1141 return vnode1;
1143 return NULL;
1145 /* Walk all variables with definitions in current unit. */
1146 #define FOR_EACH_DEFINED_VARIABLE(node) \
1147 for ((node) = varpool_first_defined_variable (); (node); \
1148 (node) = varpool_next_defined_variable (node))
1150 /* Return first function with body defined. */
1151 static inline struct cgraph_node *
1152 cgraph_first_defined_function (void)
1154 symtab_node *node;
1155 for (node = symtab_nodes; node; node = node->next)
1157 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1158 if (cn && cn->definition)
1159 return cn;
1161 return NULL;
1164 /* Return next function with body defined after NODE. */
1165 static inline struct cgraph_node *
1166 cgraph_next_defined_function (struct cgraph_node *node)
1168 symtab_node *node1 = node->next;
1169 for (; node1; node1 = node1->next)
1171 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1172 if (cn1 && cn1->definition)
1173 return cn1;
1175 return NULL;
1178 /* Walk all functions with body defined. */
1179 #define FOR_EACH_DEFINED_FUNCTION(node) \
1180 for ((node) = cgraph_first_defined_function (); (node); \
1181 (node) = cgraph_next_defined_function ((node)))
1183 /* Return first function. */
1184 static inline struct cgraph_node *
1185 cgraph_first_function (void)
1187 symtab_node *node;
1188 for (node = symtab_nodes; node; node = node->next)
1189 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1190 return cn;
1191 return NULL;
1194 /* Return next function. */
1195 static inline struct cgraph_node *
1196 cgraph_next_function (struct cgraph_node *node)
1198 symtab_node *node1 = node->next;
1199 for (; node1; node1 = node1->next)
1200 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1201 return cn1;
1202 return NULL;
1204 /* Walk all functions. */
1205 #define FOR_EACH_FUNCTION(node) \
1206 for ((node) = cgraph_first_function (); (node); \
1207 (node) = cgraph_next_function ((node)))
1209 /* Return true when NODE is a function with Gimple body defined
1210 in current unit. Functions can also be define externally or they
1211 can be thunks with no Gimple representation.
1213 Note that at WPA stage, the function body may not be present in memory. */
1215 static inline bool
1216 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1218 return node->definition && !node->thunk.thunk_p && !node->alias;
1221 /* Return first function with body defined. */
1222 static inline struct cgraph_node *
1223 cgraph_first_function_with_gimple_body (void)
1225 symtab_node *node;
1226 for (node = symtab_nodes; node; node = node->next)
1228 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1229 if (cn && cgraph_function_with_gimple_body_p (cn))
1230 return cn;
1232 return NULL;
1235 /* Return next reachable static variable with initializer after NODE. */
1236 static inline struct cgraph_node *
1237 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1239 symtab_node *node1 = node->next;
1240 for (; node1; node1 = node1->next)
1242 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1243 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1244 return cn1;
1246 return NULL;
1249 /* Walk all functions with body defined. */
1250 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1251 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1252 (node) = cgraph_next_function_with_gimple_body (node))
1254 /* Create a new static variable of type TYPE. */
1255 tree add_new_static_var (tree type);
1257 /* Return true if iterator CSI points to nothing. */
1258 static inline bool
1259 csi_end_p (cgraph_node_set_iterator csi)
1261 return csi.index >= csi.set->nodes.length ();
1264 /* Advance iterator CSI. */
1265 static inline void
1266 csi_next (cgraph_node_set_iterator *csi)
1268 csi->index++;
1271 /* Return the node pointed to by CSI. */
1272 static inline struct cgraph_node *
1273 csi_node (cgraph_node_set_iterator csi)
1275 return csi.set->nodes[csi.index];
1278 /* Return an iterator to the first node in SET. */
1279 static inline cgraph_node_set_iterator
1280 csi_start (cgraph_node_set set)
1282 cgraph_node_set_iterator csi;
1284 csi.set = set;
1285 csi.index = 0;
1286 return csi;
1289 /* Return true if SET contains NODE. */
1290 static inline bool
1291 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1293 cgraph_node_set_iterator csi;
1294 csi = cgraph_node_set_find (set, node);
1295 return !csi_end_p (csi);
1298 /* Return number of nodes in SET. */
1299 static inline size_t
1300 cgraph_node_set_size (cgraph_node_set set)
1302 return set->nodes.length ();
1305 /* Return true if iterator VSI points to nothing. */
1306 static inline bool
1307 vsi_end_p (varpool_node_set_iterator vsi)
1309 return vsi.index >= vsi.set->nodes.length ();
1312 /* Advance iterator VSI. */
1313 static inline void
1314 vsi_next (varpool_node_set_iterator *vsi)
1316 vsi->index++;
1319 /* Return the node pointed to by VSI. */
1320 static inline varpool_node *
1321 vsi_node (varpool_node_set_iterator vsi)
1323 return vsi.set->nodes[vsi.index];
1326 /* Return an iterator to the first node in SET. */
1327 static inline varpool_node_set_iterator
1328 vsi_start (varpool_node_set set)
1330 varpool_node_set_iterator vsi;
1332 vsi.set = set;
1333 vsi.index = 0;
1334 return vsi;
1337 /* Return true if SET contains NODE. */
1338 static inline bool
1339 varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
1341 varpool_node_set_iterator vsi;
1342 vsi = varpool_node_set_find (set, node);
1343 return !vsi_end_p (vsi);
1346 /* Return number of nodes in SET. */
1347 static inline size_t
1348 varpool_node_set_size (varpool_node_set set)
1350 return set->nodes.length ();
1353 /* Uniquize all constants that appear in memory.
1354 Each constant in memory thus far output is recorded
1355 in `const_desc_table'. */
1357 struct GTY(()) constant_descriptor_tree {
1358 /* A MEM for the constant. */
1359 rtx rtl;
1361 /* The value of the constant. */
1362 tree value;
1364 /* Hash of value. Computing the hash from value each time
1365 hashfn is called can't work properly, as that means recursive
1366 use of the hash table during hash table expansion. */
1367 hashval_t hash;
1370 /* Return true if set is nonempty. */
1371 static inline bool
1372 cgraph_node_set_nonempty_p (cgraph_node_set set)
1374 return !set->nodes.is_empty ();
1377 /* Return true if set is nonempty. */
1378 static inline bool
1379 varpool_node_set_nonempty_p (varpool_node_set set)
1381 return !set->nodes.is_empty ();
1384 /* Return true when function NODE is only called directly or it has alias.
1385 i.e. it is not externally visible, address was not taken and
1386 it is not used in any other non-standard way. */
1388 static inline bool
1389 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1391 gcc_assert (!node->global.inlined_to);
1392 return (!node->force_output && !node->address_taken
1393 && !node->used_from_other_partition
1394 && !DECL_VIRTUAL_P (node->decl)
1395 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1396 && !DECL_STATIC_DESTRUCTOR (node->decl)
1397 && !node->externally_visible);
1400 /* Return true when function NODE can be removed from callgraph
1401 if all direct calls are eliminated. */
1403 static inline bool
1404 varpool_can_remove_if_no_refs (varpool_node *node)
1406 if (DECL_EXTERNAL (node->decl))
1407 return true;
1408 return (!node->force_output && !node->used_from_other_partition
1409 && ((DECL_COMDAT (node->decl)
1410 && !node->forced_by_abi
1411 && !symtab_used_from_object_file_p (node))
1412 || !node->externally_visible
1413 || DECL_HAS_VALUE_EXPR_P (node->decl)));
1416 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1417 i.e. if the variable is not externally visible or not used in some magic
1418 way (asm statement or such).
1419 The magic uses are all summarized in force_output flag. */
1421 static inline bool
1422 varpool_all_refs_explicit_p (varpool_node *vnode)
1424 return (vnode->definition
1425 && !vnode->externally_visible
1426 && !vnode->used_from_other_partition
1427 && !vnode->force_output);
1430 /* Constant pool accessor function. */
1431 htab_t constant_pool_htab (void);
1433 /* FIXME: inappropriate dependency of cgraph on IPA. */
1434 #include "ipa-ref-inline.h"
1436 /* Return node that alias N is aliasing. */
1438 static inline symtab_node *
1439 symtab_alias_target (symtab_node *n)
1441 struct ipa_ref *ref;
1442 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1443 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1444 return ref->referred;
1447 static inline struct cgraph_node *
1448 cgraph_alias_target (struct cgraph_node *n)
1450 return dyn_cast <cgraph_node *> (symtab_alias_target (n));
1453 static inline varpool_node *
1454 varpool_alias_target (varpool_node *n)
1456 return dyn_cast <varpool_node *> (symtab_alias_target (n));
1459 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1460 Do not walk through thunks.
1461 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1463 static inline struct cgraph_node *
1464 cgraph_function_or_thunk_node (struct cgraph_node *node,
1465 enum availability *availability = NULL)
1467 struct cgraph_node *n;
1469 n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node,
1470 availability));
1471 if (!n && availability)
1472 *availability = AVAIL_NOT_AVAILABLE;
1473 return n;
1475 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1476 Do not walk through thunks.
1477 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1479 static inline varpool_node *
1480 varpool_variable_node (varpool_node *node,
1481 enum availability *availability = NULL)
1483 varpool_node *n;
1485 if (node)
1486 n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node,
1487 availability));
1488 else
1489 n = NULL;
1491 if (!n && availability)
1492 *availability = AVAIL_NOT_AVAILABLE;
1493 return n;
1496 /* Return true when the edge E represents a direct recursion. */
1497 static inline bool
1498 cgraph_edge_recursive_p (struct cgraph_edge *e)
1500 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1501 if (e->caller->global.inlined_to)
1502 return e->caller->global.inlined_to->decl == callee->decl;
1503 else
1504 return e->caller->decl == callee->decl;
1507 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1508 static inline bool
1509 decl_is_tm_clone (const_tree fndecl)
1511 struct cgraph_node *n = cgraph_get_node (fndecl);
1512 if (n)
1513 return n->tm_clone;
1514 return false;
1517 /* Likewise indicate that a node is needed, i.e. reachable via some
1518 external means. */
1520 static inline void
1521 cgraph_mark_force_output_node (struct cgraph_node *node)
1523 node->force_output = 1;
1524 gcc_checking_assert (!node->global.inlined_to);
1527 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1528 or abstract function kept for debug info purposes only. */
1530 static inline bool
1531 symtab_real_symbol_p (symtab_node *node)
1533 struct cgraph_node *cnode;
1535 if (DECL_ABSTRACT (node->decl))
1536 return false;
1537 if (!is_a <cgraph_node *> (node))
1538 return true;
1539 cnode = cgraph (node);
1540 if (cnode->global.inlined_to)
1541 return false;
1542 return true;
1545 /* Return true if NODE can be discarded by linker from the binary. */
1547 static inline bool
1548 symtab_can_be_discarded (symtab_node *node)
1550 return (DECL_EXTERNAL (node->decl)
1551 || (DECL_ONE_ONLY (node->decl)
1552 && node->resolution != LDPR_PREVAILING_DEF
1553 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1554 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1557 /* Return true if NODE is local to a particular COMDAT group, and must not
1558 be named from outside the COMDAT. This is used for C++ decloned
1559 constructors. */
1561 static inline bool
1562 symtab_comdat_local_p (symtab_node *node)
1564 return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1567 /* Return true if ONE and TWO are part of the same COMDAT group. */
1569 static inline bool
1570 symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1572 if (cgraph_node *cn = dyn_cast <cgraph_node *> (one))
1574 if (cn->global.inlined_to)
1575 one = cn->global.inlined_to;
1577 if (cgraph_node *cn = dyn_cast <cgraph_node *> (two))
1579 if (cn->global.inlined_to)
1580 two = cn->global.inlined_to;
1583 return DECL_COMDAT_GROUP (one->decl) == DECL_COMDAT_GROUP (two->decl);
1585 #endif /* GCC_CGRAPH_H */