]>
Commit | Line | Data |
---|---|---|
1c4a429a | 1 | /* Callgraph handling code. |
ad616de1 | 2 | Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. |
1c4a429a JH |
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 | |
366ccddb KC |
19 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA |
20 | 02110-1301, USA. */ | |
1c4a429a JH |
21 | |
22 | #ifndef GCC_CGRAPH_H | |
23 | #define GCC_CGRAPH_H | |
6674a6ce | 24 | #include "tree.h" |
e42922b1 | 25 | #include "basic-block.h" |
1c4a429a | 26 | |
6b02a499 JH |
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 | ||
dafc5b82 | 49 | /* Information about the function collected locally. |
25c84396 | 50 | Available after function is analyzed. */ |
dafc5b82 | 51 | |
ed2df68b | 52 | struct cgraph_local_info GTY(()) |
dafc5b82 | 53 | { |
95c755e9 JH |
54 | /* Size of the function before inlining. */ |
55 | int self_insns; | |
6674a6ce | 56 | |
e0bb17a8 | 57 | /* Set when function function is visible in current compilation unit only |
e2209b03 | 58 | and its address is never taken. */ |
b4e19405 | 59 | unsigned local : 1; |
6674a6ce | 60 | |
e7d6beb0 | 61 | /* Set when function is visible by other units. */ |
b4e19405 | 62 | unsigned externally_visible : 1; |
e7d6beb0 | 63 | |
f6981e16 | 64 | /* Set once it has been finalized so we consider it to be output. */ |
b4e19405 | 65 | unsigned finalized : 1; |
b58b1157 | 66 | |
b3c3af2f | 67 | /* False when there something makes inlining impossible (such as va_arg). */ |
b4e19405 | 68 | unsigned inlinable : 1; |
6674a6ce | 69 | |
e2209b03 | 70 | /* True when function should be inlined independently on its size. */ |
b4e19405 | 71 | unsigned disregard_inline_limits : 1; |
6674a6ce | 72 | |
95c755e9 JH |
73 | /* True when the function has been originally extern inline, but it is |
74 | redefined now. */ | |
b4e19405 | 75 | unsigned redefined_extern_inline : 1; |
6674a6ce KZ |
76 | |
77 | /* True if statics_read_for_function and | |
78 | statics_written_for_function contain valid data. */ | |
b4e19405 | 79 | unsigned for_functions_valid : 1; |
8634c649 JJ |
80 | |
81 | /* True if the function is going to be emitted in some other translation | |
82 | unit, referenced from vtable. */ | |
b4e19405 | 83 | unsigned vtable_method : 1; |
dafc5b82 JH |
84 | }; |
85 | ||
86 | /* Information about the function that needs to be computed globally | |
87 | once compilation is finished. Available only with -funit-at-time. */ | |
88 | ||
ed2df68b | 89 | struct cgraph_global_info GTY(()) |
dafc5b82 | 90 | { |
18c6ada9 JH |
91 | /* For inline clones this points to the function they will be inlined into. */ |
92 | struct cgraph_node *inlined_to; | |
93 | ||
b58b1157 JH |
94 | /* Estimated size of the function after inlining. */ |
95 | int insns; | |
96 | ||
670cd5c5 JH |
97 | /* Estimated growth after inlining. INT_MIN if not computed. */ |
98 | int estimated_growth; | |
99 | ||
18c6ada9 | 100 | /* Set iff the function has been inlined at least once. */ |
1bb17c21 | 101 | bool inlined; |
dafc5b82 JH |
102 | }; |
103 | ||
b255a036 JH |
104 | /* Information about the function that is propagated by the RTL backend. |
105 | Available only for functions that has been already assembled. */ | |
106 | ||
ed2df68b | 107 | struct cgraph_rtl_info GTY(()) |
b255a036 | 108 | { |
6de9cd9a | 109 | int preferred_incoming_stack_boundary; |
b255a036 JH |
110 | }; |
111 | ||
ba228239 | 112 | /* The cgraph data structure. |
e0bb17a8 | 113 | Each function decl has assigned cgraph_node listing callees and callers. */ |
1c4a429a | 114 | |
d1bd0ded | 115 | struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) |
1c4a429a JH |
116 | { |
117 | tree decl; | |
118 | struct cgraph_edge *callees; | |
119 | struct cgraph_edge *callers; | |
ed2df68b JH |
120 | struct cgraph_node *next; |
121 | struct cgraph_node *previous; | |
1c4a429a JH |
122 | /* For nested functions points to function the node is nested in. */ |
123 | struct cgraph_node *origin; | |
124 | /* Points to first nested function, if any. */ | |
125 | struct cgraph_node *nested; | |
126 | /* Pointer to the next function with same origin, if any. */ | |
127 | struct cgraph_node *next_nested; | |
8bd87c4e JH |
128 | /* Pointer to the next function in cgraph_nodes_queue. */ |
129 | struct cgraph_node *next_needed; | |
18c6ada9 JH |
130 | /* Pointer to the next clone. */ |
131 | struct cgraph_node *next_clone; | |
1655dc9d | 132 | struct cgraph_node *prev_clone; |
6b02a499 JH |
133 | /* Pointer to a single unique cgraph node for this function. If the |
134 | function is to be output, this is the copy that will survive. */ | |
135 | struct cgraph_node *master_clone; | |
c22cacf3 | 136 | |
1431042e | 137 | PTR GTY ((skip)) aux; |
1c4a429a | 138 | |
95c755e9 JH |
139 | struct cgraph_local_info local; |
140 | struct cgraph_global_info global; | |
141 | struct cgraph_rtl_info rtl; | |
c22cacf3 | 142 | |
e42922b1 JH |
143 | /* Expected number of executions: calculated in profile.c. */ |
144 | gcov_type count; | |
95c755e9 JH |
145 | /* Unique id of the node. */ |
146 | int uid; | |
474eccc6 ILT |
147 | /* Ordering of all cgraph nodes. */ |
148 | int order; | |
b4e19405 | 149 | |
1c4a429a | 150 | /* Set when function must be output - it is externally visible |
e2209b03 | 151 | or its address is taken. */ |
b4e19405 | 152 | unsigned needed : 1; |
1c4a429a | 153 | /* Set when function is reachable by call from other function |
e0bb17a8 | 154 | that is either reachable or needed. */ |
b4e19405 | 155 | unsigned reachable : 1; |
50674e96 | 156 | /* Set once the function is lowered (i.e. its CFG is built). */ |
b4e19405 | 157 | unsigned lowered : 1; |
25c84396 RH |
158 | /* Set once the function has been instantiated and its callee |
159 | lists created. */ | |
b4e19405 | 160 | unsigned analyzed : 1; |
1c4a429a | 161 | /* Set when function is scheduled to be assembled. */ |
b4e19405 | 162 | unsigned output : 1; |
ce91e74c | 163 | /* Set when function is visible by other units. */ |
b4e19405 | 164 | unsigned externally_visible : 1; |
12527dce | 165 | /* Set for aliases once they got through assemble_alias. */ |
b4e19405 | 166 | unsigned alias : 1; |
ea99e0be JH |
167 | |
168 | /* In non-unit-at-a-time mode the function body of inline candidates is saved | |
169 | into clone before compiling so the function in original form can be | |
170 | inlined later. This pointer points to the clone. */ | |
171 | tree inline_decl; | |
1c4a429a JH |
172 | }; |
173 | ||
2563c224 | 174 | struct cgraph_edge GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) |
1c4a429a | 175 | { |
ed2df68b JH |
176 | struct cgraph_node *caller; |
177 | struct cgraph_node *callee; | |
2563c224 | 178 | struct cgraph_edge *prev_caller; |
1c4a429a | 179 | struct cgraph_edge *next_caller; |
2563c224 | 180 | struct cgraph_edge *prev_callee; |
1c4a429a | 181 | struct cgraph_edge *next_callee; |
e0704a46 | 182 | tree call_stmt; |
18c6ada9 | 183 | PTR GTY ((skip (""))) aux; |
dc0bfe6a JH |
184 | /* When NULL, inline this call. When non-NULL, points to the explanation |
185 | why function was not inlined. */ | |
186 | const char *inline_failed; | |
e42922b1 JH |
187 | /* Expected number of executions: calculated in profile.c. */ |
188 | gcov_type count; | |
189 | /* Depth of loop nest, 1 means no loop nest. */ | |
190 | int loop_nest; | |
1c4a429a JH |
191 | }; |
192 | ||
b2c0ad40 KH |
193 | typedef struct cgraph_edge *cgraph_edge_p; |
194 | ||
195 | DEF_VEC_P(cgraph_edge_p); | |
196 | DEF_VEC_ALLOC_P(cgraph_edge_p,heap); | |
197 | ||
ba228239 | 198 | /* The cgraph_varpool data structure. |
e69529cd JH |
199 | Each static variable decl has assigned cgraph_varpool_node. */ |
200 | ||
ed2df68b | 201 | struct cgraph_varpool_node GTY(()) |
e69529cd JH |
202 | { |
203 | tree decl; | |
bedb9fc0 RH |
204 | /* Pointer to the next function in cgraph_varpool_nodes. */ |
205 | struct cgraph_varpool_node *next; | |
8bd87c4e JH |
206 | /* Pointer to the next function in cgraph_varpool_nodes_queue. */ |
207 | struct cgraph_varpool_node *next_needed; | |
474eccc6 ILT |
208 | /* Ordering of all cgraph nodes. */ |
209 | int order; | |
e69529cd JH |
210 | |
211 | /* Set when function must be output - it is externally visible | |
e2209b03 | 212 | or its address is taken. */ |
b4e19405 | 213 | unsigned needed : 1; |
cd9c7bd2 JH |
214 | /* Needed variables might become dead by optimization. This flag |
215 | forces the variable to be output even if it appears dead otherwise. */ | |
b4e19405 | 216 | unsigned force_output : 1; |
cd9c7bd2 JH |
217 | /* Set once the variable has been instantiated and its callee |
218 | lists created. */ | |
b4e19405 | 219 | unsigned analyzed : 1; |
e69529cd | 220 | /* Set once it has been finalized so we consider it to be output. */ |
b4e19405 | 221 | unsigned finalized : 1; |
6b02a499 | 222 | /* Set when variable is scheduled to be assembled. */ |
b4e19405 | 223 | unsigned output : 1; |
e7d6beb0 | 224 | /* Set when function is visible by other units. */ |
b4e19405 | 225 | unsigned externally_visible : 1; |
1a612e0a | 226 | /* Set for aliases once they got through assemble_alias. */ |
b4e19405 | 227 | unsigned alias : 1; |
e69529cd JH |
228 | }; |
229 | ||
474eccc6 ILT |
230 | /* Every top level asm statement is put into a cgraph_asm_node. */ |
231 | ||
232 | struct cgraph_asm_node GTY(()) | |
233 | { | |
234 | /* Next asm node. */ | |
235 | struct cgraph_asm_node *next; | |
236 | /* String for this asm node. */ | |
237 | tree asm_str; | |
238 | /* Ordering of all cgraph nodes. */ | |
239 | int order; | |
240 | }; | |
241 | ||
ed2df68b JH |
242 | extern GTY(()) struct cgraph_node *cgraph_nodes; |
243 | extern GTY(()) int cgraph_n_nodes; | |
b58b1157 | 244 | extern GTY(()) int cgraph_max_uid; |
dafc5b82 | 245 | extern bool cgraph_global_info_ready; |
e7d6beb0 | 246 | extern bool cgraph_function_flags_ready; |
ed2df68b | 247 | extern GTY(()) struct cgraph_node *cgraph_nodes_queue; |
50674e96 | 248 | extern GTY(()) struct cgraph_node *cgraph_expand_queue; |
1c4a429a | 249 | |
cd9c7bd2 | 250 | extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_first_unanalyzed_node; |
ed2df68b | 251 | extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_nodes_queue; |
386b46cf | 252 | extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_nodes; |
474eccc6 ILT |
253 | extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes; |
254 | extern GTY(()) int cgraph_order; | |
e69529cd | 255 | |
1c4a429a | 256 | /* In cgraph.c */ |
439f7bc3 | 257 | void dump_cgraph (FILE *); |
18c6ada9 | 258 | void dump_cgraph_node (FILE *, struct cgraph_node *); |
ea99e0be | 259 | void cgraph_insert_node_to_hashtable (struct cgraph_node *node); |
cd9c7bd2 JH |
260 | void dump_varpool (FILE *); |
261 | void dump_cgraph_varpool_node (FILE *, struct cgraph_varpool_node *); | |
18c6ada9 | 262 | void cgraph_remove_edge (struct cgraph_edge *); |
439f7bc3 | 263 | void cgraph_remove_node (struct cgraph_node *); |
2563c224 | 264 | void cgraph_node_remove_callees (struct cgraph_node *node); |
18c6ada9 JH |
265 | struct cgraph_edge *cgraph_create_edge (struct cgraph_node *, |
266 | struct cgraph_node *, | |
c22cacf3 | 267 | tree, gcov_type, int); |
e42922b1 | 268 | struct cgraph_node *cgraph_node (tree); |
bedb9fc0 | 269 | struct cgraph_node *cgraph_node_for_asm (tree asmname); |
e42922b1 | 270 | struct cgraph_edge *cgraph_edge (struct cgraph_node *, tree); |
439f7bc3 AJ |
271 | struct cgraph_local_info *cgraph_local_info (tree); |
272 | struct cgraph_global_info *cgraph_global_info (tree); | |
273 | struct cgraph_rtl_info *cgraph_rtl_info (tree); | |
274 | const char * cgraph_node_name (struct cgraph_node *); | |
c5a4444c | 275 | struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *, |
c22cacf3 MS |
276 | struct cgraph_node *, |
277 | tree, gcov_type, int, bool); | |
c5a4444c JH |
278 | struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, |
279 | int, bool); | |
1c4a429a | 280 | |
e42922b1 | 281 | struct cgraph_varpool_node *cgraph_varpool_node (tree); |
bedb9fc0 | 282 | struct cgraph_varpool_node *cgraph_varpool_node_for_asm (tree asmname); |
e69529cd JH |
283 | void cgraph_varpool_mark_needed_node (struct cgraph_varpool_node *); |
284 | void cgraph_varpool_finalize_decl (tree); | |
18c6ada9 | 285 | void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *); |
e69529cd | 286 | |
474eccc6 ILT |
287 | struct cgraph_asm_node *cgraph_add_asm_node (tree); |
288 | ||
1bb17c21 | 289 | bool cgraph_function_possibly_inlined_p (tree); |
e42922b1 | 290 | void cgraph_unnest_node (struct cgraph_node *); |
cd9c7bd2 JH |
291 | void cgraph_varpool_enqueue_needed_node (struct cgraph_varpool_node *); |
292 | void cgraph_varpool_reset_queue (void); | |
293 | bool decide_is_variable_needed (struct cgraph_varpool_node *, tree); | |
1bb17c21 | 294 | |
6b02a499 JH |
295 | enum availability cgraph_function_body_availability (struct cgraph_node *); |
296 | enum availability cgraph_variable_initializer_availability (struct cgraph_varpool_node *); | |
297 | bool cgraph_is_master_clone (struct cgraph_node *); | |
298 | struct cgraph_node *cgraph_master_clone (struct cgraph_node *); | |
953ff289 | 299 | void cgraph_add_new_function (tree); |
6b02a499 | 300 | |
1c4a429a | 301 | /* In cgraphunit.c */ |
f6d1b84a | 302 | bool cgraph_assemble_pending_functions (void); |
cd9c7bd2 | 303 | bool cgraph_varpool_assemble_pending_decls (void); |
6b00c969 | 304 | void cgraph_finalize_function (tree, bool); |
439f7bc3 | 305 | void cgraph_finalize_compilation_unit (void); |
439f7bc3 | 306 | void cgraph_optimize (void); |
8dafba3c RH |
307 | void cgraph_mark_needed_node (struct cgraph_node *); |
308 | void cgraph_mark_reachable_node (struct cgraph_node *); | |
18c6ada9 JH |
309 | bool cgraph_inline_p (struct cgraph_edge *, const char **reason); |
310 | bool cgraph_preserve_function_body_p (tree); | |
311 | void verify_cgraph (void); | |
312 | void verify_cgraph_node (struct cgraph_node *); | |
35b6fdcf | 313 | void cgraph_build_static_cdtor (char which, tree body, int priority); |
6674a6ce | 314 | void cgraph_reset_static_var_maps (void); |
9b3e897d | 315 | void init_cgraph (void); |
57fb5341 | 316 | struct cgraph_node *cgraph_function_versioning (struct cgraph_node *, |
c22cacf3 | 317 | VEC(cgraph_edge_p,heap)*, |
b2c0ad40 | 318 | varray_type); |
953ff289 | 319 | void cgraph_analyze_function (struct cgraph_node *); |
ea99e0be | 320 | struct cgraph_node *save_inline_function_body (struct cgraph_node *); |
1c4a429a | 321 | |
ca31b95f JH |
322 | /* In ipa.c */ |
323 | bool cgraph_remove_unreachable_nodes (bool, FILE *); | |
324 | int cgraph_postorder (struct cgraph_node **); | |
325 | ||
326 | /* In ipa-inline.c */ | |
d63db217 | 327 | bool cgraph_decide_inlining_incrementally (struct cgraph_node *, bool); |
06191a23 JH |
328 | void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool); |
329 | void cgraph_mark_inline_edge (struct cgraph_edge *, bool); | |
9de21a23 | 330 | bool cgraph_default_inline_p (struct cgraph_node *, const char **); |
1c4a429a | 331 | #endif /* GCC_CGRAPH_H */ |