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