]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cgraph.h
add a hash_set based on hash_table
[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
d52f5295
ML
53enum availability
54{
55 /* Not yet set by cgraph_function_body_availability. */
56 AVAIL_UNSET,
57 /* Function body/variable initializer is unknown. */
58 AVAIL_NOT_AVAILABLE,
59 /* Function body/variable initializer is known but might be replaced
60 by a different one from other compilation unit and thus needs to
61 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
62 arbitrary side effects on escaping variables and functions, while
63 like AVAILABLE it might access static variables. */
64 AVAIL_INTERPOSABLE,
65 /* Function body/variable initializer is known and will be used in final
66 program. */
67 AVAIL_AVAILABLE,
68 /* Function body/variable initializer is known and all it's uses are
69 explicitly visible within current unit (ie it's address is never taken and
70 it is not exported to other units). Currently used only for functions. */
71 AVAIL_LOCAL
72};
73
74/* Classification of symbols WRT partitioning. */
75enum symbol_partitioning_class
76{
77 /* External declarations are ignored by partitioning algorithms and they are
78 added into the boundary later via compute_ltrans_boundary. */
79 SYMBOL_EXTERNAL,
80 /* Partitioned symbols are pur into one of partitions. */
81 SYMBOL_PARTITION,
82 /* Duplicated symbols (such as comdat or constant pool references) are
83 copied into every node needing them via add_symbol_to_partition. */
84 SYMBOL_DUPLICATE
85};
86
1f00098b
JH
87/* Base of all entries in the symbol table.
88 The symtab_node is inherited by cgraph and varpol nodes. */
a3bfa8b8
DM
89class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
90 chain_next ("%h.next"), chain_prev ("%h.previous")))
5e20cdc9 91 symtab_node
1f00098b 92{
a3bfa8b8 93public:
fec39fa6
TS
94 /* Return name. */
95 const char *name () const;
96
97 /* Return asm name. */
98 const char * asm_name () const;
99
d52f5295
ML
100 /* Add node into symbol table. This function is not used directly, but via
101 cgraph/varpool node creation routines. */
102 void register_symbol (void);
103
104 /* Remove symbol from symbol table. */
105 void remove (void);
106
107 /* Dump symtab node to F. */
108 void dump (FILE *f);
109
110 /* Dump symtab node to stderr. */
111 void DEBUG_FUNCTION debug (void);
112
113 /* Verify consistency of node. */
114 void DEBUG_FUNCTION verify (void);
115
116 /* Return ipa reference from this symtab_node to
117 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
118 of the use and STMT the statement (if it exists). */
119 struct ipa_ref *add_reference (symtab_node *referred_node,
120 enum ipa_ref_use use_type);
121
122 /* Return ipa reference from this symtab_node to
123 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
124 of the use and STMT the statement (if it exists). */
125 struct ipa_ref *add_reference (symtab_node *referred_node,
126 enum ipa_ref_use use_type, gimple stmt);
127
128 /* If VAL is a reference to a function or a variable, add a reference from
129 this symtab_node to the corresponding symbol table node. USE_TYPE specify
130 type of the use and STMT the statement (if it exists). Return the new
131 reference or NULL if none was created. */
132 struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type,
133 gimple stmt);
134
135 /* Clone all references from symtab NODE to this symtab_node. */
136 void clone_references (symtab_node *node);
137
138 /* Remove all stmt references in non-speculative references.
139 Those are not maintained during inlining & clonning.
140 The exception are speculative references that are updated along
141 with callgraph edges associated with them. */
142 void clone_referring (symtab_node *node);
143
144 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
145 struct ipa_ref *clone_reference (struct ipa_ref *ref, gimple stmt);
146
147 /* Find the structure describing a reference to REFERRED_NODE
148 and associated with statement STMT. */
149 struct ipa_ref *find_reference (symtab_node *referred_node, gimple stmt,
150 unsigned int lto_stmt_uid);
151
152 /* Remove all references that are associated with statement STMT. */
153 void remove_stmt_references (gimple stmt);
154
155 /* Remove all stmt references in non-speculative references.
156 Those are not maintained during inlining & clonning.
157 The exception are speculative references that are updated along
158 with callgraph edges associated with them. */
159 void clear_stmts_in_references (void);
160
161 /* Remove all references in ref list. */
162 void remove_all_references (void);
163
164 /* Remove all referring items in ref list. */
165 void remove_all_referring (void);
166
167 /* Dump references in ref list to FILE. */
168 void dump_references (FILE *file);
169
170 /* Dump referring in list to FILE. */
171 void dump_referring (FILE *);
172
173 /* Iterates I-th reference in the list, REF is also set. */
174 struct ipa_ref *iterate_reference (unsigned i, struct ipa_ref *&ref);
175
176 /* Iterates I-th referring item in the list, REF is also set. */
177 struct ipa_ref *iterate_referring (unsigned i, struct ipa_ref *&ref);
178
179 /* Iterates I-th referring alias item in the list, REF is also set. */
180 struct ipa_ref *iterate_direct_aliases (unsigned i, struct ipa_ref *&ref);
181
182 /* Return true if symtab node and TARGET represents
183 semantically equivalent symbols. */
184 bool semantically_equivalent_p (symtab_node *target);
185
186 /* Classify symbol symtab node for partitioning. */
187 enum symbol_partitioning_class get_partitioning_class (void);
188
189 /* Return comdat group. */
190 tree get_comdat_group ()
191 {
192 return x_comdat_group;
193 }
194
195 /* Return comdat group as identifier_node. */
196 tree get_comdat_group_id ()
197 {
198 if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE)
199 x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group);
200 return x_comdat_group;
201 }
202
203 /* Set comdat group. */
204 void set_comdat_group (tree group)
205 {
206 gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE
207 || DECL_P (group));
208 x_comdat_group = group;
209 }
210
211 /* Return section as string. */
212 const char * get_section ()
213 {
214 if (!x_section)
215 return NULL;
216 return x_section->name;
217 }
218
219 /* Remove node from same comdat group. */
220 void remove_from_same_comdat_group (void);
221
222 /* Add this symtab_node to the same comdat group that OLD is in. */
223 void add_to_same_comdat_group (symtab_node *old_node);
224
225 /* Dissolve the same_comdat_group list in which NODE resides. */
226 void dissolve_same_comdat_group_list (void);
227
228 /* Return true when symtab_node is known to be used from other (non-LTO)
229 object file. Known only when doing LTO via linker plugin. */
230 bool used_from_object_file_p (void);
231
232 /* Walk the alias chain to return the symbol NODE is alias of.
233 If NODE is not an alias, return NODE.
234 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
235 symtab_node *ultimate_alias_target (enum availability *avail = NULL);
236
237 /* Return next reachable static symbol with initializer after NODE. */
238 inline symtab_node *next_defined_symbol (void);
239
240 /* Add reference recording that symtab node is alias of TARGET.
241 The function can fail in the case of aliasing cycles; in this case
242 it returns false. */
243 bool resolve_alias (symtab_node *target);
244
245 /* C++ FE sometimes change linkage flags after producing same
246 body aliases. */
247 void fixup_same_cpp_alias_visibility (symtab_node *target);
248
249 /* Call calback on symtab node and aliases associated to this node.
250 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
251 skipped. */
252 bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *),
253 void *data,
254 bool include_overwrite);
255
256 /* If node can not be interposable by static or dynamic linker to point to
257 different definition, return this symbol. Otherwise look for alias with
258 such property and if none exists, introduce new one. */
259 symtab_node *noninterposable_alias (void);
260
261 /* Return node that alias is aliasing. */
262 inline symtab_node *get_alias_target (void);
263
264 /* Set section for symbol and its aliases. */
265 void set_section (const char *section);
266
267 /* Set section, do not recurse into aliases.
268 When one wants to change section of symbol and its aliases,
269 use set_section. */
270 void set_section_for_node (const char *section);
271
272 /* Set initialization priority to PRIORITY. */
273 void set_init_priority (priority_type priority);
274
275 /* Return the initialization priority. */
276 priority_type get_init_priority ();
277
278 /* Return availability of NODE. */
279 enum availability get_availability (void);
280
281 /* Make DECL local. */
282 void make_decl_local (void);
283
284 /* Return true if list contains an alias. */
285 bool has_aliases_p (void);
286
287 /* Return true when the symbol is real symbol, i.e. it is not inline clone
288 or abstract function kept for debug info purposes only. */
289 bool real_symbol_p (void);
290
291 /* Return true if NODE can be discarded by linker from the binary. */
292 inline bool
293 can_be_discarded_p (void)
294 {
295 return (DECL_EXTERNAL (decl)
296 || (get_comdat_group ()
297 && resolution != LDPR_PREVAILING_DEF
298 && resolution != LDPR_PREVAILING_DEF_IRONLY
299 && resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
300 }
301
302 /* Return true if NODE is local to a particular COMDAT group, and must not
303 be named from outside the COMDAT. This is used for C++ decloned
304 constructors. */
305 inline bool comdat_local_p (void)
306 {
307 return (same_comdat_group && !TREE_PUBLIC (decl));
308 }
309
310 /* Return true if ONE and TWO are part of the same COMDAT group. */
311 inline bool in_same_comdat_group_p (symtab_node *target);
312
313 /* Return true when there is a reference to node and it is not vtable. */
314 bool address_taken_from_non_vtable_p (void);
315
316 /* Return true if symbol is known to be nonzero. */
317 bool nonzero_address ();
318
319 /* Return symbol table node associated with DECL, if any,
320 and NULL otherwise. */
321 static inline symtab_node *get (const_tree decl)
322 {
323#ifdef ENABLE_CHECKING
324 /* Check that we are called for sane type of object - functions
325 and static or external variables. */
326 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
327 || (TREE_CODE (decl) == VAR_DECL
328 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
329 || in_lto_p)));
330 /* Check that the mapping is sane - perhaps this check can go away,
331 but at the moment frontends tends to corrupt the mapping by calling
332 memcpy/memset on the tree nodes. */
333 gcc_checking_assert (!decl->decl_with_vis.symtab_node
334 || decl->decl_with_vis.symtab_node->decl == decl);
335#endif
336 return decl->decl_with_vis.symtab_node;
337 }
338
339 /* Dump symbol table to F. */
340 static void dump_table (FILE *);
341
342 /* Dump symbol table to stderr. */
343 static inline DEBUG_FUNCTION void debug_symtab (void)
344 {
345 dump_table (stderr);
346 }
347
348 /* Verify symbol table for internal consistency. */
349 static DEBUG_FUNCTION void verify_symtab_nodes (void);
350
351 /* Return true when NODE is known to be used from other (non-LTO)
352 object file. Known only when doing LTO via linker plugin. */
353 static bool used_from_object_file_p_worker (symtab_node *node);
354
1f00098b 355 /* Type of the symbol. */
b8dbdb12
RG
356 ENUM_BITFIELD (symtab_type) type : 8;
357
358 /* The symbols resolution. */
359 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
360
e70670cf
JH
361 /*** Flags representing the symbol type. ***/
362
363 /* True when symbol corresponds to a definition in current unit.
364 set via cgraph_finalize_function or varpool_finalize_decl */
365 unsigned definition : 1;
9041d2e6
ML
366 /* True when symbol is an alias.
367 Set by ssemble_alias. */
e70670cf 368 unsigned alias : 1;
08346abd
JH
369 /* True when alias is a weakref. */
370 unsigned weakref : 1;
40a7fe1e 371 /* C++ frontend produce same body aliases and extra name aliases for
688010ba 372 virtual functions and vtables that are obviously equivalent.
40a7fe1e
JH
373 Those aliases are bit special, especially because C++ frontend
374 visibility code is so ugly it can not get them right at first time
375 and their visibility needs to be copied from their "masters" at
376 the end of parsing. */
377 unsigned cpp_implicit_alias : 1;
e70670cf
JH
378 /* Set once the definition was analyzed. The list of references and
379 other properties are built during analysis. */
380 unsigned analyzed : 1;
6de88c6a
JH
381 /* Set for write-only variables. */
382 unsigned writeonly : 1;
e70670cf
JH
383
384
385 /*** Visibility and linkage flags. ***/
386
b8dbdb12
RG
387 /* Set when function is visible by other units. */
388 unsigned externally_visible : 1;
4bcfd75c 389 /* The symbol will be assumed to be used in an invisible way (like
edb983b2 390 by an toplevel asm statement). */
b8dbdb12 391 unsigned force_output : 1;
edb983b2
JH
392 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
393 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
394 to static and it does not inhibit optimization. */
395 unsigned forced_by_abi : 1;
702d8703
JH
396 /* True when the name is known to be unique and thus it does not need mangling. */
397 unsigned unique_name : 1;
e257a17c
JH
398 /* Specify whether the section was set by user or by
399 compiler via -ffunction-sections. */
400 unsigned implicit_section : 1;
3d8d0043
MJ
401 /* True when body and other characteristics have been removed by
402 symtab_remove_unreachable_nodes. */
403 unsigned body_removed : 1;
b8dbdb12 404
e70670cf
JH
405 /*** WHOPR Partitioning flags.
406 These flags are used at ltrans stage when only part of the callgraph is
407 available. ***/
b8dbdb12 408
e70670cf
JH
409 /* Set when variable is used from other LTRANS partition. */
410 unsigned used_from_other_partition : 1;
9041d2e6 411 /* Set when function is available in the other LTRANS partition.
e70670cf
JH
412 During WPA output it is used to mark nodes that are present in
413 multiple partitions. */
414 unsigned in_other_partition : 1;
b8dbdb12 415
b8dbdb12 416
e70670cf
JH
417
418 /*** other flags. ***/
419
420 /* Set when symbol has address taken. */
421 unsigned address_taken : 1;
569b1784
JH
422 /* Set when init priority is set. */
423 unsigned in_init_priority_hash : 1;
e70670cf
JH
424
425
426 /* Ordering of all symtab entries. */
427 int order;
428
429 /* Declaration representing the symbol. */
430 tree decl;
960bfb69 431
2aae7680 432 /* Linked list of symbol table entries starting with symtab_nodes. */
5e20cdc9
DM
433 symtab_node *next;
434 symtab_node *previous;
e70670cf 435
1ab24192 436 /* Linked list of symbols with the same asm name. There may be multiple
e70670cf
JH
437 entries for single symbol name during LTO, because symbols are renamed
438 only after partitioning.
439
440 Because inline clones are kept in the assembler name has, they also produce
441 duplicate entries.
442
443 There are also several long standing bugs where frontends and builtin
444 code produce duplicated decls. */
5e20cdc9
DM
445 symtab_node *next_sharing_asm_name;
446 symtab_node *previous_sharing_asm_name;
2aae7680 447
d52f5295
ML
448 /* Circular list of nodes in the same comdat group if non-NULL. */
449 symtab_node *same_comdat_group;
e55637b7 450
e70670cf
JH
451 /* Vectors of referring and referenced entities. */
452 struct ipa_ref_list ref_list;
453
40a7fe1e
JH
454 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
455 depending to what was known to frontend on the creation time.
456 Once alias is resolved, this pointer become NULL. */
457 tree alias_target;
458
e70670cf
JH
459 /* File stream where this node is being written to. */
460 struct lto_file_decl_data * lto_file_data;
461
960bfb69 462 PTR GTY ((skip)) aux;
aede2c10
JH
463
464 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
f961457f 465 tree x_comdat_group;
24d047a3
JH
466
467 /* Section name. Again can be private, if allowed. */
f961457f 468 section_hash_entry *x_section;
e257a17c 469
d52f5295
ML
470protected:
471 /* Dump base fields of symtab nodes to F. Not to be used directly. */
472 void dump_base (FILE *);
569b1784 473
d52f5295
ML
474 /* Verify common part of symtab node. */
475 bool DEBUG_FUNCTION verify_base (void);
89330618 476
d52f5295
ML
477 /* Remove node from symbol table. This function is not used directly, but via
478 cgraph/varpool node removal routines. */
479 void unregister (void);
480
481 /* Return the initialization and finalization priority information for
482 DECL. If there is no previous priority information, a freshly
483 allocated structure is returned. */
484 struct symbol_priority_map *priority_info (void);
485
486private:
487 /* Worker for set_section. */
488 static bool set_section (symtab_node *n, void *s);
489
490 /* Worker for symtab_resolve_alias. */
491 static bool set_implicit_section (symtab_node *n, void *);
492
493 /* Worker searching noninterposable alias. */
494 static bool noninterposable_alias (symtab_node *node, void *data);
1f00098b 495};
1c4a429a 496
e55637b7
ML
497/* Walk all aliases for NODE. */
498#define FOR_EACH_ALIAS(node, alias) \
d52f5295 499 for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++)
6b02a499 500
d7f09764
DN
501/* This is the information that is put into the cgraph local structure
502 to recover a function. */
503struct lto_file_decl_data;
504
8a4a83ed 505extern const char * const cgraph_availability_names[];
430c6ceb 506extern const char * const ld_plugin_symbol_resolution_names[];
714c800f 507extern const char * const tls_model_names[];
8a4a83ed 508
6744a6ab
JH
509/* Information about thunk, used only for same body aliases. */
510
511struct GTY(()) cgraph_thunk_info {
512 /* Information about the thunk. */
513 HOST_WIDE_INT fixed_offset;
514 HOST_WIDE_INT virtual_value;
515 tree alias;
516 bool this_adjusting;
517 bool virtual_offset_p;
518 /* Set to true when alias node is thunk. */
519 bool thunk_p;
520};
521
dafc5b82 522/* Information about the function collected locally.
25c84396 523 Available after function is analyzed. */
dafc5b82 524
d1b38208 525struct GTY(()) cgraph_local_info {
e0bb17a8 526 /* Set when function function is visible in current compilation unit only
e2209b03 527 and its address is never taken. */
b4e19405 528 unsigned local : 1;
6674a6ce 529
124f1be6
MJ
530 /* False when there is something makes versioning impossible. */
531 unsigned versionable : 1;
532
61e03ffc
JH
533 /* False when function calling convention and signature can not be changed.
534 This is the case when __builtin_apply_args is used. */
535 unsigned can_change_signature : 1;
536
95c755e9
JH
537 /* True when the function has been originally extern inline, but it is
538 redefined now. */
b4e19405 539 unsigned redefined_extern_inline : 1;
0a35513e
AH
540
541 /* True if the function may enter serial irrevocable mode. */
542 unsigned tm_may_enter_irr : 1;
dafc5b82
JH
543};
544
545/* Information about the function that needs to be computed globally
726a989a 546 once compilation is finished. Available only with -funit-at-a-time. */
dafc5b82 547
d1b38208 548struct GTY(()) cgraph_global_info {
726a989a
RB
549 /* For inline clones this points to the function they will be
550 inlined into. */
d52f5295 551 cgraph_node *inlined_to;
dafc5b82
JH
552};
553
b255a036
JH
554/* Information about the function that is propagated by the RTL backend.
555 Available only for functions that has been already assembled. */
556
d1b38208 557struct GTY(()) cgraph_rtl_info {
17b29c0a 558 unsigned int preferred_incoming_stack_boundary;
27c07cc5
RO
559
560 /* Call unsaved hard registers really used by the corresponding
561 function (including ones used by functions called by the
562 function). */
563 HARD_REG_SET function_used_regs;
564 /* Set if function_used_regs is valid. */
565 unsigned function_used_regs_valid: 1;
b255a036
JH
566};
567
9187e02d
JH
568/* Represent which DECL tree (or reference to such tree)
569 will be replaced by another tree while versioning. */
570struct GTY(()) ipa_replace_map
571{
572 /* The tree that will be replaced. */
573 tree old_tree;
574 /* The new (replacing) tree. */
575 tree new_tree;
922f15c2
JH
576 /* Parameter number to replace, when old_tree is NULL. */
577 int parm_num;
9187e02d
JH
578 /* True when a substitution should be done, false otherwise. */
579 bool replace_p;
580 /* True when we replace a reference to old_tree. */
581 bool ref_p;
582};
9187e02d
JH
583
584struct GTY(()) cgraph_clone_info
585{
d52f5295 586 vec<ipa_replace_map *, va_gc> *tree_map;
9187e02d 587 bitmap args_to_skip;
08ad1d6d 588 bitmap combined_args_to_skip;
9187e02d
JH
589};
590
0136f8f0
AH
591enum cgraph_simd_clone_arg_type
592{
593 SIMD_CLONE_ARG_TYPE_VECTOR,
594 SIMD_CLONE_ARG_TYPE_UNIFORM,
595 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
596 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
597 SIMD_CLONE_ARG_TYPE_MASK
598};
599
600/* Function arguments in the original function of a SIMD clone.
601 Supplementary data for `struct simd_clone'. */
602
603struct GTY(()) cgraph_simd_clone_arg {
604 /* Original function argument as it originally existed in
605 DECL_ARGUMENTS. */
606 tree orig_arg;
607
608 /* orig_arg's function (or for extern functions type from
609 TYPE_ARG_TYPES). */
610 tree orig_type;
611
612 /* If argument is a vector, this holds the vector version of
613 orig_arg that after adjusting the argument types will live in
614 DECL_ARGUMENTS. Otherwise, this is NULL.
615
616 This basically holds:
617 vector(simdlen) __typeof__(orig_arg) new_arg. */
618 tree vector_arg;
619
620 /* vector_arg's type (or for extern functions new vector type. */
621 tree vector_type;
622
623 /* If argument is a vector, this holds the array where the simd
624 argument is held while executing the simd clone function. This
625 is a local variable in the cloned function. Its content is
626 copied from vector_arg upon entry to the clone.
627
628 This basically holds:
629 __typeof__(orig_arg) simd_array[simdlen]. */
630 tree simd_array;
631
632 /* A SIMD clone's argument can be either linear (constant or
633 variable), uniform, or vector. */
634 enum cgraph_simd_clone_arg_type arg_type;
635
636 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
637 the constant linear step, if arg_type is
638 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
639 the uniform argument holding the step, otherwise 0. */
640 HOST_WIDE_INT linear_step;
641
642 /* Variable alignment if available, otherwise 0. */
643 unsigned int alignment;
644};
645
646/* Specific data for a SIMD function clone. */
647
648struct GTY(()) cgraph_simd_clone {
649 /* Number of words in the SIMD lane associated with this clone. */
650 unsigned int simdlen;
651
652 /* Number of annotated function arguments in `args'. This is
653 usually the number of named arguments in FNDECL. */
654 unsigned int nargs;
655
656 /* Max hardware vector size in bits for integral vectors. */
657 unsigned int vecsize_int;
658
659 /* Max hardware vector size in bits for floating point vectors. */
660 unsigned int vecsize_float;
661
662 /* The mangling character for a given vector size. This is is used
663 to determine the ISA mangling bit as specified in the Intel
664 Vector ABI. */
665 unsigned char vecsize_mangle;
666
667 /* True if this is the masked, in-branch version of the clone,
668 otherwise false. */
669 unsigned int inbranch : 1;
670
671 /* True if this is a Cilk Plus variant. */
672 unsigned int cilk_elemental : 1;
673
674 /* Doubly linked list of SIMD clones. */
d52f5295 675 cgraph_node *prev_clone, *next_clone;
0136f8f0
AH
676
677 /* Original cgraph node the SIMD clones were created for. */
d52f5295 678 cgraph_node *origin;
0136f8f0
AH
679
680 /* Annotated function arguments for the original function. */
681 struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
682};
683
d52f5295
ML
684/* Function Multiversioning info. */
685struct GTY(()) cgraph_function_version_info {
686 /* The cgraph_node for which the function version info is stored. */
687 cgraph_node *this_node;
688 /* Chains all the semantically identical function versions. The
689 first function in this chain is the version_info node of the
690 default function. */
691 struct cgraph_function_version_info *prev;
692 /* If this version node corresponds to a dispatcher for function
693 versions, this points to the version info node of the default
694 function, the first node in the chain. */
695 struct cgraph_function_version_info *next;
696 /* If this node corresponds to a function version, this points
697 to the dispatcher function decl, which is the function that must
698 be called to execute the right function version at run-time.
699
700 If this cgraph node is a dispatcher (if dispatcher_function is
701 true, in the cgraph_node struct) for function versions, this
702 points to resolver function, which holds the function body of the
703 dispatcher. The dispatcher decl is an alias to the resolver
704 function decl. */
705 tree dispatcher_resolver;
706};
707
708#define DEFCIFCODE(code, type, string) CIF_ ## code,
709/* Reasons for inlining failures. */
710
711enum cgraph_inline_failed_t {
712#include "cif-code.def"
713 CIF_N_REASONS
714};
715
716enum cgraph_inline_failed_type_t
717{
718 CIF_FINAL_NORMAL = 0,
719 CIF_FINAL_ERROR
720};
721
722struct cgraph_edge;
5fefcf92 723
ba228239 724/* The cgraph data structure.
e0bb17a8 725 Each function decl has assigned cgraph_node listing callees and callers. */
1c4a429a 726
5e20cdc9 727struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
a3bfa8b8 728public:
d52f5295
ML
729 /* Remove the node from cgraph and all inline clones inlined into it.
730 Skip however removal of FORBIDDEN_NODE and return true if it needs to be
731 removed. This allows to call the function from outer loop walking clone
732 tree. */
733 bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL);
734
735 /* Record all references from cgraph_node that are taken
736 in statement STMT. */
737 void record_stmt_references (gimple stmt);
738
739 /* Like cgraph_set_call_stmt but walk the clone tree and update all
740 clones sharing the same function body.
741 When WHOLE_SPECULATIVE_EDGES is true, all three components of
742 speculative edge gets updated. Otherwise we update only direct
743 call. */
744 void set_call_stmt_including_clones (gimple old_stmt, gimple new_stmt,
745 bool update_speculative = true);
746
747 /* Walk the alias chain to return the function cgraph_node is alias of.
748 Walk through thunk, too.
749 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
750 cgraph_node *function_symbol (enum availability *avail = NULL);
751
752 /* Create node representing clone of N executed COUNT times. Decrease
753 the execution counts from original node too.
754 The new clone will have decl set to DECL that may or may not be the same
755 as decl of N.
756
757 When UPDATE_ORIGINAL is true, the counts are subtracted from the original
758 function's profile to reflect the fact that part of execution is handled
759 by node.
760 When CALL_DUPLICATOIN_HOOK is true, the ipa passes are acknowledged about
761 the new clone. Otherwise the caller is responsible for doing so later.
762
763 If the new node is being inlined into another one, NEW_INLINED_TO should be
764 the outline function the new one is (even indirectly) inlined to.
765 All hooks will see this in node's global.inlined_to, when invoked.
766 Can be NULL if the node is not inlined. */
767 cgraph_node *create_clone (tree decl, gcov_type count, int freq,
768 bool update_original,
769 vec<cgraph_edge *> redirect_callers,
770 bool call_duplication_hook,
771 struct cgraph_node *new_inlined_to,
772 bitmap args_to_skip);
773
774 /* Create callgraph node clone with new declaration. The actual body will
775 be copied later at compilation stage. */
776 cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers,
777 vec<ipa_replace_map *, va_gc> *tree_map,
778 bitmap args_to_skip, const char * suffix);
779
780 /* cgraph node being removed from symbol table; see if its entry can be
781 replaced by other inline clone. */
782 cgraph_node *find_replacement (void);
783
784 /* Create a new cgraph node which is the new version of
785 callgraph node. REDIRECT_CALLERS holds the callers
786 edges which should be redirected to point to
787 NEW_VERSION. ALL the callees edges of the node
788 are cloned to the new version node. Return the new
789 version node.
790
791 If non-NULL BLOCK_TO_COPY determine what basic blocks
792 was copied to prevent duplications of calls that are dead
793 in the clone. */
794
795 cgraph_node *create_version_clone (tree new_decl,
796 vec<cgraph_edge *> redirect_callers,
797 bitmap bbs_to_copy);
798
799 /* Perform function versioning.
800 Function versioning includes copying of the tree and
801 a callgraph update (creating a new cgraph node and updating
802 its callees and callers).
803
804 REDIRECT_CALLERS varray includes the edges to be redirected
805 to the new version.
806
807 TREE_MAP is a mapping of tree nodes we want to replace with
808 new ones (according to results of prior analysis).
809
810 If non-NULL ARGS_TO_SKIP determine function parameters to remove
811 from new version.
812 If SKIP_RETURN is true, the new version will return void.
813 If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
814 If non_NULL NEW_ENTRY determine new entry BB of the clone.
815
816 Return the new version's cgraph node. */
817 cgraph_node *create_version_clone_with_body
818 (vec<cgraph_edge *> redirect_callers,
819 vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip,
820 bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block,
821 const char *clone_name);
822
823 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
824 corresponding to cgraph_node. */
825 struct cgraph_function_version_info *insert_new_function_version (void);
826
827 /* Get the cgraph_function_version_info node corresponding to node. */
828 struct cgraph_function_version_info *function_version (void);
829
830 /* Discover all functions and variables that are trivially needed, analyze
831 them as well as all functions and variables referred by them */
832 void analyze (void);
833
834 /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
835 aliases DECL with an adjustments made into the first parameter.
836 See comments in thunk_adjust for detail on the parameters. */
837 cgraph_node * create_thunk (tree alias, tree, bool this_adjusting,
838 HOST_WIDE_INT fixed_offset,
839 HOST_WIDE_INT virtual_value,
840 tree virtual_offset,
841 tree real_alias);
842
843
844 /* Return node that alias is aliasing. */
845 inline cgraph_node *get_alias_target (void);
846
847 /* Given function symbol, walk the alias chain to return the function node
848 is alias of. Do not walk through thunks.
849 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
850
851 cgraph_node *ultimate_alias_target (availability *availability = NULL);
852
853 /* Expand thunk NODE to gimple if possible.
854 When FORCE_GIMPLE_THUNK is true, gimple thunk is created and
855 no assembler is produced.
856 When OUTPUT_ASM_THUNK is true, also produce assembler for
857 thunks that are not lowered. */
858 bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk);
859
860 /* As an GCC extension we allow redefinition of the function. The
861 semantics when both copies of bodies differ is not well defined.
862 We replace the old body with new body so in unit at a time mode
863 we always use new body, while in normal mode we may end up with
864 old body inlined into some functions and new body expanded and
865 inlined in others. */
866 void reset (void);
867
868 /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this
869 kind of wrapper method. */
870 void create_wrapper (cgraph_node *target);
871
872 /* Verify cgraph nodes of the cgraph node. */
873 void DEBUG_FUNCTION verify_node (void);
874
875 /* Remove function from symbol table. */
876 void remove (void);
877
878 /* Dump call graph node to file F. */
879 void dump (FILE *f);
880
881 /* Dump call graph node to stderr. */
882 void DEBUG_FUNCTION debug (void);
883
884 /* When doing LTO, read cgraph_node's body from disk if it is not already
885 present. */
886 bool get_body (void);
887
888 /* Release memory used to represent body of function.
889 Use this only for functions that are released before being translated to
890 target code (i.e. RTL). Functions that are compiled to RTL and beyond
891 are free'd in final.c via free_after_compilation(). */
892 void release_body (void);
893
894 /* cgraph_node is no longer nested function; update cgraph accordingly. */
895 void unnest (void);
896
897 /* Bring cgraph node local. */
898 void make_local (void);
899
900 /* Likewise indicate that a node is having address taken. */
901 void mark_address_taken (void);
902
903 /* Set fialization priority to PRIORITY. */
904 void set_fini_priority (priority_type priority);
905
906 /* Return the finalization priority. */
907 priority_type get_fini_priority (void);
908
909 /* Create edge from a given function to CALLEE in the cgraph. */
910 struct cgraph_edge *create_edge (cgraph_node *callee,
911 gimple call_stmt, gcov_type count,
912 int freq);
913 /* Create an indirect edge with a yet-undetermined callee where the call
914 statement destination is a formal parameter of the caller with index
915 PARAM_INDEX. */
916 struct cgraph_edge *create_indirect_edge (gimple call_stmt, int ecf_flags,
917 gcov_type count, int freq);
918
919 /* Like cgraph_create_edge walk the clone tree and update all clones sharing
920 same function body. If clones already have edge for OLD_STMT; only
921 update the edge same way as cgraph_set_call_stmt_including_clones does. */
922 void create_edge_including_clones (struct cgraph_node *callee,
923 gimple old_stmt, gimple stmt,
924 gcov_type count,
925 int freq,
926 cgraph_inline_failed_t reason);
927
928 /* Return the callgraph edge representing the GIMPLE_CALL statement
929 CALL_STMT. */
930 cgraph_edge *get_edge (gimple call_stmt);
931
932 /* Collect all callers of cgraph_node and its aliases that are known to lead
933 to NODE (i.e. are not overwritable). */
934 vec<cgraph_edge *> collect_callers (void);
935
936 /* Remove all callers from the node. */
937 void remove_callers (void);
938
939 /* Remove all callees from the node. */
940 void remove_callees (void);
941
942 /* Return function availability. See cgraph.h for description of individual
943 return values. */
944 enum availability get_availability (void);
945
946 /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node
947 if any to NOTHROW. */
948 void set_nothrow_flag (bool nothrow);
949
950 /* Set TREE_READONLY on cgraph_node's decl and on aliases of the node
951 if any to READONLY. */
952 void set_const_flag (bool readonly, bool looping);
953
954 /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
955 if any to PURE. */
956 void set_pure_flag (bool pure, bool looping);
957
958 /* Call all node duplication hooks. */
959 void call_duplication_hooks (cgraph_node *node2);
960
961 /* Call calback on function and aliases associated to the function.
962 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
963 skipped. */
964
965 bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
966 void *),
967 void *data, bool include_overwritable);
968
969 /* Call calback on cgraph_node, thunks and aliases associated to NODE.
970 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
971 skipped. */
972 bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node,
973 void *data),
974 void *data,
975 bool include_overwritable);
976
977 /* Call all node insertion hooks. */
978 void call_function_insertion_hooks (void);
979
980 /* Likewise indicate that a node is needed, i.e. reachable via some
981 external means. */
982 inline void mark_force_output (void);
983
984 /* Return true when function can be marked local. */
985 bool local_p (void);
986
987 /* Return true if cgraph_node can be made local for API change.
988 Extern inline functions and C++ COMDAT functions can be made local
989 at the expense of possible code size growth if function is used in multiple
990 compilation units. */
991 bool can_be_local_p (void);
992
993 /* Return true when cgraph_node can not return or throw and thus
994 it is safe to ignore its side effects for IPA analysis. */
995 bool cannot_return_p (void);
996
997 /* Return true when function cgraph_node and all its aliases are only called
998 directly.
999 i.e. it is not externally visible, address was not taken and
1000 it is not used in any other non-standard way. */
1001 bool only_called_directly_p (void);
1002
1003 /* Return true when function is only called directly or it has alias.
1004 i.e. it is not externally visible, address was not taken and
1005 it is not used in any other non-standard way. */
1006 inline bool only_called_directly_or_aliased_p (void);
1007
1008 /* Return true when function cgraph_node can be expected to be removed
1009 from program when direct calls in this compilation unit are removed.
1010
1011 As a special case COMDAT functions are
1012 cgraph_can_remove_if_no_direct_calls_p while the are not
1013 cgraph_only_called_directly_p (it is possible they are called from other
1014 unit)
1015
1016 This function behaves as cgraph_only_called_directly_p because eliminating
1017 all uses of COMDAT function does not make it necessarily disappear from
1018 the program unless we are compiling whole program or we do LTO. In this
1019 case we know we win since dynamic linking will not really discard the
1020 linkonce section. */
1021 bool will_be_removed_from_program_if_no_direct_calls_p (void);
1022
1023 /* Return true when function can be removed from callgraph
1024 if all direct calls are eliminated. */
1025 bool can_remove_if_no_direct_calls_and_refs_p (void);
1026
1027 /* Return true when function cgraph_node and its aliases can be removed from
1028 callgraph if all direct calls are eliminated. */
1029 bool can_remove_if_no_direct_calls_p (void);
1030
1031 /* Return true when callgraph node is a function with Gimple body defined
1032 in current unit. Functions can also be define externally or they
1033 can be thunks with no Gimple representation.
1034
1035 Note that at WPA stage, the function body may not be present in memory. */
1036 inline bool has_gimple_body_p (void);
1037
1038 /* Return true if function should be optimized for size. */
1039 bool optimize_for_size_p (void);
1040
1041 /* Dump the callgraph to file F. */
1042 static void dump_cgraph (FILE *f);
1043
1044 /* Dump the call graph to stderr. */
1045 static inline void debug_cgraph (void)
1046 {
1047 dump_cgraph (stderr);
1048 }
1049
1050 /* Record that DECL1 and DECL2 are semantically identical function
1051 versions. */
1052 static void record_function_versions (tree decl1, tree decl2);
1053
1054 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
1055 DECL is a duplicate declaration. */
1056 static void delete_function_version (tree decl);
1057
1058 /* Add the function FNDECL to the call graph.
1059 Unlike cgraph_finalize_function, this function is intended to be used
1060 by middle end and allows insertion of new function at arbitrary point
1061 of compilation. The function can be either in high, low or SSA form
1062 GIMPLE.
1063
1064 The function is assumed to be reachable and have address taken (so no
1065 API breaking optimizations are performed on it).
1066
1067 Main work done by this function is to enqueue the function for later
1068 processing to avoid need the passes to be re-entrant. */
1069 static void add_new_function (tree fndecl, bool lowered);
1070
1071 /* Return callgraph node for given symbol and check it is a function. */
1072 static inline cgraph_node *get (const_tree decl)
1073 {
1074 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1075 return dyn_cast <cgraph_node *> (symtab_node::get (decl));
1076 }
1077
1078 /* Return cgraph node assigned to DECL. Create new one when needed. */
1079 static cgraph_node * create (tree decl);
1080
1081 /* Allocate new callgraph node and insert it into basic data structures. */
1082 static cgraph_node * create_empty (void);
1083
1084 /* Try to find a call graph node for declaration DECL and if it does not
1085 exist or if it corresponds to an inline clone, create a new one. */
1086 static cgraph_node * get_create (tree);
1087
1088 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
1089 Return NULL if there's no such node. */
1090 static cgraph_node *get_for_asmname (tree asmname);
1091
1092 /* Attempt to mark ALIAS as an alias to DECL. Return alias node if
1093 successful and NULL otherwise.
1094 Same body aliases are output whenever the body of DECL is output,
1095 and cgraph_node::get (ALIAS) transparently
1096 returns cgraph_node::get (DECL). */
1097 static cgraph_node * create_same_body_alias (tree alias, tree decl);
1098
1099 /* Worker for cgraph_can_remove_if_no_direct_calls_p. */
1100 static bool used_from_object_file_p_worker (cgraph_node *node, void *)
1101 {
1102 return node->used_from_object_file_p ();
1103 }
1104
1105 /* Return true when cgraph_node can not be local.
1106 Worker for cgraph_local_node_p. */
1107 static bool non_local_p (cgraph_node *node, void *);
1108
1109 /* Verify whole cgraph structure. */
1110 static void DEBUG_FUNCTION verify_cgraph_nodes (void);
1111
1112 /* Worker to bring NODE local. */
1113 static bool make_local (cgraph_node *node, void *);
1114
1115 /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
1116 the function body is associated
1117 with (not necessarily cgraph_node (DECL). */
1118 static cgraph_node *create_alias (tree alias, tree target);
1119
1120 static cgraph_edge * create_edge (cgraph_node *caller, cgraph_node *callee,
1121 gimple call_stmt, gcov_type count,
1122 int freq,
1123 bool indir_unknown_callee);
1124
1c4a429a
JH
1125 struct cgraph_edge *callees;
1126 struct cgraph_edge *callers;
e33c6cd6
MJ
1127 /* List of edges representing indirect calls with a yet undetermined
1128 callee. */
1129 struct cgraph_edge *indirect_calls;
1c4a429a 1130 /* For nested functions points to function the node is nested in. */
d52f5295 1131 cgraph_node *origin;
1c4a429a 1132 /* Points to first nested function, if any. */
d52f5295 1133 cgraph_node *nested;
1c4a429a 1134 /* Pointer to the next function with same origin, if any. */
d52f5295 1135 cgraph_node *next_nested;
18c6ada9 1136 /* Pointer to the next clone. */
d52f5295
ML
1137 cgraph_node *next_sibling_clone;
1138 cgraph_node *prev_sibling_clone;
1139 cgraph_node *clones;
1140 cgraph_node *clone_of;
70d539ce
JH
1141 /* For functions with many calls sites it holds map from call expression
1142 to the edge to speed up cgraph_edge function. */
1143 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
97ba0040
JH
1144 /* Declaration node used to be clone of. */
1145 tree former_clone_of;
c22cacf3 1146
0136f8f0
AH
1147 /* If this is a SIMD clone, this points to the SIMD specific
1148 information for it. */
1149 struct cgraph_simd_clone *simdclone;
1150 /* If this function has SIMD clones, this points to the first clone. */
d52f5295 1151 cgraph_node *simd_clones;
0136f8f0 1152
0e3776db
JH
1153 /* Interprocedural passes scheduled to have their transform functions
1154 applied next time we execute local pass on them. We maintain it
1155 per-function in order to allow IPA passes to introduce new functions. */
9771b263 1156 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
0e3776db 1157
95c755e9
JH
1158 struct cgraph_local_info local;
1159 struct cgraph_global_info global;
1160 struct cgraph_rtl_info rtl;
9187e02d 1161 struct cgraph_clone_info clone;
6744a6ab 1162 struct cgraph_thunk_info thunk;
c22cacf3 1163
e42922b1
JH
1164 /* Expected number of executions: calculated in profile.c. */
1165 gcov_type count;
db0bf14f
JH
1166 /* How to scale counts at materialization time; used to merge
1167 LTO units with different number of profile runs. */
1168 int count_materialization_scale;
95c755e9
JH
1169 /* Unique id of the node. */
1170 int uid;
2fa3d31b
JH
1171 /* ID assigned by the profiling. */
1172 unsigned int profile_id;
86ce5d2f
ML
1173 /* Time profiler: first run of function. */
1174 int tp_first_run;
3691626c 1175
6b20f353
DS
1176 /* Set when decl is an abstract function pointed to by the
1177 ABSTRACT_DECL_ORIGIN of a reachable function. */
c0c123ef 1178 unsigned used_as_abstract_origin : 1;
50674e96 1179 /* Set once the function is lowered (i.e. its CFG is built). */
b4e19405 1180 unsigned lowered : 1;
25c84396
RH
1181 /* Set once the function has been instantiated and its callee
1182 lists created. */
257eb6e3 1183 unsigned process : 1;
5fefcf92
JH
1184 /* How commonly executed the node is. Initialized during branch
1185 probabilities pass. */
1186 ENUM_BITFIELD (node_frequency) frequency : 2;
844db5d0
JH
1187 /* True when function can only be called at startup (from static ctor). */
1188 unsigned only_called_at_startup : 1;
1189 /* True when function can only be called at startup (from static dtor). */
1190 unsigned only_called_at_exit : 1;
0a35513e
AH
1191 /* True when function is the transactional clone of a function which
1192 is called only from inside transactions. */
1193 /* ?? We should be able to remove this. We have enough bits in
1194 cgraph to calculate it. */
1195 unsigned tm_clone : 1;
3649b9b7
ST
1196 /* True if this decl is a dispatcher for function versions. */
1197 unsigned dispatcher_function : 1;
1f26ac87
JM
1198 /* True if this decl calls a COMDAT-local function. This is set up in
1199 compute_inline_parameters and inline_call. */
1200 unsigned calls_comdat_local : 1;
3649b9b7
ST
1201};
1202
fed5ae11
DK
1203/* A cgraph node set is a collection of cgraph nodes. A cgraph node
1204 can appear in multiple sets. */
1cb1a99f 1205struct cgraph_node_set_def
fed5ae11 1206{
1cb1a99f 1207 struct pointer_map_t *map;
d52f5295 1208 vec<cgraph_node *> nodes;
fed5ae11
DK
1209};
1210
d52f5295
ML
1211typedef cgraph_node_set_def *cgraph_node_set;
1212typedef struct varpool_node_set_def *varpool_node_set;
2942c502 1213
d52f5295 1214class varpool_node;
2942c502
JH
1215
1216/* A varpool node set is a collection of varpool nodes. A varpool node
1217 can appear in multiple sets. */
1cb1a99f 1218struct varpool_node_set_def
2942c502 1219{
1cb1a99f 1220 struct pointer_map_t * map;
d52f5295 1221 vec<varpool_node *> nodes;
2942c502
JH
1222};
1223
fed5ae11 1224/* Iterator structure for cgraph node sets. */
84562394 1225struct cgraph_node_set_iterator
fed5ae11
DK
1226{
1227 cgraph_node_set set;
1228 unsigned index;
84562394 1229};
fed5ae11 1230
2942c502 1231/* Iterator structure for varpool node sets. */
84562394 1232struct varpool_node_set_iterator
2942c502
JH
1233{
1234 varpool_node_set set;
1235 unsigned index;
84562394 1236};
2942c502 1237
e33c6cd6
MJ
1238/* Structure containing additional information about an indirect call. */
1239
1240struct GTY(()) cgraph_indirect_call_info
1241{
8b7773a4
MJ
1242 /* When polymorphic is set, this field contains offset where the object which
1243 was actually used in the polymorphic resides within a larger structure.
1244 If agg_contents is set, the field contains the offset within the aggregate
1245 from which the address to call was loaded. */
3339f0bc 1246 HOST_WIDE_INT offset, speculative_offset;
b258210c
MJ
1247 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
1248 HOST_WIDE_INT otr_token;
1249 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
3339f0bc 1250 tree otr_type, outer_type, speculative_outer_type;
e33c6cd6
MJ
1251 /* Index of the parameter that is called. */
1252 int param_index;
5f902d76
JH
1253 /* ECF flags determined from the caller. */
1254 int ecf_flags;
634ab819
JH
1255 /* Profile_id of common target obtrained from profile. */
1256 int common_target_id;
1257 /* Probability that call will land in function with COMMON_TARGET_ID. */
1258 int common_target_probability;
b258210c
MJ
1259
1260 /* Set when the call is a virtual call with the parameter being the
1261 associated object pointer rather than a simple direct call. */
1262 unsigned polymorphic : 1;
8b7773a4
MJ
1263 /* Set when the call is a call of a pointer loaded from contents of an
1264 aggregate at offset. */
1265 unsigned agg_contents : 1;
c13bc3d9
MJ
1266 /* Set when this is a call through a member pointer. */
1267 unsigned member_ptr : 1;
8b7773a4
MJ
1268 /* When the previous bit is set, this one determines whether the destination
1269 is loaded from a parameter passed by reference. */
1270 unsigned by_ref : 1;
68377e53
JH
1271 unsigned int maybe_in_construction : 1;
1272 unsigned int maybe_derived_type : 1;
3339f0bc 1273 unsigned int speculative_maybe_derived_type : 1;
e33c6cd6
MJ
1274};
1275
d1b38208 1276struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
6009ee7b
MJ
1277 /* Expected number of executions: calculated in profile.c. */
1278 gcov_type count;
d52f5295
ML
1279 cgraph_node *caller;
1280 cgraph_node *callee;
2563c224 1281 struct cgraph_edge *prev_caller;
1c4a429a 1282 struct cgraph_edge *next_caller;
2563c224 1283 struct cgraph_edge *prev_callee;
1c4a429a 1284 struct cgraph_edge *next_callee;
726a989a 1285 gimple call_stmt;
e33c6cd6
MJ
1286 /* Additional information about an indirect call. Not cleared when an edge
1287 becomes direct. */
1288 struct cgraph_indirect_call_info *indirect_info;
18c6ada9 1289 PTR GTY ((skip (""))) aux;
61a05df1
JH
1290 /* When equal to CIF_OK, inline this call. Otherwise, points to the
1291 explanation why function was not inlined. */
84562394 1292 enum cgraph_inline_failed_t inline_failed;
6009ee7b
MJ
1293 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
1294 when the function is serialized in. */
1295 unsigned int lto_stmt_uid;
b8698a0f 1296 /* Expected frequency of executions within the function.
45a80bb9
JH
1297 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
1298 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
1299 int frequency;
6009ee7b
MJ
1300 /* Unique id of the edge. */
1301 int uid;
e33c6cd6
MJ
1302 /* Whether this edge was made direct by indirect inlining. */
1303 unsigned int indirect_inlining_edge : 1;
1304 /* Whether this edge describes an indirect call with an undetermined
1305 callee. */
1306 unsigned int indirect_unknown_callee : 1;
1307 /* Whether this edge is still a dangling */
d7f09764
DN
1308 /* True if the corresponding CALL stmt cannot be inlined. */
1309 unsigned int call_stmt_cannot_inline_p : 1;
2505c5ed
JH
1310 /* Can this call throw externally? */
1311 unsigned int can_throw_external : 1;
042ae7d2
JH
1312 /* Edges with SPECULATIVE flag represents indirect calls that was
1313 speculatively turned into direct (i.e. by profile feedback).
1314 The final code sequence will have form:
1315
1316 if (call_target == expected_fn)
1317 expected_fn ();
1318 else
1319 call_target ();
1320
1321 Every speculative call is represented by three components attached
1322 to a same call statement:
1323 1) a direct call (to expected_fn)
1324 2) an indirect call (to call_target)
1325 3) a IPA_REF_ADDR refrence to expected_fn.
1326
1327 Optimizers may later redirect direct call to clone, so 1) and 3)
1328 do not need to necesarily agree with destination. */
1329 unsigned int speculative : 1;
1c4a429a
JH
1330};
1331
45a80bb9
JH
1332#define CGRAPH_FREQ_BASE 1000
1333#define CGRAPH_FREQ_MAX 100000
1334
8a4a83ed
JH
1335/* The varpool data structure.
1336 Each static variable decl has assigned varpool_node. */
e69529cd 1337
5e20cdc9 1338class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
a3bfa8b8 1339public:
9041d2e6
ML
1340 /* Dump given varpool node to F. */
1341 void dump (FILE *f);
1342
1343 /* Dump given varpool node to stderr. */
1344 void DEBUG_FUNCTION debug (void);
1345
1346 /* Remove variable from symbol table. */
1347 void remove (void);
1348
1349 /* Remove node initializer when it is no longer needed. */
1350 void remove_initializer (void);
1351
1352 void analyze (void);
1353
1354 /* Return variable availability. */
1355 availability get_availability (void);
1356
1357 /* When doing LTO, read variable's constructor from disk if
1358 it is not already present. */
1359 tree get_constructor (void);
1360
1361 /* Return true if variable has constructor that can be used for folding. */
1362 bool ctor_useable_for_folding_p (void);
1363
1364 /* For given variable pool node, walk the alias chain to return the function
1365 the variable is alias of. Do not walk through thunks.
1366 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1367 inline varpool_node *ultimate_alias_target
1368 (availability *availability = NULL);
1369
1370 /* Return node that alias is aliasing. */
1371 inline varpool_node *get_alias_target (void);
1372
1373 /* Output one variable, if necessary. Return whether we output it. */
1374 bool assemble_decl (void);
1375
1376 /* For variables in named sections make sure get_variable_section
1377 is called before we switch to those sections. Then section
1378 conflicts between read-only and read-only requiring relocations
1379 sections can be resolved. */
1380 void finalize_named_section_flags (void);
1381
1382 /* Call calback on varpool symbol and aliases associated to varpool symbol.
1383 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1384 skipped. */
1385 bool call_for_node_and_aliases (bool (*callback) (varpool_node *, void *),
1386 void *data,
1387 bool include_overwritable);
1388
1389 /* Return true when variable should be considered externally visible. */
1390 bool externally_visible_p (void);
1391
1392 /* Return true when all references to variable must be visible
1393 in ipa_ref_list.
1394 i.e. if the variable is not externally visible or not used in some magic
1395 way (asm statement or such).
1396 The magic uses are all summarized in force_output flag. */
1397 inline bool all_refs_explicit_p ();
1398
1399 /* Return true when variable can be removed from variable pool
1400 if all direct calls are eliminated. */
1401 inline bool can_remove_if_no_refs_p (void);
1402
1403 /* Return varpool node for given symbol and check it is a function. */
1404 static inline varpool_node *get (const_tree decl);
1405
1406 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct
1407 the middle end to output the variable to asm file, if needed or externally
1408 visible. */
1409 static void finalize_decl (tree decl);
1410
1411 /* Output all variables enqueued to be assembled. */
1412 static bool output_variables (void);
1413
1414 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
1415 Extra name aliases are output whenever DECL is output. */
1416 static varpool_node * create_extra_name_alias (tree alias, tree decl);
1417
1418 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
1419 Extra name aliases are output whenever DECL is output. */
1420 static varpool_node * create_alias (tree, tree);
1421
1422 /* Dump the variable pool to F. */
1423 static void dump_varpool (FILE *f);
1424
1425 /* Dump the variable pool to stderr. */
1426 static void DEBUG_FUNCTION debug_varpool (void);
1427
1428 /* Allocate new callgraph node and insert it into basic data structures. */
1429 static varpool_node *create_empty (void);
1430
1431 /* Return varpool node assigned to DECL. Create new one when needed. */
1432 static varpool_node *get_create (tree decl);
1433
1434 /* Given an assembler name, lookup node. */
1435 static varpool_node *get_for_asmname (tree asmname);
1436
6b02a499 1437 /* Set when variable is scheduled to be assembled. */
b4e19405 1438 unsigned output : 1;
eb1d8159 1439
59b36ecf
JJ
1440 /* Set if the variable is dynamically initialized, except for
1441 function local statics. */
1442 unsigned dynamically_initialized : 1;
56363ffd
JH
1443
1444 ENUM_BITFIELD(tls_model) tls_model : 3;
eb6a09a7
JH
1445
1446 /* Set if the variable is known to be used by single function only.
1447 This is computed by ipa_signle_use pass and used by late optimizations
1448 in places where optimization would be valid for local static variable
1449 if we did not do any inter-procedural code movement. */
1450 unsigned used_by_single_function : 1;
d52f5295 1451
9041d2e6
ML
1452private:
1453 /* Assemble thunks and aliases associated to varpool node. */
1454 void assemble_aliases (void);
e69529cd
JH
1455};
1456
65d630d4 1457/* Every top level asm statement is put into a asm_node. */
474eccc6 1458
65d630d4 1459struct GTY(()) asm_node {
474eccc6 1460 /* Next asm node. */
65d630d4 1461 struct asm_node *next;
474eccc6
ILT
1462 /* String for this asm node. */
1463 tree asm_str;
1464 /* Ordering of all cgraph nodes. */
1465 int order;
1466};
1467
5d59b5e1
LC
1468/* Report whether or not THIS symtab node is a function, aka cgraph_node. */
1469
1470template <>
1471template <>
1472inline bool
7de90a6c 1473is_a_helper <cgraph_node *>::test (symtab_node *p)
5d59b5e1 1474{
d52f5295 1475 return p && p->type == SYMTAB_FUNCTION;
5d59b5e1
LC
1476}
1477
1478/* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
1479
1480template <>
1481template <>
1482inline bool
7de90a6c 1483is_a_helper <varpool_node *>::test (symtab_node *p)
5d59b5e1 1484{
d52f5295 1485 return p && p->type == SYMTAB_VARIABLE;
5d59b5e1
LC
1486}
1487
5e20cdc9 1488extern GTY(()) symtab_node *symtab_nodes;
ed2df68b 1489extern GTY(()) int cgraph_n_nodes;
b58b1157 1490extern GTY(()) int cgraph_max_uid;
9088c1cc 1491extern GTY(()) int cgraph_edge_max_uid;
dafc5b82 1492extern bool cgraph_global_info_ready;
f45e0ad1
JH
1493enum cgraph_state
1494{
66058468
JH
1495 /* Frontend is parsing and finalizing functions. */
1496 CGRAPH_STATE_PARSING,
f45e0ad1
JH
1497 /* Callgraph is being constructed. It is safe to add new functions. */
1498 CGRAPH_STATE_CONSTRUCTION,
ca0f62a8
JH
1499 /* Callgraph is being at LTO time. */
1500 CGRAPH_LTO_STREAMING,
f45e0ad1
JH
1501 /* Callgraph is built and IPA passes are being run. */
1502 CGRAPH_STATE_IPA,
7a388ee4
JH
1503 /* Callgraph is built and all functions are transformed to SSA form. */
1504 CGRAPH_STATE_IPA_SSA,
f45e0ad1
JH
1505 /* Functions are now ordered and being passed to RTL expanders. */
1506 CGRAPH_STATE_EXPANSION,
1507 /* All cgraph expansion is done. */
1508 CGRAPH_STATE_FINISHED
1509};
1510extern enum cgraph_state cgraph_state;
e7d6beb0 1511extern bool cgraph_function_flags_ready;
66058468 1512extern cgraph_node_set cgraph_new_nodes;
1c4a429a 1513
65d630d4 1514extern GTY(()) struct asm_node *asm_nodes;
2aae7680 1515extern GTY(()) int symtab_order;
40a7fe1e 1516extern bool cpp_implicit_aliases_done;
e69529cd 1517
2aae7680 1518/* In symtab.c */
5e20cdc9 1519symtab_node *symtab_node_for_asm (const_tree asmname);
2aae7680 1520
1c4a429a 1521/* In cgraph.c */
12123452 1522void release_function_body (tree);
ce47fda3 1523struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
d52f5295
ML
1524void cgraph_remove_edge (struct cgraph_edge *);
1525
042ae7d2 1526void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
4b685e14 1527void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
439f7bc3
AJ
1528struct cgraph_local_info *cgraph_local_info (tree);
1529struct cgraph_global_info *cgraph_global_info (tree);
1530struct cgraph_rtl_info *cgraph_rtl_info (tree);
66a20fc2
JH
1531void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
1532 struct cgraph_edge *);
1c4a429a 1533
1bb17c21 1534bool cgraph_function_possibly_inlined_p (tree);
d52f5295
ML
1535bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
1536void cgraph_redirect_edge_callee (struct cgraph_edge *, cgraph_node *);
1537struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *,
1538 cgraph_node *);
1bb17c21 1539
61a05df1 1540const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
1cf11770 1541cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
6b02a499 1542
be330ed4 1543bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
9088c1cc 1544typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
d52f5295 1545typedef void (*cgraph_node_hook)(cgraph_node *, void *);
2c8326a5 1546typedef void (*varpool_node_hook)(varpool_node *, void *);
9088c1cc
MJ
1547typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
1548 void *);
d52f5295 1549typedef void (*cgraph_2node_hook)(cgraph_node *, cgraph_node *,
9088c1cc
MJ
1550 void *);
1551struct cgraph_edge_hook_list;
1552struct cgraph_node_hook_list;
26e5b0fd 1553struct varpool_node_hook_list;
9088c1cc
MJ
1554struct cgraph_2edge_hook_list;
1555struct cgraph_2node_hook_list;
1556struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
1557void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
d52f5295 1558cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
9088c1cc 1559 void *);
d52f5295 1560void cgraph_remove_node_removal_hook (cgraph_node_hook_list *);
26e5b0fd
JH
1561struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
1562 void *);
1563void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
d52f5295 1564cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
129a37fc 1565 void *);
d52f5295 1566void cgraph_remove_function_insertion_hook (cgraph_node_hook_list *);
26e5b0fd
JH
1567struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
1568 void *);
1569void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
9088c1cc
MJ
1570struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
1571void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
1572struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
1573void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
8132a837 1574gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
09ce3660 1575struct cgraph_edge *
042ae7d2 1576cgraph_turn_edge_to_speculative (struct cgraph_edge *,
d52f5295 1577 cgraph_node *,
042ae7d2
JH
1578 gcov_type, int);
1579void cgraph_speculative_call_info (struct cgraph_edge *,
1580 struct cgraph_edge *&,
1581 struct cgraph_edge *&,
1582 struct ipa_ref *&);
4484a35a 1583extern bool gimple_check_call_matching_types (gimple, tree, bool);
9c8305f8
JH
1584
1585/* In cgraphunit.c */
65d630d4 1586struct asm_node *add_asm_node (tree);
9c8305f8
JH
1587extern FILE *cgraph_dump_file;
1588void cgraph_finalize_function (tree, bool);
65d630d4
JH
1589void finalize_compilation_unit (void);
1590void compile (void);
9c8305f8 1591void init_cgraph (void);
b4d05578 1592void cgraph_process_new_functions (void);
66a20fc2 1593void cgraph_process_same_body_aliases (void);
3649b9b7
ST
1594/* Initialize datastructures so DECL is a function in lowered gimple form.
1595 IN_SSA is true if the gimple is in SSA. */
e70670cf 1596basic_block init_lowered_empty_function (tree, bool);
66a20fc2
JH
1597
1598/* In cgraphclones.c */
1599
1600struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
d52f5295 1601 cgraph_node *, gimple,
66a20fc2 1602 unsigned, gcov_type, int, bool);
66a20fc2 1603tree clone_function_name (tree decl, const char *);
d52f5295 1604
66a20fc2 1605void cgraph_materialize_all_clones (void);
d52f5295 1606void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *,
9c8305f8 1607 bool, bitmap, bool, bitmap, basic_block);
09ce3660 1608struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
9c8305f8 1609
917948d3
ZD
1610/* In cgraphbuild.c */
1611unsigned int rebuild_cgraph_edges (void);
99b766fc 1612void cgraph_rebuild_references (void);
9187e02d 1613int compute_call_stmt_bb_frequency (tree, basic_block bb);
9c8305f8 1614void record_references_in_initializer (tree, bool);
917948d3 1615
ca31b95f 1616/* In ipa.c */
04142cc3 1617bool symtab_remove_unreachable_nodes (bool, FILE *);
fed5ae11
DK
1618cgraph_node_set cgraph_node_set_new (void);
1619cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
d52f5295
ML
1620 cgraph_node *);
1621void cgraph_node_set_add (cgraph_node_set, cgraph_node *);
1622void cgraph_node_set_remove (cgraph_node_set, cgraph_node *);
fed5ae11
DK
1623void dump_cgraph_node_set (FILE *, cgraph_node_set);
1624void debug_cgraph_node_set (cgraph_node_set);
1cb1a99f 1625void free_cgraph_node_set (cgraph_node_set);
9c8305f8 1626void cgraph_build_static_cdtor (char which, tree body, int priority);
fed5ae11 1627
2942c502
JH
1628varpool_node_set varpool_node_set_new (void);
1629varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
2c8326a5
OE
1630 varpool_node *);
1631void varpool_node_set_add (varpool_node_set, varpool_node *);
1632void varpool_node_set_remove (varpool_node_set, varpool_node *);
2942c502
JH
1633void dump_varpool_node_set (FILE *, varpool_node_set);
1634void debug_varpool_node_set (varpool_node_set);
1cb1a99f 1635void free_varpool_node_set (varpool_node_set);
4a444e58 1636void ipa_discover_readonly_nonaddressable_vars (void);
ca31b95f 1637
fed5ae11 1638/* In predict.c */
ca30a539
JH
1639bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
1640
8a4a83ed 1641/* In varpool.c */
b34fd25c 1642void varpool_reset_queue (void);
6a6dac52 1643tree ctor_for_folding (tree);
38877e98 1644void varpool_add_new_variable (tree);
b5493fb2 1645void symtab_initialize_asm_name_hash (void);
5e20cdc9 1646void symtab_prevail_in_asm_name_hash (symtab_node *node);
8a4a83ed 1647
d8a2d370
DN
1648/* In cgraph.c */
1649extern void change_decl_assembler_name (tree, tree);
68e56cc4 1650
d52f5295
ML
1651/* Return true when the symbol is real symbol, i.e. it is not inline clone
1652 or abstract function kept for debug info purposes only. */
1653inline bool
1654symtab_node::real_symbol_p (void)
1655{
1656 cgraph_node *cnode;
1657
1658 if (DECL_ABSTRACT (decl))
1659 return false;
1660 if (!is_a <cgraph_node *> (this))
1661 return true;
1662 cnode = dyn_cast <cgraph_node *> (this);
1663 if (cnode->global.inlined_to)
1664 return false;
1665 return true;
1666}
1667
89330618
JH
1668/* Return true if DECL should have entry in symbol table if used.
1669 Those are functions and static & external veriables*/
1670
0241e486 1671static inline bool
89330618
JH
1672decl_in_symtab_p (const_tree decl)
1673{
1674 return (TREE_CODE (decl) == FUNCTION_DECL
1675 || (TREE_CODE (decl) == VAR_DECL
1676 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))));
1677}
1678
d52f5295
ML
1679inline bool
1680symtab_node::in_same_comdat_group_p (symtab_node *target)
aede2c10 1681{
d52f5295 1682 symtab_node *source = this;
aede2c10 1683
d52f5295
ML
1684 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
1685 {
1686 if (cn->global.inlined_to)
1687 source = cn->global.inlined_to;
1688 }
1689 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
1690 {
1691 if (cn->global.inlined_to)
1692 target = cn->global.inlined_to;
1693 }
1694
1695 return source->get_comdat_group () == target->get_comdat_group ();
1f00098b
JH
1696}
1697
d52f5295
ML
1698/* Return node that alias is aliasing. */
1699
1700inline symtab_node *
1701symtab_node::get_alias_target (void)
1f00098b 1702{
d52f5295
ML
1703 struct ipa_ref *ref = NULL;
1704 iterate_reference (0, ref);
1705 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1706 return ref->referred;
1f00098b
JH
1707}
1708
d52f5295
ML
1709/* Return next reachable static symbol with initializer after the node. */
1710inline symtab_node *
1711symtab_node::next_defined_symbol (void)
1ab24192 1712{
d52f5295
ML
1713 symtab_node *node1 = next;
1714
1715 for (; node1; node1 = node1->next)
1716 if (node1->definition)
1717 return node1;
1718
1719 return NULL;
1ab24192
JH
1720}
1721
1722/* Return varpool node for given symbol and check it is a function. */
9041d2e6
ML
1723inline varpool_node *
1724varpool_node::get (const_tree decl)
1ab24192
JH
1725{
1726 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
d52f5295 1727 return dyn_cast<varpool_node *> (symtab_node::get (decl));
1ab24192
JH
1728}
1729
1730/* Walk all symbols. */
1731#define FOR_EACH_SYMBOL(node) \
67348ccc 1732 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1f00098b 1733
d6d229c6
JH
1734/* Return first static symbol with definition. */
1735static inline symtab_node *
1736symtab_first_defined_symbol (void)
1737{
1738 symtab_node *node;
1739
1740 for (node = symtab_nodes; node; node = node->next)
1741 if (node->definition)
1742 return node;
1743
1744 return NULL;
1745}
1746
d6d229c6
JH
1747/* Walk all symbols with definitions in current unit. */
1748#define FOR_EACH_DEFINED_SYMBOL(node) \
1749 for ((node) = symtab_first_defined_symbol (); (node); \
d52f5295 1750 (node) = node->next_defined_symbol ())
66058468
JH
1751
1752/* Return first variable. */
2c8326a5 1753static inline varpool_node *
66058468
JH
1754varpool_first_variable (void)
1755{
5e20cdc9 1756 symtab_node *node;
67348ccc 1757 for (node = symtab_nodes; node; node = node->next)
7de90a6c 1758 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
5d59b5e1 1759 return vnode;
66058468
JH
1760 return NULL;
1761}
1762
1763/* Return next variable after NODE. */
2c8326a5
OE
1764static inline varpool_node *
1765varpool_next_variable (varpool_node *node)
66058468 1766{
5e20cdc9 1767 symtab_node *node1 = node->next;
67348ccc 1768 for (; node1; node1 = node1->next)
7de90a6c 1769 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
5d59b5e1 1770 return vnode1;
66058468
JH
1771 return NULL;
1772}
1773/* Walk all variables. */
1774#define FOR_EACH_VARIABLE(node) \
1775 for ((node) = varpool_first_variable (); \
1776 (node); \
1777 (node) = varpool_next_variable ((node)))
1778
d6d229c6 1779/* Return first static variable with initializer. */
2c8326a5 1780static inline varpool_node *
68e56cc4
JH
1781varpool_first_static_initializer (void)
1782{
5e20cdc9 1783 symtab_node *node;
67348ccc 1784 for (node = symtab_nodes; node; node = node->next)
68e56cc4 1785 {
7de90a6c 1786 varpool_node *vnode = dyn_cast <varpool_node *> (node);
67348ccc 1787 if (vnode && DECL_INITIAL (node->decl))
5d59b5e1 1788 return vnode;
68e56cc4
JH
1789 }
1790 return NULL;
1791}
1792
d6d229c6 1793/* Return next static variable with initializer after NODE. */
2c8326a5
OE
1794static inline varpool_node *
1795varpool_next_static_initializer (varpool_node *node)
68e56cc4 1796{
5e20cdc9 1797 symtab_node *node1 = node->next;
67348ccc 1798 for (; node1; node1 = node1->next)
68e56cc4 1799 {
7de90a6c 1800 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
67348ccc 1801 if (vnode1 && DECL_INITIAL (node1->decl))
5d59b5e1 1802 return vnode1;
68e56cc4
JH
1803 }
1804 return NULL;
1805}
1806
1807/* Walk all static variables with initializer set. */
1808#define FOR_EACH_STATIC_INITIALIZER(node) \
1809 for ((node) = varpool_first_static_initializer (); (node); \
1810 (node) = varpool_next_static_initializer (node))
2aae7680 1811
d6d229c6 1812/* Return first static variable with definition. */
2c8326a5 1813static inline varpool_node *
66058468 1814varpool_first_defined_variable (void)
2aae7680 1815{
5e20cdc9 1816 symtab_node *node;
67348ccc 1817 for (node = symtab_nodes; node; node = node->next)
2aae7680 1818 {
7de90a6c 1819 varpool_node *vnode = dyn_cast <varpool_node *> (node);
67348ccc 1820 if (vnode && vnode->definition)
5d59b5e1 1821 return vnode;
2aae7680
JH
1822 }
1823 return NULL;
1824}
1825
d6d229c6 1826/* Return next static variable with definition after NODE. */
2c8326a5
OE
1827static inline varpool_node *
1828varpool_next_defined_variable (varpool_node *node)
2aae7680 1829{
5e20cdc9 1830 symtab_node *node1 = node->next;
67348ccc 1831 for (; node1; node1 = node1->next)
2aae7680 1832 {
7de90a6c 1833 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
67348ccc 1834 if (vnode1 && vnode1->definition)
5d59b5e1 1835 return vnode1;
2aae7680
JH
1836 }
1837 return NULL;
1838}
65c70e6b
JH
1839/* Walk all variables with definitions in current unit. */
1840#define FOR_EACH_DEFINED_VARIABLE(node) \
66058468
JH
1841 for ((node) = varpool_first_defined_variable (); (node); \
1842 (node) = varpool_next_defined_variable (node))
68e56cc4 1843
c47d0034 1844/* Return first function with body defined. */
d52f5295 1845static inline cgraph_node *
c47d0034
JH
1846cgraph_first_defined_function (void)
1847{
5e20cdc9 1848 symtab_node *node;
67348ccc 1849 for (node = symtab_nodes; node; node = node->next)
c47d0034 1850 {
7de90a6c 1851 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
67348ccc 1852 if (cn && cn->definition)
5d59b5e1 1853 return cn;
c47d0034
JH
1854 }
1855 return NULL;
1856}
1857
45896127 1858/* Return next function with body defined after NODE. */
d52f5295
ML
1859static inline cgraph_node *
1860cgraph_next_defined_function (cgraph_node *node)
c47d0034 1861{
5e20cdc9 1862 symtab_node *node1 = node->next;
67348ccc 1863 for (; node1; node1 = node1->next)
c47d0034 1864 {
7de90a6c 1865 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
67348ccc 1866 if (cn1 && cn1->definition)
5d59b5e1 1867 return cn1;
c47d0034
JH
1868 }
1869 return NULL;
1870}
1871
1872/* Walk all functions with body defined. */
1873#define FOR_EACH_DEFINED_FUNCTION(node) \
1874 for ((node) = cgraph_first_defined_function (); (node); \
2aae7680
JH
1875 (node) = cgraph_next_defined_function ((node)))
1876
1877/* Return first function. */
d52f5295 1878static inline cgraph_node *
2aae7680
JH
1879cgraph_first_function (void)
1880{
5e20cdc9 1881 symtab_node *node;
67348ccc 1882 for (node = symtab_nodes; node; node = node->next)
7de90a6c 1883 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
5d59b5e1 1884 return cn;
2aae7680
JH
1885 return NULL;
1886}
1887
1888/* Return next function. */
d52f5295
ML
1889static inline cgraph_node *
1890cgraph_next_function (cgraph_node *node)
2aae7680 1891{
5e20cdc9 1892 symtab_node *node1 = node->next;
67348ccc 1893 for (; node1; node1 = node1->next)
7de90a6c 1894 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
5d59b5e1 1895 return cn1;
2aae7680
JH
1896 return NULL;
1897}
65c70e6b
JH
1898/* Walk all functions. */
1899#define FOR_EACH_FUNCTION(node) \
2aae7680
JH
1900 for ((node) = cgraph_first_function (); (node); \
1901 (node) = cgraph_next_function ((node)))
c47d0034 1902
d52f5295 1903/* Return true when callgraph node is a function with Gimple body defined
c47d0034
JH
1904 in current unit. Functions can also be define externally or they
1905 can be thunks with no Gimple representation.
1906
1907 Note that at WPA stage, the function body may not be present in memory. */
1908
d52f5295
ML
1909inline bool
1910cgraph_node::has_gimple_body_p (void)
c47d0034 1911{
d52f5295 1912 return definition && !thunk.thunk_p && !alias;
c47d0034
JH
1913}
1914
1915/* Return first function with body defined. */
d52f5295 1916static inline cgraph_node *
c47d0034
JH
1917cgraph_first_function_with_gimple_body (void)
1918{
5e20cdc9 1919 symtab_node *node;
67348ccc 1920 for (node = symtab_nodes; node; node = node->next)
c47d0034 1921 {
7de90a6c 1922 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
d52f5295 1923 if (cn && cn->has_gimple_body_p ())
5d59b5e1 1924 return cn;
c47d0034
JH
1925 }
1926 return NULL;
1927}
1928
1929/* Return next reachable static variable with initializer after NODE. */
d52f5295
ML
1930static inline cgraph_node *
1931cgraph_next_function_with_gimple_body (cgraph_node *node)
c47d0034 1932{
5e20cdc9 1933 symtab_node *node1 = node->next;
67348ccc 1934 for (; node1; node1 = node1->next)
c47d0034 1935 {
7de90a6c 1936 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
d52f5295 1937 if (cn1 && cn1->has_gimple_body_p ())
5d59b5e1 1938 return cn1;
c47d0034
JH
1939 }
1940 return NULL;
1941}
1942
1943/* Walk all functions with body defined. */
1944#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1945 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1946 (node) = cgraph_next_function_with_gimple_body (node))
1947
43d861a5
RL
1948/* Create a new static variable of type TYPE. */
1949tree add_new_static_var (tree type);
1950
fed5ae11
DK
1951/* Return true if iterator CSI points to nothing. */
1952static inline bool
1953csi_end_p (cgraph_node_set_iterator csi)
1954{
9771b263 1955 return csi.index >= csi.set->nodes.length ();
fed5ae11
DK
1956}
1957
1958/* Advance iterator CSI. */
1959static inline void
1960csi_next (cgraph_node_set_iterator *csi)
1961{
1962 csi->index++;
1963}
1964
1965/* Return the node pointed to by CSI. */
d52f5295 1966static inline cgraph_node *
fed5ae11
DK
1967csi_node (cgraph_node_set_iterator csi)
1968{
9771b263 1969 return csi.set->nodes[csi.index];
fed5ae11
DK
1970}
1971
1972/* Return an iterator to the first node in SET. */
1973static inline cgraph_node_set_iterator
1974csi_start (cgraph_node_set set)
1975{
1976 cgraph_node_set_iterator csi;
1977
1978 csi.set = set;
1979 csi.index = 0;
1980 return csi;
1981}
1982
1983/* Return true if SET contains NODE. */
1984static inline bool
d52f5295 1985cgraph_node_in_set_p (cgraph_node *node, cgraph_node_set set)
fed5ae11
DK
1986{
1987 cgraph_node_set_iterator csi;
1988 csi = cgraph_node_set_find (set, node);
1989 return !csi_end_p (csi);
1990}
1991
1992/* Return number of nodes in SET. */
1993static inline size_t
1994cgraph_node_set_size (cgraph_node_set set)
1995{
9771b263 1996 return set->nodes.length ();
fed5ae11
DK
1997}
1998
2942c502
JH
1999/* Return true if iterator VSI points to nothing. */
2000static inline bool
2001vsi_end_p (varpool_node_set_iterator vsi)
2002{
9771b263 2003 return vsi.index >= vsi.set->nodes.length ();
2942c502
JH
2004}
2005
2006/* Advance iterator VSI. */
2007static inline void
2008vsi_next (varpool_node_set_iterator *vsi)
2009{
2010 vsi->index++;
2011}
2012
2013/* Return the node pointed to by VSI. */
2c8326a5 2014static inline varpool_node *
2942c502
JH
2015vsi_node (varpool_node_set_iterator vsi)
2016{
9771b263 2017 return vsi.set->nodes[vsi.index];
2942c502
JH
2018}
2019
2020/* Return an iterator to the first node in SET. */
2021static inline varpool_node_set_iterator
2022vsi_start (varpool_node_set set)
2023{
2024 varpool_node_set_iterator vsi;
2025
2026 vsi.set = set;
2027 vsi.index = 0;
2028 return vsi;
2029}
2030
2942c502
JH
2031/* Return number of nodes in SET. */
2032static inline size_t
2033varpool_node_set_size (varpool_node_set set)
2034{
9771b263 2035 return set->nodes.length ();
2942c502
JH
2036}
2037
d48e9cea
OR
2038/* Uniquize all constants that appear in memory.
2039 Each constant in memory thus far output is recorded
2040 in `const_desc_table'. */
2041
2042struct GTY(()) constant_descriptor_tree {
2043 /* A MEM for the constant. */
2044 rtx rtl;
b8698a0f 2045
d48e9cea
OR
2046 /* The value of the constant. */
2047 tree value;
2048
2049 /* Hash of value. Computing the hash from value each time
2050 hashfn is called can't work properly, as that means recursive
2051 use of the hash table during hash table expansion. */
2052 hashval_t hash;
2053};
2054
ace72c88
JH
2055/* Return true if set is nonempty. */
2056static inline bool
2057cgraph_node_set_nonempty_p (cgraph_node_set set)
2058{
9771b263 2059 return !set->nodes.is_empty ();
ace72c88
JH
2060}
2061
2062/* Return true if set is nonempty. */
2063static inline bool
2064varpool_node_set_nonempty_p (varpool_node_set set)
2065{
9771b263 2066 return !set->nodes.is_empty ();
ace72c88
JH
2067}
2068
d52f5295 2069/* Return true when function is only called directly or it has alias.
b20996ff
JH
2070 i.e. it is not externally visible, address was not taken and
2071 it is not used in any other non-standard way. */
2072
d52f5295
ML
2073inline bool
2074cgraph_node::only_called_directly_or_aliased_p (void)
2075{
2076 gcc_assert (!global.inlined_to);
2077 return (!force_output && !address_taken
2078 && !used_from_other_partition
2079 && !DECL_VIRTUAL_P (decl)
2080 && !DECL_STATIC_CONSTRUCTOR (decl)
2081 && !DECL_STATIC_DESTRUCTOR (decl)
2082 && !externally_visible);
b20996ff
JH
2083}
2084
9041d2e6 2085/* Return true when variable can be removed from variable pool
df7705b1
JH
2086 if all direct calls are eliminated. */
2087
9041d2e6
ML
2088inline bool
2089varpool_node::can_remove_if_no_refs_p (void)
df7705b1 2090{
9041d2e6 2091 if (DECL_EXTERNAL (decl))
6649df51 2092 return true;
9041d2e6
ML
2093 return (!force_output && !used_from_other_partition
2094 && ((DECL_COMDAT (decl)
2095 && !forced_by_abi
2096 && !used_from_object_file_p ())
2097 || !externally_visible
2098 || DECL_HAS_VALUE_EXPR_P (decl)));
df7705b1
JH
2099}
2100
9041d2e6 2101/* Return true when all references to variable must be visible in ipa_ref_list.
4a444e58
JH
2102 i.e. if the variable is not externally visible or not used in some magic
2103 way (asm statement or such).
61502ca8 2104 The magic uses are all summarized in force_output flag. */
4a444e58 2105
9041d2e6
ML
2106inline bool
2107varpool_node::all_refs_explicit_p ()
4a444e58 2108{
9041d2e6
ML
2109 return (definition
2110 && !externally_visible
2111 && !used_from_other_partition
2112 && !force_output);
4a444e58
JH
2113}
2114
d48e9cea
OR
2115/* Constant pool accessor function. */
2116htab_t constant_pool_htab (void);
fed5ae11 2117
d52f5295 2118/* Return node that alias is aliasing. */
39e2db00 2119
d52f5295
ML
2120inline cgraph_node *
2121cgraph_node::get_alias_target (void)
cd35bcf7 2122{
d52f5295 2123 return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ());
cd35bcf7
JH
2124}
2125
9041d2e6
ML
2126/* Return node that alias is aliasing. */
2127
2128inline varpool_node *
2129varpool_node::get_alias_target (void)
be330ed4 2130{
9041d2e6 2131 return dyn_cast <varpool_node *> (symtab_node::get_alias_target ());
be330ed4
JH
2132}
2133
d52f5295
ML
2134/* Given function symbol, walk the alias chain to return the function node
2135 is alias of. Do not walk through thunks.
073a8998 2136 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
be330ed4 2137
d52f5295
ML
2138inline cgraph_node *
2139cgraph_node::ultimate_alias_target (enum availability *availability)
be330ed4 2140{
d52f5295
ML
2141 cgraph_node *n = dyn_cast <cgraph_node *> (symtab_node::ultimate_alias_target
2142 (availability));
40a7fe1e 2143 if (!n && availability)
39e2db00 2144 *availability = AVAIL_NOT_AVAILABLE;
e70670cf 2145 return n;
be330ed4 2146}
9041d2e6
ML
2147
2148/* For given variable pool node, walk the alias chain to return the function
2149 the variable is alias of. Do not walk through thunks.
073a8998 2150 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
cd35bcf7 2151
9041d2e6
ML
2152inline varpool_node *
2153varpool_node::ultimate_alias_target (availability *availability)
cd35bcf7 2154{
9041d2e6
ML
2155 varpool_node *n = dyn_cast <varpool_node *>
2156 (symtab_node::ultimate_alias_target (availability));
ff36fcbe 2157
40a7fe1e 2158 if (!n && availability)
cd35bcf7 2159 *availability = AVAIL_NOT_AVAILABLE;
e70670cf 2160 return n;
cd35bcf7
JH
2161}
2162
d7d1d041
RG
2163/* Return true when the edge E represents a direct recursion. */
2164static inline bool
2165cgraph_edge_recursive_p (struct cgraph_edge *e)
2166{
d52f5295 2167 cgraph_node *callee = e->callee->ultimate_alias_target ();
d7d1d041 2168 if (e->caller->global.inlined_to)
67348ccc 2169 return e->caller->global.inlined_to->decl == callee->decl;
d7d1d041 2170 else
67348ccc 2171 return e->caller->decl == callee->decl;
d7d1d041 2172}
0a35513e
AH
2173
2174/* Return true if the TM_CLONE bit is set for a given FNDECL. */
2175static inline bool
2176decl_is_tm_clone (const_tree fndecl)
2177{
d52f5295 2178 cgraph_node *n = cgraph_node::get (fndecl);
0a35513e
AH
2179 if (n)
2180 return n->tm_clone;
2181 return false;
2182}
9c8305f8
JH
2183
2184/* Likewise indicate that a node is needed, i.e. reachable via some
2185 external means. */
2186
d52f5295
ML
2187inline void
2188cgraph_node::mark_force_output (void)
1f26ac87 2189{
d52f5295
ML
2190 force_output = 1;
2191 gcc_checking_assert (!global.inlined_to);
1f26ac87
JM
2192}
2193
1c4a429a 2194#endif /* GCC_CGRAPH_H */