cgraph.h (symtab_node_base): Add definition, alias and analyzed flags...
[platform/upstream/gcc.git] / gcc / cgraph.h
1 /* Callgraph handling code.
2    Copyright (C) 2003-2013 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 "tree.h"
28 #include "basic-block.h"
29 #include "function.h"
30 #include "ipa-ref.h"
31
32 /* Symbol table consists of functions and variables.
33    TODO: add labels and CONST_DECLs.  */
34 enum symtab_type
35 {
36   SYMTAB_SYMBOL,
37   SYMTAB_FUNCTION,
38   SYMTAB_VARIABLE
39 };
40
41 /* Base of all entries in the symbol table.
42    The symtab_node is inherited by cgraph and varpol nodes.  */
43 struct GTY(()) symtab_node_base
44 {
45   /* Type of the symbol.  */
46   ENUM_BITFIELD (symtab_type) type : 8;
47
48   /* The symbols resolution.  */
49   ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
50
51   /*** Flags representing the symbol type.  ***/
52
53   /* True when symbol corresponds to a definition in current unit.
54      set via cgraph_finalize_function or varpool_finalize_decl  */
55   unsigned definition : 1;
56   /* True when symbol is an alias.  
57      Set by assemble_alias.  */
58   unsigned alias : 1;
59   /* Set once the definition was analyzed.  The list of references and
60      other properties are built during analysis.  */
61   unsigned analyzed : 1;
62
63
64   /*** Visibility and linkage flags.  ***/
65
66   /* Set when function is visible by other units.  */
67   unsigned externally_visible : 1;
68   /* Needed variables might become dead by optimization.  This flag
69      forces the variable to be output even if it appears dead otherwise.  */
70   unsigned force_output : 1;
71   /* True when the name is known to be unique and thus it does not need mangling.  */
72   unsigned unique_name : 1;
73
74
75   /*** WHOPR Partitioning flags.
76        These flags are used at ltrans stage when only part of the callgraph is
77        available. ***/
78
79   /* Set when variable is used from other LTRANS partition.  */
80   unsigned used_from_other_partition : 1;
81   /* Set when function is available in the other LTRANS partition.  
82      During WPA output it is used to mark nodes that are present in
83      multiple partitions.  */
84   unsigned in_other_partition : 1;
85
86
87
88   /*** other flags.  ***/
89
90   /* Set when symbol has address taken. */
91   unsigned address_taken : 1;
92
93
94   /* Ordering of all symtab entries.  */
95   int order;
96
97   /* Declaration representing the symbol.  */
98   tree decl;
99
100   /* Linked list of symbol table entries starting with symtab_nodes.  */
101   symtab_node next;
102   symtab_node previous;
103
104   /* Linked list of symbols with the same asm name.  There may be multiple
105      entries for single symbol name during LTO, because symbols are renamed
106      only after partitioning.
107
108      Because inline clones are kept in the assembler name has, they also produce
109      duplicate entries.
110
111      There are also several long standing bugs where frontends and builtin
112      code produce duplicated decls.  */
113   symtab_node next_sharing_asm_name;
114   symtab_node previous_sharing_asm_name;
115
116   /* Circular list of nodes in the same comdat group if non-NULL.  */
117   symtab_node same_comdat_group;
118
119   /* Vectors of referring and referenced entities.  */
120   struct ipa_ref_list ref_list;
121
122   /* File stream where this node is being written to.  */
123   struct lto_file_decl_data * lto_file_data;
124
125   PTR GTY ((skip)) aux;
126 };
127
128 enum availability
129 {
130   /* Not yet set by cgraph_function_body_availability.  */
131   AVAIL_UNSET,
132   /* Function body/variable initializer is unknown.  */
133   AVAIL_NOT_AVAILABLE,
134   /* Function body/variable initializer is known but might be replaced
135      by a different one from other compilation unit and thus needs to
136      be dealt with a care.  Like AVAIL_NOT_AVAILABLE it can have
137      arbitrary side effects on escaping variables and functions, while
138      like AVAILABLE it might access static variables.  */
139   AVAIL_OVERWRITABLE,
140   /* Function body/variable initializer is known and will be used in final
141      program.  */
142   AVAIL_AVAILABLE,
143   /* Function body/variable initializer is known and all it's uses are explicitly
144      visible within current unit (ie it's address is never taken and it is not
145      exported to other units).
146      Currently used only for functions.  */
147   AVAIL_LOCAL
148 };
149
150 /* This is the information that is put into the cgraph local structure
151    to recover a function.  */
152 struct lto_file_decl_data;
153
154 extern const char * const cgraph_availability_names[];
155 extern const char * const ld_plugin_symbol_resolution_names[];
156
157 /* Information about thunk, used only for same body aliases.  */
158
159 struct GTY(()) cgraph_thunk_info {
160   /* Information about the thunk.  */
161   HOST_WIDE_INT fixed_offset;
162   HOST_WIDE_INT virtual_value;
163   tree alias;
164   bool this_adjusting;
165   bool virtual_offset_p;
166   /* Set to true when alias node is thunk.  */
167   bool thunk_p;
168 };
169
170 /* Information about the function collected locally.
171    Available after function is analyzed.  */
172
173 struct GTY(()) cgraph_local_info {
174   /* Set when function function is visible in current compilation unit only
175      and its address is never taken.  */
176   unsigned local : 1;
177
178   /* False when there is something makes versioning impossible.  */
179   unsigned versionable : 1;
180
181   /* False when function calling convention and signature can not be changed.
182      This is the case when __builtin_apply_args is used.  */
183   unsigned can_change_signature : 1;
184
185   /* True when the function has been originally extern inline, but it is
186      redefined now.  */
187   unsigned redefined_extern_inline : 1;
188
189   /* True if the function may enter serial irrevocable mode.  */
190   unsigned tm_may_enter_irr : 1;
191 };
192
193 /* Information about the function that needs to be computed globally
194    once compilation is finished.  Available only with -funit-at-a-time.  */
195
196 struct GTY(()) cgraph_global_info {
197   /* For inline clones this points to the function they will be
198      inlined into.  */
199   struct cgraph_node *inlined_to;
200 };
201
202 /* Information about the function that is propagated by the RTL backend.
203    Available only for functions that has been already assembled.  */
204
205 struct GTY(()) cgraph_rtl_info {
206    unsigned int preferred_incoming_stack_boundary;
207 };
208
209 /* Represent which DECL tree (or reference to such tree)
210    will be replaced by another tree while versioning.  */
211 struct GTY(()) ipa_replace_map
212 {
213   /* The tree that will be replaced.  */
214   tree old_tree;
215   /* The new (replacing) tree.  */
216   tree new_tree;
217   /* Parameter number to replace, when old_tree is NULL.  */
218   int parm_num;
219   /* True when a substitution should be done, false otherwise.  */
220   bool replace_p;
221   /* True when we replace a reference to old_tree.  */
222   bool ref_p;
223 };
224 typedef struct ipa_replace_map *ipa_replace_map_p;
225
226 struct GTY(()) cgraph_clone_info
227 {
228   vec<ipa_replace_map_p, va_gc> *tree_map;
229   bitmap args_to_skip;
230   bitmap combined_args_to_skip;
231 };
232
233
234 /* The cgraph data structure.
235    Each function decl has assigned cgraph_node listing callees and callers.  */
236
237 struct GTY(()) cgraph_node {
238   struct symtab_node_base symbol;
239   struct cgraph_edge *callees;
240   struct cgraph_edge *callers;
241   /* List of edges representing indirect calls with a yet undetermined
242      callee.  */
243   struct cgraph_edge *indirect_calls;
244   /* For nested functions points to function the node is nested in.  */
245   struct cgraph_node *
246     GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
247     origin;
248   /* Points to first nested function, if any.  */
249   struct cgraph_node *
250     GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
251     nested;
252   /* Pointer to the next function with same origin, if any.  */
253   struct cgraph_node *
254     GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
255     next_nested;
256   /* Pointer to the next clone.  */
257   struct cgraph_node *next_sibling_clone;
258   struct cgraph_node *prev_sibling_clone;
259   struct cgraph_node *clones;
260   struct cgraph_node *clone_of;
261   /* For functions with many calls sites it holds map from call expression
262      to the edge to speed up cgraph_edge function.  */
263   htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
264   /* Declaration node used to be clone of. */
265   tree former_clone_of;
266
267   /* Interprocedural passes scheduled to have their transform functions
268      applied next time we execute local pass on them.  We maintain it
269      per-function in order to allow IPA passes to introduce new functions.  */
270   vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
271
272   struct cgraph_local_info local;
273   struct cgraph_global_info global;
274   struct cgraph_rtl_info rtl;
275   struct cgraph_clone_info clone;
276   struct cgraph_thunk_info thunk;
277
278   /* Expected number of executions: calculated in profile.c.  */
279   gcov_type count;
280   /* How to scale counts at materialization time; used to merge
281      LTO units with different number of profile runs.  */
282   int count_materialization_scale;
283   /* Unique id of the node.  */
284   int uid;
285
286   /* Set when decl is an abstract function pointed to by the
287      ABSTRACT_DECL_ORIGIN of a reachable function.  */
288   unsigned abstract_and_needed : 1;
289   /* Set once the function is lowered (i.e. its CFG is built).  */
290   unsigned lowered : 1;
291   /* Set once the function has been instantiated and its callee
292      lists created.  */
293   unsigned process : 1;
294   /* Set for aliases created as C++ same body aliases.  */
295   unsigned same_body_alias : 1;
296   /* How commonly executed the node is.  Initialized during branch
297      probabilities pass.  */
298   ENUM_BITFIELD (node_frequency) frequency : 2;
299   /* True when function can only be called at startup (from static ctor).  */
300   unsigned only_called_at_startup : 1;
301   /* True when function can only be called at startup (from static dtor).  */
302   unsigned only_called_at_exit : 1;
303   /* True when function is the transactional clone of a function which
304      is called only from inside transactions.  */
305   /* ?? We should be able to remove this.  We have enough bits in
306      cgraph to calculate it.  */
307   unsigned tm_clone : 1;
308   /* True if this decl is a dispatcher for function versions.  */
309   unsigned dispatcher_function : 1;
310 };
311
312
313 typedef struct cgraph_node *cgraph_node_ptr;
314
315
316 /* Function Multiversioning info.  */
317 struct GTY(()) cgraph_function_version_info {
318   /* The cgraph_node for which the function version info is stored.  */
319   struct cgraph_node *this_node;
320   /* Chains all the semantically identical function versions.  The
321      first function in this chain is the version_info node of the
322      default function.  */
323   struct cgraph_function_version_info *prev;
324   /* If this version node corresponds to a dispatcher for function
325      versions, this points to the version info node of the default
326      function, the first node in the chain.  */
327   struct cgraph_function_version_info *next;
328   /* If this node corresponds to a function version, this points
329      to the dispatcher function decl, which is the function that must
330      be called to execute the right function version at run-time.
331
332      If this cgraph node is a dispatcher (if dispatcher_function is
333      true, in the cgraph_node struct) for function versions, this
334      points to resolver function, which holds the function body of the
335      dispatcher. The dispatcher decl is an alias to the resolver
336      function decl.  */
337   tree dispatcher_resolver;
338 };
339
340 /* Get the cgraph_function_version_info node corresponding to node.  */
341 struct cgraph_function_version_info *
342   get_cgraph_node_version (struct cgraph_node *node);
343
344 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
345    corresponding to cgraph_node NODE.  */
346 struct cgraph_function_version_info *
347   insert_new_cgraph_node_version (struct cgraph_node *node);
348
349 /* Record that DECL1 and DECL2 are semantically identical function
350    versions.  */
351 void record_function_versions (tree decl1, tree decl2);
352
353 /* Remove the cgraph_function_version_info and cgraph_node for DECL.  This
354    DECL is a duplicate declaration.  */
355 void delete_function_version (tree decl);
356
357 /* A cgraph node set is a collection of cgraph nodes.  A cgraph node
358    can appear in multiple sets.  */
359 struct cgraph_node_set_def
360 {
361   struct pointer_map_t *map;
362   vec<cgraph_node_ptr> nodes;
363 };
364
365 typedef struct varpool_node *varpool_node_ptr;
366
367
368 /* A varpool node set is a collection of varpool nodes.  A varpool node
369    can appear in multiple sets.  */
370 struct varpool_node_set_def
371 {
372   struct pointer_map_t * map;
373   vec<varpool_node_ptr> nodes;
374 };
375
376 typedef struct cgraph_node_set_def *cgraph_node_set;
377
378
379 typedef struct varpool_node_set_def *varpool_node_set;
380
381
382 /* Iterator structure for cgraph node sets.  */
383 typedef struct
384 {
385   cgraph_node_set set;
386   unsigned index;
387 } cgraph_node_set_iterator;
388
389 /* Iterator structure for varpool node sets.  */
390 typedef struct
391 {
392   varpool_node_set set;
393   unsigned index;
394 } varpool_node_set_iterator;
395
396 #define DEFCIFCODE(code, string)        CIF_ ## code,
397 /* Reasons for inlining failures.  */
398 typedef enum cgraph_inline_failed_enum {
399 #include "cif-code.def"
400   CIF_N_REASONS
401 } cgraph_inline_failed_t;
402
403 /* Structure containing additional information about an indirect call.  */
404
405 struct GTY(()) cgraph_indirect_call_info
406 {
407   /* When polymorphic is set, this field contains offset where the object which
408      was actually used in the polymorphic resides within a larger structure.
409      If agg_contents is set, the field contains the offset within the aggregate
410      from which the address to call was loaded.  */
411   HOST_WIDE_INT offset;
412   /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set).  */
413   HOST_WIDE_INT otr_token;
414   /* Type of the object from OBJ_TYPE_REF_OBJECT. */
415   tree otr_type;
416   /* Index of the parameter that is called.  */
417   int param_index;
418   /* ECF flags determined from the caller.  */
419   int ecf_flags;
420
421   /* Set when the call is a virtual call with the parameter being the
422      associated object pointer rather than a simple direct call.  */
423   unsigned polymorphic : 1;
424   /* Set when the call is a call of a pointer loaded from contents of an
425      aggregate at offset.  */
426   unsigned agg_contents : 1;
427   /* When the previous bit is set, this one determines whether the destination
428      is loaded from a parameter passed by reference. */
429   unsigned by_ref : 1;
430 };
431
432 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
433   /* Expected number of executions: calculated in profile.c.  */
434   gcov_type count;
435   struct cgraph_node *caller;
436   struct cgraph_node *callee;
437   struct cgraph_edge *prev_caller;
438   struct cgraph_edge *next_caller;
439   struct cgraph_edge *prev_callee;
440   struct cgraph_edge *next_callee;
441   gimple call_stmt;
442   /* Additional information about an indirect call.  Not cleared when an edge
443      becomes direct.  */
444   struct cgraph_indirect_call_info *indirect_info;
445   PTR GTY ((skip (""))) aux;
446   /* When equal to CIF_OK, inline this call.  Otherwise, points to the
447      explanation why function was not inlined.  */
448   cgraph_inline_failed_t inline_failed;
449   /* The stmt_uid of call_stmt.  This is used by LTO to recover the call_stmt
450      when the function is serialized in.  */
451   unsigned int lto_stmt_uid;
452   /* Expected frequency of executions within the function.
453      When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
454      per function call.  The range is 0 to CGRAPH_FREQ_MAX.  */
455   int frequency;
456   /* Unique id of the edge.  */
457   int uid;
458   /* Whether this edge was made direct by indirect inlining.  */
459   unsigned int indirect_inlining_edge : 1;
460   /* Whether this edge describes an indirect call with an undetermined
461      callee.  */
462   unsigned int indirect_unknown_callee : 1;
463   /* Whether this edge is still a dangling  */
464   /* True if the corresponding CALL stmt cannot be inlined.  */
465   unsigned int call_stmt_cannot_inline_p : 1;
466   /* Can this call throw externally?  */
467   unsigned int can_throw_external : 1;
468 };
469
470 #define CGRAPH_FREQ_BASE 1000
471 #define CGRAPH_FREQ_MAX 100000
472
473 typedef struct cgraph_edge *cgraph_edge_p;
474
475
476 /* The varpool data structure.
477    Each static variable decl has assigned varpool_node.  */
478
479 struct GTY(()) varpool_node {
480   struct symtab_node_base symbol;
481   /* For aliases points to declaration DECL is alias of.  */
482   tree alias_of;
483
484   /* Set when variable is scheduled to be assembled.  */
485   unsigned output : 1;
486   unsigned extra_name_alias : 1;
487 };
488
489 /* Every top level asm statement is put into a asm_node.  */
490
491 struct GTY(()) asm_node {
492   /* Next asm node.  */
493   struct asm_node *next;
494   /* String for this asm node.  */
495   tree asm_str;
496   /* Ordering of all cgraph nodes.  */
497   int order;
498 };
499
500 /* Symbol table entry.  */
501 union GTY((desc ("%h.symbol.type"), chain_next ("%h.symbol.next"),
502            chain_prev ("%h.symbol.previous"))) symtab_node_def {
503   struct symtab_node_base GTY ((tag ("SYMTAB_SYMBOL"))) symbol;
504   /* To access the following fields,
505      use the use dyn_cast or as_a to obtain the concrete type.  */
506   struct cgraph_node GTY ((tag ("SYMTAB_FUNCTION"))) x_function;
507   struct varpool_node GTY ((tag ("SYMTAB_VARIABLE"))) x_variable;
508 };
509
510 /* Report whether or not THIS symtab node is a function, aka cgraph_node.  */
511
512 template <>
513 template <>
514 inline bool
515 is_a_helper <cgraph_node>::test (symtab_node_def *p)
516 {
517   return p->symbol.type == SYMTAB_FUNCTION;
518 }
519
520 /* Report whether or not THIS symtab node is a vriable, aka varpool_node.  */
521
522 template <>
523 template <>
524 inline bool
525 is_a_helper <varpool_node>::test (symtab_node_def *p)
526 {
527   return p->symbol.type == SYMTAB_VARIABLE;
528 }
529
530 extern GTY(()) symtab_node symtab_nodes;
531 extern GTY(()) int cgraph_n_nodes;
532 extern GTY(()) int cgraph_max_uid;
533 extern GTY(()) int cgraph_edge_max_uid;
534 extern bool cgraph_global_info_ready;
535 enum cgraph_state
536 {
537   /* Frontend is parsing and finalizing functions.  */
538   CGRAPH_STATE_PARSING,
539   /* Callgraph is being constructed.  It is safe to add new functions.  */
540   CGRAPH_STATE_CONSTRUCTION,
541   /* Callgraph is built and IPA passes are being run.  */
542   CGRAPH_STATE_IPA,
543   /* Callgraph is built and all functions are transformed to SSA form.  */
544   CGRAPH_STATE_IPA_SSA,
545   /* Functions are now ordered and being passed to RTL expanders.  */
546   CGRAPH_STATE_EXPANSION,
547   /* All cgraph expansion is done.  */
548   CGRAPH_STATE_FINISHED
549 };
550 extern enum cgraph_state cgraph_state;
551 extern bool cgraph_function_flags_ready;
552 extern cgraph_node_set cgraph_new_nodes;
553
554 extern GTY(()) struct asm_node *asm_nodes;
555 extern GTY(()) int symtab_order;
556 extern bool same_body_aliases_done;
557
558 /* In symtab.c  */
559 void symtab_register_node (symtab_node);
560 void symtab_unregister_node (symtab_node);
561 void symtab_remove_node (symtab_node);
562 symtab_node symtab_get_node (const_tree);
563 symtab_node symtab_node_for_asm (const_tree asmname);
564 const char * symtab_node_asm_name (symtab_node);
565 const char * symtab_node_name (symtab_node);
566 void symtab_insert_node_to_hashtable (symtab_node);
567 void symtab_add_to_same_comdat_group (symtab_node, symtab_node);
568 void symtab_dissolve_same_comdat_group_list (symtab_node node);
569 void dump_symtab (FILE *);
570 void debug_symtab (void);
571 void dump_symtab_node (FILE *, symtab_node);
572 void debug_symtab_node (symtab_node);
573 void dump_symtab_base (FILE *, symtab_node);
574 void verify_symtab (void);
575 void verify_symtab_node (symtab_node);
576 bool verify_symtab_base (symtab_node);
577 bool symtab_used_from_object_file_p (symtab_node);
578 void symtab_make_decl_local (tree);
579 symtab_node symtab_alias_ultimate_target (symtab_node, enum availability *);
580
581 /* In cgraph.c  */
582 void dump_cgraph (FILE *);
583 void debug_cgraph (void);
584 void dump_cgraph_node (FILE *, struct cgraph_node *);
585 void debug_cgraph_node (struct cgraph_node *);
586 void cgraph_remove_edge (struct cgraph_edge *);
587 void cgraph_remove_node (struct cgraph_node *);
588 void cgraph_release_function_body (struct cgraph_node *);
589 void cgraph_node_remove_callees (struct cgraph_node *node);
590 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
591                                         struct cgraph_node *,
592                                         gimple, gcov_type, int);
593 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
594                                                  int, gcov_type, int);
595 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
596 struct cgraph_node * cgraph_create_node (tree);
597 struct cgraph_node * cgraph_create_empty_node (void);
598 struct cgraph_node * cgraph_get_create_node (tree);
599 struct cgraph_node * cgraph_get_create_real_symbol_node (tree);
600 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
601 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
602                                        HOST_WIDE_INT, tree, tree);
603 struct cgraph_node *cgraph_node_for_asm (tree);
604 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
605 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
606 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
607 struct cgraph_local_info *cgraph_local_info (tree);
608 struct cgraph_global_info *cgraph_global_info (tree);
609 struct cgraph_rtl_info *cgraph_rtl_info (tree);
610 struct cgraph_node *cgraph_create_function_alias (tree, tree);
611 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
612                                          struct cgraph_node *);
613 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
614                                          struct cgraph_edge *);
615
616 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
617 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
618 bool cgraph_only_called_directly_p (struct cgraph_node *);
619
620 bool cgraph_function_possibly_inlined_p (tree);
621 void cgraph_unnest_node (struct cgraph_node *);
622
623 enum availability cgraph_function_body_availability (struct cgraph_node *);
624 void cgraph_add_new_function (tree, bool);
625 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
626
627 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
628 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
629 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
630 bool cgraph_node_cannot_return (struct cgraph_node *);
631 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
632 bool cgraph_will_be_removed_from_program_if_no_direct_calls
633   (struct cgraph_node *node);
634 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
635   (struct cgraph_node *node);
636 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
637 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
638 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
639                                          bool (*) (struct cgraph_node *, void *),
640                                          void *,
641                                          bool);
642 bool cgraph_for_node_and_aliases (struct cgraph_node *,
643                                   bool (*) (struct cgraph_node *, void *),
644                                   void *, bool);
645 vec<cgraph_edge_p>  collect_callers_of_node (struct cgraph_node *node);
646 void verify_cgraph (void);
647 void verify_cgraph_node (struct cgraph_node *);
648 void cgraph_mark_address_taken_node (struct cgraph_node *);
649
650 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
651 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
652 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
653                                   void *);
654 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
655                                   void *);
656 struct cgraph_edge_hook_list;
657 struct cgraph_node_hook_list;
658 struct cgraph_2edge_hook_list;
659 struct cgraph_2node_hook_list;
660 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
661 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
662 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
663                                                             void *);
664 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
665 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
666                                                                   void *);
667 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
668 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
669 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
670 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
671 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
672 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
673 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
674 bool cgraph_propagate_frequency (struct cgraph_node *node);
675 struct cgraph_node * cgraph_function_node (struct cgraph_node *, enum availability *);
676
677 /* In cgraphunit.c  */
678 struct asm_node *add_asm_node (tree);
679 extern FILE *cgraph_dump_file;
680 void cgraph_finalize_function (tree, bool);
681 void finalize_compilation_unit (void);
682 void compile (void);
683 void init_cgraph (void);
684 bool cgraph_process_new_functions (void);
685 void cgraph_process_same_body_aliases (void);
686 void fixup_same_cpp_alias_visibility (symtab_node, symtab_node target, tree);
687 /*  Initialize datastructures so DECL is a function in lowered gimple form.
688     IN_SSA is true if the gimple is in SSA.  */
689 basic_block init_lowered_empty_function (tree, bool);
690 void cgraph_reset_node (struct cgraph_node *);
691
692 /* In cgraphclones.c  */
693
694 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
695                                         struct cgraph_node *, gimple,
696                                         unsigned, gcov_type, int, bool);
697 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
698                                         int, bool, vec<cgraph_edge_p>,
699                                         bool);
700 tree clone_function_name (tree decl, const char *);
701 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
702                                                   vec<cgraph_edge_p>,
703                                                   vec<ipa_replace_map_p, va_gc> *tree_map,
704                                                   bitmap args_to_skip,
705                                                   const char *clone_name);
706 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
707 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
708 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
709 void cgraph_create_edge_including_clones (struct cgraph_node *,
710                                           struct cgraph_node *,
711                                           gimple, gimple, gcov_type, int,
712                                           cgraph_inline_failed_t);
713 void cgraph_materialize_all_clones (void);
714 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
715                 tree, vec<cgraph_edge_p>, bitmap);
716 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
717                                                 vec<cgraph_edge_p>,
718                                                 vec<ipa_replace_map_p, va_gc> *,
719                                                 bitmap, bool, bitmap,
720                                                 basic_block, const char *);
721 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
722                                bool, bitmap, bool, bitmap, basic_block);
723
724 /* In cgraphbuild.c  */
725 unsigned int rebuild_cgraph_edges (void);
726 void cgraph_rebuild_references (void);
727 int compute_call_stmt_bb_frequency (tree, basic_block bb);
728 void record_references_in_initializer (tree, bool);
729 void ipa_record_stmt_references (struct cgraph_node *, gimple);
730
731 /* In ipa.c  */
732 bool symtab_remove_unreachable_nodes (bool, FILE *);
733 cgraph_node_set cgraph_node_set_new (void);
734 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
735                                                struct cgraph_node *);
736 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
737 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
738 void dump_cgraph_node_set (FILE *, cgraph_node_set);
739 void debug_cgraph_node_set (cgraph_node_set);
740 void free_cgraph_node_set (cgraph_node_set);
741 void cgraph_build_static_cdtor (char which, tree body, int priority);
742
743 varpool_node_set varpool_node_set_new (void);
744 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
745                                                struct varpool_node *);
746 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
747 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
748 void dump_varpool_node_set (FILE *, varpool_node_set);
749 void debug_varpool_node_set (varpool_node_set);
750 void free_varpool_node_set (varpool_node_set);
751 void ipa_discover_readonly_nonaddressable_vars (void);
752 bool varpool_externally_visible_p (struct varpool_node *);
753
754 /* In predict.c  */
755 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
756 bool cgraph_optimize_for_size_p (struct cgraph_node *);
757
758 /* In varpool.c  */
759 struct varpool_node *varpool_node_for_decl (tree);
760 struct varpool_node *varpool_node_for_asm (tree asmname);
761 void varpool_mark_needed_node (struct varpool_node *);
762 void debug_varpool (void);
763 void dump_varpool (FILE *);
764 void dump_varpool_node (FILE *, struct varpool_node *);
765
766 void varpool_finalize_decl (tree);
767 bool decide_is_variable_needed (struct varpool_node *, tree);
768 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
769 void cgraph_make_node_local (struct cgraph_node *);
770 bool cgraph_node_can_be_local_p (struct cgraph_node *);
771
772
773 void varpool_remove_node (struct varpool_node *node);
774 void varpool_finalize_named_section_flags (struct varpool_node *node);
775 bool varpool_output_variables (void);
776 bool varpool_assemble_decl (struct varpool_node *node);
777 void varpool_analyze_node (struct varpool_node *);
778 struct varpool_node * varpool_extra_name_alias (tree, tree);
779 struct varpool_node * varpool_create_variable_alias (tree, tree);
780 void varpool_reset_queue (void);
781 bool const_value_known_p (tree);
782 bool varpool_for_node_and_aliases (struct varpool_node *,
783                                    bool (*) (struct varpool_node *, void *),
784                                    void *, bool);
785 void varpool_add_new_variable (tree);
786 void symtab_initialize_asm_name_hash (void);
787 void symtab_prevail_in_asm_name_hash (symtab_node node);
788 void varpool_remove_initializer (struct varpool_node *);
789
790
791 /* Return callgraph node for given symbol and check it is a function. */
792 static inline struct cgraph_node *
793 cgraph (symtab_node node)
794 {
795   gcc_checking_assert (!node || node->symbol.type == SYMTAB_FUNCTION);
796   return (struct cgraph_node *)node;
797 }
798
799 /* Return varpool node for given symbol and check it is a variable.  */
800 static inline struct varpool_node *
801 varpool (symtab_node node)
802 {
803   gcc_checking_assert (!node || node->symbol.type == SYMTAB_VARIABLE);
804   return (struct varpool_node *)node;
805 }
806
807 /* Return callgraph node for given symbol and check it is a function. */
808 static inline struct cgraph_node *
809 cgraph_get_node (const_tree decl)
810 {
811   gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
812   return cgraph (symtab_get_node (decl));
813 }
814
815 /* Return varpool node for given symbol and check it is a function. */
816 static inline struct varpool_node *
817 varpool_get_node (const_tree decl)
818 {
819   gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
820   return varpool (symtab_get_node (decl));
821 }
822
823 /* Return asm name of cgraph node.  */
824 static inline const char *
825 cgraph_node_asm_name(struct cgraph_node *node)
826 {
827   return symtab_node_asm_name ((symtab_node)node);
828 }
829
830 /* Return asm name of varpool node.  */
831 static inline const char *
832 varpool_node_asm_name(struct varpool_node *node)
833 {
834   return symtab_node_asm_name ((symtab_node)node);
835 }
836
837 /* Return name of cgraph node.  */
838 static inline const char *
839 cgraph_node_name(struct cgraph_node *node)
840 {
841   return symtab_node_name ((symtab_node)node);
842 }
843
844 /* Return name of varpool node.  */
845 static inline const char *
846 varpool_node_name(struct varpool_node *node)
847 {
848   return symtab_node_name ((symtab_node)node);
849 }
850
851 /* Walk all symbols.  */
852 #define FOR_EACH_SYMBOL(node) \
853    for ((node) = symtab_nodes; (node); (node) = (node)->symbol.next)
854
855
856 /* Return first variable.  */
857 static inline struct varpool_node *
858 varpool_first_variable (void)
859 {
860   symtab_node node;
861   for (node = symtab_nodes; node; node = node->symbol.next)
862     if (varpool_node *vnode = dyn_cast <varpool_node> (node))
863       return vnode;
864   return NULL;
865 }
866
867 /* Return next variable after NODE.  */
868 static inline struct varpool_node *
869 varpool_next_variable (struct varpool_node *node)
870 {
871   symtab_node node1 = (symtab_node) node->symbol.next;
872   for (; node1; node1 = node1->symbol.next)
873     if (varpool_node *vnode1 = dyn_cast <varpool_node> (node1))
874       return vnode1;
875   return NULL;
876 }
877 /* Walk all variables.  */
878 #define FOR_EACH_VARIABLE(node) \
879    for ((node) = varpool_first_variable (); \
880         (node); \
881         (node) = varpool_next_variable ((node)))
882
883 /* Return first reachable static variable with initializer.  */
884 static inline struct varpool_node *
885 varpool_first_static_initializer (void)
886 {
887   symtab_node node;
888   for (node = symtab_nodes; node; node = node->symbol.next)
889     {
890       varpool_node *vnode = dyn_cast <varpool_node> (node);
891       if (vnode && DECL_INITIAL (node->symbol.decl))
892         return vnode;
893     }
894   return NULL;
895 }
896
897 /* Return next reachable static variable with initializer after NODE.  */
898 static inline struct varpool_node *
899 varpool_next_static_initializer (struct varpool_node *node)
900 {
901   symtab_node node1 = (symtab_node) node->symbol.next;
902   for (; node1; node1 = node1->symbol.next)
903     {
904       varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
905       if (vnode1 && DECL_INITIAL (node1->symbol.decl))
906         return vnode1;
907     }
908   return NULL;
909 }
910
911 /* Walk all static variables with initializer set.  */
912 #define FOR_EACH_STATIC_INITIALIZER(node) \
913    for ((node) = varpool_first_static_initializer (); (node); \
914         (node) = varpool_next_static_initializer (node))
915
916 /* Return first reachable static variable with initializer.  */
917 static inline struct varpool_node *
918 varpool_first_defined_variable (void)
919 {
920   symtab_node node;
921   for (node = symtab_nodes; node; node = node->symbol.next)
922     {
923       varpool_node *vnode = dyn_cast <varpool_node> (node);
924       if (vnode && vnode->symbol.definition)
925         return vnode;
926     }
927   return NULL;
928 }
929
930 /* Return next reachable static variable with initializer after NODE.  */
931 static inline struct varpool_node *
932 varpool_next_defined_variable (struct varpool_node *node)
933 {
934   symtab_node node1 = (symtab_node) node->symbol.next;
935   for (; node1; node1 = node1->symbol.next)
936     {
937       varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
938       if (vnode1 && vnode1->symbol.definition)
939         return vnode1;
940     }
941   return NULL;
942 }
943 /* Walk all variables with definitions in current unit.  */
944 #define FOR_EACH_DEFINED_VARIABLE(node) \
945    for ((node) = varpool_first_defined_variable (); (node); \
946         (node) = varpool_next_defined_variable (node))
947
948 /* Return first function with body defined.  */
949 static inline struct cgraph_node *
950 cgraph_first_defined_function (void)
951 {
952   symtab_node node;
953   for (node = symtab_nodes; node; node = node->symbol.next)
954     {
955       cgraph_node *cn = dyn_cast <cgraph_node> (node);
956       if (cn && cn->symbol.definition)
957         return cn;
958     }
959   return NULL;
960 }
961
962 /* Return next function with body defined after NODE.  */
963 static inline struct cgraph_node *
964 cgraph_next_defined_function (struct cgraph_node *node)
965 {
966   symtab_node node1 = (symtab_node) node->symbol.next;
967   for (; node1; node1 = node1->symbol.next)
968     {
969       cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
970       if (cn1 && cn1->symbol.definition)
971         return cn1;
972     }
973   return NULL;
974 }
975
976 /* Walk all functions with body defined.  */
977 #define FOR_EACH_DEFINED_FUNCTION(node) \
978    for ((node) = cgraph_first_defined_function (); (node); \
979         (node) = cgraph_next_defined_function ((node)))
980
981 /* Return first function.  */
982 static inline struct cgraph_node *
983 cgraph_first_function (void)
984 {
985   symtab_node node;
986   for (node = symtab_nodes; node; node = node->symbol.next)
987     if (cgraph_node *cn = dyn_cast <cgraph_node> (node))
988       return cn;
989   return NULL;
990 }
991
992 /* Return next function.  */
993 static inline struct cgraph_node *
994 cgraph_next_function (struct cgraph_node *node)
995 {
996   symtab_node node1 = (symtab_node) node->symbol.next;
997   for (; node1; node1 = node1->symbol.next)
998     if (cgraph_node *cn1 = dyn_cast <cgraph_node> (node1))
999       return cn1;
1000   return NULL;
1001 }
1002 /* Walk all functions.  */
1003 #define FOR_EACH_FUNCTION(node) \
1004    for ((node) = cgraph_first_function (); (node); \
1005         (node) = cgraph_next_function ((node)))
1006
1007 /* Return true when NODE is a function with Gimple body defined
1008    in current unit.  Functions can also be define externally or they
1009    can be thunks with no Gimple representation.
1010
1011    Note that at WPA stage, the function body may not be present in memory.  */
1012
1013 static inline bool
1014 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1015 {
1016   return node->symbol.definition && !node->thunk.thunk_p && !node->symbol.alias;
1017 }
1018
1019 /* Return first function with body defined.  */
1020 static inline struct cgraph_node *
1021 cgraph_first_function_with_gimple_body (void)
1022 {
1023   symtab_node node;
1024   for (node = symtab_nodes; node; node = node->symbol.next)
1025     {
1026       cgraph_node *cn = dyn_cast <cgraph_node> (node);
1027       if (cn && cgraph_function_with_gimple_body_p (cn))
1028         return cn;
1029     }
1030   return NULL;
1031 }
1032
1033 /* Return next reachable static variable with initializer after NODE.  */
1034 static inline struct cgraph_node *
1035 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1036 {
1037   symtab_node node1 = node->symbol.next;
1038   for (; node1; node1 = node1->symbol.next)
1039     {
1040       cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
1041       if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1042         return cn1;
1043     }
1044   return NULL;
1045 }
1046
1047 /* Walk all functions with body defined.  */
1048 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1049    for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1050         (node) = cgraph_next_function_with_gimple_body (node))
1051
1052 /* Create a new static variable of type TYPE.  */
1053 tree add_new_static_var (tree type);
1054
1055 /* Return true if iterator CSI points to nothing.  */
1056 static inline bool
1057 csi_end_p (cgraph_node_set_iterator csi)
1058 {
1059   return csi.index >= csi.set->nodes.length ();
1060 }
1061
1062 /* Advance iterator CSI.  */
1063 static inline void
1064 csi_next (cgraph_node_set_iterator *csi)
1065 {
1066   csi->index++;
1067 }
1068
1069 /* Return the node pointed to by CSI.  */
1070 static inline struct cgraph_node *
1071 csi_node (cgraph_node_set_iterator csi)
1072 {
1073   return csi.set->nodes[csi.index];
1074 }
1075
1076 /* Return an iterator to the first node in SET.  */
1077 static inline cgraph_node_set_iterator
1078 csi_start (cgraph_node_set set)
1079 {
1080   cgraph_node_set_iterator csi;
1081
1082   csi.set = set;
1083   csi.index = 0;
1084   return csi;
1085 }
1086
1087 /* Return true if SET contains NODE.  */
1088 static inline bool
1089 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1090 {
1091   cgraph_node_set_iterator csi;
1092   csi = cgraph_node_set_find (set, node);
1093   return !csi_end_p (csi);
1094 }
1095
1096 /* Return number of nodes in SET.  */
1097 static inline size_t
1098 cgraph_node_set_size (cgraph_node_set set)
1099 {
1100   return set->nodes.length ();
1101 }
1102
1103 /* Return true if iterator VSI points to nothing.  */
1104 static inline bool
1105 vsi_end_p (varpool_node_set_iterator vsi)
1106 {
1107   return vsi.index >= vsi.set->nodes.length ();
1108 }
1109
1110 /* Advance iterator VSI.  */
1111 static inline void
1112 vsi_next (varpool_node_set_iterator *vsi)
1113 {
1114   vsi->index++;
1115 }
1116
1117 /* Return the node pointed to by VSI.  */
1118 static inline struct varpool_node *
1119 vsi_node (varpool_node_set_iterator vsi)
1120 {
1121   return vsi.set->nodes[vsi.index];
1122 }
1123
1124 /* Return an iterator to the first node in SET.  */
1125 static inline varpool_node_set_iterator
1126 vsi_start (varpool_node_set set)
1127 {
1128   varpool_node_set_iterator vsi;
1129
1130   vsi.set = set;
1131   vsi.index = 0;
1132   return vsi;
1133 }
1134
1135 /* Return true if SET contains NODE.  */
1136 static inline bool
1137 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
1138 {
1139   varpool_node_set_iterator vsi;
1140   vsi = varpool_node_set_find (set, node);
1141   return !vsi_end_p (vsi);
1142 }
1143
1144 /* Return number of nodes in SET.  */
1145 static inline size_t
1146 varpool_node_set_size (varpool_node_set set)
1147 {
1148   return set->nodes.length ();
1149 }
1150
1151 /* Uniquize all constants that appear in memory.
1152    Each constant in memory thus far output is recorded
1153    in `const_desc_table'.  */
1154
1155 struct GTY(()) constant_descriptor_tree {
1156   /* A MEM for the constant.  */
1157   rtx rtl;
1158
1159   /* The value of the constant.  */
1160   tree value;
1161
1162   /* Hash of value.  Computing the hash from value each time
1163      hashfn is called can't work properly, as that means recursive
1164      use of the hash table during hash table expansion.  */
1165   hashval_t hash;
1166 };
1167
1168 /* Return true if set is nonempty.  */
1169 static inline bool
1170 cgraph_node_set_nonempty_p (cgraph_node_set set)
1171 {
1172   return !set->nodes.is_empty ();
1173 }
1174
1175 /* Return true if set is nonempty.  */
1176 static inline bool
1177 varpool_node_set_nonempty_p (varpool_node_set set)
1178 {
1179   return !set->nodes.is_empty ();
1180 }
1181
1182 /* Return true when function NODE is only called directly or it has alias.
1183    i.e. it is not externally visible, address was not taken and
1184    it is not used in any other non-standard way.  */
1185
1186 static inline bool
1187 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1188 {
1189   gcc_assert (!node->global.inlined_to);
1190   return (!node->symbol.force_output && !node->symbol.address_taken
1191           && !node->symbol.used_from_other_partition
1192           && !DECL_VIRTUAL_P (node->symbol.decl)
1193           && !DECL_STATIC_CONSTRUCTOR (node->symbol.decl)
1194           && !DECL_STATIC_DESTRUCTOR (node->symbol.decl)
1195           && !node->symbol.externally_visible);
1196 }
1197
1198 /* Return true when function NODE can be removed from callgraph
1199    if all direct calls are eliminated.  */
1200
1201 static inline bool
1202 varpool_can_remove_if_no_refs (struct varpool_node *node)
1203 {
1204   if (DECL_EXTERNAL (node->symbol.decl))
1205     return true;
1206   return (!node->symbol.force_output && !node->symbol.used_from_other_partition
1207           && ((DECL_COMDAT (node->symbol.decl)
1208                && !symtab_used_from_object_file_p ((symtab_node) node))
1209               || !node->symbol.externally_visible
1210               || DECL_HAS_VALUE_EXPR_P (node->symbol.decl)));
1211 }
1212
1213 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1214    i.e. if the variable is not externally visible or not used in some magic
1215    way (asm statement or such).
1216    The magic uses are all summarized in force_output flag.  */
1217
1218 static inline bool
1219 varpool_all_refs_explicit_p (struct varpool_node *vnode)
1220 {
1221   return (vnode->symbol.definition
1222           && !vnode->symbol.externally_visible
1223           && !vnode->symbol.used_from_other_partition
1224           && !vnode->symbol.force_output);
1225 }
1226
1227 /* Constant pool accessor function.  */
1228 htab_t constant_pool_htab (void);
1229
1230 /* FIXME: inappropriate dependency of cgraph on IPA.  */
1231 #include "ipa-ref-inline.h"
1232
1233 /* Return node that alias N is aliasing.  */
1234
1235 static inline symtab_node
1236 symtab_alias_target (symtab_node n)
1237 {
1238   struct ipa_ref *ref;
1239   ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref);
1240   gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1241   return ref->referred;
1242 }
1243
1244 static inline struct cgraph_node *
1245 cgraph_alias_target (struct cgraph_node *n)
1246 {
1247   return dyn_cast <cgraph_node> (symtab_alias_target ((symtab_node) n));
1248 }
1249
1250 static inline struct varpool_node *
1251 varpool_alias_target (struct varpool_node *n)
1252 {
1253   return dyn_cast <varpool_node> (symtab_alias_target ((symtab_node) n));
1254 }
1255
1256 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1257    Do not walk through thunks.
1258    When AVAILABILITY is non-NULL, get minimal availability in the chain.  */
1259
1260 static inline struct cgraph_node *
1261 cgraph_function_or_thunk_node (struct cgraph_node *node, enum availability *availability)
1262 {
1263   struct cgraph_node *n;
1264
1265   n = dyn_cast <cgraph_node> (symtab_alias_ultimate_target ((symtab_node)node, availability));
1266   if (!n)
1267     *availability = AVAIL_NOT_AVAILABLE;
1268   return n;
1269 }
1270 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1271    Do not walk through thunks.
1272    When AVAILABILITY is non-NULL, get minimal availability in the chain.  */
1273
1274 static inline struct varpool_node *
1275 varpool_variable_node (struct varpool_node *node, enum availability *availability)
1276 {
1277   struct varpool_node *n;
1278
1279   n = dyn_cast <varpool_node> (symtab_alias_ultimate_target ((symtab_node)node, availability));
1280   if (!n)
1281     *availability = AVAIL_NOT_AVAILABLE;
1282   return n;
1283 }
1284
1285 /* Return true when the edge E represents a direct recursion.  */
1286 static inline bool
1287 cgraph_edge_recursive_p (struct cgraph_edge *e)
1288 {
1289   struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1290   if (e->caller->global.inlined_to)
1291     return e->caller->global.inlined_to->symbol.decl == callee->symbol.decl;
1292   else
1293     return e->caller->symbol.decl == callee->symbol.decl;
1294 }
1295
1296 /* Return true if the TM_CLONE bit is set for a given FNDECL.  */
1297 static inline bool
1298 decl_is_tm_clone (const_tree fndecl)
1299 {
1300   struct cgraph_node *n = cgraph_get_node (fndecl);
1301   if (n)
1302     return n->tm_clone;
1303   return false;
1304 }
1305
1306 /* Likewise indicate that a node is needed, i.e. reachable via some
1307    external means.  */
1308
1309 static inline void
1310 cgraph_mark_force_output_node (struct cgraph_node *node)
1311 {
1312   node->symbol.force_output = 1;
1313   gcc_checking_assert (!node->global.inlined_to);
1314 }
1315
1316 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1317    or abstract function kept for debug info purposes only.  */
1318
1319 static inline bool
1320 symtab_real_symbol_p (symtab_node node)
1321 {
1322   struct cgraph_node *cnode;
1323
1324   if (!is_a <cgraph_node> (node))
1325     return true;
1326   cnode = cgraph (node);
1327   if (cnode->global.inlined_to)
1328     return false;
1329   if (cnode->abstract_and_needed)
1330     return false;
1331   return true;
1332 }
1333 #endif  /* GCC_CGRAPH_H  */