OSDN Git Service

gcc/ada/
[pf3gnuchains/gcc-fork.git] / gcc / cgraph.h
1 /* Callgraph handling code.
2    Copyright (C) 2003, 2004, 2005, 2006, 2007 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 3, 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 COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #ifndef GCC_CGRAPH_H
22 #define GCC_CGRAPH_H
23 #include "tree.h"
24 #include "basic-block.h"
25
26 enum availability
27 {
28   /* Not yet set by cgraph_function_body_availability.  */
29   AVAIL_UNSET,
30   /* Function body/variable initializer is unknown.  */
31   AVAIL_NOT_AVAILABLE,
32   /* Function body/variable initializer is known but might be replaced
33      by a different one from other compilation unit and thus needs to
34      be dealt with a care.  Like AVAIL_NOT_AVAILABLE it can have
35      arbitrary side effects on escaping variables and functions, while
36      like AVAILABLE it might access static variables.  */
37   AVAIL_OVERWRITABLE,
38   /* Function body/variable initializer is known and will be used in final
39      program.  */
40   AVAIL_AVAILABLE,
41   /* Function body/variable initializer is known and all it's uses are explicitly
42      visible within current unit (ie it's address is never taken and it is not
43      exported to other units).
44      Currently used only for functions.  */
45   AVAIL_LOCAL
46 };
47
48 extern const char * const cgraph_availability_names[];
49
50 /* Information about the function collected locally.
51    Available after function is analyzed.  */
52
53 struct cgraph_local_info GTY(())
54 {
55   /* Estimated stack frame consumption by the function.  */
56   HOST_WIDE_INT estimated_self_stack_size;
57
58   /* Size of the function before inlining.  */
59   int self_insns;
60
61   /* Set when function function is visible in current compilation unit only
62      and its address is never taken.  */
63   unsigned local : 1;
64
65   /* Set when function is visible by other units.  */
66   unsigned externally_visible : 1;
67
68   /* Set once it has been finalized so we consider it to be output.  */
69   unsigned finalized : 1;
70
71   /* False when there something makes inlining impossible (such as va_arg).  */
72   unsigned inlinable : 1;
73
74   /* True when function should be inlined independently on its size.  */
75   unsigned disregard_inline_limits : 1;
76
77   /* True when the function has been originally extern inline, but it is
78      redefined now.  */
79   unsigned redefined_extern_inline : 1;
80
81   /* True if statics_read_for_function and
82      statics_written_for_function contain valid data.  */
83   unsigned for_functions_valid : 1;
84
85   /* True if the function is going to be emitted in some other translation
86      unit, referenced from vtable.  */
87   unsigned vtable_method : 1;
88 };
89
90 /* Information about the function that needs to be computed globally
91    once compilation is finished.  Available only with -funit-at-time.  */
92
93 struct cgraph_global_info GTY(())
94 {
95   /* Estimated stack frame consumption by the function.  */
96   HOST_WIDE_INT estimated_stack_size;
97   /* Expected offset of the stack frame of inlined function.  */
98   HOST_WIDE_INT stack_frame_offset;
99
100   /* For inline clones this points to the function they will be inlined into.  */
101   struct cgraph_node *inlined_to;
102
103   /* Estimated size of the function after inlining.  */
104   int insns;
105
106   /* Estimated growth after inlining.  INT_MIN if not computed.  */
107   int estimated_growth;
108
109   /* Set iff the function has been inlined at least once.  */
110   bool inlined;
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 cgraph_rtl_info GTY(())
117 {
118    int preferred_incoming_stack_boundary;
119 };
120
121 /* The cgraph data structure.
122    Each function decl has assigned cgraph_node listing callees and callers.  */
123
124 struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
125 {
126   tree decl;
127   struct cgraph_edge *callees;
128   struct cgraph_edge *callers;
129   struct cgraph_node *next;
130   struct cgraph_node *previous;
131   /* For nested functions points to function the node is nested in.  */
132   struct cgraph_node *origin;
133   /* Points to first nested function, if any.  */
134   struct cgraph_node *nested;
135   /* Pointer to the next function with same origin, if any.  */
136   struct cgraph_node *next_nested;
137   /* Pointer to the next function in cgraph_nodes_queue.  */
138   struct cgraph_node *next_needed;
139   /* Pointer to the next clone.  */
140   struct cgraph_node *next_clone;
141   struct cgraph_node *prev_clone;
142   /* Pointer to a single unique cgraph node for this function.  If the
143      function is to be output, this is the copy that will survive.  */
144   struct cgraph_node *master_clone;
145   /* For functions with many calls sites it holds map from call expression
146      to the edge to speed up cgraph_edge function.  */
147   htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
148
149   PTR GTY ((skip)) aux;
150
151   struct cgraph_local_info local;
152   struct cgraph_global_info global;
153   struct cgraph_rtl_info rtl;
154
155   /* Expected number of executions: calculated in profile.c.  */
156   gcov_type count;
157   /* Unique id of the node.  */
158   int uid;
159   /* Ordering of all cgraph nodes.  */
160   int order;
161
162   /* Set when function must be output - it is externally visible
163      or its address is taken.  */
164   unsigned needed : 1;
165   /* Set when function is reachable by call from other function
166      that is either reachable or needed.  */
167   unsigned reachable : 1;
168   /* Set once the function is lowered (i.e. its CFG is built).  */
169   unsigned lowered : 1;
170   /* Set once the function has been instantiated and its callee
171      lists created.  */
172   unsigned analyzed : 1;
173   /* Set when function is scheduled to be assembled.  */
174   unsigned output : 1;
175   /* Set for aliases once they got through assemble_alias.  */
176   unsigned alias : 1;
177
178   /* In non-unit-at-a-time mode the function body of inline candidates is saved
179      into clone before compiling so the function in original form can be
180      inlined later.  This pointer points to the clone.  */
181   tree inline_decl;
182
183   /* unique id for profiling. pid is not suitable because of different
184      number of cfg nodes with -fprofile-generate and -fprofile-use */
185   int pid;
186 };
187
188 struct cgraph_edge GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
189 {
190   struct cgraph_node *caller;
191   struct cgraph_node *callee;
192   struct cgraph_edge *prev_caller;
193   struct cgraph_edge *next_caller;
194   struct cgraph_edge *prev_callee;
195   struct cgraph_edge *next_callee;
196   tree call_stmt;
197   PTR GTY ((skip (""))) aux;
198   /* When NULL, inline this call.  When non-NULL, points to the explanation
199      why function was not inlined.  */
200   const char *inline_failed;
201   /* Expected number of executions: calculated in profile.c.  */
202   gcov_type count;
203   /* Expected frequency of executions within the function. 
204      When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
205      per function call.  The range is 0 to CGRAPH_FREQ_MAX.  */
206   int frequency;
207   /* Depth of loop nest, 1 means no loop nest.  */
208   int loop_nest;
209 };
210
211 #define CGRAPH_FREQ_BASE 1000
212 #define CGRAPH_FREQ_MAX 100000
213
214 typedef struct cgraph_edge *cgraph_edge_p;
215
216 DEF_VEC_P(cgraph_edge_p);
217 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
218
219 /* The varpool data structure.
220    Each static variable decl has assigned varpool_node.  */
221
222 struct varpool_node GTY(())
223 {
224   tree decl;
225   /* Pointer to the next function in varpool_nodes.  */
226   struct varpool_node *next;
227   /* Pointer to the next function in varpool_nodes_queue.  */
228   struct varpool_node *next_needed;
229   /* Ordering of all cgraph nodes.  */
230   int order;
231
232   /* Set when function must be output - it is externally visible
233      or its address is taken.  */
234   unsigned needed : 1;
235   /* Needed variables might become dead by optimization.  This flag
236      forces the variable to be output even if it appears dead otherwise.  */
237   unsigned force_output : 1;
238   /* Set once the variable has been instantiated and its callee
239      lists created.  */
240   unsigned analyzed : 1;
241   /* Set once it has been finalized so we consider it to be output.  */
242   unsigned finalized : 1;
243   /* Set when variable is scheduled to be assembled.  */
244   unsigned output : 1;
245   /* Set when function is visible by other units.  */
246   unsigned externally_visible : 1;
247   /* Set for aliases once they got through assemble_alias.  */
248   unsigned alias : 1;
249 };
250
251 /* Every top level asm statement is put into a cgraph_asm_node.  */
252
253 struct cgraph_asm_node GTY(())
254 {
255   /* Next asm node.  */
256   struct cgraph_asm_node *next;
257   /* String for this asm node.  */
258   tree asm_str;
259   /* Ordering of all cgraph nodes.  */
260   int order;
261 };
262
263 extern GTY(()) struct cgraph_node *cgraph_nodes;
264 extern GTY(()) int cgraph_n_nodes;
265 extern GTY(()) int cgraph_max_uid;
266 extern GTY(()) int cgraph_max_pid;
267 extern bool cgraph_global_info_ready;
268 enum cgraph_state
269 {
270   /* Callgraph is being constructed.  It is safe to add new functions.  */
271   CGRAPH_STATE_CONSTRUCTION,
272   /* Callgraph is built and IPA passes are being run.  */
273   CGRAPH_STATE_IPA,
274   /* Callgraph is built and all functions are transformed to SSA form.  */
275   CGRAPH_STATE_IPA_SSA,
276   /* Functions are now ordered and being passed to RTL expanders.  */
277   CGRAPH_STATE_EXPANSION,
278   /* All cgraph expansion is done.  */
279   CGRAPH_STATE_FINISHED
280 };
281 extern enum cgraph_state cgraph_state;
282 extern bool cgraph_function_flags_ready;
283 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
284 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
285
286 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
287 extern GTY(()) int cgraph_order;
288
289 /* In cgraph.c  */
290 void dump_cgraph (FILE *);
291 void debug_cgraph (void);
292 void dump_cgraph_node (FILE *, struct cgraph_node *);
293 void debug_cgraph_node (struct cgraph_node *);
294 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
295 void cgraph_remove_edge (struct cgraph_edge *);
296 void cgraph_remove_node (struct cgraph_node *);
297 void cgraph_release_function_body (struct cgraph_node *);
298 void cgraph_node_remove_callees (struct cgraph_node *node);
299 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
300                                         struct cgraph_node *,
301                                         tree, gcov_type, int, int);
302 struct cgraph_node *cgraph_node (tree);
303 struct cgraph_node *cgraph_node_for_asm (tree asmname);
304 struct cgraph_edge *cgraph_edge (struct cgraph_node *, tree);
305 void cgraph_set_call_stmt (struct cgraph_edge *, tree);
306 struct cgraph_local_info *cgraph_local_info (tree);
307 struct cgraph_global_info *cgraph_global_info (tree);
308 struct cgraph_rtl_info *cgraph_rtl_info (tree);
309 const char * cgraph_node_name (struct cgraph_node *);
310 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
311                                         struct cgraph_node *,
312                                         tree, gcov_type, int, int, bool);
313 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, int,
314                                         int, bool);
315
316 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
317
318 struct cgraph_asm_node *cgraph_add_asm_node (tree);
319
320 bool cgraph_function_possibly_inlined_p (tree);
321 void cgraph_unnest_node (struct cgraph_node *);
322
323 enum availability cgraph_function_body_availability (struct cgraph_node *);
324 bool cgraph_is_master_clone (struct cgraph_node *);
325 struct cgraph_node *cgraph_master_clone (struct cgraph_node *);
326 void cgraph_add_new_function (tree, bool);
327
328 /* In cgraphunit.c  */
329 void cgraph_finalize_function (tree, bool);
330 void cgraph_finalize_compilation_unit (void);
331 void cgraph_optimize (void);
332 void cgraph_mark_needed_node (struct cgraph_node *);
333 void cgraph_mark_reachable_node (struct cgraph_node *);
334 bool cgraph_inline_p (struct cgraph_edge *, const char **reason);
335 bool cgraph_preserve_function_body_p (tree);
336 void verify_cgraph (void);
337 void verify_cgraph_node (struct cgraph_node *);
338 void cgraph_build_static_cdtor (char which, tree body, int priority);
339 void cgraph_reset_static_var_maps (void);
340 void init_cgraph (void);
341 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
342                                                 VEC(cgraph_edge_p,heap)*,
343                                                 varray_type);
344 void cgraph_analyze_function (struct cgraph_node *);
345 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
346 void record_references_in_initializer (tree);
347 bool cgraph_process_new_functions (void);
348
349 /* In cgraphbuild.c  */
350 unsigned int rebuild_cgraph_edges (void);
351
352 /* In ipa.c  */
353 bool cgraph_remove_unreachable_nodes (bool, FILE *);
354 int cgraph_postorder (struct cgraph_node **);
355
356 /* In varpool.c  */
357
358 extern GTY(()) struct varpool_node *varpool_nodes_queue;
359 extern GTY(()) struct varpool_node *varpool_nodes;
360
361 struct varpool_node *varpool_node (tree);
362 struct varpool_node *varpool_node_for_asm (tree asmname);
363 void varpool_mark_needed_node (struct varpool_node *);
364 void dump_varpool (FILE *);
365 void dump_varpool_node (FILE *, struct varpool_node *);
366
367 void varpool_finalize_decl (tree);
368 bool decide_is_variable_needed (struct varpool_node *, tree);
369 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
370
371 bool varpool_assemble_pending_decls (void);
372 bool varpool_assemble_decl (struct varpool_node *node);
373 bool varpool_analyze_pending_decls (void);
374 void varpool_output_debug_info (void);
375 void varpool_remove_unreferenced_decls (void);
376
377 /* Walk all reachable static variables.  */
378 #define FOR_EACH_STATIC_VARIABLE(node) \
379    for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
380
381 /* Return first reachable static variable with initializer.  */
382 static inline struct varpool_node *
383 varpool_first_static_initializer (void)
384 {
385   struct varpool_node *node;
386   for (node = varpool_nodes_queue; node; node = node->next_needed)
387     {
388       gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
389       if (DECL_INITIAL (node->decl))
390         return node;
391     }
392   return NULL;
393 }
394
395 /* Return next reachable static variable with initializer after NODE.  */
396 static inline struct varpool_node *
397 varpool_next_static_initializer (struct varpool_node *node)
398 {
399   for (node = node->next_needed; node; node = node->next_needed)
400     {
401       gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
402       if (DECL_INITIAL (node->decl))
403         return node;
404     }
405   return NULL;
406 }
407
408 /* Walk all static variables with initializer set.  */
409 #define FOR_EACH_STATIC_INITIALIZER(node) \
410    for ((node) = varpool_first_static_initializer (); (node); \
411         (node) = varpool_next_static_initializer (node))
412
413 /* In ipa-inline.c  */
414 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
415 void cgraph_mark_inline_edge (struct cgraph_edge *, bool);
416 bool cgraph_default_inline_p (struct cgraph_node *, const char **);
417
418
419 /* Create a new static variable of type TYPE.  */
420 tree add_new_static_var (tree type);
421
422 #endif  /* GCC_CGRAPH_H  */