cgraph.c (cgraph_make_edge, [...]): Set nothrow flag.
[gcc.git] / gcc / cgraph.h
1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>. */
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 struct inline_summary {
57 /* Estimated stack frame consumption by the function. */
58 HOST_WIDE_INT estimated_self_stack_size;
59
60 /* Size of the function before inlining. */
61 int self_insns;
62 } inline_summary;
63
64 /* Set when function function is visible in current compilation unit only
65 and its address is never taken. */
66 unsigned local : 1;
67
68 /* Set when function is visible by other units. */
69 unsigned externally_visible : 1;
70
71 /* Set once it has been finalized so we consider it to be output. */
72 unsigned finalized : 1;
73
74 /* False when there something makes inlining impossible (such as va_arg). */
75 unsigned inlinable : 1;
76
77 /* True when function should be inlined independently on its size. */
78 unsigned disregard_inline_limits : 1;
79
80 /* True when the function has been originally extern inline, but it is
81 redefined now. */
82 unsigned redefined_extern_inline : 1;
83
84 /* True if statics_read_for_function and
85 statics_written_for_function contain valid data. */
86 unsigned for_functions_valid : 1;
87
88 /* True if the function is going to be emitted in some other translation
89 unit, referenced from vtable. */
90 unsigned vtable_method : 1;
91 };
92
93 /* Information about the function that needs to be computed globally
94 once compilation is finished. Available only with -funit-at-a-time. */
95
96 struct cgraph_global_info GTY(())
97 {
98 /* Estimated stack frame consumption by the function. */
99 HOST_WIDE_INT estimated_stack_size;
100 /* Expected offset of the stack frame of inlined function. */
101 HOST_WIDE_INT stack_frame_offset;
102
103 /* For inline clones this points to the function they will be
104 inlined into. */
105 struct cgraph_node *inlined_to;
106
107 /* Estimated size of the function after inlining. */
108 int insns;
109
110 /* Estimated growth after inlining. INT_MIN if not computed. */
111 int estimated_growth;
112
113 /* Set iff the function has been inlined at least once. */
114 bool inlined;
115 };
116
117 /* Information about the function that is propagated by the RTL backend.
118 Available only for functions that has been already assembled. */
119
120 struct cgraph_rtl_info GTY(())
121 {
122 unsigned int preferred_incoming_stack_boundary;
123 };
124
125 /* The cgraph data structure.
126 Each function decl has assigned cgraph_node listing callees and callers. */
127
128 struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
129 {
130 tree decl;
131 struct cgraph_edge *callees;
132 struct cgraph_edge *callers;
133 struct cgraph_node *next;
134 struct cgraph_node *previous;
135 /* For nested functions points to function the node is nested in. */
136 struct cgraph_node *origin;
137 /* Points to first nested function, if any. */
138 struct cgraph_node *nested;
139 /* Pointer to the next function with same origin, if any. */
140 struct cgraph_node *next_nested;
141 /* Pointer to the next function in cgraph_nodes_queue. */
142 struct cgraph_node *next_needed;
143 /* Pointer to the next clone. */
144 struct cgraph_node *next_clone;
145 struct cgraph_node *prev_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 /* unique id for profiling. pid is not suitable because of different
164 number of cfg nodes with -fprofile-generate and -fprofile-use */
165 int pid;
166
167 /* Set when function must be output - it is externally visible
168 or its address is taken. */
169 unsigned needed : 1;
170 /* Set when decl is an abstract function pointed to by the
171 ABSTRACT_DECL_ORIGIN of a reachable function. */
172 unsigned abstract_and_needed : 1;
173 /* Set when function is reachable by call from other function
174 that is either reachable or needed. */
175 unsigned reachable : 1;
176 /* Set once the function is lowered (i.e. its CFG is built). */
177 unsigned lowered : 1;
178 /* Set once the function has been instantiated and its callee
179 lists created. */
180 unsigned analyzed : 1;
181 /* Set when function is scheduled to be processed by local passes. */
182 unsigned process : 1;
183 /* Set for aliases once they got through assemble_alias. */
184 unsigned alias : 1;
185
186 /* In non-unit-at-a-time mode the function body of inline candidates is saved
187 into clone before compiling so the function in original form can be
188 inlined later. This pointer points to the clone. */
189 tree inline_decl;
190 };
191
192 #define DEFCIFCODE(code, string) CIF_ ## code,
193 /* Reasons for inlining failures. */
194 typedef enum {
195 #include "cif-code.def"
196 CIF_N_REASONS
197 } cgraph_inline_failed_t;
198
199 struct cgraph_edge GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
200 {
201 struct cgraph_node *caller;
202 struct cgraph_node *callee;
203 struct cgraph_edge *prev_caller;
204 struct cgraph_edge *next_caller;
205 struct cgraph_edge *prev_callee;
206 struct cgraph_edge *next_callee;
207 gimple call_stmt;
208 PTR GTY ((skip (""))) aux;
209 /* When equal to CIF_OK, inline this call. Otherwise, points to the
210 explanation why function was not inlined. */
211 cgraph_inline_failed_t inline_failed;
212 /* Expected number of executions: calculated in profile.c. */
213 gcov_type count;
214 /* Expected frequency of executions within the function.
215 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
216 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
217 int frequency;
218 /* Depth of loop nest, 1 means no loop nest. */
219 unsigned int loop_nest : 30;
220 /* Whether this edge describes a call that was originally indirect. */
221 unsigned int indirect_call : 1;
222 /* Can this call throw externally? */
223 unsigned int can_throw_external : 1;
224 /* Unique id of the edge. */
225 int uid;
226 };
227
228 #define CGRAPH_FREQ_BASE 1000
229 #define CGRAPH_FREQ_MAX 100000
230
231 typedef struct cgraph_edge *cgraph_edge_p;
232
233 DEF_VEC_P(cgraph_edge_p);
234 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
235
236 /* The varpool data structure.
237 Each static variable decl has assigned varpool_node. */
238
239 struct varpool_node GTY((chain_next ("%h.next")))
240 {
241 tree decl;
242 /* Pointer to the next function in varpool_nodes. */
243 struct varpool_node *next;
244 /* Pointer to the next function in varpool_nodes_queue. */
245 struct varpool_node *next_needed;
246 /* Ordering of all cgraph nodes. */
247 int order;
248
249 /* Set when function must be output - it is externally visible
250 or its address is taken. */
251 unsigned needed : 1;
252 /* Needed variables might become dead by optimization. This flag
253 forces the variable to be output even if it appears dead otherwise. */
254 unsigned force_output : 1;
255 /* Set once the variable has been instantiated and its callee
256 lists created. */
257 unsigned analyzed : 1;
258 /* Set once it has been finalized so we consider it to be output. */
259 unsigned finalized : 1;
260 /* Set when variable is scheduled to be assembled. */
261 unsigned output : 1;
262 /* Set when function is visible by other units. */
263 unsigned externally_visible : 1;
264 /* Set for aliases once they got through assemble_alias. */
265 unsigned alias : 1;
266 };
267
268 /* Every top level asm statement is put into a cgraph_asm_node. */
269
270 struct cgraph_asm_node GTY(())
271 {
272 /* Next asm node. */
273 struct cgraph_asm_node *next;
274 /* String for this asm node. */
275 tree asm_str;
276 /* Ordering of all cgraph nodes. */
277 int order;
278 };
279
280 extern GTY(()) struct cgraph_node *cgraph_nodes;
281 extern GTY(()) int cgraph_n_nodes;
282 extern GTY(()) int cgraph_max_uid;
283 extern GTY(()) int cgraph_edge_max_uid;
284 extern GTY(()) int cgraph_max_pid;
285 extern bool cgraph_global_info_ready;
286 enum cgraph_state
287 {
288 /* Callgraph is being constructed. It is safe to add new functions. */
289 CGRAPH_STATE_CONSTRUCTION,
290 /* Callgraph is built and IPA passes are being run. */
291 CGRAPH_STATE_IPA,
292 /* Callgraph is built and all functions are transformed to SSA form. */
293 CGRAPH_STATE_IPA_SSA,
294 /* Functions are now ordered and being passed to RTL expanders. */
295 CGRAPH_STATE_EXPANSION,
296 /* All cgraph expansion is done. */
297 CGRAPH_STATE_FINISHED
298 };
299 extern enum cgraph_state cgraph_state;
300 extern bool cgraph_function_flags_ready;
301 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
302 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
303
304 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
305 extern GTY(()) int cgraph_order;
306
307 /* In cgraph.c */
308 void dump_cgraph (FILE *);
309 void debug_cgraph (void);
310 void dump_cgraph_node (FILE *, struct cgraph_node *);
311 void debug_cgraph_node (struct cgraph_node *);
312 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
313 void cgraph_remove_edge (struct cgraph_edge *);
314 void cgraph_remove_node (struct cgraph_node *);
315 void cgraph_release_function_body (struct cgraph_node *);
316 void cgraph_node_remove_callees (struct cgraph_node *node);
317 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
318 struct cgraph_node *,
319 gimple, gcov_type, int, int);
320 struct cgraph_node *cgraph_node (tree);
321 struct cgraph_node *cgraph_node_for_asm (tree asmname);
322 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
323 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
324 void cgraph_update_edges_for_call_stmt (gimple, gimple);
325 struct cgraph_local_info *cgraph_local_info (tree);
326 struct cgraph_global_info *cgraph_global_info (tree);
327 struct cgraph_rtl_info *cgraph_rtl_info (tree);
328 const char * cgraph_node_name (struct cgraph_node *);
329 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
330 struct cgraph_node *,
331 gimple, gcov_type, int, int, bool);
332 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, int,
333 int, bool);
334
335 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
336
337 struct cgraph_asm_node *cgraph_add_asm_node (tree);
338
339 bool cgraph_function_possibly_inlined_p (tree);
340 void cgraph_unnest_node (struct cgraph_node *);
341
342 enum availability cgraph_function_body_availability (struct cgraph_node *);
343 void cgraph_add_new_function (tree, bool);
344 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
345
346 /* In cgraphunit.c */
347 void cgraph_finalize_function (tree, bool);
348 void cgraph_mark_if_needed (tree);
349 void cgraph_finalize_compilation_unit (void);
350 void cgraph_optimize (void);
351 void cgraph_mark_needed_node (struct cgraph_node *);
352 void cgraph_mark_reachable_node (struct cgraph_node *);
353 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
354 bool cgraph_preserve_function_body_p (tree);
355 void verify_cgraph (void);
356 void verify_cgraph_node (struct cgraph_node *);
357 void cgraph_build_static_cdtor (char which, tree body, int priority);
358 void cgraph_reset_static_var_maps (void);
359 void init_cgraph (void);
360 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
361 VEC(cgraph_edge_p,heap)*,
362 varray_type,
363 bitmap);
364 void cgraph_analyze_function (struct cgraph_node *);
365 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
366 void record_references_in_initializer (tree);
367 bool cgraph_process_new_functions (void);
368
369 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
370 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
371 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
372 void *);
373 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
374 void *);
375 struct cgraph_edge_hook_list;
376 struct cgraph_node_hook_list;
377 struct cgraph_2edge_hook_list;
378 struct cgraph_2node_hook_list;
379 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
380 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
381 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
382 void *);
383 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
384 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
385 void *);
386 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
387 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
388 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
389 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
390 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
391 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
392
393 /* In cgraphbuild.c */
394 unsigned int rebuild_cgraph_edges (void);
395 int compute_call_stmt_bb_frequency (basic_block bb);
396
397 /* In ipa.c */
398 bool cgraph_remove_unreachable_nodes (bool, FILE *);
399 int cgraph_postorder (struct cgraph_node **);
400
401 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
402
403 /* In varpool.c */
404
405 extern GTY(()) struct varpool_node *varpool_nodes_queue;
406 extern GTY(()) struct varpool_node *varpool_nodes;
407
408 struct varpool_node *varpool_node (tree);
409 struct varpool_node *varpool_node_for_asm (tree asmname);
410 void varpool_mark_needed_node (struct varpool_node *);
411 void debug_varpool (void);
412 void dump_varpool (FILE *);
413 void dump_varpool_node (FILE *, struct varpool_node *);
414
415 void varpool_finalize_decl (tree);
416 bool decide_is_variable_needed (struct varpool_node *, tree);
417 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
418
419 bool varpool_assemble_pending_decls (void);
420 bool varpool_assemble_decl (struct varpool_node *node);
421 bool varpool_analyze_pending_decls (void);
422 void varpool_remove_unreferenced_decls (void);
423 void varpool_empty_needed_queue (void);
424
425 /* Walk all reachable static variables. */
426 #define FOR_EACH_STATIC_VARIABLE(node) \
427 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
428
429 /* Return first reachable static variable with initializer. */
430 static inline struct varpool_node *
431 varpool_first_static_initializer (void)
432 {
433 struct varpool_node *node;
434 for (node = varpool_nodes_queue; node; node = node->next_needed)
435 {
436 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
437 if (DECL_INITIAL (node->decl))
438 return node;
439 }
440 return NULL;
441 }
442
443 /* Return next reachable static variable with initializer after NODE. */
444 static inline struct varpool_node *
445 varpool_next_static_initializer (struct varpool_node *node)
446 {
447 for (node = node->next_needed; node; node = node->next_needed)
448 {
449 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
450 if (DECL_INITIAL (node->decl))
451 return node;
452 }
453 return NULL;
454 }
455
456 /* Walk all static variables with initializer set. */
457 #define FOR_EACH_STATIC_INITIALIZER(node) \
458 for ((node) = varpool_first_static_initializer (); (node); \
459 (node) = varpool_next_static_initializer (node))
460
461 /* In ipa-inline.c */
462 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
463 unsigned int compute_inline_parameters (struct cgraph_node *);
464
465
466 /* Create a new static variable of type TYPE. */
467 tree add_new_static_var (tree type);
468
469 #endif /* GCC_CGRAPH_H */