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