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