cgraph.h (tls_model_names): New variable.
[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 "is-a.h"
25 #include "plugin-api.h"
26 #include "vec.h"
27 #include "basic-block.h"
28 #include "function.h"
29 #include "ipa-ref.h"
30
31 /* Symbol table consists of functions and variables.
32    TODO: add labels and CONST_DECLs.  */
33 enum symtab_type
34 {
35   SYMTAB_SYMBOL,
36   SYMTAB_FUNCTION,
37   SYMTAB_VARIABLE
38 };
39
40 /* Section names are stored as reference counted strings in GGC safe hashtable
41    (to make them survive through PCH).  */
42
43 struct GTY(()) section_hash_entry_d
44 {
45   int ref_count;
46   char *name;  /* As long as this datastructure stays in GGC, we can not put
47                   string at the tail of structure of GGC dies in horrible
48                   way  */
49 };
50
51 typedef struct section_hash_entry_d section_hash_entry;
52
53 /* Base of all entries in the symbol table.
54    The symtab_node is inherited by cgraph and varpol nodes.  */
55 class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
56            chain_next ("%h.next"), chain_prev ("%h.previous")))
57   symtab_node
58 {
59 public:
60   /* Return name.  */
61   const char *name () const;
62
63   /* Return asm name.  */
64   const char * asm_name () const;
65
66   /* Type of the symbol.  */
67   ENUM_BITFIELD (symtab_type) type : 8;
68
69   /* The symbols resolution.  */
70   ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
71
72   /*** Flags representing the symbol type.  ***/
73
74   /* True when symbol corresponds to a definition in current unit.
75      set via cgraph_finalize_function or varpool_finalize_decl  */
76   unsigned definition : 1;
77   /* True when symbol is an alias.  
78      Set by assemble_alias.  */
79   unsigned alias : 1;
80   /* True when alias is a weakref.  */
81   unsigned weakref : 1;
82   /* C++ frontend produce same body aliases and extra name aliases for
83      virtual functions and vtables that are obviously equivalent.
84      Those aliases are bit special, especially because C++ frontend
85      visibility code is so ugly it can not get them right at first time
86      and their visibility needs to be copied from their "masters" at
87      the end of parsing.  */
88   unsigned cpp_implicit_alias : 1;
89   /* Set once the definition was analyzed.  The list of references and
90      other properties are built during analysis.  */
91   unsigned analyzed : 1;
92   /* Set for write-only variables.  */
93   unsigned writeonly : 1;
94
95
96   /*** Visibility and linkage flags.  ***/
97
98   /* Set when function is visible by other units.  */
99   unsigned externally_visible : 1;
100   /* The symbol will be assumed to be used in an invisible way (like
101      by an toplevel asm statement).  */
102   unsigned force_output : 1;
103   /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
104      exported.  Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
105      to static and it does not inhibit optimization.  */
106   unsigned forced_by_abi : 1;
107   /* True when the name is known to be unique and thus it does not need mangling.  */
108   unsigned unique_name : 1;
109   /* Specify whether the section was set by user or by
110      compiler via -ffunction-sections.  */
111   unsigned implicit_section : 1;
112   /* True when body and other characteristics have been removed by
113      symtab_remove_unreachable_nodes. */
114   unsigned body_removed : 1;
115
116   /*** WHOPR Partitioning flags.
117        These flags are used at ltrans stage when only part of the callgraph is
118        available. ***/
119
120   /* Set when variable is used from other LTRANS partition.  */
121   unsigned used_from_other_partition : 1;
122   /* Set when function is available in the other LTRANS partition.  
123      During WPA output it is used to mark nodes that are present in
124      multiple partitions.  */
125   unsigned in_other_partition : 1;
126
127
128
129   /*** other flags.  ***/
130
131   /* Set when symbol has address taken. */
132   unsigned address_taken : 1;
133   /* Set when init priority is set.  */
134   unsigned in_init_priority_hash : 1;
135
136
137   /* Ordering of all symtab entries.  */
138   int order;
139
140   /* Declaration representing the symbol.  */
141   tree decl;
142
143   /* Linked list of symbol table entries starting with symtab_nodes.  */
144   symtab_node *next;
145   symtab_node *previous;
146
147   /* Linked list of symbols with the same asm name.  There may be multiple
148      entries for single symbol name during LTO, because symbols are renamed
149      only after partitioning.
150
151      Because inline clones are kept in the assembler name has, they also produce
152      duplicate entries.
153
154      There are also several long standing bugs where frontends and builtin
155      code produce duplicated decls.  */
156   symtab_node *next_sharing_asm_name;
157   symtab_node *previous_sharing_asm_name;
158
159   /* Circular list of nodes in the same comdat group if non-NULL.  */
160   symtab_node *same_comdat_group;
161
162   /* Return comdat group.  */
163   tree get_comdat_group ()
164     {
165       return x_comdat_group;
166     }
167
168   /* Return comdat group as identifier_node.  */
169   tree get_comdat_group_id ()
170     {
171       if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE)
172         x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group);
173       return x_comdat_group;
174     }
175
176   /* Set comdat group.  */
177   void set_comdat_group (tree group)
178     {
179       gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE
180                            || DECL_P (group));
181       x_comdat_group = group;
182     }
183
184   /* Return section as string.  */
185   const char * get_section ()
186     {
187       if (!x_section)
188         return NULL;
189       return x_section->name;
190     }
191
192   /* Vectors of referring and referenced entities.  */
193   struct ipa_ref_list ref_list;
194
195   /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
196      depending to what was known to frontend on the creation time.
197      Once alias is resolved, this pointer become NULL.  */
198   tree alias_target;
199
200   /* File stream where this node is being written to.  */
201   struct lto_file_decl_data * lto_file_data;
202
203   PTR GTY ((skip)) aux;
204
205   /* Comdat group the symbol is in.  Can be private if GGC allowed that.  */
206   tree x_comdat_group;
207
208   /* Section name. Again can be private, if allowed.  */
209   section_hash_entry *x_section;
210
211   /* Set section for symbol and its aliases.  */
212   void set_section (const char *section);
213   void set_section_for_node (const char *section);
214
215   void set_init_priority (priority_type priority);
216   priority_type get_init_priority ();
217 };
218
219 enum availability
220 {
221   /* Not yet set by cgraph_function_body_availability.  */
222   AVAIL_UNSET,
223   /* Function body/variable initializer is unknown.  */
224   AVAIL_NOT_AVAILABLE,
225   /* Function body/variable initializer is known but might be replaced
226      by a different one from other compilation unit and thus needs to
227      be dealt with a care.  Like AVAIL_NOT_AVAILABLE it can have
228      arbitrary side effects on escaping variables and functions, while
229      like AVAILABLE it might access static variables.  */
230   AVAIL_OVERWRITABLE,
231   /* Function body/variable initializer is known and will be used in final
232      program.  */
233   AVAIL_AVAILABLE,
234   /* Function body/variable initializer is known and all it's uses are explicitly
235      visible within current unit (ie it's address is never taken and it is not
236      exported to other units).
237      Currently used only for functions.  */
238   AVAIL_LOCAL
239 };
240
241 /* This is the information that is put into the cgraph local structure
242    to recover a function.  */
243 struct lto_file_decl_data;
244
245 extern const char * const cgraph_availability_names[];
246 extern const char * const ld_plugin_symbol_resolution_names[];
247 extern const char * const tls_model_names[];
248
249 /* Information about thunk, used only for same body aliases.  */
250
251 struct GTY(()) cgraph_thunk_info {
252   /* Information about the thunk.  */
253   HOST_WIDE_INT fixed_offset;
254   HOST_WIDE_INT virtual_value;
255   tree alias;
256   bool this_adjusting;
257   bool virtual_offset_p;
258   /* Set to true when alias node is thunk.  */
259   bool thunk_p;
260 };
261
262 /* Information about the function collected locally.
263    Available after function is analyzed.  */
264
265 struct GTY(()) cgraph_local_info {
266   /* Set when function function is visible in current compilation unit only
267      and its address is never taken.  */
268   unsigned local : 1;
269
270   /* False when there is something makes versioning impossible.  */
271   unsigned versionable : 1;
272
273   /* False when function calling convention and signature can not be changed.
274      This is the case when __builtin_apply_args is used.  */
275   unsigned can_change_signature : 1;
276
277   /* True when the function has been originally extern inline, but it is
278      redefined now.  */
279   unsigned redefined_extern_inline : 1;
280
281   /* True if the function may enter serial irrevocable mode.  */
282   unsigned tm_may_enter_irr : 1;
283 };
284
285 /* Information about the function that needs to be computed globally
286    once compilation is finished.  Available only with -funit-at-a-time.  */
287
288 struct GTY(()) cgraph_global_info {
289   /* For inline clones this points to the function they will be
290      inlined into.  */
291   struct cgraph_node *inlined_to;
292 };
293
294 /* Information about the function that is propagated by the RTL backend.
295    Available only for functions that has been already assembled.  */
296
297 struct GTY(()) cgraph_rtl_info {
298    unsigned int preferred_incoming_stack_boundary;
299
300   /* Call unsaved hard registers really used by the corresponding
301      function (including ones used by functions called by the
302      function).  */
303   HARD_REG_SET function_used_regs;
304   /* Set if function_used_regs is valid.  */
305   unsigned function_used_regs_valid: 1;
306 };
307
308 /* Represent which DECL tree (or reference to such tree)
309    will be replaced by another tree while versioning.  */
310 struct GTY(()) ipa_replace_map
311 {
312   /* The tree that will be replaced.  */
313   tree old_tree;
314   /* The new (replacing) tree.  */
315   tree new_tree;
316   /* Parameter number to replace, when old_tree is NULL.  */
317   int parm_num;
318   /* True when a substitution should be done, false otherwise.  */
319   bool replace_p;
320   /* True when we replace a reference to old_tree.  */
321   bool ref_p;
322 };
323 typedef struct ipa_replace_map *ipa_replace_map_p;
324
325 struct GTY(()) cgraph_clone_info
326 {
327   vec<ipa_replace_map_p, va_gc> *tree_map;
328   bitmap args_to_skip;
329   bitmap combined_args_to_skip;
330 };
331
332 enum cgraph_simd_clone_arg_type
333 {
334   SIMD_CLONE_ARG_TYPE_VECTOR,
335   SIMD_CLONE_ARG_TYPE_UNIFORM,
336   SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
337   SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
338   SIMD_CLONE_ARG_TYPE_MASK
339 };
340
341 /* Function arguments in the original function of a SIMD clone.
342    Supplementary data for `struct simd_clone'.  */
343
344 struct GTY(()) cgraph_simd_clone_arg {
345   /* Original function argument as it originally existed in
346      DECL_ARGUMENTS.  */
347   tree orig_arg;
348
349   /* orig_arg's function (or for extern functions type from
350      TYPE_ARG_TYPES).  */
351   tree orig_type;
352
353   /* If argument is a vector, this holds the vector version of
354      orig_arg that after adjusting the argument types will live in
355      DECL_ARGUMENTS.  Otherwise, this is NULL.
356
357      This basically holds:
358        vector(simdlen) __typeof__(orig_arg) new_arg.  */
359   tree vector_arg;
360
361   /* vector_arg's type (or for extern functions new vector type.  */
362   tree vector_type;
363
364   /* If argument is a vector, this holds the array where the simd
365      argument is held while executing the simd clone function.  This
366      is a local variable in the cloned function.  Its content is
367      copied from vector_arg upon entry to the clone.
368
369      This basically holds:
370        __typeof__(orig_arg) simd_array[simdlen].  */
371   tree simd_array;
372
373   /* A SIMD clone's argument can be either linear (constant or
374      variable), uniform, or vector.  */
375   enum cgraph_simd_clone_arg_type arg_type;
376
377   /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
378      the constant linear step, if arg_type is
379      SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
380      the uniform argument holding the step, otherwise 0.  */
381   HOST_WIDE_INT linear_step;
382
383   /* Variable alignment if available, otherwise 0.  */
384   unsigned int alignment;
385 };
386
387 /* Specific data for a SIMD function clone.  */
388
389 struct GTY(()) cgraph_simd_clone {
390   /* Number of words in the SIMD lane associated with this clone.  */
391   unsigned int simdlen;
392
393   /* Number of annotated function arguments in `args'.  This is
394      usually the number of named arguments in FNDECL.  */
395   unsigned int nargs;
396
397   /* Max hardware vector size in bits for integral vectors.  */
398   unsigned int vecsize_int;
399
400   /* Max hardware vector size in bits for floating point vectors.  */
401   unsigned int vecsize_float;
402
403   /* The mangling character for a given vector size.  This is is used
404      to determine the ISA mangling bit as specified in the Intel
405      Vector ABI.  */
406   unsigned char vecsize_mangle;
407
408   /* True if this is the masked, in-branch version of the clone,
409      otherwise false.  */
410   unsigned int inbranch : 1;
411
412   /* True if this is a Cilk Plus variant.  */
413   unsigned int cilk_elemental : 1;
414
415   /* Doubly linked list of SIMD clones.  */
416   struct cgraph_node *prev_clone, *next_clone;
417
418   /* Original cgraph node the SIMD clones were created for.  */
419   struct cgraph_node *origin;
420
421   /* Annotated function arguments for the original function.  */
422   struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
423 };
424
425
426 /* The cgraph data structure.
427    Each function decl has assigned cgraph_node listing callees and callers.  */
428
429 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
430 public:
431   struct cgraph_edge *callees;
432   struct cgraph_edge *callers;
433   /* List of edges representing indirect calls with a yet undetermined
434      callee.  */
435   struct cgraph_edge *indirect_calls;
436   /* For nested functions points to function the node is nested in.  */
437   struct cgraph_node *origin;
438   /* Points to first nested function, if any.  */
439   struct cgraph_node *nested;
440   /* Pointer to the next function with same origin, if any.  */
441   struct cgraph_node *next_nested;
442   /* Pointer to the next clone.  */
443   struct cgraph_node *next_sibling_clone;
444   struct cgraph_node *prev_sibling_clone;
445   struct cgraph_node *clones;
446   struct cgraph_node *clone_of;
447   /* For functions with many calls sites it holds map from call expression
448      to the edge to speed up cgraph_edge function.  */
449   htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
450   /* Declaration node used to be clone of. */
451   tree former_clone_of;
452
453   /* If this is a SIMD clone, this points to the SIMD specific
454      information for it.  */
455   struct cgraph_simd_clone *simdclone;
456   /* If this function has SIMD clones, this points to the first clone.  */
457   struct cgraph_node *simd_clones;
458
459   /* Interprocedural passes scheduled to have their transform functions
460      applied next time we execute local pass on them.  We maintain it
461      per-function in order to allow IPA passes to introduce new functions.  */
462   vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
463
464   struct cgraph_local_info local;
465   struct cgraph_global_info global;
466   struct cgraph_rtl_info rtl;
467   struct cgraph_clone_info clone;
468   struct cgraph_thunk_info thunk;
469
470   /* Expected number of executions: calculated in profile.c.  */
471   gcov_type count;
472   /* How to scale counts at materialization time; used to merge
473      LTO units with different number of profile runs.  */
474   int count_materialization_scale;
475   /* Unique id of the node.  */
476   int uid;
477   /* ID assigned by the profiling.  */
478   unsigned int profile_id;
479   /* Time profiler: first run of function.  */
480   int tp_first_run;
481
482   /* Set when decl is an abstract function pointed to by the
483      ABSTRACT_DECL_ORIGIN of a reachable function.  */
484   unsigned used_as_abstract_origin : 1;
485   /* Set once the function is lowered (i.e. its CFG is built).  */
486   unsigned lowered : 1;
487   /* Set once the function has been instantiated and its callee
488      lists created.  */
489   unsigned process : 1;
490   /* How commonly executed the node is.  Initialized during branch
491      probabilities pass.  */
492   ENUM_BITFIELD (node_frequency) frequency : 2;
493   /* True when function can only be called at startup (from static ctor).  */
494   unsigned only_called_at_startup : 1;
495   /* True when function can only be called at startup (from static dtor).  */
496   unsigned only_called_at_exit : 1;
497   /* True when function is the transactional clone of a function which
498      is called only from inside transactions.  */
499   /* ?? We should be able to remove this.  We have enough bits in
500      cgraph to calculate it.  */
501   unsigned tm_clone : 1;
502   /* True if this decl is a dispatcher for function versions.  */
503   unsigned dispatcher_function : 1;
504   /* True if this decl calls a COMDAT-local function.  This is set up in
505      compute_inline_parameters and inline_call.  */
506   unsigned calls_comdat_local : 1;
507
508   void set_fini_priority (priority_type priority);
509   priority_type get_fini_priority ();
510 };
511
512
513 typedef struct cgraph_node *cgraph_node_ptr;
514
515
516 /* Function Multiversioning info.  */
517 struct GTY(()) cgraph_function_version_info {
518   /* The cgraph_node for which the function version info is stored.  */
519   struct cgraph_node *this_node;
520   /* Chains all the semantically identical function versions.  The
521      first function in this chain is the version_info node of the
522      default function.  */
523   struct cgraph_function_version_info *prev;
524   /* If this version node corresponds to a dispatcher for function
525      versions, this points to the version info node of the default
526      function, the first node in the chain.  */
527   struct cgraph_function_version_info *next;
528   /* If this node corresponds to a function version, this points
529      to the dispatcher function decl, which is the function that must
530      be called to execute the right function version at run-time.
531
532      If this cgraph node is a dispatcher (if dispatcher_function is
533      true, in the cgraph_node struct) for function versions, this
534      points to resolver function, which holds the function body of the
535      dispatcher. The dispatcher decl is an alias to the resolver
536      function decl.  */
537   tree dispatcher_resolver;
538 };
539
540 /* Get the cgraph_function_version_info node corresponding to node.  */
541 struct cgraph_function_version_info *
542   get_cgraph_node_version (struct cgraph_node *node);
543
544 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
545    corresponding to cgraph_node NODE.  */
546 struct cgraph_function_version_info *
547   insert_new_cgraph_node_version (struct cgraph_node *node);
548
549 /* Record that DECL1 and DECL2 are semantically identical function
550    versions.  */
551 void record_function_versions (tree decl1, tree decl2);
552
553 /* Remove the cgraph_function_version_info and cgraph_node for DECL.  This
554    DECL is a duplicate declaration.  */
555 void delete_function_version (tree decl);
556
557 /* A cgraph node set is a collection of cgraph nodes.  A cgraph node
558    can appear in multiple sets.  */
559 struct cgraph_node_set_def
560 {
561   struct pointer_map_t *map;
562   vec<cgraph_node_ptr> nodes;
563 };
564
565 class varpool_node;
566 typedef varpool_node *varpool_node_ptr;
567
568
569 /* A varpool node set is a collection of varpool nodes.  A varpool node
570    can appear in multiple sets.  */
571 struct varpool_node_set_def
572 {
573   struct pointer_map_t * map;
574   vec<varpool_node_ptr> nodes;
575 };
576
577 typedef struct cgraph_node_set_def *cgraph_node_set;
578
579
580 typedef struct varpool_node_set_def *varpool_node_set;
581
582
583 /* Iterator structure for cgraph node sets.  */
584 struct cgraph_node_set_iterator
585 {
586   cgraph_node_set set;
587   unsigned index;
588 };
589
590 /* Iterator structure for varpool node sets.  */
591 struct varpool_node_set_iterator
592 {
593   varpool_node_set set;
594   unsigned index;
595 };
596
597 #define DEFCIFCODE(code, type, string)  CIF_ ## code,
598 /* Reasons for inlining failures.  */
599 enum cgraph_inline_failed_t {
600 #include "cif-code.def"
601   CIF_N_REASONS
602 };
603
604 enum cgraph_inline_failed_type_t
605 {
606   CIF_FINAL_NORMAL = 0,
607   CIF_FINAL_ERROR
608 };
609
610 /* Structure containing additional information about an indirect call.  */
611
612 struct GTY(()) cgraph_indirect_call_info
613 {
614   /* When polymorphic is set, this field contains offset where the object which
615      was actually used in the polymorphic resides within a larger structure.
616      If agg_contents is set, the field contains the offset within the aggregate
617      from which the address to call was loaded.  */
618   HOST_WIDE_INT offset;
619   /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set).  */
620   HOST_WIDE_INT otr_token;
621   /* Type of the object from OBJ_TYPE_REF_OBJECT. */
622   tree otr_type, outer_type;
623   /* Index of the parameter that is called.  */
624   int param_index;
625   /* ECF flags determined from the caller.  */
626   int ecf_flags;
627   /* Profile_id of common target obtrained from profile.  */
628   int common_target_id;
629   /* Probability that call will land in function with COMMON_TARGET_ID.  */
630   int common_target_probability;
631
632   /* Set when the call is a virtual call with the parameter being the
633      associated object pointer rather than a simple direct call.  */
634   unsigned polymorphic : 1;
635   /* Set when the call is a call of a pointer loaded from contents of an
636      aggregate at offset.  */
637   unsigned agg_contents : 1;
638   /* Set when this is a call through a member pointer.  */
639   unsigned member_ptr : 1;
640   /* When the previous bit is set, this one determines whether the destination
641      is loaded from a parameter passed by reference. */
642   unsigned by_ref : 1;
643   unsigned int maybe_in_construction : 1;
644   unsigned int maybe_derived_type : 1;
645 };
646
647 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
648   /* Expected number of executions: calculated in profile.c.  */
649   gcov_type count;
650   struct cgraph_node *caller;
651   struct cgraph_node *callee;
652   struct cgraph_edge *prev_caller;
653   struct cgraph_edge *next_caller;
654   struct cgraph_edge *prev_callee;
655   struct cgraph_edge *next_callee;
656   gimple call_stmt;
657   /* Additional information about an indirect call.  Not cleared when an edge
658      becomes direct.  */
659   struct cgraph_indirect_call_info *indirect_info;
660   PTR GTY ((skip (""))) aux;
661   /* When equal to CIF_OK, inline this call.  Otherwise, points to the
662      explanation why function was not inlined.  */
663   enum cgraph_inline_failed_t inline_failed;
664   /* The stmt_uid of call_stmt.  This is used by LTO to recover the call_stmt
665      when the function is serialized in.  */
666   unsigned int lto_stmt_uid;
667   /* Expected frequency of executions within the function.
668      When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
669      per function call.  The range is 0 to CGRAPH_FREQ_MAX.  */
670   int frequency;
671   /* Unique id of the edge.  */
672   int uid;
673   /* Whether this edge was made direct by indirect inlining.  */
674   unsigned int indirect_inlining_edge : 1;
675   /* Whether this edge describes an indirect call with an undetermined
676      callee.  */
677   unsigned int indirect_unknown_callee : 1;
678   /* Whether this edge is still a dangling  */
679   /* True if the corresponding CALL stmt cannot be inlined.  */
680   unsigned int call_stmt_cannot_inline_p : 1;
681   /* Can this call throw externally?  */
682   unsigned int can_throw_external : 1;
683   /* Edges with SPECULATIVE flag represents indirect calls that was
684      speculatively turned into direct (i.e. by profile feedback).
685      The final code sequence will have form:
686
687      if (call_target == expected_fn)
688        expected_fn ();
689      else
690        call_target ();
691
692      Every speculative call is represented by three components attached
693      to a same call statement:
694      1) a direct call (to expected_fn)
695      2) an indirect call (to call_target)
696      3) a IPA_REF_ADDR refrence to expected_fn.
697
698      Optimizers may later redirect direct call to clone, so 1) and 3)
699      do not need to necesarily agree with destination.  */
700   unsigned int speculative : 1;
701 };
702
703 #define CGRAPH_FREQ_BASE 1000
704 #define CGRAPH_FREQ_MAX 100000
705
706 typedef struct cgraph_edge *cgraph_edge_p;
707
708
709 /* The varpool data structure.
710    Each static variable decl has assigned varpool_node.  */
711
712 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
713 public:
714   /* Set when variable is scheduled to be assembled.  */
715   unsigned output : 1;
716
717   /* Set if the variable is dynamically initialized, except for
718      function local statics.   */
719   unsigned dynamically_initialized : 1;
720
721   ENUM_BITFIELD(tls_model) tls_model : 3;
722 };
723
724 /* Every top level asm statement is put into a asm_node.  */
725
726 struct GTY(()) asm_node {
727   /* Next asm node.  */
728   struct asm_node *next;
729   /* String for this asm node.  */
730   tree asm_str;
731   /* Ordering of all cgraph nodes.  */
732   int order;
733 };
734
735 /* Report whether or not THIS symtab node is a function, aka cgraph_node.  */
736
737 template <>
738 template <>
739 inline bool
740 is_a_helper <cgraph_node *>::test (symtab_node *p)
741 {
742   return p->type == SYMTAB_FUNCTION;
743 }
744
745 /* Report whether or not THIS symtab node is a vriable, aka varpool_node.  */
746
747 template <>
748 template <>
749 inline bool
750 is_a_helper <varpool_node *>::test (symtab_node *p)
751 {
752   return p->type == SYMTAB_VARIABLE;
753 }
754
755 extern GTY(()) symtab_node *symtab_nodes;
756 extern GTY(()) int cgraph_n_nodes;
757 extern GTY(()) int cgraph_max_uid;
758 extern GTY(()) int cgraph_edge_max_uid;
759 extern bool cgraph_global_info_ready;
760 enum cgraph_state
761 {
762   /* Frontend is parsing and finalizing functions.  */
763   CGRAPH_STATE_PARSING,
764   /* Callgraph is being constructed.  It is safe to add new functions.  */
765   CGRAPH_STATE_CONSTRUCTION,
766   /* Callgraph is being at LTO time.  */
767   CGRAPH_LTO_STREAMING,
768   /* Callgraph is built and IPA passes are being run.  */
769   CGRAPH_STATE_IPA,
770   /* Callgraph is built and all functions are transformed to SSA form.  */
771   CGRAPH_STATE_IPA_SSA,
772   /* Functions are now ordered and being passed to RTL expanders.  */
773   CGRAPH_STATE_EXPANSION,
774   /* All cgraph expansion is done.  */
775   CGRAPH_STATE_FINISHED
776 };
777 extern enum cgraph_state cgraph_state;
778 extern bool cgraph_function_flags_ready;
779 extern cgraph_node_set cgraph_new_nodes;
780
781 extern GTY(()) struct asm_node *asm_nodes;
782 extern GTY(()) int symtab_order;
783 extern bool cpp_implicit_aliases_done;
784
785 /* Classifcation of symbols WRT partitioning.  */
786 enum symbol_partitioning_class
787 {
788    /* External declarations are ignored by partitioning algorithms and they are
789       added into the boundary later via compute_ltrans_boundary.  */
790    SYMBOL_EXTERNAL,
791    /* Partitioned symbols are pur into one of partitions.  */
792    SYMBOL_PARTITION,
793    /* Duplicated symbols (such as comdat or constant pool references) are
794       copied into every node needing them via add_symbol_to_partition.  */
795    SYMBOL_DUPLICATE
796 };
797
798
799 /* In symtab.c  */
800 void symtab_register_node (symtab_node *);
801 void symtab_unregister_node (symtab_node *);
802 void symtab_remove_from_same_comdat_group (symtab_node *);
803 void symtab_remove_node (symtab_node *);
804 symtab_node *symtab_node_for_asm (const_tree asmname);
805 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
806 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
807 void dump_symtab (FILE *);
808 void debug_symtab (void);
809 void dump_symtab_node (FILE *, symtab_node *);
810 void debug_symtab_node (symtab_node *);
811 void dump_symtab_base (FILE *, symtab_node *);
812 void verify_symtab (void);
813 void verify_symtab_node (symtab_node *);
814 bool verify_symtab_base (symtab_node *);
815 bool symtab_used_from_object_file_p (symtab_node *);
816 void symtab_make_decl_local (tree);
817 symtab_node *symtab_alias_ultimate_target (symtab_node *,
818                                           enum availability *avail = NULL);
819 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
820 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
821 bool symtab_for_node_and_aliases (symtab_node *,
822                                   bool (*) (symtab_node *, void *),
823                                   void *,
824                                   bool);
825 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
826 enum availability symtab_node_availability (symtab_node *);
827 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
828 enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
829
830 /* In cgraph.c  */
831 void dump_cgraph (FILE *);
832 void debug_cgraph (void);
833 void dump_cgraph_node (FILE *, struct cgraph_node *);
834 void debug_cgraph_node (struct cgraph_node *);
835 void cgraph_remove_edge (struct cgraph_edge *);
836 void cgraph_remove_node (struct cgraph_node *);
837 void cgraph_release_function_body (struct cgraph_node *);
838 void release_function_body (tree);
839 void cgraph_node_remove_callees (struct cgraph_node *node);
840 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
841                                         struct cgraph_node *,
842                                         gimple, gcov_type, int);
843 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
844                                                  int, gcov_type, int);
845 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
846 struct cgraph_node * cgraph_create_node (tree);
847 struct cgraph_node * cgraph_create_empty_node (void);
848 struct cgraph_node * cgraph_get_create_node (tree);
849 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
850 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
851                                        HOST_WIDE_INT, tree, tree);
852 struct cgraph_node *cgraph_node_for_asm (tree);
853 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
854 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
855 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
856 struct cgraph_local_info *cgraph_local_info (tree);
857 struct cgraph_global_info *cgraph_global_info (tree);
858 struct cgraph_rtl_info *cgraph_rtl_info (tree);
859 struct cgraph_node *cgraph_create_function_alias (tree, tree);
860 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
861                                          struct cgraph_node *);
862 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
863                                          struct cgraph_edge *);
864
865 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
866 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
867 bool cgraph_only_called_directly_p (struct cgraph_node *);
868
869 bool cgraph_function_possibly_inlined_p (tree);
870 void cgraph_unnest_node (struct cgraph_node *);
871
872 enum availability cgraph_function_body_availability (struct cgraph_node *);
873 void cgraph_add_new_function (tree, bool);
874 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
875 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
876
877 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
878 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
879 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
880 bool cgraph_node_cannot_return (struct cgraph_node *);
881 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
882 bool cgraph_will_be_removed_from_program_if_no_direct_calls
883   (struct cgraph_node *node);
884 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
885   (struct cgraph_node *node);
886 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
887 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
888 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
889                                          bool (*) (struct cgraph_node *, void *),
890                                          void *,
891                                          bool);
892 bool cgraph_for_node_and_aliases (struct cgraph_node *,
893                                   bool (*) (struct cgraph_node *, void *),
894                                   void *, bool);
895 vec<cgraph_edge_p>  collect_callers_of_node (struct cgraph_node *node);
896 void verify_cgraph (void);
897 void verify_cgraph_node (struct cgraph_node *);
898 void cgraph_mark_address_taken_node (struct cgraph_node *);
899
900 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
901 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
902 typedef void (*varpool_node_hook)(varpool_node *, void *);
903 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
904                                   void *);
905 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
906                                   void *);
907 struct cgraph_edge_hook_list;
908 struct cgraph_node_hook_list;
909 struct varpool_node_hook_list;
910 struct cgraph_2edge_hook_list;
911 struct cgraph_2node_hook_list;
912 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
913 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
914 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
915                                                             void *);
916 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
917 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
918                                                               void *);
919 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
920 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
921                                                                   void *);
922 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
923 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
924                                                                     void *);
925 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
926 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
927 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
928 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
929 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
930 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
931 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
932 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
933                                            enum availability *avail = NULL);
934 bool cgraph_get_body (struct cgraph_node *node);
935 struct cgraph_edge *
936 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
937                                  struct cgraph_node *,
938                                  gcov_type, int);
939 void cgraph_speculative_call_info (struct cgraph_edge *,
940                                    struct cgraph_edge *&,
941                                    struct cgraph_edge *&,
942                                    struct ipa_ref *&);
943 extern bool gimple_check_call_matching_types (gimple, tree, bool);
944
945 /* In cgraphunit.c  */
946 struct asm_node *add_asm_node (tree);
947 extern FILE *cgraph_dump_file;
948 void cgraph_finalize_function (tree, bool);
949 void finalize_compilation_unit (void);
950 void compile (void);
951 void init_cgraph (void);
952 void cgraph_process_new_functions (void);
953 void cgraph_process_same_body_aliases (void);
954 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
955 /*  Initialize datastructures so DECL is a function in lowered gimple form.
956     IN_SSA is true if the gimple is in SSA.  */
957 basic_block init_lowered_empty_function (tree, bool);
958 void cgraph_reset_node (struct cgraph_node *);
959 bool expand_thunk (struct cgraph_node *, bool, bool);
960 void cgraph_make_wrapper (struct cgraph_node *source,
961                           struct cgraph_node *target);
962
963 /* In cgraphclones.c  */
964
965 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
966                                         struct cgraph_node *, gimple,
967                                         unsigned, gcov_type, int, bool);
968 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
969                                         int, bool, vec<cgraph_edge_p>,
970                                         bool, struct cgraph_node *, bitmap);
971 tree clone_function_name (tree decl, const char *);
972 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
973                                                   vec<cgraph_edge_p>,
974                                                   vec<ipa_replace_map_p, va_gc> *tree_map,
975                                                   bitmap args_to_skip,
976                                                   const char *clone_name);
977 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
978 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
979 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
980                                             bool update_speculative = true);
981 void cgraph_create_edge_including_clones (struct cgraph_node *,
982                                           struct cgraph_node *,
983                                           gimple, gimple, gcov_type, int,
984                                           cgraph_inline_failed_t);
985 void cgraph_materialize_all_clones (void);
986 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
987                 tree, vec<cgraph_edge_p>, bitmap);
988 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
989                                                 vec<cgraph_edge_p>,
990                                                 vec<ipa_replace_map_p, va_gc> *,
991                                                 bitmap, bool, bitmap,
992                                                 basic_block, const char *);
993 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
994                                bool, bitmap, bool, bitmap, basic_block);
995 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
996
997 /* In cgraphbuild.c  */
998 unsigned int rebuild_cgraph_edges (void);
999 void cgraph_rebuild_references (void);
1000 int compute_call_stmt_bb_frequency (tree, basic_block bb);
1001 void record_references_in_initializer (tree, bool);
1002 void ipa_record_stmt_references (struct cgraph_node *, gimple);
1003
1004 /* In ipa.c  */
1005 bool symtab_remove_unreachable_nodes (bool, FILE *);
1006 cgraph_node_set cgraph_node_set_new (void);
1007 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
1008                                                struct cgraph_node *);
1009 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
1010 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
1011 void dump_cgraph_node_set (FILE *, cgraph_node_set);
1012 void debug_cgraph_node_set (cgraph_node_set);
1013 void free_cgraph_node_set (cgraph_node_set);
1014 void cgraph_build_static_cdtor (char which, tree body, int priority);
1015
1016 varpool_node_set varpool_node_set_new (void);
1017 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
1018                                                  varpool_node *);
1019 void varpool_node_set_add (varpool_node_set, varpool_node *);
1020 void varpool_node_set_remove (varpool_node_set, varpool_node *);
1021 void dump_varpool_node_set (FILE *, varpool_node_set);
1022 void debug_varpool_node_set (varpool_node_set);
1023 void free_varpool_node_set (varpool_node_set);
1024 void ipa_discover_readonly_nonaddressable_vars (void);
1025 bool varpool_externally_visible_p (varpool_node *);
1026
1027 /* In ipa-visibility.c */
1028 bool cgraph_local_node_p (struct cgraph_node *);
1029 bool address_taken_from_non_vtable_p (symtab_node *node);
1030
1031
1032 /* In predict.c  */
1033 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
1034 bool cgraph_optimize_for_size_p (struct cgraph_node *);
1035
1036 /* In varpool.c  */
1037 varpool_node *varpool_create_empty_node (void);
1038 varpool_node *varpool_node_for_decl (tree);
1039 varpool_node *varpool_node_for_asm (tree asmname);
1040 void varpool_mark_needed_node (varpool_node *);
1041 void debug_varpool (void);
1042 void dump_varpool (FILE *);
1043 void dump_varpool_node (FILE *, varpool_node *);
1044
1045 void varpool_finalize_decl (tree);
1046 enum availability cgraph_variable_initializer_availability (varpool_node *);
1047 void cgraph_make_node_local (struct cgraph_node *);
1048 bool cgraph_node_can_be_local_p (struct cgraph_node *);
1049
1050
1051 void varpool_remove_node (varpool_node *node);
1052 void varpool_finalize_named_section_flags (varpool_node *node);
1053 bool varpool_output_variables (void);
1054 bool varpool_assemble_decl (varpool_node *node);
1055 void varpool_analyze_node (varpool_node *);
1056 varpool_node * varpool_extra_name_alias (tree, tree);
1057 varpool_node * varpool_create_variable_alias (tree, tree);
1058 void varpool_reset_queue (void);
1059 tree ctor_for_folding (tree);
1060 bool varpool_for_node_and_aliases (varpool_node *,
1061                                    bool (*) (varpool_node *, void *),
1062                                    void *, bool);
1063 void varpool_add_new_variable (tree);
1064 void symtab_initialize_asm_name_hash (void);
1065 void symtab_prevail_in_asm_name_hash (symtab_node *node);
1066 void varpool_remove_initializer (varpool_node *);
1067
1068 /* In cgraph.c */
1069 extern void change_decl_assembler_name (tree, tree);
1070
1071 /* Return symbol table node associated with DECL, if any,
1072    and NULL otherwise.  */
1073
1074 static inline symtab_node *
1075 symtab_get_node (const_tree decl)
1076 {
1077 #ifdef ENABLE_CHECKING
1078   /* Check that we are called for sane type of object - functions
1079      and static or external variables.  */
1080   gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
1081                        || (TREE_CODE (decl) == VAR_DECL
1082                            && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1083                                || in_lto_p)));
1084   /* Check that the mapping is sane - perhaps this check can go away,
1085      but at the moment frontends tends to corrupt the mapping by calling
1086      memcpy/memset on the tree nodes.  */
1087   gcc_checking_assert (!decl->decl_with_vis.symtab_node
1088                        || decl->decl_with_vis.symtab_node->decl == decl);
1089 #endif
1090   return decl->decl_with_vis.symtab_node;
1091 }
1092
1093 /* Return callgraph node for given symbol and check it is a function. */
1094 static inline struct cgraph_node *
1095 cgraph (symtab_node *node)
1096 {
1097   gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
1098   return (struct cgraph_node *)node;
1099 }
1100
1101 /* Return varpool node for given symbol and check it is a variable.  */
1102 static inline varpool_node *
1103 varpool (symtab_node *node)
1104 {
1105   gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
1106   return (varpool_node *)node;
1107 }
1108
1109 /* Return callgraph node for given symbol and check it is a function. */
1110 static inline struct cgraph_node *
1111 cgraph_get_node (const_tree decl)
1112 {
1113   gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1114   return cgraph (symtab_get_node (decl));
1115 }
1116
1117 /* Return varpool node for given symbol and check it is a function. */
1118 static inline varpool_node *
1119 varpool_get_node (const_tree decl)
1120 {
1121   gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1122   return varpool (symtab_get_node (decl));
1123 }
1124
1125 /* Walk all symbols.  */
1126 #define FOR_EACH_SYMBOL(node) \
1127    for ((node) = symtab_nodes; (node); (node) = (node)->next)
1128
1129 /* Return first static symbol with definition.  */
1130 static inline symtab_node *
1131 symtab_first_defined_symbol (void)
1132 {
1133   symtab_node *node;
1134
1135   for (node = symtab_nodes; node; node = node->next)
1136     if (node->definition)
1137       return node;
1138
1139   return NULL;
1140 }
1141
1142 /* Return next reachable static symbol with initializer after NODE.  */
1143 static inline symtab_node *
1144 symtab_next_defined_symbol (symtab_node *node)
1145 {
1146   symtab_node *node1 = node->next;
1147
1148   for (; node1; node1 = node1->next)
1149     if (node1->definition)
1150       return node1;
1151
1152   return NULL;
1153 }
1154 /* Walk all symbols with definitions in current unit.  */
1155 #define FOR_EACH_DEFINED_SYMBOL(node) \
1156    for ((node) = symtab_first_defined_symbol (); (node); \
1157         (node) = symtab_next_defined_symbol (node))
1158
1159 /* Return first variable.  */
1160 static inline varpool_node *
1161 varpool_first_variable (void)
1162 {
1163   symtab_node *node;
1164   for (node = symtab_nodes; node; node = node->next)
1165     if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1166       return vnode;
1167   return NULL;
1168 }
1169
1170 /* Return next variable after NODE.  */
1171 static inline varpool_node *
1172 varpool_next_variable (varpool_node *node)
1173 {
1174   symtab_node *node1 = node->next;
1175   for (; node1; node1 = node1->next)
1176     if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1177       return vnode1;
1178   return NULL;
1179 }
1180 /* Walk all variables.  */
1181 #define FOR_EACH_VARIABLE(node) \
1182    for ((node) = varpool_first_variable (); \
1183         (node); \
1184         (node) = varpool_next_variable ((node)))
1185
1186 /* Return first static variable with initializer.  */
1187 static inline varpool_node *
1188 varpool_first_static_initializer (void)
1189 {
1190   symtab_node *node;
1191   for (node = symtab_nodes; node; node = node->next)
1192     {
1193       varpool_node *vnode = dyn_cast <varpool_node *> (node);
1194       if (vnode && DECL_INITIAL (node->decl))
1195         return vnode;
1196     }
1197   return NULL;
1198 }
1199
1200 /* Return next static variable with initializer after NODE.  */
1201 static inline varpool_node *
1202 varpool_next_static_initializer (varpool_node *node)
1203 {
1204   symtab_node *node1 = node->next;
1205   for (; node1; node1 = node1->next)
1206     {
1207       varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1208       if (vnode1 && DECL_INITIAL (node1->decl))
1209         return vnode1;
1210     }
1211   return NULL;
1212 }
1213
1214 /* Walk all static variables with initializer set.  */
1215 #define FOR_EACH_STATIC_INITIALIZER(node) \
1216    for ((node) = varpool_first_static_initializer (); (node); \
1217         (node) = varpool_next_static_initializer (node))
1218
1219 /* Return first static variable with definition.  */
1220 static inline varpool_node *
1221 varpool_first_defined_variable (void)
1222 {
1223   symtab_node *node;
1224   for (node = symtab_nodes; node; node = node->next)
1225     {
1226       varpool_node *vnode = dyn_cast <varpool_node *> (node);
1227       if (vnode && vnode->definition)
1228         return vnode;
1229     }
1230   return NULL;
1231 }
1232
1233 /* Return next static variable with definition after NODE.  */
1234 static inline varpool_node *
1235 varpool_next_defined_variable (varpool_node *node)
1236 {
1237   symtab_node *node1 = node->next;
1238   for (; node1; node1 = node1->next)
1239     {
1240       varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1241       if (vnode1 && vnode1->definition)
1242         return vnode1;
1243     }
1244   return NULL;
1245 }
1246 /* Walk all variables with definitions in current unit.  */
1247 #define FOR_EACH_DEFINED_VARIABLE(node) \
1248    for ((node) = varpool_first_defined_variable (); (node); \
1249         (node) = varpool_next_defined_variable (node))
1250
1251 /* Return first function with body defined.  */
1252 static inline struct cgraph_node *
1253 cgraph_first_defined_function (void)
1254 {
1255   symtab_node *node;
1256   for (node = symtab_nodes; node; node = node->next)
1257     {
1258       cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1259       if (cn && cn->definition)
1260         return cn;
1261     }
1262   return NULL;
1263 }
1264
1265 /* Return next function with body defined after NODE.  */
1266 static inline struct cgraph_node *
1267 cgraph_next_defined_function (struct cgraph_node *node)
1268 {
1269   symtab_node *node1 = node->next;
1270   for (; node1; node1 = node1->next)
1271     {
1272       cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1273       if (cn1 && cn1->definition)
1274         return cn1;
1275     }
1276   return NULL;
1277 }
1278
1279 /* Walk all functions with body defined.  */
1280 #define FOR_EACH_DEFINED_FUNCTION(node) \
1281    for ((node) = cgraph_first_defined_function (); (node); \
1282         (node) = cgraph_next_defined_function ((node)))
1283
1284 /* Return first function.  */
1285 static inline struct cgraph_node *
1286 cgraph_first_function (void)
1287 {
1288   symtab_node *node;
1289   for (node = symtab_nodes; node; node = node->next)
1290     if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1291       return cn;
1292   return NULL;
1293 }
1294
1295 /* Return next function.  */
1296 static inline struct cgraph_node *
1297 cgraph_next_function (struct cgraph_node *node)
1298 {
1299   symtab_node *node1 = node->next;
1300   for (; node1; node1 = node1->next)
1301     if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1302       return cn1;
1303   return NULL;
1304 }
1305 /* Walk all functions.  */
1306 #define FOR_EACH_FUNCTION(node) \
1307    for ((node) = cgraph_first_function (); (node); \
1308         (node) = cgraph_next_function ((node)))
1309
1310 /* Return true when NODE is a function with Gimple body defined
1311    in current unit.  Functions can also be define externally or they
1312    can be thunks with no Gimple representation.
1313
1314    Note that at WPA stage, the function body may not be present in memory.  */
1315
1316 static inline bool
1317 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1318 {
1319   return node->definition && !node->thunk.thunk_p && !node->alias;
1320 }
1321
1322 /* Return first function with body defined.  */
1323 static inline struct cgraph_node *
1324 cgraph_first_function_with_gimple_body (void)
1325 {
1326   symtab_node *node;
1327   for (node = symtab_nodes; node; node = node->next)
1328     {
1329       cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1330       if (cn && cgraph_function_with_gimple_body_p (cn))
1331         return cn;
1332     }
1333   return NULL;
1334 }
1335
1336 /* Return next reachable static variable with initializer after NODE.  */
1337 static inline struct cgraph_node *
1338 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1339 {
1340   symtab_node *node1 = node->next;
1341   for (; node1; node1 = node1->next)
1342     {
1343       cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1344       if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1345         return cn1;
1346     }
1347   return NULL;
1348 }
1349
1350 /* Walk all functions with body defined.  */
1351 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1352    for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1353         (node) = cgraph_next_function_with_gimple_body (node))
1354
1355 /* Create a new static variable of type TYPE.  */
1356 tree add_new_static_var (tree type);
1357
1358 /* Return true if iterator CSI points to nothing.  */
1359 static inline bool
1360 csi_end_p (cgraph_node_set_iterator csi)
1361 {
1362   return csi.index >= csi.set->nodes.length ();
1363 }
1364
1365 /* Advance iterator CSI.  */
1366 static inline void
1367 csi_next (cgraph_node_set_iterator *csi)
1368 {
1369   csi->index++;
1370 }
1371
1372 /* Return the node pointed to by CSI.  */
1373 static inline struct cgraph_node *
1374 csi_node (cgraph_node_set_iterator csi)
1375 {
1376   return csi.set->nodes[csi.index];
1377 }
1378
1379 /* Return an iterator to the first node in SET.  */
1380 static inline cgraph_node_set_iterator
1381 csi_start (cgraph_node_set set)
1382 {
1383   cgraph_node_set_iterator csi;
1384
1385   csi.set = set;
1386   csi.index = 0;
1387   return csi;
1388 }
1389
1390 /* Return true if SET contains NODE.  */
1391 static inline bool
1392 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1393 {
1394   cgraph_node_set_iterator csi;
1395   csi = cgraph_node_set_find (set, node);
1396   return !csi_end_p (csi);
1397 }
1398
1399 /* Return number of nodes in SET.  */
1400 static inline size_t
1401 cgraph_node_set_size (cgraph_node_set set)
1402 {
1403   return set->nodes.length ();
1404 }
1405
1406 /* Return true if iterator VSI points to nothing.  */
1407 static inline bool
1408 vsi_end_p (varpool_node_set_iterator vsi)
1409 {
1410   return vsi.index >= vsi.set->nodes.length ();
1411 }
1412
1413 /* Advance iterator VSI.  */
1414 static inline void
1415 vsi_next (varpool_node_set_iterator *vsi)
1416 {
1417   vsi->index++;
1418 }
1419
1420 /* Return the node pointed to by VSI.  */
1421 static inline varpool_node *
1422 vsi_node (varpool_node_set_iterator vsi)
1423 {
1424   return vsi.set->nodes[vsi.index];
1425 }
1426
1427 /* Return an iterator to the first node in SET.  */
1428 static inline varpool_node_set_iterator
1429 vsi_start (varpool_node_set set)
1430 {
1431   varpool_node_set_iterator vsi;
1432
1433   vsi.set = set;
1434   vsi.index = 0;
1435   return vsi;
1436 }
1437
1438 /* Return true if SET contains NODE.  */
1439 static inline bool
1440 varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
1441 {
1442   varpool_node_set_iterator vsi;
1443   vsi = varpool_node_set_find (set, node);
1444   return !vsi_end_p (vsi);
1445 }
1446
1447 /* Return number of nodes in SET.  */
1448 static inline size_t
1449 varpool_node_set_size (varpool_node_set set)
1450 {
1451   return set->nodes.length ();
1452 }
1453
1454 /* Uniquize all constants that appear in memory.
1455    Each constant in memory thus far output is recorded
1456    in `const_desc_table'.  */
1457
1458 struct GTY(()) constant_descriptor_tree {
1459   /* A MEM for the constant.  */
1460   rtx rtl;
1461
1462   /* The value of the constant.  */
1463   tree value;
1464
1465   /* Hash of value.  Computing the hash from value each time
1466      hashfn is called can't work properly, as that means recursive
1467      use of the hash table during hash table expansion.  */
1468   hashval_t hash;
1469 };
1470
1471 /* Return true if set is nonempty.  */
1472 static inline bool
1473 cgraph_node_set_nonempty_p (cgraph_node_set set)
1474 {
1475   return !set->nodes.is_empty ();
1476 }
1477
1478 /* Return true if set is nonempty.  */
1479 static inline bool
1480 varpool_node_set_nonempty_p (varpool_node_set set)
1481 {
1482   return !set->nodes.is_empty ();
1483 }
1484
1485 /* Return true when function NODE is only called directly or it has alias.
1486    i.e. it is not externally visible, address was not taken and
1487    it is not used in any other non-standard way.  */
1488
1489 static inline bool
1490 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1491 {
1492   gcc_assert (!node->global.inlined_to);
1493   return (!node->force_output && !node->address_taken
1494           && !node->used_from_other_partition
1495           && !DECL_VIRTUAL_P (node->decl)
1496           && !DECL_STATIC_CONSTRUCTOR (node->decl)
1497           && !DECL_STATIC_DESTRUCTOR (node->decl)
1498           && !node->externally_visible);
1499 }
1500
1501 /* Return true when function NODE can be removed from callgraph
1502    if all direct calls are eliminated.  */
1503
1504 static inline bool
1505 varpool_can_remove_if_no_refs (varpool_node *node)
1506 {
1507   if (DECL_EXTERNAL (node->decl))
1508     return true;
1509   return (!node->force_output && !node->used_from_other_partition
1510           && ((DECL_COMDAT (node->decl)
1511                && !node->forced_by_abi
1512                && !symtab_used_from_object_file_p (node))
1513               || !node->externally_visible
1514               || DECL_HAS_VALUE_EXPR_P (node->decl)));
1515 }
1516
1517 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1518    i.e. if the variable is not externally visible or not used in some magic
1519    way (asm statement or such).
1520    The magic uses are all summarized in force_output flag.  */
1521
1522 static inline bool
1523 varpool_all_refs_explicit_p (varpool_node *vnode)
1524 {
1525   return (vnode->definition
1526           && !vnode->externally_visible
1527           && !vnode->used_from_other_partition
1528           && !vnode->force_output);
1529 }
1530
1531 /* Constant pool accessor function.  */
1532 htab_t constant_pool_htab (void);
1533
1534 /* FIXME: inappropriate dependency of cgraph on IPA.  */
1535 #include "ipa-ref-inline.h"
1536
1537 /* Return node that alias N is aliasing.  */
1538
1539 static inline symtab_node *
1540 symtab_alias_target (symtab_node *n)
1541 {
1542   struct ipa_ref *ref;
1543   ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1544   gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1545   return ref->referred;
1546 }
1547
1548 static inline struct cgraph_node *
1549 cgraph_alias_target (struct cgraph_node *n)
1550 {
1551   return dyn_cast <cgraph_node *> (symtab_alias_target (n));
1552 }
1553
1554 static inline varpool_node *
1555 varpool_alias_target (varpool_node *n)
1556 {
1557   return dyn_cast <varpool_node *> (symtab_alias_target (n));
1558 }
1559
1560 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1561    Do not walk through thunks.
1562    When AVAILABILITY is non-NULL, get minimal availability in the chain.  */
1563
1564 static inline struct cgraph_node *
1565 cgraph_function_or_thunk_node (struct cgraph_node *node,
1566                                enum availability *availability = NULL)
1567 {
1568   struct cgraph_node *n;
1569
1570   n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node,
1571                                                               availability));
1572   if (!n && availability)
1573     *availability = AVAIL_NOT_AVAILABLE;
1574   return n;
1575 }
1576 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1577    Do not walk through thunks.
1578    When AVAILABILITY is non-NULL, get minimal availability in the chain.  */
1579
1580 static inline varpool_node *
1581 varpool_variable_node (varpool_node *node,
1582                        enum availability *availability = NULL)
1583 {
1584   varpool_node *n;
1585
1586   if (node)
1587     n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node,
1588                                                                  availability));
1589   else
1590     n = NULL;
1591
1592   if (!n && availability)
1593     *availability = AVAIL_NOT_AVAILABLE;
1594   return n;
1595 }
1596
1597 /* Return true when the edge E represents a direct recursion.  */
1598 static inline bool
1599 cgraph_edge_recursive_p (struct cgraph_edge *e)
1600 {
1601   struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1602   if (e->caller->global.inlined_to)
1603     return e->caller->global.inlined_to->decl == callee->decl;
1604   else
1605     return e->caller->decl == callee->decl;
1606 }
1607
1608 /* Return true if the TM_CLONE bit is set for a given FNDECL.  */
1609 static inline bool
1610 decl_is_tm_clone (const_tree fndecl)
1611 {
1612   struct cgraph_node *n = cgraph_get_node (fndecl);
1613   if (n)
1614     return n->tm_clone;
1615   return false;
1616 }
1617
1618 /* Likewise indicate that a node is needed, i.e. reachable via some
1619    external means.  */
1620
1621 static inline void
1622 cgraph_mark_force_output_node (struct cgraph_node *node)
1623 {
1624   node->force_output = 1;
1625   gcc_checking_assert (!node->global.inlined_to);
1626 }
1627
1628 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1629    or abstract function kept for debug info purposes only.  */
1630
1631 static inline bool
1632 symtab_real_symbol_p (symtab_node *node)
1633 {
1634   struct cgraph_node *cnode;
1635
1636   if (DECL_ABSTRACT (node->decl))
1637     return false;
1638   if (!is_a <cgraph_node *> (node))
1639     return true;
1640   cnode = cgraph (node);
1641   if (cnode->global.inlined_to)
1642     return false;
1643   return true;
1644 }
1645
1646 /* Return true if NODE can be discarded by linker from the binary.  */
1647
1648 static inline bool
1649 symtab_can_be_discarded (symtab_node *node)
1650 {
1651   return (DECL_EXTERNAL (node->decl)
1652           || (node->get_comdat_group ()
1653               && node->resolution != LDPR_PREVAILING_DEF
1654               && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1655               && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1656 }
1657
1658 /* Return true if NODE is local to a particular COMDAT group, and must not
1659    be named from outside the COMDAT.  This is used for C++ decloned
1660    constructors.  */
1661
1662 static inline bool
1663 symtab_comdat_local_p (symtab_node *node)
1664 {
1665   return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1666 }
1667
1668 /* Return true if ONE and TWO are part of the same COMDAT group.  */
1669
1670 static inline bool
1671 symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1672 {
1673   if (cgraph_node *cn = dyn_cast <cgraph_node *> (one))
1674     {
1675       if (cn->global.inlined_to)
1676         one = cn->global.inlined_to;
1677     }
1678   if (cgraph_node *cn = dyn_cast <cgraph_node *> (two))
1679     {
1680       if (cn->global.inlined_to)
1681         two = cn->global.inlined_to;
1682     }
1683
1684   return one->get_comdat_group () == two->get_comdat_group ();
1685 }
1686 #endif  /* GCC_CGRAPH_H  */