PR preprocessor/60723 - missing system-ness marks for macro tokens
[official-gcc.git] / gcc / cgraph.h
blob3ab051615e3b55cbd9f1b30e75e802a71fde93fc
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 ();
287 /* Walk all aliases for NODE. */
288 #define FOR_EACH_ALIAS(node, alias) \
289 for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++)
291 enum availability
293 /* Not yet set by cgraph_function_body_availability. */
294 AVAIL_UNSET,
295 /* Function body/variable initializer is unknown. */
296 AVAIL_NOT_AVAILABLE,
297 /* Function body/variable initializer is known but might be replaced
298 by a different one from other compilation unit and thus needs to
299 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
300 arbitrary side effects on escaping variables and functions, while
301 like AVAILABLE it might access static variables. */
302 AVAIL_OVERWRITABLE,
303 /* Function body/variable initializer is known and will be used in final
304 program. */
305 AVAIL_AVAILABLE,
306 /* Function body/variable initializer is known and all it's uses are explicitly
307 visible within current unit (ie it's address is never taken and it is not
308 exported to other units).
309 Currently used only for functions. */
310 AVAIL_LOCAL
313 /* This is the information that is put into the cgraph local structure
314 to recover a function. */
315 struct lto_file_decl_data;
317 extern const char * const cgraph_availability_names[];
318 extern const char * const ld_plugin_symbol_resolution_names[];
319 extern const char * const tls_model_names[];
321 /* Information about thunk, used only for same body aliases. */
323 struct GTY(()) cgraph_thunk_info {
324 /* Information about the thunk. */
325 HOST_WIDE_INT fixed_offset;
326 HOST_WIDE_INT virtual_value;
327 tree alias;
328 bool this_adjusting;
329 bool virtual_offset_p;
330 /* Set to true when alias node is thunk. */
331 bool thunk_p;
334 /* Information about the function collected locally.
335 Available after function is analyzed. */
337 struct GTY(()) cgraph_local_info {
338 /* Set when function function is visible in current compilation unit only
339 and its address is never taken. */
340 unsigned local : 1;
342 /* False when there is something makes versioning impossible. */
343 unsigned versionable : 1;
345 /* False when function calling convention and signature can not be changed.
346 This is the case when __builtin_apply_args is used. */
347 unsigned can_change_signature : 1;
349 /* True when the function has been originally extern inline, but it is
350 redefined now. */
351 unsigned redefined_extern_inline : 1;
353 /* True if the function may enter serial irrevocable mode. */
354 unsigned tm_may_enter_irr : 1;
357 /* Information about the function that needs to be computed globally
358 once compilation is finished. Available only with -funit-at-a-time. */
360 struct GTY(()) cgraph_global_info {
361 /* For inline clones this points to the function they will be
362 inlined into. */
363 struct cgraph_node *inlined_to;
366 /* Information about the function that is propagated by the RTL backend.
367 Available only for functions that has been already assembled. */
369 struct GTY(()) cgraph_rtl_info {
370 unsigned int preferred_incoming_stack_boundary;
372 /* Call unsaved hard registers really used by the corresponding
373 function (including ones used by functions called by the
374 function). */
375 HARD_REG_SET function_used_regs;
376 /* Set if function_used_regs is valid. */
377 unsigned function_used_regs_valid: 1;
380 /* Represent which DECL tree (or reference to such tree)
381 will be replaced by another tree while versioning. */
382 struct GTY(()) ipa_replace_map
384 /* The tree that will be replaced. */
385 tree old_tree;
386 /* The new (replacing) tree. */
387 tree new_tree;
388 /* Parameter number to replace, when old_tree is NULL. */
389 int parm_num;
390 /* True when a substitution should be done, false otherwise. */
391 bool replace_p;
392 /* True when we replace a reference to old_tree. */
393 bool ref_p;
395 typedef struct ipa_replace_map *ipa_replace_map_p;
397 struct GTY(()) cgraph_clone_info
399 vec<ipa_replace_map_p, va_gc> *tree_map;
400 bitmap args_to_skip;
401 bitmap combined_args_to_skip;
404 enum cgraph_simd_clone_arg_type
406 SIMD_CLONE_ARG_TYPE_VECTOR,
407 SIMD_CLONE_ARG_TYPE_UNIFORM,
408 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
409 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
410 SIMD_CLONE_ARG_TYPE_MASK
413 /* Function arguments in the original function of a SIMD clone.
414 Supplementary data for `struct simd_clone'. */
416 struct GTY(()) cgraph_simd_clone_arg {
417 /* Original function argument as it originally existed in
418 DECL_ARGUMENTS. */
419 tree orig_arg;
421 /* orig_arg's function (or for extern functions type from
422 TYPE_ARG_TYPES). */
423 tree orig_type;
425 /* If argument is a vector, this holds the vector version of
426 orig_arg that after adjusting the argument types will live in
427 DECL_ARGUMENTS. Otherwise, this is NULL.
429 This basically holds:
430 vector(simdlen) __typeof__(orig_arg) new_arg. */
431 tree vector_arg;
433 /* vector_arg's type (or for extern functions new vector type. */
434 tree vector_type;
436 /* If argument is a vector, this holds the array where the simd
437 argument is held while executing the simd clone function. This
438 is a local variable in the cloned function. Its content is
439 copied from vector_arg upon entry to the clone.
441 This basically holds:
442 __typeof__(orig_arg) simd_array[simdlen]. */
443 tree simd_array;
445 /* A SIMD clone's argument can be either linear (constant or
446 variable), uniform, or vector. */
447 enum cgraph_simd_clone_arg_type arg_type;
449 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
450 the constant linear step, if arg_type is
451 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
452 the uniform argument holding the step, otherwise 0. */
453 HOST_WIDE_INT linear_step;
455 /* Variable alignment if available, otherwise 0. */
456 unsigned int alignment;
459 /* Specific data for a SIMD function clone. */
461 struct GTY(()) cgraph_simd_clone {
462 /* Number of words in the SIMD lane associated with this clone. */
463 unsigned int simdlen;
465 /* Number of annotated function arguments in `args'. This is
466 usually the number of named arguments in FNDECL. */
467 unsigned int nargs;
469 /* Max hardware vector size in bits for integral vectors. */
470 unsigned int vecsize_int;
472 /* Max hardware vector size in bits for floating point vectors. */
473 unsigned int vecsize_float;
475 /* The mangling character for a given vector size. This is is used
476 to determine the ISA mangling bit as specified in the Intel
477 Vector ABI. */
478 unsigned char vecsize_mangle;
480 /* True if this is the masked, in-branch version of the clone,
481 otherwise false. */
482 unsigned int inbranch : 1;
484 /* True if this is a Cilk Plus variant. */
485 unsigned int cilk_elemental : 1;
487 /* Doubly linked list of SIMD clones. */
488 struct cgraph_node *prev_clone, *next_clone;
490 /* Original cgraph node the SIMD clones were created for. */
491 struct cgraph_node *origin;
493 /* Annotated function arguments for the original function. */
494 struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
498 /* The cgraph data structure.
499 Each function decl has assigned cgraph_node listing callees and callers. */
501 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
502 public:
503 struct cgraph_edge *callees;
504 struct cgraph_edge *callers;
505 /* List of edges representing indirect calls with a yet undetermined
506 callee. */
507 struct cgraph_edge *indirect_calls;
508 /* For nested functions points to function the node is nested in. */
509 struct cgraph_node *origin;
510 /* Points to first nested function, if any. */
511 struct cgraph_node *nested;
512 /* Pointer to the next function with same origin, if any. */
513 struct cgraph_node *next_nested;
514 /* Pointer to the next clone. */
515 struct cgraph_node *next_sibling_clone;
516 struct cgraph_node *prev_sibling_clone;
517 struct cgraph_node *clones;
518 struct cgraph_node *clone_of;
519 /* For functions with many calls sites it holds map from call expression
520 to the edge to speed up cgraph_edge function. */
521 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
522 /* Declaration node used to be clone of. */
523 tree former_clone_of;
525 /* If this is a SIMD clone, this points to the SIMD specific
526 information for it. */
527 struct cgraph_simd_clone *simdclone;
528 /* If this function has SIMD clones, this points to the first clone. */
529 struct cgraph_node *simd_clones;
531 /* Interprocedural passes scheduled to have their transform functions
532 applied next time we execute local pass on them. We maintain it
533 per-function in order to allow IPA passes to introduce new functions. */
534 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
536 struct cgraph_local_info local;
537 struct cgraph_global_info global;
538 struct cgraph_rtl_info rtl;
539 struct cgraph_clone_info clone;
540 struct cgraph_thunk_info thunk;
542 /* Expected number of executions: calculated in profile.c. */
543 gcov_type count;
544 /* How to scale counts at materialization time; used to merge
545 LTO units with different number of profile runs. */
546 int count_materialization_scale;
547 /* Unique id of the node. */
548 int uid;
549 /* ID assigned by the profiling. */
550 unsigned int profile_id;
551 /* Time profiler: first run of function. */
552 int tp_first_run;
554 /* Set when decl is an abstract function pointed to by the
555 ABSTRACT_DECL_ORIGIN of a reachable function. */
556 unsigned used_as_abstract_origin : 1;
557 /* Set once the function is lowered (i.e. its CFG is built). */
558 unsigned lowered : 1;
559 /* Set once the function has been instantiated and its callee
560 lists created. */
561 unsigned process : 1;
562 /* How commonly executed the node is. Initialized during branch
563 probabilities pass. */
564 ENUM_BITFIELD (node_frequency) frequency : 2;
565 /* True when function can only be called at startup (from static ctor). */
566 unsigned only_called_at_startup : 1;
567 /* True when function can only be called at startup (from static dtor). */
568 unsigned only_called_at_exit : 1;
569 /* True when function is the transactional clone of a function which
570 is called only from inside transactions. */
571 /* ?? We should be able to remove this. We have enough bits in
572 cgraph to calculate it. */
573 unsigned tm_clone : 1;
574 /* True if this decl is a dispatcher for function versions. */
575 unsigned dispatcher_function : 1;
576 /* True if this decl calls a COMDAT-local function. This is set up in
577 compute_inline_parameters and inline_call. */
578 unsigned calls_comdat_local : 1;
580 void set_fini_priority (priority_type priority);
581 priority_type get_fini_priority ();
585 typedef struct cgraph_node *cgraph_node_ptr;
588 /* Function Multiversioning info. */
589 struct GTY(()) cgraph_function_version_info {
590 /* The cgraph_node for which the function version info is stored. */
591 struct cgraph_node *this_node;
592 /* Chains all the semantically identical function versions. The
593 first function in this chain is the version_info node of the
594 default function. */
595 struct cgraph_function_version_info *prev;
596 /* If this version node corresponds to a dispatcher for function
597 versions, this points to the version info node of the default
598 function, the first node in the chain. */
599 struct cgraph_function_version_info *next;
600 /* If this node corresponds to a function version, this points
601 to the dispatcher function decl, which is the function that must
602 be called to execute the right function version at run-time.
604 If this cgraph node is a dispatcher (if dispatcher_function is
605 true, in the cgraph_node struct) for function versions, this
606 points to resolver function, which holds the function body of the
607 dispatcher. The dispatcher decl is an alias to the resolver
608 function decl. */
609 tree dispatcher_resolver;
612 /* Get the cgraph_function_version_info node corresponding to node. */
613 struct cgraph_function_version_info *
614 get_cgraph_node_version (struct cgraph_node *node);
616 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
617 corresponding to cgraph_node NODE. */
618 struct cgraph_function_version_info *
619 insert_new_cgraph_node_version (struct cgraph_node *node);
621 /* Record that DECL1 and DECL2 are semantically identical function
622 versions. */
623 void record_function_versions (tree decl1, tree decl2);
625 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
626 DECL is a duplicate declaration. */
627 void delete_function_version (tree decl);
629 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
630 can appear in multiple sets. */
631 struct cgraph_node_set_def
633 struct pointer_map_t *map;
634 vec<cgraph_node_ptr> nodes;
637 class varpool_node;
638 typedef varpool_node *varpool_node_ptr;
641 /* A varpool node set is a collection of varpool nodes. A varpool node
642 can appear in multiple sets. */
643 struct varpool_node_set_def
645 struct pointer_map_t * map;
646 vec<varpool_node_ptr> nodes;
649 typedef struct cgraph_node_set_def *cgraph_node_set;
652 typedef struct varpool_node_set_def *varpool_node_set;
655 /* Iterator structure for cgraph node sets. */
656 struct cgraph_node_set_iterator
658 cgraph_node_set set;
659 unsigned index;
662 /* Iterator structure for varpool node sets. */
663 struct varpool_node_set_iterator
665 varpool_node_set set;
666 unsigned index;
669 #define DEFCIFCODE(code, type, string) CIF_ ## code,
670 /* Reasons for inlining failures. */
671 enum cgraph_inline_failed_t {
672 #include "cif-code.def"
673 CIF_N_REASONS
676 enum cgraph_inline_failed_type_t
678 CIF_FINAL_NORMAL = 0,
679 CIF_FINAL_ERROR
682 /* Structure containing additional information about an indirect call. */
684 struct GTY(()) cgraph_indirect_call_info
686 /* When polymorphic is set, this field contains offset where the object which
687 was actually used in the polymorphic resides within a larger structure.
688 If agg_contents is set, the field contains the offset within the aggregate
689 from which the address to call was loaded. */
690 HOST_WIDE_INT offset;
691 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
692 HOST_WIDE_INT otr_token;
693 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
694 tree otr_type, outer_type;
695 /* Index of the parameter that is called. */
696 int param_index;
697 /* ECF flags determined from the caller. */
698 int ecf_flags;
699 /* Profile_id of common target obtrained from profile. */
700 int common_target_id;
701 /* Probability that call will land in function with COMMON_TARGET_ID. */
702 int common_target_probability;
704 /* Set when the call is a virtual call with the parameter being the
705 associated object pointer rather than a simple direct call. */
706 unsigned polymorphic : 1;
707 /* Set when the call is a call of a pointer loaded from contents of an
708 aggregate at offset. */
709 unsigned agg_contents : 1;
710 /* Set when this is a call through a member pointer. */
711 unsigned member_ptr : 1;
712 /* When the previous bit is set, this one determines whether the destination
713 is loaded from a parameter passed by reference. */
714 unsigned by_ref : 1;
715 unsigned int maybe_in_construction : 1;
716 unsigned int maybe_derived_type : 1;
719 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
720 /* Expected number of executions: calculated in profile.c. */
721 gcov_type count;
722 struct cgraph_node *caller;
723 struct cgraph_node *callee;
724 struct cgraph_edge *prev_caller;
725 struct cgraph_edge *next_caller;
726 struct cgraph_edge *prev_callee;
727 struct cgraph_edge *next_callee;
728 gimple call_stmt;
729 /* Additional information about an indirect call. Not cleared when an edge
730 becomes direct. */
731 struct cgraph_indirect_call_info *indirect_info;
732 PTR GTY ((skip (""))) aux;
733 /* When equal to CIF_OK, inline this call. Otherwise, points to the
734 explanation why function was not inlined. */
735 enum cgraph_inline_failed_t inline_failed;
736 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
737 when the function is serialized in. */
738 unsigned int lto_stmt_uid;
739 /* Expected frequency of executions within the function.
740 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
741 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
742 int frequency;
743 /* Unique id of the edge. */
744 int uid;
745 /* Whether this edge was made direct by indirect inlining. */
746 unsigned int indirect_inlining_edge : 1;
747 /* Whether this edge describes an indirect call with an undetermined
748 callee. */
749 unsigned int indirect_unknown_callee : 1;
750 /* Whether this edge is still a dangling */
751 /* True if the corresponding CALL stmt cannot be inlined. */
752 unsigned int call_stmt_cannot_inline_p : 1;
753 /* Can this call throw externally? */
754 unsigned int can_throw_external : 1;
755 /* Edges with SPECULATIVE flag represents indirect calls that was
756 speculatively turned into direct (i.e. by profile feedback).
757 The final code sequence will have form:
759 if (call_target == expected_fn)
760 expected_fn ();
761 else
762 call_target ();
764 Every speculative call is represented by three components attached
765 to a same call statement:
766 1) a direct call (to expected_fn)
767 2) an indirect call (to call_target)
768 3) a IPA_REF_ADDR refrence to expected_fn.
770 Optimizers may later redirect direct call to clone, so 1) and 3)
771 do not need to necesarily agree with destination. */
772 unsigned int speculative : 1;
775 #define CGRAPH_FREQ_BASE 1000
776 #define CGRAPH_FREQ_MAX 100000
778 typedef struct cgraph_edge *cgraph_edge_p;
781 /* The varpool data structure.
782 Each static variable decl has assigned varpool_node. */
784 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
785 public:
786 /* Set when variable is scheduled to be assembled. */
787 unsigned output : 1;
789 /* Set if the variable is dynamically initialized, except for
790 function local statics. */
791 unsigned dynamically_initialized : 1;
793 ENUM_BITFIELD(tls_model) tls_model : 3;
795 /* Set if the variable is known to be used by single function only.
796 This is computed by ipa_signle_use pass and used by late optimizations
797 in places where optimization would be valid for local static variable
798 if we did not do any inter-procedural code movement. */
799 unsigned used_by_single_function : 1;
802 /* Every top level asm statement is put into a asm_node. */
804 struct GTY(()) asm_node {
805 /* Next asm node. */
806 struct asm_node *next;
807 /* String for this asm node. */
808 tree asm_str;
809 /* Ordering of all cgraph nodes. */
810 int order;
813 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
815 template <>
816 template <>
817 inline bool
818 is_a_helper <cgraph_node *>::test (symtab_node *p)
820 return p->type == SYMTAB_FUNCTION;
823 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
825 template <>
826 template <>
827 inline bool
828 is_a_helper <varpool_node *>::test (symtab_node *p)
830 return p->type == SYMTAB_VARIABLE;
833 extern GTY(()) symtab_node *symtab_nodes;
834 extern GTY(()) int cgraph_n_nodes;
835 extern GTY(()) int cgraph_max_uid;
836 extern GTY(()) int cgraph_edge_max_uid;
837 extern bool cgraph_global_info_ready;
838 enum cgraph_state
840 /* Frontend is parsing and finalizing functions. */
841 CGRAPH_STATE_PARSING,
842 /* Callgraph is being constructed. It is safe to add new functions. */
843 CGRAPH_STATE_CONSTRUCTION,
844 /* Callgraph is being at LTO time. */
845 CGRAPH_LTO_STREAMING,
846 /* Callgraph is built and IPA passes are being run. */
847 CGRAPH_STATE_IPA,
848 /* Callgraph is built and all functions are transformed to SSA form. */
849 CGRAPH_STATE_IPA_SSA,
850 /* Functions are now ordered and being passed to RTL expanders. */
851 CGRAPH_STATE_EXPANSION,
852 /* All cgraph expansion is done. */
853 CGRAPH_STATE_FINISHED
855 extern enum cgraph_state cgraph_state;
856 extern bool cgraph_function_flags_ready;
857 extern cgraph_node_set cgraph_new_nodes;
859 extern GTY(()) struct asm_node *asm_nodes;
860 extern GTY(()) int symtab_order;
861 extern bool cpp_implicit_aliases_done;
863 /* Classifcation of symbols WRT partitioning. */
864 enum symbol_partitioning_class
866 /* External declarations are ignored by partitioning algorithms and they are
867 added into the boundary later via compute_ltrans_boundary. */
868 SYMBOL_EXTERNAL,
869 /* Partitioned symbols are pur into one of partitions. */
870 SYMBOL_PARTITION,
871 /* Duplicated symbols (such as comdat or constant pool references) are
872 copied into every node needing them via add_symbol_to_partition. */
873 SYMBOL_DUPLICATE
877 /* In symtab.c */
878 void symtab_register_node (symtab_node *);
879 void symtab_unregister_node (symtab_node *);
880 void symtab_remove_from_same_comdat_group (symtab_node *);
881 void symtab_remove_node (symtab_node *);
882 symtab_node *symtab_node_for_asm (const_tree asmname);
883 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
884 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
885 void dump_symtab (FILE *);
886 void debug_symtab (void);
887 void dump_symtab_node (FILE *, symtab_node *);
888 void debug_symtab_node (symtab_node *);
889 void dump_symtab_base (FILE *, symtab_node *);
890 void verify_symtab (void);
891 void verify_symtab_node (symtab_node *);
892 bool verify_symtab_base (symtab_node *);
893 bool symtab_used_from_object_file_p (symtab_node *);
894 void symtab_make_decl_local (tree);
895 symtab_node *symtab_alias_ultimate_target (symtab_node *,
896 enum availability *avail = NULL);
897 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
898 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
899 bool symtab_for_node_and_aliases (symtab_node *,
900 bool (*) (symtab_node *, void *),
901 void *,
902 bool);
903 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
904 enum availability symtab_node_availability (symtab_node *);
905 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
906 enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
908 /* In cgraph.c */
909 void dump_cgraph (FILE *);
910 void debug_cgraph (void);
911 void dump_cgraph_node (FILE *, struct cgraph_node *);
912 void debug_cgraph_node (struct cgraph_node *);
913 void cgraph_remove_edge (struct cgraph_edge *);
914 void cgraph_remove_node (struct cgraph_node *);
915 void cgraph_release_function_body (struct cgraph_node *);
916 void release_function_body (tree);
917 void cgraph_node_remove_callees (struct cgraph_node *node);
918 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
919 struct cgraph_node *,
920 gimple, gcov_type, int);
921 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
922 int, gcov_type, int);
923 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
924 struct cgraph_node * cgraph_create_node (tree);
925 struct cgraph_node * cgraph_create_empty_node (void);
926 struct cgraph_node * cgraph_get_create_node (tree);
927 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
928 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
929 HOST_WIDE_INT, tree, tree);
930 struct cgraph_node *cgraph_node_for_asm (tree);
931 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
932 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
933 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
934 struct cgraph_local_info *cgraph_local_info (tree);
935 struct cgraph_global_info *cgraph_global_info (tree);
936 struct cgraph_rtl_info *cgraph_rtl_info (tree);
937 struct cgraph_node *cgraph_create_function_alias (tree, tree);
938 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
939 struct cgraph_node *);
940 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
941 struct cgraph_edge *);
943 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
944 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
945 bool cgraph_only_called_directly_p (struct cgraph_node *);
947 bool cgraph_function_possibly_inlined_p (tree);
948 void cgraph_unnest_node (struct cgraph_node *);
950 enum availability cgraph_function_body_availability (struct cgraph_node *);
951 void cgraph_add_new_function (tree, bool);
952 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
953 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
955 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
956 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
957 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
958 bool cgraph_node_cannot_return (struct cgraph_node *);
959 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
960 bool cgraph_will_be_removed_from_program_if_no_direct_calls
961 (struct cgraph_node *node);
962 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
963 (struct cgraph_node *node);
964 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
965 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
966 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
967 bool (*) (struct cgraph_node *, void *),
968 void *,
969 bool);
970 bool cgraph_for_node_and_aliases (struct cgraph_node *,
971 bool (*) (struct cgraph_node *, void *),
972 void *, bool);
973 vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
974 void verify_cgraph (void);
975 void verify_cgraph_node (struct cgraph_node *);
976 void cgraph_mark_address_taken_node (struct cgraph_node *);
978 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
979 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
980 typedef void (*varpool_node_hook)(varpool_node *, void *);
981 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
982 void *);
983 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
984 void *);
985 struct cgraph_edge_hook_list;
986 struct cgraph_node_hook_list;
987 struct varpool_node_hook_list;
988 struct cgraph_2edge_hook_list;
989 struct cgraph_2node_hook_list;
990 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
991 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
992 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
993 void *);
994 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
995 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
996 void *);
997 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
998 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
999 void *);
1000 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
1001 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
1002 void *);
1003 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
1004 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
1005 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
1006 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
1007 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
1008 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
1009 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
1010 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
1011 enum availability *avail = NULL);
1012 bool cgraph_get_body (struct cgraph_node *node);
1013 struct cgraph_edge *
1014 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
1015 struct cgraph_node *,
1016 gcov_type, int);
1017 void cgraph_speculative_call_info (struct cgraph_edge *,
1018 struct cgraph_edge *&,
1019 struct cgraph_edge *&,
1020 struct ipa_ref *&);
1021 extern bool gimple_check_call_matching_types (gimple, tree, bool);
1023 /* In cgraphunit.c */
1024 struct asm_node *add_asm_node (tree);
1025 extern FILE *cgraph_dump_file;
1026 void cgraph_finalize_function (tree, bool);
1027 void finalize_compilation_unit (void);
1028 void compile (void);
1029 void init_cgraph (void);
1030 void cgraph_process_new_functions (void);
1031 void cgraph_process_same_body_aliases (void);
1032 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
1033 /* Initialize datastructures so DECL is a function in lowered gimple form.
1034 IN_SSA is true if the gimple is in SSA. */
1035 basic_block init_lowered_empty_function (tree, bool);
1036 void cgraph_reset_node (struct cgraph_node *);
1037 bool expand_thunk (struct cgraph_node *, bool, bool);
1038 void cgraph_make_wrapper (struct cgraph_node *source,
1039 struct cgraph_node *target);
1041 /* In cgraphclones.c */
1043 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
1044 struct cgraph_node *, gimple,
1045 unsigned, gcov_type, int, bool);
1046 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
1047 int, bool, vec<cgraph_edge_p>,
1048 bool, struct cgraph_node *, bitmap);
1049 tree clone_function_name (tree decl, const char *);
1050 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
1051 vec<cgraph_edge_p>,
1052 vec<ipa_replace_map_p, va_gc> *tree_map,
1053 bitmap args_to_skip,
1054 const char *clone_name);
1055 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
1056 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
1057 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
1058 bool update_speculative = true);
1059 void cgraph_create_edge_including_clones (struct cgraph_node *,
1060 struct cgraph_node *,
1061 gimple, gimple, gcov_type, int,
1062 cgraph_inline_failed_t);
1063 void cgraph_materialize_all_clones (void);
1064 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
1065 tree, vec<cgraph_edge_p>, bitmap);
1066 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
1067 vec<cgraph_edge_p>,
1068 vec<ipa_replace_map_p, va_gc> *,
1069 bitmap, bool, bitmap,
1070 basic_block, const char *);
1071 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
1072 bool, bitmap, bool, bitmap, basic_block);
1073 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
1075 /* In cgraphbuild.c */
1076 unsigned int rebuild_cgraph_edges (void);
1077 void cgraph_rebuild_references (void);
1078 int compute_call_stmt_bb_frequency (tree, basic_block bb);
1079 void record_references_in_initializer (tree, bool);
1080 void ipa_record_stmt_references (struct cgraph_node *, gimple);
1082 /* In ipa.c */
1083 bool symtab_remove_unreachable_nodes (bool, FILE *);
1084 cgraph_node_set cgraph_node_set_new (void);
1085 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
1086 struct cgraph_node *);
1087 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
1088 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
1089 void dump_cgraph_node_set (FILE *, cgraph_node_set);
1090 void debug_cgraph_node_set (cgraph_node_set);
1091 void free_cgraph_node_set (cgraph_node_set);
1092 void cgraph_build_static_cdtor (char which, tree body, int priority);
1094 varpool_node_set varpool_node_set_new (void);
1095 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
1096 varpool_node *);
1097 void varpool_node_set_add (varpool_node_set, varpool_node *);
1098 void varpool_node_set_remove (varpool_node_set, varpool_node *);
1099 void dump_varpool_node_set (FILE *, varpool_node_set);
1100 void debug_varpool_node_set (varpool_node_set);
1101 void free_varpool_node_set (varpool_node_set);
1102 void ipa_discover_readonly_nonaddressable_vars (void);
1103 bool varpool_externally_visible_p (varpool_node *);
1105 /* In ipa-visibility.c */
1106 bool cgraph_local_node_p (struct cgraph_node *);
1107 bool address_taken_from_non_vtable_p (symtab_node *node);
1110 /* In predict.c */
1111 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
1112 bool cgraph_optimize_for_size_p (struct cgraph_node *);
1114 /* In varpool.c */
1115 varpool_node *varpool_create_empty_node (void);
1116 varpool_node *varpool_node_for_decl (tree);
1117 varpool_node *varpool_node_for_asm (tree asmname);
1118 void varpool_mark_needed_node (varpool_node *);
1119 void debug_varpool (void);
1120 void dump_varpool (FILE *);
1121 void dump_varpool_node (FILE *, varpool_node *);
1123 void varpool_finalize_decl (tree);
1124 enum availability cgraph_variable_initializer_availability (varpool_node *);
1125 void cgraph_make_node_local (struct cgraph_node *);
1126 bool cgraph_node_can_be_local_p (struct cgraph_node *);
1129 void varpool_remove_node (varpool_node *node);
1130 void varpool_finalize_named_section_flags (varpool_node *node);
1131 bool varpool_output_variables (void);
1132 bool varpool_assemble_decl (varpool_node *node);
1133 void varpool_analyze_node (varpool_node *);
1134 varpool_node * varpool_extra_name_alias (tree, tree);
1135 varpool_node * varpool_create_variable_alias (tree, tree);
1136 void varpool_reset_queue (void);
1137 tree ctor_for_folding (tree);
1138 bool varpool_for_node_and_aliases (varpool_node *,
1139 bool (*) (varpool_node *, void *),
1140 void *, bool);
1141 void varpool_add_new_variable (tree);
1142 void symtab_initialize_asm_name_hash (void);
1143 void symtab_prevail_in_asm_name_hash (symtab_node *node);
1144 void varpool_remove_initializer (varpool_node *);
1146 /* In cgraph.c */
1147 extern void change_decl_assembler_name (tree, tree);
1149 /* Return symbol table node associated with DECL, if any,
1150 and NULL otherwise. */
1152 static inline symtab_node *
1153 symtab_get_node (const_tree decl)
1155 #ifdef ENABLE_CHECKING
1156 /* Check that we are called for sane type of object - functions
1157 and static or external variables. */
1158 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
1159 || (TREE_CODE (decl) == VAR_DECL
1160 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1161 || in_lto_p)));
1162 /* Check that the mapping is sane - perhaps this check can go away,
1163 but at the moment frontends tends to corrupt the mapping by calling
1164 memcpy/memset on the tree nodes. */
1165 gcc_checking_assert (!decl->decl_with_vis.symtab_node
1166 || decl->decl_with_vis.symtab_node->decl == decl);
1167 #endif
1168 return decl->decl_with_vis.symtab_node;
1171 /* Return callgraph node for given symbol and check it is a function. */
1172 static inline struct cgraph_node *
1173 cgraph (symtab_node *node)
1175 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
1176 return (struct cgraph_node *)node;
1179 /* Return varpool node for given symbol and check it is a variable. */
1180 static inline varpool_node *
1181 varpool (symtab_node *node)
1183 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
1184 return (varpool_node *)node;
1187 /* Return callgraph node for given symbol and check it is a function. */
1188 static inline struct cgraph_node *
1189 cgraph_get_node (const_tree decl)
1191 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1192 return cgraph (symtab_get_node (decl));
1195 /* Return varpool node for given symbol and check it is a function. */
1196 static inline varpool_node *
1197 varpool_get_node (const_tree decl)
1199 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1200 return varpool (symtab_get_node (decl));
1203 /* Walk all symbols. */
1204 #define FOR_EACH_SYMBOL(node) \
1205 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1207 /* Return first static symbol with definition. */
1208 static inline symtab_node *
1209 symtab_first_defined_symbol (void)
1211 symtab_node *node;
1213 for (node = symtab_nodes; node; node = node->next)
1214 if (node->definition)
1215 return node;
1217 return NULL;
1220 /* Return next reachable static symbol with initializer after NODE. */
1221 static inline symtab_node *
1222 symtab_next_defined_symbol (symtab_node *node)
1224 symtab_node *node1 = node->next;
1226 for (; node1; node1 = node1->next)
1227 if (node1->definition)
1228 return node1;
1230 return NULL;
1232 /* Walk all symbols with definitions in current unit. */
1233 #define FOR_EACH_DEFINED_SYMBOL(node) \
1234 for ((node) = symtab_first_defined_symbol (); (node); \
1235 (node) = symtab_next_defined_symbol (node))
1237 /* Return first variable. */
1238 static inline varpool_node *
1239 varpool_first_variable (void)
1241 symtab_node *node;
1242 for (node = symtab_nodes; node; node = node->next)
1243 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1244 return vnode;
1245 return NULL;
1248 /* Return next variable after NODE. */
1249 static inline varpool_node *
1250 varpool_next_variable (varpool_node *node)
1252 symtab_node *node1 = node->next;
1253 for (; node1; node1 = node1->next)
1254 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1255 return vnode1;
1256 return NULL;
1258 /* Walk all variables. */
1259 #define FOR_EACH_VARIABLE(node) \
1260 for ((node) = varpool_first_variable (); \
1261 (node); \
1262 (node) = varpool_next_variable ((node)))
1264 /* Return first static variable with initializer. */
1265 static inline varpool_node *
1266 varpool_first_static_initializer (void)
1268 symtab_node *node;
1269 for (node = symtab_nodes; node; node = node->next)
1271 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1272 if (vnode && DECL_INITIAL (node->decl))
1273 return vnode;
1275 return NULL;
1278 /* Return next static variable with initializer after NODE. */
1279 static inline varpool_node *
1280 varpool_next_static_initializer (varpool_node *node)
1282 symtab_node *node1 = node->next;
1283 for (; node1; node1 = node1->next)
1285 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1286 if (vnode1 && DECL_INITIAL (node1->decl))
1287 return vnode1;
1289 return NULL;
1292 /* Walk all static variables with initializer set. */
1293 #define FOR_EACH_STATIC_INITIALIZER(node) \
1294 for ((node) = varpool_first_static_initializer (); (node); \
1295 (node) = varpool_next_static_initializer (node))
1297 /* Return first static variable with definition. */
1298 static inline varpool_node *
1299 varpool_first_defined_variable (void)
1301 symtab_node *node;
1302 for (node = symtab_nodes; node; node = node->next)
1304 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1305 if (vnode && vnode->definition)
1306 return vnode;
1308 return NULL;
1311 /* Return next static variable with definition after NODE. */
1312 static inline varpool_node *
1313 varpool_next_defined_variable (varpool_node *node)
1315 symtab_node *node1 = node->next;
1316 for (; node1; node1 = node1->next)
1318 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1319 if (vnode1 && vnode1->definition)
1320 return vnode1;
1322 return NULL;
1324 /* Walk all variables with definitions in current unit. */
1325 #define FOR_EACH_DEFINED_VARIABLE(node) \
1326 for ((node) = varpool_first_defined_variable (); (node); \
1327 (node) = varpool_next_defined_variable (node))
1329 /* Return first function with body defined. */
1330 static inline struct cgraph_node *
1331 cgraph_first_defined_function (void)
1333 symtab_node *node;
1334 for (node = symtab_nodes; node; node = node->next)
1336 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1337 if (cn && cn->definition)
1338 return cn;
1340 return NULL;
1343 /* Return next function with body defined after NODE. */
1344 static inline struct cgraph_node *
1345 cgraph_next_defined_function (struct cgraph_node *node)
1347 symtab_node *node1 = node->next;
1348 for (; node1; node1 = node1->next)
1350 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1351 if (cn1 && cn1->definition)
1352 return cn1;
1354 return NULL;
1357 /* Walk all functions with body defined. */
1358 #define FOR_EACH_DEFINED_FUNCTION(node) \
1359 for ((node) = cgraph_first_defined_function (); (node); \
1360 (node) = cgraph_next_defined_function ((node)))
1362 /* Return first function. */
1363 static inline struct cgraph_node *
1364 cgraph_first_function (void)
1366 symtab_node *node;
1367 for (node = symtab_nodes; node; node = node->next)
1368 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1369 return cn;
1370 return NULL;
1373 /* Return next function. */
1374 static inline struct cgraph_node *
1375 cgraph_next_function (struct cgraph_node *node)
1377 symtab_node *node1 = node->next;
1378 for (; node1; node1 = node1->next)
1379 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1380 return cn1;
1381 return NULL;
1383 /* Walk all functions. */
1384 #define FOR_EACH_FUNCTION(node) \
1385 for ((node) = cgraph_first_function (); (node); \
1386 (node) = cgraph_next_function ((node)))
1388 /* Return true when NODE is a function with Gimple body defined
1389 in current unit. Functions can also be define externally or they
1390 can be thunks with no Gimple representation.
1392 Note that at WPA stage, the function body may not be present in memory. */
1394 static inline bool
1395 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1397 return node->definition && !node->thunk.thunk_p && !node->alias;
1400 /* Return first function with body defined. */
1401 static inline struct cgraph_node *
1402 cgraph_first_function_with_gimple_body (void)
1404 symtab_node *node;
1405 for (node = symtab_nodes; node; node = node->next)
1407 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1408 if (cn && cgraph_function_with_gimple_body_p (cn))
1409 return cn;
1411 return NULL;
1414 /* Return next reachable static variable with initializer after NODE. */
1415 static inline struct cgraph_node *
1416 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1418 symtab_node *node1 = node->next;
1419 for (; node1; node1 = node1->next)
1421 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1422 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1423 return cn1;
1425 return NULL;
1428 /* Walk all functions with body defined. */
1429 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1430 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1431 (node) = cgraph_next_function_with_gimple_body (node))
1433 /* Create a new static variable of type TYPE. */
1434 tree add_new_static_var (tree type);
1436 /* Return true if iterator CSI points to nothing. */
1437 static inline bool
1438 csi_end_p (cgraph_node_set_iterator csi)
1440 return csi.index >= csi.set->nodes.length ();
1443 /* Advance iterator CSI. */
1444 static inline void
1445 csi_next (cgraph_node_set_iterator *csi)
1447 csi->index++;
1450 /* Return the node pointed to by CSI. */
1451 static inline struct cgraph_node *
1452 csi_node (cgraph_node_set_iterator csi)
1454 return csi.set->nodes[csi.index];
1457 /* Return an iterator to the first node in SET. */
1458 static inline cgraph_node_set_iterator
1459 csi_start (cgraph_node_set set)
1461 cgraph_node_set_iterator csi;
1463 csi.set = set;
1464 csi.index = 0;
1465 return csi;
1468 /* Return true if SET contains NODE. */
1469 static inline bool
1470 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1472 cgraph_node_set_iterator csi;
1473 csi = cgraph_node_set_find (set, node);
1474 return !csi_end_p (csi);
1477 /* Return number of nodes in SET. */
1478 static inline size_t
1479 cgraph_node_set_size (cgraph_node_set set)
1481 return set->nodes.length ();
1484 /* Return true if iterator VSI points to nothing. */
1485 static inline bool
1486 vsi_end_p (varpool_node_set_iterator vsi)
1488 return vsi.index >= vsi.set->nodes.length ();
1491 /* Advance iterator VSI. */
1492 static inline void
1493 vsi_next (varpool_node_set_iterator *vsi)
1495 vsi->index++;
1498 /* Return the node pointed to by VSI. */
1499 static inline varpool_node *
1500 vsi_node (varpool_node_set_iterator vsi)
1502 return vsi.set->nodes[vsi.index];
1505 /* Return an iterator to the first node in SET. */
1506 static inline varpool_node_set_iterator
1507 vsi_start (varpool_node_set set)
1509 varpool_node_set_iterator vsi;
1511 vsi.set = set;
1512 vsi.index = 0;
1513 return vsi;
1516 /* Return true if SET contains NODE. */
1517 static inline bool
1518 varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
1520 varpool_node_set_iterator vsi;
1521 vsi = varpool_node_set_find (set, node);
1522 return !vsi_end_p (vsi);
1525 /* Return number of nodes in SET. */
1526 static inline size_t
1527 varpool_node_set_size (varpool_node_set set)
1529 return set->nodes.length ();
1532 /* Uniquize all constants that appear in memory.
1533 Each constant in memory thus far output is recorded
1534 in `const_desc_table'. */
1536 struct GTY(()) constant_descriptor_tree {
1537 /* A MEM for the constant. */
1538 rtx rtl;
1540 /* The value of the constant. */
1541 tree value;
1543 /* Hash of value. Computing the hash from value each time
1544 hashfn is called can't work properly, as that means recursive
1545 use of the hash table during hash table expansion. */
1546 hashval_t hash;
1549 /* Return true if set is nonempty. */
1550 static inline bool
1551 cgraph_node_set_nonempty_p (cgraph_node_set set)
1553 return !set->nodes.is_empty ();
1556 /* Return true if set is nonempty. */
1557 static inline bool
1558 varpool_node_set_nonempty_p (varpool_node_set set)
1560 return !set->nodes.is_empty ();
1563 /* Return true when function NODE is only called directly or it has alias.
1564 i.e. it is not externally visible, address was not taken and
1565 it is not used in any other non-standard way. */
1567 static inline bool
1568 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1570 gcc_assert (!node->global.inlined_to);
1571 return (!node->force_output && !node->address_taken
1572 && !node->used_from_other_partition
1573 && !DECL_VIRTUAL_P (node->decl)
1574 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1575 && !DECL_STATIC_DESTRUCTOR (node->decl)
1576 && !node->externally_visible);
1579 /* Return true when function NODE can be removed from callgraph
1580 if all direct calls are eliminated. */
1582 static inline bool
1583 varpool_can_remove_if_no_refs (varpool_node *node)
1585 if (DECL_EXTERNAL (node->decl))
1586 return true;
1587 return (!node->force_output && !node->used_from_other_partition
1588 && ((DECL_COMDAT (node->decl)
1589 && !node->forced_by_abi
1590 && !symtab_used_from_object_file_p (node))
1591 || !node->externally_visible
1592 || DECL_HAS_VALUE_EXPR_P (node->decl)));
1595 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1596 i.e. if the variable is not externally visible or not used in some magic
1597 way (asm statement or such).
1598 The magic uses are all summarized in force_output flag. */
1600 static inline bool
1601 varpool_all_refs_explicit_p (varpool_node *vnode)
1603 return (vnode->definition
1604 && !vnode->externally_visible
1605 && !vnode->used_from_other_partition
1606 && !vnode->force_output);
1609 /* Constant pool accessor function. */
1610 htab_t constant_pool_htab (void);
1612 /* Return node that alias N is aliasing. */
1614 static inline symtab_node *
1615 symtab_alias_target (symtab_node *n)
1617 struct ipa_ref *ref = NULL;
1618 n->iterate_reference (0, ref);
1619 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1620 return ref->referred;
1623 static inline struct cgraph_node *
1624 cgraph_alias_target (struct cgraph_node *n)
1626 return dyn_cast <cgraph_node *> (symtab_alias_target (n));
1629 static inline varpool_node *
1630 varpool_alias_target (varpool_node *n)
1632 return dyn_cast <varpool_node *> (symtab_alias_target (n));
1635 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1636 Do not walk through thunks.
1637 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1639 static inline struct cgraph_node *
1640 cgraph_function_or_thunk_node (struct cgraph_node *node,
1641 enum availability *availability = NULL)
1643 struct cgraph_node *n;
1645 n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node,
1646 availability));
1647 if (!n && availability)
1648 *availability = AVAIL_NOT_AVAILABLE;
1649 return n;
1651 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1652 Do not walk through thunks.
1653 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1655 static inline varpool_node *
1656 varpool_variable_node (varpool_node *node,
1657 enum availability *availability = NULL)
1659 varpool_node *n;
1661 if (node)
1662 n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node,
1663 availability));
1664 else
1665 n = NULL;
1667 if (!n && availability)
1668 *availability = AVAIL_NOT_AVAILABLE;
1669 return n;
1672 /* Return true when the edge E represents a direct recursion. */
1673 static inline bool
1674 cgraph_edge_recursive_p (struct cgraph_edge *e)
1676 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1677 if (e->caller->global.inlined_to)
1678 return e->caller->global.inlined_to->decl == callee->decl;
1679 else
1680 return e->caller->decl == callee->decl;
1683 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1684 static inline bool
1685 decl_is_tm_clone (const_tree fndecl)
1687 struct cgraph_node *n = cgraph_get_node (fndecl);
1688 if (n)
1689 return n->tm_clone;
1690 return false;
1693 /* Likewise indicate that a node is needed, i.e. reachable via some
1694 external means. */
1696 static inline void
1697 cgraph_mark_force_output_node (struct cgraph_node *node)
1699 node->force_output = 1;
1700 gcc_checking_assert (!node->global.inlined_to);
1703 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1704 or abstract function kept for debug info purposes only. */
1706 static inline bool
1707 symtab_real_symbol_p (symtab_node *node)
1709 struct cgraph_node *cnode;
1711 if (DECL_ABSTRACT (node->decl))
1712 return false;
1713 if (!is_a <cgraph_node *> (node))
1714 return true;
1715 cnode = cgraph (node);
1716 if (cnode->global.inlined_to)
1717 return false;
1718 return true;
1721 /* Return true if NODE can be discarded by linker from the binary. */
1723 static inline bool
1724 symtab_can_be_discarded (symtab_node *node)
1726 return (DECL_EXTERNAL (node->decl)
1727 || (node->get_comdat_group ()
1728 && node->resolution != LDPR_PREVAILING_DEF
1729 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1730 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1733 /* Return true if NODE is local to a particular COMDAT group, and must not
1734 be named from outside the COMDAT. This is used for C++ decloned
1735 constructors. */
1737 static inline bool
1738 symtab_comdat_local_p (symtab_node *node)
1740 return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1743 /* Return true if ONE and TWO are part of the same COMDAT group. */
1745 static inline bool
1746 symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1748 if (cgraph_node *cn = dyn_cast <cgraph_node *> (one))
1750 if (cn->global.inlined_to)
1751 one = cn->global.inlined_to;
1753 if (cgraph_node *cn = dyn_cast <cgraph_node *> (two))
1755 if (cn->global.inlined_to)
1756 two = cn->global.inlined_to;
1759 return one->get_comdat_group () == two->get_comdat_group ();
1761 #endif /* GCC_CGRAPH_H */