svnmerge up to trunk revision 211147
[official-gcc.git] / gcc / cgraph.h
blobc7047de011d3700f331775b3461d009e9da0d7cd
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 /* Return comdat group. */
145 tree get_comdat_group ()
147 return comdat_group_;
150 tree get_comdat_group_id ()
152 if (comdat_group_ && TREE_CODE (comdat_group_) != IDENTIFIER_NODE)
153 comdat_group_ = DECL_ASSEMBLER_NAME (comdat_group_);
154 return comdat_group_;
157 /* Set comdat group. */
158 void set_comdat_group (tree group)
160 comdat_group_ = group;
163 /* Vectors of referring and referenced entities. */
164 struct ipa_ref_list ref_list;
166 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
167 depending to what was known to frontend on the creation time.
168 Once alias is resolved, this pointer become NULL. */
169 tree alias_target;
171 /* File stream where this node is being written to. */
172 struct lto_file_decl_data * lto_file_data;
174 PTR GTY ((skip)) aux;
176 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
177 tree comdat_group_;
180 enum availability
182 /* Not yet set by cgraph_function_body_availability. */
183 AVAIL_UNSET,
184 /* Function body/variable initializer is unknown. */
185 AVAIL_NOT_AVAILABLE,
186 /* Function body/variable initializer is known but might be replaced
187 by a different one from other compilation unit and thus needs to
188 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
189 arbitrary side effects on escaping variables and functions, while
190 like AVAILABLE it might access static variables. */
191 AVAIL_OVERWRITABLE,
192 /* Function body/variable initializer is known and will be used in final
193 program. */
194 AVAIL_AVAILABLE,
195 /* Function body/variable initializer is known and all it's uses are explicitly
196 visible within current unit (ie it's address is never taken and it is not
197 exported to other units).
198 Currently used only for functions. */
199 AVAIL_LOCAL
202 /* This is the information that is put into the cgraph local structure
203 to recover a function. */
204 struct lto_file_decl_data;
206 extern const char * const cgraph_availability_names[];
207 extern const char * const ld_plugin_symbol_resolution_names[];
209 /* Information about thunk, used only for same body aliases. */
211 struct GTY(()) cgraph_thunk_info {
212 /* Information about the thunk. */
213 HOST_WIDE_INT fixed_offset;
214 HOST_WIDE_INT virtual_value;
215 tree alias;
216 bool this_adjusting;
217 bool virtual_offset_p;
218 /* Set to true when alias node is thunk. */
219 bool thunk_p;
222 /* Information about the function collected locally.
223 Available after function is analyzed. */
225 struct GTY(()) cgraph_local_info {
226 /* Set when function function is visible in current compilation unit only
227 and its address is never taken. */
228 unsigned local : 1;
230 /* False when there is something makes versioning impossible. */
231 unsigned versionable : 1;
233 /* False when function calling convention and signature can not be changed.
234 This is the case when __builtin_apply_args is used. */
235 unsigned can_change_signature : 1;
237 /* True when the function has been originally extern inline, but it is
238 redefined now. */
239 unsigned redefined_extern_inline : 1;
241 /* True if the function may enter serial irrevocable mode. */
242 unsigned tm_may_enter_irr : 1;
244 /* have we computed liveness pressure for inlining decisions */
245 unsigned liveness_pressure_computed : 1;
247 /* what is the liveness pressure value */
248 unsigned liveness_pressure;
251 /* Information about the function that needs to be computed globally
252 once compilation is finished. Available only with -funit-at-a-time. */
254 struct GTY(()) cgraph_global_info {
255 /* For inline clones this points to the function they will be
256 inlined into. */
257 struct cgraph_node *inlined_to;
260 /* Information about the function that is propagated by the RTL backend.
261 Available only for functions that has been already assembled. */
263 struct GTY(()) cgraph_rtl_info {
264 unsigned int preferred_incoming_stack_boundary;
266 /* Call unsaved hard registers really used by the corresponding
267 function (including ones used by functions called by the
268 function). */
269 HARD_REG_SET function_used_regs;
270 /* Set if function_used_regs is valid. */
271 unsigned function_used_regs_valid: 1;
274 /* Represent which DECL tree (or reference to such tree)
275 will be replaced by another tree while versioning. */
276 struct GTY(()) ipa_replace_map
278 /* The tree that will be replaced. */
279 tree old_tree;
280 /* The new (replacing) tree. */
281 tree new_tree;
282 /* Parameter number to replace, when old_tree is NULL. */
283 int parm_num;
284 /* True when a substitution should be done, false otherwise. */
285 bool replace_p;
286 /* True when we replace a reference to old_tree. */
287 bool ref_p;
289 typedef struct ipa_replace_map *ipa_replace_map_p;
291 struct GTY(()) cgraph_clone_info
293 vec<ipa_replace_map_p, va_gc> *tree_map;
294 bitmap args_to_skip;
295 bitmap combined_args_to_skip;
298 enum cgraph_simd_clone_arg_type
300 SIMD_CLONE_ARG_TYPE_VECTOR,
301 SIMD_CLONE_ARG_TYPE_UNIFORM,
302 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
303 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
304 SIMD_CLONE_ARG_TYPE_MASK
307 /* Function arguments in the original function of a SIMD clone.
308 Supplementary data for `struct simd_clone'. */
310 struct GTY(()) cgraph_simd_clone_arg {
311 /* Original function argument as it originally existed in
312 DECL_ARGUMENTS. */
313 tree orig_arg;
315 /* orig_arg's function (or for extern functions type from
316 TYPE_ARG_TYPES). */
317 tree orig_type;
319 /* If argument is a vector, this holds the vector version of
320 orig_arg that after adjusting the argument types will live in
321 DECL_ARGUMENTS. Otherwise, this is NULL.
323 This basically holds:
324 vector(simdlen) __typeof__(orig_arg) new_arg. */
325 tree vector_arg;
327 /* vector_arg's type (or for extern functions new vector type. */
328 tree vector_type;
330 /* If argument is a vector, this holds the array where the simd
331 argument is held while executing the simd clone function. This
332 is a local variable in the cloned function. Its content is
333 copied from vector_arg upon entry to the clone.
335 This basically holds:
336 __typeof__(orig_arg) simd_array[simdlen]. */
337 tree simd_array;
339 /* A SIMD clone's argument can be either linear (constant or
340 variable), uniform, or vector. */
341 enum cgraph_simd_clone_arg_type arg_type;
343 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
344 the constant linear step, if arg_type is
345 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
346 the uniform argument holding the step, otherwise 0. */
347 HOST_WIDE_INT linear_step;
349 /* Variable alignment if available, otherwise 0. */
350 unsigned int alignment;
353 /* Specific data for a SIMD function clone. */
355 struct GTY(()) cgraph_simd_clone {
356 /* Number of words in the SIMD lane associated with this clone. */
357 unsigned int simdlen;
359 /* Number of annotated function arguments in `args'. This is
360 usually the number of named arguments in FNDECL. */
361 unsigned int nargs;
363 /* Max hardware vector size in bits for integral vectors. */
364 unsigned int vecsize_int;
366 /* Max hardware vector size in bits for floating point vectors. */
367 unsigned int vecsize_float;
369 /* The mangling character for a given vector size. This is is used
370 to determine the ISA mangling bit as specified in the Intel
371 Vector ABI. */
372 unsigned char vecsize_mangle;
374 /* True if this is the masked, in-branch version of the clone,
375 otherwise false. */
376 unsigned int inbranch : 1;
378 /* True if this is a Cilk Plus variant. */
379 unsigned int cilk_elemental : 1;
381 /* Doubly linked list of SIMD clones. */
382 struct cgraph_node *prev_clone, *next_clone;
384 /* Original cgraph node the SIMD clones were created for. */
385 struct cgraph_node *origin;
387 /* Annotated function arguments for the original function. */
388 struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
392 /* The cgraph data structure.
393 Each function decl has assigned cgraph_node listing callees and callers. */
395 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
396 public:
397 struct cgraph_edge *callees;
398 struct cgraph_edge *callers;
399 /* List of edges representing indirect calls with a yet undetermined
400 callee. */
401 struct cgraph_edge *indirect_calls;
402 /* For nested functions points to function the node is nested in. */
403 struct cgraph_node *origin;
404 /* Points to first nested function, if any. */
405 struct cgraph_node *nested;
406 /* Pointer to the next function with same origin, if any. */
407 struct cgraph_node *next_nested;
408 /* Pointer to the next clone. */
409 struct cgraph_node *next_sibling_clone;
410 struct cgraph_node *prev_sibling_clone;
411 struct cgraph_node *clones;
412 struct cgraph_node *clone_of;
413 /* For functions with many calls sites it holds map from call expression
414 to the edge to speed up cgraph_edge function. */
415 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
416 /* Declaration node used to be clone of. */
417 tree former_clone_of;
419 /* If this is a SIMD clone, this points to the SIMD specific
420 information for it. */
421 struct cgraph_simd_clone *simdclone;
422 /* If this function has SIMD clones, this points to the first clone. */
423 struct cgraph_node *simd_clones;
425 /* Interprocedural passes scheduled to have their transform functions
426 applied next time we execute local pass on them. We maintain it
427 per-function in order to allow IPA passes to introduce new functions. */
428 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
430 struct cgraph_local_info local;
431 struct cgraph_global_info global;
432 struct cgraph_rtl_info rtl;
433 struct cgraph_clone_info clone;
434 struct cgraph_thunk_info thunk;
436 /* Expected number of executions: calculated in profile.c. */
437 gcov_type count;
438 /* How to scale counts at materialization time; used to merge
439 LTO units with different number of profile runs. */
440 int count_materialization_scale;
441 /* Unique id of the node. */
442 int uid;
443 /* ID assigned by the profiling. */
444 unsigned int profile_id;
445 /* Time profiler: first run of function. */
446 int tp_first_run;
448 /* Set when decl is an abstract function pointed to by the
449 ABSTRACT_DECL_ORIGIN of a reachable function. */
450 unsigned used_as_abstract_origin : 1;
451 /* Set once the function is lowered (i.e. its CFG is built). */
452 unsigned lowered : 1;
453 /* Set once the function has been instantiated and its callee
454 lists created. */
455 unsigned process : 1;
456 /* How commonly executed the node is. Initialized during branch
457 probabilities pass. */
458 ENUM_BITFIELD (node_frequency) frequency : 2;
459 /* True when function can only be called at startup (from static ctor). */
460 unsigned only_called_at_startup : 1;
461 /* True when function can only be called at startup (from static dtor). */
462 unsigned only_called_at_exit : 1;
463 /* True when function is the transactional clone of a function which
464 is called only from inside transactions. */
465 /* ?? We should be able to remove this. We have enough bits in
466 cgraph to calculate it. */
467 unsigned tm_clone : 1;
468 /* True if this decl is a dispatcher for function versions. */
469 unsigned dispatcher_function : 1;
470 /* True if this decl calls a COMDAT-local function. This is set up in
471 compute_inline_parameters and inline_call. */
472 unsigned calls_comdat_local : 1;
476 typedef struct cgraph_node *cgraph_node_ptr;
479 /* Function Multiversioning info. */
480 struct GTY(()) cgraph_function_version_info {
481 /* The cgraph_node for which the function version info is stored. */
482 struct cgraph_node *this_node;
483 /* Chains all the semantically identical function versions. The
484 first function in this chain is the version_info node of the
485 default function. */
486 struct cgraph_function_version_info *prev;
487 /* If this version node corresponds to a dispatcher for function
488 versions, this points to the version info node of the default
489 function, the first node in the chain. */
490 struct cgraph_function_version_info *next;
491 /* If this node corresponds to a function version, this points
492 to the dispatcher function decl, which is the function that must
493 be called to execute the right function version at run-time.
495 If this cgraph node is a dispatcher (if dispatcher_function is
496 true, in the cgraph_node struct) for function versions, this
497 points to resolver function, which holds the function body of the
498 dispatcher. The dispatcher decl is an alias to the resolver
499 function decl. */
500 tree dispatcher_resolver;
503 /* Get the cgraph_function_version_info node corresponding to node. */
504 struct cgraph_function_version_info *
505 get_cgraph_node_version (struct cgraph_node *node);
507 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
508 corresponding to cgraph_node NODE. */
509 struct cgraph_function_version_info *
510 insert_new_cgraph_node_version (struct cgraph_node *node);
512 /* Record that DECL1 and DECL2 are semantically identical function
513 versions. */
514 void record_function_versions (tree decl1, tree decl2);
516 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
517 DECL is a duplicate declaration. */
518 void delete_function_version (tree decl);
520 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
521 can appear in multiple sets. */
522 struct cgraph_node_set_def
524 struct pointer_map_t *map;
525 vec<cgraph_node_ptr> nodes;
528 class varpool_node;
529 typedef varpool_node *varpool_node_ptr;
532 /* A varpool node set is a collection of varpool nodes. A varpool node
533 can appear in multiple sets. */
534 struct varpool_node_set_def
536 struct pointer_map_t * map;
537 vec<varpool_node_ptr> nodes;
540 typedef struct cgraph_node_set_def *cgraph_node_set;
543 typedef struct varpool_node_set_def *varpool_node_set;
546 /* Iterator structure for cgraph node sets. */
547 struct cgraph_node_set_iterator
549 cgraph_node_set set;
550 unsigned index;
553 /* Iterator structure for varpool node sets. */
554 struct varpool_node_set_iterator
556 varpool_node_set set;
557 unsigned index;
560 #define DEFCIFCODE(code, type, string) CIF_ ## code,
561 /* Reasons for inlining failures. */
562 enum cgraph_inline_failed_t {
563 #include "cif-code.def"
564 CIF_N_REASONS
567 enum cgraph_inline_failed_type_t
569 CIF_FINAL_NORMAL = 0,
570 CIF_FINAL_ERROR
573 /* Structure containing additional information about an indirect call. */
575 struct GTY(()) cgraph_indirect_call_info
577 /* When polymorphic is set, this field contains offset where the object which
578 was actually used in the polymorphic resides within a larger structure.
579 If agg_contents is set, the field contains the offset within the aggregate
580 from which the address to call was loaded. */
581 HOST_WIDE_INT offset;
582 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
583 HOST_WIDE_INT otr_token;
584 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
585 tree otr_type, outer_type;
586 /* Index of the parameter that is called. */
587 int param_index;
588 /* ECF flags determined from the caller. */
589 int ecf_flags;
590 /* Profile_id of common target obtrained from profile. */
591 int common_target_id;
592 /* Probability that call will land in function with COMMON_TARGET_ID. */
593 int common_target_probability;
595 /* Set when the call is a virtual call with the parameter being the
596 associated object pointer rather than a simple direct call. */
597 unsigned polymorphic : 1;
598 /* Set when the call is a call of a pointer loaded from contents of an
599 aggregate at offset. */
600 unsigned agg_contents : 1;
601 /* Set when this is a call through a member pointer. */
602 unsigned member_ptr : 1;
603 /* When the previous bit is set, this one determines whether the destination
604 is loaded from a parameter passed by reference. */
605 unsigned by_ref : 1;
606 unsigned int maybe_in_construction : 1;
607 unsigned int maybe_derived_type : 1;
610 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
611 /* Expected number of executions: calculated in profile.c. */
612 gcov_type count;
613 struct cgraph_node *caller;
614 struct cgraph_node *callee;
615 struct cgraph_edge *prev_caller;
616 struct cgraph_edge *next_caller;
617 struct cgraph_edge *prev_callee;
618 struct cgraph_edge *next_callee;
619 gimple call_stmt;
620 /* Additional information about an indirect call. Not cleared when an edge
621 becomes direct. */
622 struct cgraph_indirect_call_info *indirect_info;
623 PTR GTY ((skip (""))) aux;
624 /* When equal to CIF_OK, inline this call. Otherwise, points to the
625 explanation why function was not inlined. */
626 enum cgraph_inline_failed_t inline_failed;
627 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
628 when the function is serialized in. */
629 unsigned int lto_stmt_uid;
630 /* Expected frequency of executions within the function.
631 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
632 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
633 int frequency;
634 /* Unique id of the edge. */
635 int uid;
636 /* Liveness pressure at the call site */
637 unsigned int caller_liveness_pressure;
638 /* Whether this edge was made direct by indirect inlining. */
639 unsigned int indirect_inlining_edge : 1;
640 /* Whether this edge describes an indirect call with an undetermined
641 callee. */
642 unsigned int indirect_unknown_callee : 1;
643 /* Whether this edge is still a dangling */
644 /* True if the corresponding CALL stmt cannot be inlined. */
645 unsigned int call_stmt_cannot_inline_p : 1;
646 /* Can this call throw externally? */
647 unsigned int can_throw_external : 1;
648 /* Edges with SPECULATIVE flag represents indirect calls that was
649 speculatively turned into direct (i.e. by profile feedback).
650 The final code sequence will have form:
652 if (call_target == expected_fn)
653 expected_fn ();
654 else
655 call_target ();
657 Every speculative call is represented by three components attached
658 to a same call statement:
659 1) a direct call (to expected_fn)
660 2) an indirect call (to call_target)
661 3) a IPA_REF_ADDR refrence to expected_fn.
663 Optimizers may later redirect direct call to clone, so 1) and 3)
664 do not need to necesarily agree with destination. */
665 unsigned int speculative : 1;
668 #define CGRAPH_FREQ_BASE 1000
669 #define CGRAPH_FREQ_MAX 100000
671 typedef struct cgraph_edge *cgraph_edge_p;
674 /* The varpool data structure.
675 Each static variable decl has assigned varpool_node. */
677 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
678 public:
679 /* Set when variable is scheduled to be assembled. */
680 unsigned output : 1;
682 /* Set if the variable is dynamically initialized, except for
683 function local statics. */
684 unsigned dynamically_initialized : 1;
687 /* Every top level asm statement is put into a asm_node. */
689 struct GTY(()) asm_node {
690 /* Next asm node. */
691 struct asm_node *next;
692 /* String for this asm node. */
693 tree asm_str;
694 /* Ordering of all cgraph nodes. */
695 int order;
698 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
700 template <>
701 template <>
702 inline bool
703 is_a_helper <cgraph_node *>::test (symtab_node *p)
705 return p->type == SYMTAB_FUNCTION;
708 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
710 template <>
711 template <>
712 inline bool
713 is_a_helper <varpool_node *>::test (symtab_node *p)
715 return p->type == SYMTAB_VARIABLE;
718 extern GTY(()) symtab_node *symtab_nodes;
719 extern GTY(()) int cgraph_n_nodes;
720 extern GTY(()) int cgraph_max_uid;
721 extern GTY(()) int cgraph_edge_max_uid;
722 extern bool cgraph_global_info_ready;
723 enum cgraph_state
725 /* Frontend is parsing and finalizing functions. */
726 CGRAPH_STATE_PARSING,
727 /* Callgraph is being constructed. It is safe to add new functions. */
728 CGRAPH_STATE_CONSTRUCTION,
729 /* Callgraph is being at LTO time. */
730 CGRAPH_LTO_STREAMING,
731 /* Callgraph is built and IPA passes are being run. */
732 CGRAPH_STATE_IPA,
733 /* Callgraph is built and all functions are transformed to SSA form. */
734 CGRAPH_STATE_IPA_SSA,
735 /* Functions are now ordered and being passed to RTL expanders. */
736 CGRAPH_STATE_EXPANSION,
737 /* All cgraph expansion is done. */
738 CGRAPH_STATE_FINISHED
740 extern enum cgraph_state cgraph_state;
741 extern bool cgraph_function_flags_ready;
742 extern cgraph_node_set cgraph_new_nodes;
744 extern GTY(()) struct asm_node *asm_nodes;
745 extern GTY(()) int symtab_order;
746 extern bool cpp_implicit_aliases_done;
748 /* Classifcation of symbols WRT partitioning. */
749 enum symbol_partitioning_class
751 /* External declarations are ignored by partitioning algorithms and they are
752 added into the boundary later via compute_ltrans_boundary. */
753 SYMBOL_EXTERNAL,
754 /* Partitioned symbols are pur into one of partitions. */
755 SYMBOL_PARTITION,
756 /* Duplicated symbols (such as comdat or constant pool references) are
757 copied into every node needing them via add_symbol_to_partition. */
758 SYMBOL_DUPLICATE
762 /* In symtab.c */
763 void symtab_register_node (symtab_node *);
764 void symtab_unregister_node (symtab_node *);
765 void symtab_remove_from_same_comdat_group (symtab_node *);
766 void symtab_remove_node (symtab_node *);
767 symtab_node *symtab_node_for_asm (const_tree asmname);
768 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
769 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
770 void dump_symtab (FILE *);
771 void debug_symtab (void);
772 void dump_symtab_node (FILE *, symtab_node *);
773 void debug_symtab_node (symtab_node *);
774 void dump_symtab_base (FILE *, symtab_node *);
775 void verify_symtab (void);
776 void verify_symtab_node (symtab_node *);
777 bool verify_symtab_base (symtab_node *);
778 bool symtab_used_from_object_file_p (symtab_node *);
779 void symtab_make_decl_local (tree);
780 symtab_node *symtab_alias_ultimate_target (symtab_node *,
781 enum availability *avail = NULL);
782 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
783 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
784 bool symtab_for_node_and_aliases (symtab_node *,
785 bool (*) (symtab_node *, void *),
786 void *,
787 bool);
788 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
789 enum availability symtab_node_availability (symtab_node *);
790 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
791 enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
793 /* In cgraph.c */
794 void dump_cgraph (FILE *);
795 void debug_cgraph (void);
796 void dump_cgraph_node (FILE *, struct cgraph_node *);
797 void debug_cgraph_node (struct cgraph_node *);
798 void cgraph_remove_edge (struct cgraph_edge *);
799 void cgraph_remove_node (struct cgraph_node *);
800 void cgraph_release_function_body (struct cgraph_node *);
801 void release_function_body (tree);
802 void cgraph_node_remove_callees (struct cgraph_node *node);
803 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
804 struct cgraph_node *,
805 gimple, gcov_type, int);
806 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
807 int, gcov_type, int);
808 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
809 struct cgraph_node * cgraph_create_node (tree);
810 struct cgraph_node * cgraph_create_empty_node (void);
811 struct cgraph_node * cgraph_get_create_node (tree);
812 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
813 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
814 HOST_WIDE_INT, tree, tree);
815 struct cgraph_node *cgraph_node_for_asm (tree);
816 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
817 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
818 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
819 struct cgraph_local_info *cgraph_local_info (tree);
820 struct cgraph_global_info *cgraph_global_info (tree);
821 struct cgraph_rtl_info *cgraph_rtl_info (tree);
822 struct cgraph_node *cgraph_create_function_alias (tree, tree);
823 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
824 struct cgraph_node *);
825 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
826 struct cgraph_edge *);
828 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
829 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
830 bool cgraph_only_called_directly_p (struct cgraph_node *);
832 bool cgraph_function_possibly_inlined_p (tree);
833 void cgraph_unnest_node (struct cgraph_node *);
835 enum availability cgraph_function_body_availability (struct cgraph_node *);
836 void cgraph_add_new_function (tree, bool);
837 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
838 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
840 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
841 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
842 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
843 bool cgraph_node_cannot_return (struct cgraph_node *);
844 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
845 bool cgraph_will_be_removed_from_program_if_no_direct_calls
846 (struct cgraph_node *node);
847 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
848 (struct cgraph_node *node);
849 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
850 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
851 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
852 bool (*) (struct cgraph_node *, void *),
853 void *,
854 bool);
855 bool cgraph_for_node_and_aliases (struct cgraph_node *,
856 bool (*) (struct cgraph_node *, void *),
857 void *, bool);
858 vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
859 void verify_cgraph (void);
860 void verify_cgraph_node (struct cgraph_node *);
861 void cgraph_mark_address_taken_node (struct cgraph_node *);
863 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
864 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
865 typedef void (*varpool_node_hook)(varpool_node *, void *);
866 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
867 void *);
868 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
869 void *);
870 struct cgraph_edge_hook_list;
871 struct cgraph_node_hook_list;
872 struct varpool_node_hook_list;
873 struct cgraph_2edge_hook_list;
874 struct cgraph_2node_hook_list;
875 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
876 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
877 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
878 void *);
879 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
880 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
881 void *);
882 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
883 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
884 void *);
885 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
886 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
887 void *);
888 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
889 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
890 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
891 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
892 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
893 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
894 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
895 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
896 enum availability *avail = NULL);
897 bool cgraph_get_body (struct cgraph_node *node);
898 struct cgraph_edge *
899 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
900 struct cgraph_node *,
901 gcov_type, int);
902 void cgraph_speculative_call_info (struct cgraph_edge *,
903 struct cgraph_edge *&,
904 struct cgraph_edge *&,
905 struct ipa_ref *&);
906 extern bool gimple_check_call_matching_types (gimple, tree, bool);
908 /* In cgraphunit.c */
909 struct asm_node *add_asm_node (tree);
910 extern FILE *cgraph_dump_file;
911 void cgraph_finalize_function (tree, bool);
912 void finalize_compilation_unit (void);
913 void compile (void);
914 void init_cgraph (void);
915 void cgraph_process_new_functions (void);
916 void cgraph_process_same_body_aliases (void);
917 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
918 /* Initialize datastructures so DECL is a function in lowered gimple form.
919 IN_SSA is true if the gimple is in SSA. */
920 basic_block init_lowered_empty_function (tree, bool);
921 void cgraph_reset_node (struct cgraph_node *);
922 bool expand_thunk (struct cgraph_node *, bool);
924 /* In cgraphclones.c */
926 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
927 struct cgraph_node *, gimple,
928 unsigned, gcov_type, int, bool);
929 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
930 int, bool, vec<cgraph_edge_p>,
931 bool, struct cgraph_node *, bitmap);
932 tree clone_function_name (tree decl, const char *);
933 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
934 vec<cgraph_edge_p>,
935 vec<ipa_replace_map_p, va_gc> *tree_map,
936 bitmap args_to_skip,
937 const char *clone_name);
938 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
939 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
940 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
941 bool update_speculative = true);
942 void cgraph_create_edge_including_clones (struct cgraph_node *,
943 struct cgraph_node *,
944 gimple, gimple, gcov_type, int,
945 cgraph_inline_failed_t);
946 void cgraph_materialize_all_clones (void);
947 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
948 tree, vec<cgraph_edge_p>, bitmap);
949 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
950 vec<cgraph_edge_p>,
951 vec<ipa_replace_map_p, va_gc> *,
952 bitmap, bool, bitmap,
953 basic_block, const char *);
954 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
955 bool, bitmap, bool, bitmap, basic_block);
956 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
958 /* In cgraphbuild.c */
959 unsigned int rebuild_cgraph_edges (void);
960 void cgraph_rebuild_references (void);
961 int compute_call_stmt_bb_frequency (tree, basic_block bb);
962 void record_references_in_initializer (tree, bool);
963 void ipa_record_stmt_references (struct cgraph_node *, gimple);
965 /* In ipa.c */
966 bool symtab_remove_unreachable_nodes (bool, FILE *);
967 cgraph_node_set cgraph_node_set_new (void);
968 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
969 struct cgraph_node *);
970 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
971 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
972 void dump_cgraph_node_set (FILE *, cgraph_node_set);
973 void debug_cgraph_node_set (cgraph_node_set);
974 void free_cgraph_node_set (cgraph_node_set);
975 void cgraph_build_static_cdtor (char which, tree body, int priority);
977 varpool_node_set varpool_node_set_new (void);
978 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
979 varpool_node *);
980 void varpool_node_set_add (varpool_node_set, varpool_node *);
981 void varpool_node_set_remove (varpool_node_set, varpool_node *);
982 void dump_varpool_node_set (FILE *, varpool_node_set);
983 void debug_varpool_node_set (varpool_node_set);
984 void free_varpool_node_set (varpool_node_set);
985 void ipa_discover_readonly_nonaddressable_vars (void);
986 bool varpool_externally_visible_p (varpool_node *);
988 /* In ipa-visibility.c */
989 bool cgraph_local_node_p (struct cgraph_node *);
992 /* In predict.c */
993 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
994 bool cgraph_optimize_for_size_p (struct cgraph_node *);
996 /* In varpool.c */
997 varpool_node *varpool_create_empty_node (void);
998 varpool_node *varpool_node_for_decl (tree);
999 varpool_node *varpool_node_for_asm (tree asmname);
1000 void varpool_mark_needed_node (varpool_node *);
1001 void debug_varpool (void);
1002 void dump_varpool (FILE *);
1003 void dump_varpool_node (FILE *, varpool_node *);
1005 void varpool_finalize_decl (tree);
1006 enum availability cgraph_variable_initializer_availability (varpool_node *);
1007 void cgraph_make_node_local (struct cgraph_node *);
1008 bool cgraph_node_can_be_local_p (struct cgraph_node *);
1011 void varpool_remove_node (varpool_node *node);
1012 void varpool_finalize_named_section_flags (varpool_node *node);
1013 bool varpool_output_variables (void);
1014 bool varpool_assemble_decl (varpool_node *node);
1015 void varpool_analyze_node (varpool_node *);
1016 varpool_node * varpool_extra_name_alias (tree, tree);
1017 varpool_node * varpool_create_variable_alias (tree, tree);
1018 void varpool_reset_queue (void);
1019 tree ctor_for_folding (tree);
1020 bool varpool_for_node_and_aliases (varpool_node *,
1021 bool (*) (varpool_node *, void *),
1022 void *, bool);
1023 void varpool_add_new_variable (tree);
1024 void symtab_initialize_asm_name_hash (void);
1025 void symtab_prevail_in_asm_name_hash (symtab_node *node);
1026 void varpool_remove_initializer (varpool_node *);
1028 /* In cgraph.c */
1029 extern void change_decl_assembler_name (tree, tree);
1031 /* Return symbol table node associated with DECL, if any,
1032 and NULL otherwise. */
1034 static inline symtab_node *
1035 symtab_get_node (const_tree decl)
1037 #ifdef ENABLE_CHECKING
1038 /* Check that we are called for sane type of object - functions
1039 and static or external variables. */
1040 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
1041 || (TREE_CODE (decl) == VAR_DECL
1042 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1043 || in_lto_p)));
1044 /* Check that the mapping is sane - perhaps this check can go away,
1045 but at the moment frontends tends to corrupt the mapping by calling
1046 memcpy/memset on the tree nodes. */
1047 gcc_checking_assert (!decl->decl_with_vis.symtab_node
1048 || decl->decl_with_vis.symtab_node->decl == decl);
1049 #endif
1050 return decl->decl_with_vis.symtab_node;
1053 /* Return callgraph node for given symbol and check it is a function. */
1054 static inline struct cgraph_node *
1055 cgraph (symtab_node *node)
1057 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
1058 return (struct cgraph_node *)node;
1061 /* Return varpool node for given symbol and check it is a variable. */
1062 static inline varpool_node *
1063 varpool (symtab_node *node)
1065 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
1066 return (varpool_node *)node;
1069 /* Return callgraph node for given symbol and check it is a function. */
1070 static inline struct cgraph_node *
1071 cgraph_get_node (const_tree decl)
1073 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1074 return cgraph (symtab_get_node (decl));
1077 /* Return varpool node for given symbol and check it is a function. */
1078 static inline varpool_node *
1079 varpool_get_node (const_tree decl)
1081 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1082 return varpool (symtab_get_node (decl));
1085 /* Walk all symbols. */
1086 #define FOR_EACH_SYMBOL(node) \
1087 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1089 /* Return first static symbol with definition. */
1090 static inline symtab_node *
1091 symtab_first_defined_symbol (void)
1093 symtab_node *node;
1095 for (node = symtab_nodes; node; node = node->next)
1096 if (node->definition)
1097 return node;
1099 return NULL;
1102 /* Return next reachable static symbol with initializer after NODE. */
1103 static inline symtab_node *
1104 symtab_next_defined_symbol (symtab_node *node)
1106 symtab_node *node1 = node->next;
1108 for (; node1; node1 = node1->next)
1109 if (node1->definition)
1110 return node1;
1112 return NULL;
1114 /* Walk all symbols with definitions in current unit. */
1115 #define FOR_EACH_DEFINED_SYMBOL(node) \
1116 for ((node) = symtab_first_defined_symbol (); (node); \
1117 (node) = symtab_next_defined_symbol (node))
1119 /* Return first variable. */
1120 static inline varpool_node *
1121 varpool_first_variable (void)
1123 symtab_node *node;
1124 for (node = symtab_nodes; node; node = node->next)
1125 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1126 return vnode;
1127 return NULL;
1130 /* Return next variable after NODE. */
1131 static inline varpool_node *
1132 varpool_next_variable (varpool_node *node)
1134 symtab_node *node1 = node->next;
1135 for (; node1; node1 = node1->next)
1136 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1137 return vnode1;
1138 return NULL;
1140 /* Walk all variables. */
1141 #define FOR_EACH_VARIABLE(node) \
1142 for ((node) = varpool_first_variable (); \
1143 (node); \
1144 (node) = varpool_next_variable ((node)))
1146 /* Return first static variable with initializer. */
1147 static inline varpool_node *
1148 varpool_first_static_initializer (void)
1150 symtab_node *node;
1151 for (node = symtab_nodes; node; node = node->next)
1153 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1154 if (vnode && DECL_INITIAL (node->decl))
1155 return vnode;
1157 return NULL;
1160 /* Return next static variable with initializer after NODE. */
1161 static inline varpool_node *
1162 varpool_next_static_initializer (varpool_node *node)
1164 symtab_node *node1 = node->next;
1165 for (; node1; node1 = node1->next)
1167 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1168 if (vnode1 && DECL_INITIAL (node1->decl))
1169 return vnode1;
1171 return NULL;
1174 /* Walk all static variables with initializer set. */
1175 #define FOR_EACH_STATIC_INITIALIZER(node) \
1176 for ((node) = varpool_first_static_initializer (); (node); \
1177 (node) = varpool_next_static_initializer (node))
1179 /* Return first static variable with definition. */
1180 static inline varpool_node *
1181 varpool_first_defined_variable (void)
1183 symtab_node *node;
1184 for (node = symtab_nodes; node; node = node->next)
1186 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1187 if (vnode && vnode->definition)
1188 return vnode;
1190 return NULL;
1193 /* Return next static variable with definition after NODE. */
1194 static inline varpool_node *
1195 varpool_next_defined_variable (varpool_node *node)
1197 symtab_node *node1 = node->next;
1198 for (; node1; node1 = node1->next)
1200 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1201 if (vnode1 && vnode1->definition)
1202 return vnode1;
1204 return NULL;
1206 /* Walk all variables with definitions in current unit. */
1207 #define FOR_EACH_DEFINED_VARIABLE(node) \
1208 for ((node) = varpool_first_defined_variable (); (node); \
1209 (node) = varpool_next_defined_variable (node))
1211 /* Return first function with body defined. */
1212 static inline struct cgraph_node *
1213 cgraph_first_defined_function (void)
1215 symtab_node *node;
1216 for (node = symtab_nodes; node; node = node->next)
1218 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1219 if (cn && cn->definition)
1220 return cn;
1222 return NULL;
1225 /* Return next function with body defined after NODE. */
1226 static inline struct cgraph_node *
1227 cgraph_next_defined_function (struct cgraph_node *node)
1229 symtab_node *node1 = node->next;
1230 for (; node1; node1 = node1->next)
1232 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1233 if (cn1 && cn1->definition)
1234 return cn1;
1236 return NULL;
1239 /* Walk all functions with body defined. */
1240 #define FOR_EACH_DEFINED_FUNCTION(node) \
1241 for ((node) = cgraph_first_defined_function (); (node); \
1242 (node) = cgraph_next_defined_function ((node)))
1244 /* Return first function. */
1245 static inline struct cgraph_node *
1246 cgraph_first_function (void)
1248 symtab_node *node;
1249 for (node = symtab_nodes; node; node = node->next)
1250 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1251 return cn;
1252 return NULL;
1255 /* Return next function. */
1256 static inline struct cgraph_node *
1257 cgraph_next_function (struct cgraph_node *node)
1259 symtab_node *node1 = node->next;
1260 for (; node1; node1 = node1->next)
1261 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1262 return cn1;
1263 return NULL;
1265 /* Walk all functions. */
1266 #define FOR_EACH_FUNCTION(node) \
1267 for ((node) = cgraph_first_function (); (node); \
1268 (node) = cgraph_next_function ((node)))
1270 /* Return true when NODE is a function with Gimple body defined
1271 in current unit. Functions can also be define externally or they
1272 can be thunks with no Gimple representation.
1274 Note that at WPA stage, the function body may not be present in memory. */
1276 static inline bool
1277 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1279 return node->definition && !node->thunk.thunk_p && !node->alias;
1282 /* Return first function with body defined. */
1283 static inline struct cgraph_node *
1284 cgraph_first_function_with_gimple_body (void)
1286 symtab_node *node;
1287 for (node = symtab_nodes; node; node = node->next)
1289 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1290 if (cn && cgraph_function_with_gimple_body_p (cn))
1291 return cn;
1293 return NULL;
1296 /* Return next reachable static variable with initializer after NODE. */
1297 static inline struct cgraph_node *
1298 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1300 symtab_node *node1 = node->next;
1301 for (; node1; node1 = node1->next)
1303 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1304 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1305 return cn1;
1307 return NULL;
1310 /* Walk all functions with body defined. */
1311 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1312 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1313 (node) = cgraph_next_function_with_gimple_body (node))
1315 /* Create a new static variable of type TYPE. */
1316 tree add_new_static_var (tree type);
1318 /* Return true if iterator CSI points to nothing. */
1319 static inline bool
1320 csi_end_p (cgraph_node_set_iterator csi)
1322 return csi.index >= csi.set->nodes.length ();
1325 /* Advance iterator CSI. */
1326 static inline void
1327 csi_next (cgraph_node_set_iterator *csi)
1329 csi->index++;
1332 /* Return the node pointed to by CSI. */
1333 static inline struct cgraph_node *
1334 csi_node (cgraph_node_set_iterator csi)
1336 return csi.set->nodes[csi.index];
1339 /* Return an iterator to the first node in SET. */
1340 static inline cgraph_node_set_iterator
1341 csi_start (cgraph_node_set set)
1343 cgraph_node_set_iterator csi;
1345 csi.set = set;
1346 csi.index = 0;
1347 return csi;
1350 /* Return true if SET contains NODE. */
1351 static inline bool
1352 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1354 cgraph_node_set_iterator csi;
1355 csi = cgraph_node_set_find (set, node);
1356 return !csi_end_p (csi);
1359 /* Return number of nodes in SET. */
1360 static inline size_t
1361 cgraph_node_set_size (cgraph_node_set set)
1363 return set->nodes.length ();
1366 /* Return true if iterator VSI points to nothing. */
1367 static inline bool
1368 vsi_end_p (varpool_node_set_iterator vsi)
1370 return vsi.index >= vsi.set->nodes.length ();
1373 /* Advance iterator VSI. */
1374 static inline void
1375 vsi_next (varpool_node_set_iterator *vsi)
1377 vsi->index++;
1380 /* Return the node pointed to by VSI. */
1381 static inline varpool_node *
1382 vsi_node (varpool_node_set_iterator vsi)
1384 return vsi.set->nodes[vsi.index];
1387 /* Return an iterator to the first node in SET. */
1388 static inline varpool_node_set_iterator
1389 vsi_start (varpool_node_set set)
1391 varpool_node_set_iterator vsi;
1393 vsi.set = set;
1394 vsi.index = 0;
1395 return vsi;
1398 /* Return true if SET contains NODE. */
1399 static inline bool
1400 varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
1402 varpool_node_set_iterator vsi;
1403 vsi = varpool_node_set_find (set, node);
1404 return !vsi_end_p (vsi);
1407 /* Return number of nodes in SET. */
1408 static inline size_t
1409 varpool_node_set_size (varpool_node_set set)
1411 return set->nodes.length ();
1414 /* Uniquize all constants that appear in memory.
1415 Each constant in memory thus far output is recorded
1416 in `const_desc_table'. */
1418 struct GTY(()) constant_descriptor_tree {
1419 /* A MEM for the constant. */
1420 rtx rtl;
1422 /* The value of the constant. */
1423 tree value;
1425 /* Hash of value. Computing the hash from value each time
1426 hashfn is called can't work properly, as that means recursive
1427 use of the hash table during hash table expansion. */
1428 hashval_t hash;
1431 /* Return true if set is nonempty. */
1432 static inline bool
1433 cgraph_node_set_nonempty_p (cgraph_node_set set)
1435 return !set->nodes.is_empty ();
1438 /* Return true if set is nonempty. */
1439 static inline bool
1440 varpool_node_set_nonempty_p (varpool_node_set set)
1442 return !set->nodes.is_empty ();
1445 /* Return true when function NODE is only called directly or it has alias.
1446 i.e. it is not externally visible, address was not taken and
1447 it is not used in any other non-standard way. */
1449 static inline bool
1450 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1452 gcc_assert (!node->global.inlined_to);
1453 return (!node->force_output && !node->address_taken
1454 && !node->used_from_other_partition
1455 && !DECL_VIRTUAL_P (node->decl)
1456 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1457 && !DECL_STATIC_DESTRUCTOR (node->decl)
1458 && !node->externally_visible);
1461 /* Return true when function NODE can be removed from callgraph
1462 if all direct calls are eliminated. */
1464 static inline bool
1465 varpool_can_remove_if_no_refs (varpool_node *node)
1467 if (DECL_EXTERNAL (node->decl))
1468 return true;
1469 return (!node->force_output && !node->used_from_other_partition
1470 && ((DECL_COMDAT (node->decl)
1471 && !node->forced_by_abi
1472 && !symtab_used_from_object_file_p (node))
1473 || !node->externally_visible
1474 || DECL_HAS_VALUE_EXPR_P (node->decl)));
1477 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1478 i.e. if the variable is not externally visible or not used in some magic
1479 way (asm statement or such).
1480 The magic uses are all summarized in force_output flag. */
1482 static inline bool
1483 varpool_all_refs_explicit_p (varpool_node *vnode)
1485 return (vnode->definition
1486 && !vnode->externally_visible
1487 && !vnode->used_from_other_partition
1488 && !vnode->force_output);
1491 /* Constant pool accessor function. */
1492 htab_t constant_pool_htab (void);
1494 /* FIXME: inappropriate dependency of cgraph on IPA. */
1495 #include "ipa-ref-inline.h"
1497 /* Return node that alias N is aliasing. */
1499 static inline symtab_node *
1500 symtab_alias_target (symtab_node *n)
1502 struct ipa_ref *ref;
1503 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1504 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1505 return ref->referred;
1508 static inline struct cgraph_node *
1509 cgraph_alias_target (struct cgraph_node *n)
1511 return dyn_cast <cgraph_node *> (symtab_alias_target (n));
1514 static inline varpool_node *
1515 varpool_alias_target (varpool_node *n)
1517 return dyn_cast <varpool_node *> (symtab_alias_target (n));
1520 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1521 Do not walk through thunks.
1522 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1524 static inline struct cgraph_node *
1525 cgraph_function_or_thunk_node (struct cgraph_node *node,
1526 enum availability *availability = NULL)
1528 struct cgraph_node *n;
1530 n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node,
1531 availability));
1532 if (!n && availability)
1533 *availability = AVAIL_NOT_AVAILABLE;
1534 return n;
1536 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1537 Do not walk through thunks.
1538 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1540 static inline varpool_node *
1541 varpool_variable_node (varpool_node *node,
1542 enum availability *availability = NULL)
1544 varpool_node *n;
1546 if (node)
1547 n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node,
1548 availability));
1549 else
1550 n = NULL;
1552 if (!n && availability)
1553 *availability = AVAIL_NOT_AVAILABLE;
1554 return n;
1557 /* Return true when the edge E represents a direct recursion. */
1558 static inline bool
1559 cgraph_edge_recursive_p (struct cgraph_edge *e)
1561 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1562 if (e->caller->global.inlined_to)
1563 return e->caller->global.inlined_to->decl == callee->decl;
1564 else
1565 return e->caller->decl == callee->decl;
1568 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1569 static inline bool
1570 decl_is_tm_clone (const_tree fndecl)
1572 struct cgraph_node *n = cgraph_get_node (fndecl);
1573 if (n)
1574 return n->tm_clone;
1575 return false;
1578 /* Likewise indicate that a node is needed, i.e. reachable via some
1579 external means. */
1581 static inline void
1582 cgraph_mark_force_output_node (struct cgraph_node *node)
1584 node->force_output = 1;
1585 gcc_checking_assert (!node->global.inlined_to);
1588 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1589 or abstract function kept for debug info purposes only. */
1591 static inline bool
1592 symtab_real_symbol_p (symtab_node *node)
1594 struct cgraph_node *cnode;
1596 if (DECL_ABSTRACT (node->decl))
1597 return false;
1598 if (!is_a <cgraph_node *> (node))
1599 return true;
1600 cnode = cgraph (node);
1601 if (cnode->global.inlined_to)
1602 return false;
1603 return true;
1606 /* Return true if NODE can be discarded by linker from the binary. */
1608 static inline bool
1609 symtab_can_be_discarded (symtab_node *node)
1611 return (DECL_EXTERNAL (node->decl)
1612 || (node->get_comdat_group ()
1613 && node->resolution != LDPR_PREVAILING_DEF
1614 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1615 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1618 /* Return true if NODE is local to a particular COMDAT group, and must not
1619 be named from outside the COMDAT. This is used for C++ decloned
1620 constructors. */
1622 static inline bool
1623 symtab_comdat_local_p (symtab_node *node)
1625 return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1628 /* Return true if ONE and TWO are part of the same COMDAT group. */
1630 static inline bool
1631 symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1633 if (cgraph_node *cn = dyn_cast <cgraph_node *> (one))
1635 if (cn->global.inlined_to)
1636 one = cn->global.inlined_to;
1638 if (cgraph_node *cn = dyn_cast <cgraph_node *> (two))
1640 if (cn->global.inlined_to)
1641 two = cn->global.inlined_to;
1644 return one->get_comdat_group () == two->get_comdat_group ();
1646 #endif /* GCC_CGRAPH_H */