]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cgraph.h
[D] Don't predefine GNU_StackGrowsDown on every target.
[thirdparty/gcc.git] / gcc / cgraph.h
CommitLineData
1c4a429a 1/* Callgraph handling code.
a5544970 2 Copyright (C) 2003-2019 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
3995f3a2 24#include "profile-count.h"
f0889939
AM
25#include "ipa-ref.h"
26#include "plugin-api.h"
27
efd9eb29
TV
28extern void debuginfo_early_init (void);
29extern void debuginfo_init (void);
30extern void debuginfo_fini (void);
31extern void debuginfo_start (void);
32extern void debuginfo_stop (void);
33extern void debuginfo_early_start (void);
34extern void debuginfo_early_stop (void);
35
f0889939
AM
36class ipa_opt_pass_d;
37typedef ipa_opt_pass_d *ipa_opt_pass;
1f00098b
JH
38
39/* Symbol table consists of functions and variables.
e70670cf 40 TODO: add labels and CONST_DECLs. */
1f00098b
JH
41enum symtab_type
42{
960bfb69 43 SYMTAB_SYMBOL,
1f00098b
JH
44 SYMTAB_FUNCTION,
45 SYMTAB_VARIABLE
46};
47
f961457f
JH
48/* Section names are stored as reference counted strings in GGC safe hashtable
49 (to make them survive through PCH). */
50
50686850 51struct GTY((for_user)) section_hash_entry
f961457f
JH
52{
53 int ref_count;
67914693 54 char *name; /* As long as this datastructure stays in GGC, we cannot put
f961457f
JH
55 string at the tail of structure of GGC dies in horrible
56 way */
57};
58
ca752f39 59struct section_name_hasher : ggc_ptr_hash<section_hash_entry>
2a22f99c
TS
60{
61 typedef const char *compare_type;
62
63 static hashval_t hash (section_hash_entry *);
64 static bool equal (section_hash_entry *, const char *);
65};
66
d52f5295
ML
67enum availability
68{
69 /* Not yet set by cgraph_function_body_availability. */
70 AVAIL_UNSET,
71 /* Function body/variable initializer is unknown. */
72 AVAIL_NOT_AVAILABLE,
73 /* Function body/variable initializer is known but might be replaced
74 by a different one from other compilation unit and thus needs to
75 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
76 arbitrary side effects on escaping variables and functions, while
77 like AVAILABLE it might access static variables. */
78 AVAIL_INTERPOSABLE,
79 /* Function body/variable initializer is known and will be used in final
80 program. */
81 AVAIL_AVAILABLE,
82 /* Function body/variable initializer is known and all it's uses are
83 explicitly visible within current unit (ie it's address is never taken and
84 it is not exported to other units). Currently used only for functions. */
85 AVAIL_LOCAL
86};
87
88/* Classification of symbols WRT partitioning. */
89enum symbol_partitioning_class
90{
91 /* External declarations are ignored by partitioning algorithms and they are
92 added into the boundary later via compute_ltrans_boundary. */
93 SYMBOL_EXTERNAL,
94 /* Partitioned symbols are pur into one of partitions. */
95 SYMBOL_PARTITION,
96 /* Duplicated symbols (such as comdat or constant pool references) are
97 copied into every node needing them via add_symbol_to_partition. */
98 SYMBOL_DUPLICATE
99};
100
1f00098b
JH
101/* Base of all entries in the symbol table.
102 The symtab_node is inherited by cgraph and varpol nodes. */
a3bfa8b8
DM
103class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
104 chain_next ("%h.next"), chain_prev ("%h.previous")))
5e20cdc9 105 symtab_node
1f00098b 106{
a3bfa8b8 107public:
4325656f
ML
108 friend class symbol_table;
109
fec39fa6
TS
110 /* Return name. */
111 const char *name () const;
112
464d0118
ML
113 /* Return dump name. */
114 const char *dump_name () const;
115
fec39fa6 116 /* Return asm name. */
464d0118
ML
117 const char *asm_name () const;
118
119 /* Return dump name with assembler name. */
120 const char *dump_asm_name () const;
fec39fa6 121
d52f5295
ML
122 /* Add node into symbol table. This function is not used directly, but via
123 cgraph/varpool node creation routines. */
124 void register_symbol (void);
125
126 /* Remove symbol from symbol table. */
127 void remove (void);
128
129 /* Dump symtab node to F. */
130 void dump (FILE *f);
131
132 /* Dump symtab node to stderr. */
133 void DEBUG_FUNCTION debug (void);
134
135 /* Verify consistency of node. */
136 void DEBUG_FUNCTION verify (void);
137
138 /* Return ipa reference from this symtab_node to
139 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
140 of the use and STMT the statement (if it exists). */
3dafb85c
ML
141 ipa_ref *create_reference (symtab_node *referred_node,
142 enum ipa_ref_use use_type);
d52f5295
ML
143
144 /* Return ipa reference from this symtab_node to
145 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
146 of the use and STMT the statement (if it exists). */
3dafb85c 147 ipa_ref *create_reference (symtab_node *referred_node,
355fe088 148 enum ipa_ref_use use_type, gimple *stmt);
d52f5295
ML
149
150 /* If VAL is a reference to a function or a variable, add a reference from
2d8d3ae2 151 this symtab_node to the corresponding symbol table node. Return the new
d52f5295 152 reference or NULL if none was created. */
2d8d3ae2 153 ipa_ref *maybe_create_reference (tree val, gimple *stmt);
d52f5295
ML
154
155 /* Clone all references from symtab NODE to this symtab_node. */
156 void clone_references (symtab_node *node);
157
158 /* Remove all stmt references in non-speculative references.
159 Those are not maintained during inlining & clonning.
160 The exception are speculative references that are updated along
161 with callgraph edges associated with them. */
162 void clone_referring (symtab_node *node);
163
164 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
355fe088 165 ipa_ref *clone_reference (ipa_ref *ref, gimple *stmt);
d52f5295
ML
166
167 /* Find the structure describing a reference to REFERRED_NODE
168 and associated with statement STMT. */
355fe088 169 ipa_ref *find_reference (symtab_node *referred_node, gimple *stmt,
3dafb85c 170 unsigned int lto_stmt_uid);
d52f5295
ML
171
172 /* Remove all references that are associated with statement STMT. */
355fe088 173 void remove_stmt_references (gimple *stmt);
d52f5295
ML
174
175 /* Remove all stmt references in non-speculative references.
176 Those are not maintained during inlining & clonning.
177 The exception are speculative references that are updated along
178 with callgraph edges associated with them. */
179 void clear_stmts_in_references (void);
180
181 /* Remove all references in ref list. */
182 void remove_all_references (void);
183
184 /* Remove all referring items in ref list. */
185 void remove_all_referring (void);
186
187 /* Dump references in ref list to FILE. */
188 void dump_references (FILE *file);
189
190 /* Dump referring in list to FILE. */
191 void dump_referring (FILE *);
192
b84d4347
ML
193 /* Get number of references for this node. */
194 inline unsigned num_references (void)
195 {
196 return ref_list.references ? ref_list.references->length () : 0;
197 }
198
d52f5295 199 /* Iterates I-th reference in the list, REF is also set. */
3dafb85c 200 ipa_ref *iterate_reference (unsigned i, ipa_ref *&ref);
d52f5295
ML
201
202 /* Iterates I-th referring item in the list, REF is also set. */
3dafb85c 203 ipa_ref *iterate_referring (unsigned i, ipa_ref *&ref);
d52f5295
ML
204
205 /* Iterates I-th referring alias item in the list, REF is also set. */
3dafb85c 206 ipa_ref *iterate_direct_aliases (unsigned i, ipa_ref *&ref);
d52f5295
ML
207
208 /* Return true if symtab node and TARGET represents
209 semantically equivalent symbols. */
210 bool semantically_equivalent_p (symtab_node *target);
211
212 /* Classify symbol symtab node for partitioning. */
213 enum symbol_partitioning_class get_partitioning_class (void);
214
215 /* Return comdat group. */
216 tree get_comdat_group ()
217 {
218 return x_comdat_group;
219 }
220
221 /* Return comdat group as identifier_node. */
222 tree get_comdat_group_id ()
223 {
224 if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE)
225 x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group);
226 return x_comdat_group;
227 }
228
229 /* Set comdat group. */
230 void set_comdat_group (tree group)
231 {
232 gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE
233 || DECL_P (group));
234 x_comdat_group = group;
235 }
236
237 /* Return section as string. */
238 const char * get_section ()
239 {
240 if (!x_section)
241 return NULL;
242 return x_section->name;
243 }
244
245 /* Remove node from same comdat group. */
246 void remove_from_same_comdat_group (void);
247
248 /* Add this symtab_node to the same comdat group that OLD is in. */
249 void add_to_same_comdat_group (symtab_node *old_node);
250
251 /* Dissolve the same_comdat_group list in which NODE resides. */
252 void dissolve_same_comdat_group_list (void);
253
254 /* Return true when symtab_node is known to be used from other (non-LTO)
255 object file. Known only when doing LTO via linker plugin. */
256 bool used_from_object_file_p (void);
257
258 /* Walk the alias chain to return the symbol NODE is alias of.
259 If NODE is not an alias, return NODE.
f13fe18b
JH
260 When AVAILABILITY is non-NULL, get minimal availability in the chain.
261 When REF is non-NULL, assume that reference happens in symbol REF
262 when determining the availability. */
263 symtab_node *ultimate_alias_target (enum availability *avail = NULL,
264 struct symtab_node *ref = NULL);
d52f5295
ML
265
266 /* Return next reachable static symbol with initializer after NODE. */
267 inline symtab_node *next_defined_symbol (void);
268
269 /* Add reference recording that symtab node is alias of TARGET.
71e54687 270 If TRANSPARENT is true make the alias to be transparent alias.
d52f5295
ML
271 The function can fail in the case of aliasing cycles; in this case
272 it returns false. */
71e54687 273 bool resolve_alias (symtab_node *target, bool transparent = false);
d52f5295
ML
274
275 /* C++ FE sometimes change linkage flags after producing same
276 body aliases. */
277 void fixup_same_cpp_alias_visibility (symtab_node *target);
278
6cbde2e3 279 /* Call callback on symtab node and aliases associated to this node.
d52f5295 280 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
6cbde2e3 281 skipped. */
d52f5295 282 bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *),
a6a543bf
JH
283 void *data,
284 bool include_overwrite);
d52f5295 285
67914693 286 /* If node cannot be interposable by static or dynamic linker to point to
d52f5295
ML
287 different definition, return this symbol. Otherwise look for alias with
288 such property and if none exists, introduce new one. */
289 symtab_node *noninterposable_alias (void);
290
291 /* Return node that alias is aliasing. */
292 inline symtab_node *get_alias_target (void);
293
294 /* Set section for symbol and its aliases. */
295 void set_section (const char *section);
296
297 /* Set section, do not recurse into aliases.
298 When one wants to change section of symbol and its aliases,
299 use set_section. */
300 void set_section_for_node (const char *section);
301
302 /* Set initialization priority to PRIORITY. */
303 void set_init_priority (priority_type priority);
304
305 /* Return the initialization priority. */
306 priority_type get_init_priority ();
307
f13fe18b
JH
308 /* Return availability of NODE when referenced from REF. */
309 enum availability get_availability (symtab_node *ref = NULL);
310
f714ecf5
JH
311 /* During LTO stream-in this predicate can be used to check whether node
312 in question prevails in the linking to save some memory usage. */
313 bool prevailing_p (void);
314
f13fe18b
JH
315 /* Return true if NODE binds to current definition in final executable
316 when referenced from REF. If REF is NULL return conservative value
317 for any reference. */
318 bool binds_to_current_def_p (symtab_node *ref = NULL);
d52f5295
ML
319
320 /* Make DECL local. */
321 void make_decl_local (void);
322
ed2a53e7
JH
323 /* Copy visibility from N. */
324 void copy_visibility_from (symtab_node *n);
325
428f0c67
JH
326 /* Return desired alignment of the definition. This is NOT alignment useful
327 to access THIS, because THIS may be interposable and DECL_ALIGN should
328 be used instead. It however must be guaranteed when output definition
329 of THIS. */
330 unsigned int definition_alignment ();
331
332 /* Return true if alignment can be increased. */
333 bool can_increase_alignment_p ();
334
335 /* Increase alignment of symbol to ALIGN. */
336 void increase_alignment (unsigned int align);
337
d52f5295
ML
338 /* Return true if list contains an alias. */
339 bool has_aliases_p (void);
340
341 /* Return true when the symbol is real symbol, i.e. it is not inline clone
342 or abstract function kept for debug info purposes only. */
343 bool real_symbol_p (void);
344
39aa9b23
JH
345 /* Return true when the symbol needs to be output to the LTO symbol table. */
346 bool output_to_lto_symbol_table_p (void);
347
3dafb85c
ML
348 /* Determine if symbol declaration is needed. That is, visible to something
349 either outside this translation unit, something magic in the system
350 configury. This function is used just during symbol creation. */
351 bool needed_p (void);
352
c2e84327
DM
353 /* Return true if this symbol is a function from the C frontend specified
354 directly in RTL form (with "__RTL"). */
355 bool native_rtl_p () const;
356
3dafb85c 357 /* Return true when there are references to the node. */
d7438551 358 bool referred_to_p (bool include_self = true);
3dafb85c 359
f1703a2e
JH
360 /* Return true if symbol can be discarded by linker from the binary.
361 Assume that symbol is used (so there is no need to take into account
362 garbage collecting linkers)
363
364 This can happen for comdats, commons and weaks when they are previaled
365 by other definition at static linking time. */
d52f5295
ML
366 inline bool
367 can_be_discarded_p (void)
368 {
369 return (DECL_EXTERNAL (decl)
f1703a2e
JH
370 || ((get_comdat_group ()
371 || DECL_COMMON (decl)
372 || (DECL_SECTION_NAME (decl) && DECL_WEAK (decl)))
373 && ((resolution != LDPR_PREVAILING_DEF
374 && resolution != LDPR_PREVAILING_DEF_IRONLY_EXP)
375 || flag_incremental_link)
376 && resolution != LDPR_PREVAILING_DEF_IRONLY));
d52f5295
ML
377 }
378
379 /* Return true if NODE is local to a particular COMDAT group, and must not
380 be named from outside the COMDAT. This is used for C++ decloned
381 constructors. */
382 inline bool comdat_local_p (void)
383 {
384 return (same_comdat_group && !TREE_PUBLIC (decl));
385 }
386
387 /* Return true if ONE and TWO are part of the same COMDAT group. */
388 inline bool in_same_comdat_group_p (symtab_node *target);
389
d52f5295
ML
390 /* Return true if symbol is known to be nonzero. */
391 bool nonzero_address ();
392
3cb251b7
JH
393 /* Return 0 if symbol is known to have different address than S2,
394 Return 1 if symbol is known to have same address as S2,
b2539e1e
JH
395 return 2 otherwise.
396
397 If MEMORY_ACCESSED is true, assume that both memory pointer to THIS
398 and S2 is going to be accessed. This eliminates the situations when
399 either THIS or S2 is NULL and is seful for comparing bases when deciding
400 about memory aliasing. */
401 int equal_address_to (symtab_node *s2, bool memory_accessed = false);
3cb251b7 402
0a7246ee
JH
403 /* Return true if symbol's address may possibly be compared to other
404 symbol's address. */
405 bool address_matters_p ();
406
407 /* Return true if NODE's address can be compared. This use properties
408 of NODE only and does not look if the address is actually taken in
409 interesting way. For that use ADDRESS_MATTERS_P instead. */
410 bool address_can_be_compared_p (void);
411
d52f5295
ML
412 /* Return symbol table node associated with DECL, if any,
413 and NULL otherwise. */
414 static inline symtab_node *get (const_tree decl)
415 {
d52f5295
ML
416 /* Check that we are called for sane type of object - functions
417 and static or external variables. */
418 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
419 || (TREE_CODE (decl) == VAR_DECL
420 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
421 || in_lto_p)));
422 /* Check that the mapping is sane - perhaps this check can go away,
423 but at the moment frontends tends to corrupt the mapping by calling
424 memcpy/memset on the tree nodes. */
425 gcc_checking_assert (!decl->decl_with_vis.symtab_node
426 || decl->decl_with_vis.symtab_node->decl == decl);
d52f5295
ML
427 return decl->decl_with_vis.symtab_node;
428 }
429
f7217cde
JH
430 /* Try to find a symtab node for declaration DECL and if it does not
431 exist or if it corresponds to an inline clone, create a new one. */
432 static inline symtab_node * get_create (tree node);
433
3dafb85c
ML
434 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
435 Return NULL if there's no such node. */
436 static symtab_node *get_for_asmname (const_tree asmname);
437
d52f5295
ML
438 /* Verify symbol table for internal consistency. */
439 static DEBUG_FUNCTION void verify_symtab_nodes (void);
440
b2b29377
MM
441 /* Perform internal consistency checks, if they are enabled. */
442 static inline void checking_verify_symtab_nodes (void);
443
1f00098b 444 /* Type of the symbol. */
b8dbdb12
RG
445 ENUM_BITFIELD (symtab_type) type : 8;
446
447 /* The symbols resolution. */
448 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
449
e70670cf
JH
450 /*** Flags representing the symbol type. ***/
451
452 /* True when symbol corresponds to a definition in current unit.
3dafb85c 453 set via finalize_function or finalize_decl */
e70670cf 454 unsigned definition : 1;
9041d2e6
ML
455 /* True when symbol is an alias.
456 Set by ssemble_alias. */
e70670cf 457 unsigned alias : 1;
71e54687
JH
458 /* When true the alias is translated into its target symbol either by GCC
459 or assembler (it also may just be a duplicate declaration of the same
460 linker name).
461
462 Currently transparent aliases come in three different flavors
463 - aliases having the same assembler name as their target (aka duplicated
464 declarations). In this case the assembler names compare via
465 assembler_names_equal_p and weakref is false
466 - aliases that are renamed at a time being output to final file
467 by varasm.c. For those DECL_ASSEMBLER_NAME have
468 IDENTIFIER_TRANSPARENT_ALIAS set and thus also their assembler
469 name must be unique.
470 Weakrefs belong to this cateogry when we target assembler without
471 .weakref directive.
472 - weakrefs that are renamed by assembler via .weakref directive.
473 In this case the alias may or may not be definition (depending if
474 target declaration was seen by the compiler), weakref is set.
475 Unless we are before renaming statics, assembler names are different.
476
477 Given that we now support duplicate declarations, the second option is
478 redundant and will be removed. */
479 unsigned transparent_alias : 1;
08346abd
JH
480 /* True when alias is a weakref. */
481 unsigned weakref : 1;
40a7fe1e 482 /* C++ frontend produce same body aliases and extra name aliases for
688010ba 483 virtual functions and vtables that are obviously equivalent.
40a7fe1e 484 Those aliases are bit special, especially because C++ frontend
67914693 485 visibility code is so ugly it cannot get them right at first time
40a7fe1e
JH
486 and their visibility needs to be copied from their "masters" at
487 the end of parsing. */
488 unsigned cpp_implicit_alias : 1;
e70670cf
JH
489 /* Set once the definition was analyzed. The list of references and
490 other properties are built during analysis. */
491 unsigned analyzed : 1;
6de88c6a
JH
492 /* Set for write-only variables. */
493 unsigned writeonly : 1;
f7217cde
JH
494 /* Visibility of symbol was used for further optimization; do not
495 permit further changes. */
496 unsigned refuse_visibility_changes : 1;
e70670cf
JH
497
498 /*** Visibility and linkage flags. ***/
499
b8dbdb12
RG
500 /* Set when function is visible by other units. */
501 unsigned externally_visible : 1;
7861b648
AK
502 /* Don't reorder to other symbols having this set. */
503 unsigned no_reorder : 1;
4bcfd75c 504 /* The symbol will be assumed to be used in an invisible way (like
edb983b2 505 by an toplevel asm statement). */
b8dbdb12 506 unsigned force_output : 1;
edb983b2
JH
507 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
508 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
509 to static and it does not inhibit optimization. */
510 unsigned forced_by_abi : 1;
702d8703
JH
511 /* True when the name is known to be unique and thus it does not need mangling. */
512 unsigned unique_name : 1;
e257a17c
JH
513 /* Specify whether the section was set by user or by
514 compiler via -ffunction-sections. */
515 unsigned implicit_section : 1;
3d8d0043
MJ
516 /* True when body and other characteristics have been removed by
517 symtab_remove_unreachable_nodes. */
518 unsigned body_removed : 1;
b8dbdb12 519
e70670cf
JH
520 /*** WHOPR Partitioning flags.
521 These flags are used at ltrans stage when only part of the callgraph is
522 available. ***/
b8dbdb12 523
e70670cf
JH
524 /* Set when variable is used from other LTRANS partition. */
525 unsigned used_from_other_partition : 1;
9041d2e6 526 /* Set when function is available in the other LTRANS partition.
e70670cf
JH
527 During WPA output it is used to mark nodes that are present in
528 multiple partitions. */
529 unsigned in_other_partition : 1;
b8dbdb12 530
b8dbdb12 531
e70670cf
JH
532
533 /*** other flags. ***/
534
535 /* Set when symbol has address taken. */
536 unsigned address_taken : 1;
569b1784
JH
537 /* Set when init priority is set. */
538 unsigned in_init_priority_hash : 1;
e70670cf 539
1f6be682
IV
540 /* Set when symbol needs to be streamed into LTO bytecode for LTO, or in case
541 of offloading, for separate compilation for a different target. */
542 unsigned need_lto_streaming : 1;
543
544 /* Set when symbol can be streamed into bytecode for offloading. */
545 unsigned offloadable : 1;
546
aab778d3
L
547 /* Set when symbol is an IFUNC resolver. */
548 unsigned ifunc_resolver : 1;
549
e70670cf
JH
550
551 /* Ordering of all symtab entries. */
552 int order;
553
554 /* Declaration representing the symbol. */
555 tree decl;
960bfb69 556
2aae7680 557 /* Linked list of symbol table entries starting with symtab_nodes. */
5e20cdc9
DM
558 symtab_node *next;
559 symtab_node *previous;
e70670cf 560
1ab24192 561 /* Linked list of symbols with the same asm name. There may be multiple
e70670cf
JH
562 entries for single symbol name during LTO, because symbols are renamed
563 only after partitioning.
564
565 Because inline clones are kept in the assembler name has, they also produce
566 duplicate entries.
567
568 There are also several long standing bugs where frontends and builtin
569 code produce duplicated decls. */
5e20cdc9
DM
570 symtab_node *next_sharing_asm_name;
571 symtab_node *previous_sharing_asm_name;
2aae7680 572
d52f5295
ML
573 /* Circular list of nodes in the same comdat group if non-NULL. */
574 symtab_node *same_comdat_group;
e55637b7 575
e70670cf 576 /* Vectors of referring and referenced entities. */
3dafb85c 577 ipa_ref_list ref_list;
e70670cf 578
40a7fe1e
JH
579 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
580 depending to what was known to frontend on the creation time.
581 Once alias is resolved, this pointer become NULL. */
582 tree alias_target;
583
e70670cf
JH
584 /* File stream where this node is being written to. */
585 struct lto_file_decl_data * lto_file_data;
586
960bfb69 587 PTR GTY ((skip)) aux;
aede2c10
JH
588
589 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
f961457f 590 tree x_comdat_group;
24d047a3
JH
591
592 /* Section name. Again can be private, if allowed. */
f961457f 593 section_hash_entry *x_section;
e257a17c 594
d52f5295
ML
595protected:
596 /* Dump base fields of symtab nodes to F. Not to be used directly. */
597 void dump_base (FILE *);
569b1784 598
d52f5295
ML
599 /* Verify common part of symtab node. */
600 bool DEBUG_FUNCTION verify_base (void);
89330618 601
d52f5295
ML
602 /* Remove node from symbol table. This function is not used directly, but via
603 cgraph/varpool node removal routines. */
604 void unregister (void);
605
606 /* Return the initialization and finalization priority information for
607 DECL. If there is no previous priority information, a freshly
608 allocated structure is returned. */
609 struct symbol_priority_map *priority_info (void);
610
31de7606
JH
611 /* Worker for call_for_symbol_and_aliases_1. */
612 bool call_for_symbol_and_aliases_1 (bool (*callback) (symtab_node *, void *),
613 void *data,
614 bool include_overwrite);
d52f5295
ML
615private:
616 /* Worker for set_section. */
617 static bool set_section (symtab_node *n, void *s);
618
619 /* Worker for symtab_resolve_alias. */
620 static bool set_implicit_section (symtab_node *n, void *);
621
622 /* Worker searching noninterposable alias. */
623 static bool noninterposable_alias (symtab_node *node, void *data);
31de7606
JH
624
625 /* Worker for ultimate_alias_target. */
f13fe18b
JH
626 symtab_node *ultimate_alias_target_1 (enum availability *avail = NULL,
627 symtab_node *ref = NULL);
464d0118
ML
628
629 /* Get dump name with normal or assembly name. */
630 const char *get_dump_name (bool asm_name_p) const;
1f00098b 631};
1c4a429a 632
b2b29377
MM
633inline void
634symtab_node::checking_verify_symtab_nodes (void)
635{
636 if (flag_checking)
637 symtab_node::verify_symtab_nodes ();
638}
639
e55637b7
ML
640/* Walk all aliases for NODE. */
641#define FOR_EACH_ALIAS(node, alias) \
d52f5295 642 for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++)
6b02a499 643
d7f09764
DN
644/* This is the information that is put into the cgraph local structure
645 to recover a function. */
646struct lto_file_decl_data;
647
8a4a83ed 648extern const char * const cgraph_availability_names[];
430c6ceb 649extern const char * const ld_plugin_symbol_resolution_names[];
714c800f 650extern const char * const tls_model_names[];
8a4a83ed 651
a3e61d61
PMR
652/* Sub-structure of cgraph_node. Holds information about thunk, used only for
653 same body aliases.
654
655 Thunks are basically wrappers around methods which are introduced in case
656 of multiple inheritance in order to adjust the value of the "this" pointer
657 or of the returned value.
658
659 In the case of this-adjusting thunks, each back-end can override the
660 can_output_mi_thunk/output_mi_thunk target hooks to generate a minimal thunk
661 (with a tail call for instance) directly as assembly. For the default hook
662 or for the case where the can_output_mi_thunk hooks return false, the thunk
663 is gimplified and lowered using the regular machinery. */
6744a6ab
JH
664
665struct GTY(()) cgraph_thunk_info {
a3e61d61 666 /* Offset used to adjust "this". */
6744a6ab 667 HOST_WIDE_INT fixed_offset;
a3e61d61
PMR
668
669 /* Offset in the virtual table to get the offset to adjust "this". Valid iff
670 VIRTUAL_OFFSET_P is true. */
6744a6ab 671 HOST_WIDE_INT virtual_value;
a3e61d61 672
44662f68
EB
673 /* Offset from "this" to get the offset to adjust "this". Zero means: this
674 offset is to be ignored. */
675 HOST_WIDE_INT indirect_offset;
676
a3e61d61
PMR
677 /* Thunk target, i.e. the method that this thunk wraps. Depending on the
678 TARGET_USE_LOCAL_THUNK_ALIAS_P macro, this may have to be a new alias. */
6744a6ab 679 tree alias;
a3e61d61
PMR
680
681 /* Nonzero for a "this" adjusting thunk and zero for a result adjusting
682 thunk. */
6744a6ab 683 bool this_adjusting;
a3e61d61
PMR
684
685 /* If true, this thunk is what we call a virtual thunk. In this case:
686 * for this-adjusting thunks, after the FIXED_OFFSET based adjustment is
687 done, add to the result the offset found in the vtable at:
688 vptr + VIRTUAL_VALUE
e75a0b31 689 * for result-adjusting thunks, the FIXED_OFFSET adjustment is done after
a3e61d61 690 the virtual one. */
6744a6ab 691 bool virtual_offset_p;
a3e61d61
PMR
692
693 /* ??? True for special kind of thunks, seems related to instrumentation. */
d5e254e1 694 bool add_pointer_bounds_args;
a3e61d61
PMR
695
696 /* Set to true when alias node (the cgraph_node to which this struct belong)
697 is a thunk. Access to any other fields is invalid if this is false. */
6744a6ab
JH
698 bool thunk_p;
699};
700
dafc5b82 701/* Information about the function collected locally.
25c84396 702 Available after function is analyzed. */
dafc5b82 703
d1b38208 704struct GTY(()) cgraph_local_info {
026c3cfd
AH
705 /* Set when function is visible in current compilation unit only and
706 its address is never taken. */
b4e19405 707 unsigned local : 1;
6674a6ce 708
124f1be6
MJ
709 /* False when there is something makes versioning impossible. */
710 unsigned versionable : 1;
711
67914693 712 /* False when function calling convention and signature cannot be changed.
61e03ffc
JH
713 This is the case when __builtin_apply_args is used. */
714 unsigned can_change_signature : 1;
715
95c755e9
JH
716 /* True when the function has been originally extern inline, but it is
717 redefined now. */
b4e19405 718 unsigned redefined_extern_inline : 1;
0a35513e
AH
719
720 /* True if the function may enter serial irrevocable mode. */
721 unsigned tm_may_enter_irr : 1;
dafc5b82
JH
722};
723
724/* Information about the function that needs to be computed globally
726a989a 725 once compilation is finished. Available only with -funit-at-a-time. */
dafc5b82 726
d1b38208 727struct GTY(()) cgraph_global_info {
726a989a
RB
728 /* For inline clones this points to the function they will be
729 inlined into. */
d52f5295 730 cgraph_node *inlined_to;
dafc5b82
JH
731};
732
9187e02d
JH
733/* Represent which DECL tree (or reference to such tree)
734 will be replaced by another tree while versioning. */
735struct GTY(()) ipa_replace_map
736{
737 /* The tree that will be replaced. */
738 tree old_tree;
739 /* The new (replacing) tree. */
740 tree new_tree;
922f15c2
JH
741 /* Parameter number to replace, when old_tree is NULL. */
742 int parm_num;
9187e02d
JH
743 /* True when a substitution should be done, false otherwise. */
744 bool replace_p;
745 /* True when we replace a reference to old_tree. */
746 bool ref_p;
747};
9187e02d
JH
748
749struct GTY(()) cgraph_clone_info
750{
d52f5295 751 vec<ipa_replace_map *, va_gc> *tree_map;
9187e02d 752 bitmap args_to_skip;
08ad1d6d 753 bitmap combined_args_to_skip;
9187e02d
JH
754};
755
0136f8f0
AH
756enum cgraph_simd_clone_arg_type
757{
758 SIMD_CLONE_ARG_TYPE_VECTOR,
759 SIMD_CLONE_ARG_TYPE_UNIFORM,
d9a6bd32 760 /* These are only for integer/pointer arguments passed by value. */
0136f8f0
AH
761 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
762 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
e01d41e5 763 /* These 6 are only for reference type arguments or arguments passed
d9a6bd32
JJ
764 by reference. */
765 SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP,
e01d41e5 766 SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP,
d9a6bd32 767 SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP,
e01d41e5 768 SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP,
d9a6bd32 769 SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP,
e01d41e5 770 SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP,
0136f8f0
AH
771 SIMD_CLONE_ARG_TYPE_MASK
772};
773
774/* Function arguments in the original function of a SIMD clone.
775 Supplementary data for `struct simd_clone'. */
776
777struct GTY(()) cgraph_simd_clone_arg {
778 /* Original function argument as it originally existed in
779 DECL_ARGUMENTS. */
780 tree orig_arg;
781
782 /* orig_arg's function (or for extern functions type from
783 TYPE_ARG_TYPES). */
784 tree orig_type;
785
786 /* If argument is a vector, this holds the vector version of
787 orig_arg that after adjusting the argument types will live in
788 DECL_ARGUMENTS. Otherwise, this is NULL.
789
790 This basically holds:
791 vector(simdlen) __typeof__(orig_arg) new_arg. */
792 tree vector_arg;
793
794 /* vector_arg's type (or for extern functions new vector type. */
795 tree vector_type;
796
797 /* If argument is a vector, this holds the array where the simd
798 argument is held while executing the simd clone function. This
799 is a local variable in the cloned function. Its content is
800 copied from vector_arg upon entry to the clone.
801
802 This basically holds:
803 __typeof__(orig_arg) simd_array[simdlen]. */
804 tree simd_array;
805
806 /* A SIMD clone's argument can be either linear (constant or
807 variable), uniform, or vector. */
808 enum cgraph_simd_clone_arg_type arg_type;
809
d9a6bd32 810 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_*CONSTANT_STEP this is
0136f8f0 811 the constant linear step, if arg_type is
e01d41e5 812 SIMD_CLONE_ARG_TYPE_LINEAR_*VARIABLE_STEP, this is index of
0136f8f0
AH
813 the uniform argument holding the step, otherwise 0. */
814 HOST_WIDE_INT linear_step;
815
816 /* Variable alignment if available, otherwise 0. */
817 unsigned int alignment;
818};
819
820/* Specific data for a SIMD function clone. */
821
822struct GTY(()) cgraph_simd_clone {
823 /* Number of words in the SIMD lane associated with this clone. */
824 unsigned int simdlen;
825
826 /* Number of annotated function arguments in `args'. This is
827 usually the number of named arguments in FNDECL. */
828 unsigned int nargs;
829
830 /* Max hardware vector size in bits for integral vectors. */
831 unsigned int vecsize_int;
832
833 /* Max hardware vector size in bits for floating point vectors. */
834 unsigned int vecsize_float;
835
5f490f9f
JJ
836 /* Machine mode of the mask argument(s), if they are to be passed
837 as bitmasks in integer argument(s). VOIDmode if masks are passed
838 as vectors of characteristic type. */
839 machine_mode mask_mode;
840
026c3cfd 841 /* The mangling character for a given vector size. This is used
0136f8f0
AH
842 to determine the ISA mangling bit as specified in the Intel
843 Vector ABI. */
844 unsigned char vecsize_mangle;
845
846 /* True if this is the masked, in-branch version of the clone,
847 otherwise false. */
848 unsigned int inbranch : 1;
849
0136f8f0 850 /* Doubly linked list of SIMD clones. */
d52f5295 851 cgraph_node *prev_clone, *next_clone;
0136f8f0
AH
852
853 /* Original cgraph node the SIMD clones were created for. */
d52f5295 854 cgraph_node *origin;
0136f8f0
AH
855
856 /* Annotated function arguments for the original function. */
3dafb85c 857 cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
0136f8f0
AH
858};
859
d52f5295 860/* Function Multiversioning info. */
2a22f99c 861struct GTY((for_user)) cgraph_function_version_info {
d52f5295
ML
862 /* The cgraph_node for which the function version info is stored. */
863 cgraph_node *this_node;
864 /* Chains all the semantically identical function versions. The
865 first function in this chain is the version_info node of the
866 default function. */
3dafb85c 867 cgraph_function_version_info *prev;
d52f5295
ML
868 /* If this version node corresponds to a dispatcher for function
869 versions, this points to the version info node of the default
870 function, the first node in the chain. */
3dafb85c 871 cgraph_function_version_info *next;
d52f5295
ML
872 /* If this node corresponds to a function version, this points
873 to the dispatcher function decl, which is the function that must
874 be called to execute the right function version at run-time.
875
876 If this cgraph node is a dispatcher (if dispatcher_function is
877 true, in the cgraph_node struct) for function versions, this
878 points to resolver function, which holds the function body of the
879 dispatcher. The dispatcher decl is an alias to the resolver
880 function decl. */
881 tree dispatcher_resolver;
882};
883
884#define DEFCIFCODE(code, type, string) CIF_ ## code,
885/* Reasons for inlining failures. */
886
887enum cgraph_inline_failed_t {
888#include "cif-code.def"
889 CIF_N_REASONS
890};
891
892enum cgraph_inline_failed_type_t
893{
894 CIF_FINAL_NORMAL = 0,
895 CIF_FINAL_ERROR
896};
897
898struct cgraph_edge;
5fefcf92 899
ca752f39 900struct cgraph_edge_hasher : ggc_ptr_hash<cgraph_edge>
2a22f99c 901{
355fe088 902 typedef gimple *compare_type;
2a22f99c
TS
903
904 static hashval_t hash (cgraph_edge *);
355fe088
TS
905 static hashval_t hash (gimple *);
906 static bool equal (cgraph_edge *, gimple *);
2a22f99c
TS
907};
908
ba228239 909/* The cgraph data structure.
e0bb17a8 910 Each function decl has assigned cgraph_node listing callees and callers. */
1c4a429a 911
5e20cdc9 912struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
a3bfa8b8 913public:
4325656f
ML
914 friend class symbol_table;
915
d52f5295
ML
916 /* Remove the node from cgraph and all inline clones inlined into it.
917 Skip however removal of FORBIDDEN_NODE and return true if it needs to be
918 removed. This allows to call the function from outer loop walking clone
919 tree. */
920 bool remove_symbol_and_inline_clones (cgraph_node *forbidden_node = NULL);
921
922 /* Record all references from cgraph_node that are taken
923 in statement STMT. */
355fe088 924 void record_stmt_references (gimple *stmt);
d52f5295
ML
925
926 /* Like cgraph_set_call_stmt but walk the clone tree and update all
927 clones sharing the same function body.
928 When WHOLE_SPECULATIVE_EDGES is true, all three components of
929 speculative edge gets updated. Otherwise we update only direct
930 call. */
355fe088 931 void set_call_stmt_including_clones (gimple *old_stmt, gcall *new_stmt,
d52f5295
ML
932 bool update_speculative = true);
933
934 /* Walk the alias chain to return the function cgraph_node is alias of.
935 Walk through thunk, too.
f13fe18b
JH
936 When AVAILABILITY is non-NULL, get minimal availability in the chain.
937 When REF is non-NULL, assume that reference happens in symbol REF
938 when determining the availability. */
939 cgraph_node *function_symbol (enum availability *avail = NULL,
940 struct symtab_node *ref = NULL);
d52f5295 941
6cbde2e3
BE
942 /* Walk the alias chain to return the function cgraph_node is alias of.
943 Walk through non virtual thunks, too. Thus we return either a function
944 or a virtual thunk node.
f13fe18b
JH
945 When AVAILABILITY is non-NULL, get minimal availability in the chain.
946 When REF is non-NULL, assume that reference happens in symbol REF
947 when determining the availability. */
6cbde2e3 948 cgraph_node *function_or_virtual_thunk_symbol
f13fe18b
JH
949 (enum availability *avail = NULL,
950 struct symtab_node *ref = NULL);
6cbde2e3 951
d52f5295
ML
952 /* Create node representing clone of N executed COUNT times. Decrease
953 the execution counts from original node too.
954 The new clone will have decl set to DECL that may or may not be the same
955 as decl of N.
956
957 When UPDATE_ORIGINAL is true, the counts are subtracted from the original
958 function's profile to reflect the fact that part of execution is handled
959 by node.
960 When CALL_DUPLICATOIN_HOOK is true, the ipa passes are acknowledged about
961 the new clone. Otherwise the caller is responsible for doing so later.
962
963 If the new node is being inlined into another one, NEW_INLINED_TO should be
964 the outline function the new one is (even indirectly) inlined to.
965 All hooks will see this in node's global.inlined_to, when invoked.
0bdad123
ML
966 Can be NULL if the node is not inlined. SUFFIX is string that is appended
967 to the original name. */
1bad9c18 968 cgraph_node *create_clone (tree decl, profile_count count,
d52f5295
ML
969 bool update_original,
970 vec<cgraph_edge *> redirect_callers,
971 bool call_duplication_hook,
3dafb85c 972 cgraph_node *new_inlined_to,
0bdad123 973 bitmap args_to_skip, const char *suffix = NULL);
d52f5295 974
53aedcce
MP
975 /* Create callgraph node clone with new declaration. The actual body will be
976 copied later at compilation stage. The name of the new clone will be
977 constructed from the name of the original node, SUFFIX and NUM_SUFFIX. */
d52f5295
ML
978 cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers,
979 vec<ipa_replace_map *, va_gc> *tree_map,
53aedcce
MP
980 bitmap args_to_skip, const char * suffix,
981 unsigned num_suffix);
d52f5295
ML
982
983 /* cgraph node being removed from symbol table; see if its entry can be
984 replaced by other inline clone. */
985 cgraph_node *find_replacement (void);
986
987 /* Create a new cgraph node which is the new version of
988 callgraph node. REDIRECT_CALLERS holds the callers
989 edges which should be redirected to point to
990 NEW_VERSION. ALL the callees edges of the node
991 are cloned to the new version node. Return the new
992 version node.
993
994 If non-NULL BLOCK_TO_COPY determine what basic blocks
995 was copied to prevent duplications of calls that are dead
0bdad123
ML
996 in the clone.
997
998 SUFFIX is string that is appended to the original name. */
d52f5295
ML
999
1000 cgraph_node *create_version_clone (tree new_decl,
1001 vec<cgraph_edge *> redirect_callers,
0bdad123
ML
1002 bitmap bbs_to_copy,
1003 const char *suffix = NULL);
d52f5295
ML
1004
1005 /* Perform function versioning.
1006 Function versioning includes copying of the tree and
1007 a callgraph update (creating a new cgraph node and updating
1008 its callees and callers).
1009
1010 REDIRECT_CALLERS varray includes the edges to be redirected
1011 to the new version.
1012
1013 TREE_MAP is a mapping of tree nodes we want to replace with
1014 new ones (according to results of prior analysis).
1015
1016 If non-NULL ARGS_TO_SKIP determine function parameters to remove
1017 from new version.
1018 If SKIP_RETURN is true, the new version will return void.
1019 If non-NULL BLOCK_TO_COPY determine what basic blocks to copy.
1020 If non_NULL NEW_ENTRY determine new entry BB of the clone.
1021
5928bc2e
ML
1022 If TARGET_ATTRIBUTES is non-null, when creating a new declaration,
1023 add the attributes to DECL_ATTRIBUTES. And call valid_attribute_p
1024 that will promote value of the attribute DECL_FUNCTION_SPECIFIC_TARGET
1025 of the declaration.
1026
d52f5295
ML
1027 Return the new version's cgraph node. */
1028 cgraph_node *create_version_clone_with_body
1029 (vec<cgraph_edge *> redirect_callers,
1030 vec<ipa_replace_map *, va_gc> *tree_map, bitmap args_to_skip,
1031 bool skip_return, bitmap bbs_to_copy, basic_block new_entry_block,
5928bc2e 1032 const char *clone_name, tree target_attributes = NULL_TREE);
d52f5295
ML
1033
1034 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
1035 corresponding to cgraph_node. */
3dafb85c 1036 cgraph_function_version_info *insert_new_function_version (void);
d52f5295
ML
1037
1038 /* Get the cgraph_function_version_info node corresponding to node. */
3dafb85c 1039 cgraph_function_version_info *function_version (void);
d52f5295
ML
1040
1041 /* Discover all functions and variables that are trivially needed, analyze
1042 them as well as all functions and variables referred by them */
1043 void analyze (void);
1044
1045 /* Add thunk alias into callgraph. The alias declaration is ALIAS and it
1046 aliases DECL with an adjustments made into the first parameter.
a3e61d61 1047 See comments in struct cgraph_thunk_info for detail on the parameters. */
d52f5295
ML
1048 cgraph_node * create_thunk (tree alias, tree, bool this_adjusting,
1049 HOST_WIDE_INT fixed_offset,
1050 HOST_WIDE_INT virtual_value,
44662f68 1051 HOST_WIDE_INT indirect_offset,
d52f5295
ML
1052 tree virtual_offset,
1053 tree real_alias);
1054
1055
1056 /* Return node that alias is aliasing. */
1057 inline cgraph_node *get_alias_target (void);
1058
1059 /* Given function symbol, walk the alias chain to return the function node
1060 is alias of. Do not walk through thunks.
f13fe18b
JH
1061 When AVAILABILITY is non-NULL, get minimal availability in the chain.
1062 When REF is non-NULL, assume that reference happens in symbol REF
1063 when determining the availability. */
d52f5295 1064
f13fe18b
JH
1065 cgraph_node *ultimate_alias_target (availability *availability = NULL,
1066 symtab_node *ref = NULL);
d52f5295
ML
1067
1068 /* Expand thunk NODE to gimple if possible.
1069 When FORCE_GIMPLE_THUNK is true, gimple thunk is created and
1070 no assembler is produced.
1071 When OUTPUT_ASM_THUNK is true, also produce assembler for
1072 thunks that are not lowered. */
1073 bool expand_thunk (bool output_asm_thunks, bool force_gimple_thunk);
1074
6a4bad95
MJ
1075 /* Call expand_thunk on all callers that are thunks and analyze those
1076 nodes that were expanded. */
1077 void expand_all_artificial_thunks ();
1078
3dafb85c
ML
1079 /* Assemble thunks and aliases associated to node. */
1080 void assemble_thunks_and_aliases (void);
1081
1082 /* Expand function specified by node. */
1083 void expand (void);
1084
d52f5295
ML
1085 /* As an GCC extension we allow redefinition of the function. The
1086 semantics when both copies of bodies differ is not well defined.
1087 We replace the old body with new body so in unit at a time mode
1088 we always use new body, while in normal mode we may end up with
1089 old body inlined into some functions and new body expanded and
1090 inlined in others. */
1091 void reset (void);
1092
1093 /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this
1094 kind of wrapper method. */
1095 void create_wrapper (cgraph_node *target);
1096
1097 /* Verify cgraph nodes of the cgraph node. */
1098 void DEBUG_FUNCTION verify_node (void);
1099
1100 /* Remove function from symbol table. */
1101 void remove (void);
1102
1103 /* Dump call graph node to file F. */
1104 void dump (FILE *f);
1105
1106 /* Dump call graph node to stderr. */
1107 void DEBUG_FUNCTION debug (void);
1108
1109 /* When doing LTO, read cgraph_node's body from disk if it is not already
1110 present. */
70486010
JH
1111 bool get_untransformed_body (void);
1112
1113 /* Prepare function body. When doing LTO, read cgraph_node's body from disk
1114 if it is not already present. When some IPA transformations are scheduled,
1115 apply them. */
d52f5295
ML
1116 bool get_body (void);
1117
1118 /* Release memory used to represent body of function.
1119 Use this only for functions that are released before being translated to
1120 target code (i.e. RTL). Functions that are compiled to RTL and beyond
1121 are free'd in final.c via free_after_compilation(). */
bf898b30 1122 void release_body (bool keep_arguments = false);
d52f5295 1123
8ccda8bc
EB
1124 /* Return the DECL_STRUCT_FUNCTION of the function. */
1125 struct function *get_fun (void);
1126
d52f5295
ML
1127 /* cgraph_node is no longer nested function; update cgraph accordingly. */
1128 void unnest (void);
1129
1130 /* Bring cgraph node local. */
1131 void make_local (void);
1132
1133 /* Likewise indicate that a node is having address taken. */
1134 void mark_address_taken (void);
1135
1136 /* Set fialization priority to PRIORITY. */
1137 void set_fini_priority (priority_type priority);
1138
1139 /* Return the finalization priority. */
1140 priority_type get_fini_priority (void);
1141
1142 /* Create edge from a given function to CALLEE in the cgraph. */
3dafb85c 1143 cgraph_edge *create_edge (cgraph_node *callee,
1bad9c18 1144 gcall *call_stmt, profile_count count);
3dafb85c 1145
d52f5295
ML
1146 /* Create an indirect edge with a yet-undetermined callee where the call
1147 statement destination is a formal parameter of the caller with index
1148 PARAM_INDEX. */
538dd0b7 1149 cgraph_edge *create_indirect_edge (gcall *call_stmt, int ecf_flags,
1bad9c18 1150 profile_count count,
3dafb85c 1151 bool compute_indirect_info = true);
d52f5295
ML
1152
1153 /* Like cgraph_create_edge walk the clone tree and update all clones sharing
1154 same function body. If clones already have edge for OLD_STMT; only
1155 update the edge same way as cgraph_set_call_stmt_including_clones does. */
3dafb85c 1156 void create_edge_including_clones (cgraph_node *callee,
355fe088 1157 gimple *old_stmt, gcall *stmt,
3995f3a2 1158 profile_count count,
d52f5295
ML
1159 cgraph_inline_failed_t reason);
1160
1161 /* Return the callgraph edge representing the GIMPLE_CALL statement
1162 CALL_STMT. */
355fe088 1163 cgraph_edge *get_edge (gimple *call_stmt);
d52f5295
ML
1164
1165 /* Collect all callers of cgraph_node and its aliases that are known to lead
4a414de8 1166 to NODE (i.e. are not overwritable) and that are not thunks. */
d52f5295
ML
1167 vec<cgraph_edge *> collect_callers (void);
1168
1169 /* Remove all callers from the node. */
1170 void remove_callers (void);
1171
1172 /* Remove all callees from the node. */
1173 void remove_callees (void);
1174
1175 /* Return function availability. See cgraph.h for description of individual
1176 return values. */
f13fe18b 1177 enum availability get_availability (symtab_node *ref = NULL);
d52f5295
ML
1178
1179 /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node
1180 if any to NOTHROW. */
a2b056a3 1181 bool set_nothrow_flag (bool nothrow);
d52f5295 1182
0fab169b
PK
1183 /* SET DECL_IS_MALLOC on cgraph_node's decl and on aliases of the node
1184 if any. */
1185 bool set_malloc_flag (bool malloc_p);
1186
69a4e898
JH
1187 /* If SET_CONST is true, mark function, aliases and thunks to be ECF_CONST.
1188 If SET_CONST if false, clear the flag.
1189
1190 When setting the flag be careful about possible interposition and
1191 do not set the flag for functions that can be interposet and set pure
1192 flag for functions that can bind to other definition.
1193
1194 Return true if any change was done. */
1195
1196 bool set_const_flag (bool set_const, bool looping);
d52f5295
ML
1197
1198 /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
69a4e898
JH
1199 if any to PURE.
1200
1201 When setting the flag, be careful about possible interposition.
1202 Return true if any change was done. */
1203
1204 bool set_pure_flag (bool pure, bool looping);
d52f5295 1205
6cbde2e3 1206 /* Call callback on function and aliases associated to the function.
d52f5295
ML
1207 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1208 skipped. */
1209
1210 bool call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
1211 void *),
1212 void *data, bool include_overwritable);
1213
6cbde2e3 1214 /* Call callback on cgraph_node, thunks and aliases associated to NODE.
d52f5295 1215 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
6cbde2e3 1216 skipped. When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
d52f5295
ML
1217 skipped. */
1218 bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node,
6cbde2e3
BE
1219 void *data),
1220 void *data,
1221 bool include_overwritable,
1222 bool exclude_virtual_thunks = false);
d52f5295 1223
d52f5295
ML
1224 /* Likewise indicate that a node is needed, i.e. reachable via some
1225 external means. */
1226 inline void mark_force_output (void);
1227
1228 /* Return true when function can be marked local. */
1229 bool local_p (void);
1230
1231 /* Return true if cgraph_node can be made local for API change.
1232 Extern inline functions and C++ COMDAT functions can be made local
1233 at the expense of possible code size growth if function is used in multiple
1234 compilation units. */
1235 bool can_be_local_p (void);
1236
67914693 1237 /* Return true when cgraph_node cannot return or throw and thus
d52f5295
ML
1238 it is safe to ignore its side effects for IPA analysis. */
1239 bool cannot_return_p (void);
1240
1241 /* Return true when function cgraph_node and all its aliases are only called
1242 directly.
1243 i.e. it is not externally visible, address was not taken and
1244 it is not used in any other non-standard way. */
1245 bool only_called_directly_p (void);
1246
1247 /* Return true when function is only called directly or it has alias.
1248 i.e. it is not externally visible, address was not taken and
1249 it is not used in any other non-standard way. */
1250 inline bool only_called_directly_or_aliased_p (void);
1251
1252 /* Return true when function cgraph_node can be expected to be removed
1253 from program when direct calls in this compilation unit are removed.
1254
1255 As a special case COMDAT functions are
1256 cgraph_can_remove_if_no_direct_calls_p while the are not
1257 cgraph_only_called_directly_p (it is possible they are called from other
1258 unit)
1259
1260 This function behaves as cgraph_only_called_directly_p because eliminating
1261 all uses of COMDAT function does not make it necessarily disappear from
1262 the program unless we are compiling whole program or we do LTO. In this
1263 case we know we win since dynamic linking will not really discard the
e0d514da
JH
1264 linkonce section.
1265
1266 If WILL_INLINE is true, assume that function will be inlined into all the
1267 direct calls. */
1268 bool will_be_removed_from_program_if_no_direct_calls_p
1269 (bool will_inline = false);
d52f5295
ML
1270
1271 /* Return true when function can be removed from callgraph
e0d514da
JH
1272 if all direct calls and references are eliminated. The function does
1273 not take into account comdat groups. */
d52f5295
ML
1274 bool can_remove_if_no_direct_calls_and_refs_p (void);
1275
1276 /* Return true when function cgraph_node and its aliases can be removed from
e0d514da
JH
1277 callgraph if all direct calls are eliminated.
1278 If WILL_INLINE is true, assume that function will be inlined into all the
1279 direct calls. */
1280 bool can_remove_if_no_direct_calls_p (bool will_inline = false);
d52f5295
ML
1281
1282 /* Return true when callgraph node is a function with Gimple body defined
1283 in current unit. Functions can also be define externally or they
1284 can be thunks with no Gimple representation.
1285
1286 Note that at WPA stage, the function body may not be present in memory. */
1287 inline bool has_gimple_body_p (void);
1288
1289 /* Return true if function should be optimized for size. */
1290 bool optimize_for_size_p (void);
1291
1292 /* Dump the callgraph to file F. */
1293 static void dump_cgraph (FILE *f);
1294
1295 /* Dump the call graph to stderr. */
3dafb85c
ML
1296 static inline
1297 void debug_cgraph (void)
d52f5295
ML
1298 {
1299 dump_cgraph (stderr);
1300 }
1301
4325656f
ML
1302 /* Get unique identifier of the node. */
1303 inline int get_uid ()
1304 {
1305 return m_uid;
1306 }
1307
d52f5295
ML
1308 /* Record that DECL1 and DECL2 are semantically identical function
1309 versions. */
1310 static void record_function_versions (tree decl1, tree decl2);
1311
1312 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
1313 DECL is a duplicate declaration. */
9acb4592 1314 static void delete_function_version_by_decl (tree decl);
d52f5295
ML
1315
1316 /* Add the function FNDECL to the call graph.
3dafb85c 1317 Unlike finalize_function, this function is intended to be used
d52f5295
ML
1318 by middle end and allows insertion of new function at arbitrary point
1319 of compilation. The function can be either in high, low or SSA form
1320 GIMPLE.
1321
1322 The function is assumed to be reachable and have address taken (so no
1323 API breaking optimizations are performed on it).
1324
1325 Main work done by this function is to enqueue the function for later
1326 processing to avoid need the passes to be re-entrant. */
1327 static void add_new_function (tree fndecl, bool lowered);
1328
1329 /* Return callgraph node for given symbol and check it is a function. */
1330 static inline cgraph_node *get (const_tree decl)
1331 {
1332 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1333 return dyn_cast <cgraph_node *> (symtab_node::get (decl));
1334 }
1335
3dafb85c
ML
1336 /* DECL has been parsed. Take it, queue it, compile it at the whim of the
1337 logic in effect. If NO_COLLECT is true, then our caller cannot stand to
1338 have the garbage collector run at the moment. We would need to either
1339 create a new GC context, or just not compile right now. */
1340 static void finalize_function (tree, bool);
1341
d52f5295
ML
1342 /* Return cgraph node assigned to DECL. Create new one when needed. */
1343 static cgraph_node * create (tree decl);
1344
d52f5295
ML
1345 /* Try to find a call graph node for declaration DECL and if it does not
1346 exist or if it corresponds to an inline clone, create a new one. */
1347 static cgraph_node * get_create (tree);
1348
3dafb85c
ML
1349 /* Return local info for the compiled function. */
1350 static cgraph_local_info *local_info (tree decl);
1351
3dafb85c 1352 /* Return local info for the compiled function. */
88f554b4 1353 static struct cgraph_rtl_info *rtl_info (tree);
3dafb85c 1354
d52f5295
ML
1355 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
1356 Return NULL if there's no such node. */
1357 static cgraph_node *get_for_asmname (tree asmname);
1358
1359 /* Attempt to mark ALIAS as an alias to DECL. Return alias node if
1360 successful and NULL otherwise.
1361 Same body aliases are output whenever the body of DECL is output,
1362 and cgraph_node::get (ALIAS) transparently
1363 returns cgraph_node::get (DECL). */
1364 static cgraph_node * create_same_body_alias (tree alias, tree decl);
1365
d52f5295
ML
1366 /* Verify whole cgraph structure. */
1367 static void DEBUG_FUNCTION verify_cgraph_nodes (void);
1368
b2b29377
MM
1369 /* Verify cgraph, if consistency checking is enabled. */
1370 static inline void checking_verify_cgraph_nodes (void);
1371
d52f5295
ML
1372 /* Worker to bring NODE local. */
1373 static bool make_local (cgraph_node *node, void *);
1374
1375 /* Mark ALIAS as an alias to DECL. DECL_NODE is cgraph node representing
1376 the function body is associated
1377 with (not necessarily cgraph_node (DECL). */
1378 static cgraph_node *create_alias (tree alias, tree target);
1379
17d1bf76
ML
1380 /* Return true if NODE has thunk. */
1381 static bool has_thunk_p (cgraph_node *node, void *);
1382
3dafb85c
ML
1383 cgraph_edge *callees;
1384 cgraph_edge *callers;
e33c6cd6
MJ
1385 /* List of edges representing indirect calls with a yet undetermined
1386 callee. */
3dafb85c 1387 cgraph_edge *indirect_calls;
1c4a429a 1388 /* For nested functions points to function the node is nested in. */
d52f5295 1389 cgraph_node *origin;
1c4a429a 1390 /* Points to first nested function, if any. */
d52f5295 1391 cgraph_node *nested;
1c4a429a 1392 /* Pointer to the next function with same origin, if any. */
d52f5295 1393 cgraph_node *next_nested;
18c6ada9 1394 /* Pointer to the next clone. */
d52f5295
ML
1395 cgraph_node *next_sibling_clone;
1396 cgraph_node *prev_sibling_clone;
1397 cgraph_node *clones;
1398 cgraph_node *clone_of;
70d539ce
JH
1399 /* For functions with many calls sites it holds map from call expression
1400 to the edge to speed up cgraph_edge function. */
2a22f99c 1401 hash_table<cgraph_edge_hasher> *GTY(()) call_site_hash;
97ba0040
JH
1402 /* Declaration node used to be clone of. */
1403 tree former_clone_of;
c22cacf3 1404
0136f8f0
AH
1405 /* If this is a SIMD clone, this points to the SIMD specific
1406 information for it. */
3dafb85c 1407 cgraph_simd_clone *simdclone;
0136f8f0 1408 /* If this function has SIMD clones, this points to the first clone. */
d52f5295 1409 cgraph_node *simd_clones;
0136f8f0 1410
0e3776db
JH
1411 /* Interprocedural passes scheduled to have their transform functions
1412 applied next time we execute local pass on them. We maintain it
1413 per-function in order to allow IPA passes to introduce new functions. */
9771b263 1414 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
0e3776db 1415
3dafb85c
ML
1416 cgraph_local_info local;
1417 cgraph_global_info global;
88f554b4 1418 struct cgraph_rtl_info *rtl;
3dafb85c
ML
1419 cgraph_clone_info clone;
1420 cgraph_thunk_info thunk;
c22cacf3 1421
e42922b1 1422 /* Expected number of executions: calculated in profile.c. */
3995f3a2 1423 profile_count count;
db0bf14f
JH
1424 /* How to scale counts at materialization time; used to merge
1425 LTO units with different number of profile runs. */
1426 int count_materialization_scale;
2fa3d31b
JH
1427 /* ID assigned by the profiling. */
1428 unsigned int profile_id;
86ce5d2f
ML
1429 /* Time profiler: first run of function. */
1430 int tp_first_run;
3691626c 1431
6b20f353
DS
1432 /* Set when decl is an abstract function pointed to by the
1433 ABSTRACT_DECL_ORIGIN of a reachable function. */
c0c123ef 1434 unsigned used_as_abstract_origin : 1;
50674e96 1435 /* Set once the function is lowered (i.e. its CFG is built). */
b4e19405 1436 unsigned lowered : 1;
25c84396
RH
1437 /* Set once the function has been instantiated and its callee
1438 lists created. */
257eb6e3 1439 unsigned process : 1;
5fefcf92
JH
1440 /* How commonly executed the node is. Initialized during branch
1441 probabilities pass. */
1442 ENUM_BITFIELD (node_frequency) frequency : 2;
844db5d0
JH
1443 /* True when function can only be called at startup (from static ctor). */
1444 unsigned only_called_at_startup : 1;
1445 /* True when function can only be called at startup (from static dtor). */
1446 unsigned only_called_at_exit : 1;
0a35513e
AH
1447 /* True when function is the transactional clone of a function which
1448 is called only from inside transactions. */
1449 /* ?? We should be able to remove this. We have enough bits in
1450 cgraph to calculate it. */
1451 unsigned tm_clone : 1;
3649b9b7
ST
1452 /* True if this decl is a dispatcher for function versions. */
1453 unsigned dispatcher_function : 1;
1f26ac87 1454 /* True if this decl calls a COMDAT-local function. This is set up in
0bceb671 1455 compute_fn_summary and inline_call. */
1f26ac87 1456 unsigned calls_comdat_local : 1;
b84d4347
ML
1457 /* True if node has been created by merge operation in IPA-ICF. */
1458 unsigned icf_merged: 1;
8413ca87
JJ
1459 /* True if call to node can't result in a call to free, munmap or
1460 other operation that could make previously non-trapping memory
1461 accesses trapping. */
1462 unsigned nonfreeing_fn : 1;
ebc8f0bb 1463 /* True if there was multiple COMDAT bodies merged by lto-symtab. */
88636b62 1464 unsigned merged_comdat : 1;
a79b7ec5
TV
1465 /* True if function was created to be executed in parallel. */
1466 unsigned parallelized_function : 1;
41f669d8
JH
1467 /* True if function is part split out by ipa-split. */
1468 unsigned split_part : 1;
4f4ada6a
JH
1469 /* True if the function appears as possible target of indirect call. */
1470 unsigned indirect_call_target : 1;
31de7606
JH
1471
1472private:
4325656f
ML
1473 /* Unique id of the node. */
1474 int m_uid;
1475
31de7606
JH
1476 /* Worker for call_for_symbol_and_aliases. */
1477 bool call_for_symbol_and_aliases_1 (bool (*callback) (cgraph_node *,
1478 void *),
1479 void *data, bool include_overwritable);
3649b9b7
ST
1480};
1481
fed5ae11
DK
1482/* A cgraph node set is a collection of cgraph nodes. A cgraph node
1483 can appear in multiple sets. */
1cb1a99f 1484struct cgraph_node_set_def
fed5ae11 1485{
b787e7a2 1486 hash_map<cgraph_node *, size_t> *map;
d52f5295 1487 vec<cgraph_node *> nodes;
fed5ae11
DK
1488};
1489
d52f5295
ML
1490typedef cgraph_node_set_def *cgraph_node_set;
1491typedef struct varpool_node_set_def *varpool_node_set;
2942c502 1492
d52f5295 1493class varpool_node;
2942c502
JH
1494
1495/* A varpool node set is a collection of varpool nodes. A varpool node
1496 can appear in multiple sets. */
1cb1a99f 1497struct varpool_node_set_def
2942c502 1498{
b787e7a2 1499 hash_map<varpool_node *, size_t> * map;
d52f5295 1500 vec<varpool_node *> nodes;
2942c502
JH
1501};
1502
fed5ae11 1503/* Iterator structure for cgraph node sets. */
84562394 1504struct cgraph_node_set_iterator
fed5ae11
DK
1505{
1506 cgraph_node_set set;
1507 unsigned index;
84562394 1508};
fed5ae11 1509
2942c502 1510/* Iterator structure for varpool node sets. */
84562394 1511struct varpool_node_set_iterator
2942c502
JH
1512{
1513 varpool_node_set set;
1514 unsigned index;
84562394 1515};
2942c502 1516
ba392339
JH
1517/* Context of polymorphic call. It represent information about the type of
1518 instance that may reach the call. This is used by ipa-devirt walkers of the
1519 type inheritance graph. */
1520
1521class GTY(()) ipa_polymorphic_call_context {
1522public:
1523 /* The called object appears in an object of type OUTER_TYPE
1524 at offset OFFSET. When information is not 100% reliable, we
1525 use SPECULATIVE_OUTER_TYPE and SPECULATIVE_OFFSET. */
1526 HOST_WIDE_INT offset;
1527 HOST_WIDE_INT speculative_offset;
1528 tree outer_type;
1529 tree speculative_outer_type;
1530 /* True if outer object may be in construction or destruction. */
4081ada2 1531 unsigned maybe_in_construction : 1;
ba392339 1532 /* True if outer object may be of derived type. */
4081ada2 1533 unsigned maybe_derived_type : 1;
ba392339
JH
1534 /* True if speculative outer object may be of derived type. We always
1535 speculate that construction does not happen. */
4081ada2 1536 unsigned speculative_maybe_derived_type : 1;
ba392339
JH
1537 /* True if the context is invalid and all calls should be redirected
1538 to BUILTIN_UNREACHABLE. */
4081ada2
JH
1539 unsigned invalid : 1;
1540 /* True if the outer type is dynamic. */
1541 unsigned dynamic : 1;
ba392339
JH
1542
1543 /* Build empty "I know nothing" context. */
1544 ipa_polymorphic_call_context ();
1545 /* Build polymorphic call context for indirect call E. */
1546 ipa_polymorphic_call_context (cgraph_edge *e);
1547 /* Build polymorphic call context for IP invariant CST.
1548 If specified, OTR_TYPE specify the type of polymorphic call
1549 that takes CST+OFFSET as a prameter. */
1550 ipa_polymorphic_call_context (tree cst, tree otr_type = NULL,
1551 HOST_WIDE_INT offset = 0);
1552 /* Build context for pointer REF contained in FNDECL at statement STMT.
1553 if INSTANCE is non-NULL, return pointer to the object described by
1554 the context. */
355fe088 1555 ipa_polymorphic_call_context (tree fndecl, tree ref, gimple *stmt,
ba392339
JH
1556 tree *instance = NULL);
1557
1558 /* Look for vtable stores or constructor calls to work out dynamic type
1559 of memory location. */
355fe088 1560 bool get_dynamic_type (tree, tree, tree, gimple *);
ba392339
JH
1561
1562 /* Make context non-speculative. */
1563 void clear_speculation ();
1564
6ff65dd7
MJ
1565 /* Produce context specifying all derrived types of OTR_TYPE. If OTR_TYPE is
1566 NULL, the context is set to dummy "I know nothing" setting. */
1567 void clear_outer_type (tree otr_type = NULL);
1568
ba392339 1569 /* Walk container types and modify context to point to actual class
67a1b94c
JH
1570 containing OTR_TYPE (if non-NULL) as base class.
1571 Return true if resulting context is valid.
1572
1573 When CONSIDER_PLACEMENT_NEW is false, reject contexts that may be made
5764ee3c 1574 valid only via allocation of new polymorphic type inside by means
67a1b94c
JH
1575 of placement new.
1576
1577 When CONSIDER_BASES is false, only look for actual fields, not base types
1578 of TYPE. */
1579 bool restrict_to_inner_class (tree otr_type,
1580 bool consider_placement_new = true,
1581 bool consider_bases = true);
1582
1583 /* Adjust all offsets in contexts by given number of bits. */
1584 void offset_by (HOST_WIDE_INT);
67914693 1585 /* Use when we cannot track dynamic type change. This speculatively assume
4081ada2 1586 type change is not happening. */
f9bb202b 1587 void possible_dynamic_type_change (bool, tree otr_type = NULL);
67a1b94c
JH
1588 /* Assume that both THIS and a given context is valid and strenghten THIS
1589 if possible. Return true if any strenghtening was made.
1590 If actual type the context is being used in is known, OTR_TYPE should be
1591 set accordingly. This improves quality of combined result. */
1592 bool combine_with (ipa_polymorphic_call_context, tree otr_type = NULL);
df0d8136 1593 bool meet_with (ipa_polymorphic_call_context, tree otr_type = NULL);
67a1b94c
JH
1594
1595 /* Return TRUE if context is fully useless. */
1596 bool useless_p () const;
44210a96
MJ
1597 /* Return TRUE if this context conveys the same information as X. */
1598 bool equal_to (const ipa_polymorphic_call_context &x) const;
ba392339 1599
44210a96
MJ
1600 /* Dump human readable context to F. If NEWLINE is true, it will be
1601 terminated by a newline. */
1602 void dump (FILE *f, bool newline = true) const;
ba392339
JH
1603 void DEBUG_FUNCTION debug () const;
1604
1605 /* LTO streaming. */
1606 void stream_out (struct output_block *) const;
1607 void stream_in (struct lto_input_block *, struct data_in *data_in);
1608
1609private:
67a1b94c 1610 bool combine_speculation_with (tree, HOST_WIDE_INT, bool, tree);
df0d8136 1611 bool meet_speculation_with (tree, HOST_WIDE_INT, bool, tree);
ba392339
JH
1612 void set_by_decl (tree, HOST_WIDE_INT);
1613 bool set_by_invariant (tree, tree, HOST_WIDE_INT);
df0d8136 1614 bool speculation_consistent_p (tree, HOST_WIDE_INT, bool, tree) const;
4081ada2 1615 void make_speculative (tree otr_type = NULL);
ba392339
JH
1616};
1617
e33c6cd6
MJ
1618/* Structure containing additional information about an indirect call. */
1619
1620struct GTY(()) cgraph_indirect_call_info
1621{
ba392339
JH
1622 /* When agg_content is set, an offset where the call pointer is located
1623 within the aggregate. */
1624 HOST_WIDE_INT offset;
1625 /* Context of the polymorphic call; use only when POLYMORPHIC flag is set. */
1626 ipa_polymorphic_call_context context;
b258210c
MJ
1627 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
1628 HOST_WIDE_INT otr_token;
1629 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
ba392339 1630 tree otr_type;
e33c6cd6
MJ
1631 /* Index of the parameter that is called. */
1632 int param_index;
5f902d76
JH
1633 /* ECF flags determined from the caller. */
1634 int ecf_flags;
634ab819
JH
1635 /* Profile_id of common target obtrained from profile. */
1636 int common_target_id;
1637 /* Probability that call will land in function with COMMON_TARGET_ID. */
1638 int common_target_probability;
b258210c
MJ
1639
1640 /* Set when the call is a virtual call with the parameter being the
1641 associated object pointer rather than a simple direct call. */
1642 unsigned polymorphic : 1;
8b7773a4
MJ
1643 /* Set when the call is a call of a pointer loaded from contents of an
1644 aggregate at offset. */
1645 unsigned agg_contents : 1;
c13bc3d9
MJ
1646 /* Set when this is a call through a member pointer. */
1647 unsigned member_ptr : 1;
91bb9f80
MJ
1648 /* When the agg_contents bit is set, this one determines whether the
1649 destination is loaded from a parameter passed by reference. */
8b7773a4 1650 unsigned by_ref : 1;
91bb9f80
MJ
1651 /* When the agg_contents bit is set, this one determines whether we can
1652 deduce from the function body that the loaded value from the reference is
1653 never modified between the invocation of the function and the load
1654 point. */
1655 unsigned guaranteed_unmodified : 1;
0127c169
JH
1656 /* For polymorphic calls this specify whether the virtual table pointer
1657 may have changed in between function entry and the call. */
1658 unsigned vptr_changed : 1;
e33c6cd6
MJ
1659};
1660
2a22f99c
TS
1661struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"),
1662 for_user)) cgraph_edge {
3dafb85c 1663 friend class cgraph_node;
8b25212d 1664 friend class symbol_table;
3dafb85c
ML
1665
1666 /* Remove the edge in the cgraph. */
1667 void remove (void);
1668
1669 /* Change field call_stmt of edge to NEW_STMT.
1670 If UPDATE_SPECULATIVE and E is any component of speculative
1671 edge, then update all components. */
538dd0b7 1672 void set_call_stmt (gcall *new_stmt, bool update_speculative = true);
3dafb85c
ML
1673
1674 /* Redirect callee of the edge to N. The function does not update underlying
1675 call expression. */
1676 void redirect_callee (cgraph_node *n);
1677
6a4bad95
MJ
1678 /* If the edge does not lead to a thunk, simply redirect it to N. Otherwise
1679 create one or more equivalent thunks for N and redirect E to the first in
1680 the chain. Note that it is then necessary to call
1681 n->expand_all_artificial_thunks once all callers are redirected. */
1682 void redirect_callee_duplicating_thunks (cgraph_node *n);
1683
3dafb85c
ML
1684 /* Make an indirect edge with an unknown callee an ordinary edge leading to
1685 CALLEE. DELTA is an integer constant that is to be added to the this
1686 pointer (first parameter) to compensate for skipping
1687 a thunk adjustment. */
1688 cgraph_edge *make_direct (cgraph_node *callee);
1689
1690 /* Turn edge into speculative call calling N2. Update
1691 the profile so the direct call is taken COUNT times
1692 with FREQUENCY. */
1bad9c18 1693 cgraph_edge *make_speculative (cgraph_node *n2, profile_count direct_count);
3dafb85c
ML
1694
1695 /* Given speculative call edge, return all three components. */
1696 void speculative_call_info (cgraph_edge *&direct, cgraph_edge *&indirect,
1697 ipa_ref *&reference);
1698
1699 /* Speculative call edge turned out to be direct call to CALLE_DECL.
1700 Remove the speculative call sequence and return edge representing the call.
1701 It is up to caller to redirect the call as appropriate. */
1702 cgraph_edge *resolve_speculation (tree callee_decl = NULL);
1703
1704 /* If necessary, change the function declaration in the call statement
1705 associated with the edge so that it corresponds to the edge callee. */
355fe088 1706 gimple *redirect_call_stmt_to_callee (void);
3dafb85c
ML
1707
1708 /* Create clone of edge in the node N represented
1709 by CALL_EXPR the callgraph. */
538dd0b7 1710 cgraph_edge * clone (cgraph_node *n, gcall *call_stmt, unsigned stmt_uid,
1bad9c18 1711 profile_count num, profile_count den,
3995f3a2 1712 bool update_original);
3dafb85c 1713
90988f77 1714 /* Verify edge count and frequency. */
1bad9c18 1715 bool verify_count ();
90988f77 1716
67914693 1717 /* Return true when call of edge cannot lead to return from caller
3dafb85c
ML
1718 and thus it is safe to ignore its side effects for IPA analysis
1719 when computing side effects of the caller. */
1720 bool cannot_lead_to_return_p (void);
1721
1722 /* Return true when the edge represents a direct recursion. */
1723 bool recursive_p (void);
1724
1725 /* Return true if the call can be hot. */
1726 bool maybe_hot_p (void);
1727
8b25212d
ML
1728 /* Get unique identifier of the edge. */
1729 inline int get_uid ()
1730 {
1731 return m_uid;
1732 }
1733
3dafb85c
ML
1734 /* Rebuild cgraph edges for current function node. This needs to be run after
1735 passes that don't update the cgraph. */
1736 static unsigned int rebuild_edges (void);
1737
1738 /* Rebuild cgraph references for current function node. This needs to be run
1739 after passes that don't update the cgraph. */
1740 static void rebuild_references (void);
1741
f714ecf5
JH
1742 /* During LTO stream in this can be used to check whether call can possibly
1743 be internal to the current translation unit. */
1744 bool possibly_call_in_translation_unit_p (void);
1745
6009ee7b 1746 /* Expected number of executions: calculated in profile.c. */
3995f3a2 1747 profile_count count;
d52f5295
ML
1748 cgraph_node *caller;
1749 cgraph_node *callee;
3dafb85c
ML
1750 cgraph_edge *prev_caller;
1751 cgraph_edge *next_caller;
1752 cgraph_edge *prev_callee;
1753 cgraph_edge *next_callee;
538dd0b7 1754 gcall *call_stmt;
e33c6cd6
MJ
1755 /* Additional information about an indirect call. Not cleared when an edge
1756 becomes direct. */
3dafb85c 1757 cgraph_indirect_call_info *indirect_info;
18c6ada9 1758 PTR GTY ((skip (""))) aux;
61a05df1
JH
1759 /* When equal to CIF_OK, inline this call. Otherwise, points to the
1760 explanation why function was not inlined. */
84562394 1761 enum cgraph_inline_failed_t inline_failed;
6009ee7b
MJ
1762 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
1763 when the function is serialized in. */
1764 unsigned int lto_stmt_uid;
e33c6cd6
MJ
1765 /* Whether this edge was made direct by indirect inlining. */
1766 unsigned int indirect_inlining_edge : 1;
1767 /* Whether this edge describes an indirect call with an undetermined
1768 callee. */
1769 unsigned int indirect_unknown_callee : 1;
1770 /* Whether this edge is still a dangling */
d7f09764
DN
1771 /* True if the corresponding CALL stmt cannot be inlined. */
1772 unsigned int call_stmt_cannot_inline_p : 1;
2505c5ed
JH
1773 /* Can this call throw externally? */
1774 unsigned int can_throw_external : 1;
042ae7d2
JH
1775 /* Edges with SPECULATIVE flag represents indirect calls that was
1776 speculatively turned into direct (i.e. by profile feedback).
1777 The final code sequence will have form:
1778
1779 if (call_target == expected_fn)
1780 expected_fn ();
1781 else
1782 call_target ();
1783
1784 Every speculative call is represented by three components attached
1785 to a same call statement:
1786 1) a direct call (to expected_fn)
1787 2) an indirect call (to call_target)
1788 3) a IPA_REF_ADDR refrence to expected_fn.
1789
1790 Optimizers may later redirect direct call to clone, so 1) and 3)
1791 do not need to necesarily agree with destination. */
1792 unsigned int speculative : 1;
f9bb202b
JH
1793 /* Set to true when caller is a constructor or destructor of polymorphic
1794 type. */
1795 unsigned in_polymorphic_cdtor : 1;
3dafb85c 1796
f13fe18b
JH
1797 /* Return true if call must bind to current definition. */
1798 bool binds_to_current_def_p ();
1799
1bad9c18
JH
1800 /* Expected frequency of executions within the function.
1801 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
1802 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
1803 int frequency ();
41f0e819
JH
1804
1805 /* Expected frequency of executions within the function. */
1806 sreal sreal_frequency ();
3dafb85c 1807private:
8b25212d
ML
1808 /* Unique id of the edge. */
1809 int m_uid;
1810
3dafb85c
ML
1811 /* Remove the edge from the list of the callers of the callee. */
1812 void remove_caller (void);
1813
1814 /* Remove the edge from the list of the callees of the caller. */
1815 void remove_callee (void);
90988f77
ML
1816
1817 /* Set callee N of call graph edge and add it to the corresponding set of
1818 callers. */
1819 void set_callee (cgraph_node *n);
1820
1821 /* Output flags of edge to a file F. */
1822 void dump_edge_flags (FILE *f);
1823
1824 /* Verify that call graph edge corresponds to DECL from the associated
1825 statement. Return true if the verification should fail. */
1826 bool verify_corresponds_to_fndecl (tree decl);
1c4a429a
JH
1827};
1828
45a80bb9
JH
1829#define CGRAPH_FREQ_BASE 1000
1830#define CGRAPH_FREQ_MAX 100000
1831
8a4a83ed
JH
1832/* The varpool data structure.
1833 Each static variable decl has assigned varpool_node. */
e69529cd 1834
5e20cdc9 1835class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
a3bfa8b8 1836public:
9041d2e6
ML
1837 /* Dump given varpool node to F. */
1838 void dump (FILE *f);
1839
1840 /* Dump given varpool node to stderr. */
1841 void DEBUG_FUNCTION debug (void);
1842
1843 /* Remove variable from symbol table. */
1844 void remove (void);
1845
1846 /* Remove node initializer when it is no longer needed. */
1847 void remove_initializer (void);
1848
1849 void analyze (void);
1850
1851 /* Return variable availability. */
f13fe18b 1852 availability get_availability (symtab_node *ref = NULL);
9041d2e6
ML
1853
1854 /* When doing LTO, read variable's constructor from disk if
1855 it is not already present. */
1856 tree get_constructor (void);
1857
1858 /* Return true if variable has constructor that can be used for folding. */
1859 bool ctor_useable_for_folding_p (void);
1860
1861 /* For given variable pool node, walk the alias chain to return the function
1862 the variable is alias of. Do not walk through thunks.
f13fe18b
JH
1863 When AVAILABILITY is non-NULL, get minimal availability in the chain.
1864 When REF is non-NULL, assume that reference happens in symbol REF
1865 when determining the availability. */
9041d2e6 1866 inline varpool_node *ultimate_alias_target
f13fe18b 1867 (availability *availability = NULL, symtab_node *ref = NULL);
9041d2e6
ML
1868
1869 /* Return node that alias is aliasing. */
1870 inline varpool_node *get_alias_target (void);
1871
1872 /* Output one variable, if necessary. Return whether we output it. */
1873 bool assemble_decl (void);
1874
1875 /* For variables in named sections make sure get_variable_section
1876 is called before we switch to those sections. Then section
1877 conflicts between read-only and read-only requiring relocations
1878 sections can be resolved. */
1879 void finalize_named_section_flags (void);
1880
1881 /* Call calback on varpool symbol and aliases associated to varpool symbol.
1882 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
1883 skipped. */
31de7606
JH
1884 bool call_for_symbol_and_aliases (bool (*callback) (varpool_node *, void *),
1885 void *data,
1886 bool include_overwritable);
9041d2e6
ML
1887
1888 /* Return true when variable should be considered externally visible. */
1889 bool externally_visible_p (void);
1890
1891 /* Return true when all references to variable must be visible
1892 in ipa_ref_list.
1893 i.e. if the variable is not externally visible or not used in some magic
1894 way (asm statement or such).
1895 The magic uses are all summarized in force_output flag. */
1896 inline bool all_refs_explicit_p ();
1897
1898 /* Return true when variable can be removed from variable pool
1899 if all direct calls are eliminated. */
1900 inline bool can_remove_if_no_refs_p (void);
1901
3dafb85c
ML
1902 /* Add the variable DECL to the varpool.
1903 Unlike finalize_decl function is intended to be used
1904 by middle end and allows insertion of new variable at arbitrary point
1905 of compilation. */
1906 static void add (tree decl);
1907
9041d2e6
ML
1908 /* Return varpool node for given symbol and check it is a function. */
1909 static inline varpool_node *get (const_tree decl);
1910
1911 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct
1912 the middle end to output the variable to asm file, if needed or externally
1913 visible. */
1914 static void finalize_decl (tree decl);
1915
9041d2e6
ML
1916 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
1917 Extra name aliases are output whenever DECL is output. */
1918 static varpool_node * create_extra_name_alias (tree alias, tree decl);
1919
1920 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
1921 Extra name aliases are output whenever DECL is output. */
1922 static varpool_node * create_alias (tree, tree);
1923
1924 /* Dump the variable pool to F. */
1925 static void dump_varpool (FILE *f);
1926
1927 /* Dump the variable pool to stderr. */
1928 static void DEBUG_FUNCTION debug_varpool (void);
1929
1930 /* Allocate new callgraph node and insert it into basic data structures. */
1931 static varpool_node *create_empty (void);
1932
1933 /* Return varpool node assigned to DECL. Create new one when needed. */
1934 static varpool_node *get_create (tree decl);
1935
1936 /* Given an assembler name, lookup node. */
1937 static varpool_node *get_for_asmname (tree asmname);
1938
6b02a499 1939 /* Set when variable is scheduled to be assembled. */
b4e19405 1940 unsigned output : 1;
eb1d8159 1941
d5e254e1
IE
1942 /* Set when variable has statically initialized pointer
1943 or is a static bounds variable and needs initalization. */
1944 unsigned need_bounds_init : 1;
1945
59b36ecf
JJ
1946 /* Set if the variable is dynamically initialized, except for
1947 function local statics. */
1948 unsigned dynamically_initialized : 1;
56363ffd
JH
1949
1950 ENUM_BITFIELD(tls_model) tls_model : 3;
eb6a09a7
JH
1951
1952 /* Set if the variable is known to be used by single function only.
1953 This is computed by ipa_signle_use pass and used by late optimizations
1954 in places where optimization would be valid for local static variable
1955 if we did not do any inter-procedural code movement. */
1956 unsigned used_by_single_function : 1;
d52f5295 1957
9041d2e6
ML
1958private:
1959 /* Assemble thunks and aliases associated to varpool node. */
1960 void assemble_aliases (void);
31de7606
JH
1961
1962 /* Worker for call_for_node_and_aliases. */
1963 bool call_for_symbol_and_aliases_1 (bool (*callback) (varpool_node *, void *),
1964 void *data,
1965 bool include_overwritable);
e69529cd
JH
1966};
1967
65d630d4 1968/* Every top level asm statement is put into a asm_node. */
474eccc6 1969
65d630d4 1970struct GTY(()) asm_node {
3dafb85c
ML
1971
1972
474eccc6 1973 /* Next asm node. */
3dafb85c 1974 asm_node *next;
474eccc6
ILT
1975 /* String for this asm node. */
1976 tree asm_str;
1977 /* Ordering of all cgraph nodes. */
1978 int order;
1979};
1980
5d59b5e1
LC
1981/* Report whether or not THIS symtab node is a function, aka cgraph_node. */
1982
1983template <>
1984template <>
1985inline bool
7de90a6c 1986is_a_helper <cgraph_node *>::test (symtab_node *p)
5d59b5e1 1987{
d52f5295 1988 return p && p->type == SYMTAB_FUNCTION;
5d59b5e1
LC
1989}
1990
1991/* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
1992
1993template <>
1994template <>
1995inline bool
7de90a6c 1996is_a_helper <varpool_node *>::test (symtab_node *p)
5d59b5e1 1997{
d52f5295 1998 return p && p->type == SYMTAB_VARIABLE;
5d59b5e1
LC
1999}
2000
3dafb85c
ML
2001/* Macros to access the next item in the list of free cgraph nodes and
2002 edges. */
2003#define NEXT_FREE_NODE(NODE) dyn_cast<cgraph_node *> ((NODE)->next)
2004#define SET_NEXT_FREE_NODE(NODE,NODE2) ((NODE))->next = NODE2
2005#define NEXT_FREE_EDGE(EDGE) (EDGE)->prev_caller
2006
2007typedef void (*cgraph_edge_hook)(cgraph_edge *, void *);
2008typedef void (*cgraph_node_hook)(cgraph_node *, void *);
2009typedef void (*varpool_node_hook)(varpool_node *, void *);
2010typedef void (*cgraph_2edge_hook)(cgraph_edge *, cgraph_edge *, void *);
2011typedef void (*cgraph_2node_hook)(cgraph_node *, cgraph_node *, void *);
2012
2013struct cgraph_edge_hook_list;
2014struct cgraph_node_hook_list;
2015struct varpool_node_hook_list;
2016struct cgraph_2edge_hook_list;
2017struct cgraph_2node_hook_list;
2018
2019/* Map from a symbol to initialization/finalization priorities. */
2020struct GTY(()) symbol_priority_map {
3dafb85c
ML
2021 priority_type init;
2022 priority_type fini;
2023};
2024
2025enum symtab_state
f45e0ad1 2026{
66058468 2027 /* Frontend is parsing and finalizing functions. */
3dafb85c 2028 PARSING,
f45e0ad1 2029 /* Callgraph is being constructed. It is safe to add new functions. */
3dafb85c 2030 CONSTRUCTION,
17e0fc92 2031 /* Callgraph is being streamed-in at LTO time. */
3dafb85c 2032 LTO_STREAMING,
17e0fc92 2033 /* Callgraph is built and early IPA passes are being run. */
3dafb85c 2034 IPA,
7a388ee4 2035 /* Callgraph is built and all functions are transformed to SSA form. */
3dafb85c 2036 IPA_SSA,
17e0fc92
JH
2037 /* All inline decisions are done; it is now possible to remove extern inline
2038 functions and virtual call targets. */
2039 IPA_SSA_AFTER_INLINING,
f45e0ad1 2040 /* Functions are now ordered and being passed to RTL expanders. */
3dafb85c 2041 EXPANSION,
f45e0ad1 2042 /* All cgraph expansion is done. */
3dafb85c 2043 FINISHED
f45e0ad1 2044};
1c4a429a 2045
7edd9b15 2046struct asmname_hasher : ggc_ptr_hash <symtab_node>
2a22f99c 2047{
2a22f99c 2048 typedef const_tree compare_type;
2a22f99c
TS
2049
2050 static hashval_t hash (symtab_node *n);
2051 static bool equal (symtab_node *n, const_tree t);
2a22f99c
TS
2052};
2053
3dafb85c
ML
2054class GTY((tag ("SYMTAB"))) symbol_table
2055{
2056public:
2057 friend class symtab_node;
2058 friend class cgraph_node;
2059 friend class cgraph_edge;
2060
8b25212d 2061 symbol_table (): cgraph_max_uid (1), edges_max_uid (1)
4008290f
ML
2062 {
2063 }
2064
3dafb85c 2065 /* Initialize callgraph dump file. */
c582198b 2066 void initialize (void);
3dafb85c
ML
2067
2068 /* Register a top-level asm statement ASM_STR. */
2069 inline asm_node *finalize_toplevel_asm (tree asm_str);
2070
2071 /* Analyze the whole compilation unit once it is parsed completely. */
2072 void finalize_compilation_unit (void);
2073
2074 /* C++ frontend produce same body aliases all over the place, even before PCH
2075 gets streamed out. It relies on us linking the aliases with their function
2076 in order to do the fixups, but ipa-ref is not PCH safe. Consequentely we
2077 first produce aliases without links, but once C++ FE is sure he won't sream
2078 PCH we build the links via this function. */
2079 void process_same_body_aliases (void);
2080
2081 /* Perform simple optimizations based on callgraph. */
2082 void compile (void);
2083
2084 /* Process CGRAPH_NEW_FUNCTIONS and perform actions necessary to add these
2085 functions into callgraph in a way so they look like ordinary reachable
2086 functions inserted into callgraph already at construction time. */
2087 void process_new_functions (void);
2088
2089 /* Once all functions from compilation unit are in memory, produce all clones
2090 and update all calls. We might also do this on demand if we don't want to
2091 bring all functions to memory prior compilation, but current WHOPR
026c3cfd 2092 implementation does that and it is bit easier to keep everything right
3dafb85c
ML
2093 in this order. */
2094 void materialize_all_clones (void);
2095
2096 /* Register a symbol NODE. */
2097 inline void register_symbol (symtab_node *node);
2098
2099 inline void
2100 clear_asm_symbols (void)
2101 {
2102 asmnodes = NULL;
2103 asm_last_node = NULL;
2104 }
2105
2106 /* Perform reachability analysis and reclaim all unreachable nodes. */
17e0fc92 2107 bool remove_unreachable_nodes (FILE *file);
3dafb85c
ML
2108
2109 /* Optimization of function bodies might've rendered some variables as
2110 unnecessary so we want to avoid these from being compiled. Re-do
2111 reachability starting from variables that are either externally visible
2112 or was referred from the asm output routines. */
2113 void remove_unreferenced_decls (void);
2114
2115 /* Unregister a symbol NODE. */
2116 inline void unregister (symtab_node *node);
2117
2118 /* Allocate new callgraph node and insert it into basic data structures. */
2119 cgraph_node *create_empty (void);
2120
74644756
ML
2121 /* Release a callgraph NODE. */
2122 void release_symbol (cgraph_node *node);
3dafb85c
ML
2123
2124 /* Output all variables enqueued to be assembled. */
2125 bool output_variables (void);
2126
3dafb85c
ML
2127 /* Weakrefs may be associated to external decls and thus not output
2128 at expansion time. Emit all necessary aliases. */
2129 void output_weakrefs (void);
2130
2131 /* Return first static symbol with definition. */
2132 inline symtab_node *first_symbol (void);
2133
2134 /* Return first assembler symbol. */
2135 inline asm_node *
2136 first_asm_symbol (void)
2137 {
2138 return asmnodes;
2139 }
2140
2141 /* Return first static symbol with definition. */
2142 inline symtab_node *first_defined_symbol (void);
2143
2144 /* Return first variable. */
2145 inline varpool_node *first_variable (void);
2146
2147 /* Return next variable after NODE. */
2148 inline varpool_node *next_variable (varpool_node *node);
2149
2150 /* Return first static variable with initializer. */
2151 inline varpool_node *first_static_initializer (void);
2152
2153 /* Return next static variable with initializer after NODE. */
2154 inline varpool_node *next_static_initializer (varpool_node *node);
2155
2156 /* Return first static variable with definition. */
2157 inline varpool_node *first_defined_variable (void);
2158
2159 /* Return next static variable with definition after NODE. */
2160 inline varpool_node *next_defined_variable (varpool_node *node);
2161
2162 /* Return first function with body defined. */
2163 inline cgraph_node *first_defined_function (void);
2164
2165 /* Return next function with body defined after NODE. */
2166 inline cgraph_node *next_defined_function (cgraph_node *node);
2167
2168 /* Return first function. */
2169 inline cgraph_node *first_function (void);
2170
2171 /* Return next function. */
2172 inline cgraph_node *next_function (cgraph_node *node);
2173
2174 /* Return first function with body defined. */
2175 cgraph_node *first_function_with_gimple_body (void);
2176
2177 /* Return next reachable static variable with initializer after NODE. */
2178 inline cgraph_node *next_function_with_gimple_body (cgraph_node *node);
2179
2180 /* Register HOOK to be called with DATA on each removed edge. */
2181 cgraph_edge_hook_list *add_edge_removal_hook (cgraph_edge_hook hook,
2182 void *data);
2183
2184 /* Remove ENTRY from the list of hooks called on removing edges. */
2185 void remove_edge_removal_hook (cgraph_edge_hook_list *entry);
2186
2187 /* Register HOOK to be called with DATA on each removed node. */
2188 cgraph_node_hook_list *add_cgraph_removal_hook (cgraph_node_hook hook,
2189 void *data);
2190
2191 /* Remove ENTRY from the list of hooks called on removing nodes. */
2192 void remove_cgraph_removal_hook (cgraph_node_hook_list *entry);
2193
2194 /* Register HOOK to be called with DATA on each removed node. */
2195 varpool_node_hook_list *add_varpool_removal_hook (varpool_node_hook hook,
2196 void *data);
2197
2198 /* Remove ENTRY from the list of hooks called on removing nodes. */
2199 void remove_varpool_removal_hook (varpool_node_hook_list *entry);
2200
2201 /* Register HOOK to be called with DATA on each inserted node. */
2202 cgraph_node_hook_list *add_cgraph_insertion_hook (cgraph_node_hook hook,
2203 void *data);
2204
2205 /* Remove ENTRY from the list of hooks called on inserted nodes. */
2206 void remove_cgraph_insertion_hook (cgraph_node_hook_list *entry);
2207
2208 /* Register HOOK to be called with DATA on each inserted node. */
2209 varpool_node_hook_list *add_varpool_insertion_hook (varpool_node_hook hook,
2210 void *data);
2211
2212 /* Remove ENTRY from the list of hooks called on inserted nodes. */
2213 void remove_varpool_insertion_hook (varpool_node_hook_list *entry);
2214
2215 /* Register HOOK to be called with DATA on each duplicated edge. */
2216 cgraph_2edge_hook_list *add_edge_duplication_hook (cgraph_2edge_hook hook,
2217 void *data);
2218 /* Remove ENTRY from the list of hooks called on duplicating edges. */
2219 void remove_edge_duplication_hook (cgraph_2edge_hook_list *entry);
2220
2221 /* Register HOOK to be called with DATA on each duplicated node. */
2222 cgraph_2node_hook_list *add_cgraph_duplication_hook (cgraph_2node_hook hook,
2223 void *data);
2224
2225 /* Remove ENTRY from the list of hooks called on duplicating nodes. */
2226 void remove_cgraph_duplication_hook (cgraph_2node_hook_list *entry);
2227
2228 /* Call all edge removal hooks. */
2229 void call_edge_removal_hooks (cgraph_edge *e);
2230
2231 /* Call all node insertion hooks. */
2232 void call_cgraph_insertion_hooks (cgraph_node *node);
2233
2234 /* Call all node removal hooks. */
2235 void call_cgraph_removal_hooks (cgraph_node *node);
2236
2237 /* Call all node duplication hooks. */
2238 void call_cgraph_duplication_hooks (cgraph_node *node, cgraph_node *node2);
2239
2240 /* Call all edge duplication hooks. */
2241 void call_edge_duplication_hooks (cgraph_edge *cs1, cgraph_edge *cs2);
2242
2243 /* Call all node removal hooks. */
2244 void call_varpool_removal_hooks (varpool_node *node);
2245
2246 /* Call all node insertion hooks. */
2247 void call_varpool_insertion_hooks (varpool_node *node);
2248
2249 /* Arrange node to be first in its entry of assembler_name_hash. */
2250 void symtab_prevail_in_asm_name_hash (symtab_node *node);
2251
2252 /* Initalize asm name hash unless. */
2253 void symtab_initialize_asm_name_hash (void);
2254
2255 /* Set the DECL_ASSEMBLER_NAME and update symtab hashtables. */
2256 void change_decl_assembler_name (tree decl, tree name);
e69529cd 2257
6c52831d
ML
2258 /* Dump symbol table to F. */
2259 void dump (FILE *f);
2260
2261 /* Dump symbol table to stderr. */
e94497fb 2262 void DEBUG_FUNCTION debug (void);
6c52831d 2263
71e54687
JH
2264 /* Return true if assembler names NAME1 and NAME2 leads to the same symbol
2265 name. */
2266 static bool assembler_names_equal_p (const char *name1, const char *name2);
2267
3dafb85c
ML
2268 int cgraph_count;
2269 int cgraph_max_uid;
2270
2271 int edges_count;
2272 int edges_max_uid;
2273
2274 symtab_node* GTY(()) nodes;
2275 asm_node* GTY(()) asmnodes;
2276 asm_node* GTY(()) asm_last_node;
2277 cgraph_node* GTY(()) free_nodes;
2278
2279 /* Head of a linked list of unused (freed) call graph edges.
2280 Do not GTY((delete)) this list so UIDs gets reliably recycled. */
2281 cgraph_edge * GTY(()) free_edges;
2282
2283 /* The order index of the next symtab node to be created. This is
2284 used so that we can sort the cgraph nodes in order by when we saw
2285 them, to support -fno-toplevel-reorder. */
2286 int order;
2287
2288 /* Set when whole unit has been analyzed so we can access global info. */
2289 bool global_info_ready;
2290 /* What state callgraph is in right now. */
2291 enum symtab_state state;
2292 /* Set when the cgraph is fully build and the basic flags are computed. */
2293 bool function_flags_ready;
2294
2295 bool cpp_implicit_aliases_done;
2296
2297 /* Hash table used to hold sectoons. */
2a22f99c 2298 hash_table<section_name_hasher> *GTY(()) section_hash;
3dafb85c
ML
2299
2300 /* Hash table used to convert assembler names into nodes. */
2a22f99c 2301 hash_table<asmname_hasher> *assembler_name_hash;
3dafb85c
ML
2302
2303 /* Hash table used to hold init priorities. */
b086d530 2304 hash_map<symtab_node *, symbol_priority_map> *init_priority_hash;
3dafb85c
ML
2305
2306 FILE* GTY ((skip)) dump_file;
2307
f8a1abf8
JH
2308 /* Return symbol used to separate symbol name from suffix. */
2309 static char symbol_suffix_separator ();
2310
0bdad123
ML
2311 FILE* GTY ((skip)) ipa_clones_dump_file;
2312
2313 hash_set <const cgraph_node *> GTY ((skip)) cloned_nodes;
2314
3dafb85c
ML
2315private:
2316 /* Allocate new callgraph node. */
2317 inline cgraph_node * allocate_cgraph_symbol (void);
2318
2319 /* Allocate a cgraph_edge structure and fill it with data according to the
2320 parameters of which only CALLEE can be NULL (when creating an indirect call
2321 edge). */
2322 cgraph_edge *create_edge (cgraph_node *caller, cgraph_node *callee,
1bad9c18 2323 gcall *call_stmt, profile_count count,
3dafb85c
ML
2324 bool indir_unknown_callee);
2325
2326 /* Put the edge onto the free list. */
2327 void free_edge (cgraph_edge *e);
2328
2329 /* Insert NODE to assembler name hash. */
2330 void insert_to_assembler_name_hash (symtab_node *node, bool with_clones);
2331
2332 /* Remove NODE from assembler name hash. */
2333 void unlink_from_assembler_name_hash (symtab_node *node, bool with_clones);
2334
2335 /* Hash asmnames ignoring the user specified marks. */
2336 static hashval_t decl_assembler_name_hash (const_tree asmname);
2337
2338 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
2339 static bool decl_assembler_name_equal (tree decl, const_tree asmname);
2340
2a22f99c 2341 friend struct asmname_hasher;
3dafb85c
ML
2342
2343 /* List of hooks triggered when an edge is removed. */
2344 cgraph_edge_hook_list * GTY((skip)) m_first_edge_removal_hook;
2345 /* List of hooks triggem_red when a cgraph node is removed. */
2346 cgraph_node_hook_list * GTY((skip)) m_first_cgraph_removal_hook;
2347 /* List of hooks triggered when an edge is duplicated. */
2348 cgraph_2edge_hook_list * GTY((skip)) m_first_edge_duplicated_hook;
2349 /* List of hooks triggered when a node is duplicated. */
2350 cgraph_2node_hook_list * GTY((skip)) m_first_cgraph_duplicated_hook;
2351 /* List of hooks triggered when an function is inserted. */
2352 cgraph_node_hook_list * GTY((skip)) m_first_cgraph_insertion_hook;
2353 /* List of hooks triggered when an variable is inserted. */
2354 varpool_node_hook_list * GTY((skip)) m_first_varpool_insertion_hook;
2355 /* List of hooks triggered when a node is removed. */
2356 varpool_node_hook_list * GTY((skip)) m_first_varpool_removal_hook;
2357};
2358
2359extern GTY(()) symbol_table *symtab;
2360
2361extern vec<cgraph_node *> cgraph_new_nodes;
2aae7680 2362
2a22f99c
TS
2363inline hashval_t
2364asmname_hasher::hash (symtab_node *n)
2365{
2366 return symbol_table::decl_assembler_name_hash
2367 (DECL_ASSEMBLER_NAME (n->decl));
2368}
2369
2370inline bool
2371asmname_hasher::equal (symtab_node *n, const_tree t)
2372{
2373 return symbol_table::decl_assembler_name_equal (n->decl, t);
2374}
2375
1c4a429a 2376/* In cgraph.c */
3edf64aa 2377void cgraph_c_finalize (void);
12123452 2378void release_function_body (tree);
3dafb85c 2379cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
d52f5295 2380
355fe088 2381void cgraph_update_edges_for_call_stmt (gimple *, tree, gimple *);
1bb17c21
JH
2382bool cgraph_function_possibly_inlined_p (tree);
2383
61a05df1 2384const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
1cf11770 2385cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
6b02a499 2386
355fe088 2387extern bool gimple_check_call_matching_types (gimple *, tree, bool);
9c8305f8
JH
2388
2389/* In cgraphunit.c */
3edf64aa
DM
2390void cgraphunit_c_finalize (void);
2391
3649b9b7
ST
2392/* Initialize datastructures so DECL is a function in lowered gimple form.
2393 IN_SSA is true if the gimple is in SSA. */
3995f3a2 2394basic_block init_lowered_empty_function (tree, bool, profile_count);
66a20fc2 2395
44662f68
EB
2396tree thunk_adjust (gimple_stmt_iterator *, tree, bool, HOST_WIDE_INT, tree,
2397 HOST_WIDE_INT);
66a20fc2
JH
2398/* In cgraphclones.c */
2399
7958186b
MP
2400tree clone_function_name_numbered (const char *name, const char *suffix);
2401tree clone_function_name_numbered (tree decl, const char *suffix);
2402tree clone_function_name (const char *name, const char *suffix,
2403 unsigned long number);
53aedcce
MP
2404tree clone_function_name (tree decl, const char *suffix,
2405 unsigned long number);
7958186b 2406tree clone_function_name (tree decl, const char *suffix);
d52f5295 2407
d52f5295 2408void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *,
9c8305f8 2409 bool, bitmap, bool, bitmap, basic_block);
9c8305f8 2410
0bdad123
ML
2411void dump_callgraph_transformation (const cgraph_node *original,
2412 const cgraph_node *clone,
2413 const char *suffix);
b0fd4d7e
MJ
2414tree cgraph_build_function_type_skip_args (tree orig_type, bitmap args_to_skip,
2415 bool skip_return);
0bdad123 2416
917948d3 2417/* In cgraphbuild.c */
9187e02d 2418int compute_call_stmt_bb_frequency (tree, basic_block bb);
9c8305f8 2419void record_references_in_initializer (tree, bool);
917948d3 2420
ca31b95f 2421/* In ipa.c */
9c8305f8 2422void cgraph_build_static_cdtor (char which, tree body, int priority);
2e14744f 2423bool ipa_discover_variable_flags (void);
ca31b95f 2424
8a4a83ed 2425/* In varpool.c */
6a6dac52 2426tree ctor_for_folding (tree);
68e56cc4 2427
27d020cf
JH
2428/* In ipa-inline-analysis.c */
2429void initialize_inline_failed (struct cgraph_edge *);
2430bool speculation_useful_p (struct cgraph_edge *e, bool anticipate_inlining);
2431
d52f5295
ML
2432/* Return true when the symbol is real symbol, i.e. it is not inline clone
2433 or abstract function kept for debug info purposes only. */
2434inline bool
2435symtab_node::real_symbol_p (void)
2436{
2437 cgraph_node *cnode;
2438
00de328a 2439 if (DECL_ABSTRACT_P (decl))
d52f5295 2440 return false;
71e54687
JH
2441 if (transparent_alias && definition)
2442 return false;
d52f5295
ML
2443 if (!is_a <cgraph_node *> (this))
2444 return true;
2445 cnode = dyn_cast <cgraph_node *> (this);
2446 if (cnode->global.inlined_to)
2447 return false;
2448 return true;
2449}
2450
89330618 2451/* Return true if DECL should have entry in symbol table if used.
97b7f138 2452 Those are functions and static & external veriables*/
89330618 2453
0241e486 2454static inline bool
89330618
JH
2455decl_in_symtab_p (const_tree decl)
2456{
2457 return (TREE_CODE (decl) == FUNCTION_DECL
2458 || (TREE_CODE (decl) == VAR_DECL
2459 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))));
2460}
2461
d52f5295
ML
2462inline bool
2463symtab_node::in_same_comdat_group_p (symtab_node *target)
aede2c10 2464{
d52f5295 2465 symtab_node *source = this;
aede2c10 2466
d52f5295
ML
2467 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
2468 {
2469 if (cn->global.inlined_to)
2470 source = cn->global.inlined_to;
2471 }
2472 if (cgraph_node *cn = dyn_cast <cgraph_node *> (target))
2473 {
2474 if (cn->global.inlined_to)
2475 target = cn->global.inlined_to;
2476 }
2477
2478 return source->get_comdat_group () == target->get_comdat_group ();
1f00098b
JH
2479}
2480
d52f5295
ML
2481/* Return node that alias is aliasing. */
2482
2483inline symtab_node *
2484symtab_node::get_alias_target (void)
1f00098b 2485{
3dafb85c 2486 ipa_ref *ref = NULL;
d52f5295
ML
2487 iterate_reference (0, ref);
2488 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
2489 return ref->referred;
1f00098b
JH
2490}
2491
d52f5295 2492/* Return next reachable static symbol with initializer after the node. */
31de7606 2493
d52f5295
ML
2494inline symtab_node *
2495symtab_node::next_defined_symbol (void)
1ab24192 2496{
d52f5295
ML
2497 symtab_node *node1 = next;
2498
2499 for (; node1; node1 = node1->next)
2500 if (node1->definition)
2501 return node1;
2502
2503 return NULL;
1ab24192
JH
2504}
2505
31de7606
JH
2506/* Iterates I-th reference in the list, REF is also set. */
2507
2508inline ipa_ref *
2509symtab_node::iterate_reference (unsigned i, ipa_ref *&ref)
2510{
2511 vec_safe_iterate (ref_list.references, i, &ref);
2512
2513 return ref;
2514}
2515
2516/* Iterates I-th referring item in the list, REF is also set. */
2517
2518inline ipa_ref *
2519symtab_node::iterate_referring (unsigned i, ipa_ref *&ref)
2520{
2521 ref_list.referring.iterate (i, &ref);
2522
2523 return ref;
2524}
2525
2526/* Iterates I-th referring alias item in the list, REF is also set. */
2527
2528inline ipa_ref *
2529symtab_node::iterate_direct_aliases (unsigned i, ipa_ref *&ref)
2530{
2531 ref_list.referring.iterate (i, &ref);
2532
2533 if (ref && ref->use != IPA_REF_ALIAS)
2534 return NULL;
2535
2536 return ref;
2537}
2538
2539/* Return true if list contains an alias. */
2540
2541inline bool
2542symtab_node::has_aliases_p (void)
2543{
2544 ipa_ref *ref = NULL;
31de7606 2545
190bbd0b 2546 return (iterate_direct_aliases (0, ref) != NULL);
31de7606
JH
2547}
2548
2549/* Return true when RESOLUTION indicate that linker will use
2550 the symbol from non-LTO object files. */
2551
2552inline bool
2553resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution)
2554{
2555 return (resolution == LDPR_PREVAILING_DEF
2556 || resolution == LDPR_PREEMPTED_REG
2557 || resolution == LDPR_RESOLVED_EXEC
2558 || resolution == LDPR_RESOLVED_DYN);
2559}
2560
2561/* Return true when symtab_node is known to be used from other (non-LTO)
2562 object file. Known only when doing LTO via linker plugin. */
2563
2564inline bool
2565symtab_node::used_from_object_file_p (void)
2566{
2567 if (!TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
2568 return false;
2569 if (resolution_used_from_other_file_p (resolution))
2570 return true;
2571 return false;
2572}
2573
1ab24192 2574/* Return varpool node for given symbol and check it is a function. */
3dafb85c 2575
9041d2e6
ML
2576inline varpool_node *
2577varpool_node::get (const_tree decl)
1ab24192
JH
2578{
2579 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
d52f5295 2580 return dyn_cast<varpool_node *> (symtab_node::get (decl));
1ab24192
JH
2581}
2582
3dafb85c
ML
2583/* Register a symbol NODE. */
2584
2585inline void
2586symbol_table::register_symbol (symtab_node *node)
2587{
2588 node->next = nodes;
2589 node->previous = NULL;
2590
2591 if (nodes)
2592 nodes->previous = node;
2593 nodes = node;
2594
2595 node->order = order++;
2596}
2597
2598/* Register a top-level asm statement ASM_STR. */
2599
2600asm_node *
2601symbol_table::finalize_toplevel_asm (tree asm_str)
2602{
2603 asm_node *node;
2604
2605 node = ggc_cleared_alloc<asm_node> ();
2606 node->asm_str = asm_str;
2607 node->order = order++;
2608 node->next = NULL;
2609
2610 if (asmnodes == NULL)
2611 asmnodes = node;
2612 else
2613 asm_last_node->next = node;
2614
2615 asm_last_node = node;
2616 return node;
2617}
2618
2619/* Unregister a symbol NODE. */
2620inline void
2621symbol_table::unregister (symtab_node *node)
2622{
2623 if (node->previous)
2624 node->previous->next = node->next;
2625 else
2626 nodes = node->next;
2627
2628 if (node->next)
2629 node->next->previous = node->previous;
2630
2631 node->next = NULL;
2632 node->previous = NULL;
2633}
2634
3dafb85c
ML
2635/* Release a callgraph NODE with UID and put in to the list of free nodes. */
2636
2637inline void
74644756 2638symbol_table::release_symbol (cgraph_node *node)
3dafb85c
ML
2639{
2640 cgraph_count--;
2641
2642 /* Clear out the node to NULL all pointers and add the node to the free
2643 list. */
2644 memset (node, 0, sizeof (*node));
2645 node->type = SYMTAB_FUNCTION;
3dafb85c
ML
2646 SET_NEXT_FREE_NODE (node, free_nodes);
2647 free_nodes = node;
2648}
2649
2650/* Allocate new callgraph node. */
2651
2652inline cgraph_node *
2653symbol_table::allocate_cgraph_symbol (void)
2654{
2655 cgraph_node *node;
2656
2657 if (free_nodes)
2658 {
2659 node = free_nodes;
2660 free_nodes = NEXT_FREE_NODE (node);
2661 }
2662 else
74644756 2663 node = ggc_cleared_alloc<cgraph_node> ();
3dafb85c 2664
4325656f 2665 node->m_uid = cgraph_max_uid++;
3dafb85c
ML
2666 return node;
2667}
2668
2669
2670/* Return first static symbol with definition. */
2671inline symtab_node *
2672symbol_table::first_symbol (void)
2673{
2674 return nodes;
2675}
2676
1ab24192
JH
2677/* Walk all symbols. */
2678#define FOR_EACH_SYMBOL(node) \
3dafb85c 2679 for ((node) = symtab->first_symbol (); (node); (node) = (node)->next)
1f00098b 2680
d6d229c6 2681/* Return first static symbol with definition. */
3dafb85c
ML
2682inline symtab_node *
2683symbol_table::first_defined_symbol (void)
d6d229c6
JH
2684{
2685 symtab_node *node;
2686
3dafb85c 2687 for (node = nodes; node; node = node->next)
d6d229c6
JH
2688 if (node->definition)
2689 return node;
2690
2691 return NULL;
2692}
2693
d6d229c6
JH
2694/* Walk all symbols with definitions in current unit. */
2695#define FOR_EACH_DEFINED_SYMBOL(node) \
3dafb85c 2696 for ((node) = symtab->first_defined_symbol (); (node); \
d52f5295 2697 (node) = node->next_defined_symbol ())
66058468
JH
2698
2699/* Return first variable. */
3dafb85c
ML
2700inline varpool_node *
2701symbol_table::first_variable (void)
66058468 2702{
5e20cdc9 2703 symtab_node *node;
3dafb85c 2704 for (node = nodes; node; node = node->next)
7de90a6c 2705 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
5d59b5e1 2706 return vnode;
66058468
JH
2707 return NULL;
2708}
2709
2710/* Return next variable after NODE. */
3dafb85c
ML
2711inline varpool_node *
2712symbol_table::next_variable (varpool_node *node)
66058468 2713{
5e20cdc9 2714 symtab_node *node1 = node->next;
67348ccc 2715 for (; node1; node1 = node1->next)
7de90a6c 2716 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
5d59b5e1 2717 return vnode1;
66058468
JH
2718 return NULL;
2719}
2720/* Walk all variables. */
2721#define FOR_EACH_VARIABLE(node) \
3dafb85c 2722 for ((node) = symtab->first_variable (); \
66058468 2723 (node); \
3dafb85c 2724 (node) = symtab->next_variable ((node)))
66058468 2725
d6d229c6 2726/* Return first static variable with initializer. */
3dafb85c
ML
2727inline varpool_node *
2728symbol_table::first_static_initializer (void)
68e56cc4 2729{
5e20cdc9 2730 symtab_node *node;
3dafb85c 2731 for (node = nodes; node; node = node->next)
68e56cc4 2732 {
7de90a6c 2733 varpool_node *vnode = dyn_cast <varpool_node *> (node);
67348ccc 2734 if (vnode && DECL_INITIAL (node->decl))
5d59b5e1 2735 return vnode;
68e56cc4
JH
2736 }
2737 return NULL;
2738}
2739
d6d229c6 2740/* Return next static variable with initializer after NODE. */
3dafb85c
ML
2741inline varpool_node *
2742symbol_table::next_static_initializer (varpool_node *node)
68e56cc4 2743{
5e20cdc9 2744 symtab_node *node1 = node->next;
67348ccc 2745 for (; node1; node1 = node1->next)
68e56cc4 2746 {
7de90a6c 2747 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
67348ccc 2748 if (vnode1 && DECL_INITIAL (node1->decl))
5d59b5e1 2749 return vnode1;
68e56cc4
JH
2750 }
2751 return NULL;
2752}
2753
2754/* Walk all static variables with initializer set. */
2755#define FOR_EACH_STATIC_INITIALIZER(node) \
3dafb85c
ML
2756 for ((node) = symtab->first_static_initializer (); (node); \
2757 (node) = symtab->next_static_initializer (node))
2aae7680 2758
d6d229c6 2759/* Return first static variable with definition. */
3dafb85c
ML
2760inline varpool_node *
2761symbol_table::first_defined_variable (void)
2aae7680 2762{
5e20cdc9 2763 symtab_node *node;
3dafb85c 2764 for (node = nodes; node; node = node->next)
2aae7680 2765 {
7de90a6c 2766 varpool_node *vnode = dyn_cast <varpool_node *> (node);
67348ccc 2767 if (vnode && vnode->definition)
5d59b5e1 2768 return vnode;
2aae7680
JH
2769 }
2770 return NULL;
2771}
2772
d6d229c6 2773/* Return next static variable with definition after NODE. */
3dafb85c
ML
2774inline varpool_node *
2775symbol_table::next_defined_variable (varpool_node *node)
2aae7680 2776{
5e20cdc9 2777 symtab_node *node1 = node->next;
67348ccc 2778 for (; node1; node1 = node1->next)
2aae7680 2779 {
7de90a6c 2780 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
67348ccc 2781 if (vnode1 && vnode1->definition)
5d59b5e1 2782 return vnode1;
2aae7680
JH
2783 }
2784 return NULL;
2785}
65c70e6b
JH
2786/* Walk all variables with definitions in current unit. */
2787#define FOR_EACH_DEFINED_VARIABLE(node) \
3dafb85c
ML
2788 for ((node) = symtab->first_defined_variable (); (node); \
2789 (node) = symtab->next_defined_variable (node))
68e56cc4 2790
c47d0034 2791/* Return first function with body defined. */
3dafb85c
ML
2792inline cgraph_node *
2793symbol_table::first_defined_function (void)
c47d0034 2794{
5e20cdc9 2795 symtab_node *node;
3dafb85c 2796 for (node = nodes; node; node = node->next)
c47d0034 2797 {
7de90a6c 2798 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
67348ccc 2799 if (cn && cn->definition)
5d59b5e1 2800 return cn;
c47d0034
JH
2801 }
2802 return NULL;
2803}
2804
45896127 2805/* Return next function with body defined after NODE. */
3dafb85c
ML
2806inline cgraph_node *
2807symbol_table::next_defined_function (cgraph_node *node)
c47d0034 2808{
5e20cdc9 2809 symtab_node *node1 = node->next;
67348ccc 2810 for (; node1; node1 = node1->next)
c47d0034 2811 {
7de90a6c 2812 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
67348ccc 2813 if (cn1 && cn1->definition)
5d59b5e1 2814 return cn1;
c47d0034
JH
2815 }
2816 return NULL;
2817}
2818
2819/* Walk all functions with body defined. */
2820#define FOR_EACH_DEFINED_FUNCTION(node) \
3dafb85c
ML
2821 for ((node) = symtab->first_defined_function (); (node); \
2822 (node) = symtab->next_defined_function ((node)))
2aae7680
JH
2823
2824/* Return first function. */
3dafb85c
ML
2825inline cgraph_node *
2826symbol_table::first_function (void)
2aae7680 2827{
5e20cdc9 2828 symtab_node *node;
3dafb85c 2829 for (node = nodes; node; node = node->next)
7de90a6c 2830 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
5d59b5e1 2831 return cn;
2aae7680
JH
2832 return NULL;
2833}
2834
2835/* Return next function. */
3dafb85c
ML
2836inline cgraph_node *
2837symbol_table::next_function (cgraph_node *node)
2aae7680 2838{
5e20cdc9 2839 symtab_node *node1 = node->next;
67348ccc 2840 for (; node1; node1 = node1->next)
7de90a6c 2841 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
5d59b5e1 2842 return cn1;
2aae7680
JH
2843 return NULL;
2844}
c47d0034
JH
2845
2846/* Return first function with body defined. */
3dafb85c
ML
2847inline cgraph_node *
2848symbol_table::first_function_with_gimple_body (void)
c47d0034 2849{
5e20cdc9 2850 symtab_node *node;
3dafb85c 2851 for (node = nodes; node; node = node->next)
c47d0034 2852 {
7de90a6c 2853 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
d52f5295 2854 if (cn && cn->has_gimple_body_p ())
5d59b5e1 2855 return cn;
c47d0034
JH
2856 }
2857 return NULL;
2858}
2859
2860/* Return next reachable static variable with initializer after NODE. */
3dafb85c
ML
2861inline cgraph_node *
2862symbol_table::next_function_with_gimple_body (cgraph_node *node)
c47d0034 2863{
5e20cdc9 2864 symtab_node *node1 = node->next;
67348ccc 2865 for (; node1; node1 = node1->next)
c47d0034 2866 {
7de90a6c 2867 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
d52f5295 2868 if (cn1 && cn1->has_gimple_body_p ())
5d59b5e1 2869 return cn1;
c47d0034
JH
2870 }
2871 return NULL;
2872}
2873
3dafb85c
ML
2874/* Walk all functions. */
2875#define FOR_EACH_FUNCTION(node) \
2876 for ((node) = symtab->first_function (); (node); \
2877 (node) = symtab->next_function ((node)))
2878
2879/* Return true when callgraph node is a function with Gimple body defined
2880 in current unit. Functions can also be define externally or they
2881 can be thunks with no Gimple representation.
2882
2883 Note that at WPA stage, the function body may not be present in memory. */
2884
2885inline bool
2886cgraph_node::has_gimple_body_p (void)
2887{
2888 return definition && !thunk.thunk_p && !alias;
2889}
2890
c47d0034
JH
2891/* Walk all functions with body defined. */
2892#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
3dafb85c
ML
2893 for ((node) = symtab->first_function_with_gimple_body (); (node); \
2894 (node) = symtab->next_function_with_gimple_body (node))
c47d0034 2895
d48e9cea
OR
2896/* Uniquize all constants that appear in memory.
2897 Each constant in memory thus far output is recorded
2898 in `const_desc_table'. */
2899
2a22f99c 2900struct GTY((for_user)) constant_descriptor_tree {
d48e9cea
OR
2901 /* A MEM for the constant. */
2902 rtx rtl;
b8698a0f 2903
d48e9cea
OR
2904 /* The value of the constant. */
2905 tree value;
2906
2907 /* Hash of value. Computing the hash from value each time
2908 hashfn is called can't work properly, as that means recursive
2909 use of the hash table during hash table expansion. */
2910 hashval_t hash;
2911};
2912
d52f5295 2913/* Return true when function is only called directly or it has alias.
b20996ff
JH
2914 i.e. it is not externally visible, address was not taken and
2915 it is not used in any other non-standard way. */
2916
d52f5295
ML
2917inline bool
2918cgraph_node::only_called_directly_or_aliased_p (void)
2919{
2920 gcc_assert (!global.inlined_to);
2921 return (!force_output && !address_taken
aab778d3 2922 && !ifunc_resolver
d52f5295
ML
2923 && !used_from_other_partition
2924 && !DECL_VIRTUAL_P (decl)
2925 && !DECL_STATIC_CONSTRUCTOR (decl)
2926 && !DECL_STATIC_DESTRUCTOR (decl)
a6a543bf 2927 && !used_from_object_file_p ()
d52f5295 2928 && !externally_visible);
b20996ff
JH
2929}
2930
31de7606
JH
2931/* Return true when function can be removed from callgraph
2932 if all direct calls are eliminated. */
2933
2934inline bool
2935cgraph_node::can_remove_if_no_direct_calls_and_refs_p (void)
2936{
2937 gcc_checking_assert (!global.inlined_to);
31de7606
JH
2938 /* Extern inlines can always go, we will use the external definition. */
2939 if (DECL_EXTERNAL (decl))
2940 return true;
67914693 2941 /* When function is needed, we cannot remove it. */
31de7606
JH
2942 if (force_output || used_from_other_partition)
2943 return false;
2944 if (DECL_STATIC_CONSTRUCTOR (decl)
2945 || DECL_STATIC_DESTRUCTOR (decl))
2946 return false;
2947 /* Only COMDAT functions can be removed if externally visible. */
2948 if (externally_visible
2949 && (!DECL_COMDAT (decl)
2950 || forced_by_abi
2951 || used_from_object_file_p ()))
2952 return false;
2953 return true;
2954}
2955
b2b29377
MM
2956/* Verify cgraph, if consistency checking is enabled. */
2957
2958inline void
2959cgraph_node::checking_verify_cgraph_nodes (void)
2960{
2961 if (flag_checking)
2962 cgraph_node::verify_cgraph_nodes ();
2963}
2964
9041d2e6 2965/* Return true when variable can be removed from variable pool
df7705b1
JH
2966 if all direct calls are eliminated. */
2967
9041d2e6
ML
2968inline bool
2969varpool_node::can_remove_if_no_refs_p (void)
df7705b1 2970{
9041d2e6 2971 if (DECL_EXTERNAL (decl))
6649df51 2972 return true;
9041d2e6
ML
2973 return (!force_output && !used_from_other_partition
2974 && ((DECL_COMDAT (decl)
2975 && !forced_by_abi
2976 && !used_from_object_file_p ())
2977 || !externally_visible
2978 || DECL_HAS_VALUE_EXPR_P (decl)));
df7705b1
JH
2979}
2980
9041d2e6 2981/* Return true when all references to variable must be visible in ipa_ref_list.
4a444e58
JH
2982 i.e. if the variable is not externally visible or not used in some magic
2983 way (asm statement or such).
61502ca8 2984 The magic uses are all summarized in force_output flag. */
4a444e58 2985
9041d2e6
ML
2986inline bool
2987varpool_node::all_refs_explicit_p ()
4a444e58 2988{
9041d2e6
ML
2989 return (definition
2990 && !externally_visible
2991 && !used_from_other_partition
2992 && !force_output);
4a444e58
JH
2993}
2994
ca752f39 2995struct tree_descriptor_hasher : ggc_ptr_hash<constant_descriptor_tree>
2a22f99c
TS
2996{
2997 static hashval_t hash (constant_descriptor_tree *);
2998 static bool equal (constant_descriptor_tree *, constant_descriptor_tree *);
2999};
3000
d48e9cea 3001/* Constant pool accessor function. */
2a22f99c 3002hash_table<tree_descriptor_hasher> *constant_pool_htab (void);
fed5ae11 3003
d52f5295 3004/* Return node that alias is aliasing. */
39e2db00 3005
d52f5295
ML
3006inline cgraph_node *
3007cgraph_node::get_alias_target (void)
cd35bcf7 3008{
d52f5295 3009 return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ());
cd35bcf7
JH
3010}
3011
9041d2e6
ML
3012/* Return node that alias is aliasing. */
3013
3014inline varpool_node *
3015varpool_node::get_alias_target (void)
be330ed4 3016{
9041d2e6 3017 return dyn_cast <varpool_node *> (symtab_node::get_alias_target ());
be330ed4
JH
3018}
3019
31de7606
JH
3020/* Walk the alias chain to return the symbol NODE is alias of.
3021 If NODE is not an alias, return NODE.
f13fe18b
JH
3022 When AVAILABILITY is non-NULL, get minimal availability in the chain.
3023 When REF is non-NULL, assume that reference happens in symbol REF
3024 when determining the availability. */
31de7606
JH
3025
3026inline symtab_node *
f13fe18b
JH
3027symtab_node::ultimate_alias_target (enum availability *availability,
3028 symtab_node *ref)
31de7606
JH
3029{
3030 if (!alias)
3031 {
3032 if (availability)
f13fe18b 3033 *availability = get_availability (ref);
31de7606
JH
3034 return this;
3035 }
3036
f13fe18b 3037 return ultimate_alias_target_1 (availability, ref);
31de7606
JH
3038}
3039
d52f5295
ML
3040/* Given function symbol, walk the alias chain to return the function node
3041 is alias of. Do not walk through thunks.
f13fe18b
JH
3042 When AVAILABILITY is non-NULL, get minimal availability in the chain.
3043 When REF is non-NULL, assume that reference happens in symbol REF
3044 when determining the availability. */
be330ed4 3045
d52f5295 3046inline cgraph_node *
f13fe18b
JH
3047cgraph_node::ultimate_alias_target (enum availability *availability,
3048 symtab_node *ref)
be330ed4 3049{
31de7606 3050 cgraph_node *n = dyn_cast <cgraph_node *>
f13fe18b 3051 (symtab_node::ultimate_alias_target (availability, ref));
40a7fe1e 3052 if (!n && availability)
39e2db00 3053 *availability = AVAIL_NOT_AVAILABLE;
e70670cf 3054 return n;
be330ed4 3055}
9041d2e6
ML
3056
3057/* For given variable pool node, walk the alias chain to return the function
3058 the variable is alias of. Do not walk through thunks.
f13fe18b
JH
3059 When AVAILABILITY is non-NULL, get minimal availability in the chain.
3060 When REF is non-NULL, assume that reference happens in symbol REF
3061 when determining the availability. */
cd35bcf7 3062
9041d2e6 3063inline varpool_node *
f13fe18b
JH
3064varpool_node::ultimate_alias_target (availability *availability,
3065 symtab_node *ref)
cd35bcf7 3066{
9041d2e6 3067 varpool_node *n = dyn_cast <varpool_node *>
f13fe18b 3068 (symtab_node::ultimate_alias_target (availability, ref));
ff36fcbe 3069
40a7fe1e 3070 if (!n && availability)
cd35bcf7 3071 *availability = AVAIL_NOT_AVAILABLE;
e70670cf 3072 return n;
cd35bcf7
JH
3073}
3074
90988f77
ML
3075/* Set callee N of call graph edge and add it to the corresponding set of
3076 callers. */
3077
3078inline void
3079cgraph_edge::set_callee (cgraph_node *n)
3080{
3081 prev_caller = NULL;
3082 if (n->callers)
3083 n->callers->prev_caller = this;
3084 next_caller = n->callers;
3085 n->callers = this;
3086 callee = n;
3087}
3088
3089/* Redirect callee of the edge to N. The function does not update underlying
3090 call expression. */
3091
3092inline void
3093cgraph_edge::redirect_callee (cgraph_node *n)
3094{
3095 /* Remove from callers list of the current callee. */
3096 remove_callee ();
3097
3098 /* Insert to callers list of the new callee. */
3099 set_callee (n);
3100}
3101
3dafb85c 3102/* Return true when the edge represents a direct recursion. */
31de7606 3103
3dafb85c
ML
3104inline bool
3105cgraph_edge::recursive_p (void)
d7d1d041 3106{
3dafb85c
ML
3107 cgraph_node *c = callee->ultimate_alias_target ();
3108 if (caller->global.inlined_to)
3109 return caller->global.inlined_to->decl == c->decl;
d7d1d041 3110 else
3dafb85c 3111 return caller->decl == c->decl;
d7d1d041 3112}
0a35513e 3113
90988f77
ML
3114/* Remove the edge from the list of the callers of the callee. */
3115
3116inline void
3117cgraph_edge::remove_callee (void)
3118{
3119 gcc_assert (!indirect_unknown_callee);
3120 if (prev_caller)
3121 prev_caller->next_caller = next_caller;
3122 if (next_caller)
3123 next_caller->prev_caller = prev_caller;
3124 if (!prev_caller)
3125 callee->callers = next_caller;
3126}
3127
f13fe18b
JH
3128/* Return true if call must bind to current definition. */
3129
3130inline bool
3131cgraph_edge::binds_to_current_def_p ()
3132{
3133 if (callee)
3134 return callee->binds_to_current_def_p (caller);
3135 else
aff98801 3136 return false;
f13fe18b
JH
3137}
3138
1bad9c18
JH
3139/* Expected frequency of executions within the function.
3140 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
3141 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
3142
3143inline int
3144cgraph_edge::frequency ()
3145{
3146 return count.to_cgraph_frequency (caller->global.inlined_to
3147 ? caller->global.inlined_to->count
3148 : caller->count);
3149}
3150
41f0e819 3151
0a35513e
AH
3152/* Return true if the TM_CLONE bit is set for a given FNDECL. */
3153static inline bool
3154decl_is_tm_clone (const_tree fndecl)
3155{
d52f5295 3156 cgraph_node *n = cgraph_node::get (fndecl);
0a35513e
AH
3157 if (n)
3158 return n->tm_clone;
3159 return false;
3160}
9c8305f8
JH
3161
3162/* Likewise indicate that a node is needed, i.e. reachable via some
3163 external means. */
3164
d52f5295
ML
3165inline void
3166cgraph_node::mark_force_output (void)
1f26ac87 3167{
d52f5295
ML
3168 force_output = 1;
3169 gcc_checking_assert (!global.inlined_to);
1f26ac87
JM
3170}
3171
893479de
AM
3172/* Return true if function should be optimized for size. */
3173
3174inline bool
3175cgraph_node::optimize_for_size_p (void)
3176{
b065b669 3177 if (opt_for_fn (decl, optimize_size))
893479de
AM
3178 return true;
3179 if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
3180 return true;
3181 else
3182 return false;
3183}
3184
31de7606
JH
3185/* Return symtab_node for NODE or create one if it is not present
3186 in symtab. */
3187
3188inline symtab_node *
3189symtab_node::get_create (tree node)
f7217cde
JH
3190{
3191 if (TREE_CODE (node) == VAR_DECL)
3192 return varpool_node::get_create (node);
3193 else
3194 return cgraph_node::get_create (node);
3195}
3196
f13fe18b 3197/* Return availability of NODE when referenced from REF. */
31de7606
JH
3198
3199inline enum availability
f13fe18b 3200symtab_node::get_availability (symtab_node *ref)
31de7606
JH
3201{
3202 if (is_a <cgraph_node *> (this))
f13fe18b 3203 return dyn_cast <cgraph_node *> (this)->get_availability (ref);
31de7606 3204 else
f13fe18b 3205 return dyn_cast <varpool_node *> (this)->get_availability (ref);
31de7606
JH
3206}
3207
3208/* Call calback on symtab node and aliases associated to this node.
6b715bf6 3209 When INCLUDE_OVERWRITABLE is false, overwritable symbols are skipped. */
31de7606
JH
3210
3211inline bool
3212symtab_node::call_for_symbol_and_aliases (bool (*callback) (symtab_node *,
3213 void *),
3214 void *data,
3215 bool include_overwritable)
3216{
6b715bf6
JH
3217 if (include_overwritable
3218 || get_availability () > AVAIL_INTERPOSABLE)
3219 {
3220 if (callback (this, data))
3221 return true;
3222 }
190bbd0b 3223 if (has_aliases_p ())
31de7606
JH
3224 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
3225 return false;
3226}
3227
3228/* Call callback on function and aliases associated to the function.
6b715bf6 3229 When INCLUDE_OVERWRITABLE is false, overwritable symbols are
31de7606
JH
3230 skipped. */
3231
3232inline bool
3233cgraph_node::call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
3234 void *),
3235 void *data,
3236 bool include_overwritable)
3237{
6b715bf6
JH
3238 if (include_overwritable
3239 || get_availability () > AVAIL_INTERPOSABLE)
3240 {
3241 if (callback (this, data))
3242 return true;
3243 }
190bbd0b 3244 if (has_aliases_p ())
31de7606 3245 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
31de7606
JH
3246 return false;
3247}
3248
3249/* Call calback on varpool symbol and aliases associated to varpool symbol.
6b715bf6 3250 When INCLUDE_OVERWRITABLE is false, overwritable symbols are
31de7606
JH
3251 skipped. */
3252
3253inline bool
3254varpool_node::call_for_symbol_and_aliases (bool (*callback) (varpool_node *,
3255 void *),
3256 void *data,
3257 bool include_overwritable)
3258{
6b715bf6
JH
3259 if (include_overwritable
3260 || get_availability () > AVAIL_INTERPOSABLE)
3261 {
3262 if (callback (this, data))
3263 return true;
3264 }
190bbd0b 3265 if (has_aliases_p ())
31de7606 3266 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
31de7606
JH
3267 return false;
3268}
3269
0a7246ee
JH
3270/* Return true if refernece may be used in address compare. */
3271
3272inline bool
3273ipa_ref::address_matters_p ()
3274{
3275 if (use != IPA_REF_ADDR)
3276 return false;
3277 /* Addresses taken from virtual tables are never compared. */
3278 if (is_a <varpool_node *> (referring)
3279 && DECL_VIRTUAL_P (referring->decl))
3280 return false;
3281 return referred->address_can_be_compared_p ();
3282}
3283
ba392339
JH
3284/* Build polymorphic call context for indirect call E. */
3285
3286inline
3287ipa_polymorphic_call_context::ipa_polymorphic_call_context (cgraph_edge *e)
3288{
3289 gcc_checking_assert (e->indirect_info->polymorphic);
3290 *this = e->indirect_info->context;
3291}
3292
3293/* Build empty "I know nothing" context. */
3294
3295inline
3296ipa_polymorphic_call_context::ipa_polymorphic_call_context ()
3297{
3298 clear_speculation ();
3299 clear_outer_type ();
3300 invalid = false;
3301}
3302
3303/* Make context non-speculative. */
3304
3305inline void
3306ipa_polymorphic_call_context::clear_speculation ()
3307{
3308 speculative_outer_type = NULL;
3309 speculative_offset = 0;
3310 speculative_maybe_derived_type = false;
3311}
3312
6ff65dd7
MJ
3313/* Produce context specifying all derrived types of OTR_TYPE. If OTR_TYPE is
3314 NULL, the context is set to dummy "I know nothing" setting. */
ba392339
JH
3315
3316inline void
3317ipa_polymorphic_call_context::clear_outer_type (tree otr_type)
3318{
3319 outer_type = otr_type ? TYPE_MAIN_VARIANT (otr_type) : NULL;
3320 offset = 0;
3321 maybe_derived_type = true;
3322 maybe_in_construction = true;
4081ada2 3323 dynamic = true;
ba392339 3324}
67a1b94c
JH
3325
3326/* Adjust all offsets in contexts by OFF bits. */
3327
3328inline void
3329ipa_polymorphic_call_context::offset_by (HOST_WIDE_INT off)
3330{
3331 if (outer_type)
3332 offset += off;
3333 if (speculative_outer_type)
3334 speculative_offset += off;
3335}
3336
3337/* Return TRUE if context is fully useless. */
3338
3339inline bool
3340ipa_polymorphic_call_context::useless_p () const
3341{
3342 return (!outer_type && !speculative_outer_type);
3343}
d5e254e1 3344
2a72a953
DM
3345/* When using fprintf (or similar), problems can arise with
3346 transient generated strings. Many string-generation APIs
3347 only support one result being alive at once (e.g. by
3348 returning a pointer to a statically-allocated buffer).
3349
3350 If there is more than one generated string within one
3351 fprintf call: the first string gets evicted or overwritten
3352 by the second, before fprintf is fully evaluated.
3353 See e.g. PR/53136.
3354
3355 This function provides a workaround for this, by providing
3356 a simple way to create copies of these transient strings,
3357 without the need to have explicit cleanup:
3358
3359 fprintf (dumpfile, "string 1: %s string 2:%s\n",
3360 xstrdup_for_dump (EXPR_1),
3361 xstrdup_for_dump (EXPR_2));
3362
3363 This is actually a simple wrapper around ggc_strdup, but
3364 the name documents the intent. We require that no GC can occur
3365 within the fprintf call. */
3366
3367static inline const char *
3368xstrdup_for_dump (const char *transient_str)
3369{
3370 return ggc_strdup (transient_str);
3371}
3372
f714ecf5
JH
3373/* During LTO stream-in this predicate can be used to check whether node
3374 in question prevails in the linking to save some memory usage. */
3375inline bool
3376symtab_node::prevailing_p (void)
3377{
3378 return definition && ((!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
3379 || previous_sharing_asm_name == NULL);
3380}
3381
212755ff
DM
3382extern GTY(()) symbol_table *saved_symtab;
3383
3384#if CHECKING_P
3385
3386namespace selftest {
3387
3388/* An RAII-style class for use in selftests for temporarily using a different
3389 symbol_table, so that such tests can be isolated from each other. */
3390
3391class symbol_table_test
3392{
3393 public:
3394 /* Constructor. Override "symtab". */
3395 symbol_table_test ();
3396
3397 /* Destructor. Restore the saved_symtab. */
3398 ~symbol_table_test ();
3399};
3400
3401} // namespace selftest
3402
3403#endif /* CHECKING_P */
3404
1c4a429a 3405#endif /* GCC_CGRAPH_H */