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