OSDN Git Service

Daily bump.
[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 extern const char * const cgraph_availability_names[];
50
51 /* Information about the function collected locally.
52    Available after function is analyzed.  */
53
54 struct cgraph_local_info GTY(())
55 {
56   /* Estimated stack frame consumption by the function.  */
57   HOST_WIDE_INT estimated_self_stack_size;
58
59   /* Size of the function before inlining.  */
60   int self_insns;
61
62   /* Set when function function is visible in current compilation unit only
63      and its address is never taken.  */
64   unsigned local : 1;
65
66   /* Set when function is visible by other units.  */
67   unsigned externally_visible : 1;
68
69   /* Set once it has been finalized so we consider it to be output.  */
70   unsigned finalized : 1;
71
72   /* False when there something makes inlining impossible (such as va_arg).  */
73   unsigned inlinable : 1;
74
75   /* True when function should be inlined independently on its size.  */
76   unsigned disregard_inline_limits : 1;
77
78   /* True when the function has been originally extern inline, but it is
79      redefined now.  */
80   unsigned redefined_extern_inline : 1;
81
82   /* True if statics_read_for_function and
83      statics_written_for_function contain valid data.  */
84   unsigned for_functions_valid : 1;
85
86   /* True if the function is going to be emitted in some other translation
87      unit, referenced from vtable.  */
88   unsigned vtable_method : 1;
89 };
90
91 /* Information about the function that needs to be computed globally
92    once compilation is finished.  Available only with -funit-at-time.  */
93
94 struct cgraph_global_info GTY(())
95 {
96   /* Estimated stack frame consumption by the function.  */
97   HOST_WIDE_INT estimated_stack_size;
98   /* Expected offset of the stack frame of inlined function.  */
99   HOST_WIDE_INT stack_frame_offset;
100
101   /* For inline clones this points to the function they will be inlined into.  */
102   struct cgraph_node *inlined_to;
103
104   /* Estimated size of the function after inlining.  */
105   int insns;
106
107   /* Estimated growth after inlining.  INT_MIN if not computed.  */
108   int estimated_growth;
109
110   /* Set iff the function has been inlined at least once.  */
111   bool inlined;
112 };
113
114 /* Information about the function that is propagated by the RTL backend.
115    Available only for functions that has been already assembled.  */
116
117 struct cgraph_rtl_info GTY(())
118 {
119    int preferred_incoming_stack_boundary;
120 };
121
122 /* The cgraph data structure.
123    Each function decl has assigned cgraph_node listing callees and callers.  */
124
125 struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
126 {
127   tree decl;
128   struct cgraph_edge *callees;
129   struct cgraph_edge *callers;
130   struct cgraph_node *next;
131   struct cgraph_node *previous;
132   /* For nested functions points to function the node is nested in.  */
133   struct cgraph_node *origin;
134   /* Points to first nested function, if any.  */
135   struct cgraph_node *nested;
136   /* Pointer to the next function with same origin, if any.  */
137   struct cgraph_node *next_nested;
138   /* Pointer to the next function in cgraph_nodes_queue.  */
139   struct cgraph_node *next_needed;
140   /* Pointer to the next clone.  */
141   struct cgraph_node *next_clone;
142   struct cgraph_node *prev_clone;
143   /* Pointer to a single unique cgraph node for this function.  If the
144      function is to be output, this is the copy that will survive.  */
145   struct cgraph_node *master_clone;
146   /* For functions with many calls sites it holds map from call expression
147      to the edge to speed up cgraph_edge function.  */
148   htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
149
150   PTR GTY ((skip)) aux;
151
152   struct cgraph_local_info local;
153   struct cgraph_global_info global;
154   struct cgraph_rtl_info rtl;
155
156   /* Expected number of executions: calculated in profile.c.  */
157   gcov_type count;
158   /* Unique id of the node.  */
159   int uid;
160   /* Ordering of all cgraph nodes.  */
161   int order;
162
163   /* Set when function must be output - it is externally visible
164      or its address is taken.  */
165   unsigned needed : 1;
166   /* Set when function is reachable by call from other function
167      that is either reachable or needed.  */
168   unsigned reachable : 1;
169   /* Set once the function is lowered (i.e. its CFG is built).  */
170   unsigned lowered : 1;
171   /* Set once the function has been instantiated and its callee
172      lists created.  */
173   unsigned analyzed : 1;
174   /* Set when function is scheduled to be assembled.  */
175   unsigned output : 1;
176   /* Set for aliases once they got through assemble_alias.  */
177   unsigned alias : 1;
178
179   /* In non-unit-at-a-time mode the function body of inline candidates is saved
180      into clone before compiling so the function in original form can be
181      inlined later.  This pointer points to the clone.  */
182   tree inline_decl;
183 };
184
185 struct cgraph_edge GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
186 {
187   struct cgraph_node *caller;
188   struct cgraph_node *callee;
189   struct cgraph_edge *prev_caller;
190   struct cgraph_edge *next_caller;
191   struct cgraph_edge *prev_callee;
192   struct cgraph_edge *next_callee;
193   tree call_stmt;
194   PTR GTY ((skip (""))) aux;
195   /* When NULL, inline this call.  When non-NULL, points to the explanation
196      why function was not inlined.  */
197   const char *inline_failed;
198   /* Expected number of executions: calculated in profile.c.  */
199   gcov_type count;
200   /* Depth of loop nest, 1 means no loop nest.  */
201   int loop_nest;
202 };
203
204 typedef struct cgraph_edge *cgraph_edge_p;
205
206 DEF_VEC_P(cgraph_edge_p);
207 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
208
209 /* The varpool data structure.
210    Each static variable decl has assigned varpool_node.  */
211
212 struct varpool_node GTY(())
213 {
214   tree decl;
215   /* Pointer to the next function in varpool_nodes.  */
216   struct varpool_node *next;
217   /* Pointer to the next function in varpool_nodes_queue.  */
218   struct varpool_node *next_needed;
219   /* Ordering of all cgraph nodes.  */
220   int order;
221
222   /* Set when function must be output - it is externally visible
223      or its address is taken.  */
224   unsigned needed : 1;
225   /* Needed variables might become dead by optimization.  This flag
226      forces the variable to be output even if it appears dead otherwise.  */
227   unsigned force_output : 1;
228   /* Set once the variable has been instantiated and its callee
229      lists created.  */
230   unsigned analyzed : 1;
231   /* Set once it has been finalized so we consider it to be output.  */
232   unsigned finalized : 1;
233   /* Set when variable is scheduled to be assembled.  */
234   unsigned output : 1;
235   /* Set when function is visible by other units.  */
236   unsigned externally_visible : 1;
237   /* Set for aliases once they got through assemble_alias.  */
238   unsigned alias : 1;
239 };
240
241 /* Every top level asm statement is put into a cgraph_asm_node.  */
242
243 struct cgraph_asm_node GTY(())
244 {
245   /* Next asm node.  */
246   struct cgraph_asm_node *next;
247   /* String for this asm node.  */
248   tree asm_str;
249   /* Ordering of all cgraph nodes.  */
250   int order;
251 };
252
253 extern GTY(()) struct cgraph_node *cgraph_nodes;
254 extern GTY(()) int cgraph_n_nodes;
255 extern GTY(()) int cgraph_max_uid;
256 extern bool cgraph_global_info_ready;
257 enum cgraph_state
258 {
259   /* Callgraph is being constructed.  It is safe to add new functions.  */
260   CGRAPH_STATE_CONSTRUCTION,
261   /* Callgraph is built and IPA passes are being run.  */
262   CGRAPH_STATE_IPA,
263   /* Functions are now ordered and being passed to RTL expanders.  */
264   CGRAPH_STATE_EXPANSION,
265   /* All cgraph expansion is done.  */
266   CGRAPH_STATE_FINISHED
267 };
268 extern enum cgraph_state cgraph_state;
269 extern bool cgraph_function_flags_ready;
270 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
271 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
272
273 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
274 extern GTY(()) int cgraph_order;
275
276 /* In cgraph.c  */
277 void dump_cgraph (FILE *);
278 void dump_cgraph_node (FILE *, struct cgraph_node *);
279 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
280 void cgraph_remove_edge (struct cgraph_edge *);
281 void cgraph_remove_node (struct cgraph_node *);
282 void cgraph_node_remove_callees (struct cgraph_node *node);
283 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
284                                         struct cgraph_node *,
285                                         tree, gcov_type, int);
286 struct cgraph_node *cgraph_node (tree);
287 struct cgraph_node *cgraph_node_for_asm (tree asmname);
288 struct cgraph_edge *cgraph_edge (struct cgraph_node *, tree);
289 void cgraph_set_call_stmt (struct cgraph_edge *, tree);
290 struct cgraph_local_info *cgraph_local_info (tree);
291 struct cgraph_global_info *cgraph_global_info (tree);
292 struct cgraph_rtl_info *cgraph_rtl_info (tree);
293 const char * cgraph_node_name (struct cgraph_node *);
294 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
295                                         struct cgraph_node *,
296                                         tree, gcov_type, int, bool);
297 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type,
298                                         int, bool);
299
300 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
301
302 struct cgraph_asm_node *cgraph_add_asm_node (tree);
303
304 bool cgraph_function_possibly_inlined_p (tree);
305 void cgraph_unnest_node (struct cgraph_node *);
306
307 enum availability cgraph_function_body_availability (struct cgraph_node *);
308 bool cgraph_is_master_clone (struct cgraph_node *);
309 struct cgraph_node *cgraph_master_clone (struct cgraph_node *);
310 void cgraph_add_new_function (tree, bool);
311
312 /* In cgraphunit.c  */
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 void record_references_in_initializer (tree);
331 bool cgraph_process_new_functions (void);
332
333 /* In ipa.c  */
334 bool cgraph_remove_unreachable_nodes (bool, FILE *);
335 int cgraph_postorder (struct cgraph_node **);
336
337 /* In varpool.c  */
338
339 extern GTY(()) struct varpool_node *varpool_nodes_queue;
340 extern GTY(()) struct varpool_node *varpool_nodes;
341
342 struct varpool_node *varpool_node (tree);
343 struct varpool_node *varpool_node_for_asm (tree asmname);
344 void varpool_mark_needed_node (struct varpool_node *);
345 void dump_varpool (FILE *);
346 void dump_varpool_node (FILE *, struct varpool_node *);
347
348 void varpool_finalize_decl (tree);
349 bool decide_is_variable_needed (struct varpool_node *, tree);
350 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
351
352 bool varpool_assemble_pending_decls (void);
353 bool varpool_assemble_decl (struct varpool_node *node);
354 bool varpool_analyze_pending_decls (void);
355 void varpool_output_debug_info (void);
356 void varpool_remove_unreferenced_decls (void);
357
358 /* Walk all reachable static variables.  */
359 #define FOR_EACH_STATIC_VARIABLE(node) \
360    for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
361
362 /* Return first reachable static variable with initializer.  */
363 static inline struct varpool_node *
364 varpool_first_static_initializer (void)
365 {
366   struct varpool_node *node;
367   for (node = varpool_nodes_queue; node; node = node->next_needed)
368     {
369       gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
370       if (DECL_INITIAL (node->decl))
371         return node;
372     }
373   return NULL;
374 }
375
376 /* Return next reachable static variable with initializer after NODE.  */
377 static inline struct varpool_node *
378 varpool_next_static_initializer (struct varpool_node *node)
379 {
380   for (node = node->next_needed; node; node = node->next_needed)
381     {
382       gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
383       if (DECL_INITIAL (node->decl))
384         return node;
385     }
386   return NULL;
387 }
388
389 /* Walk all static variables with initializer set.  */
390 #define FOR_EACH_STATIC_INITIALIZER(node) \
391    for ((node) = varpool_first_static_initializer (); (node); \
392         (node) = varpool_next_static_initializer (node))
393
394 /* In ipa-inline.c  */
395 bool cgraph_decide_inlining_incrementally (struct cgraph_node *, bool);
396 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
397 void cgraph_mark_inline_edge (struct cgraph_edge *, bool);
398 bool cgraph_default_inline_p (struct cgraph_node *, const char **);
399 #endif  /* GCC_CGRAPH_H  */