2014-04-15 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / cgraph.h
blob15310d8886100833342c998ccb53fa388fe6b971
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;
81 /*** Visibility and linkage flags. ***/
83 /* Set when function is visible by other units. */
84 unsigned externally_visible : 1;
85 /* The symbol will be assumed to be used in an invisible way (like
86 by an toplevel asm statement). */
87 unsigned force_output : 1;
88 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
89 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
90 to static and it does not inhibit optimization. */
91 unsigned forced_by_abi : 1;
92 /* True when the name is known to be unique and thus it does not need mangling. */
93 unsigned unique_name : 1;
94 /* True when body and other characteristics have been removed by
95 symtab_remove_unreachable_nodes. */
96 unsigned body_removed : 1;
98 /*** WHOPR Partitioning flags.
99 These flags are used at ltrans stage when only part of the callgraph is
100 available. ***/
102 /* Set when variable is used from other LTRANS partition. */
103 unsigned used_from_other_partition : 1;
104 /* Set when function is available in the other LTRANS partition.
105 During WPA output it is used to mark nodes that are present in
106 multiple partitions. */
107 unsigned in_other_partition : 1;
111 /*** other flags. ***/
113 /* Set when symbol has address taken. */
114 unsigned address_taken : 1;
117 /* Ordering of all symtab entries. */
118 int order;
120 /* Declaration representing the symbol. */
121 tree decl;
123 /* Linked list of symbol table entries starting with symtab_nodes. */
124 symtab_node *next;
125 symtab_node *previous;
127 /* Linked list of symbols with the same asm name. There may be multiple
128 entries for single symbol name during LTO, because symbols are renamed
129 only after partitioning.
131 Because inline clones are kept in the assembler name has, they also produce
132 duplicate entries.
134 There are also several long standing bugs where frontends and builtin
135 code produce duplicated decls. */
136 symtab_node *next_sharing_asm_name;
137 symtab_node *previous_sharing_asm_name;
139 /* Circular list of nodes in the same comdat group if non-NULL. */
140 symtab_node *same_comdat_group;
142 /* Vectors of referring and referenced entities. */
143 struct ipa_ref_list ref_list;
145 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
146 depending to what was known to frontend on the creation time.
147 Once alias is resolved, this pointer become NULL. */
148 tree alias_target;
150 /* File stream where this node is being written to. */
151 struct lto_file_decl_data * lto_file_data;
153 PTR GTY ((skip)) aux;
156 enum availability
158 /* Not yet set by cgraph_function_body_availability. */
159 AVAIL_UNSET,
160 /* Function body/variable initializer is unknown. */
161 AVAIL_NOT_AVAILABLE,
162 /* Function body/variable initializer is known but might be replaced
163 by a different one from other compilation unit and thus needs to
164 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
165 arbitrary side effects on escaping variables and functions, while
166 like AVAILABLE it might access static variables. */
167 AVAIL_OVERWRITABLE,
168 /* Function body/variable initializer is known and will be used in final
169 program. */
170 AVAIL_AVAILABLE,
171 /* Function body/variable initializer is known and all it's uses are explicitly
172 visible within current unit (ie it's address is never taken and it is not
173 exported to other units).
174 Currently used only for functions. */
175 AVAIL_LOCAL
178 /* This is the information that is put into the cgraph local structure
179 to recover a function. */
180 struct lto_file_decl_data;
182 extern const char * const cgraph_availability_names[];
183 extern const char * const ld_plugin_symbol_resolution_names[];
185 /* Information about thunk, used only for same body aliases. */
187 struct GTY(()) cgraph_thunk_info {
188 /* Information about the thunk. */
189 HOST_WIDE_INT fixed_offset;
190 HOST_WIDE_INT virtual_value;
191 tree alias;
192 bool this_adjusting;
193 bool virtual_offset_p;
194 /* Set to true when alias node is thunk. */
195 bool thunk_p;
198 /* Information about the function collected locally.
199 Available after function is analyzed. */
201 struct GTY(()) cgraph_local_info {
202 /* Set when function function is visible in current compilation unit only
203 and its address is never taken. */
204 unsigned local : 1;
206 /* False when there is something makes versioning impossible. */
207 unsigned versionable : 1;
209 /* False when function calling convention and signature can not be changed.
210 This is the case when __builtin_apply_args is used. */
211 unsigned can_change_signature : 1;
213 /* True when the function has been originally extern inline, but it is
214 redefined now. */
215 unsigned redefined_extern_inline : 1;
217 /* True if the function may enter serial irrevocable mode. */
218 unsigned tm_may_enter_irr : 1;
221 /* Information about the function that needs to be computed globally
222 once compilation is finished. Available only with -funit-at-a-time. */
224 struct GTY(()) cgraph_global_info {
225 /* For inline clones this points to the function they will be
226 inlined into. */
227 struct cgraph_node *inlined_to;
230 /* Information about the function that is propagated by the RTL backend.
231 Available only for functions that has been already assembled. */
233 struct GTY(()) cgraph_rtl_info {
234 unsigned int preferred_incoming_stack_boundary;
237 /* Represent which DECL tree (or reference to such tree)
238 will be replaced by another tree while versioning. */
239 struct GTY(()) ipa_replace_map
241 /* The tree that will be replaced. */
242 tree old_tree;
243 /* The new (replacing) tree. */
244 tree new_tree;
245 /* Parameter number to replace, when old_tree is NULL. */
246 int parm_num;
247 /* True when a substitution should be done, false otherwise. */
248 bool replace_p;
249 /* True when we replace a reference to old_tree. */
250 bool ref_p;
252 typedef struct ipa_replace_map *ipa_replace_map_p;
254 struct GTY(()) cgraph_clone_info
256 vec<ipa_replace_map_p, va_gc> *tree_map;
257 bitmap args_to_skip;
258 bitmap combined_args_to_skip;
261 enum cgraph_simd_clone_arg_type
263 SIMD_CLONE_ARG_TYPE_VECTOR,
264 SIMD_CLONE_ARG_TYPE_UNIFORM,
265 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
266 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
267 SIMD_CLONE_ARG_TYPE_MASK
270 /* Function arguments in the original function of a SIMD clone.
271 Supplementary data for `struct simd_clone'. */
273 struct GTY(()) cgraph_simd_clone_arg {
274 /* Original function argument as it originally existed in
275 DECL_ARGUMENTS. */
276 tree orig_arg;
278 /* orig_arg's function (or for extern functions type from
279 TYPE_ARG_TYPES). */
280 tree orig_type;
282 /* If argument is a vector, this holds the vector version of
283 orig_arg that after adjusting the argument types will live in
284 DECL_ARGUMENTS. Otherwise, this is NULL.
286 This basically holds:
287 vector(simdlen) __typeof__(orig_arg) new_arg. */
288 tree vector_arg;
290 /* vector_arg's type (or for extern functions new vector type. */
291 tree vector_type;
293 /* If argument is a vector, this holds the array where the simd
294 argument is held while executing the simd clone function. This
295 is a local variable in the cloned function. Its content is
296 copied from vector_arg upon entry to the clone.
298 This basically holds:
299 __typeof__(orig_arg) simd_array[simdlen]. */
300 tree simd_array;
302 /* A SIMD clone's argument can be either linear (constant or
303 variable), uniform, or vector. */
304 enum cgraph_simd_clone_arg_type arg_type;
306 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
307 the constant linear step, if arg_type is
308 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
309 the uniform argument holding the step, otherwise 0. */
310 HOST_WIDE_INT linear_step;
312 /* Variable alignment if available, otherwise 0. */
313 unsigned int alignment;
316 /* Specific data for a SIMD function clone. */
318 struct GTY(()) cgraph_simd_clone {
319 /* Number of words in the SIMD lane associated with this clone. */
320 unsigned int simdlen;
322 /* Number of annotated function arguments in `args'. This is
323 usually the number of named arguments in FNDECL. */
324 unsigned int nargs;
326 /* Max hardware vector size in bits for integral vectors. */
327 unsigned int vecsize_int;
329 /* Max hardware vector size in bits for floating point vectors. */
330 unsigned int vecsize_float;
332 /* The mangling character for a given vector size. This is is used
333 to determine the ISA mangling bit as specified in the Intel
334 Vector ABI. */
335 unsigned char vecsize_mangle;
337 /* True if this is the masked, in-branch version of the clone,
338 otherwise false. */
339 unsigned int inbranch : 1;
341 /* True if this is a Cilk Plus variant. */
342 unsigned int cilk_elemental : 1;
344 /* Doubly linked list of SIMD clones. */
345 struct cgraph_node *prev_clone, *next_clone;
347 /* Original cgraph node the SIMD clones were created for. */
348 struct cgraph_node *origin;
350 /* Annotated function arguments for the original function. */
351 struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
355 /* The cgraph data structure.
356 Each function decl has assigned cgraph_node listing callees and callers. */
358 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
359 public:
360 struct cgraph_edge *callees;
361 struct cgraph_edge *callers;
362 /* List of edges representing indirect calls with a yet undetermined
363 callee. */
364 struct cgraph_edge *indirect_calls;
365 /* For nested functions points to function the node is nested in. */
366 struct cgraph_node *origin;
367 /* Points to first nested function, if any. */
368 struct cgraph_node *nested;
369 /* Pointer to the next function with same origin, if any. */
370 struct cgraph_node *next_nested;
371 /* Pointer to the next clone. */
372 struct cgraph_node *next_sibling_clone;
373 struct cgraph_node *prev_sibling_clone;
374 struct cgraph_node *clones;
375 struct cgraph_node *clone_of;
376 /* For functions with many calls sites it holds map from call expression
377 to the edge to speed up cgraph_edge function. */
378 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
379 /* Declaration node used to be clone of. */
380 tree former_clone_of;
382 /* If this is a SIMD clone, this points to the SIMD specific
383 information for it. */
384 struct cgraph_simd_clone *simdclone;
385 /* If this function has SIMD clones, this points to the first clone. */
386 struct cgraph_node *simd_clones;
388 /* Interprocedural passes scheduled to have their transform functions
389 applied next time we execute local pass on them. We maintain it
390 per-function in order to allow IPA passes to introduce new functions. */
391 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
393 struct cgraph_local_info local;
394 struct cgraph_global_info global;
395 struct cgraph_rtl_info rtl;
396 struct cgraph_clone_info clone;
397 struct cgraph_thunk_info thunk;
399 /* Expected number of executions: calculated in profile.c. */
400 gcov_type count;
401 /* How to scale counts at materialization time; used to merge
402 LTO units with different number of profile runs. */
403 int count_materialization_scale;
404 /* Unique id of the node. */
405 int uid;
406 /* ID assigned by the profiling. */
407 unsigned int profile_id;
408 /* Time profiler: first run of function. */
409 int tp_first_run;
411 /* Set when decl is an abstract function pointed to by the
412 ABSTRACT_DECL_ORIGIN of a reachable function. */
413 unsigned used_as_abstract_origin : 1;
414 /* Set once the function is lowered (i.e. its CFG is built). */
415 unsigned lowered : 1;
416 /* Set once the function has been instantiated and its callee
417 lists created. */
418 unsigned process : 1;
419 /* How commonly executed the node is. Initialized during branch
420 probabilities pass. */
421 ENUM_BITFIELD (node_frequency) frequency : 2;
422 /* True when function can only be called at startup (from static ctor). */
423 unsigned only_called_at_startup : 1;
424 /* True when function can only be called at startup (from static dtor). */
425 unsigned only_called_at_exit : 1;
426 /* True when function is the transactional clone of a function which
427 is called only from inside transactions. */
428 /* ?? We should be able to remove this. We have enough bits in
429 cgraph to calculate it. */
430 unsigned tm_clone : 1;
431 /* True if this decl is a dispatcher for function versions. */
432 unsigned dispatcher_function : 1;
433 /* True if this decl calls a COMDAT-local function. This is set up in
434 compute_inline_parameters and inline_call. */
435 unsigned calls_comdat_local : 1;
439 typedef struct cgraph_node *cgraph_node_ptr;
442 /* Function Multiversioning info. */
443 struct GTY(()) cgraph_function_version_info {
444 /* The cgraph_node for which the function version info is stored. */
445 struct cgraph_node *this_node;
446 /* Chains all the semantically identical function versions. The
447 first function in this chain is the version_info node of the
448 default function. */
449 struct cgraph_function_version_info *prev;
450 /* If this version node corresponds to a dispatcher for function
451 versions, this points to the version info node of the default
452 function, the first node in the chain. */
453 struct cgraph_function_version_info *next;
454 /* If this node corresponds to a function version, this points
455 to the dispatcher function decl, which is the function that must
456 be called to execute the right function version at run-time.
458 If this cgraph node is a dispatcher (if dispatcher_function is
459 true, in the cgraph_node struct) for function versions, this
460 points to resolver function, which holds the function body of the
461 dispatcher. The dispatcher decl is an alias to the resolver
462 function decl. */
463 tree dispatcher_resolver;
466 /* Get the cgraph_function_version_info node corresponding to node. */
467 struct cgraph_function_version_info *
468 get_cgraph_node_version (struct cgraph_node *node);
470 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
471 corresponding to cgraph_node NODE. */
472 struct cgraph_function_version_info *
473 insert_new_cgraph_node_version (struct cgraph_node *node);
475 /* Record that DECL1 and DECL2 are semantically identical function
476 versions. */
477 void record_function_versions (tree decl1, tree decl2);
479 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
480 DECL is a duplicate declaration. */
481 void delete_function_version (tree decl);
483 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
484 can appear in multiple sets. */
485 struct cgraph_node_set_def
487 struct pointer_map_t *map;
488 vec<cgraph_node_ptr> nodes;
491 class varpool_node;
492 typedef varpool_node *varpool_node_ptr;
495 /* A varpool node set is a collection of varpool nodes. A varpool node
496 can appear in multiple sets. */
497 struct varpool_node_set_def
499 struct pointer_map_t * map;
500 vec<varpool_node_ptr> nodes;
503 typedef struct cgraph_node_set_def *cgraph_node_set;
506 typedef struct varpool_node_set_def *varpool_node_set;
509 /* Iterator structure for cgraph node sets. */
510 struct cgraph_node_set_iterator
512 cgraph_node_set set;
513 unsigned index;
516 /* Iterator structure for varpool node sets. */
517 struct varpool_node_set_iterator
519 varpool_node_set set;
520 unsigned index;
523 #define DEFCIFCODE(code, type, string) CIF_ ## code,
524 /* Reasons for inlining failures. */
525 enum cgraph_inline_failed_t {
526 #include "cif-code.def"
527 CIF_N_REASONS
530 enum cgraph_inline_failed_type_t
532 CIF_FINAL_NORMAL = 0,
533 CIF_FINAL_ERROR
536 /* Structure containing additional information about an indirect call. */
538 struct GTY(()) cgraph_indirect_call_info
540 /* When polymorphic is set, this field contains offset where the object which
541 was actually used in the polymorphic resides within a larger structure.
542 If agg_contents is set, the field contains the offset within the aggregate
543 from which the address to call was loaded. */
544 HOST_WIDE_INT offset;
545 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
546 HOST_WIDE_INT otr_token;
547 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
548 tree otr_type, outer_type;
549 /* Index of the parameter that is called. */
550 int param_index;
551 /* ECF flags determined from the caller. */
552 int ecf_flags;
553 /* Profile_id of common target obtrained from profile. */
554 int common_target_id;
555 /* Probability that call will land in function with COMMON_TARGET_ID. */
556 int common_target_probability;
558 /* Set when the call is a virtual call with the parameter being the
559 associated object pointer rather than a simple direct call. */
560 unsigned polymorphic : 1;
561 /* Set when the call is a call of a pointer loaded from contents of an
562 aggregate at offset. */
563 unsigned agg_contents : 1;
564 /* Set when this is a call through a member pointer. */
565 unsigned member_ptr : 1;
566 /* When the previous bit is set, this one determines whether the destination
567 is loaded from a parameter passed by reference. */
568 unsigned by_ref : 1;
569 unsigned int maybe_in_construction : 1;
570 unsigned int maybe_derived_type : 1;
573 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
574 /* Expected number of executions: calculated in profile.c. */
575 gcov_type count;
576 struct cgraph_node *caller;
577 struct cgraph_node *callee;
578 struct cgraph_edge *prev_caller;
579 struct cgraph_edge *next_caller;
580 struct cgraph_edge *prev_callee;
581 struct cgraph_edge *next_callee;
582 gimple call_stmt;
583 /* Additional information about an indirect call. Not cleared when an edge
584 becomes direct. */
585 struct cgraph_indirect_call_info *indirect_info;
586 PTR GTY ((skip (""))) aux;
587 /* When equal to CIF_OK, inline this call. Otherwise, points to the
588 explanation why function was not inlined. */
589 enum cgraph_inline_failed_t inline_failed;
590 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
591 when the function is serialized in. */
592 unsigned int lto_stmt_uid;
593 /* Expected frequency of executions within the function.
594 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
595 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
596 int frequency;
597 /* Unique id of the edge. */
598 int uid;
599 /* Whether this edge was made direct by indirect inlining. */
600 unsigned int indirect_inlining_edge : 1;
601 /* Whether this edge describes an indirect call with an undetermined
602 callee. */
603 unsigned int indirect_unknown_callee : 1;
604 /* Whether this edge is still a dangling */
605 /* True if the corresponding CALL stmt cannot be inlined. */
606 unsigned int call_stmt_cannot_inline_p : 1;
607 /* Can this call throw externally? */
608 unsigned int can_throw_external : 1;
609 /* Edges with SPECULATIVE flag represents indirect calls that was
610 speculatively turned into direct (i.e. by profile feedback).
611 The final code sequence will have form:
613 if (call_target == expected_fn)
614 expected_fn ();
615 else
616 call_target ();
618 Every speculative call is represented by three components attached
619 to a same call statement:
620 1) a direct call (to expected_fn)
621 2) an indirect call (to call_target)
622 3) a IPA_REF_ADDR refrence to expected_fn.
624 Optimizers may later redirect direct call to clone, so 1) and 3)
625 do not need to necesarily agree with destination. */
626 unsigned int speculative : 1;
629 #define CGRAPH_FREQ_BASE 1000
630 #define CGRAPH_FREQ_MAX 100000
632 typedef struct cgraph_edge *cgraph_edge_p;
635 /* The varpool data structure.
636 Each static variable decl has assigned varpool_node. */
638 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
639 public:
640 /* Set when variable is scheduled to be assembled. */
641 unsigned output : 1;
643 /* Set if the variable is dynamically initialized, except for
644 function local statics. */
645 unsigned dynamically_initialized : 1;
648 /* Every top level asm statement is put into a asm_node. */
650 struct GTY(()) asm_node {
651 /* Next asm node. */
652 struct asm_node *next;
653 /* String for this asm node. */
654 tree asm_str;
655 /* Ordering of all cgraph nodes. */
656 int order;
659 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
661 template <>
662 template <>
663 inline bool
664 is_a_helper <cgraph_node>::test (symtab_node *p)
666 return p->type == SYMTAB_FUNCTION;
669 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
671 template <>
672 template <>
673 inline bool
674 is_a_helper <varpool_node>::test (symtab_node *p)
676 return p->type == SYMTAB_VARIABLE;
679 extern GTY(()) symtab_node *symtab_nodes;
680 extern GTY(()) int cgraph_n_nodes;
681 extern GTY(()) int cgraph_max_uid;
682 extern GTY(()) int cgraph_edge_max_uid;
683 extern bool cgraph_global_info_ready;
684 enum cgraph_state
686 /* Frontend is parsing and finalizing functions. */
687 CGRAPH_STATE_PARSING,
688 /* Callgraph is being constructed. It is safe to add new functions. */
689 CGRAPH_STATE_CONSTRUCTION,
690 /* Callgraph is being at LTO time. */
691 CGRAPH_LTO_STREAMING,
692 /* Callgraph is built and IPA passes are being run. */
693 CGRAPH_STATE_IPA,
694 /* Callgraph is built and all functions are transformed to SSA form. */
695 CGRAPH_STATE_IPA_SSA,
696 /* Functions are now ordered and being passed to RTL expanders. */
697 CGRAPH_STATE_EXPANSION,
698 /* All cgraph expansion is done. */
699 CGRAPH_STATE_FINISHED
701 extern enum cgraph_state cgraph_state;
702 extern bool cgraph_function_flags_ready;
703 extern cgraph_node_set cgraph_new_nodes;
705 extern GTY(()) struct asm_node *asm_nodes;
706 extern GTY(()) int symtab_order;
707 extern bool cpp_implicit_aliases_done;
709 /* Classifcation of symbols WRT partitioning. */
710 enum symbol_partitioning_class
712 /* External declarations are ignored by partitioning algorithms and they are
713 added into the boundary later via compute_ltrans_boundary. */
714 SYMBOL_EXTERNAL,
715 /* Partitioned symbols are pur into one of partitions. */
716 SYMBOL_PARTITION,
717 /* Duplicated symbols (such as comdat or constant pool references) are
718 copied into every node needing them via add_symbol_to_partition. */
719 SYMBOL_DUPLICATE
723 /* In symtab.c */
724 void symtab_register_node (symtab_node *);
725 void symtab_unregister_node (symtab_node *);
726 void symtab_remove_node (symtab_node *);
727 symtab_node *symtab_get_node (const_tree);
728 symtab_node *symtab_node_for_asm (const_tree asmname);
729 void symtab_insert_node_to_hashtable (symtab_node *);
730 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
731 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
732 void dump_symtab (FILE *);
733 void debug_symtab (void);
734 void dump_symtab_node (FILE *, symtab_node *);
735 void debug_symtab_node (symtab_node *);
736 void dump_symtab_base (FILE *, symtab_node *);
737 void verify_symtab (void);
738 void verify_symtab_node (symtab_node *);
739 bool verify_symtab_base (symtab_node *);
740 bool symtab_used_from_object_file_p (symtab_node *);
741 void symtab_make_decl_local (tree);
742 symtab_node *symtab_alias_ultimate_target (symtab_node *,
743 enum availability *avail = NULL);
744 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
745 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
746 bool symtab_for_node_and_aliases (symtab_node *,
747 bool (*) (symtab_node *, void *),
748 void *,
749 bool);
750 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
751 enum availability symtab_node_availability (symtab_node *);
752 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
753 enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
755 /* In cgraph.c */
756 void dump_cgraph (FILE *);
757 void debug_cgraph (void);
758 void dump_cgraph_node (FILE *, struct cgraph_node *);
759 void debug_cgraph_node (struct cgraph_node *);
760 void cgraph_remove_edge (struct cgraph_edge *);
761 void cgraph_remove_node (struct cgraph_node *);
762 void cgraph_release_function_body (struct cgraph_node *);
763 void release_function_body (tree);
764 void cgraph_node_remove_callees (struct cgraph_node *node);
765 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
766 struct cgraph_node *,
767 gimple, gcov_type, int);
768 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
769 int, gcov_type, int);
770 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
771 struct cgraph_node * cgraph_create_node (tree);
772 struct cgraph_node * cgraph_create_empty_node (void);
773 struct cgraph_node * cgraph_get_create_node (tree);
774 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
775 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
776 HOST_WIDE_INT, tree, tree);
777 struct cgraph_node *cgraph_node_for_asm (tree);
778 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
779 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
780 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
781 struct cgraph_local_info *cgraph_local_info (tree);
782 struct cgraph_global_info *cgraph_global_info (tree);
783 struct cgraph_rtl_info *cgraph_rtl_info (tree);
784 struct cgraph_node *cgraph_create_function_alias (tree, tree);
785 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
786 struct cgraph_node *);
787 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
788 struct cgraph_edge *);
790 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
791 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
792 bool cgraph_only_called_directly_p (struct cgraph_node *);
794 bool cgraph_function_possibly_inlined_p (tree);
795 void cgraph_unnest_node (struct cgraph_node *);
797 enum availability cgraph_function_body_availability (struct cgraph_node *);
798 void cgraph_add_new_function (tree, bool);
799 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
800 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
802 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
803 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
804 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
805 bool cgraph_node_cannot_return (struct cgraph_node *);
806 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
807 bool cgraph_will_be_removed_from_program_if_no_direct_calls
808 (struct cgraph_node *node);
809 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
810 (struct cgraph_node *node);
811 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
812 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
813 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
814 bool (*) (struct cgraph_node *, void *),
815 void *,
816 bool);
817 bool cgraph_for_node_and_aliases (struct cgraph_node *,
818 bool (*) (struct cgraph_node *, void *),
819 void *, bool);
820 vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
821 void verify_cgraph (void);
822 void verify_cgraph_node (struct cgraph_node *);
823 void cgraph_mark_address_taken_node (struct cgraph_node *);
825 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
826 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
827 typedef void (*varpool_node_hook)(varpool_node *, void *);
828 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
829 void *);
830 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
831 void *);
832 struct cgraph_edge_hook_list;
833 struct cgraph_node_hook_list;
834 struct varpool_node_hook_list;
835 struct cgraph_2edge_hook_list;
836 struct cgraph_2node_hook_list;
837 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
838 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
839 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
840 void *);
841 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
842 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
843 void *);
844 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
845 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
846 void *);
847 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
848 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
849 void *);
850 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
851 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
852 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
853 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
854 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
855 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
856 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
857 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
858 enum availability *avail = NULL);
859 bool cgraph_get_body (struct cgraph_node *node);
860 struct cgraph_edge *
861 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
862 struct cgraph_node *,
863 gcov_type, int);
864 void cgraph_speculative_call_info (struct cgraph_edge *,
865 struct cgraph_edge *&,
866 struct cgraph_edge *&,
867 struct ipa_ref *&);
868 extern bool gimple_check_call_matching_types (gimple, tree, bool);
870 /* In cgraphunit.c */
871 struct asm_node *add_asm_node (tree);
872 extern FILE *cgraph_dump_file;
873 void cgraph_finalize_function (tree, bool);
874 void finalize_compilation_unit (void);
875 void compile (void);
876 void init_cgraph (void);
877 void cgraph_process_new_functions (void);
878 void cgraph_process_same_body_aliases (void);
879 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
880 /* Initialize datastructures so DECL is a function in lowered gimple form.
881 IN_SSA is true if the gimple is in SSA. */
882 basic_block init_lowered_empty_function (tree, bool);
883 void cgraph_reset_node (struct cgraph_node *);
884 bool expand_thunk (struct cgraph_node *, bool);
886 /* In cgraphclones.c */
888 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
889 struct cgraph_node *, gimple,
890 unsigned, gcov_type, int, bool);
891 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
892 int, bool, vec<cgraph_edge_p>,
893 bool, struct cgraph_node *, bitmap);
894 tree clone_function_name (tree decl, const char *);
895 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
896 vec<cgraph_edge_p>,
897 vec<ipa_replace_map_p, va_gc> *tree_map,
898 bitmap args_to_skip,
899 const char *clone_name);
900 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
901 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
902 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
903 bool update_speculative = true);
904 void cgraph_create_edge_including_clones (struct cgraph_node *,
905 struct cgraph_node *,
906 gimple, gimple, gcov_type, int,
907 cgraph_inline_failed_t);
908 void cgraph_materialize_all_clones (void);
909 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
910 tree, vec<cgraph_edge_p>, bitmap);
911 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
912 vec<cgraph_edge_p>,
913 vec<ipa_replace_map_p, va_gc> *,
914 bitmap, bool, bitmap,
915 basic_block, const char *);
916 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
917 bool, bitmap, bool, bitmap, basic_block);
918 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
920 /* In cgraphbuild.c */
921 unsigned int rebuild_cgraph_edges (void);
922 void cgraph_rebuild_references (void);
923 int compute_call_stmt_bb_frequency (tree, basic_block bb);
924 void record_references_in_initializer (tree, bool);
925 void ipa_record_stmt_references (struct cgraph_node *, gimple);
927 /* In ipa.c */
928 bool symtab_remove_unreachable_nodes (bool, FILE *);
929 cgraph_node_set cgraph_node_set_new (void);
930 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
931 struct cgraph_node *);
932 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
933 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
934 void dump_cgraph_node_set (FILE *, cgraph_node_set);
935 void debug_cgraph_node_set (cgraph_node_set);
936 void free_cgraph_node_set (cgraph_node_set);
937 void cgraph_build_static_cdtor (char which, tree body, int priority);
939 varpool_node_set varpool_node_set_new (void);
940 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
941 varpool_node *);
942 void varpool_node_set_add (varpool_node_set, varpool_node *);
943 void varpool_node_set_remove (varpool_node_set, varpool_node *);
944 void dump_varpool_node_set (FILE *, varpool_node_set);
945 void debug_varpool_node_set (varpool_node_set);
946 void free_varpool_node_set (varpool_node_set);
947 void ipa_discover_readonly_nonaddressable_vars (void);
948 bool varpool_externally_visible_p (varpool_node *);
950 /* In predict.c */
951 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
952 bool cgraph_optimize_for_size_p (struct cgraph_node *);
954 /* In varpool.c */
955 varpool_node *varpool_create_empty_node (void);
956 varpool_node *varpool_node_for_decl (tree);
957 varpool_node *varpool_node_for_asm (tree asmname);
958 void varpool_mark_needed_node (varpool_node *);
959 void debug_varpool (void);
960 void dump_varpool (FILE *);
961 void dump_varpool_node (FILE *, varpool_node *);
963 void varpool_finalize_decl (tree);
964 enum availability cgraph_variable_initializer_availability (varpool_node *);
965 void cgraph_make_node_local (struct cgraph_node *);
966 bool cgraph_node_can_be_local_p (struct cgraph_node *);
969 void varpool_remove_node (varpool_node *node);
970 void varpool_finalize_named_section_flags (varpool_node *node);
971 bool varpool_output_variables (void);
972 bool varpool_assemble_decl (varpool_node *node);
973 void varpool_analyze_node (varpool_node *);
974 varpool_node * varpool_extra_name_alias (tree, tree);
975 varpool_node * varpool_create_variable_alias (tree, tree);
976 void varpool_reset_queue (void);
977 tree ctor_for_folding (tree);
978 bool varpool_for_node_and_aliases (varpool_node *,
979 bool (*) (varpool_node *, void *),
980 void *, bool);
981 void varpool_add_new_variable (tree);
982 void symtab_initialize_asm_name_hash (void);
983 void symtab_prevail_in_asm_name_hash (symtab_node *node);
984 void varpool_remove_initializer (varpool_node *);
986 /* In cgraph.c */
987 extern void change_decl_assembler_name (tree, tree);
989 /* Return callgraph node for given symbol and check it is a function. */
990 static inline struct cgraph_node *
991 cgraph (symtab_node *node)
993 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
994 return (struct cgraph_node *)node;
997 /* Return varpool node for given symbol and check it is a variable. */
998 static inline varpool_node *
999 varpool (symtab_node *node)
1001 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
1002 return (varpool_node *)node;
1005 /* Return callgraph node for given symbol and check it is a function. */
1006 static inline struct cgraph_node *
1007 cgraph_get_node (const_tree decl)
1009 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1010 return cgraph (symtab_get_node (decl));
1013 /* Return varpool node for given symbol and check it is a function. */
1014 static inline varpool_node *
1015 varpool_get_node (const_tree decl)
1017 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1018 return varpool (symtab_get_node (decl));
1021 /* Walk all symbols. */
1022 #define FOR_EACH_SYMBOL(node) \
1023 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1026 /* Return first variable. */
1027 static inline varpool_node *
1028 varpool_first_variable (void)
1030 symtab_node *node;
1031 for (node = symtab_nodes; node; node = node->next)
1032 if (varpool_node *vnode = dyn_cast <varpool_node> (node))
1033 return vnode;
1034 return NULL;
1037 /* Return next variable after NODE. */
1038 static inline varpool_node *
1039 varpool_next_variable (varpool_node *node)
1041 symtab_node *node1 = node->next;
1042 for (; node1; node1 = node1->next)
1043 if (varpool_node *vnode1 = dyn_cast <varpool_node> (node1))
1044 return vnode1;
1045 return NULL;
1047 /* Walk all variables. */
1048 #define FOR_EACH_VARIABLE(node) \
1049 for ((node) = varpool_first_variable (); \
1050 (node); \
1051 (node) = varpool_next_variable ((node)))
1053 /* Return first reachable static variable with initializer. */
1054 static inline varpool_node *
1055 varpool_first_static_initializer (void)
1057 symtab_node *node;
1058 for (node = symtab_nodes; node; node = node->next)
1060 varpool_node *vnode = dyn_cast <varpool_node> (node);
1061 if (vnode && DECL_INITIAL (node->decl))
1062 return vnode;
1064 return NULL;
1067 /* Return next reachable static variable with initializer after NODE. */
1068 static inline varpool_node *
1069 varpool_next_static_initializer (varpool_node *node)
1071 symtab_node *node1 = node->next;
1072 for (; node1; node1 = node1->next)
1074 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
1075 if (vnode1 && DECL_INITIAL (node1->decl))
1076 return vnode1;
1078 return NULL;
1081 /* Walk all static variables with initializer set. */
1082 #define FOR_EACH_STATIC_INITIALIZER(node) \
1083 for ((node) = varpool_first_static_initializer (); (node); \
1084 (node) = varpool_next_static_initializer (node))
1086 /* Return first reachable static variable with initializer. */
1087 static inline varpool_node *
1088 varpool_first_defined_variable (void)
1090 symtab_node *node;
1091 for (node = symtab_nodes; node; node = node->next)
1093 varpool_node *vnode = dyn_cast <varpool_node> (node);
1094 if (vnode && vnode->definition)
1095 return vnode;
1097 return NULL;
1100 /* Return next reachable static variable with initializer after NODE. */
1101 static inline varpool_node *
1102 varpool_next_defined_variable (varpool_node *node)
1104 symtab_node *node1 = node->next;
1105 for (; node1; node1 = node1->next)
1107 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
1108 if (vnode1 && vnode1->definition)
1109 return vnode1;
1111 return NULL;
1113 /* Walk all variables with definitions in current unit. */
1114 #define FOR_EACH_DEFINED_VARIABLE(node) \
1115 for ((node) = varpool_first_defined_variable (); (node); \
1116 (node) = varpool_next_defined_variable (node))
1118 /* Return first function with body defined. */
1119 static inline struct cgraph_node *
1120 cgraph_first_defined_function (void)
1122 symtab_node *node;
1123 for (node = symtab_nodes; node; node = node->next)
1125 cgraph_node *cn = dyn_cast <cgraph_node> (node);
1126 if (cn && cn->definition)
1127 return cn;
1129 return NULL;
1132 /* Return next function with body defined after NODE. */
1133 static inline struct cgraph_node *
1134 cgraph_next_defined_function (struct cgraph_node *node)
1136 symtab_node *node1 = node->next;
1137 for (; node1; node1 = node1->next)
1139 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
1140 if (cn1 && cn1->definition)
1141 return cn1;
1143 return NULL;
1146 /* Walk all functions with body defined. */
1147 #define FOR_EACH_DEFINED_FUNCTION(node) \
1148 for ((node) = cgraph_first_defined_function (); (node); \
1149 (node) = cgraph_next_defined_function ((node)))
1151 /* Return first function. */
1152 static inline struct cgraph_node *
1153 cgraph_first_function (void)
1155 symtab_node *node;
1156 for (node = symtab_nodes; node; node = node->next)
1157 if (cgraph_node *cn = dyn_cast <cgraph_node> (node))
1158 return cn;
1159 return NULL;
1162 /* Return next function. */
1163 static inline struct cgraph_node *
1164 cgraph_next_function (struct cgraph_node *node)
1166 symtab_node *node1 = node->next;
1167 for (; node1; node1 = node1->next)
1168 if (cgraph_node *cn1 = dyn_cast <cgraph_node> (node1))
1169 return cn1;
1170 return NULL;
1172 /* Walk all functions. */
1173 #define FOR_EACH_FUNCTION(node) \
1174 for ((node) = cgraph_first_function (); (node); \
1175 (node) = cgraph_next_function ((node)))
1177 /* Return true when NODE is a function with Gimple body defined
1178 in current unit. Functions can also be define externally or they
1179 can be thunks with no Gimple representation.
1181 Note that at WPA stage, the function body may not be present in memory. */
1183 static inline bool
1184 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1186 return node->definition && !node->thunk.thunk_p && !node->alias;
1189 /* Return first function with body defined. */
1190 static inline struct cgraph_node *
1191 cgraph_first_function_with_gimple_body (void)
1193 symtab_node *node;
1194 for (node = symtab_nodes; node; node = node->next)
1196 cgraph_node *cn = dyn_cast <cgraph_node> (node);
1197 if (cn && cgraph_function_with_gimple_body_p (cn))
1198 return cn;
1200 return NULL;
1203 /* Return next reachable static variable with initializer after NODE. */
1204 static inline struct cgraph_node *
1205 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1207 symtab_node *node1 = node->next;
1208 for (; node1; node1 = node1->next)
1210 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
1211 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1212 return cn1;
1214 return NULL;
1217 /* Walk all functions with body defined. */
1218 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1219 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1220 (node) = cgraph_next_function_with_gimple_body (node))
1222 /* Create a new static variable of type TYPE. */
1223 tree add_new_static_var (tree type);
1225 /* Return true if iterator CSI points to nothing. */
1226 static inline bool
1227 csi_end_p (cgraph_node_set_iterator csi)
1229 return csi.index >= csi.set->nodes.length ();
1232 /* Advance iterator CSI. */
1233 static inline void
1234 csi_next (cgraph_node_set_iterator *csi)
1236 csi->index++;
1239 /* Return the node pointed to by CSI. */
1240 static inline struct cgraph_node *
1241 csi_node (cgraph_node_set_iterator csi)
1243 return csi.set->nodes[csi.index];
1246 /* Return an iterator to the first node in SET. */
1247 static inline cgraph_node_set_iterator
1248 csi_start (cgraph_node_set set)
1250 cgraph_node_set_iterator csi;
1252 csi.set = set;
1253 csi.index = 0;
1254 return csi;
1257 /* Return true if SET contains NODE. */
1258 static inline bool
1259 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1261 cgraph_node_set_iterator csi;
1262 csi = cgraph_node_set_find (set, node);
1263 return !csi_end_p (csi);
1266 /* Return number of nodes in SET. */
1267 static inline size_t
1268 cgraph_node_set_size (cgraph_node_set set)
1270 return set->nodes.length ();
1273 /* Return true if iterator VSI points to nothing. */
1274 static inline bool
1275 vsi_end_p (varpool_node_set_iterator vsi)
1277 return vsi.index >= vsi.set->nodes.length ();
1280 /* Advance iterator VSI. */
1281 static inline void
1282 vsi_next (varpool_node_set_iterator *vsi)
1284 vsi->index++;
1287 /* Return the node pointed to by VSI. */
1288 static inline varpool_node *
1289 vsi_node (varpool_node_set_iterator vsi)
1291 return vsi.set->nodes[vsi.index];
1294 /* Return an iterator to the first node in SET. */
1295 static inline varpool_node_set_iterator
1296 vsi_start (varpool_node_set set)
1298 varpool_node_set_iterator vsi;
1300 vsi.set = set;
1301 vsi.index = 0;
1302 return vsi;
1305 /* Return true if SET contains NODE. */
1306 static inline bool
1307 varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
1309 varpool_node_set_iterator vsi;
1310 vsi = varpool_node_set_find (set, node);
1311 return !vsi_end_p (vsi);
1314 /* Return number of nodes in SET. */
1315 static inline size_t
1316 varpool_node_set_size (varpool_node_set set)
1318 return set->nodes.length ();
1321 /* Uniquize all constants that appear in memory.
1322 Each constant in memory thus far output is recorded
1323 in `const_desc_table'. */
1325 struct GTY(()) constant_descriptor_tree {
1326 /* A MEM for the constant. */
1327 rtx rtl;
1329 /* The value of the constant. */
1330 tree value;
1332 /* Hash of value. Computing the hash from value each time
1333 hashfn is called can't work properly, as that means recursive
1334 use of the hash table during hash table expansion. */
1335 hashval_t hash;
1338 /* Return true if set is nonempty. */
1339 static inline bool
1340 cgraph_node_set_nonempty_p (cgraph_node_set set)
1342 return !set->nodes.is_empty ();
1345 /* Return true if set is nonempty. */
1346 static inline bool
1347 varpool_node_set_nonempty_p (varpool_node_set set)
1349 return !set->nodes.is_empty ();
1352 /* Return true when function NODE is only called directly or it has alias.
1353 i.e. it is not externally visible, address was not taken and
1354 it is not used in any other non-standard way. */
1356 static inline bool
1357 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1359 gcc_assert (!node->global.inlined_to);
1360 return (!node->force_output && !node->address_taken
1361 && !node->used_from_other_partition
1362 && !DECL_VIRTUAL_P (node->decl)
1363 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1364 && !DECL_STATIC_DESTRUCTOR (node->decl)
1365 && !node->externally_visible);
1368 /* Return true when function NODE can be removed from callgraph
1369 if all direct calls are eliminated. */
1371 static inline bool
1372 varpool_can_remove_if_no_refs (varpool_node *node)
1374 if (DECL_EXTERNAL (node->decl))
1375 return true;
1376 return (!node->force_output && !node->used_from_other_partition
1377 && ((DECL_COMDAT (node->decl)
1378 && !node->forced_by_abi
1379 && !symtab_used_from_object_file_p (node))
1380 || !node->externally_visible
1381 || DECL_HAS_VALUE_EXPR_P (node->decl)));
1384 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1385 i.e. if the variable is not externally visible or not used in some magic
1386 way (asm statement or such).
1387 The magic uses are all summarized in force_output flag. */
1389 static inline bool
1390 varpool_all_refs_explicit_p (varpool_node *vnode)
1392 return (vnode->definition
1393 && !vnode->externally_visible
1394 && !vnode->used_from_other_partition
1395 && !vnode->force_output);
1398 /* Constant pool accessor function. */
1399 htab_t constant_pool_htab (void);
1401 /* FIXME: inappropriate dependency of cgraph on IPA. */
1402 #include "ipa-ref-inline.h"
1404 /* Return node that alias N is aliasing. */
1406 static inline symtab_node *
1407 symtab_alias_target (symtab_node *n)
1409 struct ipa_ref *ref;
1410 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1411 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1412 return ref->referred;
1415 static inline struct cgraph_node *
1416 cgraph_alias_target (struct cgraph_node *n)
1418 return dyn_cast <cgraph_node> (symtab_alias_target (n));
1421 static inline varpool_node *
1422 varpool_alias_target (varpool_node *n)
1424 return dyn_cast <varpool_node> (symtab_alias_target (n));
1427 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1428 Do not walk through thunks.
1429 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1431 static inline struct cgraph_node *
1432 cgraph_function_or_thunk_node (struct cgraph_node *node,
1433 enum availability *availability = NULL)
1435 struct cgraph_node *n;
1437 n = dyn_cast <cgraph_node> (symtab_alias_ultimate_target (node,
1438 availability));
1439 if (!n && availability)
1440 *availability = AVAIL_NOT_AVAILABLE;
1441 return n;
1443 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1444 Do not walk through thunks.
1445 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1447 static inline varpool_node *
1448 varpool_variable_node (varpool_node *node,
1449 enum availability *availability = NULL)
1451 varpool_node *n;
1453 if (node)
1454 n = dyn_cast <varpool_node> (symtab_alias_ultimate_target (node,
1455 availability));
1456 else
1457 n = NULL;
1459 if (!n && availability)
1460 *availability = AVAIL_NOT_AVAILABLE;
1461 return n;
1464 /* Return true when the edge E represents a direct recursion. */
1465 static inline bool
1466 cgraph_edge_recursive_p (struct cgraph_edge *e)
1468 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1469 if (e->caller->global.inlined_to)
1470 return e->caller->global.inlined_to->decl == callee->decl;
1471 else
1472 return e->caller->decl == callee->decl;
1475 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1476 static inline bool
1477 decl_is_tm_clone (const_tree fndecl)
1479 struct cgraph_node *n = cgraph_get_node (fndecl);
1480 if (n)
1481 return n->tm_clone;
1482 return false;
1485 /* Likewise indicate that a node is needed, i.e. reachable via some
1486 external means. */
1488 static inline void
1489 cgraph_mark_force_output_node (struct cgraph_node *node)
1491 node->force_output = 1;
1492 gcc_checking_assert (!node->global.inlined_to);
1495 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1496 or abstract function kept for debug info purposes only. */
1498 static inline bool
1499 symtab_real_symbol_p (symtab_node *node)
1501 struct cgraph_node *cnode;
1503 if (DECL_ABSTRACT (node->decl))
1504 return false;
1505 if (!is_a <cgraph_node> (node))
1506 return true;
1507 cnode = cgraph (node);
1508 if (cnode->global.inlined_to)
1509 return false;
1510 return true;
1513 /* Return true if NODE can be discarded by linker from the binary. */
1515 static inline bool
1516 symtab_can_be_discarded (symtab_node *node)
1518 return (DECL_EXTERNAL (node->decl)
1519 || (DECL_ONE_ONLY (node->decl)
1520 && node->resolution != LDPR_PREVAILING_DEF
1521 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1522 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1525 /* Return true if NODE is local to a particular COMDAT group, and must not
1526 be named from outside the COMDAT. This is used for C++ decloned
1527 constructors. */
1529 static inline bool
1530 symtab_comdat_local_p (symtab_node *node)
1532 return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1535 /* Return true if ONE and TWO are part of the same COMDAT group. */
1537 static inline bool
1538 symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1540 return DECL_COMDAT_GROUP (one->decl) == DECL_COMDAT_GROUP (two->decl);
1542 #endif /* GCC_CGRAPH_H */