OSDN Git Service

* cgraphbuild.c: Include ipa-inline.h.
[pf3gnuchains/gcc-fork.git] / gcc / cgraph.h
1 /* Callgraph handling code.
2    Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3    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"    /* FIXME: inappropriate dependency of cgraph on IPA.  */
31
32 enum availability
33 {
34   /* Not yet set by cgraph_function_body_availability.  */
35   AVAIL_UNSET,
36   /* Function body/variable initializer is unknown.  */
37   AVAIL_NOT_AVAILABLE,
38   /* Function body/variable initializer is known but might be replaced
39      by a different one from other compilation unit and thus needs to
40      be dealt with a care.  Like AVAIL_NOT_AVAILABLE it can have
41      arbitrary side effects on escaping variables and functions, while
42      like AVAILABLE it might access static variables.  */
43   AVAIL_OVERWRITABLE,
44   /* Function body/variable initializer is known and will be used in final
45      program.  */
46   AVAIL_AVAILABLE,
47   /* Function body/variable initializer is known and all it's uses are explicitly
48      visible within current unit (ie it's address is never taken and it is not
49      exported to other units).
50      Currently used only for functions.  */
51   AVAIL_LOCAL
52 };
53
54 /* This is the information that is put into the cgraph local structure
55    to recover a function.  */
56 struct lto_file_decl_data;
57
58 extern const char * const cgraph_availability_names[];
59 extern const char * const ld_plugin_symbol_resolution_names[];
60
61 /* Information about thunk, used only for same body aliases.  */
62
63 struct GTY(()) cgraph_thunk_info {
64   /* Information about the thunk.  */
65   HOST_WIDE_INT fixed_offset;
66   HOST_WIDE_INT virtual_value;
67   tree alias;
68   bool this_adjusting;
69   bool virtual_offset_p;
70   /* Set to true when alias node is thunk.  */
71   bool thunk_p;
72 };
73
74 /* Information about the function collected locally.
75    Available after function is analyzed.  */
76
77 struct GTY(()) cgraph_local_info {
78   /* File stream where this node is being written to.  */
79   struct lto_file_decl_data * lto_file_data;
80
81   /* Set when function function is visible in current compilation unit only
82      and its address is never taken.  */
83   unsigned local : 1;
84
85   /* Set when function is visible by other units.  */
86   unsigned externally_visible : 1;
87   
88   /* Set once it has been finalized so we consider it to be output.  */
89   unsigned finalized : 1;
90
91   /* False when function calling convention and signature can not be changed.
92      This is the case when __builtin_apply_args is used.  */
93   unsigned can_change_signature : 1;
94
95   /* True when the function has been originally extern inline, but it is
96      redefined now.  */
97   unsigned redefined_extern_inline : 1;
98
99   /* True if the function is going to be emitted in some other translation
100      unit, referenced from vtable.  */
101   unsigned vtable_method : 1;
102 };
103
104 /* Information about the function that needs to be computed globally
105    once compilation is finished.  Available only with -funit-at-a-time.  */
106
107 struct GTY(()) cgraph_global_info {
108   /* For inline clones this points to the function they will be
109      inlined into.  */
110   struct cgraph_node *inlined_to;
111 };
112
113 /* Information about the function that is propagated by the RTL backend.
114    Available only for functions that has been already assembled.  */
115
116 struct GTY(()) cgraph_rtl_info {
117    unsigned int preferred_incoming_stack_boundary;
118 };
119
120 /* Represent which DECL tree (or reference to such tree)
121    will be replaced by another tree while versioning.  */
122 struct GTY(()) ipa_replace_map
123 {
124   /* The tree that will be replaced.  */
125   tree old_tree;
126   /* The new (replacing) tree.  */
127   tree new_tree;
128   /* Parameter number to replace, when old_tree is NULL.  */
129   int parm_num;
130   /* True when a substitution should be done, false otherwise.  */
131   bool replace_p;
132   /* True when we replace a reference to old_tree.  */
133   bool ref_p;
134 };
135 typedef struct ipa_replace_map *ipa_replace_map_p;
136 DEF_VEC_P(ipa_replace_map_p);
137 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
138
139 struct GTY(()) cgraph_clone_info
140 {
141   VEC(ipa_replace_map_p,gc)* tree_map;
142   bitmap args_to_skip;
143   bitmap combined_args_to_skip;
144 };
145
146
147 /* The cgraph data structure.
148    Each function decl has assigned cgraph_node listing callees and callers.  */
149
150 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
151   tree decl;
152   struct cgraph_edge *callees;
153   struct cgraph_edge *callers;
154   struct cgraph_node *next;
155   struct cgraph_node *previous;
156   /* List of edges representing indirect calls with a yet undetermined
157      callee.  */
158   struct cgraph_edge *indirect_calls;
159   /* For nested functions points to function the node is nested in.  */
160   struct cgraph_node *origin;
161   /* Points to first nested function, if any.  */
162   struct cgraph_node *nested;
163   /* Pointer to the next function with same origin, if any.  */
164   struct cgraph_node *next_nested;
165   /* Pointer to the next function in cgraph_nodes_queue.  */
166   struct cgraph_node *next_needed;
167   /* Pointer to the next clone.  */
168   struct cgraph_node *next_sibling_clone;
169   struct cgraph_node *prev_sibling_clone;
170   struct cgraph_node *clones;
171   struct cgraph_node *clone_of;
172   /* For normal nodes pointer to the list of alias and thunk nodes,
173      in alias/thunk nodes pointer to the normal node.  */
174   struct cgraph_node *same_body;
175   /* Circular list of nodes in the same comdat group if non-NULL.  */
176   struct cgraph_node *same_comdat_group;
177   /* For functions with many calls sites it holds map from call expression
178      to the edge to speed up cgraph_edge function.  */
179   htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
180   /* Declaration node used to be clone of. */
181   tree former_clone_of;
182
183   PTR GTY ((skip)) aux;
184
185   /* Interprocedural passes scheduled to have their transform functions
186      applied next time we execute local pass on them.  We maintain it
187      per-function in order to allow IPA passes to introduce new functions.  */
188   VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
189
190   struct ipa_ref_list ref_list;
191   struct cgraph_local_info local;
192   struct cgraph_global_info global;
193   struct cgraph_rtl_info rtl;
194   struct cgraph_clone_info clone;
195   struct cgraph_thunk_info thunk;
196
197   /* Expected number of executions: calculated in profile.c.  */
198   gcov_type count;
199   /* How to scale counts at materialization time; used to merge
200      LTO units with different number of profile runs.  */
201   int count_materialization_scale;
202   /* Unique id of the node.  */
203   int uid;
204   /* Ordering of all cgraph nodes.  */
205   int order;
206
207   /* unique id for profiling. pid is not suitable because of different
208      number of cfg nodes with -fprofile-generate and -fprofile-use */
209   int pid;
210   enum ld_plugin_symbol_resolution resolution;
211
212   /* Set when function must be output for some reason.  The primary
213      use of this flag is to mark functions needed to be output for
214      non-standard reason.  Functions that are externally visible
215      or reachable from functions needed to be output are marked
216      by specialized flags.  */
217   unsigned needed : 1;
218   /* Set when function has address taken.
219      In current implementation it imply needed flag. */
220   unsigned address_taken : 1;
221   /* Set when decl is an abstract function pointed to by the
222      ABSTRACT_DECL_ORIGIN of a reachable function.  */
223   unsigned abstract_and_needed : 1;
224   /* Set when function is reachable by call from other function
225      that is either reachable or needed.
226      This flag is computed at original cgraph construction and then
227      updated in cgraph_remove_unreachable_nodes.  Note that after
228      cgraph_remove_unreachable_nodes cgraph still can contain unreachable
229      nodes when they are needed for virtual clone instantiation.  */
230   unsigned reachable : 1;
231   /* Set when function is reachable by call from other LTRANS partition.  */
232   unsigned reachable_from_other_partition : 1;
233   /* Set once the function is lowered (i.e. its CFG is built).  */
234   unsigned lowered : 1;
235   /* Set once the function has been instantiated and its callee
236      lists created.  */
237   unsigned analyzed : 1;
238   /* Set when function is available in the other LTRANS partition.  
239      During WPA output it is used to mark nodes that are present in
240      multiple partitions.  */
241   unsigned in_other_partition : 1;
242   /* Set when function is scheduled to be processed by local passes.  */
243   unsigned process : 1;
244   /* Set for aliases once they got through assemble_alias.  */
245   unsigned alias : 1;
246   /* Set for nodes that was constructed and finalized by frontend.  */
247   unsigned finalized_by_frontend : 1;
248   /* Set for alias and thunk nodes, same_body points to the node they are alias
249      of and they are linked through the next/previous pointers.  */
250   unsigned same_body_alias : 1;
251   /* How commonly executed the node is.  Initialized during branch
252      probabilities pass.  */
253   ENUM_BITFIELD (node_frequency) frequency : 2;
254   /* True when function can only be called at startup (from static ctor).  */
255   unsigned only_called_at_startup : 1;
256   /* True when function can only be called at startup (from static dtor).  */
257   unsigned only_called_at_exit : 1;
258 };
259
260 typedef struct cgraph_node *cgraph_node_ptr;
261
262 DEF_VEC_P(cgraph_node_ptr);
263 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
264 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
265
266 /* A cgraph node set is a collection of cgraph nodes.  A cgraph node
267    can appear in multiple sets.  */
268 struct GTY(()) cgraph_node_set_def
269 {
270   htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
271   VEC(cgraph_node_ptr, gc) *nodes;
272 };
273
274 typedef struct varpool_node *varpool_node_ptr;
275
276 DEF_VEC_P(varpool_node_ptr);
277 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
278 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
279
280 /* A varpool node set is a collection of varpool nodes.  A varpool node
281    can appear in multiple sets.  */
282 struct GTY(()) varpool_node_set_def
283 {
284   htab_t GTY((param_is (struct varpool_node_set_element_def))) hashtab;
285   VEC(varpool_node_ptr, gc) *nodes;
286 };
287
288 typedef struct cgraph_node_set_def *cgraph_node_set;
289
290 DEF_VEC_P(cgraph_node_set);
291 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
292 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
293
294 typedef struct varpool_node_set_def *varpool_node_set;
295
296 DEF_VEC_P(varpool_node_set);
297 DEF_VEC_ALLOC_P(varpool_node_set,gc);
298 DEF_VEC_ALLOC_P(varpool_node_set,heap);
299
300 /* A cgraph node set element contains an index in the vector of nodes in
301    the set.  */
302 struct GTY(()) cgraph_node_set_element_def
303 {
304   struct cgraph_node *node;
305   HOST_WIDE_INT index;
306 };
307
308 typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
309 typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
310
311 /* Iterator structure for cgraph node sets.  */
312 typedef struct
313 {
314   cgraph_node_set set;
315   unsigned index;
316 } cgraph_node_set_iterator;
317
318 /* A varpool node set element contains an index in the vector of nodes in
319    the set.  */
320 struct GTY(()) varpool_node_set_element_def
321 {
322   struct varpool_node *node;
323   HOST_WIDE_INT index;
324 };
325
326 typedef struct varpool_node_set_element_def *varpool_node_set_element;
327 typedef const struct varpool_node_set_element_def *const_varpool_node_set_element;
328
329 /* Iterator structure for varpool node sets.  */
330 typedef struct
331 {
332   varpool_node_set set;
333   unsigned index;
334 } varpool_node_set_iterator;
335
336 #define DEFCIFCODE(code, string)        CIF_ ## code,
337 /* Reasons for inlining failures.  */
338 typedef enum {
339 #include "cif-code.def"
340   CIF_N_REASONS
341 } cgraph_inline_failed_t;
342
343 /* Structure containing additional information about an indirect call.  */
344
345 struct GTY(()) cgraph_indirect_call_info
346 {
347   /* Offset accumulated from ancestor jump functions of inlined call graph
348      edges.  */
349   HOST_WIDE_INT anc_offset;
350   /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set).  */
351   HOST_WIDE_INT otr_token;
352   /* Delta by which must be added to this parameter to compensate for a skipped
353      this adjusting thunk.  */
354   HOST_WIDE_INT thunk_delta;
355   /* Type of the object from OBJ_TYPE_REF_OBJECT. */
356   tree otr_type;
357   /* Index of the parameter that is called.  */
358   int param_index;
359   /* ECF flags determined from the caller.  */
360   int ecf_flags;
361
362   /* Set when the call is a virtual call with the parameter being the
363      associated object pointer rather than a simple direct call.  */
364   unsigned polymorphic : 1;
365 };
366
367 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
368   /* Expected number of executions: calculated in profile.c.  */
369   gcov_type count;
370   struct cgraph_node *caller;
371   struct cgraph_node *callee;
372   struct cgraph_edge *prev_caller;
373   struct cgraph_edge *next_caller;
374   struct cgraph_edge *prev_callee;
375   struct cgraph_edge *next_callee;
376   gimple call_stmt;
377   /* Additional information about an indirect call.  Not cleared when an edge
378      becomes direct.  */
379   struct cgraph_indirect_call_info *indirect_info;
380   PTR GTY ((skip (""))) aux;
381   /* When equal to CIF_OK, inline this call.  Otherwise, points to the
382      explanation why function was not inlined.  */
383   cgraph_inline_failed_t inline_failed;
384   /* The stmt_uid of call_stmt.  This is used by LTO to recover the call_stmt
385      when the function is serialized in.  */
386   unsigned int lto_stmt_uid;
387   /* Expected frequency of executions within the function.
388      When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
389      per function call.  The range is 0 to CGRAPH_FREQ_MAX.  */
390   int frequency;
391   /* Unique id of the edge.  */
392   int uid;
393   /* Estimated size and time of the call statement.  */
394   int call_stmt_size;
395   int call_stmt_time;
396   /* Depth of loop nest, 1 means no loop nest.  */
397   unsigned short int loop_nest;
398   /* Whether this edge was made direct by indirect inlining.  */
399   unsigned int indirect_inlining_edge : 1;
400   /* Whether this edge describes an indirect call with an undetermined
401      callee.  */
402   unsigned int indirect_unknown_callee : 1;
403   /* Whether this edge is still a dangling  */
404   /* True if the corresponding CALL stmt cannot be inlined.  */
405   unsigned int call_stmt_cannot_inline_p : 1;
406   /* Can this call throw externally?  */
407   unsigned int can_throw_external : 1;
408 };
409
410 #define CGRAPH_FREQ_BASE 1000
411 #define CGRAPH_FREQ_MAX 100000
412
413 typedef struct cgraph_edge *cgraph_edge_p;
414
415 DEF_VEC_P(cgraph_edge_p);
416 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
417
418 /* The varpool data structure.
419    Each static variable decl has assigned varpool_node.  */
420
421 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
422   tree decl;
423   /* Pointer to the next function in varpool_nodes.  */
424   struct varpool_node *next, *prev;
425   /* Pointer to the next function in varpool_nodes_queue.  */
426   struct varpool_node *next_needed, *prev_needed;
427   /* For normal nodes a pointer to the first extra name alias.  For alias
428      nodes a pointer to the normal node.  */
429   struct varpool_node *extra_name;
430   /* Circular list of nodes in the same comdat group if non-NULL.  */
431   struct varpool_node *same_comdat_group;
432   struct ipa_ref_list ref_list;
433   /* File stream where this node is being written to.  */
434   struct lto_file_decl_data * lto_file_data;
435   PTR GTY ((skip)) aux;
436   /* Ordering of all cgraph nodes.  */
437   int order;
438   enum ld_plugin_symbol_resolution resolution;
439
440   /* Set when function must be output - it is externally visible
441      or its address is taken.  */
442   unsigned needed : 1;
443   /* Needed variables might become dead by optimization.  This flag
444      forces the variable to be output even if it appears dead otherwise.  */
445   unsigned force_output : 1;
446   /* Set once the variable has been instantiated and its callee
447      lists created.  */
448   unsigned analyzed : 1;
449   /* Set once it has been finalized so we consider it to be output.  */
450   unsigned finalized : 1;
451   /* Set when variable is scheduled to be assembled.  */
452   unsigned output : 1;
453   /* Set when function is visible by other units.  */
454   unsigned externally_visible : 1;
455   /* Set for aliases once they got through assemble_alias.  Also set for
456      extra name aliases in varpool_extra_name_alias.  */
457   unsigned alias : 1;
458   /* Set when variable is used from other LTRANS partition.  */
459   unsigned used_from_other_partition : 1;
460   /* Set when variable is available in the other LTRANS partition.
461      During WPA output it is used to mark nodes that are present in
462      multiple partitions.  */
463   unsigned in_other_partition : 1;
464 };
465
466 /* Every top level asm statement is put into a cgraph_asm_node.  */
467
468 struct GTY(()) cgraph_asm_node {
469   /* Next asm node.  */
470   struct cgraph_asm_node *next;
471   /* String for this asm node.  */
472   tree asm_str;
473   /* Ordering of all cgraph nodes.  */
474   int order;
475 };
476
477 extern GTY(()) struct cgraph_node *cgraph_nodes;
478 extern GTY(()) int cgraph_n_nodes;
479 extern GTY(()) int cgraph_max_uid;
480 extern GTY(()) int cgraph_edge_max_uid;
481 extern GTY(()) int cgraph_max_pid;
482 extern bool cgraph_global_info_ready;
483 enum cgraph_state
484 {
485   /* Callgraph is being constructed.  It is safe to add new functions.  */
486   CGRAPH_STATE_CONSTRUCTION,
487   /* Callgraph is built and IPA passes are being run.  */
488   CGRAPH_STATE_IPA,
489   /* Callgraph is built and all functions are transformed to SSA form.  */
490   CGRAPH_STATE_IPA_SSA,
491   /* Functions are now ordered and being passed to RTL expanders.  */
492   CGRAPH_STATE_EXPANSION,
493   /* All cgraph expansion is done.  */
494   CGRAPH_STATE_FINISHED
495 };
496 extern enum cgraph_state cgraph_state;
497 extern bool cgraph_function_flags_ready;
498 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
499 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
500
501 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
502 extern GTY(()) int cgraph_order;
503
504 /* In cgraph.c  */
505 void dump_cgraph (FILE *);
506 void debug_cgraph (void);
507 void dump_cgraph_node (FILE *, struct cgraph_node *);
508 void debug_cgraph_node (struct cgraph_node *);
509 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
510 void cgraph_remove_edge (struct cgraph_edge *);
511 void cgraph_remove_node (struct cgraph_node *);
512 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
513 void cgraph_release_function_body (struct cgraph_node *);
514 void cgraph_node_remove_callees (struct cgraph_node *node);
515 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
516                                         struct cgraph_node *,
517                                         gimple, gcov_type, int, int);
518 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
519                                                  int, gcov_type, int, int);
520 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
521 struct cgraph_node * cgraph_get_node (const_tree);
522 struct cgraph_node * cgraph_get_node_or_alias (const_tree);
523 struct cgraph_node * cgraph_create_node (tree);
524 struct cgraph_node * cgraph_get_create_node (tree);
525 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
526 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
527                                        HOST_WIDE_INT, tree, tree);
528 void cgraph_remove_same_body_alias (struct cgraph_node *);
529 struct cgraph_node *cgraph_node_for_asm (tree);
530 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
531 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
532 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
533 void cgraph_create_edge_including_clones (struct cgraph_node *,
534                                           struct cgraph_node *,
535                                           gimple, gimple, gcov_type, int, int,
536                                           cgraph_inline_failed_t);
537 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
538 struct cgraph_local_info *cgraph_local_info (tree);
539 struct cgraph_global_info *cgraph_global_info (tree);
540 struct cgraph_rtl_info *cgraph_rtl_info (tree);
541 const char * cgraph_node_name (struct cgraph_node *);
542 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
543                                         struct cgraph_node *, gimple,
544                                         unsigned, gcov_type, int, int, bool);
545 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type, int,
546                                         int, bool, VEC(cgraph_edge_p,heap) *);
547
548 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
549 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *,
550                               HOST_WIDE_INT);
551
552 struct cgraph_asm_node *cgraph_add_asm_node (tree);
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 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
561                                                   VEC(cgraph_edge_p,heap)*,
562                                                   VEC(ipa_replace_map_p,gc)* tree_map,
563                                                   bitmap args_to_skip,
564                                                   const char *clone_name);
565
566 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
567 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
568 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
569 tree clone_function_name (tree decl, const char *);
570 bool cgraph_node_cannot_return (struct cgraph_node *);
571 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
572 bool cgraph_will_be_removed_from_program_if_no_direct_calls
573   (struct cgraph_node *node);
574 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
575   (struct cgraph_node *node);
576 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution);
577 bool cgraph_used_from_object_file_p (struct cgraph_node *node);
578 bool varpool_used_from_object_file_p (struct varpool_node *node);
579
580 /* In cgraphunit.c  */
581 extern FILE *cgraph_dump_file;
582 void cgraph_finalize_function (tree, bool);
583 void cgraph_mark_if_needed (tree);
584 void cgraph_analyze_function (struct cgraph_node *);
585 void cgraph_finalize_compilation_unit (void);
586 void cgraph_optimize (void);
587 void cgraph_mark_needed_node (struct cgraph_node *);
588 void cgraph_mark_address_taken_node (struct cgraph_node *);
589 void cgraph_mark_reachable_node (struct cgraph_node *);
590 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
591 bool cgraph_preserve_function_body_p (tree);
592 void verify_cgraph (void);
593 void verify_cgraph_node (struct cgraph_node *);
594 void cgraph_build_static_cdtor (char which, tree body, int priority);
595 void cgraph_reset_static_var_maps (void);
596 void init_cgraph (void);
597 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
598                                                 VEC(cgraph_edge_p,heap)*,
599                                                 VEC(ipa_replace_map_p,gc)*,
600                                                 bitmap, bitmap, basic_block,
601                                                 const char *);
602 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
603                                bitmap, basic_block);
604 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
605 void record_references_in_initializer (tree, bool);
606 bool cgraph_process_new_functions (void);
607
608 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
609
610 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
611 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
612 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
613                                   void *);
614 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
615                                   void *);
616 struct cgraph_edge_hook_list;
617 struct cgraph_node_hook_list;
618 struct cgraph_2edge_hook_list;
619 struct cgraph_2node_hook_list;
620 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
621 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
622 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
623                                                             void *);
624 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
625 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
626                                                                   void *);
627 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
628 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
629 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
630 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
631 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
632 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
633 void cgraph_materialize_all_clones (void);
634 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
635 bool cgraph_propagate_frequency (struct cgraph_node *node);
636 /* In cgraphbuild.c  */
637 unsigned int rebuild_cgraph_edges (void);
638 void cgraph_rebuild_references (void);
639 void reset_inline_failed (struct cgraph_node *);
640 int compute_call_stmt_bb_frequency (tree, basic_block bb);
641
642 /* In ipa.c  */
643 bool cgraph_remove_unreachable_nodes (bool, FILE *);
644 int cgraph_postorder (struct cgraph_node **);
645 cgraph_node_set cgraph_node_set_new (void);
646 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
647                                                struct cgraph_node *);
648 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
649 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
650 void dump_cgraph_node_set (FILE *, cgraph_node_set);
651 void debug_cgraph_node_set (cgraph_node_set);
652
653 varpool_node_set varpool_node_set_new (void);
654 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
655                                                struct varpool_node *);
656 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
657 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
658 void dump_varpool_node_set (FILE *, varpool_node_set);
659 void debug_varpool_node_set (varpool_node_set);
660 void ipa_discover_readonly_nonaddressable_vars (void);
661 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
662
663 /* In predict.c  */
664 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
665
666 /* In varpool.c  */
667 extern GTY(()) struct varpool_node *varpool_nodes_queue;
668 extern GTY(()) struct varpool_node *varpool_nodes;
669
670 struct varpool_node *varpool_node (tree);
671 struct varpool_node *varpool_node_for_asm (tree asmname);
672 void varpool_mark_needed_node (struct varpool_node *);
673 void debug_varpool (void);
674 void dump_varpool (FILE *);
675 void dump_varpool_node (FILE *, struct varpool_node *);
676
677 void varpool_finalize_decl (tree);
678 bool decide_is_variable_needed (struct varpool_node *, tree);
679 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
680 void cgraph_make_decl_local (tree);
681 void cgraph_make_node_local (struct cgraph_node *);
682 bool cgraph_node_can_be_local_p (struct cgraph_node *);
683
684
685 struct varpool_node * varpool_get_node (const_tree decl);
686 void varpool_remove_node (struct varpool_node *node);
687 void varpool_finalize_named_section_flags (struct varpool_node *node);
688 bool varpool_assemble_pending_decls (void);
689 bool varpool_assemble_decl (struct varpool_node *node);
690 bool varpool_analyze_pending_decls (void);
691 void varpool_remove_unreferenced_decls (void);
692 void varpool_empty_needed_queue (void);
693 struct varpool_node * varpool_extra_name_alias (tree, tree);
694 const char * varpool_node_name (struct varpool_node *node);
695 void varpool_reset_queue (void);
696 bool const_value_known_p (tree);
697
698 /* Walk all reachable static variables.  */
699 #define FOR_EACH_STATIC_VARIABLE(node) \
700    for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
701
702 /* Return first reachable static variable with initializer.  */
703 static inline struct varpool_node *
704 varpool_first_static_initializer (void)
705 {
706   struct varpool_node *node;
707   for (node = varpool_nodes_queue; node; node = node->next_needed)
708     {
709       gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
710       if (DECL_INITIAL (node->decl))
711         return node;
712     }
713   return NULL;
714 }
715
716 /* Return next reachable static variable with initializer after NODE.  */
717 static inline struct varpool_node *
718 varpool_next_static_initializer (struct varpool_node *node)
719 {
720   for (node = node->next_needed; node; node = node->next_needed)
721     {
722       gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
723       if (DECL_INITIAL (node->decl))
724         return node;
725     }
726   return NULL;
727 }
728
729 /* Walk all static variables with initializer set.  */
730 #define FOR_EACH_STATIC_INITIALIZER(node) \
731    for ((node) = varpool_first_static_initializer (); (node); \
732         (node) = varpool_next_static_initializer (node))
733
734 /* In ipa-inline.c  */
735 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
736 void compute_inline_parameters (struct cgraph_node *);
737 cgraph_inline_failed_t cgraph_edge_inlinable_p (struct cgraph_edge *);
738
739
740 /* Create a new static variable of type TYPE.  */
741 tree add_new_static_var (tree type);
742
743 /* Return true if iterator CSI points to nothing.  */
744 static inline bool
745 csi_end_p (cgraph_node_set_iterator csi)
746 {
747   return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
748 }
749
750 /* Advance iterator CSI.  */
751 static inline void
752 csi_next (cgraph_node_set_iterator *csi)
753 {
754   csi->index++;
755 }
756
757 /* Return the node pointed to by CSI.  */
758 static inline struct cgraph_node *
759 csi_node (cgraph_node_set_iterator csi)
760 {
761   return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
762 }
763
764 /* Return an iterator to the first node in SET.  */
765 static inline cgraph_node_set_iterator
766 csi_start (cgraph_node_set set)
767 {
768   cgraph_node_set_iterator csi;
769
770   csi.set = set;
771   csi.index = 0;
772   return csi;
773 }
774
775 /* Return true if SET contains NODE.  */
776 static inline bool
777 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
778 {
779   cgraph_node_set_iterator csi;
780   csi = cgraph_node_set_find (set, node);
781   return !csi_end_p (csi);
782 }
783
784 /* Return number of nodes in SET.  */
785 static inline size_t
786 cgraph_node_set_size (cgraph_node_set set)
787 {
788   return htab_elements (set->hashtab);
789 }
790
791 /* Return true if iterator VSI points to nothing.  */
792 static inline bool
793 vsi_end_p (varpool_node_set_iterator vsi)
794 {
795   return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
796 }
797
798 /* Advance iterator VSI.  */
799 static inline void
800 vsi_next (varpool_node_set_iterator *vsi)
801 {
802   vsi->index++;
803 }
804
805 /* Return the node pointed to by VSI.  */
806 static inline struct varpool_node *
807 vsi_node (varpool_node_set_iterator vsi)
808 {
809   return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
810 }
811
812 /* Return an iterator to the first node in SET.  */
813 static inline varpool_node_set_iterator
814 vsi_start (varpool_node_set set)
815 {
816   varpool_node_set_iterator vsi;
817
818   vsi.set = set;
819   vsi.index = 0;
820   return vsi;
821 }
822
823 /* Return true if SET contains NODE.  */
824 static inline bool
825 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
826 {
827   varpool_node_set_iterator vsi;
828   vsi = varpool_node_set_find (set, node);
829   return !vsi_end_p (vsi);
830 }
831
832 /* Return number of nodes in SET.  */
833 static inline size_t
834 varpool_node_set_size (varpool_node_set set)
835 {
836   return htab_elements (set->hashtab);
837 }
838
839 /* Uniquize all constants that appear in memory.
840    Each constant in memory thus far output is recorded
841    in `const_desc_table'.  */
842
843 struct GTY(()) constant_descriptor_tree {
844   /* A MEM for the constant.  */
845   rtx rtl;
846
847   /* The value of the constant.  */
848   tree value;
849
850   /* Hash of value.  Computing the hash from value each time
851      hashfn is called can't work properly, as that means recursive
852      use of the hash table during hash table expansion.  */
853   hashval_t hash;
854 };
855
856 /* Return true if set is nonempty.  */
857 static inline bool
858 cgraph_node_set_nonempty_p (cgraph_node_set set)
859 {
860   return !VEC_empty (cgraph_node_ptr, set->nodes);
861 }
862
863 /* Return true if set is nonempty.  */
864 static inline bool
865 varpool_node_set_nonempty_p (varpool_node_set set)
866 {
867   return !VEC_empty (varpool_node_ptr, set->nodes);
868 }
869
870 /* Return true when function NODE is only called directly.
871    i.e. it is not externally visible, address was not taken and
872    it is not used in any other non-standard way.  */
873
874 static inline bool
875 cgraph_only_called_directly_p (struct cgraph_node *node)
876 {
877   gcc_assert (!node->global.inlined_to);
878   return (!node->needed && !node->address_taken
879           && !node->reachable_from_other_partition
880           && !DECL_STATIC_CONSTRUCTOR (node->decl)
881           && !DECL_STATIC_DESTRUCTOR (node->decl)
882           && !node->local.externally_visible);
883 }
884
885 /* Return true when function NODE can be removed from callgraph
886    if all direct calls are eliminated.  */
887
888 static inline bool
889 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
890 {
891   /* Extern inlines can always go, we will use the external definition.  */
892   if (DECL_EXTERNAL (node->decl))
893     return true;
894   return !node->address_taken && cgraph_can_remove_if_no_direct_calls_and_refs_p (node);
895 }
896
897 /* Return true when function NODE can be removed from callgraph
898    if all direct calls are eliminated.  */
899
900 static inline bool
901 varpool_can_remove_if_no_refs (struct varpool_node *node)
902 {
903   return (!node->force_output && !node->used_from_other_partition
904           && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
905               || DECL_ARTIFICIAL (node->decl))
906           && (DECL_COMDAT (node->decl) || !node->externally_visible));
907 }
908
909 /* Return true when all references to VNODE must be visible in ipa_ref_list.
910    i.e. if the variable is not externally visible or not used in some magic
911    way (asm statement or such).
912    The magic uses are all summarized in force_output flag.  */
913
914 static inline bool
915 varpool_all_refs_explicit_p (struct varpool_node *vnode)
916 {
917   return (!vnode->externally_visible
918           && !vnode->used_from_other_partition
919           && !vnode->force_output);
920 }
921
922 /* Constant pool accessor function.  */
923 htab_t constant_pool_htab (void);
924
925 /* Return true when the edge E represents a direct recursion.  */
926 static inline bool
927 cgraph_edge_recursive_p (struct cgraph_edge *e)
928 {
929   if (e->caller->global.inlined_to)
930     return e->caller->global.inlined_to->decl == e->callee->decl;
931   else
932     return e->caller->decl == e->callee->decl;
933 }
934
935
936 /* FIXME: inappropriate dependency of cgraph on IPA.  */
937 #include "ipa-ref-inline.h"
938
939 #endif  /* GCC_CGRAPH_H  */