c-common.c (handle_tls_model_attribute): Use set_decl_tls_model.
[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   ENUM_BITFIELD(tls_model) tls_model : 3;
713 };
714
715 /* Every top level asm statement is put into a asm_node.  */
716
717 struct GTY(()) asm_node {
718   /* Next asm node.  */
719   struct asm_node *next;
720   /* String for this asm node.  */
721   tree asm_str;
722   /* Ordering of all cgraph nodes.  */
723   int order;
724 };
725
726 /* Report whether or not THIS symtab node is a function, aka cgraph_node.  */
727
728 template <>
729 template <>
730 inline bool
731 is_a_helper <cgraph_node *>::test (symtab_node *p)
732 {
733   return p->type == SYMTAB_FUNCTION;
734 }
735
736 /* Report whether or not THIS symtab node is a vriable, aka varpool_node.  */
737
738 template <>
739 template <>
740 inline bool
741 is_a_helper <varpool_node *>::test (symtab_node *p)
742 {
743   return p->type == SYMTAB_VARIABLE;
744 }
745
746 extern GTY(()) symtab_node *symtab_nodes;
747 extern GTY(()) int cgraph_n_nodes;
748 extern GTY(()) int cgraph_max_uid;
749 extern GTY(()) int cgraph_edge_max_uid;
750 extern bool cgraph_global_info_ready;
751 enum cgraph_state
752 {
753   /* Frontend is parsing and finalizing functions.  */
754   CGRAPH_STATE_PARSING,
755   /* Callgraph is being constructed.  It is safe to add new functions.  */
756   CGRAPH_STATE_CONSTRUCTION,
757   /* Callgraph is being at LTO time.  */
758   CGRAPH_LTO_STREAMING,
759   /* Callgraph is built and IPA passes are being run.  */
760   CGRAPH_STATE_IPA,
761   /* Callgraph is built and all functions are transformed to SSA form.  */
762   CGRAPH_STATE_IPA_SSA,
763   /* Functions are now ordered and being passed to RTL expanders.  */
764   CGRAPH_STATE_EXPANSION,
765   /* All cgraph expansion is done.  */
766   CGRAPH_STATE_FINISHED
767 };
768 extern enum cgraph_state cgraph_state;
769 extern bool cgraph_function_flags_ready;
770 extern cgraph_node_set cgraph_new_nodes;
771
772 extern GTY(()) struct asm_node *asm_nodes;
773 extern GTY(()) int symtab_order;
774 extern bool cpp_implicit_aliases_done;
775
776 /* Classifcation of symbols WRT partitioning.  */
777 enum symbol_partitioning_class
778 {
779    /* External declarations are ignored by partitioning algorithms and they are
780       added into the boundary later via compute_ltrans_boundary.  */
781    SYMBOL_EXTERNAL,
782    /* Partitioned symbols are pur into one of partitions.  */
783    SYMBOL_PARTITION,
784    /* Duplicated symbols (such as comdat or constant pool references) are
785       copied into every node needing them via add_symbol_to_partition.  */
786    SYMBOL_DUPLICATE
787 };
788
789
790 /* In symtab.c  */
791 void symtab_register_node (symtab_node *);
792 void symtab_unregister_node (symtab_node *);
793 void symtab_remove_from_same_comdat_group (symtab_node *);
794 void symtab_remove_node (symtab_node *);
795 symtab_node *symtab_node_for_asm (const_tree asmname);
796 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
797 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
798 void dump_symtab (FILE *);
799 void debug_symtab (void);
800 void dump_symtab_node (FILE *, symtab_node *);
801 void debug_symtab_node (symtab_node *);
802 void dump_symtab_base (FILE *, symtab_node *);
803 void verify_symtab (void);
804 void verify_symtab_node (symtab_node *);
805 bool verify_symtab_base (symtab_node *);
806 bool symtab_used_from_object_file_p (symtab_node *);
807 void symtab_make_decl_local (tree);
808 symtab_node *symtab_alias_ultimate_target (symtab_node *,
809                                           enum availability *avail = NULL);
810 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
811 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
812 bool symtab_for_node_and_aliases (symtab_node *,
813                                   bool (*) (symtab_node *, void *),
814                                   void *,
815                                   bool);
816 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
817 enum availability symtab_node_availability (symtab_node *);
818 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
819 enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
820
821 /* In cgraph.c  */
822 void dump_cgraph (FILE *);
823 void debug_cgraph (void);
824 void dump_cgraph_node (FILE *, struct cgraph_node *);
825 void debug_cgraph_node (struct cgraph_node *);
826 void cgraph_remove_edge (struct cgraph_edge *);
827 void cgraph_remove_node (struct cgraph_node *);
828 void cgraph_release_function_body (struct cgraph_node *);
829 void release_function_body (tree);
830 void cgraph_node_remove_callees (struct cgraph_node *node);
831 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
832                                         struct cgraph_node *,
833                                         gimple, gcov_type, int);
834 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
835                                                  int, gcov_type, int);
836 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
837 struct cgraph_node * cgraph_create_node (tree);
838 struct cgraph_node * cgraph_create_empty_node (void);
839 struct cgraph_node * cgraph_get_create_node (tree);
840 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
841 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
842                                        HOST_WIDE_INT, tree, tree);
843 struct cgraph_node *cgraph_node_for_asm (tree);
844 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
845 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
846 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
847 struct cgraph_local_info *cgraph_local_info (tree);
848 struct cgraph_global_info *cgraph_global_info (tree);
849 struct cgraph_rtl_info *cgraph_rtl_info (tree);
850 struct cgraph_node *cgraph_create_function_alias (tree, tree);
851 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
852                                          struct cgraph_node *);
853 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
854                                          struct cgraph_edge *);
855
856 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
857 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
858 bool cgraph_only_called_directly_p (struct cgraph_node *);
859
860 bool cgraph_function_possibly_inlined_p (tree);
861 void cgraph_unnest_node (struct cgraph_node *);
862
863 enum availability cgraph_function_body_availability (struct cgraph_node *);
864 void cgraph_add_new_function (tree, bool);
865 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
866 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
867
868 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
869 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
870 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
871 bool cgraph_node_cannot_return (struct cgraph_node *);
872 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
873 bool cgraph_will_be_removed_from_program_if_no_direct_calls
874   (struct cgraph_node *node);
875 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
876   (struct cgraph_node *node);
877 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
878 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
879 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
880                                          bool (*) (struct cgraph_node *, void *),
881                                          void *,
882                                          bool);
883 bool cgraph_for_node_and_aliases (struct cgraph_node *,
884                                   bool (*) (struct cgraph_node *, void *),
885                                   void *, bool);
886 vec<cgraph_edge_p>  collect_callers_of_node (struct cgraph_node *node);
887 void verify_cgraph (void);
888 void verify_cgraph_node (struct cgraph_node *);
889 void cgraph_mark_address_taken_node (struct cgraph_node *);
890
891 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
892 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
893 typedef void (*varpool_node_hook)(varpool_node *, void *);
894 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
895                                   void *);
896 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
897                                   void *);
898 struct cgraph_edge_hook_list;
899 struct cgraph_node_hook_list;
900 struct varpool_node_hook_list;
901 struct cgraph_2edge_hook_list;
902 struct cgraph_2node_hook_list;
903 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
904 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
905 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
906                                                             void *);
907 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
908 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
909                                                               void *);
910 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
911 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
912                                                                   void *);
913 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
914 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
915                                                                     void *);
916 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
917 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
918 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
919 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
920 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
921 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
922 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
923 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
924                                            enum availability *avail = NULL);
925 bool cgraph_get_body (struct cgraph_node *node);
926 struct cgraph_edge *
927 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
928                                  struct cgraph_node *,
929                                  gcov_type, int);
930 void cgraph_speculative_call_info (struct cgraph_edge *,
931                                    struct cgraph_edge *&,
932                                    struct cgraph_edge *&,
933                                    struct ipa_ref *&);
934 extern bool gimple_check_call_matching_types (gimple, tree, bool);
935
936 /* In cgraphunit.c  */
937 struct asm_node *add_asm_node (tree);
938 extern FILE *cgraph_dump_file;
939 void cgraph_finalize_function (tree, bool);
940 void finalize_compilation_unit (void);
941 void compile (void);
942 void init_cgraph (void);
943 void cgraph_process_new_functions (void);
944 void cgraph_process_same_body_aliases (void);
945 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
946 /*  Initialize datastructures so DECL is a function in lowered gimple form.
947     IN_SSA is true if the gimple is in SSA.  */
948 basic_block init_lowered_empty_function (tree, bool);
949 void cgraph_reset_node (struct cgraph_node *);
950 bool expand_thunk (struct cgraph_node *, bool, bool);
951 void cgraph_make_wrapper (struct cgraph_node *source,
952                           struct cgraph_node *target);
953
954 /* In cgraphclones.c  */
955
956 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
957                                         struct cgraph_node *, gimple,
958                                         unsigned, gcov_type, int, bool);
959 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
960                                         int, bool, vec<cgraph_edge_p>,
961                                         bool, struct cgraph_node *, bitmap);
962 tree clone_function_name (tree decl, const char *);
963 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
964                                                   vec<cgraph_edge_p>,
965                                                   vec<ipa_replace_map_p, va_gc> *tree_map,
966                                                   bitmap args_to_skip,
967                                                   const char *clone_name);
968 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
969 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
970 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
971                                             bool update_speculative = true);
972 void cgraph_create_edge_including_clones (struct cgraph_node *,
973                                           struct cgraph_node *,
974                                           gimple, gimple, gcov_type, int,
975                                           cgraph_inline_failed_t);
976 void cgraph_materialize_all_clones (void);
977 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
978                 tree, vec<cgraph_edge_p>, bitmap);
979 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
980                                                 vec<cgraph_edge_p>,
981                                                 vec<ipa_replace_map_p, va_gc> *,
982                                                 bitmap, bool, bitmap,
983                                                 basic_block, const char *);
984 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
985                                bool, bitmap, bool, bitmap, basic_block);
986 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
987
988 /* In cgraphbuild.c  */
989 unsigned int rebuild_cgraph_edges (void);
990 void cgraph_rebuild_references (void);
991 int compute_call_stmt_bb_frequency (tree, basic_block bb);
992 void record_references_in_initializer (tree, bool);
993 void ipa_record_stmt_references (struct cgraph_node *, gimple);
994
995 /* In ipa.c  */
996 bool symtab_remove_unreachable_nodes (bool, FILE *);
997 cgraph_node_set cgraph_node_set_new (void);
998 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
999                                                struct cgraph_node *);
1000 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
1001 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
1002 void dump_cgraph_node_set (FILE *, cgraph_node_set);
1003 void debug_cgraph_node_set (cgraph_node_set);
1004 void free_cgraph_node_set (cgraph_node_set);
1005 void cgraph_build_static_cdtor (char which, tree body, int priority);
1006
1007 varpool_node_set varpool_node_set_new (void);
1008 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
1009                                                  varpool_node *);
1010 void varpool_node_set_add (varpool_node_set, varpool_node *);
1011 void varpool_node_set_remove (varpool_node_set, varpool_node *);
1012 void dump_varpool_node_set (FILE *, varpool_node_set);
1013 void debug_varpool_node_set (varpool_node_set);
1014 void free_varpool_node_set (varpool_node_set);
1015 void ipa_discover_readonly_nonaddressable_vars (void);
1016 bool varpool_externally_visible_p (varpool_node *);
1017
1018 /* In ipa-visibility.c */
1019 bool cgraph_local_node_p (struct cgraph_node *);
1020 bool address_taken_from_non_vtable_p (symtab_node *node);
1021
1022
1023 /* In predict.c  */
1024 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
1025 bool cgraph_optimize_for_size_p (struct cgraph_node *);
1026
1027 /* In varpool.c  */
1028 varpool_node *varpool_create_empty_node (void);
1029 varpool_node *varpool_node_for_decl (tree);
1030 varpool_node *varpool_node_for_asm (tree asmname);
1031 void varpool_mark_needed_node (varpool_node *);
1032 void debug_varpool (void);
1033 void dump_varpool (FILE *);
1034 void dump_varpool_node (FILE *, varpool_node *);
1035
1036 void varpool_finalize_decl (tree);
1037 enum availability cgraph_variable_initializer_availability (varpool_node *);
1038 void cgraph_make_node_local (struct cgraph_node *);
1039 bool cgraph_node_can_be_local_p (struct cgraph_node *);
1040
1041
1042 void varpool_remove_node (varpool_node *node);
1043 void varpool_finalize_named_section_flags (varpool_node *node);
1044 bool varpool_output_variables (void);
1045 bool varpool_assemble_decl (varpool_node *node);
1046 void varpool_analyze_node (varpool_node *);
1047 varpool_node * varpool_extra_name_alias (tree, tree);
1048 varpool_node * varpool_create_variable_alias (tree, tree);
1049 void varpool_reset_queue (void);
1050 tree ctor_for_folding (tree);
1051 bool varpool_for_node_and_aliases (varpool_node *,
1052                                    bool (*) (varpool_node *, void *),
1053                                    void *, bool);
1054 void varpool_add_new_variable (tree);
1055 void symtab_initialize_asm_name_hash (void);
1056 void symtab_prevail_in_asm_name_hash (symtab_node *node);
1057 void varpool_remove_initializer (varpool_node *);
1058
1059 /* In cgraph.c */
1060 extern void change_decl_assembler_name (tree, tree);
1061
1062 /* Return symbol table node associated with DECL, if any,
1063    and NULL otherwise.  */
1064
1065 static inline symtab_node *
1066 symtab_get_node (const_tree decl)
1067 {
1068 #ifdef ENABLE_CHECKING
1069   /* Check that we are called for sane type of object - functions
1070      and static or external variables.  */
1071   gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
1072                        || (TREE_CODE (decl) == VAR_DECL
1073                            && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1074                                || in_lto_p)));
1075   /* Check that the mapping is sane - perhaps this check can go away,
1076      but at the moment frontends tends to corrupt the mapping by calling
1077      memcpy/memset on the tree nodes.  */
1078   gcc_checking_assert (!decl->decl_with_vis.symtab_node
1079                        || decl->decl_with_vis.symtab_node->decl == decl);
1080 #endif
1081   return decl->decl_with_vis.symtab_node;
1082 }
1083
1084 /* Return callgraph node for given symbol and check it is a function. */
1085 static inline struct cgraph_node *
1086 cgraph (symtab_node *node)
1087 {
1088   gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
1089   return (struct cgraph_node *)node;
1090 }
1091
1092 /* Return varpool node for given symbol and check it is a variable.  */
1093 static inline varpool_node *
1094 varpool (symtab_node *node)
1095 {
1096   gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
1097   return (varpool_node *)node;
1098 }
1099
1100 /* Return callgraph node for given symbol and check it is a function. */
1101 static inline struct cgraph_node *
1102 cgraph_get_node (const_tree decl)
1103 {
1104   gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1105   return cgraph (symtab_get_node (decl));
1106 }
1107
1108 /* Return varpool node for given symbol and check it is a function. */
1109 static inline varpool_node *
1110 varpool_get_node (const_tree decl)
1111 {
1112   gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1113   return varpool (symtab_get_node (decl));
1114 }
1115
1116 /* Walk all symbols.  */
1117 #define FOR_EACH_SYMBOL(node) \
1118    for ((node) = symtab_nodes; (node); (node) = (node)->next)
1119
1120 /* Return first static symbol with definition.  */
1121 static inline symtab_node *
1122 symtab_first_defined_symbol (void)
1123 {
1124   symtab_node *node;
1125
1126   for (node = symtab_nodes; node; node = node->next)
1127     if (node->definition)
1128       return node;
1129
1130   return NULL;
1131 }
1132
1133 /* Return next reachable static symbol with initializer after NODE.  */
1134 static inline symtab_node *
1135 symtab_next_defined_symbol (symtab_node *node)
1136 {
1137   symtab_node *node1 = node->next;
1138
1139   for (; node1; node1 = node1->next)
1140     if (node1->definition)
1141       return node1;
1142
1143   return NULL;
1144 }
1145 /* Walk all symbols with definitions in current unit.  */
1146 #define FOR_EACH_DEFINED_SYMBOL(node) \
1147    for ((node) = symtab_first_defined_symbol (); (node); \
1148         (node) = symtab_next_defined_symbol (node))
1149
1150 /* Return first variable.  */
1151 static inline varpool_node *
1152 varpool_first_variable (void)
1153 {
1154   symtab_node *node;
1155   for (node = symtab_nodes; node; node = node->next)
1156     if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1157       return vnode;
1158   return NULL;
1159 }
1160
1161 /* Return next variable after NODE.  */
1162 static inline varpool_node *
1163 varpool_next_variable (varpool_node *node)
1164 {
1165   symtab_node *node1 = node->next;
1166   for (; node1; node1 = node1->next)
1167     if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1168       return vnode1;
1169   return NULL;
1170 }
1171 /* Walk all variables.  */
1172 #define FOR_EACH_VARIABLE(node) \
1173    for ((node) = varpool_first_variable (); \
1174         (node); \
1175         (node) = varpool_next_variable ((node)))
1176
1177 /* Return first static variable with initializer.  */
1178 static inline varpool_node *
1179 varpool_first_static_initializer (void)
1180 {
1181   symtab_node *node;
1182   for (node = symtab_nodes; node; node = node->next)
1183     {
1184       varpool_node *vnode = dyn_cast <varpool_node *> (node);
1185       if (vnode && DECL_INITIAL (node->decl))
1186         return vnode;
1187     }
1188   return NULL;
1189 }
1190
1191 /* Return next static variable with initializer after NODE.  */
1192 static inline varpool_node *
1193 varpool_next_static_initializer (varpool_node *node)
1194 {
1195   symtab_node *node1 = node->next;
1196   for (; node1; node1 = node1->next)
1197     {
1198       varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1199       if (vnode1 && DECL_INITIAL (node1->decl))
1200         return vnode1;
1201     }
1202   return NULL;
1203 }
1204
1205 /* Walk all static variables with initializer set.  */
1206 #define FOR_EACH_STATIC_INITIALIZER(node) \
1207    for ((node) = varpool_first_static_initializer (); (node); \
1208         (node) = varpool_next_static_initializer (node))
1209
1210 /* Return first static variable with definition.  */
1211 static inline varpool_node *
1212 varpool_first_defined_variable (void)
1213 {
1214   symtab_node *node;
1215   for (node = symtab_nodes; node; node = node->next)
1216     {
1217       varpool_node *vnode = dyn_cast <varpool_node *> (node);
1218       if (vnode && vnode->definition)
1219         return vnode;
1220     }
1221   return NULL;
1222 }
1223
1224 /* Return next static variable with definition after NODE.  */
1225 static inline varpool_node *
1226 varpool_next_defined_variable (varpool_node *node)
1227 {
1228   symtab_node *node1 = node->next;
1229   for (; node1; node1 = node1->next)
1230     {
1231       varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1232       if (vnode1 && vnode1->definition)
1233         return vnode1;
1234     }
1235   return NULL;
1236 }
1237 /* Walk all variables with definitions in current unit.  */
1238 #define FOR_EACH_DEFINED_VARIABLE(node) \
1239    for ((node) = varpool_first_defined_variable (); (node); \
1240         (node) = varpool_next_defined_variable (node))
1241
1242 /* Return first function with body defined.  */
1243 static inline struct cgraph_node *
1244 cgraph_first_defined_function (void)
1245 {
1246   symtab_node *node;
1247   for (node = symtab_nodes; node; node = node->next)
1248     {
1249       cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1250       if (cn && cn->definition)
1251         return cn;
1252     }
1253   return NULL;
1254 }
1255
1256 /* Return next function with body defined after NODE.  */
1257 static inline struct cgraph_node *
1258 cgraph_next_defined_function (struct cgraph_node *node)
1259 {
1260   symtab_node *node1 = node->next;
1261   for (; node1; node1 = node1->next)
1262     {
1263       cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1264       if (cn1 && cn1->definition)
1265         return cn1;
1266     }
1267   return NULL;
1268 }
1269
1270 /* Walk all functions with body defined.  */
1271 #define FOR_EACH_DEFINED_FUNCTION(node) \
1272    for ((node) = cgraph_first_defined_function (); (node); \
1273         (node) = cgraph_next_defined_function ((node)))
1274
1275 /* Return first function.  */
1276 static inline struct cgraph_node *
1277 cgraph_first_function (void)
1278 {
1279   symtab_node *node;
1280   for (node = symtab_nodes; node; node = node->next)
1281     if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1282       return cn;
1283   return NULL;
1284 }
1285
1286 /* Return next function.  */
1287 static inline struct cgraph_node *
1288 cgraph_next_function (struct cgraph_node *node)
1289 {
1290   symtab_node *node1 = node->next;
1291   for (; node1; node1 = node1->next)
1292     if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1293       return cn1;
1294   return NULL;
1295 }
1296 /* Walk all functions.  */
1297 #define FOR_EACH_FUNCTION(node) \
1298    for ((node) = cgraph_first_function (); (node); \
1299         (node) = cgraph_next_function ((node)))
1300
1301 /* Return true when NODE is a function with Gimple body defined
1302    in current unit.  Functions can also be define externally or they
1303    can be thunks with no Gimple representation.
1304
1305    Note that at WPA stage, the function body may not be present in memory.  */
1306
1307 static inline bool
1308 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1309 {
1310   return node->definition && !node->thunk.thunk_p && !node->alias;
1311 }
1312
1313 /* Return first function with body defined.  */
1314 static inline struct cgraph_node *
1315 cgraph_first_function_with_gimple_body (void)
1316 {
1317   symtab_node *node;
1318   for (node = symtab_nodes; node; node = node->next)
1319     {
1320       cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1321       if (cn && cgraph_function_with_gimple_body_p (cn))
1322         return cn;
1323     }
1324   return NULL;
1325 }
1326
1327 /* Return next reachable static variable with initializer after NODE.  */
1328 static inline struct cgraph_node *
1329 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1330 {
1331   symtab_node *node1 = node->next;
1332   for (; node1; node1 = node1->next)
1333     {
1334       cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1335       if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1336         return cn1;
1337     }
1338   return NULL;
1339 }
1340
1341 /* Walk all functions with body defined.  */
1342 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1343    for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1344         (node) = cgraph_next_function_with_gimple_body (node))
1345
1346 /* Create a new static variable of type TYPE.  */
1347 tree add_new_static_var (tree type);
1348
1349 /* Return true if iterator CSI points to nothing.  */
1350 static inline bool
1351 csi_end_p (cgraph_node_set_iterator csi)
1352 {
1353   return csi.index >= csi.set->nodes.length ();
1354 }
1355
1356 /* Advance iterator CSI.  */
1357 static inline void
1358 csi_next (cgraph_node_set_iterator *csi)
1359 {
1360   csi->index++;
1361 }
1362
1363 /* Return the node pointed to by CSI.  */
1364 static inline struct cgraph_node *
1365 csi_node (cgraph_node_set_iterator csi)
1366 {
1367   return csi.set->nodes[csi.index];
1368 }
1369
1370 /* Return an iterator to the first node in SET.  */
1371 static inline cgraph_node_set_iterator
1372 csi_start (cgraph_node_set set)
1373 {
1374   cgraph_node_set_iterator csi;
1375
1376   csi.set = set;
1377   csi.index = 0;
1378   return csi;
1379 }
1380
1381 /* Return true if SET contains NODE.  */
1382 static inline bool
1383 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1384 {
1385   cgraph_node_set_iterator csi;
1386   csi = cgraph_node_set_find (set, node);
1387   return !csi_end_p (csi);
1388 }
1389
1390 /* Return number of nodes in SET.  */
1391 static inline size_t
1392 cgraph_node_set_size (cgraph_node_set set)
1393 {
1394   return set->nodes.length ();
1395 }
1396
1397 /* Return true if iterator VSI points to nothing.  */
1398 static inline bool
1399 vsi_end_p (varpool_node_set_iterator vsi)
1400 {
1401   return vsi.index >= vsi.set->nodes.length ();
1402 }
1403
1404 /* Advance iterator VSI.  */
1405 static inline void
1406 vsi_next (varpool_node_set_iterator *vsi)
1407 {
1408   vsi->index++;
1409 }
1410
1411 /* Return the node pointed to by VSI.  */
1412 static inline varpool_node *
1413 vsi_node (varpool_node_set_iterator vsi)
1414 {
1415   return vsi.set->nodes[vsi.index];
1416 }
1417
1418 /* Return an iterator to the first node in SET.  */
1419 static inline varpool_node_set_iterator
1420 vsi_start (varpool_node_set set)
1421 {
1422   varpool_node_set_iterator vsi;
1423
1424   vsi.set = set;
1425   vsi.index = 0;
1426   return vsi;
1427 }
1428
1429 /* Return true if SET contains NODE.  */
1430 static inline bool
1431 varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
1432 {
1433   varpool_node_set_iterator vsi;
1434   vsi = varpool_node_set_find (set, node);
1435   return !vsi_end_p (vsi);
1436 }
1437
1438 /* Return number of nodes in SET.  */
1439 static inline size_t
1440 varpool_node_set_size (varpool_node_set set)
1441 {
1442   return set->nodes.length ();
1443 }
1444
1445 /* Uniquize all constants that appear in memory.
1446    Each constant in memory thus far output is recorded
1447    in `const_desc_table'.  */
1448
1449 struct GTY(()) constant_descriptor_tree {
1450   /* A MEM for the constant.  */
1451   rtx rtl;
1452
1453   /* The value of the constant.  */
1454   tree value;
1455
1456   /* Hash of value.  Computing the hash from value each time
1457      hashfn is called can't work properly, as that means recursive
1458      use of the hash table during hash table expansion.  */
1459   hashval_t hash;
1460 };
1461
1462 /* Return true if set is nonempty.  */
1463 static inline bool
1464 cgraph_node_set_nonempty_p (cgraph_node_set set)
1465 {
1466   return !set->nodes.is_empty ();
1467 }
1468
1469 /* Return true if set is nonempty.  */
1470 static inline bool
1471 varpool_node_set_nonempty_p (varpool_node_set set)
1472 {
1473   return !set->nodes.is_empty ();
1474 }
1475
1476 /* Return true when function NODE is only called directly or it has alias.
1477    i.e. it is not externally visible, address was not taken and
1478    it is not used in any other non-standard way.  */
1479
1480 static inline bool
1481 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1482 {
1483   gcc_assert (!node->global.inlined_to);
1484   return (!node->force_output && !node->address_taken
1485           && !node->used_from_other_partition
1486           && !DECL_VIRTUAL_P (node->decl)
1487           && !DECL_STATIC_CONSTRUCTOR (node->decl)
1488           && !DECL_STATIC_DESTRUCTOR (node->decl)
1489           && !node->externally_visible);
1490 }
1491
1492 /* Return true when function NODE can be removed from callgraph
1493    if all direct calls are eliminated.  */
1494
1495 static inline bool
1496 varpool_can_remove_if_no_refs (varpool_node *node)
1497 {
1498   if (DECL_EXTERNAL (node->decl))
1499     return true;
1500   return (!node->force_output && !node->used_from_other_partition
1501           && ((DECL_COMDAT (node->decl)
1502                && !node->forced_by_abi
1503                && !symtab_used_from_object_file_p (node))
1504               || !node->externally_visible
1505               || DECL_HAS_VALUE_EXPR_P (node->decl)));
1506 }
1507
1508 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1509    i.e. if the variable is not externally visible or not used in some magic
1510    way (asm statement or such).
1511    The magic uses are all summarized in force_output flag.  */
1512
1513 static inline bool
1514 varpool_all_refs_explicit_p (varpool_node *vnode)
1515 {
1516   return (vnode->definition
1517           && !vnode->externally_visible
1518           && !vnode->used_from_other_partition
1519           && !vnode->force_output);
1520 }
1521
1522 /* Constant pool accessor function.  */
1523 htab_t constant_pool_htab (void);
1524
1525 /* FIXME: inappropriate dependency of cgraph on IPA.  */
1526 #include "ipa-ref-inline.h"
1527
1528 /* Return node that alias N is aliasing.  */
1529
1530 static inline symtab_node *
1531 symtab_alias_target (symtab_node *n)
1532 {
1533   struct ipa_ref *ref;
1534   ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
1535   gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1536   return ref->referred;
1537 }
1538
1539 static inline struct cgraph_node *
1540 cgraph_alias_target (struct cgraph_node *n)
1541 {
1542   return dyn_cast <cgraph_node *> (symtab_alias_target (n));
1543 }
1544
1545 static inline varpool_node *
1546 varpool_alias_target (varpool_node *n)
1547 {
1548   return dyn_cast <varpool_node *> (symtab_alias_target (n));
1549 }
1550
1551 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1552    Do not walk through thunks.
1553    When AVAILABILITY is non-NULL, get minimal availability in the chain.  */
1554
1555 static inline struct cgraph_node *
1556 cgraph_function_or_thunk_node (struct cgraph_node *node,
1557                                enum availability *availability = NULL)
1558 {
1559   struct cgraph_node *n;
1560
1561   n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node,
1562                                                               availability));
1563   if (!n && availability)
1564     *availability = AVAIL_NOT_AVAILABLE;
1565   return n;
1566 }
1567 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1568    Do not walk through thunks.
1569    When AVAILABILITY is non-NULL, get minimal availability in the chain.  */
1570
1571 static inline varpool_node *
1572 varpool_variable_node (varpool_node *node,
1573                        enum availability *availability = NULL)
1574 {
1575   varpool_node *n;
1576
1577   if (node)
1578     n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node,
1579                                                                  availability));
1580   else
1581     n = NULL;
1582
1583   if (!n && availability)
1584     *availability = AVAIL_NOT_AVAILABLE;
1585   return n;
1586 }
1587
1588 /* Return true when the edge E represents a direct recursion.  */
1589 static inline bool
1590 cgraph_edge_recursive_p (struct cgraph_edge *e)
1591 {
1592   struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1593   if (e->caller->global.inlined_to)
1594     return e->caller->global.inlined_to->decl == callee->decl;
1595   else
1596     return e->caller->decl == callee->decl;
1597 }
1598
1599 /* Return true if the TM_CLONE bit is set for a given FNDECL.  */
1600 static inline bool
1601 decl_is_tm_clone (const_tree fndecl)
1602 {
1603   struct cgraph_node *n = cgraph_get_node (fndecl);
1604   if (n)
1605     return n->tm_clone;
1606   return false;
1607 }
1608
1609 /* Likewise indicate that a node is needed, i.e. reachable via some
1610    external means.  */
1611
1612 static inline void
1613 cgraph_mark_force_output_node (struct cgraph_node *node)
1614 {
1615   node->force_output = 1;
1616   gcc_checking_assert (!node->global.inlined_to);
1617 }
1618
1619 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1620    or abstract function kept for debug info purposes only.  */
1621
1622 static inline bool
1623 symtab_real_symbol_p (symtab_node *node)
1624 {
1625   struct cgraph_node *cnode;
1626
1627   if (DECL_ABSTRACT (node->decl))
1628     return false;
1629   if (!is_a <cgraph_node *> (node))
1630     return true;
1631   cnode = cgraph (node);
1632   if (cnode->global.inlined_to)
1633     return false;
1634   return true;
1635 }
1636
1637 /* Return true if NODE can be discarded by linker from the binary.  */
1638
1639 static inline bool
1640 symtab_can_be_discarded (symtab_node *node)
1641 {
1642   return (DECL_EXTERNAL (node->decl)
1643           || (node->get_comdat_group ()
1644               && node->resolution != LDPR_PREVAILING_DEF
1645               && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1646               && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1647 }
1648
1649 /* Return true if NODE is local to a particular COMDAT group, and must not
1650    be named from outside the COMDAT.  This is used for C++ decloned
1651    constructors.  */
1652
1653 static inline bool
1654 symtab_comdat_local_p (symtab_node *node)
1655 {
1656   return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1657 }
1658
1659 /* Return true if ONE and TWO are part of the same COMDAT group.  */
1660
1661 static inline bool
1662 symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1663 {
1664   if (cgraph_node *cn = dyn_cast <cgraph_node *> (one))
1665     {
1666       if (cn->global.inlined_to)
1667         one = cn->global.inlined_to;
1668     }
1669   if (cgraph_node *cn = dyn_cast <cgraph_node *> (two))
1670     {
1671       if (cn->global.inlined_to)
1672         two = cn->global.inlined_to;
1673     }
1674
1675   return one->get_comdat_group () == two->get_comdat_group ();
1676 }
1677 #endif  /* GCC_CGRAPH_H  */