re PR tree-optimization/59287 (points-to analysis confused by union accesses)
[official-gcc.git] / gcc / cgraph.h
blobc6b35f9cfc425c9c145391a607081352633f543d
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 /* Return name. */
48 const char *name () const;
50 /* Return asm name. */
51 const char * asm_name () const;
53 /* Type of the symbol. */
54 ENUM_BITFIELD (symtab_type) type : 8;
56 /* The symbols resolution. */
57 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
59 /*** Flags representing the symbol type. ***/
61 /* True when symbol corresponds to a definition in current unit.
62 set via cgraph_finalize_function or varpool_finalize_decl */
63 unsigned definition : 1;
64 /* True when symbol is an alias.
65 Set by assemble_alias. */
66 unsigned alias : 1;
67 /* True when alias is a weakref. */
68 unsigned weakref : 1;
69 /* C++ frontend produce same body aliases and extra name aliases for
70 virtual functions and vtables that are obviously equivalent.
71 Those aliases are bit special, especially because C++ frontend
72 visibility code is so ugly it can not get them right at first time
73 and their visibility needs to be copied from their "masters" at
74 the end of parsing. */
75 unsigned cpp_implicit_alias : 1;
76 /* Set once the definition was analyzed. The list of references and
77 other properties are built during analysis. */
78 unsigned analyzed : 1;
81 /*** Visibility and linkage flags. ***/
83 /* Set when function is visible by other units. */
84 unsigned externally_visible : 1;
85 /* The symbol will be assumed to be used in an invisiable way (like
86 by an toplevel asm statement). */
87 unsigned force_output : 1;
88 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
89 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
90 to static and it does not inhibit optimization. */
91 unsigned forced_by_abi : 1;
92 /* True when the name is known to be unique and thus it does not need mangling. */
93 unsigned unique_name : 1;
96 /*** WHOPR Partitioning flags.
97 These flags are used at ltrans stage when only part of the callgraph is
98 available. ***/
100 /* Set when variable is used from other LTRANS partition. */
101 unsigned used_from_other_partition : 1;
102 /* Set when function is available in the other LTRANS partition.
103 During WPA output it is used to mark nodes that are present in
104 multiple partitions. */
105 unsigned in_other_partition : 1;
109 /*** other flags. ***/
111 /* Set when symbol has address taken. */
112 unsigned address_taken : 1;
115 /* Ordering of all symtab entries. */
116 int order;
118 /* Declaration representing the symbol. */
119 tree decl;
121 /* Linked list of symbol table entries starting with symtab_nodes. */
122 symtab_node *next;
123 symtab_node *previous;
125 /* Linked list of symbols with the same asm name. There may be multiple
126 entries for single symbol name during LTO, because symbols are renamed
127 only after partitioning.
129 Because inline clones are kept in the assembler name has, they also produce
130 duplicate entries.
132 There are also several long standing bugs where frontends and builtin
133 code produce duplicated decls. */
134 symtab_node *next_sharing_asm_name;
135 symtab_node *previous_sharing_asm_name;
137 /* Circular list of nodes in the same comdat group if non-NULL. */
138 symtab_node *same_comdat_group;
140 /* Vectors of referring and referenced entities. */
141 struct ipa_ref_list ref_list;
143 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
144 depending to what was known to frontend on the creation time.
145 Once alias is resolved, this pointer become NULL. */
146 tree alias_target;
148 /* File stream where this node is being written to. */
149 struct lto_file_decl_data * lto_file_data;
151 PTR GTY ((skip)) aux;
154 enum availability
156 /* Not yet set by cgraph_function_body_availability. */
157 AVAIL_UNSET,
158 /* Function body/variable initializer is unknown. */
159 AVAIL_NOT_AVAILABLE,
160 /* Function body/variable initializer is known but might be replaced
161 by a different one from other compilation unit and thus needs to
162 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
163 arbitrary side effects on escaping variables and functions, while
164 like AVAILABLE it might access static variables. */
165 AVAIL_OVERWRITABLE,
166 /* Function body/variable initializer is known and will be used in final
167 program. */
168 AVAIL_AVAILABLE,
169 /* Function body/variable initializer is known and all it's uses are explicitly
170 visible within current unit (ie it's address is never taken and it is not
171 exported to other units).
172 Currently used only for functions. */
173 AVAIL_LOCAL
176 /* This is the information that is put into the cgraph local structure
177 to recover a function. */
178 struct lto_file_decl_data;
180 extern const char * const cgraph_availability_names[];
181 extern const char * const ld_plugin_symbol_resolution_names[];
183 /* Information about thunk, used only for same body aliases. */
185 struct GTY(()) cgraph_thunk_info {
186 /* Information about the thunk. */
187 HOST_WIDE_INT fixed_offset;
188 HOST_WIDE_INT virtual_value;
189 tree alias;
190 bool this_adjusting;
191 bool virtual_offset_p;
192 /* Set to true when alias node is thunk. */
193 bool thunk_p;
196 /* Information about the function collected locally.
197 Available after function is analyzed. */
199 struct GTY(()) cgraph_local_info {
200 /* Set when function function is visible in current compilation unit only
201 and its address is never taken. */
202 unsigned local : 1;
204 /* False when there is something makes versioning impossible. */
205 unsigned versionable : 1;
207 /* False when function calling convention and signature can not be changed.
208 This is the case when __builtin_apply_args is used. */
209 unsigned can_change_signature : 1;
211 /* True when the function has been originally extern inline, but it is
212 redefined now. */
213 unsigned redefined_extern_inline : 1;
215 /* True if the function may enter serial irrevocable mode. */
216 unsigned tm_may_enter_irr : 1;
219 /* Information about the function that needs to be computed globally
220 once compilation is finished. Available only with -funit-at-a-time. */
222 struct GTY(()) cgraph_global_info {
223 /* For inline clones this points to the function they will be
224 inlined into. */
225 struct cgraph_node *inlined_to;
228 /* Information about the function that is propagated by the RTL backend.
229 Available only for functions that has been already assembled. */
231 struct GTY(()) cgraph_rtl_info {
232 unsigned int preferred_incoming_stack_boundary;
235 /* Represent which DECL tree (or reference to such tree)
236 will be replaced by another tree while versioning. */
237 struct GTY(()) ipa_replace_map
239 /* The tree that will be replaced. */
240 tree old_tree;
241 /* The new (replacing) tree. */
242 tree new_tree;
243 /* Parameter number to replace, when old_tree is NULL. */
244 int parm_num;
245 /* True when a substitution should be done, false otherwise. */
246 bool replace_p;
247 /* True when we replace a reference to old_tree. */
248 bool ref_p;
250 typedef struct ipa_replace_map *ipa_replace_map_p;
252 struct GTY(()) cgraph_clone_info
254 vec<ipa_replace_map_p, va_gc> *tree_map;
255 bitmap args_to_skip;
256 bitmap combined_args_to_skip;
260 /* The cgraph data structure.
261 Each function decl has assigned cgraph_node listing callees and callers. */
263 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
264 public:
265 struct cgraph_edge *callees;
266 struct cgraph_edge *callers;
267 /* List of edges representing indirect calls with a yet undetermined
268 callee. */
269 struct cgraph_edge *indirect_calls;
270 /* For nested functions points to function the node is nested in. */
271 struct cgraph_node *origin;
272 /* Points to first nested function, if any. */
273 struct cgraph_node *nested;
274 /* Pointer to the next function with same origin, if any. */
275 struct cgraph_node *next_nested;
276 /* Pointer to the next clone. */
277 struct cgraph_node *next_sibling_clone;
278 struct cgraph_node *prev_sibling_clone;
279 struct cgraph_node *clones;
280 struct cgraph_node *clone_of;
281 /* For functions with many calls sites it holds map from call expression
282 to the edge to speed up cgraph_edge function. */
283 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
284 /* Declaration node used to be clone of. */
285 tree former_clone_of;
287 /* Interprocedural passes scheduled to have their transform functions
288 applied next time we execute local pass on them. We maintain it
289 per-function in order to allow IPA passes to introduce new functions. */
290 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
292 struct cgraph_local_info local;
293 struct cgraph_global_info global;
294 struct cgraph_rtl_info rtl;
295 struct cgraph_clone_info clone;
296 struct cgraph_thunk_info thunk;
298 /* Expected number of executions: calculated in profile.c. */
299 gcov_type count;
300 /* How to scale counts at materialization time; used to merge
301 LTO units with different number of profile runs. */
302 int count_materialization_scale;
303 /* Unique id of the node. */
304 int uid;
305 /* ID assigned by the profiling. */
306 unsigned int profile_id;
307 /* Time profiler: first run of function. */
308 int tp_first_run;
310 /* Set when decl is an abstract function pointed to by the
311 ABSTRACT_DECL_ORIGIN of a reachable function. */
312 unsigned used_as_abstract_origin : 1;
313 /* Set once the function is lowered (i.e. its CFG is built). */
314 unsigned lowered : 1;
315 /* Set once the function has been instantiated and its callee
316 lists created. */
317 unsigned process : 1;
318 /* How commonly executed the node is. Initialized during branch
319 probabilities pass. */
320 ENUM_BITFIELD (node_frequency) frequency : 2;
321 /* True when function can only be called at startup (from static ctor). */
322 unsigned only_called_at_startup : 1;
323 /* True when function can only be called at startup (from static dtor). */
324 unsigned only_called_at_exit : 1;
325 /* True when function is the transactional clone of a function which
326 is called only from inside transactions. */
327 /* ?? We should be able to remove this. We have enough bits in
328 cgraph to calculate it. */
329 unsigned tm_clone : 1;
330 /* True if this decl is a dispatcher for function versions. */
331 unsigned dispatcher_function : 1;
335 typedef struct cgraph_node *cgraph_node_ptr;
338 /* Function Multiversioning info. */
339 struct GTY(()) cgraph_function_version_info {
340 /* The cgraph_node for which the function version info is stored. */
341 struct cgraph_node *this_node;
342 /* Chains all the semantically identical function versions. The
343 first function in this chain is the version_info node of the
344 default function. */
345 struct cgraph_function_version_info *prev;
346 /* If this version node corresponds to a dispatcher for function
347 versions, this points to the version info node of the default
348 function, the first node in the chain. */
349 struct cgraph_function_version_info *next;
350 /* If this node corresponds to a function version, this points
351 to the dispatcher function decl, which is the function that must
352 be called to execute the right function version at run-time.
354 If this cgraph node is a dispatcher (if dispatcher_function is
355 true, in the cgraph_node struct) for function versions, this
356 points to resolver function, which holds the function body of the
357 dispatcher. The dispatcher decl is an alias to the resolver
358 function decl. */
359 tree dispatcher_resolver;
362 /* Get the cgraph_function_version_info node corresponding to node. */
363 struct cgraph_function_version_info *
364 get_cgraph_node_version (struct cgraph_node *node);
366 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
367 corresponding to cgraph_node NODE. */
368 struct cgraph_function_version_info *
369 insert_new_cgraph_node_version (struct cgraph_node *node);
371 /* Record that DECL1 and DECL2 are semantically identical function
372 versions. */
373 void record_function_versions (tree decl1, tree decl2);
375 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
376 DECL is a duplicate declaration. */
377 void delete_function_version (tree decl);
379 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
380 can appear in multiple sets. */
381 struct cgraph_node_set_def
383 struct pointer_map_t *map;
384 vec<cgraph_node_ptr> nodes;
387 typedef struct varpool_node *varpool_node_ptr;
390 /* A varpool node set is a collection of varpool nodes. A varpool node
391 can appear in multiple sets. */
392 struct varpool_node_set_def
394 struct pointer_map_t * map;
395 vec<varpool_node_ptr> nodes;
398 typedef struct cgraph_node_set_def *cgraph_node_set;
401 typedef struct varpool_node_set_def *varpool_node_set;
404 /* Iterator structure for cgraph node sets. */
405 typedef struct
407 cgraph_node_set set;
408 unsigned index;
409 } cgraph_node_set_iterator;
411 /* Iterator structure for varpool node sets. */
412 typedef struct
414 varpool_node_set set;
415 unsigned index;
416 } varpool_node_set_iterator;
418 #define DEFCIFCODE(code, string) CIF_ ## code,
419 /* Reasons for inlining failures. */
420 typedef enum cgraph_inline_failed_enum {
421 #include "cif-code.def"
422 CIF_N_REASONS
423 } cgraph_inline_failed_t;
425 /* Structure containing additional information about an indirect call. */
427 struct GTY(()) cgraph_indirect_call_info
429 /* When polymorphic is set, this field contains offset where the object which
430 was actually used in the polymorphic resides within a larger structure.
431 If agg_contents is set, the field contains the offset within the aggregate
432 from which the address to call was loaded. */
433 HOST_WIDE_INT offset;
434 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
435 HOST_WIDE_INT otr_token;
436 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
437 tree otr_type, outer_type;
438 /* Index of the parameter that is called. */
439 int param_index;
440 /* ECF flags determined from the caller. */
441 int ecf_flags;
442 /* Profile_id of common target obtrained from profile. */
443 int common_target_id;
444 /* Probability that call will land in function with COMMON_TARGET_ID. */
445 int common_target_probability;
447 /* Set when the call is a virtual call with the parameter being the
448 associated object pointer rather than a simple direct call. */
449 unsigned polymorphic : 1;
450 /* Set when the call is a call of a pointer loaded from contents of an
451 aggregate at offset. */
452 unsigned agg_contents : 1;
453 /* Set when this is a call through a member pointer. */
454 unsigned member_ptr : 1;
455 /* When the previous bit is set, this one determines whether the destination
456 is loaded from a parameter passed by reference. */
457 unsigned by_ref : 1;
458 unsigned int maybe_in_construction : 1;
459 unsigned int maybe_derived_type : 1;
462 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
463 /* Expected number of executions: calculated in profile.c. */
464 gcov_type count;
465 struct cgraph_node *caller;
466 struct cgraph_node *callee;
467 struct cgraph_edge *prev_caller;
468 struct cgraph_edge *next_caller;
469 struct cgraph_edge *prev_callee;
470 struct cgraph_edge *next_callee;
471 gimple call_stmt;
472 /* Additional information about an indirect call. Not cleared when an edge
473 becomes direct. */
474 struct cgraph_indirect_call_info *indirect_info;
475 PTR GTY ((skip (""))) aux;
476 /* When equal to CIF_OK, inline this call. Otherwise, points to the
477 explanation why function was not inlined. */
478 cgraph_inline_failed_t inline_failed;
479 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
480 when the function is serialized in. */
481 unsigned int lto_stmt_uid;
482 /* Expected frequency of executions within the function.
483 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
484 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
485 int frequency;
486 /* Unique id of the edge. */
487 int uid;
488 /* Whether this edge was made direct by indirect inlining. */
489 unsigned int indirect_inlining_edge : 1;
490 /* Whether this edge describes an indirect call with an undetermined
491 callee. */
492 unsigned int indirect_unknown_callee : 1;
493 /* Whether this edge is still a dangling */
494 /* True if the corresponding CALL stmt cannot be inlined. */
495 unsigned int call_stmt_cannot_inline_p : 1;
496 /* Can this call throw externally? */
497 unsigned int can_throw_external : 1;
498 /* Edges with SPECULATIVE flag represents indirect calls that was
499 speculatively turned into direct (i.e. by profile feedback).
500 The final code sequence will have form:
502 if (call_target == expected_fn)
503 expected_fn ();
504 else
505 call_target ();
507 Every speculative call is represented by three components attached
508 to a same call statement:
509 1) a direct call (to expected_fn)
510 2) an indirect call (to call_target)
511 3) a IPA_REF_ADDR refrence to expected_fn.
513 Optimizers may later redirect direct call to clone, so 1) and 3)
514 do not need to necesarily agree with destination. */
515 unsigned int speculative : 1;
518 #define CGRAPH_FREQ_BASE 1000
519 #define CGRAPH_FREQ_MAX 100000
521 typedef struct cgraph_edge *cgraph_edge_p;
524 /* The varpool data structure.
525 Each static variable decl has assigned varpool_node. */
527 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
528 public:
529 /* Set when variable is scheduled to be assembled. */
530 unsigned output : 1;
532 /* Set when variable has statically initialized pointer
533 or is a static bounds variable and needs initalization. */
534 unsigned need_bounds_init : 1;
536 /* Set if the variable is dynamically initialized, except for
537 function local statics. */
538 unsigned dynamically_initialized : 1;
541 /* Every top level asm statement is put into a asm_node. */
543 struct GTY(()) asm_node {
544 /* Next asm node. */
545 struct asm_node *next;
546 /* String for this asm node. */
547 tree asm_str;
548 /* Ordering of all cgraph nodes. */
549 int order;
552 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
554 template <>
555 template <>
556 inline bool
557 is_a_helper <cgraph_node>::test (symtab_node *p)
559 return p->type == SYMTAB_FUNCTION;
562 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
564 template <>
565 template <>
566 inline bool
567 is_a_helper <varpool_node>::test (symtab_node *p)
569 return p->type == SYMTAB_VARIABLE;
572 extern GTY(()) symtab_node *symtab_nodes;
573 extern GTY(()) int cgraph_n_nodes;
574 extern GTY(()) int cgraph_max_uid;
575 extern GTY(()) int cgraph_edge_max_uid;
576 extern bool cgraph_global_info_ready;
577 enum cgraph_state
579 /* Frontend is parsing and finalizing functions. */
580 CGRAPH_STATE_PARSING,
581 /* Callgraph is being constructed. It is safe to add new functions. */
582 CGRAPH_STATE_CONSTRUCTION,
583 /* Callgraph is being at LTO time. */
584 CGRAPH_LTO_STREAMING,
585 /* Callgraph is built and IPA passes are being run. */
586 CGRAPH_STATE_IPA,
587 /* Callgraph is built and all functions are transformed to SSA form. */
588 CGRAPH_STATE_IPA_SSA,
589 /* Functions are now ordered and being passed to RTL expanders. */
590 CGRAPH_STATE_EXPANSION,
591 /* All cgraph expansion is done. */
592 CGRAPH_STATE_FINISHED
594 extern enum cgraph_state cgraph_state;
595 extern bool cgraph_function_flags_ready;
596 extern cgraph_node_set cgraph_new_nodes;
598 extern GTY(()) struct asm_node *asm_nodes;
599 extern GTY(()) int symtab_order;
600 extern bool cpp_implicit_aliases_done;
602 /* In symtab.c */
603 void symtab_register_node (symtab_node *);
604 void symtab_unregister_node (symtab_node *);
605 void symtab_remove_node (symtab_node *);
606 symtab_node *symtab_get_node (const_tree);
607 symtab_node *symtab_node_for_asm (const_tree asmname);
608 void symtab_insert_node_to_hashtable (symtab_node *);
609 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
610 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
611 void dump_symtab (FILE *);
612 void debug_symtab (void);
613 void dump_symtab_node (FILE *, symtab_node *);
614 void debug_symtab_node (symtab_node *);
615 void dump_symtab_base (FILE *, symtab_node *);
616 void verify_symtab (void);
617 void verify_symtab_node (symtab_node *);
618 bool verify_symtab_base (symtab_node *);
619 bool symtab_used_from_object_file_p (symtab_node *);
620 void symtab_make_decl_local (tree);
621 symtab_node *symtab_alias_ultimate_target (symtab_node *,
622 enum availability *avail = NULL);
623 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
624 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
625 bool symtab_for_node_and_aliases (symtab_node *,
626 bool (*) (symtab_node *, void *),
627 void *,
628 bool);
629 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
630 enum availability symtab_node_availability (symtab_node *);
631 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
633 /* In cgraph.c */
634 void dump_cgraph (FILE *);
635 void debug_cgraph (void);
636 void dump_cgraph_node (FILE *, struct cgraph_node *);
637 void debug_cgraph_node (struct cgraph_node *);
638 void cgraph_remove_edge (struct cgraph_edge *);
639 void cgraph_remove_node (struct cgraph_node *);
640 void cgraph_release_function_body (struct cgraph_node *);
641 void release_function_body (tree);
642 void cgraph_node_remove_callees (struct cgraph_node *node);
643 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
644 struct cgraph_node *,
645 gimple, gcov_type, int);
646 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
647 int, gcov_type, int);
648 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
649 struct cgraph_node * cgraph_create_node (tree);
650 struct cgraph_node * cgraph_create_empty_node (void);
651 struct cgraph_node * cgraph_get_create_node (tree);
652 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
653 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
654 HOST_WIDE_INT, tree, tree);
655 struct cgraph_node *cgraph_node_for_asm (tree);
656 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
657 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
658 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
659 struct cgraph_local_info *cgraph_local_info (tree);
660 struct cgraph_global_info *cgraph_global_info (tree);
661 struct cgraph_rtl_info *cgraph_rtl_info (tree);
662 struct cgraph_node *cgraph_create_function_alias (tree, tree);
663 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
664 struct cgraph_node *);
665 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
666 struct cgraph_edge *);
668 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
669 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
670 bool cgraph_only_called_directly_p (struct cgraph_node *);
672 bool cgraph_function_possibly_inlined_p (tree);
673 void cgraph_unnest_node (struct cgraph_node *);
675 enum availability cgraph_function_body_availability (struct cgraph_node *);
676 void cgraph_add_new_function (tree, bool);
677 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
679 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
680 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
681 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
682 bool cgraph_node_cannot_return (struct cgraph_node *);
683 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
684 bool cgraph_will_be_removed_from_program_if_no_direct_calls
685 (struct cgraph_node *node);
686 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
687 (struct cgraph_node *node);
688 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
689 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
690 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
691 bool (*) (struct cgraph_node *, void *),
692 void *,
693 bool);
694 bool cgraph_for_node_and_aliases (struct cgraph_node *,
695 bool (*) (struct cgraph_node *, void *),
696 void *, bool);
697 vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
698 void verify_cgraph (void);
699 void verify_cgraph_node (struct cgraph_node *);
700 void cgraph_mark_address_taken_node (struct cgraph_node *);
702 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
703 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
704 typedef void (*varpool_node_hook)(struct varpool_node *, void *);
705 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
706 void *);
707 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
708 void *);
709 struct cgraph_edge_hook_list;
710 struct cgraph_node_hook_list;
711 struct varpool_node_hook_list;
712 struct cgraph_2edge_hook_list;
713 struct cgraph_2node_hook_list;
714 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
715 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
716 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
717 void *);
718 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
719 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
720 void *);
721 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
722 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
723 void *);
724 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
725 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
726 void *);
727 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
728 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
729 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
730 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
731 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
732 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
733 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
734 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
735 enum availability *avail = NULL);
736 bool cgraph_get_body (struct cgraph_node *node);
737 struct cgraph_edge *
738 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
739 struct cgraph_node *,
740 gcov_type, int);
741 void cgraph_speculative_call_info (struct cgraph_edge *,
742 struct cgraph_edge *&,
743 struct cgraph_edge *&,
744 struct ipa_ref *&);
745 extern bool gimple_check_call_matching_types (gimple, tree, bool);
747 /* In cgraphunit.c */
748 struct asm_node *add_asm_node (tree);
749 extern FILE *cgraph_dump_file;
750 void cgraph_finalize_function (tree, bool);
751 void finalize_compilation_unit (void);
752 void compile (void);
753 void init_cgraph (void);
754 void cgraph_process_new_functions (void);
755 void cgraph_process_same_body_aliases (void);
756 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
757 /* Initialize datastructures so DECL is a function in lowered gimple form.
758 IN_SSA is true if the gimple is in SSA. */
759 basic_block init_lowered_empty_function (tree, bool);
760 void cgraph_reset_node (struct cgraph_node *);
761 bool expand_thunk (struct cgraph_node *, bool);
763 /* In cgraphclones.c */
765 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
766 struct cgraph_node *, gimple,
767 unsigned, gcov_type, int, bool);
768 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
769 int, bool, vec<cgraph_edge_p>,
770 bool, struct cgraph_node *);
771 tree clone_function_name (tree decl, const char *);
772 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
773 vec<cgraph_edge_p>,
774 vec<ipa_replace_map_p, va_gc> *tree_map,
775 bitmap args_to_skip,
776 const char *clone_name);
777 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
778 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
779 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
780 bool update_speculative = true);
781 void cgraph_create_edge_including_clones (struct cgraph_node *,
782 struct cgraph_node *,
783 gimple, gimple, gcov_type, int,
784 cgraph_inline_failed_t);
785 void cgraph_materialize_all_clones (void);
786 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
787 tree, vec<cgraph_edge_p>, bitmap);
788 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
789 vec<cgraph_edge_p>,
790 vec<ipa_replace_map_p, va_gc> *,
791 bitmap, bool, bitmap,
792 basic_block, const char *);
793 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
794 bool, bitmap, bool, bitmap, basic_block);
795 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
797 /* In cgraphbuild.c */
798 unsigned int rebuild_cgraph_edges (void);
799 void cgraph_rebuild_references (void);
800 int compute_call_stmt_bb_frequency (tree, basic_block bb);
801 void record_references_in_initializer (tree, bool);
802 void ipa_record_stmt_references (struct cgraph_node *, gimple);
804 /* In ipa.c */
805 bool symtab_remove_unreachable_nodes (bool, FILE *);
806 cgraph_node_set cgraph_node_set_new (void);
807 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
808 struct cgraph_node *);
809 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
810 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
811 void dump_cgraph_node_set (FILE *, cgraph_node_set);
812 void debug_cgraph_node_set (cgraph_node_set);
813 void free_cgraph_node_set (cgraph_node_set);
814 void cgraph_build_static_cdtor (char which, tree body, int priority);
816 varpool_node_set varpool_node_set_new (void);
817 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
818 struct varpool_node *);
819 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
820 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
821 void dump_varpool_node_set (FILE *, varpool_node_set);
822 void debug_varpool_node_set (varpool_node_set);
823 void free_varpool_node_set (varpool_node_set);
824 void ipa_discover_readonly_nonaddressable_vars (void);
825 bool varpool_externally_visible_p (struct varpool_node *);
827 /* In predict.c */
828 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
829 bool cgraph_optimize_for_size_p (struct cgraph_node *);
831 /* In varpool.c */
832 struct varpool_node *varpool_create_empty_node (void);
833 struct varpool_node *varpool_node_for_decl (tree);
834 struct varpool_node *varpool_node_for_asm (tree asmname);
835 void varpool_mark_needed_node (struct varpool_node *);
836 void debug_varpool (void);
837 void dump_varpool (FILE *);
838 void dump_varpool_node (FILE *, struct varpool_node *);
840 void varpool_finalize_decl (tree);
841 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
842 void cgraph_make_node_local (struct cgraph_node *);
843 bool cgraph_node_can_be_local_p (struct cgraph_node *);
846 void varpool_remove_node (struct varpool_node *node);
847 void varpool_finalize_named_section_flags (struct varpool_node *node);
848 bool varpool_output_variables (void);
849 bool varpool_assemble_decl (struct varpool_node *node);
850 void varpool_analyze_node (struct varpool_node *);
851 struct varpool_node * varpool_extra_name_alias (tree, tree);
852 struct varpool_node * varpool_create_variable_alias (tree, tree);
853 void varpool_reset_queue (void);
854 tree ctor_for_folding (tree);
855 bool varpool_for_node_and_aliases (struct varpool_node *,
856 bool (*) (struct varpool_node *, void *),
857 void *, bool);
858 void varpool_add_new_variable (tree);
859 void symtab_initialize_asm_name_hash (void);
860 void symtab_prevail_in_asm_name_hash (symtab_node *node);
861 void varpool_remove_initializer (struct varpool_node *);
863 /* In cgraph.c */
864 extern void change_decl_assembler_name (tree, tree);
866 /* Return callgraph node for given symbol and check it is a function. */
867 static inline struct cgraph_node *
868 cgraph (symtab_node *node)
870 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
871 return (struct cgraph_node *)node;
874 /* Return varpool node for given symbol and check it is a variable. */
875 static inline struct varpool_node *
876 varpool (symtab_node *node)
878 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
879 return (struct varpool_node *)node;
882 /* Return callgraph node for given symbol and check it is a function. */
883 static inline struct cgraph_node *
884 cgraph_get_node (const_tree decl)
886 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
887 return cgraph (symtab_get_node (decl));
890 /* Return varpool node for given symbol and check it is a function. */
891 static inline struct varpool_node *
892 varpool_get_node (const_tree decl)
894 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
895 return varpool (symtab_get_node (decl));
898 /* Walk all symbols. */
899 #define FOR_EACH_SYMBOL(node) \
900 for ((node) = symtab_nodes; (node); (node) = (node)->next)
903 /* Return first variable. */
904 static inline struct varpool_node *
905 varpool_first_variable (void)
907 symtab_node *node;
908 for (node = symtab_nodes; node; node = node->next)
909 if (varpool_node *vnode = dyn_cast <varpool_node> (node))
910 return vnode;
911 return NULL;
914 /* Return next variable after NODE. */
915 static inline struct varpool_node *
916 varpool_next_variable (struct varpool_node *node)
918 symtab_node *node1 = node->next;
919 for (; node1; node1 = node1->next)
920 if (varpool_node *vnode1 = dyn_cast <varpool_node> (node1))
921 return vnode1;
922 return NULL;
924 /* Walk all variables. */
925 #define FOR_EACH_VARIABLE(node) \
926 for ((node) = varpool_first_variable (); \
927 (node); \
928 (node) = varpool_next_variable ((node)))
930 /* Return first reachable static variable with initializer. */
931 static inline struct varpool_node *
932 varpool_first_static_initializer (void)
934 symtab_node *node;
935 for (node = symtab_nodes; node; node = node->next)
937 varpool_node *vnode = dyn_cast <varpool_node> (node);
938 if (vnode && DECL_INITIAL (node->decl))
939 return vnode;
941 return NULL;
944 /* Return next reachable static variable with initializer after NODE. */
945 static inline struct varpool_node *
946 varpool_next_static_initializer (struct varpool_node *node)
948 symtab_node *node1 = node->next;
949 for (; node1; node1 = node1->next)
951 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
952 if (vnode1 && DECL_INITIAL (node1->decl))
953 return vnode1;
955 return NULL;
958 /* Walk all static variables with initializer set. */
959 #define FOR_EACH_STATIC_INITIALIZER(node) \
960 for ((node) = varpool_first_static_initializer (); (node); \
961 (node) = varpool_next_static_initializer (node))
963 /* Return first reachable static variable with initializer. */
964 static inline struct varpool_node *
965 varpool_first_defined_variable (void)
967 symtab_node *node;
968 for (node = symtab_nodes; node; node = node->next)
970 varpool_node *vnode = dyn_cast <varpool_node> (node);
971 if (vnode && vnode->definition)
972 return vnode;
974 return NULL;
977 /* Return next reachable static variable with initializer after NODE. */
978 static inline struct varpool_node *
979 varpool_next_defined_variable (struct varpool_node *node)
981 symtab_node *node1 = node->next;
982 for (; node1; node1 = node1->next)
984 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
985 if (vnode1 && vnode1->definition)
986 return vnode1;
988 return NULL;
990 /* Walk all variables with definitions in current unit. */
991 #define FOR_EACH_DEFINED_VARIABLE(node) \
992 for ((node) = varpool_first_defined_variable (); (node); \
993 (node) = varpool_next_defined_variable (node))
995 /* Return first function with body defined. */
996 static inline struct cgraph_node *
997 cgraph_first_defined_function (void)
999 symtab_node *node;
1000 for (node = symtab_nodes; node; node = node->next)
1002 cgraph_node *cn = dyn_cast <cgraph_node> (node);
1003 if (cn && cn->definition)
1004 return cn;
1006 return NULL;
1009 /* Return next function with body defined after NODE. */
1010 static inline struct cgraph_node *
1011 cgraph_next_defined_function (struct cgraph_node *node)
1013 symtab_node *node1 = node->next;
1014 for (; node1; node1 = node1->next)
1016 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
1017 if (cn1 && cn1->definition)
1018 return cn1;
1020 return NULL;
1023 /* Walk all functions with body defined. */
1024 #define FOR_EACH_DEFINED_FUNCTION(node) \
1025 for ((node) = cgraph_first_defined_function (); (node); \
1026 (node) = cgraph_next_defined_function ((node)))
1028 /* Return first function. */
1029 static inline struct cgraph_node *
1030 cgraph_first_function (void)
1032 symtab_node *node;
1033 for (node = symtab_nodes; node; node = node->next)
1034 if (cgraph_node *cn = dyn_cast <cgraph_node> (node))
1035 return cn;
1036 return NULL;
1039 /* Return next function. */
1040 static inline struct cgraph_node *
1041 cgraph_next_function (struct cgraph_node *node)
1043 symtab_node *node1 = node->next;
1044 for (; node1; node1 = node1->next)
1045 if (cgraph_node *cn1 = dyn_cast <cgraph_node> (node1))
1046 return cn1;
1047 return NULL;
1049 /* Walk all functions. */
1050 #define FOR_EACH_FUNCTION(node) \
1051 for ((node) = cgraph_first_function (); (node); \
1052 (node) = cgraph_next_function ((node)))
1054 /* Return true when NODE is a function with Gimple body defined
1055 in current unit. Functions can also be define externally or they
1056 can be thunks with no Gimple representation.
1058 Note that at WPA stage, the function body may not be present in memory. */
1060 static inline bool
1061 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1063 return node->definition && !node->thunk.thunk_p && !node->alias;
1066 /* Return first function with body defined. */
1067 static inline struct cgraph_node *
1068 cgraph_first_function_with_gimple_body (void)
1070 symtab_node *node;
1071 for (node = symtab_nodes; node; node = node->next)
1073 cgraph_node *cn = dyn_cast <cgraph_node> (node);
1074 if (cn && cgraph_function_with_gimple_body_p (cn))
1075 return cn;
1077 return NULL;
1080 /* Return next reachable static variable with initializer after NODE. */
1081 static inline struct cgraph_node *
1082 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1084 symtab_node *node1 = node->next;
1085 for (; node1; node1 = node1->next)
1087 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
1088 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1089 return cn1;
1091 return NULL;
1094 /* Walk all functions with body defined. */
1095 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1096 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1097 (node) = cgraph_next_function_with_gimple_body (node))
1099 /* Create a new static variable of type TYPE. */
1100 tree add_new_static_var (tree type);
1102 /* Return true if iterator CSI points to nothing. */
1103 static inline bool
1104 csi_end_p (cgraph_node_set_iterator csi)
1106 return csi.index >= csi.set->nodes.length ();
1109 /* Advance iterator CSI. */
1110 static inline void
1111 csi_next (cgraph_node_set_iterator *csi)
1113 csi->index++;
1116 /* Return the node pointed to by CSI. */
1117 static inline struct cgraph_node *
1118 csi_node (cgraph_node_set_iterator csi)
1120 return csi.set->nodes[csi.index];
1123 /* Return an iterator to the first node in SET. */
1124 static inline cgraph_node_set_iterator
1125 csi_start (cgraph_node_set set)
1127 cgraph_node_set_iterator csi;
1129 csi.set = set;
1130 csi.index = 0;
1131 return csi;
1134 /* Return true if SET contains NODE. */
1135 static inline bool
1136 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1138 cgraph_node_set_iterator csi;
1139 csi = cgraph_node_set_find (set, node);
1140 return !csi_end_p (csi);
1143 /* Return number of nodes in SET. */
1144 static inline size_t
1145 cgraph_node_set_size (cgraph_node_set set)
1147 return set->nodes.length ();
1150 /* Return true if iterator VSI points to nothing. */
1151 static inline bool
1152 vsi_end_p (varpool_node_set_iterator vsi)
1154 return vsi.index >= vsi.set->nodes.length ();
1157 /* Advance iterator VSI. */
1158 static inline void
1159 vsi_next (varpool_node_set_iterator *vsi)
1161 vsi->index++;
1164 /* Return the node pointed to by VSI. */
1165 static inline struct varpool_node *
1166 vsi_node (varpool_node_set_iterator vsi)
1168 return vsi.set->nodes[vsi.index];
1171 /* Return an iterator to the first node in SET. */
1172 static inline varpool_node_set_iterator
1173 vsi_start (varpool_node_set set)
1175 varpool_node_set_iterator vsi;
1177 vsi.set = set;
1178 vsi.index = 0;
1179 return vsi;
1182 /* Return true if SET contains NODE. */
1183 static inline bool
1184 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
1186 varpool_node_set_iterator vsi;
1187 vsi = varpool_node_set_find (set, node);
1188 return !vsi_end_p (vsi);
1191 /* Return number of nodes in SET. */
1192 static inline size_t
1193 varpool_node_set_size (varpool_node_set set)
1195 return set->nodes.length ();
1198 /* Uniquize all constants that appear in memory.
1199 Each constant in memory thus far output is recorded
1200 in `const_desc_table'. */
1202 struct GTY(()) constant_descriptor_tree {
1203 /* A MEM for the constant. */
1204 rtx rtl;
1206 /* The value of the constant. */
1207 tree value;
1209 /* Hash of value. Computing the hash from value each time
1210 hashfn is called can't work properly, as that means recursive
1211 use of the hash table during hash table expansion. */
1212 hashval_t hash;
1215 /* Return true if set is nonempty. */
1216 static inline bool
1217 cgraph_node_set_nonempty_p (cgraph_node_set set)
1219 return !set->nodes.is_empty ();
1222 /* Return true if set is nonempty. */
1223 static inline bool
1224 varpool_node_set_nonempty_p (varpool_node_set set)
1226 return !set->nodes.is_empty ();
1229 /* Return true when function NODE is only called directly or it has alias.
1230 i.e. it is not externally visible, address was not taken and
1231 it is not used in any other non-standard way. */
1233 static inline bool
1234 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1236 gcc_assert (!node->global.inlined_to);
1237 return (!node->force_output && !node->address_taken
1238 && !node->used_from_other_partition
1239 && !DECL_VIRTUAL_P (node->decl)
1240 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1241 && !DECL_STATIC_DESTRUCTOR (node->decl)
1242 && !node->externally_visible);
1245 /* Return true when function NODE can be removed from callgraph
1246 if all direct calls are eliminated. */
1248 static inline bool
1249 varpool_can_remove_if_no_refs (struct varpool_node *node)
1251 if (DECL_EXTERNAL (node->decl))
1252 return true;
1253 return (!node->force_output && !node->used_from_other_partition
1254 && ((DECL_COMDAT (node->decl)
1255 && !node->forced_by_abi
1256 && !symtab_used_from_object_file_p (node))
1257 || !node->externally_visible
1258 || DECL_HAS_VALUE_EXPR_P (node->decl)));
1261 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1262 i.e. if the variable is not externally visible or not used in some magic
1263 way (asm statement or such).
1264 The magic uses are all summarized in force_output flag. */
1266 static inline bool
1267 varpool_all_refs_explicit_p (struct varpool_node *vnode)
1269 return (vnode->definition
1270 && !vnode->externally_visible
1271 && !vnode->used_from_other_partition
1272 && !vnode->force_output);
1275 /* Constant pool accessor function. */
1276 htab_t constant_pool_htab (void);
1278 /* FIXME: inappropriate dependency of cgraph on IPA. */
1279 #include "ipa-ref-inline.h"
1281 /* Return node that alias N is aliasing. */
1283 static inline symtab_node *
1284 symtab_alias_target (symtab_node *n)
1286 struct ipa_ref *ref;
1287 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1288 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1289 return ref->referred;
1292 static inline struct cgraph_node *
1293 cgraph_alias_target (struct cgraph_node *n)
1295 return dyn_cast <cgraph_node> (symtab_alias_target (n));
1298 static inline struct varpool_node *
1299 varpool_alias_target (struct varpool_node *n)
1301 return dyn_cast <varpool_node> (symtab_alias_target (n));
1304 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1305 Do not walk through thunks.
1306 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1308 static inline struct cgraph_node *
1309 cgraph_function_or_thunk_node (struct cgraph_node *node,
1310 enum availability *availability = NULL)
1312 struct cgraph_node *n;
1314 n = dyn_cast <cgraph_node> (symtab_alias_ultimate_target (node,
1315 availability));
1316 if (!n && availability)
1317 *availability = AVAIL_NOT_AVAILABLE;
1318 return n;
1320 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1321 Do not walk through thunks.
1322 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1324 static inline struct varpool_node *
1325 varpool_variable_node (struct varpool_node *node,
1326 enum availability *availability = NULL)
1328 struct varpool_node *n;
1330 n = dyn_cast <varpool_node> (symtab_alias_ultimate_target (node,
1331 availability));
1332 if (!n && availability)
1333 *availability = AVAIL_NOT_AVAILABLE;
1334 return n;
1337 /* Return true when the edge E represents a direct recursion. */
1338 static inline bool
1339 cgraph_edge_recursive_p (struct cgraph_edge *e)
1341 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1342 if (e->caller->global.inlined_to)
1343 return e->caller->global.inlined_to->decl == callee->decl;
1344 else
1345 return e->caller->decl == callee->decl;
1348 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1349 static inline bool
1350 decl_is_tm_clone (const_tree fndecl)
1352 struct cgraph_node *n = cgraph_get_node (fndecl);
1353 if (n)
1354 return n->tm_clone;
1355 return false;
1358 /* Likewise indicate that a node is needed, i.e. reachable via some
1359 external means. */
1361 static inline void
1362 cgraph_mark_force_output_node (struct cgraph_node *node)
1364 node->force_output = 1;
1365 gcc_checking_assert (!node->global.inlined_to);
1368 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1369 or abstract function kept for debug info purposes only. */
1371 static inline bool
1372 symtab_real_symbol_p (symtab_node *node)
1374 struct cgraph_node *cnode;
1376 if (DECL_ABSTRACT (node->decl))
1377 return false;
1378 if (!is_a <cgraph_node> (node))
1379 return true;
1380 cnode = cgraph (node);
1381 if (cnode->global.inlined_to)
1382 return false;
1383 return true;
1386 /* Return true if NODE can be discarded by linker from the binary. */
1388 static inline bool
1389 symtab_can_be_discarded (symtab_node *node)
1391 return (DECL_EXTERNAL (node->decl)
1392 || (DECL_ONE_ONLY (node->decl)
1393 && node->resolution != LDPR_PREVAILING_DEF
1394 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1395 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1397 #endif /* GCC_CGRAPH_H */