* rtl.h (insn_location): Declare.
[official-gcc.git] / gcc / cgraph.h
blob9c6f55896b0def9e2ca9dff03c9275ef46d6f164
1 /* Callgraph handling code.
2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_CGRAPH_H
22 #define GCC_CGRAPH_H
24 #include "is-a.h"
25 #include "plugin-api.h"
26 #include "vec.h"
27 #include "basic-block.h"
28 #include "function.h"
29 #include "ipa-ref.h"
31 /* Symbol table consists of functions and variables.
32 TODO: add labels and CONST_DECLs. */
33 enum symtab_type
35 SYMTAB_SYMBOL,
36 SYMTAB_FUNCTION,
37 SYMTAB_VARIABLE
40 /* Base of all entries in the symbol table.
41 The symtab_node is inherited by cgraph and varpol nodes. */
42 class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
43 chain_next ("%h.next"), chain_prev ("%h.previous")))
44 symtab_node
46 public:
47 /* Return name. */
48 const char *name () const;
50 /* Return asm name. */
51 const char * asm_name () const;
53 /* Type of the symbol. */
54 ENUM_BITFIELD (symtab_type) type : 8;
56 /* The symbols resolution. */
57 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
59 /*** Flags representing the symbol type. ***/
61 /* True when symbol corresponds to a definition in current unit.
62 set via cgraph_finalize_function or varpool_finalize_decl */
63 unsigned definition : 1;
64 /* True when symbol is an alias.
65 Set by assemble_alias. */
66 unsigned alias : 1;
67 /* True when alias is a weakref. */
68 unsigned weakref : 1;
69 /* C++ frontend produce same body aliases and extra name aliases for
70 virtual functions and vtables that are obviously equivalent.
71 Those aliases are bit special, especially because C++ frontend
72 visibility code is so ugly it can not get them right at first time
73 and their visibility needs to be copied from their "masters" at
74 the end of parsing. */
75 unsigned cpp_implicit_alias : 1;
76 /* Set once the definition was analyzed. The list of references and
77 other properties are built during analysis. */
78 unsigned analyzed : 1;
79 /* Set for write-only variables. */
80 unsigned writeonly : 1;
83 /*** Visibility and linkage flags. ***/
85 /* Set when function is visible by other units. */
86 unsigned externally_visible : 1;
87 /* The symbol will be assumed to be used in an invisible way (like
88 by an toplevel asm statement). */
89 unsigned force_output : 1;
90 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
91 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
92 to static and it does not inhibit optimization. */
93 unsigned forced_by_abi : 1;
94 /* True when the name is known to be unique and thus it does not need mangling. */
95 unsigned unique_name : 1;
96 /* True when body and other characteristics have been removed by
97 symtab_remove_unreachable_nodes. */
98 unsigned body_removed : 1;
100 /*** WHOPR Partitioning flags.
101 These flags are used at ltrans stage when only part of the callgraph is
102 available. ***/
104 /* Set when variable is used from other LTRANS partition. */
105 unsigned used_from_other_partition : 1;
106 /* Set when function is available in the other LTRANS partition.
107 During WPA output it is used to mark nodes that are present in
108 multiple partitions. */
109 unsigned in_other_partition : 1;
113 /*** other flags. ***/
115 /* Set when symbol has address taken. */
116 unsigned address_taken : 1;
119 /* Ordering of all symtab entries. */
120 int order;
122 /* Declaration representing the symbol. */
123 tree decl;
125 /* Linked list of symbol table entries starting with symtab_nodes. */
126 symtab_node *next;
127 symtab_node *previous;
129 /* Linked list of symbols with the same asm name. There may be multiple
130 entries for single symbol name during LTO, because symbols are renamed
131 only after partitioning.
133 Because inline clones are kept in the assembler name has, they also produce
134 duplicate entries.
136 There are also several long standing bugs where frontends and builtin
137 code produce duplicated decls. */
138 symtab_node *next_sharing_asm_name;
139 symtab_node *previous_sharing_asm_name;
141 /* Circular list of nodes in the same comdat group if non-NULL. */
142 symtab_node *same_comdat_group;
144 /* Return comdat group. */
145 tree get_comdat_group ()
147 return comdat_group_;
150 tree get_comdat_group_id ()
152 if (comdat_group_ && TREE_CODE (comdat_group_) != IDENTIFIER_NODE)
153 comdat_group_ = DECL_ASSEMBLER_NAME (comdat_group_);
154 return comdat_group_;
157 /* Set comdat group. */
158 void set_comdat_group (tree group)
160 comdat_group_ = group;
163 /* Vectors of referring and referenced entities. */
164 struct ipa_ref_list ref_list;
166 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
167 depending to what was known to frontend on the creation time.
168 Once alias is resolved, this pointer become NULL. */
169 tree alias_target;
171 /* File stream where this node is being written to. */
172 struct lto_file_decl_data * lto_file_data;
174 PTR GTY ((skip)) aux;
176 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
177 tree comdat_group_;
180 enum availability
182 /* Not yet set by cgraph_function_body_availability. */
183 AVAIL_UNSET,
184 /* Function body/variable initializer is unknown. */
185 AVAIL_NOT_AVAILABLE,
186 /* Function body/variable initializer is known but might be replaced
187 by a different one from other compilation unit and thus needs to
188 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
189 arbitrary side effects on escaping variables and functions, while
190 like AVAILABLE it might access static variables. */
191 AVAIL_OVERWRITABLE,
192 /* Function body/variable initializer is known and will be used in final
193 program. */
194 AVAIL_AVAILABLE,
195 /* Function body/variable initializer is known and all it's uses are explicitly
196 visible within current unit (ie it's address is never taken and it is not
197 exported to other units).
198 Currently used only for functions. */
199 AVAIL_LOCAL
202 /* This is the information that is put into the cgraph local structure
203 to recover a function. */
204 struct lto_file_decl_data;
206 extern const char * const cgraph_availability_names[];
207 extern const char * const ld_plugin_symbol_resolution_names[];
209 /* Information about thunk, used only for same body aliases. */
211 struct GTY(()) cgraph_thunk_info {
212 /* Information about the thunk. */
213 HOST_WIDE_INT fixed_offset;
214 HOST_WIDE_INT virtual_value;
215 tree alias;
216 bool this_adjusting;
217 bool virtual_offset_p;
218 /* Set to true when alias node is thunk. */
219 bool thunk_p;
222 /* Information about the function collected locally.
223 Available after function is analyzed. */
225 struct GTY(()) cgraph_local_info {
226 /* Set when function function is visible in current compilation unit only
227 and its address is never taken. */
228 unsigned local : 1;
230 /* False when there is something makes versioning impossible. */
231 unsigned versionable : 1;
233 /* False when function calling convention and signature can not be changed.
234 This is the case when __builtin_apply_args is used. */
235 unsigned can_change_signature : 1;
237 /* True when the function has been originally extern inline, but it is
238 redefined now. */
239 unsigned redefined_extern_inline : 1;
241 /* True if the function may enter serial irrevocable mode. */
242 unsigned tm_may_enter_irr : 1;
245 /* Information about the function that needs to be computed globally
246 once compilation is finished. Available only with -funit-at-a-time. */
248 struct GTY(()) cgraph_global_info {
249 /* For inline clones this points to the function they will be
250 inlined into. */
251 struct cgraph_node *inlined_to;
254 /* Information about the function that is propagated by the RTL backend.
255 Available only for functions that has been already assembled. */
257 struct GTY(()) cgraph_rtl_info {
258 unsigned int preferred_incoming_stack_boundary;
260 /* Call unsaved hard registers really used by the corresponding
261 function (including ones used by functions called by the
262 function). */
263 HARD_REG_SET function_used_regs;
264 /* Set if function_used_regs is valid. */
265 unsigned function_used_regs_valid: 1;
268 /* Represent which DECL tree (or reference to such tree)
269 will be replaced by another tree while versioning. */
270 struct GTY(()) ipa_replace_map
272 /* The tree that will be replaced. */
273 tree old_tree;
274 /* The new (replacing) tree. */
275 tree new_tree;
276 /* Parameter number to replace, when old_tree is NULL. */
277 int parm_num;
278 /* True when a substitution should be done, false otherwise. */
279 bool replace_p;
280 /* True when we replace a reference to old_tree. */
281 bool ref_p;
283 typedef struct ipa_replace_map *ipa_replace_map_p;
285 struct GTY(()) cgraph_clone_info
287 vec<ipa_replace_map_p, va_gc> *tree_map;
288 bitmap args_to_skip;
289 bitmap combined_args_to_skip;
292 enum cgraph_simd_clone_arg_type
294 SIMD_CLONE_ARG_TYPE_VECTOR,
295 SIMD_CLONE_ARG_TYPE_UNIFORM,
296 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
297 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
298 SIMD_CLONE_ARG_TYPE_MASK
301 /* Function arguments in the original function of a SIMD clone.
302 Supplementary data for `struct simd_clone'. */
304 struct GTY(()) cgraph_simd_clone_arg {
305 /* Original function argument as it originally existed in
306 DECL_ARGUMENTS. */
307 tree orig_arg;
309 /* orig_arg's function (or for extern functions type from
310 TYPE_ARG_TYPES). */
311 tree orig_type;
313 /* If argument is a vector, this holds the vector version of
314 orig_arg that after adjusting the argument types will live in
315 DECL_ARGUMENTS. Otherwise, this is NULL.
317 This basically holds:
318 vector(simdlen) __typeof__(orig_arg) new_arg. */
319 tree vector_arg;
321 /* vector_arg's type (or for extern functions new vector type. */
322 tree vector_type;
324 /* If argument is a vector, this holds the array where the simd
325 argument is held while executing the simd clone function. This
326 is a local variable in the cloned function. Its content is
327 copied from vector_arg upon entry to the clone.
329 This basically holds:
330 __typeof__(orig_arg) simd_array[simdlen]. */
331 tree simd_array;
333 /* A SIMD clone's argument can be either linear (constant or
334 variable), uniform, or vector. */
335 enum cgraph_simd_clone_arg_type arg_type;
337 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
338 the constant linear step, if arg_type is
339 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
340 the uniform argument holding the step, otherwise 0. */
341 HOST_WIDE_INT linear_step;
343 /* Variable alignment if available, otherwise 0. */
344 unsigned int alignment;
347 /* Specific data for a SIMD function clone. */
349 struct GTY(()) cgraph_simd_clone {
350 /* Number of words in the SIMD lane associated with this clone. */
351 unsigned int simdlen;
353 /* Number of annotated function arguments in `args'. This is
354 usually the number of named arguments in FNDECL. */
355 unsigned int nargs;
357 /* Max hardware vector size in bits for integral vectors. */
358 unsigned int vecsize_int;
360 /* Max hardware vector size in bits for floating point vectors. */
361 unsigned int vecsize_float;
363 /* The mangling character for a given vector size. This is is used
364 to determine the ISA mangling bit as specified in the Intel
365 Vector ABI. */
366 unsigned char vecsize_mangle;
368 /* True if this is the masked, in-branch version of the clone,
369 otherwise false. */
370 unsigned int inbranch : 1;
372 /* True if this is a Cilk Plus variant. */
373 unsigned int cilk_elemental : 1;
375 /* Doubly linked list of SIMD clones. */
376 struct cgraph_node *prev_clone, *next_clone;
378 /* Original cgraph node the SIMD clones were created for. */
379 struct cgraph_node *origin;
381 /* Annotated function arguments for the original function. */
382 struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
386 /* The cgraph data structure.
387 Each function decl has assigned cgraph_node listing callees and callers. */
389 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
390 public:
391 struct cgraph_edge *callees;
392 struct cgraph_edge *callers;
393 /* List of edges representing indirect calls with a yet undetermined
394 callee. */
395 struct cgraph_edge *indirect_calls;
396 /* For nested functions points to function the node is nested in. */
397 struct cgraph_node *origin;
398 /* Points to first nested function, if any. */
399 struct cgraph_node *nested;
400 /* Pointer to the next function with same origin, if any. */
401 struct cgraph_node *next_nested;
402 /* Pointer to the next clone. */
403 struct cgraph_node *next_sibling_clone;
404 struct cgraph_node *prev_sibling_clone;
405 struct cgraph_node *clones;
406 struct cgraph_node *clone_of;
407 /* For functions with many calls sites it holds map from call expression
408 to the edge to speed up cgraph_edge function. */
409 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
410 /* Declaration node used to be clone of. */
411 tree former_clone_of;
413 /* If this is a SIMD clone, this points to the SIMD specific
414 information for it. */
415 struct cgraph_simd_clone *simdclone;
416 /* If this function has SIMD clones, this points to the first clone. */
417 struct cgraph_node *simd_clones;
419 /* Interprocedural passes scheduled to have their transform functions
420 applied next time we execute local pass on them. We maintain it
421 per-function in order to allow IPA passes to introduce new functions. */
422 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
424 struct cgraph_local_info local;
425 struct cgraph_global_info global;
426 struct cgraph_rtl_info rtl;
427 struct cgraph_clone_info clone;
428 struct cgraph_thunk_info thunk;
430 /* Expected number of executions: calculated in profile.c. */
431 gcov_type count;
432 /* How to scale counts at materialization time; used to merge
433 LTO units with different number of profile runs. */
434 int count_materialization_scale;
435 /* Unique id of the node. */
436 int uid;
437 /* ID assigned by the profiling. */
438 unsigned int profile_id;
439 /* Time profiler: first run of function. */
440 int tp_first_run;
442 /* Set when decl is an abstract function pointed to by the
443 ABSTRACT_DECL_ORIGIN of a reachable function. */
444 unsigned used_as_abstract_origin : 1;
445 /* Set once the function is lowered (i.e. its CFG is built). */
446 unsigned lowered : 1;
447 /* Set once the function has been instantiated and its callee
448 lists created. */
449 unsigned process : 1;
450 /* How commonly executed the node is. Initialized during branch
451 probabilities pass. */
452 ENUM_BITFIELD (node_frequency) frequency : 2;
453 /* True when function can only be called at startup (from static ctor). */
454 unsigned only_called_at_startup : 1;
455 /* True when function can only be called at startup (from static dtor). */
456 unsigned only_called_at_exit : 1;
457 /* True when function is the transactional clone of a function which
458 is called only from inside transactions. */
459 /* ?? We should be able to remove this. We have enough bits in
460 cgraph to calculate it. */
461 unsigned tm_clone : 1;
462 /* True if this decl is a dispatcher for function versions. */
463 unsigned dispatcher_function : 1;
464 /* True if this decl calls a COMDAT-local function. This is set up in
465 compute_inline_parameters and inline_call. */
466 unsigned calls_comdat_local : 1;
470 typedef struct cgraph_node *cgraph_node_ptr;
473 /* Function Multiversioning info. */
474 struct GTY(()) cgraph_function_version_info {
475 /* The cgraph_node for which the function version info is stored. */
476 struct cgraph_node *this_node;
477 /* Chains all the semantically identical function versions. The
478 first function in this chain is the version_info node of the
479 default function. */
480 struct cgraph_function_version_info *prev;
481 /* If this version node corresponds to a dispatcher for function
482 versions, this points to the version info node of the default
483 function, the first node in the chain. */
484 struct cgraph_function_version_info *next;
485 /* If this node corresponds to a function version, this points
486 to the dispatcher function decl, which is the function that must
487 be called to execute the right function version at run-time.
489 If this cgraph node is a dispatcher (if dispatcher_function is
490 true, in the cgraph_node struct) for function versions, this
491 points to resolver function, which holds the function body of the
492 dispatcher. The dispatcher decl is an alias to the resolver
493 function decl. */
494 tree dispatcher_resolver;
497 /* Get the cgraph_function_version_info node corresponding to node. */
498 struct cgraph_function_version_info *
499 get_cgraph_node_version (struct cgraph_node *node);
501 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
502 corresponding to cgraph_node NODE. */
503 struct cgraph_function_version_info *
504 insert_new_cgraph_node_version (struct cgraph_node *node);
506 /* Record that DECL1 and DECL2 are semantically identical function
507 versions. */
508 void record_function_versions (tree decl1, tree decl2);
510 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
511 DECL is a duplicate declaration. */
512 void delete_function_version (tree decl);
514 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
515 can appear in multiple sets. */
516 struct cgraph_node_set_def
518 struct pointer_map_t *map;
519 vec<cgraph_node_ptr> nodes;
522 class varpool_node;
523 typedef varpool_node *varpool_node_ptr;
526 /* A varpool node set is a collection of varpool nodes. A varpool node
527 can appear in multiple sets. */
528 struct varpool_node_set_def
530 struct pointer_map_t * map;
531 vec<varpool_node_ptr> nodes;
534 typedef struct cgraph_node_set_def *cgraph_node_set;
537 typedef struct varpool_node_set_def *varpool_node_set;
540 /* Iterator structure for cgraph node sets. */
541 struct cgraph_node_set_iterator
543 cgraph_node_set set;
544 unsigned index;
547 /* Iterator structure for varpool node sets. */
548 struct varpool_node_set_iterator
550 varpool_node_set set;
551 unsigned index;
554 #define DEFCIFCODE(code, type, string) CIF_ ## code,
555 /* Reasons for inlining failures. */
556 enum cgraph_inline_failed_t {
557 #include "cif-code.def"
558 CIF_N_REASONS
561 enum cgraph_inline_failed_type_t
563 CIF_FINAL_NORMAL = 0,
564 CIF_FINAL_ERROR
567 /* Structure containing additional information about an indirect call. */
569 struct GTY(()) cgraph_indirect_call_info
571 /* When polymorphic is set, this field contains offset where the object which
572 was actually used in the polymorphic resides within a larger structure.
573 If agg_contents is set, the field contains the offset within the aggregate
574 from which the address to call was loaded. */
575 HOST_WIDE_INT offset;
576 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
577 HOST_WIDE_INT otr_token;
578 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
579 tree otr_type, outer_type;
580 /* Index of the parameter that is called. */
581 int param_index;
582 /* ECF flags determined from the caller. */
583 int ecf_flags;
584 /* Profile_id of common target obtrained from profile. */
585 int common_target_id;
586 /* Probability that call will land in function with COMMON_TARGET_ID. */
587 int common_target_probability;
589 /* Set when the call is a virtual call with the parameter being the
590 associated object pointer rather than a simple direct call. */
591 unsigned polymorphic : 1;
592 /* Set when the call is a call of a pointer loaded from contents of an
593 aggregate at offset. */
594 unsigned agg_contents : 1;
595 /* Set when this is a call through a member pointer. */
596 unsigned member_ptr : 1;
597 /* When the previous bit is set, this one determines whether the destination
598 is loaded from a parameter passed by reference. */
599 unsigned by_ref : 1;
600 unsigned int maybe_in_construction : 1;
601 unsigned int maybe_derived_type : 1;
604 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
605 /* Expected number of executions: calculated in profile.c. */
606 gcov_type count;
607 struct cgraph_node *caller;
608 struct cgraph_node *callee;
609 struct cgraph_edge *prev_caller;
610 struct cgraph_edge *next_caller;
611 struct cgraph_edge *prev_callee;
612 struct cgraph_edge *next_callee;
613 gimple call_stmt;
614 /* Additional information about an indirect call. Not cleared when an edge
615 becomes direct. */
616 struct cgraph_indirect_call_info *indirect_info;
617 PTR GTY ((skip (""))) aux;
618 /* When equal to CIF_OK, inline this call. Otherwise, points to the
619 explanation why function was not inlined. */
620 enum cgraph_inline_failed_t inline_failed;
621 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
622 when the function is serialized in. */
623 unsigned int lto_stmt_uid;
624 /* Expected frequency of executions within the function.
625 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
626 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
627 int frequency;
628 /* Unique id of the edge. */
629 int uid;
630 /* Whether this edge was made direct by indirect inlining. */
631 unsigned int indirect_inlining_edge : 1;
632 /* Whether this edge describes an indirect call with an undetermined
633 callee. */
634 unsigned int indirect_unknown_callee : 1;
635 /* Whether this edge is still a dangling */
636 /* True if the corresponding CALL stmt cannot be inlined. */
637 unsigned int call_stmt_cannot_inline_p : 1;
638 /* Can this call throw externally? */
639 unsigned int can_throw_external : 1;
640 /* Edges with SPECULATIVE flag represents indirect calls that was
641 speculatively turned into direct (i.e. by profile feedback).
642 The final code sequence will have form:
644 if (call_target == expected_fn)
645 expected_fn ();
646 else
647 call_target ();
649 Every speculative call is represented by three components attached
650 to a same call statement:
651 1) a direct call (to expected_fn)
652 2) an indirect call (to call_target)
653 3) a IPA_REF_ADDR refrence to expected_fn.
655 Optimizers may later redirect direct call to clone, so 1) and 3)
656 do not need to necesarily agree with destination. */
657 unsigned int speculative : 1;
660 #define CGRAPH_FREQ_BASE 1000
661 #define CGRAPH_FREQ_MAX 100000
663 typedef struct cgraph_edge *cgraph_edge_p;
666 /* The varpool data structure.
667 Each static variable decl has assigned varpool_node. */
669 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
670 public:
671 /* Set when variable is scheduled to be assembled. */
672 unsigned output : 1;
674 /* Set if the variable is dynamically initialized, except for
675 function local statics. */
676 unsigned dynamically_initialized : 1;
679 /* Every top level asm statement is put into a asm_node. */
681 struct GTY(()) asm_node {
682 /* Next asm node. */
683 struct asm_node *next;
684 /* String for this asm node. */
685 tree asm_str;
686 /* Ordering of all cgraph nodes. */
687 int order;
690 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
692 template <>
693 template <>
694 inline bool
695 is_a_helper <cgraph_node *>::test (symtab_node *p)
697 return p->type == SYMTAB_FUNCTION;
700 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
702 template <>
703 template <>
704 inline bool
705 is_a_helper <varpool_node *>::test (symtab_node *p)
707 return p->type == SYMTAB_VARIABLE;
710 extern GTY(()) symtab_node *symtab_nodes;
711 extern GTY(()) int cgraph_n_nodes;
712 extern GTY(()) int cgraph_max_uid;
713 extern GTY(()) int cgraph_edge_max_uid;
714 extern bool cgraph_global_info_ready;
715 enum cgraph_state
717 /* Frontend is parsing and finalizing functions. */
718 CGRAPH_STATE_PARSING,
719 /* Callgraph is being constructed. It is safe to add new functions. */
720 CGRAPH_STATE_CONSTRUCTION,
721 /* Callgraph is being at LTO time. */
722 CGRAPH_LTO_STREAMING,
723 /* Callgraph is built and IPA passes are being run. */
724 CGRAPH_STATE_IPA,
725 /* Callgraph is built and all functions are transformed to SSA form. */
726 CGRAPH_STATE_IPA_SSA,
727 /* Functions are now ordered and being passed to RTL expanders. */
728 CGRAPH_STATE_EXPANSION,
729 /* All cgraph expansion is done. */
730 CGRAPH_STATE_FINISHED
732 extern enum cgraph_state cgraph_state;
733 extern bool cgraph_function_flags_ready;
734 extern cgraph_node_set cgraph_new_nodes;
736 extern GTY(()) struct asm_node *asm_nodes;
737 extern GTY(()) int symtab_order;
738 extern bool cpp_implicit_aliases_done;
740 /* Classifcation of symbols WRT partitioning. */
741 enum symbol_partitioning_class
743 /* External declarations are ignored by partitioning algorithms and they are
744 added into the boundary later via compute_ltrans_boundary. */
745 SYMBOL_EXTERNAL,
746 /* Partitioned symbols are pur into one of partitions. */
747 SYMBOL_PARTITION,
748 /* Duplicated symbols (such as comdat or constant pool references) are
749 copied into every node needing them via add_symbol_to_partition. */
750 SYMBOL_DUPLICATE
754 /* In symtab.c */
755 void symtab_register_node (symtab_node *);
756 void symtab_unregister_node (symtab_node *);
757 void symtab_remove_from_same_comdat_group (symtab_node *);
758 void symtab_remove_node (symtab_node *);
759 symtab_node *symtab_node_for_asm (const_tree asmname);
760 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
761 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
762 void dump_symtab (FILE *);
763 void debug_symtab (void);
764 void dump_symtab_node (FILE *, symtab_node *);
765 void debug_symtab_node (symtab_node *);
766 void dump_symtab_base (FILE *, symtab_node *);
767 void verify_symtab (void);
768 void verify_symtab_node (symtab_node *);
769 bool verify_symtab_base (symtab_node *);
770 bool symtab_used_from_object_file_p (symtab_node *);
771 void symtab_make_decl_local (tree);
772 symtab_node *symtab_alias_ultimate_target (symtab_node *,
773 enum availability *avail = NULL);
774 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
775 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
776 bool symtab_for_node_and_aliases (symtab_node *,
777 bool (*) (symtab_node *, void *),
778 void *,
779 bool);
780 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
781 enum availability symtab_node_availability (symtab_node *);
782 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
783 enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
785 /* In cgraph.c */
786 void dump_cgraph (FILE *);
787 void debug_cgraph (void);
788 void dump_cgraph_node (FILE *, struct cgraph_node *);
789 void debug_cgraph_node (struct cgraph_node *);
790 void cgraph_remove_edge (struct cgraph_edge *);
791 void cgraph_remove_node (struct cgraph_node *);
792 void cgraph_release_function_body (struct cgraph_node *);
793 void release_function_body (tree);
794 void cgraph_node_remove_callees (struct cgraph_node *node);
795 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
796 struct cgraph_node *,
797 gimple, gcov_type, int);
798 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
799 int, gcov_type, int);
800 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
801 struct cgraph_node * cgraph_create_node (tree);
802 struct cgraph_node * cgraph_create_empty_node (void);
803 struct cgraph_node * cgraph_get_create_node (tree);
804 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
805 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
806 HOST_WIDE_INT, tree, tree);
807 struct cgraph_node *cgraph_node_for_asm (tree);
808 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
809 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
810 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
811 struct cgraph_local_info *cgraph_local_info (tree);
812 struct cgraph_global_info *cgraph_global_info (tree);
813 struct cgraph_rtl_info *cgraph_rtl_info (tree);
814 struct cgraph_node *cgraph_create_function_alias (tree, tree);
815 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
816 struct cgraph_node *);
817 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
818 struct cgraph_edge *);
820 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
821 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
822 bool cgraph_only_called_directly_p (struct cgraph_node *);
824 bool cgraph_function_possibly_inlined_p (tree);
825 void cgraph_unnest_node (struct cgraph_node *);
827 enum availability cgraph_function_body_availability (struct cgraph_node *);
828 void cgraph_add_new_function (tree, bool);
829 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
830 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
832 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
833 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
834 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
835 bool cgraph_node_cannot_return (struct cgraph_node *);
836 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
837 bool cgraph_will_be_removed_from_program_if_no_direct_calls
838 (struct cgraph_node *node);
839 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
840 (struct cgraph_node *node);
841 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
842 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
843 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
844 bool (*) (struct cgraph_node *, void *),
845 void *,
846 bool);
847 bool cgraph_for_node_and_aliases (struct cgraph_node *,
848 bool (*) (struct cgraph_node *, void *),
849 void *, bool);
850 vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
851 void verify_cgraph (void);
852 void verify_cgraph_node (struct cgraph_node *);
853 void cgraph_mark_address_taken_node (struct cgraph_node *);
855 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
856 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
857 typedef void (*varpool_node_hook)(varpool_node *, void *);
858 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
859 void *);
860 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
861 void *);
862 struct cgraph_edge_hook_list;
863 struct cgraph_node_hook_list;
864 struct varpool_node_hook_list;
865 struct cgraph_2edge_hook_list;
866 struct cgraph_2node_hook_list;
867 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
868 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
869 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
870 void *);
871 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
872 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
873 void *);
874 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
875 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
876 void *);
877 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
878 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
879 void *);
880 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
881 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
882 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
883 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
884 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
885 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
886 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
887 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
888 enum availability *avail = NULL);
889 bool cgraph_get_body (struct cgraph_node *node);
890 struct cgraph_edge *
891 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
892 struct cgraph_node *,
893 gcov_type, int);
894 void cgraph_speculative_call_info (struct cgraph_edge *,
895 struct cgraph_edge *&,
896 struct cgraph_edge *&,
897 struct ipa_ref *&);
898 extern bool gimple_check_call_matching_types (gimple, tree, bool);
900 /* In cgraphunit.c */
901 struct asm_node *add_asm_node (tree);
902 extern FILE *cgraph_dump_file;
903 void cgraph_finalize_function (tree, bool);
904 void finalize_compilation_unit (void);
905 void compile (void);
906 void init_cgraph (void);
907 void cgraph_process_new_functions (void);
908 void cgraph_process_same_body_aliases (void);
909 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
910 /* Initialize datastructures so DECL is a function in lowered gimple form.
911 IN_SSA is true if the gimple is in SSA. */
912 basic_block init_lowered_empty_function (tree, bool);
913 void cgraph_reset_node (struct cgraph_node *);
914 bool expand_thunk (struct cgraph_node *, bool, bool);
915 void cgraph_make_wrapper (struct cgraph_node *source,
916 struct cgraph_node *target);
918 /* In cgraphclones.c */
920 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
921 struct cgraph_node *, gimple,
922 unsigned, gcov_type, int, bool);
923 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
924 int, bool, vec<cgraph_edge_p>,
925 bool, struct cgraph_node *, bitmap);
926 tree clone_function_name (tree decl, const char *);
927 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
928 vec<cgraph_edge_p>,
929 vec<ipa_replace_map_p, va_gc> *tree_map,
930 bitmap args_to_skip,
931 const char *clone_name);
932 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
933 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
934 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
935 bool update_speculative = true);
936 void cgraph_create_edge_including_clones (struct cgraph_node *,
937 struct cgraph_node *,
938 gimple, gimple, gcov_type, int,
939 cgraph_inline_failed_t);
940 void cgraph_materialize_all_clones (void);
941 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
942 tree, vec<cgraph_edge_p>, bitmap);
943 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
944 vec<cgraph_edge_p>,
945 vec<ipa_replace_map_p, va_gc> *,
946 bitmap, bool, bitmap,
947 basic_block, const char *);
948 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
949 bool, bitmap, bool, bitmap, basic_block);
950 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
952 /* In cgraphbuild.c */
953 unsigned int rebuild_cgraph_edges (void);
954 void cgraph_rebuild_references (void);
955 int compute_call_stmt_bb_frequency (tree, basic_block bb);
956 void record_references_in_initializer (tree, bool);
957 void ipa_record_stmt_references (struct cgraph_node *, gimple);
959 /* In ipa.c */
960 bool symtab_remove_unreachable_nodes (bool, FILE *);
961 cgraph_node_set cgraph_node_set_new (void);
962 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
963 struct cgraph_node *);
964 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
965 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
966 void dump_cgraph_node_set (FILE *, cgraph_node_set);
967 void debug_cgraph_node_set (cgraph_node_set);
968 void free_cgraph_node_set (cgraph_node_set);
969 void cgraph_build_static_cdtor (char which, tree body, int priority);
971 varpool_node_set varpool_node_set_new (void);
972 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
973 varpool_node *);
974 void varpool_node_set_add (varpool_node_set, varpool_node *);
975 void varpool_node_set_remove (varpool_node_set, varpool_node *);
976 void dump_varpool_node_set (FILE *, varpool_node_set);
977 void debug_varpool_node_set (varpool_node_set);
978 void free_varpool_node_set (varpool_node_set);
979 void ipa_discover_readonly_nonaddressable_vars (void);
980 bool varpool_externally_visible_p (varpool_node *);
982 /* In ipa-visibility.c */
983 bool cgraph_local_node_p (struct cgraph_node *);
984 bool address_taken_from_non_vtable_p (symtab_node *node);
987 /* In predict.c */
988 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
989 bool cgraph_optimize_for_size_p (struct cgraph_node *);
991 /* In varpool.c */
992 varpool_node *varpool_create_empty_node (void);
993 varpool_node *varpool_node_for_decl (tree);
994 varpool_node *varpool_node_for_asm (tree asmname);
995 void varpool_mark_needed_node (varpool_node *);
996 void debug_varpool (void);
997 void dump_varpool (FILE *);
998 void dump_varpool_node (FILE *, varpool_node *);
1000 void varpool_finalize_decl (tree);
1001 enum availability cgraph_variable_initializer_availability (varpool_node *);
1002 void cgraph_make_node_local (struct cgraph_node *);
1003 bool cgraph_node_can_be_local_p (struct cgraph_node *);
1006 void varpool_remove_node (varpool_node *node);
1007 void varpool_finalize_named_section_flags (varpool_node *node);
1008 bool varpool_output_variables (void);
1009 bool varpool_assemble_decl (varpool_node *node);
1010 void varpool_analyze_node (varpool_node *);
1011 varpool_node * varpool_extra_name_alias (tree, tree);
1012 varpool_node * varpool_create_variable_alias (tree, tree);
1013 void varpool_reset_queue (void);
1014 tree ctor_for_folding (tree);
1015 bool varpool_for_node_and_aliases (varpool_node *,
1016 bool (*) (varpool_node *, void *),
1017 void *, bool);
1018 void varpool_add_new_variable (tree);
1019 void symtab_initialize_asm_name_hash (void);
1020 void symtab_prevail_in_asm_name_hash (symtab_node *node);
1021 void varpool_remove_initializer (varpool_node *);
1023 /* In cgraph.c */
1024 extern void change_decl_assembler_name (tree, tree);
1026 /* Return symbol table node associated with DECL, if any,
1027 and NULL otherwise. */
1029 static inline symtab_node *
1030 symtab_get_node (const_tree decl)
1032 #ifdef ENABLE_CHECKING
1033 /* Check that we are called for sane type of object - functions
1034 and static or external variables. */
1035 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
1036 || (TREE_CODE (decl) == VAR_DECL
1037 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1038 || in_lto_p)));
1039 /* Check that the mapping is sane - perhaps this check can go away,
1040 but at the moment frontends tends to corrupt the mapping by calling
1041 memcpy/memset on the tree nodes. */
1042 gcc_checking_assert (!decl->decl_with_vis.symtab_node
1043 || decl->decl_with_vis.symtab_node->decl == decl);
1044 #endif
1045 return decl->decl_with_vis.symtab_node;
1048 /* Return callgraph node for given symbol and check it is a function. */
1049 static inline struct cgraph_node *
1050 cgraph (symtab_node *node)
1052 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
1053 return (struct cgraph_node *)node;
1056 /* Return varpool node for given symbol and check it is a variable. */
1057 static inline varpool_node *
1058 varpool (symtab_node *node)
1060 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
1061 return (varpool_node *)node;
1064 /* Return callgraph node for given symbol and check it is a function. */
1065 static inline struct cgraph_node *
1066 cgraph_get_node (const_tree decl)
1068 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1069 return cgraph (symtab_get_node (decl));
1072 /* Return varpool node for given symbol and check it is a function. */
1073 static inline varpool_node *
1074 varpool_get_node (const_tree decl)
1076 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1077 return varpool (symtab_get_node (decl));
1080 /* Walk all symbols. */
1081 #define FOR_EACH_SYMBOL(node) \
1082 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1084 /* Return first static symbol with definition. */
1085 static inline symtab_node *
1086 symtab_first_defined_symbol (void)
1088 symtab_node *node;
1090 for (node = symtab_nodes; node; node = node->next)
1091 if (node->definition)
1092 return node;
1094 return NULL;
1097 /* Return next reachable static symbol with initializer after NODE. */
1098 static inline symtab_node *
1099 symtab_next_defined_symbol (symtab_node *node)
1101 symtab_node *node1 = node->next;
1103 for (; node1; node1 = node1->next)
1104 if (node1->definition)
1105 return node1;
1107 return NULL;
1109 /* Walk all symbols with definitions in current unit. */
1110 #define FOR_EACH_DEFINED_SYMBOL(node) \
1111 for ((node) = symtab_first_defined_symbol (); (node); \
1112 (node) = symtab_next_defined_symbol (node))
1114 /* Return first variable. */
1115 static inline varpool_node *
1116 varpool_first_variable (void)
1118 symtab_node *node;
1119 for (node = symtab_nodes; node; node = node->next)
1120 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1121 return vnode;
1122 return NULL;
1125 /* Return next variable after NODE. */
1126 static inline varpool_node *
1127 varpool_next_variable (varpool_node *node)
1129 symtab_node *node1 = node->next;
1130 for (; node1; node1 = node1->next)
1131 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1132 return vnode1;
1133 return NULL;
1135 /* Walk all variables. */
1136 #define FOR_EACH_VARIABLE(node) \
1137 for ((node) = varpool_first_variable (); \
1138 (node); \
1139 (node) = varpool_next_variable ((node)))
1141 /* Return first static variable with initializer. */
1142 static inline varpool_node *
1143 varpool_first_static_initializer (void)
1145 symtab_node *node;
1146 for (node = symtab_nodes; node; node = node->next)
1148 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1149 if (vnode && DECL_INITIAL (node->decl))
1150 return vnode;
1152 return NULL;
1155 /* Return next static variable with initializer after NODE. */
1156 static inline varpool_node *
1157 varpool_next_static_initializer (varpool_node *node)
1159 symtab_node *node1 = node->next;
1160 for (; node1; node1 = node1->next)
1162 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1163 if (vnode1 && DECL_INITIAL (node1->decl))
1164 return vnode1;
1166 return NULL;
1169 /* Walk all static variables with initializer set. */
1170 #define FOR_EACH_STATIC_INITIALIZER(node) \
1171 for ((node) = varpool_first_static_initializer (); (node); \
1172 (node) = varpool_next_static_initializer (node))
1174 /* Return first static variable with definition. */
1175 static inline varpool_node *
1176 varpool_first_defined_variable (void)
1178 symtab_node *node;
1179 for (node = symtab_nodes; node; node = node->next)
1181 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1182 if (vnode && vnode->definition)
1183 return vnode;
1185 return NULL;
1188 /* Return next static variable with definition after NODE. */
1189 static inline varpool_node *
1190 varpool_next_defined_variable (varpool_node *node)
1192 symtab_node *node1 = node->next;
1193 for (; node1; node1 = node1->next)
1195 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1196 if (vnode1 && vnode1->definition)
1197 return vnode1;
1199 return NULL;
1201 /* Walk all variables with definitions in current unit. */
1202 #define FOR_EACH_DEFINED_VARIABLE(node) \
1203 for ((node) = varpool_first_defined_variable (); (node); \
1204 (node) = varpool_next_defined_variable (node))
1206 /* Return first function with body defined. */
1207 static inline struct cgraph_node *
1208 cgraph_first_defined_function (void)
1210 symtab_node *node;
1211 for (node = symtab_nodes; node; node = node->next)
1213 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1214 if (cn && cn->definition)
1215 return cn;
1217 return NULL;
1220 /* Return next function with body defined after NODE. */
1221 static inline struct cgraph_node *
1222 cgraph_next_defined_function (struct cgraph_node *node)
1224 symtab_node *node1 = node->next;
1225 for (; node1; node1 = node1->next)
1227 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1228 if (cn1 && cn1->definition)
1229 return cn1;
1231 return NULL;
1234 /* Walk all functions with body defined. */
1235 #define FOR_EACH_DEFINED_FUNCTION(node) \
1236 for ((node) = cgraph_first_defined_function (); (node); \
1237 (node) = cgraph_next_defined_function ((node)))
1239 /* Return first function. */
1240 static inline struct cgraph_node *
1241 cgraph_first_function (void)
1243 symtab_node *node;
1244 for (node = symtab_nodes; node; node = node->next)
1245 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1246 return cn;
1247 return NULL;
1250 /* Return next function. */
1251 static inline struct cgraph_node *
1252 cgraph_next_function (struct cgraph_node *node)
1254 symtab_node *node1 = node->next;
1255 for (; node1; node1 = node1->next)
1256 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1257 return cn1;
1258 return NULL;
1260 /* Walk all functions. */
1261 #define FOR_EACH_FUNCTION(node) \
1262 for ((node) = cgraph_first_function (); (node); \
1263 (node) = cgraph_next_function ((node)))
1265 /* Return true when NODE is a function with Gimple body defined
1266 in current unit. Functions can also be define externally or they
1267 can be thunks with no Gimple representation.
1269 Note that at WPA stage, the function body may not be present in memory. */
1271 static inline bool
1272 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1274 return node->definition && !node->thunk.thunk_p && !node->alias;
1277 /* Return first function with body defined. */
1278 static inline struct cgraph_node *
1279 cgraph_first_function_with_gimple_body (void)
1281 symtab_node *node;
1282 for (node = symtab_nodes; node; node = node->next)
1284 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1285 if (cn && cgraph_function_with_gimple_body_p (cn))
1286 return cn;
1288 return NULL;
1291 /* Return next reachable static variable with initializer after NODE. */
1292 static inline struct cgraph_node *
1293 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1295 symtab_node *node1 = node->next;
1296 for (; node1; node1 = node1->next)
1298 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1299 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1300 return cn1;
1302 return NULL;
1305 /* Walk all functions with body defined. */
1306 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1307 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1308 (node) = cgraph_next_function_with_gimple_body (node))
1310 /* Create a new static variable of type TYPE. */
1311 tree add_new_static_var (tree type);
1313 /* Return true if iterator CSI points to nothing. */
1314 static inline bool
1315 csi_end_p (cgraph_node_set_iterator csi)
1317 return csi.index >= csi.set->nodes.length ();
1320 /* Advance iterator CSI. */
1321 static inline void
1322 csi_next (cgraph_node_set_iterator *csi)
1324 csi->index++;
1327 /* Return the node pointed to by CSI. */
1328 static inline struct cgraph_node *
1329 csi_node (cgraph_node_set_iterator csi)
1331 return csi.set->nodes[csi.index];
1334 /* Return an iterator to the first node in SET. */
1335 static inline cgraph_node_set_iterator
1336 csi_start (cgraph_node_set set)
1338 cgraph_node_set_iterator csi;
1340 csi.set = set;
1341 csi.index = 0;
1342 return csi;
1345 /* Return true if SET contains NODE. */
1346 static inline bool
1347 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1349 cgraph_node_set_iterator csi;
1350 csi = cgraph_node_set_find (set, node);
1351 return !csi_end_p (csi);
1354 /* Return number of nodes in SET. */
1355 static inline size_t
1356 cgraph_node_set_size (cgraph_node_set set)
1358 return set->nodes.length ();
1361 /* Return true if iterator VSI points to nothing. */
1362 static inline bool
1363 vsi_end_p (varpool_node_set_iterator vsi)
1365 return vsi.index >= vsi.set->nodes.length ();
1368 /* Advance iterator VSI. */
1369 static inline void
1370 vsi_next (varpool_node_set_iterator *vsi)
1372 vsi->index++;
1375 /* Return the node pointed to by VSI. */
1376 static inline varpool_node *
1377 vsi_node (varpool_node_set_iterator vsi)
1379 return vsi.set->nodes[vsi.index];
1382 /* Return an iterator to the first node in SET. */
1383 static inline varpool_node_set_iterator
1384 vsi_start (varpool_node_set set)
1386 varpool_node_set_iterator vsi;
1388 vsi.set = set;
1389 vsi.index = 0;
1390 return vsi;
1393 /* Return true if SET contains NODE. */
1394 static inline bool
1395 varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
1397 varpool_node_set_iterator vsi;
1398 vsi = varpool_node_set_find (set, node);
1399 return !vsi_end_p (vsi);
1402 /* Return number of nodes in SET. */
1403 static inline size_t
1404 varpool_node_set_size (varpool_node_set set)
1406 return set->nodes.length ();
1409 /* Uniquize all constants that appear in memory.
1410 Each constant in memory thus far output is recorded
1411 in `const_desc_table'. */
1413 struct GTY(()) constant_descriptor_tree {
1414 /* A MEM for the constant. */
1415 rtx rtl;
1417 /* The value of the constant. */
1418 tree value;
1420 /* Hash of value. Computing the hash from value each time
1421 hashfn is called can't work properly, as that means recursive
1422 use of the hash table during hash table expansion. */
1423 hashval_t hash;
1426 /* Return true if set is nonempty. */
1427 static inline bool
1428 cgraph_node_set_nonempty_p (cgraph_node_set set)
1430 return !set->nodes.is_empty ();
1433 /* Return true if set is nonempty. */
1434 static inline bool
1435 varpool_node_set_nonempty_p (varpool_node_set set)
1437 return !set->nodes.is_empty ();
1440 /* Return true when function NODE is only called directly or it has alias.
1441 i.e. it is not externally visible, address was not taken and
1442 it is not used in any other non-standard way. */
1444 static inline bool
1445 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1447 gcc_assert (!node->global.inlined_to);
1448 return (!node->force_output && !node->address_taken
1449 && !node->used_from_other_partition
1450 && !DECL_VIRTUAL_P (node->decl)
1451 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1452 && !DECL_STATIC_DESTRUCTOR (node->decl)
1453 && !node->externally_visible);
1456 /* Return true when function NODE can be removed from callgraph
1457 if all direct calls are eliminated. */
1459 static inline bool
1460 varpool_can_remove_if_no_refs (varpool_node *node)
1462 if (DECL_EXTERNAL (node->decl))
1463 return true;
1464 return (!node->force_output && !node->used_from_other_partition
1465 && ((DECL_COMDAT (node->decl)
1466 && !node->forced_by_abi
1467 && !symtab_used_from_object_file_p (node))
1468 || !node->externally_visible
1469 || DECL_HAS_VALUE_EXPR_P (node->decl)));
1472 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1473 i.e. if the variable is not externally visible or not used in some magic
1474 way (asm statement or such).
1475 The magic uses are all summarized in force_output flag. */
1477 static inline bool
1478 varpool_all_refs_explicit_p (varpool_node *vnode)
1480 return (vnode->definition
1481 && !vnode->externally_visible
1482 && !vnode->used_from_other_partition
1483 && !vnode->force_output);
1486 /* Constant pool accessor function. */
1487 htab_t constant_pool_htab (void);
1489 /* FIXME: inappropriate dependency of cgraph on IPA. */
1490 #include "ipa-ref-inline.h"
1492 /* Return node that alias N is aliasing. */
1494 static inline symtab_node *
1495 symtab_alias_target (symtab_node *n)
1497 struct ipa_ref *ref;
1498 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1499 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1500 return ref->referred;
1503 static inline struct cgraph_node *
1504 cgraph_alias_target (struct cgraph_node *n)
1506 return dyn_cast <cgraph_node *> (symtab_alias_target (n));
1509 static inline varpool_node *
1510 varpool_alias_target (varpool_node *n)
1512 return dyn_cast <varpool_node *> (symtab_alias_target (n));
1515 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1516 Do not walk through thunks.
1517 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1519 static inline struct cgraph_node *
1520 cgraph_function_or_thunk_node (struct cgraph_node *node,
1521 enum availability *availability = NULL)
1523 struct cgraph_node *n;
1525 n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node,
1526 availability));
1527 if (!n && availability)
1528 *availability = AVAIL_NOT_AVAILABLE;
1529 return n;
1531 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1532 Do not walk through thunks.
1533 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1535 static inline varpool_node *
1536 varpool_variable_node (varpool_node *node,
1537 enum availability *availability = NULL)
1539 varpool_node *n;
1541 if (node)
1542 n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node,
1543 availability));
1544 else
1545 n = NULL;
1547 if (!n && availability)
1548 *availability = AVAIL_NOT_AVAILABLE;
1549 return n;
1552 /* Return true when the edge E represents a direct recursion. */
1553 static inline bool
1554 cgraph_edge_recursive_p (struct cgraph_edge *e)
1556 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1557 if (e->caller->global.inlined_to)
1558 return e->caller->global.inlined_to->decl == callee->decl;
1559 else
1560 return e->caller->decl == callee->decl;
1563 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1564 static inline bool
1565 decl_is_tm_clone (const_tree fndecl)
1567 struct cgraph_node *n = cgraph_get_node (fndecl);
1568 if (n)
1569 return n->tm_clone;
1570 return false;
1573 /* Likewise indicate that a node is needed, i.e. reachable via some
1574 external means. */
1576 static inline void
1577 cgraph_mark_force_output_node (struct cgraph_node *node)
1579 node->force_output = 1;
1580 gcc_checking_assert (!node->global.inlined_to);
1583 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1584 or abstract function kept for debug info purposes only. */
1586 static inline bool
1587 symtab_real_symbol_p (symtab_node *node)
1589 struct cgraph_node *cnode;
1591 if (DECL_ABSTRACT (node->decl))
1592 return false;
1593 if (!is_a <cgraph_node *> (node))
1594 return true;
1595 cnode = cgraph (node);
1596 if (cnode->global.inlined_to)
1597 return false;
1598 return true;
1601 /* Return true if NODE can be discarded by linker from the binary. */
1603 static inline bool
1604 symtab_can_be_discarded (symtab_node *node)
1606 return (DECL_EXTERNAL (node->decl)
1607 || (node->get_comdat_group ()
1608 && node->resolution != LDPR_PREVAILING_DEF
1609 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1610 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1613 /* Return true if NODE is local to a particular COMDAT group, and must not
1614 be named from outside the COMDAT. This is used for C++ decloned
1615 constructors. */
1617 static inline bool
1618 symtab_comdat_local_p (symtab_node *node)
1620 return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1623 /* Return true if ONE and TWO are part of the same COMDAT group. */
1625 static inline bool
1626 symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1628 if (cgraph_node *cn = dyn_cast <cgraph_node *> (one))
1630 if (cn->global.inlined_to)
1631 one = cn->global.inlined_to;
1633 if (cgraph_node *cn = dyn_cast <cgraph_node *> (two))
1635 if (cn->global.inlined_to)
1636 two = cn->global.inlined_to;
1639 return one->get_comdat_group () == two->get_comdat_group ();
1641 #endif /* GCC_CGRAPH_H */