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