cgraph.h (struct cgraph_node): Remove inline_decl member.
[gcc.git] / gcc / cgraph.h
1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
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 /* Function inlining information. */
52
53 struct GTY(()) inline_summary
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
62 /* Information about the function collected locally.
63 Available after function is analyzed. */
64
65 struct GTY(()) cgraph_local_info {
66 struct inline_summary inline_summary;
67
68 /* Set when function function is visible in current compilation unit only
69 and its address is never taken. */
70 unsigned local : 1;
71
72 /* Set when function is visible by other units. */
73 unsigned externally_visible : 1;
74
75 /* Set once it has been finalized so we consider it to be output. */
76 unsigned finalized : 1;
77
78 /* False when there something makes inlining impossible (such as va_arg). */
79 unsigned inlinable : 1;
80
81 /* True when function should be inlined independently on its size. */
82 unsigned disregard_inline_limits : 1;
83
84 /* True when the function has been originally extern inline, but it is
85 redefined now. */
86 unsigned redefined_extern_inline : 1;
87
88 /* True if statics_read_for_function and
89 statics_written_for_function contain valid data. */
90 unsigned for_functions_valid : 1;
91
92 /* True if the function is going to be emitted in some other translation
93 unit, referenced from vtable. */
94 unsigned vtable_method : 1;
95 };
96
97 /* Information about the function that needs to be computed globally
98 once compilation is finished. Available only with -funit-at-a-time. */
99
100 struct GTY(()) cgraph_global_info {
101 /* Estimated stack frame consumption by the function. */
102 HOST_WIDE_INT estimated_stack_size;
103 /* Expected offset of the stack frame of inlined function. */
104 HOST_WIDE_INT stack_frame_offset;
105
106 /* For inline clones this points to the function they will be
107 inlined into. */
108 struct cgraph_node *inlined_to;
109
110 /* Estimated size of the function after inlining. */
111 int insns;
112
113 /* Estimated growth after inlining. INT_MIN if not computed. */
114 int estimated_growth;
115
116 /* Set iff the function has been inlined at least once. */
117 bool inlined;
118 };
119
120 /* Information about the function that is propagated by the RTL backend.
121 Available only for functions that has been already assembled. */
122
123 struct GTY(()) cgraph_rtl_info {
124 unsigned int preferred_incoming_stack_boundary;
125 };
126
127 /* Represent which DECL tree (or reference to such tree)
128 will be replaced by another tree while versioning. */
129 struct GTY(()) ipa_replace_map
130 {
131 /* The tree that will be replaced. */
132 tree old_tree;
133 /* The new (replacing) tree. */
134 tree new_tree;
135 /* True when a substitution should be done, false otherwise. */
136 bool replace_p;
137 /* True when we replace a reference to old_tree. */
138 bool ref_p;
139 };
140 typedef struct ipa_replace_map *ipa_replace_map_p;
141 DEF_VEC_P(ipa_replace_map_p);
142 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
143
144 struct GTY(()) cgraph_clone_info
145 {
146 VEC(ipa_replace_map_p,gc)* tree_map;
147 bitmap args_to_skip;
148 };
149
150 /* The cgraph data structure.
151 Each function decl has assigned cgraph_node listing callees and callers. */
152
153 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
154 tree decl;
155 struct cgraph_edge *callees;
156 struct cgraph_edge *callers;
157 struct cgraph_node *next;
158 struct cgraph_node *previous;
159 /* For nested functions points to function the node is nested in. */
160 struct cgraph_node *origin;
161 /* Points to first nested function, if any. */
162 struct cgraph_node *nested;
163 /* Pointer to the next function with same origin, if any. */
164 struct cgraph_node *next_nested;
165 /* Pointer to the next function in cgraph_nodes_queue. */
166 struct cgraph_node *next_needed;
167 /* Pointer to the next clone. */
168 struct cgraph_node *next_sibling_clone;
169 struct cgraph_node *prev_sibling_clone;
170 struct cgraph_node *clones;
171 struct cgraph_node *clone_of;
172 /* For functions with many calls sites it holds map from call expression
173 to the edge to speed up cgraph_edge function. */
174 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
175
176 PTR GTY ((skip)) aux;
177
178 struct cgraph_local_info local;
179 struct cgraph_global_info global;
180 struct cgraph_rtl_info rtl;
181 struct cgraph_clone_info clone;
182
183 /* Expected number of executions: calculated in profile.c. */
184 gcov_type count;
185 /* Unique id of the node. */
186 int uid;
187 /* Ordering of all cgraph nodes. */
188 int order;
189
190 /* unique id for profiling. pid is not suitable because of different
191 number of cfg nodes with -fprofile-generate and -fprofile-use */
192 int pid;
193
194 /* Set when function must be output - it is externally visible
195 or its address is taken. */
196 unsigned needed : 1;
197 /* Set when function has address taken. */
198 unsigned address_taken : 1;
199 /* Set when decl is an abstract function pointed to by the
200 ABSTRACT_DECL_ORIGIN of a reachable function. */
201 unsigned abstract_and_needed : 1;
202 /* Set when function is reachable by call from other function
203 that is either reachable or needed. */
204 unsigned reachable : 1;
205 /* Set once the function is lowered (i.e. its CFG is built). */
206 unsigned lowered : 1;
207 /* Set once the function has been instantiated and its callee
208 lists created. */
209 unsigned analyzed : 1;
210 /* Set when function is scheduled to be processed by local passes. */
211 unsigned process : 1;
212 /* Set for aliases once they got through assemble_alias. */
213 unsigned alias : 1;
214 /* Set for nodes that was constructed and finalized by frontend. */
215 unsigned finalized_by_frontend : 1;
216 };
217
218 typedef struct cgraph_node *cgraph_node_ptr;
219
220 DEF_VEC_P(cgraph_node_ptr);
221 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
222 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
223
224 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
225 can appear in multiple sets. */
226 struct GTY(()) cgraph_node_set_def
227 {
228 htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
229 VEC(cgraph_node_ptr, gc) *nodes;
230 PTR GTY ((skip)) aux;
231 };
232
233 typedef struct cgraph_node_set_def *cgraph_node_set;
234
235 DEF_VEC_P(cgraph_node_set);
236 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
237 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
238
239 /* A cgraph node set element contains an index in the vector of nodes in
240 the set. */
241 struct GTY(()) cgraph_node_set_element_def
242 {
243 struct cgraph_node *node;
244 HOST_WIDE_INT index;
245 };
246
247 typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
248 typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
249
250 /* Iterator structure for cgraph node sets. */
251 typedef struct
252 {
253 cgraph_node_set set;
254 unsigned index;
255 } cgraph_node_set_iterator;
256
257 #define DEFCIFCODE(code, string) CIF_ ## code,
258 /* Reasons for inlining failures. */
259 typedef enum {
260 #include "cif-code.def"
261 CIF_N_REASONS
262 } cgraph_inline_failed_t;
263
264 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
265 struct cgraph_node *caller;
266 struct cgraph_node *callee;
267 struct cgraph_edge *prev_caller;
268 struct cgraph_edge *next_caller;
269 struct cgraph_edge *prev_callee;
270 struct cgraph_edge *next_callee;
271 gimple call_stmt;
272 PTR GTY ((skip (""))) aux;
273 /* When equal to CIF_OK, inline this call. Otherwise, points to the
274 explanation why function was not inlined. */
275 cgraph_inline_failed_t inline_failed;
276 /* Expected number of executions: calculated in profile.c. */
277 gcov_type count;
278 /* Expected frequency of executions within the function.
279 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
280 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
281 int frequency;
282 /* Depth of loop nest, 1 means no loop nest. */
283 unsigned int loop_nest : 30;
284 /* Whether this edge describes a call that was originally indirect. */
285 unsigned int indirect_call : 1;
286 /* Can this call throw externally? */
287 unsigned int can_throw_external : 1;
288 /* Unique id of the edge. */
289 int uid;
290 };
291
292 #define CGRAPH_FREQ_BASE 1000
293 #define CGRAPH_FREQ_MAX 100000
294
295 typedef struct cgraph_edge *cgraph_edge_p;
296
297 DEF_VEC_P(cgraph_edge_p);
298 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
299
300 /* The varpool data structure.
301 Each static variable decl has assigned varpool_node. */
302
303 struct GTY((chain_next ("%h.next"))) varpool_node {
304 tree decl;
305 /* Pointer to the next function in varpool_nodes. */
306 struct varpool_node *next;
307 /* Pointer to the next function in varpool_nodes_queue. */
308 struct varpool_node *next_needed;
309 /* Ordering of all cgraph nodes. */
310 int order;
311
312 /* Set when function must be output - it is externally visible
313 or its address is taken. */
314 unsigned needed : 1;
315 /* Needed variables might become dead by optimization. This flag
316 forces the variable to be output even if it appears dead otherwise. */
317 unsigned force_output : 1;
318 /* Set once the variable has been instantiated and its callee
319 lists created. */
320 unsigned analyzed : 1;
321 /* Set once it has been finalized so we consider it to be output. */
322 unsigned finalized : 1;
323 /* Set when variable is scheduled to be assembled. */
324 unsigned output : 1;
325 /* Set when function is visible by other units. */
326 unsigned externally_visible : 1;
327 /* Set for aliases once they got through assemble_alias. */
328 unsigned alias : 1;
329 };
330
331 /* Every top level asm statement is put into a cgraph_asm_node. */
332
333 struct GTY(()) cgraph_asm_node {
334 /* Next asm node. */
335 struct cgraph_asm_node *next;
336 /* String for this asm node. */
337 tree asm_str;
338 /* Ordering of all cgraph nodes. */
339 int order;
340 };
341
342 extern GTY(()) struct cgraph_node *cgraph_nodes;
343 extern GTY(()) int cgraph_n_nodes;
344 extern GTY(()) int cgraph_max_uid;
345 extern GTY(()) int cgraph_edge_max_uid;
346 extern GTY(()) int cgraph_max_pid;
347 extern bool cgraph_global_info_ready;
348 enum cgraph_state
349 {
350 /* Callgraph is being constructed. It is safe to add new functions. */
351 CGRAPH_STATE_CONSTRUCTION,
352 /* Callgraph is built and IPA passes are being run. */
353 CGRAPH_STATE_IPA,
354 /* Callgraph is built and all functions are transformed to SSA form. */
355 CGRAPH_STATE_IPA_SSA,
356 /* Functions are now ordered and being passed to RTL expanders. */
357 CGRAPH_STATE_EXPANSION,
358 /* All cgraph expansion is done. */
359 CGRAPH_STATE_FINISHED
360 };
361 extern enum cgraph_state cgraph_state;
362 extern bool cgraph_function_flags_ready;
363 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
364 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
365
366 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
367 extern GTY(()) int cgraph_order;
368
369 /* In cgraph.c */
370 void dump_cgraph (FILE *);
371 void debug_cgraph (void);
372 void dump_cgraph_node (FILE *, struct cgraph_node *);
373 void debug_cgraph_node (struct cgraph_node *);
374 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
375 void cgraph_remove_edge (struct cgraph_edge *);
376 void cgraph_remove_node (struct cgraph_node *);
377 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
378 void cgraph_release_function_body (struct cgraph_node *);
379 void cgraph_node_remove_callees (struct cgraph_node *node);
380 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
381 struct cgraph_node *,
382 gimple, gcov_type, int, int);
383 struct cgraph_node *cgraph_node (tree);
384 struct cgraph_node *cgraph_node_for_asm (tree asmname);
385 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
386 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
387 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
388 void cgraph_create_edge_including_clones (struct cgraph_node *,
389 struct cgraph_node *,
390 gimple, gcov_type, int, int,
391 cgraph_inline_failed_t);
392 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
393 struct cgraph_local_info *cgraph_local_info (tree);
394 struct cgraph_global_info *cgraph_global_info (tree);
395 struct cgraph_rtl_info *cgraph_rtl_info (tree);
396 const char * cgraph_node_name (struct cgraph_node *);
397 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
398 struct cgraph_node *,
399 gimple, gcov_type, int, int, bool);
400 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, int,
401 int, bool);
402
403 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
404
405 struct cgraph_asm_node *cgraph_add_asm_node (tree);
406
407 bool cgraph_function_possibly_inlined_p (tree);
408 void cgraph_unnest_node (struct cgraph_node *);
409
410 enum availability cgraph_function_body_availability (struct cgraph_node *);
411 void cgraph_add_new_function (tree, bool);
412 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
413 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
414 VEC(cgraph_edge_p,heap)*,
415 VEC(ipa_replace_map_p,gc)* tree_map,
416 bitmap args_to_skip);
417
418 /* In cgraphunit.c */
419 void cgraph_finalize_function (tree, bool);
420 void cgraph_mark_if_needed (tree);
421 void cgraph_finalize_compilation_unit (void);
422 void cgraph_optimize (void);
423 void cgraph_mark_needed_node (struct cgraph_node *);
424 void cgraph_mark_address_taken_node (struct cgraph_node *);
425 void cgraph_mark_reachable_node (struct cgraph_node *);
426 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
427 bool cgraph_preserve_function_body_p (tree);
428 void verify_cgraph (void);
429 void verify_cgraph_node (struct cgraph_node *);
430 void cgraph_build_static_cdtor (char which, tree body, int priority);
431 void cgraph_reset_static_var_maps (void);
432 void init_cgraph (void);
433 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
434 VEC(cgraph_edge_p,heap)*,
435 VEC(ipa_replace_map_p,gc)*,
436 bitmap);
437 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap);
438 void cgraph_analyze_function (struct cgraph_node *);
439 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
440 void record_references_in_initializer (tree);
441 bool cgraph_process_new_functions (void);
442
443 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
444 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
445 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
446 void *);
447 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
448 void *);
449 struct cgraph_edge_hook_list;
450 struct cgraph_node_hook_list;
451 struct cgraph_2edge_hook_list;
452 struct cgraph_2node_hook_list;
453 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
454 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
455 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
456 void *);
457 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
458 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
459 void *);
460 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
461 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
462 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
463 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
464 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
465 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
466 void cgraph_materialize_all_clones (void);
467
468 /* In cgraphbuild.c */
469 unsigned int rebuild_cgraph_edges (void);
470 int compute_call_stmt_bb_frequency (tree, basic_block bb);
471
472 /* In ipa.c */
473 bool cgraph_remove_unreachable_nodes (bool, FILE *);
474 int cgraph_postorder (struct cgraph_node **);
475 cgraph_node_set cgraph_node_set_new (void);
476 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
477 struct cgraph_node *);
478 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
479 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
480 void dump_cgraph_node_set (FILE *, cgraph_node_set);
481 void debug_cgraph_node_set (cgraph_node_set);
482
483
484 /* In predict.c */
485 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
486
487 /* In varpool.c */
488 extern GTY(()) struct varpool_node *varpool_nodes_queue;
489 extern GTY(()) struct varpool_node *varpool_nodes;
490
491 struct varpool_node *varpool_node (tree);
492 struct varpool_node *varpool_node_for_asm (tree asmname);
493 void varpool_mark_needed_node (struct varpool_node *);
494 void debug_varpool (void);
495 void dump_varpool (FILE *);
496 void dump_varpool_node (FILE *, struct varpool_node *);
497
498 void varpool_finalize_decl (tree);
499 bool decide_is_variable_needed (struct varpool_node *, tree);
500 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
501
502 bool varpool_assemble_pending_decls (void);
503 bool varpool_assemble_decl (struct varpool_node *node);
504 bool varpool_analyze_pending_decls (void);
505 void varpool_remove_unreferenced_decls (void);
506 void varpool_empty_needed_queue (void);
507
508 /* Walk all reachable static variables. */
509 #define FOR_EACH_STATIC_VARIABLE(node) \
510 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
511
512 /* Return first reachable static variable with initializer. */
513 static inline struct varpool_node *
514 varpool_first_static_initializer (void)
515 {
516 struct varpool_node *node;
517 for (node = varpool_nodes_queue; node; node = node->next_needed)
518 {
519 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
520 if (DECL_INITIAL (node->decl))
521 return node;
522 }
523 return NULL;
524 }
525
526 /* Return next reachable static variable with initializer after NODE. */
527 static inline struct varpool_node *
528 varpool_next_static_initializer (struct varpool_node *node)
529 {
530 for (node = node->next_needed; node; node = node->next_needed)
531 {
532 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
533 if (DECL_INITIAL (node->decl))
534 return node;
535 }
536 return NULL;
537 }
538
539 /* Walk all static variables with initializer set. */
540 #define FOR_EACH_STATIC_INITIALIZER(node) \
541 for ((node) = varpool_first_static_initializer (); (node); \
542 (node) = varpool_next_static_initializer (node))
543
544 /* In ipa-inline.c */
545 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
546 unsigned int compute_inline_parameters (struct cgraph_node *);
547
548
549 /* Create a new static variable of type TYPE. */
550 tree add_new_static_var (tree type);
551
552
553 /* Return true if iterator CSI points to nothing. */
554 static inline bool
555 csi_end_p (cgraph_node_set_iterator csi)
556 {
557 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
558 }
559
560 /* Advance iterator CSI. */
561 static inline void
562 csi_next (cgraph_node_set_iterator *csi)
563 {
564 csi->index++;
565 }
566
567 /* Return the node pointed to by CSI. */
568 static inline struct cgraph_node *
569 csi_node (cgraph_node_set_iterator csi)
570 {
571 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
572 }
573
574 /* Return an iterator to the first node in SET. */
575 static inline cgraph_node_set_iterator
576 csi_start (cgraph_node_set set)
577 {
578 cgraph_node_set_iterator csi;
579
580 csi.set = set;
581 csi.index = 0;
582 return csi;
583 }
584
585 /* Return true if SET contains NODE. */
586 static inline bool
587 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
588 {
589 cgraph_node_set_iterator csi;
590 csi = cgraph_node_set_find (set, node);
591 return !csi_end_p (csi);
592 }
593
594 /* Return number of nodes in SET. */
595 static inline size_t
596 cgraph_node_set_size (cgraph_node_set set)
597 {
598 return htab_elements (set->hashtab);
599 }
600
601
602 #endif /* GCC_CGRAPH_H */