OSDN Git Service

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