OSDN Git Service

PR tree-optimization/16632
[pf3gnuchains/gcc-fork.git] / gcc / cgraph.h
1 /* Callgraph handling code.
2    Copyright (C) 2003, 2004 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, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 #ifndef GCC_CGRAPH_H
23 #define GCC_CGRAPH_H
24 #include "hashtab.h"
25 #include "bitmap.h"
26 #include "tree.h"
27
28 /* Information about the function collected locally.
29    Available after function is analyzed.  */
30
31 struct cgraph_local_info GTY(())
32 {
33   /* Size of the function before inlining.  */
34   int self_insns;
35
36   /* Set when function function is visible in current compilation unit only
37      and it's address is never taken.  */
38   bool local;
39
40   /* Set when function is defined in another compilation unit.  */
41   bool external;
42
43   /* Set when this function calls a function external of the
44      compilation unit.  In general, such calls are modeled as reading
45      and writing all variables (both bits on) but sometime there are
46      attributes on the called function so we can do better.  */
47   bool calls_read_all;
48   bool calls_write_all;
49
50   /* Set once it has been finalized so we consider it to be output.  */
51   bool finalized;
52
53   /* False when there something makes inlining impossible (such as va_arg).  */
54   bool inlinable;
55
56   /* True when function should be inlined independently on it's size.  */
57   bool disregard_inline_limits;
58
59   /* True when the function has been originally extern inline, but it is
60      redefined now.  */
61   bool redefined_extern_inline;
62
63   /* True if statics_read_for_function and
64      statics_written_for_function contain valid data.  */
65   bool for_functions_valid;
66 };
67
68 /* Information about the function that needs to be computed globally
69    once compilation is finished.  Available only with -funit-at-time.  */
70
71 struct cgraph_global_info GTY(())
72 {
73   /* For inline clones this points to the function they will be inlined into.  */
74   struct cgraph_node *inlined_to;
75
76   /* Estimated size of the function after inlining.  */
77   int insns;
78
79   /* Set iff the function has been inlined at least once.  */
80   bool inlined;
81 };
82
83 /* Information about the function that is propagated by the RTL backend.
84    Available only for functions that has been already assembled.  */
85
86 struct cgraph_rtl_info GTY(())
87 {
88    int preferred_incoming_stack_boundary;
89    bool const_function;
90    bool pure_function;
91 };
92
93 /* FIXME -- PROFILE-RESTRUCTURE: When the next round of the profiling
94    code gets merged in, it will contain a restructing where ssa form
95    is built for every function within the compilation unit before the
96    rest of the compilation continues.  When this reorgination is done,
97    it will no longer be necessary to have the _decl_uid versions of
98    local_static_vars_info and global_static_vars_info structures.
99    Having both structures is now required because the _ann_uid values
100    for static variables are reset as each function is compiled.
101    Currently, the analysis is done using the _decl_uid versions and
102    converted to the _var_ann versions on demand.
103
104    Also, the var_anns_valid fields within these structures can also go
105    away.
106 */
107
108 /* The static variables defined within the compilation unit that are
109    loaded or stored directly by function that owns this structure.  */ 
110
111 struct local_static_vars_info_d GTY(())
112 {
113   bitmap statics_read_by_decl_uid;
114   bitmap statics_written_by_decl_uid;
115 };
116
117 struct global_static_vars_info_d GTY(())
118 {
119   bitmap statics_read_by_decl_uid;
120   bitmap statics_written_by_decl_uid;
121   bitmap statics_read_by_ann_uid;
122   bitmap statics_written_by_ann_uid;
123   bitmap statics_not_read_by_decl_uid;
124   bitmap statics_not_written_by_decl_uid;
125   bitmap statics_not_read_by_ann_uid;
126   bitmap statics_not_written_by_ann_uid;
127
128   /* var_anns_valid is reset at the start of compilation for each
129      function because the indexing that the "_var_anns" is based
130      on is invalidated between function compilations.  This allows for
131      lazy creation of the "_var_ann" variables.  */
132   bool var_anns_valid;
133 };
134
135 /* Statics that are read and written by some set of functions. The
136    local ones are based on the loads and stores local to the function.
137    The global ones are based on the local info as well as the
138    transitive closure of the functions that are called.  The
139    structures are separated to allow the global structures to be
140    shared between several functions since every function within a
141    strongly connected component will have the same information.  This
142    sharing saves both time and space in the computation of the vectors
143    as well as their translation from decl_uid form to ann_uid
144    form.  */ 
145
146 typedef struct local_static_vars_info_d *local_static_vars_info_t;
147 typedef struct global_static_vars_info_d *global_static_vars_info_t;
148
149 struct static_vars_info_d GTY(()) 
150 {
151   local_static_vars_info_t local;
152   global_static_vars_info_t global;
153 };
154
155 typedef struct static_vars_info_d *static_vars_info_t;
156
157 /* The cgraph data structure.
158    Each function decl has assigned cgraph_node listing callees and callers.  */
159
160 struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
161 {
162   tree decl;
163   struct cgraph_edge *callees;
164   struct cgraph_edge *callers;
165   struct cgraph_node *next;
166   struct cgraph_node *previous;
167   /* For nested functions points to function the node is nested in.  */
168   struct cgraph_node *origin;
169   /* Points to first nested function, if any.  */
170   struct cgraph_node *nested;
171   /* Pointer to the next function with same origin, if any.  */
172   struct cgraph_node *next_nested;
173   /* Pointer to the next function in cgraph_nodes_queue.  */
174   struct cgraph_node *next_needed;
175   /* Pointer to the next clone.  */
176   struct cgraph_node *next_clone;
177   /* Pointer to next node in a recursive call graph cycle; */
178   struct cgraph_node *next_cycle;
179   PTR GTY ((skip)) aux;
180
181   struct cgraph_local_info local;
182   struct cgraph_global_info global;
183   struct cgraph_rtl_info rtl;
184   
185   /* Pointer to the structure that contains the sets of global
186      variables modified by function calls.  */
187   static_vars_info_t static_vars_info;
188
189   /* Unique id of the node.  */
190   int uid;
191   /* Set when function must be output - it is externally visible
192      or it's address is taken.  */
193   bool needed;
194   /* Set when function is reachable by call from other function
195      that is either reachable or needed.  */
196   bool reachable;
197   /* Set once the function has been instantiated and its callee
198      lists created.  */
199   bool analyzed;
200   /* Set when function is scheduled to be assembled.  */
201   bool output;
202 };
203
204 struct cgraph_edge GTY((chain_next ("%h.next_caller")))
205 {
206   struct cgraph_node *caller;
207   struct cgraph_node *callee;
208   struct cgraph_edge *next_caller;
209   struct cgraph_edge *next_callee;
210   tree call_expr;
211   PTR GTY ((skip (""))) aux;
212   /* When NULL, inline this call.  When non-NULL, points to the explanation
213      why function was not inlined.  */
214   const char *inline_failed;
215 };
216
217 /* The cgraph_varpool data structure.
218    Each static variable decl has assigned cgraph_varpool_node.  */
219
220 struct cgraph_varpool_node GTY(())
221 {
222   tree decl;
223   /* Pointer to the next function in cgraph_varpool_nodes_queue.  */
224   struct cgraph_varpool_node *next_needed;
225
226   /* Set when function must be output - it is externally visible
227      or it's address is taken.  */
228   bool needed;
229   /* Set once it has been finalized so we consider it to be output.  */
230   bool finalized;
231   /* Set when function is scheduled to be assembled.  */
232   bool output;
233 };
234
235 extern GTY(()) struct cgraph_node *cgraph_nodes;
236 extern GTY(()) int cgraph_n_nodes;
237 extern GTY(()) int cgraph_max_uid;
238 extern bool cgraph_global_info_ready;
239 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
240
241 extern GTY(()) int cgraph_varpool_n_nodes;
242 extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_nodes_queue;
243
244 /* In cgraph.c  */
245 void dump_cgraph (FILE *);
246 void dump_cgraph_node (FILE *, struct cgraph_node *);
247 void cgraph_remove_edge (struct cgraph_edge *);
248 void cgraph_remove_node (struct cgraph_node *);
249 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
250                                         struct cgraph_node *,
251                                         tree);
252 struct cgraph_node *cgraph_node (tree decl);
253 struct cgraph_edge *cgraph_edge (struct cgraph_node *, tree call_expr);
254 bool cgraph_calls_p (tree, tree);
255 struct cgraph_local_info *cgraph_local_info (tree);
256 struct cgraph_global_info *cgraph_global_info (tree);
257 struct cgraph_rtl_info *cgraph_rtl_info (tree);
258 const char * cgraph_node_name (struct cgraph_node *);
259 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *, struct cgraph_node *, tree);
260 struct cgraph_node * cgraph_clone_node (struct cgraph_node *);
261
262 struct cgraph_varpool_node *cgraph_varpool_node (tree decl);
263 void cgraph_varpool_mark_needed_node (struct cgraph_varpool_node *);
264 void cgraph_varpool_finalize_decl (tree);
265 bool cgraph_varpool_assemble_pending_decls (void);
266 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
267
268 bool cgraph_function_possibly_inlined_p (tree);
269 void cgraph_unnest_node (struct cgraph_node *node);
270
271 /* In cgraphunit.c  */
272 bool cgraph_assemble_pending_functions (void);
273 void cgraph_finalize_function (tree, bool);
274 void cgraph_finalize_compilation_unit (void);
275 void cgraph_create_edges (struct cgraph_node *, tree);
276 void cgraph_optimize (void);
277 void cgraph_mark_needed_node (struct cgraph_node *);
278 void cgraph_mark_reachable_node (struct cgraph_node *);
279 bool cgraph_inline_p (struct cgraph_edge *, const char **reason);
280 bool cgraph_preserve_function_body_p (tree);
281 void verify_cgraph (void);
282 void verify_cgraph_node (struct cgraph_node *);
283 void cgraph_mark_inline_edge (struct cgraph_edge *e);
284 void cgraph_clone_inlined_nodes (struct cgraph_edge *e, bool duplicate);
285 void cgraph_build_static_cdtor (char which, tree body, int priority);
286 void cgraph_reset_static_var_maps (void);
287 bitmap get_global_statics_not_read (tree fn);
288 bitmap get_global_statics_not_written(tree fn);
289 void init_cgraph (void);
290
291 #endif  /* GCC_CGRAPH_H  */