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