2013-11-13 Christophe Lyon <christophe.lyon@linaro.org>
[official-gcc.git] / gcc / cgraph.h
blobdd99dc830b646286ed1b5335b2cd3496d7e62b74
1 /* Callgraph handling code.
2 Copyright (C) 2003-2013 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 /* Type of the symbol. */
48 ENUM_BITFIELD (symtab_type) type : 8;
50 /* The symbols resolution. */
51 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
53 /*** Flags representing the symbol type. ***/
55 /* True when symbol corresponds to a definition in current unit.
56 set via cgraph_finalize_function or varpool_finalize_decl */
57 unsigned definition : 1;
58 /* True when symbol is an alias.
59 Set by assemble_alias. */
60 unsigned alias : 1;
61 /* True when alias is a weakref. */
62 unsigned weakref : 1;
63 /* C++ frontend produce same body aliases and extra name aliases for
64 virtual functions and vtables that are obviously equivalent.
65 Those aliases are bit special, especially because C++ frontend
66 visibility code is so ugly it can not get them right at first time
67 and their visibility needs to be copied from their "masters" at
68 the end of parsing. */
69 unsigned cpp_implicit_alias : 1;
70 /* Set once the definition was analyzed. The list of references and
71 other properties are built during analysis. */
72 unsigned analyzed : 1;
75 /*** Visibility and linkage flags. ***/
77 /* Set when function is visible by other units. */
78 unsigned externally_visible : 1;
79 /* The symbol will be assumed to be used in an invisiable way (like
80 by an toplevel asm statement). */
81 unsigned force_output : 1;
82 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
83 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
84 to static and it does not inhibit optimization. */
85 unsigned forced_by_abi : 1;
86 /* True when the name is known to be unique and thus it does not need mangling. */
87 unsigned unique_name : 1;
90 /*** WHOPR Partitioning flags.
91 These flags are used at ltrans stage when only part of the callgraph is
92 available. ***/
94 /* Set when variable is used from other LTRANS partition. */
95 unsigned used_from_other_partition : 1;
96 /* Set when function is available in the other LTRANS partition.
97 During WPA output it is used to mark nodes that are present in
98 multiple partitions. */
99 unsigned in_other_partition : 1;
103 /*** other flags. ***/
105 /* Set when symbol has address taken. */
106 unsigned address_taken : 1;
109 /* Ordering of all symtab entries. */
110 int order;
112 /* Declaration representing the symbol. */
113 tree decl;
115 /* Linked list of symbol table entries starting with symtab_nodes. */
116 symtab_node *next;
117 symtab_node *previous;
119 /* Linked list of symbols with the same asm name. There may be multiple
120 entries for single symbol name during LTO, because symbols are renamed
121 only after partitioning.
123 Because inline clones are kept in the assembler name has, they also produce
124 duplicate entries.
126 There are also several long standing bugs where frontends and builtin
127 code produce duplicated decls. */
128 symtab_node *next_sharing_asm_name;
129 symtab_node *previous_sharing_asm_name;
131 /* Circular list of nodes in the same comdat group if non-NULL. */
132 symtab_node *same_comdat_group;
134 /* Vectors of referring and referenced entities. */
135 struct ipa_ref_list ref_list;
137 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
138 depending to what was known to frontend on the creation time.
139 Once alias is resolved, this pointer become NULL. */
140 tree alias_target;
142 /* File stream where this node is being written to. */
143 struct lto_file_decl_data * lto_file_data;
145 PTR GTY ((skip)) aux;
148 enum availability
150 /* Not yet set by cgraph_function_body_availability. */
151 AVAIL_UNSET,
152 /* Function body/variable initializer is unknown. */
153 AVAIL_NOT_AVAILABLE,
154 /* Function body/variable initializer is known but might be replaced
155 by a different one from other compilation unit and thus needs to
156 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
157 arbitrary side effects on escaping variables and functions, while
158 like AVAILABLE it might access static variables. */
159 AVAIL_OVERWRITABLE,
160 /* Function body/variable initializer is known and will be used in final
161 program. */
162 AVAIL_AVAILABLE,
163 /* Function body/variable initializer is known and all it's uses are explicitly
164 visible within current unit (ie it's address is never taken and it is not
165 exported to other units).
166 Currently used only for functions. */
167 AVAIL_LOCAL
170 /* This is the information that is put into the cgraph local structure
171 to recover a function. */
172 struct lto_file_decl_data;
174 extern const char * const cgraph_availability_names[];
175 extern const char * const ld_plugin_symbol_resolution_names[];
177 /* Information about thunk, used only for same body aliases. */
179 struct GTY(()) cgraph_thunk_info {
180 /* Information about the thunk. */
181 HOST_WIDE_INT fixed_offset;
182 HOST_WIDE_INT virtual_value;
183 tree alias;
184 bool this_adjusting;
185 bool virtual_offset_p;
186 /* Set to true when alias node is thunk. */
187 bool thunk_p;
190 /* Information about the function collected locally.
191 Available after function is analyzed. */
193 struct GTY(()) cgraph_local_info {
194 /* Set when function function is visible in current compilation unit only
195 and its address is never taken. */
196 unsigned local : 1;
198 /* False when there is something makes versioning impossible. */
199 unsigned versionable : 1;
201 /* False when function calling convention and signature can not be changed.
202 This is the case when __builtin_apply_args is used. */
203 unsigned can_change_signature : 1;
205 /* True when the function has been originally extern inline, but it is
206 redefined now. */
207 unsigned redefined_extern_inline : 1;
209 /* True if the function may enter serial irrevocable mode. */
210 unsigned tm_may_enter_irr : 1;
213 /* Information about the function that needs to be computed globally
214 once compilation is finished. Available only with -funit-at-a-time. */
216 struct GTY(()) cgraph_global_info {
217 /* For inline clones this points to the function they will be
218 inlined into. */
219 struct cgraph_node *inlined_to;
222 /* Information about the function that is propagated by the RTL backend.
223 Available only for functions that has been already assembled. */
225 struct GTY(()) cgraph_rtl_info {
226 unsigned int preferred_incoming_stack_boundary;
229 /* Represent which DECL tree (or reference to such tree)
230 will be replaced by another tree while versioning. */
231 struct GTY(()) ipa_replace_map
233 /* The tree that will be replaced. */
234 tree old_tree;
235 /* The new (replacing) tree. */
236 tree new_tree;
237 /* Parameter number to replace, when old_tree is NULL. */
238 int parm_num;
239 /* True when a substitution should be done, false otherwise. */
240 bool replace_p;
241 /* True when we replace a reference to old_tree. */
242 bool ref_p;
244 typedef struct ipa_replace_map *ipa_replace_map_p;
246 struct GTY(()) cgraph_clone_info
248 vec<ipa_replace_map_p, va_gc> *tree_map;
249 bitmap args_to_skip;
250 bitmap combined_args_to_skip;
254 /* The cgraph data structure.
255 Each function decl has assigned cgraph_node listing callees and callers. */
257 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
258 public:
259 struct cgraph_edge *callees;
260 struct cgraph_edge *callers;
261 /* List of edges representing indirect calls with a yet undetermined
262 callee. */
263 struct cgraph_edge *indirect_calls;
264 /* For nested functions points to function the node is nested in. */
265 struct cgraph_node *origin;
266 /* Points to first nested function, if any. */
267 struct cgraph_node *nested;
268 /* Pointer to the next function with same origin, if any. */
269 struct cgraph_node *next_nested;
270 /* Pointer to the next clone. */
271 struct cgraph_node *next_sibling_clone;
272 struct cgraph_node *prev_sibling_clone;
273 struct cgraph_node *clones;
274 struct cgraph_node *clone_of;
275 /* For functions with many calls sites it holds map from call expression
276 to the edge to speed up cgraph_edge function. */
277 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
278 /* Declaration node used to be clone of. */
279 tree former_clone_of;
281 /* Interprocedural passes scheduled to have their transform functions
282 applied next time we execute local pass on them. We maintain it
283 per-function in order to allow IPA passes to introduce new functions. */
284 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
286 struct cgraph_local_info local;
287 struct cgraph_global_info global;
288 struct cgraph_rtl_info rtl;
289 struct cgraph_clone_info clone;
290 struct cgraph_thunk_info thunk;
292 /* Expected number of executions: calculated in profile.c. */
293 gcov_type count;
294 /* How to scale counts at materialization time; used to merge
295 LTO units with different number of profile runs. */
296 int count_materialization_scale;
297 /* Unique id of the node. */
298 int uid;
299 /* ID assigned by the profiling. */
300 unsigned int profile_id;
301 /* Time profiler: first run of function. */
302 int tp_first_run;
304 /* Set when decl is an abstract function pointed to by the
305 ABSTRACT_DECL_ORIGIN of a reachable function. */
306 unsigned used_as_abstract_origin : 1;
307 /* Set once the function is lowered (i.e. its CFG is built). */
308 unsigned lowered : 1;
309 /* Set once the function has been instantiated and its callee
310 lists created. */
311 unsigned process : 1;
312 /* How commonly executed the node is. Initialized during branch
313 probabilities pass. */
314 ENUM_BITFIELD (node_frequency) frequency : 2;
315 /* True when function can only be called at startup (from static ctor). */
316 unsigned only_called_at_startup : 1;
317 /* True when function can only be called at startup (from static dtor). */
318 unsigned only_called_at_exit : 1;
319 /* True when function is the transactional clone of a function which
320 is called only from inside transactions. */
321 /* ?? We should be able to remove this. We have enough bits in
322 cgraph to calculate it. */
323 unsigned tm_clone : 1;
324 /* True if this decl is a dispatcher for function versions. */
325 unsigned dispatcher_function : 1;
329 typedef struct cgraph_node *cgraph_node_ptr;
332 /* Function Multiversioning info. */
333 struct GTY(()) cgraph_function_version_info {
334 /* The cgraph_node for which the function version info is stored. */
335 struct cgraph_node *this_node;
336 /* Chains all the semantically identical function versions. The
337 first function in this chain is the version_info node of the
338 default function. */
339 struct cgraph_function_version_info *prev;
340 /* If this version node corresponds to a dispatcher for function
341 versions, this points to the version info node of the default
342 function, the first node in the chain. */
343 struct cgraph_function_version_info *next;
344 /* If this node corresponds to a function version, this points
345 to the dispatcher function decl, which is the function that must
346 be called to execute the right function version at run-time.
348 If this cgraph node is a dispatcher (if dispatcher_function is
349 true, in the cgraph_node struct) for function versions, this
350 points to resolver function, which holds the function body of the
351 dispatcher. The dispatcher decl is an alias to the resolver
352 function decl. */
353 tree dispatcher_resolver;
356 /* Get the cgraph_function_version_info node corresponding to node. */
357 struct cgraph_function_version_info *
358 get_cgraph_node_version (struct cgraph_node *node);
360 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
361 corresponding to cgraph_node NODE. */
362 struct cgraph_function_version_info *
363 insert_new_cgraph_node_version (struct cgraph_node *node);
365 /* Record that DECL1 and DECL2 are semantically identical function
366 versions. */
367 void record_function_versions (tree decl1, tree decl2);
369 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
370 DECL is a duplicate declaration. */
371 void delete_function_version (tree decl);
373 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
374 can appear in multiple sets. */
375 struct cgraph_node_set_def
377 struct pointer_map_t *map;
378 vec<cgraph_node_ptr> nodes;
381 typedef struct varpool_node *varpool_node_ptr;
384 /* A varpool node set is a collection of varpool nodes. A varpool node
385 can appear in multiple sets. */
386 struct varpool_node_set_def
388 struct pointer_map_t * map;
389 vec<varpool_node_ptr> nodes;
392 typedef struct cgraph_node_set_def *cgraph_node_set;
395 typedef struct varpool_node_set_def *varpool_node_set;
398 /* Iterator structure for cgraph node sets. */
399 typedef struct
401 cgraph_node_set set;
402 unsigned index;
403 } cgraph_node_set_iterator;
405 /* Iterator structure for varpool node sets. */
406 typedef struct
408 varpool_node_set set;
409 unsigned index;
410 } varpool_node_set_iterator;
412 #define DEFCIFCODE(code, string) CIF_ ## code,
413 /* Reasons for inlining failures. */
414 typedef enum cgraph_inline_failed_enum {
415 #include "cif-code.def"
416 CIF_N_REASONS
417 } cgraph_inline_failed_t;
419 /* Structure containing additional information about an indirect call. */
421 struct GTY(()) cgraph_indirect_call_info
423 /* When polymorphic is set, this field contains offset where the object which
424 was actually used in the polymorphic resides within a larger structure.
425 If agg_contents is set, the field contains the offset within the aggregate
426 from which the address to call was loaded. */
427 HOST_WIDE_INT offset;
428 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
429 HOST_WIDE_INT otr_token;
430 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
431 tree otr_type;
432 /* Index of the parameter that is called. */
433 int param_index;
434 /* ECF flags determined from the caller. */
435 int ecf_flags;
436 /* Profile_id of common target obtrained from profile. */
437 int common_target_id;
438 /* Probability that call will land in function with COMMON_TARGET_ID. */
439 int common_target_probability;
441 /* Set when the call is a virtual call with the parameter being the
442 associated object pointer rather than a simple direct call. */
443 unsigned polymorphic : 1;
444 /* Set when the call is a call of a pointer loaded from contents of an
445 aggregate at offset. */
446 unsigned agg_contents : 1;
447 /* Set when this is a call through a member pointer. */
448 unsigned member_ptr : 1;
449 /* When the previous bit is set, this one determines whether the destination
450 is loaded from a parameter passed by reference. */
451 unsigned by_ref : 1;
454 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
455 /* Expected number of executions: calculated in profile.c. */
456 gcov_type count;
457 struct cgraph_node *caller;
458 struct cgraph_node *callee;
459 struct cgraph_edge *prev_caller;
460 struct cgraph_edge *next_caller;
461 struct cgraph_edge *prev_callee;
462 struct cgraph_edge *next_callee;
463 gimple call_stmt;
464 /* Additional information about an indirect call. Not cleared when an edge
465 becomes direct. */
466 struct cgraph_indirect_call_info *indirect_info;
467 PTR GTY ((skip (""))) aux;
468 /* When equal to CIF_OK, inline this call. Otherwise, points to the
469 explanation why function was not inlined. */
470 cgraph_inline_failed_t inline_failed;
471 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
472 when the function is serialized in. */
473 unsigned int lto_stmt_uid;
474 /* Expected frequency of executions within the function.
475 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
476 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
477 int frequency;
478 /* Unique id of the edge. */
479 int uid;
480 /* Whether this edge was made direct by indirect inlining. */
481 unsigned int indirect_inlining_edge : 1;
482 /* Whether this edge describes an indirect call with an undetermined
483 callee. */
484 unsigned int indirect_unknown_callee : 1;
485 /* Whether this edge is still a dangling */
486 /* True if the corresponding CALL stmt cannot be inlined. */
487 unsigned int call_stmt_cannot_inline_p : 1;
488 /* Can this call throw externally? */
489 unsigned int can_throw_external : 1;
490 /* Edges with SPECULATIVE flag represents indirect calls that was
491 speculatively turned into direct (i.e. by profile feedback).
492 The final code sequence will have form:
494 if (call_target == expected_fn)
495 expected_fn ();
496 else
497 call_target ();
499 Every speculative call is represented by three components attached
500 to a same call statement:
501 1) a direct call (to expected_fn)
502 2) an indirect call (to call_target)
503 3) a IPA_REF_ADDR refrence to expected_fn.
505 Optimizers may later redirect direct call to clone, so 1) and 3)
506 do not need to necesarily agree with destination. */
507 unsigned int speculative : 1;
510 #define CGRAPH_FREQ_BASE 1000
511 #define CGRAPH_FREQ_MAX 100000
513 typedef struct cgraph_edge *cgraph_edge_p;
516 /* The varpool data structure.
517 Each static variable decl has assigned varpool_node. */
519 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
520 public:
521 /* Set when variable is scheduled to be assembled. */
522 unsigned output : 1;
525 /* Every top level asm statement is put into a asm_node. */
527 struct GTY(()) asm_node {
528 /* Next asm node. */
529 struct asm_node *next;
530 /* String for this asm node. */
531 tree asm_str;
532 /* Ordering of all cgraph nodes. */
533 int order;
536 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
538 template <>
539 template <>
540 inline bool
541 is_a_helper <cgraph_node>::test (symtab_node *p)
543 return p->type == SYMTAB_FUNCTION;
546 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
548 template <>
549 template <>
550 inline bool
551 is_a_helper <varpool_node>::test (symtab_node *p)
553 return p->type == SYMTAB_VARIABLE;
556 extern GTY(()) symtab_node *symtab_nodes;
557 extern GTY(()) int cgraph_n_nodes;
558 extern GTY(()) int cgraph_max_uid;
559 extern GTY(()) int cgraph_edge_max_uid;
560 extern bool cgraph_global_info_ready;
561 enum cgraph_state
563 /* Frontend is parsing and finalizing functions. */
564 CGRAPH_STATE_PARSING,
565 /* Callgraph is being constructed. It is safe to add new functions. */
566 CGRAPH_STATE_CONSTRUCTION,
567 /* Callgraph is being at LTO time. */
568 CGRAPH_LTO_STREAMING,
569 /* Callgraph is built and IPA passes are being run. */
570 CGRAPH_STATE_IPA,
571 /* Callgraph is built and all functions are transformed to SSA form. */
572 CGRAPH_STATE_IPA_SSA,
573 /* Functions are now ordered and being passed to RTL expanders. */
574 CGRAPH_STATE_EXPANSION,
575 /* All cgraph expansion is done. */
576 CGRAPH_STATE_FINISHED
578 extern enum cgraph_state cgraph_state;
579 extern bool cgraph_function_flags_ready;
580 extern cgraph_node_set cgraph_new_nodes;
582 extern GTY(()) struct asm_node *asm_nodes;
583 extern GTY(()) int symtab_order;
584 extern bool cpp_implicit_aliases_done;
586 /* In symtab.c */
587 void symtab_register_node (symtab_node *);
588 void symtab_unregister_node (symtab_node *);
589 void symtab_remove_node (symtab_node *);
590 symtab_node *symtab_get_node (const_tree);
591 symtab_node *symtab_node_for_asm (const_tree asmname);
592 const char * symtab_node_asm_name (symtab_node *);
593 const char * symtab_node_name (symtab_node *);
594 void symtab_insert_node_to_hashtable (symtab_node *);
595 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
596 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
597 void dump_symtab (FILE *);
598 void debug_symtab (void);
599 void dump_symtab_node (FILE *, symtab_node *);
600 void debug_symtab_node (symtab_node *);
601 void dump_symtab_base (FILE *, symtab_node *);
602 void verify_symtab (void);
603 void verify_symtab_node (symtab_node *);
604 bool verify_symtab_base (symtab_node *);
605 bool symtab_used_from_object_file_p (symtab_node *);
606 void symtab_make_decl_local (tree);
607 symtab_node *symtab_alias_ultimate_target (symtab_node *,
608 enum availability *avail = NULL);
609 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
610 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
611 bool symtab_for_node_and_aliases (symtab_node *,
612 bool (*) (symtab_node *, void *),
613 void *,
614 bool);
615 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
616 enum availability symtab_node_availability (symtab_node *);
617 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
619 /* In cgraph.c */
620 void dump_cgraph (FILE *);
621 void debug_cgraph (void);
622 void dump_cgraph_node (FILE *, struct cgraph_node *);
623 void debug_cgraph_node (struct cgraph_node *);
624 void cgraph_remove_edge (struct cgraph_edge *);
625 void cgraph_remove_node (struct cgraph_node *);
626 void cgraph_release_function_body (struct cgraph_node *);
627 void release_function_body (tree);
628 void cgraph_node_remove_callees (struct cgraph_node *node);
629 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
630 struct cgraph_node *,
631 gimple, gcov_type, int);
632 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
633 int, gcov_type, int);
634 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
635 struct cgraph_node * cgraph_create_node (tree);
636 struct cgraph_node * cgraph_create_empty_node (void);
637 struct cgraph_node * cgraph_get_create_node (tree);
638 struct cgraph_node * cgraph_get_create_real_symbol_node (tree);
639 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
640 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
641 HOST_WIDE_INT, tree, tree);
642 struct cgraph_node *cgraph_node_for_asm (tree);
643 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
644 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
645 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
646 struct cgraph_local_info *cgraph_local_info (tree);
647 struct cgraph_global_info *cgraph_global_info (tree);
648 struct cgraph_rtl_info *cgraph_rtl_info (tree);
649 struct cgraph_node *cgraph_create_function_alias (tree, tree);
650 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
651 struct cgraph_node *);
652 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
653 struct cgraph_edge *);
655 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
656 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
657 bool cgraph_only_called_directly_p (struct cgraph_node *);
659 bool cgraph_function_possibly_inlined_p (tree);
660 void cgraph_unnest_node (struct cgraph_node *);
662 enum availability cgraph_function_body_availability (struct cgraph_node *);
663 void cgraph_add_new_function (tree, bool);
664 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
666 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
667 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
668 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
669 bool cgraph_node_cannot_return (struct cgraph_node *);
670 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
671 bool cgraph_will_be_removed_from_program_if_no_direct_calls
672 (struct cgraph_node *node);
673 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
674 (struct cgraph_node *node);
675 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
676 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
677 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
678 bool (*) (struct cgraph_node *, void *),
679 void *,
680 bool);
681 bool cgraph_for_node_and_aliases (struct cgraph_node *,
682 bool (*) (struct cgraph_node *, void *),
683 void *, bool);
684 vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
685 void verify_cgraph (void);
686 void verify_cgraph_node (struct cgraph_node *);
687 void cgraph_mark_address_taken_node (struct cgraph_node *);
689 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
690 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
691 typedef void (*varpool_node_hook)(struct varpool_node *, void *);
692 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
693 void *);
694 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
695 void *);
696 struct cgraph_edge_hook_list;
697 struct cgraph_node_hook_list;
698 struct varpool_node_hook_list;
699 struct cgraph_2edge_hook_list;
700 struct cgraph_2node_hook_list;
701 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
702 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
703 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
704 void *);
705 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
706 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
707 void *);
708 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
709 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
710 void *);
711 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
712 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
713 void *);
714 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
715 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
716 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
717 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
718 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
719 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
720 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
721 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
722 enum availability *avail = NULL);
723 bool cgraph_get_body (struct cgraph_node *node);
724 struct cgraph_edge *
725 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
726 struct cgraph_node *,
727 gcov_type, int);
728 void cgraph_speculative_call_info (struct cgraph_edge *,
729 struct cgraph_edge *&,
730 struct cgraph_edge *&,
731 struct ipa_ref *&);
732 extern bool gimple_check_call_matching_types (gimple, tree, bool);
734 /* In cgraphunit.c */
735 struct asm_node *add_asm_node (tree);
736 extern FILE *cgraph_dump_file;
737 void cgraph_finalize_function (tree, bool);
738 void finalize_compilation_unit (void);
739 void compile (void);
740 void init_cgraph (void);
741 bool cgraph_process_new_functions (void);
742 void cgraph_process_same_body_aliases (void);
743 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
744 /* Initialize datastructures so DECL is a function in lowered gimple form.
745 IN_SSA is true if the gimple is in SSA. */
746 basic_block init_lowered_empty_function (tree, bool);
747 void cgraph_reset_node (struct cgraph_node *);
748 bool expand_thunk (struct cgraph_node *, bool);
750 /* In cgraphclones.c */
752 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
753 struct cgraph_node *, gimple,
754 unsigned, gcov_type, int, bool);
755 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
756 int, bool, vec<cgraph_edge_p>,
757 bool, struct cgraph_node *);
758 tree clone_function_name (tree decl, const char *);
759 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
760 vec<cgraph_edge_p>,
761 vec<ipa_replace_map_p, va_gc> *tree_map,
762 bitmap args_to_skip,
763 const char *clone_name);
764 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
765 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
766 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
767 bool update_speculative = true);
768 void cgraph_create_edge_including_clones (struct cgraph_node *,
769 struct cgraph_node *,
770 gimple, gimple, gcov_type, int,
771 cgraph_inline_failed_t);
772 void cgraph_materialize_all_clones (void);
773 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
774 tree, vec<cgraph_edge_p>, bitmap);
775 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
776 vec<cgraph_edge_p>,
777 vec<ipa_replace_map_p, va_gc> *,
778 bitmap, bool, bitmap,
779 basic_block, const char *);
780 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
781 bool, bitmap, bool, bitmap, basic_block);
782 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
784 /* In cgraphbuild.c */
785 unsigned int rebuild_cgraph_edges (void);
786 void cgraph_rebuild_references (void);
787 int compute_call_stmt_bb_frequency (tree, basic_block bb);
788 void record_references_in_initializer (tree, bool);
789 void ipa_record_stmt_references (struct cgraph_node *, gimple);
791 /* In ipa.c */
792 bool symtab_remove_unreachable_nodes (bool, FILE *);
793 cgraph_node_set cgraph_node_set_new (void);
794 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
795 struct cgraph_node *);
796 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
797 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
798 void dump_cgraph_node_set (FILE *, cgraph_node_set);
799 void debug_cgraph_node_set (cgraph_node_set);
800 void free_cgraph_node_set (cgraph_node_set);
801 void cgraph_build_static_cdtor (char which, tree body, int priority);
803 varpool_node_set varpool_node_set_new (void);
804 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
805 struct varpool_node *);
806 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
807 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
808 void dump_varpool_node_set (FILE *, varpool_node_set);
809 void debug_varpool_node_set (varpool_node_set);
810 void free_varpool_node_set (varpool_node_set);
811 void ipa_discover_readonly_nonaddressable_vars (void);
812 bool varpool_externally_visible_p (struct varpool_node *);
814 /* In predict.c */
815 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
816 bool cgraph_optimize_for_size_p (struct cgraph_node *);
818 /* In varpool.c */
819 struct varpool_node *varpool_create_empty_node (void);
820 struct varpool_node *varpool_node_for_decl (tree);
821 struct varpool_node *varpool_node_for_asm (tree asmname);
822 void varpool_mark_needed_node (struct varpool_node *);
823 void debug_varpool (void);
824 void dump_varpool (FILE *);
825 void dump_varpool_node (FILE *, struct varpool_node *);
827 void varpool_finalize_decl (tree);
828 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
829 void cgraph_make_node_local (struct cgraph_node *);
830 bool cgraph_node_can_be_local_p (struct cgraph_node *);
833 void varpool_remove_node (struct varpool_node *node);
834 void varpool_finalize_named_section_flags (struct varpool_node *node);
835 bool varpool_output_variables (void);
836 bool varpool_assemble_decl (struct varpool_node *node);
837 void varpool_analyze_node (struct varpool_node *);
838 struct varpool_node * varpool_extra_name_alias (tree, tree);
839 struct varpool_node * varpool_create_variable_alias (tree, tree);
840 void varpool_reset_queue (void);
841 tree ctor_for_folding (tree);
842 bool varpool_for_node_and_aliases (struct varpool_node *,
843 bool (*) (struct varpool_node *, void *),
844 void *, bool);
845 void varpool_add_new_variable (tree);
846 void symtab_initialize_asm_name_hash (void);
847 void symtab_prevail_in_asm_name_hash (symtab_node *node);
848 void varpool_remove_initializer (struct varpool_node *);
851 /* Return callgraph node for given symbol and check it is a function. */
852 static inline struct cgraph_node *
853 cgraph (symtab_node *node)
855 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
856 return (struct cgraph_node *)node;
859 /* Return varpool node for given symbol and check it is a variable. */
860 static inline struct varpool_node *
861 varpool (symtab_node *node)
863 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
864 return (struct varpool_node *)node;
867 /* Return callgraph node for given symbol and check it is a function. */
868 static inline struct cgraph_node *
869 cgraph_get_node (const_tree decl)
871 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
872 return cgraph (symtab_get_node (decl));
875 /* Return varpool node for given symbol and check it is a function. */
876 static inline struct varpool_node *
877 varpool_get_node (const_tree decl)
879 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
880 return varpool (symtab_get_node (decl));
883 /* Return asm name of cgraph node. */
884 static inline const char *
885 cgraph_node_asm_name (struct cgraph_node *node)
887 return symtab_node_asm_name (node);
890 /* Return asm name of varpool node. */
891 static inline const char *
892 varpool_node_asm_name (struct varpool_node *node)
894 return symtab_node_asm_name (node);
897 /* Return name of cgraph node. */
898 static inline const char *
899 cgraph_node_name (struct cgraph_node *node)
901 return symtab_node_name (node);
904 /* Return name of varpool node. */
905 static inline const char *
906 varpool_node_name (struct varpool_node *node)
908 return symtab_node_name (node);
911 /* Walk all symbols. */
912 #define FOR_EACH_SYMBOL(node) \
913 for ((node) = symtab_nodes; (node); (node) = (node)->next)
916 /* Return first variable. */
917 static inline struct varpool_node *
918 varpool_first_variable (void)
920 symtab_node *node;
921 for (node = symtab_nodes; node; node = node->next)
922 if (varpool_node *vnode = dyn_cast <varpool_node> (node))
923 return vnode;
924 return NULL;
927 /* Return next variable after NODE. */
928 static inline struct varpool_node *
929 varpool_next_variable (struct varpool_node *node)
931 symtab_node *node1 = node->next;
932 for (; node1; node1 = node1->next)
933 if (varpool_node *vnode1 = dyn_cast <varpool_node> (node1))
934 return vnode1;
935 return NULL;
937 /* Walk all variables. */
938 #define FOR_EACH_VARIABLE(node) \
939 for ((node) = varpool_first_variable (); \
940 (node); \
941 (node) = varpool_next_variable ((node)))
943 /* Return first reachable static variable with initializer. */
944 static inline struct varpool_node *
945 varpool_first_static_initializer (void)
947 symtab_node *node;
948 for (node = symtab_nodes; node; node = node->next)
950 varpool_node *vnode = dyn_cast <varpool_node> (node);
951 if (vnode && DECL_INITIAL (node->decl))
952 return vnode;
954 return NULL;
957 /* Return next reachable static variable with initializer after NODE. */
958 static inline struct varpool_node *
959 varpool_next_static_initializer (struct varpool_node *node)
961 symtab_node *node1 = node->next;
962 for (; node1; node1 = node1->next)
964 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
965 if (vnode1 && DECL_INITIAL (node1->decl))
966 return vnode1;
968 return NULL;
971 /* Walk all static variables with initializer set. */
972 #define FOR_EACH_STATIC_INITIALIZER(node) \
973 for ((node) = varpool_first_static_initializer (); (node); \
974 (node) = varpool_next_static_initializer (node))
976 /* Return first reachable static variable with initializer. */
977 static inline struct varpool_node *
978 varpool_first_defined_variable (void)
980 symtab_node *node;
981 for (node = symtab_nodes; node; node = node->next)
983 varpool_node *vnode = dyn_cast <varpool_node> (node);
984 if (vnode && vnode->definition)
985 return vnode;
987 return NULL;
990 /* Return next reachable static variable with initializer after NODE. */
991 static inline struct varpool_node *
992 varpool_next_defined_variable (struct varpool_node *node)
994 symtab_node *node1 = node->next;
995 for (; node1; node1 = node1->next)
997 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
998 if (vnode1 && vnode1->definition)
999 return vnode1;
1001 return NULL;
1003 /* Walk all variables with definitions in current unit. */
1004 #define FOR_EACH_DEFINED_VARIABLE(node) \
1005 for ((node) = varpool_first_defined_variable (); (node); \
1006 (node) = varpool_next_defined_variable (node))
1008 /* Return first function with body defined. */
1009 static inline struct cgraph_node *
1010 cgraph_first_defined_function (void)
1012 symtab_node *node;
1013 for (node = symtab_nodes; node; node = node->next)
1015 cgraph_node *cn = dyn_cast <cgraph_node> (node);
1016 if (cn && cn->definition)
1017 return cn;
1019 return NULL;
1022 /* Return next function with body defined after NODE. */
1023 static inline struct cgraph_node *
1024 cgraph_next_defined_function (struct cgraph_node *node)
1026 symtab_node *node1 = node->next;
1027 for (; node1; node1 = node1->next)
1029 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
1030 if (cn1 && cn1->definition)
1031 return cn1;
1033 return NULL;
1036 /* Walk all functions with body defined. */
1037 #define FOR_EACH_DEFINED_FUNCTION(node) \
1038 for ((node) = cgraph_first_defined_function (); (node); \
1039 (node) = cgraph_next_defined_function ((node)))
1041 /* Return first function. */
1042 static inline struct cgraph_node *
1043 cgraph_first_function (void)
1045 symtab_node *node;
1046 for (node = symtab_nodes; node; node = node->next)
1047 if (cgraph_node *cn = dyn_cast <cgraph_node> (node))
1048 return cn;
1049 return NULL;
1052 /* Return next function. */
1053 static inline struct cgraph_node *
1054 cgraph_next_function (struct cgraph_node *node)
1056 symtab_node *node1 = node->next;
1057 for (; node1; node1 = node1->next)
1058 if (cgraph_node *cn1 = dyn_cast <cgraph_node> (node1))
1059 return cn1;
1060 return NULL;
1062 /* Walk all functions. */
1063 #define FOR_EACH_FUNCTION(node) \
1064 for ((node) = cgraph_first_function (); (node); \
1065 (node) = cgraph_next_function ((node)))
1067 /* Return true when NODE is a function with Gimple body defined
1068 in current unit. Functions can also be define externally or they
1069 can be thunks with no Gimple representation.
1071 Note that at WPA stage, the function body may not be present in memory. */
1073 static inline bool
1074 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1076 return node->definition && !node->thunk.thunk_p && !node->alias;
1079 /* Return first function with body defined. */
1080 static inline struct cgraph_node *
1081 cgraph_first_function_with_gimple_body (void)
1083 symtab_node *node;
1084 for (node = symtab_nodes; node; node = node->next)
1086 cgraph_node *cn = dyn_cast <cgraph_node> (node);
1087 if (cn && cgraph_function_with_gimple_body_p (cn))
1088 return cn;
1090 return NULL;
1093 /* Return next reachable static variable with initializer after NODE. */
1094 static inline struct cgraph_node *
1095 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1097 symtab_node *node1 = node->next;
1098 for (; node1; node1 = node1->next)
1100 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
1101 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1102 return cn1;
1104 return NULL;
1107 /* Walk all functions with body defined. */
1108 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1109 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1110 (node) = cgraph_next_function_with_gimple_body (node))
1112 /* Create a new static variable of type TYPE. */
1113 tree add_new_static_var (tree type);
1115 /* Return true if iterator CSI points to nothing. */
1116 static inline bool
1117 csi_end_p (cgraph_node_set_iterator csi)
1119 return csi.index >= csi.set->nodes.length ();
1122 /* Advance iterator CSI. */
1123 static inline void
1124 csi_next (cgraph_node_set_iterator *csi)
1126 csi->index++;
1129 /* Return the node pointed to by CSI. */
1130 static inline struct cgraph_node *
1131 csi_node (cgraph_node_set_iterator csi)
1133 return csi.set->nodes[csi.index];
1136 /* Return an iterator to the first node in SET. */
1137 static inline cgraph_node_set_iterator
1138 csi_start (cgraph_node_set set)
1140 cgraph_node_set_iterator csi;
1142 csi.set = set;
1143 csi.index = 0;
1144 return csi;
1147 /* Return true if SET contains NODE. */
1148 static inline bool
1149 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1151 cgraph_node_set_iterator csi;
1152 csi = cgraph_node_set_find (set, node);
1153 return !csi_end_p (csi);
1156 /* Return number of nodes in SET. */
1157 static inline size_t
1158 cgraph_node_set_size (cgraph_node_set set)
1160 return set->nodes.length ();
1163 /* Return true if iterator VSI points to nothing. */
1164 static inline bool
1165 vsi_end_p (varpool_node_set_iterator vsi)
1167 return vsi.index >= vsi.set->nodes.length ();
1170 /* Advance iterator VSI. */
1171 static inline void
1172 vsi_next (varpool_node_set_iterator *vsi)
1174 vsi->index++;
1177 /* Return the node pointed to by VSI. */
1178 static inline struct varpool_node *
1179 vsi_node (varpool_node_set_iterator vsi)
1181 return vsi.set->nodes[vsi.index];
1184 /* Return an iterator to the first node in SET. */
1185 static inline varpool_node_set_iterator
1186 vsi_start (varpool_node_set set)
1188 varpool_node_set_iterator vsi;
1190 vsi.set = set;
1191 vsi.index = 0;
1192 return vsi;
1195 /* Return true if SET contains NODE. */
1196 static inline bool
1197 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
1199 varpool_node_set_iterator vsi;
1200 vsi = varpool_node_set_find (set, node);
1201 return !vsi_end_p (vsi);
1204 /* Return number of nodes in SET. */
1205 static inline size_t
1206 varpool_node_set_size (varpool_node_set set)
1208 return set->nodes.length ();
1211 /* Uniquize all constants that appear in memory.
1212 Each constant in memory thus far output is recorded
1213 in `const_desc_table'. */
1215 struct GTY(()) constant_descriptor_tree {
1216 /* A MEM for the constant. */
1217 rtx rtl;
1219 /* The value of the constant. */
1220 tree value;
1222 /* Hash of value. Computing the hash from value each time
1223 hashfn is called can't work properly, as that means recursive
1224 use of the hash table during hash table expansion. */
1225 hashval_t hash;
1228 /* Return true if set is nonempty. */
1229 static inline bool
1230 cgraph_node_set_nonempty_p (cgraph_node_set set)
1232 return !set->nodes.is_empty ();
1235 /* Return true if set is nonempty. */
1236 static inline bool
1237 varpool_node_set_nonempty_p (varpool_node_set set)
1239 return !set->nodes.is_empty ();
1242 /* Return true when function NODE is only called directly or it has alias.
1243 i.e. it is not externally visible, address was not taken and
1244 it is not used in any other non-standard way. */
1246 static inline bool
1247 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1249 gcc_assert (!node->global.inlined_to);
1250 return (!node->force_output && !node->address_taken
1251 && !node->used_from_other_partition
1252 && !DECL_VIRTUAL_P (node->decl)
1253 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1254 && !DECL_STATIC_DESTRUCTOR (node->decl)
1255 && !node->externally_visible);
1258 /* Return true when function NODE can be removed from callgraph
1259 if all direct calls are eliminated. */
1261 static inline bool
1262 varpool_can_remove_if_no_refs (struct varpool_node *node)
1264 if (DECL_EXTERNAL (node->decl))
1265 return true;
1266 return (!node->force_output && !node->used_from_other_partition
1267 && ((DECL_COMDAT (node->decl)
1268 && !node->forced_by_abi
1269 && !symtab_used_from_object_file_p (node))
1270 || !node->externally_visible
1271 || DECL_HAS_VALUE_EXPR_P (node->decl)));
1274 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1275 i.e. if the variable is not externally visible or not used in some magic
1276 way (asm statement or such).
1277 The magic uses are all summarized in force_output flag. */
1279 static inline bool
1280 varpool_all_refs_explicit_p (struct varpool_node *vnode)
1282 return (vnode->definition
1283 && !vnode->externally_visible
1284 && !vnode->used_from_other_partition
1285 && !vnode->force_output);
1288 /* Constant pool accessor function. */
1289 htab_t constant_pool_htab (void);
1291 /* FIXME: inappropriate dependency of cgraph on IPA. */
1292 #include "ipa-ref-inline.h"
1294 /* Return node that alias N is aliasing. */
1296 static inline symtab_node *
1297 symtab_alias_target (symtab_node *n)
1299 struct ipa_ref *ref;
1300 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1301 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1302 return ref->referred;
1305 static inline struct cgraph_node *
1306 cgraph_alias_target (struct cgraph_node *n)
1308 return dyn_cast <cgraph_node> (symtab_alias_target (n));
1311 static inline struct varpool_node *
1312 varpool_alias_target (struct varpool_node *n)
1314 return dyn_cast <varpool_node> (symtab_alias_target (n));
1317 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1318 Do not walk through thunks.
1319 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1321 static inline struct cgraph_node *
1322 cgraph_function_or_thunk_node (struct cgraph_node *node,
1323 enum availability *availability = NULL)
1325 struct cgraph_node *n;
1327 n = dyn_cast <cgraph_node> (symtab_alias_ultimate_target (node,
1328 availability));
1329 if (!n && availability)
1330 *availability = AVAIL_NOT_AVAILABLE;
1331 return n;
1333 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1334 Do not walk through thunks.
1335 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1337 static inline struct varpool_node *
1338 varpool_variable_node (struct varpool_node *node,
1339 enum availability *availability = NULL)
1341 struct varpool_node *n;
1343 n = dyn_cast <varpool_node> (symtab_alias_ultimate_target (node,
1344 availability));
1345 if (!n && availability)
1346 *availability = AVAIL_NOT_AVAILABLE;
1347 return n;
1350 /* Return true when the edge E represents a direct recursion. */
1351 static inline bool
1352 cgraph_edge_recursive_p (struct cgraph_edge *e)
1354 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1355 if (e->caller->global.inlined_to)
1356 return e->caller->global.inlined_to->decl == callee->decl;
1357 else
1358 return e->caller->decl == callee->decl;
1361 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1362 static inline bool
1363 decl_is_tm_clone (const_tree fndecl)
1365 struct cgraph_node *n = cgraph_get_node (fndecl);
1366 if (n)
1367 return n->tm_clone;
1368 return false;
1371 /* Likewise indicate that a node is needed, i.e. reachable via some
1372 external means. */
1374 static inline void
1375 cgraph_mark_force_output_node (struct cgraph_node *node)
1377 node->force_output = 1;
1378 gcc_checking_assert (!node->global.inlined_to);
1381 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1382 or abstract function kept for debug info purposes only. */
1384 static inline bool
1385 symtab_real_symbol_p (symtab_node *node)
1387 struct cgraph_node *cnode;
1389 if (DECL_ABSTRACT (node->decl))
1390 return false;
1391 if (!is_a <cgraph_node> (node))
1392 return true;
1393 cnode = cgraph (node);
1394 if (cnode->global.inlined_to)
1395 return false;
1396 return true;
1399 /* Return true if NODE can be discarded by linker from the binary. */
1401 static inline bool
1402 symtab_can_be_discarded (symtab_node *node)
1404 return (DECL_EXTERNAL (node->decl)
1405 || (DECL_ONE_ONLY (node->decl)
1406 && node->resolution != LDPR_PREVAILING_DEF
1407 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1408 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1410 #endif /* GCC_CGRAPH_H */