PR c++/54859
[official-gcc.git] / gcc / cgraph.h
blob25c1f33eb579e5f59b2983f21ea429143715a6e0
1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
3 2012 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef GCC_CGRAPH_H
23 #define GCC_CGRAPH_H
25 #include "is-a.h"
26 #include "plugin-api.h"
27 #include "vec.h"
28 #include "tree.h"
29 #include "basic-block.h"
30 #include "function.h"
31 #include "ipa-ref.h"
33 /* Symbol table consists of functions and variables.
34 TODO: add labels, constant pool and aliases. */
35 enum symtab_type
37 SYMTAB_SYMBOL,
38 SYMTAB_FUNCTION,
39 SYMTAB_VARIABLE
42 /* Base of all entries in the symbol table.
43 The symtab_node is inherited by cgraph and varpol nodes. */
44 struct GTY(()) symtab_node_base
46 /* Type of the symbol. */
47 ENUM_BITFIELD (symtab_type) type : 8;
49 /* The symbols resolution. */
50 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
52 /* Set when function has address taken.
53 In current implementation it imply needed flag. */
54 unsigned address_taken : 1;
55 /* Set when variable is used from other LTRANS partition. */
56 unsigned used_from_other_partition : 1;
57 /* Set when function is available in the other LTRANS partition.
58 During WPA output it is used to mark nodes that are present in
59 multiple partitions. */
60 unsigned in_other_partition : 1;
61 /* Set when function is visible by other units. */
62 unsigned externally_visible : 1;
63 /* Needed variables might become dead by optimization. This flag
64 forces the variable to be output even if it appears dead otherwise. */
65 unsigned force_output : 1;
67 /* Ordering of all symtab entries. */
68 int order;
70 tree decl;
72 /* Vectors of referring and referenced entities. */
73 struct ipa_ref_list ref_list;
75 /* Circular list of nodes in the same comdat group if non-NULL. */
76 symtab_node same_comdat_group;
78 /* File stream where this node is being written to. */
79 struct lto_file_decl_data * lto_file_data;
81 /* Linked list of symbol table entries starting with symtab_nodes. */
82 symtab_node next;
83 symtab_node previous;
84 /* Linked list of symbols with the same asm name. There may be multiple
85 entries for single symbol name in the case of LTO resolutions,
86 existence of inline clones, or duplicated declaration. The last case
87 is a long standing bug frontends and builtin handling. */
88 symtab_node next_sharing_asm_name;
89 symtab_node previous_sharing_asm_name;
91 PTR GTY ((skip)) aux;
94 enum availability
96 /* Not yet set by cgraph_function_body_availability. */
97 AVAIL_UNSET,
98 /* Function body/variable initializer is unknown. */
99 AVAIL_NOT_AVAILABLE,
100 /* Function body/variable initializer is known but might be replaced
101 by a different one from other compilation unit and thus needs to
102 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
103 arbitrary side effects on escaping variables and functions, while
104 like AVAILABLE it might access static variables. */
105 AVAIL_OVERWRITABLE,
106 /* Function body/variable initializer is known and will be used in final
107 program. */
108 AVAIL_AVAILABLE,
109 /* Function body/variable initializer is known and all it's uses are explicitly
110 visible within current unit (ie it's address is never taken and it is not
111 exported to other units).
112 Currently used only for functions. */
113 AVAIL_LOCAL
116 /* This is the information that is put into the cgraph local structure
117 to recover a function. */
118 struct lto_file_decl_data;
120 extern const char * const cgraph_availability_names[];
121 extern const char * const ld_plugin_symbol_resolution_names[];
123 /* Information about thunk, used only for same body aliases. */
125 struct GTY(()) cgraph_thunk_info {
126 /* Information about the thunk. */
127 HOST_WIDE_INT fixed_offset;
128 HOST_WIDE_INT virtual_value;
129 tree alias;
130 bool this_adjusting;
131 bool virtual_offset_p;
132 /* Set to true when alias node is thunk. */
133 bool thunk_p;
136 /* Information about the function collected locally.
137 Available after function is analyzed. */
139 struct GTY(()) cgraph_local_info {
140 /* Set when function function is visible in current compilation unit only
141 and its address is never taken. */
142 unsigned local : 1;
144 /* Set once it has been finalized so we consider it to be output. */
145 unsigned finalized : 1;
147 /* False when there is something makes versioning impossible. */
148 unsigned versionable : 1;
150 /* False when function calling convention and signature can not be changed.
151 This is the case when __builtin_apply_args is used. */
152 unsigned can_change_signature : 1;
154 /* True when the function has been originally extern inline, but it is
155 redefined now. */
156 unsigned redefined_extern_inline : 1;
158 /* True if the function may enter serial irrevocable mode. */
159 unsigned tm_may_enter_irr : 1;
162 /* Information about the function that needs to be computed globally
163 once compilation is finished. Available only with -funit-at-a-time. */
165 struct GTY(()) cgraph_global_info {
166 /* For inline clones this points to the function they will be
167 inlined into. */
168 struct cgraph_node *inlined_to;
171 /* Information about the function that is propagated by the RTL backend.
172 Available only for functions that has been already assembled. */
174 struct GTY(()) cgraph_rtl_info {
175 unsigned int preferred_incoming_stack_boundary;
178 /* Represent which DECL tree (or reference to such tree)
179 will be replaced by another tree while versioning. */
180 struct GTY(()) ipa_replace_map
182 /* The tree that will be replaced. */
183 tree old_tree;
184 /* The new (replacing) tree. */
185 tree new_tree;
186 /* Parameter number to replace, when old_tree is NULL. */
187 int parm_num;
188 /* True when a substitution should be done, false otherwise. */
189 bool replace_p;
190 /* True when we replace a reference to old_tree. */
191 bool ref_p;
193 typedef struct ipa_replace_map *ipa_replace_map_p;
194 DEF_VEC_P(ipa_replace_map_p);
195 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
197 struct GTY(()) cgraph_clone_info
199 VEC(ipa_replace_map_p,gc)* tree_map;
200 bitmap args_to_skip;
201 bitmap combined_args_to_skip;
205 /* The cgraph data structure.
206 Each function decl has assigned cgraph_node listing callees and callers. */
208 struct GTY(()) cgraph_node {
209 struct symtab_node_base symbol;
210 struct cgraph_edge *callees;
211 struct cgraph_edge *callers;
212 /* List of edges representing indirect calls with a yet undetermined
213 callee. */
214 struct cgraph_edge *indirect_calls;
215 /* For nested functions points to function the node is nested in. */
216 struct cgraph_node *
217 GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
218 origin;
219 /* Points to first nested function, if any. */
220 struct cgraph_node *
221 GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
222 nested;
223 /* Pointer to the next function with same origin, if any. */
224 struct cgraph_node *
225 GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
226 next_nested;
227 /* Pointer to the next clone. */
228 struct cgraph_node *next_sibling_clone;
229 struct cgraph_node *prev_sibling_clone;
230 struct cgraph_node *clones;
231 struct cgraph_node *clone_of;
232 /* For functions with many calls sites it holds map from call expression
233 to the edge to speed up cgraph_edge function. */
234 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
235 /* Declaration node used to be clone of. */
236 tree former_clone_of;
238 /* Interprocedural passes scheduled to have their transform functions
239 applied next time we execute local pass on them. We maintain it
240 per-function in order to allow IPA passes to introduce new functions. */
241 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
243 struct cgraph_local_info local;
244 struct cgraph_global_info global;
245 struct cgraph_rtl_info rtl;
246 struct cgraph_clone_info clone;
247 struct cgraph_thunk_info thunk;
249 /* Expected number of executions: calculated in profile.c. */
250 gcov_type count;
251 /* How to scale counts at materialization time; used to merge
252 LTO units with different number of profile runs. */
253 int count_materialization_scale;
254 /* Unique id of the node. */
255 int uid;
257 /* Set when decl is an abstract function pointed to by the
258 ABSTRACT_DECL_ORIGIN of a reachable function. */
259 unsigned abstract_and_needed : 1;
260 /* Set once the function is lowered (i.e. its CFG is built). */
261 unsigned lowered : 1;
262 /* Set once the function has been instantiated and its callee
263 lists created. */
264 unsigned analyzed : 1;
265 /* Set when function is scheduled to be processed by local passes. */
266 unsigned process : 1;
267 /* Set for aliases once they got through assemble_alias. */
268 unsigned alias : 1;
269 /* Set for aliases created as C++ same body aliases. */
270 unsigned same_body_alias : 1;
271 /* How commonly executed the node is. Initialized during branch
272 probabilities pass. */
273 ENUM_BITFIELD (node_frequency) frequency : 2;
274 /* True when function can only be called at startup (from static ctor). */
275 unsigned only_called_at_startup : 1;
276 /* True when function can only be called at startup (from static dtor). */
277 unsigned only_called_at_exit : 1;
278 /* True when function is the transactional clone of a function which
279 is called only from inside transactions. */
280 /* ?? We should be able to remove this. We have enough bits in
281 cgraph to calculate it. */
282 unsigned tm_clone : 1;
283 /* True if this decl is a dispatcher for function versions. */
284 unsigned dispatcher_function : 1;
287 DEF_VEC_P(symtab_node);
288 DEF_VEC_ALLOC_P(symtab_node,heap);
289 DEF_VEC_ALLOC_P(symtab_node,gc);
291 typedef struct cgraph_node *cgraph_node_ptr;
293 DEF_VEC_P(cgraph_node_ptr);
294 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
295 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
297 /* Function Multiversioning info. */
298 struct GTY(()) cgraph_function_version_info {
299 /* The cgraph_node for which the function version info is stored. */
300 struct cgraph_node *this_node;
301 /* Chains all the semantically identical function versions. The
302 first function in this chain is the version_info node of the
303 default function. */
304 struct cgraph_function_version_info *prev;
305 /* If this version node corresponds to a dispatcher for function
306 versions, this points to the version info node of the default
307 function, the first node in the chain. */
308 struct cgraph_function_version_info *next;
309 /* If this node corresponds to a function version, this points
310 to the dispatcher function decl, which is the function that must
311 be called to execute the right function version at run-time.
313 If this cgraph node is a dispatcher (if dispatcher_function is
314 true, in the cgraph_node struct) for function versions, this
315 points to resolver function, which holds the function body of the
316 dispatcher. The dispatcher decl is an alias to the resolver
317 function decl. */
318 tree dispatcher_resolver;
321 /* Get the cgraph_function_version_info node corresponding to node. */
322 struct cgraph_function_version_info *
323 get_cgraph_node_version (struct cgraph_node *node);
325 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
326 corresponding to cgraph_node NODE. */
327 struct cgraph_function_version_info *
328 insert_new_cgraph_node_version (struct cgraph_node *node);
330 /* Record that DECL1 and DECL2 are semantically identical function
331 versions. */
332 void record_function_versions (tree decl1, tree decl2);
334 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
335 DECL is a duplicate declaration. */
336 void delete_function_version (tree decl);
338 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
339 can appear in multiple sets. */
340 struct cgraph_node_set_def
342 struct pointer_map_t *map;
343 VEC(cgraph_node_ptr, heap) *nodes;
346 typedef struct varpool_node *varpool_node_ptr;
348 DEF_VEC_P(varpool_node_ptr);
349 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
350 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
352 /* A varpool node set is a collection of varpool nodes. A varpool node
353 can appear in multiple sets. */
354 struct varpool_node_set_def
356 struct pointer_map_t * map;
357 VEC(varpool_node_ptr, heap) *nodes;
360 typedef struct cgraph_node_set_def *cgraph_node_set;
362 DEF_VEC_P(cgraph_node_set);
363 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
364 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
366 typedef struct varpool_node_set_def *varpool_node_set;
368 DEF_VEC_P(varpool_node_set);
369 DEF_VEC_ALLOC_P(varpool_node_set,gc);
370 DEF_VEC_ALLOC_P(varpool_node_set,heap);
372 /* Iterator structure for cgraph node sets. */
373 typedef struct
375 cgraph_node_set set;
376 unsigned index;
377 } cgraph_node_set_iterator;
379 /* Iterator structure for varpool node sets. */
380 typedef struct
382 varpool_node_set set;
383 unsigned index;
384 } varpool_node_set_iterator;
386 #define DEFCIFCODE(code, string) CIF_ ## code,
387 /* Reasons for inlining failures. */
388 typedef enum cgraph_inline_failed_enum {
389 #include "cif-code.def"
390 CIF_N_REASONS
391 } cgraph_inline_failed_t;
393 /* Structure containing additional information about an indirect call. */
395 struct GTY(()) cgraph_indirect_call_info
397 /* When polymorphic is set, this field contains offset where the object which
398 was actually used in the polymorphic resides within a larger structure.
399 If agg_contents is set, the field contains the offset within the aggregate
400 from which the address to call was loaded. */
401 HOST_WIDE_INT offset;
402 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
403 HOST_WIDE_INT otr_token;
404 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
405 tree otr_type;
406 /* Index of the parameter that is called. */
407 int param_index;
408 /* ECF flags determined from the caller. */
409 int ecf_flags;
411 /* Set when the call is a virtual call with the parameter being the
412 associated object pointer rather than a simple direct call. */
413 unsigned polymorphic : 1;
414 /* Set when the call is a call of a pointer loaded from contents of an
415 aggregate at offset. */
416 unsigned agg_contents : 1;
417 /* When the previous bit is set, this one determines whether the destination
418 is loaded from a parameter passed by reference. */
419 unsigned by_ref : 1;
422 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
423 /* Expected number of executions: calculated in profile.c. */
424 gcov_type count;
425 struct cgraph_node *caller;
426 struct cgraph_node *callee;
427 struct cgraph_edge *prev_caller;
428 struct cgraph_edge *next_caller;
429 struct cgraph_edge *prev_callee;
430 struct cgraph_edge *next_callee;
431 gimple call_stmt;
432 /* Additional information about an indirect call. Not cleared when an edge
433 becomes direct. */
434 struct cgraph_indirect_call_info *indirect_info;
435 PTR GTY ((skip (""))) aux;
436 /* When equal to CIF_OK, inline this call. Otherwise, points to the
437 explanation why function was not inlined. */
438 cgraph_inline_failed_t inline_failed;
439 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
440 when the function is serialized in. */
441 unsigned int lto_stmt_uid;
442 /* Expected frequency of executions within the function.
443 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
444 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
445 int frequency;
446 /* Unique id of the edge. */
447 int uid;
448 /* Whether this edge was made direct by indirect inlining. */
449 unsigned int indirect_inlining_edge : 1;
450 /* Whether this edge describes an indirect call with an undetermined
451 callee. */
452 unsigned int indirect_unknown_callee : 1;
453 /* Whether this edge is still a dangling */
454 /* True if the corresponding CALL stmt cannot be inlined. */
455 unsigned int call_stmt_cannot_inline_p : 1;
456 /* Can this call throw externally? */
457 unsigned int can_throw_external : 1;
460 #define CGRAPH_FREQ_BASE 1000
461 #define CGRAPH_FREQ_MAX 100000
463 typedef struct cgraph_edge *cgraph_edge_p;
465 DEF_VEC_P(cgraph_edge_p);
466 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
468 /* The varpool data structure.
469 Each static variable decl has assigned varpool_node. */
471 struct GTY(()) varpool_node {
472 struct symtab_node_base symbol;
473 /* For aliases points to declaration DECL is alias of. */
474 tree alias_of;
476 /* Set once the variable has been instantiated and its callee
477 lists created. */
478 unsigned analyzed : 1;
479 /* Set once it has been finalized so we consider it to be output. */
480 unsigned finalized : 1;
481 /* Set when variable is scheduled to be assembled. */
482 unsigned output : 1;
483 /* Set for aliases once they got through assemble_alias. Also set for
484 extra name aliases in varpool_extra_name_alias. */
485 unsigned alias : 1;
486 unsigned extra_name_alias : 1;
489 /* Every top level asm statement is put into a asm_node. */
491 struct GTY(()) asm_node {
492 /* Next asm node. */
493 struct asm_node *next;
494 /* String for this asm node. */
495 tree asm_str;
496 /* Ordering of all cgraph nodes. */
497 int order;
500 /* Symbol table entry. */
501 union GTY((desc ("%h.symbol.type"), chain_next ("%h.symbol.next"),
502 chain_prev ("%h.symbol.previous"))) symtab_node_def {
503 struct symtab_node_base GTY ((tag ("SYMTAB_SYMBOL"))) symbol;
504 /* To access the following fields,
505 use the use dyn_cast or as_a to obtain the concrete type. */
506 struct cgraph_node GTY ((tag ("SYMTAB_FUNCTION"))) x_function;
507 struct varpool_node GTY ((tag ("SYMTAB_VARIABLE"))) x_variable;
510 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
512 template <>
513 template <>
514 inline bool
515 is_a_helper <cgraph_node>::test (symtab_node_def *p)
517 return p->symbol.type == SYMTAB_FUNCTION;
520 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
522 template <>
523 template <>
524 inline bool
525 is_a_helper <varpool_node>::test (symtab_node_def *p)
527 return p->symbol.type == SYMTAB_VARIABLE;
530 extern GTY(()) symtab_node symtab_nodes;
531 extern GTY(()) int cgraph_n_nodes;
532 extern GTY(()) int cgraph_max_uid;
533 extern GTY(()) int cgraph_edge_max_uid;
534 extern bool cgraph_global_info_ready;
535 enum cgraph_state
537 /* Frontend is parsing and finalizing functions. */
538 CGRAPH_STATE_PARSING,
539 /* Callgraph is being constructed. It is safe to add new functions. */
540 CGRAPH_STATE_CONSTRUCTION,
541 /* Callgraph is built and IPA passes are being run. */
542 CGRAPH_STATE_IPA,
543 /* Callgraph is built and all functions are transformed to SSA form. */
544 CGRAPH_STATE_IPA_SSA,
545 /* Functions are now ordered and being passed to RTL expanders. */
546 CGRAPH_STATE_EXPANSION,
547 /* All cgraph expansion is done. */
548 CGRAPH_STATE_FINISHED
550 extern enum cgraph_state cgraph_state;
551 extern bool cgraph_function_flags_ready;
552 extern cgraph_node_set cgraph_new_nodes;
554 extern GTY(()) struct asm_node *asm_nodes;
555 extern GTY(()) int symtab_order;
556 extern bool same_body_aliases_done;
558 /* In symtab.c */
559 void symtab_register_node (symtab_node);
560 void symtab_unregister_node (symtab_node);
561 void symtab_remove_node (symtab_node);
562 symtab_node symtab_get_node (const_tree);
563 symtab_node symtab_node_for_asm (const_tree asmname);
564 const char * symtab_node_asm_name (symtab_node);
565 const char * symtab_node_name (symtab_node);
566 void symtab_insert_node_to_hashtable (symtab_node);
567 void symtab_add_to_same_comdat_group (symtab_node, symtab_node);
568 void symtab_dissolve_same_comdat_group_list (symtab_node node);
569 void dump_symtab (FILE *);
570 void debug_symtab (void);
571 void dump_symtab_node (FILE *, symtab_node);
572 void debug_symtab_node (symtab_node);
573 void dump_symtab_base (FILE *, symtab_node);
574 void verify_symtab (void);
575 void verify_symtab_node (symtab_node);
576 bool verify_symtab_base (symtab_node);
577 bool symtab_used_from_object_file_p (symtab_node);
578 void symtab_make_decl_local (tree);
580 /* In cgraph.c */
581 void dump_cgraph (FILE *);
582 void debug_cgraph (void);
583 void dump_cgraph_node (FILE *, struct cgraph_node *);
584 void debug_cgraph_node (struct cgraph_node *);
585 void cgraph_remove_edge (struct cgraph_edge *);
586 void cgraph_remove_node (struct cgraph_node *);
587 void cgraph_release_function_body (struct cgraph_node *);
588 void cgraph_node_remove_callees (struct cgraph_node *node);
589 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
590 struct cgraph_node *,
591 gimple, gcov_type, int);
592 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
593 int, gcov_type, int);
594 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
595 struct cgraph_node * cgraph_create_node (tree);
596 struct cgraph_node * cgraph_create_empty_node (void);
597 struct cgraph_node * cgraph_get_create_node (tree);
598 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
599 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
600 HOST_WIDE_INT, tree, tree);
601 struct cgraph_node *cgraph_node_for_asm (tree);
602 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
603 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
604 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
605 struct cgraph_local_info *cgraph_local_info (tree);
606 struct cgraph_global_info *cgraph_global_info (tree);
607 struct cgraph_rtl_info *cgraph_rtl_info (tree);
608 struct cgraph_node *cgraph_create_function_alias (tree, tree);
609 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
610 struct cgraph_node *);
611 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
612 struct cgraph_edge *);
614 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
615 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
616 bool cgraph_only_called_directly_p (struct cgraph_node *);
618 bool cgraph_function_possibly_inlined_p (tree);
619 void cgraph_unnest_node (struct cgraph_node *);
621 enum availability cgraph_function_body_availability (struct cgraph_node *);
622 void cgraph_add_new_function (tree, bool);
623 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
625 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
626 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
627 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
628 bool cgraph_node_cannot_return (struct cgraph_node *);
629 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
630 bool cgraph_will_be_removed_from_program_if_no_direct_calls
631 (struct cgraph_node *node);
632 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
633 (struct cgraph_node *node);
634 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
635 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
636 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
637 bool (*) (struct cgraph_node *, void *),
638 void *,
639 bool);
640 bool cgraph_for_node_and_aliases (struct cgraph_node *,
641 bool (*) (struct cgraph_node *, void *),
642 void *, bool);
643 VEC (cgraph_edge_p, heap) * collect_callers_of_node (struct cgraph_node *node);
644 void verify_cgraph (void);
645 void verify_cgraph_node (struct cgraph_node *);
646 void cgraph_mark_address_taken_node (struct cgraph_node *);
648 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
649 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
650 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
651 void *);
652 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
653 void *);
654 struct cgraph_edge_hook_list;
655 struct cgraph_node_hook_list;
656 struct cgraph_2edge_hook_list;
657 struct cgraph_2node_hook_list;
658 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
659 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
660 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
661 void *);
662 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
663 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
664 void *);
665 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
666 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
667 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
668 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
669 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
670 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
671 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
672 bool cgraph_propagate_frequency (struct cgraph_node *node);
674 /* In cgraphunit.c */
675 struct asm_node *add_asm_node (tree);
676 extern FILE *cgraph_dump_file;
677 void cgraph_finalize_function (tree, bool);
678 void finalize_compilation_unit (void);
679 void compile (void);
680 void init_cgraph (void);
681 bool cgraph_process_new_functions (void);
682 void cgraph_process_same_body_aliases (void);
683 void fixup_same_cpp_alias_visibility (symtab_node node, symtab_node target, tree alias);
684 /* Initialize datastructures so DECL is a function in lowered gimple form.
685 IN_SSA is true if the gimple is in SSA. */
686 basic_block init_lowered_empty_function (tree decl, bool in_ssa);
688 /* In cgraphclones.c */
690 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
691 struct cgraph_node *, gimple,
692 unsigned, gcov_type, int, bool);
693 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
694 int, bool, VEC(cgraph_edge_p,heap) *,
695 bool);
696 tree clone_function_name (tree decl, const char *);
697 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
698 VEC(cgraph_edge_p,heap)*,
699 VEC(ipa_replace_map_p,gc)* tree_map,
700 bitmap args_to_skip,
701 const char *clone_name);
702 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
703 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
704 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
705 void cgraph_create_edge_including_clones (struct cgraph_node *,
706 struct cgraph_node *,
707 gimple, gimple, gcov_type, int,
708 cgraph_inline_failed_t);
709 void cgraph_materialize_all_clones (void);
710 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
711 tree, VEC(cgraph_edge_p,heap)*, bitmap);
712 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
713 VEC(cgraph_edge_p,heap)*,
714 VEC(ipa_replace_map_p,gc)*,
715 bitmap, bool, bitmap,
716 basic_block, const char *);
717 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*,
718 bool, bitmap, bool, bitmap, basic_block);
720 /* In cgraphbuild.c */
721 unsigned int rebuild_cgraph_edges (void);
722 void cgraph_rebuild_references (void);
723 int compute_call_stmt_bb_frequency (tree, basic_block bb);
724 void record_references_in_initializer (tree, bool);
726 /* In ipa.c */
727 bool symtab_remove_unreachable_nodes (bool, FILE *);
728 cgraph_node_set cgraph_node_set_new (void);
729 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
730 struct cgraph_node *);
731 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
732 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
733 void dump_cgraph_node_set (FILE *, cgraph_node_set);
734 void debug_cgraph_node_set (cgraph_node_set);
735 void free_cgraph_node_set (cgraph_node_set);
736 void cgraph_build_static_cdtor (char which, tree body, int priority);
738 varpool_node_set varpool_node_set_new (void);
739 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
740 struct varpool_node *);
741 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
742 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
743 void dump_varpool_node_set (FILE *, varpool_node_set);
744 void debug_varpool_node_set (varpool_node_set);
745 void free_varpool_node_set (varpool_node_set);
746 void ipa_discover_readonly_nonaddressable_vars (void);
747 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
748 bool varpool_externally_visible_p (struct varpool_node *, bool);
750 /* In predict.c */
751 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
752 bool cgraph_optimize_for_size_p (struct cgraph_node *);
754 /* In varpool.c */
755 struct varpool_node *varpool_node_for_decl (tree);
756 struct varpool_node *varpool_node_for_asm (tree asmname);
757 void varpool_mark_needed_node (struct varpool_node *);
758 void debug_varpool (void);
759 void dump_varpool (FILE *);
760 void dump_varpool_node (FILE *, struct varpool_node *);
762 void varpool_finalize_decl (tree);
763 bool decide_is_variable_needed (struct varpool_node *, tree);
764 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
765 void cgraph_make_node_local (struct cgraph_node *);
766 bool cgraph_node_can_be_local_p (struct cgraph_node *);
769 void varpool_remove_node (struct varpool_node *node);
770 void varpool_finalize_named_section_flags (struct varpool_node *node);
771 bool varpool_output_variables (void);
772 bool varpool_assemble_decl (struct varpool_node *node);
773 void varpool_analyze_node (struct varpool_node *);
774 struct varpool_node * varpool_extra_name_alias (tree, tree);
775 struct varpool_node * varpool_create_variable_alias (tree, tree);
776 void varpool_reset_queue (void);
777 bool const_value_known_p (tree);
778 bool varpool_for_node_and_aliases (struct varpool_node *,
779 bool (*) (struct varpool_node *, void *),
780 void *, bool);
781 void varpool_add_new_variable (tree);
782 void symtab_initialize_asm_name_hash (void);
783 void symtab_prevail_in_asm_name_hash (symtab_node node);
786 /* Return callgraph node for given symbol and check it is a function. */
787 static inline struct cgraph_node *
788 cgraph (symtab_node node)
790 gcc_checking_assert (!node || node->symbol.type == SYMTAB_FUNCTION);
791 return (struct cgraph_node *)node;
794 /* Return varpool node for given symbol and check it is a variable. */
795 static inline struct varpool_node *
796 varpool (symtab_node node)
798 gcc_checking_assert (!node || node->symbol.type == SYMTAB_VARIABLE);
799 return (struct varpool_node *)node;
802 /* Return callgraph node for given symbol and check it is a function. */
803 static inline struct cgraph_node *
804 cgraph_get_node (const_tree decl)
806 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
807 return cgraph (symtab_get_node (decl));
810 /* Return varpool node for given symbol and check it is a function. */
811 static inline struct varpool_node *
812 varpool_get_node (const_tree decl)
814 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
815 return varpool (symtab_get_node (decl));
818 /* Return asm name of cgraph node. */
819 static inline const char *
820 cgraph_node_asm_name(struct cgraph_node *node)
822 return symtab_node_asm_name ((symtab_node)node);
825 /* Return asm name of varpool node. */
826 static inline const char *
827 varpool_node_asm_name(struct varpool_node *node)
829 return symtab_node_asm_name ((symtab_node)node);
832 /* Return name of cgraph node. */
833 static inline const char *
834 cgraph_node_name(struct cgraph_node *node)
836 return symtab_node_name ((symtab_node)node);
839 /* Return name of varpool node. */
840 static inline const char *
841 varpool_node_name(struct varpool_node *node)
843 return symtab_node_name ((symtab_node)node);
846 /* Walk all symbols. */
847 #define FOR_EACH_SYMBOL(node) \
848 for ((node) = symtab_nodes; (node); (node) = (node)->symbol.next)
851 /* Return first variable. */
852 static inline struct varpool_node *
853 varpool_first_variable (void)
855 symtab_node node;
856 for (node = symtab_nodes; node; node = node->symbol.next)
857 if (varpool_node *vnode = dyn_cast <varpool_node> (node))
858 return vnode;
859 return NULL;
862 /* Return next variable after NODE. */
863 static inline struct varpool_node *
864 varpool_next_variable (struct varpool_node *node)
866 symtab_node node1 = (symtab_node) node->symbol.next;
867 for (; node1; node1 = node1->symbol.next)
868 if (varpool_node *vnode1 = dyn_cast <varpool_node> (node1))
869 return vnode1;
870 return NULL;
872 /* Walk all variables. */
873 #define FOR_EACH_VARIABLE(node) \
874 for ((node) = varpool_first_variable (); \
875 (node); \
876 (node) = varpool_next_variable ((node)))
878 /* Return first reachable static variable with initializer. */
879 static inline struct varpool_node *
880 varpool_first_static_initializer (void)
882 symtab_node node;
883 for (node = symtab_nodes; node; node = node->symbol.next)
885 varpool_node *vnode = dyn_cast <varpool_node> (node);
886 if (vnode && DECL_INITIAL (node->symbol.decl))
887 return vnode;
889 return NULL;
892 /* Return next reachable static variable with initializer after NODE. */
893 static inline struct varpool_node *
894 varpool_next_static_initializer (struct varpool_node *node)
896 symtab_node node1 = (symtab_node) node->symbol.next;
897 for (; node1; node1 = node1->symbol.next)
899 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
900 if (vnode1 && DECL_INITIAL (node1->symbol.decl))
901 return vnode1;
903 return NULL;
906 /* Walk all static variables with initializer set. */
907 #define FOR_EACH_STATIC_INITIALIZER(node) \
908 for ((node) = varpool_first_static_initializer (); (node); \
909 (node) = varpool_next_static_initializer (node))
911 /* Return first reachable static variable with initializer. */
912 static inline struct varpool_node *
913 varpool_first_defined_variable (void)
915 symtab_node node;
916 for (node = symtab_nodes; node; node = node->symbol.next)
918 varpool_node *vnode = dyn_cast <varpool_node> (node);
919 if (vnode && vnode->analyzed)
920 return vnode;
922 return NULL;
925 /* Return next reachable static variable with initializer after NODE. */
926 static inline struct varpool_node *
927 varpool_next_defined_variable (struct varpool_node *node)
929 symtab_node node1 = (symtab_node) node->symbol.next;
930 for (; node1; node1 = node1->symbol.next)
932 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
933 if (vnode1 && vnode1->analyzed)
934 return vnode1;
936 return NULL;
938 /* Walk all variables with definitions in current unit. */
939 #define FOR_EACH_DEFINED_VARIABLE(node) \
940 for ((node) = varpool_first_defined_variable (); (node); \
941 (node) = varpool_next_defined_variable (node))
943 /* Return first function with body defined. */
944 static inline struct cgraph_node *
945 cgraph_first_defined_function (void)
947 symtab_node node;
948 for (node = symtab_nodes; node; node = node->symbol.next)
950 cgraph_node *cn = dyn_cast <cgraph_node> (node);
951 if (cn && cn->analyzed)
952 return cn;
954 return NULL;
957 /* Return next function with body defined after NODE. */
958 static inline struct cgraph_node *
959 cgraph_next_defined_function (struct cgraph_node *node)
961 symtab_node node1 = (symtab_node) node->symbol.next;
962 for (; node1; node1 = node1->symbol.next)
964 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
965 if (cn1 && cn1->analyzed)
966 return cn1;
968 return NULL;
971 /* Walk all functions with body defined. */
972 #define FOR_EACH_DEFINED_FUNCTION(node) \
973 for ((node) = cgraph_first_defined_function (); (node); \
974 (node) = cgraph_next_defined_function ((node)))
976 /* Return first function. */
977 static inline struct cgraph_node *
978 cgraph_first_function (void)
980 symtab_node node;
981 for (node = symtab_nodes; node; node = node->symbol.next)
982 if (cgraph_node *cn = dyn_cast <cgraph_node> (node))
983 return cn;
984 return NULL;
987 /* Return next function. */
988 static inline struct cgraph_node *
989 cgraph_next_function (struct cgraph_node *node)
991 symtab_node node1 = (symtab_node) node->symbol.next;
992 for (; node1; node1 = node1->symbol.next)
993 if (cgraph_node *cn1 = dyn_cast <cgraph_node> (node1))
994 return cn1;
995 return NULL;
997 /* Walk all functions. */
998 #define FOR_EACH_FUNCTION(node) \
999 for ((node) = cgraph_first_function (); (node); \
1000 (node) = cgraph_next_function ((node)))
1002 /* Return true when NODE is a function with Gimple body defined
1003 in current unit. Functions can also be define externally or they
1004 can be thunks with no Gimple representation.
1006 Note that at WPA stage, the function body may not be present in memory. */
1008 static inline bool
1009 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1011 return node->analyzed && !node->thunk.thunk_p && !node->alias;
1014 /* Return first function with body defined. */
1015 static inline struct cgraph_node *
1016 cgraph_first_function_with_gimple_body (void)
1018 symtab_node node;
1019 for (node = symtab_nodes; node; node = node->symbol.next)
1021 cgraph_node *cn = dyn_cast <cgraph_node> (node);
1022 if (cn && cgraph_function_with_gimple_body_p (cn))
1023 return cn;
1025 return NULL;
1028 /* Return next reachable static variable with initializer after NODE. */
1029 static inline struct cgraph_node *
1030 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1032 symtab_node node1 = node->symbol.next;
1033 for (; node1; node1 = node1->symbol.next)
1035 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
1036 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1037 return cn1;
1039 return NULL;
1042 /* Walk all functions with body defined. */
1043 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1044 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1045 (node) = cgraph_next_function_with_gimple_body (node))
1047 /* Create a new static variable of type TYPE. */
1048 tree add_new_static_var (tree type);
1050 /* Return true if iterator CSI points to nothing. */
1051 static inline bool
1052 csi_end_p (cgraph_node_set_iterator csi)
1054 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
1057 /* Advance iterator CSI. */
1058 static inline void
1059 csi_next (cgraph_node_set_iterator *csi)
1061 csi->index++;
1064 /* Return the node pointed to by CSI. */
1065 static inline struct cgraph_node *
1066 csi_node (cgraph_node_set_iterator csi)
1068 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
1071 /* Return an iterator to the first node in SET. */
1072 static inline cgraph_node_set_iterator
1073 csi_start (cgraph_node_set set)
1075 cgraph_node_set_iterator csi;
1077 csi.set = set;
1078 csi.index = 0;
1079 return csi;
1082 /* Return true if SET contains NODE. */
1083 static inline bool
1084 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1086 cgraph_node_set_iterator csi;
1087 csi = cgraph_node_set_find (set, node);
1088 return !csi_end_p (csi);
1091 /* Return number of nodes in SET. */
1092 static inline size_t
1093 cgraph_node_set_size (cgraph_node_set set)
1095 return VEC_length (cgraph_node_ptr, set->nodes);
1098 /* Return true if iterator VSI points to nothing. */
1099 static inline bool
1100 vsi_end_p (varpool_node_set_iterator vsi)
1102 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
1105 /* Advance iterator VSI. */
1106 static inline void
1107 vsi_next (varpool_node_set_iterator *vsi)
1109 vsi->index++;
1112 /* Return the node pointed to by VSI. */
1113 static inline struct varpool_node *
1114 vsi_node (varpool_node_set_iterator vsi)
1116 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
1119 /* Return an iterator to the first node in SET. */
1120 static inline varpool_node_set_iterator
1121 vsi_start (varpool_node_set set)
1123 varpool_node_set_iterator vsi;
1125 vsi.set = set;
1126 vsi.index = 0;
1127 return vsi;
1130 /* Return true if SET contains NODE. */
1131 static inline bool
1132 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
1134 varpool_node_set_iterator vsi;
1135 vsi = varpool_node_set_find (set, node);
1136 return !vsi_end_p (vsi);
1139 /* Return number of nodes in SET. */
1140 static inline size_t
1141 varpool_node_set_size (varpool_node_set set)
1143 return VEC_length (varpool_node_ptr, set->nodes);
1146 /* Uniquize all constants that appear in memory.
1147 Each constant in memory thus far output is recorded
1148 in `const_desc_table'. */
1150 struct GTY(()) constant_descriptor_tree {
1151 /* A MEM for the constant. */
1152 rtx rtl;
1154 /* The value of the constant. */
1155 tree value;
1157 /* Hash of value. Computing the hash from value each time
1158 hashfn is called can't work properly, as that means recursive
1159 use of the hash table during hash table expansion. */
1160 hashval_t hash;
1163 /* Return true if set is nonempty. */
1164 static inline bool
1165 cgraph_node_set_nonempty_p (cgraph_node_set set)
1167 return !VEC_empty (cgraph_node_ptr, set->nodes);
1170 /* Return true if set is nonempty. */
1171 static inline bool
1172 varpool_node_set_nonempty_p (varpool_node_set set)
1174 return !VEC_empty (varpool_node_ptr, set->nodes);
1177 /* Return true when function NODE is only called directly or it has alias.
1178 i.e. it is not externally visible, address was not taken and
1179 it is not used in any other non-standard way. */
1181 static inline bool
1182 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1184 gcc_assert (!node->global.inlined_to);
1185 return (!node->symbol.force_output && !node->symbol.address_taken
1186 && !node->symbol.used_from_other_partition
1187 && !DECL_STATIC_CONSTRUCTOR (node->symbol.decl)
1188 && !DECL_STATIC_DESTRUCTOR (node->symbol.decl)
1189 && !node->symbol.externally_visible);
1192 /* Return true when function NODE can be removed from callgraph
1193 if all direct calls are eliminated. */
1195 static inline bool
1196 varpool_can_remove_if_no_refs (struct varpool_node *node)
1198 if (DECL_EXTERNAL (node->symbol.decl))
1199 return true;
1200 return (!node->symbol.force_output && !node->symbol.used_from_other_partition
1201 && ((DECL_COMDAT (node->symbol.decl)
1202 && !symtab_used_from_object_file_p ((symtab_node) node))
1203 || !node->symbol.externally_visible
1204 || DECL_HAS_VALUE_EXPR_P (node->symbol.decl)));
1207 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1208 i.e. if the variable is not externally visible or not used in some magic
1209 way (asm statement or such).
1210 The magic uses are all summarized in force_output flag. */
1212 static inline bool
1213 varpool_all_refs_explicit_p (struct varpool_node *vnode)
1215 return (vnode->analyzed
1216 && !vnode->symbol.externally_visible
1217 && !vnode->symbol.used_from_other_partition
1218 && !vnode->symbol.force_output);
1221 /* Constant pool accessor function. */
1222 htab_t constant_pool_htab (void);
1224 /* FIXME: inappropriate dependency of cgraph on IPA. */
1225 #include "ipa-ref-inline.h"
1227 /* Return node that alias N is aliasing. */
1229 static inline struct cgraph_node *
1230 cgraph_alias_aliased_node (struct cgraph_node *n)
1232 struct ipa_ref *ref;
1234 ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref);
1235 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1236 if (is_a <cgraph_node> (ref->referred))
1237 return ipa_ref_node (ref);
1238 return NULL;
1241 /* Return node that alias N is aliasing. */
1243 static inline struct varpool_node *
1244 varpool_alias_aliased_node (struct varpool_node *n)
1246 struct ipa_ref *ref;
1248 ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref);
1249 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1250 if (is_a <varpool_node> (ref->referred))
1251 return ipa_ref_varpool_node (ref);
1252 return NULL;
1255 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1256 Walk through thunk, too.
1257 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1259 static inline struct cgraph_node *
1260 cgraph_function_node (struct cgraph_node *node, enum availability *availability)
1262 if (availability)
1263 *availability = cgraph_function_body_availability (node);
1264 while (node)
1266 if (node->alias && node->analyzed)
1267 node = cgraph_alias_aliased_node (node);
1268 else if (node->thunk.thunk_p)
1269 node = node->callees->callee;
1270 else
1271 return node;
1272 if (node && availability)
1274 enum availability a;
1275 a = cgraph_function_body_availability (node);
1276 if (a < *availability)
1277 *availability = a;
1280 if (availability)
1281 *availability = AVAIL_NOT_AVAILABLE;
1282 return NULL;
1285 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1286 Do not walk through thunks.
1287 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1289 static inline struct cgraph_node *
1290 cgraph_function_or_thunk_node (struct cgraph_node *node, enum availability *availability)
1292 if (availability)
1293 *availability = cgraph_function_body_availability (node);
1294 while (node)
1296 if (node->alias && node->analyzed)
1297 node = cgraph_alias_aliased_node (node);
1298 else
1299 return node;
1300 if (node && availability)
1302 enum availability a;
1303 a = cgraph_function_body_availability (node);
1304 if (a < *availability)
1305 *availability = a;
1308 if (availability)
1309 *availability = AVAIL_NOT_AVAILABLE;
1310 return NULL;
1313 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1314 Do not walk through thunks.
1315 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1317 static inline struct varpool_node *
1318 varpool_variable_node (struct varpool_node *node, enum availability *availability)
1320 if (availability)
1321 *availability = cgraph_variable_initializer_availability (node);
1322 while (node)
1324 if (node->alias && node->analyzed)
1325 node = varpool_alias_aliased_node (node);
1326 else
1327 return node;
1328 if (node && availability)
1330 enum availability a;
1331 a = cgraph_variable_initializer_availability (node);
1332 if (a < *availability)
1333 *availability = a;
1336 if (availability)
1337 *availability = AVAIL_NOT_AVAILABLE;
1338 return NULL;
1341 /* Return true when the edge E represents a direct recursion. */
1342 static inline bool
1343 cgraph_edge_recursive_p (struct cgraph_edge *e)
1345 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1346 if (e->caller->global.inlined_to)
1347 return e->caller->global.inlined_to->symbol.decl == callee->symbol.decl;
1348 else
1349 return e->caller->symbol.decl == callee->symbol.decl;
1352 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1353 static inline bool
1354 decl_is_tm_clone (const_tree fndecl)
1356 struct cgraph_node *n = cgraph_get_node (fndecl);
1357 if (n)
1358 return n->tm_clone;
1359 return false;
1362 /* Likewise indicate that a node is needed, i.e. reachable via some
1363 external means. */
1365 static inline void
1366 cgraph_mark_force_output_node (struct cgraph_node *node)
1368 node->symbol.force_output = 1;
1369 gcc_checking_assert (!node->global.inlined_to);
1372 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1373 or extern function kept around just for inlining. */
1375 static inline bool
1376 symtab_real_symbol_p (symtab_node node)
1378 struct cgraph_node *cnode;
1379 struct ipa_ref *ref;
1381 if (!is_a <cgraph_node> (node))
1382 return true;
1383 cnode = cgraph (node);
1384 if (cnode->global.inlined_to)
1385 return false;
1386 if (cnode->abstract_and_needed)
1387 return false;
1388 /* We keep virtual clones in symtab. */
1389 if (!cnode->analyzed
1390 || DECL_EXTERNAL (cnode->symbol.decl))
1391 return (cnode->callers
1392 || ipa_ref_list_referring_iterate (&cnode->symbol.ref_list, 0, ref));
1393 return true;
1395 #endif /* GCC_CGRAPH_H */