* config/darwin.c (darwin_assemble_visibility): Treat
[official-gcc.git] / gcc / ipa-inline.h
blobec9cf4d13ace49967cde9720be144d6d78b1cf9b
1 /* Inlining decision heuristics.
2 Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
6 This file is part of GCC.
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.
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.
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/>. */
22 /* Representation of inline parameters that do depend on context function is
23 inlined into (i.e. known constant values of function parameters.
25 Conditions that are interesting for function body are collected into CONDS
26 vector. They are of simple for function_param OP VAL, where VAL is
27 IPA invariant. The conditions are then referred by predicates. */
29 typedef struct GTY(()) condition
31 /* If agg_contents is set, this is the offset from which the used data was
32 loaded. */
33 HOST_WIDE_INT offset;
34 tree val;
35 int operand_num;
36 ENUM_BITFIELD(tree_code) code : 16;
37 /* Set if the used data were loaded from an aggregate parameter or from
38 data received by reference. */
39 unsigned agg_contents : 1;
40 /* If agg_contents is set, this differentiates between loads from data
41 passed by reference and by value. */
42 unsigned by_ref : 1;
43 } condition;
45 /* Inline hints are reasons why inline heuristics should preffer inlining given function.
46 They are represtented as bitmap of the following values. */
47 enum inline_hints_vals {
48 INLINE_HINT_indirect_call = 1,
49 INLINE_HINT_loop_iterations = 2,
50 INLINE_HINT_loop_stride = 4
52 typedef int inline_hints;
54 DEF_VEC_O (condition);
55 DEF_VEC_ALLOC_O (condition, gc);
57 typedef VEC(condition,gc) *conditions;
59 /* Representation of predicates i.e. formulas using conditions defined
60 above. Predicates are simple logical formulas in conjunctive-disjunctive
61 form.
63 Predicate is array of clauses terminated by 0. Every clause must be true
64 in order to make predicate true.
65 Clauses are represented as bitmaps of conditions. One of conditions
66 must be true in order for clause to be true. */
68 #define MAX_CLAUSES 8
69 typedef unsigned int clause_t;
70 struct GTY(()) predicate
72 clause_t clause[MAX_CLAUSES + 1];
75 /* Represnetation of function body size and time depending on the inline
76 context. We keep simple array of record, every containing of predicate
77 and time/size to account.
79 We keep values scaled up, so fractional sizes and times can be
80 accounted. */
81 #define INLINE_SIZE_SCALE 2
82 #define INLINE_TIME_SCALE (CGRAPH_FREQ_BASE * 2)
83 typedef struct GTY(()) size_time_entry
85 struct predicate predicate;
86 int size;
87 int time;
88 } size_time_entry;
89 DEF_VEC_O (size_time_entry);
90 DEF_VEC_ALLOC_O (size_time_entry, gc);
92 /* Function inlining information. */
93 struct GTY(()) inline_summary
95 /* Information about the function body itself. */
97 /* Estimated stack frame consumption by the function. */
98 HOST_WIDE_INT estimated_self_stack_size;
99 /* Size of the function body. */
100 int self_size;
101 /* Time of the function body. */
102 int self_time;
104 /* False when there something makes inlining impossible (such as va_arg). */
105 unsigned inlinable : 1;
107 /* Information about function that will result after applying all the
108 inline decisions present in the callgraph. Generally kept up to
109 date only for functions that are not inline clones. */
111 /* Estimated stack frame consumption by the function. */
112 HOST_WIDE_INT estimated_stack_size;
113 /* Expected offset of the stack frame of inlined function. */
114 HOST_WIDE_INT stack_frame_offset;
115 /* Estimated size of the function after inlining. */
116 int time;
117 int size;
119 /* Conditional size/time information. The summaries are being
120 merged during inlining. */
121 conditions conds;
122 VEC(size_time_entry,gc) *entry;
124 /* Predicate on when some loop in the function becomes to have known
125 bounds. */
126 struct predicate * GTY((skip)) loop_iterations;
127 /* Predicate on when some loop in the function becomes to have known
128 stride. */
129 struct predicate * GTY((skip)) loop_stride;
133 typedef struct inline_summary inline_summary_t;
134 DEF_VEC_O(inline_summary_t);
135 DEF_VEC_ALLOC_O(inline_summary_t,gc);
136 extern GTY(()) VEC(inline_summary_t,gc) *inline_summary_vec;
138 /* Information kept about parameter of call site. */
139 struct inline_param_summary
141 /* REG_BR_PROB_BASE based probability that parameter will change in between
142 two invocation of the calls.
143 I.e. loop invariant parameters
144 REG_BR_PROB_BASE/estimated_iterations and regular
145 parameters REG_BR_PROB_BASE.
147 Value 0 is reserved for compile time invariants. */
148 int change_prob;
150 typedef struct inline_param_summary inline_param_summary_t;
151 DEF_VEC_O(inline_param_summary_t);
152 DEF_VEC_ALLOC_O(inline_param_summary_t,heap);
154 /* Information kept about callgraph edges. */
155 struct inline_edge_summary
157 /* Estimated size and time of the call statement. */
158 int call_stmt_size;
159 int call_stmt_time;
160 /* Depth of loop nest, 0 means no nesting. */
161 unsigned short int loop_depth;
162 struct predicate *predicate;
163 /* Array indexed by parameters.
164 0 means that parameter change all the time, REG_BR_PROB_BASE means
165 that parameter is constant. */
166 VEC (inline_param_summary_t, heap) *param;
169 typedef struct inline_edge_summary inline_edge_summary_t;
170 DEF_VEC_O(inline_edge_summary_t);
171 DEF_VEC_ALLOC_O(inline_edge_summary_t,heap);
172 extern VEC(inline_edge_summary_t,heap) *inline_edge_summary_vec;
174 typedef struct edge_growth_cache_entry
176 int time, size;
177 inline_hints hints;
178 } edge_growth_cache_entry;
179 DEF_VEC_O(edge_growth_cache_entry);
180 DEF_VEC_ALLOC_O(edge_growth_cache_entry,heap);
182 extern VEC(int,heap) *node_growth_cache;
183 extern VEC(edge_growth_cache_entry,heap) *edge_growth_cache;
185 /* In ipa-inline-analysis.c */
186 void debug_inline_summary (struct cgraph_node *);
187 void dump_inline_summaries (FILE *f);
188 void dump_inline_summary (FILE *f, struct cgraph_node *node);
189 void dump_inline_hints (FILE *f, inline_hints);
190 void inline_generate_summary (void);
191 void inline_read_summary (void);
192 void inline_write_summary (void);
193 void inline_free_summary (void);
194 void initialize_inline_failed (struct cgraph_edge *);
195 int estimate_time_after_inlining (struct cgraph_node *, struct cgraph_edge *);
196 int estimate_size_after_inlining (struct cgraph_node *, struct cgraph_edge *);
197 void estimate_ipcp_clone_size_and_time (struct cgraph_node *,
198 VEC (tree, heap) *known_vals,
199 VEC (tree, heap) *known_binfos,
200 int *, int *);
201 int do_estimate_growth (struct cgraph_node *);
202 void inline_merge_summary (struct cgraph_edge *edge);
203 void inline_update_overall_summary (struct cgraph_node *node);
204 int do_estimate_edge_growth (struct cgraph_edge *edge);
205 int do_estimate_edge_time (struct cgraph_edge *edge);
206 inline_hints do_estimate_edge_hints (struct cgraph_edge *edge);
207 void initialize_growth_caches (void);
208 void free_growth_caches (void);
209 void compute_inline_parameters (struct cgraph_node *, bool);
211 /* In ipa-inline-transform.c */
212 bool inline_call (struct cgraph_edge *, bool, VEC (cgraph_edge_p, heap) **, int *, bool);
213 unsigned int inline_transform (struct cgraph_node *);
214 void clone_inlined_nodes (struct cgraph_edge *e, bool, bool, int *);
216 extern int ncalls_inlined;
217 extern int nfunctions_inlined;
219 static inline struct inline_summary *
220 inline_summary (struct cgraph_node *node)
222 return &VEC_index (inline_summary_t, inline_summary_vec, node->uid);
225 static inline struct inline_edge_summary *
226 inline_edge_summary (struct cgraph_edge *edge)
228 return &VEC_index (inline_edge_summary_t,
229 inline_edge_summary_vec, edge->uid);
232 /* Return estimated unit growth after inlning all calls to NODE.
233 Quick accesors to the inline growth caches.
234 For convenience we keep zero 0 as unknown. Because growth
235 can be both positive and negative, we simply increase positive
236 growths by 1. */
237 static inline int
238 estimate_growth (struct cgraph_node *node)
240 int ret;
241 if ((int)VEC_length (int, node_growth_cache) <= node->uid
242 || !(ret = VEC_index (int, node_growth_cache, node->uid)))
243 return do_estimate_growth (node);
244 return ret - (ret > 0);
248 /* Return estimated callee growth after inlining EDGE. */
250 static inline int
251 estimate_edge_growth (struct cgraph_edge *edge)
253 int ret;
254 if ((int)VEC_length (edge_growth_cache_entry, edge_growth_cache) <= edge->uid
255 || !(ret = VEC_index (edge_growth_cache_entry,
256 edge_growth_cache,
257 edge->uid).size))
258 return do_estimate_edge_growth (edge);
259 return ret - (ret > 0);
263 /* Return estimated callee runtime increase after inlning
264 EDGE. */
266 static inline int
267 estimate_edge_time (struct cgraph_edge *edge)
269 int ret;
270 if ((int)VEC_length (edge_growth_cache_entry, edge_growth_cache) <= edge->uid
271 || !(ret = VEC_index (edge_growth_cache_entry,
272 edge_growth_cache,
273 edge->uid).time))
274 return do_estimate_edge_time (edge);
275 return ret - (ret > 0);
279 /* Return estimated callee runtime increase after inlning
280 EDGE. */
282 static inline inline_hints
283 estimate_edge_hints (struct cgraph_edge *edge)
285 inline_hints ret;
286 if ((int)VEC_length (edge_growth_cache_entry, edge_growth_cache) <= edge->uid
287 || !(ret = VEC_index (edge_growth_cache_entry,
288 edge_growth_cache,
289 edge->uid).hints))
290 return do_estimate_edge_hints (edge);
291 return ret - 1;
295 /* Reset cached value for NODE. */
297 static inline void
298 reset_node_growth_cache (struct cgraph_node *node)
300 if ((int)VEC_length (int, node_growth_cache) > node->uid)
301 VEC_replace (int, node_growth_cache, node->uid, 0);
304 /* Reset cached value for EDGE. */
306 static inline void
307 reset_edge_growth_cache (struct cgraph_edge *edge)
309 if ((int)VEC_length (edge_growth_cache_entry, edge_growth_cache) > edge->uid)
311 struct edge_growth_cache_entry zero = {0, 0, 0};
312 VEC_replace (edge_growth_cache_entry, edge_growth_cache, edge->uid, zero);