OSDN Git Service

* cgraph.c: Update copyright.
[pf3gnuchains/gcc-fork.git] / gcc / cgraph.h
1 /* Callgraph handling code.
2    Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3    Contributed by Jan Hubicka
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA.  */
21
22 #ifndef GCC_CGRAPH_H
23 #define GCC_CGRAPH_H
24 #include "tree.h"
25 #include "basic-block.h"
26
27 enum availability
28 {
29   /* Not yet set by cgraph_function_body_availability.  */
30   AVAIL_UNSET,
31   /* Function body/variable initializer is unknown.  */
32   AVAIL_NOT_AVAILABLE,
33   /* Function body/variable initializer is known but might be replaced
34      by a different one from other compilation unit and thus needs to
35      be dealt with a care.  Like AVAIL_NOT_AVAILABLE it can have
36      arbitrary side effects on escaping variables and functions, while
37      like AVAILABLE it might access static variables.  */
38   AVAIL_OVERWRITABLE,
39   /* Function body/variable initializer is known and will be used in final
40      program.  */
41   AVAIL_AVAILABLE,
42   /* Function body/variable initializer is known and all it's uses are explicitly
43      visible within current unit (ie it's address is never taken and it is not
44      exported to other units).
45      Currently used only for functions.  */
46   AVAIL_LOCAL
47 };
48
49 /* Information about the function collected locally.
50    Available after function is analyzed.  */
51
52 struct cgraph_local_info GTY(())
53 {
54   /* Estimated stack frame consumption by the function.  */
55   HOST_WIDE_INT estimated_self_stack_size;
56
57   /* Size of the function before inlining.  */
58   int self_insns;
59
60   /* Set when function function is visible in current compilation unit only
61      and its address is never taken.  */
62   unsigned local : 1;
63
64   /* Set when function is visible by other units.  */
65   unsigned externally_visible : 1;
66
67   /* Set once it has been finalized so we consider it to be output.  */
68   unsigned finalized : 1;
69
70   /* False when there something makes inlining impossible (such as va_arg).  */
71   unsigned inlinable : 1;
72
73   /* True when function should be inlined independently on its size.  */
74   unsigned disregard_inline_limits : 1;
75
76   /* True when the function has been originally extern inline, but it is
77      redefined now.  */
78   unsigned redefined_extern_inline : 1;
79
80   /* True if statics_read_for_function and
81      statics_written_for_function contain valid data.  */
82   unsigned for_functions_valid : 1;
83
84   /* True if the function is going to be emitted in some other translation
85      unit, referenced from vtable.  */
86   unsigned vtable_method : 1;
87 };
88
89 /* Information about the function that needs to be computed globally
90    once compilation is finished.  Available only with -funit-at-time.  */
91
92 struct cgraph_global_info GTY(())
93 {
94   /* Estimated stack frame consumption by the function.  */
95   HOST_WIDE_INT estimated_stack_size;
96   /* Expected offset of the stack frame of inlined function.  */
97   HOST_WIDE_INT stack_frame_offset;
98
99   /* For inline clones this points to the function they will be inlined into.  */
100   struct cgraph_node *inlined_to;
101
102   /* Estimated size of the function after inlining.  */
103   int insns;
104
105   /* Estimated growth after inlining.  INT_MIN if not computed.  */
106   int estimated_growth;
107
108   /* Set iff the function has been inlined at least once.  */
109   bool inlined;
110 };
111
112 /* Information about the function that is propagated by the RTL backend.
113    Available only for functions that has been already assembled.  */
114
115 struct cgraph_rtl_info GTY(())
116 {
117    int preferred_incoming_stack_boundary;
118 };
119
120 /* The cgraph data structure.
121    Each function decl has assigned cgraph_node listing callees and callers.  */
122
123 struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
124 {
125   tree decl;
126   struct cgraph_edge *callees;
127   struct cgraph_edge *callers;
128   struct cgraph_node *next;
129   struct cgraph_node *previous;
130   /* For nested functions points to function the node is nested in.  */
131   struct cgraph_node *origin;
132   /* Points to first nested function, if any.  */
133   struct cgraph_node *nested;
134   /* Pointer to the next function with same origin, if any.  */
135   struct cgraph_node *next_nested;
136   /* Pointer to the next function in cgraph_nodes_queue.  */
137   struct cgraph_node *next_needed;
138   /* Pointer to the next clone.  */
139   struct cgraph_node *next_clone;
140   struct cgraph_node *prev_clone;
141   /* Pointer to a single unique cgraph node for this function.  If the
142      function is to be output, this is the copy that will survive.  */
143   struct cgraph_node *master_clone;
144   /* For functions with many calls sites it holds map from call expression
145      to the edge to speed up cgraph_edge function.  */
146   htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
147
148   PTR GTY ((skip)) aux;
149
150   struct cgraph_local_info local;
151   struct cgraph_global_info global;
152   struct cgraph_rtl_info rtl;
153
154   /* Expected number of executions: calculated in profile.c.  */
155   gcov_type count;
156   /* Unique id of the node.  */
157   int uid;
158   /* Ordering of all cgraph nodes.  */
159   int order;
160
161   /* Set when function must be output - it is externally visible
162      or its address is taken.  */
163   unsigned needed : 1;
164   /* Set when function is reachable by call from other function
165      that is either reachable or needed.  */
166   unsigned reachable : 1;
167   /* Set once the function is lowered (i.e. its CFG is built).  */
168   unsigned lowered : 1;
169   /* Set once the function has been instantiated and its callee
170      lists created.  */
171   unsigned analyzed : 1;
172   /* Set when function is scheduled to be assembled.  */
173   unsigned output : 1;
174   /* Set for aliases once they got through assemble_alias.  */
175   unsigned alias : 1;
176
177   /* In non-unit-at-a-time mode the function body of inline candidates is saved
178      into clone before compiling so the function in original form can be
179      inlined later.  This pointer points to the clone.  */
180   tree inline_decl;
181 };
182
183 struct cgraph_edge GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
184 {
185   struct cgraph_node *caller;
186   struct cgraph_node *callee;
187   struct cgraph_edge *prev_caller;
188   struct cgraph_edge *next_caller;
189   struct cgraph_edge *prev_callee;
190   struct cgraph_edge *next_callee;
191   tree call_stmt;
192   PTR GTY ((skip (""))) aux;
193   /* When NULL, inline this call.  When non-NULL, points to the explanation
194      why function was not inlined.  */
195   const char *inline_failed;
196   /* Expected number of executions: calculated in profile.c.  */
197   gcov_type count;
198   /* Depth of loop nest, 1 means no loop nest.  */
199   int loop_nest;
200 };
201
202 typedef struct cgraph_edge *cgraph_edge_p;
203
204 DEF_VEC_P(cgraph_edge_p);
205 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
206
207 /* The cgraph_varpool data structure.
208    Each static variable decl has assigned cgraph_varpool_node.  */
209
210 struct cgraph_varpool_node GTY(())
211 {
212   tree decl;
213   /* Pointer to the next function in cgraph_varpool_nodes.  */
214   struct cgraph_varpool_node *next;
215   /* Pointer to the next function in cgraph_varpool_nodes_queue.  */
216   struct cgraph_varpool_node *next_needed;
217   /* Ordering of all cgraph nodes.  */
218   int order;
219
220   /* Set when function must be output - it is externally visible
221      or its address is taken.  */
222   unsigned needed : 1;
223   /* Needed variables might become dead by optimization.  This flag
224      forces the variable to be output even if it appears dead otherwise.  */
225   unsigned force_output : 1;
226   /* Set once the variable has been instantiated and its callee
227      lists created.  */
228   unsigned analyzed : 1;
229   /* Set once it has been finalized so we consider it to be output.  */
230   unsigned finalized : 1;
231   /* Set when variable is scheduled to be assembled.  */
232   unsigned output : 1;
233   /* Set when function is visible by other units.  */
234   unsigned externally_visible : 1;
235   /* Set for aliases once they got through assemble_alias.  */
236   unsigned alias : 1;
237 };
238
239 /* Every top level asm statement is put into a cgraph_asm_node.  */
240
241 struct cgraph_asm_node GTY(())
242 {
243   /* Next asm node.  */
244   struct cgraph_asm_node *next;
245   /* String for this asm node.  */
246   tree asm_str;
247   /* Ordering of all cgraph nodes.  */
248   int order;
249 };
250
251 extern GTY(()) struct cgraph_node *cgraph_nodes;
252 extern GTY(()) int cgraph_n_nodes;
253 extern GTY(()) int cgraph_max_uid;
254 extern bool cgraph_global_info_ready;
255 extern bool cgraph_function_flags_ready;
256 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
257 extern GTY(()) struct cgraph_node *cgraph_expand_queue;
258
259 extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_first_unanalyzed_node;
260 extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_nodes_queue;
261 extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_nodes;
262 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
263 extern GTY(()) int cgraph_order;
264
265 /* In cgraph.c  */
266 void dump_cgraph (FILE *);
267 void dump_cgraph_node (FILE *, struct cgraph_node *);
268 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
269 void dump_varpool (FILE *);
270 void dump_cgraph_varpool_node (FILE *, struct cgraph_varpool_node *);
271 void cgraph_remove_edge (struct cgraph_edge *);
272 void cgraph_remove_node (struct cgraph_node *);
273 void cgraph_node_remove_callees (struct cgraph_node *node);
274 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
275                                         struct cgraph_node *,
276                                         tree, gcov_type, int);
277 struct cgraph_node *cgraph_node (tree);
278 struct cgraph_node *cgraph_node_for_asm (tree asmname);
279 struct cgraph_edge *cgraph_edge (struct cgraph_node *, tree);
280 void cgraph_set_call_stmt (struct cgraph_edge *, tree);
281 struct cgraph_local_info *cgraph_local_info (tree);
282 struct cgraph_global_info *cgraph_global_info (tree);
283 struct cgraph_rtl_info *cgraph_rtl_info (tree);
284 const char * cgraph_node_name (struct cgraph_node *);
285 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
286                                         struct cgraph_node *,
287                                         tree, gcov_type, int, bool);
288 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type,
289                                         int, bool);
290
291 struct cgraph_varpool_node *cgraph_varpool_node (tree);
292 struct cgraph_varpool_node *cgraph_varpool_node_for_asm (tree asmname);
293 void cgraph_varpool_mark_needed_node (struct cgraph_varpool_node *);
294 void cgraph_varpool_finalize_decl (tree);
295 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
296
297 struct cgraph_asm_node *cgraph_add_asm_node (tree);
298
299 bool cgraph_function_possibly_inlined_p (tree);
300 void cgraph_unnest_node (struct cgraph_node *);
301 void cgraph_varpool_enqueue_needed_node (struct cgraph_varpool_node *);
302 void cgraph_varpool_reset_queue (void);
303 bool decide_is_variable_needed (struct cgraph_varpool_node *, tree);
304
305 enum availability cgraph_function_body_availability (struct cgraph_node *);
306 enum availability cgraph_variable_initializer_availability (struct cgraph_varpool_node *);
307 bool cgraph_is_master_clone (struct cgraph_node *);
308 struct cgraph_node *cgraph_master_clone (struct cgraph_node *);
309 void cgraph_add_new_function (tree);
310
311 /* In cgraphunit.c  */
312 bool cgraph_varpool_assemble_pending_decls (void);
313 void cgraph_finalize_function (tree, bool);
314 void cgraph_finalize_compilation_unit (void);
315 void cgraph_optimize (void);
316 void cgraph_mark_needed_node (struct cgraph_node *);
317 void cgraph_mark_reachable_node (struct cgraph_node *);
318 bool cgraph_inline_p (struct cgraph_edge *, const char **reason);
319 bool cgraph_preserve_function_body_p (tree);
320 void verify_cgraph (void);
321 void verify_cgraph_node (struct cgraph_node *);
322 void cgraph_build_static_cdtor (char which, tree body, int priority);
323 void cgraph_reset_static_var_maps (void);
324 void init_cgraph (void);
325 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
326                                                 VEC(cgraph_edge_p,heap)*,
327                                                 varray_type);
328 void cgraph_analyze_function (struct cgraph_node *);
329 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
330
331 /* In ipa.c  */
332 bool cgraph_remove_unreachable_nodes (bool, FILE *);
333 int cgraph_postorder (struct cgraph_node **);
334
335 /* In ipa-inline.c  */
336 bool cgraph_decide_inlining_incrementally (struct cgraph_node *, bool);
337 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
338 void cgraph_mark_inline_edge (struct cgraph_edge *, bool);
339 bool cgraph_default_inline_p (struct cgraph_node *, const char **);
340 #endif  /* GCC_CGRAPH_H  */