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