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