]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cgraph.h
ipa-devirt.c (odr_subtypes_equivalent_p): Disable temporary hack forgotten in previou...
[thirdparty/gcc.git] / gcc / cgraph.h
CommitLineData
1c4a429a 1/* Callgraph handling code.
23a5b65a 2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
1c4a429a
JH
3 Contributed by Jan Hubicka
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
1c4a429a
JH
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
1c4a429a
JH
20
21#ifndef GCC_CGRAPH_H
22#define GCC_CGRAPH_H
7a8cba34 23
5d59b5e1 24#include "is-a.h"
051f8cc6 25#include "plugin-api.h"
7a8cba34 26#include "vec.h"
4d648807 27#include "basic-block.h"
7a8cba34 28#include "function.h"
1f00098b
JH
29#include "ipa-ref.h"
30
31/* Symbol table consists of functions and variables.
e70670cf 32 TODO: add labels and CONST_DECLs. */
1f00098b
JH
33enum symtab_type
34{
960bfb69 35 SYMTAB_SYMBOL,
1f00098b
JH
36 SYMTAB_FUNCTION,
37 SYMTAB_VARIABLE
38};
39
f961457f
JH
40/* Section names are stored as reference counted strings in GGC safe hashtable
41 (to make them survive through PCH). */
42
43struct GTY(()) section_hash_entry_d
44{
45 int ref_count;
46 char *name; /* As long as this datastructure stays in GGC, we can not put
47 string at the tail of structure of GGC dies in horrible
48 way */
49};
50
51typedef struct section_hash_entry_d section_hash_entry;
52
1f00098b
JH
53/* Base of all entries in the symbol table.
54 The symtab_node is inherited by cgraph and varpol nodes. */
a3bfa8b8
DM
55class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
56 chain_next ("%h.next"), chain_prev ("%h.previous")))
5e20cdc9 57 symtab_node
1f00098b 58{
a3bfa8b8 59public:
fec39fa6
TS
60 /* Return name. */
61 const char *name () const;
62
63 /* Return asm name. */
64 const char * asm_name () const;
65
1f00098b 66 /* Type of the symbol. */
b8dbdb12
RG
67 ENUM_BITFIELD (symtab_type) type : 8;
68
69 /* The symbols resolution. */
70 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
71
e70670cf
JH
72 /*** Flags representing the symbol type. ***/
73
74 /* True when symbol corresponds to a definition in current unit.
75 set via cgraph_finalize_function or varpool_finalize_decl */
76 unsigned definition : 1;
77 /* True when symbol is an alias.
78 Set by assemble_alias. */
79 unsigned alias : 1;
08346abd
JH
80 /* True when alias is a weakref. */
81 unsigned weakref : 1;
40a7fe1e 82 /* C++ frontend produce same body aliases and extra name aliases for
688010ba 83 virtual functions and vtables that are obviously equivalent.
40a7fe1e
JH
84 Those aliases are bit special, especially because C++ frontend
85 visibility code is so ugly it can not get them right at first time
86 and their visibility needs to be copied from their "masters" at
87 the end of parsing. */
88 unsigned cpp_implicit_alias : 1;
e70670cf
JH
89 /* Set once the definition was analyzed. The list of references and
90 other properties are built during analysis. */
91 unsigned analyzed : 1;
6de88c6a
JH
92 /* Set for write-only variables. */
93 unsigned writeonly : 1;
e70670cf
JH
94
95
96 /*** Visibility and linkage flags. ***/
97
b8dbdb12
RG
98 /* Set when function is visible by other units. */
99 unsigned externally_visible : 1;
4bcfd75c 100 /* The symbol will be assumed to be used in an invisible way (like
edb983b2 101 by an toplevel asm statement). */
b8dbdb12 102 unsigned force_output : 1;
edb983b2
JH
103 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
104 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
105 to static and it does not inhibit optimization. */
106 unsigned forced_by_abi : 1;
702d8703
JH
107 /* True when the name is known to be unique and thus it does not need mangling. */
108 unsigned unique_name : 1;
e257a17c
JH
109 /* Specify whether the section was set by user or by
110 compiler via -ffunction-sections. */
111 unsigned implicit_section : 1;
3d8d0043
MJ
112 /* True when body and other characteristics have been removed by
113 symtab_remove_unreachable_nodes. */
114 unsigned body_removed : 1;
b8dbdb12 115
e70670cf
JH
116 /*** WHOPR Partitioning flags.
117 These flags are used at ltrans stage when only part of the callgraph is
118 available. ***/
b8dbdb12 119
e70670cf
JH
120 /* Set when variable is used from other LTRANS partition. */
121 unsigned used_from_other_partition : 1;
122 /* Set when function is available in the other LTRANS partition.
123 During WPA output it is used to mark nodes that are present in
124 multiple partitions. */
125 unsigned in_other_partition : 1;
b8dbdb12 126
b8dbdb12 127
e70670cf
JH
128
129 /*** other flags. ***/
130
131 /* Set when symbol has address taken. */
132 unsigned address_taken : 1;
569b1784
JH
133 /* Set when init priority is set. */
134 unsigned in_init_priority_hash : 1;
e70670cf
JH
135
136
137 /* Ordering of all symtab entries. */
138 int order;
139
140 /* Declaration representing the symbol. */
141 tree decl;
960bfb69 142
2aae7680 143 /* Linked list of symbol table entries starting with symtab_nodes. */
5e20cdc9
DM
144 symtab_node *next;
145 symtab_node *previous;
e70670cf 146
1ab24192 147 /* Linked list of symbols with the same asm name. There may be multiple
e70670cf
JH
148 entries for single symbol name during LTO, because symbols are renamed
149 only after partitioning.
150
151 Because inline clones are kept in the assembler name has, they also produce
152 duplicate entries.
153
154 There are also several long standing bugs where frontends and builtin
155 code produce duplicated decls. */
5e20cdc9
DM
156 symtab_node *next_sharing_asm_name;
157 symtab_node *previous_sharing_asm_name;
2aae7680 158
e70670cf 159 /* Circular list of nodes in the same comdat group if non-NULL. */
5e20cdc9 160 symtab_node *same_comdat_group;
e70670cf 161
aede2c10
JH
162 /* Return comdat group. */
163 tree get_comdat_group ()
164 {
f961457f 165 return x_comdat_group;
aede2c10
JH
166 }
167
569b1784 168 /* Return comdat group as identifier_node. */
d67ff7b7
JM
169 tree get_comdat_group_id ()
170 {
f961457f
JH
171 if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE)
172 x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group);
173 return x_comdat_group;
d67ff7b7
JM
174 }
175
aede2c10
JH
176 /* Set comdat group. */
177 void set_comdat_group (tree group)
178 {
24d047a3
JH
179 gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE
180 || DECL_P (group));
f961457f 181 x_comdat_group = group;
24d047a3
JH
182 }
183
e257a17c
JH
184 /* Return section as string. */
185 const char * get_section ()
186 {
f961457f 187 if (!x_section)
e257a17c 188 return NULL;
f961457f 189 return x_section->name;
24d047a3
JH
190 }
191
d122681a
ML
192 /* Return ipa reference from this symtab_node to
193 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
194 of the use and STMT the statement (if it exists). */
195 struct ipa_ref *add_reference (symtab_node *referred_node,
196 enum ipa_ref_use use_type);
197
198 /* Return ipa reference from this symtab_node to
199 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
200 of the use and STMT the statement (if it exists). */
201 struct ipa_ref *add_reference (symtab_node *referred_node,
202 enum ipa_ref_use use_type, gimple stmt);
203
204 /* If VAL is a reference to a function or a variable, add a reference from
205 this symtab_node to the corresponding symbol table node. USE_TYPE specify
206 type of the use and STMT the statement (if it exists). Return the new
207 reference or NULL if none was created. */
208 struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type,
209 gimple stmt);
210
211 /* Clone all references from symtab NODE to this symtab_node. */
212 void clone_references (symtab_node *node);
213
214 /* Remove all stmt references in non-speculative references.
215 Those are not maintained during inlining & clonning.
216 The exception are speculative references that are updated along
217 with callgraph edges associated with them. */
218 void clone_referring (symtab_node *node);
219
220 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
221 struct ipa_ref *clone_reference (struct ipa_ref *ref, gimple stmt);
222
223 /* Find the structure describing a reference to REFERRED_NODE
224 and associated with statement STMT. */
225 struct ipa_ref *find_reference (symtab_node *, gimple, unsigned int);
226
227 /* Remove all references that are associated with statement STMT. */
228 void remove_stmt_references (gimple stmt);
229
230 /* Remove all stmt references in non-speculative references.
231 Those are not maintained during inlining & clonning.
232 The exception are speculative references that are updated along
233 with callgraph edges associated with them. */
234 void clear_stmts_in_references (void);
235
236 /* Remove all references in ref list. */
237 void remove_all_references (void);
238
239 /* Remove all referring items in ref list. */
240 void remove_all_referring (void);
241
242 /* Dump references in ref list to FILE. */
243 void dump_references (FILE *file);
244
245 /* Dump referring in list to FILE. */
246 void dump_referring (FILE *);
247
248 /* Return true if list contains an alias. */
249 bool has_aliases_p (void);
250
251 /* Iterates I-th reference in the list, REF is also set. */
252 struct ipa_ref *iterate_reference (unsigned i, struct ipa_ref *&ref);
253
254 /* Iterates I-th referring item in the list, REF is also set. */
255 struct ipa_ref *iterate_referring (unsigned i, struct ipa_ref *&ref);
256
e55637b7
ML
257 /* Iterates I-th referring alias item in the list, REF is also set. */
258 struct ipa_ref *iterate_direct_aliases (unsigned i, struct ipa_ref *&ref);
259
e70670cf
JH
260 /* Vectors of referring and referenced entities. */
261 struct ipa_ref_list ref_list;
262
40a7fe1e
JH
263 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
264 depending to what was known to frontend on the creation time.
265 Once alias is resolved, this pointer become NULL. */
266 tree alias_target;
267
e70670cf
JH
268 /* File stream where this node is being written to. */
269 struct lto_file_decl_data * lto_file_data;
270
960bfb69 271 PTR GTY ((skip)) aux;
aede2c10
JH
272
273 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
f961457f 274 tree x_comdat_group;
24d047a3
JH
275
276 /* Section name. Again can be private, if allowed. */
f961457f 277 section_hash_entry *x_section;
e257a17c
JH
278
279 /* Set section for symbol and its aliases. */
f961457f
JH
280 void set_section (const char *section);
281 void set_section_for_node (const char *section);
569b1784
JH
282
283 void set_init_priority (priority_type priority);
284 priority_type get_init_priority ();
1f00098b 285};
1c4a429a 286
e55637b7
ML
287/* Walk all aliases for NODE. */
288#define FOR_EACH_ALIAS(node, alias) \
289 for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++)
290
6b02a499
JH
291enum availability
292{
293 /* Not yet set by cgraph_function_body_availability. */
294 AVAIL_UNSET,
295 /* Function body/variable initializer is unknown. */
296 AVAIL_NOT_AVAILABLE,
297 /* Function body/variable initializer is known but might be replaced
298 by a different one from other compilation unit and thus needs to
299 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
300 arbitrary side effects on escaping variables and functions, while
301 like AVAILABLE it might access static variables. */
302 AVAIL_OVERWRITABLE,
303 /* Function body/variable initializer is known and will be used in final
304 program. */
305 AVAIL_AVAILABLE,
306 /* Function body/variable initializer is known and all it's uses are explicitly
307 visible within current unit (ie it's address is never taken and it is not
308 exported to other units).
309 Currently used only for functions. */
310 AVAIL_LOCAL
311};
312
d7f09764
DN
313/* This is the information that is put into the cgraph local structure
314 to recover a function. */
315struct lto_file_decl_data;
316
8a4a83ed 317extern const char * const cgraph_availability_names[];
430c6ceb 318extern const char * const ld_plugin_symbol_resolution_names[];
714c800f 319extern const char * const tls_model_names[];
8a4a83ed 320
6744a6ab
JH
321/* Information about thunk, used only for same body aliases. */
322
323struct GTY(()) cgraph_thunk_info {
324 /* Information about the thunk. */
325 HOST_WIDE_INT fixed_offset;
326 HOST_WIDE_INT virtual_value;
327 tree alias;
328 bool this_adjusting;
329 bool virtual_offset_p;
330 /* Set to true when alias node is thunk. */
331 bool thunk_p;
332};
333
dafc5b82 334/* Information about the function collected locally.
25c84396 335 Available after function is analyzed. */
dafc5b82 336
d1b38208 337struct GTY(()) cgraph_local_info {
e0bb17a8 338 /* Set when function function is visible in current compilation unit only
e2209b03 339 and its address is never taken. */
b4e19405 340 unsigned local : 1;
6674a6ce 341
124f1be6
MJ
342 /* False when there is something makes versioning impossible. */
343 unsigned versionable : 1;
344
61e03ffc
JH
345 /* False when function calling convention and signature can not be changed.
346 This is the case when __builtin_apply_args is used. */
347 unsigned can_change_signature : 1;
348
95c755e9
JH
349 /* True when the function has been originally extern inline, but it is
350 redefined now. */
b4e19405 351 unsigned redefined_extern_inline : 1;
0a35513e
AH
352
353 /* True if the function may enter serial irrevocable mode. */
354 unsigned tm_may_enter_irr : 1;
dafc5b82
JH
355};
356
357/* Information about the function that needs to be computed globally
726a989a 358 once compilation is finished. Available only with -funit-at-a-time. */
dafc5b82 359
d1b38208 360struct GTY(()) cgraph_global_info {
726a989a
RB
361 /* For inline clones this points to the function they will be
362 inlined into. */
18c6ada9 363 struct cgraph_node *inlined_to;
dafc5b82
JH
364};
365
b255a036
JH
366/* Information about the function that is propagated by the RTL backend.
367 Available only for functions that has been already assembled. */
368
d1b38208 369struct GTY(()) cgraph_rtl_info {
17b29c0a 370 unsigned int preferred_incoming_stack_boundary;
27c07cc5
RO
371
372 /* Call unsaved hard registers really used by the corresponding
373 function (including ones used by functions called by the
374 function). */
375 HARD_REG_SET function_used_regs;
376 /* Set if function_used_regs is valid. */
377 unsigned function_used_regs_valid: 1;
b255a036
JH
378};
379
9187e02d
JH
380/* Represent which DECL tree (or reference to such tree)
381 will be replaced by another tree while versioning. */
382struct GTY(()) ipa_replace_map
383{
384 /* The tree that will be replaced. */
385 tree old_tree;
386 /* The new (replacing) tree. */
387 tree new_tree;
922f15c2
JH
388 /* Parameter number to replace, when old_tree is NULL. */
389 int parm_num;
9187e02d
JH
390 /* True when a substitution should be done, false otherwise. */
391 bool replace_p;
392 /* True when we replace a reference to old_tree. */
393 bool ref_p;
394};
395typedef struct ipa_replace_map *ipa_replace_map_p;
9187e02d
JH
396
397struct GTY(()) cgraph_clone_info
398{
9771b263 399 vec<ipa_replace_map_p, va_gc> *tree_map;
9187e02d 400 bitmap args_to_skip;
08ad1d6d 401 bitmap combined_args_to_skip;
9187e02d
JH
402};
403
0136f8f0
AH
404enum cgraph_simd_clone_arg_type
405{
406 SIMD_CLONE_ARG_TYPE_VECTOR,
407 SIMD_CLONE_ARG_TYPE_UNIFORM,
408 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
409 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
410 SIMD_CLONE_ARG_TYPE_MASK
411};
412
413/* Function arguments in the original function of a SIMD clone.
414 Supplementary data for `struct simd_clone'. */
415
416struct GTY(()) cgraph_simd_clone_arg {
417 /* Original function argument as it originally existed in
418 DECL_ARGUMENTS. */
419 tree orig_arg;
420
421 /* orig_arg's function (or for extern functions type from
422 TYPE_ARG_TYPES). */
423 tree orig_type;
424
425 /* If argument is a vector, this holds the vector version of
426 orig_arg that after adjusting the argument types will live in
427 DECL_ARGUMENTS. Otherwise, this is NULL.
428
429 This basically holds:
430 vector(simdlen) __typeof__(orig_arg) new_arg. */
431 tree vector_arg;
432
433 /* vector_arg's type (or for extern functions new vector type. */
434 tree vector_type;
435
436 /* If argument is a vector, this holds the array where the simd
437 argument is held while executing the simd clone function. This
438 is a local variable in the cloned function. Its content is
439 copied from vector_arg upon entry to the clone.
440
441 This basically holds:
442 __typeof__(orig_arg) simd_array[simdlen]. */
443 tree simd_array;
444
445 /* A SIMD clone's argument can be either linear (constant or
446 variable), uniform, or vector. */
447 enum cgraph_simd_clone_arg_type arg_type;
448
449 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
450 the constant linear step, if arg_type is
451 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
452 the uniform argument holding the step, otherwise 0. */
453 HOST_WIDE_INT linear_step;
454
455 /* Variable alignment if available, otherwise 0. */
456 unsigned int alignment;
457};
458
459/* Specific data for a SIMD function clone. */
460
461struct GTY(()) cgraph_simd_clone {
462 /* Number of words in the SIMD lane associated with this clone. */
463 unsigned int simdlen;
464
465 /* Number of annotated function arguments in `args'. This is
466 usually the number of named arguments in FNDECL. */
467 unsigned int nargs;
468
469 /* Max hardware vector size in bits for integral vectors. */
470 unsigned int vecsize_int;
471
472 /* Max hardware vector size in bits for floating point vectors. */
473 unsigned int vecsize_float;
474
475 /* The mangling character for a given vector size. This is is used
476 to determine the ISA mangling bit as specified in the Intel
477 Vector ABI. */
478 unsigned char vecsize_mangle;
479
480 /* True if this is the masked, in-branch version of the clone,
481 otherwise false. */
482 unsigned int inbranch : 1;
483
484 /* True if this is a Cilk Plus variant. */
485 unsigned int cilk_elemental : 1;
486
487 /* Doubly linked list of SIMD clones. */
488 struct cgraph_node *prev_clone, *next_clone;
489
490 /* Original cgraph node the SIMD clones were created for. */
491 struct cgraph_node *origin;
492
493 /* Annotated function arguments for the original function. */
494 struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
495};
496
5fefcf92 497
ba228239 498/* The cgraph data structure.
e0bb17a8 499 Each function decl has assigned cgraph_node listing callees and callers. */
1c4a429a 500
5e20cdc9 501struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
a3bfa8b8 502public:
1c4a429a
JH
503 struct cgraph_edge *callees;
504 struct cgraph_edge *callers;
e33c6cd6
MJ
505 /* List of edges representing indirect calls with a yet undetermined
506 callee. */
507 struct cgraph_edge *indirect_calls;
1c4a429a 508 /* For nested functions points to function the node is nested in. */
a3bfa8b8 509 struct cgraph_node *origin;
1c4a429a 510 /* Points to first nested function, if any. */
a3bfa8b8 511 struct cgraph_node *nested;
1c4a429a 512 /* Pointer to the next function with same origin, if any. */
a3bfa8b8 513 struct cgraph_node *next_nested;
18c6ada9 514 /* Pointer to the next clone. */
9187e02d
JH
515 struct cgraph_node *next_sibling_clone;
516 struct cgraph_node *prev_sibling_clone;
517 struct cgraph_node *clones;
518 struct cgraph_node *clone_of;
70d539ce
JH
519 /* For functions with many calls sites it holds map from call expression
520 to the edge to speed up cgraph_edge function. */
521 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
97ba0040
JH
522 /* Declaration node used to be clone of. */
523 tree former_clone_of;
c22cacf3 524
0136f8f0
AH
525 /* If this is a SIMD clone, this points to the SIMD specific
526 information for it. */
527 struct cgraph_simd_clone *simdclone;
528 /* If this function has SIMD clones, this points to the first clone. */
529 struct cgraph_node *simd_clones;
530
0e3776db
JH
531 /* Interprocedural passes scheduled to have their transform functions
532 applied next time we execute local pass on them. We maintain it
533 per-function in order to allow IPA passes to introduce new functions. */
9771b263 534 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
0e3776db 535
95c755e9
JH
536 struct cgraph_local_info local;
537 struct cgraph_global_info global;
538 struct cgraph_rtl_info rtl;
9187e02d 539 struct cgraph_clone_info clone;
6744a6ab 540 struct cgraph_thunk_info thunk;
c22cacf3 541
e42922b1
JH
542 /* Expected number of executions: calculated in profile.c. */
543 gcov_type count;
db0bf14f
JH
544 /* How to scale counts at materialization time; used to merge
545 LTO units with different number of profile runs. */
546 int count_materialization_scale;
95c755e9
JH
547 /* Unique id of the node. */
548 int uid;
2fa3d31b
JH
549 /* ID assigned by the profiling. */
550 unsigned int profile_id;
86ce5d2f
ML
551 /* Time profiler: first run of function. */
552 int tp_first_run;
3691626c 553
6b20f353
DS
554 /* Set when decl is an abstract function pointed to by the
555 ABSTRACT_DECL_ORIGIN of a reachable function. */
c0c123ef 556 unsigned used_as_abstract_origin : 1;
50674e96 557 /* Set once the function is lowered (i.e. its CFG is built). */
b4e19405 558 unsigned lowered : 1;
25c84396
RH
559 /* Set once the function has been instantiated and its callee
560 lists created. */
257eb6e3 561 unsigned process : 1;
5fefcf92
JH
562 /* How commonly executed the node is. Initialized during branch
563 probabilities pass. */
564 ENUM_BITFIELD (node_frequency) frequency : 2;
844db5d0
JH
565 /* True when function can only be called at startup (from static ctor). */
566 unsigned only_called_at_startup : 1;
567 /* True when function can only be called at startup (from static dtor). */
568 unsigned only_called_at_exit : 1;
0a35513e
AH
569 /* True when function is the transactional clone of a function which
570 is called only from inside transactions. */
571 /* ?? We should be able to remove this. We have enough bits in
572 cgraph to calculate it. */
573 unsigned tm_clone : 1;
3649b9b7
ST
574 /* True if this decl is a dispatcher for function versions. */
575 unsigned dispatcher_function : 1;
1f26ac87
JM
576 /* True if this decl calls a COMDAT-local function. This is set up in
577 compute_inline_parameters and inline_call. */
578 unsigned calls_comdat_local : 1;
569b1784
JH
579
580 void set_fini_priority (priority_type priority);
581 priority_type get_fini_priority ();
1c4a429a
JH
582};
583
7380e6ef 584
fed5ae11
DK
585typedef struct cgraph_node *cgraph_node_ptr;
586
fed5ae11 587
3649b9b7
ST
588/* Function Multiversioning info. */
589struct GTY(()) cgraph_function_version_info {
590 /* The cgraph_node for which the function version info is stored. */
591 struct cgraph_node *this_node;
592 /* Chains all the semantically identical function versions. The
593 first function in this chain is the version_info node of the
594 default function. */
595 struct cgraph_function_version_info *prev;
596 /* If this version node corresponds to a dispatcher for function
597 versions, this points to the version info node of the default
598 function, the first node in the chain. */
599 struct cgraph_function_version_info *next;
600 /* If this node corresponds to a function version, this points
601 to the dispatcher function decl, which is the function that must
602 be called to execute the right function version at run-time.
603
604 If this cgraph node is a dispatcher (if dispatcher_function is
605 true, in the cgraph_node struct) for function versions, this
606 points to resolver function, which holds the function body of the
607 dispatcher. The dispatcher decl is an alias to the resolver
608 function decl. */
609 tree dispatcher_resolver;
610};
611
612/* Get the cgraph_function_version_info node corresponding to node. */
613struct cgraph_function_version_info *
614 get_cgraph_node_version (struct cgraph_node *node);
615
616/* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
617 corresponding to cgraph_node NODE. */
618struct cgraph_function_version_info *
619 insert_new_cgraph_node_version (struct cgraph_node *node);
620
621/* Record that DECL1 and DECL2 are semantically identical function
622 versions. */
623void record_function_versions (tree decl1, tree decl2);
624
625/* Remove the cgraph_function_version_info and cgraph_node for DECL. This
626 DECL is a duplicate declaration. */
627void delete_function_version (tree decl);
628
fed5ae11
DK
629/* A cgraph node set is a collection of cgraph nodes. A cgraph node
630 can appear in multiple sets. */
1cb1a99f 631struct cgraph_node_set_def
fed5ae11 632{
1cb1a99f 633 struct pointer_map_t *map;
9771b263 634 vec<cgraph_node_ptr> nodes;
fed5ae11
DK
635};
636
2c8326a5
OE
637class varpool_node;
638typedef varpool_node *varpool_node_ptr;
2942c502 639
2942c502
JH
640
641/* A varpool node set is a collection of varpool nodes. A varpool node
642 can appear in multiple sets. */
1cb1a99f 643struct varpool_node_set_def
2942c502 644{
1cb1a99f 645 struct pointer_map_t * map;
9771b263 646 vec<varpool_node_ptr> nodes;
2942c502
JH
647};
648
fed5ae11
DK
649typedef struct cgraph_node_set_def *cgraph_node_set;
650
fed5ae11 651
2942c502
JH
652typedef struct varpool_node_set_def *varpool_node_set;
653
2942c502 654
fed5ae11 655/* Iterator structure for cgraph node sets. */
84562394 656struct cgraph_node_set_iterator
fed5ae11
DK
657{
658 cgraph_node_set set;
659 unsigned index;
84562394 660};
fed5ae11 661
2942c502 662/* Iterator structure for varpool node sets. */
84562394 663struct varpool_node_set_iterator
2942c502
JH
664{
665 varpool_node_set set;
666 unsigned index;
84562394 667};
2942c502 668
1cf11770 669#define DEFCIFCODE(code, type, string) CIF_ ## code,
61a05df1 670/* Reasons for inlining failures. */
84562394 671enum cgraph_inline_failed_t {
61a05df1
JH
672#include "cif-code.def"
673 CIF_N_REASONS
84562394 674};
61a05df1 675
1cf11770
L
676enum cgraph_inline_failed_type_t
677{
678 CIF_FINAL_NORMAL = 0,
679 CIF_FINAL_ERROR
680};
681
e33c6cd6
MJ
682/* Structure containing additional information about an indirect call. */
683
684struct GTY(()) cgraph_indirect_call_info
685{
8b7773a4
MJ
686 /* When polymorphic is set, this field contains offset where the object which
687 was actually used in the polymorphic resides within a larger structure.
688 If agg_contents is set, the field contains the offset within the aggregate
689 from which the address to call was loaded. */
690 HOST_WIDE_INT offset;
b258210c
MJ
691 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
692 HOST_WIDE_INT otr_token;
693 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
68377e53 694 tree otr_type, outer_type;
e33c6cd6
MJ
695 /* Index of the parameter that is called. */
696 int param_index;
5f902d76
JH
697 /* ECF flags determined from the caller. */
698 int ecf_flags;
634ab819
JH
699 /* Profile_id of common target obtrained from profile. */
700 int common_target_id;
701 /* Probability that call will land in function with COMMON_TARGET_ID. */
702 int common_target_probability;
b258210c
MJ
703
704 /* Set when the call is a virtual call with the parameter being the
705 associated object pointer rather than a simple direct call. */
706 unsigned polymorphic : 1;
8b7773a4
MJ
707 /* Set when the call is a call of a pointer loaded from contents of an
708 aggregate at offset. */
709 unsigned agg_contents : 1;
c13bc3d9
MJ
710 /* Set when this is a call through a member pointer. */
711 unsigned member_ptr : 1;
8b7773a4
MJ
712 /* When the previous bit is set, this one determines whether the destination
713 is loaded from a parameter passed by reference. */
714 unsigned by_ref : 1;
68377e53
JH
715 unsigned int maybe_in_construction : 1;
716 unsigned int maybe_derived_type : 1;
e33c6cd6
MJ
717};
718
d1b38208 719struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
6009ee7b
MJ
720 /* Expected number of executions: calculated in profile.c. */
721 gcov_type count;
ed2df68b
JH
722 struct cgraph_node *caller;
723 struct cgraph_node *callee;
2563c224 724 struct cgraph_edge *prev_caller;
1c4a429a 725 struct cgraph_edge *next_caller;
2563c224 726 struct cgraph_edge *prev_callee;
1c4a429a 727 struct cgraph_edge *next_callee;
726a989a 728 gimple call_stmt;
e33c6cd6
MJ
729 /* Additional information about an indirect call. Not cleared when an edge
730 becomes direct. */
731 struct cgraph_indirect_call_info *indirect_info;
18c6ada9 732 PTR GTY ((skip (""))) aux;
61a05df1
JH
733 /* When equal to CIF_OK, inline this call. Otherwise, points to the
734 explanation why function was not inlined. */
84562394 735 enum cgraph_inline_failed_t inline_failed;
6009ee7b
MJ
736 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
737 when the function is serialized in. */
738 unsigned int lto_stmt_uid;
b8698a0f 739 /* Expected frequency of executions within the function.
45a80bb9
JH
740 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
741 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
742 int frequency;
6009ee7b
MJ
743 /* Unique id of the edge. */
744 int uid;
e33c6cd6
MJ
745 /* Whether this edge was made direct by indirect inlining. */
746 unsigned int indirect_inlining_edge : 1;
747 /* Whether this edge describes an indirect call with an undetermined
748 callee. */
749 unsigned int indirect_unknown_callee : 1;
750 /* Whether this edge is still a dangling */
d7f09764
DN
751 /* True if the corresponding CALL stmt cannot be inlined. */
752 unsigned int call_stmt_cannot_inline_p : 1;
2505c5ed
JH
753 /* Can this call throw externally? */
754 unsigned int can_throw_external : 1;
042ae7d2
JH
755 /* Edges with SPECULATIVE flag represents indirect calls that was
756 speculatively turned into direct (i.e. by profile feedback).
757 The final code sequence will have form:
758
759 if (call_target == expected_fn)
760 expected_fn ();
761 else
762 call_target ();
763
764 Every speculative call is represented by three components attached
765 to a same call statement:
766 1) a direct call (to expected_fn)
767 2) an indirect call (to call_target)
768 3) a IPA_REF_ADDR refrence to expected_fn.
769
770 Optimizers may later redirect direct call to clone, so 1) and 3)
771 do not need to necesarily agree with destination. */
772 unsigned int speculative : 1;
1c4a429a
JH
773};
774
45a80bb9
JH
775#define CGRAPH_FREQ_BASE 1000
776#define CGRAPH_FREQ_MAX 100000
777
b2c0ad40
KH
778typedef struct cgraph_edge *cgraph_edge_p;
779
b2c0ad40 780
8a4a83ed
JH
781/* The varpool data structure.
782 Each static variable decl has assigned varpool_node. */
e69529cd 783
5e20cdc9 784class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
a3bfa8b8 785public:
6b02a499 786 /* Set when variable is scheduled to be assembled. */
b4e19405 787 unsigned output : 1;
eb1d8159 788
59b36ecf
JJ
789 /* Set if the variable is dynamically initialized, except for
790 function local statics. */
791 unsigned dynamically_initialized : 1;
56363ffd
JH
792
793 ENUM_BITFIELD(tls_model) tls_model : 3;
eb6a09a7
JH
794
795 /* Set if the variable is known to be used by single function only.
796 This is computed by ipa_signle_use pass and used by late optimizations
797 in places where optimization would be valid for local static variable
798 if we did not do any inter-procedural code movement. */
799 unsigned used_by_single_function : 1;
e69529cd
JH
800};
801
65d630d4 802/* Every top level asm statement is put into a asm_node. */
474eccc6 803
65d630d4 804struct GTY(()) asm_node {
474eccc6 805 /* Next asm node. */
65d630d4 806 struct asm_node *next;
474eccc6
ILT
807 /* String for this asm node. */
808 tree asm_str;
809 /* Ordering of all cgraph nodes. */
810 int order;
811};
812
5d59b5e1
LC
813/* Report whether or not THIS symtab node is a function, aka cgraph_node. */
814
815template <>
816template <>
817inline bool
7de90a6c 818is_a_helper <cgraph_node *>::test (symtab_node *p)
5d59b5e1 819{
67348ccc 820 return p->type == SYMTAB_FUNCTION;
5d59b5e1
LC
821}
822
823/* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
824
825template <>
826template <>
827inline bool
7de90a6c 828is_a_helper <varpool_node *>::test (symtab_node *p)
5d59b5e1 829{
67348ccc 830 return p->type == SYMTAB_VARIABLE;
5d59b5e1
LC
831}
832
5e20cdc9 833extern GTY(()) symtab_node *symtab_nodes;
ed2df68b 834extern GTY(()) int cgraph_n_nodes;
b58b1157 835extern GTY(()) int cgraph_max_uid;
9088c1cc 836extern GTY(()) int cgraph_edge_max_uid;
dafc5b82 837extern bool cgraph_global_info_ready;
f45e0ad1
JH
838enum cgraph_state
839{
66058468
JH
840 /* Frontend is parsing and finalizing functions. */
841 CGRAPH_STATE_PARSING,
f45e0ad1
JH
842 /* Callgraph is being constructed. It is safe to add new functions. */
843 CGRAPH_STATE_CONSTRUCTION,
ca0f62a8
JH
844 /* Callgraph is being at LTO time. */
845 CGRAPH_LTO_STREAMING,
f45e0ad1
JH
846 /* Callgraph is built and IPA passes are being run. */
847 CGRAPH_STATE_IPA,
7a388ee4
JH
848 /* Callgraph is built and all functions are transformed to SSA form. */
849 CGRAPH_STATE_IPA_SSA,
f45e0ad1
JH
850 /* Functions are now ordered and being passed to RTL expanders. */
851 CGRAPH_STATE_EXPANSION,
852 /* All cgraph expansion is done. */
853 CGRAPH_STATE_FINISHED
854};
855extern enum cgraph_state cgraph_state;
e7d6beb0 856extern bool cgraph_function_flags_ready;
66058468 857extern cgraph_node_set cgraph_new_nodes;
1c4a429a 858
65d630d4 859extern GTY(()) struct asm_node *asm_nodes;
2aae7680 860extern GTY(()) int symtab_order;
40a7fe1e 861extern bool cpp_implicit_aliases_done;
e69529cd 862
96451279
JH
863/* Classifcation of symbols WRT partitioning. */
864enum symbol_partitioning_class
865{
866 /* External declarations are ignored by partitioning algorithms and they are
867 added into the boundary later via compute_ltrans_boundary. */
868 SYMBOL_EXTERNAL,
869 /* Partitioned symbols are pur into one of partitions. */
870 SYMBOL_PARTITION,
871 /* Duplicated symbols (such as comdat or constant pool references) are
872 copied into every node needing them via add_symbol_to_partition. */
873 SYMBOL_DUPLICATE
874};
875
876
2aae7680 877/* In symtab.c */
5e20cdc9
DM
878void symtab_register_node (symtab_node *);
879void symtab_unregister_node (symtab_node *);
7b3376a0 880void symtab_remove_from_same_comdat_group (symtab_node *);
5e20cdc9 881void symtab_remove_node (symtab_node *);
5e20cdc9 882symtab_node *symtab_node_for_asm (const_tree asmname);
5e20cdc9
DM
883void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
884void symtab_dissolve_same_comdat_group_list (symtab_node *node);
8f940ee6
JH
885void dump_symtab (FILE *);
886void debug_symtab (void);
5e20cdc9
DM
887void dump_symtab_node (FILE *, symtab_node *);
888void debug_symtab_node (symtab_node *);
889void dump_symtab_base (FILE *, symtab_node *);
474ffc72 890void verify_symtab (void);
5e20cdc9
DM
891void verify_symtab_node (symtab_node *);
892bool verify_symtab_base (symtab_node *);
893bool symtab_used_from_object_file_p (symtab_node *);
65d630d4 894void symtab_make_decl_local (tree);
5e20cdc9 895symtab_node *symtab_alias_ultimate_target (symtab_node *,
40a7fe1e 896 enum availability *avail = NULL);
5e20cdc9
DM
897bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
898void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
899bool symtab_for_node_and_aliases (symtab_node *,
900 bool (*) (symtab_node *, void *),
af15184a
JH
901 void *,
902 bool);
5e20cdc9
DM
903symtab_node *symtab_nonoverwritable_alias (symtab_node *);
904enum availability symtab_node_availability (symtab_node *);
905bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
96451279 906enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
2aae7680 907
1c4a429a 908/* In cgraph.c */
439f7bc3 909void dump_cgraph (FILE *);
c4e622b6 910void debug_cgraph (void);
18c6ada9 911void dump_cgraph_node (FILE *, struct cgraph_node *);
c4e622b6 912void debug_cgraph_node (struct cgraph_node *);
18c6ada9 913void cgraph_remove_edge (struct cgraph_edge *);
439f7bc3 914void cgraph_remove_node (struct cgraph_node *);
3a40c18a 915void cgraph_release_function_body (struct cgraph_node *);
12123452 916void release_function_body (tree);
2563c224 917void cgraph_node_remove_callees (struct cgraph_node *node);
18c6ada9
JH
918struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
919 struct cgraph_node *,
898b8927 920 gimple, gcov_type, int);
ce47fda3 921struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
898b8927 922 int, gcov_type, int);
ce47fda3 923struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
a358e188 924struct cgraph_node * cgraph_create_node (tree);
66a20fc2 925struct cgraph_node * cgraph_create_empty_node (void);
a358e188 926struct cgraph_node * cgraph_get_create_node (tree);
87e7b310
JH
927struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
928struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
051f8cc6 929 HOST_WIDE_INT, tree, tree);
4537ec0c 930struct cgraph_node *cgraph_node_for_asm (tree);
726a989a 931struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
042ae7d2 932void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
4b685e14 933void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
439f7bc3
AJ
934struct cgraph_local_info *cgraph_local_info (tree);
935struct cgraph_global_info *cgraph_global_info (tree);
936struct cgraph_rtl_info *cgraph_rtl_info (tree);
39e2db00 937struct cgraph_node *cgraph_create_function_alias (tree, tree);
66a20fc2
JH
938void cgraph_call_node_duplication_hooks (struct cgraph_node *,
939 struct cgraph_node *);
940void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
941 struct cgraph_edge *);
1c4a429a 942
18c6ada9 943void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
042ae7d2 944struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
be330ed4 945bool cgraph_only_called_directly_p (struct cgraph_node *);
e69529cd 946
1bb17c21 947bool cgraph_function_possibly_inlined_p (tree);
e42922b1 948void cgraph_unnest_node (struct cgraph_node *);
1bb17c21 949
6b02a499 950enum availability cgraph_function_body_availability (struct cgraph_node *);
f45e0ad1 951void cgraph_add_new_function (tree, bool);
61a05df1 952const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
1cf11770 953cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
6b02a499 954
20cdc2be 955void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
530f3a1b
JH
956void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
957void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
d56026c2
JH
958bool cgraph_node_cannot_return (struct cgraph_node *);
959bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
508e4757
JH
960bool cgraph_will_be_removed_from_program_if_no_direct_calls
961 (struct cgraph_node *node);
962bool cgraph_can_remove_if_no_direct_calls_and_refs_p
963 (struct cgraph_node *node);
9aa3f5c5 964bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
be330ed4 965bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
be330ed4
JH
966bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
967 bool (*) (struct cgraph_node *, void *),
968 void *,
969 bool);
970bool cgraph_for_node_and_aliases (struct cgraph_node *,
971 bool (*) (struct cgraph_node *, void *),
972 void *, bool);
9771b263 973vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
18c6ada9
JH
974void verify_cgraph (void);
975void verify_cgraph_node (struct cgraph_node *);
9c8305f8 976void cgraph_mark_address_taken_node (struct cgraph_node *);
d7f09764 977
9088c1cc
MJ
978typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
979typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
2c8326a5 980typedef void (*varpool_node_hook)(varpool_node *, void *);
9088c1cc
MJ
981typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
982 void *);
983typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
984 void *);
985struct cgraph_edge_hook_list;
986struct cgraph_node_hook_list;
26e5b0fd 987struct varpool_node_hook_list;
9088c1cc
MJ
988struct cgraph_2edge_hook_list;
989struct cgraph_2node_hook_list;
990struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
991void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
992struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
993 void *);
994void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
26e5b0fd
JH
995struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
996 void *);
997void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
129a37fc
JH
998struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
999 void *);
1000void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
26e5b0fd
JH
1001struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
1002 void *);
1003void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
129a37fc 1004void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
9088c1cc
MJ
1005struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
1006void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
1007struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
1008void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
8132a837 1009gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
40a7fe1e
JH
1010struct cgraph_node * cgraph_function_node (struct cgraph_node *,
1011 enum availability *avail = NULL);
a2e2a668 1012bool cgraph_get_body (struct cgraph_node *node);
09ce3660 1013struct cgraph_edge *
042ae7d2
JH
1014cgraph_turn_edge_to_speculative (struct cgraph_edge *,
1015 struct cgraph_node *,
1016 gcov_type, int);
1017void cgraph_speculative_call_info (struct cgraph_edge *,
1018 struct cgraph_edge *&,
1019 struct cgraph_edge *&,
1020 struct ipa_ref *&);
4484a35a 1021extern bool gimple_check_call_matching_types (gimple, tree, bool);
9c8305f8
JH
1022
1023/* In cgraphunit.c */
65d630d4 1024struct asm_node *add_asm_node (tree);
9c8305f8
JH
1025extern FILE *cgraph_dump_file;
1026void cgraph_finalize_function (tree, bool);
65d630d4
JH
1027void finalize_compilation_unit (void);
1028void compile (void);
9c8305f8 1029void init_cgraph (void);
b4d05578 1030void cgraph_process_new_functions (void);
66a20fc2 1031void cgraph_process_same_body_aliases (void);
5e20cdc9 1032void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
3649b9b7
ST
1033/* Initialize datastructures so DECL is a function in lowered gimple form.
1034 IN_SSA is true if the gimple is in SSA. */
e70670cf
JH
1035basic_block init_lowered_empty_function (tree, bool);
1036void cgraph_reset_node (struct cgraph_node *);
d211e471 1037bool expand_thunk (struct cgraph_node *, bool, bool);
8be2dc8c
ML
1038void cgraph_make_wrapper (struct cgraph_node *source,
1039 struct cgraph_node *target);
66a20fc2
JH
1040
1041/* In cgraphclones.c */
1042
1043struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
1044 struct cgraph_node *, gimple,
1045 unsigned, gcov_type, int, bool);
1046struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
9771b263 1047 int, bool, vec<cgraph_edge_p>,
610c8ef0 1048 bool, struct cgraph_node *, bitmap);
66a20fc2
JH
1049tree clone_function_name (tree decl, const char *);
1050struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
9771b263
DN
1051 vec<cgraph_edge_p>,
1052 vec<ipa_replace_map_p, va_gc> *tree_map,
66a20fc2
JH
1053 bitmap args_to_skip,
1054 const char *clone_name);
1055struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
1056bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
042ae7d2
JH
1057void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
1058 bool update_speculative = true);
66a20fc2
JH
1059void cgraph_create_edge_including_clones (struct cgraph_node *,
1060 struct cgraph_node *,
1061 gimple, gimple, gcov_type, int,
1062 cgraph_inline_failed_t);
1063void cgraph_materialize_all_clones (void);
9c8305f8 1064struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
9771b263 1065 tree, vec<cgraph_edge_p>, bitmap);
9c8305f8 1066struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
9771b263
DN
1067 vec<cgraph_edge_p>,
1068 vec<ipa_replace_map_p, va_gc> *,
9c8305f8
JH
1069 bitmap, bool, bitmap,
1070 basic_block, const char *);
9771b263 1071void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
9c8305f8 1072 bool, bitmap, bool, bitmap, basic_block);
09ce3660 1073struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
9c8305f8 1074
917948d3
ZD
1075/* In cgraphbuild.c */
1076unsigned int rebuild_cgraph_edges (void);
99b766fc 1077void cgraph_rebuild_references (void);
9187e02d 1078int compute_call_stmt_bb_frequency (tree, basic_block bb);
9c8305f8 1079void record_references_in_initializer (tree, bool);
82338059 1080void ipa_record_stmt_references (struct cgraph_node *, gimple);
917948d3 1081
ca31b95f 1082/* In ipa.c */
04142cc3 1083bool symtab_remove_unreachable_nodes (bool, FILE *);
fed5ae11
DK
1084cgraph_node_set cgraph_node_set_new (void);
1085cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
1086 struct cgraph_node *);
1087void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
1088void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
1089void dump_cgraph_node_set (FILE *, cgraph_node_set);
1090void debug_cgraph_node_set (cgraph_node_set);
1cb1a99f 1091void free_cgraph_node_set (cgraph_node_set);
9c8305f8 1092void cgraph_build_static_cdtor (char which, tree body, int priority);
fed5ae11 1093
2942c502
JH
1094varpool_node_set varpool_node_set_new (void);
1095varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
2c8326a5
OE
1096 varpool_node *);
1097void varpool_node_set_add (varpool_node_set, varpool_node *);
1098void varpool_node_set_remove (varpool_node_set, varpool_node *);
2942c502
JH
1099void dump_varpool_node_set (FILE *, varpool_node_set);
1100void debug_varpool_node_set (varpool_node_set);
1cb1a99f 1101void free_varpool_node_set (varpool_node_set);
4a444e58 1102void ipa_discover_readonly_nonaddressable_vars (void);
2c8326a5 1103bool varpool_externally_visible_p (varpool_node *);
ca31b95f 1104
7f7beb3f
JH
1105/* In ipa-visibility.c */
1106bool cgraph_local_node_p (struct cgraph_node *);
d211e471 1107bool address_taken_from_non_vtable_p (symtab_node *node);
7f7beb3f
JH
1108
1109
fed5ae11 1110/* In predict.c */
ca30a539 1111bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
e6416b30 1112bool cgraph_optimize_for_size_p (struct cgraph_node *);
ca30a539 1113
8a4a83ed 1114/* In varpool.c */
2c8326a5
OE
1115varpool_node *varpool_create_empty_node (void);
1116varpool_node *varpool_node_for_decl (tree);
1117varpool_node *varpool_node_for_asm (tree asmname);
1118void varpool_mark_needed_node (varpool_node *);
d85478c2 1119void debug_varpool (void);
8a4a83ed 1120void dump_varpool (FILE *);
2c8326a5 1121void dump_varpool_node (FILE *, varpool_node *);
8a4a83ed
JH
1122
1123void varpool_finalize_decl (tree);
2c8326a5 1124enum availability cgraph_variable_initializer_availability (varpool_node *);
a550d677
MJ
1125void cgraph_make_node_local (struct cgraph_node *);
1126bool cgraph_node_can_be_local_p (struct cgraph_node *);
8a4a83ed 1127
2942c502 1128
2c8326a5
OE
1129void varpool_remove_node (varpool_node *node);
1130void varpool_finalize_named_section_flags (varpool_node *node);
65d630d4 1131bool varpool_output_variables (void);
2c8326a5
OE
1132bool varpool_assemble_decl (varpool_node *node);
1133void varpool_analyze_node (varpool_node *);
1134varpool_node * varpool_extra_name_alias (tree, tree);
1135varpool_node * varpool_create_variable_alias (tree, tree);
b34fd25c 1136void varpool_reset_queue (void);
0b83e688 1137bool varpool_ctor_useable_for_folding_p (varpool_node *);
6a6dac52 1138tree ctor_for_folding (tree);
2c8326a5
OE
1139bool varpool_for_node_and_aliases (varpool_node *,
1140 bool (*) (varpool_node *, void *),
cd35bcf7 1141 void *, bool);
38877e98 1142void varpool_add_new_variable (tree);
b5493fb2 1143void symtab_initialize_asm_name_hash (void);
5e20cdc9 1144void symtab_prevail_in_asm_name_hash (symtab_node *node);
2c8326a5 1145void varpool_remove_initializer (varpool_node *);
0b83e688 1146tree varpool_get_constructor (struct varpool_node *node);
8a4a83ed 1147
d8a2d370
DN
1148/* In cgraph.c */
1149extern void change_decl_assembler_name (tree, tree);
68e56cc4 1150
aede2c10
JH
1151/* Return symbol table node associated with DECL, if any,
1152 and NULL otherwise. */
1153
1154static inline symtab_node *
1155symtab_get_node (const_tree decl)
1156{
1157#ifdef ENABLE_CHECKING
1158 /* Check that we are called for sane type of object - functions
1159 and static or external variables. */
1160 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
1161 || (TREE_CODE (decl) == VAR_DECL
1162 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1163 || in_lto_p)));
1164 /* Check that the mapping is sane - perhaps this check can go away,
1165 but at the moment frontends tends to corrupt the mapping by calling
1166 memcpy/memset on the tree nodes. */
1167 gcc_checking_assert (!decl->decl_with_vis.symtab_node
1168 || decl->decl_with_vis.symtab_node->decl == decl);
1169#endif
1170 return decl->decl_with_vis.symtab_node;
1171}
1172
1f00098b
JH
1173/* Return callgraph node for given symbol and check it is a function. */
1174static inline struct cgraph_node *
5e20cdc9 1175cgraph (symtab_node *node)
1f00098b 1176{
67348ccc 1177 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
1ab24192 1178 return (struct cgraph_node *)node;
1f00098b
JH
1179}
1180
1181/* Return varpool node for given symbol and check it is a variable. */
2c8326a5 1182static inline varpool_node *
5e20cdc9 1183varpool (symtab_node *node)
1f00098b 1184{
67348ccc 1185 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
2c8326a5 1186 return (varpool_node *)node;
1f00098b
JH
1187}
1188
1ab24192
JH
1189/* Return callgraph node for given symbol and check it is a function. */
1190static inline struct cgraph_node *
1191cgraph_get_node (const_tree decl)
1192{
1193 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1194 return cgraph (symtab_get_node (decl));
1195}
1196
1197/* Return varpool node for given symbol and check it is a function. */
2c8326a5 1198static inline varpool_node *
1ab24192
JH
1199varpool_get_node (const_tree decl)
1200{
1201 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1202 return varpool (symtab_get_node (decl));
1203}
1204
1205/* Walk all symbols. */
1206#define FOR_EACH_SYMBOL(node) \
67348ccc 1207 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1f00098b 1208
d6d229c6
JH
1209/* Return first static symbol with definition. */
1210static inline symtab_node *
1211symtab_first_defined_symbol (void)
1212{
1213 symtab_node *node;
1214
1215 for (node = symtab_nodes; node; node = node->next)
1216 if (node->definition)
1217 return node;
1218
1219 return NULL;
1220}
1221
1222/* Return next reachable static symbol with initializer after NODE. */
1223static inline symtab_node *
1224symtab_next_defined_symbol (symtab_node *node)
1225{
1226 symtab_node *node1 = node->next;
1227
1228 for (; node1; node1 = node1->next)
1229 if (node1->definition)
1230 return node1;
1231
1232 return NULL;
1233}
1234/* Walk all symbols with definitions in current unit. */
1235#define FOR_EACH_DEFINED_SYMBOL(node) \
1236 for ((node) = symtab_first_defined_symbol (); (node); \
1237 (node) = symtab_next_defined_symbol (node))
66058468
JH
1238
1239/* Return first variable. */
2c8326a5 1240static inline varpool_node *
66058468
JH
1241varpool_first_variable (void)
1242{
5e20cdc9 1243 symtab_node *node;
67348ccc 1244 for (node = symtab_nodes; node; node = node->next)
7de90a6c 1245 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
5d59b5e1 1246 return vnode;
66058468
JH
1247 return NULL;
1248}
1249
1250/* Return next variable after NODE. */
2c8326a5
OE
1251static inline varpool_node *
1252varpool_next_variable (varpool_node *node)
66058468 1253{
5e20cdc9 1254 symtab_node *node1 = node->next;
67348ccc 1255 for (; node1; node1 = node1->next)
7de90a6c 1256 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
5d59b5e1 1257 return vnode1;
66058468
JH
1258 return NULL;
1259}
1260/* Walk all variables. */
1261#define FOR_EACH_VARIABLE(node) \
1262 for ((node) = varpool_first_variable (); \
1263 (node); \
1264 (node) = varpool_next_variable ((node)))
1265
d6d229c6 1266/* Return first static variable with initializer. */
2c8326a5 1267static inline varpool_node *
68e56cc4
JH
1268varpool_first_static_initializer (void)
1269{
5e20cdc9 1270 symtab_node *node;
67348ccc 1271 for (node = symtab_nodes; node; node = node->next)
68e56cc4 1272 {
7de90a6c 1273 varpool_node *vnode = dyn_cast <varpool_node *> (node);
67348ccc 1274 if (vnode && DECL_INITIAL (node->decl))
5d59b5e1 1275 return vnode;
68e56cc4
JH
1276 }
1277 return NULL;
1278}
1279
d6d229c6 1280/* Return next static variable with initializer after NODE. */
2c8326a5
OE
1281static inline varpool_node *
1282varpool_next_static_initializer (varpool_node *node)
68e56cc4 1283{
5e20cdc9 1284 symtab_node *node1 = node->next;
67348ccc 1285 for (; node1; node1 = node1->next)
68e56cc4 1286 {
7de90a6c 1287 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
67348ccc 1288 if (vnode1 && DECL_INITIAL (node1->decl))
5d59b5e1 1289 return vnode1;
68e56cc4
JH
1290 }
1291 return NULL;
1292}
1293
1294/* Walk all static variables with initializer set. */
1295#define FOR_EACH_STATIC_INITIALIZER(node) \
1296 for ((node) = varpool_first_static_initializer (); (node); \
1297 (node) = varpool_next_static_initializer (node))
2aae7680 1298
d6d229c6 1299/* Return first static variable with definition. */
2c8326a5 1300static inline varpool_node *
66058468 1301varpool_first_defined_variable (void)
2aae7680 1302{
5e20cdc9 1303 symtab_node *node;
67348ccc 1304 for (node = symtab_nodes; node; node = node->next)
2aae7680 1305 {
7de90a6c 1306 varpool_node *vnode = dyn_cast <varpool_node *> (node);
67348ccc 1307 if (vnode && vnode->definition)
5d59b5e1 1308 return vnode;
2aae7680
JH
1309 }
1310 return NULL;
1311}
1312
d6d229c6 1313/* Return next static variable with definition after NODE. */
2c8326a5
OE
1314static inline varpool_node *
1315varpool_next_defined_variable (varpool_node *node)
2aae7680 1316{
5e20cdc9 1317 symtab_node *node1 = node->next;
67348ccc 1318 for (; node1; node1 = node1->next)
2aae7680 1319 {
7de90a6c 1320 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
67348ccc 1321 if (vnode1 && vnode1->definition)
5d59b5e1 1322 return vnode1;
2aae7680
JH
1323 }
1324 return NULL;
1325}
65c70e6b
JH
1326/* Walk all variables with definitions in current unit. */
1327#define FOR_EACH_DEFINED_VARIABLE(node) \
66058468
JH
1328 for ((node) = varpool_first_defined_variable (); (node); \
1329 (node) = varpool_next_defined_variable (node))
68e56cc4 1330
c47d0034
JH
1331/* Return first function with body defined. */
1332static inline struct cgraph_node *
1333cgraph_first_defined_function (void)
1334{
5e20cdc9 1335 symtab_node *node;
67348ccc 1336 for (node = symtab_nodes; node; node = node->next)
c47d0034 1337 {
7de90a6c 1338 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
67348ccc 1339 if (cn && cn->definition)
5d59b5e1 1340 return cn;
c47d0034
JH
1341 }
1342 return NULL;
1343}
1344
45896127 1345/* Return next function with body defined after NODE. */
c47d0034
JH
1346static inline struct cgraph_node *
1347cgraph_next_defined_function (struct cgraph_node *node)
1348{
5e20cdc9 1349 symtab_node *node1 = node->next;
67348ccc 1350 for (; node1; node1 = node1->next)
c47d0034 1351 {
7de90a6c 1352 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
67348ccc 1353 if (cn1 && cn1->definition)
5d59b5e1 1354 return cn1;
c47d0034
JH
1355 }
1356 return NULL;
1357}
1358
1359/* Walk all functions with body defined. */
1360#define FOR_EACH_DEFINED_FUNCTION(node) \
1361 for ((node) = cgraph_first_defined_function (); (node); \
2aae7680
JH
1362 (node) = cgraph_next_defined_function ((node)))
1363
1364/* Return first function. */
1365static inline struct cgraph_node *
1366cgraph_first_function (void)
1367{
5e20cdc9 1368 symtab_node *node;
67348ccc 1369 for (node = symtab_nodes; node; node = node->next)
7de90a6c 1370 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
5d59b5e1 1371 return cn;
2aae7680
JH
1372 return NULL;
1373}
1374
1375/* Return next function. */
1376static inline struct cgraph_node *
1377cgraph_next_function (struct cgraph_node *node)
1378{
5e20cdc9 1379 symtab_node *node1 = node->next;
67348ccc 1380 for (; node1; node1 = node1->next)
7de90a6c 1381 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
5d59b5e1 1382 return cn1;
2aae7680
JH
1383 return NULL;
1384}
65c70e6b
JH
1385/* Walk all functions. */
1386#define FOR_EACH_FUNCTION(node) \
2aae7680
JH
1387 for ((node) = cgraph_first_function (); (node); \
1388 (node) = cgraph_next_function ((node)))
c47d0034
JH
1389
1390/* Return true when NODE is a function with Gimple body defined
1391 in current unit. Functions can also be define externally or they
1392 can be thunks with no Gimple representation.
1393
1394 Note that at WPA stage, the function body may not be present in memory. */
1395
1396static inline bool
1397cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1398{
67348ccc 1399 return node->definition && !node->thunk.thunk_p && !node->alias;
c47d0034
JH
1400}
1401
1402/* Return first function with body defined. */
1403static inline struct cgraph_node *
1404cgraph_first_function_with_gimple_body (void)
1405{
5e20cdc9 1406 symtab_node *node;
67348ccc 1407 for (node = symtab_nodes; node; node = node->next)
c47d0034 1408 {
7de90a6c 1409 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
5d59b5e1
LC
1410 if (cn && cgraph_function_with_gimple_body_p (cn))
1411 return cn;
c47d0034
JH
1412 }
1413 return NULL;
1414}
1415
1416/* Return next reachable static variable with initializer after NODE. */
1417static inline struct cgraph_node *
1418cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1419{
5e20cdc9 1420 symtab_node *node1 = node->next;
67348ccc 1421 for (; node1; node1 = node1->next)
c47d0034 1422 {
7de90a6c 1423 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
5d59b5e1
LC
1424 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1425 return cn1;
c47d0034
JH
1426 }
1427 return NULL;
1428}
1429
1430/* Walk all functions with body defined. */
1431#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1432 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1433 (node) = cgraph_next_function_with_gimple_body (node))
1434
43d861a5
RL
1435/* Create a new static variable of type TYPE. */
1436tree add_new_static_var (tree type);
1437
fed5ae11
DK
1438/* Return true if iterator CSI points to nothing. */
1439static inline bool
1440csi_end_p (cgraph_node_set_iterator csi)
1441{
9771b263 1442 return csi.index >= csi.set->nodes.length ();
fed5ae11
DK
1443}
1444
1445/* Advance iterator CSI. */
1446static inline void
1447csi_next (cgraph_node_set_iterator *csi)
1448{
1449 csi->index++;
1450}
1451
1452/* Return the node pointed to by CSI. */
1453static inline struct cgraph_node *
1454csi_node (cgraph_node_set_iterator csi)
1455{
9771b263 1456 return csi.set->nodes[csi.index];
fed5ae11
DK
1457}
1458
1459/* Return an iterator to the first node in SET. */
1460static inline cgraph_node_set_iterator
1461csi_start (cgraph_node_set set)
1462{
1463 cgraph_node_set_iterator csi;
1464
1465 csi.set = set;
1466 csi.index = 0;
1467 return csi;
1468}
1469
1470/* Return true if SET contains NODE. */
1471static inline bool
1472cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1473{
1474 cgraph_node_set_iterator csi;
1475 csi = cgraph_node_set_find (set, node);
1476 return !csi_end_p (csi);
1477}
1478
1479/* Return number of nodes in SET. */
1480static inline size_t
1481cgraph_node_set_size (cgraph_node_set set)
1482{
9771b263 1483 return set->nodes.length ();
fed5ae11
DK
1484}
1485
2942c502
JH
1486/* Return true if iterator VSI points to nothing. */
1487static inline bool
1488vsi_end_p (varpool_node_set_iterator vsi)
1489{
9771b263 1490 return vsi.index >= vsi.set->nodes.length ();
2942c502
JH
1491}
1492
1493/* Advance iterator VSI. */
1494static inline void
1495vsi_next (varpool_node_set_iterator *vsi)
1496{
1497 vsi->index++;
1498}
1499
1500/* Return the node pointed to by VSI. */
2c8326a5 1501static inline varpool_node *
2942c502
JH
1502vsi_node (varpool_node_set_iterator vsi)
1503{
9771b263 1504 return vsi.set->nodes[vsi.index];
2942c502
JH
1505}
1506
1507/* Return an iterator to the first node in SET. */
1508static inline varpool_node_set_iterator
1509vsi_start (varpool_node_set set)
1510{
1511 varpool_node_set_iterator vsi;
1512
1513 vsi.set = set;
1514 vsi.index = 0;
1515 return vsi;
1516}
1517
1518/* Return true if SET contains NODE. */
1519static inline bool
2c8326a5 1520varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
2942c502
JH
1521{
1522 varpool_node_set_iterator vsi;
1523 vsi = varpool_node_set_find (set, node);
1524 return !vsi_end_p (vsi);
1525}
1526
1527/* Return number of nodes in SET. */
1528static inline size_t
1529varpool_node_set_size (varpool_node_set set)
1530{
9771b263 1531 return set->nodes.length ();
2942c502
JH
1532}
1533
d48e9cea
OR
1534/* Uniquize all constants that appear in memory.
1535 Each constant in memory thus far output is recorded
1536 in `const_desc_table'. */
1537
1538struct GTY(()) constant_descriptor_tree {
1539 /* A MEM for the constant. */
1540 rtx rtl;
b8698a0f 1541
d48e9cea
OR
1542 /* The value of the constant. */
1543 tree value;
1544
1545 /* Hash of value. Computing the hash from value each time
1546 hashfn is called can't work properly, as that means recursive
1547 use of the hash table during hash table expansion. */
1548 hashval_t hash;
1549};
1550
ace72c88
JH
1551/* Return true if set is nonempty. */
1552static inline bool
1553cgraph_node_set_nonempty_p (cgraph_node_set set)
1554{
9771b263 1555 return !set->nodes.is_empty ();
ace72c88
JH
1556}
1557
1558/* Return true if set is nonempty. */
1559static inline bool
1560varpool_node_set_nonempty_p (varpool_node_set set)
1561{
9771b263 1562 return !set->nodes.is_empty ();
ace72c88
JH
1563}
1564
be330ed4 1565/* Return true when function NODE is only called directly or it has alias.
b20996ff
JH
1566 i.e. it is not externally visible, address was not taken and
1567 it is not used in any other non-standard way. */
1568
1569static inline bool
be330ed4 1570cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
b20996ff 1571{
530f3a1b 1572 gcc_assert (!node->global.inlined_to);
67348ccc
DM
1573 return (!node->force_output && !node->address_taken
1574 && !node->used_from_other_partition
1575 && !DECL_VIRTUAL_P (node->decl)
1576 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1577 && !DECL_STATIC_DESTRUCTOR (node->decl)
1578 && !node->externally_visible);
b20996ff
JH
1579}
1580
df7705b1
JH
1581/* Return true when function NODE can be removed from callgraph
1582 if all direct calls are eliminated. */
1583
1584static inline bool
2c8326a5 1585varpool_can_remove_if_no_refs (varpool_node *node)
df7705b1 1586{
67348ccc 1587 if (DECL_EXTERNAL (node->decl))
6649df51 1588 return true;
67348ccc
DM
1589 return (!node->force_output && !node->used_from_other_partition
1590 && ((DECL_COMDAT (node->decl)
1591 && !node->forced_by_abi
1592 && !symtab_used_from_object_file_p (node))
1593 || !node->externally_visible
1594 || DECL_HAS_VALUE_EXPR_P (node->decl)));
df7705b1
JH
1595}
1596
4a444e58
JH
1597/* Return true when all references to VNODE must be visible in ipa_ref_list.
1598 i.e. if the variable is not externally visible or not used in some magic
1599 way (asm statement or such).
61502ca8 1600 The magic uses are all summarized in force_output flag. */
4a444e58
JH
1601
1602static inline bool
2c8326a5 1603varpool_all_refs_explicit_p (varpool_node *vnode)
4a444e58 1604{
67348ccc
DM
1605 return (vnode->definition
1606 && !vnode->externally_visible
1607 && !vnode->used_from_other_partition
1608 && !vnode->force_output);
4a444e58
JH
1609}
1610
d48e9cea
OR
1611/* Constant pool accessor function. */
1612htab_t constant_pool_htab (void);
fed5ae11 1613
39e2db00
JH
1614/* Return node that alias N is aliasing. */
1615
5e20cdc9
DM
1616static inline symtab_node *
1617symtab_alias_target (symtab_node *n)
39e2db00 1618{
d122681a
ML
1619 struct ipa_ref *ref = NULL;
1620 n->iterate_reference (0, ref);
39e2db00 1621 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
e70670cf 1622 return ref->referred;
39e2db00
JH
1623}
1624
e70670cf
JH
1625static inline struct cgraph_node *
1626cgraph_alias_target (struct cgraph_node *n)
cd35bcf7 1627{
7de90a6c 1628 return dyn_cast <cgraph_node *> (symtab_alias_target (n));
cd35bcf7
JH
1629}
1630
2c8326a5
OE
1631static inline varpool_node *
1632varpool_alias_target (varpool_node *n)
be330ed4 1633{
7de90a6c 1634 return dyn_cast <varpool_node *> (symtab_alias_target (n));
be330ed4
JH
1635}
1636
1637/* Given NODE, walk the alias chain to return the function NODE is alias of.
1638 Do not walk through thunks.
073a8998 1639 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
be330ed4
JH
1640
1641static inline struct cgraph_node *
40a7fe1e
JH
1642cgraph_function_or_thunk_node (struct cgraph_node *node,
1643 enum availability *availability = NULL)
be330ed4 1644{
e70670cf
JH
1645 struct cgraph_node *n;
1646
7de90a6c
DM
1647 n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node,
1648 availability));
40a7fe1e 1649 if (!n && availability)
39e2db00 1650 *availability = AVAIL_NOT_AVAILABLE;
e70670cf 1651 return n;
be330ed4 1652}
cd35bcf7
JH
1653/* Given NODE, walk the alias chain to return the function NODE is alias of.
1654 Do not walk through thunks.
073a8998 1655 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
cd35bcf7 1656
2c8326a5
OE
1657static inline varpool_node *
1658varpool_variable_node (varpool_node *node,
40a7fe1e 1659 enum availability *availability = NULL)
cd35bcf7 1660{
2c8326a5 1661 varpool_node *n;
e70670cf 1662
ff36fcbe 1663 if (node)
7de90a6c
DM
1664 n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node,
1665 availability));
ff36fcbe
EB
1666 else
1667 n = NULL;
1668
40a7fe1e 1669 if (!n && availability)
cd35bcf7 1670 *availability = AVAIL_NOT_AVAILABLE;
e70670cf 1671 return n;
cd35bcf7
JH
1672}
1673
d7d1d041
RG
1674/* Return true when the edge E represents a direct recursion. */
1675static inline bool
1676cgraph_edge_recursive_p (struct cgraph_edge *e)
1677{
be330ed4 1678 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
d7d1d041 1679 if (e->caller->global.inlined_to)
67348ccc 1680 return e->caller->global.inlined_to->decl == callee->decl;
d7d1d041 1681 else
67348ccc 1682 return e->caller->decl == callee->decl;
d7d1d041 1683}
0a35513e
AH
1684
1685/* Return true if the TM_CLONE bit is set for a given FNDECL. */
1686static inline bool
1687decl_is_tm_clone (const_tree fndecl)
1688{
1689 struct cgraph_node *n = cgraph_get_node (fndecl);
1690 if (n)
1691 return n->tm_clone;
1692 return false;
1693}
9c8305f8
JH
1694
1695/* Likewise indicate that a node is needed, i.e. reachable via some
1696 external means. */
1697
1698static inline void
1699cgraph_mark_force_output_node (struct cgraph_node *node)
1700{
67348ccc 1701 node->force_output = 1;
9c8305f8
JH
1702 gcc_checking_assert (!node->global.inlined_to);
1703}
65d630d4 1704
b5493fb2 1705/* Return true when the symbol is real symbol, i.e. it is not inline clone
e70670cf 1706 or abstract function kept for debug info purposes only. */
b5493fb2
JH
1707
1708static inline bool
5e20cdc9 1709symtab_real_symbol_p (symtab_node *node)
b5493fb2
JH
1710{
1711 struct cgraph_node *cnode;
b5493fb2 1712
67348ccc 1713 if (DECL_ABSTRACT (node->decl))
c0c123ef 1714 return false;
7de90a6c 1715 if (!is_a <cgraph_node *> (node))
b5493fb2
JH
1716 return true;
1717 cnode = cgraph (node);
1718 if (cnode->global.inlined_to)
1719 return false;
b5493fb2
JH
1720 return true;
1721}
09ce3660
JH
1722
1723/* Return true if NODE can be discarded by linker from the binary. */
1724
1725static inline bool
5e20cdc9 1726symtab_can_be_discarded (symtab_node *node)
09ce3660 1727{
67348ccc 1728 return (DECL_EXTERNAL (node->decl)
aede2c10 1729 || (node->get_comdat_group ()
67348ccc
DM
1730 && node->resolution != LDPR_PREVAILING_DEF
1731 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1732 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
09ce3660 1733}
1f26ac87
JM
1734
1735/* Return true if NODE is local to a particular COMDAT group, and must not
1736 be named from outside the COMDAT. This is used for C++ decloned
1737 constructors. */
1738
1739static inline bool
1740symtab_comdat_local_p (symtab_node *node)
1741{
1742 return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1743}
1744
1745/* Return true if ONE and TWO are part of the same COMDAT group. */
1746
1747static inline bool
1748symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1749{
d6d229c6
JH
1750 if (cgraph_node *cn = dyn_cast <cgraph_node *> (one))
1751 {
1752 if (cn->global.inlined_to)
1753 one = cn->global.inlined_to;
1754 }
1755 if (cgraph_node *cn = dyn_cast <cgraph_node *> (two))
1756 {
1757 if (cn->global.inlined_to)
1758 two = cn->global.inlined_to;
1759 }
1760
aede2c10
JH
1761 return one->get_comdat_group () == two->get_comdat_group ();
1762}
1c4a429a 1763#endif /* GCC_CGRAPH_H */