s-os_lib.ads, [...] (GM_Time_Of): New routine to create an OS_Time from time parts.
[official-gcc.git] / gcc / cgraph.h
blob3d1f938b45e376e62dc094fbfe172b3250979af9
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 /* Section names are stored as reference counted strings in GGC safe hashtable
41 (to make them survive through PCH). */
43 struct GTY(()) section_hash_entry_d
45 int ref_count;
46 char *name; /* As long as this datastructure stays in GGC, we can not put
47 string at the tail of structure of GGC dies in horrible
48 way */
51 typedef struct section_hash_entry_d section_hash_entry;
53 /* Base of all entries in the symbol table.
54 The symtab_node is inherited by cgraph and varpol nodes. */
55 class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
56 chain_next ("%h.next"), chain_prev ("%h.previous")))
57 symtab_node
59 public:
60 /* Return name. */
61 const char *name () const;
63 /* Return asm name. */
64 const char * asm_name () const;
66 /* Type of the symbol. */
67 ENUM_BITFIELD (symtab_type) type : 8;
69 /* The symbols resolution. */
70 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
72 /*** Flags representing the symbol type. ***/
74 /* True when symbol corresponds to a definition in current unit.
75 set via cgraph_finalize_function or varpool_finalize_decl */
76 unsigned definition : 1;
77 /* True when symbol is an alias.
78 Set by assemble_alias. */
79 unsigned alias : 1;
80 /* True when alias is a weakref. */
81 unsigned weakref : 1;
82 /* C++ frontend produce same body aliases and extra name aliases for
83 virtual functions and vtables that are obviously equivalent.
84 Those aliases are bit special, especially because C++ frontend
85 visibility code is so ugly it can not get them right at first time
86 and their visibility needs to be copied from their "masters" at
87 the end of parsing. */
88 unsigned cpp_implicit_alias : 1;
89 /* Set once the definition was analyzed. The list of references and
90 other properties are built during analysis. */
91 unsigned analyzed : 1;
92 /* Set for write-only variables. */
93 unsigned writeonly : 1;
96 /*** Visibility and linkage flags. ***/
98 /* Set when function is visible by other units. */
99 unsigned externally_visible : 1;
100 /* The symbol will be assumed to be used in an invisible way (like
101 by an toplevel asm statement). */
102 unsigned force_output : 1;
103 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
104 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
105 to static and it does not inhibit optimization. */
106 unsigned forced_by_abi : 1;
107 /* True when the name is known to be unique and thus it does not need mangling. */
108 unsigned unique_name : 1;
109 /* Specify whether the section was set by user or by
110 compiler via -ffunction-sections. */
111 unsigned implicit_section : 1;
112 /* True when body and other characteristics have been removed by
113 symtab_remove_unreachable_nodes. */
114 unsigned body_removed : 1;
116 /*** WHOPR Partitioning flags.
117 These flags are used at ltrans stage when only part of the callgraph is
118 available. ***/
120 /* Set when variable is used from other LTRANS partition. */
121 unsigned used_from_other_partition : 1;
122 /* Set when function is available in the other LTRANS partition.
123 During WPA output it is used to mark nodes that are present in
124 multiple partitions. */
125 unsigned in_other_partition : 1;
129 /*** other flags. ***/
131 /* Set when symbol has address taken. */
132 unsigned address_taken : 1;
133 /* Set when init priority is set. */
134 unsigned in_init_priority_hash : 1;
137 /* Ordering of all symtab entries. */
138 int order;
140 /* Declaration representing the symbol. */
141 tree decl;
143 /* Linked list of symbol table entries starting with symtab_nodes. */
144 symtab_node *next;
145 symtab_node *previous;
147 /* Linked list of symbols with the same asm name. There may be multiple
148 entries for single symbol name during LTO, because symbols are renamed
149 only after partitioning.
151 Because inline clones are kept in the assembler name has, they also produce
152 duplicate entries.
154 There are also several long standing bugs where frontends and builtin
155 code produce duplicated decls. */
156 symtab_node *next_sharing_asm_name;
157 symtab_node *previous_sharing_asm_name;
159 /* Circular list of nodes in the same comdat group if non-NULL. */
160 symtab_node *same_comdat_group;
162 /* Return comdat group. */
163 tree get_comdat_group ()
165 return x_comdat_group;
168 /* Return comdat group as identifier_node. */
169 tree get_comdat_group_id ()
171 if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE)
172 x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group);
173 return x_comdat_group;
176 /* Set comdat group. */
177 void set_comdat_group (tree group)
179 gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE
180 || DECL_P (group));
181 x_comdat_group = group;
184 /* Return section as string. */
185 const char * get_section ()
187 if (!x_section)
188 return NULL;
189 return x_section->name;
192 /* Return ipa reference from this symtab_node to
193 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
194 of the use and STMT the statement (if it exists). */
195 struct ipa_ref *add_reference (symtab_node *referred_node,
196 enum ipa_ref_use use_type);
198 /* Return ipa reference from this symtab_node to
199 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
200 of the use and STMT the statement (if it exists). */
201 struct ipa_ref *add_reference (symtab_node *referred_node,
202 enum ipa_ref_use use_type, gimple stmt);
204 /* If VAL is a reference to a function or a variable, add a reference from
205 this symtab_node to the corresponding symbol table node. USE_TYPE specify
206 type of the use and STMT the statement (if it exists). Return the new
207 reference or NULL if none was created. */
208 struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type,
209 gimple stmt);
211 /* Clone all references from symtab NODE to this symtab_node. */
212 void clone_references (symtab_node *node);
214 /* Remove all stmt references in non-speculative references.
215 Those are not maintained during inlining & clonning.
216 The exception are speculative references that are updated along
217 with callgraph edges associated with them. */
218 void clone_referring (symtab_node *node);
220 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
221 struct ipa_ref *clone_reference (struct ipa_ref *ref, gimple stmt);
223 /* Find the structure describing a reference to REFERRED_NODE
224 and associated with statement STMT. */
225 struct ipa_ref *find_reference (symtab_node *, gimple, unsigned int);
227 /* Remove all references that are associated with statement STMT. */
228 void remove_stmt_references (gimple stmt);
230 /* Remove all stmt references in non-speculative references.
231 Those are not maintained during inlining & clonning.
232 The exception are speculative references that are updated along
233 with callgraph edges associated with them. */
234 void clear_stmts_in_references (void);
236 /* Remove all references in ref list. */
237 void remove_all_references (void);
239 /* Remove all referring items in ref list. */
240 void remove_all_referring (void);
242 /* Dump references in ref list to FILE. */
243 void dump_references (FILE *file);
245 /* Dump referring in list to FILE. */
246 void dump_referring (FILE *);
248 /* Return true if list contains an alias. */
249 bool has_aliases_p (void);
251 /* Iterates I-th reference in the list, REF is also set. */
252 struct ipa_ref *iterate_reference (unsigned i, struct ipa_ref *&ref);
254 /* Iterates I-th referring item in the list, REF is also set. */
255 struct ipa_ref *iterate_referring (unsigned i, struct ipa_ref *&ref);
257 /* Iterates I-th referring alias item in the list, REF is also set. */
258 struct ipa_ref *iterate_direct_aliases (unsigned i, struct ipa_ref *&ref);
260 /* Vectors of referring and referenced entities. */
261 struct ipa_ref_list ref_list;
263 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
264 depending to what was known to frontend on the creation time.
265 Once alias is resolved, this pointer become NULL. */
266 tree alias_target;
268 /* File stream where this node is being written to. */
269 struct lto_file_decl_data * lto_file_data;
271 PTR GTY ((skip)) aux;
273 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
274 tree x_comdat_group;
276 /* Section name. Again can be private, if allowed. */
277 section_hash_entry *x_section;
279 /* Set section for symbol and its aliases. */
280 void set_section (const char *section);
281 void set_section_for_node (const char *section);
283 void set_init_priority (priority_type priority);
284 priority_type get_init_priority ();
286 /* Return true if symbol is known to be nonzero. */
287 bool nonzero_address ();
290 /* Walk all aliases for NODE. */
291 #define FOR_EACH_ALIAS(node, alias) \
292 for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++)
294 enum availability
296 /* Not yet set by cgraph_function_body_availability. */
297 AVAIL_UNSET,
298 /* Function body/variable initializer is unknown. */
299 AVAIL_NOT_AVAILABLE,
300 /* Function body/variable initializer is known but might be replaced
301 by a different one from other compilation unit and thus needs to
302 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
303 arbitrary side effects on escaping variables and functions, while
304 like AVAILABLE it might access static variables. */
305 AVAIL_OVERWRITABLE,
306 /* Function body/variable initializer is known and will be used in final
307 program. */
308 AVAIL_AVAILABLE,
309 /* Function body/variable initializer is known and all it's uses are explicitly
310 visible within current unit (ie it's address is never taken and it is not
311 exported to other units).
312 Currently used only for functions. */
313 AVAIL_LOCAL
316 /* This is the information that is put into the cgraph local structure
317 to recover a function. */
318 struct lto_file_decl_data;
320 extern const char * const cgraph_availability_names[];
321 extern const char * const ld_plugin_symbol_resolution_names[];
322 extern const char * const tls_model_names[];
324 /* Information about thunk, used only for same body aliases. */
326 struct GTY(()) cgraph_thunk_info {
327 /* Information about the thunk. */
328 HOST_WIDE_INT fixed_offset;
329 HOST_WIDE_INT virtual_value;
330 tree alias;
331 bool this_adjusting;
332 bool virtual_offset_p;
333 /* Set to true when alias node is thunk. */
334 bool thunk_p;
337 /* Information about the function collected locally.
338 Available after function is analyzed. */
340 struct GTY(()) cgraph_local_info {
341 /* Set when function function is visible in current compilation unit only
342 and its address is never taken. */
343 unsigned local : 1;
345 /* False when there is something makes versioning impossible. */
346 unsigned versionable : 1;
348 /* False when function calling convention and signature can not be changed.
349 This is the case when __builtin_apply_args is used. */
350 unsigned can_change_signature : 1;
352 /* True when the function has been originally extern inline, but it is
353 redefined now. */
354 unsigned redefined_extern_inline : 1;
356 /* True if the function may enter serial irrevocable mode. */
357 unsigned tm_may_enter_irr : 1;
360 /* Information about the function that needs to be computed globally
361 once compilation is finished. Available only with -funit-at-a-time. */
363 struct GTY(()) cgraph_global_info {
364 /* For inline clones this points to the function they will be
365 inlined into. */
366 struct cgraph_node *inlined_to;
369 /* Information about the function that is propagated by the RTL backend.
370 Available only for functions that has been already assembled. */
372 struct GTY(()) cgraph_rtl_info {
373 unsigned int preferred_incoming_stack_boundary;
375 /* Call unsaved hard registers really used by the corresponding
376 function (including ones used by functions called by the
377 function). */
378 HARD_REG_SET function_used_regs;
379 /* Set if function_used_regs is valid. */
380 unsigned function_used_regs_valid: 1;
383 /* Represent which DECL tree (or reference to such tree)
384 will be replaced by another tree while versioning. */
385 struct GTY(()) ipa_replace_map
387 /* The tree that will be replaced. */
388 tree old_tree;
389 /* The new (replacing) tree. */
390 tree new_tree;
391 /* Parameter number to replace, when old_tree is NULL. */
392 int parm_num;
393 /* True when a substitution should be done, false otherwise. */
394 bool replace_p;
395 /* True when we replace a reference to old_tree. */
396 bool ref_p;
398 typedef struct ipa_replace_map *ipa_replace_map_p;
400 struct GTY(()) cgraph_clone_info
402 vec<ipa_replace_map_p, va_gc> *tree_map;
403 bitmap args_to_skip;
404 bitmap combined_args_to_skip;
407 enum cgraph_simd_clone_arg_type
409 SIMD_CLONE_ARG_TYPE_VECTOR,
410 SIMD_CLONE_ARG_TYPE_UNIFORM,
411 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
412 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
413 SIMD_CLONE_ARG_TYPE_MASK
416 /* Function arguments in the original function of a SIMD clone.
417 Supplementary data for `struct simd_clone'. */
419 struct GTY(()) cgraph_simd_clone_arg {
420 /* Original function argument as it originally existed in
421 DECL_ARGUMENTS. */
422 tree orig_arg;
424 /* orig_arg's function (or for extern functions type from
425 TYPE_ARG_TYPES). */
426 tree orig_type;
428 /* If argument is a vector, this holds the vector version of
429 orig_arg that after adjusting the argument types will live in
430 DECL_ARGUMENTS. Otherwise, this is NULL.
432 This basically holds:
433 vector(simdlen) __typeof__(orig_arg) new_arg. */
434 tree vector_arg;
436 /* vector_arg's type (or for extern functions new vector type. */
437 tree vector_type;
439 /* If argument is a vector, this holds the array where the simd
440 argument is held while executing the simd clone function. This
441 is a local variable in the cloned function. Its content is
442 copied from vector_arg upon entry to the clone.
444 This basically holds:
445 __typeof__(orig_arg) simd_array[simdlen]. */
446 tree simd_array;
448 /* A SIMD clone's argument can be either linear (constant or
449 variable), uniform, or vector. */
450 enum cgraph_simd_clone_arg_type arg_type;
452 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
453 the constant linear step, if arg_type is
454 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
455 the uniform argument holding the step, otherwise 0. */
456 HOST_WIDE_INT linear_step;
458 /* Variable alignment if available, otherwise 0. */
459 unsigned int alignment;
462 /* Specific data for a SIMD function clone. */
464 struct GTY(()) cgraph_simd_clone {
465 /* Number of words in the SIMD lane associated with this clone. */
466 unsigned int simdlen;
468 /* Number of annotated function arguments in `args'. This is
469 usually the number of named arguments in FNDECL. */
470 unsigned int nargs;
472 /* Max hardware vector size in bits for integral vectors. */
473 unsigned int vecsize_int;
475 /* Max hardware vector size in bits for floating point vectors. */
476 unsigned int vecsize_float;
478 /* The mangling character for a given vector size. This is is used
479 to determine the ISA mangling bit as specified in the Intel
480 Vector ABI. */
481 unsigned char vecsize_mangle;
483 /* True if this is the masked, in-branch version of the clone,
484 otherwise false. */
485 unsigned int inbranch : 1;
487 /* True if this is a Cilk Plus variant. */
488 unsigned int cilk_elemental : 1;
490 /* Doubly linked list of SIMD clones. */
491 struct cgraph_node *prev_clone, *next_clone;
493 /* Original cgraph node the SIMD clones were created for. */
494 struct cgraph_node *origin;
496 /* Annotated function arguments for the original function. */
497 struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
501 /* The cgraph data structure.
502 Each function decl has assigned cgraph_node listing callees and callers. */
504 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
505 public:
506 struct cgraph_edge *callees;
507 struct cgraph_edge *callers;
508 /* List of edges representing indirect calls with a yet undetermined
509 callee. */
510 struct cgraph_edge *indirect_calls;
511 /* For nested functions points to function the node is nested in. */
512 struct cgraph_node *origin;
513 /* Points to first nested function, if any. */
514 struct cgraph_node *nested;
515 /* Pointer to the next function with same origin, if any. */
516 struct cgraph_node *next_nested;
517 /* Pointer to the next clone. */
518 struct cgraph_node *next_sibling_clone;
519 struct cgraph_node *prev_sibling_clone;
520 struct cgraph_node *clones;
521 struct cgraph_node *clone_of;
522 /* For functions with many calls sites it holds map from call expression
523 to the edge to speed up cgraph_edge function. */
524 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
525 /* Declaration node used to be clone of. */
526 tree former_clone_of;
528 /* If this is a SIMD clone, this points to the SIMD specific
529 information for it. */
530 struct cgraph_simd_clone *simdclone;
531 /* If this function has SIMD clones, this points to the first clone. */
532 struct cgraph_node *simd_clones;
534 /* Interprocedural passes scheduled to have their transform functions
535 applied next time we execute local pass on them. We maintain it
536 per-function in order to allow IPA passes to introduce new functions. */
537 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
539 struct cgraph_local_info local;
540 struct cgraph_global_info global;
541 struct cgraph_rtl_info rtl;
542 struct cgraph_clone_info clone;
543 struct cgraph_thunk_info thunk;
545 /* Expected number of executions: calculated in profile.c. */
546 gcov_type count;
547 /* How to scale counts at materialization time; used to merge
548 LTO units with different number of profile runs. */
549 int count_materialization_scale;
550 /* Unique id of the node. */
551 int uid;
552 /* ID assigned by the profiling. */
553 unsigned int profile_id;
554 /* Time profiler: first run of function. */
555 int tp_first_run;
557 /* Set when decl is an abstract function pointed to by the
558 ABSTRACT_DECL_ORIGIN of a reachable function. */
559 unsigned used_as_abstract_origin : 1;
560 /* Set once the function is lowered (i.e. its CFG is built). */
561 unsigned lowered : 1;
562 /* Set once the function has been instantiated and its callee
563 lists created. */
564 unsigned process : 1;
565 /* How commonly executed the node is. Initialized during branch
566 probabilities pass. */
567 ENUM_BITFIELD (node_frequency) frequency : 2;
568 /* True when function can only be called at startup (from static ctor). */
569 unsigned only_called_at_startup : 1;
570 /* True when function can only be called at startup (from static dtor). */
571 unsigned only_called_at_exit : 1;
572 /* True when function is the transactional clone of a function which
573 is called only from inside transactions. */
574 /* ?? We should be able to remove this. We have enough bits in
575 cgraph to calculate it. */
576 unsigned tm_clone : 1;
577 /* True if this decl is a dispatcher for function versions. */
578 unsigned dispatcher_function : 1;
579 /* True if this decl calls a COMDAT-local function. This is set up in
580 compute_inline_parameters and inline_call. */
581 unsigned calls_comdat_local : 1;
583 void set_fini_priority (priority_type priority);
584 priority_type get_fini_priority ();
588 typedef struct cgraph_node *cgraph_node_ptr;
591 /* Function Multiversioning info. */
592 struct GTY(()) cgraph_function_version_info {
593 /* The cgraph_node for which the function version info is stored. */
594 struct cgraph_node *this_node;
595 /* Chains all the semantically identical function versions. The
596 first function in this chain is the version_info node of the
597 default function. */
598 struct cgraph_function_version_info *prev;
599 /* If this version node corresponds to a dispatcher for function
600 versions, this points to the version info node of the default
601 function, the first node in the chain. */
602 struct cgraph_function_version_info *next;
603 /* If this node corresponds to a function version, this points
604 to the dispatcher function decl, which is the function that must
605 be called to execute the right function version at run-time.
607 If this cgraph node is a dispatcher (if dispatcher_function is
608 true, in the cgraph_node struct) for function versions, this
609 points to resolver function, which holds the function body of the
610 dispatcher. The dispatcher decl is an alias to the resolver
611 function decl. */
612 tree dispatcher_resolver;
615 /* Get the cgraph_function_version_info node corresponding to node. */
616 struct cgraph_function_version_info *
617 get_cgraph_node_version (struct cgraph_node *node);
619 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
620 corresponding to cgraph_node NODE. */
621 struct cgraph_function_version_info *
622 insert_new_cgraph_node_version (struct cgraph_node *node);
624 /* Record that DECL1 and DECL2 are semantically identical function
625 versions. */
626 void record_function_versions (tree decl1, tree decl2);
628 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
629 DECL is a duplicate declaration. */
630 void delete_function_version (tree decl);
632 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
633 can appear in multiple sets. */
634 struct cgraph_node_set_def
636 struct pointer_map_t *map;
637 vec<cgraph_node_ptr> nodes;
640 class varpool_node;
641 typedef varpool_node *varpool_node_ptr;
644 /* A varpool node set is a collection of varpool nodes. A varpool node
645 can appear in multiple sets. */
646 struct varpool_node_set_def
648 struct pointer_map_t * map;
649 vec<varpool_node_ptr> nodes;
652 typedef struct cgraph_node_set_def *cgraph_node_set;
655 typedef struct varpool_node_set_def *varpool_node_set;
658 /* Iterator structure for cgraph node sets. */
659 struct cgraph_node_set_iterator
661 cgraph_node_set set;
662 unsigned index;
665 /* Iterator structure for varpool node sets. */
666 struct varpool_node_set_iterator
668 varpool_node_set set;
669 unsigned index;
672 #define DEFCIFCODE(code, type, string) CIF_ ## code,
673 /* Reasons for inlining failures. */
674 enum cgraph_inline_failed_t {
675 #include "cif-code.def"
676 CIF_N_REASONS
679 enum cgraph_inline_failed_type_t
681 CIF_FINAL_NORMAL = 0,
682 CIF_FINAL_ERROR
685 /* Structure containing additional information about an indirect call. */
687 struct GTY(()) cgraph_indirect_call_info
689 /* When polymorphic is set, this field contains offset where the object which
690 was actually used in the polymorphic resides within a larger structure.
691 If agg_contents is set, the field contains the offset within the aggregate
692 from which the address to call was loaded. */
693 HOST_WIDE_INT offset;
694 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
695 HOST_WIDE_INT otr_token;
696 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
697 tree otr_type, outer_type;
698 /* Index of the parameter that is called. */
699 int param_index;
700 /* ECF flags determined from the caller. */
701 int ecf_flags;
702 /* Profile_id of common target obtrained from profile. */
703 int common_target_id;
704 /* Probability that call will land in function with COMMON_TARGET_ID. */
705 int common_target_probability;
707 /* Set when the call is a virtual call with the parameter being the
708 associated object pointer rather than a simple direct call. */
709 unsigned polymorphic : 1;
710 /* Set when the call is a call of a pointer loaded from contents of an
711 aggregate at offset. */
712 unsigned agg_contents : 1;
713 /* Set when this is a call through a member pointer. */
714 unsigned member_ptr : 1;
715 /* When the previous bit is set, this one determines whether the destination
716 is loaded from a parameter passed by reference. */
717 unsigned by_ref : 1;
718 unsigned int maybe_in_construction : 1;
719 unsigned int maybe_derived_type : 1;
722 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
723 /* Expected number of executions: calculated in profile.c. */
724 gcov_type count;
725 struct cgraph_node *caller;
726 struct cgraph_node *callee;
727 struct cgraph_edge *prev_caller;
728 struct cgraph_edge *next_caller;
729 struct cgraph_edge *prev_callee;
730 struct cgraph_edge *next_callee;
731 gimple call_stmt;
732 /* Additional information about an indirect call. Not cleared when an edge
733 becomes direct. */
734 struct cgraph_indirect_call_info *indirect_info;
735 PTR GTY ((skip (""))) aux;
736 /* When equal to CIF_OK, inline this call. Otherwise, points to the
737 explanation why function was not inlined. */
738 enum cgraph_inline_failed_t inline_failed;
739 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
740 when the function is serialized in. */
741 unsigned int lto_stmt_uid;
742 /* Expected frequency of executions within the function.
743 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
744 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
745 int frequency;
746 /* Unique id of the edge. */
747 int uid;
748 /* Whether this edge was made direct by indirect inlining. */
749 unsigned int indirect_inlining_edge : 1;
750 /* Whether this edge describes an indirect call with an undetermined
751 callee. */
752 unsigned int indirect_unknown_callee : 1;
753 /* Whether this edge is still a dangling */
754 /* True if the corresponding CALL stmt cannot be inlined. */
755 unsigned int call_stmt_cannot_inline_p : 1;
756 /* Can this call throw externally? */
757 unsigned int can_throw_external : 1;
758 /* Edges with SPECULATIVE flag represents indirect calls that was
759 speculatively turned into direct (i.e. by profile feedback).
760 The final code sequence will have form:
762 if (call_target == expected_fn)
763 expected_fn ();
764 else
765 call_target ();
767 Every speculative call is represented by three components attached
768 to a same call statement:
769 1) a direct call (to expected_fn)
770 2) an indirect call (to call_target)
771 3) a IPA_REF_ADDR refrence to expected_fn.
773 Optimizers may later redirect direct call to clone, so 1) and 3)
774 do not need to necesarily agree with destination. */
775 unsigned int speculative : 1;
778 #define CGRAPH_FREQ_BASE 1000
779 #define CGRAPH_FREQ_MAX 100000
781 typedef struct cgraph_edge *cgraph_edge_p;
784 /* The varpool data structure.
785 Each static variable decl has assigned varpool_node. */
787 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
788 public:
789 /* Set when variable is scheduled to be assembled. */
790 unsigned output : 1;
792 /* Set if the variable is dynamically initialized, except for
793 function local statics. */
794 unsigned dynamically_initialized : 1;
796 ENUM_BITFIELD(tls_model) tls_model : 3;
798 /* Set if the variable is known to be used by single function only.
799 This is computed by ipa_signle_use pass and used by late optimizations
800 in places where optimization would be valid for local static variable
801 if we did not do any inter-procedural code movement. */
802 unsigned used_by_single_function : 1;
805 /* Every top level asm statement is put into a asm_node. */
807 struct GTY(()) asm_node {
808 /* Next asm node. */
809 struct asm_node *next;
810 /* String for this asm node. */
811 tree asm_str;
812 /* Ordering of all cgraph nodes. */
813 int order;
816 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
818 template <>
819 template <>
820 inline bool
821 is_a_helper <cgraph_node *>::test (symtab_node *p)
823 return p->type == SYMTAB_FUNCTION;
826 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
828 template <>
829 template <>
830 inline bool
831 is_a_helper <varpool_node *>::test (symtab_node *p)
833 return p->type == SYMTAB_VARIABLE;
836 extern GTY(()) symtab_node *symtab_nodes;
837 extern GTY(()) int cgraph_n_nodes;
838 extern GTY(()) int cgraph_max_uid;
839 extern GTY(()) int cgraph_edge_max_uid;
840 extern bool cgraph_global_info_ready;
841 enum cgraph_state
843 /* Frontend is parsing and finalizing functions. */
844 CGRAPH_STATE_PARSING,
845 /* Callgraph is being constructed. It is safe to add new functions. */
846 CGRAPH_STATE_CONSTRUCTION,
847 /* Callgraph is being at LTO time. */
848 CGRAPH_LTO_STREAMING,
849 /* Callgraph is built and IPA passes are being run. */
850 CGRAPH_STATE_IPA,
851 /* Callgraph is built and all functions are transformed to SSA form. */
852 CGRAPH_STATE_IPA_SSA,
853 /* Functions are now ordered and being passed to RTL expanders. */
854 CGRAPH_STATE_EXPANSION,
855 /* All cgraph expansion is done. */
856 CGRAPH_STATE_FINISHED
858 extern enum cgraph_state cgraph_state;
859 extern bool cgraph_function_flags_ready;
860 extern cgraph_node_set cgraph_new_nodes;
862 extern GTY(()) struct asm_node *asm_nodes;
863 extern GTY(()) int symtab_order;
864 extern bool cpp_implicit_aliases_done;
866 /* Classifcation of symbols WRT partitioning. */
867 enum symbol_partitioning_class
869 /* External declarations are ignored by partitioning algorithms and they are
870 added into the boundary later via compute_ltrans_boundary. */
871 SYMBOL_EXTERNAL,
872 /* Partitioned symbols are pur into one of partitions. */
873 SYMBOL_PARTITION,
874 /* Duplicated symbols (such as comdat or constant pool references) are
875 copied into every node needing them via add_symbol_to_partition. */
876 SYMBOL_DUPLICATE
880 /* In symtab.c */
881 void symtab_register_node (symtab_node *);
882 void symtab_unregister_node (symtab_node *);
883 void symtab_remove_from_same_comdat_group (symtab_node *);
884 void symtab_remove_node (symtab_node *);
885 symtab_node *symtab_node_for_asm (const_tree asmname);
886 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
887 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
888 void dump_symtab (FILE *);
889 void debug_symtab (void);
890 void dump_symtab_node (FILE *, symtab_node *);
891 void debug_symtab_node (symtab_node *);
892 void dump_symtab_base (FILE *, symtab_node *);
893 void verify_symtab (void);
894 void verify_symtab_node (symtab_node *);
895 bool verify_symtab_base (symtab_node *);
896 bool symtab_used_from_object_file_p (symtab_node *);
897 void symtab_make_decl_local (tree);
898 symtab_node *symtab_alias_ultimate_target (symtab_node *,
899 enum availability *avail = NULL);
900 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
901 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
902 bool symtab_for_node_and_aliases (symtab_node *,
903 bool (*) (symtab_node *, void *),
904 void *,
905 bool);
906 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
907 enum availability symtab_node_availability (symtab_node *);
908 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
909 enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
911 /* In cgraph.c */
912 void dump_cgraph (FILE *);
913 void debug_cgraph (void);
914 void dump_cgraph_node (FILE *, struct cgraph_node *);
915 void debug_cgraph_node (struct cgraph_node *);
916 void cgraph_remove_edge (struct cgraph_edge *);
917 void cgraph_remove_node (struct cgraph_node *);
918 void cgraph_release_function_body (struct cgraph_node *);
919 void release_function_body (tree);
920 void cgraph_node_remove_callees (struct cgraph_node *node);
921 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
922 struct cgraph_node *,
923 gimple, gcov_type, int);
924 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
925 int, gcov_type, int);
926 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
927 struct cgraph_node * cgraph_create_node (tree);
928 struct cgraph_node * cgraph_create_empty_node (void);
929 struct cgraph_node * cgraph_get_create_node (tree);
930 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
931 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
932 HOST_WIDE_INT, tree, tree);
933 struct cgraph_node *cgraph_node_for_asm (tree);
934 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
935 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
936 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
937 struct cgraph_local_info *cgraph_local_info (tree);
938 struct cgraph_global_info *cgraph_global_info (tree);
939 struct cgraph_rtl_info *cgraph_rtl_info (tree);
940 struct cgraph_node *cgraph_create_function_alias (tree, tree);
941 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
942 struct cgraph_node *);
943 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
944 struct cgraph_edge *);
946 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
947 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
948 bool cgraph_only_called_directly_p (struct cgraph_node *);
950 bool cgraph_function_possibly_inlined_p (tree);
951 void cgraph_unnest_node (struct cgraph_node *);
953 enum availability cgraph_function_body_availability (struct cgraph_node *);
954 void cgraph_add_new_function (tree, bool);
955 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
956 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
958 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
959 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
960 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
961 bool cgraph_node_cannot_return (struct cgraph_node *);
962 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
963 bool cgraph_will_be_removed_from_program_if_no_direct_calls
964 (struct cgraph_node *node);
965 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
966 (struct cgraph_node *node);
967 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
968 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
969 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
970 bool (*) (struct cgraph_node *, void *),
971 void *,
972 bool);
973 bool cgraph_for_node_and_aliases (struct cgraph_node *,
974 bool (*) (struct cgraph_node *, void *),
975 void *, bool);
976 vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
977 void verify_cgraph (void);
978 void verify_cgraph_node (struct cgraph_node *);
979 void cgraph_mark_address_taken_node (struct cgraph_node *);
981 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
982 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
983 typedef void (*varpool_node_hook)(varpool_node *, void *);
984 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
985 void *);
986 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
987 void *);
988 struct cgraph_edge_hook_list;
989 struct cgraph_node_hook_list;
990 struct varpool_node_hook_list;
991 struct cgraph_2edge_hook_list;
992 struct cgraph_2node_hook_list;
993 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
994 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
995 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
996 void *);
997 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
998 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
999 void *);
1000 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
1001 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
1002 void *);
1003 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
1004 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
1005 void *);
1006 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
1007 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
1008 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
1009 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
1010 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
1011 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
1012 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
1013 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
1014 enum availability *avail = NULL);
1015 bool cgraph_get_body (struct cgraph_node *node);
1016 struct cgraph_edge *
1017 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
1018 struct cgraph_node *,
1019 gcov_type, int);
1020 void cgraph_speculative_call_info (struct cgraph_edge *,
1021 struct cgraph_edge *&,
1022 struct cgraph_edge *&,
1023 struct ipa_ref *&);
1024 extern bool gimple_check_call_matching_types (gimple, tree, bool);
1026 /* In cgraphunit.c */
1027 struct asm_node *add_asm_node (tree);
1028 extern FILE *cgraph_dump_file;
1029 void cgraph_finalize_function (tree, bool);
1030 void finalize_compilation_unit (void);
1031 void compile (void);
1032 void init_cgraph (void);
1033 void cgraph_process_new_functions (void);
1034 void cgraph_process_same_body_aliases (void);
1035 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
1036 /* Initialize datastructures so DECL is a function in lowered gimple form.
1037 IN_SSA is true if the gimple is in SSA. */
1038 basic_block init_lowered_empty_function (tree, bool);
1039 void cgraph_reset_node (struct cgraph_node *);
1040 bool expand_thunk (struct cgraph_node *, bool, bool);
1041 void cgraph_make_wrapper (struct cgraph_node *source,
1042 struct cgraph_node *target);
1044 /* In cgraphclones.c */
1046 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
1047 struct cgraph_node *, gimple,
1048 unsigned, gcov_type, int, bool);
1049 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
1050 int, bool, vec<cgraph_edge_p>,
1051 bool, struct cgraph_node *, bitmap);
1052 tree clone_function_name (tree decl, const char *);
1053 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
1054 vec<cgraph_edge_p>,
1055 vec<ipa_replace_map_p, va_gc> *tree_map,
1056 bitmap args_to_skip,
1057 const char *clone_name);
1058 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
1059 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
1060 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
1061 bool update_speculative = true);
1062 void cgraph_create_edge_including_clones (struct cgraph_node *,
1063 struct cgraph_node *,
1064 gimple, gimple, gcov_type, int,
1065 cgraph_inline_failed_t);
1066 void cgraph_materialize_all_clones (void);
1067 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
1068 tree, vec<cgraph_edge_p>, bitmap);
1069 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
1070 vec<cgraph_edge_p>,
1071 vec<ipa_replace_map_p, va_gc> *,
1072 bitmap, bool, bitmap,
1073 basic_block, const char *);
1074 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
1075 bool, bitmap, bool, bitmap, basic_block);
1076 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
1078 /* In cgraphbuild.c */
1079 unsigned int rebuild_cgraph_edges (void);
1080 void cgraph_rebuild_references (void);
1081 int compute_call_stmt_bb_frequency (tree, basic_block bb);
1082 void record_references_in_initializer (tree, bool);
1083 void ipa_record_stmt_references (struct cgraph_node *, gimple);
1085 /* In ipa.c */
1086 bool symtab_remove_unreachable_nodes (bool, FILE *);
1087 cgraph_node_set cgraph_node_set_new (void);
1088 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
1089 struct cgraph_node *);
1090 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
1091 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
1092 void dump_cgraph_node_set (FILE *, cgraph_node_set);
1093 void debug_cgraph_node_set (cgraph_node_set);
1094 void free_cgraph_node_set (cgraph_node_set);
1095 void cgraph_build_static_cdtor (char which, tree body, int priority);
1097 varpool_node_set varpool_node_set_new (void);
1098 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
1099 varpool_node *);
1100 void varpool_node_set_add (varpool_node_set, varpool_node *);
1101 void varpool_node_set_remove (varpool_node_set, varpool_node *);
1102 void dump_varpool_node_set (FILE *, varpool_node_set);
1103 void debug_varpool_node_set (varpool_node_set);
1104 void free_varpool_node_set (varpool_node_set);
1105 void ipa_discover_readonly_nonaddressable_vars (void);
1106 bool varpool_externally_visible_p (varpool_node *);
1108 /* In ipa-visibility.c */
1109 bool cgraph_local_node_p (struct cgraph_node *);
1110 bool address_taken_from_non_vtable_p (symtab_node *node);
1113 /* In predict.c */
1114 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
1115 bool cgraph_optimize_for_size_p (struct cgraph_node *);
1117 /* In varpool.c */
1118 varpool_node *varpool_create_empty_node (void);
1119 varpool_node *varpool_node_for_decl (tree);
1120 varpool_node *varpool_node_for_asm (tree asmname);
1121 void varpool_mark_needed_node (varpool_node *);
1122 void debug_varpool (void);
1123 void dump_varpool (FILE *);
1124 void dump_varpool_node (FILE *, varpool_node *);
1126 void varpool_finalize_decl (tree);
1127 enum availability cgraph_variable_initializer_availability (varpool_node *);
1128 void cgraph_make_node_local (struct cgraph_node *);
1129 bool cgraph_node_can_be_local_p (struct cgraph_node *);
1132 void varpool_remove_node (varpool_node *node);
1133 void varpool_finalize_named_section_flags (varpool_node *node);
1134 bool varpool_output_variables (void);
1135 bool varpool_assemble_decl (varpool_node *node);
1136 void varpool_analyze_node (varpool_node *);
1137 varpool_node * varpool_extra_name_alias (tree, tree);
1138 varpool_node * varpool_create_variable_alias (tree, tree);
1139 void varpool_reset_queue (void);
1140 bool varpool_ctor_useable_for_folding_p (varpool_node *);
1141 tree ctor_for_folding (tree);
1142 bool varpool_for_node_and_aliases (varpool_node *,
1143 bool (*) (varpool_node *, void *),
1144 void *, bool);
1145 void varpool_add_new_variable (tree);
1146 void symtab_initialize_asm_name_hash (void);
1147 void symtab_prevail_in_asm_name_hash (symtab_node *node);
1148 void varpool_remove_initializer (varpool_node *);
1149 tree varpool_get_constructor (struct varpool_node *node);
1151 /* In cgraph.c */
1152 extern void change_decl_assembler_name (tree, tree);
1154 /* Return true if DECL should have entry in symbol table if used.
1155 Those are functions and static & external veriables*/
1157 static inline bool
1158 decl_in_symtab_p (const_tree decl)
1160 return (TREE_CODE (decl) == FUNCTION_DECL
1161 || (TREE_CODE (decl) == VAR_DECL
1162 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))));
1165 /* Return symbol table node associated with DECL, if any,
1166 and NULL otherwise. */
1168 static inline symtab_node *
1169 symtab_get_node (const_tree decl)
1171 #ifdef ENABLE_CHECKING
1172 gcc_checking_assert (decl_in_symtab_p (decl));
1173 /* Check that the mapping is sane - perhaps this check can go away,
1174 but at the moment frontends tends to corrupt the mapping by calling
1175 memcpy/memset on the tree nodes. */
1176 gcc_checking_assert (!decl->decl_with_vis.symtab_node
1177 || decl->decl_with_vis.symtab_node->decl == decl);
1178 #endif
1179 return decl->decl_with_vis.symtab_node;
1182 /* Return callgraph node for given symbol and check it is a function. */
1183 static inline struct cgraph_node *
1184 cgraph (symtab_node *node)
1186 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
1187 return (struct cgraph_node *)node;
1190 /* Return varpool node for given symbol and check it is a variable. */
1191 static inline varpool_node *
1192 varpool (symtab_node *node)
1194 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
1195 return (varpool_node *)node;
1198 /* Return callgraph node for given symbol and check it is a function. */
1199 static inline struct cgraph_node *
1200 cgraph_get_node (const_tree decl)
1202 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1203 return cgraph (symtab_get_node (decl));
1206 /* Return varpool node for given symbol and check it is a function. */
1207 static inline varpool_node *
1208 varpool_get_node (const_tree decl)
1210 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1211 return varpool (symtab_get_node (decl));
1214 /* Walk all symbols. */
1215 #define FOR_EACH_SYMBOL(node) \
1216 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1218 /* Return first static symbol with definition. */
1219 static inline symtab_node *
1220 symtab_first_defined_symbol (void)
1222 symtab_node *node;
1224 for (node = symtab_nodes; node; node = node->next)
1225 if (node->definition)
1226 return node;
1228 return NULL;
1231 /* Return next reachable static symbol with initializer after NODE. */
1232 static inline symtab_node *
1233 symtab_next_defined_symbol (symtab_node *node)
1235 symtab_node *node1 = node->next;
1237 for (; node1; node1 = node1->next)
1238 if (node1->definition)
1239 return node1;
1241 return NULL;
1243 /* Walk all symbols with definitions in current unit. */
1244 #define FOR_EACH_DEFINED_SYMBOL(node) \
1245 for ((node) = symtab_first_defined_symbol (); (node); \
1246 (node) = symtab_next_defined_symbol (node))
1248 /* Return first variable. */
1249 static inline varpool_node *
1250 varpool_first_variable (void)
1252 symtab_node *node;
1253 for (node = symtab_nodes; node; node = node->next)
1254 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1255 return vnode;
1256 return NULL;
1259 /* Return next variable after NODE. */
1260 static inline varpool_node *
1261 varpool_next_variable (varpool_node *node)
1263 symtab_node *node1 = node->next;
1264 for (; node1; node1 = node1->next)
1265 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1266 return vnode1;
1267 return NULL;
1269 /* Walk all variables. */
1270 #define FOR_EACH_VARIABLE(node) \
1271 for ((node) = varpool_first_variable (); \
1272 (node); \
1273 (node) = varpool_next_variable ((node)))
1275 /* Return first static variable with initializer. */
1276 static inline varpool_node *
1277 varpool_first_static_initializer (void)
1279 symtab_node *node;
1280 for (node = symtab_nodes; node; node = node->next)
1282 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1283 if (vnode && DECL_INITIAL (node->decl))
1284 return vnode;
1286 return NULL;
1289 /* Return next static variable with initializer after NODE. */
1290 static inline varpool_node *
1291 varpool_next_static_initializer (varpool_node *node)
1293 symtab_node *node1 = node->next;
1294 for (; node1; node1 = node1->next)
1296 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1297 if (vnode1 && DECL_INITIAL (node1->decl))
1298 return vnode1;
1300 return NULL;
1303 /* Walk all static variables with initializer set. */
1304 #define FOR_EACH_STATIC_INITIALIZER(node) \
1305 for ((node) = varpool_first_static_initializer (); (node); \
1306 (node) = varpool_next_static_initializer (node))
1308 /* Return first static variable with definition. */
1309 static inline varpool_node *
1310 varpool_first_defined_variable (void)
1312 symtab_node *node;
1313 for (node = symtab_nodes; node; node = node->next)
1315 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1316 if (vnode && vnode->definition)
1317 return vnode;
1319 return NULL;
1322 /* Return next static variable with definition after NODE. */
1323 static inline varpool_node *
1324 varpool_next_defined_variable (varpool_node *node)
1326 symtab_node *node1 = node->next;
1327 for (; node1; node1 = node1->next)
1329 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1330 if (vnode1 && vnode1->definition)
1331 return vnode1;
1333 return NULL;
1335 /* Walk all variables with definitions in current unit. */
1336 #define FOR_EACH_DEFINED_VARIABLE(node) \
1337 for ((node) = varpool_first_defined_variable (); (node); \
1338 (node) = varpool_next_defined_variable (node))
1340 /* Return first function with body defined. */
1341 static inline struct cgraph_node *
1342 cgraph_first_defined_function (void)
1344 symtab_node *node;
1345 for (node = symtab_nodes; node; node = node->next)
1347 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1348 if (cn && cn->definition)
1349 return cn;
1351 return NULL;
1354 /* Return next function with body defined after NODE. */
1355 static inline struct cgraph_node *
1356 cgraph_next_defined_function (struct cgraph_node *node)
1358 symtab_node *node1 = node->next;
1359 for (; node1; node1 = node1->next)
1361 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1362 if (cn1 && cn1->definition)
1363 return cn1;
1365 return NULL;
1368 /* Walk all functions with body defined. */
1369 #define FOR_EACH_DEFINED_FUNCTION(node) \
1370 for ((node) = cgraph_first_defined_function (); (node); \
1371 (node) = cgraph_next_defined_function ((node)))
1373 /* Return first function. */
1374 static inline struct cgraph_node *
1375 cgraph_first_function (void)
1377 symtab_node *node;
1378 for (node = symtab_nodes; node; node = node->next)
1379 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1380 return cn;
1381 return NULL;
1384 /* Return next function. */
1385 static inline struct cgraph_node *
1386 cgraph_next_function (struct cgraph_node *node)
1388 symtab_node *node1 = node->next;
1389 for (; node1; node1 = node1->next)
1390 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1391 return cn1;
1392 return NULL;
1394 /* Walk all functions. */
1395 #define FOR_EACH_FUNCTION(node) \
1396 for ((node) = cgraph_first_function (); (node); \
1397 (node) = cgraph_next_function ((node)))
1399 /* Return true when NODE is a function with Gimple body defined
1400 in current unit. Functions can also be define externally or they
1401 can be thunks with no Gimple representation.
1403 Note that at WPA stage, the function body may not be present in memory. */
1405 static inline bool
1406 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1408 return node->definition && !node->thunk.thunk_p && !node->alias;
1411 /* Return first function with body defined. */
1412 static inline struct cgraph_node *
1413 cgraph_first_function_with_gimple_body (void)
1415 symtab_node *node;
1416 for (node = symtab_nodes; node; node = node->next)
1418 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1419 if (cn && cgraph_function_with_gimple_body_p (cn))
1420 return cn;
1422 return NULL;
1425 /* Return next reachable static variable with initializer after NODE. */
1426 static inline struct cgraph_node *
1427 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1429 symtab_node *node1 = node->next;
1430 for (; node1; node1 = node1->next)
1432 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1433 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1434 return cn1;
1436 return NULL;
1439 /* Walk all functions with body defined. */
1440 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1441 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1442 (node) = cgraph_next_function_with_gimple_body (node))
1444 /* Create a new static variable of type TYPE. */
1445 tree add_new_static_var (tree type);
1447 /* Return true if iterator CSI points to nothing. */
1448 static inline bool
1449 csi_end_p (cgraph_node_set_iterator csi)
1451 return csi.index >= csi.set->nodes.length ();
1454 /* Advance iterator CSI. */
1455 static inline void
1456 csi_next (cgraph_node_set_iterator *csi)
1458 csi->index++;
1461 /* Return the node pointed to by CSI. */
1462 static inline struct cgraph_node *
1463 csi_node (cgraph_node_set_iterator csi)
1465 return csi.set->nodes[csi.index];
1468 /* Return an iterator to the first node in SET. */
1469 static inline cgraph_node_set_iterator
1470 csi_start (cgraph_node_set set)
1472 cgraph_node_set_iterator csi;
1474 csi.set = set;
1475 csi.index = 0;
1476 return csi;
1479 /* Return true if SET contains NODE. */
1480 static inline bool
1481 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1483 cgraph_node_set_iterator csi;
1484 csi = cgraph_node_set_find (set, node);
1485 return !csi_end_p (csi);
1488 /* Return number of nodes in SET. */
1489 static inline size_t
1490 cgraph_node_set_size (cgraph_node_set set)
1492 return set->nodes.length ();
1495 /* Return true if iterator VSI points to nothing. */
1496 static inline bool
1497 vsi_end_p (varpool_node_set_iterator vsi)
1499 return vsi.index >= vsi.set->nodes.length ();
1502 /* Advance iterator VSI. */
1503 static inline void
1504 vsi_next (varpool_node_set_iterator *vsi)
1506 vsi->index++;
1509 /* Return the node pointed to by VSI. */
1510 static inline varpool_node *
1511 vsi_node (varpool_node_set_iterator vsi)
1513 return vsi.set->nodes[vsi.index];
1516 /* Return an iterator to the first node in SET. */
1517 static inline varpool_node_set_iterator
1518 vsi_start (varpool_node_set set)
1520 varpool_node_set_iterator vsi;
1522 vsi.set = set;
1523 vsi.index = 0;
1524 return vsi;
1527 /* Return true if SET contains NODE. */
1528 static inline bool
1529 varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
1531 varpool_node_set_iterator vsi;
1532 vsi = varpool_node_set_find (set, node);
1533 return !vsi_end_p (vsi);
1536 /* Return number of nodes in SET. */
1537 static inline size_t
1538 varpool_node_set_size (varpool_node_set set)
1540 return set->nodes.length ();
1543 /* Uniquize all constants that appear in memory.
1544 Each constant in memory thus far output is recorded
1545 in `const_desc_table'. */
1547 struct GTY(()) constant_descriptor_tree {
1548 /* A MEM for the constant. */
1549 rtx rtl;
1551 /* The value of the constant. */
1552 tree value;
1554 /* Hash of value. Computing the hash from value each time
1555 hashfn is called can't work properly, as that means recursive
1556 use of the hash table during hash table expansion. */
1557 hashval_t hash;
1560 /* Return true if set is nonempty. */
1561 static inline bool
1562 cgraph_node_set_nonempty_p (cgraph_node_set set)
1564 return !set->nodes.is_empty ();
1567 /* Return true if set is nonempty. */
1568 static inline bool
1569 varpool_node_set_nonempty_p (varpool_node_set set)
1571 return !set->nodes.is_empty ();
1574 /* Return true when function NODE is only called directly or it has alias.
1575 i.e. it is not externally visible, address was not taken and
1576 it is not used in any other non-standard way. */
1578 static inline bool
1579 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1581 gcc_assert (!node->global.inlined_to);
1582 return (!node->force_output && !node->address_taken
1583 && !node->used_from_other_partition
1584 && !DECL_VIRTUAL_P (node->decl)
1585 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1586 && !DECL_STATIC_DESTRUCTOR (node->decl)
1587 && !node->externally_visible);
1590 /* Return true when function NODE can be removed from callgraph
1591 if all direct calls are eliminated. */
1593 static inline bool
1594 varpool_can_remove_if_no_refs (varpool_node *node)
1596 if (DECL_EXTERNAL (node->decl))
1597 return true;
1598 return (!node->force_output && !node->used_from_other_partition
1599 && ((DECL_COMDAT (node->decl)
1600 && !node->forced_by_abi
1601 && !symtab_used_from_object_file_p (node))
1602 || !node->externally_visible
1603 || DECL_HAS_VALUE_EXPR_P (node->decl)));
1606 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1607 i.e. if the variable is not externally visible or not used in some magic
1608 way (asm statement or such).
1609 The magic uses are all summarized in force_output flag. */
1611 static inline bool
1612 varpool_all_refs_explicit_p (varpool_node *vnode)
1614 return (vnode->definition
1615 && !vnode->externally_visible
1616 && !vnode->used_from_other_partition
1617 && !vnode->force_output);
1620 /* Constant pool accessor function. */
1621 htab_t constant_pool_htab (void);
1623 /* Return node that alias N is aliasing. */
1625 static inline symtab_node *
1626 symtab_alias_target (symtab_node *n)
1628 struct ipa_ref *ref = NULL;
1629 n->iterate_reference (0, ref);
1630 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1631 return ref->referred;
1634 static inline struct cgraph_node *
1635 cgraph_alias_target (struct cgraph_node *n)
1637 return dyn_cast <cgraph_node *> (symtab_alias_target (n));
1640 static inline varpool_node *
1641 varpool_alias_target (varpool_node *n)
1643 return dyn_cast <varpool_node *> (symtab_alias_target (n));
1646 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1647 Do not walk through thunks.
1648 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1650 static inline struct cgraph_node *
1651 cgraph_function_or_thunk_node (struct cgraph_node *node,
1652 enum availability *availability = NULL)
1654 struct cgraph_node *n;
1656 n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node,
1657 availability));
1658 if (!n && availability)
1659 *availability = AVAIL_NOT_AVAILABLE;
1660 return n;
1662 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1663 Do not walk through thunks.
1664 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1666 static inline varpool_node *
1667 varpool_variable_node (varpool_node *node,
1668 enum availability *availability = NULL)
1670 varpool_node *n;
1672 if (node)
1673 n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node,
1674 availability));
1675 else
1676 n = NULL;
1678 if (!n && availability)
1679 *availability = AVAIL_NOT_AVAILABLE;
1680 return n;
1683 /* Return true when the edge E represents a direct recursion. */
1684 static inline bool
1685 cgraph_edge_recursive_p (struct cgraph_edge *e)
1687 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1688 if (e->caller->global.inlined_to)
1689 return e->caller->global.inlined_to->decl == callee->decl;
1690 else
1691 return e->caller->decl == callee->decl;
1694 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1695 static inline bool
1696 decl_is_tm_clone (const_tree fndecl)
1698 struct cgraph_node *n = cgraph_get_node (fndecl);
1699 if (n)
1700 return n->tm_clone;
1701 return false;
1704 /* Likewise indicate that a node is needed, i.e. reachable via some
1705 external means. */
1707 static inline void
1708 cgraph_mark_force_output_node (struct cgraph_node *node)
1710 node->force_output = 1;
1711 gcc_checking_assert (!node->global.inlined_to);
1714 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1715 or abstract function kept for debug info purposes only. */
1717 static inline bool
1718 symtab_real_symbol_p (symtab_node *node)
1720 struct cgraph_node *cnode;
1722 if (DECL_ABSTRACT (node->decl))
1723 return false;
1724 if (!is_a <cgraph_node *> (node))
1725 return true;
1726 cnode = cgraph (node);
1727 if (cnode->global.inlined_to)
1728 return false;
1729 return true;
1732 /* Return true if NODE can be discarded by linker from the binary. */
1734 static inline bool
1735 symtab_can_be_discarded (symtab_node *node)
1737 return (DECL_EXTERNAL (node->decl)
1738 || (node->get_comdat_group ()
1739 && node->resolution != LDPR_PREVAILING_DEF
1740 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1741 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1744 /* Return true if NODE is local to a particular COMDAT group, and must not
1745 be named from outside the COMDAT. This is used for C++ decloned
1746 constructors. */
1748 static inline bool
1749 symtab_comdat_local_p (symtab_node *node)
1751 return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1754 /* Return true if ONE and TWO are part of the same COMDAT group. */
1756 static inline bool
1757 symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1759 if (cgraph_node *cn = dyn_cast <cgraph_node *> (one))
1761 if (cn->global.inlined_to)
1762 one = cn->global.inlined_to;
1764 if (cgraph_node *cn = dyn_cast <cgraph_node *> (two))
1766 if (cn->global.inlined_to)
1767 two = cn->global.inlined_to;
1770 return one->get_comdat_group () == two->get_comdat_group ();
1772 #endif /* GCC_CGRAPH_H */