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