]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cgraph.h
* constexpr.c (cxx_eval_store_expression): Formatting fix. Handle
[thirdparty/gcc.git] / gcc / cgraph.h
CommitLineData
ae01b312 1/* Callgraph handling code.
fbd26352 2 Copyright (C) 2003-2019 Free Software Foundation, Inc.
ae01b312 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
8c4c00c1 9Software Foundation; either version 3, or (at your option) any later
ae01b312 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
8c4c00c1 18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
ae01b312 20
21#ifndef GCC_CGRAPH_H
22#define GCC_CGRAPH_H
0f71a633 23
db9cef39 24#include "profile-count.h"
ec2e0095 25#include "ipa-ref.h"
26#include "plugin-api.h"
40d8e161 27#include "ipa-param-manipulation.h"
ec2e0095 28
36a03e27 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
ec2e0095 37class ipa_opt_pass_d;
38typedef ipa_opt_pass_d *ipa_opt_pass;
b6c89d32 39
40/* Symbol table consists of functions and variables.
15ca8f90 41 TODO: add labels and CONST_DECLs. */
b6c89d32 42enum symtab_type
43{
7d0d0ce1 44 SYMTAB_SYMBOL,
b6c89d32 45 SYMTAB_FUNCTION,
46 SYMTAB_VARIABLE
47};
48
738a6bda 49/* Section names are stored as reference counted strings in GGC safe hashtable
50 (to make them survive through PCH). */
51
df8eb490 52struct GTY((for_user)) section_hash_entry
738a6bda 53{
54 int ref_count;
f4d3c071 55 char *name; /* As long as this datastructure stays in GGC, we cannot put
738a6bda 56 string at the tail of structure of GGC dies in horrible
57 way */
58};
59
b594087e 60struct section_name_hasher : ggc_ptr_hash<section_hash_entry>
2ef51f0e 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
415d1b9a 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
b6c89d32 102/* Base of all entries in the symbol table.
103 The symtab_node is inherited by cgraph and varpol nodes. */
251317e4 104struct GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
105 chain_next ("%h.next"), chain_prev ("%h.previous")))
452659af 106 symtab_node
b6c89d32 107{
2043dfcc 108public:
2c8bbd94 109 friend class symbol_table;
110
f1c8b4d7 111 /* Return name. */
112 const char *name () const;
113
0e388735 114 /* Return dump name. */
115 const char *dump_name () const;
116
f1c8b4d7 117 /* Return asm name. */
0e388735 118 const char *asm_name () const;
119
120 /* Return dump name with assembler name. */
121 const char *dump_asm_name () const;
f1c8b4d7 122
b340d73f 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
415d1b9a 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
4f6144ba 139 /* Dump symtab callgraph in graphviz format. */
140 void dump_graphviz (FILE *f);
141
415d1b9a 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). */
35ee1c66 151 ipa_ref *create_reference (symtab_node *referred_node,
152 enum ipa_ref_use use_type);
415d1b9a 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). */
35ee1c66 157 ipa_ref *create_reference (symtab_node *referred_node,
42acab1c 158 enum ipa_ref_use use_type, gimple *stmt);
415d1b9a 159
160 /* If VAL is a reference to a function or a variable, add a reference from
7dab0c61 161 this symtab_node to the corresponding symbol table node. Return the new
415d1b9a 162 reference or NULL if none was created. */
7dab0c61 163 ipa_ref *maybe_create_reference (tree val, gimple *stmt);
415d1b9a 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. */
42acab1c 175 ipa_ref *clone_reference (ipa_ref *ref, gimple *stmt);
415d1b9a 176
177 /* Find the structure describing a reference to REFERRED_NODE
178 and associated with statement STMT. */
42acab1c 179 ipa_ref *find_reference (symtab_node *referred_node, gimple *stmt,
35ee1c66 180 unsigned int lto_stmt_uid);
415d1b9a 181
182 /* Remove all references that are associated with statement STMT. */
42acab1c 183 void remove_stmt_references (gimple *stmt);
415d1b9a 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
52200d03 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
415d1b9a 209 /* Iterates I-th reference in the list, REF is also set. */
35ee1c66 210 ipa_ref *iterate_reference (unsigned i, ipa_ref *&ref);
415d1b9a 211
212 /* Iterates I-th referring item in the list, REF is also set. */
35ee1c66 213 ipa_ref *iterate_referring (unsigned i, ipa_ref *&ref);
415d1b9a 214
215 /* Iterates I-th referring alias item in the list, REF is also set. */
35ee1c66 216 ipa_ref *iterate_direct_aliases (unsigned i, ipa_ref *&ref);
415d1b9a 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.
2f7867dc 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);
415d1b9a 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.
e0dec29d 280 If TRANSPARENT is true make the alias to be transparent alias.
415d1b9a 281 The function can fail in the case of aliasing cycles; in this case
282 it returns false. */
e0dec29d 283 bool resolve_alias (symtab_node *target, bool transparent = false);
415d1b9a 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
cfd85d03 289 /* Call callback on symtab node and aliases associated to this node.
415d1b9a 290 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
cfd85d03 291 skipped. */
415d1b9a 292 bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *),
e88fecaf 293 void *data,
294 bool include_overwrite);
415d1b9a 295
f4d3c071 296 /* If node cannot be interposable by static or dynamic linker to point to
415d1b9a 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
2f7867dc 318 /* Return availability of NODE when referenced from REF. */
319 enum availability get_availability (symtab_node *ref = NULL);
320
42157758 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
2f7867dc 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);
415d1b9a 329
330 /* Make DECL local. */
331 void make_decl_local (void);
332
9b0e5d40 333 /* Copy visibility from N. */
334 void copy_visibility_from (symtab_node *n);
335
331d5983 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
415d1b9a 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
fa30257b 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
35ee1c66 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
175e0d6b 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
35ee1c66 367 /* Return true when there are references to the node. */
3a1c9df2 368 bool referred_to_p (bool include_self = true);
35ee1c66 369
c7549d13 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. */
415d1b9a 376 inline bool
377 can_be_discarded_p (void)
378 {
379 return (DECL_EXTERNAL (decl)
c7549d13 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));
415d1b9a 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
415d1b9a 400 /* Return true if symbol is known to be nonzero. */
401 bool nonzero_address ();
402
c11b875d 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,
f5d3c0a6 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);
c11b875d 412
ce7711df 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
415d1b9a 422 /* Return symbol table node associated with DECL, if any,
423 and NULL otherwise. */
424 static inline symtab_node *get (const_tree decl)
425 {
415d1b9a 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);
415d1b9a 437 return decl->decl_with_vis.symtab_node;
438 }
439
8e857c41 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
35ee1c66 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
415d1b9a 448 /* Verify symbol table for internal consistency. */
449 static DEBUG_FUNCTION void verify_symtab_nodes (void);
450
382ecba7 451 /* Perform internal consistency checks, if they are enabled. */
452 static inline void checking_verify_symtab_nodes (void);
453
b6c89d32 454 /* Type of the symbol. */
a83af0c5 455 ENUM_BITFIELD (symtab_type) type : 8;
456
457 /* The symbols resolution. */
458 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
459
15ca8f90 460 /*** Flags representing the symbol type. ***/
461
462 /* True when symbol corresponds to a definition in current unit.
35ee1c66 463 set via finalize_function or finalize_decl */
15ca8f90 464 unsigned definition : 1;
97221fd7 465 /* True when symbol is an alias.
466 Set by ssemble_alias. */
15ca8f90 467 unsigned alias : 1;
e0dec29d 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;
f2526cce 490 /* True when alias is a weakref. */
491 unsigned weakref : 1;
48669653 492 /* C++ frontend produce same body aliases and extra name aliases for
a04e8d62 493 virtual functions and vtables that are obviously equivalent.
48669653 494 Those aliases are bit special, especially because C++ frontend
f4d3c071 495 visibility code is so ugly it cannot get them right at first time
48669653 496 and their visibility needs to be copied from their "masters" at
497 the end of parsing. */
498 unsigned cpp_implicit_alias : 1;
15ca8f90 499 /* Set once the definition was analyzed. The list of references and
500 other properties are built during analysis. */
501 unsigned analyzed : 1;
703ad42c 502 /* Set for write-only variables. */
503 unsigned writeonly : 1;
8e857c41 504 /* Visibility of symbol was used for further optimization; do not
505 permit further changes. */
506 unsigned refuse_visibility_changes : 1;
15ca8f90 507
508 /*** Visibility and linkage flags. ***/
509
a83af0c5 510 /* Set when function is visible by other units. */
511 unsigned externally_visible : 1;
6b722052 512 /* Don't reorder to other symbols having this set. */
513 unsigned no_reorder : 1;
bce6ce2d 514 /* The symbol will be assumed to be used in an invisible way (like
6a1c0403 515 by an toplevel asm statement). */
a83af0c5 516 unsigned force_output : 1;
6a1c0403 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;
5c368d8a 521 /* True when the name is known to be unique and thus it does not need mangling. */
522 unsigned unique_name : 1;
e4c07a06 523 /* Specify whether the section was set by user or by
524 compiler via -ffunction-sections. */
525 unsigned implicit_section : 1;
fa4052b3 526 /* True when body and other characteristics have been removed by
527 symtab_remove_unreachable_nodes. */
528 unsigned body_removed : 1;
a83af0c5 529
15ca8f90 530 /*** WHOPR Partitioning flags.
531 These flags are used at ltrans stage when only part of the callgraph is
532 available. ***/
a83af0c5 533
15ca8f90 534 /* Set when variable is used from other LTRANS partition. */
535 unsigned used_from_other_partition : 1;
97221fd7 536 /* Set when function is available in the other LTRANS partition.
15ca8f90 537 During WPA output it is used to mark nodes that are present in
538 multiple partitions. */
539 unsigned in_other_partition : 1;
a83af0c5 540
a83af0c5 541
15ca8f90 542
543 /*** other flags. ***/
544
545 /* Set when symbol has address taken. */
546 unsigned address_taken : 1;
9db80d42 547 /* Set when init priority is set. */
548 unsigned in_init_priority_hash : 1;
15ca8f90 549
b0c5e347 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
b859b598 557 /* Set when symbol is an IFUNC resolver. */
558 unsigned ifunc_resolver : 1;
559
15ca8f90 560
561 /* Ordering of all symtab entries. */
562 int order;
563
564 /* Declaration representing the symbol. */
565 tree decl;
7d0d0ce1 566
0704fb2e 567 /* Linked list of symbol table entries starting with symtab_nodes. */
452659af 568 symtab_node *next;
569 symtab_node *previous;
15ca8f90 570
cfbe30aa 571 /* Linked list of symbols with the same asm name. There may be multiple
15ca8f90 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. */
452659af 580 symtab_node *next_sharing_asm_name;
581 symtab_node *previous_sharing_asm_name;
0704fb2e 582
415d1b9a 583 /* Circular list of nodes in the same comdat group if non-NULL. */
584 symtab_node *same_comdat_group;
e4a2b488 585
15ca8f90 586 /* Vectors of referring and referenced entities. */
35ee1c66 587 ipa_ref_list ref_list;
15ca8f90 588
48669653 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
15ca8f90 594 /* File stream where this node is being written to. */
595 struct lto_file_decl_data * lto_file_data;
596
7d0d0ce1 597 PTR GTY ((skip)) aux;
8c016392 598
599 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
738a6bda 600 tree x_comdat_group;
71e19e54 601
602 /* Section name. Again can be private, if allowed. */
738a6bda 603 section_hash_entry *x_section;
e4c07a06 604
415d1b9a 605protected:
606 /* Dump base fields of symtab nodes to F. Not to be used directly. */
607 void dump_base (FILE *);
9db80d42 608
415d1b9a 609 /* Verify common part of symtab node. */
610 bool DEBUG_FUNCTION verify_base (void);
56ac70ed 611
415d1b9a 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
50f2a18b 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);
415d1b9a 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);
50f2a18b 634
635 /* Worker for ultimate_alias_target. */
2f7867dc 636 symtab_node *ultimate_alias_target_1 (enum availability *avail = NULL,
637 symtab_node *ref = NULL);
0e388735 638
639 /* Get dump name with normal or assembly name. */
640 const char *get_dump_name (bool asm_name_p) const;
b6c89d32 641};
ae01b312 642
382ecba7 643inline void
644symtab_node::checking_verify_symtab_nodes (void)
645{
646 if (flag_checking)
647 symtab_node::verify_symtab_nodes ();
648}
649
e4a2b488 650/* Walk all aliases for NODE. */
651#define FOR_EACH_ALIAS(node, alias) \
415d1b9a 652 for (unsigned x_i = 0; node->iterate_direct_aliases (x_i, alias); x_i++)
e1be32b8 653
7bfefa9d 654/* This is the information that is put into the cgraph local structure
655 to recover a function. */
656struct lto_file_decl_data;
657
1d416bd7 658extern const char * const cgraph_availability_names[];
6e673e69 659extern const char * const ld_plugin_symbol_resolution_names[];
b7393cee 660extern const char * const tls_model_names[];
1d416bd7 661
0e3918d8 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. */
28454517 674
675struct GTY(()) cgraph_thunk_info {
0e3918d8 676 /* Offset used to adjust "this". */
28454517 677 HOST_WIDE_INT fixed_offset;
0e3918d8 678
679 /* Offset in the virtual table to get the offset to adjust "this". Valid iff
680 VIRTUAL_OFFSET_P is true. */
28454517 681 HOST_WIDE_INT virtual_value;
0e3918d8 682
4c7db812 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
0e3918d8 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. */
28454517 689 tree alias;
0e3918d8 690
691 /* Nonzero for a "this" adjusting thunk and zero for a result adjusting
692 thunk. */
28454517 693 bool this_adjusting;
0e3918d8 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
8acf51b5 699 * for result-adjusting thunks, the FIXED_OFFSET adjustment is done after
0e3918d8 700 the virtual one. */
28454517 701 bool virtual_offset_p;
0e3918d8 702
0e3918d8 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. */
28454517 705 bool thunk_p;
706};
707
80a85d8a 708/* Information about the function collected locally.
ec1e35b2 709 Available after function is analyzed. */
80a85d8a 710
fb1e4f4a 711struct GTY(()) cgraph_local_info {
47ae02b7 712 /* Set when function is visible in current compilation unit only and
713 its address is never taken. */
a16eb452 714 unsigned local : 1;
acc70efa 715
c8d92fc1 716 /* False when there is something makes versioning impossible. */
717 unsigned versionable : 1;
718
f4d3c071 719 /* False when function calling convention and signature cannot be changed.
3c97c75d 720 This is the case when __builtin_apply_args is used. */
721 unsigned can_change_signature : 1;
722
69435b7f 723 /* True when the function has been originally extern inline, but it is
724 redefined now. */
a16eb452 725 unsigned redefined_extern_inline : 1;
4c0315d0 726
727 /* True if the function may enter serial irrevocable mode. */
728 unsigned tm_may_enter_irr : 1;
80a85d8a 729};
730
731/* Information about the function that needs to be computed globally
75a70cf9 732 once compilation is finished. Available only with -funit-at-a-time. */
80a85d8a 733
fb1e4f4a 734struct GTY(()) cgraph_global_info {
75a70cf9 735 /* For inline clones this points to the function they will be
736 inlined into. */
415d1b9a 737 cgraph_node *inlined_to;
80a85d8a 738};
739
ccf4ab6b 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{
ccf4ab6b 744 /* The new (replacing) tree. */
745 tree new_tree;
1bf41320 746 /* Parameter number to replace, when old_tree is NULL. */
747 int parm_num;
ccf4ab6b 748};
ccf4ab6b 749
750struct GTY(()) cgraph_clone_info
751{
40d8e161 752 /* Constants discovered by IPA-CP, i.e. which parameter should be replaced
753 with what. */
415d1b9a 754 vec<ipa_replace_map *, va_gc> *tree_map;
40d8e161 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;
ccf4ab6b 769};
770
d09768a4 771enum cgraph_simd_clone_arg_type
772{
773 SIMD_CLONE_ARG_TYPE_VECTOR,
774 SIMD_CLONE_ARG_TYPE_UNIFORM,
43895be5 775 /* These are only for integer/pointer arguments passed by value. */
d09768a4 776 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
777 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
9561765e 778 /* These 6 are only for reference type arguments or arguments passed
43895be5 779 by reference. */
780 SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP,
9561765e 781 SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP,
43895be5 782 SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP,
9561765e 783 SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP,
43895be5 784 SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP,
9561765e 785 SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP,
d09768a4 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
43895be5 825 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_*CONSTANT_STEP this is
d09768a4 826 the constant linear step, if arg_type is
9561765e 827 SIMD_CLONE_ARG_TYPE_LINEAR_*VARIABLE_STEP, this is index of
d09768a4 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
a96a7710 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
47ae02b7 856 /* The mangling character for a given vector size. This is used
d09768a4 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
d09768a4 865 /* Doubly linked list of SIMD clones. */
415d1b9a 866 cgraph_node *prev_clone, *next_clone;
d09768a4 867
868 /* Original cgraph node the SIMD clones were created for. */
415d1b9a 869 cgraph_node *origin;
d09768a4 870
871 /* Annotated function arguments for the original function. */
35ee1c66 872 cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
d09768a4 873};
874
415d1b9a 875/* Function Multiversioning info. */
2ef51f0e 876struct GTY((for_user)) cgraph_function_version_info {
415d1b9a 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. */
35ee1c66 882 cgraph_function_version_info *prev;
415d1b9a 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. */
35ee1c66 886 cgraph_function_version_info *next;
415d1b9a 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;
125b6d78 914
b594087e 915struct cgraph_edge_hasher : ggc_ptr_hash<cgraph_edge>
2ef51f0e 916{
42acab1c 917 typedef gimple *compare_type;
2ef51f0e 918
919 static hashval_t hash (cgraph_edge *);
42acab1c 920 static hashval_t hash (gimple *);
921 static bool equal (cgraph_edge *, gimple *);
2ef51f0e 922};
923
c7bf1374 924/* The cgraph data structure.
d01481af 925 Each function decl has assigned cgraph_node listing callees and callers. */
ae01b312 926
2e966e2a 927struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node
251317e4 928{
2c8bbd94 929 friend class symbol_table;
930
415d1b9a 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. */
42acab1c 939 void record_stmt_references (gimple *stmt);
415d1b9a 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. */
42acab1c 946 void set_call_stmt_including_clones (gimple *old_stmt, gcall *new_stmt,
415d1b9a 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.
2f7867dc 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);
415d1b9a 956
cfd85d03 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.
2f7867dc 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. */
cfd85d03 963 cgraph_node *function_or_virtual_thunk_symbol
2f7867dc 964 (enum availability *avail = NULL,
965 struct symtab_node *ref = NULL);
cfd85d03 966
415d1b9a 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.
9dc70d59 981 Can be NULL if the node is not inlined. SUFFIX is string that is appended
982 to the original name. */
151b9ff5 983 cgraph_node *create_clone (tree decl, profile_count count,
415d1b9a 984 bool update_original,
985 vec<cgraph_edge *> redirect_callers,
986 bool call_duplication_hook,
35ee1c66 987 cgraph_node *new_inlined_to,
40d8e161 988 ipa_param_adjustments *param_adjustments,
989 const char *suffix = NULL);
415d1b9a 990
9175d3dd 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. */
415d1b9a 994 cgraph_node *create_virtual_clone (vec<cgraph_edge *> redirect_callers,
995 vec<ipa_replace_map *, va_gc> *tree_map,
40d8e161 996 ipa_param_adjustments *param_adjustments,
997 const char * suffix, unsigned num_suffix);
415d1b9a 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
9dc70d59 1012 in the clone.
1013
1014 SUFFIX is string that is appended to the original name. */
415d1b9a 1015
1016 cgraph_node *create_version_clone (tree new_decl,
1017 vec<cgraph_edge *> redirect_callers,
9dc70d59 1018 bitmap bbs_to_copy,
1019 const char *suffix = NULL);
415d1b9a 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
eba46615 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
415d1b9a 1043 Return the new version's cgraph node. */
1044 cgraph_node *create_version_clone_with_body
1045 (vec<cgraph_edge *> redirect_callers,
40d8e161 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);
415d1b9a 1050
1051 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
1052 corresponding to cgraph_node. */
35ee1c66 1053 cgraph_function_version_info *insert_new_function_version (void);
415d1b9a 1054
1055 /* Get the cgraph_function_version_info node corresponding to node. */
35ee1c66 1056 cgraph_function_version_info *function_version (void);
415d1b9a 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.
0e3918d8 1064 See comments in struct cgraph_thunk_info for detail on the parameters. */
415d1b9a 1065 cgraph_node * create_thunk (tree alias, tree, bool this_adjusting,
1066 HOST_WIDE_INT fixed_offset,
1067 HOST_WIDE_INT virtual_value,
4c7db812 1068 HOST_WIDE_INT indirect_offset,
415d1b9a 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.
2f7867dc 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. */
415d1b9a 1081
2f7867dc 1082 cgraph_node *ultimate_alias_target (availability *availability = NULL,
1083 symtab_node *ref = NULL);
415d1b9a 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
fe3c9f1e 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
35ee1c66 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
415d1b9a 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
4f6144ba 1123 /* Dump call graph node to file F. */
1124 void dump_graphviz (FILE *f);
1125
415d1b9a 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. */
4560777c 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. */
415d1b9a 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(). */
8e92a5ee 1142 void release_body (bool keep_arguments = false);
415d1b9a 1143
9d4a0f4b 1144 /* Return the DECL_STRUCT_FUNCTION of the function. */
332b7382 1145 struct function *get_fun () const;
9d4a0f4b 1146
415d1b9a 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. */
35ee1c66 1163 cgraph_edge *create_edge (cgraph_node *callee,
73b9626d 1164 gcall *call_stmt, profile_count count,
1165 bool cloning_p = false);
35ee1c66 1166
415d1b9a 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. */
1a91d914 1170 cgraph_edge *create_indirect_edge (gcall *call_stmt, int ecf_flags,
151b9ff5 1171 profile_count count,
73b9626d 1172 bool cloning_p = false);
415d1b9a 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. */
35ee1c66 1177 void create_edge_including_clones (cgraph_node *callee,
42acab1c 1178 gimple *old_stmt, gcall *stmt,
db9cef39 1179 profile_count count,
415d1b9a 1180 cgraph_inline_failed_t reason);
1181
1182 /* Return the callgraph edge representing the GIMPLE_CALL statement
1183 CALL_STMT. */
42acab1c 1184 cgraph_edge *get_edge (gimple *call_stmt);
415d1b9a 1185
1186 /* Collect all callers of cgraph_node and its aliases that are known to lead
f6bd593a 1187 to NODE (i.e. are not overwritable) and that are not thunks. */
415d1b9a 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. */
2f7867dc 1198 enum availability get_availability (symtab_node *ref = NULL);
415d1b9a 1199
1200 /* Set TREE_NOTHROW on cgraph_node's decl and on aliases of the node
1201 if any to NOTHROW. */
ace7bf06 1202 bool set_nothrow_flag (bool nothrow);
415d1b9a 1203
bd5ef087 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
530dc126 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);
415d1b9a 1218
1219 /* Set DECL_PURE_P on cgraph_node's decl and on aliases of the node
530dc126 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);
415d1b9a 1226
cfd85d03 1227 /* Call callback on function and aliases associated to the function.
415d1b9a 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
cfd85d03 1235 /* Call callback on cgraph_node, thunks and aliases associated to NODE.
415d1b9a 1236 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
cfd85d03 1237 skipped. When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
415d1b9a 1238 skipped. */
1239 bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node,
cfd85d03 1240 void *data),
1241 void *data,
1242 bool include_overwritable,
1243 bool exclude_virtual_thunks = false);
415d1b9a 1244
415d1b9a 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
f4d3c071 1258 /* Return true when cgraph_node cannot return or throw and thus
415d1b9a 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
b12b920e 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);
415d1b9a 1291
1292 /* Return true when function can be removed from callgraph
b12b920e 1293 if all direct calls and references are eliminated. The function does
1294 not take into account comdat groups. */
415d1b9a 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
b12b920e 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);
415d1b9a 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
e3e42b03 1310 /* Return true if this node represents a former, i.e. an expanded, thunk. */
1311 inline bool former_thunk_p (void);
1312
415d1b9a 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. */
35ee1c66 1320 static inline
1321 void debug_cgraph (void)
415d1b9a 1322 {
1323 dump_cgraph (stderr);
1324 }
1325
2c8bbd94 1326 /* Get unique identifier of the node. */
1327 inline int get_uid ()
1328 {
1329 return m_uid;
1330 }
1331
1add72d5 1332 /* Get summary id of the node. */
1333 inline int get_summary_id ()
1334 {
1335 return m_summary_id;
1336 }
1337
415d1b9a 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. */
a0ffb0fb 1344 static void delete_function_version_by_decl (tree decl);
415d1b9a 1345
1346 /* Add the function FNDECL to the call graph.
35ee1c66 1347 Unlike finalize_function, this function is intended to be used
415d1b9a 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
35ee1c66 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
415d1b9a 1372 /* Return cgraph node assigned to DECL. Create new one when needed. */
1373 static cgraph_node * create (tree decl);
1374
415d1b9a 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
35ee1c66 1379 /* Return local info for the compiled function. */
1380 static cgraph_local_info *local_info (tree decl);
1381
35ee1c66 1382 /* Return local info for the compiled function. */
2ec5d342 1383 static struct cgraph_rtl_info *rtl_info (const_tree);
35ee1c66 1384
415d1b9a 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
415d1b9a 1396 /* Verify whole cgraph structure. */
1397 static void DEBUG_FUNCTION verify_cgraph_nodes (void);
1398
382ecba7 1399 /* Verify cgraph, if consistency checking is enabled. */
1400 static inline void checking_verify_cgraph_nodes (void);
1401
415d1b9a 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
c1df982e 1410 /* Return true if NODE has thunk. */
1411 static bool has_thunk_p (cgraph_node *node, void *);
1412
35ee1c66 1413 cgraph_edge *callees;
1414 cgraph_edge *callers;
799c8711 1415 /* List of edges representing indirect calls with a yet undetermined
1416 callee. */
35ee1c66 1417 cgraph_edge *indirect_calls;
ae01b312 1418 /* For nested functions points to function the node is nested in. */
415d1b9a 1419 cgraph_node *origin;
ae01b312 1420 /* Points to first nested function, if any. */
415d1b9a 1421 cgraph_node *nested;
ae01b312 1422 /* Pointer to the next function with same origin, if any. */
415d1b9a 1423 cgraph_node *next_nested;
b0cdf642 1424 /* Pointer to the next clone. */
415d1b9a 1425 cgraph_node *next_sibling_clone;
1426 cgraph_node *prev_sibling_clone;
1427 cgraph_node *clones;
1428 cgraph_node *clone_of;
8df22c5c 1429 /* For functions with many calls sites it holds map from call expression
1430 to the edge to speed up cgraph_edge function. */
2ef51f0e 1431 hash_table<cgraph_edge_hasher> *GTY(()) call_site_hash;
b9ffeffb 1432 /* Declaration node used to be clone of. */
1433 tree former_clone_of;
a0c938f0 1434
d09768a4 1435 /* If this is a SIMD clone, this points to the SIMD specific
1436 information for it. */
35ee1c66 1437 cgraph_simd_clone *simdclone;
d09768a4 1438 /* If this function has SIMD clones, this points to the first clone. */
415d1b9a 1439 cgraph_node *simd_clones;
d09768a4 1440
6d1cc52c 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. */
f1f41a6c 1444 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
6d1cc52c 1445
35ee1c66 1446 cgraph_local_info local;
1447 cgraph_global_info global;
deb7cbe5 1448 struct cgraph_rtl_info *rtl;
35ee1c66 1449 cgraph_clone_info clone;
1450 cgraph_thunk_info thunk;
a0c938f0 1451
edc6a4c0 1452 /* Expected number of executions: calculated in profile.c. */
db9cef39 1453 profile_count count;
c470c5a9 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;
fe37be54 1457 /* ID assigned by the profiling. */
1458 unsigned int profile_id;
38fe12e3 1459 /* Time profiler: first run of function. */
1460 int tp_first_run;
9fac1c66 1461
d544ceff 1462 /* Set when decl is an abstract function pointed to by the
1463 ABSTRACT_DECL_ORIGIN of a reachable function. */
abb1a237 1464 unsigned used_as_abstract_origin : 1;
773c5ba7 1465 /* Set once the function is lowered (i.e. its CFG is built). */
a16eb452 1466 unsigned lowered : 1;
ec1e35b2 1467 /* Set once the function has been instantiated and its callee
1468 lists created. */
09fc9532 1469 unsigned process : 1;
125b6d78 1470 /* How commonly executed the node is. Initialized during branch
1471 probabilities pass. */
1472 ENUM_BITFIELD (node_frequency) frequency : 2;
0f9fb931 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;
4c0315d0 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;
cc8ef84f 1482 /* True if this decl is a dispatcher for function versions. */
1483 unsigned dispatcher_function : 1;
468088ac 1484 /* True if this decl calls a COMDAT-local function. This is set up in
1297cbcd 1485 compute_fn_summary and inline_call. */
468088ac 1486 unsigned calls_comdat_local : 1;
52200d03 1487 /* True if node has been created by merge operation in IPA-ICF. */
1488 unsigned icf_merged: 1;
04c849b3 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;
57e20c4a 1493 /* True if there was multiple COMDAT bodies merged by lto-symtab. */
7d38b7bc 1494 unsigned merged_comdat : 1;
66460ec1 1495 /* True if function was created to be executed in parallel. */
1496 unsigned parallelized_function : 1;
71e37927 1497 /* True if function is part split out by ipa-split. */
1498 unsigned split_part : 1;
75e72311 1499 /* True if the function appears as possible target of indirect call. */
1500 unsigned indirect_call_target : 1;
50f2a18b 1501
1502private:
2c8bbd94 1503 /* Unique id of the node. */
1504 int m_uid;
1505
1add72d5 1506 /* Summary id that is recycled. */
1507 int m_summary_id;
1508
50f2a18b 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);
cc8ef84f 1513};
1514
13f90d63 1515/* A cgraph node set is a collection of cgraph nodes. A cgraph node
1516 can appear in multiple sets. */
19ad01f7 1517struct cgraph_node_set_def
13f90d63 1518{
06ecf488 1519 hash_map<cgraph_node *, size_t> *map;
415d1b9a 1520 vec<cgraph_node *> nodes;
13f90d63 1521};
1522
415d1b9a 1523typedef cgraph_node_set_def *cgraph_node_set;
1524typedef struct varpool_node_set_def *varpool_node_set;
0cddb138 1525
2e966e2a 1526struct varpool_node;
0cddb138 1527
1528/* A varpool node set is a collection of varpool nodes. A varpool node
1529 can appear in multiple sets. */
19ad01f7 1530struct varpool_node_set_def
0cddb138 1531{
06ecf488 1532 hash_map<varpool_node *, size_t> * map;
415d1b9a 1533 vec<varpool_node *> nodes;
0cddb138 1534};
1535
13f90d63 1536/* Iterator structure for cgraph node sets. */
b3e7c666 1537struct cgraph_node_set_iterator
13f90d63 1538{
1539 cgraph_node_set set;
1540 unsigned index;
b3e7c666 1541};
13f90d63 1542
0cddb138 1543/* Iterator structure for varpool node sets. */
b3e7c666 1544struct varpool_node_set_iterator
0cddb138 1545{
1546 varpool_node_set set;
1547 unsigned index;
b3e7c666 1548};
0cddb138 1549
e33892d7 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. */
c500eb01 1564 unsigned maybe_in_construction : 1;
e33892d7 1565 /* True if outer object may be of derived type. */
c500eb01 1566 unsigned maybe_derived_type : 1;
e33892d7 1567 /* True if speculative outer object may be of derived type. We always
1568 speculate that construction does not happen. */
c500eb01 1569 unsigned speculative_maybe_derived_type : 1;
e33892d7 1570 /* True if the context is invalid and all calls should be redirected
1571 to BUILTIN_UNREACHABLE. */
c500eb01 1572 unsigned invalid : 1;
1573 /* True if the outer type is dynamic. */
1574 unsigned dynamic : 1;
e33892d7 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. */
42acab1c 1588 ipa_polymorphic_call_context (tree fndecl, tree ref, gimple *stmt,
e33892d7 1589 tree *instance = NULL);
1590
1591 /* Look for vtable stores or constructor calls to work out dynamic type
1592 of memory location. */
915df3d8 1593 bool get_dynamic_type (tree, tree, tree, gimple *, unsigned *);
e33892d7 1594
1595 /* Make context non-speculative. */
1596 void clear_speculation ();
1597
dfb61776 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
e33892d7 1602 /* Walk container types and modify context to point to actual class
2b7b45ca 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
2fbe7a32 1607 valid only via allocation of new polymorphic type inside by means
2b7b45ca 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);
f4d3c071 1618 /* Use when we cannot track dynamic type change. This speculatively assume
c500eb01 1619 type change is not happening. */
007a6c27 1620 void possible_dynamic_type_change (bool, tree otr_type = NULL);
2b7b45ca 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);
9a271891 1626 bool meet_with (ipa_polymorphic_call_context, tree otr_type = NULL);
2b7b45ca 1627
1628 /* Return TRUE if context is fully useless. */
1629 bool useless_p () const;
245ab191 1630 /* Return TRUE if this context conveys the same information as X. */
1631 bool equal_to (const ipa_polymorphic_call_context &x) const;
e33892d7 1632
245ab191 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;
e33892d7 1636 void DEBUG_FUNCTION debug () const;
1637
1638 /* LTO streaming. */
1639 void stream_out (struct output_block *) const;
2e966e2a 1640 void stream_in (class lto_input_block *, class data_in *data_in);
e33892d7 1641
1642private:
2b7b45ca 1643 bool combine_speculation_with (tree, HOST_WIDE_INT, bool, tree);
9a271891 1644 bool meet_speculation_with (tree, HOST_WIDE_INT, bool, tree);
e33892d7 1645 void set_by_decl (tree, HOST_WIDE_INT);
1646 bool set_by_invariant (tree, tree, HOST_WIDE_INT);
9a271891 1647 bool speculation_consistent_p (tree, HOST_WIDE_INT, bool, tree) const;
c500eb01 1648 void make_speculative (tree otr_type = NULL);
e33892d7 1649};
1650
799c8711 1651/* Structure containing additional information about an indirect call. */
1652
251317e4 1653class GTY(()) cgraph_indirect_call_info
799c8711 1654{
251317e4 1655public:
e33892d7 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;
6378ffb3 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. */
e33892d7 1664 tree otr_type;
799c8711 1665 /* Index of the parameter that is called. */
1666 int param_index;
f8b7e3ec 1667 /* ECF flags determined from the caller. */
1668 int ecf_flags;
6a261305 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;
6378ffb3 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;
0d491188 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;
2f6c1cf4 1680 /* Set when this is a call through a member pointer. */
1681 unsigned member_ptr : 1;
665ff45b 1682 /* When the agg_contents bit is set, this one determines whether the
1683 destination is loaded from a parameter passed by reference. */
0d491188 1684 unsigned by_ref : 1;
665ff45b 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;
43aac8cb 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;
799c8711 1693};
1694
251317e4 1695class GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"),
1696 for_user)) cgraph_edge
1697{
1698public:
2e966e2a 1699 friend struct cgraph_node;
d24fc4aa 1700 friend class symbol_table;
35ee1c66 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. */
1a91d914 1708 void set_call_stmt (gcall *new_stmt, bool update_speculative = true);
35ee1c66 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
fe3c9f1e 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
35ee1c66 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. */
151b9ff5 1729 cgraph_edge *make_speculative (cgraph_node *n2, profile_count direct_count);
35ee1c66 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. */
42acab1c 1742 gimple *redirect_call_stmt_to_callee (void);
35ee1c66 1743
1744 /* Create clone of edge in the node N represented
1745 by CALL_EXPR the callgraph. */
1a91d914 1746 cgraph_edge * clone (cgraph_node *n, gcall *call_stmt, unsigned stmt_uid,
151b9ff5 1747 profile_count num, profile_count den,
db9cef39 1748 bool update_original);
35ee1c66 1749
c308ecc8 1750 /* Verify edge count and frequency. */
151b9ff5 1751 bool verify_count ();
c308ecc8 1752
f4d3c071 1753 /* Return true when call of edge cannot lead to return from caller
35ee1c66 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
8070b8d5 1761 /* Return true if the edge may be considered hot. */
35ee1c66 1762 bool maybe_hot_p (void);
1763
d24fc4aa 1764 /* Get unique identifier of the edge. */
1765 inline int get_uid ()
1766 {
1767 return m_uid;
1768 }
1769
1add72d5 1770 /* Get summary id of the edge. */
1771 inline int get_summary_id ()
1772 {
1773 return m_summary_id;
1774 }
1775
35ee1c66 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
42157758 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
3e994825 1788 /* Expected number of executions: calculated in profile.c. */
db9cef39 1789 profile_count count;
415d1b9a 1790 cgraph_node *caller;
1791 cgraph_node *callee;
35ee1c66 1792 cgraph_edge *prev_caller;
1793 cgraph_edge *next_caller;
1794 cgraph_edge *prev_callee;
1795 cgraph_edge *next_callee;
1a91d914 1796 gcall *call_stmt;
799c8711 1797 /* Additional information about an indirect call. Not cleared when an edge
1798 becomes direct. */
35ee1c66 1799 cgraph_indirect_call_info *indirect_info;
b0cdf642 1800 PTR GTY ((skip (""))) aux;
326a9581 1801 /* When equal to CIF_OK, inline this call. Otherwise, points to the
1802 explanation why function was not inlined. */
b3e7c666 1803 enum cgraph_inline_failed_t inline_failed;
3e994825 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;
799c8711 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 */
7bfefa9d 1813 /* True if the corresponding CALL stmt cannot be inlined. */
1814 unsigned int call_stmt_cannot_inline_p : 1;
17b28e52 1815 /* Can this call throw externally? */
1816 unsigned int can_throw_external : 1;
4d044066 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;
007a6c27 1835 /* Set to true when caller is a constructor or destructor of polymorphic
1836 type. */
1837 unsigned in_polymorphic_cdtor : 1;
35ee1c66 1838
2f7867dc 1839 /* Return true if call must bind to current definition. */
1840 bool binds_to_current_def_p ();
1841
151b9ff5 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 ();
7c343235 1846
1847 /* Expected frequency of executions within the function. */
1848 sreal sreal_frequency ();
35ee1c66 1849private:
d24fc4aa 1850 /* Unique id of the edge. */
1851 int m_uid;
1852
1add72d5 1853 /* Summary id that is recycled. */
1854 int m_summary_id;
1855
35ee1c66 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);
c308ecc8 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);
ae01b312 1872};
1873
4ae20857 1874#define CGRAPH_FREQ_BASE 1000
1875#define CGRAPH_FREQ_MAX 100000
1876
1d416bd7 1877/* The varpool data structure.
1878 Each static variable decl has assigned varpool_node. */
229dcfae 1879
251317e4 1880struct GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node
1881{
97221fd7 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. */
2f7867dc 1897 availability get_availability (symtab_node *ref = NULL);
97221fd7 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.
2f7867dc 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. */
97221fd7 1911 inline varpool_node *ultimate_alias_target
2f7867dc 1912 (availability *availability = NULL, symtab_node *ref = NULL);
97221fd7 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. */
50f2a18b 1929 bool call_for_symbol_and_aliases (bool (*callback) (varpool_node *, void *),
1930 void *data,
1931 bool include_overwritable);
97221fd7 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
35ee1c66 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
97221fd7 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
97221fd7 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
e1be32b8 1984 /* Set when variable is scheduled to be assembled. */
a16eb452 1985 unsigned output : 1;
e43059ff 1986
085f6ebf 1987 /* Set if the variable is dynamically initialized, except for
1988 function local statics. */
1989 unsigned dynamically_initialized : 1;
5e68df57 1990
1991 ENUM_BITFIELD(tls_model) tls_model : 3;
3f1f2be0 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;
415d1b9a 1998
97221fd7 1999private:
2000 /* Assemble thunks and aliases associated to varpool node. */
2001 void assemble_aliases (void);
50f2a18b 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);
229dcfae 2007};
2008
cf951b1a 2009/* Every top level asm statement is put into a asm_node. */
56af936e 2010
cf951b1a 2011struct GTY(()) asm_node {
35ee1c66 2012
2013
56af936e 2014 /* Next asm node. */
35ee1c66 2015 asm_node *next;
56af936e 2016 /* String for this asm node. */
2017 tree asm_str;
2018 /* Ordering of all cgraph nodes. */
2019 int order;
2020};
2021
2dc9831f 2022/* Report whether or not THIS symtab node is a function, aka cgraph_node. */
2023
2024template <>
2025template <>
2026inline bool
13cbeaac 2027is_a_helper <cgraph_node *>::test (symtab_node *p)
2dc9831f 2028{
415d1b9a 2029 return p && p->type == SYMTAB_FUNCTION;
2dc9831f 2030}
2031
2032/* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
2033
2034template <>
2035template <>
2036inline bool
13cbeaac 2037is_a_helper <varpool_node *>::test (symtab_node *p)
2dc9831f 2038{
415d1b9a 2039 return p && p->type == SYMTAB_VARIABLE;
2dc9831f 2040}
2041
35ee1c66 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 {
35ee1c66 2056 priority_type init;
2057 priority_type fini;
2058};
2059
2060enum symtab_state
523c1122 2061{
ff2a5ada 2062 /* Frontend is parsing and finalizing functions. */
35ee1c66 2063 PARSING,
523c1122 2064 /* Callgraph is being constructed. It is safe to add new functions. */
35ee1c66 2065 CONSTRUCTION,
366970c6 2066 /* Callgraph is being streamed-in at LTO time. */
35ee1c66 2067 LTO_STREAMING,
366970c6 2068 /* Callgraph is built and early IPA passes are being run. */
35ee1c66 2069 IPA,
f517b36e 2070 /* Callgraph is built and all functions are transformed to SSA form. */
35ee1c66 2071 IPA_SSA,
366970c6 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,
523c1122 2075 /* Functions are now ordered and being passed to RTL expanders. */
35ee1c66 2076 EXPANSION,
523c1122 2077 /* All cgraph expansion is done. */
35ee1c66 2078 FINISHED
523c1122 2079};
ae01b312 2080
576d4555 2081struct asmname_hasher : ggc_ptr_hash <symtab_node>
2ef51f0e 2082{
2ef51f0e 2083 typedef const_tree compare_type;
2ef51f0e 2084
2085 static hashval_t hash (symtab_node *n);
2086 static bool equal (symtab_node *n, const_tree t);
2ef51f0e 2087};
2088
35ee1c66 2089class GTY((tag ("SYMTAB"))) symbol_table
2090{
2091public:
2e966e2a 2092 friend struct symtab_node;
2093 friend struct cgraph_node;
2094 friend struct cgraph_edge;
35ee1c66 2095
1add72d5 2096 symbol_table (): cgraph_max_uid (1), cgraph_max_summary_id (0),
72b1ee08 2097 edges_max_uid (1), edges_max_summary_id (0),
2098 cgraph_released_summary_ids (), edge_released_summary_ids ()
a5d83f7d 2099 {
2100 }
2101
35ee1c66 2102 /* Initialize callgraph dump file. */
1140c305 2103 void initialize (void);
35ee1c66 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
47ae02b7 2129 implementation does that and it is bit easier to keep everything right
35ee1c66 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. */
366970c6 2144 bool remove_unreachable_nodes (FILE *file);
35ee1c66 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
8a604555 2158 /* Release a callgraph NODE. */
2159 void release_symbol (cgraph_node *node);
35ee1c66 2160
2161 /* Output all variables enqueued to be assembled. */
2162 bool output_variables (void);
2163
35ee1c66 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);
229dcfae 2294
acd183e4 2295 /* Dump symbol table to F. */
2296 void dump (FILE *f);
2297
4f6144ba 2298 /* Dump symbol table to F in graphviz format. */
2299 void dump_graphviz (FILE *f);
2300
acd183e4 2301 /* Dump symbol table to stderr. */
9e53fe99 2302 void DEBUG_FUNCTION debug (void);
acd183e4 2303
1add72d5 2304 /* Assign a new summary ID for the callgraph NODE. */
2305 inline int assign_summary_id (cgraph_node *node)
2306 {
72b1ee08 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
1add72d5 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 {
72b1ee08 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
1add72d5 2323 return edge->m_summary_id;
2324 }
2325
e0dec29d 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
35ee1c66 2330 int cgraph_count;
2331 int cgraph_max_uid;
1add72d5 2332 int cgraph_max_summary_id;
35ee1c66 2333
2334 int edges_count;
2335 int edges_max_uid;
1add72d5 2336 int edges_max_summary_id;
35ee1c66 2337
72b1ee08 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
35ee1c66 2344 symtab_node* GTY(()) nodes;
2345 asm_node* GTY(()) asmnodes;
2346 asm_node* GTY(()) asm_last_node;
35ee1c66 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. */
2ef51f0e 2363 hash_table<section_name_hasher> *GTY(()) section_hash;
35ee1c66 2364
2365 /* Hash table used to convert assembler names into nodes. */
2ef51f0e 2366 hash_table<asmname_hasher> *assembler_name_hash;
35ee1c66 2367
2368 /* Hash table used to hold init priorities. */
8f359205 2369 hash_map<symtab_node *, symbol_priority_map> *init_priority_hash;
35ee1c66 2370
2371 FILE* GTY ((skip)) dump_file;
2372
11075c28 2373 /* Return symbol used to separate symbol name from suffix. */
2374 static char symbol_suffix_separator ();
2375
9dc70d59 2376 FILE* GTY ((skip)) ipa_clones_dump_file;
2377
2378 hash_set <const cgraph_node *> GTY ((skip)) cloned_nodes;
2379
35ee1c66 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
73b9626d 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. */
35ee1c66 2388 cgraph_edge *create_edge (cgraph_node *caller, cgraph_node *callee,
151b9ff5 2389 gcall *call_stmt, profile_count count,
73b9626d 2390 bool indir_unknown_callee, bool cloning_p);
35ee1c66 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
2ef51f0e 2407 friend struct asmname_hasher;
35ee1c66 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;
0704fb2e 2428
2ef51f0e 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
ae01b312 2442/* In cgraph.c */
415309e2 2443void cgraph_c_finalize (void);
adf64732 2444void release_function_body (tree);
35ee1c66 2445cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
415d1b9a 2446
42acab1c 2447void cgraph_update_edges_for_call_stmt (gimple *, tree, gimple *);
5bd74231 2448bool cgraph_function_possibly_inlined_p (tree);
2449
326a9581 2450const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
4f13e575 2451cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
e1be32b8 2452
42acab1c 2453extern bool gimple_check_call_matching_types (gimple *, tree, bool);
da5e1e7c 2454
2455/* In cgraphunit.c */
415309e2 2456void cgraphunit_c_finalize (void);
2457
cc8ef84f 2458/* Initialize datastructures so DECL is a function in lowered gimple form.
2459 IN_SSA is true if the gimple is in SSA. */
db9cef39 2460basic_block init_lowered_empty_function (tree, bool, profile_count);
f41db742 2461
4c7db812 2462tree thunk_adjust (gimple_stmt_iterator *, tree, bool, HOST_WIDE_INT, tree,
2463 HOST_WIDE_INT);
f41db742 2464/* In cgraphclones.c */
2465
87943388 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);
9175d3dd 2470tree clone_function_name (tree decl, const char *suffix,
2471 unsigned long number);
87943388 2472tree clone_function_name (tree decl, const char *suffix);
415d1b9a 2473
415d1b9a 2474void tree_function_versioning (tree, tree, vec<ipa_replace_map *, va_gc> *,
40d8e161 2475 ipa_param_adjustments *,
2476 bool, bitmap, basic_block);
da5e1e7c 2477
9dc70d59 2478void dump_callgraph_transformation (const cgraph_node *original,
2479 const cgraph_node *clone,
2480 const char *suffix);
79acaae1 2481/* In cgraphbuild.c */
ccf4ab6b 2482int compute_call_stmt_bb_frequency (tree, basic_block bb);
da5e1e7c 2483void record_references_in_initializer (tree, bool);
79acaae1 2484
65c1a668 2485/* In ipa.c */
da5e1e7c 2486void cgraph_build_static_cdtor (char which, tree body, int priority);
8c8b8b86 2487bool ipa_discover_variable_flags (void);
65c1a668 2488
1d416bd7 2489/* In varpool.c */
df8d3e89 2490tree ctor_for_folding (tree);
960df590 2491
b9a58fc5 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
415d1b9a 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
16d41ae2 2503 if (DECL_ABSTRACT_P (decl))
415d1b9a 2504 return false;
e0dec29d 2505 if (transparent_alias && definition)
2506 return false;
415d1b9a 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
56ac70ed 2515/* Return true if DECL should have entry in symbol table if used.
e5b7a90b 2516 Those are functions and static & external veriables*/
56ac70ed 2517
85d7c6da 2518static inline bool
56ac70ed 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
415d1b9a 2526inline bool
2527symtab_node::in_same_comdat_group_p (symtab_node *target)
8c016392 2528{
415d1b9a 2529 symtab_node *source = this;
8c016392 2530
415d1b9a 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 ();
b6c89d32 2543}
2544
415d1b9a 2545/* Return node that alias is aliasing. */
2546
2547inline symtab_node *
2548symtab_node::get_alias_target (void)
b6c89d32 2549{
35ee1c66 2550 ipa_ref *ref = NULL;
415d1b9a 2551 iterate_reference (0, ref);
2552 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
2553 return ref->referred;
b6c89d32 2554}
2555
415d1b9a 2556/* Return next reachable static symbol with initializer after the node. */
50f2a18b 2557
415d1b9a 2558inline symtab_node *
2559symtab_node::next_defined_symbol (void)
cfbe30aa 2560{
415d1b9a 2561 symtab_node *node1 = next;
2562
2563 for (; node1; node1 = node1->next)
2564 if (node1->definition)
2565 return node1;
2566
2567 return NULL;
cfbe30aa 2568}
2569
50f2a18b 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;
50f2a18b 2609
5154126f 2610 return (iterate_direct_aliases (0, ref) != NULL);
50f2a18b 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
cfbe30aa 2638/* Return varpool node for given symbol and check it is a function. */
35ee1c66 2639
97221fd7 2640inline varpool_node *
2641varpool_node::get (const_tree decl)
cfbe30aa 2642{
2643 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
415d1b9a 2644 return dyn_cast<varpool_node *> (symtab_node::get (decl));
cfbe30aa 2645}
2646
35ee1c66 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
35ee1c66 2699/* Release a callgraph NODE with UID and put in to the list of free nodes. */
2700
2701inline void
8a604555 2702symbol_table::release_symbol (cgraph_node *node)
35ee1c66 2703{
2704 cgraph_count--;
72b1ee08 2705 if (node->m_summary_id != -1)
2706 cgraph_released_summary_ids.safe_push (node->m_summary_id);
2707 ggc_free (node);
35ee1c66 2708}
2709
2710/* Allocate new callgraph node. */
2711
2712inline cgraph_node *
2713symbol_table::allocate_cgraph_symbol (void)
2714{
2715 cgraph_node *node;
2716
72b1ee08 2717 node = ggc_cleared_alloc<cgraph_node> ();
2718 node->type = SYMTAB_FUNCTION;
2719 node->m_summary_id = -1;
2c8bbd94 2720 node->m_uid = cgraph_max_uid++;
35ee1c66 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
cfbe30aa 2732/* Walk all symbols. */
2733#define FOR_EACH_SYMBOL(node) \
35ee1c66 2734 for ((node) = symtab->first_symbol (); (node); (node) = (node)->next)
b6c89d32 2735
52638b9c 2736/* Return first static symbol with definition. */
35ee1c66 2737inline symtab_node *
2738symbol_table::first_defined_symbol (void)
52638b9c 2739{
2740 symtab_node *node;
2741
35ee1c66 2742 for (node = nodes; node; node = node->next)
52638b9c 2743 if (node->definition)
2744 return node;
2745
2746 return NULL;
2747}
2748
52638b9c 2749/* Walk all symbols with definitions in current unit. */
2750#define FOR_EACH_DEFINED_SYMBOL(node) \
35ee1c66 2751 for ((node) = symtab->first_defined_symbol (); (node); \
415d1b9a 2752 (node) = node->next_defined_symbol ())
ff2a5ada 2753
2754/* Return first variable. */
35ee1c66 2755inline varpool_node *
2756symbol_table::first_variable (void)
ff2a5ada 2757{
452659af 2758 symtab_node *node;
35ee1c66 2759 for (node = nodes; node; node = node->next)
13cbeaac 2760 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
2dc9831f 2761 return vnode;
ff2a5ada 2762 return NULL;
2763}
2764
2765/* Return next variable after NODE. */
35ee1c66 2766inline varpool_node *
2767symbol_table::next_variable (varpool_node *node)
ff2a5ada 2768{
452659af 2769 symtab_node *node1 = node->next;
02774f2d 2770 for (; node1; node1 = node1->next)
13cbeaac 2771 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
2dc9831f 2772 return vnode1;
ff2a5ada 2773 return NULL;
2774}
2775/* Walk all variables. */
2776#define FOR_EACH_VARIABLE(node) \
35ee1c66 2777 for ((node) = symtab->first_variable (); \
ff2a5ada 2778 (node); \
35ee1c66 2779 (node) = symtab->next_variable ((node)))
ff2a5ada 2780
52638b9c 2781/* Return first static variable with initializer. */
35ee1c66 2782inline varpool_node *
2783symbol_table::first_static_initializer (void)
960df590 2784{
452659af 2785 symtab_node *node;
35ee1c66 2786 for (node = nodes; node; node = node->next)
960df590 2787 {
13cbeaac 2788 varpool_node *vnode = dyn_cast <varpool_node *> (node);
02774f2d 2789 if (vnode && DECL_INITIAL (node->decl))
2dc9831f 2790 return vnode;
960df590 2791 }
2792 return NULL;
2793}
2794
52638b9c 2795/* Return next static variable with initializer after NODE. */
35ee1c66 2796inline varpool_node *
2797symbol_table::next_static_initializer (varpool_node *node)
960df590 2798{
452659af 2799 symtab_node *node1 = node->next;
02774f2d 2800 for (; node1; node1 = node1->next)
960df590 2801 {
13cbeaac 2802 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
02774f2d 2803 if (vnode1 && DECL_INITIAL (node1->decl))
2dc9831f 2804 return vnode1;
960df590 2805 }
2806 return NULL;
2807}
2808
2809/* Walk all static variables with initializer set. */
2810#define FOR_EACH_STATIC_INITIALIZER(node) \
35ee1c66 2811 for ((node) = symtab->first_static_initializer (); (node); \
2812 (node) = symtab->next_static_initializer (node))
0704fb2e 2813
52638b9c 2814/* Return first static variable with definition. */
35ee1c66 2815inline varpool_node *
2816symbol_table::first_defined_variable (void)
0704fb2e 2817{
452659af 2818 symtab_node *node;
35ee1c66 2819 for (node = nodes; node; node = node->next)
0704fb2e 2820 {
13cbeaac 2821 varpool_node *vnode = dyn_cast <varpool_node *> (node);
02774f2d 2822 if (vnode && vnode->definition)
2dc9831f 2823 return vnode;
0704fb2e 2824 }
2825 return NULL;
2826}
2827
52638b9c 2828/* Return next static variable with definition after NODE. */
35ee1c66 2829inline varpool_node *
2830symbol_table::next_defined_variable (varpool_node *node)
0704fb2e 2831{
452659af 2832 symtab_node *node1 = node->next;
02774f2d 2833 for (; node1; node1 = node1->next)
0704fb2e 2834 {
13cbeaac 2835 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
02774f2d 2836 if (vnode1 && vnode1->definition)
2dc9831f 2837 return vnode1;
0704fb2e 2838 }
2839 return NULL;
2840}
7c455d87 2841/* Walk all variables with definitions in current unit. */
2842#define FOR_EACH_DEFINED_VARIABLE(node) \
35ee1c66 2843 for ((node) = symtab->first_defined_variable (); (node); \
2844 (node) = symtab->next_defined_variable (node))
960df590 2845
91bf9d9a 2846/* Return first function with body defined. */
35ee1c66 2847inline cgraph_node *
2848symbol_table::first_defined_function (void)
91bf9d9a 2849{
452659af 2850 symtab_node *node;
35ee1c66 2851 for (node = nodes; node; node = node->next)
91bf9d9a 2852 {
13cbeaac 2853 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
02774f2d 2854 if (cn && cn->definition)
2dc9831f 2855 return cn;
91bf9d9a 2856 }
2857 return NULL;
2858}
2859
11ec81bd 2860/* Return next function with body defined after NODE. */
35ee1c66 2861inline cgraph_node *
2862symbol_table::next_defined_function (cgraph_node *node)
91bf9d9a 2863{
452659af 2864 symtab_node *node1 = node->next;
02774f2d 2865 for (; node1; node1 = node1->next)
91bf9d9a 2866 {
13cbeaac 2867 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
02774f2d 2868 if (cn1 && cn1->definition)
2dc9831f 2869 return cn1;
91bf9d9a 2870 }
2871 return NULL;
2872}
2873
2874/* Walk all functions with body defined. */
2875#define FOR_EACH_DEFINED_FUNCTION(node) \
35ee1c66 2876 for ((node) = symtab->first_defined_function (); (node); \
2877 (node) = symtab->next_defined_function ((node)))
0704fb2e 2878
2879/* Return first function. */
35ee1c66 2880inline cgraph_node *
2881symbol_table::first_function (void)
0704fb2e 2882{
452659af 2883 symtab_node *node;
35ee1c66 2884 for (node = nodes; node; node = node->next)
13cbeaac 2885 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
2dc9831f 2886 return cn;
0704fb2e 2887 return NULL;
2888}
2889
2890/* Return next function. */
35ee1c66 2891inline cgraph_node *
2892symbol_table::next_function (cgraph_node *node)
0704fb2e 2893{
452659af 2894 symtab_node *node1 = node->next;
02774f2d 2895 for (; node1; node1 = node1->next)
13cbeaac 2896 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
2dc9831f 2897 return cn1;
0704fb2e 2898 return NULL;
2899}
91bf9d9a 2900
2901/* Return first function with body defined. */
35ee1c66 2902inline cgraph_node *
2903symbol_table::first_function_with_gimple_body (void)
91bf9d9a 2904{
452659af 2905 symtab_node *node;
35ee1c66 2906 for (node = nodes; node; node = node->next)
91bf9d9a 2907 {
13cbeaac 2908 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
415d1b9a 2909 if (cn && cn->has_gimple_body_p ())
2dc9831f 2910 return cn;
91bf9d9a 2911 }
2912 return NULL;
2913}
2914
2915/* Return next reachable static variable with initializer after NODE. */
35ee1c66 2916inline cgraph_node *
2917symbol_table::next_function_with_gimple_body (cgraph_node *node)
91bf9d9a 2918{
452659af 2919 symtab_node *node1 = node->next;
02774f2d 2920 for (; node1; node1 = node1->next)
91bf9d9a 2921 {
13cbeaac 2922 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
415d1b9a 2923 if (cn1 && cn1->has_gimple_body_p ())
2dc9831f 2924 return cn1;
91bf9d9a 2925 }
2926 return NULL;
2927}
2928
35ee1c66 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
e3e42b03 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
91bf9d9a 2957/* Walk all functions with body defined. */
2958#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
35ee1c66 2959 for ((node) = symtab->first_function_with_gimple_body (); (node); \
2960 (node) = symtab->next_function_with_gimple_body (node))
91bf9d9a 2961
9261e5d9 2962/* Uniquize all constants that appear in memory.
2963 Each constant in memory thus far output is recorded
2964 in `const_desc_table'. */
2965
2ef51f0e 2966struct GTY((for_user)) constant_descriptor_tree {
9261e5d9 2967 /* A MEM for the constant. */
2968 rtx rtl;
48e1416a 2969
9261e5d9 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
415d1b9a 2979/* Return true when function is only called directly or it has alias.
59dd4830 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
415d1b9a 2983inline bool
2984cgraph_node::only_called_directly_or_aliased_p (void)
2985{
2986 gcc_assert (!global.inlined_to);
2987 return (!force_output && !address_taken
b859b598 2988 && !ifunc_resolver
415d1b9a 2989 && !used_from_other_partition
2990 && !DECL_VIRTUAL_P (decl)
2991 && !DECL_STATIC_CONSTRUCTOR (decl)
2992 && !DECL_STATIC_DESTRUCTOR (decl)
e88fecaf 2993 && !used_from_object_file_p ()
415d1b9a 2994 && !externally_visible);
59dd4830 2995}
2996
50f2a18b 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);
50f2a18b 3004 /* Extern inlines can always go, we will use the external definition. */
3005 if (DECL_EXTERNAL (decl))
3006 return true;
f4d3c071 3007 /* When function is needed, we cannot remove it. */
50f2a18b 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
382ecba7 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
97221fd7 3031/* Return true when variable can be removed from variable pool
7410370b 3032 if all direct calls are eliminated. */
3033
97221fd7 3034inline bool
3035varpool_node::can_remove_if_no_refs_p (void)
7410370b 3036{
97221fd7 3037 if (DECL_EXTERNAL (decl))
aa419a52 3038 return true;
97221fd7 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)));
7410370b 3045}
3046
97221fd7 3047/* Return true when all references to variable must be visible in ipa_ref_list.
8dfbf71d 3048 i.e. if the variable is not externally visible or not used in some magic
3049 way (asm statement or such).
0a10fd82 3050 The magic uses are all summarized in force_output flag. */
8dfbf71d 3051
97221fd7 3052inline bool
3053varpool_node::all_refs_explicit_p ()
8dfbf71d 3054{
97221fd7 3055 return (definition
3056 && !externally_visible
3057 && !used_from_other_partition
3058 && !force_output);
8dfbf71d 3059}
3060
b594087e 3061struct tree_descriptor_hasher : ggc_ptr_hash<constant_descriptor_tree>
2ef51f0e 3062{
3063 static hashval_t hash (constant_descriptor_tree *);
3064 static bool equal (constant_descriptor_tree *, constant_descriptor_tree *);
3065};
3066
9261e5d9 3067/* Constant pool accessor function. */
2ef51f0e 3068hash_table<tree_descriptor_hasher> *constant_pool_htab (void);
13f90d63 3069
415d1b9a 3070/* Return node that alias is aliasing. */
c70f46b0 3071
415d1b9a 3072inline cgraph_node *
3073cgraph_node::get_alias_target (void)
e0eaac80 3074{
415d1b9a 3075 return dyn_cast <cgraph_node *> (symtab_node::get_alias_target ());
e0eaac80 3076}
3077
97221fd7 3078/* Return node that alias is aliasing. */
3079
3080inline varpool_node *
3081varpool_node::get_alias_target (void)
74fa5f1c 3082{
97221fd7 3083 return dyn_cast <varpool_node *> (symtab_node::get_alias_target ());
74fa5f1c 3084}
3085
50f2a18b 3086/* Walk the alias chain to return the symbol NODE is alias of.
3087 If NODE is not an alias, return NODE.
2f7867dc 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. */
50f2a18b 3091
3092inline symtab_node *
2f7867dc 3093symtab_node::ultimate_alias_target (enum availability *availability,
3094 symtab_node *ref)
50f2a18b 3095{
3096 if (!alias)
3097 {
3098 if (availability)
2f7867dc 3099 *availability = get_availability (ref);
50f2a18b 3100 return this;
3101 }
3102
2f7867dc 3103 return ultimate_alias_target_1 (availability, ref);
50f2a18b 3104}
3105
415d1b9a 3106/* Given function symbol, walk the alias chain to return the function node
3107 is alias of. Do not walk through thunks.
2f7867dc 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. */
74fa5f1c 3111
415d1b9a 3112inline cgraph_node *
2f7867dc 3113cgraph_node::ultimate_alias_target (enum availability *availability,
3114 symtab_node *ref)
74fa5f1c 3115{
50f2a18b 3116 cgraph_node *n = dyn_cast <cgraph_node *>
2f7867dc 3117 (symtab_node::ultimate_alias_target (availability, ref));
48669653 3118 if (!n && availability)
c70f46b0 3119 *availability = AVAIL_NOT_AVAILABLE;
15ca8f90 3120 return n;
74fa5f1c 3121}
97221fd7 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.
2f7867dc 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. */
e0eaac80 3128
97221fd7 3129inline varpool_node *
2f7867dc 3130varpool_node::ultimate_alias_target (availability *availability,
3131 symtab_node *ref)
e0eaac80 3132{
97221fd7 3133 varpool_node *n = dyn_cast <varpool_node *>
2f7867dc 3134 (symtab_node::ultimate_alias_target (availability, ref));
6cdce0f6 3135
48669653 3136 if (!n && availability)
e0eaac80 3137 *availability = AVAIL_NOT_AVAILABLE;
15ca8f90 3138 return n;
e0eaac80 3139}
3140
c308ecc8 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
35ee1c66 3168/* Return true when the edge represents a direct recursion. */
50f2a18b 3169
35ee1c66 3170inline bool
3171cgraph_edge::recursive_p (void)
17c205c9 3172{
35ee1c66 3173 cgraph_node *c = callee->ultimate_alias_target ();
3174 if (caller->global.inlined_to)
3175 return caller->global.inlined_to->decl == c->decl;
17c205c9 3176 else
35ee1c66 3177 return caller->decl == c->decl;
17c205c9 3178}
4c0315d0 3179
c308ecc8 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
2f7867dc 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
841257c2 3202 return false;
2f7867dc 3203}
3204
151b9ff5 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
7c343235 3217
4c0315d0 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{
415d1b9a 3222 cgraph_node *n = cgraph_node::get (fndecl);
4c0315d0 3223 if (n)
3224 return n->tm_clone;
3225 return false;
3226}
da5e1e7c 3227
3228/* Likewise indicate that a node is needed, i.e. reachable via some
3229 external means. */
3230
415d1b9a 3231inline void
3232cgraph_node::mark_force_output (void)
468088ac 3233{
415d1b9a 3234 force_output = 1;
3235 gcc_checking_assert (!global.inlined_to);
468088ac 3236}
3237
e5a23585 3238/* Return true if function should be optimized for size. */
3239
3240inline bool
3241cgraph_node::optimize_for_size_p (void)
3242{
0c321de1 3243 if (opt_for_fn (decl, optimize_size))
e5a23585 3244 return true;
3245 if (frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
3246 return true;
3247 else
3248 return false;
3249}
3250
50f2a18b 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)
8e857c41 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
2f7867dc 3263/* Return availability of NODE when referenced from REF. */
50f2a18b 3264
3265inline enum availability
2f7867dc 3266symtab_node::get_availability (symtab_node *ref)
50f2a18b 3267{
3268 if (is_a <cgraph_node *> (this))
2f7867dc 3269 return dyn_cast <cgraph_node *> (this)->get_availability (ref);
50f2a18b 3270 else
2f7867dc 3271 return dyn_cast <varpool_node *> (this)->get_availability (ref);
50f2a18b 3272}
3273
3274/* Call calback on symtab node and aliases associated to this node.
aaa36a78 3275 When INCLUDE_OVERWRITABLE is false, overwritable symbols are skipped. */
50f2a18b 3276
3277inline bool
3278symtab_node::call_for_symbol_and_aliases (bool (*callback) (symtab_node *,
3279 void *),
3280 void *data,
3281 bool include_overwritable)
3282{
aaa36a78 3283 if (include_overwritable
3284 || get_availability () > AVAIL_INTERPOSABLE)
3285 {
3286 if (callback (this, data))
3287 return true;
3288 }
5154126f 3289 if (has_aliases_p ())
50f2a18b 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.
aaa36a78 3295 When INCLUDE_OVERWRITABLE is false, overwritable symbols are
50f2a18b 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{
aaa36a78 3304 if (include_overwritable
3305 || get_availability () > AVAIL_INTERPOSABLE)
3306 {
3307 if (callback (this, data))
3308 return true;
3309 }
5154126f 3310 if (has_aliases_p ())
50f2a18b 3311 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
50f2a18b 3312 return false;
3313}
3314
3315/* Call calback on varpool symbol and aliases associated to varpool symbol.
aaa36a78 3316 When INCLUDE_OVERWRITABLE is false, overwritable symbols are
50f2a18b 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{
aaa36a78 3325 if (include_overwritable
3326 || get_availability () > AVAIL_INTERPOSABLE)
3327 {
3328 if (callback (this, data))
3329 return true;
3330 }
5154126f 3331 if (has_aliases_p ())
50f2a18b 3332 return call_for_symbol_and_aliases_1 (callback, data, include_overwritable);
50f2a18b 3333 return false;
3334}
3335
ce7711df 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
e33892d7 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
dfb61776 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. */
e33892d7 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;
c500eb01 3389 dynamic = true;
e33892d7 3390}
2b7b45ca 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}
058a1b7a 3410
5ae49d3e 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
42157758 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
564850b9 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
ae01b312 3471#endif /* GCC_CGRAPH_H */