1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005 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 /* Information about the function collected locally.
50 Available after function is analyzed. */
52 struct cgraph_local_info
GTY(())
54 /* Size of the function before inlining. */
57 /* Set when function function is visible in current compilation unit only
58 and its address is never taken. */
61 /* Set when function is visible by other units. */
62 bool externally_visible
;
64 /* Set once it has been finalized so we consider it to be output. */
67 /* False when there something makes inlining impossible (such as va_arg). */
70 /* True when function should be inlined independently on its size. */
71 bool disregard_inline_limits
;
73 /* True when the function has been originally extern inline, but it is
75 bool redefined_extern_inline
;
77 /* True if statics_read_for_function and
78 statics_written_for_function contain valid data. */
79 bool for_functions_valid
;
81 /* True if the function is going to be emitted in some other translation
82 unit, referenced from vtable. */
86 /* Information about the function that needs to be computed globally
87 once compilation is finished. Available only with -funit-at-time. */
89 struct cgraph_global_info
GTY(())
91 /* For inline clones this points to the function they will be inlined into. */
92 struct cgraph_node
*inlined_to
;
94 /* Estimated size of the function after inlining. */
97 /* Estimated growth after inlining. INT_MIN if not computed. */
100 /* Set iff the function has been inlined at least once. */
104 /* Information about the function that is propagated by the RTL backend.
105 Available only for functions that has been already assembled. */
107 struct cgraph_rtl_info
GTY(())
109 int preferred_incoming_stack_boundary
;
112 /* The cgraph data structure.
113 Each function decl has assigned cgraph_node listing callees and callers. */
115 struct cgraph_node
GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
118 struct cgraph_edge
*callees
;
119 struct cgraph_edge
*callers
;
120 struct cgraph_node
*next
;
121 struct cgraph_node
*previous
;
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
;
128 /* Pointer to the next function in cgraph_nodes_queue. */
129 struct cgraph_node
*next_needed
;
130 /* Pointer to the next clone. */
131 struct cgraph_node
*next_clone
;
132 struct cgraph_node
*prev_clone
;
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
;
137 PTR
GTY ((skip
)) aux
;
139 struct cgraph_local_info local
;
140 struct cgraph_global_info global
;
141 struct cgraph_rtl_info rtl
;
143 /* Expected number of executions: calculated in profile.c. */
145 /* Unique id of the node. */
147 /* Set when function must be output - it is externally visible
148 or its address is taken. */
150 /* Set when function is reachable by call from other function
151 that is either reachable or needed. */
153 /* Set once the function is lowered (ie it's CFG is built). */
155 /* Set once the function has been instantiated and its callee
158 /* Set when function is scheduled to be assembled. */
160 /* Set when function is visible by other units. */
161 bool externally_visible
;
162 /* Set for aliases once they got through assemble_alias. */
165 /* In non-unit-at-a-time mode the function body of inline candidates is saved
166 into clone before compiling so the function in original form can be
167 inlined later. This pointer points to the clone. */
171 struct cgraph_edge
GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
173 struct cgraph_node
*caller
;
174 struct cgraph_node
*callee
;
175 struct cgraph_edge
*prev_caller
;
176 struct cgraph_edge
*next_caller
;
177 struct cgraph_edge
*prev_callee
;
178 struct cgraph_edge
*next_callee
;
180 PTR
GTY ((skip (""))) aux
;
181 /* When NULL, inline this call. When non-NULL, points to the explanation
182 why function was not inlined. */
183 const char *inline_failed
;
184 /* Expected number of executions: calculated in profile.c. */
186 /* Depth of loop nest, 1 means no loop nest. */
190 /* The cgraph_varpool data structure.
191 Each static variable decl has assigned cgraph_varpool_node. */
193 struct cgraph_varpool_node
GTY(())
196 /* Pointer to the next function in cgraph_varpool_nodes. */
197 struct cgraph_varpool_node
*next
;
198 /* Pointer to the next function in cgraph_varpool_nodes_queue. */
199 struct cgraph_varpool_node
*next_needed
;
201 /* Set when function must be output - it is externally visible
202 or its address is taken. */
204 /* Needed variables might become dead by optimization. This flag
205 forces the variable to be output even if it appears dead otherwise. */
207 /* Set once the variable has been instantiated and its callee
210 /* Set once it has been finalized so we consider it to be output. */
212 /* Set when variable is scheduled to be assembled. */
214 /* Set when function is visible by other units. */
215 bool externally_visible
;
216 /* Set for aliases once they got through assemble_alias. */
220 extern GTY(()) struct cgraph_node
*cgraph_nodes
;
221 extern GTY(()) int cgraph_n_nodes
;
222 extern GTY(()) int cgraph_max_uid
;
223 extern bool cgraph_global_info_ready
;
224 extern bool cgraph_function_flags_ready
;
225 extern GTY(()) struct cgraph_node
*cgraph_nodes_queue
;
227 extern GTY(()) struct cgraph_varpool_node
*cgraph_varpool_first_unanalyzed_node
;
228 extern GTY(()) struct cgraph_varpool_node
*cgraph_varpool_nodes_queue
;
231 void dump_cgraph (FILE *);
232 void dump_cgraph_node (FILE *, struct cgraph_node
*);
233 void cgraph_insert_node_to_hashtable (struct cgraph_node
*node
);
234 void dump_varpool (FILE *);
235 void dump_cgraph_varpool_node (FILE *, struct cgraph_varpool_node
*);
236 void cgraph_remove_edge (struct cgraph_edge
*);
237 void cgraph_remove_node (struct cgraph_node
*);
238 void cgraph_node_remove_callees (struct cgraph_node
*node
);
239 struct cgraph_edge
*cgraph_create_edge (struct cgraph_node
*,
240 struct cgraph_node
*,
241 tree
, gcov_type
, int);
242 struct cgraph_node
*cgraph_node (tree
);
243 struct cgraph_node
*cgraph_node_for_asm (tree asmname
);
244 struct cgraph_edge
*cgraph_edge (struct cgraph_node
*, tree
);
245 struct cgraph_local_info
*cgraph_local_info (tree
);
246 struct cgraph_global_info
*cgraph_global_info (tree
);
247 struct cgraph_rtl_info
*cgraph_rtl_info (tree
);
248 const char * cgraph_node_name (struct cgraph_node
*);
249 struct cgraph_edge
* cgraph_clone_edge (struct cgraph_edge
*,
250 struct cgraph_node
*,
251 tree
, gcov_type
, int, bool);
252 struct cgraph_node
* cgraph_clone_node (struct cgraph_node
*, gcov_type
,
255 struct cgraph_varpool_node
*cgraph_varpool_node (tree
);
256 struct cgraph_varpool_node
*cgraph_varpool_node_for_asm (tree asmname
);
257 void cgraph_varpool_mark_needed_node (struct cgraph_varpool_node
*);
258 void cgraph_varpool_finalize_decl (tree
);
259 void cgraph_redirect_edge_callee (struct cgraph_edge
*, struct cgraph_node
*);
261 bool cgraph_function_possibly_inlined_p (tree
);
262 void cgraph_unnest_node (struct cgraph_node
*);
263 void cgraph_varpool_enqueue_needed_node (struct cgraph_varpool_node
*);
264 void cgraph_varpool_reset_queue (void);
265 bool decide_is_variable_needed (struct cgraph_varpool_node
*, tree
);
267 enum availability
cgraph_function_body_availability (struct cgraph_node
*);
268 enum availability
cgraph_variable_initializer_availability (struct cgraph_varpool_node
*);
269 bool cgraph_is_master_clone (struct cgraph_node
*);
270 struct cgraph_node
*cgraph_master_clone (struct cgraph_node
*);
272 /* In cgraphunit.c */
273 bool cgraph_assemble_pending_functions (void);
274 bool cgraph_varpool_assemble_pending_decls (void);
275 void cgraph_finalize_function (tree
, bool);
276 void cgraph_lower_function (struct cgraph_node
*);
277 void cgraph_finalize_compilation_unit (void);
278 void cgraph_optimize (void);
279 void cgraph_mark_needed_node (struct cgraph_node
*);
280 void cgraph_mark_reachable_node (struct cgraph_node
*);
281 bool cgraph_inline_p (struct cgraph_edge
*, const char **reason
);
282 bool cgraph_preserve_function_body_p (tree
);
283 void verify_cgraph (void);
284 void verify_cgraph_node (struct cgraph_node
*);
285 void cgraph_build_static_cdtor (char which
, tree body
, int priority
);
286 void cgraph_reset_static_var_maps (void);
287 void init_cgraph (void);
288 struct cgraph_node
*cgraph_function_versioning (struct cgraph_node
*,
289 varray_type
, varray_type
);
290 struct cgraph_node
*save_inline_function_body (struct cgraph_node
*);
293 bool cgraph_remove_unreachable_nodes (bool, FILE *);
294 int cgraph_postorder (struct cgraph_node
**);
296 /* In ipa-inline.c */
297 bool cgraph_decide_inlining_incrementally (struct cgraph_node
*, bool);
298 void cgraph_clone_inlined_nodes (struct cgraph_edge
*, bool, bool);
299 void cgraph_mark_inline_edge (struct cgraph_edge
*, bool);
300 bool cgraph_default_inline_p (struct cgraph_node
*, const char **);
301 #endif /* GCC_CGRAPH_H */