1/* Callgraph handling code.
2   Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
3   Contributed by Jan Hubicka
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING.  If not, write to the Free
19Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
2002110-1301, USA.  */
21
22#ifndef GCC_CGRAPH_H
23#define GCC_CGRAPH_H
24#include "tree.h"
25#include "basic-block.h"
26
27enum 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/* Information about the function collected locally.
50   Available after function is analyzed.  */
51
52struct cgraph_local_info GTY(())
53{
54  /* Size of the function before inlining.  */
55  int self_insns;
56
57  /* Set when function function is visible in current compilation unit only
58     and its address is never taken.  */
59  unsigned local : 1;
60
61  /* Set when function is visible by other units.  */
62  unsigned externally_visible : 1;
63
64  /* Set once it has been finalized so we consider it to be output.  */
65  unsigned finalized : 1;
66
67  /* False when there something makes inlining impossible (such as va_arg).  */
68  unsigned inlinable : 1;
69
70  /* True when function should be inlined independently on its size.  */
71  unsigned disregard_inline_limits : 1;
72
73  /* True when the function has been originally extern inline, but it is
74     redefined now.  */
75  unsigned redefined_extern_inline : 1;
76
77  /* True if statics_read_for_function and
78     statics_written_for_function contain valid data.  */
79  unsigned for_functions_valid : 1;
80
81  /* True if the function is going to be emitted in some other translation
82     unit, referenced from vtable.  */
83  unsigned vtable_method : 1;
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
89struct cgraph_global_info GTY(())
90{
91  /* For inline clones this points to the function they will be inlined into.  */
92  struct cgraph_node *inlined_to;
93
94  /* Estimated size of the function after inlining.  */
95  int insns;
96
97  /* Estimated growth after inlining.  INT_MIN if not computed.  */
98  int estimated_growth;
99
100  /* Set iff the function has been inlined at least once.  */
101  bool inlined;
102};
103
104/* Information about the function that is propagated by the RTL backend.
105   Available only for functions that has been already assembled.  */
106
107struct cgraph_rtl_info GTY(())
108{
109   int preferred_incoming_stack_boundary;
110};
111
112/* The cgraph data structure.
113   Each function decl has assigned cgraph_node listing callees and callers.  */
114
115struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
116{
117  tree decl;
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;
136  /* For functions with many calls sites it holds map from call expression
137     to the edge to speed up cgraph_edge function.  */
138  htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
139
140  PTR GTY ((skip)) aux;
141
142  struct cgraph_local_info local;
143  struct cgraph_global_info global;
144  struct cgraph_rtl_info rtl;
145
146  /* Expected number of executions: calculated in profile.c.  */
147  gcov_type count;
148  /* Unique id of the node.  */
149  int uid;
150  /* Ordering of all cgraph nodes.  */
151  int order;
152
153  /* Set when function must be output - it is externally visible
154     or its address is taken.  */
155  unsigned needed : 1;
156  /* Set when function is reachable by call from other function
157     that is either reachable or needed.  */
158  unsigned reachable : 1;
159  /* Set once the function is lowered (i.e. its CFG is built).  */
160  unsigned lowered : 1;
161  /* Set once the function has been instantiated and its callee
162     lists created.  */
163  unsigned analyzed : 1;
164  /* Set when function is scheduled to be assembled.  */
165  unsigned output : 1;
166  /* Set for aliases once they got through assemble_alias.  */
167  unsigned alias : 1;
168
169  /* In non-unit-at-a-time mode the function body of inline candidates is saved
170     into clone before compiling so the function in original form can be
171     inlined later.  This pointer points to the clone.  */
172  tree inline_decl;
173};
174
175struct cgraph_edge GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
176{
177  struct cgraph_node *caller;
178  struct cgraph_node *callee;
179  struct cgraph_edge *prev_caller;
180  struct cgraph_edge *next_caller;
181  struct cgraph_edge *prev_callee;
182  struct cgraph_edge *next_callee;
183  tree call_stmt;
184  PTR GTY ((skip (""))) aux;
185  /* When NULL, inline this call.  When non-NULL, points to the explanation
186     why function was not inlined.  */
187  const char *inline_failed;
188  /* Expected number of executions: calculated in profile.c.  */
189  gcov_type count;
190  /* Depth of loop nest, 1 means no loop nest.  */
191  int loop_nest;
192};
193
194typedef struct cgraph_edge *cgraph_edge_p;
195
196DEF_VEC_P(cgraph_edge_p);
197DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
198
199/* The cgraph_varpool data structure.
200   Each static variable decl has assigned cgraph_varpool_node.  */
201
202struct cgraph_varpool_node GTY(())
203{
204  tree decl;
205  /* Pointer to the next function in cgraph_varpool_nodes.  */
206  struct cgraph_varpool_node *next;
207  /* Pointer to the next function in cgraph_varpool_nodes_queue.  */
208  struct cgraph_varpool_node *next_needed;
209  /* Ordering of all cgraph nodes.  */
210  int order;
211
212  /* Set when function must be output - it is externally visible
213     or its address is taken.  */
214  unsigned needed : 1;
215  /* Needed variables might become dead by optimization.  This flag
216     forces the variable to be output even if it appears dead otherwise.  */
217  unsigned force_output : 1;
218  /* Set once the variable has been instantiated and its callee
219     lists created.  */
220  unsigned analyzed : 1;
221  /* Set once it has been finalized so we consider it to be output.  */
222  unsigned finalized : 1;
223  /* Set when variable is scheduled to be assembled.  */
224  unsigned output : 1;
225  /* Set when function is visible by other units.  */
226  unsigned externally_visible : 1;
227  /* Set for aliases once they got through assemble_alias.  */
228  unsigned alias : 1;
229};
230
231/* Every top level asm statement is put into a cgraph_asm_node.  */
232
233struct cgraph_asm_node GTY(())
234{
235  /* Next asm node.  */
236  struct cgraph_asm_node *next;
237  /* String for this asm node.  */
238  tree asm_str;
239  /* Ordering of all cgraph nodes.  */
240  int order;
241};
242
243extern GTY(()) struct cgraph_node *cgraph_nodes;
244extern GTY(()) int cgraph_n_nodes;
245extern GTY(()) int cgraph_max_uid;
246extern bool cgraph_global_info_ready;
247extern bool cgraph_function_flags_ready;
248extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
249extern GTY(()) struct cgraph_node *cgraph_expand_queue;
250
251extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_first_unanalyzed_node;
252extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_last_needed_node;
253extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_nodes_queue;
254extern GTY(()) struct cgraph_varpool_node *cgraph_varpool_nodes;
255extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
256extern GTY(()) int cgraph_order;
257
258/* In cgraph.c  */
259void dump_cgraph (FILE *);
260void dump_cgraph_node (FILE *, struct cgraph_node *);
261void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
262void dump_varpool (FILE *);
263void dump_cgraph_varpool_node (FILE *, struct cgraph_varpool_node *);
264void cgraph_remove_edge (struct cgraph_edge *);
265void cgraph_remove_node (struct cgraph_node *);
266void cgraph_node_remove_callees (struct cgraph_node *node);
267struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
268					struct cgraph_node *,
269					tree, gcov_type, int);
270struct cgraph_node *cgraph_node (tree);
271struct cgraph_node *cgraph_node_for_asm (tree asmname);
272struct cgraph_edge *cgraph_edge (struct cgraph_node *, tree);
273void cgraph_set_call_stmt (struct cgraph_edge *, tree);
274struct cgraph_local_info *cgraph_local_info (tree);
275struct cgraph_global_info *cgraph_global_info (tree);
276struct cgraph_rtl_info *cgraph_rtl_info (tree);
277const char * cgraph_node_name (struct cgraph_node *);
278struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
279					struct cgraph_node *,
280					tree, gcov_type, int, bool);
281struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type,
282					int, bool);
283
284struct cgraph_varpool_node *cgraph_varpool_node (tree);
285struct cgraph_varpool_node *cgraph_varpool_node_for_asm (tree asmname);
286void cgraph_varpool_mark_needed_node (struct cgraph_varpool_node *);
287void cgraph_varpool_finalize_decl (tree);
288void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
289
290struct cgraph_asm_node *cgraph_add_asm_node (tree);
291
292bool cgraph_function_possibly_inlined_p (tree);
293void cgraph_unnest_node (struct cgraph_node *);
294void cgraph_varpool_enqueue_needed_node (struct cgraph_varpool_node *);
295void cgraph_varpool_reset_queue (void);
296bool decide_is_variable_needed (struct cgraph_varpool_node *, tree);
297
298enum availability cgraph_function_body_availability (struct cgraph_node *);
299enum availability cgraph_variable_initializer_availability (struct cgraph_varpool_node *);
300bool cgraph_is_master_clone (struct cgraph_node *);
301struct cgraph_node *cgraph_master_clone (struct cgraph_node *);
302void cgraph_add_new_function (tree);
303
304/* In cgraphunit.c  */
305/* APPLE LOCAL radar 6305545 */
306void lower_if_nested_functions (tree);
307bool cgraph_assemble_pending_functions (void);
308bool cgraph_varpool_assemble_pending_decls (void);
309void cgraph_finalize_function (tree, bool);
310void cgraph_finalize_compilation_unit (void);
311void cgraph_optimize (void);
312void cgraph_mark_needed_node (struct cgraph_node *);
313void cgraph_mark_reachable_node (struct cgraph_node *);
314bool cgraph_inline_p (struct cgraph_edge *, const char **reason);
315bool cgraph_preserve_function_body_p (tree);
316void verify_cgraph (void);
317void verify_cgraph_node (struct cgraph_node *);
318void cgraph_build_static_cdtor (char which, tree body, int priority);
319void cgraph_reset_static_var_maps (void);
320void init_cgraph (void);
321struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
322						VEC(cgraph_edge_p,heap)*,
323						varray_type);
324void cgraph_analyze_function (struct cgraph_node *);
325struct cgraph_node *save_inline_function_body (struct cgraph_node *);
326
327/* In ipa.c  */
328bool cgraph_remove_unreachable_nodes (bool, FILE *);
329int cgraph_postorder (struct cgraph_node **);
330
331/* In ipa-inline.c  */
332bool cgraph_decide_inlining_incrementally (struct cgraph_node *, bool);
333void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
334void cgraph_mark_inline_edge (struct cgraph_edge *, bool);
335bool cgraph_default_inline_p (struct cgraph_node *, const char **);
336#endif  /* GCC_CGRAPH_H  */
337