* cgraph.h (symtab_first_defined_symbol, symtab_next_defined_symbol):
[official-gcc.git] / gcc / cgraph.h
blob8f13ecbe11cefcc4e18891ef1a928181659a7625
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_node (symtab_node *);
729 symtab_node *symtab_get_node (const_tree);
730 symtab_node *symtab_node_for_asm (const_tree asmname);
731 void symtab_insert_node_to_hashtable (symtab_node *);
732 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
733 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
734 void dump_symtab (FILE *);
735 void debug_symtab (void);
736 void dump_symtab_node (FILE *, symtab_node *);
737 void debug_symtab_node (symtab_node *);
738 void dump_symtab_base (FILE *, symtab_node *);
739 void verify_symtab (void);
740 void verify_symtab_node (symtab_node *);
741 bool verify_symtab_base (symtab_node *);
742 bool symtab_used_from_object_file_p (symtab_node *);
743 void symtab_make_decl_local (tree);
744 symtab_node *symtab_alias_ultimate_target (symtab_node *,
745 enum availability *avail = NULL);
746 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
747 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
748 bool symtab_for_node_and_aliases (symtab_node *,
749 bool (*) (symtab_node *, void *),
750 void *,
751 bool);
752 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
753 enum availability symtab_node_availability (symtab_node *);
754 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
755 enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
757 /* In cgraph.c */
758 void dump_cgraph (FILE *);
759 void debug_cgraph (void);
760 void dump_cgraph_node (FILE *, struct cgraph_node *);
761 void debug_cgraph_node (struct cgraph_node *);
762 void cgraph_remove_edge (struct cgraph_edge *);
763 void cgraph_remove_node (struct cgraph_node *);
764 void cgraph_release_function_body (struct cgraph_node *);
765 void release_function_body (tree);
766 void cgraph_node_remove_callees (struct cgraph_node *node);
767 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
768 struct cgraph_node *,
769 gimple, gcov_type, int);
770 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
771 int, gcov_type, int);
772 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
773 struct cgraph_node * cgraph_create_node (tree);
774 struct cgraph_node * cgraph_create_empty_node (void);
775 struct cgraph_node * cgraph_get_create_node (tree);
776 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
777 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
778 HOST_WIDE_INT, tree, tree);
779 struct cgraph_node *cgraph_node_for_asm (tree);
780 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
781 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
782 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
783 struct cgraph_local_info *cgraph_local_info (tree);
784 struct cgraph_global_info *cgraph_global_info (tree);
785 struct cgraph_rtl_info *cgraph_rtl_info (tree);
786 struct cgraph_node *cgraph_create_function_alias (tree, tree);
787 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
788 struct cgraph_node *);
789 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
790 struct cgraph_edge *);
792 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
793 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
794 bool cgraph_only_called_directly_p (struct cgraph_node *);
796 bool cgraph_function_possibly_inlined_p (tree);
797 void cgraph_unnest_node (struct cgraph_node *);
799 enum availability cgraph_function_body_availability (struct cgraph_node *);
800 void cgraph_add_new_function (tree, bool);
801 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
802 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
804 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
805 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
806 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
807 bool cgraph_node_cannot_return (struct cgraph_node *);
808 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
809 bool cgraph_will_be_removed_from_program_if_no_direct_calls
810 (struct cgraph_node *node);
811 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
812 (struct cgraph_node *node);
813 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
814 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
815 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
816 bool (*) (struct cgraph_node *, void *),
817 void *,
818 bool);
819 bool cgraph_for_node_and_aliases (struct cgraph_node *,
820 bool (*) (struct cgraph_node *, void *),
821 void *, bool);
822 vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
823 void verify_cgraph (void);
824 void verify_cgraph_node (struct cgraph_node *);
825 void cgraph_mark_address_taken_node (struct cgraph_node *);
827 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
828 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
829 typedef void (*varpool_node_hook)(varpool_node *, void *);
830 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
831 void *);
832 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
833 void *);
834 struct cgraph_edge_hook_list;
835 struct cgraph_node_hook_list;
836 struct varpool_node_hook_list;
837 struct cgraph_2edge_hook_list;
838 struct cgraph_2node_hook_list;
839 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
840 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
841 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
842 void *);
843 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
844 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
845 void *);
846 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
847 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
848 void *);
849 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
850 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
851 void *);
852 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
853 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
854 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
855 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
856 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
857 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
858 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
859 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
860 enum availability *avail = NULL);
861 bool cgraph_get_body (struct cgraph_node *node);
862 struct cgraph_edge *
863 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
864 struct cgraph_node *,
865 gcov_type, int);
866 void cgraph_speculative_call_info (struct cgraph_edge *,
867 struct cgraph_edge *&,
868 struct cgraph_edge *&,
869 struct ipa_ref *&);
870 extern bool gimple_check_call_matching_types (gimple, tree, bool);
872 /* In cgraphunit.c */
873 struct asm_node *add_asm_node (tree);
874 extern FILE *cgraph_dump_file;
875 void cgraph_finalize_function (tree, bool);
876 void finalize_compilation_unit (void);
877 void compile (void);
878 void init_cgraph (void);
879 void cgraph_process_new_functions (void);
880 void cgraph_process_same_body_aliases (void);
881 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
882 /* Initialize datastructures so DECL is a function in lowered gimple form.
883 IN_SSA is true if the gimple is in SSA. */
884 basic_block init_lowered_empty_function (tree, bool);
885 void cgraph_reset_node (struct cgraph_node *);
886 bool expand_thunk (struct cgraph_node *, bool);
888 /* In cgraphclones.c */
890 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
891 struct cgraph_node *, gimple,
892 unsigned, gcov_type, int, bool);
893 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
894 int, bool, vec<cgraph_edge_p>,
895 bool, struct cgraph_node *, bitmap);
896 tree clone_function_name (tree decl, const char *);
897 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
898 vec<cgraph_edge_p>,
899 vec<ipa_replace_map_p, va_gc> *tree_map,
900 bitmap args_to_skip,
901 const char *clone_name);
902 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
903 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
904 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
905 bool update_speculative = true);
906 void cgraph_create_edge_including_clones (struct cgraph_node *,
907 struct cgraph_node *,
908 gimple, gimple, gcov_type, int,
909 cgraph_inline_failed_t);
910 void cgraph_materialize_all_clones (void);
911 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
912 tree, vec<cgraph_edge_p>, bitmap);
913 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
914 vec<cgraph_edge_p>,
915 vec<ipa_replace_map_p, va_gc> *,
916 bitmap, bool, bitmap,
917 basic_block, const char *);
918 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
919 bool, bitmap, bool, bitmap, basic_block);
920 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
922 /* In cgraphbuild.c */
923 unsigned int rebuild_cgraph_edges (void);
924 void cgraph_rebuild_references (void);
925 int compute_call_stmt_bb_frequency (tree, basic_block bb);
926 void record_references_in_initializer (tree, bool);
927 void ipa_record_stmt_references (struct cgraph_node *, gimple);
929 /* In ipa.c */
930 bool symtab_remove_unreachable_nodes (bool, FILE *);
931 cgraph_node_set cgraph_node_set_new (void);
932 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
933 struct cgraph_node *);
934 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
935 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
936 void dump_cgraph_node_set (FILE *, cgraph_node_set);
937 void debug_cgraph_node_set (cgraph_node_set);
938 void free_cgraph_node_set (cgraph_node_set);
939 void cgraph_build_static_cdtor (char which, tree body, int priority);
941 varpool_node_set varpool_node_set_new (void);
942 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
943 varpool_node *);
944 void varpool_node_set_add (varpool_node_set, varpool_node *);
945 void varpool_node_set_remove (varpool_node_set, varpool_node *);
946 void dump_varpool_node_set (FILE *, varpool_node_set);
947 void debug_varpool_node_set (varpool_node_set);
948 void free_varpool_node_set (varpool_node_set);
949 void ipa_discover_readonly_nonaddressable_vars (void);
950 bool varpool_externally_visible_p (varpool_node *);
952 /* In predict.c */
953 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
954 bool cgraph_optimize_for_size_p (struct cgraph_node *);
956 /* In varpool.c */
957 varpool_node *varpool_create_empty_node (void);
958 varpool_node *varpool_node_for_decl (tree);
959 varpool_node *varpool_node_for_asm (tree asmname);
960 void varpool_mark_needed_node (varpool_node *);
961 void debug_varpool (void);
962 void dump_varpool (FILE *);
963 void dump_varpool_node (FILE *, varpool_node *);
965 void varpool_finalize_decl (tree);
966 enum availability cgraph_variable_initializer_availability (varpool_node *);
967 void cgraph_make_node_local (struct cgraph_node *);
968 bool cgraph_node_can_be_local_p (struct cgraph_node *);
971 void varpool_remove_node (varpool_node *node);
972 void varpool_finalize_named_section_flags (varpool_node *node);
973 bool varpool_output_variables (void);
974 bool varpool_assemble_decl (varpool_node *node);
975 void varpool_analyze_node (varpool_node *);
976 varpool_node * varpool_extra_name_alias (tree, tree);
977 varpool_node * varpool_create_variable_alias (tree, tree);
978 void varpool_reset_queue (void);
979 tree ctor_for_folding (tree);
980 bool varpool_for_node_and_aliases (varpool_node *,
981 bool (*) (varpool_node *, void *),
982 void *, bool);
983 void varpool_add_new_variable (tree);
984 void symtab_initialize_asm_name_hash (void);
985 void symtab_prevail_in_asm_name_hash (symtab_node *node);
986 void varpool_remove_initializer (varpool_node *);
988 /* In cgraph.c */
989 extern void change_decl_assembler_name (tree, tree);
991 /* Return callgraph node for given symbol and check it is a function. */
992 static inline struct cgraph_node *
993 cgraph (symtab_node *node)
995 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
996 return (struct cgraph_node *)node;
999 /* Return varpool node for given symbol and check it is a variable. */
1000 static inline varpool_node *
1001 varpool (symtab_node *node)
1003 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
1004 return (varpool_node *)node;
1007 /* Return callgraph node for given symbol and check it is a function. */
1008 static inline struct cgraph_node *
1009 cgraph_get_node (const_tree decl)
1011 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1012 return cgraph (symtab_get_node (decl));
1015 /* Return varpool node for given symbol and check it is a function. */
1016 static inline varpool_node *
1017 varpool_get_node (const_tree decl)
1019 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1020 return varpool (symtab_get_node (decl));
1023 /* Walk all symbols. */
1024 #define FOR_EACH_SYMBOL(node) \
1025 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1027 /* Return first static symbol with definition. */
1028 static inline symtab_node *
1029 symtab_first_defined_symbol (void)
1031 symtab_node *node;
1033 for (node = symtab_nodes; node; node = node->next)
1034 if (node->definition)
1035 return node;
1037 return NULL;
1040 /* Return next reachable static symbol with initializer after NODE. */
1041 static inline symtab_node *
1042 symtab_next_defined_symbol (symtab_node *node)
1044 symtab_node *node1 = node->next;
1046 for (; node1; node1 = node1->next)
1047 if (node1->definition)
1048 return node1;
1050 return NULL;
1052 /* Walk all symbols with definitions in current unit. */
1053 #define FOR_EACH_DEFINED_SYMBOL(node) \
1054 for ((node) = symtab_first_defined_symbol (); (node); \
1055 (node) = symtab_next_defined_symbol (node))
1057 /* Return first variable. */
1058 static inline varpool_node *
1059 varpool_first_variable (void)
1061 symtab_node *node;
1062 for (node = symtab_nodes; node; node = node->next)
1063 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1064 return vnode;
1065 return NULL;
1068 /* Return next variable after NODE. */
1069 static inline varpool_node *
1070 varpool_next_variable (varpool_node *node)
1072 symtab_node *node1 = node->next;
1073 for (; node1; node1 = node1->next)
1074 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1075 return vnode1;
1076 return NULL;
1078 /* Walk all variables. */
1079 #define FOR_EACH_VARIABLE(node) \
1080 for ((node) = varpool_first_variable (); \
1081 (node); \
1082 (node) = varpool_next_variable ((node)))
1084 /* Return first static variable with initializer. */
1085 static inline varpool_node *
1086 varpool_first_static_initializer (void)
1088 symtab_node *node;
1089 for (node = symtab_nodes; node; node = node->next)
1091 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1092 if (vnode && DECL_INITIAL (node->decl))
1093 return vnode;
1095 return NULL;
1098 /* Return next static variable with initializer after NODE. */
1099 static inline varpool_node *
1100 varpool_next_static_initializer (varpool_node *node)
1102 symtab_node *node1 = node->next;
1103 for (; node1; node1 = node1->next)
1105 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1106 if (vnode1 && DECL_INITIAL (node1->decl))
1107 return vnode1;
1109 return NULL;
1112 /* Walk all static variables with initializer set. */
1113 #define FOR_EACH_STATIC_INITIALIZER(node) \
1114 for ((node) = varpool_first_static_initializer (); (node); \
1115 (node) = varpool_next_static_initializer (node))
1117 /* Return first static variable with definition. */
1118 static inline varpool_node *
1119 varpool_first_defined_variable (void)
1121 symtab_node *node;
1122 for (node = symtab_nodes; node; node = node->next)
1124 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1125 if (vnode && vnode->definition)
1126 return vnode;
1128 return NULL;
1131 /* Return next static variable with definition after NODE. */
1132 static inline varpool_node *
1133 varpool_next_defined_variable (varpool_node *node)
1135 symtab_node *node1 = node->next;
1136 for (; node1; node1 = node1->next)
1138 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1139 if (vnode1 && vnode1->definition)
1140 return vnode1;
1142 return NULL;
1144 /* Walk all variables with definitions in current unit. */
1145 #define FOR_EACH_DEFINED_VARIABLE(node) \
1146 for ((node) = varpool_first_defined_variable (); (node); \
1147 (node) = varpool_next_defined_variable (node))
1149 /* Return first function with body defined. */
1150 static inline struct cgraph_node *
1151 cgraph_first_defined_function (void)
1153 symtab_node *node;
1154 for (node = symtab_nodes; node; node = node->next)
1156 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1157 if (cn && cn->definition)
1158 return cn;
1160 return NULL;
1163 /* Return next function with body defined after NODE. */
1164 static inline struct cgraph_node *
1165 cgraph_next_defined_function (struct cgraph_node *node)
1167 symtab_node *node1 = node->next;
1168 for (; node1; node1 = node1->next)
1170 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1171 if (cn1 && cn1->definition)
1172 return cn1;
1174 return NULL;
1177 /* Walk all functions with body defined. */
1178 #define FOR_EACH_DEFINED_FUNCTION(node) \
1179 for ((node) = cgraph_first_defined_function (); (node); \
1180 (node) = cgraph_next_defined_function ((node)))
1182 /* Return first function. */
1183 static inline struct cgraph_node *
1184 cgraph_first_function (void)
1186 symtab_node *node;
1187 for (node = symtab_nodes; node; node = node->next)
1188 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1189 return cn;
1190 return NULL;
1193 /* Return next function. */
1194 static inline struct cgraph_node *
1195 cgraph_next_function (struct cgraph_node *node)
1197 symtab_node *node1 = node->next;
1198 for (; node1; node1 = node1->next)
1199 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1200 return cn1;
1201 return NULL;
1203 /* Walk all functions. */
1204 #define FOR_EACH_FUNCTION(node) \
1205 for ((node) = cgraph_first_function (); (node); \
1206 (node) = cgraph_next_function ((node)))
1208 /* Return true when NODE is a function with Gimple body defined
1209 in current unit. Functions can also be define externally or they
1210 can be thunks with no Gimple representation.
1212 Note that at WPA stage, the function body may not be present in memory. */
1214 static inline bool
1215 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1217 return node->definition && !node->thunk.thunk_p && !node->alias;
1220 /* Return first function with body defined. */
1221 static inline struct cgraph_node *
1222 cgraph_first_function_with_gimple_body (void)
1224 symtab_node *node;
1225 for (node = symtab_nodes; node; node = node->next)
1227 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1228 if (cn && cgraph_function_with_gimple_body_p (cn))
1229 return cn;
1231 return NULL;
1234 /* Return next reachable static variable with initializer after NODE. */
1235 static inline struct cgraph_node *
1236 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1238 symtab_node *node1 = node->next;
1239 for (; node1; node1 = node1->next)
1241 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1242 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1243 return cn1;
1245 return NULL;
1248 /* Walk all functions with body defined. */
1249 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1250 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1251 (node) = cgraph_next_function_with_gimple_body (node))
1253 /* Create a new static variable of type TYPE. */
1254 tree add_new_static_var (tree type);
1256 /* Return true if iterator CSI points to nothing. */
1257 static inline bool
1258 csi_end_p (cgraph_node_set_iterator csi)
1260 return csi.index >= csi.set->nodes.length ();
1263 /* Advance iterator CSI. */
1264 static inline void
1265 csi_next (cgraph_node_set_iterator *csi)
1267 csi->index++;
1270 /* Return the node pointed to by CSI. */
1271 static inline struct cgraph_node *
1272 csi_node (cgraph_node_set_iterator csi)
1274 return csi.set->nodes[csi.index];
1277 /* Return an iterator to the first node in SET. */
1278 static inline cgraph_node_set_iterator
1279 csi_start (cgraph_node_set set)
1281 cgraph_node_set_iterator csi;
1283 csi.set = set;
1284 csi.index = 0;
1285 return csi;
1288 /* Return true if SET contains NODE. */
1289 static inline bool
1290 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1292 cgraph_node_set_iterator csi;
1293 csi = cgraph_node_set_find (set, node);
1294 return !csi_end_p (csi);
1297 /* Return number of nodes in SET. */
1298 static inline size_t
1299 cgraph_node_set_size (cgraph_node_set set)
1301 return set->nodes.length ();
1304 /* Return true if iterator VSI points to nothing. */
1305 static inline bool
1306 vsi_end_p (varpool_node_set_iterator vsi)
1308 return vsi.index >= vsi.set->nodes.length ();
1311 /* Advance iterator VSI. */
1312 static inline void
1313 vsi_next (varpool_node_set_iterator *vsi)
1315 vsi->index++;
1318 /* Return the node pointed to by VSI. */
1319 static inline varpool_node *
1320 vsi_node (varpool_node_set_iterator vsi)
1322 return vsi.set->nodes[vsi.index];
1325 /* Return an iterator to the first node in SET. */
1326 static inline varpool_node_set_iterator
1327 vsi_start (varpool_node_set set)
1329 varpool_node_set_iterator vsi;
1331 vsi.set = set;
1332 vsi.index = 0;
1333 return vsi;
1336 /* Return true if SET contains NODE. */
1337 static inline bool
1338 varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
1340 varpool_node_set_iterator vsi;
1341 vsi = varpool_node_set_find (set, node);
1342 return !vsi_end_p (vsi);
1345 /* Return number of nodes in SET. */
1346 static inline size_t
1347 varpool_node_set_size (varpool_node_set set)
1349 return set->nodes.length ();
1352 /* Uniquize all constants that appear in memory.
1353 Each constant in memory thus far output is recorded
1354 in `const_desc_table'. */
1356 struct GTY(()) constant_descriptor_tree {
1357 /* A MEM for the constant. */
1358 rtx rtl;
1360 /* The value of the constant. */
1361 tree value;
1363 /* Hash of value. Computing the hash from value each time
1364 hashfn is called can't work properly, as that means recursive
1365 use of the hash table during hash table expansion. */
1366 hashval_t hash;
1369 /* Return true if set is nonempty. */
1370 static inline bool
1371 cgraph_node_set_nonempty_p (cgraph_node_set set)
1373 return !set->nodes.is_empty ();
1376 /* Return true if set is nonempty. */
1377 static inline bool
1378 varpool_node_set_nonempty_p (varpool_node_set set)
1380 return !set->nodes.is_empty ();
1383 /* Return true when function NODE is only called directly or it has alias.
1384 i.e. it is not externally visible, address was not taken and
1385 it is not used in any other non-standard way. */
1387 static inline bool
1388 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1390 gcc_assert (!node->global.inlined_to);
1391 return (!node->force_output && !node->address_taken
1392 && !node->used_from_other_partition
1393 && !DECL_VIRTUAL_P (node->decl)
1394 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1395 && !DECL_STATIC_DESTRUCTOR (node->decl)
1396 && !node->externally_visible);
1399 /* Return true when function NODE can be removed from callgraph
1400 if all direct calls are eliminated. */
1402 static inline bool
1403 varpool_can_remove_if_no_refs (varpool_node *node)
1405 if (DECL_EXTERNAL (node->decl))
1406 return true;
1407 return (!node->force_output && !node->used_from_other_partition
1408 && ((DECL_COMDAT (node->decl)
1409 && !node->forced_by_abi
1410 && !symtab_used_from_object_file_p (node))
1411 || !node->externally_visible
1412 || DECL_HAS_VALUE_EXPR_P (node->decl)));
1415 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1416 i.e. if the variable is not externally visible or not used in some magic
1417 way (asm statement or such).
1418 The magic uses are all summarized in force_output flag. */
1420 static inline bool
1421 varpool_all_refs_explicit_p (varpool_node *vnode)
1423 return (vnode->definition
1424 && !vnode->externally_visible
1425 && !vnode->used_from_other_partition
1426 && !vnode->force_output);
1429 /* Constant pool accessor function. */
1430 htab_t constant_pool_htab (void);
1432 /* FIXME: inappropriate dependency of cgraph on IPA. */
1433 #include "ipa-ref-inline.h"
1435 /* Return node that alias N is aliasing. */
1437 static inline symtab_node *
1438 symtab_alias_target (symtab_node *n)
1440 struct ipa_ref *ref;
1441 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1442 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1443 return ref->referred;
1446 static inline struct cgraph_node *
1447 cgraph_alias_target (struct cgraph_node *n)
1449 return dyn_cast <cgraph_node *> (symtab_alias_target (n));
1452 static inline varpool_node *
1453 varpool_alias_target (varpool_node *n)
1455 return dyn_cast <varpool_node *> (symtab_alias_target (n));
1458 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1459 Do not walk through thunks.
1460 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1462 static inline struct cgraph_node *
1463 cgraph_function_or_thunk_node (struct cgraph_node *node,
1464 enum availability *availability = NULL)
1466 struct cgraph_node *n;
1468 n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node,
1469 availability));
1470 if (!n && availability)
1471 *availability = AVAIL_NOT_AVAILABLE;
1472 return n;
1474 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1475 Do not walk through thunks.
1476 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1478 static inline varpool_node *
1479 varpool_variable_node (varpool_node *node,
1480 enum availability *availability = NULL)
1482 varpool_node *n;
1484 if (node)
1485 n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node,
1486 availability));
1487 else
1488 n = NULL;
1490 if (!n && availability)
1491 *availability = AVAIL_NOT_AVAILABLE;
1492 return n;
1495 /* Return true when the edge E represents a direct recursion. */
1496 static inline bool
1497 cgraph_edge_recursive_p (struct cgraph_edge *e)
1499 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1500 if (e->caller->global.inlined_to)
1501 return e->caller->global.inlined_to->decl == callee->decl;
1502 else
1503 return e->caller->decl == callee->decl;
1506 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1507 static inline bool
1508 decl_is_tm_clone (const_tree fndecl)
1510 struct cgraph_node *n = cgraph_get_node (fndecl);
1511 if (n)
1512 return n->tm_clone;
1513 return false;
1516 /* Likewise indicate that a node is needed, i.e. reachable via some
1517 external means. */
1519 static inline void
1520 cgraph_mark_force_output_node (struct cgraph_node *node)
1522 node->force_output = 1;
1523 gcc_checking_assert (!node->global.inlined_to);
1526 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1527 or abstract function kept for debug info purposes only. */
1529 static inline bool
1530 symtab_real_symbol_p (symtab_node *node)
1532 struct cgraph_node *cnode;
1534 if (DECL_ABSTRACT (node->decl))
1535 return false;
1536 if (!is_a <cgraph_node *> (node))
1537 return true;
1538 cnode = cgraph (node);
1539 if (cnode->global.inlined_to)
1540 return false;
1541 return true;
1544 /* Return true if NODE can be discarded by linker from the binary. */
1546 static inline bool
1547 symtab_can_be_discarded (symtab_node *node)
1549 return (DECL_EXTERNAL (node->decl)
1550 || (DECL_ONE_ONLY (node->decl)
1551 && node->resolution != LDPR_PREVAILING_DEF
1552 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1553 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1556 /* Return true if NODE is local to a particular COMDAT group, and must not
1557 be named from outside the COMDAT. This is used for C++ decloned
1558 constructors. */
1560 static inline bool
1561 symtab_comdat_local_p (symtab_node *node)
1563 return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1566 /* Return true if ONE and TWO are part of the same COMDAT group. */
1568 static inline bool
1569 symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1571 if (cgraph_node *cn = dyn_cast <cgraph_node *> (one))
1573 if (cn->global.inlined_to)
1574 one = cn->global.inlined_to;
1576 if (cgraph_node *cn = dyn_cast <cgraph_node *> (two))
1578 if (cn->global.inlined_to)
1579 two = cn->global.inlined_to;
1582 return DECL_COMDAT_GROUP (one->decl) == DECL_COMDAT_GROUP (two->decl);
1584 #endif /* GCC_CGRAPH_H */