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