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