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