1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
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
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
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, 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "basic-block.h"
29 /* Not yet set by cgraph_function_body_availability. */
31 /* Function body/variable initializer is unknown. */
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. */
39 /* Function body/variable initializer is known and will be used in final
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. */
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. */
62 /* Set when function function is visible in current compilation unit only
63 and its address is never taken. */
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
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. */
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. */
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")))
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. */
158 /* Unique id of the node. */
160 /* Ordering of all cgraph nodes. */
163 /* Set when function must be output - it is externally visible
164 or its address is taken. */
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
173 unsigned analyzed
: 1;
174 /* Set when function is scheduled to be assembled. */
176 /* Set for aliases once they got through assemble_alias. */
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. */
184 /* Call unsaved hard registers really used by the corresponding
185 function (including ones used by functions called by the
187 HARD_REG_SET function_used_regs
;
190 struct cgraph_edge
GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
192 struct cgraph_node
*caller
;
193 struct cgraph_node
*callee
;
194 struct cgraph_edge
*prev_caller
;
195 struct cgraph_edge
*next_caller
;
196 struct cgraph_edge
*prev_callee
;
197 struct cgraph_edge
*next_callee
;
199 PTR
GTY ((skip (""))) aux
;
200 /* When NULL, inline this call. When non-NULL, points to the explanation
201 why function was not inlined. */
202 const char *inline_failed
;
203 /* Expected number of executions: calculated in profile.c. */
205 /* Depth of loop nest, 1 means no loop nest. */
209 typedef struct cgraph_edge
*cgraph_edge_p
;
211 DEF_VEC_P(cgraph_edge_p
);
212 DEF_VEC_ALLOC_P(cgraph_edge_p
,heap
);
214 /* The varpool data structure.
215 Each static variable decl has assigned varpool_node. */
217 struct varpool_node
GTY(())
220 /* Pointer to the next function in varpool_nodes. */
221 struct varpool_node
*next
;
222 /* Pointer to the next function in varpool_nodes_queue. */
223 struct varpool_node
*next_needed
;
224 /* Ordering of all cgraph nodes. */
227 /* Set when function must be output - it is externally visible
228 or its address is taken. */
230 /* Needed variables might become dead by optimization. This flag
231 forces the variable to be output even if it appears dead otherwise. */
232 unsigned force_output
: 1;
233 /* Set once the variable has been instantiated and its callee
235 unsigned analyzed
: 1;
236 /* Set once it has been finalized so we consider it to be output. */
237 unsigned finalized
: 1;
238 /* Set when variable is scheduled to be assembled. */
240 /* Set when function is visible by other units. */
241 unsigned externally_visible
: 1;
242 /* Set for aliases once they got through assemble_alias. */
246 /* Every top level asm statement is put into a cgraph_asm_node. */
248 struct cgraph_asm_node
GTY(())
251 struct cgraph_asm_node
*next
;
252 /* String for this asm node. */
254 /* Ordering of all cgraph nodes. */
258 extern GTY(()) struct cgraph_node
*cgraph_nodes
;
259 extern GTY(()) int cgraph_n_nodes
;
260 extern GTY(()) int cgraph_max_uid
;
261 extern bool cgraph_global_info_ready
;
262 extern bool cgraph_function_flags_ready
;
263 extern GTY(()) struct cgraph_node
*cgraph_nodes_queue
;
264 extern GTY(()) struct cgraph_node
*cgraph_expand_queue
;
266 extern GTY(()) struct cgraph_asm_node
*cgraph_asm_nodes
;
267 extern GTY(()) int cgraph_order
;
270 void dump_cgraph (FILE *);
271 void dump_cgraph_node (FILE *, struct cgraph_node
*);
272 void cgraph_insert_node_to_hashtable (struct cgraph_node
*node
);
273 void cgraph_remove_edge (struct cgraph_edge
*);
274 void cgraph_remove_node (struct cgraph_node
*);
275 void cgraph_node_remove_callees (struct cgraph_node
*node
);
276 struct cgraph_edge
*cgraph_create_edge (struct cgraph_node
*,
277 struct cgraph_node
*,
278 tree
, gcov_type
, int);
279 struct cgraph_node
*cgraph_node (tree
);
280 struct cgraph_node
*cgraph_node_for_asm (tree asmname
);
281 struct cgraph_edge
*cgraph_edge (struct cgraph_node
*, tree
);
282 void cgraph_set_call_stmt (struct cgraph_edge
*, tree
);
283 struct cgraph_local_info
*cgraph_local_info (tree
);
284 struct cgraph_global_info
*cgraph_global_info (tree
);
285 struct cgraph_rtl_info
*cgraph_rtl_info (tree
);
286 const char * cgraph_node_name (struct cgraph_node
*);
287 struct cgraph_edge
* cgraph_clone_edge (struct cgraph_edge
*,
288 struct cgraph_node
*,
289 tree
, gcov_type
, int, bool);
290 struct cgraph_node
* cgraph_clone_node (struct cgraph_node
*, gcov_type
,
293 void cgraph_redirect_edge_callee (struct cgraph_edge
*, struct cgraph_node
*);
295 struct cgraph_asm_node
*cgraph_add_asm_node (tree
);
297 bool cgraph_function_possibly_inlined_p (tree
);
298 void cgraph_unnest_node (struct cgraph_node
*);
300 enum availability
cgraph_function_body_availability (struct cgraph_node
*);
301 bool cgraph_is_master_clone (struct cgraph_node
*);
302 struct cgraph_node
*cgraph_master_clone (struct cgraph_node
*);
303 void cgraph_add_new_function (tree
);
305 /* In cgraphunit.c */
306 void cgraph_finalize_function (tree
, bool);
307 void cgraph_finalize_compilation_unit (void);
308 void cgraph_optimize (void);
309 void cgraph_mark_needed_node (struct cgraph_node
*);
310 void cgraph_mark_reachable_node (struct cgraph_node
*);
311 bool cgraph_inline_p (struct cgraph_edge
*, const char **reason
);
312 bool cgraph_preserve_function_body_p (tree
);
313 void verify_cgraph (void);
314 void verify_cgraph_node (struct cgraph_node
*);
315 void cgraph_build_static_cdtor (char which
, tree body
, int priority
);
316 void cgraph_reset_static_var_maps (void);
317 void init_cgraph (void);
318 struct cgraph_node
*cgraph_function_versioning (struct cgraph_node
*,
319 VEC(cgraph_edge_p
,heap
)*,
321 void cgraph_analyze_function (struct cgraph_node
*);
322 struct cgraph_node
*save_inline_function_body (struct cgraph_node
*);
323 void record_references_in_initializer (tree
);
326 bool cgraph_remove_unreachable_nodes (bool, FILE *);
327 int cgraph_postorder (struct cgraph_node
**);
331 extern GTY(()) struct varpool_node
*varpool_nodes_queue
;
332 extern GTY(()) struct varpool_node
*varpool_nodes
;
334 struct varpool_node
*varpool_node (tree
);
335 struct varpool_node
*varpool_node_for_asm (tree asmname
);
336 void varpool_mark_needed_node (struct varpool_node
*);
337 void dump_varpool (FILE *);
338 void dump_varpool_node (FILE *, struct varpool_node
*);
340 void varpool_finalize_decl (tree
);
341 bool decide_is_variable_needed (struct varpool_node
*, tree
);
342 enum availability
cgraph_variable_initializer_availability (struct varpool_node
*);
344 bool varpool_assemble_pending_decls (void);
345 bool varpool_assemble_decl (struct varpool_node
*node
);
346 bool varpool_analyze_pending_decls (void);
347 void varpool_output_debug_info (void);
348 void varpool_remove_unreferenced_decls (void);
350 /* In ipa-inline.c */
351 bool cgraph_decide_inlining_incrementally (struct cgraph_node
*, bool);
352 void cgraph_clone_inlined_nodes (struct cgraph_edge
*, bool, bool);
353 void cgraph_mark_inline_edge (struct cgraph_edge
*, bool);
354 bool cgraph_default_inline_p (struct cgraph_node
*, const char **);
355 #endif /* GCC_CGRAPH_H */