PR c++/35116
[official-gcc.git] / gcc / cgraph.h
blob89ffeb6c45c0baf423914732cab8ae82af9b7036
1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
6 This file is part of GCC.
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.
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.
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/>. */
22 #ifndef GCC_CGRAPH_H
23 #define GCC_CGRAPH_H
24 #include "tree.h"
25 #include "basic-block.h"
27 enum availability
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
49 extern const char * const cgraph_availability_names[];
51 /* Information about the function collected locally.
52 Available after function is analyzed. */
54 struct cgraph_local_info GTY(())
56 /* Estimated stack frame consumption by the function. */
57 HOST_WIDE_INT estimated_self_stack_size;
59 /* Size of the function before inlining. */
60 int self_insns;
62 /* Set when function function is visible in current compilation unit only
63 and its address is never taken. */
64 unsigned local : 1;
66 /* Set when function is visible by other units. */
67 unsigned externally_visible : 1;
69 /* Set once it has been finalized so we consider it to be output. */
70 unsigned finalized : 1;
72 /* False when there something makes inlining impossible (such as va_arg). */
73 unsigned inlinable : 1;
75 /* True when function should be inlined independently on its size. */
76 unsigned disregard_inline_limits : 1;
78 /* True when the function has been originally extern inline, but it is
79 redefined now. */
80 unsigned redefined_extern_inline : 1;
82 /* True if statics_read_for_function and
83 statics_written_for_function contain valid data. */
84 unsigned for_functions_valid : 1;
86 /* True if the function is going to be emitted in some other translation
87 unit, referenced from vtable. */
88 unsigned vtable_method : 1;
91 /* Information about the function that needs to be computed globally
92 once compilation is finished. Available only with -funit-at-time. */
94 struct cgraph_global_info GTY(())
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;
101 /* For inline clones this points to the function they will be inlined into. */
102 struct cgraph_node *inlined_to;
104 /* Estimated size of the function after inlining. */
105 int insns;
107 /* Estimated growth after inlining. INT_MIN if not computed. */
108 int estimated_growth;
110 /* Set iff the function has been inlined at least once. */
111 bool inlined;
114 /* Information about the function that is propagated by the RTL backend.
115 Available only for functions that has been already assembled. */
117 struct cgraph_rtl_info GTY(())
119 int preferred_incoming_stack_boundary;
122 /* The cgraph data structure.
123 Each function decl has assigned cgraph_node listing callees and callers. */
125 struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
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;
150 PTR GTY ((skip)) aux;
152 struct cgraph_local_info local;
153 struct cgraph_global_info global;
154 struct cgraph_rtl_info rtl;
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;
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;
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;
184 /* unique id for profiling. pid is not suitable because of different
185 number of cfg nodes with -fprofile-generate and -fprofile-use */
186 int pid;
189 struct cgraph_edge GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
191 struct cgraph_node *caller;
192 struct cgraph_node *callee;
193 struct cgraph_edge *prev_caller;
194 struct cgraph_edge *next_caller;
195 struct cgraph_edge *prev_callee;
196 struct cgraph_edge *next_callee;
197 tree call_stmt;
198 PTR GTY ((skip (""))) aux;
199 /* When NULL, inline this call. When non-NULL, points to the explanation
200 why function was not inlined. */
201 const char *inline_failed;
202 /* Expected number of executions: calculated in profile.c. */
203 gcov_type count;
204 /* Expected frequency of executions within the function.
205 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
206 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
207 int frequency;
208 /* Depth of loop nest, 1 means no loop nest. */
209 int loop_nest;
212 #define CGRAPH_FREQ_BASE 1000
213 #define CGRAPH_FREQ_MAX 100000
215 typedef struct cgraph_edge *cgraph_edge_p;
217 DEF_VEC_P(cgraph_edge_p);
218 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
220 /* The varpool data structure.
221 Each static variable decl has assigned varpool_node. */
223 struct varpool_node GTY(())
225 tree decl;
226 /* Pointer to the next function in varpool_nodes. */
227 struct varpool_node *next;
228 /* Pointer to the next function in varpool_nodes_queue. */
229 struct varpool_node *next_needed;
230 /* Ordering of all cgraph nodes. */
231 int order;
233 /* Set when function must be output - it is externally visible
234 or its address is taken. */
235 unsigned needed : 1;
236 /* Needed variables might become dead by optimization. This flag
237 forces the variable to be output even if it appears dead otherwise. */
238 unsigned force_output : 1;
239 /* Set once the variable has been instantiated and its callee
240 lists created. */
241 unsigned analyzed : 1;
242 /* Set once it has been finalized so we consider it to be output. */
243 unsigned finalized : 1;
244 /* Set when variable is scheduled to be assembled. */
245 unsigned output : 1;
246 /* Set when function is visible by other units. */
247 unsigned externally_visible : 1;
248 /* Set for aliases once they got through assemble_alias. */
249 unsigned alias : 1;
252 /* Every top level asm statement is put into a cgraph_asm_node. */
254 struct cgraph_asm_node GTY(())
256 /* Next asm node. */
257 struct cgraph_asm_node *next;
258 /* String for this asm node. */
259 tree asm_str;
260 /* Ordering of all cgraph nodes. */
261 int order;
264 extern GTY(()) struct cgraph_node *cgraph_nodes;
265 extern GTY(()) int cgraph_n_nodes;
266 extern GTY(()) int cgraph_max_uid;
267 extern GTY(()) int cgraph_max_pid;
268 extern bool cgraph_global_info_ready;
269 enum cgraph_state
271 /* Callgraph is being constructed. It is safe to add new functions. */
272 CGRAPH_STATE_CONSTRUCTION,
273 /* Callgraph is built and IPA passes are being run. */
274 CGRAPH_STATE_IPA,
275 /* Callgraph is built and all functions are transformed to SSA form. */
276 CGRAPH_STATE_IPA_SSA,
277 /* Functions are now ordered and being passed to RTL expanders. */
278 CGRAPH_STATE_EXPANSION,
279 /* All cgraph expansion is done. */
280 CGRAPH_STATE_FINISHED
282 extern enum cgraph_state cgraph_state;
283 extern bool cgraph_function_flags_ready;
284 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
285 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
287 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
288 extern GTY(()) int cgraph_order;
290 /* In cgraph.c */
291 void dump_cgraph (FILE *);
292 void debug_cgraph (void);
293 void dump_cgraph_node (FILE *, struct cgraph_node *);
294 void debug_cgraph_node (struct cgraph_node *);
295 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
296 void cgraph_remove_edge (struct cgraph_edge *);
297 void cgraph_remove_node (struct cgraph_node *);
298 void cgraph_release_function_body (struct cgraph_node *);
299 void cgraph_node_remove_callees (struct cgraph_node *node);
300 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
301 struct cgraph_node *,
302 tree, gcov_type, int, int);
303 struct cgraph_node *cgraph_node (tree);
304 struct cgraph_node *cgraph_node_for_asm (tree asmname);
305 struct cgraph_edge *cgraph_edge (struct cgraph_node *, tree);
306 void cgraph_set_call_stmt (struct cgraph_edge *, tree);
307 void cgraph_update_edges_for_call_stmt (tree, tree, tree);
308 struct cgraph_local_info *cgraph_local_info (tree);
309 struct cgraph_global_info *cgraph_global_info (tree);
310 struct cgraph_rtl_info *cgraph_rtl_info (tree);
311 const char * cgraph_node_name (struct cgraph_node *);
312 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
313 struct cgraph_node *,
314 tree, gcov_type, int, int, bool);
315 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, int,
316 int, bool);
318 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
320 struct cgraph_asm_node *cgraph_add_asm_node (tree);
322 bool cgraph_function_possibly_inlined_p (tree);
323 void cgraph_unnest_node (struct cgraph_node *);
325 enum availability cgraph_function_body_availability (struct cgraph_node *);
326 bool cgraph_is_master_clone (struct cgraph_node *);
327 struct cgraph_node *cgraph_master_clone (struct cgraph_node *);
328 void cgraph_add_new_function (tree, bool);
330 /* In cgraphunit.c */
331 void cgraph_finalize_function (tree, bool);
332 void cgraph_finalize_compilation_unit (void);
333 void cgraph_optimize (void);
334 void cgraph_mark_needed_node (struct cgraph_node *);
335 void cgraph_mark_reachable_node (struct cgraph_node *);
336 bool cgraph_inline_p (struct cgraph_edge *, const char **reason);
337 bool cgraph_preserve_function_body_p (tree);
338 void verify_cgraph (void);
339 void verify_cgraph_node (struct cgraph_node *);
340 void cgraph_build_static_cdtor (char which, tree body, int priority);
341 void cgraph_reset_static_var_maps (void);
342 void init_cgraph (void);
343 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
344 VEC(cgraph_edge_p,heap)*,
345 varray_type);
346 void cgraph_analyze_function (struct cgraph_node *);
347 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
348 void record_references_in_initializer (tree);
349 bool cgraph_process_new_functions (void);
351 /* In cgraphbuild.c */
352 unsigned int rebuild_cgraph_edges (void);
354 /* In ipa.c */
355 bool cgraph_remove_unreachable_nodes (bool, FILE *);
356 int cgraph_postorder (struct cgraph_node **);
358 /* In varpool.c */
360 extern GTY(()) struct varpool_node *varpool_nodes_queue;
361 extern GTY(()) struct varpool_node *varpool_nodes;
363 struct varpool_node *varpool_node (tree);
364 struct varpool_node *varpool_node_for_asm (tree asmname);
365 void varpool_mark_needed_node (struct varpool_node *);
366 void dump_varpool (FILE *);
367 void dump_varpool_node (FILE *, struct varpool_node *);
369 void varpool_finalize_decl (tree);
370 bool decide_is_variable_needed (struct varpool_node *, tree);
371 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
373 bool varpool_assemble_pending_decls (void);
374 bool varpool_assemble_decl (struct varpool_node *node);
375 bool varpool_analyze_pending_decls (void);
376 void varpool_output_debug_info (void);
377 void varpool_remove_unreferenced_decls (void);
379 /* Walk all reachable static variables. */
380 #define FOR_EACH_STATIC_VARIABLE(node) \
381 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
383 /* Return first reachable static variable with initializer. */
384 static inline struct varpool_node *
385 varpool_first_static_initializer (void)
387 struct varpool_node *node;
388 for (node = varpool_nodes_queue; node; node = node->next_needed)
390 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
391 if (DECL_INITIAL (node->decl))
392 return node;
394 return NULL;
397 /* Return next reachable static variable with initializer after NODE. */
398 static inline struct varpool_node *
399 varpool_next_static_initializer (struct varpool_node *node)
401 for (node = node->next_needed; node; node = node->next_needed)
403 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
404 if (DECL_INITIAL (node->decl))
405 return node;
407 return NULL;
410 /* Walk all static variables with initializer set. */
411 #define FOR_EACH_STATIC_INITIALIZER(node) \
412 for ((node) = varpool_first_static_initializer (); (node); \
413 (node) = varpool_next_static_initializer (node))
415 /* In ipa-inline.c */
416 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
417 void cgraph_mark_inline_edge (struct cgraph_edge *, bool);
418 bool cgraph_default_inline_p (struct cgraph_node *, const char **);
421 /* Create a new static variable of type TYPE. */
422 tree add_new_static_var (tree type);
424 #endif /* GCC_CGRAPH_H */