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