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