OSDN Git Service

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